public void ImportHeightMapAndGridMap(string heightmapFile, string gridmapFile = null) { if (File.Exists(heightmapFile)) { heightmapContent = new ContentManager(graphicsDeviceControl1.Services, contentBuilder.OutputDirectory); contentBuilder.Add(heightmapFile, "heightmap", null, "TextureProcessor"); bool gridmapFileExists = !string.IsNullOrEmpty(gridmapFile) && File.Exists(gridmapFile); if (gridmapFileExists) { contentBuilder.Add(gridmapFile, "gridmap", null, "TextureProcessor"); } contentBuilder.Build(); camera.Detach(Terrain.TerrainIndexer); Terrain = new Terrain(GraphicsDevice, camera, heightmapContent.Load <Texture2D>("heightmap"), heightmapFile, effectFile, terrainTextureFile); Terrain.Texture = grassTexture; terrainBrush.Terrain = Terrain; if (gridmapFileExists) { List <string> assets = Grid.RoadAssetFiles; Grid = new Grid(Terrain, 8, camera, GraphicsDevice, basicEffect); Grid.RoadModel = contentManager.Load <Model>("jalan_raya"); Grid.RoadModel_belok = contentManager.Load <Model>("jalan_raya_belok"); Grid.GridMapFile = gridmapFile; Grid.GridMap = heightmapContent.Load <Texture2D>("gridmap"); Grid.ImportGridMap(); Grid.RoadAssetFiles = assets; gridPointer = new GridPointer(Grid); gridPointers = new List <GridPointer>(); } camera.Attach(Terrain.TerrainIndexer); camera.Notify(); } }
private void Editor_Load(object sender, EventArgs e) { string errorBuild = ""; try { mapModel = new EditorModel.MapModel(); mouseMoving = false; mouseEventArgs = null; tempMouseX = tempMouseY = -1; text = ""; basicEffect = new BasicEffect(graphicsDeviceControl1.GraphicsDevice); contentBuilder = ContentBuilder.Instance; contentManager = new ContentManager(graphicsDeviceControl1.Services, contentBuilder.OutputDirectory); heightmapContent = new ContentManager(graphicsDeviceControl1.Services, contentBuilder.OutputDirectory); spriteBatch = new SpriteBatch(graphicsDeviceControl1.GraphicsDevice); //MessageBox.Show(GraphicsDevice.Adapter.Description); effectFile = AssemblyDirectory + "\\Assets\\effects.fx"; terrainTextureFile = AssemblyDirectory + "\\Assets\\Textures\\grass.dds"; //importer reference: http://msdn.microsoft.com/en-us/library/bb447762%28v=xnagamestudio.20%29.aspx contentBuilder.Add(AssemblyDirectory + "\\Assets\\SegoeUI.spritefont", "SegoeUI.spritefont", null, "FontDescriptionProcessor"); contentBuilder.Add(effectFile, "effects", null, "EffectProcessor"); contentBuilder.Add(AssemblyDirectory + "\\Assets\\brush.bmp", "brush", null, "TextureProcessor"); contentBuilder.Add(terrainTextureFile, "grass", null, "TextureProcessor"); contentBuilder.Add(AssemblyDirectory + "\\Assets\\video_camera.png", "video_camera", null, "TextureProcessor"); contentBuilder.Add(AssemblyDirectory + "\\Assets\\Roads\\jalan_raya.fbx", "jalan_raya", null, "ModelProcessor"); contentBuilder.Add(AssemblyDirectory + "\\Assets\\Roads\\jalan_raya_belok.fbx", "jalan_raya_belok", null, "ModelProcessor"); contentBuilder.Add(AssemblyDirectory + "\\Assets\\heightmap2.png", "heightmap", null, "TextureProcessor"); string error = contentBuilder.Build(); if (!string.IsNullOrEmpty(error)) { throw new Exception(error); } errorBuild = contentBuilder.Build(); spriteFont = contentManager.Load <SpriteFont>("SegoeUI.spritefont"); terrainEffect = contentManager.Load <Effect>("effects"); brushHeightMap = contentManager.Load <Texture2D>("brush"); grassTexture = contentManager.Load <Texture2D>("grass"); camera = new Camera(GraphicsDevice); camera.Position = new Vector3(0, 50, 0); camera.AspectRatio = graphicsDeviceControl1.GraphicsDevice.Viewport.AspectRatio; camera.Rotate(20, 45, 0); camera.Attach(this); CheckIsOrthographic(); string heightMapFile = AssemblyDirectory + "\\test_HeightMap.png"; Terrain = new Terrain(GraphicsDevice, camera, heightMapFile, effectFile, terrainTextureFile, 128, 128); Terrain.Texture = grassTexture; //heightmapContent = new ContentManager(graphicsDeviceControl1.Services, contentBuilder.OutputDirectory); //quadTreeTerrain = new QuadTree(Vector3.Zero, 1025, 1025, camera, GraphicsDevice, 1); //quadTreeTerrain.Effect.Texture = grassTexture; editorMode = new EditorMode_Select(this); Selected = null; selectedBoundingBox = new ModelBoundingBox(graphicsDeviceControl1.GraphicsDevice, camera, false); selectedBoundingBox.SpriteBatch = spriteBatch; selectedBoundingBox.SpriteFont = spriteFont; CheckActiveTransformMode(); terrainBrush = new TerrainBrush(GraphicsDevice, Terrain, brushHeightMap); terrainBrush.BasicEffect = basicEffect; Grid = new Grid(Terrain, 8, camera, GraphicsDevice, basicEffect); Grid.RoadModel = contentManager.Load <Model>("jalan_raya"); Grid.RoadModel_belok = contentManager.Load <Model>("jalan_raya_belok"); Grid.GridMapFile = AssemblyDirectory + "\\Assets\\gridmap.png"; Grid.ExportGridMap(); Grid.RoadAssetFiles.Add(AssemblyDirectory + "\\Assets\\Roads\\jalan_raya.fbx"); Grid.RoadAssetFiles.Add(AssemblyDirectory + "\\Assets\\Roads\\jalan_raya_belok.fbx"); Grid.RoadAssetFiles.Add(AssemblyDirectory + "\\Assets\\Roads\\texture_jalan_raya.png"); Grid.RoadAssetFiles.Add(AssemblyDirectory + "\\Assets\\Roads\\texture_jalan_raya_belok.png"); gridPointer = new GridPointer(Grid); gridPointers = new List <GridPointer>(); mapModel.MainCamera.Texture = contentManager.Load <Texture2D>("video_camera"); mapModel.MainCamera.GraphicsDevice = GraphicsDevice; mapModel.MainCamera.Camera = camera; mapModel.MainCamera.BasicEffect = basicEffect; timer = new System.Threading.Timer((c) => SetGravity(), null, Timeout.Infinite, Timeout.Infinite); camera.Notify(); } catch (Exception ex) { if (!DesignMode) { if (mainUserControl != null && mainUserControl.StatusStrip1 != null) { mainUserControl.StatusStrip1.Text = ex.Message + "\r\n" + ex.StackTrace; } else { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); } } } }