Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
namespace Unity.Formats.USD {
public class UsdRecorderBehaviour : PlayableBehaviour {

// Conversion to keyframes (60 frames per second) to work around QuickLook bug
const int kExportFrameRate = 60;
bool m_isPaused = false;
public UsdRecorderClip Clip;

Expand Down Expand Up @@ -67,9 +69,13 @@ public void BeginRecording(double currentTime, GameObject root) {
// m_usdScene.Stage.SetTimeCodesPerSecond(1);
//}

// TODO: How does one extract the time mode (frames or seconds) from the Timeline?
Clip.UsdScene.Stage.SetFramesPerSecond(30);
Clip.UsdScene.Stage.SetTimeCodesPerSecond(1);
// Regardless of the actual sampling rate (e.g. Timeline playback speed), we are converting
// the timecode from seconds to frames with a sampling rate of 60 FPS. This has the nice quality
// of adding additional numerical stability.
// In the event that the timeline is not configured for 60 FPS playback, we rely on USD's linear
// interpolation mode to up-sample to 60 FPS.
Clip.UsdScene.FrameRate = kExportFrameRate ;
Clip.UsdScene.Stage.SetInterpolationType(pxr.UsdInterpolationType.UsdInterpolationTypeLinear);

// For simplicity in this example, adding game objects while recording is not supported.
Clip.Context = new ExportContext();
Expand All @@ -78,7 +84,7 @@ public void BeginRecording(double currentTime, GameObject root) {
Clip.Context.activePolicy = Clip.m_activePolicy;
Clip.Context.exportMaterials = Clip.m_exportMaterials;

Clip.UsdScene.StartTime = currentTime;
Clip.UsdScene.StartTime = currentTime * kExportFrameRate ;

// Export the "default" frame, that is, all data which doesn't vary over time.
Clip.UsdScene.Time = null;
Expand All @@ -104,7 +110,7 @@ public void StopRecording(double currentTime) {
}

Clip.Context = new ExportContext();
Clip.UsdScene.EndTime = currentTime;
Clip.UsdScene.EndTime = currentTime * kExportFrameRate ;

// In a real exporter, additional error handling should be added here.
if (!string.IsNullOrEmpty(Clip.m_usdFile)) {
Expand All @@ -129,7 +135,7 @@ void ProcessRecording(double currentTime, GameObject root) {
Debug.LogError("Process: context.scene is null");
}

Clip.UsdScene.Time = currentTime;
Clip.UsdScene.Time = currentTime * kExportFrameRate ;
Clip.Context.exportMaterials = false;
SceneExporter.Export(root, Clip.Context, zeroRootTransform: false);
}
Expand Down Expand Up @@ -195,4 +201,4 @@ public void OnFrameEnd(Playable playable, FrameData info, object playerData) {
ProcessRecording(playable.GetTime(), Clip.GetExportRoot(playable.GetGraph()));
}
}
}
}
Loading