How to implement a modular clothing system?

Started by
3 comments, last by Nagle 2 years, 9 months ago

I want my character to have swappable clothes (for example different pieces of armor, different helmets and etc), how do I approach this? A quick youtube search told me to just parent cloth to the rig of the character. Is it a good approach? What if some parts of the cloth object need to be simulated in the game?

Advertisement

Conceptually, this is simple. Just build your assets in a modular fashion. Build a head, a torso, a pelvis, a legs, and a foot area. Build skinned assets for hairstyles, helmets, undershirts, coats, underpants, overpants, socks, and boots. Finally, build rules in your game for “which assets completely cover the assets below them?”

You might have a dress shirt that completely covers the torso, but you might have T-shirt or wife beater shirt that doesn,t' so if wearing a wife beater shirt, you need to draw the torso, whereas if you wear the dress shirt, you don't

Similarly, you might have high boots which cover the feet and socks areas, so you don't need to draw those when wearing those boots, but if wearing sandals, you DO need to draw at least the socks. (If the socks cover the feet, those don't need to be drawn.)

So, finally, at runtime, you need to assemble the set of meshes the character is wearing, mark those meshes that are “covered” by outer layers as “not drawn," and draw the rest. They should all reference the same base “skeleton” asset, so that you run the animation once (onto the skeleton) and then render all of the attached meshes.

Are you using your own engine, or something ready-made? For example, in Unreal, this is pretty easily done with the “set master pose component.” You'd make an invisible skeleton mesh be the “Master pose component” and then, for each skinned mesh for each piece of clothing worn, you “set master pose component” to that invisible skeleton, and everything will move and render together.

Note how I said “just build your assets in a modular fashion” above? There's nothing “just" about it, because unless you essentially use the same topology as the base body asset, you may very well run into cases where the skin pokes through the T-shirt, or the hairstyle pokes through the helmet, or the feet poke through the boots – paying VERY CAREFUL attention to the underlying topology, and offsetting it outwards by a sufficient amount for each piece of clothing, is quite important. Also, you may need to model the inside of shirts that open in the collar, jackets that are unzipped, and so far, else you will see a mysterious hole when the player views the character such that the “insides” could be seen. That, or use two-sided geometry, but two-sided geometry has so many problems I strongly recommend against it for any modern game system.

enum Bool { True, False, FileNotFound };

@hplus0603 Thanks for the info! Answered my questions, especially the part:

They should all reference the same base “skeleton” asset, so that you run the animation once (onto the skeleton) and then render all of the attached meshes.

Second Life has exactly this. Clothing and avatars are completely separate, sold separately by different sellers, and mix and match.

Getting dressed is complicated. Troubles usually involve an inner layer sticking through an outer layer. Sometimes this is fixed by sticking a 2D “alpha” layer on the item which peeks through, to blank it out.

This is all a huge headache. There really needs to be a system which, when you get dressed, does some physics type adjustments to the models to move the vertices in and out a bit to avoid collisions. Metahuman Creator does that with hair; they fluff the hair and let it fall until it collides, then lock it to the skeleton.

Long dresses are tough; legs tend to go through them. So is long hair. Those really need some cloth physics.

This topic is closed to new replies.

Advertisement