Ejemplo n.º 1
0
 def rebuild_out_sockets(self):
     links = {
         sock.name: [link.to_socket for link in sock.links]
         for sock in self.outputs
     }
     self.outputs.clear()
     new_socks = []
     for i, (sock_a, sock_b) in enumerate(
             zip(list(self.inputs)[1::2],
                 list(self.inputs)[2::2])):
         sock_a_link = get_other_socket(sock_a) if sock_a.links else None
         sock_b_link = get_other_socket(sock_b) if sock_b.links else None
         if sock_a_link and sock_b_link:
             if sock_a_link.bl_idname == sock_b_link.bl_idname:
                 new_socks.append(
                     self.outputs.new(sock_a_link.bl_idname, f"Out_{i}"))
             else:
                 new_socks.append(
                     self.outputs.new("SvStringsSocket", f"Out_{i}"))
         elif sock_a_link and getattr(self, sock_b.prop_name) == 'None':
             new_socks.append(
                 self.outputs.new(sock_a_link.bl_idname, f"Out_{i}"))
         elif sock_b_link and getattr(self, sock_a.prop_name) == 'None':
             new_socks.append(
                 self.outputs.new(sock_b_link.bl_idname, f"Out_{i}"))
         else:
             new_socks.append(
                 self.outputs.new("SvStringsSocket", f"Out_{i}"))
     new_links = [
         self.id_data.links.new(sock, other_socket) for sock in new_socks
         if sock.name in links for other_socket in links[sock.name]
     ]
     for link in new_links:
         link.is_valid = True
Ejemplo n.º 2
0
def get_socket_data(socket):
    other = get_other_socket(socket)
    if socket.bl_idname == "SvDummySocket":
        socket = get_other_socket(socket)

    socket_bl_idname = socket.bl_idname
    socket_name = socket.name
    return socket_name, socket_bl_idname, socket.prop_name
Ejemplo n.º 3
0
def get_socket_data(socket):
    other = get_other_socket(socket)
    if socket.bl_idname == "SvDummySocket":
        socket = get_other_socket(socket)

    socket_bl_idname = socket.bl_idname
    socket_name = socket.name
    return socket_name, socket_bl_idname, socket.prop_name
Ejemplo n.º 4
0
    def process(self):
        if not self.outputs['Matrix'].is_linked:
            return
    
        loc_ = self.inputs['Location'].sv_get()
        loc = Vector_generate(loc_)

        scale_ = self.inputs['Scale'].sv_get()
        scale = Vector_generate(scale_)


        rot_ = self.inputs['Rotation'].sv_get()
        rot = Vector_generate(rot_)

        rotA = [[]]
        angle = [[0.0]]
        # it isn't a good idea to hide things like this
        if self.inputs['Angle'].is_linked:
            other = get_other_socket(self.inputs['Angle'])
            
            if isinstance(other, StringsSocket):
                angle = self.inputs['Angle'].sv_get()
            elif isinstance(other, VerticesSocket):
                rotA_ = self.inputs['Angle'].sv_get()
                rotA = Vector_generate(rotA_)

        max_l = max(len(loc[0]), len(scale[0]), len(rot[0]), len(angle[0]), len(rotA[0]))
        orig = []
        for l in range(max_l):
            M = mathutils.Matrix()
            orig.append(M)
        matrixes_ = matrixdef(orig, loc, scale, rot, angle, rotA)
        matrixes = Matrix_listing(matrixes_)
        SvSetSocketAnyType(self, 'Matrix', matrixes)
