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"},
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 &&
131 Action &pose_object_action = pose_object->adt->action->wrap();
132 const slot_handle_t pose_object_slot = pose_object->adt->slot_handle;
135 existing_paths.
add(existing_path);
144 &pose_object->id, &RNA_PoseBone, pose_bone);
146 for (
const RNAPath &rna_path : rna_paths) {
150 &bone_pointer, rna_path.path.c_str(), &resolved_pointer, &resolved_property))
157 &resolved_pointer, resolved_property);
158 if (!rna_path_id_to_prop.has_value()) {
163 !existing_paths.
contains({rna_path_id_to_prop.value(), std::nullopt, i}))
169 &bmain, slot, {rna_path_id_to_prop.value(),
i}, {1, values[
i]}, key_settings);
207 if (shelf_region->
runtime->visible) {
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";
438 ot->srna,
"pose_name",
nullptr,
MAX_NAME,
"Pose Name",
"Name for the new pose asset");
445 ot->srna,
"catalog_path",
nullptr,
MAX_NAME,
"Catalog",
"Catalog to use for the new asset");
462 "Update existing channels in the pose asset but don't remove or add any channels"},
466 "Replace with Selection",
467 "Completely replace all channels in the pose asset with the current selection"},
471 "Add Selected Bones",
472 "Add channels of the selection to the pose asset. Existing channels will be updated"},
476 "Remove Selected Bones",
477 "Remove channels of the selection from the pose asset"},
478 {0,
nullptr, 0,
nullptr,
nullptr},
496 return reinterpret_cast<bAction *
>(
514 &pose_object.
id, &RNA_PoseBone, pose_bone);
517 for (
RNAPath &rna_path : rna_paths) {
521 &bone_pointer, rna_path.path.c_str(), &resolved_pointer, &resolved_property))
526 &resolved_pointer, resolved_property);
527 if (!rna_path_id_to_prop.has_value()) {
533 for (
const float value : values) {
534 RNAPath path = {rna_path_id_to_prop.value(), std::nullopt,
i};
535 path_values.
append({path, value});
567 constexpr int pose_frame = 1;
582 existing_paths.add({fcurve.rna_path, std::nullopt, fcurve.array_index});
587 for (
const PathValue &path_value : path_values) {
589 if (existing_paths.contains(path_value.rna_path)) {
593 {pose_frame, path_value.value},
594 {path_value.rna_path.path, path_value.rna_path.index.value()});
600 for (
const PathValue &path_value : path_values) {
604 {pose_frame, path_value.value},
605 {path_value.rna_path.path, path_value.rna_path.index.value()});
610 Channelbag *channelbag = strip_data->channelbag_for_slot(slot.handle);
616 for (
const PathValue &path_value : path_values) {
620 {pose_frame, path_value.value},
621 {path_value.rna_path.path, path_value.rna_path.index.value()});
626 Channelbag *channelbag = strip_data->channelbag_for_slot(slot.handle);
631 Map<RNAPath, FCurve *> fcurve_map;
633 pose_action, pose_action.slot_array[0]->handle, [&](
FCurve &fcurve) {
634 fcurve_map.add({fcurve.rna_path, std::nullopt, fcurve.array_index}, &fcurve);
636 for (
const PathValue &path_value : path_values) {
637 if (existing_paths.contains(path_value.rna_path)) {
638 FCurve *fcurve = fcurve_map.lookup(path_value.rna_path);
657 if (!pose_object || !pose_object->
pose) {
722 ot->name =
"Modify Pose Asset";
724 "Update the selected pose asset in the asset library from the currently selected bones. The "
725 "mode defines how the asset is updated";
726 ot->idname =
"POSELIB_OT_asset_modify";
737 "Specify which parts of the pose asset are overwritten");
773 std::optional<AssetLibraryReference> library_ref =
774 asset->owner_asset_library().library_reference();
801 IFACE_(
"Delete Pose Asset"),
803 IFACE_(
"Permanently delete pose asset blend file? This cannot be undone.") :
804 IFACE_(
"The asset is local to the file. Deleting it will just clear the asset status."),
812 ot->name =
"Delete Pose Asset";
813 ot->description =
"Delete the selected Pose Asset";
814 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)
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)
bool write_to_disk(const CatalogFilePath &blend_file_path)
const CatalogID catalog_id
AssetCatalogService & catalog_service() const
void foreach_fcurve_in_action_slot(Action &action, slot_handle_t handle, FunctionRef< void(FCurve &fcurve)> callback)
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)
decltype(::ActionSlot::handle) slot_handle_t
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)
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)
bool asset_edit_id_save(Main &global_main, const ID &id, 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)
void refresh_asset_library_from_asset(const bContext *C, const blender::asset_system::AssetRepresentation &asset)
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)
VecBase< float, 2 > float2
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)
std::string RNA_string_get(PointerRNA *ptr, const char *name)
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)
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
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, std::optional< std::string > message)
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)