Discussion:
maya API - how to get surface shader name?
(too old to reply)
Maahes
2007-03-28 02:14:26 UTC
Permalink
Heya. I've just started writing a Maya exporter this week (so I'm a
total noob to Maya API and don't know any Mel script other than
loadPlugin and unloadPlugin) and I'm having trouble with something that
seems like it should be really simple.

I have a shaderEngine object and I'm trying to get the name of the
surface material object that is applied to it. (ie. the name that comes
up in the HyperShade window for each shader).

I've tried grabbing the surface Shader attribute but its name is
"surfaceShader"... so that was a dead end for me.

My code to this point looks like:


meshFn.getConnectedShaders(0, shaders, shaderPolygons);
for (u32 obj=0; obj<shaders.length(); obj++)
{
MObject shader = shaders[obj];
MFnSet shaderFn( shader, &status );
if (status == MS::kSuccess)
{
// so shaderFn is a shader engine node. (tested this earlier)
// how do I get the name of the material surface it is using?
// ???
}
}


Can anyone help, or point me to some resources that can help me.
I can't find anything in the Maya help that tells me where to go from here.
Maahes
2007-03-28 03:41:14 UTC
Permalink
Ok, I worked it out..
The code (with error checking removed for simplicity) looks like:



meshFn.getConnectedShaders(0, shaderArray, shaderPolygons);
for (u32 iShader=0; iShader < shaderArray.length(); iShader++)
{
// get the plug for SurfaceShader
MPlug shaderPlug = MFnDependencyNode( shaderArray[iShader]
).findPlug( "surfaceShader", &status );

// get the connections to this plug
MPlugArray aPlugs;
shaderPlug.connectedTo( aPlugs, true, false, &status );

// assume first connection is material. Is this a safe assumption??
MFnDependencyNode surfaceShader( aPlugs[0].node(), &status );

// MaterialName is surfaceShader.name().asChar()
}
Post by Maahes
Heya. I've just started writing a Maya exporter this week (so I'm a
total noob to Maya API and don't know any Mel script other than
loadPlugin and unloadPlugin) and I'm having trouble with something that
seems like it should be really simple.
I have a shaderEngine object and I'm trying to get the name of the
surface material object that is applied to it. (ie. the name that comes
up in the HyperShade window for each shader).
I've tried grabbing the surface Shader attribute but its name is
"surfaceShader"... so that was a dead end for me.
meshFn.getConnectedShaders(0, shaders, shaderPolygons);
for (u32 obj=0; obj<shaders.length(); obj++)
{
MObject shader = shaders[obj];
MFnSet shaderFn( shader, &status );
if (status == MS::kSuccess)
{
// so shaderFn is a shader engine node. (tested this earlier)
// how do I get the name of the material surface it is using?
// ???
}
}
Can anyone help, or point me to some resources that can help me.
I can't find anything in the Maya help that tells me where to go from here.
Loading...