更新了版本
This commit is contained in:
@@ -85,6 +85,12 @@ export class BimEngine {
|
||||
this.registry.emit(event, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订阅事件
|
||||
* @param event 事件名称
|
||||
* @param listener 事件监听器
|
||||
* @returns 取消订阅函数
|
||||
*/
|
||||
public on<K extends keyof EngineEvents>(event: K, listener: (payload: EngineEvents[K]) => void): () => void {
|
||||
return this.registry.on(event, listener);
|
||||
}
|
||||
|
||||
@@ -134,21 +134,32 @@ export class Engine implements IBimComponent {
|
||||
|
||||
// 监听构件点击事件
|
||||
// 底层 interactionModule trigger 格式: [{url: string, ids: string[]}]
|
||||
this.engine.events.on('click', (data: any) => {
|
||||
const registry = this.registry;
|
||||
if (data && Array.isArray(data) && data.length > 0 && data[0].url) {
|
||||
this.selectedComponent = {
|
||||
url: data[0].url,
|
||||
id: data[0].ids?.[0]
|
||||
};
|
||||
console.log('[Engine] 构件选中:', this.selectedComponent);
|
||||
registry.emit('component:selected', this.selectedComponent);
|
||||
} else {
|
||||
this.selectedComponent = null;
|
||||
console.log('[Engine] 取消选中');
|
||||
registry.emit('component:deselected', {});
|
||||
}
|
||||
});
|
||||
if (this.engine?.events?.on) {
|
||||
this.engine.events.on('click', (data: any) => {
|
||||
const registry = this.registry;
|
||||
console.log('[Engine] 底层 click 事件触发:', data);
|
||||
if (data && Array.isArray(data) && data.length > 0 && data[0].url) {
|
||||
this.selectedComponent = {
|
||||
url: data[0].url,
|
||||
id: data[0].ids?.[0]
|
||||
};
|
||||
console.log('[Engine] 触发 component:selected:', this.selectedComponent);
|
||||
registry.emit('component:selected', this.selectedComponent);
|
||||
} else {
|
||||
this.selectedComponent = null;
|
||||
console.log('[Engine] 触发 component:deselected');
|
||||
registry.emit('component:deselected', {});
|
||||
}
|
||||
});
|
||||
|
||||
// 监听模型加载完成事件
|
||||
this.engine.events.on('loading_completed', () => {
|
||||
console.log('[Engine] 底层 LoadingCompleted 事件触发');
|
||||
this.registry.emit('engine:model-loading-completed', {});
|
||||
});
|
||||
} else {
|
||||
console.warn('[Engine] 底层引擎不支持 events.on 方法,无法监听点击事件');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('[Engine] Failed to initialize engine:', error);
|
||||
@@ -1032,6 +1043,58 @@ export class Engine implements IBimComponent {
|
||||
this.engine.modelProperties.getModelProperties(url, id, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取构件位置和详细信息(问题报告用)
|
||||
* @param params 查询参数
|
||||
* @param params.url 模型 URL
|
||||
* @param params.ids 构件 ID 数组
|
||||
* @returns 构件数据,包含位置、属性等信息
|
||||
*/
|
||||
public getModelPosition(params: { url: string; ids: number[] }): any {
|
||||
if (!this._isInitialized || !this.engine) {
|
||||
console.error('[Engine] Cannot get model position: engine not initialized.');
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!this.engine.issueReport?.getMoldePosition) {
|
||||
console.error('[Engine] getMoldePosition method not available in issueReport');
|
||||
return null;
|
||||
}
|
||||
|
||||
console.log('[Engine] Getting model position:', params);
|
||||
|
||||
// 调用底层引擎 issueReport.getMoldePosition 获取构件信息
|
||||
return this.engine.issueReport.getMoldePosition(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到指定相机视角(问题报告用)
|
||||
* @param cameraData 相机配置数据,包含 position、target、rotation 等信息
|
||||
* @returns 是否跳转成功
|
||||
*/
|
||||
public jumpToCamera(cameraData: any): boolean {
|
||||
if (!this._isInitialized || !this.engine) {
|
||||
console.error('[Engine] Cannot jump to camera: engine not initialized.');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.engine.issueReport?.jumptoCamera) {
|
||||
console.error('[Engine] jumptoCamera method not available in issueReport');
|
||||
return false;
|
||||
}
|
||||
|
||||
console.log('[Engine] Jumping to camera:', cameraData);
|
||||
|
||||
// 调用底层引擎 issueReport.jumptoCamera 跳转视角
|
||||
try {
|
||||
this.engine.issueReport.jumptoCamera(cameraData);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('[Engine] Failed to jump to camera:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 结束:构件选中 ====================
|
||||
|
||||
// ==================== 模型树 ====================
|
||||
|
||||
@@ -274,6 +274,34 @@ export class EngineManager extends BaseManager {
|
||||
this.engineInstance.resumeRendering();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取构件位置和详细信息(问题报告用)
|
||||
* @param params 查询参数
|
||||
* @param params.url 模型 URL
|
||||
* @param params.ids 构件 ID 数组
|
||||
* @returns 构件数据
|
||||
*/
|
||||
public getModelPosition(params: { url: string; ids: number[] }): any {
|
||||
if (!this.engineInstance) {
|
||||
console.warn('[EngineManager] 3D Engine not initialized.');
|
||||
return null;
|
||||
}
|
||||
return this.engineInstance.getModelPosition(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到指定相机视角(问题报告用)
|
||||
* @param cameraData 相机配置数据,包含 position、target、rotation 等信息
|
||||
* @returns 是否跳转成功
|
||||
*/
|
||||
public jumpToCamera(cameraData: any): boolean {
|
||||
if (!this.engineInstance) {
|
||||
console.warn('[EngineManager] 3D Engine not initialized.');
|
||||
return false;
|
||||
}
|
||||
return this.engineInstance.jumpToCamera(cameraData);
|
||||
}
|
||||
|
||||
/** 销毁引擎管理器 */
|
||||
public destroy(): void {
|
||||
if (this.engineInstance) {
|
||||
|
||||
@@ -5,6 +5,7 @@ export interface EngineEvents {
|
||||
|
||||
// Engine Events
|
||||
'engine:model-loaded': { url: string };
|
||||
'engine:model-loading-completed': {};
|
||||
'engine:object-clicked': { objectId: string; position: { x: number; y: number; z: number } };
|
||||
|
||||
// 树组件事件
|
||||
|
||||
Reference in New Issue
Block a user