[Bf-blender-cvs] [d1858148e6d] fluid-mantaflow: added pause/resume bake functionality

Sebastián Barschkis noreply at git.blender.org
Mon May 7 17:30:13 CEST 2018


Commit: d1858148e6d77c5d340e24f360721b20f3d664eb
Author: Sebastián Barschkis
Date:   Mon May 7 17:29:58 2018 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rBd1858148e6d77c5d340e24f360721b20f3d664eb

added pause/resume bake functionality

works for all bake types (data, noise, mesh, particles)

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

M	release/scripts/startup/bl_ui/properties_physics_smoke.py
M	source/blender/blenkernel/intern/smoke.c
M	source/blender/editors/physics/physics_fluid.c
M	source/blender/editors/physics/physics_intern.h
M	source/blender/editors/physics/physics_ops.c
M	source/blender/makesdna/DNA_smoke_types.h
M	source/blender/makesrna/intern/rna_smoke.c

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

diff --git a/release/scripts/startup/bl_ui/properties_physics_smoke.py b/release/scripts/startup/bl_ui/properties_physics_smoke.py
index 8ae669a3fc6..08c02311a6c 100644
--- a/release/scripts/startup/bl_ui/properties_physics_smoke.py
+++ b/release/scripts/startup/bl_ui/properties_physics_smoke.py
@@ -159,12 +159,18 @@ class PHYSICS_PT_smoke(PhysicButtonsPanel, Panel):
                 col.prop(domain, "particle_randomness")
 
             split = layout.split()
-            if domain.cache_baked_data:
-                split.operator("manta.free_data", text="Free Data")
-            elif domain.cache_baking_data:
-                split.operator("manta.cancel_bake", text="Cancel")
-            else:
+            bake_incomplete = domain.cache_frame_pause_data != -1
+            if domain.cache_baked_data and not domain.cache_baking_data and bake_incomplete:
+                col = split.column()
+                col.operator("manta.bake_data", text="Resume")
+                col = split.column()
+                col.operator("manta.free_data", text="Free")
+            elif not domain.cache_baked_data and domain.cache_baking_data:
+                split.operator("manta.pause_bake", text="Pause Data")
+            elif not domain.cache_baked_data and not domain.cache_baking_data:
                 split.operator("manta.bake_data", text="Bake Data")
+            else:
+                split.operator("manta.free_data", text="Free Data")
 
         elif md.smoke_type == 'FLOW':
             flow = md.flow_settings
@@ -396,12 +402,18 @@ class PHYSICS_PT_smoke_noise(PhysicButtonsPanel, Panel):
 
         split = layout.split()
         split.enabled = domain.cache_baked_data
-        if domain.cache_baked_noise:
-            split.operator("manta.free_noise", text="Free Noise")
-        elif domain.cache_baking_noise:
-            split.operator("manta.cancel_bake", text="Cancel")
-        else:
+        bake_incomplete = domain.cache_frame_pause_noise != -1
+        if domain.cache_baked_noise and not domain.cache_baking_noise and bake_incomplete:
+            col = split.column()
+            col.operator("manta.bake_noise", text="Resume")
+            col = split.column()
+            col.operator("manta.free_noise", text="Free")
+        elif not domain.cache_baked_noise and domain.cache_baking_noise:
+            split.operator("manta.pause_bake", text="Pause Noise")
+        elif not domain.cache_baked_noise and not domain.cache_baking_noise:
             split.operator("manta.bake_noise", text="Bake Noise")
+        else:
+            split.operator("manta.free_noise", text="Free Noise")
 
 class PHYSICS_PT_smoke_mesh(PhysicButtonsPanel, Panel):
     bl_label = "Fluid Mesh"
@@ -459,13 +471,18 @@ class PHYSICS_PT_smoke_mesh(PhysicButtonsPanel, Panel):
 
         split = layout.split()
         split.enabled = domain.cache_baked_data
-        if domain.cache_baked_mesh:
-            split.operator("manta.free_mesh", text="Free Mesh")
-        elif domain.cache_baking_mesh:
-            split.operator("manta.cancel_bake", text="Cancel")
-        else:
+        bake_incomplete = domain.cache_frame_pause_mesh != -1
+        if domain.cache_baked_mesh and not domain.cache_baking_mesh and bake_incomplete:
+            col = split.column()
+            col.operator("manta.bake_mesh", text="Resume")
+            col = split.column()
+            col.operator("manta.free_mesh", text="Free")
+        elif not domain.cache_baked_mesh and domain.cache_baking_mesh:
+            split.operator("manta.pause_bake", text="Pause Mesh")
+        elif not domain.cache_baked_mesh and not domain.cache_baking_mesh:
             split.operator("manta.bake_mesh", text="Bake Mesh")
-
+        else:
+            split.operator("manta.free_mesh", text="Free Mesh")
 
 class PHYSICS_PT_smoke_particles(PhysicButtonsPanel, Panel):
     bl_label = "Fluid Particles"
@@ -524,12 +541,19 @@ 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)
-        if domain.cache_baked_particles:
-            split.operator("manta.free_particles", text="Free Particles")
-        elif domain.cache_baking_particles:
-            split.operator("manta.cancel_bake", text="Cancel")
-        else:
+        bake_incomplete = domain.cache_frame_pause_particles != -1
+        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.free_particles", text="Free")
+        elif not domain.cache_baked_particles and domain.cache_baking_particles:
+            split.operator("manta.pause_bake", text="Pause Particles")
+        elif not domain.cache_baked_particles and not domain.cache_baking_particles:
             split.operator("manta.bake_particles", text="Bake Particles")
+        else:
+            split.operator("manta.free_particles", text="Free Particles")
 
 class PHYSICS_PT_smoke_diffusion(PhysicButtonsPanel, Panel):
     bl_label = "Fluid Diffusion"
diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c
index 23572e37fec..39766b13049 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -572,6 +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;
 			BLI_path_make_safe(smd->domain->cache_directory);
 			BLI_make_file_string("/", smd->domain->cache_directory, BKE_tempdir_base(), "");
 			smd->domain->cache_flag = 0;
@@ -730,6 +734,12 @@ void smokeModifier_copy(struct SmokeModifierData *smd, struct SmokeModifierData
 		tsmd->domain->cache_volume_format = smd->domain->cache_volume_format;
 		tsmd->domain->cache_particle_format = smd->domain->cache_particle_format;
 		tsmd->domain->cache_noise_format = smd->domain->cache_noise_format;
+		tsmd->domain->cache_frame_start = smd->domain->cache_frame_start;
+		tsmd->domain->cache_frame_end = smd->domain->cache_frame_end;
+		tsmd->domain->cache_frame_pause_data = smd->domain->cache_frame_pause_data;
+		tsmd->domain->cache_frame_pause_noise = smd->domain->cache_frame_pause_noise;
+		tsmd->domain->cache_frame_pause_mesh = smd->domain->cache_frame_pause_mesh;
+		tsmd->domain->cache_frame_pause_particles = smd->domain->cache_frame_pause_particles;
 		tsmd->domain->slice_method = smd->domain->slice_method;
 		tsmd->domain->axis_slice_method = smd->domain->axis_slice_method;
 		tsmd->domain->slice_per_voxel = smd->domain->slice_per_voxel;
@@ -3123,11 +3133,15 @@ static void smokeModifier_process(SmokeModifierData *smd, Scene *scene, Object *
 		startframe = smd->domain->cache_frame_start;
 		endframe = smd->domain->cache_frame_end;
 
-		bool isBaking = (smd->domain->cache_flag & (FLUID_CACHE_BAKING_DATA|FLUID_CACHE_BAKING_NOISE|
+		bool is_baking = (smd->domain->cache_flag & (FLUID_CACHE_BAKING_DATA|FLUID_CACHE_BAKING_NOISE|
 													FLUID_CACHE_BAKING_MESH|FLUID_CACHE_BAKING_PARTICLES));
+		bool is_baked = (smd->domain->cache_flag & (FLUID_CACHE_BAKED_DATA|FLUID_CACHE_BAKED_NOISE|
+												   FLUID_CACHE_BAKED_MESH|FLUID_CACHE_BAKED_PARTICLES));
 
-		/* Reset fluid if no fluid present (obviously) or if timeline gets reset to startframe when no (!) baking is running */
-		if (!smd->domain->fluid || (framenr == startframe && !isBaking))
+		/* Reset fluid if no fluid present (obviously)
+		 * or if timeline gets reset to startframe when no (!) baking is running
+		 * or if no baking is running and also there is no baked data present */
+		if (!smd->domain->fluid || (framenr == startframe && !is_baking) || (!is_baking && !is_baked))
 			smokeModifier_reset_ex(smd, false);
 
 		if (!smd->domain->fluid && (framenr != startframe) && (smd->domain->flags & MOD_SMOKE_FILE_LOAD) == 0)
@@ -3136,14 +3150,10 @@ static void smokeModifier_process(SmokeModifierData *smd, Scene *scene, Object *
 		smd->domain->flags &= ~MOD_SMOKE_FILE_LOAD;
 		CLAMP(framenr, startframe, endframe);
 
-		/* If already viewing a pre/after frame, no need to reload */
-		if ((smd->time == framenr) && (framenr != scene->r.cfra))
-			return;
-
 		if (smokeModifier_init(smd, ob, scene, dm) == 0)
 			return;
 
-		if (isBaking) {
+		if (is_baking) {
 			if (smd->domain->cache_flag & FLUID_CACHE_BAKING_DATA) {
 				smoke_step(scene, ob, smd, framenr);
 				fluid_write_data(smd->domain->fluid, smd, framenr);
diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c
index 92ce2ff47ee..c6594ad7b2f 100644
--- a/source/blender/editors/physics/physics_fluid.c
+++ b/source/blender/editors/physics/physics_fluid.c
@@ -1145,6 +1145,8 @@ typedef struct FluidMantaflowJob {
 	
 	int success;
 	double start;
+
+	int* pause_frame;
 } FluidMantaflowJob;
 
 static bool fluid_manta_initjob(bContext *C, FluidMantaflowJob *job, wmOperator *op, char *error_msg, int error_size)
@@ -1182,10 +1184,10 @@ static void fluid_manta_bake_free(void *customdata)
 static void fluid_manta_bake_sequence(FluidMantaflowJob *job)
 {
 	SmokeDomainSettings *sds = job->smd->domain;
-	SmokeModifierData *smd = job->smd;
 	Scene *scene = job->scene;
 	int frame = 1, orig_frame;
 	int frames;
+	int *pause_frame = NULL;
 
 	frames = sds->cache_frame_end - sds->cache_frame_start + 1;
 
@@ -1198,21 +1200,27 @@ static void fluid_manta_bake_sequence(FluidMantaflowJob *job)
 	if (job->do_update)
 		*(job->do_update) = true;
 
+	/* Get current pause frame (pointer) - depending on bake type */
+	pause_frame = job->pause_frame;
+
 	/* Set frame to start 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list