Assets: Expose more data in the asset representation RNA/BPY
The asset handle type is supposed to be replaced by the asset representation type. It is designed for the asset system as opposed to the file browser backend. This commit adds more members to its RNA type to query data, so more usages of the asset handle type in Python can be converted. Part of #102877 and #108806.
This commit is contained in:
@@ -44,6 +44,8 @@ const EnumPropertyItem rna_enum_aset_library_type_items[] = {
|
||||
|
||||
# include "RNA_access.hh"
|
||||
|
||||
using namespace blender::asset_system;
|
||||
|
||||
static char *rna_AssetMetaData_path(const PointerRNA * /*ptr*/)
|
||||
{
|
||||
return BLI_strdup("asset_data");
|
||||
@@ -339,7 +341,7 @@ void rna_AssetMetaData_catalog_id_update(bContext *C, PointerRNA *ptr)
|
||||
return;
|
||||
}
|
||||
|
||||
AssetLibrary *asset_library = ED_fileselect_active_asset_library_get(sfile);
|
||||
::AssetLibrary *asset_library = ED_fileselect_active_asset_library_get(sfile);
|
||||
if (asset_library == nullptr) {
|
||||
/* The SpaceFile may not be an asset browser but a regular file browser. */
|
||||
return;
|
||||
@@ -382,14 +384,64 @@ static PointerRNA rna_AssetHandle_local_id_get(PointerRNA *ptr)
|
||||
return rna_pointer_inherit_refine(ptr, &RNA_ID, id);
|
||||
}
|
||||
|
||||
static void rna_AssetRepresentation_name_get(PointerRNA *ptr, char *value)
|
||||
{
|
||||
const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
|
||||
const blender::StringRefNull name = asset->get_name();
|
||||
BLI_strncpy(value, name.c_str(), name.size() + 1);
|
||||
}
|
||||
|
||||
static int rna_AssetRepresentation_name_length(PointerRNA *ptr)
|
||||
{
|
||||
const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
|
||||
const blender::StringRefNull name = asset->get_name();
|
||||
return name.size();
|
||||
}
|
||||
|
||||
static PointerRNA rna_AssetRepresentation_metadata_get(PointerRNA *ptr)
|
||||
{
|
||||
const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
|
||||
|
||||
AssetMetaData &asset_data = asset->get_metadata();
|
||||
|
||||
/* Note that for local ID assets, the asset metadata is owned by the ID. Let the pointer inherit
|
||||
* accordingly, so that the #PointerRNA.owner_id is set to the ID, and the metadata can be
|
||||
* recognized as editable. */
|
||||
|
||||
if (asset->is_local_id()) {
|
||||
PointerRNA id_ptr = RNA_id_pointer_create(asset->local_id());
|
||||
return rna_pointer_inherit_refine(&id_ptr, &RNA_AssetMetaData, &asset_data);
|
||||
}
|
||||
|
||||
return rna_pointer_inherit_refine(ptr, &RNA_AssetMetaData, &asset_data);
|
||||
}
|
||||
|
||||
static int rna_AssetRepresentation_id_type_get(PointerRNA *ptr)
|
||||
{
|
||||
using namespace blender::asset_system;
|
||||
|
||||
const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
|
||||
return asset->get_id_type();
|
||||
}
|
||||
|
||||
static PointerRNA rna_AssetRepresentation_local_id_get(PointerRNA *ptr)
|
||||
{
|
||||
const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
|
||||
return rna_pointer_inherit_refine(ptr, &RNA_ID, asset->local_id());
|
||||
}
|
||||
|
||||
static void rna_AssetRepresentation_full_library_path_get(PointerRNA *ptr, char *value)
|
||||
{
|
||||
const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
|
||||
const std::string full_library_path = asset->get_identifier().full_library_path();
|
||||
BLI_strncpy(value, full_library_path.c_str(), full_library_path.size() + 1);
|
||||
}
|
||||
|
||||
static int rna_AssetRepresentation_full_library_path_length(PointerRNA *ptr)
|
||||
{
|
||||
const AssetRepresentation *asset = static_cast<const AssetRepresentation *>(ptr->data);
|
||||
const std::string full_library_path = asset->get_identifier().full_library_path();
|
||||
return full_library_path.size();
|
||||
}
|
||||
|
||||
const EnumPropertyItem *rna_asset_library_reference_itemf(bContext * /*C*/,
|
||||
PointerRNA * /*ptr*/,
|
||||
PropertyRNA * /*prop*/,
|
||||
@@ -603,6 +655,19 @@ static void rna_def_asset_representation(BlenderRNA *brna)
|
||||
"Information about an entity that makes it possible for the asset system "
|
||||
"to deal with the entity as asset");
|
||||
|
||||
prop = RNA_def_property(srna, "name", PROP_STRING, PROP_FILENAME);
|
||||
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
||||
RNA_def_property_string_funcs(
|
||||
prop, "rna_AssetRepresentation_name_get", "rna_AssetRepresentation_name_length", nullptr);
|
||||
RNA_def_property_ui_text(prop, "Name", "");
|
||||
RNA_def_struct_name_property(srna, prop);
|
||||
|
||||
prop = RNA_def_property(srna, "metadata", PROP_POINTER, PROP_NONE);
|
||||
RNA_def_property_struct_type(prop, "AssetMetaData");
|
||||
RNA_def_property_pointer_funcs(
|
||||
prop, "rna_AssetRepresentation_metadata_get", nullptr, nullptr, nullptr);
|
||||
RNA_def_property_ui_text(prop, "Asset Metadata", "Additional information about the asset");
|
||||
|
||||
prop = RNA_def_property(srna, "id_type", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_items(prop, rna_enum_id_type_items);
|
||||
RNA_def_property_enum_funcs(prop, "rna_AssetRepresentation_id_type_get", nullptr, nullptr);
|
||||
@@ -614,6 +679,27 @@ static void rna_def_asset_representation(BlenderRNA *brna)
|
||||
* assets are supported. */
|
||||
"The type of the data-block, if the asset represents one ('NONE' otherwise)");
|
||||
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_ID);
|
||||
|
||||
prop = RNA_def_property(srna, "local_id", PROP_POINTER, PROP_NONE);
|
||||
RNA_def_property_struct_type(prop, "ID");
|
||||
RNA_def_property_pointer_funcs(
|
||||
prop, "rna_AssetRepresentation_local_id_get", nullptr, nullptr, nullptr);
|
||||
RNA_def_property_ui_text(prop,
|
||||
"",
|
||||
"The local data-block this asset represents; only valid if that is a "
|
||||
"data-block in this file");
|
||||
|
||||
prop = RNA_def_property(srna, "full_library_path", PROP_STRING, PROP_FILENAME);
|
||||
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
||||
RNA_def_property_string_funcs(prop,
|
||||
"rna_AssetRepresentation_full_library_path_get",
|
||||
"rna_AssetRepresentation_full_library_path_length",
|
||||
nullptr);
|
||||
RNA_def_property_ui_text(
|
||||
prop,
|
||||
"Full Library Path",
|
||||
"Absolute path to the .blend file containing this asset extended with the path "
|
||||
"of the asset inside the file");
|
||||
}
|
||||
|
||||
static void rna_def_asset_catalog_path(BlenderRNA *brna)
|
||||
|
||||
Reference in New Issue
Block a user