Files
Neutron/src/GamePort/Game/PlayerAppearance.cs
T

32 lines
1.3 KiB
C#

using System.Numerics;
using GamePort.Assets;
namespace GamePort.Game;
/// <summary>Stored current-atlas material state. Source alpha/FC requests and
/// late direct RGBA writes have different owners and must retain their order.</summary>
public sealed class PlayerAppearance
{
public Vector4 Color { get; private set; } = Vector4.One;
public bool BlendEnabled { get; private set; }
public bool Conventional { get; private set; }
public MeshBlend Blend => !BlendEnabled ? MeshBlend.Opaque : Conventional ? MeshBlend.Alpha : MeshBlend.Additive;
public void SetAlpha(float alpha)
{
if (!float.IsFinite(alpha) || alpha > 1) throw new ArgumentOutOfRangeException(nameof(alpha));
BlendEnabled = alpha > 0;
Color = alpha > 0 ? new(1,1,1,alpha) : Vector4.One;
Conventional = alpha <= 0;
}
public void SetBlend(bool conventional) => Conventional = conventional;
public void SetColor(Vector4 color)
{
if (!float.IsFinite(color.X+color.Y+color.Z+color.W)
|| color.X<0 || color.Y<0 || color.Z<0 || color.W<0 || color.W>1)
throw new ArgumentOutOfRangeException(nameof(color));
Color = color;
}
public void Reset() { Color=Vector4.One; BlendEnabled=false; Conventional=false; }
}