PDA

View Full Version : Quicker way to switch materials to mia_material?


techmage
06-26-2009, 10:47 AM
So I have a scene I am importing from another program to set up and render in maya. It has a bunch of materials that import as maya blinn. I need to switch all of these materials to mia_material_x_passes. My typical workflow for this is to select the maya blinn node, go to it's shading engine node, then drag the mia_material into the mental ray material, photon and shadow slot. Then connect up the textures through gamma correct nodes.

This can actually take a fair bit of time in scenes which can have a few dozen materials with textures. It's like 8-12 mouse clicks, with like 4-6 middle mouse drags per material.

I am just curious, is there any quicker way to do this? Anyone know of any script anywhere that might aid this? Or anything built into maya?

Hamburger
06-26-2009, 10:58 AM
Courtesy of Joojaa from Highend3D

proc connectAndSet(string $original,string $target){
$conn=`connectionInfo -sfd $original`;
if ($conn!=""){
connectAttr -force $conn $target;
} else {
connectAttr -force $original $target;
disconnectAttr $original $target;
}
}

proc convertPhongToMia(string $original){
$target=`mrCreateCustomNode -asShader "" mia_material`;
connectAndSet($original+".color",$target+".diffuse");
//... any other mapping you need comes here...

// a bit weak test should work for simple materials,
// not used in special context
$sg=`connectionInfo -dfs ($original+".outColor")`;
if ($sg[0]!=""){
$sgr=`match "[^.]*" ((string)$sg[0])`;
connectAttr -force ($target+".outValue") ($sgr+".miMaterialShader");
connectAttr -force ($target+".outValue") ($sgr+".miPhotonShader");
connectAttr -force ($target+".outValue") ($sgr+".miShadowShader");
}
delete $original;
rename $target $original;
}




for ($item in`ls -et phong`)
convertPhongToMia($item);

From memory this needs a little tweaking as this is from a Phong material to mia_material (not mia_material_x_passes) but just edit the script to work with Blinn to mia_material_x_passes. Its easy.

There is also one issue where the shaders turn green however it still renders great so I ignored this for one project.

However maybe someone on this site canhelp fix this script in that regard. But hope this is a good start.

chuckie7413
06-26-2009, 01:47 PM
very handy indeed.

Thanks

CGTalk Moderation
06-26-2009, 01:47 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.