From f4d28a6ee632e00b9fe529377d823c3e56fe4a37 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Mon, 13 Apr 2015 09:48:50 +0200 Subject: [PATCH] Hide camera when clicking on it --- js/CameraContainer.js | 4 ++++ js/FixedCamera.js | 5 +++++ prototype/js/main.js | 11 +++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/js/CameraContainer.js b/js/CameraContainer.js index 7da76c9..3123c47 100644 --- a/js/CameraContainer.js +++ b/js/CameraContainer.js @@ -58,3 +58,7 @@ CameraContainer.prototype.nextCamera = function() { this.current_camera%=this.cameras.length; } } + +CameraContainer.prototype.map = function(callback) { + this.cameras.map(callback); +} diff --git a/js/FixedCamera.js b/js/FixedCamera.js index fe3c46b..280dd57 100644 --- a/js/FixedCamera.js +++ b/js/FixedCamera.js @@ -105,3 +105,8 @@ FixedCamera.prototype.addToScene = function(scene) { scene.add(this.mesh); scene.add(this.line); } + +FixedCamera.prototype.traverse = function(callback) { + callback(this.mesh); + callback(this.line); +} diff --git a/prototype/js/main.js b/prototype/js/main.js index 4739b14..16c296f 100644 --- a/prototype/js/main.js +++ b/prototype/js/main.js @@ -204,6 +204,9 @@ function click(event) { var intersects = raycaster.intersectObjects(scene.children, true); + // Re-show all cameras + cameras.map(function(elt) { show(elt); }); + if ( intersects.length > 0 ) { var minDistance; var bestIndex; @@ -221,14 +224,18 @@ function click(event) { if (bestIndex !== undefined) { if (cameras.getById(intersects[bestIndex].object.id) !== undefined) { - cameras.get(0).move(cameras.getById(intersects[bestIndex].object.id)); + var new_camera = cameras.getById(intersects[bestIndex].object.id); + hide(new_camera) + cameras.get(0).move(new_camera); } } // Looking for objects for (o in objects) { if ( intersects[bestIndex].object.id == objects[o].id && cameras.get(objects[o].seen_by[0]) !== undefined) { - cameras.get(0).move(cameras.get(objects[o].seen_by[0])); + var new_camera = cameras.get(objects[o].seen_by[0]); + hide(new_camera); + cameras.get(0).move(new_camera); break; } }