Skip to content

Commit a2589e5

Browse files
committed
Merge branch 'master' into UNI-41138-connect-UI-to-exporter
2 parents 2ac023c + df46dee commit a2589e5

13 files changed

+107
-765
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 100 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ namespace Editor
6464

6565
public class ModelExporter : System.IDisposable
6666
{
67+
// To be replaced by checkbox in Fbx Export settings
68+
bool removeAnimationsFromSkinnedMeshRenderer = true;
69+
6770
const string Title =
6871
"exports static meshes with materials and textures";
6972

@@ -1267,9 +1270,23 @@ protected bool ExportInstance (GameObject unityGo, FbxNode fbxNode, FbxScene fbx
12671270
SharedMeshes [unityPrefabParent.name] = fbxNode.GetMesh ();
12681271
return true;
12691272
}
1273+
return false;
12701274
}
1275+
1276+
// We don't export the mesh because we already have it from the parent, but we still need to assign the material
1277+
var renderer = unityGo.GetComponent<Renderer>();
1278+
var materials = renderer ? renderer.sharedMaterials : null;
12711279

1272-
if (fbxMesh == null) return false;
1280+
Unity.FbxSdk.FbxSurfaceMaterial newMaterial = null;
1281+
if (materials != null)
1282+
{
1283+
foreach (var mat in materials) {
1284+
if (MaterialMap.TryGetValue(mat.name, out newMaterial));
1285+
{
1286+
fbxNode.AddMaterial(newMaterial);
1287+
}
1288+
}
1289+
}
12731290

12741291
// set the fbxNode containing the mesh
12751292
fbxNode.SetNodeAttribute (fbxMesh);
@@ -1791,6 +1808,12 @@ protected void ExportAnimationClip (AnimationClip uniAnimClip, GameObject uniRoo
17911808
if (!uniGO) {
17921809
continue;
17931810
}
1811+
1812+
// Do not create the curves if the component is a SkinnedMeshRenderer and if the option in FBX Export settings is toggled on.
1813+
if (removeAnimationsFromSkinnedMeshRenderer && (uniGO.GetComponent<SkinnedMeshRenderer>() != null || uniGO.GetComponentInChildren<SkinnedMeshRenderer>() != null))
1814+
{
1815+
continue;
1816+
}
17941817

17951818
int index = QuaternionCurve.GetQuaternionIndex (uniCurveBinding.propertyName);
17961819
if (index >= 0) {
@@ -2985,6 +3008,24 @@ static void OnClipContextClick(MenuCommand command)
29853008
}
29863009
}
29873010

3011+
/// <summary>
3012+
/// Validate the menu item defined by the function OnClipContextClick.
3013+
/// </summary>
3014+
[MenuItem(TimelineClipMenuItemName, true, 31)]
3015+
static bool ValidateOnClipContextClick()
3016+
{
3017+
Object[] selectedObjects = Selection.objects;
3018+
3019+
foreach (Object editorClipSelected in selectedObjects)
3020+
{
3021+
if (editorClipSelected.GetType().Name.Contains("EditorClip"))
3022+
{
3023+
return true;
3024+
}
3025+
}
3026+
return false;
3027+
}
3028+
29883029
protected static bool ExportSingleEditorClip(Object editorClipSelected)
29893030
{
29903031
if (editorClipSelected.GetType().Name.Contains("EditorClip"))
@@ -3003,19 +3044,25 @@ protected static bool ExportSingleEditorClip(Object editorClipSelected)
30033044
return false;
30043045
}
30053046

