scripted/pyFrameContextTest.py
2 import maya.api.OpenMayaRender
as omr
3 import maya.api.OpenMaya
as om
51 class frameContextTest(omr.MRenderOverride):
52 ''' Sample class which prints some trace information about the current frame context during setup()
54 def __init__(self, name):
55 omr.MRenderOverride.__init__(self, name)
56 self.mRenderOperations = collections.OrderedDict()
57 self.mUIName =
"Frame Context Test Override"
58 self.mCurrentOperationIndex = -1
60 def supportedDrawAPIs(self):
61 return ( omr.MRenderer.kAllDevices )
63 def startOperationIterator(self):
64 self.mCurrentOperationIndex = 0
67 def renderOperation(self):
68 if self.mCurrentOperationIndex >= 0
and self.mCurrentOperationIndex < len(self.mRenderOperations):
69 return self.mRenderOperations[self.mRenderOperations.keys()[self.mCurrentOperationIndex]]
73 def nextRenderOperation(self):
74 self.mCurrentOperationIndex += 1
75 return self.mCurrentOperationIndex < len(self.mRenderOperations)
77 def setup(self, panelName ):
82 frameCtx = self.getFrameContext()
84 print(
'> MRenderOverride Frame Information Extraction Trace')
85 print(
'> --------------------------------------------------')
86 dim = frameCtx.getViewportDimensions()
91 print(
'> Destination: ' + panelName)
92 print(
'> Viewport: ' + str(originX) +
',' + str(originY) +
',' + str(width) +
',' + str(height))
93 cameraPath = frameCtx.getCurrentCameraPath()
94 cameraName = cameraPath.fullPathName()
95 print(
'> Camera path: ' + cameraName)
96 projection = frameCtx.getMatrix(omr.MFrameContext.kProjectionMtx)
97 print(
'> Projection matrix:' + str(projection))
98 projection = frameCtx.getMatrix(omr.MFrameContext.kViewMtx)
99 print(
'> View matrix:' + str(projection))
101 bparams = frameCtx.getBackgroundParameters();
102 print(
"> Background:")
103 print(
"> - gradient = " + str(bparams[0]))
104 print(
"> - colorColor1 = " + str(bparams[4]))
105 print(
"> - colorColor2 = " + str(bparams[5]))
107 print(
"> Display style: " + str(frameCtx.getDisplayStyle()))
108 print(
"> Wire on shaded: " + str(frameCtx.wireOnShadedMode()))
109 print(
"> Lighting mode: " + str(frameCtx.getLightingMode()))
110 print(
"> Light limit: " + str(frameCtx.getLightLimit()))
112 if frameCtx.getPostEffectEnabled( omr.MFrameContext.kAmbientOcclusion ):
113 print(
"> SSAO enabled")
114 if frameCtx.getPostEffectEnabled( omr.MFrameContext.kMotionBlur ):
115 print(
"> Motion blur enabled");
116 if frameCtx.getPostEffectEnabled( omr.MFrameContext.kViewColorTransformEnabled ):
117 print(
"> Color management enabled")
118 if frameCtx.getPostEffectEnabled( omr.MFrameContext.kDepthOfField ):
119 dofParams = frameCtx.getDOFParameters()
120 print(
"> Depth-of-field enabled: " + str(dofParams[0]))
121 print(
"> - Focus distance: " + str(dofParams[1]))
122 print(
"> - Alpha: " + str(dofParams[2]))
123 if frameCtx.getPostEffectEnabled( omr.MFrameContext.kAntiAliasing ):
124 print(
"> Anti-aliasing enabled")
125 fogParams = frameCtx.getHwFogParameters()
127 print(
"> Fog Enabled:")
128 print(
"> - Fog mode: " + str(fogParams[1]))
129 print(
"> - Fog start: " + str(fogParams[2]))
130 print(
"> - Fog end: " + str(fogParams[3]))
131 print(
"> - Fog density: " + str(fogParams[4]))
132 print(
"> - Fog color: " + str(fogParams[5]))
135 if not self.mRenderOperations:
136 self.mRenderOperations[
'SceneRender'] = omr.MSceneRender(
'SceneRender')
137 self.mRenderOperations[
'Present'] = omr.MPresentTarget(
'Present')
140 self.mCurrentOperationIndex = -1
142 mFrameContextInstance =
None
144 def initializePlugin(obj):
145 plugin = om.MFnPlugin(obj)
146 global mFrameContextInstance
147 mFrameContextInstance = frameContextTest(
'my_frame_context_test')
148 omr.MRenderer.registerOverride(mFrameContextInstance)
150 def uninitializePlugin(obj):
151 plugin = om.MFnPlugin(obj)
152 global mFrameContextInstance
153 if mFrameContextInstance
is not None:
154 omr.MRenderer.deregisterOverride(mFrameContextInstance)
155 mFrameContextInstance =
None