54 from builtins
import range
55 import maya.OpenMaya
as OpenMaya
56 import maya.OpenMayaMPx
as OpenMayaMPx
57 import maya.OpenMayaRender
as OpenMayaRender
58 import maya.OpenMayaUI
as OpenMayaUI
63 kPluginLocatorTypeName =
"spFootPrintLocator"
64 kPluginLocatorManipTypeName =
"spFootPrintLocatorManip"
69 glRenderer = OpenMayaRender.MHardwareRenderer.theRenderer()
70 glFT = glRenderer.glFunctionTable()
72 sole = ( [ 0.00, 0.0, -0.70 ],
84 [ -0.15, 0.0, -0.14 ],
85 [ -0.16, 0.0, -0.25 ],
86 [ -0.17, 0.0, -0.35 ],
87 [ -0.17, 0.0, -0.46 ],
88 [ -0.16, 0.0, -0.54 ],
89 [ -0.13, 0.0, -0.61 ],
90 [ -0.09, 0.0, -0.65 ],
91 [ -0.04, 0.0, -0.69 ],
92 [ -0.00, 0.0, -0.70 ] )
94 heel = ( [ 0.00, 0.0, 0.06 ],
103 [ -0.04, 0.0, 0.30 ],
104 [ -0.09, 0.0, 0.29 ],
105 [ -0.11, 0.0, 0.28 ],
106 [ -0.13, 0.0, 0.25 ],
107 [ -0.14, 0.0, 0.21 ],
108 [ -0.14, 0.0, 0.15 ],
109 [ -0.13, 0.0, 0.06 ],
110 [ -0.00, 0.0, 0.06 ] )
113 class footPrintLocatorManip(OpenMayaMPx.MPxManipContainer):
115 OpenMayaMPx.MPxManipContainer.__init__(self)
119 def createChildren(self):
124 self.fDistanceManip = self.addDistanceManip(
"distanceManip",
"distance")
127 distanceManipFn.setStartPoint(startPoint)
128 distanceManipFn.setDirection(direction)
130 sys.stderr.write(
"ERROR: footPrintLocatorManip.createChildren\n")
133 def plugToManipConversion( manipIndex ):
136 numDataObj = numData.create(OpenMaya.MFnNumericData.k3Double)
138 vec = self.nodeTranslation()
139 numData.setData3Double(vec.x, vec.y, vec.z)
141 returnData = OpenMaya.MManipData(numDataObj)
143 sys.stderr.write(
"ERROR: footPrintLocatorManip.plugToManipConversion\n")
147 def connectToDependNode(self, node):
150 dagNodeFn.getPath(self.fNodePath)
155 sizePlug = nodeFn.findPlug(
'size')
156 distanceManipFn.connectToDistancePlug(sizePlug)
158 self.finishAddingManips()
159 OpenMayaMPx.MPxManipContainer.connectToDependNode(self, node)
161 sys.stderr.write(
"ERROR: footPrintLocatorManip.connectToDependNode\n")
164 def draw(self, view, path, style, status):
165 OpenMayaMPx.MPxManipContainer.draw(self, view, path, style, status)
169 textPosVector = self.nodeTranslation()
170 textPosPoint =
OpenMaya.MPoint(textPosVector.x, textPosVector.y, textPosVector.z)
172 view.drawText(
'Stretch Me!', textPosPoint, OpenMayaUI.M3dView.kLeft)
175 def startPointCallback(self, index):
177 numDataObj = numData.create(OpenMaya.MFnNumericData.k3Double)
179 vec = self.nodeTranslation()
180 numData.setData3Double(vec.x, vec.y, vec.z)
184 def nodeTranslation(self):
194 return transformFn.translation(OpenMaya.MSpace.kWorld)
197 class footPrintLocator(OpenMayaMPx.MPxLocatorNode):
201 OpenMayaMPx.MPxLocatorNode.__init__(self)
203 def compute(self, plug, dataBlock):
204 return OpenMaya.kUnknownParameter
206 def draw(self, view, path, style, status):
207 thisNode = self.thisMObject()
211 sizeVal = plug.asMDistance()
213 multiplier = sizeVal.asCentimeters()
217 if style == OpenMayaUI.M3dView.kFlatShaded
or style == OpenMayaUI.M3dView.kGouraudShaded:
218 glFT.glPushAttrib(OpenMayaRender.MGL_CURRENT_BIT)
220 if status == OpenMayaUI.M3dView.kActive:
221 view.setDrawColor( 13, OpenMayaUI.M3dView.kActiveColors )
223 view.setDrawColor( 13, OpenMayaUI.M3dView.kDormantColors )
226 glFT.glBegin( OpenMayaRender.MGL_TRIANGLE_FAN )
227 for i
in range(last):
228 glFT.glVertex3f(sole[i][0]*multiplier, sole[i][1]*multiplier, sole[i][2]*multiplier)
232 glFT.glBegin( OpenMayaRender.MGL_TRIANGLE_FAN )
233 for i
in range(last):
234 glFT.glVertex3f(heel[i][0]*multiplier, heel[i][1]*multiplier, heel[i][2]*multiplier)
239 glFT.glBegin(OpenMayaRender.MGL_LINES)
242 for i
in range(last):
243 glFT.glVertex3f( sole[i][0]*multiplier, sole[i][1]*multiplier, sole[i][2]*multiplier )
244 glFT.glVertex3f( sole[i+1][0]*multiplier, sole[i+1][1]*multiplier, sole[i+1][2]*multiplier )
247 for i
in range(last):
248 glFT.glVertex3f( heel[i][0]*multiplier, heel[i][1]*multiplier, heel[i][2]*multiplier )
249 glFT.glVertex3f( heel[i+1][0]*multiplier, heel[i+1][1]*multiplier, heel[i+1][2]*multiplier )
258 def boundingBox(self):
259 thisNode = self.thisMObject()
262 sizeVal = plug.asMDistance()
264 multiplier = sizeVal.asCentimeters()
269 corner1 = corner1 * multiplier
270 corner2 = corner2 * multiplier
276 def locatorCreator():
277 return OpenMayaMPx.asMPxPtr( footPrintLocator() )
279 def locatorInitializer():
281 footPrintLocator.size = unitFn.create(
"size",
"in", OpenMaya.MFnUnitAttribute.kDistance)
282 unitFn.setDefault(10.0)
283 unitFn.setStorable(
True)
284 unitFn.setWritable(
True)
286 footPrintLocator.addAttribute( footPrintLocator.size )
287 OpenMayaMPx.MPxManipContainer.addToManipConnectTable(footPrintLocatorId)
289 def locatorManipCreator():
290 return OpenMayaMPx.asMPxPtr( footPrintLocatorManip() )
292 def locatorManipInitializer():
293 OpenMayaMPx.MPxManipContainer.initialize()
297 def initializePlugin(mobject):
298 mplugin = OpenMayaMPx.MFnPlugin(mobject)
301 mplugin.registerNode( kPluginLocatorTypeName, footPrintLocatorId, locatorCreator, locatorInitializer, OpenMayaMPx.MPxNode.kLocatorNode )
303 sys.stderr.write(
"Failed to register node: %s" % kPluginLocatorTypeName )
307 mplugin.registerNode( kPluginLocatorManipTypeName, footPrintLocatorManipId, locatorManipCreator, locatorManipInitializer, OpenMayaMPx.MPxNode.kManipContainer )
309 sys.stderr.write(
"Failed to register node: %s" % kPluginLocatorManipTypeName )
314 def uninitializePlugin(mobject):
315 mplugin = OpenMayaMPx.MFnPlugin(mobject)
317 mplugin.deregisterNode( footPrintLocatorId )
319 sys.stderr.write(
"Failed to deregister node: %s" % kPluginLocatorTypeName )
323 mplugin.deregisterNode( footPrintLocatorManipId )
325 sys.stderr.write(
"Failed to deregister node: %s" % kPluginLocatorManipTypeName )