Skip to content

Commit

Permalink
Fix path deform tool crashing on meshless nodes (#344)
Browse files Browse the repository at this point in the history
* Fix path deform tool crashing with meshless nodes

* Fix crash from path tool desync

* Fix crash when trying to remove desync path points
  • Loading branch information
grillo-delmal authored May 3, 2024
1 parent 04e8434 commit 45c43a3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
19 changes: 12 additions & 7 deletions source/creator/viewport/common/mesheditor/tools/pathdeform.d
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,14 @@ class PathDeformTool : NodeSelect {
}

if (action == PathDeformActionID.StartTransform || action == PathDeformActionID.StartShiftTransform) {
(cast(MeshEditorAction!DeformationAction)(impl.getDeformAction())).clear();
auto deform = (cast(MeshEditorAction!DeformationAction)(impl.getDeformAction()));
if(deform !is null) deform.clear();
}

if (action == PathDeformActionID.RemovePoint || action == PathDeformActionID.AddPoint) {
if (action == PathDeformActionID.RemovePoint) {
int idx = path.findPoint(impl.mousePos);
path.removePoint(idx);
if(idx != -1) path.removePoint(idx);
} else if (action == PathDeformActionID.AddPoint) {
path.addPoint(impl.mousePos);
}
Expand Down Expand Up @@ -289,13 +290,17 @@ class PathDeformTool : NodeSelect {
}

} else if (action == PathDeformActionID.Shift || action == PathDeformActionID.StartShiftTransform) {
float off = path.findClosestPointOffset(impl.mousePos);
vec2 pos = path.eval(off);
editPath.points[pathDragTarget].position = pos;
if(pathDragTarget != -1){
float off = path.findClosestPointOffset(impl.mousePos);
vec2 pos = path.eval(off);
editPath.points[pathDragTarget].position = pos;
}

} else if (action == PathDeformActionID.Transform || action == PathDeformActionID.StartTransform) {
vec2 relTranslation = impl.mousePos - impl.lastMousePos;
editPath.points[pathDragTarget].position += relTranslation;
if(pathDragTarget != -1){
vec2 relTranslation = impl.mousePos - impl.lastMousePos;
editPath.points[pathDragTarget].position += relTranslation;
}
}

editPath.update();
Expand Down
10 changes: 9 additions & 1 deletion source/creator/viewport/common/spline.d
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ public:
return mat4.identity();
}

mat4 exportTarget(T)(ref T mesh, size_t i, ref vec2 vtx, vec2 tangent, vec2 initTangent) {
return mat4.identity();
}

mat4 exportTarget(ref IncMesh mesh, size_t i, ref vec2 vtx, vec2 tangent, vec2 initTangent, mat4 invert, vec2 deformation) {
mesh.vertices[i].position = (invert * vec4(vtx, 0, 1)).xy - deformation;
return mat4.identity();
Expand Down Expand Up @@ -252,7 +256,11 @@ public:
pt.y + rel.y * tangent.x + rel.x * tangent.y
);
// writefln("%s %s %s", vtx, rel, tangent);
result = exportTarget(mesh, i, vtx, tangent, initTangents.length > i ? initTangents[i]: tangent, invert, deformations[i]);
if(deformations is null){
result = exportTarget(mesh, i, vtx, tangent, initTangents.length > i ? initTangents[i]: tangent);
} else {
result = exportTarget(mesh, i, vtx, tangent, initTangents.length > i ? initTangents[i]: tangent, invert, deformations[i]);
}
}
return result;
}
Expand Down

0 comments on commit 45c43a3

Please sign in to comment.