예제 #1
0
        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);
        }