Hi,
I would like to assign different shaders to group of faces of a mesh I have created. I followed Maya API How-To #08 How do I assign polygon objects (and individual face components) to a Shading Group? but when I try to use the AssignToShadingGroup function Maya returns this message:
"Cannot add the following items to the set since they would break the exclusivity constraint: myMesh.f[0:299]"
As mentioned in (MEL How-To #104 How do I assign an object or face component to a material?) this kind of error can be overcome in MEL by the -forceElement tag. Is there a way to fix this also via API? Why am I given this message? What am I doing wrong?
I have also tried to use this MGlobal::exectuteCommand call:
MString comando = "sets -e -forceElement blinn3SG"; but I got this result:
// Error: line 1: Connection not made: 'myMeshShape.instObjGroups[0]' -> 'initialShadingGroup.dagSetMembers[1]'. Connections cannot be modified during evaluation. //
// Error: line 1: Cannot add the following items to the set since they would break the exclusivity constraint: //
// Error: file: C:/AW/Maya7.0/scripts/others/timeSlider.mel line 40: Cannot add the following items to the set since they would break the exclusivity constraint: myMesh.f[0:299]
CODE
MItMeshPolygon pIt(existingMeshNodeDagPath);
MSelectionList selList;
selList.clear();
int indexPolygon =0;pIt.reset();
for (indexPolygon; !pIt.isDone(); pIt.next(),indexPolygon++ )
{
//here I am selecting the first 300 polygons
if(indexPolygon < 300 )stat = selList.add ( existingMeshNodeDagPath,
pIt.polygon() , true);
if(stat != MS::kSuccess)cerr << "\nFails to add polygon to shaderGroup \n";
}
indexPolygon++;
MGlobal::setActiveSelectionList ( selList, MGlobal::kReplaceList);
//MString comando = "sets -e -forceElement blinn3SG";
//MGlobal::executeCommand(comando);
indexPolygon = 0;
MItSelectionList iter(selList);
if(stat != MS::kSuccess)cerr << "\nFails to initialize Selection List \n";
MDagPath dagPathEl;
MObject component;
int lungh = selList.length();
for(; !iter.isDone(); iter.next())
{
iter.getDagPath(dagPathEl, component);
dagPathEl.extendToShape();
AssignToShadingGroup(m_oaOutMeshShadingGroup[0], dagPathEl, component);
}
using this function taken from Maya API How-To #08:
CODE
MStatus MShadingGroup::AssignToShadingGroup(
const MObject & shadingGroup,
const MDagPath & dagPath,
const MObject & component )
{
MStatus status;
MFnSet fnSG( shadingGroup, &status );
if ( fnSG.restriction() != MFnSet::kRenderableOnly )
return MS::kFailure;
status = fnSG.addMember( dagPath, component );
if ( status != MS::kSuccess )
{
cerr << " ! MShadingGroup::assignToShadingGroup could not add Dag/Component to SG ! " << endl;
}
return status;
}
If you can help me somehow I would be so happy cause at the moment I am really stuck on this thing.
Mikelem