[Bf-blender-cvs] [8ad5665ee6b] fluid-mantaflow: Mantaflow: Updated entire smoke.c code

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


Commit: 8ad5665ee6bfc33cb37bd574c84eda8564f96dd6
Author: Sebastián Barschkis
Date:   Sun Oct 28 18:26:52 2018 +0100
Branches: fluid-mantaflow
https://developer.blender.org/rB8ad5665ee6bfc33cb37bd574c84eda8564f96dd6

Mantaflow: Updated entire smoke.c code

Big customizations to make old smoke.c work with smoke and liquids

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

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

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

diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c
index be3a025a96f..7416c451206 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -22,6 +22,7 @@
  *
  * Contributor(s): Daniel Genrich
  *                 Blender Foundation
+ *                 Sebastian Barschkis (sebbas)
  *
  * ***** END GPL LICENSE BLOCK *****
  */
@@ -100,9 +101,11 @@
 #	include "PIL_time.h"
 #endif
 
-#include "smoke_API.h"
+#ifdef WITH_MANTA
+#	include "manta_fluid_API.h"
+#endif
 
-#ifdef WITH_SMOKE
+#ifdef WITH_MANTA
 
 static ThreadMutex object_update_lock = BLI_MUTEX_INITIALIZER;
 
@@ -118,71 +121,38 @@ struct SmokeModifierData;
 #define ADD_IF_LOWER_NEG(a, b) (max_ff((a) + (b), min_ff((a), (b))))
 #define ADD_IF_LOWER(a, b) (((b) > 0) ? ADD_IF_LOWER_POS((a), (b)) : ADD_IF_LOWER_NEG((a), (b)))
 
-#else /* WITH_SMOKE */
+#else /* WITH_MANTA */
 
 /* Stubs to use when smoke is disabled */
-struct WTURBULENCE *smoke_turbulence_init(int *UNUSED(res), int UNUSED(amplify), int UNUSED(noisetype), const char *UNUSED(noisefile_path), int UNUSED(use_fire), int UNUSED(use_colors)) { return NULL; }
-//struct FLUID_3D *smoke_init(int *UNUSED(res), float *UNUSED(dx), float *UNUSED(dtdef), int UNUSED(use_heat), int UNUSED(use_fire), int UNUSED(use_colors)) { return NULL; }
-void smoke_free(struct FLUID_3D *UNUSED(fluid)) {}
-float *smoke_get_density(struct FLUID_3D *UNUSED(fluid)) { return NULL; }
-void smoke_turbulence_free(struct WTURBULENCE *UNUSED(wt)) {}
-void smoke_initWaveletBlenderRNA(struct WTURBULENCE *UNUSED(wt), float *UNUSED(strength)) {}
-void smoke_initBlenderRNA(struct FLUID_3D *UNUSED(fluid), float *UNUSED(alpha), float *UNUSED(beta), float *UNUSED(dt_factor), float *UNUSED(vorticity),
-                          int *UNUSED(border_colli), float *UNUSED(burning_rate), float *UNUSED(flame_smoke), float *UNUSED(flame_smoke_color),
-                          float *UNUSED(flame_vorticity), float *UNUSED(flame_ignition_temp), float *UNUSED(flame_max_temp)) {}
+void fluid_free(struct FLUID *UNUSED(fluid));
+float *smoke_get_density(struct FLUID *UNUSED(fluid));
+
+void fluid_free(struct FLUID *UNUSED(fluid)) {}
+float *smoke_get_density(struct FLUID *UNUSED(fluid)) { return NULL; }
 struct Mesh *smokeModifier_do(SmokeModifierData *UNUSED(smd), Depsgraph *UNUSED(depsgraph), Scene *UNUSED(scene), Object *UNUSED(ob), Mesh *UNUSED(me)) { return NULL; }
 float smoke_get_velocity_at(struct Object *UNUSED(ob), float UNUSED(position[3]), float UNUSED(velocity[3])) { return 0.0f; }
 
-#endif /* WITH_SMOKE */
+#endif /* WITH_MANTA */
 
-#ifdef WITH_SMOKE
+#ifdef WITH_MANTA
 
