From e4ef3ae8697f8431c8f4191a43eda3b3b2f0d289 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 1 Feb 2016 15:06:53 -0800 Subject: [PATCH 1/3] automatically save adjustments to offset of equipped items --- examples/attachedEntitiesManager.js | 37 ++++++++++++---------- examples/controllers/handControllerGrab.js | 10 +++--- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/examples/attachedEntitiesManager.js b/examples/attachedEntitiesManager.js index f44564d6dc..01f8f861c9 100644 --- a/examples/attachedEntitiesManager.js +++ b/examples/attachedEntitiesManager.js @@ -116,6 +116,7 @@ function AttachedEntitiesManager() { manager.checkIfWearable(parsedMessage.grabbedEntity, parsedMessage.joint) // manager.saveAttachedEntities(); } else if (parsedMessage.action === 'shared-release') { + manager.updateRelativeOffsets(parsedMessage.grabbedEntity); // manager.saveAttachedEntities(); } else if (parsedMessage.action === 'equip') { // manager.saveAttachedEntities(); @@ -173,11 +174,12 @@ function AttachedEntitiesManager() { parentJointIndex: bestJointIndex }; - if (!this.avatarIsInDressingRoom() && - bestJointOffset && bestJointOffset.constructor === Array && bestJointOffset.length > 1) { - // don't snap the entity to the preferred position if the avatar is in the dressing room. - wearProps.localPosition = bestJointOffset[0]; - wearProps.localRotation = bestJointOffset[1]; + if (bestJointOffset && bestJointOffset.constructor === Array && bestJointOffset.length > 1) { + if (!this.avatarIsInDressingRoom()) { + // don't snap the entity to the preferred position if the avatar is in the dressing room. + wearProps.localPosition = bestJointOffset[0]; + wearProps.localRotation = bestJointOffset[1]; + } } Entities.editEntity(grabbedEntity, wearProps); } else if (props.parentID != NULL_UUID) { @@ -189,12 +191,19 @@ function AttachedEntitiesManager() { } } - this.updateRelativeOffsets = function(entityID, props) { + this.updateRelativeOffsets = function(entityID) { // save the preferred (current) relative position and rotation into the user-data of the entity - var wearableData = getEntityCustomData('wearable', entityID, DEFAULT_WEARABLE_DATA); - var currentJointName = MyAvatar.getJointNames()[props.parentJointIndex]; - wearableData.joints[currentJointName] = [props.localPosition, props.localRotation]; - setEntityCustomData('wearable', entityID, wearableData); + var props = Entities.getEntityProperties(entityID); + if (props.parentID == MyAvatar.sessionUUID) { + grabData = getEntityCustomData('grabKey', entityID, {}); + grabbableData = getEntityCustomData('grabbableKey', entityID, {}); + var wearableData = getEntityCustomData('wearable', entityID, DEFAULT_WEARABLE_DATA); + var currentJointName = MyAvatar.getJointNames()[props.parentJointIndex]; + wearableData.joints[currentJointName] = [props.localPosition, props.localRotation]; + setEntityCustomData('wearable', entityID, wearableData); + return true; + } + return false; } this.saveAttachedEntities = function() { @@ -203,12 +212,8 @@ function AttachedEntitiesManager() { var nearbyEntities = Entities.findEntities(MyAvatar.position, ATTACHED_ENTITY_SEARCH_DISTANCE); for (i = 0; i < nearbyEntities.length; i++) { var entityID = nearbyEntities[i]; - var props = Entities.getEntityProperties(entityID); - if (props.parentID == MyAvatar.sessionUUID) { - grabData = getEntityCustomData('grabKey', entityID, {}); - grabbableData = getEntityCustomData('grabbableKey', entityID, {}); - this.updateRelativeOffsets(entityID, props); - props = Entities.getEntityProperties(entityID); // refresh, because updateRelativeOffsets changed them + if (this.updateRelativeOffsets(entityID)) { + var props = Entities.getEntityProperties(entityID); // refresh, because updateRelativeOffsets changed them this.scrubProperties(props); saveData.push(props); } diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 838134cfff..842c54b86d 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -1217,10 +1217,12 @@ function MyController(hand) { this.hasPresetOffsets = function() { var wearableData = getEntityCustomData('wearable', this.grabbedEntity, {joints: {}}); - var allowedJoints = wearableData.joints; - var handJointName = this.hand === RIGHT_HAND ? "RightHand" : "LeftHand"; - if (handJointName in allowedJoints) { - return true; + if ("joints" in wearableData) { + var allowedJoints = wearableData.joints; + var handJointName = this.hand === RIGHT_HAND ? "RightHand" : "LeftHand"; + if (handJointName in allowedJoints) { + return true; + } } } From 30e97c2a76bcdafa30d2f2cef9866917de680fc6 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 2 Feb 2016 16:34:06 -0800 Subject: [PATCH 2/3] run attachedEntitiesManager.js by default, but without a UI --- examples/attachedEntitiesManager.js | 75 ++++++++++++++++------------- examples/defaultScripts.js | 1 + 2 files changed, 42 insertions(+), 34 deletions(-) diff --git a/examples/attachedEntitiesManager.js b/examples/attachedEntitiesManager.js index 01f8f861c9..c44ac66a44 100644 --- a/examples/attachedEntitiesManager.js +++ b/examples/attachedEntitiesManager.js @@ -22,41 +22,44 @@ var MINIMUM_DROP_DISTANCE_FROM_JOINT = 0.4; var ATTACHED_ENTITY_SEARCH_DISTANCE = 10.0; var ATTACHED_ENTITIES_SETTINGS_KEY = "ATTACHED_ENTITIES"; var DRESSING_ROOM_DISTANCE = 2.0; +var SHOW_TOOL_BAR = false; // tool bar -HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; -var BUTTON_SIZE = 32; -var PADDING = 3; -Script.include(["libraries/toolBars.js"]); -var toolBar = new ToolBar(0, 0, ToolBar.VERTICAL, "highfidelity.attachedEntities.toolbar", function(screenSize) { - return { - x: (BUTTON_SIZE + PADDING), - y: (screenSize.y / 2 - BUTTON_SIZE * 2 + PADDING) - }; -}); -var saveButton = toolBar.addOverlay("image", { - width: BUTTON_SIZE, - height: BUTTON_SIZE, - imageURL: "http://headache.hungry.com/~seth/hifi/save.png", - color: { - red: 255, - green: 255, - blue: 255 - }, - alpha: 1 -}); -var loadButton = toolBar.addOverlay("image", { - width: BUTTON_SIZE, - height: BUTTON_SIZE, - imageURL: "http://headache.hungry.com/~seth/hifi/load.png", - color: { - red: 255, - green: 255, - blue: 255 - }, - alpha: 1 -}); +if (SHOW_TOOL_BAR) { + HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; + var BUTTON_SIZE = 32; + var PADDING = 3; + Script.include(["libraries/toolBars.js"]); + var toolBar = new ToolBar(0, 0, ToolBar.VERTICAL, "highfidelity.attachedEntities.toolbar", function(screenSize) { + return { + x: (BUTTON_SIZE + PADDING), + y: (screenSize.y / 2 - BUTTON_SIZE * 2 + PADDING) + }; + }); + var saveButton = toolBar.addOverlay("image", { + width: BUTTON_SIZE, + height: BUTTON_SIZE, + imageURL: "http://headache.hungry.com/~seth/hifi/save.png", + color: { + red: 255, + green: 255, + blue: 255 + }, + alpha: 1 + }); + var loadButton = toolBar.addOverlay("image", { + width: BUTTON_SIZE, + height: BUTTON_SIZE, + imageURL: "http://headache.hungry.com/~seth/hifi/load.png", + color: { + red: 255, + green: 255, + blue: 255 + }, + alpha: 1 + }); +} function mousePressEvent(event) { @@ -73,10 +76,14 @@ function mousePressEvent(event) { } function scriptEnding() { - toolBar.cleanup(); + if (SHOW_TOOL_BAR) { + toolBar.cleanup(); + } } -Controller.mousePressEvent.connect(mousePressEvent); +if (SHOW_TOOL_BAR) { + Controller.mousePressEvent.connect(mousePressEvent); +} Script.scriptEnding.connect(scriptEnding); diff --git a/examples/defaultScripts.js b/examples/defaultScripts.js index 5ca62470ee..35af5f4eae 100644 --- a/examples/defaultScripts.js +++ b/examples/defaultScripts.js @@ -21,3 +21,4 @@ Script.load("controllers/squeezeHands.js"); Script.load("grab.js"); Script.load("directory.js"); Script.load("dialTone.js"); +Script.load("attachedEntitiesManager.js"); From ad2a7bfc3c4048bae461a0de08244ab0108c92fc Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 3 Feb 2016 10:54:08 -0800 Subject: [PATCH 3/3] code review --- examples/attachedEntitiesManager.js | 4 ++-- examples/controllers/handControllerGrab.js | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/attachedEntitiesManager.js b/examples/attachedEntitiesManager.js index c44ac66a44..1cdd61ad39 100644 --- a/examples/attachedEntitiesManager.js +++ b/examples/attachedEntitiesManager.js @@ -40,7 +40,7 @@ if (SHOW_TOOL_BAR) { var saveButton = toolBar.addOverlay("image", { width: BUTTON_SIZE, height: BUTTON_SIZE, - imageURL: "http://headache.hungry.com/~seth/hifi/save.png", + imageURL: ".../save.png", color: { red: 255, green: 255, @@ -51,7 +51,7 @@ if (SHOW_TOOL_BAR) { var loadButton = toolBar.addOverlay("image", { width: BUTTON_SIZE, height: BUTTON_SIZE, - imageURL: "http://headache.hungry.com/~seth/hifi/load.png", + imageURL: ".../load.png", color: { red: 255, green: 255, diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 842c54b86d..ee3184d78f 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -1224,6 +1224,7 @@ function MyController(hand) { return true; } } + return false; } this.getPresetPosition = function() {