Skip to content

Commit

Permalink
multi-edit: Fix bugs: transformation matrix is not updated when T/R/S…
Browse files Browse the repository at this point in the history
… is changed during edit of armed parameter. (#165)
  • Loading branch information
seagetch authored Jan 19, 2023
1 parent 7c58a55 commit 59e899e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
13 changes: 13 additions & 0 deletions source/creator/panels/inspector.d
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
module creator.panels.inspector;
import creator.viewport.vertex;
import creator.viewport.model.deform;
import creator.core;
import creator.panels;
import creator.widgets;
Expand Down Expand Up @@ -1154,6 +1155,12 @@ void incInspectorDeformFloatDragVal(string name, string paramName, float adjustS
} else {
incActionPush(action);
}

if (auto editor = incViewportModelDeformGetEditor()) {
if (auto e = editor.getEditorFor(node)) {
e.adjustPathTransform();
}
}
}
}

Expand Down Expand Up @@ -1297,6 +1304,12 @@ void incInspectorDeformSetValue(Node node, Parameter param, string paramName, ve
} else {
incActionPush(action);
}

if (auto editor = incViewportModelDeformGetEditor()) {
if (auto e = editor.getEditorFor(node)) {
e.adjustPathTransform();
}
}
}

void incInspectorDeformTRS(Node node, Parameter param, vec2u cursor) {
Expand Down
12 changes: 8 additions & 4 deletions source/creator/viewport/common/mesheditor.d
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ public:
mousePos = incInputGetMousePosition();
if (deformOnly) {
vec4 pIn = vec4(-mousePos.x, -mousePos.y, 0, 1);
// mat4 tr = target.transform.matrix().inverse();
mat4 tr = transform.inverse();
vec4 pOut = tr * pIn;
mousePos = vec2(pOut.x, pOut.y);
Expand Down Expand Up @@ -894,7 +893,7 @@ public:

override
void removeVertexAt(vec2 vertex) {
mesh.removeVertexAt(vertex); // mirror(axis, mousePos)
mesh.removeVertexAt(vertex);
}

override
Expand Down Expand Up @@ -1111,7 +1110,12 @@ public:

override
void adjustPathTransform() {
mat4 trans = (target? target.transform.matrix: transform).inverse * transform;
ref CatmullSpline doAdjust(ref CatmullSpline p) {
for (int i; i < p.points.length; i++) {
p.points[i].position = (trans * vec4(p.points[i].position, 0, 1)).xy;
}
p.update();
remapPathTarget(p, mat4.identity);
return p;
}
Expand All @@ -1120,6 +1124,8 @@ public:
path.target = doAdjust(path.target);
path = doAdjust(path);
}
lastMousePos = (trans * vec4(lastMousePos, 0, 1)).xy;
transform = this.target.transform.matrix;
forceResetAction();
}

Expand Down Expand Up @@ -1148,7 +1154,6 @@ public:
override
void setTarget(Node target) {
super.setTarget(target);
// transform = (target && target.parent()) ? target.parent().transform.matrix : mat4.identity;
transform = target? target.transform.matrix : mat4.identity;
refreshMesh();
}
Expand Down Expand Up @@ -1391,7 +1396,6 @@ public:

if (vtxAtMouse !is null && !isSelecting) {
MeshVertex*[] one = [vtxAtMouse];
// mesh.drawPointSubset(one, vec4(1, 1, 1, 0.3), trans, 15);
}

if (isSelecting) {
Expand Down
13 changes: 0 additions & 13 deletions source/creator/viewport/model/deform.d
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,6 @@ void incViewportNodeDeformNotifyParamValueChanged() {
e.adjustPathTransform();
}
}
/*
foreach (d; drawables) {
if (Drawable drawable = cast(Drawable)d) {
DeformationParameterBinding deform = cast(DeformationParameterBinding)param.getBinding(drawable, "deform");
if (deform) {
auto binding = deform.getValue(param.findClosestKeypoint());
auto e = editor.getEditorFor(drawable);
e.applyOffsets(binding.vertexOffsets);
e.adjustPathTransform();
}
}
}
*/
} else {
editor = null;
}
Expand Down
6 changes: 6 additions & 0 deletions source/creator/viewport/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import creator.core.input;
import creator.actions;
import creator.viewport;
import creator.viewport.model;
import creator.viewport.model.deform;
import creator.viewport.vertex;
import creator.viewport.anim;
import creator.viewport.test;
Expand Down Expand Up @@ -339,6 +340,11 @@ void incViewportTransformHandle() {
param.addBinding(b);
status.actions["Add"]= new ParameterBindingAddAction(param, b);
}
if (auto editor = incViewportModelDeformGetEditor()) {
if (auto e = editor.getEditorFor(node)) {
e.adjustPathTransform();
}
}
// Push action
if (paramName !in status.actions)
status.actions[paramName] = new ParameterBindingValueChangeAction!(float)(b.getName(), b, index.x, index.y);
Expand Down

0 comments on commit 59e899e

Please sign in to comment.