Esempio n. 1
0
        public SkyLight CreateSkyLight(Dictionary <string, Texture> textures)
        {
            var        assembly     = typeof(SkyLight).Assembly;
            var        types        = assembly.GetTypes();
            MethodInfo createMethod = null;

            for (int i = 0; i < types.Length; i++)
            {
                if (types[i].IsAbstract || !types[i].IsSubclassOf(typeof(SkyLight)))
                {
                    continue;
                }
                var attributes = types[i].GetCustomAttributes(typeof(SkyLightTypeAttribute), true);
                if (attributes != null && attributes.Length > 0)
                {
                    var shaderAttribute = attributes[0] as SkyLightTypeAttribute;
                    if (shaderAttribute != null && shaderAttribute.skyLightType == shaderType)
                    {
                        var method = types[i].GetMethod("Create", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
                        if (method != null)
                        {
                            createMethod = method;
                            break;
                        }
                    }
                }
            }

            if (createMethod == null)
            {
                return(null);
            }
            SkyLight sky = createMethod.Invoke(null, new object[] { }) as SkyLight;

            if (sky == null)
            {
                return(null);
            }

            if (shaderParams != null)
            {
                for (int i = 0; i < shaderParams.Count; i++)
                {
                    SceneSerialization.SetParameterToObject(sky, shaderParams[i].paramName, shaderParams[i].paramValue, textures);
                }
            }

            Log.Info($"天空盒创建成功:{sky.GetType()}");


            return(sky);
        }
Esempio n. 2
0
        public MaterialShader CreateShader(Dictionary <string, Texture> textures)
        {
            var        assembly     = typeof(MaterialShader).Assembly;
            var        types        = assembly.GetTypes();
            MethodInfo createMethod = null;

            for (int i = 0; i < types.Length; i++)
            {
                if (types[i].IsAbstract || !types[i].IsSubclassOf(typeof(MaterialShader)))
                {
                    continue;
                }
                var attributes = types[i].GetCustomAttributes(typeof(ShaderTypeAttribute), true);
                if (attributes != null && attributes.Length > 0)
                {
                    var shaderAttribute = attributes[0] as ShaderTypeAttribute;
                    if (shaderAttribute != null && shaderAttribute.shaderType == shaderType)
                    {
                        var method = types[i].GetMethod("Create", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
                        if (method != null)
                        {
                            createMethod = method;
                            break;
                        }
                    }
                }
            }
            if (createMethod == null)
            {
                Log.Warn($"Shader初时化失败!未找到该类型的Shader:{shaderType}");
                return(null);
            }
            MaterialShader shader = createMethod.Invoke(null, new object[] { }) as MaterialShader;

            if (shader == null)
            {
                return(null);
            }
            if (shaderParams != null)
            {
                for (int i = 0; i < shaderParams.Count; i++)
                {
                    SceneSerialization.SetParameterToObject(shader, shaderParams[i].paramName, shaderParams[i].paramValue, textures);
                }
            }

            return(shader);
        }
Esempio n. 3
0
        public void CreatePrimitive(string scenePath, Dictionary <string, MaterialShader> shadersDic, Dictionary <string, Mesh[]> meshDic, List <PrimitiveBase> output)
        {
            //Dictionary<string, PrimitiveParamDataSerialization> geoParamDic = new Dictionary<string, PrimitiveParamDataSerialization>();
            //for (int i = 0; i < geoParams.Count; i++)
            //{
            //    geoParamDic[geoParams[i].paramName] = geoParams[i];
            //}

            List <MaterialShader> s = new List <MaterialShader>();

            for (int i = 0; i < shaders.Count; i++)
            {
                if (shadersDic.ContainsKey(shaders[i].shaderName))
                {
                    s.Add(shadersDic[shaders[i].shaderName]);
                }
            }

            System.Type[]          types = typeof(PrimitiveBase).Assembly.GetTypes();
            System.Type            geoSerializationType = typeof(PrimitiveSerialization);
            PrimitiveSerialization geoSerialization     = null;

            for (int i = 0; i < types.Length; i++)
            {
                if (types[i].IsAbstract)
                {
                    continue;
                }
                if (types[i].IsSubclassOf(geoSerializationType))
                {
                    var attributes = types[i].GetCustomAttributes(typeof(PrimitiveAnalyseAttribute), false);
                    if (attributes == null || attributes.Length == 0)
                    {
                        continue;
                    }
                    var geoattribute = attributes[0] as PrimitiveAnalyseAttribute;
                    if (geoattribute == null)
                    {
                        continue;
                    }
                    if (geoattribute.type == type)
                    {
                        geoSerialization = System.Activator.CreateInstance(types[i]) as PrimitiveSerialization;
                        break;
                    }
                }
            }

            if (geoSerialization == null)
            {
                Log.Warn($"几何体创建失败!不确定的几何体类型:{type}");
                return;
            }

            for (int i = 0; i < geoParams.Count; i++)
            {
                SceneSerialization.SetParameterToObject(geoSerialization, geoParams[i].paramName, geoParams[i].paramValue, null);
            }

            geoSerialization.meshes  = meshDic;
            geoSerialization.shaders = s;
            geoSerialization.GenerateGeometry(scenePath, output);
        }