diff --git a/source/creator/panels/viewport.d b/source/creator/panels/viewport.d index 765f4d5ff..6ed66a0d5 100644 --- a/source/creator/panels/viewport.d +++ b/source/creator/panels/viewport.d @@ -186,6 +186,9 @@ protected: } igPopStyleVar(); + import creator.viewport.model : incSelectIO; + incSelectIO(); + igPushStyleVar(ImGuiStyleVar.FrameBorderSize, 0); incBeginViewportToolArea("ToolArea", ImGuiDir.Left); igPushStyleVar_Vec2(ImGuiStyleVar.FramePadding, ImVec2(6, 6)); diff --git a/source/creator/viewport/model/package.d b/source/creator/viewport/model/package.d index 5e26798e7..9128f84b0 100644 --- a/source/creator/viewport/model/package.d +++ b/source/creator/viewport/model/package.d @@ -23,6 +23,7 @@ import std.stdio; private { Part[] foundParts; + Part[] mouseOverParts; enum ENTRY_SIZE = 48; } @@ -39,8 +40,8 @@ enum ViewporMenuSortMode { ViewporMenuSortMode incViewportModelMenuSortMode = ViewporMenuSortMode.ZSort; -void incViewportModelMenuOpening() { - foundParts.length = 0; +void incFoundParts(ref Part[] parts) { + parts.length = 0; vec2 mpos = incInputGetMousePosition()*-1; mloop: foreach(ref Part part; incActivePuppet.getAllParts()) { @@ -51,29 +52,52 @@ void incViewportModelMenuOpening() { foreach(pn; incSelectedNodes()) { if (pn.uuid == part.uuid) continue mloop; } - foundParts ~= part; + parts ~= part; } } +} +void incSortFoundParts(ref Part[] parts, ViewporMenuSortMode mode) { import std.algorithm.sorting : sort; import std.algorithm.mutation : SwapStrategy; import std.math : cmp; - if (incViewportModelMenuSortMode == ViewporMenuSortMode.ZSort) { + if (mode == ViewporMenuSortMode.ZSort) { sort!((a, b) => cmp( a.zSortNoOffset, - b.zSortNoOffset) < 0, SwapStrategy.stable)(foundParts); + b.zSortNoOffset) < 0, SwapStrategy.stable)(parts); - } else if (incViewportModelMenuSortMode == ViewporMenuSortMode.SizeSort) { + } else if (mode == ViewporMenuSortMode.SizeSort) { sort!((a, b) => cmp( (a.bounds.z - a.bounds.x) * (a.bounds.w - a.bounds.y), - (b.bounds.z - b.bounds.x) * (b.bounds.w - b.bounds.y)) < 0, SwapStrategy.stable)(foundParts); + (b.bounds.z - b.bounds.x) * (b.bounds.w - b.bounds.y)) < 0, SwapStrategy.stable)(parts); } else { throw new Exception("Unknown sort mode"); } } +void incViewportModelMenuOpening() { + incFoundParts(foundParts); + incSortFoundParts(foundParts, incViewportModelMenuSortMode); +} + +void incDrawMouse() { + if (mouseOverParts.length > 0) + mouseOverParts[0].drawBounds(); +} + +void incSelectIO() { + incFoundParts(mouseOverParts); + incSortFoundParts(mouseOverParts, ViewporMenuSortMode.ZSort); + if (mouseOverParts.length > 0) { + if (igIsItemClicked(ImGuiMouseButton.Left)) { + incSelectNode(mouseOverParts[0]); + //incFocusCamera(part); + } + } +} + void incViewportModelMenu() { if (auto editor = incViewportModelDeformGetEditor()) { editor.popupMenu(); @@ -266,6 +290,8 @@ void incViewportModelDraw(Camera camera) { incActivePuppet.update(); incActivePuppet.draw(); + incDrawMouse(); + if (param) { incViewportModelDeformDraw(camera, param); } else {