Ejemplo n.º 1
0
    def update(self):
        # inputs
        if 'vertices' in self.inputs and self.inputs['vertices'].links and \
           type(self.inputs['vertices'].links[0].from_socket) == VerticesSocket:
            vers_ = SvGetSocketAnyType(self, self.inputs['vertices'])
            vers = Vector_generate(vers_)
        else:
            vers = []

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

            vecs_ = SvGetSocketAnyType(self, self.inputs['vectors'])
            vecs = Vector_generate(vecs_)
        else:
            vecs = []

        if 'multiplier' in self.inputs and self.inputs['multiplier'].links and \
           type(self.inputs['multiplier'].links[0].from_socket) == StringsSocket:

            mult = SvGetSocketAnyType(self, self.inputs['multiplier'])
        else:
            mult = [[self.mult_]]

        # outputs
        if 'vertices' in self.outputs and self.outputs['vertices'].links:
            mov = self.moved(vers, vecs, mult)
            SvSetSocketAnyType(self, 'vertices', mov)
Ejemplo n.º 2
0
    def update(self):
        for name in ['vertices1', 'vertices2', 'matrix1', 'matrix2']:
            if name not in self.inputs:
                return

        if self.inputs['vertices1'].links and self.inputs['vertices2'].links:
            prop1_ = SvGetSocketAnyType(self, self.inputs['vertices1'])
            prop1 = Vector_generate(prop1_)
            prop2_ = SvGetSocketAnyType(self, self.inputs['vertices2'])
            prop2 = Vector_generate(prop2_)

        elif self.inputs['matrix1'].links and self.inputs['matrix2'].links:
            propa = SvGetSocketAnyType(self, self.inputs['matrix1'])
            prop1 = Matrix_location(Matrix_generate(propa))
            propb = SvGetSocketAnyType(self, self.inputs['matrix2'])
            prop2 = Matrix_location(Matrix_generate(propb))
        else:
            prop1, prop2 = [], []

        if prop1 and prop2:
            if self.outputs['distances'].links:
                #print ('distances input', str(prop1), str(prop2))
                if self.Cross_dist:
                    output = self.calcM(prop1, prop2)
                else:
                    output = self.calcV(prop1, prop2)
                SvSetSocketAnyType(self, 'distances', output)

                #print ('distances out' , str(output))
        else:
            SvSetSocketAnyType(self, 'distances', [])
Ejemplo n.º 3
0
    def update(self):
        if not 'Edges' in self.outputs:
            return
        if not all((s.links for s in self.inputs)):
            return
        if not any((s.links for s in self.outputs)):
            return

        versR = Vector_generate(SvGetSocketAnyType(self, self.inputs['VersR']))
        versD = Vector_generate(SvGetSocketAnyType(self, self.inputs['VersD']))
        edgeR = SvGetSocketAnyType(self, self.inputs['EdgeR'])
        edgeD = SvGetSocketAnyType(self, self.inputs['EdgeD'])
        verts_out = []
        edges_out = []
        mesh_join = self.mesh_join
        # only first obj
        verD = [v - versD[0][0] for v in versD[0]]
        edgD = edgeD[0]
        d_vector = verD[-1].copy()
        d_scale = d_vector.length
        d_vector.normalize()
        for vc, edg in zip(versR, edgeR):
            if mesh_join:
                v_out = []
                v_out_app = v_out.append
            e_out = []
            e_out_app = e_out.append

            for e in edg:
                if not mesh_join:
                    v_out = []
                    v_out_app = v_out.append
                e_vector = vc[e[1]] - vc[e[0]]
                e_scale = e_vector.length
                e_vector.normalize()
                q1 = d_vector.rotation_difference(e_vector)
                mat_s = Matrix.Scale(e_scale / d_scale, 4)
                mat_r = Matrix.Rotation(q1.angle, 4, q1.axis)
                mat_l = Matrix.Translation(vc[e[0]])
                mat = mat_l * mat_r * mat_s

                offset = len(v_out)
                for v in verD:
                    v_out_app((mat * v)[:])
                if mesh_join:
                    for edge in edgD:
                        e_out_app([i + offset for i in edge])
                else:
                    verts_out.append(v_out)
                    edges_out.append(edgD)
            if mesh_join:
                verts_out.append(v_out)
                edges_out.append(e_out)

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

        if 'Edges' in self.outputs and self.outputs['Edges'].links:
            SvSetSocketAnyType(self, 'Edges', edges_out)
Ejemplo n.º 4
0
    def update(self):
        # inputs
        if 'Matrix' in self.outputs and self.outputs['Matrix'].links:
            if self.inputs['Original'].links and \
               type(self.inputs['Original'].links[0].from_socket) == MatrixSocket:

                orig_ = SvGetSocketAnyType(self, self.inputs['Original'])
                orig = Matrix_generate(orig_)
            else:
                return

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

                loc_ = SvGetSocketAnyType(self, self.inputs['Location'])
                loc = Vector_generate(loc_)
            else:
                loc = [[]]

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

                scale_ = SvGetSocketAnyType(self, self.inputs['Scale'])
                scale = Vector_generate(scale_)
            else:
                scale = [[]]

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

                rot_ = SvGetSocketAnyType(self, self.inputs['Rotation'])
                rot = Vector_generate(rot_)
                #print ('matrix_def', str(rot_))
            else:
                rot = [[]]

            rotA = [[]]
            angle = [[0.0]]
            if 'Angle' in self.inputs and self.inputs['Angle'].links:

                if type(self.inputs['Angle'].links[0].from_socket
                        ) == StringsSocket:
                    angle = SvGetSocketAnyType(self, self.inputs['Angle'])

                elif type(self.inputs['Angle'].links[0].from_socket
                          ) == VerticesSocket:
                    rotA_ = SvGetSocketAnyType(self, self.inputs['Angle'])
                    rotA = Vector_generate(rotA_)

            # outputs
            #print(loc)
            matrixes_ = matrixdef(orig, loc, scale, rot, angle, rotA)
            matrixes = Matrix_listing(matrixes_)
            SvSetSocketAnyType(self, 'Matrix', matrixes)
Ejemplo n.º 5
0
    def update(self):
        # inputs
        if 'Location' in self.inputs and self.inputs['Location'].links and \
           type(self.inputs['Location'].links[0].from_socket) == VerticesSocket:

            loc_ = SvGetSocketAnyType(self, self.inputs['Location'])
            loc = Vector_generate(loc_)
        else:
            loc = [[]]

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

            scale_ = SvGetSocketAnyType(self, self.inputs['Scale'])
            scale = Vector_generate(scale_)
        else:
            scale = [[]]

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

            rot_ = SvGetSocketAnyType(self, self.inputs['Rotation'])
            rot = Vector_generate(rot_)
            #print ('matrix_def', str(rot_))
        else:
            rot = [[]]

        rotA = [[]]
        angle = [[0.0]]
        if 'Angle' in self.inputs and self.inputs['Angle'].links:
            if type(self.inputs['Angle'].links[0].from_socket
                    ) == StringsSocket:
                angle = SvGetSocketAnyType(self, self.inputs['Angle'])

            elif type(self.inputs['Angle'].links[0].from_socket
                      ) == VerticesSocket:
                rotA_ = SvGetSocketAnyType(self, self.inputs['Angle'])
                rotA = Vector_generate(rotA_)

        # outputs
        if 'Matrix' in self.outputs and self.outputs['Matrix'].links:

            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)
            if len(orig) == 0:
                return
            matrixes_ = matrixdef(orig, loc, scale, rot, angle, rotA)
            matrixes = Matrix_listing(matrixes_)
            SvSetSocketAnyType(self, 'Matrix', matrixes)
Ejemplo n.º 6
0
    def update(self):

        if not self.noise_dict:
            self.noise_dict = {
                t[0]: t[1]
                for t in inspect.getmembers(noise.types)
                if isinstance(t[1], int)
            }

        if self.outputs and not self.outputs[0].links:
            return

        if 'Vertices' in self.inputs and self.inputs['Vertices'].links:

            verts = Vector_generate(
                SvGetSocketAnyType(self, self.inputs['Vertices']))
            out = []
            n_t = self.noise_dict[self.noise_type]
            n_f = self.noise_f[self.out_mode]

            for obj in verts:
                out.append([n_f(v, n_t) for v in obj])

            if 'Noise V' in self.outputs and self.outputs['Noise V'].links:
                SvSetSocketAnyType(self, 'Noise V', Vector_degenerate(out))

            if 'Noise S' in self.outputs and self.outputs['Noise S'].links:
                SvSetSocketAnyType(self, 'Noise S', out)
            return

        SvSetSocketAnyType(self, self.outputs[0].name, [[]])
Ejemplo n.º 7
0
    def update(self):
        # inputs
        if 'Vectors' in self.outputs and len(
                self.outputs['Vectors'].links) > 0:
            if self.inputs['Vectors'].links and \
                    type(self.inputs['Vectors'].links[0].from_socket) == VerticesSocket \
                    and self.inputs['Matrixes'] and \
                    type(self.inputs['Matrixes'].links[0].from_socket) == MatrixSocket:

                vecs_ = SvGetSocketAnyType(self, self.inputs['Vectors'])

                vecs = Vector_generate(vecs_)
                #print (vecs)

                mats_ = dataCorrect(
                    SvGetSocketAnyType(self, self.inputs['Matrixes']))
                mats = Matrix_generate(mats_)
            else:
                vecs = [[]]
                mats = [Matrix()]

            # outputs

            vectors_ = self.vecscorrect(vecs, mats)
            vectors = Vector_degenerate(vectors_)
            SvSetSocketAnyType(self, 'Vectors', vectors)
