Esempio n. 1
0
    def generate_callback(self, n_id, IV):
        inputs = self.inputs

        verts, matrices = [], []
        text = ''

        # gather vertices from input
        propv = inputs['vertices'].sv_get()
        verts = dataCorrect(propv)

        # end early, no point doing anything else.
        if not verts:
            return

        # draw text on locations instead of indices.
        text_so = inputs['text'].sv_get(default=[])
        text = dataCorrect(text_so)
        if text:
            fullList(text, len(verts))
            for i, t in enumerate(text):
                fullList(text[i], len(verts[i]))

        # read non vertex inputs in a loop and assign to data_collected
        data_collected = []
        for socket in ['edges', 'faces', 'matrix']:
            propm = inputs[socket].sv_get(default=[])
            input_stream = dataCorrect(propm)
            data_collected.append(input_stream)

        edges, faces, matrices = data_collected

        bg = self.draw_bg
        settings = self.get_settings()
        IV.callback_enable(
            n_id, verts, edges, faces, matrices, bg, settings, text)
Esempio n. 2
0
    def process(self):
        if not any(s.is_linked for s in self.outputs):
            return
        if self.inputs["Vertices"].is_linked and self.inputs["Poly Egde"].is_linked:
            verts = self.inputs["Vertices"].sv_get()
            poly = self.inputs["Poly Egde"].sv_get()
            verts = dataCorrect(verts)
            poly = dataCorrect(poly)
            self.inputs["Mask"].sv_get(default=[[1, 0]])

            has_true_out = True
            has_false_out = False
            verts_out = []
            poly_edge_out = []
            for ve, pe, ma in zip(verts, poly, repeat_last(mask)):
                current_mask = islice(cycle(ma), len(ve))
                vert_index = [i for i, m in enumerate(current_mask) if m]
                if len(vert_index) < len(ve):
                    index_set = set(vert_index)
                    if has_true_out:
                        vert_dict = {j: i for i, j in enumerate(vert_index)}
                        new_vert = [ve[i] for i in vert_index]
                        is_ss = index_set.issuperset
                        new_pe = [[vert_dict[n] for n in fe] for fe in pe if is_ss(fe)]
                        verts_out.append(new_vert)
                        poly_edge_out.append(new_pe)

                else:  # no reprocessing needed
                    verts_out.append(ve)
                    poly_edge_out.append(pe)

            self.outputs["Vertices"].sv_set(verts_out)
            self.outputs["Poly Egde"].sv_set(poly_edge_out)
Esempio n. 3
0
    def process(self):

        if 'vertices' in self.inputs and self.inputs['vertices'].is_linked and \
           'edges' in self.inputs and self.inputs['edges'].is_linked:

            verts = dataCorrect(
                SvGetSocketAnyType(self, self.inputs['vertices']))
            edges = dataCorrect(SvGetSocketAnyType(self, self.inputs['edges']))
            sides = repeat_last(self.inputs['Sides'].sv_get()[0])
            verts_out = []
            edges_out = []
            polys_out = []

            for v, e, s in zip(verts, edges, sides):
                res = fill_holes(v, e, int(s))
                if not res:
                    return
                verts_out.append(res[0])
                edges_out.append(res[1])
                polys_out.append(res[2])

            if 'vertices' in self.outputs and self.outputs[
                    'vertices'].is_linked:
                SvSetSocketAnyType(self, 'vertices', verts_out)

            if 'edges' in self.outputs and self.outputs['edges'].is_linked:
                SvSetSocketAnyType(self, 'edges', edges_out)

            if 'polygons' in self.outputs and self.outputs[
                    'polygons'].is_linked:
                SvSetSocketAnyType(self, 'polygons', polys_out)
Esempio n. 4
0
    def update(self):
        multi_socket(self, min=2)

        if 'x0' in self.inputs and len(self.inputs['x0'].links) > 0:
            inputsocketname = self.inputs[0].name
            outputsocketname = [
                'data',
            ]
            changable_sockets(self, inputsocketname, outputsocketname)

        if 'data' in self.outputs and len(self.outputs['data'].links) > 0:
            if 'x0' in self.inputs and len(self.inputs['x0'].links) > 0:
                X = SvGetSocketAnyType(self, self.inputs['data'])
                slots = []
                for socket in self.inputs:
                    if socket.links:
                        slots.append(SvGetSocketAnyType(self, socket))
                if len(slots) < 2:
                    return

                X_ = dataCorrect(X)
                result = []
                for socket in slots:
                    result.extend(self.f(X_, dataCorrect(socket)))

                SvSetSocketAnyType(self, 'data', result)
