#include <math.h>
#include <maya/MPxNode.h>
#include <maya/MIOStream.h>
#include <maya/MString.h>
#include <maya/MTypeId.h>
#include <maya/MPlug.h>
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MFloatVector.h>
#include <maya/MFnPlugin.h>
{
public:
VolumeNode();
~VolumeNode() override;
SchedulingType
schedulingType()
const override {
return SchedulingType::kParallel; }
static void * creator();
private:
};
MObject VolumeNode::aOutTransparency;
VolumeNode::VolumeNode()
{
}
VolumeNode::~VolumeNode()
{
}
void* VolumeNode::creator()
{
return new VolumeNode();
}
{
aToggleCamera = nAttr.
create(
"cameraSpace",
"cs",
aToggleObject = nAttr.
create(
"objectSpace",
"os",
aFarPointC = nAttr.
createPoint(
"farPointCamera",
"fc" );
aFarPointW = nAttr.
createPoint(
"farPointWorld",
"fw" );
aOutTransparency = nAttr.
createColor(
"outTransparency",
"ot" );
return MS::kSuccess;
}
{
if ((plug != aOutColor) && (plug.
parent() != aOutColor) &&
(plug != aOutTransparency) && (plug.
parent() != aOutTransparency))
return MS::kUnknownParameter;
if (Camera) {
interval = FarCamera - PointCam;
}
if (Object) {
interval = FarObject - PointObj;
}
if (World) {
interval = FarWorld - PointWor;
}
double value = (interval[0]*interval[0]) +
(interval[1]*interval[1]) +
(interval[2]*interval[2]);
double dist = sqrt ( value );
if (dist <= Distance) {
resultColor[0] = InputColor[0];
resultColor[1] = InputColor[1];
resultColor[2] = InputColor[2];
}
outColor = resultColor;
MFloatVector transparency(resultColor[2],resultColor[2],resultColor[2]);
outTrans = transparency;
float& outAlpha = outAlphaHandle.
asFloat();
outAlpha = resultColor[2];
return MS::kSuccess;
}
{
const MString UserClassify(
"shader/volume" );
MFnPlugin plugin( obj, PLUGIN_COMPANY,
"4.5",
"Any");
CHECK_MSTATUS( plugin.registerNode(
"volumeNode", VolumeNode::id,
VolumeNode::creator, VolumeNode::initialize,
return MS::kSuccess;
}
{
return MS::kSuccess;
}