9 from builtins
import object
10 from builtins
import range
12 from OpenGL.GL
import *
13 import maya.api.OpenMayaRender
as omr
14 import maya.api.OpenMayaUI
as omui
15 import maya.api.OpenMaya
as om
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.
26 kMaya3dSceneRender = 1
27 kMaya3dSceneRenderOpaque = 2
28 kMaya3dSceneRenderTransparent = 3
35 kMaya3dSceneRenderUI = 10
50 def printDrawContextLightInfo(drawContext):
52 considerAllSceneLights = omr.MDrawContext.kFilteredIgnoreLightLimit
53 omr.MRenderer.needEvaluateAllLights()
54 lightCount = drawContext.numberOfActiveLights(considerAllSceneLights)
58 positions = om.MFloatPointArray()
59 position = om.MFloatPoint(0, 0, 0)
60 direction = om.MFloatVector()
64 for i
in range(lightCount):
65 lightParam = drawContext.getLightParameterInformation( i, considerAllSceneLights )
66 if not lightParam
is None:
67 print(
"\tLight " + str(i) +
"\n\t{")
69 for pname
in lightParam.parameterList():
70 ptype = lightParam.parameterType(pname)
71 if ptype == omr.MLightParameterInformation.kBoolean:
72 print(
"\t\tLight parameter " + pname +
". Bool " + str(lightParam.getParameter(pname)))
73 elif ptype == omr.MLightParameterInformation.kInteger:
74 print(
"\t\tLight parameter " + pname +
". Integer " + str(lightParam.getParameter(pname)))
75 elif ptype == omr.MLightParameterInformation.kFloat:
76 print(
"\t\tLight parameter " + pname +
". Float " + str(lightParam.getParameter(pname)))
77 elif ptype == omr.MLightParameterInformation.kFloat2:
78 print(
"\t\tLight parameter " + pname +
". Float " + str(lightParam.getParameter(pname)))
79 elif ptype == omr.MLightParameterInformation.kFloat3:
80 print(
"\t\tLight parameter " + pname +
". Float3 " + str(lightParam.getParameter(pname)))
81 elif ptype == omr.MLightParameterInformation.kFloat4:
82 print(
"\t\tLight parameter " + pname +
". Float4 " + str(lightParam.getParameter(pname)))
83 elif ptype == omr.MLightParameterInformation.kFloat4x4Row:
84 print(
"\t\tLight parameter " + pname +
". Float4x4Row " + str(lightParam.getParameter(pname)))
85 elif ptype == omr.MLightParameterInformation.kFloat4x4Col:
86 print(
"\t\tLight parameter " + pname +
". kFloat4x4Col " + str(lightParam.getParameter(pname)))
87 elif ptype == omr.MLightParameterInformation.kTexture2:
89 print(
"\t\tLight texture parameter " + pname +
". OpenGL texture id = " + str(lightParam.getParameterTextureHandle(pname)))
92 elif ptype == omr.MLightParameterInformation.kSampler:
93 print(
"\t\tLight sampler parameter " + pname +
". filter = " + str(lightParam.getParameter(pname).filter))
94 elif ptype == omr.MLightParameterInformation.kTextureCube:
96 print(
"\t\tLight texture parameter " + pname +
". OpenGL texture id = " + str(lightParam.getParameterTextureHandle(pname)))
103 semantic = lightParam.parameterSemantic(pname)
104 if semantic == omr.MLightParameterInformation.kLightEnabled:
105 print(
"\t\t- Parameter semantic : light enabled")
106 elif semantic == omr.MLightParameterInformation.kWorldPosition:
107 print(
"\t\t- Parameter semantic : world position")
108 floatVals = lightParam.getParameter(pname)
109 position += om.MFloatPoint( floatVals[0], floatVals[1], floatVals[2] )
110 positionCount = positionCount + 1
111 elif semantic == omr.MLightParameterInformation.kWorldDirection:
112 print(
"\t\t- Parameter semantic : world direction")
113 direction = lightParam.getParameter(pname)
114 elif semantic == omr.MLightParameterInformation.kIntensity:
115 print(
"\t\t- Parameter semantic : intensity")
116 elif semantic == omr.MLightParameterInformation.kColor:
117 print(
"\t\t- Parameter semantic : color")
118 color = om.MColor( lightParam.getParameter(pname) )
119 elif semantic == omr.MLightParameterInformation.kEmitsDiffuse:
120 print(
"\t\t- Parameter semantic : emits-diffuse")
121 elif semantic == omr.MLightParameterInformation.kEmitsSpecular:
122 print(
"\t\t- Parameter semantic : emits-specular")
123 elif semantic == omr.MLightParameterInformation.kDecayRate:
124 print(
"\t\t- Parameter semantic : decay rate")
125 elif semantic == omr.MLightParameterInformation.kDropoff:
126 print(
"\t\t- Parameter semantic : drop-off")
127 elif semantic == omr.MLightParameterInformation.kCosConeAngle:
128 print(
"\t\t- Parameter semantic : cosine cone angle")
129 elif semantic == omr.MLightParameterInformation.kShadowMap:
130 print(
"\t\t- Parameter semantic : shadow map")
131 elif semantic == omr.MLightParameterInformation.kShadowSamp:
132 print(
"\t\t- Parameter semantic : shadow map sampler")
133 elif semantic == omr.MLightParameterInformation.kShadowBias:
134 print(
"\t\t- Parameter semantic : shadow map bias")
135 elif semantic == omr.MLightParameterInformation.kShadowMapSize:
136 print(
"\t\t- Parameter semantic : shadow map size")
137 elif semantic == omr.MLightParameterInformation.kShadowViewProj:
138 print(
"\t\t- Parameter semantic : shadow map view projection matrix")
139 elif semantic == omr.MLightParameterInformation.kShadowColor:
140 print(
"\t\t- Parameter semantic : shadow color")
141 elif semantic == omr.MLightParameterInformation.kGlobalShadowOn:
142 print(
"\t\t- Parameter semantic : global shadows on")
143 elif semantic == omr.MLightParameterInformation.kShadowOn:
144 print(
"\t\t- Parameter semantic : local shadows on")
145 elif semantic == omr.MLightParameterInformation.kDepthRange:
146 print(
"\t\t- Parameter semantic : depth range")
149 if positionCount > 1:
150 position /= positionCount
151 print(
"\t\tCompute average position " + str(position))
154 print(
"\t\tSemantic -> Parameter Name Lookups")
155 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kLightEnabled)
158 floatVals = lightParam.getParameter(omr.MLightParameterInformation.kLightEnabled)
161 print(
"\t\t\tkLightEnabled -> " + str(paramNames) +
" -- " + str(floatVals))
162 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kWorldPosition)
163 print(
"\t\t\tkWorldPosition -> " + str(paramNames))
164 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kWorldDirection)
165 print(
"\t\t\tkWorldDirection -> " + str(paramNames))
166 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kIntensity)
167 print(
"\t\t\tkIntensity -> " + str(paramNames))
168 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kColor)
169 print(
"\t\t\tkColor -> " + str(paramNames))
170 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kEmitsDiffuse)
171 print(
"\t\t\tkEmitsDiffuse -> " + str(paramNames))
172 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kEmitsSpecular)
173 print(
"\t\t\tkEmitsSpecular -> " + str(paramNames))
174 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kDecayRate)
175 print(
"\t\t\tkDecayRate -> " + str(paramNames))
176 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kDropoff)
177 print(
"\t\t\tkDropoff -> " + str(paramNames))
178 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kCosConeAngle)
179 print(
"\t\t\tkCosConeAngle -> " + str(paramNames))
180 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kIrradianceIn)
181 print(
"\t\t\tkIrradianceIn -> " + str(paramNames))
182 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kShadowMap)
183 print(
"\t\t\tkShadowMap -> " + str(paramNames))
184 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kShadowSamp)
185 print(
"\t\t\tkShadowSamp -> " + str(paramNames))
186 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kShadowBias)
187 print(
"\t\t\tkShadowBias -> " + str(paramNames))
188 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kShadowMapSize)
189 print(
"\t\t\tkShadowMapSize -> " + str(paramNames))
190 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kShadowColor)
191 print(
"\t\t\tkShadowColor -> " + str(paramNames))
192 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kGlobalShadowOn)
193 print(
"\t\t\tkGlobalShadowOn -> " + str(paramNames))
194 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kShadowOn)
195 print(
"\t\t\tkShadowOn -> " + str(paramNames))
196 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kDepthRange)
197 print(
"\t\t\tkDepthRange -> " + str(paramNames))
213 def callbackDataPrint(context, renderItemList, shaderInstance):
214 if not shaderInstance
is None:
215 paramNames = shaderInstance.parameterList()
216 paramCount = len(paramNames)
217 print(
"\tSHADER: # of parameters = " + str(paramCount))
218 for i
in range(paramCount):
219 print(
"\t\tPARAM[" + paramNames[i] +
"]")
221 numItems = len(renderItemList)
222 for i
in range(numItems):
223 item = renderItemList[i]
225 path = item.sourceDagPath()
226 print(
"\tRENDER ITEM: '" + item.name() +
"' -- SOURCE: '" + path.fullPathName() +
"'")
228 passCtx = context.getPassContext()
229 passId = passCtx.passIdentifier()
230 passSem = passCtx.passSemantics()
231 print(
"PASS ID[" + passId +
"], PASS SEMANTICS[" + str(passSem) +
"]")
239 def shaderOverrideCallbackBindLightingInfo(drawContext, renderItemList, shaderInstance):
240 if shaderInstance
is None:
245 globalShadowsOn =
False
246 localShadowsOn =
False
247 direction = om.MFloatVector(0.0, 0.0, 1.0)
249 lightColor = [ 0.0, 0.0, 0.0 ]
254 considerAllSceneLights = omr.MDrawContext.kFilteredIgnoreLightLimit
255 omr.MRenderer.needEvaluateAllLights()
256 lightCount = drawContext.numberOfActiveLights(considerAllSceneLights)
258 shadowViewProj = om.MMatrix()
259 shadowResourceTexture =
None
260 samplerDesc = omr.MSamplerStateDesc()
261 shadowColor = [ 0.0, 0.0, 0.0 ]
263 foundDirectional =
False
264 for i
in range(lightCount):
267 globalShadowsOn =
False
268 localShadowsOn =
False
269 direction = om.MFloatVector(0.0, 0.0, 1.0)
271 lightColor = [ 0.0, 0.0, 0.0 ]
273 lightParam = drawContext.getLightParameterInformation( i, considerAllSceneLights )
274 if not lightParam
is None:
275 for pname
in lightParam.parameterList():
276 semantic = lightParam.parameterSemantic( pname )
278 if semantic == omr.MLightParameterInformation.kWorldDirection:
279 floatVals = lightParam.getParameter( pname )
280 direction = om.MFloatVector( floatVals[0], floatVals[1], floatVals[2] )
281 foundDirectional =
True
282 elif semantic == omr.MLightParameterInformation.kIntensity:
283 floatVals = lightParam.getParameter( pname )
284 lightIntensity = floatVals[0]
285 elif semantic == omr.MLightParameterInformation.kColor:
286 lightColor = lightParam.getParameter( pname )
289 elif semantic == omr.MLightParameterInformation.kGlobalShadowOn:
290 intVals = lightParam.getParameter( pname )
292 globalShadowsOn = (intVals[0] != 0)
293 elif semantic == omr.MLightParameterInformation.kShadowOn:
294 intVals = lightParam.getParameter( pname )
296 localShadowsOn = (intVals[0] != 0)
297 elif semantic == omr.MLightParameterInformation.kShadowViewProj:
298 shadowViewProj = lightParam.getParameter( pname )
299 elif semantic == omr.MLightParameterInformation.kShadowMap:
300 shadowResourceTexture = lightParam.getParameter( pname )
301 elif semantic == omr.MLightParameterInformation.kShadowSamp:
302 samplerDesc = lightParam.getParameter( pname )
303 elif semantic == omr.MLightParameterInformation.kShadowColor:
304 shadowColor = lightParam.getParameter( pname )
308 if foundDirectional
and globalShadowsOn
and localShadowsOn
and not shadowResourceTexture
is None:
309 resourceHandle = shadowResourceTexture.resourceHandle()
310 if resourceHandle > 0:
311 debugShadowBindings =
False
313 shaderInstance.setParameter(
"mayaShadowPCF1_shadowMap", shadowResource )
314 if debugShadowBindings:
315 print(
"Bound shadow map to shader param mayaShadowPCF1_shadowMap")
319 shaderInstance.setParameter(
"mayaShadowPCF1_shadowViewProj", shadowViewProj )
320 if debugShadowBindings:
321 print(
"Bound shadow map transform to shader param mayaShadowPCF1_shadowViewProj")
325 shaderInstance.setParameter(
"mayaShadowPCF1_shadowColor", shadowColor )
326 if debugShadowBindings:
327 print(
"Bound shadow map color to shader param mayaShadowPCF1_shadowColor")
331 textureManager = omr.MRenderer.getTextureManager()
332 if not textureManager
is None:
333 textureManager.releaseTexture(shadowResourceTexture)
334 shadowResourceTexture =
None
337 shaderInstance.setParameter(
"mayaDirectionalLight_direction", direction)
338 shaderInstance.setParameter(
"mayaDirectionalLight_intensity", lightIntensity)
339 shaderInstance.setParameter(
"mayaDirectionalLight_color", lightColor)
340 shaderInstance.setParameter(
"mayaShadowPCF1_mayaGlobalShadowOn", globalShadowsOn)
341 shaderInstance.setParameter(
"mayaShadowPCF1_mayaShadowOn", localShadowsOn)
346 def shaderOverridePreDrawCallback(context, renderItemList, shaderInstance):
347 print(
"PRE-draw callback triggered for render item list with data:")
348 callbackDataPrint(context, renderItemList, shaderInstance)
352 printDrawContextLightInfo( context )
358 def shaderOverridePostDrawCallback(context, renderItemList, shaderInstance):
359 print(
"POST-draw callback triggered for render item list with data:")
360 callbackDataPrint(context, renderItemList, shaderInstance)
367 class viewRenderHUDOperation(omr.MHUDRender):
369 omr.MHUDRender.__init__(self)
374 def targetOverrideList(self):
375 if not self.mTargets
is None:
376 return [ self.mTargets[kMyColorTarget], self.mTargets[kMyDepthTarget] ]
379 def hasUIDrawables(self):
382 def addUIDrawables(self, drawManager2D, frameContext):
384 drawManager2D.beginDrawable()
386 drawManager2D.setColor( om.MColor( (0.455, 0.212, 0.596) ) )
388 drawManager2D.setFontSize( omr.MUIDrawManager.kSmallFontSize )
391 dim = frameContext.getViewportDimensions()
396 drawManager2D.text( om.MPoint(w*0.5, h*0.91),
"Sample VP2 Renderer Override", omr.MUIDrawManager.kCenter )
399 viewportInfoText =
"Viewport information: x= "
400 viewportInfoText += str(x)
401 viewportInfoText +=
", y= "
402 viewportInfoText += str(y)
403 viewportInfoText +=
", w= "
404 viewportInfoText += str(w)
405 viewportInfoText +=
", h= "
406 viewportInfoText += str(h)
407 drawManager2D.text( om.MPoint(w*0.5, h*0.885), viewportInfoText, omr.MUIDrawManager.kCenter )
410 drawManager2D.endDrawable()
412 def setRenderTargets(self, targets):
413 self.mTargets = targets
422 class viewRenderPresentTarget(omr.MPresentTarget):
423 def __init__(self, name):
424 omr.MPresentTarget.__init__(self, name)
429 def targetOverrideList(self):
430 if not self.mTargets
is None:
431 return [ self.mTargets[kMyColorTarget], self.mTargets[kMyDepthTarget] ]
434 def setRenderTargets(self, targets):
435 self.mTargets = targets
445 class viewRenderQuadRender(omr.MQuadRender):
448 kPost_EffectMonochrome = 1
449 kPost_EffectEdgeDetect = 2
450 kPost_EffectInvert = 3
457 def __init__(self, name):
458 omr.MQuadRender.__init__(self, name)
461 self.mShaderInstance =
None
465 self.mViewRectangle = om.MFloatPoint()
467 self.mShader = self.kEffectNone
470 if not self.mShaderInstance
is None:
471 shaderMgr = omr.MRenderer.getShaderManager()
472 if not shaderMgr
is None:
473 shaderMgr.releaseShader(self.mShaderInstance)
474 self.mShaderInstance =
None
481 if self.mShaderInstance
is None:
482 shaderMgr = omr.MRenderer.getShaderManager()
483 if not shaderMgr
is None:
496 if self.mShader == self.kPre_MandelBrot:
497 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"MandelBrot",
"" )
498 elif self.mShader == self.kPost_EffectMonochrome:
499 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"FilterMonochrome",
"" )
500 elif self.mShader == self.kPost_EffectEdgeDetect:
501 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"FilterEdgeDetect",
"" )
502 elif self.mShader == self.kPost_EffectInvert:
503 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"Invert",
"" )
504 elif self.mShader == self.kScene_Threshold:
505 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"Threshold",
"" )
506 elif self.mShader == self.kScene_BlurHoriz:
507 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"Blur",
"BlurHoriz" )
508 elif self.mShader == self.kScene_BlurVert:
509 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"Blur",
"BlurVert" )
510 elif self.mShader == self.kSceneBlur_Blend:
511 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"Blend",
"Add" )
518 if not self.mShaderInstance
is None:
519 if self.mShader == self.kPre_MandelBrot:
522 self.mShaderInstance.setParameter(
"gIterate", 50)
524 print(
"Could not change mandelbrot parameter")
527 elif self.mShader == self.kPost_EffectInvert:
531 self.mShaderInstance.setParameter(
"gInputTex", self.mTargets[kMyColorTarget])
533 print(
"Could not set input render target / texture parameter on invert shader")
536 elif self.mShader == self.kScene_Threshold:
540 self.mShaderInstance.setParameter(
"gSourceTex", self.mTargets[kMyColorTarget])
542 print(
"Could not set input render target / texture parameter on threshold shader")
544 self.mShaderInstance.setParameter(
"gBrightThreshold", 0.7 )
546 elif self.mShader == self.kScene_BlurHoriz:
550 self.mShaderInstance.setParameter(
"gSourceTex", self.mTargets[kMyBlurTarget])
552 print(
"Could not set input render target / texture parameter on hblur shader")
555 elif self.mShader == self.kScene_BlurVert:
559 self.mShaderInstance.setParameter(
"gSourceTex", self.mTargets[kMyBlurTarget])
561 print(
"Could not set input render target / texture parameter on vblur shader")
564 elif self.mShader == self.kSceneBlur_Blend:
568 self.mShaderInstance.setParameter(
"gSourceTex", self.mTargets[kMyColorTarget])
574 self.mShaderInstance.setParameter(
"gSourceTex2", self.mTargets[kMyBlurTarget])
577 self.mShaderInstance.setParameter(
"gBlendSrc", 0.3 )
579 elif self.mShader == self.kPost_EffectMonochrome:
583 self.mShaderInstance.setParameter(
"gInputTex", self.mTargets[kMyColorTarget])
585 print(
"Could not set input render target / texture parameter on monochrome shader")
588 elif self.mShader == self.kPost_EffectEdgeDetect:
592 self.mShaderInstance.setParameter(
"gInputTex", self.mTargets[kMyColorTarget])
594 print(
"Could not set input render target / texture parameter on edge detect shader")
596 self.mShaderInstance.setParameter(
"gThickness", 1.0 )
597 self.mShaderInstance.setParameter(
"gThreshold", 0.1 )
599 return self.mShaderInstance
606 def targetOverrideList(self):
607 if not self.mTargets
is None:
609 if self.mShader == self.kScene_Threshold
or self.mShader == self.kScene_BlurHoriz
or self.mShader == self.kScene_BlurVert:
610 return [ self.mTargets[kMyBlurTarget] ]
612 return [ self.mTargets[kMyColorTarget], self.mTargets[kMyDepthTarget] ]
616 def clearOperation(self):
617 clearOp = self.mClearOperation
619 if self.mShader == self.kPre_MandelBrot:
620 clearOp.setClearGradient(
False )
621 clearOp.setMask( omr.MClearOperation.kClearAll )
624 clearOp.setClearGradient(
False )
625 clearOp.setMask( omr.MClearOperation.kClearNone )
628 def setRenderTargets(self, targets):
629 self.mTargets = targets
631 def setShader(self, shader):
632 self.mShader = shader
634 def viewRectangle(self):
635 return self.mViewRectangle
637 def setViewRectangle(self, rect):
638 self.mViewRectangle = rect
646 class simpleViewRenderSceneRender(omr.MSceneRender):
647 def __init__(self, name):
648 omr.MSceneRender.__init__(self, name)
650 self.mViewRectangle = om.MFloatPoint(0.0, 0.0, 1.0, 1.0)
652 def viewportRectangleOverride(self):
654 testRectangleSize =
False
655 if testRectangleSize:
657 self.mViewRectangle = om.MFloatPoint(0.33, 0.10, 0.50, 0.50)
658 return self.mViewRectangle
660 def clearOperation(self):
662 val1 = [ 0.0, 0.2, 0.8, 1.0 ]
663 val2 = [ 0.5, 0.4, 0.1, 1.0 ]
664 clearOp = self.mClearOperation
665 clearOp.setClearColor( val1 )
666 clearOp.setClearColor2( val2 )
667 clearOp.setClearGradient(
True )
677 class viewRenderSceneRender(omr.MSceneRender):
678 def __init__(self, name, sceneFilter, clearMask):
679 omr.MSceneRender.__init__(self, name)
681 self.mSelectionList = om.MSelectionList()
686 self.mCameraOverride = omr.MCameraOverride()
688 self.mViewRectangle = om.MFloatPoint(0.0, 0.0, 1.0, 1.0)
692 self.mShaderOverride =
None
694 self.mSceneFilter = sceneFilter
696 self.mClearMask = clearMask
699 self.mUseShaderOverride =
False
700 self.mUseStockShaderOverride =
False
701 self.mAttachPrePostShaderCallback =
False
702 self.mUseShadowShader =
False
703 self.mOverrideDisplayMode =
True
704 self.mOverrideLightingMode =
False
705 self.mOverrideCullingMode =
False
706 self.mDebugTargetResourceHandle =
False
707 self.mOverrrideM3dViewDisplayMode =
False
708 self.mPrevDisplayStyle = omui.M3dView.kGouraudShaded
709 self.mFilterDrawNothing =
False
710 self.mFilterDrawSelected =
False
711 self.mEnableSRGBWrite =
False
715 if not self.mShaderOverride
is None:
716 shaderMgr = omr.MRenderer.getShaderManager()
717 if not shaderMgr
is None:
718 shaderMgr.releaseShader(self.mShaderOverride)
719 self.mShaderOverride =
None
721 def setRenderTargets(self, targets):
722 self.mTargets = targets
724 def targetOverrideList(self):
725 if not self.mTargets
is None:
726 return [ self.mTargets[kMyColorTarget], self.mTargets[kMyDepthTarget] ]
730 def enableSRGBWrite(self):
731 return self.mEnableSRGBWrite
735 def cameraOverride(self):
736 if len(self.mPanelName) > 0:
737 view = omui.M3dView.getM3dViewFromModelPanel(self.mPanelName)
738 self.mCameraOverride.mCameraPath = view.getCamera()
739 return self.mCameraOverride
741 print(
"\t" + self.mName +
": Query custom scene camera override -- no override set")
746 def renderFilterOverride(self):
747 return self.mSceneFilter
753 def displayModeOverride(self):
754 if self.mOverrideDisplayMode:
755 return ( omr.MSceneRender.kBoundingBox | omr.MSceneRender.kShaded )
756 return omr.MSceneRender.kNoDisplayModeOverride
760 def lightModeOverride(self):
761 if self.mOverrideLightingMode:
762 return omr.MSceneRender.kSelectedLights
763 return omr.MSceneRender.kNoLightingModeOverride
766 def shadowEnableOverride(self):
767 if (self.mSceneFilter & omr.MSceneRender.kRenderShadedItems) == 0:
775 def cullingOverride(self):
776 if self.mOverrideCullingMode:
777 return omr.MSceneRender.kCullBackFaces
778 return omr.MSceneRender.kNoCullingOverride
785 if self.mOverrrideM3dViewDisplayMode:
786 if len(self.mPanelName) > 0:
787 view = omui.M3dView.getM3dViewFromModelPanel(self.mPanelName)
788 self.mPrevDisplayStyle = view.displayStyle();
789 view.setDisplayStyle( omui.M3dView.kGouraudShaded )
795 def postRender(self):
796 if self.mDebugTargetResourceHandle:
800 if not self.mTargets[kMyColorTarget]
is None:
801 colorResourceHandle = self.mTargets[kMyColorTarget].resourceHandle()
802 print(
"\t - Color target resource handle = " + str(colorResourceHandle))
804 if not self.mTargets[kMyDepthTarget]
is None:
805 depthStencilResourceHandle = self.mTargets[kMyDepthTarget].resourceHandle()
806 print(
"\t - Depth target resource handle = " + str(depthStencilResourceHandle))
808 if self.mOverrrideM3dViewDisplayMode:
809 if len(self.mPanelName) > 0:
810 view = omui.M3dView.getM3dViewFromModelPanel(self.mPanelName)
811 view.setDisplayStyle( self.mPrevDisplayStyle )
815 def getObjectTypeExclusions(self):
817 return omr.MFrameContext.kExcludeCameras
828 def objectSetOverride(self):
829 self.mSelectionList.clear()
835 if self.mFilterDrawNothing:
836 return self.mSelectionList
841 if self.mFilterDrawSelected:
842 selList = om.MGlobal.getActiveSelectionList()
843 if selList.length() > 0:
844 iter = om.MItSelectionList(selList)
845 while not iter.isDone():
846 comp = iter.getComponent()
847 self.mSelectionList.add( comp[0], comp[1] )
850 if self.mSelectionList.length() > 0:
851 print(
"\t" + self.name() +
" : Filtering render with active object list")
852 return self.mSelectionList
861 def clearOperation(self):
862 clearOp = self.mClearOperation
863 if (self.mSceneFilter & (omr.MSceneRender.kRenderOpaqueShadedItems | omr.MSceneRender.kRenderTransparentShadedItems | omr.MSceneRender.kRenderUIItems)) != 0:
864 clearOp.setClearGradient(
False)
868 val1 = [ 0.0, 0.2, 0.8, 1.0 ]
869 val2 = [ 0.5, 0.4, 0.1, 1.0 ]
870 clearOp.setClearColor(val1)
871 clearOp.setClearColor2(val2)
872 clearOp.setClearGradient(
True)
874 clearOp.setMask(self.mClearMask)
882 def shaderOverride(self):
883 if self.mUseShaderOverride:
884 if self.mShaderOverride
is None:
885 shaderManager = omr.MRenderer.getShaderManager()
886 if not shaderManager
is None:
889 if not self.mUseStockShaderOverride:
890 if self.mUseShadowShader:
893 preCallBack = shaderOverrideCallbackBindLightingInfo
894 self.mShaderOverride = shaderManager.getEffectsFileShader(
"MayaBlinnDirectionalLightShadow",
"",
None,
True, preCallBack, postCallBack)
897 if self.mAttachPrePostShaderCallback:
898 preCallBack = shaderOverridePreDrawCallback
899 if self.mAttachPrePostShaderCallback:
900 postCallBack = shaderOverridePostDrawCallback
901 self.mShaderOverride = shaderManager.getEffectsFileShader(
"Gooch",
"",
None,
True, preCallBack, postCallBack)
905 if self.mAttachPrePostShaderCallback:
906 preCallBack = shaderOverridePreDrawCallback
907 if self.mAttachPrePostShaderCallback:
908 postCallBack = shaderOverridePostDrawCallback
909 self.mShaderOverride = shaderManager.getStockShader( omr.MShaderManager.k3dBlinnShader, preCallBack, postCallBack)
911 if not self.mShaderOverride
is None:
912 print(
"\t" + self.name() +
" : Set stock shader override " + str(omr.MShaderManager.k3dBlinnShader))
913 diffColor = [0.0, 0.4, 1.0, 1.0]
915 self.mShaderOverride.setParameter(
"diffuseColor", diffColor)
917 print(
"Could not set diffuseColor on shader")
919 return self.mShaderOverride
924 def hasUIDrawables(self):
928 def addPreUIDrawables(self, drawManager, frameContext):
929 drawManager.beginDrawable()
930 drawManager.setColor( om.MColor( (0.1, 0.5, 0.95) ) )
931 drawManager.setFontSize( omr.MUIDrawManager.kSmallFontSize )
932 drawManager.text( om.MPoint( -2, 2, -2 ),
"Pre UI draw test in Scene operation", omr.MUIDrawManager.kRight )
933 drawManager.line( om.MPoint( -2, 0, -2 ), om.MPoint( -2, 2, -2 ) )
934 drawManager.setColor( om.MColor( (1.0, 1.0, 1.0) ) )
935 drawManager.sphere( om.MPoint( -2, 2, -2 ), 0.8,
False )
936 drawManager.setColor( om.MColor( (0.1, 0.5, 0.95, 0.4) ) )
937 drawManager.sphere( om.MPoint( -2, 2, -2 ), 0.8,
True )
938 drawManager.endDrawable()
941 def addPostUIDrawables(self, drawManager, frameContext):
942 drawManager.beginDrawable()
943 drawManager.setColor( om.MColor( (0.05, 0.95, 0.34) ) )
944 drawManager.setFontSize( omr.MUIDrawManager.kSmallFontSize )
945 drawManager.text( om.MPoint( 2, 2, 2 ),
"Post UI draw test in Scene operation", omr.MUIDrawManager.kLeft )
946 drawManager.line( om.MPoint( 2, 0, 2), om.MPoint( 2, 2, 2 ) )
947 drawManager.setColor( om.MColor( (1.0, 1.0, 1.0) ) )
948 drawManager.sphere( om.MPoint( 2, 2, 2 ), 0.8,
False )
949 drawManager.setColor( om.MColor( (0.05, 0.95, 0.34, 0.4) ) )
950 drawManager.sphere( om.MPoint( 2, 2, 2 ), 0.8,
True )
951 drawManager.endDrawable()
954 return self.mPanelName
956 def setPanelName(self, name):
957 self.mPanelName = name
959 def viewRectangle(self):
960 return self.mViewRectangle
962 def setViewRectangle(self, rect):
963 self.mViewRectangle = rect
965 def colorTarget(self):
966 if not self.mTargets
is None:
967 return self.mTargets[kMyColorTarget]
970 def depthTarget(self):
971 if not self.mTargets
is None:
972 return self.mTargets[kMyDepthTarget]
975 def setEnableSRGBWriteFlag(self, val):
976 self.mEnableSRGBWrite = val
978 def enableSRGBWriteFlag(self):
979 return self.mEnableSRGBWrite
994 class viewRenderUserOperation(omr.MUserRenderOperation):
995 def __init__(self, name):
996 omr.MUserRenderOperation.__init__(self, name)
1001 self.mCameraOverride = omr.MCameraOverride()
1003 self.mViewRectangle = om.MFloatPoint(0.0, 0.0, 1.0, 1.0)
1005 self.mTargets =
None
1007 self.fEnableSRGBWriteFlag =
False
1009 self.fDrawLabel =
False
1011 self.fUserCameraOverride =
False
1013 self.fDebugDrawContext =
False
1014 self.fDebugLightingInfo =
False
1016 def execute(self, drawContext):
1018 debugPassInformation =
False
1019 if debugPassInformation:
1020 passCtx = drawContext.getPassContext()
1021 passId = passCtx.passIdentifier()
1022 passSem = passCtx.passSemantics()
1023 print(
"viewRenderUserOperation: drawing in pass[" + str(passId) +
"], semantic[" + str(passSem) +
"]")
1030 overrideName = omr.MRenderer.activeRenderOverride()
1031 overrideFunc = omr.MRenderer.findRenderOverride( overrideName )
1035 if self.fDebugLightingInfo:
1036 printDrawContextLightInfo( drawContext )
1040 if self.fDebugDrawContext:
1041 matrix = drawContext.getMatrix(omr.MFrameContext.kWorldMtx)
1042 print(
"World matrix is: " + str(matrix))
1044 viewDirection = drawContext.getTuple(omr.MFrameContext.kViewDirection)
1045 print(
"Viewdirection is: " + str(viewDirection))
1047 box = drawContext.getSceneBox()
1048 print(
"Screen box is: " + str(box))
1049 print(
"\tcenter=" + str(box.center))
1051 vpdim = drawContext.getViewportDimensions()
1052 print(
"Viewport dimension: " + str(vpdim))
1056 if len(self.mPanelName) > 0:
1057 view = omui.M3dView.getM3dViewFromModelPanel(self.mPanelName)
1060 targetSize = drawContext.getRenderTargetSize()
1063 testString =
"Drawing with override: "
1064 testString += overrideFunc.name()
1065 pos = om.MPoint(0.0, 0.0, 0.0)
1066 glColor3f( 1.0, 1.0, 1.0 )
1067 view.drawText( testString, pos )
1069 def cameraOverride(self):
1070 if self.fUserCameraOverride:
1071 if len(self.mPanelName) > 0:
1072 view = omui.M3dView.getM3dViewFromModelPanel(self.mPanelName)
1073 self.mCameraOverride.mCameraPath = view.getCamera()
1074 return self.mCameraOverride
1078 def targetOverrideList(self):
1079 if not self.mTargets
is None:
1080 return [ self.mTargets[kMyColorTarget], self.mTargets[kMyDepthTarget] ]
1083 def enableSRGBWrite(self):
1084 return self.fEnableSRGBWriteFlag
1086 def hasUIDrawables(self):
1089 def addUIDrawables(self, drawManager, frameContext):
1090 drawManager.beginDrawable()
1091 drawManager.setColor( om.MColor( (0.95, 0.5, 0.1) ) )
1092 drawManager.text( om.MPoint( 0, 2, 0 ),
"UI draw test in user operation" )
1093 drawManager.line( om.MPoint( 0, 0, 0), om.MPoint( 0, 2, 0 ) )
1094 drawManager.setColor( om.MColor( (1.0, 1.0, 1.0) ) )
1095 drawManager.sphere( om.MPoint( 0, 2, 0 ), 0.8,
False )
1096 drawManager.setColor( om.MColor( (0.95, 0.5, 0.1, 0.4) ) )
1097 drawManager.sphere( om.MPoint( 0, 2, 0 ), 0.8,
True )
1098 drawManager.endDrawable()
1100 def setRenderTargets(self, targets):
1101 self.mTargets = targets
1103 def setEnableSRGBWriteFlag(self, val):
1104 self.fEnableSRGBWriteFlag = val
1106 def panelName(self):
1107 return self.mPanelName
1109 def setPanelName(self, name):
1110 self.mPanelName = name
1112 def viewRectangle(self):
1113 return self.mViewRectangle
1115 def setViewRectangle(self, rect):
1116 self.mViewRectangle = rect
1143 class viewRenderOverride(omr.MRenderOverride):
1144 def __init__(self, name):
1145 omr.MRenderOverride.__init__(self, name)
1149 self.mUIName =
"Sample VP2 Renderer Override"
1152 self.mRenderOperations = []
1153 self.mRenderOperationNames = []
1155 for i
in range(kNumberOfOps):
1156 self.mRenderOperations.append(
None)
1157 self.mRenderOperationNames.append(
"")
1158 self.mCurrentOperation = -1
1161 self.mTargetOverrideNames = []
1162 self.mTargetDescriptions = []
1164 self.mTargetSupportsSRGBWrite = []
1166 for i
in range(kTargetCount):
1167 self.mTargetOverrideNames.append(
"")
1168 self.mTargetDescriptions.append(
None)
1169 self.mTargets.append(
None)
1170 self.mTargetSupportsSRGBWrite.append(
False)
1174 colorFormat = omr.MRenderer.kR8G8B8A8_UNORM
1175 depthFormat = omr.MRenderer.kD24S8
1182 self.mTargetOverrideNames [kMyColorTarget] =
"__viewRenderOverrideCustomColorTarget__"
1183 self.mTargetDescriptions [kMyColorTarget] = omr.MRenderTargetDescription(self.mTargetOverrideNames[kMyColorTarget], 256, 256, sampleCount, colorFormat, 0,
False)
1184 self.mTargets [kMyColorTarget] =
None
1185 self.mTargetSupportsSRGBWrite[kMyColorTarget] =
False
1187 self.mTargetOverrideNames [kMyDepthTarget] =
"__viewRenderOverrideCustomDepthTarget__"
1188 self.mTargetDescriptions [kMyDepthTarget] = omr.MRenderTargetDescription(self.mTargetOverrideNames[kMyDepthTarget], 256, 256, sampleCount, depthFormat, 0,
False)
1189 self.mTargets [kMyDepthTarget] =
None
1190 self.mTargetSupportsSRGBWrite[kMyDepthTarget] =
False
1192 self.mTargetOverrideNames [kMyBlurTarget] =
"__viewRenderOverrideBlurTarget__"
1193 self.mTargetDescriptions [kMyBlurTarget]= omr.MRenderTargetDescription(self.mTargetOverrideNames[kMyBlurTarget], 256, 256, sampleCount, colorFormat, 0,
False)
1194 self.mTargets [kMyBlurTarget] =
None
1195 self.mTargetSupportsSRGBWrite[kMyBlurTarget] =
False
1198 self.mSplitUIDraw =
False
1201 self.mDebugOverride =
False
1204 self.mSimpleRendering =
False
1207 self.mPanelName =
""
1210 targetMgr = omr.MRenderer.getRenderTargetManager()
1213 for i
in range(kTargetCount):
1214 self.mTargetDescriptions[i] =
None
1216 if not self.mTargets[i]
is None:
1217 if not targetMgr
is None:
1218 targetMgr.releaseRenderTarget(self.mTargets[i])
1219 self.mTargets[i] =
None
1226 for i
in range(kNumberOfOps):
1227 self.mRenderOperations[i] =
None
1237 def supportedDrawAPIs(self):
1238 return ( omr.MRenderer.kOpenGL | omr.MRenderer.kDirectX11 | omr.MRenderer.kOpenGLCoreProfile )
1242 def startOperationIterator(self):
1243 self.mCurrentOperation = 0
1247 def renderOperation(self):
1248 if self.mCurrentOperation >= 0
and self.mCurrentOperation < kNumberOfOps:
1249 while self.mRenderOperations[self.mCurrentOperation]
is None:
1250 self.mCurrentOperation = self.mCurrentOperation+1
1251 if self.mCurrentOperation >= kNumberOfOps:
1254 if not self.mRenderOperations[self.mCurrentOperation]
is None:
1255 if self.mDebugOverride:
1256 print(
"\t" + self.name() +
"Queue render operation[" + str(self.mCurrentOperation) +
"] = (" + self.mRenderOperations[self.mCurrentOperation].name() +
")")
1257 return self.mRenderOperations[self.mCurrentOperation]
1261 def nextRenderOperation(self):
1262 self.mCurrentOperation = self.mCurrentOperation + 1
1263 if self.mCurrentOperation < kNumberOfOps:
1270 def updateRenderTargets(self):
1271 if self.mDebugOverride:
1272 print(
"\t" + self.name() +
": Set output render target overrides: color=" + self.mTargetDescriptions[kMyColorTarget].name() +
", depth=" + self.mTargetDescriptions[kMyDepthTarget].name())
1277 targetSize = omr.MRenderer.outputTargetSize()
1278 targetWidth = targetSize[0]
1279 targetHeight = targetSize[1]
1289 for targetId
in range(kTargetCount):
1290 self.mTargetDescriptions[targetId].setWidth( targetWidth )
1291 self.mTargetDescriptions[targetId].setHeight( targetHeight )
1294 colorTargetSupportsSGRBWrite =
False
1296 sDebugSRGBWrite =
False
1298 testUnorderedWriteAccess =
False
1302 targetManager = omr.MRenderer.getRenderTargetManager()
1303 if not targetManager
is None:
1305 if omr.MRenderer.drawAPI() != omr.MRenderer.kOpenGL:
1307 for i
in range(omr.MRenderer.kNumberOfRasterFormats):
1308 if targetManager.formatSupportsSRGBWrite(i):
1309 print(
"Format " + str(i) +
" supports SRGBwrite")
1311 for targetId
in range(kTargetCount):
1314 supportsSRGBWrite =
False
1315 if omr.MRenderer.drawAPI() != omr.MRenderer.kOpenGL:
1316 supportsSRGBWrite = targetManager.formatSupportsSRGBWrite( self.mTargetDescriptions[targetId].rasterFormat() )
1317 self.mTargetSupportsSRGBWrite[targetId] = supportsSRGBWrite
1318 self.mTargetDescriptions[targetId].setAllowsUnorderedAccess( testUnorderedWriteAccess )
1321 if targetId == kMyColorTarget:
1322 colorTargetSupportsSGRBWrite = supportsSRGBWrite
1325 if targetId == kMyColorTarget
or targetId == kMyBlurTarget:
1326 print(
"Color target " + str(targetId) +
" supports sRGB write = " + str(supportsSRGBWrite))
1328 if targetId == kMyDepthTarget:
1329 print(
"Depth target supports sRGB write = " + str(supportsSRGBWrite))
1332 if self.mTargets[targetId]
is None:
1333 self.mTargets[targetId] = targetManager.acquireRenderTarget( self.mTargetDescriptions[targetId] )
1337 self.mTargets[targetId].updateDescription( self.mTargetDescriptions[targetId] )
1339 if testUnorderedWriteAccess
and not self.mTargets[targetId]
is None:
1340 returnDesc = self.mTargets[targetId].targetDescription()
1341 self.mTargetDescriptions[targetId].setAllowsUnorderedAccess( returnDesc.allowsUnorderedAccess() )
1342 print(
"Acquire target[" + returnDesc.name() +
"] with unordered access = " + str(returnDesc.allowsUnorderedAccess()) +
". Should fail if attempting with depth target = " + str(targetId == kMyDepthTarget))
1350 quadOp = self.mRenderOperations[kBackgroundBlit]
1351 if not quadOp
is None:
1352 quadOp.setRenderTargets(self.mTargets)
1354 sceneOp = self.mRenderOperations[kMaya3dSceneRender]
1355 if not sceneOp
is None:
1356 sceneOp.setRenderTargets(self.mTargets)
1357 sceneOp.setEnableSRGBWriteFlag( colorTargetSupportsSGRBWrite )
1359 opaqueSceneOp = self.mRenderOperations[kMaya3dSceneRenderOpaque]
1360 if not opaqueSceneOp
is None:
1361 opaqueSceneOp.setRenderTargets(self.mTargets)
1362 opaqueSceneOp.setEnableSRGBWriteFlag( colorTargetSupportsSGRBWrite )
1364 transparentSceneOp = self.mRenderOperations[kMaya3dSceneRenderTransparent]
1365 if not transparentSceneOp
is None:
1366 transparentSceneOp.setRenderTargets(self.mTargets)
1367 transparentSceneOp.setEnableSRGBWriteFlag( colorTargetSupportsSGRBWrite )
1369 uiSceneOp = self.mRenderOperations[kMaya3dSceneRenderUI]
1370 if not uiSceneOp
is None:
1371 uiSceneOp.setRenderTargets(self.mTargets)
1372 uiSceneOp.setEnableSRGBWriteFlag(
False )
1374 quadOp2 = self.mRenderOperations[kPostOperation1]
1375 if not quadOp2
is None:
1376 quadOp2.setRenderTargets(self.mTargets)
1378 quadOp3 = self.mRenderOperations[kPostOperation2]
1379 if not quadOp3
is None:
1380 quadOp3.setRenderTargets(self.mTargets)
1382 userOp = self.mRenderOperations[kUserOpNumber]
1383 if not userOp
is None:
1384 userOp.setRenderTargets(self.mTargets)
1385 userOp.setEnableSRGBWriteFlag( colorTargetSupportsSGRBWrite )
1387 presentOp = self.mRenderOperations[kPresentOp]
1388 if not presentOp
is None:
1389 presentOp.setRenderTargets(self.mTargets)
1391 thresholdOp = self.mRenderOperations[kThresholdOp]
1392 if not thresholdOp
is None:
1393 thresholdOp.setRenderTargets(self.mTargets)
1395 horizBlur = self.mRenderOperations[kHorizBlurOp]
1396 if not horizBlur
is None:
1397 horizBlur.setRenderTargets(self.mTargets)
1399 vertBlur = self.mRenderOperations[kVertBlurOp]
1400 if not vertBlur
is None:
1401 vertBlur.setRenderTargets(self.mTargets)
1403 blendOp = self.mRenderOperations[kBlendOp]
1404 if not blendOp
is None:
1405 blendOp.setRenderTargets(self.mTargets)
1407 hudOp = self.mRenderOperations[kHUDBlit]
1408 if not hudOp
is None:
1409 hudOp.setRenderTargets(self.mTargets)
1411 return (
not self.mTargets[kMyColorTarget]
is None and not self.mTargets[kMyDepthTarget]
is None and not self.mTargets[kMyBlurTarget]
is None)
1417 def setup(self, destination ):
1418 if self.mDebugOverride:
1419 print(self.name() +
" : Perform setup with panel [" + destination +
"]")
1424 self.mPanelName = destination
1433 if self.mRenderOperations[kPresentOp]
is None:
1436 if self.mSimpleRendering:
1437 self.mSplitUIDraw =
False
1439 self.mRenderOperations[kBackgroundBlit] =
None
1441 self.mRenderOperationNames[kMaya3dSceneRender] =
"__MySimpleSceneRender"
1442 sceneOp = simpleViewRenderSceneRender( self.mRenderOperationNames[kMaya3dSceneRender] )
1443 self.mRenderOperations[kMaya3dSceneRender] = sceneOp
1446 self.mRenderOperations[kMaya3dSceneRenderOpaque] =
None
1447 self.mRenderOperations[kMaya3dSceneRenderTransparent] =
None
1448 self.mRenderOperations[kThresholdOp] =
None
1449 self.mRenderOperations[kHorizBlurOp] =
None
1450 self.mRenderOperations[kVertBlurOp] =
None
1451 self.mRenderOperations[kPostOperation1] =
None
1452 self.mRenderOperations[kPostOperation2] =
None
1453 self.mRenderOperations[kMaya3dSceneRenderUI] =
None
1454 self.mRenderOperations[kUserOpNumber] =
None
1456 self.mRenderOperations[kHUDBlit] = viewRenderHUDOperation()
1457 self.mRenderOperationNames[kHUDBlit] = self.mRenderOperations[kHUDBlit].name()
1459 self.mRenderOperationNames[kPresentOp] =
"__MyPresentTarget"
1460 self.mRenderOperations[kPresentOp] = viewRenderPresentTarget( self.mRenderOperationNames[kPresentOp] )
1461 self.mRenderOperationNames[kPresentOp] = self.mRenderOperations[kPresentOp].name()
1466 rect = om.MFloatPoint(0.0, 0.0, 1.0, 1.0)
1470 self.mRenderOperationNames[kBackgroundBlit] =
"__MyPreQuadRender"
1471 quadOp = viewRenderQuadRender( self.mRenderOperationNames[kBackgroundBlit] )
1472 quadOp.setShader( viewRenderQuadRender.kPre_MandelBrot )
1473 quadOp.setViewRectangle(rect)
1474 self.mRenderOperations[kBackgroundBlit] = quadOp
1486 self.mSplitUIDraw =
True
1487 self.mRenderOperations[kMaya3dSceneRender] =
None
1488 self.mRenderOperations[kMaya3dSceneRenderOpaque] =
None
1489 self.mRenderOperations[kMaya3dSceneRenderTransparent] =
None
1490 self.mRenderOperations[kMaya3dSceneRenderUI] =
None
1491 if self.mSplitUIDraw:
1496 self.mRenderOperationNames[kMaya3dSceneRenderOpaque] =
"__MyStdSceneRenderOpaque"
1497 clearMask = omr.MClearOperation.kClearDepth | omr.MClearOperation.kClearStencil
1498 sceneOp = viewRenderSceneRender( self.mRenderOperationNames[kMaya3dSceneRenderOpaque], omr.MSceneRender.kRenderOpaqueShadedItems, clearMask )
1499 sceneOp.setViewRectangle(rect)
1500 self.mRenderOperations[kMaya3dSceneRenderOpaque] = sceneOp
1503 sDrawTransparent =
True
1504 if sDrawTransparent:
1505 self.mRenderOperationNames[kMaya3dSceneRenderTransparent] =
"__MyStdSceneRenderTransparent"
1506 clearMask = omr.MClearOperation.kClearDepth | omr.MClearOperation.kClearStencil
1508 clearMask = omr.MClearOperation.kClearNone
1509 sceneOp = viewRenderSceneRender( self.mRenderOperationNames[kMaya3dSceneRenderTransparent], omr.MSceneRender.kRenderTransparentShadedItems, clearMask )
1510 sceneOp.setViewRectangle(rect)
1511 self.mRenderOperations[kMaya3dSceneRenderTransparent] = sceneOp
1514 self.mRenderOperationNames[kMaya3dSceneRenderUI] =
"__MyStdSceneRenderUI"
1515 clearMask = omr.MClearOperation.kClearDepth | omr.MClearOperation.kClearStencil
1516 if sDrawOpaque
or sDrawTransparent:
1517 clearMask = omr.MClearOperation.kClearStencil
1518 sceneOp = viewRenderSceneRender( self.mRenderOperationNames[kMaya3dSceneRenderUI], omr.MSceneRender.kRenderUIItems, clearMask )
1519 sceneOp.setViewRectangle(rect)
1520 self.mRenderOperations[kMaya3dSceneRenderUI] = sceneOp
1523 self.mRenderOperationNames[kMaya3dSceneRender] =
"__MyStdSceneRender"
1524 clearMask = omr.MClearOperation.kClearDepth | omr.MClearOperation.kClearStencil
1525 sceneOp = viewRenderSceneRender( self.mRenderOperationNames[kMaya3dSceneRender], omr.MSceneRender.kNoSceneFilterOverride, clearMask )
1526 sceneOp.setViewRectangle(rect)
1527 self.mRenderOperations[kMaya3dSceneRender] = sceneOp
1533 self.mRenderOperationNames[kThresholdOp] =
"__ThresholdColor"
1534 quadThreshold = viewRenderQuadRender( self.mRenderOperationNames[kThresholdOp] )
1535 quadThreshold.setShader( viewRenderQuadRender.kScene_Threshold )
1536 quadThreshold.setViewRectangle(rect)
1537 self.mRenderOperations[kThresholdOp] = quadThreshold
1539 self.mRenderOperationNames[kHorizBlurOp] =
"__HorizontalBlur"
1540 quadHBlur = viewRenderQuadRender( self.mRenderOperationNames[kHorizBlurOp] )
1541 quadHBlur.setShader( viewRenderQuadRender.kScene_BlurHoriz )
1542 quadHBlur.setViewRectangle(rect)
1543 self.mRenderOperations[kHorizBlurOp] = quadHBlur
1545 self.mRenderOperationNames[kVertBlurOp] =
"__VerticalBlur"
1546 quadVBlur = viewRenderQuadRender( self.mRenderOperationNames[kVertBlurOp] )
1547 quadVBlur.setShader( viewRenderQuadRender.kScene_BlurVert )
1548 quadVBlur.setViewRectangle(rect)
1549 self.mRenderOperations[kVertBlurOp] = quadVBlur
1551 self.mRenderOperationNames[kBlendOp] =
"__SceneBlurBlend"
1552 quadBlend = viewRenderQuadRender( self.mRenderOperationNames[kBlendOp] )
1553 quadBlend.setShader( viewRenderQuadRender.kSceneBlur_Blend )
1554 quadBlend.setViewRectangle(rect)
1555 self.mRenderOperations[kBlendOp] = quadBlend
1559 self.mRenderOperationNames[kUserOpNumber] =
"__MyCustomSceneRender"
1560 userOp = viewRenderUserOperation( self.mRenderOperationNames[kUserOpNumber] )
1561 userOp.setViewRectangle(rect)
1562 self.mRenderOperations[kUserOpNumber] = userOp
1564 wantPostQuadOps =
False
1568 self.mRenderOperationNames[kPostOperation1] =
"__PostOperation1"
1569 quadOp2 = viewRenderQuadRender( self.mRenderOperationNames[kPostOperation1] )
1570 quadOp2.setShader( viewRenderQuadRender.kPost_EffectMonochrome )
1571 quadOp2.setViewRectangle(rect)
1573 self.mRenderOperations[kPostOperation1] = quadOp2
1575 self.mRenderOperations[kPostOperation1] =
None
1578 self.mRenderOperationNames[kPostOperation2] =
"__PostOperation2"
1579 quadOp3 = viewRenderQuadRender( self.mRenderOperationNames[kPostOperation2] )
1580 quadOp3.setShader( viewRenderQuadRender.kPost_EffectInvert )
1581 quadOp3.setViewRectangle(rect)
1583 self.mRenderOperations[kPostOperation2] = quadOp3
1585 self.mRenderOperations[kPostOperation2] =
None
1590 self.mRenderOperationNames[kPresentOp] =
"__MyPresentTarget"
1591 self.mRenderOperations[kPresentOp] = viewRenderPresentTarget( self.mRenderOperationNames[kPresentOp] )
1592 self.mRenderOperationNames[kPresentOp] = self.mRenderOperations[kPresentOp].name()
1595 self.mRenderOperations[kHUDBlit] = viewRenderHUDOperation()
1596 self.mRenderOperationNames[kHUDBlit] = self.mRenderOperations[kHUDBlit].name()
1599 if not self.mSimpleRendering:
1601 gotTargets = self.updateRenderTargets()
1605 if not self.mRenderOperations[kMaya3dSceneRender]
is None:
1606 self.mRenderOperations[kMaya3dSceneRender].setPanelName( self.mPanelName )
1607 if not self.mRenderOperations[kMaya3dSceneRenderOpaque]
is None:
1608 self.mRenderOperations[kMaya3dSceneRenderOpaque].setPanelName( self.mPanelName )
1609 if not self.mRenderOperations[kMaya3dSceneRenderTransparent]
is None:
1610 self.mRenderOperations[kMaya3dSceneRenderTransparent].setPanelName( self.mPanelName )
1611 if not self.mRenderOperations[kMaya3dSceneRenderUI]
is None:
1612 self.mRenderOperations[kMaya3dSceneRenderUI].setPanelName( self.mPanelName )
1613 if not self.mRenderOperations[kUserOpNumber]
is None:
1614 self.mRenderOperations[kUserOpNumber].setPanelName( self.mPanelName )
1616 self.mCurrentOperation = -1
1624 if self.mDebugOverride:
1625 print(self.name() +
" : Perform cleanup. panelname=" + self.mPanelName)
1627 quadOp = self.mRenderOperations[kPostOperation1]
1628 if not quadOp
is None:
1629 quadOp.setRenderTargets(
None)
1631 quadOp = self.mRenderOperations[kPostOperation2]
1632 if not quadOp
is None:
1633 quadOp.setRenderTargets(
None)
1636 self.mPanelName =
""
1638 self.mCurrentOperation = -1
1640 def panelName(self):
1641 return self.mPanelName
1643 def setSimpleRendering(self, flag):
1644 self.mSimpleRendering = flag
1650 viewRenderOverrideInstance =
None
1655 def initializePlugin(obj):
1656 plugin = om.MFnPlugin(obj)
1658 global viewRenderOverrideInstance
1659 viewRenderOverrideInstance = viewRenderOverride(
"my_viewRenderOverride" )
1660 omr.MRenderer.registerOverride(viewRenderOverrideInstance)
1662 sys.stderr.write(
"registerOverride\n")
1671 def uninitializePlugin(obj):
1672 plugin = om.MFnPlugin(obj)
1674 global viewRenderOverrideInstance
1675 if not viewRenderOverrideInstance
is None:
1676 omr.MRenderer.deregisterOverride(viewRenderOverrideInstance)
1677 viewRenderOverrideInstance =
None
1679 sys.stderr.write(
"deregisterOverride\n")