/// <summary> /// Constructor. /// </summary> /// <param name="document">Scene document.</param> /// <param name="entity">Entity owning this proxy.</param> /// <param name="quadTerrain">Quad terrain to proxy.</param> public QuadTerrainProxy(SceneDocument document, EntityProxy entity, QuadTerrainComponent quadTerrain) : base(document, entity) { base.name = defaultName; this.quadTerrain = quadTerrain; // Add to entity base.Entity.Components.Add(quadTerrain); }
/// <summary> /// Saves the height map data at the specified position and area. /// </summary> /// <returns>Undo buffer information.</returns> /// <param name="terrain">Terrain to get undo information from.</param> /// <param name="xs">X position of top-left corner.</param> /// <param name="ys">Y position of top-left corner.</param> /// <param name="dimension">Dimension of undo area.</param> public Documents.SceneDocument.TerrainDeformUndoInfo?GetHeightMapUndo(QuadTerrainComponent terrain, int xs, int ys, int dimension) { // Create undo array float[] undo = new float[dimension * dimension]; // Get data float[] data = terrain.GetHeight(); // Capture all valid height pixels for (int y = ys; y < ys + dimension; y++) { // Cannot go out of bounds if (y < 0 || y >= mapDimension) { continue; } for (int x = xs; x < xs + dimension; x++) { // Cannot go out of bounds if (x < 0 || x >= mapDimension) { continue; } // Get height pixel float value = data[y * mapDimension + x]; // Save height pixel int xd = (x - xs); int yd = (y - ys); if (xd < 0 || xd >= dimension) { continue; } if (yd < 0 || yd >= dimension) { continue; } undo[yd * dimension + xd] = value; } } // Create undo information Documents.SceneDocument.TerrainDeformUndoInfo undoInfo = new Documents.SceneDocument.TerrainDeformUndoInfo { TerrainEditor = this, TerrainComponent = terrain, HeightMap = heightMapData, UndoBuffer = undo, Position = new Microsoft.Xna.Framework.Point(xs, ys), Dimension = dimension, }; return(undoInfo); }
/// <summary> /// Restores undo information to the height map. /// </summary> /// <param name="undoInfo">Undo information.</param> public void RestoreHeightMapUndo(Documents.SceneDocument.TerrainDeformUndoInfo undoInfo) { // Get area of undo operation int xs = undoInfo.Position.X; int ys = undoInfo.Position.Y; int dimension = undoInfo.Dimension; // Set all valid height pixels QuadTerrainComponent terrain = undoInfo.TerrainComponent; float[] data = terrain.GetHeight(); for (int y = ys; y < ys + dimension; y++) { // Cannot go out of bounds if (y < 0 || y >= mapDimension) { continue; } for (int x = xs; x < xs + dimension; x++) { // Cannot go out of bounds if (x < 0 || x >= mapDimension) { continue; } // Get height pixel int xd = (x - xs); int yd = (y - ys); if (xd < 0 || xd >= dimension) { continue; } if (yd < 0 || yd >= dimension) { continue; } float value = undoInfo.UndoBuffer[yd * dimension + xd]; // Set height pixel data[y * terrain.MapDimension + x] = value; } } // Set height back in editor if this is active terrain if (terrain == this.terrain) { heightMapData = data; UpdatePreview(); } // Set data back on terrain terrain.SetHeight(data); }
/// <summary> /// Sync editor textures with terrain. /// </summary> /// <param name="terrain">Terrain to sync textures from.</param> private void InitialiseTexturePreviews(QuadTerrainComponent terrain) { // Set each texture preview SetTexturePreview(terrain, 0, Texture0PictureBox); SetTexturePreview(terrain, 1, Texture1PictureBox); SetTexturePreview(terrain, 2, Texture2PictureBox); SetTexturePreview(terrain, 3, Texture3PictureBox); SetTexturePreview(terrain, 4, Texture4PictureBox); SetTexturePreview(terrain, 5, Texture5PictureBox); SetTexturePreview(terrain, 6, Texture6PictureBox); SetTexturePreview(terrain, 7, Texture7PictureBox); SetTexturePreview(terrain, 8, Texture8PictureBox); }
/// <summary> /// Sets the texture preview from specified index. /// </summary> /// <param name="terrain">Terrain component.</param> /// <param name="index">Texture index.</param> /// <param name="pictureBox">Picture box to receive image.</param> private void SetTexturePreview(QuadTerrainComponent terrain, int index, PictureBox pictureBox) { // Get texture description from index QuadTerrainComponent.DaggerfallTerrainTexture textureDesc = terrain.GetDaggerfallTexture(index); // Get Daggerfall image file imageReader.LibraryType = LibraryTypes.Texture; DFImageFile imageFile = imageReader.GetImageFile(TextureFile.IndexToFileName(textureDesc.Archive)); // Get managed bitmap and set on picture box Bitmap textureBitmap = imageFile.GetManagedBitmap(textureDesc.Record, 0, true, false); pictureBox.Image = textureBitmap; pictureBox.Refresh(); }
/// <summary> /// Sets terrain component to edit. /// </summary> /// <param name="terrain">Terrain component.</param> public void SetTerrain(QuadTerrainComponent terrain, Documents.SceneDocument document) { // Store reference to terrain this.terrain = terrain; this.document = document; // Get arena2 path from active core this.arena2Path = terrain.Core.Arena2Path; this.imageReader.Arena2Path = this.arena2Path; // Load terrain maps InitialiseMaps(terrain); // Load texture previews InitialiseTexturePreviews(terrain); }
/// <summary> /// Creates a new quad terrain proxy. /// </summary> private QuadTerrainProxy AddQuadTerrainComponentProxy(EntityProxy parent) { // Create new quad terrain QuadTerrainComponent quadTerrain = new QuadTerrainComponent(worldControl.Core, QuadTerrainComponent.TerrainSize.Small); // Create new quad terrain proxy QuadTerrainProxy quadTerrainProxy = new QuadTerrainProxy(sceneDocument, parent, quadTerrain); // Add new quad terrain proxy to tree view TreeNode quadTerrainNode = AddTreeNode(parent.TreeNode, quadTerrainProxy); // Assign tree node to proxy quadTerrainProxy.TreeNode = quadTerrainNode; return(quadTerrainProxy); }
/// <summary> /// Sync editor maps with terrain maps. /// </summary> /// <param name="terrain">Terrain to sync maps from.</param> private void InitialiseMaps(QuadTerrainComponent terrain) { // Store values this.mapDimension = terrain.MapDimension; this.leafDimension = terrain.LeafDimension; this.gridDivisions = mapDimension / leafDimension; this.levelCount = terrain.LevelCount; // Create perlin map data perlinMapData = new float[mapDimension * mapDimension]; // Get map data heightMapData = terrain.GetHeight(); blendMap0Data = terrain.GetBlend(0); blendMap1Data = terrain.GetBlend(1); // Create initial perlin map GenerateNoise((int)GlobalSeedUpDown.Value); GeneratePerlinMap(); // Set initial preview UpdatePreview(); }
/// <summary> /// Stop editing a terrain. /// </summary> public void ClearTerrain() { this.terrain = null; }