Exemplo n.º 1
0
bool util::isDrivenBySplineIK(const MFnIkJoint & iJoint)
{
    // spline IK can drive the starting joint's translate channel but
    // it has no connection to the translate plug.
    // we treat the joint as animated in this case.
    // find the ikHandle node.
    MPlug msgPlug = iJoint.findPlug("message", false);
    MPlugArray msgPlugDst;
    msgPlug.connectedTo(msgPlugDst, false, true);
    for (unsigned int i = 0; i < msgPlugDst.length(); i++) {
        MFnDependencyNode ikHandle(msgPlugDst[i].node());
        if (!ikHandle.object().hasFn(MFn::kIkHandle)) continue;

        // find the ikSolver node.
        MPlug ikSolverPlug = ikHandle.findPlug("ikSolver");
        MPlugArray ikSolverDst;
        ikSolverPlug.connectedTo(ikSolverDst, true, false);
        for (unsigned int j = 0; j < ikSolverDst.length(); j++) {

            // return true if the ikSolver is a spline solver.
            if (ikSolverDst[j].node().hasFn(MFn::kSplineSolver)) {
                return true;
            }
        }
    }
    
    return false;
}
Exemplo n.º 2
0
void ExtractNormalMap(MFnDependencyNode& fn, unsigned int* tex = NULL)
{
	MString texname;

	MPlug p = fn.findPlug( "normalCamera" );
	MPlugArray plugs;
	p.connectedTo(plugs,true,true);

	for(int i = 0; i != plugs.length(); ++i)
	{
		if (plugs[i].node().apiType() == MFn::kBump) 
		{
			MFnDependencyNode fnDepBump( plugs[i].node() );
			MPlug pp = fnDepBump.findPlug( "bumpValue" );

			MPlugArray pplugs;
			pp.connectedTo(pplugs, true, true);
			
			for(int j = 0; j != pplugs.length(); ++j)
			{
				if (pplugs[j].node().apiType() == MFn::kFileTexture) 
				{
					MFnDependencyNode fnDep(pplugs[j].node());
					texname = fnDep.name();
					break;
				}
			}
		}
	}

	*tex = GetTextureID( texname );
}
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;
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
0
MObject getConnectedShadingEngine(MObject node)
{
	MObject se = MObject::kNullObj;

	MFnDependencyNode depFn(node);
	MPlugArray plugArray;
	depFn.getConnections(plugArray);
	for( uint i = 0; i < plugArray.length(); i++)
	{
		if( plugArray[i].isSource() )
		{
			MPlugArray desArray;
			plugArray[i].connectedTo(desArray, false, true);
			for(uint k = 0; k < desArray.length(); k++)
			{
				if( desArray[k].node().hasFn(MFn::kShadingEngine))
				{
					se = desArray[k].node();
				}
			}
		}
	}

	return se;
}
Exemplo n.º 6
0
void ParameterisedHolder<B>::nonNetworkedConnections( const MPlug &plug, MPlugArray &connectionsFromPlug, MPlugArray &connectionsToPlug ) const
{
    MPlugArray from;
    MPlugArray to;

    // the MPlug.connectedTo() method is documented as always returning networked plugs.
    plug.connectedTo( from, false, true );
    plug.connectedTo( to, true, false );

    connectionsFromPlug.clear();
    connectionsFromPlug.setLength( from.length() );
    connectionsToPlug.clear();
    connectionsToPlug.setLength( to.length() );

    for( unsigned i=0; i<from.length(); i++ )
    {
        // the MPlug( node, attribute ) constructor is documented as always returning non-networked plugs.
        connectionsFromPlug.set( MPlug( from[i].node(), from[i].attribute() ), i );
    }

    for( unsigned i=0; i<to.length(); i++ )
    {
        connectionsToPlug.set( MPlug( to[i].node(), to[i].attribute() ), i );
    }
}
//-----------------------------------------------------------------------------
// Returns the vsSkinner node if the passed node is connected to a vsSkinner node
//-----------------------------------------------------------------------------
MStatus CVsSkinnerCmd::ConnectedToSkinnerNode(
	const MDagPath &iDagPath,
	MDagPath &oDagPath )
{
	MPlugArray pA;
	MPlugArray pA1;

	if ( MFnDagNode( iDagPath ).getConnections( pA ) && pA.length() )
	{
		MObject mObj;

		const uint np( pA.length() );
		for ( uint i( 0U ); i != np; ++i )
		{
			if ( pA[ i ].connectedTo( pA1, true, true ) && pA1.length() )
			{
				const uint np1( pA1.length() );
				for ( uint j( 0U ); j != np1; ++j )
				{
					mObj = pA1[ j ].node();

					if ( IsSkinnerNode( mObj ) )
					{
						MDagPath::getAPathTo( mObj, oDagPath );
						return MS::kSuccess;
					}
				}
			}
		}
	}

	return MS::kFailure;
}
Exemplo n.º 8
0
// to check if an object is animated, we need to check e.g. its transform inputs
// if the object is from an instancer node, always return true
bool MayaObject::isObjAnimated()
{
	MStatus stat;
	bool returnValue = false;
	
	if( this->instancerParticleId > -1)
		return true;

	if( this->mobject.hasFn(MFn::kTransform))
	{
		MFnDependencyNode depFn(this->mobject, &stat);
		if(stat)
		{
			MPlugArray connections;
			depFn.getConnections(connections);
			if( connections.length() == 0)
				returnValue = false;
			else{
				for( uint cId = 0; cId < connections.length(); cId++)
				{
					if( connections[cId].isDestination())
					{
						returnValue = true;
					}
				}
			}
			
		}
	}
	return returnValue;
}
void Exporter::extractColor(Color& tempcolor, MFnDependencyNode& fn, MString name)
{
	MPlug p;

	MString r = name;
	r += "R";
	MString g = name;
	g += "G";
	MString b = name;
	b += "B";
	MString a = name;
	a += "A";

	p = fn.findPlug(r.asChar());
	p.getValue(tempcolor.r);
	p = fn.findPlug(g.asChar());
	p.getValue(tempcolor.g);
	p = fn.findPlug(b.asChar());
	p.getValue(tempcolor.b);
	p = fn.findPlug(a.asChar());
	p.getValue(tempcolor.a);
	p = fn.findPlug(name.asChar());

	MPlugArray connections;
	p.connectedTo(connections, true, false);

	int debug = connections.length();

	for (int i = 0; i != connections.length(); ++i)
	{
		// if file texture found
		if (connections[i].node().apiType() == MFn::kFileTexture)
		{
			// bind a function set to it ....
			MFnDependencyNode fnDep(connections[i].node());

			// to get the node name
			tempcolor.texfileInternal = fnDep.name().asChar();
			MPlug filename = fnDep.findPlug("ftn");

			//sparar hela s�kv�gen till texturen
			tempcolor.texfileExternal = filename.asString().asChar();

			//kopierar texturfiler
			std::string base_filename = tempcolor.texfileExternal.substr(tempcolor.texfileExternal.find_last_of("/\\") + 1);

			CopyFile(tempcolor.texfileExternal.c_str(), base_filename.c_str(), false);

			// stop looping
			break;
		}

	}

}
Exemplo n.º 10
0
//standard attributes
void sixdofConstraintNode::computeConstraint(const MPlug& plug, MDataBlock& data)
{
   // std::cout << "sixdofConstraintNode::computeConstraint" << std::endl;

    MObject thisObject(thisMObject());
    MPlug plgRigidBodyA(thisObject, ia_rigidBodyA);
    MPlug plgRigidBodyB(thisObject, ia_rigidBodyB);
    MObject update;
    //force evaluation of the rigidBody
    plgRigidBodyA.getValue(update);
    plgRigidBodyB.getValue(update);

    rigid_body_t::pointer  rigid_bodyA;
    if(plgRigidBodyA.isConnected()) {
        MPlugArray connections;
        plgRigidBodyA.connectedTo(connections, true, true);
        if(connections.length() != 0) {
            MFnDependencyNode fnNodeA(connections[0].node());
            if(fnNodeA.typeId() == rigidBodyNode::typeId) {
                rigidBodyNode *pRigidBodyNodeA = static_cast<rigidBodyNode*>(fnNodeA.userNode());
                rigid_bodyA = pRigidBodyNodeA->rigid_body();    
            } else {
                std::cout << "sixdofConstraintNode connected to a non-rigidbody node!" << std::endl;
            }
        }
    }

    rigid_body_t::pointer  rigid_bodyB;
	if(plgRigidBodyB.isConnected()) {
        MPlugArray connections;
        plgRigidBodyB.connectedTo(connections, true, true);
        if(connections.length() != 0) {
            MFnDependencyNode fnNodeB(connections[0].node());
            if(fnNodeB.typeId() == rigidBodyNode::typeId) {
                rigidBodyNode *pRigidBodyNodeB = static_cast<rigidBodyNode*>(fnNodeB.userNode());
                rigid_bodyB = pRigidBodyNodeB->rigid_body();    
            } else {
                std::cout << "sixdofConstraintNode connected to a non-rigidbody node!" << std::endl;
            }
        }
    }

    if(rigid_bodyA && rigid_bodyB) {
        //not connected to a rigid body, put a default one
        constraint_t::pointer constraint = static_cast<constraint_t::pointer>(m_constraint);
        solver_t::remove_constraint(constraint);
        m_constraint = solver_t::create_sixdof_constraint(rigid_bodyA, vec3f(), rigid_bodyB, vec3f());
        constraint = static_cast<constraint_t::pointer>(m_constraint);
        solver_t::add_constraint(constraint);
    }

    data.outputValue(ca_constraint).set(true);
    data.setClean(plug);
}
Exemplo n.º 11
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);
		}		
	}

}
Exemplo n.º 12
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;
}
Exemplo n.º 13
0
bool isConnected(const char *attrName, MFnDependencyNode& depFn, bool dest, bool primaryChild = false)
{
	MStatus stat;
	MPlugArray pa;
	depFn.getConnections(pa);

	for (uint pId = 0; pId < pa.length(); pId++)
	{
		if (dest)
		{
			if (!pa[pId].isDestination())
				continue;
		}
		else{
			if (!pa[pId].isSource())
				continue;
		}
		MPlug plug = pa[pId];
		if (primaryChild)
			while (plug.isChild())
				plug = plug.parent();
		if (plug.isElement())
			plug = plug.array();
		if ((getAttributeNameFromPlug(plug) == attrName))
			return true;
	}
	return false;
}
Exemplo n.º 14
0
void ExtractAttribute(MFnDependencyNode& fn, std::string name, SMatAttrib& attrib)
{
	MPlug p;

	// extract attribute color
	std::string r = name + "R";
	std::string g = name + "G";
	std::string b = name + "B";

	p = fn.findPlug(r.c_str());	p.getValue(attrib.color[0]);
	p = fn.findPlug(g.c_str());	p.getValue(attrib.color[1]);
	p = fn.findPlug(b.c_str());	p.getValue(attrib.color[2]);

	// extract attribute texture
	MString texname;

	p = fn.findPlug(name.c_str());
	
	MPlugArray plugs;
	p.connectedTo(plugs,true,true);

	for(int i = 0; i != plugs.length(); ++i)
	{
		if (plugs[i].node().apiType() == MFn::kFileTexture) 
		{
			MFnDependencyNode fnDep(plugs[i].node());
			texname = fnDep.name();
			break;
		}
	}

	attrib.textureID = GetTextureID( texname );
}
Exemplo n.º 15
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;
}
Exemplo n.º 16
0
MObject getConnectedInNode(const MObject& thisObject, const char *attrName)
{
    MObject result = MObject::kNullObj;
    MString indexStr, base;
    int index = -1;
    if (getArrayIndex(attrName, indexStr, base))
    {
        index = indexStr.asInt();
        attrName = base.asChar();
    }
    MFnDependencyNode depFn(thisObject);
    MPlug inPlug = depFn.findPlug(attrName);
    if (index > -1)
        inPlug = inPlug[index];
    MString plugname = inPlug.name();

    if (!inPlug.isConnected())
        return result;

    MPlugArray connectedPlugs;
    inPlug.connectedTo(connectedPlugs, true, false);
    if (connectedPlugs.length() == 0)
        return result;

    return connectedPlugs[0].node();
}
Exemplo n.º 17
0
void rigidBodyNode::updateShape(const MPlug& plug, MDataBlock& data, float& collisionMarginOffset)
{
	MObject thisObject(thisMObject());
    MPlug plgCollisionShape(thisObject, ia_collisionShape);
    MObject update;
    //force evaluation of the shape
    plgCollisionShape.getValue(update);

   /* vec3f prevCenter(0, 0, 0);
    quatf prevRotation(qidentity<float>());
    if(m_rigid_body) {
        prevCenter = m_rigid_body->collision_shape()->center();
        prevRotation = m_rigid_body->collision_shape()->rotation();
    }*/

    collision_shape_t::pointer  collision_shape;
	
    if(plgCollisionShape.isConnected()) {
        MPlugArray connections;
        plgCollisionShape.connectedTo(connections, true, true);
        if(connections.length() != 0) {
            MFnDependencyNode fnNode(connections[0].node());
            if(fnNode.typeId() == collisionShapeNode::typeId) {
				collisionShapeNode *pCollisionShapeNode = static_cast<collisionShapeNode*>(fnNode.userNode());
				pCollisionShapeNode->setCollisionMarginOffset(collisionMarginOffset); //mb
                collision_shape = pCollisionShapeNode->collisionShape();
            } else {
                std::cout << "rigidBodyNode connected to a non-collision shape node!" << std::endl;
            }
        }
    }

	data.outputValue(ca_rigidBody).set(true);
    data.setClean(plug);
}
Exemplo n.º 18
0
//
// Write the 'disconnectAttr' statements for those connections which were
// made in referenced files, but broken in the main scene.
//
void maTranslator::writeBrokenRefConnections(fstream& f)
{
	unsigned int	numBrokenConnections = fBrokenConnSrcs.length();
	unsigned int	i;

	for (i = 0; i < numBrokenConnections; i++)
	{
		f << "disconnectAttr \""
		  << fBrokenConnSrcs[i].partialName(true).asChar()
		  << "\" \""
		  << fBrokenConnDests[i].partialName(true).asChar()
		  << "\"";

		//
		// If the destination plug is a multi for which index does not
		// matter, then we must add a "-na/nextAvailable" flag to the
		// command.
		//
		MObject			attr = fBrokenConnDests[i].attribute();
		MFnAttribute	attrFn(attr);

		if (!attrFn.indexMatters()) f << " -na";

		f << ";" << endl;
	}
}
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;
}
	void DocumentExporter::saveParamClip()
	{
		int length = 0;
		
		MItDependencyNodes CharacterItr(MFn::kCharacter);
		for (int i1 = 0; !CharacterItr.isDone(); CharacterItr.next(), i1++)
		{
			MFnCharacter character;
			if (!character.setObject(CharacterItr.item())) continue;

			MPlugArray array;
			character.getMemberPlugs(array);

			length = array.length();
		}

		MIntArray  arrayChannelAttribute(length, 0);


		MItDependencyNodes clipItr(MFn::kClip);
		MFnClip clipFn;
		for (int i1 = 0; !clipItr.isDone(); clipItr.next(), i1++)
		{

			if (!clipFn.setObject(clipItr.item())) continue;

			// save original param
			MIntArray  arrayOriginalChannelAttribute(length);
			clipFn.getAbsoluteChannelSettings(arrayOriginalChannelAttribute);
			ParamClipVec.push_back(arrayOriginalChannelAttribute);

			// set relativeClip on
			clipFn.setAbsoluteChannelSettings(arrayChannelAttribute);
		}
	}
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;
}
Exemplo n.º 22
0
MStatus disconnectAllPlugsTo(MPlug & dstPlug)
{
    MStatus status = MS::kSuccess;
    MPlugArray array;
    dstPlug.connectedTo(array, true, false, &status);
    unsigned int arrayLength = array.length();

    for (unsigned int i = 0; i < arrayLength; i++)
    {
        MPlug srcPlug = array[i];
        if (status == MS::kSuccess)
        {
            MDGModifier modifier;
            status = modifier.disconnect(srcPlug, dstPlug);
            status = modifier.doIt();
            if (status != MS::kSuccess)
            {
                MString theError("Disconnect ");
                theError += srcPlug.name();
                theError += MString(" -> ");
                theError += dstPlug.name();
                theError += MString(" failed, status = ");
                theError += status.errorString();
                MGlobal::displayError(theError);
                return status;
            }
        }
    }
    return MS::kSuccess;
}
Exemplo n.º 23
0
MObject slopeShaderBehavior::findShadingEngine(MObject &node)
//
//	Description:
//		Given the material MObject this method will
//	return the shading group that it is assigned to.
//	if there is no shading group associated with
//	the material than a null MObject is apssed back.
//
{
	MFnDependencyNode nodeFn(node);
	MPlug srcPlug = nodeFn.findPlug("outColor");
	MPlugArray nodeConnections;
	srcPlug.connectedTo(nodeConnections, false, true);
	//loop through the connections
	//and find the shading engine node that
	//it is connected to
	//
	for(unsigned i = 0; i < nodeConnections.length(); i++)
	{
		if(nodeConnections[i].node().hasFn(MFn::kShadingEngine))
			return nodeConnections[i].node();
	}

	//no shading engine associated so return a
	//null MObject
	//
	return MObject();
}
Exemplo n.º 24
0
void geometryReplicatorGeometryOverride::updateDG()
{
	if (!fPath.isValid()) {
		MFnDependencyNode fnThisNode(fThisNode);

		MObject messageAttr = fnThisNode.attribute("message");
		MPlug messagePlug(fThisNode, messageAttr);

		MPlugArray connections;
		if (messagePlug.connectedTo(connections, false, true)) {
			for (unsigned int i = 0; i < connections.length(); ++i) {
				MObject node = connections[i].node();
				if (node.hasFn(MFn::kMesh) ||
					node.hasFn(MFn::kNurbsSurface) ||
					node.hasFn(MFn::kNurbsCurve) ||
					node.hasFn(MFn::kBezierCurve))
				{
					MDagPath path;
					MDagPath::getAPathTo(node, path);

					fPath = path;
					fType = path.apiType();

					break;
				}
			}
		}
	}
}
Exemplo n.º 25
0
MObject findShader(MObject& setNode, SXRShaderData& d)
//
//  Description:
//      Find the shading node for the given shading group set node.
//
{
	MFnDependencyNode fnNode(setNode);
	d.name	= fnNode.name();
	// cout << "looking for shader in node " << fnNode.name().asChar() << "\n";
	MPlug shaderPlug = fnNode.findPlug("surfaceShader");

	if (!shaderPlug.isNull()) {			
		MPlugArray connectedPlugs;
		bool asSrc = false;
		bool asDst = true;
		shaderPlug.connectedTo( connectedPlugs, asDst, asSrc );

		if (connectedPlugs.length() != 1)
			Msg("!Error getting shader");
		else 
			return connectedPlugs[0].node();
	}

	Msg("!Error finding surface shader for node '%s'",fnNode.name().asChar());
	return MObject::kNullObj;
}
Exemplo n.º 26
0
bool ShadingNode::isAttributeValid(MString attributeName)
{
	MStatus stat;
	MFnDependencyNode depFn(this->mobject);
	MPlugArray pa;
	depFn.getConnections(pa);
	for (uint pId = 0; pId < pa.length(); pId++)
	{
		if (pa[pId].isDestination())
		{
			MPlug parentPlug = pa[pId];
			while (parentPlug.isChild())
				parentPlug = parentPlug.parent();
			MString plugName = getAttributeNameFromPlug(parentPlug);
			if (plugName == attributeName)
			{
				for (size_t inattrId = 0; inattrId < this->inputAttributes.size(); inattrId++)
				{
					if (attributeName == inputAttributes[inattrId].name.c_str())
						return true;
				}
			}
		}
	}

	return false;
}
Exemplo n.º 27
0
void ShadingNode::getConnectedInputObjects(MObjectArray& objectArray)
{
	MStatus stat;
	MFnDependencyNode depFn(this->mobject);
	MStringArray aliasArray;
	depFn.getAliasList(aliasArray);
	MObjectArray objectList;
	MPlugArray connections;
	depFn.getConnections(connections);

	for (uint connId = 0; connId < connections.length(); connId++)
	{
		MPlug p = connections[connId];
		if (!p.isDestination())
			continue;
		
		// a connection can be a direct connection or a child connection e.g. colorR, colorG...
		// but in a shader description file only the main attribute is listed so we go up until we have the main plug
		MPlug mainPlug = p;
		while (mainPlug.isChild())
			mainPlug = mainPlug.parent();
		if (mainPlug.isElement())
			mainPlug = mainPlug.array();
		MStringArray stringArray;
		// name contains node.attributeName, so we have to get rid of the nodeName
		mainPlug.name().split('.', stringArray);
		MString plugName = stringArray[stringArray.length() - 1];
		if (!this->isAttributeValid(plugName))
			continue;
		getConnectedInNodes(p, objectList);
		makeUniqueArray(objectList);
	}
	objectArray = objectList;
}
Exemplo n.º 28
0
    //---------------------------------------------------
    bool DagHelper::hasConnection ( const MPlug& plug, bool asSource, bool asDestination )
    {
        MPlugArray plugs;
        plug.connectedTo ( plugs, asDestination, asSource );
        if ( plugs.length() > 0 ) return true;

        return plug.numConnectedChildren() > 0;
    }
