private void ParseFaceList(AseParser parser, IList<AseFace> faces) { parser.Consume("{"); for (;;) { var attr = parser.Consume(); if (attr == null || attr == "}") { break; } if (0 == string.Compare(attr, "*MESH_FACE", StringComparison.InvariantCultureIgnoreCase)) { var index = int.Parse(parser.Consume().TrimEnd(':'), CultureInfo.InvariantCulture); parser.Consume("A:"); var a = parser.ConsumeInt(); parser.Consume("B:"); var b = parser.ConsumeInt(); parser.Consume("C:"); var c = parser.ConsumeInt(); parser.Consume("AB:"); var ab = parser.ConsumeInt(); parser.Consume("BC:"); var bc = parser.ConsumeInt(); parser.Consume("CA:"); var ca = parser.ConsumeInt(); faces[index] = new AseFace { A = a, B = b, C = c }; if (parser.Lexem == "*MESH_SMOOTHING") { parser.Consume(); if (parser.Lexem != "*MESH_MTLID") { parser.ConsumeInt(); } } if (parser.Lexem == "*MESH_MTLID") { parser.Consume(); parser.ConsumeInt(); } continue; } parser.UnknownLexemError(); } }
private void ParsSubMesh(AseParser parser, Scene scene, Node node) { var mesh = new SeparateStreamsMesh(); var submesh = mesh.CreateSubmesh(); node.Mesh = mesh; scene.Geometries.Add(mesh); ArrayMeshStream<Float3> vertices = null; ListMeshStream<Float3> normalStream = null; FaceNormal[] normals = null; ArrayMeshStream<Float3> tvertices = null; ArrayMeshStream<Color> cols = null; AseFace[] faces = null; AseTFace[] tfaces = null; Tuple<int, int, int>[] colFaces = null; //TODO: submesh can have it's own vertex streams parser.Consume("{"); for (;;) { var attr = parser.Consume(); if (attr == null || attr == "}") { break; } if (0 == string.Compare(attr, "*TIMEVALUE", StringComparison.InvariantCultureIgnoreCase)) { parser.ConsumeFloat(); continue; } if (0 == string.Compare(attr, "*MESH_NUMVERTEX", StringComparison.InvariantCultureIgnoreCase)) { vertices = new ArrayMeshStream<Float3>(parser.ConsumeInt(), converterFactory); mesh.SetStream(Streams.Position, 0, vertices); continue; } if (0 == string.Compare(attr, "*MESH_VERTEX_LIST", StringComparison.InvariantCultureIgnoreCase)) { this.ParseVertexList(parser, vertices); continue; } if (0 == string.Compare(attr, "*MESH_NUMTVERTEX", StringComparison.InvariantCultureIgnoreCase)) { tvertices = new ArrayMeshStream<Float3>(parser.ConsumeInt(), converterFactory); mesh.SetStream(Streams.TexCoord, 0, tvertices); continue; } if (0 == string.Compare(attr, "*MESH_TVERTLIST", StringComparison.InvariantCultureIgnoreCase)) { this.ParseTVertList(parser, tvertices); continue; } if (0 == string.Compare(attr, "*MESH_NUMTVFACES", StringComparison.InvariantCultureIgnoreCase)) { tfaces = new AseTFace[parser.ConsumeInt()]; continue; } if (0 == string.Compare(attr, "*MESH_TFACELIST", StringComparison.InvariantCultureIgnoreCase)) { this.ParseTFaceList(parser, tfaces); continue; } if (0 == string.Compare(attr, "*MESH_NUMCVERTEX", StringComparison.InvariantCultureIgnoreCase)) { cols = new ArrayMeshStream<Color>(parser.ConsumeInt(), converterFactory); mesh.SetStream(Streams.Color, 0, cols); continue; } if (0 == string.Compare(attr, "*MESH_CVERTLIST", StringComparison.InvariantCultureIgnoreCase)) { this.ParseColList(parser, cols); continue; } if (0 == string.Compare(attr, "*MESH_NUMCVFACES", StringComparison.InvariantCultureIgnoreCase)) { colFaces = new Tuple<int, int, int>[parser.ConsumeInt()]; continue; } if (0 == string.Compare(attr, "*MESH_CFACELIST", StringComparison.InvariantCultureIgnoreCase)) { this.ParseColFaceList(parser, colFaces); continue; } if (0 == string.Compare(attr, "*MESH_NORMALS", StringComparison.InvariantCultureIgnoreCase)) { normals = new FaceNormal[faces.Length]; this.ParsNormalList(parser, normals); continue; } if (0 == string.Compare(attr, "*MESH_NUMFACES", StringComparison.InvariantCultureIgnoreCase)) { faces = new AseFace[parser.ConsumeInt()]; continue; } if (0 == string.Compare(attr, "*MESH_FACE_LIST", StringComparison.InvariantCultureIgnoreCase)) { this.ParseFaceList(parser, faces); continue; } parser.UnknownLexemError(); } ListMeshStream<int> positionIndices = null; if (vertices != null) { positionIndices = new ListMeshStream<int>(faces.Length * 3,converterFactory); submesh.SetIndexStream(Streams.Position, 0, positionIndices); } ListMeshStream<int> normalIndices = null; if (normals != null) { normalStream = new ListMeshStream<Float3>(faces.Length * 3, converterFactory); mesh.SetStream(Streams.Normal, 0, normalStream); normalIndices = new ListMeshStream<int>(faces.Length * 3, converterFactory); submesh.SetIndexStream(Streams.Normal, 0, normalIndices); } ListMeshStream<int> colorIndices = null; if (cols != null) { colorIndices = new ListMeshStream<int>(faces.Length * 3, converterFactory); submesh.SetIndexStream(Streams.Color, 0, colorIndices); } ListMeshStream<int> texCoordIndices = null; if (tvertices != null) { texCoordIndices = new ListMeshStream<int>(faces.Length * 3, converterFactory); submesh.SetIndexStream(Streams.TexCoord, 0, texCoordIndices); } for (int i = 0; i < faces.Length; ++i) { // -------------------------------------------------- // if (positionIndices != null) { positionIndices.Add(faces[i].A); } if (normalIndices != null) { normalIndices.Add(normalStream.Count); normalStream.Add(normals[i].A.Normal); } if (colorIndices != null) { colorIndices.Add(colFaces[i].Item1); } if (texCoordIndices != null) { texCoordIndices.Add(tfaces[i].A); } // -------------------------------------------------- // if (positionIndices != null) { positionIndices.Add(faces[i].C); } if (normalIndices != null) { normalIndices.Add(normalStream.Count); normalStream.Add(normals[i].C.Normal); } if (colorIndices != null) { colorIndices.Add(colFaces[i].Item3); } if (texCoordIndices != null) { texCoordIndices.Add(tfaces[i].C); } // -------------------------------------------------- // if (positionIndices != null) { positionIndices.Add(faces[i].B); } if (normalIndices != null) { normalIndices.Add(normalStream.Count); normalStream.Add(normals[i].B.Normal); } if (colorIndices != null) { colorIndices.Add(colFaces[i].Item2); } if (texCoordIndices != null) { texCoordIndices.Add(tfaces[i].B); } // -------------------------------------------------- // } }