mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-17 02:07:58 -05:00
Add generic XModel Export dumper without bone support yet
This commit is contained in:
24
src/Common/Utils/HalfFloat.cpp
Normal file
24
src/Common/Utils/HalfFloat.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include "HalfFloat.h"
|
||||
|
||||
float HalfFloat::ToFloat(const half_float_t half)
|
||||
{
|
||||
if (half)
|
||||
{
|
||||
union
|
||||
{
|
||||
uint32_t u;
|
||||
float f;
|
||||
} result{};
|
||||
|
||||
result.u = ((half << 16) & 0x80000000) | (((((half << 14) & 0xFFFC000)
|
||||
- (~(half << 14) & 0x10000000)) ^ 0x80000000) >> 1);
|
||||
return result.f;
|
||||
}
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
half_float_t HalfFloat::ToHalf(float f)
|
||||
{
|
||||
return 0;
|
||||
}
|
14
src/Common/Utils/HalfFloat.h
Normal file
14
src/Common/Utils/HalfFloat.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
typedef uint16_t half_float_t;
|
||||
|
||||
class HalfFloat
|
||||
{
|
||||
HalfFloat() = default;
|
||||
|
||||
public:
|
||||
static float ToFloat(half_float_t half);
|
||||
static half_float_t ToHalf(float f);
|
||||
};
|
@ -1,7 +1,10 @@
|
||||
#include "Pack.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
#include "HalfFloat.h"
|
||||
|
||||
union PackUtil32
|
||||
{
|
||||
uint32_t u;
|
||||
@ -13,8 +16,8 @@ union PackUtil32
|
||||
|
||||
uint32_t Pack32::Vec2PackTexCoords(const float* in)
|
||||
{
|
||||
// TODO
|
||||
return 0;
|
||||
return static_cast<uint32_t>(HalfFloat::ToHalf(in[0])) << 16
|
||||
| HalfFloat::ToHalf(in[1]);
|
||||
}
|
||||
|
||||
uint32_t Pack32::Vec3PackUnitVec(const float* in)
|
||||
@ -23,26 +26,23 @@ uint32_t Pack32::Vec3PackUnitVec(const float* in)
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void Pack32::Vec2UnpackTexCoords(const uint32_t in, float* out)
|
||||
{
|
||||
PackUtil32 packTemp{};
|
||||
|
||||
const auto inHiDw = (in >> 16) & UINT16_MAX;
|
||||
const auto inLoDw = in & UINT16_MAX;
|
||||
const auto inHiDw = static_cast<half_float_t>((in >> 16) & UINT16_MAX);
|
||||
const auto inLoDw = static_cast<half_float_t>(in & UINT16_MAX);
|
||||
|
||||
if (inHiDw)
|
||||
packTemp.u = ((inHiDw << 16) & 0x80000000) | (((((inHiDw << 14) & 0xFFFC000)
|
||||
- (~(inHiDw << 14) & 0x10000000)) ^ 0x80000000) >> 1);
|
||||
else
|
||||
packTemp.f = 0.0f;
|
||||
out[0] = packTemp.f;
|
||||
|
||||
if (inLoDw)
|
||||
packTemp.u = ((inLoDw << 16) & 0x80000000) | (((((inLoDw << 14) & 0xFFFC000)
|
||||
- (~(inLoDw << 14) & 0x10000000)) ^ 0x80000000) >> 1);
|
||||
else
|
||||
packTemp.f = 0.0f;
|
||||
out[1] = packTemp.f;
|
||||
out[0] = HalfFloat::ToFloat(inHiDw);
|
||||
out[1] = HalfFloat::ToFloat(inLoDw);
|
||||
}
|
||||
|
||||
void Pack32::Vec3UnpackUnitVec(const uint32_t in, float* out)
|
||||
@ -55,3 +55,11 @@ void Pack32::Vec3UnpackUnitVec(const uint32_t in, float* out)
|
||||
out[1] = (static_cast<float>(_in.uc[1]) + -127.0f) * decodeScale;
|
||||
out[2] = (static_cast<float>(_in.uc[2]) + -127.0f) * decodeScale;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -4,9 +4,13 @@
|
||||
|
||||
class Pack32
|
||||
{
|
||||
Pack32() = default;
|
||||
|
||||
public:
|
||||
static uint32_t Vec2PackTexCoords(const float* in);
|
||||
static uint32_t Vec3PackUnitVec(const float* in);
|
||||
static uint32_t Vec4PackGfxColor(const float* in);
|
||||
static void Vec2UnpackTexCoords(uint32_t in, float* out);
|
||||
static void Vec3UnpackUnitVec(uint32_t in, float* out);
|
||||
static void Vec4UnpackGfxColor(uint32_t in, float* out);
|
||||
};
|
11
src/Common/Utils/QuatInt16.cpp
Normal file
11
src/Common/Utils/QuatInt16.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include "QuatInt16.h"
|
||||
|
||||
quat_int_16 QuatInt16::ToInt16(const float quat)
|
||||
{
|
||||
return static_cast<quat_int_16>(quat * INT16_MAX);
|
||||
}
|
||||
|
||||
float QuatInt16::ToFloat(const quat_int_16 quat)
|
||||
{
|
||||
return static_cast<float>(quat) / static_cast<float>(INT16_MAX);
|
||||
}
|
14
src/Common/Utils/QuatInt16.h
Normal file
14
src/Common/Utils/QuatInt16.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
typedef int16_t quat_int_16;
|
||||
|
||||
class QuatInt16
|
||||
{
|
||||
QuatInt16() = default;
|
||||
|
||||
public:
|
||||
static quat_int_16 ToInt16(float quat);
|
||||
static float ToFloat(quat_int_16 quat);
|
||||
};
|
Reference in New Issue
Block a user