Пример #1
0
        public void OnChunkAdd(Terrain.TerrainChunkNode chunk, EventArgs e)
        {
            if (!chunk.HasController(typeof(GrassPopulator)))
            {
                GrassPopulator grass;
                chunk.AddController(grass = new GrassPopulator(PhysicsWorld, cam));
                grass.GenPatches(chunk, 5, 12);
            }
            if (!chunk.HasController(typeof(RockPopulator)))
            {
                RockPopulator rock;
                chunk.AddController(rock = new RockPopulator(PhysicsWorld, cam));
                rock.GenPatches(chunk, 3, 3);
            }
            if (!chunk.HasController(typeof(TreePopulator)))
            {
                TreePopulator tree;
                chunk.AddController(tree = new TreePopulator(PhysicsWorld, cam));
                tree.GenPatches(chunk, 2, 2);
            }


            /*
             *  for (int i = 0; i < chunk.hm.heights.Length; i++)
             *  {
             *      chunk.hm.heights[i] = 0f;
             *  }
             *  chunk.hm.RebuildTerrainMesh();*/
        }
Пример #2
0
 public void OnChunkRemove(Terrain.TerrainChunkNode chunk, EventArgs e)
 {
     if (chunk.HasController(typeof(GrassPopulator)))
     {
         GrassPopulator grass = (GrassPopulator)chunk.GetController(typeof(GrassPopulator));
         grass.Destroy();
         grass.Destroy();
     }
     if (chunk.HasController(typeof(RockPopulator)))
     {
         RockPopulator rock = (RockPopulator)chunk.GetController(typeof(RockPopulator));
         rock.Destroy();
         rock = null;
     }
 }
Пример #3
0
        public override void Init()
        {
            Environment.AmbientLight.Color.Set(0.2f, 0.15f, 0.1f, 1.0f);
            Environment.DirectionalLight.Direction.Set(1.9f, 0.35f, 1.9f).NormalizeStore();
            Environment.DirectionalLight.Color.Set(0.5f, 0.3f, 0.1f, 1.0f);
            ((PerspectiveCamera)Camera).FieldOfView = 75;

            ShadowMappingComponent smc;

            RenderManager.AddComponent(smc = new ShadowMappingComponent(cam, Environment));
            smc.RenderMode = ShadowMappingComponent.ShadowRenderMode.Forward;

            Geometry landscape = ((Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\landscape\\map.obj")).GetChildGeom(0);

            rootNode.AddChild(landscape);


            landscape.SetShader(typeof(Terrain.TerrainShader));
            Material terrainMaterial = new Material();

            Texture grass     = AssetManager.LoadTexture(Assets.AssetManager.GetAppPath() + "\\textures\\grass.jpg");
            Texture grass_nrm = AssetManager.LoadTexture(Assets.AssetManager.GetAppPath() + "\\textures\\grass_NRM.jpg");
            Texture dirt      = AssetManager.LoadTexture(Assets.AssetManager.GetAppPath() + "\\textures\\dirt.jpg");
            Texture dirt_nrm  = AssetManager.LoadTexture(Assets.AssetManager.GetAppPath() + "\\textures\\dirt_NRM.jpg");



            terrainMaterial.SetValue(TerrainMaterial.TEXTURE_DIFFUSE0, grass);
            terrainMaterial.SetValue(TerrainMaterial.TEXTURE_SCALE_0, 16);
            terrainMaterial.SetValue(TerrainMaterial.TEXTURE_NORMAL0, grass_nrm);
            terrainMaterial.SetValue(TerrainMaterial.TEXTURE_DIFFUSE_SLOPE, dirt);
            terrainMaterial.SetValue(TerrainMaterial.TEXTURE_NORMAL_SLOPE, dirt_nrm);
            terrainMaterial.SetValue(TerrainMaterial.TEXTURE_SCALE_SLOPE, 16);
            terrainMaterial.SetValue(Material.MATERIAL_CASTSHADOWS, false);
            terrainMaterial.SetValue(Material.SHININESS, 0.15f);
            terrainMaterial.SetValue(Material.ROUGHNESS, 0.8f);


            landscape.Material = terrainMaterial;

            landscape.SetLocalScale(new Math.Vector3f(3f, 2f, 3f));

            PhysicsWorld.AddObject(landscape, 0.0f);



            AddComponent(new SkydomeComponent());


            //  Rendering.NormalMapRenderer nmr;
            //  RenderManager.AddComponent(nmr = new Rendering.NormalMapRenderer(Environment, Camera));
            //   RenderManager.PostProcessor.PostFilters.Add(new Rendering.PostProcess.Filters.SSAOFilter(nmr));


            GrassPopulator grassPop;

            rootNode.AddController(grassPop = new GrassPopulator(PhysicsWorld, cam));
            grassPop.GenPatches(12, 3, 128);


            RenderManager.PostProcessor.PostFilters.Add(new FXAAFilter());
        }