public static void Restore(DMesh3 mesh, BinaryReader reader) { int version = reader.ReadInt32(); if (version != DMesh3Version) { throw new Exception("gSerialization.Restore: Incorrect DMesh3Version!"); } MeshComponents components = (MeshComponents)reader.ReadInt32(); Restore(mesh.VerticesBuffer, reader); Restore(mesh.TrianglesBuffer, reader); Restore(mesh.EdgesBuffer, reader); Restore(mesh.EdgesRefCounts.RawRefCounts, reader); if ((components & MeshComponents.VertexNormals) != 0) { mesh.EnableVertexNormals(Vector3f.AxisY); Restore(mesh.NormalsBuffer, reader); } else { mesh.DiscardVertexNormals(); } if ((components & MeshComponents.VertexColors) != 0) { mesh.EnableVertexColors(Vector3f.One); Restore(mesh.ColorsBuffer, reader); } else { mesh.DiscardVertexColors(); } if ((components & MeshComponents.VertexUVs) != 0) { mesh.EnableVertexUVs(Vector2f.Zero); Restore(mesh.UVBuffer, reader); } else { mesh.DiscardVertexUVs(); } if ((components & MeshComponents.FaceGroups) != 0) { mesh.EnableTriangleGroups(0); Restore(mesh.GroupsBuffer, reader); } else { mesh.DiscardTriangleGroups(); } mesh.RebuildFromEdgeRefcounts(); }
void append_mesh() { if (Meshes == null || Meshes.Count == 0) { Meshes = new List <DMesh3>(); } cur_mesh = new DMesh3(MeshComponents.VertexNormals); if (ColorSourceF != null) { cur_mesh.EnableVertexColors(Colorf.White); } Meshes.Add(cur_mesh); }
public void AppendPathSolid(IEnumerable <Vector3d> vertices, double radius, Colorf color) { TubeGenerator tubegen = new TubeGenerator() { Vertices = new List <Vector3d>(vertices), Polygon = Polygon2d.MakeCircle(radius, 6), NoSharedVertices = false }; DMesh3 mesh = tubegen.Generate().MakeDMesh(); if (Mesh.HasVertexColors) { mesh.EnableVertexColors(color); } AppendMesh(mesh, Mesh.AllocateTriangleGroup()); }
public void AppendBox(Frame3f frame, Vector3f size, Colorf color) { TrivialBox3Generator boxgen = new TrivialBox3Generator() { Box = new Box3d(frame, size), NoSharedVertices = false }; boxgen.Generate(); DMesh3 mesh = new DMesh3(); boxgen.MakeMesh(mesh); if (Mesh.HasVertexColors) { mesh.EnableVertexColors(color); } AppendMesh(mesh, Mesh.AllocateTriangleGroup()); }
protected DMesh3 MakeDebugGraphMesh() { DMesh3 graphMesh = new DMesh3(); graphMesh.EnableVertexColors(Vector3f.One); foreach (int vid in Graph.VertexIndices()) { if (TipVertices.Contains(vid)) { MeshEditor.AppendBox(graphMesh, Graph.GetVertex(vid), 0.3f, Colorf.Green); } else if (TipBaseVertices.Contains(vid)) { MeshEditor.AppendBox(graphMesh, Graph.GetVertex(vid), 0.225f, Colorf.Magenta); } else if (GroundVertices.Contains(vid)) { MeshEditor.AppendBox(graphMesh, Graph.GetVertex(vid), 0.35f, Colorf.Blue); } else { MeshEditor.AppendBox(graphMesh, Graph.GetVertex(vid), 0.15f, Colorf.White); } } foreach (int eid in Graph.EdgeIndices()) { Segment3d seg = Graph.GetEdgeSegment(eid); MeshEditor.AppendLine(graphMesh, seg, 0.1f); } return graphMesh; }