示例#1
0
    def importKlf(self):
        pos = NodegraphAPI.GetViewPortPosition(NodegraphAPI.GetRootNode())
        currentItemName = str(self.listWidget.currentItem().text())
        checkCat = str(self.catedoryCB.currentText())

        if not checkCat == 'ALL':
            klfName = os.path.join(self.directory, checkCat,
                                   currentItemName + '.klf')
            expression = 'path.join(getenv("MATLIB",0), "material_library", "{}", "{}")'.format(
                checkCat, currentItemName + '.klf')
        else:
            klfName = os.path.join(
                str(self.listWidget.currentItem().data(
                    QtCore.Qt.UserRole).toPyObject()),
                currentItemName + '.klf')
            expression= 'path.join(getenv("MATLIB",0), "material_library", "{}", "{}")'\
                .format(str(self.listWidget.currentItem().data(QtCore.Qt.UserRole).toPyObject()).split(os.sep)[-1], currentItemName+'.klf')

        if os.path.exists(klfName):
            lfm = NodegraphAPI.CreateNode('LookFileMaterialsIn',
                                          NodegraphAPI.GetRootNode())
            lfm.setName('LFMI_' + currentItemName)
            DrawingModule.SetCustomNodeColor(lfm, 0.4, 0, 0.15)
            lfm.getParameter('lookfile').setExpression(expression)
            NodegraphAPI.SetNodePosition(lfm, ((pos[0][0]), pos[0][1]))
        else:
            QtGui.QMessageBox.information(
                None, currentItemName,
                'There is no Look File for {}, try importing Material!'.format(
                    currentItemName))
    def setUpClass(cls):
        '''Procedurally create nodes for testing.'''

        # Add a PxrUsdIn node and set its motion sample times
        pxrUsdInNode = NodegraphAPI.CreateNode('PxrUsdIn',
                                               NodegraphAPI.GetRootNode())
        pxrUsdInNode.getParameter('motionSampleTimes').setValue('0 -1', 0)

        # Add a RenderSettings node and turn on motion blur
        renderSettingsNode = NodegraphAPI.CreateNode(
            'RenderSettings', NodegraphAPI.GetRootNode())
        mts = renderSettingsNode.getParameter(
            'args.renderSettings.maxTimeSamples')
        mts.getChild('value').setValue(2, 0)
        mts.getChild('enable').setValue(1, 0)
        sc = renderSettingsNode.getParameter(
            'args.renderSettings.shutterClose')
        sc.getChild('value').setValue(0.5, 0)
        sc.getChild('enable').setValue(1, 0)

        # Connect the two nodes together and view from the RS node
        pxrUsdInNode.getOutputPortByIndex(0).connect(
            renderSettingsNode.getInputPortByIndex(0))
        NodegraphAPI.SetNodeViewed(renderSettingsNode, True, True)

        # Set the current frame
        NodegraphAPI.SetCurrentTime(50)
    def createRestParts(self, InData):
        root = (InData[2][0] - 100, InData[2][1] - 100)
        mergeNode = NodegraphAPI.CreateNode('Merge',
                                            NodegraphAPI.GetRootNode())
        NodegraphAPI.SetNodePosition(mergeNode, root)
        mergeNode.addInputPort('i%d' % 0)
        mergeNode.addInputPort('i%d' % 1)
        mergeNode.getInputPort("i0").connect(InData[0].getOutputPort("out"))
        mergeNode.getInputPort("i1").connect(InData[1].getOutputPort("out"))

        upstreamDot = NodegraphAPI.CreateNode('Dot',
                                              NodegraphAPI.GetRootNode())
        downstreamDot = NodegraphAPI.CreateNode('Dot',
                                                NodegraphAPI.GetRootNode())
        NodegraphAPI.SetNodePosition(downstreamDot, (root[0] - 400, root[1]))
        NodegraphAPI.SetNodePosition(upstreamDot,
                                     (root[0] - 400, root[1] + 200))
        downstreamDot.getInputPort("input").connect(
            upstreamDot.getOutputPort("output"))
        origNode = InData[3]
        upstreamDot.getInputPort("input").connect(
            origNode.getOutputPort("out"))

        LookFileBakeNode = NodegraphAPI.CreateNode('LookFileBake',
                                                   NodegraphAPI.GetRootNode())
        NodegraphAPI.SetNodePosition(LookFileBakeNode,
                                     (root[0] - 200, root[1] - 100))
        LookFileBakeNode.getInputPort("orig").connect(
            downstreamDot.getOutputPort("output"))
        LookFileBakeNode.getInputPort("default").connect(
            mergeNode.getOutputPort("out"))
