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

feat: show/hide Mesh Group Child Nodes Bounds #394

Merged
Merged
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
10 changes: 10 additions & 0 deletions source/creator/viewport/common/mesheditor/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ private:
bool mirrorVert = false;
VertexToolMode toolMode = VertexToolMode.Points;

bool showMeshgroupNodeChild = true;

public:
bool deformOnly;
bool hasPopupMeshgroupNoDrawables = false;

this(bool deformOnly) {
this.deformOnly = deformOnly;
Expand Down Expand Up @@ -326,5 +329,12 @@ public:
return true;
}

void setShowMeshgroupNodeChild(bool show) {
this.showMeshgroupNodeChild = show;
}

bool getShowMeshgroupNodeChild() {
return showMeshgroupNodeChild;
}
}

52 changes: 52 additions & 0 deletions source/creator/viewport/vertex/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,41 @@ void incViewportVertexTools() {
editor.viewportTools();
}

class MeshGroupNodeDrawer {
Node node;
this(Node node) {
this.node = node;
}

void draw() {
import inochi2d.core.dbg;

if (!editor.getShowMeshgroupNodeChild())
return;

node.drawBounds();

auto trans = node.transform.matrix();
inDbgSetBuffer([vec3(0, 0, 0)], [0]);
inDbgPointsSize(10);
inDbgDrawPoints(vec4(0, 0, 0, 1), trans);
inDbgPointsSize(6);
inDbgDrawPoints(vec4(0.5, 0.8, 0.5, 1), trans);
}
}

void incViewportVertexOptions() {
igPushStyleVar(ImGuiStyleVar.ItemSpacing, ImVec2(0, 0));
igPushStyleVar(ImGuiStyleVar.WindowPadding, ImVec2(4, 4));
igBeginGroup();
if (incButtonColored("\ue3eb##mesh-group-view-node", ImVec2(0, 0), editor.getShowMeshgroupNodeChild() ? ImVec4.init : ImVec4(0.6, 0.6, 0.6, 1))) {
editor.setShowMeshgroupNodeChild(!editor.getShowMeshgroupNodeChild());
}
incTooltip(_("Show Mesh Group Child Nodes Bounds"));
igEndGroup();

igSameLine(0, 4);

igBeginGroup();
if (igButton("")) {
foreach (d; incSelectedNodes) {
Expand Down Expand Up @@ -206,6 +238,7 @@ void incViewportVertexDraw(Camera camera) {
mat4 transform = mgroup.transform.matrix.inverse;
mgroup.setOneTimeTransform(&transform);
Node[] subParts;
Node[] subNodes;
void findSubDrawable(Node n) {
if (auto m = cast(MeshGroup)n) {
foreach (child; n.children)
Expand All @@ -218,6 +251,8 @@ void incViewportVertexDraw(Camera camera) {
subParts ~= d;
foreach (child; n.children)
findSubDrawable(child);
} else {
subNodes ~= n;
}
}
findSubDrawable(mgroup);
Expand All @@ -228,9 +263,26 @@ void incViewportVertexDraw(Camera camera) {
a.zSort,
b.zSort) > 0, SwapStrategy.stable)(subParts);

foreach (part; subNodes) {
auto nd = new MeshGroupNodeDrawer(part);
nd.draw();
}

foreach (part; subParts) {
part.drawOne();
}

if (subParts.length == 0 && !editor.hasPopupMeshgroupNoDrawables) {
import creator.widgets.dialog;
editor.hasPopupMeshgroupNoDrawables = true;
incDialog(
"NO_DRAWABLES",
__("No Drawables"),
_("This meshgroup has no drawables to deform. To deform, replace the child with a meshgroup or other type."),
DialogLevel.Info, DialogButtons.OK
);
}

mgroup.setOneTimeTransform(null);
}
}
Expand Down
Loading