Character Clothing Tutorial

This example goes in detail about how to set up a simple skirt simulation for a character.

Original version versus improved version with Obi Cloth simulation.
Some wind aerodynamics has been added here too.

The Character

First, we need to download "Unity Chan" model available on the Asset Store (Download here).

Now, instantiate your character on the scene (find it under /models/ folder in unity chan folder). This character has several separate clothing pieces skinned to the same skeleton as the body mesh. It makes no difference at all if your character has only one mesh (body + clothes combined), however keeping separate meshes for clothes is advisable for performance.

Obi Topology

Now we are going to generate the topology asset for our skirt. This step is crucial as it allows Obi to generate a particles-and-constraints representation of the skirt mesh. Right click on any of your project folders, and select Create->Obi->Obi Mesh Topology. This will create an empty topology asset that you should rename as you wish, in this case we chose "UC_skirt".

In the topology asset inspector, set your cloth mesh (called "Shirts") as the "Input mesh" and click generate. If everything goes well, you will see a flat-shaded representation of your mesh in the preview, with its topological borders outlined in red:



Obi Cloth

Now select the mesh you wish to apply the simulation to. Make sure the GameObject you select has a SkinnedMeshRenderer component. If it does not, it means you're either selecting the wrong object, or your cloth is not skinned to a skeleton.

Then, add an ObiCloth component to it. You will notice it will add some other components related to obiCloth too.

Obi Solver

We will also need to have an ObiSolver component to manage our cloth simulation. This component can either be added to the root of your character, to your cloth mesh, or to a completely different GameObject. It all depends on how you want your simulations to interact, and how you wish to organize your scene. Read more on ObiSolvers here.

In this case, we just created a new GameObject (adequately named "Solver") and added the ObiSolver to it. Make sure the ObiSolver "Max Particles" property is set higher than your cloth vertex count, so that there's enough particles in the solver pool to represent your mesh.

Notice how the icons represent Obi Cloth component and Obi Solver component on the scene.

Initializing and unfixing particles

Now we only need to feed the solver and the topology asset to the ObiCloth component, and hit "Initialize". After this, your cloth is fully set up and you only need to tweak parameters in order to get it to behave as you want. Make sure your ObiCloth status changes to "Initialized", as in the following image:



By default Obi fixes all particles in a character cloth, which means they will all follow the animation and ignore the simulation. So now you have to unfix some particles in your cloth so that they are free to move. To do this click on "Edit particles", select all particles you want to be affected by the simulation and click the Unfix icon. They will turn blue and the geometry will turn light gray instead.

Skin Constraints

You might notice that even after unfixing some particles, they are not completely free to move anywhere they want. This is because Obi uses skin constraints to control how animation and simulation are blended together, and to automagically resolve collisions with your character mesh.

You can tweak the per-particle Skin Radius, Backstop and Backstop Radius properties to control how the skin constraints do their job.

Read about skin constraints parameters here.

Last tweaks

To achieve the results seen at the top of this page

  • Disable every constraint component but distance and skin ones.
  • Distance constraint has "stiffness" set to 1 (stretching stiffness) so that the cloth doesn't stretch at all.
  • Distance constraint has "slack" set to 0.5 (compression stiffness). (More on Distance constraints here)

For the Skin Radius and backstop parameters, enter "Edit Particles" mode on the Obi Cloth component, select all particles by pressing the "invert selection" button or selecting them by hand with "paint selection" tool. Select the parameter on the list and paint the values the same way we did:

Read about skin constraints parameters here.

To understand all parameters, please read Distance constraints manual page. If you want to add aerodynamics to your cloth (wind effect), activate the aerodynamics constraint component, and read the Aerodynamics Constraints manual page here

Summary

  • Create an ObiMeshTopology asset and feed it our cloth mesh.
  • Add an ObiCloth component to our cloth object, which must also have a SkinnedMeshRenderer.
  • Add an ObiSolver component to any object in the scene.
  • Feed both the solver and the topology asset to our ObiCloth, and initialize it.
  • Tweak stuff (unfix particles, paint particle properties, adjust constraint parameters, etc).