From e9695231b627c7b7c3381c8db032e74e6bf58f7c Mon Sep 17 00:00:00 2001 From: Casey Bianco-Davis Date: Mon, 24 Apr 2023 14:27:41 -0700 Subject: [PATCH] grease-pencil-tools: add local camera for rotate canvas and flip canvas. previously the local cameras would be ignored by the rotate/flip. --- greasepencil_tools/draw_tools.py | 4 +++- greasepencil_tools/rotate_canvas.py | 4 ++-- greasepencil_tools/ui_panels.py | 11 ++++++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/greasepencil_tools/draw_tools.py b/greasepencil_tools/draw_tools.py index 375b43322..692279057 100644 --- a/greasepencil_tools/draw_tools.py +++ b/greasepencil_tools/draw_tools.py @@ -2,6 +2,8 @@ import bpy +from .ui_panels import get_camera + class GP_OT_camera_flip_x(bpy.types.Operator): bl_idname = "gp.camera_flip_x" bl_label = "Camera Flip X" @@ -14,7 +16,7 @@ class GP_OT_camera_flip_x(bpy.types.Operator): and context.space_data.region_3d.view_perspective == 'CAMERA' def execute(self, context): - context.scene.camera.scale.x *= -1 + get_camera().scale.x *= -1 return {"FINISHED"} def register(): diff --git a/greasepencil_tools/rotate_canvas.py b/greasepencil_tools/rotate_canvas.py index 812aa0259..4b325a9b5 100644 --- a/greasepencil_tools/rotate_canvas.py +++ b/greasepencil_tools/rotate_canvas.py @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-or-later from .prefs import get_addon_prefs +from .ui_panels import get_camera import bpy import math @@ -215,8 +216,7 @@ class RC_OT_RotateCanvas(bpy.types.Operator): self.ratio_inv = w / h if self.in_cam: - # Get camera from scene - self.cam = bpy.context.scene.camera + self.cam = get_camera() #return if one element is locked (else bypass location) if self.cam.lock_rotation[:] != (False, False, False): diff --git a/greasepencil_tools/ui_panels.py b/greasepencil_tools/ui_panels.py index 2e8a50f1b..d4d902ef6 100644 --- a/greasepencil_tools/ui_panels.py +++ b/greasepencil_tools/ui_panels.py @@ -2,6 +2,14 @@ import bpy +def get_camera(): + if bpy.context.area.type == 'VIEW_3D' and bpy.context.space_data.use_local_camera: + # Get camera from area's local camera + return bpy.context.space_data.camera + else: + # Get camera from scene + return bpy.context.scene.camera + class GP_PT_sidebarPanel(bpy.types.Panel): bl_label = "Grease Pencil Tools" bl_space_type = "VIEW_3D" @@ -30,8 +38,9 @@ class GP_PT_sidebarPanel(bpy.types.Panel): row.operator('view3d.rotate_canvas_reset', text = 'Reset Rotation', icon = 'FILE_REFRESH') row.operator('view3d.rotate_canvas_set', text = 'Save Rotation', icon = 'DRIVER_ROTATIONAL_DIFFERENCE') + cam = get_camera() # View flip - if context.scene.camera and context.scene.camera.scale.x < 0: + if cam and cam.scale.x < 0: row = layout.row(align=True) row.operator('gp.camera_flip_x', text = 'Camera Mirror Flip', icon = 'MOD_MIRROR') row.label(text='', icon='LOOP_BACK') -- 2.30.2