#if _MSC_VER >= 1700
#pragma warning( disable: 4005 )
#endif
#include <maya/MPxLocatorNode.h>
#include <maya/MString.h>
#include <maya/MDagPath.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/MMatrix.h>
#include <maya/MFnUnitAttribute.h>
#include <maya/MDrawRegistry.h>
#include <maya/MPxDrawOverride.h>
#include <maya/MUserData.h>
#include <maya/MDrawContext.h>
#include <maya/MGlobal.h>
#include <maya/MSelectionList.h>
#include <maya/MViewport2Renderer.h>
#include <maya/MHWGeometryUtilities.h>
#include <maya/MStateManager.h>
#include <maya/MShaderManager.h>
#include <maya/MRenderTargetManager.h>
#include <maya/MAnimControl.h>
#include <assert.h>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <d3d11.h>
#if _MSC_VER < 1700
#include <d3dx11.h>
#include <xnamath.h>
#else
#include <dxgi.h>
#include <DirectXMath.h>
using namespace DirectX;
#endif
#include <d3dcompiler.h>
#ifndef D3DCOMPILE_ENABLE_STRICTNESS
#define D3DCOMPILE_ENABLE_STRICTNESS D3D10_SHADER_ENABLE_STRICTNESS
#define D3DCOMPILE_DEBUG D3D10_SHADER_DEBUG
#endif
#endif //_WIN32
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();
virtual bool isBounded() const;
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() {}
float fMultiplier;
float fColor[3];
bool fCustomBoxDraw;
};
class FootPrintDrawAgent
{
public:
FootPrintDrawAgent(){}
virtual ~FootPrintDrawAgent(){}
virtual void drawShaded( float multiplier ) = 0;
virtual void drawBoundingBox(
const MPoint&,
const MPoint&) = 0;
virtual void drawWireframe( float multiplier ) = 0;
virtual void beginDraw() = 0;
virtual void endDraw() = 0;
mWorldViewMatrix = wvMatrix;
mProjectionMatrix = projMatrix;
}
void setColor(
const MColor& color){
mColor = color;
}
protected:
};
class FootPrintDrawAgentGL : public FootPrintDrawAgent
{
public:
static FootPrintDrawAgentGL& getDrawAgent(){
static FootPrintDrawAgentGL obj;
return obj;
}
virtual void drawShaded( float multiplier );
virtual void drawBoundingBox(
const MPoint& min,
const MPoint& max );
virtual void drawWireframe( float multiplier );
virtual void beginDraw();
virtual void endDraw();
private:
FootPrintDrawAgentGL(){}
~FootPrintDrawAgentGL(){}
FootPrintDrawAgentGL( const FootPrintDrawAgentGL& v ){}
FootPrintDrawAgentGL operator = (const FootPrintDrawAgentGL& v){ return *this; }
};
#ifdef _WIN32
class FootPrintDrawAgentDX : public FootPrintDrawAgent
{
public:
static FootPrintDrawAgentDX& getDrawAgent(){
static FootPrintDrawAgentDX obj;
return obj;
}
virtual void drawShaded( float multiplier );
virtual void drawBoundingBox(
const MPoint& min,
const MPoint& max );
virtual void drawWireframe( float multiplier );
virtual void beginDraw();
virtual void endDraw();
bool releaseDXResources();
private:
ID3D11Device* mDevicePtr;
ID3D11DeviceContext* mDeviceContextPtr;
ID3D11Buffer* mBoundingboxVertexBufferPtr;
ID3D11Buffer* mBoundingboxIndexBufferPtr;
ID3D11Buffer* mSoleVertexBufferPtr;
ID3D11Buffer* mHeelVertexBufferPtr;
ID3D11Buffer* mSoleWireIndexBufferPtr;
ID3D11Buffer* mSoleShadedIndexBufferPtr;
ID3D11Buffer* mHeelWireIndexBufferPtr;
ID3D11Buffer* mHeelShadedIndexBufferPtr;
ID3D11Buffer* mConstantBufferPtr;
ID3D11VertexShader* mVertexShaderPtr;
ID3D11PixelShader* mPixelShaderPtr;
ID3D11InputLayout* mVertexLayoutPtr;
unsigned int mStride;
unsigned int mOffset;
struct ConstantBufferDef
{
XMMATRIX fWVP;
XMFLOAT4 fMatColor;
};
bool initShadersDX();
bool initBuffersDX();
void setupConstantBuffer( const XMMATRIX& scale );
private:
FootPrintDrawAgentDX():
mDevicePtr(NULL), mDeviceContextPtr(NULL), mStride(sizeof(float)*3), mOffset(0),
mBoundingboxVertexBufferPtr(NULL),
mBoundingboxIndexBufferPtr(NULL),
mSoleVertexBufferPtr(NULL),
mHeelVertexBufferPtr(NULL),
mSoleWireIndexBufferPtr(NULL),
mSoleShadedIndexBufferPtr(NULL),
mHeelWireIndexBufferPtr(NULL),
mHeelShadedIndexBufferPtr(NULL),
mConstantBufferPtr(NULL),
mVertexShaderPtr(NULL),
mPixelShaderPtr(NULL),
mVertexLayoutPtr(NULL)
{}
~FootPrintDrawAgentDX(){}
FootPrintDrawAgentDX( const FootPrintDrawAgentDX& v ){}
FootPrintDrawAgentDX operator = (const FootPrintDrawAgentDX& v){ return *this; }
};
#endif // _WIN32
void FootPrintDrawAgentGL::beginDraw()
{
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadMatrixd(mWorldViewMatrix.matrix[0]);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadMatrixd(mProjectionMatrix.matrix[0]);
glPushAttrib( GL_CURRENT_BIT );
}
void FootPrintDrawAgentGL::endDraw()
{
glPopAttrib();
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}
void FootPrintDrawAgentGL::drawShaded( float multiplier )
{
glColor4fv( &(mColor.r) );
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();
}
void FootPrintDrawAgentGL::drawBoundingBox(
const MPoint& min,
const MPoint& max )
{
glColor4fv( &(mColor.r) );
float bottomLeftFront[3] = { (float)min[0], (float)min[1], (float)min[2] };
float topLeftFront[3] = { (float)min[0], (float)max[1], (float)min[2] };
float bottomRightFront[3] = { (float)max[0], (float)min[1], (float)min[2] };
float topRightFront[3] = { (float)max[0], (float)max[1], (float)min[2] };
float bottomLeftBack[3] = { (float)min[0], (float)min[1], (float)max[2] };
float topLeftBack[3] = { (float)min[0], (float)max[1], (float)max[2] };
float bottomRightBack[3] = { (float)max[0], (float)min[1], (float)max[2] };
float topRightBack[3] = { (float)max[0], (float)max[1], (float)max[2] };
glBegin( GL_LINES );
glVertex3fv( bottomLeftFront );
glVertex3fv( bottomRightFront );
glVertex3fv( bottomRightFront );
glVertex3fv( bottomRightBack );
glVertex3fv( bottomRightBack );
glVertex3fv( bottomLeftBack );
glVertex3fv( bottomLeftBack );
glVertex3fv( bottomLeftFront );
glVertex3fv( topLeftFront );
glVertex3fv( topRightFront );
glVertex3fv( topRightFront );
glVertex3fv( topRightBack );
glVertex3fv( topRightBack );
glVertex3fv( topLeftBack );
glVertex3fv( topLeftBack );
glVertex3fv( topLeftFront );
glVertex3fv( bottomLeftFront );
glVertex3fv( topLeftFront );
glVertex3fv( bottomRightFront );
glVertex3fv( topRightFront );
glVertex3fv( bottomRightBack );
glVertex3fv( topRightBack );
glVertex3fv( bottomLeftBack );
glVertex3fv( topLeftBack );
glEnd();
}
void FootPrintDrawAgentGL::drawWireframe( float multiplier )
{
glColor4fv( &(mColor.r) );
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();
}
#ifdef _WIN32
void FootPrintDrawAgentDX::beginDraw()
{
if( !mDevicePtr || !mDeviceContextPtr ){
if ( theRenderer ){
if ( mDevicePtr ){
mDevicePtr->GetImmediateContext( &mDeviceContextPtr );
}
}
}
assert( mDevicePtr );
assert( mDeviceContextPtr );
if ( mDevicePtr && mDeviceContextPtr ){
if ( initShadersDX() ){
mDeviceContextPtr->VSSetShader(mVertexShaderPtr, NULL, 0);
mDeviceContextPtr->IASetInputLayout(mVertexLayoutPtr);
mDeviceContextPtr->PSSetShader(mPixelShaderPtr, NULL, 0);
}
initBuffersDX();
}
}
void FootPrintDrawAgentDX::endDraw()
{}
void FootPrintDrawAgentDX::setupConstantBuffer( const XMMATRIX& scale )
{
assert( mDeviceContextPtr );
if ( !mDeviceContextPtr )
return;
XMMATRIX dxTransform = XMMATRIX(
(float)mWorldViewMatrix.matrix[0][0], (float)mWorldViewMatrix.matrix[0][1], (float)mWorldViewMatrix.matrix[0][2], (float)mWorldViewMatrix.matrix[0][3],
(float)mWorldViewMatrix.matrix[1][0], (float)mWorldViewMatrix.matrix[1][1], (float)mWorldViewMatrix.matrix[1][2], (float)mWorldViewMatrix.matrix[1][3],
(float)mWorldViewMatrix.matrix[2][0], (float)mWorldViewMatrix.matrix[2][1], (float)mWorldViewMatrix.matrix[2][2], (float)mWorldViewMatrix.matrix[2][3],
(float)mWorldViewMatrix.matrix[3][0], (float)mWorldViewMatrix.matrix[3][1], (float)mWorldViewMatrix.matrix[3][2], (float)mWorldViewMatrix.matrix[3][3]);
XMMATRIX dxProjection = XMMATRIX(
(float)mProjectionMatrix.matrix[0][0], (float)mProjectionMatrix.matrix[0][1], (float)mProjectionMatrix.matrix[0][2], (float)mProjectionMatrix.matrix[0][3],
(float)mProjectionMatrix.matrix[1][0], (float)mProjectionMatrix.matrix[1][1], (float)mProjectionMatrix.matrix[1][2], (float)mProjectionMatrix.matrix[1][3],
(float)mProjectionMatrix.matrix[2][0], (float)mProjectionMatrix.matrix[2][1], (float)mProjectionMatrix.matrix[2][2], (float)mProjectionMatrix.matrix[2][3],
(float)mProjectionMatrix.matrix[3][0], (float)mProjectionMatrix.matrix[3][1], (float)mProjectionMatrix.matrix[3][2], (float)mProjectionMatrix.matrix[3][3]);
ConstantBufferDef cb;
cb.fWVP = XMMatrixTranspose(scale * dxTransform * dxProjection);
cb.fMatColor = XMFLOAT4( mColor.r, mColor.g, mColor.b, mColor.a);
mDeviceContextPtr->UpdateSubresource(mConstantBufferPtr, 0, NULL, &cb, 0, 0);
mDeviceContextPtr->VSSetConstantBuffers(0, 1, &mConstantBufferPtr);
mDeviceContextPtr->PSSetConstantBuffers(0, 1, &mConstantBufferPtr);
}
void FootPrintDrawAgentDX::drawShaded( float multiplier )
{
assert( mDeviceContextPtr );
if ( !mDeviceContextPtr )
return;
XMMATRIX scale(
multiplier, 0.0f, 0.0f, 0.0f,
0.0f, multiplier, 0.0f, 0.0f,
0.0f, 0.0f, multiplier, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f );
setupConstantBuffer( scale );
mDeviceContextPtr->IASetVertexBuffers(0, 1, &mSoleVertexBufferPtr, &mStride, &mOffset);
mDeviceContextPtr->IASetIndexBuffer(mSoleShadedIndexBufferPtr, DXGI_FORMAT_R16_UINT, 0);
mDeviceContextPtr->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
mDeviceContextPtr->DrawIndexed(3 * (soleCount-2), 0, 0);
mDeviceContextPtr->IASetVertexBuffers(0, 1, &mHeelVertexBufferPtr, &mStride, &mOffset);
mDeviceContextPtr->IASetIndexBuffer(mHeelShadedIndexBufferPtr, DXGI_FORMAT_R16_UINT, 0);
mDeviceContextPtr->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
mDeviceContextPtr->DrawIndexed(3 * (heelCount-2), 0, 0);
}
void FootPrintDrawAgentDX::drawBoundingBox(
const MPoint& min,
const MPoint& max )
{
assert( mDeviceContextPtr );
if ( !mDeviceContextPtr )
return;
XMMATRIX scale(
static_cast<float>(max[0]- min[0]), 0.0f, 0.0f, 0.0f,
0.0f, static_cast<float>(max[1]-min[1]), 0.0f, 0.0f,
0.0f, 0.0f, static_cast<float>(max[2]-min[2]), 0.0f,
0.0f, 0.0f, 0.0f, 1.0f );
setupConstantBuffer( scale );
mDeviceContextPtr->IASetVertexBuffers(0, 1, &mBoundingboxVertexBufferPtr, &mStride, &mOffset);
mDeviceContextPtr->IASetIndexBuffer(mBoundingboxIndexBufferPtr, DXGI_FORMAT_R16_UINT, 0);
mDeviceContextPtr->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST);
mDeviceContextPtr->DrawIndexed(2 * 12, 0, 0);
}
void FootPrintDrawAgentDX::drawWireframe( float multiplier )
{
assert( mDeviceContextPtr );
if ( !mDeviceContextPtr )
return;
XMMATRIX scale(
multiplier, 0.0f, 0.0f, 0.0f,
0.0f, multiplier, 0.0f, 0.0f,
0.0f, 0.0f, multiplier, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f );
setupConstantBuffer( scale );
mDeviceContextPtr->IASetVertexBuffers(0, 1, &mSoleVertexBufferPtr, &mStride, &mOffset);
mDeviceContextPtr->IASetIndexBuffer(mSoleWireIndexBufferPtr, DXGI_FORMAT_R16_UINT, 0);
mDeviceContextPtr->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST);
mDeviceContextPtr->DrawIndexed(2 * (soleCount-1), 0, 0);
mDeviceContextPtr->IASetVertexBuffers(0, 1, &mHeelVertexBufferPtr, &mStride, &mOffset);
mDeviceContextPtr->IASetIndexBuffer(mHeelWireIndexBufferPtr, DXGI_FORMAT_R16_UINT, 0);
mDeviceContextPtr->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST);
mDeviceContextPtr->DrawIndexed(2 * (heelCount-1), 0, 0);
}
#endif // _WIN32
{
public:
{
return new FootPrintDrawOverride(obj);
}
virtual ~FootPrintDrawOverride();
virtual bool isBounded(
virtual bool disableInternalBoundingBoxDraw() const;
virtual bool hasUIDrawables() const { return true; }
virtual void addUIDrawables(
protected:
bool mCustomBoxDraw;
private:
FootPrintDrawOverride(
const MObject& obj);
float getMultiplier(
const MDagPath& objPath)
const;
};
FootPrintDrawOverride::FootPrintDrawOverride(
const MObject& obj)
: MHWRender::MPxDrawOverride(obj, FootPrintDrawOverride::draw)
, mCustomBoxDraw(true)
{
}
FootPrintDrawOverride::~FootPrintDrawOverride()
{
}
{
}
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;
FootPrintDrawOverride *nonConstThis = (FootPrintDrawOverride *)this;
nonConstThis->mCurrentBoundingBox.clear();
nonConstThis->mCurrentBoundingBox.expand( corner1 );
nonConstThis->mCurrentBoundingBox.expand( corner2 );
return mCurrentBoundingBox;
}
bool FootPrintDrawOverride::disableInternalBoundingBoxDraw() const
{
return mCustomBoxDraw;
}
MUserData* FootPrintDrawOverride::prepareForDraw(
{
FootPrintData* data = dynamic_cast<FootPrintData*>(oldData);
if (!data)
{
data = new FootPrintData();
}
data->fMultiplier = getMultiplier(objPath);
data->fColor[0] = color.
r;
data->fColor[1] = color.
g;
data->fColor[2] = color.
b;
data->fCustomBoxDraw = mCustomBoxDraw;
data->fCurrentBoundingBox = mCurrentBoundingBox;
return data;
}
void FootPrintDrawOverride::addUIDrawables(
{
MColor textColor( 0.1f, 0.8f, 0.8f, 1.0f );
}
{
const FootPrintData* footData = dynamic_cast<const FootPrintData*>(data);
if (!footData)
return;
bool debugDestination = false;
if (debugDestination)
{
MString destinationType =
" 3d viewport";
destinationType = " 2d viewport";
destinationType = "n image";
printf(
"footprint node render destination is a%s. Destination name=%s\n", destinationType.
asChar(), destinationIdentifier.
asChar());
}
if ( objectOverrideInfo.
fOverrideEnabled && !objectOverrideInfo.
fEnableVisible )
return;
bool drawAsBoundingbox =
if ( drawAsBoundingbox && !footData->fCustomBoxDraw )
{
return;
}
if (!objectOverrideInfo.
fPlaybackVisible &&
(animPlay || animScrub))
{
return;
}
{
if (!animPlay && !animScrub)
drawAsBoundingbox = true;
}
if (!theRenderer)
return;
bool castingShadows = false;
for (
unsigned int i=0; i<passSem.
length(); i++)
{
castingShadows = true;
}
bool debugPassInformation = false;
if (debugPassInformation)
{
printf(
"footprint node drawing in pass[%s], semantic[", passId.
asChar());
for (
unsigned int i=0; i<passSem.
length(); i++)
printf(" %s", passSem[i].asChar());
printf("\n");
}
float multiplier = footData->fMultiplier;
float color[4] = {
footData->fColor[0],
footData->fColor[1],
footData->fColor[2],
1.0f
};
bool requireBlending = false;
if (!castingShadows)
{
{
color[0] = color[1] = color[2] = (color[0] + color[1] + color[2]) / 3.0f;
}
{
requireBlending = true;
color[3] = 0.3f;
}
}
bool rasterStateModified = false;
{
if (stateMgr && requireBlending)
{
if (!blendState)
{
}
if (blendState)
{
}
}
if (pOldRasterState)
{
if (desc.cullMode != cullMode)
{
if (!rasterState)
{
desc.cullMode = cullMode;
}
if (rasterState)
{
rasterStateModified = true;
}
}
}
}
FootPrintDrawAgentGL& drawAgentRef = FootPrintDrawAgentGL::getDrawAgent();
FootPrintDrawAgent* drawAgentPtr = &drawAgentRef;
#ifdef _WIN32
{
FootPrintDrawAgentDX& drawAgentRef = FootPrintDrawAgentDX::getDrawAgent();
drawAgentPtr = &drawAgentRef;
}
#endif
assert( drawAgentPtr );
if ( drawAgentPtr ){
drawAgentPtr->setColor(
MColor(color[0],color[1],color[2],color[3]) );
drawAgentPtr->setMatrix( transform, projection );
drawAgentPtr->beginDraw();
if ( drawAsBoundingbox )
{
MPoint min = footData->fCurrentBoundingBox.min();
MPoint max = footData->fCurrentBoundingBox.max();
drawAgentPtr->drawBoundingBox( min, max );
} else {
const bool overideTemplated = objectOverrideInfo.fOverrideEnabled &&
const bool overrideNoShaded = objectOverrideInfo.fOverrideEnabled && !objectOverrideInfo.
fEnableShading;
if ( overideTemplated || overrideNoShaded ){
drawAgentPtr->drawWireframe( multiplier );
} else {
if( (displayStyle & MHWRender::MFrameContext::kGouraudShaded) ||
{
drawAgentPtr->drawShaded( multiplier );
}
{
drawAgentPtr->drawWireframe( multiplier );
}
}
}
drawAgentPtr->endDraw();
}
if(stateMgr && (displayStyle & MHWRender::MFrameContext::kGouraudShaded))
{
if (stateMgr && pOldBlendState)
{
}
if (rasterStateModified && pOldRasterState)
{
}
}
}
#ifdef _WIN32
bool FootPrintDrawAgentDX::initShadersDX()
{
assert( mDevicePtr );
if ( !mDevicePtr )
return false;
HRESULT hr;
DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
ID3DBlob* vsBlob = NULL;
ID3DBlob* psBlob = NULL;
ID3DBlob* pErrorBlob;
if (!mVertexShaderPtr)
{
#if _MSC_VER < 1700
hr = D3DX11CompileFromFile(
effectLocation.asChar(),
NULL,
NULL,
"mainVS",
"vs_5_0",
dwShaderFlags,
0,
NULL,
&vsBlob,
&pErrorBlob,
NULL);
#else
hr = D3DCompileFromFile(
effectLocation.asWChar(),
NULL,
NULL,
"mainVS",
"vs_5_0",
dwShaderFlags,
0,
&vsBlob,
&pErrorBlob);
#endif
if (FAILED(hr))
{
printf("Failed to compile vertex shader\n");
if (pErrorBlob) pErrorBlob->Release();
return false;
}
if (pErrorBlob) pErrorBlob->Release();
hr = mDevicePtr->CreateVertexShader(
vsBlob->GetBufferPointer(), vsBlob->GetBufferSize(), NULL, &mVertexShaderPtr);
if (FAILED(hr))
{
printf("Failed to create vertex shader\n");
vsBlob->Release();
return false;
}
}
if (!mVertexLayoutPtr)
{
D3D11_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
int numLayoutElements = sizeof layout/sizeof layout[0];
hr = mDevicePtr->CreateInputLayout(
layout, numLayoutElements, vsBlob->GetBufferPointer(), vsBlob->GetBufferSize(), &mVertexLayoutPtr);
vsBlob->Release();
if (FAILED(hr))
{
printf("Failed to create input layout\n");
return false;
}
}
if (!mPixelShaderPtr)
{
#if _MSC_VER < 1700
hr = D3DX11CompileFromFile(
effectLocation.asChar(),
NULL,
NULL,
"mainPS",
"ps_5_0",
dwShaderFlags,
0,
NULL,
&psBlob,
&pErrorBlob,
NULL);
#else
hr = D3DCompileFromFile(
effectLocation.asWChar(),
NULL,
NULL,
"mainPS",
"ps_5_0",
dwShaderFlags,
0,
&psBlob,
&pErrorBlob);
#endif
if (FAILED(hr))
{
printf("Failed to compile vertex shader\n");
mVertexShaderPtr->Release();
mVertexLayoutPtr->Release();
if (pErrorBlob) pErrorBlob->Release();
return false;
}
if (pErrorBlob) pErrorBlob->Release();
hr = mDevicePtr->CreatePixelShader(
psBlob->GetBufferPointer(), psBlob->GetBufferSize(), NULL, &mPixelShaderPtr);
psBlob->Release();
if (FAILED(hr))
{
printf("Failed to create pixel shader\n");
mVertexShaderPtr->Release();
mVertexLayoutPtr->Release();
return false;
}
}
return true;
}
bool FootPrintDrawAgentDX::initBuffersDX()
{
assert( mDevicePtr );
if ( !mDevicePtr )
return false;
HRESULT hr;
D3D11_BUFFER_DESC bd;
ZeroMemory(&bd, sizeof(bd));
D3D11_SUBRESOURCE_DATA InitData;
ZeroMemory(&InitData, sizeof(InitData));
if (!mBoundingboxVertexBufferPtr)
{
float bbData[][3] = {
{ -0.5, -0.5f, -0.5f},
{ 0.5, -0.5f, -0.5f},
{ 0.5, -0.5f, 0.5f},
{ -0.5, -0.5f, 0.5f},
{ -0.5, 0.5f, -0.5f},
{ 0.5, 0.5f, -0.5f},
{ 0.5, 0.5f, 0.5f},
{ -0.5, 0.5f, 0.5f}};
bd.Usage = D3D11_USAGE_IMMUTABLE;
bd.ByteWidth = sizeof(float) * 3 * 8;
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = 0;
InitData.pSysMem = bbData;
hr = mDevicePtr->CreateBuffer(&bd, &InitData, &mBoundingboxVertexBufferPtr);
if (FAILED(hr)) return false;
}
if( !mBoundingboxIndexBufferPtr ){
unsigned short bbWireIndices[] =
{
0,1,
1,2,
2,3,
3,0,
4,5,
5,6,
6,7,
7,4,
0,4,
1,5,
2,6,
3,7
};
bd.Usage = D3D11_USAGE_IMMUTABLE;
bd.ByteWidth = sizeof(unsigned short) * 2 * 12;
bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
bd.CPUAccessFlags = 0;
InitData.pSysMem = bbWireIndices;
hr = mDevicePtr->CreateBuffer(&bd, &InitData, &mBoundingboxIndexBufferPtr);
if (FAILED(hr)) return false;
}
if (!mSoleVertexBufferPtr)
{
bd.Usage = D3D11_USAGE_IMMUTABLE;
bd.ByteWidth = sizeof(float) * 3 * soleCount;
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = 0;
InitData.pSysMem = sole;
hr = mDevicePtr->CreateBuffer(&bd, &InitData, &mSoleVertexBufferPtr);
if (FAILED(hr)) return false;
}
if (!mHeelVertexBufferPtr)
{
bd.Usage = D3D11_USAGE_IMMUTABLE;
bd.ByteWidth = sizeof(float) * 3 * heelCount;
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = 0;
InitData.pSysMem = heel;
hr = mDevicePtr->CreateBuffer(&bd, &InitData, &mHeelVertexBufferPtr);
if (FAILED(hr)) return false;
}
if (!mSoleWireIndexBufferPtr)
{
unsigned short soleWireIndices[] =
{
0, 1,
1, 2,
2, 3,
3, 4,
4, 5,
5, 6,
6, 7,
7, 8,
8, 9,
9, 10,
10, 11,
11, 12,
12, 13,
13, 14,
14, 15,
15, 16,
16, 17,
17, 18,
18, 19,
19, 20
};
bd.Usage = D3D11_USAGE_IMMUTABLE;
bd.ByteWidth = sizeof(unsigned short) * 2 * (soleCount-1);
bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
bd.CPUAccessFlags = 0;
InitData.pSysMem = soleWireIndices;
hr = mDevicePtr->CreateBuffer(&bd, &InitData, &mSoleWireIndexBufferPtr);
if (FAILED(hr)) return false;
}
if (!mHeelWireIndexBufferPtr)
{
unsigned short heelWireIndices[] =
{
0, 1,
1, 2,
2, 3,
3, 4,
4, 5,
5, 6,
6, 7,
7, 8,
8, 9,
9, 10,
10, 11,
11, 12,
12, 13,
13, 14,
14, 15,
15, 16
};
bd.Usage = D3D11_USAGE_IMMUTABLE;
bd.ByteWidth = sizeof(unsigned short) * 2 * (heelCount-1);
bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
bd.CPUAccessFlags = 0;
InitData.pSysMem = heelWireIndices;
hr = mDevicePtr->CreateBuffer(&bd, &InitData, &mHeelWireIndexBufferPtr);
if (FAILED(hr)) return false;
}
if (!mSoleShadedIndexBufferPtr)
{
unsigned short soleShadedIndices[] =
{
0, 1, 2,
0, 2, 3,
0, 3, 4,
0, 4, 5,
0, 5, 6,
0, 6, 7,
0, 7, 8,
0, 8, 9,
0, 9, 10,
0, 10, 11,
0, 11, 12,
0, 12, 13,
0, 13, 14,
0, 14, 15,
0, 15, 16,
0, 16, 17,
0, 17, 18,
0, 18, 19,
0, 19, 20
};
bd.Usage = D3D11_USAGE_IMMUTABLE;
bd.ByteWidth = sizeof(unsigned short) * 3 * (soleCount-2);
bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
bd.CPUAccessFlags = 0;
InitData.pSysMem = soleShadedIndices;
hr = mDevicePtr->CreateBuffer(&bd, &InitData, &mSoleShadedIndexBufferPtr);
if (FAILED(hr)) return false;
}
if (!mHeelShadedIndexBufferPtr)
{
unsigned short heelShadedIndices[] =
{
0, 1, 2,
0, 2, 3,
0, 3, 4,
0, 4, 5,
0, 5, 6,
0, 6, 7,
0, 7, 8,
0, 8, 9,
0, 9, 10,
0, 10, 11,
0, 11, 12,
0, 12, 13,
0, 13, 14,
0, 14, 15,
0, 15, 16
};
bd.Usage = D3D11_USAGE_IMMUTABLE;
bd.ByteWidth = sizeof(unsigned short) * 3 * (heelCount-2);
bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
bd.CPUAccessFlags = 0;
InitData.pSysMem = heelShadedIndices;
hr = mDevicePtr->CreateBuffer(&bd, &InitData, &mHeelShadedIndexBufferPtr);
if (FAILED(hr)) return false;
}
if (!mConstantBufferPtr)
{
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = sizeof(ConstantBufferDef);
bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
bd.CPUAccessFlags = 0;
hr = mDevicePtr->CreateBuffer(&bd, NULL, &mConstantBufferPtr);
if (FAILED(hr)) return false;
}
return true;
}
bool FootPrintDrawAgentDX::releaseDXResources()
{
if (mBoundingboxVertexBufferPtr)
{
mBoundingboxVertexBufferPtr->Release();
mBoundingboxVertexBufferPtr = NULL;
}
if (mBoundingboxIndexBufferPtr)
{
mBoundingboxIndexBufferPtr->Release();
mBoundingboxIndexBufferPtr = NULL;
}
if (mSoleVertexBufferPtr)
{
mSoleVertexBufferPtr->Release();
mSoleVertexBufferPtr = NULL;
}
if (mHeelVertexBufferPtr)
{
mHeelVertexBufferPtr->Release();
mHeelVertexBufferPtr = NULL;
}
if (mSoleWireIndexBufferPtr)
{
mSoleWireIndexBufferPtr->Release();
mSoleWireIndexBufferPtr = NULL;
}
if (mSoleShadedIndexBufferPtr)
{
mSoleShadedIndexBufferPtr->Release();
mSoleShadedIndexBufferPtr = NULL;
}
if (mHeelWireIndexBufferPtr)
{
mHeelWireIndexBufferPtr->Release();
mHeelWireIndexBufferPtr = NULL;
}
if (mHeelShadedIndexBufferPtr)
{
mHeelShadedIndexBufferPtr->Release();
mHeelShadedIndexBufferPtr = NULL;
}
if (mVertexShaderPtr)
{
mVertexShaderPtr->Release();
mVertexShaderPtr = NULL;
}
if (mPixelShaderPtr)
{
mPixelShaderPtr->Release();
mPixelShaderPtr = NULL;
}
if (mVertexLayoutPtr)
{
mVertexLayoutPtr->Release();
mVertexLayoutPtr = NULL;
}
if (mConstantBufferPtr)
{
mConstantBufferPtr->Release();
mConstantBufferPtr = NULL;
}
return true;
}
#endif // _WIN32
{
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;
}
#ifdef _WIN32
FootPrintDrawAgentDX& drawAgentRef = FootPrintDrawAgentDX::getDrawAgent();
drawAgentRef.releaseDXResources();
#endif
return status;
}