28#include "RNA_prototypes.hh"
81 paths.
append({
"location"});
86 paths.
append({
"rotation_quaternion"});
89 paths.
append({
"rotation_axis_angle"});
97 paths.
append({
"rotation_euler"});
102 paths.
extend({{
"bbone_curveinx"},
131 for (
Object *pose_object : pose_objects) {
134 const bArmature *armature = id_cast<bArmature *>(pose_object->data);
137 if (pose_object->adt && pose_object->adt->action &&
140 Action &pose_object_action = pose_object->adt->action->wrap();
141 const slot_handle_t pose_object_slot = pose_object->adt->slot_handle;
143 pose_object_action, pose_object_slot, [&](
const FCurve &fcurve) {
145 existing_paths.
add(existing_path);
149 for (
bPoseChannel &pose_bone : pose_object->pose->chanbase) {
151 {&pose_bone, pose_bone.bone_get(*pose_object)}))
156 &pose_object->id, RNA_PoseBone, &pose_bone);
162 &bone_pointer,
rna_path.path.c_str(), &resolved_pointer, &resolved_property))
169 &resolved_pointer, resolved_property);
170 if (!rna_path_id_to_prop.has_value()) {
175 !existing_paths.
contains({rna_path_id_to_prop.value(), std::nullopt, i}))
181 &bmain, slot, {rna_path_id_to_prop.value(), i}, {1, values[i]}, key_settings);
241 for (
const PointerRNA &ptr : selected_objects) {
242 Object *
object =
reinterpret_cast<Object *
>(ptr.owner_id);
246 selected_pose_objects.
append(
object);
252 if (active_object && active_object->
pose && !selected_pose_objects.
contains(active_object)) {
253 selected_pose_objects.
append(active_object);
255 return selected_pose_objects;
265 if (selected_pose_objects.
is_empty()) {
287 if (catalog_path_c[0] &&
library) {
315 BLI_assert_msg(user_library,
"The passed lib_ref is expected to be a user library");
320 "The passed lib_ref is expected to be an on disk library");
333 if (selected_pose_objects.
is_empty()) {
349 if (catalog_path_c[0]) {
359 *bmain, pose_action.
id, name, *user_library, pose_asset_reference, *op->
reports);
361 library->catalog_service().write_to_disk(*final_full_asset_filepath);
381 if (name[0] ==
'\0') {
386 const int enum_value =
RNA_enum_get(op->
ptr,
"asset_library_reference");
389 switch (lib_ref.
type) {
413 std::optional<AssetLibraryReference> dest_library_ref =
416 if (!dest_library_ref) {
421 "asset_library_reference",
440 const char *edit_text,
443 const int enum_value =
RNA_enum_get(ptr,
"asset_library_reference");
452 ot->
name =
"Create Pose Asset...";
453 ot->
description =
"Create a new asset from the selected bones in the scene";
454 ot->
idname =
"POSELIB_OT_create_pose_asset";
462 ot->
srna,
"pose_name",
nullptr,
MAX_NAME,
"Pose Name",
"Name for the new pose asset");
470 ot->
srna,
"catalog_path",
nullptr,
MAX_NAME,
"Catalog",
"Catalog to use for the new asset");
487 "Update existing channels in the pose asset but don't remove or add any channels"},
491 "Replace with Selection",
492 "Completely replace all channels in the pose asset with the current selection"},
496 "Add Selected Bones",
497 "Add channels of the selection to the pose asset. Existing channels will be updated"},
501 "Remove Selected Bones",
502 "Remove channels of the selection from the pose asset"},
503 {0,
nullptr, 0,
nullptr,
nullptr},
529 return reinterpret_cast<bAction *
>(
582 const bArmature *armature = id_cast<bArmature *>(pose_object.
data);
585 {&pose_bone, pose_bone.bone_get(pose_object)}))
590 &pose_object.
id, RNA_PoseBone, &pose_bone);
597 &bone_pointer,
rna_path.path.c_str(), &resolved_pointer, &resolved_property))
602 &resolved_pointer, resolved_property);
603 if (!rna_path_id_to_prop.has_value()) {
609 for (
const float value : values) {
610 RNAPath path = {rna_path_id_to_prop.value(), std::nullopt, i};
611 path_values.
append({path, value});
643 constexpr int pose_frame = 1;
658 existing_paths.add({fcurve.rna_path(), std::nullopt, fcurve.array_index});
663 for (
const PathValue &path_value : path_values) {
665 if (existing_paths.contains(path_value.rna_path)) {
669 {pose_frame, path_value.value},
670 {path_value.rna_path.path, path_value.rna_path.index.value()});
676 for (
const PathValue &path_value : path_values) {
680 {pose_frame, path_value.value},
681 {path_value.rna_path.path, path_value.rna_path.index.value()});
686 Channelbag *channelbag = strip_data->channelbag_for_slot(slot.handle);
692 for (
const PathValue &path_value : path_values) {
696 {pose_frame, path_value.value},
697 {path_value.rna_path.path, path_value.rna_path.index.value()});
702 Channelbag *channelbag = strip_data->channelbag_for_slot(slot.handle);
707 Map<RNAPath, FCurve *> fcurve_map;
709 pose_action, pose_action.slot_array[0]->handle, [&](FCurve &fcurve) {
710 fcurve_map.add({fcurve.rna_path(), std::nullopt, fcurve.array_index}, &fcurve);
712 for (
const PathValue &path_value : path_values) {
713 if (existing_paths.contains(path_value.rna_path)) {
714 FCurve *fcurve = fcurve_map.lookup(path_value.rna_path);
741 if (!pose_object || !pose_object->
pose) {
783 ot->
name =
"Modify Pose Asset";
785 "Update the selected pose asset in the asset library from the currently selected bones. The "
786 "mode defines how the asset is updated";
787 ot->
idname =
"POSELIB_OT_asset_modify";
798 "Specify which parts of the pose asset are overwritten");
813 std::optional<AssetLibraryReference> library_ref =
814 asset->owner_asset_library().library_reference();
854 IFACE_(
"Delete Pose Asset"),
856 IFACE_(
"Permanently delete pose asset blend file? This cannot be undone.") :
857 IFACE_(
"The asset is local to the file. Deleting it will just clear the asset status."),
865 ot->
name =
"Delete Pose Asset";
866 ot->
description =
"Delete the selected Pose Asset";
867 ot->
idname =
"POSELIB_OT_asset_delete";
Functions and classes to work with Actions.
Functionality to iterate an Action in various ways.
Functions to deal with Armatures.
Functions to insert, delete or modify keyframes.
Functions to work with animation poses.
Helper functions for animation to interact with the RNA system.
Main runtime representation of an asset.
#define ID_IS_LINKED(_id)
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
bool contains(const Key &key) const
bool contains(const T &value) const
void append(const T &value)
IndexRange index_range() const
void extend(Span< T > array)
Slot & slot_add_for_id(const ID &animated_id)
Span< const Layer * > layers() const
Span< const StripKeyframeData * > strip_keyframe_data() const
Layer & layer_add(std::optional< StringRefNull > name)
bool fcurve_remove(FCurve &fcurve_to_remove)
FCurve & fcurve_ensure(Main *bmain, const FCurveDescriptor &fcurve_descriptor)
static constexpr slot_handle_t unassigned
SingleKeyingResult keyframe_insert(Main *bmain, const Slot &slot, const FCurveDescriptor &fcurve_descriptor, float2 time_value, const KeyframeSettings &settings, eInsertKeyFlags insert_key_flags=INSERTKEY_NOFLAGS, std::optional< float2 > cycle_range=std::nullopt)
Channelbag & channelbag_for_slot_ensure(const Slot &slot)
const T & data(const Action &owning_action) const
static AssetCatalogPath from_user_input(const char *path)
const CatalogID catalog_id
bool is_potentially_editable_asset_blend() const
ID_Type get_id_type() const
void foreach_fcurve_in_action_slot(Action &action, slot_handle_t handle, FunctionRef< void(FCurve &fcurve)> callback)
decltype(blender::ActionSlot::handle) slot_handle_t
Action & action_add(Main &bmain, StringRefNull name)
Vector< RNAPath > get_keyable_id_property_paths(const PointerRNA &ptr)
Vector< float > get_rna_values(PointerRNA *ptr, PropertyRNA *prop)
bool bone_is_selected(const bArmature *armature, const Bone *bone)
SingleKeyingResult insert_vert_fcurve(FCurve *fcu, const float2 position, const KeyframeSettings &settings, eInsertKeyFlags flag)
Main Key-framing API call.
Slot & get_best_pose_slot_for_id(const ID &id, Action &pose_data)
ID * asset_edit_id_from_weak_reference(Main &global_main, ID_Type id_type, const AssetWeakReference &weak_ref)
bool asset_edit_id_save(Main &global_main, ID &id, ReportList &reports)
std::optional< std::string > asset_edit_id_save_as(Main &global_main, const ID &id, StringRefNull name, const bUserAssetLibrary &user_library, AssetWeakReference &r_weak_ref, ReportList &reports)
bool asset_edit_id_delete(Main &global_main, ID &id, ReportList &reports)
bool asset_edit_id_is_writable(const ID &id)
bool asset_edit_id_is_editable(const ID &id)
static wmOperatorStatus pose_asset_delete_invoke(bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus pose_asset_delete_exec(bContext *C, wmOperator *op)
static void ensure_asset_ui_visible(bContext &C)
static bool pose_asset_create_poll(bContext *C)
static const EnumPropertyItem * rna_asset_library_reference_itemf(bContext *, PointerRNA *, PropertyRNA *, bool *r_free)
static Vector< PathValue > generate_path_values(Object &pose_object)
static wmOperatorStatus pose_asset_create_exec(bContext *C, wmOperator *op)
static bool pose_asset_potentially_editable_poll(bContext *C)
static wmOperatorStatus pose_asset_modify_exec(bContext *C, wmOperator *op)
void POSELIB_OT_asset_delete(wmOperatorType *ot)
static std::string pose_asset_modify_description(bContext *, wmOperatorType *, PointerRNA *ptr)
static wmOperatorStatus create_pose_asset_user_library(bContext *C, wmOperator *op, const char name[MAX_NAME], const AssetLibraryReference lib_ref)
static Vector< Object * > get_selected_pose_objects(bContext *C)
static blender::animrig::Action & extract_pose(Main &bmain, const Span< Object * > pose_objects)
static bool pose_asset_modify_poll(bContext *C)
void POSELIB_OT_create_pose_asset(wmOperatorType *ot)
static void replace_pose_key(Main &bmain, blender::animrig::StripKeyframeData &strip_data, const blender::animrig::Slot &slot, const float2 time_value, const blender::animrig::FCurveDescriptor &fcurve_descriptor)
static wmOperatorStatus pose_asset_create_invoke(bContext *C, wmOperator *op, const wmEvent *)
static Vector< RNAPath > construct_pose_rna_paths(const PointerRNA &bone_pointer)
static void update_pose_action_from_scene(Main *bmain, blender::animrig::Action &pose_action, Object &pose_object, const AssetModifyMode mode)
static void visit_library_prop_catalogs_catalog_for_search_fn(const bContext *C, PointerRNA *ptr, PropertyRNA *, const char *edit_text, FunctionRef< void(StringPropertySearchVisitParams)> visit_fn)
static wmOperatorStatus create_pose_asset_local(bContext *C, wmOperator *op, const StringRefNull name, const AssetLibraryReference lib_ref)
static const EnumPropertyItem prop_asset_overwrite_modes[]
void POSELIB_OT_asset_modify(wmOperatorType *ot)
static bool is_pose_asset_blend_editable(const bAction &action, ReportList *reports)
static bAction * get_action_of_selected_asset(bContext *C)
void show_catalog_in_visible_shelves(const bContext &C, const StringRefNull catalog_path)
int library_reference_to_enum_value(const AssetLibraryReference *library)
void refresh_asset_library(const bContext *C, const AssetLibraryReference &library_ref)
AssetLibraryReference library_reference_from_enum_value(int value)
void generate_preview(const bContext *C, ID *id)
asset_system::AssetCatalog & library_ensure_catalogs_in_path(asset_system::AssetLibrary &library, const asset_system::AssetCatalogPath &path)
void visit_library_catalogs_catalog_for_search(const Main &bmain, const AssetLibraryReference lib, const StringRef edit_text, const FunctionRef< void(StringPropertySearchVisitParams)> visit_fn)
std::optional< AssetLibraryReference > get_user_library_ref_for_save(const asset_system::AssetLibrary *preferred_library)
void refresh_asset_library_from_asset(const bContext *C, const asset_system::AssetRepresentation &asset)
const EnumPropertyItem * library_reference_to_rna_enum_itemf(bool include_readonly, bool include_current_file, bool include_remote_libraries, bool include_separate_online_essentials)
void WM_main_add_notifier(uint type, void *reference)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
ScrArea * CTX_wm_area(const bContext *C)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
void RNA_def_property_enum_default(PropertyRNA *prop, int value)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
bool RNA_path_resolve(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
@ ASSET_LIBRARY_USE_REMOTE_URL
std::optional< std::string > RNA_path_from_ID_to_property(const PointerRNA *ptr, PropertyRNA *prop)
class asset_system::AssetRepresentation * CTX_wm_asset(const bContext *C)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
bool RNA_struct_property_is_set_ex(PointerRNA *ptr, const char *identifier, bool use_ghost)
std::string RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop)
void BKE_asset_metadata_catalog_id_set(AssetMetaData *asset_data, bUUID catalog_id, const char *catalog_simple_name)
struct bUserAssetLibrary * BKE_preferences_asset_library_find_index(const struct UserDef *userdef, int index) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
@ FILE_BROWSE_MODE_ASSETS
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
void ED_undo_push_op(bContext *C, wmOperator *op)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier_c_str, int type, int subtype)
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
VecBase< float, 2 > float2
@ PROP_STRING_SEARCH_SUGGESTION
void BKE_report(ReportList *reports, eReportType type, const char *message)
void RNA_def_property_string_search_func_runtime(PropertyRNA *prop, StringPropertySearchFunc search_fn, const eStringPropertySearchFlag search_flag)
wmWindowManager * CTX_wm_manager(const bContext *C)
bool ED_operator_posemode_context(bContext *C)
bool RNA_property_is_idprop(const PropertyRNA *prop)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
wmOperatorStatus WM_operator_props_dialog_popup(bContext *C, wmOperator *op, int width, std::optional< std::string > title, std::optional< std::string > confirm_text, const bool cancel_default, std::optional< std::string > message, const bool show_icon)
asset_system::AssetLibrary * AS_asset_library_load(const Main *bmain, const AssetLibraryReference &library_reference)
wmOperatorStatus WM_operator_confirm_ex(bContext *C, wmOperator *op, const char *title, const char *message, const char *confirm_text, ui::AlertIcon icon, bool cancel_default)
void BKE_id_free(Main *bmain, void *idv)
void ED_region_visibility_change_update(bContext *C, ScrArea *area, ARegion *region)
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Main * CTX_data_main(const bContext *C)
void BKE_fcurve_delete_keys_all(FCurve &fcu)
IDNewNameResult BKE_id_rename(Main &bmain, ID &id, StringRefNull name, const IDNewNameMode mode=IDNewNameMode::RenameExistingNever)
std::string RNA_string_get(PointerRNA *ptr, const char *name)
bool CTX_data_selected_objects(const bContext *C, Vector< PointerRNA > *list)
bScreen * WM_window_get_active_screen(const wmWindow *win)
Object * CTX_data_active_object(const bContext *C)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
bke::ARegionRuntime * runtime
struct AssetMetaData * asset_data
ListBaseT< SpaceLink > spacedata
eFileBrowse_Mode browse_mode
ListBaseT< bPoseChannel > chanbase
ListBaseT< struct ScrArea > areabase
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
std::string(*) get_description(bContext *C, wmOperatorType *ot, PointerRNA *ptr)
struct ReportList * reports