Source 2 Simulated cloth physics tutorial + example showcase


Wooaaah haha cloth is awesome, in this guide you’ll learn how to make that!

Facepunch wiki guide, it’s more formal and to the point.

INTRODUCTION

This post is both a short guide and a showcase of what I’ve been working on, last time I experimented with the liquid shader and I didn’t find it necessary to make a guide, although I did leave some pointers in it.
The reason being I didn’t find the liquid shader to be that complicated or important enough to warrant a whole guide, cloth physics on the other hand is, and given that the only thing remotely close to a guide that I could find was an embedded video of some guy trying to speedrun through making cloth (doing mistakes and double-takes) I thought this was due to a nice introductory guide because I really think everyone should know about it, as I can find countless of uses for it, say no more to shitty jiggle bones.

WHAT YOU’LL NEED:

  • Some knowledge on Blender, or a 3d modelling program
  • Source tools to export in the format DMX
  • Source 2 modding tools, namely ModelDoc (currently only available through HL:A)
  • Knowing how to make models in ModelDoc

SETTING UP

Half-life: Alyx’s modding tools support clothing, but that’s just about it, the hard part will be done outside ModelDoc, in my case Blender, here how cloth functions:

    • The part of the mesh that needs to be cloth is added (weight painted) to a vertex group that marks it as such
    • A low poly “proximity” (called proxy) mesh is created
    • The proxy is the one that’s simulated, different vertex groups are applied to it to control various parameters
    • Both are exported in the DMX format

Step 4 is particular, in ModelDoc the proxy needs to be in DMX instead of the usual SMD or even FBX, moreover, it needs to be of the latest versions, using “binary 3” or higher and “model 22”, only these will work, you can find these options here:
image

Although not necessary, a user by the name of Rectus made an experimental Blender Source tool addon that allows you to easily add the vertex groups needed for the process, it also lists all of them:
image
I say it’s not necessary because you only need the name of the vertex groups to match, you can also find these in the good old valve developer community, with short explanations to boot, mind you, in complete Valve fashions, most of these are either useless or is unknown if they do anything at all, the main 2 you’ll need to use are cloth_enable and cloth_goal_strength_v2.

FINALLY THE TUTORIAL PART

Finally the tutorial part
Rev up your modelling program and m̶a̶k̶e find a model to port, create the cloth_enable vertex group, select all of the mesh you want to be simulated cloth, and apply it to that group.

Now for the proxy, the easiest way I’ve found is to copy the mesh with SHIFT+D, then separate it into its own object with P (by selection), blender now has a neat feature called “Un-subdivide”, which does just what you think, select 4 iterations and it should be fine, clean any residual tris, triangles will mess with the simulations, and even worse ngons will break it altogether, keep the proxy in the low hundreds, it should look like this:
image

Try keeping the proxy as close as possible to the original mesh, if you think it doesn’t fit as well as it should, you can use the shrinkwrap modifier on the proxy selecting the main mesh as the target (in this case I removed the eye holes for simplicity’s sake).

Now to assign the vertex groups to the proxy, luckily since it’s a copy of the original, it’s going to keep all of the vertex groups, including the ones for its bones (which you still need!), if you build it up from scratch you will need to redo the vertex groups, including “cloth_enable” (which you still need!), other than cloth enable, the main vertex group you need is cloth_goal_strength, this marks the parts that will anchor the cloth to the model, in the VDC it describes it as “(0 - 1) Controls the [sic] how much animations influence the vertex position.”, while not wrong, in complete VDC fashion, for beginners it might seem cryptic and confusing, it basically means “How much the mesh will follow the bones instead of the simulation”, 1 being 100%, making it immobile and a point to anchor the cloth.
You can do anything in between 0 and 1, which can be useful to ease in cloth, for this tutorial we’ll just use 1, so select the edges and apply them to cloth_goal_strenth like this:


I use v2 of cloth goal strength because I am cool and advanced.

Now you can export them using the aforementioned DMX format! (See “SETTING UP”), although Source 2 has “Y” for the up axis, not “Z”, which I only realized now, it shouldn’t cause many problems since I’ve never noticed it.

MODELDOC

I added “Knowing how to make models in ModelDoc” to the list of requirements because I don’t want to make a tutorial inside a tutorial, so get your model in modeldoc and add a "ClothProxyMeshFile"

Obviously having the DMX file in the correct HL:A folder, next, check the "Add Bones To Render Mesh"
image

