Script to Batch Convert Shaders to Renderman?

Script to Batch Convert Shaders to Renderman?

Anonymous
Not applicable
2,239 Views
1 Reply
Message 1 of 2

Script to Batch Convert Shaders to Renderman?

Anonymous
Not applicable

l've imported an FBX file into Maya and of course all of the shaders are Phong, obviously Renderman doesn't support Phong. Normally I would just go into Hypershade and do it manually, but are well over 300 hundred texture and shader nodes. So I was curious to know if there's a script available that could easily convert the Phong shaders to PxrSurface shaders? I know such a script exists to convert Phong shaders to Mia materials for Mental Ray. 

 

Here's the code, it works well, and I've tried editing it for Renderman's PxrSurface to no avial. I am a 100% novice in all forms of coding so any help would be much appreciated.

 

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);
0 Likes
2,240 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

I realize this post is from a couple years ago, but I had the same question and thought it might be helpful to add the code that I ended up using.

 

Modified the original from: https://forum.highend3d.com/t/batch-converting-materials/45302

to convert simple lambert materials to PxrSurface (color only, not sure what to add for texture, etc).

 

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 convertlambertToRenderman(string $original){
  $target=`shadingNode -asShader PxrSurface`;
  connectAndSet($original+".color",$target+".diffuseColor");
  //... any other mapping you need comes here...
 
  // a bit weak test should work for simple materials,
  // not used in special context  delete  $original;
  $sg=`connectionInfo -dfs ($original+".outColor")`;
  if ($sg[0]!=""){
    $sgr=`match "[^.]*" ((string)$sg[0])`;
    connectAttr -force ($target+".outColor") ($sgr+".surfaceShader");
  }
  if($original != "lambert1"){
    delete $original;
    rename $target $original;
  }
}

for ($item in`ls -et lambert`)
  convertlambertToRenderman($item);

 

 

0 Likes