Difference between revisions of "Documentation:Clothes"

From MakeHuman Community Wiki
Jump to: navigation, search
(Created page with "MakeClothes, as its name implies, is a Blender addon that is used to construct clothing assets for use in the MakeHuman program. Clothes can be modeled using any technique tha...")
 
Line 77: Line 77:
 
* License. Defaults to: AGPL3
 
* License. Defaults to: AGPL3
 
* HomePage. Defaults to:!LINK!http://www.makehuman.org/ -- http://www.makehuman.org/!/LINK!
 
* HomePage. Defaults to:!LINK!http://www.makehuman.org/ -- http://www.makehuman.org/!/LINK!
 +
 +
 +
=== MHBlenderTools: MakeClothes rigid fitting ===
 +
The standard clothes fitting algorithm is suitable for flexible clothes, especially clothes that follow the body closely. However, is does not work well for rigid objects like shoes, Therefore, MakeClothes has a variant suitable for rigid shoes. Rigid fitting is used on a vertex group basis, so rigid and flexible fitting can be mixed in the same piece of clothing.
 +
Rigid fitting is used for every vertex group whose name starts with a '*'. Each such vertex group in the human must contain exactly three vertices, that determine the triangle used for fitting in this group.
 +
!IMAGE!Pictures/rf-100-orig.png!/IMAGE!
 +
The use of rigid vertex groups is best explained by an example. Consider a pair of shoes, which is a rigid object. We used the standard MakeClothes settings and an adult human with the original shoe to the left. Then the mhclo file was loaded onto a baby, with the result to the right. The shoe is recognizable but it has been deformed in an undesirable way. However, even though the quality of the fitting is poor, make sure to save the mhclo file, because we will need it at the end of this tutorial.
 +
!IMAGE!Pictures/rf-110-projection.png!/IMAGE!
 +
Each clothing vertex v is associated with a triangle t in the human mesh, i.e. three human vertices v1, v2, v3. Letrdenote the location of v andr1,r2,r3the locations of the corners of the triangle. Further, let d be the perpendicular distance from the clothes vertex to the plane spanned by the triangle. MakeClothes assigns three weights w1, w2, w3, such that
 +
    r= w1r1+ w2r2+ w3r3+d,
 +
where the sum of weights w1+ w2+ w3= 1. When the clothing is loaded onto a different character, the new location becomes
 +
    r'= w1r'1+ w2r'2+ w3r'3+d',
 +
wherer'1,r'2,r'3are the locations of the three human vertices in the new character, and
 +
    d' = Sd= (sxdx, sydy, szdz)
 +
is obtained from the original offsetdby inhomogeneous global scaling with the diagonal scale matrix
 +
    S = diag(sx, sy, sz).
 +
The important observation is that the quality of the fitting depends crucially on the chosen triangle, i.e. the triple of human vertices the determines the clothes vertex location. The standard choice is to choose the human triangle closest to to clothing vertex. In rigid fitting the triangle is the same for all vertices, and is defined by the tree vertices in the vertex group.
 +
!IMAGE!Pictures/rf-120-vgroups.png!/IMAGE!
 +
Here we see the vertex groups used to fit the left shoe. The standard vertex group Left consists of all vertices close to the left shoe, in the tights helper. On the other hand, the rigid vertex group *Left only contains three vertices that define the single triangle used for all clothes vertices in this group.
 +
!IMAGE!Pictures/rf-130-triangles.png!/IMAGE!
 +
The next illustration shows the corresponding triangles used for fitting. The Left group uses many triangles obtained by triangulating the corresponding faces. Different shoe vertices are associated with triangles that are transformed differently, and the rigid character of the shoe is lost. The *Left group only has one single triangle, with corners at the three vertices in the vertex group. The same triangle is used by all left shoe vertices.
 +
!IMAGE!Pictures/rf-140-rename-vgroups.png!/IMAGE!
 +
Once the human vertex groups have been defined, we proceed with clothes-making. Rename the shoe vertex groups to *Left and *Right, to make the shoes use rigid fitting. Recall that the human can have several overlapping vertex groups, but in a piece of clothing each vertex must belong to exactly one group.
 +
!IMAGE!Pictures/rf-150-offset-scaling.png!/IMAGE!
 +
Next we open the Offset Scaling section and select Foot as the body part. In flexible fitting, the offsets are usually very small, and selecting the correct body part is not so important. In contrast, this step is very important in rigid fitting, because many vertices are far away from their triangles and the offsets must be scaled correctly. Press Examing Boundary for a visual inspection of which vertices define the global scale matrix..
 +
!IMAGE!Pictures/rf-160-baby-shoes.png!/IMAGE!
 +
This picture shows the shoe loaded on a baby, using flexible fitting (blue) and rigid fitting (red). Rigid fitting clearly maintains the shape of the shoe much better.
 +
However, one problem remains: bone weighting. Start up MakeHuman and load the shoes under the Geometries > Clothes tab. Export the character with a rig in one of the formats that allows that, e.g. mhx, and import the character into Blender. Now try to pose the feet. As we see in the picture below, the shoe does not follow the foot but is squashed or stretched in strange ways.
 +
!IMAGE!Pictures/rf-170-bad-deformation.png!/IMAGE!
 +
The reason is that rigid fitting affects the bone weights as well as the vertex locations. The bone weights are interpolated between the three corners of the triangle, rather than using the information from the entire foot. To correct this we need to use two different associations between clothes and human vertices: rigid fitting for vertex locations, but flexible fitting for bone weights.
 +
Fortunately, MakeHuman can handle this situation, although there is currently no elegant interface for it in MakeClothes. In a text editor, open the mhclo file obtained by standard fitting in the beginning of this tutotial (this is why you needed to save it), and copy everything after the line
 +
verts 0
 +
to the end of the new mhclo file obtained by rigid fitting. Before the copied section, insert the line
 +
weighting_verts
 +
Export the shoes again from MakeHuman and import into Blender. The shoes should now both maintain their rigid shape and deform correctly.
 +
!IMAGE!Pictures/rf-190-good-deformation.png!/IMAGE!
 +
Due to an unfortunate behavior in MakeHuman, it is possible that the updated mhclo file is not loaded after it has replaced the old one. This is because MakeHuman automatically compiles mhclo and obj files when loaded, so they can be loaded faster next time. Although this behavior is convenient for ordinary users, it is very confusing and frustrating for clothes makers. If MakeHuman insists on loading old versions of your clothes, you may need to delete the compiled files (*.mhpxy and *.npz), or restart MakeHuman, or both. After the compiled files are gone, the updated clothes should load without problems.
 +
!IMAGE!Pictures/rf-180-compiled-files.png!/IMAGE!

Revision as of 11:21, 20 May 2016

MakeClothes, as its name implies, is a Blender addon that is used to construct clothing assets for use in the MakeHuman program. Clothes can be modeled using any technique that is natural. For example, clothing can be modeled from scratch, or by altering either the human mesh or the “clothing helpers” (see below) provided by the MakeClothes tool. When designing and modeling a clothing item, there are two restrictions that should be kept in mind. First, the algorithm for mapping a clothing mesh to the human mesh requires that theclothing mesh consists entirely of quad faces. Second, it is important to know that MakeClothes supports only one material per item of clothing. Upon completing the MakeClothes workflow, a new folder will be created by the tool within %USER%/makehuman/v1/data/clothes. That folder will assume the unique name that the user provides for the clothing item. This folder will be populated with the assets necessary to make the item available in MakeHuman. The one additional, useful but not essential, item that the user must supply is a thumbnail icon for the clothing. The thumbnail icon can be created with any image editing program as a 128 x128 pixel image in .png format. The file should then be saved in the same folder as the other assets and the extension changed to .thumb.

Using MakeClothes addon

MakeClothes is controlled by the MakeClothes panel in the N-shelf to the right of the viewport. It consists of the main buttons that are always visible, and several hidden sections that can be displayed by enabling a checkbox.

!IMAGE!Pictures/mc2-010-main.png!/IMAGE! 

The main section contains the following:

  • Type: Specifies the character to be used as a reference. It can be one of the following:
  • Base Mesh: The MakeHuman mesh without any targets applied.
  • Average Male: A caucasian young male.
  • Average Female: A caucasian young female.
  • Average Child: A caucasian young child.
  • Average Baby: A caucasian young baby.
  • Base Mesh with Helpers: The MakeHuman mesh without any targets applied.
  • Average Male with Helpers: A caucasian young male.
  • Average Female with Helpers: A caucasian young female.
  • Average Childwith Helpers: A caucasian young child.
  • Average Baby with Helpers: A caucasian young baby.
  • Load Human mesh: the button to load the selected type into the scene.

Note:"helpers" in MakeHuman are a type of special, invisible geometry over the base mesh which can be loaded to help model clothes, for example, a helper sweater, helper tights etc. They have their own materials. It is important to note that no alterations should be made to the base mesh type after it is loaded otherwise the script will fail. The picture below shows the result of pressing "Load Human Mesh", with type set to Base Mesh.