3006-
public static void ExportSingleTimelineClip(TimelineClip timelineClipSelected, GameObject animationTrackGObject, string filePath = null)
3047+
public static void ExportSingleTimelineClip(TimelineClip timelineClipSelected, GameObject animationTrackGObject, string folderPath = null)
30073048
{
3008-
UnityEngine.Object[] myArray = new UnityEngine.Object[] {
3049+
3050+
UnityEngine.Object[] exportArray = new UnityEngine.Object[] {
30093051
animationTrackGObject,
30103052
timelineClipSelected.animationClip
30113053
};
30123054

30133055
if (!string.IsNullOrEmpty (filePath)) {
3014-
ExportObjects (filePath, myArray, timelineAnim: true);
3056+
ExportObjects (filePath, exportArray, timelineAnim: true);
30153057
return;
30163058
}
30173059

3018-
ExportModelEditorWindow.Init (myArray, string.Format ("{0}@{1}", animationTrackGObject.name, timelineClipSelected.displayName), isTimelineAnim: true);
3060+
string AnimFbxFormat = "{0}@{1}";
3061+
if (timelineClipSelected.displayName.Contains("@"))
3062+
{
3063+
AnimFbxFormat = "{1}";
3064+
}
3065+
ExportModelEditorWindow.Init (myArray, string.Format (AnimFbxFormat, animationTrackGObject.name, timelineClipSelected.displayName), isTimelineAnim: true);
30193066
}
30203067

30213068
/// <summary>
@@ -3075,7 +3122,7 @@ public static void ExportAllTimelineClips(GameObject objectWithPlayableDirector,
30753122
}
30763123

30773124
/// <summary>
3078-
/// Validate the menu item defined by the function above.
3125+
/// Validate the menu item defined by the function OnPlayableDirectorGameObjectContextClick.
30793126
/// </summary>
30803127
[MenuItem(ClipMenuItemName, true, 31)]
30813128
public static bool ValidateClipContextClick()
@@ -3090,7 +3137,7 @@ public static bool ValidateClipContextClick()
30903137
foreach (Object obj in selection)
30913138
{
30923139
GameObject gameObj = obj as GameObject;
3093-
if (gameObj !=null && gameObj.GetComponent<PlayableDirector>() != null)
3140+
if (gameObj != null && gameObj.GetComponent<PlayableDirector>() != null)
30943141
{
30953142
return true;
30963143
}
@@ -3099,6 +3146,33 @@ public static bool ValidateClipContextClick()
30993146
return false;
31003147
}
31013148

3149+
public static void ExportAllTimelineClips(GameObject objectWithPlayableDirector, string folderPath)
3150+
{
3151+
PlayableDirector pd = objectWithPlayableDirector.GetComponent<PlayableDirector>();
3152+
if (pd != null)
3153+
{
3154+
foreach (PlayableBinding output in pd.playableAsset.outputs)
3155+
{
3156+
AnimationTrack animationTrack = output.sourceObject as AnimationTrack;
3157+
3158+
GameObject animationTrackObject = pd.GetGenericBinding(output.sourceObject) as GameObject;
3159+
// One file by animation clip
3160+
foreach(TimelineClip timelineClip in animationTrack.GetClips())
3161+
{
3162+
string AnimFbxFormat = AnimFbxFileFormat;
3163+
if (timelineClip.displayName.Contains("@"))
3164+
{
3165+
AnimFbxFormat = "{0}/{2}.fbx";
3166+
}
3167+
string filePath = string.Format(AnimFbxFormat, folderPath, animationTrackObject.name, timelineClip.displayName);
3168+
3169+
UnityEngine.Object[] exportArray = new UnityEngine.Object[] { animationTrackObject, timelineClip.animationClip };
3170+
ExportObjects(filePath, exportArray, AnimationExportType.timelineAnimationClip);
3171+
}
3172+
}
3173+
}
3174+
}
3175+
31023176
/// <summary>
31033177
/// Add a menu item "Export Model..." to a GameObject's context menu.
31043178
/// </summary>
@@ -3114,7 +3188,7 @@ static void OnContextItem (MenuCommand command)
31143188
}
31153189

31163190
/// <summary>
3117-
/// Validate the menu item defined by the function above.
3191+
/// Validate the menu item defined by the function OnContextItem.
31183192
/// </summary>
31193193
[MenuItem (MenuItemName, true, 30)]
31203194
public static bool OnValidateMenuItem ()
@@ -3123,7 +3197,7 @@ public static bool OnValidateMenuItem ()
31233197
}
31243198

