Beispiel #1
0
void findConnectedNodeTypes(uint nodeId, MObject thisObject, MObjectArray& connectedElements, MPlugArray& completeList, bool upstream)
{

	MGlobal::displayInfo(MString("thisNode: ") + getObjectName(thisObject));

	MString name = getObjectName(thisObject);

	MFnDependencyNode depFn(thisObject);
	if(depFn.typeId().id() == nodeId)
	{
		connectedElements.append(thisObject);
		MGlobal::displayInfo(MString("found object with correct id: ") + depFn.name());
		return;
	}

	bool downstream = !upstream;

	MPlugArray plugArray;
	depFn.getConnections(plugArray);

	int numc = plugArray.length();

	for( uint plugId = 0; plugId < plugArray.length(); plugId++)
	{
		MPlug plug = plugArray[plugId];
		if( isPlugInList(plug, completeList))
			continue;

		completeList.append(plug);

		MString pn = plug.name();
		if( upstream && plug.isDestination())
			continue;
		if( downstream && plug.isSource())
			continue;
		
		MPlugArray otherSidePlugs;
		bool asDest = plug.isDestination();
		bool asSrc = plug.isSource();
		MGlobal::displayInfo(MString("findConnectedNodeTypes: checking plug ") + plug.name());
		plug.connectedTo(otherSidePlugs, asDest, asSrc);
		for( uint cplugId = 0; cplugId < otherSidePlugs.length(); cplugId++)
		{
			findConnectedNodeTypes(nodeId, otherSidePlugs[cplugId].node(), connectedElements, completeList, upstream);
		}		
	}

}
MStatus lrutils::getMetaNodeConnection(MObject metaNodeObj, MObject & connectedObj, MString name) {
    MStatus status = MS::kFailure;
    MFnDependencyNode metaNodeFn( metaNodeObj );
    MPlug metaNodePlug = metaNodeFn.findPlug( name, true, &status );
    if( status != MS::kSuccess ) {
        return status;
    }
    //MyCheckStatusReturn(status, "MFnDependencyNode.findPlug() '"+name+"' failed");

    if (metaNodePlug.isSource()) {
        //follow the plug connection to the connected plug on the other object
        MPlugArray connectedPlugs;
        metaNodePlug.connectedTo(connectedPlugs,false,true,&status);
        MyCheckStatusReturn(status,"MPlug.connectedTo() failed");
        MPlug connectedPlug = connectedPlugs[0];

        //get the connected object
        connectedObj = connectedPlug.node(&status);
        MyCheckStatusReturn(status, "MPlug.node() failed");
        status = MS::kSuccess;
    }
    if (metaNodePlug.isDestination()) {
        MPlugArray connectedPlugs;
        metaNodePlug.connectedTo(connectedPlugs,true,false,&status);
        MyCheckStatusReturn(status,"MPlug.connectedTo() failed");
        MPlug connectedPlug = connectedPlugs[0];

        connectedObj = connectedPlug.node(&status);
        MyCheckStatusReturn(status, "MPlug.node() failed");
        status = MS::kSuccess;
    }

    return status;
}
Beispiel #3
0
void getConnectedNodes(MObject& thisObject, MObjectArray& nodeList)
{
	MFnDependencyNode depFn(thisObject);
	MPlugArray connectedPlugs;
	depFn.getConnections(connectedPlugs);
	int numConnections = connectedPlugs.length();
	
	for( int i = 0; i <  numConnections; i++)
	{
		// check for incoming connections only. Outgoing connections are not relevant
		MPlug plug = connectedPlugs[i];
		// an plug can be source AND destination at the same time, like the displacement attribute of a displacementShader
		if( plug.isSource() && !plug.isDestination())
			continue;
		MObject plugObject = getOtherSideNode(plug);
		if( plugObject != MObject::kNullObj)
			nodeList.append(plugObject);
	}
	//return (numConnections > 0);
}
Beispiel #4
0
bool ShadingNode::isOutPlugValid(MPlug plug)
{
	MPlug tmpPlug = plug;
	
	if (!tmpPlug.isSource())
		return false;

	while (tmpPlug.isChild())
		tmpPlug = tmpPlug.parent();

	// if we have an array, check the main plug
	if (tmpPlug.isElement())
		tmpPlug = tmpPlug.array();

	MString plugName = getAttributeNameFromPlug(tmpPlug);

	for (size_t attrId = 0; attrId < this->outputAttributes.size(); attrId++)
	{
		if (plugName == outputAttributes[attrId].name.c_str())
			return true;
	}
	return false;
}