diff --git a/source/creator/actions/mesh.d b/source/creator/actions/mesh.d index 98b9be6b0..e34b0a7df 100644 --- a/source/creator/actions/mesh.d +++ b/source/creator/actions/mesh.d @@ -75,14 +75,16 @@ abstract class MeshAction : LazyBoundAction { class MeshAddAction : MeshAction { MeshVertex*[] vertices; + MeshVertex*[][4] axisVertices; this(string name, IncMeshEditorOne editor, IncMesh mesh, void delegate() update = null) { super(name, editor, mesh, update); } - void addVertex(MeshVertex* vertex) { + void addVertex(MeshVertex* vertex, int axis = 0) { vertices ~= vertex; mesh.vertices ~= vertex; + axisVertices[axis] ~= vertex; dirty = true; } @@ -96,6 +98,9 @@ class MeshAddAction : MeshAction { override void clear() { vertices.length = 0; + foreach (v; axisVertices) { + v.length = 0; + } super.clear(); } diff --git a/source/creator/viewport/common/mesheditor/operations/base.d b/source/creator/viewport/common/mesheditor/operations/base.d index 623e6f9c0..3f7613307 100644 --- a/source/creator/viewport/common/mesheditor/operations/base.d +++ b/source/creator/viewport/common/mesheditor/operations/base.d @@ -64,12 +64,7 @@ public: bool mutateSelection = false; bool invertSelection = false; ulong maybeSelectOne; - - // you should call updateVtxAtMouse() for updating vtxAtMouse - // because it also updates prevVtxAtMouse - // Note: prevVtxAtMouse for Undo may not safe to use currently ulong vtxAtMouse; - ulong prevVtxAtMouse; vec2 selectOrigin; IncMesh previewMesh; @@ -77,13 +72,6 @@ public: bool deforming = false; float meshEditAOE = 4; - void updateVtxAtMouse(ulong vtxIndex) { - // we hope prevVtxAtMouse tracks the previous != -1 vtxAtMouse - if (vtxAtMouse != -1) - prevVtxAtMouse = vtxAtMouse; - vtxAtMouse = vtxIndex; - } - bool isSelected(ulong vertIndex) { import std.algorithm.searching : canFind; return selected.canFind(vertIndex); @@ -257,7 +245,6 @@ public: this(bool deformOnly) { this.deformOnly = deformOnly; - prevVtxAtMouse = ulong(-1); } VertexToolMode getToolMode() { diff --git a/source/creator/viewport/common/mesheditor/tools/grid.d b/source/creator/viewport/common/mesheditor/tools/grid.d index 502e0e989..0ddb50851 100644 --- a/source/creator/viewport/common/mesheditor/tools/grid.d +++ b/source/creator/viewport/common/mesheditor/tools/grid.d @@ -272,7 +272,7 @@ class GridTool : NodeSelect { meshData.regenerateGrid(); mesh.copyFromMeshData(meshData); impl.refreshMesh(); - impl.updateVtxAtMouse(ulong(-1)); + impl.vtxAtMouse = ulong(-1); } } else { diff --git a/source/creator/viewport/common/mesheditor/tools/point.d b/source/creator/viewport/common/mesheditor/tools/point.d index c56543ac2..89463cdfd 100644 --- a/source/creator/viewport/common/mesheditor/tools/point.d +++ b/source/creator/viewport/common/mesheditor/tools/point.d @@ -25,7 +25,9 @@ import std.stdio; class PointTool : NodeSelect { Action action; - bool autoConnect = true; + + // using static for remembering the last setting + static bool autoConnect = true; override bool onDragStart(vec2 mousePos, IncMeshEditorOne impl) { if (!impl.deformOnly) { @@ -130,7 +132,7 @@ class PointTool : NodeSelect { impl.selected.length = 0; impl.updateMirrorSelected(); impl.maybeSelectOne = ulong(-1); - impl.updateVtxAtMouse(ulong(-1)); + impl.vtxAtMouse = ulong(-1); changed = true; } @@ -146,7 +148,7 @@ class PointTool : NodeSelect { } else { impl.foreachMirror((uint axis) { vertex = new MeshVertex(impl.mirror(axis, impl.mousePos)); - action.addVertex(vertex); + action.addVertex(vertex, axis); }); } impl.refreshMesh(); @@ -167,7 +169,7 @@ class PointTool : NodeSelect { auto lastAddAction = incActionFindLast!MeshAddAction(3); if (lastAddAction is null || lastAddAction.vertices.length == 0) return; - auto prevVertexIdx = impl.getVertexFromPoint(lastAddAction.vertices[$ - 1].position); + auto prevVertexIdx = impl.getVertexFromPoint(lastAddAction.axisVertices[0][$ - 1].position); auto prevVertex = impl.getVerticesByIndex([prevVertexIdx])[0]; if (prevVertex == null) return; auto action = new MeshConnectAction(impl.getTarget().name, impl, mesh); @@ -483,7 +485,7 @@ class PointToolInfo : ToolInfoBase!PointTool { } else { auto pointTool = cast(PointTool)(editors.length == 0 ? null: editors.values()[0].getTool()); igBeginGroup(); - if (incButtonColored("", ImVec2(0, 0), (pointTool !is null && !pointTool.isAutoConnect())? ImVec4.init : ImVec4(0.6, 0.6, 0.6, 1))) { + if (incButtonColored("", ImVec2(0, 0), (pointTool !is null && !pointTool.isAutoConnect())? ImVec4(0.6, 0.6, 0.6, 1) : ImVec4.init)) { foreach (e; editors) { auto pt = cast(PointTool)(e.getTool()); if (pt !is null) diff --git a/source/creator/viewport/common/mesheditor/tools/select.d b/source/creator/viewport/common/mesheditor/tools/select.d index ed34aae70..66f8e302f 100644 --- a/source/creator/viewport/common/mesheditor/tools/select.d +++ b/source/creator/viewport/common/mesheditor/tools/select.d @@ -114,7 +114,7 @@ class NodeSelect : Tool, Draggable { impl.mousePos = -impl.mousePos; } - impl.updateVtxAtMouse(impl.getVertexFromPoint(impl.mousePos)); + impl.vtxAtMouse = impl.getVertexFromPoint(impl.mousePos); return 0; }