-void smoke_reallocate_fluid(SmokeDomainSettings *sds, float dx, int res[3], int free_old)
+void smoke_reallocate_fluid(SmokeDomainSettings *sds, int res[3], int free_old)
 {
-	int use_heat = (sds->active_fields & SM_ACTIVE_HEAT);
-	int use_fire = (sds->active_fields & SM_ACTIVE_FIRE);
-	int use_colors = (sds->active_fields & SM_ACTIVE_COLORS);
-
 	if (free_old && sds->fluid)
-		smoke_free(sds->fluid);
+		fluid_free(sds->fluid);
 	if (!min_iii(res[0], res[1], res[2])) {
 		sds->fluid = NULL;
 		return;
 	}
-	sds->fluid = smoke_init(res, dx, DT_DEFAULT, use_heat, use_fire, use_colors);
-	smoke_initBlenderRNA(sds->fluid, &(sds->alpha), &(sds->beta), &(sds->time_scale), &(sds->vorticity), &(sds->border_collisions),
-	                     &(sds->burning_rate), &(sds->flame_smoke), sds->flame_smoke_color, &(sds->flame_vorticity), &(sds->flame_ignition), &(sds->flame_max_temp));
 
-	/* reallocate shadow buffer */
-	if (sds->shadow)
-		MEM_freeN(sds->shadow);
-	sds->shadow = MEM_callocN(sizeof(float) * res[0] * res[1] * res[2], "SmokeDomainShadow");
+	sds->fluid = fluid_init(res, sds->smd);
 }
 
-void smoke_reallocate_highres_fluid(SmokeDomainSettings *sds, float dx, int res[3], int free_old)
+void smoke_reallocate_highres_fluid(SmokeDomainSettings *sds, int res[3])
 {
-	int use_fire = (sds->active_fields & (SM_ACTIVE_HEAT | SM_ACTIVE_FIRE));
-	int use_colors = (sds->active_fields & SM_ACTIVE_COLORS);
-
-	if (free_old && sds->wt)
-		smoke_turbulence_free(sds->wt);
-	if (!min_iii(res[0], res[1], res[2])) {
-		sds->wt = NULL;
-		return;
-	}
-
-	/* smoke_turbulence_init uses non-threadsafe functions from fftw3 lib (like fftw_plan & co). */
-	BLI_thread_lock(LOCK_FFTW);
-
-	sds->wt = smoke_turbulence_init(res, sds->amplify + 1, sds->noise, BKE_tempdir_session(), use_fire, use_colors);
-
-	BLI_thread_unlock(LOCK_FFTW);
-
-	sds->res_wt[0] = res[0] * (sds->amplify + 1);
-	sds->res_wt[1] = res[1] * (sds->amplify + 1);
-	sds->res_wt[2] = res[2] * (sds->amplify + 1);
-	sds->dx_wt = dx / (sds->amplify + 1);
-	smoke_initWaveletBlenderRNA(sds->wt, &(sds->strength));
+	sds->res_noise[0] = res[0] * sds->noise_scale;
+	sds->res_noise[1] = res[1] * sds->noise_scale;
+	sds->res_noise[2] = res[2] * sds->noise_scale;
 }
 
 /* convert global position to domain cell space */
@@ -274,14 +244,40 @@ static void smoke_set_domain_from_mesh(SmokeDomainSettings *sds, Object *ob, Mes
 	sds->cell_size[2] /= (float)sds->base_res[2];
 }
 
-static int smokeModifier_init(SmokeModifierData *smd, Object *ob, int scene_framenr, Mesh *me)
+static void smoke_set_domain_gravity(Scene *scene, SmokeDomainSettings *sds)
+{
+	float gravity[3] = {0.0f, 0.0f, -1.0f};
+	float gravity_mag;
+
+	/* use global gravity if enabled */
+	if (scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY) {
+		copy_v3_v3(gravity, scene->physics_settings.gravity);
+		/* map default value to 1.0 */
+		mul_v3_fl(gravity, 1.0f / 9.810f);
+
+		/* convert gravity to domain space */
+		gravity_mag = len_v3(gravity);
+		mul_mat3_m4_v3(sds->imat, gravity);
+		normalize_v3(gravity);
+		mul_v3_fl(gravity, gravity_mag);
+
+		sds->gravity[0] = gravity[0];
+		sds->gravity[1] = gravity[1];
+		sds->gravity[2] = gravity[2];
+	}
+}
+
+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;
 		int res[3];
-		/* set domain dimensions from mesh */
+		/* set domain dimensions from derivedmesh */
 		smoke_set_domain_from_mesh(sds, ob, me, true);
+		/* set domain gravity */
+		smoke_set_domain_gravity(scene, sds);
 		/* reset domain values */
 		zero_v3_int(sds->shift);
 		zero_v3(sds->shift_f);
