Blender V5.3
anim_asset_ops.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_listbase.hh"
10
11#include "BKE_asset.hh"
12#include "BKE_asset_edit.hh"
13#include "BKE_context.hh"
14#include "BKE_fcurve.hh"
15#include "BKE_global.hh"
16#include "BKE_icons.hh"
17#include "BKE_lib_id.hh"
18#include "BKE_preferences.h"
19#include "BKE_report.hh"
20#include "BKE_screen.hh"
21
22#include "DNA_asset_types.h"
23
24#include "WM_api.hh"
25
26#include "RNA_access.hh"
27#include "RNA_define.hh"
28#include "RNA_prototypes.hh"
29
30#include "ED_asset.hh"
31#include "ED_asset_library.hh"
32#include "ED_asset_list.hh"
35#include "ED_asset_shelf.hh"
36#include "ED_fileselect.hh"
37#include "ED_screen.hh"
38#include "ED_undo.hh"
39
40#include "UI_interface_icons.hh"
41#include "UI_resources.hh"
42
43#include "BLT_translation.hh"
44
45#include "ANIM_action.hh"
47#include "ANIM_armature.hh"
48#include "ANIM_keyframing.hh"
49#include "ANIM_pose.hh"
50#include "ANIM_rna.hh"
51
52#include "AS_asset_catalog.hh"
54#include "AS_asset_library.hh"
56
57#include "anim_intern.hh"
58
60
62 PointerRNA * /*ptr*/,
63 PropertyRNA * /*prop*/,
64 bool *r_free)
65{
67 /*include_readonly=*/false,
68 /*include_current_file=*/true,
69 /*include_remote_libraries=*/false,
70 /*include_separate_online_essentials=*/false);
71 *r_free = true;
72 BLI_assert(items != nullptr);
73 return items;
74}
75
77{
78 BLI_assert(bone_pointer.type == RNA_PoseBone);
79
80 Vector<RNAPath> paths;
81 paths.append({"location"});
82 paths.append({"scale"});
83 bPoseChannel *pose_bone = static_cast<bPoseChannel *>(bone_pointer.data);
84 switch (pose_bone->rotmode) {
85 case ROT_MODE_QUAT:
86 paths.append({"rotation_quaternion"});
87 break;
89 paths.append({"rotation_axis_angle"});
90 break;
91 case ROT_MODE_XYZ:
92 case ROT_MODE_XZY:
93 case ROT_MODE_YXZ:
94 case ROT_MODE_YZX:
95 case ROT_MODE_ZXY:
96 case ROT_MODE_ZYX:
97 paths.append({"rotation_euler"});
98 default:
99 break;
100 }
101
102 paths.extend({{"bbone_curveinx"},
103 {"bbone_curveoutx"},
104 {"bbone_curveinz"},
105 {"bbone_curveoutz"},
106 {"bbone_rollin"},
107 {"bbone_rollout"},
108 {"bbone_scalein"},
109 {"bbone_scaleout"},
110 {"bbone_easein"},
111 {"bbone_easeout"}});
112
114
115 return paths;
116}
117
118static blender::animrig::Action &extract_pose(Main &bmain, const Span<Object *> pose_objects)
119{
120 /* This currently only looks at the pose and not other things that could go onto different
121 * slots on the same action. */
122
123 using namespace blender::animrig;
125 Action &action = action_add(bmain, "pose_create");
126 Layer &layer = action.layer_add("pose");
127 Strip &strip = layer.strip_add(action, Strip::Type::Keyframe);
128 StripKeyframeData &strip_data = strip.data<StripKeyframeData>(action);
130
131 for (Object *pose_object : pose_objects) {
132 BLI_assert(pose_object->pose);
133 Slot &slot = action.slot_add_for_id(pose_object->id);
134 const bArmature *armature = id_cast<bArmature *>(pose_object->data);
135
136 Set<RNAPath> existing_paths;
137 if (pose_object->adt && pose_object->adt->action &&
138 pose_object->adt->slot_handle != Slot::unassigned)
139 {
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) {
144 RNAPath existing_path = {fcurve.rna_path(), std::nullopt, fcurve.array_index};
145 existing_paths.add(existing_path);
146 });
147 }
148
149 for (bPoseChannel &pose_bone : pose_object->pose->chanbase) {
151 {&pose_bone, pose_bone.bone_get(*pose_object)}))
152 {
153 continue;
154 }
156 &pose_object->id, RNA_PoseBone, &pose_bone);
157 Vector<RNAPath> rna_paths = construct_pose_rna_paths(bone_pointer);
158 for (const RNAPath &rna_path : rna_paths) {
159 PointerRNA resolved_pointer;
160 PropertyRNA *resolved_property;
161 if (!RNA_path_resolve(
162 &bone_pointer, rna_path.path.c_str(), &resolved_pointer, &resolved_property))
163 {
164 continue;
165 }
166 const Vector<float> values = blender::animrig::get_rna_values(&resolved_pointer,
167 resolved_property);
168 const std::optional<std::string> rna_path_id_to_prop = RNA_path_from_ID_to_property(
169 &resolved_pointer, resolved_property);
170 if (!rna_path_id_to_prop.has_value()) {
171 continue;
172 }
173 for (const int i : values.index_range()) {
174 if (RNA_property_is_idprop(resolved_property) &&
175 !existing_paths.contains({rna_path_id_to_prop.value(), std::nullopt, i}))
176 {
177 /* Skipping custom properties without animation. */
178 continue;
179 }
180 strip_data.keyframe_insert(
181 &bmain, slot, {rna_path_id_to_prop.value(), i}, {1, values[i]}, key_settings);
182 }
183 }
184 }
185 }
186 return action;
187}
188
196{
197 ScrArea *current_area = CTX_wm_area(&C);
198 if (!current_area || current_area->type->spaceid != SPACE_VIEW3D) {
199 /* Opening the asset shelf will only work from the 3D viewport. */
200 return;
201 }
202
204 for (wmWindow &win : wm->windows) {
205 const bScreen *screen = WM_window_get_active_screen(&win);
206 for (ScrArea &area : screen->areabase) {
207 if (area.type->spaceid == SPACE_FILE) {
208 SpaceFile *sfile = area.spacedata.first_as<SpaceFile>();
209 if (sfile->browse_mode == FILE_BROWSE_MODE_ASSETS) {
210 /* Asset Browser is open. */
211 return;
212 }
213 continue;
214 }
215 const ARegion *shelf_region = BKE_area_find_region_type(&area, RGN_TYPE_ASSET_SHELF);
216 if (!shelf_region) {
217 continue;
218 }
219 if (shelf_region->runtime->visible) {
220 /* A visible asset shelf was found. */
221 return;
222 }
223 }
224 }
225
226 /* At this point, no asset shelf or asset browser was visible anywhere. */
227 ARegion *shelf_region = BKE_area_find_region_type(current_area, RGN_TYPE_ASSET_SHELF);
228 if (!shelf_region) {
229 return;
230 }
231 shelf_region->flag &= ~RGN_FLAG_HIDDEN;
233}
234
236{
237 Vector<PointerRNA> selected_objects;
238 CTX_data_selected_objects(C, &selected_objects);
239
240 Vector<Object *> selected_pose_objects;
241 for (const PointerRNA &ptr : selected_objects) {
242 Object *object = reinterpret_cast<Object *>(ptr.owner_id);
243 if (!object->pose) {
244 continue;
245 }
246 selected_pose_objects.append(object);
247 }
248
249 Object *active_object = CTX_data_active_object(C);
250 /* The active object may not be selected, it should be added because you can still switch to pose
251 * mode. */
252 if (active_object && active_object->pose && !selected_pose_objects.contains(active_object)) {
253 selected_pose_objects.append(active_object);
254 }
255 return selected_pose_objects;
256}
257
259 wmOperator *op,
260 const StringRefNull name,
261 const AssetLibraryReference lib_ref)
262{
263 Vector<Object *> selected_pose_objects = get_selected_pose_objects(C);
264
265 if (selected_pose_objects.is_empty()) {
266 return OPERATOR_CANCELLED;
267 }
268
269 Main *bmain = CTX_data_main(C);
270 /* Extract the pose into a new action. */
271 blender::animrig::Action &pose_action = extract_pose(*bmain, selected_pose_objects);
272 asset::mark_id(&pose_action.id);
273 if (!G.background) {
274 asset::generate_preview(C, &pose_action.id);
275 }
276 BKE_id_rename(*bmain, pose_action.id, name);
277
278 /* Add asset to catalog. */
279 char catalog_path_c[MAX_NAME];
280 RNA_string_get(op->ptr, "catalog_path", catalog_path_c);
281
282 AssetMetaData &meta_data = *pose_action.id.asset_data;
284 /* NOTE(@ChrisLend): I don't know if a local library can fail to load.
285 * Just being defensive here. */
287 if (catalog_path_c[0] && library) {
288 const asset_system::AssetCatalogPath catalog_path =
291 catalog_path);
292 BKE_asset_metadata_catalog_id_set(&meta_data, catalog.catalog_id, catalog.simple_name.c_str());
293 }
294
297
299
301
302 return OPERATOR_FINISHED;
303}
304
306 wmOperator *op,
307 const char name[MAX_NAME],
308 const AssetLibraryReference lib_ref)
309{
311 Main *bmain = CTX_data_main(C);
312
314 &U, lib_ref.custom_library_index);
315 BLI_assert_msg(user_library, "The passed lib_ref is expected to be a user library");
316 if (!user_library) {
317 return OPERATOR_CANCELLED;
318 }
320 "The passed lib_ref is expected to be an on disk library");
321 if (user_library->flag & ASSET_LIBRARY_USE_REMOTE_URL) {
322 return OPERATOR_CANCELLED;
323 }
324
326 if (!library) {
327 BKE_report(op->reports, RPT_ERROR, "Failed to load asset library");
328 return OPERATOR_CANCELLED;
329 }
330
331 Vector<Object *> selected_pose_objects = get_selected_pose_objects(C);
332
333 if (selected_pose_objects.is_empty()) {
334 return OPERATOR_CANCELLED;
335 }
336
337 /* Temporary action in current main that will be exported and later deleted. */
338 blender::animrig::Action &pose_action = extract_pose(*bmain, selected_pose_objects);
339 asset::mark_id(&pose_action.id);
340 if (!G.background) {
341 asset::generate_preview(C, &pose_action.id);
342 }
343
344 /* Add asset to catalog. */
345 char catalog_path_c[MAX_NAME];
346 RNA_string_get(op->ptr, "catalog_path", catalog_path_c);
347
348 AssetMetaData &meta_data = *pose_action.id.asset_data;
349 if (catalog_path_c[0]) {
350 const asset_system::AssetCatalogPath catalog_path =
353 *library, catalog_path);
354 BKE_asset_metadata_catalog_id_set(&meta_data, catalog.catalog_id, catalog.simple_name.c_str());
355 }
356
357 AssetWeakReference pose_asset_reference;
358 const std::optional<std::string> final_full_asset_filepath = bke::asset_edit_id_save_as(
359 *bmain, pose_action.id, name, *user_library, pose_asset_reference, *op->reports);
360
361 library->catalog_service().write_to_disk(*final_full_asset_filepath);
364
365 BKE_id_free(bmain, &pose_action.id);
366
368
370
371 return OPERATOR_FINISHED;
372}
373
375{
376 char name[MAX_NAME] = "";
377 PropertyRNA *name_prop = RNA_struct_find_property(op->ptr, "pose_name");
378 if (RNA_property_is_set(op->ptr, name_prop)) {
379 RNA_property_string_get(op->ptr, name_prop, name);
380 }
381 if (name[0] == '\0') {
382 BKE_report(op->reports, RPT_ERROR, "No name set");
383 return OPERATOR_CANCELLED;
384 }
385
386 const int enum_value = RNA_enum_get(op->ptr, "asset_library_reference");
388
389 switch (lib_ref.type) {
391 return create_pose_asset_local(C, op, name, lib_ref);
392
394 return create_pose_asset_user_library(C, op, name, lib_ref);
395
396 default:
397 /* Only local and custom libraries should be exposed in the enum. */
399 break;
400 }
401
402 BKE_report(op->reports, RPT_ERROR, "Unexpected library type. Failed to create pose asset");
403
404 return OPERATOR_FINISHED;
405}
406
408 wmOperator *op,
409 const wmEvent * /*event*/)
410{
411 /* If the library isn't saved from the operator's last execution, use the first library. */
412 if (!RNA_struct_property_is_set_ex(op->ptr, "asset_library_reference", false)) {
413 std::optional<AssetLibraryReference> dest_library_ref =
415
416 if (!dest_library_ref) {
417 BKE_report(op->reports, RPT_WARNING, "No editable asset library to save into");
418 return OPERATOR_CANCELLED;
419 }
420 RNA_enum_set(op->ptr,
421 "asset_library_reference",
422 asset::library_reference_to_enum_value(&*dest_library_ref));
423 }
424
425 return WM_operator_props_dialog_popup(C, op, 400, std::nullopt, IFACE_("Create"));
426}
427
429{
431 return false;
432 }
433 return true;
434}
435
437 const bContext *C,
438 PointerRNA *ptr,
439 PropertyRNA * /*prop*/,
440 const char *edit_text,
442{
443 const int enum_value = RNA_enum_get(ptr, "asset_library_reference");
445
447 *CTX_data_main(C), lib_ref, edit_text, visit_fn);
448}
449
451{
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";
456
460
461 ot->prop = RNA_def_string(
462 ot->srna, "pose_name", nullptr, MAX_NAME, "Pose Name", "Name for the new pose asset");
463
464 PropertyRNA *prop = RNA_def_property(ot->srna, "asset_library_reference", PROP_ENUM, PROP_NONE);
467 RNA_def_property_ui_text(prop, "Library", "Asset library used to store the new pose");
468
469 prop = RNA_def_string(
470 ot->srna, "catalog_path", nullptr, MAX_NAME, "Catalog", "Catalog to use for the new asset");
473}
474
481
484 "ADJUST",
485 0,
486 "Adjust",
487 "Update existing channels in the pose asset but don't remove or add any channels"},
489 "REPLACE",
490 0,
491 "Replace with Selection",
492 "Completely replace all channels in the pose asset with the current selection"},
493 {MODIFY_ADD,
494 "ADD",
495 0,
496 "Add Selected Bones",
497 "Add channels of the selection to the pose asset. Existing channels will be updated"},
499 "REMOVE",
500 0,
501 "Remove Selected Bones",
502 "Remove channels of the selection from the pose asset"},
503 {0, nullptr, 0, nullptr, nullptr},
504};
505
517{
519 if (!asset) {
520 return nullptr;
521 }
522
523 if (asset->get_id_type() != ID_AC) {
524 return nullptr;
525 }
526
527 AssetWeakReference asset_reference = asset->make_weak_reference();
528 Main *bmain = CTX_data_main(C);
529 return reinterpret_cast<bAction *>(
530 bke::asset_edit_id_from_weak_reference(*bmain, ID_AC, asset_reference));
531}
532
539static bool is_pose_asset_blend_editable(const bAction &action, ReportList *reports)
540{
541 if (!bke::asset_edit_id_is_editable(action.id)) {
542 BKE_reportf(reports, RPT_ERROR, "Action is not editable");
543 return false;
544 }
545 if (!bke::asset_edit_id_is_writable(action.id)) {
546 BKE_reportf(reports, RPT_ERROR, "Asset blend file is not editable");
547 return false;
548 }
549 return true;
550}
551
558{
559 const asset_system::AssetRepresentation *asset_handle = CTX_wm_asset(C);
560 if (!asset_handle || asset_handle->get_id_type() != ID_AC) {
561 CTX_wm_operator_poll_msg_set(C, "No selected pose asset");
562 return false;
563 }
564 if (asset_handle->is_local_id()) {
565 return true;
566 }
567 if (!asset_handle->is_potentially_editable_asset_blend()) {
568 CTX_wm_operator_poll_msg_set(C, "Asset blend file is not editable");
569 return false;
570 }
571 return true;
572}
573
578
580{
581 Vector<PathValue> path_values;
582 const bArmature *armature = id_cast<bArmature *>(pose_object.data);
583 for (bPoseChannel &pose_bone : pose_object.pose->chanbase) {
585 {&pose_bone, pose_bone.bone_get(pose_object)}))
586 {
587 continue;
588 }
590 &pose_object.id, RNA_PoseBone, &pose_bone);
591 Vector<RNAPath> rna_paths = construct_pose_rna_paths(bone_pointer);
592
593 for (RNAPath &rna_path : rna_paths) {
594 PointerRNA resolved_pointer;
595 PropertyRNA *resolved_property;
596 if (!RNA_path_resolve(
597 &bone_pointer, rna_path.path.c_str(), &resolved_pointer, &resolved_property))
598 {
599 continue;
600 }
601 const std::optional<std::string> rna_path_id_to_prop = RNA_path_from_ID_to_property(
602 &resolved_pointer, resolved_property);
603 if (!rna_path_id_to_prop.has_value()) {
604 continue;
605 }
606 Vector<float> values = blender::animrig::get_rna_values(&resolved_pointer,
607 resolved_property);
608 int i = 0;
609 for (const float value : values) {
610 RNAPath path = {rna_path_id_to_prop.value(), std::nullopt, i};
611 path_values.append({path, value});
612 i++;
613 }
614 }
615 }
616 return path_values;
617}
618
619static inline void replace_pose_key(Main &bmain,
621 const blender::animrig::Slot &slot,
622 const float2 time_value,
623 const blender::animrig::FCurveDescriptor &fcurve_descriptor)
624{
625 using namespace blender::animrig;
626 Channelbag &channelbag = strip_data.channelbag_for_slot_ensure(slot);
627 FCurve &fcurve = channelbag.fcurve_ensure(&bmain, fcurve_descriptor);
628
629 /* Clearing all keys beforehand in case the pose was not defined on frame defined in
630 * `time_value`. */
633 insert_vert_fcurve(&fcurve, time_value, key_settings, INSERTKEY_NOFLAGS);
634}
635
637 blender::animrig::Action &pose_action,
638 Object &pose_object,
639 const AssetModifyMode mode)
640{
641 using namespace blender::animrig;
642 /* The frame on which an FCurve has a key to define a pose. */
643 constexpr int pose_frame = 1;
644 if (pose_action.slot_array_num < 1) {
645 /* All actions should have slots at this point. */
647 return;
648 }
649
650 Slot &slot = blender::animrig::get_best_pose_slot_for_id(pose_object.id, pose_action);
651 BLI_assert(pose_action.strip_keyframe_data().size() == 1);
652 BLI_assert(pose_action.layers().size() == 1);
653 StripKeyframeData *strip_data = pose_action.strip_keyframe_data()[0];
654 Vector<PathValue> path_values = generate_path_values(pose_object);
655
656 Set<RNAPath> existing_paths;
657 foreach_fcurve_in_action_slot(pose_action, slot.handle, [&](const FCurve &fcurve) {
658 existing_paths.add({fcurve.rna_path(), std::nullopt, fcurve.array_index});
659 });
660
661 switch (mode) {
662 case MODIFY_ADJUST: {
663 for (const PathValue &path_value : path_values) {
664 /* Only updating existing channels. */
665 if (existing_paths.contains(path_value.rna_path)) {
666 replace_pose_key(*bmain,
667 *strip_data,
668 slot,
669 {pose_frame, path_value.value},
670 {path_value.rna_path.path, path_value.rna_path.index.value()});
671 }
672 }
673 break;
674 }
675 case MODIFY_ADD: {
676 for (const PathValue &path_value : path_values) {
677 replace_pose_key(*bmain,
678 *strip_data,
679 slot,
680 {pose_frame, path_value.value},
681 {path_value.rna_path.path, path_value.rna_path.index.value()});
682 }
683 break;
684 }
685 case MODIFY_REPLACE: {
686 Channelbag *channelbag = strip_data->channelbag_for_slot(slot.handle);
687 if (!channelbag) {
688 /* No channels to remove. */
689 return;
690 }
691 channelbag->fcurves_clear();
692 for (const PathValue &path_value : path_values) {
693 replace_pose_key(*bmain,
694 *strip_data,
695 slot,
696 {pose_frame, path_value.value},
697 {path_value.rna_path.path, path_value.rna_path.index.value()});
698 }
699 break;
700 }
701 case MODIFY_REMOVE: {
702 Channelbag *channelbag = strip_data->channelbag_for_slot(slot.handle);
703 if (!channelbag) {
704 /* No channels to remove. */
705 return;
706 }
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);
711 });
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);
715 channelbag->fcurve_remove(*fcurve);
716 }
717 }
718 break;
719 }
720 }
721}
722
724{
726 if (!action) {
727 BKE_report(op->reports, RPT_ERROR, "Failed to load pose asset");
728 return OPERATOR_CANCELLED;
729 }
730
731 if (ID_IS_LINKED(action) && !is_pose_asset_blend_editable(*action, op->reports)) {
732 return OPERATOR_CANCELLED;
733 }
734
735 /* Get asset now. Asset browser might get tagged for refreshing through operations below, and not
736 * allow querying items from context until refreshed, see #140781. */
738
739 Main *bmain = CTX_data_main(C);
740 Object *pose_object = CTX_data_active_object(C);
741 if (!pose_object || !pose_object->pose) {
742 return OPERATOR_CANCELLED;
743 }
744
745 AssetModifyMode mode = AssetModifyMode(RNA_enum_get(op->ptr, "mode"));
746 update_pose_action_from_scene(bmain, action->wrap(), *pose_object, mode);
747
748 if (ID_IS_LINKED(action)) {
749 /* Not needed for local assets. */
750 bke::asset_edit_id_save(*bmain, action->id, *op->reports);
751 }
752 else {
753 /* Only create undo-step for local actions. Undoing external files isn't supported. */
754 ED_undo_push_op(C, op);
755 }
756
759
760 return OPERATOR_FINISHED;
761}
762
764{
766 CTX_wm_operator_poll_msg_set(C, "Pose assets can only be modified from Pose Mode");
767 return false;
768 }
770}
771
772static std::string pose_asset_modify_description(bContext * /* C */,
773 wmOperatorType * /* ot */,
774 PointerRNA *ptr)
775{
776 const int mode = RNA_enum_get(ptr, "mode");
777 return TIP_(std::string(prop_asset_overwrite_modes[mode].description));
778}
779
780/* Calling it overwrite instead of save because we aren't actually saving an opened asset. */
782{
783 ot->name = "Modify Pose Asset";
784 ot->description =
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";
788
792
793 RNA_def_enum(ot->srna,
794 "mode",
797 "Overwrite Mode",
798 "Specify which parts of the pose asset are overwritten");
799}
800
802{
804 if (!action) {
805 return OPERATOR_CANCELLED;
806 }
807
809 if (ID_IS_LINKED(action) && !is_pose_asset_blend_editable(*action, op->reports)) {
810 return OPERATOR_CANCELLED;
811 }
812
813 std::optional<AssetLibraryReference> library_ref =
814 asset->owner_asset_library().library_reference();
815
816 if (ID_IS_LINKED(action)) {
818 }
819 else {
820 asset::clear_id(&action->id);
821 /* Only create undo-step for local actions. Undoing external files isn't supported. */
822 ED_undo_push_op(C, op);
823 }
824
825 asset::refresh_asset_library(C, library_ref.value());
826
828
829 return OPERATOR_FINISHED;
830}
831
833 wmOperator *op,
834 const wmEvent * /*event*/)
835{
836 /* Perform some checks that the 'exec' function also does, so that when things aren't editable,
837 * the user gets a message about this *before* having to confirm the deletion. */
839 if (!action) {
840 /* TODO: if this ever happens, figure out how that happened, and see if more
841 * useful information can be included in the report. After all, the poll
842 * function already checks that the active asset exists and is an Action. */
843 BKE_report(op->reports, RPT_ERROR, "Could not load Action for the active asset");
844 return OPERATOR_CANCELLED;
845 }
846
847 if (ID_IS_LINKED(action) && !is_pose_asset_blend_editable(*action, op->reports)) {
848 return OPERATOR_CANCELLED;
849 }
850
852 C,
853 op,
854 IFACE_("Delete Pose Asset"),
855 ID_IS_LINKED(action) ?
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."),
858 IFACE_("Delete"),
860 false);
861}
862
864{
865 ot->name = "Delete Pose Asset";
866 ot->description = "Delete the selected Pose Asset";
867 ot->idname = "POSELIB_OT_asset_delete";
868
872}
873
874} // namespace blender::ed::animrig
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 TIP_(msgid)
#define IFACE_(msgid)
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
#define MAX_NAME
Definition DNA_defs.h:63
#define C
Definition RandGen.cpp:29
#define NA_ADDED
Definition WM_types.hh:636
#define NA_EDITED
Definition WM_types.hh:634
#define NC_ASSET
Definition WM_types.hh:417
#define NA_REMOVED
Definition WM_types.hh:637
#define ND_ASSET_LIST
Definition WM_types.hh:591
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
bool contains(const Key &key) const
Definition BLI_set.hh:310
bool add(const Key &key)
Definition BLI_set.hh:248
bool contains(const T &value) const
void append(const T &value)
bool is_empty() const
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)
#define layer
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)
Definition anim_rna.cc:202
Vector< float > get_rna_values(PointerRNA *ptr, PropertyRNA *prop)
Definition anim_rna.cc:26
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)
Definition pose.cc:471
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)
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ BEZT_KEYTYPE_KEYFRAME
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)
@ RPT_WARNING
Definition BKE_report.hh:40
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)
Definition rna_path.cc:529
@ ASSET_LIBRARY_USE_REMOTE_URL
std::optional< std::string > RNA_path_from_ID_to_property(const PointerRNA *ptr, PropertyRNA *prop)
Definition rna_path.cc:1237
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)
Definition asset.cc:164
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)
Definition ed_undo.cc:553
@ ASSET_LIBRARY_CUSTOM
@ ASSET_LIBRARY_LOCAL
Global G
Definition blender.cc:57
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
Definition RNA_types.hh:883
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
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)
Definition area.cc:2599
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:1024
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
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)
Definition lib_id.cc:2654
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
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
The meta-data of an asset. By creating and giving this for a data-block (ID.asset_data),...
struct AssetMetaData * asset_data
Definition DNA_ID.h:424
struct bPose * pose
StructRNA * type
Definition RNA_types.hh:63
ListBaseT< SpaceLink > spacedata
struct SpaceType * type
eFileBrowse_Mode browse_mode
ListBaseT< bPoseChannel > chanbase
ListBaseT< struct ScrArea > areabase
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
std::string(*) get_description(bContext *C, wmOperatorType *ot, PointerRNA *ptr)
Definition WM_types.hh:1197
struct ReportList * reports