#include "particleAttrNode.h"
#include <maya/MStatus.h>
#include <maya/MObject.h>
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>
#include <maya/MPlug.h>
#include <maya/MVector.h>
#include <maya/MDoubleArray.h>
#include <maya/MVectorArray.h>
#include <maya/MPlugArray.h>
#include <maya/MPointArray.h>
#include <maya/MFnDoubleArrayData.h>
#include <maya/MFnVectorArrayData.h>
#include <maya/MFnMesh.h>
#include <maya/MFnTypedAttribute.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MDynamicsUtil.h>
MTypeId particleAttrNode::id = 0x81036;
MObject particleAttrNode::outPositionPP;
MObject particleAttrNode::particleCount;
particleAttrNode::particleAttrNode()
{}
particleAttrNode::~particleAttrNode()
{}
void* particleAttrNode::creator()
{
return new particleAttrNode();
}
MStatus particleAttrNode::initialize()
{
vectArrayDataFn.
create( defaultVectArray );
typedAttrFn.
create(
"outPosition",
"opos",
&status );
outPositionPP = typedAttrFn.
object();
addAttribute( outPositionPP );
particleCount = numAttrFn.
object();
addAttribute( particleCount );
attributeAffects( computeNode, outPositionPP );
attributeAffects( particleCount, outPositionPP );
return status;
}
{
MStatus status = MS::kUnknownParameter;
{
status = compute2DTexture( plug, block );
}
{
status = computeMesh( plug, block );
}
return status;
}
{
bool doUcoord = false;
bool doVcoord = false;
bool doOutColor = ( plug.
attribute() == outColorPP );
bool doOutValue = ( plug.
attribute() == outValuePP );
status = dataDoubleArrayFn.
setObject( uCoordD );
if( status == MS::kSuccess )
{
uAry = dataDoubleArrayFn.
array();
{
doUcoord = true;
}
}
status = MS::kSuccess;
status = dataDoubleArrayFn.
setObject( vCoordD );
if( status == MS::kSuccess )
{
vAry = dataDoubleArrayFn.
array();
{
doVcoord = true;
}
}
status = MS::kSuccess;
if( doOutColor )
{
status = dataVectorArrayFn.
setObject( colorD );
if( status == MS::kSuccess )
{
outColorAry = dataVectorArrayFn.
array();
}
}
status = MS::kSuccess;
if( doOutValue )
{
status = dataDoubleArrayFn.
setObject( valueD );
if( status == MS::kSuccess )
{
outValueAry = dataDoubleArrayFn.
array();
}
}
unsigned int uCount = ( doUcoord ? uAry.
length() : 0 );
unsigned int vCount = ( doVcoord ? vAry.
length() : 0 );
unsigned int count = ( (uCount) > (vCount) ? (uCount) : (vCount) );
if( doOutColor ) outColorAry.
setLength( count );
if( doOutValue ) outValueAry.
setLength( count );
bool hasTextureNode =
computeNode );
if( hasTextureNode )
{
computeNode,
uAry,
vAry,
&outColorAry,
&outValueAry );
if( (minValue != 0.0) || (maxValue != 1.0) )
{
double r = maxValue - minValue;
if( doOutValue )
{
for( unsigned int i = 0; i < count; i++ )
{
outValueAry[i] = (r * outValueAry[i]) + minValue;
}
}
if( doOutColor )
{
MVector minVector( minValue, minValue, minValue );
for( unsigned int i = 0; i < count; i++ )
{
outColorAry[i] = (r * outColorAry[i]) + minVector;
}
}
}
}
else
{
for( unsigned int i = 0; i < count; i++ )
{
if( doOutColor )
{
outColorAry[i] = clr;
}
if( doOutValue )
{
outValueAry[i] = clr.x;
}
}
}
dataVectorArrayFn.
set( outColorAry );
dataDoubleArrayFn.
set( outValueAry );
return MS::kSuccess;
}
{
MPlug compPlug( thisMObject(), computeNode );
compPlug.connectedTo( conns, true, false, &status );
{
return MS::kFailure;
}
MFnMesh meshFn( compNode, &status );
if( status != MS::kSuccess )
{
return MS::kFailure;
}
meshFn.getPoints( points );
unsigned int nPoints = points.
length();
unsigned int nParticles = 0;
if( nSignedPart > 0 )
{
nParticles = nSignedPart;
}
status = dataVectorArrayFn.
setObject( posD );
if( status == MS::kSuccess )
{
outPosArray = dataVectorArrayFn.
array();
}
for( unsigned int i = 0; i < nParticles; i++ )
{
unsigned int index = i;
if( nParticles > nPoints )
{
index = i % nPoints;
}
outPosArray[i] = pos;
}
dataVectorArrayFn.
set( outPosArray );
return MS::kSuccess;
}