#include <maya/MObject.h>
#include <maya/MColor.h>
#include <maya/MString.h>
#include <maya/MStringArray.h>
#include <maya/MFnDependencyNode.h>
#include <maya/MPlug.h>
#include <maya/MPlugArray.h>
#include <assert.h>
#include "ShadingConnection.h"
{
this->m_shaderObj = shaderObj;
this->m_shapeName = shapeName;
this->m_directConnection = true;
if (attribute != "")
traverseAttribute(attribute);
}
ShadingConnection::TYPE ShadingConnection::traverseAttribute(
MString attributeName)
{
MPlug plug = shaderNode.findPlug( attributeName, &status );
assert(status);
this->m_attributeName = attributeName;
return analyzePlug(plug);
}
ShadingConnection::TYPE ShadingConnection::analyzePlug(
MPlug plug)
{
plug.
connectedTo( connectedElements,
true,
false, &status );
assert(status);
if (connectedElements.
length() == 0)
{
assert(numChildren == 3);
float red, green, blue;
return setConstantColor(
MColor(red, green, blue, 1.0));
}
MObject connectedObject = connectedElements[0].node(&status);
assert(status);
{
return traverseTripleShadingSwitch(connectedObject);
}
return setTexture(connectedObject);
}
ShadingConnection::TYPE ShadingConnection::traverseTripleShadingSwitch(
MObject connectedObject)
{
m_directConnection = false;
MPlug inputPlug = node.findPlug(
"input" );
assert( numChildren >= 2);
for (unsigned int index = 0; index < numElements; index++)
{
inShapePlug.
connectedTo( inShapeConnections,
true,
false, &status );
unsigned int numCorrespondingShapes = inShapeConnections.
length();
for (unsigned int shapeNum = 0; shapeNum < numCorrespondingShapes; shapeNum++)
{
MObject inShapeObj = inShapeConnections[0].node(&status);
assert(status);
MString inShapeName = inShape.name();
if (inShapeName == m_shapeName)
return analyzePlug(inTexturePlug);
}
}
MPlug defaultPlug = node.findPlug(
"default");
return analyzePlug(defaultPlug);
}
ShadingConnection::TYPE ShadingConnection::type()
{
return m_type;
}
MColor ShadingConnection::constantColor()
{
assert(m_type == CONSTANT_COLOR);
return m_constantColor;
}
MObject ShadingConnection::texture()
{
assert(m_type == TEXTURE);
return m_texture;
}
MObject ShadingConnection::shaderObj()
{
return m_shaderObj;
}
MString ShadingConnection::shaderName()
{
assert(stat);
return shaderNode.name();
}
MString ShadingConnection::attributeName()
{
return m_attributeName;
}
MString ShadingConnection::shapeName()
{
return m_shapeName;
}
ShadingConnection::TYPE ShadingConnection::setConstantColor(
MColor col)
{
m_constantColor = col;
m_type = CONSTANT_COLOR;
return m_type;
}
ShadingConnection::TYPE ShadingConnection::setTexture(
MObject texture)
{
m_texture = texture;
m_type = TEXTURE;
return m_type;
}
bool ShadingConnection::isDirectConnection()
{
return m_directConnection;
}