def booleanOp(fv0, fv1, opstr, temppath): try: import pymesh except ImportError: print( "ERROR: CSG requires pymesh, which could not successfully be imported" ) print("returning first mesh only.") return fv0 else: file0 = os.path.join(temppath, 'file0.obj') file1 = os.path.join(temppath, 'file1.obj') writeFV(file0, fv0) writeFV(file1, fv1) mesh1 = pymesh.meshio.load_mesh(file0) if mesh1.vertex_per_face != 3: mesh1 = pymesh.quad_to_tri(mesh1) mesh2 = pymesh.meshio.load_mesh(file1) if mesh2.vertex_per_face != 3: mesh2 = pymesh.quad_to_tri(mesh2) meshout = pymesh.boolean(mesh1, mesh2, operation=opstr, engine='igl') # os.remove(file0) # os.remove(file1) return {'vertices': meshout.vertices, 'faces': meshout.faces}
def main(): args = parse_args(); mesh = pymesh.load_mesh(args.input_mesh); if (mesh.vertex_per_face != 4): raise IOError("input mesh is not a quad mesh"); mesh = pymesh.quad_to_tri(mesh, args.keep_symmetry); pymesh.save_mesh(args.output_mesh, mesh, *mesh.get_attribute_names());
def main(): args = parse_args() mesh = pymesh.load_mesh(args.input_mesh) if (mesh.vertex_per_face != 4): raise IOError("input mesh is not a quad mesh") mesh = pymesh.quad_to_tri(mesh, args.keep_symmetry) pymesh.save_mesh(args.output_mesh, mesh, *mesh.get_attribute_names())
def main(): args = parse_args(); mesh = pymesh.load_mesh(args.input_mesh); if (mesh.vertex_per_face != 4): logging.warning("Input mesh is not quad mesh."); pymesh.save_mesh(args.output_mesh, mesh, *mesh.get_attribute_names()); else: mesh = pymesh.quad_to_tri(mesh, args.keep_symmetry); pymesh.save_mesh(args.output_mesh, mesh, *mesh.get_attribute_names());
def main(): args = parse_args() mesh = pymesh.load_mesh(args.input_mesh) if mesh.vertex_per_face == 4: logging.warning("Converting quad mesh to triangle mesh.") mesh = pymesh.quad_to_tri(mesh) if args.exact: name, ext = os.path.splitext(args.output_mesh) exact_mesh_file = name + ".xml" else: exact_mesh_file = None if mesh.num_vertices == 0 or mesh.num_faces == 0: # Empty input mesh, output empty mesh as well. result = pymesh.form_mesh(np.zeros((0, 3), dtype=float), np.zeros((0, 3), dtype=int)) if args.timing: update_info(args.output_mesh, 0) else: if args.engine == "igl": empty = pymesh.form_mesh(np.zeros((0, 3)), np.zeros((0, 3))) r = pymesh.boolean(mesh, empty, "union", engine=args.engine, with_timing=args.timing, exact_mesh_file=exact_mesh_file) else: # Empty mesh is valid for these libraries, using bbox instead. bbox = mesh.bbox center = (bbox[0] + bbox[1]) * 0.5 box = pymesh.generate_box_mesh(bbox[0] - np.ones(mesh.dim), bbox[1] + np.ones(mesh.dim)) r = pymesh.boolean(mesh, box, "intersection", engine=args.engine, with_timing=args.timing, exact_mesh_file=exact_mesh_file) if args.timing: result, timing = r update_info(args.output_mesh, timing) else: result = r pymesh.save_mesh(args.output_mesh, result)
def main(): args = parse_args(); mesh = pymesh.load_mesh(args.input_mesh); if mesh.vertex_per_face == 4: logging.warning("Converting quad mesh to triangle mesh."); mesh = pymesh.quad_to_tri(mesh); if args.exact: name,ext = os.path.splitext(args.output_mesh); exact_mesh_file = name + ".xml"; else: exact_mesh_file = None; if mesh.num_vertices ==0 or mesh.num_faces == 0: # Empty input mesh, output empty mesh as well. result = pymesh.form_mesh(np.zeros((0,3),dtype=float), np.zeros((0,3),dtype=int)); if args.timing: update_info(args.output_mesh, 0); else: if args.engine == "igl": empty = pymesh.form_mesh(np.zeros((0,3)), np.zeros((0,3))); r = pymesh.boolean( mesh, empty, "union", engine=args.engine, with_timing = args.timing, exact_mesh_file=exact_mesh_file); else: # Empty mesh is valid for these libraries, using bbox instead. bbox = mesh.bbox; center = (bbox[0] + bbox[1]) * 0.5; box = pymesh.generate_box_mesh( bbox[0] - np.ones(mesh.dim), bbox[1] + np.ones(mesh.dim)); r = pymesh.boolean( mesh, box, "intersection", engine=args.engine, with_timing = args.timing, exact_mesh_file=exact_mesh_file); if args.timing: result, timing = r; update_info(args.output_mesh, timing); else: result = r; pymesh.save_mesh(args.output_mesh, result);
def print_self_intersection_info(mesh, info): if mesh.vertex_per_face == 4: print_red("Converting quad to tri for self-intersection check.") mesh = pymesh.quad_to_tri(mesh) if mesh.num_vertices == 0 or mesh.num_faces == 0: num_intersections = 0 num_coplanar_intersecting_faces = 0 else: intersecting_faces = pymesh.detect_self_intersection(mesh) num_intersections = len(intersecting_faces) intersect_and_coplanar = coplanar_analysis(mesh, intersecting_faces) num_coplanar_intersecting_faces = len(intersect_and_coplanar) info["self_intersect"] = num_intersections > 0 info["num_self_intersections"] = num_intersections info["num_coplanar_intersecting_faces"] = num_coplanar_intersecting_faces print_property("self intersect", info["self_intersect"], False) if num_intersections > 0: print_property("num self intersections", num_intersections, 0) print_property("num coplanar intersecting faces", num_coplanar_intersecting_faces, 0)
def print_self_intersection_info(mesh, info): if mesh.vertex_per_face == 4: print_red("Converting quad to tri for self-intersection check."); mesh = pymesh.quad_to_tri(mesh); if mesh.num_vertices == 0 or mesh.num_faces == 0: num_intersections = 0; num_coplanar_intersecting_faces = 0; else: intersecting_faces = pymesh.detect_self_intersection(mesh); num_intersections = len(intersecting_faces); intersect_and_coplanar = coplanar_analysis(mesh, intersecting_faces); num_coplanar_intersecting_faces = len(intersect_and_coplanar); info["self_intersect"] = num_intersections > 0; info["num_self_intersections"] = num_intersections; info["num_coplanar_intersecting_faces"] = num_coplanar_intersecting_faces; print_property("self intersect", info["self_intersect"], False); if num_intersections > 0: print_property("num self intersections", num_intersections, 0); print_property("num coplanar intersecting faces", num_coplanar_intersecting_faces, 0);
def main(): args = parse_args() numeric_level = getattr(logging, args.log, None) if not isinstance(numeric_level, int): raise ValueError('Invalid log level: %s' % loglevel) logging.basicConfig(level=numeric_level) logger = logging.getLogger("tet.py") mesh = pymesh.load_mesh(args.in_mesh) if mesh.vertex_per_face == 4: logger.info("Spliting quad mesh into triangle mesh") mesh = pymesh.quad_to_tri(mesh) tet_mesh, t = pymesh.tetrahedralize(mesh, args.cell_size, args.radius_edge_ratio, args.facet_distance, args.feature_angle, args.engine, with_timing=True) pymesh.save_mesh(args.out_mesh, tet_mesh) logger.info("Running time: {}".format(t))
def main(): args = parse_args(); numeric_level = getattr(logging, args.log, None); if not isinstance(numeric_level, int): raise ValueError('Invalid log level: %s' % loglevel); logging.basicConfig(level=numeric_level); logger = logging.getLogger("tet.py"); mesh = pymesh.load_mesh(args.in_mesh); if mesh.vertex_per_face == 4: logger.info("Spliting quad mesh into triangle mesh"); mesh = pymesh.quad_to_tri(mesh); tet_mesh, t = pymesh.tetrahedralize(mesh, args.cell_size, args.radius_edge_ratio, args.facet_distance, args.feature_angle, args.engine, with_timing=True); pymesh.save_mesh(args.out_mesh, tet_mesh); logger.info("Running time: {}".format(t));