예제 #1
0
    def _create_master_grip_bone(self, armature_object):
        _LOG.enter()

        bpy.ops.object.mode_set(mode='EDIT', toggle=False)

        finger3_tip_name = self.get_last_segment_name_of_finger(3)
        finger4_tip_name = self.get_last_segment_name_of_finger(4)

        finger3_root_name = self.get_first_segment_name_of_finger(3)
        finger4_root_name = self.get_first_segment_name_of_finger(4)

        roll = self._bone_info["edit_bones"][finger3_root_name]["roll"]

        finger3_head = self._bone_info["edit_bones"][finger3_root_name]["head"]
        finger3_tail = self._bone_info["edit_bones"][finger3_tip_name]["tail"]

        finger4_head = self._bone_info["edit_bones"][finger4_root_name]["head"]
        finger4_tail = self._bone_info["edit_bones"][finger4_tip_name]["tail"]

        head = (finger3_head + finger4_head) / 2
        tail = (finger3_tail + finger4_tail) / 2

        bone_name = self._get_master_grip_bone_name()
        bones = armature_object.data.edit_bones
        bone = bones.new(bone_name)
        bone.head = head
        bone.tail = tail
        bone.roll = roll

        parent_name = self.get_immediate_parent_name_of_finger(3)
        parent_bone = RigService.find_edit_bone_by_name(parent_name, armature_object)

        bone.parent = parent_bone

        # Needed to save bone
        bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
        bpy.ops.object.mode_set(mode='POSE', toggle=False)

        pose_bone = RigService.find_pose_bone_by_name(bone_name, armature_object)

        root_bone3 = RigService.find_pose_bone_by_name(finger3_root_name, armature_object)
        root_bone4 = RigService.find_pose_bone_by_name(finger4_root_name, armature_object)

        pose_bone.location = (root_bone3.location + root_bone4.location) / 2

        RigService.display_pose_bone_as_empty(armature_object, bone_name, 'CIRCLE')
        pose_bone.custom_shape_scale = 0.6

        for i in range(3):
            pose_bone.lock_location[i] = True
            pose_bone.lock_scale[i] = True
예제 #2
0
 def _apply_ik_constraint(self, armature_object):
     _LOG.enter()
     right = RigService.find_pose_bone_by_name("right_eye_ik",
                                               armature_object)
     left = RigService.find_pose_bone_by_name("left_eye_ik",
                                              armature_object)
     RigService.add_ik_constraint_to_pose_bone(self.get_eye_name(True),
                                               armature_object,
                                               right,
                                               chain_length=1)
     RigService.add_ik_constraint_to_pose_bone(self.get_eye_name(False),
                                               armature_object,
                                               left,
                                               chain_length=1)
예제 #3
0
    def _create_knee_ik_bone(self, armature_object):
        _LOG.enter()
        bpy.ops.object.mode_set(mode='EDIT', toggle=False)
        bones = armature_object.data.edit_bones
        bone = bones.new(self.which_leg + "_knee_ik")

        bone.head = self._bone_info["pose_bones"][
            self.get_upper_leg_name()]["head"]
        bone.tail = self._bone_info["pose_bones"][
            self.get_upper_leg_name()]["tail"]

        length = bone.tail - bone.head
        bone.tail = bone.tail + length / 5
        bone.head = bone.head + length

        bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
        bpy.ops.object.mode_set(mode='POSE', toggle=False)
        RigService.display_pose_bone_as_empty(armature_object,
                                              self.which_leg + "_knee_ik",
                                              empty_type="SPHERE")

        pose_bone = RigService.find_pose_bone_by_name(
            self.which_leg + "_knee_ik", armature_object)
        for i in range(3):
            pose_bone.lock_scale[i] = True
예제 #4
0
    def _create_point_ik_bone(self, finger_number, armature_object):
        _LOG.enter()

        bpy.ops.object.mode_set(mode='EDIT', toggle=False)

        tip_name = self.get_last_segment_name_of_finger(finger_number)

        head = self._bone_info["pose_bones"][tip_name]["head"]
        tail = self._bone_info["pose_bones"][tip_name]["tail"]
        roll = self._bone_info["edit_bones"][tip_name]["roll"]

        length = tail - head
        tail = tail + length
        head = head + length

        bone_name = self._get_point_ik_bone_name_for_finger(finger_number)
        bones = armature_object.data.edit_bones
        bone = bones.new(bone_name)
        bone.head = head
        bone.tail = tail
        bone.roll = roll

        # Needed to save bone
        bpy.ops.object.mode_set(mode='OBJECT', toggle=False)

        bpy.ops.object.mode_set(mode='POSE', toggle=False)
        RigService.display_pose_bone_as_empty(armature_object, bone_name, empty_type="SPHERE")
        pose_bone = RigService.find_pose_bone_by_name(bone_name, armature_object)

        scales = [0.5, 0.5, 0.5, 0.5, 0.7]
        pose_bone.custom_shape_scale = scales[finger_number - 1]
        _LOG.debug("scale", pose_bone.custom_shape_scale)
