#include <maya/MIOStream.h>
#include <maya/MPxIkSolverNode.h>
#include <maya/MString.h>
#include <maya/MFnPlugin.h>
#include <maya/MObject.h>
#include <maya/MIkHandleGroup.h>
#include <maya/MFnIkHandle.h>
#include <maya/MDagPath.h>
#include <maya/MVector.h>
#include <maya/MPoint.h>
#include <maya/MDoubleArray.h>
#define MAX_ITERATIONS 1
#define kSolverType "simpleSolverNode"
public:
simpleSolverNode();
~simpleSolverNode() override;
static void* creator();
private:
};
MTypeId simpleSolverNode::id( 0x80100 );
simpleSolverNode::simpleSolverNode()
{
}
simpleSolverNode::~simpleSolverNode() {}
void* simpleSolverNode::creator()
{
return new simpleSolverNode;
}
MStatus simpleSolverNode::initialize()
{
return MS::kSuccess;
}
MString simpleSolverNode::solverTypeName() const
{
}
MStatus simpleSolverNode::doSolve()
{
doSimpleSolver();
return MS::kSuccess;
}
MStatus simpleSolverNode::doSimpleSolver()
{
if (NULL == handle_group) {
return MS::kFailure;
}
fnHandle.getEffector(end_effector);
fnHandle.getStartJoint( start_joint );
MVector v1 = start_position - effector_position;
MVector v2 = start_position - handle_position;
double angle = v1.
angle( v2 );
#define CW rot = -1.0 * angle; // clockwise
#define CCW rot = angle; // counter-clockwise
double rot = 0.0;
MVector U = effector_position - start_position;
MVector P = handle_position - effector_position;
double PdotN = P[0]*N[0] + P[1]*N[1];
if ( PdotN < 0 ) {
CCW;
} else {
CW;
}
if ( getJointAngles( jointAngles ) ) {
jointAngles.
set( jointAngles[0] + rot, 0 );
setJointAngles( jointAngles );
}
return MS::kSuccess;
}
{
MFnPlugin plugin( obj, PLUGIN_COMPANY,
"3.0",
"Any");
status = plugin.registerNode("simpleSolverNode",
simpleSolverNode::id,
&simpleSolverNode::creator,
&simpleSolverNode::initialize,
if (!status) {
status.
perror(
"registerNode");
return status;
}
return status;
}
{
status = plugin.deregisterNode(simpleSolverNode::id);
if (!status) {
status.
perror(
"deregisterNode");
return status;
}
return status;
}