Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions AssetLoader/src/GLTFBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ inline float ConvertElement<float, true, Uint16>(Uint16 Src)
}


// ========================== Int16/Uint16 -> Int8/Uint8 ===========================
template <>
inline Uint8 ConvertElement<Uint8, true, Uint16>(Uint16 Src)
{
return static_cast<Uint8>((static_cast<Uint32>(Src) * 255 + 128) / 65535);
}

template <>
inline Int8 ConvertElement<Int8, true, Int16>(Int16 Src)
{
// Scale from [-32768, 32767] ? [-128, 127] with rounding
// Use 32-bit math to avoid overflow
Int32 temp = static_cast<Int32>(Src) * 127; // multiply first
temp += (Src >= 0 ? 16384 : -16384); // add 0.5 for rounding
temp /= 32767; // scale down
return static_cast<Int8>(temp);
}


template <typename SrcType, typename DstType, bool IsNormalized>
inline void WriteGltfData(const void* pSrc,
Uint32 NumComponents,
Expand Down
Loading