如何使用Maya C ++ API创建阴影组并分配给多边形

时间:2019-06-13 11:33:09

标签: c++ maya

如何使用Maya C ++ API创建着色组并分配给多边形

我已经使用Maya C ++ API创建了一个多边形,但是它只是一个变换和一个网格,它连接到initialShadingGroup。

现在我要创建一个兰伯特,将其添加到多边形中,然后创建一个新的着色组,将兰伯特添加到着色组中

我知道如何分配一个着色组,但不知道如何创建一个着色组并可以检入Maya。

  

http://ewertb.mayasound.com/api/api.008.php

这是我的一些代码

    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;

最后,我只想用一种新的兰伯特材料创建一个球体 就像单击Maya Shelt中的球体一样。

我知道如何使用python / mel或c ++ api创建mel / python。

我只想知道如何使用c ++ API

谢谢

0 个答案:

没有答案