[IXModel] Correct more structs
This commit is contained in:
parent
7d9c588e0e
commit
b28df707b4
@ -41,7 +41,7 @@ namespace Assets
|
||||
|
||||
// Read bone names
|
||||
model->boneNames = builder->getAllocator()->allocateArray<unsigned short>(model->numBones);
|
||||
for (int i = 0; i < model->numBones; ++i)
|
||||
for (char i = 0; i < model->numBones; ++i)
|
||||
{
|
||||
model->boneNames[i] = Game::SL_GetString(reader.readCString(), 0);
|
||||
}
|
||||
@ -86,9 +86,9 @@ namespace Assets
|
||||
std::memcpy(surface, baseSurface, sizeof(Game::XSurface));
|
||||
|
||||
surface->tileMode = reader.read<char>();
|
||||
surface->deformed = reader.read<char>();
|
||||
surface->deformed = reader.read<bool>();
|
||||
|
||||
surface->streamHandle = reader.read<unsigned char>();
|
||||
surface->zoneHandle = reader.read<char>();
|
||||
surface->partBits[0] = reader.read<int>();
|
||||
surface->partBits[1] = reader.read<int>();
|
||||
surface->partBits[2] = reader.read<int>();
|
||||
@ -99,37 +99,37 @@ namespace Assets
|
||||
surface->baseTriIndex = reader.read<unsigned __int16>();
|
||||
surface->baseVertIndex = reader.read<unsigned __int16>();
|
||||
|
||||
surface->numVertices = reader.read<unsigned short>();
|
||||
surface->numPrimitives = reader.read<unsigned short>();
|
||||
surface->numCT = reader.read<int>();
|
||||
surface->vertCount = reader.read<unsigned short>();
|
||||
surface->triCount = reader.read<unsigned short>();
|
||||
surface->vertListCount = reader.read<unsigned int>();
|
||||
|
||||
surface->blendNum1 = reader.read<short>();
|
||||
surface->blendNum2 = reader.read<short>();
|
||||
surface->blendNum3 = reader.read<short>();
|
||||
surface->blendNum4 = reader.read<short>();
|
||||
surface->vertInfo.vertCount[0] = reader.read<short>();
|
||||
surface->vertInfo.vertCount[1] = reader.read<short>();
|
||||
surface->vertInfo.vertCount[2] = reader.read<short>();
|
||||
surface->vertInfo.vertCount[3] = reader.read<short>();
|
||||
|
||||
surface->blendInfo = reinterpret_cast<char*>(reader.read(2, surface->blendNum1 + (3 * surface->blendNum2) + (5 * surface->blendNum3) + (7 * surface->blendNum4)));
|
||||
surface->vertInfo.vertsBlend = reader.readArray<unsigned short>(surface->vertInfo.vertCount[0] + (3 * surface->vertInfo.vertCount[1]) + (5 * surface->vertInfo.vertCount[2]) + (7 * surface->vertInfo.vertCount[3]));
|
||||
|
||||
surface->vertexBuffer = reader.readArray<Game::GfxPackedVertex>(surface->numVertices);
|
||||
surface->indexBuffer = reader.readArray<Game::Face>(surface->numPrimitives);
|
||||
surface->verts0 = reader.readArray<Game::GfxPackedVertex>(surface->vertCount);
|
||||
surface->triIndices = reader.readArray<unsigned __int16>(3 * surface->triCount);
|
||||
|
||||
// Read vert list
|
||||
if (reader.readByte())
|
||||
{
|
||||
surface->ct = reader.readArray<Game::XRigidVertList>(surface->numCT);
|
||||
surface->vertList = reader.readArray<Game::XRigidVertList>(surface->vertListCount);
|
||||
|
||||
for (int j = 0; j < surface->numCT; ++j)
|
||||
for (unsigned int j = 0; j < surface->vertListCount; ++j)
|
||||
{
|
||||
Game::XRigidVertList* vertList = &surface->ct[j];
|
||||
Game::XRigidVertList* vertList = &surface->vertList[j];
|
||||
|
||||
vertList->entry = reader.readArray<Game::XSurfaceCollisionTree>();
|
||||
vertList->entry->node = reinterpret_cast<char*>(reader.read(16, vertList->entry->numNode));
|
||||
vertList->entry->leaf = reader.readArray<short>(vertList->entry->numLeaf);
|
||||
vertList->collisionTree = reader.readArray<Game::XSurfaceCollisionTree>();
|
||||
vertList->collisionTree->nodes = reader.readArray<Game::XSurfaceCollisionNode>(vertList->collisionTree->nodeCount);
|
||||
vertList->collisionTree->leafs = reader.readArray<Game::XSurfaceCollisionLeaf>(vertList->collisionTree->leafCount);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
surface->ct = nullptr;
|
||||
surface->vertList = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -212,7 +212,7 @@ namespace Assets
|
||||
|
||||
if (asset->materialHandles)
|
||||
{
|
||||
for (unsigned char i = 0; i < asset->numsurfs; ++i)
|
||||
for (char i = 0; i < asset->numsurfs; ++i)
|
||||
{
|
||||
if (asset->materialHandles[i])
|
||||
{
|
||||
@ -314,7 +314,7 @@ namespace Assets
|
||||
Game::Material** destMaterials = buffer->dest<Game::Material*>();
|
||||
buffer->saveArray(asset->materialHandles, asset->numsurfs);
|
||||
|
||||
for (unsigned char i = 0; i < asset->numsurfs; ++i)
|
||||
for (char i = 0; i < asset->numsurfs; ++i)
|
||||
{
|
||||
if (asset->materialHandles[i])
|
||||
{
|
||||
|
@ -11,18 +11,22 @@ namespace Assets
|
||||
Game::XSurfaceCollisionTree* destEntry = buffer->dest<Game::XSurfaceCollisionTree>();
|
||||
buffer->save(entry);
|
||||
|
||||
if (entry->node)
|
||||
if (entry->nodes)
|
||||
{
|
||||
AssertSize(Game::XSurfaceCollisionNode, 16);
|
||||
|
||||
buffer->align(Utils::Stream::ALIGN_16);
|
||||
buffer->save(entry->node, 16, entry->numNode);
|
||||
Utils::Stream::ClearPointer(&destEntry->node);
|
||||
buffer->saveArray(entry->nodes, entry->nodeCount);
|
||||
Utils::Stream::ClearPointer(&destEntry->nodes);
|
||||
}
|
||||
|
||||
if (entry->leaf)
|
||||
if (entry->leafs)
|
||||
{
|
||||
AssertSize(Game::XSurfaceCollisionLeaf, 2);
|
||||
|
||||
buffer->align(Utils::Stream::ALIGN_2);
|
||||
buffer->saveArray(entry->leaf, entry->numLeaf);
|
||||
Utils::Stream::ClearPointer(&destEntry->leaf);
|
||||
buffer->saveArray(entry->leafs, entry->leafCount);
|
||||
Utils::Stream::ClearPointer(&destEntry->leafs);
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,60 +34,58 @@ namespace Assets
|
||||
{
|
||||
Utils::Stream* buffer = builder->getBuffer();
|
||||
|
||||
if (surf->blendInfo)
|
||||
if (surf->vertInfo.vertsBlend)
|
||||
{
|
||||
buffer->align(Utils::Stream::ALIGN_2);
|
||||
buffer->save(surf->blendInfo, sizeof(short), surf->blendNum1 + (surf->blendNum2 * 3) + (surf->blendNum3 * 5) + (surf->blendNum4 * 7));
|
||||
Utils::Stream::ClearPointer(&destSurf->blendInfo);
|
||||
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);
|
||||
}
|
||||
|
||||
// Access vertex block
|
||||
buffer->pushBlock(Game::XFILE_BLOCK_VERTEX);
|
||||
if (surf->vertexBuffer)
|
||||
if (surf->verts0)
|
||||
{
|
||||
AssertSize(Game::GfxPackedVertex, 32);
|
||||
|
||||
buffer->align(Utils::Stream::ALIGN_16);
|
||||
buffer->saveArray(surf->vertexBuffer, surf->numVertices);
|
||||
Utils::Stream::ClearPointer(&destSurf->vertexBuffer);
|
||||
buffer->saveArray(surf->verts0, surf->vertCount);
|
||||
Utils::Stream::ClearPointer(&destSurf->verts0);
|
||||
}
|
||||
buffer->popBlock();
|
||||
|
||||
// Save_XRigidVertListArray
|
||||
if (surf->ct)
|
||||
if (surf->vertList)
|
||||
{
|
||||
AssertSize(Game::XRigidVertList, 12);
|
||||
|
||||
buffer->align(Utils::Stream::ALIGN_4);
|
||||
|
||||
Game::XRigidVertList* destCt = buffer->dest<Game::XRigidVertList>();
|
||||
buffer->saveArray(surf->ct, surf->numCT);
|
||||
buffer->saveArray(surf->vertList, surf->vertListCount);
|
||||
|
||||
for (int i = 0; i < surf->numCT; ++i)
|
||||
for (unsigned int i = 0; i < surf->vertListCount; ++i)
|
||||
{
|
||||
Game::XRigidVertList* destRigidVertList = &destCt[i];
|
||||
Game::XRigidVertList* rigidVertList = &surf->ct[i];
|
||||
Game::XRigidVertList* rigidVertList = &surf->vertList[i];
|
||||
|
||||
if (rigidVertList->entry)
|
||||
if (rigidVertList->collisionTree)
|
||||
{
|
||||
buffer->align(Utils::Stream::ALIGN_4);
|
||||
this->saveXSurfaceCollisionTree(rigidVertList->entry, builder);
|
||||
Utils::Stream::ClearPointer(&destRigidVertList->entry);
|
||||
this->saveXSurfaceCollisionTree(rigidVertList->collisionTree, builder);
|
||||
Utils::Stream::ClearPointer(&destRigidVertList->collisionTree);
|
||||
}
|
||||
}
|
||||
|
||||
Utils::Stream::ClearPointer(&destSurf->ct);
|
||||
Utils::Stream::ClearPointer(&destSurf->vertList);
|
||||
}
|
||||
|
||||
// Access index block
|
||||
buffer->pushBlock(Game::XFILE_BLOCK_INDEX);
|
||||
if (surf->indexBuffer)
|
||||
if (surf->triIndices)
|
||||
{
|
||||
AssertSize(Game::Face, 6);
|
||||
|
||||
buffer->align(Utils::Stream::ALIGN_16);
|
||||
buffer->saveArray(surf->indexBuffer, surf->numPrimitives);
|
||||
Utils::Stream::ClearPointer(&destSurf->indexBuffer);
|
||||
buffer->saveArray(surf->triIndices, surf->triCount * 3);
|
||||
Utils::Stream::ClearPointer(&destSurf->triIndices);
|
||||
}
|
||||
buffer->popBlock();
|
||||
}
|
||||
|
@ -21,16 +21,16 @@ namespace Components
|
||||
for (int i = 0; i < surfs->numSurfaces; ++i)
|
||||
{
|
||||
Game::XSurface* surface = &surfs->surfaces[i];
|
||||
if (surface->streamHandle == 0xFF)
|
||||
if (surface->zoneHandle == -1)
|
||||
{
|
||||
IDirect3DVertexBuffer9* vertexBuffer;
|
||||
IDirect3DIndexBuffer9* indexBuffer;
|
||||
|
||||
Game::Load_VertexBuffer(surface->vertexBuffer, &vertexBuffer, surface->numVertices * 32);
|
||||
Game::Load_IndexBuffer(surface->indexBuffer, &indexBuffer, surface->numPrimitives * 3);
|
||||
Game::Load_VertexBuffer(surface->verts0, &vertexBuffer, surface->vertCount * 32);
|
||||
Game::Load_IndexBuffer(surface->triIndices, &indexBuffer, surface->triCount * 3);
|
||||
|
||||
ModelSurfs::BufferMap[surface->vertexBuffer] = vertexBuffer;
|
||||
ModelSurfs::BufferMap[surface->indexBuffer] = indexBuffer;
|
||||
ModelSurfs::BufferMap[surface->verts0] = vertexBuffer;
|
||||
ModelSurfs::BufferMap[surface->triIndices] = indexBuffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -130,10 +130,10 @@ namespace Components
|
||||
char* source = &surfaceData[i * 84];
|
||||
|
||||
std::memcpy(&tempSurfaces[i], source, 12);
|
||||
std::memcpy(&tempSurfaces[i].indexBuffer, source + 16, 20);
|
||||
std::memcpy(&tempSurfaces[i].numCT, source + 40, 8);
|
||||
std::memcpy(&tempSurfaces[i].triIndices, source + 16, 20);
|
||||
std::memcpy(&tempSurfaces[i].vertListCount, source + 40, 8);
|
||||
std::memcpy(&tempSurfaces[i].partBits, source + 52, 24);
|
||||
tempSurfaces[i].streamHandle = 0xFF; // Fake handle for buffer interception
|
||||
tempSurfaces[i].zoneHandle = -1; // Fake handle for buffer interception
|
||||
}
|
||||
|
||||
std::memcpy(surfaceData, tempSurfaces, 64 * modelSurfs->numSurfaces);
|
||||
@ -185,18 +185,18 @@ namespace Components
|
||||
{
|
||||
Game::XSurface* surface = &header.surfaces->surfaces[i];
|
||||
|
||||
if (surface->streamHandle == 0xFF)
|
||||
if (surface->zoneHandle == -1)
|
||||
{
|
||||
hasCustomSurface = true;
|
||||
|
||||
auto buffer = ModelSurfs::BufferMap.find(surface->indexBuffer);
|
||||
auto buffer = ModelSurfs::BufferMap.find(surface->triIndices);
|
||||
if (buffer != ModelSurfs::BufferMap.end())
|
||||
{
|
||||
buffer->second->Release();
|
||||
ModelSurfs::BufferMap.erase(buffer);
|
||||
}
|
||||
|
||||
buffer = ModelSurfs::BufferMap.find(surface->vertexBuffer);
|
||||
buffer = ModelSurfs::BufferMap.find(surface->verts0);
|
||||
if (buffer != ModelSurfs::BufferMap.end())
|
||||
{
|
||||
buffer->second->Release();
|
||||
|
@ -165,19 +165,19 @@ namespace Components
|
||||
char* source = &buffer[i * 84];
|
||||
|
||||
std::memcpy(&tempSurfaces[i], source, 12);
|
||||
std::memcpy(&tempSurfaces[i].indexBuffer, source + 16, 20);
|
||||
std::memcpy(&tempSurfaces[i].numCT, source + 40, 8);
|
||||
std::memcpy(&tempSurfaces[i].triIndices, source + 16, 20);
|
||||
std::memcpy(&tempSurfaces[i].vertListCount, source + 40, 8);
|
||||
std::memcpy(&tempSurfaces[i].partBits, source + 52, 24);
|
||||
|
||||
if (Zones::ZoneVersion >= 332)
|
||||
{
|
||||
struct
|
||||
{
|
||||
short pad; // +0
|
||||
char flag; // +2
|
||||
unsigned char streamHandle; // +3
|
||||
unsigned short numVertices; // +4
|
||||
unsigned short numPrimitives; // +6
|
||||
short pad; // +0
|
||||
char flag; // +2
|
||||
char zoneHandle; // +3
|
||||
unsigned short vertCount; // +4
|
||||
unsigned short triCount; // +6
|
||||
// [...]
|
||||
} surface332;
|
||||
|
||||
@ -191,9 +191,9 @@ namespace Components
|
||||
}
|
||||
|
||||
// Copy the correct data back to our surface
|
||||
tempSurfaces[i].streamHandle = surface332.streamHandle;
|
||||
tempSurfaces[i].numVertices = surface332.numVertices;
|
||||
tempSurfaces[i].numPrimitives = surface332.numPrimitives;
|
||||
tempSurfaces[i].zoneHandle = surface332.zoneHandle;
|
||||
tempSurfaces[i].vertCount = surface332.vertCount;
|
||||
tempSurfaces[i].triCount = surface332.triCount;
|
||||
|
||||
//std::memmove(&tempSurfaces[i].numVertices, &tempSurfaces[i].numPrimitives, 6);
|
||||
}
|
||||
|
@ -1517,23 +1517,41 @@ namespace Game
|
||||
int error;
|
||||
} structuredDataFindState_t;
|
||||
|
||||
struct XSurfaceCollisionLeaf
|
||||
{
|
||||
unsigned __int16 triangleBeginIndex;
|
||||
};
|
||||
|
||||
struct XSurfaceCollisionAabb
|
||||
{
|
||||
unsigned __int16 mins[3];
|
||||
unsigned __int16 maxs[3];
|
||||
};
|
||||
|
||||
struct XSurfaceCollisionNode
|
||||
{
|
||||
XSurfaceCollisionAabb aabb;
|
||||
unsigned __int16 childBeginIndex;
|
||||
unsigned __int16 childCount;
|
||||
};
|
||||
|
||||
struct XSurfaceCollisionTree
|
||||
{
|
||||
float trans[3];
|
||||
float scale[3];
|
||||
int numNode;
|
||||
char* node; // el size 16
|
||||
int numLeaf;
|
||||
short* leaf;
|
||||
unsigned int nodeCount;
|
||||
XSurfaceCollisionNode *nodes;
|
||||
unsigned int leafCount;
|
||||
XSurfaceCollisionLeaf *leafs;
|
||||
};
|
||||
|
||||
struct XRigidVertList
|
||||
{
|
||||
unsigned short boneOffset;
|
||||
unsigned short vertCount;
|
||||
unsigned short triOffset;
|
||||
unsigned short triCount;
|
||||
XSurfaceCollisionTree* entry;
|
||||
unsigned __int16 boneOffset;
|
||||
unsigned __int16 vertCount;
|
||||
unsigned __int16 triOffset;
|
||||
unsigned __int16 triCount;
|
||||
XSurfaceCollisionTree *collisionTree;
|
||||
};
|
||||
|
||||
struct GfxPackedVertex
|
||||
@ -1546,31 +1564,26 @@ namespace Game
|
||||
float normal[3];
|
||||
};
|
||||
|
||||
struct Face
|
||||
struct XSurfaceVertexInfo
|
||||
{
|
||||
unsigned short v1;
|
||||
unsigned short v2;
|
||||
unsigned short v3;
|
||||
__int16 vertCount[4];
|
||||
unsigned __int16 *vertsBlend;
|
||||
};
|
||||
|
||||
struct XSurface
|
||||
{
|
||||
char tileMode;
|
||||
char deformed;
|
||||
unsigned short numVertices; // +2
|
||||
unsigned short numPrimitives; // +4
|
||||
unsigned char streamHandle; // something to do with buffers, +6
|
||||
bool deformed;
|
||||
unsigned __int16 vertCount;
|
||||
unsigned __int16 triCount;
|
||||
char zoneHandle;
|
||||
unsigned __int16 baseTriIndex;
|
||||
unsigned __int16 baseVertIndex;
|
||||
Face* indexBuffer; // +12
|
||||
short blendNum1; // +16
|
||||
short blendNum2; // +18
|
||||
short blendNum3; // +20
|
||||
short blendNum4; // +22
|
||||
char* blendInfo; // +24
|
||||
GfxPackedVertex* vertexBuffer; // +28
|
||||
int numCT; // +32
|
||||
XRigidVertList* ct; // +36
|
||||
unsigned __int16 *triIndices;
|
||||
XSurfaceVertexInfo vertInfo;
|
||||
GfxPackedVertex *verts0;
|
||||
unsigned int vertListCount;
|
||||
XRigidVertList *vertList;
|
||||
int partBits[6];
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user