/// <summary> /// Initializes a new instance of the <see cref="MODL"/> class. /// </summary> /// <param name="from">The <see cref="BaseChunk" /> to use for creating this Chunk. The given data will be interpreted respectively.</param> public MODL(BaseChunk from) : base(from) { while (!EndOfData) { BaseChunk nextChunk = ReadChunk(); switch (nextChunk.ChunkName) { case "MTYP": Type = (MTYP)nextChunk.ReadInt32(); break; case "MNDX": index = nextChunk.ReadInt32(); break; case "NAME": Name = nextChunk.ReadString(nextChunk.Data.Length); break; case "PRNT": parentName = nextChunk.ReadString(nextChunk.Data.Length); break; case "FLGS": Flag = new ModelFlag(true, nextChunk.ReadInt32()); break; case "TRAN": Scale = nextChunk.ReadVector3(); Rotation = nextChunk.ReadVector3(); Translation = nextChunk.ReadVector3(); UnknownTRAN = nextChunk.ReadFloat(); break; case "GEOM": Geometry = new GEOM(nextChunk); break; } } }
/// <summary> /// Initializes a new instance of the <see cref="HEDR"/> class. /// </summary> /// <param name="from">The <see cref="BaseChunk" /> to use for creating this Chunk. The given data will be interpreted respectively.</param> public HEDR(BaseChunk from) : base(from) { while (!EndOfData) { BaseChunk nextChunk = ReadChunk(); switch (nextChunk.ChunkName) { case "SHVO": Shvo = nextChunk.ReadInt32(); break; case "MSH2": Mesh = new MSH2(nextChunk); break; default: break; } } }
/// <summary> /// Initializes a new instance of the <see cref="MATD"/> class. /// </summary> /// <param name="from">The <see cref="BaseChunk" /> to use for creating this Chunk. The given data will be interpreted respectively.</param> public MATD(BaseChunk from) : base(from) { while (!EndOfData) { BaseChunk nextChunk = ReadChunk(); switch (nextChunk.ChunkName) { case "NAME": Name = nextChunk.ReadString(nextChunk.Data.Length); break; case "DATA": Diffuse = nextChunk.ReadColor(); Ambient = nextChunk.ReadColor(); Specular = nextChunk.ReadColor(); SpecularSharpness = nextChunk.ReadFloat(); break; case "ATRB": attribute = nextChunk.ReadInt32(); break; } //catch texture entrys (usually TX0D) Match txMatch = Regex.Match(nextChunk.ChunkName, "TX[0-9]{1}D"); if (txMatch.Success) { //the number sits at the 3rd position = [2] //the symbol "0" ist at position 48 in the ascii table int index = txMatch.Value[2] - 48; Textures[index] = nextChunk.ReadString(nextChunk.Data.Length); } } }
/// <summary> /// Initializes a new instance of the <see cref="SEGM"/> class. /// </summary> /// <param name="from">The <see cref="BaseChunk" /> to use for creating this Chunk. The given data will be interpreted respectively.</param> public SEGM(BaseChunk from) : base(from) { List <Vector3> verts = new List <Vector3>(); List <Vector3> normals = new List <Vector3>(); List <Vector2> uvs = new List <Vector2>(); Polygon currentPoly = new Polygon(vertices); bool lastBoundry = false; while (!EndOfData) { BaseChunk nextChunk = ReadChunk(); int count = 0; switch (nextChunk.ChunkName) { case "MATI": matIndex = nextChunk.ReadInt32(); break; case "POSL": count = nextChunk.ReadInt32(); for (int i = 0; i < count; i++) { verts.Add(nextChunk.ReadVector3()); } break; case "NRML": count = nextChunk.ReadInt32(); for (int i = 0; i < count; i++) { normals.Add(nextChunk.ReadVector3()); } break; case "UV0L": count = nextChunk.ReadInt32(); for (int i = 0; i < count; i++) { uvs.Add(nextChunk.ReadVector2()); } break; case "STRP": count = nextChunk.ReadInt32(); for (int i = 0; i < count; i++) { VertexIndex next = nextChunk.ReadVertexIndex(); if (next.polyBoundary && !lastBoundry) { //polygon finished, add to buffer if (currentPoly.VertexIndices.Count > 0) { polygons.Add(currentPoly); } //start new polygon currentPoly = new Polygon(vertices); //write first index value to polygon currentPoly.VertexIndices.Add(next.index); } else { if (currentPoly != null) { currentPoly.VertexIndices.Add(next.index); } else { //this should never happen Log.Add("Warning: Lone Vertex in Strip Buffer!", LogType.Warning); } } lastBoundry = next.polyBoundary; } break; } } if (uvs.Count > 0) { hasUVs = true; } for (int i = 0; i < verts.Count; i++) { //since uv coordinates are optional, deliver empty ones if non existent Vector2 uv = (i < uvs.Count) ? uvs[i] : new Vector2(); vertices.Add(new Vertex(verts[i], normals[i], uv)); } //Add last Polygon if (currentPoly != null && currentPoly.VertexIndices.Count > 0) { polygons.Add(currentPoly); } }