#include <maya/MMatrix.h>
#include <maya/MPxTransformationMatrix.h>
#include <maya/MPxTransform.h>
#include <maya/MFnPlugin.h>
#include <maya/MPlug.h>
#include <maya/MDGContext.h>
#include <maya/MFnUnitAttribute.h>
#define _USE_MATH_DEFINES
#include <math.h>
class normalTransformMatrix : public MPxTransformationMatrix
{
// - The virtual asMatrix() method which passes the matrix
// back to Maya when the command "xform -q -ws -m" is invoked
public:
normalTransformMatrix();
static void *creator();
//virtual method which passes the matrix when you use the xform command
virtual MMatrix asMatrix() const;
virtual MMatrix asMatrix(double percent) const;
virtual MMatrix asRotateMatrix() const;
//methods to set and get the new localScale attributes we will add
double getLocalScaleX() const;
double getLocalScaleY() const;
double getLocalScaleZ() const;
void setLocalScaleX(double localScaleX);
void setLocalScaleY(double localScaleY);
void setLocalScaleZ(double localScaleZ);
//methods to set and get the new offset attributes we will add
double getOffsetTranslateX() const;
double getOffsetTranslateY() const;
double getOffsetTranslateZ() const;
void setOffsetTranslateX(double offsetTranslateX);
void setOffsetTranslateY(double offsetTranslateY);
void setOffsetTranslateZ(double offsetTranslateZ);
//
double getOffsetRotateX() const;
double getOffsetRotateY() const;
double getOffsetRotateZ() const;
void setOffsetRotateX(double offsetRotateX);
void setOffsetRotateY(double offsetRotateY);
void setOffsetRotateZ(double offsetRotateZ);
//
double getOffsetScaleX() const;
double getOffsetScaleY() const;
double getOffsetScaleZ() const;
void setOffsetScaleX(double offsetScaleX);
void setOffsetScaleY(double offsetScaleY);
void setOffsetScaleZ(double offsetScaleZ);
//
static MTypeId xformId;
protected:
typedef MPxTransformationMatrix ParentClass;
//variables to store extra values that are used to calculate the matrix
// local scale
double localScaleX_val = 1.0;
double localScaleY_val = 1.0;
double localScaleZ_val = 1.0;
//offset translate
double offsetTranslateX_val = 0.0;
double offsetTranslateY_val = 0.0;
double offsetTranslateZ_val = 0.0;
//offset rotate
double offsetRotateX_val = 0.0;
double offsetRotateY_val = 0.0;
double offsetRotateZ_val = 0.0;
//offset scale
double offsetScaleX_val = 1.0;
double offsetScaleY_val = 1.0;
double offsetScaleZ_val = 1.0;
};
// Matrix constructor. Initialize any class variables.
normalTransformMatrix::normalTransformMatrix()
{
localScaleX_val = 1.0;
localScaleY_val = 1.0;
localScaleZ_val = 1.0;
}
void *normalTransformMatrix::creator()
{
return new normalTransformMatrix();
}
//
// Utility method for getting the rock
// motion in the X axis
//
double normalTransformMatrix::getLocalScaleX() const
{
return localScaleX_val;
}
double normalTransformMatrix::getLocalScaleY() const
{
return localScaleY_val;
}
double normalTransformMatrix::getLocalScaleZ() const
{
return localScaleZ_val;
}
//
double normalTransformMatrix::getOffsetTranslateX() const
{
return offsetTranslateX_val;
}
double normalTransformMatrix::getOffsetTranslateY() const
{
return offsetTranslateY_val;
}
double normalTransformMatrix::getOffsetTranslateZ() const
{
return offsetTranslateZ_val;
}
//
double normalTransformMatrix::getOffsetRotateX() const
{
return offsetRotateX_val;
}
double normalTransformMatrix::getOffsetRotateY() const
{
return offsetRotateY_val;
}
double normalTransformMatrix::getOffsetRotateZ() const
{
return offsetRotateZ_val;
}
//
double normalTransformMatrix::getOffsetScaleX() const
{
return offsetScaleX_val;
}
double normalTransformMatrix::getOffsetScaleY() const
{
return offsetScaleY_val;
}
double normalTransformMatrix::getOffsetScaleZ() const
{
return offsetScaleZ_val;
}
//
// Utility method for setting the rcok
// motion in the X axis
//
void normalTransformMatrix::setLocalScaleX(double scale)
{
localScaleX_val = scale;
}
void normalTransformMatrix::setLocalScaleY(double scale)
{
localScaleY_val = scale;
}
void normalTransformMatrix::setLocalScaleZ(double scale)
{
localScaleZ_val = scale;
}
//
void normalTransformMatrix::setOffsetTranslateX(double scale)
{
offsetTranslateX_val = scale;
}
void normalTransformMatrix::setOffsetTranslateY(double scale)
{
offsetTranslateY_val = scale;
}
void normalTransformMatrix::setOffsetTranslateZ(double scale)
{
offsetTranslateZ_val = scale;
}
//
void normalTransformMatrix::setOffsetRotateX(double scale)
{
offsetRotateX_val = scale;
}
void normalTransformMatrix::setOffsetRotateY(double scale)
{
offsetRotateY_val = scale;
}
void normalTransformMatrix::setOffsetRotateZ(double scale)
{
offsetRotateZ_val = scale;
}
//
void normalTransformMatrix::setOffsetScaleX(double scale)
{
offsetScaleX_val = scale;
}
void normalTransformMatrix::setOffsetScaleY(double scale)
{
offsetScaleY_val = scale;
}
void normalTransformMatrix::setOffsetScaleZ(double scale)
{
offsetScaleZ_val = scale;
}
//
// This method will be used to return information to
// Maya. Use the attributes which are outside of
// the regular transform attributes to build a new
// matrix. This new matrix will be passed back to
// Maya.
//
MMatrix normalTransformMatrix::asMatrix() const
{
// Get the current transform matrix
MMatrix mm = ParentClass::asMatrix();
//Convert It To A MTransformationMatrix
MTransformationMatrix m(mm);
//Get the translate that appears in the channel box
MVector trans = m.getTranslation(MSpace::kTransform);
//Add the offset
trans += MVector(offsetTranslateX_val, offsetTranslateY_val, offsetTranslateZ_val);
//Scale it by the localScale
trans[0] *= localScaleX_val;
trans[1] *= localScaleY_val;
trans[2] *= localScaleZ_val;
//Put that value into the transformaton matrix
m.setTranslation(trans, MSpace::kTransform);
//Get the rotate that appears in the channel box
MQuaternion quatRotate = m.rotation();
//Apply the offset rotation
double convert_constant = M_PI / 180;
MEulerRotation eulerOffsetRotate(offsetRotateX_val*convert_constant, offsetRotateY_val*convert_constant, offsetRotateZ_val*convert_constant);
MQuaternion quatOffsetRotate = eulerOffsetRotate.asQuaternion();
quatRotate *= quatOffsetRotate;
MEulerRotation eulRotate = quatRotate.asEulerRotation();
//Put that value into the transformaton matrix
m.rotateTo(eulRotate);
//Get the scale that appears in the channel box
double s[3];
m.getScale(s, MSpace::kTransform);
//Apply the offset scale
s[0] *= offsetScaleX_val;
s[1] *= offsetScaleY_val;
s[2] *= offsetScaleZ_val;
m.setScale(s, MSpace::kTransform);
return m.asMatrix();
}
MMatrix normalTransformMatrix::asMatrix(double percent) const//not used by the viewport
{
MGlobal::displayInfo("calling the percent func");
MPxTransformationMatrix m(*this);
//Get the translate that appears in the channel box
MVector trans = m.translation();
//Add the offset translate
trans += MVector(offsetTranslateX_val, offsetTranslateY_val, offsetTranslateZ_val);
//Scale it by the localScale
trans[0] *= localScaleX_val;
trans[1] *= localScaleY_val;
trans[2] *= localScaleZ_val;
//Apply the percent function (so the xform command can use it)
trans *= percent;
//Put that value into the transformaton matrix
m.translateTo(trans);
/*
//Make any changes to the rotate and scale pivots (None for us)
MPoint rotatePivotTrans = m.rotatePivot();
rotatePivotTrans = rotatePivotTrans * percent;
m.setRotatePivot(rotatePivotTrans);
MPoint scalePivotTrans = m.scalePivotTranslation();
scalePivotTrans = scalePivotTrans * percent;
m.setScalePivotTranslation(scalePivotTrans);
//Get the rotate that appears in the channel box
MQuaternion quatRotate = m.rotation();
//Apply the offset rotation
MEulerRotation eulerOffsetRotate(offsetRotateX_val, offsetRotateY_val, offsetRotateZ_val);
MQuaternion quatOffsetRotate = eulerOffsetRotate.asQuaternion();
quatRotate *= quatOffsetRotate;
MEulerRotation eulRotate = quatRotate.asEulerRotation();
//Apply the percentage to the rotate value.
m.rotateTo(eulRotate * percent);
//Get the scale that appears in the channel box
MVector s = m.scale(MSpace::kTransform);
//Apply the offset scale
s.x *= offsetScaleX_val;
s.y *= offsetScaleY_val;
s.z *= offsetScaleZ_val;
//Apply the percentage to the scale
s.x = 1.0 + (s.x - 1.0)*percent;
s.y = 1.0 + (s.y - 1.0)*percent;
s.z = 1.0 + (s.z - 1.0)*percent;
m.scaleTo(s, MSpace::kTransform);
*/
return m.asMatrix();
}
MMatrix normalTransformMatrix::asRotateMatrix() const
{
// To be implemented
return ParentClass::asRotateMatrix();
}
MTypeId normalTransformMatrix::xformId(0x00000007);
class normalTransformNode : public MPxTransform
{
// A really simple custom transform.
public:
normalTransformNode();
normalTransformNode(normalTransformMatrix *);
virtual ~normalTransformNode();
virtual MPxTransformationMatrix *createTransformationMatrix();//???
virtual void postConstructor();
virtual MStatus validateAndSetValue(
const MPlug& plug,
const MDataHandle& handle);
virtual void resetTransformation(MPxTransformationMatrix *);
virtual void resetTransformation(const MMatrix &);
// Utility for getting the related matrix pointer
normalTransformMatrix *getNormalTransformMatrix();
virtual MMatrix getMatrix(MDGContext & context, MStatus *);
virtual MStatus compute(const MPlug& plug, MDataBlock& block);
const char*className();
static void* creator();
static MStatus initialize();
static MObject aLocalScale;
static MObject aLocalScaleX;
static MObject aLocalScaleY;
static MObject aLocalScaleZ;
static MObject aOffsetTranslate;
static MObject aOffsetTranslateX;
static MObject aOffsetTranslateY;
static MObject aOffsetTranslateZ;
static MObject aOffsetRotate;
static MObject aOffsetRotateX;
static MObject aOffsetRotateY;
static MObject aOffsetRotateZ;
static MObject aOffsetScale;
static MObject aOffsetScaleX;
static MObject aOffsetScaleY;
static MObject aOffsetScaleZ;
static MObject aParentOffsetMatrix;
static MTypeId id;
protected:
// Degrees
double localScaleX_val = 1.0;
double localScaleY_val = 1.0;
double localScaleZ_val = 1.0;
double offsetTranslateX_val = 0.0;
double offsetTranslateY_val = 0.0;
double offsetTranslateZ_val = 0.0;
double offsetRotateX_val = 0.0;
double offsetRotateY_val = 0.0;
double offsetRotateZ_val = 0.0;
double offsetScaleX_val = 1.0;
double offsetScaleY_val = 1.0;
double offsetScaleZ_val = 1.0;
typedef MPxTransform ParentClass;
};
MMatrix normalTransformNode::getMatrix(MDGContext & context, MStatus *)
{
return MMatrix();
}
MObject normalTransformNode::aLocalScale;
MObject normalTransformNode::aLocalScaleX;
MObject normalTransformNode::aLocalScaleY;
MObject normalTransformNode::aLocalScaleZ;
MObject normalTransformNode::aOffsetTranslate;
MObject normalTransformNode::aOffsetTranslateX;
MObject normalTransformNode::aOffsetTranslateY;
MObject normalTransformNode::aOffsetTranslateZ;
MObject normalTransformNode::aOffsetRotate;
MObject normalTransformNode::aOffsetRotateX;
MObject normalTransformNode::aOffsetRotateY;
MObject normalTransformNode::aOffsetRotateZ;
MObject normalTransformNode::aOffsetScale;
MObject normalTransformNode::aOffsetScaleX;
MObject normalTransformNode::aOffsetScaleY;
MObject normalTransformNode::aOffsetScaleZ;
MObject normalTransformNode::aParentOffsetMatrix;
MTypeId normalTransformNode::id(0x00000006);
//
// Constructor of the transform node
//
normalTransformNode::normalTransformNode()
: ParentClass()
{
}
// Post constructor method. Have access to *this. Node setup
// operations that do not go into the initialize() method should go
// here.
void normalTransformNode::postConstructor()
{
// Make sure the parent takes care of anything it needs.
//
ParentClass::postConstructor();
// The baseTransformationMatrix pointer should be setup properly
// at this point, but just in case, set the value if it is missing.
//
if (NULL == transformationMatrixPtr()) {
//baseTransformationMatrix = new MPxTransformationMatrix();//???
}
//MPlug aLocalScaleX_plug(thisMObject(), aLocalScaleX);//???
//MPlug aLocalScaleY_plug(thisMObject(), aLocalScaleY);
//MPlug aLocalScaleZ_plug(thisMObject(), aLocalScaleZ);
}
MStatus normalTransformNode::compute(const MPlug& plug, MDataBlock& block)
{
MGlobal::displayInfo("running compute");
MStatus returnStatus;
if ((plug.attribute() == MPxTransform::matrix)
|| (plug.attribute() == MPxTransform::inverseMatrix)
|| (plug.attribute() == MPxTransform::worldMatrix)
|| (plug.attribute() == MPxTransform::worldInverseMatrix)
|| (plug.attribute() == MPxTransform::parentMatrix)
|| (plug.attribute() == MPxTransform::parentInverseMatrix))
{
MStatus status = MS::kSuccess;
//get the MPxTransformationMatrix instance that is paired with this node
normalTransformMatrix *ltm = getNormalTransformMatrix();
//get the localScale translate plug values
MPlug localScaleX_plug(thisMObject(), aLocalScaleX);
MPlug localScaleY_plug(thisMObject(), aLocalScaleY);
MPlug localScaleZ_plug(thisMObject(), aLocalScaleZ);
MDataHandle localScaleXHandle = block.inputValue(localScaleX_plug, &status);
MDataHandle localScaleYHandle = block.inputValue(localScaleY_plug, &status);
MDataHandle localScaleZHandle = block.inputValue(localScaleZ_plug, &status);
localScaleX_val = localScaleXHandle.asDouble();
localScaleY_val = localScaleYHandle.asDouble();
localScaleZ_val = localScaleZHandle.asDouble();
//get the offset translate plug values
MPlug offsetTranslateX_plug(thisMObject(), aOffsetTranslateX);
MPlug offsetTranslateY_plug(thisMObject(), aOffsetTranslateY);
MPlug offsetTranslateZ_plug(thisMObject(), aOffsetTranslateZ);
MDataHandle offsetTranslateXHandle = block.inputValue(offsetTranslateX_plug, &status);
MDataHandle offsetTranslateYHandle = block.inputValue(offsetTranslateY_plug, &status);
MDataHandle offsetTranslateZHandle = block.inputValue(offsetTranslateZ_plug, &status);
offsetTranslateX_val = offsetTranslateXHandle.asDouble();
offsetTranslateY_val = offsetTranslateYHandle.asDouble();
offsetTranslateZ_val = offsetTranslateZHandle.asDouble();
//get the offset rotate plug values
MPlug offsetRotateX_plug(thisMObject(), aOffsetRotateX);
MPlug offsetRotateY_plug(thisMObject(), aOffsetRotateY);
MPlug offsetRotateZ_plug(thisMObject(), aOffsetRotateZ);
MDataHandle offsetRotateXHandle = block.inputValue(offsetRotateX_plug, &status);
MDataHandle offsetRotateYHandle = block.inputValue(offsetRotateY_plug, &status);
MDataHandle offsetRotateZHandle = block.inputValue(offsetRotateZ_plug, &status);
offsetRotateX_val = offsetRotateXHandle.asDouble();
offsetRotateY_val = offsetRotateYHandle.asDouble();
offsetRotateZ_val = offsetRotateZHandle.asDouble();
//get the offset rotate plug values
MPlug offsetScaleX_plug(thisMObject(), aOffsetScaleX);
MPlug offsetScaleY_plug(thisMObject(), aOffsetScaleY);
MPlug offsetScaleZ_plug(thisMObject(), aOffsetScaleZ);
MDataHandle offsetScaleXHandle = block.inputValue(offsetScaleX_plug, &status);
MDataHandle offsetScaleYHandle = block.inputValue(offsetScaleY_plug, &status);
MDataHandle offsetScaleZHandle = block.inputValue(offsetScaleZ_plug, &status);
offsetScaleX_val = offsetScaleXHandle.asDouble();
offsetScaleY_val = offsetScaleYHandle.asDouble();
offsetScaleZ_val = offsetScaleZHandle.asDouble();
// Update the values in the MPxTransformationMatrix
if (ltm)
{
ltm->setLocalScaleX(localScaleX_val);
ltm->setLocalScaleY(localScaleY_val);
ltm->setLocalScaleZ(localScaleZ_val);
ltm->setOffsetTranslateX(offsetTranslateX_val);
ltm->setOffsetTranslateY(offsetTranslateY_val);
ltm->setOffsetTranslateZ(offsetTranslateZ_val);
ltm->setOffsetRotateX(offsetRotateX_val);
ltm->setOffsetRotateY(offsetRotateY_val);
ltm->setOffsetRotateZ(offsetRotateZ_val);
ltm->setOffsetScaleX(offsetScaleX_val);
ltm->setOffsetScaleY(offsetScaleY_val);
ltm->setOffsetScaleZ(offsetScaleZ_val);
}
else
{
MGlobal::displayInfo("Failed to get normal transform matrix");
}
}
return MPxTransform::compute(plug, block);
}
//
// Destructor of the normal transform
//
normalTransformNode::~normalTransformNode()
{
}
//
// Method that returns the new transformation matrix
//
MPxTransformationMatrix *normalTransformNode::createTransformationMatrix()
{
return new normalTransformMatrix();
}
//
// Method that returns a new transform node
//
void *normalTransformNode::creator()
{
return new normalTransformNode();
}
//
// Node initialize method. We configure node
// attributes here. Static method so
// the *this pointer is not available.
//
MStatus normalTransformNode::initialize()
{
MFnCompoundAttribute compoundFn;
MFnUnitAttribute unitFn;
//local scale attributes
aLocalScale = compoundFn.create("localScale", "ls");
aLocalScaleX = unitFn.create("localScaleX", "lsX", MFnUnitAttribute::kDistance, 1.0);
unitFn.setKeyable(true);
unitFn.setAffectsWorldSpace(true);
compoundFn.addChild(aLocalScaleX);
aLocalScaleY = unitFn.create("localScaleY", "lsY", MFnUnitAttribute::kDistance, 1.0);
unitFn.setKeyable(true);
unitFn.setAffectsWorldSpace(true);
compoundFn.addChild(aLocalScaleY);
aLocalScaleZ = unitFn.create("localScaleZ", "lsZ", MFnUnitAttribute::kDistance, 1.0);
unitFn.setKeyable(true);
unitFn.setAffectsWorldSpace(true);
compoundFn.addChild(aLocalScaleZ);
//offset translate attributes
aOffsetTranslate = compoundFn.create("offsetTranslate", "ot");
aOffsetTranslateX = unitFn.create("offsetTranslateX", "otX", MFnUnitAttribute::kDistance, 0.0);
unitFn.setKeyable(true);
unitFn.setAffectsWorldSpace(true);
compoundFn.addChild(aOffsetTranslateX);
aOffsetTranslateY = unitFn.create("offsetTranslateY", "otY", MFnUnitAttribute::kDistance, 0.0);
unitFn.setKeyable(true);
unitFn.setAffectsWorldSpace(true);
compoundFn.addChild(aOffsetTranslateY);
aOffsetTranslateZ = unitFn.create("offsetTranslateZ", "otZ", MFnUnitAttribute::kDistance, 0.0);
unitFn.setKeyable(true);
unitFn.setAffectsWorldSpace(true);
compoundFn.addChild(aOffsetTranslateZ);
//offset rotate attributes
aOffsetRotate = compoundFn.create("offsetRotate", "or");
aOffsetRotateX = unitFn.create("offsetRotateX", "orX", MFnUnitAttribute::kDistance, 0.0);
unitFn.setKeyable(true);
unitFn.setAffectsWorldSpace(true);
compoundFn.addChild(aOffsetRotateX);
aOffsetRotateY = unitFn.create("offsetRotateY", "orY", MFnUnitAttribute::kDistance, 0.0);
unitFn.setKeyable(true);
unitFn.setAffectsWorldSpace(true);
compoundFn.addChild(aOffsetRotateY);
aOffsetRotateZ = unitFn.create("offsetRotateZ", "orZ", MFnUnitAttribute::kDistance, 0.0);
unitFn.setKeyable(true);
unitFn.setAffectsWorldSpace(true);
compoundFn.addChild(aOffsetRotateZ);
//offset Scale attributes
aOffsetScale = compoundFn.create("offsetScale", "os");
aOffsetScaleX = unitFn.create("offsetScaleX", "osX", MFnUnitAttribute::kDistance, 1.0);
unitFn.setKeyable(true);
unitFn.setAffectsWorldSpace(true);
compoundFn.addChild(aOffsetScaleX);
aOffsetScaleY = unitFn.create("offsetScaleY", "osY", MFnUnitAttribute::kDistance, 1.0);
unitFn.setKeyable(true);
unitFn.setAffectsWorldSpace(true);
compoundFn.addChild(aOffsetScaleY);
aOffsetScaleZ = unitFn.create("offsetScaleZ", "osZ", MFnUnitAttribute::kDistance, 1.0);
unitFn.setKeyable(true);
unitFn.setAffectsWorldSpace(true);
compoundFn.addChild(aOffsetScaleZ);
addAttribute(aLocalScale);
addAttribute(aOffsetTranslate);
addAttribute(aOffsetRotate);
addAttribute(aOffsetScale);
// Need to update matrix when attribute is modified
attributeAffects(aLocalScaleX, matrix);
attributeAffects(aLocalScaleY, matrix);
attributeAffects(aLocalScaleZ, matrix);
attributeAffects(aOffsetTranslateX, matrix);
attributeAffects(aOffsetTranslateY, matrix);
attributeAffects(aOffsetTranslateZ, matrix);
attributeAffects(aOffsetRotateX, matrix);
attributeAffects(aOffsetRotateY, matrix);
attributeAffects(aOffsetRotateZ, matrix);
attributeAffects(aOffsetScaleX, matrix);
attributeAffects(aOffsetScaleY, matrix);
attributeAffects(aOffsetScaleZ, matrix);
// This is required so that the validateAndSet method
// is called
mustCallValidateAndSet(aLocalScaleX);
mustCallValidateAndSet(aLocalScaleY);
mustCallValidateAndSet(aLocalScaleZ);
mustCallValidateAndSet(aOffsetTranslateX);
mustCallValidateAndSet(aOffsetTranslateY);
mustCallValidateAndSet(aOffsetTranslateZ);
mustCallValidateAndSet(aOffsetRotateX);
mustCallValidateAndSet(aOffsetRotateY);
mustCallValidateAndSet(aOffsetRotateZ);
mustCallValidateAndSet(aOffsetScaleX);
mustCallValidateAndSet(aOffsetScaleY);
mustCallValidateAndSet(aOffsetScaleZ);
return MS::kSuccess;
}
//
// Debugging method
//
const char* normalTransformNode::className()
{
return "normalTransformNode";
}
//
// Reset transformation
//
void normalTransformNode::resetTransformation(const MMatrix &matrix)
{
ParentClass::resetTransformation(matrix);
}
//
// Reset transformation
//
void normalTransformNode::resetTransformation(MPxTransformationMatrix *resetMatrix)
{
ParentClass::resetTransformation(resetMatrix);
}
//this method updates the data in the MTransformationMatrix
MStatus normalTransformNode::validateAndSetValue(
const MPlug& plug,
const MDataHandle& handle)
{
MStatus status = MS::kSuccess;
// Make sure that there is something interesting to process.
//
if (plug.isNull())
return MS::kFailure;
MDataBlock block = forceCache();
MDataHandle blockHandle = block.outputValue(plug, &status);
//========================
// LocalScale
//========================
if (plug == aLocalScaleX)
{
// Update the value
double localScaleXin = handle.asDouble();
blockHandle.set(localScaleXin);
localScaleX_val = localScaleXin;
// Update the custom transformation matrix to the correct value
normalTransformMatrix *ltm = getNormalTransformMatrix();
if (ltm) {
MGlobal::displayInfo(MString("setting local scale X:") + localScaleX_val);
ltm->setLocalScaleX(localScaleXin);
}
else {
MGlobal::displayError("Failed to get rock transform matrix");
}
blockHandle.setClean();
// Mark the matrix as dirty so that DG information will update.
MGlobal::displayInfo("matrix is being dirted");
dirtyMatrix();
return MS::kSuccess;
}
if (plug == aLocalScaleY)
{
// Update the value
double localScaleYin = handle.asDouble();
blockHandle.set(localScaleYin);
localScaleY_val = localScaleYin;
// Update the custom transformation matrix to the correct value
normalTransformMatrix *ltm = getNormalTransformMatrix();
if (ltm)
ltm->setLocalScaleY(localScaleYin);
else
MGlobal::displayError("Failed to get rock transform matrix");
blockHandle.setClean();
// Mark the matrix as dirty so that DG information will update.
dirtyMatrix();
return MS::kSuccess;
}
if (plug == aLocalScaleZ)
{
// Update the value
double localScaleZin = handle.asDouble();
blockHandle.set(localScaleZin);
localScaleZ_val = localScaleZin;
// Update the custom transformation matrix to the correct value
normalTransformMatrix *ltm = getNormalTransformMatrix();
if (ltm)
ltm->setLocalScaleZ(localScaleZin);
else
MGlobal::displayError("Failed to get rock transform matrix");//!!! remove these
blockHandle.setClean();
// Mark the matrix as dirty so that DG information will update.
dirtyMatrix();
return MS::kSuccess;
}
//========================
// offsetTranslate
//========================
if (plug == aOffsetTranslateX)
{
// Update the value
double offsetTranslateXin = handle.asDouble();
blockHandle.set(offsetTranslateXin);
offsetTranslateX_val = offsetTranslateXin;
// Update the custom transformation matrix to the correct value
normalTransformMatrix *ltm = getNormalTransformMatrix();
if (ltm)
ltm->setOffsetTranslateX(offsetTranslateXin);
else
MGlobal::displayError("Failed to get rock transform matrix");//!!! remove these
blockHandle.setClean();
// Mark the matrix as dirty so that DG information will update.
dirtyMatrix();
return MS::kSuccess;
}
if (plug == aOffsetTranslateY)
{
// Update the value
double offsetTranslateYin = handle.asDouble();
blockHandle.set(offsetTranslateYin);
offsetTranslateY_val = offsetTranslateYin;
// Update the custom transformation matrix to the correct value
normalTransformMatrix *ltm = getNormalTransformMatrix();
if (ltm)
ltm->setOffsetTranslateY(offsetTranslateYin);
else
MGlobal::displayError("Failed to get rock transform matrix");//!!! remove these
blockHandle.setClean();
// Mark the matrix as dirty so that DG information will update.
dirtyMatrix();
return MS::kSuccess;
}
if (plug == aOffsetTranslateZ)
{
// Update the value
double offsetTranslateZin = handle.asDouble();
blockHandle.set(offsetTranslateZin);
offsetTranslateZ_val = offsetTranslateZin;
// Update the custom transformation matrix to the correct value
normalTransformMatrix *ltm = getNormalTransformMatrix();
if (ltm)
ltm->setOffsetTranslateZ(offsetTranslateZin);
else
MGlobal::displayError("Failed to get rock transform matrix");//!!! remove these
blockHandle.setClean();
// Mark the matrix as dirty so that DG information will update.
dirtyMatrix();
return MS::kSuccess;
}
//========================
// offsetRotate
//========================
if (plug == aOffsetRotateX)
{
// Update the value
double offsetRotateXin = handle.asDouble();
blockHandle.set(offsetRotateXin);
offsetRotateX_val = offsetRotateXin;
// Update the custom transformation matrix to the correct value
normalTransformMatrix *ltm = getNormalTransformMatrix();
if (ltm)
ltm->setOffsetRotateX(offsetRotateXin);
else
MGlobal::displayError("Failed to get rock transform matrix");//!!! remove these
blockHandle.setClean();
// Mark the matrix as dirty so that DG information will update.
dirtyMatrix();
return MS::kSuccess;
}
if (plug == aOffsetRotateY)
{
// Update the value
double offsetRotateYin = handle.asDouble();
blockHandle.set(offsetRotateYin);
offsetRotateY_val = offsetRotateYin;
// Update the custom transformation matrix to the correct value
normalTransformMatrix *ltm = getNormalTransformMatrix();
if (ltm)
ltm->setOffsetRotateY(offsetRotateYin);
else
MGlobal::displayError("Failed to get rock transform matrix");//!!! remove these
blockHandle.setClean();
// Mark the matrix as dirty so that DG information will update.
dirtyMatrix();
return MS::kSuccess;
}
if (plug == aOffsetRotateZ)
{
// Update the value
double offsetRotateZin = handle.asDouble();
blockHandle.set(offsetRotateZin);
offsetRotateZ_val = offsetRotateZin;
// Update the custom transformation matrix to the correct value
normalTransformMatrix *ltm = getNormalTransformMatrix();
if (ltm)
ltm->setOffsetRotateZ(offsetRotateZin);
else
MGlobal::displayError("Failed to get rock transform matrix");//!!! remove these
blockHandle.setClean();
// Mark the matrix as dirty so that DG information will update.
dirtyMatrix();
return MS::kSuccess;
}
//========================
// offsetScale
//========================
if (plug == aOffsetScaleX)
{
// Update the value
double offsetScaleXin = handle.asDouble();
blockHandle.set(offsetScaleXin);
offsetScaleX_val = offsetScaleXin;
// Update the custom transformation matrix to the correct value
normalTransformMatrix *ltm = getNormalTransformMatrix();
if (ltm)
ltm->setOffsetScaleX(offsetScaleXin);
else
MGlobal::displayError("Failed to get rock transform matrix");//!!! remove these
blockHandle.setClean();
// Mark the matrix as dirty so that DG information will update.
dirtyMatrix();
return MS::kSuccess;
}
if (plug == aOffsetScaleY)
{
// Update the value
double offsetScaleYin = handle.asDouble();
blockHandle.set(offsetScaleYin);
offsetScaleY_val = offsetScaleYin;
// Update the custom transformation matrix to the correct value
normalTransformMatrix *ltm = getNormalTransformMatrix();
if (ltm)
ltm->setOffsetScaleY(offsetScaleYin);
else
MGlobal::displayError("Failed to get rock transform matrix");//!!! remove these
blockHandle.setClean();
// Mark the matrix as dirty so that DG information will update.
dirtyMatrix();
return MS::kSuccess;
}
if (plug == aOffsetScaleZ)
{
// Update the value
double offsetScaleZin = handle.asDouble();
blockHandle.set(offsetScaleZin);
offsetScaleZ_val = offsetScaleZin;
// Update the custom transformation matrix to the correct value
normalTransformMatrix *ltm = getNormalTransformMatrix();
if (ltm)
ltm->setOffsetScaleZ(offsetScaleZin);
else
MGlobal::displayError("Failed to get rock transform matrix");//!!! remove these
blockHandle.setClean();
// Mark the matrix as dirty so that DG information will update.
dirtyMatrix();
return MS::kSuccess;
}
// Allow processing for other attributes
return ParentClass::validateAndSetValue(plug, handle);
}
//
// Method for returning the current rocking transformation matrix
//
normalTransformMatrix *normalTransformNode::getNormalTransformMatrix()
{
normalTransformMatrix *ltm = (normalTransformMatrix *)transformationMatrixPtr();
return ltm;
}
//fix the manipulator stuff!!!