Ejemplo n.º 8
0
def sv_main(vec=[], pol=[], iter=3):

    in_sockets = [['v', 'vec', vec], ['s', 'pol', pol], ['s', 'iter', iter]]

    if not vec: vec = [[[0, 1, 1], [0, 2, 2], [3, 3, 0]]]
    if not pol: pol = [[[0, 1, 2]]]
    vec_gen = Vector_generate(vec)

    def fractalize(vec_gen, pol, iter):
        out = []
        if iter:
            print(vec_gen, iter)
            vers_new = []
            for obj in vec_gen:
                for v1 in obj:
                    up = [v1 / 2 + v2 / 2 for v2 in vec_gen[0]]
                    vers_new.append(up)
            #print(levelsOflist(vec_gen))
            #pols_new =[[vec[p] for p in objpol] for objpol in pol]
            out = fractalize(vers_new, pol, iter - 1)
        else:
            out = dataCorrect(vec_gen, 1)
        #print(out)
        return out

    out_ = fractalize(vec_gen, pol, iter)
    out = Vector_degenerate(out_)
    #print(out)

    out_sockets = [['v', 'vec', out]]

    return in_sockets, out_sockets
Ejemplo n.º 9
0
    def makeobjects(self, vers, edg_pol, mats):
        # inception
        # fht = предохранитель от перебора рёбер и полигонов.
        fht = []
        if len(edg_pol[0][0]) == 2:
            pols = []
            for edgs in edg_pol:
                maxi = max(max(a) for a in edgs)
                fht.append(maxi)
                #print (maxi)
        elif len(edg_pol[0][0]) > 2:
            edgs = []
            for pols in edg_pol:
                maxi = max(max(a) for a in pols)
                fht.append(maxi)
                #print (maxi)
        #print (fht)
        vertices = Vector_generate(vers)
        matrixes = Matrix_generate(mats)
        #print('mats' + str(matrixes))
        objects = {}
        fhtagn = []
        for u, f in enumerate(fht):
            fhtagn.append(min(len(vertices[u]), fht[u]))
        #lenmesh = len(vertices) - 1
        #print ('запекание вершин ', vertices, " матрицы запекашка ", matrixes, " полиглоты ", edg_pol)
        #print (matrixes)
        for i, m in enumerate(matrixes):
            k = i
            lenver = len(vertices) - 1
            if i > lenver:
                v = vertices[-1]
                k = lenver
            else:
                v = vertices[k]
            #print (fhtagn, len(v)-1)
            if (len(v)-1) < fhtagn[k]:
                continue
            # возможно такая сложность не нужна, но пусть лежит тут. Удалять лишние точки не обязательно.
            elif fhtagn[k] < (len(v)-1):
                nonneed = (len(v)-1) - fhtagn[k]
                for q in range(nonneed):
                    v.pop((fhtagn[k]+1))
                #print (fhtagn[k], (len(v)-1))

            e = edg_pol[k] if edgs else []
            p = edg_pol[k] if pols else []

            objects[str(i)] = self.makemesh(i, v, e, p, m)
        for ite in objects.values():
            me = ite[1]
            ob = ite[0]
            calcedg = True
            if edgs:
                calcedg = False
            me.update(calc_edges=calcedg)
            bpy.context.scene.objects.link(ob)
Ejemplo n.º 10
0
 def get_data(name, fallback=[]):
     TypeSocket = get_socket_type(name)
     if has_good_link(name, TypeSocket):
         d = dataCorrect(SvGetSocketAnyType(node, inputs[name]))
         if name == 'matrix':
             d = Matrix_generate(d) if d else []
         elif name == 'vertices':
             d = Vector_generate(d) if d else []
         return d
     return fallback
Ejemplo n.º 11
0
    def update(self):
        if 'vertices' in self.inputs and self.inputs['vertices'].links \
           and self.inputs['edg_pol'].links \
           and self.inputs['cut_matrix'].links:

            verts_ob = Vector_generate(
                SvGetSocketAnyType(self, self.inputs['vertices']))
            edg_pols_ob = SvGetSocketAnyType(self, self.inputs['edg_pol'])

            if self.inputs['matrix'].links:

                matrixs = SvGetSocketAnyType(self, self.inputs['matrix'])
            else:
                matrixs = []
                for le in verts_ob:
                    matrixs.append(Matrix())
            cut_mats = SvGetSocketAnyType(self, self.inputs['cut_matrix'])

            verts_out = []
            edges_out = []
            for cut_mat in cut_mats:
                cut_mat = Matrix(cut_mat)
                pp = Vector((0.0, 0.0, 0.0)) * cut_mat.transposed()
                pno = Vector((0.0, 0.0, 1.0)) * cut_mat.to_3x3().transposed()

                verts_pre_out = []
                edges_pre_out = []
                for idx_mob, matrix in enumerate(matrixs):
                    idx_vob = min(idx_mob, len(verts_ob) - 1)
                    idx_epob = min(idx_mob, len(edg_pols_ob) - 1)
                    matrix = Matrix(matrix)

                    x_me = section(verts_ob[idx_vob], edg_pols_ob[idx_epob],
                                   matrix, pp, pno, self.fill_check, self.tri)
                    if x_me:
                        verts_pre_out.append(x_me['Verts'])
                        edges_pre_out.append(x_me['Edges'])

                if verts_pre_out:
                    verts_out.extend(verts_pre_out)
                    edges_out.extend(edges_pre_out)

            if 'vertices' in self.outputs and self.outputs['vertices'].links:
                output = Vector_degenerate(verts_out)
                SvSetSocketAnyType(self, 'vertices', output)

            if 'edges' in self.outputs and self.outputs['edges'].links:

                SvSetSocketAnyType(self, 'edges', edges_out)

        else:
            pass
Ejemplo n.º 12
0
    def makeobjects(self, vers, edg_pol, mats):
        try:
            num_keys = len(edg_pol[0][0])
        except:
            num_keys = 0

        vertices = Vector_generate(vers)
        matrixes = Matrix_generate(mats)
        edgs, pols, max_vert_index, fht = [], [], [], []

        if num_keys >= 2:
            for k in edg_pol:
                maxi = max(max(a) for a in k)
                fht.append(maxi)

        for u, f in enumerate(fht):
            max_vert_index.append(min(len(vertices[u]), fht[u]))

        objects = {}
        for i, m in enumerate(matrixes):
            k = i
            lenver = len(vertices) - 1
            if i > lenver:
                v = vertices[-1]
                k = lenver
            else:
                v = vertices[k]

            if max_vert_index:
                if (len(v) - 1) < max_vert_index[k]:
                    continue

                elif max_vert_index[k] < (len(v) - 1):
                    nonneed = (len(v) - 1) - max_vert_index[k]
                    for q in range(nonneed):
                        v.pop((max_vert_index[k] + 1))

            e, p = [], []
            if num_keys == 2:
                e = edg_pol[k]
            elif num_keys > 2:
                p = edg_pol[k]

            objects[str(i)] = self.makemesh(i, v, e, p, m)

        for ob, me in objects.values():
            calcedg = False if (num_keys == 2) else True
            me.update(calc_edges=calcedg)
            bpy.context.scene.objects.link(ob)
Ejemplo n.º 13
0
    def update(self):
        if not 'polygons' in self.outputs:
            return
        if not any((s.links for s in self.outputs)):
            return

        if 'vertices' in self.inputs and self.inputs['vertices'].links and \
           'polygons' in self.inputs and self.inputs['polygons'].links:

            verts = Vector_generate(
                SvGetSocketAnyType(self, self.inputs['vertices']))
            polys = SvGetSocketAnyType(self, self.inputs['polygons'])
            if 'thickness' in self.inputs:
                thickness = self.inputs['thickness'].sv_get()
            else:
                thickness = [[self.thickness]]

            #print (verts,polys)

            verts_out = []
            edges_out = []
            polys_out = []
            newpo_out = []
            fullList(thickness, len(verts))
            for v, p, t in zip(verts, polys, thickness):
                verlen = set(range(len(v)))
                res = soldify(v, p, t, verlen)

                if not res:
                    return
                verts_out.append(res[0])
                edges_out.append(res[1])
                polys_out.append(res[2])
                newpo_out.append(res[3])

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

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

            if 'polygons' in self.outputs and self.outputs['polygons'].links:
                SvSetSocketAnyType(self, 'polygons', polys_out)

            if 'newpols' in self.outputs and self.outputs['newpols'].links:
                SvSetSocketAnyType(self, 'newpols', newpo_out)
Ejemplo n.º 14
0
    def update(self):

        if self.outputs['Volume'].links and self.inputs['Vers'].links:
            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'].links:
                SvSetSocketAnyType(self, 'Volume', out)
Ejemplo n.º 15
0
    def update(self):
        if not any([s.links for s in self.outputs]):
            return

        if 'Vertices' in self.inputs and self.inputs['Vertices'].links and \
           'PolyEdge' in self.inputs and self.inputs['PolyEdge'].links:

            verts = Vector_generate(SvGetSocketAnyType(self, self.inputs['Vertices']))
            polys = SvGetSocketAnyType(self, self.inputs['PolyEdge'])
            if 'Distance' in self.inputs:
                distance = self.inputs['Distance'].sv_get()[0]
            else:
                distance = [self.distance]
            if 'Doubles' in self.outputs:
                has_double_out = bool('Doubles' in self.outputs)

            verts_out = []
            edges_out = []
            polys_out = []
            d_out = []

            for v, p, d in zip(verts, polys, repeat_last(distance)):
                res = remove_doubles(v, p, d, has_double_out)
                if not res:
                    return
                verts_out.append(res[0])
                edges_out.append(res[1])
                polys_out.append(res[2])
                d_out.append(res[3])

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

            if 'Edges' in self.outputs and self.outputs['Edges'].links:
                SvSetSocketAnyType(self, 'Edges', edges_out)

            if 'Polygons' in self.outputs and self.outputs['Polygons'].links:
                SvSetSocketAnyType(self, 'Polygons', polys_out)

            if 'Doubles' in self.outputs and self.outputs['Doubles'].links:
                SvSetSocketAnyType(self, 'Doubles', d_out)
