Skip to content

Commit

Permalink
Experiment: Preview and Select Node via Mouse Hover in Viewport
Browse files Browse the repository at this point in the history
This experiment aims to introduce a feature that allows users to preview and select nodes by hovering their mouse over them in the viewport. This will provide a more intuitive and efficient way of interacting with nodes.

Todo
* To address potential performance concerns, the hover-based node selection feature will be disabled by default until a high-performance algorithm is implemented.
* Users can enable it in the settings as an experimental option, allowing for testing and feedback while minimizing performance impacts.
  • Loading branch information
r888800009 committed Sep 29, 2024
1 parent 834a8bc commit e91e3b8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
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

0 comments on commit e91e3b8

Please sign in to comment.