diff --git a/scripts/system/create/entitySelectionTool/entitySelectionTool.js b/scripts/system/create/entitySelectionTool/entitySelectionTool.js index 0f8c8cc8bf..b4bf427a85 100644 --- a/scripts/system/create/entitySelectionTool/entitySelectionTool.js +++ b/scripts/system/create/entitySelectionTool/entitySelectionTool.js @@ -19,6 +19,7 @@ const SPACE_LOCAL = "local"; const SPACE_WORLD = "world"; const HIGHLIGHT_LIST_NAME = "editHandleHighlightList"; +const MIN_DISTANCE_TO_REZ_FROM_AVATAR = 3; Script.include([ "../../libraries/controllers.js", @@ -26,7 +27,6 @@ Script.include([ "../../libraries/utils.js" ]); - function deepCopy(v) { return JSON.parse(JSON.stringify(v)); } @@ -638,18 +638,19 @@ SelectionManager = (function() { that.teleportToEntity = function() { if (that.hasSelection()) { - var distanceFromTarget = 3 + Math.max(Math.max(that.worldDimensions.x, that.worldDimensions.y), that.worldDimensions.z); + var distanceFromTarget = MIN_DISTANCE_TO_REZ_FROM_AVATAR + Math.max(Math.max(that.worldDimensions.x, that.worldDimensions.y), that.worldDimensions.z); var teleportTargetPosition = Vec3.sum(that.worldPosition, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: distanceFromTarget })); MyAvatar.goToLocation(teleportTargetPosition, false); } else { audioFeedback.rejection(); + Window.notifyEditError("You have nothing selected."); } }; that.moveEntitiesSelectionToAvatar = function() { - if (that.hasSelection()) { + if (that.hasSelection() && that.hasUnlockedSelection()) { that.saveProperties(); - var distanceFromTarget = 3 + Math.max(Math.max(that.worldDimensions.x, that.worldDimensions.y), that.worldDimensions.z); + var distanceFromTarget = MIN_DISTANCE_TO_REZ_FROM_AVATAR + Math.max(Math.max(that.worldDimensions.x, that.worldDimensions.y), that.worldDimensions.z); var targetPosition = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -distanceFromTarget })); // editing a parent will cause all the children to automatically follow along, so don't // edit any entity who has an ancestor in that.selections @@ -670,9 +671,106 @@ SelectionManager = (function() { that._update(false, this); } else { audioFeedback.rejection(); + Window.notifyEditError("You have nothing selected or the selection has locked entities."); } }; + that.selectParent = function() { + if (that.hasSelection()) { + var currentSelection = that.selections; + that.selections = []; + for (var i = 0; i < currentSelection.length; i++) { + var properties = Entities.getEntityProperties(currentSelection[i], ['parentID']); + if (properties.parentID !== Uuid.NULL) { + that.selections.push(properties.parentID); + } + } + that._update(true, this); + } else { + audioFeedback.rejection(); + Window.notifyEditError("You have nothing selected."); + } + }; + + that.selectTopParent = function() { + if (that.hasSelection()) { + var currentSelection = that.selections; + that.selections = []; + for (var i = 0; i < currentSelection.length; i++) { + var topParentId = getTopParent(currentSelection[i]); + if (topParentId !== Uuid.NULL) { + that.selections.push(topParentId); + } + } + that._update(true, this); + } else { + audioFeedback.rejection(); + Window.notifyEditError("You have nothing selected."); + } + }; + + function getTopParent(id) { + var topParentId = Uuid.NULL; + var properties = Entities.getEntityProperties(id, ['parentID']); + if(properties.parentID === Uuid.NULL) { + topParentId = id; + } else { + topParentId = getTopParent(properties.parentID); + } + return topParentId; + } + + that.addChildrenToSelection = function() { + if (that.hasSelection()) { + for (var i = 0; i < that.selections.length; i++) { + var childrenIds = Entities.getChildrenIDs(that.selections[i]); + var collectNewChildren; + var j; + var k = 0; + do { + collectNewChildren = Entities.getChildrenIDs(childrenIds[k]); + if (collectNewChildren.length > 0) { + for (j = 0; j < collectNewChildren.length; j++) { + childrenIds.push(collectNewChildren[j]); + } + } + k++; + } while (k < childrenIds.length); + if (childrenIds.length > 0) { + for (j = 0; j < childrenIds.length; j++) { + that.selections.push(childrenIds[j]); + } + } + } + that._update(true, this); + } else { + audioFeedback.rejection(); + Window.notifyEditError("You have nothing selected."); + } + }; + + that.hasUnlockedSelection = function() { + var selectionNotLocked = true; + for (var i = 0; i < that.selections.length; i++) { + var properties = Entities.getEntityProperties(that.selections[i], ['locked']); + if (properties.locked) { + selectionNotLocked = false; + break; + } + } + return selectionNotLocked; + }; + + that.selectFamily = function() { + that.selectParent(); + that.addChildrenToSelection(); + }; + + that.selectTopFamily = function() { + that.selectTopParent(); + that.addChildrenToSelection(); + }; + return that; })(); @@ -698,8 +796,8 @@ SelectionDisplay = (function() { const COLOR_DUPLICATOR = { red: 162, green: 0, blue: 255 }; const COLOR_ROTATE_CURRENT_RING = { red: 255, green: 99, blue: 9 }; const COLOR_BOUNDING_EDGE = { red: 160, green: 160, blue: 160 }; - const COLOR_BOUNDING_EDGE_PARENT = { red: 194, green: 123, blue: 0 }; //{ red: 255, green: 160, blue: 0 }; - const COLOR_BOUNDING_EDGE_CHILDREN = { red: 0, green: 168, blue: 214 }; // { red: 0, green: 200, blue: 255 } + const COLOR_BOUNDING_EDGE_PARENT = { red: 194, green: 123, blue: 0 }; + const COLOR_BOUNDING_EDGE_CHILDREN = { red: 0, green: 168, blue: 214 }; const COLOR_SCALE_CUBE = { red: 192, green: 192, blue: 192 }; const COLOR_DEBUG_PICK_PLANE = { red: 255, green: 255, blue: 255 }; const COLOR_DEBUG_PICK_PLANE_HIT = { red: 255, green: 165, blue: 0 };