This commit is contained in:
yinsx
2025-12-24 15:15:13 +08:00
commit df085f3f8f
27 changed files with 1926 additions and 0 deletions

View File

@ -0,0 +1,63 @@
// Babylon.js 场景管理器
class BabylonSceneManager {
constructor(canvasId) {
this.canvas = document.getElementById(canvasId);
this.engine = new BABYLON.Engine(this.canvas, true);
this.scene = null;
this.camera = null;
this.onModelLoaded = null;
}
init() {
this.scene = new BABYLON.Scene(this.engine);
this.scene.clearColor = new BABYLON.Color3(0.1, 0.1, 0.1);
this.camera = new BABYLON.ArcRotateCamera(
"camera",
0,
Math.PI / 2,
2,
new BABYLON.Vector3(0, 1.5, 0),
this.scene
);
this.camera.attachControl(this.canvas, true);
this.camera.minZ = 0.01;
this.camera.lowerRadiusLimit = 1;
this.camera.upperRadiusLimit = 5;
this.scene.createDefaultEnvironment();
this.engine.runRenderLoop(() => {
this.scene.render();
});
window.addEventListener('resize', () => {
this.engine.resize();
});
}
loadModel(modelPath, onSuccess, onError) {
BABYLON.SceneLoader.ImportMesh("", "./", modelPath, this.scene,
(meshes) => {
this.scene.lights.forEach(light => {
light.intensity = 50;
});
if (onSuccess) {
onSuccess(meshes);
}
},
null,
(scene, message) => {
if (onError) {
onError(message);
}
}
);
}
}
// 导出到全局
if (typeof window !== 'undefined') {
window.BabylonSceneManager = BabylonSceneManager;
}