#include <maya/MPxNode.h>
#include <maya/MGlobal.h>
#include <maya/MFnCompoundAttribute.h>
#include <maya/MFnEnumAttribute.h>
#include <maya/MFnMatrixAttribute.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MFnTypedAttribute.h>
#include <maya/MFnDependencyNode.h>
#include <maya/MFnIkJoint.h>
#include <maya/MFnPlugin.h>
#include <maya/MAngle.h>
#include <maya/MEulerRotation.h>
#include <maya/MMatrix.h>
#include <maya/MTransformationMatrix.h>
#include <maya/MString.h>
#include <maya/MTypeId.h>
#include <maya/MPlug.h>
#include <maya/MPlugArray.h>
#include <maya/MQuaternion.h>
#include <maya/MVector.h>
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>
#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
namespace {
static const MString JOINT_ORIENT_TYPE_XYZ =
"xyz";
static const MString JOINT_ORIENT_TYPE_YZX =
"yzx";
static const MString JOINT_ORIENT_TYPE_ZXY =
"zxy";
static const MString JOINT_ORIENT_TYPE_XZY =
"xzy";
static const MString JOINT_ORIENT_TYPE_YXZ =
"yxz";
static const MString JOINT_ORIENT_TYPE_ZYX =
"zyx";
}
class rebalanceTransform :
public MPxNode
{
public:
rebalanceTransform();
~rebalanceTransform() override;
static void* creator();
static MObject inputParentInverseMatrix;
static MObject inputJointOrientType;
static MObject inputSegmentScaleCompensate;
};
MObject rebalanceTransform::inputWorldMatrix;
MObject rebalanceTransform::inputParentInverseMatrix;
MObject rebalanceTransform::inputJointOrient;
MObject rebalanceTransform::inputJointOrientType;
MObject rebalanceTransform::inputRotateOrder;
MObject rebalanceTransform::inputRotateAxis;
MObject rebalanceTransform::inputSegmentScaleCompensate;
MObject rebalanceTransform::inputInverseScale;
MObject rebalanceTransform::output;
MObject rebalanceTransform::outputTranslation;
MObject rebalanceTransform::outputRotation;
MObject rebalanceTransform::outputScale;
MTypeId rebalanceTransform::id( 0x080047 );
rebalanceTransform::rebalanceTransform() {}
rebalanceTransform::~rebalanceTransform() {}
{
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:
}
auto clamp = [](auto v)
{
auto clamp = [](double x)
{
const double kScaleEpsilon = 1.0e-12;
return (((x < kScaleEpsilon) && (x >= 0)) ? kScaleEpsilon : (((x<0) && (x>= -kScaleEpsilon))?(-kScaleEpsilon):x) );
};
v[0] = clamp(v[0]);
v[1] = clamp(v[1]);
v[2] = clamp(v[2]);
};
if( joType == JOINT_ORIENT_TYPE_XYZ ){
} else if( joType == JOINT_ORIENT_TYPE_YZX ){
} else if( joType == JOINT_ORIENT_TYPE_ZXY ){
} else if( joType == JOINT_ORIENT_TYPE_XZY ){
} else if( joType == JOINT_ORIENT_TYPE_YXZ ){
} else if( joType == JOINT_ORIENT_TYPE_ZYX ){
} else {
}
MEulerRotation er( jX.asRadians(), jY.asRadians(), jZ.asRadians(), jointOrientType );
MEulerRotation eRotateAxis( rX.asRadians(), rY.asRadians(), rZ.asRadians(), rotateOrder );
bool segmentScaleCompensate = data.
inputValue( inputSegmentScaleCompensate ).
asBool();
clamp(jointScale);
} else if (plug == output) {
} else {
return MS::kUnknownParameter;
}
return( MS::kSuccess );
}
void* rebalanceTransform::creator()
{
return( new rebalanceTransform() );
}
MStatus rebalanceTransform::initialize()
{
inputWorldMatrix = mAttr.
create(
"inputWorldMatrix",
"iwm");
inputParentInverseMatrix = mAttr.
create(
"inputParentInverseMatrix",
"ipi");
inputRotateOrder = eAttr.
create(
"inputRotateOrder",
"iro", 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);
output = cAttr.
create(
"output",
"o", &stat);
stat = cAttr.
addChild(outputTranslation);
stat = addAttribute(inputJointOrient);
stat = addAttribute(inputJointOrientType);
stat = addAttribute(output);
stat = addAttribute(inputWorldMatrix);
stat = addAttribute(inputParentInverseMatrix);
stat = addAttribute(inputRotateOrder);
stat = addAttribute(inputRotateAxis);
stat = addAttribute(inputSegmentScaleCompensate);
stat = addAttribute(inputInverseScale);
stat = attributeAffects(inputWorldMatrix, output);
stat = attributeAffects(inputParentInverseMatrix, output);
stat = attributeAffects(inputJointOrient, output);
stat = attributeAffects(inputJointOrientType, output);
stat = attributeAffects(inputRotateOrder, output);
stat = attributeAffects(inputRotateAxis, output);
stat = attributeAffects(inputSegmentScaleCompensate, output);
stat = attributeAffects(inputInverseScale, output);
stat = attributeAffects(inputJointOrient, outputTranslation);
stat = attributeAffects(inputJointOrientType, outputTranslation);
stat = attributeAffects(inputParentInverseMatrix, outputTranslation);
stat = attributeAffects(inputRotateOrder, outputTranslation);
stat = attributeAffects(inputRotateAxis, outputTranslation);
stat = attributeAffects(inputSegmentScaleCompensate, outputTranslation);
stat = attributeAffects(inputInverseScale, outputTranslation);
stat = attributeAffects(inputWorldMatrix, outputTranslation);
stat = attributeAffects(inputJointOrient, outputRotation);
stat = attributeAffects(inputJointOrientType, outputRotation);
stat = attributeAffects(inputParentInverseMatrix, outputRotation);
stat = attributeAffects(inputRotateOrder, outputRotation);
stat = attributeAffects(inputRotateAxis, outputRotation);
stat = attributeAffects(inputSegmentScaleCompensate, outputRotation);
stat = attributeAffects(inputInverseScale, outputRotation);
stat = attributeAffects(inputWorldMatrix, outputRotation);
stat = attributeAffects(inputJointOrient, outputScale);
stat = attributeAffects(inputJointOrientType, outputScale);
stat = attributeAffects(inputParentInverseMatrix, outputScale);
stat = attributeAffects(inputRotateOrder, outputScale);
stat = attributeAffects(inputRotateAxis, outputScale);
stat = attributeAffects(inputSegmentScaleCompensate, outputScale);
stat = attributeAffects(inputInverseScale, outputScale);
stat = attributeAffects(inputWorldMatrix, outputScale);
return( MS::kSuccess );
}
{
MFnPlugin plugin( obj, PLUGIN_COMPANY ,
"6.0",
"Any");
status = plugin.registerNode( "rebalanceTransform", rebalanceTransform::id, rebalanceTransform::creator,
rebalanceTransform::initialize );
if (!status) {
status.
perror(
"registerNode");
return( status );
}
return( status );
}
{
status = plugin.deregisterNode( rebalanceTransform::id );
if (!status) {
status.
perror(
"deregisterNode");
return( status );
}
return( status );
}