Tuesday, February 2, 2010

Tutorial:Render Hairs (curve export) for "dummies" (of Blender)

Ok.. it's time I show the modellers I can also do some (little) modelling and not only programming :P ..

What you need:
1. Blender 2.49b
2. Makehuman latest nightly build

What we want:
Get the hairs exported and render it in blender.

This tutorial not only show how to render hairs from makehuman, but any nurb curves (because Blender internal render engine will not show nurb curves). And it's so easy.. it's all in only 2 steps! 

Step 1. Makehuman

Start Makehuman, then select libraries 

From the Libraries, choose say the ponytail hair...

Now the heads will make a cool looking rotation (who programmed that? kudos to you! :D ), and the ponytail goes in front.. but no its not yet selected ;) - It just rotated for you to become comfortable selecting it (I didnt programmed that)-- To get it REALLY selected you need to double-click the ponytail.. like so  *click-click*

And suddenly pop comes the hair on the model.. *pop*

Now go back to the Libraries and you notice several things:

  • The "test" hair is back in the center. Don't worry about that (I'll soon write a fix in the code.. just bear with this.. its a nightly build anyway :P)
  • There's a weird number on the top of the "Save" textbox. Don't mind that. It's for experimenting the different hair-ribbon width. You can play with it if you want. Giving a real number between 1.0 to 100.0  will change generated hair-ribbons on the base model (just give a new number say 3.0 then chose a hairstyle.. then *pop with width 3.0*) 
  • The radiobutton "Save to Wavefront .obj as Curves" should be selected for the tutorial..
  • Please leave the default filename "saved_hair.obj", otherwise it won't save properly. There is a bug I need to fix somewhere in the code.

Okidoks.. we can now... 

Tip: Did you know this cool feature (easter egg?)... Press Ctrl-F11 (at least in Windows).. and you will see that makehuman will own your entire screen :D

Step 2. Blender

Open Blender (make sure you have 2.49b or higher, because obj import with curve support works only after or equal 2.49b). Go to File-->Import-->Wavefront (.obj)

A window comes asking you where the obj file is. Now guess where your file was saved? Temporarily I coded it so it saves in model directory. In Windows its pretty easy landing yourself there. As illustrated below,  just choose the  thingy and then from there choose your  "My Documents" folder.

And Presto! you can now choose your makehuman folder

choose it then choose the "model" Folder now choose your "saved_hair.obj" file and then choose "Import a Wavefront OBJ"an "Import..." window pops. Quickly, without even thinking what all the buttons say press on the "Import" button.

Now look, we have the hairs imported as curves :)  .. That's pretty neat. But apparently (in Blender 2.49b) there is a bug somewhere (I think its the blender import_obj.py script). There are points that forgot to connect themselves to the curves (each is supposed to be an end-controlpoint of one of these curves)

Well as a temporary "fix" we just delete those points.. luckily we can select all with one click (I am not sure myself why :P).  Right click on only one of those points (not the curve).. and all of the hanging points will be selected. Like so... *right click* (checkout the mouse  at  the most bottom part where I selected only one point)Now in Object mode of Blender try to choose all of the hairs (don't choose anything else.. like camera or lights). Here is where you can show your "B" skills in Blender. Press "B" in the Object mode, then enbox the hairs and you got them chosen

Our goal is to Join the whole objects (Why? .. because we want to edit them ALL at once in Editmode.. and we wouldnt want to do each strand one by one). Thus (still in Object mode), press Ctrl-J. Now Blender is a bit weird. It didn't allow me to join several times when I tried selecting. It complained to me that the the objects aren't of the type that can be joined. So make sure only the hairs are selected. If you still have problems joining, try to select by parts i.e. use your "B"-skills twice.. select half of them then press "Shift+B" (so you wont lose the first selection while selecting more) and select the rest of the hair. 

So now things get joined and they look like so..

Step 3: Still Blender (oops.. there's a Step 3!)

If you are in Objectmode press "Tab" to go to Editmode (while the whole joined hairstrands remain selected)

choose the  ("Editing")  thingy and then choose "Bevel Depth" in "Curve and Surface"ok.. now what I am about to tell you isn't really supposed to be used by us in this way.. but it works great in our case and we are lazy geniuses/genii who want to exploit the functionality of Blender. Bevel is usually used for edge of surfaces and we have a nonexistent "curve" in the 3-dimensional affine plane over the real field... eh... Anyway, Blender allows us to "Bevel" on curves and the weird result is what we want. 

After choosing Beveldepth, give it a value of something like 0.05 (or lesser if you want thiner hairs rendered). Guess what happened? You might not have seen it clearly in Editmode, but in Objectmode the curves turned into some sort of mesh nurbs giving actually a real object to render! Just what we want :)

Press the  thingy (in Panels.. this thingy is called "Scene", you get it by pressing F10 too) . And you can then press on Render (using Brender internal render engine). Like so...

Now you get a cool hair render :) 

Ok. Thanks a lot for reading it up to here and sorry for the bad english and for being unecessarily funny (or silly) and very informal in this tutorial. I hope this was palatable to the commoners.

5 comments:

  1. This is weird. When I import images in blogspot directly from my PC, they dont get imported with their original size (Im not sure how big but they are smaller than 1200x780 dpi). Even choosing "Large" when importing does not solve this.

    ReplyDelete
  2. The double-click thing was new to me. I always wondered why hair didn't show up on my models.

    Apparently you must do hair last. If you resize a character, the hair will be left behind.

    A character imported as an obj will come in ten times too small compared to his hair. Change the Clamp scale setting from 10 to 100 in the obj import panel. A MHX character apparently comes in with the right size.

    Eventually we don't really want hair to be bevelled curves, but rather strand particles. Unfortunately, it does not seem to be possible to create editable particle hair from python in Blender 2.49b. It is possible to change various particle settings, but not to define guide curves. Hopefully this will be possible in 2.5.

    ReplyDelete
  3. I have a small problem. When you have 2 screens configured with Twinview, Ctrl+F11 maximizes the window to the entire virtual desktop, not the screen which is currently at.

    ReplyDelete
  4. Hehe.. terribly sorry, that was supposed to be secret information I leaked. But we will work on it as soon as some other important features are dealt with. For the meantime you will have to satisfy yourself with singleview 1 screen :( .. thank you for your understanding and sorry for the inconvenience

    ReplyDelete
  5. I've been playing with blender for months and have a problem coloring hair that import that is not mesh but nurbs? Why is this?

    ReplyDelete

© MHteam 2001-2010