Skip to content

Commit 5029f35

Browse files
committed
simplify how bones are gathered in export skeleton
- assume that the bone hierarchy has a single root: the root bone - go from the known bones upwards, adding all nodes that are in between the starting bone and the root to the bone set
1 parent 2ffef6e commit 5029f35

File tree

1 file changed

+7
-41
lines changed

1 file changed

+7
-41
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -892,29 +892,6 @@ SkinnedMeshRenderer unitySkin
892892
return true;
893893
}
894894

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-
918895
/// <summary>
919896
/// Gets the bind pose for the Unity bone.
920897
/// </summary>
@@ -977,28 +954,17 @@ private bool ExportSkeleton (SkinnedMeshRenderer skinnedMesh, FbxScene fbxScene,
977954
index[unityBoneTransform] = boneIndex;
978955
}
979956

980-
// Step 1: create the bones.
957+
// Step 1: gather all the bones
981958
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;
984961
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 ();
995963

996-
boneSet.Add (t);
997-
}
964+
boneSet.Add (t);
998965

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);
1002968
}
1003969
}
1004970

0 commit comments

Comments
 (0)