Compare commits

...

5 Commits

Author SHA1 Message Date
Martin Gerhardy b879def00a UI: applied coding guidelines 2022-05-26 17:36:41 +02:00
Martin Gerhardy 384df5885b UI: removed vector interface 2022-05-26 17:15:03 +02:00
Martin Gerhardy a44c21ce84 VOXEDIT: show the view matrix manipulator in edit mode, too 2022-05-26 09:58:47 +02:00
Martin Gerhardy 004509d77f MAKE: fixed update-imguizmo target 2022-05-24 21:11:20 +02:00
Martin Gerhardy 8cee533420 VOXELFORMAT: helper method to access the parent MeshExt structure 2022-05-24 21:02:36 +02:00
9 changed files with 704 additions and 749 deletions

View File

@ -116,7 +116,6 @@ update-backward:
update-imguizmo:
$(call UPDATE_GIT,imguizmo,https://github.com/CedricGuillemet/ImGuizmo.git)
cp $(UPDATEDIR)/imguizmo.sync/ImGuizmo.* src/modules/ui/imgui/dearimgui
dos2unix src/modules/ui/imgui/dearimgui/ImSeq*
dos2unix src/modules/ui/imgui/dearimgui/ImGuizmo*
update-im-neo-sequencer:

View File

@ -2669,6 +2669,13 @@ namespace IMGUIZMO_NAMESPACE
}
}
void ViewManipulate(float* view, const float* projection, OPERATION operation, MODE mode, float* matrix, float length, ImVec2 position, ImVec2 size, ImU32 backgroundColor)
{
// Scale is always local or matrix will be skewed when applying world scale or oriented matrix
ComputeContext(view, projection, matrix, (operation & SCALE) ? LOCAL : mode);
ViewManipulate(view, length, position, size, backgroundColor);
}
void ViewManipulate(float* view, float length, ImVec2 position, ImVec2 size, ImU32 backgroundColor)
{
static bool isDraging = false;

View File

@ -210,6 +210,9 @@ namespace IMGUIZMO_NAMESPACE
//
IMGUI_API void ViewManipulate(float* view, float length, ImVec2 position, ImVec2 size, ImU32 backgroundColor);
// use this version if you did not call Manipulate before and you are just using ViewManipulate
IMGUI_API void ViewManipulate(float* view, const float* projection, OPERATION operation, MODE mode, float* matrix, float length, ImVec2 position, ImVec2 size, ImU32 backgroundColor);
IMGUI_API void SetID(int id);
// return true if the cursor is over the operation's gizmo

File diff suppressed because it is too large Load Diff

View File

@ -2,100 +2,93 @@
// Created by Matty on 2022-01-28.
//
#ifndef IMGUI_NEO_SEQUENCER_H
#define IMGUI_NEO_SEQUENCER_H
#pragma once
#include "imgui.h"
#include <vector>
typedef int ImGuiNeoSequencerFlags;
typedef int ImGuiNeoSequencerCol;
typedef int ImGuiNeoTimelineFlags;
// Flags for ImGui::BeginNeoSequencer()
enum ImGuiNeoSequencerFlags_
{
ImGuiNeoSequencerFlags_None = 0 ,
ImGuiNeoSequencerFlags_AllowLengthChanging = 1 << 0,
ImGuiNeoSequencerFlags_AllowSelection = 1 << 1,
ImGuiNeoSequencerFlags_HideZoom = 1 << 2,
ImGuiNeoSequencerFlags_ZoomBottomOverlay = 1 << 3,
enum ImGuiNeoSequencerFlags_ {
ImGuiNeoSequencerFlags_None = 0,
ImGuiNeoSequencerFlags_AllowLengthChanging = 1 << 0,
ImGuiNeoSequencerFlags_AllowSelection = 1 << 1,
ImGuiNeoSequencerFlags_HideZoom = 1 << 2,
ImGuiNeoSequencerFlags_ZoomBottomOverlay = 1 << 3,
};
// Flags for ImGui::BeginNeoTimeline()
enum ImGuiNeoTimelineFlags_
{
ImGuiNeoTimelineFlags_None = 0 ,
ImGuiNeoTimelineFlags_AllowFrameChanging = 1 << 0,
ImGuiNeoTimelineFlags_Group = 1 << 1,
enum ImGuiNeoTimelineFlags_ {
ImGuiNeoTimelineFlags_None = 0,
ImGuiNeoTimelineFlags_AllowFrameChanging = 1 << 0,
ImGuiNeoTimelineFlags_Group = 1 << 1,
};
enum ImGuiNeoSequencerCol_
{
ImGuiNeoSequencerCol_Bg,
ImGuiNeoSequencerCol_TopBarBg,
ImGuiNeoSequencerCol_SelectedTimeline,
ImGuiNeoSequencerCol_TimelineBorder,
ImGuiNeoSequencerCol_TimelinesBg,
ImGuiNeoSequencerCol_FramePointer,
ImGuiNeoSequencerCol_FramePointerHovered,
ImGuiNeoSequencerCol_FramePointerPressed,
ImGuiNeoSequencerCol_Keyframe,
ImGuiNeoSequencerCol_KeyframeHovered,
ImGuiNeoSequencerCol_KeyframePressed,
ImGuiNeoSequencerCol_FramePointerLine,
enum ImGuiNeoSequencerCol_ {
ImGuiNeoSequencerCol_Bg,
ImGuiNeoSequencerCol_TopBarBg,
ImGuiNeoSequencerCol_SelectedTimeline,
ImGuiNeoSequencerCol_TimelineBorder,
ImGuiNeoSequencerCol_TimelinesBg,
ImGuiNeoSequencerCol_FramePointer,
ImGuiNeoSequencerCol_FramePointerHovered,
ImGuiNeoSequencerCol_FramePointerPressed,
ImGuiNeoSequencerCol_Keyframe,
ImGuiNeoSequencerCol_KeyframeHovered,
ImGuiNeoSequencerCol_KeyframePressed,
ImGuiNeoSequencerCol_FramePointerLine,
ImGuiNeoSequencerCol_ZoomBarBg,
ImGuiNeoSequencerCol_ZoomBarSlider,
ImGuiNeoSequencerCol_ZoomBarSliderHovered,
ImGuiNeoSequencerCol_ZoomBarSliderEnds,
ImGuiNeoSequencerCol_ZoomBarSliderEndsHovered,
ImGuiNeoSequencerCol_COUNT
ImGuiNeoSequencerCol_ZoomBarBg,
ImGuiNeoSequencerCol_ZoomBarSlider,
ImGuiNeoSequencerCol_ZoomBarSliderHovered,
ImGuiNeoSequencerCol_ZoomBarSliderEnds,
ImGuiNeoSequencerCol_ZoomBarSliderEndsHovered,
ImGuiNeoSequencerCol_COUNT
};
struct ImGuiNeoSequencerStyle {
float SequencerRounding = 2.5f; // Corner rounding around whole sequencer
float TopBarHeight = 0.0f; // Value <= 0.0f = Height is calculated by FontSize + FramePadding.y * 2.0f
bool TopBarShowFrameLines = true; // Show line for every frame in top bar
bool TopBarShowFrameTexts = true; // Show frame number every 10th frame
ImVec2 ItemSpacing = {4.0f,0.5f};
float DepthItemSpacing = 10.0f; // Amount of text offset per depth level in timeline values
float TopBarSpacing = 3.0f; // Space between top bar and timeline
float TimelineBorderSize = 1.0f;
float CurrentFramePointerSize = 7.0f; // Size of pointing arrow above current frame line
float CurrentFrameLineWidth = 1.0f; // Width of line showing current frame over timeline
float ZoomHeightScale = 1.0f; // Scale of Zoom bar, base height is font size
float SequencerRounding = 2.5f; // Corner rounding around whole sequencer
float TopBarHeight = 0.0f; // Value <= 0.0f = Height is calculated by FontSize + FramePadding.y * 2.0f
bool TopBarShowFrameLines = true; // Show line for every frame in top bar
bool TopBarShowFrameTexts = true; // Show frame number every 10th frame
ImVec2 ItemSpacing = {4.0f, 0.5f};
float DepthItemSpacing = 10.0f; // Amount of text offset per depth level in timeline values
float TopBarSpacing = 3.0f; // Space between top bar and timeline
float TimelineBorderSize = 1.0f;
float CurrentFramePointerSize = 7.0f; // Size of pointing arrow above current frame line
float CurrentFrameLineWidth = 1.0f; // Width of line showing current frame over timeline
float ZoomHeightScale = 1.0f; // Scale of Zoom bar, base height is font size
ImVec4 Colors[ImGuiNeoSequencerCol_COUNT];
ImVec4 Colors[ImGuiNeoSequencerCol_COUNT];
ImGuiNeoSequencerStyle();
ImGuiNeoSequencerStyle();
};
namespace ImGui {
IMGUI_API const ImVec4& GetStyleNeoSequencerColorVec4(ImGuiNeoSequencerCol idx);
IMGUI_API ImGuiNeoSequencerStyle& GetNeoSequencerStyle();
IMGUI_API void PushNeoSequencerStyleColor(ImGuiNeoSequencerCol idx, ImU32 col);
IMGUI_API void PushNeoSequencerStyleColor(ImGuiNeoSequencerCol idx, const ImVec4& col);
IMGUI_API void PopNeoSequencerStyleColor(int count = 1);
IMGUI_API const ImVec4 &GetStyleNeoSequencerColorVec4(ImGuiNeoSequencerCol idx);
IMGUI_API ImGuiNeoSequencerStyle &GetNeoSequencerStyle();
IMGUI_API bool BeginNeoSequencer(const char* id, uint32_t * frame, uint32_t * startFrame, uint32_t * endFrame,const ImVec2& size = ImVec2(0, 0),ImGuiNeoSequencerFlags flags = ImGuiNeoSequencerFlags_None);
IMGUI_API void EndNeoSequencer(); //Call only when BeginNeoSequencer() returns true!!
IMGUI_API void PushNeoSequencerStyleColor(ImGuiNeoSequencerCol idx, ImU32 col);
IMGUI_API void PushNeoSequencerStyleColor(ImGuiNeoSequencerCol idx, const ImVec4 &col);
IMGUI_API void PopNeoSequencerStyleColor(int count = 1);
IMGUI_API bool BeginNeoGroup(const char* label, bool* open = nullptr);
IMGUI_API void EndNeoGroup();
IMGUI_API bool BeginNeoSequencer(const char *id, uint32_t *frame, uint32_t *startFrame, uint32_t *endFrame,
const ImVec2 &size = ImVec2(0, 0),
ImGuiNeoSequencerFlags flags = ImGuiNeoSequencerFlags_None);
// Call only when BeginNeoSequencer() returns true!!
IMGUI_API void EndNeoSequencer();
IMGUI_API bool BeginNeoTimeline(const char* label,uint32_t ** keyframes, uint32_t keyframeCount, bool * open = nullptr, ImGuiNeoTimelineFlags flags = ImGuiNeoTimelineFlags_None);
IMGUI_API void EndNeoTimeLine(); //Call only when BeginNeoTimeline() returns true!!
IMGUI_API bool BeginNeoGroup(const char *label, bool *open = nullptr);
IMGUI_API void EndNeoGroup();
IMGUI_API bool NeoBeginCreateKeyframe(uint32_t * frame);
IMGUI_API bool BeginNeoTimeline(const char *label, uint32_t **keyframes, uint32_t keyframeCount, bool *open = nullptr,
ImGuiNeoTimelineFlags flags = ImGuiNeoTimelineFlags_None);
// Call only when BeginNeoTimeline() returns true!!
IMGUI_API void EndNeoTimeLine();
#ifdef __cplusplus
// C++ helper
IMGUI_API bool BeginNeoTimeline(const char* label,std::vector<uint32_t> & keyframes ,bool * open = nullptr);
#endif
}
IMGUI_API bool NeoBeginCreateKeyframe(uint32_t *frame);
#endif //IMGUI_NEO_SEQUENCER_H
} // namespace ImGui

View File

@ -25,6 +25,19 @@
namespace voxelformat {
MeshFormat::MeshExt* MeshFormat::getParent(const voxelformat::SceneGraph &sceneGraph, MeshFormat::Meshes &meshes, int nodeId) {
if (!sceneGraph.hasNode(nodeId)) {
return nullptr;
}
const int parent = sceneGraph.node(nodeId).parent();
for (MeshExt &me : meshes) {
if (me.nodeId == parent) {
return &me;
}
}
return nullptr;
}
glm::vec3 MeshFormat::getScale() {
const float scale = core::Var::getSafe(cfg::VoxformatScale)->floatVal();

View File

@ -31,6 +31,8 @@ protected:
const glm::vec3 &scale = glm::vec3(1.0f), bool quad = false, bool withColor = true,
bool withTexCoords = true) = 0;
static MeshExt* getParent(const voxelformat::SceneGraph &sceneGraph, Meshes &meshes, int nodeId);
static glm::vec3 getScale();
// checks if the winding needs flipping if the scale values are negative
static bool flipWinding(const glm::vec3 &scale);

View File

@ -6,8 +6,8 @@
#include "IconsForkAwesome.h"
#include "core/ArrayLength.h"
#include "core/collection/DynamicArray.h"
#include "ui/imgui/dearimgui/imgui_neo_sequencer.h"
#include "ui/imgui/dearimgui/imgui.h"
#include "ui/imgui/dearimgui/imgui_neo_sequencer.h"
#include "voxedit-util/SceneManager.h"
#include "voxelformat/SceneGraph.h"
#include "voxelformat/SceneGraphNode.h"
@ -22,15 +22,15 @@ void AnimationTimeline::update(const char *sequencerTitle, ImGuiID dockIdMainDow
ImGui::SetNextWindowDockID(dockIdMainDown, ImGuiCond_Appearing);
if (ImGui::Begin(sequencerTitle, nullptr, ImGuiWindowFlags_NoSavedSettings)) {
if (ImGui::Button(ICON_FA_PLUS_SQUARE " Add")) {
sceneMgr().nodeForeachGroup([&] (int nodeId) {
voxelformat::SceneGraphNode& node = sceneGraph.node(nodeId);
sceneMgr().nodeForeachGroup([&](int nodeId) {
voxelformat::SceneGraphNode &node = sceneGraph.node(nodeId);
node.addKeyFrame(currentFrame);
});
}
ImGui::SameLine();
if (ImGui::Button(ICON_FA_MINUS_SQUARE " Remove")) {
sceneMgr().nodeForeachGroup([&] (int nodeId) {
voxelformat::SceneGraphNode& node = sceneGraph.node(nodeId);
sceneMgr().nodeForeachGroup([&](int nodeId) {
voxelformat::SceneGraphNode &node = sceneGraph.node(nodeId);
node.removeKeyFrame(currentFrame);
});
}
@ -43,7 +43,10 @@ void AnimationTimeline::update(const char *sequencerTitle, ImGuiID dockIdMainDow
for (voxelformat::SceneGraphKeyFrame &kf : modelNode.keyFrames()) {
keys.push_back(&kf.frame);
}
if (ImGui::BeginNeoTimeline(modelNode.name().c_str(), keys.data(), keys.size(), nullptr)) {
const char *label = modelNode.name().c_str();
uint32_t **keyframes = keys.data();
const uint32_t keyframeCount = keys.size();
if (ImGui::BeginNeoTimeline(label, keyframes, keyframeCount, nullptr, ImGuiNeoTimelineFlags_None)) {
sceneMgr().setCurrentFrame(currentFrame);
ImGui::EndNeoTimeLine();
}

View File

@ -214,9 +214,6 @@ void Viewport::renderGizmo(video::Camera &camera, const float headerSize, const
return;
}
const EditMode editMode = sceneMgr().editMode();
if (editMode != EditMode::Scene) {
return;
}
ImGuiIO &io = ImGui::GetIO();
@ -251,26 +248,36 @@ void Viewport::renderGizmo(video::Camera &camera, const float headerSize, const
ImGuizmo::SetDrawlist();
ImGuizmo::SetRect(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y + headerSize, size.x, size.y);
ImGuizmo::SetOrthographic(camera.mode() == video::CameraMode::Orthogonal);
const float step = (float)core::Var::getSafe(cfg::VoxEditGridsize)->intVal();
const float snap[]{step, step, step};
const uint32_t keyFrame = node.keyFrameForFrame(sceneMgr().currentFrame());
const voxelformat::SceneGraphTransform &transform = node.transform(keyFrame);
glm::mat4 transformMatrix = transform.matrix();
glm::mat4 deltaMatrix(0.0f);
ImGuizmo::Manipulate(glm::value_ptr(camera.viewMatrix()), glm::value_ptr(camera.projectionMatrix()),
(ImGuizmo::OPERATION)operation, mode, glm::value_ptr(transformMatrix),
glm::value_ptr(deltaMatrix), _guizmoSnap->boolVal() ? snap : nullptr);
if (ImGuizmo::IsUsing()) {
_guizmoActivated = true;
sceneMgr().nodeUpdateTransform(-1, transformMatrix, &deltaMatrix, keyFrame, false);
} else if (_guizmoActivated) {
sceneMgr().nodeUpdateTransform(-1, transformMatrix, &deltaMatrix, keyFrame, true);
_guizmoActivated = false;
if (editMode == EditMode::Scene) {
const float step = (float)core::Var::getSafe(cfg::VoxEditGridsize)->intVal();
const float snap[]{step, step, step};
const uint32_t keyFrame = node.keyFrameForFrame(sceneMgr().currentFrame());
const voxelformat::SceneGraphTransform &transform = node.transform(keyFrame);
glm::mat4 transformMatrix = transform.matrix();
glm::mat4 deltaMatrix(0.0f);
ImGuizmo::Manipulate(glm::value_ptr(camera.viewMatrix()), glm::value_ptr(camera.projectionMatrix()),
(ImGuizmo::OPERATION)operation, mode, glm::value_ptr(transformMatrix),
glm::value_ptr(deltaMatrix), _guizmoSnap->boolVal() ? snap : nullptr);
if (editMode == EditMode::Scene) {
if (ImGuizmo::IsUsing()) {
_guizmoActivated = true;
sceneMgr().nodeUpdateTransform(-1, transformMatrix, &deltaMatrix, keyFrame, false);
} else if (_guizmoActivated) {
sceneMgr().nodeUpdateTransform(-1, transformMatrix, &deltaMatrix, keyFrame, true);
_guizmoActivated = false;
}
}
}
glm::mat4 viewMatrix = camera.viewMatrix();
ImGuizmo::ViewManipulate(glm::value_ptr(viewMatrix), camera.targetDistance(), ImGui::GetWindowPos(),
ImVec2(128, 128), 0);
if (editMode == EditMode::Scene) {
ImGuizmo::ViewManipulate(glm::value_ptr(viewMatrix), camera.targetDistance(), ImGui::GetWindowPos(),
ImVec2(128, 128), 0);
} else {
glm::mat4 transformMatrix = glm::mat4(1.0f); // not used
ImGuizmo::ViewManipulate(glm::value_ptr(viewMatrix), glm::value_ptr(camera.projectionMatrix()),
(ImGuizmo::OPERATION)operation, mode, glm::value_ptr(transformMatrix), camera.targetDistance(), ImGui::GetWindowPos(),
ImVec2(128, 128), 0);
}
if (viewMatrix != camera.viewMatrix()) {
glm::vec3 scale;
glm::vec3 translation;