Пример #1
0
def writeScript(katanaFile=None, jsonFile):
    from Katana import KatanaFile, NodegraphAPI

    if katanaFile is not None:
        KatanaFile.Load(katanaFile)
    json_data = {}
    print "\n\n########################"
    for node in NodegraphAPI.GetAllNodes():
        if node.getType() == "ArnoldShadingNode":
            node_name = node.getName()
            shader_type = node.getParameter('nodeType').getValue(0)
            if shader_type.startswith("lc_"):
                #~ check if shader_type in SHADERMAPPING
                if not shader_type in SHADERMAPPING:
                    print "#ERROR#", shader_type
                    continue
                json_data[node_name] = []
                #~ read paramter value and record it!
                json_data[node_name].append(shader_type)
                shader_data = []
                for para_name in SHADERMAPPING[shader_type][1]:
                    node.checkDynamicParameters()
                    k_parameter_value = node.getParameter(
                        'parameters.%s.value' % para_name)
                    k_parameter_enable = node.getParameter(
                        'parameters.%s.enable' % para_name)
                    #~ if parameter connected to a node
                    if isPortConnected(node, para_name):
                        connected_node = node.getInputPort(
                            para_name).getConnectedPorts()[0].getNode()
                        # if k_parameter_value.getType() == "numberArray":
                        #     if node_name == "bg_remap_color":
                        #         print node.getInputPort(para_name).getConnectedPorts()[0].getNode()
                        # else:
                        #     connected_node = node.getInputPort(para_name).getConnectedPorts()[0].getNode()
                        shader_data.append(
                            (False, para_name, True, connected_node.getName()))
                    #~ if parameter is a value
                    else:
                        value = []
                        enable = False
                        if k_parameter_enable.getValue(0):
                            enable = True
                        if k_parameter_value.getType() == "numberArray":
                            for child in k_parameter_value.getChildren():
                                value.append(child.getValue(0))
                        else:
                            value.append(k_parameter_value.getValue(0))
                        shader_data.append((enable, para_name, False, value))
                json_data[node_name].append(shader_data)

    print "#$~", jsonFile
    outfile = open(jsonFile, 'w')
    json.dump(json_data, outfile, ensure_ascii=False, sort_keys=True, indent=4)
    outfile.close()
    print "########################\n"
Пример #2
0
def get_scene_nodes():
    '''
    :description get all nodes from the scene
    :example
        from core import nodegraph
        scene_nodes = nodegraph.get_scene_nodes()
        print scene_nodes    
    '''
    nodes = []
    knodes = NodegraphAPI.GetAllNodes(includeDeleted=False)
    for knode in knodes:
        nodes.append(knode.getName())
    return nodes
Пример #3
0
def PopulateCallback(layeredMenu):
    primitiveNames = []
    for node in NodegraphAPI.GetAllNodes():
        if node.getType() == "Render" or node.getType(
        ) == "ImageWrite" or 'pbRend' in node.getName():
            primitiveNames.append(node.getName())
        else:
            pass

    for primitiveName in primitiveNames:
        layeredMenu.addEntry(primitiveName,
                             text=primitiveName,
                             color=(0.8, 0.24, 0.26))
Пример #4
0
def check(file):
    from Katana import KatanaFile, NodegraphAPI
    KatanaFile.Load(file)

    print ""
    for node in NodegraphAPI.GetAllNodes():
        if node.getType() == "ArnoldShadingNode":
            node_name = node.getName()
            shader_type = node.getParameter('nodeType').getValue(0)
            if shader_type.startswith("lc_"):
                #~ check if shader_type in SHADERMAPPING
                print "#ERROR#", node_name, shader_type
                continue
Пример #5
0
def get_studio_nodes(key, value=None):
    # group_nodes = NodegraphAPI.GetAllNodesByType('Group', includeDeleted=False)
    k_nodes = NodegraphAPI.GetAllNodes(includeDeleted=False)
    studio_nodes = {}
    for k_node in k_nodes:
        parameter = k_node.getParameter(key)
        if not parameter:
            continue
        node_value = parameter.getValue(1.0)
        if value:
            if parameter.getValue(1.0) != value:
                continue
            studio_nodes.setdefault(k_node, node_value)
        else:
            studio_nodes.setdefault(k_node, node_value)
    return studio_nodes
Пример #6
0
def setParameterNodeGraph(parameter_name,
                          value,
                          time=1.0,
                          t='',
                          selected=False,
                          recursive=False):
    '''
    this method set the given paramter to the given value on all the nodes in the node graph,
    if selected is True, then only selected nodes will be affected,
    if recursive is True, then the group nodes will be expanded recursivly if any,
    
    By default, we set the value at time 1.0, this can be changed by specifying the time, and
    node with any type will be targeted. If you want to shrink the nodes down to the type of 'Alembic_In' 
    for instance, then you can specify t='Alembic_In'

    obsoleted:
    if strictly is True, then we use strict name matching rule to look up the given parameters,
    otherwise it will be true if the lower case of the given parameter name is included in the lower 
    case of the parameter name on the nodes.
    '''
    if t and isinstance(t, str):
        nodes = NodegraphAPI.GetAllNodesByType(t)
    else:
        nodes = NodegraphAPI.GetAllNodes()
    if selected:
        sel_nodes = NodegraphAPI.GetAllSelectedNodes()
        if recursive:
            sel_nodes = ng_traverseGroupDown(sel_nodes)
        nodes = list(set(nodes).intersection(sel_nodes))
    # set attribute
    log = ''
    for n in nodes:
        # lets try to access the parameter directly
        param = n.getParameter(parameter_name)
        if param:
            param.setUseNodeDefault(False)
            param.setValue(value, time)
            log += ('%s: %s at time %s\n') % (param.getFullName(), str(value),
                                              str(time))
            continue
        # get the parameters' objects
        params = setParameters({parameter_name: [value, time]}, n)
        if params:
            log += ('%s: %s at time %s\n') % (params[0].getFullName(),
                                              str(value), str(time))
    if log:
        print log