diff --git a/src/components/button-group/index.ts b/src/components/button-group/index.ts index fbe6188..c0b3d3f 100644 --- a/src/components/button-group/index.ts +++ b/src/components/button-group/index.ts @@ -10,12 +10,11 @@ import { t, localeManager } from '../../services/locale'; import { themeManager } from '../../services/theme'; import type { ThemeConfig } from '../../themes/types'; import { IBimComponent } from '../../types/component'; -import { ManagerRegistry } from '../../core/manager-registry'; -import { EngineEvents } from '../../types/events'; +import type { EngineEvents } from '../../types/events'; export class BimButtonGroup implements IBimComponent { private container: HTMLElement; - private options: ButtonGroupOptions; + protected options: ButtonGroupOptions; private groups: ButtonGroup[] = []; private activeBtnIds: Set = new Set(); private btnRefs: Map = new Map(); @@ -63,8 +62,7 @@ export class BimButtonGroup implements IBimComponent { } protected emit(event: K, payload: EngineEvents[K]) { - const registry = ManagerRegistry.getInstance(); - registry.emit(event, payload); + this.options.registry?.emit(event, payload); } private initContainer(): void { diff --git a/src/components/button-group/index.type.ts b/src/components/button-group/index.type.ts index bf9cb71..1a6615d 100644 --- a/src/components/button-group/index.type.ts +++ b/src/components/button-group/index.type.ts @@ -1,3 +1,5 @@ +import type { ManagerRegistry } from '../../core/manager-registry'; + export type ButtonType = 'button' | 'menu'; /** 按钮组样式类型 */ @@ -97,6 +99,8 @@ export interface ButtonGroupOptions extends ButtonGroupColors { showLabel?: boolean; visibility?: Record; className?: string; + /** Manager 注册表实例(用于事件通信) */ + registry?: ManagerRegistry; } export interface ClickPayload { diff --git a/src/components/engine/index.ts b/src/components/engine/index.ts index 7e98004..9dfc45d 100644 --- a/src/components/engine/index.ts +++ b/src/components/engine/index.ts @@ -5,10 +5,10 @@ import type { EngineOptions, ModelLoadOptions, EngineInfo } from './types'; import { type MeasureMode } from '../../types/measure'; import type { MeasureUnit, MeasurePrecision } from '../measure-panel/types'; import type { SectionBoxRange } from '../section-box-panel/types'; -import { ManagerRegistry } from '../../core/manager-registry'; +import type { ManagerRegistry } from '../../core/manager-registry'; // 导入第三方 SDK 的 createEngine 函数(从 npm 包引入) -import { createEngine as createEngineSDK } from 'iflow-engine-base'; -//import { createEngine as createEngineSDK } from '../../../../bim_engine_base/dist/bim-engine-sdk.es'; +//import { createEngine as createEngineSDK } from 'iflow-engine-base'; +import { createEngine as createEngineSDK } from '../../../../bim_engine_base/dist/bim-engine-sdk.es'; import "../../../../bim_engine_base/dist/iflow-engine-base.css" export type { EngineOptions, ModelLoadOptions, EngineInfo }; @@ -17,8 +17,8 @@ export type { EngineOptions, ModelLoadOptions, EngineInfo }; * 创建 Engine 实例的工厂函数 * 兼容旧代码直接 import { createEngine } 的方式 */ -export const createEngine = (options: EngineOptions) => { - return new Engine(options); +export const createEngine = (options: EngineOptions, registry: ManagerRegistry) => { + return new Engine(options, registry); }; /** @@ -26,8 +26,11 @@ export const createEngine = (options: EngineOptions) => { * 负责创建和管理第三方 3D 引擎实例 */ export class Engine implements IBimComponent { + /** 第三方 3D 引擎实例 */ /** 第三方 3D 引擎实例 */ private engine: any = null; + /** 管理器注册表实例 */ + private registry: ManagerRegistry; /** 引擎挂载的容器元素 */ private container: HTMLElement; /** 引擎容器 ID(用于传递给 createEngine) */ @@ -53,7 +56,9 @@ export class Engine implements IBimComponent { * 构造函数 * @param options 3D 引擎配置选项 */ - constructor(options: EngineOptions) { + constructor(options: EngineOptions, registry: ManagerRegistry) { + // 保存注册表 + this.registry = registry; // 解析容器元素 this.container = options.container; // 如果容器没有 id,生成一个唯一的 id @@ -127,7 +132,7 @@ export class Engine implements IBimComponent { // 监听构件点击事件 this.engine.events.on('click', (hit: any) => { - const registry = ManagerRegistry.getInstance(); + const registry = this.registry; if (hit && hit.object) { this.selectedComponent = { url: hit.object.url, @@ -238,6 +243,17 @@ export class Engine implements IBimComponent { this.engine.dispose(); } + /** + * 调整渲染器尺寸 + * 容器大小变化时调用,自动更新渲染器、相机投影矩阵和后处理合成器 + */ + public resize(): void { + if (!this._isInitialized || !this.engine) { + return; + } + // this.engine.handleWindowResize(); + } + // ==================== 测量功能方法 ==================== // ==================== 测量功能(统一 API) ==================== diff --git a/src/components/menu/buttons/four.ts b/src/components/menu/buttons/four.ts index 94e5e25..dd01436 100644 --- a/src/components/menu/buttons/four.ts +++ b/src/components/menu/buttons/four.ts @@ -1,13 +1,12 @@ import { MenuItemConfig } from '../item'; -import { ManagerRegistry } from '../../../core/manager-registry'; +import type { ManagerRegistry } from '../../../core/manager-registry'; -export const fourMenuButton = (): MenuItemConfig => { +export const fourMenuButton = (registry: ManagerRegistry): MenuItemConfig => { return { id: 'fourMenu', label: 'menu.info', icon: '', onClick: () => { - const registry = ManagerRegistry.getInstance(); registry.engineInfo?.show(); registry.engine3d?.rightKey?.hide(); } diff --git a/src/components/menu/buttons/home.ts b/src/components/menu/buttons/home.ts index e565b35..1325ec9 100644 --- a/src/components/menu/buttons/home.ts +++ b/src/components/menu/buttons/home.ts @@ -1,17 +1,16 @@ import { MenuItemConfig } from '../item'; -import { ManagerRegistry } from '../../../core/manager-registry'; +import type { ManagerRegistry } from '../../../core/manager-registry'; import { secondMenuButton } from './second'; import { fourMenuButton } from './four'; -export const homeMenuButton = (): MenuItemConfig => { +export const homeMenuButton = (registry: ManagerRegistry): MenuItemConfig => { return { id: 'homeMenu', label: 'menu.home', group: 'home', - children: [secondMenuButton(), fourMenuButton()], + children: [secondMenuButton(registry), fourMenuButton(registry)], icon: '', onClick: () => { - const registry = ManagerRegistry.getInstance(); registry.engineInfo?.show(); registry.engine3d?.rightKey?.hide(); } diff --git a/src/components/menu/buttons/info.ts b/src/components/menu/buttons/info.ts index c9e0dfd..22911d4 100644 --- a/src/components/menu/buttons/info.ts +++ b/src/components/menu/buttons/info.ts @@ -1,14 +1,13 @@ import { MenuItemConfig } from '../item'; -import { ManagerRegistry } from '../../../core/manager-registry'; +import type { ManagerRegistry } from '../../../core/manager-registry'; -export const infoMenuButton = (): MenuItemConfig => { +export const infoMenuButton = (registry: ManagerRegistry): MenuItemConfig => { return { id: 'infoMenu', label: 'menu.info', group: 'info', icon: '', onClick: () => { - const registry = ManagerRegistry.getInstance(); registry.engineInfo?.show(); registry.engine3d?.rightKey?.hide(); } diff --git a/src/components/menu/buttons/second.ts b/src/components/menu/buttons/second.ts index 3398227..e71313a 100644 --- a/src/components/menu/buttons/second.ts +++ b/src/components/menu/buttons/second.ts @@ -1,13 +1,12 @@ import { MenuItemConfig } from '../item'; -import { ManagerRegistry } from '../../../core/manager-registry'; +import type { ManagerRegistry } from '../../../core/manager-registry'; -export const secondMenuButton = (): MenuItemConfig => { +export const secondMenuButton = (registry: ManagerRegistry): MenuItemConfig => { return { id: 'infoMenu', label: 'menu.info', icon: '', onClick: () => { - const registry = ManagerRegistry.getInstance(); registry.engineInfo?.show(); registry.engine3d?.rightKey?.hide(); } diff --git a/src/components/walk-path-panel/index.ts b/src/components/walk-path-panel/index.ts index 96ef17a..399c6b5 100644 --- a/src/components/walk-path-panel/index.ts +++ b/src/components/walk-path-panel/index.ts @@ -3,7 +3,7 @@ import type { ThemeConfig } from '../../themes/types'; import { IBimComponent } from '../../types/component'; import { localeManager, t } from '../../services/locale'; import { themeManager } from '../../services/theme'; -import { ManagerRegistry } from '../../core/manager-registry'; +import type { ManagerRegistry } from '../../core/manager-registry'; import type { RoamingPoint } from './types'; /** @@ -13,13 +13,20 @@ import type { RoamingPoint } from './types'; export class WalkPathPanel implements IBimComponent { public element!: HTMLElement; + /** 管理器注册表実例 */ + private registry: ManagerRegistry; + /** 管理器注册表实例 */ - private registry = ManagerRegistry.getInstance(); /** 国际化订阅取消函数 */ private unsubscribeLocale: (() => void) | null = null; /** 主题订阅取消函数 */ private unsubscribeTheme: (() => void) | null = null; + constructor(registry: ManagerRegistry) { + this.registry = registry; + } + + /** 漫游点列表 */ private points: RoamingPoint[] = []; /** 漫游时间(毫秒) */