40 import maya.OpenMaya
as OpenMaya
41 import maya.OpenMayaMPx
as OpenMayaMPx
78 kPluginNodeTypeName =
"spSimpleSpring"
79 spSimpleSpringNodeId = OpenMaya.MTypeId(0x87004)
82 class simpleSpring(OpenMayaMPx.MPxSpringNode):
83 aSpringFactor = OpenMaya.MObject()
86 OpenMayaMPx.MPxSpringNode.__init__(self)
90 def compute(self, plug, block):
92 In this simple example, do nothing in this method. But get the
93 spring factor here for "applySpringLaw" to compute output force.
95 Note: always let this method return "kUnknownParameter" so that
96 "applySpringLaw" can be called when Maya needs to compute spring force.
98 It is recommended to only override compute() to get user defined
102 self.__myFactor = self.springFactor(block)
106 return OpenMaya.kUnknownParameter
109 def applySpringLaw(self, stiffness, damping, restLength, endMass1, endMass2,
110 endP1, endP2, endV1, endV2, forceV1, forceV2):
112 In this overridden method, the attribute, aSpringFactor, is used
113 to compute output force with a simple spring law.
115 F = - factor * (L - restLength) * Vector of (endP1 - endP2).
117 distV = endP1 - endP2
121 F = self.__myFactor * (L - restLength)
134 def springFactor(self, block):
135 hValue = block.inputValue(simpleSpring.aSpringFactor)
136 value = hValue.asDouble()
140 def end1WeightValue(self, block):
141 hValue = block.inputValue(simpleSpring.mEnd1Weight)
142 value = hValue.asDouble()
146 def end2WeightValue(self, block):
147 hValue = block.inputValue(simpleSpring.mEnd2Weight)
148 value = hValue.asDouble()
156 return OpenMayaMPx.asMPxPtr(simpleSpring())
160 numAttr = OpenMaya.MFnNumericAttribute()
162 simpleSpring.aSpringFactor = numAttr.create(
"springFactor",
"sf", OpenMaya.MFnNumericData.kDouble, 1.0)
163 numAttr.setKeyable(
True)
164 simpleSpring.addAttribute(simpleSpring.aSpringFactor)
168 def initializePlugin(mobject):
169 mplugin = OpenMayaMPx.MFnPlugin(mobject,
"Autodesk",
"3.0",
"Any")
171 mplugin.registerNode(kPluginNodeTypeName, spSimpleSpringNodeId,
172 creator, initializer, OpenMayaMPx.MPxNode.kSpringNode)
174 sys.stderr.write(
"Failed to register node: %s" % kPluginNodeTypeName )
179 def uninitializePlugin(mobject):
180 mplugin = OpenMayaMPx.MFnPlugin(mobject)
182 mplugin.deregisterNode( spSimpleSpringNodeId )
184 sys.stderr.write(
"Failed to deregister node: %s" % kPluginNodeTypeName )