def process(self): if not any(socket.is_linked for socket in self.outputs): return surface_s = self.inputs['Surface'].sv_get() knot_s = self.inputs['Knot'].sv_get() count_s = self.inputs['Count'].sv_get() input_level = get_data_nesting_level(surface_s, data_types=(SvSurface,)) flat_output = input_level < 2 surface_s = ensure_nesting_level(surface_s, 2, data_types=(SvSurface,)) knot_s = ensure_nesting_level(knot_s, 3) count_s = ensure_nesting_level(count_s, 3) surfaces_out = [] for surfaces, knots_i, counts_i in zip_long_repeat(surface_s, knot_s, count_s): new_surfaces = [] for surface, knots, counts in zip_long_repeat(surfaces, knots_i, counts_i): surface = SvNurbsSurface.get(surface) if surface is None: raise Exception("One of surfaces is not NURBS") for knot, count in zip_long_repeat(knots, counts): surface = surface.insert_knot(self.direction, knot, count, if_possible=self.if_possible) new_surfaces.append(surface) if flat_output: surfaces_out.extend(new_surfaces) else: surfaces_out.append(new_surfaces) self.outputs['Surface'].sv_set(surfaces_out)
def process(self): if not any(socket.is_linked for socket in self.outputs): return surface_s = self.inputs['Surface'].sv_get() input_level = get_data_nesting_level(surface_s, data_types=(SvSurface, )) flat_output = input_level < 2 surface_s = ensure_nesting_level(surface_s, 2, data_types=(SvSurface, )) tolerance = self.tolerance surfaces_out = [] for surfaces in surface_s: new_surfaces = [] for surface in surfaces: surface = SvNurbsSurface.get(surface) if surface is None: raise Exception("One of surfaces is not NURBS") surface = remove_excessive_knots(surface, self.direction, tolerance=tolerance) new_surfaces.append(surface) if flat_output: surfaces_out.extend(new_surfaces) else: surfaces_out.append(new_surfaces) self.outputs['Surface'].sv_set(surfaces_out)
def process(self): if not any(socket.is_linked for socket in self.outputs): return solids = self.inputs[0].sv_get() faces = [] faces_add = faces.extend if self.flat_output else faces.append wires = [] wires_add = wires.extend if self.flat_output else wires.append face_trims_out = [] for solid in solids: face_surface = [] outer_wires = [] for f in solid.Faces: surface = SvSolidFaceSurface(f) if self.nurbs_output: out_surface = SvNurbsSurface.get(surface) if out_surface is None: out_surface = surface else: out_surface = surface face_surface.append(out_surface) outer_wire = [] face_trims = [] for e in f.OuterWire.Edges: try: if self.nurbs_output: outer_wire.append( SvSolidEdgeCurve(e).to_nurbs()) else: outer_wire.append(SvSolidEdgeCurve(e)) except TypeError: pass trim, m, M = f.curveOnSurface(e) if self.nurbs_output: trim = trim.toBSpline(m, M) trim = SvFreeCadNurbsCurve(trim, ndim=2) else: #trim = trim.trim(m, M) trim = SvFreeCadCurve(trim, (m, M), ndim=2) face_trims.append(trim) #face_trims = SvConcatCurve(face_trims) outer_wires.append(outer_wire) face_trims_out.append(face_trims) faces_add(face_surface) wires_add(outer_wires) self.outputs['Solid Faces'].sv_set(faces) self.outputs['Outer Wire'].sv_set(wires) if 'TrimCurves' in self.outputs: self.outputs['TrimCurves'].sv_set(face_trims_out)
def process(self): if not any(socket.is_linked for socket in self.outputs): return surface_s = self.inputs['Surface'].sv_get() field_s = self.inputs['Field'].sv_get() coeff_s = self.inputs['Coefficient'].sv_get() surface_out = [] for surface, field, coeff in zip_long_repeat(surface_s, field_s, coeff_s): if isinstance(coeff, (list, tuple)): coeff = coeff[0] if self.use_control_points: nurbs = SvNurbsSurface.get(surface) if nurbs is not None: control_points = nurbs.get_control_points() else: raise Exception("Surface is not a NURBS!") m, n, _ = control_points.shape control_points = control_points.reshape((m * n, 3)) cpt_xs = control_points[:, 0] cpt_ys = control_points[:, 1] cpt_zs = control_points[:, 2] cpt_dxs, cpt_dys, cpt_dzs = field.evaluate_grid( cpt_xs, cpt_ys, cpt_zs) xs = cpt_xs + coeff * cpt_dxs ys = cpt_ys + coeff * cpt_dys zs = cpt_zs + coeff * cpt_dzs control_points = np.stack((xs, ys, zs)).T control_points = control_points.reshape((m, n, 3)) new_surface = SvNurbsSurface.build( nurbs.get_nurbs_implementation(), nurbs.get_degree_u(), nurbs.get_degree_v(), nurbs.get_knotvector_u(), nurbs.get_knotvector_v(), control_points, nurbs.get_weights()) else: new_surface = SvDeformedByFieldSurface( surface, field, coeff, by_normal=self.by_normal) surface_out.append(new_surface) self.outputs['Surface'].sv_set(surface_out)
def deconstruct(self, surface): nurbs = SvNurbsSurface.get(surface) if nurbs is None: nurbs = surface try: degree_u = nurbs.get_degree_u() degree_v = nurbs.get_degree_v() except: degree_u = None degree_v = None if hasattr(nurbs, 'get_knotvector_u'): knots_u = nurbs.get_knotvector_u().tolist() knots_v = nurbs.get_knotvector_v().tolist() else: knots_u = [] knots_v = [] try: points = nurbs.get_control_points() n_u, n_v, _ = points.shape if self.split_points: points = points.tolist() else: points = points.reshape((n_u * n_v, 3)).tolist() except Exception as e: points = [] n_u = n_v = 0 if hasattr(nurbs, 'get_weights'): weights = nurbs.get_weights() if self.split_points: weights = weights.tolist() else: weights = weights.flatten().tolist() else: weights = [] return degree_u, degree_v, knots_u, knots_v, points, n_u, n_v, weights
def get_faces(solid): face_surface = [] outer_wires = [] trims = [] for f in solid.Faces: surface = SvSolidFaceSurface(f) if self.nurbs_output: out_surface = SvNurbsSurface.get(surface) if out_surface is None: out_surface = surface else: out_surface = surface face_surface.append(out_surface) outer_wire = [] face_trims = [] for e in f.OuterWire.Edges: try: if self.nurbs_output: outer_wire.append(SvSolidEdgeCurve(e).to_nurbs()) else: outer_wire.append(SvSolidEdgeCurve(e)) except TypeError: pass trim,m,M = f.curveOnSurface(e) if self.nurbs_output: trim = trim.toBSpline(m,M) trim = SvFreeCadNurbsCurve(trim, ndim=2) else: #trim = trim.trim(m, M) trim = SvFreeCadCurve(trim, (m,M), ndim=2) face_trims.append(trim) outer_wires.append(outer_wire) trims.append(face_trims) return face_surface, outer_wires, trims
def surface_to_freecad(sv_surface, make_face=False): """ Convert SvSurface into FreeCAD's Surface. The surface must be presentable as NURBS. input: * sv_surface: SvSurface * make_face: if True, create a Part.Face out of the surface and assign it to the `face` property of the resulting surface output: SvFreeCadNurbsSurface """ nurbs = SvNurbsSurface.get(sv_surface) if nurbs is None: raise TypeError(f"{sv_surface} is not a NURBS surface") sv_fc_nurbs = SvNurbsMaths.build_surface(SvNurbsMaths.FREECAD, nurbs.get_degree_u(), nurbs.get_degree_v(), nurbs.get_knotvector_u(), nurbs.get_knotvector_v(), nurbs.get_control_points(), nurbs.get_weights()) if make_face: sv_fc_nurbs.face = Part.Face(sv_fc_nurbs.surface) return sv_fc_nurbs