feat: 优化测量功能架构与引擎组件
- 重构测量激活逻辑,在 Engine 组件中添加统一的 activateMeasure(mode) 方法 - 简化 MeasureDialogManager,移除冗余的 handleMeasureTypeChange 方法 - 添加 EngineManager.activateMeasure 转发方法 - 修复 loadModel 错误,正确调用 Engine 组件方法 - 为 Engine 组件设置固定背景渐变色 - MeasurePanel 初始化时触发 onModeChange 回调 - 添加 MeasureMode 共享类型定义 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import type { BimEngine } from '../bim-engine';
|
||||
import { RightKeyManager } from './right-key-manager';
|
||||
import { infoMenuButton } from '../components/menu/buttons/info';
|
||||
import { homeMenuButton } from '../components/menu/buttons/home';
|
||||
import type { MeasureMode } from '../types/measure';
|
||||
|
||||
/**
|
||||
* 3D 引擎管理器
|
||||
@@ -76,20 +77,20 @@ export class EngineManager extends BimComponent {
|
||||
public isInitialized(): boolean {
|
||||
return this.engineInstance !== null && this.engineInstance.isInitialized();
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载 3D 模型
|
||||
* @param url 模型文件 URL
|
||||
* @param options 加载选项(位置、旋转、缩放)
|
||||
*/
|
||||
public loadModel(url: string, options?: ModelLoadOptions): void {
|
||||
if (!this.engineInstance || !this.engineInstance.isInitialized()) {
|
||||
console.error('[EngineManager] 3D Engine not initialized. Please call initialize() first.');
|
||||
if (!this.engineInstance) {
|
||||
console.warn('[EngineManager] 3D Engine not initialized.');
|
||||
return;
|
||||
}
|
||||
this.engineInstance.loadModel(url, options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取原始 3D 引擎实例
|
||||
* 用于直接调用第三方引擎的其他 API
|
||||
@@ -102,6 +103,50 @@ export class EngineManager extends BimComponent {
|
||||
return this.engineInstance.getEngine();
|
||||
}
|
||||
|
||||
/**
|
||||
* 回到主视角
|
||||
*/
|
||||
public CameraGoHome(): void {
|
||||
if (!this.engineInstance) {
|
||||
console.warn('[EngineManager] 3D Engine not initialized.');
|
||||
return;
|
||||
}
|
||||
this.engineInstance.CameraGoHome();
|
||||
}
|
||||
/**
|
||||
* 激活测量功能
|
||||
* @param mode 测量类型
|
||||
*/
|
||||
public activateMeasure(mode: MeasureMode): void {
|
||||
if (!this.engineInstance) {
|
||||
console.warn('[EngineManager] 3D Engine not initialized.');
|
||||
return;
|
||||
}
|
||||
this.engineInstance.activateMeasure(mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 停用测量功能
|
||||
*/
|
||||
public deactivateMeasure(): void {
|
||||
if (!this.engineInstance) {
|
||||
return;
|
||||
}
|
||||
this.engineInstance.deactivateMeasure();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前激活的测量类型
|
||||
*/
|
||||
public getCurrentMeasureType(): MeasureMode | null {
|
||||
if (!this.engineInstance) {
|
||||
return null;
|
||||
}
|
||||
return this.engineInstance.getCurrentMeasureType();
|
||||
}
|
||||
|
||||
// ==================== 结束:测量功能方法 ====================
|
||||
|
||||
/**
|
||||
* 销毁 3D 引擎实例
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {BimComponent} from '../core/component';
|
||||
import {BimEngine} from '../bim-engine';
|
||||
import {BimDialog} from "../components/dialog";
|
||||
import { BimComponent } from '../core/component';
|
||||
import { BimEngine } from '../bim-engine';
|
||||
import { BimDialog } from "../components/dialog";
|
||||
import { MeasurePanel } from '../components/measure-panel';
|
||||
import type { MeasureConfig, MeasureMode, MeasureResult } from '../components/measure-panel/types';
|
||||
|
||||
@@ -47,12 +47,11 @@ export class MeasureDialogManager extends BimComponent {
|
||||
|
||||
// 创建测量面板(只做 UI,不实现真实测量)
|
||||
this.panel = new MeasurePanel({
|
||||
defaultMode: 'distance', // 默认展示前四个,且默认选中“距离”
|
||||
defaultMode: 'distance', // 默认展示前四个,且默认选中"距离"
|
||||
defaultExpanded: false,
|
||||
onModeChange: (mode) => {
|
||||
// 这里只做事件/占位:未来可在这里切换引擎内置工具
|
||||
// 本次需求不实现真实测量,因此仅保留回调位置
|
||||
console.log('[MeasureDialogManager] 当前测量方式已切换:', mode);
|
||||
this.engine.engine?.activateMeasure(mode);
|
||||
},
|
||||
onClearAll: () => {
|
||||
// 预留:未来可清理引擎测量绘制/标注
|
||||
@@ -90,6 +89,7 @@ export class MeasureDialogManager extends BimComponent {
|
||||
},
|
||||
onClose: () => {
|
||||
this.engine.toolbar?.setBtnActive('measure', false)
|
||||
this.destroy()
|
||||
}
|
||||
});
|
||||
this.dialog.init();
|
||||
@@ -183,6 +183,11 @@ export class MeasureDialogManager extends BimComponent {
|
||||
}
|
||||
|
||||
public destroy(): void {
|
||||
// 停用测量功能
|
||||
if (this.engine.engine) {
|
||||
this.engine.engine.deactivateMeasure();
|
||||
}
|
||||
|
||||
// 关闭弹窗
|
||||
if (this.dialog) {
|
||||
this.dialog.destroy();
|
||||
|
||||
Reference in New Issue
Block a user