Added option to hide arrows

This commit is contained in:
Thomas FORGIONE 2015-04-22 16:24:45 +02:00
parent 9ea0e14712
commit a46bac5663
2 changed files with 27 additions and 7 deletions

View File

@ -20,6 +20,8 @@
<label for="fullarrow">Full arrow</label> <label for="fullarrow">Full arrow</label>
<input type="checkbox" id="collisions" style="margin-bottom:10px" checked> <input type="checkbox" id="collisions" style="margin-bottom:10px" checked>
<label for="collisions">Collisions</label> <label for="collisions">Collisions</label>
<input type="checkbox" id="showarrows" style="margin-bottom:10px" checked>
<label for="showarrows">Show arrows</label>
<div style="border-width:1px; border-style: solid;" id="container"></div> <div style="border-width:1px; border-style: solid;" id="container"></div>
# #
</section> </section>

32
prototype/js/main.js vendored
View File

@ -12,6 +12,7 @@ var loader;
var container_size = {width: 1067, height: 600}; var container_size = {width: 1067, height: 600};
var prev = {x:0, y:0, go:false}; var prev = {x:0, y:0, go:false};
var showArrows = true;
init(); init();
animate(); animate();
@ -36,6 +37,11 @@ function init() {
cameras.mainCamera().collisions = collisions.checked; cameras.mainCamera().collisions = collisions.checked;
} }
var showarrows = document.getElementById('showarrows');
showarrows.onchange = function() {
showArrows = showarrows.checked;
}
// on initialise le moteur de rendu // on initialise le moteur de rendu
container = document.getElementById('container'); container = document.getElementById('container');
container.style.height = container_size.height + 'px'; container.style.height = container_size.height + 'px';
@ -218,7 +224,17 @@ function loadScene() {
} }
function render() { function render() {
cameras.map(function(camera) { if (camera instanceof FixedCamera) show(camera); }); var transform = showArrows ? show : hide;
cameras.map(function(camera) {
if (camera instanceof FixedCamera) {
transform(camera);
camera.traverse(function(elt) {
elt.raycastable = showArrows;
});
}
});
cameras.updateMainCamera(); cameras.updateMainCamera();
cameras.update(cameras.mainCamera()); cameras.update(cameras.mainCamera());
cameras.look(); cameras.look();
@ -313,12 +329,14 @@ function pointedCamera(event) {
// Looking for cameras // Looking for cameras
for (i in intersects) { for (i in intersects) {
if ((intersects[i].distance > 0.5 && minDistance === undefined) || (intersects[i].distance < minDistance )) { if (intersects[i].object.raycastable) {
// We will not consider a line as clickable if ((intersects[i].distance > 0.5 && minDistance === undefined) || (intersects[i].distance < minDistance )) {
if (! (intersects[i].object instanceof THREE.Line)) { // We will not consider a line as clickable
if (!(intersects[i].object instanceof THREE.Mesh && intersects[i].object.material.opacity < 0.1)) { if (! (intersects[i].object instanceof THREE.Line)) {
minDistance = intersects[i].distance; if (!(intersects[i].object instanceof THREE.Mesh && intersects[i].object.material.opacity < 0.1)) {
bestIndex = i; minDistance = intersects[i].distance;
bestIndex = i;
}
} }
} }
} }