Wednesday, April 21, 2010

The face is back

Two missing pieces of rig functionality have been brought back into the MHX importer for Blender 2.5: dynamic FK/IK switching and driven shape keys.

The options for choosing between FK and IK during import are gone. Instead, the amount of IK blending is controlled by the four sliders on top of the face panel; they control arm/leg IK on the left/right side, as in the left picture.

The facial shapekeys are driven by the remaining control bones in the face panel. You may notice that the bones at the center of the mouth are gone. This is becaues pydrivers, aka scripted drivers, are not yet implemented in Blender 2.5, so it is not possible to use several bones to control a single shape. But that was probably not a good idea anyway.

With this functionality restored, there is little reason to import mhx files into Blender 2.49 anymore.

Monday, April 19, 2010

MHX import as a Blender 2.5 add-on

Blender 2.5 has a new plugin system, which I believe has been developed by Brendon Murphy (Meta-Androcto). The MHX scripts have been modified to work with this system, and will hopefully and eventually be automatically included in future Blender releases.

1. Copy import_scene_mhx.py and import_hair_obj.py from Makehuman/importers/mhx/blender25x to Blender25/.blender/scripts/add-ons, where Makehuman and Blender25 are the directories where the corresponding programs are located. This step will hopefully be unnecessary in the future.

2. In Blender 2.5, open the File > User Preferences window and navigate to the Add-Ons tab.

3. Enable Import MakeHuman (.mhx). If you want to import hair, enable also Import MakeHuman hair (.obj).

4. MHX files can now be imported from the File > Import menu.

There is a third file in the Makehuman/importers/mhx/blender25x folder, which exports a Blender file to MHX. This has also been made into a plugin, but it is not really intended for public use.



Update: Meta-Androcto told me that the mhx importer should be automatically copied to the Blender distribution, but it does not seem to have happened. Until it does, you need to copy import_scene_mhx.py and import_hair_obj.py from Makehuman/importers/mhx/blender25x/ manually. There are three ways to do this.

1. Copy the files to Blender/.blender/scripts/addons/ (before starting Blender). Once there the add-ons can be enabled as described in the post.

2. Copy the files to Blender/.blender/scripts/io/. The import options are automatically enabled on startup.

3. Load the files into Blender's text editor and run the scripts from there. Once they have run once, the import alternatives are there.

Sunday, April 18, 2010

Modular rigging

After learning more about how the Gobo rig was implemented, I started to add some improvements to the classic rig. Eventually the two rigs started to share a sizable part of their codebase. Since I religiously dislike keeping redundant code, I decided to merge the two rigs, and change the import script so that one can choose between them during load-time instead.

One immediate benefit of this is file size. Keeping information about both rigs in the same file adds to the size of the mhx file, but only slightly. But we now only need to export a single mhx file, so the total file size and export time is almost halved (for Blender 2.5, there is still a separate 2.49 file). More significantly, it is now possible to pick rigs for different body parts independently.


The import interface now looks as in the picture, and as you see we can choose between the classic and Gobo rigs. Alternatively, we can choose between different rigs for separate body parts below, provided that the box "Use rig preset" is unchecked. You can build your own custom rig by combining different selections. The remaining checkboxes allow you to include various parts of the character.

The IK rig for fingers is a disaster. However, this is not really the rig's fault - Mancandy uses essentially the same rig, I think. The problem is that Blender's IK solvers work best if the mesh is modeled with knees, elbows and finger joints slightly bent. Remodeling MH's base mesh is of course not an option, but it is possible to bend the joints during import. The code is in the import script, but disabled due to a bug.

A long-standing problem has been that the display objects have been hanging around on layer 1, instead of being hidden on the invisible layer 20. This has now been fixed.

Tuesday, April 13, 2010

Developing in makehuman - 6 - The camera

When your plugin allows editing a certain part of the model, it's often good to focus the camera on that region. There are two camera's used in makehuman, accessible from the application class as modelCamera and guiCamera. The camera which we are interested in is the modelCamera. The application class itself is accessible in every GUI control as app.
A camera has the following properties:

Sunday, April 11, 2010

Some math for gravity effect of hairstrands

Many thanks to Manuel who installed watchmath in our Blogger site so I could type in some math about hairs :)

In hair_properties.py, hairstrands are first created with a fixed length along normal of the head. We may denote the length as $l$. When gravity is applied the strand should fall, the shape of this fall looks like the graph of (for simplicity we consider our curves in 2 dimensions) \[y = -cx^4\]