示例#4
0
    def build(self):
        informationTuple = self.depthDigger()
        materialNodeMap = informationTuple[0]
        levelNodeMap = informationTuple[1]
        nodeDataMap = informationTuple[2]

        nodeMergeList = []
        """Reset node position"""
        i = 0
        for materialNodes in materialNodeMap:
            i += 1
            offsetX = (i-1)*500
            #~ Create a group to hold some nodes in single material
            groupNode = NodegraphAPI.CreateNode('Group', NodegraphAPI.GetRootNode())
            groupName = "%s_%s"%(materialNodes,self.suffixGroup)
            groupNode.setName(groupName)
            NodegraphAPI.SetNodePosition(groupNode, (0 + offsetX, 0))
            #~ Create a Network Material Node
            networkMaterialNode = NodegraphAPI.CreateNode('NetworkMaterial', NodegraphAPI.GetRootNode())
            NodegraphAPI.SetNodePosition(networkMaterialNode, (0 + offsetX, -250))
            materialName = "%s_%s"%(materialNodes,self.suffixNetworkMaterial)
            networkMaterialNode.getParameter('name').setValue(str(materialName), 0)
            networkMaterialNode.addInputPort('arnoldSurface')
            networkMaterialNode.addInputPort('arnoldBump')
            nodeMergeList.append(networkMaterialNode)
            tempLevelCount = {}
            for node in materialNodeMap[materialNodes]:
                for level in levelNodeMap:
                    if node in levelNodeMap[level]:
                        if tempLevelCount.has_key(level):
                            tempLevelCount[level] += 1
                        else:
                            tempLevelCount[level] = 1
            for node in materialNodeMap[materialNodes]:
                thisLevel = 1
                for level in levelNodeMap:
                    if node in levelNodeMap[level]:
                        thisLevel = level
                offsetY = (thisLevel - 1)*100
                name = str(node)
                offset = (offsetX,offsetY)
                type = str(nodeDataMap[name][0])
                paraList = nodeDataMap[name][1]
                """Create"""
                activeNode = self.createNodes(name,offset,type,paraList)
                activeNode.setParent(groupNode)
        upstreamMergeNode = self.createMergeNodes(nodeMergeList, NodegraphAPI.GetRootNode())
        NodegraphAPI.SetNodePosition(upstreamMergeNode,((len(nodeMergeList)/2)*500, -600))
        upstreamMergeNode.setName("MaterialsMerge")
        dowmstreamMergeNode = NodegraphAPI.CreateNode('Merge',NodegraphAPI.GetRootNode())
        dowmstreamMergeNode.addInputPort('i%d' % 0)
        dowmstreamMergeNode.getInputPort("i0").connect(upstreamMergeNode.getOutputPort("out"))
        NodegraphAPI.SetNodePosition(dowmstreamMergeNode,((len(nodeMergeList)/2)*500, -1000))
        dowmstreamMergeNode.setName("MergePass")
        self.pos = ((len(nodeMergeList)/2)*500, -1000)
        """Connect"""
        self.connectNodes()
        Result = dowmstreamMergeNode
        return Result
    def createAlembicNode(self):
        AlembicData = self.AlembicData
        MaterialData = self.MaterialData
        # Create Node
        modelName = "Model_In"
        nodeList = []
        standardNode = NodegraphAPI.CreateNode('Alembic_In',
                                               NodegraphAPI.GetRootNode())
        #standardNode.getParameter('name').setValue("/root/world/geo/%s"%modelName, 0)
        #standardNode.setName(modelName)
        standardNode.getParameter('abcAsset').setValue(
            "C:/Users/mili/Desktop/c_NGJL_mod.abc", 0)
        NodegraphAPI.SetNodePosition(standardNode, (0, 0))
        nodeList.append(standardNode)

        pruneNode = NodegraphAPI.CreateNode('Prune',
                                            NodegraphAPI.GetRootNode())
        NodegraphAPI.SetNodePosition(standardNode, (0, 50))
        pruneNode.getInputPort('A').connect(standardNode.getOutputPort('out'))
        nodeList.append(pruneNode)

        facesetGroupNode = NodegraphAPI.CreateNode('GroupStack',
                                                   NodegraphAPI.GetRootNode())
        facesetGroupNode.setName("FaceSetGroup")
        facesetGroupNode.setChildNodeType('FaceSetCreate')
        facesetGroupNode.getInputPort('in').connect(
            pruneNode.getOutputPort('out'))
        NodegraphAPI.SetNodePosition(facesetGroupNode, (0, -50))
        nodeList.append(facesetGroupNode)

        materialassignGroupNode = NodegraphAPI.CreateNode(
            'GroupStack', NodegraphAPI.GetRootNode())
        materialassignGroupNode.setName("MaterialAssignGroup")
        materialassignGroupNode.setChildNodeType('MaterialAssign')
        materialassignGroupNode.getInputPort('in').connect(
            facesetGroupNode.getOutputPort('out'))
        NodegraphAPI.SetNodePosition(materialassignGroupNode, (0, -100))
        nodeList.append(materialassignGroupNode)

        nodegraphTab = UI4.App.Tabs.FindTopTab('Node Graph')

        for data in AlembicData:
            self.createFaceSet(facesetGroupNode, data)
        for material in MaterialData:
            data = (material, MaterialData[material])
            self.createMatrialAssign(materialassignGroupNode, data)
        pruneNode = NodegraphAPI.GetNode("Prune")
        pruneList = [
            '/root/world/geo/%s/front' % modelName,
            '/root/world/geo/%s/persp' % modelName,
            '/root/world/geo/%s/side' % modelName,
            '/root/world/geo/%s/top' % modelName,
        ]
        pruneNode.getParameter('cel').setValue('(' + ' '.join(pruneList) + ')',
                                               0)

        if nodegraphTab:
            nodegraphTab.floatNodes(nodeList)
