def RegisterGUI(): """ Register the GafferUIItem and GafferAddLocationAction classes that are used by the GUI. GafferAddLocationAction - Controls how this item appears in the "Add..." menu GafferUIItem - Controls the tabs in the Gaffer UI """ from Katana import UI4 from PluginAPI.BaseGafferAction import BaseGafferAddLocationAction UndoGrouping = UI4.Util.UndoGrouping.UndoGrouping FnKatImport.FromObject(GafferAPI.UIItems, merge = ['*']) #////////////////////////////////////////////////////////////////////////////// #/// class GafferFlagUIItem(GafferUIItem): # decorateChildTreeItem no longer required to hide children, left # here to retain correct behavior in Katana <= 2.5.5 def decorateChildTreeItem(self, rootProducer, item, childItem): childItem.setHidden(True) def isChildVisible(self, name, type): """Flag doesn't show children of any type.""" return False class AddWhiteFlagAction(BaseGafferAddLocationAction): def __init__(self, parent, parentPath, nodeName, preselectMethod): BaseGafferAddLocationAction.__init__(self, parent, self.getActionName(), parentPath, nodeName, preselectMethod) self.setIcon(UI4.Util.ScenegraphIconManager.GetIcon('polymesh')) def go(self, checked=None): node = self.getNode() if not node: return u = UndoGrouping(self.getActionName()) newPath = node.addWhiteFlag('whiteFlag1', self.getParentPath(), scriptItemClassName = self.getPackageName()) self.preselectPath(newPath) def getPackageName(self): return PackageName @staticmethod def getActionName(): return 'Add White Flag' @staticmethod def getMenuGroup(): return None # Register the ScriptAction GafferAPI.GafferPluginsModule.RegisterCreateCallback('AddWhiteFlagAction', AddWhiteFlagAction) GafferAPI.GafferPluginsModule.RegisterGafferUIItem(PackageName, GafferFlagUIItem)
def RegisterGUI(): """ Register the GafferUIItem and GafferAddLocationAction classes that are used by the GUI. GafferAddLocationAction - Controls how this item appears in the "Add..." menu GafferUIItem - Controls the tabs in the Gaffer UI """ from Katana import UI4, QT4FormWidgets, FormMaster from PluginAPI.BaseGafferAction import BaseGafferAddLocationAction UndoGrouping = UI4.Util.UndoGrouping.UndoGrouping FnKatImport.FromObject(GafferAPI.UIItems, merge=['*']) #////////////////////////////////////////////////////////////////////////////// #/// class GafferMasterMaterialUIItem(GafferUIItem): def getMaterialTabPolicy(self): from LightScriptItem import GafferLightUIItem return GafferLightUIItem.GetMaterialTabPolicy(self) def decorateTreeItem(self, rootProducer, item): #from LightScriptItem import GafferLightUIItemClass as GafferLightUIItem from LightScriptItem import GafferLightUIItem log.debug("GafferLightUIItem = %s" % GafferLightUIItem) GafferUIItem.decorateTreeItem(self, rootProducer, item) GafferLightUIItem.DecorateShaderColumn(self, rootProducer, item) def mousePressEvent(self, event, item, column): from LightScriptItem import GafferLightUIItem if not item: return if column == C.COLUMN_SHADER: return GafferLightUIItem.ShaderColumnClickEvent( self, event, item, column) return GafferUIItem.mousePressEvent(self, event, item, column) class AddMasterMaterialAction(BaseGafferAddLocationAction): def __init__(self, parent, parentPath, nodeName, preselectMethod): BaseGafferAddLocationAction.__init__(self, parent, self.getActionName(), parentPath, nodeName, preselectMethod) self.setIcon( UI4.Util.ScenegraphIconManager.GetIcon('light material')) def go(self, checked=None): node = self.getNode() if not node: return u = UndoGrouping(self.getActionName()) desiredPath = self.getParentPath() + '/material1' newPath = node.addMasterMaterial( desiredPath, alwaysCreateWithOptionalLeafRename=True, scriptItemClassName=self.getPackageName()) self.preselectPath(newPath) def getPackageName(self): return PackageName @staticmethod def getActionName(): return 'Add Master Material' @staticmethod def getMenuGroup(): return 'Materials' # Register the ScriptAction GafferAPI.GafferPluginsModule.RegisterCreateCallback( 'AddMasterMaterialAction', AddMasterMaterialAction) GafferAPI.GafferPluginsModule.RegisterGafferUIItem( PackageName, GafferMasterMaterialUIItem)
# Copyright (c) 2017 Light Chaser Animation Inc. All rights reserved. from __future__ import with_statement import Katana, FnKatImport FnKatImport.FromObject(Katana.Plugins.ViewerManipulatorAPI, merge=['*']) from LightManipulatorBase import LightManipulator LINE_COLOR = (1, 1, 0, 1) HANDLE_COLOR = (0.5, 1, 1, 1) DISABLED_HANDLE_COLOR = (0.5, 0.5, 0.5, 1) GEOMETRY_COLOR = (0, 1, 0, 0.125) BOLD_GEOMETRY_COLOR = (0.5, 1, 0.5, 0.125) LENS_COLOR = (0, 0.5, 1, 0.4) RADIUS_COLOR = (1, 1, 1, 0.125) BRIGHT_COLOR = (1, 1, 1, 0.125) DISABLED_GEOMETRY_COLOR = (0.5, 0.5, 0.5, 0.125) BOLD_DISABLED_GEOMETRY_COLOR = (0.67, 0.67, 0.67, 0.125) GL = GLStateManager.GLStateSet def cPowerToAngle(cpower, intensity, wideAngle): if cpower == 0: return 0 return math.degrees((math.radians(wideAngle) / math.pi * math.acos(math.pow(intensity, 1.0 / cpower))) * 2.0) def angleToCPower(angle, intensity, wideAngle): if angle > wideAngle: angle = wideAngle
def RegisterGUI(): """ Register the GafferUIItem and GafferAddLocationAction classes that are used by the GUI. GafferAddLocationAction - Controls how this item appears in the "Add..." menu GafferUIItem - Controls the tabs in the Gaffer UI """ from Katana import UI4, QT4FormWidgets, FormMaster from PluginAPI.BaseGafferAction import BaseGafferAddLocationAction UndoGrouping = UI4.Util.UndoGrouping.UndoGrouping FnKatImport.FromObject(GafferAPI.UIItems, merge=['*']) class GafferAimTargetUIItem(GafferUIItem): def getObjectTabPolicy(self): editorNode = self.getReferencedNode('node_primCreate') if not editorNode: return scriptItem = self.getScriptItem() rootPolicy = QT4FormWidgets.PythonGroupPolicy('object') rootPolicy.getWidgetHints()['hideTitle'] = True nodePolicy = FormMaster.CreateParameterPolicy( None, editorNode.getParameter("transform")) rootPolicy.addChildPolicy(nodePolicy) return rootPolicy def getLinkingTabPolicy(self): editorNode = self.getReferencedNode('node_aimConstraint') if not editorNode: return scriptItem = self.getScriptItem() rootPolicy = QT4FormWidgets.PythonGroupPolicy('object') rootPolicy.getWidgetHints()['hideTitle'] = True nodePolicy = FormMaster.CreateParameterPolicy( None, editorNode.getParameter("basePath")) rootPolicy.addChildPolicy(nodePolicy) return rootPolicy class GafferAimTargetScriptAction(BaseGafferAddLocationAction): def __init__(self, parent, parentPath, nodeName, preselectMethod): BaseGafferAddLocationAction.__init__(self, parent, self.getActionName(), parentPath, nodeName, preselectMethod) self.setIcon(LocalIcon('coordsys16')) def getPackageName(self): return PackageName @staticmethod def getActionName(): return 'Add Aim Target' @staticmethod def getMenuGroup(): return 'Lighting' def go(self, checked=None): node = self.getNode() if not node: return u = UndoGrouping(self.getActionName()) newPath = node.addAimTarget( self.getParentPath(), 'aim1', scriptItemClassName=self.getPackageName()) self.preselectPath(newPath) # Register the ScriptAction GafferAPI.GafferPluginsModule.RegisterCreateCallback( 'GafferAimTargetScriptAction', GafferAimTargetScriptAction) GafferAPI.GafferPluginsModule.RegisterGafferUIItem(PackageName, GafferAimTargetUIItem)
def RegisterGUI(): """ Register the GafferUIItem and GafferAddLocationAction classes that are used by the GUI. GafferAddLocationAction - Controls how this item appears in the "Add..." menu GafferUIItem - Controls the tabs in the Gaffer UI """ from Katana import UI4, QT4FormWidgets,FormMaster from PluginAPI.BaseGafferAction import BaseGafferAddLocationAction UndoGrouping = UI4.Util.UndoGrouping.UndoGrouping FnKatImport.FromObject(GafferAPI.UIItems, merge = ['*']) #////////////////////////////////////////////////////////////////////////////// #/// class GafferRigUIItem(GafferUIItem): def getObjectTabPolicy(self): editorNode = self.getReferencedNode('node_primCreate') if not editorNode: return scriptItem = self.getScriptItem() rootPolicy = QT4FormWidgets.PythonGroupPolicy('object') rootPolicy.getWidgetHints()['hideTitle'] = True nodePolicy = FormMaster.CreateParameterPolicy(None, editorNode.getParameter("transform")) rootPolicy.addChildPolicy(nodePolicy) AddConstraintPolicy(scriptItem, rootPolicy, scriptItem.getPointConstraintNode(), 'point', ['targetPath.i0', 'allowMissingTargets', 'baseOrigin', 'targetOrigin']) AddConstraintPolicy(scriptItem, rootPolicy, scriptItem.getOrientConstraintNode(), 'orient', ['targetPath', 'targetOrientation', 'targetFaceIndex', 'allowMissingTargets', 'xAxis', 'yAxis', 'zAxis']) return rootPolicy def fillContextMenu(self, menu): GafferUIItem.fillContextMenu(self, menu) locked = self.getReferencedNode('node_primCreate').isLocked() scriptItem = self.getScriptItem() def Ungroup(): u = UI4.Util.UndoGrouping.UndoGrouping( 'Ungroup Rig %s' % scriptItem.getFullName()) gafferNode = scriptItem.getGafferPro() hcNode = SA.GetHierarchyCreateNode(gafferNode) treeEntry = hcNode.getLocationTree( atLocation=scriptItem.getFullName()) childPaths = [scriptItem.getFullName() + '/' + x.name for x in treeEntry.children] cookedRoot = Nodes3DAPI.GetGeometryProducer(gafferNode) itemXforms = [] for childPath in childPaths: childScriptItem = gafferNode.getScriptItemForPath(childPath) xform = None xformNode = None if childScriptItem and hasattr( childScriptItem, 'getAbstractTransformNode'): xformNode = childScriptItem.getAbstractTransformNode() if xformNode: locProducer = cookedRoot.getProducerByPath(childPath) if locProducer: xform = locProducer.getFlattenedGlobalXform() newPath = hcNode.reparentLocation(childPath, scriptItem.getFullName().rsplit('/', 1)[0]) if xform and xformNode: t, s, r = GeoAPI.Util.Matrix.explodeMatrix4x4(xform) xformNode.setInteractiveTransform(newPath, s, r, t, NodegraphAPI.GetCurrentTime()) scriptItem.delete() menu.addSeparator() menu.addAction('Ungroup Rig', Ungroup).setEnabled(not locked) class AddRigAction(BaseGafferAddLocationAction): def __init__(self, parent, parentPath, nodeName, preselectMethod): BaseGafferAddLocationAction.__init__(self, parent, self.getActionName(), parentPath, nodeName, preselectMethod) self.setIcon(UI4.Util.ScenegraphIconManager.GetIcon('locator')) def go(self, checked=None): node = self.getNode() if not node: return u = UndoGrouping(self.getActionName()) desiredPath = self.getParentPath() + '/rig1' newPath = node.addRig(desiredPath, alwaysCreateWithOptionalLeafRename = True, scriptItemClassName = self.getPackageName()) self.preselectPath(newPath) def getPackageName(self): return PackageName @staticmethod def getActionName(): return 'Add Rig' @staticmethod def getMenuGroup(): return 'Lighting' # Register the ScriptAction GafferAPI.GafferPluginsModule.RegisterCreateCallback('AddRigAction', AddRigAction) GafferAPI.GafferPluginsModule.RegisterGafferUIItem(PackageName, GafferRigUIItem)
def RegisterGUI(): """ Register the GafferUIItem and GafferAddLocationAction classes that are used by the GUI. GafferAddLocationAction - Controls how this item appears in the "Add..." menu GafferUIItem - Controls the tabs in the Gaffer UI """ from Katana import UI4, QT4FormWidgets, FormMaster from PluginAPI.BaseGafferAction import BaseGafferAddLocationAction UndoGrouping = UI4.Util.UndoGrouping.UndoGrouping FnKatImport.FromObject(GafferAPI.UIItems, merge=['*']) global GafferLightUIItem class GafferLightUIItem(GafferUIItem): def getObjectTabPolicy(self): editorNode = self.getReferencedNode('node_lightCreate') if not editorNode: return scriptItem = self.getScriptItem() rootPolicy = QT4FormWidgets.PythonGroupPolicy('object') rootPolicy.getWidgetHints()['hideTitle'] = True geoPolicy = QT4FormWidgets.PythonGroupPolicy( 'geometry', rootPolicy) geoPolicy.getWidgetHints()['open'] = True rootPolicy.addChildPolicy(geoPolicy) attrsParam = SA.GetAttributesParameterForPath( scriptItem.getGafferPro(), scriptItem.getFullName(), create=False) radiusParam = editorNode.getParameter('radius') if attrsParam and attrsParam.getChild('geometry'): geoParam = attrsParam.getChild('geometry') if not radiusParam: radiusParam = geoParam.getChild('radius') if radiusParam: radiusPolicy = QT4FormWidgets.ValuePolicyProxy( FormMaster.CreateParameterPolicy(geoPolicy, radiusParam)) radiusPolicy.getWidgetHints()['min'] = '0' geoPolicy.addChildPolicy(radiusPolicy) for name in ('fov', 'centerOfInterest', 'near', 'far', 'screenWindow'): geoPolicy.addChildPolicy( FormMaster.CreateParameterPolicy( geoPolicy, editorNode.getParameter(name))) transformPolicy = FormMaster.CreateParameterPolicy( rootPolicy, editorNode.getParameter('transform')) rootPolicy.addChildPolicy(transformPolicy) constraintNode = self.getReferencedNode('node_aimConstraint') if not constraintNode: return rootPolicy AddConstraintPolicy(scriptItem, rootPolicy, constraintNode, 'aim', [ 'targetPath.i0', 'targetOrigin', 'baseAimAxis', 'baseUpAxis', 'targetUpAxis' ]) displayPolicy = QT4FormWidgets.PythonGroupPolicy( 'display', rootPolicy) rootPolicy.addChildPolicy(displayPolicy) vosNode = self.getReferencedNode('node_viewerObjectSettings') if vosNode: # textPolicy = FormMaster.NodeBypassPolicy(displayPolicy, vosNode) # hints = textPolicy.getWidgetHints() # hints['label'] = 'display annotation' # hints['widget'] = 'checkBox' # displayPolicy.addChildPolicy(textPolicy) displayPolicy.addChildPolicy( FormMaster.CreateParameterPolicy( displayPolicy, vosNode.getParameter( 'args.viewer.default.annotation.text'))) previewColorPolicy = QT4FormWidgets.ValuePolicyProxy( FormMaster.CreateParameterPolicy( displayPolicy, editorNode.getParameter('previewColor'))) displayPolicy.addChildPolicy(previewColorPolicy) return rootPolicy #static to allow other non-inherited types to call @staticmethod def GetMaterialTabPolicy(self): editorNode = self.getReferencedNode('node_material') if not editorNode: return scriptItem = self.getScriptItem() rootPolicy = QT4FormWidgets.PythonGroupPolicy('material') rootPolicy.getWidgetHints()['open'] = True lookFileEnablePolicy = QT4FormWidgets.ValuePolicyProxy( FormMaster.CreateParameterPolicy( rootPolicy, SA.GetLookFileMaterialEnabledParameter(scriptItem))) lookFileEnablePolicy.setWidgetHints({'widget': 'checkBox'}) rootPolicy.addChildPolicy(lookFileEnablePolicy) refPolicy = QT4FormWidgets.PythonGroupPolicy( 'reference', rootPolicy) refPolicy.getWidgetHints().update({ 'open': True, 'conditionalVisOp': 'notEqualTo', 'conditionalVisPath': '../%s' % lookFileEnablePolicy.getName(), 'conditionalVisValue': '0', }) rootPolicy.addChildPolicy(refPolicy) refParam = SA.GetLookFileMaterialReferenceParameter(scriptItem) remap = { 'asset': 'lookfile', } for param in refParam.getChildren(): policy = QT4FormWidgets.ValuePolicyProxy( FormMaster.CreateParameterPolicy(refPolicy, param)) hints = {} editorNode.addParameterHints( 'Material.lookfile.' + remap.get(policy.getName(), policy.getName()), hints) if policy.getName() == 'materialPath': hints = dict(hints) hints['assetPolicy'] = '../asset' policy.setWidgetHints(hints) refPolicy.addChildPolicy(policy) rootPolicy.addChildPolicy( FormMaster.CreateParameterPolicy( rootPolicy, editorNode.getParameter('addShaderType'))) rootPolicy.addChildPolicy( FormMaster.CreateParameterPolicy( rootPolicy, editorNode.getParameter('shaders'))) return rootPolicy def getMaterialTabPolicy(self): return self.__class__.GetMaterialTabPolicy(self) def getLinkingTabPolicy(self): return self.__class__.GetLinkingTabPolicy(self) @staticmethod def GetLinkingTabPolicy(self): scriptItem = self.getScriptItem() gnode = scriptItem.getGafferPro() if not gnode: return rootPolicy = QT4FormWidgets.PythonGroupPolicy('linking') rootPolicy.getWidgetHints()['hideTitle'] = True def addLinkingPolicy(defaultPolicy, exceptionsPolicy, name): if not defaultPolicy: return group = QT4FormWidgets.PythonGroupPolicy(name, rootPolicy) group.getWidgetHints()['open'] = True rootPolicy.addChildPolicy(group) policy = QT4FormWidgets.ValuePolicyProxy( FormMaster.CreateParameterPolicy(group, defaultPolicy)) policy.setWidgetHints({ 'widget': 'mapper', 'options': 'on:1|off:0' }) group.addChildPolicy(policy) policy = FormMaster.NodeBypassPolicy( group, exceptionsPolicy.getNode()) hints = policy.getWidgetHints() hints['label'] = 'enable exceptions' hints['widget'] = 'checkBox' hints['headerChild'] = 'objects' group.addChildPolicy(policy) cel = QT4FormWidgets.ValuePolicyProxy( FormMaster.CreateParameterPolicy(group, exceptionsPolicy)) hints = {} hints['widget'] = 'cel' hints['conditionalVisOps'] = { 'conditionalVisOp': 'notEqualTo', 'conditionalVisPath': '../' + policy.getName(), 'conditionalVisValue': '0', } hints['widget'] = 'cel' hints['help'] = \ 'Exceptions will not work unless scene' \ ' is connected into Gaffer' hints['helpAlert'] = 'warning' hints['open'] = True cel.setWidgetHints(hints) group.addChildPolicy(cel) addLinkingPolicy(scriptItem.getDefaultLinkingParameter(), scriptItem.getLinkingExceptionsParameter(), 'light linking') addLinkingPolicy(scriptItem.getDefaultShadowLinkingParameter(), scriptItem.getShadowLinkingExceptionsParameter(), 'shadow linking') if rootPolicy.getNumChildren(): return rootPolicy @staticmethod def DecorateShaderColumn(self, rootProducer, item): path, paramKey = item.getItemData() scriptItem = self.getScriptItem() if not rootProducer: rootProducer = SA.GetInternalProducer( scriptItem.getGafferPro()) if rootProducer: #materialProducer = rootProducer.getProducerByPath( # scriptItem.getMaterialPath()) # GEOLIB3 We're resolving materials here, no need to walk to # the material location materialProducer = rootProducer.getProducerByPath( scriptItem.getFullName()) else: materialProducer = None if hasattr(scriptItem, 'getMasterMaterial'): masterMaterial = scriptItem.getMasterMaterial() else: masterMaterial = None localLookFileMaterialSet = scriptItem.getLookFileMaterialEnabled() if masterMaterial: item.setText(C.COLUMN_SHADER, masterMaterial) elif materialProducer: item.setText(C.COLUMN_SHADER, "<none>") if localLookFileMaterialSet: #local icon item.setIcon( C.COLUMN_SHADER, UI4.Util.ScenegraphIconManager.GetIcon( 'katana standard')) materialAttr = materialProducer.getGlobalAttribute('material') if materialAttr: refPathAttr = materialAttr.childByName( 'info.reference.materialPath') if refPathAttr: if not localLookFileMaterialSet: #inherited item.setIcon( C.COLUMN_SHADER, UI4.Util.ScenegraphIconManager.GetIcon( 'katana standard')) #set to base name of material path item.setText( C.COLUMN_SHADER, refPathAttr.getData()[0].rsplit('/', 1)[-1]) else: attrName = scriptItem.getMaterialParameterName() shaderAttr = materialAttr.childByName(attrName) if shaderAttr: item.setText(C.COLUMN_SHADER, str(shaderAttr.getData()[0])) else: item.setText(C.COLUMN_SHADER, "<none>") def decorateTreeItem(self, rootProducer, item): GafferUIItem.decorateTreeItem(self, rootProducer, item) self.__class__.DecorateShaderColumn(self, rootProducer, item) scriptItem = self.getScriptItem() color = scriptItem.getColor(rootProducer) if not color is None: item.setIcon(C.COLUMN_COLOR, ColorIcon(tuple(color))) intensity = scriptItem.getIntensity(rootProducer) if not intensity is None: item.setText(C.COLUMN_INT, '%.2f' % intensity) exposure = scriptItem.getExposure(rootProducer) if not exposure is None: item.setText(C.COLUMN_EXP, '%.2f' % exposure) link = scriptItem.getDefaultLinkingParameter().getValue(0.0) exc = scriptItem.getLinkingExceptionsEnabled() item.setText(C.COLUMN_LINK, ("on" if link else "off") + ("*" if exc else "")) def prePaint(self, painter, option, item, column): if column == C.COLUMN_SHADER: scriptItem = self.getScriptItem() if scriptItem.getMasterMaterial(): return GetInheritedColorOption(option) return GafferUIItem.prePaint(self, painter, option, item, column) # decorateChildTreeItem no longer required to hide children, left # here to retain correct behavior in Katana <= 2.5.5 def decorateChildTreeItem(self, rootProducer, item, childItem): childType = SA.GetHierarchyCreateNode( self.getScriptItem().getGafferPro()).getTypeOfLocation( childItem.getItemData()[0]) childItem.setHidden(childType not in frozenset(('locator', ))) def isChildVisible(self, name, type): """Light only shows locators.""" return type == 'locator' @staticmethod def ShaderColumnClickEvent(self, event, item, column): scriptItem = self.getScriptItem() def go(popupItem, meta): u = UI4.Util.UndoGrouping.UndoGrouping('Set Light Shader') #log.debug("popupItem = %s" % popupItem) if meta == MASTER_MATERIAL_KEY: scriptItem.setMasterMaterial(popupItem) else: scriptItem.setShader(popupItem) def setLookFileMaterial(spref, path): u = UI4.Util.UndoGrouping.UndoGrouping( 'Set Look File Material') scriptItem.setLookFileMaterial(spref, path) lookFileValue = scriptItem.getLookFileMaterial() lookFileActive = False if scriptItem.getLookFileMaterialEnabled(): lookFileActive = True getMasterMaterialPaths = None if hasattr(scriptItem, 'setMasterMaterial'): getMasterMaterialPaths = scriptItem.getGafferPro( ).getMasterMaterialPaths profile = scriptItem.getProfile() if hasattr(profile, 'getLightShaderType'): shaderType = profile.getLightShaderType() StandAloneShaderPopup.ShowForTreeItem( item, column, go, getMasterMaterialPaths, setLookFileCallback=setLookFileMaterial, lookFileValue=lookFileValue, lookFileActive=lookFileActive, shaderType=shaderType, shouldIncludeShaderCallback=profile.shouldIncludeShader, profile=profile) return True def mousePressEvent(self, event, item, column): if not item: return if column == C.COLUMN_SHADER: return self.__class__.ShaderColumnClickEvent( self, event, item, column) elif column == C.COLUMN_COLOR: button = event.button() if button == QtCore.Qt.LeftButton: policy = self.getScriptItem().getColorPolicy() if policy: isAnimationCurve = False needsKeyFrames = False autoKeyEnabled = NodegraphAPI.GetAutoKeyAll() for child in policy.getArrayChildren(): if child.isCurveEnabled(): isAnimationCurve = True if not NodegraphAPI.GetAutoKeyAll( ) and not child.getCurveAutoKey(): autoKeyEnabled = False if not child.getCurveKey(): needsKeyFrames = True if isAnimationCurve and needsKeyFrames and autoKeyEnabled is False: QtGui.QMessageBox.question( None, "Changing animated parameter", "Warning, one or more of the color channels are animated without auto-key frame enabled. You may need to add key frames when changing this color or activate auto-keying", "OK") UI4.Util.Color.ShowColorPicker(policy) #TODO, handle multiselection case elif button == QtCore.Qt.MidButton: policy = self.getScriptItem().getColorPolicy() if policy is None: return GafferUIItem.mousePressEvent( self, event, item, column) dragDict = QT4Color.GetColorPolicyDragDict(policy) dragDict['itemhash'] = hash(item) dragData = QT4Color.BuildDragDataFromInfo(**dragDict) mimeData = QtCore.QMimeData() mimeData.setData(QT4Color.GetColorDragType(), dragData) pixmap = QT4Widgets.InteractiveDrag.buildDragPixmap( QT4Color.BuildDragPixmapFromColor(dragDict['color']), 1) drag = QT4Widgets.InteractiveDrag(item.treeWidget(), mimeData, pixmap) event.accept() drag.exec_() else: return GafferUIItem.mousePressEvent(self, event, item, column) def dragMoveEvent(self, event, item, column): if column == C.COLUMN_COLOR: if event.provides(QT4Color.GetColorDragType()): colorInfo = QT4Color.GetColorInfoFromDragObject(event) if hash(item) == colorInfo.get('itemhash'): return False return True def dropEvent(self, event, item, column): if column == C.COLUMN_COLOR: if event.provides(QT4Color.GetColorDragType()): colorInfo = QT4Color.GetColorInfoFromDragObject(event) u = UI4.Util.UndoGrouping.UndoGrouping('Drop Color') self.getScriptItem().setColor(colorInfo['color'][0:3]) def replaceEditor(self, editor, option, item, column): if column == C.COLUMN_INT: editor.setValidator(QtGui.QDoubleValidator(editor)) elif column == C.COLUMN_EXP: editor.setValidator(QtGui.QDoubleValidator(editor)) return editor def isItemColumnEditable(self, item, column): if column == C.COLUMN_INT: return self.getScriptItem().canEditIntensity() elif column == C.COLUMN_EXP: return self.getScriptItem().canEditExposure() else: return GafferUIItem.isItemColumnEditable(self, item, column) def itemEdited(self, item, column, value, createKeyframe=False): try: if column == C.COLUMN_INT: u = UI4.Util.UndoGrouping.UndoGrouping('Edit Intensity') if item.isSelected(): for si in self._getScriptItemsForSelectedItems(item): if si.canEditIntensity(): si.setIntensity(value, createKeyframe) else: si = self.getScriptItem() si.setIntensity(value, createKeyframe) return True elif column == C.COLUMN_EXP: si = self.getScriptItem() si.setExposure(value, createKeyframe) return True else: return GafferUIItem.itemEdited(self, item, column, value) except ScriptItems.AnimationKeyNotFoundException, ex: if QtGui.QMessageBox.question( None, "Changing animated parameter", "You are attempting to change an animated parameter without a key frame at the current frame. Would you like to add a new key frame?", "Cancel", "Create Key") != 0: if createKeyframe is False: self.itemEdited( item, column, value, True ) # Call function again but setting key frame if necessary else: item.setText(column, '%.2f' % ex.getValue()) # Reset the value in the tree except ScriptItems.AnimatingExpressionException, ex: if QtGui.QMessageBox.question( None, "Changing expression parameter", "Cannot change a parameter that is set by an expression.", "OK") == 0: item.setText(column, '%.2f' % ex.getValue())
def RegisterGUI(): """ Register the GafferUIItem and GafferAddLocationAction classes that are used by the GUI. GafferAddLocationAction - Controls how this item appears in the "Add..." menu GafferUIItem - Controls the tabs in the Gaffer UI """ from Katana import UI4, QT4FormWidgets, FormMaster from PluginAPI.BaseGafferAction import BaseGafferAddLocationAction UndoGrouping = UI4.Util.UndoGrouping.UndoGrouping FnKatImport.FromObject(GafferAPI.UIItems, merge=['*']) #////////////////////////////////////////////////////////////////////////////// #/// class GafferSkyDomeUIItem(GafferUIItem): # decorateChildTreeItem no longer required to hide children, left # here to retain correct behavior in Katana <= 2.5.5 def decorateChildTreeItem(self, rootProducer, item, childItem): childItem.setHidden(True) def isChildVisible(self, name, type): """SkyDome doesn't show children of any type.""" return False def decorateTreeItem(self, rootProducer, item): from LightScriptItem import GafferLightUIItem GafferUIItem.decorateTreeItem(self, rootProducer, item) GafferLightUIItem.DecorateShaderColumn(self, rootProducer, item) if not rootProducer: item.setIcon(C.COLUMN_NAME, LocalIcon('skydome16')) return activeSkyDomePathAttr = rootProducer.getAttribute( 'arnoldGlobalStatements.background') activeSkyDomePath = activeSkyDomePathAttr and \ activeSkyDomePathAttr.getData()[0] if (self.getNode().getParameter('pathName').getValue(0) + '/material' == activeSkyDomePath): item.setIcon(C.COLUMN_NAME, LocalIcon('skydome16')) else: #TODO, inactive item.setIcon(C.COLUMN_NAME, LocalIcon('skydomeInactive16')) def mousePressEvent(self, event, item, column): if not item: return if column == C.COLUMN_SHADER: from LightScriptItem import GafferLightUIItem return GafferLightUIItem.ShaderColumnClickEvent( self, event, item, column) return GafferUIItem.mousePressEvent(self, event, item, column) def getMaterialTabPolicy(self): from LightScriptItem import GafferLightUIItem return GafferLightUIItem.GetMaterialTabPolicy(self) def getObjectTabPolicy(self): editorNode = self.getReferencedNode('node_primCreate') if not editorNode: return rootPolicy = QT4FormWidgets.PythonGroupPolicy('object') rootPolicy.getWidgetHints()['hideTitle'] = True scriptItem = self.getScriptItem() attrsParam = SA.GetAttributesParameterForPath( scriptItem.getGafferPro(), scriptItem.getMaterialPath(), create=False) if attrsParam: for name in ('resolution', ): param = attrsParam.getChild("geometry." + name) if not param: continue policy = QT4FormWidgets.ValuePolicyProxy( FormMaster.CreateParameterPolicy(rootPolicy, param)) policy.getWidgetHints()['int'] = True rootPolicy.addChildPolicy(policy) for name in ( 'previewAlpha', 'transform', 'viewerPickable', ): rootPolicy.addChildPolicy( FormMaster.CreateParameterPolicy( rootPolicy, editorNode.getParameter(name))) ll = scriptItem.getNode().getParameter('latlongOrientation') if ll: llp = FormMaster.CreateParameterPolicy(rootPolicy, ll) llp.getWidgetHints()['widget'] = 'popup' llp.getWidgetHints()['options'] = 'Interior|Exterior' llp.getWidgetHints( )['help'] = Resources.HELP_LATLONGORIENTATION rootPolicy.addChildPolicy(llp) return rootPolicy def getLinkingTabPolicy(self): from LightScriptItem import GafferLightUIItem return GafferLightUIItem.GetLinkingTabPolicy(self) def fillContextMenu(self, menu): menu.addSeparator() scriptItem = self.getScriptItem() def go(): u = UI4.Util.UndoGrouping.UndoGrouping('Activate Skydome') scriptItem.makeActiveAsBackground() menu.addAction('Make Active As Background', go) class AddSkyDomeAction(BaseGafferAddLocationAction): def __init__(self, parent, parentPath, nodeName, preselectMethod): BaseGafferAddLocationAction.__init__(self, parent, self.getActionName(), parentPath, nodeName, preselectMethod) self.setIcon(LocalIcon('skydome16')) def go(self, checked=None): node = self.getNode() if not node: return u = UndoGrouping(self.getActionName()) newPath = node.addSkyDome( 'sky', self.getParentPath(), scriptItemClassName=self.getPackageName()) self.preselectPath(newPath) def getPackageName(self): return PackageName @staticmethod def getActionName(): return 'Add Sky Dome' @staticmethod def getMenuGroup(): return 'Sky' # Register the ScriptAction GafferAPI.GafferPluginsModule.RegisterCreateCallback( 'AddSkyDomeAction', AddSkyDomeAction) GafferAPI.GafferPluginsModule.RegisterGafferUIItem(PackageName, GafferSkyDomeUIItem)