add view3d utility
2.2.1 - added: class View3D to calculate area 3d related coordinates
This commit is contained in:
+31
-1
@@ -5,7 +5,7 @@ from mathutils import Vector#, Matrix
|
||||
from pathlib import Path
|
||||
import math
|
||||
from math import radians
|
||||
|
||||
from .view3d_utils import View3D
|
||||
from . import utils
|
||||
|
||||
|
||||
@@ -38,6 +38,35 @@ class GPTB_OT_flipx_view(bpy.types.Operator):
|
||||
context.scene.camera.scale.x *= -1
|
||||
return {"FINISHED"}
|
||||
|
||||
class GPTB_OT_view_camera_frame_fit(bpy.types.Operator):
|
||||
bl_idname = "view3d.view_camera_frame_fit"
|
||||
bl_label = "View Fit"
|
||||
bl_description = "Fit the camera in view (view 1:1)"
|
||||
bl_options = {"REGISTER"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.area.type == 'VIEW_3D' and \
|
||||
context.region_data.view_perspective == 'CAMERA'
|
||||
|
||||
def zoom_from_fac(self, zoomfac):
|
||||
from math import sqrt
|
||||
return (sqrt(4 * zoomfac) - sqrt(2)) * 50.0
|
||||
|
||||
def execute(self, context):
|
||||
# Calculate zoom level to fit in view considering upper and side panel (Not done by native view 1:1)
|
||||
# context.space_data.region_3d.view_camera_zoom = 0 # (value range: -30, - 600)
|
||||
view3d = View3D()
|
||||
view3d.fit_camera_view()
|
||||
|
||||
## re-center
|
||||
# context.space_data.region_3d.view_camera_offset = (0,0)
|
||||
|
||||
# With a margin
|
||||
# Calculate pan to fit view in viewport
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
class GPTB_OT_rename_data_from_obj(bpy.types.Operator):
|
||||
bl_idname = "gp.rename_data_from_obj"
|
||||
bl_label = "Rename GP From Object"
|
||||
@@ -635,6 +664,7 @@ class GPTB_OT_open_addon_prefs(bpy.types.Operator):
|
||||
classes = (
|
||||
GPTB_OT_copy_text,
|
||||
GPTB_OT_flipx_view,
|
||||
GPTB_OT_view_camera_frame_fit,
|
||||
GPTB_OT_rename_data_from_obj,
|
||||
GPTB_OT_draw_cam,
|
||||
GPTB_OT_set_view_as_cam,
|
||||
|
||||
Reference in New Issue
Block a user