Editor/FabLodSettings.cs
namespace FabBridge;

/// <summary>
/// User-configurable LOD switch thresholds. LOD0 is always 0.0; subsequent entries control
/// at what distance each lower LOD takes over. Edited from the Fab Bridge widget.
/// </summary>
public static class FabLodSettings
{
	/// <summary>
	/// Switch threshold per LOD index. Index 0 (LOD0) is always 0.0. The list is grown on demand
	/// by <see cref="GetThreshold"/> when a model has more LODs than are explicitly configured.
	/// </summary>
	public static List<float> SwitchThresholds { get; } = new() { 0f, 25f, 50f, 100f, 200f, 400f, 800f, 1600f };

	/// <summary>
	/// Return the switch_threshold to write for the given LOD level. LOD0 is forced to 0.0;
	/// for levels beyond the configured list, the last entry keeps doubling.
	/// </summary>
	public static float GetThreshold( int lod )
	{
		if ( lod <= 0 )
			return 0f;

		if ( lod < SwitchThresholds.Count )
			return SwitchThresholds[lod];

		var last = SwitchThresholds[^1];
		return last * (1 << (lod - SwitchThresholds.Count + 1));
	}

	/// <summary>
	/// Set a single LOD threshold, growing the list with the previous default if needed.
	/// LOD0 is ignored — it's always 0.0.
	/// </summary>
	public static void SetThreshold( int lod, float value )
	{
		if ( lod <= 0 )
			return;

		while ( SwitchThresholds.Count <= lod )
			SwitchThresholds.Add( SwitchThresholds[^1] * 2f );

		SwitchThresholds[lod] = value;
	}
}