Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

Commit

Permalink
Toggle world scale when editing #5
Browse files Browse the repository at this point in the history
  • Loading branch information
brianchirls committed Feb 23, 2017
1 parent 3c344c4 commit 7e8fd5b
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ window.WebVRConfig = {
};

const CHARACTER_SCALE = 1.5;
const WORLD_SHRINK_SCALE = 1 / 10;

const THREE = window.THREE = require('three');

Expand Down Expand Up @@ -35,6 +36,9 @@ document.body.appendChild(renderer.domElement);
// Create a three.js scene.
const scene = new THREE.Scene();

const world = new THREE.Object3D();
scene.add(world);

// Create a three.js camera.
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 10000);

Expand All @@ -55,7 +59,7 @@ const floor = new THREE.Mesh(
);
floor.receiveShadow = true;
floor.rotation.x = -Math.PI / 2;
scene.add(floor);
world.add(floor);

// sky is just a box for now, as long as it's a solid color
// might require a half-sphere later for a gradient or atmosphere
Expand All @@ -70,6 +74,21 @@ const room = new THREE.Mesh(
room.position.y = 490;
scene.add(room);

// editing state
let isEditing = false;
function updateEditingState() {
const worldScale = isEditing ? WORLD_SHRINK_SCALE : 1;
world.scale.set(worldScale, worldScale, worldScale);

// todo: adjust this for kids!!
world.position.y = isEditing ? 0.6 : 0;
}

function toggleEditing() {
isEditing = !isEditing;
updateEditingState();
}

// set up controllers
let controllerGeometryPromise;
const controllers = [];
Expand All @@ -79,6 +98,8 @@ for (let i = 0; i < 2; i++) {
controller.standingMatrix = controls.getStandingMatrix();
scene.add(controller);
controllers.push(controller);

controller.addEventListener('thumbpaddown', toggleEditing);
}

function loadController() {
Expand Down Expand Up @@ -165,7 +186,7 @@ Promise.all([
}
}
});
scene.add(model);
world.add(model);
});
});

Expand Down Expand Up @@ -319,4 +340,7 @@ window.addEventListener('keydown', e => {
vrDisplay.exitPresent();
}
}
if (event.keyCode === 32) { // space
toggleEditing();
}
}, true);

0 comments on commit 7e8fd5b

Please sign in to comment.