!IMAGE!Pictures/mc2-011-main_0.png!/IMAGE! 

A human mesh is loaded into the viewport, and more tools are enabled:

  • Mesh Type: MakeClothes divides meshes into two types: human and clothing. This button displays the mesh type (Human/Clothing) of the active mesh and is greyed out if the active object is not a mesh. (MakeHuman normally detects the items accurately, but in the event of an error, you can click the button to change the mesh type so that it is treated as a clothing item instead of human if it is a clothing item and wrongly detected as a human item)
  • Create Vertex Groups From Selection: MakeClothes uses vertex groups to control the fitting.
  • Make Clothes. This is the main entry point for the MakeClothes script. With one human and one piece of clothing selected, create an association between clothes vertices and human triangles, i.e. triplets of human vertices. Both meshes must have vertex groups with identical names, and each clothing vertex must belong to exactly one vertex group. The result of the association is saved in the file ObjectName/ObjectName.mhclo, in the default directory. This button is greyed out if the active object is not a mesh.
  • Test Clothes. This buttons loads a piece of clothing (an .mhclo file) and fits it to the active mesh, which must be a human. Typically a second human is loaded on a different layer, and the quality of the clothes fitted to that character can immediately be checked in Blender. To test the clothes under the strictest conditions, the human model used for testing should be quite different from the human used for clothes-making. If the original character is an adult, Baby With Helpers is a good choice.

If, instead, the Human With Helpers button is pressed, the full MakeHuman mesh including the helper geometry is loaded. Different materials are assigned to each type of helper geometry. The materials are ordered in the order of the vertex number. This makes it easy to peel off one helper type at a time.

!IMAGE!Pictures/makeclothes03.png!/IMAGE! 

Glue clothes to the body

The clothes are meshes that be done directly in Blender, or in another package and then imported into Blender as an obj file. Note that the mesh type is Clothing, which is the default unless the mesh has been declared to be a human. A simple method to obtain a starting point modelling is to duplicate part of the human mesh and separate it from the human. However, in this case the duplicated mesh will still be a human. To change the mesh type, press the toggle button Human. The status is now changed into Clothing. After loading the human, next step is to "glue" the clothes to the human, in order that they will automatically fit the body changes. To control this association, MakeClothes uses vertex groups. Each clothing vertex must belong to exactly one vertex group, and a vertex group with thesame namemust exist in the human mesh as well. Only human vertices in the correct vertex group will be considered when making clothes. Vertex groups speed up the clothes-making process by pruning the search tree, and can be used to control the appearance of clothes as well. However, assigning vertex groups can be quite tedious, and in many cases it is sufficient let MakeClothes create vertex groups automatically. This is done automatically when a human mesh is loaded. If a clothing mesh does not have any vertex groups, it is also done automatically, when the MakeClothes button is pressed.

Automatic vertex groups

If vertex groups need to be reassigned, e.g. because a piece of clothing has been edited, the automatic vertex groups can be used. When the human is selected, there is a button, visible in the image above, called "Create Vertex Groups From Selection". Selecting a cloth, the button change in "Create Vertex Groups". Both the buttons do the same thing, but there is a little difference: in the human is possible to generate the vertex groups only for a sub set of the vertices (selected in edit mode), while for clothing the vertex groups must include all vertices. This is because we need to associate onlya partof the human vertices withallvertices of the clothing. For example, we need to associate all the vertices of a skirt with the human torso only. Pressing the button, the following vertex groups are created:

  • Mid: Vertices on or very close to the center line (|x| < 0:001).
  • Left: Vertices to the left of the center line (x > 0:001). For a human the Mid vertices are also included in the Left group.
  • Right. Vertices to the right of the center line (x z 0:001). For a human the Mid vertices are also included in the Right group.
  • Delete: An empty group only created for humans. Human vertices hidden by the piece of clothing can be added to this groups. These vertices are then optionally deleted when the clothing is applied in MakeHuman, thus avoiding that blotches of skin poking through the clothes. Note that when a vertex is deleted, so are all faces containing this vertex. Don't assign a vertex to the Delete group unless all faces containing it are hidden by the pieces of clothing.

In the image below, vertices assigned to the Mid and Left groups for a nude human.

!IMAGE!Pictures/auto-vert.png!/IMAGE! 

Generate the clothes file.

When both clothing and human has the vertex groups with same name, just press the MakeClothes button to generate the files.

