Added file dialog to graph editor.
This commit is contained in:
parent
6d9a6fca56
commit
0f9f9d6283
@ -28,6 +28,8 @@ set(ozz_build_simd_ref OFF CACHE BOOL "")
|
||||
set(ozz_build_msvc_rt_dll OFF CACHE BOOL "")
|
||||
add_subdirectory(3rdparty/ozz-animation)
|
||||
|
||||
add_subdirectory(3rdparty/nativefiledialog-extended)
|
||||
|
||||
set(ThirdPartyIncludeDeps
|
||||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/glfw/deps>
|
||||
@ -121,7 +123,16 @@ target_sources(AnimTestbed PRIVATE
|
||||
3rdparty/imgui/imgui_stacklayout_internal.h
|
||||
)
|
||||
|
||||
target_link_libraries(AnimTestbed AnimTestbedCode glfw ozz_base ozz_geometry ozz_animation ${OPENGL_LIBRARIES})
|
||||
target_link_libraries(AnimTestbed
|
||||
PUBLIC
|
||||
AnimTestbedCode
|
||||
glfw
|
||||
ozz_base
|
||||
ozz_geometry
|
||||
ozz_animation
|
||||
${OPENGL_LIBRARIES}
|
||||
PRIVATE
|
||||
nfd)
|
||||
|
||||
# Tests
|
||||
add_executable(runtests)
|
||||
|
7
README.md
Normal file
7
README.md
Normal file
@ -0,0 +1,7 @@
|
||||
# AnimTestbed
|
||||
|
||||
A yet to be named project that implements an animation engine based on hierarchical blend trees.
|
||||
|
||||
# Dependencies
|
||||
|
||||
apt-get install libgtk-3-dev libxapp-gtk3-module
|
@ -14,9 +14,11 @@
|
||||
#include "imgui.h"
|
||||
#include "imnodes.h"
|
||||
#include "misc/cpp/imgui_stdlib.h"
|
||||
#include "nfd.h"
|
||||
#include "src/AnimGraph/AnimGraphResource.h"
|
||||
|
||||
struct EditorState {
|
||||
std::string filename;
|
||||
AnimGraphResource* rootGraphResource = nullptr;
|
||||
|
||||
std::vector<AnimGraphResource*> hierarchyStack;
|
||||
@ -381,6 +383,7 @@ void AnimGraphEditorClear() {
|
||||
delete sEditorState.rootGraphResource;
|
||||
}
|
||||
|
||||
sEditorState.filename = "";
|
||||
sEditorState.rootGraphResource =
|
||||
dynamic_cast<AnimGraphResource*>(AnimNodeResourceFactory("BlendTree"));
|
||||
sEditorState.rootGraphResource->m_name = "Root";
|
||||
@ -452,22 +455,60 @@ void BlendTreeEditorNodePopup() {
|
||||
|
||||
void AnimGraphEditorMenuBar() {
|
||||
ImGui::BeginMenuBar();
|
||||
if (ImGui::Button("Save")) {
|
||||
sEditorState.rootGraphResource->SaveToFile("editor_graph.json");
|
||||
}
|
||||
if (ImGui::Button("Load")) {
|
||||
AnimGraphEditorClear();
|
||||
if (ImGui::BeginMenu("File")) {
|
||||
if (ImGui::MenuItem("New")) {
|
||||
AnimGraphEditorClear();
|
||||
}
|
||||
if (ImGui::MenuItem("Load ...", "Ctrl+L")) {
|
||||
nfdu8char_t* outPath;
|
||||
nfdu8filteritem_t filters[1] = {{"Json files", "json"}};
|
||||
nfdopendialogu8args_t args = {0};
|
||||
args.filterList = filters;
|
||||
args.filterCount = 1;
|
||||
args.defaultPath = ".";
|
||||
nfdresult_t result = NFD_OpenDialogU8_With(&outPath, &args);
|
||||
|
||||
delete sEditorState.rootGraphResource;
|
||||
if (result == NFD_OKAY) {
|
||||
AnimGraphEditorClear();
|
||||
delete sEditorState.rootGraphResource;
|
||||
|
||||
sEditorState.rootGraphResource =
|
||||
AnimGraphResource::CreateFromFile("editor_graph.json");
|
||||
sEditorState.filename = outPath;
|
||||
sEditorState.rootGraphResource =
|
||||
AnimGraphResource::CreateFromFile(sEditorState.filename.c_str());
|
||||
|
||||
AnimGraphEditorResetHierarchyStack();
|
||||
}
|
||||
if (ImGui::Button("Clear")) {
|
||||
AnimGraphEditorClear();
|
||||
AnimGraphEditorResetHierarchyStack();
|
||||
NFD_FreePathU8(outPath);
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem(
|
||||
"Save",
|
||||
"Ctrl+S",
|
||||
nullptr,
|
||||
!sEditorState.filename.empty())) {
|
||||
sEditorState.rootGraphResource->SaveToFile(sEditorState.filename.c_str());
|
||||
}
|
||||
if (ImGui::MenuItem("Save as ...")) {
|
||||
nfdu8char_t* outPath;
|
||||
nfdu8filteritem_t filters[1] = {{"Json files", "json"}};
|
||||
nfdsavedialogu8args_t args = {0};
|
||||
args.filterList = filters;
|
||||
args.filterCount = 1;
|
||||
args.defaultPath = ".";
|
||||
nfdresult_t result =
|
||||
NFD_SaveDialogU8(&outPath, args.filterList, 1, ".", "BlendTree.json");
|
||||
|
||||
if (result == NFD_OKAY) {
|
||||
sEditorState.filename = outPath;
|
||||
sEditorState.rootGraphResource->SaveToFile(
|
||||
sEditorState.filename.c_str());
|
||||
NFD_FreePathU8(outPath);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
if (ImGui::Button("Content")) {
|
||||
ax::NodeEditor::NavigateToContent();
|
||||
}
|
||||
@ -487,9 +528,11 @@ void AnimGraphEditorMenuBar() {
|
||||
}
|
||||
|
||||
void AnimGraphEditorBreadcrumbNavigation() {
|
||||
ImGui::Text("Navigation:");
|
||||
ImGui::SameLine();
|
||||
|
||||
for (size_t i = 0, n = sEditorState.hierarchyStack.size(); i < n; i++) {
|
||||
AnimGraphResource* graph_resource =
|
||||
dynamic_cast<AnimGraphResource*>(sEditorState.hierarchyStack[i]);
|
||||
AnimGraphResource* graph_resource = sEditorState.hierarchyStack[i];
|
||||
ImGui::PushID(graph_resource);
|
||||
|
||||
bool highlight_button = i == sEditorState.hierarchyStackIndex;
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include "3rdparty/imgui-node-editor/imgui_node_editor.h"
|
||||
#include "3rdparty/json/json.hpp"
|
||||
#include "3rdparty/nativefiledialog-extended/src/include/nfd.h"
|
||||
#include "AnimGraph/AnimGraphBlendTree.h"
|
||||
#include "AnimGraph/AnimGraphData.h"
|
||||
#include "AnimGraphEditor/AnimGraphEditor.h"
|
||||
@ -462,6 +463,8 @@ int main() {
|
||||
gApplicationConfig.window_size[1]);
|
||||
}
|
||||
|
||||
NFD_Init();
|
||||
|
||||
// setup sokol_gfx and sokol_time
|
||||
stm_setup();
|
||||
sg_desc desc = {
|
||||
@ -1065,6 +1068,9 @@ int main() {
|
||||
|
||||
sgl_shutdown();
|
||||
sg_shutdown();
|
||||
|
||||
NFD_Quit();
|
||||
|
||||
glfwTerminate();
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user