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 #2
0
MObject getOtherSideSourceNode(MString& plugName, MObject& thisObject, bool checkChildren, MString& outPlugName)
{
	MStatus stat;
	MObject result = MObject::kNullObj;
	MFnDependencyNode depFn(thisObject, &stat);	if (stat != MStatus::kSuccess) return result;
	MPlugArray pa;
	depFn.getConnections(pa);
	MPlug connectedPlug;
	for (uint pId = 0; pId < pa.length(); pId++)
	{
		MPlug plug = pa[pId];
		if (!plug.isDestination())
			continue;
		while (plug.isChild())
		{
			plug = plug.parent();
		}
		if (getAttributeNameFromPlug(plug) == plugName)
		{
			connectedPlug = pa[pId];
		}
	}
	if (connectedPlug.isNull())
		return result;
	connectedPlug.connectedTo(pa, true, false, &stat); if (stat != MStatus::kSuccess) return result;
	if (pa.length() == 0)
		return result;
	MPlug otherSidePlug = pa[0];
	result = otherSidePlug.node();
	outPlugName = getAttributeNameFromPlug(otherSidePlug);
	if (otherSidePlug.isChild())
		outPlugName = getAttributeNameFromPlug(otherSidePlug.parent());
	return result;
}
Beispiel #3
0
	//	get DagPath from connected node
	//
	MDagPath getConnectNodeDagPath( MObject& inObject )
	{
		// First, to get the input plug/ Attr in thisNode()
		// Next, get the input actual node 
		// Last, get the source node's dag path by using dagNodeFn 

		MObject thisNode = thisMObject();	// Get this actual plugin node's MObject...that's us!

		MPlug plugAttr( thisNode, inObject );	// Get our attribute on our node
		MDagPath dPathSrcObj;

		if ( plugAttr.isConnected() )
		{
			// get dagPath
			//
			MPlugArray plugArr;
			plugAttr.connectedTo( plugArr, true, false, &status ) ;	// Now list connections on our attr
			MPlug srcPlug = plugArr[0] ;		// Get the plug that is connected into our aSurface attr.

			MObject oSrcObj = srcPlug.node( &status ) ;	// Get the actual node that is connected.
			MFnDagNode dagNodeFn( oSrcObj, &status ) ;	// Put that into a Dag Node Function Set...
			dagNodeFn.getPath( dPathSrcObj ) ;		// Now get the dagPath of this node.

				// print out the dag path as string
			//cout << "path: " << dPathSrcObj.fullPathName().asChar() << endl;

			return dPathSrcObj;
		}
	}
