Add Model dumping for T6

This commit is contained in:
Jan
2021-08-14 15:39:40 +02:00
parent 963e6537ca
commit d5780a1124
19 changed files with 878 additions and 84 deletions

View File

@ -21,12 +21,12 @@ GfxColor Common::Vec4PackGfxColor(const vec4_t* in)
void Common::Vec2UnpackTexCoords(const PackedTexCoords& in, vec2_t* out)
{
Pack32::Vec2UnpackTexCoords(in.packed, reinterpret_cast<float*>(out));
Pack32::Vec2UnpackTexCoordsVU(in.packed, reinterpret_cast<float*>(out));
}
void Common::Vec3UnpackUnitVec(const PackedUnitVec& in, vec3_t* out)
{
Pack32::Vec3UnpackUnitVec(in.packed, reinterpret_cast<float*>(out));
Pack32::Vec3UnpackUnitVecScaleBased(in.packed, reinterpret_cast<float*>(out));
}
void Common::Vec4UnpackGfxColor(const GfxColor& in, vec4_t* out)

View File

@ -21,12 +21,12 @@ GfxColor Common::Vec4PackGfxColor(const vec4_t* in)
void Common::Vec2UnpackTexCoords(const PackedTexCoords& in, vec2_t* out)
{
Pack32::Vec2UnpackTexCoords(in.packed, reinterpret_cast<float*>(out));
Pack32::Vec2UnpackTexCoordsVU(in.packed, reinterpret_cast<float*>(out));
}
void Common::Vec3UnpackUnitVec(const PackedUnitVec& in, vec3_t* out)
{
Pack32::Vec3UnpackUnitVec(in.packed, reinterpret_cast<float*>(out));
Pack32::Vec3UnpackUnitVecScaleBased(in.packed, reinterpret_cast<float*>(out));
}
void Common::Vec4UnpackGfxColor(const GfxColor& in, vec4_t* out)

View File

@ -21,12 +21,12 @@ GfxColor Common::Vec4PackGfxColor(const vec4_t* in)
void Common::Vec2UnpackTexCoords(const PackedTexCoords& in, vec2_t* out)
{
Pack32::Vec2UnpackTexCoords(in.packed, reinterpret_cast<float*>(out));
Pack32::Vec2UnpackTexCoordsVU(in.packed, reinterpret_cast<float*>(out));
}
void Common::Vec3UnpackUnitVec(const PackedUnitVec& in, vec3_t* out)
{
Pack32::Vec3UnpackUnitVec(in.packed, reinterpret_cast<float*>(out));
Pack32::Vec3UnpackUnitVecScaleBased(in.packed, reinterpret_cast<float*>(out));
}
void Common::Vec4UnpackGfxColor(const GfxColor& in, vec4_t* out)

View File

@ -75,12 +75,12 @@ GfxColor Common::Vec4PackGfxColor(const vec4_t* in)
void Common::Vec2UnpackTexCoords(const PackedTexCoords& in, vec2_t* out)
{
Pack32::Vec2UnpackTexCoords(in.packed, reinterpret_cast<float*>(out));
Pack32::Vec2UnpackTexCoordsVU(in.packed, reinterpret_cast<float*>(out));
}
void Common::Vec3UnpackUnitVec(const PackedUnitVec& in, vec3_t* out)
{
Pack32::Vec3UnpackUnitVec(in.packed, reinterpret_cast<float*>(out));
Pack32::Vec3UnpackUnitVecScaleBased(in.packed, reinterpret_cast<float*>(out));
}
void Common::Vec4UnpackGfxColor(const GfxColor& in, vec4_t* out)

View File

