forked from gradientspace/geometry3Sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added area-extrusion, renamed loop-extrusion
- Loading branch information
Showing
7 changed files
with
154 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace g3 | ||
{ | ||
public class MeshExtrudeFaces | ||
{ | ||
public DMesh3 Mesh; | ||
public int[] Triangles; | ||
|
||
// arguments | ||
|
||
public SetGroupBehavior Group = SetGroupBehavior.AutoGenerate; | ||
|
||
// set new position based on original loop vertex position, normal, and index | ||
public Func<Vector3d, Vector3f, int, Vector3d> ExtrudedPositionF; | ||
|
||
// outputs | ||
public List<Index2i> EdgePairs; | ||
public MeshVertexSelection ExtrudeVertices; | ||
public int[] JoinTriangles; | ||
public int SetGroupID; | ||
|
||
|
||
public MeshExtrudeFaces(DMesh3 mesh, int[] triangles, bool bForceCopyArray = false) | ||
{ | ||
Mesh = mesh; | ||
if (bForceCopyArray) | ||
Triangles = (int[])triangles.Clone(); | ||
else | ||
Triangles = triangles; | ||
|
||
ExtrudedPositionF = (pos, normal, idx) => { | ||
return pos + Vector3d.AxisY; | ||
}; | ||
} | ||
|
||
public MeshExtrudeFaces(DMesh3 mesh, IEnumerable<int> triangles) | ||
{ | ||
Mesh = mesh; | ||
Triangles = triangles.ToArray(); | ||
|
||
ExtrudedPositionF = (pos, normal, idx) => { | ||
return pos + Vector3d.AxisY; | ||
}; | ||
} | ||
|
||
|
||
|
||
public virtual ValidationStatus Validate() | ||
{ | ||
// [todo] check that boundary is ok | ||
|
||
|
||
return ValidationStatus.Ok; | ||
} | ||
|
||
|
||
public virtual bool Extrude() | ||
{ | ||
MeshEditor editor = new MeshEditor(Mesh); | ||
|
||
MeshNormals normals = null; | ||
bool bHaveNormals = Mesh.HasVertexNormals; | ||
if (!bHaveNormals) { | ||
normals = new MeshNormals(Mesh); | ||
normals.Compute(); | ||
} | ||
|
||
editor.SeparateTriangles(Triangles, true, out EdgePairs); | ||
|
||
ExtrudeVertices = new MeshVertexSelection(Mesh); | ||
ExtrudeVertices.SelectTriangleVertices(Triangles); | ||
|
||
Vector3d[] NewVertices = new Vector3d[ExtrudeVertices.Count]; | ||
int k = 0; | ||
foreach (int vid in ExtrudeVertices) { | ||
Vector3d v = Mesh.GetVertex(vid); | ||
Vector3f n = (bHaveNormals) ? Mesh.GetVertexNormal(vid) : (Vector3f)normals.Normals[vid]; | ||
NewVertices[k++] = ExtrudedPositionF(v, n, vid); | ||
} | ||
k = 0; | ||
foreach (int vid in ExtrudeVertices) | ||
Mesh.SetVertex(vid, NewVertices[k++]); | ||
|
||
|
||
SetGroupID = Group.GetGroupID(Mesh); | ||
JoinTriangles = editor.StitchUnorderedEdges(EdgePairs, SetGroupID); | ||
|
||
return true; | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
|
||
namespace g3 | ||
{ | ||
|
||
public struct SetGroupBehavior | ||
{ | ||
public enum Modes | ||
{ | ||
Ignore = 0, | ||
AutoGenerate = 1, | ||
UseConstant = 2 | ||
}; | ||
Modes Mode; | ||
int SetGroupID; | ||
|
||
public SetGroupBehavior(Modes mode, int id = 0) { | ||
Mode = mode; | ||
SetGroupID = id; | ||
} | ||
|
||
public int GetGroupID(DMesh3 mesh) | ||
{ | ||
if (Mode == Modes.Ignore) | ||
return -1; | ||
else if (Mode == Modes.AutoGenerate) | ||
return mesh.AllocateTriangleGroup(); | ||
else | ||
return SetGroupID; | ||
} | ||
|
||
public static SetGroupBehavior Ignore { get { return new SetGroupBehavior(Modes.Ignore, 0); } } | ||
public static SetGroupBehavior AutoGenerate { get { return new SetGroupBehavior(Modes.AutoGenerate, 0); } } | ||
public static SetGroupBehavior SetTo(int groupID) { return new SetGroupBehavior(Modes.UseConstant, groupID); } | ||
} | ||
|
||
|
||
public static class MeshOps | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters