#include <maya/MTime.h>
#include <maya/MFnMesh.h>
#include <maya/MPoint.h>
#include <maya/MFloatPoint.h>
#include <maya/MFloatPointArray.h>
#include <maya/MIntArray.h>
#include <maya/MDoubleArray.h>
#include <maya/MFnUnitAttribute.h>
#include <maya/MFnTypedAttribute.h>
#include <maya/MFnPlugin.h>
#include <maya/MPxNode.h>
#include <maya/MObject.h>
#include <maya/MPlug.h>
#include <maya/MDataBlock.h>
#include <maya/MFnMeshData.h>
#include <maya/MIOStream.h>
#define McheckErr(stat,msg) \
if ( MS::kSuccess != stat ) { \
cerr << msg; \
return MS::kFailure; \
}
{
public:
animCube() {};
virtual ~animCube() {};
static void* creator();
protected:
};
void* animCube::creator()
{
return new animCube;
}
{
animCube::time = unitAttr.
create(
"time",
"tm",
0.0, &returnStatus );
McheckErr(returnStatus, "ERROR creating animCube time attribute\n");
animCube::outputMesh = typedAttr.
create(
"outputMesh",
"out",
&returnStatus );
McheckErr(returnStatus, "ERROR creating animCube output attribute\n");
returnStatus = addAttribute(animCube::time);
McheckErr(returnStatus, "ERROR adding time attribute\n");
returnStatus = addAttribute(animCube::outputMesh);
McheckErr(returnStatus, "ERROR adding outputMesh attribute\n");
returnStatus = attributeAffects(animCube::time,
animCube::outputMesh);
McheckErr(returnStatus, "ERROR in attributeAffects\n");
}
{
const float cubeSize = 0.5f * (float)( frame % 10 + 1 );
points.
append( -cubeSize, -cubeSize, -cubeSize );
points.
append( cubeSize, -cubeSize, -cubeSize );
points.
append( cubeSize, -cubeSize, cubeSize );
points.
append( -cubeSize, -cubeSize, cubeSize );
points.
append( -cubeSize, cubeSize, -cubeSize );
points.
append( -cubeSize, cubeSize, cubeSize );
points.
append( cubeSize, cubeSize, cubeSize );
points.
append( cubeSize, cubeSize, -cubeSize );
static const bool sTestVertexIdAndFaceId =
(getenv("MAYA_TEST_VERTEXID_AND_FACEID") != NULL);
if (sTestVertexIdAndFaceId)
{
switch (frame % 4)
{
case 1:
newMesh = createQuads(points, outData, stat);
break;
case 2:
newMesh = createReverseQuads(points, outData, stat);
break;
case 3:
newMesh = createTris(points, outData, stat);
break;
case 0:
newMesh = createReverseTris(points, outData, stat);
break;
default:
newMesh = createQuads(points, outData, stat);
break;
}
}
else
{
newMesh = createQuads(points, outData, stat);
}
return newMesh;
}
{
const int numFaces = 6;
int face_counts[numFaces] = { 4, 4, 4, 4, 4, 4 };
MIntArray faceCounts( face_counts, numFaces );
const int numFaceConnects = 24;
int face_connects[ numFaceConnects ] = {0, 1, 2, 3,
4, 5, 6, 7,
3, 2, 6, 5,
0, 3, 5, 4,
0, 4, 7, 1,
1, 7, 6, 2};
MIntArray faceConnects( face_connects, numFaceConnects );
points, faceCounts, faceConnects, outData, &stat);
}
MObject animCube::createReverseQuads(
{
const int numFaces = 6;
int face_counts[numFaces] = { 4, 4, 4, 4, 4, 4 };
MIntArray faceCounts( face_counts, numFaces );
const int numFaceConnects = 24;
int face_connects[ numFaceConnects ] = {0, 3, 2, 1,
4, 7, 6, 5,
3, 5, 6, 2,
0, 4, 5, 3,
0, 1, 7, 4,
1, 2, 6, 7};
MIntArray faceConnects( face_connects, numFaceConnects );
points, faceCounts, faceConnects, outData, &stat);
}
{
const int numFaces = 12;
int face_counts[numFaces] = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3};
MIntArray faceCounts( face_counts, numFaces );
const int numFaceConnects = 36;
int face_connects[ numFaceConnects ] = {0, 1, 2,
2, 3, 0,
4, 5, 6,
6, 7, 4,
3, 2, 6,
6, 5, 3,
0, 3, 5,
5, 4, 0,
0, 4, 7,
7, 1, 0,
1, 7, 6,
6, 2, 1};
MIntArray faceConnects( face_connects, numFaceConnects );
points, faceCounts, faceConnects, outData, &stat);
}
MObject animCube::createReverseTris(
{
const int numFaces = 12;
int face_counts[numFaces] = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3};
MIntArray faceCounts( face_counts, numFaces );
const int numFaceConnects = 36;
int face_connects[ numFaceConnects ] = {0, 2, 1,
2, 0, 3,
4, 6, 5,
6, 4, 7,
3, 6, 2,
6, 3, 5,
0, 5, 3,
5, 0, 4,
0, 7, 4,
7, 0, 1,
1, 6, 7,
6, 1, 2};
MIntArray faceConnects( face_connects, numFaceConnects );
points, faceCounts, faceConnects, outData, &stat);
}
{
if (plug == outputMesh) {
McheckErr(returnStatus, "Error getting time data handle\n");
McheckErr(returnStatus, "ERROR getting polygon data handle\n");
McheckErr(returnStatus, "ERROR creating outputData");
createMesh(time, newOutputData, returnStatus);
McheckErr(returnStatus, "ERROR creating new Cube");
outputHandle.
set(newOutputData);
} else
}
{
MFnPlugin plugin(obj, PLUGIN_COMPANY,
"4.0",
"Any");
status = plugin.registerNode("animCube", animCube::id,
animCube::creator, animCube::initialize);
if (!status) {
status.
perror(
"registerNode");
return status;
}
return status;
}
{
status = plugin.deregisterNode(animCube::id);
if (!status) {
status.
perror(
"deregisterNode");
return status;
}
return status;
}