Editor/Wall/ArchTrimGen.cs

Editor helper that generates architectural trim geometry. It finds a profile, selects a brush from style and for each run of trim paths computes surviving cut and damage segments, then extrudes mesh geometry onto the provided canvas.

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

namespace Sunless.Architecture;

public static class ArchTrimGen
{
	public static void Build( ArchMesh canvas, ArchTrimPart trim, ArchRoom room, ArchBuilding building, ArchKit kit, ArchStyle style, ArchPlan plan = null )
	{
		var chain = room is null
			? new[] { trim.Palette, building.Palette }
			: new[] { trim.Palette, room.Palette, building.Palette };

		var profile = kit.FindProfile( trim.Profile );

		if ( profile is null || !profile.IsUsable )
		{
			return;
		}

		var brush = style.Brush( trim.Surface, chain );

		// One resolution: a following run climbs the jambs of what its host opened, so its path is asked for
		// rather than read off the record - the ghost asks the same question and gets the same answer.
		foreach ( var path in ArchTrimFollow.Runs( plan, kit, trim ).Where( run => run.Count >= 2 ) )
		{
			var level = room?.Floor ?? 0;
			var hostId = building?.Id ?? 0;

			foreach ( var (points, closed) in ArchCut.Surviving( plan, kit, level, hostId, path, ArchCutAffects.Trims ) )
			{
				var surviving = closed ? points.Append( points[0] ).ToList() : points;

				foreach ( var (damaged, damageClosed) in ArchDamage.Surviving( plan, kit, level, hostId, surviving ) )
				{
					canvas.Extrude( damaged, profile, 1f, Rotation.From( 0f, 0f, trim.Roll ), brush, damageClosed );
				}
			}
		}
	}

}