From ab011d5b30409aca9c0ab52dcd1a65f08ad16d0a Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 3 Dec 2014 16:49:49 -0800 Subject: [PATCH 1/9] fix for non-animating models --- libraries/entities/src/ModelEntityItem.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 63fe3daa03..0de2035dec 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -374,17 +374,9 @@ bool ModelEntityItem::isAnimatingSomething() const { } EntityItem::SimulationState ModelEntityItem::computeSimulationState() const { - EntityItem::SimulationState baseClassState = EntityItem::computeSimulationState(); - - // if the base class is static, then consider our animation state, and upgrade to changing if - // we are animating. If the base class has a higher simulation state than static, then - // use the base class state. - if (baseClassState == EntityItem::Static) { - if (isAnimatingSomething()) { - return EntityItem::Moving; - } - } - return baseClassState; + // if we're animating then we need to have update() periodically called on this entity + // which means we need to categorized as Moving + return isAnimatingSomething() ? EntityItem::Moving : EntityItem::computeSimulationState(); } void ModelEntityItem::update(const quint64& updateTime) { From 74acf9513bd8863f825b14291217ba2c1eee1562 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 4 Dec 2014 08:47:18 -0800 Subject: [PATCH 2/9] Fix entity tool selection when inactive --- examples/newEditEntities.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/newEditEntities.js b/examples/newEditEntities.js index 92db9daab5..a95c542311 100644 --- a/examples/newEditEntities.js +++ b/examples/newEditEntities.js @@ -566,6 +566,10 @@ function mouseReleaseEvent(event) { } function mouseClickEvent(event) { + if (!isActive) { + return; + } + var result = findClickedEntity(event); if (result === null) { if (!event.isShifted) { From f48d304df02f21ae7e2bd0d56cd7e45512dc2f16 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 4 Dec 2014 10:03:54 -0800 Subject: [PATCH 3/9] Add registrationPoint to SelectionManager --- examples/libraries/entitySelectionTool.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/libraries/entitySelectionTool.js b/examples/libraries/entitySelectionTool.js index 40b5b78a31..0622e4c72c 100644 --- a/examples/libraries/entitySelectionTool.js +++ b/examples/libraries/entitySelectionTool.js @@ -33,10 +33,12 @@ SelectionManager = (function() { that.localRotation = Quat.fromPitchYawRollDegrees(0, 0, 0); that.localPosition = { x: 0, y: 0, z: 0 }; that.localDimensions = { x: 0, y: 0, z: 0 }; + that.localRegistrationPoint = { x: 0.5, y: 0.5, z: 0.5 }; that.worldRotation = Quat.fromPitchYawRollDegrees(0, 0, 0); that.worldPosition = { x: 0, y: 0, z: 0 }; that.worldDimensions = { x: 0, y: 0, z: 0 }; + that.worldRegistrationPoint = { x: 0.5, y: 0.5, z: 0.5 }; that.centerPosition = { x: 0, y: 0, z: 0 }; that.saveProperties = function() { @@ -153,6 +155,7 @@ SelectionManager = (function() { that.localDimensions = properties.dimensions; that.localPosition = properties.position; that.localRotation = properties.rotation; + that.localRegistrationPoint = properties.registrationPoint; that.worldDimensions = properties.boundingBox.dimensions; that.worldPosition = properties.boundingBox.center; From 53f195eec413c54edb01ca3afb2e6b0c39bf924a Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 4 Dec 2014 10:05:34 -0800 Subject: [PATCH 4/9] Fix position of overlays when registrationPoint is not centered --- examples/libraries/entitySelectionTool.js | 81 +++++++++++++++-------- 1 file changed, 53 insertions(+), 28 deletions(-) diff --git a/examples/libraries/entitySelectionTool.js b/examples/libraries/entitySelectionTool.js index 0622e4c72c..3e50bff8f7 100644 --- a/examples/libraries/entitySelectionTool.js +++ b/examples/libraries/entitySelectionTool.js @@ -985,26 +985,40 @@ SelectionDisplay = (function () { that.updateRotationHandles(); that.highlightSelectable(); - var rotation, dimensions, position; + var rotation, dimensions, position, registrationPoint; if (spaceMode == SPACE_LOCAL) { rotation = SelectionManager.localRotation; dimensions = SelectionManager.localDimensions; position = SelectionManager.localPosition; + registrationPoint = SelectionManager.localRegistrationPoint; } else { rotation = Quat.fromPitchYawRollDegrees(0, 0, 0); dimensions = SelectionManager.worldDimensions; position = SelectionManager.worldPosition; + registrationPoint = SelectionManager.worldRegistrationPoint; } - var halfDimensions = Vec3.multiply(0.5, dimensions); + var registrationPointDimensions = { + x: dimensions.x * registrationPoint.x, + y: dimensions.y * registrationPoint.y, + z: dimensions.z * registrationPoint.z, + }; - var left = -halfDimensions.x; - var right = halfDimensions.x; - var top = halfDimensions.y; - var bottom = -halfDimensions.y; - var front = far = halfDimensions.z; - var near = -halfDimensions.z; + // Center of entity, relative to registration point + var center = { + x: dimensions.x / 2 - registrationPointDimensions.x, + y: dimensions.y / 2 - registrationPointDimensions.y, + z: dimensions.z / 2 - registrationPointDimensions.z, + }; + + // Distances in world coordinates relative to the registration point + var left = -registrationPointDimensions.x; + var right = dimensions.x - registrationPointDimensions.x; + var bottom = -registrationPointDimensions.y; + var top = dimensions.y - registrationPointDimensions.y; + var near = -registrationPointDimensions.z; + var front = far = dimensions.z - registrationPointDimensions.z; var worldTop = SelectionManager.worldDimensions.y / 2; @@ -1017,25 +1031,25 @@ SelectionDisplay = (function () { var LTF = { x: left, y: top, z: far }; var RTF = { x: right, y: top, z: far }; - var TOP = { x: 0, y: top, z: 0 }; - var BOTTOM = { x: 0, y: bottom, z: 0 }; - var LEFT = { x: left, y: 0, z: 0 }; - var RIGHT = { x: right, y: 0, z: 0 }; - var NEAR = { x: 0, y: 0, z: near }; - var FAR = { x: 0, y: 0, z: far }; + var TOP = { x: center.x, y: top, z: center.z }; + var BOTTOM = { x: center.x, y: bottom, z: center.z }; + var LEFT = { x: left, y: center.y, z: center.z }; + var RIGHT = { x: right, y: center.y, z: center.z }; + var NEAR = { x: center.x, y: center.y, z: near }; + var FAR = { x: center.x, y: center.y, z: far }; - var EdgeTR = { x: right, y: top, z: 0 }; - var EdgeTL = { x: left, y: top, z: 0 }; - var EdgeTF = { x: 0, y: top, z: front }; - var EdgeTN = { x: 0, y: top, z: near }; - var EdgeBR = { x: right, y: bottom, z: 0 }; - var EdgeBL = { x: left, y: bottom, z: 0 }; - var EdgeBF = { x: 0, y: bottom, z: front }; - var EdgeBN = { x: 0, y: bottom, z: near }; - var EdgeNR = { x: right, y: 0, z: near }; - var EdgeNL = { x: left, y: 0, z: near }; - var EdgeFR = { x: right, y: 0, z: front }; - var EdgeFL = { x: left, y: 0, z: front }; + var EdgeTR = { x: right, y: top, z: center.z }; + var EdgeTL = { x: left, y: top, z: center.z }; + var EdgeTF = { x: center.x, y: top, z: front }; + var EdgeTN = { x: center.x, y: top, z: near }; + var EdgeBR = { x: right, y: bottom, z: center.z }; + var EdgeBL = { x: left, y: bottom, z: center.z }; + var EdgeBF = { x: center.x, y: bottom, z: front }; + var EdgeBN = { x: center.x, y: bottom, z: near }; + var EdgeNR = { x: right, y: center.y, z: near }; + var EdgeNL = { x: left, y: center.y, z: near }; + var EdgeFR = { x: right, y: center.y, z: front }; + var EdgeFL = { x: left, y: center.y, z: front }; LBN = Vec3.multiplyQbyV(rotation, LBN); RBN = Vec3.multiplyQbyV(rotation, RBN); @@ -1114,8 +1128,10 @@ SelectionDisplay = (function () { Overlays.editOverlay(grabberNEAR, { visible: extendedStretchHandlesVisible, rotation: rotation, position: NEAR }); Overlays.editOverlay(grabberFAR, { visible: extendedStretchHandlesVisible, rotation: rotation, position: FAR }); + var boxPosition = Vec3.multiplyQbyV(rotation, center); + boxPosition = Vec3.sum(position, boxPosition); Overlays.editOverlay(selectionBox, { - position: position, + position: boxPosition, dimensions: dimensions, rotation: rotation, visible: !(mode == "ROTATE_YAW" || mode == "ROTATE_PITCH" || mode == "ROTATE_ROLL"), @@ -1143,8 +1159,17 @@ SelectionDisplay = (function () { if (selectionManager.selections.length > 1) { for (; i < selectionManager.selections.length; i++) { var properties = Entities.getEntityProperties(selectionManager.selections[i]); + + // Adjust overlay position to take registrationPoint into account + // centeredRP = registrationPoint with range [-0.5, 0.5] + var centeredRP = Vec3.subtract(properties.registrationPoint, { x: 0.5, y: 0.5, z: 0.5 }); + var offset = vec3Mult(properties.dimensions, centeredRP); + offset = Vec3.multiply(-1, offset); + offset = Vec3.multiplyQbyV(properties.rotation, offset); + var boxPosition = Vec3.sum(properties.position, offset); + Overlays.editOverlay(selectionBoxes[i], { - position: properties.position, + position: boxPosition, rotation: properties.rotation, dimensions: properties.dimensions, visible: true, From efdc8f54948f2a031b4b77d607dcfa104b7266d9 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 4 Dec 2014 10:19:51 -0800 Subject: [PATCH 5/9] Fix stretch tools to work correctly with registrationPoint --- examples/libraries/entitySelectionTool.js | 43 ++++++++++++++--------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/examples/libraries/entitySelectionTool.js b/examples/libraries/entitySelectionTool.js index 3e50bff8f7..16dc52b239 100644 --- a/examples/libraries/entitySelectionTool.js +++ b/examples/libraries/entitySelectionTool.js @@ -1428,6 +1428,8 @@ SelectionDisplay = (function () { var initialDimensions = null; var initialIntersection = null; var initialProperties = null; + var registrationPoint = null; + var deltaPivot = null; var pickRayPosition = null; var rotation = null; @@ -1440,18 +1442,29 @@ SelectionDisplay = (function () { rotation = SelectionManager.localRotation; initialPosition = SelectionManager.localPosition; initialDimensions = SelectionManager.localDimensions; + registrationPoint = SelectionManager.localRegistrationPoint; } else { rotation = SelectionManager.worldRotation; initialPosition = SelectionManager.worldPosition; initialDimensions = SelectionManager.worldDimensions; + registrationPoint = SelectionManager.worldRegistrationPoint; } - var scaledOffset = { - x: initialDimensions.x * offset.x * 0.5, - y: initialDimensions.y * offset.y * 0.5, - z: initialDimensions.z * offset.z * 0.5, - }; - pickRayPosition = Vec3.sum(initialPosition, Vec3.multiplyQbyV(rotation, scaledOffset)); + // Modify range of registrationPoint to be [-0.5, 0.5] + var centeredRP = Vec3.subtract(registrationPoint, { x: 0.5, y: 0.5, z: 0.5 }); + + // Scale pivot to be in the same range as registrationPoint + var scaledPivot = Vec3.multiply(0.5, pivot) + deltaPivot = Vec3.subtract(centeredRP, scaledPivot); + + var scaledOffset = Vec3.multiply(0.5, offset); + + // Offset from the registration point + offsetRP = Vec3.subtract(scaledOffset, centeredRP); + + // Scaled offset in world coordinates + var scaledOffsetWorld = vec3Mult(initialDimensions, offsetRP); + pickRayPosition = Vec3.sum(initialPosition, Vec3.multiplyQbyV(rotation, scaledOffsetWorld)); if (numDimensions == 1 && mask.x) { var start = Vec3.multiplyQbyV(rotation, { x: -10000, y: 0, z: 0 }); @@ -1578,8 +1591,7 @@ SelectionDisplay = (function () { newDimensions.y = Math.max(newDimensions.y, MINIMUM_DIMENSION); newDimensions.z = Math.max(newDimensions.z, MINIMUM_DIMENSION); - var p = Vec3.multiply(0.5, pivot); - var changeInPosition = Vec3.multiplyQbyV(rotation, vec3Mult(p, changeInDimensions)); + var changeInPosition = Vec3.multiplyQbyV(rotation, vec3Mult(deltaPivot, changeInDimensions)); var newPosition = Vec3.sum(initialPosition, changeInPosition); for (var i = 0; i < SelectionManager.selections.length; i++) { @@ -1617,20 +1629,19 @@ SelectionDisplay = (function () { function addStretchTool(overlay, mode, pivot, direction, offset) { if (!pivot) { - pivot = Vec3.multiply(-1, direction); - pivot.y = direction.y; + pivot = direction; } var tool = makeStretchTool(mode, direction, pivot, offset); addGrabberTool(overlay, tool); } - addStretchTool(grabberNEAR, "STRETCH_NEAR", { x: 0, y: 0, z: -1 }, { x: 0, y: 0, z: 1 }, { x: 0, y: 0, z: -1 }); - addStretchTool(grabberFAR, "STRETCH_FAR", { x: 0, y: 0, z: 1 }, { x: 0, y: 0, z: -1 }, { x: 0, y: 0, z: 1 }); - addStretchTool(grabberTOP, "STRETCH_TOP", { x: 0, y: 1, z: 0 }, { x: 0, y: -1, z: 0 }, { x: 0, y: 1, z: 0 }); - addStretchTool(grabberBOTTOM, "STRETCH_BOTTOM", { x: 0, y: -1, z: 0 }, { x: 0, y: 1, z: 0 }, { x: 0, y: -1, z: 0 }); - addStretchTool(grabberRIGHT, "STRETCH_RIGHT", { x: 1, y: 0, z: 0 }, { x: -1, y: 0, z: 0 }, { x: 1, y: 0, z: 0 }); - addStretchTool(grabberLEFT, "STRETCH_LEFT", { x: -1, y: 0, z: 0 }, { x: 1, y: 0, z: 0 }, { x: -1, y: 0, z: 0 }); + addStretchTool(grabberNEAR, "STRETCH_NEAR", { x: 0, y: 0, z: 1 }, { x: 0, y: 0, z: 1 }, { x: 0, y: 0, z: -1 }); + addStretchTool(grabberFAR, "STRETCH_FAR", { x: 0, y: 0, z: -1 }, { x: 0, y: 0, z: -1 }, { x: 0, y: 0, z: 1 }); + addStretchTool(grabberTOP, "STRETCH_TOP", { x: 0, y: -1, z: 0 }, { x: 0, y: -1, z: 0 }, { x: 0, y: 1, z: 0 }); + addStretchTool(grabberBOTTOM, "STRETCH_BOTTOM", { x: 0, y: 1, z: 0 }, { x: 0, y: 1, z: 0 }, { x: 0, y: -1, z: 0 }); + addStretchTool(grabberRIGHT, "STRETCH_RIGHT", { x: -1, y: 0, z: 0 }, { x: -1, y: 0, z: 0 }, { x: 1, y: 0, z: 0 }); + addStretchTool(grabberLEFT, "STRETCH_LEFT", { x: 1, y: 0, z: 0 }, { x: 1, y: 0, z: 0 }, { x: -1, y: 0, z: 0 }); addStretchTool(grabberLBN, "STRETCH_LBN", null, {x: 1, y: 0, z: 1}, { x: -1, y: -1, z: -1 }); addStretchTool(grabberRBN, "STRETCH_RBN", null, {x: -1, y: 0, z: 1}, { x: 1, y: -1, z: -1 }); From b2c5b19fd7228f569a4e86db585b335acee1c8bf Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 4 Dec 2014 10:20:02 -0800 Subject: [PATCH 6/9] Remove print --- examples/libraries/gridTool.js | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/libraries/gridTool.js b/examples/libraries/gridTool.js index aa412b1a76..7d98befec8 100644 --- a/examples/libraries/gridTool.js +++ b/examples/libraries/gridTool.js @@ -90,7 +90,6 @@ Grid = function(opts) { } that.snapToSpacing = function(delta, majorOnly) { - print('snaptogrid? ' + snapToGrid); if (!snapToGrid) { return delta; } From acd5495b2ab4a2ef33eb62312d27cff351a36a3a Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 4 Dec 2014 10:29:10 -0800 Subject: [PATCH 7/9] Add getRelativeCenterPosition --- examples/libraries/entitySelectionTool.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/libraries/entitySelectionTool.js b/examples/libraries/entitySelectionTool.js index 16dc52b239..e30b9d2d95 100644 --- a/examples/libraries/entitySelectionTool.js +++ b/examples/libraries/entitySelectionTool.js @@ -218,6 +218,17 @@ function normalizeDegrees(degrees) { return degrees; } +// Return the enter position of an entity relative to it's registrationPoint +// A registration point of (0.5, 0.5, 0.5) will have an offset of (0, 0, 0) +// A registration point of (1.0, 1.0, 1.0) will have an offset of (-dimensions.x / 2, -dimensions.y / 2, -dimensions.z / 2) +function getRelativeCenterPosition(dimensions, registrationPoint) { + return { + x: -dimensions.x * (registrationPoint.x - 0.5), + y: -dimensions.y * (registrationPoint.y - 0.5), + z: -dimensions.z * (registrationPoint.z - 0.5), + } +} + SelectionDisplay = (function () { var that = {}; @@ -1005,12 +1016,7 @@ SelectionDisplay = (function () { z: dimensions.z * registrationPoint.z, }; - // Center of entity, relative to registration point - var center = { - x: dimensions.x / 2 - registrationPointDimensions.x, - y: dimensions.y / 2 - registrationPointDimensions.y, - z: dimensions.z / 2 - registrationPointDimensions.z, - }; + center = getRelativeCenterPosition(position, dimensions, registrationPoint); // Distances in world coordinates relative to the registration point var left = -registrationPointDimensions.x; From 1f82831bcc0ea6a01d4ea7d2748f173173557d6f Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 4 Dec 2014 10:47:09 -0800 Subject: [PATCH 8/9] Fix call to getRelativeCenterPosition --- examples/libraries/entitySelectionTool.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/libraries/entitySelectionTool.js b/examples/libraries/entitySelectionTool.js index e30b9d2d95..2953203fc6 100644 --- a/examples/libraries/entitySelectionTool.js +++ b/examples/libraries/entitySelectionTool.js @@ -1016,7 +1016,8 @@ SelectionDisplay = (function () { z: dimensions.z * registrationPoint.z, }; - center = getRelativeCenterPosition(position, dimensions, registrationPoint); + // Center of entity, relative to registration point + center = getRelativeCenterPosition(dimensions, registrationPoint); // Distances in world coordinates relative to the registration point var left = -registrationPointDimensions.x; From 1ee45e8bd1f5bdb26745eff045eff1f19c7de035 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 4 Dec 2014 11:24:56 -0800 Subject: [PATCH 9/9] Fix entity tool rotation to rotate around registration point --- examples/libraries/entitySelectionTool.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/examples/libraries/entitySelectionTool.js b/examples/libraries/entitySelectionTool.js index 2953203fc6..fa97e9351f 100644 --- a/examples/libraries/entitySelectionTool.js +++ b/examples/libraries/entitySelectionTool.js @@ -1786,17 +1786,27 @@ SelectionDisplay = (function () { } var yawChange = Quat.fromVec3Degrees({ x: 0, y: angleFromZero, z: 0 }); + + // Entities should only reposition if we are rotating multiple selections around + // the selections center point. Otherwise, the rotation will be around the entities + // registration point which does not need repositioning. + var reposition = SelectionManager.selections.length > 1; for (var i = 0; i < SelectionManager.selections.length; i++) { var entityID = SelectionManager.selections[i]; var properties = Entities.getEntityProperties(entityID); var initialProperties = SelectionManager.savedProperties[entityID.id]; - var dPos = Vec3.subtract(initialProperties.position, initialPosition); - dPos = Vec3.multiplyQbyV(yawChange, dPos); - Entities.editEntity(entityID, { - position: Vec3.sum(initialPosition, dPos), + var newProperties = { rotation: Quat.multiply(yawChange, initialProperties.rotation), - }); + }; + + if (reposition) { + var dPos = Vec3.subtract(initialProperties.position, initialPosition); + dPos = Vec3.multiplyQbyV(yawChange, dPos); + newProperties.position = Vec3.sum(initialPosition, dPos); + } + + Entities.editEntity(entityID, newProperties); } updateRotationDegreesOverlay(angleFromZero, yawHandleRotation, yawCenter);