Rollback the method to handle empty bones for GLTF2
A patch made the assimp to ignore empty bones. However, some assets can have bones which don't have weights but are connected to other bones.pull/3461/head
parent
9f880e2214
commit
ad7f8910e9
|
@ -928,14 +928,7 @@ aiNode *ImportNode(aiScene *pScene, glTF2::Asset &r, std::vector<unsigned int> &
|
||||||
std::vector<std::vector<aiVertexWeight>> weighting(numBones);
|
std::vector<std::vector<aiVertexWeight>> weighting(numBones);
|
||||||
BuildVertexWeightMapping(node.meshes[0]->primitives[primitiveNo], weighting);
|
BuildVertexWeightMapping(node.meshes[0]->primitives[primitiveNo], weighting);
|
||||||
|
|
||||||
unsigned int realNumBones = 0;
|
mesh->mNumBones = static_cast<unsigned int>(numBones);
|
||||||
for (uint32_t i = 0; i < numBones; ++i) {
|
|
||||||
if (weighting[i].size() > 0) {
|
|
||||||
realNumBones++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mesh->mNumBones = static_cast<unsigned int>(realNumBones);
|
|
||||||
mesh->mBones = new aiBone *[mesh->mNumBones];
|
mesh->mBones = new aiBone *[mesh->mNumBones];
|
||||||
|
|
||||||
// GLTF and Assimp choose to store bone weights differently.
|
// GLTF and Assimp choose to store bone weights differently.
|
||||||
|
@ -951,10 +944,8 @@ aiNode *ImportNode(aiScene *pScene, glTF2::Asset &r, std::vector<unsigned int> &
|
||||||
mat4 *pbindMatrices = nullptr;
|
mat4 *pbindMatrices = nullptr;
|
||||||
node.skin->inverseBindMatrices->ExtractData(pbindMatrices);
|
node.skin->inverseBindMatrices->ExtractData(pbindMatrices);
|
||||||
|
|
||||||
int cb = 0;
|
|
||||||
for (uint32_t i = 0; i < numBones; ++i) {
|
for (uint32_t i = 0; i < numBones; ++i) {
|
||||||
const std::vector<aiVertexWeight> &weights = weighting[i];
|
const std::vector<aiVertexWeight> &weights = weighting[i];
|
||||||
if (weights.size() > 0) {
|
|
||||||
aiBone *bone = new aiBone();
|
aiBone *bone = new aiBone();
|
||||||
|
|
||||||
Ref<Node> joint = node.skin->jointNames[i];
|
Ref<Node> joint = node.skin->jointNames[i];
|
||||||
|
@ -970,10 +961,18 @@ aiNode *ImportNode(aiScene *pScene, glTF2::Asset &r, std::vector<unsigned int> &
|
||||||
GetNodeTransform(bone->mOffsetMatrix, *joint);
|
GetNodeTransform(bone->mOffsetMatrix, *joint);
|
||||||
CopyValue(pbindMatrices[i], bone->mOffsetMatrix);
|
CopyValue(pbindMatrices[i], bone->mOffsetMatrix);
|
||||||
bone->mNumWeights = static_cast<uint32_t>(weights.size());
|
bone->mNumWeights = static_cast<uint32_t>(weights.size());
|
||||||
|
|
||||||
|
if (bone->mNumWeights > 0) {
|
||||||
bone->mWeights = new aiVertexWeight[bone->mNumWeights];
|
bone->mWeights = new aiVertexWeight[bone->mNumWeights];
|
||||||
memcpy(bone->mWeights, weights.data(), bone->mNumWeights * sizeof(aiVertexWeight));
|
memcpy(bone->mWeights, weights.data(), bone->mNumWeights * sizeof(aiVertexWeight));
|
||||||
mesh->mBones[cb++] = bone;
|
} else {
|
||||||
|
// Assimp expects all bones to have at least 1 weight.
|
||||||
|
bone->mWeights = new aiVertexWeight[1];
|
||||||
|
bone->mNumWeights = 1;
|
||||||
|
bone->mWeights->mVertexId = 0;
|
||||||
|
bone->mWeights->mWeight = 0.f;
|
||||||
}
|
}
|
||||||
|
mesh->mBones[i] = bone;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pbindMatrices) {
|
if (pbindMatrices) {
|
||||||
|
|
Loading…
Reference in New Issue