CGI Python

3D Software Integration – Prompto

For demo videos, Prompto wanted the offline rendering power of Blender, to be able to process a scene created in Unreal.

While carrying over most of the data is quite easy, the materials are a big problem. There is no obvious way to package these up in a mutually understood filetype. Unlike the geometry, which we can store in a simple fbx or obj.

One thing to note, when working with multiple material IDs, I recommend using the obj filetype. I had some issues with duplicate material IDs being merged to the first match, messing up the index values. Obj merges duplicated material assignments as well, but it also merges the face groups allowing for automatic index matching. But this might be too in depth for this high level overview. Just a suggestion. It’s very hard to match material IDs with face groups programmatically, so be aware of this easy fix.

After some initial research I noticed Unreal is able to write out their materials as T3D files. This is basically a textual representation of the complete nodegraph, but looks quite chaotic at first.

I was able to access the parameter overrides and inheretance structure from each actor in the scene using the new Python API that recently came to UE4. This data was stored in json format and read back in in Blender.

With this json data and the T3D files, I took to Blender, and set up a recursive system to reconstruct the complex, production nodegraphs from scratch. Below you can see a small section of a bigger network, created and layed out completely by the script.

partial network in Unreal (sample data)
partial network in Blender (reconstructed from scratch)

However, not all Unreal nodes have obvious matches in Blender, so I had to get creative. To accomplish this, I used node groups, and built a small network to behave as a custom node that would match the behaviour of Unreal-specific nodes. Below you can see an example. The green node you see on the left of the image above is the result of the self-contained network below.

Custom node

Unreal also has the ability to create custom nodes. Like the example above, this comes down to being a nested graph. The main difference here was that I did not know how many, nor which nodes had to be generated.

To solve this, I generalized the recursive system I used for the main node tree, and treated this nested tree as a branch.

Nested branch of nodes

One other thing that I had to keep in mind was that these nested trees were not included in the T3D file I discussed above. I had to write some additional code to fetch any assets that were referenced by the materials and wrote them to disk as well.

Having this data pipeline allowed us to add Blender to our pipeline and use it as a gateway for many things including automated rendering and automted shapespark scene generation.

If you would like to know more about this project, please contact me and we can talk about it in more detail.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *