Esempio n. 1
0
 public StlTriangle(StlNormal normal, StlVertex v1, StlVertex v2, StlVertex v3)
 {
     Normal = normal;
     Vertex1 = v1;
     Vertex2 = v2;
     Vertex3 = v3;
 }
Esempio n. 2
0
 public StlTriangle(StlNormal normal, StlVertex v1, StlVertex v2, StlVertex v3)
 {
     Normal  = normal;
     Vertex1 = v1;
     Vertex2 = v2;
     Vertex3 = v3;
 }
Esempio n. 3
0
 public StlTriangle(StlNormal normal, StlVertex vertex1, StlVertex vertexv2, StlVertex vertex3)
 {
     Normal  = normal;
     Vertex1 = vertex1;
     Vertex2 = vertexv2;
     Vertex3 = vertex3;
 }
Esempio n. 4
0
        } //Rotate the mesh with the rotation matrix

        public StlVertex MultiplyByMatrix(StlVertex vertex, double[][] rotation)
        {
            /*| a11 a12 a13 |    | b1 |    | a11*b1 + a12*b2 + a13*b3 |
             | a21 a22 a23 | x | b2 | = | a21*b1 + a22*b2 + a23*b3 |
             | a31 a32 a33 |    | b3 |    | a31*b1 + a32*b2 + a33*b3 |  */
            double x = rotation[0][0] * vertex.X + rotation[0][1] * vertex.Y + rotation[0][2] * vertex.Z;
            double y = rotation[1][0] * vertex.X + rotation[1][1] * vertex.Y + rotation[1][2] * vertex.Z;
            double z = rotation[2][0] * vertex.X + rotation[2][1] * vertex.Y + rotation[2][2] * vertex.Z;

            return(new StlVertex((float)x, (float)y, (float)z));
        } //Multiplicate Vector with Matrix
Esempio n. 5
0
 private static Point ToPoint(StlVertex vertex)
 {
     return(new Point(vertex.X, vertex.Y, vertex.Z));
 }
Esempio n. 6
0
 private static Vector3 FromSTLVertex(StlVertex stlVertex)
 {
     return(new Vector3(stlVertex.X, stlVertex.Y, stlVertex.Z));
 }
Esempio n. 7
0
        public static List <List <StlTriangle> > test(string filePath)
        {
            var content = get_model(filePath);

            if (content == null)
            {
                return(null);
            }
            XmlDocument document = new XmlDocument();

            document.LoadXml(content);
            List <List <StlTriangle> > allMeshes = new List <List <StlTriangle> > ();

            var model = document.DocumentElement;

            if (model != null && model.Name == "model")
            {
                var ressources = getChild(model, "resources");
                if (ressources != null)
                {
                    var objects = getChilds(ressources, "object");
                    foreach (var obj in objects)
                    {
                        var mesh = getChild(obj, "mesh");
                        if (mesh != null)
                        {
                            List <StlVertex> ver = new List <StlVertex> ();
                            var vertices         = getChild(mesh, "vertices");
                            if (vertices != null)
                            {
                                var vertexs = getChilds(vertices, "vertex");
                                foreach (var verchild in vertexs)
                                {
                                    var newVertex = new StlVertex();
                                    newVertex.X = float.Parse(verchild.Attributes["x"].Value, CultureInfo.InvariantCulture);
                                    newVertex.Y = float.Parse(verchild.Attributes["y"].Value, CultureInfo.InvariantCulture);
                                    newVertex.Z = float.Parse(verchild.Attributes["z"].Value, CultureInfo.InvariantCulture);
                                    ver.Add(newVertex);
                                }
                            }
                            var triangles = getChild(mesh, "triangles");
                            var Opti      = new Opti();
                            if (triangles != null)
                            {
                                var tris  = getChilds(triangles, "triangle");
                                var faces = tris.Select(x => {
                                    var Face     = new StlTriangle(new StlNormal(), new StlVertex(), new StlVertex(), new StlVertex());
                                    Face.Vertex1 = ver.ElementAt(int.Parse(x.Attributes["v1"].Value));
                                    Face.Vertex2 = ver.ElementAt(int.Parse(x.Attributes["v2"].Value));
                                    Face.Vertex3 = ver.ElementAt(int.Parse(x.Attributes["v3"].Value));
                                    Face.Normal  = Opti.FNormalFromVertices(new List <StlVertex> {
                                        Face.Vertex1, Face.Vertex2, Face.Vertex3
                                    });
                                    return(Face);
                                }).ToList();
                                allMeshes.Add(faces);
                            }
                        }
                    }
                }
            }
            return(allMeshes);
        }