// Copyright (c) Wojciech Figat. All rights reserved. using System; using FlaxEngine; namespace FlaxEditor.Tools.Terrain.Undo { /// /// The terrain heightmap editing action that records before and after states to swap between unmodified and modified terrain data. /// /// /// [Serializable] unsafe class EditTerrainHeightMapAction : EditTerrainMapAction { /// /// Initializes a new instance of the class. /// /// The terrain. public EditTerrainHeightMapAction(FlaxEngine.Terrain terrain) : base(terrain, sizeof(float)) { } /// public override string ActionString => "Edit terrain heightmap"; /// protected override IntPtr GetData(ref Int2 patchCoord, object tag) { return new IntPtr(TerrainTools.GetHeightmapData(Terrain, patchCoord)); } /// protected override void SetData(ref Int2 patchCoord, IntPtr data, object tag) { var offset = Int2.Zero; var size = new Int2((int)Mathf.Sqrt(_heightmapLength)); if (TerrainTools.ModifyHeightMap(Terrain, patchCoord, (float*)data, offset, size)) throw new Exception("Failed to modify the heightmap."); } } }