#include <maya/MPxLocatorNode.h>
#include <maya/MString.h>
#include <maya/MTypeId.h>
#include <maya/MPlug.h>
#include <maya/MVector.h>
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>
#include <maya/MColor.h>
#include <maya/M3dView.h>
#include <maya/MFnPlugin.h>
#include <maya/MDistance.h>
#include <maya/MFnUnitAttribute.h>
#include <maya/MGlobal.h>
#include <maya/MDrawRegistry.h>
#include <maya/MPxGeometryOverride.h>
#include <maya/MUserData.h>
#include <maya/MDrawContext.h>
#include <maya/MShaderManager.h>
#include <maya/MHWGeometry.h>
#include <maya/MHWGeometryUtilities.h>
#include <maya/MPointArray.h>
#include <assert.h>
static float sole[][3] = { { 0.00f, 0.0f, -0.70f },
{ 0.04f, 0.0f, -0.69f },
{ 0.09f, 0.0f, -0.65f },
{ 0.13f, 0.0f, -0.61f },
{ 0.16f, 0.0f, -0.54f },
{ 0.17f, 0.0f, -0.46f },
{ 0.17f, 0.0f, -0.35f },
{ 0.16f, 0.0f, -0.25f },
{ 0.15f, 0.0f, -0.14f },
{ 0.13f, 0.0f, 0.00f },
{ 0.00f, 0.0f, 0.00f },
{ -0.13f, 0.0f, 0.00f },
{ -0.15f, 0.0f, -0.14f },
{ -0.16f, 0.0f, -0.25f },
{ -0.17f, 0.0f, -0.35f },
{ -0.17f, 0.0f, -0.46f },
{ -0.16f, 0.0f, -0.54f },
{ -0.13f, 0.0f, -0.61f },
{ -0.09f, 0.0f, -0.65f },
{ -0.04f, 0.0f, -0.69f },
{ -0.00f, 0.0f, -0.70f } };
static float heel[][3] = { { 0.00f, 0.0f, 0.06f },
{ 0.13f, 0.0f, 0.06f },
{ 0.14f, 0.0f, 0.15f },
{ 0.14f, 0.0f, 0.21f },
{ 0.13f, 0.0f, 0.25f },
{ 0.11f, 0.0f, 0.28f },
{ 0.09f, 0.0f, 0.29f },
{ 0.04f, 0.0f, 0.30f },
{ 0.00f, 0.0f, 0.30f },
{ -0.04f, 0.0f, 0.30f },
{ -0.09f, 0.0f, 0.29f },
{ -0.11f, 0.0f, 0.28f },
{ -0.13f, 0.0f, 0.25f },
{ -0.14f, 0.0f, 0.21f },
{ -0.14f, 0.0f, 0.15f },
{ -0.13f, 0.0f, 0.06f },
{ -0.00f, 0.0f, 0.06f } };
static int soleCount = 21;
static int heelCount = 17;
{
public:
footPrint();
virtual ~footPrint();
static void * creator();
public:
static MString drawDbClassification;
};
MTypeId footPrint::id( 0x00080033 );
MString footPrint::drawDbClassification(
"drawdb/geometry/light/footPrint_GeometryOverride");
static bool sMakeFootPrintDirLight = (getenv("MAYA_FOOTPRINT_GEOMETRY_OVERRIDE_AS_DIRLIGHT") != NULL);
static MString lightClassification(
"light:drawdb/geometry/light/footPrint_GeometryOverride:drawdb/light/directionalLight");
MString footPrint::drawRegistrantId(
"FootprintNode_GeometryOverridePlugin");
static bool sUseLegacyDraw = (getenv("MAYA_ENABLE_VP2_PLUGIN_LOCATOR_LEGACY_DRAW") != NULL);
footPrint::footPrint() {}
footPrint::~footPrint() {}
{
}
{
MPlug plug( thisNode, size );
plug.getValue( sizeVal );
{
glPushAttrib( GL_CURRENT_BIT );
} else {
}
glBegin( GL_TRIANGLE_FAN );
int i;
int last = soleCount - 1;
for ( i = 0; i < last; ++i ) {
glVertex3f( sole[i][0] * multiplier,
sole[i][1] * multiplier,
sole[i][2] * multiplier );
}
glEnd();
glBegin( GL_TRIANGLE_FAN );
last = heelCount - 1;
for ( i = 0; i < last; ++i ) {
glVertex3f( heel[i][0] * multiplier,
heel[i][1] * multiplier,
heel[i][2] * multiplier );
}
glEnd();
glPopAttrib();
}
glBegin( GL_LINES );
int i;
int last = soleCount - 1;
for ( i = 0; i < last; ++i ) {
glVertex3f( sole[i][0] * multiplier,
sole[i][1] * multiplier,
sole[i][2] * multiplier );
glVertex3f( sole[i+1][0] * multiplier,
sole[i+1][1] * multiplier,
sole[i+1][2] * multiplier );
}
last = heelCount - 1;
for ( i = 0; i < last; ++i ) {
glVertex3f( heel[i][0] * multiplier,
heel[i][1] * multiplier,
heel[i][2] * multiplier );
glVertex3f( heel[i+1][0] * multiplier,
heel[i+1][1] * multiplier,
heel[i+1][2] * multiplier );
}
glEnd();
}
bool footPrint::isBounded() const
{
return true;
}
{
MPlug plug( thisNode, size );
plug.getValue( sizeVal );
MPoint corner1( -0.17, 0.0, -0.7 );
MPoint corner2( 0.17, 0.0, 0.3 );
corner1 = corner1 * multiplier;
corner2 = corner2 * multiplier;
}
{
}
void* footPrint::creator()
{
return new footPrint();
}
{
public:
{
return new FootPrintGeometryOverride(obj);
}
virtual ~FootPrintGeometryOverride();
{
return false;
}
{
fprintf(stderr, "footPrintGeometryOverride: ");
fprintf(stderr, message.
asChar());
fprintf(stderr, "\n");
}
private:
FootPrintGeometryOverride(
const MObject& obj);
float mMultiplier;
bool mMultiplierChanged;
};
FootPrintGeometryOverride::FootPrintGeometryOverride(
const MObject& obj)
, mSolidUIShader(NULL)
, mLocatorNode(obj)
, mMultiplier(0.0f)
, mMultiplierChanged(true)
{
if (!renderer)
return;
if (!shaderMgr)
return;
}
FootPrintGeometryOverride::~FootPrintGeometryOverride()
{
if(mSolidUIShader)
{
if (renderer)
{
if (shaderMgr)
{
}
}
mSolidUIShader = NULL;
}
}
{
}
const MString colorParameterName_ =
"solidColor";
const MString wireframeHeelItemName_ =
"heelLocatorWires";
const MString wireframeSoleItemName_ =
"soleLocatorWires";
const MString shadedHeelItemName_ =
"heelLocatorTriangles";
const MString shadedSoleItemName_ =
"soleLocatorTriangles";
void FootPrintGeometryOverride::updateDG()
{
MPlug plug(mLocatorNode, footPrint::size);
float newScale = 1.0f;
if (!plug.isNull())
{
if (plug.getValue(sizeVal))
{
}
}
if (newScale != mMultiplier)
{
mMultiplier = newScale;
mMultiplierChanged = true;
}
}
{
int index = list.
indexOf(wireframeHeelItemName_);
if (index < 0)
{
wireframeHeelItemName_,
}
else
{
wireframeHeel = list.
itemAt(index);
}
if(wireframeHeel)
{
if (mSolidUIShader)
{
float wireframeColor[4] = { color.
r, color.
g, color.
b, 1.0f };
mSolidUIShader->setParameter(colorParameterName_, wireframeColor);
}
}
index = list.
indexOf(wireframeSoleItemName_);
if (index < 0)
{
wireframeSoleItemName_,
}
else
{
wireframeSole = list.
itemAt(index);
}
if(wireframeSole)
{
if (mSolidUIShader)
{
float wireframeColor[4] = { color.
r, color.
g, color.
b, 1.0f };
mSolidUIShader->setParameter(colorParameterName_, wireframeColor);
}
}
index = list.
indexOf(shadedHeelItemName_);
if (index < 0)
{
shadedHeelItemName_,
}
else
{
shadedHeelItem = list.
itemAt(index);
}
if(shadedHeelItem)
{
if (mSolidUIShader)
{
float wireframeColor[4] = { color.
r, color.
g, color.
b, 1.0f };
mSolidUIShader->setParameter(colorParameterName_, wireframeColor);
}
}
index = list.
indexOf(shadedSoleItemName_);
if (index < 0)
{
shadedSoleItemName_,
}
else
{
shadedSoleItem = list.
itemAt(index);
}
if(shadedSoleItem)
{
if (mSolidUIShader)
{
float wireframeColor[4] = { color.
r, color.
g, color.
b, 1.0f };
mSolidUIShader->setParameter(colorParameterName_, wireframeColor);
}
}
}
void FootPrintGeometryOverride::populateGeometry(
{
float* vertices = NULL;
const int numberOfVertexRequirments = vertexBufferDescriptorList.
length();
for (int requirmentNumber = 0; requirmentNumber < numberOfVertexRequirments; ++requirmentNumber)
{
if (!vertexBufferDescriptorList.
getDescriptor(requirmentNumber, vertexBufferDescriptor))
{
continue;
}
switch (vertexBufferDescriptor.
semantic())
{
{
if (!verticesBuffer)
{
if (verticesBuffer)
{
vertices = (
float*)verticesBuffer->
acquire(soleCount+heelCount);
}
}
}
break;
default:
break;
}
}
int verticesPointerOffset = 0;
for (int currentVertex = 0 ; currentVertex < soleCount+heelCount; ++currentVertex)
{
if(vertices)
{
if (currentVertex < heelCount)
{
int heelVtx = currentVertex;
vertices[verticesPointerOffset++] = heel[heelVtx][0] * mMultiplier;
vertices[verticesPointerOffset++] = heel[heelVtx][1] * mMultiplier;
vertices[verticesPointerOffset++] = heel[heelVtx][2] * mMultiplier;
}
else
{
int soleVtx = currentVertex - heelCount;
vertices[verticesPointerOffset++] = sole[soleVtx][0] * mMultiplier;
vertices[verticesPointerOffset++] = sole[soleVtx][1] * mMultiplier;
vertices[verticesPointerOffset++] = sole[soleVtx][2] * mMultiplier;
}
}
}
if(verticesBuffer && vertices)
{
verticesBuffer->
commit(vertices);
}
for (
int i=0; i < renderItems.
length(); ++i)
{
if (!item)
{
continue;
}
int startIndex = 0;
int endIndex = 0;
int numIndex = 0;
bool isWireFrame = true;
if (item->
name() == wireframeHeelItemName_ )
{
numIndex = heelCount;
}
else if (item->
name() == wireframeSoleItemName_ )
{
startIndex = heelCount;
numIndex = soleCount;
}
else if (item->
name() == shadedHeelItemName_ )
{
numIndex = heelCount - 2;
startIndex = 1;
endIndex = heelCount - 2;
isWireFrame = false;
}
else if (item->
name() == shadedSoleItemName_ )
{
startIndex = heelCount;
endIndex = heelCount + soleCount - 2;
numIndex = soleCount - 2;
isWireFrame = false;
}
if (numIndex)
{
unsigned int* indices = (
unsigned int*)indexBuffer->
acquire(numIndex);
for(int i = 0; i < numIndex; )
{
if (isWireFrame)
{
indices[i] = startIndex + i;
i++;
}
else
{
indices[i] = startIndex + i/2;
if (i+1 < numIndex)
indices[i+1] = endIndex - i/2;
i += 2;
}
}
}
}
mMultiplierChanged = false;
}
{
stat = addAttribute( size );
if (!stat) {
return stat;
}
}
{
MFnPlugin plugin( obj, PLUGIN_COMPANY,
"3.0",
"Any");
status = plugin.registerNode(
"footPrint_GeometryOverride",
footPrint::id,
&footPrint::creator,
&footPrint::initialize,
sUseLegacyDraw ? NULL : (sMakeFootPrintDirLight ? &lightClassification : &footPrint::drawDbClassification));
if (!status) {
status.
perror(
"registerNode");
return status;
}
if (!sUseLegacyDraw)
{
footPrint::drawDbClassification,
footPrint::drawRegistrantId,
FootPrintGeometryOverride::Creator);
if (!status) {
status.
perror(
"registerDrawOverrideCreator");
return status;
}
}
return status;
}
{
if (!sUseLegacyDraw)
{
footPrint::drawDbClassification,
footPrint::drawRegistrantId);
if (!status) {
status.
perror(
"deregisterDrawOverrideCreator");
return status;
}
}
status = plugin.deregisterNode( footPrint::id );
if (!status) {
status.
perror(
"deregisterNode");
return status;
}
return status;
}