MStatus lrutils::getFKControlByNum(MObject metaDataNode, unsigned int fkNum, MObject& fkCtlObj) {
    MStatus status;

    if(!metaDataNode.isNull()) {
        MFnDependencyNode metaDataFn(metaDataNode);
        MPlug fkControlsPlug = metaDataFn.findPlug( "FKControllers", true, &status );
        MyCheckStatusReturn(status, "MFnDependencyNode.findPlug() failed");

        //follow the plug connection to the connected plug on the other object
        MPlugArray connectedControlPlugs;
        fkControlsPlug.connectedTo(connectedControlPlugs,false,true,&status);
        MyCheckStatusReturn(status,"MPlug.connectedTo() failed");
        if( connectedControlPlugs.length() > 0) {
            //for some reason when more than one plug is connected in an MPlugArray,
            //the first object connected is in index 1 and the second object connected is
            //in index 2. The following code simply reverses the number we are
            //looking for since this is the case.
            if( connectedControlPlugs.length() > 1) {
                if(fkNum == 1) {
                    fkNum = 0;
                } else if (fkNum == 0) {
                    fkNum = 1;
                }
            }
            MPlug controlPlug = connectedControlPlugs[fkNum];
            //MPlug jointPlug = fkControlsPlug.connectionByPhysicalIndex(0);
            fkCtlObj = controlPlug.node(&status);
            MyCheckStatusReturn(status, "MPlug.node() failed");
        }
    }

    return status;
}
MStatus lrutils::getMetaChildByName(MObject metaNodeObj, MString name, MObject& metaChildObj) {
    MStatus status = MS::kFailure;

    MFnDependencyNode metaNodeFn( metaNodeObj );
    MPlug metaChildrenPlug = metaNodeFn.findPlug( "metaChildren", true, &status );
    MyCheckStatusReturn(status, "MFnDependencyNode.findPlug() failed");

    //follow the plug connection to the connected plug on the other object
    MPlugArray connectedChildPlugs;
    metaChildrenPlug.connectedTo(connectedChildPlugs,false,true,&status);
    MyCheckStatusReturn(status,"MPlug.connectedTo() failed");

    for (unsigned int i = 0; i < connectedChildPlugs.length(); i++) {
        MPlug connectedPlug = connectedChildPlugs[i];
        MObject connectedNodeObj = connectedPlug.node(&status);
        MyCheckStatusReturn(status, "MPlug.node() failed");

        MFnDependencyNode connectedNodeFn( connectedNodeObj );
        MString connectedNodeName = connectedNodeFn.name();
        int index = connectedNodeName.indexW( name );
        if( index != -1 ) {
            metaChildObj = connectedNodeObj;
            status = MS::kSuccess;
            break;
        }
    }

    return status;
}
MStatus lrutils::getMetaChildByRigId(MObject metaNodeObj, MString rigId, MObject& metaChildObj) {
    MStatus status = MS::kFailure;

    MFnDependencyNode metaNodeFn( metaNodeObj );
    MPlug metaChildrenPlug = metaNodeFn.findPlug( "metaChildren", true, &status );
    MyCheckStatusReturn(status, "MFnDependencyNode.findPlug() failed");

    //follow the plug connection to the connected plug on the other object
    MPlugArray connectedChildPlugs;
    metaChildrenPlug.connectedTo(connectedChildPlugs,false,true,&status);
    MyCheckStatusReturn(status,"MPlug.connectedTo() failed");

    for (unsigned int i = 0; i < connectedChildPlugs.length(); i++) {
        MPlug connectedPlug = connectedChildPlugs[i];
        MObject connectedNodeObj = connectedPlug.node(&status);
        MyCheckStatusReturn(status, "MPlug.node() failed");

        MFnDependencyNode connectedNodeFn( connectedNodeObj );

        //get the rigId number held in the rigId attribute
        MPlug rigIdPlug = connectedNodeFn.findPlug(MString("rigId"),true,&status);
        MyCheckStatusReturn(status,"findPlug failed");
        MString childRigId;
        rigIdPlug.getValue(childRigId);
        //if rigId is in childRigId then return the object
        if( childRigId.indexW(rigId) != -1 ) {
            metaChildObj = connectedNodeObj;
            status = MS::kSuccess;
            break;
        } 
    }

    return status;
}
Beispiel #7
0
MString getConnectedFileTexturePath(const MString& plugName, MFnDependencyNode& depFn)
{
    MStatus stat;
    MString path = "";
    MPlug plug = depFn.findPlug(plugName, &stat);
    if (!stat)
        return path;
    if (plug.isConnected())
    {
        MPlugArray parray;
        plug.connectedTo(parray, true, false, &stat);
        if (!stat)
            return path;

        if (parray.length() == 0)
            return path;

        MPlug destPlug = parray[0];
        MObject fileNode = destPlug.node();
        if (!fileNode.hasFn(MFn::kFileTexture))
        {
            return path;
        }

        MFnDependencyNode fileDepFn(fileNode);
        MPlug ftn = fileDepFn.findPlug("fileTextureName", &stat);

        if (!stat)
        {
            return path;
        }
        path = ftn.asString();
    }
    return path;
}
Beispiel #8
0
MObject getConnectedFileTextureObject(MString& plugName, MFnDependencyNode& depFn)
{
	MStatus stat;
	MString path = "";
	MPlug plug = depFn.findPlug(plugName, &stat);
	if( !stat )
		return MObject::kNullObj;
	if( plug.isConnected())
	{
		MPlugArray parray;
		plug.connectedTo(parray, true, false, &stat);
		if( !stat )
			return MObject::kNullObj;

		if( parray.length() == 0 )
			return MObject::kNullObj;

		MPlug destPlug = parray[0];
		MObject fileNode = destPlug.node();	
		if( !fileNode.hasFn(MFn::kFileTexture) )
		{
			return MObject::kNullObj;
		}else{
			return fileNode;
		}

	}
	return MObject::kNullObj;
}
    //---------------------------------------------------
    int DagHelper::getNextAvailableIndex ( const MObject& object, const MString& attribute, int startIndex )
    {
        MPlug p = MFnDependencyNode ( object ).findPlug ( attribute );

        if ( p.node().isNull() ) return -1;

        return getNextAvailableIndex ( p, startIndex );
    }
