From ddd9a031ad3d761bbb6ba96c2cc112307249777b Mon Sep 17 00:00:00 2001 From: Martin Gerhardy Date: Sat, 2 Apr 2022 20:49:57 +0200 Subject: [PATCH] VOXEDIT: allow to edit the interpolation type in a keyframe #136 --- .../modules/voxedit-ui/PositionsPanel.cpp | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/tools/voxedit/modules/voxedit-ui/PositionsPanel.cpp b/src/tools/voxedit/modules/voxedit-ui/PositionsPanel.cpp index 4c96caf54..da66364e8 100644 --- a/src/tools/voxedit/modules/voxedit-ui/PositionsPanel.cpp +++ b/src/tools/voxedit/modules/voxedit-ui/PositionsPanel.cpp @@ -9,6 +9,8 @@ #include "voxedit-util/Config.h" #include "voxedit-util/SceneManager.h" #include "voxelformat/SceneGraph.h" +#include "voxelformat/SceneGraphNode.h" +#include "core/ArrayLength.h" #include @@ -140,7 +142,9 @@ void PositionsPanel::sceneView(command::CommandExecutionListener &listener) { if (activeNode != -1) { voxelformat::SceneGraphNode &node = sceneGraph.node(activeNode); const uint32_t frame = sceneMgr().currentFrame(); - voxelformat::SceneGraphTransform &transform = node.transform(node.keyFrameForFrame(frame)); + const uint32_t keyFrame = node.keyFrameForFrame(frame); + voxelformat::SceneGraphKeyFrame &sceneGraphKeyFrame = node.keyFrame(keyFrame); + voxelformat::SceneGraphTransform &transform = sceneGraphKeyFrame.transform; float matrixTranslation[3], matrixRotation[3], matrixScale[3]; ImGuizmo::DecomposeMatrixToComponents(glm::value_ptr(transform.matrix()), matrixTranslation, matrixRotation, matrixScale); @@ -150,6 +154,26 @@ void PositionsPanel::sceneView(command::CommandExecutionListener &listener) { change |= ImGui::InputFloat3("Rt", matrixRotation); change |= ImGui::InputFloat3("Sc", matrixScale); change |= ImGui::InputFloat3("Pv", glm::value_ptr(pivot)); + + static const char *interpolationStrings[] = {"Instant", "Linear", "QuadEaseIn", + "QuadEaseOut", "QuadEaseInOut", "CubicEaseIn", + "CubicEaseOut", "CubicEaseInOut"}; + static_assert((int)voxelformat::InterpolationType::Max == lengthof(interpolationStrings), "Array sizes don't match"); + + const int currentInterpolation = (int)sceneGraphKeyFrame.interpolation; + if (ImGui::BeginCombo("Interpolation##interpolationstrings", interpolationStrings[currentInterpolation])) { + for (int n = 0; n < lengthof(interpolationStrings); n++) { + const bool isSelected = (currentInterpolation == n); + if (ImGui::Selectable(interpolationStrings[n], isSelected)) { + sceneGraphKeyFrame.interpolation = (voxelformat::InterpolationType)n; + } + if (isSelected) { + ImGui::SetItemDefaultFocus(); + } + } + ImGui::EndCombo(); + } + if (change) { glm::mat4 matrix; ImGuizmo::RecomposeMatrixFromComponents(matrixTranslation, matrixRotation, matrixScale,