Esempio n. 5
0
    def process(self):
        global cache_viewer_baker
        # node id, used as ref
        n_id = node_id(self)
        if 'matrix' not in self.inputs:
            return

        cache_viewer_baker[n_id + 'v'] = []
        cache_viewer_baker[n_id + 'ep'] = []
        cache_viewer_baker[n_id + 'm'] = []

        if not self.id_data.sv_show:
            callback_disable(n_id)
            return

        if self.activate and (self.inputs['vertices'].links
                              or self.inputs['matrix'].links):
            callback_disable(n_id)

            if self.inputs['vertices'].links and \
                type(self.inputs['vertices'].links[0].from_socket) == VerticesSocket:

                propv = SvGetSocketAnyType(self, self.inputs['vertices'])
                cache_viewer_baker[n_id + 'v'] = dataCorrect(propv)
            else:
                cache_viewer_baker[n_id + 'v'] = []

            if self.inputs['edg_pol'].links and \
                type(self.inputs['edg_pol'].links[0].from_socket) == StringsSocket:
                prope = SvGetSocketAnyType(self, self.inputs['edg_pol'])
                cache_viewer_baker[n_id + 'ep'] = dataCorrect(prope)
                #print (prope)
            else:
                cache_viewer_baker[n_id + 'ep'] = []

            if self.inputs['matrix'].links and \
                type(self.inputs['matrix'].links[0].from_socket) == MatrixSocket:
                propm = SvGetSocketAnyType(self, self.inputs['matrix'])
                cache_viewer_baker[n_id + 'm'] = dataCorrect(propm)
            else:
                cache_viewer_baker[n_id + 'm'] = []

        else:
            callback_disable(n_id)

        if cache_viewer_baker[n_id + 'v'] or cache_viewer_baker[n_id + 'm']:
            callback_enable(n_id, cache_viewer_baker[n_id+'v'], cache_viewer_baker[n_id+'ep'], \
                cache_viewer_baker[n_id+'m'], self.Vertex_show, self.color_view.copy(), self.transparant, self.shading)

            self.use_custom_color = True
            self.color = (1, 0.3, 0)
        else:
            self.use_custom_color = True
            self.color = (0.1, 0.05, 0)
            #print ('отражения вершин ',len(cache_viewer_baker['v']), " рёбёры ", len(cache_viewer_baker['ep']), "матрицы",len(cache_viewer_baker['m']))
        if not self.inputs['vertices'].links and not self.inputs[
                'matrix'].links:
            callback_disable(n_id)
Esempio n. 6
0
    def process(self):
        global cache_viewer_baker
        # node id, used as ref
        n_id = node_id(self)
        if 'matrix' not in self.inputs:
            return

        cache_viewer_baker[n_id+'v'] = []
        cache_viewer_baker[n_id+'ep'] = []
        cache_viewer_baker[n_id+'m'] = []

        if not self.id_data.sv_show:
            callback_disable(n_id)
            return

        if self.activate and (self.inputs['vertices'].links or self.inputs['matrix'].links):
            callback_disable(n_id)

            if self.inputs['vertices'].links and \
                type(self.inputs['vertices'].links[0].from_socket) == VerticesSocket:

                propv = SvGetSocketAnyType(self, self.inputs['vertices'])
                cache_viewer_baker[n_id+'v'] = dataCorrect(propv)
            else:
                cache_viewer_baker[n_id+'v'] = []

            if self.inputs['edg_pol'].links and \
                type(self.inputs['edg_pol'].links[0].from_socket) == StringsSocket:
                prope = SvGetSocketAnyType(self, self.inputs['edg_pol'])
                cache_viewer_baker[n_id+'ep'] = dataCorrect(prope)
                #print (prope)
            else:
                cache_viewer_baker[n_id+'ep'] = []

            if self.inputs['matrix'].links and \
                type(self.inputs['matrix'].links[0].from_socket) == MatrixSocket:
                propm = SvGetSocketAnyType(self, self.inputs['matrix'])
                cache_viewer_baker[n_id+'m'] = dataCorrect(propm)
            else:
                cache_viewer_baker[n_id+'m'] = []

        else:
            callback_disable(n_id)

        if cache_viewer_baker[n_id+'v'] or cache_viewer_baker[n_id+'m']:
            callback_enable(n_id, cache_viewer_baker[n_id+'v'], cache_viewer_baker[n_id+'ep'], \
                cache_viewer_baker[n_id+'m'], self.Vertex_show, self.color_view.copy(), self.transparant, self.shading)

            self.use_custom_color = True
            self.color = (1, 0.3, 0)
        else:
            self.use_custom_color = True
            self.color = (0.1, 0.05, 0)
            #print ('отражения вершин ',len(cache_viewer_baker['v']), " рёбёры ", len(cache_viewer_baker['ep']), "матрицы",len(cache_viewer_baker['m']))
        if not self.inputs['vertices'].links and not self.inputs['matrix'].links:
            callback_disable(n_id)
