From 70b061b4fdd487c971b12fd0f772767387ebc8f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Barschkis?= Date: Fri, 3 Apr 2020 16:38:38 +0200 Subject: Fluid: Refactored caching in main Mantaflow class This refactor cleans up code for the Manta file IO. It also improves the cache 'Replay' option. --- source/blender/blenkernel/intern/fluid.c | 38 +++++++++++++++++++++++------ source/blender/makesdna/DNA_fluid_types.h | 40 +++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 7 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c index e8da4385fb9..cbb933725eb 100644 --- a/source/blender/blenkernel/intern/fluid.c +++ b/source/blender/blenkernel/intern/fluid.c @@ -3673,8 +3673,14 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd, uint numobj = 0; FluidModifierData *mmd_parent = NULL; - bool is_startframe; + bool is_startframe, has_advanced; is_startframe = (scene_framenr == mds->cache_frame_start); + has_advanced = (scene_framenr == mmd->time + 1); + + /* Do not process modifier if current frame is out of cache range. */ + if (scene_framenr < mds->cache_frame_start || scene_framenr > mds->cache_frame_end) { + return; + } /* Reset fluid if no fluid present. */ if (!mds->fluid) { @@ -3766,6 +3772,20 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd, read_cache = false; bake_cache = baking_data || baking_noise || baking_mesh || baking_particles || baking_guide; + bool next_data, next_noise, next_mesh, next_particles, next_guide; + next_data = manta_has_data(mds->fluid, mmd, scene_framenr + 1); + next_noise = manta_has_noise(mds->fluid, mmd, scene_framenr + 1); + next_mesh = manta_has_mesh(mds->fluid, mmd, scene_framenr + 1); + next_particles = manta_has_particles(mds->fluid, mmd, scene_framenr + 1); + next_guide = manta_has_guiding(mds->fluid, mmd, scene_framenr + 1, guide_parent); + + bool prev_data, prev_noise, prev_mesh, prev_particles, prev_guide; + prev_data = manta_has_data(mds->fluid, mmd, scene_framenr - 1); + prev_noise = manta_has_noise(mds->fluid, mmd, scene_framenr - 1); + prev_mesh = manta_has_mesh(mds->fluid, mmd, scene_framenr - 1); + prev_particles = manta_has_particles(mds->fluid, mmd, scene_framenr - 1); + prev_guide = manta_has_guiding(mds->fluid, mmd, scene_framenr - 1, guide_parent); + bool with_gdomain; with_gdomain = (mds->guide_source == FLUID_DOMAIN_GUIDE_SRC_DOMAIN); @@ -3824,6 +3844,7 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd, default: /* Always trying to read the cache in replay mode. */ read_cache = true; + bake_cache = false; break; } @@ -3908,7 +3929,7 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd, BKE_fluid_reallocate_fluid(mds, mds->res, 1); } /* Read data cache */ - if (!baking_data && !baking_particles && !baking_mesh && !mode_replay) { + if (!baking_data && !baking_particles && !baking_mesh && next_data) { has_data = manta_update_smoke_structures(mds->fluid, mmd, data_frame); } else { @@ -3933,18 +3954,21 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd, break; case FLUID_DOMAIN_CACHE_REPLAY: default: - baking_data = !has_data; + baking_data = !has_data && (is_startframe || prev_data); if (with_smoke && with_noise) { - baking_noise = !has_noise; + baking_noise = !has_noise && (is_startframe || prev_noise); } if (with_liquid && with_mesh) { - baking_mesh = !has_mesh; + baking_mesh = !has_mesh && (is_startframe || prev_mesh); } if (with_liquid && with_particles) { - baking_particles = !has_particles; + baking_particles = !has_particles && (is_startframe || prev_particles); } - bake_cache = baking_data || baking_noise || baking_mesh || baking_particles; + /* Only bake if time advanced by one frame. */ + if (is_startframe || has_advanced) { + bake_cache = baking_data || baking_noise || baking_mesh || baking_particles; + } break; } diff --git a/source/blender/makesdna/DNA_fluid_types.h b/source/blender/makesdna/DNA_fluid_types.h index f344e860d2e..bb85d8304ec 100644 --- a/source/blender/makesdna/DNA_fluid_types.h +++ b/source/blender/makesdna/DNA_fluid_types.h @@ -215,6 +215,46 @@ enum { #define FLUID_DOMAIN_SMOKE_SCRIPT "smoke_script.py" #define FLUID_DOMAIN_LIQUID_SCRIPT "liquid_script.py" +#define FLUID_DOMAIN_FILE_CONFIG "config_####" + +#define FLUID_DOMAIN_FILE_DENSITY "density_####" +#define FLUID_DOMAIN_FILE_SHADOW "shadow_####" +#define FLUID_DOMAIN_FILE_VEL "vel_####" +#define FLUID_DOMAIN_FILE_HEAT "heat_####" +#define FLUID_DOMAIN_FILE_COLORR "color_r_####" +#define FLUID_DOMAIN_FILE_COLORG "color_g_####" +#define FLUID_DOMAIN_FILE_COLORB "color_b_####" +#define FLUID_DOMAIN_FILE_FLAME "flame_####" +#define FLUID_DOMAIN_FILE_FUEL "fuel_####" +#define FLUID_DOMAIN_FILE_REACT "react_####" + +#define FLUID_DOMAIN_FILE_PHI "phi_####" +#define FLUID_DOMAIN_FILE_PP "pp_####" +#define FLUID_DOMAIN_FILE_PVEL "pVel_####" + +#define FLUID_DOMAIN_FILE_DENSITYNOISE "density_noise_####" +#define FLUID_DOMAIN_FILE_COLORRNOISE "color_r_noise_####" +#define FLUID_DOMAIN_FILE_COLORGNOISE "color_g_noise_####" +#define FLUID_DOMAIN_FILE_COLORBNOISE "color_b_noise_####" +#define FLUID_DOMAIN_FILE_FLAMENOISE "flame_noise_####" +#define FLUID_DOMAIN_FILE_FUELNOISE "fuel_noise_####" +#define FLUID_DOMAIN_FILE_REACTNOISE "react_noise_####" + +#define FLUID_DOMAIN_FILE_MESH "lMesh_####" +#define FLUID_DOMAIN_FILE_MESHVEL "lVelMesh_####" + +#define FLUID_DOMAIN_FILE_PPSND "ppSnd_####" +#define FLUID_DOMAIN_FILE_PVELSND "pVelSnd_####" +#define FLUID_DOMAIN_FILE_PLIFESND "pLifeSnd_####" + +#define FLUID_DOMAIN_FILE_GUIDEVEL "guidevel_####" + +#define FLUID_DOMAIN_EXTENSION_UNI ".uni" +#define FLUID_DOMAIN_EXTENSION_OPENVDB ".vdb" +#define FLUID_DOMAIN_EXTENSION_RAW ".raw" +#define FLUID_DOMAIN_EXTENSION_OBJ ".obj" +#define FLUID_DOMAIN_EXTENSION_BINOBJ ".bobj.gz" + enum { FLUID_DOMAIN_CACHE_REPLAY = 0, FLUID_DOMAIN_CACHE_MODULAR = 1, -- cgit v1.2.3