From 3db0b8a1fdf92c6f43c43f62c4adab0d4e3f7673 Mon Sep 17 00:00:00 2001 From: syuilo <4439005+syuilo@users.noreply.github.com> Date: Wed, 15 Apr 2026 08:51:47 +0900 Subject: [PATCH] cm --- packages/frontend/src/utility/room/engine.ts | 132 +++++++++--------- .../src/utility/room/objects/allInOnePc.ts | 6 +- .../src/utility/room/objects/aquarium.ts | 11 +- .../src/utility/room/objects/beamLamp.ts | 5 +- .../src/utility/room/objects/blind.ts | 6 +- .../src/utility/room/objects/books.ts | 5 +- .../src/utility/room/objects/cupNoodle.ts | 4 +- .../src/utility/room/objects/desktopPc.ts | 9 +- .../src/utility/room/objects/laptopPc.ts | 6 +- .../src/utility/room/objects/lavaLamp.ts | 23 +-- .../frontend/src/utility/room/objects/mug.ts | 4 +- .../room/objects/tabletopDigitalClock.ts | 6 +- .../frontend/src/utility/room/objects/tv.ts | 6 +- .../utility/room/objects/woodRingFloorLamp.ts | 5 +- .../room/objects/woodRingsPendantLight.ts | 3 +- packages/frontend/src/utility/room/utility.ts | 11 +- 16 files changed, 126 insertions(+), 116 deletions(-) diff --git a/packages/frontend/src/utility/room/engine.ts b/packages/frontend/src/utility/room/engine.ts index 43abcb130d..05ff33475c 100644 --- a/packages/frontend/src/utility/room/engine.ts +++ b/packages/frontend/src/utility/room/engine.ts @@ -44,7 +44,7 @@ import { EventEmitter } from 'eventemitter3'; import { genId } from '../id.js'; import { deepClone } from '../clone.js'; import { getObjectDef } from './object-defs.js'; -import { HorizontalCameraKeyboardMoveInput, applyMorphTargetsToMesh, camelToKebab, findMaterial, scaleMorph } from './utility.js'; +import { HorizontalCameraKeyboardMoveInput, applyMorphTargetsToMesh, camelToKebab, cm, findMaterial, scaleMorph } from './utility.js'; const BAKE_TRANSFORM = false; // 実験的 const SNAPSHOT_RENDERING = false; // 実験的 @@ -498,7 +498,7 @@ export class RoomEngine extends EventEmitter { private roomCollisionMeshes: BABYLON.AbstractMesh[] = []; public roomState: RoomState; - private _gridSnapping = { enabled: true, scale: 4/*cm*/ }; + private _gridSnapping = { enabled: true, scale: cm(4) }; get gridSnapping() { return this._gridSnapping; } @@ -552,7 +552,7 @@ export class RoomEngine extends EventEmitter { //this.scene.autoClearDepthAndStencil = false; this.scene.skipPointerMovePicking = true; - const skybox = BABYLON.MeshBuilder.CreateBox('skybox', { size: 100000/*cm*/ }, this.scene); + const skybox = BABYLON.MeshBuilder.CreateBox('skybox', { size: cm(100000) }, this.scene); const skyboxMat = new BABYLON.StandardMaterial('skyboxMat', this.scene); skyboxMat.backFaceCulling = false; skyboxMat.disableLighting = true; @@ -571,41 +571,41 @@ export class RoomEngine extends EventEmitter { this.scene.ambientColor = new BABYLON.Color3(1.0, 0.9, 0.8); this.envMapIndoor = BABYLON.CubeTexture.CreateFromPrefilteredData('/client-assets/room/indoor.env', this.scene); - this.envMapIndoor.boundingBoxSize = new BABYLON.Vector3(500/*cm*/, 500/*cm*/, 500/*cm*/); + this.envMapIndoor.boundingBoxSize = new BABYLON.Vector3(cm(500), cm(500), cm(500)); this.envMapOutdoor = BABYLON.CubeTexture.CreateFromPrefilteredData(this.time === 2 ? '/client-assets/room/outdoor-night.env' : '/client-assets/room/outdoor-day.env', this.scene); this.envMapOutdoor.level = this.time === 0 ? 0.5 : this.time === 1 ? 0.3 : 0.1; this.scene.collisionsEnabled = true; - this.camera = new BABYLON.UniversalCamera('camera', new BABYLON.Vector3(0, 130/*cm*/, 0/*cm*/), this.scene); + this.camera = new BABYLON.UniversalCamera('camera', new BABYLON.Vector3(0, cm(130), cm(0)), this.scene); this.camera.inputs.removeByType('FreeCameraKeyboardMoveInput'); this.camera.inputs.add(new HorizontalCameraKeyboardMoveInput(this.camera, this.fps)); this.camera.attachControl(this.canvas); - this.camera.minZ = 1/*cm*/; - this.camera.maxZ = 100000/*cm*/; + this.camera.minZ = cm(1); + this.camera.maxZ = cm(100000); this.camera.fov = 1; - this.camera.ellipsoid = new BABYLON.Vector3(15/*cm*/, 65/*cm*/, 15/*cm*/); + this.camera.ellipsoid = new BABYLON.Vector3(cm(15), cm(65), cm(15)); this.camera.checkCollisions = true; this.camera.applyGravity = true; this.camera.needMoveForGravity = true; this.fixedCamera = new BABYLON.UniversalCamera('fixedCamera', new BABYLON.Vector3(0, 0, 0), this.scene); - this.fixedCamera.minZ = 1/*cm*/; - this.fixedCamera.maxZ = 100000/*cm*/; + this.fixedCamera.minZ = cm(1); + this.fixedCamera.maxZ = cm(100000); this.fixedCamera.fov = 1; this.fixedCamera.inputs.removeByType('FreeCameraKeyboardMoveInput'); this.fixedCamera.attachControl(this.canvas); - this.birdeyeCamera = new BABYLON.ArcRotateCamera('birdeyeCamera', -Math.PI / 2, Math.PI / 2.5, 300/*cm*/, new BABYLON.Vector3(0, 90/*cm*/, 0), this.scene); + this.birdeyeCamera = new BABYLON.ArcRotateCamera('birdeyeCamera', -Math.PI / 2, Math.PI / 2.5, cm(300), new BABYLON.Vector3(0, cm(90), 0), this.scene); this.birdeyeCamera.attachControl(this.canvas); - this.birdeyeCamera.minZ = 1/*cm*/; - this.birdeyeCamera.maxZ = 100000/*cm*/; + this.birdeyeCamera.minZ = cm(1); + this.birdeyeCamera.maxZ = cm(100000); this.birdeyeCamera.fov = 0.5; this.birdeyeCamera.lowerBetaLimit = 0; this.birdeyeCamera.upperBetaLimit = (Math.PI / 2) + 0.1; - this.birdeyeCamera.lowerRadiusLimit = 50/*cm*/; - this.birdeyeCamera.upperRadiusLimit = 1000/*cm*/; + this.birdeyeCamera.lowerRadiusLimit = cm(50); + this.birdeyeCamera.upperRadiusLimit = cm(1000); this.scene.activeCamera = this.camera; @@ -614,10 +614,10 @@ export class RoomEngine extends EventEmitter { ambientLight.intensity = 0.5; //ambientLight.intensity = 0; - this.roomLight = new BABYLON.SpotLight('roomLight', new BABYLON.Vector3(0, 249/*cm*/, 0), new BABYLON.Vector3(0, -1, 0), 16, 8, this.scene); + this.roomLight = new BABYLON.SpotLight('roomLight', new BABYLON.Vector3(0, cm(249), 0), new BABYLON.Vector3(0, -1, 0), 16, 8, this.scene); this.roomLight.diffuse = new BABYLON.Color3(1.0, 0.9, 0.8); - this.roomLight.shadowMinZ = 10/*cm*/; - this.roomLight.shadowMaxZ = 300/*cm*/; + this.roomLight.shadowMinZ = cm(10); + this.roomLight.shadowMaxZ = cm(300); this.shadowGeneratorForRoomLight = new BABYLON.ShadowGenerator(4096, this.roomLight); this.shadowGeneratorForRoomLight.forceBackFacesOnly = true; @@ -631,8 +631,8 @@ export class RoomEngine extends EventEmitter { sunLight.position = new BABYLON.Vector3(-20, 1000, 1000); sunLight.diffuse = this.time === 0 ? new BABYLON.Color3(1.0, 0.9, 0.8) : this.time === 1 ? new BABYLON.Color3(1.0, 0.8, 0.6) : new BABYLON.Color3(0.6, 0.8, 1.0); sunLight.intensity = this.time === 0 ? 3 : this.time === 1 ? 1 : 0.25; - sunLight.shadowMinZ = 1000/*cm*/; - sunLight.shadowMaxZ = 2000/*cm*/; + sunLight.shadowMinZ = cm(1000); + sunLight.shadowMaxZ = cm(2000); this.shadowGeneratorForSunLight = new BABYLON.ShadowGenerator(4096, sunLight); this.shadowGeneratorForSunLight.forceBackFacesOnly = true; @@ -683,7 +683,7 @@ export class RoomEngine extends EventEmitter { //const lensEffect = new BABYLON.LensRenderingPipeline('lens', { // edge_blur: 1.0, // distortion: 0.5, - // dof_focus_distance: 90/*cm*/, + // dof_focus_distance: cm(90), // dof_aperture: 6.0, // dof_pentagon: true, // dof_gain: 2.0, @@ -694,17 +694,17 @@ export class RoomEngine extends EventEmitter { this.putParticleSystem = new BABYLON.ParticleSystem('', 64, this.scene); this.putParticleSystem.particleTexture = new BABYLON.Texture('/client-assets/room/steam.png'); - this.putParticleSystem.createCylinderEmitter(5/*cm*/, 1/*cm*/, 5/*cm*/); - this.putParticleSystem.minEmitBox = new BABYLON.Vector3(-3/*cm*/, 0, -3/*cm*/); - this.putParticleSystem.maxEmitBox = new BABYLON.Vector3(3/*cm*/, 0, 3/*cm*/); + this.putParticleSystem.createCylinderEmitter(cm(5), cm(1), cm(5)); + this.putParticleSystem.minEmitBox = new BABYLON.Vector3(cm(-3), 0, cm(-3)); + this.putParticleSystem.maxEmitBox = new BABYLON.Vector3(cm(3), 0, cm(3)); this.putParticleSystem.minEmitPower = 700; this.putParticleSystem.maxEmitPower = 1000; this.putParticleSystem.addVelocityGradient(0, 1); this.putParticleSystem.addVelocityGradient(1, 0); this.putParticleSystem.minLifeTime = 0.2; this.putParticleSystem.maxLifeTime = 0.2; - this.putParticleSystem.minSize = 1/*cm*/; - this.putParticleSystem.maxSize = 4/*cm*/; + this.putParticleSystem.minSize = cm(1); + this.putParticleSystem.maxSize = cm(4); this.putParticleSystem.emitRate = 256; this.putParticleSystem.blendMode = BABYLON.ParticleSystem.BLENDMODE_ADD; this.putParticleSystem.color1 = new BABYLON.Color4(1, 1, 1, 0.3); @@ -722,19 +722,19 @@ export class RoomEngine extends EventEmitter { // gridMaterial.gridRatio = v; //}, { immediate: true }); - this.xGridPreviewPlane = BABYLON.MeshBuilder.CreatePlane('xGridPreviewPlane', { width: 1000/*cm*/, height: 1000/*cm*/ }, this.scene); + this.xGridPreviewPlane = BABYLON.MeshBuilder.CreatePlane('xGridPreviewPlane', { width: cm(1000), height: cm(1000) }, this.scene); this.xGridPreviewPlane.rotation = new BABYLON.Vector3(0, 0, Math.PI / 2); this.xGridPreviewPlane.material = gridMaterial; this.xGridPreviewPlane.isPickable = false; this.xGridPreviewPlane.isVisible = false; - this.yGridPreviewPlane = BABYLON.MeshBuilder.CreatePlane('yGridPreviewPlane', { width: 1000/*cm*/, height: 1000/*cm*/ }, this.scene); + this.yGridPreviewPlane = BABYLON.MeshBuilder.CreatePlane('yGridPreviewPlane', { width: cm(1000), height: cm(1000) }, this.scene); this.yGridPreviewPlane.rotation = new BABYLON.Vector3(Math.PI / 2, 0, 0); this.yGridPreviewPlane.material = gridMaterial; this.yGridPreviewPlane.isPickable = false; this.yGridPreviewPlane.isVisible = false; - this.zGridPreviewPlane = BABYLON.MeshBuilder.CreatePlane('zGridPreviewPlane', { width: 1000/*cm*/, height: 1000/*cm*/ }, this.scene); + this.zGridPreviewPlane = BABYLON.MeshBuilder.CreatePlane('zGridPreviewPlane', { width: cm(1000), height: cm(1000) }, this.scene); this.zGridPreviewPlane.material = gridMaterial; this.zGridPreviewPlane.isPickable = false; this.zGridPreviewPlane.isVisible = false; @@ -833,7 +833,7 @@ export class RoomEngine extends EventEmitter { options: o.options, }))); - //const sphere = BABYLON.MeshBuilder.CreateSphere('sphere', { diameter: 1/*cm*/ }, this.scene); + //const sphere = BABYLON.MeshBuilder.CreateSphere('sphere', { diameter: cm(1) }, this.scene); const frameInterval = 1000 / this.fps; let lastTime = performance.now(); @@ -920,7 +920,7 @@ export class RoomEngine extends EventEmitter { if (placement === 'side') { // 前方に向かってレイを飛ばす - const ray = new BABYLON.Ray(this.camera.position, dir, 1000/*cm*/); + const ray = new BABYLON.Ray(this.camera.position, dir, cm(1000)); const hit = this.scene.pickWithRay(ray, (m) => isCollisionTarget(m) && (m.name.includes('__ROOM_WALL__') || m.name.includes('__SIDE__'))); if (hit != null && hit.pickedPoint != null && hit.pickedMesh != null) { newPos.x = hit.pickedPoint.x; @@ -933,7 +933,7 @@ export class RoomEngine extends EventEmitter { } } else if (placement === 'wall') { // 前方に向かってレイを飛ばす - const ray = new BABYLON.Ray(this.camera.position, dir, 1000/*cm*/); + const ray = new BABYLON.Ray(this.camera.position, dir, cm(1000)); const hit = this.scene.pickWithRay(ray, (m) => isCollisionTarget(m) && (m.name.includes('__ROOM_WALL__'))); if (hit != null && hit.pickedPoint != null && hit.pickedMesh != null) { newPos.x = hit.pickedPoint.x; @@ -945,30 +945,30 @@ export class RoomEngine extends EventEmitter { } } else if (placement === 'bottom') { // 上に向かってレイを飛ばす - const ray = new BABYLON.Ray(newPos, new BABYLON.Vector3(0, 1, 0), 1000/*cm*/); + const ray = new BABYLON.Ray(newPos, new BABYLON.Vector3(0, 1, 0), cm(1000)); const hit = this.scene.pickWithRay(ray, (m) => isCollisionTarget(m) && (m.name.includes('__ROOM_CEILING__') || m.name.includes('__BOTTOM__'))); if (hit != null && hit.pickedPoint != null && hit.pickedMesh != null) { newPos.y = hit.pickedPoint.y; sticky = hit.pickedMesh.metadata?.objectId ?? null; } - if (newPos.y > 250/*cm*/) newPos.y = 250/*cm*/; + if (newPos.y > cm(250)) newPos.y = cm(250); } else if (placement === 'ceiling') { - newPos.y = 250/*cm*/; + newPos.y = cm(250); if (this.gridSnapping.enabled) { - this.yGridPreviewPlane.position = new BABYLON.Vector3(grabbing.mesh.position.x, 250/*cm*/ - 0.1/*cm*/, grabbing.mesh.position.z); + this.yGridPreviewPlane.position = new BABYLON.Vector3(grabbing.mesh.position.x, cm(250) - cm(0.1), grabbing.mesh.position.z); this.yGridPreviewPlane.isVisible = true; } } else if (placement === 'floor') { newPos.y = 0; if (this.gridSnapping.enabled) { - this.yGridPreviewPlane.position = new BABYLON.Vector3(grabbing.mesh.position.x, 0.1/*cm*/, grabbing.mesh.position.z); + this.yGridPreviewPlane.position = new BABYLON.Vector3(grabbing.mesh.position.x, cm(0.1), grabbing.mesh.position.z); this.yGridPreviewPlane.isVisible = true; } } else { // 下に向かってレイを飛ばす - const ray = new BABYLON.Ray(newPos, new BABYLON.Vector3(0, -1, 0), 1000/*cm*/); + const ray = new BABYLON.Ray(newPos, new BABYLON.Vector3(0, -1, 0), cm(1000)); const hit = this.scene.pickWithRay(ray, (m) => isCollisionTarget(m) && (m.name.includes('__ROOM_FLOOR__') || m.name.includes('__ROOM_TOP__') || m.name.includes('__TOP__'))); if (hit != null && hit.pickedPoint != null && hit.pickedMesh != null) { newPos.y = hit.pickedPoint.y; @@ -977,7 +977,7 @@ export class RoomEngine extends EventEmitter { if (newPos.y < 0) newPos.y = 0; if (this.gridSnapping.enabled) { - this.yGridPreviewPlane.position = new BABYLON.Vector3(grabbing.mesh.position.x, grabbing.mesh.position.y + 0.1/*cm*/, grabbing.mesh.position.z); + this.yGridPreviewPlane.position = new BABYLON.Vector3(grabbing.mesh.position.x, grabbing.mesh.position.y + cm(0.1), grabbing.mesh.position.z); this.yGridPreviewPlane.isVisible = true; } } @@ -989,7 +989,7 @@ export class RoomEngine extends EventEmitter { //const _dir = newPos.subtract(pos).normalize(); //for (let i = 0; i < grabbing.distance; i++) { // // posを1cmずつnewPosの方向に動かす - // pos.addInPlace(_dir.scale(1/*cm*/)); + // pos.addInPlace(_dir.scale(cm(1))); // // 前方に向かってレイを飛ばして衝突チェック // const ray = new BABYLON.Ray(this.camera.position, dir, i); // const hit = this.scene.pickWithRay(ray, (m) => isCollisionTarget(m)); @@ -1002,7 +1002,7 @@ export class RoomEngine extends EventEmitter { // grabbing.mesh.position = pos.clone(); //} - //const ray = new BABYLON.Ray(this.camera.position, this.camera.getDirection(BABYLON.Axis.Z), 1000/*cm*/); + //const ray = new BABYLON.Ray(this.camera.position, this.camera.getDirection(BABYLON.Axis.Z), cm(1000)); //const hit = this.scene.pickWithRay(ray, (m) => m.name.includes('__COLLISION_WALL__'))!; //if (hit.pickedMesh != null) { // const grabbingBox = this.grabbing.mesh.getBoundingInfo().boundingBox; @@ -1038,7 +1038,7 @@ export class RoomEngine extends EventEmitter { const envObj = await BABYLON.ImportMeshAsync('/client-assets/room/env.glb', this.scene); envObj.meshes[0].scaling = envObj.meshes[0].scaling.scale(WORLD_SCALE); envObj.meshes[0].bakeCurrentTransformIntoVertices(); - envObj.meshes[0].position = new BABYLON.Vector3(0, -900/*cm*/, 0); // 4階くらいの想定 + envObj.meshes[0].position = new BABYLON.Vector3(0, cm(-900), 0); // 4階くらいの想定 envObj.meshes[0].rotation = new BABYLON.Vector3(0, -Math.PI, 0); for (const mesh of envObj.meshes) { mesh.isPickable = false; @@ -1053,7 +1053,7 @@ export class RoomEngine extends EventEmitter { private async loadRoomModel() { //await BABYLON.InitializeCSG2Async(); - //const box = BABYLON.MeshBuilder.CreateBox('box', { size: 50/*cm*/ }, this.scene); + //const box = BABYLON.MeshBuilder.CreateBox('box', { size: cm(50) }, this.scene); //const boxCsg = BABYLON.CSG2.FromMesh(box); const meshes: BABYLON.Mesh[] = []; @@ -1069,14 +1069,14 @@ export class RoomEngine extends EventEmitter { ceilingResult.meshes[0].scaling = ceilingResult.meshes[0].scaling.scale(WORLD_SCALE); const ceilingRoot = new BABYLON.Mesh('ceiling', this.scene); ceilingRoot.addChild(ceilingResult.meshes[0]); - ceilingRoot.position = new BABYLON.Vector3(0, 250/*cm*/, 0); + ceilingRoot.position = new BABYLON.Vector3(0, cm(250), 0); meshes.push(ceilingRoot); const wallEResult = await BABYLON.ImportMeshAsync('/client-assets/room/rooms/default/300-wall.glb', this.scene); wallEResult.meshes[0].scaling = wallEResult.meshes[0].scaling.scale(WORLD_SCALE); const wallERoot = new BABYLON.Mesh('wallE', this.scene); wallERoot.addChild(wallEResult.meshes[0]); - wallERoot.position = new BABYLON.Vector3(-150/*cm*/, 0, 0); + wallERoot.position = new BABYLON.Vector3(cm(-150), 0, 0); wallERoot.rotation = new BABYLON.Vector3(0, Math.PI, 0); meshes.push(wallERoot); const wallEMaterial = findMaterial(wallEResult.meshes[0], '__X_WALL__'); @@ -1086,7 +1086,7 @@ export class RoomEngine extends EventEmitter { wallWResult.meshes[0].scaling = wallWResult.meshes[0].scaling.scale(WORLD_SCALE); const wallWRoot = new BABYLON.Mesh('wallW', this.scene); wallWRoot.addChild(wallWResult.meshes[0]); - wallWRoot.position = new BABYLON.Vector3(150/*cm*/, 0, 0); + wallWRoot.position = new BABYLON.Vector3(cm(150), 0, 0); meshes.push(wallWRoot); const wallWMaterial = findMaterial(wallWResult.meshes[0], '__X_WALL__'); wallWMaterial.albedoColor = new BABYLON.Color3(...this.roomState.heya.options.wallW.color); @@ -1095,7 +1095,7 @@ export class RoomEngine extends EventEmitter { wallNResult.meshes[0].scaling = wallNResult.meshes[0].scaling.scale(WORLD_SCALE); const wallNRoot = new BABYLON.Mesh('wallN', this.scene); wallNRoot.addChild(wallNResult.meshes[0]); - wallNRoot.position = new BABYLON.Vector3(0, 0, -150/*cm*/); + wallNRoot.position = new BABYLON.Vector3(0, 0, cm(-150)); wallNRoot.rotation = new BABYLON.Vector3(0, Math.PI / 2, 0); meshes.push(wallNRoot); const wallNMaterial = findMaterial(wallNResult.meshes[0], '__X_WALL__'); @@ -1105,7 +1105,7 @@ export class RoomEngine extends EventEmitter { wallSResult.meshes[0].scaling = wallSResult.meshes[0].scaling.scale(WORLD_SCALE); const wallSRoot = new BABYLON.Mesh('wallS', this.scene); wallSRoot.addChild(wallSResult.meshes[0]); - wallSRoot.position = new BABYLON.Vector3(0, 0, 150/*cm*/); + wallSRoot.position = new BABYLON.Vector3(0, 0, cm(150)); wallSRoot.rotation = new BABYLON.Vector3(0, -Math.PI / 2, 0); meshes.push(wallSRoot); const wallSMaterial = findMaterial(wallSResult.meshes[0], '__X_WALL__'); @@ -1451,7 +1451,7 @@ export class RoomEngine extends EventEmitter { if (placement === 'top') { // stickyな場合にsticky先とのレイの距離が0になりstickyされていない初期状態でgrabbingが始まってしまうのでちょっと浮かす - selectedObject.position.y += 1/*cm*/; + selectedObject.position.y += cm(1); } const distance = BABYLON.Vector3.Distance(this.camera.position, selectedObject.position); @@ -1582,7 +1582,7 @@ export class RoomEngine extends EventEmitter { public sitChair(objectId: string) { this.isSitting = true; this.fixedCamera.parent = this.objectMeshs.get(objectId); - this.fixedCamera.position = new BABYLON.Vector3(0, 120/*cm*/, 0); + this.fixedCamera.position = new BABYLON.Vector3(0, cm(120), 0); this.fixedCamera.rotation = new BABYLON.Vector3(0, 0, 0); this.scene.activeCamera = this.fixedCamera; this.selectObject(null); @@ -1661,7 +1661,7 @@ export class RoomEngine extends EventEmitter { this.selectObject(null); const dir = this.camera.getDirection(BABYLON.Axis.Z).scale(this.scene.useRightHandedSystem ? -1 : 1); - const distance = 50/*cm*/; + const distance = cm(50); const id = genId(); @@ -1845,7 +1845,7 @@ export class RoomEngine extends EventEmitter { public changeGrabbingDistance(delta: number) { if (this.grabbingCtx == null) return; this.grabbingCtx.distance -= delta; - if (this.grabbingCtx.distance < 5/*cm*/) this.grabbingCtx.distance = 5/*cm*/; + if (this.grabbingCtx.distance < cm(5)) this.grabbingCtx.distance = cm(5); } public changeGrabbingRotationY(delta: number) { @@ -1934,17 +1934,17 @@ export class RoomObjectPreviewEngine { this.scene.ambientColor = new BABYLON.Color3(1.0, 0.9, 0.8); this.envMapIndoor = BABYLON.CubeTexture.CreateFromPrefilteredData('/client-assets/room/indoor.env', this.scene); - this.envMapIndoor.boundingBoxSize = new BABYLON.Vector3(500/*cm*/, 500/*cm*/, 500/*cm*/); + this.envMapIndoor.boundingBoxSize = new BABYLON.Vector3(cm(500), cm(500), cm(500)); - this.camera = new BABYLON.ArcRotateCamera('camera', -Math.PI / 2, Math.PI / 2.5, 300/*cm*/, new BABYLON.Vector3(0, 90/*cm*/, 0), this.scene); + this.camera = new BABYLON.ArcRotateCamera('camera', -Math.PI / 2, Math.PI / 2.5, cm(300), new BABYLON.Vector3(0, cm(90), 0), this.scene); this.camera.attachControl(this.canvas); - this.camera.minZ = 1/*cm*/; - this.camera.maxZ = 100000/*cm*/; + this.camera.minZ = cm(1); + this.camera.maxZ = cm(100000); this.camera.fov = 0.5; this.camera.lowerBetaLimit = 0; this.camera.upperBetaLimit = (Math.PI / 2) + 0.1; - this.camera.lowerRadiusLimit = 50/*cm*/; - this.camera.upperRadiusLimit = 1000/*cm*/; + this.camera.lowerRadiusLimit = cm(50); + this.camera.upperRadiusLimit = cm(1000); this.camera.useAutoRotationBehavior = true; this.camera.autoRotationBehavior!.idleRotationSpeed = 0.3; //this.camera.mode = BABYLON.Camera.ORTHOGRAPHIC_CAMERA; @@ -1955,10 +1955,10 @@ export class RoomObjectPreviewEngine { ambientLight.intensity = 0.5; //ambientLight.intensity = 0; - this.roomLight = new BABYLON.SpotLight('roomLight', new BABYLON.Vector3(0, 249/*cm*/, 0), new BABYLON.Vector3(0, -1, 0), 16, 8, this.scene); + this.roomLight = new BABYLON.SpotLight('roomLight', new BABYLON.Vector3(0, cm(249), 0), new BABYLON.Vector3(0, -1, 0), 16, 8, this.scene); this.roomLight.diffuse = new BABYLON.Color3(1.0, 0.9, 0.8); - this.roomLight.shadowMinZ = 10/*cm*/; - this.roomLight.shadowMaxZ = 300/*cm*/; + this.roomLight.shadowMinZ = cm(10); + this.roomLight.shadowMaxZ = cm(300); this.shadowGenerator1 = new BABYLON.ShadowGenerator(4096, this.roomLight); this.shadowGenerator1.forceBackFacesOnly = true; @@ -1972,15 +1972,15 @@ export class RoomObjectPreviewEngine { gridMaterial.mainColor = new BABYLON.Color3(0, 0, 0); gridMaterial.minorUnitVisibility = 1; gridMaterial.opacity = 0.5; - gridMaterial.gridRatio = 10/*cm*/; + gridMaterial.gridRatio = cm(10); - //this.zGridPreviewPlane = BABYLON.MeshBuilder.CreatePlane('zGridPreviewPlane', { width: 1000/*cm*/, height: 1000/*cm*/ }, this.scene); + //this.zGridPreviewPlane = BABYLON.MeshBuilder.CreatePlane('zGridPreviewPlane', { width: cm(1000), height: cm(1000) }, this.scene); //this.zGridPreviewPlane.material = gridMaterial; //this.zGridPreviewPlane.rotation = new BABYLON.Vector3(Math.PI / 2, 0, 0); //this.scene.fogMode = BABYLON.Scene.FOGMODE_LINEAR; - //this.scene.fogStart = 100/*cm*/; - //this.scene.fogEnd = 110/*cm*/; + //this.scene.fogStart = cm(100); + //this.scene.fogEnd = cm(110); //this.scene.fogColor = new BABYLON.Color3(0.0, 0.0, 0.0); } @@ -2007,7 +2007,7 @@ export class RoomObjectPreviewEngine { } // reset camera rotation - this.camera.setPosition(new BABYLON.Vector3(0, 90/*cm*/, 300/*cm*/)); + this.camera.setPosition(new BABYLON.Vector3(0, cm(90), cm(300))); const def = getObjectDef(type); diff --git a/packages/frontend/src/utility/room/objects/allInOnePc.ts b/packages/frontend/src/utility/room/objects/allInOnePc.ts index 1f63f4e20f..47c167c3c3 100644 --- a/packages/frontend/src/utility/room/objects/allInOnePc.ts +++ b/packages/frontend/src/utility/room/objects/allInOnePc.ts @@ -5,7 +5,7 @@ import * as BABYLON from '@babylonjs/core'; import { defineObject } from '../engine.js'; -import { createPlaneUvMapper } from '../utility.js'; +import { cm, createPlaneUvMapper } from '../utility.js'; export const allInOnePc = defineObject({ id: 'allInOnePc', @@ -51,10 +51,10 @@ export const allInOnePc = defineObject({ const scale = new BABYLON.Vector3(); matrix.decompose(scale); - const light = new BABYLON.SpotLight('', new BABYLON.Vector3(0/*cm*/, 30/*cm*/ / 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, room?.lightContainer != null); light.parent = model.root; light.diffuse = new BABYLON.Color3(1.0, 1.0, 1.0); - light.range = 100/*cm*/; + light.range = cm(100); if (room?.lightContainer != null) room.lightContainer.addLight(light); const screenMesh = model.findMesh('__X_SCREEN__'); diff --git a/packages/frontend/src/utility/room/objects/aquarium.ts b/packages/frontend/src/utility/room/objects/aquarium.ts index 246fd549df..281b849edf 100644 --- a/packages/frontend/src/utility/room/objects/aquarium.ts +++ b/packages/frontend/src/utility/room/objects/aquarium.ts @@ -5,6 +5,7 @@ import * as BABYLON from '@babylonjs/core'; import { defineObject } from '../engine.js'; +import { cm } from '../utility.js'; export const aquarium = defineObject({ id: 'aquarium', @@ -26,19 +27,19 @@ export const aquarium = defineObject({ const emitter = new BABYLON.TransformNode('emitter', scene); emitter.parent = root; - emitter.position = new BABYLON.Vector3(17/*cm*/, 7/*cm*/, -9/*cm*/); + emitter.position = new BABYLON.Vector3(cm(17), cm(7), cm(-9)); const ps = new BABYLON.ParticleSystem('', 128, scene); ps.particleTexture = new BABYLON.Texture('/client-assets/room/objects/lava-lamp/bubble.png'); ps.emitter = emitter; ps.isLocal = true; - ps.minEmitBox = new BABYLON.Vector3(-2/*cm*/, 0, -2/*cm*/); - ps.maxEmitBox = new BABYLON.Vector3(2/*cm*/, 0, 2/*cm*/); + ps.minEmitBox = new BABYLON.Vector3(cm(-2), 0, cm(-2)); + ps.maxEmitBox = new BABYLON.Vector3(cm(2), 0, cm(2)); ps.minEmitPower = 40; ps.maxEmitPower = 60; ps.minLifeTime = 0.5; ps.maxLifeTime = 0.5; - ps.minSize = 0.1/*cm*/; - ps.maxSize = 1/*cm*/; + ps.minSize = cm(0.1); + ps.maxSize = cm(1); ps.direction1 = new BABYLON.Vector3(0, 1, 0); ps.direction2 = new BABYLON.Vector3(0, 1, 0); ps.noiseTexture = noiseTexture; diff --git a/packages/frontend/src/utility/room/objects/beamLamp.ts b/packages/frontend/src/utility/room/objects/beamLamp.ts index 121cf174f4..63ecd38f07 100644 --- a/packages/frontend/src/utility/room/objects/beamLamp.ts +++ b/packages/frontend/src/utility/room/objects/beamLamp.ts @@ -5,6 +5,7 @@ import * as BABYLON from '@babylonjs/core'; import { defineObject } from '../engine.js'; +import { cm } from '../utility.js'; export const beamLamp = defineObject({ id: 'beamLamp', @@ -18,11 +19,11 @@ export const beamLamp = defineObject({ createInstance: ({ room, root, scene }) => { return { onInited: () => { - const light = new BABYLON.PointLight('beamLampLight', new BABYLON.Vector3(0, 10/*cm*/, 0), scene, room?.lightContainer != null); + 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 = 300; - light.range = 100/*cm*/; + light.range = cm(100); if (room?.lightContainer != null) room.lightContainer.addLight(light); }, interactions: {}, diff --git a/packages/frontend/src/utility/room/objects/blind.ts b/packages/frontend/src/utility/room/objects/blind.ts index d5b3e2f6cc..7fd749d054 100644 --- a/packages/frontend/src/utility/room/objects/blind.ts +++ b/packages/frontend/src/utility/room/objects/blind.ts @@ -5,7 +5,7 @@ import * as BABYLON from '@babylonjs/core'; import { defineObject } from '../engine.js'; -import { createOverridedStates } from '../utility.js'; +import { cm, createOverridedStates } from '../utility.js'; export const blind = defineObject({ id: 'blind', @@ -65,9 +65,9 @@ export const blind = defineObject({ for (let i = 0; i < options.blades; i++) { const b = blade.clone('blade_' + i); // createInstanceを使いたいが、削除するときになぜかエラーになる if (i / options.blades < temp.open) { - b.position.y -= (i * 4/*cm*/) / Math.abs(scale.y); + b.position.y -= (i * cm(4)) / Math.abs(scale.y); } else { - b.position.y -= (((options.blades - 1) * temp.open * 4/*cm*/) + (i * 0.3/*cm*/)) / Math.abs(scale.y); + b.position.y -= (((options.blades - 1) * temp.open * cm(4)) + (i * cm(0.3))) / Math.abs(scale.y); } blades.push(b); } diff --git a/packages/frontend/src/utility/room/objects/books.ts b/packages/frontend/src/utility/room/objects/books.ts index 3c7aec76db..f8d41cfa06 100644 --- a/packages/frontend/src/utility/room/objects/books.ts +++ b/packages/frontend/src/utility/room/objects/books.ts @@ -5,6 +5,7 @@ import * as BABYLON from '@babylonjs/core'; import { defineObject } from '../engine.js'; +import { cm } from '../utility.js'; export const books = defineObject({ id: 'books', @@ -52,8 +53,8 @@ export const books = defineObject({ ]; for (const meshes of bookMeshes) { - const z = Math.random() * 0.005/*cm*/; - const y = Math.random() * 0.0025/*cm*/; + const z = Math.random() * cm(0.005); + const y = Math.random() * cm(0.0025); for (const mesh of meshes) { mesh.position.z -= z; mesh.position.y += y; diff --git a/packages/frontend/src/utility/room/objects/cupNoodle.ts b/packages/frontend/src/utility/room/objects/cupNoodle.ts index d45d70882c..16b4092590 100644 --- a/packages/frontend/src/utility/room/objects/cupNoodle.ts +++ b/packages/frontend/src/utility/room/objects/cupNoodle.ts @@ -5,7 +5,7 @@ import * as BABYLON from '@babylonjs/core'; import { defineObject } from '../engine.js'; -import { yuge } from '../utility.js'; +import { cm, yuge } from '../utility.js'; export const cupNoodle = defineObject({ id: 'cupNoodle', @@ -21,7 +21,7 @@ export const cupNoodle = defineObject({ return { onInited: () => { - yugeDispose = yuge(scene, root, new BABYLON.Vector3(0, 10/*cm*/, 0)); + yugeDispose = yuge(scene, root, new BABYLON.Vector3(0, cm(10), 0)); }, interactions: {}, dispose: () => { diff --git a/packages/frontend/src/utility/room/objects/desktopPc.ts b/packages/frontend/src/utility/room/objects/desktopPc.ts index 061783a726..e725c8b9e5 100644 --- a/packages/frontend/src/utility/room/objects/desktopPc.ts +++ b/packages/frontend/src/utility/room/objects/desktopPc.ts @@ -5,6 +5,7 @@ import * as BABYLON from '@babylonjs/core'; import { defineObject } from '../engine.js'; +import { cm } from '../utility.js'; export const desktopPc = defineObject({ id: 'desktopPc', @@ -47,16 +48,16 @@ export const desktopPc = defineObject({ }, placement: 'top', createInstance: ({ options, model, root, scene, room }) => { - const light1 = new BABYLON.SpotLight('', new BABYLON.Vector3(0, 10/*cm*/, 22/*cm*/), 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, room?.lightContainer != null); light1.parent = root; light1.intensity = 500; - light1.range = 30/*cm*/; + light1.range = cm(30); if (room?.lightContainer != null) room.lightContainer.addLight(light1); - const light2 = new BABYLON.SpotLight('', new BABYLON.Vector3(-5/*cm*/, 33/*cm*/, -9/*cm*/), 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, room?.lightContainer != null); light2.parent = root; light2.intensity = 500; - light2.range = 30/*cm*/; + light2.range = cm(30); if (room?.lightContainer != null) room.lightContainer.addLight(light2); const bodyMaterial = model.findMaterial('__X_BODY__'); diff --git a/packages/frontend/src/utility/room/objects/laptopPc.ts b/packages/frontend/src/utility/room/objects/laptopPc.ts index 21b697ef74..37fcbc6b02 100644 --- a/packages/frontend/src/utility/room/objects/laptopPc.ts +++ b/packages/frontend/src/utility/room/objects/laptopPc.ts @@ -5,7 +5,7 @@ import * as BABYLON from '@babylonjs/core'; import { defineObject } from '../engine.js'; -import { createPlaneUvMapper } from '../utility.js'; +import { cm, createPlaneUvMapper } from '../utility.js'; export const laptopPc = defineObject({ id: 'laptopPc', @@ -63,10 +63,10 @@ export const laptopPc = defineObject({ const screenMesh = model.findMesh('__X_SCREEN__'); const hutaNode = model.findTransformNode('__X_HUTA__'); - const light = new BABYLON.SpotLight('', new BABYLON.Vector3(0/*cm*/, 10/*cm*/ / 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, room?.lightContainer != null); light.parent = hutaNode; light.diffuse = new BABYLON.Color3(1.0, 1.0, 1.0); - light.range = 100/*cm*/; + light.range = cm(100); if (room?.lightContainer != null) room.lightContainer.addLight(light); const bodyMaterial = model.findMaterial('__X_BODY__'); diff --git a/packages/frontend/src/utility/room/objects/lavaLamp.ts b/packages/frontend/src/utility/room/objects/lavaLamp.ts index 9b1af76a92..ba59bc611b 100644 --- a/packages/frontend/src/utility/room/objects/lavaLamp.ts +++ b/packages/frontend/src/utility/room/objects/lavaLamp.ts @@ -4,6 +4,7 @@ */ import * as BABYLON from '@babylonjs/core'; import { defineObject } from '../engine.js'; +import { cm } from '../utility.js'; export const lavaLamp = defineObject({ id: 'lavaLamp', @@ -17,16 +18,16 @@ export const lavaLamp = defineObject({ createInstance: ({ room, scene, root }) => { return { onInited: () => { - const light = new BABYLON.PointLight('lavaLampLight', new BABYLON.Vector3(0, 11/*cm*/, 0), scene, room?.lightContainer != null); + const light = new BABYLON.PointLight('lavaLampLight', new BABYLON.Vector3(0, cm(11), 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*/; + light.range = cm(100); if (room?.lightContainer != null) room.lightContainer.addLight(light); - const sphere = BABYLON.MeshBuilder.CreateSphere('lavaLampLightSphere', { diameter: 4/*cm*/ }, scene); + const sphere = BABYLON.MeshBuilder.CreateSphere('lavaLampLightSphere', { diameter: cm(4) }, scene); sphere.parent = root; - sphere.position = new BABYLON.Vector3(0, 15/*cm*/, 0); + sphere.position = new BABYLON.Vector3(0, cm(15), 0); const mat = new BABYLON.StandardMaterial('lavaLampLightMat', scene); mat.emissiveColor = new BABYLON.Color3(1.0, 0.5, 0.2); @@ -36,27 +37,27 @@ export const lavaLamp = defineObject({ const anim = new BABYLON.Animation('lavaLampLightAnim', 'position.y', 60, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE); anim.setKeys([ - { frame: 0, value: 11/*cm*/ }, - { frame: 500, value: 38/*cm*/ }, + { frame: 0, value: cm(11) }, + { frame: 500, value: cm(38) }, ]); sphere.animations = [anim]; scene.beginAnimation(sphere, 0, 500, true); const emitter = new BABYLON.TransformNode('emitter', scene); emitter.parent = root; - emitter.position = new BABYLON.Vector3(0, 10/*cm*/, 0); + emitter.position = new BABYLON.Vector3(0, cm(10), 0); const ps = new BABYLON.ParticleSystem('', 32, scene); ps.particleTexture = new BABYLON.Texture('/client-assets/room/objects/lava-lamp/bubble.png'); ps.emitter = emitter; ps.isLocal = true; - ps.minEmitBox = new BABYLON.Vector3(-1/*cm*/, 0, -1/*cm*/); - ps.maxEmitBox = new BABYLON.Vector3(1/*cm*/, 0, 1/*cm*/); + ps.minEmitBox = new BABYLON.Vector3(cm(-1), 0, cm(-1)); + ps.maxEmitBox = new BABYLON.Vector3(cm(1), 0, cm(1)); ps.minEmitPower = 2; ps.maxEmitPower = 3; ps.minLifeTime = 9; ps.maxLifeTime = 9; - ps.minSize = 0.5/*cm*/; - ps.maxSize = 1/*cm*/; + ps.minSize = cm(0.5); + ps.maxSize = cm(1); ps.direction1 = new BABYLON.Vector3(0, 1, 0); ps.direction2 = new BABYLON.Vector3(0, 1, 0); ps.emitRate = 1; diff --git a/packages/frontend/src/utility/room/objects/mug.ts b/packages/frontend/src/utility/room/objects/mug.ts index 56d91a88c8..b3c3bc4d3e 100644 --- a/packages/frontend/src/utility/room/objects/mug.ts +++ b/packages/frontend/src/utility/room/objects/mug.ts @@ -5,7 +5,7 @@ import * as BABYLON from '@babylonjs/core'; import { defineObject } from '../engine.js'; -import { yuge } from '../utility.js'; +import { cm, yuge } from '../utility.js'; export const mug = defineObject({ id: 'mug', @@ -21,7 +21,7 @@ export const mug = defineObject({ return { onInited: () => { - yugeDispose = yuge(scene, root, new BABYLON.Vector3(0, 5/*cm*/, 0)); + yugeDispose = yuge(scene, root, new BABYLON.Vector3(0, cm(5), 0)); }, interactions: {}, dispose: () => { diff --git a/packages/frontend/src/utility/room/objects/tabletopDigitalClock.ts b/packages/frontend/src/utility/room/objects/tabletopDigitalClock.ts index 05ee12b9ef..e9488e31fc 100644 --- a/packages/frontend/src/utility/room/objects/tabletopDigitalClock.ts +++ b/packages/frontend/src/utility/room/objects/tabletopDigitalClock.ts @@ -5,7 +5,7 @@ import * as BABYLON from '@babylonjs/core'; import { defineObject } from '../engine.js'; -import { get7segMeshesOfCurrentTime } from '../utility.js'; +import { cm, get7segMeshesOfCurrentTime } from '../utility.js'; export const tabletopDigitalClock = defineObject({ id: 'tabletopDigitalClock', @@ -35,10 +35,10 @@ export const tabletopDigitalClock = defineObject({ placement: 'top', noCollisions: true, createInstance: ({ root, room, options, model, scene }) => { - const light = new BABYLON.SpotLight('', new BABYLON.Vector3(0, 3/*cm*/, 1/*cm*/), 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, room?.lightContainer != null); light.parent = root; light.intensity = 100; - light.range = 30/*cm*/; + light.range = cm(30); if (room?.lightContainer != null) room.lightContainer.addLight(light); const segmentMeshes = { diff --git a/packages/frontend/src/utility/room/objects/tv.ts b/packages/frontend/src/utility/room/objects/tv.ts index 7aaca4ee93..62f724d84b 100644 --- a/packages/frontend/src/utility/room/objects/tv.ts +++ b/packages/frontend/src/utility/room/objects/tv.ts @@ -5,7 +5,7 @@ import * as BABYLON from '@babylonjs/core'; import { defineObject } from '../engine.js'; -import { createPlaneUvMapper, initTv } from '../utility.js'; +import { cm, createPlaneUvMapper, initTv } from '../utility.js'; export const tv = defineObject({ id: 'tv', @@ -35,10 +35,10 @@ export const tv = defineObject({ const scale = new BABYLON.Vector3(); matrix.decompose(scale); - const light = new BABYLON.SpotLight('', new BABYLON.Vector3(0/*cm*/, 30/*cm*/ / 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, room?.lightContainer != null); light.parent = model.root; light.diffuse = new BABYLON.Color3(1.0, 1.0, 1.0); - light.range = 150/*cm*/; + light.range = cm(150); if (room?.lightContainer != null) room.lightContainer.addLight(light); const screenMesh = model.findMesh('__TV_SCREEN__'); diff --git a/packages/frontend/src/utility/room/objects/woodRingFloorLamp.ts b/packages/frontend/src/utility/room/objects/woodRingFloorLamp.ts index 233664020c..4f176394f4 100644 --- a/packages/frontend/src/utility/room/objects/woodRingFloorLamp.ts +++ b/packages/frontend/src/utility/room/objects/woodRingFloorLamp.ts @@ -5,6 +5,7 @@ import * as BABYLON from '@babylonjs/core'; import { defineObject } from '../engine.js'; +import { cm } from '../utility.js'; export const woodRingFloorLamp = defineObject({ id: 'woodRingFloorLamp', @@ -61,7 +62,7 @@ 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(0/*cm*/, 0/*cm*/, 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, room?.lightContainer != null); light.parent = lamp; if (room?.lightContainer != null) room.lightContainer.addLight(light); lights.push(light); @@ -83,7 +84,7 @@ export const woodRingFloorLamp = defineObject({ const applyLightBrightness = () => { for (const light of lights) { light.intensity = 10000 * options.lightBrightness; - light.range = 200/*cm*/ * options.lightBrightness; + light.range = cm(200) * options.lightBrightness; } for (const lamp of lamps) { const emissive = lamp.material as BABYLON.PBRMaterial; diff --git a/packages/frontend/src/utility/room/objects/woodRingsPendantLight.ts b/packages/frontend/src/utility/room/objects/woodRingsPendantLight.ts index f6ea433d50..07f127925d 100644 --- a/packages/frontend/src/utility/room/objects/woodRingsPendantLight.ts +++ b/packages/frontend/src/utility/room/objects/woodRingsPendantLight.ts @@ -5,6 +5,7 @@ import * as BABYLON from '@babylonjs/core'; import { defineObject, WORLD_SCALE } from '../engine.js'; +import { cm } from '../utility.js'; const remap = (value: number, fromMin: number, fromMax: number, toMin: number, toMax: number) => { return toMin + ((value - fromMin) / (fromMax - fromMin)) * (toMax - toMin); @@ -87,7 +88,7 @@ export const woodRingsPendantLight = defineObject({ const applyLightBrightness = () => { light.intensity = 10000 * options.lightBrightness; - light.range = 200/*cm*/ * options.lightBrightness; + light.range = cm(200) * options.lightBrightness; const emissive = lamp.material as BABYLON.PBRMaterial; emissive.emissiveIntensity = options.lightBrightness * 10; }; diff --git a/packages/frontend/src/utility/room/utility.ts b/packages/frontend/src/utility/room/utility.ts index cc298e84d6..a2a03d4787 100644 --- a/packages/frontend/src/utility/room/utility.ts +++ b/packages/frontend/src/utility/room/utility.ts @@ -6,6 +6,9 @@ import * as BABYLON from '@babylonjs/core'; import type { RoomEngine } from './engine.js'; +//export const cm = (value: number) => value / 100; +export const cm = (value: number) => value; + export function yuge(scene: BABYLON.Scene, mesh: BABYLON.Mesh, offset: BABYLON.Vector3) { const emitter = new BABYLON.TransformNode('emitter', scene); emitter.parent = mesh; @@ -13,14 +16,14 @@ export function yuge(scene: BABYLON.Scene, mesh: BABYLON.Mesh, offset: BABYLON.V const ps = new BABYLON.ParticleSystem('steamParticleSystem', 8, scene); ps.particleTexture = new BABYLON.Texture('/client-assets/room/steam.png'); ps.emitter = emitter; - ps.minEmitBox = new BABYLON.Vector3(-1/*cm*/, 0, -1/*cm*/); - ps.maxEmitBox = new BABYLON.Vector3(1/*cm*/, 0, 1/*cm*/); + ps.minEmitBox = new BABYLON.Vector3(cm(-1), 0, cm(-1)); + ps.maxEmitBox = new BABYLON.Vector3(cm(1), 0, cm(1)); ps.minEmitPower = 10; ps.maxEmitPower = 12; ps.minLifeTime = 2; ps.maxLifeTime = 3; - ps.addSizeGradient(0, 10/*cm*/, 12/*cm*/); - ps.addSizeGradient(1, 18/*cm*/, 20/*cm*/); + ps.addSizeGradient(0, cm(10), cm(12)); + ps.addSizeGradient(1, cm(18), cm(20)); ps.direction1 = new BABYLON.Vector3(-0.3, 1, 0.3); ps.direction2 = new BABYLON.Vector3(0.3, 1, -0.3); ps.emitRate = 0.5;