I struggled through trying to figure out the details of getting a model from Blender to Panda. Here is what I worked out.
My setup
Blender 2.36
Ubuntu Linux 5.04
Python 2.4
Panda 1.0.5
DirectX8exporter236 I couldn’t get the default DirectX exporter to export textures. This newer version fixed that problem.
Create a Model
The Blender User guide has a chapter called Your first animation in 30 + 30 minutes which shows you how to model & animate Gus, the gingerbread man. Follow this, except:
don’t do the subdivision surfaces (they aren’t exported)
don’t do materials the way they suggest. Instead, you want to do a UV texture. See Unwrapping Suzanne in the User Guide.
The exporter doesn’t like it if you scale, rotate, or move the model in Object mode. You can check if you’ve done this by clearing any transformations (alt-g, alt-s, and alt-r). Instead, scale/rotate/move the vertices in Edit mode.
Export to .x
You need to export each animation to a separate .x file. I made three animations for Gus:
idle
walking
dancing
so I end up with three .x files
gus.x
gus_walk.x
gus_dance.x
For each one, you need to:
Select the animation in the Action editor
Bake it
Set the animation start & end frames (Buttons View -> Scene)
Export
This includes a copy of the mesh in every .x file. That is lame, but I’m not sure what to do about it. It still works, but I’m sure it isn’t very good for efficiency.
Convert to .egg
Blender convention is to name bones with .L and .R at the end, like Arm.L or Foot.R. Some features in Blender depend on these names (paste flipped pose, for example). Additionally, Blender has a habit of naming new objects things like cube.001 and cube.002. x2egg can’t handle . in names, so we have to strip them out.
Finally, Blender seems to have different ideas about which way is up, so we tell x2egg to rotate the model with -TR -90,0,0.
I wrote a python script to do this for me (it doesn’t strip “.001” because I can just rename the objects in Blender):
#!/usr/bin/env python
import sys
import os
import re
xfile = sys.argv[1]
eggfile = re.sub("\.x$", ".egg", xfile)
if xfile == eggfile: # safety check
print "Refusing to overwrite source file %s" % xfile
sys.exit(1)
# clean up some blender conventions that x2egg doesn't like
xdata = open(xfile).read()
xdata = re.sub ("\.L", "_L", xdata)
xdata = re.sub ("\.R", "_R", xdata)
fh = open(xfile, "w")
fh.write(xdata)
fh.close()
os.system("x2egg %s -o %s -TR -90,0,0 %s" %
(xfile, eggfile, " ".join(sys.argv[2:])))
View in pview
You should be able to look at the egg files with commands like “pview gus.egg” and “pview gus_walk.egg.”
Load into Panda
You can load the mesh and animations like this:
gus = Actor.Actor("gus", { "idle" : "gus",
"walk" : "gus_walk",
"dance" : "gus_dance" })