示例#6
0
    def importLmtl(self):
        pos = NodegraphAPI.GetViewPortPosition(NodegraphAPI.GetRootNode())
        currentItemName = str(self.listWidget.currentItem().text())
        checkCat = str(self.catedoryCB.currentText())

        if not checkCat == 'ALL':
            klfName = os.path.join(self.directory, checkCat,
                                   currentItemName + '.klf')
            expression = 'path.join(getenv("MATLIB",0), "material_library", "{}", "{}")'.format(
                checkCat, currentItemName + '.klf')
        else:
            klfName = os.path.join(
                str(self.listWidget.currentItem().data(
                    QtCore.Qt.UserRole).toPyObject()),
                currentItemName + '.klf')
            expression= 'path.join(getenv("MATLIB",0), "material_library", "{}", "{}")'\
                .format(str(self.listWidget.currentItem().data(QtCore.Qt.UserRole).toPyObject()).split(os.sep)[-1], currentItemName+'.klf')

        if os.path.exists(klfName):
            materialNode = NodegraphAPI.CreateNode('Material',
                                                   NodegraphAPI.GetRootNode())
            materialNode.getParameter('name').setValue(currentItemName, 0)
            DrawingModule.SetCustomNodeColor(materialNode, 0.2, 0.27, 0.4)
            materialNode.getParameter('action').setValue(
                'create from Look File', 0)
            materialNode.getParameter('lookfile.lookfile').setExpression(
                expression)
            NodegraphAPI.SetNodePosition(materialNode,
                                         ((pos[0][0]), pos[0][1]))

            materialAssign = NodegraphAPI.CreateNode(
                'MaterialAssign', NodegraphAPI.GetRootNode())
            materialAssign.setName('MA_' + currentItemName)
            materialAssign.getParameter(
                'args.materialAssign.value').setExpression(
                    "scenegraphLocationFromNode(getNode('{}'))".format(
                        materialNode.getName()))
            DrawingModule.SetCustomNodeColor(materialAssign, 0.2, 0.27, 0.4)
            NodegraphAPI.SetNodePosition(materialAssign,
                                         ((pos[0][0]), pos[0][1] - 50))
            materialNode.getOutputPort('out').connect(
                materialAssign.getInputPort('input'))
            NodegraphAPI.SetNodeEdited(materialAssign,
                                       edited=True,
                                       exclusive=True)

        else:
            QtGui.QMessageBox.information(
                None, currentItemName,
                'There in no Look File for {}, try importing Material!'.format(
                    currentItemName))
示例#7
0
def ActionCallback(value):
    """
    Callback for the layered menu, which creates a PrmanShadingNode node and
    sets its B{nodeType} parameter to the given C{value}, which is the name of
    a PRMan shader as set for the menu entry in L{IkaPopulateCallback()}.

    @type value: C{str}
    @rtype: C{object}
    @param value: An arbitrary object that the menu entry that was chosen
        represents. In our case here, this is the name of a PRMan shader as
        passed to the L{LayeredMenuAPI.LayeredMenu.addEntry()} function in
        L{IkaPopulateCallback()}.
    @return: An arbitrary object. In our case here, we return the created
        PrmanShadingNode node, which is then placed in the B{Node Graph} tab
        because it is a L{NodegraphAPI.Node} instance.
    """

    # Remove ris/ or osl/ prefix from the node name.
    if (value.find('ris/') == 0 or value.find('osl/') == 0):
        name = value[4:]
    else:
        name = value

    # Create a node containing the chosen type.
    if (name.find('integrator') == 0):
        node = NodegraphAPI.CreateNode('PrmanIntegratorSettings',
                                       NodegraphAPI.GetRootNode())

    else:
        node = NodegraphAPI.CreateNode('PrmanShadingNode',
                                       NodegraphAPI.GetRootNode())
        node.getParameter('nodeType').setValue(value, 0)

    # Set the node's name.
    node.setName(name)
    node.getParameter('name').setValue(node.getName(), 0)

    # Set the node's color based on its shader category.
    for category in colorDict:
        if (category in name):
            color = colorDict[category]
            DrawingModule.SetCustomNodeColor(node, color[0], color[1],
                                             color[2])
            break

    # Update the Node Graph.
    for tab in UI4.App.Tabs.GetTabsByType('Node Graph'):
        tab.update()

    return node
