def update(self): if 'Size' in self.inputs and self.inputs['Size'].links: size = SvGetSocketAnyType(self, self.inputs['Size'])[0] else: size = [self.Size] if 'Divx' in self.inputs and self.inputs['Divx'].links: divx = int(SvGetSocketAnyType(self, self.inputs['Divx'])[0][0]) else: divx = self.Divx if 'Divy' in self.inputs and self.inputs['Divy'].links: divy = int(SvGetSocketAnyType(self, self.inputs['Divy'])[0][0]) else: divy = self.Divy if 'Divz' in self.inputs and self.inputs['Divz'].links: divz = int(SvGetSocketAnyType(self, self.inputs['Divz'])[0][0]) else: divz = self.Divz out = [a for a in (zip(*[self.makecube(s, divx, divy, divz) for s in size]))] # outputs if 'Vers' in self.outputs and self.outputs['Vers'].links: SvSetSocketAnyType(self, 'Vers', out[0]) if 'Edgs' in self.outputs and self.outputs['Edgs'].links: SvSetSocketAnyType(self, 'Edgs', out[1]) if 'Pols' in self.outputs and self.outputs['Pols'].links: SvSetSocketAnyType(self, 'Pols', out[2])
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)
def update(self): multi_socket(self, min=2) if 'x0' in self.inputs and len(self.inputs['x0'].links) > 0: inputsocketname = self.inputs[0].name outputsocketname = [ 'data', ] changable_sockets(self, inputsocketname, outputsocketname) if 'data' in self.outputs and len(self.outputs['data'].links) > 0: if 'x0' in self.inputs and len(self.inputs['x0'].links) > 0: X = SvGetSocketAnyType(self, self.inputs['data']) slots = [] for socket in self.inputs: if socket.links: slots.append(SvGetSocketAnyType(self, socket)) if len(slots) < 2: return X_ = dataCorrect(X) result = [] for socket in slots: result.extend(self.f(X_, dataCorrect(socket))) SvSetSocketAnyType(self, 'data', result)
def update(self): # inputs if 'Vertices' in self.inputs and self.inputs['Vertices'].links: Vertices = SvGetSocketAnyType(self, self.inputs['Vertices']) else: Vertices = [] if 'Vert A' in self.inputs and self.inputs['Vert A'].links: Vert_A = SvGetSocketAnyType(self, self.inputs['Vert A'])[0] else: Vert_A = [[0.0, 0.0, 0.0]] if 'Vert B' in self.inputs and self.inputs['Vert B'].links: Vert_B = SvGetSocketAnyType(self, self.inputs['Vert B'])[0] else: Vert_B = [[1.0, 0.0, 0.0]] if 'Plane' in self.inputs and self.inputs['Plane'].links: Plane = SvGetSocketAnyType(self, self.inputs['Plane']) else: Plane = [Matrix()] # outputs if 'Vertices' in self.outputs and self.outputs['Vertices'].links: if self.mode == 'VERTEX': parameters = match_long_repeat([Vertices, Vert_A]) points = [mirrorPoint(v, a) for v, a in zip(*parameters)] SvSetSocketAnyType(self, 'Vertices', points) elif self.mode == 'AXIS': parameters = match_long_repeat([Vertices, Vert_A, Vert_B]) points = [mirrorAxis(v, a, b) for v, a, b in zip(*parameters)] SvSetSocketAnyType(self, 'Vertices', points) elif self.mode == 'PLANE': parameters = match_long_repeat([Vertices, Plane]) points = [mirrorPlane(v, p) for v, p in zip(*parameters)] SvSetSocketAnyType(self, 'Vertices', points)
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)
def update(self): # inputs if 'Count' in self.inputs and self.inputs['Count'].links and \ type(self.inputs['Count'].links[0].from_socket) == bpy.types.StringsSocket: Coun = SvGetSocketAnyType(self, self.inputs['Count'])[0] else: Coun = [self.count_inner] if 'Seed' in self.inputs and self.inputs['Seed'].links and \ type(self.inputs['Seed'].links[0].from_socket) == bpy.types.StringsSocket: Seed = SvGetSocketAnyType(self, self.inputs['Seed'])[0] else: Seed = [self.seed] # outputs if 'Random' in self.outputs and self.outputs['Random'].links: Random = [] param = match_long_repeat([Coun, Seed]) # set seed, protect against float input # seed = 0 is special value for blender which unsets the seed value # and starts to use system time making the random values unrepeatable. # So when seed = 0 we use a random value far from 0, generated used random.org for c, s in zip(*param): int_seed = int(round(s)) if int_seed: seed_set(int_seed) else: seed_set(140230) Random.append([ random_unit_vector().to_tuple() for i in range(int(max(1, c))) ]) SvSetSocketAnyType(self, 'Random', Random)
def update(self): # достаём два слота - вершины и полики if 'Data' in self.inputs and self.inputs['Data'].links: inputsocketname = 'Data' outputsocketname = [ 'Data', ] changable_sockets(self, inputsocketname, outputsocketname) data = SvGetSocketAnyType(self, self.inputs['Data']) if 'Number' in self.inputs and self.inputs['Number'].links: tmp = SvGetSocketAnyType(self, self.inputs['Number']) Number = tmp[0] else: Number = [self.number] if 'Data' in self.outputs and self.outputs['Data'].links: out_ = self.count(data, self.level, Number) if self.unwrap: if len(out_) > 0: out = [] for o in out_: out.extend(o) else: out = out_ SvSetSocketAnyType(self, 'Data', out)
def update(self): # inputs if 'Radius' in self.inputs and self.inputs['Radius'].links: Radius = SvGetSocketAnyType(self, self.inputs['Radius'])[0] else: Radius = [self.rad_] if 'Nº Vertices' in self.inputs and self.inputs['Nº Vertices'].links: Vertices = SvGetSocketAnyType(self, self.inputs['Nº Vertices'])[0] Vertices = list(map(lambda x: max(3, int(x)), Vertices)) else: Vertices = [self.vert_] if 'Degrees' in self.inputs and self.inputs['Degrees'].links: Angle = SvGetSocketAnyType(self, self.inputs['Degrees'])[0] Angle = list(map(lambda x: min(360, max(0, x)), Angle)) else: # okay this is silly but since the rest was written before this gave degrees. Angle = [degrees(self.degr_)] parameters = match_long_repeat([Angle, Vertices, Radius]) # outputs if 'Vertices' in self.outputs and self.outputs['Vertices'].links: points = [self.make_verts(a, v, r) for a, v, r in zip(*parameters)] SvSetSocketAnyType(self, 'Vertices', points) if 'Edges' in self.outputs and self.outputs['Edges'].links: edg = [self.make_edges(v, a) for a, v, r in zip(*parameters)] SvSetSocketAnyType(self, 'Edges', edg) if 'Polygons' in self.outputs and self.outputs['Polygons'].links: plg = [self.make_faces(a, v) for a, v, r in zip(*parameters)] SvSetSocketAnyType(self, 'Polygons', plg)
def update(self): # достаём два слота - вершины и полики if 'Centers' in self.outputs and self.outputs[ 'Centers'].links or self.outputs['Normals'].links: if 'Polygons' in self.inputs and 'Vertices' in self.inputs and self.inputs[ 'Polygons'].links and self.inputs['Vertices'].links: #if type(self.inputs['Poligons'].links[0].from_socket) == StringsSocket: pols = SvGetSocketAnyType(self, self.inputs['Polygons']) #if type(self.inputs['Vertices'].links[0].from_socket) == VerticesSocket: vers = SvGetSocketAnyType(self, self.inputs['Vertices']) normalsFORout = [] for i, obj in enumerate(vers): mesh_temp = bpy.data.meshes.new('temp') mesh_temp.from_pydata(obj, [], pols[i]) mesh_temp.update(calc_edges=True) tempobj = [] for v in mesh_temp.vertices: tempobj.append(v.normal[:]) normalsFORout.append(tempobj) bpy.data.meshes.remove(mesh_temp) #print (normalsFORout) if 'Normals' in self.outputs and self.outputs['Normals'].links: SvSetSocketAnyType(self, 'Normals', normalsFORout)
def update(self): # inputs if 'vertices' in self.outputs and self.outputs['vertices'].links or \ 'edg_pol' in self.outputs and self.outputs['edg_pol'].links: if 'vertices' in self.inputs and self.inputs['vertices'].links and \ 'edg_pol' in self.inputs and self.inputs['edg_pol'].links: vertices = SvGetSocketAnyType(self, self.inputs['vertices']) edgs_pols = SvGetSocketAnyType(self, self.inputs['edg_pol']) else: return vert_out = [] edpo_out = [] for k, ob in enumerate(edgs_pols): for ep in ob: new_vers = [] new_edpo = [] for i, index in enumerate(ep): new_vers.append(vertices[k][index]) new_edpo.append(i) vert_out.append(new_vers) edpo_out.append([new_edpo]) if 'vertices' in self.outputs and self.outputs['vertices'].links: SvSetSocketAnyType(self, 'vertices', vert_out) if 'edg_pol' in self.outputs and self.outputs['edg_pol'].links: SvSetSocketAnyType(self, 'edg_pol', edpo_out)
def update(self): if 'polygons' not in self.outputs: return if 'vertices' in self.inputs and self.inputs['vertices'].links and \ 'edges' in self.inputs and self.inputs['edges'].links: verts = dataCorrect( SvGetSocketAnyType(self, self.inputs['vertices'])) edges = dataCorrect(SvGetSocketAnyType(self, self.inputs['edges'])) sides = repeat_last(self.inputs['Sides'].sv_get()[0]) verts_out = [] edges_out = [] polys_out = [] for v, e, s in zip(verts, edges, sides): res = fill_holes(v, e, int(s)) if not res: return verts_out.append(res[0]) edges_out.append(res[1]) polys_out.append(res[2]) if 'vertices' in self.outputs and self.outputs['vertices'].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)
def update(self): if not ('Edges' in self.outputs): return # inputs if self.outputs['Edges'].links or self.outputs['Vertices'].links: if self.inputs['Level'].links: Integer = int( SvGetSocketAnyType(self, self.inputs['Level'])[0][0]) else: Integer = self.level_ if self.inputs['Size'].links: Step = SvGetSocketAnyType(self, self.inputs['Size'])[0][0] else: Step = self.size_ # outputs if self.outputs['Vertices'].links: verts = self.hilbert(Step, Integer) SvSetSocketAnyType(self, 'Vertices', verts) if self.outputs['Edges'].links: listEdg = [] r = len(verts[0]) - 1 for i in range(r): listEdg.append((i, i + 1)) edg = list(listEdg) SvSetSocketAnyType(self, 'Edges', [edg])
def update(self): if 'Vertices' in self.inputs and self.inputs['Vertices'].links and \ 'PolyEdge' in self.inputs and self.inputs['PolyEdge'].links: verts = SvGetSocketAnyType(self, self.inputs['Vertices']) poly_edge = SvGetSocketAnyType(self, self.inputs['PolyEdge']) verts_out = [] poly_edge_out = [] offset = 0 for obj in zip(verts, poly_edge): verts_out.extend(obj[0]) if offset: res = [ list(map(lambda x: operator.add(offset, x), ep)) for ep in obj[1] ] poly_edge_out.extend(res) else: poly_edge_out.extend(obj[1]) offset += len(obj[0]) if 'Vertices' in self.outputs and self.outputs['Vertices'].links: SvSetSocketAnyType(self, 'Vertices', [verts_out]) if 'PolyEdge' in self.outputs and self.outputs['PolyEdge'].links: SvSetSocketAnyType(self, 'PolyEdge', [poly_edge_out])
def update(self): if 'Data' in self.inputs and len(self.inputs['Data'].links) > 0: inputsocketname = 'Data' outputsocketname = ['Item', 'Other'] changable_sockets(self, inputsocketname, outputsocketname) if 'Item' in self.outputs and self.outputs['Item'].links or \ 'Other' in self.outputs and self.outputs['Other'].links: if 'Data' in self.inputs and self.inputs['Data'].links: data = SvGetSocketAnyType(self, self.inputs['Data']) if 'Item' in self.inputs and self.inputs['Item'].links: items = SvGetSocketAnyType(self, self.inputs['Item']) else: items = [[self.item]] if 'Item' in self.outputs and self.outputs['Item'].links: if self.level - 1: out = self.get(data, self.level - 1, items, self.get_items) else: out = self.get_items(data, items[0]) SvSetSocketAnyType(self, 'Item', out) if 'Other' in self.outputs and self.outputs['Other'].links: if self.level - 1: out = self.get(data, self.level - 1, items, self.get_other) else: out = self.get_other(data, items[0]) SvSetSocketAnyType(self, 'Other', out)
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', [])
def update(self): # inputs if 'Start' in self.inputs and self.inputs['Start'].links: tmp = SvGetSocketAnyType(self, self.inputs['Start']) Start = tmp[0][0] else: Start = self.start_ if 'Stop' in self.inputs and self.inputs['Stop'].links: tmp = SvGetSocketAnyType(self, self.inputs['Stop']) Stop = tmp[0][0] else: Stop = self.stop_ if 'Divisions' in self.inputs and self.inputs['Divisions'].links: tmp = SvGetSocketAnyType(self, self.inputs['Divisions']) Divisions = tmp[0][0] else: Divisions = self.divisions_ # outputs if 'Range' in self.outputs and self.outputs['Range'].links: if Divisions < 2: Divisions = 2 Range = [Start] if Divisions > 2: Range.extend([c for c in self.xfrange(Start, Stop, Divisions)]) Range.append(Stop) SvSetSocketAnyType(self, 'Range', [Range])
def update(self): # inputs if 'Start' in self.inputs and self.inputs['Start'].links: tmp = SvGetSocketAnyType(self, self.inputs['Start']) Start = tmp[0][0] else: Start = self.start_ if 'Stop' in self.inputs and self.inputs['Stop'].links: tmp = SvGetSocketAnyType(self, self.inputs['Stop']) Stop = tmp[0][0] else: Stop = self.stop_ if 'Step' in self.inputs and self.inputs['Step'].links: tmp = SvGetSocketAnyType(self, self.inputs['Step']) Step = tmp[0][0] else: Step = self.step_ # outputs if 'Series' in self.outputs and len(self.outputs['Series'].links) > 0: #print (Start, Stop, Step) if Step < 0: Step = 1 if Stop < Start: Stop = Start+1 series = [c for c in self.xfrange(Start, Stop, Step)] SvSetSocketAnyType(self, 'Series', [series])
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)
def update(self): global cache_viewer_baker # node id, used as ref n_id = node_id(self) if 'matrix' not in self.inputs: return cache_viewer_baker[n_id+'v'] = [] cache_viewer_baker[n_id+'ep'] = [] cache_viewer_baker[n_id+'m'] = [] if not self.id_data.sv_show: callback_disable(n_id) return if self.activate and (self.inputs['vertices'].links or self.inputs['matrix'].links): callback_disable(n_id) if self.inputs['vertices'].links and \ type(self.inputs['vertices'].links[0].from_socket) == VerticesSocket: propv = SvGetSocketAnyType(self, self.inputs['vertices']) cache_viewer_baker[n_id+'v'] = dataCorrect(propv) else: cache_viewer_baker[n_id+'v'] = [] if self.inputs['edg_pol'].links and \ type(self.inputs['edg_pol'].links[0].from_socket) == StringsSocket: prope = SvGetSocketAnyType(self, self.inputs['edg_pol']) cache_viewer_baker[n_id+'ep'] = dataCorrect(prope) #print (prope) else: cache_viewer_baker[n_id+'ep'] = [] if self.inputs['matrix'].links and \ type(self.inputs['matrix'].links[0].from_socket) == MatrixSocket: propm = SvGetSocketAnyType(self, self.inputs['matrix']) cache_viewer_baker[n_id+'m'] = dataCorrect(propm) else: cache_viewer_baker[n_id+'m'] = [] else: callback_disable(n_id) if cache_viewer_baker[n_id+'v'] or cache_viewer_baker[n_id+'m']: callback_enable(n_id, cache_viewer_baker[n_id+'v'], cache_viewer_baker[n_id+'ep'], \ cache_viewer_baker[n_id+'m'], self.Vertex_show, self.color_view.copy(), self.transparant, self.shading) self.use_custom_color = True self.color = (1, 0.3, 0) else: self.use_custom_color = True self.color = (0.1, 0.05, 0) #print ('отражения вершин ',len(cache_viewer_baker['v']), " рёбёры ", len(cache_viewer_baker['ep']), "матрицы",len(cache_viewer_baker['m'])) if not self.inputs['vertices'].links and not self.inputs['matrix'].links: callback_disable(n_id)
def update(self): # inputs ch = self.check_slots(1) if ch: for c in ch[:-1]: self.inputs.remove(self.inputs[ch[0]]) if 'X' in self.inputs and self.inputs['X'].links: vecs = SvGetSocketAnyType(self, self.inputs['X']) else: vecs = [[0.0]] list_mult = [] for idx, multi in enumerate(self.inputs[1:]): if multi.links and \ type(multi.links[0].from_socket) == StringsSocket: mult = SvGetSocketAnyType(self, multi) ch = self.check_slots(2) if not ch: self.inputs.new('StringsSocket', 'n[.]', "n[.]") list_mult.extend(mult) if len(list_mult) == 0: list_mult = [[0.0]] # outputs if 'Result' in self.outputs and self.outputs['Result'].links: code_formula = parser.expr(self.formula).compile() r_ = [] result = [] max_l = 0 for list_m in list_mult: l1 = len(list_m) max_l = max(max_l, l1) max_l = max(max_l, len(vecs[0])) for list_m in list_mult: d = max_l - len(list_m) if d > 0: for d_ in range(d): list_m.append(list_m[-1]) lres = [] for l in range(max_l): ltmp = [] for list_m in list_mult: ltmp.append(list_m[l]) lres.append(ltmp) r = self.inte(vecs, code_formula, lres) result.extend(r) SvSetSocketAnyType(self, 'Result', result)
def get_data(self): out = "" if self.text_mode == 'CSV': data_out = [] for socket in self.inputs: if socket.links and \ type(socket.links[0].from_socket) == StringsSocket: tmp = SvGetSocketAnyType(self, socket) if tmp: # flatten list data_out.extend( list(itertools.chain.from_iterable([tmp]))) csv_str = io.StringIO() writer = csv.writer(csv_str, dialect=self.csv_dialect) for row in zip(*data_out): writer.writerow(row) out = csv_str.getvalue() elif self.text_mode == 'JSON': data_out = {} name_dict = {'m': 'Matrix', 's': 'Data', 'v': 'Vertices'} for socket in self.inputs: if socket.links: tmp = SvGetSocketAnyType(self, socket) if tmp: tmp_name = socket.links[ 0].from_node.name + ':' + socket.links[ 0].from_socket.name name = tmp_name j = 1 while name in data_out: # unique names for json name = tmp_name + str(j) j += 1 data_out[name] = (get_socket_type(self, socket.name), tmp) if self.json_mode == 'pretty': out = json.dumps(data_out, indent=4) else: # compact out = json.dumps(data_out, separators=(',', ':')) elif self.text_mode == 'SV': if self.inputs['Data'].links: data = SvGetSocketAnyType(self, self.inputs['Data']) if self.sv_mode == 'pretty': out = pprint.pformat(data) else: # compact out = str(data) return out
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)
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
def update(self): # changable types sockets in output # you need the next: # typ - needed self value # newsocket - needed self value # inputsocketname to get one socket to define type # outputsocketname to get list of outputs, that will be changed inputsocketname = 'data' outputsocketname = ['dataTrue', 'dataFalse'] changable_sockets(self, inputsocketname, outputsocketname) # input sockets if 'data' not in self.inputs: return False data = [[]] mask = [[1, 0]] if self.inputs['data'].links: data = SvGetSocketAnyType(self, self.inputs['data']) if self.inputs['mask'].links and \ type(self.inputs['mask'].links[0].from_socket) == StringsSocket: mask = SvGetSocketAnyType(self, self.inputs['mask']) result = self.getMask(data, mask, self.Level) # outupy sockets data if 'dataTrue' in self.outputs and self.outputs['dataTrue'].is_linked: SvSetSocketAnyType(self, 'dataTrue', result[0]) else: SvSetSocketAnyType(self, 'dataTrue', [[]]) # print ('всё',result) if 'dataFalse' in self.outputs and self.outputs['dataFalse'].is_linked: SvSetSocketAnyType(self, 'dataFalse', result[1]) else: SvSetSocketAnyType(self, 'dataFalse', [[]]) if 'mask' in self.outputs and self.outputs['mask'].is_linked: SvSetSocketAnyType(self, 'mask', result[2]) else: SvSetSocketAnyType(self, 'mask', [[]]) if 'ind_true' in self.outputs and self.outputs['ind_true'].is_linked: SvSetSocketAnyType(self, 'ind_true', result[3]) else: SvSetSocketAnyType(self, 'ind_true', [[]]) if 'ind_false' in self.outputs and self.outputs['ind_false'].is_linked: SvSetSocketAnyType(self, 'ind_false', result[4]) else: SvSetSocketAnyType(self, 'ind_false', [[]])
def update(self): # inputs VerticesA = [] VerticesB = [] factor = [] if 'Vertice A' in self.inputs and self.inputs['Vertice A'].links: VerticesA = SvGetSocketAnyType(self, self.inputs['Vertice A']) if 'Vertice B' in self.inputs and self.inputs['Vertice B'].links: VerticesB = SvGetSocketAnyType(self, self.inputs['Vertice B']) if 'Factor' in self.inputs and self.inputs['Factor'].links: factor = SvGetSocketAnyType(self, self.inputs['Factor']) if not (VerticesA and VerticesB): return if not factor: factor = [[self.factor_]] # outputs if 'EvPoint' in self.outputs and self.outputs['EvPoint'].links: points = [] # match inputs using fullList, longest list matching on A and B # extend factor list if necessary, it should not control length of output max_obj = max(len(VerticesA), len(VerticesB)) fullList(VerticesA, max_obj) fullList(VerticesB, max_obj) if len(factor) < max_obj: fullList(factor, max_obj) for i in range(max_obj): points_ = [] max_l = max(len(VerticesA[i]), len(VerticesB[i])) fullList(VerticesA[i], max_l) fullList(VerticesB[i], max_l) for j in range(max_l): tmp_pts = [(Vector(VerticesA[i][j]).lerp(VerticesB[i][j], factor[i][k]))[:] for k in range(len(factor[i]))] points_.extend(tmp_pts) points.append(points_) if not points: return SvSetSocketAnyType(self, 'EvPoint', points)
def update(self): # inputs A = [] B = [] factor = [] # 0 is valid value so I use [] as placeholder if 'A' in self.inputs and self.inputs['A'].links and \ type(self.inputs['A'].links[0].from_socket) == MatrixSocket: A = Matrix_generate(SvGetSocketAnyType(self, self.inputs['A'])) if not A: A = [Matrix.Identity(4)] if 'B' in self.inputs and self.inputs['B'].links and \ type(self.inputs['B'].links[0].from_socket) == MatrixSocket: B = Matrix_generate(SvGetSocketAnyType(self, self.inputs['B'])) if not B: B = [Matrix.Identity(4)] if 'Factor' in self.inputs and self.inputs['Factor'].links and \ type(self.inputs['Factor'].links[0].from_socket) == StringsSocket: factor = SvGetSocketAnyType(self, self.inputs['Factor']) if not factor: factor = [[self.factor_]] if 'C' in self.outputs and self.outputs['C'].links: matrixes_ = [] # match inputs, first matrix A and B using fullList # then extend the factor list if necessary, # A and B should control length of list, not interpolation lists max_l = max(len(A), len(B)) fullList(A, max_l) fullList(B, max_l) if len(factor) < max_l: fullList(factor, max_l) for i in range(max_l): for k in range(len(factor[i])): matrixes_.append(A[i].lerp(B[i], factor[i][k])) if not matrixes_: return matrixes = Matrix_listing(matrixes_) SvSetSocketAnyType(self, 'C', matrixes)
def update(self): # check if running during startup, cancel if True try: l = bpy.data.node_groups[self.id_data.name] except Exception as e: print("Bakery cannot run during startup", e) return if self.inputs['vertices'].links and self.inputs['edg_pol'].links and self.activate: if 'vertices' in self.inputs and self.inputs['vertices'].links and \ type(self.inputs['vertices'].links[0].from_socket) == VerticesSocket: propv = SvGetSocketAnyType(self, self.inputs['vertices']) vertices = dataCorrect(propv, nominal_dept=2) else: vertices = [] if 'edg_pol' in self.inputs and self.inputs['edg_pol'].links and \ type(self.inputs['edg_pol'].links[0].from_socket) == StringsSocket: prope = SvGetSocketAnyType(self, self.inputs['edg_pol']) edges = dataCorrect(prope) else: edges = [] if 'matrix' in self.inputs and self.inputs['matrix'].links and \ type(self.inputs['matrix'].links[0].from_socket) == MatrixSocket: propm = SvGetSocketAnyType(self, self.inputs['matrix']) matrices = dataCorrect(propm) else: matrices = [] if vertices and edges: for i in vertices: matrices.append(Matrix()) if vertices and edges: self.makeobjects(vertices, edges, matrices) self.use_custom_color = True self.color = (1, 0.3, 0) else: self.use_custom_color = True self.color = (0.1, 0.05, 0) for obj in bpy.context.scene.objects: nam = 'Sv_' + self.name if nam in obj.name: bpy.context.scene.objects[obj.name].select = True bpy.ops.object.delete(use_global=False) global sverchok_bakery_cache sverchok_bakery_cache[self.name] = []
def update(self): if self.inputs['Data'].links: # адаптивный сокет inputsocketname = 'Data' outputsocketname = ["Middl", 'First', 'Last'] changable_sockets(self, inputsocketname, outputsocketname) if 'First' in self.outputs and self.outputs['First'].links or \ 'Last' in self.outputs and self.outputs['Last'].links or \ 'Middl' in self.outputs and self.outputs['Middl'].links: data = SvGetSocketAnyType(self, self.inputs['Data']) # blocking too height values of levels, reduce levels = levelsOflist(data) - 2 if levels >= self.level: levels = self.level - 1 elif levels < 1: levels = 1 # assign out if self.outputs['First'].links: out = self.count(data, levels, 0) SvSetSocketAnyType(self, 'First', out) if self.outputs['Middl'].links: out = self.count(data, levels, 1) SvSetSocketAnyType(self, 'Middl', out) if self.outputs['Last'].links: out = self.count(data, levels, 2) SvSetSocketAnyType(self, 'Last', out)
def update(self): if 'data' in self.inputs and self.inputs['data'].links: # get any type socket from input: data = SvGetSocketAnyType(self, self.inputs['data']) # Process data leve = min((levelsOflist(data) - 2), self.level) result = self.beat(data, leve, leve) # multisocket - from util(formula node) multi_socket(self, min=1, start=2, breck=True, output=len(result)) # adaptive socket - from util(mask list node) # list to pack and change type of multysockets in output... maybe not so quick outputsocketname = [name.name for name in self.outputs] changable_sockets(self, 'data', outputsocketname) self.multi_socket_type = get_socket_type_full(self, 'data') # how to assign correct property to adaptive output: # in nearest future with socket's data' dictionary we will send # only node_name+layout_name+socket_name in str() format # and will make separate definition to easyly assign and # get and recognise data from dictionary for i, out in enumerate(result): SvSetSocket(self.outputs[i], out) if i >= 32: break
def update(self): # inputs if len(self.outputs['Edges'].links) > 0 or len( self.outputs['Vertices'].links) > 0: if len(self.inputs['Level'].links) > 0: Integer = int( SvGetSocketAnyType(self, self.inputs['Level'])[0][0]) else: Integer = self.level_ if len(self.inputs['Size'].links) > 0: Step = eval(self.inputs['Size'].links[0].from_socket. StringsProperty)[0][0] else: Step = self.size_ # outputs if 'Vertices' in self.outputs and len( self.outputs['Vertices'].links) > 0: verts = self.hilbert(0.0, 0.0, Step * 1.0, 0.0, 0.0, Step * 1.0, Integer) self.outputs['Vertices'].VerticesProperty = str([verts]) if 'Edges' in self.outputs and len(self.outputs['Edges'].links) > 0: listEdg = [] r = len(verts) - 1 for i in range(r): listEdg.append((i, i + 1)) edg = list(listEdg) self.outputs['Edges'].StringsProperty = str([edg])
def update(self): # inputs multi_socket(self, min=1) if 'data' in self.inputs and len(self.inputs['data'].links) > 0: inputsocketname = 'data' outputsocketname = ['data'] changable_sockets(self, inputsocketname, outputsocketname) if 'data' in self.outputs and self.outputs['data'].links: slots = [] for socket in self.inputs: if socket.links: slots.append(SvGetSocketAnyType(self, socket)) if len(slots) == 0: return list_result = joiner(slots, self.JoinLevel) result = list_result.copy() if self.mix_check: list_mix = myZip_2(slots, self.JoinLevel) result = list_mix.copy() if self.wrap_check: list_wrap = wrapper_2(slots, list_result, self.JoinLevel) result = list_wrap.copy() if self.mix_check: list_wrap_mix = wrapper_2(slots, list_mix, self.JoinLevel) result = list_wrap_mix.copy() SvSetSocketAnyType(self, 'data', result)
def update(self): outputs = self.outputs ''' - is hnd_edges socket created, means all sockets exist. - is anything connected to the Verts socket? ''' if not (('hnd Edges' in outputs) and (outputs['Verts'].links)): return ''' operational scheme: (spline = handle set (k1, ctrl1, ctrl2, k2)) - num_vert can be given per spline - if no num_vert is given, default is used for all splines - if node receives more splines than items in num_vert list, last is re-used. - each (k1 ctrl1 ctrl2 k2) must have input - the length of (k1 ctrl1 ctrl2 k2) individually must be equal (no last used) ''' inputs = self.inputs handle_names = ['knot_1', 'ctrl_1', 'ctrl_2', 'knot_2'] if not all([inputs[p].links for p in handle_names]): return # assume they all match, reduce cycles used for checking. handle_sockets = (inputs[handle_names[i]] for i in range(4)) handle_data = [] for socket in handle_sockets: v = [] if isinstance(socket.links[0].from_socket, VerticesSocket): v = SvGetSocketAnyType(self, socket, deepcopy=False)[0] handle_data.append(v) knots_1, ctrls_1, ctrls_2, knots_2 = handle_data if not (len(knots_1) == len(ctrls_1) == len(ctrls_2) == len(knots_2)): return # get vert_nums, or pad till matching quantity nv = [] nv_links = inputs['num_verts'].links if nv_links: if isinstance(nv_links[0].from_socket, StringsSocket): nv = SvGetSocketAnyType(self, inputs['num_verts'], deepcopy=False)[0] if nv and (len(nv) < len(knots_1)): pad_num = len(knots_1) - len(nv) for i in range(pad_num): nv.append(nv[-1]) else: for i in range(len(knots_1)): nv.append(self.num_verts) # iterate over them verts_out = [] edges_out = [] h_verts_out = [] h_edges_out = [] for idx, handle_set in enumerate(zip(knots_1, ctrls_1, ctrls_2, knots_2)): divisions = nv[idx] if idx < len(nv) else 3 v, e = generate_bezier(handle_set, divisions) verts_out.append(v) edges_out.append(e) # for visual h_verts_out.append(handle_set) h_edges_out.append([(0, 1), (2, 3)]) # reaches here if we got usable data. SvSetSocketAnyType(self, 'Verts', verts_out) if outputs['Edges'].links: SvSetSocketAnyType(self, 'Edges', edges_out) # optional, show handles. this is useful for visual debug. if outputs['hnd Verts'].links: SvSetSocketAnyType(self, 'hnd Verts', h_verts_out) if outputs['hnd Edges'].links: SvSetSocketAnyType(self, 'hnd Edges', h_edges_out)
def update(self): outputs = self.outputs inputs = self.inputs ''' - is Edges socket created, means all sockets exist. - is anything connected to the Verts socket? ''' if not 'Edges' in outputs: return # if not 'Verts' in outputs: # return if not all([outputs['Verts'].links, inputs['arc_pts'].links]): return ''' operational scheme: - input: : each 3 points are 'a' 'b' and 'c', then input must be a flat list of [v1a, v1b, v1c, v2a, v2b, v2c, ....] : len(arc_pts) % 3 === 0, else no processing. - satisfied by input, the output will be n lists of verts+edges - [n = (len(arc_pts) / 3)] ''' # assume they all match, reduce cycles used for checking. v = [] if isinstance(inputs['arc_pts'].links[0].from_socket, VerticesSocket): v = SvGetSocketAnyType(self, inputs['arc_pts'], deepcopy=False)[0] if not (len(v) % 3 == 0): return num_arcs = len(v) // 3 # get vert_nums, or pad till matching quantity nv = [] nv_links = inputs['num_verts'].links if nv_links: if isinstance(nv_links[0].from_socket, StringsSocket): nv = SvGetSocketAnyType(self, inputs['num_verts'], deepcopy=False)[0] if nv and (len(nv) < num_arcs): pad_num = num_arcs - len(nv) for i in range(pad_num): nv.append(nv[-1]) else: for i in range(num_arcs): nv.append(self.num_verts) # do arcs will generated nested lists of arcs(verts+edges) make_edges = True if outputs['Edges'].links else False verts_out, edges_out = make_all_arcs(v, nv, make_edges) # reaches here if we got usable data. SvSetSocketAnyType(self, 'Verts', verts_out) if make_edges: SvSetSocketAnyType(self, 'Edges', edges_out)