//- // ========================================================================== // Copyright (C) 1995 - 2005 Alias Systems Corp. and/or its licensors. All // rights reserved. // // The coded instructions, statements, computer programs, and/or related // material (collectively the "Data") in these files are provided by Alias // Systems Corp. ("Alias") and/or its licensors for the exclusive use of the // Customer (as defined in the Alias Software License Agreement that // accompanies this Alias software). Such Customer has the right to use, // modify, and incorporate the Data into other products and to distribute such // products for use by end-users. // // THE DATA IS PROVIDED "AS IS". ALIAS HEREBY DISCLAIMS ALL WARRANTIES // RELATING TO THE DATA, INCLUDING, WITHOUT LIMITATION, ANY AND ALL EXPRESS OR // IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND/OR FITNESS FOR A // PARTICULAR PURPOSE. IN NO EVENT SHALL ALIAS BE LIABLE FOR ANY DAMAGES // WHATSOEVER, WHETHER DIRECT, INDIRECT, SPECIAL, OR PUNITIVE, WHETHER IN AN // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, OR IN EQUITY, // ARISING OUT OF ACCESS TO, USE OF, OR RELIANCE UPON THE DATA. // ========================================================================== //+ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class simpleLoft : public MPxNode { public: simpleLoft() {}; virtual ~simpleLoft(); virtual MStatus compute( const MPlug& plug, MDataBlock& data ); MObject loft( MObject &curve, MObject &surfFn, MStatus &stat ); static void* creator(); static MStatus initialize(); public: static MObject inputCurve; // The input curve. static MObject outputSurface; // The output curve. static MTypeId id; // The IFF type id }; MTypeId simpleLoft::id( 0x80011 ); MObject simpleLoft::inputCurve; MObject simpleLoft::outputSurface; simpleLoft::~simpleLoft() {} void* simpleLoft::creator() { return new simpleLoft(); } MStatus simpleLoft::initialize() { MFnTypedAttribute typedAttr; MStatus stat; inputCurve = typedAttr.create( "inputCurve", "in", MFnNurbsCurveData::kNurbsCurve, &stat ); if ( !stat ) { stat.perror("ERROR creating simpleLoft curve attribute"); return stat; } outputSurface = typedAttr.create( "outputSurface", "out", MFnNurbsSurfaceData::kNurbsSurface, &stat ); if ( !stat ) { stat.perror("ERROR creating simpleLoft surface attribute"); return stat; } typedAttr.setStorable( false ); stat = addAttribute( inputCurve ); if (!stat) { stat.perror("addAttribute"); return stat;} stat = addAttribute( outputSurface ); if (!stat) { stat.perror("addAttribute"); return stat;} stat = attributeAffects( inputCurve, outputSurface ); if (!stat) { stat.perror("attributeAffects"); return stat;} return MS::kSuccess; } MObject simpleLoft::loft( MObject &curve, MObject &newSurfData, MStatus &stat ) { MFnNurbsSurface surfFn; MPointArray cvs; MDoubleArray ku, kv; MFnNurbsCurve curveFn (curve); stat = curveFn.getCVs (cvs, MSpace::kWorld); if ( stat != MS::kSuccess ) { cerr << "Error in getting CVs: " << stat << endl; return MObject::kNullObj; } int i, j, k = cvs.length(); // create knot vectors for U and V ku.append( 0.0 ); ku.append( 0.0 ); ku.append( 0.0 ); ku.append( 1.0 ); ku.append( 1.0 ); ku.append( 1.0 ); kv.append( 0.0 ); kv.append( 0.0 ); kv.append( 0.0 ); for ( i = 1; i < k-3; i ++ ) kv.append( (double) i ); kv.append( k-3 ); kv.append( k-3 ); kv.append( k-3 ); // create cvs for the surface for ( i = 1; i < 4; i++ ) { for ( j = 0; j < k; j++ ) { MPoint point = cvs[j]; point.z += (double) i; // loft in Z by 1 cvs.append( point ); } } MObject surf = surfFn.create( cvs, ku, kv, 3, 3, MFnNurbsSurface::kOpen, MFnNurbsSurface::kOpen, false, newSurfData, &stat ); if ( stat != MS::kSuccess ) { cerr << "Error in creating surface: " << stat << endl; return MObject::kNullObj; } // stat = MGlobal::addToModel( surf ); return surf; } MStatus simpleLoft::compute( const MPlug& plug, MDataBlock& data ) { MStatus stat; if ( plug == outputSurface ) // loft inputCurve into surface { MDataHandle inputData = data.inputValue( inputCurve, &stat ); if( stat != MS::kSuccess ) { cerr << "ERROR getting data: " << stat << endl; return stat; } MObject curve = inputData.asNurbsCurve(); MFnNurbsCurve curveFn( curve, &stat ); if( stat != MS::kSuccess ) { cerr << "ERROR creating curve function set:" << stat << endl; return stat; } MDataHandle surfHandle = data.outputValue( simpleLoft::outputSurface ); if( stat != MS::kSuccess ) { cerr << "Error in getting data handle: " << stat << endl; return stat; } MFnNurbsSurfaceData dataCreator; MObject newSurfData = dataCreator.create( &stat ); if ( stat != MS::kSuccess ) { cerr << "Error creating new nurbs surface data block: " << stat << endl; return stat; } MObject newSurf = loft( curve, newSurfData, stat ); if( stat != MS::kSuccess ) { cerr << "Error in creating surface: " << stat << endl; return stat; } // newSurf is the new surface object, but it has been packed // into the datablock we created for it, and the data block // is what we must put onto the plug. surfHandle.set( newSurfData ); stat = data.setClean( plug ); if( stat != MS::kSuccess ) { cerr << "Error in cleaning outputSurface plug: " << stat << endl; return stat; } } else { return MS::kUnknownParameter; } return MS::kSuccess; } MStatus initializePlugin( MObject obj ) { MStatus status; MFnPlugin plugin( obj, "Alias", "3.0", "Any"); status = plugin.registerNode( "simpleLoft", simpleLoft::id, simpleLoft::creator, simpleLoft::initialize ); if (!status) { status.perror("registerNode"); return status; } return status; } MStatus uninitializePlugin( MObject obj) { MStatus status; MFnPlugin plugin( obj ); status = plugin.deregisterNode( simpleLoft::id ); if (!status) { status.perror("deregisterNode"); return status; } return status; }