From df5df25c80ab9f8660c44f43d2da32dd227a1318 Mon Sep 17 00:00:00 2001 From: syuilo <4439005+syuilo@users.noreply.github.com> Date: Sat, 4 Apr 2026 20:55:48 +0900 Subject: [PATCH] wip --- packages/frontend/src/utility/room/engine.ts | 82 +++++++++---------- .../src/utility/room/objects/beamLamp.ts | 4 +- .../src/utility/room/objects/lavaLamp.ts | 4 +- .../utility/room/objects/woodRingFloorLamp.ts | 4 +- 4 files changed, 44 insertions(+), 50 deletions(-) diff --git a/packages/frontend/src/utility/room/engine.ts b/packages/frontend/src/utility/room/engine.ts index c1db88415e..a4fc2fc9bd 100644 --- a/packages/frontend/src/utility/room/engine.ts +++ b/packages/frontend/src/utility/room/engine.ts @@ -1616,61 +1616,55 @@ export class RoomObjectPreviewEngine { def.treatLoaderResult?.(loaderResult); - let hasCollisionMesh = false; - for (const mesh of loaderResult.meshes) { - if (mesh.name.includes('__COLLISION__')) { - hasCollisionMesh = true; - break; - } - } - root.addChild(subRoot); + const model = new ModelManager(subRoot, loaderResult.meshes.filter(m => m !== subRoot), (meshes) => { + for (const m of meshes) { + const mesh = m; + + // シェイプキー(morph)を考慮してbounding boxを更新するために必要 + mesh.refreshBoundingInfo({ applyMorph: true }); + + if (mesh.name.includes('__COLLISION__')) { + mesh.receiveShadows = false; + mesh.isVisible = false; + mesh.checkCollisions = true; + } else if (mesh.name.includes('__TOP__') || mesh.name.includes('__SIDE__')) { + mesh.receiveShadows = false; + mesh.isVisible = false; + } else { + if (def.receiveShadows !== false) mesh.receiveShadows = true; + if (def.castShadows !== false) { + this.shadowGenerator1.addShadowCaster(mesh); + } + + if (mesh.material) { + if (mesh.material instanceof BABYLON.MultiMaterial) { + for (const subMat of mesh.material.subMaterials) { + (subMat as BABYLON.PBRMaterial).reflectionTexture = this.envMapIndoor; + } + } else { + (mesh.material as BABYLON.PBRMaterial).reflectionTexture = this.envMapIndoor; + } + } + } + + if (!this.scene.meshes.includes(mesh)) this.scene.addMesh(mesh); + } + }); + const objectInstance = await def.createInstance({ room: null, scene: this.scene, root, options: args.options, - model: new ModelManager(subRoot, loaderResult.meshes.filter(m => m !== subRoot), (meshes) => { - for (const m of meshes) { - const mesh = m; - - // シェイプキー(morph)を考慮してbounding boxを更新するために必要 - mesh.refreshBoundingInfo({ applyMorph: true }); - - mesh.checkCollisions = !hasCollisionMesh; - - if (mesh.name.includes('__COLLISION__')) { - mesh.receiveShadows = false; - mesh.isVisible = false; - mesh.checkCollisions = true; - } else if (mesh.name.includes('__TOP__') || mesh.name.includes('__SIDE__')) { - mesh.receiveShadows = false; - mesh.isVisible = false; - } else { - if (def.receiveShadows !== false) mesh.receiveShadows = true; - if (def.castShadows !== false) { - this.shadowGenerator1.addShadowCaster(mesh); - } - - if (mesh.material) { - if (mesh.material instanceof BABYLON.MultiMaterial) { - for (const subMat of mesh.material.subMaterials) { - (subMat as BABYLON.PBRMaterial).reflectionTexture = this.envMapIndoor; - } - } else { - (mesh.material as BABYLON.PBRMaterial).reflectionTexture = this.envMapIndoor; - } - } - } - - if (!this.scene.meshes.includes(mesh)) this.scene.addMesh(mesh); - } - }), + model, }); objectInstance.onInited?.(); + model.bakeMesh(); + this.objectInstance = objectInstance; this.objectMesh = root; } diff --git a/packages/frontend/src/utility/room/objects/beamLamp.ts b/packages/frontend/src/utility/room/objects/beamLamp.ts index 56fc47eb8b..172cb37388 100644 --- a/packages/frontend/src/utility/room/objects/beamLamp.ts +++ b/packages/frontend/src/utility/room/objects/beamLamp.ts @@ -17,12 +17,12 @@ export const beamLamp = defineObject({ createInstance: ({ room, root, scene }) => { return { onInited: () => { - const light = new BABYLON.PointLight('beamLampLight', new BABYLON.Vector3(0, 10/*cm*/, 0), scene, true); + const light = new BABYLON.PointLight('beamLampLight', new BABYLON.Vector3(0, 10/*cm*/, 0), scene, room?.lightContainer != null); light.parent = root; light.diffuse = new BABYLON.Color3(1.0, 0.5, 0.2); light.intensity = 300; light.range = 100/*cm*/; - room.lightContainer.addLight(light); + if (room?.lightContainer != null) room.lightContainer.addLight(light); }, interactions: {}, }; diff --git a/packages/frontend/src/utility/room/objects/lavaLamp.ts b/packages/frontend/src/utility/room/objects/lavaLamp.ts index 121a8fa334..72cfd5857a 100644 --- a/packages/frontend/src/utility/room/objects/lavaLamp.ts +++ b/packages/frontend/src/utility/room/objects/lavaLamp.ts @@ -16,12 +16,12 @@ export const lavaLamp = defineObject({ createInstance: ({ room, scene, root }) => { return { onInited: () => { - const light = new BABYLON.PointLight('lavaLampLight', new BABYLON.Vector3(0, 11/*cm*/, 0), scene, true); + const light = new BABYLON.PointLight('lavaLampLight', new BABYLON.Vector3(0, 11/*cm*/, 0), scene, room?.lightContainer != null); light.parent = root; light.diffuse = new BABYLON.Color3(1.0, 0.5, 0.2); light.intensity = 300; light.range = 100/*cm*/; - room.lightContainer.addLight(light); + if (room?.lightContainer != null) room.lightContainer.addLight(light); const sphere = BABYLON.MeshBuilder.CreateSphere('lavaLampLightSphere', { diameter: 4/*cm*/ }, scene); sphere.parent = root; diff --git a/packages/frontend/src/utility/room/objects/woodRingFloorLamp.ts b/packages/frontend/src/utility/room/objects/woodRingFloorLamp.ts index de193a2376..b9761ff13f 100644 --- a/packages/frontend/src/utility/room/objects/woodRingFloorLamp.ts +++ b/packages/frontend/src/utility/room/objects/woodRingFloorLamp.ts @@ -47,12 +47,12 @@ export const woodRingFloorLamp = defineObject({ const lamps = model.findMeshes('__X_LAMP__'); for (const lamp of lamps) { - const light = new BABYLON.SpotLight('', new BABYLON.Vector3(0/*cm*/, 0/*cm*/, 0), new BABYLON.Vector3(0, -1, 0), Math.PI / 1, 2, scene, true); + const light = new BABYLON.SpotLight('', new BABYLON.Vector3(0/*cm*/, 0/*cm*/, 0), new BABYLON.Vector3(0, -1, 0), Math.PI / 1, 2, scene, room?.lightContainer != null); light.parent = lamp; light.diffuse = new BABYLON.Color3(1.0, 0.5, 0.2); light.intensity = 5000; light.range = 150/*cm*/; - room.lightContainer.addLight(light); + if (room?.lightContainer != null) room.lightContainer.addLight(light); } return {