Browse Source

add a group for room stuff

master
Peter Hajas 3 years ago
parent
commit
822e93c457
  1. 14
      script.js

14
script.js

@ -10,7 +10,7 @@ renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement ); document.body.appendChild( renderer.domElement );
const light = new THREE.AmbientLight(0xFFAAAA, 1) const light = new THREE.AmbientLight(0xFFAAAA, 1)
light.position.z = 100 // light.position.z = 100
scene.add(light) scene.add(light)
// back the camera up // back the camera up
@ -28,7 +28,7 @@ function animate() {
homeContainer.rotation.z += 0.005; homeContainer.rotation.z += 0.005;
renderer.render( scene, camera ); renderer.render( scene, camera );
}; }
animate(); animate();
@ -52,13 +52,17 @@ function configureScene(data) {
// Add geometry for the rooms // Add geometry for the rooms
for (var room of data.rooms) { for (var room of data.rooms) {
let roomContainer = new THREE.Group()
let roomGeo = new THREE.BoxGeometry(room.w, room.h, room.d) let roomGeo = new THREE.BoxGeometry(room.w, room.h, room.d)
let roomColor = new THREE.Color(room.color) let roomColor = new THREE.Color(room.color)
let roomMaterial = new THREE.MeshPhysicalMaterial({ color: roomColor }) let roomMaterial = new THREE.MeshPhysicalMaterial({ color: roomColor })
let roomMesh = new THREE.Mesh(roomGeo, roomMaterial) let roomMesh = new THREE.Mesh(roomGeo, roomMaterial)
setPosition(roomMesh, room.x, room.y, room.z || 0, room.w, room.h, room.d) roomContainer.add(roomMesh)
roomMesh.userData = room.name
home.add(roomMesh) setPosition(roomContainer, room.x, room.y, room.z || 0, room.w, room.h, room.d)
roomContainer.userData = room.name
home.add(roomContainer)
minX = Math.min(minX, room.x) minX = Math.min(minX, room.x)
minY = Math.min(minY, room.y) minY = Math.min(minY, room.y)

Loading…
Cancel
Save