Esempio n. 7
0
    def process(self):
        if not (self.id_data.sv_show and self.activate):
            callback_disable(node_id(self))
            return

        n_id = node_id(self)

        global cache_viewer_baker
        vertex_ref = n_id + 'v'
        poledg_ref = n_id + 'ep'
        matrix_ref = n_id + 'm'
        cache_viewer_baker[vertex_ref] = []
        cache_viewer_baker[poledg_ref] = []
        cache_viewer_baker[matrix_ref] = []

        callback_disable(n_id)

        # every time you hit a dot, you pay a price, so alias and benefit
        inputs = self.inputs

        # this should catch accidental connections which otherwise will cause
        # an unrecoverable crash. It might even be an idea to have step in between
        # new connections and processing, it could auto rewire s->s v->v m->m.
        def check_origin(to_socket, socket_type):
            sock_string = sock_dict.get(socket_type)
            return inputs[to_socket].links[0].from_socket.bl_idname == sock_string

        vertex_links = inputs['vertices'].is_linked and check_origin('vertices', 'v')
        matrix_links = inputs['matrix'].is_linked and check_origin('matrix', 'm')
        edgepol_links = inputs['edg_pol'].is_linked and check_origin('edg_pol', 's')

        if (vertex_links or matrix_links):

            if vertex_links:
                propv = inputs['vertices'].sv_get(deepcopy=False, default=[])
                if propv:
                    verts = dataCorrect(propv)
                    for v in verts:
                        if any(l != 3 for l in map(len, v)):
                            raise ValueError
                    cache_viewer_baker[vertex_ref] = verts

            if edgepol_links:
                prope = inputs['edg_pol'].sv_get(deepcopy=False, default=[])
                if prope:
                    cache_viewer_baker[poledg_ref] = dataCorrect(prope)

            if matrix_links:
                propm = inputs['matrix'].sv_get(deepcopy=False, default=[])
                if propm:
                    cache_viewer_baker[matrix_ref] = dataCorrect(propm)

        if cache_viewer_baker[vertex_ref] or cache_viewer_baker[matrix_ref]:
            config_options = self.get_options()
            callback_enable(n_id, cache_viewer_baker, config_options)
Esempio n. 8
0
    def process(self):
        if not self.outputs["data"].is_linked:
            return

        data_ = self.inputs["data"].sv_get()
        data = dataCorrect(data_, nominal_dept=self.level)
        out_ = []
        for obj in data:
            out_.append(svQsort(obj))
        out = dataCorrect(out_)
        self.outputs["data"].sv_set(out)
Esempio n. 9
0
 def execute(self, context):
     global cache_viewer_baker
     nid = node_id(bpy.data.node_groups[self.idtree].nodes[self.idname])
     if cache_viewer_baker[nid + "m"] and not cache_viewer_baker[nid + "v"]:
         return {"CANCELLED"}
     vers = dataCorrect(cache_viewer_baker[nid + "v"])
     edg_pol = dataCorrect(cache_viewer_baker[nid + "ep"])
     if cache_viewer_baker[nid + "m"]:
         matrixes = dataCorrect(cache_viewer_baker[nid + "m"])
     else:
         matrixes = []
         for i in range((len(vers))):
             matrixes.append(Matrix())
     self.makeobjects(vers, edg_pol, matrixes)
     return {"FINISHED"}
Esempio n. 10
0
    def process(self):
        # check if running during startup, cancel if True
        try:
            l = bpy.data.node_groups[self.id_data.name]
        except Exception as e:
            print("Bakery cannot run during startup", e)
            return

        if self.inputs['vertices'].links and self.inputs['edg_pol'].links and self.activate:
            if 'vertices' in self.inputs and self.inputs['vertices'].links and \
                    type(self.inputs['vertices'].links[0].from_socket) == VerticesSocket:
                propv = SvGetSocketAnyType(self, self.inputs['vertices'])
                vertices = dataCorrect(propv, nominal_dept=2)
            else:
                vertices = []

            if 'edg_pol' in self.inputs and self.inputs['edg_pol'].links and \
                    type(self.inputs['edg_pol'].links[0].from_socket) == StringsSocket:
                prope = SvGetSocketAnyType(self, self.inputs['edg_pol'])
                edges = dataCorrect(prope)
            else:
                edges = []

            if 'matrix' in self.inputs and self.inputs['matrix'].links and \
                    type(self.inputs['matrix'].links[0].from_socket) == MatrixSocket:
                propm = SvGetSocketAnyType(self, self.inputs['matrix'])
                matrices = dataCorrect(propm)
            else:
                matrices = []
                if vertices and edges:
                    for i in vertices:
                        matrices.append(Matrix())

            if vertices and edges:
                self.makeobjects(vertices, edges, matrices)
            self.use_custom_color = True
            self.color = (1, 0.3, 0)
        else:
            self.use_custom_color = True
            self.color = (0.1, 0.05, 0)

            for obj in bpy.context.scene.objects:
                nam = 'Sv_' + self.name
                if nam in obj.name:
                    bpy.context.scene.objects[obj.name].select = True
                    bpy.ops.object.delete(use_global=False)
            global sverchok_bakery_cache
            sverchok_bakery_cache[self.name] = []
