[Bf-blender-cvs] [ed35ac426e6] fluid-mantaflow: fix for inflow with subframes/adaptive time steps

Sebastián Barschkis noreply at git.blender.org
Mon May 14 15:57:00 CEST 2018


Commit: ed35ac426e6a8d646c9a329637c5acd978bda52a
Author: Sebastián Barschkis
Date:   Mon May 14 15:22:18 2018 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rBed35ac426e6a8d646c9a329637c5acd978bda52a

fix for inflow with subframes/adaptive time steps

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

M	release/scripts/startup/bl_ui/properties_physics_smoke.py
M	source/blender/blenkernel/BKE_smoke.h
M	source/blender/blenkernel/intern/smoke.c
M	source/blender/editors/physics/physics_fluid.c

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

diff --git a/release/scripts/startup/bl_ui/properties_physics_smoke.py b/release/scripts/startup/bl_ui/properties_physics_smoke.py
index 08c02311a6c..bc0d35e4898 100644
--- a/release/scripts/startup/bl_ui/properties_physics_smoke.py
+++ b/release/scripts/startup/bl_ui/properties_physics_smoke.py
@@ -159,7 +159,7 @@ class PHYSICS_PT_smoke(PhysicButtonsPanel, Panel):
                 col.prop(domain, "particle_randomness")
 
             split = layout.split()
-            bake_incomplete = domain.cache_frame_pause_data != -1
+            bake_incomplete = domain.cache_frame_pause_data
             if domain.cache_baked_data and not domain.cache_baking_data and bake_incomplete:
                 col = split.column()
                 col.operator("manta.bake_data", text="Resume")
@@ -402,7 +402,7 @@ class PHYSICS_PT_smoke_noise(PhysicButtonsPanel, Panel):
 
         split = layout.split()
         split.enabled = domain.cache_baked_data
-        bake_incomplete = domain.cache_frame_pause_noise != -1
+        bake_incomplete = domain.cache_frame_pause_noise
         if domain.cache_baked_noise and not domain.cache_baking_noise and bake_incomplete:
             col = split.column()
             col.operator("manta.bake_noise", text="Resume")
@@ -471,7 +471,7 @@ class PHYSICS_PT_smoke_mesh(PhysicButtonsPanel, Panel):
 
         split = layout.split()
         split.enabled = domain.cache_baked_data
-        bake_incomplete = domain.cache_frame_pause_mesh != -1
+        bake_incomplete = domain.cache_frame_pause_mesh
         if domain.cache_baked_mesh and not domain.cache_baking_mesh and bake_incomplete:
             col = split.column()
             col.operator("manta.bake_mesh", text="Resume")
@@ -541,11 +541,10 @@ class PHYSICS_PT_smoke_particles(PhysicButtonsPanel, Panel):
 
         split = layout.split()
         split.enabled = domain.cache_baked_data and (domain.use_drop_particles or domain.use_bubble_particles or domain.use_floater_particles or domain.use_tracer_particles)
-        bake_incomplete = domain.cache_frame_pause_particles != -1
+        bake_incomplete = domain.cache_frame_pause_particles
         if domain.cache_baked_particles and not domain.cache_baking_particles and bake_incomplete:
-            if domain.cache_frame_pause_particles != -1: # only show resume operator when bake is not complete
-                col = split.column()
-                col.operator("manta.bake_particles", text="Resume")
+            col = split.column()
+            col.operator("manta.bake_particles", text="Resume")
             col = split.column()
             col.operator("manta.free_particles", text="Free")
         elif not domain.cache_baked_particles and domain.cache_baking_particles:
diff --git a/source/blender/blenkernel/BKE_smoke.h b/source/blender/blenkernel/BKE_smoke.h
index 4ab5a240502..3ea6fc56acb 100644
--- a/source/blender/blenkernel/BKE_smoke.h
+++ b/source/blender/blenkernel/BKE_smoke.h
@@ -44,7 +44,7 @@ void smokeModifier_reset(struct SmokeModifierData *smd);
 void smokeModifier_createType(struct SmokeModifierData *smd);
 void smokeModifier_copy(struct SmokeModifierData *smd, struct SmokeModifierData *tsmd);
 
