A breakdown of the process for creating 3D animations for research in computer graphics and physics-based simulation.
Made for CG beginners.
Include Python scripts and bash commands.
Tools: Python, Maya, Blender, RenderMan, Houdini, Bash Commands.
Jan 9, 2023
Since Dec 2018, I started working with Prof. Mridul Aanjaneya to create animation that demonstrate results in computer graphics research, mostly in particle-based simulation.
We started with Maya and RenderMan, and gradually expanded our tool kit to include Bash scripts, Python, Blender, and Houdini.
I started sharing the procedure and tools I used to create with an open-sourced GitHub repository since Summer 2021. However, it would be hard for you to find the information you need if you are new to 3D animation.
So in this blog, I want to share the breakdown of the general animation pipeline I used in the previous projects.
I hope this will be helpful for you to understand the process.
Generally, the process of creating animation for particle-based simulation research can be divided into the following 5 steps:
Create a 3D scene.
Import simulation data.
Polish the 3D scene.
Render the animation.
Generate the video.
Step 1 and 3 are the steps that involve creating 3D art using CG softwares, involving 3D modeling, texturing, lighting, and more. I suggest you to check out Blender if you are a CG beginner.
step 2 and 4 are the main steps that involve scripting, and would be our focus in this blog.
In the first step, we need to create a 3D scene that represent the environment of where the simulation takes place.
Usually, before we conduct any simulation, we have imaged which real-life or imaginary scenario it will be applied. So now it is the time for you to set it up.
It can be something complex, but can also be something as simple as a white backdrop or wooden table.
Figures from our paper rendered with this process.
An Efficient Geometric Multigrid Solver for Viscous Liquids - SCA 2019
Mridul Aanjaneya, Chengguizi Han, Ryan Goldade and Christopher Batty
There will be different simulations involving different types of objects, like rigid bodies, fluids, smoke, fire, etc. I'm using particle-based simulation as an example because it is what we have mainly worked on. Particle-based method is versatile and can simulate different types of objects and phenomena, like viscosity, coiling, and buckling.
Suppose we have a batch of particle-based simulation data ready, usually exported in plain text format (.txt), and now we want to import them into the scene.
We need to convert the data first so it's compatible with the scene, there are two ways depending on the needs:
Render as mesh.
Render as particles.
Here is a comparison for the 2 methods:
Mesh approach: use convert.py to convert TXT files into vertex-only OBJ files, import the vertex-only OBJ files into Houdini and convert them into meshes, export mesh OBJ files from Houdini, and import them into Blender or Maya.
Particle approach: use convert.py to convert TXT files into RIB files, render the RIB file sequence with RenderMan, from Terminal or your Command Line Interface.
💡 Side note: RIB is the file format that allows RenderMan to render from Terminal with command:
$ prman -progress <file-name>.rib
Here is a quick glance of the script I created to convert simulation data into OBJ or RIB format:
You can view the whole script here convert.py, and run the script with the command:
$ convert.py <directory> <rib or obj> <start frame> <end frame>
After running the script, we obtain a sequence of OBJ (vertex-only) or RIB files that describe the particles, however, the two approaches will have different level of information at this step.
Mesh approach: vertex-only OBJ file only include information of the particle position. We need to use Houdini to convert vertex-only file sequence into mesh sequence.
Particle approach: RIB file include information for the particle position, size of the particle sphere, as well as their shading materials. The particle RIB file sequence is ready to render with RenderMan along with the scene in RIB format, which is usually another standalone RIB file.
💡 To learn how to use Houdini to convert vertex-only OBJ file into mesh, please check out this post I created: Houdini Particles to Mesh.
Figures from our paper rendered with this process
A Novel Discretization and Numerical Solver for Non-Fourier Diffusion - SIGGRAPH Asia 2020
Tao Xue*, Haozhe Su*, Chengguizi Han, Chenfanfu Jiang and Mridul Aanjaneya (*Joint first authors)
Now you've created a 3D scene, import the simulation data into the scene, and you can start polishing the scene.
There are several components you can consider when polishing the scene:
Finding References
Detailed Modeling
Lighting
Shading and Texturing
Camera Setup
This is the part where you can be creative and detail-oriented. I will leave the exploration to you!
Now, I suppose you have your scene that is render-ready.
There are generally two ways to render a scene with the simulation data:
Render on CG software with built-in renderer.
Export the scene to RIB files and render with RenderMan from Terminal.
There are advantages and disadvantages for each approach.
If we choose to render with built-in renderer, it is very easy to start rendering and we do not need to consider the OS. However, we can only render on the current machine, the software GUI must be kept open, and the rendering will terminate if the software crashes.
If we choose to render with RIB files, we can distribute work seamlessly on different machines, and it is easy to control remotely via SSH, and there is no need to keep the software GUI open. However, we need to modify RIB files according to the OS and version of RenderMan, and it requires planning with multiple machines that may have different hardware thus different rendering speed, and we usually need to rely on the CG software's support to export the scene as a RIB file.
Here is a script - render.py - to render a sequence of RIB files if you select the second approach. Run it with the command:
$ render.py <data set> <file prefix> <start frame> <end frame>
After running the script, we obtain a batch of EXR image files.
💡 EXR or OpenEXR, is a file format used to store high-dynamic range (HDR) image that contains a greater range of brightness than traditional images. Rendering a scene into EXR format delivers a better results than rendering the scene into PNG format.
Figures from our paper rendered with this process.
A Unified Second-Order Accurate in Time MPM Formulation for Simulating Viscoelastic Liquids with Phase Change - SIGGRAPH 2021
Haozhe Su*, Tao Xue*, Chengguizi Han, Chenfanfu Jiang and Mridul Aanjaneya (*Joint first authors)
Now we have obtained a sequence of EXR image files, and it is time for us to generate the final video.
There might be different ways of obtaining the results, and in my workflow, I use bash commands to convert the images into video.
First, run the following command so that the current terminal window knows the environment variables:
$ source <path-to-mitsuba>/setpath.sh
Then, convert EXR files into PNG files with the Mistuba renderer 0.6 utilities:
$ mtsutil tonemap -t *.exr
💡 Normally, we can use $ magick to convert image formats. It is a command-line utility maintained by ImageMagick. However, it generates a much bigger PNG file compared to Mitsuba with a lower quality. So, we switched from ImageMagick to Mitsuba.
Now, we can convert the PNG file sequence (0001.png, 0002.png, etc) into a MP4 video, with a frame rate of 24:
$ ffmpeg -framerate 24 -i %04d.png -c:v libx264 -profile:v high -crf 20 -pix_fmt yuv420p output.mp4
With this command, we can obtain the result as output.mp4.
To summarize, we briefly discussed how we can create an animation given a data set of physics-based simulation data, with some Python scripts I created.
Create a 3D scene.
Using a CG software, e.g. Blender.
Import simulation data.
Convert TXT file data into OBJ file (mesh approach) or RIB file (particle approach) with convert.py.
Mesh approach: use Houdini to convert vertices into meshes.
Particle approach: use convert.py to finalize the particle positions and shading.
Polish the 3D scene.
Consider texturing, shading, lighting, and camera.
Export the environment setup of the 3D scene.
Render the animation.
Render the animation with CG software's built-in renderer.
Or, render the animation with render.py.
Generate the video.
Use bash scripts and Mitsuba renderer utilities.
Feel free to reach out to me if you have any comments or questions.
Happy rendering! 💐
Best,
Laurel Han
Created: Jan 9, 2023
Last modified: Oct 16, 2023