diff --git a/script.js b/script.js index bbb492a..9e90156 100644 --- a/script.js +++ b/script.js @@ -27,6 +27,17 @@ function animate() { animate(); +function setPosition(mesh, x, y, z, w, h, d) { + // position sets the *center* position + // our coordinates are top/left/bottom + let meshX = x - w/2 + let meshY = y - h/2 + let meshZ = z - d/2 + mesh.position.x = meshX + mesh.position.y = meshY + mesh.position.z = meshZ +} + function configureScene(data) { // Add geometry for the rooms for (var room of data.rooms) { @@ -34,8 +45,7 @@ function configureScene(data) { let roomColor = new THREE.Color(room.color) let roomMaterial = new THREE.MeshPhysicalMaterial({ color: roomColor }) let roomMesh = new THREE.Mesh(roomGeo, roomMaterial) - roomMesh.position.x = room.x - roomMesh.position.y = room.y + setPosition(roomMesh, room.x, room.y, room.z || 0, room.w, room.h, room.d) roomMesh.userData = room.name home.add(roomMesh) }