CGI Python

3D Preview Generation – Prompto

For my second assignment at Prompto, I was tasked to develop an automatic thumbnail generator. The idea is to be able to see what a 3D scene / object looks like, without having to manually open the file and look around.

The script will open the file for us, ahead of time, and analyse whatever is inside. It can do so on any given 3D filetype (fbx, dae, blend, obj, abc, etc). You can also specify one or more folders, out of which it will extract all valid files and analyse them in batch. This whole process can run fully autonomous and unsupervised.

After opening / importing the file, 4 camera’s are generated based on the dimensions of the content. The largest side on the xy plane will be used to create a square around the object. It will then be shifted, in order to get a slight offset before generating the cameras. This will make sure the cameras’ center rays hit different sections of the object, enabling us to get a greater amount of difference from all 4 views.

When all cameras are in place, the script will have to choose one to generate the image from. This is done by calculating the amount of detail visible to each one.

I am able to do so by calculating the dot product between the look direction of the camera and the normal of each face (plane) of the content. When the dot product is below 0, the 2 vectors point towards each other.

2D representation, note that all vectors were normalized

This calculation is followed by a ray, cast from the currently checked plane’s center, pointing in the direction of the camera (with a length of the distance between the origin point and the camera). If this ray does not hit any other piece of geometry, it is clearly visible to the currently checked camera.

The camera with the most visible planes’ centers will be chosen to proceed with.
The rest will be cleaned up.

The last step before generating the image is making sure the viewport looks aesthetically pleasing. This is done by some simple stepts that have a large impact. Including:

  • Generating a ground plane
  • Upping the anti-aliasing samples
  • Generating some lights and shadows

Some more tiny improvements were made to the environment to get the most out of our scene.

The preview image is generated using OpenGL. This is GPU accelerated and thus goes rather quickly. This image can now be used to present to a user in a custom asset management tool, in order to give him or her a better understanding of what asset they are about to bring into their digital environment. But of course there are many other use cases for a preview image. The output of the script is the image below.

You can read more about Prompto here.

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 *