Esempio n. 11
0
    def process(self):
        verts_socket, polys_socket = self.inputs
        vol_socket = self.outputs[0]

        if vol_socket.is_linked and verts_socket.is_linked:  # and polys_socket.is_linked ?

            vertices = Vector_generate(dataCorrect(verts_socket.sv_get()))
            faces = dataCorrect(polys_socket.sv_get())

            out = []
            for verts_obj, faces_obj in zip(vertices, faces):
                bm = bmesh_from_pydata(verts_obj, [], faces_obj, normal_update=True)
                out.append(bm.calc_volume())
                bm.free()
 
            vol_socket.sv_set(out)
Esempio n. 12
0
 def process(self):
     if not self.outputs[0].is_linked:
         return
     X_ = self.inputs['pols'].sv_get()
     X = dataCorrect(X_)
     result = pols_edges(X, self.unique_edges)
     self.outputs['edgs'].sv_set(result)
Esempio n. 13
0
    def process(self):
        """
        colorsys.rgb_to_yiq(r, g, b)
        colorsys.yiq_to_rgb(y, i, q)
        colorsys.rgb_to_hls(r, g, b)
        colorsys.hls_to_rgb(h, l, s)
        colorsys.rgb_to_hsv(r, g, b)
        colorsys.hsv_to_rgb(h, s, v)
        """

        color_input = self.inputs['Colors']
        if color_input.is_linked:
            abc = self.inputs['Colors'].sv_get()
            data = dataCorrect(abc)
        else:
            data = [[self.unit_color[:]]]

        A, B, C, D = [], [], [], []
        if self.use_alpha:
            for obj in data:
                a_, b_, c_, d_ = (list(x) for x in zip(*obj))
                A.append(a_)
                B.append(b_)
                C.append(c_)
                D.append(d_)
            for i, socket in enumerate(self.outputs):
                self.outputs[socket.name].sv_set([A, B, C, D][i])
        else:
            for obj in data:
                a_, b_, c_ = (list(x) for x in zip(*obj))
                A.append(a_)
                B.append(b_)
                C.append(c_)
            for i, socket in enumerate(self.outputs[:3]):
                self.outputs[socket.name].sv_set([A, B, C][i])
Esempio n. 14
0
    def process(self):
        if not any(s.is_linked for s in self.outputs):
            return

        if self.inputs['Vertices'].is_linked:
            verts = self.inputs['Vertices'].sv_get()
            verts = dataCorrect(verts)
            t_ins = self.inputs['Interval'].sv_get()
            verts_out = []
            for v, t_in in zip(verts, repeat_last(t_ins)):
                pts = np.array(v).T
                tmp = np.apply_along_axis(np.linalg.norm, 0, pts[:, :-1]-pts[:, 1:])
                t = np.insert(tmp, 0, 0).cumsum()
                t = t/t[-1]
                t_corr = [min(1, max(t_c, 0)) for t_c in t_in]
                # this should also be numpy
                if self.mode == 'LIN':
                    out = [np.interp(t_corr, t, pts[i]) for i in range(3)]
                    verts_out.append(list(zip(*out)))
                else:  # SPL
                    spl = cubic_spline(v, t)
                    out = eval_spline(spl, t, t_corr)
                    verts_out.append(out)

            self.outputs['Vertices'].sv_set(verts_out)
Esempio n. 15
0
    def process(self):
        if not any(s.is_linked for s in self.outputs):
            return

        if self.inputs['Vertices'].is_linked:
            verts = self.inputs['Vertices'].sv_get()
            verts = dataCorrect(verts)
            t_ins_x = self.inputs['IntervalX'].sv_get()
            t_ins_y = self.inputs['IntervalY'].sv_get()

            if self.regime == 'P' and self.direction == 'U':
                self.direction = 'UV'
            if self.defgrid:
                t_ins_x = [[i/10 for i in range(11)]]
                t_ins_y = [[i/10 for i in range(11)]]
            if self.regime == 'G':
                vertsX = self.interpol(verts, t_ins_x)
                if self.direction == 'UV':
                    verts_T = np.swapaxes(np.array(vertsX),0,1).tolist()
                    verts_out = self.interpol(verts_T, t_ins_y)

                else:
                    verts_out = vertsX
            else:
                verts_out_ = []
                for x,y in zip(t_ins_x[0],t_ins_y[0]):
                    vertsX = self.interpol(verts, [[x]])
                    verts_T = np.swapaxes(np.array(vertsX),0,1).tolist()
                    vertsY = self.interpol(verts_T, [[y]])
                    verts_out_.extend(vertsY)

                verts_out = [[i[0] for i in verts_out_]]
            self.outputs['Vertices'].sv_set(verts_out)
