From 414a28fb195100d61aee7c37a9a817ea5169e346 Mon Sep 17 00:00:00 2001 From: syuilo <4439005+syuilo@users.noreply.github.com> Date: Sat, 9 May 2026 14:06:07 +0900 Subject: [PATCH] wip --- packages/frontend/src/world/room/engine.ts | 2 +- packages/frontend/src/world/room/object.ts | 2 +- .../src/world/room/objects/allInOnePc.ts | 10 +++++++--- .../src/world/room/objects/beamLamp.ts | 19 ++++++++++++------- .../src/world/room/objects/desktopPc.ts | 18 +++++++++++++----- .../world/room/objects/ductRailSpotLights.ts | 12 +++++++++--- .../world/room/objects/handheldGameConsole.ts | 2 +- .../src/world/room/objects/laptopPc.ts | 10 +++++++--- .../src/world/room/objects/largeMousepad.ts | 2 +- .../src/world/room/objects/lavaLamp.ts | 9 ++++++--- .../src/world/room/objects/monitor.ts | 10 +++++++--- .../src/world/room/objects/spotLight.ts | 10 +++++++--- .../room/objects/tabletopDigitalClock.ts | 4 ++-- .../frontend/src/world/room/objects/tv.ts | 10 +++++++--- .../world/room/objects/wallMountSpotLight.ts | 10 +++++++--- .../world/room/objects/woodRingFloorLamp.ts | 12 +++++++++--- .../room/objects/woodRingsPendantLight.ts | 10 +++++++--- .../frontend/src/world/room/previewEngine.ts | 1 - 18 files changed, 104 insertions(+), 49 deletions(-) diff --git a/packages/frontend/src/world/room/engine.ts b/packages/frontend/src/world/room/engine.ts index c92fba4c4e..f70b856a2a 100644 --- a/packages/frontend/src/world/room/engine.ts +++ b/packages/frontend/src/world/room/engine.ts @@ -881,9 +881,9 @@ export class RoomEngine extends EventEmitter { }); const objectInstance = await def.createInstance({ - room: this, scene: this.scene, sr: this.sr, + lc: this.lightContainer, root, options: args.options, model, diff --git a/packages/frontend/src/world/room/object.ts b/packages/frontend/src/world/room/object.ts index 68513c3ba7..eb9f320cd0 100644 --- a/packages/frontend/src/world/room/object.ts +++ b/packages/frontend/src/world/room/object.ts @@ -112,9 +112,9 @@ export type ObjectDef = { isChair?: boolean; treatLoaderResult?: (loaderResult: BABYLON.AssetContainer) => void; createInstance: (args: { - room?: RoomEngine | null; scene: BABYLON.Scene; sr: BABYLON.SnapshotRenderingHelper; + lc: BABYLON.ClusteredLightContainer | null; root: BABYLON.Mesh; options: Readonly>; model: ModelManager; diff --git a/packages/frontend/src/world/room/objects/allInOnePc.ts b/packages/frontend/src/world/room/objects/allInOnePc.ts index e21988bdac..50f4848da7 100644 --- a/packages/frontend/src/world/room/objects/allInOnePc.ts +++ b/packages/frontend/src/world/room/objects/allInOnePc.ts @@ -48,18 +48,18 @@ export const allInOnePc = defineObject({ }, placement: 'top', hasTexture: true, - createInstance: async ({ room, scene, options, model, graphicsQuality }) => { + createInstance: async ({ lc, scene, options, model, graphicsQuality }) => { const matrix = model.root.getWorldMatrix(true); const scale = new BABYLON.Vector3(); matrix.decompose(scale); // TODO: graphicsQualityがLOWならそもそも追加しない - const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(30) / Math.abs(scale.y), 0), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, room?.lightContainer != null); + const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(30) / Math.abs(scale.y), 0), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, lc != null); light.parent = model.root; light.diffuse = new BABYLON.Color3(1.0, 1.0, 1.0); light.range = cm(100) * getLightRangeFactorByGraphicsQuality(graphicsQuality); light.radius = cm(20); - if (room?.lightContainer != null) room.lightContainer.addLight(light); + if (lc != null) lc.addLight(light); const screenMesh = model.findMesh('__X_SCREEN__'); @@ -142,6 +142,10 @@ export const allInOnePc = defineObject({ } }, interactions: {}, + dispose: () => { + light.dispose(); + if (lc != null) lc.removeLight(light); + }, }; }, }); diff --git a/packages/frontend/src/world/room/objects/beamLamp.ts b/packages/frontend/src/world/room/objects/beamLamp.ts index 47195b8e3a..610727c2ef 100644 --- a/packages/frontend/src/world/room/objects/beamLamp.ts +++ b/packages/frontend/src/world/room/objects/beamLamp.ts @@ -18,17 +18,22 @@ export const beamLamp = defineObject({ placement: 'top', hasCollisions: false, canPreMeshesMerging: true, - createInstance: ({ room, root, scene, graphicsQuality }) => { + createInstance: ({ lc, root, scene, graphicsQuality }) => { + const light = new BABYLON.PointLight('beamLampLight', new BABYLON.Vector3(0, cm(10), 0), scene, lc != null); + light.parent = root; + light.diffuse = new BABYLON.Color3(1.0, 0.5, 0.2); + light.intensity = 0.03 * WORLD_SCALE * WORLD_SCALE; + light.range = cm(100) * getLightRangeFactorByGraphicsQuality(graphicsQuality); + if (lc != null) lc.addLight(light); + return { onInited: () => { - const light = new BABYLON.PointLight('beamLampLight', new BABYLON.Vector3(0, cm(10), 0), scene, room?.lightContainer != null); - light.parent = root; - light.diffuse = new BABYLON.Color3(1.0, 0.5, 0.2); - light.intensity = 0.03 * WORLD_SCALE * WORLD_SCALE; - light.range = cm(100) * getLightRangeFactorByGraphicsQuality(graphicsQuality); - if (room?.lightContainer != null) room.lightContainer.addLight(light); }, interactions: {}, + dispose: () => { + light.dispose(); + if (lc != null) lc.removeLight(light); + }, }; }, }); diff --git a/packages/frontend/src/world/room/objects/desktopPc.ts b/packages/frontend/src/world/room/objects/desktopPc.ts index a3f79e98ef..5aec987b41 100644 --- a/packages/frontend/src/world/room/objects/desktopPc.ts +++ b/packages/frontend/src/world/room/objects/desktopPc.ts @@ -50,19 +50,19 @@ export const desktopPc = defineObject({ placement: 'top', hasCollisions: true, canPreMeshesMerging: true, - createInstance: ({ options, model, root, scene, room, graphicsQuality }) => { + createInstance: ({ options, model, root, scene, lc, graphicsQuality }) => { // TODO: graphicsQualityがLOWならそもそも追加しない - const light1 = new BABYLON.SpotLight('', new BABYLON.Vector3(0, cm(10), cm(22)), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, room?.lightContainer != null); + const light1 = new BABYLON.SpotLight('', new BABYLON.Vector3(0, cm(10), cm(22)), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, lc != null); light1.parent = root; light1.intensity = 0.05 * WORLD_SCALE * WORLD_SCALE; light1.range = cm(30) * getLightRangeFactorByGraphicsQuality(graphicsQuality); - if (room?.lightContainer != null) room.lightContainer.addLight(light1); + if (lc != null) lc.addLight(light1); - const light2 = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(-5), cm(33), cm(-9)), new BABYLON.Vector3(1, 0, 0), Math.PI / 1, 2, scene, room?.lightContainer != null); + const light2 = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(-5), cm(33), cm(-9)), new BABYLON.Vector3(1, 0, 0), Math.PI / 1, 2, scene, lc != null); light2.parent = root; light2.intensity = 0.05 * WORLD_SCALE * WORLD_SCALE; light2.range = cm(30) * getLightRangeFactorByGraphicsQuality(graphicsQuality); - if (room?.lightContainer != null) room.lightContainer.addLight(light2); + if (lc != null) lc.addLight(light2); const bodyMaterial = model.findMaterial('__X_BODY__'); const coverMaterial = model.findMaterial('__X_COVER__'); @@ -127,6 +127,14 @@ export const desktopPc = defineObject({ applyLedColor(); }, interactions: {}, + dispose: () => { + light1.dispose(); + light2.dispose(); + if (lc != null) { + lc.removeLight(light1); + lc.removeLight(light2); + } + }, }; }, }); diff --git a/packages/frontend/src/world/room/objects/ductRailSpotLights.ts b/packages/frontend/src/world/room/objects/ductRailSpotLights.ts index 9262dc743a..d6cadff39f 100644 --- a/packages/frontend/src/world/room/objects/ductRailSpotLights.ts +++ b/packages/frontend/src/world/room/objects/ductRailSpotLights.ts @@ -53,7 +53,7 @@ export const ductRailSpotLights = defineObject({ }, placement: 'ceiling', hasCollisions: false, - createInstance: ({ room, scene, options, model, graphicsQuality }) => { + createInstance: ({ lc, scene, options, model, graphicsQuality }) => { const bodyMaterial = model.findMaterial('__X_BODY__'); const applyBodyColor = () => { @@ -66,10 +66,10 @@ export const ductRailSpotLights = defineObject({ const lamps = model.findMeshes('__X_LAMP__'); const lights: BABYLON.SpotLight[] = []; for (const lamp of lamps) { - const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(0), 0), new BABYLON.Vector3(0, -1, 0), Math.PI / 1, 2, scene, room?.lightContainer != null); + const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(0), 0), new BABYLON.Vector3(0, -1, 0), Math.PI / 1, 2, scene, lc != null); light.parent = lamp; light.radius = cm(8); - if (room?.lightContainer != null) room.lightContainer.addLight(light); + if (lc != null) lc.addLight(light); lights.push(light); } @@ -126,6 +126,12 @@ export const ductRailSpotLights = defineObject({ } }, interactions: {}, + dispose: () => { + for (const light of lights) { + light.dispose(); + if (lc != null) lc.removeLight(light); + } + }, }; }, }); diff --git a/packages/frontend/src/world/room/objects/handheldGameConsole.ts b/packages/frontend/src/world/room/objects/handheldGameConsole.ts index 3e5cb3d663..5f686991e8 100644 --- a/packages/frontend/src/world/room/objects/handheldGameConsole.ts +++ b/packages/frontend/src/world/room/objects/handheldGameConsole.ts @@ -44,7 +44,7 @@ export const handheldGameConsole = defineObject({ placement: 'top', hasCollisions: false, hasTexture: true, - createInstance: async ({ room, scene, options, model, graphicsQuality }) => { + createInstance: async ({ scene, options, model, graphicsQuality }) => { const screenMesh = model.findMesh('__X_SCREEN__'); const bodyMaterial = model.findMaterial('__X_BODY__'); diff --git a/packages/frontend/src/world/room/objects/laptopPc.ts b/packages/frontend/src/world/room/objects/laptopPc.ts index 1a4bbfc29d..dd6e058406 100644 --- a/packages/frontend/src/world/room/objects/laptopPc.ts +++ b/packages/frontend/src/world/room/objects/laptopPc.ts @@ -57,7 +57,7 @@ export const laptopPc = defineObject({ placement: 'top', hasCollisions: false, hasTexture: true, - createInstance: async ({ room, scene, options, model, graphicsQuality }) => { + createInstance: async ({ lc, scene, options, model, graphicsQuality }) => { const matrix = model.root.getWorldMatrix(true); const scale = new BABYLON.Vector3(); matrix.decompose(scale); @@ -66,12 +66,12 @@ export const laptopPc = defineObject({ const hutaNode = model.findTransformNode('__X_HUTA__'); // TODO: graphicsQualityがLOWならそもそも追加しない - const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(10) / Math.abs(scale.y), 0), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, room?.lightContainer != null); + const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(10) / Math.abs(scale.y), 0), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, lc != null); light.parent = hutaNode; light.diffuse = new BABYLON.Color3(1.0, 1.0, 1.0); light.range = cm(100) * getLightRangeFactorByGraphicsQuality(graphicsQuality); light.radius = cm(15); - if (room?.lightContainer != null) room.lightContainer.addLight(light); + if (lc != null) lc.addLight(light); const bodyMaterial = model.findMaterial('__X_BODY__'); const bezelMaterial = model.findMaterial('__X_BEZEL__'); @@ -167,6 +167,10 @@ export const laptopPc = defineObject({ } }, interactions: {}, + dispose: () => { + light.dispose(); + if (lc != null) lc.removeLight(light); + }, }; }, }); diff --git a/packages/frontend/src/world/room/objects/largeMousepad.ts b/packages/frontend/src/world/room/objects/largeMousepad.ts index f7d1cbf048..142df23a1a 100644 --- a/packages/frontend/src/world/room/objects/largeMousepad.ts +++ b/packages/frontend/src/world/room/objects/largeMousepad.ts @@ -30,7 +30,7 @@ export const largeMousepad = defineObject({ placement: 'top', hasCollisions: false, hasTexture: true, - createInstance: async ({ room, scene, options, model }) => { + createInstance: async ({ scene, options, model }) => { const padMesh = model.findMesh('__X_PAD__'); const padMaterial = model.findMaterial('__X_PAD__'); diff --git a/packages/frontend/src/world/room/objects/lavaLamp.ts b/packages/frontend/src/world/room/objects/lavaLamp.ts index 8d5e244bfc..449b03f3f6 100644 --- a/packages/frontend/src/world/room/objects/lavaLamp.ts +++ b/packages/frontend/src/world/room/objects/lavaLamp.ts @@ -39,7 +39,7 @@ export const lavaLamp = defineObject({ placement: 'top', hasCollisions: false, canPreMeshesMerging: true, - createInstance: ({ options, room, scene, sr, root, model, graphicsQuality }) => { + createInstance: ({ options, lc, scene, sr, root, model, graphicsQuality }) => { const bodyMaterial = model.findMaterial('__X_BODY__'); const glassMaterial = model.findMaterial('__X_GLASS__'); const lightMaterial = model.findMaterial('__X_LIGHT__'); @@ -59,12 +59,12 @@ export const lavaLamp = defineObject({ applyGlassColor(); // TODO: graphicsQualityがLOWならそもそも追加しない - const light = new BABYLON.PointLight('lavaLampLight', new BABYLON.Vector3(0, cm(11), 0), scene, room?.lightContainer != null); + const light = new BABYLON.PointLight('lavaLampLight', new BABYLON.Vector3(0, cm(11), 0), scene, lc != null); light.parent = root; light.intensity = 0.03 * WORLD_SCALE * WORLD_SCALE; light.range = cm(50) * getLightRangeFactorByGraphicsQuality(graphicsQuality); light.radius = cm(5); - if (room?.lightContainer != null) room.lightContainer.addLight(light); + if (lc != null) lc.addLight(light); const applyLightColor = () => { const [r, g, b] = options.lightColor; @@ -155,9 +155,12 @@ export const lavaLamp = defineObject({ } }, dispose: () => { + light.dispose(); + if (lc != null) lc.removeLight(light); if (animationObserver != null) { scene.onAfterAnimationsObservable.remove(animationObserver); } + ps.dispose(); }, }; }, diff --git a/packages/frontend/src/world/room/objects/monitor.ts b/packages/frontend/src/world/room/objects/monitor.ts index 7be89b48d4..db26b9fa22 100644 --- a/packages/frontend/src/world/room/objects/monitor.ts +++ b/packages/frontend/src/world/room/objects/monitor.ts @@ -43,18 +43,18 @@ export const monitor = defineObject({ }, placement: 'top', hasTexture: true, - createInstance: async ({ room, scene, options, model, graphicsQuality }) => { + createInstance: async ({ lc, scene, options, model, graphicsQuality }) => { const matrix = model.root.getWorldMatrix(true); const scale = new BABYLON.Vector3(); matrix.decompose(scale); // TODO: graphicsQualityがLOWならそもそも追加しない - const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(20) / Math.abs(scale.y), 0), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, room?.lightContainer != null); + const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(20) / Math.abs(scale.y), 0), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, lc != null); light.parent = model.root; light.diffuse = new BABYLON.Color3(1.0, 1.0, 1.0); light.range = cm(100) * getLightRangeFactorByGraphicsQuality(graphicsQuality); light.radius = cm(20); - if (room?.lightContainer != null) room.lightContainer.addLight(light); + if (lc != null) lc.addLight(light); const screenMesh = model.findMesh('__X_SCREEN__'); @@ -130,6 +130,10 @@ export const monitor = defineObject({ } }, interactions: {}, + dispose: () => { + light.dispose(); + if (lc != null) lc.removeLight(light); + }, }; }, }); diff --git a/packages/frontend/src/world/room/objects/spotLight.ts b/packages/frontend/src/world/room/objects/spotLight.ts index 3021502350..67c2da0d5c 100644 --- a/packages/frontend/src/world/room/objects/spotLight.ts +++ b/packages/frontend/src/world/room/objects/spotLight.ts @@ -53,7 +53,7 @@ export const spotLight = defineObject({ }, placement: 'bottom', hasCollisions: false, - createInstance: ({ room, scene, options, model, graphicsQuality }) => { + createInstance: ({ lc, scene, options, model, graphicsQuality }) => { const bodyMaterial = model.findMaterial('__X_BODY__'); const applyBodyColor = () => { @@ -64,10 +64,10 @@ export const spotLight = defineObject({ applyBodyColor(); const lamp = model.findMesh('__X_LAMP__'); - const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(0), 0), new BABYLON.Vector3(0, -1, 0), Math.PI / 1, 2, scene, room?.lightContainer != null); + const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(0), 0), new BABYLON.Vector3(0, -1, 0), Math.PI / 1, 2, scene, lc != null); light.parent = lamp; light.radius = cm(8); - if (room?.lightContainer != null) room.lightContainer.addLight(light); + if (lc != null) lc.addLight(light); const applyLightColor = () => { const [r, g, b] = options.lightColor; @@ -112,6 +112,10 @@ export const spotLight = defineObject({ } }, interactions: {}, + dispose: () => { + light.dispose(); + if (lc != null) lc.removeLight(light); + }, }; }, }); diff --git a/packages/frontend/src/world/room/objects/tabletopDigitalClock.ts b/packages/frontend/src/world/room/objects/tabletopDigitalClock.ts index 5d58e14320..585310643e 100644 --- a/packages/frontend/src/world/room/objects/tabletopDigitalClock.ts +++ b/packages/frontend/src/world/room/objects/tabletopDigitalClock.ts @@ -40,11 +40,11 @@ export const tabletopDigitalClock = defineObject({ const scale = new BABYLON.Vector3(); matrix.decompose(scale); - //const light = new BABYLON.SpotLight('', new BABYLON.Vector3(0, cm(3), cm(1)), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, room?.lightContainer != null); + //const light = new BABYLON.SpotLight('', new BABYLON.Vector3(0, cm(3), cm(1)), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, lc != null); //light.parent = root; //light.intensity = 0.01 * WORLD_SCALE * WORLD_SCALE; //light.range = cm(30); - //if (room?.lightContainer != null) room.lightContainer.addLight(light); + //if (lc != null) lc.addLight(light); const segmentMeshes = { '1a': model.findMesh('__TIME_7SEG_1A__'), diff --git a/packages/frontend/src/world/room/objects/tv.ts b/packages/frontend/src/world/room/objects/tv.ts index 43688e9f86..8590da8f6a 100644 --- a/packages/frontend/src/world/room/objects/tv.ts +++ b/packages/frontend/src/world/room/objects/tv.ts @@ -33,17 +33,17 @@ export const tv = defineObject({ placement: 'top', hasCollisions: true, hasTexture: true, - createInstance: ({ options, room, model, scene, timer, graphicsQuality }) => { + createInstance: ({ options, lc, model, scene, timer, graphicsQuality }) => { const matrix = model.root.getWorldMatrix(true); const scale = new BABYLON.Vector3(); matrix.decompose(scale); - const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(30) / Math.abs(scale.y), 0), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, room?.lightContainer != null); + const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(30) / Math.abs(scale.y), 0), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, lc != null); light.parent = model.root; light.diffuse = new BABYLON.Color3(1.0, 1.0, 1.0); light.range = cm(200) * getLightRangeFactorByGraphicsQuality(graphicsQuality); light.radius = cm(40); - if (room?.lightContainer != null) room.lightContainer.addLight(light); + if (lc != null) lc.addLight(light); const screenMesh = model.findMesh('__TV_SCREEN__'); screenMesh.markVerticesDataAsUpdatable(BABYLON.VertexBuffer.UVKind, true); @@ -96,6 +96,10 @@ export const tv = defineObject({ } }, interactions: {}, + dispose: () => { + light.dispose(); + if (lc != null) lc.removeLight(light); + }, }; }, }); diff --git a/packages/frontend/src/world/room/objects/wallMountSpotLight.ts b/packages/frontend/src/world/room/objects/wallMountSpotLight.ts index 64277767d6..81288c73fe 100644 --- a/packages/frontend/src/world/room/objects/wallMountSpotLight.ts +++ b/packages/frontend/src/world/room/objects/wallMountSpotLight.ts @@ -55,7 +55,7 @@ export const wallMountSpotLight = defineObject({ hasCollisions: false, canPreMeshesMerging: false, hasTexture: false, - createInstance: ({ room, scene, options, model, graphicsQuality }) => { + createInstance: ({ lc, scene, options, model, graphicsQuality }) => { const bodyMesh = model.findMesh('__X_BODY__'); const bodyMaterial = model.findMaterial('__X_BODY__'); @@ -67,10 +67,10 @@ export const wallMountSpotLight = defineObject({ applyBodyColor(); const lamp = model.findMesh('__X_LAMP__'); - const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(0), 0), new BABYLON.Vector3(0, -1, 0), Math.PI / 1, 2, scene, room?.lightContainer != null); + const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(0), 0), new BABYLON.Vector3(0, -1, 0), Math.PI / 1, 2, scene, lc != null); light.parent = lamp; light.radius = cm(5); - if (room?.lightContainer != null) room.lightContainer.addLight(light); + if (lc != null) lc.addLight(light); const applyLightColor = () => { const [r, g, b] = options.lightColor; @@ -113,6 +113,10 @@ export const wallMountSpotLight = defineObject({ } }, interactions: {}, + dispose: () => { + light.dispose(); + if (lc != null) lc.removeLight(light); + }, }; }, }); diff --git a/packages/frontend/src/world/room/objects/woodRingFloorLamp.ts b/packages/frontend/src/world/room/objects/woodRingFloorLamp.ts index baca0198d7..946968a020 100644 --- a/packages/frontend/src/world/room/objects/woodRingFloorLamp.ts +++ b/packages/frontend/src/world/room/objects/woodRingFloorLamp.ts @@ -42,7 +42,7 @@ export const woodRingFloorLamp = defineObject({ }, placement: 'floor', hasCollisions: true, - createInstance: ({ room, scene, options, model, graphicsQuality }) => { + createInstance: ({ lc, scene, options, model, graphicsQuality }) => { const shadeMaterial = model.findMaterial('__X_SHADE__'); const applyShadeColor = () => { @@ -64,10 +64,10 @@ export const woodRingFloorLamp = defineObject({ const lamps = model.findMeshes('__X_LAMP__'); const lights: BABYLON.SpotLight[] = []; for (const lamp of lamps) { - const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(0), 0), new BABYLON.Vector3(0, -1, 0), Math.PI / 1, 2, scene, room?.lightContainer != null); + const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(0), 0), new BABYLON.Vector3(0, -1, 0), Math.PI / 1, 2, scene, lc != null); light.parent = lamp; light.radius = cm(5); - if (room?.lightContainer != null) room.lightContainer.addLight(light); + if (lc != null) lc.addLight(light); lights.push(light); } @@ -105,6 +105,12 @@ export const woodRingFloorLamp = defineObject({ applyLightBrightness(); }, interactions: {}, + dispose: () => { + for (const light of lights) { + light.dispose(); + if (lc != null) lc.removeLight(light); + } + } }; }, }); diff --git a/packages/frontend/src/world/room/objects/woodRingsPendantLight.ts b/packages/frontend/src/world/room/objects/woodRingsPendantLight.ts index 248fc70231..d6b695be4f 100644 --- a/packages/frontend/src/world/room/objects/woodRingsPendantLight.ts +++ b/packages/frontend/src/world/room/objects/woodRingsPendantLight.ts @@ -54,7 +54,7 @@ export const woodRingsPendantLight = defineObject({ }, placement: 'ceiling', hasCollisions: false, - createInstance: ({ room, scene, options, model, graphicsQuality }) => { + createInstance: ({ lc, scene, options, model, graphicsQuality }) => { const shadeMaterial = model.findMaterial('__X_SHADE__'); const applyShadeColor = () => { @@ -74,10 +74,10 @@ export const woodRingsPendantLight = defineObject({ applyBodyColor(); const lamp = model.findMesh('__X_LAMP__'); - const light = new BABYLON.PointLight('', new BABYLON.Vector3(0, 0, 0), scene, room?.lightContainer != null); + const light = new BABYLON.PointLight('', new BABYLON.Vector3(0, 0, 0), scene, lc != null); light.parent = lamp; light.radius = cm(5); - if (room?.lightContainer != null) room.lightContainer.addLight(light); + if (lc != null) lc.addLight(light); //const lensFlareSystem = new BABYLON.LensFlareSystem('lensFlareSystem', light, scene); //const flare00 = new BABYLON.LensFlare(0.1, 1.7, new BABYLON.Color3(...options.lightColor), '/client-assets/world/lensflare.png', lensFlareSystem); @@ -126,6 +126,10 @@ export const woodRingsPendantLight = defineObject({ } }, interactions: {}, + dispose: () => { + light.dispose(); + if (lc != null) lc.removeLight(light); + }, }; }, }); diff --git a/packages/frontend/src/world/room/previewEngine.ts b/packages/frontend/src/world/room/previewEngine.ts index e8550c67bb..fbaee90fd0 100644 --- a/packages/frontend/src/world/room/previewEngine.ts +++ b/packages/frontend/src/world/room/previewEngine.ts @@ -334,7 +334,6 @@ export class RoomObjectPreviewEngine { this.timerForEachObject = new Timer(); const objectInstance = await def.createInstance({ - room: null, scene: this.scene, sr: this.sr, root,