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): 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): 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)
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)