Editor/Geometry/ArchSlab.cs

Editor utility that builds a thickened face (slab) for architecture meshes. It cleans up coincident corner points from an input loop and, if valid, creates a prism between the base corners and the lifted corners using ArchMesh.Prism.

File Access
using System.Collections.Generic;
using System.Linq;
using Sandbox;

namespace Sunless.Architecture;

// A face given thickness. Coincident corners are dropped first: a hip's end slopes collapse to degenerate
// triangles at a full-length ridge, and a foundation loop can arrive with a doubled point from a boolean.
public static class ArchSlab
{
	public static void Face( ArchMesh canvas, List<Vector3> face, Vector3 lift, ArchBrush brush )
	{
		var corners = Cleaned( face );

		if ( corners.Count < 3 || lift.IsNearZeroLength )
		{
			return;
		}

		canvas.Prism( corners, corners.Select( point => point + lift ).ToList(), brush );
	}

	public static List<Vector3> Cleaned( IReadOnlyList<Vector3> face )
	{
		var corners = new List<Vector3>();

		foreach ( var point in face )
		{
			if ( corners.Count > 0 && (corners[^1] - point).Length < 0.05f )
			{
				continue;
			}

			corners.Add( point );
		}

		if ( corners.Count > 2 && (corners[0] - corners[^1]).Length < 0.05f )
		{
			corners.RemoveAt( corners.Count - 1 );
		}

		return corners;
	}
}