28 import maya.api.OpenMaya
as om
29 import maya.api.OpenMayaUI
as omui
30 import maya.api.OpenMayaAnim
as oma
31 import maya.api.OpenMayaRender
as omr
35 The presence of this function tells Maya that the plugin produces, and
36 expects to be passed, objects created using the Maya Python API 2.0.
40 def matrixAsArray(matrix):
43 array.append(matrix[i])
48 sole = [ [ 0.00, 0.0, -0.70 ],
60 [ -0.15, 0.0, -0.14 ],
61 [ -0.16, 0.0, -0.25 ],
62 [ -0.17, 0.0, -0.35 ],
63 [ -0.17, 0.0, -0.46 ],
64 [ -0.16, 0.0, -0.54 ],
65 [ -0.13, 0.0, -0.61 ],
66 [ -0.09, 0.0, -0.65 ],
67 [ -0.04, 0.0, -0.69 ],
68 [ -0.00, 0.0, -0.70 ] ]
69 heel = [ [ 0.00, 0.0, 0.06 ],
85 [ -0.00, 0.0, 0.06 ] ]
95 class footPrint(omui.MPxLocatorNode):
96 id = om.MTypeId( 0x80007 )
97 drawDbClassification =
"drawdb/geometry/footPrint"
98 drawRegistrantId =
"FootprintNodePlugin"
108 unitFn = om.MFnUnitAttribute()
110 footPrint.size = unitFn.create(
"size",
"sz", om.MFnUnitAttribute.kDistance )
111 unitFn.default = om.MDistance(1.0)
113 om.MPxNode.addAttribute( footPrint.size )
116 omui.MPxLocatorNode.__init__(self)
118 def compute(self, plug, data):
121 def draw(self, view, path, style, status):
124 thisNode = self.thisMObject()
125 plug = om.MPlug( thisNode, footPrint.size )
126 sizeVal = plug.asMDistance()
127 multiplier = sizeVal.asCentimeters()
129 global sole, soleCount
130 global heel, heelCount
135 import maya.OpenMayaRender
as v1omr
136 glRenderer = v1omr.MHardwareRenderer.theRenderer()
137 glFT = glRenderer.glFunctionTable()
139 if ( style == omui.M3dView.kFlatShaded )
or ( style == omui.M3dView.kGouraudShaded ):
142 glFT.glPushAttrib( v1omr.MGL_CURRENT_BIT )
145 glFT.glDisable( v1omr.MGL_CULL_FACE )
147 if status == omui.M3dView.kActive:
148 view.setDrawColor( 13, omui.M3dView.kActiveColors )
150 view.setDrawColor( 13, omui.M3dView.kDormantColors )
152 glFT.glBegin( v1omr.MGL_TRIANGLE_FAN )
153 for i
in range(soleCount-1):
154 glFT.glVertex3f( sole[i][0] * multiplier, sole[i][1] * multiplier, sole[i][2] * multiplier )
157 glFT.glBegin( v1omr.MGL_TRIANGLE_FAN )
158 for i
in range(heelCount-1):
159 glFT.glVertex3f( heel[i][0] * multiplier, heel[i][1] * multiplier, heel[i][2] * multiplier )
166 glFT.glBegin( v1omr.MGL_LINES )
167 for i
in range(soleCount-1):
168 glFT.glVertex3f( sole[i][0] * multiplier, sole[i][1] * multiplier, sole[i][2] * multiplier )
169 glFT.glVertex3f( sole[i+1][0] * multiplier, sole[i+1][1] * multiplier, sole[i+1][2] * multiplier )
171 for i
in range(heelCount-1):
172 glFT.glVertex3f( heel[i][0] * multiplier, heel[i][1] * multiplier, heel[i][2] * multiplier )
173 glFT.glVertex3f( heel[i+1][0] * multiplier, heel[i+1][1] * multiplier, heel[i+1][2] * multiplier )
179 view.setDrawColor( om.MColor( (0.1, 0.8, 0.8, 1.0) ) )
180 view.drawText(
"Footprint", om.MPoint( 0.0, 0.0, 0.0 ), omui.M3dView.kCenter )
185 def boundingBox(self):
188 thisNode = self.thisMObject()
189 plug = om.MPlug( thisNode, footPrint.size )
190 sizeVal = plug.asMDistance()
191 multiplier = sizeVal.asCentimeters()
193 corner1 = om.MPoint( -0.17, 0.0, -0.7 )
194 corner2 = om.MPoint( 0.17, 0.0, 0.3 )
196 corner1 *= multiplier
197 corner2 *= multiplier
199 return om.MBoundingBox( corner1, corner2 )
206 class footPrintData(om.MUserData):
208 om.MUserData.__init__(self,
False)
210 self.fColor = om.MColor()
211 self.fLineList = om.MPointArray()
212 self.fTriangleList = om.MPointArray()
214 class footPrintDrawOverride(omr.MPxDrawOverride):
217 return footPrintDrawOverride(obj)
224 def __init__(self, obj):
225 omr.MPxDrawOverride.__init__(self, obj,
None,
False)
230 self.mCustomBoxDraw =
True
231 self.mCurrentBoundingBox = om.MBoundingBox()
233 def supportedDrawAPIs(self):
235 return omr.MRenderer.kOpenGL | omr.MRenderer.kDirectX11 | omr.MRenderer.kOpenGLCoreProfile
237 def isBounded(self, objPath, cameraPath):
240 def boundingBox(self, objPath, cameraPath):
241 corner1 = om.MPoint( -0.17, 0.0, -0.7 )
242 corner2 = om.MPoint( 0.17, 0.0, 0.3 )
244 multiplier = self.getMultiplier(objPath)
245 corner1 *= multiplier
246 corner2 *= multiplier
248 self.mCurrentBoundingBox.clear()
249 self.mCurrentBoundingBox.expand( corner1 )
250 self.mCurrentBoundingBox.expand( corner2 )
252 return self.mCurrentBoundingBox
254 def disableInternalBoundingBoxDraw(self):
255 return self.mCustomBoxDraw
257 def prepareForDraw(self, objPath, cameraPath, frameContext, oldData):
260 if not isinstance(data, footPrintData):
261 data = footPrintData()
264 global soleCount, sole
265 global heelCount, heel
267 fMultiplier = self.getMultiplier(objPath)
269 data.fLineList.clear()
271 for i
in range(soleCount-1):
272 data.fLineList.append( om.MPoint(sole[i][0] * fMultiplier, sole[i][1] * fMultiplier, sole[i][2] * fMultiplier) )
273 data.fLineList.append( om.MPoint(sole[i+1][0] * fMultiplier, sole[i+1][1] * fMultiplier, sole[i+1][2] * fMultiplier) )
275 for i
in range(heelCount-1):
276 data.fLineList.append( om.MPoint(heel[i][0] * fMultiplier, heel[i][1] * fMultiplier, heel[i][2] * fMultiplier) )
277 data.fLineList.append( om.MPoint(heel[i+1][0] * fMultiplier, heel[i+1][1] * fMultiplier, heel[i+1][2] * fMultiplier) )
279 data.fTriangleList.clear()
281 for i
in range(1,soleCount-1):
282 data.fTriangleList.append( om.MPoint(sole[0][0] * fMultiplier, sole[0][1] * fMultiplier, sole[0][2] * fMultiplier) )
283 data.fTriangleList.append( om.MPoint(sole[i][0] * fMultiplier, sole[i][1] * fMultiplier, sole[i][2] * fMultiplier) )
284 data.fTriangleList.append( om.MPoint(sole[i+1][0] * fMultiplier, sole[i+1][1] * fMultiplier, sole[i+1][2] * fMultiplier) )
286 for i
in range(1,heelCount-1):
287 data.fTriangleList.append( om.MPoint(heel[0][0] * fMultiplier, heel[0][1] * fMultiplier, heel[0][2] * fMultiplier) )
288 data.fTriangleList.append( om.MPoint(heel[i][0] * fMultiplier, heel[i][1] * fMultiplier, heel[i][2] * fMultiplier) )
289 data.fTriangleList.append( om.MPoint(heel[i+1][0] * fMultiplier, heel[i+1][1] * fMultiplier, heel[i+1][2] * fMultiplier) )
291 data.fColor = omr.MGeometryUtilities.wireframeColor(objPath)
295 def hasUIDrawables(self):
298 def addUIDrawables(self, objPath, drawManager, frameContext, data):
300 if not isinstance(locatordata, footPrintData):
303 drawManager.beginDrawable()
306 drawManager.setColor( locatordata.fColor )
307 drawManager.setDepthPriority(5)
309 if (frameContext.getDisplayStyle() & omr.MFrameContext.kGouraudShaded):
310 drawManager.mesh(omr.MGeometry.kTriangles, locatordata.fTriangleList)
312 drawManager.mesh(omr.MUIDrawManager.kLines, locatordata.fLineList)
315 pos = om.MPoint( 0.0, 0.0, 0.0 )
316 textColor = om.MColor( (0.1, 0.8, 0.8, 1.0) )
318 drawManager.setColor( textColor )
319 drawManager.setFontSize( omr.MUIDrawManager.kSmallFontSize )
320 drawManager.text(pos,
"Footprint", omr.MUIDrawManager.kCenter )
322 drawManager.endDrawable()
324 def getMultiplier(self, objPath):
326 footprintNode = objPath.node()
327 plug = om.MPlug(footprintNode, footPrint.size)
329 sizeVal = plug.asMDistance()
330 return sizeVal.asCentimeters()
334 def initializePlugin(obj):
335 plugin = om.MFnPlugin(obj,
"Autodesk",
"3.0",
"Any")
338 plugin.registerNode(
"footPrint", footPrint.id, footPrint.creator, footPrint.initialize, om.MPxNode.kLocatorNode, footPrint.drawDbClassification)
340 sys.stderr.write(
"Failed to register node\n")
344 omr.MDrawRegistry.registerDrawOverrideCreator(footPrint.drawDbClassification, footPrint.drawRegistrantId, footPrintDrawOverride.creator)
346 sys.stderr.write(
"Failed to register override\n")
349 def uninitializePlugin(obj):
350 plugin = om.MFnPlugin(obj)
353 plugin.deregisterNode(footPrint.id)
355 sys.stderr.write(
"Failed to deregister node\n")
359 omr.MDrawRegistry.deregisterDrawOverrideCreator(footPrint.drawDbClassification, footPrint.drawRegistrantId)
361 sys.stderr.write(
"Failed to deregister override\n")