From 9ec2a01475c60f6653c2e69dcf08f81b9e63dbe1 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Fri, 27 Nov 2015 12:13:53 -0800 Subject: [PATCH 1/5] isolate grab script changes from bow branch --- examples/controllers/handControllerGrab.js | 92 +++++++++++++--------- 1 file changed, 55 insertions(+), 37 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index f8a2eeefa5..0a6aec6e7d 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -37,6 +37,7 @@ var BUMPER_ON_VALUE = 0.5; var DISTANCE_HOLDING_RADIUS_FACTOR = 5; // multiplied by distance between hand and object var DISTANCE_HOLDING_ACTION_TIMEFRAME = 0.1; // how quickly objects move to their new position var DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR = 2.0; // object rotates this much more than hand did + var NO_INTERSECT_COLOR = { red: 10, green: 10, @@ -86,6 +87,7 @@ var ZERO_VEC = { y: 0, z: 0 }; + var NULL_ACTION_ID = "{00000000-0000-0000-000000000000}"; var MSEC_PER_SEC = 1000.0; @@ -95,7 +97,8 @@ var ACTION_TTL = 15; // seconds var ACTION_TTL_REFRESH = 5; var PICKS_PER_SECOND_PER_HAND = 5; var MSECS_PER_SEC = 1000.0; -var GRABBABLE_PROPERTIES = ["position", +var GRABBABLE_PROPERTIES = [ + "position", "rotation", "gravity", "ignoreForCollisions", @@ -104,17 +107,15 @@ var GRABBABLE_PROPERTIES = ["position", "name" ]; - var GRABBABLE_DATA_KEY = "grabbableKey"; // shared with grab.js var GRAB_USER_DATA_KEY = "grabKey"; // shared with grab.js +var BEAM_DISABLER_KEY = 'beamDisablerKey' var DEFAULT_GRABBABLE_DATA = { grabbable: true, invertSolidWhileHeld: false }; -var disabledHand = 'none'; - // states for the state machine var STATE_OFF = 0; @@ -307,7 +308,14 @@ function MyController(hand) { position: closePoint, linePoints: [ZERO_VEC, farPoint], color: color, - lifetime: 0.1 + lifetime: 0.1, + collisionsWillMove: false, + ignoreForCollisions: true, + userData: JSON.stringify({ + grabbableKey: { + grabbable: false + } + }) }); } @@ -322,7 +330,14 @@ function MyController(hand) { position: closePoint, linePoints: [ZERO_VEC, farPoint], color: color, - lifetime: LIFETIME + lifetime: LIFETIME, + collisionsWillMove: false, + ignoreForCollisions: true, + userData: JSON.stringify({ + grabbableKey: { + grabbable: false + } + }) }); } else { var age = Entities.getEntityProperties(this.pointer, "age").age; @@ -396,11 +411,6 @@ function MyController(hand) { this.search = function() { this.grabbedEntity = null; - // if this hand is the one that's disabled, we don't want to search for anything at all - if (this.hand === disabledHand) { - return; - } - if (this.state == STATE_SEARCHING ? this.triggerSmoothedReleased() : this.bumperReleased()) { this.setState(STATE_RELEASE); return; @@ -445,17 +455,7 @@ function MyController(hand) { // the ray is intersecting something we can move. var intersectionDistance = Vec3.distance(pickRay.origin, intersection.intersection); - //this code will disabled the beam for the opposite hand of the one that grabbed it if the entity says so var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, intersection.entityID, DEFAULT_GRABBABLE_DATA); - if (grabbableData["turnOffOppositeBeam"]) { - if (this.hand === RIGHT_HAND) { - disabledHand = LEFT_HAND; - } else { - disabledHand = RIGHT_HAND; - } - } else { - disabledHand = 'none'; - } if (intersection.properties.name == "Grab Debug Entity") { continue; @@ -526,7 +526,14 @@ function MyController(hand) { green: 255, blue: 0 }, - lifetime: 0.1 + lifetime: 0.1, + collisionsWillMove: false, + ignoreForCollisions: true, + userData: JSON.stringify({ + grabbableKey: { + grabbable: false + } + }) }); } @@ -540,8 +547,7 @@ function MyController(hand) { if (typeof grabbableDataForCandidate.grabbable !== 'undefined' && !grabbableDataForCandidate.grabbable) { continue; } - var propsForCandidate = - Entities.getEntityProperties(nearbyEntities[i], GRABBABLE_PROPERTIES); + var propsForCandidate = Entities.getEntityProperties(nearbyEntities[i], GRABBABLE_PROPERTIES); if (propsForCandidate.type == 'Unknown') { continue; @@ -737,15 +743,8 @@ function MyController(hand) { this.nearGrabbing = function() { var now = Date.now(); - var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA); - var turnOffOtherHand = grabbableData["turnOffOtherHand"]; - if (turnOffOtherHand) { - //don't activate the second hand grab because the script is handling the second hand logic - return; - } - if (this.state == STATE_NEAR_GRABBING && this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); Entities.callEntityMethod(this.grabbedEntity, "releaseGrab"); @@ -1094,10 +1093,6 @@ function MyController(hand) { this.release = function() { - if (this.hand !== disabledHand) { - //release the disabled hand when we let go with the main one - disabledHand = 'none'; - } this.lineOff(); if (this.grabbedEntity !== null) { @@ -1218,12 +1213,35 @@ mapping.from([Controller.Standard.LB]).peek().to(leftController.bumperPress); Controller.enableMapping(MAPPING_NAME); +var handToDisable = 'none'; function update() { - rightController.update(); - leftController.update(); + if (handToDisable !== 0) { + leftController.update(); + } + if (handToDisable !== 1) { + rightController.update(); + } } +Messages.subscribe('Hifi-Beam-Disabler'); + +handleBeamDisablerMessages = function(channel, message, sender) { + + if (sender === MyAvatar.sessionUUID) { + handToDisable = message; + if (message === 'left') { + handToDisable = 1; + } + if (message === 'right') { + handToDisable = 0; + } + } + +} + +Messages.messageReceived.connect(handleBeamDisablerMessages); + function cleanup() { rightController.cleanup(); leftController.cleanup(); From 8f51ee6f580b65b1a5ad45cf7b2fd3311e645fcc Mon Sep 17 00:00:00 2001 From: James Pollack Date: Sat, 28 Nov 2015 22:29:12 -0800 Subject: [PATCH 2/5] rename hand disabler --- examples/controllers/handControllerGrab.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 0a6aec6e7d..158e67b5db 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -1224,17 +1224,17 @@ function update() { } } -Messages.subscribe('Hifi-Beam-Disabler'); +Messages.subscribe('Hifi-Hand-Disabler'); handleBeamDisablerMessages = function(channel, message, sender) { if (sender === MyAvatar.sessionUUID) { handToDisable = message; if (message === 'left') { - handToDisable = 1; + handToDisable = LEFT_HAND; } if (message === 'right') { - handToDisable = 0; + handToDisable = RIGHT_HAND; } } From 1315201bdcb564434ff508e6a464e3d7ca764014 Mon Sep 17 00:00:00 2001 From: James Pollack Date: Sat, 28 Nov 2015 22:55:44 -0800 Subject: [PATCH 3/5] update name of function --- 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 158e67b5db..eb07ec4133 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -1226,7 +1226,7 @@ function update() { Messages.subscribe('Hifi-Hand-Disabler'); -handleBeamDisablerMessages = function(channel, message, sender) { +handleHandDisablerMessages = function(channel, message, sender) { if (sender === MyAvatar.sessionUUID) { handToDisable = message; @@ -1240,7 +1240,7 @@ handleBeamDisablerMessages = function(channel, message, sender) { } -Messages.messageReceived.connect(handleBeamDisablerMessages); +Messages.messageReceived.connect(handleHandDisablerMessages); function cleanup() { rightController.cleanup(); From 1e2398cbea6b499c56b852ad07c331b1e375a88f Mon Sep 17 00:00:00 2001 From: James Pollack Date: Sat, 28 Nov 2015 23:04:52 -0800 Subject: [PATCH 4/5] use constants --- 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 eb07ec4133..bd63ab55e2 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -1216,10 +1216,10 @@ Controller.enableMapping(MAPPING_NAME); var handToDisable = 'none'; function update() { - if (handToDisable !== 0) { + if (handToDisable !== LEFT_HAND) { leftController.update(); } - if (handToDisable !== 1) { + if (handToDisable !== RIGHT_HAND) { rightController.update(); } } From 55f797838f4e45004dbacebe87d9119ca98fe990 Mon Sep 17 00:00:00 2001 From: James Pollack Date: Sat, 28 Nov 2015 23:22:00 -0800 Subject: [PATCH 5/5] remove unused key --- examples/controllers/handControllerGrab.js | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index bd63ab55e2..0812dc8980 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -109,7 +109,6 @@ var GRABBABLE_PROPERTIES = [ var GRABBABLE_DATA_KEY = "grabbableKey"; // shared with grab.js var GRAB_USER_DATA_KEY = "grabKey"; // shared with grab.js -var BEAM_DISABLER_KEY = 'beamDisablerKey' var DEFAULT_GRABBABLE_DATA = { grabbable: true,