Ejemplo n.º 16
0
    def update(self):

        if 'Vertices' in self.inputs and self.inputs['Vertices'].links:

            verts = Vector_generate(
                SvGetSocketAnyType(self, self.inputs['Vertices']))

            verts_out = []
            polys_out = []

            for v_obj in verts:
                res = make_hull(v_obj)
                if not res:
                    return
                verts_out.append(res[0])
                polys_out.append(res[1])

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

            if 'Polygons' in self.outputs and self.outputs['Polygons'].links:
                SvSetSocketAnyType(self, 'Polygons', polys_out)
Ejemplo n.º 17
0
    def update(self):
        if not ('vertices' in self.outputs and self.outputs['vertices'].links
                or 'edges' in self.outputs and self.outputs['edges'].links or
                'polygons' in self.outputs and self.outputs['polygons'].links):
            return

        if 'vertices' in self.inputs and self.inputs['vertices'].links and \
           'polygons' in self.inputs and self.inputs['polygons'].links:

            verts = Vector_generate(
                SvGetSocketAnyType(self, self.inputs['vertices']))
            polys = SvGetSocketAnyType(self, self.inputs['polygons'])
            if 'thickness' in self.inputs:
                thickness = self.inputs['thickness'].sv_get()[0]
            else:
                thickness = [self.thickness]
            verts_out = []
            edges_out = []
            polys_out = []
            for v, p, t in zip(verts, polys, repeat_last(thickness)):
                res = wireframe(v, p, t, self.offset, self.replace,
                                self.boundary, self.even_offset,
                                self.relative_offset)

                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'].links:
                SvSetSocketAnyType(self, 'vertices', verts_out)

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

            if 'polygons' in self.outputs and self.outputs['polygons'].links:
                SvSetSocketAnyType(self, 'polygons', polys_out)
Ejemplo n.º 18
0
    def update(self):

        if self.outputs['Vers'].links and self.inputs['Vers'].links:
            vertices = Vector_generate(
                SvGetSocketAnyType(self, self.inputs['Vers']))
            faces = SvGetSocketAnyType(self, self.inputs['Pols'])
            offset = self.inputs['Offset'].sv_get()[0]
            nsides = self.inputs['N sides'].sv_get()[0][0]
            radius = self.inputs['Radius'].sv_get()[0]
            #print(radius,nsides,offset)
            outv = []
            oute = []
            outo = []
            outn = []
            for verts_obj, faces_obj in zip(vertices, faces):
                # this is for one object
                fullList(offset, len(faces_obj))
                fullList(radius, len(faces_obj))
                verlen = set(range(len(verts_obj)))
                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[:])
                list_0 = [f.index for f in bme.faces]
                # calculation itself
                result = \
                    self.Offset_pols(bme, list_0, offset, radius, nsides, verlen)
                outv.append(result[0])
                oute.append(result[1])
                outo.append(result[2])
                outn.append(result[3])
            if self.outputs['Vers'].links:
                SvSetSocketAnyType(self, 'Vers', outv)
            if self.outputs['Edgs'].links:
                SvSetSocketAnyType(self, 'Edgs', oute)
            if self.outputs['OutPols'].links:
                SvSetSocketAnyType(self, 'OutPols', outo)
            if self.outputs['InPols'].links:
                SvSetSocketAnyType(self, 'InPols', outn)
Ejemplo n.º 19
0
    def process(self):

        verts = Vector_generate(
            SvGetSocketAnyType(self, self.inputs['Vertices']))
        faces = self.inputs['Polygons'].sv_get()

        if not (len(verts) == len(faces)):
            return

        verts_out = []
        polys_out = []

        for v_obj, f_obj in zip(verts, faces):
            res = join_tris(v_obj, f_obj, self.limit)
            if not res:
                return
            verts_out.append(res[0])
            polys_out.append(res[1])

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

        SvSetSocketAnyType(self, 'Polygons', polys_out)
Ejemplo n.º 20
0
    def update(self):
        # inputs
        if 'Vectors' in self.outputs and self.outputs['Vectors'].links:
            if not ('Vectors' in self.inputs and self.inputs['Vectors'].links):
                return
            if not ('Matrixes' in self.inputs
                    and self.inputs['Matrixes'].links):
                return
            if type(self.inputs['Vectors'].links[0].from_socket) == VerticesSocket and \
               type(self.inputs['Matrixes'].links[0].from_socket) == MatrixSocket:

                vecs_ = SvGetSocketAnyType(self, self.inputs['Vectors'])
                vecs = Vector_generate(vecs_)

                mats_ = SvGetSocketAnyType(self, self.inputs['Matrixes'])
                mats = Matrix_generate(mats_)
            else:
                vecs = [[]]
                mats = [Matrix()]

            # outputs
            vectors_ = self.vecscorrect(vecs, mats)
            vectors = Vector_degenerate(vectors_)
            SvSetSocketAnyType(self, 'Vectors', vectors)
Ejemplo n.º 21
0
    def makeobjects(self, vers, edg_pol, mats):
        # fht = предохранитель от перебора рёбер и полигонов.
        fht = []
        if len(edg_pol[0][0]) == 2:
            pols = []
            for edgs in edg_pol:
                maxi = max(max(a) for a in edgs)
                fht.append(maxi)
        elif len(edg_pol[0][0]) > 2:
            edgs = []
            for pols in edg_pol:
                maxi = max(max(a) for a in pols)
                fht.append(maxi)
        vertices = Vector_generate(vers)
        matrixes = Matrix_generate(mats)
        objects = {}
        fhtagn = []
        for u, f in enumerate(fht):
            fhtagn.append(min(len(vertices[u]), fht[u]))
        #lenmesh = len(vertices) - 1

        # name space for particular bakery node
        # defined only by matrices count (without .001 etc)
        global sverchok_bakery_cache
        try:
            cache = sverchok_bakery_cache[self.name]
        except:
            cache = []
        names = ['Sv_' + self.name + str(i) for i, t in enumerate(mats)]
        #print('bakery'+str(names)+str(cache))

        # delete previous objects удаляет предыдущие объекты, если есть, если надо.
        bpy.ops.object.select_all(action='DESELECT')
        for i, obj in enumerate(bpy.context.scene.objects):
            nam = 'Sv_' + self.name
            if nam in obj.name:
                if obj.name not in names:
                    bpy.context.scene.objects[obj.name].select = True
                    bpy.ops.object.delete(use_global=False)

        for i, m in enumerate(matrixes):
            # solution to reduce number of vertices respect to edges/pols
            ########
            k = i
            lenver = len(vertices) - 1
            if i > lenver:
                v = vertices[-1]
                k = lenver
            else:
                v = vertices[k]
            if (len(v)-1) < fhtagn[k]:
                continue
            elif fhtagn[k] < (len(v)-1):
                nonneed = (len(v)-1) - fhtagn[k]
                for q in range(nonneed):
                    v.pop((fhtagn[k]+1))
            #########
            # end of solution to reduce vertices

            e = edg_pol[k] if edgs else []
            p = edg_pol[k] if pols else []

            # to change old, create new separately
            if names[i] not in cache:
                objects[str(i)] = self.makemesh(names[i], v, e, p, m)
            elif bpy.context.scene.objects.find(names[i]) >= 0:
                objects[str(i)] = self.makemesh_exist(names[i], v, e, p, m)
            else:
                objects[str(i)] = self.makemesh(names[i], v, e, p, m)

        for i, ite in enumerate(objects.values()):
            me = ite[1]
            ob = ite[0]
            calcedg = True
            if edgs:
                calcedg = False
            me.update(calc_edges=calcedg)
            if ob.name not in cache:
                bpy.context.scene.objects.link(ob)

        # save cache
        sverchok_bakery_cache[self.name] = names
Ejemplo n.º 22
0
    def process(self):

        SSSAT = SvSetSocketAnyType
        bcsrc = bpy.context.scene.ray_cast
        outputs = self.outputs
        out = []
        OutLoc = []
        OutNorm = []
        INDSucc = []
        OutMatrix = []
        ObjectID = []

        st = Vector_generate(SvGetSocketAnyType(self, self.inputs['start']))
        en = Vector_generate(SvGetSocketAnyType(self, self.inputs['end']))
        start = [Vector(x) for x in st[0]]
        end = [Vector(x) for x in en[0]]
        if self.Iteration == 'match_short':
            temp = match_short([start, end])
            start, end = temp[0], temp[1]
        if self.Iteration == 'match_long_repeat':
            temp = match_long_repeat([start, end])
            start, end = temp[0], temp[1]

        if self.Modes == 'Object' and (self.formula in bpy.data.objects):

            if 'data.object' in outputs:
                outputs.remove(outputs['data.object'])

            if 'hited object matrix' in outputs:
                outputs.remove(outputs['hited object matrix'])

            obj = bpy.data.objects[self.formula]
            i = 0
            while i < len(end):
                out.append(obj.ray_cast(start[i], end[i]))
                i = i + 1
            for i in out:
                OutNorm.append(i[1][:])
                INDSucc.append(i[2])
                OutLoc.append(i[0][:])

        if self.Modes == 'World':

            if 'data.object' not in outputs:
                outputs.new("VerticesSocket", "data.object")
            if 'hited object matrix' not in outputs:
                outputs.new("MatrixSocket", "hited object matrix")

            for i, last in enumerate(end):
                src = bcsrc(start[i], last)
                OutLoc.append(src[3][:])
                OutNorm.append(src[4][:])
                INDSucc.append(src[0])
                OutMatrix.append(src[2][:])
                OutMatrix = [[a[:], b[:], c[:], d[:]]
                             for a, b, c, d in OutMatrix]
                ObjectID.append(src[1])

        if outputs['HitP'].links:
            SSSAT(self, 'HitP', [OutLoc])
        if outputs['HitNorm'].links:
            SSSAT(self, 'HitNorm', [OutNorm])
        if outputs['INDEX/Succes'].links:
            SSSAT(self, 'INDEX/Succes', [INDSucc])
        if 'hited object matrix' in outputs:
            if outputs['hited object matrix'].links:
                SSSAT(self, 'hited object matrix', OutMatrix)
        if 'data.object' in outputs:
            if outputs['data.object'].links:
                SSSAT(self, 'data.object', [ObjectID])
Ejemplo n.º 23
0
def draw_callback_px(n_id, draw_verts, draw_edges, draw_faces, draw_matrix, draw_bg, settings, text):
    context = bpy.context

    # ensure data or empty lists.
    data_vector = Vector_generate(draw_verts) if draw_verts else []
    data_edges = draw_edges
    data_faces = draw_faces
    data_matrix = Matrix_generate(draw_matrix) if draw_matrix else []
    data_text = text

    if (data_vector, data_matrix) == (0, 0):
    #    callback_disable(n_id)
    #   not sure that it is safe to disable the callback in callback
    #   just return instead.
        return

    region = context.region
    region3d = context.space_data.region_3d

    vert_idx_color = settings['numid_verts_col']
    edge_idx_color = settings['numid_edges_col']
    face_idx_color = settings['numid_faces_col']
    vert_bg_color = settings['bg_verts_col']
    edge_bg_color = settings['bg_edges_col']
    face_bg_color = settings['bg_faces_col']
    display_vert_index = settings['display_vert_index']
    display_edge_index = settings['display_edge_index']
    display_face_index = settings['display_face_index']

    font_id = 0
    text_height = 13
    blf.size(font_id, text_height, 72)  # should check prefs.dpi

    region_mid_width = region.width / 2.0
    region_mid_height = region.height / 2.0

    # vars for projection
    perspective_matrix = region3d.perspective_matrix.copy()

    def draw_index(rgb, rgb2, index, vec, text=''):

        vec_4d = perspective_matrix * vec.to_4d()
        if vec_4d.w <= 0.0:
            return

        x = region_mid_width + region_mid_width * (vec_4d.x / vec_4d.w)
        y = region_mid_height + region_mid_height * (vec_4d.y / vec_4d.w)
        if text:
            index = str(text[0])
        else:
            index = str(index)

        if draw_bg:
            polyline = get_points(index)

            ''' draw polygon '''
            bgl.glColor4f(*rgb2)
            bgl.glBegin(bgl.GL_POLYGON)
            for pointx, pointy in polyline:
                bgl.glVertex2f(pointx+x, pointy+y)
            bgl.glEnd()

        ''' draw text '''
        txt_width, txt_height = blf.dimensions(0, index)
        bgl.glColor4f(*rgb)
        blf.position(0, x - (txt_width / 2), y - (txt_height / 2), 0)
        blf.draw(0, index)

    ########
    # points
    def calc_median(vlist):
        a = Vector((0, 0, 0))
        for v in vlist:
            a += v
        return a / len(vlist)

    for obj_index, verts in enumerate(data_vector):
        final_verts = verts
        if data_text:
            text_obj = data_text[obj_index]
        else:
            text_obj = ''

        # quicklt apply matrix if necessary
        if draw_matrix:
            matrix = data_matrix[obj_index]
            final_verts = [matrix * v for v in verts]

        if display_vert_index:
            for idx, v in enumerate(final_verts):
                if text_obj:
                    draw_index(vert_idx_color, vert_bg_color, idx, v, text_obj[idx])
                else:
                    draw_index(vert_idx_color, vert_bg_color, idx, v)

        if data_edges and display_edge_index:
            for edge_index, (idx1, idx2) in enumerate(data_edges[obj_index]):
                
                v1 = Vector(final_verts[idx1])
                v2 = Vector(final_verts[idx2])
                loc = v1 + ((v2 - v1) / 2)
                if text_obj:
                    draw_index(edge_idx_color, edge_bg_color, edge_index, loc, text_obj[edge_index])
                else:
                    draw_index(edge_idx_color, edge_bg_color, edge_index, loc)

        if data_faces and display_face_index:
            for face_index, f in enumerate(data_faces[obj_index]):
                verts = [Vector(final_verts[idx]) for idx in f]
                median = calc_median(verts)
                if text_obj:
                    draw_index(face_idx_color, face_bg_color, face_index, median, text_obj[face_index])
                else:
                    draw_index(face_idx_color, face_bg_color, face_index, median)
Ejemplo n.º 24
0
def draw_callback_view(handle, sl1, sl2, sl3, vs, colo, tran, shade):
    context = bpy.context
    from bgl import glEnable, glDisable, glColor3f, glVertex3f, glPointSize, \
                glLineWidth, glBegin, glEnd, glLineStipple, GL_POINTS, \
                GL_LINE_STRIP, GL_LINES, GL_LINE, GL_LINE_STIPPLE, GL_POLYGON, \
                GL_POLYGON_STIPPLE, GL_POLYGON_SMOOTH, glPolygonStipple, \
                GL_TRIANGLES, GL_QUADS, glColor4f
    # define globals, separate edgs from pols
    if tran:
        polyholy = GL_POLYGON_STIPPLE
        edgeholy = GL_LINE_STIPPLE
        edgeline = GL_LINE_STRIP
    else:
        polyholy = GL_POLYGON
        edgeholy = GL_LINE
        edgeline = GL_LINES

    if sl1:
        data_vector = Vector_generate(sl1)
        verlen = len(data_vector) - 1
        verlen_every = [len(d) - 1 for d in data_vector]
    else:
        data_vector = []
        verlen = 0

    if sl2:
        if sl2[0]:
            if len(sl2[0][0]) == 2:
                data_edges = sl2
                data_polygons = []
            elif len(sl2[0][0]) > 2:
                data_polygons = sl2
                data_edges = []
        else:
            data_polygons = []
            data_edges = []

    else:
        data_edges, data_polygons = [], []

    if sl3:
        data_matrix = Matrix_generate(sl3)
    else:
        data_matrix = [Matrix() for i in range(verlen + 1)]

    coloa = colo[0]
    colob = colo[1]
    coloc = colo[2]

    if (data_vector, data_polygons, data_matrix, data_edges) == (0, 0, 0, 0):
        callback_disable(handle)
    #print ('вход', sl1, sl2, sl3)
    #print ('преобраз', data_vector)

    # draw_matrix vars
    zero = Vector((0.0, 0.0, 0.0))
    x_p = Vector((0.5, 0.0, 0.0))
    x_n = Vector((-0.5, 0.0, 0.0))
    y_p = Vector((0.0, 0.5, 0.0))
    y_n = Vector((0.0, -0.5, 0.0))
    z_p = Vector((0.0, 0.0, 0.5))
    z_n = Vector((0.0, 0.0, -0.5))
    bb = [Vector() for i in range(24)]

    def draw_matrix(mat):
        zero_tx = mat * zero

        glLineWidth(2.0)
        # x
        glColor3f(1.0, 0.2, 0.2)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * x_p))
        glEnd()

        glColor3f(0.6, 0.0, 0.0)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * x_n))
        glEnd()

        # y
        glColor3f(0.2, 1.0, 0.2)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * y_p))
        glEnd()

        glColor3f(0.0, 0.6, 0.0)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * y_n))
        glEnd()

        # z
        glColor3f(0.2, 0.2, 1.0)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * z_p))
        glEnd()

        glColor3f(0.0, 0.0, 0.6)
        glBegin(GL_LINES)
        glVertex3f(*(zero_tx))
        glVertex3f(*(mat * z_n))
        glEnd()

        # bounding box vertices
        i = 0
        glColor3f(1.0, 1.0, 1.0)
        series1 = (-0.5, -0.3, -0.1, 0.1, 0.3, 0.5)
        series2 = (-0.5, 0.5)
        z = 0
        for x in series1:
            for y in series2:
                bb[i][:] = x, y, z
                bb[i] = mat * bb[i]
                i += 1
        for y in series1:
            for x in series2:
                bb[i][:] = x, y, z
                bb[i] = mat * bb[i]
                i += 1

        # bounding box drawing
        glLineWidth(1.0)
        glLineStipple(1, 0xAAAA)
        glEnable(GL_LINE_STIPPLE)

        for i in range(0, 24, 2):
            glBegin(GL_LINE_STRIP)
            glVertex3f(*bb[i])
            glVertex3f(*bb[i + 1])
            glEnd()

    # MAYBE WE SHOULD CONNECT ITERATION FOR ALL PROCESS TO DECREASE
    # TIME?
    ########
    # points
    if vs:
        if data_vector:
            glPointSize(3.0)
            glColor3f(0.8, 0.9, 1.0)

            for i, matrix in enumerate(data_matrix):
                glBegin(GL_POINTS)
                k = i
                if i > verlen:
                    k = verlen
                for vert in data_vector[k]:
                    vec_corrected = data_matrix[i] * vert
                    glVertex3f(*vec_corrected)
                    #print ('рисовальня', matrix, vec_corrected)
                glEnd()
                glPointSize(3.0)

    #######
    # lines
    if data_edges and data_vector:
        glColor3f(coloa, colob, coloc)
        glLineWidth(1.0)
        glEnable(edgeholy)

        for i, matrix in enumerate(data_matrix):  # object
            k = i
            if i > verlen:  # filter to share objects
                k = verlen
            for line in data_edges[k]:  # line
                if max(line) > verlen_every[k]:
                    line = data_edges[k][-1]
                glBegin(edgeline)
                for point in line:  # point
                    vec_corrected = data_matrix[i] * data_vector[k][int(point)]
                    glVertex3f(*vec_corrected)
                glEnd()
                glPointSize(1.75)
                glLineWidth(1.0)
        glDisable(edgeholy)

    #######
    # polygons
    vectorlight = Vector((-0.66, -0.66, -0.66))
    if data_polygons and data_vector:
        glLineWidth(1.0)
        glEnable(polyholy)

        for i, matrix in enumerate(data_matrix):  # object
            k = i
            if i > verlen:
                k = verlen
            oblen = len(data_polygons[k])
            for j, pol in enumerate(data_polygons[k]):
                if max(pol) > verlen_every[k]:
                    pol = data_edges[k][-1]
                    j = len(data_edges[k]) - 1
                if shade:
                    normal_no_ = mathutils.geometry.normal(
                        data_vector[k][pol[0]], data_vector[k][pol[1]],
                        data_vector[k][pol[2]])
                    normal_no = (normal_no_.angle(vectorlight, 0)) / math.pi
                    randa = (normal_no * coloa) - 0.1
                    randb = (normal_no * colob) - 0.1
                    randc = (normal_no * coloc) - 0.1
                else:
                    randa = ((j / oblen) + coloa) / 2.5
                    randb = ((j / oblen) + colob) / 2.5
                    randc = ((j / oblen) + coloc) / 2.5
                if len(pol) > 4:
                    glBegin(GL_TRIANGLES)
                    glColor4f(randa + 0.2, randb + 0.2, randc + 0.2, 0.5)
                    #glColor3f(randa+0.2, randb+0.2, randc+0.2)
                    v = [data_vector[k][i] for i in pol]
                    tess_poly = mathutils.geometry.tessellate_polygon([v])
                    for a, b, c in tess_poly:
                        glVertex3f(*(data_matrix[i] * v[a]))
                        glVertex3f(*(data_matrix[i] * v[b]))
                        glVertex3f(*(data_matrix[i] * v[c]))
                elif len(pol) == 4:
                    glBegin(GL_POLYGON)
                    glColor3f(randa + 0.2, randb + 0.2, randc + 0.2)
                    for point in pol:
                        vec_corrected = data_matrix[i] * data_vector[k][int(
                            point)]
                        glVertex3f(*vec_corrected)
                else:
                    glBegin(GL_TRIANGLES)
                    glColor3f(randa + 0.2, randb + 0.2, randc + 0.2)
                    for point in pol:
                        vec_corrected = data_matrix[i] * data_vector[k][int(
                            point)]
                        glVertex3f(*vec_corrected)
                glEnd()
                glPointSize(1.75)
                glLineWidth(1.0)
        glDisable(polyholy)

    # for future bezier drawing - to remake
    #if data_edges and data_vector and bezier:
    # here 3 lines that i must understand
    #from bpy_extras.view3d_utils import location_3d_to_region_2d
    #region = context.region
    #region_data = context.region_data

    #glEnable(GL_BLEND)
    #glColor4f(1, 0, 0, 0.5)
    #glLineWidth(1.0)
    #glBegin(GL_LINE_STRIP)
    #for i in range(current_frame):
    #glVertex2f(*location_3d_to_region_2d(region, region_data, (math.sin(i / 10), 0, i / 10)).to_tuple())
    #glEnd()
    #glDisable(GL_BLEND)

    #######
    # matrix
    if data_matrix and not data_vector:
        for mat in data_matrix:
            draw_matrix(mat)
