#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;
}
{
{
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 );
{
uAry = dataDoubleArrayFn.
array();
{
doUcoord = true;
}
}
status = dataDoubleArrayFn.
setObject( vCoordD );
{
vAry = dataDoubleArrayFn.
array();
{
doVcoord = true;
}
}
if( doOutColor )
{
status = dataVectorArrayFn.
setObject( colorD );
{
outColorAry = dataVectorArrayFn.
array();
}
}
if( doOutValue )
{
status = dataDoubleArrayFn.
setObject( valueD );
{
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 );
}
{
MPlug compPlug( thisMObject(), computeNode );
compPlug.connectedTo( conns, true, false, &status );
{
}
MFnMesh meshFn( compNode, &status );
{
}
meshFn.getPoints( points );
unsigned int nPoints = points.
length();
unsigned int nParticles = 0;
if( nSignedPart > 0 )
{
nParticles = nSignedPart;
}
status = dataVectorArrayFn.
setObject( posD );
{
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 );
}