Today we’ll be using the Build modifier with Python. I’ll be using the 2.83 version of Blender.
Here’s the video version of this article:
The Build modifier is use to construct a mesh gradually, piece by piece. I’ll demonstrate it on the example of a UV sphere.
Here are the steps to go:
Table of Contents
Step 1 – Add the Build Modifier Manually
Let’s start by adding the Build modifier manually, without Python. So, delete the default cube, add a UV sphere, scale it (S 5) and add the Build modifier. This will make the sphere disappear. If you now hit the Play Animation button, the sphere will be built face after face in a specific order:
Step 2 – Change the Start Frame and Duration of the Effect
You can change the start frame and duration of the effect. Let’s make the building process be a bit slower and start at frame 20. You can set the values in the Modifiers tab. Set Start to 20 (A) and Length to 280 (B). Also change End in the Timeline to 300 (C):
Then go to frame 1 and play the animation again. Now it will take more time to build the mesh.
Step 3 – Randomize the Build Order
You can also randomize the order in which the faces are built. To do that just check Randomize in the Modifiers tab. Then go back to frame 1 and play again:
Step 4 – Deconstruct the Mesh
You can also deconstruct a mesh instead of building it. To do that check Reversed in the Modifiers tab. Go back to frame one and play. This time the mesh will be complete at the beginning and then the faces will disappear in a random order (assuming you didn’t uncheck Randomize):
Step 5 – Add the Build Modifier in Python Code
Now that you know what the Build modifier does, let’s see how to add it in Python code. First of all, delete the UV sphere and make sure the End frame of the Timeline is set to 300. Then go to the Scripting workspace and add a new script.
We’re going to create 30 UV spheres in 3 rows with 10 spheres in each. In middle row the spheres will be built in a predefined order, in the last row the spheres will be built in a random order and in the foremost row they will be deconstructed in a random order. The code is pretty straightforward. Just type it in (or copy and paste):
import bpy
# build in predefined order
for i in range(10):
# Create a UV sphere and scale it.
bpy.ops.mesh.primitive_uv_sphere_add(location=(10 * i, 10, 10))
bpy.ops.transform.resize(value=(5, 5, 5))
# Add the Build modifier.
bpy.ops.object.modifier_add(type='BUILD')
# Set the start frame and the total time of the build effect.
bpy.context.object.modifiers["Build"].frame_start = 10 * i
bpy.context.object.modifiers["Build"].frame_duration = 50
# build in random order
for i in range(10):
bpy.ops.mesh.primitive_uv_sphere_add(location=(10 * i, 20, 20))
bpy.ops.transform.resize(value=(5, 5, 5))
bpy.ops.object.modifier_add(type='BUILD')
bpy.context.object.modifiers["Build"].frame_start = 100 + 10 * i
bpy.context.object.modifiers["Build"].frame_duration = 50
# Randomize the order in which the faces are created.
bpy.context.object.modifiers["Build"].use_random_order = True
# deconstruct in random order
for i in range(10):
bpy.ops.mesh.primitive_uv_sphere_add(location=(10 * i, 0, 0))
bpy.ops.transform.resize(value=(5, 5, 5))
bpy.ops.object.modifier_add(type='BUILD')
bpy.context.object.modifiers["Build"].frame_start = 200 + 10 * i
bpy.context.object.modifiers["Build"].frame_duration = 50
bpy.context.object.modifiers["Build"].use_random_order = True
# Deconstruct the mesh instead of building it.
bpy.context.object.modifiers["Build"].use_reverse = True
Step 6 – Run the Script and Watch the Effect
Now run the script and go back to the Layout workspace. There you will see the effect better. Go to frame 1 if you’re not there and play the animation. Zoom out if necessary.