#include <maya/MIOStream.h>
#include <maya/MFnPlugin.h>
#include <maya/MPxPolyTrg.h>
#include <maya/MFnMessageAttribute.h>
#include <maya/MPxCommand.h>
#include <maya/MSyntax.h>
#include <maya/MArgDatabase.h>
#include <maya/MArgList.h>
#include <maya/MString.h>
#include <maya/MSelectionList.h>
#include <maya/MGlobal.h>
#include <maya/MDagPath.h>
#define MCHECKERR(stat,msg) \
if ( MS::kSuccess != stat ) { \
return MS::kFailure; \
}
#define EQUAL(a,b) ( (((a-b) > -0.00001) && ((a-b) < 0.00001)) ? 1 : 0 )
#define EQUAL2(a,b) ((EQUAL(a[0],b[0]) && EQUAL(a[1],b[1]) ) ? 1 : 0)
#define EQUAL3(a,b) ((EQUAL(a[0],b[0]) && EQUAL(a[1],b[1]) && EQUAL(a[2],b[2]) ) ? 1 : 0)
#define MCHECKERR_RETURN(stat,msg) \
if ( MS::kSuccess != stat ) { \
displayError( msg ); \
fErrorCount = 1; \
return MS::kFailure; \
}
#define MCHECKERR_BREAK(stat,msg) \
if ( MS::kSuccess != stat ) { \
displayError( msg ); \
fErrorCount = 1; \
break; \
}
{
public:
polyTrgNode() {};
virtual ~polyTrgNode();
static void* creator();
static void triangulateFace( const float *vert,
const float *norm,
const int *loopSizes,
const int nbLoops,
const int nbTrg,
unsigned short *trg );
public:
private:
};
polyTrgNode::~polyTrgNode()
{
unregisterTrgFunction( "triangulate" );
}
void * polyTrgNode::creator()
{
return new polyTrgNode();
}
void polyTrgNode::postConstructor()
{
registerTrgFunction( "triangulate", polyTrgNode::triangulateFace );
}
bool polyTrgNode::isAbstractClass( void ) const
{
return false;
}
{
}
{
}
void
polyTrgNode::triangulateFace(
const float *vert,
const float *norm,
const int *loopSizes,
const int nbLoops,
const int nbTrg,
unsigned short *trg
)
{
cerr << "polyTrgNode::triangulate() - This is an API registered triangulation.\n";
cerr << "Numb Loops = " << nbLoops << "\n";
int nbVert = 0;
cerr << "Loop sizes: ";
for (int i=0; i<nbLoops; i++ ) {
nbVert += loopSizes[i];
cerr << loopSizes[i] << " ";
}
cerr << "\n";
cerr << "Numb Vert = " << nbVert << "\n";
cerr << "Vertices:\n";
for (int v=0; v<nbVert; v++ ) {
cerr << vert[3*v] << " " << vert[3*v+1] << " " << vert[3*v+2] << " " <<"\n";
}
cerr << " nbTrg = " << nbTrg << "\n";
unsigned short v0 = 0;
unsigned short v1 = 1;
unsigned short v2 = 2;
for (int k=0; k<nbTrg; k++){
trg[3*k] = v0;
trg[3*k+1] = v1;
trg[3*k+2] = v2;
v1 = v2;
v2 ++;
if (v2 >= nbVert) {
v2 = 0;
}
}
cerr << "Triangulation\n";
for (int k1=0; k1<nbTrg; k1++){
cerr << trg[3*k1] << " " << trg[3*k1+1] << " " << trg[3*k1+2] << "\n";
}
}
{
MFnPlugin plugin(obj,
"MPxPlyTrg::Poly api example plug-in",
"4.5",
"Any");
MStatus stat = plugin.registerNode(
"polyTrgNode",
polyTrgNode::id,
polyTrgNode::creator,
polyTrgNode::initialize);
return stat;
}
{
MStatus stat = plugin.deregisterNode(polyTrgNode::id);
return stat;
}