예제 #5
0
 def _set_upper_arm_ik_target(self, armature_object, chain_length):
     _LOG.enter()
     bpy.ops.object.mode_set(mode='POSE', toggle=False)
     upper_arm_name = self.get_upper_arm_name()
     elbow_name = self.which_arm + "_elbow_ik"
     elbow_bone = RigService.find_pose_bone_by_name(elbow_name, armature_object)
     self.add_upper_arm_rotation_constraints(armature_object)
     RigService.add_ik_constraint_to_pose_bone(upper_arm_name, armature_object, elbow_bone, chain_length)
예제 #6
0
 def _set_finger_ik_target(self, finger_number, armature_object, chain_length):
     _LOG.enter()
     bpy.ops.object.mode_set(mode='POSE', toggle=False)
     tip_name = self.get_last_segment_name_of_finger(finger_number)
     ik_name = self._get_point_ik_bone_name_for_finger(finger_number)
     ik_bone = RigService.find_pose_bone_by_name(ik_name, armature_object)
     self.add_finger_rotation_constraints(finger_number, armature_object)
     RigService.add_ik_constraint_to_pose_bone(tip_name, armature_object, ik_bone, chain_length)
예제 #7
0
 def _set_shoulder_ik_target(self, armature_object, chain_length):
     _LOG.enter()
     bpy.ops.object.mode_set(mode='POSE', toggle=False)
     shoulder_name = self.get_shoulder_name()
     shoulder_ik_name = self.which_arm + "_shoulder_ik"
     shoulder_bone = RigService.find_pose_bone_by_name(shoulder_ik_name, armature_object)
     self.add_shoulder_rotation_constraints(armature_object)
     RigService.add_ik_constraint_to_pose_bone(shoulder_name, armature_object, shoulder_bone, chain_length)
예제 #8
0
 def _setup_head(self, armature_object):
     _LOG.enter()
     head = self.get_list_of_head_bones()  # pylint: disable=E1111
     _LOG.dump("Head", head)
     self._set_use_connect_on_bones(armature_object, head)
     bpy.ops.object.mode_set(mode='POSE', toggle=False)
     first_head_bone = RigService.find_pose_bone_by_name(
         head[0], armature_object)
     first_head_bone.rigify_type = 'spines.super_head'
예제 #9
0
 def _setup_arms(self, armature_object):
     _LOG.enter()
     bpy.ops.object.mode_set(mode='POSE', toggle=False)
     for side in [True, False]:
         arm = self.get_list_of_arm_bones(side)  # pylint: disable=E1111
         _LOG.dump("Arm", arm)
         self._set_use_connect_on_bones(armature_object, arm)
         first_arm_bone = RigService.find_pose_bone_by_name(
             arm[0], armature_object)
         first_arm_bone.rigify_type = 'limbs.arm'
예제 #10
0
 def _setup_shoulders(self, armature_object):
     _LOG.enter()
     for side in [True, False]:
         shoulder = self.get_list_of_shoulder_bones(side)  # pylint: disable=E1111
         _LOG.dump("Shoulder", shoulder)
         self._set_use_connect_on_bones(armature_object, shoulder)
         bpy.ops.object.mode_set(mode='POSE', toggle=False)
         first_shoulder_bone = RigService.find_pose_bone_by_name(
             shoulder[0], armature_object)
         first_shoulder_bone.rigify_type = 'basic.super_copy'
예제 #11
0
 def _setup_legs(self, armature_object):
     _LOG.enter()
     for side in [True, False]:
         leg = self.get_list_of_leg_bones(side)  # pylint: disable=E1111
         _LOG.dump("Leg", leg)
         self._set_use_connect_on_bones(armature_object, leg)
         bpy.ops.object.mode_set(mode='POSE', toggle=False)
         first_leg_bone = RigService.find_pose_bone_by_name(
             leg[0], armature_object)
         first_leg_bone.rigify_type = 'limbs.paw'
