Use ex­pres­sions to con­trol Par­ti­cles

shows how to use MEL and Python in Maya to give val­ues to Per Par­ti­cle at­tributes based on cod­ing

3D World - - CONTENTS - au­thor syaw­ish a rehman A mo­tion graph­ics and VFX artist from Pak­istan with nine years’ ex­pe­ri­ence, Syaw­ish loves mo­tion graph­ics and mak­ing video tu­to­ri­als. www.bit.ly/syaw­ish

Syaw­ish A Rehman shows how to use Maya to give val­ues to Per Par­ti­cle at­tributes based on cod­ing

in Maya, npar­ti­cles are one of the most pow­er­ful fea­tures in your tool­kit. Not only can you do amazing things with them, but you can also cre­ate ex­pres­sions to ma­nip­u­late every sin­gle par­ti­cle. You cre­ate an ex­pres­sion and Maya ac­tu­ally eval­u­ates on every frame what that ex­pres­sion dic­tates and ma­nip­u­lates each par­ti­cle ac­cord­ingly. The Maya ex­pres­sion sys­tem in it­self is very pow­er­ful, so the pos­si­bil­i­ties of what you can do with ex­pres­sions in Maya are lim­it­less.

In this tu­to­rial, we’ll cre­ate a sim­ple for­est scene us­ing npar­ti­cles and I’ll show how to use ex­pres­sions to make the for­est look ran­dom and re­al­is­tic, as well as how to cre­ate a field to con­trol any at­tribute of the par­ti­cles. For ex­am­ple, you can cre­ate a field to con­trol the scale of the trees, as we’ll do, and the trees in­side that field will be smaller or larger than the oth­ers depend­ing on what you write in the ex­pres­sions. We’ll be us­ing a field in this case be­cause it has a mag­ni­tude that can de­tect what par­ti­cles are be­ing in­flu­enced. You’ll learn the ba­sics of ma­nip­u­lat­ing any at­tribute of every sin­gle par­ti­cle in a par­ti­cle ar­ray us­ing ex­pres­sions. You’ll also learn where all the at­tributes are ac­tu­ally hid­den and how to ac­ti­vate them.

01 cre­ate an emit­ter

Se­lect the mesh you want to emit par­ti­cles from. Un­der the FX mod­ule in Maya, go to the npar­ti­cles menu. Click Cre­ate Emit­ter>emit from Ob­ject. In my case, I’ll be emit­ting par­ti­cles from a poly­plane. Once you’ve cre­ated the emit­ter, turn the Grav­ity and Speed to zero in the Nu­cleus node and the Emit­ter node re­spec­tively. Key the emis­sion rate to stop emit­ting.

02 pre­pare your ge­om­e­try

For this tu­to­rial, I’m go­ing to cre­ate a cou­ple of trees to use as in­stanc­ing ge­om­e­try to place with par­ti­cles over the poly­plane. If you want to fol­low what I’m do­ing, just go the Win­dows menu bar and un­der the Gen­eral Edi­tors sub­menu, find Visor. This con­tains many types of use­ful ob­jects. Un­der Trees, se­lect Cherry Tree and then draw it on your sur­face with a paint stroke. Af­ter­wards, sim­ply con­vert the mesh from paint stroke to poly­gons and com­bine the leaves and the trunk.

03 in­stanc­ing ge­om­e­try

First of all, delete the his­tory on your ge­om­e­try and freeze trans­for­ma­tions. Se­lect the in­stanc­ing ge­om­e­try first, in this case, the tree mesh, and then se­lect the npar­ti­cles node. Un­der the FX mod­ule> npar­ti­cles, find In­stancer and click it. Now, you should see all the par­ti­cles you had cre­ated re­placed with the Tree mesh that you had se­lected. All the copies of the tree mesh have the same at­tributes, so we have to add some ran­dom­ness.

04 ran­domis­ing ro­ta­tions

