86 lines
2.3 KiB
TypeScript
86 lines
2.3 KiB
TypeScript
/**
|
|
* @file MainApp.ts
|
|
* @description 主应用类,负责初始化和协调所有子模块
|
|
*/
|
|
|
|
import { AppDom } from './AppDom';
|
|
import { AppEngin } from './AppEngin';
|
|
import { AppScene } from './AppScene';
|
|
import { AppCamera } from './AppCamera';
|
|
import { AppLight } from './AppLight';
|
|
import { AppEnv } from './AppEnv';
|
|
import { AppModel } from './AppModel';
|
|
import { AppConfig } from './AppConfig';
|
|
|
|
/**
|
|
* 主应用类 - 3D场景的核心控制器
|
|
* 负责管理DOM、引擎、场景、相机、灯光、环境、模型和动画等子模块
|
|
*/
|
|
export class MainApp {
|
|
appDom: AppDom;
|
|
appEngin: AppEngin;
|
|
appScene: AppScene;
|
|
appCamera: AppCamera;
|
|
appModel: AppModel;
|
|
appLight: AppLight;
|
|
appEnv: AppEnv;
|
|
|
|
|
|
constructor() {
|
|
this.appDom = new AppDom();
|
|
this.appEngin = new AppEngin(this);
|
|
this.appScene = new AppScene(this);
|
|
this.appCamera = new AppCamera(this);
|
|
this.appModel = new AppModel(this);
|
|
this.appLight = new AppLight(this);
|
|
this.appEnv = new AppEnv(this);
|
|
|
|
window.addEventListener("resize", () => this.appEngin.handleResize());
|
|
}
|
|
|
|
/**
|
|
* 加载应用配置
|
|
* @param config 配置对象
|
|
*/
|
|
loadAConfig(config: any): void {
|
|
AppConfig.container = config.container || 'renderDom';
|
|
AppConfig.modelUrlList = config.modelUrlList || [];
|
|
AppConfig.env = config.env
|
|
AppConfig.success = config.success;
|
|
AppConfig.error = config.error;
|
|
|
|
}
|
|
|
|
loadModel(): void {
|
|
this.appModel.loadModel();
|
|
}
|
|
|
|
/** 唤醒/初始化所有子模块 */
|
|
async Awake(): Promise<void> {
|
|
this.appDom.Awake();
|
|
this.appEngin.Awake();
|
|
this.appScene.Awake();
|
|
this.appCamera.Awake();
|
|
this.appLight.Awake();
|
|
this.appEnv.Awake();
|
|
|
|
this.appModel.initManagers();
|
|
this.update();
|
|
}
|
|
|
|
/** 启动渲染循环 */
|
|
update(): void {
|
|
if (!this.appEngin.object) return;
|
|
this.appEngin.object.runRenderLoop(() => {
|
|
this.appScene.object?.render();
|
|
this.appCamera.update();
|
|
});
|
|
}
|
|
|
|
/** 销毁应用,释放所有资源 */
|
|
async dispose(): Promise<void> {
|
|
this.appModel?.clean();
|
|
this.appEnv?.clean();
|
|
}
|
|
}
|