@@ -102,6 +102,7 @@ FbxScene *VROFBXExporter::loadFBX(std::string fbxPath) {
102
102
//
103
103
// NOTE: This apparently stopped working after FBX SDK 2015 (tried in versions 2016 and 2018)
104
104
// https://forums.autodesk.com/t5/fbx-forum/issue-with-convertpivotanimationrecursive-and-default-transform/td-p/6887073
105
+ pinfo (" Baking pivots..." );
105
106
scene->GetRootNode ()->ResetPivotSetAndConvertAnimation (kAnimationFPS );
106
107
107
108
return scene;
@@ -566,14 +567,12 @@ bool SortByBoneWeight(const VROBoneIndexWeight &i, const VROBoneIndexWeight &j)
566
567
567
568
void VROFBXExporter::exportSkin (FbxNode *node, const viro::Node::Skeleton &skeleton, viro::Node::Geometry::Skin *outSkin) {
568
569
FbxMesh *mesh = node->GetMesh ();
569
- unsigned int numDeformers = mesh->GetDeformerCount ();
570
-
571
- // Not understood, typically identity matrix
572
- // FbxAMatrix geometryTransform = Utilities::GetGeometryTransformation(node);
573
-
574
- // Each FBX deformer contains clusters. Clusters each contain a link (which is a
575
- // bone). Normally only one deformer per mesh.
576
570
571
+ /*
572
+ Each FBX deformer contains clusters. Clusters each contain a link (which is a
573
+ bone). Normally only one deformer per mesh.
574
+ */
575
+ unsigned int numDeformers = mesh->GetDeformerCount ();
577
576
std::map<int , std::vector<VROBoneIndexWeight>> bones;
578
577
579
578
for (unsigned int deformerIndex = 0 ; deformerIndex < numDeformers; ++deformerIndex) {
@@ -616,6 +615,16 @@ void VROFBXExporter::exportSkin(FbxNode *node, const viro::Node::Skeleton &skele
616
615
*/
617
616
std::string boneName = cluster->GetLink ()->GetName ();
618
617
unsigned int boneIndex = findBoneIndexUsingName (boneName, skeleton);
618
+
619
+ /*
620
+ If a model has more bones that we support, we ignore the bones that are beyond
621
+ our max bone index. This will likely ruin the animation, so log a warning.
622
+ */
623
+ if (boneIndex >= kMaxBones ) {
624
+ pinfo (" Warning: Viro only supports %d bones: bone %d will be discarded, animations may be skewed" ,
625
+ kMaxBones , boneIndex);
626
+ continue ;
627
+ }
619
628
620
629
/*
621
630
Sanity check: the transform matrix for each cluster's parent node should
@@ -652,8 +661,10 @@ void VROFBXExporter::exportSkin(FbxNode *node, const viro::Node::Skeleton &skele
652
661
int controlPointIndex = cluster->GetControlPointIndices ()[i];
653
662
float boneWeight = cluster->GetControlPointWeights ()[i];
654
663
655
- // Associates a control point (vertex) with a bone, and gives
656
- // the bone a weight on that control point
664
+ /*
665
+ Associates a control point (vertex) with a bone, and gives
666
+ the bone a weight on that control point.
667
+ */
657
668
VROBoneIndexWeight bone (boneIndex, boneWeight);
658
669
bones[controlPointIndex].push_back (bone);
659
670
}
@@ -663,11 +674,11 @@ void VROFBXExporter::exportSkin(FbxNode *node, const viro::Node::Skeleton &skele
663
674
for (auto &kv : bones) {
664
675
std::vector<VROBoneIndexWeight> &bones = kv.second ;
665
676
666
- // If there are more than kMaxBones bones, use only those with greatest
677
+ // If there are more than kMaxBoneInfluences bones, use only those with greatest
667
678
// weight, and renormalize
668
- if (bones.size () > kMaxBones ) {
679
+ if (bones.size () > kMaxBoneInfluences ) {
669
680
std::sort (bones.begin (), bones.end (), SortByBoneWeight);
670
- bones.erase (bones.begin () + kMaxBones , bones.end ());
681
+ bones.erase (bones.begin () + kMaxBoneInfluences , bones.end ());
671
682
672
683
float total = 0 ;
673
684
for (VROBoneIndexWeight &bone : bones) {
@@ -679,8 +690,8 @@ void VROFBXExporter::exportSkin(FbxNode *node, const viro::Node::Skeleton &skele
679
690
}
680
691
681
692
// Add extra dummy bones to each control point that has fewer than
682
- // kMaxBones
683
- for (size_t i = bones.size (); i < kMaxBones ; ++i) {
693
+ // kMaxBoneInfluences
694
+ for (size_t i = bones.size (); i < kMaxBoneInfluences ; ++i) {
684
695
bones.push_back ({0 , 0 });
685
696
}
686
697
}
@@ -713,14 +724,14 @@ void VROFBXExporter::exportSkin(FbxNode *node, const viro::Node::Skeleton &skele
713
724
pinfo (" No bones found for control point %d" , controlPointIndex);
714
725
}
715
726
716
- for (int b = 0 ; b < kMaxBones ; b++) {
727
+ for (int b = 0 ; b < kMaxBoneInfluences ; b++) {
717
728
boneIndicesData.push_back (0 );
718
729
boneWeightsData.push_back (0 );
719
730
}
720
731
}
721
732
else {
722
733
std::vector<VROBoneIndexWeight> &boneData = it->second ;
723
- passert (boneData.size () == kMaxBones );
734
+ passert (boneData.size () == kMaxBoneInfluences );
724
735
725
736
if (kDebugGeometrySource ) {
726
737
pinfo (" Control point %d" , controlPointIndex);
@@ -738,27 +749,27 @@ void VROFBXExporter::exportSkin(FbxNode *node, const viro::Node::Skeleton &skele
738
749
}
739
750
}
740
751
741
- int intsPerVertex = kMaxBones ;
752
+ int intsPerVertex = kMaxBoneInfluences ;
742
753
int numVertices = (uint32_t )boneIndicesData.size () / intsPerVertex;
743
754
744
755
viro::Node::Geometry::Source *boneIndices = outSkin->mutable_bone_indices ();
745
756
boneIndices->set_semantic (viro::Node_Geometry_Source_Semantic_BoneIndices);
746
757
boneIndices->set_vertex_count (numVertices);
747
758
boneIndices->set_float_components (false );
748
- boneIndices->set_components_per_vertex (kMaxBones );
759
+ boneIndices->set_components_per_vertex (kMaxBoneInfluences );
749
760
boneIndices->set_bytes_per_component (sizeof (int ));
750
761
boneIndices->set_data_offset (0 );
751
- boneIndices->set_data_stride (sizeof (int ) * kMaxBones );
762
+ boneIndices->set_data_stride (sizeof (int ) * kMaxBoneInfluences );
752
763
boneIndices->set_data (boneIndicesData.data (), boneIndicesData.size () * sizeof (int ));
753
764
754
765
viro::Node::Geometry::Source *boneWeights = outSkin->mutable_bone_weights ();
755
766
boneWeights->set_semantic (viro::Node_Geometry_Source_Semantic_BoneWeights);
756
767
boneWeights->set_vertex_count (numVertices);
757
768
boneWeights->set_float_components (true );
758
- boneWeights->set_components_per_vertex (kMaxBones );
769
+ boneWeights->set_components_per_vertex (kMaxBoneInfluences );
759
770
boneWeights->set_bytes_per_component (sizeof (float ));
760
771
boneWeights->set_data_offset (0 );
761
- boneWeights->set_data_stride (sizeof (float ) * kMaxBones );
772
+ boneWeights->set_data_stride (sizeof (float ) * kMaxBoneInfluences );
762
773
boneWeights->set_data (boneWeightsData.data (), boneWeightsData.size () * sizeof (float ));
763
774
}
764
775
0 commit comments