Started thedmd/imgui-node-editor integration
This commit is contained in:
+128
-5
@@ -22,6 +22,7 @@
|
||||
#include "SkinnedMesh.h"
|
||||
#include "SkinnedMeshResource.h"
|
||||
#include "src/AnimGraph/AnimGraphEditor.h"
|
||||
#include "3rdparty/imgui-node-editor/imgui_node_editor.h"
|
||||
|
||||
const int Width = 1024;
|
||||
const int Height = 768;
|
||||
@@ -172,13 +173,22 @@ struct ApplicationConfig {
|
||||
int window_position[2] = {100, 30};
|
||||
int window_size[2] = {1000, 600};
|
||||
|
||||
struct GraphEditor {
|
||||
struct LegacyGraphEditor {
|
||||
bool visible = false;
|
||||
int position[2] = {20, 20};
|
||||
int size[2] = {800, 500};
|
||||
};
|
||||
GraphEditor graph_editor;
|
||||
LegacyGraphEditor legacy_graph_editor;
|
||||
|
||||
struct GraphEditor {
|
||||
bool visible = false;
|
||||
int position[2] = {20, 20};
|
||||
int size[2] = {800, 500};
|
||||
ax::NodeEditor::Config config = {};
|
||||
ax::NodeEditor::EditorContext* context = nullptr;
|
||||
};
|
||||
GraphEditor graph_editor;
|
||||
|
||||
struct SkinnedMeshWidget {
|
||||
bool visible = false;
|
||||
int position[2] = {20, 20};
|
||||
@@ -215,12 +225,18 @@ void to_json(nlohmann::json& j, const ApplicationConfig& config) {
|
||||
j["main_window"]["size"][0] = config.window_size[0];
|
||||
j["main_window"]["size"][1] = config.window_size[1];
|
||||
|
||||
j["legacy_graph_editor"]["visible"] = config.legacy_graph_editor.visible;
|
||||
j["legacy_graph_editor"]["position"][0] = config.legacy_graph_editor.position[0];
|
||||
j["legacy_graph_editor"]["position"][1] = config.legacy_graph_editor.position[1];
|
||||
j["legacy_graph_editor"]["size"][0] = config.legacy_graph_editor.size[0];
|
||||
j["legacy_graph_editor"]["size"][1] = config.legacy_graph_editor.size[1];
|
||||
|
||||
j["graph_editor"]["visible"] = config.graph_editor.visible;
|
||||
j["graph_editor"]["position"][0] = config.graph_editor.position[0];
|
||||
j["graph_editor"]["position"][1] = config.graph_editor.position[1];
|
||||
j["graph_editor"]["size"][0] = config.graph_editor.size[0];
|
||||
j["graph_editor"]["size"][1] = config.graph_editor.size[1];
|
||||
|
||||
|
||||
j["skinned_mesh_widget"]["visible"] = config.skinned_mesh_widget.visible;
|
||||
j["skinned_mesh_widget"]["position"][0] =
|
||||
config.skinned_mesh_widget.position[0];
|
||||
@@ -266,11 +282,29 @@ void from_json(const nlohmann::json& j, ApplicationConfig& config) {
|
||||
}
|
||||
}
|
||||
|
||||
if (j.contains("legacy_graph_editor")) {
|
||||
if (j["legacy_graph_editor"].contains("visible")) {
|
||||
config.legacy_graph_editor.visible = j["legacy_graph_editor"]["visible"];
|
||||
}
|
||||
|
||||
if (j["legacy_graph_editor"].contains("position")
|
||||
and j["legacy_graph_editor"]["position"].size() == 2) {
|
||||
config.legacy_graph_editor.position[0] = j["legacy_graph_editor"]["position"].at(0);
|
||||
config.legacy_graph_editor.position[1] = j["legacy_graph_editor"]["position"].at(1);
|
||||
}
|
||||
|
||||
if (j["legacy_graph_editor"].contains("size")
|
||||
and j["legacy_graph_editor"]["size"].size() == 2) {
|
||||
config.legacy_graph_editor.size[0] = j["legacy_graph_editor"]["size"].at(0);
|
||||
config.legacy_graph_editor.size[1] = j["legacy_graph_editor"]["size"].at(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (j.contains("graph_editor")) {
|
||||
if (j["graph_editor"].contains("visible")) {
|
||||
config.graph_editor.visible = j["graph_editor"]["visible"];
|
||||
}
|
||||
|
||||
|
||||
if (j["graph_editor"].contains("position")
|
||||
and j["graph_editor"]["position"].size() == 2) {
|
||||
config.graph_editor.position[0] = j["graph_editor"]["position"].at(0);
|
||||
@@ -283,7 +317,7 @@ void from_json(const nlohmann::json& j, ApplicationConfig& config) {
|
||||
config.graph_editor.size[1] = j["graph_editor"]["size"].at(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (j.contains("skinned_mesh_widget")) {
|
||||
if (j["skinned_mesh_widget"].contains("visible")) {
|
||||
config.skinned_mesh_widget.visible = j["skinned_mesh_widget"]["visible"];
|
||||
@@ -636,6 +670,10 @@ int main() {
|
||||
|
||||
Viewport offscreen_viewport;
|
||||
|
||||
// Graph Editor
|
||||
gApplicationConfig.graph_editor.config.SettingsFile = "graph_editor.json";
|
||||
gApplicationConfig.graph_editor.context = ax::NodeEditor::CreateEditor(&gApplicationConfig.graph_editor.config);
|
||||
|
||||
// draw loop
|
||||
while (!glfwWindowShouldClose(w)) {
|
||||
// Update time
|
||||
@@ -762,6 +800,10 @@ int main() {
|
||||
&gApplicationConfig.animation_player_widget.visible);
|
||||
|
||||
ImGui::Separator();
|
||||
ImGui::Checkbox(
|
||||
"Legacy Graph Editor",
|
||||
&gApplicationConfig.legacy_graph_editor.visible);
|
||||
|
||||
ImGui::Checkbox(
|
||||
"ImGui Demo",
|
||||
&gApplicationConfig.show_imgui_demo_window);
|
||||
@@ -1031,6 +1073,86 @@ int main() {
|
||||
gApplicationConfig.graph_editor.size[0] = graph_editor_size.x;
|
||||
gApplicationConfig.graph_editor.size[1] = graph_editor_size.y;
|
||||
|
||||
ax::NodeEditor::SetCurrentEditor(gApplicationConfig.graph_editor.context);
|
||||
ax::NodeEditor::Begin("Graph Editor");
|
||||
|
||||
int unique_id = 1;
|
||||
ax::NodeEditor::BeginNode(unique_id++);
|
||||
|
||||
// Node A
|
||||
ImGui::Text("Node A");
|
||||
ax::NodeEditor::BeginPin(unique_id++, ax::NodeEditor::PinKind::Input);
|
||||
ImGui::Text("In");
|
||||
ax::NodeEditor::EndPin();
|
||||
ImGui::SameLine();
|
||||
ax::NodeEditor::BeginPin(unique_id++, ax::NodeEditor::PinKind::Output);
|
||||
ImGui::Text("Out");
|
||||
ax::NodeEditor::EndPin();
|
||||
|
||||
ax::NodeEditor::EndNode();
|
||||
|
||||
// Node B
|
||||
ax::NodeEditor::BeginNode(unique_id++);
|
||||
|
||||
ImGui::Text("Node B");
|
||||
ax::NodeEditor::BeginPin(unique_id++, ax::NodeEditor::PinKind::Input);
|
||||
ImGui::Text("In");
|
||||
ax::NodeEditor::EndPin();
|
||||
ImGui::SameLine();
|
||||
ax::NodeEditor::BeginPin(unique_id++, ax::NodeEditor::PinKind::Output);
|
||||
ImGui::Text("Out");
|
||||
ax::NodeEditor::EndPin();
|
||||
|
||||
ax::NodeEditor::EndNode();
|
||||
|
||||
// Create Connections
|
||||
if (ax::NodeEditor::BeginCreate()) {
|
||||
ax::NodeEditor::PinId input_pin_id, output_pin_id;
|
||||
if (ax::NodeEditor::QueryNewLink(&input_pin_id, &output_pin_id)) {
|
||||
if (input_pin_id && output_pin_id) {
|
||||
if (ax::NodeEditor::AcceptNewItem()) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ax::NodeEditor::EndCreate();
|
||||
|
||||
ax::NodeEditor::End();
|
||||
|
||||
ax::NodeEditor::SetCurrentEditor(nullptr);
|
||||
|
||||
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
// Legacy Animation Graph Editor
|
||||
if (gApplicationConfig.legacy_graph_editor.visible) {
|
||||
ImGui::SetNextWindowPos(
|
||||
ImVec2(
|
||||
gApplicationConfig.legacy_graph_editor.position[0],
|
||||
gApplicationConfig.legacy_graph_editor.position[1]),
|
||||
ImGuiCond_FirstUseEver);
|
||||
ImGui::SetNextWindowSize(
|
||||
ImVec2(
|
||||
gApplicationConfig.legacy_graph_editor.size[0],
|
||||
gApplicationConfig.legacy_graph_editor.size[1]),
|
||||
ImGuiCond_FirstUseEver);
|
||||
|
||||
ImGui::Begin(
|
||||
"Legacy Graph Editor",
|
||||
&gApplicationConfig.legacy_graph_editor.visible,
|
||||
ImGuiWindowFlags_MenuBar);
|
||||
|
||||
ImVec2 graph_editor_position = ImGui::GetWindowPos();
|
||||
gApplicationConfig.legacy_graph_editor.position[0] = graph_editor_position.x;
|
||||
gApplicationConfig.legacy_graph_editor.position[1] = graph_editor_position.y;
|
||||
|
||||
ImVec2 graph_editor_size = ImGui::GetWindowSize();
|
||||
gApplicationConfig.legacy_graph_editor.size[0] = graph_editor_size.x;
|
||||
gApplicationConfig.legacy_graph_editor.size[1] = graph_editor_size.y;
|
||||
|
||||
AnimGraphEditorUpdate();
|
||||
|
||||
ImGui::End();
|
||||
@@ -1065,6 +1187,7 @@ int main() {
|
||||
save_application_config("animtestbed_config.json");
|
||||
|
||||
/* cleanup */
|
||||
ax::NodeEditor::DestroyEditor(gApplicationConfig.graph_editor.context);
|
||||
ImNodes::DestroyContext();
|
||||
ImGui::DestroyContext();
|
||||
sgl_shutdown();
|
||||
|
||||
Reference in New Issue
Block a user