From 4a3b434fd48f7186988d4350e72fa8df92a65044 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 5 Nov 2015 10:35:02 -0800 Subject: [PATCH 1/2] change grabbing-non-colliding to trigger. fix whiteboard and some other scripts --- examples/controllers/handControllerGrab.js | 75 ++++++++++--------- .../whiteboard/colorSelectorEntityScript.js | 4 +- .../whiteboard/eraseBoardEntityScript.js | 4 +- .../whiteboard/whiteboardEntityScript.js | 8 +- .../painting/whiteboard/whiteboardSpawner.js | 5 +- examples/toybox/lights/lightSwitch.js | 7 +- unpublishedScripts/basketballsResetter.js | 4 +- unpublishedScripts/hiddenEntityReset.js | 4 +- unpublishedScripts/masterReset.js | 5 +- unpublishedScripts/targetsResetter.js | 4 +- 10 files changed, 66 insertions(+), 54 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index b0721de119..6ea08e5a43 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -101,10 +101,10 @@ var STATE_DISTANCE_HOLDING = 2; var STATE_CONTINUE_DISTANCE_HOLDING = 3; var STATE_NEAR_GRABBING = 4; var STATE_CONTINUE_NEAR_GRABBING = 5; -var STATE_NEAR_GRABBING_NON_COLLIDING = 6; -var STATE_CONTINUE_NEAR_GRABBING_NON_COLLIDING = 7; -var STATE_FAR_GRABBING_NON_COLLIDING = 8; -var STATE_CONTINUE_FAR_GRABBING_NON_COLLIDING = 9; +var STATE_NEAR_TRIGGER = 6; +var STATE_CONTINUE_NEAR_TRIGGER = 7; +var STATE_FAR_TRIGGER = 8; +var STATE_CONTINUE_FAR_TRIGGER = 9; var STATE_RELEASE = 10; @@ -122,14 +122,14 @@ function stateToName(state) { return "near_grabbing"; case STATE_CONTINUE_NEAR_GRABBING: return "continue_near_grabbing"; - case STATE_NEAR_GRABBING_NON_COLLIDING: - return "near_grabbing_non_colliding"; - case STATE_CONTINUE_NEAR_GRABBING_NON_COLLIDING: - return "continue_near_grabbing_non_colliding"; - case STATE_FAR_GRABBING_NON_COLLIDING: - return "far_grabbing_non_colliding"; - case STATE_CONTINUE_FAR_GRABBING_NON_COLLIDING: - return "continue_far_grabbing_non_colliding"; + case STATE_NEAR_TRIGGER: + return "near_trigger"; + case STATE_CONTINUE_NEAR_TRIGGER: + return "continue_near_trigger"; + case STATE_FAR_TRIGGER: + return "far_trigger"; + case STATE_CONTINUE_FAR_TRIGGER: + return "continue_far_trigger"; case STATE_RELEASE: return "release"; } @@ -212,17 +212,17 @@ function MyController(hand) { case STATE_CONTINUE_NEAR_GRABBING: this.continueNearGrabbing(); break; - case STATE_NEAR_GRABBING_NON_COLLIDING: - this.nearGrabbingNonColliding(); + case STATE_NEAR_TRIGGER: + this.nearTrigger(); break; - case STATE_CONTINUE_NEAR_GRABBING_NON_COLLIDING: - this.continueNearGrabbingNonColliding(); + case STATE_CONTINUE_NEAR_TRIGGER: + this.continueNearTrigger(); break; - case STATE_FAR_GRABBING_NON_COLLIDING: - this.farGrabbingNonColliding(); + case STATE_FAR_TRIGGER: + this.farTrigger(); break; - case STATE_CONTINUE_FAR_GRABBING_NON_COLLIDING: - this.continueFarGrabbingNonColliding(); + case STATE_CONTINUE_FAR_TRIGGER: + this.continueFarTrigger(); break; case STATE_RELEASE: this.release(); @@ -394,7 +394,7 @@ function MyController(hand) { // the hand is very close to the intersected object. go into close-grabbing mode. if (grabbableData.wantsTrigger) { this.grabbedEntity = intersection.entityID; - this.setState(STATE_NEAR_GRABBING_NON_COLLIDING); + this.setState(STATE_NEAR_TRIGGER); return; } else if (!intersection.properties.locked) { this.grabbedEntity = intersection.entityID; @@ -411,7 +411,7 @@ function MyController(hand) { return; } else if (grabbableData.wantsTrigger) { this.grabbedEntity = intersection.entityID; - this.setState(STATE_FAR_GRABBING_NON_COLLIDING); + this.setState(STATE_FAR_TRIGGER); return; } } @@ -483,7 +483,7 @@ function MyController(hand) { return; } if (grabbableData.wantsTrigger) { - this.setState(STATE_NEAR_GRABBING_NON_COLLIDING); + this.setState(STATE_NEAR_TRIGGER); return; } else if (!props.locked) { this.setState(STATE_NEAR_GRABBING); @@ -538,6 +538,7 @@ function MyController(hand) { this.continueDistanceHolding = function() { if (this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); + Entities.callEntityMethod(this.grabbedEntity, "releaseGrab"); return; } @@ -631,6 +632,7 @@ function MyController(hand) { if (this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); + Entities.callEntityMethod(this.grabbedEntity, "releaseGrab"); return; } @@ -698,6 +700,7 @@ function MyController(hand) { this.continueNearGrabbing = function() { if (this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); + Entities.callEntityMethod(this.grabbedEntity, "releaseGrab"); return; } @@ -733,9 +736,10 @@ function MyController(hand) { } }; - this.nearGrabbingNonColliding = function() { + this.nearTrigger = function() { if (this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); + Entities.callEntityMethod(this.grabbedEntity, "stopNearTrigger"); return; } if (this.hand === RIGHT_HAND) { @@ -743,13 +747,14 @@ function MyController(hand) { } else { Entities.callEntityMethod(this.grabbedEntity, "setLeftHand"); } - Entities.callEntityMethod(this.grabbedEntity, "startNearGrabNonColliding"); - this.setState(STATE_CONTINUE_NEAR_GRABBING_NON_COLLIDING); + Entities.callEntityMethod(this.grabbedEntity, "startNearTrigger"); + this.setState(STATE_CONTINUE_NEAR_TRIGGER); }; - this.farGrabbingNonColliding = function() { + this.farTrigger = function() { if (this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); + Entities.callEntityMethod(this.grabbedEntity, "stopFarTrigger"); return; } @@ -758,22 +763,24 @@ function MyController(hand) { } else { Entities.callEntityMethod(this.grabbedEntity, "setLeftHand"); } - Entities.callEntityMethod(this.grabbedEntity, "startFarGrabNonColliding"); - this.setState(STATE_CONTINUE_FAR_GRABBING_NON_COLLIDING); + Entities.callEntityMethod(this.grabbedEntity, "startFarTrigger"); + this.setState(STATE_CONTINUE_FAR_TRIGGER); }; - this.continueNearGrabbingNonColliding = function() { + this.continueNearTrigger = function() { if (this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); + Entities.callEntityMethod(this.grabbedEntity, "stopNearTrigger"); return; } - Entities.callEntityMethod(this.grabbedEntity, "continueNearGrabbingNonColliding"); + Entities.callEntityMethod(this.grabbedEntity, "continueNearTrigger"); }; - this.continueFarGrabbingNonColliding = function() { + this.continueFarTrigger = function() { if (this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); + Entities.callEntityMethod(this.grabbedEntity, "stopNearTrigger"); return; } @@ -789,12 +796,13 @@ function MyController(hand) { this.lastPickTime = now; if (intersection.entityID != this.grabbedEntity) { this.setState(STATE_RELEASE); + Entities.callEntityMethod(this.grabbedEntity, "stopFarTrigger"); return; } } this.lineOn(pickRay.origin, Vec3.multiply(pickRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR); - Entities.callEntityMethod(this.grabbedEntity, "continueFarGrabbingNonColliding"); + Entities.callEntityMethod(this.grabbedEntity, "continueFarTrigger"); }; _this.allTouchedIDs = {}; @@ -876,7 +884,6 @@ function MyController(hand) { if (this.actionID !== null) { Entities.deleteAction(this.grabbedEntity, this.actionID); } - Entities.callEntityMethod(this.grabbedEntity, "releaseGrab"); } this.deactivateEntity(this.grabbedEntity); diff --git a/examples/painting/whiteboard/colorSelectorEntityScript.js b/examples/painting/whiteboard/colorSelectorEntityScript.js index f1105604c7..3c07527d02 100644 --- a/examples/painting/whiteboard/colorSelectorEntityScript.js +++ b/examples/painting/whiteboard/colorSelectorEntityScript.js @@ -20,7 +20,7 @@ ColorSelector.prototype = { - startFarGrabNonColliding: function() { + startFarTrigger: function() { this.selectColor(); }, @@ -46,4 +46,4 @@ // entity scripts always need to return a newly constructed object of our type return new ColorSelector(); -}); \ No newline at end of file +}); diff --git a/examples/painting/whiteboard/eraseBoardEntityScript.js b/examples/painting/whiteboard/eraseBoardEntityScript.js index 14679c625b..dd36242a6d 100644 --- a/examples/painting/whiteboard/eraseBoardEntityScript.js +++ b/examples/painting/whiteboard/eraseBoardEntityScript.js @@ -20,7 +20,7 @@ BoardEraser.prototype = { - startFarGrabNonColliding: function() { + startFarTrigger: function() { this.eraseBoard(); }, @@ -42,4 +42,4 @@ // entity scripts always need to return a newly constructed object of our type return new BoardEraser(); -}); \ No newline at end of file +}); diff --git a/examples/painting/whiteboard/whiteboardEntityScript.js b/examples/painting/whiteboard/whiteboardEntityScript.js index c10a8c23fe..d2b2c386ef 100644 --- a/examples/painting/whiteboard/whiteboardEntityScript.js +++ b/examples/painting/whiteboard/whiteboardEntityScript.js @@ -43,7 +43,7 @@ this.hand = LEFT_HAND; }, - startFarGrabNonColliding: function() { + startFarTrigger: function() { if (this.painting) { return; } @@ -62,7 +62,7 @@ }); }, - continueFarGrabbingNonColliding: function() { + continueFarTrigger: function() { var handPosition = this.getHandPosition(); var pickRay = { origin: handPosition, @@ -183,7 +183,7 @@ }, - releaseGrab: function() { + stopFarTrigger: function() { if(this.hand !== this.whichHand) { return; } @@ -249,4 +249,4 @@ // entity scripts always need to return a newly constructed object of our type return new Whiteboard(); -}); \ No newline at end of file +}); diff --git a/examples/painting/whiteboard/whiteboardSpawner.js b/examples/painting/whiteboard/whiteboardSpawner.js index 701112e1a8..3411061074 100644 --- a/examples/painting/whiteboard/whiteboardSpawner.js +++ b/examples/painting/whiteboard/whiteboardSpawner.js @@ -74,6 +74,9 @@ var drawingSurface = Entities.addEntity({ userData: JSON.stringify({ color: { currentColor: colors[0] + }, + "grabbableKey": { + wantsTrigger:true } }) @@ -211,4 +214,4 @@ function cleanup() { // Uncomment this line to delete whiteboard and all associated entity on script close -// Script.scriptEnding.connect(cleanup); \ No newline at end of file +// Script.scriptEnding.connect(cleanup); diff --git a/examples/toybox/lights/lightSwitch.js b/examples/toybox/lights/lightSwitch.js index fbd314a9af..5d6497fccb 100644 --- a/examples/toybox/lights/lightSwitch.js +++ b/examples/toybox/lights/lightSwitch.js @@ -33,7 +33,7 @@ this.toggleLights(); }, - startNearGrabNonColliding: function () { + startNearTrigger: function () { this.toggleLights(); }, @@ -61,7 +61,8 @@ setEntityCustomData(this.resetKey, this.entityID, { on: on, type: lightType, - resetMe: true + resetMe: true, + grabbableKey: {wantsTrigger:true} }); }, @@ -89,4 +90,4 @@ // entity scripts always need to return a newly constructed object of our type return new LightSwitch(); -}); \ No newline at end of file +}); diff --git a/unpublishedScripts/basketballsResetter.js b/unpublishedScripts/basketballsResetter.js index 6335312d57..4d02296e8e 100644 --- a/unpublishedScripts/basketballsResetter.js +++ b/unpublishedScripts/basketballsResetter.js @@ -17,7 +17,7 @@ var HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; Resetter.prototype = { - startNearGrabNonColliding: function() { + startNearTrigger: function() { this.resetObjects(); }, @@ -108,4 +108,4 @@ var HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; }; return new Resetter(); -}); \ No newline at end of file +}); diff --git a/unpublishedScripts/hiddenEntityReset.js b/unpublishedScripts/hiddenEntityReset.js index f56c705ce4..d343c52497 100644 --- a/unpublishedScripts/hiddenEntityReset.js +++ b/unpublishedScripts/hiddenEntityReset.js @@ -39,7 +39,7 @@ }, - startNearGrabNonColliding: function() { + startNearTrigger: function() { this.triggerReset(); }, @@ -1259,4 +1259,4 @@ }; // entity scripts always need to return a newly constructed object of our type return new ResetSwitch(); -}); \ No newline at end of file +}); diff --git a/unpublishedScripts/masterReset.js b/unpublishedScripts/masterReset.js index b138db163d..364807f42f 100644 --- a/unpublishedScripts/masterReset.js +++ b/unpublishedScripts/masterReset.js @@ -247,7 +247,8 @@ MasterReset = function() { resetMe: true }, grabbableKey: { - grabbable: false + grabbable: false, + wantsTrigger:true } }) }); @@ -1237,4 +1238,4 @@ MasterReset = function() { Script.scriptEnding.connect(cleanup); } -}; \ No newline at end of file +}; diff --git a/unpublishedScripts/targetsResetter.js b/unpublishedScripts/targetsResetter.js index a522c19593..326c0ce1be 100644 --- a/unpublishedScripts/targetsResetter.js +++ b/unpublishedScripts/targetsResetter.js @@ -17,7 +17,7 @@ Resetter.prototype = { - startNearGrabNonColliding: function() { + startNearTrigger: function() { this.resetObjects(); }, @@ -125,4 +125,4 @@ }; return new Resetter(); -}); \ No newline at end of file +}); From c898d9a47483609d1fabe68367792291343082b6 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 5 Nov 2015 10:48:16 -0800 Subject: [PATCH 2/2] set wantstrigger correctly on lightswitch --- examples/toybox/lights/lightSwitch.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/examples/toybox/lights/lightSwitch.js b/examples/toybox/lights/lightSwitch.js index 5d6497fccb..6051b7c0ae 100644 --- a/examples/toybox/lights/lightSwitch.js +++ b/examples/toybox/lights/lightSwitch.js @@ -15,35 +15,35 @@ /*global LightSwitch */ -(function () { +(function() { var _this; var utilitiesScript = Script.resolvePath("../../libraries/utils.js"); Script.include(utilitiesScript); - LightSwitch = function () { + LightSwitch = function() { _this = this; this.switchSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/sounds/Switches%20and%20sliders/lamp_switch_2.wav"); }; LightSwitch.prototype = { - clickReleaseOnEntity: function (entityID, mouseEvent) { + clickReleaseOnEntity: function(entityID, mouseEvent) { if (!mouseEvent.isLeftButton) { return; } this.toggleLights(); }, - startNearTrigger: function () { + startNearTrigger: function() { this.toggleLights(); }, - toggleLights: function () { + toggleLights: function() { var lightData = getEntityCustomData(this.resetKey, this.entityID, {}); var on = !lightData.on; var lightType = lightData.type; var lights = Entities.findEntities(this.position, 20); - lights.forEach(function (light) { + lights.forEach(function(light) { var type = getEntityCustomData(_this.resetKey, light, {}).type; if (type === lightType && JSON.stringify(light) !== JSON.stringify(_this.entityID)) { Entities.editEntity(light, { @@ -61,12 +61,15 @@ setEntityCustomData(this.resetKey, this.entityID, { on: on, type: lightType, - resetMe: true, - grabbableKey: {wantsTrigger:true} + resetMe: true + }); + + setEntityCustomData('grabbableKey', this.entityID, { + wantsTrigger: true }); }, - flipSwitch: function () { + flipSwitch: function() { var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation; var axis = { x: 0, @@ -80,7 +83,7 @@ rotation: rotation }); }, - preload: function (entityID) { + preload: function(entityID) { this.entityID = entityID; this.resetKey = "resetMe"; //The light switch is static, so just cache its position once @@ -90,4 +93,4 @@ // entity scripts always need to return a newly constructed object of our type return new LightSwitch(); -}); +}); \ No newline at end of file