MStatus liqLightNodeBehavior::connectNodeToAttr( MObject &sourceNode, MPlug &destinationPlug, bool force )
{
    //CM_TRACE_FUNC("liqLightNodeBehavior::connectNodeToAttr("<<sourceNode.apiTypeStr()<<","<< destinationPlug.name()<<","<<force<<")");

    MStatus result = MS::kFailure;
    MFnDependencyNode src(sourceNode);

    /*
    if we are dragging from a liquidLight
    to a light then connect the assignedObjects
    plug to the plug being passed in
    */

    if(destinationPlug.node().hasFn(MFn::kLight))
    {
        if(src.typeName() == "liquidLight")
        {
            MPlug srcPlug = src.findPlug("assignedObjects");

            MObject dstNode = destinationPlug.node();
            MFnDependencyNode dst( dstNode );
            MPlug dstPlug = dst.findPlug("liquidLightShaderNode");

            if(!srcPlug.isNull() && !destinationPlug.isNull() && destinationPlug == dstPlug )
            {
                //MString boolean = (force)? "true":"false";
                MString cmd = "connectAttr ";
                //cmd += "-force " + boolean + " ";
                cmd += srcPlug.name() + " ";
                cmd += destinationPlug.name();
                result = MGlobal::executeCommand(cmd);
            }
        }
    }
    else
    {
        /* in all of the other cases we do not need the plug just the node
        that it is on                                                    */
        MObject destinationNode = destinationPlug.node();
        result = connectNodeToNode(sourceNode, destinationNode, force);
    }

    return result;
}
Beispiel #11
0
    // getBindPoseMatrix.
    // should be a relatively harmless function.
    // well you're wrong: this is one of the most stupid/difficult things in
    // Maya:
    //   1st try: just get the "bindPose"-plug, and use it as matrix:
    //             MFnIkJoint joint(jointPath.node());
    //             MPlug bindMatrixPlug = joint.findPlug("bindPose");
    //             MObject bindMatrixObject;
    //             bindMatrixPlug.getValue(bindMatrixObject);
    //             MFnMatrixData matrixData(bindMatrixObject);
    //             MMatrix bindMatrix = matrixData.matrix();
    //      Looks correct. But isn't. Not only, that we want the local
    //      transform (but that wouldn't be difficult (just look at the
    //      parent...), the bindPose plug seems
    //      to be shared between instances. If a joint is instanced, the
    //      bindMatrix would be the same as for the other instance. Bad luck :(
    //   2nd try: extract the local-transform out of the bindPose-plug. That's
    //      what is done here. (at least for now. (seen first in
    //      MS' xporttranslator).
    //      Still not the really correct way: it's possible to break the
    //      bindPose-plug. Maya still works, but our exporter doesn't.
    //   3rd (and correct way):
    //        http://www.greggman.com/pages/mayastuff.htm
    //
    // again: not yet very much error-checking...
    MMatrix
    BindPoseTool::getBindPoseMatrix(MFnIkJoint joint) const
    {
        // get bindPose-plug on joint
        MPlug tempBindPosePlug = joint.findPlug("bindPose");

        MPlugArray mapConnections;
        tempBindPosePlug.connectedTo(mapConnections, false, true);

        if (mapConnections.length() != 1)
        {
            //cout << "returning currentMatrix" << endl;
            // certainly not the most correct way of dealing with the problem...
            return joint.transformation().asMatrix();
        }

        // find the other end. actually we shouldn't call it "bindPosePlug",
        // but worldTransformPlug (as that's where it enters).

        // theoretically someone could bind the bindPose to other nodes,
        // than the bindPose-node. in this case there's a problem.
        MPlug bindPosePlug = mapConnections[0];

        // this node should be a "dagPose"-node (in case you want to look it
        // up in the help)
        MFnDependencyNode bindPoseNode(bindPosePlug.node());

        // and as such, has the "xformMatrix"-attribute.
        MObject xformMatrixAttribute = bindPoseNode.attribute("xformMatrix");

        MPlug localTransformPlug(bindPosePlug.node(), xformMatrixAttribute);
        // xformMatrix is an array. to get our localmatrix we need to select
        // the same index, as our bindPosePlug (logicalIndex()).
        localTransformPlug.selectAncestorLogicalIndex(
                            bindPosePlug.logicalIndex(), xformMatrixAttribute);

        MObject localMatrixObject;
        localTransformPlug.getValue(localMatrixObject);
        // extract the matrix out of the object.
        return MFnMatrixData(localMatrixObject).matrix();
    }
    //---------------------------------------------------
    // set the bind pose for a transform
    //
    MStatus DagHelper::setBindPoseInverse ( const MObject& node, const MMatrix& bindPoseInverse )
    {
        MStatus status;
        MFnDependencyNode dgFn ( node );
        MPlug bindPosePlug = dgFn.findPlug ( "bindPose", &status );
        if ( status != MS::kSuccess )
        {
            MGlobal::displayWarning ( MString ( "No bindPose found on node " ) + dgFn.name() );
            return status;
        }

        MFnMatrixData matrixFn;
        MObject val = matrixFn.create ( bindPoseInverse.inverse(), &status );
        MObject invval = matrixFn.create ( bindPoseInverse, &status );
        if ( status != MS::kSuccess )
        {
            MGlobal::displayWarning ( MString ( "Error setting bindPose on node " ) + dgFn.name() );
            return status;
        }

        // set the bind pose on the joint itself
        bindPosePlug.setValue ( val );

        // Now, perhaps more significantly, see if there's a
        // skinCluster using this bone and update its bind
        // pose (as the joint bind pose is not connected to
        // the skin - it's set at bind time from the joint's
        // current position, and our importer may not want to
        // disturb the current scene state just to put bones
        // in a bind position before creating skin clusters)
        MObject _node ( node );
        MItDependencyGraph it ( _node, MFn::kSkinClusterFilter );
        while ( !it.isDone() )
        {
            MPlug plug = it.thisPlug();
            unsigned int idx = plug.logicalIndex();
            MFnDependencyNode skinFn ( plug.node() );
            MPlug skinBindPosePlug = skinFn.findPlug ( "bindPreMatrix", &status );

            if ( status == MS::kSuccess )
            {
                // The skinCluster stores inverse inclusive matrix
                // so notice we use invval (the MObject created off
                // the inverse matrix here)
                skinBindPosePlug = skinBindPosePlug.elementByLogicalIndex ( idx );
                skinBindPosePlug.setValue ( invval );
            }

            it.next();
        }

        return status;
    }
