예제 #1
0
        public void Write(FileWriter writer, LayoutHeader header)
        {
            if (MatColor != STColor8.White)
            {
                HasMaterialColor = true;
            }
            if (!ChanControl.HasDefaults())
            {
                HasChannelControl = true;
            }
            if (!BlendMode.HasDefaults())
            {
                HasBlendMode = true;
            }
            if (!((AlphaCompare)AlphaCompare).HasDefaults())
            {
                HasAlphaCompare = true;
            }

            if (TextureMaps?.Length > 0 && TexCoordGens?.Count == 0)
            {
                TexCoordGens = new List <TexCoordGenEntry>(TextureMaps.Length);
                for (int i = 0; i < TextureMaps?.Length; i++)
                {
                    TexCoordGens[i] = new TexCoordGenEntry();
                }
            }

            flags = 0;
            if (HasMaterialColor)
            {
                flags |= (1 << 27);
            }

            if (HasChannelControl)
            {
                flags |= (1 << 25);
            }

            if (HasBlendMode)
            {
                flags |= (1 << 24);
            }

            if (HasAlphaCompare)
            {
                flags |= (1 << 23);
            }

            flags |= (uint)((TevStages.Length & 31) << 18);
            flags |= (uint)((IndirectStages.Count & 0x7) << 15);
            flags |= (uint)((IndirectTexTransforms.Count & 0x3) << 13);
            if (HasTevSwapTable)
            {
                flags |= (1 << 12);
            }

            flags |= (uint)((TexCoordGens.Count & 0xF) << 8);
            flags |= (uint)((TextureTransforms.Length & 0xF) << 4);
            flags |= (uint)((TextureMaps.Length & 0xF) << 0);


            writer.WriteString(Name, 0x14);
            writer.Write(BlackColor.ToColor16());
            writer.Write(WhiteColor.ToColor16());
            writer.Write(ColorRegister3.ToColor16());
            writer.Write(TevColor1);
            writer.Write(TevColor2);
            writer.Write(TevColor3);
            writer.Write(TevColor4);
            writer.Write(flags);

            for (int i = 0; i < TextureMaps.Length; i++)
            {
                ((TextureRef)TextureMaps[i]).Write(writer);
            }

            for (int i = 0; i < TextureTransforms.Length; i++)
            {
                TextureTransforms[i].Write(writer);
            }

            for (int i = 0; i < TexCoordGens.Count; i++)
            {
                TexCoordGens[i].Write(writer);
            }

            if (HasChannelControl)
            {
                ChanControl.Write(writer);
            }
            if (HasMaterialColor)
            {
                writer.Write(MatColor);
            }
            if (HasTevSwapTable)
            {
                TevSwapModeTable.Write(writer);
            }

            for (int i = 0; i < IndirectTexTransforms.Count; i++)
            {
                IndirectTexTransforms[i].Write(writer);
            }

            for (int i = 0; i < IndirectStages.Count; i++)
            {
                IndirectStages[i].Write(writer);
            }

            for (int i = 0; i < TevStages.Length; i++)
            {
                ((TevStage)TevStages[i]).Write(writer);
            }

            if (HasAlphaCompare)
            {
                AlphaCompare.Write(writer);
            }
            if (HasBlendMode)
            {
                BlendMode.Write(writer);
            }
        }