Ejemplo n.º 5
0
    def process(self):
        if not self.outputs['Matrix'].is_linked:
            return

        loc_ = self.inputs['Location'].sv_get()
        loc = Vector_generate(loc_)

        scale_ = self.inputs['Scale'].sv_get()
        scale = Vector_generate(scale_)

        rot_ = self.inputs['Rotation'].sv_get()
        rot = Vector_generate(rot_)

        rotA = [[]]
        angle = [[0.0]]
        # it isn't a good idea to hide things like this
        if self.inputs['Angle'].is_linked:
            other = get_other_socket(self.inputs['Angle'])

            if isinstance(other, StringsSocket):
                angle = self.inputs['Angle'].sv_get()
            elif isinstance(other, VerticesSocket):
                rotA_ = self.inputs['Angle'].sv_get()
                rotA = Vector_generate(rotA_)

        max_l = max(len(loc[0]), len(scale[0]), len(rot[0]), len(angle[0]),
                    len(rotA[0]))
        orig = []
        for l in range(max_l):
            M = mathutils.Matrix()
            orig.append(M)
        matrixes_ = matrixdef(orig, loc, scale, rot, angle, rotA)
        matrixes = Matrix_listing(matrixes_)
        SvSetSocketAnyType(self, 'Matrix', matrixes)
Ejemplo n.º 6
0
 def update(self):
     other = get_other_socket(self.inputs[0])
     if not other:
         return
     self.multi_socket_type = other.bl_idname
     multi_socket(self, min=1, start=0, breck=True, out_count=self.count)
     outputsocketname = [name.name for name in self.outputs]
     changable_sockets(self, 'data', outputsocketname)
Ejemplo n.º 7
0
 def data_type_check(cls, socket, source_data):
     checking_sockets = cls.get_data_type_checking_socket_types()
     expected_type = checking_sockets.get(socket.bl_idname)
     if expected_type is None:
         return False
     if not get_other_socket(socket).bl_idname in cls.get_arbitrary_type_socket_types():
         return False
     return is_ultimately(source_data, expected_type)
Ejemplo n.º 8
0
 def update(self):
     other = get_other_socket(self.inputs[0])
     if not other:
         return
     self.multi_socket_type = other.bl_idname
     multi_socket(self, min=1, start=0, breck=True, out_count=self.count)
     outputsocketname = [name.name for name in self.outputs]
     changable_sockets(self, 'data', outputsocketname)
Ejemplo n.º 9
0
def check_data_in(soc):
    #puts data in nested list if necessary
            
    if type(soc.sv_get()[0]) == list:
        return soc.sv_get()
    elif get_other_socket(soc).bl_idname in SPECIAL_SOCKETS:
        return [soc.sv_get()]
    else:
        print('Switch mk2 node did not expect such type of input socket')
Ejemplo n.º 10
0
def cross_test_socket(self, A, B):
    """ A is origin type, B is destination type """
    other = get_other_socket(self)
    get_type = {
        'v': 'VerticesSocket',
        'm': 'MatrixSocket',
        'q': "SvQuaternionSocket"
    }
    return other.bl_idname == get_type[A] and self.bl_idname == get_type[B]
Ejemplo n.º 11
0
 def auto_count(self):
     data = self.inputs['data'].sv_get(default="not found")
     other = get_other_socket(self.inputs['data'])
     if other and data == "not found":
         update_system.process_to_node(other.node)
         data = self.inputs['data'].sv_get()
         
     leve = levelsOflist(data)
     if leve+1 < self.level:
         self.level = leve+1
     result = self.beat(data, self.level)
     self.count = min(len(result), 16)
Ejemplo n.º 12
0
    def auto_count(self):
        data = self.inputs['data'].sv_get(default="not found")
        other = get_other_socket(self.inputs['data'])
        if other and data == "not found":
            update_system.process_to_node(other.node)
            data = self.inputs['data'].sv_get()

        leve = levelsOflist(data)
        if leve + 1 < self.level:
            self.level = leve + 1
        result = self.beat(data, self.level)
        self.count = min(len(result), 16)
Ejemplo n.º 13
0
 def update(self):
     inputs_A = [i for i in self.inputs if i.name[0] == 'A']
     for in_soc, out_soc in zip(inputs_A, self.outputs):
         
         if not in_soc.links:
             new_type = in_soc.bl_idname
         else:
             in_other = get_other_socket(in_soc)
             new_type = in_other.bl_idname
             
         if new_type == out_soc.bl_idname:
             continue
         
         replace_socket(out_soc, new_type)
