From 79b34ae54150635436a30531d3400ccf0b4d4c5f Mon Sep 17 00:00:00 2001 From: Alezia Kurdis <60075796+AleziaKurdis@users.noreply.github.com> Date: Thu, 24 Dec 2020 22:57:49 -0500 Subject: [PATCH] Add "Rotate as the Next Clicked Surface" Add "Rotate as the Next Clicked Surface" --- scripts/system/create/edit.js | 97 +++++++++++++++---- .../entitySelectionTool.js | 64 +++++++++++- 2 files changed, 140 insertions(+), 21 deletions(-) diff --git a/scripts/system/create/edit.js b/scripts/system/create/edit.js index 9e94b68ba1..92a6206100 100644 --- a/scripts/system/create/edit.js +++ b/scripts/system/create/edit.js @@ -109,6 +109,8 @@ var entityIconOverlayManager = new EntityIconOverlayManager(["Light", "ParticleE }); var hmdMultiSelectMode = false; +var expectingRotateAsClickedSurface = false; +var keepSelectedOnNextClick = false; var cameraManager = new CameraManager(); @@ -1106,25 +1108,41 @@ function findClickedEntity(event) { } var result; - - if (iconResult.intersects) { - result = iconResult; - } else if (entityResult.intersects) { - result = entityResult; + if (expectingRotateAsClickedSurface) { + if (!SelectionManager.hasSelection() || !SelectionManager.hasUnlockedSelection()) { + audioFeedback.rejection(); + Window.notifyEditError("You have nothing selected, or the selection is locked."); + expectingRotateAsClickedSurface = false; + } else { + //Rotate Selection according the Surface Normal + selectionDisplay.rotateSelection(Quat.lookAt(Vec3.ZERO, Vec3.multiply(entityResult.surfaceNormal, -1), Vec3.UP)); + selectionManager._update(false, this); + pushCommandForSelections(); + expectingRotateAsClickedSurface = false; + audioFeedback.action(); + } + keepSelectedOnNextClick = true; + return null; } else { - return null; - } + if (iconResult.intersects) { + result = iconResult; + } else if (entityResult.intersects) { + result = entityResult; + } else { + return null; + } - if (!result.accurate) { - return null; - } + if (!result.accurate) { + return null; + } - var foundEntity = result.entityID; - return { - pickRay: pickRay, - entityID: foundEntity, - intersection: result.intersection - }; + var foundEntity = result.entityID; + return { + pickRay: pickRay, + entityID: foundEntity, + intersection: result.intersection + }; + } } // Handles selections on overlays while in edit mode by querying entities from @@ -1295,7 +1313,10 @@ function mouseClickEvent(event) { if (result === null || result === undefined) { if (!event.isShifted) { - selectionManager.clearSelections(this); + if (!keepSelectedOnNextClick) { + selectionManager.clearSelections(this); + } + keepSelectedOnNextClick = false; } return; } @@ -2052,6 +2073,26 @@ function gridToAvatarKey(value) { alignGridToAvatar(); } } +function rotateAsNextClickedSurfaceKey(value) { + if (value === 0) { // on release + rotateAsNextClickedSurface(); + } +} +function quickRotate90xKey(value) { + if (value === 0) { // on release + selectionDisplay.rotate90degreeSelection("X"); + } +} +function quickRotate90yKey(value) { + if (value === 0) { // on release + selectionDisplay.rotate90degreeSelection("Y"); + } +} +function quickRotate90zKey(value) { + if (value === 0) { // on release + selectionDisplay.rotate90degreeSelection("Z"); + } +} function recursiveAdd(newParentID, parentData) { if (parentData.children !== undefined) { var children = parentData.children; @@ -2819,6 +2860,10 @@ mapping.from([Controller.Hardware.Keyboard.J]).to(gridKey); mapping.from([Controller.Hardware.Keyboard.G]).to(viewGridKey); mapping.from([Controller.Hardware.Keyboard.H]).to(snapKey); mapping.from([Controller.Hardware.Keyboard.K]).to(gridToAvatarKey); +mapping.from([Controller.Hardware.Keyboard["0"]]).to(rotateAsNextClickedSurfaceKey); +mapping.from([Controller.Hardware.Keyboard["7"]]).to(quickRotate90xKey); +mapping.from([Controller.Hardware.Keyboard["8"]]).to(quickRotate90yKey); +mapping.from([Controller.Hardware.Keyboard["9"]]).to(quickRotate90zKey); mapping.from([Controller.Hardware.Keyboard.X]) .when([Controller.Hardware.Keyboard.Control]) .to(whenReleased(function() { selectionManager.cutSelectedEntities() })); @@ -2867,6 +2912,14 @@ keyUpEventFromUIWindow = function(keyUpEvent) { snapKey(pressedValue); } else if (keyUpEvent.keyCodeString === "K") { gridToAvatarKey(pressedValue); + } else if (keyUpEvent.keyCodeString === "0") { + rotateAsNextClickedSurfaceKey(pressedValue); + } else if (keyUpEvent.keyCodeString === "7") { + quickRotate90xKey(pressedValue); + } else if (keyUpEvent.keyCodeString === "8") { + quickRotate90yKey(pressedValue); + } else if (keyUpEvent.keyCodeString === "9") { + quickRotate90zKey(pressedValue); } else if (keyUpEvent.controlKey && keyUpEvent.keyCodeString === "X") { selectionManager.cutSelectedEntities(); } else if (keyUpEvent.controlKey && keyUpEvent.keyCodeString === "C") { @@ -3015,4 +3068,14 @@ function toggleGridVisibility() { } } +function rotateAsNextClickedSurface() { + if (!SelectionManager.hasSelection() || !SelectionManager.hasUnlockedSelection()) { + audioFeedback.rejection(); + Window.notifyEditError("You have nothing selected, or the selection is locked."); + expectingRotateAsClickedSurface = false; + } else { + expectingRotateAsClickedSurface = true; + } +} + }()); // END LOCAL_SCOPE diff --git a/scripts/system/create/entitySelectionTool/entitySelectionTool.js b/scripts/system/create/entitySelectionTool/entitySelectionTool.js index f9a30ef6a5..8941ff24f2 100644 --- a/scripts/system/create/entitySelectionTool/entitySelectionTool.js +++ b/scripts/system/create/entitySelectionTool/entitySelectionTool.js @@ -103,10 +103,25 @@ SelectionManager = (function() { if (wantDebug) { print("setting selection to " + messageParsed.entityID); } - if (hmdMultiSelectMode) { - that.addEntity(messageParsed.entityID, true, that); + if (expectingRotateAsClickedSurface) { + if (!SelectionManager.hasSelection() || !SelectionManager.hasUnlockedSelection()) { + audioFeedback.rejection(); + Window.notifyEditError("You have nothing selected, or the selection is locked."); + expectingRotateAsClickedSurface = false; + } else { + //Rotate Selection according the Surface Normal + selectionDisplay.rotateSelection(Quat.lookAt(Vec3.ZERO, Vec3.multiply(messageParsed.surfaceNormal, -1), Vec3.UP)); + that._update(false, this); + pushCommandForSelections(); + expectingRotateAsClickedSurface = false; + audioFeedback.action(); + } } else { - that.setSelections([messageParsed.entityID], that); + if (hmdMultiSelectMode) { + that.addEntity(messageParsed.entityID, true, that); + } else { + that.setSelections([messageParsed.entityID], that); + } } } } else if (messageParsed.method === "clearSelection") { @@ -2377,7 +2392,48 @@ SelectionDisplay = (function() { } debugPickPlaneHits = []; }; - + + that.rotateSelection = function(rotation) { + SelectionManager.saveProperties(); + if (SelectionManager.selections.length === 1) { + SelectionManager.savedProperties[SelectionManager.selections[0]].rotation = Quat.IDENTITY; + } + updateSelectionsRotation(rotation, SelectionManager.worldPosition); + }; + + that.rotate90degreeSelection = function(axis) { + //axis is a string and expect "X", "Y" or "Z" + if (!SelectionManager.hasSelection() || !SelectionManager.hasUnlockedSelection()) { + audioFeedback.rejection(); + Window.notifyEditError("You have nothing selected, or the selection is locked."); + } else { + var currentRotation, axisRotation; + SelectionManager.saveProperties(); + if (selectionManager.selections.length === 1 && spaceMode === SPACE_LOCAL) { + currentRotation = SelectionManager.localRotation; + }else{ + currentRotation = SelectionManager.worldRotation; + } + switch(axis) { + case "X": + axisRotation = Quat.angleAxis(90.0, Quat.getRight(currentRotation)); + break; + case "Y": + axisRotation = Quat.angleAxis(90.0, Quat.getUp(currentRotation)); + break; + case "Z": + axisRotation = Quat.angleAxis(90.0, Quat.getForward(currentRotation)); + break; + default: + return; + } + updateSelectionsRotation(axisRotation, SelectionManager.worldPosition); + SelectionManager._update(false, this); + pushCommandForSelections(); + audioFeedback.action(); + } + }; + function addUnlitMaterialOnToolEntity(toolEntityParentID) { var toolEntitiesMaterialData = "{\n \"materialVersion\": 1,\n \"materials\": [\n {\n \"name\": \"0\",\n \"defaultFallthrough\": true,\n \"unlit\": true,\n \"model\": \"hifi_pbr\"\n }\n ]\n}"; var materialEntityID = Entities.addEntity({