From 3a23ec86d55c8a6b91b2356ff41982b6aac81247 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 14 Feb 2017 13:57:48 -0800 Subject: [PATCH] handles etc work better --- .../system/controllers/handControllerGrab.js | 68 +++++++++++------- scripts/system/html/js/entityList.js | 4 +- scripts/system/html/js/entityProperties.js | 4 +- .../system/libraries/entitySelectionTool.js | 70 +++++++++---------- 4 files changed, 80 insertions(+), 66 deletions(-) diff --git a/scripts/system/controllers/handControllerGrab.js b/scripts/system/controllers/handControllerGrab.js index f61ea3013e..e7ca74cf54 100644 --- a/scripts/system/controllers/handControllerGrab.js +++ b/scripts/system/controllers/handControllerGrab.js @@ -738,6 +738,7 @@ function MyController(hand) { this.grabPointIntersectsEntity = false; this.stylus = null; this.homeButtonTouched = false; + this.editTriggered = false; // Until there is some reliable way to keep track of a "stack" of parentIDs, we'll have problems // when more than one avatar does parenting grabs on things. This script tries to work @@ -858,9 +859,10 @@ function MyController(hand) { }; this.setState = function(newState, reason) { - if ((isInEditMode() && this.grabbedEntity !== HMD.tabletID )&& (newState !== STATE_OFF && - newState !== STATE_SEARCHING && - newState !== STATE_OVERLAY_STYLUS_TOUCHING)) { + if ((isInEditMode() && this.grabbedEntity !== HMD.tabletID) && + (newState !== STATE_OFF && + newState !== STATE_SEARCHING && + newState !== STATE_OVERLAY_STYLUS_TOUCHING)) { return; } setGrabCommunications((newState === STATE_DISTANCE_HOLDING) || (newState === STATE_NEAR_GRABBING)); @@ -1037,7 +1039,7 @@ function MyController(hand) { } var searchSphereLocation = Vec3.sum(distantPickRay.origin, - Vec3.multiply(distantPickRay.direction, this.searchSphereDistance)); + Vec3.multiply(distantPickRay.direction, this.searchSphereDistance)); this.searchSphereOn(searchSphereLocation, SEARCH_SPHERE_SIZE * this.searchSphereDistance, (this.triggerSmoothedGrab() || this.secondarySqueezed()) ? COLORS_GRAB_SEARCHING_FULL_SQUEEZE : @@ -1199,6 +1201,10 @@ function MyController(hand) { this.checkForUnexpectedChildren(); + if (this.editTriggered) { + this.editTriggered = false; + } + if (this.triggerSmoothedReleased() && this.secondaryReleased()) { this.waitForTriggerRelease = false; } @@ -1636,22 +1642,24 @@ function MyController(hand) { return aDistance - bDistance; }); entity = grabbableEntities[0]; - name = entityPropertiesCache.getProps(entity).name; - this.grabbedEntity = entity; - if (this.entityWantsTrigger(entity)) { - if (this.triggerSmoothedGrab()) { - this.setState(STATE_NEAR_TRIGGER, "near trigger '" + name + "'"); - return; + if (!isInEditMode() || entity == HMD.tabletID) { + name = entityPropertiesCache.getProps(entity).name; + this.grabbedEntity = entity; + if (this.entityWantsTrigger(entity)) { + if (this.triggerSmoothedGrab()) { + this.setState(STATE_NEAR_TRIGGER, "near trigger '" + name + "'"); + return; + } else { + // potentialNearTriggerEntity = entity; + } } else { - // potentialNearTriggerEntity = entity; - } - } else { - // If near something grabbable, grab it! - if ((this.triggerSmoothedGrab() || this.secondarySqueezed()) && nearGrabEnabled) { - this.setState(STATE_NEAR_GRABBING, "near grab '" + name + "'"); - return; - } else { - // potentialNearGrabEntity = entity; + // If near something grabbable, grab it! + if ((this.triggerSmoothedGrab() || this.secondarySqueezed()) && nearGrabEnabled) { + this.setState(STATE_NEAR_GRABBING, "near grab '" + name + "'"); + return; + } else { + // potentialNearGrabEntity = entity; + } } } } @@ -1666,16 +1674,22 @@ function MyController(hand) { } } - if (rayPickInfo.entityID) { - if (this.triggerSmoothedGrab() && isInEditMode()) { - this.searchIndicatorOn(rayPickInfo.searchRay); - Messages.sendLocalMessage("entityToolUpdates", JSON.stringify({ - method: "selectEntity", - entityID: rayPickInfo.entityID - })); - return; + if (isInEditMode()) { + this.searchIndicatorOn(rayPickInfo.searchRay); + if (this.triggerSmoothedGrab()) { + if (!this.editTriggered && rayPickInfo.entityID) { + Messages.sendLocalMessage("entityToolUpdates", JSON.stringify({ + method: "selectEntity", + entityID: rayPickInfo.entityID + })); + } + this.editTriggered = true; } + Reticle.setVisible(false); + return; + } + if (rayPickInfo.entityID) { entity = rayPickInfo.entityID; name = entityPropertiesCache.getProps(entity).name; if (this.entityWantsTrigger(entity)) { diff --git a/scripts/system/html/js/entityList.js b/scripts/system/html/js/entityList.js index 1af9c1e1d6..048d5561df 100644 --- a/scripts/system/html/js/entityList.js +++ b/scripts/system/html/js/entityList.js @@ -330,10 +330,10 @@ function loaded() { } } else if (data.type == "update") { var newEntities = data.entities; - if (newEntities.length == 0) { + if (newEntities && newEntities.length == 0) { elNoEntitiesMessage.style.display = "block"; elFooter.firstChild.nodeValue = "0 entities found"; - } else { + } else if (newEntities) { elNoEntitiesMessage.style.display = "none"; for (var i = 0; i < newEntities.length; i++) { var id = newEntities[i].id; diff --git a/scripts/system/html/js/entityProperties.js b/scripts/system/html/js/entityProperties.js index 957cea4528..1c15aafa8b 100644 --- a/scripts/system/html/js/entityProperties.js +++ b/scripts/system/html/js/entityProperties.js @@ -732,7 +732,7 @@ function loaded() { } } else if (data.type == "update") { - if (data.selections.length == 0) { + if (!data.selections || data.selections.length == 0) { if (editor !== null && lastEntityID !== null) { saveJSONUserData(true); deleteJSONEditor(); @@ -741,7 +741,7 @@ function loaded() { elType.innerHTML = "No selection"; elID.innerHTML = ""; disableProperties(); - } else if (data.selections.length > 1) { + } else if (data.selections && data.selections.length > 1) { deleteJSONEditor(); var selections = data.selections; diff --git a/scripts/system/libraries/entitySelectionTool.js b/scripts/system/libraries/entitySelectionTool.js index 4fd708a86e..08ae7ae5f7 100644 --- a/scripts/system/libraries/entitySelectionTool.js +++ b/scripts/system/libraries/entitySelectionTool.js @@ -1028,44 +1028,44 @@ SelectionDisplay = (function() { that.TRIGGER_OFF_VALUE = 0.15; that.triggered = false; var activeHand = Controller.Standard.RightHand; - // function makeTriggerHandler(hand) { - // return function (value) { - // if (!that.triggered && (value > that.TRIGGER_GRAB_VALUE)) { // should we smooth? - // that.triggered = true; - // if (activeHand !== hand) { - // // No switching while the other is already triggered, so no need to release. - // activeHand = (activeHand === Controller.Standard.RightHand) ? Controller.Standard.LeftHand : Controller.Standard.RightHand; - // } - // if (Reticle.pointingAtSystemOverlay || Overlays.getOverlayAtPoint(Reticle.position)) { - // return; - // } - // var eventResult = that.mousePressEvent({}); - // if (!eventResult || (eventResult === 'selectionBox')) { - // var pickRay = controllerComputePickRay(); - // if (pickRay) { - // var entityIntersection = Entities.findRayIntersection(pickRay, true); + function makeTriggerHandler(hand) { + return function (value) { + if (!that.triggered && (value > that.TRIGGER_GRAB_VALUE)) { // should we smooth? + that.triggered = true; + if (activeHand !== hand) { + // No switching while the other is already triggered, so no need to release. + activeHand = (activeHand === Controller.Standard.RightHand) ? Controller.Standard.LeftHand : Controller.Standard.RightHand; + } + if (Reticle.pointingAtSystemOverlay || Overlays.getOverlayAtPoint(Reticle.position)) { + return; + } + var eventResult = that.mousePressEvent({}); + // if (!eventResult || (eventResult === 'selectionBox')) { + // var pickRay = controllerComputePickRay(); + // if (pickRay) { + // var entityIntersection = Entities.findRayIntersection(pickRay, true); - // var overlayIntersection = Overlays.findRayIntersection(pickRay); - // if (entityIntersection.intersects && - // (!overlayIntersection.intersects || (entityIntersection.distance < overlayIntersection.distance))) { + // var overlayIntersection = Overlays.findRayIntersection(pickRay); + // if (entityIntersection.intersects && + // (!overlayIntersection.intersects || (entityIntersection.distance < overlayIntersection.distance))) { - // if (HMD.tabletID === entityIntersection.entityID) { - // return; - // } + // if (HMD.tabletID === entityIntersection.entityID) { + // return; + // } - // selectionManager.setSelections([entityIntersection.entityID]); - // } - // } - // } - // } else if (that.triggered && (value < that.TRIGGER_OFF_VALUE)) { - // that.triggered = false; - // that.mouseReleaseEvent({}); - // } - // }; - // } - // that.triggerMapping.from(Controller.Standard.RT).peek().to(makeTriggerHandler(Controller.Standard.RightHand)); - // that.triggerMapping.from(Controller.Standard.LT).peek().to(makeTriggerHandler(Controller.Standard.LeftHand)); + // selectionManager.setSelections([entityIntersection.entityID]); + // } + // } + // } + } else if (that.triggered && (value < that.TRIGGER_OFF_VALUE)) { + that.triggered = false; + that.mouseReleaseEvent({}); + } + }; + } + that.triggerMapping.from(Controller.Standard.RT).peek().to(makeTriggerHandler(Controller.Standard.RightHand)); + that.triggerMapping.from(Controller.Standard.LT).peek().to(makeTriggerHandler(Controller.Standard.LeftHand)); function controllerComputePickRay() { @@ -2064,7 +2064,7 @@ SelectionDisplay = (function() { }); Overlays.editOverlay(grabberPointLightL, { visible: false - }); + }); Overlays.editOverlay(grabberPointLightR, { visible: false });