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:
authorKévin Dietrich <kevin.dietrich@mailoo.org>2022-01-17 16:50:47 +0300
committerKévin Dietrich <kevin.dietrich@mailoo.org>2022-01-17 16:51:04 +0300
commit0a08ac2528eee972c4dc23554ffd088305e6ae92 (patch)
tree2ef9014dc16053ce6d249d877110766b0972a2ac /source/blender/editors
parent9d3f35a0bf1bf5776363bfd61d53a7c85b5827a4 (diff)
Alembic: add support for reading override layers
Override layers are a standard feature of Alembic, where archives can override data from other archives, provided that the hierarchies match. This is useful for modifying a UV map, updating an animation, or even creating some sort of LOD system where low resolution meshes are swapped by high resolution versions. It is possible to add UV maps and vertex colors using this system, however, they will only appear in the spreadsheet editor when viewing evaluated data, as the UV map and Vertex color UI only show data present on the original mesh. Implementation wise, this adds a `CacheFileLayer` data structure to the `CacheFile` DNA, as well as some operators and UI to present and manage the layers. For both the Alembic importer and the Cycles procedural, the main change is creating an archive from a list of filepaths, instead of a single one. After importing the base file through the regular import operator, layers can be added to or removed from the `CacheFile` via the UI list under the `Override Layers` panel located in the Mesh Sequence Cache modifier. Layers can also be moved around or hidden. See differential page for tests files and demos. Reviewed by: brecht, sybren Differential Revision: https://developer.blender.org/D13603
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/include/UI_interface.h7
-rw-r--r--source/blender/editors/interface/interface_intern.h3
-rw-r--r--source/blender/editors/interface/interface_template_list.cc1
-rw-r--r--source/blender/editors/interface/interface_templates.c61
-rw-r--r--source/blender/editors/io/io_cache.c168
-rw-r--r--source/blender/editors/io/io_cache.h4
-rw-r--r--source/blender/editors/io/io_ops.c5
7 files changed, 247 insertions, 2 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 9ce07cd2e07..3796fa51499 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -2426,6 +2426,13 @@ void uiTemplateCacheFileProcedural(uiLayout *layout,
*/
void uiTemplateCacheFileTimeSettings(uiLayout *layout, struct PointerRNA *fileptr);
+/**
+ * Draw the override layers related properties of the CacheFile.
+ */
+void uiTemplateCacheFileLayers(uiLayout *layout,
+ const struct bContext *C,
+ struct PointerRNA *fileptr);
+
/* Default UIList class name, keep in sync with its declaration in bl_ui/__init__.py */
#define UI_UL_DEFAULT_CLASS_NAME "UI_UL_list"
enum uiTemplateListFlags {
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 923f741e3ae..2d1138b46a7 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -1528,6 +1528,9 @@ uiTreeViewHandle *ui_block_view_find_matching_in_old_block(const uiBlock *new_bl
uiButTreeRow *ui_block_view_find_treerow_in_old_block(const uiBlock *new_block,
const uiTreeViewItemHandle *new_item_handle);
+/* interface_templates.c */
+struct uiListType *UI_UL_cache_file_layers(void);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/editors/interface/interface_template_list.cc b/source/blender/editors/interface/interface_template_list.cc
index 13e539b5095..817599605a9 100644
--- a/source/blender/editors/interface/interface_template_list.cc
+++ b/source/blender/editors/interface/interface_template_list.cc
@@ -1322,6 +1322,7 @@ PointerRNA *UI_list_custom_drag_operator_set(uiList *ui_list,
void ED_uilisttypes_ui()
{
WM_uilisttype_add(UI_UL_asset_view());
+ WM_uilisttype_add(UI_UL_cache_file_layers());
}
/** \} */
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 00e9a75848a..8330f8c0db7 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -6474,6 +6474,67 @@ void uiTemplateCacheFileTimeSettings(uiLayout *layout, PointerRNA *fileptr)
uiLayoutSetActive(row, !RNA_boolean_get(fileptr, "is_sequence"));
}
+static void cache_file_layer_item(uiList *UNUSED(ui_list),
+ bContext *UNUSED(C),
+ uiLayout *layout,
+ PointerRNA *UNUSED(dataptr),
+ PointerRNA *itemptr,
+ int UNUSED(icon),
+ PointerRNA *UNUSED(active_dataptr),
+ const char *UNUSED(active_propname),
+ int UNUSED(index),
+ int UNUSED(flt_flag))
+{
+ uiLayout *row = uiLayoutRow(layout, true);
+ uiItemR(row, itemptr, "hide_layer", UI_ITEM_R_NO_BG, "", ICON_NONE);
+ uiItemR(row, itemptr, "filepath", UI_ITEM_R_NO_BG, "", ICON_NONE);
+}
+
+uiListType *UI_UL_cache_file_layers()
+{
+ uiListType *list_type = (uiListType *)MEM_callocN(sizeof(*list_type), __func__);
+
+ BLI_strncpy(list_type->idname, "UI_UL_cache_file_layers", sizeof(list_type->idname));
+ list_type->draw_item = cache_file_layer_item;
+
+ return list_type;
+}
+
+void uiTemplateCacheFileLayers(uiLayout *layout, const bContext *C, PointerRNA *fileptr)
+{
+ /* Ensure that the context has a CacheFile as this may not be set inside of modifiers panels. */
+ uiLayoutSetContextPointer(layout, "edit_cachefile", fileptr);
+
+ uiLayout *row = uiLayoutRow(layout, false);
+ uiLayout *col = uiLayoutColumn(row, true);
+
+ uiTemplateList(col,
+ (bContext *)C,
+ "UI_UL_cache_file_layers",
+ "cache_file_layers",
+ fileptr,
+ "layers",
+ fileptr,
+ "active_index",
+ "",
+ 1,
+ 5,
+ UILST_LAYOUT_DEFAULT,
+ 1,
+ UI_TEMPLATE_LIST_FLAG_NONE);
+
+ col = uiLayoutColumn(row, true);
+ uiItemO(col, "", ICON_ADD, "cachefile.layer_add");
+ uiItemO(col, "", ICON_REMOVE, "cachefile.layer_remove");
+
+ CacheFile *file = fileptr->data;
+ if (BLI_listbase_count(&file->layers) > 1) {
+ uiItemS_ex(col, 1.0f);
+ uiItemO(col, "", ICON_TRIA_UP, "cachefile.layer_move");
+ uiItemO(col, "", ICON_TRIA_DOWN, "cachefile.layer_move");
+ }
+}
+
bool uiTemplateCacheFilePointer(PointerRNA *ptr, const char *propname, PointerRNA *r_file_ptr)
{
PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
diff --git a/source/blender/editors/io/io_cache.c b/source/blender/editors/io/io_cache.c
index bf20c1f6438..4f71a804986 100644
--- a/source/blender/editors/io/io_cache.c
+++ b/source/blender/editors/io/io_cache.c
@@ -26,6 +26,7 @@
#include "DNA_cachefile_types.h"
#include "DNA_space_types.h"
+#include "BLI_listbase.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
@@ -36,6 +37,7 @@
#include "BKE_report.h"
#include "RNA_access.h"
+#include "RNA_define.h"
#include "DEG_depsgraph.h"
@@ -46,6 +48,12 @@
#include "io_cache.h"
+static void reload_cachefile(bContext *C, CacheFile *cache_file)
+{
+ Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
+ BKE_cachefile_reload(depsgraph, cache_file);
+}
+
static void cachefile_init(bContext *C, wmOperator *op)
{
PropertyPointerRNA *pprop;
@@ -146,8 +154,7 @@ static int cachefile_reload_exec(bContext *C, wmOperator *UNUSED(op))
return OPERATOR_CANCELLED;
}
- Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
- BKE_cachefile_reload(depsgraph, cache_file);
+ reload_cachefile(C, cache_file);
return OPERATOR_FINISHED;
}
@@ -164,3 +171,160 @@ void CACHEFILE_OT_reload(wmOperatorType *ot)
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
+
+/* ***************************** Add Layer Operator **************************** */
+
+static int cachefile_layer_open_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
+ char filepath[FILE_MAX];
+ Main *bmain = CTX_data_main(C);
+
+ BLI_strncpy(filepath, BKE_main_blendfile_path(bmain), sizeof(filepath));
+ BLI_path_extension_replace(filepath, sizeof(filepath), ".abc");
+ RNA_string_set(op->ptr, "filepath", filepath);
+ }
+
+ /* There is no more CacheFile set when returning from the file selector, so store it here. */
+ op->customdata = CTX_data_edit_cachefile(C);
+
+ WM_event_add_fileselect(C, op);
+
+ return OPERATOR_RUNNING_MODAL;
+
+ UNUSED_VARS(event);
+}
+
+static int cachefile_layer_add_exec(bContext *C, wmOperator *op)
+{
+ if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
+ BKE_report(op->reports, RPT_ERROR, "No filename given");
+ return OPERATOR_CANCELLED;
+ }
+
+ CacheFile *cache_file = op->customdata;
+
+ if (!cache_file) {
+ return OPERATOR_CANCELLED;
+ }
+
+ char filename[FILE_MAX];
+ RNA_string_get(op->ptr, "filepath", filename);
+
+ CacheFileLayer *layer = BKE_cachefile_add_layer(cache_file, filename);
+
+ if (!layer) {
+ WM_report(RPT_ERROR, "Could not add a layer to the cache file");
+ return OPERATOR_CANCELLED;
+ }
+
+ reload_cachefile(C, cache_file);
+ WM_main_add_notifier(NC_OBJECT | ND_DRAW, NULL);
+ return OPERATOR_FINISHED;
+}
+
+void CACHEFILE_OT_layer_add(wmOperatorType *ot)
+{
+ ot->name = "Add layer";
+ ot->description = "Add an override layer to the archive";
+ ot->idname = "CACHEFILE_OT_layer_add";
+
+ /* api callbacks */
+ ot->invoke = cachefile_layer_open_invoke;
+ ot->exec = cachefile_layer_add_exec;
+
+ WM_operator_properties_filesel(ot,
+ FILE_TYPE_ALEMBIC | FILE_TYPE_FOLDER,
+ FILE_BLENDER,
+ FILE_OPENFILE,
+ WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH,
+ FILE_DEFAULTDISPLAY,
+ FILE_SORT_DEFAULT);
+}
+
+/* ***************************** Remove Layer Operator **************************** */
+
+static int cachefile_layer_remove_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ CacheFile *cache_file = CTX_data_edit_cachefile(C);
+
+ if (!cache_file) {
+ return OPERATOR_CANCELLED;
+ }
+
+ CacheFileLayer *layer = BKE_cachefile_get_active_layer(cache_file);
+ BKE_cachefile_remove_layer(cache_file, layer);
+
+ reload_cachefile(C, cache_file);
+ WM_main_add_notifier(NC_OBJECT | ND_DRAW, NULL);
+ return OPERATOR_FINISHED;
+}
+
+void CACHEFILE_OT_layer_remove(wmOperatorType *ot)
+{
+ ot->name = "Add layer";
+ ot->description = "Remove an override layer to the archive";
+ ot->idname = "CACHEFILE_OT_layer_remove";
+
+ /* api callbacks */
+ ot->exec = cachefile_layer_remove_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+/* ***************************** Move Layer Operator **************************** */
+
+static int cachefile_layer_move_exec(bContext *C, wmOperator *op)
+{
+ CacheFile *cache_file = CTX_data_edit_cachefile(C);
+
+ if (!cache_file) {
+ return OPERATOR_CANCELLED;
+ }
+
+ CacheFileLayer *layer = BKE_cachefile_get_active_layer(cache_file);
+
+ if (!layer) {
+ return OPERATOR_CANCELLED;
+ }
+
+ const int dir = RNA_enum_get(op->ptr, "direction");
+
+ if (BLI_listbase_link_move(&cache_file->layers, layer, dir)) {
+ cache_file->active_layer = BLI_findindex(&cache_file->layers, layer) + 1;
+ /* Only reload if something moved, might be expensive. */
+ reload_cachefile(C, cache_file);
+ WM_main_add_notifier(NC_OBJECT | ND_DRAW, NULL);
+ }
+
+ return OPERATOR_FINISHED;
+}
+
+void CACHEFILE_OT_layer_move(wmOperatorType *ot)
+{
+ static const EnumPropertyItem layer_slot_move[] = {
+ {-1, "UP", 0, "Up", ""},
+ {1, "DOWN", 0, "Down", ""},
+ {0, NULL, 0, NULL, NULL},
+ };
+
+ ot->name = "Move layer";
+ ot->description =
+ "Move layer in the list, layers further down the list will overwrite data from the layers "
+ "higher up";
+ ot->idname = "CACHEFILE_OT_layer_move";
+
+ /* api callbacks */
+ ot->exec = cachefile_layer_move_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ RNA_def_enum(ot->srna,
+ "direction",
+ layer_slot_move,
+ 0,
+ "Direction",
+ "Direction to move the active vertex group towards");
+}
diff --git a/source/blender/editors/io/io_cache.h b/source/blender/editors/io/io_cache.h
index be6e31842af..297e065434f 100644
--- a/source/blender/editors/io/io_cache.h
+++ b/source/blender/editors/io/io_cache.h
@@ -27,3 +27,7 @@ struct wmOperatorType;
void CACHEFILE_OT_open(struct wmOperatorType *ot);
void CACHEFILE_OT_reload(struct wmOperatorType *ot);
+
+void CACHEFILE_OT_layer_add(struct wmOperatorType *ot);
+void CACHEFILE_OT_layer_remove(struct wmOperatorType *ot);
+void CACHEFILE_OT_layer_move(struct wmOperatorType *ot);
diff --git a/source/blender/editors/io/io_ops.c b/source/blender/editors/io/io_ops.c
index 5dff0b69c2a..d9bbd7d8692 100644
--- a/source/blender/editors/io/io_ops.c
+++ b/source/blender/editors/io/io_ops.c
@@ -69,5 +69,10 @@ void ED_operatortypes_io(void)
WM_operatortype_append(CACHEFILE_OT_open);
WM_operatortype_append(CACHEFILE_OT_reload);
+
+ WM_operatortype_append(CACHEFILE_OT_layer_add);
+ WM_operatortype_append(CACHEFILE_OT_layer_remove);
+ WM_operatortype_append(CACHEFILE_OT_layer_move);
+
WM_operatortype_append(WM_OT_obj_export);
}