Editor tool class for the SubTerrain system that implements a slope brush. It records the brush stroke start, sets slope start UV/height based on the terrain storage, and draws a simple overlay line from start to current drag position while dragging.
using Sandbox;
namespace Editor.SubTerrain;
/// <summary>
/// Slope tool. Click where the ramp should start, then drag to where it should end.
/// Each painted texel is lerped toward an inclined plane from start to end height.
/// </summary>
[Title( "Slope" )]
[Icon( "landscape" )]
[Alias( "subterrain_slope" )]
[Group( "1" )]
[Order( 4 )]
public class SubSlopeTool : SubTerrainBaseBrushTool
{
Vector3 _startLocal;
public SubSlopeTool( SubTerrainTool parent ) : base( parent )
{
Mode = SubTerrainSculptMode.Slope;
}
protected override void OnStrokeStart( Terrain terrain, Vector3 hitPosition )
{
_startLocal = hitPosition;
SlopeStartUV = new Vector2( hitPosition.x, hitPosition.y ) / terrain.Storage.TerrainSize;
SlopeStartHeight01 = hitPosition.z / terrain.Storage.TerrainHeight;
}
protected override void DrawToolOverlay( Terrain terrain, Vector3 worldCenter )
{
if ( !_dragging )
return;
var startWorld = terrain.WorldTransform.PointToWorld( _startLocal );
Gizmo.Draw.Color = Color.FromBytes( 250, 220, 120 );
Gizmo.Draw.Line( startWorld, worldCenter );
}
}