예제 #1
0
        public static Mesh LoadMesh(XmlElement def)
        {
            Mesh toReturn = new Mesh();

            if(def.HasAttribute("filename"))
            {
                string str_file = def.GetAttribute("filename");
                bool smooth = false;
                if (def.HasAttribute("smooth"))
                    smooth = Convert.ToBoolean(def.GetAttribute("smooth"));

                toReturn.loadFromFile(str_file, smooth);
            }

            toReturn.SetupCells();

            return toReturn;
        }
예제 #2
0
 //virtual public BoundingBox getBoundingBox() { return _boundingBox; }
 protected void CalculateNormals(Mesh parent)
 {
     if(GlobalVars.verbose)
     {
         System.Console.WriteLine("Calculating vertex normals for mesh " + parent.id);
     }
     //Get the list of faces attached to a given vertex
     for (int i = 0; i < parent.countVertices; i++)
     {
         //Sum together all the normals of the faces attached to this vertex
         List<int> faceList = parent.vertexFaces[i];
         Normal normalSum = new Normal(0,0,0);
         for(int j = 0; j < faceList.Count; j++)
         {
             normalSum += parent.NormalForFace(faceList[j]);
         }
         normalSum.Normalize();
         parent.normals[i] = normalSum;
     }
 }
예제 #3
0
        public override void ParseFaces(Mesh parent, bool smooth)
        {
            int pastLastIndex = indexOfFaces + countFaces;
            int[] indexs = new int[5];
            MeshTriangle triangle;

            for (int i = indexOfFaces; i < pastLastIndex; i++)
            {
                string[] tokens = fileLines[i].Split(' ');
                int numVerts = Convert.ToInt32(tokens[0]);

                switch (numVerts)
                {
                    case 3: //Face is a triangle
                        for (int j = 1; j < 4; j++)
                        {
                            indexs[j] = Convert.ToInt32(tokens[j]);
                        }
                        //Create new triangle
                        if (smooth)
                            triangle = new SmoothMeshTriangle(parent);
                        else
                            triangle = new FlatMeshTriangle(parent);
                        triangle.SetVertexIndices(indexs[1], indexs[2], indexs[3]);
                        //Update list of faces for given vertexs using current index
                        parent.vertexFaces[indexs[1]].Add(parent.countTriangles);
                        parent.vertexFaces[indexs[2]].Add(parent.countTriangles);
                        parent.vertexFaces[indexs[3]].Add(parent.countTriangles);
                        parent.countTriangles++;
                        parent.AddObject(triangle);
                        break;

                    case 4: //Face is a quad
                        for (int j = 1; j < 5; j++)
                        {
                            indexs[j] = Convert.ToInt32(tokens[j]);
                        }
                        //Create new triangle
                        if (smooth)
                            triangle = new SmoothMeshTriangle(parent);
                        else
                            triangle = new FlatMeshTriangle(parent);
                        triangle.SetVertexIndices(indexs[1], indexs[2], indexs[3]);
                        //Update list of faces for given vertexs using current index
                        parent.vertexFaces[indexs[1]].Add(parent.countTriangles);
                        parent.vertexFaces[indexs[2]].Add(parent.countTriangles);
                        parent.vertexFaces[indexs[3]].Add(parent.countTriangles);
                        parent.countTriangles++;
                        parent.AddObject(triangle);
                        //Create new triangle
                        if (smooth)
                            triangle = new SmoothMeshTriangle(parent);
                        else
                            triangle = new FlatMeshTriangle(parent);
                        triangle.SetVertexIndices(indexs[3], indexs[4], indexs[1]);
                        //Update list of faces for given vertexs using current index
                        parent.vertexFaces[indexs[3]].Add(parent.countTriangles);
                        parent.vertexFaces[indexs[4]].Add(parent.countTriangles);
                        parent.vertexFaces[indexs[1]].Add(parent.countTriangles);
                        parent.countTriangles++;
                        parent.AddObject(triangle);
                        break;

                    default: //What the f**k kind of input are you feeding this poor parser?
                        throw new System.FormatException("Invalid token at line " + (i + 1) +
                            ": " + numVerts + "is not a valid number of vertices for a face.");
                }
            }
            CalculateNormals(parent);
        }
예제 #4
0
        public override void ParseVertices(Mesh parent)
        {
            int pastLastIndex = indexOfVertices + countVertices;

            for (int i = indexOfVertices; i < pastLastIndex; i++)
            {
                //Tokenize each line...
                string[] vertices = fileLines[i].Split(' ');

                float x = Convert.ToSingle(vertices[0]);
                float y = Convert.ToSingle(vertices[1]);
                float z = Convert.ToSingle(vertices[2]);

                parent.vertices.Add(new Point3D(x, y, z));
                parent.vertexFaces.Add(new List<int>());
                parent.normals.Add(new Normal(0, 0, 0));
                parent.countVertices++;
            }
        }
예제 #5
0
 public abstract void ParseVertices(Mesh parent);
예제 #6
0
 public virtual void ParseUV(Mesh parent)
 {
 }
예제 #7
0
 public abstract void ParseFaces(Mesh parent, bool smooth);