From e2e19884bb3f1d5ef8320bd58f16c17f9a01cd4a Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Tue, 31 Jan 2017 13:40:34 -0800 Subject: [PATCH] Tablet should work even when not connected to any domain. handControllerGrab.js and WebTablet.js now parents objects to the AVATAR_SELF_ID parentID, instead of using MyAvatar.sessionUUID, which is unavailable when not connected to any domain. I removed several early returns handControllerGrab.js that prevented grabbing from working if MyAvatar.sessionUUID was invalid. There were places in the EntityItem.cpp and EntityScriptingInterface.cpp C++ that would log an error if parentID was set to AVATAR_SELF_ID. This was to prevent AVATAR_SELF_ID from ever going over the network. Instead, we now prevent this by replacing all outgoing references of AVATAR_SELF_ID with the sessionID of the current node. --- libraries/entities/src/EntityItem.cpp | 10 +++++++- .../entities/src/EntityScriptingInterface.cpp | 8 ------- .../system/controllers/handControllerGrab.js | 23 ++++++++++--------- scripts/system/libraries/WebTablet.js | 5 +++- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 5cd92a5638..d763eea7e3 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -281,7 +281,15 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet APPEND_ENTITY_PROPERTY(PROP_HREF, getHref()); APPEND_ENTITY_PROPERTY(PROP_DESCRIPTION, getDescription()); APPEND_ENTITY_PROPERTY(PROP_ACTION_DATA, getActionData()); - APPEND_ENTITY_PROPERTY(PROP_PARENT_ID, getParentID()); + + // convert AVATAR_SELF_ID to actual sessionUUID. + QUuid actualParentID = getParentID(); + if (actualParentID == AVATAR_SELF_ID) { + auto nodeList = DependencyManager::get(); + actualParentID = nodeList->getSessionUUID(); + } + APPEND_ENTITY_PROPERTY(PROP_PARENT_ID, actualParentID); + APPEND_ENTITY_PROPERTY(PROP_PARENT_JOINT_INDEX, getParentJointIndex()); APPEND_ENTITY_PROPERTY(PROP_QUERY_AA_CUBE, getQueryAACube()); APPEND_ENTITY_PROPERTY(PROP_LAST_EDITED_BY, getLastEditedBy()); diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 46bc46adab..0d42c55fbd 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -190,11 +190,6 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties propertiesWithSimID.setOwningAvatarID(myNodeID); } - if (propertiesWithSimID.getParentID() == AVATAR_SELF_ID) { - qCDebug(entities) << "ERROR: Cannot set entity parent ID to the local-only MyAvatar ID"; - propertiesWithSimID.setParentID(QUuid()); - } - auto dimensions = propertiesWithSimID.getDimensions(); float volume = dimensions.x * dimensions.y * dimensions.z; auto density = propertiesWithSimID.getDensity(); @@ -371,9 +366,6 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& if (!scriptSideProperties.parentIDChanged()) { properties.setParentID(entity->getParentID()); - } else if (scriptSideProperties.getParentID() == AVATAR_SELF_ID) { - qCDebug(entities) << "ERROR: Cannot set entity parent ID to the local-only MyAvatar ID"; - properties.setParentID(QUuid()); } if (!scriptSideProperties.parentJointIndexChanged()) { properties.setParentJointIndex(entity->getParentJointIndex()); diff --git a/scripts/system/controllers/handControllerGrab.js b/scripts/system/controllers/handControllerGrab.js index 972d95e9e9..69fb01eab7 100644 --- a/scripts/system/controllers/handControllerGrab.js +++ b/scripts/system/controllers/handControllerGrab.js @@ -143,6 +143,7 @@ var ONE_VEC = { }; var NULL_UUID = "{00000000-0000-0000-0000-000000000000}"; +var AVATAR_SELF_ID = "{00000000-0000-0000-0000-000000000001}"; var DEFAULT_REGISTRATION_POINT = { x: 0.5, y: 0.5, z: 0.5 }; var INCHES_TO_METERS = 1.0 / 39.3701; @@ -895,9 +896,7 @@ function MyController(hand) { if (!SHOW_GRAB_POINT_SPHERE) { return; } - if (!MyAvatar.sessionUUID) { - return; - } + if (!this.grabPointSphere) { this.grabPointSphere = Overlays.addOverlay("sphere", { localPosition: getGrabPointSphereOffset(this.handToController()), @@ -909,7 +908,7 @@ function MyController(hand) { visible: true, ignoreRayIntersection: true, drawInFront: false, - parentID: MyAvatar.sessionUUID, + parentID: AVATAR_SELF_ID, parentJointIndex: MyAvatar.getJointIndex(this.hand === RIGHT_HAND ? "_CONTROLLER_RIGHTHAND" : "_CONTROLLER_LEFTHAND") @@ -961,9 +960,6 @@ function MyController(hand) { if (this.stylus) { return; } - if (!MyAvatar.sessionUUID) { - return; - } var stylusProperties = { url: Script.resourcesPath() + "meshes/tablet-stylus-fat.fbx", @@ -977,7 +973,7 @@ function MyController(hand) { visible: true, ignoreRayIntersection: true, drawInFront: false, - parentID: MyAvatar.sessionUUID, + parentID: AVATAR_SELF_ID, parentJointIndex: MyAvatar.getJointIndex(this.hand === RIGHT_HAND ? "_CAMERA_RELATIVE_CONTROLLER_RIGHTHAND" : "_CAMERA_RELATIVE_CONTROLLER_LEFTHAND") @@ -2341,7 +2337,7 @@ function MyController(hand) { } var reparentProps = { - parentID: MyAvatar.sessionUUID, + parentID: AVATAR_SELF_ID, parentJointIndex: handJointIndex, velocity: {x: 0, y: 0, z: 0}, angularVelocity: {x: 0, y: 0, z: 0} @@ -2478,7 +2474,7 @@ function MyController(hand) { if (this.state == STATE_HOLD && now - this.lastUnequipCheckTime > MSECS_PER_SEC * CHECK_TOO_FAR_UNEQUIP_TIME) { this.lastUnequipCheckTime = now; - if (props.parentID == MyAvatar.sessionUUID) { + if (props.parentID == AVATAR_SELF_ID) { var handPosition; if (this.ignoreIK) { handPosition = getControllerWorldLocation(this.handToController(), false).position; @@ -3012,7 +3008,7 @@ function MyController(hand) { }; this.thisHandIsParent = function(props) { - if (props.parentID != MyAvatar.sessionUUID) { + if (props.parentID !== MyAvatar.sessionUUID && props.parentID !== AVATAR_SELF_ID) { return false; } @@ -3046,16 +3042,21 @@ function MyController(hand) { // find children of avatar's hand joint var handJointIndex = MyAvatar.getJointIndex(this.hand === RIGHT_HAND ? "RightHand" : "LeftHand"); var children = Entities.getChildrenIDsOfJoint(MyAvatar.sessionUUID, handJointIndex); + children = children.concat(Entities.getChildrenIDsOfJoint(AVATAR_SELF_ID, handJointIndex)); + // find children of faux controller joint var controllerJointIndex = MyAvatar.getJointIndex(this.hand === RIGHT_HAND ? "_CONTROLLER_RIGHTHAND" : "_CONTROLLER_LEFTHAND"); children = children.concat(Entities.getChildrenIDsOfJoint(MyAvatar.sessionUUID, controllerJointIndex)); + children = children.concat(Entities.getChildrenIDsOfJoint(AVATAR_SELF_ID, controllerJointIndex)); + // find children of faux camera-relative controller joint var controllerCRJointIndex = MyAvatar.getJointIndex(this.hand === RIGHT_HAND ? "_CAMERA_RELATIVE_CONTROLLER_RIGHTHAND" : "_CAMERA_RELATIVE_CONTROLLER_LEFTHAND"); children = children.concat(Entities.getChildrenIDsOfJoint(MyAvatar.sessionUUID, controllerCRJointIndex)); + children = children.concat(Entities.getChildrenIDsOfJoint(AVATAR_SELF_ID, controllerCRJointIndex)); children.forEach(function(childID) { if (childID !== _this.stylus) { diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 65551b2140..29561362d5 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -25,6 +25,8 @@ var ROT_Y_180 = {x: 0, y: 1, z: 0, w: 0}; var TABLET_TEXTURE_RESOLUTION = { x: 480, y: 706 }; var INCHES_TO_METERS = 1 / 39.3701; +var AVATAR_SELF_ID = "{00000000-0000-0000-0000-000000000001}"; + var TABLET_URL = Script.resourcesPath() + "meshes/tablet-with-home-button.fbx"; // will need to be recaclulated if dimensions of fbx model change. @@ -101,7 +103,7 @@ WebTablet = function (url, width, dpi, hand, clientOnly) { "grabbableKey": {"grabbable": true} }), dimensions: {x: this.width, y: this.height, z: this.depth}, - parentID: MyAvatar.sessionUUID + parentID: AVATAR_SELF_ID }; // compute position, rotation & parentJointIndex of the tablet @@ -310,6 +312,7 @@ WebTablet.prototype.register = function() { WebTablet.prototype.cleanUpOldTabletsOnJoint = function(jointIndex) { var children = Entities.getChildrenIDsOfJoint(MyAvatar.sessionUUID, jointIndex); + children = children.concat(Entities.getChildrenIDsOfJoint(AVATAR_SELF_ID, jointIndex)); print("cleanup " + children); children.forEach(function(childID) { var props = Entities.getEntityProperties(childID, ["name"]);