mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-11 07:18:11 -05:00
Dump IW4 xmodels as obj
This commit is contained in:
@ -0,0 +1,25 @@
|
||||
#include "CommonIW4.h"
|
||||
|
||||
#include "Utils/Pack.h"
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
PackedTexCoords Common::Vec2PackTexCoords(const vec2_t* in)
|
||||
{
|
||||
return PackedTexCoords{Pack32::Vec2PackTexCoords(reinterpret_cast<const float*>(in))};
|
||||
}
|
||||
|
||||
PackedUnitVec Common::Vec3PackUnitVec(const vec3_t* in)
|
||||
{
|
||||
return PackedUnitVec{Pack32::Vec3PackUnitVec(reinterpret_cast<const float*>(in))};
|
||||
}
|
||||
|
||||
void Common::Vec2UnpackTexCoords(const PackedTexCoords& in, vec2_t* out)
|
||||
{
|
||||
Pack32::Vec2UnpackTexCoords(in.packed, reinterpret_cast<float*>(out));
|
||||
}
|
||||
|
||||
void Common::Vec3UnpackUnitVec(const PackedUnitVec& in, vec3_t* out)
|
||||
{
|
||||
Pack32::Vec3UnpackUnitVec(in.packed, reinterpret_cast<float*>(out));
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "IW4.h"
|
||||
|
||||
namespace IW4
|
||||
{
|
||||
inline const char* szWeapTypeNames[]
|
||||
@ -192,4 +194,13 @@ namespace IW4
|
||||
"rear",
|
||||
"all",
|
||||
};
|
||||
}
|
||||
|
||||
class Common
|
||||
{
|
||||
public:
|
||||
static PackedTexCoords Vec2PackTexCoords(const vec2_t* in);
|
||||
static PackedUnitVec Vec3PackUnitVec(const vec3_t* in);
|
||||
static void Vec2UnpackTexCoords(const PackedTexCoords& in, vec2_t* out);
|
||||
static void Vec3UnpackUnitVec(const PackedUnitVec& in, vec3_t* out);
|
||||
};
|
||||
}
|
||||
|
@ -650,9 +650,9 @@ namespace IW4
|
||||
{
|
||||
MaterialInfo info;
|
||||
char stateBitsEntry[48];
|
||||
char textureCount;
|
||||
char constantCount;
|
||||
char stateBitsCount;
|
||||
unsigned char textureCount;
|
||||
unsigned char constantCount;
|
||||
unsigned char stateBitsCount;
|
||||
char stateFlags;
|
||||
char cameraRegion;
|
||||
MaterialTechniqueSet* techniqueSet;
|
||||
|
57
src/Common/Utils/Pack.cpp
Normal file
57
src/Common/Utils/Pack.cpp
Normal 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
12
src/Common/Utils/Pack.h
Normal 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);
|
||||
};
|
Reference in New Issue
Block a user