예제 #1
0
        public MaterialManager(Grendgine_Collada scene, List <Batch> batches, string modelPath)
        {
            #region List initialization
            m_indirectTexBlock    = new List <IndirectTexturing>();
            m_cullModeBlock       = new List <GXCullMode>();
            m_materialColorBlock  = new List <Color?>();
            m_channelControlBlock = new List <ChannelControl>();
            m_ambientColorBlock   = new List <Color?>();
            m_lightingColorBlock  = new List <Color?>();
            m_texCoord1GenBlock   = new List <TexCoordGen>();
            m_texCoord2GenBlock   = new List <TexCoordGen>();
            m_texMatrix1Block     = new List <TexMatrix>();
            m_texMatrix2Block     = new List <TexMatrix>();
            TextureList           = new List <BinaryTextureImage>();
            m_tevOrderBlock       = new List <TevOrder>();
            m_tevColorBlock       = new List <Color?>();
            m_tevKonstColorBlock  = new List <Color?>();
            m_tevStageBlock       = new List <TevStage>();
            m_swapModeBlock       = new List <TevSwapMode>();
            m_swapTableBlock      = new List <TevSwapModeTable>();
            m_fogBlock            = new List <Fog>();
            m_alphaCompBlock      = new List <AlphaCompare>();
            m_blendModeBlock      = new List <BlendMode>();
            m_zModeBlock          = new List <ZMode>();
            m_zCompLocBlock       = new List <bool>();
            m_ditherBlock         = new List <bool>();
            NumColorChannelsBlock = new List <byte>();
            NumTexGensBlock       = new List <byte>();
            NumTevSTagesBlock     = new List <byte>();

            Materials = new List <Material>();
            #endregion

            Grendgine_Collada_Material[] GrendgineMaterials = scene.Library_Materials.Material;
            Grendgine_Collada_Effect[]   Effects            = scene.Library_Effects.Effect;
            Grendgine_Collada_Image[]    Images             = scene.Library_Images.Image;

            foreach (Batch bat in batches)
            {
                Grendgine_Collada_Material batMat    = GrendgineMaterials.First(x => x.Name == bat.MaterialName || x.ID == bat.MaterialName);
                Grendgine_Collada_Effect   batEffect = Effects.First(x => x.ID == batMat.Instance_Effect.URL.Remove(0, 1));
                Grendgine_Collada_Phong    phong     = batEffect.Profile_COMMON[0].Technique.Phong;

                Material mat = new Material(phong, bat, modelPath, Images);
                Materials.Add(mat);
            }
        }
예제 #2
0
        void CreateLibraryEffects(ref SimpleCollada data)
        {
            data.Library_Effects.Effect = new Grendgine_Collada_Effect[1];
            Grendgine_Collada_Effect efct = new Grendgine_Collada_Effect();

            efct.ID = "ID4";
            Grendgine_Collada_Profile_COMMON prof = new Grendgine_Collada_Profile_COMMON();

            prof.Technique          = new Grendgine_Collada_Effect_Technique_COMMON();
            prof.Technique.sID      = "COMMON";
            prof.Technique.Constant = new Grendgine_Collada_Constant();
            prof.Technique.Constant.Transparency             = new Grendgine_Collada_FX_Common_Float_Or_Param_Type();
            prof.Technique.Constant.Transparency.Float       = new Grendgine_Collada_SID_Float();
            prof.Technique.Constant.Transparency.Float.Value = 1;

            prof.Technique.Constant.Transparent        = new Grendgine_Collada_FX_Common_Color_Or_Texture_Type();
            prof.Technique.Constant.Transparent.Opaque = Grendgine_Collada_FX_Opaque_Channel.A_ONE;
            prof.Technique.Constant.Transparent.Color  = new Grendgine_Collada_Color();
            prof.Technique.Constant.Transparent.Color.Value_As_String = "0 0 0 1";

            efct.Profile_COMMON            = new Grendgine_Collada_Profile_COMMON[] { prof };
            data.Library_Effects.Effect[0] = efct;
        }