示例#8
0
    def build(self,InPos):
        offsetX = InPos[0] - 200
        offsetY = InPos[1]
        AlembicData = self.AlembicData
        MaterialData = self.MaterialData
        #~ Create Node
        modelName = "asset"
        nodeList = []
        self.standardNode = NodegraphAPI.CreateNode('Alembic_In', NodegraphAPI.GetRootNode())
        self.standardNode.getParameter('name').setValue("/root/world/geo/%s"%modelName, 0)
        self.standardNode.setName("Asset")
        self.standardNode.getParameter('abcAsset').setValue("C:/Users/mili/Desktop/c_NGJL_mod.abc", 0)
        NodegraphAPI.SetNodePosition(self.standardNode, (0+offsetX, 150+offsetY))
        nodeList.append(self.standardNode)

        pruneNode = NodegraphAPI.CreateNode('Prune', NodegraphAPI.GetRootNode())
        NodegraphAPI.SetNodePosition(pruneNode, (0+offsetX, 100+offsetY))
        pruneNode.getInputPort('A').connect(self.standardNode.getOutputPort('out'))
        nodeList.append(pruneNode)
        pruneList = [
            '/root/world/geo/%s/front'%modelName,
            '/root/world/geo/%s/persp'%modelName,
            '/root/world/geo/%s/side'%modelName,
            '/root/world/geo/%s/top'%modelName,
        ]
        pruneNode.getParameter('cel').setValue('(' + ' '.join(pruneList) + ')', 0)

        facesetGroupNode = NodegraphAPI.CreateNode('GroupStack', NodegraphAPI.GetRootNode())
        facesetGroupNode.setName("FaceSetGroup")
        facesetGroupNode.setChildNodeType('FaceSetCreate')
        facesetGroupNode.getInputPort('in').connect(pruneNode.getOutputPort('out'))
        NodegraphAPI.SetNodePosition(facesetGroupNode, (0+offsetX, 50+offsetY))
        nodeList.append(facesetGroupNode)

        materialassignGroupNode = NodegraphAPI.CreateNode('GroupStack', NodegraphAPI.GetRootNode())
        materialassignGroupNode.setName("MaterialAssignGroup")
        materialassignGroupNode.setChildNodeType('MaterialAssign')
        materialassignGroupNode.getInputPort('in').connect(facesetGroupNode.getOutputPort('out'))
        NodegraphAPI.SetNodePosition(materialassignGroupNode, (0+offsetX, offsetY))
        nodeList.append(materialassignGroupNode)

        for data in AlembicData:
            self.createFaceSet(facesetGroupNode,data)
        for material in MaterialData:
            data = (material,MaterialData[material])
            self.createMatrialAssign(materialassignGroupNode,data)
        Result = materialassignGroupNode
        return Result
示例#9
0
def create_global_variable(label, values, force=False):
    '''
    :description create global variables on root node
    :param label <str>
    :param values <list>
    :param force <bool>    
    :example
        from core import scene
        label = 'camera'
        values = ['alembic1', 'default1', 'default2', 'default3']
        scene.create_global_variable(label, values, force=True)
    '''
    roo_node = NodegraphAPI.GetRootNode()
    variable_parameter = roo_node.getParameter('variables')
    exists_variables = []
    for child in variable_parameter.getChildren():
        exists_variables.append(child.getName())
    if label in exists_variables and not force:
        print '#warnings: already exists the global variable', label
        return
    if label in exists_variables:
        exists_variable = variable_parameter.getChild(label)
        variable_parameter.deleteChild(exists_variable)
    child_group = variable_parameter.createChildGroup(label)
    child_group.createChildNumber('enable', 1)
    children = child_group.createChildStringArray('options', len(values), 1)
    for index, child in enumerate(children.getChildren()):
        child_group.createChildString('value', values[index])
        child.setValue(values[index], 1)
    return True
示例#10
0
def create_node():    
    template_path = resources.get_template_path()    
    latest_version = versions.get_latest_version(template_path, 'lighting')
    if not latest_version:
        message = 'not found any publish versions'
        QtGui.QMessageBox.warning(
            None, 'Warning', message, QtGui.QMessageBox.Ok)
        return            
    xml_scene = os.path.join(
        template_path, 'lighting', latest_version, 'lighting.xml')     
    if not os.path.isfile(xml_scene):
        message = 'not found xml in the latest publish \n<%s>\n<%s>' % (
            latest_version, xml_scene)
        QtGui.QMessageBox.warning(
            None, 'Warning', message, QtGui.QMessageBox.Ok)
        return     
    scene.new_katana_scene()    
    root_node = NodegraphAPI.GetRootNode()
    knodes = scene.xml_file_to_nodes(xml_scene, parent=root_node)
    print '# info: lighting template nodes'
    for knode in knodes:
        print '\t', knode.getName()
    message = [
        'template type: '.rjust(15) + 'lighting',
        'version: '.rjust(15) + latest_version,
        'path: '.rjust(15) + xml_scene
        ]
    QtGui.QMessageBox.information(
            None, 'success', '\n'.join(message), QtGui.QMessageBox.Ok)
    print '\n'.join(message)
示例#11
0
def addSampleBlock(root = NodegraphAPI.GetRootNode(),name = 'sample',task='Object'):
    children = root.getChildren()
    nbChildren = root.getNumChildren()
    dotNode = None
    for child in children:
        if child.getType() == 'Dot':
            dotNode = child
    dotNodePos = NodegraphAPI.GetNodePosition(dotNode)

    newSampleNode = createOpScriptSample(root,name,task)
    paramUI(root,name,task)

    #reorder the button to be the last param
    newSampleParam = root.getParameters()
    paramAddBlocker = newSampleParam.getChild('addSampleNode')
    numberOfChild = newSampleParam.getNumChildren() -1
    newSampleParam.reorderChild(paramAddBlocker,numberOfChild)

    if nbChildren == 1:
        sendGroup = root.getSendPort('in')
        newSampleNode.getInputPort('i0').connect(sendGroup)
        newSampleNode.getOutputPort('out').connect(dotNode.getInputPort('input'))
        NodegraphAPI.SetNodePosition(dotNode,(dotNodePos[0],dotNodePos[1]-50))
    else:
        inputDotNodeProducer = dotNode.getInputSource('input',NodegraphAPI.GetCurrentGraphState())[0]
        inputDotNodeProducer.connect(newSampleNode.getInputPort('i0'))
        newSampleNode.getOutputPort('out').connect(dotNode.getInputPort('input'))
        NodegraphAPI.SetNodePosition(newSampleNode,dotNodePos)
        NodegraphAPI.SetNodePosition(dotNode,(dotNodePos[0],dotNodePos[1]-50))
