mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-19 15:52:53 +00:00
chore: improve api for vector packing for models
This commit is contained in:
parent
1f5050befa
commit
f653530714
@ -4,32 +4,32 @@
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
PackedTexCoords Common::Vec2PackTexCoords(const vec2_t* in)
|
||||
PackedTexCoords Common::Vec2PackTexCoords(const float (&in)[2])
|
||||
{
|
||||
return PackedTexCoords{Pack32::Vec2PackTexCoords(reinterpret_cast<const float*>(in))};
|
||||
return PackedTexCoords{pack32::Vec2PackTexCoordsVU(in)};
|
||||
}
|
||||
|
||||
PackedUnitVec Common::Vec3PackUnitVec(const vec3_t* in)
|
||||
PackedUnitVec Common::Vec3PackUnitVec(const float (&in)[3])
|
||||
{
|
||||
return PackedUnitVec{Pack32::Vec3PackUnitVec(reinterpret_cast<const float*>(in))};
|
||||
return PackedUnitVec{pack32::Vec3PackUnitVecScaleBased(in)};
|
||||
}
|
||||
|
||||
GfxColor Common::Vec4PackGfxColor(const vec4_t* in)
|
||||
GfxColor Common::Vec4PackGfxColor(const float (&in)[4])
|
||||
{
|
||||
return GfxColor{Pack32::Vec4PackGfxColor(reinterpret_cast<const float*>(in))};
|
||||
return GfxColor{pack32::Vec4PackGfxColor(in)};
|
||||
}
|
||||
|
||||
void Common::Vec2UnpackTexCoords(const PackedTexCoords& in, vec2_t* out)
|
||||
void Common::Vec2UnpackTexCoords(const PackedTexCoords& in, float (&out)[2])
|
||||
{
|
||||
Pack32::Vec2UnpackTexCoordsVU(in.packed, reinterpret_cast<float*>(out));
|
||||
pack32::Vec2UnpackTexCoordsVU(in.packed, out);
|
||||
}
|
||||
|
||||
void Common::Vec3UnpackUnitVec(const PackedUnitVec& in, vec3_t* out)
|
||||
void Common::Vec3UnpackUnitVec(const PackedUnitVec& in, float (&out)[3])
|
||||
{
|
||||
Pack32::Vec3UnpackUnitVecScaleBased(in.packed, reinterpret_cast<float*>(out));
|
||||
pack32::Vec3UnpackUnitVecScaleBased(in.packed, out);
|
||||
}
|
||||
|
||||
void Common::Vec4UnpackGfxColor(const GfxColor& in, vec4_t* out)
|
||||
void Common::Vec4UnpackGfxColor(const GfxColor& in, float (&out)[4])
|
||||
{
|
||||
Pack32::Vec4UnpackGfxColor(in.packed, reinterpret_cast<float*>(out));
|
||||
pack32::Vec4UnpackGfxColor(in.packed, out);
|
||||
}
|
||||
|
@ -21,11 +21,11 @@ namespace IW3
|
||||
return result;
|
||||
}
|
||||
|
||||
static PackedTexCoords Vec2PackTexCoords(const vec2_t* in);
|
||||
static PackedUnitVec Vec3PackUnitVec(const vec3_t* in);
|
||||
static GfxColor Vec4PackGfxColor(const vec4_t* in);
|
||||
static void Vec2UnpackTexCoords(const PackedTexCoords& in, vec2_t* out);
|
||||
static void Vec3UnpackUnitVec(const PackedUnitVec& in, vec3_t* out);
|
||||
static void Vec4UnpackGfxColor(const GfxColor& in, vec4_t* out);
|
||||
static PackedTexCoords Vec2PackTexCoords(const float (&in)[2]);
|
||||
static PackedUnitVec Vec3PackUnitVec(const float (&in)[3]);
|
||||
static GfxColor Vec4PackGfxColor(const float (&in)[4]);
|
||||
static void Vec2UnpackTexCoords(const PackedTexCoords& in, float (&out)[2]);
|
||||
static void Vec3UnpackUnitVec(const PackedUnitVec& in, float (&out)[3]);
|
||||
static void Vec4UnpackGfxColor(const GfxColor& in, float (&out)[4]);
|
||||
};
|
||||
} // namespace IW3
|
||||
|
@ -20,32 +20,32 @@ int Common::StringTable_HashString(const char* str)
|
||||
return result;
|
||||
}
|
||||
|
||||
PackedTexCoords Common::Vec2PackTexCoords(const vec2_t* in)
|
||||
PackedTexCoords Common::Vec2PackTexCoords(const float (&in)[2])
|
||||
{
|
||||
return PackedTexCoords{Pack32::Vec2PackTexCoords(reinterpret_cast<const float*>(in))};
|
||||
return PackedTexCoords{pack32::Vec2PackTexCoordsVU(in)};
|
||||
}
|
||||
|
||||
PackedUnitVec Common::Vec3PackUnitVec(const vec3_t* in)
|
||||
PackedUnitVec Common::Vec3PackUnitVec(const float (&in)[3])
|
||||
{
|
||||
return PackedUnitVec{Pack32::Vec3PackUnitVec(reinterpret_cast<const float*>(in))};
|
||||
return PackedUnitVec{pack32::Vec3PackUnitVecScaleBased(in)};
|
||||
}
|
||||
|
||||
GfxColor Common::Vec4PackGfxColor(const vec4_t* in)
|
||||
GfxColor Common::Vec4PackGfxColor(const float (&in)[4])
|
||||
{
|
||||
return GfxColor{Pack32::Vec4PackGfxColor(reinterpret_cast<const float*>(in))};
|
||||
return GfxColor{pack32::Vec4PackGfxColor(in)};
|
||||
}
|
||||
|
||||
void Common::Vec2UnpackTexCoords(const PackedTexCoords& in, vec2_t* out)
|
||||
void Common::Vec2UnpackTexCoords(const PackedTexCoords& in, float (&out)[2])
|
||||
{
|
||||
Pack32::Vec2UnpackTexCoordsVU(in.packed, reinterpret_cast<float*>(out));
|
||||
pack32::Vec2UnpackTexCoordsVU(in.packed, out);
|
||||
}
|
||||
|
||||
void Common::Vec3UnpackUnitVec(const PackedUnitVec& in, vec3_t* out)
|
||||
void Common::Vec3UnpackUnitVec(const PackedUnitVec& in, float (&out)[3])
|
||||
{
|
||||
Pack32::Vec3UnpackUnitVecScaleBased(in.packed, reinterpret_cast<float*>(out));
|
||||
pack32::Vec3UnpackUnitVecScaleBased(in.packed, out);
|
||||
}
|
||||
|
||||
void Common::Vec4UnpackGfxColor(const GfxColor& in, vec4_t* out)
|
||||
void Common::Vec4UnpackGfxColor(const GfxColor& in, float (&out)[4])
|
||||
{
|
||||
Pack32::Vec4UnpackGfxColor(in.packed, reinterpret_cast<float*>(out));
|
||||
pack32::Vec4UnpackGfxColor(in.packed, out);
|
||||
}
|
||||
|
@ -28,11 +28,11 @@ namespace IW4
|
||||
|
||||
static int StringTable_HashString(const char* str);
|
||||
|
||||
static PackedTexCoords Vec2PackTexCoords(const vec2_t* in);
|
||||
static PackedUnitVec Vec3PackUnitVec(const vec3_t* in);
|
||||
static GfxColor Vec4PackGfxColor(const vec4_t* in);
|
||||
static void Vec2UnpackTexCoords(const PackedTexCoords& in, vec2_t* out);
|
||||
static void Vec3UnpackUnitVec(const PackedUnitVec& in, vec3_t* out);
|
||||
static void Vec4UnpackGfxColor(const GfxColor& in, vec4_t* out);
|
||||
static PackedTexCoords Vec2PackTexCoords(const float (&in)[2]);
|
||||
static PackedUnitVec Vec3PackUnitVec(const float (&in)[3]);
|
||||
static GfxColor Vec4PackGfxColor(const float (&in)[4]);
|
||||
static void Vec2UnpackTexCoords(const PackedTexCoords& in, float (&out)[2]);
|
||||
static void Vec3UnpackUnitVec(const PackedUnitVec& in, float (&out)[3]);
|
||||
static void Vec4UnpackGfxColor(const GfxColor& in, float (&out)[4]);
|
||||
};
|
||||
} // namespace IW4
|
||||
|
@ -20,32 +20,32 @@ int Common::StringTable_HashString(const char* str)
|
||||
return result;
|
||||
}
|
||||
|
||||
PackedTexCoords Common::Vec2PackTexCoords(const vec2_t* in)
|
||||
PackedTexCoords Common::Vec2PackTexCoords(const float (&in)[2])
|
||||
{
|
||||
return PackedTexCoords{Pack32::Vec2PackTexCoords(reinterpret_cast<const float*>(in))};
|
||||
return PackedTexCoords{pack32::Vec2PackTexCoordsVU(in)};
|
||||
}
|
||||
|
||||
PackedUnitVec Common::Vec3PackUnitVec(const vec3_t* in)
|
||||
PackedUnitVec Common::Vec3PackUnitVec(const float (&in)[3])
|
||||
{
|
||||
return PackedUnitVec{Pack32::Vec3PackUnitVec(reinterpret_cast<const float*>(in))};
|
||||
return PackedUnitVec{pack32::Vec3PackUnitVecScaleBased(in)};
|
||||
}
|
||||
|
||||
GfxColor Common::Vec4PackGfxColor(const vec4_t* in)
|
||||
GfxColor Common::Vec4PackGfxColor(const float (&in)[4])
|
||||
{
|
||||
return GfxColor{Pack32::Vec4PackGfxColor(reinterpret_cast<const float*>(in))};
|
||||
return GfxColor{pack32::Vec4PackGfxColor(in)};
|
||||
}
|
||||
|
||||
void Common::Vec2UnpackTexCoords(const PackedTexCoords& in, vec2_t* out)
|
||||
void Common::Vec2UnpackTexCoords(const PackedTexCoords& in, float (&out)[2])
|
||||
{
|
||||
Pack32::Vec2UnpackTexCoordsVU(in.packed, reinterpret_cast<float*>(out));
|
||||
pack32::Vec2UnpackTexCoordsVU(in.packed, out);
|
||||
}
|
||||
|
||||
void Common::Vec3UnpackUnitVec(const PackedUnitVec& in, vec3_t* out)
|
||||
void Common::Vec3UnpackUnitVec(const PackedUnitVec& in, float (&out)[3])
|
||||
{
|
||||
Pack32::Vec3UnpackUnitVecScaleBased(in.packed, reinterpret_cast<float*>(out));
|
||||
pack32::Vec3UnpackUnitVecScaleBased(in.packed, out);
|
||||
}
|
||||
|
||||
void Common::Vec4UnpackGfxColor(const GfxColor& in, vec4_t* out)
|
||||
void Common::Vec4UnpackGfxColor(const GfxColor& in, float (&out)[4])
|
||||
{
|
||||
Pack32::Vec4UnpackGfxColor(in.packed, reinterpret_cast<float*>(out));
|
||||
pack32::Vec4UnpackGfxColor(in.packed, out);
|
||||
}
|
||||
|
@ -9,11 +9,11 @@ namespace IW5
|
||||
public:
|
||||
static int StringTable_HashString(const char* str);
|
||||
|
||||
static PackedTexCoords Vec2PackTexCoords(const vec2_t* in);
|
||||
static PackedUnitVec Vec3PackUnitVec(const vec3_t* in);
|
||||
static GfxColor Vec4PackGfxColor(const vec4_t* in);
|
||||
static void Vec2UnpackTexCoords(const PackedTexCoords& in, vec2_t* out);
|
||||
static void Vec3UnpackUnitVec(const PackedUnitVec& in, vec3_t* out);
|
||||
static void Vec4UnpackGfxColor(const GfxColor& in, vec4_t* out);
|
||||
static PackedTexCoords Vec2PackTexCoords(const float (&in)[2]);
|
||||
static PackedUnitVec Vec3PackUnitVec(const float (&in)[3]);
|
||||
static GfxColor Vec4PackGfxColor(const float (&in)[4]);
|
||||
static void Vec2UnpackTexCoords(const PackedTexCoords& in, float (&out)[2]);
|
||||
static void Vec3UnpackUnitVec(const PackedUnitVec& in, float (&out)[3]);
|
||||
static void Vec4UnpackGfxColor(const GfxColor& in, float (&out)[4]);
|
||||
};
|
||||
} // namespace IW5
|
||||
|
@ -58,32 +58,32 @@ int Common::Com_HashString(const char* str, const int len)
|
||||
return result;
|
||||
}
|
||||
|
||||
PackedTexCoords Common::Vec2PackTexCoords(const vec2_t* in)
|
||||
PackedTexCoords Common::Vec2PackTexCoords(const float (&in)[2])
|
||||
{
|
||||
return PackedTexCoords{Pack32::Vec2PackTexCoords(reinterpret_cast<const float*>(in))};
|
||||
return PackedTexCoords{pack32::Vec2PackTexCoordsVU(in)};
|
||||
}
|
||||
|
||||
PackedUnitVec Common::Vec3PackUnitVec(const vec3_t* in)
|
||||
PackedUnitVec Common::Vec3PackUnitVec(const float (&in)[3])
|
||||
{
|
||||
return PackedUnitVec{Pack32::Vec3PackUnitVec(reinterpret_cast<const float*>(in))};
|
||||
return PackedUnitVec{pack32::Vec3PackUnitVecScaleBased(in)};
|
||||
}
|
||||
|
||||
GfxColor Common::Vec4PackGfxColor(const vec4_t* in)
|
||||
GfxColor Common::Vec4PackGfxColor(const float (&in)[4])
|
||||
{
|
||||
return GfxColor{Pack32::Vec4PackGfxColor(reinterpret_cast<const float*>(in))};
|
||||
return GfxColor{pack32::Vec4PackGfxColor(in)};
|
||||
}
|
||||
|
||||
void Common::Vec2UnpackTexCoords(const PackedTexCoords& in, vec2_t* out)
|
||||
void Common::Vec2UnpackTexCoords(const PackedTexCoords& in, float (&out)[2])
|
||||
{
|
||||
Pack32::Vec2UnpackTexCoordsVU(in.packed, reinterpret_cast<float*>(out));
|
||||
pack32::Vec2UnpackTexCoordsVU(in.packed, out);
|
||||
}
|
||||
|
||||
void Common::Vec3UnpackUnitVec(const PackedUnitVec& in, vec3_t* out)
|
||||
void Common::Vec3UnpackUnitVec(const PackedUnitVec& in, float (&out)[3])
|
||||
{
|
||||
Pack32::Vec3UnpackUnitVecScaleBased(in.packed, reinterpret_cast<float*>(out));
|
||||
pack32::Vec3UnpackUnitVecScaleBased(in.packed, out);
|
||||
}
|
||||
|
||||
void Common::Vec4UnpackGfxColor(const GfxColor& in, vec4_t* out)
|
||||
void Common::Vec4UnpackGfxColor(const GfxColor& in, float (&out)[4])
|
||||
{
|
||||
Pack32::Vec4UnpackGfxColor(in.packed, reinterpret_cast<float*>(out));
|
||||
pack32::Vec4UnpackGfxColor(in.packed, out);
|
||||
}
|
||||
|
@ -11,11 +11,11 @@ namespace T5
|
||||
static int Com_HashString(const char* str);
|
||||
static int Com_HashString(const char* str, int len);
|
||||
|
||||
static PackedTexCoords Vec2PackTexCoords(const vec2_t* in);
|
||||
static PackedUnitVec Vec3PackUnitVec(const vec3_t* in);
|
||||
static GfxColor Vec4PackGfxColor(const vec4_t* in);
|
||||
static void Vec2UnpackTexCoords(const PackedTexCoords& in, vec2_t* out);
|
||||
static void Vec3UnpackUnitVec(const PackedUnitVec& in, vec3_t* out);
|
||||
static void Vec4UnpackGfxColor(const GfxColor& in, vec4_t* out);
|
||||
static PackedTexCoords Vec2PackTexCoords(const float (&in)[2]);
|
||||
static PackedUnitVec Vec3PackUnitVec(const float (&in)[3]);
|
||||
static GfxColor Vec4PackGfxColor(const float (&in)[4]);
|
||||
static void Vec2UnpackTexCoords(const PackedTexCoords& in, float (&out)[2]);
|
||||
static void Vec3UnpackUnitVec(const PackedUnitVec& in, float (&out)[3]);
|
||||
static void Vec4UnpackGfxColor(const GfxColor& in, float (&out)[4]);
|
||||
};
|
||||
} // namespace T5
|
||||
|
@ -58,32 +58,32 @@ int Common::Com_HashString(const char* str, const int len)
|
||||
return result;
|
||||
}
|
||||
|
||||
PackedTexCoords Common::Vec2PackTexCoords(const vec2_t* in)
|
||||
PackedTexCoords Common::Vec2PackTexCoords(const float (&in)[2])
|
||||
{
|
||||
return PackedTexCoords{Pack32::Vec2PackTexCoords(in->v)};
|
||||
return PackedTexCoords{pack32::Vec2PackTexCoordsUV(in)};
|
||||
}
|
||||
|
||||
PackedUnitVec Common::Vec3PackUnitVec(const vec3_t* in)
|
||||
PackedUnitVec Common::Vec3PackUnitVec(const float (&in)[3])
|
||||
{
|
||||
return PackedUnitVec{Pack32::Vec3PackUnitVec(in->v)};
|
||||
return PackedUnitVec{pack32::Vec3PackUnitVecThirdBased(in)};
|
||||
}
|
||||
|
||||
GfxColor Common::Vec4PackGfxColor(const vec4_t* in)
|
||||
GfxColor Common::Vec4PackGfxColor(const float (&in)[4])
|
||||
{
|
||||
return GfxColor{Pack32::Vec4PackGfxColor(in->v)};
|
||||
return GfxColor{pack32::Vec4PackGfxColor(in)};
|
||||
}
|
||||
|
||||
void Common::Vec2UnpackTexCoords(const PackedTexCoords& in, vec2_t* out)
|
||||
void Common::Vec2UnpackTexCoords(const PackedTexCoords& in, float (&out)[2])
|
||||
{
|
||||
Pack32::Vec2UnpackTexCoordsUV(in.packed, out->v);
|
||||
pack32::Vec2UnpackTexCoordsUV(in.packed, out);
|
||||
}
|
||||
|
||||
void Common::Vec3UnpackUnitVec(const PackedUnitVec& in, vec3_t* out)
|
||||
void Common::Vec3UnpackUnitVec(const PackedUnitVec& in, float (&out)[3])
|
||||
{
|
||||
Pack32::Vec3UnpackUnitVecThirdBased(in.packed, out->v);
|
||||
pack32::Vec3UnpackUnitVecThirdBased(in.packed, out);
|
||||
}
|
||||
|
||||
void Common::Vec4UnpackGfxColor(const GfxColor& in, vec4_t* out)
|
||||
void Common::Vec4UnpackGfxColor(const GfxColor& in, float (&out)[4])
|
||||
{
|
||||
Pack32::Vec4UnpackGfxColor(in.packed, out->v);
|
||||
pack32::Vec4UnpackGfxColor(in.packed, out);
|
||||
}
|
||||
|
@ -41,11 +41,11 @@ namespace T6
|
||||
return result;
|
||||
}
|
||||
|
||||
static PackedTexCoords Vec2PackTexCoords(const vec2_t* in);
|
||||
static PackedUnitVec Vec3PackUnitVec(const vec3_t* in);
|
||||
static GfxColor Vec4PackGfxColor(const vec4_t* in);
|
||||
static void Vec2UnpackTexCoords(const PackedTexCoords& in, vec2_t* out);
|
||||
static void Vec3UnpackUnitVec(const PackedUnitVec& in, vec3_t* out);
|
||||
static void Vec4UnpackGfxColor(const GfxColor& in, vec4_t* out);
|
||||
static PackedTexCoords Vec2PackTexCoords(const float (&in)[2]);
|
||||
static PackedUnitVec Vec3PackUnitVec(const float (&in)[3]);
|
||||
static GfxColor Vec4PackGfxColor(const float (&in)[4]);
|
||||
static void Vec2UnpackTexCoords(const PackedTexCoords& in, float (&out)[2]);
|
||||
static void Vec3UnpackUnitVec(const PackedUnitVec& in, float (&out)[3]);
|
||||
static void Vec4UnpackGfxColor(const GfxColor& in, float (&out)[4]);
|
||||
};
|
||||
} // namespace T6
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <limits>
|
||||
|
||||
union PackUtil32
|
||||
{
|
||||
@ -14,70 +15,98 @@ union PackUtil32
|
||||
uint8_t uc[4];
|
||||
};
|
||||
|
||||
uint32_t Pack32::Vec2PackTexCoords(const float* in)
|
||||
namespace pack32
|
||||
{
|
||||
return static_cast<uint32_t>(HalfFloat::ToHalf(in[0])) << 16 | HalfFloat::ToHalf(in[1]);
|
||||
}
|
||||
uint32_t Vec2PackTexCoordsUV(const float (&in)[2])
|
||||
{
|
||||
return static_cast<uint32_t>(HalfFloat::ToHalf(in[1])) << 16 | HalfFloat::ToHalf(in[0]);
|
||||
}
|
||||
|
||||
uint32_t Pack32::Vec3PackUnitVec(const float* in)
|
||||
{
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
uint32_t Vec2PackTexCoordsVU(const float (&in)[2])
|
||||
{
|
||||
return static_cast<uint32_t>(HalfFloat::ToHalf(in[0])) << 16 | HalfFloat::ToHalf(in[1]);
|
||||
}
|
||||
|
||||
uint32_t Pack32::Vec4PackGfxColor(const float* in)
|
||||
{
|
||||
return static_cast<uint8_t>(std::clamp(in[0], 0.0f, 1.0f) * 255.0f) | static_cast<uint8_t>(std::clamp(in[1], 0.0f, 1.0f) * 255.0f) << 8
|
||||
| static_cast<uint8_t>(std::clamp(in[2], 0.0f, 1.0f) * 255.0f) << 16 | static_cast<uint8_t>(std::clamp(in[3], 0.0f, 1.0f) * 255.0f) << 24;
|
||||
}
|
||||
uint32_t Vec3PackUnitVecScaleBased(const float (&in)[3])
|
||||
{
|
||||
// TODO: Implement
|
||||
assert(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Pack32::Vec2UnpackTexCoordsUV(const uint32_t in, float* out)
|
||||
{
|
||||
const auto inHiDw = static_cast<half_float_t>((in >> 16) & UINT16_MAX);
|
||||
const auto inLoDw = static_cast<half_float_t>(in & UINT16_MAX);
|
||||
uint32_t Vec3PackUnitVecThirdBased(const float (&in)[3])
|
||||
{
|
||||
// This is based on the game's reversed code, the original code may have made a bit more sense
|
||||
PackUtil32 x;
|
||||
x.f = (in[0] - -24624.0939334638f) * 0.0001218318939208984f;
|
||||
PackUtil32 y;
|
||||
y.f = (in[1] - -24624.0939334638f) * 0.0001218318939208984f;
|
||||
PackUtil32 z;
|
||||
z.f = (in[2] - -24624.0939334638f) * 0.0001218318939208984f;
|
||||
|
||||
out[0] = HalfFloat::ToFloat(inLoDw);
|
||||
out[1] = HalfFloat::ToFloat(inHiDw);
|
||||
}
|
||||
return x.u | y.u << 10u | z.u << 20u;
|
||||
}
|
||||
|
||||
void Pack32::Vec2UnpackTexCoordsVU(const uint32_t in, float* out)
|
||||
{
|
||||
const auto inHiDw = static_cast<half_float_t>((in >> 16) & UINT16_MAX);
|
||||
const auto inLoDw = static_cast<half_float_t>(in & UINT16_MAX);
|
||||
uint32_t Vec4PackGfxColor(const float (&in)[4])
|
||||
{
|
||||
// clang-format off
|
||||
return static_cast<uint8_t>(std::clamp(in[0], 0.0f, 1.0f) * 255.0f)
|
||||
| static_cast<uint8_t>(std::clamp(in[1], 0.0f, 1.0f) * 255.0f) << 8
|
||||
| static_cast<uint8_t>(std::clamp(in[2], 0.0f, 1.0f) * 255.0f) << 16
|
||||
| static_cast<uint8_t>(std::clamp(in[3], 0.0f, 1.0f) * 255.0f) << 24;
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
out[0] = HalfFloat::ToFloat(inHiDw);
|
||||
out[1] = HalfFloat::ToFloat(inLoDw);
|
||||
}
|
||||
void Vec2UnpackTexCoordsUV(const uint32_t in, float (&out)[2])
|
||||
{
|
||||
const auto inHiDw = static_cast<half_float_t>((in >> 16) & std::numeric_limits<uint16_t>::max());
|
||||
const auto inLoDw = static_cast<half_float_t>(in & std::numeric_limits<uint16_t>::max());
|
||||
|
||||
void Pack32::Vec3UnpackUnitVecScaleBased(const uint32_t in, float* out)
|
||||
{
|
||||
assert(out != nullptr);
|
||||
out[0] = HalfFloat::ToFloat(inLoDw);
|
||||
out[1] = HalfFloat::ToFloat(inHiDw);
|
||||
}
|
||||
|
||||
PackUtil32 _in{in};
|
||||
const float decodeScale = (static_cast<float>(_in.uc[3]) - -192.0f) / 32385.0f;
|
||||
out[0] = (static_cast<float>(_in.uc[0]) + -127.0f) * decodeScale;
|
||||
out[1] = (static_cast<float>(_in.uc[1]) + -127.0f) * decodeScale;
|
||||
out[2] = (static_cast<float>(_in.uc[2]) + -127.0f) * decodeScale;
|
||||
}
|
||||
void Vec2UnpackTexCoordsVU(const uint32_t in, float (&out)[2])
|
||||
{
|
||||
const auto inHiDw = static_cast<half_float_t>((in >> 16) & std::numeric_limits<uint16_t>::max());
|
||||
const auto inLoDw = static_cast<half_float_t>(in & std::numeric_limits<uint16_t>::max());
|
||||
|
||||
void Pack32::Vec3UnpackUnitVecThirdBased(const uint32_t in, float* out)
|
||||
{
|
||||
PackUtil32 v0{(in >> 0) & 0x3FF};
|
||||
PackUtil32 v1{(in >> 10) & 0x3FF};
|
||||
PackUtil32 v2{(in >> 20) & 0x3FF};
|
||||
out[0] = HalfFloat::ToFloat(inHiDw);
|
||||
out[1] = HalfFloat::ToFloat(inLoDw);
|
||||
}
|
||||
|
||||
v0.u = v0.u - 2 * (v0.u & 0x200) + 0x40400000;
|
||||
v1.u = v1.u - 2 * (v1.u & 0x200) + 0x40400000;
|
||||
v2.u = v2.u - 2 * (v2.u & 0x200) + 0x40400000;
|
||||
out[0] = (v0.f - 3.0f) * 8208.0312f;
|
||||
out[1] = (v1.f - 3.0f) * 8208.0312f;
|
||||
out[2] = (v2.f - 3.0f) * 8208.0312f;
|
||||
}
|
||||
void Vec3UnpackUnitVecScaleBased(const uint32_t in, float (&out)[3])
|
||||
{
|
||||
assert(out != nullptr);
|
||||
|
||||
void Pack32::Vec4UnpackGfxColor(uint32_t in, float* out)
|
||||
{
|
||||
out[0] = static_cast<float>(in & UINT8_MAX) / 255.0f;
|
||||
out[1] = static_cast<float>((in >> 8) & UINT8_MAX) / 255.0f;
|
||||
out[2] = static_cast<float>((in >> 16) & UINT8_MAX) / 255.0f;
|
||||
out[3] = static_cast<float>((in >> 24) & UINT8_MAX) / 255.0f;
|
||||
}
|
||||
const PackUtil32 inUtil{in};
|
||||
const float decodeScale = (static_cast<float>(inUtil.uc[3]) - -192.0f) / 32385.0f;
|
||||
out[0] = (static_cast<float>(inUtil.uc[0]) + -127.0f) * decodeScale;
|
||||
out[1] = (static_cast<float>(inUtil.uc[1]) + -127.0f) * decodeScale;
|
||||
out[2] = (static_cast<float>(inUtil.uc[2]) + -127.0f) * decodeScale;
|
||||
}
|
||||
|
||||
void Vec3UnpackUnitVecThirdBased(const uint32_t in, float (&out)[3])
|
||||
{
|
||||
// This is based on the game's reversed code, the original code may have made a bit more sense
|
||||
PackUtil32 v0{(in >> 0) & 0x3FF};
|
||||
PackUtil32 v1{(in >> 10) & 0x3FF};
|
||||
PackUtil32 v2{(in >> 20) & 0x3FF};
|
||||
|
||||
v0.u = v0.u - 2 * (v0.u & 0x200) + 0x40400000;
|
||||
v1.u = v1.u - 2 * (v1.u & 0x200) + 0x40400000;
|
||||
v2.u = v2.u - 2 * (v2.u & 0x200) + 0x40400000;
|
||||
out[0] = (v0.f - 3.0f) * 8208.0312f;
|
||||
out[1] = (v1.f - 3.0f) * 8208.0312f;
|
||||
out[2] = (v2.f - 3.0f) * 8208.0312f;
|
||||
}
|
||||
|
||||
void Vec4UnpackGfxColor(const uint32_t in, float (&out)[4])
|
||||
{
|
||||
out[0] = static_cast<float>(in & std::numeric_limits<uint8_t>::max()) / 255.0f;
|
||||
out[1] = static_cast<float>((in >> 8) & std::numeric_limits<uint8_t>::max()) / 255.0f;
|
||||
out[2] = static_cast<float>((in >> 16) & std::numeric_limits<uint8_t>::max()) / 255.0f;
|
||||
out[3] = static_cast<float>((in >> 24) & std::numeric_limits<uint8_t>::max()) / 255.0f;
|
||||
}
|
||||
|
||||
} // namespace pack32
|
||||
|
@ -2,17 +2,17 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
class Pack32
|
||||
namespace pack32
|
||||
{
|
||||
Pack32() = default;
|
||||
uint32_t Vec2PackTexCoordsUV(const float (&in)[2]);
|
||||
uint32_t Vec2PackTexCoordsVU(const float (&in)[2]);
|
||||
uint32_t Vec3PackUnitVecScaleBased(const float (&in)[3]);
|
||||
uint32_t Vec3PackUnitVecThirdBased(const float (&in)[3]);
|
||||
uint32_t Vec4PackGfxColor(const float (&in)[4]);
|
||||
|
||||
public:
|
||||
static uint32_t Vec2PackTexCoords(const float* in);
|
||||
static uint32_t Vec3PackUnitVec(const float* in);
|
||||
static uint32_t Vec4PackGfxColor(const float* in);
|
||||
static void Vec2UnpackTexCoordsUV(uint32_t in, float* out);
|
||||
static void Vec2UnpackTexCoordsVU(uint32_t in, float* out);
|
||||
static void Vec3UnpackUnitVecScaleBased(uint32_t in, float* out);
|
||||
static void Vec3UnpackUnitVecThirdBased(uint32_t in, float* out);
|
||||
static void Vec4UnpackGfxColor(uint32_t in, float* out);
|
||||
};
|
||||
void Vec2UnpackTexCoordsUV(uint32_t in, float (&out)[2]);
|
||||
void Vec2UnpackTexCoordsVU(uint32_t in, float (&out)[2]);
|
||||
void Vec3UnpackUnitVecScaleBased(uint32_t in, float (&out)[3]);
|
||||
void Vec3UnpackUnitVecThirdBased(uint32_t in, float (&out)[3]);
|
||||
void Vec4UnpackGfxColor(uint32_t in, float (&out)[4]);
|
||||
}; // namespace pack32
|
||||
|
@ -218,27 +218,14 @@ namespace
|
||||
for (auto vertexIndex = 0u; vertexIndex < surface.vertCount; vertexIndex++)
|
||||
{
|
||||
const auto& v = surface.verts0[vertexIndex];
|
||||
vec2_t uv;
|
||||
vec3_t normalVec;
|
||||
vec4_t color;
|
||||
|
||||
Common::Vec2UnpackTexCoords(v.texCoord, &uv);
|
||||
Common::Vec3UnpackUnitVec(v.normal, &normalVec);
|
||||
Common::Vec4UnpackGfxColor(v.color, &color);
|
||||
|
||||
XModelVertex vertex{};
|
||||
vertex.coordinates[0] = v.xyz[0];
|
||||
vertex.coordinates[1] = v.xyz[1];
|
||||
vertex.coordinates[2] = v.xyz[2];
|
||||
vertex.normal[0] = normalVec[0];
|
||||
vertex.normal[1] = normalVec[1];
|
||||
vertex.normal[2] = normalVec[2];
|
||||
vertex.color[0] = color[0];
|
||||
vertex.color[1] = color[1];
|
||||
vertex.color[2] = color[2];
|
||||
vertex.color[3] = color[3];
|
||||
vertex.uv[0] = uv[0];
|
||||
vertex.uv[1] = uv[1];
|
||||
Common::Vec3UnpackUnitVec(v.normal, vertex.normal);
|
||||
Common::Vec4UnpackGfxColor(v.color, vertex.color);
|
||||
Common::Vec2UnpackTexCoords(v.texCoord, vertex.uv);
|
||||
|
||||
out.m_vertices.emplace_back(vertex);
|
||||
}
|
||||
|
@ -207,27 +207,14 @@ namespace
|
||||
for (auto vertexIndex = 0u; vertexIndex < surface.vertCount; vertexIndex++)
|
||||
{
|
||||
const auto& v = surface.verts0[vertexIndex];
|
||||
vec2_t uv;
|
||||
vec3_t normalVec;
|
||||
vec4_t color;
|
||||
|
||||
Common::Vec2UnpackTexCoords(v.texCoord, &uv);
|
||||
Common::Vec3UnpackUnitVec(v.normal, &normalVec);
|
||||
Common::Vec4UnpackGfxColor(v.color, &color);
|
||||
|
||||
XModelVertex vertex{};
|
||||
vertex.coordinates[0] = v.xyz[0];
|
||||
vertex.coordinates[1] = v.xyz[1];
|
||||
vertex.coordinates[2] = v.xyz[2];
|
||||
vertex.normal[0] = normalVec[0];
|
||||
vertex.normal[1] = normalVec[1];
|
||||
vertex.normal[2] = normalVec[2];
|
||||
vertex.color[0] = color[0];
|
||||
vertex.color[1] = color[1];
|
||||
vertex.color[2] = color[2];
|
||||
vertex.color[3] = color[3];
|
||||
vertex.uv[0] = uv[0];
|
||||
vertex.uv[1] = uv[1];
|
||||
Common::Vec3UnpackUnitVec(v.normal, vertex.normal);
|
||||
Common::Vec4UnpackGfxColor(v.color, vertex.color);
|
||||
Common::Vec2UnpackTexCoords(v.texCoord, vertex.uv);
|
||||
|
||||
out.m_vertices.emplace_back(vertex);
|
||||
}
|
||||
|
@ -207,27 +207,14 @@ namespace
|
||||
for (auto vertexIndex = 0u; vertexIndex < surface.vertCount; vertexIndex++)
|
||||
{
|
||||
const auto& v = surface.verts0.packedVerts0[vertexIndex];
|
||||
vec2_t uv;
|
||||
vec3_t normalVec;
|
||||
vec4_t color;
|
||||
|
||||
Common::Vec2UnpackTexCoords(v.texCoord, &uv);
|
||||
Common::Vec3UnpackUnitVec(v.normal, &normalVec);
|
||||
Common::Vec4UnpackGfxColor(v.color, &color);
|
||||
|
||||
XModelVertex vertex{};
|
||||
vertex.coordinates[0] = v.xyz[0];
|
||||
vertex.coordinates[1] = v.xyz[1];
|
||||
vertex.coordinates[2] = v.xyz[2];
|
||||
vertex.normal[0] = normalVec[0];
|
||||
vertex.normal[1] = normalVec[1];
|
||||
vertex.normal[2] = normalVec[2];
|
||||
vertex.color[0] = color[0];
|
||||
vertex.color[1] = color[1];
|
||||
vertex.color[2] = color[2];
|
||||
vertex.color[3] = color[3];
|
||||
vertex.uv[0] = uv[0];
|
||||
vertex.uv[1] = uv[1];
|
||||
Common::Vec3UnpackUnitVec(v.normal, vertex.normal);
|
||||
Common::Vec4UnpackGfxColor(v.color, vertex.color);
|
||||
Common::Vec2UnpackTexCoords(v.texCoord, vertex.uv);
|
||||
|
||||
out.m_vertices.emplace_back(vertex);
|
||||
}
|
||||
|
@ -220,27 +220,14 @@ namespace
|
||||
for (auto vertexIndex = 0u; vertexIndex < surface.vertCount; vertexIndex++)
|
||||
{
|
||||
const auto& v = surface.verts0[vertexIndex];
|
||||
vec2_t uv;
|
||||
vec3_t normalVec;
|
||||
vec4_t color;
|
||||
|
||||
Common::Vec2UnpackTexCoords(v.texCoord, &uv);
|
||||
Common::Vec3UnpackUnitVec(v.normal, &normalVec);
|
||||
Common::Vec4UnpackGfxColor(v.color, &color);
|
||||
|
||||
XModelVertex vertex{};
|
||||
vertex.coordinates[0] = v.xyz[0];
|
||||
vertex.coordinates[1] = v.xyz[1];
|
||||
vertex.coordinates[2] = v.xyz[2];
|
||||
vertex.normal[0] = normalVec.x;
|
||||
vertex.normal[1] = normalVec.y;
|
||||
vertex.normal[2] = normalVec.z;
|
||||
vertex.color[0] = color.r;
|
||||
vertex.color[1] = color.g;
|
||||
vertex.color[2] = color.b;
|
||||
vertex.color[3] = color.a;
|
||||
vertex.uv[0] = uv.x;
|
||||
vertex.uv[1] = uv.y;
|
||||
Common::Vec3UnpackUnitVec(v.normal, vertex.normal);
|
||||
Common::Vec4UnpackGfxColor(v.color, vertex.color);
|
||||
Common::Vec2UnpackTexCoords(v.texCoord, vertex.uv);
|
||||
|
||||
out.m_vertices.emplace_back(vertex);
|
||||
}
|
||||
|
@ -246,29 +246,14 @@ namespace
|
||||
for (auto vertexIndex = 0u; vertexIndex < surface.vertCount; vertexIndex++)
|
||||
{
|
||||
const auto& v = surface.verts0[vertexIndex];
|
||||
vec2_t uv{};
|
||||
vec3_t normalVec{};
|
||||
vec3_t tangentVec{};
|
||||
vec4_t color{};
|
||||
|
||||
Common::Vec2UnpackTexCoords(v.texCoord, &uv);
|
||||
Common::Vec3UnpackUnitVec(v.normal, &normalVec);
|
||||
Common::Vec3UnpackUnitVec(v.tangent, &tangentVec);
|
||||
Common::Vec4UnpackGfxColor(v.color, &color);
|
||||
|
||||
XModelVertex vertex{};
|
||||
vertex.coordinates[0] = v.xyz.x;
|
||||
vertex.coordinates[1] = v.xyz.y;
|
||||
vertex.coordinates[2] = v.xyz.z;
|
||||
vertex.normal[0] = normalVec.x;
|
||||
vertex.normal[1] = normalVec.y;
|
||||
vertex.normal[2] = normalVec.z;
|
||||
vertex.color[0] = color.x;
|
||||
vertex.color[1] = color.y;
|
||||
vertex.color[2] = color.z;
|
||||
vertex.color[3] = color.w;
|
||||
vertex.uv[0] = uv.x;
|
||||
vertex.uv[1] = uv.y;
|
||||
Common::Vec3UnpackUnitVec(v.normal, vertex.normal);
|
||||
Common::Vec4UnpackGfxColor(v.color, vertex.color);
|
||||
Common::Vec2UnpackTexCoords(v.texCoord, vertex.uv);
|
||||
|
||||
out.m_vertices.emplace_back(vertex);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user