@@ -984,10 +984,9 @@ private bool ExportSkeleton (SkinnedMeshRenderer skinnedMesh, FbxScene fbxScene,
984
984
return false ;
985
985
}
986
986
987
- // Three steps:
987
+ // Two steps:
988
988
// 0. Set up the map from bone to index.
989
- // 1. Gather complete list of bones
990
- // 2. Set the transforms.
989
+ // 1. Set the transforms.
991
990
992
991
// Step 0: map transform to index so we can look up index by bone.
993
992
Dictionary < Transform , int > index = new Dictionary < Transform , int > ( ) ;
@@ -996,44 +995,11 @@ private bool ExportSkeleton (SkinnedMeshRenderer skinnedMesh, FbxScene fbxScene,
996
995
index [ unityBoneTransform ] = boneIndex ;
997
996
}
998
997
999
- // Step 1: gather all the bones
1000
- HashSet < Transform > boneSet = new HashSet < Transform > ( ) ;
1001
- var s = new Stack < Transform > ( bones ) ;
1002
- var root = skinnedMesh . rootBone ;
1003
- while ( s . Count > 0 ) {
1004
- var t = s . Pop ( ) ;
998
+ skinnedMeshToBonesMap . Add ( skinnedMesh , bones ) ;
1005
999
1006
- if ( ! boneSet . Add ( t ) ) {
1007
- continue ;
1008
- }
1009
-
1010
- if ( t . parent == null ) {
1011
- Debug . LogWarningFormat (
1012
- "FbxExporter: {0} is a bone but not a descendant of {1}'s mesh's root bone." ,
1013
- t . name , skinnedMesh . name
1014
- ) ;
1015
- continue ;
1016
- }
1017
-
1018
- // Each skinned mesh in Unity has one root bone, but may have objects
1019
- // between the root bone and leaf bones that are not in the bone list.
1020
- // However all objects between two bones in a hierarchy should be bones
1021
- // as well.
1022
- // e.g. in rootBone -> bone1 -> obj1 -> bone2, obj1 should be a bone
1023
- //
1024
- // Traverse from all leaf bones to the root bone adding everything in between
1025
- // to the boneSet regardless of whether it is in the skinned mesh's bone list.
1026
- if ( t != root && ! boneSet . Contains ( t . parent ) ) {
1027
- s . Push ( t . parent ) ;
1028
- }
1029
- }
1030
-
1031
- var boneList = boneSet . ToArray ( ) ;
1032
- skinnedMeshToBonesMap . Add ( skinnedMesh , boneList ) ;
1033
-
1034
- // Step 2: Set transforms
1000
+ // Step 1: Set transforms
1035
1001
var boneInfo = new SkinnedMeshBoneInfo ( skinnedMesh , index ) ;
1036
- foreach ( var bone in boneList ) {
1002
+ foreach ( var bone in bones ) {
1037
1003
var fbxBone = MapUnityObjectToFbxNode [ bone . gameObject ] ;
1038
1004
ExportBoneTransform ( fbxBone , fbxScene , bone , boneInfo ) ;
1039
1005
}
@@ -2826,7 +2792,9 @@ private bool ExportGameObjectAndParents(
2826
2792
}
2827
2793
2828
2794
SkinnedMeshBoneInfo parentBoneInfo = null ;
2829
- if ( boneInfo != null && boneInfo . skinnedMesh . rootBone != null && unityGo . transform != boneInfo . skinnedMesh . rootBone ) {
2795
+ if ( boneInfo != null && boneInfo . skinnedMesh . rootBone != null &&
2796
+ unityGo . transform != boneInfo . skinnedMesh . rootBone && boneInfo . boneDict . ContainsKey ( unityGo . transform . parent ) )
2797
+ {
2830
2798
parentBoneInfo = boneInfo ;
2831
2799
}
2832
2800
@@ -2891,17 +2859,13 @@ private bool ExportBoneTransform(
2891
2859
}
2892
2860
2893
2861
Matrix4x4 pose ;
2894
- if ( unityBone == rootBone ) {
2895
- pose = ( unityBone . parent . worldToLocalMatrix * skinnedMesh . transform . localToWorldMatrix * bindPose . inverse ) ;
2896
- } else {
2897
- // get parent's bind pose
2898
- Matrix4x4 parentBindPose ;
2899
- if ( ! boneInfo . boneToBindPose . TryGetValue ( unityBone . parent , out parentBindPose ) ) {
2900
- parentBindPose = GetBindPose ( unityBone . parent , bindPoses , boneDict , skinnedMesh ) ;
2901
- boneInfo . boneToBindPose . Add ( unityBone . parent , parentBindPose ) ;
2902
- }
2903
- pose = parentBindPose * bindPose . inverse ;
2862
+ // get parent's bind pose
2863
+ Matrix4x4 parentBindPose ;
2864
+ if ( ! boneInfo . boneToBindPose . TryGetValue ( unityBone . parent , out parentBindPose ) ) {
2865
+ parentBindPose = GetBindPose ( unityBone . parent , bindPoses , boneDict , skinnedMesh ) ;
2866
+ boneInfo . boneToBindPose . Add ( unityBone . parent , parentBindPose ) ;
2904
2867
}
2868
+ pose = parentBindPose * bindPose . inverse ;
2905
2869
2906
2870
FbxVector4 translation , rotation , scale ;
2907
2871
GetTRSFromMatrix ( pose , out translation , out rotation , out scale ) ;
0 commit comments