Ejemplo n.º 1
0
        private void readMaterialContainer(BinaryReader br)
        {
            uint num = br.ReadUInt32();

            for (uint num2 = 0u; num2 < num; num2 += 1u)
            {
                MMDMaterial mMDMaterial = new MMDMaterial();
                mMDMaterial.Name = this.readString(br);
                this.readString(br);
                mMDMaterial.Diffuse.R     = br.ReadSingle();
                mMDMaterial.Diffuse.G     = br.ReadSingle();
                mMDMaterial.Diffuse.B     = br.ReadSingle();
                mMDMaterial.Diffuse.A     = br.ReadSingle();
                mMDMaterial.Specular.R    = br.ReadSingle();
                mMDMaterial.Specular.G    = br.ReadSingle();
                mMDMaterial.Specular.B    = br.ReadSingle();
                mMDMaterial.Specular.A    = 1f;
                mMDMaterial.SpecularPower = br.ReadSingle();
                mMDMaterial.Ambient.R     = br.ReadSingle();
                mMDMaterial.Ambient.G     = br.ReadSingle();
                mMDMaterial.Ambient.B     = br.ReadSingle();
                mMDMaterial.Ambient.A     = mMDMaterial.Diffuse.A;
                mMDMaterial.renderFlag    = (uint)br.ReadByte();
                mMDMaterial.EdgeColor.R   = br.ReadSingle();
                mMDMaterial.EdgeColor.G   = br.ReadSingle();
                mMDMaterial.EdgeColor.B   = br.ReadSingle();
                mMDMaterial.EdgeColor.A   = br.ReadSingle();
                mMDMaterial.EdgeWidth     = br.ReadSingle();
                int num3 = this.readTextureIndex(br);
                int num4 = this.readTextureIndex(br);
                if (num3 >= 0)
                {
                    mMDMaterial.TextureName = this.textureTable[num3];
                }
                mMDMaterial.SphereType = (MMDSphereType)br.ReadByte();
                if (num4 >= 0)
                {
                    mMDMaterial.SphereTextureName = this.textureTable[num4];
                }
                else
                {
                    mMDMaterial.SphereType = MMDSphereType.None;
                }
                byte b = br.ReadByte();
                if (b == 0)
                {
                    int num5 = this.readTextureIndex(br);
                    if (num5 >= 0)
                    {
                        mMDMaterial.ToonTextureName = this.textureTable[num5];
                    }
                }
                else if (b == 1)
                {
                    sbyte b2 = br.ReadSByte();
                    if (b2 >= 0)
                    {
                        mMDMaterial.ToonTextureName = string.Format("toon{0:00}.bmp", (int)(b2 + 1));
                    }
                }
                this.readString(br);
                mMDMaterial.FaceCount = br.ReadUInt32();
                this.Materials.Add(mMDMaterial);
            }
            uint num6 = 0u;
            uint num7 = 0u;

            while ((ulong)num7 < (ulong)((long)this.Materials.Count))
            {
                for (uint num8 = 0u; num8 < this.Materials[(int)num7].FaceCount; num8 += 3u)
                {
                    this.FaceMaterialIndices[(int)((UIntPtr)num6)] = (int)((ushort)num7);
                    num6 += 1u;
                }
                num7 += 1u;
            }
        }
Ejemplo n.º 2
0
        private void readMaterialContainer(BinaryReader br)
        {
            uint num = br.ReadUInt32();

            for (uint num2 = 0u; num2 < num; num2 += 1u)
            {
                MMDMaterial mMDMaterial = new MMDMaterial();
                mMDMaterial.Name             = "Material" + num2;
                mMDMaterial.Diffuse.R        = br.ReadSingle();
                mMDMaterial.Diffuse.G        = br.ReadSingle();
                mMDMaterial.Diffuse.B        = br.ReadSingle();
                mMDMaterial.Diffuse.A        = br.ReadSingle();
                mMDMaterial.SpecularPower    = br.ReadSingle();
                mMDMaterial.Specular.R       = br.ReadSingle();
                mMDMaterial.Specular.G       = br.ReadSingle();
                mMDMaterial.Specular.B       = br.ReadSingle();
                mMDMaterial.Specular.A       = 1f;
                mMDMaterial.Ambient.R        = br.ReadSingle();
                mMDMaterial.Ambient.G        = br.ReadSingle();
                mMDMaterial.Ambient.B        = br.ReadSingle();
                mMDMaterial.Ambient.A        = mMDMaterial.Diffuse.A;
                mMDMaterial.toonTextureIndex = (int)br.ReadSByte();
                if (mMDMaterial.toonTextureIndex < 0)
                {
                    mMDMaterial.ToonTextureName = "";
                }
                else
                {
                    mMDMaterial.ToonTextureName = string.Format("toon{0:00}.bmp", mMDMaterial.toonTextureIndex + 1);
                }
                byte b = br.ReadByte();
                if (b == 1)
                {
                    mMDMaterial.EdgeWidth = 0.6f;
                }
                else
                {
                    mMDMaterial.EdgeWidth = 0f;
                }
                mMDMaterial.FaceCount  = br.ReadUInt32();
                mMDMaterial.SphereType = MMDSphereType.None;
                string   text  = this.readString(br, 20);
                string[] array = text.Split(new char[]
                {
                    '*'
                });
                for (int i = 0; i < array.Length; i++)
                {
                    string text2 = Path.GetExtension(array[i]).ToLower();
                    if (text2.Equals(".sph"))
                    {
                        mMDMaterial.SphereTextureName = array[i];
                        mMDMaterial.SphereType        = MMDSphereType.Mul;
                    }
                    else if (text2.Equals(".spa"))
                    {
                        mMDMaterial.SphereTextureName = array[i];
                        mMDMaterial.SphereType        = MMDSphereType.Add;
                    }
                    else
                    {
                        mMDMaterial.TextureName = array[i];
                    }
                }
                this.Materials.Add(mMDMaterial);
                mMDMaterial.renderFlag  = 14u;
                mMDMaterial.renderFlag |= ((mMDMaterial.Diffuse.A < 1f) ? 1u : 0u);
                mMDMaterial.renderFlag |= ((mMDMaterial.EdgeWidth > 0f) ? 16u : 0u);
                mMDMaterial.extendFlag  = 255u;
            }
            uint num3 = 0u;
            uint num4 = 0u;

            while ((ulong)num4 < (ulong)((long)this.Materials.Count))
            {
                for (uint num5 = 0u; num5 < this.Materials[(int)num4].FaceCount; num5 += 3u)
                {
                    this.FaceMaterialIndices[(int)((UIntPtr)num3)] = (int)((ushort)num4);
                    num3 += 1u;
                }
                num4 += 1u;
            }
        }