def execute(self, context):
        """Export a screenshot (of the 3D view)."""
        log_report("INFO", "Export screenshot: ...", self)

        panel_settings = context.scene.opengl_panel_settings
        filename_ext = panel_settings.screenshot_file_format
        ofp = self.filepath + "." + filename_ext

        # Get panel settings
        full_screenshot = not panel_settings.only_3d_view
        use_camera_perspective = panel_settings.use_camera_perspective

        # Cache previous settings
        previous_cam = bpy.context.scene.camera
        area_3d = next(area for area in bpy.context.screen.areas
                       if area.type == "VIEW_3D")
        previous_perspective = area_3d.spaces[0].region_3d.view_perspective

        # Create Screenshot
        selected_cam = get_selected_camera()
        if use_camera_perspective and selected_cam is not None:
            bpy.context.scene.camera = selected_cam
            area_3d.spaces[0].region_3d.view_perspective = "CAMERA"
            _update_ui(context)
        bpy.ops.screen.screenshot(filepath=ofp,
                                  full=full_screenshot,
                                  check_existing=False)

        # Restore previous settings
        area_3d.spaces[0].region_3d.view_perspective = previous_perspective
        bpy.context.scene.camera = previous_cam

        log_report("INFO", "Export screenshot: Done", self)
        return {"FINISHED"}
 def execute(self, context):
     """Render the point cloud and save the result as image in Blender."""
     log_report("INFO", "Save opengl render as image: ...", self)
     save_point_size = context.scene.opengl_panel_settings.save_point_size
     cam = get_selected_camera()
     image_name = "OpenGL Render"
     log_report("INFO", "image_name: " + image_name, self)
     draw_manager = DrawManager.get_singleton()
     coords, colors = draw_manager.get_coords_and_colors(visible_only=True)
     render_opengl_image(image_name, cam, coords, colors, save_point_size)
     log_report("INFO", "Save opengl render as image: Done", self)
     return {"FINISHED"}
    def execute(self, context):
        """Render the point cloud and export the result as image sequence."""
        log_report("INFO", "Export opengl render as image sequencemation: ...",
                   self)
        scene = context.scene
        save_point_size = scene.opengl_panel_settings.save_point_size

        # The export helper stores the path in self.filepath (even if it is a
        # directory)
        output_dp = self.filepath
        log_report("INFO", "Output Directory Path: " + str(output_dp), self)

        if not os.path.isdir(output_dp):
            os.mkdir(output_dp)

        # Used to cache the results
        image_name = "OpenGL Export"
        ext = "." + scene.opengl_panel_settings.render_file_format
        save_alpha = scene.opengl_panel_settings.save_alpha
        selected_cam = get_selected_camera()
        use_camera_keyframes = (
            scene.opengl_panel_settings.use_camera_keyframes_for_rendering)
        if (use_camera_keyframes and selected_cam is not None
                and selected_cam.animation_data is not None):
            animation_indices = get_object_animation_indices(selected_cam)
        else:
            animation_indices = get_scene_animation_indices()

        draw_manager = DrawManager.get_singleton()
        coords, colors = draw_manager.get_coords_and_colors(visible_only=True)
        for idx in animation_indices:
            bpy.context.scene.frame_set(idx)
            current_frame_fn = str(idx).zfill(5) + ext
            current_frame_fp = os.path.join(output_dp, current_frame_fn)

            log_report("INFO", "Output File Path: " + str(current_frame_fp),
                       self)
            render_opengl_image(image_name, selected_cam, coords, colors,
                                save_point_size)
            save_image_to_disk(image_name, current_frame_fp, save_alpha)

        log_report("INFO", "Save opengl render as animation: Done", self)
        return {"FINISHED"}
    def execute(self, context):
        """Render the point cloud and export the result as image."""
        log_report("INFO", "Export opengl render as image: ...", self)
        scene = context.scene
        save_point_size = scene.opengl_panel_settings.save_point_size

        filename_ext = scene.opengl_panel_settings.render_file_format
        ofp = self.filepath + "." + filename_ext
        log_report("INFO", "Output File Path: " + ofp, self)

        # Used to cache the results
        image_name = "OpenGL Export"

        cam = get_selected_camera()
        draw_manager = DrawManager.get_singleton()
        coords, colors = draw_manager.get_coords_and_colors(visible_only=True)
        render_opengl_image(image_name, cam, coords, colors, save_point_size)

        save_alpha = scene.opengl_panel_settings.save_alpha
        save_image_to_disk(image_name, ofp, save_alpha)

        log_report("INFO", "Save opengl render as image: Done", self)
        return {"FINISHED"}
 def poll(cls, context):
     """Return the availability status of the operator."""
     cam = get_selected_camera()
     return cam is not None and cam.animation_data is not None
    def draw(self, context):
        """Draw the panel with corrresponding properties and operators."""
        settings = context.scene.opengl_panel_settings
        layout = self.layout
        selected_cam = get_selected_camera()

        viz_box = layout.box()
        viz_box.label(text="Visualization")
        row = viz_box.row()
        row.prop(
            settings,
            "viz_point_size",
            text="OpenGL Visualization Point Size",
        )
        row = viz_box.row()
        row.operator(UpdatePointCloudVisualizationOperator.bl_idname)

        export_screenshot_box = layout.box()
        export_screenshot_box.label(
            text="Export a single or multiple"
            " screenshots (of the 3D view) to disk."
        )
        row = export_screenshot_box.row()
        row.prop(settings, "screenshot_file_format", text="File Format")
        row = export_screenshot_box.row()
        row.prop(settings, "only_3d_view", text="Export Only 3D view")
        row = export_screenshot_box.row()
        row.prop(
            settings,
            "use_camera_perspective",
            text="Use Perspective of selected Camera",
        )
        row.enabled = selected_cam is not None
        row = export_screenshot_box.row()
        row.operator(ExportScreenshotImageOperator.bl_idname)
        row = export_screenshot_box.row()
        row.prop(
            settings,
            "use_camera_keyframes_for_screenshots",
            text="Use Camera Keyframes",
        )
        row.enabled = (
            selected_cam is not None
            and selected_cam.animation_data is not None
        )
        row = export_screenshot_box.row()
        row.operator(ExportScreenshotAnimationOperator.bl_idname)

        write_point_cloud_box = layout.box()
        write_point_cloud_box.label(
            text="Select a camera to save or export an OpenGL point cloud"
            " rendering"
        )
        row = write_point_cloud_box.row()
        row.prop(
            settings,
            "save_point_size",
            text="Point Size of OpenGL Point Cloud",
        )
        row.enabled = selected_cam is not None
        save_point_cloud_box = write_point_cloud_box.box()
        save_point_cloud_box.label(text="Save point cloud rendering:")
        row = save_point_cloud_box.row()
        row.operator(SaveOpenGLRenderImageOperator.bl_idname)

        export_point_cloud_box = write_point_cloud_box.box()
        export_point_cloud_box.label(text="Export point cloud rendering:")
        row = export_point_cloud_box.row()
        row.prop(settings, "render_file_format", text="File Format")
        row.enabled = selected_cam is not None
        row = export_point_cloud_box.row()
        row.prop(settings, "save_alpha", text="Save Alpha Values")
        row.enabled = selected_cam is not None
        row = export_point_cloud_box.row()
        row.operator(ExportOpenGLRenderImageOperator.bl_idname)
        row = export_point_cloud_box.row()
        row.prop(
            settings,
            "use_camera_keyframes_for_rendering",
            text="Use Camera Keyframes",
        )
        row.enabled = (
            selected_cam is not None
            and selected_cam.animation_data is not None
        )
        row = export_point_cloud_box.row()
        row.operator(ExportOpenGLRenderAnimationOperator.bl_idname)
    def execute(self, context):
        """Export a sequence of screenshots using the selected camera."""
        log_report("INFO", "Export screenshot sequence: ...", self)

        scene = context.scene
        panel_settings = scene.opengl_panel_settings
        filename_ext = panel_settings.screenshot_file_format
        output_dp = self.filepath

        # Get panel settings
        full_screenshot = not panel_settings.only_3d_view
        use_camera_perspective = panel_settings.use_camera_perspective

        # Cache previous settings
        previous_cam = bpy.context.scene.camera
        area_3d = next(area for area in bpy.context.screen.areas
                       if area.type == "VIEW_3D")
        previous_perspective = area_3d.spaces[0].region_3d.view_perspective

        # Create Screenshots
        selected_cam = get_selected_camera()
        use_camera_keyframes = (
            scene.opengl_panel_settings.use_camera_keyframes_for_screenshots)
        if (use_camera_keyframes and selected_cam is not None
                and selected_cam.animation_data is not None):
            animation_indices = get_object_animation_indices(selected_cam)
        else:
            animation_indices = get_scene_animation_indices()
        # called_view_camera_op = False
        if use_camera_perspective and selected_cam is not None:
            bpy.context.scene.camera = selected_cam
            # Option 1
            area_3d.spaces[0].region_3d.view_perspective = "CAMERA"
            # Option 2
            # https://docs.blender.org/api/current/bpy.ops.view3d.html#bpy.ops.view3d.view_camera
            # if area_3d.spaces[0].region_3d.view_perspective != "CAMERA":
            #     bpy.ops.view3d.view_camera()
            #     called_view_camera_op = True
        for idx in animation_indices:
            bpy.context.scene.frame_set(idx)
            _update_ui(context)

            current_frame_fn = str(idx).zfill(5) + "." + filename_ext
            current_frame_fp = os.path.join(output_dp, current_frame_fn)
            log_report("INFO", "Output File Path: " + str(current_frame_fp),
                       self)
            bpy.ops.screen.screenshot(
                filepath=current_frame_fp,
                full=full_screenshot,
                check_existing=False,
            )

        # Restore previous settings
        # Option 1
        area_3d.spaces[0].region_3d.view_perspective = previous_perspective
        # Option 2
        # if called_view_camera_op:
        #     bpy.ops.view3d.view_camera()

        bpy.context.scene.camera = previous_cam
        log_report("INFO", "Export screenshot sequence: Done", self)
        return {"FINISHED"}