//- // ========================================================================== // Copyright (C) 1995 - 2006 Autodesk, Inc. and/or its licensors. All // rights reserved. // // The coded instructions, statements, computer programs, and/or related // material (collectively the "Data") in these files contain unpublished // information proprietary to Autodesk, Inc. ("Autodesk") and/or its // licensors, which is protected by U.S. and Canadian federal copyright // law and by international treaties. // // The Data is provided for use exclusively by You. You have the right // to use, modify, and incorporate this Data into other products for // purposes authorized by the Autodesk software license agreement, // without fee. // // The copyright notices in the Software and this entire statement, // including the above license grant, this restriction and the // following disclaimer, must be included in all copies of the // Software, in whole or in part, and all derivative works of // the Software, unless such copies or derivative works are solely // in the form of machine-executable object code generated by a // source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. // AUTODESK DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED // WARRANTIES INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF // NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR // PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE, OR // TRADE PRACTICE. IN NO EVENT WILL AUTODESK AND/OR ITS LICENSORS // BE LIABLE FOR ANY LOST REVENUES, DATA, OR PROFITS, OR SPECIAL, // DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES, EVEN IF AUTODESK // AND/OR ITS LICENSORS HAS BEEN ADVISED OF THE POSSIBILITY // OR PROBABILITY OF SUCH DAMAGES. // // ========================================================================== //+ //============================= DESCRIPTION ================================= // This is an example of how to write an API spring node. // //=========================================================================== #include #include #include #include #include //================================================================= // Implement your new attributes here if your node has. // Here is an example code. //================================================================= MObject simpleSpring::aSpringFactor; MTypeId simpleSpring::id( 0x80017 ); simpleSpring::simpleSpring() : factor(0.0) { } simpleSpring::~simpleSpring() { } void *simpleSpring::creator() { return new simpleSpring; } MStatus simpleSpring::initialize() // // Descriptions: // Initialize the node, attributes. // { MStatus status; MFnNumericAttribute numAttr; //================================================================= // Initialize your new attributes here. Here is an example. //================================================================= aSpringFactor = numAttr.create("springFactor","sf",MFnNumericData::kDouble); numAttr.setDefault( 1.0 ); numAttr.setKeyable( true ); status = addAttribute( aSpringFactor ); McheckErr(status, "ERROR adding aSpringFactor attribute.\n"); return( MS::kSuccess ); } MStatus simpleSpring::compute(const MPlug& /*plug*/, MDataBlock& block) // // Descriptions: // In this simple example, do nothing in this method. But get the // spring factor here for "applySpringLaw" to compute output force. // // Note: always let this method return "kUnknownParameter" so that // "applySpringLaw" can be called when Maya needs to compute spring force. // // It is recommended to only override compute() to get user defined // attributes. // { // Get spring factor, // factor = springFactor( block ); // Note: return "kUnknownParameter" so that Maya spring node can // compute spring force for this plug-in simple spring node. // return( MS::kUnknownParameter ); } MStatus simpleSpring::applySpringLaw ( double /*stiffness*/, double /*damping*/, double restLength, double /*endMass1*/, double /*endMass2*/, const MVector &endP1, const MVector &endP2, const MVector &/*endV1*/, const MVector &/*endV2*/, MVector &forceV1, MVector &forceV2 ) // // Descriptions: // In this overridden method, the attribute, aSpringFactor, is used // to compute output force with a simple spring law. // // F = - factor * (L - restLength) * Vector of (endP1 - endP2). // { MVector distV = endP1 - endP2; double L = distV.length(); distV.normalize(); double F = factor * (L - restLength); forceV1 = - F * distV; forceV2 = - forceV1; return( MS::kSuccess ); } MStatus initializePlugin(MObject obj) { MStatus status; MFnPlugin plugin(obj, PLUGIN_COMPANY, "3.0", "Any"); status = plugin.registerNode( "simpleSpring", simpleSpring::id, &simpleSpring::creator, &simpleSpring::initialize, MPxNode::kSpringNode ); if (!status) { status.perror("registerNode"); return status; } return status; } MStatus uninitializePlugin(MObject obj) { MStatus status; MFnPlugin plugin(obj); status = plugin.deregisterNode( simpleSpring::id ); if (!status) { status.perror("deregisterNode"); return status; } return status; }