[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50924] trunk/blender/source/blender: Fix #32667: Curve softbodies doesn't render animation (cycles)

Sergey Sharybin sergey.vfx at gmail.com
Thu Sep 27 16:37:21 CEST 2012


Revision: 50924
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50924
Author:   nazgul
Date:     2012-09-27 14:37:20 +0000 (Thu, 27 Sep 2012)
Log Message:
-----------
Fix #32667: Curve softbodies doesn't render animation (cycles)

Issue was caused by cycles being duplicated curve objects before converting
them to mesh. This duplication will loose pointcache which resulted in object
not being properly deformed.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_object.h
    trunk/blender/source/blender/blenkernel/BKE_pointcache.h
    trunk/blender/source/blender/blenkernel/intern/object.c
    trunk/blender/source/blender/blenkernel/intern/pointcache.c
    trunk/blender/source/blender/editors/object/object_edit.c
    trunk/blender/source/blender/makesrna/intern/rna_object_api.c
    trunk/blender/source/blender/modifiers/intern/MOD_cloth.c

Modified: trunk/blender/source/blender/blenkernel/BKE_object.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_object.h	2012-09-27 12:44:52 UTC (rev 50923)
+++ trunk/blender/source/blender/blenkernel/BKE_object.h	2012-09-27 14:37:20 UTC (rev 50924)
@@ -54,7 +54,7 @@
 void BKE_object_workob_calc_parent(struct Scene *scene, struct Object *ob, struct Object *workob);
 
 void BKE_object_transform_copy(struct Object *ob_tar, const struct Object *ob_src);
-struct SoftBody *copy_softbody(struct SoftBody *sb);
+struct SoftBody *copy_softbody(struct SoftBody *sb, int copy_caches);
 struct BulletSoftBody *copy_bulletsoftbody(struct BulletSoftBody *sb);
 void BKE_object_copy_particlesystems(struct Object *obn, struct Object *ob);
 void BKE_object_copy_softbody(struct Object *obn, struct Object *ob);
@@ -82,6 +82,7 @@
 void *BKE_object_obdata_add_from_type(int type);
 
 struct Object *BKE_object_copy(struct Object *ob);
+struct Object *BKE_object_copy_with_caches(struct Object *ob);
 void BKE_object_make_local(struct Object *ob);
 int  BKE_object_is_libdata(struct Object *ob);
 int  BKE_object_obdata_is_libdata(struct Object *ob);

Modified: trunk/blender/source/blender/blenkernel/BKE_pointcache.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_pointcache.h	2012-09-27 12:44:52 UTC (rev 50923)
+++ trunk/blender/source/blender/blenkernel/BKE_pointcache.h	2012-09-27 14:37:20 UTC (rev 50924)
@@ -303,7 +303,7 @@
 void BKE_ptcache_free_mem(struct ListBase *mem_cache);
 void BKE_ptcache_free(struct PointCache *cache);
 void BKE_ptcache_free_list(struct ListBase *ptcaches);
-struct PointCache *BKE_ptcache_copy_list(struct ListBase *ptcaches_new, struct ListBase *ptcaches_old);
+struct PointCache *BKE_ptcache_copy_list(struct ListBase *ptcaches_new, struct ListBase *ptcaches_old, int copy_data);
 
 /********************** Baking *********************/
 

Modified: trunk/blender/source/blender/blenkernel/intern/object.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/object.c	2012-09-27 12:44:52 UTC (rev 50923)
+++ trunk/blender/source/blender/blenkernel/intern/object.c	2012-09-27 14:37:20 UTC (rev 50924)
@@ -889,23 +889,44 @@
 	return ob;
 }
 
