[Bf-blender-cvs] [0a7a4d5] alembic_pointcache: Allow cache libraries to store both render and realtime (viewport) data.

Lukas Tönne noreply at git.blender.org
Thu Mar 19 21:01:42 CET 2015


Commit: 0a7a4d504b6790d8768d8e86bf0e8765c39aec71
Author: Lukas Tönne
Date:   Thu Mar 19 19:19:23 2015 +0100
Branches: alembic_pointcache
https://developer.blender.org/rB0a7a4d504b6790d8768d8e86bf0e8765c39aec71

Allow cache libraries to store both render and realtime (viewport) data.

This is the default now. It should make workflow a lot more foolproof
and convenient, since having only one of these modes active at a time
very easily leads to broken renders and confusing situations.

The problem is mostly due to the complicated way the depsgraph layer
feature is used to handle duplicator visibility. The duplicator is
declared as a child of its group's objects (even though no real
dependency exists!), so that a visible duplicator triggers updates of
invisible group objects, making instances of hidden groups possible.

However, dupli caches have to disable this dependency in order to avoid
unnecessary costly updates in hidden layers which are overridden by
cached data anyway. At the point where these dependencies are created
the evaluation context is unknown though, which means we cannot
distinguish between render and realtime evaluation for the purpose of
cache reading ...

===================================================================

M	release/scripts/startup/bl_ui/properties_object.py
M	source/blender/blenkernel/intern/cache_library.c
M	source/blender/blenkernel/intern/object_dupli.c
M	source/blender/editors/io/io_cache_library.c
M	source/blender/makesdna/DNA_cache_library_types.h
M	source/blender/makesrna/intern/rna_cache_library.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_object.py b/release/scripts/startup/bl_ui/properties_object.py
index 7aa82c5..a36d321 100644
--- a/release/scripts/startup/bl_ui/properties_object.py
+++ b/release/scripts/startup/bl_ui/properties_object.py
@@ -340,7 +340,8 @@ class OBJECT_PT_duplication(ObjectButtonsPanel, Panel):
         row.prop(ob, "use_dupli_cache_read", text="Read", toggle=True)
         row.prop(ob, "use_dupli_cache_write", text="Write", toggle=True)
         col.operator("cachelibrary.bake")
-        col.prop(cachelib, "eval_mode", expand=False)
+        row = col.row(align=True)
+        row.prop(cachelib, "eval_mode", toggle=True, expand=True)
 
         row = layout.row(align=True)
         row.label("Filter:")
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index bdb7a8a..c4dc4da 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -69,6 +69,8 @@ CacheLibrary *BKE_cache_library_add(Main *bmain, const char *name)
 	BLI_filename_make_safe(basename);
 	BLI_snprintf(cachelib->filepath, sizeof(cachelib->filepath), "//cache/%s.%s", basename, PTC_get_default_archive_extension());
 
+	cachelib->eval_mode = CACHE_LIBRARY_EVAL_REALTIME | CACHE_LIBRARY_EVAL_RENDER;
+
 	return cachelib;
 }
 
