本文整理汇总了C++中MFnNurbsCurve::create方法的典型用法代码示例。如果您正苦于以下问题:C++ MFnNurbsCurve::create方法的具体用法?C++ MFnNurbsCurve::create怎么用?C++ MFnNurbsCurve::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MFnNurbsCurve
的用法示例。
在下文中一共展示了MFnNurbsCurve::create方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateACurve
bool HesperisCurveCreator::CreateACurve(Vector3F * pos, unsigned nv, MObject &target)
{
MPointArray vertexArray;
unsigned i=0;
for(; i<nv; i++)
vertexArray.append( MPoint( pos[i].x, pos[i].y, pos[i].z ) );
const int degree = 2;
const int spans = nv - degree;
const int nknots = spans + 2 * degree - 1;
MDoubleArray knotSequences;
knotSequences.append(0.0);
for(i = 0; i < nknots-2; i++)
knotSequences.append( (double)i );
knotSequences.append(nknots-3);
MFnNurbsCurve curveFn;
MStatus stat;
curveFn.create(vertexArray,
knotSequences, degree,
MFnNurbsCurve::kOpen,
false, false,
target,
&stat );
return stat == MS::kSuccess;
}
示例2: jMakeCurve
/*
-----------------------------------------
Make a degree 1 curve from the given CVs.
-----------------------------------------
*/
static void jMakeCurve( MPointArray cvs )
{
MStatus stat;
unsigned int deg = 1;
MDoubleArray knots;
unsigned int i;
for ( i = 0; i < cvs.length(); i++ )
knots.append( (double) i );
// Now create the curve
//
MFnNurbsCurve curveFn;
curveFn.create( cvs,
knots, deg,
MFnNurbsCurve::kOpen,
false, false,
MObject::kNullObj,
&stat );
if ( MS::kSuccess != stat )
cout<<"Error creating curve."<<endl;
}
示例3: doIt
MStatus helix::doIt( const MArgList& args )
{
MStatus stat;
const unsigned deg = 3; // Curve Degree
const unsigned ncvs = 20; // Number of CVs
const unsigned spans = ncvs - deg; // Number of spans
const unsigned nknots = spans+2*deg-1;// Number of knots
double radius = 4.0; // Helix radius
double pitch = 0.5; // Helix pitch
unsigned i;
// Parse the arguments.
for ( i = 0; i < args.length(); i++ )
if ( MString( "-p" ) == args.asString( i, &stat )
&& MS::kSuccess == stat)
{
double tmp = args.asDouble( ++i, &stat );
if ( MS::kSuccess == stat )
pitch = tmp;
}
else if ( MString( "-r" ) == args.asString( i, &stat )
&& MS::kSuccess == stat)
{
double tmp = args.asDouble( ++i, &stat );
if ( MS::kSuccess == stat )
radius = tmp;
}
MPointArray controlVertices;
MDoubleArray knotSequences;
// Set up cvs and knots for the helix
//
for (i = 0; i < ncvs; i++)
controlVertices.append( MPoint( radius * cos( (double)i ),
pitch * (double)i, radius * sin( (double)i ) ) );
for (i = 0; i < nknots; i++)
knotSequences.append( (double)i );
// Now create the curve
//
MFnNurbsCurve curveFn;
curveFn.create( controlVertices,
knotSequences, deg,
MFnNurbsCurve::kOpen,
false, false,
MObject::kNullObj,
&stat );
if ( MS::kSuccess != stat )
cout<<"Error creating curve."<<endl;
return stat;
}
示例4: createHelix
void HelixButton::createHelix()
{
MStatus st;
const unsigned deg = 3; // Curve Degree
const unsigned ncvs = 20; // Number of CVs
const unsigned spans = ncvs - deg; // Number of spans
const unsigned nknots = spans + 2 * deg - 1; // Number of knots
double radius = 4.0; // Helix radius
double pitch = 0.5; // Helix pitch
unsigned i;
MPointArray controlVertices;
MDoubleArray knotSequences;
// Set up cvs and knots for the helix
for (i = 0; i < ncvs; i++) {
controlVertices.append(
MPoint(
radius * cos((double)i),
pitch * (double)i,
radius * sin((double)i)
)
);
}
for (i = 0; i < nknots; i++)
knotSequences.append((double)i);
// Now create the curve
MFnNurbsCurve curveFn;
MObject curve = curveFn.create(
controlVertices,
knotSequences,
deg,
MFnNurbsCurve::kOpen,
false,
false,
MObject::kNullObj,
&st
);
MGlobal::displayInfo("Helix curve created!");
if (!st) {
MGlobal::displayError(
HelixQtCmd::commandName + " - could not create helix: "
+ st.errorString()
);
}
}
示例5:
MStatus CreateCurves::Curve::create(CreateCurves & instance) {
MStatus status;
MFnNurbsCurve curve;
MObject curveObject = curve.create(points, knots, instance.m_degree, isLoop ? MFnNurbsCurve::kClosed : MFnNurbsCurve::kOpen, false, false, MObject::kNullObj, &status);
if (!status) {
status.perror("MFnNurbsCurve::create");
return status;
}
MDagPath path;
if (!(status = curve.getPath(path))) {
status.perror("MFnNurbsCurve::getPath");
return status;
}
instance.m_curves.append(path.transform());
return MStatus::kSuccess;
}
示例6: doConversion
//.........这里部分代码省略.........
for( int i=0; i<curveIndex; ++i )
{
curveBase += verticesPerCurve[i];
}
MPointArray vertexArray;
int numVertices = verticesPerCurve[curveIndex];
int cvOffset = 0;
if( curves->basis() != IECore::CubicBasisf::linear() && !curves->periodic() )
{
// Maya implicitly duplicates end points, so they're explicitly duplicated in the CurvePrimitives.
// We need to remove those duplicates when converting back to Maya. Remove 2 cvs at start, 2 at end.
if( numVertices < 8 )
{
IECore::msg( IECore::Msg::Warning,"ToMayaCurveConverter::doConversion", "The Curve Primitive does not have enough CVs to be converted into a Maya Curve. Needs at least 8." );
return false;
}
cvOffset = 2;
}
const std::vector<Imath::V3f>& pts = p->readable();
// triple up the start points for cubic periodic curves:
if( curves->periodic() && curves->basis() != IECore::CubicBasisf::linear() )
{
vertexArray.append( IECore::convert<MPoint, Imath::V3f>( pts[curveBase] ) );
vertexArray.append( vertexArray[0] );
}
for( int i = cvOffset; i < numVertices-cvOffset; ++i )
{
vertexArray.append( IECore::convert<MPoint, Imath::V3f>( pts[i + curveBase] ) );
}
// if the curve is periodic, the first N cvs must be identical to the last N cvs, where N is the degree
// of the curve:
if( curves->periodic() )
{
if( curves->basis() == IECore::CubicBasisf::linear() )
{
// linear: N = 1
vertexArray.append( vertexArray[0] );
}
else
{
// cubic: N = 3
vertexArray.append( vertexArray[0] );
vertexArray.append( vertexArray[1] );
vertexArray.append( vertexArray[2] );
}
}
unsigned vertexArrayLength = vertexArray.length();
MDoubleArray knotSequences;
if( curves->basis() == IECore::CubicBasisf::linear() )
{
for( unsigned i=0; i < vertexArrayLength; ++i )
{
knotSequences.append( i );
}
}
else
{
if( curves->periodic() )
{
// Periodic curve, knots must be spaced out.
knotSequences.append( -1 );
for( unsigned i=0; i < vertexArrayLength+1; ++i )
{
knotSequences.append( i );
}
}
else
{
// For a cubic curve, the first three and last three knots must be duplicated for the curve start/end to start at the first/last CV.
knotSequences.append( 0 );
knotSequences.append( 0 );
for( unsigned i=0; i < vertexArrayLength-2; ++i )
{
knotSequences.append( i );
}
knotSequences.append( vertexArrayLength-3 );
knotSequences.append( vertexArrayLength-3 );
}
}
MFnNurbsCurve fnCurve;
fnCurve.create( vertexArray, knotSequences, curves->basis() == IECore::CubicBasisf::linear() ? 1 : 3, curves->periodic() ? MFnNurbsCurve::kPeriodic : MFnNurbsCurve::kOpen, false, false, to, &s );
if (!s)
{
IECore::msg( IECore::Msg::Warning,"ToMayaCurveConverter::doConversion", s.errorString().asChar() );
return false;
}
return true;
}
示例7: mayaPoints
//.........这里部分代码省略.........
curveKnots.resize(points.size() -3 + 5);
int knotIdx = 0;
for (size_t i=0; i < curveKnots.size(); ++i) {
if (i < 3) {
curveKnots[i] = 0.0;
} else {
if (i <= curveKnots.size() - 3) {
++knotIdx;
}
curveKnots[i] = double(knotIdx);
}
}
}
}
// == Convert data
size_t mayaNumVertices = points.size();
MPointArray mayaPoints(mayaNumVertices);
for (size_t i=0; i < mayaNumVertices; i++) {
mayaPoints.set( i, points[i][0], points[i][1], points[i][2] );
}
double *knots=curveKnots.data();
MDoubleArray mayaKnots( knots, curveKnots.size());
int mayaDegree = curveOrder[curveIndex] - 1;
MFnNurbsCurve::Form mayaCurveForm = MFnNurbsCurve::kOpen; // HARDCODED
bool mayaCurveCreate2D = false;
bool mayaCurveCreateRational = true;
// == Create NurbsCurve Shape Node
MFnNurbsCurve curveFn;
MObject curveObj = curveFn.create(mayaPoints,
mayaKnots,
mayaDegree,
mayaCurveForm,
mayaCurveCreate2D,
mayaCurveCreateRational,
mayaNodeTransformObj,
&status
);
if (status != MS::kSuccess) {
return false;
}
MString nodeName( prim.GetName().GetText() );
nodeName += "Shape";
curveFn.setName(nodeName, false, &status);
std::string nodePath( prim.GetPath().GetText() );
nodePath += "/";
nodePath += nodeName.asChar();
if (context) {
context->RegisterNewMayaNode( nodePath, curveObj ); // used for undo/redo
}
// == Animate points ==
// Use blendShapeDeformer so that all the points for a frame are contained in a single node
// Almost identical code as used with MayaMeshReader.cpp
//
if (numTimeSamples > 0) {
MPointArray mayaPoints(mayaNumVertices);
MObject curveAnimObj;
MFnBlendShapeDeformer blendFn;
MObject blendObj = blendFn.create(curveObj);
示例8: doIt
//.........这里部分代码省略.........
// It is necessary to query the worldPosition attribute to force the
// particle positions to update.
//
cloud.evaluateDynamics(timeSeconds,false);
// MGlobal::executeCommand(MString("getAttr ") + cloud.name() +
// MString(".worldPosition"));
if (!cloud.isValid())
{
MGlobal::displayError( "Particle system has become invalid." );
return MS::kFailure;
}
MGlobal::displayInfo( MString("Received ") + (int)(cloud.count()) +
" particles, at time " + time);
// Request position and ID data for particles
//
cloud.position( positions );
cloud.particleIds( ids );
if (ids.length() != cloud.count() || positions.length() != cloud.count())
{
MGlobal::displayError( "Invalid array sizes." );
return MS::kFailure;
}
for (int j = 0; j < (int)cloud.count(); j++)
{
// Uncomment to show particle positions as the plugin accumulates
// samples.
/*
MGlobal::displayInfo(MString("(") + (positions[j])[0] + MString(",") +
(positions[j])[1] + MString(",") + (positions[j])[2] + MString(")"));
*/
MPoint pt(positions[j]);
if (hash.getPoints(ids[j]).length() == 0)
{
idList.append(ids[j]);
}
hash.insert(ids[j],pt);
}
i++;
}
//
// Stage 2
//
for (i = 0; i < (int)(idList.length()); i++)
{
MPointArray points = hash.getPoints(idList[i]);
// Don't bother with single samples
if (points.length() <= 1)
{
continue;
}
// Add two additional points, so that the curve covers all sampled
// values.
//
MPoint p1 = points[0]*2 - points[1];
MPoint p2 = points[points.length()-1]*2 - points[points.length()-2];
points.insert(p1,0);
points.append(p2);
// Uncomment to show information about the generated curves
/*
MGlobal::displayInfo( MString("ID ") + (int)(idList[i]) + " has " + (int)(points.length()) + " curve points.");
for (int j = 0; j < (int)(points.length()); j++)
{
MGlobal::displayInfo(MString("(") + points[j][0] + MString(",") + points[j][1] + MString(",") + points[j][2] + MString(")"));
}
*/
MDoubleArray knots;
knots.insert(0.0,0);
for (int j = 0; j < (int)(points.length()); j++)
{
knots.append((double)j);
}
knots.append(points.length()-1);
MStatus status;
MObject dummy;
MFnNurbsCurve curve;
curve.create(points,knots,3,MFnNurbsCurve::kOpen,false,false,dummy,&status);
if (!status)
{
MGlobal::displayError("Failed to create nurbs curve.");
return MS::kFailure;
}
}
return MS::kSuccess;
}