Blender V5.3
blender::asset_system::AssetRepresentation Class Reference

#include <AS_asset_representation.hh>

Inherits blender::blender::NonCopyable, and blender::blender::NonMovable.

Public Member Functions

 AssetRepresentation (StringRef relative_asset_path, StringRef name, int id_type, std::unique_ptr< AssetMetaData > metadata, AssetLibrary &owner_asset_library)
 AssetRepresentation (StringRef relative_asset_path, StringRef name, int id_type, std::unique_ptr< AssetMetaData > metadata, AssetLibrary &owner_asset_library, OnlineAssetInfo online_info)
 AssetRepresentation (ID &id, AssetLibrary &owner_asset_library)
 ~AssetRepresentation ()
AssetWeakReference make_weak_reference () const
void ensure_previewable (const bContext &C, ReportList *reports=nullptr)
PreviewImage * get_preview () const
StringRefNull get_name () const
ID_Type get_id_type () const
AssetMetaData & get_metadata () const
StringRefNull library_relative_identifier () const
std::string full_path () const
std::string full_library_path () const
Span< OnlineAssetFile > online_asset_files () const
std::optional< int64_t > online_asset_files_combined_size_in_bytes () const
std::optional< StringRefNull > online_asset_preview_url () const
std::optional< StringRefNull > online_asset_preview_hash () const
void online_asset_mark_downloaded ()
std::optional< eAssetImportMethod > get_import_method () const
bool may_override_import_method () const
bool get_use_relative_path () const
ID * local_id () const
bool is_local_id () const
bool is_online_only () const
bool is_potentially_editable_asset_blend () const
RemoteAssetFileStatus remote_file_status () const
void remote_file_status_set (RemoteAssetFileStatus status)
void online_info_set (OnlineAssetInfo info)
bool needs_download () const
AssetLibrary & owner_asset_library () const

Friends

class AssetLibrary

Detailed Description

Definition at line 44 of file AS_asset_representation.hh.

Constructor & Destructor Documentation

◆ AssetRepresentation() [1/3]

blender::asset_system::AssetRepresentation::AssetRepresentation ( StringRef relative_asset_path,
StringRef name,
int id_type,
std::unique_ptr< AssetMetaData > metadata,
AssetLibrary & owner_asset_library )

Constructs an asset representation for an external ID stored on disk. The asset will not be editable.

For online assets, use the version with #online_info below.

Definition at line 30 of file asset_representation.cc.

References AssetLibrary, AssetRepresentation(), and owner_asset_library().

Referenced by AssetLibrary, AssetRepresentation(), and AssetRepresentation().

◆ AssetRepresentation() [2/3]

blender::asset_system::AssetRepresentation::AssetRepresentation ( StringRef relative_asset_path,
StringRef name,
int id_type,
std::unique_ptr< AssetMetaData > metadata,
AssetLibrary & owner_asset_library,
OnlineAssetInfo online_info )

Constructs an asset representation for an external ID stored online (requiring download).

Definition at line 41 of file asset_representation.cc.

References AssetLibrary, AssetRepresentation(), blender::nullptr, owner_asset_library(), and blender::asset_system::UNSET.

◆ AssetRepresentation() [3/3]

blender::asset_system::AssetRepresentation::AssetRepresentation ( ID & id,
AssetLibrary & owner_asset_library )

Constructs an asset representation for an ID stored in the current file. This makes the asset local and fully editable.

Definition at line 59 of file asset_representation.cc.

References AssetLibrary, and owner_asset_library().

◆ ~AssetRepresentation()

blender::asset_system::AssetRepresentation::~AssetRepresentation ( )

Member Function Documentation

◆ ensure_previewable()

void blender::asset_system::AssetRepresentation::ensure_previewable ( const bContext & C,
ReportList * reports = nullptr )

Makes sure the asset ready to load a preview, if necessary.

For local IDs it calls BKE_previewimg_id_get(). For others, this sets loading information to the preview but doesn't actually load it. To load it, attach its #PreviewImageRuntime::icon_id to a UI button (UI loads it asynchronously then) or call BKE_previewimg_ensure() (not asynchronous).

For online assets this triggers downloading of the preview.

Definition at line 81 of file asset_representation.cc.

References blender::BKE_icon_preview_ensure(), blender::BKE_previewimg_cached_thumbnail_read(), blender::BKE_previewimg_id_get(), blender::BKE_previewimg_online_thumbnail_read(), C, full_path(), blender::bke::PreviewImageRuntime::icon_id, is_online_only(), local_id(), blender::asset_system::remote_library_asset_preview_path(), blender::asset_system::remote_library_request_preview_download(), blender::PreviewImage::runtime, and blender::THB_SOURCE_BLEND.

