public Model(string path, string meshName, GameObject parent = null) : base("mesh", parent) { var asset = AssetLoader.UseElement(path + meshName); if (asset != null) { Model model = asset as Model; Console.WriteLine("Loading model from table"); if (model != null) { meshes = model.meshes; shader = model.shader; this.meshName = meshName; this.path = path; } } else { this.path = path; this.meshName = meshName; var context = new AssimpContext(); shader = new Shader("Assets/Shaders/mesh.glsl"); shader.Use(); shader.SetMatrix4("model", Matrix4.Identity); shader.SetMatrix4("view", ref Camera.main.view); shader.SetMatrix4("projection", ref Camera.main.projection); shader.SetVector3("lightColor", LevelManager.activeScene.GetSceneColor()); shader.SetVector3("light.lightPos", LevelManager.activeScene.lightSources[0].Parent.getMatrix4X4().Translation); meshes = new List <Mesh>(); var scene = context.ImportFile(path + meshName, PostProcessSteps.Triangulate | PostProcessSteps.FlipUVs | PostProcessSteps.GenerateNormals); if (scene != null) { ProcessNode(scene.RootNode, scene); scene.Clear(); } AssetLoader.AddElement(path + meshName, this); Console.WriteLine(meshName + " has " + meshes.Count); } }
public Shader(string path) { var asset = AssetLoader.UseElement(path); if (asset != null) { Shader shader = (Shader)asset; ProgramId = shader.ProgramId; this.path = path; } else { this.path = path; string fragmentShader, vertexShader; ProgramId = GL.CreateProgram(); ParseShader(path, out vertexShader, out fragmentShader); int fs = CompileShader(fragmentShader, ShaderType.FragmentShader); int vs = CompileShader(vertexShader, ShaderType.VertexShader); GL.AttachShader(ProgramId, fs); GL.AttachShader(ProgramId, vs); GL.LinkProgram(ProgramId); GL.ValidateProgram(ProgramId); //clean intermediates GL.DeleteShader(vs); GL.DeleteShader(fs); AssetLoader.AddElement(path, this); } }