示例#12
0
def deleteBlocker(blockerName='Blocker1', root=NodegraphAPI.GetRootNode()):
    #get the node to delete
    blockerToDelete = NodegraphAPI.GetNode(blockerName)
    #get the position of the node
    blockerToDeletePos = NodegraphAPI.GetNodePosition(blockerToDelete)

    #get the connected node ports to the blocker to delete and reconnect those ports together
    outPort = blockerToDelete.getInputPort('in').getConnectedPort(0)
    inPort = blockerToDelete.getOutputPort('out').getConnectedPort(0)
    outPort.connect(inPort)

    #delete the blocker node
    blockerToDelete.delete()

    #delete the param of the blocker
    paramToDelete = root.getParameter(blockerName)
    param = root.getParameters()
    param.deleteChild(paramToDelete)

    #reposition the node inside the blockerGroup
    nodeType = 'Group'
    portToFind = inPort
    nodeToMove = portToFind.getNode()
    pos = blockerToDeletePos
    while (nodeType != 'Dot'):
        oldPos = NodegraphAPI.GetNodePosition(nodeToMove)
        nodeType = nodeToMove.getType()
        NodegraphAPI.SetNodePosition(nodeToMove, pos)
        if nodeType != 'Dot':
            portToFind = nodeToMove.getOutputPort('out').getConnectedPort(0)
            nodeToMove = portToFind.getNode()
            pos = oldPos
示例#13
0
def create_custom_global_variable(label, values, force=False):
    '''
    :description create custom global variables on root node
    :param label <str>
    :param values <list>
    :param force <bool>    
    :example
        from core import scene
        label = 'camera'
        values = ['alembic1', 'default1', 'default2', 'default3']
        scene.create_custom_global_variable(label, values, force=True)
    '''
    roo_node = NodegraphAPI.GetRootNode()
    variable_parameter = roo_node.getParameter('variables')
    exists_variables = []
    for child in variable_parameter.getChildren():
        exists_variables.append(child.getName())
    if label in exists_variables and not force:
        print '#warnings: already exists the global variable', label
        return
    if label in exists_variables:
        exists_variable = variable_parameter.getChild(label)
        variable_parameter.deleteChild(exists_variable)
    variable = variable_parameter.createChildString(label, label)
    hint = {'widget': 'popup', 'options': values}
    variable.setHintString(str(hint))
    variable.setValue(values[0], 1.0)
示例#14
0
def paramUI(groupNode = NodegraphAPI.GetRootNode(), name ='sample',task='Object'):
    groupParam = groupNode.getParameters().createChildGroup(name)
    groupParam.setHintString("{'open': 'True', 'help':' Sample tunning'}")
    #cel param
    celParam = groupParam.createChildString('CEL','')
    celParam.setHintString("{'widget': 'cel'}")
    #bypass sample set
    disableParam = groupParam.createChildNumber('disable',0)
    disableParam.setHintString("{'widget': 'checkBox', 'help': 'enable or disable the sample set'}")
    #create different type of param in function of type of component
    if task == 'Object':
        sampleDict = { '1':['diffuse','diffuse_samples'],'2':['sss','sss_samples'],'3':['backLight','backlighting_samples'],'4':['glossy1','glossy1_samples'],'5':['glossy2','glossy2_samples'],'6':['transmission','transmission_samples']}
        #Sample param
        for pos in sorted(sampleDict.keys()):
            sampleCheckBox = groupParam.createChildNumber(sampleDict[pos][0],0)
            sampleCheckBox.setHintString("{'widget': 'checkBox', 'conditionalLockOps': {'conditionalLockValue': '0', 'conditionalLockOp': 'notEqualTo', 'conditionalLockPath': '../"+sampleDict[pos][1]+"'},'help':'toggle the add_diffuse_sample'}")
            sampleSlider = groupParam.createChildNumber(sampleDict[pos][1],0)
            sampleSlider.setHintString("{'int': 'True', 'slider': 'True', 'slidermax': '10.0', 'conditionalVisOps': {'conditionalVisOp': 'equalTo', 'conditionalVisPath': '../"+sampleDict[pos][0]+"', 'conditionalVisValue': '1'}, 'slidermin': '-10.0', 'help':'add samples to the "+sampleDict[pos][0]+" component'}")
    elif task == 'Hair':
        sampleSlider = groupParam.createChildNumber('diffuse_samples',0)
        sampleSlider.setHintString("{'int': 'True', 'slider': 'True', 'slidermax': '10.0', 'slidermin': '-10.0', 'help':'add samples to the diffuse component for Hair'}")
    else:
        sampleSlider = groupParam.createChildNumber('samples',0)
        sampleSlider.setHintString("{'int': 'True', 'slider': 'True', 'slidermax': '10.0', 'slidermin': '0.0', 'help':'add samples to the Light'}")
    #param to add comment
    comment = groupParam.createChildString('comment','')
    comment.setHintString("{'widget': 'scriptEditor', 'help':'add comment and information for other user'}")
    #delete current sample block
    deleteButton = groupParam.createChildString('deleteSampleBlock','delete block')
    scriptDel = 'from sampleGroupCreate import deleteSampleBlock\\nblockName = "'+name+'"\\ndeleteSampleBlock(blockName, node)'
    deleteButton.setHintString("{'widget': 'scriptToolbar', 'buttonData': [{},{},{'text': 'delete', 'icon': '', 'scriptText': '"+scriptDel+"', 'flat': 0}], 'help': 'delete the current sampleBlock'}")
