Ejemplo n.º 1
0
        public override void LoadFromStream(BinaryReader br, MMDImportSettings importSettings)
        {
            int mtIndex = PMXParser.ReadIndex(br, importSettings.BitSettings.MaterialIndexLength);

            if (mtIndex < 0)
            {
                this.Material = null;
            }
            else
            {
                this.Material = this.Model.Materials[mtIndex];
            }

            this.Type = (MaterialMorphOffsetType)(int)br.ReadByte();

            this.Diffuse  = PMXColorRGBA.LoadFromStreamStatic(br);
            this.Specular = PMXColorRGBA.LoadFromStreamStatic(br);
            this.Ambient  = PMXColorRGB.LoadFromStreamStatic(br);

            this.EdgeColor = PMXColorRGBA.LoadFromStreamStatic(br);
            this.EdgeSize  = br.ReadSingle();

            this.TextureFactor       = PMXColorRGBA.LoadFromStreamStatic(br);
            this.SphereTextureFactor = PMXColorRGBA.LoadFromStreamStatic(br);
            this.ToonTextureFactor   = PMXColorRGBA.LoadFromStreamStatic(br);
        }
Ejemplo n.º 2
0
        public static PMXColorRGBA LoadFromStreamStatic(BinaryReader br)
        {
            PMXColorRGBA res = new PMXColorRGBA();

            res.LoadFromStream(br);
            return(res);
        }
Ejemplo n.º 3
0
        public PMXMorphOffsetMaterial(PMXModel model, PMXMorph morph) : base(model, morph)
        {
            this.MorphTargetType = PMXMorph.MORPH_IDENTIFY_MATERIAL;

            this.Diffuse             = new PMXColorRGBA();
            this.Specular            = new PMXColorRGBA();
            this.Ambient             = new PMXColorRGB();
            this.EdgeColor           = new PMXColorRGBA();
            this.TextureFactor       = new PMXColorRGBA();
            this.SphereTextureFactor = new PMXColorRGBA();
            this.ToonTextureFactor   = new PMXColorRGBA();
        }
Ejemplo n.º 4
0
        public void LoadFromStream(BinaryReader br, MMDImportSettings importSettings, string[] textures, List <PMXTriangle> triangles)
        {
            if (textures == null)
            {
                textures = new string[0];
            }

            int triangleVerticesCount;

            if (importSettings.Format == MMDImportSettings.ModelFormat.PMX)
            { //PMX format
                this.NameJP = PMXParser.ReadString(br, importSettings.TextEncoding);
                this.NameEN = PMXParser.ReadString(br, importSettings.TextEncoding);

                this.Diffuse        = PMXColorRGB.LoadFromStreamStatic(br);
                this.Alpha          = br.ReadSingle();
                this.Specular       = PMXColorRGB.LoadFromStreamStatic(br);
                this.SpecularFactor = br.ReadSingle();
                this.Ambient        = PMXColorRGB.LoadFromStreamStatic(br);

                byte flags = br.ReadByte();
                //Flag parsing
                //1st bit = double sided
                this.DoubleSided = ((flags & PMXMaterial.MATERIAL_DOUBLE_SIDED) != 0);
                //2nd bit = ground shadow
                this.GroundShadow = ((flags & PMXMaterial.MATERIAL_GROUND_SHADOW) != 0);
                //3rd bit - self shadow
                this.SelfShadow = ((flags & PMXMaterial.MATERIAL_SELF_SHADOW) != 0);
                //4th bit - self shadow+
                this.SelfShadowPlus = ((flags & PMXMaterial.MATERIAL_SELF_SHADOW_PLUS) != 0);
                //5th bit - has edge line
                this.EdgeEnabled = ((flags & PMXMaterial.MATERIAL_EDGE_ENABLED) != 0);
                //6th bit - shine with vertex colour
                this.VertexColor = ((flags & PMXMaterial.MATERIAL_VERTEX_COLOR) != 0);

                //7th and 8bit - Tri, Point or Line shadow
                int shadowType = ((flags & 0xC0) >> 6);
                this.GroundShadowType = (PMXGroundShadowType)shadowType;

                this.EdgeColor = PMXColorRGBA.LoadFromStreamStatic(br);
                this.EdgeSize  = br.ReadSingle();

                int diffIndex = PMXParser.ReadIndex(br, importSettings.BitSettings.TextureIndexLength);
                this.DiffuseTexture = this.GetTextureFromIndex(diffIndex, textures);

                int sphereIndex = PMXParser.ReadIndex(br, importSettings.BitSettings.TextureIndexLength);
                this.SphereTexture = this.GetTextureFromIndex(sphereIndex, textures);

                this.SphereMode = (PMXSphereMode)(int)(br.ReadByte());

                this.StandardToon = (br.ReadByte() == 1);
                if (this.StandardToon)
                {
                    this.StandardToonIndex = br.ReadSByte();
                }
                else
                {
                    int toonTexIndex = PMXParser.ReadIndex(br, importSettings.BitSettings.TextureIndexLength);
                    this.NonStandardToonTexture = this.GetTextureFromIndex(toonTexIndex, textures);
                }

                this.Comment          = PMXParser.ReadString(br, importSettings.TextEncoding);
                triangleVerticesCount = br.ReadInt32();
            }
            else
            { //PMD format
                this.Diffuse        = PMXColorRGB.LoadFromStreamStatic(br);
                this.Alpha          = br.ReadSingle();
                this.SpecularFactor = br.ReadSingle();
                this.Specular       = PMXColorRGB.LoadFromStreamStatic(br);
                this.Ambient        = PMXColorRGB.LoadFromStreamStatic(br);

                this._pmdToonIndex = br.ReadSByte();

                byte flags = br.ReadByte();

                this.EdgeEnabled  = (flags == 1);
                this.GroundShadow = this.EdgeEnabled;

                triangleVerticesCount = br.ReadInt32();

                string textureFile = PMDParser.ReadString(br, 20, importSettings.TextEncoding);

                if (textureFile != null)
                {
                    string[] textureRefs = textureFile.Split(new char[] { '*' }, 2, StringSplitOptions.RemoveEmptyEntries);

                    this.DiffuseTexture = textureRefs[0];

                    if (textureRefs.Length > 1)
                    {
                        this.SphereTexture = textureRefs[1];
                    }
                }
            }



            if (triangleVerticesCount % 3 != 0)
            {
                throw new InvalidDataException("Invalid triangle format!");
            }

            if (triangles != null)
            {
                int triangleCount = triangleVerticesCount / 3;

                if (triangleCount > triangles.Count)
                {
                    throw new InvalidDataException("Model doesn't have enough triangles!");
                }

                this.Triangles = triangles.GetRange(0, triangleCount);
                triangles.RemoveRange(0, triangleCount);
            }
        }