Category Archives: Cloth

Cloth Deformer W.I.P

Thicken

An old trick was to take a polygon hair prop with a higher transparency/alpha then make a duplicate, maybe scale it up a fraction, offset it bit and then you could get a thicker final mesh to render.  This gave me the idea to make a simple new plugin to Thicken out the results of the simulations.  It might also give a more realistic render and rely less upon painting in the layers of hair into the texture map.

For the Thicken beta version 0.1 I’ve allowed for a single additional layer with a surface offset, xyz displacement and a scaling factor.  I’ll probably be adding a second layer and second column of settings.  I don’t think I’ll add multiple layers because that will make for a very tricky UI.  I’ve also considered giving the layers their own shading domain but I’m not sure if that is safe yet – Carrara can cope with it when you add and remove them in the vertex modeller so it should be possible.

The Thicken plugin can of course be used to conveniently add a surface offset or indent a mesh by telling it to hide the original mesh.

I used it in the render of this cloth hair simulation.  There are only a few artefacts where the layers of hair went through each other, before the thickening was applied – you can see these on the left shoulder.  This next attempt at dynamic cloth hair used twice as many layers as the last one, with 5 down the side of the head and two more at the back.  The self collisions performed nearly perfectly but it took more than 12 hours to run when draping over the figure in a 5 second animation sequence.  I also improved the alpha map technique by using 2 pixel thick strokes to paint the tips of the hair.

LongerThickerHair

Dynamic Hair with the Cloth Deformer

After a few drafts I’m getting encouraging results with dynamic hair.  This symmetrical hair was modelled lock by lock, each one layered over the other.  The roots of the hair fully conform.  From the side of the head down till below the ears is the falloff area then right down to the tips the hair is all dynamic.  It’s important to get the initial style right where the hair does conform because it will try to return to that shape during the simulation.

LongHairDraft

Improvements are needed in the number of layers of hair.  It needs another layer at the side of the head and one or more lower at the back of the head below the ears.  There should also be more variety in the locks – I duplicated and moved the same ones at the side of the head for each layer to save time.  The texture and transparency maps need more effort and care to paint with higher contrast in the strands and cleaner detail for the alpha on the tips.  I also made a scalp prop to fit underneath based on a copy of the figure’s head geometry.

I have shown animations before with dynamic cloth hair but these did not have self collisions or enough length to drape over the costume/figure.  This example used a large sphere on an angle to cover the whole head and the ears and a capsule for the neck.  The collisions over the costume required the modified code which can recorded and store simulations at a higher fps.

LongHairDraftThumbnail

While working on this I found that the conforming falloff feature of my plugin wasn’t working quite how I wanted or expected.  It’s supposed to falloff gradually from fully conforming to fully dynamic with a painted map or zone or both – but there was not much ‘falloff’ apparent.  I made a slight change to the simulation code to improve this.  My idea is that if the falloff for a vertex is 50% then it will be pulled back half way from where the physics take it to the conforming position.  The conform rate value is now used as a speed limit instead.  The conforming force is still very strong but the falloff now produces a smoother transition.  Collisions overrule this so I will need to experiment a bit more.  I want this falloff because in cloth simulators that have an on/off pixel constrain selection this creates really obvious hard bends along that dynamic edge.  

I made another quite simple but important change to the plugin code and that was to add in a self-collision margin.  In my simulator each vertex of the cloth mesh is treated as a particle with a thickness.  Unless the user overides that thickness all of the vertex particles are thick enough so that they just touch each other.  That is one reason why a regular mesh is very important.  The new margin value allows for thinner vertices and now the cloth folds can get much closer.  The hair’s need to have self collisions become obvious because without this new change the dynamic locks would pass through and intersect with each other.  This has a big impact on the design and modelling the style because the hair must start the simulation without being tangled.

Layered Simulations

Hair Layered Over ClothingAnother problem with my simulator has become apparent when trying to run a layered simulation where one cloth items drapes over another.

My plugin is a deformer and not a physics solver.  The accurate simulations are run by getting Carrara to slowly advance the time sequencer.  The current tests I’ve been doing included attempts to combine dynamic hair with a dynamic costume – where the hair would drape as a second layer over the costume.  The simulation is normally saved at the scene’s frame rate, so when the higher fps was used on the hair the costume would not move in slow steps but jump to the next set of stored data only when at a time multiple of the scene frame rate.

A number of separate cloth mesh objects can go into the one simulation but hair and different layers and different types of cloth will need different properties.

To get this to work better I set both the dress and the long hair into record mode and then ran the simulation from one of them to get the high frame rate.  This caused an immediate crash and an impossible to find bug.  I had to give up trying to find how and where it was happening because no single specific part of the code was causing it.  I believe that there is no easy way to fix it and the code is not ‘thread safe’.  Therefore only one simulation should be set to record and run at any time.