Beispiel #13
0
MObject getOtherSideNode(MPlug& plug)
{
	MStatus stat;
	MObject result = MObject::kNullObj;

	MPlugArray plugArray;
	plug.connectedTo(plugArray, 1, 0, &stat);if( stat != MStatus::kSuccess) return result;
	if( plugArray.length() == 0)
		return result;
	MPlug otherSidePlug = plugArray[0];
	result = otherSidePlug.node();
	return result;
}
Beispiel #14
0
bool getConnectedFileTexturePath(MString& plugName, MString& nodeName, MString& value, MObject& outFileNode)
{
	MStatus stat;
	MObject obj = objectFromName(nodeName);
	if( obj == MObject::kNullObj)
		return false;

	MFnDependencyNode depFn(obj);
	MPlug plug = depFn.findPlug(plugName, &stat);
	if( !stat )
		return false;
	
	//MGlobal::displayInfo(MString("is plug connected: ") + plug.name());
	if( !plug.isConnected())
	{
		//MGlobal::displayInfo(MString("plug is NOT connected: ") + plug.name());
		return false;
	}
	MPlugArray parray;
	plug.connectedTo(parray, true, false, &stat);
	if( !stat )
		return false;

	if( parray.length() == 0 )
		return false;

	MPlug destPlug = parray[0];
	MObject fileNode = destPlug.node();
	std::cout << "filenode: " << getObjectName(fileNode).asChar() << " plug name " << destPlug.name() << "\n";
	
	if( !fileNode.hasFn(MFn::kFileTexture) )
	{
		std::cout << "node is not from type fileTexture.\n";
		return false;
	}

	MFnDependencyNode fileDepFn(fileNode);
	MPlug ftn = fileDepFn.findPlug("fileTextureName", &stat);

	if(!stat)
	{
		std::cout << "fileTextureName not found at fileTexNode.\n";
		return false;
	}
	
	MString fileTextureName = ftn.asString();
	std::cout << "fileTextureName value: " << fileTextureName.asChar() <<"\n";
	value = fileTextureName;
	outFileNode = fileNode;
	return true;
}
    //---------------------------------------------------
    //
    // Find a node connected to a node's attribute
    //
    MObject DagHelper::getNodeConnectedTo ( const MObject& node, const String& attribute )
    {
        MPlug plug;

        if ( getPlugConnectedTo ( node, attribute, plug ) )
        {
            return plug.node();
        }

        else
        {
            return MObject::kNullObj;
        }
    }
    //---------------------------------------------------
    void DagHelper::setArrayPlugSize ( MPlug& plug, uint size )
    {
        if ( plug.node().isNull() ) return;

#if MAYA_API_VERSION >= 800
        MStatus status = plug.setNumElements ( size );
        CHECK_STAT ( status );

#else
        MObject node = plug.node();
        MString plugPath = plug.info();
        if ( node.hasFn ( MFn::kDagNode ) )
        {
            MFnDagNode dagFn ( node );
            int dot = plugPath.index ( '.' );
            plugPath = dagFn.fullPathName() + plugPath.substring ( dot, plugPath.length() );
        }

        MString command = MString ( "setAttr -s " ) + size + " \"" + plugPath + "\";";

        MGlobal::executeCommand ( command );
#endif // MAYA 8.00+
    }
