Grouping Hairs to Render in Makehuman

Introduction:
When we load hairs in makehuman, they are nothing other than loading Wavefront .obj curve format. These .obj hairs are stored under ./data/hairs directory of your makehuman directory. The content of the .obj files are only the hair “guides”. The hair guides are around 200-300 strands of hair. When rendering in makehuman, the rest of the hair (btw. around 10,000 in a human’s head) are interpolated by an internal algorithm in makehuman. The number of hair interpolated are called the children of the guides. The number of children is adjustable under makehuman’s rendering settings. There are two types of algorithm involved for makehuman hair interpolator (based on Nvidia reasearch papers). One of them is the clump interpolator, which roughly just interpolates a strand to more strands by surrounding it with more hair strands (user adjusts the radius of the clump). The other interpolator which is more realistic is the multistrand interpolator. The focus of this blog is the multistrand interpolator. This interpolator tries to extract the guide-groups of the hair .obj file and then interpolate more hair-strands between the guide groups. In this tutorial we show how to group the hair guides and save them for use in makehuman. The grouping of the hair has a significant influence on how the hair will be rendered in makehuman.

You will need:

  1. Blender 2.49b
  2. A hair .obj file designed for makehuman (they are just .obj curves)
  3. This head-template head template
  4. This python script

The steps are:

  1. Open the head template in Blender
  2. Import desired hair (.obj format) (to see how check my previous blog)
  3. Now open the python file in a text-editor and copy and paste it in your blender text-editor window

    Loaded Python Script

  4. Select the hair strands you want in a group (you can select more than two)

    chosen hair strands to group

  5. Group the selected hair strands by pressing Ctrl-G

    Grouping the strands

    Note that you do not need to group all the hair strands to be able to render it in makehuman. If makehuman finds a hair strand that is not grouped then it does not use the multi-strand interpolator on it (this strand is however still rendered).

  6. Keep on making more groups until you are satisfied with the guide groupings and the number of groups you want to make
  7. Now click your mouse in the text-editor of your blender and change line 32 to the appropriate (absolute) path and filename you want the obj to be saved. The script does not support too long filenames or unicode filenames. For windows users, make sure that you use slash instead of backslash when writing the path. For instance, if you want the filename to be “hair1.obj” and if you want it saved in “C:\temp”. I won’t provide support for unicode or long filenames, so please put up with this. You change line 32 from

    file = open("C:/temp/temp.obj", 'w') 

    to

    file = open("C:/temp/hair1.obj", 'w') 
  8. Execute the code by pressing Alt-P, make sure that your active window is Blender’s text-editor window (click your mouse in the window before pressing Alt-P).

That’s all for now. Soon I will post a render using this hairstyle. This hairstyle was contributed by workingprogress of the makehuman forum.

Posted in 3D Modelling | 1 Comment

5 minutes tutorial : From Blender Hair Particles to Makehuman Hair

Goal:

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:

  1. Blender 2.49b (or lower? .. Blender 2.5xx or higher will probably not work)
  2. Makehuman nightly build
  3. This head template
  4. This python script
  5. Some creativity and patience!

Steps:

  1. Open the head template I provided, the head template will look like this:

    head template

    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.

  2. 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):

    growing hair on weight paint

    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

    choosing vertex groups

    After applying vertex group, comb the hair and do your design as you please.

  3. After having your desired hair design

    In blender Window-Type selection select the Text-Editor as shown in the figure below
  4. 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][0], guides[n][i][1],\
    guides[n][i][2]))
    #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[0].getLoc()
    file = open("C:\hair.obj", 'w')
    exportAsCurves(file,hairs,300)
    file.close()
    
  5. 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.
  6. 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).
  7. Here is the exported hair in makehuman

    hair imported 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.

Posted in 3D Modelling | 12 Comments

Cracking YouTube

I should probably get some reward from YouTube for exposing a crack. Something in the range of 2k to 20k euros is moderately good, thank you.

Yesterday I was very curious about AbiWord’s collaborative editing feature (which was apparently around for eons ago without me noticing.. go figure). So I started typing a search for YouTube to see if there is anything about it. Lo and behold, I managed to enter some YouTube anomally. And it wasn’t just a fluke, I was able to reproduce it no matter how many times I tried.

This is how it reads:

500 Internal Server Error

Sorry, something went wrong.

A team of highly trained monkeys has been dispatched to deal with this situation.

If you see them, show them this information:
**some cute MIME code.***

So is there a bug bounty for this?? :D maybe 3313.7? Google.. anyone?

Oh well, what the hell. I’ll tell you how to reproduce this bug. I hope that it will then disappear from U-Tube :D (doesn’t this remind you of… Monkey Island)

Ok here are the steps:

  1. Go to YouTube
  2. In the search type in “abiword collabo”

Hope the monkeys solve their problems soon (ah.. again Monkey-Island.. there must be some sort of conspiracy between YouTube and LucasArts/TellTale).