Referenced by AssetLibrary, blender::file_draw_list(), and blender::filelist_online_asset_preview_request().

◆ full_library_path()

std::string blender::asset_system::AssetRepresentation::full_library_path ( ) const

Return the absolute path of the blend file that contains this asset.

Note that this performs a file-system check to see whether the blend file actually exists. If it does not, an empty string is returned. This generally shouldn't be an issue, but can happen, for example when the blend file is deleted and the asset browser not refreshed.

This check is a necessity because data-blocks may have .blend and slashes in their name, and directory names may also end in .blend, resulting in an identifier like directory.blend/Objects/filename.blend/Actions/hand/wave.blend/Actions/hi.blend. Here the file is directory.blend/Objects/filename.blend and the asset is an Action named hand/wave.blend/Actions/hi.blend.

Definition at line 181 of file asset_representation.cc.

References blender::BKE_blendfile_library_path_explode(), and full_path().

Referenced by AssetLibrary, and is_potentially_editable_asset_blend().

◆ full_path()

◆ get_id_type()

◆ get_import_method()

std::optional< eAssetImportMethod > blender::asset_system::AssetRepresentation::get_import_method ( ) const

Get the import method to use for this asset. A different one may be used if may_override_import_method() returns true, otherwise, the returned value must be used. If there is no import method predefined for this asset no value is returned.

Definition at line 253 of file asset_representation.cc.

References blender::ASSETDATA_USE_OWN_IMPORT_METHOD, and get_metadata().

Referenced by AssetLibrary, and blender::ED_fileselect_asset_import_method_get().

◆ get_metadata()

◆ get_name()

◆ get_preview()

PreviewImage * blender::asset_system::AssetRepresentation::get_preview ( ) const

Get the preview of this asset.

This will only return a preview for local ID assets or after ensure_previewable() was called.

Definition at line 125 of file asset_representation.cc.

References blender::BKE_previewimg_id_get(), and local_id().

Referenced by AssetLibrary, blender::file_draw_list(), blender::filelist_file_is_preview_pending(), and blender::filelist_online_asset_preview_request().

◆ get_use_relative_path()

bool blender::asset_system::AssetRepresentation::get_use_relative_path ( ) const

Definition at line 270 of file asset_representation.cc.

Referenced by AssetLibrary.

◆ is_local_id()

◆ is_online_only()

bool blender::asset_system::AssetRepresentation::is_online_only ( ) const

The asset is purely stored online, there is no local file on disk for this.

Regardless of what this function returns, there may be 'online info' (information from a remote asset listing) available, even when the file is on disk and this function returns false.

See also
remote_file_status()

Definition at line 285 of file asset_representation.cc.

References ELEM, blender::asset_system::NOT_ON_DISK, and blender::asset_system::UNSET.

Referenced by AssetLibrary, ensure_previewable(), blender::filelist_online_asset_preview_request(), blender::handle_operator_asset_reference_props(), blender::is_filtered_asset(), needs_download(), online_asset_preview_hash(), online_asset_preview_url(), and blender::ui::popup_context_menu_for_button().

◆ is_potentially_editable_asset_blend()

bool blender::asset_system::AssetRepresentation::is_potentially_editable_asset_blend ( ) const

Returns whether the asset is stored in a probably-editable .asset.blend file.

NOTE: This is suitable for poll functions (which should not open other files). The actual operator should still check that G_FILE_ASSET_EDIT_FILE / Main::is_asset_edit_file is set on the .asset.blend file (no utility function for this exists yet).

NOTE: this function does cause some disk I/O, as it checks one (or more) paths for existence. See #AssetRepresentation::full_library_path() for more info.

If the asset is already imported, this check can be done via bke::asset_edit_id_is_editable(asset_id) and bke::asset_edit_id_is_writable(asset_id).

Definition at line 303 of file asset_representation.cc.

References BLENDER_ASSET_FILE_SUFFIX, full_library_path(), owner_asset_library(), and blender::StringRef::StringRef().

Referenced by AssetLibrary, blender::ed::asset::external_asset_rename_poll(), blender::ed::animrig::pose_asset_potentially_editable_poll(), and blender::ed::asset::screenshot_preview_poll().

◆ library_relative_identifier()

◆ local_id()

ID * blender::asset_system::AssetRepresentation::local_id ( ) const

If this asset is stored inside this current file (is_local_id() is true), this returns the ID's pointer, otherwise null.

Definition at line 275 of file asset_representation.cc.

References is_local_id().

