Fix scene doubling on reload and add dynamic inspector import
All checks were successful
Build / build (push) Successful in 1m45s
All checks were successful
Build / build (push) Successful in 1m45s
- Dispose old scene before creating new one (cleans up physics) - Stop existing render loop before starting new one - Dynamically import @babylonjs/inspector on 'i' key press 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
dfa46c85a6
commit
cf3a74ff0b
@ -37,6 +37,8 @@ export async function setupScene(
|
|||||||
const audioEngine = await createAudioEngine();
|
const audioEngine = await createAudioEngine();
|
||||||
reporter.reportProgress(30, 'Audio engine ready');
|
reporter.reportProgress(30, 'Audio engine ready');
|
||||||
|
|
||||||
|
// Stop any existing render loop before starting new one (prevents doubling on reload)
|
||||||
|
engine.stopRenderLoop();
|
||||||
engine.runRenderLoop(() => DefaultScene.MainScene.render());
|
engine.runRenderLoop(() => DefaultScene.MainScene.render());
|
||||||
|
|
||||||
return { engine, audioEngine };
|
return { engine, audioEngine };
|
||||||
@ -50,6 +52,10 @@ function createEngine(canvas: HTMLCanvasElement): Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createMainScene(engine: Engine): void {
|
function createMainScene(engine: Engine): void {
|
||||||
|
// Dispose old scene if it exists (prevents doubling on reload)
|
||||||
|
if (DefaultScene.MainScene && !DefaultScene.MainScene.isDisposed) {
|
||||||
|
DefaultScene.MainScene.dispose();
|
||||||
|
}
|
||||||
DefaultScene.MainScene = new Scene(engine);
|
DefaultScene.MainScene = new Scene(engine);
|
||||||
DefaultScene.MainScene.ambientColor = new Color3(.2, .2, .2);
|
DefaultScene.MainScene.ambientColor = new Color3(.2, .2, .2);
|
||||||
DefaultScene.MainScene.clearColor = new Color3(0, 0, 0).toColor4();
|
DefaultScene.MainScene.clearColor = new Color3(0, 0, 0).toColor4();
|
||||||
|
|||||||
@ -100,15 +100,17 @@ export class KeyboardInput {
|
|||||||
document.onkeydown = (ev) => {
|
document.onkeydown = (ev) => {
|
||||||
// Always allow inspector and camera toggle, even when disabled
|
// Always allow inspector and camera toggle, even when disabled
|
||||||
if (ev.key === 'i') {
|
if (ev.key === 'i') {
|
||||||
// Toggle Babylon Inspector
|
// Dynamically import inspector on first use (keeps it out of main bundle)
|
||||||
if (this._scene.debugLayer.isVisible()) {
|
import('@babylonjs/inspector').then(() => {
|
||||||
this._scene.debugLayer.hide();
|
if (this._scene.debugLayer.isVisible()) {
|
||||||
} else {
|
this._scene.debugLayer.hide();
|
||||||
this._scene.debugLayer.show({
|
} else {
|
||||||
overlay: true,
|
this._scene.debugLayer.show({
|
||||||
showExplorer: true,
|
overlay: true,
|
||||||
});
|
showExplorer: true,
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user