27 from builtins
import range
29 import maya.api.OpenMaya
as om
30 import maya.api.OpenMayaUI
as omui
31 import maya.api.OpenMayaAnim
as oma
32 import maya.api.OpenMayaRender
as omr
36 The presence of this function tells Maya that the plugin produces, and
37 expects to be passed, objects created using the Maya Python API 2.0.
41 def matrixAsArray(matrix):
44 array.append(matrix[i])
49 sole = [ [ 0.00, 0.0, -0.70 ],
61 [ -0.15, 0.0, -0.14 ],
62 [ -0.16, 0.0, -0.25 ],
63 [ -0.17, 0.0, -0.35 ],
64 [ -0.17, 0.0, -0.46 ],
65 [ -0.16, 0.0, -0.54 ],
66 [ -0.13, 0.0, -0.61 ],
67 [ -0.09, 0.0, -0.65 ],
68 [ -0.04, 0.0, -0.69 ],
69 [ -0.00, 0.0, -0.70 ] ]
70 heel = [ [ 0.00, 0.0, 0.06 ],
86 [ -0.00, 0.0, 0.06 ] ]
96 class footPrint(omui.MPxLocatorNode):
97 id = om.MTypeId( 0x00080067 )
98 drawDbClassification =
"drawdb/geometry/footPrint_py"
99 drawRegistrantId =
"FootprintNodePlugin_py"
109 unitFn = om.MFnUnitAttribute()
111 footPrint.size = unitFn.create(
"size",
"sz", om.MFnUnitAttribute.kDistance )
112 unitFn.default = om.MDistance(1.0)
114 om.MPxNode.addAttribute( footPrint.size )
117 omui.MPxLocatorNode.__init__(self)
119 def compute(self, plug, data):
122 def draw(self, view, path, style, status):
125 thisNode = self.thisMObject()
126 plug = om.MPlug( thisNode, footPrint.size )
127 sizeVal = plug.asMDistance()
128 multiplier = sizeVal.asCentimeters()
130 global sole, soleCount
131 global heel, heelCount
136 import maya.OpenMayaRender
as v1omr
137 glRenderer = v1omr.MHardwareRenderer.theRenderer()
138 glFT = glRenderer.glFunctionTable()
140 if ( style == omui.M3dView.kFlatShaded )
or ( style == omui.M3dView.kGouraudShaded ):
143 glFT.glPushAttrib( v1omr.MGL_CURRENT_BIT )
146 glFT.glDisable( v1omr.MGL_CULL_FACE )
148 if status == omui.M3dView.kActive:
149 view.setDrawColor( 13, omui.M3dView.kActiveColors )
151 view.setDrawColor( 13, omui.M3dView.kDormantColors )
153 glFT.glBegin( v1omr.MGL_TRIANGLE_FAN )
154 for i
in range(soleCount-1):
155 glFT.glVertex3f( sole[i][0] * multiplier, sole[i][1] * multiplier, sole[i][2] * multiplier )
158 glFT.glBegin( v1omr.MGL_TRIANGLE_FAN )
159 for i
in range(heelCount-1):
160 glFT.glVertex3f( heel[i][0] * multiplier, heel[i][1] * multiplier, heel[i][2] * multiplier )
167 glFT.glBegin( v1omr.MGL_LINES )
168 for i
in range(soleCount-1):
169 glFT.glVertex3f( sole[i][0] * multiplier, sole[i][1] * multiplier, sole[i][2] * multiplier )
170 glFT.glVertex3f( sole[i+1][0] * multiplier, sole[i+1][1] * multiplier, sole[i+1][2] * multiplier )
172 for i
in range(heelCount-1):
173 glFT.glVertex3f( heel[i][0] * multiplier, heel[i][1] * multiplier, heel[i][2] * multiplier )
174 glFT.glVertex3f( heel[i+1][0] * multiplier, heel[i+1][1] * multiplier, heel[i+1][2] * multiplier )
180 view.setDrawColor( om.MColor( (0.1, 0.8, 0.8, 1.0) ) )
181 view.drawText(
"Footprint", om.MPoint( 0.0, 0.0, 0.0 ), omui.M3dView.kCenter )
186 def boundingBox(self):
189 thisNode = self.thisMObject()
190 plug = om.MPlug( thisNode, footPrint.size )
191 sizeVal = plug.asMDistance()
192 multiplier = sizeVal.asCentimeters()
194 corner1 = om.MPoint( -0.17, 0.0, -0.7 )
195 corner2 = om.MPoint( 0.17, 0.0, 0.3 )
197 corner1 *= multiplier
198 corner2 *= multiplier
200 return om.MBoundingBox( corner1, corner2 )
207 class footPrintData(om.MUserData):
209 om.MUserData.__init__(self,
False)
211 self.fColor = om.MColor()
212 self.fLineList = om.MPointArray()
213 self.fTriangleList = om.MPointArray()
215 class footPrintDrawOverride(omr.MPxDrawOverride):
218 return footPrintDrawOverride(obj)
225 def __init__(self, obj):
226 omr.MPxDrawOverride.__init__(self, obj,
None,
False)
231 self.mCustomBoxDraw =
True
232 self.mCurrentBoundingBox = om.MBoundingBox()
234 def supportedDrawAPIs(self):
236 return omr.MRenderer.kOpenGL | omr.MRenderer.kDirectX11 | omr.MRenderer.kOpenGLCoreProfile
238 def isBounded(self, objPath, cameraPath):
241 def boundingBox(self, objPath, cameraPath):
242 corner1 = om.MPoint( -0.17, 0.0, -0.7 )
243 corner2 = om.MPoint( 0.17, 0.0, 0.3 )
245 multiplier = self.getMultiplier(objPath)
246 corner1 *= multiplier
247 corner2 *= multiplier
249 self.mCurrentBoundingBox.clear()
250 self.mCurrentBoundingBox.expand( corner1 )
251 self.mCurrentBoundingBox.expand( corner2 )
253 return self.mCurrentBoundingBox
255 def disableInternalBoundingBoxDraw(self):
256 return self.mCustomBoxDraw
258 def prepareForDraw(self, objPath, cameraPath, frameContext, oldData):
261 if not isinstance(data, footPrintData):
262 data = footPrintData()
265 global soleCount, sole
266 global heelCount, heel
268 fMultiplier = self.getMultiplier(objPath)
270 data.fLineList.clear()
272 for i
in range(soleCount-1):
273 data.fLineList.append( om.MPoint(sole[i][0] * fMultiplier, sole[i][1] * fMultiplier, sole[i][2] * fMultiplier) )
274 data.fLineList.append( om.MPoint(sole[i+1][0] * fMultiplier, sole[i+1][1] * fMultiplier, sole[i+1][2] * fMultiplier) )
276 for i
in range(heelCount-1):
277 data.fLineList.append( om.MPoint(heel[i][0] * fMultiplier, heel[i][1] * fMultiplier, heel[i][2] * fMultiplier) )
278 data.fLineList.append( om.MPoint(heel[i+1][0] * fMultiplier, heel[i+1][1] * fMultiplier, heel[i+1][2] * fMultiplier) )
280 data.fTriangleList.clear()
282 for i
in range(1,soleCount-1):
283 data.fTriangleList.append( om.MPoint(sole[0][0] * fMultiplier, sole[0][1] * fMultiplier, sole[0][2] * fMultiplier) )
284 data.fTriangleList.append( om.MPoint(sole[i][0] * fMultiplier, sole[i][1] * fMultiplier, sole[i][2] * fMultiplier) )
285 data.fTriangleList.append( om.MPoint(sole[i+1][0] * fMultiplier, sole[i+1][1] * fMultiplier, sole[i+1][2] * fMultiplier) )
287 for i
in range(1,heelCount-1):
288 data.fTriangleList.append( om.MPoint(heel[0][0] * fMultiplier, heel[0][1] * fMultiplier, heel[0][2] * fMultiplier) )
289 data.fTriangleList.append( om.MPoint(heel[i][0] * fMultiplier, heel[i][1] * fMultiplier, heel[i][2] * fMultiplier) )
290 data.fTriangleList.append( om.MPoint(heel[i+1][0] * fMultiplier, heel[i+1][1] * fMultiplier, heel[i+1][2] * fMultiplier) )
292 data.fColor = omr.MGeometryUtilities.wireframeColor(objPath)
296 def hasUIDrawables(self):
299 def addUIDrawables(self, objPath, drawManager, frameContext, data):
301 if not isinstance(locatordata, footPrintData):
304 drawManager.beginDrawable()
307 drawManager.setColor( locatordata.fColor )
308 drawManager.setDepthPriority(5)
310 if (frameContext.getDisplayStyle() & omr.MFrameContext.kGouraudShaded):
311 drawManager.mesh(omr.MGeometry.kTriangles, locatordata.fTriangleList)
313 drawManager.mesh(omr.MUIDrawManager.kLines, locatordata.fLineList)
316 pos = om.MPoint( 0.0, 0.0, 0.0 )
317 textColor = om.MColor( (0.1, 0.8, 0.8, 1.0) )
319 drawManager.setColor( textColor )
320 drawManager.setFontSize( omr.MUIDrawManager.kSmallFontSize )
321 drawManager.text(pos,
"Footprint", omr.MUIDrawManager.kCenter )
323 drawManager.endDrawable()
325 def getMultiplier(self, objPath):
327 footprintNode = objPath.node()
328 plug = om.MPlug(footprintNode, footPrint.size)
330 sizeVal = plug.asMDistance()
331 return sizeVal.asCentimeters()
335 def initializePlugin(obj):
336 plugin = om.MFnPlugin(obj,
"Autodesk",
"3.0",
"Any")
339 plugin.registerNode(
"footPrint_py", footPrint.id, footPrint.creator, footPrint.initialize, om.MPxNode.kLocatorNode, footPrint.drawDbClassification)
341 sys.stderr.write(
"Failed to register node\n")
345 omr.MDrawRegistry.registerDrawOverrideCreator(footPrint.drawDbClassification, footPrint.drawRegistrantId, footPrintDrawOverride.creator)
347 sys.stderr.write(
"Failed to register override\n")
350 def uninitializePlugin(obj):
351 plugin = om.MFnPlugin(obj)
354 plugin.deregisterNode(footPrint.id)
356 sys.stderr.write(
"Failed to deregister node\n")
360 omr.MDrawRegistry.deregisterDrawOverrideCreator(footPrint.drawDbClassification, footPrint.drawRegistrantId)
362 sys.stderr.write(
"Failed to deregister override\n")