From 81ed56cbce99c9991c989163c802b4cea42be58e Mon Sep 17 00:00:00 2001 From: Damien Picard Date: Tue, 17 Dec 2019 11:11:37 +0100 Subject: add_camera_rigs: refactor and cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix widgets’ names: they were hardcoded and didn’t follow the preferences, leading to crashes. - The UI was put back into the Item category, instead of Create, because it is not related to object creation. - Fix some strange topology in two widget shapes. - UI and operators use a new poll method, so that they work when either the rig or the camera is selected. - The composition guides UI was converted to a panel, so that they may be drag-selected. - Marker binding and DOF object operators were converted to the `bpy.data` API, making them simpler. - Bones were moved around so that they are more similar between rigs. - They were scaled down to be 1 unit long, a simpler length — for instance, widgets are the same size as modeled. Widgets were scaled up to compensate. - The camera and aim bones were placed at 1.7 unit high, to be approximately at a standing human’s eyes’ height if the scene is in meters. - Much of the rig generation was refactored to deduplicate code between the two rig types. - Automatic renaming to `.000` was removed, since Blender already handles duplicate names. - Widget prefix and collection were renamed to `WGT-` and `Widgets` respectively. This is to be closer to Rigify, hopefully unifying them. - The GPL license header was added to every file. - Some cleanup was done to better respect Python’s PEP 8. Reviewed By: Wayne Dixon Differential Revision: https://developer.blender.org/D6543 --- add_camera_rigs/ui_panels.py | 125 +++++++++++++++++++++++-------------------- 1 file changed, 68 insertions(+), 57 deletions(-) (limited to 'add_camera_rigs/ui_panels.py') diff --git a/add_camera_rigs/ui_panels.py b/add_camera_rigs/ui_panels.py index 3356d389..63fe158a 100644 --- a/add_camera_rigs/ui_panels.py +++ b/add_camera_rigs/ui_panels.py @@ -1,84 +1,95 @@ +# ##### BEGIN GPL LICENSE BLOCK ##### +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ##### END GPL LICENSE BLOCK ##### + import bpy from bpy.types import Panel +from .operators import get_arm_and_cam, CameraRigMixin + -class ADD_CAMERA_RIGS_PT_camera_rig_ui(Panel): - bl_category = 'Create' - bl_label = "Camera Rig UI" +class ADD_CAMERA_RIGS_PT_camera_rig_ui(Panel, CameraRigMixin): + bl_label = "Camera Rig" bl_space_type = 'VIEW_3D' bl_region_type = 'UI' - - _ACTIVE_OBJECT: object = None - - _ACTIVE_RIG_TYPE: str = None - - @classmethod - def poll(self, context): - self._ACTIVE_OBJECT = bpy.context.active_object - - if self._ACTIVE_OBJECT != None and "rig_id" in self._ACTIVE_OBJECT: - rigType = self._ACTIVE_OBJECT["rig_id"] - - if rigType == "Dolly_rig" or rigType == "Crane_rig": - self._ACTIVE_RIG_TYPE = rigType - return True - - return False + bl_category = 'Item' def draw(self, context): - arm = self._ACTIVE_OBJECT.data - poseBones = self._ACTIVE_OBJECT.pose.bones - activeCameraName = self._ACTIVE_OBJECT.children[0].name - - cam = bpy.data.cameras[bpy.data.objects[activeCameraName].data.name] + active_object = context.active_object + arm, cam = get_arm_and_cam(context.active_object) + pose_bones = arm.pose.bones + cam_data = cam.data layout = self.layout.box().column() layout.label(text="Clipping:") - layout.prop(cam, "clip_start", text="Start") - layout.prop(cam, "clip_end", text="End") - layout.prop(cam, "type") - layout.prop(cam.dof, "use_dof") - if cam.dof.use_dof: - if cam.dof.focus_object is None: - layout.operator("add_camera_rigs.add_dof_object", text="Add DOF Empty") - layout.prop(poseBones["Camera"], '["focus_distance"]', text="Focus Distance") - layout.prop(poseBones["Camera"], '["f-stop"]', text="F-Stop") - - layout.prop(self._ACTIVE_OBJECT, 'show_in_front', toggle=False, text='Show in front') - layout.prop(cam, "show_limits") - layout.prop(cam, "show_passepartout") - if cam.show_passepartout: - layout.prop(cam, "passepartout_alpha") + layout.prop(cam_data, "clip_start", text="Start") + layout.prop(cam_data, "clip_end", text="End") + layout.prop(cam_data, "type") + layout.prop(cam_data.dof, "use_dof") + if cam_data.dof.use_dof: + if cam_data.dof.focus_object is None: + layout.operator("add_camera_rigs.add_dof_object", + text="Add DOF Empty", icon="OUTLINER_OB_EMPTY") + layout.prop(pose_bones["Camera"], + '["focus_distance"]', text="Focus Distance") + layout.prop(pose_bones["Camera"], + '["aperture_fstop"]', text="F-Stop") + + layout.prop(active_object, 'show_in_front', + toggle=False, text='Show in Front') + layout.prop(cam_data, "show_limits") + layout.prop(cam_data, "show_passepartout") + if cam_data.show_passepartout: + layout.prop(cam_data, "passepartout_alpha") layout.row().separator() - # added the comp guides here - layout.operator( - "wm.call_menu", text="Composition Guides").name = "ADD_CAMERA_RIGS_MT_composition_guides_menu" + # Added the comp guides here + layout.popover( + panel="ADD_CAMERA_RIGS_PT_composition_guides", + text="Composition Guides",) layout.row().separator() - layout.prop(bpy.data.objects[activeCameraName], + layout.prop(cam, "hide_select", text="Make Camera Unselectable") layout.operator("add_camera_rigs.add_marker_bind", - text="Add Marker and Bind") - if bpy.context.scene.camera.name != activeCameraName: + text="Add Marker and Bind", icon="MARKER_HLT") + if context.scene.camera is not cam: layout.operator("add_camera_rigs.set_scene_camera", text="Make Camera Active", icon='CAMERA_DATA') - # Camera Lens - layout.label(text="Focal Length:") - layout.prop(poseBones["Camera"], '["focal_length"]', text="Focal Length (mm)") - if self._ACTIVE_RIG_TYPE == "Crane_rig": - layout = layout.box().column() - - # Crane arm stuff - layout.label(text="Crane Arm:") - layout.prop(poseBones["Crane_height"], 'scale', index=1, text="Arm Height") - layout.prop(poseBones["Crane_arm"], 'scale', index=1, text="Arm Length") + # Camera lens + layout.separator() + layout.prop(pose_bones["Camera"], '["lens"]', text="Focal Length (mm)") # Track to Constraint layout.label(text="Tracking:") - layout.prop(poseBones["Camera"], '["lock"]', text="Aim Lock", slider=True) + layout.prop(pose_bones["Camera"].constraints["Track To"], + 'influence', text="Aim Lock", slider=True) + + if arm["rig_id"].lower() == "crane_rig": + col = layout.box().column() + + # Crane arm stuff + col.label(text="Crane Arm:") + col.prop(pose_bones["Crane_height"], + 'scale', index=1, text="Arm Height") + col.prop(pose_bones["Crane_arm"], + 'scale', index=1, text="Arm Length") def register(): -- cgit v1.2.3