Example #1
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)
Example #2
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
Example #3
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
Example #4
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
Example #5
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
Example #6
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