Fix add-ons with Python 3.12 by replacing "imp" with "importlib"
[blender-addons.git] / add_camera_rigs / ui_panels.py
blob14f7ef66a583ec0ff814db2b1b22ce63e4937e6e
1 # SPDX-FileCopyrightText: 2019-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 import bpy
6 from bpy.types import Panel
8 from .operators import get_rig_and_cam, CameraRigMixin
11 class ADD_CAMERA_RIGS_PT_camera_rig_ui(Panel, CameraRigMixin):
12 bl_label = "Camera Rig"
13 bl_space_type = 'VIEW_3D'
14 bl_region_type = 'UI'
15 bl_category = 'Item'
17 def draw(self, context):
18 active_object = context.active_object
19 rig, cam = get_rig_and_cam(context.active_object)
20 pose_bones = rig.pose.bones
21 cam_data = cam.data
22 layout = self.layout
24 # Camera lens
25 if rig["rig_id"].lower() in ("dolly_rig", "crane_rig"):
26 layout.prop(pose_bones["Camera"], '["lens"]',
27 text="Focal Length (mm)")
29 col = layout.column(align=True)
30 col.label(text="Clipping:")
31 col.prop(cam_data, "clip_start", text="Start")
32 col.prop(cam_data, "clip_end", text="End")
34 layout.prop(cam_data, "type")
36 # DoF
37 col = layout.column(align=False)
38 col.prop(cam_data.dof, "use_dof")
39 if cam_data.dof.use_dof:
40 sub = col.column(align=True)
41 if cam_data.dof.focus_object is None:
42 sub.operator("add_camera_rigs.set_dof_bone")
43 sub.prop(cam_data.dof, "focus_object")
44 if (cam_data.dof.focus_object is not None
45 and cam_data.dof.focus_object.type == 'ARMATURE'):
46 sub.prop_search(cam_data.dof, "focus_subtarget",
47 cam_data.dof.focus_object.data, "bones")
48 sub = col.column(align=True)
49 row = sub.row(align=True)
50 row.active = cam_data.dof.focus_object is None
51 row.prop(pose_bones["Camera"],
52 '["focus_distance"]', text="Focus Distance")
53 sub.prop(pose_bones["Camera"],
54 '["aperture_fstop"]', text="F-Stop")
56 # Viewport display
57 layout.prop(active_object, 'show_in_front',
58 toggle=False, text='Show in Front')
59 layout.prop(cam_data, "show_limits")
60 col = layout.column(align=True)
61 col.prop(cam_data, "show_passepartout")
62 if cam_data.show_passepartout:
63 col.prop(cam_data, "passepartout_alpha")
65 # Composition guides
66 layout.popover(
67 panel="ADD_CAMERA_RIGS_PT_composition_guides",
68 text="Composition Guides",)
70 # Props and operators
71 col = layout.column(align=True)
72 col.prop(cam,
73 "hide_select", text="Make Camera Unselectable")
74 col.operator("add_camera_rigs.add_marker_bind",
75 text="Add Marker and Bind", icon="MARKER_HLT")
76 col.operator("add_camera_rigs.set_scene_camera",
77 text="Make Camera Active", icon='CAMERA_DATA')
79 if rig["rig_id"].lower() in ("dolly_rig", "crane_rig"):
80 # Track to Constraint
81 col = layout.column(align=True)
82 track_to_constraint = None
83 for con in pose_bones["Camera"].constraints:
84 if con.type == 'TRACK_TO':
85 track_to_constraint = con
86 break
87 if track_to_constraint is not None:
88 col.label(text="Tracking:")
89 col.prop(track_to_constraint, 'influence',
90 text="Aim Lock", slider=True)
92 # Crane arm stuff
93 if rig["rig_id"].lower() == "crane_rig":
94 col = layout.column(align=True)
95 col.label(text="Crane Arm:")
96 col.prop(pose_bones["Crane_height"],
97 'scale', index=1, text="Arm Height")
98 col.prop(pose_bones["Crane_arm"],
99 'scale', index=1, text="Arm Length")
101 # 2D rig stuff
102 elif rig["rig_id"].lower() == "2d_rig":
103 col = layout.column(align=True)
104 col.label(text="2D Rig:")
105 col.prop(pose_bones["Camera"], '["rotation_shift"]',
106 text="Rotation/Shift")
107 if cam.data.sensor_width != 36:
108 col.label(text="Please set Camera Sensor Width to 36", icon="ERROR")
111 def register():
112 bpy.utils.register_class(ADD_CAMERA_RIGS_PT_camera_rig_ui)
115 def unregister():
116 bpy.utils.unregister_class(ADD_CAMERA_RIGS_PT_camera_rig_ui)