diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2020-12-07 22:11:00 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2020-12-07 22:43:22 +0300 |
commit | f8d6489fb6e4b8f3c1029d3468ebbe6781f599dd (patch) | |
tree | d9b2cddabba936c2327389176a763ec78fd3fd95 /rigify/utils/widgets.py | |
parent | c93dc355888ec2f9a4376ad6cf0422277c69d565 (diff) |
Rigify: use separate widget collection for each generated rig.
As pointed out in comments to T73114, using the same name has downsides.
In addition, remove the widget parent object that was inherited
from the old pre-collection way Rigify worked and has no other
purpose than grouping objects like the collection already does.
Rename the widgets and the collection when renaming the rig.
Finally as an aside add a couple of options to create_widget.
Diffstat (limited to 'rigify/utils/widgets.py')
-rw-r--r-- | rigify/utils/widgets.py | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/rigify/utils/widgets.py b/rigify/utils/widgets.py index 04e176c6..f198afda 100644 --- a/rigify/utils/widgets.py +++ b/rigify/utils/widgets.py @@ -54,7 +54,7 @@ def obj_to_bone(obj, rig, bone_name, bone_transform_name=None): obj.matrix_basis = rig.matrix_world @ bone.bone.matrix_local @ Matrix.Scale(scale, 4) -def create_widget(rig, bone_name, bone_transform_name=None): +def create_widget(rig, bone_name, bone_transform_name=None, *, widget_name=None, widget_force_new=False): """ Creates an empty widget object for a bone, and returns the object. """ assert rig.mode != 'EDIT' @@ -64,37 +64,34 @@ def create_widget(rig, bone_name, bone_transform_name=None): if bone.custom_shape: return None - obj_name = WGT_PREFIX + rig.name + '_' + bone_name + obj_name = widget_name or WGT_PREFIX + rig.name + '_' + bone_name scene = bpy.context.scene - collection = ensure_widget_collection(bpy.context) + collection = ensure_widget_collection(bpy.context, 'WGTS_' + rig.name) # Check if it already exists in the scene - if obj_name in scene.objects: - # Move object to bone position, in case it changed - obj = scene.objects[obj_name] - obj_to_bone(obj, rig, bone_name, bone_transform_name) + if not widget_force_new: + if obj_name in scene.objects: + # Move object to bone position, in case it changed + obj = scene.objects[obj_name] + obj_to_bone(obj, rig, bone_name, bone_transform_name) + + return None - return None - else: # Delete object if it exists in blend data but not scene data. # This is necessary so we can then create the object without # name conflicts. if obj_name in bpy.data.objects: - bpy.data.objects[obj_name].user_clear() bpy.data.objects.remove(bpy.data.objects[obj_name]) - # Create mesh object - mesh = bpy.data.meshes.new(obj_name) - obj = bpy.data.objects.new(obj_name, mesh) - collection.objects.link(obj) + # Create mesh object + mesh = bpy.data.meshes.new(obj_name) + obj = bpy.data.objects.new(obj_name, mesh) + collection.objects.link(obj) - # Move object to bone position and set layers - obj_to_bone(obj, rig, bone_name, bone_transform_name) - wgts_group_name = 'WGTS_' + rig.name - if wgts_group_name in bpy.data.objects.keys(): - obj.parent = bpy.data.objects[wgts_group_name] + # Move object to bone position and set layers + obj_to_bone(obj, rig, bone_name, bone_transform_name) - return obj + return obj def create_circle_polygon(number_verts, axis, radius=1.0, head_tail=0.0): |