def initialize(self): for item in NodegraphAPI.GetAllNodesByType("LiveGroup", ): itemSource = item.getParameterValue("source", NodegraphAPI.GetCurrentTime()) if itemSource: if itemSource[0] != "$": itemName = item.getName() self.dLiveGroupList.append(str(itemName)) self.dLiveGroupSourceMap[str(itemName)] = str(itemSource) else: itemName = item.getName() self.dLiveGroupList.append(str(itemName)) self.dLiveGroupSourceMap[str(itemName)] = str(itemSource) ############################################################### # tmpLiveGroupSource keeps all source value from LiveGroup Node tmpLiveGroupSource = self.dLiveGroupSourceMap.values() aLiveGroupSource = [] for item in tmpLiveGroupSource: if item: Len = len(item.split("/")[-1]) aLiveGroupSource.append(item[:-Len]) if aLiveGroupSource: self.configPath = self.getMostCount( aLiveGroupSource)[0] + "config.json" #print "@@@@@@@@@@@@@@@@@@@@@" #print self.configPath #print os.path.abspath(self.configPath) if os.path.isfile(self.configPath): file = open(self.configPath, "rb") self.dLiveGroupData = json.load(file) file.close() else: self.configPath = ""
def get_render_input_data(knode): pipe_parameter = knode.getParameter('studio_pipe') assets_parameter = pipe_parameter.getChild('assets') render_mode = pipe_parameter.getChild('render_mode').getValue(1.0) frame_type = pipe_parameter.getChild('current_frame').getValue(1.0) assets_data = {} for assets_child in assets_parameter.getChildren(): if frame_type == 'Yes': start_frame = int(NodegraphAPI.GetCurrentTime()) end_frame = start_frame else: start_frame = assets_child.getChild('i0').getValue(1.0) end_frame = assets_child.getChild('i1').getValue(1.0) assets_data.setdefault(assets_child.getName(), [start_frame, end_frame]) show_path = pipe_parameter.getChild('show_path').getValue(1.0) sequence = pipe_parameter.getChild('sequence').getValue(1.0) shot = pipe_parameter.getChild('shot').getValue(1.0) global_start_frame = pipe_parameter.getChild( 'global_frame_range.i0').getValue(1.0) global_end_frame = pipe_parameter.getChild( 'global_frame_range.i1').getValue(1.0) next_version = pipe_parameter.getChild('next_version').getValue(1.0) render_input_data = { 'assets': assets_data, 'render_mode': render_mode, 'frame_type': frame_type, 'show_path': show_path, 'type': 'lighting', 'sequence': sequence, 'shot': shot, 'version': next_version, 'frame_range': [global_start_frame, global_end_frame] } return render_input_data
def __viewNodeChangedEvent(self, node): viewedTime = NodegraphAPI.GetCurrentTime() viewedNode = NodegraphAPI.GetViewNode() print "viewNode ---> ", viewedNode if not viewedNode: self.__runtime = None self.__client = None return self.__runtime = FnGeolib.GetRegisteredRuntimeInstance() txn = self.__runtime.createTransaction() op = Nodes3DAPI.GetOp(txn, viewedNode, viewedTime) if not op: self.__runtime = None return self.__client = txn.createClient() txn.setClientOp(self.__client, op) self.__runtime.commit(txn) self.__setLocations()
def getName(self): """ Returns the name of the light pass, i.e. the scene graph location of the light. """ now = NodegraphAPI.GetCurrentTime() renderPassNode = self.getRenderPassItem().getGroupNode() passesParamGroup = renderPassNode.getParameter('lightPasses') passParamGroup = passesParamGroup.getChildByIndex(self.getIndex()) lightPathParam = passParamGroup.getChild('lightPath') return lightPathParam.getValue(now)
def __setParameterValue(self, constant, value, createKeyframe): from Katana import FormMaster names = self.getProfile().getConstant(constant) param = self.__searchShaderParameters(names, edit=True) if param: frame = NodegraphAPI.GetCurrentTime() valueParam = param.getChild('value') oldValue = valueParam.getValue(NodegraphAPI.GetCurrentTime()) if valueParam.isExpression(): # Cannot keyframe an expression raise ScriptItems.AnimatingExpressionException(oldValue) elif param.isAnimated() and not NodegraphAPI.GetAutoKeyAll(): if not valueParam.hasKey(frame) and createKeyframe: valueParam.setKey(frame) elif valueParam.hasKey( frame) is False and param.getAutoKey() is False: raise ScriptItems.AnimationKeyNotFoundException(oldValue) FormMaster.CreateParameterPolicy(None, param).setValue(value)
def start_render(knode): pipe_parameter = knode.getParameter('studio_pipe') render_mode = pipe_parameter.getChild('render_mode').getValue(1.0) frame_type = pipe_parameter.getChild('current_frame').getValue(1.0) if frame_type == 'Yes': start_frame = int(NodegraphAPI.GetCurrentTime()) end_frame = start_frame else: start_frame = int(NodegraphAPI.GetInTime()) end_frame = int(NodegraphAPI.GetOutTime()) current_render_node = get_specfic_dependency_node(knode, 'Render') render.start_render(current_render_node, render_mode, [start_frame, end_frame])
def GetNodeReference(node, key, raiseOnError=True): p = node.getParameter(key) if not p: if raiseOnError: raise RuntimeError('internal network corrupt: %s', key) return now = NodegraphAPI.GetCurrentTime() node = NodegraphAPI.GetNode(p.getValue(now)) if not node and raiseOnError: raise RuntimeError('internal network corrupt: %s', key) return node
def displayModel(self,node=NodegraphAPI.GetRootNode(), nameInNode='_hiShape'): allPath =[] nameInNode = self.namelineEdit.text() node = NodegraphAPI.GetNode( 'root' ) sg = ScenegraphManager.getActiveScenegraph() time = NodegraphAPI.GetCurrentTime() producer = Nodes3DAPI.GetGeometryProducer(node, time) splitText = str(self.pathLineEdit.text()).split(' ') if len(splitText) > 0 and splitText[0] != '' : for prodpath in splitText: producer =producer.getProducerByPath(prodpath) a = self.recursiveFindPath(producer, allPath, nameInNode=nameInNode) producer = Nodes3DAPI.GetGeometryProducer(node, time) else: allPath = self.recursiveFindPath(producer, listPath=[], nameInNode=nameInNode) for item in allPath: sg.addPinnedLocation(item)
def RenameRenderPass(renderPass, newName): now = NodegraphAPI.GetCurrentTime() smNode = renderPass.getParent() oldName = renderPass.getName() # Return early if the name was not changed if oldName == newName: return oldName # Make sure new name is unique newName = GetUniquePassName(smNode, newName) # Update parameter renderPass.getGroupNode().setName(newName) # Update group name renderPass.getGroupNode().getParameter('passName').setValue(newName, now) # Rebuild outputs of Shadow Manager node BuildOutputs(smNode) return newName
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()
def AddLightPassBranch(smNode, renderPassItem, lightPath): now = NodegraphAPI.GetCurrentTime() # Get node references #depNode = GetNodeReference(smNode, 'depMergeNode') sharedDepDotNode = GetNodeReference(smNode, 'sharedDepDotNode') passGroup = renderPassItem.getGroupNode() ## LIGHT PASS lightName = lightPath.split('/')[-1] # Create container group for a light of a pass lightPassGroup = NodegraphAPI.CreateNode('Group', passGroup) lightPassGroup.addInputPort('in') lightPassGroup.addOutputPort('out') lightPassGroup.setName(lightName) lightPassGroup.setType('ShadowManagerLightPassPackage') # Add user parameters to pass group node passParamGrp = passGroup.getParameter('lightPasses') lightPassParam = passParamGrp.createChildGroup('lightPass') lightPassParamName = lightPassParam.getName() lightPassParam.createChildString('lightPath', lightPath) renderLocParam = lightPassParam.createChildString('renderLocation', '') location = "path.join(getenv('KATANA_TMPDIR', '.'), " \ "passName + '_%s.#.tx')" % lightName renderLocParam.setExpression(location) ########################################################################### # Create RenderSettings node renderSettingsNode = NodegraphAPI.CreateNode('RenderSettings', lightPassGroup) expr = 'getParent().getParent().lightPasses.' + lightPassParamName + '.lightPath' camStr = 'args.renderSettings.cameraName' renderSettingsNode.getParameter(camStr + '.value').setExpression(expr) renderSettingsNode.getParameter(camStr + '.enable').setValue(1, now) ########################################################################### # Create RenderOutputDefine node outputStr = 'args.renderSettings.outputs.outputName' outputDefNode = NodegraphAPI.CreateNode('RenderOutputDefine', lightPassGroup) ########################################################################### # Enable shadowType outputDefNode.getParameter(outputStr + '.type.value').setValue( 'shadow', now) outputDefNode.getParameter(outputStr + '.type.enable').setValue(1, now) # Set location type to file locTypeStr = outputStr + '.locationType' outputDefNode.getParameter(locTypeStr + '.value').setValue('file', now) outputDefNode.getParameter(locTypeStr + '.enable').setValue(1, now) # After setting the locationType, we need to check for dynamic parameters, # in this case locationSettings.renderLocation. outputDefNode.checkDynamicParameters() # Enable render location renderLocStr = outputStr + '.locationSettings.renderLocation' outputDefNode.getParameter(renderLocStr + '.enable').setValue(1, now) # Set render location as expression from pass group parameter exprRenderLoc = 'getParent().getParent().lightPasses.' \ + lightPassParamName + '.renderLocation' outputDefNode.getParameter(renderLocStr + '.value').setExpression(exprRenderLoc) ########################################################################### # Create render node renderNode = NodegraphAPI.CreateNode('Render', lightPassGroup) passName = "shadow_render_" + renderPassItem.getName() + "_" + lightName renderNode.getParameter('passName').setValue(passName, 0) renderNode.addInputPort('sharedDeps').connect( sharedDepDotNode.getOutputPortByIndex(0)) renderNode.addOutputPort('primary').connect( lightPassGroup.getReturnPort( lightPassGroup.getOutputPortByIndex(0).getName())) lightPassGroup.getOutputPortByIndex(0).connect( renderPassItem.getDepMergeNode().addInputPort('i0')) ########################################################################### # Create Material node groupStackNode = renderPassItem.getGroupStackNode() materialNode = NodegraphAPI.CreateNode('Material', groupStackNode) materialNode.getParameter('action').setValue('override materials', 0) exprLightPath = 'getParent().getParent().lightPasses.' \ + lightPassParamName + '.lightPath' materialNode.getParameter('overrides.CEL').setExpression(exprLightPath, 0) materialNode.getParameter('overrides.CEL').setExpressionFlag(True) attrs = materialNode.getParameter('overrides.attrs') attrPath = 'prmanLightParams.Shadow_File' matOverride = attrs.createChildGroup('materialOverride') shadowFileGroup = matOverride.createChildGroup(attrPath) shadowFileGroup.createChildString('type', 'StringAttr') shadowFileGroup.createChildString('__path', attrPath) shadowFileGroup.createChildNumber('enable', 1) exprParam = shadowFileGroup.createChildString('value', '') exprParam.setExpression(exprRenderLoc) WireInlineNodes(groupStackNode, groupStackNode.getChildren()) ########################################################################### # Link nodes internally internalNodes = [renderSettingsNode, outputDefNode, renderNode] WireInlineNodes(None, internalNodes) ########################################################################### # Link first nodes with group input renderSettingsNode.getInputPortByIndex(0).connect( lightPassGroup.getSendPort( lightPassGroup.getInputPortByIndex(0).getName())) nodeList = [lightPassGroup] return nodeList
def AddRenderPass(smNode, passName): now = NodegraphAPI.GetCurrentTime() # Create unique pass name and add name to main ShadowManager node class passName = GetUniquePassName(smNode, passName) smNode.getRenderPassNames().append(passName) # Get node references mergeNode = GetNodeReference(smNode, 'mergeNode') mergeDot = GetNodeReference(smNode, 'mergeDot') # Add input and output to merge dot iport = mergeDot.addInputPort('in1') oport = mergeDot.addOutputPort('out1') iport.connect(mergeNode.getOutputPortByIndex(0)) # Create container group for a pass passGroup = NodegraphAPI.CreateNode('Group', smNode) passGroup.addInputPort('in') passGroup.setName(passName) passGroup.setType('ShadowManagerPassPackage') passGroup.getParameters().createChildString('passName', passName) passParamGrp = passGroup.getParameters().createChildGroup('lightPasses') # Connect group to dot after merge passGroup.getInputPortByIndex(0).connect( mergeDot.getOutputPortByIndex(oport.getIndex())) ########################################################################### # Create Group Stack node assigning correct shadow file to light pass groupStackNode = NodegraphAPI.CreateNode('GroupStack', passGroup) NodegraphAPI.SetNodePosition(groupStackNode, (-450, -100)) # Connect group stack node to group groupStackNode.getInputPortByIndex(0).connect( passGroup.getSendPort(passGroup.getInputPortByIndex(0).getName())) newPort = passGroup.addOutputPort("outGroupStack") groupStackNode.getOutputPortByIndex(0).connect( passGroup.getReturnPort(passGroup.getOutputPortByIndex(0).getName())) ########################################################################### depMergeNode = NodegraphAPI.CreateNode('DependencyMerge', passGroup) NodegraphAPI.SetNodePosition(depMergeNode, (-150, -200)) # Link with pass group passGroup.addOutputPort("outDeps") depMergeNode.getOutputPortByIndex(0).connect( passGroup.getReturnPort(passGroup.getOutputPortByIndex(1).getName())) ########################################################################### # Create ShadowBranch node shadowBranchNode = NodegraphAPI.CreateNode('ShadowBranch', passGroup) NodegraphAPI.SetNodePosition(shadowBranchNode, (-150, 0)) # Connect shadow branch node to group shadowBranchNode.getInputPortByIndex(0).connect( passGroup.getSendPort(passGroup.getInputPortByIndex(0).getName())) # Position nodes and rebuild outputs PositionNodes(smNode) BuildOutputs(smNode) scriptItem = smNode.RenderPassScriptItem(passGroup) return scriptItem
def createKatanaNodes(fileOut = '/tmp/fileDispFromLua.txt'): # check if there is a node ('Attribute_Disp') existing if yes delete it # existingNode = NodegraphAPI.GetNode('Attribute_Disp') # if existingNode : # inputNodePort = existingNode.getInputPortByIndex(0) # outputNodePort = existingNode.getOutputPortByIndex(0) # inputNodePort.connect(outputNodePort) # existingNode.delete() inputFile = open(fileOut,'a') node = NodegraphAPI.GetAllSelectedNodes()[0] # select the node nodePos = NodegraphAPI.GetNodePosition(node) # get the position of node nodeOutPort = node.getOutputPortByIndex(0) # get the output port nextPort = nodeOutPort.getConnectedPorts()[0] # get the first connected port from the previous node # create the opscript node root = NodegraphAPI.GetRootNode() opscriptFindDisp = NodegraphAPI.CreateNode('OpScript',root) opscriptFindDisp.setName('findDisp') opscriptFindDisp.getParameter('CEL').setValue('/root/world//*{hasattr("materialOverride.parameters.dsp_map")}',0) opscriptFindDispUserParam = opscriptFindDisp.getParameters().createChildGroup('user') opscriptFindDispUserParamFileOut = opscriptFindDispUserParam.createChildString('fileOut',fileOut) opscriptFindDisp.getParameter('script.lua').setValue("local getdispMap = require 'dispFunc'\ngetdispMap.getDispMap()",0) opscriptFindDispInPort = opscriptFindDisp.getInputPort('i0') opscriptFindDispOutPort = opscriptFindDisp.getOutputPort('out') nodeOutPort.connect(opscriptFindDispInPort) opscriptFindDispOutPort.connect(nextPort) NodegraphAPI.SetNodePosition(opscriptFindDisp, (nodePos[0]+50,nodePos[1]-50)) opscriptFindDispPos = NodegraphAPI.GetNodePosition(opscriptFindDisp) # set the view and the edit on the opscript node NodegraphAPI.SetNodeViewed(opscriptFindDisp, True, exclusive=True) NodegraphAPI.SetNodeEdited(opscriptFindDisp, True, exclusive=True) # dummy functions to run the opscript and create the file sg = ScenegraphManager.getActiveScenegraph() node = NodegraphAPI.GetNode( 'root' ) time = NodegraphAPI.GetCurrentTime() producer = Nodes3DAPI.GetGeometryProducer( node, time) prod = producer.getProducerByPath('/root') WalkBoundAttrLocations(prod) # extract the dip for each map assetWithDisp = findDispHeight(fileOut) # create a stack of AttributeSet to set the disp if there is element in the dict if len(assetWithDisp.keys()): stack = NodegraphAPI.CreateNode("GroupStack", NodegraphAPI.GetRootNode()) stack.setName('Attribute_Disp') stack.setChildNodeType("AttributeSet") listWord = ['/location/','/prop/','/location/','/character/'] for key in assetWithDisp.keys(): path = '' attributSet = stack.buildChildNode() attributSet.getParameter('mode').setValue('CEL',0) attrPath = attributSet.getParameter('celSelection') attributSet.getParameter('attributeType').setValue('float',0) # replace the word from listWord by the wildcard '/*' so to work in lighting scene for word in listWord: if key.find(word) > 1: path = key.replace(word,'//*/') attrPath.setValue(path,0) break else: attrPath.setValue(key,0) attributSet.setName(key[key.rfind('/')+1:]) # set name to the _hi attrValue = attributSet.getParameter('numberValue.i0') attrValue.setValue(assetWithDisp[key],0) attrName = attributSet.getParameter('attributeName') attrName.setValue('arnoldStatements.disp_padding',0) NodegraphAPI.SetNodePosition(stack,opscriptFindDispPos) stackInPort = stack.getInputPort('in') stackOutPort = stack.getOutputPort('out') nodeOutPort.connect(stackInPort) stackOutPort.connect(nextPort) NodegraphAPI.SetNodeViewed(stack, True, exclusive=True) NodegraphAPI.SetNodeEdited(stack, True, exclusive=True) else: # reconnect the nodes nodeOutPort.connect(nextPort) NodegraphAPI.SetNodeViewed(node, True, exclusive=True) NodegraphAPI.SetNodeEdited(node, True, exclusive=True) # delete the opscript and the file opscriptFindDisp.delete() os.remove(fileOut) print 'finished'