Blender V4.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
9#include <cstdlib>
10
11#include "BLT_translation.hh"
12
13#include "RNA_define.hh"
14#include "RNA_enum_types.hh"
15
16#include "DNA_asset_types.h"
17#include "DNA_defs.h"
18#include "DNA_space_types.h"
19
20#include "rna_internal.hh"
21
24 "ALL",
25 0,
26 "All Libraries",
27 "Show assets from all of the listed asset libraries"},
29 "LOCAL",
30 0,
31 "Current File",
32 "Show the assets currently available in this Blender session"},
34 "ESSENTIALS",
35 0,
36 "Essentials",
37 "Show the basic building blocks and utilities coming with Blender"},
39 "CUSTOM",
40 0,
41 "Custom",
42 "Show assets from the asset libraries configured in the Preferences"},
43 {0, nullptr, 0, nullptr, nullptr},
44};
45
46#ifdef RNA_RUNTIME
47
48# include <algorithm>
49# include <fmt/format.h>
50
51# include "AS_asset_library.hh"
53
54# include "BKE_asset.hh"
55# include "BKE_context.hh"
56# include "BKE_idprop.hh"
57
58# include "BLI_listbase.h"
59# include "BLI_uuid.h"
60
61# include "ED_asset.hh"
62# include "ED_fileselect.hh"
63
64# include "RNA_access.hh"
65
66using namespace blender::asset_system;
67
68static std::optional<std::string> rna_AssetMetaData_path(const PointerRNA * /*ptr*/)
69{
70 return "asset_data";
71}
72
73static bool rna_AssetMetaData_editable_from_owner_id(const ID *owner_id,
74 const AssetMetaData *asset_data,
75 const char **r_info)
76{
77 if (owner_id && asset_data && (owner_id->asset_data == asset_data)) {
78 return true;
79 }
80
81 if (r_info) {
82 *r_info =
83 "Asset metadata from external asset libraries can't be edited, only assets stored in the "
84 "current file can";
85 }
86 return false;
87}
88
89int rna_AssetMetaData_editable(const PointerRNA *ptr, const char **r_info)
90{
91 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
92
93 return rna_AssetMetaData_editable_from_owner_id(ptr->owner_id, asset_data, r_info) ?
95 PropertyFlag(0);
96}
97
98static std::optional<std::string> rna_AssetTag_path(const PointerRNA *ptr)
99{
100 const AssetTag *asset_tag = static_cast<const AssetTag *>(ptr->data);
101 char asset_tag_name_esc[sizeof(asset_tag->name) * 2];
102 BLI_str_escape(asset_tag_name_esc, asset_tag->name, sizeof(asset_tag_name_esc));
103 return fmt::format("asset_data.tags[\"{}\"]", asset_tag_name_esc);
104}
105
106static int rna_AssetTag_editable(const PointerRNA *ptr, const char **r_info)
107{
108 AssetTag *asset_tag = static_cast<AssetTag *>(ptr->data);
109 ID *owner_id = ptr->owner_id;
110 if (owner_id && owner_id->asset_data) {
111 BLI_assert_msg(BLI_findindex(&owner_id->asset_data->tags, asset_tag) != -1,
112 "The owner of the asset tag pointer is not the asset ID containing the tag");
113 UNUSED_VARS_NDEBUG(asset_tag);
114 }
115
116 return rna_AssetMetaData_editable_from_owner_id(
117 ptr->owner_id, owner_id ? owner_id->asset_data : nullptr, r_info) ?
119 PropertyFlag(0);
120}
121
122static AssetTag *rna_AssetMetaData_tag_new(
123 ID *id, AssetMetaData *asset_data, ReportList *reports, const char *name, bool skip_if_exists)
124{
125 const char *disabled_info = nullptr;
126 if (!rna_AssetMetaData_editable_from_owner_id(id, asset_data, &disabled_info)) {
127 BKE_report(reports, RPT_WARNING, disabled_info);
128 return nullptr;
129 }
130
131 AssetTag *tag = nullptr;
132
133 if (skip_if_exists) {
134 AssetTagEnsureResult result = BKE_asset_metadata_tag_ensure(asset_data, name);
135
136 if (!result.is_new) {
138 reports, RPT_WARNING, "Tag '%s' already present for given asset", result.tag->name);
139 /* Report, but still return valid item. */
140 }
141 tag = result.tag;
142 }
143 else {
144 tag = BKE_asset_metadata_tag_add(asset_data, name);
145 }
146
147 return tag;
148}
149
150static void rna_AssetMetaData_tag_remove(ID *id,
151 AssetMetaData *asset_data,
152 ReportList *reports,
153 PointerRNA *tag_ptr)
154{
155 const char *disabled_info = nullptr;
156 if (!rna_AssetMetaData_editable_from_owner_id(id, asset_data, &disabled_info)) {
157 BKE_report(reports, RPT_WARNING, disabled_info);
158 return;
159 }
160
161 AssetTag *tag = static_cast<AssetTag *>(tag_ptr->data);
162 if (BLI_findindex(&asset_data->tags, tag) == -1) {
163 BKE_reportf(reports, RPT_ERROR, "Tag '%s' not found in given asset", tag->name);
164 return;
165 }
166
167 BKE_asset_metadata_tag_remove(asset_data, tag);
168 RNA_POINTER_INVALIDATE(tag_ptr);
169}
170
171static IDProperty **rna_AssetMetaData_idprops(PointerRNA *ptr)
172{
173 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
174 return &asset_data->properties;
175}
176
177static void rna_AssetMetaData_author_get(PointerRNA *ptr, char *value)
178{
179 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
180
181 if (asset_data->author) {
182 strcpy(value, asset_data->author);
183 }
184 else {
185 value[0] = '\0';
186 }
187}
188
189static int rna_AssetMetaData_author_length(PointerRNA *ptr)
190{
191 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
192 return asset_data->author ? strlen(asset_data->author) : 0;
193}
194
195static void rna_AssetMetaData_author_set(PointerRNA *ptr, const char *value)
196{
197 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
198
199 if (asset_data->author) {
200 MEM_freeN(asset_data->author);
201 }
202
203 if (value[0]) {
204 asset_data->author = BLI_strdup(value);
205 }
206 else {
207 asset_data->author = nullptr;
208 }
209}
210
211static void rna_AssetMetaData_description_get(PointerRNA *ptr, char *value)
212{
213 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
214
215 if (asset_data->description) {
216 strcpy(value, asset_data->description);
217 }
218 else {
219 value[0] = '\0';
220 }
221}
222
223static int rna_AssetMetaData_description_length(PointerRNA *ptr)
224{
225 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
226 return asset_data->description ? strlen(asset_data->description) : 0;
227}
228
229static void rna_AssetMetaData_description_set(PointerRNA *ptr, const char *value)
230{
231 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
232
233 if (asset_data->description) {
234 MEM_freeN(asset_data->description);
235 }
236
237 if (value[0]) {
238 asset_data->description = BLI_strdup(value);
239 }
240 else {
241 asset_data->description = nullptr;
242 }
243}
244
245static void rna_AssetMetaData_copyright_get(PointerRNA *ptr, char *value)
246{
247 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
248
249 if (asset_data->copyright) {
250 strcpy(value, asset_data->copyright);
251 }
252 else {
253 value[0] = '\0';
254 }
255}
256
257static int rna_AssetMetaData_copyright_length(PointerRNA *ptr)
258{
259 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
260 return asset_data->copyright ? strlen(asset_data->copyright) : 0;
261}
262
263static void rna_AssetMetaData_copyright_set(PointerRNA *ptr, const char *value)
264{
265 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
266
267 if (asset_data->copyright) {
268 MEM_freeN(asset_data->copyright);
269 }
270
271 if (value[0]) {
272 asset_data->copyright = BLI_strdup(value);
273 }
274 else {
275 asset_data->copyright = nullptr;
276 }
277}
278
279static void rna_AssetMetaData_license_get(PointerRNA *ptr, char *value)
280{
281 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
282
283 if (asset_data->license) {
284 strcpy(value, asset_data->license);
285 }
286 else {
287 value[0] = '\0';
288 }
289}
290
291static int rna_AssetMetaData_license_length(PointerRNA *ptr)
292{
293 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
294 return asset_data->license ? strlen(asset_data->license) : 0;
295}
296
297static void rna_AssetMetaData_license_set(PointerRNA *ptr, const char *value)
298{
299 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
300
301 if (asset_data->license) {
302 MEM_freeN(asset_data->license);
303 }
304
305 if (value[0]) {
306 asset_data->license = BLI_strdup(value);
307 }
308 else {
309 asset_data->license = nullptr;
310 }
311}
312
313static void rna_AssetMetaData_active_tag_range(
314 PointerRNA *ptr, int *min, int *max, int *softmin, int *softmax)
315{
316 const AssetMetaData *asset_data = static_cast<const AssetMetaData *>(ptr->data);
317 *min = *softmin = 0;
318 *max = *softmax = std::max(int(asset_data->tot_tags - 1), 0);
319}
320
321static void rna_AssetMetaData_catalog_id_get(PointerRNA *ptr, char *value)
322{
323 const AssetMetaData *asset_data = static_cast<const AssetMetaData *>(ptr->data);
324 BLI_uuid_format(value, asset_data->catalog_id);
325}
326
327static int rna_AssetMetaData_catalog_id_length(PointerRNA * /*ptr*/)
328{
329 return UUID_STRING_SIZE - 1;
330}
331
332static void rna_AssetMetaData_catalog_id_set(PointerRNA *ptr, const char *value)
333{
334 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
335 bUUID new_uuid;
336
337 if (value[0] == '\0') {
339 return;
340 }
341
342 if (!BLI_uuid_parse_string(&new_uuid, value)) {
343 /* TODO(@sybren): raise ValueError exception once that's possible from an RNA setter. */
344 printf("UUID %s not formatted correctly, ignoring new value\n", value);
345 return;
346 }
347
348 /* This just sets the new UUID and clears the catalog simple name. The actual
349 * catalog simple name will be updated by some update function, as it
350 * needs the asset library from the context. */
351 /* TODO(Sybren): write that update function. */
352 BKE_asset_metadata_catalog_id_set(asset_data, new_uuid, "");
353}
354
355void rna_AssetMetaData_catalog_id_update(bContext *C, PointerRNA *ptr)
356{
357 SpaceFile *sfile = CTX_wm_space_file(C);
358 if (sfile == nullptr) {
359 /* Until there is a proper Asset Service available, it's only possible to get the asset library
360 * from within the asset browser context. */
361 return;
362 }
363
365 sfile);
366 if (asset_library == nullptr) {
367 /* The SpaceFile may not be an asset browser but a regular file browser. */
368 return;
369 }
370
371 AssetMetaData *asset_data = static_cast<AssetMetaData *>(ptr->data);
372 asset_library->refresh_catalog_simplename(asset_data);
373}
374
375static PointerRNA rna_AssetHandle_file_data_get(PointerRNA *ptr)
376{
377 AssetHandle *asset_handle = static_cast<AssetHandle *>(ptr->data);
378 /* Have to cast away const, but the file entry API doesn't allow modifications anyway. */
380 ptr, &RNA_FileSelectEntry, (FileDirEntry *)asset_handle->file_data);
381}
382
383static void rna_AssetHandle_file_data_set(PointerRNA *ptr,
384 PointerRNA value,
385 ReportList * /*reports*/)
386{
387 AssetHandle *asset_handle = static_cast<AssetHandle *>(ptr->data);
388 asset_handle->file_data = static_cast<const FileDirEntry *>(value.data);
389}
390
391static void rna_AssetRepresentation_name_get(PointerRNA *ptr, char *value)
392{
393 const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
394 const blender::StringRefNull name = asset->get_name();
395 BLI_strncpy(value, name.c_str(), name.size() + 1);
396}
397
398static int rna_AssetRepresentation_name_length(PointerRNA *ptr)
399{
400 const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
401 const blender::StringRefNull name = asset->get_name();
402 return name.size();
403}
404
405static PointerRNA rna_AssetRepresentation_metadata_get(PointerRNA *ptr)
406{
407 const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
408
409 AssetMetaData &asset_data = asset->get_metadata();
410
411 /* Note that for local ID assets, the asset metadata is owned by the ID. Let the pointer inherit
412 * accordingly, so that the #PointerRNA.owner_id is set to the ID, and the metadata can be
413 * recognized as editable. */
414
415 if (asset->is_local_id()) {
416 PointerRNA id_ptr = RNA_id_pointer_create(asset->local_id());
417 return rna_pointer_inherit_refine(&id_ptr, &RNA_AssetMetaData, &asset_data);
418 }
419
420 return rna_pointer_inherit_refine(ptr, &RNA_AssetMetaData, &asset_data);
421}
422
423static int rna_AssetRepresentation_id_type_get(PointerRNA *ptr)
424{
425 const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
426 return asset->get_id_type();
427}
428
429static PointerRNA rna_AssetRepresentation_local_id_get(PointerRNA *ptr)
430{
431 const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
432 return rna_pointer_inherit_refine(ptr, &RNA_ID, asset->local_id());
433}
434
435static void rna_AssetRepresentation_full_library_path_get(PointerRNA *ptr, char *value)
436{
437 const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
438 const std::string full_library_path = asset->full_library_path();
439 BLI_strncpy(value, full_library_path.c_str(), full_library_path.size() + 1);
440}
441
442static int rna_AssetRepresentation_full_library_path_length(PointerRNA *ptr)
443{
444 const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
445 const std::string full_library_path = asset->full_library_path();
446 return full_library_path.size();
447}
448
449static void rna_AssetRepresentation_full_path_get(PointerRNA *ptr, char *value)
450{
451 const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
452 const std::string full_path = asset->full_path();
453 BLI_strncpy(value, full_path.c_str(), full_path.size() + 1);
454}
455
456static int rna_AssetRepresentation_full_path_length(PointerRNA *ptr)
457{
458 const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
459 const std::string full_path = asset->full_path();
460 return full_path.size();
461}
462
464 PointerRNA * /*ptr*/,
465 PropertyRNA * /*prop*/,
466 bool *r_free)
467{
469 if (!items) {
470 *r_free = false;
472 }
473 *r_free = true;
474 return items;
475}
476
477#else
478
480{
481 StructRNA *srna;
482 PropertyRNA *prop;
483
484 srna = RNA_def_struct(brna, "AssetTag", nullptr);
485 RNA_def_struct_path_func(srna, "rna_AssetTag_path");
486 RNA_def_struct_ui_text(srna, "Asset Tag", "User defined tag (name token)");
487
488 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
489 RNA_def_property_editable_func(prop, "rna_AssetTag_editable");
491 RNA_def_property_ui_text(prop, "Name", "The identifier that makes up this tag");
493}
494
496{
497 StructRNA *srna;
498
499 FunctionRNA *func;
500 PropertyRNA *parm;
501
502 RNA_def_property_srna(cprop, "AssetTags");
503 srna = RNA_def_struct(brna, "AssetTags", nullptr);
504 RNA_def_struct_sdna(srna, "AssetMetaData");
505 RNA_def_struct_ui_text(srna, "Asset Tags", "Collection of custom asset tags");
506
507 /* Tag collection */
508 func = RNA_def_function(srna, "new", "rna_AssetMetaData_tag_new");
509 RNA_def_function_ui_description(func, "Add a new tag to this asset");
511 parm = RNA_def_string(func, "name", nullptr, MAX_NAME, "Name", "");
513 parm = RNA_def_boolean(func,
514 "skip_if_exists",
515 false,
516 "Skip if Exists",
517 "Do not add a new tag if one of the same type already exists");
518 /* return type */
519 parm = RNA_def_pointer(func, "tag", "AssetTag", "", "New tag");
520 RNA_def_function_return(func, parm);
521
522 func = RNA_def_function(srna, "remove", "rna_AssetMetaData_tag_remove");
523 RNA_def_function_ui_description(func, "Remove an existing tag from this asset");
525 /* tag to remove */
526 parm = RNA_def_pointer(func, "tag", "AssetTag", "", "Removed tag");
529}
530
532{
533 StructRNA *srna;
534 PropertyRNA *prop;
535
536 srna = RNA_def_struct(brna, "AssetMetaData", nullptr);
537 RNA_def_struct_path_func(srna, "rna_AssetMetaData_path");
538 RNA_def_struct_ui_text(srna, "Asset Data", "Additional data stored for an asset data-block");
539 // RNA_def_struct_ui_icon(srna, ICON_ASSET); /* TODO: Icon doesn't exist! */
540 /* The struct has custom properties, but no pointer properties to other IDs! */
541 RNA_def_struct_idprops_func(srna, "rna_AssetMetaData_idprops");
543
544 prop = RNA_def_property(srna, "author", PROP_STRING, PROP_NONE);
545 RNA_def_property_editable_func(prop, "rna_AssetMetaData_editable");
547 "rna_AssetMetaData_author_get",
548 "rna_AssetMetaData_author_length",
549 "rna_AssetMetaData_author_set");
550 RNA_def_property_ui_text(prop, "Author", "Name of the creator of the asset");
551
552 prop = RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
553 RNA_def_property_editable_func(prop, "rna_AssetMetaData_editable");
555 "rna_AssetMetaData_description_get",
556 "rna_AssetMetaData_description_length",
557 "rna_AssetMetaData_description_set");
559 prop, "Description", "A description of the asset to be displayed for the user");
560
561 prop = RNA_def_property(srna, "copyright", PROP_STRING, PROP_NONE);
562 RNA_def_property_editable_func(prop, "rna_AssetMetaData_editable");
564 "rna_AssetMetaData_copyright_get",
565 "rna_AssetMetaData_copyright_length",
566 "rna_AssetMetaData_copyright_set");
568 prop,
569 "Copyright",
570 "Copyright notice for this asset. An empty copyright notice does not necessarily indicate "
571 "that this is copyright-free. Contact the author if any clarification is needed.");
572
573 prop = RNA_def_property(srna, "license", PROP_STRING, PROP_NONE);
574 RNA_def_property_editable_func(prop, "rna_AssetMetaData_editable");
576 "rna_AssetMetaData_license_get",
577 "rna_AssetMetaData_license_length",
578 "rna_AssetMetaData_license_set");
580 "License",
581 "The type of license this asset is distributed under. An empty license "
582 "name does not necessarily indicate that this is free of licensing "
583 "terms. Contact the author if any clarification is needed.");
584
585 prop = RNA_def_property(srna, "tags", PROP_COLLECTION, PROP_NONE);
586 RNA_def_property_struct_type(prop, "AssetTag");
587 RNA_def_property_editable_func(prop, "rna_AssetMetaData_editable");
589 "Tags",
590 "Custom tags (name tokens) for the asset, used for filtering and "
591 "general asset management");
592 rna_def_asset_tags_api(brna, prop);
593
594 prop = RNA_def_property(srna, "active_tag", PROP_INT, PROP_NONE);
595 RNA_def_property_int_funcs(prop, nullptr, nullptr, "rna_AssetMetaData_active_tag_range");
596 RNA_def_property_ui_text(prop, "Active Tag", "Index of the tag set for editing");
597
598 prop = RNA_def_property(srna, "catalog_id", PROP_STRING, PROP_NONE);
600 "rna_AssetMetaData_catalog_id_get",
601 "rna_AssetMetaData_catalog_id_length",
602 "rna_AssetMetaData_catalog_id_set");
604 RNA_def_property_update(prop, 0, "rna_AssetMetaData_catalog_id_update");
606 "Catalog UUID",
607 "Identifier for the asset's catalog, used by Blender to look up the "
608 "asset's catalog path. Must be a UUID according to RFC4122.");
609
610 prop = RNA_def_property(srna, "catalog_simple_name", PROP_STRING, PROP_NONE);
613 "Catalog Simple Name",
614 "Simple name of the asset's catalog, for debugging and "
615 "data recovery purposes");
616}
617
619{
620 StructRNA *srna;
621 PropertyRNA *prop;
622
623 srna = RNA_def_struct(brna, "AssetHandle", "PropertyGroup");
624 RNA_def_struct_ui_text(srna, "Asset Handle", "Reference to some asset");
625
626 /* TODO It is super ugly to expose the file data here. We have to do it though so the asset view
627 * template can populate a RNA collection with asset-handles, which are just file entries
628 * currently. A proper design is being worked on. */
629 prop = RNA_def_property(srna, "file_data", PROP_POINTER, PROP_NONE);
631 RNA_def_property_struct_type(prop, "FileSelectEntry");
633 prop, "rna_AssetHandle_file_data_get", "rna_AssetHandle_file_data_set", nullptr, nullptr);
635 prop, "File Entry", "TEMPORARY, DO NOT USE - File data used to refer to the asset");
636}
637
639{
640 StructRNA *srna;
641 PropertyRNA *prop;
642
643 srna = RNA_def_struct(brna, "AssetRepresentation", nullptr);
645 "Asset Representation",
646 "Information about an entity that makes it possible for the asset system "
647 "to deal with the entity as asset");
648
649 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_FILENAME);
652 prop, "rna_AssetRepresentation_name_get", "rna_AssetRepresentation_name_length", nullptr);
653 RNA_def_property_ui_text(prop, "Name", "");
655
656 prop = RNA_def_property(srna, "metadata", PROP_POINTER, PROP_NONE);
657 RNA_def_property_struct_type(prop, "AssetMetaData");
659 prop, "rna_AssetRepresentation_metadata_get", nullptr, nullptr, nullptr);
660 RNA_def_property_ui_text(prop, "Asset Metadata", "Additional information about the asset");
661
662 prop = RNA_def_property(srna, "id_type", PROP_ENUM, PROP_NONE);
664 RNA_def_property_enum_funcs(prop, "rna_AssetRepresentation_id_type_get", nullptr, nullptr);
667 prop,
668 "Data-block Type",
669 /* Won't ever actually return 'NONE' currently, this is just for information for once non-ID
670 * assets are supported. */
671 "The type of the data-block, if the asset represents one ('NONE' otherwise)");
673
674 prop = RNA_def_property(srna, "local_id", PROP_POINTER, PROP_NONE);
677 prop, "rna_AssetRepresentation_local_id_get", nullptr, nullptr, nullptr);
679 "",
680 "The local data-block this asset represents; only valid if that is a "
681 "data-block in this file");
682
683 prop = RNA_def_property(srna, "full_library_path", PROP_STRING, PROP_FILENAME);
686 "rna_AssetRepresentation_full_library_path_get",
687 "rna_AssetRepresentation_full_library_path_length",
688 nullptr);
689
691 prop, "Full Library Path", "Absolute path to the .blend file containing this asset");
692
693 prop = RNA_def_property(srna, "full_path", PROP_STRING, PROP_FILENAME);
696 "rna_AssetRepresentation_full_path_get",
697 "rna_AssetRepresentation_full_path_length",
698 nullptr);
699
701 prop,
702 "Full Path",
703 "Absolute path to the .blend file containing this asset extended with the path "
704 "of the asset inside the file");
705}
706
708{
709 StructRNA *srna = RNA_def_struct(brna, "AssetCatalogPath", nullptr);
710 RNA_def_struct_ui_text(srna, "Catalog Path", "");
711}
712
714{
715 StructRNA *srna = RNA_def_struct(brna, "AssetLibraryReference", nullptr);
717 srna, "Asset Library Reference", "Identifier to refer to the asset library");
718}
719
721 const char *get,
722 const char *set)
723{
724 PropertyRNA *prop = RNA_def_property(srna, "asset_library_reference", PROP_ENUM, PROP_NONE);
726 RNA_def_property_enum_funcs(prop, get, set, "rna_asset_library_reference_itemf");
727
728 return prop;
729}
730
732{
733 StructRNA *srna;
734 PropertyRNA *prop;
735
736 srna = RNA_def_struct(brna, "AssetWeakReference", nullptr);
737 RNA_def_struct_ui_text(srna, "Asset Weak Reference", "Weak reference to some asset");
738
739 prop = RNA_def_property(srna, "asset_library_type", PROP_ENUM, PROP_NONE);
742
743 prop = RNA_def_property(srna, "asset_library_identifier", PROP_STRING, PROP_NONE);
745
746 prop = RNA_def_property(srna, "relative_asset_identifier", PROP_STRING, PROP_NONE);
748}
749
764
765#endif
Main runtime representation of an asset.
AssetTag AssetTagEnsureResult BKE_asset_metadata_tag_ensure(AssetMetaData *asset_data, const char *name)
Definition asset.cc:118
AssetTag * BKE_asset_metadata_tag_add(AssetMetaData *asset_data, const char *name) ATTR_NONNULL(1
void BKE_asset_metadata_catalog_id_clear(AssetMetaData *asset_data)
Definition asset.cc:154
void BKE_asset_metadata_catalog_id_set(AssetMetaData *asset_data, bUUID catalog_id, const char *catalog_simple_name)
void BKE_asset_metadata_tag_remove(AssetMetaData *asset_data, AssetTag *tag)
Definition asset.cc:140
SpaceFile * CTX_wm_space_file(const bContext *C)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:125
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:57
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
Definition string.c:40
size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
#define UNUSED_VARS_NDEBUG(...)
bool BLI_uuid_parse_string(bUUID *uuid, const char *buffer) ATTR_NONNULL()
Definition uuid.cc:112
void BLI_uuid_format(char *buffer, bUUID uuid) ATTR_NONNULL()
Definition uuid.cc:89
#define BLT_I18NCONTEXT_ID_ID
@ ASSET_LIBRARY_CUSTOM
@ ASSET_LIBRARY_ESSENTIALS
@ ASSET_LIBRARY_LOCAL
@ ASSET_LIBRARY_ALL
#define MAX_NAME
Definition DNA_defs.h:50
#define UUID_STRING_SIZE
blender::asset_system::AssetLibrary * ED_fileselect_active_asset_library_get(const SpaceFile *sfile)
Definition filesel.cc:472
#define RNA_POINTER_INVALIDATE(ptr)
ParameterFlag
Definition RNA_types.hh:396
@ PARM_RNAPTR
Definition RNA_types.hh:399
@ PARM_REQUIRED
Definition RNA_types.hh:397
@ FUNC_USE_REPORTS
Definition RNA_types.hh:680
@ FUNC_USE_SELF_ID
Definition RNA_types.hh:667
@ STRUCT_NO_DATABLOCK_IDPROPERTIES
Definition RNA_types.hh:731
@ PROP_ENUM
Definition RNA_types.hh:69
@ PROP_INT
Definition RNA_types.hh:66
@ PROP_STRING
Definition RNA_types.hh:68
@ PROP_POINTER
Definition RNA_types.hh:70
@ PROP_COLLECTION
Definition RNA_types.hh:71
PropertyFlag
Definition RNA_types.hh:201
@ PROP_THICK_WRAP
Definition RNA_types.hh:312
@ PROP_CONTEXT_UPDATE
Definition RNA_types.hh:296
@ PROP_EDITABLE
Definition RNA_types.hh:207
@ PROP_NEVER_NULL
Definition RNA_types.hh:266
@ PROP_FILENAME
Definition RNA_types.hh:141
@ PROP_NONE
Definition RNA_types.hh:136
constexpr int64_t size() const
void refresh_catalog_simplename(AssetMetaData *asset_data)
#define printf
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105
const EnumPropertyItem * library_reference_to_rna_enum_itemf(bool include_generated)
const EnumPropertyItem rna_enum_id_type_items[]
Definition rna_ID.cc:35
PointerRNA rna_pointer_inherit_refine(const PointerRNA *ptr, StructRNA *type, void *data)
PointerRNA RNA_id_pointer_create(ID *id)
static void rna_def_asset_data(BlenderRNA *brna)
Definition rna_asset.cc:531
static void rna_def_asset_tag(BlenderRNA *brna)
Definition rna_asset.cc:479
static void rna_def_asset_library_reference(BlenderRNA *brna)
Definition rna_asset.cc:713
static void rna_def_asset_handle(BlenderRNA *brna)
Definition rna_asset.cc:618
const EnumPropertyItem rna_enum_asset_library_type_items[]
Definition rna_asset.cc:22
static void rna_def_asset_catalog_path(BlenderRNA *brna)
Definition rna_asset.cc:707
static void rna_def_asset_tags_api(BlenderRNA *brna, PropertyRNA *cprop)
Definition rna_asset.cc:495
static void rna_def_asset_representation(BlenderRNA *brna)
Definition rna_asset.cc:638
static void rna_def_asset_weak_reference(BlenderRNA *brna)
Definition rna_asset.cc:731
void RNA_def_asset(BlenderRNA *brna)
Definition rna_asset.cc:750
PropertyRNA * rna_def_asset_library_reference_common(StructRNA *srna, const char *get, const char *set)
Definition rna_asset.cc:720
void RNA_def_struct_name_property(StructRNA *srna, PropertyRNA *prop)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
void RNA_def_struct_path_func(StructRNA *srna, const char *path)
void RNA_define_animate_sdna(bool animate)
void RNA_def_struct_flag(StructRNA *srna, int flag)
void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
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 RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength)
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
void RNA_def_property_editable_func(PropertyRNA *prop, const char *editable)
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
void RNA_def_function_flag(FunctionRNA *func, int flag)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void RNA_def_struct_idprops_func(StructRNA *srna, const char *idproperties)
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
const EnumPropertyItem * rna_asset_library_reference_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free)
int rna_AssetMetaData_editable(const PointerRNA *ptr, const char **r_info)
const EnumPropertyItem rna_enum_dummy_NULL_items[]
Definition rna_rna.cc:29
#define min(a, b)
Definition sort.c:32
const struct FileDirEntry * file_data
The meta-data of an asset. By creating and giving this for a data-block (ID.asset_data),...
struct IDProperty * properties
struct bUUID catalog_id
User defined tag. Currently only used by assets, could be used more often at some point....
char name[64]
Definition DNA_ID.h:413
struct AssetMetaData * asset_data
Definition DNA_ID.h:422
ID * owner_id
Definition RNA_types.hh:40
void * data
Definition RNA_types.hh:42
Universally Unique Identifier according to RFC4122.
PointerRNA * ptr
Definition wm_files.cc:4126