Search Unity

Import Export Cinemachine Cameras to Maya + After Effects + FBX. Bake Camera Keyframes?

Discussion in 'Cinemachine' started by josterday, Aug 15, 2018.

  1. josterday

    josterday

    Joined:
    Jan 22, 2018
    Posts:
    51
    We've looked everywhere for this workflow, but there seems to be a shortage of information.

    Problem:
    - Export Cinemachine camera(s) to Compositing software (After Effects)


    We need to pull the camera data from our Cinemachine timeline into our Compositing pipeline and can't find a reliable solution. There are FBX roundtrip walkthroughs, but none of them discuss how to export a working Cinemachine timeline into Maya / After Effects / C4D.

    As it stands, the only workaround is to use a linked prefab instance on a standard camera that is keyframed in either Maya or Unity. But, my assumption is that you wouldn't be able to use those keyframes within timeline, since that is conducting the animation track for the camera's parameters.

    Ideally, you would right click a CM camera and say "Export to FBX" and that would bake the camera's PTZ/PSR into keyframes for Maya to then export. We don't want to lose the flexibility of making realtime camera adjustments within Cinemachine, but we also need to composite these cinematics within our post pipeline.

    Thanks!

    Edit: Currently, Maya does not see any animation keyframes on the camera that is imported with FBX Exporter, so either there's an additional step needed in the plug-in or a different workflow with Cinemachine specifically.
     
  2. Mad_Banny

    Mad_Banny

    Joined:
    Jun 25, 2018
    Posts:
    4
  3. josterday

    josterday

    Joined:
    Jan 22, 2018
    Posts:
    51
    Does Alembic support Camera import/export from Timeline? Looking through, it seems to be specifically for Alembic files.
     
  4. josterday

    josterday

    Joined:
    Jan 22, 2018
    Posts:
    51
    Bump on this. Any method to export Cinemachine cameras for Compositing workflow?

    This is the last piece to us completely moving to a Unity pipeline.
     
  5. markvi

    markvi

    Joined:
    Oct 31, 2016
    Posts:
    118
    Hi, can you clarify if you want to export individual Cinemachine vcams, or just the resulting camera controlled by the Cinemachine brain?

    If it's the latter, the FBX exporter now supports cameras and animation. It's still in preview, but you can still install it with Package Manager as long as you don't mind editing the package.manifest by hand: #309
    There should be a demo video in that thread, too.

    We don't have any way to export individual Cinemachine vcams, although I suppose you could put a deactivated camera component onto every single vcam with a MonoBehaviour that sets its properties to be the same as the vcam. The exporter should then be able to export those cameras.
     
  6. josterday

    josterday

    Joined:
    Jan 22, 2018
    Posts:
    51
    Hi, thanks for the response. Thought I would jump back in for updates since I'm hearing this issue echoed from a lot of fellow 3D artists and compositors who (unfortunately) aren't touching Unity/Cinemachine.

    We want to export the resulting primary camera controlled by Cinemachine. This needs to be a keyframed camera via FBX. The issue seems to be confusion over whether the FBX Exporter Plugin supports "baking" the Cinemachine camera animation and how to actually properly export a camera (in general). We seem to receive mixed results from the FBX that Unity spits out and the walkthroughs that have been posted aren't clear enough.

    Edit: Just to specify -- Do we select the primary camera with the CM Brain and do "Export to FBX"? Or do we do the VCams? Anything specific for "Transfer Animation"? Export format?

    When importing into Maya, the camera appears, but contains no animation.
     
    Last edited: Oct 4, 2018
  7. josterday

    josterday

    Joined:
    Jan 22, 2018
    Posts:
    51
    Bump. Any guidance on FBX export and Cinemachine?
     
  8. josterday

    josterday

    Joined:
    Jan 22, 2018
    Posts:
    51
    Bump again with an update:

    We tried using the recorder's option - "Animation Clip":
    - Add Primary CAMERA (with CM Brain)
    - Setting Recorded Targets to EVERYTHING
    - Record Hierarchy ON

    This spits out an .anim of the camera with baked transforms. But now what? The thought was maybe creating an empty game object and parenting a new camera to it. Then apply the .anim to the empty (or the camera).

    This would create an actual object with the transform data to be potentially output as an FBX. But...no luck. Maya, C4D, nothing recognizes any keyframe info when we output an FBX of the camera. We get the Camera object, but no transforms.

    Any insight into HOW FBX EXPORTER WORKS is greatly appreciated.
     
  9. vkovec

    vkovec

    Unity Developer - FBX Exporter

    Joined:
    Aug 9, 2017
    Posts:
    257
    Hi @josterday,

    You have the right workflow:

    1. bake the animation of the CM Brain camera with the recorder
    2. add the baked animation to a new camera in the scene and export the camera*

    *Alternatively you can also export the recorded animation from the timeline:
    1. create a new camera
    2. add it to the timeline with the recorded animation
    3. select the recorded animation and from the top menu select GameObject > Export Selected Timeline Clip...

    Here is a video that also shows the workflow (from 0:19 - 0:47):


    As for not seeing the animation in Maya, would it be possible to send me the recorded anim file?

    Here are also a few things to try/check:
    1. check that the animation applied to the new camera can be played back in Unity (otherwise it will likely not be found by the exporter either)
    2. create the new camera at the scene root instead of parented under an empty object and apply the animation directly to the camera
    3. try unchecking "Record Hierarchy" in the recorder when recording
    4. when exporting the new camera, check that in the Export Options either "Animation Only" or "Model(s) + Animation" is selected under "Include".

    upload_2018-11-9_15-22-2.png

    Best,
    Viktoria
     
    Last edited: Nov 15, 2018
  10. josterday

    josterday

    Joined:
    Jan 22, 2018
    Posts:
    51
    Hi @vkovec ,

    We're finally on to something! It's possible "record hierarchy" was the culprit? I'm still seeing strange effects:

    - The camera only showing keyframes on 0-58, even though it has transform data through frame 60 in Unity.

    - If I have "remove start offset" CHECKED (on) under the animation clip in the Timeline, the camera will be off position. Still need to test whether this is consistent.

    - Are there any issues translating focal length or any other parameters from the Unity Camera?

    - I noticed if I have a 40mm camera in Unity, I must set the C4D camera (imported FBX) to the same focal length to match. AKA that data is not translated. Even so, exporting an AEC file out of C4D into After Effects is netting slightly different results from Unity/C4D/Maya.

    Thanks! This is a huge development for us.
     
    Last edited: Feb 1, 2019
  11. amorinImgSpc

    amorinImgSpc

    Joined:
    Jun 11, 2018
    Posts:
    41
    Hi! Happy you're seeing some progress.

    1. Have you checked if it's missing frames 59-60 or if the animation itself is offset by two frames?

    2. This is intended behavior if your Unity camera starts at a transform other than 0,0,0! It allows you to have animation recorded in world-space used elsewhere.

    3. We do support it! View point 4 for for a more in depth answer.

    4. Yes! Physical cameras all import/export pretty differently depending on what software you're using. I'm glad you're able to manually set it the focal length C4D for now - we'll log a card an investigate on our side. Do you think you'd be able to send us the FBX file of your camera?

    Hope I can help;

    Alexis
     
  12. ClementSchepens

    ClementSchepens

    Joined:
    May 27, 2020
    Posts:
    25
    Hi, I'm reviving this because I need to export all CinemachineShots from my timeline as individual fbx and by script.

    I'm trying something like that :
    Code (CSharp):
    1. foreach (TimelineClip shot in camTrack.GetClips())
    2. {
    3.       ModelExporter.ExportObject("Assets/testCam_" + shot.displayName + ".fbx", (CinemachineShot)shot.asset);
    4. }
    But I get this error:
    Nothing to Export
    UnityEditor.Formats.Fbx.Exporter.ModelExporter:ExportObject (string,UnityEngine.Object)
     
  13. vkovec

    vkovec

    Unity Developer - FBX Exporter

    Joined:
    Aug 9, 2017
    Posts:
    257
    Hi @ClementSchepens,

    The FBX exporter does not currently support exporting CinemachineShots directly.
    In order to export a CinemachineShot to FBX, it will need to be recorded using the FBX recorder. The GameObject to record will be the CinemachineBrain camera.

    If you wish to record the supported camera properties, you will also need to select "Camera" under "Recorded Components". See here for camera properties that can be exported.
    upload_2021-2-10_16-50-55.png

    For examples of recording from a script, see the Samples in the Unity Recorder package.
    upload_2021-2-10_16-38-15.png

    Some changes may also be required to the FBX exporter package.
    For example making the FbxRecorderSettings class public in com.unity.formats.fbx/Editor/Sources/Recorders/FbxRecorder.

    Here are the steps to be able modify the source code locally:

    1. In the Unity Project view, under "Packages", select the FBX Exporter.
    2. Right click and select "Show in Explorer" to find the downloaded package location.
    3. Copy the com.unity.formats.fbx folder to a new location
    4. In Unity remove the FBX exporter package from the Package Manager
    5. In the Package Manager use the "+" button in the top left corner to add the copied package from disk

    Best,
    Viktoria
     

    Attached Files:

  14. ClementSchepens

    ClementSchepens

    Joined:
    May 27, 2020
    Posts:
    25
    Hi, thanks for your answer. I've been fiddling with it a bit and I'd like to know if there's a way to record without having to start the play mode.
    The current way I choosed is to record my main camera through a recorder track and then add the .anim to a dummy camera to export it as .fbx. It seems that recording directly to a .fbx gives some unwanted offsets due to the (way too complex) hierarchy.
    Another thing I have an issue with is activate the recording. I can create the tack and recording clip. But when in play mode, the recording is not triggered. Do I have to call to PrepareRecording() and StartRecording() ? Also, it seems I'm not able to get the recorder clip form the TimelineClip. I thought it could do it with "timelineClip.asset as RecorderClip" but it is not working.

    Best,
    Clément
     
  15. vkovec

    vkovec

    Unity Developer - FBX Exporter

    Joined:
    Aug 9, 2017
    Posts:
    257
    Hi Clément,

    There isn't a way to record without entering playmode, the frames are recorded as they are played back in play mode.

    I'd like to know a little bit more about this, seems like there is an issue to resolve.
    Would it be possible to share some more information such as the hierarchy, the exported FBX with offsets, and the correct FBX? It can also be done from within Unity (from the top menu: Help > Report a Bug...).

    From the Recorder documentation, adding the track and RecorderClip, setting the properties, then entering playmode should be sufficient. Do you see any errors in the console?

    I did a quick test and "timelineClip.asset as RecorderClip" as well as "(RecorderClip)timelineClip.asset" seemed to work. Are you seeing any errors?

    Best,
    Viktoria
     
    Last edited: Feb 18, 2021
  16. ClementSchepens

    ClementSchepens

    Joined:
    May 27, 2020
    Posts:
    25
    Hi, thanks for your help and sorry for the delay.
    I made a button to create a RecorderTrack and the clips that correspond to Cinemachine clips. I managed to make it work for .anim exports but now I'm trying to make it work for .fbx.
    I modified the sources to make the FbxRecorderSettings class public and made a function to create the settings :

    Code (CSharp):
    1. private FbxRecorderSettings CreateRecorderSettings(string clipName)
    2.     {
    3.         var recorderSettings = ScriptableObject.CreateInstance("FbxRecorderSettings") as FbxRecorderSettings;
    4.  
    5.         recorderSettings.animationInputSettings.AddComponentToRecord(typeof(Camera));
    6.         recorderSettings.animationInputSettings.AddComponentToRecord(typeof(Transform));
    7.         recorderSettings.animationInputSettings.AddComponentToRecord(typeof(CinemachineBrain));
    8.         recorderSettings.animationInputSettings.AddComponentToRecord(typeof(HDAdditionalCameraData));
    9.  
    10.         recorderSettings.animationInputSettings.SimplyCurves = UnityEditor.Recorder.Input.AnimationInputSettings.CurveSimplificationOptions.Disabled;
    11.         recorderSettings.animationInputSettings.gameObject = Camera.main.gameObject;
    12.  
    13.         recorderSettings.TransferAnimationSource = Camera.main.transform;
    14.         var dummyCam = Instantiate(new GameObject("CameraCapture_" + name), Camera.main.transform);
    15.         recorderSettings.TransferAnimationDest = dummyCam.transform;
    16.         recorderSettings.OutputFile = "Assets/CamRecordings/"+transform.parent.parent.name+"/"+name+"/"+clipName;
    17.         recorderSettings.FileNameGenerator.ForceAssetsFolder = true;
    18.         //recordersSettings.Add(recorderSettings);
    19.         return recorderSettings;
    20.     }
    and I assign it to the clip in this way :
    Code (CSharp):
    1. foreach(var clip in camClips)
    2.         {
    3.             var c = track.CreateClip<RecorderClip>();
    4.             c.start = clip.start;
    5.             c.duration = clip.duration;
    6.             c.displayName = clip.displayName;
    7.            
    8.             var rec = c.asset as RecorderClip;
    9.             rec.settings = CreateRecorderSettings(clip.displayName);
    10.         }
    But when I enter playmode, the recorder clips are reset to default. This is quite annoying ;-)
     
  17. vkovec

    vkovec

    Unity Developer - FBX Exporter

    Joined:
    Aug 9, 2017
    Posts:
    257
    Hi @ClementSchepens,

    I think I was able to recreate the issue with the recorder clip being reset.

    After:
    Code (CSharp):
    1.  
    2.             var c = track.CreateClip<RecorderClip>();
    3.             c.start = clip.start;
    4.             c.duration = clip.duration;
    5.             c.displayName = clip.displayName;
    6.          
    7.             var rec = c.asset as RecorderClip;
    8.             rec.settings = CreateRecorderSettings(clip.displayName);
    9.  
    try adding this line:
    Code (CSharp):
    1.  
    2. AssetDatabase.AddObjectToAsset(rec.settings, rec);
    3.  
    Let me know if it fixes the issue for you.
     
  18. ClementSchepens

    ClementSchepens

    Joined:
    May 27, 2020
    Posts:
    25
    Hi, thanks for the fast reply. It fixed this issue!
    But the recording still doesn't work.

    I have this warning:
    No script asset for ExportSettings. Check that the definition is in a file of the same name.

    And this error:
    NullReferenceException: Object reference not set to an instance of an object
    UnityEditor.Formats.Fbx.Exporter.ModelExporter.ExportInstance (UnityEngine.GameObject unityGo, Autodesk.Fbx.FbxScene fbxScene, Autodesk.Fbx.FbxNode fbxNode) (at Packages/FBXExporterCustom/com.unity.formats.fbx@4.0.0-pre.1/Editor/FbxExporter.cs:1346)
    UnityEditor.Formats.Fbx.Exporter.ModelExporter.ExportComponents (Autodesk.Fbx.FbxScene fbxScene) (at Packages/FBXExporterCustom/com.unity.formats.fbx@4.0.0-pre.1/Editor/FbxExporter.cs:3259)
    UnityEditor.Formats.Fbx.Exporter.ModelExporter.ExportAll (System.Collections.Generic.IEnumerable`1[T] unityExportSet, System.Collections.Generic.Dictionary`2[TKey,TValue] exportData) (at Packages/FBXExporterCustom/com.unity.formats.fbx@4.0.0-pre.1/Editor/FbxExporter.cs:3596)
    UnityEditor.Formats.Fbx.Exporter.ModelExporter.ExportObjects (System.String filePath, UnityEngine.Object[] objects, UnityEditor.Formats.Fbx.Exporter.IExportOptions exportOptions, System.Collections.Generic.Dictionary`2[TKey,TValue] exportData) (at Packages/FBXExporterCustom/com.unity.formats.fbx@4.0.0-pre.1/Editor/FbxExporter.cs:4466)
    UnityEditor.Formats.Fbx.Exporter.FbxRecorder.EndRecording (UnityEditor.Recorder.RecordingSession session) (at Packages/FBXExporterCustom/com.unity.formats.fbx@4.0.0-pre.1/Editor/Sources/Recorders/FbxRecorder/FbxRecorder.cs:68)
    UnityEditor.Recorder.RecordingSession.EndRecording () (at Library/PackageCache/com.unity.recorder@2.5.4/Editor/Sources/RecordingSession.cs:136)
    UnityEditor.Recorder.Timeline.RecorderPlayableBehaviour:OnBehaviourPause(Playable, FrameData) (at Library/PackageCache/com.unity.recorder@2.5.4/Editor/Timeline/RecorderPlayableBehaviour.cs:78)

    It seems that the Recorder is trying to get some material.
    The camera I'm trying to export is parent of a few objetcs (that I don't need to export). Maybe it is a problem.
     
  19. vkovec

    vkovec

    Unity Developer - FBX Exporter

    Joined:
    Aug 9, 2017
    Posts:
    257
    I think the warning is because the file containing the ExportSettings class is not called ExportSettings.cs. Will log a bug for it.

    For the error, I will log a bug for this as well. Temporary fix will be adding a null check at FbxExporter.cs line ~1346:
    Code (csharp):
    1.  
    2. foreach (var mat in materials) {
    3.     if (mat == null){
    4.         continue;
    5.     }
    6.     if (MaterialMap.TryGetValue(mat.GetInstanceID(), out newMaterial))
    7.     {
    8.          fbxNode.AddMaterial(newMaterial);
    9.     }
    10.     ...
    11.  
    It is possible to disable recording the whole hierarchy by unchecking "Record Hierarchy" in the FBX recorder settings. However if you have "Export Geometry" checked I think the objects themselves will still be exported.
    I think "Export Geometry" could be unchecked as well in this case as you are recording the camera component.

    upload_2021-3-11_10-28-20.png
     
  20. ClementSchepens

    ClementSchepens

    Joined:
    May 27, 2020
    Posts:
    25
    The team is still testing but everything seems to be working for now.
    You've been a really great help! Thanks a lot!

    Best,
    Clément
     
    Last edited: Mar 12, 2021
    vkovec likes this.