Exporting cloth animations required only a few changes to the ox3ich exporter.
=> Ox3ich exports blender meshes and animations (source, LGPL).
Since both qwagga (scene export) and ox3ich (mesh/animations export) are now available for download, I guess I’ll want to consolidate this soon with an online project manager. In the meantime… you can have a look at the notes below, outlining how ox3ich handles cloth animations.
Finding Cloth objects
myObject=bpy.data.objects["Dress"] // get the object to be exported
myObject.type == Modifier.Types.CLOTH // confirm this object has ‘cloth’ enabled
We could have an isCloth method, looking like this:
def isCloth(object):
for x in object.modifiers:
if x.type==Modifier.Types.ARMATURE:
return 1
return 0
Using Cloth Objects as equipment
A simple way to generate animations for equipment (see this article) consists in reusing the parent object’s Armature (with extra bones for equipment) and export the actual keyframes (the shape of the mesh as deformed by the armature). Mesh data is memory intensive. One advantage, however, is we don’t need to rewrite / adapt modifiers code.
Now, for equipment, we grab all actions and apply them to the actor’s armature. We’ll do the same for cloth objects. However, there is a difference
In the case of equipment the actor’s armature is on the object’s modifier stack and is really used to animate the object, not the actor.
In the case of cloth, we may not want to animate the cloth with the armature directly. Instead, we apply the armature (and the action) to the actor, which indirectly influences cloth dynamics.
So we need to retrieve the actor used to influence cloth dynamics. I’ll use the same naming convention I used for other equipment items, e.g. dress@player. Then we have:
def getArmatureForCloth(cloth):
influencingActor=bpy.data.objects[cloth.name.split('@')[-1]]
return getArmature(influencingActor)
This uses the naming convention to retrieve the actor. For basic animation export, ox3ich doesn’t need anything else (in code sample ‘object’ is the object using cloth modifier):
exportItemFile(object,path) # export basic mesh and material data
actions=getActions(object) # return actions for owner (uses naming convention)
armature=getArmatureForCloth(object) # return the owner’s armature
exportActionFiles(actions,armature,object,path) # export all actions in the usual way.
Restricting key frames for export
By default, the exporter will export mesh data for all action frames, so I’ll extend the actor naming convention to allow us to define a frame range; for example
“player.walk@30-50″ # walk cycle includes only frames 30 to 50 for export
The following function parses the frame range according to this convention
def getFrameRange(action)
range=[1,30000]
parts=action.name.split(‘@’)
if len(parts)==2:
rngString=parts.split(‘-’)
range[0]=int(rngString[0])
range[1]=int(rngString[1])
return range
Notes
This is enough to get started with exporting cloth animations. There are several shortcomings:
- The exporter does not bake cloth animations, this is done manually (so probably the cloth animation part only works if each file contains only one animation).
- The exporter doesn’t explicitly handle cyclic animations. With my sample walk cycle, it doesn’t look all that bad, but there has to be a discontinuity between the first and last frame. Minimally the last frame should be replaced by the first frame. For smoother results, two consecutive cycles should be blended together, and I’d like the exporter to do this as well.