WIP: uv-simple-select #1

Closed
Chris Blackbourn wants to merge 182 commits from uv-simple-select into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
14 changed files with 116 additions and 12 deletions
Showing only changes of commit 2a9cc75a37 - Show all commits

View File

@ -67,6 +67,9 @@ class AssetLibrary {
std::unique_ptr<AssetCatalogService> catalog_service;
/** Assets owned by this library should never be linked. */
bool never_link = false;
friend class AssetLibraryService;
public:

View File

@ -22,6 +22,8 @@ const char *AS_asset_representation_name_get(const AssetRepresentation *asset)
AssetMetaData *AS_asset_representation_metadata_get(const AssetRepresentation *asset)
ATTR_WARN_UNUSED_RESULT;
bool AS_asset_representation_is_local_id(const AssetRepresentation *asset) ATTR_WARN_UNUSED_RESULT;
bool AS_asset_representation_is_never_link(const AssetRepresentation *asset)
ATTR_WARN_UNUSED_RESULT;
#ifdef __cplusplus
}

View File

@ -0,0 +1,15 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup asset_system
*/
#pragma once
#include "BLI_string_ref.hh"
namespace blender::asset_system {
StringRefNull essentials_directory_path();
}

View File

@ -17,6 +17,7 @@ set(SRC
intern/asset_catalog.cc
intern/asset_catalog_path.cc
intern/asset_catalog_tree.cc
intern/asset_essentials_library.cc
intern/asset_identifier.cc
intern/asset_library.cc
intern/asset_library_service.cc
@ -30,6 +31,7 @@ set(SRC
AS_asset_identifier.hh
AS_asset_library.hh
AS_asset_representation.hh
AS_essentials_library.hh
intern/asset_library_service.hh
intern/asset_storage.hh
intern/utils.hh

View File

@ -0,0 +1,24 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup asset_system
*/
#include "BLI_path_util.h"
#include "BKE_appdir.h"
#include "AS_essentials_library.hh"
namespace blender::asset_system {
StringRefNull essentials_directory_path()
{
static std::string path = []() {
const char *datafiles_path = BKE_appdir_folder_id(BLENDER_DATAFILES, "assets");
return datafiles_path;
}();
return path;
}
} // namespace blender::asset_system

View File

@ -260,6 +260,12 @@ StringRefNull AssetLibrary::root_path() const
Vector<AssetLibraryReference> all_valid_asset_library_refs()
{
Vector<AssetLibraryReference> result;
{
AssetLibraryReference library_ref{};
library_ref.custom_library_index = -1;
library_ref.type = ASSET_LIBRARY_ESSENTIALS;
result.append(library_ref);
}
int i;
LISTBASE_FOREACH_INDEX (const bUserAssetLibrary *, asset_library, &U.asset_libraries, i) {
if (!BLI_is_dir(asset_library->path)) {

View File

@ -16,6 +16,7 @@
#include "AS_asset_catalog_tree.hh"
#include "AS_asset_library.hh"
#include "AS_essentials_library.hh"
#include "asset_library_service.hh"
#include "utils.hh"
@ -60,6 +61,12 @@ AssetLibrary *AssetLibraryService::get_asset_library(
const eAssetLibraryType type = eAssetLibraryType(library_reference.type);
switch (type) {
case ASSET_LIBRARY_ESSENTIALS: {
const StringRefNull root_path = essentials_directory_path();
AssetLibrary *asset_library = get_asset_library_on_disk(root_path);
asset_library->never_link = true;
return asset_library;
}
case ASSET_LIBRARY_LOCAL: {
/* For the "Current File" library we get the asset library root path based on main. */
std::string root_path = bmain ? AS_asset_library_find_suitable_root_path_from_main(bmain) :

View File

@ -10,6 +10,7 @@
#include "DNA_asset_types.h"
#include "AS_asset_identifier.hh"
#include "AS_asset_library.hh"
#include "AS_asset_representation.h"
#include "AS_asset_representation.hh"
@ -126,4 +127,11 @@ bool AS_asset_representation_is_local_id(const AssetRepresentation *asset_handle
return asset->is_local_id();
}
bool AS_asset_representation_is_never_link(const AssetRepresentation *asset_handle)
{
const asset_system::AssetRepresentation *asset =
reinterpret_cast<const asset_system::AssetRepresentation *>(asset_handle);
return asset->owner_asset_library().never_link;
}
/** \} */

View File

@ -47,7 +47,7 @@ AssetLibraryReference ED_asset_library_reference_from_enum_value(int value)
if (value < ASSET_LIBRARY_CUSTOM) {
library.type = value;
library.custom_library_index = -1;
BLI_assert(ELEM(value, ASSET_LIBRARY_ALL, ASSET_LIBRARY_LOCAL));
BLI_assert(ELEM(value, ASSET_LIBRARY_ALL, ASSET_LIBRARY_LOCAL, ASSET_LIBRARY_ESSENTIALS));
return library;
}
@ -87,6 +87,11 @@ const EnumPropertyItem *ED_asset_library_reference_to_rna_enum_itemf(const bool
ICON_CURRENT_FILE,
"Current File",
"Show the assets currently available in this Blender session"},
{ASSET_LIBRARY_ESSENTIALS,
"ESSENTIALS",
ICON_NONE,
"Essentials",
"Show the basic building blocks and utilities coming with Blender"},
{0, nullptr, 0, nullptr, nullptr},
};

View File

@ -372,6 +372,7 @@ std::optional<eFileSelectType> AssetListStorage::asset_library_reference_to_file
switch (eAssetLibraryType(library_reference.type)) {
case ASSET_LIBRARY_ALL:
return FILE_ASSET_LIBRARY_ALL;
case ASSET_LIBRARY_ESSENTIALS:
case ASSET_LIBRARY_CUSTOM:
return FILE_ASSET_LIBRARY;
case ASSET_LIBRARY_LOCAL:

View File

@ -55,6 +55,8 @@
#include "GPU_immediate_util.h"
#include "GPU_state.h"
#include "AS_asset_representation.h"
#include "filelist.h"
#include "file_intern.h" /* own include */
@ -126,6 +128,19 @@ static void draw_tile_background(const rcti *draw_rect, int colorid, int shade)
UI_draw_roundbox_aa(&draw_rect_fl, true, 5.0f, color);
}
static eFileAssetImportType get_asset_import_type(const SpaceFile *sfile, const FileDirEntry *file)
{
const FileAssetSelectParams *asset_params = ED_fileselect_get_asset_params(sfile);
BLI_assert(asset_params != NULL);
if (asset_params->import_type != FILE_ASSET_IMPORT_LINK) {
return asset_params->import_type;
}
if (AS_asset_representation_is_never_link(file->asset)) {
return FILE_ASSET_IMPORT_APPEND_REUSE;
}
return FILE_ASSET_IMPORT_LINK;
}
static void file_draw_icon(const SpaceFile *sfile,
uiBlock *block,
const FileDirEntry *file,
@ -165,13 +180,10 @@ static void file_draw_icon(const SpaceFile *sfile,
ImBuf *preview_image = filelist_file_getimage(file);
char blend_path[FILE_MAX_LIBEXTRA];
if (BLO_library_path_explode(path, blend_path, NULL, NULL)) {
const FileAssetSelectParams *asset_params = ED_fileselect_get_asset_params(sfile);
BLI_assert(asset_params != NULL);
UI_but_drag_set_asset(but,
&(AssetHandle){.file_data = file},
BLI_strdup(blend_path),
asset_params->import_type,
get_asset_import_type(sfile, file),
icon,
preview_image,
UI_DPI_FAC);
@ -558,13 +570,10 @@ static void file_draw_preview(const SpaceFile *sfile,
char blend_path[FILE_MAX_LIBEXTRA];
if (BLO_library_path_explode(path, blend_path, NULL, NULL)) {
const FileAssetSelectParams *asset_params = ED_fileselect_get_asset_params(sfile);
BLI_assert(asset_params != NULL);
UI_but_drag_set_asset(but,
&(AssetHandle){.file_data = file},
BLI_strdup(blend_path),
asset_params->import_type,
get_asset_import_type(sfile, file),
icon,
imb,
scale);

View File

@ -58,6 +58,8 @@
#include "UI_interface_icons.h"
#include "UI_view2d.h"
#include "AS_essentials_library.hh"
#include "file_intern.h"
#include "filelist.h"
@ -424,7 +426,13 @@ static void fileselect_refresh_asset_params(FileAssetSelectParams *asset_params)
}
}
switch (library->type) {
switch (eAssetLibraryType(library->type)) {
case ASSET_LIBRARY_ESSENTIALS:
BLI_strncpy(base_params->dir,
blender::asset_system::essentials_directory_path().c_str(),
sizeof(base_params->dir));
base_params->type = FILE_ASSET_LIBRARY;
break;
case ASSET_LIBRARY_ALL:
base_params->dir[0] = '\0';
base_params->type = FILE_ASSET_LIBRARY_ALL;

View File

@ -85,11 +85,11 @@ typedef struct AssetMetaData {
} AssetMetaData;
typedef enum eAssetLibraryType {
/* For the future. Display assets bundled with Blender by default. */
// ASSET_LIBRARY_BUNDLED = 0,
/** Display assets from the current session (current "Main"). */
ASSET_LIBRARY_LOCAL = 1,
ASSET_LIBRARY_ALL = 2,
/** Display assets bundled with Blender by default. */
ASSET_LIBRARY_ESSENTIALS = 3,
/** Display assets from custom asset libraries, as defined in the preferences
* (#bUserAssetLibrary). The name will be taken from #FileSelectParams.asset_library_ref.idname

View File

@ -1481,6 +1481,20 @@ install(
)
# -----------------------------------------------------------------------------
# Bundle assets
set(ASSET_BUNDLE_DIR ${CMAKE_SOURCE_DIR}/../lib/assets/publish/)
if(EXISTS "${ASSET_BUNDLE_DIR}")
install(
DIRECTORY ${ASSET_BUNDLE_DIR}
DESTINATION ${TARGETDIR_VER}/datafiles/assets
PATTERN ".svn" EXCLUDE
)
endif()
# -----------------------------------------------------------------------------
# Setup link libraries