def generate_surface(self, solid, field, count, min_r, threshold, field_min, field_max, mask, seed): counts = self.distribute_faces(solid.Faces, count) new_verts = [] mask = repeat_last_for_length(mask, len(solid.Faces)) counts = repeat_last_for_length(counts, len(solid.Faces)) for face, ok, cnt in zip(solid.Faces, mask, counts): if not ok: continue def check(uv, vert): point = Base.Vector(vert) return face.isInside(point, self.get_tolerance(), True) surface = SvSolidFaceSurface(face) _, face_verts = populate_surface(surface, field, cnt, threshold, self.proportional, field_min, field_max, min_r, seed, predicate=check) new_verts.extend(face_verts) return new_verts
def process(self): if not any(socket.is_linked for socket in self.outputs): return solids_in = self.inputs[0].sv_get(deepcopy=False) matrixes = self.inputs[1].sv_get(deepcopy=False) slices = [] slices_face = [] faces_add = slices_face.extend if self.flat_output else slices_face.append slices_add = slices.extend if self.flat_output else slices.append for solid, matrix in zip(*mlr([solids_in, matrixes])): location = matrix.decompose()[0] norm = (matrix @ Vector((0, 0, 1))) - location dist = norm.dot(location) wires = solid.slice(Base.Vector(norm), dist) edges_curves = [] faces = [] for wire in wires: for edge in wire.Edges: curve = SvSolidEdgeCurve(edge) edges_curves.append(curve) if wires: face = Part.Face(wires) faces.append(SvSolidFaceSurface(face).to_nurbs()) if faces: faces_add(faces) if edges_curves: slices_add(edges_curves) self.outputs['Edges'].sv_set(slices) self.outputs['Faces'].sv_set(slices_face)
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 make_faces(self, verts, face_idxs): result = [] for face_i in face_idxs: face_i.append(face_i[0]) verts = [verts[idx] for idx in face_i] verts = [Base.Vector(*vert) for vert in verts] wire = Part.makePolygon(verts) face = Part.Face(wire) surface = SvSolidFaceSurface(face) #.to_nurbs() result.append(surface) return result
def make_solids(solid, face_surfaces): faces = [face_surface.face for face_surface in face_surfaces] result, map = solid.generalFuse(faces) solids = map[0] if not solids: solids = result.Solids cut_faces = [] for per_input_face in map[1:]: item = [] for shape in per_input_face: if isinstance(shape, Part.Face): cut_face = SvSolidFaceSurface(shape).to_nurbs() item.append(cut_face) cut_faces.append(item) return solids, cut_faces
def make_faces(self, verts, face_idxs): tolerance = 10**(-self.accuracy) result = [] fc_vector = Base.Vector for face_i in face_idxs: face_i = list(face_i) face_i.append(face_i[0]) fc_verts = [verts[idx] for idx in face_i] fc_verts = [fc_vector(*vert) for vert in fc_verts] wire = Part.makePolygon(fc_verts) wire.fixTolerance(tolerance) face = Part.Face(wire) surface = SvSolidFaceSurface(face) #.to_nurbs() result.append(surface) return result
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 generate_surface(self, solid, field, count, min_r, radius_field, threshold, field_min, field_max, mask): counts = self.distribute_faces(solid.Faces, count) new_verts = [] new_radiuses = [] mask = repeat_last_for_length(mask, len(solid.Faces)) counts = repeat_last_for_length(counts, len(solid.Faces)) done_spheres = [] for face, ok, cnt in zip(solid.Faces, mask, counts): if not ok: continue def check(uv, vert): point = Base.Vector(vert) return face.isInside(point, self.get_tolerance(), True) surface = SvSolidFaceSurface(face) _, face_verts, radiuses = populate_surface( surface, field, cnt, threshold, self.proportional, field_min, field_max, min_r=min_r, min_r_field=radius_field, random_radius=self.random_radius, avoid_spheres=done_spheres, seed=None, predicate=check) done_spheres.extend(list(zip(face_verts, radiuses))) new_verts.extend(face_verts) new_radiuses.extend(radiuses) return new_verts, new_radiuses
def do_waffel(solid, matrix_a, matrix_b, zs_a, zs_b, thickness, split_face, select): sections_a, sections_b = make_sections(solid, matrix_a, zs_a, matrix_b, zs_b) n_a = len(sections_a) all_sections = sections_a + sections_b cyls = [] cyl_idx = 0 cyls_per_section = defaultdict(list) half_cyls1, half_cyls2 = [], [] for i, section_a in enumerate(sections_a): for j, section_b in enumerate(sections_b): r = section_a.section(section_b) if not r.Compounds[0].Edges: continue intersection_edge = r.Compounds[0].Edges[0] start = intersection_edge.Curve.value( intersection_edge.FirstParameter) end = intersection_edge.Curve.value( intersection_edge.LastParameter) #print(f"{i}+{j} => {start} - {end}") direction = end - start start = start - thickness * direction end = end + thickness * direction height = direction.Length + 2 * thickness * direction.Length direction.normalize() if split_face is not None: cylinder = Part.makeCylinder(thickness / 2.0, height, start, direction) cyls.append(cylinder) else: half1 = Part.makeCylinder(thickness / 2.0, height / 2.0, start, direction) mid = 0.5 * start + 0.5 * end half2 = Part.makeCylinder(thickness / 2.0, height / 2.0, mid, direction) half_cyls1.append(half1) half_cyls2.append(half2) cyls_per_section[i].append(cyl_idx) cyls_per_section[j].append(cyl_idx) cyl_idx += 1 if split_face is not None: half_cyls1, half_cyls2 = do_split_many(cyls, split_face, select) result_a = [] for i, section_a in enumerate(sections_a): half_cyls = [half_cyls1[k] for k in cyls_per_section[i]] part = section_a.cut(half_cyls) face = part.Faces[0] surface = SvSolidFaceSurface(face) result_a.append(surface) result_b = [] for j, section_b in enumerate(sections_b): half_cyls = [half_cyls2[k] for k in cyls_per_section[j]] part = section_b.cut(half_cyls) face = part.Faces[0] surface = SvSolidFaceSurface(face) result_b.append(surface) return result_a, result_b