#include <maya/MIOStream.h>
#include <math.h>
#include <maya/MFnPlugin.h>
#include <maya/MFnNurbsCurve.h>
#include <maya/MPointArray.h>
#include <maya/MDoubleArray.h>
#include <maya/MPoint.h>
#include <maya/MSelectionList.h>
#include <maya/MItSelectionList.h>
#include <maya/MItCurveCV.h>
#include <maya/MGlobal.h>
#include <maya/MDagPath.h>
#include <maya/MString.h>
#include <maya/MPxCommand.h>
#include <maya/MArgList.h>
{
public:
helix2();
~helix2() override;
static void* creator();
private:
double radius;
double pitch;
};
{
for (
unsigned i = 0; i < args.
length(); i++ ) {
&& MS::kSuccess == status)
{
double tmp = args.
asDouble( ++i, &status );
if ( MS::kSuccess == status )
pitch = tmp;
}
&& MS::kSuccess == status)
{
double tmp = args.
asDouble( ++i, &status );
if ( MS::kSuccess == status )
radius = tmp;
} else {
displayError( msg );
return MS::kFailure;
}
}
if (MS::kSuccess != status) {
cerr << "doIt: could not create selection list iterator\n";
return status;
}
if (list.isDone()) {
cerr << "doIt: no curve has been selected\n";
return MS::kFailure;
}
list.getDagPath( fDagPath, fComponent );
return redoIt();
}
{
unsigned i, numCVs;
numCVs = curveFn.numCVs();
status = curveFn.getCVs( fCVs );
if ( MS::kSuccess != status )
{
cerr << "redoIt: could not get cvs status: " << status << endl;
return MS::kFailure;
}
for (i = 0; i < numCVs; i++)
points[i] =
MPoint( radius * cos( (
double)i ),
pitch * (double)i,
radius * sin( (double)i ) );
status = curveFn.setCVs( points );
if ( MS::kSuccess != status )
{
cerr << "redoIt: could not setCVs status: " << status << endl;
return status;
}
status = curveFn.updateCurve();
if ( MS::kSuccess != status )
{
cerr << "redoIt: updateCurve() failed status: " << status << endl;
return status;
}
return MS::kSuccess;
}
{
status = curveFn.setCVs( fCVs );
if ( MS::kSuccess != status)
{
cerr << "undoIt: array length is " << fCVs.length()
<< "bad status: " << status << endl;
return status;
}
status = curveFn.updateCurve();
if ( MS::kSuccess != status )
{
cerr << "undoIt: updateCurve() failed status: " << status << endl;
return status;
}
return MS::kSuccess;
}
void* helix2::creator()
{
return new helix2();
}
helix2::helix2()
: radius( 4.0 ),
pitch( 0.5 ),
fComponent()
{}
helix2::~helix2()
{
fCVs.clear();
}
bool helix2::isUndoable() const
{
return true;
}
{
MFnPlugin plugin( obj, PLUGIN_COMPANY,
"3.0",
"Any");
status = plugin.registerCommand( "helix2", helix2::creator );
if (!status) {
status.
perror(
"registerCommand");
return status;
}
return status;
}
{
status = plugin.deregisterCommand( "helix2" );
if (!status) {
status.
perror(
"deregisterCommand");
return status;
}
return status;
}