EDIT: This is getting even more weird.. here is a screenshot of my browser when I use my personal computer (which has no firewall, anti-virus and other knick-knackeries)

So apparently there isn’t anything wrong, right? not right?
Well.. here is a screenshot using my office-laptop (which has OfficeScan and other bling-blings)

Both screenshots taken almost at the same time and I use the same network. Moreover, I have no problem accessing any other site so far. Well … except that in my Office Laptop, no thanks to all things installed in it, it is ten-folds slower than my home laptop.

Edit: I figured maybe this is a browser+firewall thing. So I tried the same thing on Internet Explorer 8 (I was doing everything in Opera 10.61). And indeed it was also browser related (I am pretty certain though that some sort of firewall or antivirus is triggering this all, since in my home laptop there was no problem under Opera). Here is the screenshot in from my office-laptop (that had the monkey problem in opera) with IE 8

I am going to report to Opera about this, although I don’t think I should fully blame Opera for this.

Edit: I think I finally found the solution to the bug. Just clean up the cache and change the YouTube preferred language. You can switch to your original language afterwards. Pretty strange.

Posted in Uncategorized | Tagged | Leave a comment

Understanding Baer Rings

I have been kind of inactive in mathematics, but hopefully not yet infertile. Recently there is a big thing that has been teasing me and I have to write about it. If not anywhere, at least here!

Here, we will always assume commutative unitary rings.

Let’s start with a simple definition:

Definition: Suppose that A is a ring, then A is said to be Baer if for any subset S\subset A theres is an idempotent e\in A such that eA is the set of annihilator of S.

It was in the 70’s that Mewborn showed that every reduced commutative ring has a Baer Hull, this is the smallest intermediate ring between the ring and it’s complete ring of quotients that is Baer. Mewborn showed a more detailed construction of the Baer hull of a reduced commutative ring. He showed that the Baer Hull of a reduced commutative ring is just the adjoint of the ring with all the idempotents of its complete ring of quotients.

But… there is a question, rather a conjecture, that lingers in my head…

Conjecture. Suppose that A is a reduced ring and suppose that there are finitely many idempotents (in its complete ring of quotient) e_1,e_2,\dots, e_n such that A[e_1,\dots,e_n] is a Baer ring. Then A is actually a Baer ring.

I’m thinking about this for a while, hope that the answer pops in my head soon. But why am I trying so hard to show this? Well…

I think I can show/prove the following:

Conjecture. Let A be a real Baer ring and let T be the total integral closure of A such that T is in a natural way a finitely-generated A-module. Then A is actually a real closed ring and

T= A[\sqrt{-1}]

and if I know that the first Conjecture holds true, then I can even remove the requirement of A being Baer. This would be great!

But, why am I trying so hard to show that this second Conjecture holds?? Simply because the second Conjecture is beautiful :) not to mention the fact that it is a generalization of the “classical” Artin Schreier Theorem (if you A were a field, then its total integral closure is no other than its algebraic closure. As a note, I am afraid I cannot remove the requirement that A should be real.).

Artin-Schreier Thereom. Let F be a field and let K be its algebraic closure. Suppose furthermore that F and K are unequal, but K is a finite field extension of F. Then F has actually characteristic 0. In fact, F is a real closed field and

K = F[\sqrt{-1}]

Ancel C. Mewborn, “Regular Rings and Baer Rings”, Math. Z. 1971, vol. 121, p. 211-219

Posted in Commutative Rings | Leave a comment

How to Create a Robot *.avi Animation using TUL

TUL (THOR Ultralight) is a free robotics program developed byAMROSE for use in research and education. It has a lot of useful features and here I will show how one can create a video of the robot using it. I will not guide the reader on basic use of TUL, these are  found in THOR Technical documentations and THOR Tutorial. THOR is a very useful tool and unfortunately this tool is less known to people outside the robotics community. The tool can be used for instance in simulation of human-models, mechanical models etc.

You will need:

  • Install TUL
  • Learn about TUL and its script formats ( *.wc workcells, *.tag files and programs,*.wu  workunits, *wp workpieces), which you can read in TUL documentation (takes about 15minutes of reading)
  • Download and install MonkeyJam
  • Have a *.tpg program created that you can simulate and want to export as *.avi