They will be located in your HOME/makehuman/a8/data/clothes, in order to be inbcluded automatically in MakeHuman.

Advanced tools

Under the main buttons of Makeclothes, there are seven hidden panels that can be activated clicking the checkbox. Let's see their meaning.

Show selection, Show Materials, Show UV projection

!IMAGE!Pictures/options-01.png!/IMAGE! 

Show selection.This feature is just a shortcut to quickly select some part of the human. So, instead of classic Blender selection (go in edit mode, move the mous on a vert and press Lkey to select the linked vertices), you can just press these buttons. Show Materials. This will show a button to export the materials only. It's useful in case there are not changes on geometry, but only on the material, in order to avoid to recompute all. Show UV projection.This section is useful mainly for making proxy meshes.

  • Recover seams.Creates a Seam object, which has edges where the selected mesh's UV layout has seams. The Seam object is intended to be reference for marking seams for the clothing.
  • Auto seams.
  • Project UVs.Automatically create an UV layout for the clothing, compatible with the human's UV coordinates. This is intended for the mask UV layer, which must be compatible with the body mesh for all clothes. The actual texture can use a different UV layer which can be laid out in any desirable manner.
  • Reexport Mhclo file.The mhclo file must be resaved when the mask UVs have been defined. This can be done by pressing Make clothes again, but Reexport Mhclo file is faster.

Show ZDepth, Show Offset scaling

!IMAGE!Pictures/options-02_0.png!/IMAGE! 

Show ZDepth.This option is used to assign a depth to the cloth, in order to hide skin and clothes which are covered by clothes on top of it. The Z depth specifies the stacking order, which decides which clothes should hide others. Normally the Z depth ranges between 0 (skin) and 100 (external accessories such as backpacks).

  • Depth name. Roughly indicates the preferred Z depth for various clothes types. The choices are: Body, Underwear and lingerie, Socks and stockings, Shirt and trousers, Sweater, Indoor jacket, Shoes and boots, Coat, Backpack.
  • Set Z depth.Set the Z depth depending on the selected depth name.
  • Z depth.The value of the Z depth. This is changed by the Set Z depth button, but can be dialledmanually for fine-tuning.

Show Offset scaling.The location of a clothing vertex depends on two data: a point on a body triangle, described in barycentric coordinates, and the offset from that point. The offset is scaled in the X, Y and Z directions depending on the size of a certain body part.

  • Body part.Set this to the body part which is most affected. The choices are: Custom, Body, Genital, Head, Torso, Arm, Hand, Leg, Foot.
  • Examine.Select the boundary vertices with Set boundary is invoked.
  • Set boundary.Set the boundary to vertices determined by the selected body part.
  • Custom Boundary.To manually set the bounday box.
  • X1, X2, Y1, Y2, Z1, Z2.The vertex numbers of the six vertices which define the scaling boundary. The X scale is determined from the distance between vertices X1 and X2, the Y scale by Y1 and Y2, and the Z scale by Z1 and Z2.

Show Setting, Show License

!IMAGE!Pictures/options-03.png!/IMAGE! 

Show Setting.The setting include the author name and the export path. It's possible to save and restore the settings. Show License.This set of options are to add theauthor name, the type of license and the tags for clothes. Licensing information to be put at the top of the exported mhclo file. It consists of three strings that can contain arbitary text.


MHBlenderTools: MakeClothes rigid fitting

The standard clothes fitting algorithm is suitable for flexible clothes, especially clothes that follow the body closely. However, is does not work well for rigid objects like shoes, Therefore, MakeClothes has a variant suitable for rigid shoes. Rigid fitting is used on a vertex group basis, so rigid and flexible fitting can be mixed in the same piece of clothing. Rigid fitting is used for every vertex group whose name starts with a '*'. Each such vertex group in the human must contain exactly three vertices, that determine the triangle used for fitting in this group.

!IMAGE!Pictures/rf-100-orig.png!/IMAGE! 

The use of rigid vertex groups is best explained by an example. Consider a pair of shoes, which is a rigid object. We used the standard MakeClothes settings and an adult human with the original shoe to the left. Then the mhclo file was loaded onto a baby, with the result to the right. The shoe is recognizable but it has been deformed in an undesirable way. However, even though the quality of the fitting is poor, make sure to save the mhclo file, because we will need it at the end of this tutorial.

!IMAGE!Pictures/rf-110-projection.png!/IMAGE! 

