def get_coplanar(self,vec, loc_cont, norm_cont,vec_cont): ''' if coplanar - than make flip cutting up-bottom ''' for locon, nocon, vecon in zip(loc_cont,norm_cont,vec_cont): x = [i[0] for i in vecon] y = [i[1] for i in vecon] con_domein = vec[0]<max(x) and vec[0]>min(x) and vec[1]<max(y) and vec[1]>min(y) if con_domein: a = abs(D2P(vec,locon[0],nocon[0])) if a < 0.001: return True return False
def process(self): 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() if len(edgplan[0][0]) > 2: edgplan = pols_edges(edgplan) thick = self.inputs['thick'].sv_get()[0][0] threshold_coplanar = 0.005 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 = [list(e) for e in edgp] newinds2 = newinds1.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_: if not v: continue # 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 < threshold_coplanar 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 # rounded section 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 # streight section 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) # circles to bing panels section 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 # TUBE section if vec_tube and not tubes_flag_bed_solution_i_know: for v in vec_tube: tubeverlength = len(v) if tubeverlength == 2: 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 else: tubeshift = tubeverlength // 2 crcl_cntr = IL2P( v[0], v[tubeshift], 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(tubeshift - 1) ] outeob.append([ lenvep + k, lenvep + k + tubeshift - 1 ]) newinds1.extend(outeob) newinds2.extend(outeob) for tubevert in range( tubeshift): tubevert_out = IL2P( v[tubevert], v[tubevert + tubeshift], l, n) vupperob.append( tubevert_out) vlowerob.append( tubevert_out) k += tubeshift tubes_flag_bed_solution_i_know = True elif cop < threshold_coplanar 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 'vert' in self.outputs: if self.out_up_down == 'Up': out = dataCorrect(vupper) else: out = dataCorrect(vlower) self.outputs['vert'].sv_set(out) if 'edge' in self.outputs and self.outputs['edge'].links: if self.out_up_down == 'Up': self.outputs['edge'].sv_set(outeup) else: self.outputs['edge'].sv_set(outelo) if 'centers' in self.outputs and self.outputs['centers'].links: self.outputs['centers'].sv_set(centers) print(self.name, 'is finishing')
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')