//- // ========================================================================== // 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. // ========================================================================== //+ //============================= 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, "Alias", "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; }