Add Preferences options to set up custom asset repositories

Can be found under the File Paths category. There already is a default
repository, called "Default" and pointing to the documents or home
directory. For most Linux users it will be ~/assets.blend, for Windows
users it will be the Documents directory.

Note that this is only the Preference part of this. The Asset-Browser
doesn't use this yet.

For now, asset repositories will be single .blend files. There are some
design questions regarding how the Asset Browser would display a
directory structure as repository.
This commit is contained in:
2020-10-01 15:21:28 +02:00
parent 45bb7d7013
commit d68be33df5
13 changed files with 273 additions and 1 deletions

View File

@@ -1246,6 +1246,28 @@ class USERPREF_PT_file_paths_data(FilePathsPanel, Panel):
col.prop(paths, "temporary_directory", text="Temporary Files")
class USERPREF_PT_file_paths_asset_repositories(FilePathsPanel, Panel):
bl_label = "Asset Repositories"
def draw(self, context):
layout = self.layout
layout.use_property_split = False
layout.use_property_decorate = False
paths = context.preferences.filepaths
box = layout.box()
for i, repository in enumerate(paths.asset_repositories):
row = box.row()
split = row.split(factor=0.65)
split.prop(repository, "path", text="")
split.prop(repository, "name")
row.operator("preferences.asset_repository_remove", text="", icon='X', emboss=False).index = i
row = box.row()
row.operator("preferences.asset_repository_add", text="", icon='ADD', emboss=False)
class USERPREF_PT_file_paths_render(FilePathsPanel, Panel):
bl_label = "Render"
@@ -2277,6 +2299,7 @@ classes = (
USERPREF_PT_theme_collection_colors,
USERPREF_PT_file_paths_data,
USERPREF_PT_file_paths_asset_repositories,
USERPREF_PT_file_paths_render,
USERPREF_PT_file_paths_applications,
USERPREF_PT_file_paths_development,

View File

@@ -39,7 +39,7 @@ extern "C" {
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
#define BLENDER_FILE_SUBVERSION 5
#define BLENDER_FILE_SUBVERSION 6
/* Minimum Blender version that supports reading file written with the current
* version. Older Blender versions will test this and show a warning if the file

View File

@@ -0,0 +1,46 @@
/*
* 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 bUserAssetRepository;
void BKE_preferences_asset_repository_free(struct bUserAssetRepository *repository) ATTR_NONNULL();
struct bUserAssetRepository *BKE_preferences_asset_repository_add(struct UserDef *userdef,
const char *name,
const char *path)
ATTR_NONNULL(1);
void BKE_preferences_asset_repository_remove(struct UserDef *userdef,
struct bUserAssetRepository *repository)
ATTR_NONNULL();
void BKE_preferences_asset_repository_default_add(struct UserDef *userdef) ATTR_NONNULL();
#ifdef __cplusplus
}
#endif

View File

@@ -209,6 +209,7 @@ set(SRC
intern/pbvh_bmesh.c
intern/pointcache.c
intern/pointcloud.c
intern/preferences.c
intern/report.c
intern/rigidbody.c
intern/scene.c
@@ -372,6 +373,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

View File

@@ -295,6 +295,7 @@ void BKE_blender_userdef_data_free(UserDef *userdef, bool clear_fonts)
}
BLI_freelistN(&userdef->autoexec_paths);
BLI_freelistN(&userdef->asset_repositories);
BLI_freelistN(&userdef->uistyles);
BLI_freelistN(&userdef->uifonts);

View File

@@ -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"
@@ -634,6 +635,8 @@ UserDef *BKE_blendfile_userdef_from_defaults(void)
/* Default studio light. */
BKE_studiolight_default(userdef->light_param, userdef->light_ambient);
BKE_preferences_asset_repository_default_add(userdef);
return userdef;
}

View File

@@ -0,0 +1,88 @@
/*
* 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 menu API.
*/
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_listbase.h"
#include "BLI_path_util.h"
#include "BLI_string.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 Repositories
* \{ */
bUserAssetRepository *BKE_preferences_asset_repository_add(UserDef *userdef,
const char *name,
const char *path)
{
bUserAssetRepository *repository = MEM_callocN(sizeof(*repository), "bUserAssetRepository");
BLI_addtail(&userdef->asset_repositories, repository);
if (name) {
BLI_strncpy(repository->name, IFACE_("Default"), sizeof(repository->name));
}
if (path) {
BLI_strncpy(repository->path, path, sizeof(repository->path));
}
return repository;
}
/**
* Unlink and free a repository preference member.
* \note Free's \a repository itself.
*/
void BKE_preferences_asset_repository_remove(UserDef *userdef, bUserAssetRepository *repository)
{
BLI_freelinkN(&userdef->asset_repositories, repository);
}
void BKE_preferences_asset_repository_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" repository under '[doc_path]/assets.blend'. */
bUserAssetRepository *repository = BKE_preferences_asset_repository_add(
userdef, DATA_("Default"), NULL);
BLI_join_dirfile(repository->path, sizeof(repository->path), doc_path, asset_blend_name);
}
/** \} */

View File

@@ -7147,6 +7147,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_repositories);
LISTBASE_FOREACH (wmKeyMap *, keymap, &user->user_keymaps) {
keymap->modal_items = NULL;

View File

@@ -43,6 +43,7 @@
#include "BKE_idprop.h"
#include "BKE_keyconfig.h"
#include "BKE_main.h"
#include "BKE_preferences.h"
#include "BLO_readfile.h" /* Own include. */
@@ -787,6 +788,10 @@ void BLO_version_defaults_userpref_blend(Main *bmain, UserDef *userdef)
}
}
if (!USER_VERSION_ATLEAST(291, 6)) {
BKE_preferences_asset_repository_default_add(userdef);
}
/**
* Versioning code until next subversion bump goes here.
*

View File

@@ -801,6 +801,10 @@ static void write_userdef(BlendWriter *writer, const UserDef *userdef)
BLO_write_struct(writer, bPathCompare, path_cmp);
}
LISTBASE_FOREACH (const bUserAssetRepository *, asset_repository, &userdef->asset_repositories) {
BLO_write_struct(writer, bUserAssetRepository, asset_repository);
}
LISTBASE_FOREACH (const uiStyle *, style, &userdef->uistyles) {
BLO_write_struct(writer, uiStyle, style);
}

View File

@@ -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 Repository Operator
* \{ */
static int preferences_asset_repository_add_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
{
BKE_preferences_asset_repository_add(&U, NULL, NULL);
U.runtime.is_dirty = true;
return OPERATOR_FINISHED;
}
static void PREFERENCES_OT_asset_repository_add(wmOperatorType *ot)
{
ot->name = "Add Asset Repository";
ot->idname = "PREFERENCES_OT_asset_repository_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_repository_add_exec;
ot->flag = OPTYPE_INTERNAL;
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Remove Asset Repository Operator
* \{ */
static int preferences_asset_repository_remove_exec(bContext *UNUSED(C), wmOperator *op)
{
const int index = RNA_int_get(op->ptr, "index");
bUserAssetRepository *repository = BLI_findlink(&U.asset_repositories, index);
if (repository) {
BKE_preferences_asset_repository_remove(&U, repository);
U.runtime.is_dirty = true;
}
return OPERATOR_FINISHED;
}
static void PREFERENCES_OT_asset_repository_remove(wmOperatorType *ot)
{
ot->name = "Remove Asset Repository";
ot->idname = "PREFERENCES_OT_asset_repository_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_repository_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_repository_add);
WM_operatortype_append(PREFERENCES_OT_asset_repository_remove);
}

View File

@@ -567,6 +567,13 @@ enum {
USER_MENU_TYPE_PROP = 4,
};
typedef struct bUserAssetRepository {
struct bUserAssetRepository *next, *prev;
char name[64]; /* MAX_NAME */
char path[1024]; /* FILE_MAX */
} bUserAssetRepository;
typedef struct SolidLight {
int flag;
float smooth;
@@ -733,6 +740,8 @@ typedef struct UserDef {
struct ListBase autoexec_paths;
/** #bUserMenu. */
struct ListBase user_menus;
/** #bUserAssetRepository */
struct ListBase asset_repositories;
char keyconfigstr[64];

View File

@@ -5949,6 +5949,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_repository(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
srna = RNA_def_struct(brna, "PreferencesAssetRepository", NULL);
RNA_def_struct_sdna(srna, "bUserAssetRepository");
RNA_def_struct_clear_flag(srna, STRUCT_UNDO);
RNA_def_struct_ui_text(srna,
"Asset Repository",
"Settings to define a reusable repository 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 repository");
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 repository");
RNA_def_property_update(prop, 0, "rna_userdef_update");
}
static void rna_def_userdef_filepaths(BlenderRNA *brna)
{
PropertyRNA *prop;
@@ -6120,6 +6143,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_repository(brna);
prop = RNA_def_property(srna, "asset_repositories", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, "PreferencesAssetRepository");
RNA_def_property_ui_text(prop, "Asset Repositories", "");
}
static void rna_def_userdef_experimental(BlenderRNA *brna)