-void smoke_step(struct Scene *scene, struct Object *ob, struct SmokeModifierData *smd, int frame);
+void smoke_step(struct Scene *scene, struct Object *ob, struct SmokeModifierData *smd, int frame, bool is_first_frame);
 
 float smoke_get_velocity_at(struct Object *ob, float position[3], float velocity[3]);
 int smoke_get_data_flags(struct SmokeDomainSettings *sds);
diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c
index 4a1c26015a9..be8ca14f284 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -572,10 +572,10 @@ void smokeModifier_createType(struct SmokeModifierData *smd)
 			smd->domain->cache_noise_format = MANTA_FILE_UNI;
 			smd->domain->cache_frame_start = 1;
 			smd->domain->cache_frame_end = 250;
-			smd->domain->cache_frame_pause_data = -1;
-			smd->domain->cache_frame_pause_noise = -1;
-			smd->domain->cache_frame_pause_mesh = -1;
-			smd->domain->cache_frame_pause_particles = -1;
+			smd->domain->cache_frame_pause_data = 0;
+			smd->domain->cache_frame_pause_noise = 0;
+			smd->domain->cache_frame_pause_mesh = 0;
+			smd->domain->cache_frame_pause_particles = 0;
 			modifier_path_init(smd->domain->cache_directory, sizeof(smd->domain->cache_directory), FLUID_CACHE_DIR_DEFAULT);
 			smd->domain->cache_flag = 0;
 
@@ -2424,7 +2424,7 @@ static void update_flowsflags(SmokeDomainSettings *sds, Object **flowobjs, int n
 	sds->active_fields = active_fields;
 }
 
