Automating 3Ds Max export to Unreal Datasmith using Python
Unreal has quite a handy plugin for 3Ds Max that is able to export to Unreal Datasmith.
Advantages of using Datasmith over FBX or Alembic:
- Geometry is exported as a hierarchy, rather than just a single actor. If you have 100 distinct components, you have each component as a single actor, rather than 100 material slots named “Element 0” to “Element 99”. This opens a door for further post-processing, such as automatically assigning materials based on actor name
- Animation is exported as Level Sequence.
Disadvantages:
- The exporter AFAIK does not support deformations in alembic cache. Only transformations are exported into a level sequence. This stands to reason since Geometry cache is still experimental in Unreal (as of 4.26.1).
- Some animations might not translate 1:1. We have experienced some “jaggedness” when exporting to Unreal. Be sure that the animation looks alright with “Realtime” turned on in the Max, before sending it in Unreal.
- 3Ds Max — from programmer's standpoint, Max has awful documentation about Python API and API itself is not great. 2020 version still comes with Python 2, but this should be fixed already with the 2021 version.
You can open the script editor in 3Ds Max by going through menu: “Scripting -> Script editor”. Go ahead and open “Script listener” too, so you can see interactive results. Evaluate a line by highlighting text in the script editor and hit “shift-enter”.
You can use the following command to run max in “headless” mode and quit max after the export was finished:
"D:\Program Files\Autodesk\3ds Max 2020\3dsmax.exe" -q -silent -mip -mxs "quitMAX() #nopromptfile.max" -u PythonHost "C:\Users\filip\Documents\3ds Max 2020\export\export_datasmith.py"
Sadly, there is no way to pass arguments from max to the python script. You can however create a file, run the script and then read the file in the script. You can also create a new text file, where you can write logs or results of your operation. The beauty is that you can do just about anything once you are in a python environment.
If you are interested in the source code of the Datasmith plugin for Max, you can find it in Unreal Engine repository, at path “Source/Programs/Enterprise/Datasmith”.