The solution for the layered cloth is simple enough.  A new setting and change to the plugin is required so that the costume simulation can be run first and all of the frames are then saved.  If the simulation is set to run at 150fps with a scene rate of 25fps then all 150 snap-shots of the cloth will be saved per second for use in the next simulation that layers over it.  This does make for a much larger file size so some kind of management of the stored data to discard the extra frames could also be added.

The next release of the cloth plugin will have this high definition recording and playback feature.  I will also need to add a similar feature to the Jiggle plugin for it to work consistently with my cloth.  It might also help when combining cloth with the Carrara physics solver or strand based hair.  I have not tested that yet.

Triangulation Bug ?

While working on the next video tutorial I appear to have found a bug.  The drop sheets over primitives and figures are clearly okay, but when I re-created a conforming costume this caused the plugin to crash unexpectedly.

I was able to narrow the problem down to the costume mesh.  The mesh must be triangulated before converting it into a conforming costume.  The previous example with the Long Green Dress was triangulated but the new test costume was not.

The 0.0498 release version of the plugin removes the quads / triangle mode but this problem is more likely related to how the facet mesh moves through the modifier stack.  The real cause is as yet unclear.  The fix is to make sure to manually triangulate the mesh.

Cloth Tutorials

After the public release of the latest code for the Cloth Deformer I wanted to revise the results I posted last year and re-create them with some video tutorials.

A drop sheet is always the most basic test to run – if that fails to work then the simulator is worthless.  So for the second tutorial I wanted to drop a bed sheet over a moving figure and then I decided to try and push the simulator and keep the figure moving under the sheet for at least 10 seconds.

It took a several draft simulations to get it right.  There were a few problems when the hands moved into the sheet and then proceeded to push through it – so I had to adjust the animation to avoid this problem and keep the hands out of the way.  Since the simulation result is not known until it has run, getting a hand to interact with the cloth part the way through is just too complex.

Something to keep in mind with cloth simulation is that in reality you can be constrained by clothing and cloth.  Tight non-stretch pants won’t allow you to run easily and when you’ve been double wrapped up all cosy in a bed sheet and quilt it is hard to suddenly spring out of bed without kicking and fighting your way out.

I also used different settings from the tutorial video.  I needed to set much higher friction and dampening values – otherwise the sheet slid off the figure and half the way off the bed by the end of the simulation to leave her exposed.  Also in the tutorial video some kooky key frames had got in and turned her elbows into bent straws.  I didn’t notice that until it was too late and uploaded, so hopefully the focus is all on the cloth.

Each simulation took at least 4 hours to run.  I spent at least 4 hours on key framing the animation (which isn’t that great) and the rendering took almost 4 hours as well – so running the simulation (while I slept) wasn’t really that big an issue in the production time.

Cloth Tutorial 2 Results

The twitching in the animation was much lower than I expected but I’m still more personally interested in the potential of the still frame results with my plugin.

What really worked surprisingly well was when she turns over to one side and also how the legs moved under the sheet.

A final note was that I might have made the animation physics even more interesting by using the Jiggle Deformer but alas it is not currently compatible with the Cloth Deformer.  The trouble is that Jiggle will not produce the same results when it is run at 150 fps as when it is run at 25 fps.  I will have to add a new recording mode into JIggle to use it with Cloth.  This would need to allow the results to be saved and played back without recalculation.

Grab Zones

One of the features of the new version of the Cloth Deformer is Grab Zones.  Interaction with hands and other moving objects that need to grab the cloth can be faked by using a spherical zone(s) at the start of the simulation to grab any number of vertices of the cloth.  When the grab object is moved the held vertices move with it to maintain the same local position in the zone, so they rotate as well as translate.

M5GrabZones

This animation shows a Michael 5 figure for Genesis trying to get attention by waving a slightly ripped t-shirt.  The cloth was given 4 seconds of animation to drape before starting to wave it about.  Some proxy objects were used on his arms and hand to prevent any possible collisions with him and get a very fast simulation result.  The shirts self-collisions all work well – but moving at that speed it’s hard to see any poke-thrus anyway.

In future I’d like to be able to have the grab zones turn off somehow to release their held vertices.  Also to be able to grab vertices during the simulation would be important.  That will be easy to code but a special ‘zone’ primitive is something I’ll need first so that it can have the right on/off switches in the properties interface.

Genesis 2 in a Long Green Dress

