1 from builtins
import zip
2 from builtins
import range
3 import maya.api.OpenMaya
as om
4 import maya.api.OpenMayaAnim
as oma
5 import maya.api.OpenMayaUI
as omui
6 import maya.api.OpenMayaRender
as omr
8 import maya.cmds
as cmds
18 def iconFunc( drawMgr, userData ):
19 drawMgr.beginDrawable()
21 path = mel.eval(
'getenv("MAYA_LOCATION")') +
"/icons/mayaico.png"
22 drawMgr.icon( om.MPoint(0.0, 0.0, 3.0), path, 3.14 )
28 def textFunc( drawMgr, userData ):
29 drawMgr.beginDrawable()
31 drawMgr.text( om.MPoint(200.1, 200.2, 0.3),
"left", omr.MUIDrawManager.kLeft, [200,200])
32 drawMgr.setColor( om.MColor( (1.0, 0.0, 0.0, 1.0) ) )
33 drawMgr.text( om.MPoint(200.1, 150.2, 0.3),
"center", omr.MUIDrawManager.kCenter, [200,200])
34 drawMgr.setColor( om.MColor( (0.0, 1.0, 0.0, 1.0) ) )
35 drawMgr.text( om.MPoint(200.1, 200.2, 0.3),
"right", omr.MUIDrawManager.kRight, [200,200])
39 drawMgr.setFontSize( omr.MUIDrawManager.kSmallFontSize )
40 drawMgr.setColor( om.MColor( (0.0, 0.0, 1.0, 1.0) ) )
41 drawMgr.text( om.MPoint(700.1, 50.2, 0.3),
"small", omr.MUIDrawManager.kLeft, [200,200], om.MColor((0., 1., 1., 1.)),
False )
48 def rectFunc( drawMgr, userData ):
49 drawMgr.beginDrawable()
51 drawMgr.setColor( om.MColor( (1.0, 0.0, 1.0, 1.0) ) )
52 drawMgr.rect2d( om.MPoint(50, 150, 0.3), om.MVector(0.0,1.0,0.0), 100, 300,
False )
54 drawMgr.setColor( om.MColor( (0.0, 1.0, 1.0, 1.0) ) )
55 drawMgr.rect2d( om.MPoint(450.1, 500.2, 0.3), om.MVector(-0.5,0.866025,0.0), 100, 300,
True )
61 def arcFunc( drawMgr, userData ):
62 drawMgr.beginDrawable()
64 drawMgr.setColor( om.MColor( (1.0, 1.0, 1.0, 1.0) ) )
65 drawMgr.arc2d( om.MPoint(750.1, 500.2, 0.3), om.MVector(0.866025, 0.5, 0.0), om.MVector(-0.5,0.866025,0.0), 100,
False )
67 drawMgr.setColor( om.MColor( (1.0, 1.0, 0.5, 1.0) ) )
68 drawMgr.arc2d( om.MPoint(750.1, 500.2, 0.3), om.MVector(-0.866025, -0.5, 0.0), om.MVector(0.5,-0.866025,0.0), 100,
True )
75 def circleFunc( drawMgr, userData ):
76 drawMgr.beginDrawable()
78 drawMgr.setColor( om.MColor( (0.5, 1.0, 1.0, 1.0) ) )
79 drawMgr.circle2d( om.MPoint(500.1, 200.2, 0.3), 75,
False )
80 drawMgr.setColor( om.MColor( (0.5, 1.0, 0.5, 1.0) ) )
81 drawMgr.circle2d( om.MPoint(675.1, 675.2, 0.3), 50,
True )
86 def otherFunc( drawMgr, userData ):
94 cmds.file(force=1,new=1)
95 myCyl = cmds.polyCylinder()
96 cmds.setAttr(
"pCylinder1.s",1, 3.3522764559816802, 1, type=
"double3" )
98 cmds.playbackOptions(min=0, ast=0, max=30, aet=30)
100 cmds.setAttr(
'pCylinder1.tz', 12 )
101 cmds.setAttr(
'pCylinder1.rx', 30 )
102 cmds.setKeyframe( [
'pCylinder1.tz',
'pCylinder1.rx'])
105 cmds.setAttr(
'pCylinder1.tz', 0 )
106 cmds.setAttr(
'pCylinder1.rx', 0 )
107 cmds.setKeyframe( [
'pCylinder1.tz',
'pCylinder1.rx'])
110 cmds.setAttr(
'pCylinder1.tz', -12 )
111 cmds.setAttr(
'pCylinder1.rx', -30 )
112 cmds.setKeyframe( [
'pCylinder1.tz',
'pCylinder1.rx'])
114 def createGraphEditor():
117 geName =
'myGraphEditorGraphEd';
118 if( cmds.scriptedPanel(
'myGraphEditor', exists=1) ):
119 cmds.deleteUI(
'myGraphEditor')
121 geWindow = cmds.window(width=1200,height=800)
122 gePane = cmds.paneLayout(parent=geWindow)
123 cmds.scriptedPanel(
'myGraphEditor',type=
'graphEditor', parent=gePane,tearOff=
False)
125 cmds.showWindow(geWindow)
126 return [geName, geWindow]
128 def maya_useNewAPI():
131 def initializePlugin( mobject ):
134 this method is called when the plug-in is loaded into Maya. It
135 registers all of the services that this plug-in provides with
139 mobject - a handle to the plug-in object (use MFnPlugin to access it)
142 [geName, geWindow] = createGraphEditor()
143 geCanvas = omui.MPanelCanvas(geName)
145 myCanvas = [geCanvas, geName, geWindow]
146 geCanvas.setAutoRefresh(
False )
176 layers = [ omui.MPanelCanvas.kGraphEditorBackground+55
177 , omui.MPanelCanvas.kGraphEditorGrid+55
178 , omui.MPanelCanvas.kGraphEditorAxisLabels+55
179 , omui.MPanelCanvas.kGraphEditorCurves+55
180 , omui.MPanelCanvas.kGraphEditorCurveNames+55
181 , omui.MPanelCanvas.kGraphEditorTimeMarker+55
182 , omui.MPanelCanvas.kGraphEditorTimeMarker+55
183 , omui.MPanelCanvas.kGraphEditorRetimeToolText+55
186 props = omui.MDrawProperties()
187 props.color = om.MColor( [0.2, 0.8, 0.6])
188 props.lineWidth = 0.5
189 props.lineStyle = omr.MUIDrawManager.kDotted
190 props.pointSize = 12.0
194 half_diags = [300-30*n
for n
in range(0,8)]
198 reds = [1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0]
199 greens = [0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0]
200 blues = [0.0, 0.0, 1.0, 1.0, 0.25, 0.25, 0.75, 0.75]
205 starts = [6*n
for n
in range(0,8)]
219 for r,g,b,h
in zip(reds, greens, blues, half_diags):
220 xArray += [cx-h, cx, cx+h, cx+h, cx, cx-h]
221 yArray += [cy, cy-h, cy, cy, cy+h, cy]
222 cArray += [ [r*.25, g*.25, b, a], [r*.50, g*.50, b, a], [r*.75, g*.75, b, a], [r*.75, g*.75, b, a], [r, g, b, a], [r*.25, g*.25, b, a]]
224 floatId = geCanvas.createFloatVertexBuffer( xArray, yArray, cArray )
228 for s,l
in zip(starts, layers):
229 p = geCanvas.createPrimitive( omr.MGeometry.kTriangles, floatId, s, 6, props )
230 geCanvas.addPrimitive( p, l )
236 layers = [ omui.MPanelCanvas.kGraphEditorCurves+55
237 , omui.MPanelCanvas.kGraphEditorCurves+55
238 , omui.MPanelCanvas.kGraphEditorAxisLabels+55
239 , omui.MPanelCanvas.kGraphEditorAxisLabels+55
240 , omui.MPanelCanvas.kGraphEditorCurveNames+55
241 , omui.MPanelCanvas.kGraphEditorTimeMarker+55
243 patterns = [omr.MUIDrawManager.kDotted, omr.MUIDrawManager.kShortDotted, omr.MUIDrawManager.kDashed, omr.MUIDrawManager.kShortDashed, omr.MUIDrawManager.kSolid, omr.MUIDrawManager.kDotted]
247 half_sides = half_diags = [300-30*n
for n
in range(0,6)]
251 reds = [1.0, 0.0, 1.0, 0.0, 1.0, 0.0]
252 greens = [0.0, 1.0, 0.0, 1.0, 0.0, 1.0]
253 blues = [0.5, 0.5, 1.0, 1.0, 0.25, 0.25]
258 starts = [5*n
for n
in range(0,6)]
270 for r,g,b,h
in zip(reds, greens, blues, half_sides):
271 xArray += [cx-h, cx+h, cx+h, cx-h, cx-h]
272 yArray += [cy-h, cy-h, cy+h, cy+h, cy-h]
273 cArray += [ [r*.40, g*.40, b, a], [r*.50, g*.50, b, a], [r*.60, g*.60, b, a], [r*.75, g*.75, b, a], [r, g, b, a]]
275 floatId = geCanvas.createFloatVertexBuffer( xArray, yArray, cArray )
279 for s,l,p
in zip(starts, layers, patterns):
281 id = geCanvas.createPrimitive( omr.MGeometry.kLineStrip, floatId, s, 5, props )
282 geCanvas.addPrimitive( id, l )
303 layers = [ omui.MPanelCanvas.kGraphEditorAxisLabels+55
304 , omui.MPanelCanvas.kGraphEditorCurves+55
305 , omui.MPanelCanvas.kGraphEditorCurveNames+55
306 , omui.MPanelCanvas.kGraphEditorTimeMarker+55
309 props = omui.MDrawProperties()
310 props.color = om.MColor( [0.2, 0.8, 0.6])
311 props.lineWidth = 0.5
312 props.lineStyle = omr.MUIDrawManager.kDotted
313 props.pointSize = 12.0
317 half_diags_t = [6-n
for n
in range(0,4)]
318 half_diags_y = [40, 36, 20, 18]
322 reds = [1.0, 0.0, 1.0, 0.0]
323 greens = [0.0, 1.0, 0.0, 1.0]
324 blues = [0.25, 0.25, 0.75, 0.75]
329 starts = [6*n
for n
in range(0,4)]
333 cxArray = [6, 6, 16, 16]
342 for cx, r,g,b,ht, hy
in zip(cxArray, reds, greens, blues, half_diags_t, half_diags_y):
343 tArray += [om.MTime(t)
for t
in [cx-ht, cx, cx+ht, cx+ht, cx, cx-ht]]
344 yArray += [0, -hy, 0, 0, hy, 0]
345 cArray += [ [r*.25, g*.25, b, a], [r*.50, g*.50, b, a], [r*.75, g*.75, b, a], [r*.75, g*.75, b, a], [r, g, b, a], [r*.25, g*.25, b, a]]
347 timeId = geCanvas.createTimeVertexBuffer( tArray, yArray, cArray )
351 for s,l
in zip(starts, layers):
352 p = geCanvas.createPrimitive( omr.MGeometry.kTriangles, timeId, s, 6, props )
353 geCanvas.addPrimitive( p, l )
361 tArray = [om.MTime(t)
for t
in [0,30,30,0,0]]
362 yArray = [30,30,-30,-30,30]
363 cArray = [[r*.2,1.0,1.0,1.0]
for r
in range(1,6)]
365 timeId = geCanvas.createTimeVertexBuffer( tArray, yArray, cArray )
367 props = omui.MDrawProperties()
368 props.color = om.MColor( [0.2, 0.8, 0.6])
369 props.lineWidth = 0.5
370 props.lineStyle = omr.MUIDrawManager.kDashed
371 props.pointSize = 12.0
373 primId = geCanvas.createPrimitive( omr.MGeometry.kLineStrip, timeId, 0, 5, props )
375 geCanvas.addPrimitive( primId, omui.MPanelCanvas.kGraphEditorCurveNames+56 )
379 geCanvas.registerDrawUICallback( omui.MPanelCanvas.kGraphEditorBackground+56, otherFunc )
381 geCanvas.registerDrawUICallback( omui.MPanelCanvas.kGraphEditorGrid+56, iconFunc )
383 geCanvas.registerDrawUICallback( omui.MPanelCanvas.kGraphEditorAxisLabels+56, textFunc )
385 geCanvas.registerDrawUICallback( omui.MPanelCanvas.kGraphEditorCurves+56, rectFunc )
387 geCanvas.registerDrawUICallback( omui.MPanelCanvas.kGraphEditorCurveNames+54, arcFunc )
389 geCanvas.registerDrawUICallback( omui.MPanelCanvas.kGraphEditorTimeMarker+54, circleFunc )
391 geCanvas.registerDrawUICallback( omui.MPanelCanvas.kGraphEditorRetimeToolText+56, otherFunc )
393 geCanvas.setAutoRefresh(
True )
395 print(geCanvas.isValid())
398 def uninitializePlugin( mobject ):
401 this method is called when the plug-in is unloaded from Maya. It
402 deregisters all of the services that it was providing.
405 mobject - a handle to the plug-in object (use MFnPlugin to access it)
408 [geCanvas, geName, geWindow] = myCanvas
409 if cmds.window(geWindow, exists=
True):
410 cmds.deleteUI(geWindow)
411 print(geCanvas.isValid())