示例#15
0
def createOpScriptSample(groupNode = NodegraphAPI.GetRootNode(),name = 'sample',task='Object'):
    #expression root
    celExp = 'getParent().'+name
    #create the opscript for the samples
    opscriptSampleNode = NodegraphAPI.CreateNode('OpScript',groupNode)
    #set the expression for the CEL to be the one on parent node
    opscriptSampleNode.getParameter('CEL').setExpression(celExp+".CEL",True)
    #set the name of the opScript
    opscriptSampleNode.setName('Opscript_'+name)

    #param
    opscriptUserParam = opscriptSampleNode.getParameters().createChildGroup('user')
    if task == 'Object':
        opscriptSampleNode.getParameter('script.lua').setValue("local sample = require 'addSample'\nsample.Object()",0)
        listParam = ['diffuse_samples','sss_samples','backlighting_samples','glossy1_samples','glossy2_samples','transmission_samples']
        for param in listParam:
            paramCreated = opscriptUserParam.createChildNumber(param,0.0)
            paramCreated.setExpression(celExp+'.'+param,True)
    elif task == 'Hair':
        opscriptSampleNode.getParameter('script.lua').setValue("local sample = require 'addSample'\nsample.Hair()",0)
        paramCreated = opscriptUserParam.createChildNumber('diffuse_samples',0.0)
        paramCreated.setExpression(celExp+'.'+'diffuse_samples',True)
    else:
        opscriptSampleNode.getParameter('script.lua').setValue("local sample = require 'addSample'\nsample.Light()",0)
        paramCreated = opscriptUserParam.createChildNumber('samples',0.0)
        paramCreated.setExpression(celExp+'.'+'samples',True)

    #param to enable/disable node
    disableParam = opscriptSampleNode.getParameters().createChildNumber('disable',0)
    disableParam.setExpression(celExp+'.disable',True)
    return opscriptSampleNode
示例#16
0
def createOpScript(collection, opscript, cel, root="/root"):
    node = NodegraphAPI.CreateNode("OpScript", NodegraphAPI.GetRootNode())
    node.getParameter("CEL").setValue(cel, 0.0)
    node.getParameter("script.lua").setValue(opscript, 0.0)
    node.getParameters().createChildGroup("user")
    node.getParameter("user").createChildString("collection", collection)
    node.getParameter("user").createChildString("root", root)
    return node
示例#17
0
    def _import_project(path):
        """
        Import a katana project into the current session.

        :param path: The file path to import.
        :type path: str
        """
        root = NodegraphAPI.GetRootNode()
        return KatanaFile.Import(path, floatNodes=True, parentNode=root)
def create_merge(nodes, *args):
    mergeNode = NodegraphAPI.CreateNode('Merge', NodegraphAPI.GetRootNode())
    NodegraphAPI.SetNodePosition(mergeNode, (600, 0))
    id = 0
    for node in nodes:
        if not node:
            continue
        in_port = mergeNode.addInputPort('i%s' % id).connect(
            node.getOutputPort('out'))
        id += 1
示例#19
0
 def createNodes(self,InName,InOffset,InType,InParaList):
     #~ Create Node
     standardNode = NodegraphAPI.CreateNode('ArnoldShadingNode', NodegraphAPI.GetRootNode())
     standardNode.getParameter('name').setValue(InName, 0)
     NodegraphAPI.SetNodePosition(standardNode, (0+InOffset[0], 0+InOffset[1]))
     standardNode.getParameter('nodeType').setValue(InType, 0)
     standardNode.checkDynamicParameters()
     #~ Set Node Attribute
     self.setParameter(standardNode,InName,InParaList)
     return standardNode
示例#20
0
 def populateShots(self):
     root = NodegraphAPI.GetRootNode()
     node_list = []
     if root.getParameter('variables.shot'):
         # VEG --> LG --> GS 
         shots = root.getParameter('variables.shot.options')
         for child in shots.getChildren():
             group_node = self.createShotGroup(root_node=self.shot_lg,shot=child.getValue(0))
             node_list.append(group_node)
         self.connectInsideGroup(node_list,self.shot_lg)
示例#21
0
def AddGlobalGraphStateVariable(name, options):
    variablesGroup = NodegraphAPI.GetRootNode().getParameter('variables')
    variableParam = variablesGroup.createChildGroup(name)
    variableParam.createChildNumber('enable', 1)
    variableParam.createChildString('value', options[0])
    optionsParam = variableParam.createChildStringArray(
        'options', len(options))
    for optionParam, optionValue in zip(optionsParam.getChildren(), options):
        optionParam.setValue(optionValue, 0)
    return variableParam.getName()
示例#22
0
def get_scene_katana_nodes():
    '''
    :description get all node under the root node
    :example
        from core import nodegraph
        nodegraph.get_scene_katana_nodes()
    '''
    root_node = NodegraphAPI.GetRootNode()
    children = root_node.getChildren()
    return children
