[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59777] trunk/blender/source/blender/ blenkernel: Related to #36532: show message in modifier when cloth point cache read fails,

Brecht Van Lommel brechtvanlommel at pandora.be
Tue Sep 3 21:58:09 CEST 2013


Revision: 59777
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59777
Author:   blendix
Date:     2013-09-03 19:58:09 +0000 (Tue, 03 Sep 2013)
Log Message:
-----------
Related to #36532: show message in modifier when cloth point cache read fails,
for example due to a subsurf modifier preceding a cloth modifier.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_pointcache.h
    trunk/blender/source/blender/blenkernel/intern/pointcache.c

Modified: trunk/blender/source/blender/blenkernel/BKE_pointcache.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_pointcache.h	2013-09-03 18:59:52 UTC (rev 59776)
+++ trunk/blender/source/blender/blenkernel/BKE_pointcache.h	2013-09-03 19:58:09 UTC (rev 59777)
@@ -156,6 +156,8 @@
 
 	/* total number of simulated points (the cfra parameter is just for using same function pointer with totwrite) */
 	int (*totpoint)(void *calldata, int cfra);
+	/* report error if number of points does not match */
+	void (*error)(void *calldata, const char *message);
 	/* number of points written for current cache frame */
 	int (*totwrite)(void *calldata, int cfra);
 

Modified: trunk/blender/source/blender/blenkernel/intern/pointcache.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/pointcache.c	2013-09-03 18:59:52 UTC (rev 59776)
+++ trunk/blender/source/blender/blenkernel/intern/pointcache.c	2013-09-03 19:58:09 UTC (rev 59777)
@@ -66,6 +66,7 @@
 #include "BKE_global.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
+#include "BKE_modifier.h"
 #include "BKE_object.h"
 #include "BKE_particle.h"
 #include "BKE_pointcache.h"
@@ -227,6 +228,11 @@
 	SoftBody *soft= soft_v;
 	return soft->totpoint;
 }
+static void ptcache_softbody_error(void *UNUSED(soft_v), const char *UNUSED(message))
+{
+	/* ignored for now */
+}
+
 /* Particle functions */
 void BKE_ptcache_make_particle_key(ParticleKey *key, int index, void **data, float time)
 {
@@ -405,6 +411,12 @@
 	ParticleSystem *psys = psys_v;
 	return psys->totpart;
 }
+
+static void ptcache_particle_error(void *UNUSED(psys_v), const char *UNUSED(message))
+{
+	/* ignored for now */
+}
+
 static int  ptcache_particle_totwrite(void *psys_v, int cfra)
 {
 	ParticleSystem *psys = psys_v;
@@ -534,6 +546,12 @@
 	return clmd->clothObject ? clmd->clothObject->numverts : 0;
 }
 
+static void ptcache_cloth_error(void *cloth_v, const char *message)
+{
+	ClothModifierData *clmd= cloth_v;
+	modifier_setError(&clmd->modifier, "%s", message);
+}
+
 #ifdef WITH_SMOKE
 /* Smoke functions */
 static int  ptcache_smoke_totpoint(void *smoke_v, int UNUSED(cfra))
@@ -548,6 +566,12 @@
 		return 0;
 }
 
+static void ptcache_smoke_error(void *smoke_v, const char *message)
+{
+	SmokeModifierData *smd= (SmokeModifierData *)smoke_v;
+	modifier_setError(&smd->modifier, "%s", message);
+}
+
 #define SMOKE_CACHE_VERSION "1.04"
 
 static int  ptcache_smoke_write(PTCacheFile *pf, void *smoke_v)
@@ -865,8 +889,10 @@
 
 	return 1;
 }
+
 #else // WITH_SMOKE
 static int  ptcache_smoke_totpoint(void *UNUSED(smoke_v), int UNUSED(cfra)) { return 0; }
+static void ptcache_smoke_error(void *UNUSED(smoke_v), const char *UNUSED(message)) { }
 static int  ptcache_smoke_read(PTCacheFile *UNUSED(pf), void *UNUSED(smoke_v)) { return 0; }
 static int  ptcache_smoke_write(PTCacheFile *UNUSED(pf), void *UNUSED(smoke_v)) { return 0; }
 #endif // WITH_SMOKE
@@ -879,6 +905,11 @@
 	else return surface->data->total_points;
 }
 
+static void ptcache_dynamicpaint_error(void *UNUSED(sd), const char *UNUSED(message))
+{
+	/* ignored for now */
+}
+
 #define DPAINT_CACHE_VERSION "1.01"
 
 static int  ptcache_dynamicpaint_write(PTCacheFile *pf, void *dp_v)
@@ -1055,6 +1086,11 @@
 	return rbw->numbodies;
 }
 
