#include <math.h>
#include <maya/MIOStream.h>
#include <maya/MPxNode.h>
#include <maya/MPxLocatorNode.h>
#include <maya/MString.h>
#include <maya/MTypeId.h>
#include <maya/MPlug.h>
#include <maya/MVector.h>
#include <maya/MAngle.h>
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>
#include <maya/MColor.h>
#include <maya/M3dView.h>
#include <maya/MFnPlugin.h>
#include <maya/MDistance.h>
#include <maya/MFnUnitAttribute.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MFn.h>
#include <maya/MPxNode.h>
#include <maya/MPxManipContainer.h>
#include <maya/MFnCircleSweepManip.h>
#include <maya/MFnDirectionManip.h>
#include <maya/MFnDiscManip.h>
#include <maya/MFnDistanceManip.h>
#include <maya/MFnFreePointTriadManip.h>
#include <maya/MFnStateManip.h>
#include <maya/MFnToggleManip.h>
#include <maya/MFnRotateManip.h>
#include <maya/MFnScaleManip.h>
#include <maya/MPxContext.h>
#include <maya/MPxSelectionContext.h>
#include <maya/MPxDrawOverride.h>
#include <maya/MStateManager.h>
#include <maya/MDrawRegistry.h>
#include <maya/MDrawContext.h>
#include <maya/MHWGeometryUtilities.h>
#include <maya/MShaderManager.h>
#include <maya/MFnNumericData.h>
#include <maya/MManipData.h>
#define e \
counter++; \
if (MS::kSuccess != s) { \
cerr << "Status Error in method " << method \
<< " at checkpoint #" << counter << "." << "\n" \
<< " in File: " << __FILE__ \
<< ", at Line: " << __LINE__ << endl; \
s.perror("Error"); \
}
const double delta1 = 0.01;
const double delta2 = 0.02;
const double delta3 = 0.03;
const double delta4 = 0.04;
static float centre[][3] = { { 0.10f, 0.0f, 0.10f},
{ 0.10f, 0.0f, -0.10f },
{ -0.10f, 0.0f, -0.10f },
{ -0.10f, 0.0f, 0.10f },
{ 0.10f, 0.0f, 0.10f } };
static float state1[][3] = { { 1.00f, 0.0f, 1.00f},
{ 1.00f, 0.0f, 0.50f },
{ 0.50f, 0.0f, 0.50f },
{ 0.50f, 0.0f, 1.00f },
{ 1.00f, 0.0f, 1.00f } };
static float state2[][3] = { { 1.00f, 0.0f, -1.00f},
{ 1.00f, 0.0f, -0.50f },
{ 0.50f, 0.0f, -0.50f },
{ 0.50f, 0.0f, -1.00f },
{ 1.00f, 0.0f, -1.00f } };
static float state3[][3] = { { -1.00f, 0.0f, -1.00f},
{ -1.00f, 0.0f, -0.50f },
{ -0.50f, 0.0f, -0.50f },
{ -0.50f, 0.0f, -1.00f },
{ -1.00f, 0.0f, -1.00f } };
static float state4[][3] = { { -1.00f, 0.0f, 1.00f},
{ -1.00f, 0.0f, 0.50f },
{ -0.50f, 0.0f, 0.50f },
{ -0.50f, 0.0f, 1.00f },
{ -1.00f, 0.0f, 1.00f } };
static float arrow1[][3] = { { 0.00f, 0.0f, 1.00f},
{ 0.10f, 0.0f, 0.20f },
{ -0.10f, 0.0f, 0.20f },
{ 0.00f, 0.0f, 1.00f } };
static float arrow2[][3] = { { 1.00f, 0.0f, 0.00f},
{ 0.20f, 0.0f, 0.10f },
{ 0.20f, 0.0f, -0.10f },
{ 1.00f, 0.0f, 0.00f } };
static float arrow3[][3] = { { 0.00f, 0.0f, -1.00f},
{ 0.10f, 0.0f, -0.20f },
{ -0.10f, 0.0f, -0.20f },
{ 0.00f, 0.0f, -1.00f } };
static float arrow4[][3] = { { -1.00f, 0.0f, 0.00f},
{ -0.20f, 0.0f, 0.10f },
{ -0.20f, 0.0f, -0.10f },
{ -1.00f, 0.0f, 0.00f } };
static float perimeter[][3] = { { 1.10f, 0.0f, 1.10f},
{ 1.10f, 0.0f, -1.10f },
{ -1.10f, 0.0f, -1.10f },
{ -1.10f, 0.0f, 1.10f },
{ 1.10f, 0.0f, 1.10f } };
static int centreCount = 5;
static int state1Count = 5;
static int state2Count = 5;
static int state3Count = 5;
static int state4Count = 5;
static int arrow1Count = 4;
static int arrow2Count = 4;
static int arrow3Count = 4;
static int arrow4Count = 4;
static int perimeterCount = 5;
{
public:
swissArmyLocatorManip();
~swissArmyLocatorManip() override;
static void * creator();
MManipData startPointCallback(
unsigned index)
const;
public:
};
MManipData swissArmyLocatorManip::startPointCallback(
unsigned )
const
{
manipData = numDataObj;
return manipData;
}
MVector swissArmyLocatorManip::nodeTranslation()
const
{
}
MTypeId swissArmyLocatorManip::id( 0x8001e );
swissArmyLocatorManip::swissArmyLocatorManip()
{
}
swissArmyLocatorManip::~swissArmyLocatorManip()
{
}
void* swissArmyLocatorManip::creator()
{
return new swissArmyLocatorManip();
}
MStatus swissArmyLocatorManip::initialize()
{
return stat;
}
MStatus swissArmyLocatorManip::createChildren()
{
MString method(
"swissArmyLocatorManip::createChildren");
int counter = 0;
fFreePointTriadManip = addFreePointTriadManip("freePointTriadManip",
"point");
fDirectionManip = addDirectionManip("directionManip",
"direction");
fToggleManip = addToggleManip("toggleManip", "toggle");
fStateManip = addStateManip("stateManip", "state");
fDiscManip = addDiscManip("discManip",
"angle");
fCircleSweepManip = addCircleSweepManip("circleSweepManip",
"angle");
circleSweepManipFn.setCenterPoint(
MPoint(0, 0, 0));
circleSweepManipFn.setNormal(
MVector(0, 1, 0));
circleSweepManipFn.setRadius(2.0);
circleSweepManipFn.setDrawAsArc(true);
MString manipName(
"distanceManip");
MPoint startPoint(0.0, 0.0, 0.0);
fDistanceManip = addDistanceManip(manipName,
distanceName);
distanceManipFn.setStartPoint(startPoint);
distanceManipFn.setDirection(direction);
MString RotateManipName(
"RotateManip");
fRotateManip = addRotateManip(RotateManipName, rotateName);
MString scaleManipName(
"scaleManip");
fScaleManip = addScaleManip(scaleManipName, scaleName);
return stat;
}
MStatus swissArmyLocatorManip::connectToDependNode(
const MObject &node)
{
dagNodeFn.getPath(fNodePath);
MObject parentNode = dagNodeFn.parent(0);
MPlug translationPlug = parentNodeFn.findPlug(
"t",
true, &stat);
freePointTriadManipFn.connectToPointPlug(translationPlug);
}
MPlug directionPlug = nodeFn.
findPlug(
"arrow2Direction",
true, &stat);
addPlugToManipConversionCallback(startPointIndex,
(plugToManipConversionCallback)
&swissArmyLocatorManip::startPointCallback);
}
addPlugToManipConversionCallback(startPointIndex,
(plugToManipConversionCallback)
&swissArmyLocatorManip::startPointCallback);
}
MPlug arrow1AnglePlug = nodeFn.
findPlug(
"arrow1Angle",
true, &stat);
circleSweepManipFn.connectToAnglePlug(arrow1AnglePlug);
unsigned centerIndex = circleSweepManipFn.centerIndex();
addPlugToManipConversionCallback(centerIndex,
(plugToManipConversionCallback)
&swissArmyLocatorManip::startPointCallback);
}
MPlug arrow3AnglePlug = nodeFn.
findPlug(
"arrow3Angle",
true, &stat);
discManipFn.connectToAnglePlug(arrow3AnglePlug);
unsigned centerIndex = discManipFn.centerIndex();
addPlugToManipConversionCallback(centerIndex,
(plugToManipConversionCallback)
&swissArmyLocatorManip::startPointCallback);
}
stateManipFn.connectToStatePlug(statePlug);
unsigned positionIndex = stateManipFn.positionIndex();
addPlugToManipConversionCallback(positionIndex,
(plugToManipConversionCallback)
&swissArmyLocatorManip::startPointCallback);
}
toggleManipFn.connectToTogglePlug(togglePlug);
unsigned startPointIndex = toggleManipFn.startPointIndex();
addPlugToManipConversionCallback(startPointIndex,
(plugToManipConversionCallback)
&swissArmyLocatorManip::startPointCallback);
}
transformPath.pop();
MPlug rotatePlug = transformNode.findPlug(
"rotate",
true, &stat);
rotateManipFn.connectToRotationPlug(rotatePlug);
rotateManipFn.displayWithNode(node);
}
MPlug scalePlug = transformNode.findPlug(
"scale",
true, &stat);
scaleManipFn.connectToScalePlug(scalePlug);
scaleManipFn.displayWithNode(node);
}
finishAddingManips();
return stat;
}
void swissArmyLocatorManip::preDrawUI(
const M3dView &view )
{
fTextPosition = nodeTranslation();
}
{
}
{
public:
swissArmyLocator();
~swissArmyLocator() override;
struct DrawData
{
float multiplier;
double angle1;
double angle2;
double angle3;
int state;
bool toggle;
};
void getDrawData(DrawData& data);
static void drawOutline(const DrawData& data);
static void * creator();
public:
};
MTypeId swissArmyLocator::id( 0x8001f );
MString swissArmyLocator::classification(
"drawdb/geometry/swissArmyLocator");
MString swissArmyLocator::registrantId(
"SwissArmyLocatorNodePlugin");
MObject swissArmyLocator::aArrow1Angle;
MObject swissArmyLocator::aArrow2Direction;
MObject swissArmyLocator::aArrow2DirectionX;
MObject swissArmyLocator::aArrow2DirectionY;
MObject swissArmyLocator::aArrow2DirectionZ;
MObject swissArmyLocator::aArrow3Angle;
MObject swissArmyLocator::aArrow4Distance;
swissArmyLocator::swissArmyLocator()
{}
swissArmyLocator::~swissArmyLocator()
{}
{
return MS::kUnknownParameter;
}
void swissArmyLocator::getDrawData(DrawData& data)
{
MPlug plug(node, swissArmyLocator::aSize);
plug.getValue(sizeVal);
MPlug arrow1AnglePlug(node, swissArmyLocator::aArrow1Angle);
data.angle1 = -arrow1Angle.
asRadians() - 3.1415927/2.0;
MPlug directionXPlug(node, swissArmyLocator::aArrow2DirectionX);
MPlug directionZPlug(node, swissArmyLocator::aArrow2DirectionZ);
double dirX, dirZ;
directionXPlug.getValue(dirX);
directionZPlug.getValue(dirZ);
data.angle2 = atan2(dirZ,dirX) + 3.1415927;
MPlug arrow3AnglePlug(node, swissArmyLocator::aArrow3Angle);
MPlug statePlug(node, swissArmyLocator::aState);
MPlug togglePlug(node, swissArmyLocator::aToggle);
}
void swissArmyLocator::drawOutline(const DrawData& data)
{
glBegin(GL_LINES);
int i;
int last;
if (data.toggle) {
last = centreCount - 1;
for (i = 0; i < last; ++i) {
glVertex3f(centre[i][0] * data.multiplier,
centre[i][1] * data.multiplier,
centre[i][2] * data.multiplier);
glVertex3f(centre[i+1][0] * data.multiplier,
centre[i+1][1] * data.multiplier,
centre[i+1][2] * data.multiplier);
}
}
if (data.state == 0) {
last = state1Count - 1;
for (i = 0; i < last; ++i) {
glVertex3f(state1[i][0] * data.multiplier,
state1[i][1] * data.multiplier,
state1[i][2] * data.multiplier);
glVertex3f(state1[i+1][0] * data.multiplier,
state1[i+1][1] * data.multiplier,
state1[i+1][2] * data.multiplier);
}
}
if (data.state == 1) {
last = state2Count - 1;
for (i = 0; i < last; ++i) {
glVertex3f(state2[i][0] * data.multiplier,
state2[i][1] * data.multiplier,
state2[i][2] * data.multiplier);
glVertex3f(state2[i+1][0] * data.multiplier,
state2[i+1][1] * data.multiplier,
state2[i+1][2] * data.multiplier);
}
}
if (data.state == 2) {
last = state3Count - 1;
for (i = 0; i < last; ++i) {
glVertex3f(state3[i][0] * data.multiplier,
state3[i][1] * data.multiplier,
state3[i][2] * data.multiplier);
glVertex3f(state3[i+1][0] * data.multiplier,
state3[i+1][1] * data.multiplier,
state3[i+1][2] * data.multiplier);
}
}
if (data.state == 3) {
last = state4Count - 1;
for (i = 0; i < last; ++i) {
glVertex3f(state4[i][0] * data.multiplier,
state4[i][1] * data.multiplier,
state4[i][2] * data.multiplier);
glVertex3f(state4[i+1][0] * data.multiplier,
state4[i+1][1] * data.multiplier,
state4[i+1][2] * data.multiplier);
}
}
last = arrow1Count - 1;
for (i = 0; i < last; ++i) {
glVertex3f((float) (- arrow1[i][0] * data.multiplier * cos(data.angle1)
- arrow1[i][2] * data.multiplier * sin(data.angle1)),
(float) (arrow1[i][1] * data.multiplier + delta1),
(float) (arrow1[i][2] * data.multiplier * cos(data.angle1) -
arrow1[i][0] * data.multiplier * sin(data.angle1)));
glVertex3f((float) (- arrow1[i+1][0] * data.multiplier * cos(data.angle1)
- arrow1[i+1][2] * data.multiplier * sin(data.angle1)),
(float) (arrow1[i+1][1] * data.multiplier + delta1),
(float) (arrow1[i+1][2] * data.multiplier * cos(data.angle1) -
arrow1[i+1][0] * data.multiplier * sin(data.angle1)));
}
last = arrow2Count - 1;
for (i = 0; i < last; ++i) {
glVertex3f((float) (- arrow2[i][0] * data.multiplier * cos(data.angle2)
- arrow2[i][2] * data.multiplier * sin(data.angle2)),
(float) (arrow2[i][1] * data.multiplier + delta2),
(float) (arrow2[i][2] * data.multiplier * cos(data.angle2) -
arrow2[i][0] * data.multiplier * sin(data.angle2)));
glVertex3f((float) (- arrow2[i+1][0] * data.multiplier * cos(data.angle2)
- arrow2[i+1][2] * data.multiplier * sin(data.angle2)),
(float) (arrow2[i+1][1] * data.multiplier + delta2),
(float) (arrow2[i+1][2] * data.multiplier * cos(data.angle2) -
arrow2[i+1][0] * data.multiplier * sin(data.angle2)));
}
last = arrow3Count - 1;
for (i = 0; i < last; ++i) {
glVertex3f((float) (- arrow3[i][0] * data.multiplier * cos(data.angle3)
- arrow3[i][2] * data.multiplier * sin(data.angle3)),
(float) (arrow3[i][1] * data.multiplier + delta3),
(float) (arrow3[i][2] * data.multiplier * cos(data.angle3) -
arrow3[i][0] * data.multiplier * sin(data.angle3)));
glVertex3f((float) (- arrow3[i+1][0] * data.multiplier * cos(data.angle3)
- arrow3[i+1][2] * data.multiplier * sin(data.angle3)),
(float) (arrow3[i+1][1] * data.multiplier + delta3),
(float) (arrow3[i+1][2] * data.multiplier * cos(data.angle3) -
arrow3[i+1][0] * data.multiplier * sin(data.angle3)));
}
last = arrow4Count - 1;
for (i = 0; i < last; ++i) {
glVertex3f((float) (arrow4[i][0] * data.multiplier),
(float) (arrow4[i][1] * data.multiplier + delta4),
(float) (arrow4[i][2] * data.multiplier));
glVertex3f((float) (arrow4[i+1][0] * data.multiplier),
(float) (arrow4[i+1][1] * data.multiplier + delta4),
(float) (arrow4[i+1][2] * data.multiplier));
}
last = perimeterCount - 1;
for (i = 0; i < last; ++i) {
glVertex3f(perimeter[i][0] * data.multiplier,
perimeter[i][1] * data.multiplier,
perimeter[i][2] * data.multiplier);
glVertex3f(perimeter[i+1][0] * data.multiplier,
perimeter[i+1][1] * data.multiplier,
perimeter[i+1][2] * data.multiplier);
}
glEnd();
}
bool swissArmyLocator::isBounded() const
{
return true;
}
{
MPlug plug(thisNode, aSize);
plug.getValue(sizeVal);
MPoint corner1(-1.1, 0.0, -1.1);
MPoint corner2(1.1, 0.0, 1.1);
corner1 = corner1 * multiplier;
corner2 = corner2 * multiplier;
}
void* swissArmyLocator::creator()
{
return new swissArmyLocator();
}
MStatus swissArmyLocator::initialize()
{
MString method(
"swissArmyLocator::initialize");
int counter = 0;
0.0, &s); e;
aPointX = numericFn.
create(
"pointX",
"ptx",
aPointY = numericFn.
create(
"pointY",
"pty",
aPointZ = numericFn.
create(
"pointZ",
"ptz",
aPoint = numericFn.
create(
"point",
"pt",
aPointX,
aPointY,
aPointZ, &s); e;
aArrow1Angle = unitFn.
create(
"arrow1Angle",
"a1a",
aArrow2DirectionX = numericFn.
create(
"arrow2DirectionX",
"a2x",
aArrow2DirectionY = numericFn.
create(
"arrow2DirectionY",
"a2y",
aArrow2DirectionZ = numericFn.
create(
"arrow2DirectionZ",
"a2z",
aArrow2Direction = numericFn.
create(
"arrow2Direction",
"dir",
aArrow2DirectionX,
aArrow2DirectionY,
aArrow2DirectionZ, &s); e;
aArrow3Angle = unitFn.
create(
"arrow3Angle",
"a3a",
aArrow4Distance = unitFn.
create(
"arrow2Distance",
"dis",
aState = numericFn.
create(
"state",
"s",
aToggle = numericFn.
create(
"toggle",
"t",
s = addAttribute(aPoint); e;
s = addAttribute(aArrow1Angle); e;
s = addAttribute(aArrow2Direction); e;
s = addAttribute(aArrow3Angle); e;
s = addAttribute(aArrow4Distance); e;
s = addAttribute(aState); e;
s = addAttribute(aToggle); e;
stat = addAttribute(aSize);
if (!stat) {
return stat;
}
return MS::kSuccess;
}
{
public:
{
return new swissArmyLocatorOverride(obj);
}
~swissArmyLocatorOverride() override;
const MDagPath& cameraPath)
const override;
const MDagPath& cameraPath)
const override;
static void draw(
private:
swissArmyLocatorOverride(
const MObject& obj);
};
class swissArmyLocatorData :
public MUserData
{
public:
~swissArmyLocatorData() override {}
swissArmyLocator::DrawData drawData;
float color[4];
};
swissArmyLocatorOverride::swissArmyLocatorOverride(
const MObject& obj)
:
MHWRender::MPxDrawOverride(obj, swissArmyLocatorOverride::draw)
{
}
swissArmyLocatorOverride::~swissArmyLocatorOverride()
{
}
{
}
bool swissArmyLocatorOverride::isBounded(
{
return true;
}
bool swissArmyLocatorOverride::excludedFromPostEffects() const
{
return true;
}
{
swissArmyLocator* swissNode =
dynamic_cast<swissArmyLocator*>(node.userNode());
return swissNode->boundingBox();
}
MUserData* swissArmyLocatorOverride::prepareForDraw(
{
if (!status) return NULL;
swissArmyLocator* swissNode =
dynamic_cast<swissArmyLocator*>(node.userNode());
if (!swissNode) return NULL;
swissArmyLocatorData* data =
dynamic_cast<swissArmyLocatorData*>(oldData);
if (!data)
{
data = new swissArmyLocatorData();
}
swissNode->getDrawData(data->drawData);
data->color[0] = color.
r;
data->color[1] = color.
g;
data->color[2] = color.
b;
data->color[3] = 1.0f;
return data;
}
void swissArmyLocatorOverride::draw(
{
const swissArmyLocatorData* locatorData =
dynamic_cast<const swissArmyLocatorData*>(data);
if (!stateMgr || !locatorData) return;
{
for (
unsigned int i=0; i<passSem.
length(); i++)
{
{
}
}
}
if (passShaderOverride)
{
passShaderOverride->
bind( context );
}
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadMatrixd(transform.
matrix[0]);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadMatrixd(projection.
matrix[0]);
glPushAttrib(GL_CURRENT_BIT);
glColor4fv(locatorData->color);
swissArmyLocator::drawOutline(locatorData->drawData);
glPopAttrib();
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
if (passShaderOverride)
{
passShaderOverride->
unbind( context );
if ( theRenderer )
}
}
{
MFnPlugin plugin(obj, PLUGIN_COMPANY,
"6.0",
"Any");
status = plugin.registerNode("swissArmyLocator",
swissArmyLocator::id,
&swissArmyLocator::creator,
&swissArmyLocator::initialize,
&swissArmyLocator::classification);
if (!status) {
status.
perror(
"registerNode");
return status;
}
swissArmyLocator::classification,
swissArmyLocator::registrantId,
swissArmyLocatorOverride::Creator);
if (!status) {
status.
perror(
"registerDrawOverrideCreator");
return status;
}
status = plugin.registerNode("swissArmyLocatorManip",
swissArmyLocatorManip::id,
&swissArmyLocatorManip::creator,
&swissArmyLocatorManip::initialize,
if (!status) {
status.
perror(
"registerNode");
return status;
}
return status;
}
{
status = plugin.deregisterNode(swissArmyLocator::id);
if (!status) {
status.
perror(
"deregisterNode");
return status;
}
swissArmyLocator::classification,
swissArmyLocator::registrantId);
if (!status) {
status.
perror(
"deregisterDrawOverrideCreator");
return status;
}
status = plugin.deregisterNode(swissArmyLocatorManip::id);
if (!status) {
status.
perror(
"deregisterNode");
return status;
}
return status;
}