@ -2,7 +2,11 @@
#include <cctype>
int CommonT6::Com_HashKey(const char* str, const int maxLen)
#include "Utils/Pack.h"
using namespace T6;
int Common::Com_HashKey(const char* str, const int maxLen)
{
if (str == nullptr)
return 0;
@ -19,7 +23,7 @@ int CommonT6::Com_HashKey(const char* str, const int maxLen)
return hash ^ ((hash ^ (hash >> 10)) >> 10);
}
int CommonT6::Com_HashString(const char* str)
int Common::Com_HashString(const char* str)
{
if (!str)
return 0;
@ -35,7 +39,7 @@ int CommonT6::Com_HashString(const char* str)
return result;
}
int CommonT6::Com_HashString(const char* str, const int len)
int Common::Com_HashString(const char* str, const int len)
{
if (!str)
return 0;
@ -52,4 +56,34 @@ int CommonT6::Com_HashString(const char* str, const int len)
}
return result;
}
PackedTexCoords Common::Vec2PackTexCoords(const vec2_t* in)
{
return PackedTexCoords{ Pack32::Vec2PackTexCoords(in->v) };
}
PackedUnitVec Common::Vec3PackUnitVec(const vec3_t* in)
{
return PackedUnitVec{ Pack32::Vec3PackUnitVec(in->v) };
}
GfxColor Common::Vec4PackGfxColor(const vec4_t* in)
{
return GfxColor{ Pack32::Vec4PackGfxColor(in->v) };
}
void Common::Vec2UnpackTexCoords(const PackedTexCoords& in, vec2_t* out)
{
Pack32::Vec2UnpackTexCoordsUV(in.packed, out->v);
}
void Common::Vec3UnpackUnitVec(const PackedUnitVec& in, vec3_t* out)
{
Pack32::Vec3UnpackUnitVecThirdBased(in.packed, out->v);
}
void Common::Vec4UnpackGfxColor(const GfxColor& in, vec4_t* out)
{
Pack32::Vec4UnpackGfxColor(in.packed, out->v);
}

View File

@ -1,9 +1,21 @@
#pragma once
class CommonT6
#include "T6.h"
namespace T6
{
public:
static int Com_HashKey(const char* str, int maxLen);
static int Com_HashString(const char* str);
static int Com_HashString(const char* str, int len);
};
class Common
{
public:
static int Com_HashKey(const char* str, int maxLen);
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);
};
}

View File

