Skip to content

Commit f66f60e

Browse files
committed
use animation recorder to record, then export result to fbx
1 parent 04fe4e3 commit f66f60e

File tree

7 files changed

+83
-179
lines changed

7 files changed

+83
-179
lines changed

com.unity.formats.fbx/Editor/Sources/Recorders/FbxRecorder/FbxInput.cs

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

com.unity.formats.fbx/Editor/Sources/Recorders/FbxRecorder/FbxInput.cs.meta

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

com.unity.formats.fbx/Editor/Sources/Recorders/FbxRecorder/FbxInputSettings.cs

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

com.unity.formats.fbx/Editor/Sources/Recorders/FbxRecorder/FbxInputSettings.cs.meta

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

com.unity.formats.fbx/Editor/Sources/Recorders/FbxRecorder/FbxRecorder.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
using UnityEditor.Recorder.Input;
66
using UnityEditor;
77

8-
namespace UnityEditor.Recorder
8+
namespace UnityEditor.Formats.Fbx.Exporter
99
{
10-
class FbxRecorder : GenericRecorder<FbxRecorderSettings>
10+
class FbxRecorder : GenericRecorder<FbxRecorderSettings>//GenericRecorder<FbxRecorderSettings>
1111
{
1212
public override void RecordFrame(RecordingSession ctx)
1313
{
@@ -16,7 +16,7 @@ public override void RecordFrame(RecordingSession ctx)
1616

1717
public override void EndRecording(RecordingSession session)
1818
{
19-
/*var ars = (AnimationRecorderSettings)session.settings;
19+
var ars = (FbxRecorderSettings)session.settings;
2020

2121
foreach (var input in m_Inputs)
2222
{
@@ -33,17 +33,27 @@ public override void EndRecording(RecordingSession session)
3333
var absolutePath = FileNameGenerator.SanitizePath(ars.fileNameGenerator.BuildAbsolutePath(session));
3434
var clipName = absolutePath.Replace(FileNameGenerator.SanitizePath(Application.dataPath), "Assets");
3535

36-
//AssetDatabase.CreateAsset(clip, clipName);
36+
//var tempClipName = System.IO.Path.ChangeExtension(clipName, ".asset");
37+
//AssetDatabase.CreateAsset(clip, tempClipName);
3738
#if UNITY_2018_3_OR_NEWER
3839
aInput.gameObjectRecorder.SaveToClip(clip, ars.frameRate);
3940
#else
4041
aInput.gameObjectRecorder.SaveToClip(clip);
4142
#endif
43+
var root = ((AnimationInputSettings)aInput.settings).gameObject;
44+
clip.name = "recorded_clip";
45+
Animation animator = root.AddComponent<Animation>();
46+
AnimationUtility.SetAnimationClips(animator, new AnimationClip[] { clip });
47+
var exportSettings = new ExportModelSettingsSerialize();
48+
exportSettings.SetModelAnimIncludeOption(ExportSettings.Include.Anim);
49+
ModelExporter.ExportObject(clipName, root, exportSettings);
4250

51+
52+
Object.DestroyImmediate(animator);
4353
aInput.gameObjectRecorder.ResetRecording();
4454
}
4555

46-
base.EndRecording(session);*/
56+
base.EndRecording(session);
4757
}
4858
}
4959
}

com.unity.formats.fbx/Editor/Sources/Recorders/FbxRecorder/FbxRecorderSettings.cs

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,81 @@
44
using UnityEditor.Recorder;
55
using UnityEditor.Recorder.Input;
66

7-
namespace UnityEditor.Recorder
7+
namespace UnityEditor.Formats.Fbx.Exporter
88
{
99
[RecorderSettings(typeof(FbxRecorder), "FBX", "fbx_recorder")]
1010
public class FbxRecorderSettings : RecorderSettings
1111
{
12-
[SerializeField] FbxInputSettings m_AnimationInputSettings = new FbxInputSettings();
12+
[SerializeField] AnimationInputSettings m_AnimationInputSettings = new AnimationInputSettings();
13+
14+
public AnimationInputSettings animationInputSettings
15+
{
16+
get { return m_AnimationInputSettings; }
17+
set { m_AnimationInputSettings = value; }
18+
}
19+
20+
public FbxRecorderSettings()
21+
{
22+
var goWildcard = DefaultWildcard.GeneratePattern("GameObject");
23+
24+
fileNameGenerator.AddWildcard(goWildcard, GameObjectNameResolver);
25+
fileNameGenerator.AddWildcard(DefaultWildcard.GeneratePattern("GameObjectScene"), GameObjectSceneNameResolver);
26+
27+
fileNameGenerator.forceAssetsFolder = true;
28+
fileNameGenerator.root = OutputPath.Root.AssetsFolder;
29+
fileNameGenerator.fileName = "animation_" + goWildcard + "_" + DefaultWildcard.Take;
30+
}
31+
32+
string GameObjectNameResolver(RecordingSession session)
33+
{
34+
var go = m_AnimationInputSettings.gameObject;
35+
return go != null ? go.name : "None";
36+
}
37+
38+
string GameObjectSceneNameResolver(RecordingSession session)
39+
{
40+
var go = m_AnimationInputSettings.gameObject;
41+
return go != null ? go.scene.name : "None";
42+
}
43+
44+
public override bool isPlatformSupported
45+
{
46+
get
47+
{
48+
return Application.platform == RuntimePlatform.LinuxEditor ||
49+
Application.platform == RuntimePlatform.OSXEditor ||
50+
Application.platform == RuntimePlatform.WindowsEditor;
51+
}
52+
}
1353

1454
public override IEnumerable<RecorderInputSettings> inputsSettings
1555
{
1656
get { yield return m_AnimationInputSettings; }
1757
}
1858

59+
internal override bool ValidityCheck(List<string> errors)
60+
{
61+
var ok = base.ValidityCheck(errors);
62+
63+
if (m_AnimationInputSettings.gameObject == null)
64+
{
65+
ok = false;
66+
errors.Add("No input object set");
67+
}
68+
69+
return ok;
70+
}
71+
72+
public override void OnAfterDuplicate()
73+
{
74+
m_AnimationInputSettings.DuplicateExposedReference();
75+
}
76+
77+
void OnDestroy()
78+
{
79+
m_AnimationInputSettings.ClearExposedReference();
80+
}
81+
1982
public override string extension
2083
{
2184
get { return "fbx"; }

com.unity.formats.fbx/Editor/Sources/Recorders/FbxRecorder/FbxRecorderSettingsEditor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
using UnityEditor.Recorder;
55
using UnityEditor;
66

7-
namespace UnityEditor.Recorder
7+
namespace UnityEditor.Formats.Fbx.Exporter
88
{
9-
[CustomEditor(typeof(AnimationRecorderSettings))]
9+
[CustomEditor(typeof(FbxRecorderSettings))]
1010
class FbxRecorderSettingsEditor : RecorderEditor
1111
{
1212
protected override void FileTypeAndFormatGUI()
1313
{
14-
EditorGUILayout.LabelField("Format", "Fbx");
14+
EditorGUILayout.LabelField("Format", "FBX");
1515
}
1616
}
1717
}

0 commit comments

Comments
 (0)