Here are the steps

  1. Open your *.wc or *.wu file
  2. Go to the Program tab and open your desired program *.tpg file (or create one).
  3. Simulate the program by right-clicking on it and choosing Simulate in the context-menu.
  4. Press the play button and let the simulation play
  5. After the simulation played choose Tools–>Animate… This will help you create sequences of images that can then be used to create your animation.
  6. A window will appear. Choose your Output directory and Start name (your image files will be incremented with a trailing number at the end of the start name). Choose .jpg Type for the image type. Choose S-VGA (if you want a good quality). You can play more with the other parameters as necessery.
  7. Press the Execute button as soon as you are satisfied with your settings.
  8. The robot will play the simulation again and simultaneously produce the .jpg images in the desired directory
  9. Open MonkeyJam
  10. Choose File->Import->Images… and browse through the directory where your images were created by TUL.
  11. Select all the sequential image files by Add Files>> (you can press the Shift keys and the arrow/mouse keys selecting the files and then clicking on Add Files>>)
  12. Select Import.
  13. Usually you will not need to make any other changes in the settings. But if you are familiar with animation, you can change the FPS the Composite and you can add duplicate frames (to make a better quality video) and play with other things.
  14. After changing the settings as you desired, select File->Export Avi…
  15. A window will appear and you can choose and set the video compression you want. For most Windows users Microsoft Video 1 Compression is available and easy to manage. You can also choose other Codecs and play with the settings.  But Microsoft Video compression will suffice for a simple robot animation.
  16. Thats it! The video can be now played by your favourite player.
Posted in Animation, Robotics | Leave a comment

Using Inkscape for LaTeX Documents

This tutorial shows you how to use Inkscape for editing or creating .eps or .ps graphics that can then be imported into your LaTeX Document. You will need:

  1. Inkscape 0.46 (you may try other versions too)
  2. TexText 0.4.4 (Inkscape LaTeX plugin), can be found in this site.
  3. Python 2.5 (or higher) that is used by TexText. TexText can still be used without Python, but it will apparently have limited functionality.
  4. MikTeX and all other LaTeX necessities

First let me explain a little why we are using Inkscape. Inkscape edit’s and creates svg documents. SVG format for Inkscape is an XML-based vector-graphic format and it has the following advantage:

  1. Diffing and merging different versions of .svg is easier than a binary format like .jpg (so if you use a repository like svn, you can easily differentiate the different versions of your graphics)
  2. Resolution of svg graphics is transform-invariant. This means, unless the svg file has a binary picture imbedded into it, the graphic resolution (for both printing and viewing) is unaffected from scaling, shearing, and other form of transformation.
  3. Inkscape has the ability to save as .ps and .eps which are format used in LaTeX to include graphics

Having said that, here is a simple example on how you can use Inkscape in a LaTeX document:

  1. Install all the necessary programs
  2. Do your Vector-Graphic drawing.
  3. If you need to import a .jpg or other binary image go to File->Import and choose the image
    • Note: There are two ways images can be embedded into an .svg file. One is by being referenced in the .svg file itself. The reference in the .svg file will then look like this:
      <image
             y="191.29076"
             x="260"
             id="image5237"
             height="345"
             width="360"
             sodipodi:absref="C:\Documents and Settings\jcapco\Desktop\work\sauggreifer.jpg"
             xlink:href="sauggreifer.jpg" />
      

      Another is by being embedded internally. If .svg are versioned (i.e. constantly being updated), it is recommended to have it embedded as a reference. You can have the image embedded into your svg by going into Effects -> Images -> Embed All Images.. Then the svg is saved without a referencing, it will still be a XML-based (text) file. But for the image we have a base-64 encoding:

      <image
             xlink:href="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/4QAMTmVvR2VvCAAAWv/bAEMAAwICAwICAwMDAwQDAwQFCAUF
      BAQFCgcHBggMCgwMCwoLCw0OEhANDhEOCwsQFhARExQVFRUMDxcYFhQYEhQVFP/bAEMBAwQEBQQF
      CQUFCRQNCw0UFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU
      FP/AABEIAVkBaAMBIgACEQEDEQH/xAAcAAEAAQUBAQAAAAAAAAAAAAAABgECBAUHCAP/xAA/EAAC
      AQMCAwUFBgQGAgIDAAAAAQIDBBEFBhIhMQcTQVFhFCJxgZEjMkJSobEIwdHhFSQzU2LwQ2Ny8SWC
      ...
      ...
             width="360"
             height="345"
             id="image5237"
             x="260"
             y="191.29076" />
      
  4. You may also want to insert some mathematical formulae in labeling some drawings. To do this (you must have installed TexText for this), you will have to choose Effects –> Tex Text
    • Caution: You should not forget the $ signs when typing any mathematical symbol (see the figure). Usually a scale factor of 1.0 is sufficient, you may scale or transform the LaTeX output using the Inkscape transform parameters (Shift+Ctrl+M or Object –> Transform …)

    Here is a sample using TexText:

  5. After you have finished doing your drawing and labelling you may save the result
  6. Save the result also as .ps (not .eps), using File –> Save as… and select “PostScript via Cairo (*.ps)” for the format.
  7. You may leave the default option of Cairo PS Output as it is when saving (Postscript level 3, 80 DPI) or you may want play with this settings if you are familiar with them.

  8. You may then insert the .ps into your LaTeX document using graphic or graphicx includegraphics (see any LaTeX graphics tutorial) or any other package that imports graphics (like pstricks, pictex.. etc.)
    \includegraphics[width=30mm]{inkscape-latex.ps}
    

    Here is an example of a .ps image included in LaTeX after having created it in inkscape:

Posted in LaTeX | Leave a comment