From aedce21007e68cf8812161f04d8b903d58dd002e Mon Sep 17 00:00:00 2001 From: Alezia Kurdis <60075796+AleziaKurdis@users.noreply.github.com> Date: Wed, 20 Jan 2021 23:17:06 -0500 Subject: [PATCH] Snap to Next Clicked Surface This adds the move in addition to the rotation to the "Rotate as Next Clicked Surface" action. Which is now become: "Snap to Next Clicked Surface" --- scripts/system/create/edit.js | 11 ++++++- .../entitySelectionTool.js | 31 ++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/scripts/system/create/edit.js b/scripts/system/create/edit.js index 23292cd85c..05bc7d2381 100644 --- a/scripts/system/create/edit.js +++ b/scripts/system/create/edit.js @@ -1115,7 +1115,16 @@ function findClickedEntity(event) { expectingRotateAsClickedSurface = false; } else { //Rotate Selection according the Surface Normal - selectionDisplay.rotateSelection(Quat.lookAt(Vec3.ZERO, Vec3.multiply(entityResult.surfaceNormal, -1), Vec3.UP)); + var normalRotation = Quat.lookAtSimple(Vec3.ZERO, Vec3.multiply(entityResult.surfaceNormal, -1)); + selectionDisplay.rotateSelection(normalRotation); + //Translate Selection according the clicked Surface + var distanceFromSurface; + if (selectionDisplay.getSpaceMode() === "world"){ + distanceFromSurface = SelectionManager.worldDimensions.z / 2; + } else { + distanceFromSurface = SelectionManager.localDimensions.z / 2; + } + selectionDisplay.moveSelection(Vec3.sum(entityResult.intersection, Vec3.multiplyQbyV( normalRotation, {"x": 0.0, "y":0.0, "z": distanceFromSurface}))); selectionManager._update(false, this); pushCommandForSelections(); expectingRotateAsClickedSurface = false; diff --git a/scripts/system/create/entitySelectionTool/entitySelectionTool.js b/scripts/system/create/entitySelectionTool/entitySelectionTool.js index b1ce7f801c..f4d6117bd1 100644 --- a/scripts/system/create/entitySelectionTool/entitySelectionTool.js +++ b/scripts/system/create/entitySelectionTool/entitySelectionTool.js @@ -110,7 +110,16 @@ SelectionManager = (function() { expectingRotateAsClickedSurface = false; } else { //Rotate Selection according the Surface Normal - selectionDisplay.rotateSelection(Quat.lookAt(Vec3.ZERO, Vec3.multiply(messageParsed.surfaceNormal, -1), Vec3.UP)); + var normalRotation = Quat.lookAtSimple(Vec3.ZERO, Vec3.multiply(messageParsed.surfaceNormal, -1)); + selectionDisplay.rotateSelection(normalRotation); + //Translate Selection according the clicked Surface + var distanceFromSurface; + if (selectionDisplay.getSpaceMode() === SPACE_WORLD){ + distanceFromSurface = SelectionManager.worldDimensions.z / 2; + } else { + distanceFromSurface = SelectionManager.localDimensions.z / 2; + } + selectionDisplay.moveSelection(Vec3.sum(messageParsed.intersection, Vec3.multiplyQbyV( normalRotation, {"x": 0.0, "y":0.0, "z": distanceFromSurface}))); that._update(false, this); pushCommandForSelections(); expectingRotateAsClickedSurface = false; @@ -2401,6 +2410,26 @@ SelectionDisplay = (function() { updateSelectionsRotation(rotation, SelectionManager.worldPosition); }; + that.moveSelection = function(targetPosition) { + SelectionManager.saveProperties(); + // editing a parent will cause all the children to automatically follow along, so don't + // edit any entity who has an ancestor in SelectionManager.selections + var toMove = SelectionManager.selections.filter(function (selection) { + if (SelectionManager.selections.indexOf(SelectionManager.savedProperties[selection].parentID) >= 0) { + return false; // a parent is also being moved, so don't issue an edit for this entity + } else { + return true; + } + }); + + for (var i = 0; i < toMove.length; i++) { + var id = toMove[i]; + var properties = SelectionManager.savedProperties[id]; + var newPosition = Vec3.sum(targetPosition, Vec3.subtract(properties.position, SelectionManager.worldPosition)); + Entities.editEntity(id, { position: newPosition }); + } + }; + that.rotate90degreeSelection = function(axis) { //axis is a string and expect "X", "Y" or "Z" if (!SelectionManager.hasSelection() || !SelectionManager.hasUnlockedSelection()) {