Example #1
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;
}
Example #2
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;
}
Example #3
0
void exportTerrain::printShadingData(const MFnMesh& theMesh, MString texture)
{
    MObjectArray    shaders;
    MIntArray	    indices;
    MPlug	    tPlug;
    MPlugArray      connections,inConnections;
    MObject	    node,shaderObject;
    MFnDependencyNode dpNode;
    MStatus	    status;
    
    int i,j;

    theMesh.getConnectedShaders(0 , shaders, indices);

    fout << "Shading Data:" << endl;

    //Will assume that only one shader is used, and therefore only prints
    //data for the first index;
    
    //Assuming only one shader
    dpNode.setObject( shaders[0] );
    dpNode.getConnections(connections);
    for(i=0;i < connections.length();++i){
	connections[i].connectedTo(inConnections,true,true);
	for(j=0;j<inConnections.length();++j){
	    node = inConnections[j].node();	
	    dpNode.setObject(node);
	    if(node.hasFn(MFn::kLambert) ){
		shaderObject = node;
	    }
	}
    }
    

    MFnLambertShader shader(shaderObject, &status);
    if(!status){
	status.perror("Unable to create MFnLambertShader!");
	return;
    }
    //Collect all the data
    fout << "Diffuse_Color: " << (shader.diffuseCoeff(&status)*(MColor(1.0,1.0,1.0) )*shader.color(&status)) * 
						(MColor(1.0,1.0,1.0) - shader.transparency(&status) )<< endl;
    fout << "Ambient: " << shader.ambientColor(&status) << endl;
    fout << "Emmision_Color: " << shader.incandescence(&status) << endl;	

	
    if(shaderObject.hasFn(MFn::kBlinn) ){
	MFnBlinnShader blinn(shaderObject);
	fout << "Specular_Color: " << blinn.specularColor() << endl;
	fout << "Shininess: " << blinn.eccentricity() << endl;
    }
    else if(shaderObject.hasFn(MFn::kPhong) ){
	MFnPhongShader phong(shaderObject);
	fout << "Specular_Color: " << phong.specularColor() << endl;
	fout << "Shininess: " << phong.cosPower() << endl;
    }
    else{
	fout << "Specular_Color: " << MColor() << endl;
	fout << "Shininess: " << double(0) << endl;
    }
    	
    fout << "Texture: " << texture << endl;

}