示例#1
0
 def edit_start(ebone):
     edit(ebone, 2.5)
     if do_mch:
         ebone.parent = bone_mch
     else:
         if Is.connected(bone):
             ebone.parent = ebones.get(
                 get_name(bone.parent, 'bbone_end'))
         if ebone.parent:
             self.hide_bones[rig].append(ebone.name)
             ebone.hide = True
         else:
             ebone.parent = bone.parent
         if not do_in_out:
             cbone = ebones.get(get_name(bone, 'bbone_in'))
             if cbone:
                 cbone.parent = ebone
     for cbone in bone.children_recursive:
         if (bone.head != cbone.tail):
             continue
         cbone_end = ebones.get(get_name(cbone, 'bbone_end'))
         if cbone_end:
             cbone_end.parent = ebone
             self.hide_bones[rig].append(cbone_end.name)
             cbone_end.hide = True
     ebone.tail = utils.lerp(ebone.head, ebone.tail, 0.1)
示例#2
0
def location(context, src, **kargs):
    """
    kargs:
        frame=None, group=None, action=None, insert_key=None,
        unlock=False,  # keyframe locked channels
        connected=False,  # ignore whether or not a bone is connected
    """

    insert_key = kargs.get('insert_key')
    unlock = kargs.get('unlock', False)
    kargs['results'] = kargs.get('results', list())

    if not keyframe.poll_insert(context, insert_key, src=src):
        return

    if kargs.get('connected') and Is.connected(src):
        return

    args = (context, src, 'location')

    if unlock or (True not in src.lock_location):
        keyframe.manual(*args, index=-1, **kargs)
    else:
        for i in range(3):
            if (not src.lock_location[i]):
                keyframe.manual(*args, index=i, **kargs)

    return kargs['results']
示例#3
0
 def pose_start(pbone):
     pose(pbone)
     pbone.lock_scale = (True, True, True)
     if not pbone.custom_shape:
         self.bone_widgets['start'].append(pbone)
     if not Is.connected(bone):
         con = bone.constraints.new('COPY_LOCATION')
         con.target = rig
         con.subtarget = pbone.name
示例#4
0
 def get_disconnected_parent(bone, first_loop=True):
     if ((bone is None) or (not bone.parent)):
         if first_loop:
             return
         else:
             return bone
     elif Is.connected(bone):
         # Keep going up the chain until it finds a disconnected bone
         return get_disconnected_parent(bone.parent, False)
     else:
         return bone.parent
示例#5
0
    def execute(self, context):
        poll_any = False
        for bone in context.selected_pose_bones:
            poll_loc = (keyframe.poll_unlock(bone, 'location')
                        and not Is.connected(bone))
            poll_rot = keyframe.poll_unlock(bone, 'rotation')
            poll_scale = keyframe.poll_unlock(bone, 'scale')

            polls = {
                'location': poll_loc,
                'rotation': poll_rot,
                'scale': poll_scale
            }
            if not poll_any and not polls.pop(self.mode):
                for poll in polls:
                    if polls[poll]:
                        self.mode = poll
                        break
                else:
                    continue
            polls = {
                'location': poll_loc,
                'rotation': poll_rot,
                'scale': poll_scale
            }
            if polls[self.mode]:
                self.bones.append(bone)
            poll_any = True

        if not poll_any:
            self.report({'INFO'}, "All transforms locked on selected bones")
            return {'CANCELLED'}

        if (self.mode == 'location'):
            bpy.ops.transform.translate('INVOKE_DEFAULT', True)
        elif (self.mode == 'rotation'):
            bpy.ops.transform.rotate('INVOKE_DEFAULT', True)
        elif (self.mode == 'scale'):
            bpy.ops.transform.resize('INVOKE_DEFAULT', True)
        else:
            """can't use the "all" value"""
            return {'CANCELLED'}
        context.window_manager.modal_handler_add(self)

        return {'RUNNING_MODAL'}
示例#6
0
 def edit_end(ebone):
     edit(ebone, 2.5)
     if do_mch:
         ebone.parent = bone_mch
     else:
         for tbone in bone.parent_recursive:
             if (tbone.head != bone.tail):
                 continue
             tobone_name = get_name(tbone, 'bbone_start')
             tobone = ebones.get(tobone_name)
             if tobone or ((tbone, rig) in self.selected):
                 self.hide_bones[rig].append(ebone.name)
                 ebone.hide = True
                 if tobone:
                     ebone.parent = tobone
                 else:
                     self.delayed_parenting.append(
                         ebones, ebone.name, tobone_name)
             else:
                 ebone.parent = tbone
             break
         else:
             ebone.parent = get_disconnected_parent(bone)
         if not do_in_out:
             cbone = ebones.get(get_name(bone, 'bbone_out'))
             if cbone:
                 cbone.parent = ebone
     for cbone in bone.children:
         if Is.connected(cbone):
             cbone_start = ebones.get(get_name(cbone, 'bbone_start'))
             if cbone_start:
                 cbone_start.parent = ebone
                 self.hide_bones[rig].append(cbone_start.name)
                 cbone_start.hide = True
     ebone.head = utils.lerp(ebone.head, ebone.tail, 0.9)
     ebone.translate(ebone.tail - ebone.head)
     bone.bbone_custom_handle_end = ebone
