#include "pointOnMeshInfoNode.h"
#include "getPointAndNormal.h"
#include <maya/MIOStream.h>
MTypeId pointOnMeshInfoNode::id(0x00105480);
MObject pointOnMeshInfoNode::aInMesh;
MObject pointOnMeshInfoNode::aFaceIndex;
MObject pointOnMeshInfoNode::aRelative;
MObject pointOnMeshInfoNode::aParameterU;
MObject pointOnMeshInfoNode::aParameterV;
MObject pointOnMeshInfoNode::aPosition;
MObject pointOnMeshInfoNode::aPositionX;
MObject pointOnMeshInfoNode::aPositionY;
MObject pointOnMeshInfoNode::aPositionZ;
MObject pointOnMeshInfoNode::aNormal;
MObject pointOnMeshInfoNode::aNormalX;
MObject pointOnMeshInfoNode::aNormalY;
MObject pointOnMeshInfoNode::aNormalZ;
pointOnMeshInfoNode::pointOnMeshInfoNode()
{
}
pointOnMeshInfoNode::~pointOnMeshInfoNode()
{
}
void *pointOnMeshInfoNode::creator()
{
return new pointOnMeshInfoNode();
}
MStatus pointOnMeshInfoNode::initialize()
{
MFnTypedAttribute inMeshAttrFn;
aInMesh = inMeshAttrFn.create("inMesh", "im", MFnData::kMesh);
CHECK_MSTATUS ( inMeshAttrFn.setStorable(true) );
CHECK_MSTATUS ( inMeshAttrFn.setKeyable(false) );
CHECK_MSTATUS ( inMeshAttrFn.setReadable(true) );
CHECK_MSTATUS ( inMeshAttrFn.setWritable(true) );
CHECK_MSTATUS ( inMeshAttrFn.setCached(false) );
CHECK_MSTATUS ( addAttribute(aInMesh));
MFnNumericAttribute faceIndexAttrFn;
aFaceIndex = faceIndexAttrFn.create("faceIndex", "f", MFnNumericData::kLong, 0);
CHECK_MSTATUS (faceIndexAttrFn.setStorable(true));
CHECK_MSTATUS ( faceIndexAttrFn.setKeyable(true) );
CHECK_MSTATUS ( faceIndexAttrFn.setReadable(true) );
CHECK_MSTATUS ( faceIndexAttrFn.setWritable(true) );
CHECK_MSTATUS ( faceIndexAttrFn.setMin(0) );
CHECK_MSTATUS ( addAttribute(aFaceIndex) );
MFnNumericAttribute relativeAttrFn;
aRelative = relativeAttrFn.create("relative", "r", MFnNumericData::kBoolean, 1);
CHECK_MSTATUS ( relativeAttrFn.setStorable(true) );
CHECK_MSTATUS ( relativeAttrFn.setKeyable(true));
CHECK_MSTATUS ( relativeAttrFn.setReadable(true) );
CHECK_MSTATUS ( relativeAttrFn.setWritable(true) );
CHECK_MSTATUS ( addAttribute(aRelative) );
MFnNumericAttribute parameterUAttrFn;
aParameterU = parameterUAttrFn.create("parameterU", "u", MFnNumericData::kDouble, 0.5);
CHECK_MSTATUS ( parameterUAttrFn.setStorable(true) );
CHECK_MSTATUS ( parameterUAttrFn.setKeyable(true) );
CHECK_MSTATUS ( parameterUAttrFn.setReadable(true) ) ;
CHECK_MSTATUS ( parameterUAttrFn.setWritable(true) ) ;
CHECK_MSTATUS ( addAttribute(aParameterU) );
MFnNumericAttribute parameterVAttrFn;
aParameterV = parameterVAttrFn.create("parameterV", "v", MFnNumericData::kDouble, 0.5);
CHECK_MSTATUS ( parameterVAttrFn.setStorable(true) );
CHECK_MSTATUS ( parameterVAttrFn.setKeyable(true) );
CHECK_MSTATUS ( parameterVAttrFn.setReadable(true) );
CHECK_MSTATUS ( parameterVAttrFn.setWritable(true) );
CHECK_MSTATUS ( addAttribute(aParameterV) );
MFnNumericAttribute pointXAttrFn;
aPositionX = pointXAttrFn.create("positionX", "px", MFnNumericData::kDouble, 0.0);
CHECK_MSTATUS ( pointXAttrFn.setStorable(false) );
CHECK_MSTATUS ( pointXAttrFn.setKeyable(false) );
CHECK_MSTATUS ( pointXAttrFn.setReadable(true) ) ;
CHECK_MSTATUS ( pointXAttrFn.setWritable(false) );
CHECK_MSTATUS ( addAttribute(aPositionX) );
MFnNumericAttribute pointYAttrFn;
aPositionY = pointYAttrFn.create("positionY", "py", MFnNumericData::kDouble, 0.0);
CHECK_MSTATUS ( pointYAttrFn.setStorable(false) );
CHECK_MSTATUS ( pointYAttrFn.setKeyable(false) );
CHECK_MSTATUS ( pointYAttrFn.setReadable(true) );
CHECK_MSTATUS ( pointYAttrFn.setWritable(false) );
CHECK_MSTATUS ( addAttribute(aPositionY) );
MFnNumericAttribute pointZAttrFn;
aPositionZ = pointZAttrFn.create("positionZ", "pz", MFnNumericData::kDouble, 0.0);
CHECK_MSTATUS ( pointZAttrFn.setStorable(false) );
CHECK_MSTATUS ( pointZAttrFn.setKeyable(false) );
CHECK_MSTATUS ( pointZAttrFn.setReadable(true) );
CHECK_MSTATUS ( pointZAttrFn.setWritable(false) );
CHECK_MSTATUS ( addAttribute(aPositionZ) );
MFnNumericAttribute pointAttrFn;
aPosition = pointAttrFn.create("position", "p", aPositionX, aPositionY, aPositionZ);
CHECK_MSTATUS ( pointAttrFn.setStorable(false) );
CHECK_MSTATUS ( pointAttrFn.setKeyable(false) );
CHECK_MSTATUS ( pointAttrFn.setReadable(true) );
CHECK_MSTATUS ( pointAttrFn.setWritable(false) );
CHECK_MSTATUS ( addAttribute(aPosition) );
MFnNumericAttribute normalXAttrFn;
aNormalX = normalXAttrFn.create("normalX", "nx", MFnNumericData::kDouble, 0.0);
CHECK_MSTATUS ( normalXAttrFn.setStorable(false) );
CHECK_MSTATUS ( normalXAttrFn.setKeyable(false) );
CHECK_MSTATUS ( normalXAttrFn.setReadable(true) );
CHECK_MSTATUS ( normalXAttrFn.setWritable(false) );
CHECK_MSTATUS ( addAttribute(aNormalX) );
MFnNumericAttribute normalYAttrFn;
aNormalY = normalYAttrFn.create("normalY", "ny", MFnNumericData::kDouble, 0.0);
CHECK_MSTATUS ( normalYAttrFn.setStorable(false) );
CHECK_MSTATUS ( normalYAttrFn.setKeyable(false) );
CHECK_MSTATUS ( normalYAttrFn.setReadable(true) );
CHECK_MSTATUS ( normalYAttrFn.setWritable(false) );
CHECK_MSTATUS (addAttribute(aNormalY));
MFnNumericAttribute normalZAttrFn;
aNormalZ = normalZAttrFn.create("normalZ", "nz", MFnNumericData::kDouble, 0.0);
CHECK_MSTATUS ( normalZAttrFn.setStorable(false));
CHECK_MSTATUS ( normalZAttrFn.setKeyable(false));
CHECK_MSTATUS ( normalZAttrFn.setReadable(true));
CHECK_MSTATUS ( normalZAttrFn.setWritable(false));
CHECK_MSTATUS ( addAttribute(aNormalZ));
MFnNumericAttribute normalAttrFn;
aNormal = normalAttrFn.create("normal", "n", aNormalX, aNormalY, aNormalZ);
CHECK_MSTATUS ( normalAttrFn.setStorable(false));
CHECK_MSTATUS ( normalAttrFn.setKeyable(false));
CHECK_MSTATUS ( normalAttrFn.setReadable(true));
CHECK_MSTATUS ( normalAttrFn.setWritable(false));
CHECK_MSTATUS ( addAttribute(aNormal) );
CHECK_MSTATUS ( attributeAffects(aInMesh, aPosition));
CHECK_MSTATUS ( attributeAffects(aInMesh, aPositionX));
CHECK_MSTATUS ( attributeAffects(aInMesh, aPositionY));
CHECK_MSTATUS ( attributeAffects(aInMesh, aPositionZ));
CHECK_MSTATUS ( attributeAffects(aInMesh, aNormal));
CHECK_MSTATUS ( attributeAffects(aInMesh, aNormalX));
CHECK_MSTATUS ( attributeAffects(aInMesh, aNormalY));
CHECK_MSTATUS ( attributeAffects(aInMesh, aNormalZ));
CHECK_MSTATUS ( attributeAffects(aFaceIndex, aPosition));
CHECK_MSTATUS ( attributeAffects(aFaceIndex, aPositionX));
CHECK_MSTATUS ( attributeAffects(aFaceIndex, aPositionY));
CHECK_MSTATUS ( attributeAffects(aFaceIndex, aPositionZ));
CHECK_MSTATUS ( attributeAffects(aFaceIndex, aNormal));
CHECK_MSTATUS ( attributeAffects(aFaceIndex, aNormalX));
CHECK_MSTATUS (attributeAffects(aFaceIndex, aNormalY));
CHECK_MSTATUS ( attributeAffects(aFaceIndex, aNormalZ));
CHECK_MSTATUS ( attributeAffects(aRelative, aPosition));
CHECK_MSTATUS ( attributeAffects(aRelative, aPositionX));
CHECK_MSTATUS ( attributeAffects(aRelative, aPositionY));
CHECK_MSTATUS (attributeAffects(aRelative, aPositionZ));
CHECK_MSTATUS ( attributeAffects(aRelative, aNormal));
CHECK_MSTATUS ( attributeAffects(aRelative, aNormalX));
CHECK_MSTATUS ( attributeAffects(aRelative, aNormalY));
CHECK_MSTATUS ( attributeAffects(aRelative, aNormalZ));
CHECK_MSTATUS ( attributeAffects(aParameterU, aPosition));
CHECK_MSTATUS ( attributeAffects(aParameterU, aPositionX));
CHECK_MSTATUS ( attributeAffects(aParameterU, aPositionY));
CHECK_MSTATUS ( attributeAffects(aParameterU, aPositionZ));
CHECK_MSTATUS ( attributeAffects(aParameterU, aNormal));
CHECK_MSTATUS ( attributeAffects(aParameterU, aNormalX));
CHECK_MSTATUS ( attributeAffects(aParameterU, aNormalY));
CHECK_MSTATUS ( attributeAffects(aParameterU, aNormalZ));
CHECK_MSTATUS ( attributeAffects(aParameterV, aPosition));
CHECK_MSTATUS ( attributeAffects(aParameterV, aPositionX));
CHECK_MSTATUS ( attributeAffects(aParameterV, aPositionY));
CHECK_MSTATUS ( attributeAffects(aParameterV, aPositionZ));
CHECK_MSTATUS ( attributeAffects(aParameterV, aNormal));
CHECK_MSTATUS ( attributeAffects(aParameterV, aNormalX));
CHECK_MSTATUS ( attributeAffects(aParameterV, aNormalY));
CHECK_MSTATUS ( attributeAffects(aParameterV, aNormalZ));
return MS::kSuccess;
}
MStatus pointOnMeshInfoNode::compute(const MPlug &plug, MDataBlock &data)
{
if ((plug == aPosition) || (plug == aPositionX) || (plug == aPositionY) || (plug == aPositionZ)
|| (plug == aNormal) || (plug == aNormalX) || (plug == aNormalY) || (plug == aNormalZ))
{
MDataHandle inMeshDataHandle = data.inputValue(aInMesh);
MObject inMesh = inMeshDataHandle.asMesh();
MDataHandle faceIndexDataHandle = data.inputValue(aFaceIndex);
int faceIndex = faceIndexDataHandle.asLong();
MDataHandle relativeDataHandle = data.inputValue(aRelative);
bool relative = relativeDataHandle.asBool();
MDataHandle parameterUDataHandle = data.inputValue(aParameterU);
double parameterU = parameterUDataHandle.asDouble();
MDataHandle parameterVDataHandle = data.inputValue(aParameterV);
double parameterV = parameterVDataHandle.asDouble();
MPoint point;
MVector normal;
MDagPath dummyDagPath;
getPointAndNormal(dummyDagPath, faceIndex, relative, parameterU, parameterV, point, normal, inMesh);
MDataHandle pointDataHandle = data.outputValue(aPosition);
pointDataHandle.set(point.x, point.y, point.z);
data.setClean(plug);
MDataHandle normalDataHandle = data.outputValue(aNormal);
normalDataHandle.set(normal.x, normal.y, normal.z);
data.setClean(plug);
}
else
return MS::kUnknownParameter;
return MS::kSuccess;
}