PDA

View Full Version : Shader Proagate Across Instances


~NoMaD~
12-07-2007, 10:24 PM
Hey,

Before I spend a day making a script to do this, I wanted to know if anyone already knows of a way or script that duplicates the shaders of an instance object across to all the instances in a scene? This way, if something is changed (shader assignment) on one instance, it can be done to all other instances.

Thanks in advance!

Chris

~NoMaD~
12-09-2007, 07:34 PM
Ok, I guess what I really need to know... can anyone tell me how to return the shader assigned to a face? I have used hyperShade -smn, but that selects it in the hypershade, and if I do this for every face in a model, that will take hours. All I would need is the plug or name of the connection on the end of the plug.

Anyone have any suggestions?


Thanks in advance!

Chris

Norb
12-10-2007, 10:09 PM
Just how many faces are you doing this on? Surely there'd be an easier solution rather than running a script on a per face basis (which depending on scene size could be long no matter what)

This took my machine about 10 minutes to deal with on a model with 91000 faces..
(I commented out the print statement so it would go faster)


string $sasel[] = `ls -sl -fl`;
int $i;
for ($i=0;$i<size($sasel);$i++)
{
select -r $sasel[$i];
hyperShade -smn $sasel[$i];
clear $shaders;
string $shaders[] = `ls -sl -mat`;
print ("\nFace: " + $sasel[$i] +" --- Shader: " + $shaders[0]);
}

r4inm4ker
12-11-2007, 12:18 AM
can anyone tell me how to return the shader assigned to a face?
Chris


`sets -q blinn1SG`
this will return all shapes/faces connected to the Shading Group.

r4inm4ker
12-11-2007, 12:34 AM
Here is part of the codes i wrote to solve something similar to your problem.
In short, you need to scan all the Shading Groups connected to your instance(using `sets -q $SG`), and then applied all shaders to other transforms of that instance.


string $shapeRelatives[];
string $shapeName =`sphereShape`;
string $faceName =`sphere.f[1:20]`;
string $currSG = `blinn1SG`;

if(`gmatch $shapeName "*.f*"`)
{
string $tempArray[];
//get shape name
$tempArray = `listRelatives -p -f $shapeName`;
//get all transforms
$shapeRelatives = `listRelatives -ap -f $tempArray[0]`;

}
else
//get all transforms
$shapeRelatives = `listRelatives -ap -f $shapeName`;

string $tokens[];
int $numToken = tokenize($shapeName,".",$tokens);
string $faceNumber = $tokens[$numToken-1];
for($eachRelative in $shapeRelatives)
{
if(`gmatch $shapeName "*.f*"`)
{
$eachRelative = $eachRelative+"."+ $faceNumber;
}

else
{
string $tempArray[];
//get shape name
$tempArray = `listRelatives -c -f $eachRelative`;
$eachRelative = $tempArray[0];
}

if(!`strcmp $eachRelative ("|"+$shapeName)`)
continue;

string $tempLine = "sets -e -fe "+$currSG+" " +$eachRelative;
eval($tempLine);
}

CGTalk Moderation
12-11-2007, 12:34 AM
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.