@@ -658,7 +660,7 @@ bool BKE_cache_read_dupligroup(Scene *scene, float frame, eCacheLibrary_EvalMode
 	
 	if (!dupcache || !dupgroup || !cachelib)
 		return false;
-	if (cachelib->eval_mode != eval_mode)
+	if (!(cachelib->eval_mode & eval_mode))
 		return false;
 	
 	BKE_cache_archive_path(cachelib->filepath, (ID *)cachelib, cachelib->id.lib, filename, sizeof(filename));
@@ -681,7 +683,7 @@ bool BKE_cache_read_dupligroup(Scene *scene, float frame, eCacheLibrary_EvalMode
 void BKE_cache_library_dag_recalc_tag(EvaluationContext *eval_ctx, Main *bmain)
 {
 #if 0
-	eCacheLibrary_EvalMode eval_mode = (eval_ctx->mode == DAG_EVAL_RENDER) ? CACHE_LIBRARY_EVAL_RENDER : CACHE_LIBRARY_EVAL_VIEWPORT;
+	eCacheLibrary_EvalMode eval_mode = (eval_ctx->mode == DAG_EVAL_RENDER) ? CACHE_LIBRARY_EVAL_RENDER : CACHE_LIBRARY_EVAL_REALTIME;
 	CacheLibrary *cachelib;
 	
 	FOREACH_CACHELIB_READ(bmain, cachelib, eval_mode) {
diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index d1dbf28..fa4c20a 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -1394,7 +1394,7 @@ static DupliObject *dupli_cache_add_object(DupliCache *dupcache)
 
 void BKE_object_dupli_cache_update(Scene *scene, Object *ob, EvaluationContext *eval_ctx, float frame)
 {
-	const eCacheLibrary_EvalMode eval_mode = eval_ctx->mode == DAG_EVAL_RENDER ? CACHE_LIBRARY_EVAL_RENDER : CACHE_LIBRARY_EVAL_VIEWPORT;
+	const eCacheLibrary_EvalMode eval_mode = eval_ctx->mode == DAG_EVAL_RENDER ? CACHE_LIBRARY_EVAL_RENDER : CACHE_LIBRARY_EVAL_REALTIME;
 	
 	bool is_dupligroup = (ob->transflag & OB_DUPLIGROUP) && ob->dup_group;
 	bool is_cached = (ob->transflag & OB_DUPLI_READ_CACHE) && ob->cache_library;
diff --git a/source/blender/editors/io/io_cache_library.c b/source/blender/editors/io/io_cache_library.c
index 1cf7fda..edb1901 100644
--- a/source/blender/editors/io/io_cache_library.c
+++ b/source/blender/editors/io/io_cache_library.c
@@ -260,11 +260,29 @@ static void cache_library_bake_freejob(void *customdata)
 	MEM_freeN(data);
 }
 
-static void cache_library_bake_startjob(void *customdata, short *stop, short *do_update, float *progress)
+static void cache_library_bake_do(CacheLibraryBakeJob *data, short *stop, short *do_update, float *progress)
 {
-	CacheLibraryBakeJob *data= (CacheLibraryBakeJob *)customdata;
 	Scene *scene = data->scene;
 	int start_frame, end_frame;
+	
+	data->writer = PTC_writer_dupligroup(data->group->id.name, &data->eval_ctx, scene, data->group);
+	PTC_writer_init(data->writer, data->archive);
+	
+	/* XXX where to get this from? */
+	start_frame = scene->r.sfra;
+	end_frame = scene->r.efra;
+	PTC_bake(data->bmain, scene, &data->eval_ctx, data->writer, start_frame, end_frame, stop, do_update, progress);
+	
+	if (data->writer) {
+		PTC_writer_free(data->writer);
+		data->writer = NULL;
+	}
+}
+
+static void cache_library_bake_startjob(void *customdata, short *stop, short *do_update, float *progress)
+{
+	CacheLibraryBakeJob *data = (CacheLibraryBakeJob *)customdata;
+	Scene *scene = data->scene;
 	char filename[FILE_MAX];
 	
 	data->stop = stop;
@@ -274,28 +292,24 @@ static void cache_library_bake_startjob(void *customdata, short *stop, short *do
 	data->origfra = scene->r.cfra;
 	data->origframelen = scene->r.framelen;
 	scene->r.framelen = 1.0f;
-	memset(&data->eval_ctx, 0, sizeof(EvaluationContext));
-	/* use evaluation mode defined by the cachelib */
-	if (data->cachelib->eval_mode == CACHE_LIBRARY_EVAL_VIEWPORT) {
-		data->eval_ctx.mode = DAG_EVAL_VIEWPORT;
-	}
-	else {
-		data->eval_ctx.mode = DAG_EVAL_RENDER;
-	}
 	
 	BKE_cache_archive_path(data->cachelib->filepath, (ID *)data->cachelib, data->cachelib->id.lib, filename, sizeof(filename));
 	data->archive = PTC_open_writer_archive(scene, filename);
 	
 	if (data->archive) {
-		data->writer = PTC_writer_dupligroup(data->group->id.name, &data->eval_ctx, scene, data->group);
-		PTC_writer_init(data->writer, data->archive);
 		
 		G.is_break = false;
 		
-		/* XXX where to get this from? */
-		start_frame = scene->r.sfra;
-		end_frame = scene->r.efra;
-		PTC_bake(data->bmain, scene, &data->eval_ctx, data->writer, start_frame, end_frame, stop, do_update, progress);
+		if (data->cachelib->eval_mode & CACHE_LIBRARY_EVAL_REALTIME) {
+			data->eval_ctx.mode = DAG_EVAL_VIEWPORT;
+			cache_library_bake_do(data, stop, do_update, progress);
+		}
+		
+		if (data->cachelib->eval_mode & CACHE_LIBRARY_EVAL_RENDER) {
+			data->eval_ctx.mode = DAG_EVAL_RENDER;
+			cache_library_bake_do(data, stop, do_update, progress);
+		}
+		
 	}
 	
 	*do_update = true;
diff --git a/source/blender/makesdna/DNA_cache_library_types.h b/source/blender/makesdna/DNA_cache_library_types.h
index baa5bee..114b869 100644
--- a/source/blender/makesdna/DNA_cache_library_types.h
+++ b/source/blender/makesdna/DNA_cache_library_types.h
@@ -87,8 +87,8 @@ typedef struct CacheLibrary {
 //} eCacheLibrary_Flag;
 
 typedef enum eCacheLibrary_EvalMode {
-	CACHE_LIBRARY_EVAL_VIEWPORT     = 0, /* evaluate data with viewport settings */
-	CACHE_LIBRARY_EVAL_RENDER       = 1, /* evaluate data with render settings */
+	CACHE_LIBRARY_EVAL_REALTIME     = (1 << 0), /* evaluate data with realtime settings */
+	CACHE_LIBRARY_EVAL_RENDER       = (1 << 1), /* evaluate data with render settings */
 } eCacheLibrary_EvalMode;
 
 #endif
diff --git a/source/blender/makesrna/intern/rna_cache_library.c b/source/blender/makesrna/intern/rna_cache_library.c
index 83a47fe..975201f 100644
--- a/source/blender/makesrna/intern/rna_cache_library.c
+++ b/source/blender/makesrna/intern/rna_cache_library.c
@@ -286,7 +286,7 @@ static void rna_def_cache_library(BlenderRNA *brna)
 	PropertyRNA *prop, *parm;
 	
 	static EnumPropertyItem eval_mode_items[] = {
-	    {CACHE_LIBRARY_EVAL_VIEWPORT,   "VIEWPORT",     ICON_RESTRICT_VIEW_OFF,     "Viewport",     "Evaluate data with viewport settings"},
+	    {CACHE_LIBRARY_EVAL_REALTIME,   "REALTIME",     ICON_RESTRICT_VIEW_OFF,     "Realtime",     "Evaluate data with realtime settings"},
 	    {CACHE_LIBRARY_EVAL_RENDER,     "RENDER",       ICON_RESTRICT_RENDER_OFF,   "Render",       "Evaluate data with render settings"},
 	    {0, NULL, 0, NULL, NULL}
 	};
@@ -303,7 +303,7 @@ static void rna_def_cache_library(BlenderRNA *brna)
 	prop = RNA_def_property(srna, "eval_mode", PROP_ENUM, PROP_NONE);
 	RNA_def_property_enum_sdna(prop, NULL, "eval_mode");
 	RNA_def_property_enum_items(prop, eval_mode_items);
-	RNA_def_property_enum_default(prop, CACHE_LIBRARY_EVAL_VIEWPORT);
+	RNA_def_property_flag(prop, PROP_ENUM_FLAG);
 	RNA_def_property_ui_text(prop, "Evaluation Mode", "Mode to use when evaluating data");
 	RNA_def_property_update(prop, 0, "rna_CacheLibrary_update");




More information about the Bf-blender-cvs mailing list