@ -375,14 +375,16 @@ namespace T6
void* data;
};
struct XModelPieces
union vec2_t
{
const char* name;
int numpieces;
XModelPiece* pieces;
};
float v[2];
struct
{
float x;
float y;
};
};
union vec3_t
{
@ -396,6 +398,34 @@ namespace T6
float v[3];
};
union vec4_t
{
float v[4];
struct
{
float x;
float y;
float z;
float w;
};
struct
{
float r;
float g;
float b;
float a;
};
};
struct XModelPieces
{
const char* name;
int numpieces;
XModelPiece* pieces;
};
struct PhysPresetInfo
{
float mass;
@ -555,6 +585,11 @@ namespace T6
XAnimDeltaPart* deltaPart;
};
struct DObjSkelMat
{
vec4_t axis[3];
vec4_t origin;
};
struct XModelLodInfo
{
@ -573,8 +608,8 @@ namespace T6
unsigned char numsurfs;
char lodRampType;
uint16_t* boneNames;
char* parentList;
int16_t (*quats)[4];
unsigned char* parentList;
uint16_t (*quats)[4];
float (*trans)[4];
char* partClassification;
DObjAnimMat* baseMat;
@ -588,14 +623,14 @@ namespace T6
float radius;
vec3_t mins;
vec3_t maxs;
int16_t numLods;
int16_t collLod;
uint16_t numLods;
uint16_t collLod;
float* himipInvSqRadii;
int memUsage;
int flags;
bool bad;
PhysPreset* physPreset;
char numCollmaps;
unsigned char numCollmaps;
Collmap* collmaps;
PhysConstraints* physConstraints;
vec3_t lightingOriginOffset;
@ -647,9 +682,9 @@ namespace T6
{
MaterialInfo info;
char stateBitsEntry[36];
char textureCount;
char constantCount;
char stateBitsCount;
unsigned char textureCount;
unsigned char constantCount;
unsigned char stateBitsCount;
char stateFlags;
char cameraRegion;
char probeMipBits;
@ -746,6 +781,50 @@ namespace T6
uint32_t valid : 1;
};
enum TextureSemantic
{
TS_2D = 0x0,
TS_FUNCTION = 0x1,
TS_COLOR_MAP = 0x2,
TS_UNUSED_1 = 0x3,
TS_UNUSED_2 = 0x4,
TS_NORMAL_MAP = 0x5,
TS_UNUSED_3 = 0x6,
TS_UNUSED_4 = 0x7,
TS_SPECULAR_MAP = 0x8,
TS_UNUSED_5 = 0x9,
TS_OCCLUSION_MAP = 0xA,
TS_UNUSED_6 = 0xB,
TS_COLOR0_MAP = 0xC,
TS_COLOR1_MAP = 0xD,
TS_COLOR2_MAP = 0xE,
TS_COLOR3_MAP = 0xF,
TS_COLOR4_MAP = 0x10,
TS_COLOR5_MAP = 0x11,
TS_COLOR6_MAP = 0x12,
TS_COLOR7_MAP = 0x13,
TS_COLOR8_MAP = 0x14,
TS_COLOR9_MAP = 0x15,
TS_COLOR10_MAP = 0x16,
TS_COLOR11_MAP = 0x17,
TS_COLOR12_MAP = 0x18,
TS_COLOR13_MAP = 0x19,
TS_COLOR14_MAP = 0x1A,
TS_COLOR15_MAP = 0x1B,
TS_THROW_MAP = 0x1C,
};
enum ImageCategory
{
IMG_CATEGORY_UNKNOWN = 0x0,
IMG_CATEGORY_AUTO_GENERATED = 0x1,
IMG_CATEGORY_LIGHTMAP = 0x2,
IMG_CATEGORY_LOAD_FROM_FILE = 0x3,
IMG_CATEGORY_RAW = 0x4,
IMG_CATEGORY_FIRST_UNMANAGED = 0x5,
IMG_CATEGORY_RENDERTARGET = 0x5,
IMG_CATEGORY_TEMP = 0x6,
};
struct GfxImage
{
@ -1027,29 +1106,6 @@ namespace T6
int* leafRefs;
};
union vec4_t
{
float v[4];
struct
{
float x;
float y;
float z;
float w;
};
struct
{
float r;
float g;
float b;
float a;
};
};
struct GfxWorldSun
{
unsigned int control;
@ -2025,19 +2081,6 @@ namespace T6
float vertResistDown;
};
union vec2_t
{
float v[2];
struct
{
float x;
float y;
};
};
enum TractionType
{
TRACTION_TYPE_FRONT = 0x0,

View File

@ -34,10 +34,17 @@ uint32_t Pack32::Vec4PackGfxColor(const float* in)
| static_cast<uint8_t>(std::clamp(in[3], 0.0f, 1.0f) * 255.0f) << 24;
}
void Pack32::Vec2UnpackTexCoords(const uint32_t in, float* out)
void Pack32::Vec2UnpackTexCoordsUV(const uint32_t in, float* out)
{
PackUtil32 packTemp{};
const auto inHiDw = static_cast<half_float_t>((in >> 16) & UINT16_MAX);
const auto inLoDw = static_cast<half_float_t>(in & UINT16_MAX);
out[0] = HalfFloat::ToFloat(inLoDw);
out[1] = HalfFloat::ToFloat(inHiDw);
}
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);
@ -45,7 +52,7 @@ void Pack32::Vec2UnpackTexCoords(const uint32_t in, float* out)
out[1] = HalfFloat::ToFloat(inLoDw);
}
void Pack32::Vec3UnpackUnitVec(const uint32_t in, float* out)
void Pack32::Vec3UnpackUnitVecScaleBased(const uint32_t in, float* out)
{
assert(out != nullptr);
@ -56,6 +63,20 @@ void Pack32::Vec3UnpackUnitVec(const uint32_t in, float* out)
out[2] = (static_cast<float>(_in.uc[2]) + -127.0f) * decodeScale;
}
void Pack32::Vec3UnpackUnitVecThirdBased(const uint32_t in, float* out)
{
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 Pack32::Vec4UnpackGfxColor(uint32_t in, float* out)
{
out[0] = static_cast<float>(in & UINT8_MAX) / 255.0f;

View File

@ -10,7 +10,9 @@ 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 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);
};