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)
92 elif ptype == omr.MLightParameterInformation.kTextureCube:
94 print "\t\tLight texture parameter " + pname +
". OpenGL texture id = " + str(lightParam.getParameterTextureHandle(pname))
101 semantic = lightParam.parameterSemantic(pname)
102 if semantic == omr.MLightParameterInformation.kLightEnabled:
103 print "\t\t- Parameter semantic : light enabled"
104 elif semantic == omr.MLightParameterInformation.kWorldPosition:
105 print "\t\t- Parameter semantic : world position"
106 floatVals = lightParam.getParameter(pname)
107 position += om.MFloatPoint( floatVals[0], floatVals[1], floatVals[2] )
108 positionCount = positionCount + 1
109 elif semantic == omr.MLightParameterInformation.kWorldDirection:
110 print "\t\t- Parameter semantic : world direction"
111 direction = lightParam.getParameter(pname)
112 elif semantic == omr.MLightParameterInformation.kIntensity:
113 print "\t\t- Parameter semantic : intensity"
114 elif semantic == omr.MLightParameterInformation.kColor:
115 print "\t\t- Parameter semantic : color"
116 color = om.MColor( lightParam.getParameter(pname) )
117 elif semantic == omr.MLightParameterInformation.kEmitsDiffuse:
118 print "\t\t- Parameter semantic : emits-diffuse"
119 elif semantic == omr.MLightParameterInformation.kEmitsSpecular:
120 print "\t\t- Parameter semantic : emits-specular"
121 elif semantic == omr.MLightParameterInformation.kDecayRate:
122 print "\t\t- Parameter semantic : decay rate"
123 elif semantic == omr.MLightParameterInformation.kDropoff:
124 print "\t\t- Parameter semantic : drop-off"
125 elif semantic == omr.MLightParameterInformation.kCosConeAngle:
126 print "\t\t- Parameter semantic : cosine cone angle"
127 elif semantic == omr.MLightParameterInformation.kShadowMap:
128 print "\t\t- Parameter semantic : shadow map"
129 elif semantic == omr.MLightParameterInformation.kShadowSamp:
130 print "\t\t- Parameter semantic : shadow map sampler"
131 elif semantic == omr.MLightParameterInformation.kShadowBias:
132 print "\t\t- Parameter semantic : shadow map bias"
133 elif semantic == omr.MLightParameterInformation.kShadowMapSize:
134 print "\t\t- Parameter semantic : shadow map size"
135 elif semantic == omr.MLightParameterInformation.kShadowViewProj:
136 print "\t\t- Parameter semantic : shadow map view projection matrix"
137 elif semantic == omr.MLightParameterInformation.kShadowColor:
138 print "\t\t- Parameter semantic : shadow color"
139 elif semantic == omr.MLightParameterInformation.kGlobalShadowOn:
140 print "\t\t- Parameter semantic : global shadows on"
141 elif semantic == omr.MLightParameterInformation.kShadowOn:
142 print "\t\t- Parameter semantic : local shadows on"
143 elif semantic == omr.MLightParameterInformation.kDepthRange:
144 print "\t\t- Parameter semantic : depth range"
147 if positionCount > 1:
148 position /= positionCount
149 print "\t\tCompute average position " + str(position)
152 print "\t\tSemantic -> Parameter Name Lookups"
153 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kLightEnabled)
156 floatVals = lightParam.getParameter(omr.MLightParameterInformation.kLightEnabled)
159 print "\t\t\tkLightEnabled -> " + str(paramNames) +
" -- " + str(floatVals)
160 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kWorldPosition)
161 print "\t\t\tkWorldPosition -> " + str(paramNames)
162 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kWorldDirection)
163 print "\t\t\tkWorldDirection -> " + str(paramNames)
164 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kIntensity)
165 print "\t\t\tkIntensity -> " + str(paramNames)
166 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kColor)
167 print "\t\t\tkColor -> " + str(paramNames)
168 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kEmitsDiffuse)
169 print "\t\t\tkEmitsDiffuse -> " + str(paramNames)
170 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kEmitsSpecular)
171 print "\t\t\tkEmitsSpecular -> " + str(paramNames)
172 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kDecayRate)
173 print "\t\t\tkDecayRate -> " + str(paramNames)
174 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kDropoff)
175 print "\t\t\tkDropoff -> " + str(paramNames)
176 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kCosConeAngle)
177 print "\t\t\tkCosConeAngle -> " + str(paramNames)
178 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kIrradianceIn)
179 print "\t\t\tkIrradianceIn -> " + str(paramNames)
180 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kShadowMap)
181 print "\t\t\tkShadowMap -> " + str(paramNames)
182 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kShadowSamp)
183 print "\t\t\tkShadowSamp -> " + str(paramNames)
184 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kShadowBias)
185 print "\t\t\tkShadowBias -> " + str(paramNames)
186 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kShadowMapSize)
187 print "\t\t\tkShadowMapSize -> " + str(paramNames)
188 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kShadowColor)
189 print "\t\t\tkShadowColor -> " + str(paramNames)
190 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kGlobalShadowOn)
191 print "\t\t\tkGlobalShadowOn -> " + str(paramNames)
192 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kShadowOn)
193 print "\t\t\tkShadowOn -> " + str(paramNames)
194 paramNames = lightParam.parameterNames(omr.MLightParameterInformation.kDepthRange)
195 print "\t\t\tkDepthRange -> " + str(paramNames)
211 def callbackDataPrint(context, renderItemList, shaderInstance):
212 if not shaderInstance
is None:
213 paramNames = shaderInstance.parameterList()
214 paramCount = len(paramNames)
215 print "\tSHADER: # of parameters = " + str(paramCount)
216 for i
in range(paramCount):
217 print "\t\tPARAM[" + paramNames[i] +
"]"
219 numItems = len(renderItemList)
220 for i
in range(numItems):
221 item = renderItemList[i]
223 path = item.sourceDagPath()
224 print "\tRENDER ITEM: '" + item.name() +
"' -- SOURCE: '" + path.fullPathName() +
"'"
226 passCtx = context.getPassContext()
227 passId = passCtx.passIdentifier()
228 passSem = passCtx.passSemantics()
229 print "PASS ID[" + passId +
"], PASS SEMANTICS[" + str(passSem) +
"]"
237 def shaderOverrideCallbackBindLightingInfo(drawContext, renderItemList, shaderInstance):
238 if shaderInstance
is None:
243 globalShadowsOn =
False
244 localShadowsOn =
False
245 direction = om.MFloatVector(0.0, 0.0, 1.0)
247 lightColor = [ 0.0, 0.0, 0.0 ]
252 considerAllSceneLights = omr.MDrawContext.kFilteredIgnoreLightLimit
253 omr.MRenderer.needEvaluateAllLights()
254 lightCount = drawContext.numberOfActiveLights(considerAllSceneLights)
256 shadowViewProj = om.MMatrix()
257 shadowResourceTexture =
None
258 samplerDesc = omr.MSamplerStateDesc()
259 shadowColor = [ 0.0, 0.0, 0.0 ]
261 foundDirectional =
False
262 for i
in range(lightCount):
265 globalShadowsOn =
False
266 localShadowsOn =
False
267 direction = om.MFloatVector(0.0, 0.0, 1.0)
269 lightColor = [ 0.0, 0.0, 0.0 ]
271 lightParam = drawContext.getLightParameterInformation( i, considerAllSceneLights )
272 if not lightParam
is None:
273 for pname
in lightParam.parameterList():
274 semantic = lightParam.parameterSemantic( pname )
276 if semantic == omr.MLightParameterInformation.kWorldDirection:
277 floatVals = lightParam.getParameter( pname )
278 direction = om.MFloatVector( floatVals[0], floatVals[1], floatVals[2] )
279 foundDirectional =
True
280 elif semantic == omr.MLightParameterInformation.kIntensity:
281 floatVals = lightParam.getParameter( pname )
282 lightIntensity = floatVals[0]
283 elif semantic == omr.MLightParameterInformation.kColor:
284 lightColor = lightParam.getParameter( pname )
287 elif semantic == omr.MLightParameterInformation.kGlobalShadowOn:
288 intVals = lightParam.getParameter( pname )
290 globalShadowsOn = (intVals[0] != 0)
291 elif semantic == omr.MLightParameterInformation.kShadowOn:
292 intVals = lightParam.getParameter( pname )
294 localShadowsOn = (intVals[0] != 0)
295 elif semantic == omr.MLightParameterInformation.kShadowViewProj:
296 shadowViewProj = lightParam.getParameter( pname )
297 elif semantic == omr.MLightParameterInformation.kShadowMap:
298 shadowResourceTexture = lightParam.getParameter( pname )
299 elif semantic == omr.MLightParameterInformation.kShadowSamp:
300 samplerDesc = lightParam.getParameter( pname )
301 elif semantic == omr.MLightParameterInformation.kShadowColor:
302 shadowColor = lightParam.getParameter( pname )
306 if foundDirectional
and globalShadowsOn
and localShadowsOn
and not shadowResourceTexture
is None:
307 resourceHandle = shadowResourceTexture.resourceHandle()
308 if resourceHandle > 0:
309 debugShadowBindings =
False
311 shaderInstance.setParameter(
"mayaShadowPCF1_shadowMap", shadowResource )
312 if debugShadowBindings:
313 print "Bound shadow map to shader param mayaShadowPCF1_shadowMap"
317 shaderInstance.setParameter(
"mayaShadowPCF1_shadowViewProj", shadowViewProj )
318 if debugShadowBindings:
319 print "Bound shadow map transform to shader param mayaShadowPCF1_shadowViewProj"
323 shaderInstance.setParameter(
"mayaShadowPCF1_shadowColor", shadowColor )
324 if debugShadowBindings:
325 print "Bound shadow map color to shader param mayaShadowPCF1_shadowColor"
329 textureManager = omr.MRenderer.getTextureManager()
330 if not textureManager
is None:
331 textureManager.releaseTexture(shadowResourceTexture)
332 shadowResourceTexture =
None
335 shaderInstance.setParameter(
"mayaDirectionalLight_direction", direction)
336 shaderInstance.setParameter(
"mayaDirectionalLight_intensity", lightIntensity)
337 shaderInstance.setParameter(
"mayaDirectionalLight_color", lightColor)
338 shaderInstance.setParameter(
"mayaShadowPCF1_mayaGlobalShadowOn", globalShadowsOn)
339 shaderInstance.setParameter(
"mayaShadowPCF1_mayaShadowOn", localShadowsOn)
344 def shaderOverridePreDrawCallback(context, renderItemList, shaderInstance):
345 print "PRE-draw callback triggered for render item list with data:"
346 callbackDataPrint(context, renderItemList, shaderInstance)
350 printDrawContextLightInfo( context )
356 def shaderOverridePostDrawCallback(context, renderItemList, shaderInstance):
357 print "POST-draw callback triggered for render item list with data:"
358 callbackDataPrint(context, renderItemList, shaderInstance)
365 class viewRenderHUDOperation(omr.MHUDRender):
367 omr.MHUDRender.__init__(self)
372 def targetOverrideList(self):
373 if not self.mTargets
is None:
374 return [ self.mTargets[kMyColorTarget], self.mTargets[kMyDepthTarget] ]
377 def hasUIDrawables(self):
380 def addUIDrawables(self, drawManager2D, frameContext):
382 drawManager2D.beginDrawable()
384 drawManager2D.setColor( om.MColor( (0.455, 0.212, 0.596) ) )
386 drawManager2D.setFontSize( omr.MUIDrawManager.kSmallFontSize )
389 dim = frameContext.getViewportDimensions()
394 drawManager2D.text( om.MPoint(w*0.5, h*0.91),
"Sample VP2 Renderer Override", omr.MUIDrawManager.kCenter )
397 viewportInfoText =
"Viewport information: x= "
398 viewportInfoText += str(x)
399 viewportInfoText +=
", y= "
400 viewportInfoText += str(y)
401 viewportInfoText +=
", w= "
402 viewportInfoText += str(w)
403 viewportInfoText +=
", h= "
404 viewportInfoText += str(h)
405 drawManager2D.text( om.MPoint(w*0.5, h*0.885), viewportInfoText, omr.MUIDrawManager.kCenter )
408 drawManager2D.endDrawable()
410 def setRenderTargets(self, targets):
411 self.mTargets = targets
420 class viewRenderPresentTarget(omr.MPresentTarget):
421 def __init__(self, name):
422 omr.MPresentTarget.__init__(self, name)
427 def targetOverrideList(self):
428 if not self.mTargets
is None:
429 return [ self.mTargets[kMyColorTarget], self.mTargets[kMyDepthTarget] ]
432 def setRenderTargets(self, targets):
433 self.mTargets = targets
443 class viewRenderQuadRender(omr.MQuadRender):
446 kPost_EffectMonochrome = 1
447 kPost_EffectEdgeDetect = 2
448 kPost_EffectInvert = 3
455 def __init__(self, name):
456 omr.MQuadRender.__init__(self, name)
459 self.mShaderInstance =
None
463 self.mViewRectangle = om.MFloatPoint()
465 self.mShader = self.kEffectNone
468 if not self.mShaderInstance
is None:
469 shaderMgr = omr.MRenderer.getShaderManager()
470 if not shaderMgr
is None:
471 shaderMgr.releaseShader(self.mShaderInstance)
472 self.mShaderInstance =
None
479 if self.mShaderInstance
is None:
480 shaderMgr = omr.MRenderer.getShaderManager()
481 if not shaderMgr
is None:
494 if self.mShader == self.kPre_MandelBrot:
495 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"MandelBrot",
"" )
496 elif self.mShader == self.kPost_EffectMonochrome:
497 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"FilterMonochrome",
"" )
498 elif self.mShader == self.kPost_EffectEdgeDetect:
499 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"FilterEdgeDetect",
"" )
500 elif self.mShader == self.kPost_EffectInvert:
501 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"Invert",
"" )
502 elif self.mShader == self.kScene_Threshold:
503 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"Threshold",
"" )
504 elif self.mShader == self.kScene_BlurHoriz:
505 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"Blur",
"BlurHoriz" )
506 elif self.mShader == self.kScene_BlurVert:
507 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"Blur",
"BlurVert" )
508 elif self.mShader == self.kSceneBlur_Blend:
509 self.mShaderInstance = shaderMgr.getEffectsFileShader(
"Blend",
"Add" )
516 if not self.mShaderInstance
is None:
517 if self.mShader == self.kPre_MandelBrot:
520 self.mShaderInstance.setParameter(
"gIterate", 50)
522 print "Could not change mandelbrot parameter"
525 elif self.mShader == self.kPost_EffectInvert:
529 self.mShaderInstance.setParameter(
"gInputTex", self.mTargets[kMyColorTarget])
531 print "Could not set input render target / texture parameter on invert shader"
534 elif self.mShader == self.kScene_Threshold:
538 self.mShaderInstance.setParameter(
"gSourceTex", self.mTargets[kMyColorTarget])
540 print "Could not set input render target / texture parameter on threshold shader"
542 self.mShaderInstance.setParameter(
"gBrightThreshold", 0.7 )
544 elif self.mShader == self.kScene_BlurHoriz:
548 self.mShaderInstance.setParameter(
"gSourceTex", self.mTargets[kMyBlurTarget])
550 print "Could not set input render target / texture parameter on hblur shader"
553 elif self.mShader == self.kScene_BlurVert:
557 self.mShaderInstance.setParameter(
"gSourceTex", self.mTargets[kMyBlurTarget])
559 print "Could not set input render target / texture parameter on vblur shader"
562 elif self.mShader == self.kSceneBlur_Blend:
566 self.mShaderInstance.setParameter(
"gSourceTex", self.mTargets[kMyColorTarget])
572 self.mShaderInstance.setParameter(
"gSourceTex2", self.mTargets[kMyBlurTarget])
575 self.mShaderInstance.setParameter(
"gBlendSrc", 0.3 )
577 elif self.mShader == self.kPost_EffectMonochrome:
581 self.mShaderInstance.setParameter(
"gInputTex", self.mTargets[kMyColorTarget])
583 print "Could not set input render target / texture parameter on monochrome shader"
586 elif self.mShader == self.kPost_EffectEdgeDetect:
590 self.mShaderInstance.setParameter(
"gInputTex", self.mTargets[kMyColorTarget])
592 print "Could not set input render target / texture parameter on edge detect shader"
594 self.mShaderInstance.setParameter(
"gThickness", 1.0 )
595 self.mShaderInstance.setParameter(
"gThreshold", 0.1 )
597 return self.mShaderInstance
604 def targetOverrideList(self):
605 if not self.mTargets
is None:
607 if self.mShader == self.kScene_Threshold
or self.mShader == self.kScene_BlurHoriz
or self.mShader == self.kScene_BlurVert:
608 return [ self.mTargets[kMyBlurTarget] ]
610 return [ self.mTargets[kMyColorTarget], self.mTargets[kMyDepthTarget] ]
614 def clearOperation(self):
615 clearOp = self.mClearOperation
617 if self.mShader == self.kPre_MandelBrot:
618 clearOp.setClearGradient(
False )
619 clearOp.setMask( omr.MClearOperation.kClearAll )
622 clearOp.setClearGradient(
False )
623 clearOp.setMask( omr.MClearOperation.kClearNone )
626 def setRenderTargets(self, targets):
627 self.mTargets = targets
629 def setShader(self, shader):
630 self.mShader = shader
632 def viewRectangle(self):
633 return self.mViewRectangle
635 def setViewRectangle(self, rect):
636 self.mViewRectangle = rect
644 class simpleViewRenderSceneRender(omr.MSceneRender):
645 def __init__(self, name):
646 omr.MSceneRender.__init__(self, name)
648 self.mViewRectangle = om.MFloatPoint(0.0, 0.0, 1.0, 1.0)
650 def viewportRectangleOverride(self):
652 testRectangleSize =
False
653 if testRectangleSize:
655 self.mViewRectangle = om.MFloatPoint(0.33, 0.10, 0.50, 0.50)
656 return self.mViewRectangle
658 def clearOperation(self):
660 val1 = [ 0.0, 0.2, 0.8, 1.0 ]
661 val2 = [ 0.5, 0.4, 0.1, 1.0 ]
662 clearOp = self.mClearOperation
663 clearOp.setClearColor( val1 )
664 clearOp.setClearColor2( val2 )
665 clearOp.setClearGradient(
True )
675 class viewRenderSceneRender(omr.MSceneRender):
676 def __init__(self, name, sceneFilter, clearMask):
677 omr.MSceneRender.__init__(self, name)
679 self.mSelectionList = om.MSelectionList()
684 self.mCameraOverride = omr.MCameraOverride()
686 self.mViewRectangle = om.MFloatPoint(0.0, 0.0, 1.0, 1.0)
690 self.mShaderOverride =
None
692 self.mSceneFilter = sceneFilter
694 self.mClearMask = clearMask
697 self.mUseShaderOverride =
False
698 self.mUseStockShaderOverride =
False
699 self.mAttachPrePostShaderCallback =
False
700 self.mUseShadowShader =
False
701 self.mOverrideDisplayMode =
True
702 self.mOverrideLightingMode =
False
703 self.mOverrideCullingMode =
False
704 self.mDebugTargetResourceHandle =
False
705 self.mOverrrideM3dViewDisplayMode =
False
706 self.mPrevDisplayStyle = omui.M3dView.kGouraudShaded
707 self.mFilterDrawNothing =
False
708 self.mFilterDrawSelected =
False
709 self.mEnableSRGBWrite =
False
713 if not self.mShaderOverride
is None:
714 shaderMgr = omr.MRenderer.getShaderManager()
715 if not shaderMgr
is None:
716 shaderMgr.releaseShader(self.mShaderOverride)
717 self.mShaderOverride =
None
719 def setRenderTargets(self, targets):
720 self.mTargets = targets
722 def targetOverrideList(self):
723 if not self.mTargets
is None:
724 return [ self.mTargets[kMyColorTarget], self.mTargets[kMyDepthTarget] ]
728 def enableSRGBWrite(self):
729 return self.mEnableSRGBWrite
733 def cameraOverride(self):
734 if len(self.mPanelName) > 0:
735 view = omui.M3dView.getM3dViewFromModelPanel(self.mPanelName)
736 self.mCameraOverride.mCameraPath = view.getCamera()
737 return self.mCameraOverride
739 print "\t" + self.mName +
": Query custom scene camera override -- no override set"
744 def renderFilterOverride(self):
745 return self.mSceneFilter
751 def displayModeOverride(self):
752 if self.mOverrideDisplayMode:
753 return ( omr.MSceneRender.kBoundingBox | omr.MSceneRender.kShaded )
754 return omr.MSceneRender.kNoDisplayModeOverride
758 def lightModeOverride(self):
759 if self.mOverrideLightingMode:
760 return omr.MSceneRender.kSelectedLights
761 return omr.MSceneRender.kNoLightingModeOverride
764 def shadowEnableOverride(self):
765 if (self.mSceneFilter & omr.MSceneRender.kRenderShadedItems) == 0:
773 def cullingOverride(self):
774 if self.mOverrideCullingMode:
775 return omr.MSceneRender.kCullBackFaces
776 return omr.MSceneRender.kNoCullingOverride
783 if self.mOverrrideM3dViewDisplayMode:
784 if len(self.mPanelName) > 0:
785 view = omui.M3dView.getM3dViewFromModelPanel(self.mPanelName)
786 self.mPrevDisplayStyle = view.displayStyle();
787 view.setDisplayStyle( omui.M3dView.kGouraudShaded )
793 def postRender(self):
794 if self.mDebugTargetResourceHandle:
798 if not self.mTargets[kMyColorTarget]
is None:
799 colorResourceHandle = self.mTargets[kMyColorTarget].resourceHandle()
800 print "\t - Color target resource handle = " + str(colorResourceHandle)
802 if not self.mTargets[kMyDepthTarget]
is None:
803 depthStencilResourceHandle = self.mTargets[kMyDepthTarget].resourceHandle()
804 print "\t - Depth target resource handle = " + str(depthStencilResourceHandle)
806 if self.mOverrrideM3dViewDisplayMode:
807 if len(self.mPanelName) > 0:
808 view = omui.M3dView.getM3dViewFromModelPanel(self.mPanelName)
809 view.setDisplayStyle( self.mPrevDisplayStyle )
813 def getObjectTypeExclusions(self):
815 return omr.MFrameContext.kExcludeCameras
826 def objectSetOverride(self):
827 self.mSelectionList.clear()
833 if self.mFilterDrawNothing:
834 return self.mSelectionList
839 if self.mFilterDrawSelected:
840 selList = om.MGlobal.getActiveSelectionList()
841 if selList.length() > 0:
842 iter = om.MItSelectionList(selList)
843 while not iter.isDone():
844 comp = iter.getComponent()
845 self.mSelectionList.add( comp[0], comp[1] )
848 if self.mSelectionList.length() > 0:
849 print "\t" + self.name() +
" : Filtering render with active object list"
850 return self.mSelectionList
859 def clearOperation(self):
860 clearOp = self.mClearOperation
861 if (self.mSceneFilter & (omr.MSceneRender.kRenderOpaqueShadedItems | omr.MSceneRender.kRenderTransparentShadedItems | omr.MSceneRender.kRenderUIItems)) != 0:
862 clearOp.setClearGradient(
False)
866 val1 = [ 0.0, 0.2, 0.8, 1.0 ]
867 val2 = [ 0.5, 0.4, 0.1, 1.0 ]
868 clearOp.setClearColor(val1)
869 clearOp.setClearColor2(val2)
870 clearOp.setClearGradient(
True)
872 clearOp.setMask(self.mClearMask)
880 def shaderOverride(self):
881 if self.mUseShaderOverride:
882 if self.mShaderOverride
is None:
883 shaderManager = omr.MRenderer.getShaderManager()
884 if not shaderManager
is None:
887 if not self.mUseStockShaderOverride:
888 if self.mUseShadowShader:
891 preCallBack = shaderOverrideCallbackBindLightingInfo
892 self.mShaderOverride = shaderManager.getEffectsFileShader(
"MayaBlinnDirectionalLightShadow",
"",
None,
True, preCallBack, postCallBack)
895 if self.mAttachPrePostShaderCallback:
896 preCallBack = shaderOverridePreDrawCallback
897 if self.mAttachPrePostShaderCallback:
898 postCallBack = shaderOverridePostDrawCallback
899 self.mShaderOverride = shaderManager.getEffectsFileShader(
"Gooch",
"",
None,
True, preCallBack, postCallBack)
903 if self.mAttachPrePostShaderCallback:
904 preCallBack = shaderOverridePreDrawCallback
905 if self.mAttachPrePostShaderCallback:
906 postCallBack = shaderOverridePostDrawCallback
907 self.mShaderOverride = shaderManager.getStockShader( omr.MShaderManager.k3dBlinnShader, preCallBack, postCallBack)
909 if not self.mShaderOverride
is None:
910 print "\t" + self.name() +
" : Set stock shader override " + str(omr.MShaderManager.k3dBlinnShader)
911 diffColor = [0.0, 0.4, 1.0, 1.0]
913 self.mShaderOverride.setParameter(
"diffuseColor", diffColor)
915 print "Could not set diffuseColor on shader"
917 return self.mShaderOverride
922 def hasUIDrawables(self):
926 def addPreUIDrawables(self, drawManager, frameContext):
927 drawManager.beginDrawable()
928 drawManager.setColor( om.MColor( (0.1, 0.5, 0.95) ) )
929 drawManager.setFontSize( omr.MUIDrawManager.kSmallFontSize )
930 drawManager.text( om.MPoint( -2, 2, -2 ),
"Pre UI draw test in Scene operation", omr.MUIDrawManager.kRight )
931 drawManager.line( om.MPoint( -2, 0, -2 ), om.MPoint( -2, 2, -2 ) )
932 drawManager.setColor( om.MColor( (1.0, 1.0, 1.0) ) )
933 drawManager.sphere( om.MPoint( -2, 2, -2 ), 0.8,
False )
934 drawManager.setColor( om.MColor( (0.1, 0.5, 0.95, 0.4) ) )
935 drawManager.sphere( om.MPoint( -2, 2, -2 ), 0.8,
True )
936 drawManager.endDrawable()
939 def addPostUIDrawables(self, drawManager, frameContext):
940 drawManager.beginDrawable()
941 drawManager.setColor( om.MColor( (0.05, 0.95, 0.34) ) )
942 drawManager.setFontSize( omr.MUIDrawManager.kSmallFontSize )
943 drawManager.text( om.MPoint( 2, 2, 2 ),
"Post UI draw test in Scene operation", omr.MUIDrawManager.kLeft )
944 drawManager.line( om.MPoint( 2, 0, 2), om.MPoint( 2, 2, 2 ) )
945 drawManager.setColor( om.MColor( (1.0, 1.0, 1.0) ) )
946 drawManager.sphere( om.MPoint( 2, 2, 2 ), 0.8,
False )
947 drawManager.setColor( om.MColor( (0.05, 0.95, 0.34, 0.4) ) )
948 drawManager.sphere( om.MPoint( 2, 2, 2 ), 0.8,
True )
949 drawManager.endDrawable()
952 return self.mPanelName
954 def setPanelName(self, name):
955 self.mPanelName = name
957 def viewRectangle(self):
958 return self.mViewRectangle
960 def setViewRectangle(self, rect):
961 self.mViewRectangle = rect
963 def colorTarget(self):
964 if not self.mTargets
is None:
965 return self.mTargets[kMyColorTarget]
968 def depthTarget(self):
969 if not self.mTargets
is None:
970 return self.mTargets[kMyDepthTarget]
973 def setEnableSRGBWriteFlag(self, val):
974 self.mEnableSRGBWrite = val
976 def enableSRGBWriteFlag(self):
977 return self.mEnableSRGBWrite
987 class MCustomSceneDraw:
989 def matrixAsArray(self, matrix):
992 array.append(matrix[i])
996 def drawBounds(self, dagPath, box):
997 matrix = dagPath.inclusiveMatrix()
1001 bottomLeftFront = [ minPt.x, minPt.y, minPt.z ]
1002 topLeftFront = [ minPt.x, maxPt.y, minPt.z ]
1003 bottomRightFront = [ maxPt.x, minPt.y, minPt.z ]
1004 topRightFront = [ maxPt.x, maxPt.y, minPt.z ]
1005 bottomLeftBack = [ minPt.x, minPt.y, maxPt.z ]
1006 topLeftBack = [ minPt.x, maxPt.y, maxPt.z ]
1007 bottomRightBack = [ maxPt.x, minPt.y, maxPt.z ]
1008 topRightBack = [ maxPt.x, maxPt.y, maxPt.z ]
1010 glMatrixMode( GL_MODELVIEW )
1012 glMultMatrixd( self.matrixAsArray(matrix) )
1014 glBegin( GL_LINE_STRIP )
1015 glVertex3dv( bottomLeftFront )
1016 glVertex3dv( bottomLeftBack )
1017 glVertex3dv( topLeftBack )
1018 glVertex3dv( topLeftFront )
1019 glVertex3dv( bottomLeftFront )
1020 glVertex3dv( bottomRightFront )
1021 glVertex3dv( bottomRightBack)
1022 glVertex3dv( topRightBack )
1023 glVertex3dv( topRightFront )
1024 glVertex3dv( bottomRightFront )
1028 glVertex3dv(bottomLeftBack)
1029 glVertex3dv(bottomRightBack)
1031 glVertex3dv(topLeftBack)
1032 glVertex3dv(topRightBack)
1034 glVertex3dv(topLeftFront)
1035 glVertex3dv(topRightFront)
1041 def draw(self, cameraPath, size):
1042 if not cameraPath.isValid:
1046 MDrawTraversal *trav = NULL;
1047 trav = new MSurfaceDrawTraversal;
1052 trav->enableFiltering( true );
1053 trav->setFrustum( cameraPath, width, height );
1054 if (!trav->frustumValid())
1056 delete trav; trav = NULL;
1061 unsigned int numItems = trav->numberOfItems();
1063 for (i=0; i<numItems; i++)
1066 trav->itemPath(i, path);
1070 bool drawIt = false;
1073 // Draw surfaces (polys, nurbs, subdivs)
1075 if ( path.hasFn( MFn::kMesh) ||
1076 path.hasFn( MFn::kNurbsSurface) ||
1077 path.hasFn( MFn::kSubdiv) )
1080 if (trav->itemHasStatus( i, MDrawTraversal::kActiveItem ))
1082 gGLFT->glColor3f( 1.0f, 1.0f, 1.0f );
1084 else if (trav->itemHasStatus( i, MDrawTraversal::kTemplateItem ))
1086 gGLFT->glColor3f( 0.2f, 0.2f, 0.2f );
1090 if (path.hasFn( MFn::kMesh ))
1091 gGLFT->glColor3f( 0.286f, 0.706f, 1.0f );
1092 else if (path.hasFn( MFn::kNurbsSurface))
1093 gGLFT->glColor3f( 0.486f, 0.306f, 1.0f );
1095 gGLFT->glColor3f( 0.886f, 0.206f, 1.0f );
1101 MFnDagNode dagNode(path);
1102 MBoundingBox box = dagNode.boundingBox();
1103 drawBounds( path, box );
1129 class viewRenderUserOperation(omr.MUserRenderOperation):
1130 def __init__(self, name):
1131 omr.MUserRenderOperation.__init__(self, name)
1134 self.mPanelName =
""
1136 self.mCameraOverride = omr.MCameraOverride()
1138 self.mViewRectangle = om.MFloatPoint(0.0, 0.0, 1.0, 1.0)
1140 self.mTargets =
None
1142 self.fEnableSRGBWriteFlag =
False
1144 self.fDrawLabel =
False
1146 self.fUserCameraOverride =
False
1148 self.fDrawBoundingBoxes =
False
1150 self.fDebugDrawContext =
False
1151 self.fDebugLightingInfo =
False
1153 def execute(self, drawContext):
1155 debugPassInformation =
False
1156 if debugPassInformation:
1157 passCtx = drawContext.getPassContext()
1158 passId = passCtx.passIdentifier()
1159 passSem = passCtx.passSemantics()
1160 print "viewRenderUserOperation: drawing in pass[" + str(passId) +
"], semantic[" + str(passSem) +
"]"
1167 overrideName = omr.MRenderer.activeRenderOverride()
1168 overrideFunc = omr.MRenderer.findRenderOverride( overrideName )
1172 if self.fDebugLightingInfo:
1173 printDrawContextLightInfo( drawContext )
1177 if self.fDebugDrawContext:
1178 matrix = drawContext.getMatrix(omr.MFrameContext.kWorldMtx)
1179 print "World matrix is: " + str(matrix)
1181 viewDirection = drawContext.getTuple(omr.MFrameContext.kViewDirection)
1182 print "Viewdirection is: " + str(viewDirection)
1184 box = drawContext.getSceneBox()
1185 print "Screen box is: " + str(box)
1186 print "\tcenter=" + str(box.center)
1188 vpdim = drawContext.getViewportDimensions()
1189 print "Viewport dimension: " + str(vpdim)
1193 if len(self.mPanelName) > 0:
1194 view = omui.M3dView.getM3dViewFromModelPanel(self.mPanelName)
1197 targetSize = drawContext.getRenderTargetSize()
1200 testString =
"Drawing with override: "
1201 testString += overrideFunc.name()
1202 pos = om.MPoint(0.0, 0.0, 0.0)
1203 glColor3f( 1.0, 1.0, 1.0 )
1204 view.drawText( testString, pos )
1208 if self.fDrawBoundingBoxes:
1209 cameraPath = view.getCamera()
1210 userDraw = MCustomSceneDraw()
1211 userDraw.draw( cameraPath, targetSize )
1213 def cameraOverride(self):
1214 if self.fUserCameraOverride:
1215 if len(self.mPanelName) > 0:
1216 view = omui.M3dView.getM3dViewFromModelPanel(self.mPanelName)
1217 self.mCameraOverride.mCameraPath = view.getCamera()
1218 return self.mCameraOverride
1222 def targetOverrideList(self):
1223 if not self.mTargets
is None:
1224 return [ self.mTargets[kMyColorTarget], self.mTargets[kMyDepthTarget] ]
1227 def enableSRGBWrite(self):
1228 return self.fEnableSRGBWriteFlag
1230 def hasUIDrawables(self):
1233 def addUIDrawables(self, drawManager, frameContext):
1234 drawManager.beginDrawable()
1235 drawManager.setColor( om.MColor( (0.95, 0.5, 0.1) ) )
1236 drawManager.text( om.MPoint( 0, 2, 0 ),
"UI draw test in user operation" )
1237 drawManager.line( om.MPoint( 0, 0, 0), om.MPoint( 0, 2, 0 ) )
1238 drawManager.setColor( om.MColor( (1.0, 1.0, 1.0) ) )
1239 drawManager.sphere( om.MPoint( 0, 2, 0 ), 0.8,
False )
1240 drawManager.setColor( om.MColor( (0.95, 0.5, 0.1, 0.4) ) )
1241 drawManager.sphere( om.MPoint( 0, 2, 0 ), 0.8,
True )
1242 drawManager.endDrawable()
1244 def setRenderTargets(self, targets):
1245 self.mTargets = targets
1247 def setEnableSRGBWriteFlag(self, val):
1248 self.fEnableSRGBWriteFlag = val
1250 def panelName(self):
1251 return self.mPanelName
1253 def setPanelName(self, name):
1254 self.mPanelName = name
1256 def viewRectangle(self):
1257 return self.mViewRectangle
1259 def setViewRectangle(self, rect):
1260 self.mViewRectangle = rect
1287 class viewRenderOverride(omr.MRenderOverride):
1288 def __init__(self, name):
1289 omr.MRenderOverride.__init__(self, name)
1293 self.mUIName =
"Sample VP2 Renderer Override"
1296 self.mRenderOperations = []
1297 self.mRenderOperationNames = []
1299 for i
in range(kNumberOfOps):
1300 self.mRenderOperations.append(
None)
1301 self.mRenderOperationNames.append(
"")
1302 self.mCurrentOperation = -1
1305 self.mTargetOverrideNames = []
1306 self.mTargetDescriptions = []
1308 self.mTargetSupportsSRGBWrite = []
1310 for i
in range(kTargetCount):
1311 self.mTargetOverrideNames.append(
"")
1312 self.mTargetDescriptions.append(
None)
1313 self.mTargets.append(
None)
1314 self.mTargetSupportsSRGBWrite.append(
False)
1318 colorFormat = omr.MRenderer.kR8G8B8A8_UNORM
1319 depthFormat = omr.MRenderer.kD24S8
1326 self.mTargetOverrideNames [kMyColorTarget] =
"__viewRenderOverrideCustomColorTarget__"
1327 self.mTargetDescriptions [kMyColorTarget] = omr.MRenderTargetDescription(self.mTargetOverrideNames[kMyColorTarget], 256, 256, sampleCount, colorFormat, 0,
False)
1328 self.mTargets [kMyColorTarget] =
None
1329 self.mTargetSupportsSRGBWrite[kMyColorTarget] =
False
1331 self.mTargetOverrideNames [kMyDepthTarget] =
"__viewRenderOverrideCustomDepthTarget__"
1332 self.mTargetDescriptions [kMyDepthTarget] = omr.MRenderTargetDescription(self.mTargetOverrideNames[kMyDepthTarget], 256, 256, sampleCount, depthFormat, 0,
False)
1333 self.mTargets [kMyDepthTarget] =
None
1334 self.mTargetSupportsSRGBWrite[kMyDepthTarget] =
False
1336 self.mTargetOverrideNames [kMyBlurTarget] =
"__viewRenderOverrideBlurTarget__"
1337 self.mTargetDescriptions [kMyBlurTarget]= omr.MRenderTargetDescription(self.mTargetOverrideNames[kMyBlurTarget], 256, 256, sampleCount, colorFormat, 0,
False)
1338 self.mTargets [kMyBlurTarget] =
None
1339 self.mTargetSupportsSRGBWrite[kMyBlurTarget] =
False
1342 self.mSplitUIDraw =
False
1345 self.mDebugOverride =
False
1348 self.mSimpleRendering =
False
1351 self.mPanelName =
""
1354 targetMgr = omr.MRenderer.getRenderTargetManager()
1357 for i
in range(kTargetCount):
1358 self.mTargetDescriptions[i] =
None
1360 if not self.mTargets[i]
is None:
1361 if not targetMgr
is None:
1362 targetMgr.releaseRenderTarget(self.mTargets[i])
1363 self.mTargets[i] =
None
1370 for i
in range(kNumberOfOps):
1371 self.mRenderOperations[i] =
None
1381 def supportedDrawAPIs(self):
1382 return ( omr.MRenderer.kOpenGL | omr.MRenderer.kDirectX11 | omr.MRenderer.kOpenGLCoreProfile )
1386 def startOperationIterator(self):
1387 self.mCurrentOperation = 0
1391 def renderOperation(self):
1392 if self.mCurrentOperation >= 0
and self.mCurrentOperation < kNumberOfOps:
1393 while self.mRenderOperations[self.mCurrentOperation]
is None:
1394 self.mCurrentOperation = self.mCurrentOperation+1
1395 if self.mCurrentOperation >= kNumberOfOps:
1398 if not self.mRenderOperations[self.mCurrentOperation]
is None:
1399 if self.mDebugOverride:
1400 print "\t" + self.name() +
"Queue render operation[" + str(self.mCurrentOperation) +
"] = (" + self.mRenderOperations[self.mCurrentOperation].name() +
")"
1401 return self.mRenderOperations[self.mCurrentOperation]
1405 def nextRenderOperation(self):
1406 self.mCurrentOperation = self.mCurrentOperation + 1
1407 if self.mCurrentOperation < kNumberOfOps:
1414 def updateRenderTargets(self):
1415 if self.mDebugOverride:
1416 print "\t" + self.name() +
": Set output render target overrides: color=" + self.mTargetDescriptions[kMyColorTarget].name() +
", depth=" + self.mTargetDescriptions[kMyDepthTarget].name()
1421 targetSize = omr.MRenderer.outputTargetSize()
1422 targetWidth = targetSize[0]
1423 targetHeight = targetSize[1]
1433 for targetId
in range(kTargetCount):
1434 self.mTargetDescriptions[targetId].setWidth( targetWidth )
1435 self.mTargetDescriptions[targetId].setHeight( targetHeight )
1438 colorTargetSupportsSGRBWrite =
False
1440 sDebugSRGBWrite =
False
1442 testUnorderedWriteAccess =
False
1446 targetManager = omr.MRenderer.getRenderTargetManager()
1447 if not targetManager
is None:
1449 if omr.MRenderer.drawAPI() != omr.MRenderer.kOpenGL:
1451 for i
in range(omr.MRenderer.kNumberOfRasterFormats):
1452 if targetManager.formatSupportsSRGBWrite(i):
1453 print "Format " + str(i) +
" supports SRGBwrite"
1455 for targetId
in range(kTargetCount):
1458 supportsSRGBWrite =
False
1459 if omr.MRenderer.drawAPI() != omr.MRenderer.kOpenGL:
1460 supportsSRGBWrite = targetManager.formatSupportsSRGBWrite( self.mTargetDescriptions[targetId].rasterFormat() )
1461 self.mTargetSupportsSRGBWrite[targetId] = supportsSRGBWrite
1462 self.mTargetDescriptions[targetId].setAllowsUnorderedAccess( testUnorderedWriteAccess )
1465 if targetId == kMyColorTarget:
1466 colorTargetSupportsSGRBWrite = supportsSRGBWrite
1469 if targetId == kMyColorTarget
or targetId == kMyBlurTarget:
1470 print "Color target " + str(targetId) +
" supports sRGB write = " + str(supportsSRGBWrite)
1472 if targetId == kMyDepthTarget:
1473 print "Depth target supports sRGB write = " + str(supportsSRGBWrite)
1476 if self.mTargets[targetId]
is None:
1477 self.mTargets[targetId] = targetManager.acquireRenderTarget( self.mTargetDescriptions[targetId] )
1481 self.mTargets[targetId].updateDescription( self.mTargetDescriptions[targetId] )
1483 if testUnorderedWriteAccess
and not self.mTargets[targetId]
is None:
1484 returnDesc = self.mTargets[targetId].targetDescription()
1485 self.mTargetDescriptions[targetId].setAllowsUnorderedAccess( returnDesc.allowsUnorderedAccess() )
1486 print "Acquire target[" + returnDesc.name() +
"] with unordered access = " + str(returnDesc.allowsUnorderedAccess()) +
". Should fail if attempting with depth target = " + str(targetId == kMyDepthTarget)
1494 quadOp = self.mRenderOperations[kBackgroundBlit]
1495 if not quadOp
is None:
1496 quadOp.setRenderTargets(self.mTargets)
1498 sceneOp = self.mRenderOperations[kMaya3dSceneRender]
1499 if not sceneOp
is None:
1500 sceneOp.setRenderTargets(self.mTargets)
1501 sceneOp.setEnableSRGBWriteFlag( colorTargetSupportsSGRBWrite )
1503 opaqueSceneOp = self.mRenderOperations[kMaya3dSceneRenderOpaque]
1504 if not opaqueSceneOp
is None:
1505 opaqueSceneOp.setRenderTargets(self.mTargets)
1506 opaqueSceneOp.setEnableSRGBWriteFlag( colorTargetSupportsSGRBWrite )
1508 transparentSceneOp = self.mRenderOperations[kMaya3dSceneRenderTransparent]
1509 if not transparentSceneOp
is None:
1510 transparentSceneOp.setRenderTargets(self.mTargets)
1511 transparentSceneOp.setEnableSRGBWriteFlag( colorTargetSupportsSGRBWrite )
1513 uiSceneOp = self.mRenderOperations[kMaya3dSceneRenderUI]
1514 if not uiSceneOp
is None:
1515 uiSceneOp.setRenderTargets(self.mTargets)
1516 uiSceneOp.setEnableSRGBWriteFlag(
False )
1518 quadOp2 = self.mRenderOperations[kPostOperation1]
1519 if not quadOp2
is None:
1520 quadOp2.setRenderTargets(self.mTargets)
1522 quadOp3 = self.mRenderOperations[kPostOperation2]
1523 if not quadOp3
is None:
1524 quadOp3.setRenderTargets(self.mTargets)
1526 userOp = self.mRenderOperations[kUserOpNumber]
1527 if not userOp
is None:
1528 userOp.setRenderTargets(self.mTargets)
1529 userOp.setEnableSRGBWriteFlag( colorTargetSupportsSGRBWrite )
1531 presentOp = self.mRenderOperations[kPresentOp]
1532 if not presentOp
is None:
1533 presentOp.setRenderTargets(self.mTargets)
1535 thresholdOp = self.mRenderOperations[kThresholdOp]
1536 if not thresholdOp
is None:
1537 thresholdOp.setRenderTargets(self.mTargets)
1539 horizBlur = self.mRenderOperations[kHorizBlurOp]
1540 if not horizBlur
is None:
1541 horizBlur.setRenderTargets(self.mTargets)
1543 vertBlur = self.mRenderOperations[kVertBlurOp]
1544 if not vertBlur
is None:
1545 vertBlur.setRenderTargets(self.mTargets)
1547 blendOp = self.mRenderOperations[kBlendOp]
1548 if not blendOp
is None:
1549 blendOp.setRenderTargets(self.mTargets)
1551 hudOp = self.mRenderOperations[kHUDBlit]
1552 if not hudOp
is None:
1553 hudOp.setRenderTargets(self.mTargets)
1555 return (
not self.mTargets[kMyColorTarget]
is None and not self.mTargets[kMyDepthTarget]
is None and not self.mTargets[kMyBlurTarget]
is None)
1561 def setup(self, destination ):
1562 if self.mDebugOverride:
1563 print self.name() +
" : Perform setup with panel [" + destination +
"]"
1568 self.mPanelName = destination
1577 if self.mRenderOperations[kPresentOp]
is None:
1580 if self.mSimpleRendering:
1581 self.mSplitUIDraw =
False
1583 self.mRenderOperations[kBackgroundBlit] =
None
1585 self.mRenderOperationNames[kMaya3dSceneRender] =
"__MySimpleSceneRender"
1586 sceneOp = simpleViewRenderSceneRender( self.mRenderOperationNames[kMaya3dSceneRender] )
1587 self.mRenderOperations[kMaya3dSceneRender] = sceneOp
1590 self.mRenderOperations[kMaya3dSceneRenderOpaque] =
None
1591 self.mRenderOperations[kMaya3dSceneRenderTransparent] =
None
1592 self.mRenderOperations[kThresholdOp] =
None
1593 self.mRenderOperations[kHorizBlurOp] =
None
1594 self.mRenderOperations[kVertBlurOp] =
None
1595 self.mRenderOperations[kPostOperation1] =
None
1596 self.mRenderOperations[kPostOperation2] =
None
1597 self.mRenderOperations[kMaya3dSceneRenderUI] =
None
1598 self.mRenderOperations[kUserOpNumber] =
None
1600 self.mRenderOperations[kHUDBlit] = viewRenderHUDOperation()
1601 self.mRenderOperationNames[kHUDBlit] = self.mRenderOperations[kHUDBlit].name()
1603 self.mRenderOperationNames[kPresentOp] =
"__MyPresentTarget"
1604 self.mRenderOperations[kPresentOp] = viewRenderPresentTarget( self.mRenderOperationNames[kPresentOp] )
1605 self.mRenderOperationNames[kPresentOp] = self.mRenderOperations[kPresentOp].name()
1610 rect = om.MFloatPoint(0.0, 0.0, 1.0, 1.0)
1614 self.mRenderOperationNames[kBackgroundBlit] =
"__MyPreQuadRender"
1615 quadOp = viewRenderQuadRender( self.mRenderOperationNames[kBackgroundBlit] )
1616 quadOp.setShader( viewRenderQuadRender.kPre_MandelBrot )
1617 quadOp.setViewRectangle(rect)
1618 self.mRenderOperations[kBackgroundBlit] = quadOp
1630 self.mSplitUIDraw =
True
1631 self.mRenderOperations[kMaya3dSceneRender] =
None
1632 self.mRenderOperations[kMaya3dSceneRenderOpaque] =
None
1633 self.mRenderOperations[kMaya3dSceneRenderTransparent] =
None
1634 self.mRenderOperations[kMaya3dSceneRenderUI] =
None
1635 if self.mSplitUIDraw:
1640 self.mRenderOperationNames[kMaya3dSceneRenderOpaque] =
"__MyStdSceneRenderOpaque"
1641 clearMask = omr.MClearOperation.kClearDepth | omr.MClearOperation.kClearStencil
1642 sceneOp = viewRenderSceneRender( self.mRenderOperationNames[kMaya3dSceneRenderOpaque], omr.MSceneRender.kRenderOpaqueShadedItems, clearMask )
1643 sceneOp.setViewRectangle(rect)
1644 self.mRenderOperations[kMaya3dSceneRenderOpaque] = sceneOp
1647 sDrawTransparent =
True
1648 if sDrawTransparent:
1649 self.mRenderOperationNames[kMaya3dSceneRenderTransparent] =
"__MyStdSceneRenderTransparent"
1650 clearMask = omr.MClearOperation.kClearDepth | omr.MClearOperation.kClearStencil
1652 clearMask = omr.MClearOperation.kClearNone
1653 sceneOp = viewRenderSceneRender( self.mRenderOperationNames[kMaya3dSceneRenderTransparent], omr.MSceneRender.kRenderTransparentShadedItems, clearMask )
1654 sceneOp.setViewRectangle(rect)
1655 self.mRenderOperations[kMaya3dSceneRenderTransparent] = sceneOp
1658 self.mRenderOperationNames[kMaya3dSceneRenderUI] =
"__MyStdSceneRenderUI"
1659 clearMask = omr.MClearOperation.kClearDepth | omr.MClearOperation.kClearStencil
1660 if sDrawOpaque
or sDrawTransparent:
1661 clearMask = omr.MClearOperation.kClearStencil
1662 sceneOp = viewRenderSceneRender( self.mRenderOperationNames[kMaya3dSceneRenderUI], omr.MSceneRender.kRenderUIItems, clearMask )
1663 sceneOp.setViewRectangle(rect)
1664 self.mRenderOperations[kMaya3dSceneRenderUI] = sceneOp
1667 self.mRenderOperationNames[kMaya3dSceneRender] =
"__MyStdSceneRender"
1668 clearMask = omr.MClearOperation.kClearDepth | omr.MClearOperation.kClearStencil
1669 sceneOp = viewRenderSceneRender( self.mRenderOperationNames[kMaya3dSceneRender], omr.MSceneRender.kNoSceneFilterOverride, clearMask )
1670 sceneOp.setViewRectangle(rect)
1671 self.mRenderOperations[kMaya3dSceneRender] = sceneOp
1677 self.mRenderOperationNames[kThresholdOp] =
"__ThresholdColor"
1678 quadThreshold = viewRenderQuadRender( self.mRenderOperationNames[kThresholdOp] )
1679 quadThreshold.setShader( viewRenderQuadRender.kScene_Threshold )
1680 quadThreshold.setViewRectangle(rect)
1681 self.mRenderOperations[kThresholdOp] = quadThreshold
1683 self.mRenderOperationNames[kHorizBlurOp] =
"__HorizontalBlur"
1684 quadHBlur = viewRenderQuadRender( self.mRenderOperationNames[kHorizBlurOp] )
1685 quadHBlur.setShader( viewRenderQuadRender.kScene_BlurHoriz )
1686 quadHBlur.setViewRectangle(rect)
1687 self.mRenderOperations[kHorizBlurOp] = quadHBlur
1689 self.mRenderOperationNames[kVertBlurOp] =
"__VerticalBlur"
1690 quadVBlur = viewRenderQuadRender( self.mRenderOperationNames[kVertBlurOp] )
1691 quadVBlur.setShader( viewRenderQuadRender.kScene_BlurVert )
1692 quadVBlur.setViewRectangle(rect)
1693 self.mRenderOperations[kVertBlurOp] = quadVBlur
1695 self.mRenderOperationNames[kBlendOp] =
"__SceneBlurBlend"
1696 quadBlend = viewRenderQuadRender( self.mRenderOperationNames[kBlendOp] )
1697 quadBlend.setShader( viewRenderQuadRender.kSceneBlur_Blend )
1698 quadBlend.setViewRectangle(rect)
1699 self.mRenderOperations[kBlendOp] = quadBlend
1703 self.mRenderOperationNames[kUserOpNumber] =
"__MyCustomSceneRender"
1704 userOp = viewRenderUserOperation( self.mRenderOperationNames[kUserOpNumber] )
1705 userOp.setViewRectangle(rect)
1706 self.mRenderOperations[kUserOpNumber] = userOp
1708 wantPostQuadOps =
False
1712 self.mRenderOperationNames[kPostOperation1] =
"__PostOperation1"
1713 quadOp2 = viewRenderQuadRender( self.mRenderOperationNames[kPostOperation1] )
1714 quadOp2.setShader( viewRenderQuadRender.kPost_EffectMonochrome )
1715 quadOp2.setViewRectangle(rect)
1717 self.mRenderOperations[kPostOperation1] = quadOp2
1719 self.mRenderOperations[kPostOperation1] =
None
1722 self.mRenderOperationNames[kPostOperation2] =
"__PostOperation2"
1723 quadOp3 = viewRenderQuadRender( self.mRenderOperationNames[kPostOperation2] )
1724 quadOp3.setShader( viewRenderQuadRender.kPost_EffectInvert )
1725 quadOp3.setViewRectangle(rect)
1727 self.mRenderOperations[kPostOperation2] = quadOp3
1729 self.mRenderOperations[kPostOperation2] =
None
1734 self.mRenderOperationNames[kPresentOp] =
"__MyPresentTarget"
1735 self.mRenderOperations[kPresentOp] = viewRenderPresentTarget( self.mRenderOperationNames[kPresentOp] )
1736 self.mRenderOperationNames[kPresentOp] = self.mRenderOperations[kPresentOp].name()
1739 self.mRenderOperations[kHUDBlit] = viewRenderHUDOperation()
1740 self.mRenderOperationNames[kHUDBlit] = self.mRenderOperations[kHUDBlit].name()
1743 if not self.mSimpleRendering:
1745 gotTargets = self.updateRenderTargets()
1749 if not self.mRenderOperations[kMaya3dSceneRender]
is None:
1750 self.mRenderOperations[kMaya3dSceneRender].setPanelName( self.mPanelName )
1751 if not self.mRenderOperations[kMaya3dSceneRenderOpaque]
is None:
1752 self.mRenderOperations[kMaya3dSceneRenderOpaque].setPanelName( self.mPanelName )
1753 if not self.mRenderOperations[kMaya3dSceneRenderTransparent]
is None:
1754 self.mRenderOperations[kMaya3dSceneRenderTransparent].setPanelName( self.mPanelName )
1755 if not self.mRenderOperations[kMaya3dSceneRenderUI]
is None:
1756 self.mRenderOperations[kMaya3dSceneRenderUI].setPanelName( self.mPanelName )
1757 if not self.mRenderOperations[kUserOpNumber]
is None:
1758 self.mRenderOperations[kUserOpNumber].setPanelName( self.mPanelName )
1760 self.mCurrentOperation = -1
1768 if self.mDebugOverride:
1769 print self.name() +
" : Perform cleanup. panelname=" + self.mPanelName
1771 quadOp = self.mRenderOperations[kPostOperation1]
1772 if not quadOp
is None:
1773 quadOp.setRenderTargets(
None)
1775 quadOp = self.mRenderOperations[kPostOperation2]
1776 if not quadOp
is None:
1777 quadOp.setRenderTargets(
None)
1780 self.mPanelName =
""
1782 self.mCurrentOperation = -1
1784 def panelName(self):
1785 return self.mPanelName
1787 def setSimpleRendering(self, flag):
1788 self.mSimpleRendering = flag
1794 viewRenderOverrideInstance =
None
1799 def initializePlugin(obj):
1800 plugin = om.MFnPlugin(obj)
1802 global viewRenderOverrideInstance
1803 viewRenderOverrideInstance = viewRenderOverride(
"my_viewRenderOverride" )
1804 omr.MRenderer.registerOverride(viewRenderOverrideInstance)
1806 sys.stderr.write(
"registerOverride\n")
1815 def uninitializePlugin(obj):
1816 plugin = om.MFnPlugin(obj)
1818 global viewRenderOverrideInstance
1819 if not viewRenderOverrideInstance
is None:
1820 omr.MRenderer.deregisterOverride(viewRenderOverrideInstance)
1821 viewRenderOverrideInstance =
None
1823 sys.stderr.write(
"deregisterOverride\n")