void Merge() { RecalculateSecondFileChunksIds(primaryFile.GetMaxId()); MergeNodes(); for (int i = 0; i < secondaryFile.chunkCount; i++) { primaryFile.chunks.Add(secondaryFile.chunks[i]); primaryFile.chunkCount++; } primaryFile.RecalculateChunksPositions(); mergedFile = primaryFile; }
void RecompileMeshes() { File_ChCr_746 newFile = mergedFile; for (int i = 0; i < mergedFile.chunkCount; i++) { //find mesh compiled with p3s_c4b_t2s, nStreamChunkID [15]!=0 if (mergedFile.chunks[i].type == 0x00001000) { Chunk_Mesh_801 mergedFileMeshChunk = new Chunk_Mesh_801(mergedFile.chunks[i].content); if (mergedFileMeshChunk.nStreamChunkID[15] != 0) { uint p3s_c4b_t2sChunkId = mergedFileMeshChunk.nStreamChunkID[15]; uint maxChunkId = newFile.GetMaxId(); maxChunkId++; Chunk p3s_c4b_t2sChunk = mergedFile.GetChunkById(mergedFileMeshChunk.nStreamChunkID[15]); Chunk_DataStream_800 p3s_c4b_t2sDataStreamChunk = new Chunk_DataStream_800(p3s_c4b_t2sChunk.content); DataStream_p3s_c4b_t2s p3s_c4b_t2sDataStream = new DataStream_p3s_c4b_t2s(p3s_c4b_t2sDataStreamChunk.nCount, p3s_c4b_t2sDataStreamChunk.dataStream); MeshRecompiler meshRecompiler = new MeshRecompiler(p3s_c4b_t2sDataStreamChunk.nCount, p3s_c4b_t2sDataStream); Chunk_DataStream_800 positionsDataStreamChunk = meshRecompiler.GetPositionsChunk(); Chunk_DataStream_800 texoordDataStreamChunk = meshRecompiler.GetTexcoordsChunk(); Chunk_DataStream_800 colorsDataStreamChunk = meshRecompiler.GetColorsChunk(); positionsDataStreamChunk.Serialize(); Chunk positionsChunk = new Chunk(); positionsChunk.type = 0x00001016; positionsChunk.version = 0x00000800; positionsChunk.chunkId = maxChunkId; positionsChunk.size = positionsDataStreamChunk.GetSize(); positionsChunk.content = positionsDataStreamChunk.serialized; maxChunkId++; texoordDataStreamChunk.Serialize(); Chunk texcoordsChunk = new Chunk(); texcoordsChunk.type = 0x00001016; texcoordsChunk.version = 0x00000800; texcoordsChunk.chunkId = maxChunkId; texcoordsChunk.size = texoordDataStreamChunk.GetSize(); texcoordsChunk.content = texoordDataStreamChunk.serialized; maxChunkId++; colorsDataStreamChunk.Serialize(); Chunk colorsChunk = new Chunk(); colorsChunk.type = 0x00001016; colorsChunk.version = 0x00000800; colorsChunk.chunkId = maxChunkId; colorsChunk.size = colorsDataStreamChunk.GetSize(); colorsChunk.content = colorsDataStreamChunk.serialized; maxChunkId++; newFile.chunks.Add(positionsChunk); newFile.chunkCount++; newFile.chunks.Add(texcoordsChunk); newFile.chunkCount++; newFile.chunks.Add(colorsChunk); newFile.chunkCount++; Chunk_Mesh_801 newFileMeshChunk = mergedFileMeshChunk; newFileMeshChunk.nStreamChunkID[1] = 0; newFileMeshChunk.nStreamChunkID[15] = 0; newFileMeshChunk.nStreamChunkID[0] = positionsChunk.chunkId; newFileMeshChunk.nStreamChunkID[2] = texcoordsChunk.chunkId; newFileMeshChunk.nStreamChunkID[3] = colorsChunk.chunkId; newFileMeshChunk.Serialize(); newFile.chunks[i].content = newFileMeshChunk.serialized; } } } newFile.RecalculateChunksPositions(); mergedFile = newFile; }