// SPDX-FileCopyrightText: 2024 Unity Technologies and the glTFast authors
// SPDX-License-Identifier: Apache-2.0
using System;
using UnityEngine.Rendering;
namespace GLTFast.Export
{
///
/// Vertex attribute mask.
///
[Flags]
public enum VertexAttributeUsage
{
/// No attribute.
None = 0,
///
Position = 1,
///
Normal = 1 << 1,
///
Tangent = 1 << 2,
///
Color = 1 << 3,
///
TexCoord0 = 1 << 4,
///
TexCoord1 = 1 << 5,
///
TexCoord2 = 1 << 6,
///
TexCoord3 = 1 << 7,
///
TexCoord4 = 1 << 8,
///
TexCoord5 = 1 << 9,
///
TexCoord6 = 1 << 10,
///
TexCoord7 = 1 << 11,
///
BlendWeight = 1 << 12,
///
BlendIndices = 1 << 13,
/// The first two texture coordinate channels.
TwoTexCoords = TexCoord0 | TexCoord1,
/// All eight texture coordinate channels.
AllTexCoords = TexCoord0 | TexCoord1 | TexCoord2 | TexCoord3 | TexCoord4 | TexCoord5 | TexCoord6 | TexCoord7,
/// Blend indices and weights, required for skinning/morph targets.
Skinning = BlendWeight | BlendIndices,
}
///
/// Extension methods for .
///
public static class VertexAttributeUsageExtension
{
///
/// Converts a to a mask with corresponding
/// flag enabled.
///
/// Vertex attribute.
/// Vertex attribute mask with corresponding flag enabled.
/// Thrown when an unknown VertexAttribute is detected.
public static VertexAttributeUsage ToVertexAttributeUsage(this VertexAttribute attr)
{
return attr switch
{
VertexAttribute.Position => VertexAttributeUsage.Position,
VertexAttribute.Normal => VertexAttributeUsage.Normal,
VertexAttribute.Tangent => VertexAttributeUsage.Tangent,
VertexAttribute.Color => VertexAttributeUsage.Color,
VertexAttribute.TexCoord0 => VertexAttributeUsage.TexCoord0,
VertexAttribute.TexCoord1 => VertexAttributeUsage.TexCoord1,
VertexAttribute.TexCoord2 => VertexAttributeUsage.TexCoord2,
VertexAttribute.TexCoord3 => VertexAttributeUsage.TexCoord3,
VertexAttribute.TexCoord4 => VertexAttributeUsage.TexCoord4,
VertexAttribute.TexCoord5 => VertexAttributeUsage.TexCoord5,
VertexAttribute.TexCoord6 => VertexAttributeUsage.TexCoord6,
VertexAttribute.TexCoord7 => VertexAttributeUsage.TexCoord7,
VertexAttribute.BlendWeight => VertexAttributeUsage.BlendWeight,
VertexAttribute.BlendIndices => VertexAttributeUsage.BlendIndices,
_ => throw new ArgumentOutOfRangeException(nameof(attr), attr, null)
};
}
}
}