示例#1
0
        public List <Material> GetMaterials()
        {
            List <Material> mats = new List <Material>(DAEMaterials.Count);

            for (int i = 0; i < DAEMaterials.Count; i++)
            {
                //phong
                var shdrst = new ShaderSettings();
                var rddir  = new RenderDirectives();
                shdrst.HasSkeleton      = true;
                shdrst.RecieveShadow    = false;
                shdrst.AffectedByLight  = true;
                rddir.CastShadow        = false;
                rddir.HasEdges          = true;
                shdrst.TextureDiffuse   = true;
                shdrst.DiscardInvisible = true;
                shdrst.Ambient          = true;
                var mat = new MaterialPMX(shdrst, rddir);
                mat.Name = DAEMaterials[i].Name;
                mat.UniformManager.Set("ambient_color", DAEMaterials[i].Ambient.Xyz);
                mat.SetTexture(DAEMaterials[i].DiffuseTexture, TextureType.Diffuse);

                mats.Add(mat);
            }
            return(mats);
        }
示例#2
0
        public override Material Clone()
        {
            var material = new MaterialPMX(ShaderSettings, RenderDirrectives);

            foreach (var texture in textures)
            {
                material.SetTexture(texture.Value, texture.Key);
            }
            //material.UniManager = new ShaderUniformManager(UniManager.CopyUniforms(), material);
            return(material);
        }
示例#3
0
        public override Material Clone()
        {
            var material = new MaterialPMX(ShaderSettings, RenderDirrectives);

            foreach (var texture in textures)
            {
                material.SetTexture(texture.Value, texture.Key);
            }

            return(material);
        }
示例#4
0
        void ReadMaterial(Reader reader)
        {
            int materiaCount = reader.ReadInt32();
            int offset       = 0;

            mats = new Material[materiaCount];

            for (int i = 0; i < materiaCount; i++)
            {
                ShaderSettings   shdrs = new ShaderSettings();
                RenderDirectives rndr  = new RenderDirectives();

                shdrs.HasSkeleton      = true;
                shdrs.DiscardInvisible = true;
                shdrs.AffectedByLight  = true;
                shdrs.DifuseColor      = true;
                shdrs.Ambient          = true;
                shdrs.SpecularColor    = true;

                shdrs.TextureDiffuse = true;
                string name = reader.readString();
                reader.readString();                 //eng name

                Vector4 difColor = reader.readVector4();
                //if (difColor.W == 0)//diffuse color
                //	rndr.render = false;

                Vector3 specularColour = reader.readVector3();             //specular color
                float   specularPower  = reader.ReadSingle();              //specular
                //fix zero power bug
                if (specularPower == 0)
                {
                    specularPower = 0.000001f;
                }
                Vector3 ambientColour = reader.readVector3(); //ambient color
                //setting values from flags
                var flags = new MaterialFlags(reader.ReadByte());
                shdrs.RecieveShadow   = flags.ReceiveShadow;
                shdrs.AffectedByLight = flags.ReceiveShadow;
                rndr.CastShadow       = flags.CastShadow;
                rndr.HasEdges         = flags.HasEdge;
                rndr.NoCull           = flags.NoCull;

                var outln = new Outline();
                outln.EdgeColour = reader.readVector4();
                outln.EdgeScaler = reader.ReadSingle() * 0.03f;

                int difTexIndex = reader.readVal(header.GetTextureIndexSize);

                //sphericar texture for false light sources effect
                int envTexIndex = reader.readVal(header.GetTextureIndexSize);
                int envBlend    = reader.ReadByte();
                shdrs.EnvType = (EnvironmentMode)envBlend;
                Texture2D envTex = empty;
                if (envTexIndex != 255 && envBlend > 0)
                {
                    if (textures[envTexIndex].Name != "def")
                    {
                        envTex = textures[envTexIndex];
                    }
                    else
                    {
                        shdrs.EnvType = 0;
                    }
                }
                else
                {
                    shdrs.EnvType = 0;
                }



                byte toonType = reader.ReadByte();

                Texture2D toon = empty;
                if (toonType == 0)
                {
                    int text = reader.readVal(header.GetTextureIndexSize);
                    if (text != 255)
                    {
                        shdrs.ToonShadow        = true;
                        textures[text].WrapMode = TextureWrapMode.ClampToEdge;
                        toon = textures[text];
                        //toon.GetTextureType = TextureType.toon;
                    }
                    else
                    {
                        //disable shadowing if no toon texture
                        shdrs.AffectedByLight = false;
                        shdrs.RecieveShadow   = false;
                    }
                }
                else
                {
                    byte toontex = reader.ReadByte();
                    toontex++;
                    string    texturePath = String.Format("Toys.Resourses.textures.PMX.toon{0}.bmp", toontex.ToString().PadLeft(2, '0'));
                    Texture2D toonTex     = ResourcesManager.GetResourse <Texture2D>(texturePath);
                    if (toonTex == null)
                    {
                        var assembly = System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(Texture2D)).Assembly;
                        using (Bitmap pic = new Bitmap(assembly.GetManifestResourceStream(texturePath)))
                        {
                            toonTex = new Texture2D(pic, TextureType.Toon, texturePath);
                        }
                    }

                    toon             = toonTex;
                    shdrs.ToonShadow = true;
                }
                reader.readString();
                int       count = reader.ReadInt32();
                Texture2D tex   = empty;
                if (difTexIndex != 255)
                {
                    tex = textures[difTexIndex];
                }
                var mat = new MaterialPMX(shdrs, rndr);
                mat.Name    = name;
                mat.Outline = outln;
                mat.SetTexture(tex, TextureType.Diffuse);
                mat.SetTexture(toon, TextureType.Toon);
                mat.SetTexture(envTex, TextureType.Sphere);
                mat.SpecularColour = specularColour;
                mat.Specular       = specularPower;
                mat.DiffuseColor   = difColor;
                mat.AmbientColour  = ambientColour;
                mat.UniformManager.Set("specular_color", specularColour);
                mat.UniformManager.Set("ambient_color", ambientColour);
                mat.UniformManager.Set("specular_power", specularPower);
                mat.UniformManager.Set("diffuse_color", difColor);

                if (mat.DiffuseColor.W < 0.001f)
                {
                    mat.RenderDirrectives.IsRendered = false;
                }

                //skip empty materials
                if (count == 0)
                {
                    mat.RenderDirrectives.IsRendered = false;
                }
                mat.Offset = offset;
                mat.Count  = count;
                mats[i]    = mat;
                offset    += count;
            }
        }
