Merge pull request #2261 from timmmeh/timmmeh-gltf2-validation-patch

Fix failed Assimp validation for glTF2.0 official sample animations
pull/2269/head
Kim Kulling 2018-12-11 20:15:42 +01:00 committed by GitHub
commit 15fe157fdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 5 deletions

View File

@ -832,7 +832,15 @@ aiNode* ImportNode(aiScene* pScene, glTF2::Asset& r, std::vector<unsigned int>&
aiBone* bone = new aiBone();
Ref<Node> joint = node.skin->jointNames[i];
if (!joint->name.empty()) {
bone->mName = joint->name;
} else {
// Assimp expects each bone to have a unique name.
static const std::string kDefaultName = "bone_";
char postfix[10] = {0};
ASSIMP_itoa10(postfix, i);
bone->mName = (kDefaultName + postfix);
}
GetNodeTransform(bone->mOffsetMatrix, *joint);
std::vector<aiVertexWeight>& weights = weighting[i];
@ -841,6 +849,12 @@ aiNode* ImportNode(aiScene* pScene, glTF2::Asset& r, std::vector<unsigned int>&
if (bone->mNumWeights > 0) {
bone->mWeights = new aiVertexWeight[bone->mNumWeights];
memcpy(bone->mWeights, weights.data(), bone->mNumWeights * sizeof(aiVertexWeight));
} 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;
}