[Bf-blender-cvs] [0756286ee1b] fluid-mantaflow: Mantaflow: Updated smoke.c to let mantaflow side handle inflow application

Sebastián Barschkis noreply at git.blender.org
Sat Apr 6 22:14:28 CEST 2019


Commit: 0756286ee1b32989d719e93e64bcffb909e9aa38
Author: Sebastián Barschkis
Date:   Sat Apr 6 00:00:16 2019 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rB0756286ee1b32989d719e93e64bcffb909e9aa38

Mantaflow: Updated smoke.c to let mantaflow side handle inflow application

Write inflow into separate inflow grids instead of writing directly into simulation grids

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

M	source/blender/blenkernel/intern/smoke.c

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

diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c
index 28e5de86714..45e4c6f0897 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -260,6 +260,7 @@ static void smoke_set_domain_gravity(Scene *scene, SmokeDomainSettings *sds)
 static int smokeModifier_init(SmokeModifierData *smd, Depsgraph *depsgraph, Object *ob, Scene *scene, Mesh *me)
 {
 	int scene_framenr = (int) DEG_get_ctime(depsgraph);
+
 	if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain && !smd->domain->fluid)
 	{
 		SmokeDomainSettings *sds = smd->domain;
@@ -457,7 +458,7 @@ void smokeModifier_createType(struct SmokeModifierData *smd)
 			/* domain object data */
 			smd->domain = MEM_callocN(sizeof(SmokeDomainSettings), "SmokeDomain");
 			smd->domain->smd = smd;
-			smd->domain->effector_weights = BKE_add_effector_weights(NULL);
+			smd->domain->effector_weights = BKE_effector_add_weights(NULL);
 			smd->domain->fluid = NULL;
 			smd->domain->fluid_mutex = BLI_rw_mutex_alloc();
 			smd->domain->eff_group = NULL;
@@ -582,6 +583,7 @@ void smokeModifier_createType(struct SmokeModifierData *smd)
 			smd->domain->slice_method = FLUID_DOMAIN_SLICE_VIEW_ALIGNED;
 			smd->domain->axis_slice_method = AXIS_SLICE_FULL;
 			smd->domain->slice_axis = 0;
+			smd->domain->interp_method = 0;
 			smd->domain->draw_velocity = false;
 			smd->domain->slice_per_voxel = 5.0f;
 			smd->domain->slice_depth = 0.5f;
@@ -1018,7 +1020,7 @@ static void obstacles_from_mesh_task_cb(
 						data->velocityX[index] += (data->scs->type == FLUID_EFFECTOR_TYPE_GUIDE) ? hit_vel[0] * data->scs->vel_multi : hit_vel[0];
 						data->velocityY[index] += (data->scs->type == FLUID_EFFECTOR_TYPE_GUIDE) ? hit_vel[1] * data->scs->vel_multi : hit_vel[1];
 						data->velocityZ[index] += (data->scs->type == FLUID_EFFECTOR_TYPE_GUIDE) ? hit_vel[2] * data->scs->vel_multi : hit_vel[2];
-//						printf("adding effector object vel: [%f, %f, %f], dx is: %f\n", hit_vel[0], hit_vel[1], hit_vel[2], sds->dx);
+						//printf("adding effector object vel: [%f, %f, %f], dx is: %f\n", hit_vel[0], hit_vel[1], hit_vel[2], sds->dx);
 					}
 				}
 			}
