diff --git a/__init__.py b/__init__.py index ee01b5f..3c0fc33 100644 --- a/__init__.py +++ b/__init__.py @@ -53,6 +53,7 @@ def register(): #bpy.types.Scene.bone_widget = bpy.props.PointerProperty(type=BoneWidgetSettings) #get_widgets(DefaultFolder, DefaultShapes) #get_widgets(CustomFolder, CustomShapes) + sys.modules.update({"bone_widget.ctx": context.BW_context()}) from bone_widget import ctx for f in ctx.folders: diff --git a/context.py b/context.py index 155cec1..bc98d81 100644 --- a/context.py +++ b/context.py @@ -153,12 +153,15 @@ class BW_context: ob = bpy.context.object if ob.type == 'ARMATURE': - bones = ob.pose.bones - return [b for b in bones if b.bone.select] - else: + return bpy.context.selected_pose_bones + #bones = ob.pose.bones + #return [b for b in bones if b.bone.select] + elif self.rig: widgets = self.selected_widgets return [b for b in self.rig.pose.bones if b.custom_shape in widgets] + return [] + @property def widget(self): if not self.poll(): @@ -253,7 +256,7 @@ class BW_context: return False if ob.type == 'ARMATURE' and ob.mode == 'POSE': return True - if ob.type in ('MESH','CURVE'): + if ob.type in ('MESH', 'CURVE'): return True return False diff --git a/operators.py b/operators.py index b6943a2..67420f3 100644 --- a/operators.py +++ b/operators.py @@ -420,7 +420,7 @@ class BW_OT_create_widget(Operator): @classmethod def poll(cls, context): - return ctx.bone and ctx.active_widget + return ctx.selected_bones and ctx.active_widget def execute(self, context): folder = ctx.active_folder @@ -633,23 +633,33 @@ class BW_OT_add_widget(Operator): bl_label = "Add Widget" bl_options = {'REGISTER', 'UNDO'} + replace: BoolProperty(default=False, name='Replace') + @classmethod def poll(cls, context): return ctx.widget + def invoke(self, context, event): + if event.ctrl: + self.replace = True + + return self.execute(context) + def execute(self, context): + folder = ctx.active_folder shape = ctx.widget bone = ctx.bone - if bone: - name = bone.name - else: - name = shape.name + if self.replace and ctx.active_widget: + name = ctx.active_widget.name + else: #Find a unique name + name = folder.get_widget_display_name(bone.name if bone else shape.name) - #name = name.split('-', 1)[-1] - #name = re.sub('.\d{3}', '', name) - folder = ctx.active_folder - name = folder.get_widget_clean_name(name) + i = 0 + org_name = name + while name in folder.widgets: + name = f'{org_name} {i:02d}' + i += 1 widget_path = folder.get_widget_path(name) icon_path = folder.get_icon_path(name) @@ -661,10 +671,11 @@ class BW_OT_add_widget(Operator): shape_copy = shape.copy() shape_copy.data = shape_copy.data.copy() - shape_copy.matrix_world = get_bone_matrix(bone) + if bone: + shape_copy.matrix_world = get_bone_matrix(bone) - mat = custom_shape_matrix(bone) - shape_copy.data.transform(mat) + mat = custom_shape_matrix(bone) + shape_copy.data.transform(mat) render_widget(shape_copy, icon_path) folder.add_widget(name) diff --git a/properties.py b/properties.py index 38f3295..632f2f3 100644 --- a/properties.py +++ b/properties.py @@ -70,12 +70,17 @@ def refresh(self, context): bpy.ops.bonewidget.refresh_folders() class BW_PG_folder(PropertyGroup): - icons = bpy.utils.previews.new() + #icons = bpy.utils.previews.new() path: StringProperty(subtype='FILE_PATH', default='Default', update=refresh) expand: BoolProperty() widgets: CollectionProperty(type=BW_PG_widget) widget_index: IntProperty() + @property + def icons(self): + prefs = ctx.prefs + return prefs.get_folder_previews(self.as_pointer()) + @property def abspath(self): return ctx.abspath(self.path) @@ -202,6 +207,8 @@ class BW_PG_bone_color(PropertyGroup): class BW_prefs(AddonPreferences): bl_idname = __package__ + previews = {} + default_folder: PointerProperty(type=BW_PG_folder) folders: CollectionProperty(type=BW_PG_folder) folder_index: IntProperty() @@ -225,6 +232,12 @@ class BW_prefs(AddonPreferences): #use_custom_colors: BoolProperty(name='Custom Colors', default=False, update=set_default_colors) + def get_folder_previews(self, adress): + if adress not in self.previews: + self.previews[adress] = bpy.utils.previews.new() + + return self.previews[adress] + def draw(self, context): draw_prefs(self.layout) diff --git a/ui.py b/ui.py index 95bd3ec..92a919b 100644 --- a/ui.py +++ b/ui.py @@ -249,6 +249,14 @@ class BW_PT_main(Panel): edit_row.operator('bonewidget.create_widget', text='Create') edit_row.operator('bonewidget.edit_widget', text='Edit') + # Draw Active Bone Shape + if context.active_pose_bone: + widget_col.separator() + col = widget_col.column(align=False) + col.use_property_split = True + col.prop(context.active_pose_bone, 'name', text='Bone Name') + col.prop(context.active_pose_bone, 'custom_shape', text='Widget') + if ctx.prefs.use_custom_collection and ctx.rig: widget_col.separator() row = widget_col.row() diff --git a/widgets/Custome/root.blend b/widgets/Custome/root.blend deleted file mode 100644 index 85ca7f3..0000000 Binary files a/widgets/Custome/root.blend and /dev/null differ diff --git a/widgets/Custome/root.png b/widgets/Custome/root.png deleted file mode 100644 index 1ca7cf8..0000000 Binary files a/widgets/Custome/root.png and /dev/null differ diff --git a/widgets/Default/arrow.blend b/widgets/Default/arrow.blend new file mode 100644 index 0000000..8d2c124 Binary files /dev/null and b/widgets/Default/arrow.blend differ diff --git a/widgets/Default/arrow.png b/widgets/Default/arrow.png new file mode 100644 index 0000000..7f217a4 Binary files /dev/null and b/widgets/Default/arrow.png differ diff --git a/widgets/Default/bone_l.blend b/widgets/Default/bone_l.blend deleted file mode 100644 index dfd800c..0000000 Binary files a/widgets/Default/bone_l.blend and /dev/null differ diff --git a/widgets/Default/bone_l.png b/widgets/Default/bone_l.png deleted file mode 100644 index e63d916..0000000 Binary files a/widgets/Default/bone_l.png and /dev/null differ diff --git a/widgets/Default/all.blend b/widgets/Default/eye_target.blend similarity index 100% rename from widgets/Default/all.blend rename to widgets/Default/eye_target.blend diff --git a/widgets/Default/all.png b/widgets/Default/eye_target.png similarity index 100% rename from widgets/Default/all.png rename to widgets/Default/eye_target.png diff --git a/widgets/Default/ik_l.blend b/widgets/Default/ik.blend similarity index 100% rename from widgets/Default/ik_l.blend rename to widgets/Default/ik.blend diff --git a/widgets/Default/ik_l.png b/widgets/Default/ik.png similarity index 100% rename from widgets/Default/ik_l.png rename to widgets/Default/ik.png diff --git a/widgets/Default/index_01_l.blend b/widgets/Default/index_01_l.blend new file mode 100644 index 0000000..77397bc Binary files /dev/null and b/widgets/Default/index_01_l.blend differ diff --git a/widgets/Default/index_01_l.png b/widgets/Default/index_01_l.png new file mode 100644 index 0000000..b828f2a Binary files /dev/null and b/widgets/Default/index_01_l.png differ diff --git a/widgets/Default/jaw_up.blend b/widgets/Default/jaw_up.blend deleted file mode 100644 index ab5cec5..0000000 Binary files a/widgets/Default/jaw_up.blend and /dev/null differ diff --git a/widgets/Default/jaw_up.png b/widgets/Default/jaw_up.png deleted file mode 100644 index cc02801..0000000 Binary files a/widgets/Default/jaw_up.png and /dev/null differ diff --git a/widgets/Default/plane.blend b/widgets/Default/plane.blend new file mode 100644 index 0000000..0929671 Binary files /dev/null and b/widgets/Default/plane.blend differ diff --git a/widgets/Default/plane.png b/widgets/Default/plane.png new file mode 100644 index 0000000..704491f Binary files /dev/null and b/widgets/Default/plane.png differ diff --git a/widgets/Default/root.blend b/widgets/Default/root.blend index e505bcc..c665c4b 100644 Binary files a/widgets/Default/root.blend and b/widgets/Default/root.blend differ diff --git a/widgets/Default/root.png b/widgets/Default/root.png index 7e193d9..5f9c94b 100644 Binary files a/widgets/Default/root.png and b/widgets/Default/root.png differ