marek-simonik / record3d_unity_demo

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

Any way's to clip a .r3d clip inside Unity? #11

Open PockPocket opened 10 months ago

PockPocket commented 10 months ago

Hi Marek,

I have a 4.0gb .r3d file that I'd like to cut in a bunch of smaller segments of 1 to 5 seconds - Do you know if there's any way to do so directly inside Unity or through the clip script ? When I try to edit via timeline and cut a clip it always makes the new segments starts back at the beginning of the original clip.

Any input would be truly appreciated.

Thanks, Mathieu

marek-simonik commented 10 months ago

Hi Mathieu,

please make these two changes:

  1. Replace public ClipCaps clipCaps => ClipCaps.Blending; by public ClipCaps clipCaps => ClipCaps.All; in https://github.com/marek-simonik/record3d_offline_unity_demo/blob/03292f3bfc2c6391cec27bf1c440bf670bd8c569/Assets/Scripts/R3DTimeline/R3DVideoClip.cs#L17
  2. Replace the contents of the file https://github.com/marek-simonik/record3d_offline_unity_demo/blob/master/Assets/Scripts/R3DTimeline/R3DVideoBehaviour.cs by the snippet below:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.VFX;

[Serializable]
public class R3DVideoBehaviour : PlayableBehaviour
{
    public Record3DPlayback endLocation;

    public override void OnGraphStart(Playable playable)
    {
        base.OnGraphStart(playable);
    }

    public override void ProcessFrame(Playable playable, FrameData info, object playerData)
    {
        var trackBinding = playerData as Record3DPlayback;
        if (trackBinding == null)
            return;

        int inputCount = playable.GetInputCount();

        for (int i = 0; i < inputCount; i++)
        {
            var playableInput = (ScriptPlayable<R3DVideoBehaviour>)playable.GetInput(i);
            R3DVideoBehaviour input = playableInput.GetBehaviour();
            bool isClipActive = playable.GetInputWeight(i) > 0.0;

            if (input == null || input.endLocation == null || !isClipActive)
                continue;

            var currClipTime = playableInput.GetTime();
            var clipFPS = input.endLocation.fps;
            int frameIdx = (int)Math.Round(currClipTime * clipFPS);

            input.endLocation.LoadFrame(frameIdx);

            break;
        }
    }
}

With the changes above, it should be possible to split and trim a single continuous R3DVideoClip (contained inside a R3DVideoTrack in the Timeline) into multiple R3DVideoClips in the same R3DVideoTrack. You can even duplicate the same clip segment (e.g. a 0.3s to 0.7s segment of a video) and put it at different parts of the R3DVideoTrack in the Timeline.

However, note that you should always use just and only one R3DVideoTrack per video object in the scene (i.e. you can create multiple R3DVideoTrack tracks in the Timeline, but a particular 3D video object from the scene should be assigned to just one track in the timeline).

See the attached screenshot for a better understanding.

Let me know if this helped to solve the issue.

Thanks, Marek

r3d-unity-timeline

PockPocket commented 10 months ago

Awesome! This brings so much more editing control. Thanks a lot Marek - coming in clutch as alway's! Mathieu