Beispiel #17
0
//
// simply get the node wich is connected to the named plug.
// If we have no connection, a kNullObject is returned.
//
MObject getOtherSideNode(MString& plugName, MObject& thisObject)
{
	MStatus stat;
	MObject result = MObject::kNullObj;
	MFnDependencyNode depFn(thisObject, &stat);	if( stat != MStatus::kSuccess) return result;
	MPlug plug = depFn.findPlug(plugName, &stat);	if( stat != MStatus::kSuccess) return result;
	MPlugArray plugArray;
	plug.connectedTo(plugArray, 1, 0, &stat);if( stat != MStatus::kSuccess) return result;
	if( plugArray.length() == 0)
		return result;
	MPlug otherSidePlug = plugArray[0];
	result = otherSidePlug.node();
	return result;
}
MStatus slopeShaderBehavior::connectNodeToAttr( MObject &sourceNode, MPlug &destinationPlug, bool force )
//
//	Description:
//		Overloaded function from MPxDragAndDropBehavior
//	this method will assign the correct output from the slope shader 
//	onto the given attribute.
//
{
	MStatus result = MS::kFailure;
	MFnDependencyNode src(sourceNode);

	//if we are dragging from a slopeShader
	//to a shader than connect the outColor
	//plug to the plug being passed in
	//
	if(destinationPlug.node().hasFn(MFn::kLambert)) {
		if(src.typeName() == "slopeShader")
		{
			MPlug srcPlug = src.findPlug("outColor");
			if(!srcPlug.isNull() && !destinationPlug.isNull())
			{
				MString cmd = "connectAttr ";
				cmd += srcPlug.name() + " ";
				cmd += destinationPlug.name();
				result = MGlobal::executeCommand(cmd);
			}
		}
	} else {
		//in all of the other cases we do not need the plug just the node
		//that it is on
		//
        MObject destinationNode = destinationPlug.node();
		result = connectNodeToNode(sourceNode, destinationNode, force);
	}
        
	return result;
}
    void AttributeParser::parseMeshData(MFnDependencyNode & node, MObject & attr)
    {
        MStatus status;

        MPlug plug = node.findPlug(attr, &status);
        if (!status) return;

        MObject meshNode;
        MPlugArray plugArray;
        bool success = plug.connectedTo(plugArray, true, false, &status);
        if (!status) return;
        if (success)
        {
            MPlug extPlug = plugArray[0];
            bool hasConnection = !extPlug.isNull(&status);
            if (!status) return;
            if (hasConnection)
            {
                meshNode = extPlug.node(&status);
                if (!status) return;
            }
        }

        /*
        MDataHandle dataHandle;
        status = plug.getValue(dataHandle);
        if (!status) return;

        MObject meshData;
        status = plug.getValue(meshData);
        if (!status) return;

        MFnMesh fnMesh(meshData, &status);
        if (!status) return;

        MDagPath dagPath = fnMesh.dagPath(&status);
        if (!status) return;

        MObject meshNode = dagPath.node(&status);
        */

        MFnAttribute fnAttr(attr, &status);
        if (!status) return;

        MString name = fnAttr.name(&status);
        if (!status) return;

        onMesh(plug, name, meshNode);
    }