예제 #3
0
        public void load(Grendgine_Collada_Effect effect, Dictionary <string, string> image_collection, MaterialManager material_manager)
        {
            //------------------------------------------------------
            // Diffuse
            //------------------------------------------------------
            try
            {
                string texture_id = effect.Profile_COMMON[0].Technique.Phong.Diffuse.Texture.Texture.Replace("-sampler", "");
                string filename;

                if (image_collection.TryGetValue(texture_id, out filename))
                {
                    _diffuse_image      = new Image(filename, true);
                    _diffuse_image_unit = material_manager.addImage(_diffuse_image.loadBindless());
                    _diffuse_color      = new Vector3(0.0f);
                }
                else
                {
                    throw new Exception(Debug.DebugHelper.format("\t\tDiffuse Texture", "File Not Found"));
                }
            }
            catch
            {
                float[] temp_d = effect.Profile_COMMON[0].Technique.Phong.Diffuse.Color.Value();
                _diffuse_color = new Vector3(temp_d[0], temp_d[1], temp_d[2]);
            }

            // EMISSION
            _emission = effect.Profile_COMMON[0].Technique.Phong.Eission.Color.Value()[0] * 5.0f;


            //------------------------------------------------------
            // Specular
            //------------------------------------------------------
            try
            {
                string texture_id = effect.Profile_COMMON[0].Technique.Phong.Specular.Texture.Texture.Replace("-sampler", "");
                string filename;

                if (image_collection.TryGetValue(texture_id, out filename))
                {
                    _specular_image      = new Image(filename, true);
                    _specular_image_unit = material_manager.addImage(_specular_image.loadBindless());
                }
                else
                {
                    throw new Exception(Debug.DebugHelper.format("\t\tSpecular Texture", "File Not Found"));
                }
            }
            catch
            {
                float[] temp_d = effect.Profile_COMMON[0].Technique.Phong.Specular.Color.Value();
                _specular_color = new Vector3(temp_d[0], temp_d[1], temp_d[2]);
            }
            _specular_shininess = effect.Profile_COMMON[0].Technique.Phong.Shininess.Float.Value;


            //------------------------------------------------------
            // Normal
            //------------------------------------------------------
            try
            {
                string texture_id = effect.Profile_COMMON[0].Technique.Extra[0].Technique[0].Data[0].GetElementsByTagName("texture")[0].Attributes["texture"].Value.Replace("-sampler", "");
                string filename;

                if (image_collection.TryGetValue(texture_id, out filename))
                {
                    _normal_image      = new Image(filename, false);
                    _normal_image_unit = material_manager.addImage(_normal_image.loadBindless());
                }
                else
                {
                    throw new Exception(Debug.DebugHelper.format("\t\tNormal Texture", "File Not Found"));
                }
            }
            catch
            { }


            //------------------------------------------------------
            // Displacement
            //------------------------------------------------------
            try
            {
                string texture_id = effect.Profile_COMMON[0].Technique.Phong.Ambient.Texture.Texture.Replace("-sampler", "");
                string filename;

                if (image_collection.TryGetValue(texture_id, out filename))
                {
                    _displacement_image      = new Image(filename, false);
                    _displacement_image_unit = material_manager.addImage(_displacement_image.loadBindless());
                }
                else
                {
                    throw new Exception(Debug.DebugHelper.format("\t\tDisplacement Texture", "File Not Found"));
                }
            }
            catch
            { }


            //------------------------------------------------------
            // Parallax
            //------------------------------------------------------
            try
            {
                string texture_id = effect.Profile_COMMON[0].Technique.Phong.Reflective.Texture.Texture.Replace("-sampler", "");
                string filename;

                if (image_collection.TryGetValue(texture_id, out filename))
                {
                    _parallax_image      = new Image(filename, false);
                    _parallax_image_unit = material_manager.addImage(_parallax_image.loadBindless());
                }
                else
                {
                    throw new Exception(Debug.DebugHelper.format("\t\tParallax Texture", "File Not Found"));
                }
            }
            catch
            { }
        }