Fix looped anims and add the long-awaited support for model-tags and quick and ugly fix for textures

This commit is contained in:
momo5502 2016-06-10 00:08:07 +02:00
parent 06e91f9dd2
commit a0e52dc550
3 changed files with 63 additions and 43 deletions

View File

@ -45,8 +45,8 @@ namespace Assets
memcpy(material, baseMaterial, sizeof(Game::Material));
material->name = builder->GetAllocator()->DuplicateString(name);
material->textureAtlasRowCount = 0;
material->textureAtlasColumnCount = 0;
material->textureAtlasRowCount = 1;
material->textureAtlasColumnCount = 1;
// Load animation frames
auto anims = infoData["anims"];
@ -71,6 +71,16 @@ namespace Assets
}
}
// Model surface textures are special, they need a special order and whatnot
bool replaceTexture = Utils::StartsWith(name, "mc/");
if (replaceTexture)
{
Game::MaterialTextureDef* textureTable = builder->GetAllocator()->AllocateArray<Game::MaterialTextureDef>(baseMaterial->textureCount);
std::memcpy(textureTable, baseMaterial->textureTable, sizeof(Game::MaterialTextureDef) * baseMaterial->textureCount);
material->textureTable = textureTable;
material->textureCount = baseMaterial->textureCount;
}
// Load referenced textures
auto textures = infoData["textures"];
if (textures.is_array())
@ -87,7 +97,7 @@ namespace Assets
auto map = textureInfo[0];
auto image = textureInfo[1];
if(!map.is_string() || !image.is_string()) continue;
if (!map.is_string() || !image.is_string()) continue;
Game::MaterialTextureDef textureDef;
@ -99,29 +109,54 @@ namespace Assets
textureDef.info.image = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, image.string_value(), builder).image;
textureList.push_back(textureDef);
if (replaceTexture)
{
bool applied = false;
for (char i = 0; i < baseMaterial->textureCount; ++i)
{
if (material->textureTable[i].nameHash == textureDef.nameHash)
{
applied = true;
material->textureTable[i].info.image = textureDef.info.image;
break;
}
}
if (!applied)
{
Components::Logger::Error(0, "Unable to find texture for map '%s' in %s!", map.string_value().data(), baseMaterial->name);
}
}
else
{
textureList.push_back(textureDef);
}
}
if (!textureList.empty())
if(!replaceTexture)
{
Game::MaterialTextureDef* textureTable = builder->GetAllocator()->AllocateArray<Game::MaterialTextureDef>(textureList.size());
if (!textureTable)
if (!textureList.empty())
{
Components::Logger::Error("Failed to allocate texture table!");
return;
Game::MaterialTextureDef* textureTable = builder->GetAllocator()->AllocateArray<Game::MaterialTextureDef>(textureList.size());
if (!textureTable)
{
Components::Logger::Error("Failed to allocate texture table!");
return;
}
std::memcpy(textureTable, textureList.data(), sizeof(Game::MaterialTextureDef) * textureList.size());
material->textureTable = textureTable;
}
else
{
material->textureTable = 0;
}
memcpy(textureTable, textureList.data(), sizeof(Game::MaterialTextureDef) * textureList.size());
material->textureTable = textureTable;
material->textureCount = static_cast<char>(textureList.size()) & 0xFF;
}
else
{
material->textureTable = 0;
}
material->textureCount = static_cast<char>(textureList.size()) & 0xFF;
}
header->material = material;

View File

@ -64,6 +64,10 @@ namespace Assets
Game::XSurface* surface = &surf->surfaces[i];
std::memcpy(surface, baseSurface, sizeof(Game::XSurface));
surface->streamHandle = reader.Read<unsigned char>();
surface->something = reader.Read<int>();
surface->something2 = reader.Read<int>();
surface->numVertices = reader.Read<unsigned short>();
surface->numPrimitives = reader.Read<unsigned short>();
surface->numCT = reader.Read<int>();
@ -103,15 +107,6 @@ namespace Assets
for (char i = 0; i < model->numSurfaces; ++i)
{
model->materials[i] = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_MATERIAL, reader.ReadString(), builder).material;
//if (i < 9)
{
model->materials[i] = baseModel->materials[0];
}
// else
// {
// OutputDebugStringA(model->materials[i]->name);
// }
}
// Read collision surfaces
@ -207,18 +202,6 @@ namespace Assets
buffer->PushBlock(Game::XFILE_BLOCK_VIRTUAL);
// if (!strcmp(asset->name, "viewmodel_m40a3"))
// {
// for (char i = 0; i < asset->numBones; ++i)
// {
// OutputDebugStringA(Utils::VA("Bounds[%d][0]: %f - %X\n", i, asset->boneInfo[i].bounds[0], *(DWORD*)&asset->boneInfo[i].bounds[0]));
// OutputDebugStringA(Utils::VA("Bounds[%d][1]: %f - %X\n", i, asset->boneInfo[i].bounds[1], *(DWORD*)&asset->boneInfo[i].bounds[1]));
// OutputDebugStringA(Utils::VA("Bounds[%d][2]: %f - %X\n\n", i, asset->boneInfo[i].bounds[2], *(DWORD*)&asset->boneInfo[i].bounds[2]));
// }
//
// __debugbreak();
// }
if (asset->name)
{
buffer->SaveString(builder->GetAssetName(this->GetType(), asset->name));

View File

@ -1355,7 +1355,9 @@ namespace Game
GfxPackedVertex* vertexBuffer; // +28
int numCT; // +32
XRigidVertList* ct; // +36
char pad5[24]; // +40
int something;
int something2;
char pad5[16]; // +40
// pad5 matches XModelSurfaces pad
// total size, 64
};
@ -1660,10 +1662,10 @@ namespace Game
unsigned short randomDataByteCount; // 10 - 0xA
unsigned short randomDataIntCount;// 12 - 0xC
unsigned short framecount; // 14 - 0xE
char pad1; // 16
char bLoop; // 16
char boneCount[10]; // 17
char notetrackCount; // 27
bool bLoop; // 28
bool pad1; // 28
bool bDelta; // 29
char assetType; // 30
char pad2; // 31