Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Using simple MEL expressions

From: Maya Particle Effects

Video: Using simple MEL expressions

In this section we are going to explore how to start writing some simple expressions. Now that you have created some Per Particle attributes, we have a place to put the expressions. The first thing that we're going to do is explore a way of writing an expression for color. And last time I had this arrayMapper out here and I want to break the Connection to that ramp that I had put in a color before. Now it's clean and I can right click on it again and go Creation Expression. When I do that, an Expression Editor pops right up.

Using simple MEL expressions

In this section we are going to explore how to start writing some simple expressions. Now that you have created some Per Particle attributes, we have a place to put the expressions. The first thing that we're going to do is explore a way of writing an expression for color. And last time I had this arrayMapper out here and I want to break the Connection to that ramp that I had put in a color before. Now it's clean and I can right click on it again and go Creation Expression. When I do that, an Expression Editor pops right up.

So when the Expression Editor pops up, I see that it is on rgbPP and Creation button has been selected because I am writing a Creation Expression, which means when the particles are born they are this color. My particles right now are already born. They are sitting there. So the first thing I do is I copy this, Selected Object and Attribute. I paste it down here, and I put an equal sign on it. And I am going to say = .3.

Okay. Colors in Maya have float values from 0 to 1 basically and I am going to go Create. Now let's see if we do a render of my particles, what color are they? They are all gray. Because this is influencing the red, the green, and the blue of the particles and it's making them all the same color, .3. If we go into the Color Chooser, for example, and I go into RGB, you'll see I have Red, Green, and Blue values here and you will see how those values take numbers.

So if I make each of them .3, you'll see I come up with the gray value. So I want to change my expression now. I don't want them all to come up the same color. I could make them like .7 or .2. And I can go Edit because I am changing the expression, so I have to hit Edit. Then I do a Quick Render and I get a different color of gray.

Let's say that I want to randomize the gray that these things are going to come out. I am going to go rand and rand is something that you are going to use a lot to make things random. And I am going to say I want the colors to be anywhere randomly chosen between like .2 and I am going to put a comma and 1 and close that in a parenthesis. Then I am going to hit Edit. That will change the expression. And I will rewind my particles back to beginning when they are sitting there.

And you will see now I have a variety of gray particles. They are all randomly coming out somewhere between .2 and 1 for the colors, the Red, Green, and Blue Per Particle. However, say I want to change my particles so with the Red, the Green, and the Blue are going to get different values. I can do what's called a vector expression instead. And to set up a vector expression, which is something that you'll be using a lot, I will just put two of these little arrow things here and then I am going to make my Red .3, I am going to make my White .1 and a comma after that and I'll make my Blue .7.

So this thing should look more blue than anything else I guess. And I am going to go Edit. I will take that space away there. Now let's do a Quick Render, I am going to rewind it. Put that down there and you see I have kind of blue-purple particles because they have been given different values. The Red, the Green, and the Blue have been given different values. Now say I want to randomize one of those values. So right within that expression, I say I want to randomize but the blue comes out. So right within this expression, I can put rand and enclose it once again the same way in these parentheses, .1, .7 and close it again in a parenthesis. The red is still going to be .3. The green is still going to be .1. But I am going randomize what color blue the particle is going to get. And I am going to go Edit again.

And always if you do it correctly, it will tell you down in the bar here, the Command bar, that you have been correct, Result particleShape1. So now once again I will do another render. I am going to just make sure I have saved this one out. Show you the difference. And you can see my particles are randomly colored differently because of that. Is that making sense? All right, so now that we have talked about some rudimentary ways to influence the color, I want to talk about influencing the opacity as well. So we right click in the Opacity slot there and go up, Creation Expression. And in the Expression Editor once again I have the opacityPP. I am going to take this here. You will see that I have my color expression there as well. Down here, Ctrl+V paste it down, equals, and so we'll once again we can do a next expression for opacity the same way that we did for color.

So I can say the opacity for this equals .2, enter semicolon, and go Edit. Now let's see what the opacity for these where they were, like that. When I do a new render now, and look, they are barely visible. The opacity is way down on these particles because I have made the opacity at .2. I can also randomize the opacity here as well. I can just go = rand (.1, let's do it all the way up to a full opaqueness, .1, 1. And I am going to go Edit.

I am changing that. And let's do another render and you will see it's randomized the opacity of these different particles right here. And I can do the same thing I have done with the rgbPP, per particle, I can randomize some of them and not randomize other ones of them too as well, because opacity will also have an rgbPP. So let's do that. I am going to take this almost the same way and just take this.

I am going to edit that, so my opacity is also been randomizing according to the Red, Green, and Blue channels of the particle. And I am going to push that down, hit that and do a Quick Render. And they are different than they were in the last one. The three channels have individually been changed, the Red channel has this opacity, the Green one has this opacity, and the Blue one has a randomized opacity of the different channels in these particles.

And so you can see how if you follow this basic template you can have fun playing with and tweaking the parameters for the color and the opacity.

Show transcript

This video is part of

Image for Maya Particle Effects
Maya Particle Effects

26 video lessons · 6864 viewers

Audri Phillips
Author

 

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Maya Particle Effects.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.