+static void ptcache_rigidbody_error(void *UNUSED(rb_v), const char *UNUSED(message))
+{
+	/* ignored for now */
+}
+
 /* Creating ID's */
 void BKE_ptcache_id_from_softbody(PTCacheID *pid, Object *ob, SoftBody *sb)
 {
@@ -1067,6 +1103,7 @@
 	pid->cache_ptr= &sb->pointcache;
 	pid->ptcaches= &sb->ptcaches;
 	pid->totpoint= pid->totwrite= ptcache_softbody_totpoint;
+	pid->error					= ptcache_softbody_error;
 
 	pid->write_point			= ptcache_softbody_write;
 	pid->read_point				= ptcache_softbody_read;
@@ -1107,6 +1144,7 @@
 
 	pid->totpoint				= ptcache_particle_totpoint;
 	pid->totwrite				= ptcache_particle_totwrite;
+	pid->error					= ptcache_particle_error;
 
 	pid->write_point				= ptcache_particle_write;
 	pid->read_point				= ptcache_particle_read;
@@ -1159,6 +1197,7 @@
 	pid->cache_ptr= &clmd->point_cache;
 	pid->ptcaches= &clmd->ptcaches;
 	pid->totpoint= pid->totwrite= ptcache_cloth_totpoint;
+	pid->error					= ptcache_cloth_error;
 
 	pid->write_point			= ptcache_cloth_write;
 	pid->read_point				= ptcache_cloth_read;
@@ -1197,6 +1236,7 @@
 	pid->ptcaches= &(sds->ptcaches[0]);
 
 	pid->totpoint= pid->totwrite= ptcache_smoke_totpoint;
+	pid->error					= ptcache_smoke_error;
 
 	pid->write_point			= NULL;
 	pid->read_point				= NULL;
@@ -1236,6 +1276,7 @@
 	pid->cache_ptr= &surface->pointcache;
 	pid->ptcaches= &surface->ptcaches;
 	pid->totpoint= pid->totwrite= ptcache_dynamicpaint_totpoint;
+	pid->error					= ptcache_dynamicpaint_error;
 
 	pid->write_point			= NULL;
 	pid->read_point				= NULL;
@@ -1272,6 +1313,7 @@
 	pid->cache_ptr= &rbw->pointcache;
 	pid->ptcaches= &rbw->ptcaches;
 	pid->totpoint= pid->totwrite= ptcache_rigidbody_totpoint;
+	pid->error					= ptcache_rigidbody_error;
 	
 	pid->write_point			= ptcache_rigidbody_write;
 	pid->read_point				= ptcache_rigidbody_read;
@@ -2083,21 +2125,31 @@
 		return 0;
 	}
 
-	if (!ptcache_file_header_begin_read(pf))
+	if (!ptcache_file_header_begin_read(pf)) {
+		pid->error(pid->calldata, "Failed to read point cache file");
 		error = 1;
-
-	if (!error && (pf->type != pid->type || !pid->read_header(pf)))
+	}
+	else if (pf->type != pid->type) {
+		pid->error(pid->calldata, "Point cache file has wrong type");
 		error = 1;
-
-	if (!error && pf->totpoint != pid->totpoint(pid->calldata, cfra))
+	}
+	else if (!pid->read_header(pf)) {
+		pid->error(pid->calldata, "Failed to read point cache file header");
 		error = 1;
+	}
+	else if (pf->totpoint != pid->totpoint(pid->calldata, cfra)) {
+		pid->error(pid->calldata, "Number of points in cache does not match mesh");
+		error = 1;
+	}
 
 	if (!error) {
 		ptcache_file_pointers_init(pf);
 
 		// we have stream reading here
-		if (!pid->read_stream(pf, pid->calldata))
+		if (!pid->read_stream(pf, pid->calldata)) {
+			pid->error(pid->calldata, "Failed to read point cache file data");
 			error = 1;
+		}
 	}
 
 	ptcache_file_close(pf);
@@ -2125,9 +2177,15 @@
 	if (pm) {
 		int totpoint = pm->totpoint;
 
-		if ((pid->data_types & (1<<BPHYS_DATA_INDEX)) == 0)
-			totpoint = MIN2(totpoint, pid->totpoint(pid->calldata, cfra));
+		if ((pid->data_types & (1<<BPHYS_DATA_INDEX)) == 0) {
+			int pid_totpoint = pid->totpoint(pid->calldata, cfra);
 
+			if (totpoint != pid_totpoint) {
+				pid->error(pid->calldata, "Number of points in cache does not match mesh");
+				totpoint = MIN2(totpoint, pid_totpoint);
+			}
+		}
+
 		BKE_ptcache_mem_pointers_init(pm);
 
 		for (i=0; i<totpoint; i++) {
@@ -2173,9 +2231,15 @@
 	if (pm) {
 		int totpoint = pm->totpoint;
 
-		if ((pid->data_types & (1<<BPHYS_DATA_INDEX)) == 0)
-			totpoint = MIN2(totpoint, pid->totpoint(pid->calldata, (int)cfra));
+		if ((pid->data_types & (1<<BPHYS_DATA_INDEX)) == 0) {
+			int pid_totpoint = pid->totpoint(pid->calldata, (int)cfra);
 
+			if (totpoint != pid_totpoint) {
+				pid->error(pid->calldata, "Number of points in cache does not match mesh");
+				totpoint = MIN2(totpoint, pid_totpoint);
+			}
+		}
+
 		BKE_ptcache_mem_pointers_init(pm);
 
 		for (i=0; i<totpoint; i++) {




More information about the Bf-blender-cvs mailing list