[Bf-extensions-cvs] [ece39d80] master: Rigify: Clean up "Rigify Buttons" panel UX

Demeter Dzadik noreply at git.blender.org
Tue Dec 14 12:45:05 CET 2021


Commit: ece39d809ceb27b5a06da7c4b8f25ca77016b151
Author: Demeter Dzadik
Date:   Tue Dec 14 12:44:52 2021 +0100
Branches: master
https://developer.blender.org/rBAece39d809ceb27b5a06da7c4b8f25ca77016b151

Rigify: Clean up "Rigify Buttons" panel UX

The overall goal of this patch is to improve the UI/UX of the panel previously known as "Rigify Buttons" which presumably takes its name from the old "Buttons Panel" which is now known as the Properties Editor.

Before:
{F10511640}
After:
{F10511624}

- Make Rigify less reliant on name matching when it comes to maintaining the link between the metarig, the UI script, the generated rig, and the widgets collection. (Use pointers only, names shouldn't matter!)
- Change the "Advanced" toggle button into a real sub-panel.
- Split up the "Rigify Buttons" panels into "Rigify Generation" and "Rigify Samples" panels in non-edit and edit mode respectively, to better describe what the user will find there.

Changes in the Rigify Buttons panel:
- Removed the "overwrite/new" enum.
	- If there is a target rig object, it will be overwritten. If not, it will be created.
	- If a rig object with the desired name already existed, but wasn't selected as the target rig, the "overwrite" option still overwrote that rig. I don't agree with that because this meant messing with data without indicating that that data is going to be messed with. Unaware users could lose data/work. With these changes, the worst thing that can happen is that your rig ends up with a .001 suffix.
- Removed the "rig name" text input field. Before this patch, this would always rename your rig object and your rig script text datablock, which I think is more frustrating than useful. Now you can simply rename them after generation yourself, and the names will be kept in subsequent generations.
- Single-column layout
- Changed the "Advanced Options" into a sub-panel instead.

On request:
- Added an info message to show the name of the successfully generated rig:
{F10159079}

Feedback welcome.

Reviewed By: angavrilov

Differential Revision: https://developer.blender.org/D11356

===================================================================

M	rigify/__init__.py
M	rigify/generate.py
M	rigify/rig_ui_template.py
M	rigify/ui.py
M	rigify/utils/collections.py
M	rigify/utils/widgets.py

===================================================================

diff --git a/rigify/__init__.py b/rigify/__init__.py
index 019adb48..20e18a42 100644
--- a/rigify/__init__.py
+++ b/rigify/__init__.py
@@ -512,20 +512,6 @@ def register():
     IDStore.rigify_types = CollectionProperty(type=RigifyName)
     IDStore.rigify_active_type = IntProperty(name="Rigify Active Type", description="The selected rig type")
 
-    bpy.types.Armature.rigify_advanced_generation = BoolProperty(name="Advanced Options",
-        description="Enables/disables advanced options for Rigify rig generation",
-        default=False)
-
-    def update_mode(self, context):
-        if self.rigify_generate_mode == 'new':
-            self.rigify_force_widget_update = False
-
-    bpy.types.Armature.rigify_generate_mode = EnumProperty(name="Rigify Generate Rig Mode",
-        description="'Generate Rig' mode. In 'overwrite' mode the features of the target rig will be updated as defined by the metarig. In 'new' mode a new rig will be created as defined by the metarig. Current mode",
-        update=update_mode,
-        items=( ('overwrite', 'overwrite', ''),
-                ('new', 'new', '')))
-
     bpy.types.Armature.rigify_force_widget_update = BoolProperty(name="Force Widget Update",
         description="Forces Rigify to delete and rebuild all the rig widgets. if unset, only missing widgets will be created",
         default=False)
@@ -533,6 +519,9 @@ def register():
     bpy.types.Armature.rigify_mirror_widgets = BoolProperty(name="Mirror Widgets",
         description="Make widgets for left and right side bones linked duplicates with negative X scale for the right side, based on bone name symmetry",
         default=True)
+    bpy.types.Armature.rigify_widgets_collection = PointerProperty(type=bpy.types.Collection,
+        name="Widgets Collection",
+        description="Defines which collection to place widget objects in. If unset, a new one will be created based on the name of the rig")
 
     bpy.types.Armature.rigify_target_rig = PointerProperty(type=bpy.types.Object,
         name="Rigify Target Rig",
@@ -546,11 +535,6 @@ def register():
     bpy.types.Armature.rigify_finalize_script = PointerProperty(type=bpy.types.Text,
         name="Finalize Script",
         description="Run this script after generation to apply user-specific changes")
-
-    bpy.types.Armature.rigify_rig_basename = StringProperty(name="Rigify Rig Name",
-        description="Defines the name of the Rig. If unset, in 'new' mode 'rig' will be used, in 'overwrite' mode the target rig name will be used",
-        default="")
-
     IDStore.rigify_transfer_only_selected = BoolProperty(
         name="Transfer Only Selected",
         description="Transfer selected bones only", default=True)
@@ -592,12 +576,9 @@ def unregister():
     del ArmStore.rigify_colors_index
     del ArmStore.rigify_colors_lock
     del ArmStore.rigify_theme_to_add
-    del ArmStore.rigify_advanced_generation
-    del ArmStore.rigify_generate_mode
     del ArmStore.rigify_force_widget_update
     del ArmStore.rigify_target_rig
     del ArmStore.rigify_rig_ui
-    del ArmStore.rigify_rig_basename
 
     IDStore = bpy.types.WindowManager
     del IDStore.rigify_collection
diff --git a/rigify/generate.py b/rigify/generate.py
index 501c335f..a674ade4 100644
--- a/rigify/generate.py
+++ b/rigify/generate.py
@@ -30,7 +30,7 @@ from .utils.widgets import WGT_PREFIX
 from .utils.widgets_special import create_root_widget
 from .utils.mechanism import refresh_all_drivers
 from .utils.misc import gamma_correct, select_object
-from .utils.collections import ensure_widget_collection, list_layer_collections, filter_layer_collections_by_object
+from .utils.collections import ensure_collection, list_layer_collections, filter_layer_collections_by_object
 from .utils.rig import get_rigify_type
 
 from . import base_generate
@@ -55,9 +55,6 @@ class Generator(base_generate.BaseGenerator):
 
         self.id_store = context.window_manager
 
-        self.rig_new_name = ""
-        self.rig_old_name = ""
-
 
     def find_rig_class(self, rig_type):
         rig_module = rig_lists.rigs[rig_type]["module"]
@@ -76,55 +73,42 @@ class Generator(base_generate.BaseGenerator):
         self.collection = self.layer_collection.collection
 
 
-    def __create_rig_object(self):
-        scene = self.scene
-        id_store = self.id_store
-        meta_data = self.metarig.data
-
-        # Check if the generated rig already exists, so we can
-        # regenerate in the same object.  If not, create a new
-        # object to generate the rig in.
+    def ensure_rig_object(self) -> bpy.types.Object:
+        """Check if the generated rig already exists, so we can
+        regenerate in the same object. If not, create a new
+        object to generate the rig in.
+        """
         print("Fetch rig.")
+        meta_data = self.metarig.data
 
-        self.rig_new_name = name = meta_data.rigify_rig_basename or "rig"
-
-        obj = None
-
-        # Try existing object if overwriting
-        if meta_data.rigify_generate_mode == 'overwrite':
-            obj = meta_data.rigify_target_rig
-
-            if obj:
-                self.rig_old_name = obj.name
-
-                obj.name = name
-                obj.data.name = obj.name
-
-            elif name in bpy.data.objects:
-                obj = bpy.data.objects[name]
+        target_rig = meta_data.rigify_target_rig
+        if not target_rig:
+            if "metarig" in self.metarig.name:
+                rig_new_name = self.metarig.name.replace("metarig", "rig")
+            elif "META" in self.metarig.name:
+                rig_new_name = self.metarig.name.replace("META", "RIG")
+            else:
+                rig_new_name = "RIG-" + self.metarig.name
 
-        # Create a new object if not found
-        if not obj:
-            obj = bpy.data.objects.new(name, bpy.data.armatures.new(name))
-            obj.display_type = 'WIRE'
+            target_rig = bpy.data.objects.new(rig_new_name, bpy.data.armatures.new(rig_new_name))
+            target_rig.display_type = 'WIRE'
 
         # If the object is already added to the scene, switch to its collection
-        if obj.name in self.context.scene.collection.all_objects:
-            self.__switch_to_usable_collection(obj)
+        if target_rig.name in self.context.scene.collection.all_objects:
+            self.__switch_to_usable_collection(target_rig)
         else:
             # Otherwise, add to the selected collection or the metarig collection if unusable
             if (self.layer_collection not in self.usable_collections
                 or self.layer_collection == self.view_layer.layer_collection):
                 self.__switch_to_usable_collection(self.metarig, True)
 
-            self.collection.objects.link(obj)
+            self.collection.objects.link(target_rig)
 
         # Configure and remember the object
-        meta_data.rigify_target_rig = obj
-        obj.data.pose_position = 'POSE'
+        meta_data.rigify_target_rig = target_rig
+        target_rig.data.pose_position = 'POSE'
 
-        self.obj = obj
-        return obj
+        return target_rig
 
 
     def __unhide_rig_object(self, obj):
@@ -144,11 +128,11 @@ class Generator(base_generate.BaseGenerator):
             raise Exception('Could not generate: Could not find a usable collection.')
 
 
-    def __create_widget_group(self):
-        new_group_name = "WGTS_" + self.obj.name
-        wgts_group_name = "WGTS_" + (self.rig_old_name or self.obj.name)
-
-        # Find the old widgets collection
+    def __find_legacy_collection(self) -> bpy.types.Collection:
+        """For backwards comp, matching by name to find a legacy collection.
+        (For before there was a Widget Collection PointerProperty)
+        """
+        wgts_group_name = "WGTS_" + self.obj.name
         old_collection = bpy.data.collections.get(wgts_group_name)
 
         if not old_collection:
@@ -160,16 +144,22 @@ class Generator(base_generate.BaseGenerator):
                 old_collection = legacy_collection
 
         if old_collection:
-            # Remove widgets if force update is set
-            if self.metarig.data.rigify_force_widget_update:
-                for obj in list(old_collection.objects):
-                    bpy.data.objects.remove(obj)
-
             # Rename the collection
-            old_collection.name = new_group_name
+            old_collection.name = wgts_group_name
+        
+        return old_collection
 
+    def ensure_widget_collection(self):
         # Create/find widget collection
-        self.widget_collection = ensure_widget_collection(self.context, new_group_name)
+        self.widget_collection = self.metarig.data.rigify_widgets_collection
+        if not self.widget_collection:
+            self.widget_collection = self.__find_legacy_collection()
+        if not self.widget_collection:
+            wgts_group_name = "WGTS_" + self.obj.name.replace("RIG-", "")
+            self.widget_collection = ensure_collection(self.context, wgts_group_name, hidden=True)
+
+        self.metarig.data.rigify_widgets_collection = self.widget_collection
+
         self.use_mirror_widgets = self.metarig.data.rigify_mirror_widgets
 
         # Build tables for existing widgets
@@ -177,7 +167,11 @@ class Generator(base_generate.BaseGenerator):
         self.new_widget_table = {}
         self.widget_mirror_mesh = {}
 
-        if not self.metarig.data.rigify_force_widget_update and self.obj.pose:
+        if self.metarig.data.rigify_force_widget_update:
+            # Remove widgets if force update is set
+            for obj in list(self.widget_collection.objects):
+                bpy.data.objects.remove(obj)
+        elif self.obj.pose:
             # Find all widgets from the collection referenced by the old rig
             known_widgets = set(obj.name for obj in self.widget_collection.objects)
 
@@ -430,7 +424,7 @@ class Generator(base_generate.BaseGenerator):
 
         #------------------------------------------
         # Create/find the rig object and set it up
-        obj = self.__create_rig_object()
+        self.obj = obj = self.ensure_rig_object()
 
         self.__unhide_rig_object(obj)
 
@@ -446,8 +440,8 @@ c

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list