From d0592d562c767f9de5ad725003508daf2601a81c Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Thu, 10 Sep 2015 15:30:50 -0700 Subject: [PATCH 1/2] Make the flashlight grab frame work correctly --- examples/toys/flashlight/flashlight.js | 27 +++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/examples/toys/flashlight/flashlight.js b/examples/toys/flashlight/flashlight.js index e0106dbd49..cca4d2b048 100644 --- a/examples/toys/flashlight/flashlight.js +++ b/examples/toys/flashlight/flashlight.js @@ -16,10 +16,11 @@ (function() { function debugPrint(message) { - // print(message); + print(message); } - Script.include("../../libraries/utils.js"); + //Script.include("../../libraries/utils.js"); + Script.include("https://hifi-public.s3.amazonaws.com/scripts/libraries/utils.js"); var _this; @@ -31,6 +32,15 @@ _this._spotlight = null; }; + + GRAB_FRAME_USER_DATA_KEY = "grabFrame"; + + // These constants define the Flashlight model Grab Frame + var MODEL_GRAB_FRAME = { + relativePosition: {x: 0, y: -0.1, z: 0}, + relativeRotation: Quat.angleAxis(180, {x: 1, y: 0, z: 0}) + }; + // These constants define the Spotlight position and orientation relative to the model var MODEL_LIGHT_POSITION = {x: 0, y: 0, z: 0}; var MODEL_LIGHT_ROTATION = Quat.angleAxis (-90, {x: 1, y: 0, z: 0}); @@ -43,6 +53,8 @@ Flashlight.prototype = { + + // update() will be called regulary, because we've hooked the update signal in our preload() function // we will check out userData for the grabData. In the case of the hydraGrab script, it will tell us // if we're currently being grabbed and if the person grabbing us is the current interfaces avatar. @@ -126,11 +138,20 @@ // * connecting to the update signal so we can check our grabbed state preload: function(entityID) { _this.entityID = entityID; - + var modelProperties = Entities.getEntityProperties(entityID); _this._startModelPosition = modelProperties.position; _this._startModelRotation = modelProperties.rotation; + // Make sure the Flashlight entity has a correct grab frame setup + var userData = getEntityUserData(entityID); + debugPrint(JSON.stringify(userData)); + if (!userData.grabFrame) { + setEntityCustomData(GRAB_FRAME_USER_DATA_KEY, entityID, MODEL_GRAB_FRAME); + debugPrint(JSON.stringify(MODEL_GRAB_FRAME)); + debugPrint("Assigned the grab frmae for the Flashlight entity"); + } + Script.update.connect(this.update); }, From 3bf0f388eb49b8acfe81c2605c6e4d71b8fd6674 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Thu, 10 Sep 2015 15:39:54 -0700 Subject: [PATCH 2/2] Make the flashlight grab frame work correctly --- examples/toys/flashlight/flashlight.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/toys/flashlight/flashlight.js b/examples/toys/flashlight/flashlight.js index cca4d2b048..165f693e8e 100644 --- a/examples/toys/flashlight/flashlight.js +++ b/examples/toys/flashlight/flashlight.js @@ -16,11 +16,10 @@ (function() { function debugPrint(message) { - print(message); + //print(message); } - //Script.include("../../libraries/utils.js"); - Script.include("https://hifi-public.s3.amazonaws.com/scripts/libraries/utils.js"); + Script.include("../../libraries/utils.js"); var _this;