Esempio n. 16
0
 def process(self):
     if self.inputs['data'].is_linked and self.outputs['data'].is_linked:
         outEval = SvGetSocketAnyType(self, self.inputs['data'])
         outCorr = dataCorrect(outEval)  # this is bullshit, as max 3 in levels
         levels = self.level-1
         out = self.flip(outCorr, levels)
         SvSetSocketAnyType(self, 'data', out)
Esempio n. 17
0
 def get_corrected_data(self, socket_name, socket_type):
     inputs = self.inputs
     socket = inputs[socket_name].links[0].from_socket
     if isinstance(socket, socket_type):
         return dataCorrect(inputs[socket_name].sv_get())
     else:
         return []
Esempio n. 18
0
    def get_input_or_default(self, name, this_val, fparams):
        """ fill up the fparams list with found or default values """
        socket = self.inputs[name]

        # this deals with incoming links only.
        if socket.links:
            if isinstance(this_val, list):
                try:
                    this_val = socket.sv_get()
                    this_val = dataCorrect(this_val)
                except:
                    pass
            elif isinstance(this_val, (int, float)):
                try:
                    k = str(socket.sv_get())
                    kfree = k[2:-2]
                    this_val = ast.literal_eval(kfree)
                    # this_val = socket.sv_get()[0][0]
                except:
                    pass

        # this catches movement on UI sliders.
        elif isinstance(this_val, (int, float)):
            # extra pussyfooting for the load sequence.
            t = socket.sv_get()
            if t and t[0] and t[0][0]:
                this_val = t[0][0]

        # either found input, or uses default.
        fparams.append(this_val)
Esempio n. 19
0
    def process(self):
        verts_socket, polys_socket = self.inputs
        vol_socket = self.outputs[0]

        if vol_socket.is_linked and verts_socket.is_linked:  # and polys_socket.is_linked ?

            vertices = Vector_generate(dataCorrect(verts_socket.sv_get()))
            faces = dataCorrect(polys_socket.sv_get())

            out = []
            for verts_obj, faces_obj in zip(vertices, faces):
                bm = bmesh_from_pydata(verts_obj, [], faces_obj, normal_update=True)
                out.append(bm.calc_volume())
                bm.free()
 
            vol_socket.sv_set(out)
Esempio n. 20
0
 def get_corrected_data(self, socket_name, socket_type):
     inputs = self.inputs
     socket = inputs[socket_name].links[0].from_socket
     if isinstance(socket, socket_type):
         socket_in = SvGetSocketAnyType(self, inputs[socket_name])
         return dataCorrect(socket_in)
     else:
         return []
Esempio n. 21
0
 def meta_get(self, s_name, fallback, level):
     '''
     private function for the get_input function, accepts level 0..2
     - if socket has no links, then return fallback value
     - s_name can be an index instead of socket name
     '''
     inputs = self.inputs
     if inputs[s_name].is_linked:
         socket_in = inputs[s_name].sv_get()
         if level == 1:
             data = dataCorrect(socket_in)[0]
         elif level == 2:
             data = dataCorrect(socket_in)[0][0]
         else:
             data = dataCorrect(socket_in)
         return data
     else:
         return fallback
Esempio n. 22
0
    def process(self):
        if not self.outputs['data'].is_linked:
            return

        data_ = self.inputs['data'].sv_get()
        data = dataCorrect(data_, nominal_dept=self.level).copy()
        out_ = []
        if not self.inputs['keys'].is_linked:
            for obj in data:
                out_.append(svQsort(obj))
        else:
            keys_ = self.inputs['keys'].sv_get()
            keys = dataCorrect(keys_, nominal_dept=1)
            for d,k in zip(data,keys):
                d.sort(key = lambda x: k.pop(0))
                out_.append(d)
        out = dataCorrect(out_)
        self.outputs['data'].sv_set(out)
 def process(self):
     if 'edgs' in self.outputs and len(self.outputs['edgs'].links) > 0:
         if 'pols' in self.inputs and len(self.inputs['pols'].links) > 0:
             X_ = SvGetSocketAnyType(self, self.inputs['pols'])
             X = dataCorrect(X_)
             #print('p2e-X',str(X))
             result = self.pols_edges(X)
             #result = self.polstoedgs(X)
             SvSetSocketAnyType(self, 'edgs', result)
