Ejemplo n.º 1
0
    def exec(self, context, action):
        scene = context.scene
        obj = context.active_object

        path_old = get_bone_data_path(self.old, "")
        path_new = get_bone_data_path(self.new, "")

        for group in action.groups:
            group.name = group.name.replace(self.old, self.new)

        for index, fcurve in iters.reverse_enumerate(action.fcurves):
            fcurve.data_path = fcurve.data_path.replace(path_old, path_new)
Ejemplo n.º 2
0
def group_actions_by_bone():
    bone_names = set()
    for armature in bpy.data.armatures:
        for bone in armature.bones:
            bone_names.add(bone.name)

    bone_paths = []
    for bone_name in bone_names:
        bone_paths.append((bone_name, get_bone_data_path(bone_name, "")))

    for action in bpy.data.actions:
        for fcurve in action.fcurves:
            for bone_name, bone_path in bone_paths:
                if fcurve.group and fcurve.group.name in bone_names:
                    continue
                if not fcurve.data_path.startswith(bone_path):
                    continue

                if bone_name in action.groups:
                    group = action.groups[bone_name]
                else:
                    group = action.groups.new(bone_name)
                fcurve.group = group

        overall = action.groups.get("Armature")
        if not overall:
            overall = action.groups.new("Armature")
        for fcurve in action.fcurves:
            if fcurve.group is None:
                fcurve.group = overall
Ejemplo n.º 3
0
def clean_fcurves(action):
    if len(valid_bone_names == 0):
        for armature in bpy.data.armatures:
            for bone in armature.bones:
                valid_bone_names.add(bone.name)
    if len(valid_pose_bone_paths) == 0:
        for bone_name in valid_bone_names:
            for valid_data_path in valid_data_paths:
                path = get_bone_data_path(bone_name, valid_data_path)
                valid_pose_bone_paths.add(path)

    removals = []
    for fcurve in action.fcurves:
        data_path = fcurve.data_path
        if not data_path.startswith("pose.bones"):
            continue
        if not data_path in valid_pose_bone_paths:
            removals.append(fcurve)

    for bad_group in bad_groups:
        if bad_group in action.groups:
            group = action.groups[bad_group]
            for fcurve in [fc for fc in action.fcurves if fc.group == group]:
                removals.append(fcurve)

    for bad_string in bad_strings:
        for fcurve in action.fcurves:
            if bad_string in fcurve.data_path:
                removals.append(fcurve)

    for removal in removals:
        if removal:
            print("{0}: Removing fcurve [{1}]".format(action.name,
                                                      removal.data_path))
            action.fcurves.remove(removal)
Ejemplo n.º 4
0
    def do_apply(self, context, arm, bone, pose_correction, prop_name,
                 changed_bones, length):

        for b in changed_bones:
            path = get_bone_data_path(b, prop_name)

            f = context.scene.frame_current
            for i in range(length):
                arm.keyframe_insert(path, index=i, frame=f)
Ejemplo n.º 5
0
    def exec(self, context, action):
        scene = context.scene
        obj = context.active_object
        selected_bone_names = list(
            [bone.name for bone in obj.data.bones if bone.select])

        for bone_name in selected_bone_names:
            path_prefix = get_bone_data_path(bone_name, "")

            for index, fcurve in iters.reverse_enumerate(action.fcurves):
                if fcurve.data_path.startswith(path_prefix):
                    action.fcurves.remove(fcurve)
def assign_empty_action_to_bone_action(empty, target_action):
    current_action = empty.animation_data.action

    new_group = target_action.groups.new(empty.name)

    for current_fcurve in current_action.fcurves:

        new_curve_name = get_bone_data_path(empty.name, current_fcurve.data_path)

        new_curve = current_action.fcurves.new(
            new_curve_name, current_fcurve.index, new_group.name
        )

        for k in current_fcurve.keyframe_points:
            new_curve.keyframe_points.insert(
                k.co[0], k.co[1], options={"NEEDED", "FAST"}
            )

        new_curve.update()
Ejemplo n.º 7
0
def get_rotation_at_key(action: Action, channel: str,
                        frame: int) -> Union[Quaternion, Euler, Vector]:
    options = [
        ("rotation_quaternion", [4]),
        ("rotation_euler", [3]),
        ("rotation_axis_angle", [3, 1]),
    ]

    for rotation_mode, rotation_part_lengths in options:
        rotation_parts = len(rotation_part_lengths)

        path = get_bone_data_path(channel, rotation_mode)
        curves = [fc for fc in action.fcurves if fc.data_path.startswith(path)]

        rotation = _create_default_rotation(rotation_mode)

        if not curves or len(curves) == 0:
            continue

        curve_component_index = 0

        for rotation_part_index, rotation_part_length in enumerate(
                rotation_part_lengths):
            for rotation_component_index in range(rotation_part_length):

                curve = curves[curve_component_index]

                v = curve.evaluate(frame)
                if rotation_parts > 1:
                    if rotation_component_index > 1:
                        rotation[rotation_part_index][
                            rotation_component_index] = v
                    else:
                        rotation[rotation_part_index] = v
                else:
                    rotation[rotation_component_index] = v

                curve_component_index += 1

        return rotation

    return rotation
Ejemplo n.º 8
0
def integrate_empties_action_into_bones(obj_names, master_name):
    master_action_names = []
    action_sets = {}

    for obj_name in obj_names:
        action_sets[obj_name] = []

    for action in bpy.data.actions:
        if action.name.startswith(master_name):
            master_action_names.append(action.name)
        else:
            for obj_name in obj_names:
                if action.name.startswith(obj_name):
                    action_sets[obj_name].append(action.name)
                    break

    for action_set_key in action_sets.keys():
        action_set = action_sets[action_set_key]

        for action_name in action_set:
            clean_name = (action_name.replace("Animation Base Layer",
                                              "").replace(action_set_key,
                                                          "").strip("|"))

            master_action = None

            for master_action_name in master_action_names:
                clean_master_action_name = (master_action_name.replace(
                    "Animation Base Layer", "").replace(master_name,
                                                        "").strip("|"))

                if clean_master_action_name == clean_name:
                    master_action = bpy.data.actions[master_action_name]

            if master_action is None:
                continue

            action = bpy.data.actions[action_name]

            if master_action == action:
                continue

            for fcurve in action.fcurves:
                fcurve_data_path = get_bone_data_path(action_set_key,
                                                      fcurve.data_path)
                new_fcurve = master_action.fcurves.new(
                    fcurve_data_path, index=fcurve.array_index)

                new_fcurve.keyframe_points.add(len(fcurve.keyframe_points))

                for index, key in enumerate(fcurve.keyframe_points):
                    new_key = new_fcurve.keyframe_points[index]
                    new_key.co[0] = key.co[0]
                    new_key.co[1] = key.co[1]

                new_fcurve.update()

            bpy.data.actions.remove(action)

    for action_name in master_action_names:
        action = bpy.data.actions[action_name]

        for fcurve in action.fcurves:
            if not fcurve.data_path.startswith("pose.bones"):
                fcurve.data_path = get_bone_data_path(master_name,
                                                      fcurve.data_path)
Ejemplo n.º 9
0
 def store_keyframe(bone_name, prop_type, fc_array_index, frame, value):
     fc_data_path = get_bone_data_path(pbone.name, prop_type)
     fc_key = (fc_data_path, fc_array_index)
     if not keyframes.get(fc_key):
         keyframes[fc_key] = []
     keyframes[fc_key].extend((frame, value))