Body Attractor Tutorial 
Written by Sergey Shlyaev 
Wednesday, 08 February 2012 10:34 
In this tutorial we’ll look into body attractor that shapes water into any form you want.
The idea of body attractor is the same as with point attractor. We compute custom channel that points from water particle to attraction point and use it as acceleration or force field.
The only difference is that we have lots of points and use their positions with body attractor.
For example, let’s shape water into famous Stanford bunny model. http://graphics.stanford.edu/data/3Dscanrep/ Download EMP file here: bunnyMesh.emp Download NI file here(basically just point attractor): body_attractor_start.ni For a detailed description of operators please read first part – Point Attractor Tutorial. Add EmpRead op to graph and load bunny model. Add MeshVolume op after EmpRead to convert poly model into volume. To use model’s vertices as attraction points we need world positions of them. So add Point.position channel into Channels field of MeshVolume op.
After we converted model into volume we need to export position field from it. Add FieldExport op after MeshVolume name it “FieldExportposition” and in ‘Field channel’ field write “position”.
Finally plug output of FieldExport into our “particle_nel_compute_fieldp_value” ParticeChannel op where we compute custom acceleration. Now graph looks like this:
We need to take into account this new field when computing custom acceleration. This is very easy, going from 0Particle.position[0] for point attractor to :'f'Particle.position[0] for body attractor. This is where all magic happens. Now our expression is like this:
If you run the sim now you’ll see that particles are definetely forming some part of the bunny but this is only part of it.
To form a whole bunny we need to spread water particles more evenly around the model, so they have different positions on bunny to land. To do this let’s add initial velocity to our liquid. Place FieldConstant op in graph, I’ve used <<0,1,0>> as initial velocity and plug it into ‘v’ input of LiquidEmitDistance op.
Now the sim looks like this:
Doesn’t shape very well. We need to increase attraction force. Add FieldScale after FieldParticleSplat and set scaling value. Something like 15 works well. Run the sim.
Now water ideally shapes into our model. Advantages of this setup:
Disadvantages:
That is all for our tutorial. Hope you enjoy it! Tips&Tricks
If using “Accumulate” splatting method instead of “Weighted Average” we may achieve more expressive effects. However in this case we may see some particles are being very fast and some of them may slideoff and water will lose shape of attractor model. To solve this we may reduce velocities that are higher than some threshold and introduce “Stopatattractor” option in our setup so particles that are very close to attraction point are moving significally slower then others or even stop. Velocity Cutting
Insert ParticleNelChannel op into graph after Force op. Name it “cut_high_velocities”. Set channel to velocity and type to vector. Say, we want all particles that are travelling faster then 100 meters per second to reduce their speed by half in each timestep. Put the following into expression field: (mag(.velocity) < 100) ? .velocity : .velocity*.5 This is the conditional expression. We check some condition and if it’s true we do one thing, if it’s not do another. First, we are checking how fast are our particles: mag(.velocity) < 100 if they are slower then 100 then leave velocity as is, otherwise multiply it by 0.5. Which is the same as divide by two, thus making velocity significally slower. This is for reducing velocities that are too big. StopatAttractor
To make liquid particles stop at attractor we will use distance field of our model and a NEL expression. Add FieldExport op and connect it to MeshVolume op that converts our bunny into volume. In ‘Field channel’ field write “distance”.
Insert ParticleNelChannel op after cuthighvelocities op. Name it “stop_at_attactor”. Plug exported distance field from bunny to ‘f’ input of ParticleNelChannel op.
Set channel to velocity and type to vector.
Let’s take a look at channel expression: :’f’<0.02 ? (.velocity[0]*.97) : .velocity[0] This reads: If value of connected field is less then 0.02 then multiply the X component of velocity of particle by 0.97, otherwise do not change it. Same stuff for Y and Z components of velocity vector. So, what does this mean: “value of connected field is less then 0.02”? Since we are using distance field, it means: “if we are closer than 0.02 meters (2 cm) to surface of our bunny”. Distance fields encode the distance to the surface. We have connected a distance field through the 'f' input, so its values corresponds to the distance to the closest point on the surface.
Please note, distance field is scalar field, not vector as velocity field. Now our operator will reduce velocities of those particles who are close to the surface of model. To make velocities decay faster make multiplier lower. For example using 0.1 instead of 0.97 will make them stop almost immediately.
Download NI file here: body_attractor.ni TileRefine opA good alternative to initial velocity is TileRefine op. It is useful to be sure that attraction field is defined over a whole attaction body instead of only some region in space where liquid particles currently are.
Insert TileRefine op right before particle_nel_compute_fieldp_value op so all parts of our model are considered in computation of custom_acceleraton vector.
Let’s take a look at first frame of our simulation:
On the left picture water body does not have tiles around bunny’s head and ears so they are not considered in attraction field at start of our simulation. On the right picture whole bunny including head and ears is attracting water. If we look at attraction field with StreamlineScope this is clearly seen:
On the right picture we see that attraction field is defined over a whole attaction body from the very beginning. This may be important when we have model with relatively thin jut out parts like Utah teapot with nose and handle. Take a look at teapot video: Download Video: MP4, HTML5 Video Player by VideoJS Notice very clean and organic waterflow. Homework:
Do your own experiment with your model! Try to use field as velocity field, not acceleration or force. There will be no physical correctness but you may get interesting results. Try to switch different attractor bodies in one sim. Like here:

Last Updated on Sunday, 18 March 2012 13:06 