@@ -1191,8 +1193,8 @@ static void update_obstacles(Depsgraph *depsgraph, Scene* scene, Object *ob, Smo
 	float *r = smoke_get_color_r(sds->fluid);
 	float *g = smoke_get_color_g(sds->fluid);
 	float *b = smoke_get_color_b(sds->fluid);
-	float *phiObsIn = liquid_get_phiobsin(sds->fluid);
-	float *phiGuideIn = fluid_get_phiguidein(sds->fluid);
+	float *phiObsIn = fluid_get_phiobs_in(sds->fluid);
+	float *phiGuideIn = fluid_get_phiguide_in(sds->fluid);
 	int *obstacles = smoke_get_obstacle(sds->fluid);
 	int *num_obstacles = fluid_get_num_obstacle(sds->fluid);
 	int *num_guides = fluid_get_num_guide(sds->fluid);
@@ -1245,7 +1247,7 @@ static void update_obstacles(Depsgraph *depsgraph, Scene* scene, Object *ob, Smo
 				scene->r.subframe = 0.0f;
 				scene->r.cfra = frame;
 			}
-//			printf("effector: frame: %d // scene current frame: %d // scene current subframe: %f\n", frame, scene->r.cfra, scene->r.subframe);
+			//printf("effector: frame: %d // scene current frame: %d // scene current subframe: %f\n", frame, scene->r.cfra, scene->r.subframe);
 
 			/* TODO (sebbas): Using BKE_scene_frame_get(scene) instead of new DEG_get_ctime(depsgraph) as subframes dont work with the latter yet */
 			BKE_object_modifier_update_subframe(depsgraph, scene, collob, true, 5, BKE_scene_frame_get(scene), eModifierType_Smoke);
@@ -1905,7 +1907,7 @@ static void sample_mesh(
 				velocity_map[index * 3]   += hit_vel[0] * sfs->vel_multi;
 				velocity_map[index * 3 + 1] += hit_vel[1] * sfs->vel_multi;
 				velocity_map[index * 3 + 2] += hit_vel[2] * sfs->vel_multi;
-//				printf("adding flow object vel: [%f, %f, %f]\n", hit_vel[0], hit_vel[1], hit_vel[2]);
+				//printf("adding flow object vel: [%f, %f, %f]\n", hit_vel[0], hit_vel[1], hit_vel[2]);
 			}
 			velocity_map[index * 3] += sfs->vel_coord[0];
 			velocity_map[index * 3 + 1] += sfs->vel_coord[1];
@@ -2452,22 +2454,16 @@ BLI_INLINE void apply_outflow_fields(int index, float distance_value, float *den
 	}
 }
 