Exemplo n.º 29
0
MStatus updateTCCData::getTCCNode( MSelectionList &selList )
{
    MStatus status; 
    MItSelectionList selListIter( selList );
    selListIter.setFilter( MFn::kMesh );
    
    for( ; !selListIter.isDone(); selListIter.next() )
    {
        MDagPath dagPath;
        MObject component;
        selListIter.getDagPath( dagPath, component );
        status = dagPath.extendToShape();
    
        if (status == MS::kSuccess)
        {
            MFnDependencyNode meshShapeFn(dagPath.node());
            
            MObject outMeshAttr = meshShapeFn.attribute( "outMesh" );
            MPlug outMeshPlug(dagPath.node(), outMeshAttr );
//            worldMeshPlug = worldMeshPlug.elementByLogicalIndex( 0 );
            cout<<"inMesh-connected dagnode name: "<<endl<<" > "<<outMeshPlug.info().asChar()<<endl;
            
            MPlugArray plugArray;
            outMeshPlug.connectedTo(plugArray, true, true);
            cout<<"connected attrs: "<<plugArray.length()<<endl;
            
            for (size_t k=0; k<plugArray.length(); k++)
            {
                MObject TCCnode(plugArray[k].node());
                MFnDependencyNode TCCDepNode( TCCnode );
                
                cout<<"Dependency node type: "<<TCCDepNode.typeName().asChar()<<endl;
                if (TCCDepNode.typeName() == "TCC")
                {
                    fSrcDagPath = dagPath;
                    fTCCnode = TCCnode;
                    fComponent = component;
                    return MS::kSuccess;
                }
            }
        }
    }    
    
    return MS::kFailure;
}
Exemplo n.º 30
0
bool isPlugInList(MObject obj, MPlugArray& plugArray)
{
    for (uint oId = 0; oId < plugArray.length(); oId++)
    {
        if (plugArray[oId] == obj)
            return true;
    }
    return false;
}