Referenced by AssetLibrary, ensure_previewable(), get_id_type(), get_metadata(), get_name(), get_preview(), library_relative_identifier(), and blender::WM_drag_add_asset_list_item().

◆ make_weak_reference()

AssetWeakReference blender::asset_system::AssetRepresentation::make_weak_reference ( ) const

◆ may_override_import_method()

bool blender::asset_system::AssetRepresentation::may_override_import_method ( ) const

Returns if this asset may be imported with an import method other than the one returned by get_import_method(). Also returns true if there is no predefined import method (when get_import_method() returns no value).

Definition at line 262 of file asset_representation.cc.

Referenced by AssetLibrary, and blender::ED_fileselect_asset_import_method_get().

◆ needs_download()

bool blender::asset_system::AssetRepresentation::needs_download ( ) const

Return whether this asset requires (re-)downloading before it can be used.

True for online-only assets (is_online_only()) and for on-disk assets whose files no longer match the remote listing (e.g. #AssetFileStatus::NO_MATCH).

Definition at line 340 of file asset_representation.cc.

References is_online_only(), blender::asset_system::NO_MATCH, and remote_file_status().

Referenced by AssetLibrary, blender::file_draw_list(), and blender::asset_system::remote_library_request_asset_download().

◆ online_asset_files()

Span< OnlineAssetFile > blender::asset_system::AssetRepresentation::online_asset_files ( ) const

For online assets (see is_online_only()), the files that make up this asset.

Will return an empty span if this is not an online asset.

Definition at line 193 of file asset_representation.cc.

Referenced by AssetLibrary, online_asset_files_combined_size_in_bytes(), and blender::asset_system::remote_library_request_asset_download().

◆ online_asset_files_combined_size_in_bytes()

std::optional< int64_t > blender::asset_system::AssetRepresentation::online_asset_files_combined_size_in_bytes ( ) const

Return the sum of sizes of all files associated with this asset, according to the listing.

Definition at line 202 of file asset_representation.cc.

References online_asset_files().

Referenced by AssetLibrary.

◆ online_asset_mark_downloaded()

void blender::asset_system::AssetRepresentation::online_asset_mark_downloaded ( )

Turn the online asset into a normal asset. This removes the online data, and the "is online" marking, turning it into a regular on-disk asset.

No-op if this is not an online asset.

Definition at line 241 of file asset_representation.cc.

References blender::asset_system::MATCH.

Referenced by AssetLibrary.

◆ online_asset_preview_hash()

std::optional< StringRefNull > blender::asset_system::AssetRepresentation::online_asset_preview_hash ( ) const

For online assets (see is_online_only()), the hash of the asset's preview.

Will return an empty value if this is not an online asset.

Definition at line 228 of file asset_representation.cc.

References is_online_only().

Referenced by AssetLibrary, and blender::asset_system::remote_library_request_preview_download().

◆ online_asset_preview_url()

std::optional< StringRefNull > blender::asset_system::AssetRepresentation::online_asset_preview_url ( ) const

For online assets (see is_online_only()), the URL the asset's preview should be requested from.

Will return an empty value if this is not an online asset.

Definition at line 215 of file asset_representation.cc.

References is_online_only().

Referenced by AssetLibrary, blender::asset_system::remote_library_asset_preview_path(), and blender::asset_system::remote_library_request_preview_download().

◆ online_info_set()

void blender::asset_system::AssetRepresentation::online_info_set ( OnlineAssetInfo info)

Store the remote listings online info on an on-disk asset so it can be re-downloaded. Replaces any previously set online info.

Definition at line 322 of file asset_representation.cc.

Referenced by AssetLibrary.

◆ owner_asset_library()

◆ remote_file_status()

RemoteAssetFileStatus blender::asset_system::AssetRepresentation::remote_file_status ( ) const

Status of this asset's on-disk file(s) compared to the remote listing. Returns #AssetFileStatus::UNSET if the asset has not been checked against a listing. For on-disk assets this reflects the status stamped after listing comparison. For online-only assets this reflects the status from OnlineAssetInfo.

Definition at line 313 of file asset_representation.cc.

References blender::asset_system::UNSET.

Referenced by AssetLibrary, blender::file_draw_indicator_icons(), and needs_download().

◆ remote_file_status_set()

void blender::asset_system::AssetRepresentation::remote_file_status_set ( RemoteAssetFileStatus status)

Set the file status for on-disk assets. No-op for online-only assets.

Definition at line 331 of file asset_representation.cc.

Referenced by AssetLibrary.

◆ AssetLibrary


The documentation for this class was generated from the following files: