init
This commit is contained in:
38
src/babylonjs/AppEngin.ts
Normal file
38
src/babylonjs/AppEngin.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { Engine } from '@babylonjs/core/Engines/engine';
|
||||
import { Monobehiver } from '../base/Monobehiver';
|
||||
|
||||
/**
|
||||
* 渲染引擎管理类 - 负责创建和管理3D渲染引擎
|
||||
*/
|
||||
export class AppEngin extends Monobehiver {
|
||||
object: Engine | null;
|
||||
canvas: HTMLCanvasElement | null;
|
||||
|
||||
constructor(mainApp: any) {
|
||||
super(mainApp);
|
||||
this.object = null;
|
||||
this.canvas = null;
|
||||
}
|
||||
|
||||
Awake(): void {
|
||||
this.canvas = this.mainApp.appDom.renderDom;
|
||||
if (!this.canvas) {
|
||||
throw new Error('Render canvas not found');
|
||||
}
|
||||
this.object = new Engine(this.canvas, true, {
|
||||
preserveDrawingBuffer: false, // 不保留绘图缓冲区
|
||||
stencil: true, // 启用模板缓冲
|
||||
alpha: true // 启用透明背景
|
||||
});
|
||||
this.object.setSize(window.innerWidth, window.innerHeight);
|
||||
this.object.setHardwareScalingLevel(1); // 1:1像素比例
|
||||
}
|
||||
|
||||
/** 处理窗口大小变化 */
|
||||
handleResize(): void {
|
||||
if (this.object) {
|
||||
this.object.setSize(window.innerWidth, window.innerHeight);
|
||||
this.object.resize();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user