#include <maya/MSimple.h>
#include <maya/MSelectionList.h>
#include <maya/MGlobal.h>
#include <maya/MItSelectionList.h>
#include <maya/MString.h>
#include <maya/MFnInstancer.h>
#include <maya/MItInstancer.h>
#include <maya/MDagPathArray.h>
#include <maya/MPoint.h>
#include <maya/MMatrixArray.h>
void printInstancerUsingFunctionSet(
const MDagPath& instancerPath )
{
char str[256];
sprintf( str,
"Instancer %s:", pathName.
asChar() );
int numParticles = fnInst.particleCount();
sprintf( str, " num particles = %d", numParticles );
int p = 0;
for( p = 0; p < numParticles; p++ )
{
int numInstances = fnInst.instancesForParticle( p, particlePaths, particleMatrix );
for( int i = 0; i < numInstances; i++ )
{
const MDagPath& instancedPath = particlePaths[i];
MMatrix finalMatrixForPath = instancedPathMatrix * particleMatrix;
sprintf( str,
" Path %-50s at position (%lf,%lf,%lf)", instancedPathName.
asChar(), finalPoint.
x, finalPoint.
y, finalPoint.
z );
}
}
fnInst.allInstances( allPaths, allMatrices, pathStartIndices, pathIndices );
for( p = 0; p < numParticles; p++ )
{
MMatrix particleMatrix = allMatrices[p];
int numPaths = pathStartIndices[p+1]-pathStartIndices[p];
int pathStart = pathStartIndices[p];
for( int i = pathStart; i < pathStart+numPaths; i++ )
{
int curPathIndex = pathIndices[i];
const MDagPath& curPath = allPaths[curPathIndex];
MMatrix finalMatrixForPath = instancedPathMatrix * particleMatrix;
sprintf( str,
" Path %-50s at position (%lf,%lf,%lf)", instancedPathName.
asChar(), finalPoint.
x, finalPoint.
y, finalPoint.
z );
}
}
}
void printAllInstancesUsingIterator()
{
{
MMatrix finalMatrixForPath = pathMatrix * instanceMatrix;
char str[512];
sprintf( str, "Instancer node %s, instancer path %s, instancing path %s at position (%lf,%lf,%lf)",
instancerNodeName.
asChar(), instancerPathName.
asChar(), instancePathName.
asChar(), pos.
x, pos.
y, pos.
z );
}
}
{
{
printAllInstancesUsingIterator();
}
else
{
{
if( it.getDagPath( instancerPath ) == MS::kSuccess )
{
printInstancerUsingFunctionSet( instancerPath );
}
else
{
return MS::kFailure;
}
}
}
return MS::kSuccess;
}