where $c$ is a positive constant dependent on the gravity factor. It has the formula (I got this after working out some equations on Young's elasticity formula, considering hairstrand an elastic material)
\[
c=\frac{{2^{2g/3}}}{2^6}
\]

But this is only half of the complexity. We need to keep the hairlength as $l$, whatever our gravity factor is. We basically need to calculate $x$ and $y$'s for a given length $l$ and a given gravity factor g. Getting arc-lengths of $y=-cx^4$ is a brachistrochrone problem. Using the equation of the arc-length we want to know $x_0$ such that 
\[
\int_0^{x_0} \sqrt{ 1 + 16c^2x^6}dx = l
\]

The above integral can be converted to an elliptic integral of the first kind. And the answer to our question is the "inverse" of the above integral, meaning we need Jacobi elliptic functions .. (more to come)

Saturday, April 10, 2010

hairs and gravity

Ok so this is what hairs look like after implementing gravity


I haven't implemented collision detection yet, but after collision detection hairs will flow over the body and the head instead of looking like rigid wires sticking out of the head. 

For more realistic gravity I will use Young's modulus elasticity equation. To make the hair and gravity work well (given a fixed hairstrand length) I am faced with a problem called the brachistrochrone problem. The results I have will need elliptic integrals and special functions like Jacobi's elliptic functions. The great thing about this is that it totally generalizes trigonometric functions and has more applications (in function theory they are denoted as sn, cn, etc.). I think Manuel wanted to publish some "math" results from makehuman, maybe this will give him the chance :) 

PS: unlike wordpress, blogger is really not a great place to show equation.. *sigh* why dont we use wordpress :P google isn't everything you know. 

Particle hair

Import of particle hair into Blender 2.5 is finally here!

Create a character in MH as usual, give her some hair, and go to the export menu. Select ".mhx" from the Body menu and ".obj as curves" from the Hair section. The latter is very important. Now some mhx files are created in your makehuman exports folder, together with an obj file with the hair info. Since I created my character by turning the dwarf-giant slider to the extreme left, I call her dwarf, and the hair file is then called hair_dwarf.obj. And don't close MakeHuman quite yet.

There is a new import script in the importers/mhx/blender25x folder: import_hair_obj.py. Copy it to your Blender scripts/io folder, or load and execute it in the internal text editor. In the files/import menu there is now a new option: "MakeHuman hair (.obj)".
1. First import one of the mhx files, say dwarf-gobo-25.mhx.
2. Select the imported character in the viewport, to indicate that she will receive hair. This is easy to forget.
3. Import the corresponding hair file.
And now the character has hair.


One advantage of storing hair in separate obj files is that you can easily switch hairstyle in Blender. Back in MakeHuman (you didn't close it, right), we can now choose a different hairstyle and export it. I prefer to set the Body switch to obj, and to change the name of the character to reflect the hairdo: dwarf-curly, dwarf-ponytail, dwarf-long (better than test). In Blender, delete the current hair in the particle context, and import a new one using the procedure above.

Rendering has a tendency to crash Blender, but sometimes it does not. We evidently have some problems with eyebrows and eyelashes, but that is a different story.

Update: The import script now automatically connects the hair to the mesh. The procedure for making the connection manually is hence unnecessary and has been removed from the post.

The ponytail hairstyle has some problems; the tail itself does not move with the head.

Update:
1. The hair still does not seem to be edited after importation. To fix this, toggle into particle mode, select the mesh, and toggle back into object mode.

2. Hair can now also be applied to meshes that were imported as an obj file. Just make sure that -X90 is checked and that Group is unchecked before you import the mesh.

3. The locations of the strands are given in global coordinates. Therefore the character should not be moved before her hair is connected to the mesh.

4. A hair file can be imported onto any mesh, but there are problems if the skull is not were it should be. The characters below both use the same hairstyle, which was created for the taller one.


Update: Manuel noticed that the hairs were jagged. The behavior seems to improve if B-spline interpolation is turned off, so I did so.

Monday, April 5, 2010

Sunday, April 4, 2010

Developing in makehuman - 5 - Meshes

When writing exporters, subdivision or polygon reducing algorithms it can be useful to know how the mesh is stored in Python (the C side has a different compact but less convenient representation).
© MHteam 2001-2010