Call for Submission
NAB 2012 Best of the Best Show Reel
Submit your work today!
Theme color:
  • 1/3
You are here: Homepage /  Blogs /  Duncan's Blog / Water using nCloth (part 1 of 2)
Water using nCloth (part 1 of 2)
Posted: Mar 05, 2007
Category: nCloth
Social Media:
Bookmark and Share
 
It is possible to use nCloth for water, taking advantage of its ability to accurately self collide thick vertices (spheres), in addition with the ability to collide with geometry and other cloth objects( including rigid cloth). Note that one problem with this method currently is that the water can be too damped (a bit like slush or pea soup), however it may work fine in many contexts. A hidden nCloth attribute "selfCollisionSoftness" can be used to help keep it from getting too viscous, and I will discuss the use of this later in the tutorial. Please keep in mind, however, that nCloth was designed for cloth and this tutorial is somewhat of a hack. In future nucleus will hopefully support a proper particle based water solution.



Prepackaged Water
If you want the simple and easy way of doing things, just import the following file into your scene:
nClothWater.ma (scroll to the bottom to download related material)

This creates a block of nCloth particles that you can simulate, cache and render. Open the particle shape node in the attribute editor and you will see info on how to use this (inside the notes section), as well as added attributes ( under "extra attributes") for controlling the look and resolution of the simulation.
If you scale the block along just one axis the resolution automatically adjusts to maintain a uniform particle density. It is best to render this is Mental ray with motion blur, but make sure to cache first if you want to see the motion blur. (the maya blobby render not only does not support motion blur on particles, but it also has some problems with the blobby threshold rendering) Note that to cache you need to select the nCloth shape node, not its transform, because there is no output mesh in this scene. If you wish to create constraints you can still do so by displaying the input mesh and selecting it for constraint uses.

Here is a simple workflow for a pouring glass filled with liquid that shows how one can use this cloth water file.

1. Load the water preset file nClothWater.ma.
You may need to playback and rewind once to see the correct particles as there is an initialization problem on load.
On the node "waterNClothShape" in the attribute editor there are several extra attributes for controlling the water as well as descriptions of them in the notes section. Set the resolution to detemine how detailed a solution you want.
Note that you can change the resolution(or number of particles) at any time, but if you have an initial state set then you will need to reset it. The particle density controls the amount the particles overlap. A value of 1.0 will have them just touching at the start frame. For water sometimes a value like 1.1 will keep the water from losing volume as it simulates, while values much larger will tend to result in the overall water volume increasing. Values less than 1 might be useful when simulating droplets like rain

2. Create a cylinder and scale it to the desired size of your glass. Select and delete the top face to make it open.
3. Select the cylinder and do MENU "nCloth: Create Passive"
On the nRigid node that was created turn OFF "Trapped Check" because that attribute pushes out based on the surface normal, and we are colliding with the inside of the glass, not only the outside. If you only wanted to collide with the inside then instead you could reverse normals on the glass and leave "trapped check" on. Note also that the pushout attribute looks at the normal, so it is important that you reverse the normals if you want to use that.
4. Scale the block of water to fit inside the glass. Also scale it up in y more to pour more water into the glass. Notice the way extra particles are added as you increase the y scale. When we playback the water should fall into the the glass.
5. Increase the collide thickness on the glass (nRigid1) so that the expanded blobby surface does no penetrate the glass. To do this first lets enable the attribute "blobbyScaleDisplay" (under waterNClothShape extra attributes).
This shows the maximum potential extent of the water, although it may be less depending on how many particles overlap and the blobby threshold setting. I also added a simple blinn water shader to the glass and increased the transparency to help better see the water during playback.
You can set the glass solver display to "collision thickness" then playback editing the thickness value to just push the water inward enough... about 0.07.Note that one could model and collide with a glass that has thickness, however one can model the thickness with this thickness attribute and insert a more realistic glass just for rendering, simulating on the simpler one.
5. Set the initial state of the cloth in order to have the glass start filled with water. In order to do this we temporarily need to first select the output cloth mesh and make it visible (other operations like creating a constraint will require this as well).
Do MENU "nCloth: Relax Initial State" setting the number of steps in the option box to about 50.
The water should drop down into the glass. If it doesn't make it the full way then repeat until it does. Optionally one could instead simply playback and then stop on a good frame and do "nCloth: Set Initial State". When done make the output cloth mesh invisible again because we don't want this to render.

6. Keyframe the motion of the glass. One can also play around with the simulation by doing MENU "nCloth: interactive playback" and transforming the glass object during playback ( set your slider frame range to a large value so the simulation does not stop too soon ).
7. Select waterNClothShape and do MENU "nCloth: nCache: Create New Cache" and then render the animation. Make sure you have specified your desired cache frame range. Also you must directly select the shape node "waterNClothShape" and not its parent transform. (or one could select the clothOutputMesh and make it temporarily visible again). It is generally best to cache the simulation first before rendering, especially if rendering with motion blur or on a render farm. Note that one must render with Mental Ray in order to get motion blur on particles. The mental ray blobby rendering is also generally better than with the Maya renderer.
You can edit the blobby attributes under the extra attributes of the waterNClothShape node. Here is an example of smoothing accomplished by increasing the blobby scale and threshold. Careful adjusting of the threshold can determine the size of lone droplets. Note that when the threshold is greater than 1 there will be only be water where particles overlap.
The file waterPlayground.ma shown at the top of this tutorial used a file similar to nClothWater.ma, although I've made a few modifications since then. Note how the various nCloth elements... the door flap, two floating objects and a suspended piece of cloth... interact with the cloth water. If the object has a greater mass than the water it will sink( the object at the top ), while lower mass objects float( the ball at the bottom ). Note that if you want to cache the simulation for this scene you need to select all the nCloth meshes in the scene, and the water cloth requires that the nCloth shape node be directly selected. Rendering was done in Mental Ray so that the particles had motion blur.

Warning: If you find that a file with nCloth no longer loads try removing the particle startup cache in you project/particles folder. Currently there is a bug where particle startup caches are saved for nCloth and nRigid nodes(on file save). The cache folders will have a name like nClothWater_startup, or nRigid1_startup and can be safely deleted as they are not used or needed. Also the 8.5 release has a bug where large nCloth or nRigid nodes leak memory and crash. Keeping these objects less than about 150 units in size will avoid this problem.

Part two of this tutorial will cover how the nClothWater file is setup and go in to more detailed examples.
The basic technique is to disable all edge and face relationships on the nCloth node, so that all that remains is point to point collision, then pipe the output of the nCloth into a particle system. We connect this output of the cloth into the particle system softbody mesh and goal mesh inputs. The particle system is used solely for its blobby particle rendering.
In order to post any comments, you must be logged in!
Newest users comments View All 8 Comments
Posted by ArtBerry on Sep 21, 2010 at 08:50 AM
Tell me please
What is node type of the waterNClothShape?
And where is "blobbyScaleDisplay"?
I can`t find it.
Thanks ))
Posted by awellss on Jan 27, 2009 at 04:34 AM
Hey All,

I'm having the following problem when attempting to run a simulation based on the one described in this tutorial: When the particle shape's bounding box intersects my ground plane the intersecting area shows up in the render. I've stripped down my scene to a point where it's identical to nClothWater2.ma except with an mib_amb_occlusion node connected to the ground plane's shader (mib_amb_occlusion.outValue -> lambert.transparency). I'm also rendering with my primary renderer set to "Rasterizer" in the mental ray globals, but scanline and raytracing give the same result. Any ideas?

Thnx,
Alex
Posted by Greg M on May 14, 2008 at 06:02 PM
Thank you! This is very useful! I'm using this method for a liquid simulation, but to make the splash a little more believable I'm trying to figure out a way to randomize the size of the ncloth particles. Do you know of a way to accomplish this?

[edit] No sooner do I post the question, than I figure out a way! For the benefit of others, I'll post what I did here.

Make sure blobby display is turned on, as mentioned above. You also may want to turn off the Solver Display on the waterNclothShape node. I couldn't figure out a way to randomize that, so for now I hid it and tried to pick a collision size that would accommodate all particle sizes. Then add a raidusPP attribute and add this line as a creation expression (which uses copied lines from the expression that's already there):

float $sx = waterNCloth.scaleX;
int $xres = (waterNClothShape.resolution+1)/2;
float $size = 0.25 * waterNClothShape.particleDensity * $sx/(float)$xres;
clothOutputParticleShape.radiusPP = rand(.01,.1) * $size * waterNClothShape.blobbyScale;

And that'll give you random particle sizes. It'll mess up the Blobby Scale attribute, but if you're using this for airborne liquid, that might be okay. I'm still learning, so any thoughts would be welcome!
Posted by learningmaya on Mar 22, 2008 at 08:17 PM
Thanks for your great tutorials Duncan! They are very helpful!

It states that this tutorial is Part 1 of 2. Does anyone know where Part 2 can be found?

Thank you!
Posted by Quillet on Nov 07, 2007 at 01:22 PM
hi !
thx u for your tutorial, but how i convert the Ncloth objet to Particles Blobby for to have a water effect
thx u for response :)
see u later