public new MyMesh createMeshInstance(string name, Vector3 translation, Vector3 rotation, Vector3 scale) { if (this.parentInstance != null) { throw new Exception("No se puede crear una instancia de otra malla instancia. Hay que partir del original."); } //Crear instancia MyMesh instance = new MyMesh(name, this, translation, rotation, scale); //instance.effect = effect; //BoundingBox instance.boundingBox = new TgcBoundingBox(this.boundingBox.PMin, this.boundingBox.PMax); instance.updateBoundingBox(); instance.enabled = true; return(instance); }
public override void init() { Device d3dDevice = GuiController.Instance.D3dDevice; MyMediaDir = GuiController.Instance.AlumnoEjemplosMediaDir + "Kamikaze3D\\EscenarioPrueba\\"; MyObjectsDir = GuiController.Instance.AlumnoEjemplosMediaDir + "Kamikaze3D\\Patrulla2\\"; MyShaderDir = GuiController.Instance.AlumnoEjemplosMediaDir + "Kamikaze3D\\Shaders\\"; //Crear loader TgcSceneLoader loader = new TgcSceneLoader(); //Configurar MeshFactory customizado loader.MeshFactory = new MyCustomMeshFactory(); // ------------------------------------------------------------ //Cargar la escena scene = loader.loadSceneFromFile(MyMediaDir + "escenarioPrueba-TgcScene.xml"); GuiController.Instance.RotCamera.CameraDistance = 600; //Carga la patrulla scene2 = loader.loadSceneFromFile(MyObjectsDir + "autoPolicia2-TgcScene.xml"); patrulla = (MyMesh)scene2.Meshes[0]; patrulla.Scale = new Vector3(2f, 2f, 2f); patrulla.Position = new Vector3(0f, 1f, 0f); //Cargar Shader string compilationErrors; //PhongShading.fx --> ShadowMap.fx effect = Effect.FromFile(d3dDevice, MyShaderDir + "ShadowMap.fx", null, null, ShaderFlags.None, null, out compilationErrors); if (effect == null) { throw new Exception("Error al cargar shader. Errores: " + compilationErrors); } // le asigno el efecto a las mallas foreach (MyMesh T in scene.Meshes) { T.Scale = new Vector3(2f, 2f, 2f); T.effect = effect; } patrulla.effect = effect; //-------------------------------------------------------------------------------------- // Format.R32F // Format.X8R8G8B8 g_pShadowMap = new Texture(d3dDevice, SHADOWMAP_SIZE, SHADOWMAP_SIZE, 1, Usage.RenderTarget, Format.R32F, Pool.Default); // tengo que crear un stencilbuffer para el shadowmap manualmente // para asegurarme que tenga la el mismo tamaño que el shadowmap, y que no tenga // multisample, etc etc. g_pDSShadow = d3dDevice.CreateDepthStencilSurface(SHADOWMAP_SIZE, SHADOWMAP_SIZE, DepthFormat.D24S8, MultiSampleType.None, 0, true); // por ultimo necesito una matriz de proyeccion para el shadowmap, ya // que voy a dibujar desde el pto de vista de la luz. // El angulo tiene que ser mayor a 45 para que la sombra no falle en los extremos del cono de luz // de hecho, un valor mayor a 90 todavia es mejor, porque hasta con 90 grados es muy dificil // lograr que los objetos del borde generen sombras Control panel3d = GuiController.Instance.Panel3d; float aspectRatio = (float)panel3d.Width / (float)panel3d.Height; g_mShadowProj = Matrix.PerspectiveFovLH(Geometry.DegreeToRadian(80), aspectRatio, 10, 500); d3dDevice.Transform.Projection = Matrix.PerspectiveFovLH(Geometry.DegreeToRadian(45.0f), aspectRatio, near_plane, far_plane); //Aca se agrega la flecha que facilita ver la direccion de la luz //arrow = new TgcArrow(); //arrow.Thickness = 1f; //arrow.HeadSize = new Vector2(2f, 2f); //arrow.BodyColor = Color.Blue; cont = 0; GuiController.Instance.RotCamera.targetObject(scene.Meshes[0].BoundingBox); float K = 100; GuiController.Instance.Modifiers.addVertex3f("LightLookFrom", new Vector3(-K, -K, -K), new Vector3(K, K, K), new Vector3(0, 95, 0)); GuiController.Instance.Modifiers.addVertex3f("LightLookAt", new Vector3(-K, -K, -K), new Vector3(K, K, K), new Vector3(0, 95, 0)); //GuiController.Instance.Modifiers.addFloat("Ambient", 0, 1, 0.5f); //GuiController.Instance.Modifiers.addFloat("Diffuse", 0, 1, 0.6f); //GuiController.Instance.Modifiers.addFloat("Specular", 0, 1, 0.5f); //GuiController.Instance.Modifiers.addFloat("SpecularPower", 1, 100, 16); }
/* #region Configuracion * public override string getCategory() * { * return "AlumnoEjemplos"; * } * * public override string getName() * { * return "PatrullaPhong"; * } * * public override string getDescription() * { * return "PatrullaPhong"; * } #endregion */ public /*override*/ void init() { Device d3dDevice = GuiController.Instance.D3dDevice; //MyMediaDir = GuiController.Instance.AlumnoEjemplosMediaDir + "Kamikaze3D\\EscenarioPrueba\\"; MyObjectsDir = GuiController.Instance.AlumnoEjemplosMediaDir + "Kamikaze3D\\Patrulla2\\"; MyShaderDir = GuiController.Instance.AlumnoEjemplosMediaDir + "Kamikaze3D\\Shaders\\"; //Crear loader TgcSceneLoader loader = new TgcSceneLoader(); //Configurar MeshFactory customizado loader.MeshFactory = new MyCustomMeshFactory(); // Cargo la escena del cornell box. //scene = loader.loadSceneFromFile(MyMediaDir + "escenarioPrueba-TgcScene.xml"); //Carga la patrulla scene2 = loader.loadSceneFromFile(MyObjectsDir + "autoPolicia2-TgcScene.xml"); patrulla = (MyMesh)scene2.Meshes[0]; patrulla.Scale = new Vector3(0.9f, 0.9f, 0.9f); patrulla.Position = new Vector3(1920f, 3f, 1800f); //mesh = (MyMesh)scene.Meshes[0]; //Cargar Shader string compilationErrors; effect = Effect.FromFile(d3dDevice, MyShaderDir + "PhongShading.fx", null, null, ShaderFlags.None, null, out compilationErrors); if (effect == null) { throw new Exception("Error al cargar shader. Errores: " + compilationErrors); } // configurar la tecnica effect.Technique = "DefaultTechnique"; // le asigno el efecto a las mallas //mesh.effect = effect; patrulla.effect = effect; GuiController.Instance.Modifiers.addVertex3f("LightPosition", new Vector3(-2000f, -2000f, -2000f), new Vector3(2000f, 2000f, 2000f), new Vector3(0f, 40f, -10f)); GuiController.Instance.Modifiers.addFloat("Ambient", 0, 1, 0.5f); GuiController.Instance.Modifiers.addFloat("Diffuse", 0, 1, 0.6f); GuiController.Instance.Modifiers.addFloat("Specular", 0, 1, 0.5f); //GuiController.Instance.Modifiers.addColor("AmbientColor", Color.Gray); //GuiController.Instance.Modifiers.addColor("DiffuseColor", Color.Gray); //GuiController.Instance.Modifiers.addColor("SpecularColor", Color.Blue); GuiController.Instance.Modifiers.addFloat("SpecularPower", 1, 100, 16); //Agregar Valores para la Niebla GuiController.Instance.Modifiers.addBoolean("Enabled", "Enabled", true); GuiController.Instance.Modifiers.addFloat("startDistance", 1, 2000, 300); GuiController.Instance.Modifiers.addFloat("endDistance", 1, 4000, 1200); GuiController.Instance.Modifiers.addFloat("density", 0, 10, 1); GuiController.Instance.Modifiers.addColor("color", Color.Gray); t = 0; //Crear caja para indicar ubicacion de la luz //lightBox = TgcBox.fromSize(new Vector3(5, 5, 5), Color.Yellow); // Creo el viewport, para la iluminacion dinamica //GuiController.Instance.RotCamera.setCamera(new Vector3(-10f, 40f, -10f), 300); ViewF = d3dDevice.Viewport; // Creo la luz para el fixed pipeline d3dDevice.Lights[0].Type = LightType.Point; d3dDevice.Lights[0].Diffuse = Color.FromArgb(255, 255, 255, 255); d3dDevice.Lights[0].Specular = Color.FromArgb(255, 255, 255, 255); d3dDevice.Lights[0].Attenuation0 = 0.0f; d3dDevice.Lights[0].Range = 50000.0f; d3dDevice.Lights[0].Enabled = true; //d3dDevice.Lights[0].AmbientColor = ColorValue.FromColor((Color)GuiController.Instance.Modifiers["AmbientColor"]); //d3dDevice.Lights[0].DiffuseColor = ColorValue.FromColor((Color)GuiController.Instance.Modifiers["DiffuseColor"]); //d3dDevice.Lights[0].SpecularColor = ColorValue.FromColor((Color)GuiController.Instance.Modifiers["SpecularColor"]); }