[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12726] branches/particles/source/blender: Fixes for bugs in #7833

Janne Karhu jhkarh at utu.fi
Thu Nov 29 21:30:21 CET 2007


Revision: 12726
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12726
Author:   jhk
Date:     2007-11-29 21:30:21 +0100 (Thu, 29 Nov 2007)

Log Message:
-----------
Fixes for bugs in #7833
- Hair softbody cache was reset on rendering.
- When Alt-a playback is synced to audio frames are skipped. This caused dynamics caching to go crazy. Now the first loop of playback goes through all frames if there are non cached dynamic systems.

Invalid pointcaches weren't cleared when new systems were created. This caused messed up shapes when softbody was added.

Modified Paths:
--------------
    branches/particles/source/blender/blenkernel/BKE_pointcache.h
    branches/particles/source/blender/blenkernel/intern/particle_system.c
    branches/particles/source/blender/blenkernel/intern/pointcache.c
    branches/particles/source/blender/src/buttons_object.c
    branches/particles/source/blender/src/drawview.c

Modified: branches/particles/source/blender/blenkernel/BKE_pointcache.h
===================================================================
--- branches/particles/source/blender/blenkernel/BKE_pointcache.h	2007-11-29 19:57:40 UTC (rev 12725)
+++ branches/particles/source/blender/blenkernel/BKE_pointcache.h	2007-11-29 20:30:21 UTC (rev 12726)
@@ -44,5 +44,6 @@
 int		PTCache_id_filename(struct ID *id, char *filename, int cfra, int stack_index, short do_path, short do_ext);
 FILE *	PTCache_id_fopen(struct ID *id, char mode, int cfra, int stack_index);
 void	PTCache_id_clear(struct ID *id, char mode, int cfra, int stack_index);
+int		PTCache_id_exist(struct ID *id, int cfra, int stack_index);
 
 #endif

Modified: branches/particles/source/blender/blenkernel/intern/particle_system.c
===================================================================
--- branches/particles/source/blender/blenkernel/intern/particle_system.c	2007-11-29 19:57:40 UTC (rev 12725)
+++ branches/particles/source/blender/blenkernel/intern/particle_system.c	2007-11-29 20:30:21 UTC (rev 12726)
@@ -4298,7 +4298,7 @@
 
 	if((psys->softflag&OB_SB_ENABLE)==0) return;
 
-	if((ob->recalc&OB_RECALC_TIME)==0)
+	if(ob->recalc && (ob->recalc&OB_RECALC_TIME)==0)
 		psys->softflag|=OB_SB_REDO;
 
 	/* let's replace the object's own softbody with the particle softbody */

Modified: branches/particles/source/blender/blenkernel/intern/pointcache.c
===================================================================
--- branches/particles/source/blender/blenkernel/intern/pointcache.c	2007-11-29 19:57:40 UTC (rev 12725)
+++ branches/particles/source/blender/blenkernel/intern/pointcache.c	2007-11-29 20:30:21 UTC (rev 12726)
@@ -183,3 +183,11 @@
 	return;
 }
 
+int PTCache_id_exist(struct ID *id, int cfra, int stack_index)
+{
+	char filename[(FILE_MAXDIR+FILE_MAXFILE)*2];
+	
+	PTCache_id_filename(id, filename, cfra, stack_index, 1, 1);
+
+	return BLI_exists(filename);
+}

Modified: branches/particles/source/blender/src/buttons_object.c
===================================================================
--- branches/particles/source/blender/src/buttons_object.c	2007-11-29 19:57:40 UTC (rev 12725)
+++ branches/particles/source/blender/src/buttons_object.c	2007-11-29 20:30:21 UTC (rev 12726)
@@ -3243,6 +3243,7 @@
 		if (!ob->soft) {
 			ob->soft= sbNew();
 			ob->softflag |= OB_SB_GOAL|OB_SB_EDGES;
+			softbody_clear_cache(ob, CFRA);
 		}
 	}
 	/* needed so that initial state is cached correctly */
@@ -3276,6 +3277,7 @@
 			psys->soft= sbNew();
 			psys->softflag |= OB_SB_GOAL|OB_SB_EDGES;
 			psys->soft->particles=psys;
+			clear_particles_from_cache(ob, psys, CFRA);
 		}
 		psys->softflag |= OB_SB_ENABLE;
 	}

Modified: branches/particles/source/blender/src/drawview.c
===================================================================
--- branches/particles/source/blender/src/drawview.c	2007-11-29 19:57:40 UTC (rev 12725)
+++ branches/particles/source/blender/src/drawview.c	2007-11-29 20:30:21 UTC (rev 12726)
@@ -70,6 +70,8 @@
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_meta_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_object_force.h"
 #include "DNA_object_types.h"
 #include "DNA_particle_types.h"
 #include "DNA_screen_types.h"
@@ -103,6 +105,7 @@
 #include "BKE_mesh.h"
 #include "BKE_object.h"
 #include "BKE_particle.h"
+#include "BKE_pointcache.h"
 #include "BKE_scene.h"
 #include "BKE_texture.h"
 #include "BKE_utildefines.h"
@@ -3292,10 +3295,50 @@
 	seq_stop_threads();
 }
 
+static int dynamics_cached(int sfra, int efra)
+{
+	Base *base = G.scene->base.first;
+	Object *ob;
+	ModifierData *md;
+	ParticleSystem *psys;
+	int i, stack_index, cached=1;
+
+	while(base && cached) {
+		ob = base->object;
+		if(ob->softflag & OB_SB_ENABLE && ob->soft) {
+			for(i=0, md=ob->modifiers.first; md; i++, md=md->next) {
+				if(md->type == eModifierType_Softbody) {
+					stack_index = i;
+					break;
+				}
+			}
+			for(i=sfra; i<=efra && cached; i++)
+				cached &= PTCache_id_exist(&ob->id,i,stack_index);
+		}
+
+		for(psys=ob->particlesystem.first; psys; psys=psys->next) {
+			stack_index = modifiers_indexInObject(ob,(ModifierData*)psys_get_modifier(ob,psys));
+			if(psys->part->type==PART_HAIR) {
+				if(psys->softflag & OB_SB_ENABLE && psys->soft);
+				else
+					stack_index = -1;
+			}
+
+			if(stack_index >= 0)
+				for(i=sfra; i<=efra && cached; i++)
+					cached &= PTCache_id_exist(&ob->id,i,stack_index);
+		}
+		
+		base = base->next;
+	}
+
+	return cached;
+}
 void inner_play_anim_loop(int init, int mode)
 {
 	ScrArea *sa;
 	static int last_cfra = -1;
+	static int cached = 0;
 
 	/* init */
 	if(init) {
@@ -3305,6 +3348,8 @@
 		curmode= mode;
 		last_cfra = -1;
 
+		cached = dynamics_cached(PSFRA,PEFRA);
+
 		return;
 	}
 
@@ -3380,8 +3425,10 @@
 		CFRA = PSFRA;
 		audiostream_stop();
 		audiostream_start( CFRA );
+		cached = dynamics_cached(PSFRA,PEFRA);
 	} else {
-		if (U.mixbufsize 
+		if (cached
+			&&U.mixbufsize 
 		    && (G.scene->audio.flag & AUDIO_SYNC)) {
 			CFRA = audiostream_pos();
 		} else {





More information about the Bf-blender-cvs mailing list