More demanding simulations, such as a full length dress, push my plugin to its limits.  That doesn’t mean it can’t get results though.  While also trying out Carrara 8.5’s stability with a Genesis 2 figure this simulation took about 2 hours to run, allowing about 5 seconds to go from a zeroed pose to being seated and then drape.  Again it is the still image that I am very happy with here, worth spending some extra time to do a little embroidery on the dress.

GreenDress

What is hidden in this render is that the collar of the dress sort of broke when the character’s neck bent.  The bent elbow is also a dangerous area for any practical simulation because the cloth can end up with nowhere to go.  Use of simple primitives under the skin is a good safety precaution.  Unlike certain other simulators, when mine goes wrong it doesn’t end up in a disaster.

The current code looks at all of the possible collisions of a thick vertex with an assumed convex surface – an elbow pit or neck is a concave surface.  The treatment of more complex surface interactions is what I hope to code next.  When viewed as an animation the fabric actually twitches a lot between frames, here and there.  If the surface collisions can be processed with more consistent results this should diminish.  With simple primitives there is never any twitch.

The arbor prop was not used for collisions, a few cubes were placed into the scene and then hidden for the bench seat and arm rest.

The conforming hair is not dynamic but morphed to get it out of the way for the render.  Such a hair style could possible work with draping too.  The simulation can handle layered cloth over cloth.  Internal cloth to cloth collisions are still treated as particle to particle hits to push them apart.

What is also on display here is the new Subdivider plugin.  You can get this in my Laboratory to try out.  It implements Loop(s) subdivision which is optimized for a triangular mesh.  Carrara uses Catmull-Clark subdivision which works with quads.  The Subdivider can be applied at the end of the Modifier stack when the simulation is finished to get 4 times the facets while smoothing out the cloth.

My plan for the plugin was always to expect that where it was to fit the figure’s torso to keep it as a conforming actor then allow for dynamics when it came to capes and dresses etc.  Again this simulation example did break but maybe the next version and my theories about concave and convex surfaces will work…The good thing now is that with the simulation timeout problem fixed I can run many more of them than before.

Time Killer

As I started to try out more complex simulations with full figures and drop cloths and costumes a serious issue with the Cloth Deformer emerged.  A task switch in windows or a screen saver timeout would totally kill the simulation.  The only way to keep it going was to start the simulation and then make sure to give the mouse a shake every few minutes.  If I was away for too long then hitting escape to stop the simulation would immediately bring up my blank screen saver letting me know it had died.

I could not find an answer or get much help with this and had to try and carry on without being able to run longer simulations then walk away or leave them overnight.  I had to be there at the desktop or nearby and keep an eye on the clock.

I was looking for a solution in the wrong places and wasting precious time too.  I assumed it was a Carrara SDK issue and that I was doing something wrong.  It was really only when I noticed that after running a big demanding render on multiple cores that upon returning to a word document, after leaving it open on the desktop untouched for an hour, that as I typed there was no response to my keystrokes.  After more than a few seconds I could start to type okay.

So I seem to have finally understood and hopefully fixed this problem.  Windows is deciding that despite it working hard and doing millions of calculations that my simulation is not important or not responding and then making it, or the system, idle after a certain time period.  Only by calling WINAPI SetThreadExecutionState(…) with the right flags, very frequently, in all of the simulation loops, can the plugin now be left to run on its own.

Simple Cloth Deformer

Once again I’m going to attempt to continue my work on a Cloth plugin for Carrara and release a new version.

I’ve been working on and off on this project for the last few years (mostly off)…

Where I left off in 2011 the released plugin worked with fast primitive draping and collisions.  These results were very reliable for a proxy figure covered with cylinders, spheres and capsules, also with floors, seats and stairs using scaled cubes and planes.  The problem was that the underlying primitive shapes would show through.

I had higher hopes for the Bullet Softbody physics simulator added to Carrara 8 but I’ve never been able to get any sort of reliable results from it to match my own amateurish attempt.  I also held out working on my own code for the release of a stable version of Carrara 8.5.

I picked up the project again in early 2013 and tried out lots of ideas but the best results started to come from testing the collision of thick vertices against facets.  I then realized that the flaw in this simple method was that too many face hits were occurring and that I needed to find the best surface collision.  It was at the corners or bumps, such as a knee, that things were obviously going wrong.

Cloth Simulation

Cloth Simulation

This simulation uses code that treats all of the possible detected collisions as though they were part of a convex surface.  The figure uses a DAZ Genesis character with the model’s subdivision level set to 0, which gives a low and manageable polygon count.

Animations were okay but rippled and twitched over the mesh surface where they would slide smoothly over a primitive volume.  Once I started to get results like the above for still images I was already exceeding my own demands, but I wanted to keep trying to push it just that bit further.