From 2ec712a5db30b2c847fb8da5e02f8770f99ceece Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 28 Dec 2015 15:27:17 -0800 Subject: [PATCH] disable near grabbing on sliders --- examples/controllers/handControllerGrab.js | 35 +++++++++++++++++----- examples/light_modifier/lightModifier.js | 3 +- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 50fdf3353c..9652132c08 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -788,14 +788,19 @@ function MyController(hand) { } 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); var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, intersection.entityID, DEFAULT_GRABBABLE_DATA); + var defaultDisableNearGrabData = { + disableNearGrab: false + }; + //sometimes we want things to stay right where they are when we let go. + var disableNearGrabData = getEntityCustomData('handControllerKey', intersection.entityID, defaultDisableNearGrabData); if (intersection.properties.name == "Grab Debug Entity") { continue; @@ -817,7 +822,11 @@ function MyController(hand) { } else if (!intersection.properties.locked) { this.grabbedEntity = intersection.entityID; if (this.state == STATE_SEARCHING) { - this.setState(STATE_NEAR_GRABBING); + if (disableNearGrabData.disableNearGrab !== true) { + this.setState(STATE_NEAR_GRABBING); + } else { + //disable near grab on this thing + } } else { // equipping if (typeof grabbableData.spatialKey !== 'undefined') { // TODO @@ -940,7 +949,18 @@ function MyController(hand) { this.setState(STATE_NEAR_TRIGGER); return; } else if (!props.locked && props.collisionsWillMove) { - this.setState(this.state == STATE_SEARCHING ? STATE_NEAR_GRABBING : STATE_EQUIP) + var defaultDisableNearGrabData = { + disableNearGrab: false + }; + //sometimes we want things to stay right where they are when we let go. + var disableNearGrabData = getEntityCustomData('handControllerKey', this.grabbedEntity, defaultDisableNearGrabData); + if (disableNearGrabData.disableNearGrab === true) { + //do nothing because near grab is disabled for this object + } else { + this.setState(this.state == STATE_SEARCHING ? STATE_NEAR_GRABBING : STATE_EQUIP) + + } + return; } } @@ -1753,15 +1773,14 @@ handleHandMessages = function(channel, message, sender) { } catch (e) {} - } - else if (channel === 'Hifi-Hand-RayPick-Blacklist') { + } 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) { + + if (action === 'add' && index === -1) { blacklist.push(id); } if (action === 'remove') { diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index 52d9342464..b50bbe9478 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -374,7 +374,8 @@ entitySlider.prototype = { }, handControllerKey: { disableReleaseVelocity: true, - disableMoveWithHead: true + disableMoveWithHead: true, + disableNearGrab:true } }), };