public Chunk_MONR(WMOFile file) : base(file, "MONR", Magic) { int normalCount = (int)ChunkSize / 12; normals = new Position[normalCount]; for (int i = 0; i < normalCount; i++) { float x = file.readFloat(); float z = file.readFloat() * -1; float y = file.readFloat(); normals[i] = new Position(x, y, z); } LogWrite("Loaded " + normalCount + " normals."); }
public Chunk_MOVT(WMOFile file) : base(file, "MOVT", Magic) { int vertCount = (int)ChunkSize / 12; vertices = new Position[vertCount]; for (int i = 0; i < vertCount; i++) { float x = file.readFloat(); float z = file.readFloat() * -1; float y = file.readFloat(); vertices[i] = new Position(x, y, z); } LogWrite("Loaded " + vertCount + " verticies."); }
public Chunk_MCNR(ADTFile file) : base(file, "MCNR", Magic) { normals = new Position[145]; for (int i = 0; i < 145; i++) { float x = file.readUInt8() / 127; float z = file.readUInt8() / 127; float y = file.readUInt8() / 127; // Super-hacky fix? This does not seem right, but it prevents lighting issues? if (y == 1.0 && z == 0.0) { z = 1.0f; y = 0.0f; } normals[i] = new Position(x, y, z); } }
public Vert(Position point, UV uv = null, int offset = -1) { Point = point; UV = uv; Offset = offset; }
public void addVert(Position vert) { Verts.Add(vert); }
public void addNormal(Position normal) { Normals.Add(normal); }
public override void parse() { Log.Write("Parsing model file {0} with skin {1}...", BaseName, skin.BaseName); skin.parse(); // Parse the given skin file. int ofs = 0; uint magic = readUInt32(); if (!magic.Equals(MD20_MAGIC)) // Assume Legion+ chunked format, relate offset to chunk. { seekPosition(0); // Go back to the start. while (!isEndOfStream() && !isOutOfBounds(seek + 8)) { uint chunkID = readUInt32(); uint chunkSize = readUInt32(); if (chunkID == MD21_MAGIC) { ofs = seek; break; } else { skip((int)chunkSize); } } if (ofs == 0) throw new M2Exception("Unable to find MD20 chunk inside MD21 file! Format evolved?"); } // Start reading as MD20 seekPosition(ofs); // Seek the beginning of the MD20 data. magic = readUInt32(); if (magic != MD20_MAGIC) throw new M2Exception(string.Format("Data is not MD20 at {0}", ofs)); /* * 274+ Legion * ? - ? Warlords of Draenor * 273 Mists of Pandaria * 265-272 Cataclysm * 264 Wrath of the Lich King * 260-263 The Burning Crusade * ?-256 World of Warcraft */ Version = readUInt32(); int iName = (int)readUInt32(); // Contains trailing 0-byte. int ofsName = (int)readUInt32(); Flags = readUInt32(); int nGlobalSeq = (int)readUInt32(); int ofsGlobalSeq = (int)readUInt32(); int nAnims = (int)readUInt32(); int ofsAnims = (int)readUInt32(); int nAnimLookup = (int)readUInt32(); int ofsAnimLookup = (int)readUInt32(); int nBones = (int)readUInt32(); int ofsBones = (int)readUInt32(); int nKeyBoneLookup = (int)readUInt32(); int ofsKeyBoneLookup = (int)readUInt32(); int nVerts = (int)readUInt32(); int ofsVerts = (int)readUInt32(); seekPosition(ofs + ofsName); Name = readString(iName - 1); // Verts Verts = new Position[nVerts]; Normals = new Position[nVerts]; UV1 = new UV[nVerts]; UV2 = new UV[nVerts]; seekPosition(ofs + ofsVerts); for (int i = 0; i < nVerts; i++) { float x = readFloat(); float z = readFloat() * - 1; float y = readFloat(); Verts[i] = new Position(x, y, z); uint boneWeight = readUInt32(); // 4 * byte uint boneIndices = readUInt32(); // 4 * byte Normals[i] = Position.Read(this); UV1[i] = UV.Read(this); UV2[i] = UV.Read(this); } }