Files
zhengte.babylonjs-sdk/src/babylonjs/AppEngin.ts
yinsx 99da97fcb4
All checks were successful
continuous-integration/drone/push Build is passing
1
2026-01-05 16:40:08 +08:00

40 lines
1.2 KiB
TypeScript

import { Engine } from '@babylonjs/core/Engines/engine';
import { Monobehiver } from '../base/Monobehiver';
import { AppConfig } from './AppConfig';
/**
* 渲染引擎管理类 - 负责创建和管理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 = AppConfig.container;
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();
}
}
}