S&box Wiki

Cloth Physics

Cloth Physics

This is meant to be an introductory guide on adding cloth to your models through ModelDoc, it also contains some information on the different parameters and options, some of which is still not known what effect they have.

Setting Up

Some of the work will be done outside of ModelDoc, "Blender" or "3ds Max" is recommended as they are the most prevalent 3d modelling software with "Source Export Tools".

The first step will require you to mark which part of the mesh will be affected by the Proxy, this will be the actual piece of cloth:

  1. Create a new Vertex group called: cloth_enable
  2. Select the desired part of the mesh
  3. Assign the selected mesh to the "cloth_enable" vertex group

You're done with the main mesh, you can now export it (although it's suggested you keep it, as you're going to need it to create the Proxy), the only format that currently supports cloth physics is ".DMX", its version is also important, this being "Binary 3" (or any higher version) and "Model 22".

Test if other non-Source formats are allowed to be used for cloth physics, as technically they should be.

Creating the Proximity Mesh

The "Proximity mesh" ("Proxy" for short) is a cheap mesh that's used for cloth simulation.

Cloth nodes are generated based on the Proxy's vertices, which are used to deform the main mesh, it is important to keep the Proxy as low-poly as possible without compromising functionality.

While one can be made from scratch, it is highly recommended you make one by duplicating it from the original mesh, this way all of the vertex groups are preserved, which are supremely important for this process.

The proxy must be made up of quads, tris will result in bad vertex shading on the final mesh, while ngons will render it completely unusable.
Test if a proxy made up of tris will result in bad vertex shading even on a model made up of tris.
  1. Select the mesh assigned to the "cloth_enable" vertex group
  2. Duplicate it, in Blender, this is done with ⇧ shift+d
  3. Separate the duplicated mesh from the main mesh, in Blender, this is done with P > Selection, this will become the Proxy
  4. Lower polycount, In Blender (2.8+) you have the option to un-subdivide mesh with ctrl+e > Un-Subdivide
  5. If the resulting mesh seems to differ slightly in shape, you can add the "Shrinkwrap" modifier and select the main mesh as target, the vertices will be projected onto the nearest surface for greater accuracy

The cloth will also need to stay fixed onto the model, else it will fall off, to do this we use another Vertex group called "cloth_goal_strength", as the name implies, it's used for "strength" or "stiffness", the value you assign to the vertices is indicative to how much they'll follow their original parent bones, with 0 being none at all and 1 being fully, these will serve as your cloth's anchor point. Since the proxy is the one that's used for the simulation, the main mesh will not use this vertex group.

  1. Create a new Vertex group called cloth_goal_strength
  2. Select which vertices will remain fixed
  3. Assign the selected vertices to the "cloth_goal_strength" vertex group

With this, your proxy is done, export it with the same .DMX version you used earlier to export.

The 2 Vertex groups we used are the only ones that are required, but multiple additional vertex groups exist, most of which have an unknown function, you can view the full list here, on the Valve Developer Community.

Adding the Cloth in ModelDoc

After having placed both models in the correct folders, and having added the aforementioned main mesh inside MoodelDoc, you'll need to add a "ClothProxyMeshFile":

  1. +Add > ClothProxyMeshFile
  2. Select your proxy
  3. Check the Add Bones To Render Mesh box
  4. Compile

This will generate the cloth nodes, which also serve as bones, keep them to a minimum, in this case having too many cloth nodes may yield the opposite effect and result in worse cloth physics, especially for small meshes.

With this, the cloth is technically done, however, it is highly recommended to add "Cloth Parameters".

Adding Cloth Parameters

Cloth parameters will define how the cloth behaves, although a model can have multiple *"ClothProxyMeshFile"*s, only a single "ClothParams" can be used at a time, and it's shared between all proxies, the first instance of "ClothParams" will be used and the rest will be ignored.

  1. +Add > ClothParams, alternatively, you can right click the "ClothProxyMeshList" to quickly add "ClothParams", and even any additional "ClothProxyMeshFile" if needed
  2. Check boxes and pull sliders to your liking

ClothParams include many options to control the cloth, some of which were too subtle or unclear to know what they do with certainty, while some others are just educated guesses, any contribution or correction is appreciated.

ClothParams list:

Parameter Function Range
Stretchiness Controls the stretchiness 0→inf
Shear Stretch Unknown 0→inf
Extra Iterations Additional simulation checks 0→inf
Extra Goal Iterations Unknown 0→inf
Extra Pressure Iterations Unknown 0→inf
Goal Strength Bias Goal strength is globally added/subtracted -1→1
Default Gravity Scale Cloth gravity -inf→inf
Fast Drag Air drag for quick movements -inf→inf
Slow Drag Air drag for subtle movements -inf→inf
Smooth Rate Unknown ?→?
Internal Pressure Amount of air inside the mesh, requires model to be 3D -inf→inf
Windage Normal Unknown ?→inf
Windage Tangent Amount of wind generated from the mesh, requires Internal Pressure -inf→inf
Smooth Iterations Unknown 0→inf
Ground Friction Friction between cloth and the world ?→inf
World Collision Penetration Unknown ?→?
Add World Collision Radius Radius for collision check between cloth and the world is added/subtracted -inf→inf
Volumetric Solve Amount Unknown ?→?
Minimal Bend Prevents cloth to bend over a certain amount 0→1
Follow the Lead Unknown 0/1
Force World Collision On All Nodes Unknown 0/1
Collide With World Hulls Allows cloth collision with the world 0/1
Collide With World Meshes Unknown 0/1
Collide With World Capsules And Spheres Unknown 0/1
Bend-and-Stretch Springs Unknown 0/1
Rigid Edge Hinges The edges of 2D meshes will keep some shape 0/1
Soft Skin Animation Unknown 0/1
Bend Only Springs Unknown 0/1
Immovable Object (hint) Unknown 0/1

Adding collisions with Cloth Shapes

Cloth doesn't collide with Physics Shapes, instead, it has its own Cloth Shapes, these 3 being ClothShapeBox, ClothShapeCapsule and ClothShapeSphere.

You can add and modify them as you would with Physics Shapes, however, ClothShapeCapsule differs, being able to change the radius of each point instead of the capsule as a whole, making it arguably the best shape.

Having the Cloth Shapes too thin may cause the cloth to phase through them, the same happens when the speed difference between cloth and shape is too great, stacking multiple Cloth Shapes does not help.
To Do: Figure out what "Cloth Collision Layers" are.

Special Pages



Render Time: 52ms

DB GetPage 39
Generate Html 1
SaveChanges (1) 9
Render Body 0
Render Sidebar 0