Exemple #1
0
        public TEX1(EndianBinaryReader reader, int offset)
        {
            Textures = new List <BinaryTextureImage>();

            reader.BaseStream.Seek(offset, System.IO.SeekOrigin.Begin);
            reader.SkipInt32();
            int   tex1Size = reader.ReadInt32();
            short texCount = reader.ReadInt16();

            reader.SkipInt16();

            int textureHeaderOffset    = reader.ReadInt32();
            int textureNameTableOffset = reader.ReadInt32();

            List <string> names = NameTableIO.Load(reader, offset + textureNameTableOffset);

            reader.BaseStream.Seek(textureHeaderOffset + offset, System.IO.SeekOrigin.Begin);

            for (int i = 0; i < texCount; i++)
            {
                reader.BaseStream.Seek((offset + 0x20 + (0x20 * i)), System.IO.SeekOrigin.Begin);

                BinaryTextureImage img = new BinaryTextureImage(names[i]);
                img.Load(reader, (offset + 0x20 + (0x20 * i)));
                Textures.Add(img);
            }
        }
Exemple #2
0
        public JNT1(EndianBinaryReader reader, int offset, BMDInfo modelstats = null)
        {
            BoneNameIndices = new Dictionary <string, int>();
            FlatSkeleton    = new List <Rigging.Bone>();

            reader.BaseStream.Seek(offset, System.IO.SeekOrigin.Begin);
            reader.SkipInt32();

            int jnt1Size   = reader.ReadInt32();
            int jointCount = reader.ReadInt16();

            reader.SkipInt16();

            if (modelstats != null)
            {
                modelstats.JNT1Size = jnt1Size;
            }

            int jointDataOffset   = reader.ReadInt32();
            int internTableOffset = reader.ReadInt32();
            int nameTableOffset   = reader.ReadInt32();

            List <string> names = NameTableIO.Load(reader, offset + nameTableOffset);

            int        highestRemap = 0;
            List <int> remapTable   = new List <int>();

            reader.BaseStream.Seek(offset + internTableOffset, System.IO.SeekOrigin.Begin);
            for (int i = 0; i < jointCount; i++)
            {
                int test = reader.ReadInt16();
                remapTable.Add(test);

                if (test > highestRemap)
                {
                    highestRemap = test;
                }
            }

            List <Rigging.Bone> tempList = new List <Rigging.Bone>();

            reader.BaseStream.Seek(offset + jointDataOffset, System.IO.SeekOrigin.Begin);
            for (int i = 0; i <= highestRemap; i++)
            {
                tempList.Add(new Rigging.Bone(reader, names[i]));
            }

            for (int i = 0; i < jointCount; i++)
            {
                FlatSkeleton.Add(tempList[remapTable[i]]);
            }

            foreach (Rigging.Bone bone in FlatSkeleton)
            {
                BoneNameIndices.Add(bone.Name, FlatSkeleton.IndexOf(bone));
            }

            reader.BaseStream.Seek(offset + jnt1Size, System.IO.SeekOrigin.Begin);
        }
        public MAT3(EndianBinaryReader reader, int offset)
        {
            InitLists();

            reader.BaseStream.Seek(offset, System.IO.SeekOrigin.Begin);

            reader.SkipInt32();
            int  mat3Size      = reader.ReadInt32();
            int  matCount      = reader.ReadInt16();
            long matInitOffset = 0;

            reader.SkipInt16();

            for (Mat3OffsetIndex i = 0; i <= Mat3OffsetIndex.NBTScaleData; ++i)
            {
                int sectionOffset = reader.ReadInt32();

                if (sectionOffset == 0)
                {
                    continue;
                }

                long curReaderPos = reader.BaseStream.Position;
                int  nextOffset   = reader.PeekReadInt32();
                int  sectionSize  = 0;

                if (i == Mat3OffsetIndex.NBTScaleData)
                {
                }

                if (nextOffset == 0 && i != Mat3OffsetIndex.NBTScaleData)
                {
                    long saveReaderPos = reader.BaseStream.Position;

                    reader.BaseStream.Position += 4;

                    while (reader.PeekReadInt32() == 0)
                    {
                        reader.BaseStream.Position += 4;
                    }

                    nextOffset  = reader.PeekReadInt32();
                    sectionSize = nextOffset - sectionOffset;

                    reader.BaseStream.Position = saveReaderPos;
                }
                else if (i == Mat3OffsetIndex.NBTScaleData)
                {
                    sectionSize = mat3Size - sectionOffset;
                }
                else
                {
                    sectionSize = nextOffset - sectionOffset;
                }

                reader.BaseStream.Position = (offset) + sectionOffset;

                switch (i)
                {
                case Mat3OffsetIndex.MaterialData:
                    matInitOffset = reader.BaseStream.Position;
                    break;

                case Mat3OffsetIndex.IndexData:
                    m_RemapIndices = new List <int>();

                    for (int index = 0; index < matCount; index++)
                    {
                        m_RemapIndices.Add(reader.ReadInt16());
                    }

                    break;

                case Mat3OffsetIndex.NameTable:
                    m_MaterialNames = NameTableIO.Load(reader, offset + sectionOffset);
                    break;

                case Mat3OffsetIndex.IndirectData:
                    m_IndirectTexBlock = IndirectTexturingIO.Load(reader, sectionOffset, sectionSize);
                    break;

                case Mat3OffsetIndex.CullMode:
                    m_CullModeBlock = CullModeIO.Load(reader, sectionOffset, sectionSize);
                    break;

                case Mat3OffsetIndex.MaterialColor:
                    m_MaterialColorBlock = ColorIO.Load(reader, sectionOffset, sectionSize);
                    break;

                case Mat3OffsetIndex.ColorChannelCount:
                    NumColorChannelsBlock = new List <byte>();

                    for (int chanCnt = 0; chanCnt < sectionSize; chanCnt++)
                    {
                        byte chanCntIn = reader.ReadByte();

                        if (chanCntIn < 84)
                        {
                            NumColorChannelsBlock.Add(chanCntIn);
                        }
                    }

                    break;

                case Mat3OffsetIndex.ColorChannelData:
                    m_ChannelControlBlock = ColorChannelIO.Load(reader, sectionOffset, sectionSize);
                    break;

                case Mat3OffsetIndex.AmbientColorData:
                    m_AmbientColorBlock = ColorIO.Load(reader, sectionOffset, sectionSize);
                    break;

                case Mat3OffsetIndex.LightData:
                    break;

                case Mat3OffsetIndex.TexGenCount:
                    NumTexGensBlock = new List <byte>();

                    for (int genCnt = 0; genCnt < sectionSize; genCnt++)
                    {
                        byte genCntIn = reader.ReadByte();

                        if (genCntIn < 84)
                        {
                            NumTexGensBlock.Add(genCntIn);
                        }
                    }

                    break;

                case Mat3OffsetIndex.TexCoordData:
                    m_TexCoord1GenBlock = TexCoordGenIO.Load(reader, sectionOffset, sectionSize);
                    break;

                case Mat3OffsetIndex.TexCoord2Data:
                    m_TexCoord2GenBlock = TexCoordGenIO.Load(reader, sectionOffset, sectionSize);
                    break;

                case Mat3OffsetIndex.TexMatrixData:
                    m_TexMatrix1Block = TexMatrixIO.Load(reader, sectionOffset, sectionSize);
                    break;

                case Mat3OffsetIndex.TexMatrix2Data:
                    m_TexMatrix2Block = TexMatrixIO.Load(reader, sectionOffset, sectionSize);
                    break;

                case Mat3OffsetIndex.TexNoData:
                    m_TexRemapBlock = new List <short>();
                    int texNoCnt = sectionSize / 2;

                    for (int texNo = 0; texNo < texNoCnt; texNo++)
                    {
                        m_TexRemapBlock.Add(reader.ReadInt16());
                    }

                    break;

                case Mat3OffsetIndex.TevOrderData:
                    m_TevOrderBlock = TevOrderIO.Load(reader, sectionOffset, sectionSize);
                    break;

                case Mat3OffsetIndex.TevColorData:
                    m_TevColorBlock = Int16ColorIO.Load(reader, sectionOffset, sectionSize);
                    break;

                case Mat3OffsetIndex.TevKColorData:
                    m_TevKonstColorBlock = ColorIO.Load(reader, sectionOffset, sectionSize);
                    break;

                case Mat3OffsetIndex.TevStageCount:
                    NumTevStagesBlock = new List <byte>();

                    for (int stgCnt = 0; stgCnt < sectionSize; stgCnt++)
                    {
                        byte stgCntIn = reader.ReadByte();

                        if (stgCntIn < 84)
                        {
                            NumTevStagesBlock.Add(stgCntIn);
                        }
                    }

                    break;

                case Mat3OffsetIndex.TevStageData:
                    m_TevStageBlock = TevStageIO.Load(reader, sectionOffset, sectionSize);
                    break;

                case Mat3OffsetIndex.TevSwapModeData:
                    m_SwapModeBlock = TevSwapModeIO.Load(reader, sectionOffset, sectionSize);
                    break;

                case Mat3OffsetIndex.TevSwapModeTable:
                    m_SwapTableBlock = TevSwapModeTableIO.Load(reader, sectionOffset, sectionSize);
                    break;

                case Mat3OffsetIndex.FogData:
                    m_FogBlock = FogIO.Load(reader, sectionOffset, sectionSize);
                    break;

                case Mat3OffsetIndex.AlphaCompareData:
                    m_AlphaCompBlock = AlphaCompareIO.Load(reader, sectionOffset, sectionSize);
                    break;

                case Mat3OffsetIndex.BlendData:
                    m_blendModeBlock = BlendModeIO.Load(reader, sectionOffset, sectionSize);
                    break;

                case Mat3OffsetIndex.ZModeData:
                    m_zModeBlock = ZModeIO.Load(reader, sectionOffset, sectionSize);
                    break;

                case Mat3OffsetIndex.ZCompLoc:
                    m_zCompLocBlock = new List <bool>();

                    for (int zcomp = 0; zcomp < sectionSize; zcomp++)
                    {
                        byte boolIn = reader.ReadByte();

                        if (boolIn > 1)
                        {
                            break;
                        }

                        m_zCompLocBlock.Add(Convert.ToBoolean(boolIn));
                    }

                    break;

                case Mat3OffsetIndex.DitherData:
                    m_ditherBlock = new List <bool>();

                    for (int dith = 0; dith < sectionSize; dith++)
                    {
                        byte boolIn = reader.ReadByte();

                        if (boolIn > 1)
                        {
                            break;
                        }

                        m_ditherBlock.Add(Convert.ToBoolean(boolIn));
                    }

                    break;

                case Mat3OffsetIndex.NBTScaleData:
                    m_NBTScaleBlock = NBTScaleIO.Load(reader, sectionOffset, sectionSize);
                    break;
                }

                reader.BaseStream.Position = curReaderPos;
            }

            int highestMatIndex = 0;

            for (int i = 0; i < matCount; i++)
            {
                if (m_RemapIndices[i] > highestMatIndex)
                {
                    highestMatIndex = m_RemapIndices[i];
                }
            }

            reader.BaseStream.Position = matInitOffset;
            m_Materials = new List <Material>();
            for (int i = 0; i <= highestMatIndex; i++)
            {
                LoadInitData(reader);
            }

            reader.BaseStream.Seek(offset + mat3Size, System.IO.SeekOrigin.Begin);
        }