Blender V5.3
rna_asset.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 <cstdlib>
10
11#include "BLI_path_utils.hh"
12#include "BLT_translation.hh"
13
14#include "RNA_define.hh"
15#include "RNA_enum_types.hh"
16
17#include "DNA_asset_types.h"
18#include "DNA_defs.h"
19
20#include "rna_internal.hh"
21
22namespace blender {
23
26 "ALL",
27 0,
28 "All Libraries",
29 "Show assets from all of the listed asset libraries"},
31 "LOCAL",
32 0,
33 "Current File",
34 "Show the assets currently available in this Blender session"},
36 "ESSENTIALS",
37 0,
38 "Essentials",
39 "Show basic building blocks and utilities coming with Blender"},
41 "ONLINE_ESSENTIALS",
42 0,
43 "Online Essentials",
44 "Show additional building blocks and utilities available online"},
46 "CUSTOM",
47 0,
48 "Custom",
49 "Show assets from the asset libraries configured in the Preferences"},
50 {0, nullptr, 0, nullptr, nullptr},
51};
52
53/* Note that these identifiers are written to the asset index, see #asset_indexer.cc. */
55 {ASSET_IMPORT_LINK, "LINK", ICON_LINK_BLEND, "Link", "Import the assets as linked data-block"},
57 "APPEND",
58 ICON_APPEND_BLEND,
59 "Append",
60 "Import the assets as copied data-block, with no link to the original asset data-block"},
62 "APPEND_REUSE",
63 ICON_APPEND_BLEND,
64 "Append (Reuse Data)",
65 "Import the assets as copied data-block while avoiding multiple copies of nested, "
66 "typically heavy data. For example the textures of a material asset, or the mesh of an "
67 "object asset, don't have to be copied every time this asset is imported. The instances of "
68 "the asset share the data instead."},
70 "PACK",
71 ICON_PACKAGE,
72 "Pack",
73 "Import the asset as linked data-block, and pack it in the current file (ensures that it "
74 "remains unchanged in case the library data is modified, is not available anymore, etc.)"},
75 {0, nullptr, 0, nullptr, nullptr},
76};
77
78} // namespace blender
79
80#ifdef RNA_RUNTIME
81
82# include <algorithm>
83# include <fmt/format.h>
84
85# include "AS_asset_library.hh"
88
89# include "BKE_asset.hh"
90# include "BKE_context.hh"
91# include "BKE_preferences.h"
92# include "BKE_report.hh"
93
94# include "BLI_listbase.hh"
95# include "BLI_string.hh"
96# include "BLI_uuid.hh"
97
98# include "ED_asset.hh"
99# include "ED_fileselect.hh"
100
101# include "RNA_access.hh"
102
103namespace blender {
104
105using namespace asset_system;
106
107static std::optional<std::string> rna_AssetMetaData_path(const PointerRNA * /*ptr*/)
108{
109 return "asset_data";
110}
111
112static bool rna_AssetMetaData_editable_from_owner_id(const ID *owner_id,
113 const AssetMetaData *asset_data,
114 const char **r_info)
115{
116 if (owner_id && asset_data && (owner_id->asset_data == asset_data)) {
117 return true;
118 }
119
120 if (r_info) {
121 *r_info = N_(
122 "Asset metadata from external libraries cannot be edited. Only assets stored in the "
123 "current file can be edited.");
124 }
125 return false;
126}
127
128int rna_AssetMetaData_editable(const PointerRNA *ptr, const char **r_info)
129{
130 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
131
132 return rna_AssetMetaData_editable_from_owner_id(ptr->owner_id, asset_data, r_info) ?
134 PropertyFlag(0);
135}
136
137static std::optional<std::string> rna_AssetTag_path(const PointerRNA *ptr)
138{
139 const AssetTag *asset_tag = static_cast<const AssetTag *>(ptr->data);
140 char asset_tag_name_esc[sizeof(asset_tag->name) * 2];
141 BLI_str_escape(asset_tag_name_esc, asset_tag->name, sizeof(asset_tag_name_esc));
142 return fmt::format("asset_data.tags[\"{}\"]", asset_tag_name_esc);
143}
144
145static int rna_AssetTag_editable(const PointerRNA *ptr, const char **r_info)
146{
147 AssetTag *asset_tag = static_cast<AssetTag *>(ptr->data);
148 ID *owner_id = ptr->owner_id;
149 if (owner_id && owner_id->asset_data) {
150 BLI_assert_msg(BLI_findindex(&owner_id->asset_data->tags, asset_tag) != -1,
151 "The owner of the asset tag pointer is not the asset ID containing the tag");
152 UNUSED_VARS_NDEBUG(asset_tag);
153 }
154
155 return rna_AssetMetaData_editable_from_owner_id(
156 ptr->owner_id, owner_id ? owner_id->asset_data : nullptr, r_info) ?
158 PropertyFlag(0);
159}
160
161static AssetTag *rna_AssetMetaData_tag_new(
162 ID *id, AssetMetaData *asset_data, ReportList *reports, const char *name, bool skip_if_exists)
163{
164 const char *disabled_info = nullptr;
165 if (!rna_AssetMetaData_editable_from_owner_id(id, asset_data, &disabled_info)) {
166 BKE_report(reports, RPT_WARNING, disabled_info);
167 return nullptr;
168 }
169
170 AssetTag *tag = nullptr;
171
172 if (skip_if_exists) {
174
175 if (!result.is_new) {
177 reports, RPT_WARNING, "Tag '%s' already present for given asset", result.tag->name);
178 /* Report, but still return valid item. */
179 }
180 tag = result.tag;
181 }
182 else {
183 tag = BKE_asset_metadata_tag_add(asset_data, name);
184 }
185
186 return tag;
187}
188
189static void rna_AssetMetaData_tag_remove(ID *id,
190 AssetMetaData *asset_data,
191 ReportList *reports,
192 PointerRNA *tag_ptr)
193{
194 const char *disabled_info = nullptr;
195 if (!rna_AssetMetaData_editable_from_owner_id(id, asset_data, &disabled_info)) {
196 BKE_report(reports, RPT_WARNING, disabled_info);
197 return;
198 }
199
200 AssetTag *tag = static_cast<AssetTag *>(tag_ptr->data);
201 if (BLI_findindex(&asset_data->tags, tag) == -1) {
202 BKE_reportf(reports, RPT_ERROR, "Tag '%s' not found in given asset", tag->name);
203 return;
204 }
205
206 BKE_asset_metadata_tag_remove(asset_data, tag);
207 tag_ptr->invalidate();
208}
209
210static IDProperty **rna_AssetMetaData_idprops(PointerRNA *ptr)
211{
212 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
213 return &asset_data->properties;
214}
215
216static void rna_AssetMetaData_author_get(PointerRNA *ptr, char *value)
217{
218 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
219
220 if (asset_data->author) {
221 strcpy(value, asset_data->author);
222 }
223 else {
224 value[0] = '\0';
225 }
226}
227
228static int rna_AssetMetaData_author_length(PointerRNA *ptr)
229{
230 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
231 return asset_data->author ? strlen(asset_data->author) : 0;
232}
233
234static void rna_AssetMetaData_author_set(PointerRNA *ptr, const char *value)
235{
236 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
237
238 if (asset_data->author) {
239 MEM_delete(asset_data->author);
240 }
241
242 if (value[0]) {
243 asset_data->author = BLI_strdup(value);
244 }
245 else {
246 asset_data->author = nullptr;
247 }
248}
249
250static void rna_AssetMetaData_description_get(PointerRNA *ptr, char *value)
251{
252 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
253
254 if (asset_data->description) {
255 strcpy(value, asset_data->description);
256 }
257 else {
258 value[0] = '\0';
259 }
260}
261
262static int rna_AssetMetaData_description_length(PointerRNA *ptr)
263{
264 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
265 return asset_data->description ? strlen(asset_data->description) : 0;
266}
267
268static void rna_AssetMetaData_description_set(PointerRNA *ptr, const char *value)
269{
270 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
271
272 if (asset_data->description) {
273 MEM_delete(asset_data->description);
274 }
275
276 if (value[0]) {
277 asset_data->description = BLI_strdup(value);
278 }
279 else {
280 asset_data->description = nullptr;
281 }
282}
283
284static void rna_AssetMetaData_copyright_get(PointerRNA *ptr, char *value)
285{
286 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
287
288 if (asset_data->copyright) {
289 strcpy(value, asset_data->copyright);
290 }
291 else {
292 value[0] = '\0';
293 }
294}
295
296static int rna_AssetMetaData_copyright_length(PointerRNA *ptr)
297{
298 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
299 return asset_data->copyright ? strlen(asset_data->copyright) : 0;
300}
301
302static void rna_AssetMetaData_copyright_set(PointerRNA *ptr, const char *value)
303{
304 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
305
306 if (asset_data->copyright) {
307 MEM_delete(asset_data->copyright);
308 }
309
310 if (value[0]) {
311 asset_data->copyright = BLI_strdup(value);
312 }
313 else {
314 asset_data->copyright = nullptr;
315 }
316}
317
318static void rna_AssetMetaData_license_get(PointerRNA *ptr, char *value)
319{
320 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
321
322 if (asset_data->license) {
323 strcpy(value, asset_data->license);
324 }
325 else {
326 value[0] = '\0';
327 }
328}
329
330static int rna_AssetMetaData_license_length(PointerRNA *ptr)
331{
332 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
333 return asset_data->license ? strlen(asset_data->license) : 0;
334}
335
336static void rna_AssetMetaData_license_set(PointerRNA *ptr, const char *value)
337{
338 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
339
340 if (asset_data->license) {
341 MEM_delete(asset_data->license);
342 }
343
344 if (value[0]) {
345 asset_data->license = BLI_strdup(value);
346 }
347 else {
348 asset_data->license = nullptr;
349 }
350}
351
352static void rna_AssetMetaData_active_tag_range(
353 PointerRNA *ptr, int *min, int *max, int *softmin, int *softmax)
354{
355 const AssetMetaData *asset_data = static_cast<const AssetMetaData *>(ptr->data);
356 *min = *softmin = 0;
357 *max = *softmax = std::max(int(asset_data->tot_tags - 1), 0);
358}
359
360static void rna_AssetMetaData_catalog_id_get(PointerRNA *ptr, char *value)
361{
362 const AssetMetaData *asset_data = static_cast<const AssetMetaData *>(ptr->data);
363 BLI_uuid_format(value, asset_data->catalog_id);
364}
365
366static int rna_AssetMetaData_catalog_id_length(PointerRNA * /*ptr*/)
367{
368 return UUID_STRING_SIZE - 1;
369}
370
371static void rna_AssetMetaData_catalog_id_set(PointerRNA *ptr, const char *value)
372{
373 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
374 bUUID new_uuid;
375
376 if (value[0] == '\0') {
378 return;
379 }
380
381 if (!BLI_uuid_parse_string(&new_uuid, value)) {
382 /* TODO(@sybren): raise ValueError exception once that's possible from an RNA setter. */
383 printf("UUID %s not formatted correctly, ignoring new value\n", value);
384 return;
385 }
386
387 /* This just sets the new UUID and clears the catalog simple name. The actual
388 * catalog simple name will be updated by some update function, as it
389 * needs the asset library from the context. */
390 /* TODO(Sybren): write that update function. */
391 BKE_asset_metadata_catalog_id_set(asset_data, new_uuid, "");
392}
393
394void rna_AssetMetaData_catalog_id_update(bContext *C, PointerRNA *ptr)
395{
396 SpaceFile *sfile = CTX_wm_space_file(C);
397 if (sfile == nullptr) {
398 /* Until there is a proper Asset Service available, it's only possible to get the asset library
399 * from within the asset browser context. */
400 return;
401 }
402
404 if (asset_library == nullptr) {
405 /* The SpaceFile may not be an asset browser but a regular file browser. */
406 return;
407 }
408
409 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
410 asset_library->refresh_catalog_simplename(asset_data);
411}
412
413static const EnumPropertyItem *rna_AssetMetaData_preferred_import_method_itemf(
414 bContext * /*C*/, PointerRNA * /*ptr*/, PropertyRNA * /*prop*/, bool *r_free)
415{
416 EnumPropertyItem *items = nullptr;
417 int items_num = 0;
418 for (const EnumPropertyItem *item = rna_enum_asset_import_method_items; item->identifier; item++)
419 {
420 switch (eAssetImportMethod(item->value)) {
422 if (U.experimental.no_data_block_packing) {
423 RNA_enum_item_add(&items, &items_num, item);
424 }
425 break;
426 }
427 case ASSET_IMPORT_PACK: {
428 if (!U.experimental.no_data_block_packing) {
429 RNA_enum_item_add(&items, &items_num, item);
430 }
431 break;
432 }
433 default: {
434 RNA_enum_item_add(&items, &items_num, item);
435 break;
436 }
437 }
438 }
439 RNA_enum_item_end(&items, &items_num);
440 *r_free = true;
441 return items;
442}
443
444int rna_AssetMetaData_preferred_import_method_default(PointerRNA * /*ptr*/, PropertyRNA * /*prop*/)
445{
446 return U.experimental.no_data_block_packing ? ASSET_IMPORT_APPEND_REUSE : ASSET_IMPORT_PACK;
447}
448
449static int rna_AssetLibrary_type_get(PointerRNA *ptr)
450{
451 asset_system::AssetLibrary *asset_library = static_cast<asset_system::AssetLibrary *>(ptr->data);
452 return asset_library->library_type();
453}
454
455static bool rna_AssetLibrary_is_editable_get(PointerRNA *ptr)
456{
457 asset_system::AssetLibrary *asset_library = static_cast<asset_system::AssetLibrary *>(ptr->data);
458 return !asset_library->is_read_only();
459}
460
461static PointerRNA rna_AssetLibrary_user_library_get(PointerRNA *ptr)
462{
463 const asset_system::AssetLibrary *asset_library = static_cast<asset_system::AssetLibrary *>(
464 ptr->data);
465 const std::optional<AssetLibraryReference> library_ref = asset_library->library_reference();
466 if (!library_ref || (library_ref->type != ASSET_LIBRARY_CUSTOM)) {
467 return {};
468 }
470 &U, library_ref->custom_library_index);
471 return RNA_pointer_create_discrete(nullptr, RNA_UserAssetLibrary, user_library);
472}
473
474static const char *rna_AssetLibrary_online_assets_url()
475{
477}
478
479static const char *rna_AssetLibrary_online_assets_cache_path()
480{
482}
483
484static void rna_AssetRepresentation_name_get(PointerRNA *ptr, char *value)
485{
486 const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
487 const StringRefNull name = asset->get_name();
488 BLI_strncpy(value, name.c_str(), name.size() + 1);
489}
490
491static int rna_AssetRepresentation_name_length(PointerRNA *ptr)
492{
493 const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
494 const StringRefNull name = asset->get_name();
495 return name.size();
496}
497
498static PointerRNA rna_AssetRepresentation_owner_asset_library_get(PointerRNA *ptr)
499{
500 AssetRepresentation *asset = static_cast<AssetRepresentation *>(ptr->data);
501 return RNA_pointer_create_discrete(nullptr, RNA_AssetLibrary, &asset->owner_asset_library());
502}
503
504static PointerRNA rna_AssetRepresentation_metadata_get(PointerRNA *ptr)
505{
506 const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
507
508 AssetMetaData &asset_data = asset->get_metadata();
509
510 /* Note that for local ID assets, the asset metadata is owned by the ID. Let the pointer inherit
511 * accordingly, so that the #PointerRNA.owner_id is set to the ID, and the metadata can be
512 * recognized as editable. */
513
514 if (asset->is_local_id()) {
515 PointerRNA id_ptr = RNA_id_pointer_create(asset->local_id());
516 return RNA_pointer_create_with_parent(id_ptr, RNA_AssetMetaData, &asset_data);
517 }
518
519 return RNA_pointer_create_with_parent(*ptr, RNA_AssetMetaData, &asset_data);
520}
521
522static int rna_AssetRepresentation_id_type_get(PointerRNA *ptr)
523{
524 const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
525 return asset->get_id_type();
526}
527
528static PointerRNA rna_AssetRepresentation_local_id_get(PointerRNA *ptr)
529{
530 const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
531 return RNA_id_pointer_create(asset->local_id());
532}
533
534static void rna_AssetRepresentation_full_library_path_get(PointerRNA *ptr, char *value)
535{
536 const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
537 const std::string full_library_path = asset->full_library_path();
538 BLI_strncpy(value, full_library_path.c_str(), full_library_path.size() + 1);
539}
540
541static int rna_AssetRepresentation_full_library_path_length(PointerRNA *ptr)
542{
543 const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
544 const std::string full_library_path = asset->full_library_path();
545 return full_library_path.size();
546}
547
548static void rna_AssetRepresentation_full_path_get(PointerRNA *ptr, char *value)
549{
550 const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
551 const std::string full_path = asset->full_path();
552 BLI_strncpy(value, full_path.c_str(), full_path.size() + 1);
553}
554
555static int rna_AssetRepresentation_full_path_length(PointerRNA *ptr)
556{
557 const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
558 const std::string full_path = asset->full_path();
559 return full_path.size();
560}
561
562static bool rna_AssetRepresentation_is_online_get(PointerRNA *ptr)
563{
564 const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
565 return asset->is_online_only();
566}
567
569 PointerRNA * /*ptr*/,
570 PropertyRNA * /*prop*/,
571 bool *r_free)
572{
574 /* Include all valid libraries for the user to choose from. */
575 /*include_readonly=*/true,
576 /*include_current_file=*/true,
577 /*include_remote_libraries=*/true,
578 /*include_separate_online_essentials=*/false);
579 if (!items) {
580 *r_free = false;
582 }
583 *r_free = true;
584 return items;
585}
586
587} // namespace blender
588
589#else
590
591namespace blender {
592
594{
595 StructRNA *srna;
596 PropertyRNA *prop;
597
598 srna = RNA_def_struct(brna, "AssetTag", nullptr);
599 RNA_def_struct_path_func(srna, "rna_AssetTag_path");
600 RNA_def_struct_ui_text(srna, "Asset Tag", "User defined tag (name token)");
601
602 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
603 RNA_def_property_editable_func(prop, "rna_AssetTag_editable");
605 RNA_def_property_ui_text(prop, "Name", "The identifier that makes up this tag");
607}
608
610{
611 StructRNA *srna;
612
613 FunctionRNA *func;
614 PropertyRNA *parm;
615
616 RNA_def_property_srna(cprop, "AssetTags");
617 srna = RNA_def_struct(brna, "AssetTags", nullptr);
618 RNA_def_struct_sdna(srna, "AssetMetaData");
619 RNA_def_struct_ui_text(srna, "Asset Tags", "Collection of custom asset tags");
620
621 /* Tag collection */
622 func = RNA_def_function(srna, "new", "rna_AssetMetaData_tag_new");
623 RNA_def_function_ui_description(func, "Add a new tag to this asset");
625 parm = RNA_def_string(func, "name", nullptr, MAX_NAME, "Name", "");
627 parm = RNA_def_boolean(func,
628 "skip_if_exists",
629 false,
630 "Skip if Exists",
631 "Do not add a new tag if one of the same type already exists");
632 /* return type */
633 parm = RNA_def_pointer(func, "tag", "AssetTag", "", "New tag");
634 RNA_def_function_return(func, parm);
635
636 func = RNA_def_function(srna, "remove", "rna_AssetMetaData_tag_remove");
637 RNA_def_function_ui_description(func, "Remove an existing tag from this asset");
639 /* tag to remove */
640 parm = RNA_def_pointer(func, "tag", "AssetTag", "", "Removed tag");
643}
644
646{
647 StructRNA *srna;
648 PropertyRNA *prop;
649
650 srna = RNA_def_struct(brna, "AssetMetaData", nullptr);
651 RNA_def_struct_path_func(srna, "rna_AssetMetaData_path");
652 RNA_def_struct_ui_text(srna, "Asset Data", "Additional data stored for an asset data-block");
653 // RNA_def_struct_ui_icon(srna, ICON_ASSET); /* TODO: Icon doesn't exist! */
654 /* The struct has custom properties, but no pointer properties to other IDs! */
655 /* FIXME: These need to remain 'user-defined' properties for now, as they are _not_ accessible
656 * through RNA system.
657 * Current situation is not great, as these idprops are technically system-defined (users have no
658 * access/control over them), yet they behave as user-defined ones.
659 * Ultimately it's a similar issue as with the 'Node Modifier' - though not sure the same
660 * solution (actually using RNA access to them) would be desired here?. */
661 RNA_def_struct_idprops_func(srna, "rna_AssetMetaData_idprops");
663
664 prop = RNA_def_property(srna, "author", PROP_STRING, PROP_NONE);
665 RNA_def_property_editable_func(prop, "rna_AssetMetaData_editable");
667 "rna_AssetMetaData_author_get",
668 "rna_AssetMetaData_author_length",
669 "rna_AssetMetaData_author_set");
670 RNA_def_property_ui_text(prop, "Author", "Name of the creator of the asset");
671
672 prop = RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
673 RNA_def_property_editable_func(prop, "rna_AssetMetaData_editable");
675 "rna_AssetMetaData_description_get",
676 "rna_AssetMetaData_description_length",
677 "rna_AssetMetaData_description_set");
679 prop, "Description", "A description of the asset to be displayed for the user");
680
681 prop = RNA_def_property(srna, "copyright", PROP_STRING, PROP_NONE);
682 RNA_def_property_editable_func(prop, "rna_AssetMetaData_editable");
684 "rna_AssetMetaData_copyright_get",
685 "rna_AssetMetaData_copyright_length",
686 "rna_AssetMetaData_copyright_set");
688 prop,
689 "Copyright",
690 "Copyright notice for this asset. An empty copyright notice does not necessarily indicate "
691 "that this is copyright-free. Contact the author if any clarification is needed.");
692
693 prop = RNA_def_property(srna, "license", PROP_STRING, PROP_NONE);
694 RNA_def_property_editable_func(prop, "rna_AssetMetaData_editable");
696 "rna_AssetMetaData_license_get",
697 "rna_AssetMetaData_license_length",
698 "rna_AssetMetaData_license_set");
700 "License",
701 "The type of license this asset is distributed under. An empty license "
702 "name does not necessarily indicate that this is free of licensing "
703 "terms. Contact the author if any clarification is needed.");
704
705 prop = RNA_def_property(srna, "tags", PROP_COLLECTION, PROP_NONE);
706 RNA_def_property_struct_type(prop, "AssetTag");
707 RNA_def_property_editable_func(prop, "rna_AssetMetaData_editable");
709 "Tags",
710 "Custom tags (name tokens) for the asset, used for filtering and "
711 "general asset management");
712 rna_def_asset_tags_api(brna, prop);
713
714 prop = RNA_def_property(srna, "active_tag", PROP_INT, PROP_NONE);
715 RNA_def_property_int_funcs(prop, nullptr, nullptr, "rna_AssetMetaData_active_tag_range");
716 RNA_def_property_ui_text(prop, "Active Tag", "Index of the tag set for editing");
717
718 prop = RNA_def_property(srna, "catalog_id", PROP_STRING, PROP_NONE);
720 "rna_AssetMetaData_catalog_id_get",
721 "rna_AssetMetaData_catalog_id_length",
722 "rna_AssetMetaData_catalog_id_set");
724 RNA_def_property_update(prop, 0, "rna_AssetMetaData_catalog_id_update");
726 "Catalog UUID",
727 "Identifier for the asset's catalog, used by Blender to look up the "
728 "asset's catalog path. Must be a UUID according to RFC4122.");
729
730 prop = RNA_def_property(srna, "catalog_simple_name", PROP_STRING, PROP_NONE);
733 "Catalog Simple Name",
734 "Simple name of the asset's catalog, for debugging and "
735 "data recovery purposes");
736
737 prop = RNA_def_property(srna, "use_preferred_import_method", PROP_BOOLEAN, PROP_BOOLEAN);
739 RNA_def_property_editable_func(prop, "rna_AssetMetaData_editable");
741 prop,
742 "Use Preferred Import Method",
743 "When \"Follow Asset or Preferences\" is selected for the import "
744 "method in the Asset Browser, use the preferred import method of this asset");
745
746 prop = RNA_def_property(srna, "preferred_import_method", PROP_ENUM, PROP_NONE);
749 prop, nullptr, nullptr, "rna_AssetMetaData_preferred_import_method_itemf");
750 RNA_def_property_enum_default_func(prop, "rna_AssetMetaData_preferred_import_method_default");
751 RNA_def_property_editable_func(prop, "rna_AssetMetaData_editable");
753 "Default Import Method",
754 /* TODO */
755 "");
756}
757
759{
760 StructRNA *srna;
761 PropertyRNA *prop;
762
763 srna = RNA_def_struct(brna, "AssetRepresentation", nullptr);
765 "Asset Representation",
766 "Information about an entity that makes it possible for the asset system "
767 "to deal with the entity as asset");
768
769 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_FILENAME);
772 prop, "rna_AssetRepresentation_name_get", "rna_AssetRepresentation_name_length", nullptr);
773 RNA_def_property_ui_text(prop, "Name", "");
775
776 prop = RNA_def_property(srna, "owner_asset_library", PROP_POINTER, PROP_NONE);
777 RNA_def_property_struct_type(prop, "AssetLibrary");
779 prop, "rna_AssetRepresentation_owner_asset_library_get", nullptr, nullptr, nullptr);
780 RNA_def_property_ui_text(prop, "Owner Asset Library", "The asset library containing this asset");
781
782 prop = RNA_def_property(srna, "metadata", PROP_POINTER, PROP_NONE);
783 RNA_def_property_struct_type(prop, "AssetMetaData");
785 prop, "rna_AssetRepresentation_metadata_get", nullptr, nullptr, nullptr);
786 RNA_def_property_ui_text(prop, "Asset Metadata", "Additional information about the asset");
787
788 prop = RNA_def_property(srna, "id_type", PROP_ENUM, PROP_NONE);
790 RNA_def_property_enum_funcs(prop, "rna_AssetRepresentation_id_type_get", nullptr, nullptr);
793 prop,
794 "Data-block Type",
795 /* Won't ever actually return 'NONE' currently, this is just for information for once non-ID
796 * assets are supported. */
797 "The type of the data-block, if the asset represents one ('NONE' otherwise)");
799
800 prop = RNA_def_property(srna, "local_id", PROP_POINTER, PROP_NONE);
803 prop, "rna_AssetRepresentation_local_id_get", nullptr, nullptr, nullptr);
805 "",
806 "The local data-block this asset represents; only valid if that is a "
807 "data-block in this file");
808
809 prop = RNA_def_property(srna, "full_library_path", PROP_STRING, PROP_FILENAME);
812 "rna_AssetRepresentation_full_library_path_get",
813 "rna_AssetRepresentation_full_library_path_length",
814 nullptr);
815
817 prop, "Full Library Path", "Absolute path to the .blend file containing this asset");
818
819 prop = RNA_def_property(srna, "full_path", PROP_STRING, PROP_FILENAME);
822 "rna_AssetRepresentation_full_path_get",
823 "rna_AssetRepresentation_full_path_length",
824 nullptr);
825
827 prop,
828 "Full Path",
829 "Absolute path to the .blend file containing this asset extended with the path "
830 "of the asset inside the file");
831
832 prop = RNA_def_property(srna, "is_online", PROP_BOOLEAN, PROP_BOOLEAN);
834 RNA_def_property_boolean_funcs(prop, "rna_AssetRepresentation_is_online_get", nullptr);
836 prop, "Is Online", "True if this asset is accessed via internet, not stored on disk");
837}
838
840{
841 StructRNA *srna = RNA_def_struct(brna, "AssetLibraryReference", nullptr);
843 srna, "Asset Library Reference", "Identifier to refer to the asset library");
844}
845
847{
848 StructRNA *srna = RNA_def_struct(brna, "AssetLibrary", nullptr);
849 RNA_def_struct_ui_text(srna, "Asset Library", "Container for asset catalogs and assets");
850
851 PropertyRNA *prop;
852
853 prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
855 RNA_def_property_enum_funcs(prop, "rna_AssetLibrary_type_get", nullptr, nullptr);
857 RNA_def_property_ui_text(prop, "Library Type", "");
858
859 prop = RNA_def_property(srna, "is_editable", PROP_BOOLEAN, PROP_NONE);
860 RNA_def_property_boolean_funcs(prop, "rna_AssetLibrary_is_editable_get", nullptr);
863 prop,
864 "Is Editable",
865 "Assets and catalogs in this library can be edited from the current Blender instance");
866
867 prop = RNA_def_property(srna, "user_library", PROP_POINTER, PROP_NONE);
868 RNA_def_property_struct_type(prop, "UserAssetLibrary");
871 prop, "rna_AssetLibrary_user_library_get", nullptr, nullptr, nullptr);
873 prop, "User Library", "The preferences entry defining this library, if there is one");
874
875 FunctionRNA *func;
876 PropertyRNA *parm;
877
878 func = RNA_def_function(srna, "online_assets_url", "rna_AssetLibrary_online_assets_url");
880 parm = RNA_def_string(
881 func, "url", nullptr, 0, "URL", "Remote location of the Online Essentials library");
882 RNA_def_function_return(func, parm);
883
884 func = RNA_def_function(
885 srna, "online_assets_cache_path", "rna_AssetLibrary_online_assets_cache_path");
887 parm = RNA_def_string(func,
888 "path",
889 nullptr,
890 0,
891 "Path",
892 "Local location of the Online Essentials library's disk cache");
893 RNA_def_function_return(func, parm);
894}
895
897 const char *get,
898 const char *set)
899{
900 PropertyRNA *prop = RNA_def_property(srna, "asset_library_reference", PROP_ENUM, PROP_NONE);
902 RNA_def_property_enum_funcs(prop, get, set, "rna_asset_library_ui_reference_itemf");
903
904 return prop;
905}
906
908{
909 StructRNA *srna;
910 PropertyRNA *prop;
911
912 srna = RNA_def_struct(brna, "AssetWeakReference", nullptr);
913 RNA_def_struct_ui_text(srna, "Asset Weak Reference", "Weak reference to some asset");
914
915 prop = RNA_def_property(srna, "asset_library_type", PROP_ENUM, PROP_NONE);
918
919 prop = RNA_def_property(srna, "asset_library_identifier", PROP_STRING, PROP_NONE);
921
922 prop = RNA_def_property(srna, "relative_asset_identifier", PROP_STRING, PROP_NONE);
924}
925
939
940} // namespace blender
941
942#endif
Main runtime representation of an asset.
#define BLT_I18NCONTEXT_ID_ID
#define MAX_NAME
Definition DNA_defs.h:63
#define UUID_STRING_SIZE
#define C
Definition RandGen.cpp:29
#define UNUSED_VARS_NDEBUG(...)
#define BLI_assert_msg(a, msg)
btScalar max
eAssetLibraryType library_type() const
virtual std::optional< AssetLibraryReference > library_reference() const =0
constexpr int64_t size() const
constexpr const char * c_str() const
StringRefNull online_essentials_cache_directory_path()
StringRefNull online_essentials_url()
const EnumPropertyItem * library_reference_to_rna_enum_itemf(bool include_readonly, bool include_current_file, bool include_remote_libraries, bool include_separate_online_essentials)
BMesh Iterators.
static void rna_def_asset_data(BlenderRNA *brna)
Definition rna_asset.cc:645
UserDef U
Definition blender.cc:58
void RNA_def_property_srna(PropertyRNA *prop, const char *type)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
void BKE_asset_metadata_catalog_id_clear(AssetMetaData *asset_data)
Definition asset.cc:158
void RNA_def_property_editable_func(PropertyRNA *prop, const char *editable)
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
static void rna_def_asset_weak_reference(BlenderRNA *brna)
Definition rna_asset.cc:907
const EnumPropertyItem rna_enum_id_type_items[]
Definition rna_ID.cc:33
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
const EnumPropertyItem rna_enum_asset_import_method_items[]
Definition rna_asset.cc:54
@ STRUCT_NO_DATABLOCK_IDPROPERTIES
void RNA_def_property_enum_default_func(PropertyRNA *prop, const char *get_default)
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
PointerRNA RNA_id_pointer_create(ID *id)
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
@ FUNC_USE_REPORTS
@ FUNC_USE_SELF_ID
Definition RNA_types.hh:980
@ FUNC_NO_SELF
Definition RNA_types.hh:998
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
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
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
static void rna_def_asset_representation(BlenderRNA *brna)
Definition rna_asset.cc:758
const EnumPropertyItem rna_enum_asset_library_type_items[]
Definition rna_asset.cc:24
void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength)
@ ASSET_LIBRARY_CUSTOM
@ ASSET_LIBRARY_ESSENTIALS
@ ASSET_LIBRARY_ONLINE_ESSENTIALS
@ ASSET_LIBRARY_LOCAL
void RNA_def_asset(BlenderRNA *brna)
Definition rna_asset.cc:926
int rna_AssetMetaData_editable(const PointerRNA *ptr, const char **r_info)
static void rna_def_asset_tag(BlenderRNA *brna)
Definition rna_asset.cc:593
void RNA_define_animate_sdna(bool animate)
void BKE_asset_metadata_tag_remove(AssetMetaData *asset_data, AssetTag *tag)
Definition asset.cc:144
AssetTag * BKE_asset_metadata_tag_add(AssetMetaData *asset_data, const char *name) ATTR_NONNULL(1
Definition asset.cc:114
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier_c_str, int type, int subtype)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
@ ASSET_IMPORT_APPEND
@ ASSET_IMPORT_APPEND_REUSE
@ PROP_BOOLEAN
Definition RNA_types.hh:210
@ PROP_POINTER
Definition RNA_types.hh:215
@ PROP_STRING
Definition RNA_types.hh:213
@ PROP_COLLECTION
Definition RNA_types.hh:216
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
PropertyRNA * rna_def_asset_library_ui_reference_common(StructRNA *srna, const char *get, const char *set)
Definition rna_asset.cc:896
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t booleanbit)
char char size_t BLI_str_escape(char *__restrict dst, StringRef src, size_t dst_maxncpy) ATTR_NONNULL(1)
static void rna_def_asset_tags_api(BlenderRNA *brna, PropertyRNA *cprop)
Definition rna_asset.cc:609
void RNA_def_struct_path_func(StructRNA *srna, const char *path)
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier_c_str, const char *call)
@ ASSETDATA_USE_OWN_IMPORT_METHOD
const EnumPropertyItem rna_enum_dummy_NULL_items[]
Definition rna_rna.cc:28
AssetTag AssetTagEnsureResult BKE_asset_metadata_tag_ensure(AssetMetaData *asset_data, const char *name)
Definition asset.cc:121
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
static void rna_def_asset_library_reference(BlenderRNA *brna)
Definition rna_asset.cc:839
void RNA_def_struct_idprops_func(StructRNA *srna, const char *idproperties)
void RNA_def_function_flag(FunctionRNA *func, FunctionFlag flag)
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 RNA_def_struct_flag(StructRNA *srna, StructFlag flag)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
void BLI_uuid_format(char *buffer, bUUID uuid) ATTR_NONNULL()
Definition uuid.cc:82
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
asset_system::AssetLibrary * ED_fileselect_active_asset_library_get(const SpaceFile *sfile)
Definition filesel.cc:491
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
@ PROP_CONTEXT_UPDATE
Definition RNA_types.hh:477
@ PROP_EDITABLE
Definition RNA_types.hh:376
@ PROP_THICK_WRAP
Definition RNA_types.hh:493
@ PROP_NEVER_NULL
Definition RNA_types.hh:447
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
PointerRNA RNA_pointer_create_with_parent(const PointerRNA &parent, StructRNA *type, void *data)
const EnumPropertyItem * rna_asset_library_ui_reference_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free)
SpaceFile * CTX_wm_space_file(const bContext *C)
void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
@ PROP_FILENAME
Definition RNA_types.hh:286
@ PARM_REQUIRED
Definition RNA_types.hh:631
@ PARM_RNAPTR
Definition RNA_types.hh:633
void RNA_def_struct_name_property(StructRNA *srna, PropertyRNA *prop, const bool allow_replace)
static void rna_def_asset_library(BlenderRNA *brna)
Definition rna_asset.cc:846
#define min(a, b)
Definition sort.cc:38
The meta-data of an asset. By creating and giving this for a data-block (ID.asset_data),...
struct IDProperty * properties
User defined tag. Currently only used by assets, could be used more often at some point....
Universally Unique Identifier according to RFC4122.
#define N_(msgid)