//---------------------------------------------------
    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.º 2
0
void getConnectedChildPlugs(const MPlug& plug, bool dest, MPlugArray& thisNodePlugs, MPlugArray& otherSidePlugs)
{
    if (plug.numConnectedChildren() == 0)
        return;
    for (uint chId = 0; chId < plug.numChildren(); chId++)
        if (plug.child(chId).isConnected())
        {
            if ((plug.child(chId).isDestination() && dest) || (plug.child(chId).isSource() && !dest))
            {
                thisNodePlugs.append(plug.child(chId));
                otherSidePlugs.append(getDirectConnectedPlug(plug, dest));
            }
        }
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
// returns 0 if static, 1 if sampled, and 2 if a curve
int util::getSampledType(const MPlug& iPlug)
{
    MPlugArray conns;

    iPlug.connectedTo(conns, true, false);

    // it's possible that only some element of an array plug or
    // some component of a compound plus is connected
    if (conns.length() == 0)
    {
        if (iPlug.isArray())
        {
            unsigned int numConnectedElements = iPlug.numConnectedElements();
            for (unsigned int e = 0; e < numConnectedElements; e++)
            {
                int retVal = getSampledType(iPlug.connectionByPhysicalIndex(e));
                if (retVal > 0)
                    return retVal;
            }
        }
        else if (iPlug.isCompound() && iPlug.numConnectedChildren() > 0)
        {
            unsigned int numChildren = iPlug.numChildren();
            for (unsigned int c = 0; c < numChildren; c++)
            {
                int retVal = getSampledType(iPlug.child(c));
                if (retVal > 0)
                    return retVal;
            }
        }
        return 0;
    }

    MObject ob;
    MFnDependencyNode nodeFn;
    for (unsigned i = 0; i < conns.length(); i++)
    {
        ob = conns[i].node();
        MFn::Type type = ob.apiType();

        switch (type)
        {
            case MFn::kAnimCurveTimeToAngular:
            case MFn::kAnimCurveTimeToDistance:
            case MFn::kAnimCurveTimeToTime:
            case MFn::kAnimCurveTimeToUnitless:
            {
                nodeFn.setObject(ob);
                MPlug incoming = nodeFn.findPlug("i", true);

                // sampled
                if (incoming.isConnected())
                    return 1;

                // curve
                else
                    return 2;
            }
            break;

            case MFn::kMute:
            {
                nodeFn.setObject(ob);
                MPlug mutePlug = nodeFn.findPlug("mute", true);

                // static
                if (mutePlug.asBool())
                    return 0;
                // curve
                else
                   return 2;
            }
            break;

            default:
            break;
        }
    }

    return 1;
}
void ShadingNetworkExporter::createShader(const MObject& node)
{
    MStatus status;
    MFnDependencyNode depNodeFn(node);

    const OSLShaderInfo *shaderInfo =
        ShadingNodeRegistry::getShaderInfo(depNodeFn.typeName());

    if(!shaderInfo)
    {
        std::cout << "Skipping unsupported shader: " << depNodeFn.typeName() << "\n";
        return;
    }

    if(m_shadersExported.count(depNodeFn.name()) != 0)
    {
        std::cout << "Skipping already exported shader: " << depNodeFn.name() << "\n";
        return;
    }

    m_shadersExported.insert(depNodeFn.name());

    asr::ParamArray shaderParams;

    for(int i = 0, e = shaderInfo->paramInfo.size(); i < e; ++i)
    {
        const OSLParamInfo& paramInfo = shaderInfo->paramInfo[i];

        // Skip output attributes.
        if(paramInfo.isOutput)
        {
            std::cout << "Skipping output attribute: " << "\n";
            std::cout << paramInfo << std::endl;
            continue;
        }

        if(!paramInfo.validDefault)
        {
            std::cout << "Skipping attribute without valid default: " << "\n";
            std::cout << paramInfo << std::endl;
            continue;
        }

        if(paramInfo.isArray)
        {
            std::cout << "Skipping array attribute: " << "\n";
            std::cout << paramInfo << std::endl;
            continue;
        }

        MPlug plug = depNodeFn.findPlug(paramInfo.mayaAttributeName, &status);
        if(!status)
        {
            std::cout << "Skipping unknown attribute: "
                        << paramInfo.mayaAttributeName << std::endl;
            continue;
        }

        if(plug.isConnected())
        {
            MObject srcNode;
            if(AttributeUtils::get(plug, srcNode))
                createShader(srcNode);

            continue;
        }

        if(plug.isCompound() && plug.numConnectedChildren() != 0)
        {
            std::cout << "Skipping connected compound attribute: " << plug.name() << "\n";
            continue;
        }

        if(plug.isArray() && plug.numConnectedElements() != 0)
        {
            std::cout << "Skipping connected array attribute: " << plug.name() << "\n";
            continue;
        }

        processAttribute(plug, paramInfo, shaderParams);
    }

    m_shaderGroup->add_shader(
        shaderInfo->shaderType.asChar(),
        shaderInfo->shaderName.asChar(),
        depNodeFn.name().asChar(),
        shaderParams);
}
void ShadingNetworkExporter::addConnections(const MObject& node)
{
    MStatus status;
    MFnDependencyNode depNodeFn(node);

    const OSLShaderInfo *shaderInfo =
        ShadingNodeRegistry::getShaderInfo(depNodeFn.typeName());

    if(!shaderInfo)
    {
        std::cout << "Skipping unsupported shader: " << depNodeFn.typeName() << "\n";
        return;
    }

    if(m_shadersExported.count(depNodeFn.name()) != 0)
    {
        std::cout << "Skipping already exported shader: " << depNodeFn.name() << "\n";
        return;
    }

    m_shadersExported.insert(depNodeFn.name());

    for(int i = 0, e = shaderInfo->paramInfo.size(); i < e; ++i)
    {
        const OSLParamInfo& paramInfo = shaderInfo->paramInfo[i];

        // Skip output attributes.
        if(paramInfo.isOutput)
            continue;

        MPlug plug = depNodeFn.findPlug(paramInfo.mayaAttributeName, &status);
        if(!status)
        {
            std::cout << "Skipping unknown attribute: "
                        << paramInfo.mayaAttributeName << std::endl;
            continue;
        }

        if(plug.isConnected())
        {
            MPlug srcPlug;
            if(AttributeUtils::getPlugConnectedTo(plug, srcPlug))
            {
                MFnDependencyNode srcDepNodeFn(srcPlug.node());

                const OSLShaderInfo *srcShaderInfo =
                    ShadingNodeRegistry::getShaderInfo(srcDepNodeFn.typeName());

                if(!srcShaderInfo)
                    continue;

                if(const OSLParamInfo *srcParamInfo = srcShaderInfo->findParam(srcPlug.name()))
                {
                    m_shaderGroup->add_connection(
                        srcDepNodeFn.name().asChar(),
                        srcParamInfo->paramName.asChar(),
                        depNodeFn.name().asChar(),
                        paramInfo.paramName.asChar());
                }

                addConnections(srcPlug.node());
            }
        }

        if(plug.isCompound() && plug.numConnectedChildren() != 0)
        {
            // ???
        }

        if(plug.isArray() && plug.numConnectedElements() != 0)
        {
            // ???
        }
    }
}