2022-02-27 07:53:44 -05:00
|
|
|
#include <STDInclude.hpp>
|
2022-06-22 11:36:06 -04:00
|
|
|
#include "IXModel.hpp"
|
2017-01-16 11:42:50 -05:00
|
|
|
|
|
|
|
namespace Assets
|
|
|
|
{
|
2018-12-17 08:29:18 -05:00
|
|
|
void IXModel::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder)
|
2017-01-16 11:42:50 -05:00
|
|
|
{
|
2023-02-15 06:58:31 -05:00
|
|
|
header->model = builder->getIW4OfApi()->read<Game::XModel>(Game::XAssetType::ASSET_TYPE_XMODEL, name);
|
2017-06-05 15:03:04 -04:00
|
|
|
|
2023-02-15 06:58:31 -05:00
|
|
|
if (header->model)
|
2017-01-16 11:42:50 -05:00
|
|
|
{
|
2023-02-15 06:58:31 -05:00
|
|
|
// ???
|
|
|
|
if (header->model->physCollmap)
|
2017-01-16 11:42:50 -05:00
|
|
|
{
|
2023-02-15 06:58:31 -05:00
|
|
|
Components::AssetHandler::StoreTemporaryAsset(Game::XAssetType::ASSET_TYPE_PHYSCOLLMAP, { header->model->physCollmap });
|
2017-01-16 11:42:50 -05:00
|
|
|
}
|
|
|
|
|
2023-02-15 06:58:31 -05:00
|
|
|
if (header->model->physPreset)
|
2017-01-16 11:42:50 -05:00
|
|
|
{
|
2023-02-15 06:58:31 -05:00
|
|
|
Components::AssetHandler::StoreTemporaryAsset(Game::XAssetType::ASSET_TYPE_PHYSPRESET, { header->model->physPreset });
|
2017-01-16 11:42:50 -05:00
|
|
|
}
|
|
|
|
|
2023-02-15 06:58:31 -05:00
|
|
|
for (size_t i = 0; i < header->model->numLods; i++)
|
2017-01-16 11:42:50 -05:00
|
|
|
{
|
2023-02-15 06:58:31 -05:00
|
|
|
const auto& info = header->model->lodInfo[i];
|
|
|
|
Components::AssetHandler::StoreTemporaryAsset(Game::XAssetType::ASSET_TYPE_XMODEL_SURFS, { info.modelSurfs });
|
2017-01-16 11:42:50 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IXModel::mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
|
|
|
{
|
|
|
|
Game::XModel* asset = header.model;
|
|
|
|
|
|
|
|
if (asset->boneNames)
|
|
|
|
{
|
|
|
|
for (char i = 0; i < asset->numBones; ++i)
|
|
|
|
{
|
|
|
|
builder->addScriptString(asset->boneNames[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asset->materialHandles)
|
|
|
|
{
|
2017-03-25 08:42:21 -04:00
|
|
|
for (unsigned char i = 0; i < asset->numsurfs; ++i)
|
2017-01-16 11:42:50 -05:00
|
|
|
{
|
|
|
|
if (asset->materialHandles[i])
|
|
|
|
{
|
|
|
|
builder->loadAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, asset->materialHandles[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; ++i)
|
|
|
|
{
|
|
|
|
if (asset->lodInfo[i].modelSurfs)
|
|
|
|
{
|
2018-05-09 06:04:20 -04:00
|
|
|
builder->loadAsset(Game::XAssetType::ASSET_TYPE_XMODEL_SURFS, asset->lodInfo[i].modelSurfs);
|
2017-01-16 11:42:50 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asset->physPreset)
|
|
|
|
{
|
|
|
|
builder->loadAsset(Game::XAssetType::ASSET_TYPE_PHYSPRESET, asset->physPreset);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asset->physCollmap)
|
|
|
|
{
|
2018-05-09 06:04:20 -04:00
|
|
|
builder->loadAsset(Game::XAssetType::ASSET_TYPE_PHYSCOLLMAP, asset->physCollmap);
|
2017-01-16 11:42:50 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IXModel::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
|
|
|
{
|
|
|
|
AssertSize(Game::XModel, 304);
|
|
|
|
|
|
|
|
Utils::Stream* buffer = builder->getBuffer();
|
|
|
|
Game::XModel* asset = header.model;
|
|
|
|
Game::XModel* dest = buffer->dest<Game::XModel>();
|
|
|
|
buffer->save(asset);
|
|
|
|
|
|
|
|
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
|
|
|
|
|
|
|
|
if (asset->name)
|
|
|
|
{
|
|
|
|
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
|
|
|
|
Utils::Stream::ClearPointer(&dest->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asset->boneNames)
|
|
|
|
{
|
|
|
|
buffer->align(Utils::Stream::ALIGN_2);
|
|
|
|
|
|
|
|
unsigned short* destBoneNames = buffer->dest<unsigned short>();
|
|
|
|
buffer->saveArray(asset->boneNames, asset->numBones);
|
|
|
|
|
|
|
|
for (char i = 0; i < asset->numBones; ++i)
|
|
|
|
{
|
2022-12-14 03:40:15 -05:00
|
|
|
builder->mapScriptString(destBoneNames[i]);
|
2017-01-16 11:42:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Utils::Stream::ClearPointer(&dest->boneNames);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asset->parentList)
|
|
|
|
{
|
2022-12-14 03:40:15 -05:00
|
|
|
if (builder->hasPointer(asset->parentList))
|
|
|
|
{
|
|
|
|
dest->parentList = builder->getPointer(asset->parentList);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
builder->storePointer(asset->parentList);
|
|
|
|
buffer->save(asset->parentList, asset->numBones - asset->numRootBones);
|
|
|
|
Utils::Stream::ClearPointer(&dest->parentList);
|
|
|
|
}
|
2017-01-16 11:42:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (asset->quats)
|
|
|
|
{
|
2022-12-14 03:40:15 -05:00
|
|
|
if (builder->hasPointer(asset->quats))
|
|
|
|
{
|
|
|
|
dest->quats = builder->getPointer(asset->quats);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buffer->align(Utils::Stream::ALIGN_2);
|
|
|
|
builder->storePointer(asset->quats);
|
|
|
|
buffer->saveArray(asset->quats, (asset->numBones - asset->numRootBones) * 4);
|
|
|
|
Utils::Stream::ClearPointer(&dest->quats);
|
|
|
|
}
|
2017-01-16 11:42:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (asset->trans)
|
|
|
|
{
|
2022-12-14 03:40:15 -05:00
|
|
|
if (builder->hasPointer(asset->trans))
|
|
|
|
{
|
|
|
|
dest->trans = builder->getPointer(asset->trans);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buffer->align(Utils::Stream::ALIGN_4);
|
|
|
|
builder->storePointer(asset->trans);
|
|
|
|
buffer->saveArray(asset->trans, (asset->numBones - asset->numRootBones) * 3);
|
|
|
|
Utils::Stream::ClearPointer(&dest->trans);
|
|
|
|
}
|
2017-01-16 11:42:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (asset->partClassification)
|
|
|
|
{
|
2022-12-14 03:40:15 -05:00
|
|
|
if (builder->hasPointer(asset->partClassification))
|
|
|
|
{
|
|
|
|
dest->partClassification = builder->getPointer(asset->partClassification);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
builder->storePointer(asset->partClassification);
|
|
|
|
buffer->save(asset->partClassification, asset->numBones);
|
|
|
|
Utils::Stream::ClearPointer(&dest->partClassification);
|
|
|
|
}
|
2017-01-16 11:42:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (asset->baseMat)
|
|
|
|
{
|
|
|
|
AssertSize(Game::DObjAnimMat, 32);
|
2022-12-14 03:40:15 -05:00
|
|
|
if (builder->hasPointer(asset->baseMat))
|
|
|
|
{
|
|
|
|
dest->baseMat = builder->getPointer(asset->baseMat);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buffer->align(Utils::Stream::ALIGN_4);
|
|
|
|
builder->storePointer(asset->baseMat);
|
|
|
|
buffer->saveArray(asset->baseMat, asset->numBones);
|
|
|
|
Utils::Stream::ClearPointer(&dest->baseMat);
|
|
|
|
}
|
2017-01-16 11:42:50 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asset->materialHandles)
|
|
|
|
{
|
|
|
|
buffer->align(Utils::Stream::ALIGN_4);
|
|
|
|
|
|
|
|
Game::Material** destMaterials = buffer->dest<Game::Material*>();
|
|
|
|
buffer->saveArray(asset->materialHandles, asset->numsurfs);
|
|
|
|
|
2017-03-25 08:42:21 -04:00
|
|
|
for (unsigned char i = 0; i < asset->numsurfs; ++i)
|
2017-01-16 11:42:50 -05:00
|
|
|
{
|
|
|
|
if (asset->materialHandles[i])
|
|
|
|
{
|
|
|
|
destMaterials[i] = builder->saveSubAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, asset->materialHandles[i]).material;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Utils::Stream::ClearPointer(&dest->materialHandles);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save_XModelLodInfoArray
|
|
|
|
{
|
|
|
|
AssertSize(Game::XModelLodInfo, 44);
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; ++i)
|
|
|
|
{
|
|
|
|
if (asset->lodInfo[i].modelSurfs)
|
|
|
|
{
|
2018-05-09 08:33:52 -04:00
|
|
|
dest->lodInfo[i].modelSurfs = builder->saveSubAsset(Game::XAssetType::ASSET_TYPE_XMODEL_SURFS, asset->lodInfo[i].modelSurfs).modelSurfs;
|
2017-01-16 11:42:50 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save_XModelCollSurfArray
|
|
|
|
if (asset->collSurfs)
|
|
|
|
{
|
|
|
|
AssertSize(Game::XModelCollSurf_s, 44);
|
|
|
|
|
|
|
|
buffer->align(Utils::Stream::ALIGN_4);
|
|
|
|
|
|
|
|
Game::XModelCollSurf_s* destColSurfs = buffer->dest<Game::XModelCollSurf_s>();
|
|
|
|
buffer->saveArray(asset->collSurfs, asset->numCollSurfs);
|
|
|
|
|
|
|
|
for (int i = 0; i < asset->numCollSurfs; ++i)
|
|
|
|
{
|
|
|
|
Game::XModelCollSurf_s* destCollSurf = &destColSurfs[i];
|
|
|
|
Game::XModelCollSurf_s* collSurf = &asset->collSurfs[i];
|
|
|
|
|
|
|
|
if (collSurf->collTris)
|
|
|
|
{
|
|
|
|
buffer->align(Utils::Stream::ALIGN_4);
|
|
|
|
|
|
|
|
buffer->save(collSurf->collTris, 48, collSurf->numCollTris);
|
|
|
|
Utils::Stream::ClearPointer(&destCollSurf->collTris);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Utils::Stream::ClearPointer(&dest->collSurfs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asset->boneInfo)
|
|
|
|
{
|
|
|
|
AssertSize(Game::XBoneInfo, 28);
|
|
|
|
|
|
|
|
buffer->align(Utils::Stream::ALIGN_4);
|
|
|
|
|
|
|
|
buffer->saveArray(asset->boneInfo, asset->numBones);
|
|
|
|
Utils::Stream::ClearPointer(&dest->boneInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asset->physPreset)
|
|
|
|
{
|
|
|
|
dest->physPreset = builder->saveSubAsset(Game::XAssetType::ASSET_TYPE_PHYSPRESET, asset->physPreset).physPreset;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asset->physCollmap)
|
|
|
|
{
|
2018-05-09 06:04:20 -04:00
|
|
|
dest->physCollmap = builder->saveSubAsset(Game::XAssetType::ASSET_TYPE_PHYSCOLLMAP, asset->physCollmap).physCollmap;
|
2017-01-16 11:42:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
buffer->popBlock();
|
|
|
|
}
|
|
|
|
}
|