Blender V4.5
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 "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
19#include "rna_internal.hh"
20
23 "ALL",
24 0,
25 "All Libraries",
26 "Show assets from all of the listed asset libraries"},
28 "LOCAL",
29 0,
30 "Current File",
31 "Show the assets currently available in this Blender session"},
33 "ESSENTIALS",
34 0,
35 "Essentials",
36 "Show the basic building blocks and utilities coming with Blender"},
38 "CUSTOM",
39 0,
40 "Custom",
41 "Show assets from the asset libraries configured in the Preferences"},
42 {0, nullptr, 0, nullptr, nullptr},
43};
44
45#ifdef RNA_RUNTIME
46
47# include <algorithm>
48# include <fmt/format.h>
49
50# include "AS_asset_library.hh"
52
53# include "BKE_asset.hh"
54# include "BKE_context.hh"
55# include "BKE_report.hh"
56
57# include "BLI_listbase.h"
58# include "BLI_string.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 = N_(
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) {
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,
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 tag_ptr->invalidate();
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_create_with_parent(id_ptr, &RNA_AssetMetaData, &asset_data);
418 }
419
420 return RNA_pointer_create_with_parent(*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_id_pointer_create(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 /* Include all valid libraries for the user to choose from. */
470 /*include_readonly=*/true,
471 /*include_current_file=*/true);
472 if (!items) {
473 *r_free = false;
475 }
476 *r_free = true;
477 return items;
478}
479
480#else
481
483{
484 StructRNA *srna;
485 PropertyRNA *prop;
486
487 srna = RNA_def_struct(brna, "AssetTag", nullptr);
488 RNA_def_struct_path_func(srna, "rna_AssetTag_path");
489 RNA_def_struct_ui_text(srna, "Asset Tag", "User defined tag (name token)");
490
491 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
492 RNA_def_property_editable_func(prop, "rna_AssetTag_editable");
494 RNA_def_property_ui_text(prop, "Name", "The identifier that makes up this tag");
496}
497
499{
500 StructRNA *srna;
501
502 FunctionRNA *func;
503 PropertyRNA *parm;
504
505 RNA_def_property_srna(cprop, "AssetTags");
506 srna = RNA_def_struct(brna, "AssetTags", nullptr);
507 RNA_def_struct_sdna(srna, "AssetMetaData");
508 RNA_def_struct_ui_text(srna, "Asset Tags", "Collection of custom asset tags");
509
510 /* Tag collection */
511 func = RNA_def_function(srna, "new", "rna_AssetMetaData_tag_new");
512 RNA_def_function_ui_description(func, "Add a new tag to this asset");
514 parm = RNA_def_string(func, "name", nullptr, MAX_NAME, "Name", "");
516 parm = RNA_def_boolean(func,
517 "skip_if_exists",
518 false,
519 "Skip if Exists",
520 "Do not add a new tag if one of the same type already exists");
521 /* return type */
522 parm = RNA_def_pointer(func, "tag", "AssetTag", "", "New tag");
523 RNA_def_function_return(func, parm);
524
525 func = RNA_def_function(srna, "remove", "rna_AssetMetaData_tag_remove");
526 RNA_def_function_ui_description(func, "Remove an existing tag from this asset");
528 /* tag to remove */
529 parm = RNA_def_pointer(func, "tag", "AssetTag", "", "Removed tag");
532}
533
535{
536 StructRNA *srna;
537 PropertyRNA *prop;
538
539 srna = RNA_def_struct(brna, "AssetMetaData", nullptr);
540 RNA_def_struct_path_func(srna, "rna_AssetMetaData_path");
541 RNA_def_struct_ui_text(srna, "Asset Data", "Additional data stored for an asset data-block");
542 // RNA_def_struct_ui_icon(srna, ICON_ASSET); /* TODO: Icon doesn't exist! */
543 /* The struct has custom properties, but no pointer properties to other IDs! */
544 RNA_def_struct_idprops_func(srna, "rna_AssetMetaData_idprops");
546
547 prop = RNA_def_property(srna, "author", PROP_STRING, PROP_NONE);
548 RNA_def_property_editable_func(prop, "rna_AssetMetaData_editable");
550 "rna_AssetMetaData_author_get",
551 "rna_AssetMetaData_author_length",
552 "rna_AssetMetaData_author_set");
553 RNA_def_property_ui_text(prop, "Author", "Name of the creator of the asset");
554
555 prop = RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
556 RNA_def_property_editable_func(prop, "rna_AssetMetaData_editable");
558 "rna_AssetMetaData_description_get",
559 "rna_AssetMetaData_description_length",
560 "rna_AssetMetaData_description_set");
562 prop, "Description", "A description of the asset to be displayed for the user");
563
564 prop = RNA_def_property(srna, "copyright", PROP_STRING, PROP_NONE);
565 RNA_def_property_editable_func(prop, "rna_AssetMetaData_editable");
567 "rna_AssetMetaData_copyright_get",
568 "rna_AssetMetaData_copyright_length",
569 "rna_AssetMetaData_copyright_set");
571 prop,
572 "Copyright",
573 "Copyright notice for this asset. An empty copyright notice does not necessarily indicate "
574 "that this is copyright-free. Contact the author if any clarification is needed.");
575
576 prop = RNA_def_property(srna, "license", PROP_STRING, PROP_NONE);
577 RNA_def_property_editable_func(prop, "rna_AssetMetaData_editable");
579 "rna_AssetMetaData_license_get",
580 "rna_AssetMetaData_license_length",
581 "rna_AssetMetaData_license_set");
583 "License",
584 "The type of license this asset is distributed under. An empty license "
585 "name does not necessarily indicate that this is free of licensing "
586 "terms. Contact the author if any clarification is needed.");
587
588 prop = RNA_def_property(srna, "tags", PROP_COLLECTION, PROP_NONE);
589 RNA_def_property_struct_type(prop, "AssetTag");
590 RNA_def_property_editable_func(prop, "rna_AssetMetaData_editable");
592 "Tags",
593 "Custom tags (name tokens) for the asset, used for filtering and "
594 "general asset management");
595 rna_def_asset_tags_api(brna, prop);
596
597 prop = RNA_def_property(srna, "active_tag", PROP_INT, PROP_NONE);
598 RNA_def_property_int_funcs(prop, nullptr, nullptr, "rna_AssetMetaData_active_tag_range");
599 RNA_def_property_ui_text(prop, "Active Tag", "Index of the tag set for editing");
600
601 prop = RNA_def_property(srna, "catalog_id", PROP_STRING, PROP_NONE);
603 "rna_AssetMetaData_catalog_id_get",
604 "rna_AssetMetaData_catalog_id_length",
605 "rna_AssetMetaData_catalog_id_set");
607 RNA_def_property_update(prop, 0, "rna_AssetMetaData_catalog_id_update");
609 "Catalog UUID",
610 "Identifier for the asset's catalog, used by Blender to look up the "
611 "asset's catalog path. Must be a UUID according to RFC4122.");
612
613 prop = RNA_def_property(srna, "catalog_simple_name", PROP_STRING, PROP_NONE);
616 "Catalog Simple Name",
617 "Simple name of the asset's catalog, for debugging and "
618 "data recovery purposes");
619}
620
622{
623 StructRNA *srna;
624 PropertyRNA *prop;
625
626 srna = RNA_def_struct(brna, "AssetHandle", "PropertyGroup");
627 RNA_def_struct_ui_text(srna, "Asset Handle", "Reference to some asset");
628
629 /* TODO It is super ugly to expose the file data here. We have to do it though so the asset view
630 * template can populate a RNA collection with asset-handles, which are just file entries
631 * currently. A proper design is being worked on. */
632 prop = RNA_def_property(srna, "file_data", PROP_POINTER, PROP_NONE);
634 RNA_def_property_struct_type(prop, "FileSelectEntry");
636 prop, "rna_AssetHandle_file_data_get", "rna_AssetHandle_file_data_set", nullptr, nullptr);
638 prop, "File Entry", "TEMPORARY, DO NOT USE - File data used to refer to the asset");
639}
640
642{
643 StructRNA *srna;
644 PropertyRNA *prop;
645
646 srna = RNA_def_struct(brna, "AssetRepresentation", nullptr);
648 "Asset Representation",
649 "Information about an entity that makes it possible for the asset system "
650 "to deal with the entity as asset");
651
652 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_FILENAME);
655 prop, "rna_AssetRepresentation_name_get", "rna_AssetRepresentation_name_length", nullptr);
656 RNA_def_property_ui_text(prop, "Name", "");
658
659 prop = RNA_def_property(srna, "metadata", PROP_POINTER, PROP_NONE);
660 RNA_def_property_struct_type(prop, "AssetMetaData");
662 prop, "rna_AssetRepresentation_metadata_get", nullptr, nullptr, nullptr);
663 RNA_def_property_ui_text(prop, "Asset Metadata", "Additional information about the asset");
664
665 prop = RNA_def_property(srna, "id_type", PROP_ENUM, PROP_NONE);
667 RNA_def_property_enum_funcs(prop, "rna_AssetRepresentation_id_type_get", nullptr, nullptr);
670 prop,
671 "Data-block Type",
672 /* Won't ever actually return 'NONE' currently, this is just for information for once non-ID
673 * assets are supported. */
674 "The type of the data-block, if the asset represents one ('NONE' otherwise)");
676
677 prop = RNA_def_property(srna, "local_id", PROP_POINTER, PROP_NONE);
680 prop, "rna_AssetRepresentation_local_id_get", nullptr, nullptr, nullptr);
682 "",
683 "The local data-block this asset represents; only valid if that is a "
684 "data-block in this file");
685
686 prop = RNA_def_property(srna, "full_library_path", PROP_STRING, PROP_FILENAME);
689 "rna_AssetRepresentation_full_library_path_get",
690 "rna_AssetRepresentation_full_library_path_length",
691 nullptr);
692
694 prop, "Full Library Path", "Absolute path to the .blend file containing this asset");
695
696 prop = RNA_def_property(srna, "full_path", PROP_STRING, PROP_FILENAME);
699 "rna_AssetRepresentation_full_path_get",
700 "rna_AssetRepresentation_full_path_length",
701 nullptr);
702
704 prop,
705 "Full Path",
706 "Absolute path to the .blend file containing this asset extended with the path "
707 "of the asset inside the file");
708}
709
711{
712 StructRNA *srna = RNA_def_struct(brna, "AssetCatalogPath", nullptr);
713 RNA_def_struct_ui_text(srna, "Catalog Path", "");
714}
715
717{
718 StructRNA *srna = RNA_def_struct(brna, "AssetLibraryReference", nullptr);
720 srna, "Asset Library Reference", "Identifier to refer to the asset library");
721}
722
724 const char *get,
725 const char *set)
726{
727 PropertyRNA *prop = RNA_def_property(srna, "asset_library_reference", PROP_ENUM, PROP_NONE);
729 RNA_def_property_enum_funcs(prop, get, set, "rna_asset_library_reference_itemf");
730
731 return prop;
732}
733
735{
736 StructRNA *srna;
737 PropertyRNA *prop;
738
739 srna = RNA_def_struct(brna, "AssetWeakReference", nullptr);
740 RNA_def_struct_ui_text(srna, "Asset Weak Reference", "Weak reference to some asset");
741
742 prop = RNA_def_property(srna, "asset_library_type", PROP_ENUM, PROP_NONE);
745
746 prop = RNA_def_property(srna, "asset_library_identifier", PROP_STRING, PROP_NONE);
748
749 prop = RNA_def_property(srna, "relative_asset_identifier", PROP_STRING, PROP_NONE);
751}
752
767
768#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:126
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:53
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:586
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
Definition string.cc:41
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 UUID_STRING_SIZE
blender::asset_system::AssetLibrary * ED_fileselect_active_asset_library_get(const SpaceFile *sfile)
Definition filesel.cc:475
ParameterFlag
Definition RNA_types.hh:510
@ PARM_RNAPTR
Definition RNA_types.hh:513
@ PARM_REQUIRED
Definition RNA_types.hh:511
@ FUNC_USE_REPORTS
Definition RNA_types.hh:805
@ FUNC_USE_SELF_ID
Definition RNA_types.hh:792
@ STRUCT_NO_DATABLOCK_IDPROPERTIES
Definition RNA_types.hh:856
@ PROP_ENUM
Definition RNA_types.hh:154
@ PROP_INT
Definition RNA_types.hh:151
@ PROP_STRING
Definition RNA_types.hh:153
@ PROP_POINTER
Definition RNA_types.hh:155
@ PROP_COLLECTION
Definition RNA_types.hh:156
PropertyFlag
Definition RNA_types.hh:286
@ PROP_THICK_WRAP
Definition RNA_types.hh:397
@ PROP_CONTEXT_UPDATE
Definition RNA_types.hh:381
@ PROP_EDITABLE
Definition RNA_types.hh:292
@ PROP_NEVER_NULL
Definition RNA_types.hh:351
@ PROP_FILENAME
Definition RNA_types.hh:226
@ PROP_NONE
Definition RNA_types.hh:221
#define C
Definition RandGen.cpp:29
ReportList * reports
Definition WM_types.hh:1025
constexpr int64_t size() const
constexpr const char * c_str() const
void refresh_catalog_simplename(AssetMetaData *asset_data)
#define printf(...)
#define MAX_NAME
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
const EnumPropertyItem * library_reference_to_rna_enum_itemf(bool include_readonly, bool include_current_file)
const EnumPropertyItem rna_enum_id_type_items[]
Definition rna_ID.cc:29
PointerRNA RNA_pointer_create_with_parent(const PointerRNA &parent, StructRNA *type, void *data)
PointerRNA RNA_id_pointer_create(ID *id)
static void rna_def_asset_data(BlenderRNA *brna)
Definition rna_asset.cc:534
static void rna_def_asset_tag(BlenderRNA *brna)
Definition rna_asset.cc:482
static void rna_def_asset_library_reference(BlenderRNA *brna)
Definition rna_asset.cc:716
static void rna_def_asset_handle(BlenderRNA *brna)
Definition rna_asset.cc:621
const EnumPropertyItem rna_enum_asset_library_type_items[]
Definition rna_asset.cc:21
static void rna_def_asset_catalog_path(BlenderRNA *brna)
Definition rna_asset.cc:710
static void rna_def_asset_tags_api(BlenderRNA *brna, PropertyRNA *cprop)
Definition rna_asset.cc:498
static void rna_def_asset_representation(BlenderRNA *brna)
Definition rna_asset.cc:641
static void rna_def_asset_weak_reference(BlenderRNA *brna)
Definition rna_asset.cc:734
void RNA_def_asset(BlenderRNA *brna)
Definition rna_asset.cc:753
PropertyRNA * rna_def_asset_library_reference_common(StructRNA *srna, const char *get, const char *set)
Definition rna_asset.cc:723
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:26
#define min(a, b)
Definition sort.cc:36
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:404
struct AssetMetaData * asset_data
Definition DNA_ID.h:413
void invalidate()
Definition RNA_types.hh:110
void * data
Definition RNA_types.hh:53
Universally Unique Identifier according to RFC4122.
max
Definition text_draw.cc:251
#define N_(msgid)
PointerRNA * ptr
Definition wm_files.cc:4226