Correct handling of empty skinned models

This commit is contained in:
Jack Andersen 2018-11-08 20:57:16 -10:00
parent 3f7431286c
commit 87e5aea6f5
1 changed files with 82 additions and 76 deletions

View File

@ -1345,17 +1345,18 @@ bool ANCS::CookCSKR(const hecl::ProjectPath& outPath,
if (!modelCookFunc(*modelPath))
Log.report(logvisor::Fatal, _SYS_STR("unable to cook '%s'"), modelPath->getRelativePath().data());
std::vector<std::pair<std::vector<std::pair<uint32_t, float>>, uint32_t>> skins;
uint32_t posCount = 0;
uint32_t normCount = 0;
athena::io::FileReader skinIO(skinIntPath.getAbsolutePath(), 1024*32, false);
if (skinIO.hasError())
Log.report(logvisor::Fatal, _SYS_STR("unable to open '%s'"), skinIntPath.getRelativePath().data());
if (!skinIO.hasError())
{
std::vector<std::string> boneNames;
uint32_t boneNameCount = skinIO.readUint32Big();
boneNames.reserve(boneNameCount);
for (uint32_t i=0 ; i<boneNameCount ; ++i)
boneNames.push_back(skinIO.readString());
std::vector<std::pair<std::vector<std::pair<uint32_t, float>>, uint32_t>> skins;
uint32_t skinCount = skinIO.readUint32Big();
skins.resize(skinCount);
for (uint32_t i=0 ; i<skinCount ; ++i)
@ -1377,10 +1378,11 @@ bool ANCS::CookCSKR(const hecl::ProjectPath& outPath,
virtualBone.second = skinIO.readUint32Big();
}
uint32_t posCount = skinIO.readUint32Big();
uint32_t normCount = skinIO.readUint32Big();
posCount = skinIO.readUint32Big();
normCount = skinIO.readUint32Big();
skinIO.close();
}
athena::io::TransactionalFileWriter skinOut(outPath.getAbsolutePath());
@ -1483,12 +1485,16 @@ bool ANCS::CookCSKRPC(const hecl::ProjectPath& outPath,
if (!modelCookFunc(*modelPath))
Log.report(logvisor::Fatal, _SYS_STR("unable to cook '%s'"), modelPath->getRelativePath().data());
athena::io::FileReader skinIO(skinIntPath.getAbsolutePath(), 1024*32, false);
if (skinIO.hasError())
Log.report(logvisor::Fatal, _SYS_STR("unable to open '%s'"), skinIntPath.getRelativePath().data());
uint32_t bankCount = 0;
std::vector<std::vector<uint32_t>> skinBanks;
uint32_t bankCount = skinIO.readUint32Big();
std::vector<std::string> boneNames;
std::vector<std::vector<std::pair<uint32_t, float>>> skins;
atUint64 uniquePoolIndexLen = 0;
std::unique_ptr<atUint8[]> uniquePoolIndexData;
athena::io::FileReader skinIO(skinIntPath.getAbsolutePath(), 1024*32, false);
if (!skinIO.hasError())
{
bankCount = skinIO.readUint32Big();
skinBanks.reserve(bankCount);
for (uint32_t i=0 ; i<bankCount ; ++i)
{
@ -1503,13 +1509,11 @@ bool ANCS::CookCSKRPC(const hecl::ProjectPath& outPath,
}
}
std::vector<std::string> boneNames;
uint32_t boneNameCount = skinIO.readUint32Big();
boneNames.reserve(boneNameCount);
for (uint32_t i=0 ; i<boneNameCount ; ++i)
boneNames.push_back(skinIO.readString());
std::vector<std::vector<std::pair<uint32_t, float>>> skins;
uint32_t skinCount = skinIO.readUint32Big();
skins.resize(skinCount);
for (uint32_t i=0 ; i<skinCount ; ++i)
@ -1530,10 +1534,11 @@ bool ANCS::CookCSKRPC(const hecl::ProjectPath& outPath,
}
}
atUint64 uniquePoolIndexLen = skinIO.length() - skinIO.position();
auto uniquePoolIndexData = skinIO.readUBytes(uniquePoolIndexLen);
uniquePoolIndexLen = skinIO.length() - skinIO.position();
uniquePoolIndexData = skinIO.readUBytes(uniquePoolIndexLen);
skinIO.close();
}
athena::io::TransactionalFileWriter skinOut(outPath.getAbsolutePath());
@ -1563,6 +1568,7 @@ bool ANCS::CookCSKRPC(const hecl::ProjectPath& outPath,
}
}
if (uniquePoolIndexLen)
skinOut.writeUBytes(uniquePoolIndexData.get(), uniquePoolIndexLen);
return true;