MStatus lrutils::deleteMetaDataPlugConnections(MPlug metaDataPlug) {
    MStatus status;
    //follow the plug connection to the connected plug on the other object
    MPlugArray connectedPlugs;
    metaDataPlug.connectedTo(connectedPlugs,false,true,&status);
    MyCheckStatusReturn(status,"MPlug.connectedTo() failed");

    for (unsigned int i = 0; i < connectedPlugs.length(); i++) {
        MPlug connectedPlug = connectedPlugs[i];
        MObject connectedNodeObj = connectedPlug.node(&status);
        MyCheckStatusReturn(status, "MPlug.node() failed");
        MGlobal::deleteNode(connectedNodeObj);
    }
    return MS::kSuccess;
}
Beispiel #21
0
bool getConnectedFileTexturePath(const MString& plugName, MString& nodeName, MString& value, MObject& outFileNode)
{
    MStatus stat;
    MObject obj = objectFromName(nodeName);
    if (obj == MObject::kNullObj)
        return false;

    MFnDependencyNode depFn(obj);
    MPlug plug = depFn.findPlug(plugName, &stat);
    if (!stat)
        return false;

    if (!plug.isConnected())
    {
        return false;
    }
    MPlugArray parray;
    plug.connectedTo(parray, true, false, &stat);
    if (!stat)
        return false;

    if (parray.length() == 0)
        return false;

    MPlug destPlug = parray[0];
    MObject fileNode = destPlug.node();

    if (!fileNode.hasFn(MFn::kFileTexture))
    {
        return false;
    }

    MFnDependencyNode fileDepFn(fileNode);
    MPlug ftn = fileDepFn.findPlug("fileTextureName", &stat);

    if (!stat)
    {
        return false;
    }

    MString fileTextureName = ftn.asString();
    value = fileTextureName;
    outFileNode = fileNode;
    return true;
}
Beispiel #22
0
/**
 *	Check if this node has animations connected (AnimCurves or MotionPaths)
 *	and indicate the type of the animation found (if any)
 */
bool Transform::hasAnimation(MObject &obj, MFn::Type &type)
{
	MFnDependencyNode dn(obj);
	MPlugArray conns;
	dn.getConnections(conns);
	for(int i=0; i<conns.length(); i++){
		MPlug conn = conns[i];
		if( conn.name() == dn.name() + ".translateX" ||
			conn.name() == dn.name() + ".translateY" ||
			conn.name() == dn.name() + ".translateZ" ||
			conn.name() == dn.name() + ".rotateX" ||
			conn.name() == dn.name() + ".rotateY" ||
			conn.name() == dn.name() + ".rotateZ" ||
			conn.name() == dn.name() + ".scaleX" ||
			conn.name() == dn.name() + ".scaleY" ||
			conn.name() == dn.name() + ".scaleZ" ){

			MPlugArray connectedTo;
			// Get all connections having this node as destination
			conn.connectedTo(connectedTo, true, false);
#ifdef GENERIC_EXPORTER
			if ( connectedTo.length() > 0 ) {
				return true;
			}
#else
			for(int j=0; j<connectedTo.length(); j++){
				MPlug origin = connectedTo[j];
				MObject origin_node = origin.node();
				if(origin_node.hasFn(MFn::kAnimCurve)){
					type = MFn::kAnimCurve;
					return true;
				}
				else if(origin_node.hasFn(MFn::kMotionPath)){
					type = MFn::kMotionPath;
					return true;
				}
			}
#endif
		}
	}
	type = MFn::kInvalid;
	return false;
}
Beispiel #23
0
MObject getOtherSideNode(const MString& plugName, MObject& thisObject, MStringArray& otherSidePlugNames)
{
    MStatus stat;
    MObject result = MObject::kNullObj;
    MFnDependencyNode depFn(thisObject, &stat);
    if (stat != MStatus::kSuccess) return result;
    MPlug plug = depFn.findPlug(plugName, &stat);
    if (stat != MStatus::kSuccess)return result;
    if (!plug.isConnected())
    {
        int numChildConnects = plug.numConnectedChildren();
        if (numChildConnects == 0)
            return result;
        else
        {
            for (int i = 0; i < numChildConnects; i++)
            {
                MPlug child = plug.child(i);
                MString otherSidePlugName;
                MObject childObj = getOtherSideNode(child.partialName(false), thisObject, otherSidePlugName);
                if (childObj != MObject::kNullObj)
                {
                    otherSidePlugNames.append(otherSidePlugName);
                    result = childObj;
                } else
                    otherSidePlugNames.append(MString(""));
            }
        }
    }
    else
    {
        MPlugArray plugArray;
        plug.connectedTo(plugArray, 1, 0, &stat);
        if (stat != MStatus::kSuccess) return result;
        if (plugArray.length() == 0)
            return result;
        MPlug otherSidePlug = plugArray[0];
        result = otherSidePlug.node();
        otherSidePlugNames.append(otherSidePlug.name());
    }
    return result;
}
                /// Returns the arnold shader assigned to the procedural. This duplicates
                /// code in GeometryTranslator.h, but there's not much can be done about that
                /// since the GeometryTranslator isn't part of the MtoA public API.
                AtNode *arnoldShader(AtNode* node)
                {
                  m_displaced = false;

                  float maximumDisplacementPadding = -AI_BIG;
                  bool enableAutoBump = false;

                  unsigned instNumber = m_dagPath.isInstanced() ? m_dagPath.instanceNumber() : 0;
                  MPlug shadingGroupPlug = GetNodeShadingGroup(m_dagPath.node(), instNumber);

                  //find and export any displacment shaders attached
                  // DISPLACEMENT MATERIAL EXPORT
                  MPlugArray        connections;
                  MFnDependencyNode fnDGShadingGroup(shadingGroupPlug.node());
                  MPlug shaderPlug = fnDGShadingGroup.findPlug("displacementShader");
                  shaderPlug.connectedTo(connections, true, false);

                  // are there any connections to displacementShader?
                  if (connections.length() > 0)
                  {
                     m_displaced = true;
                     MObject dispNode = connections[0].node();
                     GetDisplacement(dispNode, maximumDisplacementPadding, enableAutoBump);
                     m_dispPadding = maximumDisplacementPadding;
                     AtNode* dispImage(ExportNode(connections[0]));

                     m_dispNode = dispImage;
                  }

                  // Only export displacement attributes if a displacement is applied
                  if (m_displaced)
                  {
                      std::cout << "arnoldShader::m_displaced :: " << m_displaced << std::endl;
                     // Note that disp_height has no actual influence on the scale of the displacement if it is vector based
                     // it only influences the computation of the displacement bounds
                    // AiNodeSetFlt(node, "disp_padding", maximumDisplacementPadding);
                  }

                  // return the exported surface shader
                  return ExportNode( shadingGroupPlug );
                }
