Blender scripting for Flare animations
Clint here. I’ve been away from the day-to-day Flare engine project for a while, but I’m coming back with some things to share. Just figured out an update for the main Python script I use in Blender for Flare animations.
The current alpha-demo Flare animations use a keyframe for almost every single frame. And all of the animations are mashed into one Blender action. Of the 32 frames, the first 4 were standing around, the next 8 are running, etc.
I’ve been in pre-production for HD assets for everyone to use in Flare engine. I’m starting to use different Actions for each animation, which makes working on (and exporting) animations easier to work with — as intended.
# render all animations for the named armature # Clint Bellanger 2015 import bpy from math import radians angle = -45 axis = 2 # z-axis armature_name = "FemaleArm" # remember UI settings to restore at the end original_path = bpy.data.scenes.render.filepath original_frame_end = bpy.context.scene.frame_end # RenderPlatform is an Empty object located at the origin # and has the lights and cameras attached as children. platform = bpy.data.objects["RenderPlatform"] armature = bpy.data.objects[armature_name] # Render all animations for action in bpy.data.actions: # make this action the active one armature.animation_data.action = action frame_begin, frame_end = [int(x) for x in action.frame_range] bpy.context.scene.frame_end = frame_end # Render in all 8 facing directions for i in range(0,8): # rotate the render platform and all children temp_rot = platform.rotation_euler temp_rot[axis] = temp_rot[axis] - radians(angle) platform.rotation_euler = temp_rot; # set the filename action and direction prefix bpy.data.scenes.render.filepath = original_path + action.name + str(i) # render animation for this direction bpy.ops.render.render(animation=True) # restore UI settings bpy.data.scenes.render.filepath = original_path bpy.context.scene.frame_end = original_frame_end
I use this script in a Blender file that I call my render mannequin. It has a blank copy of the base hero body with a transparent masking material. All the game’s animations are already set as Actions. The lights and cameras are ready and attached to an invisible swiveling RenderPlatform at the origin.
To use the file to render a piece of armor, I would link the armor from the blender file where I created it. Then attach it to the mannequin’s armature. Running the script results in rendering every frame of animation, for every animation, for all 8 directions the character can face. The files are named like “[Action][Direction][Frame].png” e.g. Running40008.png.
I’ll explain more about how all this works soon. Still figuring it out myself. This creates a lot of images (256 of them at least) that need to be combined into a sprite sheet. That can be done in a simple batch/shell script and ImageMagick. And, that same script should copy the result right into my flare testing directory. Once I have all that clockwork correct, I’ll share all those files and include a tutorial.
The goal I’m working towards is setting up an asset workflow. I’ll be working on a piece of armor, and it’s close enough that I want to test it in the engine. Open up the mannequin file, append the new armor, and run the magic script. Then after a short rendering break it will be ready to wear and test in the Flare engine.