31253199
/// <summary>
3126-
/// Validate the menu item defined by the function above.
3200+
/// Validate the menu item defined by the function ModelOnlyOnContextItem.
31273201
/// </summary>
31283202
[MenuItem (ModelOnlyMenuItemName, true, 30)]
31293203
public static bool ModelOnlyOnValidateMenuItem ()
@@ -3137,7 +3211,23 @@ public static bool ModelOnlyOnValidateMenuItem ()
31373211
[MenuItem (AnimOnlyMenuItemName, true, 30)]
31383212
public static bool OnValidateAnimOnlyMenuItem ()
31393213
{
3140-
return true;
3214+
Object[] selection = Selection.objects;
3215+
3216+
if (selection == null || selection.Length == 0)
3217+
{
3218+
return false;
3219+
}
3220+
3221+
foreach (Object obj in selection)
3222+
{
3223+
GameObject gameObj = obj as GameObject;
3224+
if (gameObj != null && (gameObj.GetComponent<Animation>() != null || gameObj.GetComponent<Animator>() != null))
3225+
{
3226+
return true;
3227+
}
3228+
}
3229+
3230+
return false;
31413231
}
31423232

31433233
public static void DisplayNoSelectionDialog()

Assets/FbxExporters/Editor/UnitTests/ExportTimelineClipTest.cs.meta

Lines changed: 0 additions & 13 deletions
This file was deleted.

Assets/FbxExporters/Editor/UnitTests/ExporterTestBase.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,6 @@ void DeleteOnNextUpdate()
194194
[TearDown]
195195
public virtual void Term ()
196196
{
197-
// Put back the initial setting for the auto-updater toggle
198-
FbxExporters.EditorTools.ExportSettings.instance.autoUpdaterEnabled = isAutoUpdaterOn;
199-
200197
if (string.IsNullOrEmpty(_testDirectory)) {
201198
return;
202199
}
@@ -216,6 +213,7 @@ public virtual void Init()
216213
FbxExporters.EditorTools.ExportSettings.instance.autoUpdaterEnabled = true;
217214
}
218215

216+
219217
/// <summary>
220218
/// Exports the Objects in selected.
221219
/// </summary>

Assets/FbxExporters/Editor/UnitTests/FbxAnimationTest.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -834,11 +834,7 @@ public void AnimOnlyExportTest(string prefabPath)
834834

835835
// export fbx
836836
// get GameObject
837-
string filename = GetRandomFbxFilePath ();
838-
var exportOptions = new EditorTools.ExportModelSettingsSerialize ();
839-
exportOptions.SetModelAnimIncludeOption(FbxExporters.EditorTools.ExportSettings.Include.Anim);
840-
var exportedFilePath = ModelExporter.ExportObject (filename, originalGO, exportOptions);
841-
Assert.That (exportedFilePath, Is.EqualTo (filename));
837+
string filename = ExportToFbx(originalGO, true);
842838

843839
GameObject fbxObj = AssetDatabase.LoadMainAssetAtPath (filename) as GameObject;
844840
Assert.IsTrue (fbxObj);

Assets/FbxExporters/Editor/UnitTests/FbxCameraTests.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

Assets/FbxExporters/Editor/UnitTests/FbxPrefabAutoUpdaterTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,13 @@ public void TestNameMapping()
159159
// In FbxPrefab Component of Cube, add SphereFBX/Sphere name mapping
160160
FbxPrefab fbxPrefabScript = cubePrefabInstance.transform.GetComponent<FbxPrefab>();
161161

162+
162163
FbxPrefab.StringPair stringpair = new FbxPrefab.StringPair();
163164
stringpair.FBXObjectName = "SphereFBX";
164165
stringpair.UnityObjectName = "Sphere";
165166
fbxPrefabScript.NameMapping.Add(stringpair);
166167

168+
167169
FbxPrefabAutoUpdater.FbxPrefabUtility fbxPrefabUtility = new FbxPrefabAutoUpdater.FbxPrefabUtility(fbxPrefabScript);
168170

169171
Assert.IsTrue(fbxPrefabUtility.GetUnityObjectName("SphereFBX") == stringpair.UnityObjectName);
@@ -327,7 +329,7 @@ public void RemappingTest()
327329

328330

329331
[TearDown]
330-
public void StopTest()
332+
public void stopTest()
331333
{
332334
// Put back the initial setting for the auto-updater toggle
333335
FbxExporters.EditorTools.ExportSettings.instance.autoUpdaterEnabled = isAutoUpdaterOn;

Assets/FbxExporters/Editor/UnitTests/Models/Cowboy/cowboyMidPoly(riged).FBX.meta

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/FbxExporters/Editor/UnitTests/Scene.meta

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)