Showing posts with label scripting. Show all posts
Showing posts with label scripting. Show all posts

Sunday, May 20, 2012

How to use Mia material with Maya's ambient light pt2.

This is the follow-up of the post, How to use Mia material with Maya's ambient light.

The following mel script is to create a lambert material and connect it to all the existing mia_material_x_passes materials at one shot.

// create a Lambert material named ambPicker
string $ambPicker = `shadingNode -asShader lambert -name ambPicker`;
setAttr ($ambPicker +".color") -type double3 1 1 1;
setAttr ($ambPicker +".diffuse") 0;
setAttr ($ambPicker +".miFrameBufferWriteOperation") 0;

// make a connection between the ambPicker and the mia materials
string $mia_material[] = `ls -type "mia_material_x_passes"`;
for ($member in $mia_material ){
    int $connectivity = `isConnected ($ambPicker +".outColor")($member +".ao_ambient")`;
    if ($connectivity){
        print ($member +" is already connected to ambPicker.\n");
    }
    else{
    connectAttr -force($ambPicker +".outColor")($member +".ao_ambient");
    }
    setAttr ($member +".ao_on") 1;
    setAttr ($member +".ao_samples") 16;
    setAttr ($member +".ao_distance") 30;
    setAttr ($member +".ao_dark") -type double3 0 0 0 ;
   
}

You can simply delete the ambPicker material when it's not needed.

Friday, May 11, 2012

MEL: Maya file texture node initializing for Mental ray.


The default filter type in Maya's file texture node is set to Quadratic and this is not desireable for Menta ray since Mental ray uses Mipmap filter.
And the default filter value is set to 1.0 which is a little too high for most of the case.
So you need to manually tweak these settings for every single file texture node and that's tiresome.

Instead, I'd like to automate this process using a MEL script.
To make this possible, you need to execute two tasks.
One, select all the file texture nodes in the scene.
Two, for each of these selected file texture nodes, change attribute's values.

Here's the complete script.
This script switches the current Filter Type to Mipmap and set the Filter value to a modest value of 0.5.

/* select all the file texture nodes in the scene and put them in the string array*/
string $selected[] = `ls -type "file" -long`;
/* declare two strings for file node's filterType and filter */
string $filterType, $filter;
/* loop through all the file nodes */
for ($member in $selected) {
    /* get the current attributes */
    $filterType = `getAttr ($member+".filterType")`;
    $filter = `getAttr ($member+".filter")`;
    /* set new values for the attributes */
    setAttr ($member+".filterType") 1;
    setAttr ($member+".filter") .5;
}

Saturday, April 28, 2012

How to save a final gather map file for each frame


When you use the final gathering for animation, you'd probably have to refresh final gather map and rebuild it from scratch at every frame unless it's a camera fly-thru only animation.
In that case, you'd have to use very high settings for the final gathering and each frame would take a good amount of rendering time. What if you have re-render the entire sequence for some reason.
All the final gather maps that you previously calculated has been over-written and only the final gather map for the last frame remains. What a waste.
So, I'll show you a simple way to save all the final gather maps that are created during the rendering.

 
You can access and control the final gather map's name by the attribute called
"miDefaultOptions.finalGatherFilename"

You can simply set this attribute to a file name of your choice using setAttr command like below.
The filename goes between the parenthesis. 


setAttr -type "string" miDefaultOptions.finalGatherFilename ("FGmap_save."+`currentTime -q`+".fgmap");

Here, my scene file name is" FGmap_save.mb", so I typed "FGmap_save.".
You can use your scene file name or any name.
Each fgmap name will be unique by quoting the current frame number using `currentTime -q` command and appending that to the file name.


This one-line script goes to Pre render frame MEL slot under Render Options  in Common tab.


This mel script will be executed before every render begins at each frame.
Now you can find that for every test render,  the Primary Final Gather File name updates for the current frame.

Now render your sequence with FG rebuild option ON and your FGmaps will be saved for each and every frame. 

When you need to re-render any frames or the entire sequence, just switch the Rebuild option to Freeze and render again. The renderer will locate the corresponding saved FGmap for each frame.




This can be a big time saver especially when you find that you need to adjust the Point Interpolation attribute only after the sequence is once rendered.