Beispiel #25
0
MObject getOtherSideNode(const MString& plugName, MObject& thisObject, MString& otherSidePlugName)
{
    MStatus stat;
    MObject result = MObject::kNullObj;
    MFnDependencyNode depFn(thisObject, &stat);
    if (stat != MStatus::kSuccess) return result;
    MPlug plug = depFn.findPlug(plugName, &stat);
    if (stat != MStatus::kSuccess)return result;
    if (!plug.isConnected())
        return result;
    MPlugArray plugArray;
    plug.connectedTo(plugArray, 1, 0, &stat);
    if (stat != MStatus::kSuccess) return result;
    if (plugArray.length() == 0)
        return result;
    MPlug otherSidePlug = plugArray[0];
    result = otherSidePlug.node();
    otherSidePlugName = otherSidePlug.name();
    otherSidePlugName = otherSidePlug.partialName(false, false, false, false, false, true);
    return result;
}
Beispiel #26
0
		/// Returns the arnold shader to assign to the procedural.
		AtNode *arnoldShader()
		{	
			bool overrideShaders = false;
			MPlug plug = FindMayaObjectPlug( "overrideProceduralShaders" );
			if( !plug.isNull() )
			{
				// if we've been told explicitly not to override the shaders
				// in the procedurals, then early out.
				overrideShaders = plug.asBool();
				if( !overrideShaders )
				{
					return 0;
				}
			}
			
			unsigned instNumber = m_dagPath.isInstanced() ? m_dagPath.instanceNumber() : 0;
			MPlug shadingGroupPlug = GetNodeShadingGroup(m_dagPath.node(), instNumber);
			
			if( !overrideShaders )
			{
				// if we weren't explicitly told to override the shaders, then
				// decide whether to or not based on whether a non-default
				// shader has been applied to the shape by the user.
				MObject shadingGroupNode = shadingGroupPlug.node();
				MFnDependencyNode fnShadingGroupNode( shadingGroupNode );
				if( fnShadingGroupNode.name() != "initialShadingGroup" )
				{
					overrideShaders = true;
				}
			}
			
			if( overrideShaders )
			{
				return ExportNode( shadingGroupPlug );
			}
			else
			{
				return 0;
			}
		}
