Blender V4.3
asset_library.cc File Reference
#include <memory>
#include "AS_asset_catalog_tree.hh"
#include "AS_asset_library.hh"
#include "AS_asset_representation.hh"
#include "BKE_lib_remap.hh"
#include "BKE_main.hh"
#include "BKE_preferences.h"
#include "BLI_fileops.h"
#include "BLI_listbase.h"
#include "BLI_path_utils.hh"
#include "BLI_string.h"
#include "DNA_userdef_types.h"
#include "asset_catalog_collection.hh"
#include "asset_catalog_definition_file.hh"
#include "asset_library_service.hh"
#include "utils.hh"

Go to the source code of this file.

Namespaces

namespace  blender
 
namespace  blender::asset_system
 

Functions

void AS_asset_libraries_exit ()
 
AssetLibraryAS_asset_library_load (const Main *bmain, const AssetLibraryReference &library_reference)
 
AssetLibraryAS_asset_library_load (const char *name, const char *library_dirpath)
 
bool AS_asset_library_has_any_unsaved_catalogs ()
 
std::string AS_asset_library_root_path_from_library_ref (const AssetLibraryReference &library_reference)
 
std::string AS_asset_library_find_suitable_root_path_from_path (const blender::StringRefNull input_path)
 
std::string AS_asset_library_find_suitable_root_path_from_main (const Main *bmain)
 
void AS_asset_library_remap_ids (const bke::id::IDRemapper &mappings)
 
void AS_asset_full_path_explode_from_weak_ref (const AssetWeakReference *asset_reference, char r_path_buffer[1090], char **r_dir, char **r_group, char **r_name)
 
Vector< AssetLibraryReferenceblender::asset_system::all_valid_asset_library_refs ()
 
AssetLibraryReference blender::asset_system::all_library_reference ()
 
void blender::asset_system::all_library_reload_catalogs_if_dirty ()
 

Function Documentation

◆ AS_asset_full_path_explode_from_weak_ref()

void AS_asset_full_path_explode_from_weak_ref ( const AssetWeakReference * asset_reference,
char r_path_buffer[1090],
char ** r_dir,
char ** r_group,
char ** r_name )

Attempt to resolve a full path to an asset based on the currently available (not necessary loaded) asset libraries, and split it into it's directory, ID group and ID name components. The path is not guaranteed to exist on disk. On failure to resolve the reference, return arguments will point to null.

Note
Only works for asset libraries on disk and the "Current File" one (others can't be resolved).
Parameters
r_path_bufferBuffer to hold the result in on success. Will be the full path with null terminators instead of slashes separating the directory, group and name components. Must be at least FILE_MAX_LIBEXTRA long.
r_dirReturns the .blend file path with native slashes on success. Optional (passing null is allowed). For the "Current File" library this will be empty.
r_groupReturns the ID group such as "Object", "Material" or "Brush". Optional (passing null is allowed).
r_nameReturns the ID name on success. Optional (passing null is allowed).

Definition at line 104 of file asset_library.cc.

References BLI_assert, BLI_strncpy(), blender::asset_system::AssetLibraryService::get(), and blender::asset_system::AssetLibraryService::resolve_asset_weak_reference_to_exploded_path().

Referenced by blender::bke::asset_edit_id_from_weak_reference(), and blender::ed::sculpt_paint::brush_asset_edit_metadata_exec().

◆ AS_asset_libraries_exit()

void AS_asset_libraries_exit ( )

Force clearing of all asset library data. After calling this, new asset libraries can be loaded just as usual using AS_asset_library_load(), no init or other setup is needed.

Does not need to be called on exit, this is handled internally.

Definition at line 36 of file asset_library.cc.

References blender::asset_system::AssetLibraryService::destroy().

Referenced by wm_file_read_setup_wm_init().

◆ AS_asset_library_find_suitable_root_path_from_main()

std::string AS_asset_library_find_suitable_root_path_from_main ( const Main * bmain)

Uses the current location on disk of the file represented by bmain as input to AS_asset_library_find_suitable_root_path_from_path(). Refer to it for a design description.

Returns
True if the function could find a valid, that is, a non-empty path to return in r_library_path. If bmain wasn't saved into a file yet, the return value will be false.

Definition at line 92 of file asset_library.cc.

References AS_asset_library_find_suitable_root_path_from_path(), and Main::filepath.

Referenced by blender::asset_system::AssetLibraryService::get_asset_library().

◆ AS_asset_library_find_suitable_root_path_from_path()

std::string AS_asset_library_find_suitable_root_path_from_path ( blender::StringRefNull input_path)

Try to find an appropriate location for an asset library root from a file or directory path. Does not check if input_path exists.

The design is made to find an appropriate asset library path from a .blend file path, but technically works with any file or directory as input_path. Design is:

  • If input_path lies within a known asset library path (i.e. an asset library registered in the Preferences), return the asset library path.
  • Otherwise, if input_path has a parent path, return the parent path (e.g. to use the directory a .blend file is in as asset library root).
  • If input_path is empty or doesn't have a parent path (e.g. because a .blend wasn't saved yet), there is no suitable path. The caller has to decide how to handle this case.
