[Bf-blender-cvs] [fccc665] gooseberry: Changed implementation of the Cache modifier to work in tandem with the cache library system.

Lukas Tönne noreply at git.blender.org
Mon Mar 23 13:01:35 CET 2015


Commit: fccc665162ce27019b5f6c39296a7d5f62777a43
Author: Lukas Tönne
Date:   Thu Feb 26 11:50:56 2015 +0100
Branches: gooseberry
https://developer.blender.org/rBfccc665162ce27019b5f6c39296a7d5f62777a43

Changed implementation of the Cache modifier to work in tandem with the
cache library system.

The Cache modifier is now an optional "break point" of the modifier
stack:
- Without a cache modifier the stack works as before. Baking will write
  the final stack result. After baking the cache replaces the whole
  stack.
- With a cache modifier the stack result at the modifier's position is
  stored. The cache is then applied as the output of that modifier,
  skipping preceding modifiers. That way additional modifiers can be
  applied on top of the cache.
- When using multiple cache modifiers, only the last (active) one will
  be used, since all previous cache results would be discarded anyway.

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/blenkernel/BKE_DerivedMesh.h
M	source/blender/blenkernel/intern/DerivedMesh.c
M	source/blender/editors/io/io_cache_library.c
M	source/blender/editors/space_outliner/outliner_draw.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/CMakeLists.txt
M	source/blender/modifiers/MOD_modifiertypes.h
A	source/blender/modifiers/intern/MOD_cache.c
D	source/blender/modifiers/intern/MOD_pointcache.c
M	source/blender/modifiers/intern/MOD_util.c
M	source/blender/pointcache/PTC_api.cpp
M	source/blender/pointcache/PTC_api.h
M	source/blender/pointcache/alembic/abc_mesh.cpp
M	source/blender/pointcache/alembic/abc_mesh.h
M	source/blender/pointcache/intern/alembic.h

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index ff91117..bf680cf 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -170,6 +170,9 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         sub.active = md.use_random_order
         sub.prop(md, "seed")
 
+    def CACHE(self, layout, ob, md):
+        pass
+
     def MESH_CACHE(self, layout, ob, md):
         layout.prop(md, "cache_format")
         layout.prop(md, "filepath")
@@ -692,12 +695,6 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
     def PARTICLE_SYSTEM(self, layout, ob, md):
         layout.label(text="Settings can be found inside the Particle context")
 
-    def POINT_CACHE(self, layout, ob, md):
-        col = layout.column()
-        col.context_pointer_set("point_cache", md.point_cache)
-        col.context_pointer_set("point_cache_user", md)
-        col.operator("PTCACHE_OT_export")
-
     def SCREW(self, layout, ob, md):
         split = layout.split()
 
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h
index a026cc2..75092e6 100644
--- a/source/blender/blenkernel/BKE_DerivedMesh.h
+++ b/source/blender/blenkernel/BKE_DerivedMesh.h
@@ -664,6 +664,8 @@ DMCoNo *mesh_get_mapped_verts_nors(struct Scene *scene, struct Object *ob);
 #endif
 void mesh_get_mapped_verts_coords(DerivedMesh *dm, float (*r_cos)[3], const int totcos);
 
+struct ModifierData *mesh_find_cache_modifier(struct Scene *scene, struct Object *ob, int required_mode);
+
 /* */
 DerivedMesh *mesh_get_derived_final(struct Scene *scene, struct Object *ob,
                                     CustomDataMask dataMask);
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index c3490d5..414513d 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -1494,45 +1494,30 @@ static void dm_ensure_display_normals(DerivedMesh *dm)
 	}
 }
 
-/* Look for last point cache modifier that provides a valid derived mesh.
- * This will then be used as the input for remaining modifiers, or as the
- * final result if no other modifiers follow.
+/* Look for last active cache modifier.
+ * This will then be used as the input for remaining modifiers,
+ * or as the final result if no other modifiers follow.
  */
