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:
authorLukas Tönne <lukas.toenne@gmail.com>2016-12-28 19:30:58 +0300
committerLukas Tönne <lukas.toenne@gmail.com>2016-12-28 19:30:58 +0300
commit6ecab6dd8e48d564a2b43e0e81e79d079e8b4c77 (patch)
tree618e2d24eb34a05a81f726dd52eb2b7468e9296d /source/blender/blenkernel/intern/cloth.c
parent605263177b8eea24c1449e4dbf0138175ec3dddf (diff)
Revert particle system and point cache removal in blender2.8 branch.
This reverts commit 5aa19be91263a249ffae75573e3b32f24269d890 and b4a721af694817fa921b119df83d33ede7d7fed0. Due to postponement of particle system rewrite it was decided to put particle code back into the 2.8 branch for the time being.
Diffstat (limited to 'source/blender/blenkernel/intern/cloth.c')
-rw-r--r--source/blender/blenkernel/intern/cloth.c89
1 files changed, 83 insertions, 6 deletions
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index 87733341cdd..162525c7cd5 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -45,6 +45,7 @@
#include "BKE_effect.h"
#include "BKE_global.h"
#include "BKE_modifier.h"
+#include "BKE_pointcache.h"
#include "BPH_mass_spring.h"
@@ -130,6 +131,9 @@ void cloth_init(ClothModifierData *clmd )
if (!clmd->sim_parms->effector_weights)
clmd->sim_parms->effector_weights = BKE_add_effector_weights(NULL);
+
+ if (clmd->point_cache)
+ clmd->point_cache->step = 1;
}
static BVHTree *bvhselftree_build_from_cloth (ClothModifierData *clmd, float epsilon)
@@ -300,16 +304,35 @@ void bvhselftree_update_from_cloth(ClothModifierData *clmd, bool moving)
}
}
+void cloth_clear_cache(Object *ob, ClothModifierData *clmd, float framenr)
+{
+ PTCacheID pid;
+
+ BKE_ptcache_id_from_cloth(&pid, ob, clmd);
+
+ // don't do anything as long as we're in editmode!
+ if (pid.cache->edit && ob->mode & OB_MODE_PARTICLE_EDIT)
+ return;
+
+ BKE_ptcache_id_clear(&pid, PTCACHE_CLEAR_AFTER, framenr);
+}
+
static int do_init_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *result, int framenr)
{
+ PointCache *cache;
+
+ cache= clmd->point_cache;
+
/* initialize simulation data if it didn't exist already */
if (clmd->clothObject == NULL) {
if (!cloth_from_object(ob, clmd, result, framenr, 1)) {
+ BKE_ptcache_invalidate(cache);
modifier_setError(&(clmd->modifier), "Can't initialize cloth");
return 0;
}
if (clmd->clothObject == NULL) {
+ BKE_ptcache_invalidate(cache);
modifier_setError(&(clmd->modifier), "Null cloth object");
return 0;
}
@@ -347,7 +370,7 @@ static int do_step_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *resul
mul_m4_v3(ob->obmat, verts->xconst);
}
- effectors = pdInitEffectors(clmd->scene, ob, clmd->sim_parms->effector_weights, true);
+ effectors = pdInitEffectors(clmd->scene, ob, NULL, clmd->sim_parms->effector_weights, true);
if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_DYNAMIC_BASEMESH )
cloth_update_verts ( ob, clmd, result );
@@ -379,14 +402,27 @@ static int do_step_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *resul
************************************************/
void clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, DerivedMesh *dm, float (*vertexCos)[3])
{
- int framenr = scene->r.cfra, startframe = scene->r.sfra, endframe = scene->r.efra;
+ PointCache *cache;
+ PTCacheID pid;
+ float timescale;
+ int framenr, startframe, endframe;
+ int cache_result;
clmd->scene= scene; /* nice to pass on later :) */
+ framenr= (int)scene->r.cfra;
+ cache= clmd->point_cache;
- clmd->sim_parms->timescale = 1.0f;
+ BKE_ptcache_id_from_cloth(&pid, ob, clmd);
+ BKE_ptcache_id_time(&pid, scene, framenr, &startframe, &endframe, &timescale);
+ clmd->sim_parms->timescale= timescale * clmd->sim_parms->time_scale;
if (clmd->sim_parms->reset || (clmd->clothObject && dm->getNumVerts(dm) != clmd->clothObject->mvert_num)) {
clmd->sim_parms->reset = 0;
+ cache->flag |= PTCACHE_OUTDATED;
+ BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
+ BKE_ptcache_validate(cache, 0);
+ cache->last_exact= 0;
+ cache->flag &= ~PTCACHE_REDO_NEEDED;
}
// unused in the moment, calculated separately in implicit.c
@@ -394,6 +430,7 @@ void clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, Derived
/* simulation is only active during a specific period */
if (framenr < startframe) {
+ BKE_ptcache_invalidate(cache);
return;
}
else if (framenr > endframe) {
@@ -405,18 +442,58 @@ void clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, Derived
return;
if (framenr == startframe) {
+ BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
do_init_cloth(ob, clmd, dm, framenr);
+ BKE_ptcache_validate(cache, framenr);
+ cache->flag &= ~PTCACHE_REDO_NEEDED;
clmd->clothObject->last_frame= framenr;
return;
}
- if (framenr!=clmd->clothObject->last_frame+1)
+ /* try to read from cache */
+ bool can_simulate = (framenr == clmd->clothObject->last_frame+1) && !(cache->flag & PTCACHE_BAKED);
+
+ cache_result = BKE_ptcache_read(&pid, (float)framenr+scene->r.subframe, can_simulate);
+
+ if (cache_result == PTCACHE_READ_EXACT || cache_result == PTCACHE_READ_INTERPOLATED ||
+ (!can_simulate && cache_result == PTCACHE_READ_OLD)) {
+ BKE_cloth_solver_set_positions(clmd);
+ cloth_to_object (ob, clmd, vertexCos);
+
+ BKE_ptcache_validate(cache, framenr);
+
+ if (cache_result == PTCACHE_READ_INTERPOLATED && cache->flag & PTCACHE_REDO_NEEDED)
+ BKE_ptcache_write(&pid, framenr);
+
+ clmd->clothObject->last_frame= framenr;
+
+ return;
+ }
+ else if (cache_result==PTCACHE_READ_OLD) {
+ BKE_cloth_solver_set_positions(clmd);
+ }
+ else if ( /*ob->id.lib ||*/ (cache->flag & PTCACHE_BAKED)) { /* 2.4x disabled lib, but this can be used in some cases, testing further - campbell */
+ /* if baked and nothing in cache, do nothing */
+ BKE_ptcache_invalidate(cache);
return;
+ }
+
+ return;
+
+ /* if on second frame, write cache for first frame */
+ if (cache->simframe == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact==0))
+ BKE_ptcache_write(&pid, startframe);
- clmd->sim_parms->timescale *= 1.0f;
+ clmd->sim_parms->timescale *= framenr - cache->simframe;
/* do simulation */
- do_step_cloth(ob, clmd, dm, framenr);
+ BKE_ptcache_validate(cache, framenr);
+
+ if (!do_step_cloth(ob, clmd, dm, framenr)) {
+ BKE_ptcache_invalidate(cache);
+ }
+ else
+ BKE_ptcache_write(&pid, framenr);
cloth_to_object (ob, clmd, vertexCos);
clmd->clothObject->last_frame= framenr;