def build_curve_network(event=None, enforce_tangency=True): ''' mimic the curve network surfacing command from rhino ''' root_compound_shape = read_step_file("../assets/models/splinecage.stp") topology_explorer = TopologyExplorer(root_compound_shape) # approximate the hell out of all surfaces and curves # I wanna see it in its full glory display.Context.SetDeviationAngle(0.00001) # 0.001 -> default display.Context.SetDeviationCoefficient(0.0001) # 0.001 -> default tangent_constraint_faces = [f for f in topology_explorer.faces()] # loop through the imported faces # associate the length of each of the faces edges to the corresponding face _edge_length_to_face, _edge_length_to_edge = hash_edge_lenght_to_face( tangent_constraint_faces) # loop through the imported curves, avoiding the imported faces # when we've got these filtered out, we retrieved the geometry to build the surface from filtered_edges = [ e for e in topology_explorer._loop_topo( TopAbs_EDGE, root_compound_shape, TopAbs_FACE) ] filtered_length = {} for e in filtered_edges: l = round(length_from_edge(e), 3) filtered_length[l] = e input_edge_face_pairs, edges_no_adjacent_face = [], [] for l, edg in filtered_length.items(): if l in _edge_length_to_edge: edge_face_pair = [_edge_length_to_edge[l], _edge_length_to_face[l]] input_edge_face_pairs.append(edge_face_pair) else: edges_no_adjacent_face.append(edg) brep_plate_builder = BRepOffsetAPI_MakeFilling() if enforce_tangency: print("going for surface quality") brep_plate_builder.SetConstrParam( 0.0001, 0.001, 0.01, 0.01) # ?!!! Tol2d=1.0, Tol3d=1.0, TolAng=1.0, TolCurv=1.0 brep_plate_builder.SetApproxParam(8, 240) # MaxDeg=8, MaxSegments=9 brep_plate_builder.SetResolParam( 3, 64, 3) # Degree=3, NbPtsOnCur=15, NbIter=2, Anisotropie=0 else: print("quick and dirty") # illegal instruction 4??? for i in input_edge_face_pairs: display.DisplayShape(i, color=random_color()) constraint_edg, support_face = i if constraint_edg.IsNull() or support_face.IsNull(): print("OMG null") brep_plate_builder.Add(constraint_edg, support_face, GeomAbs_G1) # not entirely sure why this fails... how is that different from adding from points? # for e in edges_no_adjacent_face: # brep_plate_builder.Add(e, GeomAbs_C0) # libc++abi.dylib: terminating with uncaught exception of type Standard_OutOfRange for e in edges_no_adjacent_face: display.DisplayShape(e) for pt in divide_edge_by_nr_of_points(e, 12)[2:-2]: brep_plate_builder.Add(pt[1]) brep_plate_builder.Build() if brep_plate_builder.IsDone(): face = brep_plate_builder.Shape() display.DisplayColoredShape(face, "ORANGE") else: print("constructing the surface failed")
def build_curve_network(event=None, enforce_tangency=True): ''' mimic the curve network surfacing command from rhino ''' root_compound_shape = read_step_file("../assets/models/splinecage.stp") topology_explorer = TopologyExplorer(root_compound_shape) tangent_constraint_faces = [f for f in topology_explorer.faces()] # loop through the imported faces # associate the length of each of the faces edges to the corresponding face _edge_length_to_face, _edge_length_to_edge = hash_edge_length_to_face( tangent_constraint_faces) # loop through the imported curves, avoiding the imported faces # when we've got these filtered out, we retrieved the geometry to build the surface from filtered_edges = [ e for e in topology_explorer._loop_topo( TopAbs_EDGE, root_compound_shape, TopAbs_FACE) ] filtered_length = {} for e in filtered_edges: l = round(length_from_edge(e), 3) filtered_length[l] = e input_edge_face_pairs, edges_no_adjacent_face = [], [] for l, edg in filtered_length.items(): if l in _edge_length_to_edge: edge_face_pair = [_edge_length_to_edge[l], _edge_length_to_face[l]] input_edge_face_pairs.append(edge_face_pair) else: edges_no_adjacent_face.append(edg) brep_plate_builder = BRepOffsetAPI_MakeFilling() if enforce_tangency: print('going for surface quality...') brep_plate_builder.SetConstrParam( 0.0001, 0.001, 0.01, 0.01) # Tol2d=1.0, Tol3d=1.0, TolAng=1.0, TolCurv=1.0 brep_plate_builder.SetApproxParam(8, 240) # MaxDeg=8, MaxSegments=9 print('done.') else: print("quick and dirty") # illegal instruction 4??? for i in input_edge_face_pairs: display.DisplayShape(i, color=random_color()) constraint_edg, support_face = i if constraint_edg.IsNull() or support_face.IsNull(): print("Edge of face is null") brep_plate_builder.Add(constraint_edg, support_face, GeomAbs_G1) for e in edges_no_adjacent_face: display.DisplayShape(e) for pt in divide_edge_by_nr_of_points(e, 12)[2:-2]: brep_plate_builder.Add(pt[1]) brep_plate_builder.Build() if brep_plate_builder.IsDone(): face = brep_plate_builder.Shape() display.DisplayColoredShape(face, "ORANGE") else: print("constructing the surface failed")