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

Fix to force update part mesh setting when layer size is changed. #53

Merged
merged 1 commit into from
Jul 3, 2022
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
33 changes: 30 additions & 3 deletions source/creator/windows/psdmerge.d
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,32 @@ private:
}
}

// rebuffer Part to update shape correctly. (code copied from mesheditor.d)
void updatePart(Node node) {
import creator.viewport.common.mesh;
Part part = cast(Part)node;
if (part !is null) {
auto mesh = new IncMesh(part.getMesh());
MeshData data = mesh.export_();
data.fixWinding();

// Fix UVs
foreach(i; 0..data.uvs.length) {
// Texture 0 is always albedo texture
auto tex = part.textures[0];

// By dividing by width and height we should get the values in UV coordinate space.
data.uvs[i].x /= cast(float)tex.width;
data.uvs[i].y /= cast(float)tex.height;
data.uvs[i] += vec2(0.5, 0.5);
}
part.rebuffer(data);
}
foreach (Node child; node.children) {
updatePart(child);
}
}

void apply() {
import std.algorithm.sorting : sort;
bindings.sort!((a, b) => a.depth < b.depth)();
Expand Down Expand Up @@ -181,7 +207,8 @@ private:

// Unload PSD, we're done with it
destroy(document);

puppet.root.transformChanged();
updatePart(puppet.root);
// Repopulate texture slots, removing unused textures
puppet.populateTextureSlots();
}
Expand Down Expand Up @@ -327,7 +354,7 @@ protected:

igBeginGroup();
if (igBeginChild("###Layers", ImVec2(childWidth, childHeight))) {
incInputText("", childWidth-gapspace, layerFilter);
incInputText("##", childWidth-gapspace, layerFilter);

igBeginListBox("###LayerList", ImVec2(childWidth-gapspace, childHeight-filterWidgetHeight-optionsListHeight));
layerView();
Expand All @@ -340,7 +367,7 @@ protected:
igSameLine(0, gapspace);

if (igBeginChild("###Nodes", ImVec2(childWidth, childHeight))) {
incInputText("", childWidth, nodeFilter);
incInputText("##", childWidth, nodeFilter);

igBeginListBox("###NodeList", ImVec2(childWidth, childHeight-filterWidgetHeight-optionsListHeight));
treeView();
Expand Down