Beispiel #27
0
bool LuxRenderer::isLightMesh(mtlu_MayaObject *obj)
{
	MStatus stat;
	MObject result = MObject::kNullObj;
	MFnDependencyNode depFn(obj->mobject, &stat);	if( stat != MStatus::kSuccess) return false;
	MPlug plug = depFn.findPlug("message", &stat);	if( stat != MStatus::kSuccess) return false;
	MPlugArray plugArray;
	plug.connectedTo(plugArray, 0, 1, &stat);if( stat != MStatus::kSuccess) return false;
	if( plugArray.length() == 0)
		return false;
	for( uint i = 0; i < plugArray.length(); i++)
	{
		MPlug otherSidePlug = plugArray[i];
		logger.debug(MString("Checking message connection: ") + otherSidePlug.name());
		if( !pystring::endswith(otherSidePlug.name().asChar(), "mtlu_areaLight_geo"))
			continue;
		result = otherSidePlug.node();
		if( result.hasFn(MFn::kLight))
			return true;
	}
	return false;
}
MStatus lrutils::updateMetaDataObjectNames(MPlug metaDataPlug, MString oldRigName, MString rigName, MString oldCompName, MString compName) {
    MStatus status;
    //follow the plug connection to the connected plug on the other object
    MPlugArray connectedPlugs;
    metaDataPlug.connectedTo(connectedPlugs,false,true,&status);
    MyCheckStatusReturn(status,"MPlug.connectedTo() failed");

    for (unsigned int i = 0; i < connectedPlugs.length(); i++) {
        MPlug connectedPlug = connectedPlugs[i];
        MObject connectedNodeObj = connectedPlug.node(&status);
        MyCheckStatusReturn(status, "MPlug.node() failed");
        MFnDependencyNode connectedNodeFn( connectedNodeObj );
        MString connectedNodeName = connectedNodeFn.name();
        //set rig namespace
        lrutils::stringReplaceAll(connectedNodeName, oldRigName, rigName);
        //set component namespace
        lrutils::stringReplaceAll(connectedNodeName, oldCompName, compName);
        connectedNodeFn.setName(connectedNodeName);
    }

    return MS::kSuccess;
}
    //---------------------------------------------------
    bool DagHelper::plugHasAnimation ( const MPlug& plug )
    {
        MPlugArray connections;
        plug.connectedTo ( connections, true, false );
        unsigned int connectionsCount = connections.length();

        for ( unsigned int i = 0; i < connectionsCount; i++ )
        {
            MPlug connectedToPlug = connections[i];
            MObject nodeObj = connectedToPlug.node();
            MFnDependencyNode nodeFn ( nodeObj );
            MString typeName = nodeFn.typeName();

            if ( ( typeName == "animCurveTU" ) || ( typeName == "animCurveTL" )
                    || ( typeName == "animCurveTA" ) )
            {
                return true;
            }
        }

        return false;
    }
MStatus SurfaceAttach::compute(const MPlug& plug, MDataBlock& dataBlock) {
    if (plug != out && plug != translate & plug != rotate)
        return MS::kUnknownParameter;

    const short dataDirection = dataBlock.inputValue(SurfaceAttach::direction).asShort();
    const std::int32_t dataSamples = dataBlock.inputValue(SurfaceAttach::samples).asInt();
    const short dataGenus = dataBlock.inputValue(SurfaceAttach::genus).asShort();
    const double dataOffset = dataBlock.inputValue(SurfaceAttach::offset).asDouble();
    const bool dataReverse = dataBlock.inputValue(SurfaceAttach::reverse).asBool();
    const double dataStaticLength = dataBlock.inputValue(SurfaceAttach::staticLength).asDouble();
    const MMatrix dataParentInverse = dataBlock.inputValue(SurfaceAttach::parentInverse).asMatrix();

    MFnNurbsSurface fnSurface (dataBlock.inputValue(SurfaceAttach::surface).asNurbsSurface());
    MFnDependencyNode fnDepend (plug.node());

    // Set UV Inputs
    this->inUVs(fnDepend);

    // If Percentage or Fixed Length
    if (dataGenus > 0){
        // If the amount of samples has changed, rebuild the arrays/data
        if (this->sampleCount != dataSamples) {
            this->allocate(dataSamples);
            this->sampleCount = dataSamples;
        }

        // Calculate Lengths
        if (!dataDirection)
            this->surfaceLengthsU(fnSurface, 0.5);
        else
            this->surfaceLengthsV(fnSurface, 0.5);
    }

    // Set all the existing out Plugs
    this->setOutPlugs(dataBlock, fnSurface, dataOffset, dataReverse, dataGenus, dataStaticLength,
                      dataParentInverse, dataDirection);

    return MS::kSuccess;
}