def process(self): if not any(s.is_linked for s in self.outputs): return input_num = self.inputs["Num"].sv_get() input_step = self.inputs["Step"].sv_get() c, d = self.center, self.direction stepList = [] res1,res2 = [],[] normal_size = 1.0 if self.normalize: self.upgrade_if_needed() normal_size = self.inputs["Size"].sv_get()[0][0] for n, s in zip(*match_long_repeat([input_num, input_step])): for num in n: num = max(2,num) s = s[:(num - 1)] # shorten if needed fullList(s, num - 1) # extend if needed stepList.append([S * normal_size / sum(s) for S in s] if self.normalize else s) for s in stepList: r1,r2 = make_line(s, c, d) res1.append(r1) res2.append(r2) if self.outputs['Vertices'].is_linked: self.outputs['Vertices'].sv_set(res1) if self.outputs['Edges'].is_linked: self.outputs['Edges'].sv_set(res2)
def generate_callback(self, n_id, IV): inputs = self.inputs verts, matrices = [], [] text = '' # gather vertices from input propv = inputs['vertices'].sv_get() verts = dataCorrect(propv) # end early, no point doing anything else. if not verts: return # draw text on locations instead of indices. text_so = inputs['text'].sv_get(default=[]) text = dataCorrect(text_so) if text: fullList(text, len(verts)) for i, t in enumerate(text): fullList(text[i], len(verts[i])) # read non vertex inputs in a loop and assign to data_collected data_collected = [] for socket in ['edges', 'faces', 'matrix']: propm = inputs[socket].sv_get(default=[]) input_stream = dataCorrect(propm) data_collected.append(input_stream) edges, faces, matrices = data_collected bg = self.draw_bg settings = self.get_settings() IV.callback_enable( n_id, verts, edges, faces, matrices, bg, settings, text)
def make_line(integer, step, center): vertices = [(0.0, 0.0, 0.0)] integer = [int(integer) if type(integer) is not list else int(integer[0])] # center the line: offset the starting point of the line by half its size if center: Nn = integer[0]-1 # number of steps based on the number of vertices Ns = len(step) # number of steps given by the step list # line size (step list & repeated last step if any) size1 = sum(step[:min(Nn, Ns)]) # step list size size2 = max(0, (Nn - Ns)) * step[Ns-1] # repeated last step size size = size1 + size2 # total size # starting point of the line offset by half its size vertices = [(-0.5*size, 0.0, 0.0)] if type(step) is not list: step = [step] fullList(step, integer[0]) for i in range(integer[0]-1): v = Vector(vertices[i]) + Vector((step[i], 0.0, 0.0)) vertices.append(v[:]) edges = [] for i in range(integer[0]-1): edges.append((i, i+1)) return vertices, edges
def process(self): frame = self.inputs[0] coordinates = self.inputs[1] if frame.is_linked and coordinates.is_linked: strokes = frame.sv_get() coords = coordinates.sv_get() self.num_strokes = len(coords) set_correct_stroke_count(strokes, coords) cyclic_socket_value = self.inputs["draw cyclic"].sv_get()[0] fullList(cyclic_socket_value, self.num_strokes) pressures = self.get_pressures() for idx, (stroke, coord_set) in enumerate(zip(strokes, coords)): stroke.draw_mode = self.draw_mode stroke.draw_cyclic = cyclic_socket_value[idx] num_points = len(coord_set) pass_data_to_stroke(stroke, coord_set) flat_pressures = match_points_and_pressures(pressures[idx], num_points) pass_pressures_to_stroke(stroke, flat_pressures) # color.fill_alpha # color.alpha self.outputs[0].sv_set(strokes)
def process(self): if not any(output.is_linked for output in self.outputs): return vertices_s = self.inputs['Vertices'].sv_get(default=[[]]) masks_s = self.inputs['Mask'].sv_get() radius_s = self.inputs['Radius'].sv_get() out_coeffs = [] meshes = match_long_repeat([vertices_s, masks_s, radius_s]) for vertices, masks, radius in zip(*meshes): fullList(masks, len(vertices)) if isinstance(radius, list) and isinstance(radius[0], (int, float)): radius = radius[0] # build KDTree base = [v for v, mask in zip(vertices, masks) if mask] tree = kdtree.KDTree(len(base)) for i, v in enumerate(base): tree.insert(v, i) tree.balance() coeffs = [] for vertex, mask in zip(vertices, masks): if mask: coef = 1.0 else: _, _, rho = tree.find(vertex) coef = self.falloff(radius, rho) coeffs.append(coef) out_coeffs.append(coeffs) self.outputs['Coeffs'].sv_set(out_coeffs)
def sv_main(p=[],m=[]): in_sockets = [ ['s', 'p', p], ['s', 'm', m]] if not m: out_sockets = [ ['s', 'out', []], ['s', 'out_not', p], ] return in_sockets, out_sockets out = [] out_not = [] for opol,omas in zip(p,m): fullList(omas, len(opol)) for mas, pol in zip(omas, opol): if set(mas).intersection(pol): out.append(pol) else: out_not.append(pol) out_sockets = [ ['s', 'out', [out]], ['s', 'out_not', [out_not]], ] return in_sockets, out_sockets
def define_steplist(self, step_list, s, n, nor, normal): for num in n: num = max(2, num) s = s[:(num - 1)] # shorten if needed fullList(s, num - 1) # extend if needed step_list.append([S * nor / sum(s) for S in s] if normal else s)
def process(self): if not any(s.is_linked for s in self.outputs): return input_num = self.inputs["Num"].sv_get() input_step = self.inputs["Step"].sv_get() c, d = self.center, self.direction stepList = [] res1, res2 = [], [] normal_size = 1.0 if self.normalize: self.upgrade_if_needed() normal_size = self.inputs["Size"].sv_get()[0][0] for n, s in zip(*match_long_repeat([input_num, input_step])): for num in n: num = max(2, num) s = s[:(num - 1)] # shorten if needed fullList(s, num - 1) # extend if needed stepList.append([S * normal_size / sum(s) for S in s] if self.normalize else s) for s in stepList: r1, r2 = make_line(s, c, d) res1.append(r1) res2.append(r2) if self.outputs['Vertices'].is_linked: self.outputs['Vertices'].sv_set(res1) if self.outputs['Edges'].is_linked: self.outputs['Edges'].sv_set(res2)
def process(self): # inputs if not self.outputs['EvPoint'].is_linked: return VerticesA = self.inputs['Vertice A'].sv_get() VerticesB = self.inputs['Vertice B'].sv_get() factor = self.inputs['Factor'].sv_get() # outputs # 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) points = [] 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_) self.outputs['EvPoint'].sv_set(points)
def homogenize_input(self, segments, longest): ''' edit segments in place, extend all to match length of longest ''' for letter, letter_dict in segments.items(): if letter_dict['length'] < longest: fullList(letter_dict['data'], longest)
def process(self): if not any((s.is_linked for s in self.outputs)): return if not (self.inputs['vertices'].is_linked and self.inputs['polygons'].is_linked): return verts = self.inputs['vertices'].sv_get() polys = self.inputs['polygons'].sv_get() thickness = self.inputs['thickness'].sv_get() verts_out = [] edges_out = [] polys_out = [] newpo_out = [] fullList(thickness, len(verts)) for v, p, t in zip(verts, polys, thickness): res = solidify(v, p, t) if not res: return verts_out.append(res[0]) edges_out.append(res[1]) polys_out.append(res[2]) newpo_out.append(res[3]) self.outputs['vertices'].sv_set(verts_out) self.outputs['edges'].sv_set(edges_out) self.outputs['polygons'].sv_set(polys_out) self.outputs['newpols'].sv_set(newpo_out)
def process(self): inputs = self.inputs outputs = self.outputs sizes = inputs['vector_size'].sv_get()[0] # sizes determines FullLength num_boxes = len(sizes) radii = inputs['radius'].sv_get()[0] arc_divs = inputs['arcdiv'].sv_get()[0] lin_divs = inputs['lindiv'].sv_get()[0] div_types = inputs['div_type'].sv_get()[0] axis_aligns = inputs['odd_axis_align'].sv_get()[0] fullList(radii, num_boxes) fullList(arc_divs, num_boxes) fullList(lin_divs, num_boxes) fullList(div_types, num_boxes) fullList(axis_aligns, num_boxes) multi_dict = [] for i, args in enumerate(sizes): multi_dict.append({ 'radius': radii[i], 'arcdiv': arc_divs[i], 'lindiv': lin_divs[i], 'size': args, 'div_type': div_types[i], 'odd_axis_align': axis_aligns[i] }) # print(multi_dict[i]) out = list(zip(*[round_cube(**kwargs) for kwargs in multi_dict])) outputs['Vers'].sv_set(out[0]) outputs['Pols'].sv_set(out[1])
def joinvers(ver): ''' for joinvers to one object ''' joinvers = [] for ob in ver: fullList(list(ob), lenvers) joinvers.extend(ob) return joinvers
def process(self): # return if no outputs are connected if not any(s.is_linked for s in self.outputs): return input_num = self.inputs["Num"].sv_get() input_step = self.inputs["Step"].sv_get() params = match_long_repeat([input_num, input_step]) stepList = [] for n, s in zip(*params): num = max(2, n[0]) # sanitize the input # adjust the step list based on number of verts and steps steps = s[:(num - 1)] # shorten if needed fullList(steps, num - 1) # extend if needed if self.normalize: size = self.size / sum(steps) steps = [s * size for s in steps] stepList.append(steps) c, d = self.center, self.direction verts, edges = [ve for ve in zip(*[make_line(s, c, d) for s in stepList])] # outputs if self.outputs['Vertices'].is_linked: self.outputs['Vertices'].sv_set(verts) if self.outputs['Edges'].is_linked: self.outputs['Edges'].sv_set(edges)
def process(self): if not (self.inputs['vertices'].is_linked): return # perhaps if any of mverts is [] this should already fail. has_matrices = self.inputs['matrix'].is_linked mverts, mmatrices = self.get_geometry_from_sockets() # extend all non empty lists to longest of mverts or *mrest maxlen = max(len(mverts), len(mmatrices)) if has_matrices: fullList(mmatrices, maxlen) for obj_index, Verts in enumerate(mverts): if not Verts: continue curve_name = self.basemesh_name + "_" + str(obj_index) if has_matrices: matrix = mmatrices[obj_index] else: matrix = [] make_curve_geometry(self, bpy.context, curve_name, Verts, matrix, self.close) self.remove_non_updated_objects(obj_index) objs = self.get_children() if bpy.data.materials.get(self.material): self.set_corresponding_materials(objs)
def process(self): if not any((s.is_linked for s in self.outputs)): return if not (self.inputs['vertices'].is_linked and self.inputs['polygons'].is_linked): return verts = self.inputs['vertices'].sv_get() polys = self.inputs['polygons'].sv_get() thickness = self.inputs['thickness'].sv_get() verts_out = [] edges_out = [] polys_out = [] newpo_out = [] fullList(thickness, len(verts)) for v, p, t in zip(verts, polys, thickness): verlen = set(range(len(v))) res = solidify(v, p, t, verlen) if not res: return verts_out.append(res[0]) edges_out.append(res[1]) polys_out.append(res[2]) newpo_out.append(res[3]) self.outputs['vertices'].sv_set(verts_out) self.outputs['edges'].sv_set(edges_out) self.outputs['polygons'].sv_set(polys_out) self.outputs['newpols'].sv_set(newpo_out)
def process(self): inputs, outputs = self.inputs, self.outputs if not outputs[0].is_linked: return _noise_type = noise_dict[self.noise_type] tfunc = turbulence_f[self.out_mode] verts = inputs['Vertices'].sv_get(deepcopy=False) maxlen = len(verts) arguments = [verts] # gather socket data into arguments for socket in inputs[1:]: data = socket.sv_get()[0] fullList(data, maxlen) arguments.append(data) # iterate over vert lists and pass arguments to the turbulence function out = [] for idx, (vert_list, octaves, hard, amp, freq, seed) in enumerate(zip(*arguments)): final_vert_list = seed_adjusted(vert_list, seed) out.append([tfunc(v, octaves, hard, _noise_type, amp, freq) for v in final_vert_list]) if 'Noise V' in outputs: out = Vector_degenerate(out) outputs[0].sv_set(out)
def process(self): if not (self.outputs['Vers'].is_linked and self.inputs['Vers'].is_linked): return vertices = Vector_generate(self.inputs['Vers'].sv_get()) faces = self.inputs['Pols'].sv_get() offset = self.inputs['Offset'].sv_get()[0] nsides = self.inputs['N sides'].sv_get()[0][0] radius = self.inputs['Radius'].sv_get()[0] outv = [] oute = [] outo = [] outn = [] # for each object for verts_obj, faces_obj in zip(vertices, faces): fullList(offset, len(faces_obj)) fullList(radius, len(faces_obj)) verlen = set(range(len(verts_obj))) bm = bmesh_from_pydata(verts_obj, [], faces_obj, normal_update=True) result = self.Offset_pols(bm, offset, radius, nsides, verlen) outv.append(result[0]) oute.append(result[1]) outo.append(result[2]) outn.append(result[3]) self.outputs['Vers'].sv_set(outv) self.outputs['Edgs'].sv_set(oute) self.outputs['OutPols'].sv_set(outo) self.outputs['InPols'].sv_set(outn)
def match_points_and_pressures(pressure_set, num_points): num_pressures = len(pressure_set) if num_pressures < num_points: fullList(pressure_set, num_points) elif num_pressures > num_points: pressure_set = pressure_set[:num_points] return pressure_set
def process(self): if not self.activate: return if not (self.inputs['vertices'].is_linked and self.inputs['edges'].is_linked): # possible remove any potential existing geometry here too return # perhaps if any of mverts is [] this should already fail. mverts, *mrest = self.get_geometry_from_sockets() mode = self.selected_mode single_set = (len(mverts) == 1) and (len(mrest[-1]) > 1) if single_set and (mode in {'Merge', 'Duplicate'}): obj_index = 0 self.output_dupe_or_merged_geometry(mode, mverts, *mrest) if mode == "Duplicate": obj_index = len(mrest[1]) - 1 print(obj_index, ': len-1') else: def get_edges_matrices(obj_index): for geom in mrest: yield self.get_structure(geom, obj_index) # extend all non empty lists to longest of mverts or *mrest maxlen = max(len(mverts), *(map(len, mrest))) fullList(mverts, maxlen) for idx in range(2): if mrest[idx]: fullList(mrest[idx], maxlen) # remade by nikitron for one-object and multyspline solution, # can be switched in future 2015-12 obj_index = 0 data = mrest # get_edges_matrices(obj_index) curve_name = self.basemesh_name + "_" + str(obj_index) make_curve_geometry(self, bpy.context, curve_name, mverts, *data) ''' for obj_index, Verts in enumerate(mverts): if not Verts: continue data = get_edges_matrices(obj_index) curve_name = self.basemesh_name + "_" + str(obj_index) make_curve_geometry(self, bpy.context, curve_name, Verts, *data) ''' self.remove_non_updated_objects(obj_index) objs = self.get_children() if self.grouping: self.to_group(objs) if bpy.data.materials.get(self.material): self.set_corresponding_materials(objs)
def process(self): if not self.activate: return mverts, *mrest = self.get_geometry_from_sockets() def get_edges_faces_matrices(obj_index): for geom in mrest: yield self.get_structure(geom, obj_index) # extend all non empty lists to longest of mverts or *mrest maxlen = max(len(mverts), *(map(len, mrest))) fullList(mverts, maxlen) for idx in range(3): if mrest[idx]: fullList(mrest[idx], maxlen) if self.merge: obj_index = 0 def keep_yielding(): # this will yield all in one go. for idx, Verts in enumerate(mverts): if not Verts: continue data = get_edges_faces_matrices(idx) yield (Verts, data) yielder_object = keep_yielding() make_bmesh_geometry_merged(self, obj_index, bpy.context, yielder_object) else: for obj_index, Verts in enumerate(mverts): if not Verts: continue data = get_edges_faces_matrices(obj_index) make_bmesh_geometry(self, obj_index, bpy.context, Verts, *data) last_index = (len(mverts) - 1) if not self.merge else 0 self.remove_non_updated_objects(last_index) objs = self.get_children() if self.grouping: self.to_group(objs) # truthy if self.material is in .materials if bpy.data.materials.get(self.material): self.set_corresponding_materials() if self.autosmooth: self.set_autosmooth(objs) if self.outputs[0].is_linked: self.outputs[0].sv_set(objs)
def process(self): if not self.image_pointer: return inputs, outputs = self.inputs, self.outputs # inputs if inputs['vecs X'].is_linked: IntegerX = min(int(inputs['vecs X'].sv_get()[0][0]), 100) else: IntegerX = int(self.Xvecs) if inputs['vecs Y'].is_linked: IntegerY = min(int(inputs['vecs Y'].sv_get()[0][0]), 100) else: IntegerY = int(self.Yvecs) step_x_linked = inputs['Step X'].is_linked step_y_linked = inputs['Step Y'].is_linked StepX = inputs['Step X'].sv_get()[0] if step_x_linked else [self.Xstep] StepY = inputs['Step Y'].sv_get()[0] if step_y_linked else [self.Ystep] fullList(StepX, IntegerX) fullList(StepY, IntegerY) # outputs out = [[[]]] edg = [[[]]] plg = [[[]]] if outputs['vecs'].is_linked: out = [ self.make_vertices(IntegerX - 1, IntegerY - 1, StepX, StepY) ] outputs['vecs'].sv_set(out) if outputs['edgs'].is_linked: listEdg = [] for i in range(IntegerY): for j in range(IntegerX - 1): listEdg.append((IntegerX * i + j, IntegerX * i + j + 1)) for i in range(IntegerX): for j in range(IntegerY - 1): listEdg.append( (IntegerX * j + i, IntegerX * j + i + IntegerX)) edg = [list(listEdg)] outputs['edgs'].sv_set(edg) if outputs['pols'].is_linked: listPlg = [] for i in range(IntegerX - 1): for j in range(IntegerY - 1): listPlg.append((IntegerX * j + i, IntegerX * j + i + 1, IntegerX * j + i + IntegerX + 1, IntegerX * j + i + IntegerX)) plg = [list(listPlg)] outputs['pols'].sv_set(plg)
def process(self): if not any(socket.is_linked for socket in self.outputs): return vertices_s = self.inputs['ControlPoints'].sv_get() has_weights = self.inputs['Weights'].is_linked weights_s = self.inputs['Weights'].sv_get(default = [[1.0]]) knots_s = self.inputs['Knots'].sv_get(default = [[]]) degree_s = self.inputs['Degree'].sv_get() curves_out = [] knots_out = [] for vertices, weights, knots, degree in zip_long_repeat(vertices_s, weights_s, knots_s, degree_s): if isinstance(degree, (tuple, list)): degree = degree[0] n_source = len(vertices) fullList(weights, n_source) if self.knot_mode == 'AUTO' and self.is_cyclic: vertices = vertices + vertices[:degree] weights = weights + weights[:degree] n_total = len(vertices) # Set degree curve_degree = degree if has_weights and self.surface_mode == 'NURBS': curve_weights = weights else: curve_weights = None # Set knot vector if self.knot_mode == 'AUTO': if self.is_cyclic: self.debug("N: %s, degree: %s", n_total, degree) knots = list(range(n_total + degree + 1)) else: knots = sv_knotvector.generate(curve_degree, n_total) self.debug('Auto knots: %s', knots) curve_knotvector = knots else: self.debug('Manual knots: %s', knots) curve_knotvector = knots new_curve = SvNurbsCurve.build(self.implementation, degree, curve_knotvector, vertices, curve_weights, normalize_knots = self.normalize_knots) curve_knotvector = new_curve.get_knotvector().tolist() if self.knot_mode == 'AUTO' and self.is_cyclic: u_min = curve_knotvector[degree] u_max = curve_knotvector[-degree-1] new_curve.u_bounds = u_min, u_max else: u_min = min(curve_knotvector) u_max = max(curve_knotvector) new_curve.u_bounds = (u_min, u_max) curves_out.append(new_curve) knots_out.append(curve_knotvector) self.outputs['Curve'].sv_set(curves_out) self.outputs['Knots'].sv_set(knots_out)
def process(self): if not self.activate: return mverts, *mrest = self.get_geometry_from_sockets() def get_edges_faces_matrices(obj_index): for geom in mrest: yield self.get_structure(geom, obj_index) # extend all non empty lists to longest of mverts or *mrest maxlen = max(len(mverts), *(map(len, mrest))) fullList(mverts, maxlen) for idx in range(3): if mrest[idx]: fullList(mrest[idx], maxlen) if self.merge: obj_index = 0 def keep_yielding(): # this will yield all in one go. for idx, Verts in enumerate(mverts): if not Verts: continue data = get_edges_faces_matrices(idx) yield (Verts, data) yield 'FINAL' yielder_object = keep_yielding() make_bmesh_geometry_merged(self, obj_index, bpy.context, yielder_object) else: for obj_index, Verts in enumerate(mverts): if not Verts: continue data = get_edges_faces_matrices(obj_index) make_bmesh_geometry(self, obj_index, bpy.context, Verts, *data) self.remove_non_updated_objects(obj_index) objs = self.get_children() if self.grouping: self.to_group(objs) # truthy if self.material is in .materials if bpy.data.materials.get(self.material): self.set_corresponding_materials(objs) if self.autosmooth: self.set_autosmooth(objs) if self.outputs[0].is_linked: self.outputs[0].sv_set(objs)
def make_plane(int_x, int_y, step_x, step_y, center=False): vertices = [(0.0, 0.0, 0.0)] vertices_S = [] int_x = [int(int_x) if type(int_x) is not list else int(int_x[0])] int_y = [int(int_y) if type(int_y) is not list else int(int_y[0])] # center the grid: offset the starting point of the grid by half its size if center: Nnx = int_x[0] - 1 # number of steps based on the number of X vertices Nsx = len(step_x) # number of steps given by the X step list Nny = int_y[0] - 1 # number of steps based on the number of Y vertices Nsy = len(step_y) # number of steps given by the Y step list # grid size along X (step list & repeated last step if any) sizeX1 = sum(step_x[:min(Nnx, Nsx)]) # step list size sizeX2 = max(0, (Nnx - Nsx)) * step_x[Nsx - 1] # repeated last step size sizeX = sizeX1 + sizeX2 # total size # grid size along Y (step list & repeated last step if any) sizeY1 = sum(step_y[:min(Nny, Nsy)]) # step list size sizeY2 = max(0, (Nny - Nsy)) * step_y[Nsy - 1] # repeated last step size sizeY = sizeY1 + sizeY2 # total size # starting point of the grid offset by half its size in both directions vertices = [(-0.5 * sizeX, -0.5 * sizeY, 0.0)] if type(step_x) is not list: step_x = [step_x] if type(step_y) is not list: step_y = [step_y] fullList(step_x, int_x[0]) fullList(step_y, int_y[0]) for i in range(int_x[0] - 1): v = Vector(vertices[i]) + Vector((step_x[i], 0.0, 0.0)) vertices.append(v[:]) a = [int_y[0] - 1] for i in range(a[0]): out = [] for j in range(int_x[0]): out.append(vertices[j + int_x[0] * i]) for j in out: v = Vector(j) + Vector((0.0, step_y[i], 0.0)) vertices.append(v[:]) polygons = [] for i in range(int_x[0] - 1): for j in range(int_y[0] - 1): polygons.append( (int_x[0] * j + i, int_x[0] * j + i + 1, int_x[0] * j + i + int_x[0] + 1, int_x[0] * j + i + int_x[0])) return vertices, polygons
def f(self, x, socket): out = [] fullList(x, len(socket)) for i, obj in enumerate(socket): if type(obj) not in [int, float]: out.append(self.f(x[i], obj)) else: out.append(obj + x[i]) return out
def f(self, x, socket): out = [] fullList(x, len(socket)) for i, obj in enumerate(socket): if type(obj) not in [int, float]: out.append(self.f(x[i], obj)) else: out.append(obj+x[i]) return out
def process(self): if not any(socket.is_linked for socket in self.outputs): return vertices_s = self.inputs['Vertices'].sv_get() edges_s = self.inputs['Edges'].sv_get(default=[[]]) faces_s = self.inputs['Faces'].sv_get(default=[[]]) masks_s = self.inputs['FaceMask'].sv_get(default=[[1]]) max_angle_s = self.inputs['MaxAngle'].sv_get() face_data_s = self.inputs['FaceData'].sv_get(default=[[]]) verts_out = [] edges_out = [] faces_out = [] face_data_out = [] meshes = match_long_repeat( [vertices_s, edges_s, faces_s, masks_s, max_angle_s, face_data_s]) for vertices, edges, faces, masks, max_angle, face_data in zip( *meshes): if self.split_mode == 'NONPLANAR': if isinstance(max_angle, (list, tuple)): max_angle = max_angle[0] fullList(masks, len(faces)) if face_data: fullList(face_data, len(faces)) bm = bmesh_from_pydata(vertices, edges, faces, normal_update=True, markup_face_data=True) bm_faces = [face for mask, face in zip(masks, bm.faces[:]) if mask] if self.split_mode == 'NONPLANAR': new_geom = bmesh.ops.connect_verts_nonplanar( bm, angle_limit=radians(max_angle), faces=bm_faces) else: new_geom = bmesh.ops.connect_verts_concave(bm, faces=bm_faces) new_verts, new_edges, new_faces = pydata_from_bmesh(bm) #new_edges, new_faces = get_bm_geom(new_geom) if not face_data: new_face_data = [] else: new_face_data = face_data_from_bmesh_faces(bm, face_data) verts_out.append(new_verts) edges_out.append(new_edges) faces_out.append(new_faces) face_data_out.append(new_face_data) self.outputs['Vertices'].sv_set(verts_out) self.outputs['Edges'].sv_set(edges_out) self.outputs['Faces'].sv_set(faces_out) self.outputs['FaceData'].sv_set(face_data_out)
def make_plane(int_x, int_y, step_x, step_y, separate): vertices = [(0.0, 0.0, 0.0)] vertices_S = [] int_x = [int(int_x) if type(int_x) is not list else int(int_x[0])] int_y = [int(int_y) if type(int_y) is not list else int(int_y[0])] if type(step_x) is not list: step_x = [step_x] if type(step_y) is not list: step_y = [step_y] fullList(step_x, int_x[0]) fullList(step_y, int_y[0]) for i in range(int_x[0] - 1): v = Vector(vertices[i]) + Vector((step_x[i], 0.0, 0.0)) vertices.append(v[:]) a = [int_y[0] if separate else int_y[0] - 1] for i in range(a[0]): out = [] for j in range(int_x[0]): out.append(vertices[j + int_x[0] * i]) for j in out: v = Vector(j) + Vector((0.0, step_y[i], 0.0)) vertices.append(v[:]) if separate: vertices_S.append(out) edges = [] edges_S = [] for i in range(int_y[0]): for j in range(int_x[0] - 1): edges.append((int_x[0] * i + j, int_x[0] * i + j + 1)) if separate: out = [] for i in range(int_x[0] - 1): out.append(edges[i]) edges_S.append(out) for i in range(int_y[0] - 1): edges_S.append(edges_S[0]) else: for i in range(int_x[0]): for j in range(int_y[0] - 1): edges.append((int_x[0] * j + i, int_x[0] * j + i + int_x[0])) polygons = [] for i in range(int_x[0] - 1): for j in range(int_y[0] - 1): polygons.append( (int_x[0] * j + i, int_x[0] * j + i + 1, int_x[0] * j + i + int_x[0] + 1, int_x[0] * j + i + int_x[0])) if separate: return vertices_S, edges_S, [] else: return vertices, edges, polygons
def make_plane(int_x, int_y, step_x, step_y, separate): vertices = [(0.0, 0.0, 0.0)] vertices_S = [] int_x = [int(int_x) if type(int_x) is not list else int(int_x[0])] int_y = [int(int_y) if type(int_y) is not list else int(int_y[0])] if type(step_x) is not list: step_x = [step_x] if type(step_y) is not list: step_y = [step_y] fullList(step_x, int_x[0]) fullList(step_y, int_y[0]) for i in range(int_x[0] - 1): v = Vector(vertices[i]) + Vector((step_x[i], 0.0, 0.0)) vertices.append(v[:]) a = [int_y[0] if separate else int_y[0] - 1] for i in range(a[0]): out = [] for j in range(int_x[0]): out.append(vertices[j + int_x[0] * i]) for j in out: v = Vector(j) + Vector((0.0, step_y[i], 0.0)) vertices.append(v[:]) if separate: vertices_S.append(out) edges = [] edges_S = [] for i in range(int_y[0]): for j in range(int_x[0] - 1): edges.append((int_x[0] * i + j, int_x[0] * i + j + 1)) if separate: out = [] for i in range(int_x[0] - 1): out.append(edges[i]) edges_S.append(out) for i in range(int_y[0] - 1): edges_S.append(edges_S[0]) else: for i in range(int_x[0]): for j in range(int_y[0] - 1): edges.append((int_x[0] * j + i, int_x[0] * j + i + int_x[0])) polygons = [] for i in range(int_x[0] - 1): for j in range(int_y[0] - 1): polygons.append( (int_x[0] * j + i, int_x[0] * j + i + 1, int_x[0] * j + i + int_x[0] + 1, int_x[0] * j + i + int_x[0]) ) if separate: return vertices_S, edges_S, [] else: return vertices, edges, polygons
def process(self): if not (self.inputs['Vertices'].is_linked and self.inputs['Polygons'].is_linked): return if not (any(self.outputs[name].is_linked for name in ['Vertices', 'Edges', 'Polygons', 'NewEdges', 'NewPolys'])): return vertices_s = self.inputs['Vertices'].sv_get(default=[[]]) edges_s = self.inputs['Edges'].sv_get(default=[[]]) faces_s = self.inputs['Polygons'].sv_get(default=[[]]) mask_s = self.inputs['Mask'].sv_get(default=[[True]]) result_vertices = [] result_edges = [] result_faces = [] result_new_edges = [] result_new_faces = [] meshes = match_long_repeat([vertices_s, edges_s, faces_s, mask_s]) for vertices, edges, faces, mask in zip(*meshes): bm = bmesh_from_pydata(vertices, edges, faces) fullList(mask, len(faces)) b_faces = [] for m, face in zip(mask, bm.faces): if m: b_faces.append(face) res = bmesh.ops.triangulate( bm, faces=b_faces, quad_method=int(self.quad_mode), ngon_method=int(self.ngon_mode)) b_new_edges = [tuple(v.index for v in edge.verts) for edge in res['edges']] b_new_faces = [[v.index for v in face.verts] for face in res['faces']] new_vertices, new_edges, new_faces = pydata_from_bmesh(bm) bm.free() result_vertices.append(new_vertices) result_edges.append(new_edges) result_faces.append(new_faces) result_new_edges.append(b_new_edges) result_new_faces.append(b_new_faces) if self.outputs['Vertices'].is_linked: self.outputs['Vertices'].sv_set(result_vertices) if self.outputs['Edges'].is_linked: self.outputs['Edges'].sv_set(result_edges) if self.outputs['Polygons'].is_linked: self.outputs['Polygons'].sv_set(result_faces) if self.outputs['NewEdges'].is_linked: self.outputs['NewEdges'].sv_set(result_new_edges) if self.outputs['NewPolys'].is_linked: self.outputs['NewPolys'].sv_set(result_new_faces)
def get_selected_edges(use_mask, masks, bm_edges): if use_mask: if isinstance(masks, ndarray): masks = numpy_full_list(masks, len(bm_edges)).tolist() else: fullList(masks, len(bm_edges)) edge_id = bm_edges.layers.int.get("initial_index") return [edge for edge in bm_edges if masks[edge[edge_id]]] return bm_edges
def f(self, x, socket): ''' this makes sum of units for every socket and object ''' out = [] fullList(x, len(socket)) for i, obj in enumerate(socket): if type(obj) not in [int, float]: out.append(self.f(x[i], obj)) else: out.append(obj + x[i]) return out
def set_loops(loop_count, obj, index_socket, indices, input_colors, colors): if index_socket.is_linked: for idx, color in zip(indices, input_colors): colors[idx] = color else: if len(input_colors) < loop_count: fullList(input_colors, loop_count) elif len(input_colors) > loop_count: input_colors = input_colors[:loop_count] colors[:] = input_colors
def f(self, x, socket): ''' this makes sum of units for every socket and object ''' out = [] fullList(x, len(socket)) for i, obj in enumerate(socket): if type(obj) not in [int, float]: out.append(self.f(x[i], obj)) else: out.append(obj+x[i]) return out
def live_curve(obj_index, node, verts, radii, twist): obj, cu = get_obj_curve(obj_index, node) obj.show_wire = node.show_wire cu.bevel_depth = node.depth cu.bevel_resolution = node.resolution cu.dimensions = node.dimensions if node.dimensions == '2D': cu.fill_mode = 'FRONT' else: cu.fill_mode = 'FULL' set_bevel_object(node, cu, obj_index) kind = ["POLY", "NURBS"][bool(node.bspline)] if node.selected_mode == 'Multi': verts = [verts] radii = [radii] twist = [twist] for idx, (VERTS, RADII, TWIST) in enumerate(zip(verts, radii, twist)): full_flat = [] for v in VERTS: full_flat.extend([v[0], v[1], v[2], 1.0]) polyline = cu.splines.new(kind) polyline.points.add(len(VERTS)-1) polyline.points.foreach_set('co', full_flat) if RADII: if len(VERTS) < len(RADII): RADII = RADII[:len(VERTS)] elif len(VERTS) > len(RADII): fullList(RADII, len(VERTS)) polyline.points.foreach_set('radius', RADII) if TWIST: if len(VERTS) < len(TWIST): TWIST = TWIST[:len(VERTS)] elif len(VERTS) > len(TWIST): fullList(TWIST, len(VERTS)) polyline.points.foreach_set('tilt', TWIST) if node.close: cu.splines[idx].use_cyclic_u = True if node.bspline: polyline.order_u = len(polyline.points)-1 polyline.use_smooth = node.use_smooth return obj
def live_curve(obj_index, node, verts, radii, twist): obj, cu = node.get_obj_curve(obj_index) obj.show_wire = node.show_wire cu.bevel_depth = node.depth cu.bevel_resolution = node.resolution cu.dimensions = node.curve_dimensions if cu.dimensions == '2D': cu.fill_mode = 'FRONT' else: cu.fill_mode = 'FULL' set_bevel_object(node, cu, obj_index) kind = ["POLY", "NURBS"][bool(node.bspline)] if node.selected_mode == 'Multi': verts = [verts] radii = [radii] twist = [twist] for idx, (VERTS, RADII, TWIST) in enumerate(zip(verts, radii, twist)): full_flat = [] for v in VERTS: full_flat.extend([v[0], v[1], v[2], 1.0]) polyline = cu.splines.new(kind) polyline.points.add(len(VERTS) - 1) polyline.points.foreach_set('co', full_flat) if RADII: if len(VERTS) < len(RADII): RADII = RADII[:len(VERTS)] elif len(VERTS) > len(RADII): fullList(RADII, len(VERTS)) polyline.points.foreach_set('radius', RADII) if TWIST: if len(VERTS) < len(TWIST): TWIST = TWIST[:len(VERTS)] elif len(VERTS) > len(TWIST): fullList(TWIST, len(VERTS)) polyline.points.foreach_set('tilt', TWIST) if node.close: cu.splines[idx].use_cyclic_u = True if node.bspline: polyline.order_u = len(polyline.points) - 1 polyline.use_smooth = node.use_smooth return obj
def flip_from_mask(mask, geom, reverse): """ this mode expects a mask list with an element corresponding to each polygon """ verts, edges, faces = geom fullList(mask, len(faces)) b_faces = [] for m, face in zip(mask, faces): mask_val = bool(m) if not reverse else not bool(m) b_faces.append(face if mask_val else face[::-1]) return verts, edges, b_faces
def process(self): if not any(output.is_linked for output in self.outputs): return vertices_s = self.inputs['Vertices'].sv_get(default=[[]]) centers = self.inputs['Center'].sv_get(default=[[]])[0] directions_s = self.inputs['Direction'].sv_get(default=[[(0,0,1)]]) amplitudes_s = self.inputs['Amplitude'].sv_get(default=[0.5]) coefficients_s = self.inputs['Coefficient'].sv_get(default=[0.5]) out_vectors = [] out_units = [] out_lens = [] meshes = match_long_repeat([vertices_s, directions_s, amplitudes_s, coefficients_s]) for vertices, directions, amplitudes, coefficients in zip(*meshes): if isinstance(directions, (tuple, list)) and len(directions) == 3 and all([isinstance(x, (int, float)) for x in directions]): direction = directions else: direction = directions[0] if isinstance(amplitudes, (int, float)): amplitudes = [amplitudes] if isinstance(coefficients, (int, float)): coefficients = [coefficients] fullList(amplitudes, len(vertices)) fullList(coefficients, len(vertices)) vectors = [] units = [] lens = [] for vertex, amplitude, coefficient in zip(vertices, amplitudes, coefficients): if self.attractor_type == 'Point': length, unit = self.to_point(amplitude, coefficient, vertex, centers, direction) elif self.attractor_type == 'Line': length, unit = self.to_line(amplitude, coefficient, vertex, centers, direction) elif self.attractor_type == 'Plane': length, unit = self.to_plane(amplitude, coefficient, vertex, centers, direction) else: raise ValueError("Unknown attractor type: " + self.attractor_type) vector = length * unit units.append(tuple(unit)) lens.append(length) vectors.append(tuple(vector)) out_vectors.append(vectors) out_units.append(units) out_lens.append(lens) self.outputs['Vectors'].sv_set(out_vectors) self.outputs['Directions'].sv_set(out_units) self.outputs['Coeffs'].sv_set(out_lens)
def process(self): if not self.activate: return vertices_s = self.inputs['ControlPoints'].sv_get() has_weights = self.inputs['Weights'].is_linked weights_s = self.inputs['Weights'].sv_get(default=[[1.0]]) degree_s = self.inputs['Degree'].sv_get() vertices_s = ensure_nesting_level(vertices_s, 3) # we need to suppress depsgraph updates emminating from this part of the process/ with self.sv_throttle_tree_update(): inputs = zip_long_repeat(vertices_s, weights_s, degree_s) object_index = 0 for vertices, weights, degree in inputs: if not vertices or not weights: continue object_index += 1 if isinstance(degree, (tuple, list)): degree = degree[0] fullList(weights, len(vertices)) curve_object = self.create_curve(object_index) self.debug("Object: %s", curve_object) if not curve_object: continue curve_object.data.splines.clear() spline = curve_object.data.splines.new(type='NURBS') spline.use_bezier_u = False spline.use_bezier_v = False spline.points.add(len(vertices) - 1) for p, new_co, new_weight in zip(spline.points, vertices, weights): p.co = Vector(list(new_co) + [new_weight]) p.select = True spline.use_cyclic_u = self.is_cyclic spline.use_endpoint_u = not self.is_cyclic and self.use_endpoint spline.order_u = degree + 1 spline.resolution_u = self.resolution self.remove_non_updated_objects(object_index) self.set_corresponding_materials() objects = self.get_children() self.outputs['Objects'].sv_set(objects)
def process(self): if not self.outputs['Colors'].is_linked: return inputs = self.inputs i0_g = inputs[0].sv_get() i1_g = inputs[1].sv_get() i2_g = inputs[2].sv_get() i3_g = inputs[3].sv_get() series_vec = [] max_obj = max(map(len, (i0_g, i1_g, i2_g, i3_g))) fullList(i0_g, max_obj) fullList(i1_g, max_obj) fullList(i2_g, max_obj) fullList(i3_g, max_obj) if self.implementation == 'Python': series_vec = python_color_pack(i0_g, i1_g, i2_g, i3_g, self.selected_mode, self.use_alpha) else: series_vec = numpy_pack_vecs(i0_g, i1_g, i2_g, i3_g, self.selected_mode, self.use_alpha, self.output_numpy) self.outputs['Colors'].sv_set(series_vec)
def process(self): outputs = self.outputs if not outputs['Vertices'].is_linked: return IVerts, IFaces, IMask, Imatr = self.inputs vertices_s = IVerts.sv_get() faces_s = IFaces.sv_get() linked_extruded_polygons = outputs['ExtrudedPolys'].is_linked linked_other_polygons = outputs['OtherPolys'].is_linked result_vertices = [] result_edges = [] result_faces = [] result_extruded_faces = [] result_other_faces = [] bmlist = [bmesh_from_pydata(verts, [], faces) for verts, faces in zip(vertices_s, faces_s)] trans = Imatr.sv_get() if IMask.is_linked: flist = [np.extract(mask, bm.faces[:]) for bm, mask in zip(bmlist, IMask.sv_get())] else: flist = [bm.faces for bm in bmlist] for bm, selfaces in zip(bmlist, flist): extrfaces = extrude_discrete_faces(bm, faces=selfaces)['faces'] fullList(trans, len(extrfaces)) new_extruded_faces = [] for face, ma in zip(extrfaces, trans): normal = face.normal if normal[0] == 0 and normal[1] == 0: m_r = Matrix() if normal[2] >= 0 else Matrix.Rotation(pi, 4, 'X') else: z_axis = normal x_axis = Vector((z_axis[1] * -1, z_axis[0], 0)).normalized() y_axis = z_axis.cross(x_axis).normalized() m_r = Matrix(list([*zip(x_axis[:], y_axis[:], z_axis[:])])).to_4x4() m = (Matrix.Translation(face.calc_center_median()) @ m_r).inverted() transform(bm, matrix=ma, space=m, verts=face.verts) if linked_extruded_polygons or linked_other_polygons: new_extruded_faces.append([v.index for v in face.verts]) new_vertices, new_edges, new_faces = pydata_from_bmesh(bm) bm.free() new_other_faces = [f for f in new_faces if f not in new_extruded_faces] if linked_other_polygons else [] result_vertices.append(new_vertices) result_edges.append(new_edges) result_faces.append(new_faces) result_extruded_faces.append(new_extruded_faces) result_other_faces.append(new_other_faces) outputs['Vertices'].sv_set(result_vertices) outputs['Edges'].sv_set(result_edges) outputs['Polygons'].sv_set(result_faces) outputs['ExtrudedPolys'].sv_set(result_extruded_faces) outputs['OtherPolys'].sv_set(result_other_faces)
def python_color_pack(i0_g, i1_g, i2_g, i3_g, color_mode, use_alpha): series_vec = [] for i0, i1, i2, i3 in zip(i0_g, i1_g, i2_g, i3_g): max_v = max(map(len, (i0, i1, i2, i3))) fullList(i0, max_v) fullList(i1, max_v) fullList(i2, max_v) fullList(i3, max_v) if color_mode == 'RGB': if use_alpha: series_vec.append(list(zip(i0, i1, i2, i3))) else: series_vec.append(list(zip(i0, i1, i2))) else: if color_mode == 'HSV': convert = colorsys.hsv_to_rgb elif color_mode == 'HSL': convert = lambda h, s, l: colorsys.hls_to_rgb(h, l, s) colordata = [] for c0, c1, c2, c3 in zip(i0, i1, i2, i3): colorv = list(convert(c0, c1, c2)) if use_alpha: colordata.append([colorv[0], colorv[1], colorv[2], c3]) else: colordata.append(colorv) series_vec.append(colordata) return series_vec
def process(self): outputs = self.outputs if not outputs['Vertices'].is_linked: return IVerts, IFaces, IMask, Imatr = self.inputs vertices_s = IVerts.sv_get() faces_s = IFaces.sv_get() linked_extruded_polygons = outputs['ExtrudedPolys'].is_linked linked_other_polygons = outputs['OtherPolys'].is_linked result_vertices = [] result_edges = [] result_faces = [] result_extruded_faces = [] result_other_faces = [] bmlist = [bmesh_from_pydata(verts, [], faces) for verts, faces in zip(vertices_s, faces_s)] trans = Imatr.sv_get() if IMask.is_linked: flist = [np.extract(mask, bm.faces[:]) for bm, mask in zip(bmlist, IMask.sv_get())] else: flist = [bm.faces for bm in bmlist] for bm, selfaces in zip(bmlist, flist): extrfaces = extrude_discrete_faces(bm, faces=selfaces)['faces'] fullList(trans, len(extrfaces)) new_extruded_faces = [] for face, ma in zip(extrfaces, trans): normal = face.normal if normal[0] == 0 and normal[1] == 0: m_r = Matrix() if normal[2] >= 0 else Matrix.Rotation(pi, 4, 'X') else: z_axis = normal x_axis = Vector((z_axis[1] * -1, z_axis[0], 0)).normalized() y_axis = z_axis.cross(x_axis).normalized() m_r = Matrix(list([*zip(x_axis[:], y_axis[:], z_axis[:])])).to_4x4() m = (Matrix.Translation(face.calc_center_median()) * m_r).inverted() transform(bm, matrix=ma, space=m, verts=face.verts) if linked_extruded_polygons or linked_other_polygons: new_extruded_faces.append([v.index for v in face.verts]) new_vertices, new_edges, new_faces = pydata_from_bmesh(bm) bm.free() new_other_faces = [f for f in new_faces if f not in new_extruded_faces] if linked_other_polygons else [] result_vertices.append(new_vertices) result_edges.append(new_edges) result_faces.append(new_faces) result_extruded_faces.append(new_extruded_faces) result_other_faces.append(new_other_faces) outputs['Vertices'].sv_set(result_vertices) outputs['Edges'].sv_set(result_edges) outputs['Polygons'].sv_set(result_faces) outputs['ExtrudedPolys'].sv_set(result_extruded_faces) outputs['OtherPolys'].sv_set(result_other_faces)
def process(self): if not self.outputs['Matrix'].is_linked: return # inputs factor1 = self.inputs['Factor1'].sv_get() factor2 = self.inputs['Factor2'].sv_get() # outputs max_l = max(len(factor1), len(factor2)) fullList(factor1, max_l) fullList(factor2, max_l) matrixes_ = [] for i in range(max_l): max_inner = max(len(factor1[i]), len(factor2[i])) fullList(factor1[i], max_inner) fullList(factor2[i], max_inner) for j in range(max_inner): matrixes_.append( Matrix.Shear(self.plane_, 4, (factor1[i][j], factor2[i][j]))) matrixes = Matrix_listing(matrixes_) self.outputs['Matrix'].sv_set(matrixes)
def process(self): inputs, outputs = self.inputs, self.outputs # inputs if inputs['vecs X'].is_linked: IntegerX = min(int(inputs['vecs X'].sv_get()[0][0]), 1000000) else: IntegerX = int(self.Xvecs) if inputs['vecs Y'].is_linked: IntegerY = min(int(inputs['vecs Y'].sv_get()[0][0]), 1000000) else: IntegerY = int(self.Yvecs) step_x_linked = inputs['Step X'].is_linked step_y_linked = inputs['Step Y'].is_linked StepX = inputs['Step X'].sv_get()[0] if step_x_linked else [self.Xstep] StepY = inputs['Step Y'].sv_get()[0] if step_y_linked else [self.Ystep] fullList(StepX, IntegerX) fullList(StepY, IntegerY) # outputs out = [[[]]] edg = [[[]]] plg = [[[]]] if outputs['vecs'].is_linked: out = [self.make_vertices(IntegerX-1, IntegerY-1, StepX, StepY, self.name_image)] outputs['vecs'].sv_set(out) if outputs['edgs'].is_linked: listEdg = [] for i in range(IntegerY): for j in range(IntegerX-1): listEdg.append((IntegerX*i+j, IntegerX*i+j+1)) for i in range(IntegerX): for j in range(IntegerY-1): listEdg.append((IntegerX*j+i, IntegerX*j+i+IntegerX)) edg = [list(listEdg)] outputs['edgs'].sv_set(edg) if outputs['pols'].is_linked: listPlg = [] for i in range(IntegerX-1): for j in range(IntegerY-1): listPlg.append((IntegerX*j+i, IntegerX*j+i+1, IntegerX*j+i+IntegerX+1, IntegerX*j+i+IntegerX)) plg = [list(listPlg)] outputs['pols'].sv_set(plg)
def process(self): # inputs if 'vecs X' in self.inputs and self.inputs['vecs X'].is_linked: IntegerX = min(int(SvGetSocketAnyType(self, self.inputs['vecs X'])[0][0]), 100) else: IntegerX = int(self.Xvecs) if 'vecs Y' in self.inputs and self.inputs['vecs Y'].is_linked: IntegerY = min(int(SvGetSocketAnyType(self, self.inputs['vecs Y'])[0][0]), 100) else: IntegerY = int(self.Yvecs) if 'Step X' in self.inputs and self.inputs['Step X'].is_linked: StepX = SvGetSocketAnyType(self, self.inputs['Step X'])[0] fullList(StepX, IntegerX) else: StepX = [self.Xstep] fullList(StepX, IntegerX) if 'Step Y' in self.inputs and self.inputs['Step Y'].is_linked: StepY = SvGetSocketAnyType(self, self.inputs['Step Y'])[0] fullList(StepY, IntegerY) else: StepY = [self.Ystep] fullList(StepY, IntegerY) # outputs if 'vecs' in self.outputs and self.outputs['vecs'].is_linked: out = self.make_vertices(IntegerX-1, IntegerY-1, StepX, StepY, self.name_image) SvSetSocketAnyType(self, 'vecs', [out]) else: SvSetSocketAnyType(self, 'vecs', [[[]]]) if 'edgs' in self.outputs and len(self.outputs['edgs'].is_linked) > 0: listEdg = [] for i in range(IntegerY): for j in range(IntegerX-1): listEdg.append((IntegerX*i+j, IntegerX*i+j+1)) for i in range(IntegerX): for j in range(IntegerY-1): listEdg.append((IntegerX*j+i, IntegerX*j+i+IntegerX)) edg = list(listEdg) SvSetSocketAnyType(self, 'edgs', [edg]) else: SvSetSocketAnyType(self, 'edgs', [[[]]]) if 'pols' in self.outputs and self.outputs['pols'].is_linked: listPlg = [] for i in range(IntegerX-1): for j in range(IntegerY-1): listPlg.append((IntegerX*j+i, IntegerX*j+i+1, IntegerX*j+i+IntegerX+1, IntegerX*j+i+IntegerX)) plg = list(listPlg) SvSetSocketAnyType(self, 'pols', [plg]) else: SvSetSocketAnyType(self, 'pols', [[[]]])
def process(self): i = self.inputs o = self.outputs if not o['vertices'].is_linked: return verts = Vector_generate(i['vertices'].sv_get()) polys = i['polygons'].sv_get() ''' get_value_for( param name, fallback )''' inset_rates = self.get_value_for('inset', [[self.inset]]) distance_vals = self.get_value_for('distance', [[self.distance]]) #if self.inputs['axis'].links: # axees = self.get_value_for('axis', [[self.axis]]) #else: # axees = None # print(inset_rates) # unvectorized implementation, expects only one set of verts + faces + etc fullList(inset_rates, len(polys[0])) fullList(distance_vals, len(polys[0])) #fullList(axees, len(polys[0])) #verts, faces, axis=None, distance=0, make_inner=False verts_out = [] polys_out = [] func_args = { 'vertices': verts[0], 'faces': polys[0], 'inset_rates': inset_rates, 'axis': None, 'distances': distance_vals, 'make_inner': False } res = inset_special(**func_args) if not res: return verts_out, polys_out = res # deal with hooking up the processed data to the outputs o['vertices'].sv_set([verts_out]) if o['polygons'].is_linked: o['polygons'].sv_set([polys_out])
def process(self): i = self.inputs o = self.outputs if not o['vertices'].is_linked: return all_verts = Vector_generate(i['vertices'].sv_get()) all_polys = i['polygons'].sv_get() all_inset_rates = i['inset'].sv_get() all_distance_vals = i['distance'].sv_get() # silly auto ugrade. if not i['ignore'].prop_name: i['ignore'].prop_name = 'ignore' i['make_inner'].prop_name = 'make_inner' all_ignores = i['ignore'].sv_get() all_make_inners = i['make_inner'].sv_get() data = all_verts, all_polys, all_inset_rates, all_distance_vals, all_ignores, all_make_inners verts_out = [] polys_out = [] ignored_out = [] inset_out = [] for v, p, inset_rates, distance_vals, ignores, make_inners in zip( *data): fullList(inset_rates, len(p)) fullList(distance_vals, len(p)) fullList(ignores, len(p)) fullList(make_inners, len(p)) func_args = { 'vertices': v, 'faces': p, 'inset_rates': inset_rates, 'distances': distance_vals, 'make_inners': make_inners, 'ignores': ignores, 'zero_mode': self.zero_mode } res = inset_special(**func_args) if not res: res = v, p, [], [] verts_out.append(res[0]) polys_out.append(res[1]) ignored_out.append(res[2]) inset_out.append(res[3]) # deal with hooking up the processed data to the outputs o['vertices'].sv_set(verts_out) o['polygons'].sv_set(polys_out) o['ignored'].sv_set(ignored_out) o['inset'].sv_set(inset_out)
def process(self): # inputs if 'vecs X' in self.inputs and self.inputs['vecs X'].is_linked: IntegerX = min(int(SvGetSocketAnyType(self, self.inputs['vecs X'])[0][0]), 100) else: IntegerX = int(self.Xvecs) if 'vecs Y' in self.inputs and self.inputs['vecs Y'].is_linked: IntegerY = min(int(SvGetSocketAnyType(self, self.inputs['vecs Y'])[0][0]), 100) else: IntegerY = int(self.Yvecs) if 'Step X' in self.inputs and self.inputs['Step X'].is_linked: StepX = SvGetSocketAnyType(self, self.inputs['Step X'])[0] fullList(StepX, IntegerX) else: StepX = [self.Xstep] fullList(StepX, IntegerX) if 'Step Y' in self.inputs and self.inputs['Step Y'].is_linked: StepY = SvGetSocketAnyType(self, self.inputs['Step Y'])[0] fullList(StepY, IntegerY) else: StepY = [self.Ystep] fullList(StepY, IntegerY) # outputs if 'vecs' in self.outputs and self.outputs['vecs'].is_linked: out = self.make_vertices(IntegerX-1, IntegerY-1, StepX, StepY, self.name_image) SvSetSocketAnyType(self, 'vecs', [out]) else: SvSetSocketAnyType(self, 'vecs', [[[]]]) if 'edgs' in self.outputs and self.outputs['edgs'].is_linked: listEdg = [] for i in range(IntegerY): for j in range(IntegerX-1): listEdg.append((IntegerX*i+j, IntegerX*i+j+1)) for i in range(IntegerX): for j in range(IntegerY-1): listEdg.append((IntegerX*j+i, IntegerX*j+i+IntegerX)) edg = list(listEdg) SvSetSocketAnyType(self, 'edgs', [edg]) else: SvSetSocketAnyType(self, 'edgs', [[[]]]) if 'pols' in self.outputs and self.outputs['pols'].is_linked: listPlg = [] for i in range(IntegerX-1): for j in range(IntegerY-1): listPlg.append((IntegerX*j+i, IntegerX*j+i+1, IntegerX*j+i+IntegerX+1, IntegerX*j+i+IntegerX)) plg = list(listPlg) SvSetSocketAnyType(self, 'pols', [plg]) else: SvSetSocketAnyType(self, 'pols', [[[]]])
def process(self): i = self.inputs o = self.outputs if not o['vertices'].is_linked: return all_verts = Vector_generate(i['vertices'].sv_get()) all_polys = i['polygons'].sv_get() ''' get_value_for( param name, fallback )''' all_inset_rates = self.get_value_for('inset', [[self.inset]]) all_distance_vals = self.get_value_for('distance', [[self.distance]]) all_ignores = self.get_value_for('ignore', [[False]]) all_make_inners = self.get_value_for('make_inner', [[True]]) data = all_verts, all_polys, all_inset_rates, all_distance_vals, all_ignores, all_make_inners verts_out = [] polys_out = [] ignored_out = [] inset_out = [] for v, p, inset_rates, distance_vals, ignores, make_inners in zip( *data): fullList(inset_rates, len(p)) fullList(distance_vals, len(p)) fullList(ignores, len(p)) fullList(make_inners, len(p)) func_args = { 'vertices': v, 'faces': p, 'inset_rates': inset_rates, 'distances': distance_vals, 'make_inners': make_inners, 'ignores': ignores } res = inset_special(**func_args) if not res: res = v, p, [], [] verts_out.append(res[0]) polys_out.append(res[1]) ignored_out.append(res[2]) inset_out.append(res[3]) # deal with hooking up the processed data to the outputs o['vertices'].sv_set(verts_out) if o['polygons'].is_linked: o['polygons'].sv_set(polys_out) if o['ignored'].is_linked: o['ignored'].sv_set(ignored_out) if o['inset'].is_linked: o['inset'].sv_set(inset_out)
def process(self): # return if no outputs are connected if not any(s.is_linked for s in self.outputs): return inputs = self.inputs outputs = self.outputs input_numx = inputs["Num X"].sv_get() input_numy = inputs["Num Y"].sv_get() input_stepx = inputs["Step X"].sv_get() input_stepy = inputs["Step Y"].sv_get() params = match_long_repeat( [input_numx, input_numy, input_stepx, input_stepy]) stepListx, stepListy = [[], []] for nx, ny, sx, sy in zip(*params): numx, numy = [max(2, nx[0]), max(2, ny[0])] # sanitize the input # adjust the step list based on number of verts and steps stepsx, stepsy = [sx[:(numx - 1)], sy[:(numy - 1)]] # shorten if needed fullList(stepsx, numx - 1) # extend if needed fullList(stepsy, numy - 1) # extend if needed if self.normalize: sizex, sizey = [ self.sizex / sum(stepsx), self.sizey / sum(stepsy) ] stepsx = [sx * sizex for sx in stepsx] stepsy = [sy * sizey for sy in stepsy] stepListx.append(stepsx) stepListy.append(stepsy) c, d, s = self.center, self.direction, self.separate planes = [ make_plane(sx, sy, c, d, s) for sx, sy in zip(stepListx, stepListy) ] verts, edges, polys = [vep for vep in zip(*planes)] # outputs if outputs['Vertices'].is_linked: outputs['Vertices'].sv_set(verts) if outputs['Edges'].is_linked: outputs['Edges'].sv_set(edges) if outputs['Polygons'].is_linked: outputs['Polygons'].sv_set(polys)