From 6f92cf033059ce083f1c7f1d6d7697ca79e4d479 Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Wed, 19 Apr 2023 21:53:52 +0200 Subject: [PATCH] V8-related JS fixes --- .../controllerModules/farGrabEntity.js | 2 ++ .../controllers/controllerModules/teleport.js | 20 ++++++++++++------- scripts/system/create/edit.js | 19 +++++++++--------- .../system/create/entityList/entityList.js | 2 +- .../entitySelectionTool.js | 11 ++++------ .../libraries/controllerDispatcherUtils.js | 6 +++--- 6 files changed, 33 insertions(+), 27 deletions(-) diff --git a/scripts/system/controllers/controllerModules/farGrabEntity.js b/scripts/system/controllers/controllerModules/farGrabEntity.js index c486d46c33..fa6e7b5b15 100644 --- a/scripts/system/controllers/controllerModules/farGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farGrabEntity.js @@ -567,6 +567,8 @@ Script.include("/~/system/libraries/controllers.js"); if (this.distanceHolding) { var targetProps = Entities.getEntityProperties(this.targetObject.entityID, ["position", "rotation", "registrationPoint", "dimensions"]); + if (controllerData.rayPicks[this.hand].intersection == null) + return undefined; return worldPositionToRegistrationFrameMatrix(targetProps, controllerData.rayPicks[this.hand].intersection); } return undefined; diff --git a/scripts/system/controllers/controllerModules/teleport.js b/scripts/system/controllers/controllerModules/teleport.js index 5ed8346462..fd29dda156 100644 --- a/scripts/system/controllers/controllerModules/teleport.js +++ b/scripts/system/controllers/controllerModules/teleport.js @@ -216,15 +216,21 @@ Script.include("/~/system/libraries/controllers.js"); avatarSensorPosition.y = 0; var targetRotation = Entities.getEntityProperties(_this.targetOverlayID, ["rotation"]).rotation; - var relativePlayAreaCenterOffset = - Vec3.sum(_this.playAreaCenterOffset, { x: 0, y: -TARGET_MODEL_DIMENSIONS.y / 2, z: 0 }); - var localPosition = Vec3.multiplyQbyV(Quat.inverse(targetRotation), - Vec3.multiplyQbyV(sensorToWorldRotation, - Vec3.multiply(avatarScale, Vec3.subtract(relativePlayAreaCenterOffset, avatarSensorPosition)))); - localPosition.y = _this.teleportScaleFactor * localPosition.y; + if (targetRotation != null) { + var relativePlayAreaCenterOffset = + Vec3.sum(_this.playAreaCenterOffset, {x: 0, y: -TARGET_MODEL_DIMENSIONS.y / 2, z: 0}); + var localPosition = Vec3.multiplyQbyV(Quat.inverse(targetRotation), + Vec3.multiplyQbyV(sensorToWorldRotation, + Vec3.multiply(avatarScale, Vec3.subtract(relativePlayAreaCenterOffset, avatarSensorPosition)))); + localPosition.y = _this.teleportScaleFactor * localPosition.y; + } else { + print(""); + } playAreaOverlayProperties.parentID = _this.targetOverlayID; - playAreaOverlayProperties.localPosition = localPosition; + if (targetRotation != null) { + playAreaOverlayProperties.localPosition = localPosition; + } } Overlays.editOverlay(_this.playAreaOverlay, playAreaOverlayProperties); diff --git a/scripts/system/create/edit.js b/scripts/system/create/edit.js index cf84444862..ac02ec62f3 100644 --- a/scripts/system/create/edit.js +++ b/scripts/system/create/edit.js @@ -88,6 +88,7 @@ var selectionDisplay = SelectionDisplay; selectionDisplay.createApp = createApp; var selectionManager = SelectionManager; + selectionManager.createApp = createApp; var PARTICLE_SYSTEM_URL = Script.resolvePath("assets/images/icon-particles.svg"); var POINT_LIGHT_URL = Script.resolvePath("assets/images/icon-point-light.svg"); @@ -114,8 +115,8 @@ } }); - var hmdMultiSelectMode = false; - var expectingRotateAsClickedSurface = false; + createApp.hmdMultiSelectMode = false; + createApp.expectingRotateAsClickedSurface = false; var keepSelectedOnNextClick = false; var copiedPosition; @@ -1236,11 +1237,11 @@ } var result; - if (expectingRotateAsClickedSurface) { + if (createApp.expectingRotateAsClickedSurface) { if (!SelectionManager.hasSelection() || !SelectionManager.hasUnlockedSelection()) { audioFeedback.rejection(); Window.notifyEditError("You have nothing selected, or the selection is locked."); - expectingRotateAsClickedSurface = false; + createApp.expectingRotateAsClickedSurface = false; } else { //Rotate Selection according the Surface Normal var normalRotation = Quat.lookAtSimple(Vec3.ZERO, Vec3.multiply(entityResult.surfaceNormal, -1)); @@ -1255,7 +1256,7 @@ selectionDisplay.moveSelection(Vec3.sum(entityResult.intersection, Vec3.multiplyQbyV( normalRotation, {"x": 0.0, "y":0.0, "z": distanceFromSurface}))); selectionManager._update(false, this); createApp.pushCommandForSelections(); - expectingRotateAsClickedSurface = false; + createApp.expectingRotateAsClickedSurface = false; audioFeedback.action(); } keepSelectedOnNextClick = true; @@ -1299,7 +1300,7 @@ var entity = entityIconOverlayManager.findEntity(data.overlayID); if (entity !== null) { - if (hmdMultiSelectMode) { + if (createApp.hmdMultiSelectMode) { selectionManager.addEntity(entity, true, this); } else { selectionManager.setSelections([entity], this); @@ -2510,7 +2511,7 @@ webView.setLandscape(true); } else { if (!visible) { - hmdMultiSelectMode = false; + createApp.hmdMultiSelectMode = false; webView.setLandscape(false); } } @@ -3278,9 +3279,9 @@ if (!SelectionManager.hasSelection() || !SelectionManager.hasUnlockedSelection()) { audioFeedback.rejection(); Window.notifyEditError("You have nothing selected, or the selection is locked."); - expectingRotateAsClickedSurface = false; + createApp.expectingRotateAsClickedSurface = false; } else { - expectingRotateAsClickedSurface = true; + createApp.expectingRotateAsClickedSurface = true; } } diff --git a/scripts/system/create/entityList/entityList.js b/scripts/system/create/entityList/entityList.js index 6f45340828..67810b1f3f 100644 --- a/scripts/system/create/entityList/entityList.js +++ b/scripts/system/create/entityList/entityList.js @@ -370,7 +370,7 @@ var EntityListTool = function(shouldUseEditTabletApp, selectionManager) { } else if (data.type === 'unparent') { that.createApp.unparentSelectedEntities(); } else if (data.type === 'hmdMultiSelectMode') { - hmdMultiSelectMode = data.value; + that.createApp.hmdMultiSelectMode = data.value; } else if (data.type === 'selectAllInBox') { that.createApp.selectAllEntitiesInCurrentSelectionBox(false); } else if (data.type === 'selectAllTouchingBox') { diff --git a/scripts/system/create/entitySelectionTool/entitySelectionTool.js b/scripts/system/create/entitySelectionTool/entitySelectionTool.js index 2be752eab0..903869685e 100644 --- a/scripts/system/create/entitySelectionTool/entitySelectionTool.js +++ b/scripts/system/create/entitySelectionTool/entitySelectionTool.js @@ -88,11 +88,9 @@ SelectionManager = (function() { if (channel !== 'entityToolUpdates') { return; } - print("handleEntitySelectionToolUpdates entityToolUpdates"); if (sender !== MyAvatar.sessionUUID) { return; } - print("handleEntitySelectionToolUpdates MyAvatar.sessionUUID"); var wantDebug = false; var messageParsed; @@ -112,11 +110,11 @@ SelectionManager = (function() { if (wantDebug) { print("setting selection to " + messageParsed.entityID); } - if (expectingRotateAsClickedSurface) { + if (that.createApp.expectingRotateAsClickedSurface) { if (!SelectionManager.hasSelection() || !SelectionManager.hasUnlockedSelection()) { audioFeedback.rejection(); Window.notifyEditError("You have nothing selected, or the selection is locked."); - expectingRotateAsClickedSurface = false; + that.createApp.expectingRotateAsClickedSurface = false; } else { //Rotate Selection according the Surface Normal var normalRotation = Quat.lookAtSimple(Vec3.ZERO, Vec3.multiply(messageParsed.surfaceNormal, -1)); @@ -131,7 +129,7 @@ SelectionManager = (function() { selectionDisplay.moveSelection(Vec3.sum(messageParsed.intersection, Vec3.multiplyQbyV( normalRotation, {"x": 0.0, "y":0.0, "z": distanceFromSurface}))); that._update(false, this); that.createApp.pushCommandForSelections(); - expectingRotateAsClickedSurface = false; + that.createApp.expectingRotateAsClickedSurface = false; audioFeedback.action(); } } else { @@ -140,7 +138,7 @@ SelectionManager = (function() { if (intersectObj.intersects) { return; } - if (hmdMultiSelectMode) { + if (that.createApp.hmdMultiSelectMode) { that.addEntity(messageParsed.entityID, true, that); } else { that.setSelections([messageParsed.entityID], that); @@ -152,7 +150,6 @@ SelectionManager = (function() { that.clearSelections(); } } else if (messageParsed.method === "pointingAt") { - print("handleEntitySelectionToolUpdates pointingAt"); if (messageParsed.hand === Controller.Standard.RightHand) { that.pointingAtDesktopWindowRight = messageParsed.desktopWindow; that.pointingAtTabletRight = messageParsed.tablet; diff --git a/scripts/system/libraries/controllerDispatcherUtils.js b/scripts/system/libraries/controllerDispatcherUtils.js index bf9776d478..7f1e47ab42 100644 --- a/scripts/system/libraries/controllerDispatcherUtils.js +++ b/scripts/system/libraries/controllerDispatcherUtils.js @@ -563,8 +563,8 @@ var distanceBetweenPointAndEntityBoundingBox = function(point, entityProps) { var localPoint = entityXform.inv().xformPoint(point); var minOffset = Vec3.multiplyVbyV(entityProps.registrationPoint, entityProps.dimensions); var maxOffset = Vec3.multiplyVbyV(Vec3.subtract(ONE_VEC, entityProps.registrationPoint), entityProps.dimensions); - var localMin = Vec3.subtract(entityXform.trans, minOffset); - var localMax = Vec3.sum(entityXform.trans, maxOffset); + var localMin = Vec3.subtract(entityXform.pos, minOffset); + var localMax = Vec3.sum(entityXform.pos, maxOffset); var v = {x: localPoint.x, y: localPoint.y, z: localPoint.z}; v.x = Math.max(v.x, localMin.x); @@ -589,7 +589,7 @@ var worldPositionToRegistrationFrameMatrix = function(wptrProps, pos) { // get world matrix for intersection point var intersectionMat = new Xform({ x: 0, y: 0, z:0, w: 1 }, pos); - // calculate world matrix for registrationPoint addjusted entity + // calculate world matrix for registrationPoint adjusted entity var DEFAULT_REGISTRATION_POINT = { x: 0.5, y: 0.5, z: 0.5 }; var regRatio = Vec3.subtract(DEFAULT_REGISTRATION_POINT, wptrProps.registrationPoint); var regOffset = Vec3.multiplyVbyV(regRatio, wptrProps.dimensions);