#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/MDrawRegistry.h>
#include <maya/MPxDrawOverride.h>
#include <maya/MUserData.h>
#include <maya/MDrawContext.h>
#include <maya/MHWGeometryUtilities.h>
#include <maya/MPointArray.h>
#include <maya/MGlobal.h>
#include <maya/MEventMessage.h>
#include <maya/MFnDependencyNode.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;
 
};
MString footPrint::drawDbClassification(
"drawdb/geometry/footPrint");
 
MString footPrint::drawRegistrantId(
"FootprintNodePlugin");
 
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:
    virtual ~FootPrintData() {}
};
{
public:
    {
        return new FootPrintDrawOverride(obj);
    }
    virtual ~FootPrintDrawOverride();
    {
        
        return false;
    }
    {
        
        fprintf(stderr, "footPrintDrawOverride: ");
        fprintf(stderr, message.
asChar());
        fprintf(stderr, "\n");
    }
private:
    FootPrintDrawOverride(
const MObject& obj);
    float getMultiplier(
const MDagPath& objPath) 
const;
 
    static void OnModelEditorChanged(void *clientData);
    footPrint*  fFootPrint;
    MCallbackId fModelEditorChangedCbId;
};
FootPrintDrawOverride::FootPrintDrawOverride(
const MObject& obj)
: 
MHWRender::MPxDrawOverride(obj, NULL, false)
{
        "modelEditorChanged", OnModelEditorChanged, this);
    fFootPrint = status ? dynamic_cast<footPrint*>(node.userNode()) : NULL;
}
FootPrintDrawOverride::~FootPrintDrawOverride()
{
    fFootPrint = NULL;
    if (fModelEditorChangedCbId != 0)
    {
        fModelEditorChangedCbId = 0;
    }
}
void FootPrintDrawOverride::OnModelEditorChanged(void *clientData)
{
    
    
    FootPrintDrawOverride *ovr = static_cast<FootPrintDrawOverride*>(clientData);
    if (ovr && ovr->fFootPrint)
    {
    }
}
{
    
}
float FootPrintDrawOverride::getMultiplier(
const MDagPath& objPath)
 const 
{
    
    if (status)
    {
        MPlug plug(footprintNode, footPrint::size);
 
        if (!plug.isNull())
        {
            if (plug.getValue(sizeVal))
            {
            }
        }
    }
    return 1.0f;
}
bool FootPrintDrawOverride::isBounded(
const MDagPath& ,
 
{
    return true;
}
{
    MPoint corner1( -0.17, 0.0, -0.7 );
 
    MPoint corner2( 0.17, 0.0, 0.3 );
 
    float multiplier = getMultiplier(objPath);
    corner1 = corner1 * multiplier;
    corner2 = corner2 * multiplier;
}
MUserData* FootPrintDrawOverride::prepareForDraw(
 
{
    
    
    
    
    
    FootPrintData* data = dynamic_cast<FootPrintData*>(oldData);
    if (!data)
    {
        data = new FootPrintData();
    }
    
    float fMultiplier = getMultiplier(objPath);
    data->fSoleLineList.clear();
    for (int i = 0; i < soleCount; i++)
    {
        data->fSoleLineList.append(sole[i][0] * fMultiplier, sole[i][1] * fMultiplier, sole[i][2] * fMultiplier);
    }
    data->fHeelLineList.clear();
    for (int i = 0; i < heelCount; i++)
    {
        data->fHeelLineList.append(heel[i][0] * fMultiplier, heel[i][1] * fMultiplier, heel[i][2] * fMultiplier);
    }
    data->fSoleTriangleList.clear();    
    for (int i = 1; i <= soleCount - 2; i++)
    {
        data->fSoleTriangleList.append(sole[0][0] * fMultiplier, sole[0][1] * fMultiplier, sole[0][2] * fMultiplier);
        data->fSoleTriangleList.append(sole[i][0] * fMultiplier, sole[i][1] * fMultiplier, sole[i][2] * fMultiplier);
        data->fSoleTriangleList.append(sole[i+1][0] * fMultiplier, sole[i+1][1] * fMultiplier, sole[i+1][2] * fMultiplier);
    }
    data->fHeelTriangleList.clear();    
    for (int i = 1; i <= heelCount - 2; i++)
    {
        data->fHeelTriangleList.append(heel[0][0] * fMultiplier, heel[0][1] * fMultiplier, heel[0][2] * fMultiplier);
        data->fHeelTriangleList.append(heel[i][0] * fMultiplier, heel[i][1] * fMultiplier, heel[i][2] * fMultiplier);
        data->fHeelTriangleList.append(heel[i+1][0] * fMultiplier, heel[i+1][1] * fMultiplier, heel[i+1][2] * fMultiplier);
    }
    
    return data;
}
void FootPrintDrawOverride::addUIDrawables(
{
    
    
    FootPrintData* pLocatorData = (FootPrintData*)data;
    if (!pLocatorData)
    {
        return;
    }
    
    drawManager.
setColor( pLocatorData->fColor );
    }
    
    MColor textColor( 0.1f, 0.8f, 0.8f, 1.0f ); 
 
}
{
    stat = addAttribute( size );
    if (!stat) {
        return stat;
    }
}
{
    MFnPlugin plugin( obj, PLUGIN_COMPANY, 
"3.0", 
"Any");
 
    status = plugin.registerNode(
                "footPrint",
                footPrint::id,
                &footPrint::creator,
                &footPrint::initialize,
                &footPrint::drawDbClassification);
    if (!status) {
        status.
perror(
"registerNode");
        return status;
    }
        footPrint::drawDbClassification,
        footPrint::drawRegistrantId,
        FootPrintDrawOverride::Creator);
    if (!status) {
        status.
perror(
"registerDrawOverrideCreator");
        return status;
    }
    return status;
}
{
        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;
}