Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/fluid.c')
-rw-r--r--source/blender/blenkernel/intern/fluid.c124
1 files changed, 76 insertions, 48 deletions
diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c
index 366137b5fa6..dc872b933eb 100644
--- a/source/blender/blenkernel/intern/fluid.c
+++ b/source/blender/blenkernel/intern/fluid.c
@@ -39,6 +39,7 @@
#include "BKE_effect.h"
#include "BKE_fluid.h"
+#include "BKE_global.h"
#include "BKE_lib_id.h"
#include "BKE_modifier.h"
#include "BKE_pointcache.h"
@@ -1893,40 +1894,6 @@ static void sample_mesh(FluidFlowSettings *mfs,
v3 = mloop[mlooptri[f_index].tri[2]].v;
interp_weights_tri_v3(weights, mvert[v1].co, mvert[v2].co, mvert[v3].co, nearest.co);
- /* Initial velocity of flow object. */
- if (mfs->flags & FLUID_FLOW_INITVELOCITY && velocity_map) {
- /* Apply normal directional velocity. */
- if (mfs->vel_normal) {
- /* Interpolate vertex normal vectors to get nearest point normal. */
- normal_short_to_float_v3(n1, mvert[v1].no);
- normal_short_to_float_v3(n2, mvert[v2].no);
- normal_short_to_float_v3(n3, mvert[v3].no);
- interp_v3_v3v3v3(hit_normal, n1, n2, n3, weights);
- normalize_v3(hit_normal);
-
- /* Apply normal directional velocity. */
- velocity_map[index * 3] += hit_normal[0] * mfs->vel_normal * 0.25f;
- velocity_map[index * 3 + 1] += hit_normal[1] * mfs->vel_normal * 0.25f;
- velocity_map[index * 3 + 2] += hit_normal[2] * mfs->vel_normal * 0.25f;
- }
- /* Apply object velocity. */
- if (has_velocity && mfs->vel_multi) {
- float hit_vel[3];
- interp_v3_v3v3v3(
- hit_vel, &vert_vel[v1 * 3], &vert_vel[v2 * 3], &vert_vel[v3 * 3], weights);
- velocity_map[index * 3] += hit_vel[0] * mfs->vel_multi;
- velocity_map[index * 3 + 1] += hit_vel[1] * mfs->vel_multi;
- velocity_map[index * 3 + 2] += hit_vel[2] * mfs->vel_multi;
-# ifdef DEBUG_PRINT
- /* Debugging: Print flow object velocities. */
- printf("adding flow object vel: [%f, %f, %f]\n", hit_vel[0], hit_vel[1], hit_vel[2]);
-# endif
- }
- velocity_map[index * 3] += mfs->vel_coord[0];
- velocity_map[index * 3 + 1] += mfs->vel_coord[1];
- velocity_map[index * 3 + 2] += mfs->vel_coord[2];
- }
-
/* Compute emission strength for smoke flow. */
if (is_gas_flow) {
/* Emission from surface is based on UI configurable distance value. */
@@ -1976,6 +1943,40 @@ static void sample_mesh(FluidFlowSettings *mfs,
emission_strength *= texres.tin;
}
}
+
+ /* Initial velocity of flow object. Only compute velocity if emission is present. */
+ if (mfs->flags & FLUID_FLOW_INITVELOCITY && velocity_map && emission_strength != 0.0) {
+ /* Apply normal directional velocity. */
+ if (mfs->vel_normal) {
+ /* Interpolate vertex normal vectors to get nearest point normal. */
+ normal_short_to_float_v3(n1, mvert[v1].no);
+ normal_short_to_float_v3(n2, mvert[v2].no);
+ normal_short_to_float_v3(n3, mvert[v3].no);
+ interp_v3_v3v3v3(hit_normal, n1, n2, n3, weights);
+ normalize_v3(hit_normal);
+
+ /* Apply normal directional velocity. */
+ velocity_map[index * 3] += hit_normal[0] * mfs->vel_normal * 0.25f;
+ velocity_map[index * 3 + 1] += hit_normal[1] * mfs->vel_normal * 0.25f;
+ velocity_map[index * 3 + 2] += hit_normal[2] * mfs->vel_normal * 0.25f;
+ }
+ /* Apply object velocity. */
+ if (has_velocity && mfs->vel_multi) {
+ float hit_vel[3];
+ interp_v3_v3v3v3(
+ hit_vel, &vert_vel[v1 * 3], &vert_vel[v2 * 3], &vert_vel[v3 * 3], weights);
+ velocity_map[index * 3] += hit_vel[0] * mfs->vel_multi;
+ velocity_map[index * 3 + 1] += hit_vel[1] * mfs->vel_multi;
+ velocity_map[index * 3 + 2] += hit_vel[2] * mfs->vel_multi;
+# ifdef DEBUG_PRINT
+ /* Debugging: Print flow object velocities. */
+ printf("adding flow object vel: [%f, %f, %f]\n", hit_vel[0], hit_vel[1], hit_vel[2]);
+# endif
+ }
+ velocity_map[index * 3] += mfs->vel_coord[0];
+ velocity_map[index * 3 + 1] += mfs->vel_coord[1];
+ velocity_map[index * 3 + 2] += mfs->vel_coord[2];
+ }
}
/* Apply final influence value but also consider volume initialization factor. */
@@ -3524,7 +3525,7 @@ static Mesh *create_smoke_geometry(FluidDomainSettings *mds, Mesh *orgmesh, Obje
return result;
}
-static void manta_step(
+static int manta_step(
Depsgraph *depsgraph, Scene *scene, Object *ob, Mesh *me, FluidModifierData *mmd, int frame)
{
FluidDomainSettings *mds = mmd->domain;
@@ -3532,17 +3533,22 @@ static void manta_step(
float time_per_frame;
bool init_resolution = true;
- /* update object state */
+ /* Store baking success - bake might be aborted anytime by user. */
+ int result = 1;
+ int mode = mds->cache_type;
+ bool mode_replay = (mode == FLUID_DOMAIN_CACHE_REPLAY);
+
+ /* Update object state. */
invert_m4_m4(mds->imat, ob->obmat);
copy_m4_m4(mds->obmat, ob->obmat);
- /* gas domain might use adaptive domain */
+ /* Gas domain might use adaptive domain. */
if (mds->type == FLUID_DOMAIN_TYPE_GAS) {
init_resolution = (mds->flags & FLUID_DOMAIN_USE_ADAPTIVE_DOMAIN) != 0;
}
manta_set_domain_from_mesh(mds, ob, me, init_resolution);
- /* use local variables for adaptive loop, dt can change */
+ /* Use local variables for adaptive loop, dt can change. */
frame_length = mds->frame_length;
dt = mds->dt;
time_per_frame = 0;
@@ -3550,27 +3556,39 @@ static void manta_step(
BLI_mutex_lock(&object_update_lock);
- /* loop as long as time_per_frame (sum of sub dt's) does not exceed actual framelength */
+ /* Loop as long as time_per_frame (sum of sub dt's) does not exceed actual framelength. */
while (time_per_frame < frame_length) {
manta_adapt_timestep(mds->fluid);
dt = manta_get_timestep(mds->fluid);
- /* save adapted dt so that MANTA object can access it (important when adaptive domain creates
- * new MANTA object) */
+ /* Save adapted dt so that MANTA object can access it (important when adaptive domain creates
+ * new MANTA object). */
mds->dt = dt;
- /* count for how long this while loop is running */
+ /* Count for how long this while loop is running. */
time_per_frame += dt;
time_total += dt;
- /* Calculate inflow geometry */
+ /* Calculate inflow geometry. */
update_flowsfluids(depsgraph, scene, ob, mds, time_per_frame, frame_length, frame, dt);
+ /* If user requested stop, quit baking */
+ if (G.is_break && !mode_replay) {
+ result = 0;
+ break;
+ }
+
manta_update_variables(mds->fluid, mmd);
- /* Calculate obstacle geometry */
+ /* Calculate obstacle geometry. */
update_obstacles(depsgraph, scene, ob, mds, time_per_frame, frame_length, frame, dt);
+ /* If user requested stop, quit baking */
+ if (G.is_break && !mode_replay) {
+ result = 0;
+ break;
+ }
+
if (mds->total_cells > 1) {
update_effectors(depsgraph, scene, ob, mds, dt);
manta_bake_data(mds->fluid, mmd, frame);
@@ -3578,12 +3596,20 @@ static void manta_step(
mds->time_per_frame = time_per_frame;
mds->time_total = time_total;
}
+
+ /* If user requested stop, quit baking */
+ if (G.is_break && !mode_replay) {
+ result = 0;
+ break;
+ }
}
if (mds->type == FLUID_DOMAIN_TYPE_GAS) {
manta_smoke_calc_transparency(mds, DEG_get_evaluated_view_layer(depsgraph));
}
BLI_mutex_unlock(&object_update_lock);
+
+ return result;
}
static void manta_guiding(
@@ -3952,9 +3978,11 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd,
manta_guiding(depsgraph, scene, ob, mmd, scene_framenr);
}
if (baking_data) {
- manta_step(depsgraph, scene, ob, me, mmd, scene_framenr);
- manta_write_config(mds->fluid, mmd, scene_framenr);
- manta_write_data(mds->fluid, mmd, scene_framenr);
+ /* Only save baked data if all of it completed successfully. */
+ if (manta_step(depsgraph, scene, ob, me, mmd, scene_framenr)) {
+ manta_write_config(mds->fluid, mmd, scene_framenr);
+ manta_write_data(mds->fluid, mmd, scene_framenr);
+ }
}
if (has_data || baking_data) {
if (baking_noise && with_smoke && with_noise) {
@@ -4851,7 +4879,7 @@ void BKE_fluid_modifier_create_type_data(struct FluidModifierData *mmd)
#else
mmd->domain->openvdb_comp = VDB_COMPRESSION_ZIP;
#endif
- mmd->domain->clipping = 1e-3f;
+ mmd->domain->clipping = 1e-6f;
mmd->domain->data_depth = 0;
}
else if (mmd->type & MOD_FLUID_TYPE_FLOW) {