예제 #12
0
 def _set_hip_ik_target(self, armature_object, chain_length):
     _LOG.enter()
     bpy.ops.object.mode_set(mode='POSE', toggle=False)
     hip_name = self.get_hip_name()
     hip_ik_name = self.which_leg + "_hip_ik"
     hip_bone = RigService.find_pose_bone_by_name(hip_ik_name,
                                                  armature_object)
     self.add_hip_rotation_constraints(armature_object)
     RigService.add_ik_constraint_to_pose_bone(hip_name, armature_object,
                                               hip_bone, chain_length)
예제 #13
0
 def _setup_spine(self, armature_object):
     _LOG.enter()
     spine = self.get_list_of_spine_bones()  # pylint: disable=E1111
     _LOG.dump("Spine", spine)
     self._set_use_connect_on_bones(armature_object, spine)
     bpy.ops.object.mode_set(mode='POSE', toggle=False)
     first_spine_bone = RigService.find_pose_bone_by_name(
         spine[0], armature_object)
     first_spine_bone.rigify_type = 'spines.basic_spine'
     first_spine_bone.rigify_parameters.segments = len(spine)
예제 #14
0
 def _setup_fingers(self, armature_object):
     _LOG.enter()
     for side in [True, False]:
         for finger_number in range(5):
             finger = self.get_list_of_finger_bones(finger_number, side)  # pylint: disable=E1111
             _LOG.dump("Finger", finger)
             self._set_use_connect_on_bones(armature_object, finger)
             bpy.ops.object.mode_set(mode='POSE', toggle=False)
             first_finger_bone = RigService.find_pose_bone_by_name(
                 finger[0], armature_object)
             first_finger_bone.rigify_type = 'limbs.super_finger'
예제 #15
0
 def _set_lower_leg_ik_target(self, armature_object, chain_length):
     _LOG.enter()
     bpy.ops.object.mode_set(mode='POSE', toggle=False)
     lower_leg_name = self.get_lower_leg_name()
     foot_name = self.which_leg + "_foot_ik"
     foot_bone = RigService.find_pose_bone_by_name(foot_name,
                                                   armature_object)
     self.add_lower_leg_rotation_constraints(armature_object)
     RigService.add_ik_constraint_to_pose_bone(lower_leg_name,
                                               armature_object, foot_bone,
                                               chain_length)
예제 #16
0
    def _create_grip_bone(self, finger_number, armature_object):
        _LOG.enter()

        bpy.ops.object.mode_set(mode='EDIT', toggle=False)

        tip_name = self.get_last_segment_name_of_finger(finger_number)
        root_name = self.get_first_segment_name_of_finger(finger_number)

        head = self._bone_info["edit_bones"][root_name]["head"]
        tail = self._bone_info["edit_bones"][tip_name]["tail"]
        roll = self._bone_info["edit_bones"][root_name]["roll"]

        bone_name = self._get_grip_bone_name_for_finger(finger_number)
        bones = armature_object.data.edit_bones
        bone = bones.new(bone_name)
        bone.head = head
        bone.tail = tail
        bone.roll = roll

        # Needed to save bone
        bpy.ops.object.mode_set(mode='OBJECT', toggle=False)

        bpy.ops.object.mode_set(mode='POSE', toggle=False)

        bone_name = self._get_grip_bone_name_for_finger(finger_number)
        pose_bone = RigService.find_pose_bone_by_name(bone_name, armature_object)

        root_bone = RigService.find_pose_bone_by_name(root_name, armature_object)

        pose_bone.location = root_bone.location

        RigService.display_pose_bone_as_empty(armature_object, bone_name, 'CIRCLE')

        scales = [0.1, 0.15, 0.1, 0.1, 0.2]
        pose_bone.custom_shape_scale = scales[finger_number-1]

        for i in range(3):
            pose_bone.lock_location[i] = True
            pose_bone.lock_scale[i] = True