示例#23
0
 def createMatrialAssign(self,InGroupStackNode,InData):
     MaterialAssign = self.headMaterial + InData[0]
     alembicList = []
     for alembic in InData[1]:
         alembicName = self.headAlebic + alembic
         alembicList.append(alembicName)
     materialassignNode = NodegraphAPI.CreateNode('MaterialAssign', NodegraphAPI.GetRootNode())
     materialassignNode.getParameter('CEL').setValue("("+str(' '.join(alembicList))+")", 0)
     materialassignNode.getParameter('args.materialAssign.enable').setValue(1, 0)
     materialassignNode.getParameter("args.materialAssign.value").setValue(str(MaterialAssign), 0)
     InGroupStackNode.buildChildNode(materialassignNode)
示例#24
0
def create_viewer_settings(attribute_name):
    """
    Create viewer color settings.

    Creates a group stack with 1 group node per unique attribute_name
    value.
    This can used to find values of surfacing attributes as in
    attribute_name = "geometry.arbitrary.surfacing_object"
    attribute_name = "geometry.arbitrary.surfacing_project'

    Args:
        attribute_name (str): name of the attribute

    Returns:
        None

    """
    rootNode = NodegraphAPI.GetRootNode()
    material_stack = NodegraphAPI.CreateNode("GroupStack", rootNode)
    material_stack.setName("Surfacing_viewer_settings")
    selected_node = katana.get_selected_nodes(single=True)
    attribute_values = katana.get_objects_attribute_values(
        selected_node, attribute_name)
    position_y = 0

    for attribute_value in attribute_values:
        random_color = utils.get_random_color(attribute_value)
        viewer_settings = NodegraphAPI.CreateNode("ViewerObjectSettings",
                                                  rootNode)
        viewer_settings.setName("viewerColor_%s" % attribute_value)
        katana.add_node_to_group_last(material_stack,
                                      viewer_settings,
                                      inputPort="input")

        viewer_settings_value = viewer_settings.getParameter(
            "args.viewer.default.drawOptions.color")
        viewer_settings_value.getChild("value").getChild("i0").setValue(
            random_color[0], 0)
        viewer_settings_value.getChild("value").getChild("i1").setValue(
            random_color[1], 0)
        viewer_settings_value.getChild("value").getChild("i2").setValue(
            random_color[2], 0)
        viewer_settings_value.getChild("enable").setValue(True, 0)

        cel_statement = '/root/world//*{attr("%s.value") == "%s"}' % (
            attribute_name,
            attribute_value,
        )
        viewer_settings.getParameter("CEL").setValue(cel_statement, 0)

        NodegraphAPI.SetNodePosition(viewer_settings, (0, position_y))
        position_y = position_y - 50
示例#25
0
    def createShadingNetwork(cls, parentNode=None, xPos=0, yPos=0):
        """
        Convenience function to create the shading network for our SkyDome.

        Can be called from inside Katana using:
        C{Plugins.GafferThreeAPI.PackageClasses.SkyDomePackage.createShadingNetwork()}
        """
        if parentNode is None:
            parentNode = NodegraphAPI.GetRootNode()

        # Create shading network
        imageNode = NodegraphAPI.CreateNode('ArnoldShadingNode', parentNode)
        imageNode.getParameter('name').setValue('skyDomeImage', 0)
        NodegraphAPI.SetNodePosition(imageNode, (xPos, yPos + 120))
        imageNode.getParameter('nodeType').setValue('image', 0)
        imageNode.checkDynamicParameters()

        lightNode = NodegraphAPI.CreateNode('ArnoldShadingNode', parentNode)
        lightNode.getParameter('name').setValue('skyDomeLight', 0)
        NodegraphAPI.SetNodePosition(lightNode, (xPos, yPos + 80))
        lightNode.getParameter('nodeType').setValue('skydome_light', 0)
        lightNode.checkDynamicParameters()
        lightNode.getInputPort('color').connect(imageNode.getOutputPort('out'))

        hdriLightNode = NodegraphAPI.CreateNode('NetworkMaterial', parentNode)
        hdriLightNode.getParameter('name').setValue('hdriSkyDomeLight', 0)
        NodegraphAPI.SetNodePosition(hdriLightNode, (xPos, yPos + 40))
        hdriLightNode.addInputPort('arnoldSurface')
        hdriLightNode.getInputPort('arnoldSurface').connect(
            lightNode.getOutputPort('out'))

        lookFileMaterialsOutNode = NodegraphAPI.CreateNode(
            'LookFileMaterialsOut', parentNode)
        lookFileMaterialsOutNode.setName('hdriSkiDomeLight_bake')
        NodegraphAPI.SetNodePosition(lookFileMaterialsOutNode, (xPos, yPos))
        lookFileMaterialsOutNode.getParameter('saveTo').setValue(
            cls.DEFAULT_BAKED_LIGHT_FILENAME, 0)
        lookFileMaterialsOutNode.getInputPort('in').connect(
            hdriLightNode.getOutputPort('out'))

        # Expose shading node parameters on the network material
        cls.__exposeShaderParameter(imageNode, 'filename', 'HDRI_map',
                                    {'widget': 'fileInput'})
        cls.__exposeShaderParameter(imageNode, 'sflip')
        cls.__exposeShaderParameter(imageNode, 'tflip')
        cls.__exposeShaderParameter(imageNode, 'multiply', 'color')
        cls.__exposeShaderParameter(lightNode, 'matrix')
        cls.__exposeShaderParameter(lightNode, 'intensity')
        cls.__exposeShaderParameter(lightNode, 'exposure')
        cls.__exposeShaderParameter(lightNode, 'samples')

        return lookFileMaterialsOutNode
