Merge pull request #2543 from thomasbiang/fix_export_custom_bindpose_error

Fix export custom bindpose error
pull/2558/head
Kim Kulling 2019-07-21 14:36:24 +02:00 committed by GitHub
commit 46a8164af4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -1617,6 +1617,17 @@ void FBXExporter::WriteObjects ()
// at the same time we can build a list of all the skeleton nodes, // at the same time we can build a list of all the skeleton nodes,
// which will be used later to mark them as type "limbNode". // which will be used later to mark them as type "limbNode".
std::unordered_set<const aiNode*> limbnodes; std::unordered_set<const aiNode*> limbnodes;
//actual bone nodes in fbx, without parenting-up
std::unordered_set<std::string> setAllBoneNamesInScene;
for(unsigned int m = 0; m < mScene->mNumMeshes; ++ m)
{
aiMesh* pMesh = mScene->mMeshes[m];
for(unsigned int b = 0; b < pMesh->mNumBones; ++ b)
setAllBoneNamesInScene.insert(pMesh->mBones[b]->mName.data);
}
aiMatrix4x4 mxTransIdentity;
// and a map of nodes by bone name, as finding them is annoying. // and a map of nodes by bone name, as finding them is annoying.
std::map<std::string,aiNode*> node_by_bone; std::map<std::string,aiNode*> node_by_bone;
for (size_t mi = 0; mi < mScene->mNumMeshes; ++mi) { for (size_t mi = 0; mi < mScene->mNumMeshes; ++mi) {
@ -1660,6 +1671,11 @@ void FBXExporter::WriteObjects ()
if (node_name.find(MAGIC_NODE_TAG) != std::string::npos) { if (node_name.find(MAGIC_NODE_TAG) != std::string::npos) {
continue; continue;
} }
//not a bone in scene && no effect in transform
if(setAllBoneNamesInScene.find(node_name)==setAllBoneNamesInScene.end()
&& parent->mTransformation == mxTransIdentity) {
continue;
}
// otherwise check if this is the root of the skeleton // otherwise check if this is the root of the skeleton
bool end = false; bool end = false;
// is the mesh part of this node? // is the mesh part of this node?
@ -1824,7 +1840,10 @@ void FBXExporter::WriteObjects ()
// this should be the same as the bone's mOffsetMatrix. // this should be the same as the bone's mOffsetMatrix.
// if it's not the same, the skeleton isn't in the bind pose. // if it's not the same, the skeleton isn't in the bind pose.
const float epsilon = 1e-4f; // some error is to be expected float epsilon = 1e-4f; // some error is to be expected
float epsilon_custom = mProperties->GetPropertyFloat("BINDPOSE_EPSILON", -1);
if(epsilon_custom > 0)
epsilon = epsilon_custom;
bool bone_xform_okay = true; bool bone_xform_okay = true;
if (b && ! tr.Equal(b->mOffsetMatrix, epsilon)) { if (b && ! tr.Equal(b->mOffsetMatrix, epsilon)) {
not_in_bind_pose.insert(b); not_in_bind_pose.insert(b);

View File

@ -74,7 +74,7 @@ TEST_F( utIssues, OpacityBugWhenExporting_727 ) {
if ( newScene->mNumMaterials > 0 ) { if ( newScene->mNumMaterials > 0 ) {
std::cout << "Desc = " << desc->description << "\n"; std::cout << "Desc = " << desc->description << "\n";
EXPECT_EQ( AI_SUCCESS, newScene->mMaterials[ 0 ]->Get( AI_MATKEY_OPACITY, newOpacity ) ); EXPECT_EQ( AI_SUCCESS, newScene->mMaterials[ 0 ]->Get( AI_MATKEY_OPACITY, newOpacity ) );
EXPECT_EQ( opacity, newOpacity ); EXPECT_FLOAT_EQ( opacity, newOpacity );
} }
delete scene; delete scene;
} }