#include <math.h>
#include <maya/MIOStream.h>
#include <maya/MArgList.h>
#include <maya/MPxCommand.h>
#include <maya/MGlobal.h>
#include <maya/MSelectionList.h>
#include <maya/MPoint.h>
#include <maya/MNurbsIntersector.h>
#include <maya/MDagPath.h>
#include <maya/MMatrix.h>
#include <maya/MFnDagNode.h>
#include <maya/MFnTransform.h>
#include <maya/MVector.h>
#include <maya/MFnPlugin.h>
#include <maya/MFnNurbsSurface.h>
#include "intersectOnNurbsSurfaceCmd.h"
intersectOnNurbsSurfaceCmd::intersectOnNurbsSurfaceCmd()
{
}
intersectOnNurbsSurfaceCmd::~intersectOnNurbsSurfaceCmd()
{
}
void* intersectOnNurbsSurfaceCmd::creator()
{
return new intersectOnNurbsSurfaceCmd;
}
bool intersectOnNurbsSurfaceCmd::isUndoable() const
{
return false;
}
{
bool debug = false;
bool treeBased = true;
if(debug) cout << "intersectOnNurbsSurfaceCmd::doIt\n";
if(!stat) {
if(debug) cout << "getActiveSelectionList FAILED\n";
return( stat );
}
if(!stat)
if(debug) cout << "getDependNode FAILED\n";
if(nodeFn.childCount() > 0) {
nodeFn.setObject(child);
}
if(debug) cout << mat << endl;
if(!stat) {
if(debug) cout << "FAILED grabbing locator1\n";
return( stat );
}
if(!stat) {
if(debug) cout << "FAILED grabbing locator2\n";
return( stat );
}
if(debug) cout << "test point: " << pt << endl;
if(debug) cout << "transformed:" << pt * mat << endl;
double u=0, v=0;
if ( treeBased ) {
if(debug) cout << "tree-based NURBS intersect (MNurbsIntersector)\n";
stat = nurbIntersect.
create(nurbsObject, mat);
if(!stat) {
if(debug) cout << "MNurbsIntersector::create FAILED\n";
return( stat );
}
stat = nurbIntersect.
getIntersect(pt, ray, u, v, resultPoint, kMFnNurbsEpsilon);
if(!stat) {
if(debug) cout << "MNurbsIntersector::getIntersect FAILED!\n";
return( stat );
}
} else {
pt *= mat;
bool result = ns.intersect(pt, ray, u, v, resultPoint, kMFnNurbsEpsilon,
MSpace::kObject,
false, NULL,
false, NULL, &stat );
if(!result || !stat) {
if(debug) cout << "MFnNurbsSurface::intersect FAILED!\n";
if(stat) {
}
return( stat );
}
}
if(debug) cout << "result UV: " << u << ", " << v << endl;
MString cmd =
"pointOnSurface -u ";
cmd += u;
cmd += " -v ";
cmd += v;
cmd += " ";
if(debug) cout << "check results: result UV corresponds to world point: " << arr << endl;
if(debug) cout << "local space result point: " << resultPoint << endl;
if(debug) cout << "world space result point: " << worldResultPoint << endl;
if ( fabs( arr[0] - worldResultPoint.
x ) > 0.0001
|| fabs( arr[1] - worldResultPoint.
y ) > 0.0001
|| fabs( arr[2] - worldResultPoint.
z ) > 0.0001 ) {
cout << "check results: pointOnSurface does not match world point: " << arr << endl;
return( MS::kFailure );
}
return stat;
}
MStatus intersectOnNurbsSurfaceCmd::undoIt()
{
return status;
}
{
MFnPlugin plugin( obj, PLUGIN_COMPANY,
"8.5",
"Any");
status = plugin.registerCommand( "intersectOnNurbsSurface",
intersectOnNurbsSurfaceCmd::creator );
if (!status) {
status.
perror(
"registerCommand");
return status;
}
return status;
}
{
status = plugin.deregisterCommand( "intersectOnNurbsSurface" );
if (!status) {
status.
perror(
"deregisterCommand");
return status;
}
return status;
}