示例#26
0
 def createFaceSet(self,InGroupStackNode,InData):
     Triger = InData[2]
     if Triger == str(-1):
         return
     MeshLocation = self.headAlebic + InData[1]
     Selection = InData[2]
     #FaceSetName = InData[0] + "_FaceSet"
     facesetNode = NodegraphAPI.CreateNode('FaceSetCreate', NodegraphAPI.GetRootNode())
     #facesetNode.setName(FaceSetName)
     facesetNode.getParameter("meshLocation").setValue(str(MeshLocation), 0)
     facesetNode.getParameter("faceSetName").setValue(str(InData[4]), 0)
     facesetNode.getParameter("selection").setValue(str(Selection), 0)
     InGroupStackNode.buildChildNode(facesetNode)
示例#27
0
def xml_element_to_nodes(xml_element, parent=None):
    '''
    :description to create katana nodes from xml element
    :param xml_element <PyXmlIO.Element>
    :param parent <Nodegraph Node Object>
    :example
        from core import scene
        scene.xml_element_to_nodes(xml_element)   
    '''
    if not parent:
        parent = NodegraphAPI.GetRootNode()
    knodes = KatanaFile.Paste(xml_element, parent)
    return knodes
示例#28
0
文件: Node.py 项目: ireneher/hikatana
    def __init__(self):
        self.hideNodegraphGroupControls()
        self.addInputPort("in")
        self.addOutputPort("out")
        self.getParameters().createChildNumber("version", Constants.CURRENT_VERSION)
        location = self.getParameters().createChildString(
                        Constants.LOCATION_PARAM, Constants.DEFAULT_LOCATION
                    )
        location.setHintString(repr({"help": "SceneGraph location of collections",
                                     "widget": "newScenegraphLocation"}))

        self.__buildDefaultNetwork()
        if not self.getParent():
            self.setParent(NodegraphAPI.GetRootNode())
示例#29
0
def createMasterBlocker(name='BlockerGroup',
                        parent=NodegraphAPI.GetRootNode()):
    rootNode = parent
    #create the groupNode
    groupNode = NodegraphAPI.CreateNode('Group', rootNode)
    groupNode.setName(name)
    #add in and out port
    groupNode.addInputPort('in')
    groupNode.addOutputPort('out')
    #add attribute to switch the display of group node to normal node
    groupNodeAttrDict = {'ns_basicDisplay': 1, 'ns_iconName': ''}
    groupNode.setAttributes(groupNodeAttrDict)
    blockerName = 'Blocker1'

    #create a first blocker
    blocker = createSingleBlocker(groupNode, 'getParent().getParent().', False)
    paramui(groupNode, blocker.getName(), True)

    #reorder the button addBlocker to be the last param
    blockerParam = groupNode.getParameters()
    paramAddBlocker = blockerParam.getChild('addBlocker')
    numberOfChild = blockerParam.getNumChildren() - 1
    blockerParam.reorderChild(paramAddBlocker, numberOfChild)

    #create a dot node
    dotNode = NodegraphAPI.CreateNode('Dot', groupNode)
    dotNode.setName('outDot')

    #connection
    sendGroup = groupNode.getSendPort('in')
    returnGroup = groupNode.getReturnPort('out')
    blocker.getInputPort('in').connect(sendGroup)
    blocker.getOutputPort('out').connect(dotNode.getInputPort('input'))
    dotNode.getOutputPort('output').connect(returnGroup)

    #set position of nodes
    centralPos = NodegraphAPI.GetNodePosition(blocker)
    NodegraphAPI.SetNodePosition(dotNode, (centralPos[0], centralPos[1] - 50))

    #put the node under the mouse
    currentSelection = NodegraphAPI.GetAllSelectedNodes()
    for node in currentSelection:
        NodegraphAPI.SetNodeSelected(node, False)
    NodegraphAPI.SetNodeSelected(groupNode, True)
    # Get list of selected nodes
    nodeList = NodegraphAPI.GetAllSelectedNodes()
    # Find Nodegraph tab and float nodes
    nodegraphTab = UI4.App.Tabs.FindTopTab('Node Graph')
    if nodegraphTab:
        nodegraphTab.floatNodes(nodeList)
示例#30
0
def create_node():
    '''
    :description to create lookdev bake node
    :param None
    :example
        from resources.studio_nodes.lookdev_bake_node import node
        node.create_node()  
    '''       
    parent = NodegraphAPI.GetRootNode()
    knode = NodegraphAPI.CreateNode('LookFileBake', parent=parent)
    knode.setName(studio_nodes.LOOKDEV_BAKE_NODE_TYPE)    
    add_parameters(knode)    
    NodegraphAPI.SetNodeViewed(knode, True, exclusive=True)
    NodegraphAPI.SetNodeEdited(knode, True, exclusive=True)