cq_toplevel: allow exporting case in front/back/side orientation

This commit is contained in:
2024-02-07 22:08:46 +00:00
parent 425bd07d38
commit fd9e768fc1

View File

@@ -28,15 +28,22 @@ from vtkmodules.vtkIOImage import vtkPNGWriter
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def export_png_image(obj, file_: str): def export_png_image(obj, file_: str, orientation: str):
assy = _to_assy(obj) assy = _to_assy(obj)
renderer = toVTK(assy) renderer = toVTK(assy)
win = vtkRenderWindow() win = vtkRenderWindow()
win.AddRenderer(renderer) win.AddRenderer(renderer)
win.Render() win.Render()
camera = renderer.GetActiveCamera() camera = renderer.GetActiveCamera()
camera.Roll(-35) if orientation == "front":
camera.Elevation(-45) 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. # adjust camera so full object is visible.
# this also resizes the window, potentially changing its aspect ratio. # 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, # 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) cq.exporters.export(model_, args.export_stl)
if args.export_png: 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() model_ = model()
logger.info("exporting png to %s", args.export_png) 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: if args.export_vtk:
vtk_file = args.export_vtk vtk_file = args.export_vtk