protected virtual void ReadOctLeaf(BinaryReader reader, List <TreePolygon> treePolygons, Mesh xMesh, List <TRLMaterial> materials) { UInt32 uNextStrip = _dataStart + reader.ReadUInt32(); reader.BaseStream.Position = uNextStrip; int counter = 0; while (true) { bool bShouldWrite = true; // For debug. UInt32 uIndexCount = reader.ReadUInt32(); counter++; reader.BaseStream.Position = uNextStrip + 0x2C; UInt16[] axStripIndices = new UInt16[uIndexCount]; for (UInt32 i = 0; i < uIndexCount; i++) { axStripIndices[i] = reader.ReadUInt16(); } reader.BaseStream.Position = uNextStrip + 0x14; UInt32 materialID = reader.ReadUInt32(); if (bShouldWrite) { UInt16 i = 0; while (i < uIndexCount) { TreePolygon newPolygon = new TreePolygon(); TRLMaterial trlMaterial = materials[(int)materialID]; newPolygon.v1 = axStripIndices[i++]; newPolygon.v2 = axStripIndices[i++]; newPolygon.v3 = axStripIndices[i++]; newPolygon.textureID = trlMaterial.textureID; newPolygon.vbBaseOffset = trlMaterial.vbBaseOffset; treePolygons.Add(newPolygon); } if (xMesh != null) { xMesh.indexCount += uIndexCount; } } reader.BaseStream.Position = uNextStrip + 0x28; uNextStrip = reader.ReadUInt32(); if (uNextStrip == 0 || uIndexCount == 0) { break; } reader.BaseStream.Position = uNextStrip; } }
protected virtual void ReadOctLeaf(BinaryReader xReader, List <TreePolygon> treePolygons, Mesh xMesh, UInt32 uStartIndex) { UInt32 uNextStrip = _dataStart + xReader.ReadUInt32(); xReader.BaseStream.Position = uNextStrip; int counter = 0; while (true) { bool bShouldWrite = true; // For debug. UInt32 uLength = xReader.ReadUInt32(); if (uLength == 0 || uLength == 0xFFFFFFFF) { break; } counter++; uNextStrip += uLength; xReader.BaseStream.Position += 0x04; UInt32 uIndexCount = xReader.ReadUInt32(); if (uIndexCount == 0) { continue; } UInt16[] axStripIndices = new UInt16[uIndexCount]; for (UInt32 i = 0; i < uIndexCount; i++) { axStripIndices[i] = xReader.ReadUInt16(); } if (xReader.BaseStream.Position % 4 != 0) { xReader.BaseStream.Position += 0x02; } // Did I do this for a reason? Should this be an 'if'? while (counter == 5) { // 0xFFFF wrong? Try uTestNextStrip UInt32 uIndexCount2 = xReader.ReadUInt32(); if (/*(uIndexCount2 & 0x0000FFFF) == 0x0000FFFF || (uIndexCount2 & 0xFFFF0000) == 0xFFFF0000 ||*/ uIndexCount2 == 0) { //if (xReader.BaseStream.Position % 4 != 0) //{ // xReader.BaseStream.Position += 0x02; //} break; } xReader.BaseStream.Position += 0x04; UInt32 uTextureID = xReader.ReadUInt32(); xReader.BaseStream.Position += 0x08; UInt32 uTestNextStrip = xReader.ReadUInt32(); UInt16[] axStripIndices2 = new UInt16[uIndexCount2]; for (UInt32 i = 0; i < uIndexCount2; i++) { axStripIndices2[i] = xReader.ReadUInt16(); } if (bShouldWrite) { UInt16 i = 0; while (i < uIndexCount2) { TreePolygon newPolygon = new TreePolygon(); newPolygon.v1 = axStripIndices[axStripIndices2[i++]]; newPolygon.v2 = axStripIndices[axStripIndices2[i++]]; newPolygon.v3 = axStripIndices[axStripIndices2[i++]]; newPolygon.textureID = uTextureID; newPolygon.useExtraGeometry = true; treePolygons.Add(newPolygon); } if (xMesh != null) { xMesh.indexCount += uIndexCount2; } } xReader.BaseStream.Position = uTestNextStrip; } xReader.BaseStream.Position = uNextStrip; } // Was this a special second set of polys? Animated ones? while (true) { bool bShouldWrite = true; // For debug. UInt32 uIndexCount = xReader.ReadUInt32(); if (uIndexCount == 0) { break; } xReader.BaseStream.Position += 0x04; UInt32 uTextureID = xReader.ReadUInt32(); xReader.BaseStream.Position += 0x08; uNextStrip = xReader.ReadUInt32(); UInt16[] axStripIndices = new UInt16[uIndexCount]; for (UInt32 i = 0; i < uIndexCount; i++) { axStripIndices[i] = xReader.ReadUInt16(); } if (bShouldWrite) { UInt16 i = 0; while (i < uIndexCount) { TreePolygon newPolygon = new TreePolygon(); newPolygon.v1 = axStripIndices[i++]; newPolygon.v2 = axStripIndices[i++]; newPolygon.v3 = axStripIndices[i++]; newPolygon.textureID = uTextureID; treePolygons.Add(newPolygon); } if (xMesh != null) { xMesh.indexCount += uIndexCount; } } xReader.BaseStream.Position = uNextStrip; } }
protected virtual void ReadOctLeaf(BinaryReader reader, List <TreePolygon> treePolygons, Mesh xMesh, UInt32 uStartIndex) { UInt32 uLeafData = _dataStart + reader.ReadUInt32(); reader.BaseStream.Position = uLeafData; UInt32 uNextStrip = (UInt32)reader.BaseStream.Position; while (true) { bool bShouldWrite = true; // For debug. UInt32 uLength = reader.ReadUInt32(); if (uLength == 0 || uLength == 0xFFFFFFFF) { break; } uNextStrip += uLength; UInt32 uIndexCount = reader.ReadUInt32(); if (uIndexCount == 0) { continue; } UInt16[] axStripIndices = new UInt16[uIndexCount]; for (UInt32 i = 0; i < uIndexCount; i++) { axStripIndices[i] = reader.ReadUInt16(); } if (reader.BaseStream.Position % 4 != 0) { reader.BaseStream.Position += 0x02; } while (true) { // 0xFFFF wrong? Try uTestNextStrip UInt32 uIndexCount2 = reader.ReadUInt32(); if (/*(uIndexCount2 & 0x0000FFFF) == 0x0000FFFF || (uIndexCount2 & 0xFFFF0000) == 0xFFFF0000 ||*/ uIndexCount2 == 0) { //if (reader.BaseStream.Position % 4 != 0) //{ // reader.BaseStream.Position += 0x02; //} break; } reader.BaseStream.Position += 0x04; UInt32 uTextureID = reader.ReadUInt32(); reader.BaseStream.Position += 0x04; UInt32 uTestNextStrip = reader.ReadUInt32(); UInt16[] axStripIndices2 = new UInt16[uIndexCount2]; for (UInt32 i = 0; i < uIndexCount2; i++) { axStripIndices2[i] = reader.ReadUInt16(); } if (bShouldWrite) { UInt16 i = 0; while (i < uIndexCount2) { TreePolygon newPolygon = new TreePolygon(); newPolygon.v1 = axStripIndices[axStripIndices2[i++]]; newPolygon.v2 = axStripIndices[axStripIndices2[i++]]; newPolygon.v3 = axStripIndices[axStripIndices2[i++]]; newPolygon.textureID = uTextureID; treePolygons.Add(newPolygon); } if (xMesh != null) { xMesh.indexCount += uIndexCount2; } } reader.BaseStream.Position = uTestNextStrip; } reader.BaseStream.Position = uNextStrip; } // Was this a special second set of polys? Animated ones? while (true) { bool bShouldWrite = true; // For debug. UInt32 uIndexCount = reader.ReadUInt32(); if (uIndexCount == 0) { break; } reader.BaseStream.Position += 0x04; UInt32 uTextureID = reader.ReadUInt32(); reader.BaseStream.Position += 0x04; uNextStrip = reader.ReadUInt32(); UInt16[] axStripIndices = new UInt16[uIndexCount]; for (UInt32 i = 0; i < uIndexCount; i++) { axStripIndices[i] = reader.ReadUInt16(); } if (bShouldWrite) { UInt16 i = 0; while (i < uIndexCount) { TreePolygon newPolygon = new TreePolygon(); newPolygon.v1 = axStripIndices[i++]; newPolygon.v2 = axStripIndices[i++]; newPolygon.v3 = axStripIndices[i++]; newPolygon.textureID = uTextureID; treePolygons.Add(newPolygon); } if (xMesh != null) { xMesh.indexCount += uIndexCount; } } reader.BaseStream.Position = uNextStrip; } }