-static ModifierData *mesh_find_start_modifier(Scene *scene, Object *ob, VirtualModifierData *virtual_modifiers, int required_mode, bool useDeform)
+ModifierData *mesh_find_cache_modifier(Scene *scene, Object *ob, int required_mode)
 {
-	const bool skipVirtualArmature = (useDeform < 0);
-	
 	ModifierData *md;
 	
-#if 0
 	for (md = ob->modifiers.last; md; md = md->prev) {
-		if (md->type == eModifierType_PointCache) {
-			PointCacheModifierData *pcmd = (PointCacheModifierData *)md;
-			struct PTCReader *reader;
-			PTCReadSampleResult result;
-			
-			if (!modifier_isEnabled(scene, md, required_mode))
-				continue;
-			
-			/* XXX needs a more lightweight reader stored inside the modifier,
-			 * which can be checked quickly for valid cache samples before reading.
-			 */
-			reader = PTC_reader_point_cache(scene, ob, pcmd);
-			result = PTC_test_sample(reader, scene->r.cfra);
-			PTC_reader_free(reader);
-			
-			if (ELEM(result, PTC_READ_SAMPLE_EXACT, PTC_READ_SAMPLE_INTERPOLATED)) {
+		if (md->type == eModifierType_Cache) {
+			if (modifier_isEnabled(scene, md, required_mode))
 				break;
-			}
 		}
 	}
-	if (md)
-		return md;
-#endif
+	return md;
+}
+
+static ModifierData *mesh_find_start_modifier(Scene *UNUSED(scene), Object *ob, VirtualModifierData *virtual_modifiers, int UNUSED(required_mode), bool useDeform)
+{
+	const bool skipVirtualArmature = (useDeform < 0);
 	
-	/* no valid cache modifier found,
-	 * take virtual modifiers at list start into account
-	 */
+	ModifierData *md = NULL;
+	
+	/* take virtual modifiers at list start into account */
 	
 	if (!skipVirtualArmature) {
 		md = modifiers_getVirtualModifierList(ob, virtual_modifiers);
@@ -1603,7 +1588,14 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
 	modifiers_clearErrors(ob);
 	
 	if (BKE_cache_read_derived_mesh(G.main, scene, scene->r.cfra, ob, &cachedm)) {
-		firstmd = NULL;
+		CacheModifierData *cmd = (CacheModifierData *)mesh_find_cache_modifier(scene, ob, required_mode);
+		firstmd = &cmd->modifier;
+		
+		/* use the cache result as output of the modifier
+		 * rather than as the final dm
+		 */
+		cmd->output_dm = cachedm;
+		cachedm = NULL;
 	}
 	else {
 		firstmd = mesh_find_start_modifier(scene, ob, &virtualModifierData, required_mode, useDeform);
diff --git a/source/blender/editors/io/io_cache_library.c b/source/blender/editors/io/io_cache_library.c
index 21898af..6328c04 100644
--- a/source/blender/editors/io/io_cache_library.c
+++ b/source/blender/editors/io/io_cache_library.c
@@ -39,6 +39,7 @@
 
 #include "DNA_cache_library_types.h"
 #include "DNA_listBase.h"
+#include "DNA_modifier_types.h"
 #include "DNA_object_types.h"
 
 #include "BKE_depsgraph.h"
@@ -206,6 +207,7 @@ static void cache_library_bake_startjob(void *customdata, short *stop, short *do
 	CacheLibraryBakeJob *data= (CacheLibraryBakeJob *)customdata;
 	Scene *scene = data->scene;
 	int start_frame, end_frame;
+	int required_mode;
 	
 	data->stop = stop;
 	data->do_update = do_update;
@@ -219,7 +221,10 @@ static void cache_library_bake_startjob(void *customdata, short *stop, short *do
 	
 	G.is_break = false;
 	
-	data->archive = PTC_cachelib_writers(scene, data->cachelib, &data->writers);
+	/* XXX how can this be defined properly? */
+	required_mode = eModifierMode_Render;
+	
+	data->archive = PTC_cachelib_writers(scene, required_mode, data->cachelib, &data->writers);
 	
 	/* XXX where to get this from? */
 	start_frame = scene->r.sfra;
diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c
index 77a1899..ef2ef98 100644
--- a/source/blender/editors/space_outliner/outliner_draw.c
+++ b/source/blender/editors/space_outliner/outliner_draw.c
@@ -1170,7 +1170,7 @@ static void tselem_draw_icon(uiBlock *block, int xmax, float x, float y, TreeSto
 						UI_icon_draw(x, y, ICON_MOD_DATA_TRANSFER); break;
 					case eModifierType_NormalEdit:
 						UI_icon_draw(x, y, ICON_MOD_NORMALEDIT); break;
-					case eModifierType_PointCache:
+					case eModifierType_Cache:
 						UI_icon_draw(x, y, ICON_PHYSICS); break;
 					/* Default */
 					case eModifierType_None:
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 1751f71..f549f66 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -84,7 +84,7 @@ typedef enum ModifierType {
 	eModifierType_Wireframe         = 48,
 	eModifierType_DataTransfer      = 49,
 	eModifierType_NormalEdit        = 50,
-	eModifierType_PointCache        = 51,
+	eModifierType_Cache             = 51,
 	NUM_MODIFIER_TYPES
 } ModifierType;
 
@@ -1452,16 +1452,18 @@ enum {
 };
 
 /* point cache modifier */
-typedef struct PointCacheModifierData {
+typedef struct CacheModifierData {
 	ModifierData modifier;
 	
 	int flag;
 	int pad;
 	
-	struct PTCReader *reader;
-	struct PTCWriter *writer;
 	struct DerivedMesh *output_dm;
-} PointCacheModifierData;
+} CacheModifierData;
+
+typedef enum eCacheModifier_Flag {
+	MOD_CACHE_USE_OUTPUT              = 1,
+} eCacheModifier_Flag;
 
 /* Set Split Normals modifier */
 typedef struct NormalEditModifierData {
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 7c4167d..f242c36 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -65,7 +65,7 @@ EnumPropertyItem modifier_type_items[] = {
 	{0, "", 0, N_("Modify"), ""},
 	{eModifierType_DataTransfer, "DATA_TRANSFER", ICON_MOD_DATA_TRANSFER, "Data Transfer", ""},
 	{eModifierType_MeshCache, "MESH_CACHE", ICON_MOD_MESHDEFORM, "Mesh Cache", ""},
-	{eModifierType_PointCache, "POINT_CACHE", ICON_MOD_MESHDEFORM, "Point Cache", ""},
+	{eModifierType_Cache, "CACHE", ICON_MOD_MESHDEFORM, "Cache", ""},
 	{eModifierType_NormalEdit, "NORMAL_EDIT", ICON_MOD_NORMALEDIT, "Normal Edit", ""},
 	{eModifierType_UVProject, "UV_PROJECT", ICON_MOD_UVPROJECT, "UV Project", ""},
 	{eModifierType_UVWarp, "UV_WARP", ICON_MOD_UVPROJECT, "UV Warp", ""},
@@ -380,8 +380,8 @@ static StructRNA *rna_Modifier_refine(struct PointerRNA *ptr)
 			return &RNA_DataTransferModifier;
 		case eModifierType_NormalEdit:
 			return &RNA_NormalEditModifier;
-		case eModifierType_PointCache:
-			return &RNA_PointCacheModifier;
+		case eModifierType_Cache:
+			return &RNA_CacheModifier;
 		/* Default */
 		case eModifierType_None:
 		case eModifierType_ShapeKey:
@@ -4523,14 +4523,13 @@ static void rna_def_modifier_normaledit(BlenderRNA *brna)
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 }
 
-static void rna_def_modifier_pointcache(BlenderRNA *brna)
+static void rna_def_modifier_cache(BlenderRNA *brna)
 {
 	StructRNA *srna;
-	/*PropertyRNA *prop;*/
 
-	srna = RNA_def_struct(brna, "PointCacheModifier", "Modifier");
-	RNA_def_struct_ui_text(srna, "Point Cache Modifier", "Write and Read mesh results to/from point cache");
-	RNA_def_struct_sdna(srna, "PointCacheModifierData");
+	srna = RNA_def_struct(brna, "CacheModifier", "Modifier");
+	RNA_def_struct_ui_text(srna, "Cache Modifier", "Write and Read mesh results to/from cache libraries");
+	RNA_def_struct_sdna(srna, "CacheModifierData");
 	RNA_def_struct_ui_icon(srna, ICON_MOD_MESHDEFORM);  /* XXX, needs own icon */
 }
 
@@ -4649,7 +4648,7 @@ void RNA_def_modifier(BlenderRNA *brna)
 	rna_def_modifier_wireframe(brna);
 	rna_def_modifier_datatransfer(brna);
 	rna_def_modifier_normaledit(brna);
-	rna_def_modifier_pointcache(brna);
+	rna_def_modifier_cache(brna);
 }
 
 #endif
diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt
index 2c32627..1a73c2e 100644
-

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list