50 import maya.OpenMaya
as OpenMaya
51 import maya.OpenMayaMPx
as OpenMayaMPx
88 kPluginNodeTypeName =
"spSimpleSpring"
92 class simpleSpring(OpenMayaMPx.MPxSpringNode):
96 OpenMayaMPx.MPxSpringNode.__init__(self)
100 def compute(self, plug, block):
102 In this simple example, do nothing in this method. But get the
103 spring factor here for "applySpringLaw" to compute output force.
105 Note: always let this method return "kUnknownParameter" so that
106 "applySpringLaw" can be called when Maya needs to compute spring force.
108 It is recommended to only override compute() to get user defined
112 self.__myFactor = self.springFactor(block)
116 return OpenMaya.kUnknownParameter
119 def applySpringLaw(self, stiffness, damping, restLength, endMass1, endMass2,
120 endP1, endP2, endV1, endV2, forceV1, forceV2):
122 In this overridden method, the attribute, aSpringFactor, is used
123 to compute output force with a simple spring law.
125 F = - factor * (L - restLength) * Vector of (endP1 - endP2).
127 distV = endP1 - endP2
131 F = self.__myFactor * (L - restLength)
144 def springFactor(self, block):
145 hValue = block.inputValue(simpleSpring.aSpringFactor)
146 value = hValue.asDouble()
150 def end1WeightValue(self, block):
151 hValue = block.inputValue(simpleSpring.mEnd1Weight)
152 value = hValue.asDouble()
156 def end2WeightValue(self, block):
157 hValue = block.inputValue(simpleSpring.mEnd2Weight)
158 value = hValue.asDouble()
166 return OpenMayaMPx.asMPxPtr(simpleSpring())
172 simpleSpring.aSpringFactor = numAttr.create(
"springFactor",
"sf", OpenMaya.MFnNumericData.kDouble, 1.0)
173 numAttr.setKeyable(
True)
174 simpleSpring.addAttribute(simpleSpring.aSpringFactor)
178 def initializePlugin(mobject):
179 mplugin = OpenMayaMPx.MFnPlugin(mobject,
"Autodesk",
"3.0",
"Any")
181 mplugin.registerNode(kPluginNodeTypeName, spSimpleSpringNodeId,
182 creator, initializer, OpenMayaMPx.MPxNode.kSpringNode)
184 sys.stderr.write(
"Failed to register node: %s" % kPluginNodeTypeName )
189 def uninitializePlugin(mobject):
190 mplugin = OpenMayaMPx.MFnPlugin(mobject)
192 mplugin.deregisterNode( spSimpleSpringNodeId )
194 sys.stderr.write(
"Failed to deregister node: %s" % kPluginNodeTypeName )