Parameters
r_library_pathThe returned asset library path with a trailing slash, or an empty string if no suitable path is found. Assumed to be a buffer of at least FILE_MAXDIR bytes.
Returns
True if the function could find a valid, that is, a non-empty path to return in r_library_path.

Definition at line 78 of file asset_library.cc.

References BKE_preferences_asset_library_containing_path(), BLI_path_split_dir_part(), blender::StringRefNull::c_str(), and FILE_MAXDIR.

Referenced by AS_asset_library_find_suitable_root_path_from_main(), and blender::asset_system::AssetCatalogService::find_suitable_cdf_path_for_writing().

◆ AS_asset_library_has_any_unsaved_catalogs()

bool AS_asset_library_has_any_unsaved_catalogs ( )

◆ AS_asset_library_load() [1/2]

AssetLibrary * AS_asset_library_load ( const char * name,
const char * library_dirpath )

Return the #AssetLibrary rooted at the given directory path.

Will return the same pointer for repeated calls, until another blend file is loaded.

To get the in-memory-only "current file" asset library, pass an empty path.

Definition at line 50 of file asset_library.cc.

References blender::asset_system::AssetLibraryService::get(), blender::asset_system::AssetLibraryService::get_asset_library_current_file(), blender::asset_system::AssetLibraryService::get_asset_library_on_disk_custom(), and lib.

◆ AS_asset_library_load() [2/2]

AssetLibrary * AS_asset_library_load ( const Main * bmain,
const AssetLibraryReference & library_reference )

Load the data for an asset library, but not the asset representations themselves (loading these is currently not done in the asset system).

For the "All" asset library (ASSET_LIBRARY_ALL), every other known asset library will be loaded as well. So a call to #AssetLibrary::foreach_loaded() can be expected to iterate over all libraries.

Warning
Catalogs are reloaded, invalidating catalog pointers. Do not store catalog pointers, store CatalogIDs instead and lookup the catalog where needed.

Definition at line 43 of file asset_library.cc.

References blender::asset_system::AssetLibraryService::get(), and blender::asset_system::AssetLibraryService::get_asset_library().

Referenced by blender::ed::sculpt_paint::brush_asset_edit_metadata_exec(), blender::ed::sculpt_paint::brush_asset_save_as_exec(), filelist_readjob_all_asset_library(), filelist_readjob_load_asset_library_data(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), and blender::ed::sculpt_paint::visit_library_catalogs_catalog_for_search().

◆ AS_asset_library_remap_ids()

void AS_asset_library_remap_ids ( const blender::bke::id::IDRemapper & mappings)

An asset library can include local IDs (IDs in the current file). Their pointers need to be remapped on change (or assets removed as IDs gets removed).

Definition at line 97 of file asset_library.cc.

References blender::asset_system::AssetLibraryService::foreach_loaded_asset_library(), blender::asset_system::AssetLibraryService::get(), and blender::asset_system::AssetLibrary::remap_ids_and_remove_invalid().

Referenced by WM_main_remap_editor_id_reference().

◆ AS_asset_library_root_path_from_library_ref()

std::string AS_asset_library_root_path_from_library_ref ( const AssetLibraryReference & library_reference)