From 3b445af6fcdbd2606422bff1ce6db5bb8f4783f2 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 19 Aug 2019 15:51:00 +0900 Subject: [PATCH] Improve readability --- src/client/app/common/scripts/room/room.ts | 23 ++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/client/app/common/scripts/room/room.ts b/src/client/app/common/scripts/room/room.ts index da16b9a14b..a0f1b97223 100644 --- a/src/client/app/common/scripts/room/room.ts +++ b/src/client/app/common/scripts/room/room.ts @@ -343,7 +343,8 @@ export class Room { @autobind private loadRoom() { - new GLTFLoader().load(`/assets/room/rooms/${this.roomInfo.roomType}/${this.roomInfo.roomType}.glb`, gltf => { + const type = this.roomInfo.roomType; + new GLTFLoader().load(`/assets/room/rooms/${type}/${type}.glb`, gltf => { gltf.scene.traverse(child => { if (!(child instanceof THREE.Mesh)) return; @@ -429,8 +430,12 @@ export class Room { private applyCarpetColor() { this.roomObj.traverse(child => { if (!(child instanceof THREE.Mesh)) return; - if (child.material && (child.material as THREE.MeshStandardMaterial).name && (child.material as THREE.MeshStandardMaterial).name === 'Carpet') { - (child.material as THREE.MeshStandardMaterial).color.setHex(parseInt(this.roomInfo.carpetColor.substr(1), 16)); + if (child.material && + (child.material as THREE.MeshStandardMaterial).name && + (child.material as THREE.MeshStandardMaterial).name === 'Carpet' + ) { + const colorHex = parseInt(this.roomInfo.carpetColor.substr(1), 16); + (child.material as THREE.MeshStandardMaterial).color.setHex(colorHex); } }); } @@ -443,14 +448,18 @@ export class Room { model.traverse(child => { if (!(child instanceof THREE.Mesh)) return; for (const t of Object.keys(def.color)) { - if (!child.material || !(child.material as THREE.MeshStandardMaterial).name || (child.material as THREE.MeshStandardMaterial).name !== t) continue; + if (!child.material || + !(child.material as THREE.MeshStandardMaterial).name || + (child.material as THREE.MeshStandardMaterial).name !== t + ) continue; const prop = def.color[t]; const val = furniture.props ? furniture.props[prop] : undefined; if (val == null) continue; - (child.material as THREE.MeshStandardMaterial).color.setHex(parseInt(val.substr(1), 16)); + const colorHex = parseInt(val.substr(1), 16); + (child.material as THREE.MeshStandardMaterial).color.setHex(colorHex); } }); } @@ -487,7 +496,9 @@ export class Room { const uvInfo = def.texture[t].uv; const ctx = canvas.getContext('2d'); - ctx.drawImage(img, 0, 0, img.width, img.height, uvInfo.x, uvInfo.y, uvInfo.width, uvInfo.height); + ctx.drawImage(img, + 0, 0, img.width, img.height, + uvInfo.x, uvInfo.y, uvInfo.width, uvInfo.height); const texture = new THREE.Texture(canvas); texture.wrapS = THREE.RepeatWrapping;