November 15, 2017

Technology Sneak Peek: Python in Unreal Engine

By Ken Pimentel

At Autodesk University, we’re providing a brief glimpse of research we’re working on that will solve complicated problems with bringing CAD data into the Unreal Engine. It’s a major stepping stone (even if it’s just a glimpse) of where we’re going with Datasmith. 

Where we are today

The Datasmith workflow toolkit, currently in beta, makes moving data into Unreal Engine as frictionless as possible. Datasmith provides high-fidelity translation of common scene assets such as geometry, textures, materials, lights and cameras from popular DCC and CAD applications into Unreal Engine. As evidenced by the 8,000+ beta registrants and enthusiastic feedback from our beta users, we’ve already made great progress on delivering a workflow that saves days and weeks in preparing data for real-time use.

Where we need to go

To get to a truly frictionless workflow, we also have to address issues of automating and preparing data for real-time use. We can’t always expect data pushed through Datasmith to be “render perfect” or “optimized,” so we have to provide some means of addressing these kinds of issues in a non-destructive manner (meaning you can easily make changes to the upstream data without repeating work you’ve already done).

Traditional workflows to get data ready for the Unreal Engine rely on other tools to optimize the data.

The future revealed

This week at Autodesk University, for the first time we’re showing an early preview of using Python and Blueprints in Unreal Engine for the purpose of data preparation.
 Future workflows to get data ready will use Datasmith and Unreal Engine-based tools.

The demo provides a quick window into the possibilities when users have the option of working in Python and/or Epic’s Blueprint Visual Scripting to take advantage of new, sophisticated data preparation tools that process and optimize scene data. Data prep functions we’re exploring range from “find all parts smaller than 1 cubic centimeter and decimate them” to “find these objects and automatically repair them (fixing bad topology, gaps and overlaps).”

 In this example, the motorcycle is processed with a series of simple rules that create a more optimized version.

The example project we created for AU starts with a 3ds Max file, but it could have been any file format that we support natively with Datasmith. With over 20 supported formats (and more coming in), there’s a good chance we have the one you need. After importing the file, a series of common tasks are executed.

 A simple Python script loads the data, which could be from one of the 20+ formats Datasmith supports.

Often, you have detail in a model that is either invisible, or not relevant to the visual experience you’re creating. One method we support is the searching of metadata for specific instances and then you can remove them or optimize them. We’ll also offer a method of finding all objects not visible - which helps for internal details that aren’t pertinent and can be deleted. There will be many techniques for finding non-relevant assets and either simplifying or removing them.
 This simple Python script looks for certain names from the metadata and then deletes them.

One of the techniques for dealing with complex meshes is to create a simplified version of them. With Datasmith and Unreal Engine, you have a couple paths to evaluate. Since Datasmith supports importing BREP data from Catia, Creo, NX, SW, JT, Rhino, etc., you have the option of using tessellation and coarser parameters to get to simplified meshes. The Unreal Engine also has a quadric mesh optimizer to create LODs with. Either path will help you create more optimized versions of visible geometry to meet the performance goals of the experience.

 This Python script takes a complex seat mesh and uses the built-in Unreal Engine optimizer to construct a LOD.

Manipulating the scene organization is a common need for performance or just reorganizing the assets to be easier to work with. All real-time engines have limits on the number of objects they can process at real-time rates. For example, on an iPad, you might have a target of 1,000 objects and 1,000,000 polygons to get to 60fps for AR. On a powerful desktop, you might be able to do twice that for VR at 90fps. When many complex CAD files contain 5,000 or more objects, you’ll need to consider some method of organizing your data to limit the draw calls.

 This script takes many individual entities and combines them into a single entity.

Even though Datasmith automatically will convert materials from V-Ray, Corona, Mental Ray and others, it doesn’t mean that those materials are the ones you want. You might have your own library of optimized UE4 materials, or you could be coming from the CAD-world where materials are somewhat of an afterthought. In these cases, you want a method of finding and replacing existing materials with UE4-optimized materials. With our new Python tools, you can do this using a simple text file with a 1:1 relationship between the materials to find and the materials to replace them with.

 This script uses a search and replace strategy for materials based on a simple text file.

Datasmith will provide both Python and Blueprint interfaces so that users can pick and choose which scripting paradigm to work with. This means that Datasmith users will be able to create purpose-built, arbitrarily powerful geometric processing tools (and share them) using this new workflow. 

You can also use the Blueprint visual scripting interface to perform the same tasks using the exposed Python tools.

By moving the data processing and optimization into the Unreal Engine, means better support for automation and non-destructive workflows. Now, when changes to upstream data occurs (and this is always happening), the downstream assets can be reprocessed using scripts, instead of reworking them by hand.

The combination of frictionless data import and powerful data preparation tools unlocks the ability for Unreal Engine users to transform CAD assets into a vivid virtual experience with a minimum of effort. 

Ready to tap into the time-saving power of real-time design? Try the free Unreal Studio beta (which includs Datasmith) to accelerate your design workflows in Unreal Engine!

Stay tuned for more Technology Sneak Peeks to come, as we reveal other exciting developments with Unreal Engine!