-SoftBody *copy_softbody(SoftBody *sb)
+SoftBody *copy_softbody(SoftBody *sb, int copy_caches)
 {
 	SoftBody *sbn;
 	
 	if (sb == NULL) return(NULL);
 	
 	sbn = MEM_dupallocN(sb);
-	sbn->totspring = sbn->totpoint = 0;
-	sbn->bpoint = NULL;
-	sbn->bspring = NULL;
+
+	if (copy_caches == FALSE) {
+		sbn->totspring = sbn->totpoint = 0;
+		sbn->bpoint = NULL;
+		sbn->bspring = NULL;
+	}
+	else {
+		sbn->totspring = sb->totspring;
+		sbn->totpoint = sb->totpoint;
+
+		if (sbn->bpoint) {
+			int i;
+
+			sbn->bpoint = MEM_dupallocN(sbn->bpoint);
+
+			for (i = 0; i < sbn->totpoint; i++) {
+				if (sbn->bpoint[i].springs)
+					sbn->bpoint[i].springs = MEM_dupallocN(sbn->bpoint[i].springs);
+			}
+		}
+
+		if (sb->bspring)
+			sbn->bspring = MEM_dupallocN(sb->bspring);
+	}
 	
 	sbn->keys = NULL;
 	sbn->totkey = sbn->totpointkey = 0;
 	
 	sbn->scratch = NULL;
 
-	sbn->pointcache = BKE_ptcache_copy_list(&sbn->ptcaches, &sb->ptcaches);
+	sbn->pointcache = BKE_ptcache_copy_list(&sbn->ptcaches, &sb->ptcaches, copy_caches);
 
 	if (sb->effector_weights)
 		sbn->effector_weights = MEM_dupallocN(sb->effector_weights);
@@ -978,7 +999,7 @@
 	psysn->childcachebufs.first = psysn->childcachebufs.last = NULL;
 	psysn->renderdata = NULL;
 	
-	psysn->pointcache = BKE_ptcache_copy_list(&psysn->ptcaches, &psys->ptcaches);
+	psysn->pointcache = BKE_ptcache_copy_list(&psysn->ptcaches, &psys->ptcaches, FALSE);
 
 	/* XXX - from reading existing code this seems correct but intended usage of
 	 * pointcache should /w cloth should be added in 'ParticleSystem' - campbell */
@@ -1039,7 +1060,7 @@
 void BKE_object_copy_softbody(Object *obn, Object *ob)
 {
 	if (ob->soft)
-		obn->soft = copy_softbody(ob->soft);
+		obn->soft = copy_softbody(ob->soft, FALSE);
 }
 
 static void copy_object_pose(Object *obn, Object *ob)
@@ -1120,7 +1141,7 @@
 	copy_v3_v3(ob_tar->size, ob_src->size);
 }
 
-Object *BKE_object_copy(Object *ob)
+static Object *object_copy_do(Object *ob, int copy_caches)
 {
 	Object *obn;
 	ModifierData *md;
@@ -1181,7 +1202,7 @@
 		if (obn->pd->rng)
 			obn->pd->rng = MEM_dupallocN(ob->pd->rng);
 	}
-	obn->soft = copy_softbody(ob->soft);
+	obn->soft = copy_softbody(ob->soft, copy_caches);
 	obn->bsoft = copy_bulletsoftbody(ob->bsoft);
 
 	BKE_object_copy_particlesystems(obn, ob);
@@ -1197,6 +1218,18 @@
 	return obn;
 }
 
+/* copy objects, will re-initialize cached simulation data */
+Object *BKE_object_copy(Object *ob)
+{
+	return object_copy_do(ob, FALSE);
+}
+
+/* copy objects, will duplicate cached simulation data */
+Object *BKE_object_copy_with_caches(Object *ob)
+{
+	return object_copy_do(ob, TRUE);
+}
+
 static void extern_local_object(Object *ob)
 {
 	ParticleSystem *psys;

Modified: trunk/blender/source/blender/blenkernel/intern/pointcache.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/pointcache.c	2012-09-27 12:44:52 UTC (rev 50923)
+++ trunk/blender/source/blender/blenkernel/intern/pointcache.c	2012-09-27 14:37:20 UTC (rev 50924)
@@ -2663,32 +2663,59 @@
 	}
 }
 
