Foam Cannon Rig


I was thinking about many solutions on how to achieve realistic soap suds in maya. The type of soap suds that you would find at a car wash or in one of those foam parties from back in the college days. The two things that interested me were the way foam interacts with itself and with its surrounding environment. If the foam was very wet, it would be heavy and change the course of other foam bubbles around it. If the foam consisted mainly of bubbles, then it might just rest on the surface of other foam bubbles. If the foam bubbles were created under water, millions of little bubbles would be generated around it to simulate the air needed to create the foam, thus creating some sort of ‘school of fish’ effect playing around the foam as it bubbles up to the surface.

What I love about Maya is that she gives us an incredibly large toolbox to play with, so the solutions to come up with this type of simulation is limitless and depend on creativity. I brainstormed a few ideas before starting in the direction I wanted to go. I weighed the options by coming up with the advantages and disadvantages of each practice. Thinking for example that an nCloth solution (however dynamic and intricate the detail) was pretty slow in calculation and tedious to create multiple instances of the object. I decided to use nParticles, mainly because it was fast, it can be Cached, it can be controlled on a PP basis, and the shapes and sizes of PP and groups of PP can by dynamically customized.


Custom Attributes

nParticles has a large list of attributes. Most of them can be set at a value, while others need to be changed dynamically, animated manually, or plugged in with other attributes to synchronize the traits. I’ve played with a few things and created custom attributes to the main ‘foamCannon_Ctrl’ curve. The list of custom attributes i’ve added for the simulation on surfaces are as follows:

World Scale – The value should be changed according to the scene size the foam will be simulated in.


Rate – Emission rate.


Velocity – The speed in which the particles will travel depending on the direction of the ‘foamCannon_Ctrl’ curve.


Splash – The randomness of the distance each particle will travel in comparison to its velocity.


Spread – The size of impact the foam clusters will make. This depends highly on the distance between the ‘foamCannon_Ctrl’ curve and the point of impact.


Min Size – The size of the smallest nParticle.


Max Size – The size of the largest nParticle.


Flow Pattern – The size of each particle will be multiplied by this number at birth. Creating a sine graph starting at 0 to 1 along some frames will create a pattern in emission size.


Rotation and Instancing

One of my favourite attributes that has just recently been added to the nParticle system is the rotation on a PP basis. In the past, I had to write a quick MEL script in the PP attributes to calculate its rotation based solely on its velocity. But now, you can simply check a box and a few attributes will be enabled for tweaking of the rotation. Very awesome.

Instancing, however, is still very primitive in my opinion. A very important aspect that is used almost every time is creating an array of instances, and randomizing the index to get variations in your instanced particles. Maybe I’ve missed this feature, but unfortunately, I have still been writing a quick randomize MEL on creation to get this feature working. Anyways, a quick plug in of a primitive cube with rotation and scale on the nParticles, and I was ready to start tweaking.


Creating Foam Balls (lol)

Aww, look at these little cuties.

As the name suggests, if I were to have instanced particles, then I had better create some foam balls to go with it. Very roughly, I created a few varients of foam balls that I could see working with my simulation. I took advantage of the interesting SamplerInfo node to create a falloff in transparency around the main core of the foam balls.


Under Water Simulation

Well, ultimately I needed to create these foam particles under water. So after unchecking a few boxes in the collisions tab and adjusting the gravity in the nucleus, I had a pretty good start. One thing that is definetly needed, is a field that would alter the course of each particle seperately. I remember a time when I was swimming at a pool with my friend and he told me to swim in a straight line and reach the other end of the pool. He said that he could alter my course by pushing under water slightly and changing the current. I took on his challenge and after swimming in a very straight line, I ended up a few meters away from where I should have been. Anyway, what I’m trying to get at is even the finest movement in the current can change the course of something. This is why there should be very tiny detail in each particles movement to convince the audience that this is real. Turbulence is very powerful. Until lately, I have been using this field a lot. Unfortunately, unless the dynamic objects are floating in space, turbulence is very limited to its magnitude. In space, objects cannot slow down unless it gets stopped by another force. If an object has a velocity of ‘0’, the turbulence will still affect it, causing it to move. What has helped is the Attinuation attribute, the Falloff attribute, and damping, or conserve attributes in the particle system, but this was still far from what should be.

When the Volume Axis Field was released, I had no idea what it was used for. It’s one of the most powerful fields you can use for realistic simulation. To my understanding, in this case, it will only alter the course of the nParticle as long as it has velocity to travel. Very awesome!

Another thing that will add to the level of detail are little tiny bubbles that build around the foam, mimicking the excess air that is generated when creating the foam. The number of these ‘child’ particles should depend on the size and rate of the ‘parent’ particles to get consistant feedback, so attach a few attributes with a little multiplier and that should do it. The two newly created attributes needed to control these ‘child’ particles are the following:

Child Rate Multiplier – The emission rate of the child particles multiplied by the emission rate of the parent particles.


Child Size – The size of the child particles.