Beispiel #1
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, [[]])
Beispiel #2
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)
Beispiel #3
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
Beispiel #4
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
Beispiel #5
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)
Beispiel #6
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]))
Beispiel #7
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')
Beispiel #8
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)
Beispiel #9
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')