11 from builtins
import range
13 import maya.api.OpenMaya
as om
14 import maya.api.OpenMayaUI
as omui
15 import maya.api.OpenMayaRender
as omr
19 The presence of this function tells Maya that the plugin produces, and
20 expects to be passed, objects created using the Maya Python API 2.0.
39 class uiDrawManager(omui.MPxLocatorNode):
40 id = om.MTypeId(0x0008006C)
41 drawDbClassification =
"drawdb/geometry/uiDrawManager_py"
42 drawRegistrantId =
"uiDrawManagerPlugin_py"
49 aPrimitiveColor =
None
50 aPrimitiveTransparency =
None
78 aTextBoxTransparency =
None
86 aLineStartPoint =
None
95 aQuadVertex = [
None,
None,
None,
None]
108 aSubdivisionsAxis = 10
109 aSubdivisionsHeight = 4
110 aNumSubdivisions = 10
113 aConeDirection =
None
122 omui.MPxLocatorNode.__init__(self)
126 return uiDrawManager()
130 nAttr = om.MFnNumericAttribute()
131 eAttr = om.MFnEnumAttribute()
132 typedAttr = om.MFnTypedAttribute()
135 uiDrawManager.aUIType = eAttr.create(
"uiType",
"ut", kText)
136 eAttr.addField(
"text", kText)
137 eAttr.addField(
"line", kLine)
138 eAttr.addField(
"point", kPoint)
139 eAttr.addField(
"rect", kRect)
140 eAttr.addField(
"quad", kQuad)
141 eAttr.addField(
"sphere", kSphere)
142 eAttr.addField(
"circle", kCircle)
143 eAttr.addField(
"arc", kArc)
144 eAttr.addField(
"sphere2", kSphere2)
145 eAttr.addField(
"circle2", kCircle2)
146 eAttr.addField(
"arc2", kArc2)
147 eAttr.addField(
"cone", kCone)
148 eAttr.addField(
"cylinder", kCylinder)
149 eAttr.addField(
"capsule", kCapsule)
151 om.MPxNode.addAttribute(uiDrawManager.aUIType)
154 uiDrawManager.aSelectability = eAttr.create(
"selectability",
"st", omr.MUIDrawManager.kAutomatic)
155 eAttr.addField(
"Unselectable", omr.MUIDrawManager.kNonSelectable)
156 eAttr.addField(
"Selectable", omr.MUIDrawManager.kSelectable)
157 eAttr.addField(
"Automatic", omr.MUIDrawManager.kAutomatic)
158 om.MPxNode.addAttribute(uiDrawManager.aSelectability)
161 uiDrawManager.aPrimitiveColor = nAttr.create(
"primitiveColor",
"pc", om.MFnNumericData.k3Float)
162 nAttr.default = (1.0, 0.0, 0.0)
163 nAttr.usedAsColor =
True
164 om.MPxNode.addAttribute(uiDrawManager.aPrimitiveColor)
167 uiDrawManager.aPrimitiveTransparency = nAttr.create(
"primitiveTransparency",
"pt", om.MFnNumericData.kFloat, 0.0)
168 nAttr.setSoftMin(0.0)
169 nAttr.setSoftMax(1.0)
170 om.MPxNode.addAttribute(uiDrawManager.aPrimitiveTransparency)
173 uiDrawManager.aLineWidth = nAttr.create(
"lineWidth",
"lw", om.MFnNumericData.kFloat, 2.0)
174 om.MPxNode.addAttribute(uiDrawManager.aLineWidth)
176 uiDrawManager.aLineStyle = eAttr.create(
"lineStyle",
"ls", omr.MUIDrawManager.kSolid)
177 eAttr.addField(
"solid", omr.MUIDrawManager.kSolid)
178 eAttr.addField(
"shortdotted", omr.MUIDrawManager.kShortDotted)
179 eAttr.addField(
"shortdashed", omr.MUIDrawManager.kShortDashed)
180 eAttr.addField(
"dashed", omr.MUIDrawManager.kDashed)
181 eAttr.addField(
"dotted", omr.MUIDrawManager.kDotted)
182 om.MPxNode.addAttribute(uiDrawManager.aLineStyle)
185 uiDrawManager.aIsFilled = nAttr.create(
"isFilled",
"if", om.MFnNumericData.kBoolean, 0)
186 om.MPxNode.addAttribute(uiDrawManager.aIsFilled)
189 uiDrawManager.aRadius = nAttr.create(
"radius",
"ra", om.MFnNumericData.kDouble, 1.0)
190 om.MPxNode.addAttribute(uiDrawManager.aRadius)
193 uiDrawManager.aHeight = nAttr.create(
"height",
"he", om.MFnNumericData.kDouble, 1.0)
194 om.MPxNode.addAttribute(uiDrawManager.aHeight)
197 uiDrawManager.aDraw2D = nAttr.create(
"draw2D",
"d2", om.MFnNumericData.kBoolean, 0)
198 om.MPxNode.addAttribute(uiDrawManager.aDraw2D)
200 uiDrawManager.aPosition = nAttr.create(
"position",
"pos", om.MFnNumericData.k3Double)
201 nAttr.default = (0.0, 0.0, 0.001)
202 om.MPxNode.addAttribute(uiDrawManager.aPosition)
205 stringFn = om.MFnStringData()
206 defaultText = stringFn.create(
"uiDrawManager-Text")
207 uiDrawManager.aText = typedAttr.create(
"text",
"t", om.MFnData.kString, defaultText)
208 om.MPxNode.addAttribute(uiDrawManager.aText)
210 uiDrawManager.aTextFontSize = nAttr.create(
"textFontSize",
"tfs", om.MFnNumericData.kInt, omr.MUIDrawManager.kDefaultFontSize)
213 om.MPxNode.addAttribute(uiDrawManager.aTextFontSize)
215 uiDrawManager.fFontList = omr.MUIDrawManager.getFontList()
216 if len(uiDrawManager.fFontList) == 0:
217 sys.stderr.write(
"No font available!\n")
219 uiDrawManager.aFontFaceName = eAttr.create(
"fontFaceName",
"ffn", 0)
220 for i
in range(len(uiDrawManager.fFontList)):
221 faceName = uiDrawManager.fFontList[i]
222 eAttr.addField(faceName, i)
223 om.MPxNode.addAttribute(uiDrawManager.aFontFaceName)
225 uiDrawManager.aTextAlignment = eAttr.create(
"textAlignment",
"ta", omr.MUIDrawManager.kLeft)
226 eAttr.addField(
"left", omr.MUIDrawManager.kLeft)
227 eAttr.addField(
"center", omr.MUIDrawManager.kCenter)
228 eAttr.addField(
"right", omr.MUIDrawManager.kRight)
229 om.MPxNode.addAttribute(uiDrawManager.aTextAlignment)
231 uiDrawManager.eTextIncline = eAttr.create(
"textIncline",
"tic", omr.MUIDrawManager.kInclineNormal)
232 eAttr.addField(
"normal", omr.MUIDrawManager.kInclineNormal)
233 eAttr.addField(
"italic", omr.MUIDrawManager.kInclineItalic)
234 om.MPxNode.addAttribute(uiDrawManager.eTextIncline)
236 uiDrawManager.aTextWeight = eAttr.create(
"textWeight",
"tw", omr.MUIDrawManager.kWeightBold)
237 eAttr.addField(
"light", omr.MUIDrawManager.kWeightLight)
238 eAttr.addField(
"bold", omr.MUIDrawManager.kWeightBold)
239 om.MPxNode.addAttribute(uiDrawManager.aTextWeight)
241 uiDrawManager.aTextStretch = nAttr.create(
"textStretch",
"ts", om.MFnNumericData.kInt, omr.MUIDrawManager.kStretchUnstretched)
244 om.MPxNode.addAttribute(uiDrawManager.aTextStretch)
246 uiDrawManager.aTextLine = eAttr.create(
"textLine",
"tl", 0)
247 eAttr.addField(
"none", 0)
248 eAttr.addField(
"overline", omr.MUIDrawManager.kLineOverline)
249 eAttr.addField(
"underline", omr.MUIDrawManager.kLineUnderline)
250 eAttr.addField(
"strikeout", omr.MUIDrawManager.kLineStrikeoutLine)
251 om.MPxNode.addAttribute(uiDrawManager.aTextLine)
253 uiDrawManager.aTextBoxSize = nAttr.create(
"textBoxSize",
"tbs", om.MFnNumericData.k2Int)
254 nAttr.default = (0, 0)
255 om.MPxNode.addAttribute(uiDrawManager.aTextBoxSize)
257 uiDrawManager.aTextBoxColor = nAttr.create(
"textBoxColor",
"tbc", om.MFnNumericData.k3Float)
258 nAttr.default = (0.0, 1.0, 1.0)
259 nAttr.usedAsColor =
True
260 om.MPxNode.addAttribute(uiDrawManager.aTextBoxColor)
262 uiDrawManager.aTextBoxTransparency = nAttr.create(
"textBoxTransparency",
"tbt", om.MFnNumericData.kFloat, 0.0)
263 nAttr.setSoftMin(0.0)
264 nAttr.setSoftMax(1.0)
265 om.MPxNode.addAttribute(uiDrawManager.aTextBoxTransparency)
268 uiDrawManager.aPointSize = nAttr.create(
"pointSize",
"ps", om.MFnNumericData.kFloat, 2.0)
269 om.MPxNode.addAttribute(uiDrawManager.aPointSize)
272 uiDrawManager.aLineStartPoint = nAttr.create(
"lineStartPoint",
"lsp", om.MFnNumericData.k3Double)
273 nAttr.default = (0.0, 0.0, 0.0)
274 om.MPxNode.addAttribute(uiDrawManager.aLineStartPoint)
276 uiDrawManager.aLineEndPoint = nAttr.create(
"lineEndPoint",
"lep", om.MFnNumericData.k3Double)
277 nAttr.default = (1.0, 1.0, 1.0)
278 om.MPxNode.addAttribute(uiDrawManager.aLineEndPoint)
281 uiDrawManager.aRectUp = nAttr.create(
"rectUp",
"ru", om.MFnNumericData.k3Double)
282 nAttr.default = (0.0, 1.0, 0.0)
283 om.MPxNode.addAttribute(uiDrawManager.aRectUp)
285 uiDrawManager.aRectNormal = nAttr.create(
"rectNormal",
"rn", om.MFnNumericData.k3Double)
286 nAttr.default = (0.0, 0.0, 1.0)
287 om.MPxNode.addAttribute(uiDrawManager.aRectNormal)
289 uiDrawManager.aRectScale = nAttr.create(
"rectScale",
"rs", om.MFnNumericData.k2Double)
290 nAttr.default = (1.0, 1.0)
291 om.MPxNode.addAttribute(uiDrawManager.aRectScale)
294 defaultPosition = [ (0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (1.0, 1.0, 0.0), (0.0, 1.0, 0.0) ]
296 fullName =
"quadVertex" + str(i)
297 shortName =
"qv" + str(i)
298 uiDrawManager.aQuadVertex[i] = nAttr.create(fullName, shortName, om.MFnNumericData.k3Double)
299 nAttr.default = defaultPosition[i]
300 om.MPxNode.addAttribute(uiDrawManager.aQuadVertex[i])
303 uiDrawManager.aCircleNormal = nAttr.create(
"circleNormal",
"cn", om.MFnNumericData.k3Double)
304 nAttr.default = (0.0, 0.0, 1.0)
305 om.MPxNode.addAttribute(uiDrawManager.aCircleNormal)
308 uiDrawManager.aArcStart = nAttr.create(
"arcStartVector",
"asv", om.MFnNumericData.k3Double)
309 nAttr.default = (1.0, 0.0, 0.0)
310 om.MPxNode.addAttribute(uiDrawManager.aArcStart)
312 uiDrawManager.aArcEnd = nAttr.create(
"arcEndVector",
"aev", om.MFnNumericData.k3Double)
313 nAttr.default = (0.0, 1.0, 0.0)
314 om.MPxNode.addAttribute(uiDrawManager.aArcEnd)
316 uiDrawManager.aArcNormal = nAttr.create(
"arcNormal",
"an", om.MFnNumericData.k3Double)
317 nAttr.default = (0.0, 0.0, 1.0)
318 om.MPxNode.addAttribute(uiDrawManager.aArcNormal)
321 uiDrawManager.aSubdivisionsAxis = nAttr.create(
"subdivisionAxis",
"sda", om.MFnNumericData.kInt, 10)
322 om.MPxNode.addAttribute(uiDrawManager.aSubdivisionsAxis)
324 uiDrawManager.aSubdivisionsHeight = nAttr.create(
"subdivisionsHeight",
"sdh", om.MFnNumericData.kInt, 4)
325 om.MPxNode.addAttribute(uiDrawManager.aSubdivisionsHeight)
327 uiDrawManager.aNumSubdivisions = nAttr.create(
"numSubdivisions",
"sdn", om.MFnNumericData.kInt, 10)
328 om.MPxNode.addAttribute(uiDrawManager.aNumSubdivisions)
331 uiDrawManager.aConeDirection = nAttr.create(
"coneDirection",
"cd", om.MFnNumericData.k3Double)
332 nAttr.default = (0.0, 1.0, 0.0)
333 om.MPxNode.addAttribute(uiDrawManager.aConeDirection)
336 uiDrawManager.aCylinderUp = nAttr.create(
"cylinderUp",
"cu", om.MFnNumericData.k3Double)
337 nAttr.default = (0.0, 1.0, 0.0)
338 om.MPxNode.addAttribute(uiDrawManager.aCylinderUp)
341 uiDrawManager.aCapsuleUp = nAttr.create(
"capsuleUp",
"cau", om.MFnNumericData.k3Double)
342 nAttr.default = (0.0, 1.0, 0.0)
343 om.MPxNode.addAttribute(uiDrawManager.aCapsuleUp)
353 class uiDrawManagerData(om.MUserData):
355 om.MUserData.__init__(self,
False)
357 self.fSelectability = omr.MUIDrawManager.kAutomatic
358 self.fColor = om.MColor((1., 0., 0., 1.))
360 self.fLineStyle = omr.MUIDrawManager.kSolid
361 self.fIsFilled =
False
365 self.fPosition = om.MPoint(0.0, 0.0, 0.001)
367 self.fText =
"uiDrawManager-Text"
368 self.fTextFontSize = omr.MUIDrawManager.kDefaultFontSize
369 self.fFontFaceIndex = 0
370 self.fTextAlignment = omr.MUIDrawManager.kLeft
371 self.fTextIncline = omr.MUIDrawManager.kInclineNormal
372 self.fTextWeight = omr.MUIDrawManager.kWeightBold
373 self.fTextStretch = omr.MUIDrawManager.kStretchUnstretched
375 self.fTextBoxSize = [0, 0]
376 self.fTextBoxColor = om.MColor((0., 1., 1., 1.))
380 self.fLineStartPoint = om.MPoint(0.0, 0.0, 0.0)
381 self.fLineEndPoint = om.MPoint(1.0, 1.0, 1.0)
383 self.fRectUp = om.MVector(0.0, 1.0, 0.0)
384 self.fRectNormal = om.MVector(0.0, 0.0, 1.0)
385 self.fRectScale = [1., 1.]
387 self.fQuadVertex = [ om.MPoint(0.0, 0.0, 0.0), om.MPoint(1.0, 0.0, 0.0), om.MPoint(1.0, 1.0, 0.0), om.MPoint(0.0, 1.0, 0.0) ]
389 self.fCircleNormal = om.MVector(0.0, 0.0, 1.0)
391 self.fArcStart = om.MVector(1.0, 0.0, 0.0)
392 self.fArcEnd = om.MVector(0.0, 1.0, 0.0)
393 self.fArcNormal = om.MVector(0.0, 0.0, 1.0)
396 self.fSubdivisionsAxis = 10
397 self.fSubdivisionsHeight = 4
398 self.fNumSubdivisions = 10
401 self.fConeDirection = om.MVector(0.0, 0.0, 1.0)
403 self.fCylinderUp = om.MVector(0.0, 1.0, 0.0)
405 self.fCapsuleUp = om.MVector(0.0, 0.0, 1.0)
409 class uiDrawManagerDrawOverride(omr.MPxDrawOverride):
410 def __init__(self, obj):
411 omr.MPxDrawOverride.__init__(self, obj,
None)
415 return uiDrawManagerDrawOverride(obj)
417 def supportedDrawAPIs(self):
418 return (omr.MRenderer.kOpenGL | omr.MRenderer.kDirectX11 | omr.MRenderer.kOpenGLCoreProfile)
420 def isBounded(self, objPath, cameraPath):
423 def boundingBox(self, objPath, cameraPath):
424 return om.MBoundingBox()
426 def prepareForDraw(self, objPath, cameraPath, frameContext, oldData):
428 if not isinstance(data, uiDrawManagerData):
429 data = uiDrawManagerData()
431 uiDrawManagerNode = objPath.node()
432 if uiDrawManagerNode.isNull():
436 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aUIType)
437 data.fUIType = plug.asShort()
441 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aSelectability)
442 data.fSelectability = plug.asShort()
445 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aPrimitiveColor)
447 nData = om.MFnNumericData(o)
448 data.fColor = om.MColor(nData.getData())
451 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aPrimitiveTransparency)
452 data.fColor.a = 1.0 - plug.asFloat()
455 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aLineWidth)
456 data.fLineWidth = plug.asFloat()
459 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aLineStyle)
460 data.fLineStyle = plug.asShort()
463 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aIsFilled)
464 data.fIsFilled = plug.asBool()
467 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aRadius)
468 data.fRadius = plug.asDouble()
471 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aHeight)
472 data.fHeight = plug.asDouble()
475 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aDraw2D)
476 data.fDraw2D = plug.asBool()
479 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aPosition)
481 nData = om.MFnNumericData(o)
482 data.fPosition = om.MPoint(nData.getData())
483 data.fPosition.w = 1.0
486 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aSubdivisionsAxis)
487 data.fSubdivisionAxis = plug.asInt()
489 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aSubdivisionsHeight)
490 data.fSubdivisionHeight = plug.asInt()
492 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aNumSubdivisions)
493 data.fNumSubdivisions = plug.asInt()
495 if data.fUIType == kText:
497 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aText)
498 data.fText = plug.asString()
501 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aTextFontSize)
502 data.fTextFontSize = max(plug.asInt(), 0)
505 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aFontFaceName)
506 data.fFontFaceIndex = plug.asInt()
509 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aTextAlignment)
510 data.fTextAlignment = plug.asShort()
513 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.eTextIncline)
514 data.fTextIncline = plug.asInt()
517 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aTextWeight)
518 data.fTextWeight = plug.asInt()
521 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aTextStretch)
522 data.fTextStretch = plug.asInt()
525 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aTextLine)
526 data.fTextLine = plug.asInt()
529 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aTextBoxSize)
531 nData = om.MFnNumericData(o)
532 data.fTextBoxSize = nData.getData()
535 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aTextBoxColor)
537 nData = om.MFnNumericData(o)
538 data.fTextBoxColor = om.MColor(nData.getData())
541 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aTextBoxTransparency)
542 data.fTextBoxColor.a = 1.0 - plug.asFloat()
544 elif data.fUIType == kPoint:
546 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aPointSize)
547 data.fPointSize = plug.asFloat()
549 elif data.fUIType == kLine:
551 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aLineStartPoint)
553 nData = om.MFnNumericData(o)
554 data.fLineStartPoint = om.MPoint(nData.getData())
555 data.fLineStartPoint.w = 1.0
558 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aLineEndPoint)
560 nData = om.MFnNumericData(o)
561 data.fLineEndPoint = om.MPoint(nData.getData())
562 data.fLineEndPoint.w = 1.0
564 elif data.fUIType == kRect:
566 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aRectUp)
568 nData = om.MFnNumericData(o)
569 data.fRectUp = om.MVector(nData.getData())
572 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aRectNormal)
574 nData = om.MFnNumericData(o)
575 data.fRectNormal = om.MVector(nData.getData())
578 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aRectScale)
580 nData = om.MFnNumericData(o)
581 data.fRectScale = nData.getData()
583 elif data.fUIType == kQuad:
586 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aQuadVertex[i])
588 nData = om.MFnNumericData(o)
589 data.fQuadVertex[i] = om.MPoint(nData.getData())
591 elif data.fUIType == kCircle:
593 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aCircleNormal)
595 nData = om.MFnNumericData(o)
596 data.fCircleNormal = om.MVector(nData.getData())
598 elif data.fUIType == kArc:
600 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aArcStart)
602 nData = om.MFnNumericData(o)
603 data.fArcStart = om.MVector(nData.getData())
606 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aArcEnd)
608 nData = om.MFnNumericData(o)
609 data.fArcEnd = om.MVector(nData.getData())
612 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aArcNormal)
614 nData = om.MFnNumericData(o)
615 data.fArcNormal = om.MVector(nData.getData())
617 elif data.fUIType == kSphere:
620 elif data.fUIType == kCone:
621 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aConeDirection)
623 nData = om.MFnNumericData(o)
624 data.fConeDirection = om.MVector(nData.getData())
625 elif data.fUIType == kCylinder:
626 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aCylinderUp)
628 nData = om.MFnNumericData(o)
629 data.fCylinderUp = om.MVector(nData.getData())
630 elif data.fUIType == kCapsule:
631 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aCapsuleUp)
633 nData = om.MFnNumericData(o)
634 data.fCapsuleUp = om.MVector(nData.getData())
635 elif data.fUIType == kSphere2:
637 elif data.fUIType == kCircle2:
639 elif data.fUIType == kArc2:
641 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aArcStart)
643 nData = om.MFnNumericData(o)
644 data.fArcStart = om.MVector(nData.getData())
647 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aArcEnd)
649 nData = om.MFnNumericData(o)
650 data.fArcEnd = om.MVector(nData.getData())
653 plug = om.MPlug(uiDrawManagerNode, uiDrawManager.aArcNormal)
655 nData = om.MFnNumericData(o)
656 data.fArcNormal = om.MVector(nData.getData())
658 sys.stderr.write(
"unhandled ui type.\n")
662 def hasUIDrawables(self):
665 def addUIDrawables(self, objPath, drawManager, frameContext, data):
666 if not isinstance(data, uiDrawManagerData):
669 if data.fUIType == kText:
673 drawManager.beginDrawable(data.fSelectability)
675 drawManager.setColor(data.fColor)
676 drawManager.setFontSize(data.fTextFontSize)
677 drawManager.setFontIncline(data.fTextIncline)
678 drawManager.setFontWeight(data.fTextWeight)
679 drawManager.setFontStretch(data.fTextStretch)
680 drawManager.setFontLine(data.fTextLine)
682 faceName = uiDrawManager.fFontList[data.fFontFaceIndex]
683 drawManager.setFontName(faceName)
685 boxSize = data.fTextBoxSize
686 if boxSize[0] + boxSize[1] == 0:
692 drawManager.text2d(data.fPosition, data.fText, data.fTextAlignment, boxSize, data.fTextBoxColor,
False)
696 drawManager.text(data.fPosition, data.fText, data.fTextAlignment, boxSize, data.fTextBoxColor,
False)
698 drawManager.endDrawable()
700 elif data.fUIType == kLine:
701 drawManager.beginDrawable(data.fSelectability)
703 drawManager.setColor(data.fColor)
704 drawManager.setLineWidth(data.fLineWidth)
705 drawManager.setLineStyle(data.fLineStyle)
708 drawManager.line2d(data.fLineStartPoint, data.fLineEndPoint)
711 drawManager.line(data.fLineStartPoint, data.fLineEndPoint)
713 drawManager.endDrawable()
715 elif data.fUIType == kPoint:
716 drawManager.beginDrawable(data.fSelectability)
718 drawManager.setColor(data.fColor)
719 drawManager.setPointSize(data.fPointSize)
722 drawManager.point2d(data.fPosition)
725 drawManager.point(data.fPosition)
727 drawManager.endDrawable()
729 elif data.fUIType == kRect:
730 drawManager.beginDrawable(data.fSelectability)
732 drawManager.setColor(data.fColor)
733 drawManager.setLineWidth(data.fLineWidth)
734 drawManager.setLineStyle(data.fLineStyle)
740 drawManager.rect2d(data.fPosition, data.fRectUp, data.fRectScale[0], data.fRectScale[1], data.fIsFilled)
744 drawManager.rect(data.fPosition, data.fRectUp, data.fRectNormal, data.fRectScale[0], data.fRectScale[1], data.fIsFilled)
746 drawManager.endDrawable()
748 elif data.fUIType == kQuad:
749 drawManager.beginDrawable(data.fSelectability)
751 drawManager.setColor(data.fColor)
752 drawManager.setLineWidth(data.fLineWidth)
753 drawManager.setLineStyle(data.fLineStyle)
756 mode = omr.MUIDrawManager.kClosedLine
758 mode = omr.MUIDrawManager.kTriStrip
763 index = om.MUintArray()
770 position = om.MPointArray()
772 position.append(data.fQuadVertex[i])
776 drawManager.mesh2d(mode, position,
None, index)
779 drawManager.mesh(mode, position,
None,
None, index)
781 drawManager.endDrawable()
783 elif data.fUIType == kSphere:
784 drawManager.beginDrawable(data.fSelectability)
786 drawManager.setColor(data.fColor)
787 drawManager.setLineWidth(data.fLineWidth)
788 drawManager.setLineStyle(data.fLineStyle)
790 drawManager.sphere(data.fPosition, data.fRadius, data.fIsFilled)
792 drawManager.endDrawable()
794 elif data.fUIType == kCircle:
795 drawManager.beginDrawable(data.fSelectability)
797 drawManager.setColor(data.fColor)
798 drawManager.setLineWidth(data.fLineWidth)
799 drawManager.setLineStyle(data.fLineStyle)
803 drawManager.circle2d(data.fPosition, data.fRadius, data.fIsFilled)
806 drawManager.circle(data.fPosition, data.fCircleNormal, data.fRadius, data.fIsFilled)
808 drawManager.endDrawable()
810 elif data.fUIType == kArc:
811 drawManager.beginDrawable(data.fSelectability)
813 drawManager.setColor(data.fColor)
814 drawManager.setLineWidth(data.fLineWidth)
815 drawManager.setLineStyle(data.fLineStyle)
820 drawManager.arc2d(data.fPosition, data.fArcStart, data.fArcEnd, data.fRadius, data.fIsFilled)
825 drawManager.arc(data.fPosition, data.fArcStart, data.fArcEnd, data.fArcNormal, data.fRadius, data.fIsFilled)
827 drawManager.endDrawable()
828 elif data.fUIType == kSphere2:
829 drawManager.beginDrawable(data.fSelectability)
831 drawManager.setColor(data.fColor)
832 drawManager.setLineWidth(data.fLineWidth)
833 drawManager.setLineStyle(data.fLineStyle)
835 drawManager.sphere(data.fPosition, data.fRadius, data.fSubdivisionAxis, data.fSubdivisionHeight, data.fIsFilled)
837 drawManager.endDrawable()
838 elif data.fUIType == kCircle2:
839 drawManager.beginDrawable(data.fSelectability)
841 drawManager.setColor(data.fColor)
842 drawManager.setLineWidth(data.fLineWidth)
843 drawManager.setLineStyle(data.fLineStyle)
847 drawManager.circle2d(data.fPosition, data.fRadius, data.fNumSubdivisions, data.fIsFilled)
850 drawManager.circle(data.fPosition, data.fCircleNormal, data.fRadius, data.fNumSubdivisions, data.fIsFilled)
852 drawManager.endDrawable()
853 elif data.fUIType == kArc2:
854 drawManager.beginDrawable(data.fSelectability)
856 drawManager.setColor(data.fColor)
857 drawManager.setLineWidth(data.fLineWidth)
858 drawManager.setLineStyle(data.fLineStyle)
863 drawManager.arc2d(data.fPosition, data.fArcStart, data.fArcEnd, data.fRadius, data.fNumSubdivisions, data.fIsFilled)
868 drawManager.arc(data.fPosition, data.fArcStart, data.fArcEnd, data.fArcNormal, data.fRadius, data.fNumSubdivisions, data.fIsFilled)
870 drawManager.endDrawable()
871 elif data.fUIType == kCone:
872 drawManager.beginDrawable(data.fSelectability)
874 drawManager.setColor(data.fColor)
875 drawManager.setLineWidth(data.fLineWidth)
876 drawManager.setLineStyle(data.fLineStyle)
878 drawManager.cone(data.fPosition, data.fConeDirection, data.fRadius, data.fNumSubdivisions, data.fIsFilled)
880 drawManager.endDrawable()
881 elif data.fUIType == kCylinder:
882 drawManager.beginDrawable(data.fSelectability)
884 drawManager.setColor(data.fColor)
885 drawManager.setLineWidth(data.fLineWidth)
886 drawManager.setLineStyle(data.fLineStyle)
888 drawManager.cylinder(data.fPosition, data.fCylinderUp, data.fRadius, data.fHeight, data.fSubdivisionAxis, data.fIsFilled)
890 drawManager.endDrawable()
891 elif data.fUIType == kCapsule:
892 drawManager.beginDrawable(data.fSelectability)
894 drawManager.setColor(data.fColor)
895 drawManager.setLineWidth(data.fLineWidth)
896 drawManager.setLineStyle(data.fLineStyle)
898 drawManager.capsule(data.fPosition, om.MVector(0.0, 1.0, 0.0), data.fRadius, data.fHeight, 36, 20, data.fIsFilled)
900 drawManager.endDrawable()
902 sys.stderr.write(
"unhandled ui type.\n")
905 def initializePlugin(obj):
906 plugin = om.MFnPlugin(obj,
"Autodesk",
"3.0",
"Any")
908 plugin.registerNode(
"uiDrawManager_py", uiDrawManager.id, uiDrawManager.creator, uiDrawManager.initialize, om.MPxNode.kLocatorNode, uiDrawManager.drawDbClassification)
910 sys.stderr.write(
"Failed to register node\n")
914 omr.MDrawRegistry.registerDrawOverrideCreator(uiDrawManager.drawDbClassification, uiDrawManager.drawRegistrantId, uiDrawManagerDrawOverride.creator)
916 sys.stderr.write(
"Failed to register override\n")
919 def uninitializePlugin(obj):
920 plugin = om.MFnPlugin(obj)
922 plugin.deregisterNode(uiDrawManager.id)
924 sys.stderr.write(
"Failed to deregister node\n")
928 omr.MDrawRegistry.deregisterGeometryOverrideCreator(uiDrawManager.drawDbClassification, uiDrawManager.drawRegistrantId)
930 sys.stderr.write(
"Failed to deregister override\n")