diff --git a/cq_toplevel.py b/cq_toplevel.py index d691022..d800f62 100755 --- a/cq_toplevel.py +++ b/cq_toplevel.py @@ -28,15 +28,22 @@ from vtkmodules.vtkIOImage import vtkPNGWriter logger = logging.getLogger(__name__) -def export_png_image(obj, file_: str): +def export_png_image(obj, file_: str, orientation: str): assy = _to_assy(obj) renderer = toVTK(assy) win = vtkRenderWindow() win.AddRenderer(renderer) win.Render() camera = renderer.GetActiveCamera() - camera.Roll(-35) - camera.Elevation(-45) + if orientation == "front": + camera.Roll(-28) + camera.Elevation(-50) + elif orientation == "back": + camera.Roll(0) + camera.Elevation(-35) + elif orientation == "side": + camera.Yaw(75) + camera.Elevation(30) # adjust camera so full object is visible. # this also resizes the window, potentially changing its aspect ratio. # it's important that the window has been `Render()`'d at least once by now, @@ -106,9 +113,16 @@ def main(): cq.exporters.export(model_, args.export_stl) if args.export_png: + orientation = None + if "side" in args.export_png: + orientation = "side" + if "back" in args.export_png: + orientation = "back" + if "front" in args.export_png: + orientation = "front" model_ = model() logger.info("exporting png to %s", args.export_png) - export_png_image(model_, args.export_png) + export_png_image(model_, args.export_png, orientation) if args.export_vtk: vtk_file = args.export_vtk