Example #1
0
 def execute(operator, context):
     # please not be confused: "operator" here references to
     # SverchNodeAddOperator instance, and "self" references to
     # SverchNodeItem instance.
     operator.use_transform = True
     operator.type = self.nodetype
     node = operator.create_node(context)
     apply_default_preset(node)
     return {'FINISHED'}
Example #2
0
def view_node(tree):
    '''viewer map is a node attribute to inform to the operator how to visualize
    the node data
    it is a list with two items.
    The first item is a list with tuples, every tuple need to have the node bl_idanme and offset to the previous node
    The second item is a list with tuples, every tuple indicates a link.
    The link is defined by two pairs of numbers, refering to output and input
    The first number of every pair indicates the node being 0 the active node 1 the first needed node and so on
    The second nmber of every pair indicates de socket index.

    So to say: create a Viewer Draw with a offset of 60,0 and connect the first output to the vertices input
    the node would need to have this:

        viewer_map = [
            ("SvViewerDrawMk4", [60, 0])
            ], [
            ([0, 0], [1, 0])
            ]

    '''
    nodes = tree.nodes
    links = tree.links
    existing_node = nodes.active
    node_list = [existing_node]
    output_map = existing_node.viewer_map

    previous_state = tree.sv_process
    tree.sv_process = False

    for node in output_map[0]:
        bl_idname_new_node, offset = node
        new_node = nodes.new(bl_idname_new_node)
        apply_default_preset(new_node)
        offset_node_location(node_list[-1], new_node, offset)
        frame_adjust(node_list[-1], new_node)
        node_list.append(new_node)
    for link in output_map[1]:
        output_s, input_s = link
        links.new(node_list[output_s[0]].outputs[output_s[1]],
                  node_list[input_s[0]].inputs[input_s[1]])
    tree.sv_process = previous_state
    tree.update()
Example #3
0
def add_connection(tree, bl_idname_new_node, offset):

    nodes = tree.nodes
    links = tree.links

    output_map = get_output_sockets_map(nodes.active)

    existing_node = nodes.active

    if isinstance(bl_idname_new_node, str):
        # single new node..

        new_node = nodes.new(bl_idname_new_node)
        apply_default_preset(new_node)
        offset_node_location(existing_node, new_node, offset)
        frame_adjust(existing_node, new_node)

        outputs = existing_node.outputs
        inputs = new_node.inputs

        if existing_node.bl_idname in supported_mesh_viewers and bl_idname_new_node == 'SvIDXViewer28':
            new_node.draw_bg = True
            connect_idx_viewer(tree, existing_node, new_node)

        elif bl_idname_new_node == 'SvStethoscopeNodeMK2':
            # we can't determin thru cursor location which socket was nearest the rightclick
            # maybe in the future.. or if someone does know :)
            for socket in outputs:
                if socket.hide:
                    continue
                # connect_stethoscope to first visible output socket of active node
                links.new(socket, inputs[0])
                break

            tree.update(
            )  # without this the node won't show output until an update is triggered manually
            # existing_node.process_node(None)

        elif bl_idname_new_node == 'SvViewerDrawMk4':
            previous_state = tree.sv_process
            tree.sv_process = False
            if 'verts' in output_map:
                links.new(outputs[output_map['verts']], inputs[0])
                if 'faces' in output_map:
                    links.new(outputs[output_map['faces']], inputs[2])
                if 'edges' in output_map:
                    links.new(outputs[output_map['edges']], inputs[1])
            elif 'curve' in output_map:

                eval_node = nodes.new('SvExEvalCurveNode')
                apply_default_preset(eval_node)
                offset_node_location(existing_node, eval_node, offset)
                frame_adjust(existing_node, eval_node)
                offset_node_location(eval_node, new_node, offset)
                frame_adjust(eval_node, new_node)
                links.new(outputs[output_map['curve']], eval_node.inputs[0])
                links.new(eval_node.outputs[0], inputs[0])
                links.new(eval_node.outputs[1], inputs[1])

            elif 'surface' in output_map:
                eval_node = nodes.new('SvExEvalSurfaceNode')
                apply_default_preset(eval_node)
                offset_node_location(existing_node, eval_node, offset)
                frame_adjust(existing_node, eval_node)
                offset_node_location(eval_node, new_node, offset)
                frame_adjust(eval_node, new_node)
                links.new(outputs[output_map['surface']], eval_node.inputs[0])
                links.new(eval_node.outputs[0], inputs[0])
                links.new(eval_node.outputs[1], inputs[1])
                links.new(eval_node.outputs[2], inputs[2])
            elif 'solid' in output_map:
                tree.nodes.remove(new_node)
                new_node = nodes.new('SvSolidViewerNode')
                apply_default_preset(new_node)
                offset_node_location(existing_node, new_node, offset)
                frame_adjust(existing_node, new_node)
                links.new(outputs[output_map['solid']], new_node.inputs[0])
            tree.sv_process = previous_state
            tree.update()
            # existing_node.process_node(None)

        else:
            ...
    elif isinstance(bl_idname_new_node, list):
        # maybe vdmk2 + indexviewer
        ...