From 28c53822b15291c99f7845e3e42af285e45019f1 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Sun, 27 Dec 2015 12:37:33 -0800 Subject: [PATCH 1/3] add raypick blacklisting to hand grab script --- examples/controllers/handControllerGrab.js | 33 +++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index e0a7c55af8..aa416068f2 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -116,6 +116,11 @@ var DEFAULT_GRABBABLE_DATA = { invertSolidWhileHeld: false }; + +// sometimes we want to exclude objects from being picked +var USE_BLACKLIST = true; +var blacklist = []; + //we've created various ways of visualizing looking for and moving distant objects var USE_ENTITY_LINES_FOR_SEARCHING = false; var USE_OVERLAY_LINES_FOR_SEARCHING = false; @@ -771,7 +776,14 @@ function MyController(hand) { }) } - var intersection = Entities.findRayIntersection(pickRayBacked, true); + var intersection; + + if(USE_BLACKLIST===true){ + intersection = Entities.findRayIntersection(pickRay, true, [], blacklist); + } + else{ + intersection = Entities.findRayIntersection(pickRayBacked, true); + } if (intersection.intersects) { // the ray is intersecting something we can move. @@ -1626,6 +1638,7 @@ function update() { Messages.subscribe('Hifi-Hand-Disabler'); Messages.subscribe('Hifi-Hand-Grab'); +Messages.subscribe('Hifi-Hand-RayPick-Blacklist'); handleHandMessages = function(channel, message, sender) { if (sender === MyAvatar.sessionUUID) { @@ -1649,6 +1662,24 @@ handleHandMessages = function(channel, message, sender) { } catch (e) { } } + else if (channel === 'Hifi-Hand-RayPick-Blacklist') { + try { + var data = JSON.parse(message); + var action = data.action; + var id = data.id; + var index = blacklist.indexOf(id); + + if (action === 'add' && index ===-1) { + blacklist.push(id); + } + if (action === 'remove') { + if (index > -1) { + blacklist.splice(index, 1); + } + } + + } catch (e) {} + } } } From 546e908633f41206c032b114eaa3af179b5bc770 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Sun, 27 Dec 2015 12:46:40 -0800 Subject: [PATCH 2/3] protect blacklisting to my id --- examples/controllers/handControllerGrab.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index aa416068f2..80fcaa3f6f 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -777,7 +777,7 @@ function MyController(hand) { } var intersection; - + if(USE_BLACKLIST===true){ intersection = Entities.findRayIntersection(pickRay, true, [], blacklist); } @@ -1662,7 +1662,7 @@ handleHandMessages = function(channel, message, sender) { } catch (e) { } } - else if (channel === 'Hifi-Hand-RayPick-Blacklist') { + else if (channel === 'Hifi-Hand-RayPick-Blacklist' && sender === MyAvatar.sessionUUID) { try { var data = JSON.parse(message); var action = data.action; From 0e30393c81b7ec1067d0fdfb5f483b68004326cd Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Sun, 27 Dec 2015 12:47:56 -0800 Subject: [PATCH 3/3] make sure theres something on the blacklist --- examples/controllers/handControllerGrab.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 80fcaa3f6f..deca0aa3ba 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -778,13 +778,12 @@ function MyController(hand) { var intersection; - if(USE_BLACKLIST===true){ - intersection = Entities.findRayIntersection(pickRay, true, [], blacklist); + if (USE_BLACKLIST === true && blacklist.length !== 0) { + intersection = Entities.findRayIntersection(pickRay, true, [], blacklist); + } else { + intersection = Entities.findRayIntersection(pickRayBacked, true); } - else{ - intersection = Entities.findRayIntersection(pickRayBacked, true); - } - + if (intersection.intersects) { // the ray is intersecting something we can move. var intersectionDistance = Vec3.distance(pickRay.origin, intersection.intersection);