PDA

View Full Version : for each in object type do yadda yadda


cgbeige
12-28-2010, 10:57 PM
I'm stuck on the best way to do this. What I want to do is take the selection and separate my selected VRaylights into one array/variable for processing and then split selected meshes with V-Ray light materials into another array/variable for running a separate processing batch. There are so many lsThroughFilter, ls -type, objectType things that I don't know where to start.

If this isn't clear, here's the code for the part I'm working on (in limbo since I started trying to incorporate the distinction between $meshLights[] and $allObjects[]). If you're wondering what it does, click on the VRay Tuner 2 teaser link in my sig - I have the light portion working fine but I've hit a wall now that I have to separate out the meshes with VRayLightMat materials. The procedure should do this:

1: take selection and separate meshes with VRay Light Mats (need some sort of error check here) into array, separate VRayLights into array.
2: store and then turn off the color multiplier value for each light mat in the array so that they don't add light to the render pass. This works but I don't know how to do this for an array.
3: do the same for the environment map. √This works already.
4: hide all the lights, then render out a separate image for the individual lights (for $each).√This works already.
5: hide the lights again and then render each VRay Light Material to another file.
6: do the environment map contribution pass (if any). √This works already.

I can't just hide the mesh light objects, since they need to occlude light for other passes. As it is, the script assumes you've selected only V-Ray lights and works fine.

global proc vray_light_layerrenderer()
{
string $allObjects[];
string $obj;
$allObjects = `ls -sl -transforms`;
//initialize vrayFileNamePrefix string
int $textFieldStatus = `textFieldGrp -ex -text -forceChangeCommand vrayFileNamePrefix`;
if ($textFieldStatus == 0)
{
unifiedRenderGlobalsWindow;
}
//
//Store Environment Map State
string $currentRenderName = `textFieldGrp -q -text -forceChangeCommand vrayFileNamePrefix`;
int $envMapState = `getAttr "vraySettings.cam_overrideEnvtex"`;
if ($envMapState == 1)
{
setAttr "vraySettings.cam_overrideEnvtex" 0;
}

//Zero MatLights for bulb-based passes
string $meshLights[] = `ls -sl`; //THIS MIGHT BE A PROBLEM SINCE IT MIGHT NOT BE SELECTED
string $shapes[] = `listRelatives -s $meshLights[0]`;
string $sGroup[] = `listSets -type 1 -o $shapes[0]`;
string $sGroupMat[] = `listConnections -d 0 -s 1 $sGroup[0]`;
float $currentLightMatValue = `getAttr ($sGroupMat[0] + ".colorMultiplier")`;

//
//for shapes in object type mesh
if ( `objectType $sGroupMat[0]` == "VRayLightMtl" )
{
setAttr ($sGroupMat[0] + ".colorMultiplier") 0;
}
// else
// {
// warning "you need to select meshes with a Vray Light Material attached.";
// }

//RedoPreviousRender;


//Start rendering out images for bulb-based lights sans material and env light contribution
for ( $obj in $allObjects )
{
hide $allObjects;
showHidden $obj;
textFieldGrp -e -text $obj -forceChangeCommand vrayFileNamePrefix;
RedoPreviousRender;
showHidden $allObjects;
}
//render environment map only contribution
if ($envMapState == 1)
{
setAttr "vraySettings.cam_overrideEnvtex" 1;
RedoPreviousRender;
hide $allObjects;
textFieldGrp -e -text "environment_render" -forceChangeCommand vrayFileNamePrefix;
}

//Render UnZeroed Mat Lights (hide everything else)
//SELECT ONLY MESHES HERE AND ENTER THEM INTO AN ARRAY
if ( `objectType $sGroupMat[0]` == "VRayLightMtl" )
{
setAttr ($sGroupMat[0] + ".colorMultiplier") $currentLightMatValue;
}
// else
// {
// warning "you need to select meshes with a Vray Light Material attached.";
// }

setAttr ($sGroupMat[0] + ".colorMultiplier") $currentLightMatValue;
hide $allObjects;
showHidden $obj;
textFieldGrp -e -text $obj -forceChangeCommand vrayFileNamePrefix;
RedoPreviousRender;
showHidden $allObjects;

RedoPreviousRender;


//restore starting state
showHidden $allObjects;
select -r $allObjects;
textFieldGrp -e -text "" -forceChangeCommand vrayFileNamePrefix;
textFieldGrp -e -text $currentRenderName -forceChangeCommand vrayFileNamePrefix;
setAttr ($sGroupMat[0] + ".colorMultiplier") $currentLightMatValue;


deleteUI -window unifiedRenderGlobalsWindow;

}
////END OF PER-LIGHT RENDER BATCHING////


The opening of the render globals window is necessary to kickstart the text field on the first run. Otherwise it will fail. If I don't respond, it's because I'm going to be on vacation from Wednesday morning for a week. Thx for any help in the meantime.

cgbeige
12-29-2010, 03:18 PM
Ok I found the basic size command and entered the object count for the loop operation but don't know how to find only meshes with VrayLightMat attached an enter those into an array

Joviex
12-29-2010, 08:04 PM
Ok I found the basic size command and entered the object count for the loop operation but don't know how to find only meshes with VrayLightMat attached an enter those into an array
I do not have Vray installed, so I have no clue what "type" a vrayLight? maybe inside of Maya world, however....

In MEL:


string $lights[] = `ls -sl -dag -leaf -typ "spotLight"`;

Will list all the "spotLight" types selected in the scene.

Obviously replace spotLight with the type you are looking for. You can use the type flag multiple times for multiple types.

E.g.:


string $lgts[] = `ls -sl -dag -leaf -typ "spotLight" -typ "pointLight" -typ "areaLight"`;

Having a look at the VRay docs for lights:

The VRayLight is a V-Ray specific light source plugin that can be used to create physically accurate area lights. There are four differnt types of VRayLight objects available for Maya.

They are: VRayLightSphere, VRayLightDome, VRayLightRect, VRayLightIES.

Those are also probably the nodeType names of the Vray lights.

If you need to check what those are, simply do the same `ls` cmd with the -st flag (showTypes):


string $lights[] = `ls -sl -dag -leaf -st`;


HTH

CGTalk Moderation
12-29-2010, 08:04 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.