#include <string.h>
#include <maya/MIOStream.h>
#include <math.h>
#include <maya/MPxNode.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MFnMatrixAttribute.h>
#include <maya/MFnUnitAttribute.h>
#include <maya/MFnEnumAttribute.h>
#include <maya/MFnPlugin.h>
#include <maya/MString.h>
#include <maya/MTypeId.h>
#include <maya/MPlug.h>
#include <maya/MVector.h>
#include <maya/MMatrix.h>
#include <maya/MTransformationMatrix.h>
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>
#define EPSILON 0.001
#define ROTATE_ORDER_XYZ 0
#define ROTATE_ORDER_YZX 1
#define ROTATE_ORDER_ZXY 2
#define ROTATE_ORDER_XZY 3
#define ROTATE_ORDER_YXZ 4
#define ROTATE_ORDER_ZYX 5
#define McheckErr(stat,msg) \
if ( MS::kSuccess != stat ) { \
cerr << msg; \
return MS::kFailure; \
}
class buildRotation :
public MPxNode
{
public:
buildRotation();
~buildRotation() override;
static void* creator();
public:
};
MTypeId buildRotation::id( 0x80004 );
MObject buildRotation::rotateOrder;
MObject buildRotation::rotateMatrix;
buildRotation::buildRotation() {}
buildRotation::~buildRotation() {}
{
if ((plug == rotate) || (plug.
parent() == rotate) || (plug == rotateMatrix)) {
McheckErr(returnStatus,"ERROR getting up vector data");
McheckErr(returnStatus,"ERROR getting forward vector data");
if ( fabs( up * forward ) > EPSILON ) {
MVector newForward = orthoVec ^ up;
if ( forward * newForward < 0.0 ) {
newForward *= -1.0;
}
forward = newForward;
}
if ( transformedForward.
x < 0.0 ) {
angle *= -1.0;
}
short order = orderHandle.
asShort();
switch ( order ) {
case ROTATE_ORDER_XYZ:
case ROTATE_ORDER_YZX:
case ROTATE_ORDER_ZXY:
case ROTATE_ORDER_XZY:
case ROTATE_ORDER_YXZ:
case ROTATE_ORDER_ZYX:
default:
}
double rotation[3];
outputRot.
set( rotation[0], rotation[1], rotation[2] );
} else
return MS::kUnknownParameter;
return MS::kSuccess;
}
void* buildRotation::creator()
{
return new buildRotation();
}
MStatus buildRotation::initialize()
{
up = nAttr.
create(
"up",
"u", upX, upY, upZ );
forward = nAttr.
create(
"forward",
"f", forwardX, forwardY, forwardZ );
rotateOrder = eAttr.
create(
"rotateOrder",
"ro", ROTATE_ORDER_XYZ);
eAttr.
addField(
"xyz", ROTATE_ORDER_XYZ);
eAttr.
addField(
"yzx", ROTATE_ORDER_YZX);
eAttr.
addField(
"zxy", ROTATE_ORDER_ZXY);
eAttr.
addField(
"xzy", ROTATE_ORDER_XZY);
eAttr.
addField(
"yxz", ROTATE_ORDER_YXZ);
eAttr.
addField(
"zyx", ROTATE_ORDER_ZYX);
rotate = nAttr.
create(
"rotate",
"r", rotateX, rotateY, rotateZ );
rotateMatrix = mAttr.
create(
"rotateMatrix",
"rm" );
stat = addAttribute( up );
if (!stat) { stat.
perror(
"addAttribute");
return stat;}
stat = addAttribute( forward );
if (!stat) { stat.
perror(
"addAttribute");
return stat;}
stat = addAttribute( rotate );
if (!stat) { stat.
perror(
"addAttribute");
return stat;}
stat = addAttribute( rotateOrder );
if (!stat) { stat.
perror(
"addAttribute");
return stat;}
stat = addAttribute( rotateMatrix );
if (!stat) { stat.
perror(
"addAttribute");
return stat;}
stat = attributeAffects( up, rotate );
if (!stat) { stat.
perror(
"attributeAffects");
return stat;}
stat = attributeAffects( up, rotateMatrix );
if (!stat) { stat.
perror(
"attributeAffects");
return stat;}
stat = attributeAffects( forward, rotate );
if (!stat) { stat.
perror(
"attributeAffects");
return stat;}
stat = attributeAffects( forward, rotateMatrix );
if (!stat) { stat.
perror(
"attributeAffects");
return stat;}
stat = attributeAffects( rotateOrder, rotate );
if (!stat) { stat.
perror(
"attributeAffects");
return stat;}
stat = attributeAffects( rotateOrder, rotateMatrix );
if (!stat) { stat.
perror(
"attributeAffects");
return stat;}
return MS::kSuccess;
}
{
MFnPlugin plugin( obj, PLUGIN_COMPANY,
"3.0",
"Any");
status = plugin.registerNode( "buildRotation", buildRotation::id,
buildRotation::creator, buildRotation::initialize );
if (!status) {
status.
perror(
"registerNode");
return status;
}
return status;
}
{
status = plugin.deregisterNode( buildRotation::id );
if (!status) {
status.
perror(
"deregisterNode");
return status;
}
return status;
}