Support & use new asset library path query from master
This commit is contained in:
parent
3ff321bc98
commit
e63671c21d
|
@ -4,9 +4,14 @@
|
|||
* \ingroup asset_system
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "BKE_asset_library_custom.h"
|
||||
#include "BKE_blender.h"
|
||||
#include "BKE_blender_project.h"
|
||||
|
||||
#include "BLI_path_util.h"
|
||||
#include "BLI_string_ref.hh"
|
||||
|
||||
#include "DNA_asset_types.h"
|
||||
|
@ -188,16 +193,49 @@ std::string AssetLibraryService::root_path_from_library_ref(
|
|||
return "";
|
||||
}
|
||||
|
||||
BLI_assert(library_reference.type == ASSET_LIBRARY_CUSTOM);
|
||||
BLI_assert(library_reference.custom_library_index >= 0);
|
||||
|
||||
bUserAssetLibrary *user_library = BKE_preferences_asset_library_find_from_index(
|
||||
&U, library_reference.custom_library_index);
|
||||
if (!user_library || !user_library->path[0]) {
|
||||
return "";
|
||||
switch (library_reference.type) {
|
||||
case ASSET_LIBRARY_CUSTOM_FROM_PREFERENCES: {
|
||||
CustomAssetLibraryDefinition *user_library = BKE_asset_library_custom_find_from_index(
|
||||
&U.asset_libraries, library_reference.custom_library_index);
|
||||
if (user_library && user_library->path[0]) {
|
||||
return user_library->path;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ASSET_LIBRARY_CUSTOM_FROM_PROJECT: {
|
||||
BlenderProject *project = BKE_project_active_get();
|
||||
if (!project) {
|
||||
return "";
|
||||
}
|
||||
|
||||
ListBase *project_libraries = BKE_project_custom_asset_libraries_get(project);
|
||||
CustomAssetLibraryDefinition *project_library_ = BKE_asset_library_custom_find_from_index(
|
||||
project_libraries, library_reference.custom_library_index);
|
||||
if (!project_library_) {
|
||||
return "";
|
||||
}
|
||||
|
||||
/* Project asset libraries typically use relative paths (relative to project root directory).
|
||||
*/
|
||||
if (BLI_path_is_rel(project_library_->path)) {
|
||||
const char *project_root_path = BKE_project_root_path_get(project);
|
||||
char path[1024]; /* FILE_MAX */
|
||||
BLI_path_join(path, sizeof(path), project_root_path, project_library_->path);
|
||||
return path;
|
||||
}
|
||||
else {
|
||||
return project_library_->path;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BLI_assert_unreachable();
|
||||
break;
|
||||
}
|
||||
|
||||
return user_library->path;
|
||||
return "";
|
||||
}
|
||||
|
||||
void AssetLibraryService::allocate_service_instance()
|
||||
|
|
|
@ -153,16 +153,6 @@ void AssetList::setup()
|
|||
filelist_setindexer(files, use_asset_indexer ? &file_indexer_asset : &file_indexer_noop);
|
||||
|
||||
char path[FILE_MAXDIR] = "";
|
||||
#if 0
|
||||
/* Project asset libraries typically use relative paths (relative to project root directory).
|
||||
*/
|
||||
if ((library_ref_.type == ASSET_LIBRARY_CUSTOM_FROM_PROJECT) &&
|
||||
BLI_path_is_rel(custom_library->path)) {
|
||||
BlenderProject *project = CTX_wm_project();
|
||||
const char *project_root_path = BKE_project_root_path_get(project);
|
||||
BLI_path_join(path, sizeof(path), project_root_path, custom_library->path);
|
||||
}
|
||||
#endif
|
||||
if (!asset_lib_path.empty()) {
|
||||
BLI_strncpy(path, asset_lib_path.c_str(), sizeof(path));
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "AS_asset_library.hh"
|
||||
|
||||
#include "DNA_screen_types.h"
|
||||
#include "DNA_space_types.h"
|
||||
#include "DNA_userdef_types.h"
|
||||
|
@ -412,45 +414,26 @@ static void fileselect_refresh_asset_params(FileAssetSelectParams *asset_params)
|
|||
{
|
||||
AssetLibraryReference *library = &asset_params->asset_library_ref;
|
||||
FileSelectParams *base_params = &asset_params->base_params;
|
||||
CustomAssetLibraryDefinition *custom_library =
|
||||
ED_asset_library_find_custom_library_from_reference(library);
|
||||
|
||||
/* Ensure valid asset library, or fall-back to local one. */
|
||||
if (!custom_library) {
|
||||
if (!ED_asset_library_find_custom_library_from_reference(library)) {
|
||||
library->type = ASSET_LIBRARY_LOCAL;
|
||||
}
|
||||
|
||||
std::string root_path = AS_asset_library_root_path_from_library_ref(*library);
|
||||
BLI_strncpy(base_params->dir, root_path.c_str(), sizeof(base_params->dir));
|
||||
|
||||
switch (library->type) {
|
||||
case ASSET_LIBRARY_ALL:
|
||||
base_params->dir[0] = '\0';
|
||||
base_params->type = FILE_ASSET_LIBRARY_ALL;
|
||||
break;
|
||||
case ASSET_LIBRARY_LOCAL:
|
||||
base_params->dir[0] = '\0';
|
||||
base_params->type = FILE_MAIN_ASSET;
|
||||
break;
|
||||
case ASSET_LIBRARY_CUSTOM_FROM_PREFERENCES:
|
||||
BLI_assert(custom_library);
|
||||
BLI_strncpy(base_params->dir, custom_library->path, sizeof(base_params->dir));
|
||||
case ASSET_LIBRARY_CUSTOM_FROM_PROJECT:
|
||||
base_params->type = FILE_ASSET_LIBRARY;
|
||||
break;
|
||||
/* Project asset libraries typically use relative paths (relative to project root directory).
|
||||
*/
|
||||
case ASSET_LIBRARY_CUSTOM_FROM_PROJECT: {
|
||||
BlenderProject *project = CTX_wm_project();
|
||||
BLI_assert(custom_library);
|
||||
BLI_assert(project);
|
||||
|
||||
if (BLI_path_is_rel(custom_library->path)) {
|
||||
const char *project_root_path = BKE_project_root_path_get(project);
|
||||
BLI_path_join(
|
||||
base_params->dir, sizeof(base_params->dir), project_root_path, custom_library->path);
|
||||
}
|
||||
else {
|
||||
BLI_strncpy(base_params->dir, custom_library->path, sizeof(base_params->dir));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue