Liquid Simulation with nParticles




Valid for: Maya 2009.
Tools used: nParticles and nCloth.
Goal: simulate a liquid with rigid objects and nCloth ones.



Global overview:

    In this tutorial we are going to see how to use and setup Maya nParticles for simulating a liquid. As for any other simulation in Maya the dynamics computations for nParticles are time dependant and need information from the previous frame to compute the current one. So it's important to use a "Play every frame" Playback Speed.
    Maya nParticles work exactly the same way as classical Maya Particles: there is an emitter and a flow of particles. The emitters attributes drive the emission part of the simulation (Speed, Rate, Direction, Spread ...) and the particles attributes drive the behavior and the aspect of the particles (Size, Type, Collisions, Lifespan, Dynamics, PPAttributes ...). As in the other dynamics simulation in Maya we can interfere and improve the simulation with fields like Air Turbulence Vortex.

    Now we can start the liquid simulation.

The liquid simulation:

Preparation step:
  • A polygonal cylinder (here we use those values: Radius=1.5 Height=7.5 Subdivisions height=5).
  • A polygonal plane with enough faces (30 for the both Subdivisions values).
  • A polygonal container for the liquid with a hole at the bottom so that the liquid is able to get out through this hole. You can do as you want to create this object but it's a good idea when you finish your mesh to apply on it "Mesh->Cleanup..." (check inside the options of this command "Faces with more than 4 sides") and to delete the history for this object. In the present case we just create a polygonal sphere, duplicate it, scale down the duplicated one a little bit, make a boolean substraction between the original one and the duplicated one, cut the top of the result with a new boolean substraction between our object and a cube, create the hole with a new substraction between our object and a cylinder for making the hole.
    When everything is ready you need to place all the objects correctly, the cylinder must be above the container and the polygonal plane must be under the container hole.

    Result:


nCloth:

    Now we need to setup the nCloth object (the polygonal plane) in order to have a good simulation.
  1. Select the plane and transform it in a nCloth object (menu nDynamics "nMesh->Create nCloth"). If after this you play the animation you will see that your plane is falling down. It's a normal behavior because nCloth objects are directly connected to a nucleus node which contains a gravity. However, we want the cCloth object to be attached to something.
  2. Create a polygon cube near each corner of the plane.
  3. For each corner of the plane:
    1. Select the group of 3 vertices defining the corner.
    2. Select the adjacent cube.
    3. Apply a "nConstraint->Point To Surface".
    4. On the following picture you can see the result of the "Point To Surface" on 3 corners of the plane (blue lines show the constraints). On the last corner you can see the selection status before applying the constraint.
  4. Now if you play the animation you can see that the plane still falls due to gravity, but is hung by the corners which are fixed. If you want, you can play the animation until the position is quite stable and tell Maya that this position is the initial one instead of the planar one. For this you just have to stop on the frame where the position is good, select the position and tell Maya this is the initial state ("nSolver->Initial State->Set From Current").
  5. If you want you can animate the position of the cubes, the nCloth will follow the movement.

nParticles:

    The setup of the scene is finished. The next step is to create the liquid. In this exemple we don't use any emitter for our particles. We create them at the beginning so that all the particles are alive at the beginning and their number is constant. Note that you could use the same process with an emitter too.
  1. Fill the cylinder with nParticles.
    1. Check "nParticles->Create nParticles->Water".
    2. Select the cylinder then "nParticles->Create nParticles->Fill Object".
    3. After this you can hide your polygonal cylinder you will not need it anymore.
    4. Instead of 2. and 3. if you want to use an emitter just create one with "nParticles->Create nParticles->Create Emitter". The continuation will be the same.
  2. Now you can see your nParticles, they must look like little blue balls. If you play the animation they will fall down and interact with the nCloth if it's on their path but not yet with the polygonal container. Select the container object and apply "nMesh->Create Passive Collider". If you replay the animation it must work now and you must see the fluid simulation. For this you need a quite long Timeline (around 240 frame is necessary to see correctly the simulation).
  3. You can now play with the attributes of the nParticles to improve the simulation even if it's quite good already. You can change the values inside "Collisions" "Dynamic properties" and "Liquid Simulation" and see the result by playing the animation.
    Result :
  4. At this point you may think "It is quite interesting but useless to have a simulation of a bunch of spheres which behave like a fluid but look like spheres". To change this:
    1. Select your nParticles and apply "Modify->Convert->nParticles to Polygons".
    2. Now you must see a mesh around the nParticles. Create a layer and put it inside so you will be able to easily hide it for speed playback purposes. To improve this mesh you have to play with the nParticles attributes in the zone "Output Mesh". Be careful with some of them like the "Mesh Smooth Iteration" which is quite heavy to compute.
  5. The last thing to do is to hide your nParticles (the best way is to create a layer and put them inside).

Result :

Final result with video :



video 1: simulation without the liquid mesh.
video 2: simulation with the liquid mesh which is quite blobby because of computation time constraints.


That's all folks !!!

Now you need to experiment to understand how to properly use the attributes.



Copyright © Olivier Dumas
Tutorial written by Olivier Dumas