S&box Wiki
Home
/
Edit Cloth Physics
View
Edit
History
No Category
Developer Overview
The Project System
Publishing To Asset Party
Getting Started With Hammer
Mapping Basics
Mapping Entities
Advanced Mapping Techniques
Getting Started with Modeldoc
Animgraph & Animation
Physics
Modeldoc Nodes
Advanced Modelling
UI Basics
Styles & Stylesheets
Razor Templates
Game Menus
Materials
Built In Shaders
Shaders
Shader Reference
Sounds & Audio
Particles
Getting Started
Making Games
Input
Networking
Physics
Rendering
Editor & Tools
VR
Misc
Playing Guides
Console Commands & Variables
Dedicated Server
Log in to edit
Cloth Physics
<cat>Model.Physics</cat> <title>Cloth Physics</title> <deprecated>The tools used in this guide are outdated and experimental, there may be a better way to do cloth physics, or they may be reworked/removed entirely.</deprecated> # Setting Up Some of the work will be done outside of ModelDoc, *"Blender"* is recommended as we'll be using its *"Source Export Tools"*, more specifically a modified version of Rectus' Source tools, [made by Moonded on GitHub](https://github.com/Moonded/BlenderSourceTools) (on the right you can download the latest version under **"Releases"**). <warning>As of writing this, the Source 2 Tools are outdated, you will need to revert your Blender version for the tools to work</warning> 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. In **"Scene Properties"**, under *"Source Engine Exportables"* and *"Float Maps"*, add ```cloth_enable``` by pressing the **+** <upload src="a4aaf/8d94c8586b89caf.png" size="11671" name="84e1a780559f53ac17fd20f47784983ffbda6ccf.png" /> 2. Select the desired part of the mesh 3. Assign the selected mesh to the *"cloth_enable"* vertex group <upload src="a4aaf/8d8fb8e0c5a37f6.jpg" size="121282" name="image.jpg" /> 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"**. <upload src="a4aaf/8d8fb97f09db217.png" size="7874" name="3a41232745011407b18ec90e90979ad864b2715b.png" /> # 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. <warning>It is recommended for the proxy to be made up of mostly quads, tris will result in bad vertex shading on the final mesh, while ngons will render it completely unusable.</warning> 1. Select the mesh assigned to the *"cloth_enable"* vertex group 2. Duplicate it, in Blender, this is done with <key>SHIFT</key>+<key>D</key>, press **"mouse 2"** to leave the mesh in place. 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 <key>CTRL</key>+<key>E</key> > 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_v2"*, 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. 5. Create a new Vertex group called ```cloth_goal_strength_v2``` by adding it in the same way as *step 1* of **"Setting Up"** 6. Select which vertices will remain fixed 7. Assign the selected vertices to the *"cloth_goal_strength_v2"* vertex group <upload src="a4aaf/8d8fb992d56b859.jpg" size="49840" name="image.jpg" /> 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](https://developer.valvesoftware.com/wiki/DMX/Source_2_Vertex_attributes#Cloth_Simulation), 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** | Seemingly allows cloth collision with physics shapes, to verify | 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. <upload src="a4aaf/8d8fbaa1c8eda00.jpeg" size="21453" name="1c15fd9f0c6372fe6a497bfff8f6efd87db9556d.jpeg" /> <warning>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.</warning> <note>**To Do**: Figure out what *"Cloth Collision Layers"* are.</note>
S&box Wiki
Development
Developer Overview
6
Editor Overview
General FAQ
System Requirements
The s&box wiki
Troubleshooting
Useful Links
The Project System
4
Adding Assets
Creating a Game Project
Project Settings Window - Games
Project Types
Publishing To Asset Party
2
Uploading assets
Uploading projects
Hammer
Getting Started With Hammer
3
Getting Started With Hammer
Making Your First Map
Mapping Resources
Mapping Basics
7
Cordons
Hotspot Materials
Selection Sets
Standard Mapping Dimensions
Tool Materials
Tools Visualisation Modes
Using Entities That Require a Mesh
Mapping Entities
2
Creating a Door
Light Entities
Advanced Mapping Techniques
8
Collaborating With Prefabs and Git
Instances
Prefabs
Quixel Bridge Plugin
Tilesets
Tilesets-Advanced
Tilesets-Proxies
VIS Optimizations
Models & Animation
Getting Started with Modeldoc
7
Automatic Model Setup
Breakpieces
Creating a Model
Guide to Models
Importing Rust Weapons
LODs
ModelDoc FAQ & best practices
Animgraph & Animation
4
Animations without Animgraph
AnimEvents, AnimGraph Tags, Attachments
Animgraph
Delta Animations
Physics
3
Cloth Physics
Collisions, Physics & Surface Types
Jiggle Bones
Modeldoc Nodes
1
Custom ModelDoc nodes
Advanced Modelling
6
Bodygroups
Citizen
First Person
IKChains and Stride Retargeting
Morphs
Vertex Normals
User Interface
UI Basics
6
Custom Fonts
Embedding Websites
Enabling Pointer Events
Events and Input
UI Basics
UI with Components
Styles & Stylesheets
1
Video Backgrounds
Razor Templates
4
A Razor Overview
Aliases and SetProperty Attributes
Generic Components
Templates
Game Menus
1
Making a Custom Pause Screen
Materials & Shaders
Materials
5
Guide to Materials
Material Attributes
Material Resources
Texture Settings
Using Dynamic Expressions
Built In Shaders
2
Foliage Shader
Glass Shader
Shaders
4
Compute Shaders
Constant Buffers
Material API
Shading Model
Shader Reference
5
Anatomy of Shader Files
Getting rid of Tex2D macros
Shader Reference
Shader States
Texture Format Cheat-Sheet
Other Assets
Sounds & Audio
4
Guide to Sounds
Sound Events
Sound Occlusion
Soundscapes
Particles
5
Creating animated sprites
Creating your first particle effect
Understanding Particle Editor
Using custom sprites
Using particle systems from C#
Coding
Getting Started
5
Cheat Sheet
Learning Resources
Setting up Rider
Setting up Visual Studio
Setting up Visual Studio Code
Making Games
2
Components
GameObjects
Input
4
Commands
ConVars
Input System
Speech Recognition
Networking
7
Auth Tokens
Http Requests
Lobby System
Networked Types
Networking Basics
RPCs
WebSockets
Physics
5
Collisions
Hitboxes
Joints
Traces
Triggers
Rendering
3
Render Tags
RenderHooks
Scenes
Editor & Tools
5
Guide to Widgets
Hammer API
Hammer Gizmos
Hotload Performance
Widget Docking
VR
3
Getting Started
VR Input
VR Overlays
Misc
10
Asset Types
Attributes and Component Properties
Backend API
Code Accesslist
CPU Performance Profiling
DisplayInfo
package/find
Setting Up A Navigation Mesh
Threaded Tasks
TypeLibrary
Playing
Playing Guides
3
Default Keybinds
Proton
s&box on macOS (Experimental)
Console Commands & Variables
1
Launch Arguments
Dedicated Server
1
Dedicated Servers