Ejemplo n.º 14
0
    def update(self):
        if not len(self.inputs) == self.switch_count * 2 + 1:
            return
        if not len(self.outputs) == self.switch_count:
            return

        for i, s in enumerate(self.inputs):
            if s.name.startswith("T"):
                other = get_other_socket(s)
                out_s = self.outputs[i - 1]
                if other and not isinstance(out_s, type(other)):
                    name = out_s.name
                    self.outputs.remove(out_s)
                    self.outputs.new(other.bl_idname, name)
                    self.outputs.move(len(self.outputs) - 1, i - 1)
                count = i
Ejemplo n.º 15
0
 def update(self):
     if not len(self.inputs) == self.switch_count*2+1:
         return
     if not len(self.outputs) == self.switch_count:
         return
         
     for i,s in enumerate(self.inputs):
         if s.name.startswith("T"):
             other = get_other_socket(s)
             out_s = self.outputs[i-1]
             if other and not isinstance(out_s, type(other)):
                 name = out_s.name
                 self.outputs.remove(out_s)
                 self.outputs.new(other.bl_idname, name)
                 self.outputs.move(len(self.outputs)-1, i-1) 
             count = i
Ejemplo n.º 16
0
 def sv_update(self):
     '''adapt socket type to input type'''
     if 'O3D Geometry' in self.inputs and self.inputs[
             'O3D Geometry'].links:
         inputsocketname = 'O3D Geometry'
         outputsocketname = ['O3D Geometry']
         changable_sockets(self, inputsocketname, outputsocketname)
         if self.outputs[
                 'O3D Geometry'].bl_idname == 'SvO3TriangleMeshSocket':
             self.outputs['O3D Geometry'].label = 'O3D Triangle Mesh'
         else:
             self.outputs['O3D Geometry'].label = 'O3D Point Cloud'
         in_socket = self.inputs['Transformation']
         if in_socket.is_linked:
             in_other = get_other_socket(in_socket)
             if in_other:
                 s_type = in_other.bl_idname
                 self.method = transformation_dict[s_type]
Ejemplo n.º 17
0
    def adjust_reroutes(self):

        reroutes = [n for n in self.nodes if n.bl_idname == 'NodeReroute']
        if not reroutes:
            return
        for n in reroutes:
            s = n.inputs[0]
            if s.links:
                self.freeze(True)

                other = get_other_socket(s)
                s_type = other.bl_idname
                if n.outputs[0].bl_idname != s_type:
                    out_socket = n.outputs.new(s_type, "Output")
                    in_sockets = [l.to_socket for l in n.outputs[0].links]
                    n.outputs.remove(n.outputs[0])
                    for i_s in in_sockets:
                        l = self.links.new(i_s, out_socket)

                self.unfreeze(True)
Ejemplo n.º 18
0
    def adjust_reroutes(self):

        reroutes = [n for n in self.nodes if n.bl_idname == 'NodeReroute']
        if not reroutes:
            return
        for n in reroutes:
            s = n.inputs[0]
            if s.links:
                self.freeze(True)

                other = get_other_socket(s)
                s_type = other.bl_idname
                if n.outputs[0].bl_idname != s_type:
                    out_socket = n.outputs.new(s_type, "Output")
                    in_sockets = [l.to_socket for l in n.outputs[0].links]
                    n.outputs.remove(n.outputs[0])
                    for i_s in in_sockets:
                        l = self.links.new(i_s, out_socket)

                self.unfreeze(True)
Ejemplo n.º 19
0
def cross_test_socket(self, A, B):
    """ A is origin type, B is destination type """
    other = get_other_socket(self)
    get_type = {'v': 'VerticesSocket', 'm': 'MatrixSocket'}
    return other.bl_idname == get_type[A] and self.bl_idname == get_type[B]
Ejemplo n.º 20
0
 def other(self):
     return get_other_socket(self)
