Maya scripting 101 by Mauricio Ricaldi

One useful skill to learn in Maya is doing some basic script, it makes repetitive task easier.

Maya has two script languages to work, one is MEL that is the easier one for small tasks and short scripts, this is because you can copy/paste the command from the script editor. The other one is Python that is very similar to MEL, but you can build more complicated tools with it. But don't think MEL is less powerfull, a lot of tools I made was using mel first and then translated to pyhton, and some tools is works better in mel.

As example, we have this scene that have a x number of globes, and we need to select them several times for different tasks.

We open the script editor and make any change to the mesh:

copy/paste this to a MEL window below and it will select that object again.

We need to select all balloons at once, so we enclose the object in "quotes" and add * to any number that we find.

select -r "KJN*Anim_BD:KJN_JungleC_EXT_Auditorium_SD:KJN_BalloonA*:Balloon_Geo" ;

Now we have all selected, we can create a loop to change settings to all of them at once, we need first to store in a container called array, this will be $allObjs[]  and 'ls-sl' will fill the array with the selection.

string $allObjs[] = `ls-sl`;

The next thing is to do a loop, for this we add a variable called $x that will go to each object one by one till runs to the end of the selection that is defined by the size($allObjs).

for($x=0;$x<size($allObjs);$x++) {

As example I'm changing all the object to hold-out, the easier way is change one ballon and check the script editor.

check the last world that the attribute is called ".holdOut", so we need to do this to all the objects.

setAttr ($allObjs[$x] +".holdOut") 1;

setAttr is the command to change things in maya,  we add $allObj[$x] so $x will run from the first object to the last in a loop and then +".holdOut" 1 will change that attribute while looping.

At the end the entire script is:

select -r "KJN*Anim_BD:KJN_JungleC_EXT_Auditorium_SD:KJN_BalloonA*:Balloon_Geo" ;
string $allObjs[] = `ls-sl`;
for($x=0;$x<size($allObjs);$x++) {
 setAttr ($allObjs[$x] +".holdOut") 1;
}

You can change thie ".holdOut" with any other attribute like ".castsShadows", ".primaryVisibility", ".image" etc.


Vray Lights to render elements by Mauricio Ricaldi

Control lights is one of the most important thing to do when you light a scene, but also if you separate each light in a different pass or render element is very useful to comp it later and tweak anything without re-rendering all again.

To address this in Vray, we can render each light as separate pass, we need to create an render layer and add the lights and set, geometry, etc.

create a new render layer.

create a new render layer.

As example I have a simple scene that I added five lights.

To have more flexibility in comp I want all the lights in different passes and not all in one RGB like this render:

There is a manual way to do this, assigning each light to a render element and link it, but it takes a lot of time and if you have a bunch of scenes to light, the practical way is to do it with a script.

Phyton script is available at the end of the page :)

Phyton script is available at the end of the page :)

This small script will do the job, you need to place in the render layer (this example city_SET) and add all the lights, run the script, if you need the specular pass there is that option too. 

The script will create for each light a render element:

Now we render and will have all the passes:

From here we can comp in Nuke and add any light effect, color.

RGB render

RGB render

Using the light passes to give some mood and color to the scene .

This way we make candles, torches,  interiors and even characters, and have key lights, fill, rims, etc.. Is a better way to iluminate and has the flexibility to make changes in comp later.

Vray render elements documentation: https://docs.chaosgroup.com/display/VRAY3MAYA/Render+Elements

There is a tutorial for doing this in 3DsMax here.


Baking GI with Vray by Mauricio Ricaldi

One way to reduce to the minimum the noise in our renders is baking the GI.

When rendering environments with GI, ambient occlusion is very good idea to bake the GI specially if the camera is moving.

gi.JPG

There are certain things that don't work with this method, first if any object in your scene is animated will break the GI, making ghosting in your rendering. To solve this problem you can render those elements separated in a different layer and comp it later.

First in Maya we go to the environment layer, and enable GI, here are the basic settings:

Select the Engine as Irradiance map, also set the Mode to Incremental add to current map in Irradiance map and in Lightcache to Fly-through

We need to render a few frames where the camera is moving, think about doing a panoramic landscape but instead of photos we are photographing GI and stitching in one big file, so we can render different frames as example: if our range is 1-50, we can render each 10 frames, take all of them and save it as a GI that is called irradiance map. (if you are rendering using a farm or a network you need to save this file in an accessible place)

One tip: render the image as 100% or 50%, but not less than that, otherwise your Irradiance map will be useless.

To do this we can write a MEL script to automate the render of the GI.

float $lastFrame= `getAttr ("defaultRenderGlobals.endFrame")`;
int $frameskip = 10; // each 10 frames
int $loop = $lastFrame/(int)$frameskip;

for($x=1;$x<$loop+1;$x++) {
 
 $framerun = ((int)$frameskip*$x);
 currentTime -e $framerun; 
 RenderIntoNewWindow render;// render!!
 print ("Render Frame:"+$framerun+"\n");
 }

 

Irradiance map

Irradiance map

When all is render, we can check the irradiance map and see  if all the image is complete, is there any holes that the render didn't catch, is possible that the camera movement was to fast, the easier way is to go to that frame and render, it will add to the irradiance map automatically.

 

 

Finally we save both files, irradiance and ligthcache and set the Mode to load and locate the files, save the maya file, now you can render normally.  Remember if you are rendering into a farm, place this files where it can be loaded from the network.

Our environment layer is ready to render without any noise.

I coded a more advanced version of this tool for different TV shows, some need some tweaks here and there, if you are using render managers like Deadline you can send all the GI calculations to the farm too.

Current BakeGI tool for KJN

Current BakeGI tool for KJN


For more detailed information you can check Vray documentation: https://docs.chaosgroup.com/display/VRAY3MAYA/Render+Settings+%7C+GI+tab

and Irradiance documentation: https://docs.chaosgroup.com/display/VRAY3MAYA/Irradiance+Map+Settings