def process(self): if not any(s.is_linked for s in self.outputs): return params_in = [s.sv_get(deepcopy=False) for s in self.inputs[:4]] params_in.append(self.inputs['Fill / Stroke'].sv_get(deepcopy=False, default=[[None]])) get_curves = self.outputs['Curves'].is_linked shapes_out = [] curves_out = [] for params in zip(*mlr(params_in)): shapes = [] for loc, rad_x, rad_y, angle, atts in zip(*mlr(params)): shapes.append(SvgCircle(rad_x, rad_y, loc, angle, atts)) if get_curves: center = curve_matrix(loc, angle, rad_x, rad_y) curve = SvCircle(center, rad_x) curve.u_bounds = (0, 2 * pi) curves_out.append(curve) if self.ungroup: shapes_out.extend(shapes) else: shapes_out.append(SvgGroup(shapes)) self.outputs[0].sv_set(shapes_out) self.outputs[1].sv_set(curves_out)
def process(self): if not any(socket.is_linked for socket in self.outputs): return center_s = self.inputs['Center'].sv_get(default=[Matrix()]) radius_s = self.inputs['Radius'].sv_get() t_min_s = self.inputs['TMin'].sv_get() t_max_s = self.inputs['TMax'].sv_get() radius_s = ensure_nesting_level(radius_s, 2) t_min_s = ensure_nesting_level(t_min_s, 2) t_max_s = ensure_nesting_level(t_max_s, 2) center_s = ensure_nesting_level(center_s, 2, data_types=(Matrix, )) curves_out = [] for centers, radiuses, t_mins, t_maxs in zip_long_repeat( center_s, radius_s, t_min_s, t_max_s): for center, radius, t_min, t_max in zip_long_repeat( centers, radiuses, t_mins, t_maxs): au = self.radians_conversion_factor() t_min, t_max = t_min * au, t_max * au curve = SvCircle(matrix=center, radius=radius) curve.u_bounds = (t_min, t_max) curves_out.append(curve) self.outputs['Curve'].sv_set(curves_out)
def process(self): if not any(socket.is_linked for socket in self.outputs): return center_s = self.inputs['Center'].sv_get(default=[Matrix()]) radius_s = self.inputs['Radius'].sv_get() t_min_s = self.inputs['TMin'].sv_get() t_max_s = self.inputs['TMax'].sv_get() n_points_s = self.inputs['NPoints'].sv_get() radius_s = ensure_nesting_level(radius_s, 2) t_min_s = ensure_nesting_level(t_min_s, 2) t_max_s = ensure_nesting_level(t_max_s, 2) n_points_s = ensure_nesting_level(n_points_s, 2) center_s = ensure_nesting_level(center_s, 2, data_types=(Matrix, )) curves_out = [] for params in zip_long_repeat(center_s, radius_s, t_min_s, t_max_s, n_points_s): for center, radius, t_min, t_max, n_points in zip_long_repeat( *params): au = self.radians_conversion_factor() t_min, t_max = t_min * au, t_max * au curve = SvCircle(matrix=center, radius=radius) if self.curve_mode == 'GENERIC': curve.u_bounds = (t_min, t_max) else: curve = curve.to_nurbs_arc(n=n_points, t_min=t_min, t_max=t_max) curves_out.append(curve) self.outputs['Curve'].sv_set(curves_out)
def process(self): if not any(socket.is_linked for socket in self.outputs): return point1_s = self.inputs['Point1'].sv_get() point2_s = self.inputs['Point2'].sv_get() point3_s = self.inputs['Point3'].sv_get() point1_s = ensure_nesting_level(point1_s, 3) point2_s = ensure_nesting_level(point2_s, 3) point3_s = ensure_nesting_level(point3_s, 3) arcs_out = [] circles_out = [] centers_out = [] radius_out = [] angle_out = [] for point1s, point2s, point3s in zip_long_repeat( point1_s, point2_s, point3_s): arcs_new = [] circles_new = [] centers_new = [] radius_new = [] angle_new = [] for point1, point2, point3 in zip_long_repeat( point1s, point2s, point3s): circle_data = circle_by_three_points(point1, point2, point3) if circle_data is None: raise Exception( "Can't build a circle by these points: {}, {}, {}". format(point1, point2, point3)) matrix = circle_data.get_matrix() circle = SvCircle(matrix, circle_data.radius) arc = SvCircle(matrix, circle_data.radius) arc.u_bounds = (0.0, circle_data.arc_angle) arcs_new.append(arc) circles_new.append(circle) centers_new.append(matrix) radius_new.append(circle_data.radius) angle_new.append(circle_data.arc_angle) if self.join: arcs_out.extend(arcs_new) circles_out.extend(circles_new) centers_out.extend(centers_new) radius_out.extend(radius_new) angle_out.extend(angle_new) else: arcs_out.append(arcs_new) circles_out.append(circles_new) centers_out.append(centers_new) radius_out.append(radius_new) angle_out.append(angle_new) self.outputs['Arc'].sv_set(arcs_out) self.outputs['Circle'].sv_set(circles_out) self.outputs['Center'].sv_set(centers_out) self.outputs['Radius'].sv_set(radius_out) self.outputs['Angle'].sv_set(angle_out)
def get_curve(self): center = np.array(self.center) normal = np.array(self.normal) p1 = np.array(self.p1) circle = SvCircle(center=center, normal=-normal, vectorx=p1 - center) circle.u_bounds = (0.0, self.angle) #circle.u_bounds = (-self.angle, 0.0) return circle
def process(self): if not any(socket.is_linked for socket in self.outputs): return start_s = self.inputs['Start'].sv_get() end_s = self.inputs['End'].sv_get() tangent_s = self.inputs['Tangent'].sv_get() start_s = ensure_nesting_level(start_s, 3) end_s = ensure_nesting_level(end_s, 3) tangent_s = ensure_nesting_level(tangent_s, 3) arcs_out = [] circles_out = [] centers_out = [] radius_out = [] angle_out = [] for starts, ends, tangents in zip_long_repeat(start_s, end_s, tangent_s): arcs_new = [] circles_new = [] centers_new = [] radius_new = [] angle_new = [] for start, end, tangent in zip_long_repeat(starts, ends, tangents): circle_data = circle_by_start_end_tangent(start, end, tangent) if circle_data is None: raise Exception("Can't build a circle") matrix = circle_data.get_matrix() circle = SvCircle(matrix, circle_data.radius) arc = SvCircle(matrix, circle_data.radius) arc.u_bounds = (0.0, circle_data.arc_angle) arcs_new.append(arc) circles_new.append(circle) centers_new.append(matrix) radius_new.append(circle_data.radius) angle_new.append(circle_data.arc_angle) if self.join: arcs_out.extend(arcs_new) circles_out.extend(circles_new) centers_out.extend(centers_new) radius_out.extend(radius_new) angle_out.extend(angle_new) else: arcs_out.append(arcs_new) circles_out.append(circles_new) centers_out.append(centers_new) radius_out.append(radius_new) angle_out.append(angle_new) self.outputs['Arc'].sv_set(arcs_out) self.outputs['Circle'].sv_set(circles_out) self.outputs['Center'].sv_set(centers_out) self.outputs['Radius'].sv_set(radius_out) self.outputs['Angle'].sv_set(angle_out)
def process(self): if not any(socket.is_linked for socket in self.outputs): return curve_s = self.inputs['Curve'].sv_get() epsilon_s = self.inputs['Epsilon'].sv_get() smooth_s = self.inputs['Smooth'].sv_get() samples_s = self.inputs['Samples'].sv_get() if isinstance(curve_s[0], SvCurve): curve_s = [curve_s] epsilon_s = ensure_nesting_level(epsilon_s, 2) smooth_s = ensure_nesting_level(smooth_s, 2) samples_s = ensure_nesting_level(samples_s, 2) surface_out = [] circle_out = [] curve_out = [] inputs = zip_long_repeat(curve_s, epsilon_s, smooth_s, samples_s) for curves, epsilons, smooths, samples_i in inputs: for curve, epsilon, smooth, samples in zip_long_repeat( curves, epsilons, smooths, samples_i): new_surface = self.make_surface(curve, epsilon, smooth, samples) circle = SvCircle(Matrix(), 1.0) new_curve = SvCurveOnSurface(circle, new_surface, axis=2) surface_out.append(new_surface) curve_out.append(new_curve) circle_out.append(circle) self.outputs['Surface'].sv_set(surface_out) self.outputs['TrimCurve'].sv_set(circle_out) self.outputs['Curve'].sv_set(curve_out)
def process(self): if not any(socket.is_linked for socket in self.outputs): return verts_s = self.inputs['Vertices'].sv_get() tangent_s = self.inputs['Tangent'].sv_get(default = [[[]]]) have_tangent = self.inputs['Tangent'].is_linked verts_s = ensure_nesting_level(verts_s, 3) tangent_s = ensure_nesting_level(tangent_s, 3) tangent_s = tangent_s[0] # We can use only one tangent per curve, but let's support a spare pair of [] curve_out = [] center_out = [] radius_out = [] angle_out = [] for verts, tangent in zip_long_repeat(verts_s, tangent_s): new_curves = [] new_centers = [] new_radius = [] new_angles = [] if not have_tangent: tangent = self.calc_tangent(verts) elif not isinstance(tangent, Vector): tangent = Vector(tangent) if self.is_cyclic: verts = verts + [verts[0]] for start, end in zip(verts, verts[1:]): start = Vector(start) end = Vector(end) diff = end - start if diff.angle(tangent) < 1e-8: curve = SvLine.from_two_points(start, end) else: eq = circle_by_start_end_tangent(start, end, tangent) curve = SvCircle.from_equation(eq) _, angle = curve.get_u_bounds() tangent = Vector(curve.tangent(angle)) new_centers.append(curve.matrix) new_radius.append(curve.radius) new_angles.append(angle) new_curves.append(curve) if self.make_nurbs: new_curves = [c.to_nurbs() for c in new_curves] if self.concat: new_curves = [concatenate_curves(new_curves)] curve_out.append(new_curves) center_out.append(new_centers) radius_out.append(new_radius) angle_out.append(new_angles) self.outputs['Curve'].sv_set(curve_out) self.outputs['Center'].sv_set(center_out) self.outputs['Radius'].sv_set(radius_out) self.outputs['Angle'].sv_set(angle_out)
def interpret(self, interpreter, variables): interpreter.assert_not_closed() interpreter.start_new_segment() v0 = interpreter.position if interpreter.has_last_vertex: v0_index = interpreter.get_last_vertex() else: v0_index = interpreter.new_vertex(*v0) start = complex(*v0) rad_x_expr, rad_y_expr = self.radii rad_x = interpreter.eval_(rad_x_expr, variables) rad_y = interpreter.eval_(rad_y_expr, variables) radius = complex(rad_x, rad_y) xaxis_rot = interpreter.eval_(self.rot, variables) flag1 = interpreter.eval_(self.flag1, variables) flag2 = interpreter.eval_(self.flag2, variables) # numverts, requires -1 else it means segments (21 verts is 20 segments). if self.num_verts is not None: num_verts = interpreter.eval_(self.num_verts, variables) else: num_verts = interpreter.dflt_num_verts num_verts -= 1 end = interpreter.calc_vertex(self.is_abs, self.end[0], self.end[1], variables) end = complex(*end) arc = Arc(start, radius, xaxis_rot, flag1, flag2, end) theta = 1 / num_verts for i in range(1, num_verts + 1): v1 = x, y = arc.point(theta * i) v1_index = interpreter.new_vertex(x, y) interpreter.new_edge(v0_index, v1_index) v0_index = v1_index curve = SvCircle.from_arc(arc) interpreter.curves.append(curve) interpreter.position = v1 interpreter.new_knot("A.#", *v1) if self.close: interpreter.close_segment(v1_index) interpreter.has_last_vertex = True
def circle_to_curve(self, general_center, circle): x0 = circle.x y0 = circle.y if self.plane == 'XY': center = Vector((x0, y0, general_center[2])) matrix = Matrix.Translation(center) elif self.plane == 'YZ': center = Vector((general_center[0], x0, y0)) matrix = Matrix.Rotation(pi/2, 4, 'Y') matrix.translation = center else: center = Vector((x0, general_center[1], y0)) matrix = Matrix.Rotation(pi/2, 4, 'X') matrix.translation = center curve = SvCircle(matrix, circle.r) return curve
def extend_curve(self, curve, t_before, t_after): u_min, u_max = curve.get_u_bounds() start, end = curve.evaluate(u_min), curve.evaluate(u_max) start_extent, end_extent = None, None is_nurbs = isinstance(curve, SvNurbsCurve) if self.mode == 'LINE': tangent_start = curve.tangent(u_min) tangent_end = curve.tangent(u_max) if t_before > 0: start_extent = self.make_line(start, tangent_start, t_before, -1) start_extent = self.set_length(curve, start_extent, t_before, -1) if t_after > 0: end_extent = self.make_line(end, tangent_end, t_after, +1) end_extent = self.set_length(curve, end_extent, t_after, +1) elif self.mode == 'ARC': tangent_start = curve.tangent(u_min) tangent_end = curve.tangent(u_max) second_start = curve.second_derivative(u_min) second_end = curve.second_derivative(u_max) if t_before > 0: if np.linalg.norm(second_start) > 1e-6: eq1 = circle_by_two_derivatives(start, -tangent_start, second_start) start_extent = SvCircle.from_equation(eq1) start_extent = self.set_length(curve, start_extent, t_before, -1) if is_nurbs: start_extent = start_extent.to_nurbs() start_extent = reverse_curve(start_extent) else: start_extent = self.make_line(start, tangent_start, t_before, -1) start_extent = self.set_length(curve, start_extent, t_before, -1) if t_after > 0: if np.linalg.norm(second_end) > 1e-6: eq2 = circle_by_two_derivatives(end, tangent_end, second_end) end_extent = SvCircle.from_equation(eq2) else: end_extent = self.make_line(end, tangent_end, t_after, +1) end_extent = self.set_length(curve, end_extent, t_after, +1) elif self.mode == 'QUAD': tangent_start = curve.tangent(u_min) tangent_end = curve.tangent(u_max) second_start = curve.second_derivative(u_min) second_end = curve.second_derivative(u_max) if t_before > 0: start_extent = SvTaylorCurve(start, [-tangent_start, second_start]) start_extent = self.set_length(curve, start_extent, t_before) if is_nurbs: start_extent = start_extent.to_nurbs() start_extent = reverse_curve(start_extent) if t_after > 0: end_extent = SvTaylorCurve(end, [tangent_end, second_end]) end_extent = self.set_length(curve, end_extent, t_after) elif self.mode == 'CUBIC': tangent_start = curve.tangent(u_min) tangent_end = curve.tangent(u_max) second_start = curve.second_derivative(u_min) second_end = curve.second_derivative(u_max) third_start, third_end = curve.third_derivative_array( np.array([u_min, u_max])) if t_before > 0: start_extent = SvTaylorCurve( start, [-tangent_start, second_start, -third_start]) start_extent = self.set_length(curve, start_extent, t_before) if is_nurbs: start_extent = start_extent.to_nurbs() start_extent = reverse_curve(start_extent) if t_after > 0: end_extent = SvTaylorCurve( end, [tangent_end, second_end, third_end]) end_extent = self.set_length(curve, end_extent, t_after) else: raise Exception("Unsupported mode") if is_nurbs: if start_extent is not None and not isinstance( start_extent, SvNurbsCurve): start_extent = start_extent.to_nurbs( implementation=curve.get_nurbs_implementation()) if end_extent is not None and not isinstance( end_extent, SvNurbsCurve): end_extent = end_extent.to_nurbs( implementation=curve.get_nurbs_implementation()) return start_extent, end_extent
def get_curve(self): circle = SvCircle(self.matrix, self.radius) circle.u_bounds = (0.0, self.angle) #circle.u_bounds = (-self.angle, 0.0) return circle
def make_arc(center, radius, angle): matrix = Matrix.Translation(center) @ Matrix.Rotation( angle, 4, 'Z') circle = SvCircle(matrix, radius) circle.u_bounds = (0, pi / 2) return circle