Você está na página 1de 3

//-

// ==========================================================================
// Domingos, 11/06/2010
// dmzksh@gmail.com
// visual3dtools.blogspot.com
//
// ==========================================================================

#include <maya/MIOStream.h>
#include <math.h>

#include <maya/MFnPlugin.h>
#include <maya/MPoint.h>
#include <maya/MPointArray.h>
#include <maya/MDoubleArray.h>
#include <maya/MVector.h>
#include <maya/MVectorArray.h>
#include <maya/MMatrix.h>
#include <maya/MGlobal.h>
#include <maya/MString.h>
#include <maya/MStringArray.h>
#include <maya/MItMeshVertex.h>
#include <maya/MAngle.h>
#include <maya/MPxCommand.h>
#include <maya/MArgList.h>
#include <maya/MDagPath.h>
#include <maya/MSelectionList.h>
#include <maya/MItSelectionList.h>
#include <maya/MCommandResult.h>

class wavePlane : public MPxCommand


{

public:
wavePlane();
virtual ~wavePlane();

MStatus doIt( const MArgList& );

static void* creator();


};

//---------------------

void* wavePlane::creator()
{
return new wavePlane();
}

wavePlane::wavePlane(){}

wavePlane::~wavePlane(){}

//-------------------------
MStatus wavePlane::doIt( const MArgList& args )
{
MMatrix JacobMat;

MStatus stat;

MSelectionList selList;
MDagPath dagPath;
MObject geo;
MPoint vertex;

//get first object selected


MGlobal::getActiveSelectionList( selList );
stat=selList.getDagPath(0,dagPath);

if ( dagPath.fullPathName()=="" ){
cout<<"No Geometry selected."<<endl;
return stat;
}

//print name of obj


cout<<"\n"<<dagPath.fullPathName()<<endl;

//referencing to the selected obj


MItMeshVertex poly(dagPath,geo);

double raiz, amp=0, u=2.0;

//iterate for each vertex and calcule new position


while(poly.isDone()==false){
vertex=poly.position(MSpace::kWorld);
cout<<"\n"<<vertex<<endl;

raiz=sqrt(vertex[0]*vertex[0]+vertex[2]*vertex[2]);
vertex[1] = vertex[1] + sin(u*raiz+amp);
cout<<vertex<<endl;
stat=poly.setPosition(vertex,MSpace::kWorld);
if ( !stat ) {
stat.perror("MItMeshVertex::MItMeshVertex");
break;
}
poly.next();
}

poly.updateSurface();

return stat;
}

//-------------------------------

MStatus initializePlugin( MObject obj )


{
MStatus status;
MFnPlugin plugin( obj, "Domingos Silva", "1.0", "2011");
status = plugin.registerCommand( "wave", wavePlane::creator );
if (!status) {
status.perror("registerCommand");
return status;
}

return status;
}

MStatus uninitializePlugin( MObject obj )


{
MStatus status;
MFnPlugin plugin( obj );

status = plugin.deregisterCommand( "wave" );


if (!status) {
status.perror("deregisterCommand");
return status;
}

return status;
}

Você também pode gostar