-static PointCache *ptcache_copy(PointCache *cache)
+static PointCache *ptcache_copy(PointCache *cache, int copy_data)
 {
 	PointCache *ncache;
 
 	ncache= MEM_dupallocN(cache);
 
-	/* hmm, should these be copied over instead? */
 	ncache->mem_cache.first = NULL;
 	ncache->mem_cache.last = NULL;
-	ncache->cached_frames = NULL;
+
+	if (copy_data == FALSE) {
+		ncache->mem_cache.first = NULL;
+		ncache->mem_cache.last = NULL;
+		ncache->cached_frames = NULL;
+
+		ncache->flag= 0;
+		ncache->simframe= 0;
+	}
+	else {
+		PTCacheMem *pm;
+
+		for (pm = cache->mem_cache.first; pm; pm = pm->next) {
+			PTCacheMem *pmn = MEM_dupallocN(pm);
+			int i;
+
+			for (i = 0; i < BPHYS_TOT_DATA; i++) {
+				if (pmn->data[i])
+					pmn->data[i] = MEM_dupallocN(pm->data[i]);
+			}
+
+			BKE_ptcache_mem_pointers_init(pm);
+
+			BLI_addtail(&ncache->mem_cache, pmn);
+		}
+
+		if (ncache->cached_frames)
+			ncache->cached_frames = MEM_dupallocN(cache->cached_frames);
+	}
+
+	/* hmm, should these be copied over instead? */
 	ncache->edit = NULL;
 
-	ncache->flag= 0;
-	ncache->simframe= 0;
-
 	return ncache;
 }
+
 /* returns first point cache */
-PointCache *BKE_ptcache_copy_list(ListBase *ptcaches_new, ListBase *ptcaches_old)
+PointCache *BKE_ptcache_copy_list(ListBase *ptcaches_new, ListBase *ptcaches_old, int copy_data)
 {
 	PointCache *cache = ptcaches_old->first;
 
 	ptcaches_new->first = ptcaches_new->last = NULL;
 
 	for (; cache; cache=cache->next)
-		BLI_addtail(ptcaches_new, ptcache_copy(cache));
+		BLI_addtail(ptcaches_new, ptcache_copy(cache, copy_data));
 
 	return ptcaches_new->first;
 }

Modified: trunk/blender/source/blender/editors/object/object_edit.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_edit.c	2012-09-27 12:44:52 UTC (rev 50923)
+++ trunk/blender/source/blender/editors/object/object_edit.c	2012-09-27 14:37:20 UTC (rev 50924)
@@ -957,7 +957,7 @@
 					base->object->softflag = ob->softflag;
 					if (base->object->soft) sbFree(base->object->soft);
 					
-					base->object->soft = copy_softbody(ob->soft);
+					base->object->soft = copy_softbody(ob->soft, FALSE);
 
 					if (!modifiers_findByType(base->object, eModifierType_Softbody)) {
 						BLI_addhead(&base->object->modifiers, modifier_new(eModifierType_Softbody));

Modified: trunk/blender/source/blender/makesrna/intern/rna_object_api.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_object_api.c	2012-09-27 12:44:52 UTC (rev 50923)
+++ trunk/blender/source/blender/makesrna/intern/rna_object_api.c	2012-09-27 14:37:20 UTC (rev 50924)
@@ -96,7 +96,7 @@
 			float (*orco)[3] = NULL;
 
 			/* copies object and modifiers (but not the data) */
-			tmpobj = BKE_object_copy(ob);
+			tmpobj = BKE_object_copy_with_caches(ob);
 			tmpcu = (Curve *)tmpobj->data;
 			tmpcu->id.us--;
 

Modified: trunk/blender/source/blender/modifiers/intern/MOD_cloth.c
===================================================================
--- trunk/blender/source/blender/modifiers/intern/MOD_cloth.c	2012-09-27 12:44:52 UTC (rev 50923)
+++ trunk/blender/source/blender/modifiers/intern/MOD_cloth.c	2012-09-27 14:37:20 UTC (rev 50924)
@@ -155,7 +155,7 @@
 	if (clmd->sim_parms->effector_weights)
 		tclmd->sim_parms->effector_weights = MEM_dupallocN(clmd->sim_parms->effector_weights);
 	tclmd->coll_parms = MEM_dupallocN(clmd->coll_parms);
-	tclmd->point_cache = BKE_ptcache_copy_list(&tclmd->ptcaches, &clmd->ptcaches);
+	tclmd->point_cache = BKE_ptcache_copy_list(&tclmd->ptcaches, &clmd->ptcaches, FALSE);
 	tclmd->clothObject = NULL;
 }
 




More information about the Bf-blender-cvs mailing list