/// <summary> /// Renderiza la malla, si esta habilitada /// </summary> public void render() { if (!enabled) { return; } Device device = GuiController.Instance.D3dDevice; TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager; //Aplicar transformaciones updateMeshTransform(); //Cargar VertexDeclaration device.VertexDeclaration = vertexDeclaration; //Activar AlphaBlending si corresponde activateAlphaBlend(); //Renderizar segun el tipo de render de la malla switch (renderType) { case MeshRenderType.VERTEX_COLOR: //Hacer reset de texturas y materiales texturesManager.clear(0); texturesManager.clear(1); device.Material = TgcD3dDevice.DEFAULT_MATERIAL; //Dibujar mesh d3dMesh.DrawSubset(0); break; case MeshRenderType.DIFFUSE_MAP: //Hacer reset de Lightmap texturesManager.clear(1); //Dibujar cada subset con su Material y DiffuseMap correspondiente for (int i = 0; i < materials.Length; i++) { device.Material = materials[i]; texturesManager.set(0, diffuseMaps[i]); d3dMesh.DrawSubset(i); } break; case MeshRenderType.DIFFUSE_MAP_AND_LIGHTMAP: //Cargar Lightmap texturesManager.set(1, lightMap); device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.Modulate); device.SetTextureStageState(1, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor); device.SetTextureStageState(1, TextureStageStates.ColorArgument2, (int)TextureArgument.Current); //Dibujar cada subset con su Material y DiffuseMap correspondiente for (int i = 0; i < materials.Length; i++) { device.Material = materials[i]; texturesManager.set(0, diffuseMaps[i]); //Aplicar operacion para Lightmap device.SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.Modulate); device.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor); device.SetTextureStageState(0, TextureStageStates.ColorArgument2, (int)TextureArgument.Diffuse); d3dMesh.DrawSubset(i); } break; } //Desactivar alphaBlend resetAlphaBlend(); }
/// <summary> /// Renderiza la malla, si esta habilitada /// </summary> public void render() { if (!enabled) { return; } Device device = GuiController.Instance.D3dDevice; TgcTexture.Manager texturesManager = GuiController.Instance.TexturesManager; //Aplicar transformaciones updateMeshTransform(); //Cargar VertexDeclaration device.VertexDeclaration = vertexDeclaration; //Activar AlphaBlending si corresponde activateAlphaBlend(); //Cargar matrices para el shader setShaderMatrix(); //Renderizar segun el tipo de render de la malla effect.Technique = this.technique; int numPasses = effect.Begin(0); switch (renderType) { case MeshRenderType.VERTEX_COLOR: //Hacer reset de texturas texturesManager.clear(0); texturesManager.clear(1); //Iniciar Shader e iterar sobre sus Render Passes for (int n = 0; n < numPasses; n++) { //Iniciar pasada de shader effect.BeginPass(n); d3dMesh.DrawSubset(0); effect.EndPass(); } break; case MeshRenderType.DIFFUSE_MAP: //Hacer reset de Lightmap texturesManager.clear(1); //Iniciar Shader e iterar sobre sus Render Passes for (int n = 0; n < numPasses; n++) { //Dibujar cada subset con su DiffuseMap correspondiente for (int i = 0; i < diffuseMaps.Length; i++) { //Setear textura en shader texturesManager.shaderSet(effect, "texDiffuseMap", diffuseMaps[i]); //Iniciar pasada de shader effect.BeginPass(n); d3dMesh.DrawSubset(i); effect.EndPass(); } } break; case MeshRenderType.DIFFUSE_MAP_AND_LIGHTMAP: //Iniciar Shader e iterar sobre sus Render Passes for (int n = 0; n < numPasses; n++) { //Cargar lightmap texturesManager.shaderSet(effect, "texLightMap", lightMap); //Dibujar cada subset con su Material y su DiffuseMap correspondiente for (int i = 0; i < diffuseMaps.Length; i++) { //Setear textura en shader texturesManager.shaderSet(effect, "texDiffuseMap", diffuseMaps[i]); //Iniciar pasada de shader effect.BeginPass(n); d3dMesh.DrawSubset(i); effect.EndPass(); } } break; } //Finalizar shader effect.End(); //Desactivar alphaBlend resetAlphaBlend(); }
/// <summary> /// Crea todos los modulos necesarios de la aplicacion /// </summary> internal void initGraphics(MainForm mainForm, Control panel3d) { this.mainForm = mainForm; this.panel3d = panel3d; this.fullScreenPanel = new FullScreenPanel(); panel3d.Focus(); //Iniciar graficos this.tgcD3dDevice = new TgcD3dDevice(panel3d); this.texturesManager = new TgcTexture.Manager(); this.tgcD3dDevice.OnResetDevice(tgcD3dDevice.D3dDevice, null); //Iniciar otras herramientas this.texturesPool = new TgcTexture.Pool(); this.logger = new Logger(mainForm.LogConsole); this.text3d = new TgcDrawText(tgcD3dDevice.D3dDevice); this.tgcD3dInput = new TgcD3dInput(mainForm, panel3d); this.fpsCamera = new TgcFpsCamera(); this.rotCamera = new TgcRotationalCamera(); this.thirdPersonCamera = new TgcThirdPersonCamera(); this.axisLines = new TgcAxisLines(tgcD3dDevice.D3dDevice); this.userVars = new TgcUserVars(mainForm.getDataGridUserVars()); this.modifiers = new TgcModifiers(mainForm.getModifiersPanel()); this.elapsedTime = -1; this.frustum = new TgcFrustum(); this.mp3Player = new TgcMp3Player(); this.directSound = new TgcDirectSound(); this.fog = new TgcFog(); this.currentCamera = this.rotCamera; this.customRenderEnabled = false; this.drawer2D = new TgcDrawer2D(); this.shaders = new TgcShaders(); //toogles this.rotCamera.Enable = true; this.fpsCamera.Enable = false; this.thirdPersonCamera.Enable = false; this.fpsCounterEnable = true; this.axisLines.Enable = true; //Cargar algoritmos exampleLoader = new ExampleLoader(); examplesDir = System.Environment.CurrentDirectory + "\\" + ExampleLoader.EXAMPLES_DIR + "\\"; examplesMediaDir = examplesDir + "Media" + "\\"; alumnoEjemplosDir = System.Environment.CurrentDirectory + "\\" + "AlumnoEjemplos" + "\\"; alumnoEjemplosMediaDir = alumnoEjemplosDir + "AlumnoMedia" + "\\"; exampleLoader.loadExamplesInGui(mainForm.TreeViewExamples, new string[] { examplesDir, alumnoEjemplosDir }); //Cargar shaders del framework this.shaders.loadCommonShaders(); //Cargar ejemplo default TgcExample defaultExample = exampleLoader.getExampleByName(mainForm.Config.defaultExampleName, mainForm.Config.defaultExampleCategory); executeExample(defaultExample); }