Blender V5.3
asset_ops.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10#include <iostream>
11
12#include <fmt/format.h>
13
14#include "AS_asset_library.hh"
16#include "AS_remote_library.hh"
17
18#include "BKE_asset_edit.hh"
19#include "BKE_blendfile.hh"
20#include "BKE_bpath.hh"
21#include "BKE_context.hh"
22#include "BKE_global.hh"
23#include "BKE_icons.hh"
24#include "BKE_lib_id.hh"
25#include "BKE_main.hh"
26#include "BKE_preferences.h"
27#include "BKE_preview_image.hh"
28#include "BKE_report.hh"
29#include "BKE_screen.hh"
30
31#include "BLI_assert.hh"
32#include "BLI_fnmatch.hh"
33#include "BLI_path_utils.hh"
34#include "BLI_rect.hh"
35#include "BLI_set.hh"
36#include "BLI_string.hh"
37
38#include "ED_asset.hh"
39#include "ED_asset_list.hh"
40#include "ED_screen.hh"
41/* XXX needs access to the file list, should all be done via the asset system in future. */
43#include "ED_fileselect.hh"
44#include "ED_render.hh"
45#include "ED_util.hh"
47
48#include "BLT_translation.hh"
49
50#include "RNA_access.hh"
51#include "RNA_define.hh"
52#include "RNA_prototypes.hh"
53
54#include "IMB_imbuf.hh"
55#include "IMB_thumbs.hh"
56
57#include "RNA_types.hh"
58#include "WM_api.hh"
59
60#include "DNA_space_types.h"
61
62#include "GPU_immediate.hh"
63
64#include "UI_interface_c.hh"
65#include "UI_resources.hh"
66
67namespace blender::ed::asset {
68/* -------------------------------------------------------------------- */
69
74struct IDVecStats {
75 bool has_asset = false;
76 bool has_supported_type = false;
77 bool is_single = false;
78};
79
85{
86 IDVecStats stats;
87
88 stats.is_single = id_pointers.size() == 1;
89
90 for (const PointerRNA &ptr : id_pointers) {
92
93 ID *id = static_cast<ID *>(ptr.data);
94 if (id_type_is_supported(id)) {
95 stats.has_supported_type = true;
96 }
97 if (ID_IS_ASSET(id)) {
98 stats.has_asset = true;
99 }
100 }
101
102 return stats;
103}
104
105static const char *asset_operation_unsupported_type_msg(const bool is_single)
106{
107 const char *msg_single = N_(
108 "Data-block does not support asset operations - must be a "
109 "Brush, Collection, Node Group, Object, Pose Action, Scene, or World");
110 const char *msg_multiple = N_(
111 "No data-block selected that supports asset operations - select at least one "
112 "Brush, Collection, Node Group, Object, Pose Action, Scene, or World");
113 return is_single ? msg_single : msg_multiple;
114}
115
116/* -------------------------------------------------------------------- */
117
119 public:
120 void operator()(const bContext &C, Span<PointerRNA> ids);
121
122 void reportResults(ReportList &reports) const;
123 bool wasSuccessful() const;
124
125 private:
126 struct Stats {
127 int tot_created = 0;
128 int tot_already_asset = 0;
129 ID *last_id = nullptr;
130 };
131
132 Stats stats;
133};
134
136{
137 for (const PointerRNA &ptr : ids) {
138 BLI_assert(RNA_struct_is_ID(ptr.type));
139
140 ID *id = static_cast<ID *>(ptr.data);
141 if (id->asset_data) {
142 stats.tot_already_asset++;
143 continue;
144 }
145
146 if (mark_id(id)) {
147 generate_preview(&C, id);
148
149 stats.last_id = id;
150 stats.tot_created++;
151 }
152 }
153}
154
156{
157 return stats.tot_created > 0;
158}
159
161{
162 /* User feedback on failure. */
163 if (!wasSuccessful()) {
164 if (stats.tot_already_asset > 0) {
165 BKE_report(&reports,
166 RPT_ERROR,
167 "Selected data-blocks are already assets (or do not support use as assets)");
168 }
169 else {
170 BKE_report(&reports,
171 RPT_ERROR,
172 "No data-blocks to create assets for found (or do not support use as assets)");
173 }
174 }
175 /* User feedback on success. */
176 else if (stats.tot_created == 1) {
177 /* If only one data-block: Give more useful message by printing asset name. */
178 BKE_reportf(&reports, RPT_INFO, "Data-block '%s' is now an asset", stats.last_id->name + 2);
179 }
180 else {
181 BKE_reportf(&reports, RPT_INFO, "%i data-blocks are now assets", stats.tot_created);
182 }
183}
184
186 const wmOperator *op,
187 const Span<PointerRNA> ids)
188{
189 AssetMarkHelper mark_helper;
190 mark_helper(*C, ids);
191 mark_helper.reportResults(*op->reports);
192
193 if (!mark_helper.wasSuccessful()) {
194 return OPERATOR_CANCELLED;
195 }
196
199
200 return OPERATOR_FINISHED;
201}
202
204{
206
207 if (!ctx_stats.has_supported_type) {
209 return false;
210 }
211
212 return true;
213}
214
216{
217 ot->name = "Mark as Asset";
218 ot->description =
219 "Enable easier reuse of selected data-blocks through the Asset Browser, with the help of "
220 "customizable metadata (like previews, descriptions and tags)";
221 ot->idname = "ASSET_OT_mark";
222
223 ot->exec = [](bContext *C, wmOperator *op) -> wmOperatorStatus {
225 };
226 ot->poll = [](bContext *C) -> bool {
228 };
229
231}
232
237{
238 ot->name = "Mark as Single Asset";
239 ot->description =
240 "Enable easier reuse of a data-block through the Asset Browser, with the help of "
241 "customizable metadata (like previews, descriptions and tags)";
242 ot->idname = "ASSET_OT_mark_single";
243
244 ot->exec = [](bContext *C, wmOperator *op) -> wmOperatorStatus {
246 };
247 ot->poll = [](bContext *C) -> bool {
249 };
250
252}
253
254/* -------------------------------------------------------------------- */
255
257 const bool set_fake_user_;
258
259 public:
260 AssetClearHelper(const bool set_fake_user) : set_fake_user_(set_fake_user) {}
261
263
264 void reportResults(const bContext *C, ReportList &reports) const;
265 bool wasSuccessful() const;
266
267 private:
268 struct Stats {
269 int tot_cleared = 0;
270 ID *last_id = nullptr;
271 };
272
273 Stats stats;
274};
275
277{
278 for (const PointerRNA &ptr : ids) {
279 BLI_assert(RNA_struct_is_ID(ptr.type));
280
281 ID *id = static_cast<ID *>(ptr.data);
282 if (!id->asset_data) {
283 continue;
284 }
285
286 if (!clear_id(id)) {
287 continue;
288 }
289
290 if (set_fake_user_) {
292 }
293
294 stats.tot_cleared++;
295 stats.last_id = id;
296 }
297}
298
300{
301 if (!wasSuccessful()) {
302 /* Dedicated error message for when there is an active asset detected, but it's not an ID local
303 * to this file. Helps users better understanding what's going on. */
305 !active_asset->is_local_id())
306 {
307 BKE_report(&reports,
308 RPT_ERROR,
309 "No asset data-blocks from the current file selected (assets must be stored in "
310 "the current file to be able to edit or clear them)");
311 }
312 else {
313 BKE_report(&reports, RPT_ERROR, "No asset data-blocks selected/focused");
314 }
315 }
316 else if (stats.tot_cleared == 1) {
317 /* If only one data-block: Give more useful message by printing asset name. */
319 &reports, RPT_INFO, "Data-block '%s' is not an asset anymore", stats.last_id->name + 2);
320 }
321 else {
322 BKE_reportf(&reports, RPT_INFO, "%i data-blocks are not assets anymore", stats.tot_cleared);
323 }
324}
325
327{
328 return stats.tot_cleared > 0;
329}
330
332 const wmOperator *op,
333 const Span<PointerRNA> ids)
334{
335 const bool set_fake_user = RNA_boolean_get(op->ptr, "set_fake_user");
336 AssetClearHelper clear_helper(set_fake_user);
337 clear_helper(ids);
338 clear_helper.reportResults(C, *op->reports);
339
340 if (!clear_helper.wasSuccessful()) {
341 return OPERATOR_CANCELLED;
342 }
343
346
347 return OPERATOR_FINISHED;
348}
349
351{
353
354 if (!ctx_stats.has_asset) {
355 const char *msg_single = N_("Data-block is not marked as asset");
356 const char *msg_multiple = N_("No data-block selected that is marked as asset");
357 CTX_wm_operator_poll_msg_set(C, ctx_stats.is_single ? msg_single : msg_multiple);
358 return false;
359 }
360 if (!ctx_stats.has_supported_type) {
362 return false;
363 }
364
365 return true;
366}
367
368static std::string asset_clear_get_description(bContext * /*C*/,
369 wmOperatorType * /*ot*/,
370 PointerRNA *ptr)
371{
372 const bool set_fake_user = RNA_boolean_get(ptr, "set_fake_user");
373 if (!set_fake_user) {
374 return "";
375 }
376 return TIP_(
377 "Delete all asset metadata, turning the selected asset data-blocks back into normal "
378 "data-blocks, and set Fake User to ensure the data-blocks will still be saved");
379}
380
385{
386 ot->name = "Clear Asset";
387 ot->description =
388 "Delete all asset metadata and turn the selected asset data-blocks back into normal "
389 "data-blocks";
391 ot->idname = "ASSET_OT_clear";
392
393 ot->exec = [](bContext *C, wmOperator *op) -> wmOperatorStatus {
395 };
396 ot->poll = [](bContext *C) -> bool {
398 };
399
401
403 "set_fake_user",
404 false,
405 "Set Fake User",
406 "Ensure the data-block is saved, even when it is no longer marked as asset");
407}
408
410{
411 ot->name = "Clear Single Asset";
412 ot->description =
413 "Delete all asset metadata and turn the asset data-block back into a normal data-block";
415 ot->idname = "ASSET_OT_clear_single";
416
417 ot->exec = [](bContext *C, wmOperator *op) -> wmOperatorStatus {
419 };
420 ot->poll = [](bContext *C) -> bool {
422 };
423
425
427 "set_fake_user",
428 false,
429 "Set Fake User",
430 "Ensure the data-block is saved, even when it is no longer marked as asset");
431}
432
433/* -------------------------------------------------------------------- */
434
436{
438 return true;
439 }
440
441 /* While not inside an Asset Browser, check if there's a asset list stored for the active asset
442 * library (stored in the workspace, obtained via context). */
444 if (!library) {
445 return false;
446 }
447
450}
451
453{
455 /* Handles both global asset list storage and asset browsers. */
458}
459
464
471static std::optional<AssetLibraryAndRef> asset_library_from_context(bContext *C)
472{
473 /* Find the asset library, depending on where we were invoked from. */
477 if (!asset_lib) {
478 return {};
479 }
480 const std::optional<AssetLibraryReference> library_ref = asset_lib->library_reference();
481 if (!library_ref) {
482 return {};
483 }
484
485 return {{asset_lib, *library_ref}};
486 }
487
489 if (!library_ref) {
490 return {};
491 }
493 *library_ref);
494 if (!asset_lib) {
495 return {};
496 }
497
498 return {{asset_lib, *library_ref}};
499}
500
502{
503 /* This is also checked in the poll function, but this exec function is also called from the
504 * generic asset_library_fresh_exec() function, where it is not. */
505 if ((G.f & G_FLAG_INTERNET_ALLOW) == 0) {
506 BKE_report(op->reports, RPT_ERROR, "Online access is disabled in the Preferences");
507 return OPERATOR_CANCELLED;
508 }
509
510 /* Find the asset library, depending on where we were invoked from. */
511 const std::optional<AssetLibraryAndRef> asset_lib_and_ref = asset_library_from_context(C);
512 if (!asset_lib_and_ref ||
513 !asset_system::is_or_contains_remote_libraries(asset_lib_and_ref->reference))
514 {
516 op->reports, RPT_ERROR, "This asset library does not have a remote listing to download");
517 return OPERATOR_CANCELLED;
518 }
519
520 /* Re-download the asset listing on shift-click. */
521 asset_lib_and_ref->library->force_remote_listing_download();
522
523 /* Always end with a regular refresh, as a "forced refresh" like this should be an additional
524 * thing on top of regular refreshing (otherwise it would be weird to use the refresh button for
525 * this). */
527
528 return OPERATOR_FINISHED;
529}
530
532{
533 const std::optional<AssetLibraryAndRef> asset_lib_and_ref = asset_library_from_context(C);
534 if (!asset_lib_and_ref ||
535 !asset_system::is_or_contains_remote_libraries(asset_lib_and_ref->reference))
536 {
537 CTX_wm_operator_poll_msg_set(C, "This is not a remote library");
538 return false;
539 }
540
541 /* Check the flag after checking for the remote library to have an online component.
542 * Because if there is not, then enabling the online access in the preferences
543 * isn't going to do anything. */
544 if ((G.f & G_FLAG_INTERNET_ALLOW) == 0) {
545 CTX_wm_operator_poll_msg_set(C, "Online access is disabled in the Preferences");
546 return false;
547 }
548
549 return true;
550}
551
553{
554 /* identifiers */
555 ot->name = "Reload Remote Asset Library Listing";
556 ot->description =
557 "Re-download the asset listing of a remote library. Only supported when the active "
558 "asset library is remote or has a remote component (the Essentials library)";
559 ot->idname = "ASSET_OT_library_reload_listing";
560
561 /* API callbacks. */
564}
565
567{
568 if (RNA_boolean_get(op->ptr, "use_remote_listing")) {
569 /* Delegate to the ASSET_OT_library_reload_listing operator. */
571 }
572
573 /* Just a plain refresh of the asset browser. */
575 return OPERATOR_FINISHED;
576}
577
579 wmOperator *op,
580 const wmEvent *event)
581{
582 if (event->modifier & KM_SHIFT && RNA_boolean_get(op->ptr, "use_shift_for_remote_listing")) {
583 RNA_boolean_set(op->ptr, "use_remote_listing", true);
584 }
585 return asset_library_refresh_exec(C, op);
586}
587
589 wmOperatorType *ot,
590 PointerRNA *ptr)
591{
592 if (RNA_boolean_get(ptr, "use_remote_listing")) {
593 return "Re-download the asset listing of a remote library. Only supported when the active "
594 "asset library is remote or has a remote component (the Essentials library)";
595 }
596
597 if (RNA_boolean_get(ptr, "use_shift_for_remote_listing")) {
598 return "Reread assets and asset catalogs from the asset library on disk.\n"
599 "Shift-click: re-download the asset listing of a remote library";
600 }
601
602 return ot->description;
603}
604
606{
607 /* identifiers */
608 ot->name = "Refresh Asset Library";
609 ot->description = "Reread assets and asset catalogs from the asset library on disk";
610 ot->idname = "ASSET_OT_library_refresh";
611
612 /* API callbacks. */
617
618 PropertyRNA *prop;
619 prop = RNA_def_boolean(
620 ot->srna,
621 "use_remote_listing",
622 false,
623 "Remote Listing",
624 "Re-download the asset listing of a remote library. Only supported when the active asset "
625 "library is remote or has a remote component (the Essentials library)");
627
628 prop = RNA_def_boolean(ot->srna,
629 "use_shift_for_remote_listing",
630 false,
631 "Use Shift for Remote Listing",
632 "When this operator is invoked and the Shift key is pressed, download "
633 "the remote asset library listing");
635}
636
637/* -------------------------------------------------------------------- */
638
640{
641 const SpaceFile *sfile = CTX_wm_space_file(C);
642 if (!sfile) {
643 return false;
644 }
646 if (!asset_library) {
647 return false;
648 }
649 if (catalogs_read_only(*asset_library)) {
650 CTX_wm_operator_poll_msg_set(C, "Asset catalogs cannot be edited in this asset library");
651 return false;
652 }
653 return true;
654}
655
657{
658 SpaceFile *sfile = CTX_wm_space_file(C);
660 std::string parent_path = RNA_string_get(op->ptr, "parent_path");
661
663 asset_library, DATA_("Catalog"), parent_path);
664
665 if (sfile) {
667 }
668
671
672 return OPERATOR_FINISHED;
673}
674
676{
677 /* identifiers */
678 ot->name = "New Asset Catalog";
679 ot->description = "Create a new catalog to put assets in";
680 ot->idname = "ASSET_OT_catalog_new";
681
682 /* API callbacks. */
685
687 "parent_path",
688 nullptr,
689 0,
690 "Parent Path",
691 "Optional path defining the location to put the new catalog under");
692}
693
695{
696 SpaceFile *sfile = CTX_wm_space_file(C);
698 std::string catalog_id_str = RNA_string_get(op->ptr, "catalog_id");
699 asset_system::CatalogID catalog_id;
700 if (!BLI_uuid_parse_string(&catalog_id, catalog_id_str.c_str())) {
701 return OPERATOR_CANCELLED;
702 }
703
704 catalog_remove(asset_library, catalog_id);
705
708
709 return OPERATOR_FINISHED;
710}
711
713{
714 /* identifiers */
715 ot->name = "Delete Asset Catalog";
716 ot->description =
717 "Remove an asset catalog from the asset library (contained assets will not be affected and "
718 "show up as unassigned)";
719 ot->idname = "ASSET_OT_catalog_delete";
720
721 /* API callbacks. */
724
725 RNA_def_string(ot->srna, "catalog_id", nullptr, 0, "Catalog ID", "ID of the catalog to delete");
726}
727
729{
730 const SpaceFile *sfile = CTX_wm_space_file(C);
731 if (!sfile || ED_fileselect_is_file_browser(sfile)) {
732 return nullptr;
733 }
734
736 if (asset_lib) {
737 return &asset_lib->catalog_service();
738 }
739
740 return nullptr;
741}
742
744{
746 if (!catalog_service) {
747 return OPERATOR_CANCELLED;
748 }
749
750 catalog_service->undo();
752 return OPERATOR_FINISHED;
753}
754
756{
758 return catalog_service && catalog_service->is_undo_possbile();
759}
760
762{
763 /* identifiers */
764 ot->name = "Undo Catalog Edits";
765 ot->description = "Undo the last edit to the asset catalogs";
766 ot->idname = "ASSET_OT_catalog_undo";
767
768 /* API callbacks. */
771}
772
774{
776 if (!catalog_service) {
777 return OPERATOR_CANCELLED;
778 }
779
780 catalog_service->redo();
782 return OPERATOR_FINISHED;
783}
784
786{
788 return catalog_service && catalog_service->is_redo_possbile();
789}
790
792{
793 /* identifiers */
794 ot->name = "Redo Catalog Edits";
795 ot->description = "Redo the last undone edit to the asset catalogs";
796 ot->idname = "ASSET_OT_catalog_redo";
797
798 /* API callbacks. */
801}
802
804{
806 if (!catalog_service) {
807 return OPERATOR_CANCELLED;
808 }
809
810 catalog_service->undo_push();
811 return OPERATOR_FINISHED;
812}
813
815{
816 return get_catalog_service(C) != nullptr;
817}
818
820{
821 /* identifiers */
822 ot->name = "Store undo snapshot for asset catalog edits";
823 ot->description = "Store the current state of the asset catalogs in the undo buffer";
824 ot->idname = "ASSET_OT_catalog_undo_push";
825
826 /* API callbacks. */
829
830 /* Generally artists don't need to find & use this operator, it's meant for scripts only. */
831 ot->flag = OPTYPE_INTERNAL;
832}
833
834/* -------------------------------------------------------------------- */
835
837{
839 return false;
840 }
841
842 const Main *bmain = CTX_data_main(C);
843 if (!bmain->filepath[0]) {
844 CTX_wm_operator_poll_msg_set(C, "Cannot save asset catalogs before the Blender file is saved");
845 return false;
846 }
847
849 CTX_wm_operator_poll_msg_set(C, "No changes to be saved");
850 return false;
851 }
852
853 return true;
854}
855
868
870{
871 /* identifiers */
872 ot->name = "Save Asset Catalogs";
873 ot->description =
874 "Make any edits to any catalogs permanent by writing the current set up to the asset "
875 "library";
876 ot->idname = "ASSET_OT_catalogs_save";
877
878 /* API callbacks. */
881}
882
883/* -------------------------------------------------------------------- */
884
885static bool could_be_asset_bundle(const Main *bmain);
887static bool is_contained_in_selected_asset_library(wmOperator *op, const char *filepath);
888static bool set_filepath_for_asset_lib(const Main *bmain, wmOperator *op);
889static bool has_external_files(Main *bmain, ReportList *reports);
890
892{
893 /* This operator only works when the asset browser is set to Current File. */
894 const SpaceFile *sfile = CTX_wm_space_file(C);
895 if (sfile == nullptr) {
896 return false;
897 }
899 return false;
900 }
901
902 const Main *bmain = CTX_data_main(C);
903 if (!could_be_asset_bundle(bmain)) {
904 return false;
905 }
906
907 /* Check whether this file is already located inside any asset library. */
909 &U, bmain->filepath);
910 if (asset_lib) {
911 return false;
912 }
913
914 return true;
915}
916
918 wmOperator *op,
919 const wmEvent * /*event*/)
920{
921 Main *bmain = CTX_data_main(C);
922 if (has_external_files(bmain, op->reports)) {
923 return OPERATOR_CANCELLED;
924 }
925
927
928 /* Make the "Save As" dialog box default to "${ASSET_LIB_ROOT}/${CURRENT_FILE}.blend". */
929 if (!set_filepath_for_asset_lib(bmain, op)) {
930 return OPERATOR_CANCELLED;
931 }
932
934}
935
937{
938 Main *bmain = CTX_data_main(C);
939 if (has_external_files(bmain, op->reports)) {
940 return OPERATOR_CANCELLED;
941 }
942
943 /* Check file path, copied from #wm_file_write(). */
944 char filepath[FILE_MAX];
945 RNA_string_get(op->ptr, "filepath", filepath);
946 const size_t len = strlen(filepath);
947
948 if (len == 0) {
949 BKE_report(op->reports, RPT_ERROR, "Path is empty, cannot save");
950 return OPERATOR_CANCELLED;
951 }
952
953 if (len >= FILE_MAX) {
954 BKE_report(op->reports, RPT_ERROR, "Path too long, cannot save");
955 return OPERATOR_CANCELLED;
956 }
957
958 /* Check that the destination is actually contained in the selected asset library. */
959 if (!is_contained_in_selected_asset_library(op, filepath)) {
960 BKE_reportf(op->reports, RPT_ERROR, "Selected path is outside of the selected asset library");
961 return OPERATOR_CANCELLED;
962 }
963
964 WM_cursor_wait(true);
966 /* Store undo step, such that on a failed save the 'prepare_to_merge_on_write' call can be
967 * un-done. */
968 cat_service->undo_push();
969 cat_service->prepare_to_merge_on_write();
970
971 const wmOperatorStatus operator_result = WM_operator_name_call(
972 C, "WM_OT_save_mainfile", wm::OpCallContext::ExecDefault, op->ptr, nullptr);
973 WM_cursor_wait(false);
974
975 if (operator_result != OPERATOR_FINISHED) {
976 cat_service->undo();
977 return operator_result;
978 }
979
981 BLI_assert_msg(lib, "If the asset library is not known, how did we get here?");
983 RPT_INFO,
984 R"(Saved "%s" to asset library "%s")",
986 lib->name);
987 return OPERATOR_FINISHED;
988}
989
991 PointerRNA * /*ptr*/,
992 PropertyRNA * /*prop*/,
993 bool *r_free)
994{
996 if (!items) {
997 *r_free = false;
998 return nullptr;
999 }
1000
1001 *r_free = true;
1002 return items;
1003}
1004
1006{
1007 /* identifiers */
1008 ot->name = "Copy to Asset Library";
1009 ot->description =
1010 "Copy the current .blend file into an Asset Library. Only works on standalone .blend files "
1011 "(i.e. when no other files are referenced)";
1012 ot->idname = "ASSET_OT_bundle_install";
1013
1014 /* API callbacks. */
1018
1019 ot->prop = RNA_def_property(ot->srna, "asset_library_reference", PROP_ENUM, PROP_NONE);
1023
1027 FILE_SAVE,
1031}
1032
1033/* Cheap check to see if this is an "asset bundle" just by checking main file name.
1034 * A proper check will be done in the exec function, to ensure that no external files will be
1035 * referenced. */
1036static bool could_be_asset_bundle(const Main *bmain)
1037{
1038 return fnmatch("*_bundle.blend", bmain->filepath, FNM_CASEFOLD) == 0;
1039}
1040
1042{
1043 const int enum_value = RNA_enum_get(op->ptr, "asset_library_reference");
1044 const AssetLibraryReference lib_ref = library_reference_from_enum_value(enum_value);
1046 &U, lib_ref.custom_library_index);
1047 return lib;
1048}
1049
1050static bool is_contained_in_selected_asset_library(wmOperator *op, const char *filepath)
1051{
1053 if (!lib) {
1054 return false;
1055 }
1056 return BLI_path_contains(lib->resolved_dirpath, filepath);
1057}
1058
1063static bool set_filepath_for_asset_lib(const Main *bmain, wmOperator *op)
1064{
1065 /* Find the directory path of the selected asset library. */
1067 if (lib == nullptr) {
1068 return false;
1069 }
1070
1071 /* Concatenate the filename of the current blend file. */
1072 const char *blend_filename = BLI_path_basename(bmain->filepath);
1073 if (blend_filename == nullptr || blend_filename[0] == '\0') {
1074 return false;
1075 }
1076
1077 char file_path[FILE_MAX];
1078 BLI_path_join(file_path, sizeof(file_path), lib->resolved_dirpath, blend_filename);
1079 RNA_string_set(op->ptr, "filepath", file_path);
1080
1081 return true;
1082}
1083
1088
1090 char * /*path_dst*/,
1091 size_t /*path_dst_maxncpy*/,
1092 const char *path_src)
1093{
1094 FileCheckCallbackInfo *callback_info = static_cast<FileCheckCallbackInfo *>(
1095 bpath_data->user_data);
1096 callback_info->external_files.add(std::string(path_src));
1097 return false;
1098}
1099
1107static bool has_external_files(Main *bmain, ReportList *reports)
1108{
1109 FileCheckCallbackInfo callback_info = {reports, Set<std::string>()};
1110
1111 eBPathForeachFlag flag =
1112 (BKE_BPATH_FOREACH_PATH_SKIP_PACKED /* Packed files are fine. */
1113 | BKE_BPATH_FOREACH_PATH_SKIP_MULTIFILE /* Only report multi-files once, it's enough. */
1114 | BKE_BPATH_TRAVERSE_SKIP_WEAK_REFERENCES); /* Only care about actually used files. */
1115
1116 BPathForeachPathData bpath_data = {
1117 /*bmain*/ bmain,
1118 /*callback_function*/ &external_file_check_callback,
1119 /*flag*/ flag,
1120 /*user_data*/ &callback_info,
1121 /*absolute_base_path*/ nullptr,
1122 };
1123 BKE_bpath_foreach_path_main(&bpath_data);
1124
1125 if (callback_info.external_files.is_empty()) {
1126 /* No external dependencies. */
1127 return false;
1128 }
1129
1130 if (callback_info.external_files.size() == 1) {
1131 /* Only one external dependency, report it directly. */
1132 BKE_reportf(callback_info.reports,
1133 RPT_ERROR,
1134 "Unable to copy bundle due to external dependency: \"%s\"",
1135 callback_info.external_files.begin()->c_str());
1136 return true;
1137 }
1138
1139 /* Multiple external dependencies, report the aggregate and put details on console. */
1141 callback_info.reports,
1142 RPT_ERROR,
1143 "Unable to copy bundle due to %zu external dependencies; more details on the console",
1144 size_t(callback_info.external_files.size()));
1145 printf("Unable to copy bundle due to %zu external dependencies:\n",
1146 size_t(callback_info.external_files.size()));
1147 for (const std::string &path : callback_info.external_files) {
1148 printf(" \"%s\"\n", path.c_str());
1149 }
1150 return true;
1151}
1152
1153constexpr int DRAG_THRESHOLD = 4;
1154
1158 /* Screenshot points may not be set immediately to allow for clicking to create a screenshot with
1159 * the previous size. */
1161
1163 /* Dragged far enough to create the screenshot are instead of registering as a click. */
1165 /* Move the whole screenshot area when moving the cursor instead of placing `drag_end`. */
1168};
1169
1170/* Sort points so p1 is lower left, and p2 is top right. */
1171static inline void sort_points(int2 &p1, int2 &p2)
1172{
1173 if (p1.x > p2.x) {
1174 std::swap(p1.x, p2.x);
1175 }
1176 if (p1.y > p2.y) {
1177 std::swap(p1.y, p2.y);
1178 }
1179}
1180
1181/* Clamps the point to the window bounds. */
1182static inline int2 clamp_point_to_window(const int2 &point, const wmWindow *window)
1183{
1184 const int2 win_size = WM_window_native_pixel_size(window);
1185 return {clamp_i(point.x, 0, win_size.x - 1), clamp_i(point.y, 0, win_size.y - 1)};
1186}
1187
1188/* Ensures that the x and y distance to from p1 to p2 is equal and the resulting square remains
1189 * fully within the window bounds. The two points can be in any spacial relation to each other i.e.
1190 * if p1 was top left, it remains top left. */
1191static inline void square_points_clamp_to_window(const int2 &p1, int2 &p2, const wmWindow *window)
1192{
1193 const int2 delta = p2 - p1;
1194
1195 /* Determine the drag direction for each axis. */
1196 const int dir_x = (delta.x >= 0) ? 1 : -1;
1197 const int dir_y = (delta.y >= 0) ? 1 : -1;
1198
1199 const int size_x = std::abs(delta.x);
1200 const int size_y = std::abs(delta.y);
1201 int square_size = std::max(size_x, size_y);
1202
1203 /* Compute maximum size that fits within window bounds in the drag direction. */
1204 const int2 win_size = WM_window_native_pixel_size(window);
1205 const int max_size_x = (dir_x > 0) ? win_size.x - p1.x - 1 : p1.x;
1206 const int max_size_y = (dir_y > 0) ? win_size.y - p1.y - 1 : p1.y;
1207
1208 /* Clamp the square size so it does not exceed window bounds. */
1209 square_size = std::min({square_size, max_size_x, max_size_y});
1210
1211 /* Update p2 to form a clamped square in the same direction as the drag. */
1212 p2.x = p1.x + dir_x * square_size;
1213 p2.y = p1.y + dir_y * square_size;
1214}
1215
1216static void generate_previewimg_from_buffer(ID *id, const ImBuf *image_buffer)
1217{
1218 PreviewImage *preview_image = BKE_previewimg_id_ensure(id);
1219 BKE_previewimg_clear(preview_image);
1220
1221 for (int size_type = 0; size_type < NUM_ICON_SIZES; size_type++) {
1222 BKE_previewimg_ensure(preview_image, size_type);
1223 int width = image_buffer->x;
1224 int height = image_buffer->y;
1225 int max_size = 0;
1226 switch (size_type) {
1227 case ICON_SIZE_ICON:
1228 max_size = ICON_RENDER_DEFAULT_HEIGHT;
1229 break;
1230 case ICON_SIZE_PREVIEW:
1231 max_size = PREVIEW_RENDER_LARGE_HEIGHT;
1232 break;
1233 }
1234 if (max_size == 0) {
1235 /* Can only be reached if a new icon size is added. */
1237 continue;
1238 }
1239
1240 /* Scales down the image to `max_size` while maintaining the
1241 * aspect ratio. */
1242 if (image_buffer->x > image_buffer->y) {
1243 width = max_size;
1244 height = image_buffer->y * (width / float(image_buffer->x));
1245 }
1246 else if (image_buffer->y > image_buffer->x) {
1247 height = max_size;
1248 width = image_buffer->x * (height / float(image_buffer->y));
1249 }
1250 else {
1251 width = height = max_size;
1252 }
1253
1254 ImBuf *scaled_imbuf = IMB_scale_into_new(
1255 image_buffer, width, height, IMBScaleFilter::Nearest, false);
1256 preview_image->rect[size_type] = reinterpret_cast<uint *>(
1257 MEM_dupalloc(scaled_imbuf->byte_data()));
1258 preview_image->w[size_type] = width;
1259 preview_image->h[size_type] = height;
1260 preview_image->flag[size_type] |= PRV_USER_EDITED;
1261 IMB_freeImBuf(scaled_imbuf);
1262 }
1263}
1264
1269static ImBuf *take_screenshot_crop(bContext *C, const rcti &crop_rect)
1270{
1271 int dumprect_size[2];
1272 wmWindow *win = CTX_wm_window(C);
1273 uint8_t *dumprect = WM_window_pixels_read(C, win, dumprect_size);
1274
1275 /* Clamp coordinates to window bounds. */
1276 rcti safe_rect = crop_rect;
1277 safe_rect.xmin = max_ii(0, crop_rect.xmin);
1278 safe_rect.ymin = max_ii(0, crop_rect.ymin);
1279 safe_rect.xmax = min_ii(dumprect_size[0] - 1, crop_rect.xmax);
1280 safe_rect.ymax = min_ii(dumprect_size[1] - 1, crop_rect.ymax);
1281
1282 /* Validate rectangle. */
1283 if (!BLI_rcti_is_valid(&safe_rect)) {
1284 MEM_delete(dumprect);
1285 return nullptr;
1286 }
1287
1288 ImBuf *image_buffer = IMB_allocImBuf(dumprect_size[0], dumprect_size[1], ImBufFlags::Zero);
1289 image_buffer->color_mode = ImColorMode::RGB;
1290 image_buffer->assign_byte_data(dumprect);
1291
1292 IMB_crop(image_buffer,
1293 int2(safe_rect.xmin, safe_rect.ymin),
1294 int2(BLI_rcti_size_x(&safe_rect) + 1, BLI_rcti_size_y(&safe_rect) + 1));
1295 return image_buffer;
1296}
1297
1299{
1300 int2 p1, p2;
1301 wmWindow *win = CTX_wm_window(C);
1302 RNA_int_get_array(op->ptr, "p1", p1);
1303 RNA_int_get_array(op->ptr, "p2", p2);
1304
1305 /* Clamp points to window bounds, so the screenshot area is always valid. */
1306 p1 = clamp_point_to_window(p1, win);
1307 p2 = clamp_point_to_window(p2, win);
1308
1309 /* Squaring has to happen before sorting so the area is squared from the point where
1310 * dragging started. */
1311 if (RNA_boolean_get(op->ptr, "force_square")) {
1312 square_points_clamp_to_window(p1, p2, win);
1313 }
1314
1315 sort_points(p1, p2);
1316
1317 /* The min side is chosen arbitrarily to avoid accidental creations of very small screenshots. */
1318 constexpr int min_side = 16;
1319 if (p2.x - p1.x < min_side || p2.y - p1.y < min_side) {
1321 op->reports, RPT_ERROR, "Screenshot cannot be smaller than %i pixels on a side", min_side);
1322 return OPERATOR_CANCELLED;
1323 }
1324
1325 ImBuf *image_buffer;
1326
1329 /* Special case for taking a screenshot from a 3D viewport. In that case we do an offscreen
1330 * render to support transparency. Render settings are used as currently set up in the viewport
1331 * to comply with WYSIWYG as much as possible. One limitation is that GUI elements will not be
1332 * visible in the render. */
1333 bool render_offscreen = false;
1334 if (area_p1 == area_p2 && area_p1 != nullptr && area_p1->spacetype == SPACE_VIEW3D) {
1335 Scene *scene = CTX_data_scene(C);
1336 View3D *v3d = static_cast<View3D *>(area_p1->spacedata.first_);
1337 /* For #ED_view3d_draw_offscreen_imbuf only EEVEE only produces a good result. See #141732. */
1338 if (eDrawType(v3d->shading.type) == OB_RENDER) {
1339 const char *engine_name = scene->r.engine;
1340 render_offscreen = STR_ELEM(engine_name,
1344 }
1345 else {
1346 render_offscreen = true;
1347 }
1348 }
1349 if (render_offscreen) {
1350 View3D *v3d = static_cast<View3D *>(area_p1->spacedata.first_);
1352 if (!region) {
1353 /* Unlikely to be hit, but just being cautious. */
1355 return OPERATOR_CANCELLED;
1356 }
1357 char err_out[256] = "unknown";
1360 eDrawType(v3d->shading.type),
1361 v3d,
1362 region,
1363 region->winx,
1364 region->winy,
1367 nullptr,
1368 false,
1369 nullptr,
1370 nullptr,
1371 false,
1372 err_out);
1373
1374 /* Convert crop rect into the space relative to the area. */
1375 const rcti crop_rect = {p1.x - area_p1->totrct.xmin,
1376 p2.x - area_p1->totrct.xmin,
1377 p1.y - area_p1->totrct.ymin,
1378 p2.y - area_p1->totrct.ymin};
1379 IMB_crop(image_buffer,
1380 int2(crop_rect.xmin, crop_rect.ymin),
1381 int2(BLI_rcti_size_x(&crop_rect) + 1, BLI_rcti_size_y(&crop_rect) + 1));
1382 }
1383 else {
1384 const rcti crop_rect = {p1.x, p2.x + 1, p1.y, p2.y + 1};
1385 image_buffer = take_screenshot_crop(C, crop_rect);
1386 if (!image_buffer) {
1387 BKE_report(op->reports, RPT_ERROR, "Invalid screenshot area selection");
1388 return OPERATOR_CANCELLED;
1389 }
1390 }
1391
1392 const asset_system::AssetRepresentation *asset_handle = CTX_wm_asset(C);
1393 BLI_assert_msg(asset_handle != nullptr, "This is ensured by poll");
1394 AssetWeakReference asset_reference = asset_handle->make_weak_reference();
1395
1396 Main *bmain = CTX_data_main(C);
1398 *bmain, asset_handle->get_id_type(), asset_reference);
1399 if (id == nullptr) {
1400 BKE_report(op->reports, RPT_ERROR, "Failed to load asset");
1401 IMB_freeImBuf(image_buffer);
1402 return OPERATOR_CANCELLED;
1403 }
1404
1406
1407 generate_previewimg_from_buffer(id, image_buffer);
1408 IMB_freeImBuf(image_buffer);
1409
1411 const bool saved = bke::asset_edit_id_save(*bmain, *id, *op->reports);
1412 if (!saved) {
1413 BKE_report(op->reports, RPT_ERROR, "Saving failed");
1414 }
1415 }
1416
1419
1421
1422 return OPERATOR_FINISHED;
1423}
1424
1425static void screenshot_preview_draw(const wmWindow *window, void *operator_data)
1426{
1427 ScreenshotOperatorData *data = static_cast<ScreenshotOperatorData *>(operator_data);
1428 int2 p1 = data->p1;
1429 int2 p2 = data->p2;
1430
1431 /* Clamp points to window bounds, so the screenshot area is always valid. */
1432 p1 = clamp_point_to_window(p1, window);
1433 p2 = clamp_point_to_window(p2, window);
1434
1435 /* Squaring has to happen before sorting so the area is squared from the point where
1436 * dragging started. */
1437 if (data->force_square) {
1438 square_points_clamp_to_window(p1, p2, window);
1439 }
1440
1441 sort_points(p1, p2);
1442
1443 /* Drawing rect just out of the screenshot area to not capture the box in the picture. */
1444 const rctf screenshot_rect = {
1445 float(p1.x - 1), float(p2.x + 1), float(p1.y - 1), float(p2.y + 1)};
1446
1447 /* Drawing a semi-transparent mask to highlight the area that will be captured. */
1448 float4 mask_color = {1, 1, 1, 0.25};
1449 const int2 win_size = WM_window_native_pixel_size(window);
1450 const rctf mask_rect_bottom = {0, float(win_size.x), 0, screenshot_rect.ymin};
1451 ui::draw_roundbox_aa(&mask_rect_bottom, true, 0, mask_color);
1452 const rctf mask_rect_top = {0, float(win_size.x), screenshot_rect.ymax, float(win_size.y)};
1453 ui::draw_roundbox_aa(&mask_rect_top, true, 0, mask_color);
1454 const rctf mask_rect_left = {
1455 0, screenshot_rect.xmin, screenshot_rect.ymin, screenshot_rect.ymax};
1456 ui::draw_roundbox_aa(&mask_rect_left, true, 0, mask_color);
1457 const rctf mask_rect_right = {
1458 screenshot_rect.xmax, float(win_size.x), screenshot_rect.ymin, screenshot_rect.ymax};
1459 ui::draw_roundbox_aa(&mask_rect_right, true, 0, mask_color);
1460
1461 float4 color;
1463 ui::draw_roundbox_aa(&screenshot_rect, false, 0, color);
1464}
1465
1467{
1468 wmWindow *win = CTX_wm_window(C);
1471 WM_draw_cb_exit(win, data->draw_handle);
1472 MEM_delete(data);
1473 ED_workspace_status_text(C, nullptr);
1474}
1475
1477{
1478 RNA_boolean_set(op->ptr, "force_square", data->force_square);
1479 RNA_int_set_array(op->ptr, "p1", data->p1);
1480 RNA_int_set_array(op->ptr, "p2", data->p2);
1481}
1482
1484{
1485 ARegion *region = CTX_wm_region(C);
1486 wmWindow *win = CTX_wm_window(C);
1488
1489 const int2 screen_space_cursor = {
1490 event->mval[0] + region->winrct.xmin,
1491 event->mval[1] + region->winrct.ymin,
1492 };
1493 switch (event->type) {
1494 case LEFTMOUSE: {
1495 switch (event->val) {
1496 case KM_PRESS:
1497 data->is_mouse_down = true;
1498 data->crossed_threshold = false;
1499 data->drag_start = screen_space_cursor;
1500 break;
1501 case KM_RELEASE:
1502 data->is_mouse_down = false;
1503 data->drag_end = clamp_point_to_window(screen_space_cursor, win);
1507 return OPERATOR_FINISHED;
1508 }
1509 break;
1510 }
1511
1512 case EVT_PADENTER:
1513 case EVT_RETKEY: {
1517 return OPERATOR_FINISHED;
1518 }
1519
1520 case RIGHTMOUSE:
1521 case EVT_ESCKEY: {
1523 CTX_wm_screen(C)->do_draw = true;
1524 return OPERATOR_CANCELLED;
1525 }
1526
1527 case EVT_SPACEKEY: {
1528 switch (event->val) {
1529 case KM_PRESS:
1530 data->shift_area = true;
1531 break;
1532 case KM_RELEASE:
1533 data->shift_area = false;
1534 break;
1535
1536 default:
1537 break;
1538 }
1539 break;
1540 }
1541
1542 case EVT_LEFTSHIFTKEY:
1543 case EVT_RIGHTSHIFTKEY: {
1544 switch (event->val) {
1545 case KM_PRESS:
1546 data->force_square = false;
1547 break;
1548 case KM_RELEASE:
1549 data->force_square = true;
1550 break;
1551
1552 default:
1553 break;
1554 }
1555 break;
1556 }
1557
1558 case MOUSEMOVE: {
1559 if (data->shift_area) {
1560 const int2 delta = screen_space_cursor - data->last_cursor;
1561 const int2 new_p1 = data->p1 + delta;
1562 const int2 new_p2 = data->p2 + delta;
1563
1564 auto is_within_window = [win](const int2 &pt) -> bool {
1565 const int2 win_size = WM_window_native_pixel_size(win);
1566 return pt.x >= 0 && pt.x < win_size.x && pt.y >= 0 && pt.y < win_size.y;
1567 };
1568
1569 /* Apply movement only if the entire rectangle stays within window bounds. */
1570 if (is_within_window(new_p1) && is_within_window(new_p2)) {
1571 data->p1 = new_p1;
1572 data->p2 = new_p2;
1573 }
1574 }
1575 else if (data->is_mouse_down) {
1576 data->drag_end = clamp_point_to_window(screen_space_cursor, win);
1577
1578 if (!data->crossed_threshold) {
1579 const int2 delta = data->drag_end - data->drag_start;
1580 if (std::abs(delta.x) > DRAG_THRESHOLD && std::abs(delta.y) > DRAG_THRESHOLD) {
1581 /* Only set the points once the threshold has been crossed. This allows to just
1582 * click to confirm using a potentially existing screenshot rect. */
1583 data->crossed_threshold = true;
1584 data->p1 = data->drag_start;
1585 }
1586 }
1587
1588 if (data->crossed_threshold) {
1589 data->p2 = data->drag_end;
1590 }
1591 }
1592
1593 CTX_wm_screen(C)->do_draw = true;
1594 data->last_cursor = screen_space_cursor;
1595 break;
1596 }
1597
1598 default:
1599 break;
1600 }
1601
1602 WorkspaceStatus status(C);
1603 if (data->is_mouse_down) {
1604 status.item(IFACE_("Cancel"), ICON_EVENT_ESC, ICON_MOUSE_RMB);
1605 }
1606 else {
1607 status.item(IFACE_("Start"), ICON_MOUSE_LMB_DRAG);
1608 }
1609 status.item(IFACE_("Confirm"), ICON_MOUSE_LMB, ICON_EVENT_RETURN);
1610 status.item(IFACE_("Move"), ICON_EVENT_SPACEKEY);
1611 status.item(IFACE_("Unlock Aspect Ratio"), ICON_EVENT_SHIFT);
1612
1614}
1615
1617 wmOperator *op,
1618 const wmEvent * /* event */)
1619{
1620 wmWindow *win = CTX_wm_window(C);
1622
1626 data->is_mouse_down = false;
1627 RNA_int_get_array(op->ptr, "p1", data->p1);
1628 RNA_int_get_array(op->ptr, "p2", data->p2);
1629 data->last_cursor = data->p1;
1630 data->shift_area = false;
1631 data->crossed_threshold = false;
1632 data->force_square = RNA_boolean_get(op->ptr, "force_square");
1633
1635 CTX_wm_screen(C)->do_draw = true;
1636
1638}
1639
1641{
1642 if (G.background) {
1643 return false;
1644 }
1645
1646 const asset_system::AssetRepresentation *asset_handle = CTX_wm_asset(C);
1647 if (!asset_handle) {
1648 CTX_wm_operator_poll_msg_set(C, "No selected asset");
1649 return false;
1650 }
1651 if (asset_handle->is_local_id()) {
1652 return WM_operator_winactive(C);
1653 }
1654 if (asset_handle->is_potentially_editable_asset_blend()) {
1655 return true;
1656 }
1657
1658 CTX_wm_operator_poll_msg_set(C, "Asset cannot be modified from this file");
1659 return false;
1660}
1661
1663{
1664 /* This should be a generic operator for assets not linked to the pose-library. */
1665
1666 ot->name = "Capture Screenshot Preview";
1667 ot->description = "Capture a screenshot to use as a preview for the selected asset";
1668 ot->idname = "ASSET_OT_screenshot_preview";
1669
1674
1676 "p1",
1677 2,
1678 nullptr,
1679 0,
1680 INT_MAX,
1681 "Point 1",
1682 "First point of the screenshot in screenspace",
1683 0,
1684 3840);
1686 "p2",
1687 2,
1688 nullptr,
1689 0,
1690 INT_MAX,
1691 "Point 2",
1692 "Second point of the screenshot in screenspace",
1693 0,
1694 3840);
1696 "force_square",
1697 true,
1698 "Force Square",
1699 "If enabled, the screenshot will have the same height as width");
1700}
1701
1702/* -------------------------------------------------------------------- */
1703
1705 const bContext *C)
1706{
1707 /* Convert RNA pointers to their data. */
1708 Vector<PointerRNA> asset_pointers = CTX_data_collection_get(C, "selected_assets");
1710 for (int i : asset_pointers.index_range()) {
1711 assets[i] = static_cast<asset_system::AssetRepresentation *>(asset_pointers[i].data);
1712 }
1713
1714 if (!assets.is_empty()) {
1715 /* There were selected assets, so return those. */
1716 return assets;
1717 }
1718
1719 /* No selected assets, so return the active asset. */
1720 if (const asset_system::AssetRepresentation *active_asset = CTX_wm_asset(C)) {
1721 assets.append(active_asset);
1722 }
1723
1724 return assets;
1725}
1726
1728{
1729 if ((G.f & G_FLAG_INTERNET_ALLOW) == 0) {
1731 C, "Internet access is disabled (can be enabled in the Preferences, System tab)");
1732 return false;
1733 }
1734
1735#ifndef WITH_PYTHON
1736 UNUSED_VARS(C);
1737 CTX_wm_operator_poll_msg_set(C, "Asset downloading requires Python");
1738 return false;
1739#endif
1740
1741 return true;
1742}
1743
1745{
1747 return false;
1748 }
1749
1751 if (assets.is_empty()) {
1752 CTX_wm_operator_poll_msg_set(C, "No asset selected or active");
1753 return false;
1754 }
1755
1756 const bool has_downloadable_asset = [&]() {
1757 for (const asset_system::AssetRepresentation *asset : assets) {
1758 if (asset->needs_download()) {
1759 return true;
1760 }
1761 }
1762 return false;
1763 }();
1764
1765 if (!has_downloadable_asset) {
1766 CTX_wm_operator_poll_msg_set(C, "None of the selected assets requires downloading");
1767 return false;
1768 }
1769
1770 return true;
1771}
1772
1774{
1776
1777 for (const asset_system::AssetRepresentation *asset : assets) {
1778 if (asset->needs_download()) {
1780 }
1781 }
1782
1783 return OPERATOR_FINISHED;
1784}
1785
1787{
1788 /* identifiers */
1789 ot->name = "Download Assets";
1790 ot->description = "Download the selected asset(s)";
1791 ot->idname = "ASSET_OT_assets_download";
1792
1793 /* API callbacks. */
1796}
1797
1798/* -------------------------------------------------------------------- */
1799
1801{
1804
1805 if (!asset) {
1806 const std::string asset_relpath = RNA_string_get(op->ptr, "relative_asset_identifier");
1807 BKE_reportf(op->reports,
1808 RPT_ERROR,
1809 "Asset could not be found (relative identifier: '%s')",
1810 asset_relpath.c_str());
1811 return OPERATOR_CANCELLED;
1812 }
1813
1814 if (!asset->needs_download()) {
1816 op->reports, RPT_ERROR, "Asset '%s' doesn't need downloading", asset->get_name().c_str());
1817 return OPERATOR_CANCELLED;
1818 }
1820
1821 return OPERATOR_FINISHED;
1822}
1823
1829{
1830 /* identifiers */
1831 ot->name = "Download Asset";
1832 ot->description = "Make the asset available without internet access";
1833 ot->idname = "ASSET_OT_asset_download";
1834
1835 /* API callbacks. */
1838
1840}
1841
1842/* -------------------------------------------------------------------- */
1843
1845{
1846 const asset_system::AssetRepresentation *asset_handle = CTX_wm_asset(C);
1847 if (!asset_handle) {
1848 CTX_wm_operator_poll_msg_set(C, "No selected asset.");
1849 return false;
1850 }
1851 if (asset_handle->is_local_id()) {
1852 CTX_wm_operator_poll_msg_set(C, "Asset is local to this file and can be renamed directly.");
1853 return false;
1854 }
1855 if (!asset_handle->is_potentially_editable_asset_blend()) {
1856 CTX_wm_operator_poll_msg_set(C, "Asset cannot be modified from this file.");
1857 return false;
1858 }
1859
1860 return true;
1861}
1862
1864{
1865 Main *bmain = CTX_data_main(C);
1866
1867 /* Get the asset. */
1870 const AssetWeakReference asset_reference = asset->make_weak_reference();
1871
1873 *bmain, asset->get_id_type(), asset_reference);
1874 if (asset_id == nullptr) {
1875 BKE_report(op->reports, RPT_ERROR, "Failed to load asset");
1876 return OPERATOR_CANCELLED;
1877 }
1878
1879 const bUserAssetLibrary *user_asset_lib = asset->owner_asset_library().user_asset_library();
1880 if (!user_asset_lib) {
1881 /* Editable .asset.blend files can only come from an asset library with a bUserAssetLibrary. */
1883 return OPERATOR_CANCELLED;
1884 }
1885
1886 /* Rename the asset. */
1887 const std::string new_name = RNA_string_get(op->ptr, "new_name");
1888 if (!bke::asset_edit_id_rename(*bmain, *asset_id, new_name, *user_asset_lib, *op->reports)) {
1889 return OPERATOR_CANCELLED;
1890 }
1891
1892 std::optional<AssetLibraryReference> asset_lib_ref =
1893 asset->owner_asset_library().library_reference();
1894 if (asset_lib_ref) {
1895 asset::list::clear(&*asset_lib_ref, C);
1896 }
1898 return OPERATOR_FINISHED;
1899}
1900
1902 wmOperator *op,
1903 const wmEvent * /*event*/)
1904{
1906 RNA_string_set(op->ptr, "new_name", asset->get_name().c_str());
1907 return WM_operator_props_dialog_popup(C, op, 400, std::nullopt, IFACE_("Rename Asset"));
1908}
1909
1914{
1915 /* identifiers */
1916 ot->name = "Rename Asset";
1917 ot->description =
1918 "Change the name of this asset. Note that this cannot be un-done via the undo system";
1919 ot->idname = "ASSET_OT_external_asset_rename";
1920
1921 /* No UNDO possible, as it may rename an external file. */
1922 ot->flag = OPTYPE_REGISTER;
1923
1924 /* API callbacks. */
1928
1929 RNA_def_string(ot->srna, "new_name", nullptr, 0, "New Name", "");
1930}
1931
1932/* -------------------------------------------------------------------- */
1933
1959
1960} // namespace blender::ed::asset
Main runtime representation of an asset.
#define ICON_RENDER_DEFAULT_HEIGHT
Definition BKE_icons.hh:185
#define FILE_MAX
#define BLI_path_join(...)
#define STR_ELEM(...)
#define TIP_(msgid)
#define IFACE_(msgid)
#define DATA_(msgid)
#define ID_IS_ASSET(_id)
Definition DNA_ID.h:743
#define SPACE_TYPE_ANY
#define PREVIEW_RENDER_LARGE_HEIGHT
Definition IMB_thumbs.hh:77
#define C
Definition RandGen.cpp:29
#define ND_ASSET_LIST_READING
Definition WM_types.hh:593
#define NC_ID
Definition WM_types.hh:408
#define ND_SPACE_ASSET_PARAMS
Definition WM_types.hh:568
#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 ND_ASSET_CATALOGS
Definition WM_types.hh:599
#define NC_SPACE
Definition WM_types.hh:405
#define BLI_assert_unreachable()
#define UNUSED_VARS(...)
#define BLI_assert_msg(a, msg)
int size_type
SIMD_FORCE_INLINE btVector3 operator()(const btVector3 &x) const
Return the transform of the vector.
Definition btTransform.h:90
Iterator begin() const
Definition BLI_set.hh:499
int64_t size() const
Definition BLI_set.hh:606
bool add(const Key &key)
Definition BLI_set.hh:248
bool is_empty() const
Definition BLI_set.hh:614
constexpr int64_t size() const
Definition BLI_span.hh:256
int64_t size() const
void append(const T &value)
bool is_empty() const
IndexRange index_range() const
void item(std::string text, int icon1, int icon2=0)
Definition area.cc:1076
AssetCatalogService & catalog_service() const
virtual std::optional< AssetLibraryReference > library_reference() const =0
void reportResults(const bContext *C, ReportList &reports) const
Definition asset_ops.cc:299
void operator()(Span< PointerRNA > ids)
Definition asset_ops.cc:276
AssetClearHelper(const bool set_fake_user)
Definition asset_ops.cc:260
void operator()(const bContext &C, Span< PointerRNA > ids)
Definition asset_ops.cc:135
void reportResults(ReportList &reports) const
Definition asset_ops.cc:160
#define INT_MAX
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
bool is_or_contains_remote_libraries(const AssetLibraryReference &reference)
void remote_library_request_asset_download(const bContext &C, const AssetRepresentation &asset, ReportList *reports)
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)
bool asset_edit_id_rename(Main &global_main, ID &id, StringRefNull new_name, const bUserAssetLibrary &user_library, ReportList &reports)
bool asset_edit_id_is_writable(const ID &id)
bool has_asset_browser_storage_for_library(const AssetLibraryReference *library_reference, const bContext *C)
asset_system::AssetLibrary * library_get_once_available(const AssetLibraryReference &library_reference)
void clear(const AssetLibraryReference *library_reference, const bContext *C)
bool has_list_storage_for_library(const AssetLibraryReference *library_reference)
static bool asset_catalogs_save_poll(bContext *C)
Definition asset_ops.cc:836
static bool could_be_asset_bundle(const Main *bmain)
void catalog_remove(asset_system::AssetLibrary *library, const asset_system::CatalogID &catalog_id)
static void generate_previewimg_from_buffer(ID *id, const ImBuf *image_buffer)
bool catalogs_read_only(const asset_system::AssetLibrary &library)
static bool asset_catalog_undo_push_poll(bContext *C)
Definition asset_ops.cc:814
static std::optional< AssetLibraryAndRef > asset_library_from_context(bContext *C)
Definition asset_ops.cc:471
static bool external_file_check_callback(BPathForeachPathData *bpath_data, char *, size_t, const char *path_src)
static void ASSET_OT_clear(wmOperatorType *ot)
Definition asset_ops.cc:384
static wmOperatorStatus asset_catalogs_save_exec(bContext *C, wmOperator *)
Definition asset_ops.cc:856
void catalogs_save_from_main_path(asset_system::AssetLibrary *library, const Main *bmain)
static void ASSET_OT_catalog_redo(wmOperatorType *ot)
Definition asset_ops.cc:791
static bool external_asset_rename_poll(bContext *C)
AssetLibraryReference library_reference_from_enum_value(int value)
static std::string asset_clear_get_description(bContext *, wmOperatorType *, PointerRNA *ptr)
Definition asset_ops.cc:368
static void ASSET_OT_catalog_new(wmOperatorType *ot)
Definition asset_ops.cc:675
static bool asset_catalog_redo_poll(bContext *C)
Definition asset_ops.cc:785
static void ASSET_OT_clear_single(wmOperatorType *ot)
Definition asset_ops.cc:409
static void ASSET_OT_catalog_delete(wmOperatorType *ot)
Definition asset_ops.cc:712
static bool assets_download_poll(bContext *C)
static wmOperatorStatus asset_bundle_install_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition asset_ops.cc:917
static IDVecStats asset_operation_get_id_vec_stats_from_ids(const Span< PointerRNA > id_pointers)
Definition asset_ops.cc:84
asset_system::AssetCatalog * catalog_add(asset_system::AssetLibrary *library, StringRefNull name, StringRef parent_path=nullptr)
static void ASSET_OT_mark_single(wmOperatorType *ot)
Definition asset_ops.cc:236
static bool is_contained_in_selected_asset_library(wmOperator *op, const char *filepath)
static wmOperatorStatus asset_library_refresh_exec(bContext *C, wmOperator *op)
Definition asset_ops.cc:566
void operator_asset_reference_props_register(StructRNA &srna)
static wmOperatorStatus asset_library_reload_listing_exec(bContext *C, wmOperator *op)
Definition asset_ops.cc:501
static bool asset_clear_poll(bContext *C, const Span< PointerRNA > ids)
Definition asset_ops.cc:350
static int2 clamp_point_to_window(const int2 &point, const wmWindow *window)
static wmOperatorStatus asset_catalog_new_exec(bContext *C, wmOperator *op)
Definition asset_ops.cc:656
static bool asset_bundle_install_poll(bContext *C)
Definition asset_ops.cc:891
static wmOperatorStatus asset_download_exec(bContext *C, wmOperator *op)
static wmOperatorStatus asset_library_refresh_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition asset_ops.cc:578
static void screenshot_preview_draw(const wmWindow *window, void *operator_data)
const EnumPropertyItem * custom_libraries_rna_enum_itemf()
static void ASSET_OT_catalog_undo_push(wmOperatorType *ot)
Definition asset_ops.cc:819
static bool set_filepath_for_asset_lib(const Main *bmain, wmOperator *op)
static wmOperatorStatus screenshot_preview_exec(bContext *C, wmOperator *op)
static void ASSET_OT_assets_download(wmOperatorType *ot)
static wmOperatorStatus asset_catalog_redo_exec(bContext *C, wmOperator *)
Definition asset_ops.cc:773
static ImBuf * take_screenshot_crop(bContext *C, const rcti &crop_rect)
static wmOperatorStatus external_asset_rename_invoke(bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus screenshot_preview_modal(bContext *C, wmOperator *op, const wmEvent *event)
static void ASSET_OT_external_asset_rename(wmOperatorType *ot)
void generate_preview(const bContext *C, ID *id)
static Vector< const asset_system::AssetRepresentation * > selected_or_active_assets(const bContext *C)
constexpr int DRAG_THRESHOLD
static void ASSET_OT_bundle_install(wmOperatorType *ot)
static bool screenshot_preview_poll(bContext *C)
static const char * asset_operation_unsupported_type_msg(const bool is_single)
Definition asset_ops.cc:105
static bool asset_catalog_undo_poll(bContext *C)
Definition asset_ops.cc:755
const asset_system::AssetRepresentation * operator_asset_reference_props_get_asset_from_all_library(const bContext &C, PointerRNA &ptr, ReportList *reports)
static void screenshot_preview_exit(bContext *C, wmOperator *op)
static bool asset_mark_poll(bContext *C, const Span< PointerRNA > ids)
Definition asset_ops.cc:203
static void ASSET_OT_mark(wmOperatorType *ot)
Definition asset_ops.cc:215
static wmOperatorStatus asset_catalog_delete_exec(bContext *C, wmOperator *op)
Definition asset_ops.cc:694
static void ASSET_OT_catalog_undo(wmOperatorType *ot)
Definition asset_ops.cc:761
void refresh_asset_library_from_asset(const bContext *C, const asset_system::AssetRepresentation &asset)
static std::string asset_library_refresh_get_description(bContext *, wmOperatorType *ot, PointerRNA *ptr)
Definition asset_ops.cc:588
static bool asset_library_refresh_poll(bContext *C)
Definition asset_ops.cc:435
static asset_system::AssetCatalogService * get_catalog_service(bContext *C)
Definition asset_ops.cc:728
static void ASSET_OT_screenshot_preview(wmOperatorType *ot)
static void sort_points(int2 &p1, int2 &p2)
static wmOperatorStatus external_asset_rename_exec(bContext *C, wmOperator *op)
static wmOperatorStatus asset_catalog_undo_exec(bContext *C, wmOperator *)
Definition asset_ops.cc:743
static void do_asset_library_refresh(bContext *C)
Definition asset_ops.cc:452
static wmOperatorStatus screenshot_preview_invoke(bContext *C, wmOperator *op, const wmEvent *)
static void square_points_clamp_to_window(const int2 &p1, int2 &p2, const wmWindow *window)
static const bUserAssetLibrary * selected_asset_library(wmOperator *op)
static wmOperatorStatus asset_clear_exec(const bContext *C, const wmOperator *op, const Span< PointerRNA > ids)
Definition asset_ops.cc:331
static wmOperatorStatus asset_bundle_install_exec(bContext *C, wmOperator *op)
Definition asset_ops.cc:936
static wmOperatorStatus assets_download_exec(bContext *C, wmOperator *op)
static void screenshot_area_transfer_to_rna(wmOperator *op, ScreenshotOperatorData *data)
static bool assets_download_any_poll(bContext *C)
static void ASSET_OT_asset_download(wmOperatorType *ot)
static wmOperatorStatus asset_mark_exec(const bContext *C, const wmOperator *op, const Span< PointerRNA > ids)
Definition asset_ops.cc:185
static void ASSET_OT_library_refresh(wmOperatorType *ot)
Definition asset_ops.cc:605
bool id_type_is_supported(const ID *id)
Definition asset_type.cc:26
static bool asset_library_reload_listing_poll(bContext *C)
Definition asset_ops.cc:531
static void ASSET_OT_catalogs_save(wmOperatorType *ot)
Definition asset_ops.cc:869
static bool has_external_files(Main *bmain, ReportList *reports)
static wmOperatorStatus asset_catalog_undo_push_exec(bContext *C, wmOperator *)
Definition asset_ops.cc:803
static void ASSET_OT_library_reload_listing(wmOperatorType *ot)
Definition asset_ops.cc:552
static const EnumPropertyItem * rna_asset_library_reference_itemf(bContext *, PointerRNA *, PropertyRNA *, bool *r_free)
Definition asset_ops.cc:990
static bool asset_catalog_operator_poll(bContext *C)
Definition asset_ops.cc:639
void get_color_4fv(int colorid, float col[4])
void draw_roundbox_aa(const rctf *rect, bool filled, float rad, const float color[4])
void WM_main_add_notifier(uint type, void *reference)
UserDef U
Definition blender.cc:58
bool BLI_rcti_is_valid(const struct rcti *rect)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
Vector< PointerRNA > CTX_data_collection_get(const bContext *C, const char *member)
ImBuf * ED_view3d_draw_offscreen_imbuf(Depsgraph *depsgraph, Scene *scene, eDrawType drawtype, View3D *v3d, ARegion *region, int sizex, int sizey, ImBufFlags imbuf_flag, int alpha_mode, const char *viewname, bool restore_rv3d_mats, GPUOffScreen *ofs, GPUViewport *viewport, bool use_camera_view_bounds, char err_out[256])
int RNA_enum_get(PointerRNA *ptr, const char *name)
void ED_preview_kill_jobs_for_id(wmWindowManager *wm, const ID *id)
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 BKE_previewimg_clear(PreviewImage *prv)
void WM_event_add_notifier_ex(wmWindowManager *wm, const wmWindow *win, uint type, void *reference)
@ NUM_ICON_SIZES
@ ICON_SIZE_ICON
@ ICON_SIZE_PREVIEW
void RNA_def_property_enum_default(PropertyRNA *prop, int value)
unsigned int uint
Definition BKE_text.h:55
class asset_system::AssetRepresentation * CTX_wm_asset(const bContext *C)
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
void BKE_bpath_foreach_path_main(BPathForeachPathData *bpath_data)
Definition bpath.cc:121
void WM_cursor_modal_set(wmWindow *win, int val)
struct bUserAssetLibrary * BKE_preferences_asset_library_find_index(const struct UserDef *userdef, int index) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
wmWindow * CTX_wm_window(const bContext *C)
bool AS_asset_library_has_any_unsaved_catalogs()
uint8_t * WM_window_pixels_read(bContext *C, wmWindow *win, int r_size[2])
Definition wm_draw.cc:1575
MINLINE int max_ii(int a, int b)
bool ED_operator_asset_browsing_active(bContext *C)
void id_fake_user_set(ID *id)
Definition lib_id.cc:471
@ ASSET_LIBRARY_LOCAL
const char * RE_engine_id_BLENDER_WORKBENCH
Definition scene.cc:1719
void WM_operator_properties_filesel(wmOperatorType *ot, const int filter, const short type, const eFileSel_Action action, const eFileSel_Flag flag, const short display, const short sort)
void IMB_crop(ImBuf *ibuf, const int2 &rect_pos, const int2 &rect_size)
Definition rectop.cc:470
Vector< PointerRNA > ED_operator_get_ids_from_context_as_vec(const bContext *C)
void ED_fileselect_activate_asset_catalog(const SpaceFile *sfile, bUUID catalog_id)
Definition filesel.cc:519
const char * RE_engine_id_BLENDER_EEVEE
Definition scene.cc:1717
Global G
Definition blender.cc:57
VecBase< float, 4 > float4
void WM_draw_cb_exit(wmWindow *win, void *handle)
Definition wm_draw.cc:652
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier_c_str, int type, int subtype)
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.hh:207
void RNA_int_set_array(PointerRNA *ptr, const char *name, const int *values)
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
void IMB_freeImBuf(ImBuf *ibuf)
VecBase< int32_t, 2 > int2
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
BMesh const char void * data
void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values)
@ WM_FILESEL_FILEPATH
Definition WM_api.hh:1332
wmWindowManager * CTX_wm_manager(const bContext *C)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
unsigned char uint8_t
Definition BKE_text.h:79
PreviewImage * BKE_previewimg_id_ensure(ID *id)
void WM_cursor_modal_restore(wmWindow *win)
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)
wmOperatorStatus WM_operator_name_call(bContext *C, const char *opstring, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.hh:203
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
bool RNA_struct_is_ID(const StructRNA *type)
ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, ImBufFlags flags)
bool ED_fileselect_is_file_browser(const SpaceFile *sfile)
Definition filesel.cc:481
ScrArea * ED_area_find_under_cursor(const bContext *C, int spacetype, const int event_xy[2])
Definition area.cc:4456
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:1024
eBPathForeachFlag
Definition BKE_bpath.hh:39
@ BKE_BPATH_FOREACH_PATH_SKIP_PACKED
Definition BKE_bpath.hh:49
@ BKE_BPATH_FOREACH_PATH_SKIP_MULTIFILE
Definition BKE_bpath.hh:76
@ BKE_BPATH_TRAVERSE_SKIP_WEAK_REFERENCES
Definition BKE_bpath.hh:62
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
bool BLI_uuid_parse_string(bUUID *uuid, const char *buffer) ATTR_NONNULL()
Definition uuid.cc:105
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
@ FILE_SAVE
Definition WM_api.hh:1342
@ WM_CURSOR_CROSS
Definition wm_cursors.hh:28
bool WM_operator_winactive(bContext *C)
@ G_FLAG_INTERNET_ALLOW
Main * CTX_data_main(const bContext *C)
int2 WM_window_native_pixel_size(const wmWindow *win)
asset_system::AssetLibrary * ED_fileselect_active_asset_library_get(const SpaceFile *sfile)
Definition filesel.cc:491
bool BLI_path_contains(const char *container_path, const char *containee_path) ATTR_NONNULL(1
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
PropertyRNA * RNA_def_int_array(StructOrFunctionRNA *cont_, const char *identifier, const int len, const int *default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
@ KM_RELEASE
Definition WM_types.hh:325
void BKE_previewimg_ensure(PreviewImage *prv, int size)
SpaceFile * CTX_wm_space_file(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
bScreen * CTX_wm_screen(const bContext *C)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_INTERNAL
Definition WM_types.hh:210
std::string RNA_string_get(PointerRNA *ptr, const char *name)
@ PRV_USER_EDITED
Definition DNA_ID.h:620
const char * RE_engine_id_BLENDER_EEVEE_NEXT
Definition scene.cc:1718
void * WM_draw_cb_activate(wmWindow *win, void(*draw)(const wmWindow *win, void *customdata), void *customdata)
Definition wm_draw.cc:639
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
bool ED_fileselect_is_local_asset_library(const SpaceFile *sfile)
Definition filesel.cc:421
ImBuf * IMB_scale_into_new(const ImBuf *ibuf, int2 new_size, IMBScaleFilter filter, bool threaded=true)
Definition scaling.cc:531
void WM_cursor_wait(bool val)
MINLINE int min_ii(int a, int b)
MINLINE int clamp_i(int value, int min, int max)
Vector< PointerRNA > ED_operator_single_id_from_context_as_vec(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
void ED_workspace_status_text(bContext *C, const char *str)
Definition area.cc:1153
void WM_event_add_fileselect(bContext *C, wmOperator *op)
struct bUserAssetLibrary * BKE_preferences_asset_library_containing_path(const struct UserDef *userdef, const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
const AssetLibraryReference * CTX_wm_asset_library_ref(const bContext *C)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
const uint8_t * byte_data() const
ImColorMode color_mode
void assign_byte_data(uint8_t *data)
char filepath[1024]
Definition BKE_main.hh:267
unsigned int w[2]
Definition DNA_ID.h:645
unsigned int * rect[2]
Definition DNA_ID.h:649
unsigned int h[2]
Definition DNA_ID.h:646
struct RenderData r
ListBaseT< SpaceLink > spacedata
View3DShading shading
const asset_system::AssetLibrary * library
Definition asset_ops.cc:461
wmEventType type
Definition WM_types.hh:817
wmEventModifierFlag modifier
Definition WM_types.hh:834
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
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
std::string(*) get_description(bContext *C, wmOperatorType *ot, PointerRNA *ptr)
Definition WM_types.hh:1197
struct ReportList * reports
#define N_(msgid)