#include <maya/MIOStream.h>
#include <stdio.h>
#include <stdlib.h>
#include <maya/MPxCommand.h>
#include <maya/MFnPlugin.h>
#include <maya/MArgList.h>
#include <maya/MGlobal.h>
#include <maya/M3dView.h>
#include <maya/MDagPath.h>
#include <maya/MMatrix.h>
#include <maya/MFloatMatrix.h>
#include <maya/MRenderUtil.h>
#include <maya/MFloatPoint.h>
#include <maya/MFloatPointArray.h>
#include <maya/MFloatArray.h>
#include <maya/MFloatVectorArray.h>
#include <math.h>
#ifndef M_PI
#define M_PI        3.14159265358979323846  
#endif
{
public:
                    sampleParticles() {};
    virtual         ~sampleParticles(); 
    static void*    creator();
};
sampleParticles::~sampleParticles() {}
void* sampleParticles::creator()
{
    return new sampleParticles();
}
{
    unsigned int i;
    bool shadow = 0;
    bool reuse = 0;
    for ( i = 0; i < args.
length(); i++ )
 
            shadow = 1;
            reuse = 1;
        else
            break;
    {
        displayError( "Usage: sampleParticles [-shadow|-reuse] particleName <shadingEngine|shadingNode.plug> resX resY scale\n"
            "  Example: sampleParticles -shadow particle1 phong1SG 64 64 10;\n"
            "  Example: sampleParticles particle1 file1.outColor 128 128 5;\n" );
    }
    if ( reuse && !shadow ) 
        reuse = 0;
    int resX = args.
asInt( i+2 );
 
    int resY = args.
asInt( i+3 );
 
    if ( scale <= 0.0 )
        scale = 1.0;
    if ( resX <= 0 )
        resX = 1;
    if ( resY <= 0 )
        resY = 1;
    command += particleName;
    char tmp[2048];
    float stepU = (float) (1.0 / resX);
    float stepV = (float) (1.0 / resY);
    
    
    int x, y;
    for ( y = 0; y < resY; y++ )
        for ( x = 0; x < resX; x++ )
        {
            float curY = (float) (sin( stepU * (x) * M_PI )*2.0);
                (float) (stepU * x * scale),
                curY,
                (float) (stepV * y * scale ));
                (float) (stepU * (x+1) * scale),
                (float) (sin( stepU * (x+1) * M_PI )*2.0),
                (float) (stepV * y * scale ));
                (float) (stepU * (x) * scale),
                curY,
                (float) (stepV * (y+1) * scale ));
            du = uPt-curPt;
            dv = vPt-curPt;
            n = dv^du;  
            du.normal();
        }
    
            node, 
            shadow,
            reuse,
            cameraMat,
            &points,
            &uCoord,
            &vCoord,
            &normals,
            &points,
            &tanUs,
            &tanVs,
            NULL,   
            colors,
            transps ) )
    {
        fprintf( stderr, "%u points sampled...\n", points.length() );
        for ( i = 0; i < uCoord.length(); i++ )
        {
            sprintf( tmp, " -pos %g %g %g -at velocity -vv %g %g %g -at rgbPP -vv %g %g %g",
                points[i].x,
                points[i].y,
                points[i].z,
                normals[i].x,
                normals[i].y,
                normals[i].z,
                colors[i].x,
                colors[i].y,
                colors[i].z );
            
            if ( i % 512 == 0 )
            {
                fprintf( stderr, "%u...\n", i );
                command += particleName;
            }
        }
        if ( i % 512 )
    }
    else
    {
        displayError( node + 
MString(
" is not a shading engine!  Specify node.attr or shading group node." ) );
    }
}
{
    MFnPlugin plugin( obj, PLUGIN_COMPANY, 
"3.0", 
"Any");
 
    status = plugin.registerCommand( "sampleParticles", sampleParticles::creator );
    if (!status) {
        status.
perror(
"registerCommand");
        return status;
    }
    return status;
}
{
    status = plugin.deregisterCommand( "sampleParticles" );
    if (!status) {
        status.
perror(
"deregisterCommand");
        return status;
    }
    return status;
}