예제 #17
0
    def _create_foot_ik_bone(self, armature_object):
        _LOG.enter()

        bpy.ops.object.mode_set(mode='EDIT', toggle=False)
        foot_name = self.get_foot_name()

        bones = armature_object.data.edit_bones
        bone = bones.new(self.which_leg + "_foot_ik")
        bone.head = self._bone_info["pose_bones"][foot_name]["head"]
        bone.tail = self._bone_info["pose_bones"][foot_name]["tail"]
        bone.roll = self._bone_info["edit_bones"][foot_name]["roll"]
        bone.matrix = self._bone_info["pose_bones"][foot_name]["matrix"]

        # Needed to save bone
        bpy.ops.object.mode_set(mode='OBJECT', toggle=False)

        bpy.ops.object.mode_set(mode='POSE', toggle=False)
        RigService.display_pose_bone_as_empty(armature_object,
                                              self.which_leg + "_foot_ik",
                                              empty_type="CIRCLE")
        pose_bone = RigService.find_pose_bone_by_name(
            self.which_leg + "_foot_ik", armature_object)
        pose_bone.custom_shape_scale = 0.5

        if self.settings["leg_target_rotates_foot"]:
            bpy.ops.object.mode_set(mode='POSE', toggle=False)
            constraint = RigService.add_bone_constraint_to_pose_bone(
                self.get_foot_name(), armature_object, "COPY_ROTATION")
            constraint.target = armature_object
            constraint.subtarget = self.which_leg + "_foot_ik"

            if self.settings["leg_target_rotates_lower_leg"]:
                lower_leg_segments = self.get_reverse_list_of_bones_in_leg(
                    False, True, False, False)
                for name in lower_leg_segments:
                    constraint = RigService.add_bone_constraint_to_pose_bone(
                        name, armature_object, "COPY_ROTATION")
                    constraint.target = armature_object
                    constraint.subtarget = self.which_leg + "_foot_ik"
                    constraint.use_x = False
                    constraint.use_z = False
                    constraint.influence = 0.4 / len(lower_leg_segments)

        for i in range(3):
            pose_bone.lock_scale[i] = True
예제 #18
0
    def rigify_metadata(self):
        """Assign bone meta data fitting for the pose bones."""
        bpy.ops.object.mode_set(mode='POSE', toggle=False)
        for bone_name in self.rig_definition.keys():
            bone_info = self.rig_definition[bone_name]["rigify"]
            bone = RigService.find_pose_bone_by_name(bone_name, self.armature_object)

            if "rigify_type" in bone_info and bone_info["rigify_type"]:
                bone.rigify_type = bone_info["rigify_type"]

            if "rigify_parameters" in bone_info:
                for key in bone_info["rigify_parameters"].keys():
                    value = bone_info["rigify_parameters"][key]
                    if isinstance(value, list):
                        pass
                    else:
                        _LOG.debug("Will attempt to set bone.parameters.", key)
                        setattr(bone.rigify_parameters, str(key), value)

        bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
예제 #19
0
    def _create_eye_ik_bones(self, armature_object):
        _LOG.enter()

        bpy.ops.object.mode_set(mode='EDIT', toggle=False)

        bones = armature_object.data.edit_bones

        for side in ["left", "right"]:
            is_right = side == "right"
            bone_name = self.get_eye_name(is_right)

            bone = bones.new(side + "_eye_ik")
            head = self._bone_info["pose_bones"][bone_name]["head"]
            tail = self._bone_info["pose_bones"][bone_name]["tail"]
            length = tail - head

            bone.head = head + length * 4
            bone.tail = tail = tail + length * 4
            bone.roll = self._bone_info["edit_bones"][bone_name]["roll"]

        left_eye_bone = RigService.find_edit_bone_by_name(
            "left_eye_ik", armature_object)
        right_eye_bone = RigService.find_edit_bone_by_name(
            "right_eye_ik", armature_object)

        bone = bones.new("eye_ik")
        bone.head = (left_eye_bone.head + right_eye_bone.head) / 2
        bone.tail = (left_eye_bone.tail + right_eye_bone.tail) / 2
        bone.roll = left_eye_bone.roll

        left_eye_bone.parent = bone
        right_eye_bone.parent = bone

        if self.settings["eye_parenting_strategy"] == "HEAD":
            bone.parent = RigService.find_edit_bone_by_name(
                self.get_head_name(), armature_object)

        if self.settings["eye_parenting_strategy"] == "ROOT":
            bone.parent = RigService.find_edit_bone_by_name(
                self.get_root_name(), armature_object)

        # Needed to save bone
        bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
        bpy.ops.object.mode_set(mode='POSE', toggle=False)

        RigService.display_pose_bone_as_empty(armature_object,
                                              "left_eye_ik",
                                              "CIRCLE",
                                              scale=0.5)
        RigService.display_pose_bone_as_empty(armature_object,
                                              "right_eye_ik",
                                              "CIRCLE",
                                              scale=0.5)
        RigService.display_pose_bone_as_empty(armature_object,
                                              "eye_ik",
                                              "CIRCLE",
                                              scale=1.4)

        for side in ["left", "right"]:
            pose_bone = RigService.find_pose_bone_by_name(
                side + "_eye_ik", armature_object)
            for i in range(3):
                pose_bone.lock_rotation[i] = True
                pose_bone.lock_scale[i] = True