Dump IW4 xmodels as obj

This commit is contained in:
Jan
2021-08-01 00:30:12 +02:00
parent 2c96bc5ef8
commit 24145e15e2
11 changed files with 365 additions and 5 deletions

57
src/Common/Utils/Pack.cpp Normal file
View File

@ -0,0 +1,57 @@
#include "Pack.h"
#include <cassert>
union PackUtil32
{
uint32_t u;
int32_t i;
float f;
int8_t c[4];
uint8_t uc[4];
};
uint32_t Pack32::Vec2PackTexCoords(const float* in)
{
// TODO
return 0;
}
uint32_t Pack32::Vec3PackUnitVec(const float* in)
{
// TODO
return 0;
}
void Pack32::Vec2UnpackTexCoords(const uint32_t in, float* out)
{
PackUtil32 packTemp{};
const auto inHiDw = (in >> 16) & UINT16_MAX;
const auto inLoDw = 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;
}
void Pack32::Vec3UnpackUnitVec(const uint32_t in, float* out)
{
assert(out != nullptr);
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;
}

12
src/Common/Utils/Pack.h Normal file
View File

@ -0,0 +1,12 @@
#pragma once
#include <cstdint>
class Pack32
{
public:
static uint32_t Vec2PackTexCoords(const float* in);
static uint32_t Vec3PackUnitVec(const float* in);
static void Vec2UnpackTexCoords(uint32_t in, float* out);
static void Vec3UnpackUnitVec(uint32_t in, float* out);
};