Skip to content

Commit

Permalink
feat: allow changing the AnimationName when recording clips and from …
Browse files Browse the repository at this point in the history
…TimelineTracks
  • Loading branch information
hybridherbst committed May 15, 2023
1 parent 6730e5e commit 9513b30
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public GLTFRecorder(Transform root, bool recordBlendShapes = true, bool recordRo

public bool IsRecording => isRecording;
public double LastRecordedTime => lastRecordedTime;
public string AnimationName = "Recording";

internal class AnimationData
{
Expand Down Expand Up @@ -306,7 +307,7 @@ private void PostExport(GLTFSceneExporter exporter, GLTFRoot gltfRoot)
// exporter.ExportAnimationFromNode(ref root);

GLTFAnimation anim = new GLTFAnimation();
anim.Name = "Recording";
anim.Name = AnimationName;

CollectAndProcessAnimation(exporter, anim, addBoundsMarkerNodes, out Bounds translationBounds);

Expand Down Expand Up @@ -372,6 +373,7 @@ private static void SafeDestroy(Object obj)
private static ProfilerMarker processAnimationMarker = new ProfilerMarker("Process Animation");
private static ProfilerMarker simplifyKeyframesMarker = new ProfilerMarker("Simplify Keyframes");
private static ProfilerMarker convertValuesMarker = new ProfilerMarker("Convert Values to Arrays");

private void CollectAndProcessAnimation(GLTFSceneExporter gltfSceneExporter, GLTFAnimation anim, bool calculateTranslationBounds, out Bounds translationBounds)
{
var gotFirstValue = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ private void ProcessRecording(double getTime, Transform getExportRoot)
if (recorder == null)
{
recorder = new GLTFRecorder(getExportRoot, Clip.m_RecordBlendShapes, Clip.m_RecordAnimationPointer);
recorder.AnimationName = Clip.m_AnimationName;
recorder.StartRecording(getTime);
}
else if (getTime > recorder.LastRecordedTime)
Expand All @@ -53,46 +54,34 @@ private static bool IsPlaying()
#if UNITY_EDITOR
return EditorApplication.isPlaying;
#else
return true;
return true;
#endif
}

public override void OnPlayableDestroy(Playable playable)
{
if (!IsPlaying())
{
return;
}
if (!IsPlaying()) return;

StopRecording(playable.GetTime());
}

public override void OnGraphStart(Playable playable)
{
if (!IsPlaying())
{
return;
}
if (!IsPlaying()) return;

BeginRecording(playable.GetTime(), Clip.GetExportRoot(playable.GetGraph()));
}

public override void OnGraphStop(Playable playable)
{
if (!IsPlaying())
{
return;
}
if (!IsPlaying()) return;

StopRecording(playable.GetTime());
}

public override void ProcessFrame(Playable playable, FrameData info, object playerData)
{
if (!IsPlaying())
{
return;
}
if (!IsPlaying()) return;

double time = playable.GetTime();
GLTFRecorderHelper.Add(() => OnFrameEnd(time, playable, info, playerData));
Expand All @@ -110,16 +99,9 @@ public override void OnBehaviourPause(Playable playable, FrameData info)

public void OnFrameEnd(double time, Playable playable, FrameData info, object playerData)
{
if (!playable.IsValid())
{
return;
}

var root = Clip.GetExportRoot(playable.GetGraph());
if (!root || m_isPaused)
{
return;
}
if (!playable.IsValid()) return;
var root = Clip.GetExportRoot(playable.GetGraph());
if (!root || m_isPaused) return;

ProcessRecording(time, root);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class GLTFRecorderClip : PlayableAsset, ITimelineClipAsset
{
public ExposedReference<Transform> m_exportRoot;
public string m_File = "Assets/Recording.glb";
public string m_AnimationName = "Recording";
public int m_CaptureFrameRate = 60;
public bool m_RecordBlendShapes = true;
public bool m_RecordAnimationPointer = false;
Expand Down

0 comments on commit 9513b30

Please sign in to comment.