Example #1
0
            /// <summary>
            /// Initializes a new instance of the <see cref="PRTMRawDataMetaChunk"/> class.
            /// </summary>
            /// <param name="meta">The meta.</param>
            /// <remarks></remarks>
            public PRTMRawDataMetaChunk(ref Meta meta)
            {
                BinaryReader BR = new BinaryReader(meta.MS);

                BR.BaseStream.Position = 176;
                int tempc = BR.ReadInt32();
                int tempr = BR.ReadInt32() - meta.Map.SecondaryMagic - meta.offset;
                RawDataChunkInfo = new RawDataOffsetChunk[tempc];
                for (int x = 0; x < tempc; x++)
                {
                    RawDataChunkInfo[x] = new RawDataOffsetChunk();
                    BR.BaseStream.Position = tempr + (x * 16) + 6;
                    RawDataChunkInfo[x].ChunkSize = 56;
                    RawDataChunkInfo[x].Size = BR.ReadInt32();
                    if (RawDataChunkInfo[x].ChunkSize == 0)
                    {
                        RawDataChunkInfo[x].ChunkSize = RawDataChunkInfo[x].Size;
                    }

                    RawDataChunkInfo[x].Offset = BR.ReadInt32();
                    RawDataChunkInfo[x].ChunkCount = RawDataChunkInfo[x].Size / RawDataChunkInfo[x].ChunkSize;
                }

                BR.BaseStream.Position = 136;
                VerticeCount = BR.ReadInt32();
                tempr = BR.ReadInt32() - meta.Map.SecondaryMagic - meta.offset;
                BR.BaseStream.Position = tempr;
                for (int x = 0; x < VerticeCount; x++)
                {
                    Vector3 vec = new Vector3();

                    vec.X = BR.ReadSingle();
                    vec.Y = BR.ReadSingle();
                    vec.Z = BR.ReadSingle();
                    Vertices.Add(vec);

                    Vector3 vec2 = new Vector3();
                    vec2.X = BR.ReadSingle();
                    vec2.Y = BR.ReadSingle();
                    vec2.Z = BR.ReadSingle();
                    Normals.Add(vec2);

                    Vector3 vec3 = new Vector3();
                    vec3.X = BR.ReadSingle();
                    vec3.Y = BR.ReadSingle();
                    vec3.Z = BR.ReadSingle();
                    Binormals.Add(vec3);

                    Vector3 vec4 = new Vector3();
                    vec4.X = BR.ReadSingle();
                    vec4.Y = BR.ReadSingle();
                    vec4.Z = BR.ReadSingle();
                    Tangents.Add(vec4);

                    Vector2 vec5 = new Vector2();
                    vec5.X = BR.ReadSingle();
                    vec5.Y = BR.ReadSingle();

                    UVs.Add(vec5);
                }

                BR.BaseStream.Position = 168;
                HeaderSize = BR.ReadInt32() + 8;

                BR.BaseStream.Position = 144;
                IndiceCount = BR.ReadInt32();
                tempr = BR.ReadInt32() - meta.Map.SecondaryMagic - meta.offset;
                BR.BaseStream.Position = tempr;
                FaceCount = IndiceCount / 3;

                this.Indices = new short[IndiceCount];
                for (int x = 0; x < IndiceCount; x++)
                {
                    Indices[x] = (short)BR.ReadUInt16();
                }

                SubMeshInfo = new ModelSubMeshInfo[1];
                for (int x = 0; x < 1; x++)
                {
                    SubMeshInfo[x] = new ModelSubMeshInfo();
                    BR.BaseStream.Position = HeaderSize + RawDataChunkInfo[0].Offset + (x * 72) + 4;
                    SubMeshInfo[x].ShaderNumber = 0;
                    SubMeshInfo[x].IndiceStart = 0;
                    SubMeshInfo[x].IndiceCount = IndiceCount;
                }
            }
