mgear-dev / mgear4

mGear v.4.x.x (python 3 ready) https://mgear4.readthedocs.io
MIT License
266 stars 94 forks source link

ueGear Bridge (Maya <==> Unreal) #147

Closed tpoveda closed 11 months ago

tpoveda commented 2 years ago
miquelcampos commented 1 year ago

image

tpoveda commented 1 year ago

Export Camera from Unreal Sequencer into FBX

The objective is simple, being able to export an Unreal Camera into an FBX, so we can import it again into other DCCs such us Maya.


This can be done manually by opening a Level Sequence into the Sequencer and then going into Actions -> Export...

This operation will export a FBX file that can be imported into Maya and will keep the animations in both the transform and the specific animated camera properties (such as the focal lenght).


Exporting Sequence Cameras using Python API

API Documentation: https://docs.unrealengine.com/5.1/en-US/PythonAPI/class/SequencerTools.html

Unreal Python API exposes a function called unreal.SequencerTools.export_level_sequence_fbx that allows to export specific sequence binding and tracks into an FBX file.

In the Unreal Engine Python API examples located here: C:\Program Files\Epic Games\UE_5.1\Engine\Plugins\MovieScene\SequencerScripting\Content\Python there are some examples about how to use Sequencer Python API within sequencer_fbx_examples.py file.

Within Unreal, you can execute the following code to export a Sequence into a FBX file:

import sequencer_fbx_examples
sequencer_fbx_examples.export_fbx("/Game/Assets/Levels/Showcase","/Game/Assets/Cinematics/shot0010_001", "/Game/Assets/Cinematics/SequenceMaster", "E:\\uegear\\FBX_Test.fbx")

In this example, the shot has a camera binding with some tracks for the camera:

If you try to import the generated FBX into Maya you will notice that the generated FBX contains a transform one for each one of the animated tracks. This information is not useful.


Exporting Sequence Cameras using C++

All the functionality used to export Cameras using the Sequencer UI (throug the Actions -> Export... option) can be found in the following file: C:\Program Files\Epic Games\UE_5.1\Engine\Source\Editor\Sequencer\Private\Sequencer.cpp

More specifically in the function called ExportFBX.

We tried to implement it in the following way:

Conclusion

For now, I would wait until Epic Games exposes this functionality into the Unreal Python API. Meanwhile, as a temporal workaround, I would include an option into Maya ueGear that can automatically import an FBX camera previsouly exported by the user manually.

SimonBenAnderson commented 1 year ago

From working with Sequencer before, I think that this data is available, but it gets nested quite heavily into the clip information.

You can access the Current Level Sequence by

unreal.LevelSequenceEditorBlueprintLibrary

From there you have to handle each clip and the timeline. This is where is can get a bit complicated with juggling clip data.

SimonBenAnderson commented 1 year ago

Did some testing regarding the FBX export.

Note: As the exported data is only the camera data, Maya does not know the star and end frame of the LevelSequence shot. This data would need to be exported as some sort of accompanying xml or json.

SimonBenAnderson commented 1 year ago

There are also 3 types of possible Camera Tracks

  1. SubSequence
  2. Level Sequence Instance
  3. Level Actor

Example image below, showing of animated Camera data in the level sequence. Screenshot 2023-09-08 at 1 57 05 PM

We will need to capture every camera and check which correlates to the imported/Exported Maya Camera, so we can update it correctly.

SimonBenAnderson commented 1 year ago

Using Unreal 5.2, Maya 2024 and FBX 2020 The following is a manual export of Asset and Camera, with animated transform and focal length.

Both seem to be matching: Screenshot 2023-09-08 at 2 11 35 PM left: Maya Viewport right: Unreal Viewport

SimonBenAnderson commented 1 year ago

If you try and export a Instance Camera from the Sequencer, and the timeline is not on or over a section of the Spawnable Camera Clip, in other words, no Camera has been spawned in the Level. Then exporting the camera will result in a Component Like export. where the imported FBX file in maya will generate multiple groups instead of a camera.

SimonBenAnderson commented 11 months ago

This looks to be completed by the following PRs mGear: https://github.com/mgear-dev/mgear4/pull/281 ueGear: https://github.com/mgear-dev/ueGear/pull/5