How to create a shadinggroup and assign to a polygon with maya C++ API
i have create a polygon wiht maya C++ api,but it just a transform and a mesh,it connect to a initialShadingGroup.
now i want to create a lambert,add it to the polygon, then create a new shadinggroup,add the lambert to the shadinggroup
i have know how to assign to a shadinggroup,but dont know how to create one and could check in maya.
http://ewertb.mayasound.com/api/api.008.php
here are some code of mine
MStatus status;
MFnDependencyNode fnPolySp;
MObject objPolySp = fnPolySp.create("polySphere");
MFnDagNode fnPolyTrans;
/*
If a parent is specified, the new node is parented to it,
and the new node is returned. If no parent is specified
and the new node is a transform, the new node is returned.
Otherwise, a transform created and the new node is automatically
parented to it. The returned object is the transform, not the new node.
*/
MObject objPolyTrans = fnPolyTrans.create("transform");
MFnDagNode fnPolyShape;
MObject objPolyShp = fnPolyShape.create("mesh", objPolyTrans);
MDGModifier dgMod;
MPlug srcPlug = fnPolySp.findPlug("output");
MPlug destPlug = fnPolyShape.findPlug("inMesh");
dgMod.connect(srcPlug, destPlug);
dgMod.doIt();
MFnDependencyNode sn;
MDagPath dagPath;
MObject component;
dagPath.getAPathTo(objPolyTrans);
MObject shadingnode = sn.create("lambert");
MFnSet fnSG(shadingnode, &status);
if (fnSG.restriction() != MFnSet::kRenderableOnly)
return MS::kFailure;
status = fnSG.addMember(dagPath, objPolyTrans);
if (status != MS::kSuccess)
{
cerr << " ! MShadingGroup::assignToShadingGroup could not add Dag/Component to SG ! " << endl;
}
setResult( "MayaPluginWizard1 command executed!\n" );
MGlobal::displayInfo("MayaPluginWizard1 command redoit!\n");
return MS::kSuccess;
the final,what i want just create a sphere with a new lambert material just like click the sphere in maya shelt.
i konw how to create by python script or mel or c++api use mel/python.
i just want to know how to do it just with c++ API
Thank you