// SPDX-FileCopyrightText: 2025 Unity Technologies and the glTFast authors
// SPDX-License-Identifier: Apache-2.0
using System;
using System.Runtime.CompilerServices;
using Unity.Mathematics;
namespace GLTFast
{
/// A 3 component vector of signed bytes.
struct sbyte3
{
/// x component of the vector.
public sbyte x;
/// y component of the vector.
public sbyte y;
/// z component of the vector.
public sbyte z;
/// Constructs an sbyte3 vector from three sbyte values.
/// The constructed vector's x component will be set to this value.
/// The constructed vector's y component will be set to this value.
/// The constructed vector's z component will be set to this value.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public sbyte3(sbyte x, sbyte y, sbyte z)
{
this.x = x;
this.y = y;
this.z = z;
}
///
/// Converts 3 component vector from signed byte in glTF space to
/// float in Unity space.
///
/// 3 component vector in Unity space.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float3 GltfToUnityFloat3()
{
return new float3(-x, y, z);
}
///
/// Converts 3 component vector from signed byte in glTF space to
/// normalized float vector in Unity space. Applies normalization as last step to ensure a magnitude of 1.0.
///
/// Normalized 3 component vector in Unity space.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float3 GltfNormalToUnityFloat3()
{
var tmp = new float3(x, y, z) / 127f;
tmp = math.max(tmp, -1f);
tmp.x *= -1;
return math.normalize(tmp);
}
///
/// Converts 3 component vector from unsigned byte in glTF space to
/// normalized float vector in Unity space.
///
/// Normalized 3 component vector in Unity space.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float3 GltfToUnityNormalizedFloat3()
{
var tmp = new float3(x, y, z) / 127f;
tmp = math.max(tmp, -1f);
tmp.x *= -1;
return tmp;
}
}
}