示例#7
0
    def execute(self, context):
        current_frame = context.scene.frame_current

        poll_any = False
        for bone in context.selected_pose_bones:
            poll_loc = (keyframe.poll_unlock(bone, 'location')
                        and not Is.connected(bone))
            poll_rot = keyframe.poll_unlock(bone, 'rotation')
            poll_scale = keyframe.poll_unlock(bone, 'scale')

            polls = {
                'location': poll_loc,
                'rotation': poll_rot,
                'scale': poll_scale
            }
            if not poll_any and not polls.pop(self.mode):
                for poll in polls:
                    if polls[poll]:
                        self.mode = poll
                        break
                else:
                    continue
            polls = {
                'location': poll_loc,
                'rotation': poll_rot,
                'scale': poll_scale
            }
            if polls[self.mode]:
                self.bones[bone] = type('', (), {})
            poll_any = True

        if not poll_any:
            self.report({'INFO'}, "All transforms locked on selected bones")
            return {'CANCELLED'}

        for bone in self.bones:
            self.bones[bone].curves = get_bone_curve(bone, self.mode)

            if (self.mode == 'location'):
                self.bones[
                    bone].current_values = bone.matrix_basis.to_translation()
            elif (self.mode == 'rotation'):
                self.bones[bone].current_values = get_bone_rotation(bone)
                if self.bones[bone].current_values is None:
                    del self.bones[bone]
            elif (self.mode == 'scale'):
                self.bones[bone].current_values = bone.matrix_basis.to_scale()

        if (self.mode == 'location'):
            bpy.ops.transform.translate('INVOKE_DEFAULT')
        elif (self.mode == 'rotation'):
            if not self.bones:
                self.report({'INFO'},
                            "Cancelled Rotation (can't use Axis Angle)")
                return {'CANCELLED'}

            bpy.ops.transform.rotate('INVOKE_DEFAULT')
        elif (self.mode == 'scale'):
            bpy.ops.transform.resize('INVOKE_DEFAULT')
        else:
            """can't use the "all" value"""
            return {'CANCELLED'}

        context.window_manager.modal_handler_add(self)
        return {'RUNNING_MODAL'}
示例#8
0
    def edit_mirror_center(self, context):
        def get_bones(rig, bbone):
            ebones = rig.data.edit_bones
            ebone = ebones.get(get_name(bone, bbone))
            mebone = Get.mirror_bone(ebone)
            return (ebone, mebone)

        found = []
        for (bone, rig) in self.selected:
            if not (rig.pose.use_mirror_x or rig.data.use_mirror_x):
                continue
            mbone = Get.mirror_bone(bone)
            if mbone in found:
                continue
            else:
                found.append(bone)

            (ebone, mebone) = get_bones(rig, 'bbone_start')
            if not (ebone and mebone):
                continue

            if (ebone.parent == mebone.parent):
                # Connect heads
                if Is.connected(bone):
                    # The parent will already handle the symmetry
                    continue
                parent = ebone.parent
            else:
                (ebone, mebone) = get_bones(rig, 'bbone_end')
                if not (ebone and mebone):
                    continue

                # Find a mutual parent between the two bones
                parent = [
                    *(x for x in ebone.parent_recursive
                      if x in mebone.parent_recursive), None
                ][0]

            distance = abs(sum(ebone.head) - sum(mebone.head)) / 2
            margin = utils.lerp(bone.bone.length, mbone.bone.length,
                                0.5) / bone.bone.bbone_segments
            if distance >= margin:
                # Bones too far apart
                continue

            (prefix, replace, suffix,
             number) = utils.flip_name(bone.name, only_split=True)
            center_name = prefix + suffix + number
            center = New.bone(context, rig, name=center_name, overwrite=True)

            attributes = [
                'head',
                'head_radius',
                'tail',
                'tail_radius',
                'roll',
                'matrix',
                'layers',
                'bbone_x',
                'bbone_z',
            ]
            for atr in attributes:
                if hasattr(center, atr):
                    setattr(
                        center, atr,
                        utils.lerp(getattr(ebone, atr), getattr(mebone, atr),
                                   0.5))
            center.use_deform = False
            center.inherit_scale = 'NONE'
            center.parent = parent
            center.hide = True

            ebone.parent = mebone.parent = center
            self.hide_bones[rig].extend((ebone.name, mebone.name))
            self.center_bones[rig].append(center.name)
