feat(engine): 监听构件点击事件并记录选中状态
This commit is contained in:
@@ -47,6 +47,8 @@ export class Engine implements IBimComponent {
|
|||||||
private currentSectionAxis: 'x' | 'y' | 'z' | null = null;
|
private currentSectionAxis: 'x' | 'y' | 'z' | null = null;
|
||||||
/** 剖切盒是否激活 */
|
/** 剖切盒是否激活 */
|
||||||
private isSectionBoxActive: boolean = false;
|
private isSectionBoxActive: boolean = false;
|
||||||
|
/** 当前选中的构件信息 */
|
||||||
|
private selectedComponent: { url: string; id: string } | null = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造函数
|
* 构造函数
|
||||||
@@ -123,6 +125,20 @@ export class Engine implements IBimComponent {
|
|||||||
|
|
||||||
// 应用当前主题
|
// 应用当前主题
|
||||||
this.setTheme(themeManager.getTheme());
|
this.setTheme(themeManager.getTheme());
|
||||||
|
|
||||||
|
// 监听构件点击事件
|
||||||
|
this.engine.events.on('click', (hit: any) => {
|
||||||
|
if (hit && hit.object) {
|
||||||
|
this.selectedComponent = {
|
||||||
|
url: hit.object.url,
|
||||||
|
id: hit.object.name
|
||||||
|
};
|
||||||
|
console.log('[Engine] 构件选中:', this.selectedComponent);
|
||||||
|
} else {
|
||||||
|
this.selectedComponent = null;
|
||||||
|
console.log('[Engine] 取消选中');
|
||||||
|
}
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[Engine] Failed to initialize engine:', error);
|
console.error('[Engine] Failed to initialize engine:', error);
|
||||||
this._isInitialized = false;
|
this._isInitialized = false;
|
||||||
@@ -682,6 +698,43 @@ export class Engine implements IBimComponent {
|
|||||||
|
|
||||||
// ==================== 结束:漫游功能 ====================
|
// ==================== 结束:漫游功能 ====================
|
||||||
|
|
||||||
|
// ==================== 构件选中 ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前选中的构件
|
||||||
|
* @returns 选中构件的 URL 和 ID,未选中时返回 null
|
||||||
|
*/
|
||||||
|
public getSelectedComponent(): { url: string; id: string } | null {
|
||||||
|
return this.selectedComponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取构件属性
|
||||||
|
* @param url 模型 URL
|
||||||
|
* @param id 构件 ID
|
||||||
|
* @param callback 回调函数,接收属性数据
|
||||||
|
*/
|
||||||
|
public getComponentProperties(
|
||||||
|
url: string,
|
||||||
|
id: string,
|
||||||
|
callback: (data: any) => void
|
||||||
|
): void {
|
||||||
|
if (!this._isInitialized || !this.engine) {
|
||||||
|
console.error('[Engine] Cannot get component properties: engine not initialized.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.engine.modelProperties) {
|
||||||
|
console.error('[Engine] modelProperties not available');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('[Engine] Getting component properties:', { url, id });
|
||||||
|
this.engine.modelProperties.getModelProperties(url, id, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== 结束:构件选中 ====================
|
||||||
|
|
||||||
/** 激活框选放大功能 */
|
/** 激活框选放大功能 */
|
||||||
public activateZoomBox(): void {
|
public activateZoomBox(): void {
|
||||||
if (!this._isInitialized || !this.engine) {
|
if (!this._isInitialized || !this.engine) {
|
||||||
|
|||||||
Reference in New Issue
Block a user