Each clothing vertex v is associated with a triangle t in the human mesh, i.e. three human vertices v1, v2, v3. Letrdenote the location of v andr1,r2,r3the locations of the corners of the triangle. Further, let d be the perpendicular distance from the clothes vertex to the plane spanned by the triangle. MakeClothes assigns three weights w1, w2, w3, such that

   r= w1r1+ w2r2+ w3r3+d,

where the sum of weights w1+ w2+ w3= 1. When the clothing is loaded onto a different character, the new location becomes

   r'= w1r'1+ w2r'2+ w3r'3+d',

wherer'1,r'2,r'3are the locations of the three human vertices in the new character, and

   d' = Sd= (sxdx, sydy, szdz)

is obtained from the original offsetdby inhomogeneous global scaling with the diagonal scale matrix

   S = diag(sx, sy, sz).

The important observation is that the quality of the fitting depends crucially on the chosen triangle, i.e. the triple of human vertices the determines the clothes vertex location. The standard choice is to choose the human triangle closest to to clothing vertex. In rigid fitting the triangle is the same for all vertices, and is defined by the tree vertices in the vertex group.

!IMAGE!Pictures/rf-120-vgroups.png!/IMAGE! 

Here we see the vertex groups used to fit the left shoe. The standard vertex group Left consists of all vertices close to the left shoe, in the tights helper. On the other hand, the rigid vertex group *Left only contains three vertices that define the single triangle used for all clothes vertices in this group.

!IMAGE!Pictures/rf-130-triangles.png!/IMAGE! 

The next illustration shows the corresponding triangles used for fitting. The Left group uses many triangles obtained by triangulating the corresponding faces. Different shoe vertices are associated with triangles that are transformed differently, and the rigid character of the shoe is lost. The *Left group only has one single triangle, with corners at the three vertices in the vertex group. The same triangle is used by all left shoe vertices.

!IMAGE!Pictures/rf-140-rename-vgroups.png!/IMAGE! 

Once the human vertex groups have been defined, we proceed with clothes-making. Rename the shoe vertex groups to *Left and *Right, to make the shoes use rigid fitting. Recall that the human can have several overlapping vertex groups, but in a piece of clothing each vertex must belong to exactly one group.

!IMAGE!Pictures/rf-150-offset-scaling.png!/IMAGE! 

Next we open the Offset Scaling section and select Foot as the body part. In flexible fitting, the offsets are usually very small, and selecting the correct body part is not so important. In contrast, this step is very important in rigid fitting, because many vertices are far away from their triangles and the offsets must be scaled correctly. Press Examing Boundary for a visual inspection of which vertices define the global scale matrix..

!IMAGE!Pictures/rf-160-baby-shoes.png!/IMAGE! 

This picture shows the shoe loaded on a baby, using flexible fitting (blue) and rigid fitting (red). Rigid fitting clearly maintains the shape of the shoe much better. However, one problem remains: bone weighting. Start up MakeHuman and load the shoes under the Geometries > Clothes tab. Export the character with a rig in one of the formats that allows that, e.g. mhx, and import the character into Blender. Now try to pose the feet. As we see in the picture below, the shoe does not follow the foot but is squashed or stretched in strange ways.

!IMAGE!Pictures/rf-170-bad-deformation.png!/IMAGE! 

The reason is that rigid fitting affects the bone weights as well as the vertex locations. The bone weights are interpolated between the three corners of the triangle, rather than using the information from the entire foot. To correct this we need to use two different associations between clothes and human vertices: rigid fitting for vertex locations, but flexible fitting for bone weights. Fortunately, MakeHuman can handle this situation, although there is currently no elegant interface for it in MakeClothes. In a text editor, open the mhclo file obtained by standard fitting in the beginning of this tutotial (this is why you needed to save it), and copy everything after the line verts 0 to the end of the new mhclo file obtained by rigid fitting. Before the copied section, insert the line weighting_verts Export the shoes again from MakeHuman and import into Blender. The shoes should now both maintain their rigid shape and deform correctly.

!IMAGE!Pictures/rf-190-good-deformation.png!/IMAGE! 

Due to an unfortunate behavior in MakeHuman, it is possible that the updated mhclo file is not loaded after it has replaced the old one. This is because MakeHuman automatically compiles mhclo and obj files when loaded, so they can be loaded faster next time. Although this behavior is convenient for ordinary users, it is very confusing and frustrating for clothes makers. If MakeHuman insists on loading old versions of your clothes, you may need to delete the compiled files (*.mhpxy and *.npz), or restart MakeHuman, or both. After the compiled files are gone, the updated clothes should load without problems.

!IMAGE!Pictures/rf-180-compiled-files.png!/IMAGE!