Sun Position: fix error in HDRI mode when no env tex is selected
[blender-addons.git] / pose_library / conversion.py
blobbc65752119812f142907109d8b9c3db7a78cd685
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 """
4 Pose Library - Conversion of old pose libraries.
5 """
7 from typing import Optional
8 from collections.abc import Collection
10 if "pose_creation" not in locals():
11 from . import pose_creation
12 else:
13 import importlib
15 pose_creation = importlib.reload(pose_creation)
17 import bpy
18 from bpy.types import (
19 Action,
20 TimelineMarker,
24 def convert_old_poselib(old_poselib: Action) -> Collection[Action]:
25 """Convert an old-style pose library to a set of pose Actions.
27 Old pose libraries were one Action with multiple pose markers. Each pose
28 marker will be converted to an Action by itself and marked as asset.
29 """
31 pose_assets = [action for marker in old_poselib.pose_markers if (action := convert_old_pose(old_poselib, marker))]
33 # Mark all Actions as assets in one go. Ideally this would be done on an
34 # appropriate frame in the scene (to set up things like the background
35 # colour), but the old-style poselib doesn't contain such information. All
36 # we can do is just render on the current frame.
37 bpy.ops.asset.mark({'selected_ids': pose_assets})
39 return pose_assets
42 def convert_old_pose(old_poselib: Action, marker: TimelineMarker) -> Optional[Action]:
43 """Convert an old-style pose library pose to a pose action."""
45 frame: int = marker.frame
46 action: Optional[Action] = None
48 for fcurve in old_poselib.fcurves:
49 key = pose_creation.find_keyframe(fcurve, frame)
50 if not key:
51 continue
53 if action is None:
54 action = bpy.data.actions.new(marker.name)
56 pose_creation.create_single_key_fcurve(action, fcurve, key)
58 return action