From 813c58a1fb23d90a35d82e680ac0dce558510cd9 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Tue, 17 Jul 2018 11:53:55 -0700 Subject: [PATCH 01/28] adding check to see if near grabbing is ready --- .../controllerModules/webSurfaceLaserInput.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index a2fe0bfcd4..1706fadbb7 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -42,6 +42,16 @@ Script.include("/~/system/libraries/controllers.js"); return true; } } + nearGrabName = this.hand === RIGHT_HAND ? "RightNearParentingGrabEntity" : "LeftNearParentingGrabEntity"; + nearGrabModule = getEnabledModuleByName(nearGrabName); + if (nearGrabModule) { + return nearGrabModule.isReady(controllerData).active; + } + nearGrabName = this.hand === RIGHT_HAND ? "RightNearActionGrabEntity" : "LeftNearActionGrabEntity"; + nearGrabModule = getEnabledModuleByName(nearGrabName); + if (nearGrabModule) { + return nearGrabModule.isReady(controllerData).active; + } } return false; }; From eb7bde1bfca86eecf2ef8d291313f9dfe61c3603 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Tue, 17 Jul 2018 15:38:56 -0700 Subject: [PATCH 02/28] switching near grab priority to be before web surface laser --- .../highlightNearbyEntities.js | 2 +- .../controllerModules/inEditMode.js | 2 +- .../controllerModules/inVREditMode.js | 2 +- .../controllerModules/nearActionGrabEntity.js | 2 +- .../nearGrabHyperLinkEntity.js | 2 +- .../controllerModules/nearParentGrabEntity.js | 2 +- .../controllerModules/nearTrigger.js | 2 +- .../controllerModules/webSurfaceLaserInput.js | 32 +++++++++++++++++-- 8 files changed, 36 insertions(+), 10 deletions(-) diff --git a/scripts/system/controllers/controllerModules/highlightNearbyEntities.js b/scripts/system/controllers/controllerModules/highlightNearbyEntities.js index bc09ebee7a..3a33082f64 100644 --- a/scripts/system/controllers/controllerModules/highlightNearbyEntities.js +++ b/scripts/system/controllers/controllerModules/highlightNearbyEntities.js @@ -37,7 +37,7 @@ this.highlightedEntities = []; this.parameters = dispatcherUtils.makeDispatcherModuleParameters( - 480, + 120, this.hand === dispatcherUtils.RIGHT_HAND ? ["rightHand"] : ["leftHand"], [], 100); diff --git a/scripts/system/controllers/controllerModules/inEditMode.js b/scripts/system/controllers/controllerModules/inEditMode.js index a724c2037b..0c24e64af7 100644 --- a/scripts/system/controllers/controllerModules/inEditMode.js +++ b/scripts/system/controllers/controllerModules/inEditMode.js @@ -30,7 +30,7 @@ Script.include("/~/system/libraries/utils.js"); this.reticleMaxY; this.parameters = makeDispatcherModuleParameters( - 160, + 200, this.hand === RIGHT_HAND ? ["rightHand", "rightHandEquip", "rightHandTrigger"] : ["leftHand", "leftHandEquip", "leftHandTrigger"], [], 100, diff --git a/scripts/system/controllers/controllerModules/inVREditMode.js b/scripts/system/controllers/controllerModules/inVREditMode.js index 7b78d5e1c4..02863cf935 100644 --- a/scripts/system/controllers/controllerModules/inVREditMode.js +++ b/scripts/system/controllers/controllerModules/inVREditMode.js @@ -21,7 +21,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); this.disableModules = false; var NO_HAND_LASER = -1; // Invalid hand parameter so that default laser is not displayed. this.parameters = makeDispatcherModuleParameters( - 200, // Not too high otherwise the tablet laser doesn't work. + 240, // Not too high otherwise the tablet laser doesn't work. this.hand === RIGHT_HAND ? ["rightHand", "rightHandEquip", "rightHandTrigger"] : ["leftHand", "leftHandEquip", "leftHandTrigger"], diff --git a/scripts/system/controllers/controllerModules/nearActionGrabEntity.js b/scripts/system/controllers/controllerModules/nearActionGrabEntity.js index f528c6f80f..f3574c668f 100644 --- a/scripts/system/controllers/controllerModules/nearActionGrabEntity.js +++ b/scripts/system/controllers/controllerModules/nearActionGrabEntity.js @@ -26,7 +26,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); this.hapticTargetID = null; this.parameters = makeDispatcherModuleParameters( - 500, + 140, this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"], [], 100); diff --git a/scripts/system/controllers/controllerModules/nearGrabHyperLinkEntity.js b/scripts/system/controllers/controllerModules/nearGrabHyperLinkEntity.js index 962ae89bb9..366fcd3032 100644 --- a/scripts/system/controllers/controllerModules/nearGrabHyperLinkEntity.js +++ b/scripts/system/controllers/controllerModules/nearGrabHyperLinkEntity.js @@ -21,7 +21,7 @@ this.hyperlink = ""; this.parameters = makeDispatcherModuleParameters( - 485, + 125, this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"], [], 100); diff --git a/scripts/system/controllers/controllerModules/nearParentGrabEntity.js b/scripts/system/controllers/controllerModules/nearParentGrabEntity.js index 38334f5523..ea55ee33f9 100644 --- a/scripts/system/controllers/controllerModules/nearParentGrabEntity.js +++ b/scripts/system/controllers/controllerModules/nearParentGrabEntity.js @@ -39,7 +39,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); this.cloneAllowed = true; this.parameters = makeDispatcherModuleParameters( - 500, + 140, this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"], [], 100); diff --git a/scripts/system/controllers/controllerModules/nearTrigger.js b/scripts/system/controllers/controllerModules/nearTrigger.js index 6a9cd9fbcd..f1126dedc3 100644 --- a/scripts/system/controllers/controllerModules/nearTrigger.js +++ b/scripts/system/controllers/controllerModules/nearTrigger.js @@ -29,7 +29,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); this.startSent = false; this.parameters = makeDispatcherModuleParameters( - 480, + 120, this.hand === RIGHT_HAND ? ["rightHandTrigger", "rightHand"] : ["leftHandTrigger", "leftHand"], [], 100); diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index 1706fadbb7..527ba0bd2f 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -22,7 +22,7 @@ Script.include("/~/system/libraries/controllers.js"); this.running = false; this.parameters = makeDispatcherModuleParameters( - 120, + 160, this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"], [], 100, @@ -60,6 +60,30 @@ Script.include("/~/system/libraries/controllers.js"); return this.hand === RIGHT_HAND ? leftOverlayLaserInput : rightOverlayLaserInput; }; + this.isPointingAtGrabbableEntity = function(controllerData, triggerPressed) { + // we are searching for an entity that is not a web entity. We want to be able to + // grab a non-web entity if the ray-pick intersects one. + var intersection = controllerData.rayPicks[this.hand]; + if(intersection.type === Picks.INTERSECTED_ENTITY) { + // is pointing at an entity. + var entityProperty = Entities.getEntityProperties(intersection.objectID); + var entityType = entityProperty.type; + var isGrabbable = entityIsGrabbable(entityProperty); + return (isGrabbable && triggerPressed && entityType !== "Web"); + } else if (intersection.type === Picks.INTERSECTED_OVERLAY) { + var objectID = intersection.objectID; + if ((HMD.tabletID && objectID === HMD.tabletID) || + (HMD.tabletScreenID && objectID === HMD.tabletScreenID) || + (HMD.homeButtonID && objectID === HMD.homeButtonID)) { + return true; + } else { + var overlayType = Overlays.getOverlayType(objectID); + return overlayType === "web3d" || triggerPressed; + } + } + return false; + } + this.isPointingAtTriggerable = function(controllerData, triggerPressed) { // allow pointing at tablet, unlocked web entities, or web overlays automatically without pressing trigger, // but for pointing at locked web entities or non-web overlays user must be pressing trigger @@ -113,7 +137,8 @@ Script.include("/~/system/libraries/controllers.js"); var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE && controllerData.triggerValues[this.otherHand] <= TRIGGER_OFF_VALUE; var allowThisModule = !otherModuleRunning || isTriggerPressed; - if (allowThisModule && this.isPointingAtTriggerable(controllerData, isTriggerPressed)) { + if (allowThisModule && this.isPointingAtTriggerable(controllerData, isTriggerPressed)) { + //this.isPointingAtGrabbableEntity(controllerData, isTriggerPressed)) { this.updateAllwaysOn(); if (isTriggerPressed) { this.dominantHandOverride = true; // Override dominant hand. @@ -134,7 +159,8 @@ Script.include("/~/system/libraries/controllers.js"); var allowThisModule = !otherModuleRunning && !grabModuleNeedsToRun; var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE; var laserOn = isTriggerPressed || this.parameters.handLaser.allwaysOn; - if (allowThisModule && (laserOn && this.isPointingAtTriggerable(controllerData, isTriggerPressed))) { + if (allowThisModule && (laserOn && this.isPointingAtTriggerable(controllerData, isTriggerPressed)) && + this.isPointingAtGrabbableEntity(controllerData, isTriggerPressed)) { this.running = true; return makeRunningValues(true, [], []); } From 30ca5a8cbd08a7fb440ea4baaf336c74c7a3e770 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Tue, 17 Jul 2018 16:44:49 -0700 Subject: [PATCH 03/28] code cleanup to use web laser if laser is not pointing at grabbable entity --- .../controllerModules/webSurfaceLaserInput.js | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index 527ba0bd2f..9e07e125e7 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -64,25 +64,15 @@ Script.include("/~/system/libraries/controllers.js"); // we are searching for an entity that is not a web entity. We want to be able to // grab a non-web entity if the ray-pick intersects one. var intersection = controllerData.rayPicks[this.hand]; - if(intersection.type === Picks.INTERSECTED_ENTITY) { + if (intersection.type === Picks.INTERSECTED_ENTITY) { // is pointing at an entity. var entityProperty = Entities.getEntityProperties(intersection.objectID); var entityType = entityProperty.type; var isGrabbable = entityIsGrabbable(entityProperty); return (isGrabbable && triggerPressed && entityType !== "Web"); - } else if (intersection.type === Picks.INTERSECTED_OVERLAY) { - var objectID = intersection.objectID; - if ((HMD.tabletID && objectID === HMD.tabletID) || - (HMD.tabletScreenID && objectID === HMD.tabletScreenID) || - (HMD.homeButtonID && objectID === HMD.homeButtonID)) { - return true; - } else { - var overlayType = Overlays.getOverlayType(objectID); - return overlayType === "web3d" || triggerPressed; - } } return false; - } + }; this.isPointingAtTriggerable = function(controllerData, triggerPressed) { // allow pointing at tablet, unlocked web entities, or web overlays automatically without pressing trigger, @@ -137,8 +127,8 @@ Script.include("/~/system/libraries/controllers.js"); var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE && controllerData.triggerValues[this.otherHand] <= TRIGGER_OFF_VALUE; var allowThisModule = !otherModuleRunning || isTriggerPressed; - if (allowThisModule && this.isPointingAtTriggerable(controllerData, isTriggerPressed)) { - //this.isPointingAtGrabbableEntity(controllerData, isTriggerPressed)) { + if (allowThisModule && this.isPointingAtTriggerable(controllerData, isTriggerPressed) && + !this.isPointingAtGrabbableEntity(controllerData, isTriggerPressed)) { this.updateAllwaysOn(); if (isTriggerPressed) { this.dominantHandOverride = true; // Override dominant hand. @@ -159,8 +149,8 @@ Script.include("/~/system/libraries/controllers.js"); var allowThisModule = !otherModuleRunning && !grabModuleNeedsToRun; var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE; var laserOn = isTriggerPressed || this.parameters.handLaser.allwaysOn; - if (allowThisModule && (laserOn && this.isPointingAtTriggerable(controllerData, isTriggerPressed)) && - this.isPointingAtGrabbableEntity(controllerData, isTriggerPressed)) { + if (allowThisModule && (laserOn && this.isPointingAtTriggerable(controllerData, isTriggerPressed)) && + !this.isPointingAtGrabbableEntity(controllerData, isTriggerPressed)) { this.running = true; return makeRunningValues(true, [], []); } From ac642f126a02ebb66303fee75f8dc3bf7ff06922 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Tue, 17 Jul 2018 20:52:50 -0700 Subject: [PATCH 04/28] adding extra conditional to ensure all modules are checked --- .../controllers/controllerModules/webSurfaceLaserInput.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index 9e07e125e7..03c8a65637 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -44,12 +44,12 @@ Script.include("/~/system/libraries/controllers.js"); } nearGrabName = this.hand === RIGHT_HAND ? "RightNearParentingGrabEntity" : "LeftNearParentingGrabEntity"; nearGrabModule = getEnabledModuleByName(nearGrabName); - if (nearGrabModule) { + if (nearGrabModule && nearGrabModule.isReady(controllerData)) { return nearGrabModule.isReady(controllerData).active; } nearGrabName = this.hand === RIGHT_HAND ? "RightNearActionGrabEntity" : "LeftNearActionGrabEntity"; nearGrabModule = getEnabledModuleByName(nearGrabName); - if (nearGrabModule) { + if (nearGrabModule && nearGrabModule.isReady(controllerData)) { return nearGrabModule.isReady(controllerData).active; } } From 5276d84aa5ccbb75f19f640cf60af794dba7d516 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Thu, 19 Jul 2018 17:08:12 -0700 Subject: [PATCH 05/28] pushing what i coded out loud - it broke the way grabbing works --- .../controllers/controllerDispatcher.js | 1 + .../controllerModules/webSurfaceLaserInput.js | 56 +++++++++++++------ 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/scripts/system/controllers/controllerDispatcher.js b/scripts/system/controllers/controllerDispatcher.js index 4002fd297b..09d09248fc 100644 --- a/scripts/system/controllers/controllerDispatcher.js +++ b/scripts/system/controllers/controllerDispatcher.js @@ -298,6 +298,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); triggerValues: [_this.leftTriggerValue, _this.rightTriggerValue], triggerClicks: [_this.leftTriggerClicked, _this.rightTriggerClicked], secondaryValues: [_this.leftSecondaryValue, _this.rightSecondaryValue], + pointers: [_this.leftPointer, _this.rightPointer ], controllerLocations: controllerLocations, nearbyEntityProperties: nearbyEntityProperties, nearbyEntityPropertiesByID: nearbyEntityPropertiesByID, diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index 03c8a65637..3ee50d0f75 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -5,11 +5,12 @@ // 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, enableDispatcherModule, disableDispatcherModule, - 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, ContextOverlay, Picks, makeLaserParams +/* global Script, Entities, Controller, RIGHT_HAND, LEFT_HAND, getControllerWorldLocation, + enableDispatcherModule, disableDispatcherModule, 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, ContextOverlay, Picks, makeLaserParams */ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); @@ -19,6 +20,8 @@ Script.include("/~/system/libraries/controllers.js"); function WebSurfaceLaserInput(hand) { this.hand = hand; this.otherHand = this.hand === RIGHT_HAND ? LEFT_HAND : RIGHT_HAND; + this.ignoredEntities = []; + this.lastObjectID = null; this.running = false; this.parameters = makeDispatcherModuleParameters( @@ -60,16 +63,20 @@ Script.include("/~/system/libraries/controllers.js"); return this.hand === RIGHT_HAND ? leftOverlayLaserInput : rightOverlayLaserInput; }; - this.isPointingAtGrabbableEntity = function(controllerData, triggerPressed) { + this.isPointingAtNearGrabbableEntity = function(controllerData, triggerPressed) { // we are searching for an entity that is not a web entity. We want to be able to // grab a non-web entity if the ray-pick intersects one. var intersection = controllerData.rayPicks[this.hand]; if (intersection.type === Picks.INTERSECTED_ENTITY) { // is pointing at an entity. - var entityProperty = Entities.getEntityProperties(intersection.objectID); - var entityType = entityProperty.type; - var isGrabbable = entityIsGrabbable(entityProperty); - return (isGrabbable && triggerPressed && entityType !== "Web"); + var entityProperties = Entities.getEntityProperties(intersection.objectID); + var entityType = entityProperties.type; + if (entityIsGrabbable(entityProperties)) { + // check if entity is near grabbable. + var distance = Vec3.distance(entityProperties.position, controllerData.controllerLocations[this.hand].position); + if (distance <= NEAR_GRAB_RADIUS * MyAvatar.sensorToWorldScale) + return (triggerPressed && entityType !== "Web"); + } } return false; }; @@ -78,21 +85,30 @@ Script.include("/~/system/libraries/controllers.js"); // allow pointing at tablet, unlocked web entities, or web overlays automatically without pressing trigger, // but for pointing at locked web entities or non-web overlays user must be pressing trigger var intersection = controllerData.rayPicks[this.hand]; + var objectID = intersection.objectID; if (intersection.type === Picks.INTERSECTED_OVERLAY) { - var objectID = intersection.objectID; if ((HMD.tabletID && objectID === HMD.tabletID) || (HMD.tabletScreenID && objectID === HMD.tabletScreenID) || (HMD.homeButtonID && objectID === HMD.homeButtonID)) { + this.lastObjectID = objectID; return true; } else { var overlayType = Overlays.getOverlayType(objectID); + this.lastObjectID = objectID; return overlayType === "web3d" || triggerPressed; } } else if (intersection.type === Picks.INTERSECTED_ENTITY) { - var entityProperty = Entities.getEntityProperties(intersection.objectID); - var entityType = entityProperty.type; - var isLocked = entityProperty.locked; - return entityType === "Web" && (!isLocked || triggerPressed); + var entityProperty = Entities.getEntityProperties(objectID); + if (entityProperty.type === "Web") { + var isLocked = entityProperty.locked; + this.lastObjectID = objectID; + return (!isLocked || triggerPressed); + } else if (this.ignoredEntities.indexOf(objectID) === -1 && triggerPressed && this.lastObjectID !== objectID) { + // ignore, preserve whether it's running or not. + console.log("I'm here"); + Pointers.setIgnoreItems(controllerData.pointers[this.hand], [objectID]); + this.ignoredEntities.push(objectID); + } } return false; }; @@ -110,6 +126,11 @@ Script.include("/~/system/libraries/controllers.js"); } }; + this.reAddIgnoredEntities = function(controllerData) { + Pointers.setIncludeItems(controllerData.pointers[this.hand], this.ignoredEntities); + this.ignoredEntities = []; + } + this.updateAllwaysOn = function() { var PREFER_STYLUS_OVER_LASER = "preferStylusOverLaser"; this.parameters.handLaser.allwaysOn = !Settings.getValue(PREFER_STYLUS_OVER_LASER, false); @@ -128,7 +149,7 @@ Script.include("/~/system/libraries/controllers.js"); controllerData.triggerValues[this.otherHand] <= TRIGGER_OFF_VALUE; var allowThisModule = !otherModuleRunning || isTriggerPressed; if (allowThisModule && this.isPointingAtTriggerable(controllerData, isTriggerPressed) && - !this.isPointingAtGrabbableEntity(controllerData, isTriggerPressed)) { + !this.isPointingAtNearGrabbableEntity(controllerData, isTriggerPressed)) { this.updateAllwaysOn(); if (isTriggerPressed) { this.dominantHandOverride = true; // Override dominant hand. @@ -150,11 +171,12 @@ Script.include("/~/system/libraries/controllers.js"); var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE; var laserOn = isTriggerPressed || this.parameters.handLaser.allwaysOn; if (allowThisModule && (laserOn && this.isPointingAtTriggerable(controllerData, isTriggerPressed)) && - !this.isPointingAtGrabbableEntity(controllerData, isTriggerPressed)) { + !this.isPointingAtNearGrabbableEntity(controllerData, isTriggerPressed)) { this.running = true; return makeRunningValues(true, [], []); } this.deleteContextOverlay(); + this.reAddIgnoredEntities(controllerData); this.running = false; this.dominantHandOverride = false; return makeRunningValues(false, [], []); From 4e3a6cb320b8ea8507512c8d5a7ab54a52cf737f Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Fri, 20 Jul 2018 11:18:20 -0700 Subject: [PATCH 06/28] adding ignore for far-/near- grabbable entities when operating on web surface --- .../controllerModules/webSurfaceLaserInput.js | 35 ++++++------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index 3ee50d0f75..16e2c1a4f7 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -20,8 +20,6 @@ Script.include("/~/system/libraries/controllers.js"); function WebSurfaceLaserInput(hand) { this.hand = hand; this.otherHand = this.hand === RIGHT_HAND ? LEFT_HAND : RIGHT_HAND; - this.ignoredEntities = []; - this.lastObjectID = null; this.running = false; this.parameters = makeDispatcherModuleParameters( @@ -71,11 +69,15 @@ Script.include("/~/system/libraries/controllers.js"); // is pointing at an entity. var entityProperties = Entities.getEntityProperties(intersection.objectID); var entityType = entityProperties.type; - if (entityIsGrabbable(entityProperties)) { + if (entityIsGrabbable(entityProperties) && entityType !== "Web") { // check if entity is near grabbable. var distance = Vec3.distance(entityProperties.position, controllerData.controllerLocations[this.hand].position); - if (distance <= NEAR_GRAB_RADIUS * MyAvatar.sensorToWorldScale) - return (triggerPressed && entityType !== "Web"); + if (distance <= NEAR_GRAB_RADIUS * MyAvatar.sensorToWorldScale) { + return triggerPressed; + } else { + // far-grabbable, but still return it as true anyway + return false; + } } } return false; @@ -90,25 +92,15 @@ Script.include("/~/system/libraries/controllers.js"); if ((HMD.tabletID && objectID === HMD.tabletID) || (HMD.tabletScreenID && objectID === HMD.tabletScreenID) || (HMD.homeButtonID && objectID === HMD.homeButtonID)) { - this.lastObjectID = objectID; return true; } else { var overlayType = Overlays.getOverlayType(objectID); - this.lastObjectID = objectID; return overlayType === "web3d" || triggerPressed; } } else if (intersection.type === Picks.INTERSECTED_ENTITY) { var entityProperty = Entities.getEntityProperties(objectID); - if (entityProperty.type === "Web") { - var isLocked = entityProperty.locked; - this.lastObjectID = objectID; - return (!isLocked || triggerPressed); - } else if (this.ignoredEntities.indexOf(objectID) === -1 && triggerPressed && this.lastObjectID !== objectID) { - // ignore, preserve whether it's running or not. - console.log("I'm here"); - Pointers.setIgnoreItems(controllerData.pointers[this.hand], [objectID]); - this.ignoredEntities.push(objectID); - } + var isLocked = entityProperty.locked; + return (!isLocked || triggerPressed || entityProperty.type === "Web"); } return false; }; @@ -126,11 +118,6 @@ Script.include("/~/system/libraries/controllers.js"); } }; - this.reAddIgnoredEntities = function(controllerData) { - Pointers.setIncludeItems(controllerData.pointers[this.hand], this.ignoredEntities); - this.ignoredEntities = []; - } - this.updateAllwaysOn = function() { var PREFER_STYLUS_OVER_LASER = "preferStylusOverLaser"; this.parameters.handLaser.allwaysOn = !Settings.getValue(PREFER_STYLUS_OVER_LASER, false); @@ -148,8 +135,7 @@ Script.include("/~/system/libraries/controllers.js"); var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE && controllerData.triggerValues[this.otherHand] <= TRIGGER_OFF_VALUE; var allowThisModule = !otherModuleRunning || isTriggerPressed; - if (allowThisModule && this.isPointingAtTriggerable(controllerData, isTriggerPressed) && - !this.isPointingAtNearGrabbableEntity(controllerData, isTriggerPressed)) { + if (allowThisModule && this.isPointingAtTriggerable(controllerData, isTriggerPressed)) { this.updateAllwaysOn(); if (isTriggerPressed) { this.dominantHandOverride = true; // Override dominant hand. @@ -176,7 +162,6 @@ Script.include("/~/system/libraries/controllers.js"); return makeRunningValues(true, [], []); } this.deleteContextOverlay(); - this.reAddIgnoredEntities(controllerData); this.running = false; this.dominantHandOverride = false; return makeRunningValues(false, [], []); From be5fdef974c66ec7a4525acddb07d48870b5adba Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Fri, 20 Jul 2018 15:26:55 -0700 Subject: [PATCH 07/28] adding check in isReady for grabbing non-web entitys --- .../controllers/controllerDispatcher.js | 48 ++++++++++++++++++- .../controllerModules/webSurfaceLaserInput.js | 19 ++++---- 2 files changed, 57 insertions(+), 10 deletions(-) diff --git a/scripts/system/controllers/controllerDispatcher.js b/scripts/system/controllers/controllerDispatcher.js index 09d09248fc..8dbf4a6789 100644 --- a/scripts/system/controllers/controllerDispatcher.js +++ b/scripts/system/controllers/controllerDispatcher.js @@ -31,6 +31,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); var PROFILE = false; var DEBUG = false; + var DEBUG_OVERLAY = true; if (typeof Test !== "undefined") { PROFILE = true; @@ -48,6 +49,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); this.tabletID = null; this.blacklist = []; this.pointerManager = new PointerManager(); + this.debugOverlayID = null; // a module can occupy one or more "activity" slots while it's running. If all the required slots for a module are // not set to false (not in use), a module cannot start. When a module is using a slot, that module's name @@ -298,7 +300,6 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); triggerValues: [_this.leftTriggerValue, _this.rightTriggerValue], triggerClicks: [_this.leftTriggerClicked, _this.rightTriggerClicked], secondaryValues: [_this.leftSecondaryValue, _this.rightSecondaryValue], - pointers: [_this.leftPointer, _this.rightPointer ], controllerLocations: controllerLocations, nearbyEntityProperties: nearbyEntityProperties, nearbyEntityPropertiesByID: nearbyEntityPropertiesByID, @@ -378,6 +379,48 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); } } _this.pointerManager.updatePointersRenderState(controllerData.triggerClicks, controllerData.triggerValues); + + if (DEBUG_OVERLAY) { + if (!_this.debugOverlayID) { + + var textWidth = 0.4; + var textHeight = 0.3; + var numberOfLines = 15; + var textMargin = 0.02; + var lineHeight = (textHeight - (2 * textMargin)) / numberOfLines; + + _this.debugOverlayID = Overlays.addOverlay("text3d", { + localPosition: { x: 0.3, y: 0.2, z: 1.1 }, + localRotation: { x: 0.0, y: 0.0, z: 0.0, w: 1.0 }, + parentID: MyAvatar.sessionUUID, + parentJointIndex: MyAvatar.getJointIndex("Head"), + dimensions: { x: textWidth, y: textHeight }, + backgroundColor: { red: 0, green: 0, blue: 0 }, + color: { red: 255, green: 255, blue: 255 }, + topMargin: textMargin, + leftMargin: textMargin, + bottomMargin: textMargin, + rightMargin: textMargin, + text: "", + lineHeight: lineHeight, + alpha: 0.9, + backgroundAlpha: 0.9, + ignoreRayIntersection: true, + visible: true, + isFacingAvatar: true + }); + } + + var debugText = ""; + Object.keys(_this.runningPluginNames).forEach(function (pluginName) { + if (_this.runningPluginNames[pluginName]) { + var plugin = controllerDispatcherPlugins[pluginName]; + debugText += pluginName + ": " + plugin.parameters.priority + "\n"; + } + }); + Overlays.editOverlay(_this.debugOverlayID, { text: debugText }); + } + if (PROFILE) { Script.endProfileRange("dispatch.run"); } @@ -481,6 +524,9 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); this.cleanup = function () { Controller.disableMapping(MAPPING_NAME); _this.pointerManager.removePointers(); + if (_this.debugOverlayID) { + Overlays.deleteOverlay(_this.debugOverlayID); + } Pointers.removePointer(this.mouseRayPick); Selection.disableListHighlight(DISPATCHER_HOVERING_LIST); }; diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index 16e2c1a4f7..16cf2eef5c 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -5,12 +5,11 @@ // 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, getControllerWorldLocation, - enableDispatcherModule, disableDispatcherModule, 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, ContextOverlay, Picks, makeLaserParams +/* global Script, Entities, Controller, RIGHT_HAND, LEFT_HAND, enableDispatcherModule, disableDispatcherModule, + 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, ContextOverlay, Picks, makeLaserParams */ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); @@ -76,7 +75,7 @@ Script.include("/~/system/libraries/controllers.js"); return triggerPressed; } else { // far-grabbable, but still return it as true anyway - return false; + return true; } } } @@ -99,8 +98,9 @@ Script.include("/~/system/libraries/controllers.js"); } } else if (intersection.type === Picks.INTERSECTED_ENTITY) { var entityProperty = Entities.getEntityProperties(objectID); + var entityType = entityProperty.type; var isLocked = entityProperty.locked; - return (!isLocked || triggerPressed || entityProperty.type === "Web"); + return (!isLocked || triggerPressed || entityType === "Web"); } return false; }; @@ -135,7 +135,8 @@ Script.include("/~/system/libraries/controllers.js"); var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE && controllerData.triggerValues[this.otherHand] <= TRIGGER_OFF_VALUE; var allowThisModule = !otherModuleRunning || isTriggerPressed; - if (allowThisModule && this.isPointingAtTriggerable(controllerData, isTriggerPressed)) { + if (allowThisModule && this.isPointingAtTriggerable(controllerData, isTriggerPressed) && + !this.isPointingAtNearGrabbableEntity(controllerData, isTriggerPressed)) { this.updateAllwaysOn(); if (isTriggerPressed) { this.dominantHandOverride = true; // Override dominant hand. From 32886d67d98b7d2b964b25e39ce1a821a05593fe Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Fri, 20 Jul 2018 17:17:36 -0700 Subject: [PATCH 08/28] optimizing near-/far- grabbable entities a bit --- .../controllers/controllerDispatcher.js | 74 +++---- .../system/controllers/controllerModules/' | 181 ++++++++++++++++++ .../controllerModules/webSurfaceLaserInput.js | 12 +- 3 files changed, 223 insertions(+), 44 deletions(-) create mode 100644 scripts/system/controllers/controllerModules/' diff --git a/scripts/system/controllers/controllerDispatcher.js b/scripts/system/controllers/controllerDispatcher.js index 8dbf4a6789..399ccf0ba3 100644 --- a/scripts/system/controllers/controllerDispatcher.js +++ b/scripts/system/controllers/controllerDispatcher.js @@ -380,46 +380,46 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); } _this.pointerManager.updatePointersRenderState(controllerData.triggerClicks, controllerData.triggerValues); - if (DEBUG_OVERLAY) { - if (!_this.debugOverlayID) { +/* if (DEBUG_OVERLAY) {*/ + //if (!_this.debugOverlayID) { - var textWidth = 0.4; - var textHeight = 0.3; - var numberOfLines = 15; - var textMargin = 0.02; - var lineHeight = (textHeight - (2 * textMargin)) / numberOfLines; + //var textWidth = 0.4; + //var textHeight = 0.3; + //var numberOfLines = 15; + //var textMargin = 0.02; + //var lineHeight = (textHeight - (2 * textMargin)) / numberOfLines; - _this.debugOverlayID = Overlays.addOverlay("text3d", { - localPosition: { x: 0.3, y: 0.2, z: 1.1 }, - localRotation: { x: 0.0, y: 0.0, z: 0.0, w: 1.0 }, - parentID: MyAvatar.sessionUUID, - parentJointIndex: MyAvatar.getJointIndex("Head"), - dimensions: { x: textWidth, y: textHeight }, - backgroundColor: { red: 0, green: 0, blue: 0 }, - color: { red: 255, green: 255, blue: 255 }, - topMargin: textMargin, - leftMargin: textMargin, - bottomMargin: textMargin, - rightMargin: textMargin, - text: "", - lineHeight: lineHeight, - alpha: 0.9, - backgroundAlpha: 0.9, - ignoreRayIntersection: true, - visible: true, - isFacingAvatar: true - }); - } + //_this.debugOverlayID = Overlays.addOverlay("text3d", { + //localPosition: { x: 0.3, y: 0.2, z: 1.1 }, + //localRotation: { x: 0.0, y: 0.0, z: 0.0, w: 1.0 }, + //parentID: MyAvatar.sessionUUID, + //parentJointIndex: MyAvatar.getJointIndex("Head"), + //dimensions: { x: textWidth, y: textHeight }, + //backgroundColor: { red: 0, green: 0, blue: 0 }, + //color: { red: 255, green: 255, blue: 255 }, + //topMargin: textMargin, + //leftMargin: textMargin, + //bottomMargin: textMargin, + //rightMargin: textMargin, + //text: "", + //lineHeight: lineHeight, + //alpha: 0.9, + //backgroundAlpha: 0.9, + //ignoreRayIntersection: true, + //visible: true, + //isFacingAvatar: true + //}); + //} - var debugText = ""; - Object.keys(_this.runningPluginNames).forEach(function (pluginName) { - if (_this.runningPluginNames[pluginName]) { - var plugin = controllerDispatcherPlugins[pluginName]; - debugText += pluginName + ": " + plugin.parameters.priority + "\n"; - } - }); - Overlays.editOverlay(_this.debugOverlayID, { text: debugText }); - } + //var debugText = ""; + //Object.keys(_this.runningPluginNames).forEach(function (pluginName) { + //if (_this.runningPluginNames[pluginName]) { + //var plugin = controllerDispatcherPlugins[pluginName]; + //debugText += pluginName + ": " + plugin.parameters.priority + "\n"; + //} + //}); + //Overlays.editOverlay(_this.debugOverlayID, { text: debugText }); + /*}*/ if (PROFILE) { Script.endProfileRange("dispatch.run"); diff --git a/scripts/system/controllers/controllerModules/' b/scripts/system/controllers/controllerModules/' new file mode 100644 index 0000000000..8217e0d022 --- /dev/null +++ b/scripts/system/controllers/controllerModules/' @@ -0,0 +1,181 @@ +"use strict"; + +// webSurfaceLaserInput.js +// +// 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, enableDispatcherModule, disableDispatcherModule, + 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, ContextOverlay, Picks, makeLaserParams +*/ + +Script.include("/~/system/libraries/controllerDispatcherUtils.js"); +Script.include("/~/system/libraries/controllers.js"); + +(function() { + function WebSurfaceLaserInput(hand) { + this.hand = hand; + this.otherHand = this.hand === RIGHT_HAND ? LEFT_HAND : RIGHT_HAND; + this.running = false; + + this.parameters = makeDispatcherModuleParameters( + 160, + this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"], + [], + 100, + makeLaserParams(hand, true)); + + this.grabModuleWantsNearbyOverlay = function(controllerData) { + if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) { + var nearGrabName = this.hand === RIGHT_HAND ? "RightNearParentingGrabOverlay" : "LeftNearParentingGrabOverlay"; + var nearGrabModule = getEnabledModuleByName(nearGrabName); + if (nearGrabModule) { + var candidateOverlays = controllerData.nearbyOverlayIDs[this.hand]; + var grabbableOverlays = candidateOverlays.filter(function(overlayID) { + return Overlays.getProperty(overlayID, "grabbable"); + }); + var target = nearGrabModule.getTargetID(grabbableOverlays, controllerData); + if (target) { + return true; + } + } + nearGrabName = this.hand === RIGHT_HAND ? "RightNearParentingGrabEntity" : "LeftNearParentingGrabEntity"; + nearGrabModule = getEnabledModuleByName(nearGrabName); + if (nearGrabModule && nearGrabModule.isReady(controllerData)) { + return nearGrabModule.isReady(controllerData).active; + } + nearGrabName = this.hand === RIGHT_HAND ? "RightNearActionGrabEntity" : "LeftNearActionGrabEntity"; + nearGrabModule = getEnabledModuleByName(nearGrabName); + if (nearGrabModule && nearGrabModule.isReady(controllerData)) { + return nearGrabModule.isReady(controllerData).active; + } + } + return false; + }; + + this.getOtherModule = function() { + return this.hand === RIGHT_HAND ? leftOverlayLaserInput : rightOverlayLaserInput; + }; + + this.isPointingAtNearGrabbableEntity = function(controllerData, triggerPressed) { + // we are searching for an entity that is not a web entity. We want to be able to + // grab a non-web entity if the ray-pick intersects one. + var intersection = controllerData.rayPicks[this.hand]; + if (intersection.type === Picks.INTERSECTED_ENTITY) { + // is pointing at an entity. + var entityProperties = Entities.getEntityProperties(intersection.objectID); + var entityType = entityProperties.type; + if (entityIsGrabbable(entityProperties) && entityType !== "Web") { + // check if entity is near grabbable. + var distance = Vec3.distance(entityProperties.position, controllerData.controllerLocations[this.hand].position); + if (distance >= NEAR_GRAB_RADIUS * MyAvatar.sensorToWorldScale) { + // far-grabbable, but still return it as true anyway + return true; + } + } + } + return false; + }; + + this.isPointingAtTriggerable = function(controllerData, triggerPressed) { + // allow pointing at tablet, unlocked web entities, or web overlays automatically without pressing trigger, + // but for pointing at locked web entities or non-web overlays user must be pressing trigger + var intersection = controllerData.rayPicks[this.hand]; + var objectID = intersection.objectID; + if (intersection.type === Picks.INTERSECTED_OVERLAY) { + if ((HMD.tabletID && objectID === HMD.tabletID) || + (HMD.tabletScreenID && objectID === HMD.tabletScreenID) || + (HMD.homeButtonID && objectID === HMD.homeButtonID)) { + return true; + } else { + var overlayType = Overlays.getOverlayType(objectID); + return overlayType === "web3d" || triggerPressed; + } + } else if (intersection.type === Picks.INTERSECTED_ENTITY) { + var entityProperty = Entities.getEntityProperties(objectID); + var entityType = entityProperty.type; + var isLocked = entityProperty.locked; + return (!isLocked || triggerPressed || entityType === "Web"); + } + return false; + }; + + this.deleteContextOverlay = function() { + var farGrabModule = getEnabledModuleByName(this.hand === RIGHT_HAND + ? "RightFarActionGrabEntity" : "LeftFarActionGrabEntity"); + if (farGrabModule) { + var entityWithContextOverlay = farGrabModule.entityWithContextOverlay; + + if (entityWithContextOverlay) { + ContextOverlay.destroyContextOverlay(entityWithContextOverlay); + farGrabModule.entityWithContextOverlay = false; + } + } + }; + + this.updateAllwaysOn = function() { + var PREFER_STYLUS_OVER_LASER = "preferStylusOverLaser"; + this.parameters.handLaser.allwaysOn = !Settings.getValue(PREFER_STYLUS_OVER_LASER, false); + }; + + this.getDominantHand = function() { + return MyAvatar.getDominantHand() === "right" ? 1 : 0; + }; + + this.dominantHandOverride = false; + + this.isReady = function(controllerData) { + var otherModuleRunning = this.getOtherModule().running; + otherModuleRunning = otherModuleRunning && this.getDominantHand() !== this.hand; // Auto-swap to dominant hand. + var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE && + controllerData.triggerValues[this.otherHand] <= TRIGGER_OFF_VALUE; + var allowThisModule = !otherModuleRunning || isTriggerPressed; + if (allowThisModule && this.isPointingAtTriggerable(controllerData, isTriggerPressed) && + (controllerData.nearbyEntityProperties[this.hand] !== [])) { + this.updateAllwaysOn(); + if (isTriggerPressed) { + this.dominantHandOverride = true; // Override dominant hand. + this.getOtherModule().dominantHandOverride = false; + } + if (this.parameters.handLaser.allwaysOn || isTriggerPressed) { + return makeRunningValues(true, [], []); + } + } + return makeRunningValues(false, [], []); + }; + + this.run = function(controllerData, deltaTime) { + var otherModuleRunning = this.getOtherModule().running; + otherModuleRunning = otherModuleRunning && this.getDominantHand() !== this.hand; // Auto-swap to dominant hand. + otherModuleRunning = otherModuleRunning || this.getOtherModule().dominantHandOverride; // Override dominant hand. + var grabModuleNeedsToRun = this.grabModuleWantsNearbyOverlay(controllerData); + var allowThisModule = !otherModuleRunning && !grabModuleNeedsToRun; + var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE; + var laserOn = isTriggerPressed || this.parameters.handLaser.allwaysOn; + if (allowThisModule && (laserOn && this.isPointingAtTriggerable(controllerData, isTriggerPressed)) && + (controllerData.nearbyEntityProperties[this.hand] !== [] || (this.isPointingAtNearGrabbableEntity(controllerData, isTriggerPressed)))) { + this.running = true; + return makeRunningValues(true, [], []); + } + this.deleteContextOverlay(); + this.running = false; + this.dominantHandOverride = false; + return makeRunningValues(false, [], []); + }; + } + + var leftOverlayLaserInput = new WebSurfaceLaserInput(LEFT_HAND); + var rightOverlayLaserInput = new WebSurfaceLaserInput(RIGHT_HAND); + + enableDispatcherModule("LeftWebSurfaceLaserInput", leftOverlayLaserInput); + enableDispatcherModule("RightWebSurfaceLaserInput", rightOverlayLaserInput); + + function cleanup() { + disableDispatcherModule("LeftWebSurfaceLaserInput"); + disableDispatcherModule("RightWebSurfaceLaserInput"); + } + Script.scriptEnding.connect(cleanup); +}()); diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index 16cf2eef5c..dd7bccf667 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -60,7 +60,7 @@ Script.include("/~/system/libraries/controllers.js"); return this.hand === RIGHT_HAND ? leftOverlayLaserInput : rightOverlayLaserInput; }; - this.isPointingAtNearGrabbableEntity = function(controllerData, triggerPressed) { + this.isPointingAtFarGrabbableEntity = function(controllerData, triggerPressed) { // we are searching for an entity that is not a web entity. We want to be able to // grab a non-web entity if the ray-pick intersects one. var intersection = controllerData.rayPicks[this.hand]; @@ -71,9 +71,7 @@ Script.include("/~/system/libraries/controllers.js"); if (entityIsGrabbable(entityProperties) && entityType !== "Web") { // check if entity is near grabbable. var distance = Vec3.distance(entityProperties.position, controllerData.controllerLocations[this.hand].position); - if (distance <= NEAR_GRAB_RADIUS * MyAvatar.sensorToWorldScale) { - return triggerPressed; - } else { + if (distance >= NEAR_GRAB_RADIUS * MyAvatar.sensorToWorldScale) { // far-grabbable, but still return it as true anyway return true; } @@ -135,8 +133,8 @@ Script.include("/~/system/libraries/controllers.js"); var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE && controllerData.triggerValues[this.otherHand] <= TRIGGER_OFF_VALUE; var allowThisModule = !otherModuleRunning || isTriggerPressed; - if (allowThisModule && this.isPointingAtTriggerable(controllerData, isTriggerPressed) && - !this.isPointingAtNearGrabbableEntity(controllerData, isTriggerPressed)) { + if (allowThisModule && this.isPointingAtTriggerable(controllerData, isTriggerPressed) && + (controllerData.nearbyEntityProperties[this.hand] !== [])) { this.updateAllwaysOn(); if (isTriggerPressed) { this.dominantHandOverride = true; // Override dominant hand. @@ -158,7 +156,7 @@ Script.include("/~/system/libraries/controllers.js"); var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE; var laserOn = isTriggerPressed || this.parameters.handLaser.allwaysOn; if (allowThisModule && (laserOn && this.isPointingAtTriggerable(controllerData, isTriggerPressed)) && - !this.isPointingAtNearGrabbableEntity(controllerData, isTriggerPressed)) { + (controllerData.nearbyEntityProperties[this.hand] !== [] || !(this.isPointingAtFarGrabbableEntity(controllerData, isTriggerPressed)))) { this.running = true; return makeRunningValues(true, [], []); } From 1880c49d0358b535156d00671499f14fddab2979 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Fri, 20 Jul 2018 17:18:58 -0700 Subject: [PATCH 09/28] removing garbage file --- .../system/controllers/controllerModules/' | 181 ------------------ 1 file changed, 181 deletions(-) delete mode 100644 scripts/system/controllers/controllerModules/' diff --git a/scripts/system/controllers/controllerModules/' b/scripts/system/controllers/controllerModules/' deleted file mode 100644 index 8217e0d022..0000000000 --- a/scripts/system/controllers/controllerModules/' +++ /dev/null @@ -1,181 +0,0 @@ -"use strict"; - -// webSurfaceLaserInput.js -// -// 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, enableDispatcherModule, disableDispatcherModule, - 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, ContextOverlay, Picks, makeLaserParams -*/ - -Script.include("/~/system/libraries/controllerDispatcherUtils.js"); -Script.include("/~/system/libraries/controllers.js"); - -(function() { - function WebSurfaceLaserInput(hand) { - this.hand = hand; - this.otherHand = this.hand === RIGHT_HAND ? LEFT_HAND : RIGHT_HAND; - this.running = false; - - this.parameters = makeDispatcherModuleParameters( - 160, - this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"], - [], - 100, - makeLaserParams(hand, true)); - - this.grabModuleWantsNearbyOverlay = function(controllerData) { - if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) { - var nearGrabName = this.hand === RIGHT_HAND ? "RightNearParentingGrabOverlay" : "LeftNearParentingGrabOverlay"; - var nearGrabModule = getEnabledModuleByName(nearGrabName); - if (nearGrabModule) { - var candidateOverlays = controllerData.nearbyOverlayIDs[this.hand]; - var grabbableOverlays = candidateOverlays.filter(function(overlayID) { - return Overlays.getProperty(overlayID, "grabbable"); - }); - var target = nearGrabModule.getTargetID(grabbableOverlays, controllerData); - if (target) { - return true; - } - } - nearGrabName = this.hand === RIGHT_HAND ? "RightNearParentingGrabEntity" : "LeftNearParentingGrabEntity"; - nearGrabModule = getEnabledModuleByName(nearGrabName); - if (nearGrabModule && nearGrabModule.isReady(controllerData)) { - return nearGrabModule.isReady(controllerData).active; - } - nearGrabName = this.hand === RIGHT_HAND ? "RightNearActionGrabEntity" : "LeftNearActionGrabEntity"; - nearGrabModule = getEnabledModuleByName(nearGrabName); - if (nearGrabModule && nearGrabModule.isReady(controllerData)) { - return nearGrabModule.isReady(controllerData).active; - } - } - return false; - }; - - this.getOtherModule = function() { - return this.hand === RIGHT_HAND ? leftOverlayLaserInput : rightOverlayLaserInput; - }; - - this.isPointingAtNearGrabbableEntity = function(controllerData, triggerPressed) { - // we are searching for an entity that is not a web entity. We want to be able to - // grab a non-web entity if the ray-pick intersects one. - var intersection = controllerData.rayPicks[this.hand]; - if (intersection.type === Picks.INTERSECTED_ENTITY) { - // is pointing at an entity. - var entityProperties = Entities.getEntityProperties(intersection.objectID); - var entityType = entityProperties.type; - if (entityIsGrabbable(entityProperties) && entityType !== "Web") { - // check if entity is near grabbable. - var distance = Vec3.distance(entityProperties.position, controllerData.controllerLocations[this.hand].position); - if (distance >= NEAR_GRAB_RADIUS * MyAvatar.sensorToWorldScale) { - // far-grabbable, but still return it as true anyway - return true; - } - } - } - return false; - }; - - this.isPointingAtTriggerable = function(controllerData, triggerPressed) { - // allow pointing at tablet, unlocked web entities, or web overlays automatically without pressing trigger, - // but for pointing at locked web entities or non-web overlays user must be pressing trigger - var intersection = controllerData.rayPicks[this.hand]; - var objectID = intersection.objectID; - if (intersection.type === Picks.INTERSECTED_OVERLAY) { - if ((HMD.tabletID && objectID === HMD.tabletID) || - (HMD.tabletScreenID && objectID === HMD.tabletScreenID) || - (HMD.homeButtonID && objectID === HMD.homeButtonID)) { - return true; - } else { - var overlayType = Overlays.getOverlayType(objectID); - return overlayType === "web3d" || triggerPressed; - } - } else if (intersection.type === Picks.INTERSECTED_ENTITY) { - var entityProperty = Entities.getEntityProperties(objectID); - var entityType = entityProperty.type; - var isLocked = entityProperty.locked; - return (!isLocked || triggerPressed || entityType === "Web"); - } - return false; - }; - - this.deleteContextOverlay = function() { - var farGrabModule = getEnabledModuleByName(this.hand === RIGHT_HAND - ? "RightFarActionGrabEntity" : "LeftFarActionGrabEntity"); - if (farGrabModule) { - var entityWithContextOverlay = farGrabModule.entityWithContextOverlay; - - if (entityWithContextOverlay) { - ContextOverlay.destroyContextOverlay(entityWithContextOverlay); - farGrabModule.entityWithContextOverlay = false; - } - } - }; - - this.updateAllwaysOn = function() { - var PREFER_STYLUS_OVER_LASER = "preferStylusOverLaser"; - this.parameters.handLaser.allwaysOn = !Settings.getValue(PREFER_STYLUS_OVER_LASER, false); - }; - - this.getDominantHand = function() { - return MyAvatar.getDominantHand() === "right" ? 1 : 0; - }; - - this.dominantHandOverride = false; - - this.isReady = function(controllerData) { - var otherModuleRunning = this.getOtherModule().running; - otherModuleRunning = otherModuleRunning && this.getDominantHand() !== this.hand; // Auto-swap to dominant hand. - var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE && - controllerData.triggerValues[this.otherHand] <= TRIGGER_OFF_VALUE; - var allowThisModule = !otherModuleRunning || isTriggerPressed; - if (allowThisModule && this.isPointingAtTriggerable(controllerData, isTriggerPressed) && - (controllerData.nearbyEntityProperties[this.hand] !== [])) { - this.updateAllwaysOn(); - if (isTriggerPressed) { - this.dominantHandOverride = true; // Override dominant hand. - this.getOtherModule().dominantHandOverride = false; - } - if (this.parameters.handLaser.allwaysOn || isTriggerPressed) { - return makeRunningValues(true, [], []); - } - } - return makeRunningValues(false, [], []); - }; - - this.run = function(controllerData, deltaTime) { - var otherModuleRunning = this.getOtherModule().running; - otherModuleRunning = otherModuleRunning && this.getDominantHand() !== this.hand; // Auto-swap to dominant hand. - otherModuleRunning = otherModuleRunning || this.getOtherModule().dominantHandOverride; // Override dominant hand. - var grabModuleNeedsToRun = this.grabModuleWantsNearbyOverlay(controllerData); - var allowThisModule = !otherModuleRunning && !grabModuleNeedsToRun; - var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE; - var laserOn = isTriggerPressed || this.parameters.handLaser.allwaysOn; - if (allowThisModule && (laserOn && this.isPointingAtTriggerable(controllerData, isTriggerPressed)) && - (controllerData.nearbyEntityProperties[this.hand] !== [] || (this.isPointingAtNearGrabbableEntity(controllerData, isTriggerPressed)))) { - this.running = true; - return makeRunningValues(true, [], []); - } - this.deleteContextOverlay(); - this.running = false; - this.dominantHandOverride = false; - return makeRunningValues(false, [], []); - }; - } - - var leftOverlayLaserInput = new WebSurfaceLaserInput(LEFT_HAND); - var rightOverlayLaserInput = new WebSurfaceLaserInput(RIGHT_HAND); - - enableDispatcherModule("LeftWebSurfaceLaserInput", leftOverlayLaserInput); - enableDispatcherModule("RightWebSurfaceLaserInput", rightOverlayLaserInput); - - function cleanup() { - disableDispatcherModule("LeftWebSurfaceLaserInput"); - disableDispatcherModule("RightWebSurfaceLaserInput"); - } - Script.scriptEnding.connect(cleanup); -}()); From a2aeacab649d77acc8399291f719ea7b0f16c758 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Mon, 23 Jul 2018 12:17:19 -0700 Subject: [PATCH 10/28] adding fix for near grabbing with web entity --- .../controllerModules/webSurfaceLaserInput.js | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index dd7bccf667..5009bec0f5 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -60,25 +60,14 @@ Script.include("/~/system/libraries/controllers.js"); return this.hand === RIGHT_HAND ? leftOverlayLaserInput : rightOverlayLaserInput; }; - this.isPointingAtFarGrabbableEntity = function(controllerData, triggerPressed) { - // we are searching for an entity that is not a web entity. We want to be able to - // grab a non-web entity if the ray-pick intersects one. + this.isPointingAtNearGrabbableEntity = function(controllerData, triggerPressed) { var intersection = controllerData.rayPicks[this.hand]; - if (intersection.type === Picks.INTERSECTED_ENTITY) { - // is pointing at an entity. - var entityProperties = Entities.getEntityProperties(intersection.objectID); - var entityType = entityProperties.type; - if (entityIsGrabbable(entityProperties) && entityType !== "Web") { - // check if entity is near grabbable. - var distance = Vec3.distance(entityProperties.position, controllerData.controllerLocations[this.hand].position); - if (distance >= NEAR_GRAB_RADIUS * MyAvatar.sensorToWorldScale) { - // far-grabbable, but still return it as true anyway - return true; - } - } + var objectID = intersection.objectID; + if(intersection.type === Picks.INTERSECTED_ENTITY) { + return (controllerData.nearbyEntityPropertiesByID[objectID] !== null && triggerPressed); } return false; - }; + } this.isPointingAtTriggerable = function(controllerData, triggerPressed) { // allow pointing at tablet, unlocked web entities, or web overlays automatically without pressing trigger, @@ -98,7 +87,7 @@ Script.include("/~/system/libraries/controllers.js"); var entityProperty = Entities.getEntityProperties(objectID); var entityType = entityProperty.type; var isLocked = entityProperty.locked; - return (!isLocked || triggerPressed || entityType === "Web"); + return entityType === "Web" && (!isLocked || triggerPressed); } return false; }; @@ -156,7 +145,7 @@ Script.include("/~/system/libraries/controllers.js"); var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE; var laserOn = isTriggerPressed || this.parameters.handLaser.allwaysOn; if (allowThisModule && (laserOn && this.isPointingAtTriggerable(controllerData, isTriggerPressed)) && - (controllerData.nearbyEntityProperties[this.hand] !== [] || !(this.isPointingAtFarGrabbableEntity(controllerData, isTriggerPressed)))) { + (controllerData.nearbyEntityProperties[this.hand] !== [])) { this.running = true; return makeRunningValues(true, [], []); } From 1ec136a19c04a3f9e39ee7f691667a3713eb1231 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Mon, 23 Jul 2018 12:18:26 -0700 Subject: [PATCH 11/28] removing debug overlay statements --- .../controllers/controllerDispatcher.js | 45 ------------------- 1 file changed, 45 deletions(-) diff --git a/scripts/system/controllers/controllerDispatcher.js b/scripts/system/controllers/controllerDispatcher.js index 399ccf0ba3..91ab824a54 100644 --- a/scripts/system/controllers/controllerDispatcher.js +++ b/scripts/system/controllers/controllerDispatcher.js @@ -31,7 +31,6 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); var PROFILE = false; var DEBUG = false; - var DEBUG_OVERLAY = true; if (typeof Test !== "undefined") { PROFILE = true; @@ -380,47 +379,6 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); } _this.pointerManager.updatePointersRenderState(controllerData.triggerClicks, controllerData.triggerValues); -/* if (DEBUG_OVERLAY) {*/ - //if (!_this.debugOverlayID) { - - //var textWidth = 0.4; - //var textHeight = 0.3; - //var numberOfLines = 15; - //var textMargin = 0.02; - //var lineHeight = (textHeight - (2 * textMargin)) / numberOfLines; - - //_this.debugOverlayID = Overlays.addOverlay("text3d", { - //localPosition: { x: 0.3, y: 0.2, z: 1.1 }, - //localRotation: { x: 0.0, y: 0.0, z: 0.0, w: 1.0 }, - //parentID: MyAvatar.sessionUUID, - //parentJointIndex: MyAvatar.getJointIndex("Head"), - //dimensions: { x: textWidth, y: textHeight }, - //backgroundColor: { red: 0, green: 0, blue: 0 }, - //color: { red: 255, green: 255, blue: 255 }, - //topMargin: textMargin, - //leftMargin: textMargin, - //bottomMargin: textMargin, - //rightMargin: textMargin, - //text: "", - //lineHeight: lineHeight, - //alpha: 0.9, - //backgroundAlpha: 0.9, - //ignoreRayIntersection: true, - //visible: true, - //isFacingAvatar: true - //}); - //} - - //var debugText = ""; - //Object.keys(_this.runningPluginNames).forEach(function (pluginName) { - //if (_this.runningPluginNames[pluginName]) { - //var plugin = controllerDispatcherPlugins[pluginName]; - //debugText += pluginName + ": " + plugin.parameters.priority + "\n"; - //} - //}); - //Overlays.editOverlay(_this.debugOverlayID, { text: debugText }); - /*}*/ - if (PROFILE) { Script.endProfileRange("dispatch.run"); } @@ -524,9 +482,6 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); this.cleanup = function () { Controller.disableMapping(MAPPING_NAME); _this.pointerManager.removePointers(); - if (_this.debugOverlayID) { - Overlays.deleteOverlay(_this.debugOverlayID); - } Pointers.removePointer(this.mouseRayPick); Selection.disableListHighlight(DISPATCHER_HOVERING_LIST); }; From e4a5be668a15aa603e3210b2053c2bc62ad2536a Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Mon, 23 Jul 2018 12:29:01 -0700 Subject: [PATCH 12/28] adding check function for pointing at near grabbable entity --- scripts/system/controllers/controllerDispatcher.js | 2 -- .../controllers/controllerModules/webSurfaceLaserInput.js | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/system/controllers/controllerDispatcher.js b/scripts/system/controllers/controllerDispatcher.js index 91ab824a54..4002fd297b 100644 --- a/scripts/system/controllers/controllerDispatcher.js +++ b/scripts/system/controllers/controllerDispatcher.js @@ -48,7 +48,6 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); this.tabletID = null; this.blacklist = []; this.pointerManager = new PointerManager(); - this.debugOverlayID = null; // a module can occupy one or more "activity" slots while it's running. If all the required slots for a module are // not set to false (not in use), a module cannot start. When a module is using a slot, that module's name @@ -378,7 +377,6 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); } } _this.pointerManager.updatePointersRenderState(controllerData.triggerClicks, controllerData.triggerValues); - if (PROFILE) { Script.endProfileRange("dispatch.run"); } diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index 5009bec0f5..92423f0670 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -123,7 +123,7 @@ Script.include("/~/system/libraries/controllers.js"); controllerData.triggerValues[this.otherHand] <= TRIGGER_OFF_VALUE; var allowThisModule = !otherModuleRunning || isTriggerPressed; if (allowThisModule && this.isPointingAtTriggerable(controllerData, isTriggerPressed) && - (controllerData.nearbyEntityProperties[this.hand] !== [])) { + !this.isPointingAtNearGrabbableEntity(controllerData, isTriggerPressed)) { this.updateAllwaysOn(); if (isTriggerPressed) { this.dominantHandOverride = true; // Override dominant hand. @@ -145,7 +145,7 @@ Script.include("/~/system/libraries/controllers.js"); var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE; var laserOn = isTriggerPressed || this.parameters.handLaser.allwaysOn; if (allowThisModule && (laserOn && this.isPointingAtTriggerable(controllerData, isTriggerPressed)) && - (controllerData.nearbyEntityProperties[this.hand] !== [])) { + !this.isPointingAtNearGrabbableEntity(controllerData, isTriggerPressed)) { this.running = true; return makeRunningValues(true, [], []); } From c0dfbac480ab9cbed8f7d2e90197a903439639ce Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Tue, 24 Jul 2018 10:04:51 -0700 Subject: [PATCH 13/28] adding comment for possible solution - still WIP --- .../controllers/controllerModules/webSurfaceLaserInput.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index 92423f0670..ef9ff0c6ae 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -124,6 +124,7 @@ Script.include("/~/system/libraries/controllers.js"); var allowThisModule = !otherModuleRunning || isTriggerPressed; if (allowThisModule && this.isPointingAtTriggerable(controllerData, isTriggerPressed) && !this.isPointingAtNearGrabbableEntity(controllerData, isTriggerPressed)) { + //(controllerData.nearbyEntityProperties[this.hand] !== [])) { this.updateAllwaysOn(); if (isTriggerPressed) { this.dominantHandOverride = true; // Override dominant hand. @@ -146,6 +147,7 @@ Script.include("/~/system/libraries/controllers.js"); var laserOn = isTriggerPressed || this.parameters.handLaser.allwaysOn; if (allowThisModule && (laserOn && this.isPointingAtTriggerable(controllerData, isTriggerPressed)) && !this.isPointingAtNearGrabbableEntity(controllerData, isTriggerPressed)) { + //(controllerData.nearbyEntityProperties[this.hand] !== [])) { this.running = true; return makeRunningValues(true, [], []); } From 5b4eb922818917a81603b898d019fa8625506f20 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Tue, 21 Aug 2018 14:04:29 -0700 Subject: [PATCH 14/28] adding fix --- .../controllers/controllerModules/webSurfaceLaserInput.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index ef9ff0c6ae..4077d07c38 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -76,7 +76,7 @@ Script.include("/~/system/libraries/controllers.js"); var objectID = intersection.objectID; if (intersection.type === Picks.INTERSECTED_OVERLAY) { if ((HMD.tabletID && objectID === HMD.tabletID) || - (HMD.tabletScreenID && objectID === HMD.tabletScreenID) || + (HMD.tabletScreenID && objectID === HMD.tabletScreenID) || (HMD.homeButtonID && objectID === HMD.homeButtonID)) { return true; } else { @@ -122,9 +122,9 @@ Script.include("/~/system/libraries/controllers.js"); var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE && controllerData.triggerValues[this.otherHand] <= TRIGGER_OFF_VALUE; var allowThisModule = !otherModuleRunning || isTriggerPressed; + if (allowThisModule && this.isPointingAtTriggerable(controllerData, isTriggerPressed) && !this.isPointingAtNearGrabbableEntity(controllerData, isTriggerPressed)) { - //(controllerData.nearbyEntityProperties[this.hand] !== [])) { this.updateAllwaysOn(); if (isTriggerPressed) { this.dominantHandOverride = true; // Override dominant hand. @@ -147,7 +147,6 @@ Script.include("/~/system/libraries/controllers.js"); var laserOn = isTriggerPressed || this.parameters.handLaser.allwaysOn; if (allowThisModule && (laserOn && this.isPointingAtTriggerable(controllerData, isTriggerPressed)) && !this.isPointingAtNearGrabbableEntity(controllerData, isTriggerPressed)) { - //(controllerData.nearbyEntityProperties[this.hand] !== [])) { this.running = true; return makeRunningValues(true, [], []); } From 7360629d31b452e295ead23e38b9f46fbf231a30 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Tue, 21 Aug 2018 14:13:55 -0700 Subject: [PATCH 15/28] modifying variable naming to fit convention --- .../controllers/controllerModules/webSurfaceLaserInput.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index 4077d07c38..de3eb26086 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -84,9 +84,9 @@ Script.include("/~/system/libraries/controllers.js"); return overlayType === "web3d" || triggerPressed; } } else if (intersection.type === Picks.INTERSECTED_ENTITY) { - var entityProperty = Entities.getEntityProperties(objectID); - var entityType = entityProperty.type; - var isLocked = entityProperty.locked; + var entityProperties = Entities.getEntityProperties(objectID); + var entityType = entityProperties.type; + var isLocked = entityProperties.locked; return entityType === "Web" && (!isLocked || triggerPressed); } return false; From 7aae5366246c0799a04a320a4cf12c6ac45101a5 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Tue, 11 Sep 2018 11:41:24 -0700 Subject: [PATCH 16/28] adding fix to allow web scroll --- .../controllers/controllerModules/nearParentGrabEntity.js | 3 +++ .../controllers/controllerModules/webSurfaceLaserInput.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/system/controllers/controllerModules/nearParentGrabEntity.js b/scripts/system/controllers/controllerModules/nearParentGrabEntity.js index 6bbd19550b..2c0c668a42 100644 --- a/scripts/system/controllers/controllerModules/nearParentGrabEntity.js +++ b/scripts/system/controllers/controllerModules/nearParentGrabEntity.js @@ -24,6 +24,9 @@ Script.include("/~/system/libraries/controllers.js"); // XXX this.ignoreIK = (grabbableData.ignoreIK !== undefined) ? grabbableData.ignoreIK : true; // XXX this.kinematicGrab = (grabbableData.kinematic !== undefined) ? grabbableData.kinematic : NEAR_GRABBING_KINEMATIC; + // this offset needs to match the one in libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp:378 + //var GRAB_POINT_SPHERE_OFFSET = { x: 0.04, y: 0.13, z: 0.039 }; // x = upward, y = forward, z = lateral + function getGrabOffset(handController) { var offset = GRAB_POINT_SPHERE_OFFSET; if (handController === Controller.Standard.LeftHand) { diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index de3eb26086..dd0af0ba8f 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -146,7 +146,7 @@ Script.include("/~/system/libraries/controllers.js"); var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE; var laserOn = isTriggerPressed || this.parameters.handLaser.allwaysOn; if (allowThisModule && (laserOn && this.isPointingAtTriggerable(controllerData, isTriggerPressed)) && - !this.isPointingAtNearGrabbableEntity(controllerData, isTriggerPressed)) { + (controllerData.nearbyEntityProperties[this.hand] !== [])) { this.running = true; return makeRunningValues(true, [], []); } From d9e0352028bdb6ffed215bf6ee301885bdd44893 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Tue, 11 Sep 2018 11:44:32 -0700 Subject: [PATCH 17/28] removing debug comments --- .../controllers/controllerModules/nearParentGrabEntity.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/system/controllers/controllerModules/nearParentGrabEntity.js b/scripts/system/controllers/controllerModules/nearParentGrabEntity.js index 2c0c668a42..6bbd19550b 100644 --- a/scripts/system/controllers/controllerModules/nearParentGrabEntity.js +++ b/scripts/system/controllers/controllerModules/nearParentGrabEntity.js @@ -24,9 +24,6 @@ Script.include("/~/system/libraries/controllers.js"); // XXX this.ignoreIK = (grabbableData.ignoreIK !== undefined) ? grabbableData.ignoreIK : true; // XXX this.kinematicGrab = (grabbableData.kinematic !== undefined) ? grabbableData.kinematic : NEAR_GRABBING_KINEMATIC; - // this offset needs to match the one in libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp:378 - //var GRAB_POINT_SPHERE_OFFSET = { x: 0.04, y: 0.13, z: 0.039 }; // x = upward, y = forward, z = lateral - function getGrabOffset(handController) { var offset = GRAB_POINT_SPHERE_OFFSET; if (handController === Controller.Standard.LeftHand) { From b6c5ae2a688527cdaf5a58a64f05ce61dc9a2345 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Tue, 11 Sep 2018 15:23:40 -0700 Subject: [PATCH 18/28] staging changes --- .../controllers/controllerDispatcher.js | 2 +- .../controllerModules/nearParentGrabEntity.js | 3 ++ .../controllerModules/webSurfaceLaserInput.js | 42 ++++++++++++------- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/scripts/system/controllers/controllerDispatcher.js b/scripts/system/controllers/controllerDispatcher.js index 7a916392b9..c7a8de87b9 100644 --- a/scripts/system/controllers/controllerDispatcher.js +++ b/scripts/system/controllers/controllerDispatcher.js @@ -31,7 +31,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); var BASIC_TIMER_INTERVAL_MS = 1000 / TARGET_UPDATE_HZ; var PROFILE = false; - var DEBUG = false; + var DEBUG = true; if (typeof Test !== "undefined") { PROFILE = true; diff --git a/scripts/system/controllers/controllerModules/nearParentGrabEntity.js b/scripts/system/controllers/controllerModules/nearParentGrabEntity.js index 6bbd19550b..f805dbf60e 100644 --- a/scripts/system/controllers/controllerModules/nearParentGrabEntity.js +++ b/scripts/system/controllers/controllerModules/nearParentGrabEntity.js @@ -24,6 +24,9 @@ Script.include("/~/system/libraries/controllers.js"); // XXX this.ignoreIK = (grabbableData.ignoreIK !== undefined) ? grabbableData.ignoreIK : true; // XXX this.kinematicGrab = (grabbableData.kinematic !== undefined) ? grabbableData.kinematic : NEAR_GRABBING_KINEMATIC; + // this offset needs to match the one in libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp:378 + var GRAB_POINT_SPHERE_OFFSET = { x: 0.04, y: 0.13, z: 0.039 }; // x = upward, y = forward, z = lateral + function getGrabOffset(handController) { var offset = GRAB_POINT_SPHERE_OFFSET; if (handController === Controller.Standard.LeftHand) { diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index dd0af0ba8f..e4978884d0 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -21,6 +21,10 @@ Script.include("/~/system/libraries/controllers.js"); this.otherHand = this.hand === RIGHT_HAND ? LEFT_HAND : RIGHT_HAND; this.running = false; + // parameters for things to be working on + this.isObjectEntity = false; + this.objectID = null; + this.parameters = makeDispatcherModuleParameters( 160, this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"], @@ -60,15 +64,6 @@ Script.include("/~/system/libraries/controllers.js"); return this.hand === RIGHT_HAND ? leftOverlayLaserInput : rightOverlayLaserInput; }; - this.isPointingAtNearGrabbableEntity = function(controllerData, triggerPressed) { - var intersection = controllerData.rayPicks[this.hand]; - var objectID = intersection.objectID; - if(intersection.type === Picks.INTERSECTED_ENTITY) { - return (controllerData.nearbyEntityPropertiesByID[objectID] !== null && triggerPressed); - } - return false; - } - this.isPointingAtTriggerable = function(controllerData, triggerPressed) { // allow pointing at tablet, unlocked web entities, or web overlays automatically without pressing trigger, // but for pointing at locked web entities or non-web overlays user must be pressing trigger @@ -123,14 +118,17 @@ Script.include("/~/system/libraries/controllers.js"); controllerData.triggerValues[this.otherHand] <= TRIGGER_OFF_VALUE; var allowThisModule = !otherModuleRunning || isTriggerPressed; - if (allowThisModule && this.isPointingAtTriggerable(controllerData, isTriggerPressed) && - !this.isPointingAtNearGrabbableEntity(controllerData, isTriggerPressed)) { + if (allowThisModule && this.isPointingAtTriggerable(controllerData, isTriggerPressed)) { this.updateAllwaysOn(); if (isTriggerPressed) { this.dominantHandOverride = true; // Override dominant hand. this.getOtherModule().dominantHandOverride = false; } if (this.parameters.handLaser.allwaysOn || isTriggerPressed) { + var intersection = controllerData.rayPicks[this.hand]; + // the object is either an entity or an overlay. + this.isObjectEntity = (intersection.type === Picks.INTERSECTED_ENTITY); + this.objectID = intersection.objectID; return makeRunningValues(true, [], []); } } @@ -142,17 +140,29 @@ Script.include("/~/system/libraries/controllers.js"); otherModuleRunning = otherModuleRunning && this.getDominantHand() !== this.hand; // Auto-swap to dominant hand. otherModuleRunning = otherModuleRunning || this.getOtherModule().dominantHandOverride; // Override dominant hand. var grabModuleNeedsToRun = this.grabModuleWantsNearbyOverlay(controllerData); - var allowThisModule = !otherModuleRunning && !grabModuleNeedsToRun; + // only allow for non-near grab + var allowThisModule = !otherModuleRunning && !(grabModuleNeedsToRun && controllerData.secondaryValues[this.hand] > BUMPER_ON_VALUE); var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE; var laserOn = isTriggerPressed || this.parameters.handLaser.allwaysOn; - if (allowThisModule && (laserOn && this.isPointingAtTriggerable(controllerData, isTriggerPressed)) && - (controllerData.nearbyEntityProperties[this.hand] !== [])) { - this.running = true; - return makeRunningValues(true, [], []); + if (allowThisModule) { + if (laserOn && this.isPointingAtTriggerable(controllerData, isTriggerPressed)) { + this.running = true; + return makeRunningValues(true, [], []); + } else { + this.deleteContextOverlay(); + this.running = false; + this.dominantHandOverride = false; + return makeRunningValues(false, [], []); + } } this.deleteContextOverlay(); this.running = false; this.dominantHandOverride = false; + this.objectID = null; + if (this.hand === LEFT_HAND) { + print("allowThisModule = " + allowThisModule); + print("isPointingAtTriggerable = " + (laserOn || this.isPointingAtTriggerable(controllerData, isTriggerPressed))); + } return makeRunningValues(false, [], []); }; } From 045ac4cb0d8e38517a2f996ebd8f3209ff5566f0 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Tue, 11 Sep 2018 17:43:03 -0700 Subject: [PATCH 19/28] allowing grip button for interrupting web scroll --- .../controllerModules/webSurfaceLaserInput.js | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index e4978884d0..3ae971cf70 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -33,7 +33,7 @@ Script.include("/~/system/libraries/controllers.js"); makeLaserParams(hand, true)); this.grabModuleWantsNearbyOverlay = function(controllerData) { - if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) { + if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE || controllerData.secondaryValues[this.hand] > BUMPER_ON_VALUE) { var nearGrabName = this.hand === RIGHT_HAND ? "RightNearParentingGrabOverlay" : "LeftNearParentingGrabOverlay"; var nearGrabModule = getEnabledModuleByName(nearGrabName); if (nearGrabModule) { @@ -64,12 +64,12 @@ Script.include("/~/system/libraries/controllers.js"); return this.hand === RIGHT_HAND ? leftOverlayLaserInput : rightOverlayLaserInput; }; - this.isPointingAtTriggerable = function(controllerData, triggerPressed) { + this.isPointingAtTriggerable = function(controllerData, triggerPressed, checkEntitiesOnly) { // allow pointing at tablet, unlocked web entities, or web overlays automatically without pressing trigger, // but for pointing at locked web entities or non-web overlays user must be pressing trigger var intersection = controllerData.rayPicks[this.hand]; var objectID = intersection.objectID; - if (intersection.type === Picks.INTERSECTED_OVERLAY) { + if (intersection.type === Picks.INTERSECTED_OVERLAY && !checkEntitiesOnly) { if ((HMD.tabletID && objectID === HMD.tabletID) || (HMD.tabletScreenID && objectID === HMD.tabletScreenID) || (HMD.homeButtonID && objectID === HMD.homeButtonID)) { @@ -118,7 +118,7 @@ Script.include("/~/system/libraries/controllers.js"); controllerData.triggerValues[this.otherHand] <= TRIGGER_OFF_VALUE; var allowThisModule = !otherModuleRunning || isTriggerPressed; - if (allowThisModule && this.isPointingAtTriggerable(controllerData, isTriggerPressed)) { + if (allowThisModule && this.isPointingAtTriggerable(controllerData, isTriggerPressed, false)) { this.updateAllwaysOn(); if (isTriggerPressed) { this.dominantHandOverride = true; // Override dominant hand. @@ -141,11 +141,16 @@ Script.include("/~/system/libraries/controllers.js"); otherModuleRunning = otherModuleRunning || this.getOtherModule().dominantHandOverride; // Override dominant hand. var grabModuleNeedsToRun = this.grabModuleWantsNearbyOverlay(controllerData); // only allow for non-near grab - var allowThisModule = !otherModuleRunning && !(grabModuleNeedsToRun && controllerData.secondaryValues[this.hand] > BUMPER_ON_VALUE); + var allowThisModule = !otherModuleRunning && !grabModuleNeedsToRun; var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE; var laserOn = isTriggerPressed || this.parameters.handLaser.allwaysOn; if (allowThisModule) { - if (laserOn && this.isPointingAtTriggerable(controllerData, isTriggerPressed)) { + // if trigger is down + not pointing at a web entity, keep running web surface laser + if (isTriggerPressed && !this.isPointingAtTriggerable(controllerData, isTriggerPressed, true)) { + this.running = true; + return makeRunningValues(true, [], []); + // if trigger is down + pointing at a web entity/overlay, keep running web surface laser + } else if (laserOn && this.isPointingAtTriggerable(controllerData, isTriggerPressed, false)) { this.running = true; return makeRunningValues(true, [], []); } else { @@ -155,14 +160,11 @@ Script.include("/~/system/libraries/controllers.js"); return makeRunningValues(false, [], []); } } + // if module needs to stop from near grabs or other modules are running, stop it. this.deleteContextOverlay(); this.running = false; this.dominantHandOverride = false; this.objectID = null; - if (this.hand === LEFT_HAND) { - print("allowThisModule = " + allowThisModule); - print("isPointingAtTriggerable = " + (laserOn || this.isPointingAtTriggerable(controllerData, isTriggerPressed))); - } return makeRunningValues(false, [], []); }; } From b9f0af63e1e52837cd2e692bade3084b1c71a0c5 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Wed, 12 Sep 2018 10:38:21 -0700 Subject: [PATCH 20/28] changing check for near grabbing modules - fixes grabbing for dynamic --- .../controllerModules/webSurfaceLaserInput.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index 3ae971cf70..bd9d5f97e4 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -49,12 +49,19 @@ Script.include("/~/system/libraries/controllers.js"); nearGrabName = this.hand === RIGHT_HAND ? "RightNearParentingGrabEntity" : "LeftNearParentingGrabEntity"; nearGrabModule = getEnabledModuleByName(nearGrabName); if (nearGrabModule && nearGrabModule.isReady(controllerData)) { - return nearGrabModule.isReady(controllerData).active; - } - nearGrabName = this.hand === RIGHT_HAND ? "RightNearActionGrabEntity" : "LeftNearActionGrabEntity"; - nearGrabModule = getEnabledModuleByName(nearGrabName); - if (nearGrabModule && nearGrabModule.isReady(controllerData)) { - return nearGrabModule.isReady(controllerData).active; + // check for if near parent module is active. + var isNearGrabModuleActive = nearGrabModule.isReady(controllerData).active; + if (isNearGrabModuleActive) { + // if true, return true. + return isNearGrabModuleActive; + } else { + // check near action grab entity as a second pass. + nearGrabName = this.hand === RIGHT_HAND ? "RightNearActionGrabEntity" : "LeftNearActionGrabEntity"; + nearGrabModule = getEnabledModuleByName(nearGrabName); + if (nearGrabModule && nearGrabModule.isReady(controllerData)) { + return nearGrabModule.isReady(controllerData).active; + } + } } } return false; From a96e78c72d1c1e6963fc992da7346c39b6cbbad6 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Wed, 12 Sep 2018 10:54:38 -0700 Subject: [PATCH 21/28] removing debug --- scripts/system/controllers/controllerDispatcher.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/system/controllers/controllerDispatcher.js b/scripts/system/controllers/controllerDispatcher.js index c7a8de87b9..7a916392b9 100644 --- a/scripts/system/controllers/controllerDispatcher.js +++ b/scripts/system/controllers/controllerDispatcher.js @@ -31,7 +31,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); var BASIC_TIMER_INTERVAL_MS = 1000 / TARGET_UPDATE_HZ; var PROFILE = false; - var DEBUG = true; + var DEBUG = false; if (typeof Test !== "undefined") { PROFILE = true; From 8bef0d0de4c05644e6f24ae641b85c76051f6d97 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Wed, 12 Sep 2018 10:55:40 -0700 Subject: [PATCH 22/28] removing unused variables --- .../controllers/controllerModules/webSurfaceLaserInput.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index bd9d5f97e4..9a022409fb 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -21,10 +21,6 @@ Script.include("/~/system/libraries/controllers.js"); this.otherHand = this.hand === RIGHT_HAND ? LEFT_HAND : RIGHT_HAND; this.running = false; - // parameters for things to be working on - this.isObjectEntity = false; - this.objectID = null; - this.parameters = makeDispatcherModuleParameters( 160, this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"], @@ -133,9 +129,6 @@ Script.include("/~/system/libraries/controllers.js"); } if (this.parameters.handLaser.allwaysOn || isTriggerPressed) { var intersection = controllerData.rayPicks[this.hand]; - // the object is either an entity or an overlay. - this.isObjectEntity = (intersection.type === Picks.INTERSECTED_ENTITY); - this.objectID = intersection.objectID; return makeRunningValues(true, [], []); } } @@ -171,7 +164,6 @@ Script.include("/~/system/libraries/controllers.js"); this.deleteContextOverlay(); this.running = false; this.dominantHandOverride = false; - this.objectID = null; return makeRunningValues(false, [], []); }; } From acf34dcfdf7fff5379946f9a57d87258edf2d85b Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Wed, 12 Sep 2018 10:58:05 -0700 Subject: [PATCH 23/28] one more unused variable --- .../system/controllers/controllerModules/webSurfaceLaserInput.js | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index 9a022409fb..45a6064d17 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -128,7 +128,6 @@ Script.include("/~/system/libraries/controllers.js"); this.getOtherModule().dominantHandOverride = false; } if (this.parameters.handLaser.allwaysOn || isTriggerPressed) { - var intersection = controllerData.rayPicks[this.hand]; return makeRunningValues(true, [], []); } } From 521361293a55643fb32eea7a7aa4cb1967864e2a Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Wed, 12 Sep 2018 11:03:00 -0700 Subject: [PATCH 24/28] moving comment locations inside conditionals --- .../controllers/controllerModules/webSurfaceLaserInput.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js index 45a6064d17..4e36355621 100644 --- a/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js +++ b/scripts/system/controllers/controllerModules/webSurfaceLaserInput.js @@ -144,12 +144,12 @@ Script.include("/~/system/libraries/controllers.js"); var isTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE; var laserOn = isTriggerPressed || this.parameters.handLaser.allwaysOn; if (allowThisModule) { - // if trigger is down + not pointing at a web entity, keep running web surface laser if (isTriggerPressed && !this.isPointingAtTriggerable(controllerData, isTriggerPressed, true)) { + // if trigger is down + not pointing at a web entity, keep running web surface laser this.running = true; return makeRunningValues(true, [], []); - // if trigger is down + pointing at a web entity/overlay, keep running web surface laser } else if (laserOn && this.isPointingAtTriggerable(controllerData, isTriggerPressed, false)) { + // if trigger is down + pointing at a web entity/overlay, keep running web surface laser this.running = true; return makeRunningValues(true, [], []); } else { From 4b93f9f5cda5c5233b2a5ba89319ac6975678530 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 12 Sep 2018 12:20:03 -0700 Subject: [PATCH 25/28] Revert "use different XORed instance ID for replicas" This reverts commit a37a19da1e4e7657548fb29ad6cf4e130a5eda76. --- libraries/avatars/src/AvatarHashMap.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/libraries/avatars/src/AvatarHashMap.cpp b/libraries/avatars/src/AvatarHashMap.cpp index 284bb20f16..6fc53fcc59 100644 --- a/libraries/avatars/src/AvatarHashMap.cpp +++ b/libraries/avatars/src/AvatarHashMap.cpp @@ -86,8 +86,7 @@ void AvatarReplicas::processDeletedTraitInstance(const QUuid& parentID, AvatarTr if (_replicasMap.find(parentID) != _replicasMap.end()) { auto &replicas = _replicasMap[parentID]; for (auto avatar : replicas) { - avatar->processDeletedTraitInstance(traitType, - AvatarTraits::xoredInstanceID(instanceID, avatar->getTraitInstanceXORID())); + avatar->processDeletedTraitInstance(traitType, instanceID); } } } @@ -96,9 +95,7 @@ void AvatarReplicas::processTraitInstance(const QUuid& parentID, AvatarTraits::T if (_replicasMap.find(parentID) != _replicasMap.end()) { auto &replicas = _replicasMap[parentID]; for (auto avatar : replicas) { - avatar->processTraitInstance(traitType, - AvatarTraits::xoredInstanceID(instanceID, avatar->getTraitInstanceXORID()), - traitBinaryData); + avatar->processTraitInstance(traitType, instanceID, traitBinaryData); } } } @@ -364,11 +361,11 @@ void AvatarHashMap::processBulkAvatarTraits(QSharedPointer mess // in order to handle re-connections to the avatar mixer when the other if (traitBinarySize == AvatarTraits::DELETED_TRAIT_SIZE) { avatar->processDeletedTraitInstance(traitType, xoredInstanceID); - _replicas.processDeletedTraitInstance(avatarID, traitType, traitInstanceID); + _replicas.processDeletedTraitInstance(avatarID, traitType, xoredInstanceID); } else { auto traitData = message->read(traitBinarySize); avatar->processTraitInstance(traitType, xoredInstanceID, traitData); - _replicas.processTraitInstance(avatarID, traitType, traitInstanceID, traitData); + _replicas.processTraitInstance(avatarID, traitType, xoredInstanceID, traitData); } processedInstanceVersion = packetTraitVersion; } else { From 6d3e6a661f1bc5d3650c6d11e502d4072c78826e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 12 Sep 2018 12:20:31 -0700 Subject: [PATCH 26/28] Revert "XOR incoming trait instance IDs for other avatars" This reverts commit 9b3d9dd0f319ad2964e54a72bd17934765a91c02. --- libraries/avatars/src/AvatarData.h | 5 ----- libraries/avatars/src/AvatarHashMap.cpp | 20 ++++-------------- libraries/avatars/src/AvatarTraits.h | 21 ++----------------- libraries/avatars/src/ClientTraitsHandler.cpp | 21 ++++++++++++------- libraries/avatars/src/ClientTraitsHandler.h | 4 ++++ 5 files changed, 24 insertions(+), 47 deletions(-) diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index e9f1f5f6c3..b010a9f924 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -1193,9 +1193,6 @@ public: void setReplicaIndex(int replicaIndex) { _replicaIndex = replicaIndex; } int getReplicaIndex() { return _replicaIndex; } - const AvatarTraits::TraitInstanceID getTraitInstanceXORID() const { return _traitInstanceXORID; } - void cycleTraitInstanceXORID() { _traitInstanceXORID = QUuid::createUuid(); } - signals: /**jsdoc @@ -1502,8 +1499,6 @@ private: // privatize the copy constructor and assignment operator so they cannot be called AvatarData(const AvatarData&); AvatarData& operator= (const AvatarData&); - - AvatarTraits::TraitInstanceID _traitInstanceXORID { QUuid::createUuid() }; }; Q_DECLARE_METATYPE(AvatarData*) diff --git a/libraries/avatars/src/AvatarHashMap.cpp b/libraries/avatars/src/AvatarHashMap.cpp index 6fc53fcc59..d205a915f8 100644 --- a/libraries/avatars/src/AvatarHashMap.cpp +++ b/libraries/avatars/src/AvatarHashMap.cpp @@ -343,29 +343,17 @@ void AvatarHashMap::processBulkAvatarTraits(QSharedPointer mess AvatarTraits::TraitInstanceID traitInstanceID = QUuid::fromRfc4122(message->readWithoutCopy(NUM_BYTES_RFC4122_UUID)); - // XOR the incoming trait instance ID with this avatar object's personal XOR ID - - // this ensures that we have separate entity instances in the local tree - // if we briefly end up with two Avatar objects for this node - - // (which can occur if the shared pointer for the - // previous instance of an avatar hasn't yet gone out of scope before the - // new instance is created) - - auto xoredInstanceID = AvatarTraits::xoredInstanceID(traitInstanceID, avatar->getTraitInstanceXORID()); - message->readPrimitive(&traitBinarySize); auto& processedInstanceVersion = lastProcessedVersions.getInstanceValueRef(traitType, traitInstanceID); if (packetTraitVersion > processedInstanceVersion) { - // in order to handle re-connections to the avatar mixer when the other if (traitBinarySize == AvatarTraits::DELETED_TRAIT_SIZE) { - avatar->processDeletedTraitInstance(traitType, xoredInstanceID); - _replicas.processDeletedTraitInstance(avatarID, traitType, xoredInstanceID); + avatar->processDeletedTraitInstance(traitType, traitInstanceID); + _replicas.processDeletedTraitInstance(avatarID, traitType, traitInstanceID); } else { auto traitData = message->read(traitBinarySize); - avatar->processTraitInstance(traitType, xoredInstanceID, traitData); - _replicas.processTraitInstance(avatarID, traitType, xoredInstanceID, traitData); + avatar->processTraitInstance(traitType, traitInstanceID, traitData); + _replicas.processTraitInstance(avatarID, traitType, traitInstanceID, traitData); } processedInstanceVersion = packetTraitVersion; } else { diff --git a/libraries/avatars/src/AvatarTraits.h b/libraries/avatars/src/AvatarTraits.h index 47be0d6111..5866caf234 100644 --- a/libraries/avatars/src/AvatarTraits.h +++ b/libraries/avatars/src/AvatarTraits.h @@ -41,8 +41,7 @@ namespace AvatarTraits { const TraitWireSize DELETED_TRAIT_SIZE = -1; inline qint64 packInstancedTraitDelete(TraitType traitType, TraitInstanceID instanceID, ExtendedIODevice& destination, - TraitVersion traitVersion = NULL_TRAIT_VERSION, - TraitInstanceID xoredInstanceID = TraitInstanceID()) { + TraitVersion traitVersion = NULL_TRAIT_VERSION) { qint64 bytesWritten = 0; bytesWritten += destination.writePrimitive(traitType); @@ -51,28 +50,12 @@ namespace AvatarTraits { bytesWritten += destination.writePrimitive(traitVersion); } - if (xoredInstanceID.isNull()) { - bytesWritten += destination.write(instanceID.toRfc4122()); - } else { - bytesWritten += destination.write(xoredInstanceID.toRfc4122()); - } + bytesWritten += destination.write(instanceID.toRfc4122()); bytesWritten += destination.writePrimitive(DELETED_TRAIT_SIZE); return bytesWritten; } - - inline TraitInstanceID xoredInstanceID(TraitInstanceID localInstanceID, TraitInstanceID xorKeyID) { - QByteArray xoredInstanceID { NUM_BYTES_RFC4122_UUID, 0 }; - auto xorKeyIDBytes = xorKeyID.toRfc4122(); - auto localInstanceIDBytes = localInstanceID.toRfc4122(); - - for (auto i = 0; i < localInstanceIDBytes.size(); ++i) { - xoredInstanceID[i] = localInstanceIDBytes[i] ^ xorKeyIDBytes[i]; - } - - return QUuid::fromRfc4122(xoredInstanceID); - } }; #endif // hifi_AvatarTraits_h diff --git a/libraries/avatars/src/ClientTraitsHandler.cpp b/libraries/avatars/src/ClientTraitsHandler.cpp index 479852cf9a..94823610dc 100644 --- a/libraries/avatars/src/ClientTraitsHandler.cpp +++ b/libraries/avatars/src/ClientTraitsHandler.cpp @@ -45,7 +45,7 @@ void ClientTraitsHandler::resetForNewMixer() { _owningAvatar->prepareResetTraitInstances(); // reset the trait XOR ID since we're resetting for a new avatar mixer - _owningAvatar->cycleTraitInstanceXORID(); + _sessionXORID = QUuid::createUuid().toRfc4122(); } void ClientTraitsHandler::sendChangedTraitsToMixer() { @@ -100,15 +100,11 @@ void ClientTraitsHandler::sendChangedTraitsToMixer() { // since this is going to the mixer, use the XORed instance ID (to anonymize trait instance IDs // that would typically persist across sessions) _owningAvatar->packTraitInstance(instancedIt->traitType, instanceIDValuePair.id, *traitsPacketList, - AvatarTraits::NULL_TRAIT_VERSION, - AvatarTraits::xoredInstanceID(instanceIDValuePair.id, - _owningAvatar->getTraitInstanceXORID())); + AvatarTraits::NULL_TRAIT_VERSION, xorInstanceID(instanceIDValuePair.id)); } else if (!_shouldPerformInitialSend && instanceIDValuePair.value == Deleted) { // pack delete for this trait instance AvatarTraits::packInstancedTraitDelete(instancedIt->traitType, instanceIDValuePair.id, - *traitsPacketList, AvatarTraits::NULL_TRAIT_VERSION, - AvatarTraits::xoredInstanceID(instanceIDValuePair.id, - _owningAvatar->getTraitInstanceXORID())); + *traitsPacketList); } } @@ -122,6 +118,17 @@ void ClientTraitsHandler::sendChangedTraitsToMixer() { } } +AvatarTraits::TraitInstanceID ClientTraitsHandler::xorInstanceID(AvatarTraits::TraitInstanceID localInstanceID) { + QByteArray xorInstanceID { NUM_BYTES_RFC4122_UUID, 0 }; + auto localInstanceIDBytes = localInstanceID.toRfc4122(); + + for (auto i = 0; i < localInstanceIDBytes.size(); ++i) { + xorInstanceID[i] = localInstanceIDBytes[i] ^ _sessionXORID[i]; + } + + return QUuid::fromRfc4122(xorInstanceID); +} + void ClientTraitsHandler::processTraitOverride(QSharedPointer message, SharedNodePointer sendingNode) { if (sendingNode->getType() == NodeType::AvatarMixer) { while (message->getBytesLeftToRead()) { diff --git a/libraries/avatars/src/ClientTraitsHandler.h b/libraries/avatars/src/ClientTraitsHandler.h index 6d1592ba74..2319061502 100644 --- a/libraries/avatars/src/ClientTraitsHandler.h +++ b/libraries/avatars/src/ClientTraitsHandler.h @@ -37,6 +37,8 @@ public: void resetForNewMixer(); + AvatarTraits::TraitInstanceID xorInstanceID(AvatarTraits::TraitInstanceID localInstanceID); + public slots: void processTraitOverride(QSharedPointer message, SharedNodePointer sendingNode); @@ -53,6 +55,8 @@ private: AvatarTraits::TraitVersion _currentTraitVersion { AvatarTraits::DEFAULT_TRAIT_VERSION }; AvatarTraits::TraitVersion _currentSkeletonVersion { AvatarTraits::NULL_TRAIT_VERSION }; + + QByteArray _sessionXORID { NUM_BYTES_RFC4122_UUID, 0}; bool _shouldPerformInitialSend { false }; bool _hasChangedTraits { false }; From 1789d51d6e15ab7982579f8bbc6a03104e15d0a0 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 12 Sep 2018 12:22:07 -0700 Subject: [PATCH 27/28] Revert "cycle avatar entity IDs for new avatar mixer" This reverts commit 20912349a4f0b8854bda467ee1e1bd04d9bb67ef. --- .../src/avatars-renderer/Avatar.cpp | 1 + libraries/avatars/src/AvatarData.cpp | 10 ++-------- libraries/avatars/src/AvatarData.h | 3 +-- libraries/avatars/src/AvatarTraits.h | 2 +- libraries/avatars/src/ClientTraitsHandler.cpp | 20 +------------------ libraries/avatars/src/ClientTraitsHandler.h | 8 ++------ 6 files changed, 8 insertions(+), 36 deletions(-) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index ac25f65576..cadc3b31e3 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -141,6 +141,7 @@ Avatar::~Avatar() { } }); } + auto geometryCache = DependencyManager::get(); if (geometryCache) { geometryCache->releaseID(_nameRectGeometryID); diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index e7aaa18576..ea6dbd7074 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -1861,9 +1861,7 @@ qint64 AvatarData::packTrait(AvatarTraits::TraitType traitType, ExtendedIODevice } qint64 AvatarData::packTraitInstance(AvatarTraits::TraitType traitType, AvatarTraits::TraitInstanceID traitInstanceID, - ExtendedIODevice& destination, AvatarTraits::TraitVersion traitVersion, - AvatarTraits::TraitInstanceID wireInstanceID) { - + ExtendedIODevice& destination, AvatarTraits::TraitVersion traitVersion) { qint64 bytesWritten = 0; bytesWritten += destination.writePrimitive(traitType); @@ -1872,11 +1870,7 @@ qint64 AvatarData::packTraitInstance(AvatarTraits::TraitType traitType, AvatarTr bytesWritten += destination.writePrimitive(traitVersion); } - if (!wireInstanceID.isNull()) { - bytesWritten += destination.write(wireInstanceID.toRfc4122()); - } else { - bytesWritten += destination.write(traitInstanceID.toRfc4122()); - } + bytesWritten += destination.write(traitInstanceID.toRfc4122()); if (traitType == AvatarTraits::AvatarEntity) { // grab a read lock on the avatar entities and check for entity data for the given ID diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index b010a9f924..db2b82b0b7 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -962,8 +962,7 @@ public: qint64 packTrait(AvatarTraits::TraitType traitType, ExtendedIODevice& destination, AvatarTraits::TraitVersion traitVersion = AvatarTraits::NULL_TRAIT_VERSION); qint64 packTraitInstance(AvatarTraits::TraitType traitType, AvatarTraits::TraitInstanceID instanceID, - ExtendedIODevice& destination, AvatarTraits::TraitVersion traitVersion = AvatarTraits::NULL_TRAIT_VERSION, - AvatarTraits::TraitInstanceID wireInstanceID = AvatarTraits::TraitInstanceID()); + ExtendedIODevice& destination, AvatarTraits::TraitVersion traitVersion = AvatarTraits::NULL_TRAIT_VERSION); void prepareResetTraitInstances(); diff --git a/libraries/avatars/src/AvatarTraits.h b/libraries/avatars/src/AvatarTraits.h index 5866caf234..f0c807a432 100644 --- a/libraries/avatars/src/AvatarTraits.h +++ b/libraries/avatars/src/AvatarTraits.h @@ -41,7 +41,7 @@ namespace AvatarTraits { const TraitWireSize DELETED_TRAIT_SIZE = -1; inline qint64 packInstancedTraitDelete(TraitType traitType, TraitInstanceID instanceID, ExtendedIODevice& destination, - TraitVersion traitVersion = NULL_TRAIT_VERSION) { + TraitVersion traitVersion = NULL_TRAIT_VERSION) { qint64 bytesWritten = 0; bytesWritten += destination.writePrimitive(traitType); diff --git a/libraries/avatars/src/ClientTraitsHandler.cpp b/libraries/avatars/src/ClientTraitsHandler.cpp index 94823610dc..a06b53da7c 100644 --- a/libraries/avatars/src/ClientTraitsHandler.cpp +++ b/libraries/avatars/src/ClientTraitsHandler.cpp @@ -43,9 +43,6 @@ void ClientTraitsHandler::resetForNewMixer() { // pre-fill the instanced statuses that we will need to send next frame _owningAvatar->prepareResetTraitInstances(); - - // reset the trait XOR ID since we're resetting for a new avatar mixer - _sessionXORID = QUuid::createUuid().toRfc4122(); } void ClientTraitsHandler::sendChangedTraitsToMixer() { @@ -96,11 +93,7 @@ void ClientTraitsHandler::sendChangedTraitsToMixer() { || instanceIDValuePair.value == Updated) { // this is a changed trait we need to send or we haven't send out trait information yet // ask the owning avatar to pack it - - // since this is going to the mixer, use the XORed instance ID (to anonymize trait instance IDs - // that would typically persist across sessions) - _owningAvatar->packTraitInstance(instancedIt->traitType, instanceIDValuePair.id, *traitsPacketList, - AvatarTraits::NULL_TRAIT_VERSION, xorInstanceID(instanceIDValuePair.id)); + _owningAvatar->packTraitInstance(instancedIt->traitType, instanceIDValuePair.id, *traitsPacketList); } else if (!_shouldPerformInitialSend && instanceIDValuePair.value == Deleted) { // pack delete for this trait instance AvatarTraits::packInstancedTraitDelete(instancedIt->traitType, instanceIDValuePair.id, @@ -118,17 +111,6 @@ void ClientTraitsHandler::sendChangedTraitsToMixer() { } } -AvatarTraits::TraitInstanceID ClientTraitsHandler::xorInstanceID(AvatarTraits::TraitInstanceID localInstanceID) { - QByteArray xorInstanceID { NUM_BYTES_RFC4122_UUID, 0 }; - auto localInstanceIDBytes = localInstanceID.toRfc4122(); - - for (auto i = 0; i < localInstanceIDBytes.size(); ++i) { - xorInstanceID[i] = localInstanceIDBytes[i] ^ _sessionXORID[i]; - } - - return QUuid::fromRfc4122(xorInstanceID); -} - void ClientTraitsHandler::processTraitOverride(QSharedPointer message, SharedNodePointer sendingNode) { if (sendingNode->getType() == NodeType::AvatarMixer) { while (message->getBytesLeftToRead()) { diff --git a/libraries/avatars/src/ClientTraitsHandler.h b/libraries/avatars/src/ClientTraitsHandler.h index 2319061502..27ba58d46b 100644 --- a/libraries/avatars/src/ClientTraitsHandler.h +++ b/libraries/avatars/src/ClientTraitsHandler.h @@ -30,15 +30,13 @@ public: void markTraitUpdated(AvatarTraits::TraitType updatedTrait) { _traitStatuses[updatedTrait] = Updated; _hasChangedTraits = true; } - void markInstancedTraitUpdated(AvatarTraits::TraitType traitType, AvatarTraits::TraitInstanceID updatedInstanceID) + void markInstancedTraitUpdated(AvatarTraits::TraitType traitType, QUuid updatedInstanceID) { _traitStatuses.instanceInsert(traitType, updatedInstanceID, Updated); _hasChangedTraits = true; } - void markInstancedTraitDeleted(AvatarTraits::TraitType traitType, AvatarTraits::TraitInstanceID deleteInstanceID) + void markInstancedTraitDeleted(AvatarTraits::TraitType traitType, QUuid deleteInstanceID) { _traitStatuses.instanceInsert(traitType, deleteInstanceID, Deleted); _hasChangedTraits = true; } void resetForNewMixer(); - AvatarTraits::TraitInstanceID xorInstanceID(AvatarTraits::TraitInstanceID localInstanceID); - public slots: void processTraitOverride(QSharedPointer message, SharedNodePointer sendingNode); @@ -55,8 +53,6 @@ private: AvatarTraits::TraitVersion _currentTraitVersion { AvatarTraits::DEFAULT_TRAIT_VERSION }; AvatarTraits::TraitVersion _currentSkeletonVersion { AvatarTraits::NULL_TRAIT_VERSION }; - - QByteArray _sessionXORID { NUM_BYTES_RFC4122_UUID, 0}; bool _shouldPerformInitialSend { false }; bool _hasChangedTraits { false }; From b1f44d2ad7c82f085881f8e243f75cf06f272167 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 12 Sep 2018 12:30:15 -0700 Subject: [PATCH 28/28] perform avatar entity cleanup in AvatarManager::handleRemovedAvatar --- interface/src/avatar/AvatarManager.cpp | 5 ++++ .../src/avatars-renderer/Avatar.cpp | 24 ++++++++++--------- .../src/avatars-renderer/Avatar.h | 1 + 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/interface/src/avatar/AvatarManager.cpp b/interface/src/avatar/AvatarManager.cpp index b9e30a38eb..443d19e473 100644 --- a/interface/src/avatar/AvatarManager.cpp +++ b/interface/src/avatar/AvatarManager.cpp @@ -443,6 +443,11 @@ void AvatarManager::handleRemovedAvatar(const AvatarSharedPointer& removedAvatar avatar->die(); queuePhysicsChange(avatar); + // remove this avatar's entities from the tree now, if we wait (as we did previously) for this Avatar's destructor + // it might not fire until after we create a new instance for the same remote avatar, which creates a race + // on the creation of entities for that avatar instance and the deletion of entities for this instance + avatar->removeAvatarEntitiesFromTree(); + if (removalReason == KillAvatarReason::TheirAvatarEnteredYourBubble) { emit DependencyManager::get()->enteredIgnoreRadius(); } else if (removalReason == KillAvatarReason::AvatarDisconnected) { diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index cadc3b31e3..914a3b7c6e 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -131,17 +131,6 @@ Avatar::Avatar(QThread* thread) : } Avatar::~Avatar() { - auto treeRenderer = DependencyManager::get(); - EntityTreePointer entityTree = treeRenderer ? treeRenderer->getTree() : nullptr; - if (entityTree) { - entityTree->withWriteLock([&] { - AvatarEntityMap avatarEntities = getAvatarEntityData(); - for (auto entityID : avatarEntities.keys()) { - entityTree->deleteEntity(entityID, true, true); - } - }); - } - auto geometryCache = DependencyManager::get(); if (geometryCache) { geometryCache->releaseID(_nameRectGeometryID); @@ -386,6 +375,19 @@ void Avatar::updateAvatarEntities() { setAvatarEntityDataChanged(false); } +void Avatar::removeAvatarEntitiesFromTree() { + auto treeRenderer = DependencyManager::get(); + EntityTreePointer entityTree = treeRenderer ? treeRenderer->getTree() : nullptr; + if (entityTree) { + entityTree->withWriteLock([&] { + AvatarEntityMap avatarEntities = getAvatarEntityData(); + for (auto entityID : avatarEntities.keys()) { + entityTree->deleteEntity(entityID, true, true); + } + }); + } +} + void Avatar::relayJointDataToChildren() { forEachChild([&](SpatiallyNestablePointer child) { if (child->getNestableType() == NestableType::Entity) { diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h index 3482c3c193..4f1c010d84 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h @@ -73,6 +73,7 @@ public: void init(); void updateAvatarEntities(); + void removeAvatarEntitiesFromTree(); void simulate(float deltaTime, bool inView); virtual void simulateAttachments(float deltaTime);