diff --git a/data/voxedit/skeleton.vengi b/data/voxedit/skeleton.vengi index c29ae5b07b..e1a33ad10c 100644 Binary files a/data/voxedit/skeleton.vengi and b/data/voxedit/skeleton.vengi differ diff --git a/src/tools/voxedit/modules/voxedit-ui/Viewport.cpp b/src/tools/voxedit/modules/voxedit-ui/Viewport.cpp index 4e65427ce3..a5e56fe20e 100644 --- a/src/tools/voxedit/modules/voxedit-ui/Viewport.cpp +++ b/src/tools/voxedit/modules/voxedit-ui/Viewport.cpp @@ -521,13 +521,13 @@ void Viewport::lock(const scenegraph::SceneGraphNode &node, scenegraph::KeyFrame } void Viewport::handleGizmo(const scenegraph::SceneGraphNode &node, scenegraph::KeyFrameIndex keyFrameIdx, - const glm::mat4 &localMatrix) { + const glm::mat4 &worldMatrix) { if (ImGuizmo::IsUsing()) { lock(node, keyFrameIdx); glm::vec3 translate; glm::vec3 rotation; glm::vec3 scale; - ImGuizmo::DecomposeMatrixToComponents(glm::value_ptr(localMatrix), glm::value_ptr(translate), + ImGuizmo::DecomposeMatrixToComponents(glm::value_ptr(worldMatrix), glm::value_ptr(translate), glm::value_ptr(rotation), glm::value_ptr(scale)); if (glm::all(glm::greaterThan(scale, glm::vec3(0)))) { _bounds.maxs = _boundsNode.maxs * scale; @@ -565,7 +565,7 @@ bool Viewport::renderSceneAndModelGizmo(const video::Camera &camera) { const glm::vec3 size = region.getDimensionsInVoxels(); const scenegraph::KeyFrameIndex keyFrameIdx = node.keyFrameForFrame(sceneMgr().currentFrame()); - glm::mat4 localMatrix(1.0f); + glm::mat4 worldMatrix(1.0f); int operation = ImGuizmo::TRANSLATE; bool bounds = false; if (sceneMode) { @@ -575,7 +575,7 @@ bool Viewport::renderSceneAndModelGizmo(const video::Camera &camera) { } const scenegraph::SceneGraphTransform &transform = node.transform(keyFrameIdx); const glm::vec3 mins = -node.pivot() * size; - localMatrix = transform.localMatrix(); + worldMatrix = transform.worldMatrix(); if (glm::any(glm::epsilonNotEqual(mins, _bounds.mins, glm::epsilon()))) { _bounds.mins = mins; _bounds.maxs = mins + size; @@ -586,21 +586,21 @@ bool Viewport::renderSceneAndModelGizmo(const video::Camera &camera) { return false; } - bool shiftRegionBoundaries = true; // TODO: make this an option + bool shiftRegionBoundaries = false; // TODO: make this an option if (shiftRegionBoundaries) { const glm::vec3 &shift = region.getLowerCornerf(); - localMatrix = glm::translate(localMatrix, shift); + worldMatrix = glm::translate(worldMatrix, shift); } const bool manipulated = ImGuizmo::Manipulate( glm::value_ptr(camera.viewMatrix()), glm::value_ptr(camera.projectionMatrix()), (ImGuizmo::OPERATION)operation, - ImGuizmo::MODE::LOCAL, glm::value_ptr(localMatrix), glm::value_ptr(deltaMatrix), + ImGuizmo::MODE::WORLD, glm::value_ptr(worldMatrix), glm::value_ptr(deltaMatrix), _gizmoSnap->boolVal() ? snap : nullptr, bounds ? glm::value_ptr(_bounds.mins) : nullptr, boundsSnap); if (sceneMode) { if (shiftRegionBoundaries) { const glm::vec3 &shift = region.getLowerCornerf(); - localMatrix = glm::translate(localMatrix, -shift); + worldMatrix = glm::translate(worldMatrix, -shift); } - handleGizmo(node, keyFrameIdx, localMatrix); + handleGizmo(node, keyFrameIdx, worldMatrix); if (!_gizmoActivated && node.isModelNode() && ImGui::IsKeyPressed(ImGuiKey_LeftShift) && ImGui::IsKeyPressed(ImGuiKey_MouseLeft)) { @@ -612,11 +612,11 @@ bool Viewport::renderSceneAndModelGizmo(const video::Camera &camera) { } } if (manipulated) { - sceneMgr().nodeUpdateTransform(activeNode, localMatrix, &deltaMatrix, keyFrameIdx); + sceneMgr().nodeUpdateTransform(activeNode, worldMatrix, &deltaMatrix, keyFrameIdx, false); } _gizmoActivated = ImGuizmo::IsUsingAny(); } else { - handleGizmo(node, InvalidKeyFrame, localMatrix); + handleGizmo(node, InvalidKeyFrame, worldMatrix); _gizmoActivated = ImGuizmo::IsUsingAny(); if (manipulated) { sceneMgr().shift(activeNode, deltaMatrix[3]); diff --git a/src/tools/voxedit/modules/voxedit-util/SceneManager.cpp b/src/tools/voxedit/modules/voxedit-util/SceneManager.cpp index 25ff9dd210..eda6f26af3 100644 --- a/src/tools/voxedit/modules/voxedit-util/SceneManager.cpp +++ b/src/tools/voxedit/modules/voxedit-util/SceneManager.cpp @@ -2696,18 +2696,18 @@ bool SceneManager::mouseRayTrace(bool force) { return true; } -bool SceneManager::nodeUpdateTransform(int nodeId, const glm::mat4 &localMatrix, const glm::mat4 *deltaMatrix, - scenegraph::KeyFrameIndex keyFrameIdx) { +bool SceneManager::nodeUpdateTransform(int nodeId, const glm::mat4 &matrix, const glm::mat4 *deltaMatrix, + scenegraph::KeyFrameIndex keyFrameIdx, bool local) { if (nodeId == InvalidNodeId) { nodeForeachGroup([&] (int nodeId) { if (scenegraph::SceneGraphNode *node = sceneGraphNode(nodeId)) { - nodeUpdateTransform(*node, localMatrix, deltaMatrix, keyFrameIdx); + nodeUpdateTransform(*node, matrix, deltaMatrix, keyFrameIdx, local); } }); return true; } if (scenegraph::SceneGraphNode *node = sceneGraphNode(nodeId)) { - return nodeUpdateTransform(*node, localMatrix, deltaMatrix, keyFrameIdx); + return nodeUpdateTransform(*node, matrix, deltaMatrix, keyFrameIdx, local); } return false; } @@ -2784,19 +2784,15 @@ bool SceneManager::nodeRemoveKeyFrameByIndex(scenegraph::SceneGraphNode &node, s return false; } -bool SceneManager::nodeUpdateTransform(scenegraph::SceneGraphNode &node, const glm::mat4 &localMatrix, - const glm::mat4 *deltaMatrix, scenegraph::KeyFrameIndex keyFrameIdx) { - glm::vec3 translation; - glm::quat orientation; - glm::vec3 scale; - glm::vec3 skew; - glm::vec4 perspective; +bool SceneManager::nodeUpdateTransform(scenegraph::SceneGraphNode &node, const glm::mat4 &matrix, + const glm::mat4 *deltaMatrix, scenegraph::KeyFrameIndex keyFrameIdx, bool local) { scenegraph::SceneGraphKeyFrame &keyFrame = node.keyFrame(keyFrameIdx); scenegraph::SceneGraphTransform &transform = keyFrame.transform(); - glm::decompose(localMatrix, scale, orientation, translation, skew, perspective); - transform.setLocalTranslation(translation); - transform.setLocalOrientation(orientation); - transform.setLocalScale(scale); + if (local) { + transform.setLocalMatrix(matrix); + } else { + transform.setWorldMatrix(matrix); + } transform.update(_sceneGraph, node, keyFrame.frameIdx, _transformUpdateChildren->boolVal()); _mementoHandler.markNodeTransform(node, keyFrameIdx); diff --git a/src/tools/voxedit/modules/voxedit-util/SceneManager.h b/src/tools/voxedit/modules/voxedit-util/SceneManager.h index 3fb296a225..c85129e01f 100644 --- a/src/tools/voxedit/modules/voxedit-util/SceneManager.h +++ b/src/tools/voxedit/modules/voxedit-util/SceneManager.h @@ -406,8 +406,8 @@ class SceneManager : public core::IComponent { void onNewNodeAdded(int newNodeId, bool isChildren = false); bool nodeRename(scenegraph::SceneGraphNode &node, const core::String &name); bool nodeRemove(scenegraph::SceneGraphNode &node, bool recursive); - bool nodeUpdateTransform(scenegraph::SceneGraphNode &node, const glm::mat4 &localMatrix, - const glm::mat4 *deltaMatrix, scenegraph::KeyFrameIndex keyFrameIdx); + bool nodeUpdateTransform(scenegraph::SceneGraphNode &node, const glm::mat4 &matrix, + const glm::mat4 *deltaMatrix, scenegraph::KeyFrameIndex keyFrameIdx, bool local); bool nodeRemoveKeyFrameByIndex(scenegraph::SceneGraphNode &node, scenegraph::KeyFrameIndex keyFrameIdx); bool nodeRemoveKeyFrame(scenegraph::SceneGraphNode &node, scenegraph::FrameIndex frameIdx); bool nodeAddKeyframe(scenegraph::SceneGraphNode &node, scenegraph::FrameIndex frameIdx); @@ -416,8 +416,8 @@ class SceneManager : public core::IComponent { bool nodeUnreference(scenegraph::SceneGraphNode &node); public: - bool nodeUpdateTransform(int nodeId, const glm::mat4 &localMatrix, const glm::mat4 *deltaMatrix, - scenegraph::KeyFrameIndex keyFrameIdx); + bool nodeUpdateTransform(int nodeId, const glm::mat4 &matrix, const glm::mat4 *deltaMatrix, + scenegraph::KeyFrameIndex keyFrameIdx, bool local); bool nodeRemoveKeyFrameByIndex(int nodeId, scenegraph::KeyFrameIndex keyFrameIdx); int nodeReference(int nodeId); bool nodeRemoveKeyFrame(int nodeId, scenegraph::FrameIndex frameIdx);