Esempio n. 24
0
    def process(self):

        if self.outputs['Volume'].is_linked and self.inputs['Vers'].is_linked:
            vertices = Vector_generate(dataCorrect(SvGetSocketAnyType(self, self.inputs['Vers'])))
            faces = dataCorrect(SvGetSocketAnyType(self, self.inputs['Pols']))
            out = []
            for verts_obj, faces_obj in zip(vertices, faces):
                # this is for one object
                bme = bmesh_from_pydata(verts_obj, [], faces_obj)
                geom_in = bme.verts[:]+bme.edges[:]+bme.faces[:]
                bmesh.ops.recalc_face_normals(bme, faces=bme.faces[:])
                # calculation itself
                out.append(bme.calc_volume())
                bme.clear()
                bme.free()
                
            if self.outputs['Volume'].is_linked:
                SvSetSocketAnyType(self, 'Volume', out)
Esempio n. 25
0
    def process(self):
        if not (self.id_data.sv_show and self.activate):
            callback_disable(node_id(self))
            return

        n_id = node_id(self)

        global cache_viewer_baker
        vertex_ref = n_id + 'v'
        poledg_ref = n_id + 'ep'
        matrix_ref = n_id + 'm'
        cache_viewer_baker[vertex_ref] = []
        cache_viewer_baker[poledg_ref] = []
        cache_viewer_baker[matrix_ref] = []

        callback_disable(n_id)

        # every time you hit a dot, you pay a price, so alias and benefit
        inputs = self.inputs

        vertex_links = inputs['vertices'].is_linked
        matrix_links = inputs['matrix'].is_linked
        edgepol_links = inputs['edg_pol'].is_linked

        if vertex_links or matrix_links:

            if vertex_links:
                propv = inputs['vertices'].sv_get(deepcopy=False, default=[])
                if propv:
                    cache_viewer_baker[vertex_ref] = dataCorrect(propv)

            if edgepol_links:
                prope = inputs['edg_pol'].sv_get(deepcopy=False, default=[])
                if prope:
                    cache_viewer_baker[poledg_ref] = dataCorrect(prope)

            if matrix_links:
                propm = inputs['matrix'].sv_get(deepcopy=False, default=[])
                if propm:
                    cache_viewer_baker[matrix_ref] = dataCorrect(propm)

        if cache_viewer_baker[vertex_ref] or cache_viewer_baker[matrix_ref]:
            config_options = self.get_options()
            callback_enable(n_id, cache_viewer_baker, config_options)
Esempio n. 26
0
    def update(self):
        # multisocket - from util(formula node)
        multi_socket(self, min=2)

        if 'x0' in self.inputs and len(self.inputs['x0'].links) > 0:
            # adaptive socket - from util(mask list node)
            inputsocketname = self.inputs[
                0].name  # is you need x0 to define socket type - set 0 to 1
            outputsocketname = [
                'data',
            ]
            changable_sockets(self, inputsocketname, outputsocketname)

        if 'data' in self.outputs and len(self.outputs['data'].links) > 0:
            if 'x0' in self.inputs and len(self.inputs['x0'].links) > 0:
                # get any type socket from input:
                X = SvGetSocketAnyType(self, self.inputs['data'])
                slots = []
                for socket in self.inputs:
                    if socket.links:
                        slots.append(SvGetSocketAnyType(self, socket))

                # determine if you have enough inputs for make output
                # if not return
                # examples: all but last (last is never connected)
                # len(slots) == len(self.inputs)-1
                # if more than 2 etc.

                if len(slots) < 2:
                    return

                # Process data
                X_ = dataCorrect(X)
                result = []
                for socket in slots:
                    result.extend(self.f(X_, dataCorrect(socket)))

                # how to assign correct property to adaptive output:
                # in nearest future with socket's data' dictionary we will send
                # only node_name+layout_name+socket_name in str() format
                # and will make separate definition to easyly assign and
                # get and recognise data from dictionary
                SvSetSocketAnyType(self, 'data', result)
Esempio n. 27
0
 def get_data(name, fallback=[]):
     TypeSocket = get_socket_type(name)
     if has_good_link(name, TypeSocket):
         d = dataCorrect(inputs[name].sv_get())
         if name == 'matrix':
             d = Matrix_generate(d) if d else []
         elif name == 'vertices':
             d = Vector_generate(d) if d else []
         return d
     return fallback
