Batch Characterize Mocap Files in Motion Builder

Does anyone know have any suggestions on how to batch characterize motion capture files in motion builder? I have all the naming conventions set and exported in FBX format from blade but looking to characterize the skeleton that blade creates. Thanks for any advice!

Glenn

Of course, you’re going to start with a character object. As I’m sure you know, you’d make one like so:

character = FBCharacter('FRANK:Character')

To characterize, you need to assign a bunch of models to different HumanIK nodes in the character definition, then enable characterization in order for MotionBuilder to work its magic. In the API, all of these mapping fields are implemented as properties of the character (object list properties, to be specific).

If a node is called LeftForeArm in the UI, the property name is LeftForeArmLink. So to assign a model, you’d do something like this:

model = FBFindModelByLabelName('FRANK:jt_ForeArm_L_01')
character.PropertyList.Find('LeftForeArmLink').append(model)

To get a definitive list of these node names, you can check the property list for a character:

for prop in character.PropertyList:
    if prop.Name.endswith('Link'):
        print prop.Name

Once all of these mappings are set up, you can call SetCharacterizeOn to initialize characterization. It will return a boolean representing whether it succeeded, and if it failed, a user-friendly message will be accessible via GetCharacterizeError:

characterizeSucceeded = character.SetCharacterizeOn(True)
if not characterizeSucceeded:
    print character.GetCharacterizeError()

That’s how you actually perform the characterization. In order to batch this process based on predetermined, external data, I’d recommend storing the mapping between node names and model names in an associative data structure. It could be an XML or JSON file that you can parse into a dictionary, or just a hardcoded python dictionary in a script file somewhere. With that, and a reference to the character’s skeleton model (to avoid messiness with multiple characters and namespaces), you’d have everything you’d need to perform the characterization according to your standard mapping. As an extension to that, or as part of a larger script, or wherever, you could also set standard character settings in much the same way.

To give you a starting point, here’s a quick script defining a function that takes a character, the root joint of its skeleton, and a dictionary of node-name-to-joint-name mappings and attempts to perform the characterization.

http://pastebin.com/vECmrANx
(For posterity: http://awforsythe.com/files/CharacterizeFromDictionary.py)

It could be used like this:

FRANK_MAPPINGS = {
	'Reference': 'jt_Root01_C',
	'Hips': 'jt_Hips01_C',
	# ...
}
character = FBCharacter('FRANK:Character')
rootModel = FBFindModelByLabelName('FRANK:jt_Root01_C')

Characterize(character, rootModel, FRANK_MAPPINGS)

You’d want actual production code to be a little smarter than this (for example, handling cases of invalid node or joint names instead of simply failing), but I hope this illustrates the concepts. If you have questions, ask away.