Un­der the npar­ti­cle node, go to the Ro­ta­tion tab and turn on Com­pute Ro­ta­tion. Go to the Per Par­ti­cle (Ar­ray) At­tributes tab, right-click the Ro­ta­tion PP field. Click Cre­ate Ex­pres­sion. We only want to add some ro­ta­tion in the Y axis. A sim­ple ex­pres­sion can be used. En­ter“np ar­ti­cle shape 1. ro­ta­tion pp =<<0, rand (0,360),0 >> ;” Check what your npar­ti­cle­shape node is named.

05 ADD a Field

Se­lect the npar­ti­cle node and un­der FX mod­ule, go to Fields/solvers. Cre­ate a Vol­ume Axis field. It’s set to push your par­ti­cles away from its cen­ter. Change that un­der Vol­ume Speed At­tributes>away from Cen­ter. Set to 0.01, which is nei­ther com­plete zero nor large enough to do some­thing. The shape of the vol­ume can be what­ever you want un­der Vol­ume Con­trol At­tributes tab.

06 ADD ra­diuspp

Un­der the npar­ti­cle node, find the Add Dy­namic At­tributes tab. Here you can ac­ti­vate at­tributes sim­i­lar to Ro­ta­tionpp. You should see three but­tons; Gen­eral, Opac­ity and Color. Click Gen­eral. A new win­dow opens with three tabs. Click the Par­ti­cles tab and find ra­diuspp from the list. Click OK. You’ve ac­ti­vated the at­tribute to set an ex­pres­sion to ma­nip­u­late the ra­dius of par­ti­cles.

07 con­nect Vol­ume Field to ra­diuspp

Right-click ra­diuspp field, click Run­time Ex­pres­sion before Dy­nam­ics to add an ex­pres­sion that will be eval­u­ated before sim­u­lat­ing a frame. Write “vec­tor $field =np ar­ti­cle shape 1. in­put force [0];” to cre­ate a new vec­tor vari­able and store the in­put­force of the npar­ti­cle. Add float “$field­mag = mag($field);” to cre­ate a float vari­able to store the mag­ni­tude of the vari­able just cre­ated.

08 off­set­ting Val­ues

Be­cause the Vol­ume Field’s force on the par­ti­cles had to be so low, we need to mul­ti­ple the field­mag vari­able with 100 to get a fair value of 1. Sim­ply add “$field­mag = $field­mag * 100;” This is only for your cal­cu­la­tion, and doesn’t have any­thing to do with the ac­tual par­ti­cles. They’re still only tak­ing 0.01 force from the Vol­ume Field. Now, add “float $news­cale = 1 - $field­mag;” to store what the new scale for the par­ti­cles will be.

09 condition For scale

Now we have to add a condition where Maya eval­u­ates if the par­ti­cles are in­side the Vol­ume Field and if it de­cides they are, to then scale them down ac­cord­ingly. Add“if ($ field mag!=0){n par­ti­cle shape 1. ra­dius pp =<< $new scale ,$ new scale ,$ new scale >>;} else{ np ar­ti­cle shape 1. ra­dius pp =<< 1, 1, 1 >>; }” This condition checks if the field­mag isn’t zero. If it isn’t, it will ap­ply the news­cale to all three axes of the par­ti­cles, oth­er­wise it keeps the scale at 1.

10 at­tach con­nec­tions

We have to tell Maya to get its val­ues from the ex­pres­sion we just cre­ated. To do that, Un­der In­stancer (Ge­om­e­try Re­place­ment) tab, check Al­low All Data Types. Find the option for Scale and set to Ra­diuspp. Un­der the sub-tab called Ro­ta­tion Option, set Ro­ta­tion to Ro­ta­tionpp. This will ap­ply ran­domi­sa­tion in the ro­ta­tion we cre­ated ear­lier. •

Newspapers in English

Newspapers from Australia

© PressReader. All rights reserved.