void
VertexPolyColourCommand::CreateNodeOnMesh(MDagPath& dagPath, MObject& ourNode)
{
	MStatus status;

	MFnDependencyNode fnDependNode( dagPath.node() );
	MPlug plug_outMesh = fnDependNode.findPlug("outMesh");

	MDGModifier* modifier = new MDGModifier;

	// Create the node
	ourNode=modifier->createNode("RH_VCP_PolyColourNode", &status);
	if (status != MStatus::kSuccess)
		MGlobal::doErrorLogEntry("error");

	// Connect it
	MFnDependencyNode dn(ourNode, &status);
	if (status != MStatus::kSuccess)
		MGlobal::doErrorLogEntry("error");
	MString dnname = dn.name();
	MPlug plug_inMesh=dn.findPlug(PolyColourNode::m_inMesh,&status);
	MString plugName = plug_inMesh.name();
	if (status != MStatus::kSuccess)
		MGlobal::doErrorLogEntry("error");
	status=modifier->connect(plug_outMesh,plug_inMesh);
	if (status != MStatus::kSuccess)
		MGlobal::doErrorLogEntry("error");

	status=modifier->doIt();
	if (status != MStatus::kSuccess)
		MGlobal::doErrorLogEntry("error");

	if (m_isUndoable)
		m_undos.push_back(modifier);
	else
		delete modifier;
}
コード例 #2
0
ファイル: HesperisCmd.cpp プロジェクト: spinos/aphid
MStatus HesperisCmd::attachSelected(const Vector3F & offsetV)
{
	MGlobal::displayInfo(MString(" attach to grow mesh ") + m_growMeshName);
	MSelectionList selList;
    MGlobal::getActiveSelectionList(selList);
    
	MItSelectionList iter( selList );
	
	MDagPath apath;		
	iter.getDagPath( apath );
		
	MObject otrans = apath.node();
	if(!otrans.hasFn(MFn::kTransform)) {
		MGlobal::displayWarning("must select a transform/group to attach to grow mesh");
		return MS::kFailure;
	}
	
	ASearchHelper searcher;
	MDagPath meshGrp;
	if(!searcher.dagByFullName(m_growMeshName.asChar(), meshGrp)) {
		MGlobal::displayWarning(MString("cannot find grow mesh by name ")+m_growMeshName);
		return MS::kFailure;
	}
	MObject ogrow = meshGrp.node();
	if(!ogrow.hasFn(MFn::kTransform)) {
		MGlobal::displayWarning("-gm must be a transform/group");
		return MS::kFailure;
	}
	
	MStatus stat;
    MDGModifier modif;
	MDagModifier dmodif;
	MObject hestranslate = modif.createNode("hesperisTranslateNode", &stat);
	modif.doIt();
    
    if(hestranslate.isNull()) {
		MGlobal::displayWarning("cannot create hes translate node");
		return MS::kFailure;
	}
	
	MFnDependencyNode fhest(hestranslate);
	MFnDependencyNode fgrow(ogrow);
	
	modif.connect(fgrow.findPlug("boundingBoxMinX", true), fhest.findPlug("bBoxMinX", true));
	modif.connect(fgrow.findPlug("boundingBoxMinY", true), fhest.findPlug("bBoxMinY", true));
	modif.connect(fgrow.findPlug("boundingBoxMinZ", true), fhest.findPlug("bBoxMinZ", true));
	modif.connect(fgrow.findPlug("boundingBoxMaxX", true), fhest.findPlug("bBoxMaxX", true));
	modif.connect(fgrow.findPlug("boundingBoxMaxY", true), fhest.findPlug("bBoxMaxY", true));
	modif.connect(fgrow.findPlug("boundingBoxMaxZ", true), fhest.findPlug("bBoxMaxZ", true));
	
	MPlug psrcwpmat = fgrow.findPlug("parentMatrix", true, &stat);
	if(!stat) MGlobal::displayInfo("cannot find plug worldParentMatrix");
	modif.connect(psrcwpmat, fhest.findPlug("inParentMatrix", true));
	modif.doIt();
	
    MFnDependencyNode ftrans(otrans);

	dmodif.connect(fhest.findPlug("outTranslateX", true), ftrans.findPlug("translateX", true));
	dmodif.connect(fhest.findPlug("outTranslateY", true), ftrans.findPlug("translateY", true));
	dmodif.connect(fhest.findPlug("outTranslateZ", true), ftrans.findPlug("translateZ", true));
	stat = dmodif.doIt();
	if(!stat) MGlobal::displayInfo(MString("cannot make some connections to ")+ftrans.name());
    
    fhest.findPlug("offsetX").setValue((double)-offsetV.x);
    fhest.findPlug("offsetY").setValue((double)-offsetV.y);
    fhest.findPlug("offsetZ").setValue((double)-offsetV.z);
    return MS::kSuccess;
}
コード例 #3
0
ファイル: poseSpaceCmd.cpp プロジェクト: ahmidou/aphid
MString CBPoseSpaceCmd::cacheResult(const MPointArray& bindPoints, const MPointArray& posePoints, const MVectorArray& dx, const MVectorArray& dy, const MVectorArray& dz)
{
    MDGModifier modif;
    MObject opose = modif.createNode("sculptSpaceRecord");
    modif.doIt();

    unsigned count = dx.length();

    MVectorArray row0Array;
    row0Array.setLength(count);
    MVectorArray row1Array;
    row1Array.setLength(count);
    MVectorArray row2Array;
    row2Array.setLength(count);
    MVectorArray row3Array;
    row3Array.setLength(count);

    MVectorArray bndArray;
    bndArray.setLength(count);

    MVectorArray posArray;
    posArray.setLength(count);

    float m[4][4];

    for(unsigned i=0; i < count; i++) {
        m[0][0] = dx[i].x;
        m[0][1] = dx[i].y;
        m[0][2] = dx[i].z;
        m[0][3] = 0.f;
        m[1][0] = dy[i].x;
        m[1][1] = dy[i].y;
        m[1][2] = dy[i].z;
        m[1][3] = 0.f;
        m[2][0] = dz[i].x;
        m[2][1] = dz[i].y;
        m[2][2] = dz[i].z;
        m[2][3] = 0.f;
        m[3][0] = 0.f;
        m[3][1] = 0.f;
        m[3][2] = 0.f;
        m[3][3] = 1.f;

        MMatrix tm(m);
        tm = tm.inverse();

        tm.get(m);

        row0Array[i].x = m[0][0];
        row0Array[i].y = m[0][1];
        row0Array[i].z = m[0][2];
        row1Array[i].x = m[1][0];
        row1Array[i].y = m[1][1];
        row1Array[i].z = m[1][2];
        row2Array[i].x = m[2][0];
        row2Array[i].y = m[2][1];
        row2Array[i].z = m[2][2];
        row3Array[i].x = m[3][0];
        row3Array[i].y = m[3][1];
        row3Array[i].z = m[3][2];

        bndArray[i] = bindPoints[i];
        posArray[i] = posePoints[i];
    }

    MFnDependencyNode fposec(opose);

    MStatus stat;
    MPlug pspacerow0 = fposec.findPlug("poseSpaceRow0", false, &stat);
    MPlug pspacerow1 = fposec.findPlug("poseSpaceRow1", false, &stat);
    MPlug pspacerow2 = fposec.findPlug("poseSpaceRow2", false, &stat);
    MPlug pspacerow3 = fposec.findPlug("poseSpaceRow3", false, &stat);
    MPlug pbind = fposec.findPlug("bpnt", false, &stat);
    MPlug ppose = fposec.findPlug("ppnt", false, &stat);

    MFnVectorArrayData frow0;
    MObject orow0 = frow0.create(row0Array);
    pspacerow0.setMObject(orow0);

    MFnVectorArrayData frow1;
    MObject orow1 = frow1.create(row1Array);
    pspacerow1.setMObject(orow1);

    MFnVectorArrayData frow2;
    MObject orow2 = frow2.create(row2Array);
    pspacerow2.setMObject(orow2);

    MFnVectorArrayData frow3;
    MObject orow3 = frow3.create(row3Array);
    pspacerow3.setMObject(orow3);

    MFnVectorArrayData fbind;
    MObject obind = fbind.create(bndArray);
    pbind.setMObject(obind);

    MFnVectorArrayData fpose;
    MObject oposed = fpose.create(posArray);
    ppose.setMObject(oposed);

    return fposec.name();
}
コード例 #4
0
MObject GlobalComponent::loadComponent(MDGModifier & dgMod) {
    MStatus status = MS::kFailure;
    this->m_metaDataNode = dgMod.createNode( "MDGlobalNode", &status );
    MyCheckStatus(status, "createNode failed");

    MString metaNodeName = "MGN_";
    metaNodeName += this->m_rigName + "_";
    metaNodeName += this->m_pCompGuide->getName();
    dgMod.renameNode(this->m_metaDataNode, metaNodeName);

    MFnDependencyNode depMetaDataNodeFn(this->m_metaDataNode);
    status = dgMod.newPlugValueFloat( depMetaDataNodeFn.findPlug("version"), this->m_pCompGuide->getVersion() );
    MyCheckStatus(status, "newPlugValueFloat() failed");
    status = dgMod.newPlugValueString( depMetaDataNodeFn.findPlug("rigId"), this->m_pCompGuide->getRigId() );
    MyCheckStatus(status, "newPlugValueInt() failed");

    GlobalComponentGuidePtr globalGuide = boost::dynamic_pointer_cast<GlobalComponentGuide>(this->m_pCompGuide);
    MString ctlColor = globalGuide->getColor();
    MString ctlIcon = globalGuide->getIcon();

    status = MGlobal::executeCommand( "python(\"control = rig101().rig101WCGetByName('" + ctlIcon + "')\");" );
    status = MGlobal::executeCommand( "python(\"Utils.setControllerColor(control, '" + ctlColor + "')\");" );
    MCommandResult res;
    status = MGlobal::executeCommand( MString("python(\"control.fullPath()\");"), res );
    int resType = res.resultType();
    if( resType == MCommandResult::kString ) {
        MString sResult;
        res.getResult(sResult);
        MObject ctlObj;
        status = lrutils::getObjFromName(sResult, ctlObj);
        MyCheckStatus(status, "lrutils::getObjFromName() failed");

        MVectorArray ctlLocation = this->m_pCompGuide->getLocation(0);
        MFnTransform transformFn( ctlObj );
        lrutils::setLocation(ctlObj, ctlLocation, MFnTransform::MFnTransform(), false, false, true);

        MString ctlName = this->m_rigName + "_" + this->m_pCompGuide->getName() + "_CTL";
        dgMod.renameNode(ctlObj, ctlName);
        dgMod.doIt();

        //add the metaParent attribute to the controller
        MFnMessageAttribute mAttr;
        MObject transformAttr = mAttr.create("metaParent", "metaParent");
        transformFn.addAttribute(transformAttr);
        //connect the controller's metaParent to the MDGlobal node
        status = dgMod.connect( depMetaDataNodeFn.findPlug("controller"), transformFn.findPlug("metaParent") );

        MObject ctlGroupObj;
        lrutils::makeHomeNull(ctlObj, MFnTransform(), ctlGroupObj);
        lrutils::setLocation(ctlGroupObj, ctlLocation, MFnTransform::MFnTransform(), true, true, false);
        MFnTransform ctlGroupFn( ctlGroupObj );
        //add the metaParent attribute to the controller group
        ctlGroupFn.addAttribute(mAttr.create("metaParent", "metaParent"));
        //connect the controller group's metaParent to the MDGlobal node
        status = dgMod.connect( depMetaDataNodeFn.findPlug("controllerGroup"), ctlGroupFn.findPlug("metaParent") );
        MyCheckStatus(status, "connect failed"); 
        MObject metaRootObj;
        status = lrutils::getMetaRootByName(metaRootObj, this->m_rigName);
        MyCheckStatus(status, "lrutils::getMetaRootByName() failed");
        MObject rigCtlGroupObj;
        status = lrutils::getMetaNodeConnection(metaRootObj, rigCtlGroupObj, "ctlGroup");
        MyCheckStatus(status, "lrutils::getMetaNodeConnection() failed");
        MFnTransform rigCtlGroupFn( rigCtlGroupObj );
        rigCtlGroupFn.addChild( ctlGroupObj );

        //add controller to controller display layer
        MObject controlLayerObj;
        status = lrutils::getMetaNodeConnection(metaRootObj, controlLayerObj, "ctlLayer");
        MyCheckStatus(status, "lrutils::getMetaNodeConnection() failed");
        MFnDependencyNode controlLayerFn(controlLayerObj);
        MString controlLayerName = controlLayerFn.name();
        MGlobal::executeCommand("editDisplayLayerMembers -noRecurse "+controlLayerName+" "+rigCtlGroupFn.name()+";");
        //create parent constraints from the global controller to the rig group
        MObject rigRigGroupObj;
        status = lrutils::getMetaNodeConnection(metaRootObj, rigRigGroupObj, "rigGroup");
        MFnTransform rigRigGroupFn( rigRigGroupObj );
        MGlobal::executeCommand("parentConstraint -mo "+transformFn.name()+" "+rigRigGroupFn.name()+";", res);
        //connect the parent constraint object to the component's metadata node
        MStringArray sResults;
        res.getResult(sResults);
        status = lrutils::getObjFromName(sResults[0], this->m_rigParentConstraint);
        MyCheckStatus(status, "lrutils::getObjFromName() failed");
        MFnTransform rigParentConstraintFn( this->m_rigParentConstraint);
        rigParentConstraintFn.addAttribute(mAttr.create("metaParent", "metaParent"));
        status = dgMod.connect( depMetaDataNodeFn.findPlug("rigParentConstraint"), rigParentConstraintFn.findPlug("metaParent"));
        //create the scale constraint from the global controller to the rig group
        MGlobal::executeCommand("scaleConstraint -mo "+transformFn.name()+" "+rigRigGroupFn.name()+";", res);
        //connect the scale constraint object to the component's metadata node
        res.getResult(sResults);
        status = lrutils::getObjFromName(sResults[0], this->m_rigScaleConstraint);
        MyCheckStatus(status, "lrutils::getObjFromName() failed");
        MFnTransform rigScaleConstraintFn( this->m_rigScaleConstraint );
        rigScaleConstraintFn.addAttribute(mAttr.create("metaParent", "metaParent"));
        status = dgMod.connect( depMetaDataNodeFn.findPlug("rigScaleConstraint"), rigScaleConstraintFn.findPlug("metaParent"));
        //create scale constraint from the global controller to the noTransform group
        MObject rigNoTransformGroupObj;
        status = lrutils::getMetaNodeConnection(metaRootObj, rigNoTransformGroupObj, "noTransformGroup");
        MFnTransform rigNoTransformGroupFn( rigNoTransformGroupObj );
        MGlobal::executeCommand("scaleConstraint -mo "+transformFn.name()+" "+rigNoTransformGroupFn.name()+";", res);
        //connect the scale constraint object to the component's metadata node
        res.getResult(sResults);
        status = lrutils::getObjFromName(sResults[0], this->m_noTransformScaleConstraint);
        MyCheckStatus(status, "lrutils::getObjFromName() failed");
        MFnTransform noTransformScaleConstraintFn( this->m_noTransformScaleConstraint);
        noTransformScaleConstraintFn.addAttribute(mAttr.create("metaParent", "metaParent"));
        status = dgMod.connect( depMetaDataNodeFn.findPlug("noTransformScaleConstraint"), noTransformScaleConstraintFn.findPlug("metaParent"));
    }

    return this->m_metaDataNode;
}
コード例 #5
0
ファイル: main.cpp プロジェクト: amadlover/setupRGBShaders
MStatus setupRGBShaders::redoIt()
{
    int numLayers = meshObjs.length() / 3;

    if( numLayers == 0 && meshObjs.length() > 0 )
        numLayers++;

    if( meshObjs.length() % 3 > 0 && meshObjs.length() > 3 )
        numLayers++;

    for( int l = 0; l < numLayers; l++ ) {
        MStatus stat;

        MFnDependencyNode mrUserBufferFn( dgMod.createNode( "mentalrayUserBuffer", &stat ));
        dgDoIt();
        //MGlobal::executeCommand( MString( "connectAttr -f " ) + mrUserBufferFn.name() + ".message miDefaultOptions.frameBufferList[" + l + "]" );
        dgMod.commandToExecute( MString( "connectAttr -f " ) + mrUserBufferFn.name() + ".message miDefaultOptions.frameBufferList[" + l + "]" );
        dgDoIt();
        mrUserBufferFn.findPlug( "dataType" ).setValue( 5 );

        for( int i = 0; i < 3; i++ ) {
            if(( l * 3 + i ) > (int)meshObjs.length() - 1 ) break;

            MFnDependencyNode nkPassFn( dgMod.createNode( "nkPass" ));
            dgDoIt();
            MFnDependencyNode meshFn( meshObjs[ l * 3 + i ]);

            dgMod.commandToExecute( MString( "sets -renderable true -noSurfaceShader true -empty -name " ) + nkPassFn.name() + "SG" );
            dgDoIt();
            dgMod.commandToExecute( MString( "connectAttr -f " ) + nkPassFn.name() + ".outValue " + nkPassFn.name() + "SG.miMaterialShader" );
            dgDoIt();
            dgMod.commandToExecute( MString( "sets -e -forceElement ") + nkPassFn.name() + "SG " + meshFn.name());
            dgDoIt();

            /*MGlobal::executeCommand( MString( "sets -renderable true -noSurfaceShader true -empty -name " ) + nkPassFn.name() + "SG" );
            MGlobal::executeCommand( MString( "connectAttr -f " ) + nkPassFn.name() + ".outValue " + nkPassFn.name() + "SG.miMaterialShader" );
            MGlobal::executeCommand( MString( "sets -e -forceElement ") + nkPassFn.name() + "SG " + meshFn.name());*/

            nkPassFn.findPlug( "layerNumber" ).setValue( l );

            if( i == 0 )
                dgMod.commandToExecute( MString( "setAttr " ) + nkPassFn.name() + ".color -type double3 1 0 0" );
            //MGlobal::executeCommand( MString( "setAttr " ) + nkPassFn.name() + ".color -type double3 1 0 0" );

            if( i == 1 )
                dgMod.commandToExecute( MString( "setAttr " ) + nkPassFn.name() + ".color -type double3 0 1 0" );
            //MGlobal::executeCommand( MString( "setAttr " ) + nkPassFn.name() + ".color -type double3 0 1 0" );

            if( i == 2 )
                dgMod.commandToExecute( MString( "setAttr " ) + nkPassFn.name() + ".color -type double3 0 0 1" );
            //MGlobal::executeCommand( MString( "setAttr " ) + nkPassFn.name() + ".color -type double3 0 0 1" );

            dgDoIt();
        }
    }

    for( unsigned int c = 0; c < camObjs.length(); c++ ) {
        MFnDependencyNode mrOutputPass( dgMod.createNode( "mentalrayOutputPass" ));
        dgDoIt();
        MFnDependencyNode nkSaver( dgMod.createNode( "nkSaver" ));
        dgDoIt();
        dgMod.connect( nkSaver.findPlug( "outValue" ), mrOutputPass.findPlug( "outputShader" ));
        dgDoIt();

        MFnDependencyNode camFn( camObjs[c] );

        //MGlobal::executeCommand( MString( "connectAttr -f " ) + mrOutputPass.name() + ".message " + camFn.name() + ".miOutputShaderList[0]" );
        dgMod.commandToExecute( MString( "connectAttr -f " ) + mrOutputPass.name() + ".message " + camFn.name() + ".miOutputShaderList[0]" );
        dgDoIt();

        nkSaver.findPlug( "numLayers" ).setValue( numLayers );
        nkSaver.findPlug( "camName" ).setValue( camFn.name() );
        nkSaver.findPlug( "fileName" ).setValue( fileName );
        nkSaver.findPlug( "folderPath" ).setValue( folderPath );
        mrOutputPass.findPlug( "datatype" ).setValue( 5 );
    }

    setResult( "Shaders setup to Render" );

    return MS::kSuccess;
}
コード例 #6
0
ファイル: polyExtract.cpp プロジェクト: AlbertR/cgru170
bool tm_polyExtract::extractFaces_Func( MSelectionList &selectionList, MStringArray &node_names)
{
	MStatus status;
	MObject meshObj;
	status = selectionList.getDependNode( 0, meshObj);
	if(!status){MGlobal::displayError("tm_polyExtract::extractFaces_Func:   Can't find object !");return false;}
	MFnMesh meshFn( meshObj, &status);
	if(!status){MGlobal::displayError("tm_polyExtract::extractFaces_Func:   Non mesh object founded !");return false;}

	MDagPath meshDagPath_first, meshDagPath;
	selectionList.getDagPath( 0, meshDagPath_first);
	MObject multiFaceComponent;
	MIntArray inputFacesArray;
	inputFacesArray.clear();
	inputFacesArray.setSizeIncrement( 4096);
	MFnComponentListData compListFn;
	compListFn.create();
	for (MItSelectionList faceComponentIter(selectionList, MFn::kMeshPolygonComponent); !faceComponentIter.isDone(); faceComponentIter.next())
	{
		faceComponentIter.getDagPath(meshDagPath, multiFaceComponent);
		if(!(meshDagPath_first == meshDagPath))
		{
			MGlobal::displayError("tm_polyExtract::extractFaces_Func:   Different meshes faces founded !");
			return false;
		}
		if (!multiFaceComponent.isNull())
		{
			for (MItMeshPolygon faceIter(meshDagPath, multiFaceComponent); !faceIter.isDone(); faceIter.next())
			{
				int faceIndex = faceIter.index();
#ifdef _DEBUG
				infoMStr += faceIndex;
				infoMStr += " ";
#endif
				inputFacesArray.append( faceIndex);
				compListFn.add( multiFaceComponent );
			}
		}
	}
	if( inputFacesArray.length() == 0)
	{
		MGlobal::displayError("tm_polyExtract::extractFaces_Func:   No faces founded !");
		return false;
	}
#ifdef _DEBUG
	MGlobal::displayInfo( infoMStr);
#endif

	meshFn.setObject( meshDagPath_first);
	meshObj = meshFn.object();

//	MDagModifier dagModifier;
	MFnDagNode meshDagNodeFn;
	MFnDependencyNode depNodeFn;
	meshDagNodeFn.setObject( meshDagPath_first);
	MString meshName = meshDagNodeFn.name();
	MObject outMesh_attrObject = meshDagNodeFn.attribute( "outMesh");

// ----------------------------------- duplicate shape

	MObject duplicated_meshObjectA;
	MObject duplicated_meshObjectB;
	MObject inMesh_attrObjectA;
	MObject inMesh_attrObjectB;
/*
	MStringArray commandResult;
	MSelectionList selList;

	MGlobal::executeCommand( "duplicate " + meshDagNodeFn.name(), commandResult, 1, 1);
	selList.add( commandResult[0]);
	selList.getDependNode( 0, duplicated_meshObjectA);
	meshDagNodeFn.setObject( duplicated_meshObjectA);
	meshDagNodeFn.setName( meshName + "_tA");
	duplicated_meshObjectA = meshDagNodeFn.child(0);
	meshDagNodeFn.setObject( duplicated_meshObjectA);
	meshDagNodeFn.setName( meshName + "_sA");
	inMesh_attrObjectA = meshDagNodeFn.attribute( "inMesh");

	meshDagNodeFn.setObject( meshDagPath_first);
	selList.clear();

	MGlobal::executeCommand( "duplicate " + meshDagNodeFn.name(), commandResult, 1, 1);
	selList.add( commandResult[0]);
	selList.getDependNode( 0, duplicated_meshObjectB);
	meshDagNodeFn.setObject( duplicated_meshObjectB);
	meshDagNodeFn.setName( meshName + "_tB");
	duplicated_meshObjectB = meshDagNodeFn.child(0);
	meshDagNodeFn.setObject( duplicated_meshObjectB);
	meshDagNodeFn.setName( meshName + "_sB");
	inMesh_attrObjectB = meshDagNodeFn.attribute( "inMesh");
*/
	duplicated_meshObjectA = meshDagNodeFn.duplicate();
	meshDagNodeFn.setObject( duplicated_meshObjectA);
	meshDagNodeFn.setName( meshName + "_tA");
	duplicated_meshObjectA = meshDagNodeFn.child(0);
	meshDagNodeFn.setObject( duplicated_meshObjectA);
	meshDagNodeFn.setName( meshName + "_sA");
	inMesh_attrObjectA = meshDagNodeFn.attribute( "inMesh");

	meshDagNodeFn.setObject( meshDagPath_first);

	duplicated_meshObjectB = meshDagNodeFn.duplicate();
	meshDagNodeFn.setObject( duplicated_meshObjectB);
	meshDagNodeFn.setName( meshName + "_tB");
	duplicated_meshObjectB = meshDagNodeFn.child(0);
	meshDagNodeFn.setObject( duplicated_meshObjectB);
	meshDagNodeFn.setName( meshName + "_sB");
	inMesh_attrObjectB = meshDagNodeFn.attribute( "inMesh");

// ----------------------------------- create node deleteComponent

	MDGModifier dgModifier;

	MObject deleteComponent_nodeObjectA = dgModifier.createNode( MString("deleteComponent"));
	depNodeFn.setObject( deleteComponent_nodeObjectA );
	MObject deleteComponent_attrObjectA( depNodeFn.attribute( "deleteComponents" ));
	MObject inputGeometry_attrObjectA( depNodeFn.attribute( "inputGeometry" ));
	MObject outputGeometry_attrObjectA( depNodeFn.attribute( "outputGeometry" ));
	dgModifier.doIt();
	depNodeFn.setName( "dfA_" + meshName);
	node_names.append( depNodeFn.name());

	MObject deleteComponent_nodeObjectB = dgModifier.createNode( MString("deleteComponent"));
	depNodeFn.setObject( deleteComponent_nodeObjectB );
	MObject deleteComponent_attrObjectB( depNodeFn.attribute( "deleteComponents" ));
	MObject inputGeometry_attrObjectB( depNodeFn.attribute( "inputGeometry" ));
	MObject outputGeometry_attrObjectB( depNodeFn.attribute( "outputGeometry" ));
	dgModifier.doIt();
	depNodeFn.setName( "dfB_" + meshName);
	node_names.append( depNodeFn.name());

// ----------------------------------- set attribute deleteComponent.deleteComponents

	MObject componentList_object = compListFn.object();

	MPlug deleteComponents_plugA( deleteComponent_nodeObjectA, deleteComponent_attrObjectA );
	status = deleteComponents_plugA.setValue( componentList_object );

	MIntArray invertedFaces;
	int numPolygons = meshFn.numPolygons();
	invertedFaces.setLength( numPolygons - inputFacesArray.length());
	int selFace = 0;
	int invFace = 0;
	for( int f = 0; f < numPolygons; f++)
	{
		if( f == inputFacesArray[selFace])
			selFace++;
		else
			invertedFaces[invFace++] = f;
	}
	MFnSingleIndexedComponent singleIndexedComponentFn( meshObj);
	singleIndexedComponentFn.create( MFn::kMeshPolygonComponent);
	singleIndexedComponentFn.addElements( invertedFaces);
	compListFn.clear();
	compListFn.create();
   componentList_object = singleIndexedComponentFn.object();
	compListFn.add( componentList_object);
	componentList_object = compListFn.object();
	MPlug deleteComponents_plugB( deleteComponent_nodeObjectB, deleteComponent_attrObjectB );
	status = deleteComponents_plugB.setValue( componentList_object );

// ------------------------------------- connecting plugs
/**/
	dgModifier.connect(
			meshObj, outMesh_attrObject,
			deleteComponent_nodeObjectA, inputGeometry_attrObjectA
		);
	dgModifier.connect(
			deleteComponent_nodeObjectA, outputGeometry_attrObjectA,
			duplicated_meshObjectA, inMesh_attrObjectA
		);

	dgModifier.connect(
			meshObj, outMesh_attrObject,
			deleteComponent_nodeObjectB, inputGeometry_attrObjectB
		);
	dgModifier.connect(
			deleteComponent_nodeObjectB, outputGeometry_attrObjectB,
			duplicated_meshObjectB, inMesh_attrObjectB
		);

	dgModifier.doIt();

// ---------------------------------- assigning shading group
/**/
	meshDagNodeFn.setObject( meshDagPath_first);
	MObject instObjGroups_attrObject = meshDagNodeFn.attribute( "instObjGroups");
	MPlug instObjGroups_plug( meshObj, instObjGroups_attrObject);
	instObjGroups_plug = instObjGroups_plug.elementByPhysicalIndex(0);
	MPlugArray instObjGroups_plug_connectionsArray;
	instObjGroups_plug.connectedTo( instObjGroups_plug_connectionsArray, false, true);
	if( instObjGroups_plug_connectionsArray.length() > 0)
	{
		MPlug dagSetMembers_plug = instObjGroups_plug_connectionsArray[0];
		MObject shadingSetNode_object = dagSetMembers_plug.node();
		MFnSet setFn( shadingSetNode_object);
		setFn.addMember( duplicated_meshObjectA);
		setFn.addMember( duplicated_meshObjectB);
//depNodeFn.setObject(shadingSetNode_object);
//MGlobal::displayInfo( depNodeFn.name());
	}

// ------------------------------------------------------------
	return true;
}
コード例 #7
0
MStatus testGlassCmd::doIt(const MArgList &args)
{
	MStatus stat=MStatus::kSuccess;

	MSelectionList list;
	MFnDependencyNode meshDependFn;
	MFnDependencyNode materialDependFn;
	MDGModifier dgMod;

	//create a new material node, here is the test glass node
	MObject testGNode=dgMod.createNode(testGlassNode::id);
	materialDependFn.setObject(testGNode);
	MString testName=materialDependFn.name();
	MGlobal::displayInfo(testName+" god, please give me the node first time");


	//find the mesh node(s) from selected object(s)
	//create a new "yafaray material" attribute if the mesh node(s) dont have
	//then conect the material node to the mesh node(s)
	MGlobal::getActiveSelectionList( list );
	MItSelectionList iter( list, MFn::kMesh );
	for( ; !iter.isDone(); iter.next())
	{
		MObject meshDependNode;
		MFnNumericAttribute numAttr;
		

		iter.getDependNode( meshDependNode );
		meshDependFn.setObject( meshDependNode );
		//MString dependName=dependFn.name();
		//MGlobal::displayInfo(dependName+" is here\n");

		if( !meshDependFn.hasAttribute("YafarayMaterial") )
		{
			MObject attrYafarayMaterial=numAttr.create("YafarayMaterial","yama",MFnNumericData::kBoolean);
			numAttr.setDefault( true );
			numAttr.setStorable( true );
			meshDependFn.addAttribute(attrYafarayMaterial,MFnDependencyNode::kLocalDynamicAttr);
		}

        //find the source plug and the result plug, then connect them
		//if the result plug as  already had a sourse plug connected to it, disconnect first
		MPlug glassPlug=materialDependFn.findPlug("OutGlass");
		MPlug meshPlug=meshDependFn.findPlug("YafarayMaterial");

		MPlugArray srcMeshPlug;		
		if(meshPlug.connectedTo(srcMeshPlug, true, false))
		{
			MPlug srcPlug;
			//if(srcMeshPlug.length!=0) 
			//{
				srcPlug=srcMeshPlug[0];
			//}

			dgMod.disconnect(srcPlug, meshPlug);
		}

		dgMod.connect(glassPlug,meshPlug);

	}



	dgMod.doIt();
	//why still cant got the name here?
	MGlobal::displayInfo(testName+" god, please give me the node second time");
	
	return stat;
}