· QuickLab
Turning Blender into a game-art script with Python
How Word Sprout’s flower pots, mascot, 113 flower cards and 3D garden are made with Blender Python scripts: building characters from basic shapes, Freestyle outlines, and exporting meshes for Unity.
Most of the art in Word Sprout comes out of Blender: the six stages of a growing flower pot, Sprout the mascot with a seedling on its head, the 113 flower cards you earn from missions, and the 3D garden you can walk around. Almost none of it was made by hand in Blender’s UI, though. It’s all built by Python scripts and rendered with a single command.
Why scripts
The flower cards made the reason obvious. Model 99 flowers by hand (113 now, with seasonal cards) and changing something as small as the outline thickness means touching all 113. With a script, you change one number and run it again.
Having the source as text matters too. It’s hard to tell what changed in a .blend file, but a Python file shows up as a clean diff. The pot script still saves a .blend file when it finishes, so you can open the result in Blender if you need to.
One command
Blender can run in the background with no window and just execute a script. -b means background, -P means run this Python file, and anything after -- is read by the script itself.
# pot stages, mascot, water drop, app icon
Blender -b -P word_sprout/ArtSource/sprout_art.py
# every flower card, only some numbers, or only the seasonal cards
Blender -b -P word_sprout/ArtSource/flower_cards.py
Blender -b -P word_sprout/ArtSource/flower_cards.py -- 1 42 99
Blender -b -P word_sprout/ArtSource/flower_cards.py -- seasonBefore each image, the script starts from an empty scene with read_factory_settings(use_empty=True). Nothing from the previous image leaks in, so every run produces the same pictures.
A character from basic shapes
Sprout is made of nothing but spheres, cylinders, cones and curve tubes. The body is a slightly squashed sphere, each eye is a flat black sphere with a small white one on top for the sparkle, and the smile is a tube through nine points on a downward arc.
def mascot(z=0.0, s=1.0):
sphere((0, 0, z), (0.9*s, 0.8*s, 0.82*s), BODY) # body
for x in (-0.3, 0.3): # eyes and sparkles
sphere((x*s, -0.74*s, z+0.12*s), (0.11*s, 0.06*s, 0.15*s), EYE)
sphere(((x+0.04)*s, -0.8*s, z+0.18*s), (0.035*s, 0.02*s, 0.045*s), WHITE)
for x in (-0.52, 0.52): # cheeks
sphere((x*s, -0.66*s, z-0.1*s), (0.13*s, 0.04*s, 0.08*s), CHEEK)
# smile: a tube through nine points on a downward arc
pts = []
for i in range(9):
t = math.radians(200 + i * 140 / 8)
pts.append((0.17*s*math.cos(t), -0.79*s, z - 0.06*s + 0.12*s*math.sin(t)))
tube(pts, 0.028*s, EYE)All the colors are constants at the top of the file: terracotta for the pot, soil, three greens for leaves, pink for petals, and so on. To change a color, you change it there.
One gotcha: colors in Blender materials are in linear color space, so plugging in the sRGB values you’re used to makes everything look washed out. We write the constants in familiar sRGB and convert them to linear when building each material.
The cartoon look: Freestyle outlines
Basic shapes under plain lighting look like plastic toys. The single biggest step toward a hand-drawn feel was Freestyle outlines, drawn in dark brown on silhouettes and borders only.
scene.render.use_freestyle = True
scene.render.line_thickness_mode = "ABSOLUTE"
scene.render.line_thickness = 2.6
lineset = scene.view_layers[0].freestyle_settings.linesets[0]
lineset.select_silhouette = True
lineset.select_border = True
lineset.select_crease = False # skip inner crease lines
lineset.linestyle.color = srgb(LINE) # dark brownThe rest of the setup pushes in the same direction.
- The renderer is EEVEE. It’s fast, and plenty for pictures this simple.
- The view transform is Standard rather than Filmic, so colors come out exactly as defined.
- Every material emits a little of its own color, which keeps shaded sides from going muddy and preserves a bright, cartoon-like look.
- The camera is orthographic, with no perspective, and the background is transparent so each image renders as an RGBA PNG.
Swapping into the same frame
All six pot stages are rendered at the same size and position, so the app just swaps images and the pot appears to grow in place.
For the flower cards we built 16 templates, among them daisy, tulip, bell, rose, star, clover and orchid, and each card swaps in its own colors, petal count and decorations to make 99 cards. Every flower has Sprout’s face in the middle (eyes, cheeks, a smile) so they all look like one family. Rarer cards get sparkles, a glow and a crown, and the 14 seasonal cards wear props like a Santa hat, a witch hat, sunglasses or bunny ears. Card numbers and names follow the same order as the list in the game code, so any card can be re-rendered by number.
Exporting meshes for the 3D garden
Word Sprout also has a 3D view where you walk around your own garden with Sprout. The ground, fences, arch, fountain, bench, butterflies, bees and all 113 flowers come from Blender scripts too, but this time the scripts export meshes instead of PNGs.
These models use plain single-color materials with no textures, so a much simpler format than FBX does the job: a small binary file with a position, normal and color per vertex, followed by a list of triangles. The file starts with the four bytes WSG1 so the Unity side can check it’s reading the right format.
with open(path, "wb") as out:
out.write(b"WSG1")
out.write(struct.pack("<ii", len(vertices), len(triangles)))
for v in vertices: # position 3 + normal 3 (float) + color RGBA (byte)
out.write(struct.pack("<6f4B", *v))
out.write(struct.pack("<%di" % len(triangles), *triangles))Two conversions happen on the way out. Blender is Z-up and Unity is Y-up, so each vertex swaps y and z; that flips the handedness, so the triangle winding is reversed too (0, 1, 2 becomes 0, 2, 1). Skip that and the models render inside out. Material colors are also converted from Blender’s linear values back to sRGB for the vertex colors.
Since this has to run on phones, the garden versions are re-exported with spheres and cylinders cut down to 12 segments. The same flower definitions produce smooth shapes for the cards and light ones for the garden. On the Unity side, only planted flowers are built, there’s one material per color, and shadows are a single disc on the ground. Flowers rarely change, so GARDEN_ONLY=visit skips them and rebuilds just the garden props.
Keeping sources and outputs apart
Python scripts and .blend sources live in ArtSource/, and the PNGs and meshes the game reads live in Assets/Resources/. Game code only ever reads the outputs; the sources are only for regenerating them. The docstring at the top of each script says what it produces and how to run it again.
Blender isn’t the only tool in our asset rules: Krita is there for 2D concepts and textures, and PureRef for mood boards comparing references and colors. We don’t copy characters or art from other works, though. Word Sprout’s flowers use real flower names, but every shape and card design is our own.
At the other end, browser games like K-Claw Machine skip Blender entirely and build the shop and plush toys from basic shapes and textures drawn in code. We tend to pick whatever is lightest for each game. For how the Unity projects themselves are built in code, see Making mobile puzzle games in Unity.