Esempio n. 28
0
    def process(self):
        verts_socket, polys_socket = self.inputs
        vol_socket = self.outputs[0]

        if vol_socket.is_linked and verts_socket.is_linked:  # and polys_socket.is_linked ?

            vertices = Vector_generate(dataCorrect(verts_socket.sv_get()))
            faces = dataCorrect(polys_socket.sv_get())

            out = []
            for verts_obj, faces_obj in zip(vertices, faces):
                # this is for one object
                bm = bmesh_from_pydata(verts_obj, [], faces_obj)
                # geom_in = bm.verts[:] + bm.edges[:] + bm.faces[:]
                bmesh.ops.recalc_face_normals(bm, faces=bm.faces[:])
                out.append(bm.calc_volume())
                bm.clear()
                bm.free()
 
            vol_socket.sv_set(out)
Esempio n. 29
0
    def process(self):
        if self.inputs['X'].is_linked:
            vecs = SvGetSocketAnyType(self, self.inputs['X'])
        else:
            vecs = [[0.0]]


        # outputs
        if not self.outputs['Result'].is_linked:
            return
        
        list_mult = []
        if self.inputs['n[0]'].is_linked:
            i = 0
            for socket in self.inputs[1:]:
                if socket.is_linked:
                    list_mult.append(SvGetSocketAnyType(self, socket))
            #print(list_mult)
        code_formula = parser.expr(self.formula).compile()
        # finding nasty levels, make equal nastyness (canonical 0,1,2,3)
        levels = [levelsOflist(vecs)]
        for n in list_mult:
            levels.append(levelsOflist(n))
        maxlevel = max(max(levels), 3)
        diflevel = maxlevel - levels[0]

        if diflevel:
            vecs_ = dataSpoil([vecs], diflevel-1)
            vecs = dataCorrect(vecs_, nominal_dept=2)
        for i, lev in enumerate(levels):
            if i == 0:
                continue
            diflevel = maxlevel-lev
            if diflevel:
                list_temp = dataSpoil([list_mult[i-1]], diflevel-1)
                list_mult[i-1] = dataCorrect(list_temp, nominal_dept=2)
        #print(list_mult)
        r = self.inte(vecs, code_formula, list_mult, 3)
        result = dataCorrect(r, nominal_dept=min((levels[0]-1), 2))

        SvSetSocketAnyType(self, 'Result', result)
Esempio n. 30
0
    def process(self):
        if not self.inputs[1] and not self.inputs[1].is_linked:
            return

        matrices = dataCorrect(self.inputs[0].sv_get())
        objects = self.inputs[1].sv_get()
        matrices, objects = match_long_repeat([matrices, objects])
        for obj, mat in zip(objects, matrices):
            setattr(obj, 'matrix_world', mat)

        if self.outputs[0].is_linked:
            self.outputs[0].sv_set(objects)
Esempio n. 31
0
    def process(self):
        if not any((s.is_linked for s in self.outputs)):
            return
        if self.inputs['Vertices'].is_linked and self.inputs['Poly Egde'].is_linked:
            verts = SvGetSocketAnyType(self, self.inputs['Vertices'])
            poly = SvGetSocketAnyType(self, self.inputs['Poly Egde'])
            verts = dataCorrect(verts)
            poly = dataCorrect(poly)
            if self.inputs['Mask'].is_linked:
                mask = SvGetSocketAnyType(self, self.inputs['Mask'])
            else:
                mask = [[1, 0]]
            has_true_out = True
            has_false_out = False
            verts_out = []
            poly_edge_out = []
            for ve, pe, ma in zip(verts, poly, repeat_last(mask)):
                current_mask = islice(cycle(ma), len(ve))
                vert_index = [i for i, m in enumerate(current_mask) if m]
                if len(vert_index) < len(ve):
                    index_set = set(vert_index)
                    if has_true_out:
                        vert_dict = {j: i for i, j in enumerate(vert_index)}
                        new_vert = [ve[i] for i in vert_index]
                        is_ss = index_set.issuperset
                        new_pe = [[vert_dict[n] for n in fe]
                                  for fe in pe if is_ss(fe)]
                        verts_out.append(new_vert)
                        poly_edge_out.append(new_pe)

                else:  # no reprocessing needed
                    verts_out.append(ve)
                    poly_edge_out.append(pe)

            if 'Vertices' in self.outputs and self.outputs['Vertices'].is_linked:
                SvSetSocketAnyType(self, 'Vertices', verts_out)

            if 'Poly Egde' in self.outputs and self.outputs['Poly Egde'].is_linked:
                if poly_edge_out:
                    SvSetSocketAnyType(self, 'Poly Egde', poly_edge_out)
