[Bf-blender-cvs] [ab027c9] gooseberry: PointCache modifier to act as a terminator in modifier stacks.

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


Commit: ab027c9a347a5cef1c6799feeb2fca83e552080b
Author: Lukas Tönne
Date:   Mon Mar 23 12:12:07 2015 +0100
Branches: gooseberry
https://developer.blender.org/rBab027c9a347a5cef1c6799feeb2fca83e552080b

PointCache modifier to act as a terminator in modifier stacks.

When writing DerivedMesh data, the modifier result at the point of the
modifier will be used for writing to the cache. If this modifier is not
used the derivedFinal mesh is used instead.

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/blenkernel/intern/DerivedMesh.c
M	source/blender/editors/space_outliner/outliner_draw.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_modifier.c
A	source/blender/makesrna/intern/rna_pointcache.c
M	source/blender/modifiers/CMakeLists.txt
M	source/blender/modifiers/MOD_modifiertypes.h
A	source/blender/modifiers/intern/MOD_pointcache.c
M	source/blender/modifiers/intern/MOD_util.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index f530a05..ff91117 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -692,6 +692,12 @@ 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/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 0bfa362..2b57159 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -65,6 +65,8 @@
 #include "BKE_deform.h"
 #include "BKE_global.h" /* For debug flag, DM_update_tessface_data() func. */
 
+#include "PTC_api.h"
+
 #ifdef WITH_GAMEENGINE
 #include "BKE_navmesh_conversion.h"
 static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm);
@@ -1490,6 +1492,58 @@ static void dm_ensure_display_normals(DerivedMesh *dm)
 		CDDM_calc_normals_mapping_ex(dm, (dm->dirty & DM_DIRTY_NORMALS) ? false : true);
 	}
 }
+
+/* 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.
+ */
+static ModifierData *mesh_find_start_modifier(Scene *scene, Object *ob, VirtualModifierData *virtual_modifiers, int required_mode, bool useDeform)
+{
+	const bool skipVirtualArmature = (useDeform < 0);
+	
+	ModifierData *md;
+	
+	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)) {
+				break;
+			}
+		}
+	}
+	if (md)
+		return md;
+	
+	/* no valid cache modifier found,
+	 * take virtual modifiers at list start into account
+	 */
+	
+	if (!skipVirtualArmature) {
+		md = modifiers_getVirtualModifierList(ob, virtual_modifiers);
+	}
+	else {
+		/* game engine exception */
+		md = ob->modifiers.first;
+		if (md && md->type == eModifierType_Armature)
+			md = md->next;
+	}
+	
+	return md;
+}
+
 /* new value for useDeform -1  (hack for the gameengine):
  * - apply only the modifier stack of the object, skipping the virtual modifiers,
  * - don't apply the key
@@ -1511,7 +1565,6 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
 	int numVerts = me->totvert;
 	int required_mode;
 	bool isPrevDeform = false;
-	const bool skipVirtualArmature = (useDeform < 0);
 	MultiresModifierData *mmd = get_multires_modifier(scene, ob, 0);
 	const bool has_multires = (mmd && mmd->sculptlvl != 0);
 	bool multires_applied = false;
@@ -1540,23 +1593,14 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
 		app_flags |= MOD_APPLY_USECACHE;
 	if (useDeform)
 		deform_app_flags |= MOD_APPLY_USECACHE;
-
-	if (!skipVirtualArmature) {
-		firstmd = modifiers_getVirtualModifierList(ob, &virtualModifierData);
-	}
-	else {
-		/* game engine exception */
-		firstmd = ob->modifiers.first;
-		if (firstmd && firstmd->type == eModifierType_Armature)
-			firstmd = firstmd->next;
-	}
-
-	md = firstmd;
-
-	modifiers_clearErrors(ob);
-
+	
 	if (useRenderParams) required_mode = eModifierMode_Render;
 	else required_mode = eModifierMode_Realtime;
+	
+	modifiers_clearErrors(ob);
+	
+	firstmd = mesh_find_start_modifier(scene, ob, &virtualModifierData, required_mode, useDeform);
+	md = firstmd;
 
 	if (do_mod_wmcol || do_mod_mcol) {
 		/* Find the last active modifier generating a preview, or NULL if none. */
diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c
index 2c61e69..77a1899 100644
--- a/source/blender/editors/space_outliner/outliner_draw.c
+++ b/source/blender/editors/space_outliner/outliner_draw.c
@@ -1170,6 +1170,8 @@ 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:
+						UI_icon_draw(x, y, ICON_PHYSICS); break;
 					/* Default */
 					case eModifierType_None:
 					case eModifierType_ShapeKey:
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 414d1d7..de8e477 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -84,6 +84,7 @@ typedef enum ModifierType {
 	eModifierType_Wireframe         = 48,
 	eModifierType_DataTransfer      = 49,
 	eModifierType_NormalEdit        = 50,
+	eModifierType_PointCache        = 51,
 	NUM_MODIFIER_TYPES
 } ModifierType;
 
@@ -1452,6 +1453,18 @@ enum {
 	MOD_DATATRANSFER_USE_POLY         = 1 << 31,
 };
 
+/* point cache modifier */
+typedef struct PointCacheModifierData {
+	ModifierData modifier;
+	
+	int flag;
+	int pad;
+	
+	struct PTCReader *reader;
+	struct PTCWriter *writer;
+	struct DerivedMesh *output_dm;
+} PointCacheModifierData;
+
 /* Set Split Normals modifier */
 typedef struct NormalEditModifierData {
 	ModifierData modifier;
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 18238ab..851600d 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -452,6 +452,7 @@ extern StructRNA RNA_ParticleSystemModifier;
 extern StructRNA RNA_ParticleTarget;
 extern StructRNA RNA_PivotConstraint;
 extern StructRNA RNA_PointCache;
+extern StructRNA RNA_PointCacheModifier;
 extern StructRNA RNA_PointDensity;
 extern StructRNA RNA_PointDensityTexture;
 extern StructRNA RNA_PointLamp;
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index fb01a40..24faaca 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -65,6 +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_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", ""},
@@ -379,6 +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;
 		/* Default */
 		case eModifierType_None:
 		case eModifierType_ShapeKey:
@@ -4524,6 +4527,17 @@ 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)
+{
+	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");
+	RNA_def_struct_ui_icon(srna, ICON_MOD_MESHDEFORM);  /* XXX, needs own icon */
+}
+
 void RNA_def_modifier(BlenderRNA *brna)
 {
 	StructRNA *srna;
@@ -4639,6 +4653,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);
 }
 
 #endif
diff --git a/source/blender/makesrna/intern/rna_pointcache.c b/source/blender/makesrna/intern/rna_pointcache.c
new file mode 100644
index 0000000..5f20e77
--- /dev/null
+++ b/source/blender/makesrna/intern/rna_pointcache.c
@@ -0,0 +1,300 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * 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.
+ *
+ * Contributor(s): Blender Foundation,
+ *                 Sergey Sharybin
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/makesrna/intern/rna_pointcache.c
+ *  \ingroup RNA
+ */
+
+/* XXX hack, remove later */
+#define POINTCACHE_OLD
+
+#include "DNA_object_force.h"
+#include "DNA_pointcache_types.h"
+#include "DNA_scene_types.h"
+
+#include "RNA_define.h"
+#include "RNA_types.h"
+
+#include "rna_internal.h"
+
+#include "PTC_api.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#ifdef RNA_RUNTIME
+
+#ifdef POINTCACHE_OLD
+#

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list