Пример #1
0
        protected void ParseDataObjectMeshNormals(ref Mesh mesh)
        {
            ReadHeadOfDataObject();

            // read count
            uint numNormals = ReadInt();
            mesh.Normals = new List<Vector3D>((int)numNormals);

            // read normal vectors
            for (uint a = 0; a < numNormals; a++)
                mesh.Normals.Add(ReadVector3());

            // read normal indices
            uint numFaces = ReadInt();
            if (numFaces != mesh.PosFaces.Count)
                ThrowException("Normal face count does not match vertex face count.");

            for (uint a = 0; a < numFaces; a++)
            {
                uint numIndices = ReadInt();
                Face face = new Face();
                face.Indices = new List<uint>();
                for (uint b = 0; b < numIndices; b++)
                    face.Indices.Add(ReadInt());
                mesh.NormalFaces.Add(face);

                TestForSeparator();
            }

            CheckForClosingBrace();
        }
Пример #2
0
        protected void ParseDataObjectMesh(out Mesh mesh)
        {
            mesh = new Mesh();
            string name;
            ReadHeadOfDataObject(out name);

            // read vertex count
            uint numVertices = ReadInt();
            mesh.Positions = new List<Vector3D>((int)numVertices);

            // read vertices
            for (int a = 0; a < numVertices; a++)
                mesh.Positions.Add(ReadVector3());

            // read position faces
            uint numPosFaces = ReadInt();
            mesh.PosFaces = new List<Face>((int)numPosFaces);
            for (uint a = 0; a < numPosFaces; a++)
            {
                uint numIndices = ReadInt();
                if (numIndices < 3)
                    ThrowException(string.Format("Invalid index count {0} for face {1}.", numIndices, a));

                // read indices
                Face face = new Face();
                face.Indices = new List<uint>();
                for (uint b = 0; b < numIndices; b++)
                    face.Indices.Add(ReadInt());
                mesh.PosFaces.Add(face);
                TestForSeparator();
            }

            // here, other data objects may follow
            bool running = true;
            while (running)
            {
                string objectName = GetNextToken();

                if (objectName.Length == 0)
                    ThrowException("Unexpected end of file while parsing mesh structure");
                else if (objectName == "}")
                    break; // mesh finished
                else if (objectName == "MeshNormals")
                    ParseDataObjectMeshNormals(ref mesh);
                else if (objectName == "MeshTextureCoords")
                    ParseDataObjectMeshTextureCoords(ref mesh);
                else if (objectName == "MeshVertexColors")
                    ParseDataObjectMeshVertexColors(ref mesh);
                else if (objectName == "MeshMaterialList")
                    ParseDataObjectMeshMaterialList(ref mesh);
                else if (objectName == "VertexDuplicationIndices")
                    ParseUnknownDataObject(); // we'll ignore vertex duplication indices
                else if (objectName == "XSkinMeshHeader")
                    ParseDataObjectSkinMeshHeader(ref mesh);
                else if (objectName == "SkinWeights")
                    ParseDataObjectSkinWeights(ref mesh);
                else
                {
                    Debug.WriteLine("Unknown data object in mesh in x file");
                    ParseUnknownDataObject();
                }
            }
        }