marek-simonik / record3d_unity_demo

iPhone X -> Unity VFX Graph demo (real-time Point Cloud streaming)
https://record3d.app
128 stars 19 forks source link

Any ways to set clip in slowmotion ? #10

Open PockPocket opened 1 year ago

PockPocket commented 1 year ago

Hey, I'm trying to set one of the Record3D clip from my scene in slow-motion via the timeline but the option is greyed out:

r3d-slow-motion_Debug

Do you have any alternative to set individual .r3d clips in slow-motion ? Thanks a bunch, Mathieu

marek-simonik commented 1 year ago

Hi Mathieu,

I'm not sure why the two options are grayed-out, but here is the place where loading of frames happens for Timeline-based animation and where you should implement the playback logic you want.

You can adjust the speed of the clip e.g. by introducing a speedUpFactor property like in the example below (you could define a similarly named speedUpFactor property also on Record3DPlayback, which you could access from within R3DVideoBehaviour by calling input.endLocation.speedUpFactor; the speed-up factor property could be manually specified in the scene inspector).

double speedUpFactor = 5.0;
int frameIdx = (int)Math.Round(speedupFactor * playableInput.GetTime() * input.endLocation.fps);

Or instead of using speedUpFactor, you could directly compute the current frame index based on where in the Clip is the animation playhead currently located; the speedup would then be defined by how much you stretch the Clip in the Timeline:

var clipDuration = playableInput.GetDuration(); // Duration of the clip in the Timeline
var currClipTime = playableInput.GetTime(); // The time at which the playhead is located (relative to the start of the Clip)
double percentageOfVideo = currClipTime / (clipDuration == 0.0 ? 1.0 : clipDuration);

int frameIdx = (int)Math.Round(percentageOfVideo * input.endLocation.numberOfFrames);