DataStream_p3s_c4b_t2s Fix_p3s_c4b_t2s(DataStream_p3s_c4b_t2s p3s_c4b_t2s, Vector3 bboxMin, Vector3 bboxMax) { for (int i = 0; i < p3s_c4b_t2s.p3s_c4b_t2sElem.Count; i++) { float multiplerX = Math.Abs(bboxMin.X - bboxMax.X) / 2f; float multiplerY = Math.Abs(bboxMin.Y - bboxMax.Y) / 2f; float multiplerZ = Math.Abs(bboxMin.Z - bboxMax.Z) / 2f; if (multiplerX < 1) { multiplerX = 1; } if (multiplerY < 1) { multiplerY = 1; } if (multiplerZ < 1) { multiplerZ = 1; } short shortPosX = Utils.EvilConverter.Convert(p3s_c4b_t2s.p3s_c4b_t2sElem[i].pos[0]); short shortPosY = Utils.EvilConverter.Convert(p3s_c4b_t2s.p3s_c4b_t2sElem[i].pos[1]); short shortPosZ = Utils.EvilConverter.Convert(p3s_c4b_t2s.p3s_c4b_t2sElem[i].pos[2]); short shortPosW = Utils.EvilConverter.Convert(p3s_c4b_t2s.p3s_c4b_t2sElem[i].pos[3]); p3s_c4b_t2s.p3s_c4b_t2sElem[i].pos[0] = HalfHelper.SingleToHalf(Utils.tPackB2F(shortPosX) * multiplerX + (bboxMax.X + bboxMin.X) / 2).value; p3s_c4b_t2s.p3s_c4b_t2sElem[i].pos[1] = HalfHelper.SingleToHalf(Utils.tPackB2F(shortPosY) * multiplerY + (bboxMax.Y + bboxMin.Y) / 2).value; p3s_c4b_t2s.p3s_c4b_t2sElem[i].pos[2] = HalfHelper.SingleToHalf(Utils.tPackB2F(shortPosZ) * multiplerZ + (bboxMax.Z + bboxMin.Z) / 2).value; p3s_c4b_t2s.p3s_c4b_t2sElem[i].pos[3] = HalfHelper.SingleToHalf(Utils.tPackB2F(shortPosW)).value; } return(p3s_c4b_t2s); }
public void LoadFrom_p3s_c4b_t2s(DataStream_p3s_c4b_t2s p3s_c4b_t2sList) { mesh = new Mesh(nCount); foreach (DataStream_p3s_c4b_t2s_Elem p3s_c4b_t2s in p3s_c4b_t2sList.p3s_c4b_t2sElem) { DataStream_Positions_Elem position = new DataStream_Positions_Elem(); for (int i = 0; i < 3; i++) { Half halfEl = new Half(); halfEl.value = p3s_c4b_t2s.pos[i]; position.pos[i] = HalfHelper.HalfToSingle(halfEl); } mesh.positions.position.Add(position); DataStream_Colors_Elem color = new DataStream_Colors_Elem(); for (int i = 0; i < 4; i++) { color.rgba[i] = p3s_c4b_t2s.bgra[i]; } mesh.colors.color.Add(color); DataStream_Texcoords_Elem texoord = new DataStream_Texcoords_Elem(); for (int i = 0; i < 2; i++) { Half halfEl = new Half(); halfEl.value = p3s_c4b_t2s.uv[i]; texoord.uv[i] = HalfHelper.HalfToSingle(halfEl); } mesh.texcoords.texcoord.Add(texoord); } }
DataStream_p3s_c4b_t2s Fix_p3f_c4b_t2s(DataStream_p3f_c4b_t2s p3f_c4b_t2s) { DataStream_p3s_c4b_t2s p3s_c4b_t2s = new DataStream_p3s_c4b_t2s(); for (int i = 0; i < p3f_c4b_t2s.p3f_c4b_t2sElem.Count; i++) { DataStream_p3s_c4b_t2s_Elem elem = new DataStream_p3s_c4b_t2s_Elem(); elem.bgra = p3f_c4b_t2s.p3f_c4b_t2sElem[i].bgra; elem.uv = p3f_c4b_t2s.p3f_c4b_t2sElem[i].uv; elem.pos[0] = HalfHelper.SingleToHalf(p3f_c4b_t2s.p3f_c4b_t2sElem[i].pos[0]).value; elem.pos[1] = HalfHelper.SingleToHalf(p3f_c4b_t2s.p3f_c4b_t2sElem[i].pos[1]).value; elem.pos[2] = HalfHelper.SingleToHalf(p3f_c4b_t2s.p3f_c4b_t2sElem[i].pos[2]).value; elem.pos[3] = HalfHelper.SingleToHalf(1.0f).value; p3s_c4b_t2s.p3s_c4b_t2sElem.Add(elem); } return(p3s_c4b_t2s); }
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; }
File_ChCr_746 FixMeshes(File_ChCr_746 chCrFile) { Console.WriteLine(chCrFile.filePath); //fix mesh for (int i = 0; i < chCrFile.chunks.Count; i++) { if (chCrFile.chunks[i].type == 0x00001000) { Chunk_Mesh_801 chunkMesh = new Chunk_Mesh_801(chCrFile.chunks[i].content); //fix p3s_c4b_t2s int p3s_c4b_t2s_ChunkID = chunkMesh.Get_p3s_c4b_t2s_ChunkID(); if (p3s_c4b_t2s_ChunkID != 0) { Console.Write("."); Chunk_DataStream_800 dataStreamChunk = new Chunk_DataStream_800(chCrFile.GetChunkById((uint)p3s_c4b_t2s_ChunkID).content); if (dataStreamChunk.nElementSize == 16) { DataStream_p3s_c4b_t2s p3s_c4b_t2sDataStream = new DataStream_p3s_c4b_t2s(dataStreamChunk.nCount, dataStreamChunk.dataStream); p3s_c4b_t2sDataStream = Fix_p3s_c4b_t2s(p3s_c4b_t2sDataStream, chunkMesh.GetBboxMin(), chunkMesh.GetBboxMax()); p3s_c4b_t2sDataStream.Serialize(); dataStreamChunk.dataStream = p3s_c4b_t2sDataStream.serialized; dataStreamChunk.Serialize(); for (int j = 0; j < chCrFile.chunks.Count; j++) { if (chCrFile.chunks[j].chunkId == (uint)p3s_c4b_t2s_ChunkID) { chCrFile.chunks[j].content = dataStreamChunk.serialized; } } } //skins since alpha 3.1 use p3f_c4b_t2s if (dataStreamChunk.nElementSize == 20) { DataStream_p3f_c4b_t2s p3f_c4b_t2sDataStream = new DataStream_p3f_c4b_t2s(dataStreamChunk.nCount, dataStreamChunk.dataStream); DataStream_p3s_c4b_t2s p3s_c4b_t2sDataStream = new DataStream_p3s_c4b_t2s(); p3s_c4b_t2sDataStream = Fix_p3f_c4b_t2s(p3f_c4b_t2sDataStream); p3s_c4b_t2sDataStream.Serialize(); dataStreamChunk.dataStream = p3s_c4b_t2sDataStream.serialized; dataStreamChunk.nElementSize = p3s_c4b_t2sDataStream.GetElementSize(); dataStreamChunk.Serialize(); for (int j = 0; j < chCrFile.chunks.Count; j++) { if (chCrFile.chunks[j].chunkId == (uint)p3s_c4b_t2s_ChunkID) { chCrFile.chunks[j].content = dataStreamChunk.serialized; chCrFile.chunks[j].size = dataStreamChunk.GetSize(); } } } //fix tangents int tangents_ChunkID = chunkMesh.GetTangentsChunkID(); if (tangents_ChunkID != 0) { Console.Write("."); dataStreamChunk = new Chunk_DataStream_800(chCrFile.GetChunkById((uint)tangents_ChunkID).content); DataStream_Tangents_SC tangentsDataStream_SC = new DataStream_Tangents_SC(dataStreamChunk.nCount, dataStreamChunk.dataStream); DataStream_Tangents tangentsDataStream = new DataStream_Tangents(); tangentsDataStream = FixTangents(tangentsDataStream_SC); tangentsDataStream.Serialize(); dataStreamChunk.dataStream = tangentsDataStream.serialized; dataStreamChunk.nElementSize = tangentsDataStream.GetElementSize(); dataStreamChunk.Serialize(); for (int j = 0; j < chCrFile.chunks.Count; j++) { if (chCrFile.chunks[j].chunkId == (uint)tangents_ChunkID) { chCrFile.chunks[j].content = dataStreamChunk.serialized; chCrFile.chunks[j].size = dataStreamChunk.GetSize(); } } } //erase normals chunkMesh.nStreamChunkID[1] = 0; } chunkMesh.Serialize(); chCrFile.chunks[i].content = chunkMesh.serialized; } } //fix datastreams chunks elemsizes for (int i = 0; i < chCrFile.chunks.Count; i++) { if (chCrFile.chunks[i].type == 0x00001016) { Chunk_DataStream_800 dataStreamChunk = new Chunk_DataStream_800(chCrFile.chunks[i].content); dataStreamChunk.Serialize(); chCrFile.chunks[i].content = dataStreamChunk.serialized; } } Console.WriteLine(); chCrFile.RecalculateChunksPositions(); return(chCrFile); }
public MeshRecompiler(uint vertsCount, DataStream_p3s_c4b_t2s p3s_c4b_t2s) { nCount = vertsCount; LoadFrom_p3s_c4b_t2s(p3s_c4b_t2s); }