Ejemplo n.º 21
0
    def execute(self, context):

        ng = context.space_data.node_tree
        ng.freeze(hard=True)
        is_process = ng.sv_process
        ng.sv_process = False
        # collect data
        nodes = {n for n in ng.nodes if n.select}
        if not nodes:
            self.report({"CANCELLED"}, "No nodes selected")
            return {'CANCELLED'}
        # collect links outside of of selected nodes
        test_in = lambda l: bool(l.to_node in nodes) and bool(l.from_node
                                                              not in nodes)
        test_out = lambda l: bool(l.from_node in nodes) and bool(l.to_node
                                                                 not in nodes)
        out_links = [l for l in ng.links if test_out(l)]
        in_links = [l for l in ng.links if test_in(l)]
        locx = [n.location.x for n in nodes]
        locy = sum(n.location.y for n in nodes) / len(nodes)

        # crete node_group nodes

        group_in = ng.nodes.new("SvGroupInputsNode")
        group_in.location = (min(locx) - 300, locy)
        group_out = ng.nodes.new("SvGroupOutputsNode")
        group_out.location = (max(locx) + 300, locy)
        group_node = ng.nodes.new("SvGroupNode")
        group_node.location = (sum(locx) / len(nodes), locy)

        # create node group links and replace with a node group instead
        for i, l in enumerate(in_links):
            out_socket = l.from_socket
            in_socket = l.to_socket
            s_name = "{}:{}".format(i, in_socket.name)
            other = get_other_socket(in_socket)
            gn_socket = group_node.inputs.new(other.bl_idname, s_name)
            gi_socket = group_in.outputs.new(other.bl_idname, s_name)

            ng.links.remove(l)
            ng.links.new(in_socket, gi_socket)
            ng.links.new(gn_socket, out_socket)

        out_links_sockets = set(l.from_socket for l in out_links)

        for i, from_socket in enumerate(out_links_sockets):
            to_sockets = [l.to_socket for l in from_socket.links]
            s_name = "{}:{}".format(i, from_socket.name)
            # to account for reroutes
            other = get_other_socket(to_sockets[0])
            gn_socket = group_node.outputs.new(other.bl_idname, s_name)
            go_socket = group_out.inputs.new(other.bl_idname, s_name)
            for to_socket in to_sockets:
                l = to_socket.links[0]
                ng.links.remove(l)
                ng.links.new(go_socket, from_socket)
                ng.links.new(to_socket, gn_socket)

        # collect sockets for node group in out
        group_in.collect()
        group_out.collect()
        # deselect all
        for n in ng.nodes:
            n.select = False
        nodes.add(group_in)
        nodes.add(group_out)

        # select nodes to move
        for n in nodes:
            n.select = True

        nodes_json = create_dict_of_tree(ng, {}, selected=True)
        print(nodes_json)

        for n in nodes:
            ng.nodes.remove(n)

        group_ng = bpy.data.node_groups.new("SvGroup", 'SverchGroupTreeType')

        group_node.group_name = group_ng.name
        group_node.select = True
        group_ng.use_fake_user = True
        import_tree(group_ng, "", nodes_json)

        ng.unfreeze(hard=True)
        ng.sv_process = is_process
        ng.update()
        self.report({"INFO"}, "Node group created")
        return {'FINISHED'}
Ejemplo n.º 22
0
def is_string_to_vector(socket):
    other = get_other_socket(socket)
    return other.bl_idname == 'SvStringsSocket' and socket.bl_idname == 'SvVerticesSocket'
Ejemplo n.º 23
0
 def set_count(self, context):
     other = get_other_socket(self.inputs[0])
     if not other:
         return
     self.multi_socket_type = other.bl_idname
     multi_socket(self, min=1, start=0, breck=True, out_count=self.count)
Ejemplo n.º 24
0
def is_matrix_to_vfield(socket):
    other = get_other_socket(socket)
    return other.bl_idname == 'SvMatrixSocket' and socket.bl_idname == 'SvVectorFieldSocket'
Ejemplo n.º 25
0
def is_vertex_to_vfield(socket):
    other = get_other_socket(socket)
    return other.bl_idname == 'SvVerticesSocket' and socket.bl_idname == 'SvVectorFieldSocket'