Ejemplo n.º 25
0
    def update(self):

        if 'Vertices' in self.inputs and self.inputs['Vertices'].links:
            verts = SvGetSocketAnyType(self, self.inputs['Vertices'])

            if 'PolyEdge' in self.inputs and self.inputs['PolyEdge'].links:
                poly_edge = SvGetSocketAnyType(self, self.inputs['PolyEdge'])
                polyIn = True
            else:
                polyIn = False
                poly_edge = repeat_last([[]])

            verts_out = []
            poly_edge_out = []
            item_order = []

            polyOutput = bool(polyIn and 'PolyEdge' in self.outputs
                              and self.outputs['PolyEdge'].links)
            orderOutput = bool('Item order' in self.outputs
                               and self.outputs['Item order'].links)
            vertOutput = bool('Vertices' in self.outputs
                              and self.outputs['Vertices'].links)

            if not any((vertOutput, orderOutput, polyOutput)):
                return

            if self.mode == 'XYZ':
                # should be user settable
                op_order = [(0, False), (1, False), (2, False)]

                for v, p in zip(verts, poly_edge):
                    s_v = ((e[0], e[1], e[2], i) for i, e in enumerate(v))

                    for item_index, rev in op_order:
                        s_v = sorted(s_v,
                                     key=itemgetter(item_index),
                                     reverse=rev)

                    verts_out.append([v[:3] for v in s_v])

                    if polyOutput:
                        v_index = {item[-1]: j for j, item in enumerate(s_v)}
                        poly_edge_out.append(
                            [list(map(lambda n: v_index[n], pe)) for pe in p])
                    if orderOutput:
                        item_order.append([i[-1] for i in s_v])

            if self.mode == 'DIST':
                if 'Base Point' in self.inputs and self.inputs[
                        'Base Point'].links:
                    base_points = SvGetSocketAnyType(self,
                                                     self.inputs['Base Point'])
                    bp_iter = repeat_last(base_points[0])
                else:
                    bp = [(0, 0, 0)]
                    bp_iter = repeat_last(bp)

                for v, p, v_base in zip(verts, poly_edge, bp_iter):
                    s_v = sorted(((v_c, i) for i, v_c in enumerate(v)),
                                 key=lambda v: distK(v[0], v_base))
                    verts_out.append([vert[0] for vert in s_v])

                    if polyOutput:
                        v_index = {item[-1]: j for j, item in enumerate(s_v)}
                        poly_edge_out.append(
                            [list(map(lambda n: v_index[n], pe)) for pe in p])
                    if orderOutput:
                        item_order.append([i[-1] for i in s_v])

            if self.mode == 'AXIS':
                if 'Mat' in self.inputs and self.inputs['Mat'].links:
                    mat = Matrix_generate(
                        SvGetSocketAnyType(self, self.inputs['Mat']))
                else:
                    mat = [Matrix.Identity(4)]
                mat_iter = repeat_last(mat)

                def f(axis, q):
                    if axis.dot(q.axis) > 0:
                        return q.angle
                    else:
                        return -q.angle

                for v, p, m in zip(Vector_generate(verts), poly_edge,
                                   mat_iter):
                    axis = m * Vector((0, 0, 1))
                    axis_norm = m * Vector((1, 0, 0))
                    base_point = m * Vector((0, 0, 0))
                    intersect_d = [
                        intersect_point_line(v_c, base_point, axis)
                        for v_c in v
                    ]
                    rotate_d = [
                        f(axis, (axis_norm + v_l[0]).rotation_difference(v_c))
                        for v_c, v_l in zip(v, intersect_d)
                    ]
                    s_v = (
                        (data[0][1], data[1], i)
                        for i, data in enumerate(zip(intersect_d, rotate_d)))
                    s_v = sorted(s_v, key=itemgetter(0, 1))

                    verts_out.append([v[i[-1]].to_tuple() for i in s_v])

                    if polyOutput:
                        v_index = {item[-1]: j for j, item in enumerate(s_v)}
                        poly_edge_out.append(
                            [list(map(lambda n: v_index[n], pe)) for pe in p])
                    if orderOutput:
                        item_order.append([i[-1] for i in s_v])

            if self.mode == 'USER':
                if 'Index Data' in self.inputs and self.inputs[
                        'Index Data'].links:
                    index = SvGetSocketAnyType(self, self.inputs['Index Data'])
                else:
                    return

                for v, p, i in zip(verts, poly_edge, index):

                    s_v = sorted([(data[0], data[1], i)
                                  for i, data in enumerate(zip(i, v))],
                                 key=itemgetter(0))

                    verts_out.append([obj[1] for obj in s_v])

                    if polyOutput:
                        v_index = {item[-1]: j for j, item in enumerate(s_v)}
                        poly_edge_out.append([[v_index[k] for k in pe]
                                              for pe in p])
                    if orderOutput:
                        item_order.append([i[-1] for i in s_v])

            if vertOutput:
                SvSetSocketAnyType(self, 'Vertices', verts_out)
            if polyOutput:
                SvSetSocketAnyType(self, 'PolyEdge', poly_edge_out)
            if orderOutput:
                SvSetSocketAnyType(self, 'Item order', item_order)
