From 433176d25ae187c90f8f0660f509112e68708b1a Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Thu, 1 Feb 2018 16:18:21 +0100 Subject: [PATCH] CURA-4425 Cleanup and small refactor --- cura/Snapshot.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/cura/Snapshot.py b/cura/Snapshot.py index dc60f4ffda..d646fe8868 100644 --- a/cura/Snapshot.py +++ b/cura/Snapshot.py @@ -16,23 +16,19 @@ class Snapshot: @staticmethod def snapshot(width = 300, height = 300): scene = Application.getInstance().getController().getScene() - cam = scene.getActiveCamera() - render_width, render_height = cam.getWindowSize() - pp = PreviewPass(render_width, render_height) + active_camera = scene.getActiveCamera() + render_width, render_height = active_camera.getWindowSize() + preview_pass = PreviewPass(render_width, render_height) root = scene.getRoot() camera = Camera("snapshot", root) # determine zoom and look at - bbox = None + bbox = AxisAlignedBox() for node in DepthFirstIterator(root): if node.callDecoration("isSliceable") and node.getMeshData() and node.isVisible(): - if bbox is None: - bbox = node.getBoundingBox() - else: - bbox = bbox + node.getBoundingBox() - if bbox is None: - bbox = AxisAlignedBox() + bbox = bbox + node.getBoundingBox() + look_at = bbox.center size = max(bbox.width, bbox.height, bbox.depth * 0.5) @@ -52,10 +48,10 @@ class Snapshot: camera.setProjectionMatrix(projection_matrix) - pp.setCamera(camera) - pp.setSize(render_width, render_height) # texture size - pp.render() - pixel_output = pp.getOutput() + preview_pass.setCamera(camera) + preview_pass.setSize(render_width, render_height) # texture size + preview_pass.render() + pixel_output = preview_pass.getOutput() # It's a bit annoying that window size has to be taken into account if pixel_output.width() >= pixel_output.height(): @@ -70,5 +66,3 @@ class Snapshot: cropped_image = image.copy(0, image.height() // 2 - height // 2, width, height) return cropped_image - # if cropped_image.save("/home/jack/preview.png"): - # print("yooo")