10 from OpenGL.GL
import *
11 import maya.api.OpenMayaRender
as omr
12 import maya.api.OpenMayaUI
as omui
13 import maya.api.OpenMaya
as om
17 The presence of this function tells Maya that the plugin produces, and
18 expects to be passed, objects created using the Maya Python API 2.0.
24 kMaya3dSceneRender = 1
25 kMaya3dSceneRenderOpaque = 2
26 kMaya3dSceneRenderTransparent = 3
33 kMaya3dSceneRenderUI = 10
48 def printDrawContextLightInfo(drawContext):
50 considerAllSceneLights = omr.MDrawContext.kFilteredIgnoreLightLimit
51 omr.MRenderer.needEvaluateAllLights()
52 lightCount = drawContext.numberOfActiveLights(considerAllSceneLights)
56 positions = om.MFloatPointArray()
57 position = om.MFloatPoint(0, 0, 0)
58 direction = om.MFloatVector()
62 for i
in range(lightCount):
63 lightParam = drawContext.getLightParameterInformation( i, considerAllSceneLights )
64 if not lightParam
is None:
65 print "\tLight " + str(i) +
"\n\t{"
67 for pname
in lightParam.parameterList():
68 ptype = lightParam.parameterType(pname)
69 if ptype == omr.MLightParameterInformation.kBoolean:
70 print "\t\tLight parameter " + pname +
". Bool " + str(lightParam.getParameter(pname))
71 elif ptype == omr.MLightParameterInformation.kInteger:
72 print "\t\tLight parameter " + pname +
". Integer " + str(lightParam.getParameter(pname))
73 elif ptype == omr.MLightParameterInformation.kFloat:
74 print "\t\tLight parameter " + pname +
". Float " + str(lightParam.getParameter(pname))
75 elif ptype == omr.MLightParameterInformation.kFloat2:
76 print "\t\tLight parameter " + pname +
". Float " + str(lightParam.getParameter(pname))
77 elif ptype == omr.MLightParameterInformation.kFloat3:
78 print "\t\tLight parameter " + pname +
". Float3 " + str(lightParam.getParameter(pname))
79 elif ptype == omr.MLightParameterInformation.kFloat4:
80 print "\t\tLight parameter " + pname +
". Float4 " + str(lightParam.getParameter(pname))
81 elif ptype == omr.MLightParameterInformation.kFloat4x4Row:
82 print "\t\tLight parameter " + pname +
". Float4x4Row " + str(lightParam.getParameter(pname))
83 elif ptype == omr.MLightParameterInformation.kFloat4x4Col:
84 print "\t\tLight parameter " + pname +
". kFloat4x4Col " + str(lightParam.getParameter(pname))
85 elif ptype == omr.MLightParameterInformation.kTexture2:
87 print "\t\tLight texture parameter " + pname +
". OpenGL texture id = " + str(lightParam.getParameterTextureHandle(pname))
90 elif ptype == omr.MLightParameterInformation.kSampler:
91 print "\t\tLight sampler parameter " + pname +
". filter = " + str(lightParam.getParameter(pname).filter)
96 semantic = lightParam.parameterSemantic(pname)
97 if semantic == omr.MLightParameterInformation.kLightEnabled:
98 print "\t\t- Parameter semantic : light enabled"
99 elif semantic == omr.MLightParameterInformation.kWorldPosition:
100 print "\t\t- Parameter semantic : world position"
101 floatVals = lightParam.getParameter(pname)
102 position += om.MFloatPoint( floatVals[0], floatVals[1], floatVals[2] )
103 positionCount = positionCount + 1
104 elif semantic == omr.MLightParameterInformation.kWorldDirection:
105 print "\t\t- Parameter semantic : world direction"
106 direction = lightParam.getParameter(pname)
107 elif semantic == omr.MLightParameterInformation.kIntensity:
108 print "\t\t- Parameter semantic : intensity"
109 elif semantic == omr.MLightParameterInformation.kColor:
110 print "\t\t- Parameter semantic : color"
111 color = om.MColor( lightParam.getParameter(pname) )
112 elif semantic == omr.MLightParameterInformation.kEmitsDiffuse:
113 print "\t\t- Parameter semantic : emits-diffuse"
114 elif semantic == omr.MLightParameterInformation.kEmitsSpecular:
115 print "\t\t- Parameter semantic : emits-specular"
116 elif semantic == omr.MLightParameterInformation.kDecayRate:
117 print "\t\t- Parameter semantic : decay rate"
118 elif semantic == omr.MLightParameterInformation.kDropoff:
119 print "\t\t- Parameter semantic : drop-off"
120 elif semantic == omr.MLightParameterInformation.kCosConeAngle:
121 print "\t\t- Parameter semantic : cosine cone angle"
122 elif semantic == omr.MLightParameterInformation.kShadowMap:
123 print "\t\t- Parameter semantic : shadow map"
124 elif semantic == omr.MLightParameterInformation.kShadowSamp:
125 print "\t\t- Parameter semantic : shadow map sampler"
126 elif semantic == omr.MLightParameterInformation.kShadowBias:
127 print "\t\t- Parameter semantic : shadow map bias"
128 elif semantic == omr.MLightParameterInformation.kShadowMapSize:
129 print "\t\t- Parameter semantic : shadow map size"
130 elif semantic == omr.MLightParameterInformation.kShadowViewProj:
131 print "\t\t- Parameter semantic : shadow map view projection matrix"
132 elif semantic == omr.MLightParameterInformation.kShadowColor:
133 print "\t\t- Parameter semantic : shadow color"
134 elif semantic == omr.MLightParameterInformation.kGlobalShadowOn:
135 print "\t\t- Parameter semantic : global shadows on"
136 elif semantic == omr.MLightParameterInformation.kShadowOn:
137 print "\t\t- Parameter semantic : local shadows on"
140 if positionCount > 1:
141 position /= positionCount
142 print "\t\tCompute average position " + str(position)
145 print "\t\tSemantic -> Parameter Name Lookups"
146 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kLightEnabled)
149 floatVals = lightParam.getParameter(omr.MLightParameterInformation.kLightEnabled)
152 print "\t\t\tkLightEnabled -> " + str(paramNames) +
" -- " + str(floatVals)
153 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kWorldPosition)
154 print "\t\t\tkWorldPosition -> " + str(paramNames)
155 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kWorldDirection)
156 print "\t\t\tkWorldDirection -> " + str(paramNames)
157 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kIntensity)
158 print "\t\t\tkIntensity -> " + str(paramNames)
159 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kColor)
160 print "\t\t\tkColor -> " + str(paramNames)
161 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kEmitsDiffuse)
162 print "\t\t\tkEmitsDiffuse -> " + str(paramNames)
163 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kEmitsSpecular)
164 print "\t\t\tkEmitsSpecular -> " + str(paramNames)
165 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kDecayRate)
166 print "\t\t\tkDecayRate -> " + str(paramNames)
167 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kDropoff)
168 print "\t\t\tkDropoff -> " + str(paramNames)
169 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kCosConeAngle)
170 print "\t\t\tkCosConeAngle -> " + str(paramNames)
171 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kIrradianceIn)
172 print "\t\t\tkIrradianceIn -> " + str(paramNames)
173 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kShadowMap)
174 print "\t\t\tkShadowMap -> " + str(paramNames)
175 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kShadowSamp)
176 print "\t\t\tkShadowSamp -> " + str(paramNames)
177 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kShadowBias)
178 print "\t\t\tkShadowBias -> " + str(paramNames)
179 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kShadowMapSize)
180 print "\t\t\tkShadowMapSize -> " + str(paramNames)
181 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kShadowColor)
182 print "\t\t\tkShadowColor -> " + str(paramNames)
183 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kGlobalShadowOn)
184 print "\t\t\tkGlobalShadowOn -> " + str(paramNames)
185 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kShadowOn)
186 print "\t\t\tkShadowOn -> " + str(paramNames)
202 def callbackDataPrint(context, renderItemList, shaderInstance):
203 if not shaderInstance
is None:
204 paramNames = shaderInstance.parameterList()
205 paramCount = len(paramNames)
206 print "\tSHADER: # of parameters = " + str(paramCount)
207 for i
in range(paramCount):
208 print "\t\tPARAM[" + paramNames[i] +
"]"
210 numItems = len(renderItemList)
211 for i
in range(numItems):
212 item = renderItemList[i]
214 path = item.sourceDagPath()
215 print "\tRENDER ITEM: '" + item.name() +
"' -- SOURCE: '" + path.fullPathName() +
"'"
217 passCtx = context.getPassContext()
218 passId = passCtx.passIdentifier()
219 passSem = passCtx.passSemantics()
220 print "PASS ID[" + passId +
"], PASS SEMANTICS[" + str(passSem) +
"]"
228 def shaderOverrideCallbackBindLightingInfo(drawContext, renderItemList, shaderInstance):
229 if shaderInstance
is None:
234 globalShadowsOn =
False
235 localShadowsOn =
False
236 direction = om.MFloatVector(0.0, 0.0, 1.0)
238 lightColor = [ 0.0, 0.0, 0.0 ]
243 considerAllSceneLights = omr.MDrawContext.kFilteredIgnoreLightLimit
244 omr.MRenderer.needEvaluateAllLights()
245 lightCount = drawContext.numberOfActiveLights(considerAllSceneLights)
247 shadowViewProj = om.MMatrix()
248 shadowResourceTexture =
None
249 samplerDesc = omr.MSamplerStateDesc()
250 shadowColor = [ 0.0, 0.0, 0.0 ]
252 foundDirectional =
False
253 for i
in range(lightCount):
256 globalShadowsOn =
False
257 localShadowsOn =
False
258 direction = om.MFloatVector(0.0, 0.0, 1.0)
260 lightColor = [ 0.0, 0.0, 0.0 ]
262 lightParam = drawContext.getLightParameterInformation( i, considerAllSceneLights )
263 if not lightParam
is None:
264 for pname
in lightParam.parameterList():
265 semantic = lightParam.parameterSemantic( pname )
267 if semantic == omr.MLightParameterInformation.kWorldDirection:
268 floatVals = lightParam.getParameter( pname )
269 direction = om.MFloatVector( floatVals[0], floatVals[1], floatVals[2] )
270 foundDirectional =
True
271 elif semantic == omr.MLightParameterInformation.kIntensity:
272 floatVals = lightParam.getParameter( pname )
273 lightIntensity = floatVals[0]
274 elif semantic == omr.MLightParameterInformation.kColor:
275 lightColor = lightParam.getParameter( pname )
278 elif semantic == omr.MLightParameterInformation.kGlobalShadowOn:
279 intVals = lightParam.getParameter( pname )
281 globalShadowsOn = (intVals[0] != 0)
282 elif semantic == omr.MLightParameterInformation.kShadowOn:
283 intVals = lightParam.getParameter( pname )
285 localShadowsOn = (intVals[0] != 0)
286 elif semantic == omr.MLightParameterInformation.kShadowViewProj:
287 shadowViewProj = lightParam.getParameter( pname )
288 elif semantic == omr.MLightParameterInformation.kShadowMap:
289 shadowResourceTexture = lightParam.getParameter( pname )
290 elif semantic == omr.MLightParameterInformation.kShadowSamp:
291 samplerDesc = lightParam.getParameter( pname )
292 elif semantic == omr.MLightParameterInformation.kShadowColor:
293 shadowColor = lightParam.getParameter( pname )
297 if foundDirectional
and globalShadowsOn
and localShadowsOn
and not shadowResourceTexture
is None:
298 resourceHandle = shadowResourceTexture.resourceHandle()
299 if resourceHandle > 0:
300 debugShadowBindings =
False
302 shaderInstance.setParameter(
"mayaShadowPCF1_shadowMap", shadowResource )
303 if debugShadowBindings:
304 print "Bound shadow map to shader param mayaShadowPCF1_shadowMap"
308 shaderInstance.setParameter(
"mayaShadowPCF1_shadowViewProj", shadowViewProj )
309 if debugShadowBindings:
310 print "Bound shadow map transform to shader param mayaShadowPCF1_shadowViewProj"
314 shaderInstance.setParameter(
"mayaShadowPCF1_shadowColor", shadowColor )
315 if debugShadowBindings:
316 print "Bound shadow map color to shader param mayaShadowPCF1_shadowColor"
320 textureManager = omr.MRenderer.getTextureManager()
321 if not textureManager
is None:
322 textureManager.releaseTexture(shadowResourceTexture)
323 shadowResourceTexture =
None
326 shaderInstance.setParameter(
"mayaDirectionalLight_direction", direction)
327 shaderInstance.setParameter(
"mayaDirectionalLight_intensity", lightIntensity)
328 shaderInstance.setParameter(
"mayaDirectionalLight_color", lightColor)
329 shaderInstance.setParameter(
"mayaShadowPCF1_mayaGlobalShadowOn", globalShadowsOn)
330 shaderInstance.setParameter(
"mayaShadowPCF1_mayaShadowOn", localShadowsOn)
335 def shaderOverridePreDrawCallback(context, renderItemList, shaderInstance):
336 print "PRE-draw callback triggered for render item list with data:"
337 callbackDataPrint(context, renderItemList, shaderInstance)
341 printDrawContextLightInfo( context )
347 def shaderOverridePostDrawCallback(context, renderItemList, shaderInstance):
348 print "POST-draw callback triggered for render item list with data:"
349 callbackDataPrint(context, renderItemList, shaderInstance)
356 class viewRenderHUDOperation(omr.MHUDRender):
358 omr.MHUDRender.__init__(self)
363 def targetOverrideList(self):
364 if not self.mTargets
is None:
365 return [ self.mTargets[kMyColorTarget], self.mTargets[kMyDepthTarget] ]
368 def hasUIDrawables(self):
371 def addUIDrawables(self, drawManager2D, frameContext):
373 drawManager2D.beginDrawable()
375 drawManager2D.setColor( om.MColor( (0.455, 0.212, 0.596) ) )
377 drawManager2D.setFontSize( omr.MUIDrawManager.kSmallFontSize )
380 dim = frameContext.getViewportDimensions()
385 drawManager2D.text( om.MPoint(w*0.5, h*0.91),
"Sample VP2 Renderer Override", omr.MUIDrawManager.kCenter )
388 viewportInfoText =
"Viewport information: x= "
389 viewportInfoText += str(x)
390 viewportInfoText +=
", y= "
391 viewportInfoText += str(y)
392 viewportInfoText +=
", w= "
393 viewportInfoText += str(w)
394 viewportInfoText +=
", h= "
395 viewportInfoText += str(h)
396 drawManager2D.text( om.MPoint(w*0.5, h*0.885), viewportInfoText, omr.MUIDrawManager.kCenter )
399 drawManager2D.endDrawable()
401 def setRenderTargets(self, targets):
402 self.mTargets = targets
411 class viewRenderPresentTarget(omr.MPresentTarget):
412 def __init__(self, name):
413 omr.MPresentTarget.__init__(self, name)
418 def targetOverrideList(self):
419 if not self.mTargets
is None:
420 return [ self.mTargets[kMyColorTarget], self.mTargets[kMyDepthTarget] ]
423 def setRenderTargets(self, targets):
424 self.mTargets = targets
434 class viewRenderQuadRender(omr.MQuadRender):
437 kPost_EffectMonochrome = 1
438 kPost_EffectEdgeDetect = 2
439 kPost_EffectInvert = 3
446 def __init__(self, name):
447 omr.MQuadRender.__init__(self, name)
450 self.mShaderInstance =
None
454 self.mViewRectangle = om.MFloatPoint()
456 self.mShader = self.kEffectNone
459 if not self.mShaderInstance
is None:
460 shaderMgr = omr.MRenderer.getShaderManager()
461 if not shaderMgr
is None:
462 shaderMgr.releaseShader(self.mShaderInstance)
463 self.mShaderInstance =
None
470 if self.mShaderInstance
is None:
471 shaderMgr = omr.MRenderer.getShaderManager()
472 if not shaderMgr
is None:
485 if self.mShader == self.kPre_MandelBrot:
486 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"MandelBrot",
"" )
487 elif self.mShader == self.kPost_EffectMonochrome:
488 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"FilterMonochrome",
"" )
489 elif self.mShader == self.kPost_EffectEdgeDetect:
490 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"FilterEdgeDetect",
"" )
491 elif self.mShader == self.kPost_EffectInvert:
492 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"Invert",
"" )
493 elif self.mShader == self.kScene_Threshold:
494 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"Threshold",
"" )
495 elif self.mShader == self.kScene_BlurHoriz:
496 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"Blur",
"BlurHoriz" )
497 elif self.mShader == self.kScene_BlurVert:
498 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"Blur",
"BlurVert" )
499 elif self.mShader == self.kSceneBlur_Blend:
500 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"Blend",
"Add" )
507 if not self.mShaderInstance
is None:
508 if self.mShader == self.kPre_MandelBrot:
511 self.mShaderInstance.setParameter(
"gIterate", 50)
513 print "Could not change mandelbrot parameter"
516 elif self.mShader == self.kPost_EffectInvert:
520 self.mShaderInstance.setParameter(
"gInputTex", self.mTargets[kMyColorTarget])
522 print "Could not set input render target / texture parameter on invert shader"
525 elif self.mShader == self.kScene_Threshold:
529 self.mShaderInstance.setParameter(
"gSourceTex", self.mTargets[kMyColorTarget])
531 print "Could not set input render target / texture parameter on threshold shader"
533 self.mShaderInstance.setParameter(
"gBrightThreshold", 0.7 )
535 elif self.mShader == self.kScene_BlurHoriz:
539 self.mShaderInstance.setParameter(
"gSourceTex", self.mTargets[kMyBlurTarget])
541 print "Could not set input render target / texture parameter on hblur shader"
544 elif self.mShader == self.kScene_BlurVert:
548 self.mShaderInstance.setParameter(
"gSourceTex", self.mTargets[kMyBlurTarget])
550 print "Could not set input render target / texture parameter on vblur shader"
553 elif self.mShader == self.kSceneBlur_Blend:
557 self.mShaderInstance.setParameter(
"gSourceTex", self.mTargets[kMyColorTarget])
563 self.mShaderInstance.setParameter(
"gSourceTex2", self.mTargets[kMyBlurTarget])
566 self.mShaderInstance.setParameter(
"gBlendSrc", 0.3 )
568 elif self.mShader == self.kPost_EffectMonochrome:
572 self.mShaderInstance.setParameter(
"gInputTex", self.mTargets[kMyColorTarget])
574 print "Could not set input render target / texture parameter on monochrome shader"
577 elif self.mShader == self.kPost_EffectEdgeDetect:
581 self.mShaderInstance.setParameter(
"gInputTex", self.mTargets[kMyColorTarget])
583 print "Could not set input render target / texture parameter on edge detect shader"
585 self.mShaderInstance.setParameter(
"gThickness", 1.0 )
586 self.mShaderInstance.setParameter(
"gThreshold", 0.1 )
588 return self.mShaderInstance
595 def targetOverrideList(self):
596 if not self.mTargets
is None:
598 if self.mShader == self.kScene_Threshold
or self.mShader == self.kScene_BlurHoriz
or self.mShader == self.kScene_BlurVert:
599 return [ self.mTargets[kMyBlurTarget] ]
601 return [ self.mTargets[kMyColorTarget], self.mTargets[kMyDepthTarget] ]
605 def clearOperation(self):
606 clearOp = self.mClearOperation
608 if self.mShader == self.kPre_MandelBrot:
609 clearOp.setClearGradient(
False )
610 clearOp.setMask( omr.MClearOperation.kClearAll )
613 clearOp.setClearGradient(
False )
614 clearOp.setMask( omr.MClearOperation.kClearNone )
617 def setRenderTargets(self, targets):
618 self.mTargets = targets
620 def setShader(self, shader):
621 self.mShader = shader
623 def viewRectangle(self):
624 return self.mViewRectangle
626 def setViewRectangle(self, rect):
627 self.mViewRectangle = rect
635 class simpleViewRenderSceneRender(omr.MSceneRender):
636 def __init__(self, name):
637 omr.MSceneRender.__init__(self, name)
639 self.mViewRectangle = om.MFloatPoint(0.0, 0.0, 1.0, 1.0)
641 def viewportRectangleOverride(self):
643 testRectangleSize =
False
644 if testRectangleSize:
646 self.mViewRectangle = om.MFloatPoint(0.33, 0.10, 0.50, 0.50)
647 return self.mViewRectangle
649 def clearOperation(self):
651 val1 = [ 0.0, 0.2, 0.8, 1.0 ]
652 val2 = [ 0.5, 0.4, 0.1, 1.0 ]
653 clearOp = self.mClearOperation
654 clearOp.setClearColor( val1 )
655 clearOp.setClearColor2( val2 )
656 clearOp.setClearGradient(
True )
666 class viewRenderSceneRender(omr.MSceneRender):
667 def __init__(self, name, sceneFilter, clearMask):
668 omr.MSceneRender.__init__(self, name)
670 self.mSelectionList = om.MSelectionList()
675 self.mCameraOverride = omr.MCameraOverride()
677 self.mViewRectangle = om.MFloatPoint(0.0, 0.0, 1.0, 1.0)
681 self.mShaderOverride =
None
683 self.mSceneFilter = sceneFilter
685 self.mClearMask = clearMask
688 self.mUseShaderOverride =
False
689 self.mUseStockShaderOverride =
False
690 self.mAttachPrePostShaderCallback =
False
691 self.mUseShadowShader =
False
692 self.mOverrideDisplayMode =
True
693 self.mOverrideLightingMode =
False
694 self.mOverrideCullingMode =
False
695 self.mDebugTargetResourceHandle =
False
696 self.mOverrrideM3dViewDisplayMode =
False
697 self.mPrevDisplayStyle = omui.M3dView.kGouraudShaded
698 self.mFilterDrawNothing =
False
699 self.mFilterDrawSelected =
False
700 self.mEnableSRGBWrite =
False
704 if not self.mShaderOverride
is None:
705 shaderMgr = omr.MRenderer.getShaderManager()
706 if not shaderMgr
is None:
707 shaderMgr.releaseShader(self.mShaderOverride)
708 self.mShaderOverride =
None
710 def setRenderTargets(self, targets):
711 self.mTargets = targets
713 def targetOverrideList(self):
714 if not self.mTargets
is None:
715 return [ self.mTargets[kMyColorTarget], self.mTargets[kMyDepthTarget] ]
719 def enableSRGBWrite(self):
720 return self.mEnableSRGBWrite
724 def cameraOverride(self):
725 if len(self.mPanelName) > 0:
726 view = omui.M3dView.getM3dViewFromModelPanel(self.mPanelName)
727 self.mCameraOverride.mCameraPath = view.getCamera()
728 return self.mCameraOverride
730 print "\t" + self.mName +
": Query custom scene camera override -- no override set"
735 def renderFilterOverride(self):
736 return self.mSceneFilter
742 def displayModeOverride(self):
743 if self.mOverrideDisplayMode:
744 return ( omr.MSceneRender.kBoundingBox | omr.MSceneRender.kShaded )
745 return omr.MSceneRender.kNoDisplayModeOverride
749 def lightModeOverride(self):
750 if self.mOverrideLightingMode:
751 return omr.MSceneRender.kSelectedLights
752 return omr.MSceneRender.kNoLightingModeOverride
755 def shadowEnableOverride(self):
756 if (self.mSceneFilter & omr.MSceneRender.kRenderShadedItems) == 0:
764 def cullingOverride(self):
765 if self.mOverrideCullingMode:
766 return omr.MSceneRender.kCullBackFaces
767 return omr.MSceneRender.kNoCullingOverride
774 if self.mOverrrideM3dViewDisplayMode:
775 if len(self.mPanelName) > 0:
776 view = omui.M3dView.getM3dViewFromModelPanel(self.mPanelName)
777 self.mPrevDisplayStyle = view.displayStyle();
778 view.setDisplayStyle( omui.M3dView.kGouraudShaded )
784 def postRender(self):
785 if self.mDebugTargetResourceHandle:
789 if not self.mTargets[kMyColorTarget]
is None:
790 colorResourceHandle = self.mTargets[kMyColorTarget].resourceHandle()
791 print "\t - Color target resource handle = " + str(colorResourceHandle)
793 if not self.mTargets[kMyDepthTarget]
is None:
794 depthStencilResourceHandle = self.mTargets[kMyDepthTarget].resourceHandle()
795 print "\t - Depth target resource handle = " + str(depthStencilResourceHandle)
797 if self.mOverrrideM3dViewDisplayMode:
798 if len(self.mPanelName) > 0:
799 view = omui.M3dView.getM3dViewFromModelPanel(self.mPanelName)
800 view.setDisplayStyle( self.mPrevDisplayStyle )
804 def getObjectTypeExclusions(self):
806 return omr.MFrameContext.kExcludeCameras
817 def objectSetOverride(self):
818 self.mSelectionList.clear()
824 if self.mFilterDrawNothing:
825 return self.mSelectionList
830 if self.mFilterDrawSelected:
831 selList = om.MGlobal.getActiveSelectionList()
832 if selList.length() > 0:
833 iter = om.MItSelectionList(selList)
834 while not iter.isDone():
835 comp = iter.getComponent()
836 self.mSelectionList.add( comp[0], comp[1] )
839 if self.mSelectionList.length() > 0:
840 print "\t" + self.name() +
" : Filtering render with active object list"
841 return self.mSelectionList
850 def clearOperation(self):
851 clearOp = self.mClearOperation
852 if (self.mSceneFilter & (omr.MSceneRender.kRenderOpaqueShadedItems | omr.MSceneRender.kRenderTransparentShadedItems | omr.MSceneRender.kRenderUIItems)) != 0:
853 clearOp.setClearGradient(
False)
857 val1 = [ 0.0, 0.2, 0.8, 1.0 ]
858 val2 = [ 0.5, 0.4, 0.1, 1.0 ]
859 clearOp.setClearColor(val1)
860 clearOp.setClearColor2(val2)
861 clearOp.setClearGradient(
True)
863 clearOp.setMask(self.mClearMask)
871 def shaderOverride(self):
872 if self.mUseShaderOverride:
873 if self.mShaderOverride
is None:
874 shaderManager = omr.MRenderer.getShaderManager()
875 if not shaderManager
is None:
878 if not self.mUseStockShaderOverride:
879 if self.mUseShadowShader:
882 preCallBack = shaderOverrideCallbackBindLightingInfo
883 self.mShaderOverride = shaderManager.getEffectsFileShader(
"MayaBlinnDirectionalLightShadow",
"",
None,
True, preCallBack, postCallBack)
886 if self.mAttachPrePostShaderCallback:
887 preCallBack = shaderOverridePreDrawCallback
888 if self.mAttachPrePostShaderCallback:
889 postCallBack = shaderOverridePostDrawCallback
890 self.mShaderOverride = shaderManager.getEffectsFileShader(
"Gooch",
"",
None,
True, preCallBack, postCallBack)
894 if self.mAttachPrePostShaderCallback:
895 preCallBack = shaderOverridePreDrawCallback
896 if self.mAttachPrePostShaderCallback:
897 postCallBack = shaderOverridePostDrawCallback
898 self.mShaderOverride = shaderManager.getStockShader( omr.MShaderManager.k3dBlinnShader, preCallBack, postCallBack)
900 if not self.mShaderOverride
is None:
901 print "\t" + self.name() +
" : Set stock shader override " + str(omr.MShaderManager.k3dBlinnShader)
902 diffColor = [0.0, 0.4, 1.0, 1.0]
904 self.mShaderOverride.setParameter(
"diffuseColor", diffColor)
906 print "Could not set diffuseColor on shader"
908 return self.mShaderOverride
913 def hasUIDrawables(self):
917 def addPreUIDrawables(self, drawManager, frameContext):
918 drawManager.beginDrawable()
919 drawManager.setColor( om.MColor( (0.1, 0.5, 0.95) ) )
920 drawManager.setFontSize( omr.MUIDrawManager.kSmallFontSize )
921 drawManager.text( om.MPoint( -2, 2, -2 ),
"Pre UI draw test in Scene operation", omr.MUIDrawManager.kRight )
922 drawManager.line( om.MPoint( -2, 0, -2 ), om.MPoint( -2, 2, -2 ) )
923 drawManager.setColor( om.MColor( (1.0, 1.0, 1.0) ) )
924 drawManager.sphere( om.MPoint( -2, 2, -2 ), 0.8,
False )
925 drawManager.setColor( om.MColor( (0.1, 0.5, 0.95, 0.4) ) )
926 drawManager.sphere( om.MPoint( -2, 2, -2 ), 0.8,
True )
927 drawManager.endDrawable()
930 def addPostUIDrawables(self, drawManager, frameContext):
931 drawManager.beginDrawable()
932 drawManager.setColor( om.MColor( (0.05, 0.95, 0.34) ) )
933 drawManager.setFontSize( omr.MUIDrawManager.kSmallFontSize )
934 drawManager.text( om.MPoint( 2, 2, 2 ),
"Post UI draw test in Scene operation", omr.MUIDrawManager.kLeft )
935 drawManager.line( om.MPoint( 2, 0, 2), om.MPoint( 2, 2, 2 ) )
936 drawManager.setColor( om.MColor( (1.0, 1.0, 1.0) ) )
937 drawManager.sphere( om.MPoint( 2, 2, 2 ), 0.8,
False )
938 drawManager.setColor( om.MColor( (0.05, 0.95, 0.34, 0.4) ) )
939 drawManager.sphere( om.MPoint( 2, 2, 2 ), 0.8,
True )
940 drawManager.endDrawable()
943 return self.mPanelName
945 def setPanelName(self, name):
946 self.mPanelName = name
948 def viewRectangle(self):
949 return self.mViewRectangle
951 def setViewRectangle(self, rect):
952 self.mViewRectangle = rect
954 def colorTarget(self):
955 if not self.mTargets
is None:
956 return self.mTargets[kMyColorTarget]
959 def depthTarget(self):
960 if not self.mTargets
is None:
961 return self.mTargets[kMyDepthTarget]
964 def setEnableSRGBWriteFlag(self, val):
965 self.mEnableSRGBWrite = val
967 def enableSRGBWriteFlag(self):
968 return self.mEnableSRGBWrite
978 class MCustomSceneDraw:
980 def matrixAsArray(self, matrix):
983 array.append(matrix[i])
987 def drawBounds(self, dagPath, box):
988 matrix = dagPath.inclusiveMatrix()
992 bottomLeftFront = [ minPt.x, minPt.y, minPt.z ]
993 topLeftFront = [ minPt.x, maxPt.y, minPt.z ]
994 bottomRightFront = [ maxPt.x, minPt.y, minPt.z ]
995 topRightFront = [ maxPt.x, maxPt.y, minPt.z ]
996 bottomLeftBack = [ minPt.x, minPt.y, maxPt.z ]
997 topLeftBack = [ minPt.x, maxPt.y, maxPt.z ]
998 bottomRightBack = [ maxPt.x, minPt.y, maxPt.z ]
999 topRightBack = [ maxPt.x, maxPt.y, maxPt.z ]
1001 glMatrixMode( GL_MODELVIEW )
1003 glMultMatrixd( self.matrixAsArray(matrix) )
1005 glBegin( GL_LINE_STRIP )
1006 glVertex3dv( bottomLeftFront )
1007 glVertex3dv( bottomLeftBack )
1008 glVertex3dv( topLeftBack )
1009 glVertex3dv( topLeftFront )
1010 glVertex3dv( bottomLeftFront )
1011 glVertex3dv( bottomRightFront )
1012 glVertex3dv( bottomRightBack)
1013 glVertex3dv( topRightBack )
1014 glVertex3dv( topRightFront )
1015 glVertex3dv( bottomRightFront )
1019 glVertex3dv(bottomLeftBack)
1020 glVertex3dv(bottomRightBack)
1022 glVertex3dv(topLeftBack)
1023 glVertex3dv(topRightBack)
1025 glVertex3dv(topLeftFront)
1026 glVertex3dv(topRightFront)
1032 def draw(self, cameraPath, size):
1033 if not cameraPath.isValid:
1037 MDrawTraversal *trav = NULL;
1038 trav = new MSurfaceDrawTraversal;
1043 trav->enableFiltering( true );
1044 trav->setFrustum( cameraPath, width, height );
1045 if (!trav->frustumValid())
1047 delete trav; trav = NULL;
1052 unsigned int numItems = trav->numberOfItems();
1054 for (i=0; i<numItems; i++)
1057 trav->itemPath(i, path);
1061 bool drawIt = false;
1064 // Draw surfaces (polys, nurbs, subdivs)
1066 if ( path.hasFn( MFn::kMesh) ||
1067 path.hasFn( MFn::kNurbsSurface) ||
1068 path.hasFn( MFn::kSubdiv) )
1071 if (trav->itemHasStatus( i, MDrawTraversal::kActiveItem ))
1073 gGLFT->glColor3f( 1.0f, 1.0f, 1.0f );
1075 else if (trav->itemHasStatus( i, MDrawTraversal::kTemplateItem ))
1077 gGLFT->glColor3f( 0.2f, 0.2f, 0.2f );
1081 if (path.hasFn( MFn::kMesh ))
1082 gGLFT->glColor3f( 0.286f, 0.706f, 1.0f );
1083 else if (path.hasFn( MFn::kNurbsSurface))
1084 gGLFT->glColor3f( 0.486f, 0.306f, 1.0f );
1086 gGLFT->glColor3f( 0.886f, 0.206f, 1.0f );
1092 MFnDagNode dagNode(path);
1093 MBoundingBox box = dagNode.boundingBox();
1094 drawBounds( path, box );
1120 class viewRenderUserOperation(omr.MUserRenderOperation):
1121 def __init__(self, name):
1122 omr.MUserRenderOperation.__init__(self, name)
1125 self.mPanelName =
""
1127 self.mCameraOverride = omr.MCameraOverride()
1129 self.mViewRectangle = om.MFloatPoint(0.0, 0.0, 1.0, 1.0)
1131 self.mTargets =
None
1133 self.fEnableSRGBWriteFlag =
False
1135 self.fDrawLabel =
False
1137 self.fUserCameraOverride =
False
1139 self.fDrawBoundingBoxes =
False
1141 self.fDebugDrawContext =
False
1142 self.fDebugLightingInfo =
False
1144 def execute(self, drawContext):
1146 debugPassInformation =
False
1147 if debugPassInformation:
1148 passCtx = drawContext.getPassContext()
1149 passId = passCtx.passIdentifier()
1150 passSem = passCtx.passSemantics()
1151 print "viewRenderUserOperation: drawing in pass[" + str(passId) +
"], semantic[" + str(passSem) +
"]"
1158 overrideName = omr.MRenderer.activeRenderOverride()
1159 overrideFunc = omr.MRenderer.findRenderOverride( overrideName )
1163 if self.fDebugLightingInfo:
1164 printDrawContextLightInfo( drawContext )
1168 if self.fDebugDrawContext:
1169 matrix = drawContext.getMatrix(omr.MFrameContext.kWorldMtx)
1170 print "World matrix is: " + str(matrix)
1172 viewDirection = drawContext.getTuple(omr.MFrameContext.kViewDirection)
1173 print "Viewdirection is: " + str(viewDirection)
1175 box = drawContext.getSceneBox()
1176 print "Screen box is: " + str(box)
1177 print "\tcenter=" + str(box.center)
1179 vpdim = drawContext.getViewportDimensions()
1180 print "Viewport dimension: " + str(vpdim)
1184 if len(self.mPanelName) > 0:
1185 view = omui.M3dView.getM3dViewFromModelPanel(self.mPanelName)
1188 targetSize = drawContext.getRenderTargetSize()
1191 testString =
"Drawing with override: "
1192 testString += overrideFunc.name()
1193 pos = om.MPoint(0.0, 0.0, 0.0)
1194 glColor3f( 1.0, 1.0, 1.0 )
1195 view.drawText( testString, pos )
1199 if self.fDrawBoundingBoxes:
1200 cameraPath = view.getCamera()
1201 userDraw = MCustomSceneDraw()
1202 userDraw.draw( cameraPath, targetSize )
1204 def cameraOverride(self):
1205 if self.fUserCameraOverride:
1206 if len(self.mPanelName) > 0:
1207 view = omui.M3dView.getM3dViewFromModelPanel(self.mPanelName)
1208 self.mCameraOverride.mCameraPath = view.getCamera()
1209 return self.mCameraOverride
1213 def targetOverrideList(self):
1214 if not self.mTargets
is None:
1215 return [ self.mTargets[kMyColorTarget], self.mTargets[kMyDepthTarget] ]
1218 def enableSRGBWrite(self):
1219 return self.fEnableSRGBWriteFlag
1221 def hasUIDrawables(self):
1224 def addUIDrawables(self, drawManager, frameContext):
1225 drawManager.beginDrawable()
1226 drawManager.setColor( om.MColor( (0.95, 0.5, 0.1) ) )
1227 drawManager.text( om.MPoint( 0, 2, 0 ),
"UI draw test in user operation" )
1228 drawManager.line( om.MPoint( 0, 0, 0), om.MPoint( 0, 2, 0 ) )
1229 drawManager.setColor( om.MColor( (1.0, 1.0, 1.0) ) )
1230 drawManager.sphere( om.MPoint( 0, 2, 0 ), 0.8,
False )
1231 drawManager.setColor( om.MColor( (0.95, 0.5, 0.1, 0.4) ) )
1232 drawManager.sphere( om.MPoint( 0, 2, 0 ), 0.8,
True )
1233 drawManager.endDrawable()
1235 def setRenderTargets(self, targets):
1236 self.mTargets = targets
1238 def setEnableSRGBWriteFlag(self, val):
1239 self.fEnableSRGBWriteFlag = val
1241 def panelName(self):
1242 return self.mPanelName
1244 def setPanelName(self, name):
1245 self.mPanelName = name
1247 def viewRectangle(self):
1248 return self.mViewRectangle
1250 def setViewRectangle(self, rect):
1251 self.mViewRectangle = rect
1278 class viewRenderOverride(omr.MRenderOverride):
1279 def __init__(self, name):
1280 omr.MRenderOverride.__init__(self, name)
1284 self.mUIName =
"Sample VP2 Renderer Override"
1287 self.mRenderOperations = []
1288 self.mRenderOperationNames = []
1290 for i
in range(kNumberOfOps):
1291 self.mRenderOperations.append(
None)
1292 self.mRenderOperationNames.append(
"")
1293 self.mCurrentOperation = -1
1296 self.mTargetOverrideNames = []
1297 self.mTargetDescriptions = []
1299 self.mTargetSupportsSRGBWrite = []
1301 for i
in range(kTargetCount):
1302 self.mTargetOverrideNames.append(
"")
1303 self.mTargetDescriptions.append(
None)
1304 self.mTargets.append(
None)
1305 self.mTargetSupportsSRGBWrite.append(
False)
1309 colorFormat = omr.MRenderer.kR8G8B8A8_UNORM
1310 depthFormat = omr.MRenderer.kD24S8
1317 self.mTargetOverrideNames [kMyColorTarget] =
"__viewRenderOverrideCustomColorTarget__"
1318 self.mTargetDescriptions [kMyColorTarget] = omr.MRenderTargetDescription(self.mTargetOverrideNames[kMyColorTarget], 256, 256, sampleCount, colorFormat, 0,
False)
1319 self.mTargets [kMyColorTarget] =
None
1320 self.mTargetSupportsSRGBWrite[kMyColorTarget] =
False
1322 self.mTargetOverrideNames [kMyDepthTarget] =
"__viewRenderOverrideCustomDepthTarget__"
1323 self.mTargetDescriptions [kMyDepthTarget] = omr.MRenderTargetDescription(self.mTargetOverrideNames[kMyDepthTarget], 256, 256, sampleCount, depthFormat, 0,
False)
1324 self.mTargets [kMyDepthTarget] =
None
1325 self.mTargetSupportsSRGBWrite[kMyDepthTarget] =
False
1327 self.mTargetOverrideNames [kMyBlurTarget] =
"__viewRenderOverrideBlurTarget__"
1328 self.mTargetDescriptions [kMyBlurTarget]= omr.MRenderTargetDescription(self.mTargetOverrideNames[kMyBlurTarget], 256, 256, sampleCount, colorFormat, 0,
False)
1329 self.mTargets [kMyBlurTarget] =
None
1330 self.mTargetSupportsSRGBWrite[kMyBlurTarget] =
False
1333 self.mSplitUIDraw =
False
1336 self.mDebugOverride =
False
1339 self.mSimpleRendering =
False
1342 self.mPanelName =
""
1345 targetMgr = omr.MRenderer.getRenderTargetManager()
1348 for i
in range(kTargetCount):
1349 self.mTargetDescriptions[i] =
None
1351 if not self.mTargets[i]
is None:
1352 if not targetMgr
is None:
1353 targetMgr.releaseRenderTarget(self.mTargets[i])
1354 self.mTargets[i] =
None
1361 for i
in range(kNumberOfOps):
1362 self.mRenderOperations[i] =
None
1372 def supportedDrawAPIs(self):
1373 return ( omr.MRenderer.kOpenGL | omr.MRenderer.kDirectX11 | omr.MRenderer.kOpenGLCoreProfile )
1377 def startOperationIterator(self):
1378 self.mCurrentOperation = 0
1382 def renderOperation(self):
1383 if self.mCurrentOperation >= 0
and self.mCurrentOperation < kNumberOfOps:
1384 while self.mRenderOperations[self.mCurrentOperation]
is None:
1385 self.mCurrentOperation = self.mCurrentOperation+1
1386 if self.mCurrentOperation >= kNumberOfOps:
1389 if not self.mRenderOperations[self.mCurrentOperation]
is None:
1390 if self.mDebugOverride:
1391 print "\t" + self.name() +
"Queue render operation[" + str(self.mCurrentOperation) +
"] = (" + self.mRenderOperations[self.mCurrentOperation].name() +
")"
1392 return self.mRenderOperations[self.mCurrentOperation]
1396 def nextRenderOperation(self):
1397 self.mCurrentOperation = self.mCurrentOperation + 1
1398 if self.mCurrentOperation < kNumberOfOps:
1405 def updateRenderTargets(self):
1406 if self.mDebugOverride:
1407 print "\t" + self.name() +
": Set output render target overrides: color=" + self.mTargetDescriptions[kMyColorTarget].name() +
", depth=" + self.mTargetDescriptions[kMyDepthTarget].name()
1412 targetSize = omr.MRenderer.outputTargetSize()
1413 targetWidth = targetSize[0]
1414 targetHeight = targetSize[1]
1424 for targetId
in range(kTargetCount):
1425 self.mTargetDescriptions[targetId].setWidth( targetWidth )
1426 self.mTargetDescriptions[targetId].setHeight( targetHeight )
1429 colorTargetSupportsSGRBWrite =
False
1431 sDebugSRGBWrite =
False
1433 testUnorderedWriteAccess =
False
1437 targetManager = omr.MRenderer.getRenderTargetManager()
1438 if not targetManager
is None:
1440 if omr.MRenderer.drawAPI() != omr.MRenderer.kOpenGL:
1442 for i
in range(omr.MRenderer.kNumberOfRasterFormats):
1443 if targetManager.formatSupportsSRGBWrite(i):
1444 print "Format " + str(i) +
" supports SRGBwrite"
1446 for targetId
in range(kTargetCount):
1449 supportsSRGBWrite =
False
1450 if omr.MRenderer.drawAPI() != omr.MRenderer.kOpenGL:
1451 supportsSRGBWrite = targetManager.formatSupportsSRGBWrite( self.mTargetDescriptions[targetId].rasterFormat() )
1452 self.mTargetSupportsSRGBWrite[targetId] = supportsSRGBWrite
1453 self.mTargetDescriptions[targetId].setAllowsUnorderedAccess( testUnorderedWriteAccess )
1456 if targetId == kMyColorTarget:
1457 colorTargetSupportsSGRBWrite = supportsSRGBWrite
1460 if targetId == kMyColorTarget
or targetId == kMyBlurTarget:
1461 print "Color target " + str(targetId) +
" supports sRGB write = " + str(supportsSRGBWrite)
1463 if targetId == kMyDepthTarget:
1464 print "Depth target supports sRGB write = " + str(supportsSRGBWrite)
1467 if self.mTargets[targetId]
is None:
1468 self.mTargets[targetId] = targetManager.acquireRenderTarget( self.mTargetDescriptions[targetId] )
1472 self.mTargets[targetId].updateDescription( self.mTargetDescriptions[targetId] )
1474 if testUnorderedWriteAccess
and not self.mTargets[targetId]
is None:
1475 returnDesc = self.mTargets[targetId].targetDescription()
1476 self.mTargetDescriptions[targetId].setAllowsUnorderedAccess( returnDesc.allowsUnorderedAccess() )
1477 print "Acquire target[" + returnDesc.name() +
"] with unordered access = " + str(returnDesc.allowsUnorderedAccess()) +
". Should fail if attempting with depth target = " + str(targetId == kMyDepthTarget)
1485 quadOp = self.mRenderOperations[kBackgroundBlit]
1486 if not quadOp
is None:
1487 quadOp.setRenderTargets(self.mTargets)
1489 sceneOp = self.mRenderOperations[kMaya3dSceneRender]
1490 if not sceneOp
is None:
1491 sceneOp.setRenderTargets(self.mTargets)
1492 sceneOp.setEnableSRGBWriteFlag( colorTargetSupportsSGRBWrite )
1494 opaqueSceneOp = self.mRenderOperations[kMaya3dSceneRenderOpaque]
1495 if not opaqueSceneOp
is None:
1496 opaqueSceneOp.setRenderTargets(self.mTargets)
1497 opaqueSceneOp.setEnableSRGBWriteFlag( colorTargetSupportsSGRBWrite )
1499 transparentSceneOp = self.mRenderOperations[kMaya3dSceneRenderTransparent]
1500 if not transparentSceneOp
is None:
1501 transparentSceneOp.setRenderTargets(self.mTargets)
1502 transparentSceneOp.setEnableSRGBWriteFlag( colorTargetSupportsSGRBWrite )
1504 uiSceneOp = self.mRenderOperations[kMaya3dSceneRenderUI]
1505 if not uiSceneOp
is None:
1506 uiSceneOp.setRenderTargets(self.mTargets)
1507 uiSceneOp.setEnableSRGBWriteFlag(
False )
1509 quadOp2 = self.mRenderOperations[kPostOperation1]
1510 if not quadOp2
is None:
1511 quadOp2.setRenderTargets(self.mTargets)
1513 quadOp3 = self.mRenderOperations[kPostOperation2]
1514 if not quadOp3
is None:
1515 quadOp3.setRenderTargets(self.mTargets)
1517 userOp = self.mRenderOperations[kUserOpNumber]
1518 if not userOp
is None:
1519 userOp.setRenderTargets(self.mTargets)
1520 userOp.setEnableSRGBWriteFlag( colorTargetSupportsSGRBWrite )
1522 presentOp = self.mRenderOperations[kPresentOp]
1523 if not presentOp
is None:
1524 presentOp.setRenderTargets(self.mTargets)
1526 thresholdOp = self.mRenderOperations[kThresholdOp]
1527 if not thresholdOp
is None:
1528 thresholdOp.setRenderTargets(self.mTargets)
1530 horizBlur = self.mRenderOperations[kHorizBlurOp]
1531 if not horizBlur
is None:
1532 horizBlur.setRenderTargets(self.mTargets)
1534 vertBlur = self.mRenderOperations[kVertBlurOp]
1535 if not vertBlur
is None:
1536 vertBlur.setRenderTargets(self.mTargets)
1538 blendOp = self.mRenderOperations[kBlendOp]
1539 if not blendOp
is None:
1540 blendOp.setRenderTargets(self.mTargets)
1542 hudOp = self.mRenderOperations[kHUDBlit]
1543 if not hudOp
is None:
1544 hudOp.setRenderTargets(self.mTargets)
1546 return (
not self.mTargets[kMyColorTarget]
is None and not self.mTargets[kMyDepthTarget]
is None and not self.mTargets[kMyBlurTarget]
is None)
1552 def setup(self, destination ):
1553 if self.mDebugOverride:
1554 print self.name() +
" : Perform setup with panel [" + destination +
"]"
1559 self.mPanelName = destination
1568 if self.mRenderOperations[kPresentOp]
is None:
1571 if self.mSimpleRendering:
1572 self.mSplitUIDraw =
False
1574 self.mRenderOperations[kBackgroundBlit] =
None
1576 self.mRenderOperationNames[kMaya3dSceneRender] =
"__MySimpleSceneRender"
1577 sceneOp = simpleViewRenderSceneRender( self.mRenderOperationNames[kMaya3dSceneRender] )
1578 self.mRenderOperations[kMaya3dSceneRender] = sceneOp
1581 self.mRenderOperations[kMaya3dSceneRenderOpaque] =
None
1582 self.mRenderOperations[kMaya3dSceneRenderTransparent] =
None
1583 self.mRenderOperations[kThresholdOp] =
None
1584 self.mRenderOperations[kHorizBlurOp] =
None
1585 self.mRenderOperations[kVertBlurOp] =
None
1586 self.mRenderOperations[kPostOperation1] =
None
1587 self.mRenderOperations[kPostOperation2] =
None
1588 self.mRenderOperations[kMaya3dSceneRenderUI] =
None
1589 self.mRenderOperations[kUserOpNumber] =
None
1591 self.mRenderOperations[kHUDBlit] = viewRenderHUDOperation()
1592 self.mRenderOperationNames[kHUDBlit] = self.mRenderOperations[kHUDBlit].name()
1594 self.mRenderOperationNames[kPresentOp] =
"__MyPresentTarget"
1595 self.mRenderOperations[kPresentOp] = viewRenderPresentTarget( self.mRenderOperationNames[kPresentOp] )
1596 self.mRenderOperationNames[kPresentOp] = self.mRenderOperations[kPresentOp].name()
1601 rect = om.MFloatPoint(0.0, 0.0, 1.0, 1.0)
1605 self.mRenderOperationNames[kBackgroundBlit] =
"__MyPreQuadRender"
1606 quadOp = viewRenderQuadRender( self.mRenderOperationNames[kBackgroundBlit] )
1607 quadOp.setShader( viewRenderQuadRender.kPre_MandelBrot )
1608 quadOp.setViewRectangle(rect)
1609 self.mRenderOperations[kBackgroundBlit] = quadOp
1621 self.mSplitUIDraw =
True
1622 self.mRenderOperations[kMaya3dSceneRender] =
None
1623 self.mRenderOperations[kMaya3dSceneRenderOpaque] =
None
1624 self.mRenderOperations[kMaya3dSceneRenderTransparent] =
None
1625 self.mRenderOperations[kMaya3dSceneRenderUI] =
None
1626 if self.mSplitUIDraw:
1631 self.mRenderOperationNames[kMaya3dSceneRenderOpaque] =
"__MyStdSceneRenderOpaque"
1632 clearMask = omr.MClearOperation.kClearDepth | omr.MClearOperation.kClearStencil
1633 sceneOp = viewRenderSceneRender( self.mRenderOperationNames[kMaya3dSceneRenderOpaque], omr.MSceneRender.kRenderOpaqueShadedItems, clearMask )
1634 sceneOp.setViewRectangle(rect)
1635 self.mRenderOperations[kMaya3dSceneRenderOpaque] = sceneOp
1638 sDrawTransparent =
True
1639 if sDrawTransparent:
1640 self.mRenderOperationNames[kMaya3dSceneRenderTransparent] =
"__MyStdSceneRenderTransparent"
1641 clearMask = omr.MClearOperation.kClearDepth | omr.MClearOperation.kClearStencil
1643 clearMask = omr.MClearOperation.kClearNone
1644 sceneOp = viewRenderSceneRender( self.mRenderOperationNames[kMaya3dSceneRenderTransparent], omr.MSceneRender.kRenderTransparentShadedItems, clearMask )
1645 sceneOp.setViewRectangle(rect)
1646 self.mRenderOperations[kMaya3dSceneRenderTransparent] = sceneOp
1649 self.mRenderOperationNames[kMaya3dSceneRenderUI] =
"__MyStdSceneRenderUI"
1650 clearMask = omr.MClearOperation.kClearDepth | omr.MClearOperation.kClearStencil
1651 if sDrawOpaque
or sDrawTransparent:
1652 clearMask = omr.MClearOperation.kClearStencil
1653 sceneOp = viewRenderSceneRender( self.mRenderOperationNames[kMaya3dSceneRenderUI], omr.MSceneRender.kRenderUIItems, clearMask )
1654 sceneOp.setViewRectangle(rect)
1655 self.mRenderOperations[kMaya3dSceneRenderUI] = sceneOp
1658 self.mRenderOperationNames[kMaya3dSceneRender] =
"__MyStdSceneRender"
1659 clearMask = omr.MClearOperation.kClearDepth | omr.MClearOperation.kClearStencil
1660 sceneOp = viewRenderSceneRender( self.mRenderOperationNames[kMaya3dSceneRender], omr.MSceneRender.kNoSceneFilterOverride, clearMask )
1661 sceneOp.setViewRectangle(rect)
1662 self.mRenderOperations[kMaya3dSceneRender] = sceneOp
1668 self.mRenderOperationNames[kThresholdOp] =
"__ThresholdColor"
1669 quadThreshold = viewRenderQuadRender( self.mRenderOperationNames[kThresholdOp] )
1670 quadThreshold.setShader( viewRenderQuadRender.kScene_Threshold )
1671 quadThreshold.setViewRectangle(rect)
1672 self.mRenderOperations[kThresholdOp] = quadThreshold
1674 self.mRenderOperationNames[kHorizBlurOp] =
"__HorizontalBlur"
1675 quadHBlur = viewRenderQuadRender( self.mRenderOperationNames[kHorizBlurOp] )
1676 quadHBlur.setShader( viewRenderQuadRender.kScene_BlurHoriz )
1677 quadHBlur.setViewRectangle(rect)
1678 self.mRenderOperations[kHorizBlurOp] = quadHBlur
1680 self.mRenderOperationNames[kVertBlurOp] =
"__VerticalBlur"
1681 quadVBlur = viewRenderQuadRender( self.mRenderOperationNames[kVertBlurOp] )
1682 quadVBlur.setShader( viewRenderQuadRender.kScene_BlurVert )
1683 quadVBlur.setViewRectangle(rect)
1684 self.mRenderOperations[kVertBlurOp] = quadVBlur
1686 self.mRenderOperationNames[kBlendOp] =
"__SceneBlurBlend"
1687 quadBlend = viewRenderQuadRender( self.mRenderOperationNames[kBlendOp] )
1688 quadBlend.setShader( viewRenderQuadRender.kSceneBlur_Blend )
1689 quadBlend.setViewRectangle(rect)
1690 self.mRenderOperations[kBlendOp] = quadBlend
1694 self.mRenderOperationNames[kUserOpNumber] =
"__MyCustomSceneRender"
1695 userOp = viewRenderUserOperation( self.mRenderOperationNames[kUserOpNumber] )
1696 userOp.setViewRectangle(rect)
1697 self.mRenderOperations[kUserOpNumber] = userOp
1699 wantPostQuadOps =
False
1703 self.mRenderOperationNames[kPostOperation1] =
"__PostOperation1"
1704 quadOp2 = viewRenderQuadRender( self.mRenderOperationNames[kPostOperation1] )
1705 quadOp2.setShader( viewRenderQuadRender.kPost_EffectMonochrome )
1706 quadOp2.setViewRectangle(rect)
1708 self.mRenderOperations[kPostOperation1] = quadOp2
1710 self.mRenderOperations[kPostOperation1] =
None
1713 self.mRenderOperationNames[kPostOperation2] =
"__PostOperation2"
1714 quadOp3 = viewRenderQuadRender( self.mRenderOperationNames[kPostOperation2] )
1715 quadOp3.setShader( viewRenderQuadRender.kPost_EffectInvert )
1716 quadOp3.setViewRectangle(rect)
1718 self.mRenderOperations[kPostOperation2] = quadOp3
1720 self.mRenderOperations[kPostOperation2] =
None
1725 self.mRenderOperationNames[kPresentOp] =
"__MyPresentTarget"
1726 self.mRenderOperations[kPresentOp] = viewRenderPresentTarget( self.mRenderOperationNames[kPresentOp] )
1727 self.mRenderOperationNames[kPresentOp] = self.mRenderOperations[kPresentOp].name()
1730 self.mRenderOperations[kHUDBlit] = viewRenderHUDOperation()
1731 self.mRenderOperationNames[kHUDBlit] = self.mRenderOperations[kHUDBlit].name()
1734 if not self.mSimpleRendering:
1736 gotTargets = self.updateRenderTargets()
1740 if not self.mRenderOperations[kMaya3dSceneRender]
is None:
1741 self.mRenderOperations[kMaya3dSceneRender].setPanelName( self.mPanelName )
1742 if not self.mRenderOperations[kMaya3dSceneRenderOpaque]
is None:
1743 self.mRenderOperations[kMaya3dSceneRenderOpaque].setPanelName( self.mPanelName )
1744 if not self.mRenderOperations[kMaya3dSceneRenderTransparent]
is None:
1745 self.mRenderOperations[kMaya3dSceneRenderTransparent].setPanelName( self.mPanelName )
1746 if not self.mRenderOperations[kMaya3dSceneRenderUI]
is None:
1747 self.mRenderOperations[kMaya3dSceneRenderUI].setPanelName( self.mPanelName )
1748 if not self.mRenderOperations[kUserOpNumber]
is None:
1749 self.mRenderOperations[kUserOpNumber].setPanelName( self.mPanelName )
1751 self.mCurrentOperation = -1
1759 if self.mDebugOverride:
1760 print self.name() +
" : Perform cleanup. panelname=" + self.mPanelName
1762 quadOp = self.mRenderOperations[kPostOperation1]
1763 if not quadOp
is None:
1764 quadOp.setRenderTargets(
None)
1766 quadOp = self.mRenderOperations[kPostOperation2]
1767 if not quadOp
is None:
1768 quadOp.setRenderTargets(
None)
1771 self.mPanelName =
""
1773 self.mCurrentOperation = -1
1775 def panelName(self):
1776 return self.mPanelName
1778 def setSimpleRendering(self, flag):
1779 self.mSimpleRendering = flag
1785 viewRenderOverrideInstance =
None
1790 def initializePlugin(obj):
1791 plugin = om.MFnPlugin(obj)
1793 global viewRenderOverrideInstance
1794 viewRenderOverrideInstance = viewRenderOverride(
"my_viewRenderOverride" )
1795 omr.MRenderer.registerOverride(viewRenderOverrideInstance)
1797 sys.stderr.write(
"registerOverride\n")
1806 def uninitializePlugin(obj):
1807 plugin = om.MFnPlugin(obj)
1809 global viewRenderOverrideInstance
1810 if not viewRenderOverrideInstance
is None:
1811 omr.MRenderer.deregisterOverride(viewRenderOverrideInstance)
1812 viewRenderOverrideInstance =
None
1814 sys.stderr.write(
"deregisterOverride\n")