2022-02-27 07:53:44 -05:00
|
|
|
#include <STDInclude.hpp>
|
2016-01-25 17:47:50 -05:00
|
|
|
|
|
|
|
namespace Assets
|
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
void IXModelSurfs::saveXSurfaceCollisionTree(Game::XSurfaceCollisionTree* entry, Components::ZoneBuilder::Zone* builder)
|
2016-01-26 10:12:41 -05:00
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
AssertSize(Game::XSurfaceCollisionTree, 40);
|
2016-01-26 10:12:41 -05:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
Utils::Stream* buffer = builder->getBuffer();
|
2016-01-26 10:12:41 -05:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
Game::XSurfaceCollisionTree* destEntry = buffer->dest<Game::XSurfaceCollisionTree>();
|
|
|
|
buffer->save(entry);
|
2016-01-26 10:12:41 -05:00
|
|
|
|
2017-01-03 14:09:38 -05:00
|
|
|
if (entry->nodes)
|
2016-01-26 10:12:41 -05:00
|
|
|
{
|
2017-01-03 14:09:38 -05:00
|
|
|
AssertSize(Game::XSurfaceCollisionNode, 16);
|
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->align(Utils::Stream::ALIGN_16);
|
2017-01-03 14:09:38 -05:00
|
|
|
buffer->saveArray(entry->nodes, entry->nodeCount);
|
|
|
|
Utils::Stream::ClearPointer(&destEntry->nodes);
|
2016-01-26 10:12:41 -05:00
|
|
|
}
|
|
|
|
|
2017-01-03 14:09:38 -05:00
|
|
|
if (entry->leafs)
|
2016-01-26 10:12:41 -05:00
|
|
|
{
|
2017-01-03 14:09:38 -05:00
|
|
|
AssertSize(Game::XSurfaceCollisionLeaf, 2);
|
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->align(Utils::Stream::ALIGN_2);
|
2017-01-03 14:09:38 -05:00
|
|
|
buffer->saveArray(entry->leafs, entry->leafCount);
|
|
|
|
Utils::Stream::ClearPointer(&destEntry->leafs);
|
2016-01-26 10:12:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
void IXModelSurfs::saveXSurface(Game::XSurface* surf, Game::XSurface* destSurf, Components::ZoneBuilder::Zone* builder)
|
2016-01-26 10:12:41 -05:00
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
Utils::Stream* buffer = builder->getBuffer();
|
2016-01-26 10:12:41 -05:00
|
|
|
|
2017-01-03 14:09:38 -05:00
|
|
|
if (surf->vertInfo.vertsBlend)
|
2016-01-26 10:12:41 -05:00
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->align(Utils::Stream::ALIGN_2);
|
2017-01-03 14:09:38 -05:00
|
|
|
buffer->saveArray(surf->vertInfo.vertsBlend, surf->vertInfo.vertCount[0] + (surf->vertInfo.vertCount[1] * 3) + (surf->vertInfo.vertCount[2] * 5) + (surf->vertInfo.vertCount[3] * 7));
|
|
|
|
Utils::Stream::ClearPointer(&destSurf->vertInfo.vertsBlend);
|
2016-01-26 10:12:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Access vertex block
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->pushBlock(Game::XFILE_BLOCK_VERTEX);
|
2017-01-03 14:09:38 -05:00
|
|
|
if (surf->verts0)
|
2016-01-26 10:12:41 -05:00
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
AssertSize(Game::GfxPackedVertex, 32);
|
2017-06-14 06:06:04 -04:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->align(Utils::Stream::ALIGN_16);
|
2017-01-03 14:09:38 -05:00
|
|
|
buffer->saveArray(surf->verts0, surf->vertCount);
|
|
|
|
Utils::Stream::ClearPointer(&destSurf->verts0);
|
2016-01-26 10:12:41 -05:00
|
|
|
}
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->popBlock();
|
2016-01-26 10:12:41 -05:00
|
|
|
|
|
|
|
// Save_XRigidVertListArray
|
2017-01-03 14:09:38 -05:00
|
|
|
if (surf->vertList)
|
2016-01-26 10:12:41 -05:00
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
AssertSize(Game::XRigidVertList, 12);
|
2016-01-26 10:12:41 -05:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->align(Utils::Stream::ALIGN_4);
|
2016-01-26 10:12:41 -05:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
Game::XRigidVertList* destCt = buffer->dest<Game::XRigidVertList>();
|
2017-01-03 14:09:38 -05:00
|
|
|
buffer->saveArray(surf->vertList, surf->vertListCount);
|
2016-01-26 10:12:41 -05:00
|
|
|
|
2017-01-03 14:09:38 -05:00
|
|
|
for (unsigned int i = 0; i < surf->vertListCount; ++i)
|
2016-01-26 10:12:41 -05:00
|
|
|
{
|
|
|
|
Game::XRigidVertList* destRigidVertList = &destCt[i];
|
2017-01-03 14:09:38 -05:00
|
|
|
Game::XRigidVertList* rigidVertList = &surf->vertList[i];
|
2016-01-26 10:12:41 -05:00
|
|
|
|
2017-01-03 14:09:38 -05:00
|
|
|
if (rigidVertList->collisionTree)
|
2016-01-26 10:12:41 -05:00
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->align(Utils::Stream::ALIGN_4);
|
2017-01-03 14:09:38 -05:00
|
|
|
this->saveXSurfaceCollisionTree(rigidVertList->collisionTree, builder);
|
|
|
|
Utils::Stream::ClearPointer(&destRigidVertList->collisionTree);
|
2016-01-26 10:12:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-03 14:09:38 -05:00
|
|
|
Utils::Stream::ClearPointer(&destSurf->vertList);
|
2016-01-26 10:12:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Access index block
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->pushBlock(Game::XFILE_BLOCK_INDEX);
|
2019-02-01 16:16:42 -05:00
|
|
|
if (builder->hasPointer(surf->triIndices))
|
|
|
|
{
|
|
|
|
destSurf->triIndices = builder->getPointer(surf->triIndices);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buffer->align(Utils::Stream::ALIGN_16);
|
|
|
|
buffer->saveArray(surf->triIndices, surf->triCount * 3);
|
|
|
|
Utils::Stream::ClearPointer(&destSurf->triIndices);
|
|
|
|
}
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->popBlock();
|
2016-01-26 10:12:41 -05:00
|
|
|
}
|
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
void IXModelSurfs::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
2016-01-25 17:47:50 -05:00
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
AssertSize(Game::XModelSurfs, 36);
|
2016-01-25 17:47:50 -05:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
Utils::Stream* buffer = builder->getBuffer();
|
2018-05-09 08:33:52 -04:00
|
|
|
Game::XModelSurfs* asset = header.modelSurfs;
|
2016-11-20 08:09:07 -05:00
|
|
|
Game::XModelSurfs* dest = buffer->dest<Game::XModelSurfs>();
|
|
|
|
buffer->save(asset);
|
2016-01-25 17:47:50 -05:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
|
2016-01-25 17:47:50 -05:00
|
|
|
|
|
|
|
if (asset->name)
|
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
|
2016-06-10 07:52:55 -04:00
|
|
|
Utils::Stream::ClearPointer(&dest->name);
|
2016-01-25 17:47:50 -05:00
|
|
|
}
|
|
|
|
|
2018-05-09 08:33:52 -04:00
|
|
|
if (asset->surfs)
|
2016-01-25 17:47:50 -05:00
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
AssertSize(Game::XSurface, 64);
|
2016-01-25 17:47:50 -05:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->align(Utils::Stream::ALIGN_4);
|
2016-01-26 10:12:41 -05:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
Game::XSurface* destSurfaces = buffer->dest<Game::XSurface>();
|
2018-05-09 08:33:52 -04:00
|
|
|
buffer->saveArray(asset->surfs, asset->numsurfs);
|
2016-01-25 17:47:50 -05:00
|
|
|
|
2018-05-09 08:33:52 -04:00
|
|
|
for (int i = 0; i < asset->numsurfs; ++i)
|
2016-01-25 17:47:50 -05:00
|
|
|
{
|
2018-05-09 08:33:52 -04:00
|
|
|
this->saveXSurface(&asset->surfs[i], &destSurfaces[i], builder);
|
2016-01-25 17:47:50 -05:00
|
|
|
}
|
|
|
|
|
2018-05-09 08:33:52 -04:00
|
|
|
Utils::Stream::ClearPointer(&dest->surfs);
|
2016-01-25 17:47:50 -05:00
|
|
|
}
|
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
buffer->popBlock();
|
2016-01-25 17:47:50 -05:00
|
|
|
}
|
|
|
|
}
|