43 import maya.api.OpenMaya
as om
44 import maya.api.OpenMayaUI
as omui
45 import maya.api.OpenMayaAnim
as oma
46 import maya.api.OpenMayaRender
as omr
50 The presence of this function tells Maya that the plugin produces, and
51 expects to be passed, objects created using the Maya Python API 2.0.
55 def matrixAsArray(matrix):
58 array.append(matrix[i])
63 sole = [ [ 0.00, 0.0, -0.70 ],
75 [ -0.15, 0.0, -0.14 ],
76 [ -0.16, 0.0, -0.25 ],
77 [ -0.17, 0.0, -0.35 ],
78 [ -0.17, 0.0, -0.46 ],
79 [ -0.16, 0.0, -0.54 ],
80 [ -0.13, 0.0, -0.61 ],
81 [ -0.09, 0.0, -0.65 ],
82 [ -0.04, 0.0, -0.69 ],
83 [ -0.00, 0.0, -0.70 ] ]
84 heel = [ [ 0.00, 0.0, 0.06 ],
100 [ -0.00, 0.0, 0.06 ] ]
110 class footPrint(omui.MPxLocatorNode):
111 id = om.MTypeId( 0x00080033 )
112 drawDbClassification =
"drawdb/geometry/footPrint_GeometryOverride"
113 drawRegistrantId =
"FootprintNode_GeometryOverridePlugin"
123 unitFn = om.MFnUnitAttribute()
125 footPrint.size = unitFn.create(
"size",
"sz", om.MFnUnitAttribute.kDistance )
126 unitFn.default = om.MDistance(1.0)
128 om.MPxNode.addAttribute( footPrint.size )
131 omui.MPxLocatorNode.__init__(self)
133 def compute(self, plug, data):
136 def draw(self, view, path, style, status):
139 thisNode = self.thisMObject()
140 plug = om.MPlug( thisNode, footPrint.size )
141 sizeVal = plug.asMDistance()
142 multiplier = sizeVal.asCentimeters()
144 global sole, soleCount
145 global heel, heelCount
150 import maya.OpenMayaRender
as v1omr
151 glRenderer = v1omr.MHardwareRenderer.theRenderer()
152 glFT = glRenderer.glFunctionTable()
154 if ( style == omui.M3dView.kFlatShaded )
or ( style == omui.M3dView.kGouraudShaded ):
157 glFT.glPushAttrib( v1omr.MGL_CURRENT_BIT )
160 glFT.glDisable( v1omr.MGL_CULL_FACE )
162 if status == omui.M3dView.kActive:
163 view.setDrawColor( 13, omui.M3dView.kActiveColors )
165 view.setDrawColor( 13, omui.M3dView.kDormantColors )
167 glFT.glBegin( v1omr.MGL_TRIANGLE_FAN )
168 for i
in xrange(soleCount-1):
169 glFT.glVertex3f( sole[i][0] * multiplier, sole[i][1] * multiplier, sole[i][2] * multiplier )
172 glFT.glBegin( v1omr.MGL_TRIANGLE_FAN )
173 for i
in xrange(heelCount-1):
174 glFT.glVertex3f( heel[i][0] * multiplier, heel[i][1] * multiplier, heel[i][2] * multiplier )
181 glFT.glBegin( v1omr.MGL_LINES )
182 for i
in xrange(soleCount-1):
183 glFT.glVertex3f( sole[i][0] * multiplier, sole[i][1] * multiplier, sole[i][2] * multiplier )
184 glFT.glVertex3f( sole[i+1][0] * multiplier, sole[i+1][1] * multiplier, sole[i+1][2] * multiplier )
186 for i
in xrange(heelCount-1):
187 glFT.glVertex3f( heel[i][0] * multiplier, heel[i][1] * multiplier, heel[i][2] * multiplier )
188 glFT.glVertex3f( heel[i+1][0] * multiplier, heel[i+1][1] * multiplier, heel[i+1][2] * multiplier )
196 def boundingBox(self):
199 thisNode = self.thisMObject()
200 plug = om.MPlug( thisNode, footPrint.size )
201 sizeVal = plug.asMDistance()
202 multiplier = sizeVal.asCentimeters()
204 corner1 = om.MPoint( -0.17, 0.0, -0.7 )
205 corner2 = om.MPoint( 0.17, 0.0, 0.3 )
207 corner1 *= multiplier
208 corner2 *= multiplier
210 return om.MBoundingBox( corner1, corner2 )
218 class footPrintGeometryOverride(omr.MPxGeometryOverride):
219 colorParameterName_ =
"solidColor"
220 wireframeHeelItemName_ =
"heelLocatorWires"
221 wireframeSoleItemName_ =
"soleLocatorWires"
222 shadedHeelItemName_ =
"heelLocatorTriangles"
223 shadedSoleItemName_ =
"soleLocatorTriangles"
227 return footPrintGeometryOverride(obj)
229 def __init__(self, obj):
230 omr.MPxGeometryOverride.__init__(self, obj)
231 self. mSolidUIShader =
None
232 self.mLocatorNode = obj
233 self.mMultiplier = 0.0
234 self.mMultiplierChanged =
True
236 shaderMgr = omr.MRenderer.getShaderManager()
238 self.mSolidUIShader = shaderMgr.getStockShader(omr.MShaderManager.k3dSolidShader)
241 if self.mSolidUIShader:
242 shaderMgr = omr.MRenderer.getShaderManager()
244 shaderMgr.releaseShader(self.mSolidUIShader)
246 def supportedDrawAPIs(self):
248 return omr.MRenderer.kOpenGL | omr.MRenderer.kOpenGLCoreProfile | omr.MRenderer.kDirectX11
250 def hasUIDrawables(self):
254 plug = om.MPlug(self.mLocatorNode, footPrint.size)
257 sizeVal = plug.asMDistance()
258 newScale = sizeVal.asCentimeters()
260 if newScale != self.mMultiplier:
261 self.mMultiplier = newScale
262 self.mMultiplierChanged =
True
267 def isIndexingDirty(self, item):
270 def isStreamDirty(self, desc):
271 return self.mMultiplierChanged
273 def updateRenderItems(self, dagPath, renderList ):
277 ( (footPrintGeometryOverride.wireframeHeelItemName_,
278 footPrintGeometryOverride.wireframeSoleItemName_),
279 omr.MGeometry.kLineStrip,
280 omr.MGeometry.kWireframe),
283 ( (footPrintGeometryOverride.shadedHeelItemName_,
284 footPrintGeometryOverride.shadedSoleItemName_),
285 omr.MGeometry.kTriangleStrip,
286 omr.MGeometry.kShaded)
289 for itemNameList, geometryType, drawMode
in fullItemList:
290 for itemName
in itemNameList:
292 index = renderList.indexOf(itemName)
294 renderItem = omr.MRenderItem.create(
296 omr.MRenderItem.DecorationItem,
298 renderItem.setDrawMode(drawMode)
299 renderItem.setDepthPriority(5)
301 renderList.append(renderItem)
303 renderItem = renderList[index]
306 if self.mSolidUIShader:
307 self.mSolidUIShader.setParameter(footPrintGeometryOverride.colorParameterName_, omr.MGeometryUtilities.wireframeColor(dagPath))
308 renderItem.setShader(self.mSolidUIShader)
309 renderItem.enable(
True)
311 def populateGeometry(self, requirements, renderItems, data):
312 vertexBufferDescriptorList = requirements.vertexRequirements()
314 for vertexBufferDescriptor
in vertexBufferDescriptorList:
315 if vertexBufferDescriptor.semantic == omr.MGeometry.kPosition:
316 verticesCount = soleCount+heelCount
317 verticesBuffer = data.createVertexBuffer(vertexBufferDescriptor)
318 verticesPositionDataAddress = verticesBuffer.acquire(verticesCount,
True)
319 verticesPositionData = ((ctypes.c_float * 3)*verticesCount).from_address(verticesPositionDataAddress)
321 verticesPointerOffset = 0
325 for vtxList
in (heel, sole):
327 verticesPositionData[verticesPointerOffset][0] = vtx[0] * self.mMultiplier
328 verticesPositionData[verticesPointerOffset][1] = vtx[1] * self.mMultiplier
329 verticesPositionData[verticesPointerOffset][2] = vtx[2] * self.mMultiplier
330 verticesPointerOffset += 1
332 verticesBuffer.commit(verticesPositionDataAddress)
336 for item
in renderItems:
347 if item.name() == footPrintGeometryOverride.wireframeHeelItemName_:
349 elif item.name() == footPrintGeometryOverride.wireframeSoleItemName_:
350 startIndex = heelCount
352 elif item.name() == footPrintGeometryOverride.shadedHeelItemName_:
353 numIndex = heelCount - 2
355 endIndex = heelCount - 2
357 elif item.name() == footPrintGeometryOverride.shadedSoleItemName_:
358 startIndex = heelCount
359 endIndex = heelCount + soleCount - 2
360 numIndex = soleCount - 2
364 indexBuffer = data.createIndexBuffer(omr.MGeometry.kUnsignedInt32)
365 indicesAddress = indexBuffer.acquire(numIndex,
True)
366 indices = (ctypes.c_uint * numIndex).from_address(indicesAddress)
372 indices[i] = startIndex + i
376 indices[i] = startIndex + i/2
378 indices[i+1] = endIndex - i/2
381 indexBuffer.commit(indicesAddress)
382 item.associateWithIndexBuffer(indexBuffer)
384 mMultiplierChanged =
False
386 def initializePlugin(obj):
387 plugin = om.MFnPlugin(obj,
"Autodesk",
"3.0",
"Any")
390 plugin.registerNode(
"footPrint_GeometryOverride", footPrint.id, footPrint.creator, footPrint.initialize, om.MPxNode.kLocatorNode, footPrint.drawDbClassification)
392 sys.stderr.write(
"Failed to register node\n")
396 omr.MDrawRegistry.registerGeometryOverrideCreator(footPrint.drawDbClassification, footPrint.drawRegistrantId, footPrintGeometryOverride.creator)
398 sys.stderr.write(
"Failed to register override\n")
401 def uninitializePlugin(obj):
402 plugin = om.MFnPlugin(obj)
405 plugin.deregisterNode(footPrint.id)
407 sys.stderr.write(
"Failed to deregister node\n")
411 omr.MDrawRegistry.deregisterGeometryOverrideCreator(footPrint.drawDbClassification, footPrint.drawRegistrantId)
413 sys.stderr.write(
"Failed to deregister override\n")