Exemple #1
0
        public static void Load(string filepath, TriangleMesh triMesh, float scale)
        {
            using (System.IO.TextReader reader = File.OpenText(filepath))
            {
                XmlSerializer ser = new XmlSerializer(typeof(Collada));
                Collada c = (Collada)ser.Deserialize(reader);
                foreach (Geometry g in c.library_geometries)
                {
                    float[] floats = g.mesh.PositionFloats();
                    int[] indices = g.mesh.TrianglePositionIndices();

                    List<Vector3> vertices = new List<Vector3>();

                    for (int i = 0; i < floats.Count(); i += 3)
                    {
                        Vector3 v = new Vector3(floats[i], floats[i + 1], floats[i + 2]);
                        vertices.Add(v * scale);
                    }

                    for (int i = 0; i < indices.Count(); i += 3)
                    {
                        triMesh.AddTriangle(vertices[indices[i]], vertices[indices[i + 1]], vertices[indices[i + 2]]);
                    }
                }
            }
            triMesh.Clean();
        }
Exemple #2
0
        public static void Load(string filepath, TriangleMesh triMesh, float scale)
        {
            using (System.IO.TextReader reader = File.OpenText(filepath))
            {
                XmlSerializer ser = new XmlSerializer(typeof(Collada));
                Collada       c   = (Collada)ser.Deserialize(reader);
                foreach (Geometry g in c.library_geometries)
                {
                    float[] floats  = g.mesh.PositionFloats();
                    int[]   indices = g.mesh.TrianglePositionIndices();

                    List <Vector3> vertices = new List <Vector3>();

                    for (int i = 0; i < floats.Count(); i += 3)
                    {
                        Vector3 v = new Vector3(floats[i], floats[i + 1], floats[i + 2]);
                        vertices.Add(v * scale);
                    }

                    for (int i = 0; i < indices.Count(); i += 3)
                    {
                        triMesh.AddTriangle(vertices[indices[i]], vertices[indices[i + 1]], vertices[indices[i + 2]]);
                    }
                }
            }
            triMesh.Clean();
        }
Exemple #3
0
        public static void Load(string filepath, TriangleMesh triMesh, float scale)
        {
            STLDocument stl = null;

            using (Stream filestream = File.OpenRead(filepath))
            {
                stl = STLDocument.Read(filestream);
            }

            foreach (var facet in stl.Facets)
            {
                List <Vector3> vertices = new List <Vector3>();
                foreach (var vertex in facet.Vertices)
                {
                    Vector3 v = new Vector3((float)vertex.X, (float)vertex.Y, (float)vertex.Z);
                    vertices.Add(v * scale);
                }
                triMesh.AddTriangle(new Triangle(vertices[0], vertices[1], vertices[2]));
            }
            triMesh.Clean();
        }