diff --git a/packages/frontend-misskey-world-engine/src/room/envs/simple.ts b/packages/frontend-misskey-world-engine/src/room/envs/simple.ts index bdec8f45e8..4142f3518f 100644 --- a/packages/frontend-misskey-world-engine/src/room/envs/simple.ts +++ b/packages/frontend-misskey-world-engine/src/room/envs/simple.ts @@ -21,6 +21,7 @@ export class SimpleEnvManager extends EnvManager { private wallMaterials: Record<'zPositive' | 'zNegative' | 'xPositive' | 'xNegative', BABYLON.PBRMaterial>; private wallBeamMaterials: Record<'zPositive' | 'zNegative' | 'xPositive' | 'xNegative', BABYLON.PBRMaterial>; private pillarRoots: Record<'zp_xp' | 'zp_xn' | 'zn_xp' | 'zn_xn', BABYLON.TransformNode>; + private pillarScalingContainers: Record<'zp_xp' | 'zp_xn' | 'zn_xp' | 'zn_xn', BABYLON.TransformNode>; private pillarMaterials: Record<'zp_xp' | 'zp_xn' | 'zn_xp' | 'zn_xn', BABYLON.PBRMaterial>; private ceilingMaterial: BABYLON.PBRMaterial; private floorMaterial: BABYLON.PBRMaterial; @@ -71,8 +72,28 @@ export class SimpleEnvManager extends EnvManager { zn_xp: new BABYLON.TransformNode('pillarRootZnXp', this.engine.scene), zn_xn: new BABYLON.TransformNode('pillarRootZnXn', this.engine.scene), }; - for (const v of Object.values(this.pillarRoots)) { - v.parent = this.rootNode; + this.pillarRoots.zp_xp.parent = this.rootNode; + this.pillarRoots.zp_xp.position = new BABYLON.Vector3(cm(150), 0, cm(150)); + this.pillarRoots.zp_xp.rotation.y = -Math.PI / 2; + this.pillarRoots.zp_xn.parent = this.rootNode; + this.pillarRoots.zp_xn.position = new BABYLON.Vector3(-cm(150), 0, cm(150)); + this.pillarRoots.zp_xn.rotation.y = Math.PI; + this.pillarRoots.zn_xp.parent = this.rootNode; + this.pillarRoots.zn_xp.position = new BABYLON.Vector3(cm(150), 0, -cm(150)); + this.pillarRoots.zn_xp.rotation.y = 0; + this.pillarRoots.zn_xn.parent = this.rootNode; + this.pillarRoots.zn_xn.position = new BABYLON.Vector3(-cm(150), 0, -cm(150)); + this.pillarRoots.zn_xn.rotation.y = Math.PI / 2; + + this.pillarScalingContainers = { + zp_xp: new BABYLON.TransformNode('pillarScalingContainerZpXp', this.engine.scene), + zp_xn: new BABYLON.TransformNode('pillarScalingContainerZpXn', this.engine.scene), + zn_xp: new BABYLON.TransformNode('pillarScalingContainerZnXp', this.engine.scene), + zn_xn: new BABYLON.TransformNode('pillarScalingContainerZnXn', this.engine.scene), + }; + for (const [k, v] of Object.entries(this.pillarScalingContainers)) { + v.parent = this.pillarRoots[k as keyof typeof this.pillarRoots]; + v.scaling = new BABYLON.Vector3(-WORLD_SCALE, WORLD_SCALE, WORLD_SCALE); } const wallMaterial = new BABYLON.PBRMaterial('wallMaterial', this.engine.scene); @@ -213,6 +234,14 @@ export class SimpleEnvManager extends EnvManager { this.removeShadowCaster(mesh); } } + for (const type of ['zp_xp', 'zp_xn', 'zn_xp', 'zn_xn'] as const) { + const pillarRoot = this.pillarScalingContainers[type]; + for (const mesh of pillarRoot.getChildMeshes()) { + mesh.dispose(); + this.engine.scene.removeMesh(mesh); + this.removeShadowCaster(mesh); + } + } // TODO: 返り値をpromiseにしてちゃんとテクスチャが読み終わってからresolveする @@ -293,7 +322,7 @@ export class SimpleEnvManager extends EnvManager { } for (const type of ['zp_xp', 'zp_xn', 'zn_xp', 'zn_xn'] as const) { - const pillarRoot = this.pillarRoots[type]; + const pillarRoot = this.pillarScalingContainers[type]; const pillarOptions = options.pillars[type]; let isEnabled = pillarOptions.show; @@ -309,25 +338,38 @@ export class SimpleEnvManager extends EnvManager { isEnabled = options.walls.zNegative.withBeam && options.walls.xNegative.withBeam; } } - pillarRoot.setEnabled(isEnabled); + if (!isEnabled) continue; - const targetMaterial = this.pillarMaterials[type]; - - targetMaterial.unfreeze(); - targetMaterial.albedoColor = new BABYLON.Color3(...pillarOptions.color); - - const texPath = pillarOptions.material === 'wood' ? '/client-assets/room/textures/wall-wood2.png' - : pillarOptions.material === 'concrete' ? '/client-assets/room/textures/concrete1.png' - : null; - - if (texPath != null) { - const tex = new BABYLON.Texture(texPath, this.engine.scene, false, false); - targetMaterial.albedoTexture = tex; - } else { - targetMaterial.albedoTexture = null; + const originalRoot = this.loaderResult!.transformNodes.find(t => t.name.includes('__PILLAR__'))!; + for (const child of treeClone(originalRoot).getChildren()) { + child.parent = pillarRoot; } - targetMaterial.freeze(); + for (const child of pillarRoot.getChildMeshes()) { + if (child.material.name.includes('__PILLAR__')) { + child.material = this.pillarMaterials[type]; + } + } + + { + const targetMaterial = this.pillarMaterials[type]; + + targetMaterial.unfreeze(); + targetMaterial.albedoColor = new BABYLON.Color3(...pillarOptions.color); + + const texPath = pillarOptions.material === 'wood' ? '/client-assets/room/textures/wall-wood2.png' + : pillarOptions.material === 'concrete' ? '/client-assets/room/textures/concrete1.png' + : null; + + if (texPath != null) { + const tex = new BABYLON.Texture(texPath, this.engine.scene, false, false); + targetMaterial.albedoTexture = tex; + } else { + targetMaterial.albedoTexture = null; + } + + targetMaterial.freeze(); + } } { diff --git a/packages/frontend/assets/room/envs/simple/300.glb b/packages/frontend/assets/room/envs/simple/300.glb index f157cac65a..5fa8d969ce 100644 Binary files a/packages/frontend/assets/room/envs/simple/300.glb and b/packages/frontend/assets/room/envs/simple/300.glb differ diff --git a/packages/frontend/assets/room/envs/simple/simple.blend b/packages/frontend/assets/room/envs/simple/simple.blend index 58b94ab3dd..8bc8403189 100644 Binary files a/packages/frontend/assets/room/envs/simple/simple.blend and b/packages/frontend/assets/room/envs/simple/simple.blend differ