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:
authorSybren A. Stüvel <sybren@stuvel.eu>2018-07-05 17:23:35 +0300
committerSybren A. Stüvel <sybren@stuvel.eu>2018-07-10 13:00:58 +0300
commitde55ae56ae5d871b5bc7fa6383c90ef89d66fcd1 (patch)
tree212fc7b15f9523bcc7a1a54906f1ba6bb6006a4f /source/blender/modifiers/intern/MOD_ocean.c
parentb9bef10d1953bda4e1eb882bdc525815c2e32e01 (diff)
Ocean Modifier: refactored the delayed-refresh approach
The approach of setting 'refresh' flags on the modifier, and performing the associated actions when the modifier is being evaluated, is a bad one. Instead, we use the separation of the original and the evaluated copy to 'refresh' certain things (because they simply aren't set at all on the original). Other actions are now done directly with BKE_ocean_xxx functions on the original data, intead of during evaluation.
Diffstat (limited to 'source/blender/modifiers/intern/MOD_ocean.c')
-rw-r--r--source/blender/modifiers/intern/MOD_ocean.c56
1 files changed, 14 insertions, 42 deletions
diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c
index 26011cfc121..b4c028a44e3 100644
--- a/source/blender/modifiers/intern/MOD_ocean.c
+++ b/source/blender/modifiers/intern/MOD_ocean.c
@@ -61,13 +61,6 @@ static void init_cache_data(Object *ob, struct OceanModifierData *omd)
omd->chop_amount, omd->foam_coverage, omd->foam_fade, omd->resolution);
}
-static void clear_cache_data(struct OceanModifierData *omd)
-{
- BKE_ocean_free_cache(omd->oceancache);
- omd->oceancache = NULL;
- omd->cached = false;
-}
-
/* keep in sync with init_ocean_modifier_bake(), object_modifier.c */
static void init_ocean_modifier(struct OceanModifierData *omd)
{
@@ -91,8 +84,6 @@ static void init_ocean_modifier(struct OceanModifierData *omd)
static void simulate_ocean_modifier(struct OceanModifierData *omd)
{
- if (!omd || !omd->ocean) return;
-
BKE_ocean_simulate(omd->ocean, omd->time, omd->wave_scale, omd->chop_amount);
}
#endif /* WITH_OCEANSIM */
@@ -126,8 +117,6 @@ static void initData(ModifierData *md)
omd->seed = 0;
omd->time = 1.0;
- omd->refresh = 0;
-
omd->size = 1.0;
omd->repeat_x = 1;
omd->repeat_y = 1;
@@ -174,10 +163,8 @@ static void copyData(const ModifierData *md, ModifierData *target, const int fla
modifier_copyData_generic(md, target, flag);
- tomd->refresh = 0;
-
- /* XXX todo: copy cache runtime too */
- tomd->cached = 0;
+ /* The oceancache object will be recreated for this copy
+ * automatically when cached=true */
tomd->oceancache = NULL;
tomd->ocean = BKE_ocean_add();
@@ -409,19 +396,18 @@ static Mesh *generate_ocean_geometry(OceanModifierData *omd)
return result;
}
-static Mesh *doOcean(
- ModifierData *md, Scene *scene, Object *ob,
- Mesh *mesh,
- int UNUSED(useRenderParams))
+static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
{
OceanModifierData *omd = (OceanModifierData *) md;
+ int cfra_scene = (int)DEG_get_ctime(ctx->depsgraph);
+ Object *ob = ctx->object;
Mesh *result = NULL;
OceanResult ocr;
MVert *mverts;
- int cfra;
+ int cfra_for_cache;
int i, j;
/* use cached & inverted value for speed
@@ -437,21 +423,12 @@ static Mesh *doOcean(
return mesh;
}
- /* update modifier */
- if (omd->refresh & MOD_OCEAN_REFRESH_RESET) {
- init_ocean_modifier(omd);
- }
- if (omd->refresh & MOD_OCEAN_REFRESH_CLEAR_CACHE) {
- clear_cache_data(omd);
- }
- omd->refresh = 0;
-
/* do ocean simulation */
if (omd->cached == true) {
if (!omd->oceancache) {
init_cache_data(ob, omd);
}
- BKE_ocean_simulate_cache(omd->oceancache, scene->r.cfra);
+ BKE_ocean_simulate_cache(omd->oceancache, cfra_scene);
}
else {
simulate_ocean_modifier(omd);
@@ -470,9 +447,9 @@ static Mesh *doOcean(
false);
}
- cfra = scene->r.cfra;
- CLAMP(cfra, omd->bakestart, omd->bakeend);
- cfra -= omd->bakestart; /* shift to 0 based */
+ cfra_for_cache = cfra_scene;
+ CLAMP(cfra_for_cache, omd->bakestart, omd->bakeend);
+ cfra_for_cache -= omd->bakestart; /* shift to 0 based */
mverts = result->mvert;
@@ -501,7 +478,7 @@ static Mesh *doOcean(
float foam;
if (omd->oceancache && omd->cached == true) {
- BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra, u, v);
+ BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra_for_cache, u, v);
foam = ocr.foam;
CLAMP(foam, 0.0f, 1.0f);
}
@@ -532,7 +509,7 @@ static Mesh *doOcean(
const float v = OCEAN_CO(size_co_inv, vco[1]);
if (omd->oceancache && omd->cached == true) {
- BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra, u, v);
+ BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra_for_cache, u, v);
}
else {
BKE_ocean_eval_uv(omd->ocean, &ocr, u, v);
@@ -552,10 +529,7 @@ static Mesh *doOcean(
return result;
}
#else /* WITH_OCEANSIM */
-static Mesh *doOcean(
- ModifierData *UNUSED(md), Scene *UNUSED(scene), Object *UNUSED(ob),
- Mesh *mesh,
- int UNUSED(useRenderParams))
+static Mesh *doOcean(ModifierData *UNUSED(md), const ModifierEvalContext *UNUSED(ctx), Mesh *mesh)
{
return mesh;
}
@@ -566,10 +540,8 @@ static Mesh *applyModifier(
Mesh *mesh)
{
Mesh *result;
- Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
-
- result = doOcean(md, scene, ctx->object, mesh, 0);
+ result = doOcean(md, ctx, mesh);
if (result != mesh)
result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;