Wind Simulation Script

                                                                                                                       by   Celu Ramasamy

 

 

 

 

  This MEL script is used to generate the wave motion found in wind( and also water to some extent). Any component that can be selected with the 'filterExpand' command in maya can be used in the simulation. Example: Lattice Points, Polygon Vertex, NURBS control points,etc..

    When I was developing the script, I couldn't find a way to get the individual position of the lattice points. So in order to work my way around this problem I implemented the script on a per frame basis. The last frame displacement for each point is stored in an array. In each frame, this displacement is used to reset the point to its original untransformed location before being displaced in the current frame.

I have incorporated the following observations about wind motion onto the basic sin wave motion in this script.

i) the distance between the waves keeps varying continuously. you have a phase where the waves are closer together followed by a phase where the waves are further apart from each other.

ii) when the waves are close together there is greater surface movement (windy phase) than when they are further apart (calm phase).

iii) the shape of the waves change slightly as they move through the field.

Apart from the wind motion every object seems to under go a slight random wobble motion. I have written another script to generate this random wobble. This script can be used along with the wind simulation script to produce very nice results. Note: Right now the random wobble script is in a crude form, It does not have any UI. So you might have to edit the script inorder to customize it. Ill try to put together an UI when I find time.

 

Here is the Random Wobble Script in it's current state.

 

 

Instructions for setting up the wind simulation script.

Although this script can be applied on any component that is selectable through the 'filterExpand' command. My primary purpose for developing this script was to do wind simulation on lattice points (by setting the wave direction appropriately even water surface can be simulated).

I'll take through the steps needed to setup the script for simulation.

i) Put the script into the scripts folder.

ii) In maya, go to window > Animation Editors > Expression Editor.

In the column named 'Expression', enter,

ctWindMain;

then hit the 'create' button to create an expression and then close the Expression editor. 

iii) Then initialize the script by entering the following two commands into the script editor.

source "ctWindMain";    (source the script)

ctWindUI;    (Function that starts the UI for this script)

iv) This command will start the window shown below,

Here Enter the selection mask for the type of component you want to work with. Look up the MEL command reference for the 'filterExpand' to find out the selection mask for various types of components that can be selected. Default Value 46 selects lattice points.

Then enter the number of layers of points you want to include in your simulation.

Then enter the count of number of horizontal and vertical points present in each layer.

It is best to go for equal number of horizontal and vertical points. In that case you don't need to worry about which is the horizontal axis and which is the vertical axis. If you cannot go for equal number of horizontal and vertical points then heres what maya takes as horizontal and vertical axis.

In an initial untransformed lattice,

If your point layers are stacked along the x axis, then y axis is the horizontal axis and z axis is the vertical axis.  

If your point layers are stacked along the z axis, then x axis is the horizontal axis and y axis is the vertical axis.  

If your point layers are stacked along the y axis, then x axis is the horizontal axis and z axis is the vertical axis.  

 

After entering all the values, hit the 'Initialize Simulation Values' button.

 

v) Next this window comes up,

Select all the points belonging to a single layer, enter the layer count for that particular layer in the 'Current Layer Count' text box. Then hit 'Add Points to Layer' to assign the points to that layer.

The layers are ordered as follows, the top most layer starts with a count of 0.The layer count increases as we move from the top most layer to the bottom most layer.

Once the points belonging to all the layers are added, then finally hit the begin simulation button.

 

vi) Finally the following window shows up,

 

Wave Direction: Gives the direction of wave displacement.

U range, V range: This value can be used to simulate one small portion of the entire UV range of 0 to 1.This is useful in incases where the entire wave field is  too big for maya to handle comfortably. In that case the wave field can be simulated and rendered in passes, one small portion at a time and then composited together later to form the entire wave field ranging from 0 to 1.

U range Scaling Factor, V range Scaling Factor: Scales the parametric domain of the waves.

Subsequent Layers Scaling Factor: Except for the top most layer, all the other layers have a scaling slider that basically takes the wave motion from the top most layer scales it by the corresponding scaling factor and applies it to that particular layer.

The rest of the controls are explained amply in the UI itself.

vii) Finally to see the wave motion, hit the play button in the time slider. You should see the selected points dancing in waves.

If at any point you want to restart the simulation, hit the 'reset all' button, this will take you back to step 4, from there you can re- initialize the entire simulation.

 

Click Here to Download the Wind Simulation Script

Feel free to use this script as long as you give me credit!.

 

© 2007  Celambarasan Ramasamy. All rights reserved.