Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2020-12-14 15:39:41 +0300
committerJulian Eisel <julian@blender.org>2020-12-15 19:03:48 +0300
commite413c80371c1714d80262034d0e83b4e10e6cbe5 (patch)
treed25b0ec32070fdb8ca03c3ff1cf44bd7393d6bd0 /source/blender
parentb5d778a7d4072bfb091198a2094890157a6d017b (diff)
Asset System: Support custom asset library paths through Preferences
One of the core design aspects of the Asset Browser is that users can "mount" custom asset libraries via the Preferences. Currently an asset library is just a directory with one or more .blend files in it. We could easily support a single .blend file as asset library as well (rather than a directory). It's just disabled currently. Note that in earlier designs, asset libraries were called repositories. Idea is simple: In Preferences > File Paths, you can create custom libraries, by setting a name and selecting a path. The name is ensured to be unique. If the name or path are empty, the Asset Browser will not show it in the list of available asset libraries. The library path is not checked for validity, the Asset Browser will allow selecting invalid libraries, but show a message instead of the file list, to help the user understand what's going on. Of course the actual Asset Browser UI is not part of this commit, it's in one of the following ones. {F9497950} Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1 project milestone on developer.blender.org. Differential Revision: https://developer.blender.org/D9722 Reviewed by: Brecht Van Lommel, Hans Goudey
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/BKE_preferences.h56
-rw-r--r--source/blender/blenkernel/CMakeLists.txt2
-rw-r--r--source/blender/blenkernel/intern/blender.c1
-rw-r--r--source/blender/blenkernel/intern/blendfile.c3
-rw-r--r--source/blender/blenkernel/intern/preferences.c119
-rw-r--r--source/blender/blenloader/intern/readfile.c1
-rw-r--r--source/blender/blenloader/intern/versioning_userdef.c4
-rw-r--r--source/blender/blenloader/intern/writefile.c4
-rw-r--r--source/blender/editors/interface/interface_handlers.c6
-rw-r--r--source/blender/editors/space_buttons/buttons_ops.c2
-rw-r--r--source/blender/editors/space_userpref/userpref_ops.c61
-rw-r--r--source/blender/makesdna/DNA_userdef_types.h9
-rw-r--r--source/blender/makesrna/RNA_access.h1
-rw-r--r--source/blender/makesrna/intern/rna_userdef.c36
14 files changed, 303 insertions, 2 deletions
diff --git a/source/blender/blenkernel/BKE_preferences.h b/source/blender/blenkernel/BKE_preferences.h
new file mode 100644
index 00000000000..04a41d425bb
--- /dev/null
+++ b/source/blender/blenkernel/BKE_preferences.h
@@ -0,0 +1,56 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+/** \file
+ * \ingroup bke
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "BLI_compiler_attrs.h"
+
+struct UserDef;
+struct bUserAssetLibrary;
+
+void BKE_preferences_asset_library_free(struct bUserAssetLibrary *library) ATTR_NONNULL();
+
+struct bUserAssetLibrary *BKE_preferences_asset_library_add(struct UserDef *userdef,
+ const char *name,
+ const char *path) ATTR_NONNULL(1);
+void BKE_preferences_asset_library_name_set(struct UserDef *userdef,
+ struct bUserAssetLibrary *library,
+ const char *name) ATTR_NONNULL();
+
+void BKE_preferences_asset_library_remove(struct UserDef *userdef,
+ struct bUserAssetLibrary *library) ATTR_NONNULL();
+
+struct bUserAssetLibrary *BKE_preferences_asset_library_find_from_index(
+ const struct UserDef *userdef, int index) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+struct bUserAssetLibrary *BKE_preferences_asset_library_find_from_name(
+ const struct UserDef *userdef, const char *name) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+int BKE_preferences_asset_library_get_index(const struct UserDef *userdef,
+ const struct bUserAssetLibrary *library)
+ ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+
+void BKE_preferences_asset_library_default_add(struct UserDef *userdef) ATTR_NONNULL();
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 23ba4eb4235..0067e1c8209 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -215,6 +215,7 @@ set(SRC
intern/pbvh_bmesh.c
intern/pointcache.c
intern/pointcloud.cc
+ intern/preferences.c
intern/report.c
intern/rigidbody.c
intern/scene.c
@@ -376,6 +377,7 @@ set(SRC
BKE_persistent_data_handle.hh
BKE_pointcache.h
BKE_pointcloud.h
+ BKE_preferences.h
BKE_report.h
BKE_rigidbody.h
BKE_scene.h
diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c
index f4f25c3a153..5b5bd416ef2 100644
--- a/source/blender/blenkernel/intern/blender.c
+++ b/source/blender/blenkernel/intern/blender.c
@@ -296,6 +296,7 @@ void BKE_blender_userdef_data_free(UserDef *userdef, bool clear_fonts)
}
BLI_freelistN(&userdef->autoexec_paths);
+ BLI_freelistN(&userdef->asset_libraries);
BLI_freelistN(&userdef->uistyles);
BLI_freelistN(&userdef->uifonts);
diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c
index 567773507cf..0855db1a943 100644
--- a/source/blender/blenkernel/intern/blendfile.c
+++ b/source/blender/blenkernel/intern/blendfile.c
@@ -52,6 +52,7 @@
#include "BKE_layer.h"
#include "BKE_lib_id.h"
#include "BKE_main.h"
+#include "BKE_preferences.h"
#include "BKE_report.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
@@ -645,6 +646,8 @@ UserDef *BKE_blendfile_userdef_from_defaults(void)
/* Default studio light. */
BKE_studiolight_default(userdef->light_param, userdef->light_ambient);
+ BKE_preferences_asset_library_default_add(userdef);
+
return userdef;
}
diff --git a/source/blender/blenkernel/intern/preferences.c b/source/blender/blenkernel/intern/preferences.c
new file mode 100644
index 00000000000..c263ff7100f
--- /dev/null
+++ b/source/blender/blenkernel/intern/preferences.c
@@ -0,0 +1,119 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup bke
+ *
+ * User defined asset library API.
+ */
+
+#include <string.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_listbase.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
+#include "BLI_string_utf8.h"
+#include "BLI_string_utils.h"
+
+#include "BKE_appdir.h"
+#include "BKE_preferences.h"
+
+#include "BLT_translation.h"
+
+#include "DNA_userdef_types.h"
+
+#define U BLI_STATIC_ASSERT(false, "Global 'U' not allowed, only use arguments passed in!")
+
+/* -------------------------------------------------------------------- */
+/** \name Asset Libraries
+ * \{ */
+
+bUserAssetLibrary *BKE_preferences_asset_library_add(UserDef *userdef,
+ const char *name,
+ const char *path)
+{
+ bUserAssetLibrary *library = MEM_callocN(sizeof(*library), "bUserAssetLibrary");
+
+ BLI_addtail(&userdef->asset_libraries, library);
+
+ if (name) {
+ BKE_preferences_asset_library_name_set(userdef, library, name);
+ }
+ if (path) {
+ BLI_strncpy(library->path, path, sizeof(library->path));
+ }
+
+ return library;
+}
+
+void BKE_preferences_asset_library_name_set(UserDef *userdef,
+ bUserAssetLibrary *library,
+ const char *name)
+{
+ BLI_strncpy_utf8(library->name, name, sizeof(library->name));
+ BLI_uniquename(&userdef->asset_libraries,
+ library,
+ name,
+ '.',
+ offsetof(bUserAssetLibrary, name),
+ sizeof(library->name));
+}
+
+/**
+ * Unlink and free a library preference member.
+ * \note Free's \a library itself.
+ */
+void BKE_preferences_asset_library_remove(UserDef *userdef, bUserAssetLibrary *library)
+{
+ BLI_freelinkN(&userdef->asset_libraries, library);
+}
+
+bUserAssetLibrary *BKE_preferences_asset_library_find_from_index(const UserDef *userdef, int index)
+{
+ return BLI_findlink(&userdef->asset_libraries, index);
+}
+
+bUserAssetLibrary *BKE_preferences_asset_library_find_from_name(const UserDef *userdef,
+ const char *name)
+{
+ return BLI_findstring(&userdef->asset_libraries, name, offsetof(bUserAssetLibrary, name));
+}
+
+int BKE_preferences_asset_library_get_index(const UserDef *userdef,
+ const bUserAssetLibrary *library)
+{
+ return BLI_findindex(&userdef->asset_libraries, library);
+}
+
+void BKE_preferences_asset_library_default_add(UserDef *userdef)
+{
+ const char *asset_blend_name = "assets.blend";
+ const char *doc_path = BKE_appdir_folder_default();
+
+ /* No home or documents path found, not much we can do. */
+ if (!doc_path || !doc_path[0]) {
+ return;
+ }
+
+ /* Add new "Default" library under '[doc_path]/assets.blend'. */
+
+ bUserAssetLibrary *library = BKE_preferences_asset_library_add(userdef, DATA_("Default"), NULL);
+ BLI_join_dirfile(library->path, sizeof(library->path), doc_path, asset_blend_name);
+}
+
+/** \} */
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 8dff1aa1ed0..a3e793038f7 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -3904,6 +3904,7 @@ static BHead *read_userdef(BlendFileData *bfd, FileData *fd, BHead *bhead)
BLO_read_list(reader, &user->user_menus);
BLO_read_list(reader, &user->addons);
BLO_read_list(reader, &user->autoexec_paths);
+ BLO_read_list(reader, &user->asset_libraries);
LISTBASE_FOREACH (wmKeyMap *, keymap, &user->user_keymaps) {
keymap->modal_items = NULL;
diff --git a/source/blender/blenloader/intern/versioning_userdef.c b/source/blender/blenloader/intern/versioning_userdef.c
index 5ed7ab55851..f1572c563bf 100644
--- a/source/blender/blenloader/intern/versioning_userdef.c
+++ b/source/blender/blenloader/intern/versioning_userdef.c
@@ -44,6 +44,7 @@
#include "BKE_idprop.h"
#include "BKE_keyconfig.h"
#include "BKE_main.h"
+#include "BKE_preferences.h"
#include "BLO_readfile.h"
@@ -830,6 +831,9 @@ void blo_do_versions_userdef(UserDef *userdef)
*/
{
/* Keep this block, even when empty. */
+ if (BLI_listbase_is_empty(&userdef->asset_libraries)) {
+ BKE_preferences_asset_library_default_add(userdef);
+ }
}
LISTBASE_FOREACH (bTheme *, btheme, &userdef->themes) {
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index c64a7dc1b9f..e7d55538f7e 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -756,6 +756,10 @@ static void write_userdef(BlendWriter *writer, const UserDef *userdef)
BLO_write_struct(writer, bPathCompare, path_cmp);
}
+ LISTBASE_FOREACH (const bUserAssetLibrary *, asset_library, &userdef->asset_libraries) {
+ BLO_write_struct(writer, bUserAssetLibrary, asset_library);
+ }
+
LISTBASE_FOREACH (const uiStyle *, style, &userdef->uistyles) {
BLO_write_struct(writer, uiStyle, style);
}
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index f39ad4c4ed5..72ed2cc0933 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -626,7 +626,11 @@ static bool ui_rna_is_userdef(PointerRNA *ptr, PropertyRNA *prop)
if (base == NULL) {
base = ptr->type;
}
- if (ELEM(base, &RNA_AddonPreferences, &RNA_KeyConfigPreferences, &RNA_KeyMapItem)) {
+ if (ELEM(base,
+ &RNA_AddonPreferences,
+ &RNA_KeyConfigPreferences,
+ &RNA_KeyMapItem,
+ &RNA_UserAssetLibrary)) {
tag = true;
}
}
diff --git a/source/blender/editors/space_buttons/buttons_ops.c b/source/blender/editors/space_buttons/buttons_ops.c
index 8bdc2ed993f..8f57abf83ae 100644
--- a/source/blender/editors/space_buttons/buttons_ops.c
+++ b/source/blender/editors/space_buttons/buttons_ops.c
@@ -338,7 +338,7 @@ static int file_browse_invoke(bContext *C, wmOperator *op, const wmEvent *event)
is_relative = BLI_path_is_rel(str);
}
- if (UNLIKELY(ptr.data == &U)) {
+ if (UNLIKELY(ptr.data == &U || is_userdef)) {
is_relative = false;
}
diff --git a/source/blender/editors/space_userpref/userpref_ops.c b/source/blender/editors/space_userpref/userpref_ops.c
index d823530fd89..9cc8cc6ddaa 100644
--- a/source/blender/editors/space_userpref/userpref_ops.c
+++ b/source/blender/editors/space_userpref/userpref_ops.c
@@ -30,6 +30,7 @@
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_main.h"
+#include "BKE_preferences.h"
#include "BKE_report.h"
#include "RNA_access.h"
@@ -133,9 +134,69 @@ static void PREFERENCES_OT_autoexec_path_remove(wmOperatorType *ot)
/** \} */
+/* -------------------------------------------------------------------- */
+/** \name Add Asset Library Operator
+ * \{ */
+
+static int preferences_asset_library_add_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
+{
+ BKE_preferences_asset_library_add(&U, NULL, NULL);
+ U.runtime.is_dirty = true;
+ return OPERATOR_FINISHED;
+}
+
+static void PREFERENCES_OT_asset_library_add(wmOperatorType *ot)
+{
+ ot->name = "Add Asset Library";
+ ot->idname = "PREFERENCES_OT_asset_library_add";
+ ot->description =
+ "Add a path to a .blend file to be used by the Asset Browser as source of assets";
+
+ ot->exec = preferences_asset_library_add_exec;
+
+ ot->flag = OPTYPE_INTERNAL;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Remove Asset Library Operator
+ * \{ */
+
+static int preferences_asset_library_remove_exec(bContext *UNUSED(C), wmOperator *op)
+{
+ const int index = RNA_int_get(op->ptr, "index");
+ bUserAssetLibrary *library = BLI_findlink(&U.asset_libraries, index);
+ if (library) {
+ BKE_preferences_asset_library_remove(&U, library);
+ U.runtime.is_dirty = true;
+ }
+ return OPERATOR_FINISHED;
+}
+
+static void PREFERENCES_OT_asset_library_remove(wmOperatorType *ot)
+{
+ ot->name = "Remove Asset Library";
+ ot->idname = "PREFERENCES_OT_asset_library_remove";
+ ot->description =
+ "Remove a path to a .blend file, so the Asset Browser will not attempt to show it anymore";
+
+ ot->exec = preferences_asset_library_remove_exec;
+
+ ot->flag = OPTYPE_INTERNAL;
+
+ RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "", 0, 1000);
+}
+
+/** \} */
+
void ED_operatortypes_userpref(void)
{
WM_operatortype_append(PREFERENCES_OT_reset_default_theme);
+
WM_operatortype_append(PREFERENCES_OT_autoexec_path_add);
WM_operatortype_append(PREFERENCES_OT_autoexec_path_remove);
+
+ WM_operatortype_append(PREFERENCES_OT_asset_library_add);
+ WM_operatortype_append(PREFERENCES_OT_asset_library_remove);
}
diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h
index 8c4c43e4446..1bd013c7d54 100644
--- a/source/blender/makesdna/DNA_userdef_types.h
+++ b/source/blender/makesdna/DNA_userdef_types.h
@@ -569,6 +569,13 @@ enum {
USER_MENU_TYPE_PROP = 4,
};
+typedef struct bUserAssetLibrary {
+ struct bUserAssetLibrary *next, *prev;
+
+ char name[64]; /* MAX_NAME */
+ char path[1024]; /* FILE_MAX */
+} bUserAssetLibrary;
+
typedef struct SolidLight {
int flag;
float smooth;
@@ -740,6 +747,8 @@ typedef struct UserDef {
struct ListBase autoexec_paths;
/** #bUserMenu. */
struct ListBase user_menus;
+ /** #bUserAssetLibrary */
+ struct ListBase asset_libraries;
char keyconfigstr[64];
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index da15489370a..0b0895f9db0 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -697,6 +697,7 @@ extern StructRNA RNA_UVProjector;
extern StructRNA RNA_UVWarpModifier;
extern StructRNA RNA_UnitSettings;
extern StructRNA RNA_UnknownType;
+extern StructRNA RNA_UserAssetLibrary;
extern StructRNA RNA_UserSolidLight;
extern StructRNA RNA_VertexcolorGpencilModifier;
extern StructRNA RNA_VectorFont;
diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c
index 115bc221ce1..2175cddcd7f 100644
--- a/source/blender/makesrna/intern/rna_userdef.c
+++ b/source/blender/makesrna/intern/rna_userdef.c
@@ -184,6 +184,7 @@ static const EnumPropertyItem rna_enum_userdef_viewport_aa_items[] = {
# include "BKE_mesh_runtime.h"
# include "BKE_paint.h"
# include "BKE_pbvh.h"
+# include "BKE_preferences.h"
# include "BKE_screen.h"
# include "DEG_depsgraph.h"
@@ -335,6 +336,12 @@ static void rna_userdef_language_update(Main *UNUSED(bmain),
USERDEF_TAG_DIRTY;
}
+static void rna_userdef_asset_library_name_set(PointerRNA *ptr, const char *value)
+{
+ bUserAssetLibrary *library = (bUserAssetLibrary *)ptr->data;
+ BKE_preferences_asset_library_name_set(&U, library, value);
+}
+
static void rna_userdef_script_autoexec_update(Main *UNUSED(bmain),
Scene *UNUSED(scene),
PointerRNA *ptr)
@@ -5968,6 +5975,29 @@ static void rna_def_userdef_keymap(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Key Config", "The name of the active key configuration");
}
+static void rna_def_userdef_filepaths_asset_library(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna = RNA_def_struct(brna, "UserAssetLibrary", NULL);
+ RNA_def_struct_sdna(srna, "bUserAssetLibrary");
+ RNA_def_struct_clear_flag(srna, STRUCT_UNDO);
+ RNA_def_struct_ui_text(
+ srna, "Asset Library", "Settings to define a reusable library for Asset Browsers to use");
+
+ prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+ RNA_def_property_ui_text(
+ prop, "Name", "Identifier (not necessarily unique) for the asset library");
+ RNA_def_property_string_funcs(prop, NULL, NULL, "rna_userdef_asset_library_name_set");
+ RNA_def_struct_name_property(srna, prop);
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
+
+ prop = RNA_def_property(srna, "path", PROP_STRING, PROP_FILEPATH);
+ RNA_def_property_ui_text(prop, "Path", "Path to a .blend file to use as an asset library");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
+}
+
static void rna_def_userdef_filepaths(BlenderRNA *brna)
{
PropertyRNA *prop;
@@ -6140,6 +6170,12 @@ static void rna_def_userdef_filepaths(BlenderRNA *brna)
RNA_def_property_ui_text(prop,
"Save Preview Images",
"Enables automatic saving of preview images in the .blend file");
+
+ rna_def_userdef_filepaths_asset_library(brna);
+
+ prop = RNA_def_property(srna, "asset_libraries", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_struct_type(prop, "UserAssetLibrary");
+ RNA_def_property_ui_text(prop, "Asset Libraries", "");
}
static void rna_def_userdef_experimental(BlenderRNA *brna)