示例#5
0
        void ReadMaterial(Reader reader)
        {
            int materialCount = reader.ReadInt32();

            materialToonTable = new int[materialCount];
            mats = new Material[materialCount];
            int offset = 0;

            for (int i = 0; i < materialCount; i++)
            {
                var shdrs          = new ShaderSettings();
                var difColor       = reader.readVector4();
                var specularPower  = reader.ReadSingle();
                var specularColour = reader.readVector3();
                var ambientColour  = reader.readVector3();
                materialToonTable[i] = reader.ReadByte();
                bool            hasEdge        = (reader.ReadByte() > 0);
                int             vertCount      = reader.ReadInt32();
                EnvironmentMode envMode        = EnvironmentMode.None;
                Texture2D       diffuseTexture = null;
                Texture2D       sphereTexture  = null;
                var             pathList       = reader.readStringLength(20);
                if (pathList.Contains('*'))
                {
                    var texturePath = pathList.Split('*');
                    shdrs.EnvType = EnvironmentMode.None;

                    for (int n = 0; n < texturePath.Length; n++)
                    {
                        string path = texturePath[n];

                        EnvironmentMode sphereMode = GetEnvType(path);
                        if (sphereMode != 0)
                        {
                            sphereTexture = GetTexture(path);
                            envMode       = sphereMode;
                        }
                        else
                        {
                            diffuseTexture = GetTexture(path);
                        }
                    }
                }

                var outln = new Outline();
                outln.EdgeScaler = 0.1f;

                shdrs.HasSkeleton      = true;
                shdrs.DiscardInvisible = true;
                shdrs.AffectedByLight  = true;
                shdrs.DifuseColor      = true;
                shdrs.Ambient          = true;
                shdrs.SpecularColor    = true;
                shdrs.TextureDiffuse   = true;
                shdrs.RecieveShadow    = true;
                shdrs.EnvType          = envMode;

                var rndr = new RenderDirectives();
                rndr.HasEdges = hasEdge;
                var mat = new MaterialPMX(shdrs, rndr);
                mat.Name    = string.Format("Material {0}", i);
                mat.Outline = outln;
                if (diffuseTexture)
                {
                    mat.SetTexture(diffuseTexture, TextureType.Diffuse);
                }
                //mat.SetTexture(toon, TextureType.Toon);
                if (sphereTexture)
                {
                    mat.SetTexture(sphereTexture, TextureType.Sphere);
                }
                mat.SpecularColour = specularColour;
                mat.Specular       = specularPower;
                mat.DiffuseColor   = difColor;
                mat.AmbientColour  = ambientColour;
                mat.UniformManager.Set("specular_color", specularColour);
                mat.UniformManager.Set("ambient_color", ambientColour);
                mat.UniformManager.Set("specular_power", specularPower);
                mat.UniformManager.Set("diffuse_color", difColor);

                if (mat.DiffuseColor.W < 0.001f)
                {
                    mat.RenderDirrectives.IsRendered = false;
                }
                //skip empty materials
                if (vertCount == 0)
                {
                    mat.RenderDirrectives.IsRendered = false;
                }
                mat.Offset = offset;
                mat.Count  = vertCount;
                mats[i]    = mat;
                offset    += vertCount;
            }
        }