private Ms3dTri[] ReadMs3dTris(BinaryReader r) { UInt16 numTris = r.ReadUInt16(); Ms3dTri[] tris = new Ms3dTri[numTris]; for (int i = 0; i < numTris; i++) { tris[i] = readMs3dTri(r); } return(tris); }
// Data munging for fun and profit! private void Ms3dTris2Tris(Ms3dTri[] tris, out Tri[] t, out Vector3[] norms, out Vector2[] texs) { Tri[] ts = new Tri[tris.Length]; // Utter utter BS. for (int i = 0; i < ts.Length; i++) { ts[i] = new Tri(); } List<Vector3> normals = new List<Vector3>(); List<Vector2> texcoords = new List<Vector2>(); for (int i = 0; i < tris.Length; i++) { ts[i].P1.Vertex = tris[i].Verts[0]; ts[i].P2.Vertex = tris[i].Verts[1]; ts[i].P3.Vertex = tris[i].Verts[2]; normals.Add(tris[i].Normals[0]); normals.Add(tris[i].Normals[1]); normals.Add(tris[i].Normals[2]); ts[i].P1.Normal = 3 * i; ts[i].P2.Normal = 3 * i + 1; ts[i].P3.Normal = 3 * i + 2; texcoords.Add(tris[i].TexCoords[0]); texcoords.Add(tris[i].TexCoords[1]); texcoords.Add(tris[i].TexCoords[2]); ts[i].P1.TexCoord = 3 * i; ts[i].P2.TexCoord = 3 * i + 1; ts[i].P3.TexCoord = 3 * i + 2; } t = ts; norms = normals.ToArray(); texs = texcoords.ToArray(); }
private Ms3dTri readMs3dTri(BinaryReader r) { Ms3dTri t = new Ms3dTri(); r.ReadUInt16(); // Ignore flags // Vertex indices t.Verts[0] = (int)r.ReadUInt16(); t.Verts[1] = (int)r.ReadUInt16(); t.Verts[2] = (int)r.ReadUInt16(); // Vertex normals t.Normals[0].X = r.ReadSingle(); t.Normals[0].Y = r.ReadSingle(); t.Normals[0].Z = r.ReadSingle(); t.Normals[1].X = r.ReadSingle(); t.Normals[1].Y = r.ReadSingle(); t.Normals[1].Z = r.ReadSingle(); t.Normals[2].X = r.ReadSingle(); t.Normals[2].Y = r.ReadSingle(); t.Normals[2].Z = r.ReadSingle(); // Vertex texcoords t.TexCoords[0].X = r.ReadSingle(); t.TexCoords[1].X = r.ReadSingle(); t.TexCoords[2].X = r.ReadSingle(); t.TexCoords[0].Y = 1 - r.ReadSingle(); t.TexCoords[1].Y = 1 - r.ReadSingle(); t.TexCoords[2].Y = 1 - r.ReadSingle(); r.ReadByte(); // Ignore smoothingGroup r.ReadByte(); // Ignore groupIndex return(t); }
private Ms3dTri[] ReadMs3dTris(BinaryReader r) { UInt16 numTris = r.ReadUInt16(); Ms3dTri[] tris = new Ms3dTri[numTris]; for (int i = 0; i < numTris; i++) { tris[i] = readMs3dTri(r); } return tris; }
private Ms3dTri readMs3dTri(BinaryReader r) { Ms3dTri t = new Ms3dTri(); r.ReadUInt16(); // Ignore flags // Vertex indices t.Verts[0] = (int)r.ReadUInt16(); t.Verts[1] = (int)r.ReadUInt16(); t.Verts[2] = (int)r.ReadUInt16(); // Vertex normals t.Normals[0].X = r.ReadSingle(); t.Normals[0].Y = r.ReadSingle(); t.Normals[0].Z = r.ReadSingle(); t.Normals[1].X = r.ReadSingle(); t.Normals[1].Y = r.ReadSingle(); t.Normals[1].Z = r.ReadSingle(); t.Normals[2].X = r.ReadSingle(); t.Normals[2].Y = r.ReadSingle(); t.Normals[2].Z = r.ReadSingle(); // Vertex texcoords t.TexCoords[0].X = r.ReadSingle(); t.TexCoords[1].X = r.ReadSingle(); t.TexCoords[2].X = r.ReadSingle(); t.TexCoords[0].Y = 1 - r.ReadSingle(); t.TexCoords[1].Y = 1 - r.ReadSingle(); t.TexCoords[2].Y = 1 - r.ReadSingle(); r.ReadByte(); // Ignore smoothingGroup r.ReadByte(); // Ignore groupIndex return t; }