Gameplay/WaterExclusionVolume.cs

A sandbox editor VolumeComponent that defines a water exclusion box used by a water tool. It exposes an IgnoreHeight property and computes the box oriented world OBB (center, forward, up, half extents) from the SceneVolume bounds and the component transform.

File Access
using Sandbox;
using Sandbox.Volumes;

namespace RedSnail.WaterTool2;

/// <summary>
/// Cuts the water's surface away inside a box, for enclosed spaces that sit in the water: an underwater base, a
/// submarine, a dry dock. Only the drawing is affected; swimming and buoyancy still see the water there.
/// </summary>
[Title("Water Exclusion Volume")]
[Category("Water Tool 2")]
[Icon("format_color_reset")]
public sealed class WaterExclusionVolume : VolumeComponent, Component.ExecuteInEditor
{
	/// <summary>
	/// Cuts the water at every height inside the box's footprint, however tall the box is.
	/// </summary>
	[Property] public bool IgnoreHeight { get; set; } = false;



	public (Vector3 Center, Vector3 Forward, Vector3 Up, Vector3 HalfExtents) GetWorldOBB()
	{
		BBox local = SceneVolume.GetBounds();
		Vector3 center = WorldTransform.PointToWorld(local.Center);
		Vector3 halfExtents = local.Size * 0.5f;

		return (center, WorldRotation.Forward, WorldTransform.Up, halfExtents);
	}
}