Tuesday, November 10, 2009

Blender export with the MHX format

MakeHuman is a great program, but it does not exist in isolation. After designing your character in MakeHuman, you probably want to export it to some other 3D package. I have been working on an exporter specifically designed for Blender, because that is what I know and have access to (ok, I did play around a little with 3ds max 4.2 a long time ago, but that is history by now).


MakeHuman has of course already exporters to the standard OBJ and BVH formats, but they leave a lot to be desired. For one thing, the OBJ mesh and the BVH armature do not end up at the same place, at least not in Blender. Moreover, a barebone rig is not so useful for the animator – she typically wants more control (like arm and leg IK), a skinned mesh, and shape keys. The MHX (MakeHuman eXchange) format attempts to address these issues. I will discuss some specific problems with rigging and MHX export in a series of posts, and how things are done (or in some cases, why I have failed to implement them). However, in this initial post I will describe how to use MHX to get a rigged character from MakeHuman into Blender.

Important caveats: I have tried this with the old mesh. Since the new mesh is just around the corner (touch wood), this version has not yet been committed to the trunk. Also, I use Blender 2.49b. Trying to import mhx files into Blender 2.49a and before will probably be problematic, due to some bug in the treatment of driven bones. And the code will not work in 2.50, which is quite different from a Python point of view.

On the MakeHuman side things appear to be the same as always: create the character and press the export button. However, the makehuman/exports directory contains a new file with extension mhx, in addition to the usual obj and bvh files. It is this file that we will import into Blender.

First we need to do some preparation. In the makehuman/utils/mhx directory there is a file called ”mhx_import.py”, which you need to copy into your Blender scripts directory. When Blender starts up, there is a new entry in the File > Imports menu which says Makehuman (.mhx).

It may happen that you don’t have privileges to copy files to the Blender scripts directory; this happens on my Ubuntu box at home. If so, just open the mhx_import.py script in a text window in Blender and execute it fr
om there. Either way, you should now be prompted with a blue screen. Here you can select a number of options:


1. Should arms, legs and fingers be controlled by forward (FK) or inverse (IK) kinematics?


2. Should shapekeys be loaded? This takes some time and the blend file becomes big, but it is worth it.


3. Should the imported character replace the whole scene? It is best to hit Ctrl-X and import into a pristine blend file.

4. Do we want display objects for bones?


5. Select the directory where the import script should look for textures.


After these selections are made, we press the ”Load MHX file” button, and select the mhx file in the MakeHuman exports directory with a file browser.

After a number of seconds, you should see something like the image to the left; the character is loaded into Blender, with a panel on top of him. We are now ready to start posing. For some reason, the control bones do not show up on my system until some part of the armature, e.g. the panel over the character’s head, has been selected. The panel which controls the facial shapes more or less follows what Jason Osipa, in his famous book ”Stop staring”, calls the simple setup.


I like to move the morph panel into a separate window, which is set in wireframe mode (z-key).

And here is the result of five minutes worth of posing.

13 comments:

  1. I have started following this blog lately and appreciate the work being done here very much...

    ReplyDelete
  2. Where can I get Blender script to import MHX files? Thanks.

    ReplyDelete
  3. Good stuff and a great idea! I'm looking forward to seeing how this develops!

    ReplyDelete
  4. The mhx stuff can be downloaded from http://rapidshare.com/files/305381132/mhx-v03.zip .

    I have not committed it to the trunk yet, because vertex groups and shape keys will break when the new mesh becomes available, hopefully very soon.

    ReplyDelete
  5. Better place here ;-)
    http://www.makehuman.org/download/mhx-v03.zip

    ReplyDelete
  6. Very thank you for this great contribution has helped my a lot.

    Muchas gracias por todo este gran aporte me ha servido mucho.

    ReplyDelete
  7. Thanks Thomas, is a very useful tool!

    ReplyDelete
  8. Hey guys, im following this project since 2 years now and am very impressed about the progress...

    ReplyDelete
  9. Thanks for this great tool! I've been using MH for a few days now. Great time saver for Blender users.

    ReplyDelete
  10. Does this work with the mesh in 1.0 Alpha v4? Or is there a new version of the importer? If so where do we get it?

    ReplyDelete
  11. I get errors when running import script...

    Compiled with Python version 2.6.1.
    'import site' failed; use -v for traceback
    Checking for installed Python... No installed Python found.
    Only built-in modules are available. Some scripts may not run.
    Continuing happily.
    Traceback (most recent call last):
    File "", line 1, in
    File "C:\Program Files\Blender\.blender\scripts\mhx_import.py", line 40, in
    import os
    ImportError: No module named os
    Traceback (most recent call last):
    File "", line 1, in
    File "C:\Program Files\Blender\.blender\scripts\mhx_import.py", line 40, in
    import os
    ImportError: No module named os

    ReplyDelete
  12. Also in above...where it says File "", should be File "", also where is says line XX in, should be line XX in .

    For some reason those items did not paste in.

    ReplyDelete
  13. I have figured out that I had wrong verion of Python installed. Sorry for cluttering up the blog.

    ReplyDelete

© MHteam 2001-2010