Saturday, February 2, 2008

animation with bvh & obj - skin weights

This is part 2 of "A Match Made in Bl00dy H3ll."

I've touched on the interaction of obj and bvh formats before, but now I'm really starting to use it more and more. Not really by choice, mind you, but two of the worlds i'm spending a lot of time with are using it.

To recap, Second Life uses the bvh format for creating custom animations, and Transmutable's Tomorrow Space is using a combination of obj and bvh files for its avatars. Since I'm building their avatars, I'm getting to know the format quite well. :)

So yeah, one of the quirks of this has always been the fact that the mesh is in a file on its own and the skeleton is in the same file as the keyframes. This is woogy. That's a technical term...Woogy.

So a big question mark that popped into my brainhole was "But how does the client handle vertex to bone assignments, how do you bind skin? With second life you can just assume that it's in the binary somewhere, but if you're doing something on your own you have to come up with your own solution.

So here comes the SMAP file. This is a small textfile that Trevor came up with to define the vertex to bone assignments. It's not complicated at all really, what I'm doing is using maya to bind the mesh to the skeleton using rigid bind, then exporting the bound skin as an obj file. This has advantages because the process of binding skin assigns the mesh vertices to a series of Sets based on the names of the joints they're assigned to. In the export process, the sets are interpreted as groups within the obj itself. And there you go, a bunch of tidy little groups that are created when the mesh is drawn.

Small problem with that though, the vertices are all assigned numbers after they're imported into the client, so if you need to call the specific numbers of vertices and bind them to the skeleton you're going to have a rough time.

Aint no thang but a chicken wang.

You can do two things in Maya to pull that list. The best way is to use a mel command that lists the members of the sets. You'll need to listSets, then listSetMembers in a loopyloop, then just paste that output into a text file.

Another way is a little more hacky and not too tidy. You'll have to turn on the Edit Membership tool and select a joint. As you know, the edit membership tool is a visual way in Maya to assign vertices to the bones using just shift to add and ctrl to remove vertices from the list. The key to that is that when you select a bone with the tool enabled the appropriate vertices. Then you can just do a ls -sl; to get the list of selected points. I did a thing that selects each bone in order and spit out the list without having to worry about doing it manually.

Any questions?


Peter said...

Hey Doc,

I have a question! Why use .obj and .bvh files at all? I started looking at improving the avatars in Croquet about a year ago and decided to completely scrap the .obj/.bvh avatar work that we'd done previously at the U of MN. It just didn't make any sense to me. Sure I could have done something like Trevor did with the SMAP file (I even started down that path) but what's the point? There are other formats out there and the one that really stood out to me is from the Ogre 3D project. It has everything you could want for skinned character animations and has exporter plugins for all the major modeling packages. It even comes in two flavors: binary and XML. The XML version is great for getting started...human readable and easy to write a parser. Best of all everything is done in the tool (we used Maya) and the exporter takes care of the rest.

If you're interested in seeing the results, go to and check out the Croquelandia trailer. You can also find some older videos showing the .obj/.bvh stuff. Yuck. ;-)


drOffset said...

Hi Peter!
I delved into obj/bvh because of the freelance work i was doing, so it was out of necessity. It's kind of a hobby of mine to explore different platforms.

Haven't really looked into the Ogre 3D project, but if it supports all that I'll definitely take a look.

I'm interested in Croquet also! I had a look when I was first delving into online worlds, but it didn't stick for some some reason. Anyway, I'll have another look asap. :)

Sorry I didn't see your comment earlier, didn't know anyone even read this blog. :P