示例#9
0
    def execute(self, context):
        # active = Get.active(context)

        for rig in context.selected_editable_objects:
            if not Is.armature(rig):
                continue

            mode = rig.mode

            if not Set.mode(context, 'EDIT', rig):
                Set.mode(context, mode, rig)
                continue
            mirror = rig.data.use_mirror_x
            rig.data.use_mirror_x = False

            # Set.active(context, rig)
            bones = Get.selected_edit_bones(context, rig)

            links = []  # empty list
            for bone in bones:
                if bone.parent and not Is.connected(
                        bone):  # prevent root-error
                    link = rig.data.edit_bones.new(
                        'COR-%s<>%s' % (bone.parent.name, bone.name))
                    link.tail = bone.head
                    link.head = bone.parent.tail

                    link.layers = bone.layers
                    # link.layers = utils.layer(30)

                    # # layer 28 = IK
                    # # Layer 32 = Gap<>fillers
                    # if (rig.data.rigify_layers):
                    # link.layers	=	[True if index in (31,) else False for index, layer in enumerate(range(32))]

                    link.use_deform = False
                    link.parent = bone.parent
                    bone.parent = link
                    connect(link)
                    connect(bone)
                    link.use_connect = True
                    bone.use_connect = True

                    # bpy.ops.object.mode_set(mode='POSE');bpy.ops.object.mode_set(mode='EDIT');
                    links.append(link.name)
                    # bone = rig.pose.bones[link.name]
                    # bone.lock_ik_x = True
                    # bone.lock_ik_y = True
                    # bone.lock_ik_z = True
                    '''def gap(bone):
                        #bpy.ops.object.mode_set(mode='POSE');
                        bone = C.active_object.pose.bones[bone]
                        bone.lock_ik_x=True;	bone.lock_ik_y=True;	bone.lock_ik_z=True;
                        #bpy.ops.object.mode_set(mode='EDIT');
                    try:
                        bone.lock_ik_x=True;	bone.lock_ik_y=True;	bone.lock_ik_z=True;
                        link = link.name
                    except: continue
                    '''
                elif Is.connected(bone):
                    bone.use_connect = True
                else:  # root-ctrl-bone
                    continue
                    "or this will create a parent for a 'root' bone"
                    link = rig.data.edit_bones.new('COR-%s<>%s' %
                                                   (bone.name, bone.name))
                    link.tail = bone.tail
                    link.head = bone.head

                    link.layers = utils.layer(30)

                    # link.layers = bone.layers
                    link.use_deform = False
                    link.show_wire = True
                    bone.parent = link

                    links.append(link.name)

            rig.data.use_mirror_x = mirror
            Set.mode(context, 'POSE', rig)

            for link in links:
                link = rig.pose.bones.get(link, None)
                if link is None:
                    # if bone's head+tail are the same, it'll cancel itself out
                    continue
                links = link.name.replace('COR-', '', 1).split('<>')
                # linked = rig.pose.bones.get(links[1], None)

                if self.lock_ik:
                    link.ik_stiffness_x = 1
                    link.ik_stiffness_y = 1
                    link.ik_stiffness_z = 1
                    if (links[0] != links[1]):  # Parent <x> Child
                        link.lock_ik_x = True
                        link.lock_ik_y = True
                        link.lock_ik_z = True
                        link.lock_location = [True, True, True]
                        link.lock_rotation_w = True
                        link.lock_rotation = [True, True, True]
                        link.lock_scale = [True, True, True]
                    else:  # Original bone was copied for a control bone
                        print("Original bone was copied for a control bone")
                        # try:
                        # linked.lock_ik_x=True;	linked.lock_ik_y=True;	linked.lock_ik_z=True;
                        # linked.ik_stiffness_x=1;	linked.ik_stiffness_y=1;	linked.ik_stiffness_z=1;
                        # if not 'WGT-hips' in bpy.data.objects:
                        # bpy.context.scene.quickrig.create_wgt = 'hips'
                        # bpy.ops.quickrig.create_widgets()
                        # widget = bpy.data.objects['WGT-hips']
                        # link.custom_shape = widget
                        # #have the bone follow the original	#link.custom_shape_transform = rig.pose.bones[links[1]]
                        # link.use_custom_shape_bone_size = False
                        # con = widget.constraints.new('COPY_TRANSFORMS')
                        # con.target = rig;	con.subtarget = link.name;
                        # widget.layers[9] = True;	layers = 0
                        # for layer in widget.layers:
                        # if layers != 9:	layer = False
                        # except:	pass
                        ...

                def bgroup(name):
                    bgroups = rig.pose.bone_groups
                    if name in bgroups:
                        group = bgroups[name]
                    else:
                        group = bgroups.new(name=name)
                        group.color_set = 'CUSTOM'
                        black = ((0.0, 0.0, 0.0))
                        select = ((0.1, 0.7, 0.9))
                        c = group.colors
                        c.active, c.normal, c.select = black, black, select
                    return group

                link.bone_group = bgroup('<>')

            Set.mode(context, mode, rig)
        # if active:
        # Set.active(context, active)
        return {'FINISHED'}