22#include "RNA_prototypes.hh"
72 paths.
append({
"location"});
77 paths.
append({
"rotation_quaternion"});
80 paths.
append({
"rotation_axis_angle"});
88 paths.
append({
"rotation_euler"});
93 paths.
extend({{
"bbone_curveinx"},
116 Action &action = action_add(bmain,
"pose_create");
118 Strip &
strip = layer.strip_add(action, Strip::Type::Keyframe);
122 for (
Object *pose_object : pose_objects) {
128 if (pose_object->adt && pose_object->adt->action &&
129 pose_object->adt->slot_handle != Slot::unassigned)
131 Action &pose_object_action = pose_object->adt->action->wrap();
132 const slot_handle_t pose_object_slot = pose_object->adt->slot_handle;
133 foreach_fcurve_in_action_slot(pose_object_action, pose_object_slot, [&](
FCurve &fcurve) {
135 existing_paths.
add(existing_path);
146 &pose_object->id, &RNA_PoseBone, pose_bone);
148 for (
const RNAPath &rna_path : rna_paths) {
152 &bone_pointer, rna_path.path.c_str(), &resolved_pointer, &resolved_property))
159 &resolved_pointer, resolved_property);
160 if (!rna_path_id_to_prop.has_value()) {
165 !existing_paths.
contains({rna_path_id_to_prop.value(), std::nullopt, i}))
171 &bmain, slot, {rna_path_id_to_prop.value(), i}, {1, values[i]}, key_settings);
207 if (shelf_region->
runtime->visible) {
219 shelf_region->
flag &= ~RGN_FLAG_HIDDEN;
234 selected_pose_objects.
append(
object);
240 if (active_object && active_object->
pose && !selected_pose_objects.
contains(active_object)) {
241 selected_pose_objects.
append(active_object);
243 return selected_pose_objects;
253 if (selected_pose_objects.
is_empty()) {
275 if (catalog_path_c[0] && library) {
302 BLI_assert_msg(user_library,
"The passed lib_ref is expected to be a user library");
315 if (selected_pose_objects.
is_empty()) {
331 if (catalog_path_c[0]) {
334 *library, catalog_path);
340 *bmain, pose_action.
id,
name, *user_library, pose_asset_reference, *op->
reports);
362 if (
name[0] ==
'\0') {
367 const int enum_value =
RNA_enum_get(op->
ptr,
"asset_library_reference");
370 switch (lib_ref.
type) {
397 "asset_library_reference",
416 const char *edit_text,
428 ot->
name =
"Create Pose Asset...";
429 ot->
description =
"Create a new asset from the selected bones in the scene";
430 ot->
idname =
"POSELIB_OT_create_pose_asset";
437 ot->
srna,
"pose_name",
nullptr,
MAX_NAME,
"Pose Name",
"Name for the new pose asset");
444 ot->
srna,
"catalog_path",
nullptr,
MAX_NAME,
"Catalog",
"Catalog to use for the new asset");
451 "activate_new_action",
453 "Activate New Action",
454 "This property is deprecated and will be removed in the future");
470 "Update existing channels in the pose asset but don't remove or add any channels"},
474 "Replace with Selection",
475 "Completely replace all channels in the pose asset with the current selection"},
479 "Add Selected Bones",
480 "Add channels of the selection to the pose asset. Existing channels will be updated"},
484 "Remove Selected Bones",
485 "Remove channels of the selection from the pose asset"},
486 {0,
nullptr, 0,
nullptr,
nullptr},
504 return reinterpret_cast<bAction *
>(
524 &pose_object.
id, &RNA_PoseBone, pose_bone);
527 for (
RNAPath &rna_path : rna_paths) {
531 &bone_pointer, rna_path.path.c_str(), &resolved_pointer, &resolved_property))
536 &resolved_pointer, resolved_property);
537 if (!rna_path_id_to_prop.has_value()) {
543 for (
const float value : values) {
544 RNAPath path = {rna_path_id_to_prop.value(), std::nullopt, i};
577 constexpr int pose_frame = 1;
591 foreach_fcurve_in_action_slot(pose_action, slot.
handle, [&](
FCurve &fcurve) {
592 existing_paths.add({fcurve.rna_path, std::nullopt, fcurve.array_index});
597 for (
const PathValue &path_value : path_values) {
599 if (existing_paths.contains(path_value.rna_path)) {
603 {pose_frame, path_value.value},
604 {path_value.rna_path.path, path_value.rna_path.index.value()});
610 for (
const PathValue &path_value : path_values) {
614 {pose_frame, path_value.value},
615 {path_value.rna_path.path, path_value.rna_path.index.value()});
620 Channelbag *channelbag = strip_data->channelbag_for_slot(slot.handle);
626 for (
const PathValue &path_value : path_values) {
630 {pose_frame, path_value.value},
631 {path_value.rna_path.path, path_value.rna_path.index.value()});
636 Channelbag *channelbag = strip_data->channelbag_for_slot(slot.handle);
641 Map<RNAPath, FCurve *> fcurve_map;
643 pose_action, pose_action.slot_array[0]->handle, [&](
FCurve &fcurve) {
644 fcurve_map.add({fcurve.rna_path, std::nullopt, fcurve.array_index}, &fcurve);
646 for (
const PathValue &path_value : path_values) {
647 if (existing_paths.contains(path_value.rna_path)) {
648 FCurve *fcurve = fcurve_map.lookup(path_value.rna_path);
667 if (!pose_object || !pose_object->
pose) {
676 bke::asset_edit_id_save(*bmain, action->
id, *op->
reports);
683 asset::refresh_asset_library_from_asset(C, *asset);
706 if (!bke::asset_edit_id_is_editable(action->
id)) {
711 if (!bke::asset_edit_id_is_writable(action->
id)) {
730 ot->
name =
"Modify Pose Asset";
732 "Update the selected pose asset in the asset library from the currently selected bones. The "
733 "mode defines how the asset is updated";
734 ot->
idname =
"POSELIB_OT_asset_modify";
745 "Specify which parts of the pose asset are overwritten");
760 if (!bke::asset_edit_id_is_editable(action->
id)) {
765 if (!bke::asset_edit_id_is_writable(action->
id)) {
781 std::optional<AssetLibraryReference> library_ref =
788 asset::clear_id(&action->
id);
793 asset::refresh_asset_library(C, library_ref.value());
809 IFACE_(
"Delete Pose Asset"),
811 IFACE_(
"Permanently delete pose asset blend file? This cannot be undone.") :
812 IFACE_(
"The asset is local to the file. Deleting it will just clear the asset status."),
820 ot->
name =
"Delete Pose Asset";
822 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.
blender::asset_system::AssetLibrary * AS_asset_library_load(const Main *bmain, const AssetLibraryReference &library_reference)
Main runtime representation of an asset.
void BKE_asset_metadata_catalog_id_set(AssetMetaData *asset_data, bUUID catalog_id, const char *catalog_simple_name)
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
ScrArea * CTX_wm_area(const bContext *C)
Object * CTX_data_active_object(const bContext *C)
class blender::asset_system::AssetRepresentation * CTX_wm_asset(const bContext *C)
bool CTX_data_selected_objects(const bContext *C, blender::Vector< PointerRNA > *list)
Main * CTX_data_main(const bContext *C)
wmWindowManager * CTX_wm_manager(const bContext *C)
void BKE_fcurve_delete_keys_all(FCurve *fcu)
void BKE_id_free(Main *bmain, void *idv)
IDNewNameResult BKE_id_rename(Main &bmain, ID &id, blender::StringRefNull name, const IDNewNameMode mode=IDNewNameMode::RenameExistingNever)
struct bUserAssetLibrary * BKE_preferences_asset_library_find_index(const struct UserDef *userdef, int index) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
void BKE_report(ReportList *reports, eReportType type, const char *message)
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
#define LISTBASE_FOREACH(type, var, list)
#define ID_IS_LINKED(_id)
@ FILE_BROWSE_MODE_ASSETS
void ED_region_visibility_change_update(bContext *C, ScrArea *area, ARegion *region)
bool ED_operator_posemode_context(bContext *C)
void ED_undo_push_op(bContext *C, wmOperator *op)
@ PROP_STRING_SEARCH_SUGGESTION
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)
blender::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)
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)
bool write_to_disk(const CatalogFilePath &blend_file_path)
const CatalogID catalog_id
AssetCatalogService & catalog_service() const
virtual std::optional< AssetLibraryReference > library_reference() const =0
AssetLibrary & owner_asset_library() const
ID_Type get_id_type() const
AssetWeakReference make_weak_reference() const
void foreach_fcurve_in_action_slot(Action &action, slot_handle_t handle, FunctionRef< void(FCurve &fcurve)> callback)
bool bone_is_visible(const bArmature *armature, const Bone *bone)
Vector< RNAPath > get_keyable_id_property_paths(const PointerRNA &ptr)
Vector< float > get_rna_values(PointerRNA *ptr, PropertyRNA *prop)
decltype(::ActionSlot::handle) slot_handle_t
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)
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)
static blender::Vector< Object * > get_selected_pose_objects(bContext *C)
static wmOperatorStatus pose_asset_delete_invoke(bContext *C, wmOperator *op, const wmEvent *)
static blender::animrig::Action & extract_pose(Main &bmain, const blender::Span< Object * > pose_objects)
static wmOperatorStatus pose_asset_delete_exec(bContext *C, wmOperator *op)
static bool pose_asset_delete_poll(bContext *C)
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 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 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 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)
const EnumPropertyItem * library_reference_to_rna_enum_itemf(bool include_readonly, bool include_current_file)
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)
void visit_library_catalogs_catalog_for_search(const Main &bmain, const AssetLibraryReference lib, const StringRef edit_text, const FunctionRef< void(StringPropertySearchVisitParams)> visit_fn)
AssetLibraryReference user_library_to_library_ref(const bUserAssetLibrary &user_library)
blender::asset_system::AssetCatalog & library_ensure_catalogs_in_path(blender::asset_system::AssetLibrary &library, const blender::asset_system::AssetCatalogPath &path)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
bool RNA_struct_property_is_set_ex(PointerRNA *ptr, const char *identifier, bool use_ghost)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
bool RNA_property_is_idprop(const PropertyRNA *prop)
std::string RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
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_string_search_func_runtime(PropertyRNA *prop, StringPropertySearchFunc search_fn, const eStringPropertySearchFlag search_flag)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
std::optional< std::string > RNA_path_from_ID_to_property(const PointerRNA *ptr, PropertyRNA *prop)
bool RNA_path_resolve(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
ARegionRuntimeHandle * runtime
struct AssetMetaData * asset_data
wmOperatorStatus(* exec)(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
std::string(* get_description)(bContext *C, wmOperatorType *ot, PointerRNA *ptr)
wmOperatorStatus(* invoke)(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports
void WM_main_add_notifier(uint type, void *reference)
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)
wmOperatorStatus WM_operator_confirm_ex(bContext *C, wmOperator *op, const char *title, const char *message, const char *confirm_text, int icon, bool cancel_default)
bScreen * WM_window_get_active_screen(const wmWindow *win)