Example #2
0
            /// <summary>
            /// Initializes a new instance of the <see cref="RawDataMetaChunk"/> class.
            /// </summary>
            /// <param name="offset">The offset.</param>
            /// <param name="chunknumber">The chunknumber.</param>
            /// <param name="bb">The bb.</param>
            /// <param name="meta">The meta.</param>
            /// <remarks></remarks>
            public RawDataMetaChunk(int offset, int chunknumber, BoundingBoxContainer bb, ref Meta meta)
            {
                BinaryReader BR = new BinaryReader(meta.MS);
                BR.BaseStream.Position = offset + 4;
                VerticeCount = BR.ReadUInt16();
                FaceCount = BR.ReadUInt16();
                BR.BaseStream.Position = offset + 20;
                type = BR.ReadByte();
                BR.BaseStream.Position = offset + 68;
                HeaderSize = meta.raw.rawChunks[chunknumber].size - BR.ReadInt32() - 4;
                int tempc = BR.ReadInt32();
                int tempr = BR.ReadInt32() - meta.magic - meta.offset;
                RawDataChunkInfo = new RawDataOffsetChunk[tempc];
                for (int x = 0; x < tempc; x++)
                {
                    RawDataChunkInfo[x] = new RawDataOffsetChunk();
                    BR.BaseStream.Position = tempr + (x * 16) + 6;
                    RawDataChunkInfo[x].ChunkSize = BR.ReadUInt16();
                    RawDataChunkInfo[x].Size = BR.ReadInt32();
                    if (RawDataChunkInfo[x].ChunkSize == 0)
                    {
                        RawDataChunkInfo[x].ChunkSize = RawDataChunkInfo[x].Size;
                    }

                    RawDataChunkInfo[x].Offset = BR.ReadInt32();
                    RawDataChunkInfo[x].ChunkCount = RawDataChunkInfo[x].Size / RawDataChunkInfo[x].ChunkSize;
                }

                BR = new BinaryReader(meta.raw.rawChunks[chunknumber].MS);
                SubMeshInfo = new ModelSubMeshInfo[RawDataChunkInfo[0].ChunkCount];
                for (int x = 0; x < RawDataChunkInfo[0].ChunkCount; x++)
                {
                    SubMeshInfo[x] = new ModelSubMeshInfo();
                    BR.BaseStream.Position = HeaderSize + RawDataChunkInfo[0].Offset + (x * 72) + 4;
                    SubMeshInfo[x].ShaderNumber = BR.ReadUInt16();
                    SubMeshInfo[x].IndiceStart = BR.ReadUInt16();
                    SubMeshInfo[x].IndiceCount = BR.ReadUInt16();
                }

                BR.BaseStream.Position = 40;
                IndiceCount = BR.ReadUInt16();

                int indicechunk = 0;
                int verticechunk = 0;
                int uvchunk = 0;

                for (int x = 0; x < RawDataChunkInfo.Length; x++)
                {
                    if (RawDataChunkInfo[x].ChunkSize == 2)
                    {
                        indicechunk = x;
                        verticechunk = x + 2;
                        uvchunk = x + 3;
                        break;
                    }
                }

                int bonemapchunk = 0;
                BR.BaseStream.Position = 108;
                int tempbonemapcount = BR.ReadUInt16();
                if (tempbonemapcount > 0)
                {
                    for (int x = uvchunk + 1; x < RawDataChunkInfo.Length; x++)
                    {
                        if (RawDataChunkInfo[x].ChunkSize == 1)
                        {
                            bonemapchunk = x;
                            break;
                        }
                    }

                    BR.BaseStream.Position = HeaderSize + RawDataChunkInfo[bonemapchunk].Offset;
                    for (int x = 0; x < tempbonemapcount; x++)
                    {
                        BoneMap.Add(BR.ReadByte());
                    }
                }
                else
                {
                    BoneMap.Add(0);
                }

                RawDataChunkInfo[verticechunk].ChunkSize = RawDataChunkInfo[verticechunk].Size / VerticeCount;
                for (int x = 0; x < VerticeCount; x++)
                {
                    Vector3 vec = new Vector3();
                    BR.BaseStream.Position = HeaderSize + RawDataChunkInfo[verticechunk].Offset +
                                             (RawDataChunkInfo[verticechunk].ChunkSize * x);
                    vec.X = DecompressVertice(BR.ReadInt16(), bb.MinX, bb.MaxX);
                    vec.Y = DecompressVertice(BR.ReadInt16(), bb.MinY, bb.MaxY);
                    vec.Z = DecompressVertice(BR.ReadInt16(), bb.MinZ, bb.MaxZ);
                    Vertices.Add(vec);

                    // if (tempbonemapcount == 0) { continue; }

                    switch (RawDataChunkInfo[verticechunk].ChunkSize)
                    {
                        case 6:
                            BoneInfo b = new BoneInfo();
                            b.BoneIndex.Add(0);
                            b.Weight.Add(1.0f);
                            VerticeBones.Add(b);

                            break;
                        case 8:
                            BoneInfo c = new BoneInfo();
                            c.BoneIndex.Add(BR.ReadByte());
                            c.Weight.Add(1.0f);
                            byte tempb = BR.ReadByte();
                            if (tempb == 0)
                            {
                                VerticeBones.Add(c);
                                break;
                            }

                            BoneInfo c2 = new BoneInfo();
                            c2.BoneIndex.Add(tempb);
                            c2.Weight.Add(1.0f);
                            VerticeBones.Add(c2);
                            c.Weight[0] = 1.0f;
                            VerticeBones.Add(c);
                            break;
                        case 12:
                            BoneInfo bbb = new BoneInfo();
                            bbb.BoneIndex.Add(BR.ReadByte());
                            bbb.Weight.Add(0.99f);
                            VerticeBones.Add(bbb);
                            break;
                    }
                }

                RawDataChunkInfo[uvchunk].ChunkSize = 4;
                for (int x = 0; x < VerticeCount; x++)
                {
                    Vector2 tempuv = new Vector2();
                    BR.BaseStream.Position = HeaderSize + RawDataChunkInfo[uvchunk].Offset +
                                             (RawDataChunkInfo[uvchunk].ChunkSize * x);
                    tempuv.X = DecompressVertice(BR.ReadInt16(), bb.MinU, bb.MaxU) % 1;
                    tempuv.Y = DecompressVertice(BR.ReadInt16(), bb.MinV, bb.MaxV) % 1;

                    // if (tempuv.X > 1) { tempuv.X = tempuv.X - 1; }
                    // else
                    if (tempuv.X < 0)
                    {
                        tempuv.X = 1 - tempuv.X;
                    }

                    // if (tempuv.Y > 1) { tempuv.Y = tempuv.Y - 1; }
                    // else
                    if (tempuv.Y < 0)
                    {
                        tempuv.Y = 1 - tempuv.Y;
                    }

                    UVs.Add(tempuv);
                }

                RawDataChunkInfo[uvchunk + 1].ChunkSize = 12;
                for (int x = 0; x < VerticeCount; x++)
                {
                    BR.BaseStream.Position = HeaderSize + RawDataChunkInfo[uvchunk + 1].Offset +
                                             (RawDataChunkInfo[uvchunk + 1].ChunkSize * x);

                    int dword = BR.ReadInt32();

                    Vector3 tempnormal = DecompressNormal(dword);

                    int converto = CompressNormal(tempnormal);
                    Vector3 tempnormal2 = DecompressNormal(converto);
                    Normals.Add(tempnormal);
                }

                BR.BaseStream.Position = HeaderSize + RawDataChunkInfo[indicechunk].Offset;
                this.Indices = new short[IndiceCount];
                for (int x = 0; x < IndiceCount; x++)
                {
                    Indices[x] = (short)BR.ReadUInt16();
                }
            }
Example #3
0
            /// <summary>
            /// Initializes a new instance of the <see cref="PRTMRawDataMetaChunk"/> class.
            /// </summary>
            /// <param name="meta">The meta.</param>
            /// <remarks></remarks>
            public PRTMRawDataMetaChunk(ref Meta meta)
            {
                BinaryReader BR = new BinaryReader(meta.MS);

                BR.BaseStream.Position = 176;
                int tempc = BR.ReadInt32();
                int tempr = BR.ReadInt32() - meta.Map.SecondaryMagic - meta.offset;

                RawDataChunkInfo = new RawDataOffsetChunk[tempc];
                for (int x = 0; x < tempc; x++)
                {
                    RawDataChunkInfo[x]           = new RawDataOffsetChunk();
                    BR.BaseStream.Position        = tempr + (x * 16) + 6;
                    RawDataChunkInfo[x].ChunkSize = 56;
                    RawDataChunkInfo[x].Size      = BR.ReadInt32();
                    if (RawDataChunkInfo[x].ChunkSize == 0)
                    {
                        RawDataChunkInfo[x].ChunkSize = RawDataChunkInfo[x].Size;
                    }

                    RawDataChunkInfo[x].Offset     = BR.ReadInt32();
                    RawDataChunkInfo[x].ChunkCount = RawDataChunkInfo[x].Size / RawDataChunkInfo[x].ChunkSize;
                }

                BR.BaseStream.Position = 136;
                VerticeCount           = BR.ReadInt32();
                tempr = BR.ReadInt32() - meta.Map.SecondaryMagic - meta.offset;
                BR.BaseStream.Position = tempr;
                for (int x = 0; x < VerticeCount; x++)
                {
                    Vector3 vec = new Vector3();

                    vec.X = BR.ReadSingle();
                    vec.Y = BR.ReadSingle();
                    vec.Z = BR.ReadSingle();
                    Vertices.Add(vec);

                    Vector3 vec2 = new Vector3();
                    vec2.X = BR.ReadSingle();
                    vec2.Y = BR.ReadSingle();
                    vec2.Z = BR.ReadSingle();
                    Normals.Add(vec2);

                    Vector3 vec3 = new Vector3();
                    vec3.X = BR.ReadSingle();
                    vec3.Y = BR.ReadSingle();
                    vec3.Z = BR.ReadSingle();
                    Binormals.Add(vec3);

                    Vector3 vec4 = new Vector3();
                    vec4.X = BR.ReadSingle();
                    vec4.Y = BR.ReadSingle();
                    vec4.Z = BR.ReadSingle();
                    Tangents.Add(vec4);

                    Vector2 vec5 = new Vector2();
                    vec5.X = BR.ReadSingle();
                    vec5.Y = BR.ReadSingle();

                    UVs.Add(vec5);
                }

                BR.BaseStream.Position = 168;
                HeaderSize             = BR.ReadInt32() + 8;

                BR.BaseStream.Position = 144;
                IndiceCount            = BR.ReadInt32();
                tempr = BR.ReadInt32() - meta.Map.SecondaryMagic - meta.offset;
                BR.BaseStream.Position = tempr;
                FaceCount = IndiceCount / 3;

                this.Indices = new short[IndiceCount];
                for (int x = 0; x < IndiceCount; x++)
                {
                    Indices[x] = (short)BR.ReadUInt16();
                }

                SubMeshInfo = new ModelSubMeshInfo[1];
                for (int x = 0; x < 1; x++)
                {
                    SubMeshInfo[x]              = new ModelSubMeshInfo();
                    BR.BaseStream.Position      = HeaderSize + RawDataChunkInfo[0].Offset + (x * 72) + 4;
                    SubMeshInfo[x].ShaderNumber = 0;
                    SubMeshInfo[x].IndiceStart  = 0;
                    SubMeshInfo[x].IndiceCount  = IndiceCount;
                }
            }