Files
UsdLayerManager/cmake/modules/FindImguiNodeEditor.cmake
T
indigo 038450a1ca Vendor node editor in-tree; add material presets; debug drag regression
Move the imgui-node-editor subset the build actually compiles from
third_party/imgui-node-editor to src/ui/NodeEditor (version-controlled,
MIT LICENSE included). FindImguiNodeEditor.cmake points at the new
location; CMakeLists excludes src/ui/NodeEditor from UI_SOURCES so it
isn't compiled twice.

Material editor presets: a Presets menu (disabled with no open material)
builds a UsdPreviewSurface + UsdUVTexture graph fed by an st primvar
reader, or a MaterialX standard_surface + image graph fed by a texcoord
node. Each is one idempotent, undoable command that re-normalizes layout.
Create Material becomes an icon button. New nodes route through
FindFreeCanvasSpot so a creation never lands on top of an existing node
(overlapping nodes fight over the editor hit test and become undraggable).

Shader-ball preview: pick a previewable output (terminal or 3/4-component
color-like) instead of always the first output, so scalar-only nodes keep
the whole-material preview rather than failing Storm codegen. Per-shape
camera frame-fit margins and auto-clip framing.

Fixes: DeletePrimCommand::Undo recreates missing destination ancestors
before SdfCopySpec (parent material may have been deleted after the
command ran). ConfigWindowsMoveFromTitleBarOnly stops a content-area drag
in the node canvas from moving the whole Material Editor window.

Temporary (marked for removal once the node-editor drag regression is
diagnosed): main.cpp mirrors LOG_INFO to %APPDATA%\UsdLayerManager\
debug.log; a g_AxNodeEditorDebugLog hook in the vendored editor plus a
[NodeGraph] event-trace block in RenderNodeGraphCanvas dump click/drag/
selection/position-save state.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-08 22:35:23 +08:00

87 lines
3.7 KiB
CMake

# FindImguiNodeEditor.cmake - Find or configure thedmd/imgui-node-editor
#
# This module looks for imgui-node-editor at src/ui/NodeEditor (an in-tree,
# version-controlled subset of the upstream library — MIT licensed, see
# src/ui/NodeEditor/LICENSE — containing only the files this project's build
# actually compiles; the full upstream drop, including the standalone example
# app used to reproduce library-level bugs against a pure reference build,
# stays vendored separately at third_party/imgui-node-editor) and compiles its
# sources directly against this project's own Imgui::Imgui target so it shares
# the exact same ImGui headers/defines (no second copy of ImGui is pulled in).
#
# Inputs:
# IMGUI_NODE_EDITOR_DIR - Path to imgui-node-editor/NodeEditor root
#
# Outputs:
# ImguiNodeEditor_FOUND
# ImguiNodeEditor::ImguiNodeEditor (imported STATIC target)
if(NOT IMGUI_NODE_EDITOR_DIR)
set(IMGUI_NODE_EDITOR_DIR "${CMAKE_SOURCE_DIR}/src/ui/NodeEditor")
endif()
if(NOT IMGUI_NODE_EDITOR_BLUEPRINT_UTILITIES_DIR)
set(IMGUI_NODE_EDITOR_BLUEPRINT_UTILITIES_DIR
"${CMAKE_SOURCE_DIR}/src/ui/NodeEditor/BlueprintWidgets")
endif()
find_path(ImguiNodeEditor_INCLUDE_DIR
NAMES imgui_node_editor.h
PATHS "${IMGUI_NODE_EDITOR_DIR}/Include"
NO_DEFAULT_PATH
)
set(ImguiNodeEditor_SOURCES
"${IMGUI_NODE_EDITOR_DIR}/Source/crude_json.cpp"
"${IMGUI_NODE_EDITOR_DIR}/Source/imgui_canvas.cpp"
"${IMGUI_NODE_EDITOR_DIR}/Source/imgui_node_editor_api.cpp"
"${IMGUI_NODE_EDITOR_DIR}/Source/imgui_node_editor.cpp"
# Blueprint pin-icon widgets (Widgets/Drawing only — Builders.cpp is
# intentionally excluded, it needs Spring()/BeginHorizontal()/BeginVertical()
# from thedmd's own ImGui fork, which this project's vanilla ImGui lacks).
"${IMGUI_NODE_EDITOR_BLUEPRINT_UTILITIES_DIR}/Source/ax/Drawing.cpp"
"${IMGUI_NODE_EDITOR_BLUEPRINT_UTILITIES_DIR}/Source/ax/Widgets.cpp"
)
foreach(_src ${ImguiNodeEditor_SOURCES})
if(NOT EXISTS "${_src}")
set(ImguiNodeEditor_SOURCES_MISSING TRUE)
endif()
endforeach()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(ImguiNodeEditor
REQUIRED_VARS ImguiNodeEditor_INCLUDE_DIR
FAIL_MESSAGE "imgui-node-editor not found — expected it at src/ui/NodeEditor"
)
if(ImguiNodeEditor_FOUND AND ImguiNodeEditor_SOURCES_MISSING)
message(FATAL_ERROR "imgui-node-editor sources missing under ${IMGUI_NODE_EDITOR_DIR}/Source")
endif()
if(ImguiNodeEditor_FOUND AND NOT TARGET ImguiNodeEditor::ImguiNodeEditor)
add_library(imgui_node_editor_impl STATIC ${ImguiNodeEditor_SOURCES})
target_include_directories(imgui_node_editor_impl
PUBLIC "${ImguiNodeEditor_INCLUDE_DIR}"
"${IMGUI_NODE_EDITOR_BLUEPRINT_UTILITIES_DIR}/Include"
PRIVATE "${IMGUI_NODE_EDITOR_DIR}/Source"
"${IMGUI_NODE_EDITOR_BLUEPRINT_UTILITIES_DIR}/Source"
)
# Must be defined before the first #include <imgui.h> in every translation
# unit (imgui_internal.h hard-errors otherwise) — a command-line define
# guarantees that ordering regardless of vendored include order.
target_compile_definitions(imgui_node_editor_impl PRIVATE IMGUI_DEFINE_MATH_OPERATORS)
# Must share this project's own ImGui build (same headers/defines) rather
# than pulling in a second ImGui — imgui-node-editor only needs the public
# API plus ImRect/ImFloor from imgui_internal.h.
target_link_libraries(imgui_node_editor_impl PUBLIC Imgui::Imgui)
add_library(ImguiNodeEditor::ImguiNodeEditor ALIAS imgui_node_editor_impl)
message(STATUS "imgui-node-editor found: ${ImguiNodeEditor_INCLUDE_DIR}")
endif()
mark_as_advanced(ImguiNodeEditor_INCLUDE_DIR)