@@ -291,7 +287,7 @@ static int smokeModifier_init(SmokeModifierData *smd, Object *ob, int scene_fram
 		copy_m4_m4(sds->obmat, ob->obmat);
 
 		/* set resolutions */
-		if (smd->domain->flags & MOD_SMOKE_ADAPTIVE_DOMAIN) {
+		if (smd->domain->flags & FLUID_DOMAIN_USE_ADAPTIVE_DOMAIN) {
 			res[0] = res[1] = res[2] = 1; /* use minimum res for adaptive init */
 		}
 		else {
@@ -302,61 +298,53 @@ static int smokeModifier_init(SmokeModifierData *smd, Object *ob, int scene_fram
 		sds->res_min[0] = sds->res_min[1] = sds->res_min[2] = 0;
 		VECCOPY(sds->res_max, res);
 
+		/* set time, dt = 0.1 is at 25fps */
+		float fps = scene->r.frs_sec / scene->r.frs_sec_base;
+		sds->dt = DT_DEFAULT * (25.0f / fps);
+
 		/* allocate fluid */
-		smoke_reallocate_fluid(sds, sds->dx, sds->res, 0);
+		smoke_reallocate_fluid(sds, sds->res, 0);
 
 		smd->time = scene_framenr;
 
 		/* allocate highres fluid */
-		if (sds->flags & MOD_SMOKE_HIGHRES) {
-			smoke_reallocate_highres_fluid(sds, sds->dx, sds->res, 0);
+		if (sds->flags & FLUID_DOMAIN_USE_NOISE) {
+			smoke_reallocate_highres_fluid(sds, sds->res);
 		}
-		/* allocate shadow buffer */
-		if (!sds->shadow)
-			sds->shadow = MEM_callocN(sizeof(float) * sds->res[0] * sds->res[1] * sds->res[2], "SmokeDomainShadow");
 
 		return 1;
 	}
-	else if ((smd->type & MOD_SMOKE_TYPE_FLOW) && smd->flow)
+	else if (smd->type & MOD_SMOKE_TYPE_FLOW)
 	{
+		if (!smd->flow) {
+			smokeModifier_createType(smd);
+		}
 		smd->time = scene_framenr;
-
 		return 1;
 	}
-	else if ((smd->type & MOD_SMOKE_TYPE_COLL))
+	else if (smd->type & MOD_SMOKE_TYPE_EFFEC)
 	{
-		if (!smd->coll)
-		{
+		if (!smd->effec) {
 			smokeModifier_createType(smd);
 		}
-
 		smd->time = scene_framenr;
-
 		return 1;
 	}
-
 	return 2;
 }
 
-#endif /* WITH_SMOKE */
+#endif /* WITH_MANTA */
 
 static void smokeModifier_freeDomain(SmokeModifierData *smd)
 {
 	if (smd->domain)
 	{
-		if (smd->domain->shadow)
-			MEM_freeN(smd->domain->shadow);
-		smd->domain->shadow = NULL;
-
 		if (smd->domain->fluid)
-			smoke_free(smd->domain->fluid);
+			fluid_free(smd->domain->fluid);
 
 		if (smd->domain->fluid_mutex)
 			BLI_rw_mutex_free(smd->domain->fluid_mutex);
 
-		if (smd->domain->wt)
-			smoke_turbulence_free(smd->domain->wt);
-
 		if (smd->domain->effector_weights)
 			MEM_freeN(smd->domain->effector_weights);
 		smd->domain->effector_weights = NULL;
@@ -366,6 +354,10 @@ static void smokeModifier_freeDomain(SmokeModifierData *smd)
 			smd->domain->point_cache[0] = NULL;
 		}
 
+		if (smd->domain->mesh_velocities)
+			MEM_freeN(smd->domain->mesh_velocities);
+		smd->domain->mesh_velocities = NULL;
+
 		if (smd->domain->coba) {
 			MEM_freeN(smd->domain->coba);
 		}
@@ -379,8 +371,15 @@ static void smokeModifier_freeFlow(SmokeModifierData *smd)
 {
 	if (smd->flow)
 	{
-		if (smd->flow->mesh) BKE_id_free(NULL, smd->flow->mesh);
-		if (smd->flow->verts_old) MEM_freeN(smd->flow->verts_old);
+		if (smd->flow->mesh)
+			BKE_id_free(NULL, smd->flow->mesh);
+		smd->flow->mesh = NULL;
+
+		if (smd->flow->verts_old)
+			MEM_freeN(smd->flow->verts_old);
+		smd->flow->verts_old = NULL;
+		smd->flow->numverts = 0;
+
 		MEM_freeN(smd->flow);
 		smd->flow = NULL;
 	}
@@ -388,34 +387,19 @@ static void smokeModifier_freeFlow(SmokeModifierData *smd)
 
 static void smokeModifier_freeCollision(SmokeModifierData *smd)
 {
-	if (smd->coll)
+	if (smd->effec)
 	{
-		SmokeCollSettings *scs = smd->coll;
-
-		if (scs->numverts)
-		{
-			if (scs->verts_old)
-			{
-				MEM_freeN(scs->verts_old);
-				scs->verts_old = NULL;
-			}
-		}
-
-		if (smd->coll->mesh)
-			BKE_id_free(NULL, smd->coll->mesh);
-		smd->coll->mesh = NULL;
+		if (smd->effec->mesh)
+			BKE_id_free(NULL, smd->effec->mesh);
+		smd->effec->mesh = NULL;
 
-		MEM_freeN(

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list