From cf20389a308abd60d33f1ab58d6f44ca7ce186cc Mon Sep 17 00:00:00 2001 From: yuding <1023798085@qq.com> Date: Wed, 28 Jan 2026 11:55:57 +0800 Subject: [PATCH] =?UTF-8?q?feat(engine):=20=E7=9B=91=E5=90=AC=E6=9E=84?= =?UTF-8?q?=E4=BB=B6=E7=82=B9=E5=87=BB=E4=BA=8B=E4=BB=B6=E5=B9=B6=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E9=80=89=E4=B8=AD=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/engine/index.ts | 53 ++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/components/engine/index.ts b/src/components/engine/index.ts index 3891059..2931516 100644 --- a/src/components/engine/index.ts +++ b/src/components/engine/index.ts @@ -47,6 +47,8 @@ export class Engine implements IBimComponent { private currentSectionAxis: 'x' | 'y' | 'z' | null = null; /** 剖切盒是否激活 */ 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.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) { console.error('[Engine] Failed to initialize engine:', error); 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 { if (!this._isInitialized || !this.engine) {