当前位置导航:炫浪网>>网络学院>>图形图像>>MAYA教程

利用 randomly rotation 创造落叶(英文)

We will create some falling leaves with randomly rotation driven through expressions (don´t worry - some easy expressions!).


Create a simple nurbs-plane with patching of 3 in u and v.

Select the plane and turn it into an emitter (F4 -> particles -> Emit from object -> optionbox). To prepare the particles for moving downwards (-y), simply set the "Normal Speed" to something like -2. Set the rate to 10-20 and hit create. Play the animation some frames that you can see the particles. Now select the particles and add a gravity field with the settings magnitude=5 and attenuation=0. Now add a turbulence field with the settings magnitude=10 and attenuation=0. Depending on your scale you have to vary with these settings. The goal is that the particles should tumble around and fall slowly. You also have to experiment with the "conserve"-value of the particles. I found a 0.92 to be ok.



For this test, create a simple poly-leaf and let it instance the particles (to do that, just select the geometry (you don´t need to select the particles) and open the optionbox from the "Instancer"-command within the Particles-menu - the default-settings should be fine, just make sure that under "Particle Object to Instance" the right particles are selected - and finally hit create). Now the particles are replaced with the geometry.


Open up the attribute editor of the particle-shape and under the "Per Particle (Array) Attributes" add a "General"-dynamic attribute. Name it something like "rotPP", Data Type has to be "Vector", Attribute Type has to be "Per Particle (Array)". Hit ok.


In the "Per Particle (Array) Attributes" - folder you should now see the new attribute. Rightlick on it and add the following "Creation-expression":

particleShape1.rotPP = rand (0,360);

This just gives each particle a unique rotPP-value of 0 - 360.

Next, you need to create a runtime-expression to control this value over time. To do that - you don´t have to close the expression-editor - simply click on "runtime" in the expression-editor and add the following expression:

particleShape1.rotPP += 0.001;

The "+=" tells Maya to add a value of 0.001 each frame to the inital value given by the creation-expression.


Now we have to tell Maya to use that value "rotPP" for controlling the rotation of the particles. To do that go to the "instancer"-folder in the particle-shape node and in the Rotation-options set the Rotation to "rotPP" (the rotation-type you can leave at "none").

For testing the animation hit play. The leaves should tumble around and rotate randomly.


To control/stop the rotation when hitting a ground we have to edit the expression a little bit. First, create a second plane. Scale the plane up and place it a bit lower that it can serve as our ground. With that plane still selected, shift-select the particles and turn on "Make collide" (particles-menu) with the setting friction=0.8-1, depending on how fast you want to stop the leaves when hitting the
ground.



If you hit play, you can see that the particles stop at the ground but keep on rotating, which is not what we want. To edit that we have to take the velocity of the particle into account. Again, open the Attribute-Editor of the particle-shape node and edit the runtime-expression by right-clicking on the "rotPP"-field in the "Per particle (Array) Attributes". We´ll create a new variable that reads the velocity of each particle and divides that value by 2000:

float $vel = (particleShape1.velocity)/2000;

Now, instead of just adding a value of 0.001 to the rotPP-variable each frame, we´ll add the $vel-variable:

particleShape1.rotPP += $vel;

That´s it. When the particles hit the ground they should stop rotating (since velocity=0 -> $vel=0 and nothing is added to the rotPP value). Another good thing about the velocity is, because of the turbulence field and the conserve-setting there are moments where the leaves almost "stand still in the air", thus have only little velocity at that time and ... you guessed right, don´t rotate much - like in reality. On the other side, the faster they fall, the faster they rotate.
相关内容
赞助商链接