#include <math.h>
#include "dynExprField.h"
#include <maya/MIOStream.h>
#include <maya/MTime.h>
#include <maya/MFloatVector.h>
#include <maya/MVectorArray.h>
#include <maya/MDoubleArray.h>
#include <maya/MString.h>
#include <maya/MMatrix.h>
#include <maya/MArrayDataBuilder.h>
#include <maya/MFnDependencyNode.h>
#include <maya/MFnTypedAttribute.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MFnCompoundAttribute.h>
#include <maya/MFnUnitAttribute.h>
#include <maya/MFnVectorArrayData.h>
#include <maya/MFnDoubleArrayData.h>
#include <maya/MFnMatrixData.h>
#include <maya/MFnArrayAttrsData.h>
MTypeId dynExprField::id( 0x00107340 );
void *dynExprField::creator()
{
return new dynExprField;
}
{
status = addAttribute( mDirection );
attributeAffects(mDirection, mOutputForce);
}
{
if( !(plug == mOutputForce) )
McheckErr(status, "ERROR in plug.logicalIndex.\n");
McheckErr(status,"ERROR in hInputArray = block.outputArrayValue().\n");
McheckErr(status, "ERROR: hInputArray.jumpToElement failed.\n");
McheckErr(status, "ERROR in hCompond=hInputArray.inputValue\n");
McheckErr(status, "ERROR in fnPosition.array(), not find points.\n");
McheckErr(status,"ERROR in mhInputPPData = block.inputArrayValue().\n");
McheckErr(status, "ERROR: mhInputPPArray.jumpToElement failed.\n");
McheckErr(status, "ERROR in hInputPPData = mhInputPPData.inputValue\n");
McheckErr(status, "ERROR in hOwnerPPData = block.inputValue\n");
const MString magString(
"magnitude");
bool arrayExist;
arrayExist = inputPPArray.checkArrayExist(magString, doubleType, &status);
if(arrayExist) {
magnitudeArray = inputPPArray.getDoubleData(magString, &status);
}
arrayExist = ownerPPArray.checkArrayExist(magString, doubleType, &status);
if(arrayExist) {
magnitudeOwnerArray = ownerPPArray.getDoubleData(magString, &status);
}
const MString dirString(
"direction");
arrayExist = inputPPArray.checkArrayExist(dirString, vectorType, &status);
if(arrayExist) {
directionArray = inputPPArray.getVectorData(dirString, &status);
}
arrayExist = ownerPPArray.checkArrayExist(dirString, vectorType, &status);
if(arrayExist) {
directionOwnerArray = ownerPPArray.getVectorData(dirString, &status);
}
apply( block, points.
length(), magnitudeArray, magnitudeOwnerArray,
directionArray, directionOwnerArray, forceArray );
McheckErr(status, "ERROR in hOutArray = block.outputArrayValue.\n");
McheckErr(status, "ERROR in bOutArray = hOutArray.builder.\n");
McheckErr(status, "ERROR in hOut = bOutArray.addElement.\n");
MObject dOutputForce = fnOutputForce.
create( forceArray, &status );
McheckErr(status, "ERROR in dOutputForce = fnOutputForce.create\n");
hOut.
set( dOutputForce );
}
MStatus dynExprField::iconSizeAndOrigin(GLuint& width,
GLuint& height,
GLuint& xbo,
GLuint& ybo )
{
width = 32;
height = 32;
xbo = 4;
ybo = 4;
}
MStatus dynExprField::iconBitmap(GLubyte* bitmap)
{
bitmap[0] = 0x18;
bitmap[4] = 0x18;
bitmap[8] = 0x18;
bitmap[12] = 0x18;
bitmap[16] = 0x18;
bitmap[20] = 0x5A;
bitmap[24] = 0x3C;
bitmap[28] = 0x18;
}
{
MFnPlugin plugin(obj, PLUGIN_COMPANY,
"6.0",
"Any");
status = plugin.registerNode( "dynExprField",
dynExprField::id,
&dynExprField::creator,
&dynExprField::initialize,
if (!status) {
status.
perror(
"registerNode");
return status;
}
return status;
}
{
status = plugin.deregisterNode( dynExprField::id );
if (!status) {
status.
perror(
"deregisterNode");
return status;
}
return status;
}
double dynExprField::magnitude(
MDataBlock& block )
{
double value = 0.0;
return( value );
}
{
}
void dynExprField::apply(
int receptorSize,
)
{
MVector defaultDir = direction(block);
double defaultMag = magnitude(block);
int magArraySize = magnitudeArray.
length();
int dirArraySize = directionArray.
length();
int magOwnerArraySize = magnitudeOwnerArray.
length();
int dirOwnerArraySize = directionOwnerArray.
length();
int numOfOwner = magOwnerArraySize;
if( dirOwnerArraySize > numOfOwner )
numOfOwner = dirOwnerArraySize;
double magnitude = defaultMag;
for (int ptIndex = 0; ptIndex < receptorSize; ptIndex ++ ) {
if(receptorSize == magArraySize)
magnitude = magnitudeArray[ptIndex];
if(receptorSize == dirArraySize)
direction = directionArray[ptIndex];
if( numOfOwner > 0) {
for( int nthOwner = 0; nthOwner < numOfOwner; nthOwner++ ) {
if(magOwnerArraySize == numOfOwner)
magnitude = magnitudeOwnerArray[nthOwner];
if(dirOwnerArraySize == numOfOwner)
direction = directionOwnerArray[nthOwner];
outputForce.
append( direction * magnitude );
}
} else {
outputForce.
append( direction * magnitude );
}
}
}