Editor/Tools/PathTool.cs

Editor tool for the SubTerrain system that implements a Path brush. It records the stroke start position and slope start UV/height, sets the sculpt mode to Path, and draws a line overlay from the stored start to the current drag center while dragging.

Native Interop
using Sandbox;

namespace Editor.SubTerrain;

/// <summary>
/// Path tool. Click to set the path elevation, then drag to define direction.
/// Flattens the brush strip to the start height (constant road/trench), unlike Slope
/// which grades from start height to end height.
/// </summary>
[Title( "Path" )]
[Icon( "route" )]
[Alias( "subterrain_path" )]
[Group( "1" )]
[Order( 5 )]
public class SubPathTool : SubTerrainBaseBrushTool
{
	Vector3 _startLocal;

	public SubPathTool( SubTerrainTool parent ) : base( parent )
	{
		Mode = SubTerrainSculptMode.Path;
	}

	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( 120, 200, 250 );
		Gizmo.Draw.Line( startWorld, worldCenter );
	}
}