And compile; This will generate a "Node" for every vertex in the proxy, but the reason why you should keep the proxy low poly isn’t just for performance (also that), but because in this case, less is better, believe me, I tried some high poly proxies, they all went horribly wrong and ugly.


Cloth! If all you needed was a shitty floppy cloth that goes through the mesh and terrain, then this is where you get off, if you want to learn a bit about Cloth parameters (highly recommended) and making them collide with stuff, then go on.

CLOTH PARAMETERS

Cloth parameters are basically parameters for the cloth, see all of those sliders and checkboxes inside the ClothProxyMeshFile? Those are (almost) all useless, they do either nothing or what they do is done better with the ClothParams, so add it in, you can do it quickly by right-clicking the “ClothProxyMeshList”, which lists all ClothProxies, with these you can make all kind of soft body, did I say soft body and not cloth?
It’s so customizable, you can even use it for soft-body physics! Namely balloons, wacky wavy inflatable tube arms men, hair, boob physics, penor physics, ball physics, goo physics if you want to remake snot farm, here is a list of the most useful parameters, and a short explanation on what they do:

  • Stretchiness: How stretchy cloth is, can go from 0 to infinity
  • Extra Iterations: quality of the simulation, 0 is fine since even 1000 won’t fix the problem you’re having
  • Goal Stength Bias: Basically stiffness, it refers to goal strength but is best used for stiffness.
  • Default Gravity Scale: Gravity, can go from -inf to inf, go crazy
  • Fast Drag: Basically air resistance, the existence of “Slow Drag” tells me this is only for when moving fast
  • Slow Drag: Basically air resistance, less noticeable than Fast Drag, I guess it’s only when moving slow
  • Internal Pressure: how much air is inside, useful for balloons or keeping shapes, *wink* booba *wink*
  • Wind Tangent: WIND! Goes from -inf to inf, needs at least some Internal Pressure
  • Add World Collision Radius: collision radius check for both the world and cloth shapes (foreshadowing)
  • Minimal Bend: Basically stiffness but kinda scuffed, still good to mess with it until you find a good value
  • Collide with World Hulls: Allow collision with the world

And here is a list of dishonorable mentions, the options that always made things worse (everything not mentioned in either list should probably be left on default as I didn’t notice any changes):

  • Extra Goal Iterations: multiplies the goal strength? useless, makes everything stiff
  • Smooth Iterations: just one iteration ruins the cloth, making everything stiff
  • Follow the Lead: Thanos snaps the cloth
  • Collide with World Capsules and Spheres: in my experience, it made cloth slippery, I had a test for using cloth as sleeves and this option, for some reason, always made the sleeve slide up, all of the other “Collide with World” options seem cool, although I can’t really test them or this, since apparently, the cloth collision used in modeldoc won’t be tantamount to what will appear in-game, I don’t have access to S&box, key please? (the hammer level tester is ass)

    Bonus wacky wavy inflatable tube arm made using a pinch of internal pressure and some Wind Tangent, use too much Wind Tangent and it explodes, but the max for the slider, 1, is usually not enough to achieve this effect.

CLOTH COLLISION

Lesss gooo haha we’re done now


Oh.
Cloth can’t collide with the physics mesh, instead, it uses cloth shapes.
You can add Cloth Shapes like you would Physics Shapes, but, unlike the latter, you can’t import a mesh, to make up for it, the cloth shape capsule can have different circumferences for the 2 points:
image
Don’t ask me what cloth collision layers are, they’re probably useless for the purpose of simple cloth.
If you’re struggling with placement, these tips will also work when setting up Physics Shapes:
Use these 4 modes on the top left to your advantage
image
First is the normal mode, second is for changing location, then rotation and lastly scale, which you’re better off just using the default mode for that, the most useful for me is location, as it allows you to move by axis or by plane:
image
(arrows for axis, squares for planes)
Quick tip:

  • X is the red arrow
  • Y is the blue arrow
  • Z is the green arrow

This is assuming the values it gives you for the points is in order of “XYZ”
Here is the Nightcrawler head once I’ve set up Cloth Shapes:


(I used multiple shapes for the head to give it an odd shape)

Problem:
My cloth goes through the cloth shapes!
This is the only problem I’ll cover because it’s the only problem that got me tearing out hairs out of my head, basically from what I’ve found, there are 2 factors that make cloth clip through (it’s clipping through, it’s not ignoring it):

    • The cloth is moving too fast or too slowly
    • The ClothShape is not thick enough

