From 1f7914766c7ddaef4dcbe898c1f1d885c07c05dc Mon Sep 17 00:00:00 2001 From: James Pollack Date: Fri, 25 Sep 2015 15:26:29 -0700 Subject: [PATCH 1/2] Add ability to prevent an object from being grabbable by specifying a custom key grabbableKey to grabbable:false --- examples/controllers/handControllerGrab.js | 24 ++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index a13f1de86d..27ffbee60c 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -72,8 +72,9 @@ var STATE_NEAR_GRABBING_NON_COLLIDING = 5; var STATE_CONTINUE_NEAR_GRABBING_NON_COLLIDING = 6; var STATE_RELEASE = 7; - var GRAB_USER_DATA_KEY = "grabKey"; +var GRABBABLE_DATA_KEY = "grabbableKey"; + function MyController(hand, triggerAction) { this.hand = hand; if (this.hand === RIGHT_HAND) { @@ -182,6 +183,11 @@ function MyController(hand, triggerAction) { origin: handPosition, direction: Quat.getUp(this.getHandRotation()) }; + + var defaultGrabbableData = { + grabbable: true + }; + var intersection = Entities.findRayIntersection(pickRay, true); if (intersection.intersects && intersection.properties.collisionsWillMove === 1 && @@ -190,9 +196,15 @@ function MyController(hand, triggerAction) { var handControllerPosition = Controller.getSpatialControlPosition(this.palm); var intersectionDistance = Vec3.distance(handControllerPosition, intersection.intersection); this.grabbedEntity = intersection.entityID; + + var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, intersection.entityID, defaultGrabbableData); + if (grabbableData.grabbable === false) { + return; + } if (intersectionDistance < NEAR_PICK_MAX_DISTANCE) { // the hand is very close to the intersected object. go into close-grabbing mode. this.state = STATE_NEAR_GRABBING; + } else { // the hand is far from the intersected object. go into distance-holding mode this.state = STATE_DISTANCE_HOLDING; @@ -203,8 +215,16 @@ function MyController(hand, triggerAction) { var nearbyEntities = Entities.findEntities(handPosition, GRAB_RADIUS); var minDistance = GRAB_RADIUS; var i, props, distance; + for (i = 0; i < nearbyEntities.length; i++) { + + var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, nearbyEntities[i], defaultGrabbableData); + if (grabbableData.grabbable === false) { + return + } + props = Entities.getEntityProperties(nearbyEntities[i], ["position", "name", "collisionsWillMove", "locked"]); + distance = Vec3.distance(props.position, handPosition); if (distance < minDistance && props.name !== "pointer") { this.grabbedEntity = nearbyEntities[i]; @@ -383,7 +403,7 @@ function MyController(hand, triggerAction) { Entities.callEntityMethod(this.grabbedEntity, "continueNearGrabbingNonColliding"); }; - _this.allTouchedIDs={}; + _this.allTouchedIDs = {}; this.touchTest = function() { var maxDistance = 0.05; var leftHandPosition = MyAvatar.getLeftPalmPosition(); From affb0253db2976427b2e2d56bbcff2d891af7737 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 28 Sep 2015 10:26:52 -0700 Subject: [PATCH 2/2] Update handControllerGrab.js added a semicolon to the end of a return statement --- 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 27ffbee60c..41f36c19d5 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -220,7 +220,7 @@ function MyController(hand, triggerAction) { var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, nearbyEntities[i], defaultGrabbableData); if (grabbableData.grabbable === false) { - return + return; } props = Entities.getEntityProperties(nearbyEntities[i], ["position", "name", "collisionsWillMove", "locked"]); @@ -546,4 +546,4 @@ function cleanup() { } Script.scriptEnding.connect(cleanup); -Script.update.connect(update); \ No newline at end of file +Script.update.connect(update);