In order to get the visible triangles of a mesh you need to:
Derive the Mesh class and override its DrawForSelection method in order to draw the triangles in false colors:
public class MyMesh : Mesh { public MyMesh(Mesh other, Workspace ws) : base(other) { this.ws = ws; } public bool GetAllVisibleTriangles { get; set; } private Workspace ws; protected override void DrawForSelection(GfxDrawForSelectionParams data) { if (GetAllVisibleTriangles) { // Draws the quads with the color-coding needed for visibility computation for (int i = 0; i < Triangles.Length; i++) { ws.SetColorDrawForSelection(i); IndexTriangle tri = Triangles[i]; data.RenderContext.DrawTriangles(new Point3D[] { Vertices[tri.V1], Vertices[tri.V2], Vertices[tri.V3], }, new Vector3D[] { Vector3D.AxisZ, Vector3D.AxisZ, Vector3D.AxisZ, }); } } else { base.DrawForSelection(data); } } public int[] SelectedTriangles; protected override void Render(RenderParams data) { // Just for Debug if (SelectedTriangles != null) { for (int i = 0; i < SelectedTriangles.Length; i++) { SmoothTriangle tri = (SmoothTriangle)Triangles[SelectedTriangles[i]]; data.RenderContext.DrawTriangles(new Point3D[] { Vertices[tri.V1], Vertices[tri.V2], Vertices[tri.V3], }, new Vector3D[] { Normals[tri.N1], Normals[tri.N2], Normals[tri.N3], }); } } else base.Draw(data); } }Derive the ViewportLayout and expose a method that gets the visible triangles:
public class MyDesign : Design { public int[] GetVisibleTriangles() { MyMesh mymesh = null; // Set Selectable = false to all the entities different from the MyMesh, so they don't interfere (only one MyMesh is supported) for (int i = 0; i < Entities.Count; i++) { if (!(Entities[i] is MyMesh)) { Entities[i].Selectable = false; } else { mymesh = ((MyMesh)Entities[i]); } } mymesh.GetAllVisibleTriangles = true; int[] triangles = GetAllVisibleEntities(new Rectangle(0, 0, Size.Width, Size.Height)); mymesh.GetAllVisibleTriangles = false; for (int i = 0; i < Entities.Count; i++) { Entities[i].Selectable = true; } mymesh.SelectedTriangles = triangles; // For debug return triangles; } }Create the MyMesh object and call the exposed method to get its visible triangles:
design1.Entities.Add(new MyMesh(Mesh.CreateTorus(20, 5, 10, 20), design1), "Default", Color.Red); ... int[] visibleTriangles = design1.GetVisibleTriangles();
On the left the original mesh, on the right the same mesh with just the visible triangles drawn after the view has been rotated a bit:
Comments
Please sign in to leave a comment.