1. home

Blender scripting: generating meshes from bones

Published & Updated

Introducing my first Blender script: a tool to generate low-poly meshes from armatures. The goal was to speed up the process of prototyping simple character rigs, and to learn more about Blender and Python. The results aren't aesthetically amazing, but the script provides a very quick starting point.

 

This task proved challenging as most resources out there on Blender are now outdated, and I've found the API to be a little obtuse. Of course, as I experiment more, I'm sure it'll make more sense with time and practice. Here's the code if you want to try it out yourself:

# This script creates a new mesh based off of an armature.
# To use, run the script while an armature is selected.
import bpy
import bmesh
from mathutils import Matrix,Vector
def makeMeshFromArmature():
armature = bpy.context.active_object
try: armature.data.bones
except NameError: return
except AttributeError: return
bones = armature.data.bones
# make new mesh:
mesh = bpy.data.meshes.new('Armature Mesh')
# make new object:
mesh_obj = bpy.data.objects.new("Mesh from Armature", mesh)
# place new object in current collection:
bpy.context.collection.objects.link(mesh_obj)
# make it the active object:
bpy.context.view_layer.objects.active = mesh_obj
# select it as well:
mesh_obj.select_set(True)
# loop through bones to make bmesh:
bm = bmesh.new()
for bone in armature.data.bones:
#matrix from object to bone:
m1 = bone.matrix_local
#matrix to scale the bone (non-proportionally):
m2 = Matrix.Diagonal(Vector((0.2,bone.length,0.2,1.0)))
# matrix to slide the cube to center of bone:
m3 = Matrix.Translation(Vector((0.0,bone.length/2,0.0)))
# create the cube in the mesh:
bmesh.ops.create_cube(bm, size=1.0, matrix=m1 @ m3 @ m2)
# copy bmesh data into mesh:
bm.to_mesh(mesh)
bm.free()
# deselect all:
bpy.ops.object.select_all(action='DESELECT')
makeMeshFromArmature()

Frame-rate independent interpolation for Unity

Published

Back in 2002, Robert Penner published his book, Robert Penner's Programming Macromedia Flash MX. The book was significant in that it unveiled a set of stand-alone "easing functions" for simple animation. You've probably seen these easing functions, they've been ported to every language and websites like easings.net are dedicated to them. These functions make it simple for programmers to apply various eases to tween-based animation. By "tween-based" I'm referring to keyframe animation: interpolation between two fixed points in time.

But what about animations that don't have a start time and an end time? Consider procedural animations that happen in a real-time environment, for example: "every frame ease a game object towards another game object". Those animations can't be keyframed; mathematically, we can't interpolate the in-between values (the 'tweens) if there is no definitive end to the animation.

Continue reading

Using Journey Maps in Level Design

Published

Students come to my Level Design class expecting to learn a game engine. Some expect the course to be about block-outs, others want it to be about gameplay programming, or the aesthetics of game design, or working with assets and content pipelines. These are all great topics, and it's true that there's a ton of technical ground to cover. And there's quite a bit of built-in program-level goals like game production, best practices, teamwork, communication, etc. After making room for all of these goals, there's sometimes little bandwidth left for teaching actual design, as in: How does a team create and deliver a specific experience?

For creating and communicating a vision for a level's design, we turn to tools like mood-boards, lore-writing, floorplans, and journey maps. Each of these tools provide ways for a team to establish and document their ideas, but journey maps are perhaps the most important. When done well, a journey map not only brings together various aspects of the design into a single document, but they are also intended to be testable, for both usability and desirability.

Continue reading

Old Visual Design Work

Published

I've been collecting screenshots of my visual design and UX work. Hopefully I'll have more time in the future to discuss individual pieces. In the mean time here's a collage I threw together showcasing a wide variety of my work.

Shaders 101: an Infographic

Published

Okay, I don't know if this is technically an infographic, but it's one of the first slides from my slideshow on shaders. It's a little simplistic, but it's a helpful starting point for beginners.

Older articles