Ejemplo n.º 26
0
    def update(self):
        if self.outputs['Centers'].links or self.outputs['Normals'].links or \
                self.outputs['Origins'].links or self.outputs['Norm_abs'].links:
            if 'Polygons' in self.inputs and 'Vertices' in self.inputs \
                and self.inputs['Polygons'].links and self.inputs['Vertices'].links:

                pols_ = SvGetSocketAnyType(self, self.inputs['Polygons'])
                vers_tupls = SvGetSocketAnyType(self, self.inputs['Vertices'])
                vers_vects = Vector_generate(vers_tupls)

                # make mesh temp утилитарно - удалить в конце
                mat_collect = []
                normals_out = []
                origins = []
                norm_abs_out = []
                for verst, versv, pols in zip(vers_tupls, vers_vects, pols_):
                    # medians в векторах
                    medians = []
                    normals = []
                    centrs = []
                    norm_abs = []
                    for p in pols:
                        # medians
                        # it calcs middle point of opposite edges,
                        # than finds length vector between this two points
                        v0 = versv[p[0]]
                        v1 = versv[p[1]]
                        v2 = versv[p[2]]
                        lp = len(p)
                        if lp >= 4:
                            l = ((lp - 2) // 2) + 2
                            v3 = versv[p[l]]
                            poi_2 = (v2 + v3) / 2
                            # normals
                            norm = geometry.normal(v0, v1, v2, v3)
                            normals.append(norm)
                        else:
                            poi_2 = v2
                            # normals
                            norm = geometry.normal(v0, v1, v2)
                            normals.append(norm)
                        poi_1 = (v0 + v1) / 2
                        vm = poi_2 - poi_1
                        medians.append(vm)
                        # centrs
                        x, y, z = zip(*[verst[poi] for poi in p])
                        x, y, z = sum(x) / len(x), sum(y) / len(y), sum(
                            z) / len(z)
                        current_center = Vector((x, y, z))
                        centrs.append(current_center)
                        # normal absolute !!!
                        # это совершенно нормально!!! ;-)
                        norm_abs.append(current_center + norm)

                    norm_abs_out.append(norm_abs)
                    origins.append(centrs)
                    normals_out.extend(normals)
                    mat_collect_ = []
                    for cen, med, nor in zip(centrs, medians, normals):
                        loc = Matrix.Translation(cen)
                        # need better solution for Z,Y vectors + may be X vector correction
                        vecz = Vector((0, 1e-6, 1))
                        q_rot0 = vecz.rotation_difference(
                            nor).to_matrix().to_4x4()
                        q_rot2 = nor.rotation_difference(
                            vecz).to_matrix().to_4x4()
                        vecy = Vector((1e-6, 1, 0)) * q_rot2
                        q_rot1 = vecy.rotation_difference(
                            med).to_matrix().to_4x4()
                        # loc is matrix * rot vector * rot vector
                        M = loc * q_rot1 * q_rot0
                        lM = [j[:] for j in M]
                        mat_collect_.append(lM)
                    mat_collect.extend(mat_collect_)

                SvSetSocketAnyType(self, 'Centers', mat_collect)
                SvSetSocketAnyType(self, 'Norm_abs',
                                   Vector_degenerate(norm_abs_out))
                SvSetSocketAnyType(self, 'Origins', Vector_degenerate(origins))
                SvSetSocketAnyType(self, 'Normals',
                                   Vector_degenerate([normals_out]))
Ejemplo n.º 27
0
    def update(self):
        if not 'centers' in self.outputs:
            return
        if 'vecLine' in self.inputs and 'vecPlane' in self.inputs \
                and 'edgPlane' in self.inputs:
            print(self.name, 'is starting')
            if self.inputs['vecLine'].links and self.inputs['vecPlane'].links \
                    and self.inputs['edgPlane'].links:
                if self.bindCircle:
                    circle = [ (Vector((sin(radians(i)),cos(radians(i)),0))*self.circle_rad)/4 \
                              for i in range(0,360,30) ]
                vec = self.inputs['vecLine'].sv_get()
                vecplan = self.inputs['vecPlane'].sv_get()
                edgplan = self.inputs['edgPlane'].sv_get()
                thick = self.inputs['thick'].sv_get()[0][0]
                sinuso60 = 0.8660254037844386
                sinuso60_minus = 0.133974596
                sinuso30 = 0.5
                sinuso45 = 0.7071067811865475
                thick_2 = thick / 2
                thick_3 = thick / 3
                thick_6 = thick / 6
                threshold = self.threshold
                if 'vecContr' in self.inputs and self.inputs['vecContr'].links:
                    vecont = self.inputs['vecContr'].sv_get()
                    edgcont = self.inputs['edgContr'].sv_get()
                    vec_cont = Vector_generate(vecont)
                    loc_cont = [[i[0]] for i in vec_cont]
                    norm_cont = [[NM(i[0], i[len(i) // 2], i[-1])]
                                 for i in vec_cont]  # довести до ума
                else:
                    vec_cont = []
                if 'vecTube' in self.inputs and self.inputs['vecTube'].links:
                    vectube = self.inputs['vecTube'].sv_get()
                    vec_tube = Vector_generate(vectube)
                    tube_radius = self.inputs['radTube'].sv_get()[0][0]
                    circle_tube = [ (Vector((sin(radians(i)),cos(radians(i)),0))*tube_radius) \
                              for i in range(0,360,15) ]
                else:
                    vec_tube = []
                outeup = []
                outelo = []
                vupper = []
                vlower = []
                centers = []
                vec_ = Vector_generate(vec)
                vecplan_ = Vector_generate(vecplan)
                for centersver, vecp, edgp in zip(vecplan, vecplan_, edgplan):
                    tubes_flag_bed_solution_i_know = False
                    newinds1 = edgp.copy()
                    newinds2 = edgp.copy()
                    vupperob = vecp.copy()
                    vlowerob = vecp.copy()
                    deledges1 = []
                    deledges2 = []
                    # to define bounds
                    x = [i[0] for i in vecp]
                    y = [i[1] for i in vecp]
                    z = [i[2] for i in vecp]
                    m1x, m2x, m1y, m2y, m1z, m2z = max(x), min(x), max(y), min(
                        y), max(z), min(z)
                    l = Vector(
                        (sum(x) / len(x), sum(y) / len(y), sum(z) / len(z)))
                    n_select = [vecp[0], vecp[len(vecp) // 2],
                                vecp[-1]]  # довести до ума
                    n_select.sort(key=lambda x: sum(x[:]), reverse=False)
                    n_ = NM(n_select[0], n_select[1], n_select[2])
                    n_.normalize()
                    # а виновта ли нормаль?
                    if n_[0] < 0:
                        n = n_ * -1
                    else:
                        n = n_
                    cen = [sum(i) for i in zip(*centersver)]
                    centers.append(Vector(cen) / len(centersver))
                    k = 0
                    lenvep = len(vecp)
                    # KDtree collections closest to join edges to sockets
                    tree = KDT.KDTree(lenvep)
                    for i, v in enumerate(vecp):
                        tree.insert(v, i)
                    tree.balance()
                    # vertical edges iterations
                    # every edge is object - two points, one edge
                    for v in vec_:
                        # sort vertices by Z value
                        # find two vertices - one lower, two upper
                        vlist = [v[0], v[1]]
                        vlist.sort(key=lambda x: x[2], reverse=False)
                        # flip if coplanar to enemy plane
                        # flip plane coplanar
                        if vec_cont:
                            fliped = self.get_coplanar(v[0], loc_cont,
                                                       norm_cont, vec_cont)
                        else:
                            fliped = False
                        shortedge = (vlist[1] - vlist[0]).length
                        if fliped:
                            two, one = vlist
                        else:
                            one, two = vlist
                        # coplanar to owner
                        cop = abs(D2P(one, l, n))
                        # defining bounds
                        inside = one[0]<m1x and one[0]>m2x and one[1]<m1y and one[1]>m2y \
                                 and one[2]<=m1z and one[2]>=m2z
                        # if in bounds and coplanar do:
                        #print(self.name,l, cop, inside)
                        if cop < 0.001 and inside and shortedge > thick * threshold:
                            '''
                            huge calculations. if we can reduce...
                            '''
                            # find shift for thickness in sockets
                            diry = two - one
                            diry.normalize()
                            # solution for vertical wafel - cool but not in diagonal case
                            # angle = radians(degrees(atan(n.y/n.x))+90)
                            dirx_ = self.rotation_on_axis(diry, n, radians(90))
                            dirx = dirx_ * thick_2
                            # вектор, индекс, расстояние
                            # запоминаем порядок находим какие удалить рёбра
                            # делаем выборку левая-правая точка
                            nearv_1, near_1 = tree.find(one)[:2]
                            nearv_2, near_2 = tree.find(two)[:2]
                            # indexes of two nearest points
                            # удалить рёбра что мешают спать заодно
                            en_0, en_1, de1 = self.calc_indexes(edgp, near_1)
                            deledges1.extend(de1)
                            en_2, en_3, de2 = self.calc_indexes(edgp, near_2)
                            deledges2.extend(de2)
                            # print(vecp, one, dirx, en_0, en_1)
                            # left-right indexes and vectors
                            # с учётом интерполяций по высоте
                            l1, r1, lz1, rz1 = \
                                    self.calc_leftright(vecp, one, dirx, en_0, en_1, thick_2, diry)
                            l2, r2, lz2, rz2 = \
                                    self.calc_leftright(vecp, two, dirx, en_2, en_3, thick_2, diry)
                            # print(left2, right2, l2, r2, lz2, rz2)
                            # средняя точка и её смещение по толщине материала
                            three = (one - two) / 2 + two
                            if self.rounded:
                                '''рёбра'''
                                # пазы формируем независимо от верх низ

                                outeob1 = [[lenvep + k + 8, lenvep + k],
                                           [lenvep + k + 1, lenvep + k + 2],
                                           [lenvep + k + 2, lenvep + k + 3],
                                           [lenvep + k + 3, lenvep + k + 4],
                                           [lenvep + k + 4, lenvep + k + 5],
                                           [lenvep + k + 5, lenvep + k + 6],
                                           [lenvep + k + 6, lenvep + k + 7],
                                           [lenvep + k + 7, lenvep + k + 8],
                                           [lenvep + k + 9, lenvep + k + 1]]

                                outeob2 = [[lenvep + k, lenvep + k + 1],
                                           [lenvep + k + 1, lenvep + k + 2],
                                           [lenvep + k + 2, lenvep + k + 3],
                                           [lenvep + k + 3, lenvep + k + 4],
                                           [lenvep + k + 4, lenvep + k + 5],
                                           [lenvep + k + 5, lenvep + k + 6],
                                           [lenvep + k + 6, lenvep + k + 7],
                                           [lenvep + k + 7, lenvep + k + 8],
                                           [lenvep + k + 8, lenvep + k + 9]]
                                # наполнение списков lenvep = length(vecp)
                                newinds1.extend([[l1, lenvep + k],
                                                 [lenvep + k + 9, r1]])
                                newinds2.extend([[l2, lenvep + k + 9],
                                                 [lenvep + k, r2]])
                                '''Вектора'''
                                round1 = diry * thick_3
                                round2 = diry * thick_3 * sinuso30
                                round2_ = dirx / 3 + dirx * (2 * sinuso60 / 3)
                                round3 = diry * thick_3 * sinuso60_minus
                                round3_ = dirx / 3 + dirx * (2 * sinuso30 / 3)
                                round4 = dirx / 3
                                vupperob.extend([
                                    lz2, three + round1 - dirx,
                                    three + round2 - round2_,
                                    three + round3 - round3_, three - round4,
                                    three + round4, three + round3 + round3_,
                                    three + round2 + round2_,
                                    three + round1 + dirx, rz2
                                ])
                                vlowerob.extend([
                                    rz1, three - round1 - dirx,
                                    three - round2 - round2_,
                                    three - round3 - round3_, three - round4,
                                    three + round4, three - round3 + round3_,
                                    three - round2 + round2_,
                                    three - round1 + dirx, lz1
                                ])
                                k += 10
                            else:
                                '''рёбра'''
                                # пазы формируем независимо от верх низ
                                outeob1 = [[lenvep + k, lenvep + k + 1],
                                           [lenvep + k + 1, lenvep + k + 2],
                                           [lenvep + k + 2, lenvep + k + 3]]
                                outeob2 = [[lenvep + k, lenvep + k + 1],
                                           [lenvep + k + 1, lenvep + k + 2],
                                           [lenvep + k + 2, lenvep + k + 3]]
                                # наполнение списков lenvep = length(vecp)
                                newinds1.extend([[l1, lenvep + k],
                                                 [lenvep + k + 3, r1]])
                                newinds2.extend([[l2, lenvep + k + 3],
                                                 [lenvep + k, r2]])
                                '''Вектора'''
                                vupperob.extend(
                                    [lz2, three - dirx, three + dirx, rz2])
                                vlowerob.extend(
                                    [rz1, three + dirx, three - dirx, lz1])
                                k += 4
                            newinds1.extend(outeob1)
                            newinds2.extend(outeob2)
                            if self.bindCircle:
                                CP = self.circl_place
                                if CP == 'Midl':
                                    crcl_cntr = IL2P(one, two, Vector(
                                        (0, 0, 0)), Vector((0, 0, -1)))
                                elif CP == 'Up' and not fliped:
                                    crcl_cntr = two - diry * self.circle_rad * 2
                                elif CP == 'Down' and not fliped:
                                    crcl_cntr = one + diry * self.circle_rad * 2
                                elif CP == 'Up' and fliped:
                                    crcl_cntr = one + diry * self.circle_rad * 2
                                elif CP == 'Down' and fliped:
                                    crcl_cntr = two - diry * self.circle_rad * 2
                                # forgot howto 'else' in line iteration?
                                outeob1 = [[
                                    lenvep + k + i, lenvep + k + i + 1
                                ] for i in range(0, 11)]
                                outeob1.append([lenvep + k, lenvep + k + 11])
                                outeob2 = [[
                                    lenvep + k + i, lenvep + k + i + 1
                                ] for i in range(12, 23)]
                                outeob2.append(
                                    [lenvep + k + 12, lenvep + k + 23])
                                newinds1.extend(outeob1 + outeob2)
                                newinds2.extend(outeob1 + outeob2)
                                mat_rot_cir = n.rotation_difference(
                                    Vector((0, 0, 1))).to_matrix().to_4x4()
                                circle_to_add_1 = [vecir*mat_rot_cir+crcl_cntr+ \
                                        dirx_*self.circle_rad for vecir in circle ]
                                circle_to_add_2 = [vecir*mat_rot_cir+crcl_cntr- \
                                        dirx_*self.circle_rad for vecir in circle ]
                                vupperob.extend(circle_to_add_1 +
                                                circle_to_add_2)
                                vlowerob.extend(circle_to_add_1 +
                                                circle_to_add_2)
                                k += 24
                            if vec_tube and not tubes_flag_bed_solution_i_know:
                                for v in vec_tube:
                                    crcl_cntr = IL2P(v[0], v[1], l, n)
                                    if crcl_cntr:
                                        inside = crcl_cntr[0]<m1x and crcl_cntr[0]>m2x and crcl_cntr[1]<m1y \
                                             and crcl_cntr[1]>m2y and crcl_cntr[2]<=m1z and crcl_cntr[2]>=m2z
                                        if inside:
                                            outeob = [[
                                                lenvep + k + i,
                                                lenvep + k + i + 1
                                            ] for i in range(0, 23)]
                                            outeob.append(
                                                [lenvep + k, lenvep + k + 23])
                                            newinds1.extend(outeob)
                                            newinds2.extend(outeob)
                                            mat_rot_cir = n.rotation_difference(
                                                Vector(
                                                    (0, 0,
                                                     1))).to_matrix().to_4x4()
                                            circle_to_add = [
                                                vecir * mat_rot_cir + crcl_cntr
                                                for vecir in circle_tube
                                            ]
                                            vupperob.extend(circle_to_add)
                                            vlowerob.extend(circle_to_add)
                                            k += 24
                                tubes_flag_bed_solution_i_know = True
                        elif cop < 0.001 and inside and shortedge <= thick * threshold:
                            vupperob.extend([one, two])
                            vlowerob.extend([one, two])
                            newinds1.append([lenvep + k, lenvep + k + 1])
                            newinds2.append([lenvep + k, lenvep + k + 1])
                            k += 2
                    del tree
                    for e in deledges1:
                        if e in newinds1:
                            newinds1.remove(e)
                    for e in deledges2:
                        if e in newinds2:
                            newinds2.remove(e)
                    if vupperob or vlowerob:
                        outeup.append(newinds2)
                        outelo.append(newinds1)
                        vupper.append(vupperob)
                        vlower.append(vlowerob)
                vupper = Vector_degenerate(vupper)
                vlower = Vector_degenerate(vlower)
                centers = Vector_degenerate([centers])

                if 'vertUp' in self.outputs and self.outputs['vertUp'].links:
                    out = dataCorrect(vupper)
                    SvSetSocketAnyType(self, 'vertUp', out)
                if 'edgeUp' in self.outputs and self.outputs['edgeUp'].links:
                    SvSetSocketAnyType(self, 'edgeUp', outeup)
                if 'vertLo' in self.outputs and self.outputs['vertLo'].links:
                    SvSetSocketAnyType(self, 'vertLo', vlower)
                if 'edgeLo' in self.outputs and self.outputs['edgeLo'].links:
                    SvSetSocketAnyType(self, 'edgeLo', outelo)
                if 'centers' in self.outputs and self.outputs['centers'].links:
                    SvSetSocketAnyType(self, 'centers', centers)
                print(self.name, 'is finishing')
Ejemplo n.º 28
0
    def update(self):
        # достаём два слота - вершины и полики
        if 'Vertices' in self.outputs and self.outputs['Vertices'].links:
            if (self.inputs['PolsR'].links and self.inputs['VersR'].links
                    and self.inputs['VersD'].links
                    and self.inputs['PolsD'].links):

                if self.inputs['Z_Coef'].links:
                    z_coef = SvGetSocketAnyType(self, self.inputs['Z_Coef'])[0]
                else:
                    z_coef = []

                polsR = SvGetSocketAnyType(
                    self, self.inputs['PolsR'])[0]  # recipient one object [0]
                versR = SvGetSocketAnyType(
                    self, self.inputs['VersR'])[0]  # recipient
                polsD = SvGetSocketAnyType(
                    self, self.inputs['PolsD'])  # donor many objects [:]
                versD_ = SvGetSocketAnyType(self,
                                            self.inputs['VersD'])  # donor
                versD = Vector_generate(versD_)
                ##### it is needed for normals of vertices
                new_me = bpy.data.meshes.new('recepient')
                new_me.from_pydata(versR, [], polsR)
                new_me.update(calc_edges=True)
                new_ve = new_me.vertices
                #print (new_ve[0].normal, 'normal')

                for i, vD in enumerate(versD):

                    pD = polsD[i]
                    n_verts = len(vD)
                    n_faces = len(pD)

                    xx = [x[0] for x in vD]
                    x0 = (self.width_coef) / (max(xx) - min(xx))
                    yy = [y[1] for y in vD]
                    y0 = (self.width_coef) / (max(yy) - min(yy))
                    zz = [z[2] for z in vD]
                    zzz = (max(zz) - min(zz))
                    if zzz:
                        z0 = 1 / zzz
                    else:
                        z0 = 0
                    #print (x0, y0, z0)

                    vers_out = []
                    pols_out = []

                    for j, pR in enumerate(polsR):

                        last = len(pR) - 1
                        vs = [new_ve[v]
                              for v in pR]  # new_ve  - temporery data
                        if z_coef:
                            if j < len(z_coef):
                                z1 = z0 * z_coef[j]
                        else:
                            z1 = z0

                        new_vers = []
                        new_pols = []
                        for v in vD:
                            new_vers.append(
                                self.lerp3(vs[0], vs[1], vs[2], vs[last], v,
                                           x0, y0, z1))
                        for p in pD:
                            new_pols.append([id for id in p])
                        pols_out.append(new_pols)
                        vers_out.append(new_vers)
                    bpy.data.meshes.remove(new_me)  # cleaning and washing
                    del (new_ve)

                #print (Vector_degenerate(vers_out))

                output = Vector_degenerate(vers_out)
                #print (output)
                if 'Vertices' in self.outputs and self.outputs[
                        'Vertices'].links:
                    SvSetSocketAnyType(self, 'Vertices', output)

                if 'Poligons' in self.outputs and self.outputs[
                        'Poligons'].links:
                    SvSetSocketAnyType(self, 'Poligons', pols_out)
Ejemplo n.º 29
0
    def update(self):
        if 'vec' in self.inputs and 'edg' in self.inputs:
            print(self.name, 'is starting')
            if self.inputs['vec'].links and self.inputs['edg'].links:

                
                vec = self.inputs['vec'].sv_get()
                edg = self.inputs['edg'].sv_get()
                vecplan = self.inputs['vecplan'].sv_get()
                edgplan = self.inputs['edgplan'].sv_get()
                loc = self.inputs['loc'].sv_get()
                norm = self.inputs['norm'].sv_get()
                thick = self.inputs['thick'].sv_get()[0][0]
                sinuso60 = 0.8660254037844386
                sinuso60_minus = 0.133974596
                sinuso30 = 0.5
                sinuso45 = 0.7071067811865475
                if 'loccont' in self.inputs and self.inputs['loccont'].links and \
                       'normcont' in self.inputs and self.inputs['normcont'].links:
                    vecont = self.inputs['vecont'].sv_get()
                    loccont = self.inputs['loccont'].sv_get()
                    normcont = self.inputs['normcont'].sv_get()
                    vec_cont = Vector_generate(vecont)
                    loc_cont = Vector_generate(loccont)
                    norm_cont = Vector_generate(normcont)
                else:
                    norm_cont = [[Vector((0,0,1)) for i in range(len(norm[0]))]]
                    loc_cont = [[Vector((0,0,10000)) for i in range(len(norm[0]))]]
                    vec_cont = [[Vector((1000,0,1))] for i in range(len(norm[0]))]
                outeup = []
                outelo = []
                vupper = []
                vlower = []
                vec_ = Vector_generate(vec)
                loc_ = Vector_generate(loc)
                norm_ = Vector_generate(norm)
                vecplan_ = Vector_generate(vecplan)
                #print(self.name, 'veriables: \n', \
                #      vec_,'\n',
                #      vecplan_,'\n',
                #      loc_,'\n',
                #      loc_cont)
                for l,n,vecp, edgp in zip(loc_[0],norm_[0],vecplan_,edgplan):
                    newinds1 = edgp.copy()
                    newinds2 = edgp.copy()
                    vupperob = vecp.copy()
                    vlowerob = vecp.copy()
                    deledges1 = []
                    deledges2 = []
                    k = 0
                    lenvep = len(vecp)
                    # KDtree collections closest to join edges to sockets
                    tree = KDT.KDTree(lenvep)
                    for i,v in enumerate(vecp):
                        tree.insert(v,i)
                    tree.balance()
                    # to define bounds
                    x = [i[0] for i in vecp]
                    y = [i[1] for i in vecp]
                    m1x,m2x,m1y,m2y = max(x), min(x), max(y), min(y)
                    # vertical edges iterations
                    # every edge is object - two points, one edge
                    for v in vec_:
                        # sort vertices by Z value
                        # find two vertices - one lower, two upper
                        vlist = [v[0],v[1]]
                        vlist.sort(key=lambda x: x[2], reverse=False)
                        # flip if coplanar to enemy plane
                        # flip plane coplanar
                        fliped = self.get_coplanar(v[0], loc_cont,norm_cont, vec_cont)
                        if fliped:
                            two, one = vlist
                        else:
                            one, two = vlist
                        # coplanar to owner
                        cop = abs(D2P(one,l,n))
                        # defining bounds
                        inside = one[0]<m1x and one[0]>m2x and one[1]<m1y and one[1]>m2y
                        # if in bounds and coplanar do:
                        #print(self.name,l, cop, inside)
                        if cop < 0.001 and inside:
                            '''
                            huge calculations. if we can reduce...
                            '''
                            # find shift for thickness in sockets
                            angle = radians(degrees(atan(n.y/n.x))+90)
                            thick_2 = thick/2
                            direction = Vector((cos(angle),sin(angle),0))*thick_2
                            #matr = Euler((0,0,angle),'YZX').to_matrix().to_4x4()
                            #matr.translation = 
                            #direction = matr
                            # вектор, индекс, расстояние
                            # запоминаем порядок
                            # находим какие удалить рёбра
                            # делаем выборку левая-правая точка
                            nearv_1, near_1 = tree.find(one)[:2]
                            nearv_2, near_2 = tree.find(two)[:2]
                            # indexes of two nearest points
                            # удалить рёбра что мешают спать заодно
                            en_0, en_1, de1 = self.calc_indexes(edgp, near_1)
                            deledges1.extend(de1)
                            en_2, en_3, de2 = self.calc_indexes(edgp, near_2)
                            deledges2.extend(de2)
                            # old delete
                            # en_0,en_1 = [[t for t in i if t != near_1] for i in edgp if near_1 in i]
                            # en_2,en_3 = [[t for t in i if t != near_2] for i in edgp if near_2 in i]
                            # print(vecp, one, direction, en_0, en_1)
                            # left-right indexes and vectors
                            # с учётом интерполяций по высоте
                            left1, right1, l1, r1, lz1, rz1 = \
                                    self.calc_leftright(vecp, one, direction, en_0, en_1, thick_2)
                            left2, right2, l2, r2, lz2, rz2 = \
                                    self.calc_leftright(vecp, two, direction, en_2, en_3, thick_2)

                            # средняя точка и её смещение по толщине материала
                            three = (one-two)/2 + two
                            if self.rounded:
                                '''рёбра'''
                                if fliped:
                                    doflip = -1
                                else:
                                    doflip = 1
                                # пазы формируем независимо от верх низ

                                outeob1 = [[lenvep+k+8,lenvep+k],[lenvep+k+1,lenvep+k+2],
                                          [lenvep+k+2,lenvep+k+3],[lenvep+k+3,lenvep+k+4],
                                          [lenvep+k+4,lenvep+k+5],[lenvep+k+5,lenvep+k+6],
                                          [lenvep+k+6,lenvep+k+7],[lenvep+k+7,lenvep+k+8],
                                          [lenvep+k+9,lenvep+k+1]]

                                outeob2 = [[lenvep+k,lenvep+k+1],[lenvep+k+1,lenvep+k+2],
                                          [lenvep+k+2,lenvep+k+3],[lenvep+k+3,lenvep+k+4],
                                          [lenvep+k+4,lenvep+k+5],[lenvep+k+5,lenvep+k+6],
                                          [lenvep+k+6,lenvep+k+7],[lenvep+k+7,lenvep+k+8],
                                          [lenvep+k+8,lenvep+k+9]]
                                # наполнение списков lenvep = length(vecp)
                                newinds1.extend([[l1, lenvep+k], [lenvep+k+9, r1]])
                                newinds2.extend([[l2, lenvep+k+9], [lenvep+k, r2]])
                                '''Вектора'''
                                thick_3 = thick/3
                                thick_6 = thick/6
                                round1 = Vector((0,0,doflip*thick_3))
                                round2 = Vector((0,0,doflip*thick_3*sinuso30))
                                round2_= direction/3 + direction*(2*sinuso60/3)
                                round3 = Vector((0,0,doflip*thick_3*sinuso60_minus))
                                round3_= direction/3 + direction*(2*sinuso30/3)
                                round4 = direction/3
                                vupperob.extend([two-direction-Vector((0,0,lz2)),
                                                 three+round1-direction, three+round2-round2_,
                                                 three+round3-round3_, three-round4,
                                                 three+round4, three+round3+round3_,
                                                 three+round2+round2_, three+round1+direction,
                                                 two+direction-Vector((0,0,rz2))])
                                vlowerob.extend([one+direction-Vector((0,0,rz1)),
                                                 three-round1-direction, three-round2-round2_,
                                                 three-round3-round3_, three-round4,
                                                 three+round4, three-round3+round3_,
                                                 three-round2+round2_, three-round1+direction,
                                                 one-direction-Vector((0,0,lz1))])
                                k += 10
                            else:
                                '''рёбра'''
                                # пазы формируем независимо от верх низ
                                outeob1 = [[lenvep+k,lenvep+k+1],[lenvep+k+1,lenvep+k+2],[lenvep+k+2,lenvep+k+3]]
                                outeob2 = [[lenvep+k,lenvep+k+1],[lenvep+k+1,lenvep+k+2],[lenvep+k+2,lenvep+k+3]]
                                # наполнение списков lenvep = length(vecp)
                                newinds1.extend([[l1, lenvep+k], [lenvep+k+3, r1]])
                                newinds2.extend([[l2, lenvep+k+3], [lenvep+k, r2]])
                                '''Вектора'''
                                vupperob.extend([two-direction-Vector((0,0,lz2)), three-direction, 
                                                 three+direction, two+direction-Vector((0,0,rz2))])
                                vlowerob.extend([one+direction-Vector((0,0,rz1)), three+direction,
                                                 three-direction, one-direction-Vector((0,0,lz1))])
                                k += 4
                            newinds1.extend(outeob1)
                            newinds2.extend(outeob2)
                    del tree
                    for e in deledges1:
                        if e in newinds1:
                            newinds1.remove(e)
                    for e in deledges2:
                        if e in newinds2:
                            newinds2.remove(e)
                    if vupperob or vlowerob:
                        outeup.append(newinds2)
                        outelo.append(newinds1)
                        vupper.append(vupperob)
                        vlower.append(vlowerob)
                vupper = Vector_degenerate(vupper)
                vlower = Vector_degenerate(vlower)
                
                if 'vupper' in self.outputs and self.outputs['vupper'].links:
                    out = dataCorrect(vupper)
                    SvSetSocketAnyType(self, 'vupper', out)
                if 'outeup' in self.outputs and self.outputs['outeup'].links:
                    SvSetSocketAnyType(self, 'outeup', outeup)
                if 'vlower' in self.outputs and self.outputs['vlower'].links:
                    SvSetSocketAnyType(self, 'vlower', vlower)
                if 'outelo' in self.outputs and self.outputs['outelo'].links:
                    SvSetSocketAnyType(self, 'outelo', outelo)
                print(self.name, 'is finishing')