Skip to content

Commit

Permalink
yeeting code
Browse files Browse the repository at this point in the history
  • Loading branch information
Loyalists committed Oct 10, 2022
1 parent c62727c commit 6ae1940
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
29 changes: 20 additions & 9 deletions src/H2/Assets/XModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace ZoneTool
class IXModel
{
public:
static XModel* convert_from_iw4(IW4::XModel* asset)
static XModel* convert_from_iw4(IW4::XModel* asset, const std::function<const char* (uint16_t)>& convertToString)
{
const auto name = reinterpret_cast<std::uint64_t>(asset->name);
auto xmodel = new XModel{
Expand All @@ -22,6 +22,7 @@ namespace ZoneTool
xmodel->numCompositeModels = 0;
xmodel->scale = 1.0;
xmodel->noScalePartBits[0] = 1065353216;
//memcpy(xmodel->noScalePartBits, asset->noScalePartBits, sizeof(asset->noScalePartBits));

scr_string_t* boneNames = new scr_string_t[asset->numBones]();
for (int b = 0; b < asset->numBones; b++) {
Expand Down Expand Up @@ -52,7 +53,13 @@ namespace ZoneTool
unsigned char* partClassification = new unsigned char[asset->numBones]();
auto baseMat = new DObjAnimMat[asset->numBones]();
for (int i = 0; i < asset->numBones; i++) {
partClassification[i] = asset->partClassification[i];
uint16_t boneNameIndex = asset->boneNames[i];
std::string boneNameString = convertToString(boneNameIndex);
if (boneNameString == "tag_shield_back" || boneNameString == "tag_weapon_left")
partClassification[i] = 0x13;
else
partClassification[i] = asset->partClassification[i];

memcpy(baseMat[i].quat, asset->animMatrix[i].quat, sizeof(DObjAnimMat::quat));
memcpy(baseMat[i].trans, asset->animMatrix[i].trans, sizeof(DObjAnimMat::trans));
baseMat[i].transWeight = asset->animMatrix[i].transWeight;
Expand All @@ -65,13 +72,16 @@ namespace ZoneTool

auto materialHandles = new Material * [asset->numSurfaces]();
for (int i = 0; i < asset->numSurfaces; i++) {
const char* name = asset->materials[i]->name;
auto casted_name = reinterpret_cast<std::uint64_t>(name);
//MaterialInfo info = {
// .name = casted_name,
//};
std::string name_str = asset->materials[i]->name;
std::string prefix = "mc/";
int index = name_str.find(prefix);
if (index != std::string::npos) {
name_str.replace(index, prefix.length(), "m/");
}
const char* name2 = strdup(name_str.c_str());

materialHandles[i] = new Material{
.name = casted_name
.name = reinterpret_cast<std::uint64_t>(name2)
};
}
xmodel->materialHandles = reinterpret_cast<std::uint64_t>(materialHandles);
Expand Down Expand Up @@ -103,6 +113,7 @@ namespace ZoneTool

xmodel->numLods = asset->numLods;
xmodel->collLod = asset->collLod;
xmodel->flags = asset->flags;
xmodel->numCollSurfs = asset->numColSurfs;
xmodel->contents = asset->contents;
xmodel->radius = asset->radius;
Expand Down Expand Up @@ -132,7 +143,7 @@ namespace ZoneTool

auto invHighMipRadius = new unsigned short[xmodel->numsurfs]();
for (int i = 0; i < xmodel->numsurfs; i++) {
invHighMipRadius[i] = 65535;
invHighMipRadius[i] = 0;
}
xmodel->invHighMipRadius = reinterpret_cast<std::uint64_t>(invHighMipRadius);

Expand Down
5 changes: 4 additions & 1 deletion src/H2/Assets/XSurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ namespace ZoneTool
static XSurface* surf_convert_from_iw4(XSurface* surf, IW4::XSurface* asset)
{
// character assets have this set as 6 while weapons set this as 2...
surf->flags = 6;
surf->flags = 2;
if (asset->deformed) {
surf->flags = 6;
}
surf->vertCount = asset->vertCount;
surf->triCount = asset->triCount;
memset(surf->blendVertCounts, 0, sizeof(XSurface::blendVertCounts));
Expand Down
2 changes: 1 addition & 1 deletion src/IW4/Assets/Xmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ namespace ZoneTool

void IXModel::dump(XModel* asset, const std::function<const char*(uint16_t)>& convertToString)
{
auto* result = H2::IXModel::convert_from_iw4(asset);
auto* result = H2::IXModel::convert_from_iw4(asset, convertToString);
H2::IXModel::dump(result, convertToString);
}
}
Expand Down

0 comments on commit 6ae1940

Please sign in to comment.