-static void update_flowsfluids(Scene *scene, Object *ob, SmokeDomainSettings *sds, float time_per_frame, float frame_length, int frame)
+static void update_flowsfluids(Scene *scene, Object *ob, SmokeDomainSettings *sds, float time_per_frame, float frame_length, int frame, bool is_first_frame)
 {
 	EmissionMap *emaps = NULL;
 	int new_shift[3] = {0};
@@ -2493,7 +2493,6 @@ static void update_flowsfluids(Scene *scene, Object *ob, SmokeDomainSettings *sd
 			int hires_multiplier = 1;
 
 			/* First frame cannot have any subframes because there is (obviously) no previous frame from where subframes could come from */
-			bool is_first_frame = (frame == sds->cache_frame_start);
 			if (is_first_frame) subframes = 0;
 
 			int subframe;
@@ -2507,21 +2506,25 @@ static void update_flowsfluids(Scene *scene, Object *ob, SmokeDomainSettings *sd
 
 				/* Set scene time */
 				/* Handle emission subframe */
-				if (subframe < subframes) {
+				if (subframe < subframes && !is_first_frame) {
 					prev_frame_pos = sdt * (float)(subframe+1);
 					scene->r.subframe = prev_frame_pos;
+					scene->r.cfra = frame - 1;
 				}
 				/* Last frame in this loop (subframe == suframes). Can be real end frame or in between frames (adaptive frame) */
 				else {
 					/* Handle adaptive subframe (ie has subframe fraction). Need to set according scene subframe parameter */
 					if (time_per_frame < frame_length) {
 						scene->r.subframe = adaptframe_length;
+						scene->r.cfra = frame - 1;
 					}
 					/* Handle absolute endframe (ie no subframe fraction). Need to set the scene subframe parameter to 0 and advance current scene frame */
 					else {
 						scene->r.subframe = 0.0f;
+						scene->r.cfra = frame;
 					}
 				}
+//				printf("frame (is first: %d): %d // scene current frame: %d // scene current subframe: %f\n", is_first_frame, frame, scene->r.cfra, scene->r.subframe);
 
 				/* Emission from particles */
 				if (sfs->source == MOD_SMOKE_FLOW_SOURCE_PARTICLES) {
@@ -3135,10 +3138,14 @@ static void smokeModifier_process(SmokeModifierData *smd, Scene *scene, Object *
 	{
 		SmokeDomainSettings *sds = smd->domain;
 		int startframe, endframe, framenr;
+		bool is_first_frame;
 		framenr = scene->r.cfra;
 		startframe = sds->cache_frame_start;
 		endframe = sds->cache_frame_end;
 
+		is_first_frame = (scene->r.cfra == startframe);
+		CLAMP(framenr, startframe, endframe);
+
 		bool is_baking = (sds->cache_flag & (FLUID_CACHE_BAKING_DATA|FLUID_CACHE_BAKING_NOISE|
 											 FLUID_CACHE_BAKING_MESH|FLUID_CACHE_BAKING_PARTICLES));
 		bool is_baked = (sds->cache_flag & (FLUID_CACHE_BAKED_DATA|FLUID_CACHE_BAKED_NOISE|
@@ -3155,7 +3162,6 @@ static void smokeModifier_process(SmokeModifierData *smd, Scene *scene, Object *
 			return;
 
 		sds->flags &= ~MOD_SMOKE_FILE_LOAD;
-		CLAMP(framenr, startframe, endframe);
 
 		if (smokeModifier_init(smd, ob, scene, dm) == 0)
 			return;
@@ -3200,7 +3206,7 @@ static void smokeModifier_process(SmokeModifierData *smd, Scene *scene, Object *
 					fluid_read_data(sds->fluid, smd, framenr-1);
 
 				/* Base step needs separated bake and write calls - reason being that transparency calculation is after fluid step */
-				smoke_step(scene, ob, smd, framenr);
+				smoke_step(scene, ob, smd, framenr, is_first_frame);
 				fluid_write_data(sds->fluid, smd, framenr);
 			}
 			if (sds->cache_flag & FLUID_CACHE_BAKING_NOISE)
@@ -3226,7 +3232,6 @@ static void smokeModifier_process(SmokeModifierData *smd, Scene *scene, Object *
 				fluid_bake_particles(sds->fluid, smd, framenr);
 			}
 		}
-
 		smd->time = scene->r.cfra;
 	}
 }
@@ -3430,7 +3435,7 @@ static void smoke_calc_transparency(SmokeDomainSettings *sds, Scene *scene)
 	}
 }
 
-void smoke_step(Scene *scene, Object *ob, SmokeModifierData *smd, int frame)
+void smoke_step(Scene *scene, Object *ob, SmokeModifierData *smd, int frame, bool is_first_frame)
 {
 	SmokeDomainSettings *sds = smd->domain;
 	DerivedMesh *domain_dm = ob->derivedDeform;
@@ -3468,7 +3473,7 @@ void smoke_step(Scene *scene, Object *ob, SmokeModifierData *smd, int frame)
 		time_per_frame += sdt;
 
 		// Calculate inflow geometry
-		update_flowsfluids(scene, ob, sds, time_per_frame, dt, frame);
+		update_flowsfluids(scene, ob, sds, time_per_frame, dt, frame, is_first_frame);
 
 		// Calculate obstacle geometry
 		update_obstacles(scene, ob, sds, sdt);
diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c
index a3cebd472a8..1f17b030586 100644
--- a/source/blender/editors/physics/physics_fluid.c
+++ b/source/blender/editors/physics/physics_fluid.c
@@ -1188,6 +1188,7 @@ static void fluid_manta_bake_sequence(FluidMantaflowJob *job)
 	int frame = 1, orig_frame;
 	int frames;
 	int *pause_frame = NULL;
+	bool is_first_frame;
 
 	frames = sds->cache_frame_end - sds->cache_frame_start + 1;
 
@@ -1203,14 +1204,13 @@ static void fluid_manta_bake_sequence(FluidMantaflowJob *job)
 	/* Get current pause frame (pointer) - depending on bake type */
 	pause_frame = job->pause_frame;
 
-	/* Set frame to start point */
-	frame = (*pause_frame);
-	if (frame == -1)
-		frame = sds->cache_frame_start;
+	/* Set frame to start point (depending on current pause frame value) */
+	is_first_frame = ((*pause_frame) == 0);
+	frame = is_first_frame ? sds->cache_frame_start : (*pause_frame);
 
 	/* Save orig frame and update scene frame */
 	orig_frame = scene->r.cfra;
-	scene->r.cfra = (int)frame;
+	scene->r.cfra = frame;
 
 	/* Loop through selected frames */
 	for ( ; frame <= sds->cache_frame_end; frame++

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list