Skip to content

Commit 6b3435c

Browse files
committed
add collect dependencies that takes a single anim clip
1 parent 42a5ff1 commit 6b3435c

File tree

2 files changed

+49
-37
lines changed

2 files changed

+49
-37
lines changed

Packages/com.unity.formats.fbx/Editor/Scripts/FbxExporter.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2944,15 +2944,12 @@ public static IExportData GetExportData(GameObject rootObject, AnimationClip ani
29442944
exportOptions = DefaultOptions;
29452945
Debug.Assert(exportOptions!=null);
29462946

2947-
// get animation clips for root object from animation track
2948-
List<AnimationClip> clips = new List<AnimationClip>(){animationClip};
2949-
29502947
var goToExport = new HashSet<GameObject>();
29512948
var animationClips = new Dictionary<AnimationClip, GameObject>();
29522949
var exportComponent = new Dictionary<GameObject, System.Type>();
29532950

29542951
var exportData = new AnimationOnlyExportData(animationClips, goToExport, exportComponent);
2955-
exportData.CollectDependencies(clips.ToArray(), rootObject, exportOptions);
2952+
exportData.CollectDependencies(animationClip, rootObject, exportOptions);
29562953

29572954
return exportData;
29582955
}

Packages/com.unity.formats.fbx/Editor/Scripts/IExportData.cs

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,57 +47,72 @@ public AnimationOnlyExportData(
4747
}
4848

4949
/// <summary>
50-
/// collect all objects dependencies for animation clips.
50+
/// collect all object dependencies for given animation clip
5151
/// </summary>
5252
public void CollectDependencies(
53-
AnimationClip[] animClips,
53+
AnimationClip animClip,
5454
GameObject rootObject,
5555
IExportOptions exportOptions
5656
)
5757
{
5858
Debug.Assert(rootObject != null);
5959
Debug.Assert(exportOptions != null);
6060

61+
if (this.animationClips.ContainsKey(animClip))
62+
{
63+
// we have already exported gameobjects for this clip
64+
return;
65+
}
66+
6167
// NOTE: the object (animationRootObject) containing the animation is not necessarily animated
6268
// when driven by an animator or animation component.
63-
foreach (var animClip in animClips)
69+
this.animationClips.Add(animClip, rootObject);
70+
71+
foreach (EditorCurveBinding uniCurveBinding in AnimationUtility.GetCurveBindings(animClip))
6472
{
65-
if (this.animationClips.ContainsKey(animClip))
73+
Object uniObj = AnimationUtility.GetAnimatedObject(rootObject, uniCurveBinding);
74+
if (!uniObj)
6675
{
67-
// we have already exported gameobjects for this clip
68-
continue;
76+
return;
6977
}
7078

71-
this.animationClips.Add(animClip, rootObject);
79+
GameObject unityGo = ModelExporter.GetGameObject(uniObj);
80+
if (!unityGo)
81+
{
82+
return;
83+
}
7284

73-
foreach (EditorCurveBinding uniCurveBinding in AnimationUtility.GetCurveBindings(animClip))
85+
if (!exportOptions.AnimateSkinnedMesh && unityGo.GetComponent<SkinnedMeshRenderer>())
7486
{
75-
Object uniObj = AnimationUtility.GetAnimatedObject(rootObject, uniCurveBinding);
76-
if (!uniObj)
77-
{
78-
continue;
79-
}
80-
81-
GameObject unityGo = ModelExporter.GetGameObject(uniObj);
82-
if (!unityGo)
83-
{
84-
continue;
85-
}
86-
87-
if (!exportOptions.AnimateSkinnedMesh && unityGo.GetComponent<SkinnedMeshRenderer>())
88-
{
89-
continue;
90-
}
91-
92-
// If we have a clip driving a camera or light then force the export of FbxNodeAttribute
93-
// so that they point the right way when imported into Maya.
94-
if (unityGo.GetComponent<Light>())
95-
this.exportComponent[unityGo] = typeof(Light);
96-
else if (unityGo.GetComponent<Camera>())
97-
this.exportComponent[unityGo] = typeof(Camera);
98-
99-
this.goExportSet.Add(unityGo);
87+
return;
10088
}
89+
90+
// If we have a clip driving a camera or light then force the export of FbxNodeAttribute
91+
// so that they point the right way when imported into Maya.
92+
if (unityGo.GetComponent<Light>())
93+
this.exportComponent[unityGo] = typeof(Light);
94+
else if (unityGo.GetComponent<Camera>())
95+
this.exportComponent[unityGo] = typeof(Camera);
96+
97+
this.goExportSet.Add(unityGo);
98+
}
99+
}
100+
101+
/// <summary>
102+
/// collect all objects dependencies for animation clips.
103+
/// </summary>
104+
public void CollectDependencies(
105+
AnimationClip[] animClips,
106+
GameObject rootObject,
107+
IExportOptions exportOptions
108+
)
109+
{
110+
Debug.Assert(rootObject != null);
111+
Debug.Assert(exportOptions != null);
112+
113+
foreach (var animClip in animClips)
114+
{
115+
CollectDependencies(animClip, rootObject, exportOptions);
101116
}
102117
}
103118

0 commit comments

Comments
 (0)