#include <math.h>
#include <maya/MIOStream.h>
#include <maya/MPxCommand.h>
#include <maya/MStatus.h>
#include <maya/MObject.h>
#include <maya/MFnPlugin.h>
#include <maya/MString.h>
#include <maya/MArgList.h>
#include <maya/MGlobal.h>
#include <maya/MPoint.h>
#include <maya/MVector.h>
#include <maya/MMatrix.h>
#include <maya/MDagPath.h>
#include <maya/MSelectionList.h>
#include <maya/MItSelectionList.h>
#include <maya/MItSurfaceCV.h>
#include <maya/MItMeshVertex.h>
public:
surfaceTwist();
~surfaceTwist() override;
static void* creator();
};
#define NUM_SPANS 30
#define WIDTH 10.0
#define VERTICAL_SCALING 4.0
surfaceTwist::~surfaceTwist() {}
surfaceTwist::surfaceTwist() {}
void* surfaceTwist::creator()
{
return new surfaceTwist;
}
{
MVector toCenter( -center.
x, 0.0, -center.
y );
double rotFactor = 0.5;
MItSurfaceCV cvIter( objectPath, component,
true, &status );
if ( MS::kSuccess == status ) {
for ( ; !cvIter.isDone(); cvIter.nextRow() ) {
for ( ; !cvIter.isRowDone(); cvIter.next() ) {
pnt = pnt + toCenter;
double rotation = pnt.
y * rotFactor;
rotMatrix(0,0) = cos( rotation );
rotMatrix(0,2) = sin( rotation );
rotMatrix(2,0) = -sin( rotation );
rotMatrix(2,2) = cos( rotation );
pnt = ( pnt * rotMatrix ) - toCenter;
if ( MS::kSuccess != status )
break;
}
}
cvIter.updateSurface();
return MS::kSuccess;
} else
return MS::kFailure;
}
{
MVector toCenter( -center.
x, 0.0, -center.
y );
double rotFactor = 0.5;
if ( MS::kSuccess == status ) {
for ( ; !vertIter.isDone(); vertIter.next() ) {
pnt = pnt + toCenter;
double rotation = pnt.
y * rotFactor;
rotMatrix(0,0) = cos( rotation );
rotMatrix(0,2) = sin( rotation );
rotMatrix(2,0) = -sin( rotation );
rotMatrix(2,2) = cos( rotation );
pnt = ( pnt * rotMatrix ) - toCenter;
if ( MS::kSuccess != status )
break;
}
vertIter.updateSurface();
return MS::kSuccess;
} else
return MS::kFailure;
}
{
if (iter.isDone()) {
cerr << "Nothing selected\n";
return MS::kFailure;
}
for ( ; !iter.isDone(); iter.next() ) {
status = iter.getDagPath( objectPath, component );
status = twistNurbsSurface(objectPath, component);
status = twistPolygon(objectPath, component);
else {
cerr << "Selected object is not a NURBS surface or a polygon\n";
return MS::kFailure;
}
}
return status;
}
{
MFnPlugin plugin( obj, PLUGIN_COMPANY,
"3.0",
"Any");
status = plugin.registerCommand( "surfaceTwist", surfaceTwist::creator );
if (!status) {
status.
perror(
"registerCommand");
return status;
}
return status;
}
{
status = plugin.deregisterCommand( "surfaceTwist" );
if (!status) {
status.
perror(
"deregisterCommand");
return status;
}
return status;
}