#include <assert.h>
#include <maya/MIOStream.h>
#include <maya/MGlobal.h>
#include <maya/MString.h>
#include <maya/MPoint.h>
#include <maya/MVector.h>
#include <maya/MPointArray.h>
#include <maya/MVectorArray.h>
#include <maya/MFloatMatrix.h>
#include <maya/MArgList.h>
#include <maya/MPlug.h>
#include <maya/MFnDependencyNode.h>
#include <maya/MDagPath.h>
#include <maya/MItDag.h>
#include <maya/MSelectionList.h>
#include <maya/MPlug.h>
#include <maya/MPlugArray.h>
#include <maya/MPxCommand.h>
#include <maya/MFnDagNode.h>
#include <maya/MFnParticleSystem.h>
#include <maya/MFnPlugin.h>
#include <maya/MObjectArray.h>
#define mCommandName "particleSystemInfo" // Command name
#define CHECKRESULT(stat,msg) \
if ( MS::kSuccess != stat ) { \
cerr << msg << endl; \
}
{
public:
particleSystemInfoCmd();
virtual ~particleSystemInfoCmd();
static void* creator();
private:
};
particleSystemInfoCmd::particleSystemInfoCmd()
{
}
particleSystemInfoCmd::~particleSystemInfoCmd()
{
}
{
{
}
}
{
{
}
{
CHECKRESULT(stat, "Failed to parse particle node name argument." );
nodeFromName( particleName, particleNode );
{
}
}
}
{
if( particleNode.isNull() ) {
particleNode = dummy.
create(&stat);
CHECKRESULT(stat,"MFnParticleSystem::create(status) failed!");
CHECKRESULT(stat,"MFnParticleSystem::MFnParticleSystem(MObject,status) failed!");
stat = ps.emit(posArray, velArray);
CHECKRESULT(stat,"MFnParticleSystem::emit(posArray,velArray) failed!");
stat = ps.emit(
MPoint(5, 5, 0));
CHECKRESULT(stat,"MFnParticleSystem::emit(pos) failed!");
stat = ps.emit(
MPoint(5, 10, 0));
CHECKRESULT(stat,"MFnParticleSystem::emit(pos) failed!");
stat = ps.saveInitialState();
CHECKRESULT(stat,"MFnParticleSystem::saveInitialState() failed!");
for(
unsigned int i=0; i<accArray.
length(); i++ )
{
acc.
x = acc.
y = acc.
z = 3.0;
}
ps.setPerParticleAttribute( accName, accArray, &stat );
CHECKRESULT(stat,"MFnParticleSystem::setPerParticleAttribute(vectorArray) failed!");
}
CHECKRESULT(stat,"MFnParticleSystem::MFnParticleSystem(MObject,status) failed!");
if( ! ps.isValid() )
{
}
const MString name = ps.particleName();
const unsigned int count = ps.count();
const char* typeString = NULL;
switch( psType )
{
typeString = "Cloud";
break;
typeString = "Tube system";
break;
typeString = "Blobby";
break;
typeString = "MultiPoint";
break;
typeString = "MultiStreak";
break;
typeString = "Numeric";
break;
typeString = "Points";
break;
typeString = "Spheres";
break;
typeString = "Sprites";
break;
typeString = "Streak";
break;
default:
typeString = "Particle system";
assert( false );
break;
}
char buffer[256];
sprintf( buffer,
"%s \"%s\" has %u primitives.", typeString, name.
asChar(), count );
unsigned i;
ps.particleIds( ids );
sprintf( buffer, "count : %u ", count );
sprintf( buffer,
"%u ids.", ids.
length() );
assert( ids.
length() == count );
for( i=0; i<ids.
length(); i++ )
{
sprintf( buffer, "id %d ", ids[i] );
}
ps.position( positions );
assert( positions.
length() == count );
for( i=0; i<positions.
length(); i++ )
{
sprintf( buffer, "pos %f %f %f ", p[0], p[1], p[2] );
}
ps.velocity( vels );
assert( vels.
length() == count );
for( i=0; i<vels.
length(); i++ )
{
sprintf( buffer, "vel %f %f %f ", v[0], v[1], v[2] );
}
ps.acceleration( accs );
assert( accs.
length() == count );
for( i=0; i<accs.
length(); i++ )
{
sprintf( buffer, "acc %f %f %f ", a[0], a[1], a[2] );
}
bool flag = ps.isDeformedParticleShape(&stat);
CHECKRESULT(stat,"MFnParticleSystem::isDeformedParticleShape() failed!");
if( flag ) {
MObject obj = ps.originalParticleShape(&stat);
CHECKRESULT(stat,"MFnParticleSystem::originalParticleShape() failed!");
sprintf( buffer, "original particle shape : %s ", ps.particleName().asChar() );
}
}
flag = ps.isDeformedParticleShape(&stat);
CHECKRESULT(stat,"MFnParticleSystem::isDeformedParticleShape() failed!");
if( !flag ) {
MObject obj = ps.deformedParticleShape(&stat);
CHECKRESULT(stat,"MFnParticleSystem::deformedParticleShape() failed!");
sprintf( buffer, "deformed particle shape : %s ", ps.particleName().asChar() );
}
}
setResult(
int(ids.
length()) );
} else {
setResult( int(-1) );
}
}
void * particleSystemInfoCmd::creator() { return new particleSystemInfoCmd(); }
{
MFnPlugin plugin( obj, PLUGIN_COMPANY,
"4.5",
"Any");
MStatus status = plugin.registerCommand(mCommandName,
particleSystemInfoCmd::creator );
if (!status)
status.
perror(
"registerCommand");
return status;
}
{
MStatus status = plugin.deregisterCommand(mCommandName);
if (!status)
status.
perror(
"deregisterCommand");
return status;
}