If you follow this tutorial correctly you will be able to create hair in Blender and have it exported as curves and finally as Makehuman hair within 15minutes! 5minutes!
You will need:
- Blender 2.49b (or lower? .. Blender 2.5xx or higher will probably not work)
- Makehuman nightly build
- This head template
- This python script
- Some creativity and patience!
- Open the head template I provided, the head template will look like this:
With the head itself placed in the second layer. This will make us separate the created hair into the first layer and easily select them for export without selecting the head.
- Create Hair using Blender Particles and the head template I provided (this will ensure you that the hair will fit makehuman base model once you have exported it for use in makehuman). Just make sure you have Segments to at least 20 when making the hair.
- You can use this video to learn how to create hair using Blender Particles
It is advised to use weight paint and select the head area where you really want the hair to grow. This is how weight paint looks like. See the tutorial video linked above):
You can then apply vertex (as seen in the video tutorial) by going to Particle Systems -> Extras -> Vertex group and click on the (really) small button where the mouse is pointing in the figure below
After applying vertex group, comb the hair and do your design as you please.
- After having your desired hair design
In blender Window-Type selection select the Text-Editor as shown in the figure below
- Now open the python file in a text-editor and copy and paste it in your blender text-editor window or just paste the code shown below:
import Blender from Blender import Scene, Curve, Object, Particle from random import randrange def exportAsCurves(file, guides, number): DEG_ORDER_U = 3 # use negative indices M = min(len(guides),number) for j in xrange(0,M): n = randrange(0,len(guides)) N = len(guides[n]) for i in xrange(0,N): file.write('v %.6f %.6f %.6f\n' % (guides[n][i], guides[n][i],\ guides[n][i])) #name = group.name+"_"+guide.name #file.write('g %s\n' % name) file.write('cstype bspline\n') # not ideal, hard coded file.write('deg %d\n' % DEG_ORDER_U) # not used for curves but most files have it still curve_ls = [-(i+1) for i in xrange(N)] file.write('curv 0.0 1.0 %s\n' % (' '.join( [str(i) for i in curve_ls] ))) # hair has no U and V values for the curve # 'parm' keyword tot_parm = (DEG_ORDER_U + 1) + N tot_parm_div = float(tot_parm-1) parm_ls = [(i/tot_parm_div) for i in xrange(tot_parm)] file.write('parm u %s\n' % ' '.join( [str(i) for i in parm_ls] )) file.write('end\n') scn= Scene.GetCurrent() obj = scn.objects.active parts = obj.getParticleSystems() hairs = parts.getLoc() file = open("C:\hair.obj", 'w') exportAsCurves(file,hairs,300) file.close()
- If you press Alt-P, the hairs are saved as hair.obj file in your C: drive. This is a wavefront obj format and can be imported by makehuman. Better save it in your makehuman data folder afterwards.
- Make a copy of long.hair and long.png with the same name you saved your obj file in the data folder of makehuman (e.g. hair.hair or hair.png if your filename was hair.obj).
- Here is the exported hair in makehuman
Note: If you want it in another directory or as another filename you will have to change line 35 of the code. Just remeber you cannot use long filenames or directories or names that have unicode non-ascii characters (sorry for the lack of tech-support, you will have to live with it as I have very little time to extend this). Also observe the number 300 in line 36, this number tells Blender to export 300 hair guides. If you want more hair guides to be exported for makehuman you need to increase this number.