Esempio n. 1
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;
}
Esempio n. 2
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;
}
Esempio n. 3
0
void getConnectedChildPlugs(const char *attrName, MFnDependencyNode& depFn, bool dest, MPlugArray& thisNodePlugs, MPlugArray& otherSidePlugs)
{
    MPlug p = depFn.findPlug(attrName);
    if (p.isCompound() && !p.isArray())
    {
        getConnectedChildPlugs(p, dest, thisNodePlugs, otherSidePlugs);
        return;
    }
    if (p.isArray())
    {
        for (uint i = 0; i < p.numElements(); i++)
        {
            if (p[i].numConnectedChildren() == 0)
                continue;
            if (!p[i].isCompound())
                getConnectedChildPlugs(p[i], dest, thisNodePlugs, otherSidePlugs);
            else
            {
                if (getAttributeNameFromPlug(p) == MString("colorEntryList"))
                {
                    getConnectedChildPlugs(p[i].child(1), dest, thisNodePlugs, otherSidePlugs);
                }
            }
        }
    }
}
Esempio n. 4
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;
}
Esempio n. 5
0
bool isConnected(const char *attrName, MFnDependencyNode& depFn, bool dest, bool primaryChild = false)
{
    MStatus stat;
    MPlugArray pa;
    depFn.getConnections(pa);
    std::vector<std::string> stringParts;
    pystring::split(attrName, stringParts, ".");
    MString attName = attrName;
    if (stringParts.size() > 1)
        attName = stringParts.back().c_str();
    if (pystring::endswith(attrName, "]"))
    {
        int found = attName.rindex('[');
        if (found >= 0)
            attName = attName.substring(0, found-1);
    }

    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();
        MString plugName = plug.name();
        if (plug.isElement())
            plug = plug.array();
        MString attNameFromPlug = getAttributeNameFromPlug(plug);
        if ((attNameFromPlug == attName))
            return true;
    }
    return false;
}
Esempio n. 6
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;
}
Esempio n. 7
0
bool ShadingNode::isInPlugValid(const MPlug& plug) const
{
    MPlug tmpPlug = plug;

    if (!tmpPlug.isDestination())
        return false;

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

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

    const MString& plugName = getAttributeNameFromPlug(tmpPlug);

    for (size_t inattrId = 0; inattrId < inputAttributes.size(); inattrId++)
    {
        if (plugName == inputAttributes[inattrId].name.c_str())
            return true;
    }
    return false;
}