-BLI_INLINE void apply_inflow_fields(SmokeFlowSettings *sfs, float emission_value, float distance_value, int index, float *density, float *heat, float *fuel, float *react, float *color_r, float *color_g, float *color_b, float *phi, float *emission_in)
+BLI_INLINE void apply_inflow_fields(SmokeFlowSettings *sfs, float emission_value, float distance_value, int index, float *density, float *heat, float *fuel, float *react, float *color_r, float *color_g, float *color_b, float *phi)
 {
-	/* add liquid inflow */
+	/* add inflow */
 	if (phi) {
 		phi[index] = distance_value;
-		return;
-	}
-
-	/* save inflow value for mantaflow standalone */
-	if (emission_in) {
-		emission_in[index] = emission_value;
 	}
 
 	/* add smoke inflow */
 	int absolute_flow = (sfs->flags & FLUID_FLOW_ABSOLUTE);
-	float dens_old = density[index];
+	float dens_old = (density) ? density[index] : 0.0;
 	// float fuel_old = (fuel) ? fuel[index] : 0.0f;  /* UNUSED */
 	float dens_flow = (sfs->type == FLUID_FLOW_TYPE_FIRE) ? 0.0f : emission_value * sfs->density;
 	float fuel_flow = (fuel) ? emission_value * sfs->fuel_amount : 0.0f;
@@ -2475,24 +2471,25 @@ BLI_INLINE void apply_inflow_fields(SmokeFlowSettings *sfs, float emission_value
 	if (heat && emission_value > 0.0f) {
 		heat[index] = ADD_IF_LOWER(heat[index], sfs->temp);
 	}
-	/* absolute */
+
+	/* set density and fuel - absolute mode */
 	if (absolute_flow) {
-		if (sfs->type != FLUID_FLOW_TYPE_FIRE) {
+		if (density && sfs->type != FLUID_FLOW_TYPE_FIRE) {
 			if (dens_flow > density[index])
 				density[index] = dens_flow;
 		}
-		if (sfs->type != FLUID_FLOW_TYPE_SMOKE && fuel && fuel_flow) {
+		if (fuel && sfs->type != FLUID_FLOW_TYPE_SMOKE && fuel_flow) {
 			if (fuel_flow > fuel[index])
 				fuel[index] = fuel_flow;
 		}
 	}
-	/* additive */
+	/* set density and fuel - additive mode */
 	else {
-		if (sfs->type != FLUID_FLOW_TYPE_FIRE) {
+		if (density && sfs->type != FLUID_FLOW_TYPE_FIRE) {
 			density[index] += dens_flow;
 			CLAMP(density[index], 0.0f, 1.0f);
 		}
-		if (sfs->type != FLUID_FLOW_TYPE_SMOKE && fuel && sfs->fuel_amount) {
+		if (fuel && sfs->type != FLUID_FLOW_TYPE_SMOKE && sfs->fuel_amount) {
 			fuel[index] += fuel_flow;
 			CLAMP(fuel[index], 0.0f, 10.0f);
 		}
@@ -2540,8 +2537,11 @@ static void update_flowsflags(SmokeDomainSettings *sds, Object **flowobjs, int n
 			if (sfs->behavior == FLUID_FLOW_BEHAVIOR_OUTFLOW) {
 				active_fields |= FLUID_DOMAIN_ACTIVE_OUTFLOW;
 			}
+			/* liquids done from here */
+			if (sds->type == FLUID_DOMAIN_TYPE_LIQUID) continue;
+
 			/* activate heat field if flow produces any heat */
-			if (sfs->temp && sds->type == FLUID_DOMAIN_TYPE_GAS) {
+			if (sfs->temp) {
 				active_fields |= FLUID_DOMAIN_ACTIVE_HEAT;
 			}
 			/* activate fuel field if flow adds any fuel */
@@ -2562,7 +2562,7 @@ static void update_flowsflags(SmokeDomainSettings *sds, Object **flowobjs, int n
 		}
 	}
 	/* Monitor active fields based on domain settings */
-	if (active_fields & FLUID_DOMAIN_ACTIVE_FIRE) {
+	if (sds->type == FLUID_DOMAIN_TYPE_GAS && active_fields & FLUID_DOMAIN_ACTIVE_FIRE) {
 		/* heat is always needed for fire */
 		active_fields |= FLUID_DOMAIN_ACTIVE_HEAT;
 		/* also activate colors if domain smoke color differs from active color */
@@ -2700,7 +2700,7 @@ static void update_flowsfluids(
 						scene->r.cfra = frame;
 					}
 				}
-//				printf("flow: frame (is first: %d): %d // scene current frame: %d // scene current subframe: %f\n", is_first_frame, frame, scene->r.cfra, scene->r.subframe);
+				//printf("flow: 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 == FLUID_FLOW_SOURCE_PARTICLES) {
@@ -2751,8 +2751,8 @@ static void update_flowsfluids(
 		adjustDomainResolution(sds, new_shift, emaps, numflowobj, time_per_frame);
 	}
 
-	float *phi_in = liquid_get_phiin(sds->fluid);
-	float *phiout_in = liquid_get_phioutin(sds->fluid);
+	float *phi_in = fluid_get_phi_in(sds->fluid);
+	float *phiout_in = fluid_get_phiout_in(sds->fluid);
 	float *density = smoke_get_density(sds->fluid);
 	float *color_r = smoke_get_color_r(sds->fluid);
 	float *color_g = smoke_get_color_g(sds->fluid);
@@ -2760,13 +2760,15 @@ static void update_flowsfluids(
 	float *fuel = smoke_get_fuel(sds->fluid);
 	float *heat = smoke_get_heat(sds->fluid);
 	float *react = smoke_get_react(sds->fluid);
-	float *emission_in = smoke_get_emission_in(sds->fluid);
-//	float *bigdensity = smoke_turbulence_get_density(sds->fluid);
-//	float *bigfuel = smoke_turbulence_get_fuel(sds->fluid);
-//	float *bigreact = smoke_turbulence_get_react(sds->fluid);
-//	float *bigcolor_r = smoke_turbulence_get_color_r(sds->fluid);
-//	float *bigcolor_g = smoke_turbulence_get_color_g(sds->fluid);
-//	float *bigcolor_b = smoke_turbulence_get_color_b(sds->fluid);
+
+	float *density_in = smoke_get_density_in(sds->fluid);
+	float *heat_in = smoke_get_heat_in(sds->fluid);
+	float *color_r_in = smoke_get_color_r_in(sds->fluid);
+	float *color_g_in = smoke_get_color_g_in(sds->fluid);
+	float *color_b_in = smoke_get_color_b_in(sds->fluid);
+	float *fuel_in = smoke_get_fuel_in(sds->fluid);
+	float *react_in = smoke_get_react_in(sds->fluid);
+
 	float *velx_initial = fluid_get_in_velocity_x(sds->fluid);
 	float *vely_initial = fluid_get_in_velocity_y(sds->fluid);
 	float *velz_initial = fluid_get_in_velocity_z(sds->fluid);
@@ -2791,17 +2793,12 @@ static void update_flowsfluids(
 		if ((smd2->type & MOD_SMOKE_TYPE_FLOW) && smd2->flow) {
 			SmokeFlowSettings *sfs = smd2->flow;
 			EmissionMap *em = &emaps[flowIndex];
-//			int bigres[3];
 			float *velocity_map = em->velocity;
 			float *emission_map = em->influence;
-//			float *emission_map_high = em->influence_high;
 			float* distance_map = em->distances;
-//			float* distance_map_high = em->distances_high;
 
 			int gx, gy, gz, ex, ey, ez, dx, dy, dz;
-//			int ii, jj, kk, block_size;
 			size_t e_index, d_index;
-//			size_t index_big;
 
 			// loop 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list