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: Add SizeSort for Viewport Right Click Menu Sorting #398

Merged
merged 3 commits into from
Sep 11, 2024
Merged
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
38 changes: 34 additions & 4 deletions source/creator/viewport/model/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ private {
enum ENTRY_SIZE = 48;
}

/**
For detailed puppets or small components, we assume the user will directly point to the one they want.
ZSort is slightly less effective than SizeSort on layers with more alpha pixels (e.g., hair overlapping eyes).
SizeSort prioritizes smaller objects, making them easier to select.
*/
enum ViewporMenuSortMode {
ZSort,
SizeSort,
}

ViewporMenuSortMode incViewportModelMenuSortMode = ViewporMenuSortMode.ZSort;

void incViewportModelMenuOpening() {
foundParts.length = 0;

Expand All @@ -46,16 +58,34 @@ void incViewportModelMenuOpening() {
import std.algorithm.sorting : sort;
import std.algorithm.mutation : SwapStrategy;
import std.math : cmp;
sort!((a, b) => cmp(
a.zSortNoOffset,
b.zSortNoOffset) < 0, SwapStrategy.stable)(foundParts);

if (incViewportModelMenuSortMode == ViewporMenuSortMode.ZSort) {
sort!((a, b) => cmp(
a.zSortNoOffset,
b.zSortNoOffset) < 0, SwapStrategy.stable)(foundParts);

} else if (incViewportModelMenuSortMode == 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);

} else {
throw new Exception("Unknown sort mode");
}
}

void incViewportModelMenu() {
if (auto editor = incViewportModelDeformGetEditor()) {
editor.popupMenu();
}
igNewLine();

if (igMenuItem(incViewportModelMenuSortMode == ViewporMenuSortMode.ZSort ? __("Z-Sort") : __("Size-Sort"))) {
if (incViewportModelMenuSortMode == ViewporMenuSortMode.ZSort)
incViewportModelMenuSortMode = ViewporMenuSortMode.SizeSort;
else
incViewportModelMenuSortMode = ViewporMenuSortMode.ZSort;
}

igSeparator();

if (incSelectedNode() != incActivePuppet().root) {
Expand Down
Loading