@@ -892,29 +892,6 @@ SkinnedMeshRenderer unitySkin
892
892
return true ;
893
893
}
894
894
895
- /// <summary>
896
- /// Determines whether this Transform is a bone.
897
- /// A transform is a bone if it is in the skinned meshes bone list (represented here as a bones dict),
898
- /// or if it has both an ancestor or descendant that are bones (i.e. if it is sandwiched between two bones,
899
- /// it should be a bone as well).
900
- /// </summary>
901
- /// <returns><c>true</c> if this transform is a bone; otherwise, <c>false</c>.</returns>
902
- /// <param name="t">Transform.</param>
903
- /// <param name="bones">Skinned meshes bones.</param>
904
- private bool IsBone ( Transform t , Dictionary < Transform , int > bones )
905
- {
906
- if ( bones . ContainsKey ( t ) ) {
907
- return true ;
908
- }
909
-
910
- foreach ( Transform child in t ) {
911
- if ( IsBone ( child , bones ) ) {
912
- return true ;
913
- }
914
- }
915
- return false ;
916
- }
917
-
918
895
/// <summary>
919
896
/// Gets the bind pose for the Unity bone.
920
897
/// </summary>
@@ -977,28 +954,17 @@ private bool ExportSkeleton (SkinnedMeshRenderer skinnedMesh, FbxScene fbxScene,
977
954
index [ unityBoneTransform ] = boneIndex ;
978
955
}
979
956
980
- // Step 1: create the bones.
957
+ // Step 1: gather all the bones
981
958
HashSet < Transform > boneSet = new HashSet < Transform > ( ) ;
982
- var s = new Stack < Transform > ( ) ;
983
- s . Push ( skinnedMesh . rootBone ) ;
959
+ var s = new Stack < Transform > ( bones ) ;
960
+ var root = skinnedMesh . rootBone ;
984
961
while ( s . Count > 0 ) {
985
- var t = s . Pop ( ) ;
986
-
987
- if ( IsBone ( t , index ) ) {
988
- if ( ! boneSet . Contains ( t ) ) {
989
- // Create the bone node if we haven't already. Parent it to
990
- // its corresponding parent, or to the scene if there is none.
991
- FbxNode fbxBoneNode ;
992
- if ( ! MapUnityObjectToFbxNode . TryGetValue ( t . gameObject , out fbxBoneNode ) ) {
993
- Debug . LogErrorFormat ( "Node {0} should already be created" , t . name ) ;
994
- }
962
+ var t = s . Pop ( ) ;
995
963
996
- boneSet . Add ( t ) ;
997
- }
964
+ boneSet . Add ( t ) ;
998
965
999
- foreach ( Transform child in t ) {
1000
- s . Push ( child ) ;
1001
- }
966
+ if ( t != root && t . parent != null && ! boneSet . Contains ( t . parent ) ) {
967
+ s . Push ( t . parent ) ;
1002
968
}
1003
969
}
1004
970
0 commit comments