From 949ed3b33da797dc45472af25dbc094725badb04 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 14 Oct 2017 07:17:23 +1300 Subject: [PATCH 1/6] Add some Quat and Uuid JavaScript helper properties --- libraries/script-engine/src/Quat.h | 5 +++++ libraries/script-engine/src/ScriptUUID.h | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/libraries/script-engine/src/Quat.h b/libraries/script-engine/src/Quat.h index 3b3a6fde7c..796b2a4811 100644 --- a/libraries/script-engine/src/Quat.h +++ b/libraries/script-engine/src/Quat.h @@ -33,6 +33,7 @@ /// Scriptable interface a Quaternion helper class object. Used exclusively in the JavaScript API class Quat : public QObject, protected QScriptable { Q_OBJECT + Q_PROPERTY(glm::quat ZERO READ ZERO CONSTANT) public slots: glm::quat multiply(const glm::quat& q1, const glm::quat& q2); @@ -63,6 +64,10 @@ public slots: bool equal(const glm::quat& q1, const glm::quat& q2); glm::quat cancelOutRollAndPitch(const glm::quat& q); glm::quat cancelOutRoll(const glm::quat& q); + +private: + const glm::quat& ZERO() { return Quaternions::IDENTITY; } + }; #endif // hifi_Quat_h diff --git a/libraries/script-engine/src/ScriptUUID.h b/libraries/script-engine/src/ScriptUUID.h index 221f9c46f0..e5360754ae 100644 --- a/libraries/script-engine/src/ScriptUUID.h +++ b/libraries/script-engine/src/ScriptUUID.h @@ -20,6 +20,8 @@ /// Scriptable interface for a UUID helper class object. Used exclusively in the JavaScript API class ScriptUUID : public QObject, protected QScriptable { Q_OBJECT + Q_PROPERTY(QString NULL READ NULL_UUID CONSTANT) // String for use in scripts. + Q_PROPERTY(QString SELF READ SELF_UUID CONSTANT) public slots: QUuid fromString(const QString& string); @@ -28,6 +30,13 @@ public slots: bool isEqual(const QUuid& idA, const QUuid& idB); bool isNull(const QUuid& id); void print(const QString& label, const QUuid& id); + +private: + const QString NULL_UUID() { return NULL_ID; } + const QString SELF_UUID() { return SELF_ID; } + + const QString NULL_ID{ "{00000000-0000-0000-0000-000000000000}" }; + const QString SELF_ID{ AVATAR_SELF_ID.toString() }; }; #endif // hifi_ScriptUUID_h From fc4e440dc46dac74b12397a942ef29ffdb2bdfe5 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 14 Oct 2017 08:32:14 +1300 Subject: [PATCH 2/6] Update system scripts to use new properties --- scripts/system/attachedEntitiesManager.js | 7 +- scripts/system/away.js | 3 +- .../system/controllers/controllerDisplay.js | 6 +- .../controllerModules/equipEntity.js | 6 +- .../controllerModules/farActionGrabEntity.js | 4 +- .../controllerModules/hudOverlayPointer.js | 2 +- .../controllerModules/nearActionGrabEntity.js | 6 +- .../controllerModules/nearParentGrabEntity.js | 12 +- .../nearParentGrabOverlay.js | 6 +- .../controllerModules/overlayLaserInput.js | 2 +- .../controllerModules/tabletStylusInput.js | 6 +- .../controllers/controllerModules/teleport.js | 2 +- .../controllerModules/webEntityLaserInput.js | 18 +- scripts/system/edit.js | 2 +- scripts/system/libraries/WebTablet.js | 5 +- .../libraries/controllerDispatcherUtils.js | 15 +- scripts/system/libraries/entityCameraTool.js | 14 +- .../system/libraries/entitySelectionTool.js | 200 ++++-------------- scripts/system/libraries/overlayUtils.js | 4 +- scripts/system/libraries/touchEventUtils.js | 34 +-- scripts/system/nameTag.js | 9 +- scripts/tutorials/createTetherballStick.js | 1 - 22 files changed, 109 insertions(+), 255 deletions(-) diff --git a/scripts/system/attachedEntitiesManager.js b/scripts/system/attachedEntitiesManager.js index ee852d8d65..c0144e772f 100644 --- a/scripts/system/attachedEntitiesManager.js +++ b/scripts/system/attachedEntitiesManager.js @@ -12,7 +12,6 @@ Script.include("libraries/utils.js"); -var NULL_UUID = "{00000000-0000-0000-0000-000000000000}"; var DEFAULT_WEARABLE_DATA = { joints: {} }; @@ -116,7 +115,7 @@ function AttachedEntitiesManager() { var allowedJoints = getEntityCustomData('wearable', grabbedEntity, DEFAULT_WEARABLE_DATA).joints; var props = Entities.getEntityProperties(grabbedEntity, ["position", "parentID", "parentJointIndex"]); - if (props.parentID === NULL_UUID || props.parentID === MyAvatar.sessionUUID) { + if (props.parentID === Uuid.NULL || props.parentID === MyAvatar.sessionUUID) { var bestJointName = ""; var bestJointIndex = -1; var bestJointDistance = 0; @@ -168,7 +167,7 @@ function AttachedEntitiesManager() { if (updatePresets) { this.updateRelativeOffsets(newEntity); } - } else if (props.parentID != NULL_UUID) { + } else if (props.parentID != Uuid.NULL) { // drop the entity and set it to have no parent (not on the avatar), unless it's being equipped in a hand. if (props.parentID === MyAvatar.sessionUUID && (props.parentJointIndex == MyAvatar.getJointIndex("RightHand") || @@ -176,7 +175,7 @@ function AttachedEntitiesManager() { // this is equipped on a hand -- don't clear the parent. } else { var wearProps = Entities.getEntityProperties(grabbedEntity); - wearProps.parentID = NULL_UUID; + wearProps.parentID = Uuid.NULL; wearProps.parentJointIndex = -1; delete wearProps.id; delete wearProps.created; diff --git a/scripts/system/away.js b/scripts/system/away.js index 18eb5fa946..38589050f2 100644 --- a/scripts/system/away.js +++ b/scripts/system/away.js @@ -30,7 +30,6 @@ var OVERLAY_DATA = { }; var AVATAR_MOVE_FOR_ACTIVE_DISTANCE = 0.8; // meters -- no longer away if avatar moves this far while away -var AVATAR_SELF_ID = "{00000000-0000-0000-0000-000000000001}"; var CAMERA_MATRIX = -7; var OVERLAY_DATA_HMD = { @@ -44,7 +43,7 @@ var OVERLAY_DATA_HMD = { scale: 2 * MyAvatar.sensorToWorldScale, emissive: true, drawInFront: true, - parentID: AVATAR_SELF_ID, + parentID: Uuid.SELF, parentJointIndex: CAMERA_MATRIX }; diff --git a/scripts/system/controllers/controllerDisplay.js b/scripts/system/controllers/controllerDisplay.js index 3c2794cf96..0296243018 100644 --- a/scripts/system/controllers/controllerDisplay.js +++ b/scripts/system/controllers/controllerDisplay.js @@ -9,8 +9,6 @@ /* globals createControllerDisplay:true deleteControllerDisplay:true */ -var PARENT_ID = "{00000000-0000-0000-0000-000000000001}"; - function clamp(value, min, max) { if (value < min) { return min; @@ -178,7 +176,7 @@ createControllerDisplay = function(config) { dimensions: Vec3.multiply(sensorScaleFactor, controller.dimensions), localRotation: controller.rotation, localPosition: Vec3.multiply(sensorScaleFactor, position), - parentID: PARENT_ID, + parentID: Uuid.SELF, parentJointIndex: controller.jointIndex, ignoreRayIntersection: true }); @@ -198,7 +196,7 @@ createControllerDisplay = function(config) { url: part.modelURL, localPosition: partPosition, localRotation: innerRotation, - parentID: PARENT_ID, + parentID: Uuid.SELF, parentJointIndex: controller.jointIndex, ignoreRayIntersection: true }; diff --git a/scripts/system/controllers/controllerModules/equipEntity.js b/scripts/system/controllers/controllerModules/equipEntity.js index 4978f225ce..543d04b192 100644 --- a/scripts/system/controllers/controllerModules/equipEntity.js +++ b/scripts/system/controllers/controllerModules/equipEntity.js @@ -7,7 +7,7 @@ /* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, AVATAR_SELF_ID, - getControllerJointIndex, NULL_UUID, enableDispatcherModule, disableDispatcherModule, + getControllerJointIndex, enableDispatcherModule, disableDispatcherModule, Messages, makeDispatcherModuleParameters, makeRunningValues, Settings, entityHasActions, Vec3, Overlays, flatten, Xform, getControllerWorldLocation, ensureDynamic, entityIsCloneable, cloneEntity, DISPATCHER_PROPERTIES @@ -333,7 +333,7 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa var props = controllerData.nearbyEntityPropertiesByID[hotspot.entityID]; var hasParent = true; - if (props.parentID === NULL_UUID) { + if (props.parentID === Uuid.NULL) { hasParent = false; } @@ -539,7 +539,7 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa this.endEquipEntity = function () { Entities.editEntity(this.targetEntityID, { - parentID: NULL_UUID, + parentID: Uuid.NULL, parentJointIndex: -1 }); diff --git a/scripts/system/controllers/controllerModules/farActionGrabEntity.js b/scripts/system/controllers/controllerModules/farActionGrabEntity.js index 2ef7b1efeb..5085152622 100644 --- a/scripts/system/controllers/controllerModules/farActionGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farActionGrabEntity.js @@ -8,7 +8,7 @@ /* jslint bitwise: true */ /* global Script, Controller, LaserPointers, RayPick, RIGHT_HAND, LEFT_HAND, Mat4, MyAvatar, Vec3, Camera, Quat, - getGrabPointSphereOffset, getEnabledModuleByName, makeRunningValues, Entities, NULL_UUID, + getGrabPointSphereOffset, getEnabledModuleByName, makeRunningValues, Entities, enableDispatcherModule, disableDispatcherModule, entityIsDistanceGrabbable, makeDispatcherModuleParameters, MSECS_PER_SEC, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, PICK_MAX_DISTANCE, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD, @@ -238,7 +238,7 @@ Script.include("/~/system/libraries/controllers.js"); tag: "far-grab-" + MyAvatar.sessionUUID, ttl: ACTION_TTL }); - if (this.actionID === NULL_UUID) { + if (this.actionID === Uuid.NULL) { this.actionID = null; } diff --git a/scripts/system/controllers/controllerModules/hudOverlayPointer.js b/scripts/system/controllers/controllerModules/hudOverlayPointer.js index fe1dedefb8..220551ccb7 100644 --- a/scripts/system/controllers/controllerModules/hudOverlayPointer.js +++ b/scripts/system/controllers/controllerModules/hudOverlayPointer.js @@ -11,7 +11,7 @@ // /* global Script, Controller, LaserPointers, RayPick, RIGHT_HAND, LEFT_HAND, Mat4, MyAvatar, Vec3, Camera, Quat, - getGrabPointSphereOffset, getEnabledModuleByName, makeRunningValues, Entities, NULL_UUID, + getGrabPointSphereOffset, getEnabledModuleByName, makeRunningValues, Entities, enableDispatcherModule, disableDispatcherModule, entityIsDistanceGrabbable, makeDispatcherModuleParameters, MSECS_PER_SEC, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, PICK_MAX_DISTANCE, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD, diff --git a/scripts/system/controllers/controllerModules/nearActionGrabEntity.js b/scripts/system/controllers/controllerModules/nearActionGrabEntity.js index 2484067655..cdc5e02d88 100644 --- a/scripts/system/controllers/controllerModules/nearActionGrabEntity.js +++ b/scripts/system/controllers/controllerModules/nearActionGrabEntity.js @@ -6,7 +6,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html /* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, - getControllerJointIndex, getGrabbableData, NULL_UUID, enableDispatcherModule, disableDispatcherModule, + getControllerJointIndex, getGrabbableData, enableDispatcherModule, disableDispatcherModule, propsArePhysical, Messages, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, entityIsGrabbable, Quat, Vec3, MSECS_PER_SEC, getControllerWorldLocation, makeDispatcherModuleParameters, makeRunningValues, TRIGGER_OFF_VALUE, NEAR_GRAB_RADIUS, findGroupParent, entityIsCloneable, propsAreCloneDynamic, cloneEntity, @@ -101,7 +101,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); kinematicSetVelocity: true, ignoreIK: this.ignoreIK }); - if (this.actionID === NULL_UUID) { + if (this.actionID === Uuid.NULL) { this.actionID = null; return; } @@ -183,7 +183,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); if (targetProps) { if ((!propsArePhysical(targetProps) && !propsAreCloneDynamic(targetProps)) || - targetProps.parentID != NULL_UUID) { + targetProps.parentID !== Uuid.NULL) { return makeRunningValues(false, [], []); // let nearParentGrabEntity handle it } else { this.targetEntityID = targetProps.id; diff --git a/scripts/system/controllers/controllerModules/nearParentGrabEntity.js b/scripts/system/controllers/controllerModules/nearParentGrabEntity.js index 70d91bf1ec..9c797154eb 100644 --- a/scripts/system/controllers/controllerModules/nearParentGrabEntity.js +++ b/scripts/system/controllers/controllerModules/nearParentGrabEntity.js @@ -6,7 +6,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -/* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, AVATAR_SELF_ID, getControllerJointIndex, NULL_UUID, +/* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, AVATAR_SELF_ID, getControllerJointIndex, enableDispatcherModule, disableDispatcherModule, propsArePhysical, Messages, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, TRIGGER_OFF_VALUE, makeDispatcherModuleParameters, entityIsGrabbable, makeRunningValues, NEAR_GRAB_RADIUS, findGroupParent, Vec3, cloneEntity, entityIsCloneable, propsAreCloneDynamic, HAPTIC_PULSE_STRENGTH, @@ -120,7 +120,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); this.hapticTargetID = null; var props = controllerData.nearbyEntityPropertiesByID[this.targetEntityID]; if (this.thisHandIsParent(props)) { - if (this.previousParentID[this.targetEntityID] === NULL_UUID || this.previousParentID === undefined) { + if (this.previousParentID[this.targetEntityID] === Uuid.NULL || this.previousParentID === undefined) { Entities.editEntity(this.targetEntityID, { parentID: this.previousParentID[this.targetEntityID], parentJointIndex: this.previousParentJointIndex[this.targetEntityID] @@ -193,7 +193,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); var UNHOOK_LOOP_DETECT_MS = 200; if (_this.previouslyUnhooked[childID]) { if (now - _this.previouslyUnhooked[childID] < UNHOOK_LOOP_DETECT_MS) { - previousParentID = NULL_UUID; + previousParentID = Uuid.NULL; previousParentJointIndex = -1; } } @@ -204,7 +204,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); parentJointIndex: previousParentJointIndex }); } else { - Entities.editEntity(childID, { parentID: NULL_UUID }); + Entities.editEntity(childID, { parentID: Uuid.NULL }); } }); } @@ -253,7 +253,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); if (targetProps) { if ((propsArePhysical(targetProps) || propsAreCloneDynamic(targetProps)) && - targetProps.parentID == NULL_UUID) { + targetProps.parentID === Uuid.NULL) { return makeRunningValues(false, [], []); // let nearActionGrabEntity handle it } else { this.targetEntityID = targetProps.id; @@ -268,7 +268,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); this.run = function (controllerData, deltaTime) { if (this.grabbing) { if (controllerData.triggerClicks[this.hand] < TRIGGER_OFF_VALUE && - controllerData.secondaryValues[this.hand] < TRIGGER_OFF_VALUE) { + controllerData.secondaryValues[this.hand] < TRIGGER_OFF_VALUE) { this.endNearParentingGrabEntity(controllerData); return makeRunningValues(false, [], []); } diff --git a/scripts/system/controllers/controllerModules/nearParentGrabOverlay.js b/scripts/system/controllers/controllerModules/nearParentGrabOverlay.js index f9557f685f..112eaf4c94 100644 --- a/scripts/system/controllers/controllerModules/nearParentGrabOverlay.js +++ b/scripts/system/controllers/controllerModules/nearParentGrabOverlay.js @@ -6,7 +6,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -/* global Script, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, AVATAR_SELF_ID, getControllerJointIndex, NULL_UUID, +/* global Script, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, AVATAR_SELF_ID, getControllerJointIndex, enableDispatcherModule, disableDispatcherModule, Messages, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, makeDispatcherModuleParameters, Overlays, makeRunningValues, Vec3, resizeTablet, getTabletWidthFromSettings, NEAR_GRAB_RADIUS @@ -130,9 +130,9 @@ Script.include("/~/system/libraries/utils.js"); this.endNearParentingGrabOverlay = function () { var previousParentID = this.previousParentID[this.grabbedThingID]; - if ((previousParentID === NULL_UUID || previousParentID === null) && !this.robbed) { + if ((previousParentID === Uuid.NULL || previousParentID === null) && !this.robbed) { Overlays.editOverlay(this.grabbedThingID, { - parentID: NULL_UUID, + parentID: Uuid.NULL, parentJointIndex: -1 }); } else if (!this.robbed){ diff --git a/scripts/system/controllers/controllerModules/overlayLaserInput.js b/scripts/system/controllers/controllerModules/overlayLaserInput.js index 7dace85ec4..aabe84aecc 100644 --- a/scripts/system/controllers/controllerModules/overlayLaserInput.js +++ b/scripts/system/controllers/controllerModules/overlayLaserInput.js @@ -5,7 +5,7 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -/* global Script, Entities, Controller, RIGHT_HAND, LEFT_HAND, NULL_UUID, enableDispatcherModule, disableDispatcherModule, +/* global Script, Entities, Controller, RIGHT_HAND, LEFT_HAND, enableDispatcherModule, disableDispatcherModule, makeRunningValues, Messages, Quat, Vec3, makeDispatcherModuleParameters, Overlays, ZERO_VEC, AVATAR_SELF_ID, HMD, INCHES_TO_METERS, DEFAULT_REGISTRATION_POINT, getGrabPointSphereOffset, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD, DEFAULT_SEARCH_SPHERE_DISTANCE, TRIGGER_ON_VALUE, diff --git a/scripts/system/controllers/controllerModules/tabletStylusInput.js b/scripts/system/controllers/controllerModules/tabletStylusInput.js index 29fa878cb1..b5599b0d64 100644 --- a/scripts/system/controllers/controllerModules/tabletStylusInput.js +++ b/scripts/system/controllers/controllerModules/tabletStylusInput.js @@ -6,7 +6,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html /* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, - NULL_UUID, enableDispatcherModule, disableDispatcherModule, makeRunningValues, + enableDispatcherModule, disableDispatcherModule, makeRunningValues, Messages, Quat, Vec3, getControllerWorldLocation, makeDispatcherModuleParameters, Overlays, ZERO_VEC, AVATAR_SELF_ID, HMD, INCHES_TO_METERS, DEFAULT_REGISTRATION_POINT, Settings, getGrabPointSphereOffset, getEnabledModuleByName @@ -286,7 +286,7 @@ Script.include("/~/system/libraries/controllers.js"); } // add the tabletScreen, if it is valid - if (HMD.tabletScreenID && HMD.tabletScreenID !== NULL_UUID && + if (HMD.tabletScreenID && HMD.tabletScreenID !== Uuid.NULL && Overlays.getProperty(HMD.tabletScreenID, "visible")) { stylusTarget = TouchEventUtils.calculateTouchTargetFromOverlay(this.stylusTip, HMD.tabletScreenID); if (stylusTarget) { @@ -295,7 +295,7 @@ Script.include("/~/system/libraries/controllers.js"); } // add the tablet home button. - if (HMD.homeButtonID && HMD.homeButtonID !== NULL_UUID && + if (HMD.homeButtonID && HMD.homeButtonID !== Uuid.NULL && Overlays.getProperty(HMD.homeButtonID, "visible")) { stylusTarget = TouchEventUtils.calculateTouchTargetFromOverlay(this.stylusTip, HMD.homeButtonID); if (stylusTarget) { diff --git a/scripts/system/controllers/controllerModules/teleport.js b/scripts/system/controllers/controllerModules/teleport.js index d2717a1348..ccad9e5d0b 100644 --- a/scripts/system/controllers/controllerModules/teleport.js +++ b/scripts/system/controllers/controllerModules/teleport.js @@ -10,7 +10,7 @@ /* jslint bitwise: true */ -/* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, AVATAR_SELF_ID, getControllerJointIndex, NULL_UUID, +/* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, AVATAR_SELF_ID, getControllerJointIndex, enableDispatcherModule, disableDispatcherModule, Messages, makeDispatcherModuleParameters, makeRunningValues, Vec3, LaserPointers, RayPick, HMD, Uuid, AvatarList */ diff --git a/scripts/system/controllers/controllerModules/webEntityLaserInput.js b/scripts/system/controllers/controllerModules/webEntityLaserInput.js index 339f248547..28062109c6 100644 --- a/scripts/system/controllers/controllerModules/webEntityLaserInput.js +++ b/scripts/system/controllers/controllerModules/webEntityLaserInput.js @@ -8,7 +8,7 @@ /* jslint bitwise: true */ /* global Script, Controller, LaserPointers, RayPick, RIGHT_HAND, LEFT_HAND, Vec3, Quat, getGrabPointSphereOffset, - makeRunningValues, Entities, NULL_UUID, enableDispatcherModule, disableDispatcherModule, makeDispatcherModuleParameters, + makeRunningValues, Entities, enableDispatcherModule, disableDispatcherModule, makeDispatcherModuleParameters, PICK_MAX_DISTANCE, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD, AVATAR_SELF_ID, DEFAULT_SEARCH_SPHERE_DISTANCE, TRIGGER_ON_VALUE, ZERO_VEC, Overlays */ @@ -90,15 +90,15 @@ Script.include("/~/system/libraries/controllers.js"); var HAPTIC_STYLUS_DURATION = 20.0; function laserTargetHasKeyboardFocus(laserTarget) { - if (laserTarget && laserTarget !== NULL_UUID) { + if (laserTarget && laserTarget !== Uuid.NULL) { return Entities.keyboardFocusOverlay === laserTarget; } } function setKeyboardFocusOnLaserTarget(laserTarget) { - if (laserTarget && laserTarget !== NULL_UUID) { + if (laserTarget && laserTarget !== Uuid.NULL) { Entities.wantsHandControllerPointerEvents(laserTarget); - Overlays.keyboardFocusOverlay = NULL_UUID; + Overlays.keyboardFocusOverlay = Uuid.NULL; Entities.keyboardFocusEntity = laserTarget; } } @@ -117,7 +117,7 @@ Script.include("/~/system/libraries/controllers.js"); button: "None" }; - if (laserTarget.entityID && laserTarget.entityID !== NULL_UUID) { + if (laserTarget.entityID && laserTarget.entityID !== Uuid.NULL) { Entities.sendHoverEnterEntity(laserTarget.entityID, pointerEvent); } } @@ -137,7 +137,7 @@ Script.include("/~/system/libraries/controllers.js"); button: "None" }; - if (laserTarget.entityID && laserTarget.entityID !== NULL_UUID) { + if (laserTarget.entityID && laserTarget.entityID !== Uuid.NULL) { Entities.sendMouseMoveOnEntity(laserTarget.entityID, pointerEvent); Entities.sendHoverOverEntity(laserTarget.entityID, pointerEvent); } @@ -156,7 +156,7 @@ Script.include("/~/system/libraries/controllers.js"); isPrimaryHeld: true }; - if (laserTarget.entityID && laserTarget.entityID !== NULL_UUID) { + if (laserTarget.entityID && laserTarget.entityID !== Uuid.NULL) { Entities.sendMousePressOnEntity(laserTarget.entityID, pointerEvent); Entities.sendClickDownOnEntity(laserTarget.entityID, pointerEvent); } @@ -173,7 +173,7 @@ Script.include("/~/system/libraries/controllers.js"); button: "Primary" }; - if (laserTarget.entityID && laserTarget.entityID !== NULL_UUID) { + if (laserTarget.entityID && laserTarget.entityID !== Uuid.NULL) { Entities.sendMouseReleaseOnEntity(laserTarget.entityID, pointerEvent); Entities.sendClickReleaseOnEntity(laserTarget.entityID, pointerEvent); Entities.sendHoverLeaveEntity(laserTarget.entityID, pointerEvent); @@ -192,7 +192,7 @@ Script.include("/~/system/libraries/controllers.js"); isPrimaryHeld: true }; - if (laserTarget.entityID && laserTarget.entityID !== NULL_UUID) { + if (laserTarget.entityID && laserTarget.entityID !== Uuid.NULL) { Entities.sendMouseMoveOnEntity(laserTarget.entityID, pointerEvent); Entities.sendHoldingClickOnEntity(laserTarget.entityID, pointerEvent); } diff --git a/scripts/system/edit.js b/scripts/system/edit.js index d6d4de2a4b..3e7c057e90 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -1360,7 +1360,7 @@ function unparentSelectedEntities() { } selectedEntities.forEach(function (id, index) { var parentId = Entities.getEntityProperties(id, ["parentID"]).parentID; - if (parentId !== null && parentId.length > 0 && parentId !== "{00000000-0000-0000-0000-000000000000}") { + if (parentId !== null && parentId.length > 0 && parentId !== Uuid.NULL) { parentCheck = true; } Entities.editEntity(id, {parentID: null}); diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 92a5857390..33b0f6c45f 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -25,7 +25,6 @@ var ROT_LANDSCAPE = {x: 1.0, y: 1.0, z: 0, w: 0}; var ROT_LANDSCAPE_WINDOW = {x: 0.0, y: 0.0, z: 0.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 NO_HANDS = -1; var DELAY_FOR_30HZ = 33; // milliseconds @@ -100,7 +99,7 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location, visible) { "grabbableKey": {"grabbable": true} }), dimensions: { x: tabletWidth, y: tabletHeight, z: tabletDepth }, - parentID: AVATAR_SELF_ID, + parentID: Uuid.SELF, visible: visible }; @@ -414,7 +413,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)); + children = children.concat(Entities.getChildrenIDsOfJoint(Uuid.SELF, jointIndex)); children.forEach(function(childID) { var props = Entities.getEntityProperties(childID, ["name"]); if (props.name === "WebTablet Tablet") { diff --git a/scripts/system/libraries/controllerDispatcherUtils.js b/scripts/system/libraries/controllerDispatcherUtils.js index d6d80541ee..03af4c8253 100644 --- a/scripts/system/libraries/controllerDispatcherUtils.js +++ b/scripts/system/libraries/controllerDispatcherUtils.js @@ -7,7 +7,7 @@ /* global module, Camera, HMD, MyAvatar, controllerDispatcherPlugins:true, Quat, Vec3, Overlays, Xform, - MSECS_PER_SEC:true , LEFT_HAND:true, RIGHT_HAND:true, NULL_UUID:true, AVATAR_SELF_ID:true, FORBIDDEN_GRAB_TYPES:true, + MSECS_PER_SEC:true , LEFT_HAND:true, RIGHT_HAND:true, FORBIDDEN_GRAB_TYPES:true, HAPTIC_PULSE_STRENGTH:true, HAPTIC_PULSE_DURATION:true, ZERO_VEC:true, ONE_VEC:true, DEFAULT_REGISTRATION_POINT:true, INCHES_TO_METERS:true, TRIGGER_OFF_VALUE:true, @@ -60,9 +60,6 @@ ONE_VEC = { x: 1, y: 1, z: 1 }; LEFT_HAND = 0; RIGHT_HAND = 1; -NULL_UUID = "{00000000-0000-0000-0000-000000000000}"; -AVATAR_SELF_ID = "{00000000-0000-0000-0000-000000000001}"; - FORBIDDEN_GRAB_TYPES = ["Unknown", "Light", "PolyLine", "Zone"]; HAPTIC_PULSE_STRENGTH = 1.0; @@ -284,7 +281,7 @@ ensureDynamic = function (entityID) { // if we distance hold something and keep it very still before releasing it, it ends up // non-dynamic in bullet. If it's too still, give it a little bounce so it will fall. var props = Entities.getEntityProperties(entityID, ["velocity", "dynamic", "parentID"]); - if (props.dynamic && props.parentID === NULL_UUID) { + if (props.dynamic && props.parentID === Uuid.NULL) { var velocity = props.velocity; if (Vec3.length(velocity) < 0.05) { // see EntityMotionState.cpp DYNAMIC_LINEAR_VELOCITY_THRESHOLD velocity = { x: 0.0, y: 0.2, z: 0.0 }; @@ -295,7 +292,7 @@ ensureDynamic = function (entityID) { findGroupParent = function (controllerData, targetProps) { while (targetProps.parentID && - targetProps.parentID !== NULL_UUID && + targetProps.parentID !== Uuid.NULL && Entities.getNestableType(targetProps.parentID) == "entity") { var parentProps = Entities.getEntityProperties(targetProps.parentID, DISPATCHER_PROPERTIES); if (!parentProps) { @@ -314,19 +311,19 @@ findHandChildEntities = function(hand) { // find children of avatar's hand joint var handJointIndex = MyAvatar.getJointIndex(hand === RIGHT_HAND ? "RightHand" : "LeftHand"); var children = Entities.getChildrenIDsOfJoint(MyAvatar.sessionUUID, handJointIndex); - children = children.concat(Entities.getChildrenIDsOfJoint(AVATAR_SELF_ID, handJointIndex)); + children = children.concat(Entities.getChildrenIDsOfJoint(Uuid.SELF, handJointIndex)); // find children of faux controller joint var controllerJointIndex = getControllerJointIndex(hand); children = children.concat(Entities.getChildrenIDsOfJoint(MyAvatar.sessionUUID, controllerJointIndex)); - children = children.concat(Entities.getChildrenIDsOfJoint(AVATAR_SELF_ID, controllerJointIndex)); + children = children.concat(Entities.getChildrenIDsOfJoint(Uuid.SELF, controllerJointIndex)); // find children of faux camera-relative controller joint var controllerCRJointIndex = MyAvatar.getJointIndex(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 = children.concat(Entities.getChildrenIDsOfJoint(Uuid.SELF, controllerCRJointIndex)); return children.filter(function (childID) { var childType = Entities.getNestableType(childID); diff --git a/scripts/system/libraries/entityCameraTool.js b/scripts/system/libraries/entityCameraTool.js index 6becc81d9b..61280013ba 100644 --- a/scripts/system/libraries/entityCameraTool.js +++ b/scripts/system/libraries/entityCameraTool.js @@ -118,20 +118,12 @@ CameraManager = function() { that.targetYaw = 0; that.targetPitch = 0; - that.focalPoint = { - x: 0, - y: 0, - z: 0 - }; - that.targetFocalPoint = { - x: 0, - y: 0, - z: 0 - }; + that.focalPoint = Vec3.ZERO; + that.targetFocalPoint = Vec3.ZERO; easing = false; easingTime = 0; - startOrientation = Quat.fromPitchYawRollDegrees(0, 0, 0); + startOrientation = Quat.ZERO; that.previousCameraMode = null; diff --git a/scripts/system/libraries/entitySelectionTool.js b/scripts/system/libraries/entitySelectionTool.js index 9715cc454c..0e6a9d5310 100644 --- a/scripts/system/libraries/entitySelectionTool.js +++ b/scripts/system/libraries/entitySelectionTool.js @@ -71,44 +71,16 @@ SelectionManager = (function() { that.selections = []; var listeners = []; - that.localRotation = Quat.fromPitchYawRollDegrees(0, 0, 0); - that.localPosition = { - x: 0, - y: 0, - z: 0 - }; - that.localDimensions = { - x: 0, - y: 0, - z: 0 - }; - that.localRegistrationPoint = { - x: 0.5, - y: 0.5, - z: 0.5 - }; + that.localRotation = Quat.ZERO; + that.localPosition = Vec3.ZERO; + that.localDimensions = Vec3.ZERO; + that.localRegistrationPoint = Vec3.HALF; - that.worldRotation = Quat.fromPitchYawRollDegrees(0, 0, 0); - that.worldPosition = { - x: 0, - y: 0, - z: 0 - }; - that.worldDimensions = { - x: 0, - y: 0, - z: 0 - }; - that.worldRegistrationPoint = { - x: 0.5, - y: 0.5, - z: 0.5 - }; - that.centerPosition = { - x: 0, - y: 0, - z: 0 - }; + that.worldRotation = Quat.ZERO; + that.worldPosition = Vec3.ZERO; + that.worldDimensions = Vec3.ZERO; + that.worldRegistrationPoint = Vec3.HALF; + that.centerPosition = Vec3.ZERO; that.saveProperties = function() { that.savedProperties = {}; @@ -350,11 +322,7 @@ SelectionDisplay = (function() { }; var grabberLineWidth = 0.5; var grabberSolid = true; - var grabberMoveUpPosition = { - x: 0, - y: 0, - z: 0 - }; + var grabberMoveUpPosition = Vec3.ZERO; var lightOverlayColor = { red: 255, @@ -363,11 +331,7 @@ SelectionDisplay = (function() { }; var grabberPropertiesCorner = { - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, size: grabberSizeCorner, color: grabberColorCorner, alpha: 1, @@ -380,11 +344,7 @@ SelectionDisplay = (function() { }; var grabberPropertiesEdge = { - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, size: grabberSizeEdge, color: grabberColorEdge, alpha: 1, @@ -397,11 +357,7 @@ SelectionDisplay = (function() { }; var grabberPropertiesFace = { - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, size: grabberSizeFace, color: grabberColorFace, alpha: 1, @@ -414,11 +370,7 @@ SelectionDisplay = (function() { }; var grabberPropertiesCloner = { - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, size: grabberSizeCorner, color: grabberColorCloner, alpha: 1, @@ -436,11 +388,7 @@ SelectionDisplay = (function() { }; var highlightBox = Overlays.addOverlay("cube", { - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, size: 1, color: { red: 90, @@ -457,11 +405,7 @@ SelectionDisplay = (function() { }); var selectionBox = Overlays.addOverlay("cube", { - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, size: 1, color: { red: 255, @@ -478,11 +422,7 @@ SelectionDisplay = (function() { var selectionBoxes = []; var rotationDegreesDisplay = Overlays.addOverlay("text3d", { - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, text: "", color: { red: 0, @@ -513,11 +453,7 @@ SelectionDisplay = (function() { var grabberMoveUp = Overlays.addOverlay("image3d", { url: HIFI_PUBLIC_BUCKET + "images/up-arrow.svg", - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, color: handleColor, alpha: handleAlpha, visible: false, @@ -720,16 +656,8 @@ SelectionDisplay = (function() { var xRailOverlay = Overlays.addOverlay("line3d", { visible: false, lineWidth: 1.0, - start: { - x: 0, - y: 0, - z: 0 - }, - end: { - x: 0, - y: 0, - z: 0 - }, + start: Vec3.ZERO, + end: Vec3.ZERO, color: { red: 255, green: 0, @@ -740,16 +668,8 @@ SelectionDisplay = (function() { var yRailOverlay = Overlays.addOverlay("line3d", { visible: false, lineWidth: 1.0, - start: { - x: 0, - y: 0, - z: 0 - }, - end: { - x: 0, - y: 0, - z: 0 - }, + start: Vec3.ZERO, + end: Vec3.ZERO, color: { red: 0, green: 255, @@ -760,16 +680,8 @@ SelectionDisplay = (function() { var zRailOverlay = Overlays.addOverlay("line3d", { visible: false, lineWidth: 1.0, - start: { - x: 0, - y: 0, - z: 0 - }, - end: { - x: 0, - y: 0, - z: 0 - }, + start: Vec3.ZERO, + end: Vec3.ZERO, color: { red: 0, green: 0, @@ -781,16 +693,8 @@ SelectionDisplay = (function() { var rotateZeroOverlay = Overlays.addOverlay("line3d", { visible: false, lineWidth: 2.0, - start: { - x: 0, - y: 0, - z: 0 - }, - end: { - x: 0, - y: 0, - z: 0 - }, + start: Vec3.ZERO, + end: Vec3.ZERO, color: { red: 255, green: 0, @@ -802,16 +706,8 @@ SelectionDisplay = (function() { var rotateCurrentOverlay = Overlays.addOverlay("line3d", { visible: false, lineWidth: 2.0, - start: { - x: 0, - y: 0, - z: 0 - }, - end: { - x: 0, - y: 0, - z: 0 - }, + start: Vec3.ZERO, + end: Vec3.ZERO, color: { red: 0, green: 0, @@ -822,11 +718,7 @@ SelectionDisplay = (function() { var rotateOverlayInner = Overlays.addOverlay("circle3d", { - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, size: 1, color: { red: 51, @@ -856,11 +748,7 @@ SelectionDisplay = (function() { }); var rotateOverlayOuter = Overlays.addOverlay("circle3d", { - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, size: 1, color: { red: 51, @@ -891,11 +779,7 @@ SelectionDisplay = (function() { }); var rotateOverlayCurrent = Overlays.addOverlay("circle3d", { - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, size: 1, color: { red: 224, @@ -922,11 +806,7 @@ SelectionDisplay = (function() { var yawHandle = Overlays.addOverlay("image3d", { url: ROTATE_ARROW_WEST_NORTH_URL, - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, color: handleColor, alpha: handleAlpha, visible: false, @@ -939,11 +819,7 @@ SelectionDisplay = (function() { var pitchHandle = Overlays.addOverlay("image3d", { url: ROTATE_ARROW_WEST_NORTH_URL, - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, color: handleColor, alpha: handleAlpha, visible: false, @@ -956,11 +832,7 @@ SelectionDisplay = (function() { var rollHandle = Overlays.addOverlay("image3d", { url: ROTATE_ARROW_WEST_NORTH_URL, - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, color: handleColor, alpha: handleAlpha, visible: false, @@ -1636,7 +1508,7 @@ SelectionDisplay = (function() { position = SelectionManager.localPosition; registrationPoint = SelectionManager.localRegistrationPoint; } else { - rotation = Quat.fromPitchYawRollDegrees(0, 0, 0); + rotation = Quat.ZERO; dimensions = SelectionManager.worldDimensions; position = SelectionManager.worldPosition; registrationPoint = SelectionManager.worldRegistrationPoint; @@ -2692,7 +2564,7 @@ SelectionDisplay = (function() { var onBegin = function(event, pickRay, pickResult) { var properties = Entities.getEntityProperties(SelectionManager.selections[0]); initialProperties = properties; - rotation = (spaceMode === SPACE_LOCAL) ? properties.rotation : Quat.fromPitchYawRollDegrees(0, 0, 0); + rotation = (spaceMode === SPACE_LOCAL) ? properties.rotation : Quat.ZERO; if (spaceMode === SPACE_LOCAL) { rotation = SelectionManager.localRotation; diff --git a/scripts/system/libraries/overlayUtils.js b/scripts/system/libraries/overlayUtils.js index a5622ec435..3ba5c2bad2 100644 --- a/scripts/system/libraries/overlayUtils.js +++ b/scripts/system/libraries/overlayUtils.js @@ -18,7 +18,7 @@ OverlayGroup = function(opts) { var overlays = {}; var rootPosition = opts.position || { x: 0, y: 0, z: 0 }; - var rootRotation = opts.rotation || Quat.fromPitchYawRollRadians(0, 0, 0); + var rootRotation = opts.rotation || Quat.ZERO; var visible = opts.visible == true; function updateOverlays() { @@ -36,7 +36,7 @@ OverlayGroup = function(opts) { that.createOverlay = function(type, properties) { properties.position = properties.position || { x: 0, y: 0, z: 0 }; - properties.rotation = properties.rotation || Quat.fromPitchYawRollRadians(0, 0, 0); + properties.rotation = properties.rotation || Quat.ZERO; var overlay = Overlays.addOverlay(type, properties); diff --git a/scripts/system/libraries/touchEventUtils.js b/scripts/system/libraries/touchEventUtils.js index fbd56e16ae..c678c72778 100644 --- a/scripts/system/libraries/touchEventUtils.js +++ b/scripts/system/libraries/touchEventUtils.js @@ -6,28 +6,28 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html /* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, - controllerDispatcher.NULL_UUID, enableDispatcherModule, disableDispatcherModule, makeRunningValues, + enableDispatcherModule, disableDispatcherModule, makeRunningValues, Messages, Quat, Vec3, getControllerWorldLocation, makeDispatcherModuleParameters, Overlays, controllerDispatcher.ZERO_VEC, AVATAR_SELF_ID, HMD, INCHES_TO_METERS, DEFAULT_REGISTRATION_POINT, Settings, getGrabPointSphereOffset */ var controllerDispatcher = Script.require("/~/system/libraries/controllerDispatcherUtils.js"); function touchTargetHasKeyboardFocus(touchTarget) { - if (touchTarget.entityID && touchTarget.entityID !== controllerDispatcher.NULL_UUID) { + if (touchTarget.entityID && touchTarget.entityID !== Uuid.NULL) { return Entities.keyboardFocusEntity === touchTarget.entityID; - } else if (touchTarget.overlayID && touchTarget.overlayID !== controllerDispatcher.NULL_UUID) { + } else if (touchTarget.overlayID && touchTarget.overlayID !== Uuid.NULL) { return Overlays.keyboardFocusOverlay === touchTarget.overlayID; } } function setKeyboardFocusOnTouchTarget(touchTarget) { - if (touchTarget.entityID && touchTarget.entityID !== controllerDispatcher.NULL_UUID && + if (touchTarget.entityID && touchTarget.entityID !== Uuid.NULL && Entities.wantsHandControllerPointerEvents(touchTarget.entityID)) { - Overlays.keyboardFocusOverlay = controllerDispatcher.NULL_UUID; + Overlays.keyboardFocusOverlay = Uuid.NULL; Entities.keyboardFocusEntity = touchTarget.entityID; - } else if (touchTarget.overlayID && touchTarget.overlayID !== controllerDispatcher.NULL_UUID) { + } else if (touchTarget.overlayID && touchTarget.overlayID !== Uuid.NULL) { Overlays.keyboardFocusOverlay = touchTarget.overlayID; - Entities.keyboardFocusEntity = controllerDispatcher.NULL_UUID; + Entities.keyboardFocusEntity = Uuid.NULL; } } @@ -42,9 +42,9 @@ function sendHoverEnterEventToTouchTarget(hand, touchTarget) { button: "None" }; - if (touchTarget.entityID && touchTarget.entityID !== controllerDispatcher.NULL_UUID) { + if (touchTarget.entityID && touchTarget.entityID !== Uuid.NULL) { Entities.sendHoverEnterEntity(touchTarget.entityID, pointerEvent); - } else if (touchTarget.overlayID && touchTarget.overlayID !== controllerDispatcher.NULL_UUID) { + } else if (touchTarget.overlayID && touchTarget.overlayID !== Uuid.NULL) { Overlays.sendHoverEnterOverlay(touchTarget.overlayID, pointerEvent); } } @@ -60,10 +60,10 @@ function sendHoverOverEventToTouchTarget(hand, touchTarget) { button: "None" }; - if (touchTarget.entityID && touchTarget.entityID !== controllerDispatcher.NULL_UUID) { + if (touchTarget.entityID && touchTarget.entityID !== Uuid.NULL) { Entities.sendMouseMoveOnEntity(touchTarget.entityID, pointerEvent); Entities.sendHoverOverEntity(touchTarget.entityID, pointerEvent); - } else if (touchTarget.overlayID && touchTarget.overlayID !== controllerDispatcher.NULL_UUID) { + } else if (touchTarget.overlayID && touchTarget.overlayID !== Uuid.NULL) { Overlays.sendMouseMoveOnOverlay(touchTarget.overlayID, pointerEvent); Overlays.sendHoverOverOverlay(touchTarget.overlayID, pointerEvent); } @@ -81,10 +81,10 @@ function sendTouchStartEventToTouchTarget(hand, touchTarget) { isPrimaryHeld: true }; - if (touchTarget.entityID && touchTarget.entityID !== controllerDispatcher.NULL_UUID) { + if (touchTarget.entityID && touchTarget.entityID !== Uuid.NULL) { Entities.sendMousePressOnEntity(touchTarget.entityID, pointerEvent); Entities.sendClickDownOnEntity(touchTarget.entityID, pointerEvent); - } else if (touchTarget.overlayID && touchTarget.overlayID !== controllerDispatcher.NULL_UUID) { + } else if (touchTarget.overlayID && touchTarget.overlayID !== Uuid.NULL) { Overlays.sendMousePressOnOverlay(touchTarget.overlayID, pointerEvent); } } @@ -100,11 +100,11 @@ function sendTouchEndEventToTouchTarget(hand, touchTarget) { button: "Primary" }; - if (touchTarget.entityID && touchTarget.entityID !== controllerDispatcher.NULL_UUID) { + if (touchTarget.entityID && touchTarget.entityID !== Uuid.NULL) { Entities.sendMouseReleaseOnEntity(touchTarget.entityID, pointerEvent); Entities.sendClickReleaseOnEntity(touchTarget.entityID, pointerEvent); Entities.sendHoverLeaveEntity(touchTarget.entityID, pointerEvent); - } else if (touchTarget.overlayID && touchTarget.overlayID !== controllerDispatcher.NULL_UUID) { + } else if (touchTarget.overlayID && touchTarget.overlayID !== Uuid.NULL) { Overlays.sendMouseReleaseOnOverlay(touchTarget.overlayID, pointerEvent); } } @@ -121,10 +121,10 @@ function sendTouchMoveEventToTouchTarget(hand, touchTarget) { isPrimaryHeld: true }; - if (touchTarget.entityID && touchTarget.entityID !== controllerDispatcher.NULL_UUID) { + if (touchTarget.entityID && touchTarget.entityID !== Uuid.NULL) { Entities.sendMouseMoveOnEntity(touchTarget.entityID, pointerEvent); Entities.sendHoldingClickOnEntity(touchTarget.entityID, pointerEvent); - } else if (touchTarget.overlayID && touchTarget.overlayID !== controllerDispatcher.NULL_UUID) { + } else if (touchTarget.overlayID && touchTarget.overlayID !== Uuid.NULL) { Overlays.sendMouseMoveOnOverlay(touchTarget.overlayID, pointerEvent); } } diff --git a/scripts/system/nameTag.js b/scripts/system/nameTag.js index 17944bcf85..69e5dac1bf 100644 --- a/scripts/system/nameTag.js +++ b/scripts/system/nameTag.js @@ -13,7 +13,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html const CLIENTONLY = false; -const NULL_UUID = "{00000000-0000-0000-0000-000000000000}"; const ENTITY_CHECK_INTERVAL = 5000; // ms = 5 seconds const STARTUP_DELAY = 2000; // ms = 2 second const OLD_AGE = 3500; // we recreate the entity if older than this time in seconds @@ -24,7 +23,7 @@ const SIZE_Y = 0.075; const LETTER_OFFSET = 0.03; // arbitrary value to dynamically change width, could be more accurate by detecting characters const LINE_HEIGHT = 0.05; -var nameTagEntityID = NULL_UUID; +var nameTagEntityID = Uuid.NULL; var lastCheckForEntity = 0; // create the name tag entity after a brief delay @@ -62,9 +61,9 @@ function updateNameTag() { }; function deleteNameTag() { - if(nameTagEntityID !== NULL_UUID) { + if(nameTagEntityID !== Uuid.NULL) { Entities.deleteEntity(nameTagEntityID); - nameTagEntityID = NULL_UUID; + nameTagEntityID = Uuid.NULL; } } @@ -85,7 +84,7 @@ function cleanup() { Script.update.connect(update); function update() { // if no entity we return - if(nameTagEntityID == NULL_UUID) { + if(nameTagEntityID == Uuid.NULL) { return; } diff --git a/scripts/tutorials/createTetherballStick.js b/scripts/tutorials/createTetherballStick.js index 8d36d8ee59..35f5fb0344 100644 --- a/scripts/tutorials/createTetherballStick.js +++ b/scripts/tutorials/createTetherballStick.js @@ -14,7 +14,6 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -var NULL_UUID = "{00000000-0000-0000-0000-000000000000}"; var LIFETIME = 3600; var BALL_SIZE = 0.175; var BALL_DAMPING = 0.5; From ed1c974f755edae363e0d1934ce18f5ef87d4e0d Mon Sep 17 00:00:00 2001 From: David Rowe Date: Tue, 17 Oct 2017 15:58:51 +1300 Subject: [PATCH 3/6] Use MyAvatar.SELF_ID instead of Uuid.SELF --- interface/src/avatar/MyAvatar.h | 9 +++++++-- libraries/script-engine/src/ScriptUUID.h | 6 +----- scripts/system/away.js | 2 +- scripts/system/controllers/controllerDisplay.js | 4 ++-- scripts/system/libraries/WebTablet.js | 4 ++-- scripts/system/libraries/controllerDispatcherUtils.js | 6 +++--- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 952315a85f..6e735c6357 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -106,6 +106,8 @@ class MyAvatar : public Avatar { * "scripts/system/controllers/toggleAdvancedMovementForHandControllers.js". * @property userHeight {number} The height of the user in sensor space. (meters). * @property userEyeHeight {number} Estimated height of the users eyes in sensor space. (meters) + * @property SELF_ID {string} READ-ONLY. UUID representing "my avatar". Only use for local-only entities and overlays in situations where MyAvatar.sessionUUID is not available (e.g., if not connected to a domain). + * Note: Likely to be deprecated. */ // FIXME: `glm::vec3 position` is not accessible from QML, so this exposes position in a QML-native type @@ -152,6 +154,8 @@ class MyAvatar : public Avatar { Q_PROPERTY(float userHeight READ getUserHeight WRITE setUserHeight) Q_PROPERTY(float userEyeHeight READ getUserEyeHeight) + + Q_PROPERTY(QString SELF_ID READ SELF_UUID CONSTANT) const QString DOMINANT_LEFT_HAND = "left"; const QString DOMINANT_RIGHT_HAND = "right"; @@ -648,8 +652,6 @@ private: void setVisibleInSceneIfReady(Model* model, const render::ScenePointer& scene, bool visiblity); -private: - virtual void updatePalms() override {} void lateUpdatePalms(); @@ -826,6 +828,9 @@ private: // height of user in sensor space, when standing erect. ThreadSafeValueCache _userHeight { DEFAULT_AVATAR_HEIGHT }; + + const QString SELF_UUID() { return SELF_ID; } + const QString SELF_ID { AVATAR_SELF_ID.toString() }; }; QScriptValue audioListenModeToScriptValue(QScriptEngine* engine, const AudioListenerMode& audioListenerMode); diff --git a/libraries/script-engine/src/ScriptUUID.h b/libraries/script-engine/src/ScriptUUID.h index e5360754ae..3f504c35ba 100644 --- a/libraries/script-engine/src/ScriptUUID.h +++ b/libraries/script-engine/src/ScriptUUID.h @@ -21,7 +21,6 @@ class ScriptUUID : public QObject, protected QScriptable { Q_OBJECT Q_PROPERTY(QString NULL READ NULL_UUID CONSTANT) // String for use in scripts. - Q_PROPERTY(QString SELF READ SELF_UUID CONSTANT) public slots: QUuid fromString(const QString& string); @@ -33,10 +32,7 @@ public slots: private: const QString NULL_UUID() { return NULL_ID; } - const QString SELF_UUID() { return SELF_ID; } - - const QString NULL_ID{ "{00000000-0000-0000-0000-000000000000}" }; - const QString SELF_ID{ AVATAR_SELF_ID.toString() }; + const QString NULL_ID { "{00000000-0000-0000-0000-000000000000}" }; }; #endif // hifi_ScriptUUID_h diff --git a/scripts/system/away.js b/scripts/system/away.js index 38589050f2..2a45786d0d 100644 --- a/scripts/system/away.js +++ b/scripts/system/away.js @@ -43,7 +43,7 @@ var OVERLAY_DATA_HMD = { scale: 2 * MyAvatar.sensorToWorldScale, emissive: true, drawInFront: true, - parentID: Uuid.SELF, + parentID: MyAvatar.SELF_ID, parentJointIndex: CAMERA_MATRIX }; diff --git a/scripts/system/controllers/controllerDisplay.js b/scripts/system/controllers/controllerDisplay.js index 0296243018..dc7c9b37bd 100644 --- a/scripts/system/controllers/controllerDisplay.js +++ b/scripts/system/controllers/controllerDisplay.js @@ -176,7 +176,7 @@ createControllerDisplay = function(config) { dimensions: Vec3.multiply(sensorScaleFactor, controller.dimensions), localRotation: controller.rotation, localPosition: Vec3.multiply(sensorScaleFactor, position), - parentID: Uuid.SELF, + parentID: MyAvatar.SELF_ID, parentJointIndex: controller.jointIndex, ignoreRayIntersection: true }); @@ -196,7 +196,7 @@ createControllerDisplay = function(config) { url: part.modelURL, localPosition: partPosition, localRotation: innerRotation, - parentID: Uuid.SELF, + parentID: MyAvatar.SELF_ID, parentJointIndex: controller.jointIndex, ignoreRayIntersection: true }; diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index ba5d5962d8..c46cfaa073 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -99,7 +99,7 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location, visible) { "grabbableKey": {"grabbable": true} }), dimensions: { x: tabletWidth, y: tabletHeight, z: tabletDepth }, - parentID: Uuid.SELF, + parentID: MyAvatar.SELF_ID, visible: visible }; @@ -470,7 +470,7 @@ WebTablet.prototype.register = function() { WebTablet.prototype.cleanUpOldTabletsOnJoint = function(jointIndex) { var children = Entities.getChildrenIDsOfJoint(MyAvatar.sessionUUID, jointIndex); - children = children.concat(Entities.getChildrenIDsOfJoint(Uuid.SELF, jointIndex)); + children = children.concat(Entities.getChildrenIDsOfJoint(MyAvatar.SELF_ID, jointIndex)); children.forEach(function(childID) { var props = Entities.getEntityProperties(childID, ["name"]); if (props.name === "WebTablet Tablet") { diff --git a/scripts/system/libraries/controllerDispatcherUtils.js b/scripts/system/libraries/controllerDispatcherUtils.js index 03af4c8253..cd3f1a711f 100644 --- a/scripts/system/libraries/controllerDispatcherUtils.js +++ b/scripts/system/libraries/controllerDispatcherUtils.js @@ -311,19 +311,19 @@ findHandChildEntities = function(hand) { // find children of avatar's hand joint var handJointIndex = MyAvatar.getJointIndex(hand === RIGHT_HAND ? "RightHand" : "LeftHand"); var children = Entities.getChildrenIDsOfJoint(MyAvatar.sessionUUID, handJointIndex); - children = children.concat(Entities.getChildrenIDsOfJoint(Uuid.SELF, handJointIndex)); + children = children.concat(Entities.getChildrenIDsOfJoint(MyAvatar.SELF_ID, handJointIndex)); // find children of faux controller joint var controllerJointIndex = getControllerJointIndex(hand); children = children.concat(Entities.getChildrenIDsOfJoint(MyAvatar.sessionUUID, controllerJointIndex)); - children = children.concat(Entities.getChildrenIDsOfJoint(Uuid.SELF, controllerJointIndex)); + children = children.concat(Entities.getChildrenIDsOfJoint(MyAvatar.SELF_ID, controllerJointIndex)); // find children of faux camera-relative controller joint var controllerCRJointIndex = MyAvatar.getJointIndex(hand === RIGHT_HAND ? "_CAMERA_RELATIVE_CONTROLLER_RIGHTHAND" : "_CAMERA_RELATIVE_CONTROLLER_LEFTHAND"); children = children.concat(Entities.getChildrenIDsOfJoint(MyAvatar.sessionUUID, controllerCRJointIndex)); - children = children.concat(Entities.getChildrenIDsOfJoint(Uuid.SELF, controllerCRJointIndex)); + children = children.concat(Entities.getChildrenIDsOfJoint(MyAvatar.SELF_ID, controllerCRJointIndex)); return children.filter(function (childID) { var childType = Entities.getNestableType(childID); From 8d4e979dc8bc75c7ebafdb31e5ae1a6daf3a9682 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Tue, 17 Oct 2017 16:38:05 +1300 Subject: [PATCH 4/6] Replace usages of AVATAR_SELF_ID previously missed --- scripts/developer/tests/avatarToWorldTests.js | 2 -- .../controllers/controllerModules/equipEntity.js | 4 ++-- .../controllerModules/farActionGrabEntity.js | 10 +++++----- .../system/controllers/controllerModules/farTrigger.js | 8 ++++---- .../controllers/controllerModules/hudOverlayPointer.js | 8 ++++---- .../system/controllers/controllerModules/inEditMode.js | 8 ++++---- .../controllerModules/nearParentGrabEntity.js | 8 ++++---- .../controllerModules/nearParentGrabOverlay.js | 6 +++--- .../controllers/controllerModules/overlayLaserInput.js | 10 +++++----- .../controllers/controllerModules/tabletStylusInput.js | 4 ++-- .../system/controllers/controllerModules/teleport.js | 2 +- .../controllerModules/webEntityLaserInput.js | 8 ++++---- scripts/system/libraries/touchEventUtils.js | 2 +- 13 files changed, 39 insertions(+), 41 deletions(-) diff --git a/scripts/developer/tests/avatarToWorldTests.js b/scripts/developer/tests/avatarToWorldTests.js index c6e23fc81b..c2da49cbd4 100644 --- a/scripts/developer/tests/avatarToWorldTests.js +++ b/scripts/developer/tests/avatarToWorldTests.js @@ -1,5 +1,3 @@ -var AVATAR_SELF_ID = "{00000000-0000-0000-0000-000000000001}"; - var debugSphereBaseProperties = { type: "Sphere", dimensions: { x: 0.2, y: 0.2, z: 0.2 }, diff --git a/scripts/system/controllers/controllerModules/equipEntity.js b/scripts/system/controllers/controllerModules/equipEntity.js index 4234b4c5f8..565a67e116 100644 --- a/scripts/system/controllers/controllerModules/equipEntity.js +++ b/scripts/system/controllers/controllerModules/equipEntity.js @@ -6,7 +6,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -/* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, AVATAR_SELF_ID, +/* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, getControllerJointIndex, enableDispatcherModule, disableDispatcherModule, Messages, makeDispatcherModuleParameters, makeRunningValues, Settings, entityHasActions, Vec3, Overlays, flatten, Xform, getControllerWorldLocation, ensureDynamic, entityIsCloneable, @@ -491,7 +491,7 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa } var reparentProps = { - parentID: AVATAR_SELF_ID, + parentID: MyAvatar.SELF_ID, parentJointIndex: handJointIndex, localVelocity: {x: 0, y: 0, z: 0}, localAngularVelocity: {x: 0, y: 0, z: 0}, diff --git a/scripts/system/controllers/controllerModules/farActionGrabEntity.js b/scripts/system/controllers/controllerModules/farActionGrabEntity.js index 5085152622..951a5e1fcf 100644 --- a/scripts/system/controllers/controllerModules/farActionGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farActionGrabEntity.js @@ -9,10 +9,10 @@ /* global Script, Controller, LaserPointers, RayPick, RIGHT_HAND, LEFT_HAND, Mat4, MyAvatar, Vec3, Camera, Quat, getGrabPointSphereOffset, getEnabledModuleByName, makeRunningValues, Entities, - enableDispatcherModule, disableDispatcherModule, entityIsDistanceGrabbable, + enableDispatcherModule, disableDispatcherModule, entityIsDistanceGrabbable, entityIsGrabbable, makeDispatcherModuleParameters, MSECS_PER_SEC, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, PICK_MAX_DISTANCE, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD, - AVATAR_SELF_ID, DEFAULT_SEARCH_SPHERE_DISTANCE, TRIGGER_OFF_VALUE, TRIGGER_ON_VALUE, ZERO_VEC, ensureDynamic, + DEFAULT_SEARCH_SPHERE_DISTANCE, TRIGGER_OFF_VALUE, TRIGGER_ON_VALUE, ZERO_VEC, ensureDynamic, getControllerWorldLocation, projectOntoEntityXYPlane, ContextOverlay, HMD, Reticle, Overlays, isPointingAtUI */ @@ -33,7 +33,7 @@ Script.include("/~/system/libraries/controllers.js"); lineWidth: 5, ignoreRayIntersection: true, // always ignore this drawInFront: true, // Even when burried inside of something, show it. - parentID: AVATAR_SELF_ID + parentID: MyAvatar.SELF_ID }; var halfEnd = { type: "sphere", @@ -54,7 +54,7 @@ Script.include("/~/system/libraries/controllers.js"); lineWidth: 5, ignoreRayIntersection: true, // always ignore this drawInFront: true, // Even when burried inside of something, show it. - parentID: AVATAR_SELF_ID + parentID: MyAvatar.SELF_ID }; var fullEnd = { type: "sphere", @@ -75,7 +75,7 @@ Script.include("/~/system/libraries/controllers.js"); lineWidth: 5, ignoreRayIntersection: true, // always ignore this drawInFront: true, // Even when burried inside of something, show it. - parentID: AVATAR_SELF_ID + parentID: MyAvatar.SELF_ID }; var renderStates = [ diff --git a/scripts/system/controllers/controllerModules/farTrigger.js b/scripts/system/controllers/controllerModules/farTrigger.js index a683044e6e..133c937727 100644 --- a/scripts/system/controllers/controllerModules/farTrigger.js +++ b/scripts/system/controllers/controllerModules/farTrigger.js @@ -9,7 +9,7 @@ /* global Script, Controller, LaserPointers, RayPick, RIGHT_HAND, LEFT_HAND, MyAvatar, getGrabPointSphereOffset, makeRunningValues, Entities, enableDispatcherModule, disableDispatcherModule, makeDispatcherModuleParameters, PICK_MAX_DISTANCE, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD, - AVATAR_SELF_ID, DEFAULT_SEARCH_SPHERE_DISTANCE, getGrabbableData + DEFAULT_SEARCH_SPHERE_DISTANCE, getGrabbableData */ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); @@ -26,7 +26,7 @@ Script.include("/~/system/libraries/controllers.js"); lineWidth: 5, ignoreRayIntersection: true, // always ignore this drawInFront: true, // Even when burried inside of something, show it. - parentID: AVATAR_SELF_ID + parentID: MyAvatar.SELF_ID }; var halfEnd = { type: "sphere", @@ -47,7 +47,7 @@ Script.include("/~/system/libraries/controllers.js"); lineWidth: 5, ignoreRayIntersection: true, // always ignore this drawInFront: true, // Even when burried inside of something, show it. - parentID: AVATAR_SELF_ID + parentID: MyAvatar.SELF_ID }; var fullEnd = { type: "sphere", @@ -68,7 +68,7 @@ Script.include("/~/system/libraries/controllers.js"); lineWidth: 5, ignoreRayIntersection: true, // always ignore this drawInFront: true, // Even when burried inside of something, show it. - parentID: AVATAR_SELF_ID + parentID: MyAvatar.SELF_ID }; var renderStates = [ diff --git a/scripts/system/controllers/controllerModules/hudOverlayPointer.js b/scripts/system/controllers/controllerModules/hudOverlayPointer.js index 220551ccb7..cdcce66495 100644 --- a/scripts/system/controllers/controllerModules/hudOverlayPointer.js +++ b/scripts/system/controllers/controllerModules/hudOverlayPointer.js @@ -15,7 +15,7 @@ enableDispatcherModule, disableDispatcherModule, entityIsDistanceGrabbable, makeDispatcherModuleParameters, MSECS_PER_SEC, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, PICK_MAX_DISTANCE, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD, - AVATAR_SELF_ID, DEFAULT_SEARCH_SPHERE_DISTANCE, TRIGGER_OFF_VALUE, TRIGGER_ON_VALUE, ZERO_VEC, ensureDynamic, + DEFAULT_SEARCH_SPHERE_DISTANCE, TRIGGER_OFF_VALUE, TRIGGER_ON_VALUE, ZERO_VEC, ensureDynamic, getControllerWorldLocation, projectOntoEntityXYPlane, ContextOverlay, HMD, Reticle, Overlays, isPointingAtUI */ @@ -32,7 +32,7 @@ lineWidth: 5, ignoreRayIntersection: true, // always ignore this drawHUDLayer: true, - parentID: AVATAR_SELF_ID + parentID: MyAvatar.SELF_ID }; var halfEnd = { type: "sphere", @@ -53,7 +53,7 @@ lineWidth: 5, ignoreRayIntersection: true, // always ignore this drawHUDLayer: true, - parentID: AVATAR_SELF_ID + parentID: MyAvatar.SELF_ID }; var fullEnd = { type: "sphere", @@ -74,7 +74,7 @@ lineWidth: 5, ignoreRayIntersection: true, // always ignore this drawHUDLayer: true, - parentID: AVATAR_SELF_ID + parentID: MyAvatar.SELF_ID }; var renderStates = [ diff --git a/scripts/system/controllers/controllerModules/inEditMode.js b/scripts/system/controllers/controllerModules/inEditMode.js index cbe64b1870..faf5e98ade 100644 --- a/scripts/system/controllers/controllerModules/inEditMode.js +++ b/scripts/system/controllers/controllerModules/inEditMode.js @@ -8,7 +8,7 @@ /* jslint bitwise: true */ /* global Script, Controller, RIGHT_HAND, LEFT_HAND, enableDispatcherModule, disableDispatcherModule, makeRunningValues, - Messages, makeDispatcherModuleParameters, AVATAR_SELF_ID, HMD, getGrabPointSphereOffset, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, + Messages, makeDispatcherModuleParameters, HMD, getGrabPointSphereOffset, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD, DEFAULT_SEARCH_SPHERE_DISTANCE, TRIGGER_ON_VALUE, getEnabledModuleByName, PICK_MAX_DISTANCE, isInEditMode, LaserPointers, RayPick */ @@ -28,7 +28,7 @@ Script.include("/~/system/libraries/utils.js"); lineWidth: 5, ignoreRayIntersection: true, // always ignore this drawInFront: true, // Even when burried inside of something, show it. - parentID: AVATAR_SELF_ID + parentID: MyAvatar.SELF_ID }; var halfEnd = { type: "sphere", @@ -49,7 +49,7 @@ Script.include("/~/system/libraries/utils.js"); lineWidth: 5, ignoreRayIntersection: true, // always ignore this drawInFront: true, // Even when burried inside of something, show it. - parentID: AVATAR_SELF_ID + parentID: MyAvatar.SELF_ID }; var fullEnd = { type: "sphere", @@ -70,7 +70,7 @@ Script.include("/~/system/libraries/utils.js"); lineWidth: 5, ignoreRayIntersection: true, // always ignore this drawInFront: true, // Even when burried inside of something, show it. - parentID: AVATAR_SELF_ID + parentID: MyAvatar.SELF_ID }; var renderStates = [ diff --git a/scripts/system/controllers/controllerModules/nearParentGrabEntity.js b/scripts/system/controllers/controllerModules/nearParentGrabEntity.js index 19e531c3a3..178d459b1d 100644 --- a/scripts/system/controllers/controllerModules/nearParentGrabEntity.js +++ b/scripts/system/controllers/controllerModules/nearParentGrabEntity.js @@ -6,7 +6,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -/* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, AVATAR_SELF_ID, getControllerJointIndex, +/* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, getControllerJointIndex, enableDispatcherModule, disableDispatcherModule, propsArePhysical, Messages, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, TRIGGER_OFF_VALUE, makeDispatcherModuleParameters, entityIsGrabbable, makeRunningValues, NEAR_GRAB_RADIUS, findGroupParent, Vec3, cloneEntity, entityIsCloneable, propsAreCloneDynamic, HAPTIC_PULSE_STRENGTH, @@ -50,7 +50,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); return false; } - if (props.parentID !== MyAvatar.sessionUUID && props.parentID !== AVATAR_SELF_ID) { + if (props.parentID !== MyAvatar.sessionUUID && props.parentID !== MyAvatar.SELF_ID) { return false; } @@ -90,7 +90,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); Entities.callEntityMethod(targetProps.id, "startNearGrab", args); var reparentProps = { - parentID: AVATAR_SELF_ID, + parentID: MyAvatar.SELF_ID, parentJointIndex: handJointIndex, localVelocity: {x: 0, y: 0, z: 0}, localAngularVelocity: {x: 0, y: 0, z: 0} @@ -152,7 +152,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); var now = Date.now(); if (now - this.lastUnequipCheckTime > MSECS_PER_SEC * TEAR_AWAY_CHECK_TIME) { this.lastUnequipCheckTime = now; - if (props.parentID == AVATAR_SELF_ID) { + if (props.parentID === MyAvatar.SELF_ID) { var sensorScaleFactor = MyAvatar.sensorToWorldScale; var handPosition = controllerData.controllerLocations[this.hand].position; var dist = distanceBetweenPointAndEntityBoundingBox(handPosition, props); diff --git a/scripts/system/controllers/controllerModules/nearParentGrabOverlay.js b/scripts/system/controllers/controllerModules/nearParentGrabOverlay.js index 911576191b..925c50df5e 100644 --- a/scripts/system/controllers/controllerModules/nearParentGrabOverlay.js +++ b/scripts/system/controllers/controllerModules/nearParentGrabOverlay.js @@ -6,7 +6,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -/* global Script, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, AVATAR_SELF_ID, getControllerJointIndex, +/* global Script, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, getControllerJointIndex, enableDispatcherModule, disableDispatcherModule, Messages, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, makeDispatcherModuleParameters, Overlays, makeRunningValues, Vec3, resizeTablet, getTabletWidthFromSettings, NEAR_GRAB_RADIUS @@ -48,7 +48,7 @@ Script.include("/~/system/libraries/utils.js"); }; this.thisHandIsParent = function(props) { - if (props.parentID !== MyAvatar.sessionUUID && props.parentID !== AVATAR_SELF_ID) { + if (props.parentID !== MyAvatar.sessionUUID && props.parentID !== MyAvatar.SELF_ID) { return false; } @@ -94,7 +94,7 @@ Script.include("/~/system/libraries/utils.js"); var grabbedProperties = this.getGrabbedProperties(); var reparentProps = { - parentID: AVATAR_SELF_ID, + parentID: MyAvatar.SELF_ID, parentJointIndex: handJointIndex, velocity: {x: 0, y: 0, z: 0}, angularVelocity: {x: 0, y: 0, z: 0} diff --git a/scripts/system/controllers/controllerModules/overlayLaserInput.js b/scripts/system/controllers/controllerModules/overlayLaserInput.js index aabe84aecc..1c3d09135a 100644 --- a/scripts/system/controllers/controllerModules/overlayLaserInput.js +++ b/scripts/system/controllers/controllerModules/overlayLaserInput.js @@ -6,7 +6,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html /* global Script, Entities, Controller, RIGHT_HAND, LEFT_HAND, enableDispatcherModule, disableDispatcherModule, - makeRunningValues, Messages, Quat, Vec3, makeDispatcherModuleParameters, Overlays, ZERO_VEC, AVATAR_SELF_ID, HMD, + makeRunningValues, Messages, Quat, Vec3, makeDispatcherModuleParameters, Overlays, ZERO_VEC, HMD, INCHES_TO_METERS, DEFAULT_REGISTRATION_POINT, getGrabPointSphereOffset, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD, DEFAULT_SEARCH_SPHERE_DISTANCE, TRIGGER_ON_VALUE, TRIGGER_OFF_VALUE, getEnabledModuleByName, PICK_MAX_DISTANCE, LaserPointers, RayPick, ContextOverlay @@ -27,7 +27,7 @@ Script.include("/~/system/libraries/controllers.js"); lineWidth: 5, ignoreRayIntersection: true, // always ignore this drawInFront: true, // Even when burried inside of something, show it. - parentID: AVATAR_SELF_ID + parentID: MyAvatar.SELF_ID }; var halfEnd = { type: "sphere", @@ -48,7 +48,7 @@ Script.include("/~/system/libraries/controllers.js"); lineWidth: 5, ignoreRayIntersection: true, // always ignore this drawInFront: true, // Even when burried inside of something, show it. - parentID: AVATAR_SELF_ID + parentID: MyAvatar.SELF_ID }; var fullEnd = { type: "sphere", @@ -69,7 +69,7 @@ Script.include("/~/system/libraries/controllers.js"); lineWidth: 5, ignoreRayIntersection: true, // always ignore this drawInFront: true, // Even when burried inside of something, show it. - parentID: AVATAR_SELF_ID + parentID: MyAvatar.SELF_ID }; var renderStates = [ @@ -235,7 +235,7 @@ Script.include("/~/system/libraries/controllers.js"); var POINTER_PRESS_TO_MOVE_DELAY = 0.33; // seconds if (this.deadspotExpired || this.touchingEnterTimer > POINTER_PRESS_TO_MOVE_DELAY || distance2D(this.laserTarget.position2D, - this.pressEnterLaserTarget.position2D) > this.deadspotRadius) { + this.pressEnterLaserTarget.position2D) > this.deadspotRadius) { TouchEventUtils.sendTouchMoveEventToTouchTarget(this.hand, this.laserTarget); this.deadspotExpired = true; } diff --git a/scripts/system/controllers/controllerModules/tabletStylusInput.js b/scripts/system/controllers/controllerModules/tabletStylusInput.js index 3d7fecaf3b..beb86d0ef4 100644 --- a/scripts/system/controllers/controllerModules/tabletStylusInput.js +++ b/scripts/system/controllers/controllerModules/tabletStylusInput.js @@ -8,7 +8,7 @@ /* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, enableDispatcherModule, disableDispatcherModule, makeRunningValues, Messages, Quat, Vec3, getControllerWorldLocation, makeDispatcherModuleParameters, Overlays, ZERO_VEC, - AVATAR_SELF_ID, HMD, INCHES_TO_METERS, DEFAULT_REGISTRATION_POINT, Settings, getGrabPointSphereOffset, + HMD, INCHES_TO_METERS, DEFAULT_REGISTRATION_POINT, Settings, getGrabPointSphereOffset, getEnabledModuleByName */ @@ -172,7 +172,7 @@ Script.include("/~/system/libraries/controllers.js"); visible: true, ignoreRayIntersection: true, drawInFront: false, - parentID: AVATAR_SELF_ID, + parentID: MyAvatar.SELF_ID, parentJointIndex: MyAvatar.getJointIndex(this.hand === RIGHT_HAND ? "_CAMERA_RELATIVE_CONTROLLER_RIGHTHAND" : "_CAMERA_RELATIVE_CONTROLLER_LEFTHAND") diff --git a/scripts/system/controllers/controllerModules/teleport.js b/scripts/system/controllers/controllerModules/teleport.js index ccad9e5d0b..1c6652dc50 100644 --- a/scripts/system/controllers/controllerModules/teleport.js +++ b/scripts/system/controllers/controllerModules/teleport.js @@ -10,7 +10,7 @@ /* jslint bitwise: true */ -/* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, AVATAR_SELF_ID, getControllerJointIndex, +/* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, getControllerJointIndex, enableDispatcherModule, disableDispatcherModule, Messages, makeDispatcherModuleParameters, makeRunningValues, Vec3, LaserPointers, RayPick, HMD, Uuid, AvatarList */ diff --git a/scripts/system/controllers/controllerModules/webEntityLaserInput.js b/scripts/system/controllers/controllerModules/webEntityLaserInput.js index 28062109c6..4d4fb734f5 100644 --- a/scripts/system/controllers/controllerModules/webEntityLaserInput.js +++ b/scripts/system/controllers/controllerModules/webEntityLaserInput.js @@ -10,7 +10,7 @@ /* global Script, Controller, LaserPointers, RayPick, RIGHT_HAND, LEFT_HAND, Vec3, Quat, getGrabPointSphereOffset, makeRunningValues, Entities, enableDispatcherModule, disableDispatcherModule, makeDispatcherModuleParameters, PICK_MAX_DISTANCE, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD, - AVATAR_SELF_ID, DEFAULT_SEARCH_SPHERE_DISTANCE, TRIGGER_ON_VALUE, ZERO_VEC, Overlays + DEFAULT_SEARCH_SPHERE_DISTANCE, TRIGGER_ON_VALUE, ZERO_VEC, Overlays */ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); @@ -27,7 +27,7 @@ Script.include("/~/system/libraries/controllers.js"); lineWidth: 5, ignoreRayIntersection: true, // always ignore this drawInFront: true, // Even when burried inside of something, show it. - parentID: AVATAR_SELF_ID + parentID: MyAvatar.SELF_ID }; var halfEnd = { type: "sphere", @@ -48,7 +48,7 @@ Script.include("/~/system/libraries/controllers.js"); lineWidth: 5, ignoreRayIntersection: true, // always ignore this drawInFront: true, // Even when burried inside of something, show it. - parentID: AVATAR_SELF_ID + parentID: MyAvatar.SELF_ID }; var fullEnd = { type: "sphere", @@ -69,7 +69,7 @@ Script.include("/~/system/libraries/controllers.js"); lineWidth: 5, ignoreRayIntersection: true, // always ignore this drawInFront: true, // Even when burried inside of something, show it. - parentID: AVATAR_SELF_ID + parentID: MyAvatar.SELF_ID }; var renderStates = [ diff --git a/scripts/system/libraries/touchEventUtils.js b/scripts/system/libraries/touchEventUtils.js index c678c72778..3c76c4c144 100644 --- a/scripts/system/libraries/touchEventUtils.js +++ b/scripts/system/libraries/touchEventUtils.js @@ -8,7 +8,7 @@ /* global Script, Entities, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, enableDispatcherModule, disableDispatcherModule, makeRunningValues, Messages, Quat, Vec3, getControllerWorldLocation, makeDispatcherModuleParameters, Overlays, controllerDispatcher.ZERO_VEC, - AVATAR_SELF_ID, HMD, INCHES_TO_METERS, DEFAULT_REGISTRATION_POINT, Settings, getGrabPointSphereOffset + HMD, INCHES_TO_METERS, DEFAULT_REGISTRATION_POINT, Settings, getGrabPointSphereOffset */ var controllerDispatcher = Script.require("/~/system/libraries/controllerDispatcherUtils.js"); From f31e014e8b3137b0a1fd01bad1a5173b78e4d766 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 18 Oct 2017 20:34:55 +1300 Subject: [PATCH 5/6] Quat.ZERO --> Quat.IDENTITY --- libraries/script-engine/src/Quat.h | 4 ++-- scripts/system/libraries/entityCameraTool.js | 2 +- scripts/system/libraries/entitySelectionTool.js | 8 ++++---- scripts/system/libraries/overlayUtils.js | 4 ++-- .../marketplace/shapes/utilities/utilities.js | 1 + 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/libraries/script-engine/src/Quat.h b/libraries/script-engine/src/Quat.h index 796b2a4811..d3fb2ed5c2 100644 --- a/libraries/script-engine/src/Quat.h +++ b/libraries/script-engine/src/Quat.h @@ -33,7 +33,7 @@ /// Scriptable interface a Quaternion helper class object. Used exclusively in the JavaScript API class Quat : public QObject, protected QScriptable { Q_OBJECT - Q_PROPERTY(glm::quat ZERO READ ZERO CONSTANT) + Q_PROPERTY(glm::quat IDENTITY READ IDENTITY CONSTANT) public slots: glm::quat multiply(const glm::quat& q1, const glm::quat& q2); @@ -66,7 +66,7 @@ public slots: glm::quat cancelOutRoll(const glm::quat& q); private: - const glm::quat& ZERO() { return Quaternions::IDENTITY; } + const glm::quat& IDENTITY() const { return Quaternions::IDENTITY; } }; diff --git a/scripts/system/libraries/entityCameraTool.js b/scripts/system/libraries/entityCameraTool.js index 61280013ba..0e52353dfb 100644 --- a/scripts/system/libraries/entityCameraTool.js +++ b/scripts/system/libraries/entityCameraTool.js @@ -123,7 +123,7 @@ CameraManager = function() { easing = false; easingTime = 0; - startOrientation = Quat.ZERO; + startOrientation = Quat.IDENTITY; that.previousCameraMode = null; diff --git a/scripts/system/libraries/entitySelectionTool.js b/scripts/system/libraries/entitySelectionTool.js index 0e6a9d5310..88d1e627c3 100644 --- a/scripts/system/libraries/entitySelectionTool.js +++ b/scripts/system/libraries/entitySelectionTool.js @@ -71,12 +71,12 @@ SelectionManager = (function() { that.selections = []; var listeners = []; - that.localRotation = Quat.ZERO; + that.localRotation = Quat.IDENTITY; that.localPosition = Vec3.ZERO; that.localDimensions = Vec3.ZERO; that.localRegistrationPoint = Vec3.HALF; - that.worldRotation = Quat.ZERO; + that.worldRotation = Quat.IDENTITY; that.worldPosition = Vec3.ZERO; that.worldDimensions = Vec3.ZERO; that.worldRegistrationPoint = Vec3.HALF; @@ -1508,7 +1508,7 @@ SelectionDisplay = (function() { position = SelectionManager.localPosition; registrationPoint = SelectionManager.localRegistrationPoint; } else { - rotation = Quat.ZERO; + rotation = Quat.IDENTITY; dimensions = SelectionManager.worldDimensions; position = SelectionManager.worldPosition; registrationPoint = SelectionManager.worldRegistrationPoint; @@ -2564,7 +2564,7 @@ SelectionDisplay = (function() { var onBegin = function(event, pickRay, pickResult) { var properties = Entities.getEntityProperties(SelectionManager.selections[0]); initialProperties = properties; - rotation = (spaceMode === SPACE_LOCAL) ? properties.rotation : Quat.ZERO; + rotation = (spaceMode === SPACE_LOCAL) ? properties.rotation : Quat.IDENTITY; if (spaceMode === SPACE_LOCAL) { rotation = SelectionManager.localRotation; diff --git a/scripts/system/libraries/overlayUtils.js b/scripts/system/libraries/overlayUtils.js index 3ba5c2bad2..366cdbcc97 100644 --- a/scripts/system/libraries/overlayUtils.js +++ b/scripts/system/libraries/overlayUtils.js @@ -18,7 +18,7 @@ OverlayGroup = function(opts) { var overlays = {}; var rootPosition = opts.position || { x: 0, y: 0, z: 0 }; - var rootRotation = opts.rotation || Quat.ZERO; + var rootRotation = opts.rotation || Quat.IDENTITY; var visible = opts.visible == true; function updateOverlays() { @@ -36,7 +36,7 @@ OverlayGroup = function(opts) { that.createOverlay = function(type, properties) { properties.position = properties.position || { x: 0, y: 0, z: 0 }; - properties.rotation = properties.rotation || Quat.ZERO; + properties.rotation = properties.rotation || Quat.IDENTITY; var overlay = Overlays.addOverlay(type, properties); diff --git a/unpublishedScripts/marketplace/shapes/utilities/utilities.js b/unpublishedScripts/marketplace/shapes/utilities/utilities.js index 71986455d4..b67ba0d9d2 100644 --- a/unpublishedScripts/marketplace/shapes/utilities/utilities.js +++ b/unpublishedScripts/marketplace/shapes/utilities/utilities.js @@ -27,6 +27,7 @@ if (typeof Vec3.abs !== "function") { } if (typeof Quat.ZERO !== "object") { + // TODO: Change to Quat.IDENTITY. Quat.ZERO = Quat.fromVec3Radians(Vec3.ZERO); } From fcc7a3e440bd3f84f7574837437e353a0f93f31e Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 18 Oct 2017 21:08:10 +1300 Subject: [PATCH 6/6] Code review --- interface/src/avatar/MyAvatar.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 6e735c6357..16ed9ea5b4 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -16,6 +16,8 @@ #include +#include + #include #include #include @@ -155,7 +157,7 @@ class MyAvatar : public Avatar { Q_PROPERTY(float userHeight READ getUserHeight WRITE setUserHeight) Q_PROPERTY(float userEyeHeight READ getUserEyeHeight) - Q_PROPERTY(QString SELF_ID READ SELF_UUID CONSTANT) + Q_PROPERTY(QUuid SELF_ID READ getSelfID CONSTANT) const QString DOMINANT_LEFT_HAND = "left"; const QString DOMINANT_RIGHT_HAND = "right"; @@ -550,6 +552,8 @@ public: virtual SpatialParentTree* getParentTree() const override; + const QUuid& getSelfID() const { return AVATAR_SELF_ID; } + public slots: void increaseSize(); void decreaseSize(); @@ -828,9 +832,6 @@ private: // height of user in sensor space, when standing erect. ThreadSafeValueCache _userHeight { DEFAULT_AVATAR_HEIGHT }; - - const QString SELF_UUID() { return SELF_ID; } - const QString SELF_ID { AVATAR_SELF_ID.toString() }; }; QScriptValue audioListenModeToScriptValue(QScriptEngine* engine, const AudioListenerMode& audioListenerMode);