def execute(self, context): (rig, mesh) = self.get_rig_mesh(context) # Switch to object mode first, to prevent sending rig to empty mode # happens when switching from Armature Edit to Weight Paint (warning but no error) # from there, trying to change the armature mode gives error after fixing the mode bpy.ops.object.mode_set(mode='OBJECT') if self.mode == 'POSE': Set.active(context, rig) return bpy.ops.object.mode_set(mode='POSE') elif self.mode == 'EDIT_ARMATURE': Set.active(context, rig) return bpy.ops.object.mode_set(mode='EDIT') elif self.mode == 'WEIGHT_PAINT': Set.active(context, mesh) return bpy.ops.object.mode_set(mode='WEIGHT_PAINT') elif self.mode == 'EDIT_MESH': Set.active(context, mesh) return bpy.ops.object.mode_set(mode='EDIT') elif self.mode == 'SCULPT': Set.active(context, mesh) return bpy.ops.object.mode_set(mode='SCULPT') return {'PASS_THROUGH'}
def add_bones_bone(self, context, rig): # Add bones then set their defaults root = self.get_root(rig) prev_bones = self.get_prev_bones(rig) bone = rig.data.edit_bones.new('Bone') bone.parent = root bone.translate( Vector( utils.multiply_list( Get.cursor(context).location, rig.matrix_world.inverted().to_scale( ), # Get the transforms for the unscaled rig )) - rig.matrix_world.to_translation()) # Use the original bone size (unscaled by the rig) bone.tail = bone.head + Vector( utils.multiply_list( Vector((0, 0, 0.1)), rig.matrix_world.inverted().to_scale(), )) - rig.matrix_world.to_translation() bone = str(bone.name) # Switch back to Pose mode and setup pose bones Set.mode(context, 'POSE', rig) bone = rig.data.bones[bone] rig.data.bones.active = bone Set.select(bone)
def execute(self, context): def close_rigify(meta): """Close Rigify Layers panel by default""" text = meta.data.rigify_rig_ui for (index, line) in enumerate(text.lines): if (line.body == "class RigLayers(bpy.types.Panel):"): text.cursor_set(index + 6) # bl_category = 'Item' text.write(" bl_options = {'DEFAULT_CLOSED'}\n") return True for daz in context.selected_objects: (meta, daz) = self.poll_parse(context, daz) if None in (meta, daz): continue layers_extra = get_layers_extra(meta) Set.active(context, meta) bpy.ops.pose.rigify_generate() close_rigify(meta) rig = context.active_object meta_to_rigify(daz, rig) adjust_rigify(rig) set_layers_extra(rig, layers_extra) return {'FINISHED'}
def add_bones_root(self, context, rig): # Add bones then set their defaults root = self.get_root(rig) prev_bones = self.get_prev_bones(rig) new_root = not bool(root) if root is None: root = rig.data.edit_bones.new('root') root.tail = Vector((0, 1, 0)) root.bbone_x = 0.5 root.bbone_z = 0.01 root.layers = self.layer(27) for eb in rig.data.edit_bones: if eb.parent is None: eb.use_connect = False eb.parent = root root = str(root.name) # Switch back to Pose mode and setup pose bones Set.mode(context, 'POSE', rig) root = rig.pose.bones[root] if new_root: self.widget(root, 'Blenrig - Root') rig.data.bones.active = root.bone rig.data.layers[27] = True
def returnToArmature(context, widget): bone = fromWidgetFindBone(widget) armature = bone.id_data # Unhide collection if it was hidden in a previous run if widget.users_collection: # Try to use the widget's collection collection = widget.users_collection[0] else: # otherwise use default collection = get_collection(context) Set.visible(context, collection) Set.mode(context, 'OBJECT', widget) # collection = get_collection(context) if [x for x in armature.users_collection if x != collection]: # Don't hide the active collection collection.hide_viewport = True "New version doesn't have this" # get_collection_view_layer(collection).hide_viewport = True if getattr(context.space_data, 'local_view', None): bpy.ops.view3d.localview() Set.active(context, armature) Set.select(armature, True) Set.mode(context, 'POSE', armature) # Set.select(bone, True) # Set.active(context, bone) armature.data.bones[bone.name].select = True armature.data.bones.active = armature.data.bones[bone.name]
def empty(context, name="Empty", type='PLAIN_AXES', size=1.0, link=True): "Create a new empty object" empty = New.object(context, name, None, link) Set.empty_type(empty, type) Set.empty_size(empty, size) return empty
def add_bones_ik(self, context, rig): # Add bones then set their defaults root = self.get_root(rig) prev_bones = self.get_prev_bones(rig) pose_bones = [] for bone_name in prev_bones: prev = rig.data.edit_bones[bone_name] bone = rig.data.edit_bones.new(self.mirror_name(prev.name, 'IK')) pose_bones.append([bone.name, prev.name]) self.reset(bone, prev) bone.parent = root bone.use_deform = False # Switch back to Pose mode and setup pose bones Set.mode(context, 'POSE', rig) for bone, prev in pose_bones: bone = rig.pose.bones[bone] prev = rig.pose.bones[prev] rig.data.bones.active = bone.bone bone.custom_shape_transform = prev self.widget(bone, 'Circle', slide=(0, 0.5, 1)) bone['IK_FK'] = prev.name prev['IK_FK'] = prev.name bone['IK_IK'] = bone.name prev['IK_IK'] = bone.name bone.rotation_mode = 'QUATERNION' bone.matrix = prev.matrix # for ct in ['COPY_LOCATION', 'COPY_ROTATION', 'COPY_SCALE']: # con = deform.constraints.new(ct) # con.name = 'DEF-'+con.name # con.target = rig # con.subtarget = stretch.name # con.target_space = 'LOCAL' # con.owner_space = 'LOCAL' # con.use_offset = True # con.show_expanded = False # con = deform.constraints.new('STRETCH_TO') # con.name = 'DEF-'+con.name # con.target = rig # con.subtarget = tail.name # con.rest_length = deform.bone.length # con.head_tail = 0 if prev.bone_group: bone.bone_group = self.bgroup(rig, 'IK-' + prev.bone_group.name) else: bone.bone_group = self.bgroup(rig, 'IK') prev.bone_group = self.bgroup(rig, 'FK')
def get_prev_bones(rig): prev_bones = [] for b in rig.data.bones: if b.select: prev_bones.append(b.name) Set.select(b, False) Set.select(rig.data.edit_bones[b.name], False) return prev_bones
def armature(context, name="Armature", display_type=None, link=True): "Create and return a rig object" data = bpy.data.armatures.new(name) # armature.show_in_front = True if display_type is not None: Set.armature_display_type(data, display_type) return New.object(context, name, data, link)
def execute(self, context): rig = context.active_object active = None if context.mode == 'PAINT_WEIGHT': for obj in context.selected_objects: if obj.type == 'ARMATURE': active = rig rig = obj Set.active(context, rig) # if rig.type =='ARMATURE' and context.mode != 'EDIT_ARMATURE': meshes = self.get_meshes(context, rig) bone1 = context.active_pose_bone # bone2 = context.selected_pose_bones[1] for bone2 in context.selected_pose_bones: if bone2 == bone1: continue found = None for mesh in meshes: utils.merge_vertex_groups( mesh, bone1.name, bone2.name, # If remove is False, and the bone stayed, it would be equivalent to transferring only partial weights remove=(self.mode == 'remove')) found = True # if found: # if self.mode == 'hide': # bone2.hide = True # elif self.mode == 'show': # bone2.hide = False # elif self.mode == 'remove': if (found and self.mode == 'remove'): for ch in bone2.id_data.children: if (ch.parent_type == 'BONE') and (ch.parent_bone == bone2.name): mat = Get.matrix(ch) ch.parent_bone = bone1.name Set.matrix(ch, mat) name2 = bone2.name Set.mode(context, mode='EDIT') bone2 = rig.data.edit_bones[name2] rig.data.edit_bones.remove(bone2) Set.mode(context, mode='POSE') if active: Set.active(context, active) return {'FINISHED'}
def execute(self, context): (rigs, __) = get_rig_bones(context) for (rig, bones) in rigs.items(): for bone in bones: self.pose_func(context, rig.pose.bones[bone.name]) for rig in rigs: Set.mode(context, 'EDIT', rig) # Reparent soon-to-be orphans for (pbone, rig) in self.bones.items(): bone = rig.data.edit_bones[pbone.name] for parent in bone.parent_recursive: if (parent not in self.bones): break else: parent = None for child in bone.children: if (child not in self.bones): child.parent = parent # Remove the bbone constrollers for (pbone, rig) in self.bones.items(): ebones = rig.data.edit_bones ebones.remove(ebones[pbone.name]) for rig in rigs: Set.mode(context, 'POSE', rig) # remove unused groups groups = (rig.pose.bone_groups[bg] for bg in ("BBone FK", "BBone Stretch", "BBone Curve", "BBone Stretch [Hidden]") if rig.pose.bone_groups.get(bg)) for bg in list(groups): for bone in rig.pose.bones: if bone.bone_group == bg: break else: rig.pose.bone_groups.remove(bg) # Remove unused widgets for wgt in self.widgets: if (wgt.users < 2): # 1) mesh 2+) objects wgt_col = list(wgt.users_collection) bpy.data.objects.remove(wgt) for col in wgt_col: if not col.all_objects: bpy.data.collections.remove(col) return {'FINISHED'}
def invoke(self, context, event): if event.alt: active = context.object for ob in context.selected_objects: if Is.mesh(ob) and (ob.data.shape_keys): Set.active(context, ob) self.purge(ob) Set.active(context, active) else: self.purge(context.object) return {'FINISHED'}
def rigify_to_meta(rigify, metarig): """Retarget Rigify meshes to Metarig""" pose = (metarig.data.pose_position, rigify.data.pose_position) (metarig.data.pose_position, rigify.data.pose_position) = ('REST', 'REST') utils.update(bpy.context) for obj in bpy.data.objects: if Is.curve(obj) and obj.name.startswith(rigify.name + '-MCH-'): # Splines from angavrilov's spline rig continue for mod in obj.modifiers: if hasattr(mod, 'object') and mod.object == rigify: mod.object = metarig metafy_vgroups(rigify, obj, metarig) if (obj.parent == rigify): rigify_bone = obj.parent_bone if rigify_bone: if rigify_bone.startswith('DEF-'): meta_bone = rigify_bone[4:] else: meta_bone = rigify_bone if meta_bone in metarig.data.bones: mat = Get.matrix(obj) # pmat = obj.matrix_parent_inverse.copy() obj.parent = metarig obj.parent_bone = meta_bone # obj.matrix_parent_inverse = pmat Set.matrix(obj, mat) else: obj.parent = metarig if Is.mesh(obj): meshes = {obj.data} if hasattr(obj, 'variants'): # The LoDs store the mesh datas and drivers without an object for layer in obj.variants.layers: if layer.mesh: meshes.add(layer.mesh) for lod in layer.lods: meshes.add(lod.mesh) for mesh in meshes: if mesh: rigify_drivers(rigify, metarig, mesh.shape_keys) for mat in bpy.data.materials: rigify_drivers(rigify, metarig, mat) rigify_drivers(rigify, metarig, mat.node_tree) (metarig.data.pose_position, rigify.data.pose_position) = pose
def execute(self, context): active = obj = context.object transfer = bpy.ops.object.data_transfer if (not Is.mesh(obj)) or getattr(obj, 'DazMannequin', False): # redesignate obj obj = None for o in context.selected_objects: if Is.mesh(o) and (not getattr(o, 'DazMannequin', False)): obj = o Set.active(context, o) break if not all(( obj, obj.data.polygons, transfer.poll(context.copy()), )): self.report({'INFO'}, "Only Mannequins Selected") return {'CANCELLED'} mesh = obj.data if mesh.polygons[0].use_smooth: # only check one face, rather than all bpy.ops.object.shade_smooth() if mesh.use_auto_smooth: transfer(data_type='CUSTOM_NORMAL') for o in context.selected_objects: if Is.mesh(o): o.data.use_auto_smooth = True if obj.vertex_groups: # Vertex groups add to file size, so don't keep them for everything transfer(data_type='VGROUP_WEIGHTS', layers_select_src='ALL', layers_select_dst='NAME') if mesh.vertex_colors: transfer(data_type='VCOL', layers_select_src='ALL', layers_select_dst='NAME') if mesh.uv_layers: transfer(data_type='UV', layers_select_src='ALL', layers_select_dst='NAME') Set.active(context, active) return {'FINISHED'}
def add_bones_mch(self, context, rig, mch_parent=False): # Add bones then set their defaults root = self.get_root(rig) prev_bones = self.get_prev_bones(rig) pose_bones = [] # Get MCH Prefix parent_name = context.scene.mch_bone if parent_name == "": parent_name = "MCH-parent_" for bone_name in prev_bones: prev = rig.data.edit_bones[bone_name] # Replace bone prefixes with MCH instead of inserting keeping both name = parent_name + (prev.name.replace("DEF-", "", 1)).replace( "CTRL-", "", 1) bone = rig.data.edit_bones.new(name) pose_bones.append([bone.name, prev.name]) self.reset(bone, prev) bone.use_deform = False bone.use_connect = prev.use_connect bone.parent = prev.parent prev.use_connect = False prev.parent = bone # prev.select = False # prev.hide = True if not mch_parent: for c in prev.children: c.parent = bone Set.select(bone, False) # Switch back to Pose mode and setup pose bones Set.mode(context, 'POSE', rig) for bone, prev in pose_bones: bone = rig.pose.bones[bone] prev = rig.pose.bones[prev] rig.data.bones.active = bone.bone # self.widget(bone, 'Box') ... # Retarget drivers if not mch_parent: for tar in self.mch_driver_targets: if (tar.id is rig) and (tar.bone_target == prev.name): tar.bone_target = bone.name
def execute(self, context): mannequin.head = f" ({self.head.title()})" objects = list() for obj in context.selected_objects: if Is.mesh(obj) and Is.armature(obj.parent): inst = self.convert(context, obj) objects.append(inst) for obj in reversed(objects): Set.active_select(context, obj, isolate=False) return {'FINISHED'}
def execute(self, context): obj = context.object in_edit = (obj.mode == 'EDIT') if in_edit: Set.mode(context, 'OBJECT') active = obj.active_shape_key vg = active.vertex_group index = obj.active_shape_key_index pin = obj.show_only_shape_key obj.show_only_shape_key = True active.vertex_group = '' bpy.ops.object.shape_key_add(from_mix=True) while obj.active_shape_key_index > (index + 1): bpy.ops.object.shape_key_move(type='UP') active.vertex_group = vg shape = obj.active_shape_key if self.mirror: shape.name = utils.flip_name(active.name) shape.vertex_group = utils.flip_name(vg) else: shape.vertex_group = vg shape.name = active.name for var in ('interpolation', 'mute', 'relative_key', 'slider_max', 'slider_min', 'value'): setattr(shape, var, getattr(active, var)) driver = Get.driver(active, var) if not driver: continue newdriver = utils.copy_driver(driver, shape, var) if self.mirror: for v in newdriver.driver.variables: for t in v.targets: t.bone_target = utils.flip_name(t.bone_target) # obj.active_shape_key_index = index obj.show_only_shape_key = pin if in_edit: Set.mode(context, 'EDIT') return {'FINISHED'}
def add_bones_vis(self, context, rig): # Add bones then set their defaults root = self.get_root(rig) prev_bones = self.get_prev_bones(rig) pose_bones = [] for bone_name in prev_bones: prev = rig.data.edit_bones[bone_name] bone = rig.data.edit_bones.new(self.mirror_name(prev.name, 'VIS')) pose_bones.append([bone.name, prev.name]) self.reset(bone, prev) bone.use_deform = False bone.parent = prev # Switch back to Pose mode and setup pose bones Set.mode(context, 'POSE', rig) for bone, prev in pose_bones: bone = rig.pose.bones[bone] prev = rig.pose.bones[prev] # rig.data.bones.active = bone.bone bone.custom_shape = prev.custom_shape bone.custom_shape_transform = prev.custom_shape_transform bone.bone.show_wire = True prev.custom_shape = None bone.bone.hide_select = True bone.matrix = prev.matrix driver = bone.bone.driver_add('hide') var = driver.driver.variables.new() var.name = 'var' driver.driver.expression = 'not var' var.type = 'SINGLE_PROP' vt = var.targets[0] vt.id = rig # vt.bone_target = target.name # vt.transform_space = 'LOCAL_SPACE' # vt.transform_type = transform # # if transform == 'SINGLE_PROP': vt.data_path = prev.bone.path_from_id('select')
def execute(self, context): (rigs, self.selected) = get_rig_bones(context) for rig in rigs: Set.mode(context, 'EDIT', rig) self.hide_bones[rig] = list() self.center_bones[rig] = list() for (rig, bones) in rigs.items(): for bone in bones: self.edit_func(context, rig.data.edit_bones[bone.name]) for (ebones, ebone, tbone) in self.delayed_parenting: ebones[ebone].parent = ebones[tbone] (do_mch, do_start_end, do_in_out) = self.do() if do_start_end: self.edit_mirror_center(context) if self.warning: self.report({'WARNING'}, self.warning) for rig in rigs: Set.mode(context, 'POSE', rig) for (rig, bones) in rigs.items(): for bone in bones: self.pose_func(context, rig.pose.bones[bone.name]) def widget(ctrl_type, wgt='Sphere', global_size=6, scale=(1, 1, 1), slide=None): from mathutils import Vector bpy.ops.bonewidget.create_widget( global_size=global_size, slide=Vector(slide) if slide else Vector(), scale=scale, bones='%r' % self.bone_widgets[ctrl_type], widget=wgt, ) widget('mch', wgt='Box', global_size=1, scale=(0.75, 0.75, 1)) # widget('start', slide=(0, -0.5, 0)) widget('start', wgt='Blenrig - Box', global_size=3) # widget('end', slide=(0, 0.5, 0)) widget('end', wgt='Blenrig - Box', global_size=3) widget('in_out', global_size=7.5, slide=(0, 0.5, 0)) return {'FINISHED'}
def meta_to_rigify(metarig, rigify): """Retarget Metarig meshes to Rigify rig""" pose = (metarig.data.pose_position, rigify.data.pose_position) (metarig.data.pose_position, rigify.data.pose_position) = ('REST', 'REST') utils.update(bpy.context) for obj in bpy.data.objects: for mod in obj.modifiers: if hasattr(mod, 'object') and mod.object == metarig: mod.object = rigify rigify_vgroups(metarig, rigify, obj) if obj.parent == metarig: if obj.parent_bone: rigify_bone = vg_names.get(obj.parent_bone, False) if rigify_bone is False: rigify_bone = 'DEF-' + obj.parent_bone if rigify_bone and rigify_bone in rigify.data.bones: mat = Get.matrix(obj) # pmat = obj.matrix_parent_inverse.copy() obj.parent = rigify obj.parent_bone = rigify_bone # obj.matrix_parent_inverse = pmat Set.matrix(obj, mat) else: obj.parent = rigify if Is.mesh(obj): meshes = {obj.data} if hasattr(obj, 'variants'): # The LoDs store the mesh datas and drivers without an object for layer in obj.variants.layers: if layer.mesh: meshes.add(layer.mesh) for lod in layer.lods: meshes.add(lod.mesh) for mesh in meshes: if mesh: rigify_drivers(metarig, rigify, mesh.shape_keys) for mat in bpy.data.materials: rigify_drivers(metarig, rigify, mat) rigify_drivers(metarig, rigify, mat.node_tree) (metarig.data.pose_position, rigify.data.pose_position) = pose
def add_bones_dupli(self, context, rig): # Add bones then set their defaults root = self.get_root(rig) prev_bones = self.get_prev_bones(rig) pose_bones = [] flip_bones = [] def add_bone(bone_name): prev = rig.data.edit_bones[bone_name] bone = rig.data.edit_bones.new(prev.name) pose_bones.append([bone.name, prev.name]) self.reset(bone, prev) bone.parent = prev.parent bone.use_deform = prev.use_deform for bone_name in prev_bones: add_bone(bone_name) if rig.pose.use_mirror_x: flip = utils.flip_name(bone_name) if (flip in rig.data.edit_bones) and (flip not in ( *prev_bones, *(p for (b, p) in pose_bones))): # Mirrored bone exists but not selected add_bone(flip) flip_bones.append(flip) # Switch back to Pose mode and setup pose bones Set.mode(context, 'POSE', rig) for (bone, prev) in pose_bones: bone = rig.pose.bones[bone] prev = rig.pose.bones[prev] if (prev.name not in flip_bones): rig.data.bones.active = bone.bone bone.custom_shape = prev.custom_shape bone.custom_shape_transform = prev.custom_shape_transform bone.bone.show_wire = prev.bone.show_wire bone.matrix = prev.matrix bone.bone_group = prev.bone_group for lock in [ 'location', 'rotations_4d', 'rotation_w', 'rotation', 'scale' ]: setattr(bone, 'lock_' + lock, getattr(prev, 'lock_' + lock))
def execute(self, context): area = context.area view = area.spaces.active reg = view.region_3d # Create new camera object, add to scene, and select it camo = New.camera(context, name="Viewport", size=0.5) cam = camo.data Set.active(context, camo) # Set.active_select(camo) # Set Lock viewport to the camera view.camera = camo view.use_local_camera = True view.lock_camera = True # Send camera object to the current viewport rotation/location Set.matrix(camo, reg.view_matrix.inverted()) # Switch to camera view if reg.view_perspective != 'CAMERA': bpy.ops.view3d.view_camera() # run op to prevent changing the (actual) viewport's position # reg.view_perspective = 'CAMERA' # Mirror viewport properties to the camera cam.lens = view.lens / 2 cam.clip_start = view.clip_start cam.clip_end = view.clip_end # Re-center the camera view window if it was changed bpy.ops.view3d.view_center_camera() # reg.view_camera_offset = [0.0, 0.0] # reg.view_camera_zoom = 28 # Setup Deph of Field cam.dof.use_dof = True # cam.dof.aperture_fstop = 0.5 # Blur amount # cam.dof.aperture_fstop = 2.8 # cam.dof.focus_distance = reg.view_distance bpy.ops.ui.eyedropper_depth('INVOKE_DEFAULT') return {'FINISHED'}
def execute(self, context): obj = context.object in_edit = (obj.mode == 'EDIT') if in_edit: Set.mode(context, 'OBJECT') active = obj.active_shape_key index = obj.active_shape_key_index pin = obj.show_only_shape_key obj.show_only_shape_key = True bpy.ops.object.shape_key_add(from_mix=True) while obj.active_shape_key_index > (index + 1): bpy.ops.object.shape_key_move(type='UP') shape = obj.active_shape_key for var in ('interpolation', 'mute', 'relative_key', 'slider_max', 'slider_min', 'value'): setattr(shape, var, getattr(active, var)) # if self.keep_vertex_group: # shape.vertex_group = active.vertex_group # Redirect drivers, so that they auto update after operation for var in ('slider_max', 'slider_min', 'value'): driver = Get.driver(active, var) if driver: driver.data_path = f'key_blocks["{shape.name}"].{var}' # driver.data_path = driver.data_path.replace(active.name, shape.name, 1) name = active.name active.name += ".masked" shape.name = name obj.active_shape_key_index = index bpy.ops.object.shape_key_remove(all=False) obj.active_shape_key_index = index obj.show_only_shape_key = pin if in_edit: Set.mode(context, 'EDIT') return {'FINISHED'}
def add_placeholder_bones(rigify, obj, metarig): context = bpy.context rigify_mode = rigify.mode meta_mode = metarig.mode Set.mode(context, 'EDIT', metarig) Set.mode(context, 'EDIT', rigify) for rigify_bone in rigify.data.edit_bones.keys(): if not rigify_bone.startswith('DEF-'): # Not a DEF group, so... continue meta_bone = rigify_bone[4:] if obj.vertex_groups.get(meta_bone): # Both DEF and regular name in vertex groups continue if (meta_bone in metarig.data.edit_bones): continue rbone = rigify.data.edit_bones[rigify_bone] mbone = metarig.data.edit_bones.new(meta_bone) for attr in ( # 'bbone_curveinx', 'bbone_curveiny', # 'bbone_curveoutx', 'bbone_curveouty', # 'bbone_custom_handle_end', 'bbone_custom_handle_start', # 'bbone_easein', 'bbone_easeout', # 'bbone_handle_type_end', 'bbone_handle_type_start', # 'bbone_rollin', 'bbone_rollout', # 'bbone_scaleinx', 'bbone_scaleiny', # 'bbone_scaleoutx', 'bbone_scaleouty', # 'bbone_segments', 'bbone_x', 'bbone_z', 'envelope_distance', 'envelope_weight', 'head', 'head_radius', 'tail', 'tail_radius', 'roll', 'inherit_scale', 'use_inherit_rotation', 'use_inherit_scale', 'use_endroll_as_inroll', 'use_envelope_multiply', 'use_local_location', 'use_relative_parent', ): setattr(mbone, attr, getattr(rbone, attr)) if rbone.parent: mbone.parent = metarig.data.edit_bones.get(rbone.parent.name[4:]) if mbone.parent: mbone.layers = mbone.parent.layers Set.mode(context, meta_mode, metarig) Set.mode(context, rigify_mode, rigify)
def add_bones_stretch_tail(self, context, rig): # Add bones then set their defaults root = self.get_root(rig) prev_bones = self.get_prev_bones(rig) pose_bones = [] for bone_name in prev_bones: prev = rig.data.edit_bones[bone_name] bone = rig.data.edit_bones.new(self.mirror_name(prev.name, 'STRT')) pose_bones.append([bone.name, prev.name]) self.reset(bone, prev) bone.parent = prev.parent bone.use_deform = False # Switch back to Pose mode and setup pose bones Set.mode(context, 'POSE', rig) for bone, prev in pose_bones: bone = rig.pose.bones[bone]
def fix_toe_roll(): """ The Toe controller bone may have a bad automated roll, so recalculate it """ mode = Get.mode(rig) Set.mode(bpy.context, 'EDIT', rig) bones = rig.data.edit_bones ebones = bpy.context.selected_bones for ebone in ebones: ebone.select = False bone = tweak = None def get(name): nonlocal bone, tweak bone = bones.get(name) tweak = bones.get(name.replace('_master', '')) return (bone and tweak) def roll(name): if get(name): bone.select = True bones.active = tweak bpy.ops.armature.calculate_roll(type='ACTIVE') bone.select = False for lr in ('L', 'R'): for ind in range(1, 6): roll(f'toe{ind}.01_master.{lr}') roll(f'thumb.01_master.{lr}') roll(f'f_index.01_master.{lr}') roll(f'f_middle.01_master.{lr}') roll(f'f_ring.01_master.{lr}') roll(f'f_pinky.01_master.{lr}') for ebone in ebones: ebone.select = True Set.mode(bpy.context, mode, rig)
def execute(self, context): active = Get.active(context) active_select = Is.selected(active) selected = Get.selected(context) is_pose = bool(context.mode == 'POSE') arg = dict(only_selected=bool(selected)) if is_pose: clear = bpy.ops.pose.paths_clear # Operator only runs on active rig, so repeat for all in pose mode if selected: obs = {b.id_data for b in selected} else: obs = {ob for ob in Get.objects(context) if ob.mode == 'POSE'} for ob in obs: Set.active(context, ob) clear(**arg) else: Set.active(context, active) Set.select(active, active_select) elif bpy.ops.object.paths_clear.poll(context.copy()): bpy.ops.object.paths_clear(**arg) return {'FINISHED'}
def metafy_rigify(context, rig): """Isolate Org bones in rig, then mimic the likely original bone layers""" Set.mode(context, 'EDIT', rig) bones = rig.data.edit_bones for bone in bones.values(): bone.inherit_scale = 'ALIGNED' if bone.name.startswith('ORG-'): bone.layers = utils.layer(0) else: bones.remove(bone) Set.mode(context, 'POSE', rig) for bone in rig.pose.bones: bone.lock_rotation_w = False for index in range(3): bone.lock_location[index] = False bone.lock_rotation[index] = False bone.lock_scale[index] = False rig.data.layers = utils.layer(0)
def pose_mch(pbone): Set.select(bone, False) Set.select(pbone, True) rig.data.bones.active = pbone.bone mats = (pbone.matrix.copy(), bone.matrix.copy()) (bone.matrix, pbone.matrix) = mats pbone.rotation_mode = bone.rotation_mode pbone.lock_location = bone.lock_location pbone.lock_rotation = bone.lock_rotation pbone.lock_rotation_w = bone.lock_rotation_w pbone.lock_rotations_4d = bone.lock_rotations_4d pbone.lock_scale = (True, False, True) pbone.custom_shape_transform = bone if not pbone.custom_shape: self.bone_widgets['mch'].append(pbone) con = bone.constraints.new('COPY_ROTATION') con.target = rig con.subtarget = pbone.name con = bone.constraints.new('COPY_SCALE') con.target = rig con.subtarget = pbone.name con.use_x = con.use_z = False
def execute(self, context): active = Get.active(context) mode = context.mode pose = list() for rig in context.selected_objects: (rig, meta) = self.poll_parse(context, rig) if None in (rig, meta): continue rigify_to_meta(rig, meta) pose.append((meta, rig)) else: if mode == 'POSE': Set.mode(context, 'OBJECT') for (meta, rig) in pose: Set.select(rig, False) Set.select(meta, True) if rig == active: Set.active(context, meta) if mode == 'POSE': Set.mode(context, 'POSE') return {'FINISHED'}