Ejemplo n.º 26
0
def is_string_to_sfield(socket):
    other = get_other_socket(socket)
    return other.bl_idname == 'SvStringsSocket' and socket.bl_idname == 'SvScalarFieldSocket'
Ejemplo n.º 27
0
 def other(self):
     """Returns opposite liked socket, if socket is outputs it will return one random opposite linked socket"""
     return get_other_socket(self)
Ejemplo n.º 28
0
 def other(self):
     return get_other_socket(self)
Ejemplo n.º 29
0
 def set_count(self, context):
     other = get_other_socket(self.inputs[0])
     if not other:
         return
     self.multi_socket_type = other.bl_idname
     multi_socket(self, min=1, start=0, breck=True, out_count=self.count)
Ejemplo n.º 30
0
    def execute(self, context):
        
        ng = context.space_data.node_tree
        ng.freeze(hard=True)
        is_process = ng.sv_process
        ng.sv_process = False
        # collect data
        nodes = {n for n in ng.nodes if n.select}
        if not nodes:
            self.report({"CANCELLED"}, "No nodes selected")
            return {'CANCELLED'}
        # collect links outside of of selected nodes
        test_in = lambda l: bool(l.to_node in nodes) and bool(l.from_node not in nodes) 
        test_out = lambda l: bool(l.from_node in nodes) and bool(l.to_node not in nodes)
        out_links = [l for l in ng.links if test_out(l)]
        in_links = [l for l in ng.links if test_in(l)]
        locx = [n.location.x for n in nodes]
        locy = sum(n.location.y for n in nodes)/len(nodes)
        
        # crete node_group nodes
        
        group_in = ng.nodes.new("SvGroupInputsNode")
        group_in.location = (min(locx)-300, locy)
        group_out = ng.nodes.new("SvGroupOutputsNode")
        group_out.location = (max(locx)+300, locy)
        group_node = ng.nodes.new("SvGroupNode")
        group_node.location = (sum(locx)/len(nodes), locy)

        # create node group links and replace with a node group instead
        for i,l in enumerate(in_links):
            out_socket = l.from_socket
            in_socket = l.to_socket
            s_name = "{}:{}".format(i,in_socket.name)
            other = get_other_socket(in_socket)
            gn_socket = group_node.inputs.new(other.bl_idname, s_name )
            gi_socket = group_in.outputs.new(other.bl_idname, s_name)
            
            ng.links.remove(l)
            ng.links.new(in_socket, gi_socket)
            ng.links.new(gn_socket, out_socket)
        
        out_links_sockets = set(l.from_socket for l in out_links)
        
        for i, from_socket in enumerate(out_links_sockets):
            to_sockets = [l.to_socket for l in from_socket.links]
            s_name = "{}:{}".format(i, from_socket.name)
            # to account for reroutes
            other = get_other_socket(to_sockets[0])
            gn_socket = group_node.outputs.new(other.bl_idname, s_name)
            go_socket = group_out.inputs.new(other.bl_idname, s_name)
            for to_socket in to_sockets:
                l = to_socket.links[0]
                ng.links.remove(l)
                ng.links.new(go_socket, from_socket)
                ng.links.new(to_socket, gn_socket)
        
        # collect sockets for node group in out    
        group_in.collect()
        group_out.collect()
        # deselect all
        for n in ng.nodes:
            n.select = False
        nodes.add(group_in)
        nodes.add(group_out)
        
        # select nodes to move
        for n in nodes:
            n.select = True
        
        nodes_json = create_dict_of_tree(ng, {}, selected=True)
        print(nodes_json)
        
        for n in nodes:
            ng.nodes.remove(n)
        
        group_ng = bpy.data.node_groups.new("SvGroup", 'SverchGroupTreeType')
        
        group_node.group_name = group_ng.name
        group_node.select = True
        group_ng.use_fake_user = True
        import_tree(group_ng, "", nodes_json)
        
        ng.unfreeze(hard=True)
        ng.sv_process = is_process
        ng.update()
        self.report({"INFO"}, "Node group created")
        return {'FINISHED'}