diff --git a/AssetLoader/src/GLTFBuilder.cpp b/AssetLoader/src/GLTFBuilder.cpp index 7e274206..5aeba179 100644 --- a/AssetLoader/src/GLTFBuilder.cpp +++ b/AssetLoader/src/GLTFBuilder.cpp @@ -118,6 +118,25 @@ inline float ConvertElement(Uint16 Src) } +// ========================== Int16/Uint16 -> Int8/Uint8 =========================== +template <> +inline Uint8 ConvertElement(Uint16 Src) +{ + return static_cast((static_cast(Src) * 255 + 128) / 65535); +} + +template <> +inline Int8 ConvertElement(Int16 Src) +{ + // Scale from [-32768, 32767] ? [-128, 127] with rounding + // Use 32-bit math to avoid overflow + Int32 temp = static_cast(Src) * 127; // multiply first + temp += (Src >= 0 ? 16384 : -16384); // add 0.5 for rounding + temp /= 32767; // scale down + return static_cast(temp); +} + + template inline void WriteGltfData(const void* pSrc, Uint32 NumComponents,