Accessing Nurbs Curve Data [MEL]



 

 

NurbsCurves in maya are stored as MFn::kNurbsCurve nodes. In the hypergraph view above the transform is "curve1" and the curve shape is "curveShape1". As with all shapes in maya, the hyper-graph does not display a logical connection between the shape and the transform.

 

 

 

 

Finding all Nurbs Curves
in a Scene

When retrieving mesh data, you will need to use either MItDependencyNodes or MItDagNode in order to loop through a list of meshes.

It is worth querying isIntermediateObject() before exporting any mesh data, if the function returns true then the node will be part of the scenes history.

 

 

 


#include<maya/MItDag.h>
#include<maya/MFnNurbsCurve.h>

// create an iterator to go through all curves
MItDag it(MItDag::kDepthFirst,MFn::kNurbsCurve);

while(!it.isDone())
{
 

// attach the function set to the object
MFnNurbsCurve
fn(it.item());

// only want non-history items
if( !fn.isIntermediateObject() ) {

  // print curve name
cout
<<"Curve "<< fn.name().asChar() <<endl;

}

// get next curve
it.next();

}




 

Control Points

 

The control vertices are stored in a single array, you can retrieve that array either by using the getCVs method, or using an MITGeometry iterator.

 

 

 

 

 

 

 


#include<maya/MFnNurbsCurve.h>
#include<maya/MPointArray.h>

void outputCurvePoints(MObject& obj)
{
 

// attach the function set to the object
MFnNurbsCurve
fn(obj);

// this will hold the returned control points
MPointArray cvs;

// use the function set to get the points

fn.getCvs(cvs);

// write number of cvs
cout
<< "NumCVs " << cvs.length() << endl;

// loop through all points
for(int i=0;i!=cvs.length();++i) {

  // print control point
cout << cvs[i].x <<" "
<< cvs[
i].y <<" "
<< cvs[
i].z << "\n";

}

}


 

 

Knot Vectors

 

Maya has some very strange habits when dealing with knot vectors of curves and surfaces.

 

Maya will always return 2 knots less than it should for a given curve. This means that you have to invent the first and last knot for any parametric curve in maya.

 

 

 

 

 

 

 

 

 


#include<maya/MFnNurbsCurve.h>

void outputCurveKnots(MObject& obj)
{
 

// attach the function set to the object
MFnNurbsCurve
fn(obj);

// write number of knots
cout
<< "NumKnots " << (fn.numKnots()+2) << endl;

// write first knot that maya ignores. invent knot
// value for a clamped or periodic curve.
if( (fn.knot(1) - fn.knot(0)) < 0.01f )

  cout << fn.knot(0) << " ";

else

  cout << ( fn.knot( 0 ) - 1 ) << " ";

// write rest of the knots
for( int i=0; i<fn.numKnots(); ++i )

  cout << fn.knot(i) << " ";

// write last knot (that maya ignores)
if( (fn.knot(1) - fn.knot(0)) < 0.01f )

  cout << (fn.knot( fn.numKnots()-1 ) ) << "\n";

else

  cout << (fn.knot( fn.numKnots()-1 )+1) << "\n";
}




 

Curve Info

A few useful pieces of information may also be required when extracting Nurbs Curve information.

 

The curve degree can be found by using the degree() function of MFnNurbsCurve.

 

The order of the curve can simply be found by adding 1 to the curve degree.

 

The type of the curve may also be important. 3 types exist

 

  • MFnNurbsCurve::kOpen - the curve end and start points do not meet.
  • MFnNurbsCurve::kClosed - the end points of the curve meet, but no continuity remains.
  • MFnNurbsCurve::kPeriodic - the end points of the curves meet and continuity will be maintained.
 


#include<maya/MFnNurbsCurve.h>

void outputCurveInfo(MObject& obj)
{
 

// attach the function set to the object
MFnNurbsCurve
fn(obj);

// get the names of the uv sets on the mesh
cout << "degree " << fn.degree() << endl;

// get the names of the uv sets on the mesh
cout << "order " << (fn.degree()+1) << endl;

// write each tex coord
switch(fn.form()) {

 

// the curve type is open
case
MFnNurbsCurve::kOpen:
cout << "type open" << endl;
break;

// the curve type is closed
case
MFnNurbsCurve::kClosed:
cout << "type closed" << endl;
break;

// the curve type is periodic
case
MFnNurbsCurve::kPeriodic:
cout << "type periodic" << endl;
break;

// shouldn't get here
default
:
break;

}

}

 


 

 

What Next?

Transformation Data

Blend Shape Deformers

Lattice Deformers

index

Rob Bateman [2004]

[HOME] [MEL] [API]