Code/Gameplay/WaterExclusionVolume.cs

A scene volume component named WaterExclusionVolume used in the editor, intended to cut away the rendered water surface inside a box. It exposes an IgnoreHeight property and computes the world oriented bounding box (center, forward, up, half extents) from the SceneVolume bounds and 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);
	}
}