This is a general question for anyone who has had to work around the following problem...
I have created a plugin DG node which accepts an input (inMesh) and generates an output (outMesh), both of type kMeshData. There's nothing particularly special about this bit.
The plugin uses the input mesh to generate a modified output mesh. Simple enough, right?
The problem comes along when I have to identify shader associations with polygons in the source mesh, and attempt to apply these shaders to the target mesh.
Generally, it is necessary to create a MFnMesh interface for the 'inMesh' attribute, through which you can access verts, polys etc. etc. This interface also provides access to shader associations via getConnectedShaders() or getConnectedSetsAndMembers(). Unfortunately, these functions fail miserably, without a good explanation.
I looked up the maya knowledge base, and it documents this as a 'limitation', which occurs when you create a MFnMesh from a raw kMeshData passed through a plug.
The documented 'workaround' is to create the MFnMesh object from the dag path to the mesh, or from an object of kMesh (or DAG shape node).
But there is no path information available from a kMeshData passed via a plug. In fact, there is no obvious way to get at any DAG information from kMeshData - not that it would make sense anyway.
So how exactly are you supposed to extract polygon/shader associations from an input mesh? What alternatives are there if I want to build a target mesh which has a different polygon count & sequence but I want to keep the materials? It's not just an edited version of the input mesh but a new mesh with fresh polygons (and therefore no shader associations).
MStatus myHomeBrewNode::compute(const MPlug& plug, MDataBlock& data)
// do we need to refresh target?
if (plug == m\_outMesh)
// get handle to input mesh attribute
MDataHandle handle = data.inputValue(m\_inMesh, &status);
return (MayaStatusFailure("myHomeBrewNode::compute: could not get handle to attribute", status));
// get object
MObject mobject = handle.asMesh();
// mobject.apiTypeStr() always returns "kMeshData"
MGlobal::displayInfo(MString("source object has typestr [") + MString(mobject.apiTypeStr()) + "]n" );
// MObject->MFnMesh (always succeeds)
MFnMesh inputMesh(mobject, &status);
return (MayaStatusFailure("myHomeBrewNode::compute: could not create MFnMesh for mesh MObject", status));
// access vertic (always succceeds)
status = inputMesh.getPoints(vertices);
return (MayaStatusFailure("myHomeBrewNode::compute: could not access point array for mesh", status));
// try to get at face/shader associations
status = inputMesh.getConnectedShaders(0, shaders, faceToShaderMap);
// this ALWAYS fails, returning the following error....
return (MayaStatusFailure("myHomeBrewNode::compute: could not access polygon/shader associations", status));
Any suggestions welcome,