Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental: Preview and Select Node via Mouse Hover in Viewport #450

Draft
wants to merge 1 commit into
base: v0_8
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions source/creator/panels/viewport.d
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
40 changes: 33 additions & 7 deletions source/creator/viewport/model/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import std.stdio;

private {
Part[] foundParts;
Part[] mouseOverParts;

enum ENTRY_SIZE = 48;
}
Expand All @@ -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()) {
Expand All @@ -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();
Expand Down Expand Up @@ -266,6 +290,8 @@ void incViewportModelDraw(Camera camera) {
incActivePuppet.update();
incActivePuppet.draw();

incDrawMouse();

if (param) {
incViewportModelDeformDraw(camera, param);
} else {
Expand Down
Loading