Esempio n. 32
0
    def update(self):
        # multisocket - from util(formula node)
        multi_socket(self, min=2)

        if 'x0' in self.inputs and len(self.inputs['x0'].links) > 0:
            # adaptive socket - from util(mask list node)
            inputsocketname = self.inputs[0].name  # is you need x0 to define socket type - set 0 to 1
            outputsocketname = ['data', ]
            changable_sockets(self, inputsocketname, outputsocketname)

        if 'data' in self.outputs and len(self.outputs['data'].links) > 0:
            if 'x0' in self.inputs and len(self.inputs['x0'].links) > 0:
                # get any type socket from input:
                X = SvGetSocketAnyType(self, self.inputs['data'])
                slots = []
                for socket in self.inputs:
                    if socket.links:
                        slots.append(SvGetSocketAnyType(self, socket))

                # determine if you have enough inputs for make output
                # if not return
                # examples: all but last (last is never connected)
                # len(slots) == len(self.inputs)-1
                # if more than 2 etc.

                if len(slots) < 2:
                    return

                # Process data
                X_ = dataCorrect(X)
                result = []
                for socket in slots:
                    result.extend(self.f(X_, dataCorrect(socket)))

                # how to assign correct property to adaptive output:
                # in nearest future with socket's data' dictionary we will send
                # only node_name+layout_name+socket_name in str() format
                # and will make separate definition to easyly assign and
                # get and recognise data from dictionary
                SvSetSocketAnyType(self, 'data', result)
Esempio n. 33
0
    def process(self):
        # inputs
        if not self.outputs["Vectors"].is_linked:
            return

        vecs_ = self.inputs["Vectors"].sv_get()
        vecs = Vector_generate(vecs_)

        mats_ = dataCorrect(self.inputs["Matrixes"].sv_get())
        mats = Matrix_generate(mats_)

        vectors = self.vecscorrect(vecs, mats)
        self.outputs["Vectors"].sv_set(vectors)
Esempio n. 34
0
    def process(self):
        if not self.inputs['Vertices'].is_linked:
            return
        if not any([s.is_linked for s in self.outputs]):
            return
        has_mat_out = bool(self.outputs['Center'].is_linked)
        has_mean = bool(self.outputs['Mean'].is_linked)
        has_vert_out = bool(self.outputs['Vertices'].is_linked)
        vert = SvGetSocketAnyType(self, self.inputs['Vertices'])
        vert = dataCorrect(vert, nominal_dept=2)

        if vert:
            verts_out = []
            edges_out = []
            edges = [
                (0, 1), (1, 3), (3, 2), (2, 0),  # bottom edges
                (4, 5), (5, 7), (7, 6), (6, 4),  # top edges
                (0, 4), (1, 5), (2, 6), (3, 7)  # sides
            ]
            mat_out = []
            mean_out = []

            for v in vert:
                if has_mat_out or has_vert_out:
                    maxmin = list(zip(map(max, *v), map(min, *v)))
                    out = list(product(*reversed(maxmin)))
                    verts_out.append([l[::-1] for l in out[::-1]])
                edges_out.append(edges)
                if has_mat_out:
                    center = [(u+v)*.5 for u, v in maxmin]
                    mat = Matrix.Translation(center)
                    scale = [(u-v)*.5 for u, v in maxmin]
                    for i, s in enumerate(scale):
                        mat[i][i] = s
                    mat_out.append(mat)
                if has_mean:
                    avr = list(map(sum, zip(*v)))
                    avr = [n/len(v) for n in avr]
                    mean_out.append([avr])

            if self.outputs['Vertices'].is_linked:
                SvSetSocketAnyType(self, 'Vertices', verts_out)

            if self.outputs['Edges'].is_linked:
                SvSetSocketAnyType(self, 'Edges', edges_out)

            if self.outputs['Mean'].is_linked:
                SvSetSocketAnyType(self, 'Mean', mean_out)

            if self.outputs['Center'].is_linked:
                SvSetSocketAnyType(self, 'Center', Matrix_listing(mat_out))
Esempio n. 35
0
    def process(self):

        if not (self.inputs['vertices'].is_linked and self.inputs['edges'].is_linked):
            return

        verts = dataCorrect(self.inputs['vertices'].sv_get())
        edges = dataCorrect(self.inputs['edges'].sv_get())
        sides = repeat_last(self.inputs['Sides'].sv_get()[0])
        verts_out = []
        edges_out = []
        polys_out = []

        for v, e, s in zip(verts, edges, sides):
            res = fill_holes(v, e, int(s))
            if not res:
                return
            verts_out.append(res[0])
            edges_out.append(res[1])
            polys_out.append(res[2])

        self.outputs['vertices'].sv_set(verts_out)
        self.outputs['edges'].sv_set(edges_out)
        self.outputs['polygons'].sv_set(polys_out)