For the first problem, if the cloth moves too much, it’s going to clip through, while if the air drag or any other factor slows it down too much, the cloth might not be able to keep up with the shapes, who are moving too fast, and clip through.
In both cases it’s because that the speed difference is too high, this is the problem I was referring to in “Extra Quality Iteration”, the cloth simulation is very cheap, which makes it good on performance, but this means you can’t go too crazy on it, and extra quality iterations help so little it’s absolutely not worth it.

For the second problem, it’s more of a solution, if the cloth clips through, just make the ClothShape thicker! As a rule of thumb, you should probably always make it as THICK as possible.

And no, you can’t stack cloth shapes, trust me I’ve tried:

MULTIPLE PROXIES PER MODEL

This one gets its own section, despite being very short (hey, “what you’ll need” exists so whatever), my Fresno Nightcrawler model required 2 different proxies, one for the head and one for the baggy pants, unfortunately, there doesn’t seem to be a way to have different ClothParameters for different ClothProxies, the first that appears is the one that gets used, as a compromise I gave the whole thing 0 gravity, to keep the head shape better and to keep the pant swaying motion.

FINAL WORDS

Here is the final model:


Ain’t it neat, I’m going to use this little guy to test a lot of other Source 2 stuff, like animgraphs, and hopefully, it will be in-game someday. Please.

Since I didn’t have anywhere else to put this, here is the concept I made:


It ain’t much, but it’s the first time I made something that had no reference anywhere and didn’t already have a 3d model, the animations are also amateurish but that’s because they are, I think they came out well enough for being my first try at animating :slight_smile:

WHY DID I MAKE THIS GUIDE WHEN I COULD’VE KEPT IT TO MYSELF

Because, if you followed along, I left some parts, I don’t know what they do, I don’t know what springs do, how to create them, or how to better fix my problems, if more people get in the know, then maybe there will be documentation for when S&box is released.
Also, I want this to be the first result in Google, SOURCE 2 CLOTH TUTORIAL .
I will also update the FacePunch wiki with this information since I can edit it as a “regular” :sunglasses: , I really like this feature of Source 2 and I hope it becomes a staple in models since in reality it’s not really hard once you understand it, it’s like 3 steps.
ALTHOUGH I CAN’T TEST THE PERFORMANCE OF CLOTH SINCE I CAN’T TEST IT IN A GAME PLEASE.

35 Likes

Great job, Grodbert! Thanks for making the effort and explaining everything in good detail with screenshots and videos. Even though I’m not that much of an artist I’m sure this will be very helpful.

4 Likes

neato

4 Likes

Wow, Grodbert this is an amazing tutorial. Super well thought-out and thorough, I’ll definitely be using this at some point

4 Likes

Great and detailed guide, thanks!

4 Likes

great tutorial the community thanks you

3 Likes

This is what I call a tutorial. Great job!

3 Likes

Great job! This detailed content is what we need to thrive as a community. Thank you!

6 Likes

Haha ok, not to pressure anyone though (lol!) but I am curious whether or not the guide is correct, if someone tries to follow the steps and is able to make cloth without problem, I would like to know that.

And I guess if you’re blocked on a step or it doesn’t come out right, I could help, although right now it doesn’t look like cloth physics has many steps where something could go wrong.

(unlike in source 1 where basically everything you do ever has 1000 different possible errors/problems)

3 Likes

i do like that gave something to give people an understanding, i think people who get keys should do this, while they make stuff some people should hopefully also begin to explain stuff and maybe populate the S&Box wiki with stuff once they have an understanding.
its nice having people kinda show the way, helps people get into making stuff easier rather than giving up completely after hitting a wall. i hope to be of use like this to people too.

5 Likes

hmm yes interesting, I do concur

3 Likes

i also concur with that

:wink:

3 Likes

I also experimented with fabric. I made an ball, it consisted entirely of fabric. But in game, it did not work quite correctly, when moving model, engine does not consider movement, it always thinks that model in place where it was spawned, if this place is not in the frame, ball stops rendering, it becomes invisible, and then it is respawn in spawn place. Also, physical models and player interact poorly with this ball, any object with small weight squeezes ball and player can crush it and fabric will disappear

2 Likes

Good job i think iam gonna to make clothes for s&box

2 Likes

I Love it!!!
I need more tutorials about Source2, thank you! :heart:

1 Like

I have made a page for it on the wiki, here is the URL:

4 Likes

i love it, amazing job! cant wait to see more stuff like this updated in there at a good quality like this

1 Like