Ejemplo n.º 1
0
        public Chunk_DataStream_800 GetTexcoordsChunk()
        {
            Chunk_DataStream_800 dataStreamChunkTexcoords = new Chunk_DataStream_800();

            dataStreamChunkTexcoords.nFlags       = 0;
            dataStreamChunkTexcoords.nStreamType  = 2;
            dataStreamChunkTexcoords.nCount       = nCount;
            dataStreamChunkTexcoords.nElementSize = 8;
            dataStreamChunkTexcoords.reserved[0]  = 0;
            dataStreamChunkTexcoords.reserved[1]  = 0;
            mesh.SerializeTexcoords();
            dataStreamChunkTexcoords.dataStream = mesh.serializedTexcoords;
            return(dataStreamChunkTexcoords);
        }
Ejemplo n.º 2
0
        public Chunk_DataStream_800 GetColorsChunk()
        {
            Chunk_DataStream_800 dataStreamChunkColors = new Chunk_DataStream_800();

            dataStreamChunkColors.nFlags       = 0;
            dataStreamChunkColors.nStreamType  = 3;
            dataStreamChunkColors.nCount       = nCount;
            dataStreamChunkColors.nElementSize = 4;
            dataStreamChunkColors.reserved[0]  = 0;
            dataStreamChunkColors.reserved[1]  = 0;
            mesh.SerializeColors();
            dataStreamChunkColors.dataStream = mesh.serializedColors;
            return(dataStreamChunkColors);
        }
Ejemplo n.º 3
0
        public Chunk_DataStream_800 GetPositionsChunk()
        {
            Chunk_DataStream_800 dataStreamChunkPositions = new Chunk_DataStream_800();

            dataStreamChunkPositions.nFlags       = 0;
            dataStreamChunkPositions.nStreamType  = 0;
            dataStreamChunkPositions.nCount       = nCount;
            dataStreamChunkPositions.nElementSize = 12;
            dataStreamChunkPositions.reserved[0]  = 0;
            dataStreamChunkPositions.reserved[1]  = 0;
            mesh.SerializePositions();
            dataStreamChunkPositions.dataStream = mesh.serializedPositions;
            return(dataStreamChunkPositions);
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
        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);
        }