[Bf-blender-cvs] [b321526] gooseberry: Replaced point cache in cloth modifiers (also hair) with the new caching system.
Lukas Tönne
noreply at git.blender.org
Mon Mar 23 13:01:33 CET 2015
Commit: b321526888a1fd696927a530c9be0ec6bf5684d7
Author: Lukas Tönne
Date: Thu Feb 26 09:43:33 2015 +0100
Branches: gooseberry
https://developer.blender.org/rBb321526888a1fd696927a530c9be0ec6bf5684d7
Replaced point cache in cloth modifiers (also hair) with the new caching
system.
Conflicts:
source/blender/blenkernel/intern/cloth.c
===================================================================
M source/blender/blenkernel/BKE_cache_library.h
M source/blender/blenkernel/BKE_cloth.h
M source/blender/blenkernel/BKE_pointcache.h
M source/blender/blenkernel/intern/bpath.c
M source/blender/blenkernel/intern/cache_library.c
M source/blender/blenkernel/intern/cloth.c
M source/blender/blenkernel/intern/object.c
M source/blender/blenkernel/intern/particle_system.c
M source/blender/blenkernel/intern/pointcache.c
M source/blender/blenloader/intern/readfile.c
M source/blender/blenloader/intern/versioning_legacy.c
M source/blender/blenloader/intern/writefile.c
M source/blender/makesdna/DNA_modifier_types.h
M source/blender/makesrna/intern/rna_modifier.c
M source/blender/modifiers/intern/MOD_cloth.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_cache_library.h b/source/blender/blenkernel/BKE_cache_library.h
index 467780e..7c56ad8 100644
--- a/source/blender/blenkernel/BKE_cache_library.h
+++ b/source/blender/blenkernel/BKE_cache_library.h
@@ -39,6 +39,8 @@ struct Main;
struct Object;
struct Scene;
+struct ClothModifierData;
+
struct CacheLibrary *BKE_cache_library_add(struct Main *bmain, const char *name);
struct CacheLibrary *BKE_cache_library_copy(struct CacheLibrary *cachelib);
void BKE_cache_library_free(struct CacheLibrary *cachelib);
@@ -86,5 +88,7 @@ void BKE_cache_library_clear(struct CacheLibrary *cachelib);
void BKE_cache_library_group_update(struct Main *bmain, struct CacheLibrary *cachelib);
bool BKE_cache_read_derived_mesh(struct Main *bmain, struct Scene *scene, float frame, struct Object *ob, struct DerivedMesh **r_dm);
+bool BKE_cache_read_cloth(struct Main *bmain, struct Scene *scene, float frame, struct Object *ob, struct ClothModifierData *clmd);
+bool BKE_cache_read_hair_dynamics(struct Main *bmain, struct Scene *scene, float frame, struct Object *ob, struct ParticleSystem *psys);
#endif
diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h
index a7fad85..e985201 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -240,9 +240,6 @@ int cloth_uses_vgroup(struct ClothModifierData *clmd);
void bvhtree_update_from_cloth (struct ClothModifierData *clmd, int moving );
void bvhselftree_update_from_cloth (struct ClothModifierData *clmd, int moving );
-// needed for button_object.c
-void cloth_clear_cache (struct Object *ob, struct ClothModifierData *clmd, float framenr );
-
// needed for cloth.c
int cloth_add_spring (struct ClothModifierData *clmd, unsigned int indexA, unsigned int indexB, float restlength, int spring_type);
diff --git a/source/blender/blenkernel/BKE_pointcache.h b/source/blender/blenkernel/BKE_pointcache.h
index e18e9d4..cf0513d 100644
--- a/source/blender/blenkernel/BKE_pointcache.h
+++ b/source/blender/blenkernel/BKE_pointcache.h
@@ -260,7 +260,6 @@ void BKE_ptcache_make_particle_key(struct ParticleKey *key, int index, void **da
/**************** Creating ID's ****************************/
void BKE_ptcache_id_from_softbody(PTCacheID *pid, struct Object *ob, struct SoftBody *sb);
void BKE_ptcache_id_from_particles(PTCacheID *pid, struct Object *ob, struct ParticleSystem *psys);
-void BKE_ptcache_id_from_cloth(PTCacheID *pid, struct Object *ob, struct ClothModifierData *clmd);
void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeModifierData *smd);
void BKE_ptcache_id_from_dynamicpaint(PTCacheID *pid, struct Object *ob, struct DynamicPaintSurface *surface);
void BKE_ptcache_id_from_rigidbody(PTCacheID *pid, struct Object *ob, struct RigidBodyWorld *rbw);
diff --git a/source/blender/blenkernel/intern/bpath.c b/source/blender/blenkernel/intern/bpath.c
index 4d40aba..1db58a0 100644
--- a/source/blender/blenkernel/intern/bpath.c
+++ b/source/blender/blenkernel/intern/bpath.c
@@ -484,10 +484,6 @@ void BKE_bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int
BPATH_TRAVERSE_POINTCACHE(smd->domain->ptcaches[0]);
}
}
- else if (md->type == eModifierType_Cloth) {
- ClothModifierData *clmd = (ClothModifierData *) md;
- BPATH_TRAVERSE_POINTCACHE(clmd->ptcaches);
- }
else if (md->type == eModifierType_Ocean) {
OceanModifierData *omd = (OceanModifierData *) md;
rewrite_path_fixed(omd->cachepath, visit_cb, absbase, bpath_user_data);
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index 2a4956f..a5bfd92 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -525,3 +525,25 @@ bool BKE_cache_read_derived_mesh(Main *bmain, Scene *scene, float frame, Object
}
return false;
}
+
+bool BKE_cache_read_cloth(Main *bmain, Scene *scene, float frame, Object *ob, struct ClothModifierData *clmd)
+{
+// CacheLibrary *cachelib;
+
+// for (cachelib = bmain->cache_library.first; cachelib; cachelib = cachelib->id.next) {
+// if (PTC_cachelib_read_sample_cloth(scene, frame, cachelib, ob, clmd) != PTC_READ_SAMPLE_INVALID)
+// return true;
+// }
+ return false;
+}
+
+bool BKE_cache_read_hair_dynamics(Main *bmain, Scene *scene, float frame, Object *ob, struct ParticleSystem *psys)
+{
+ CacheLibrary *cachelib;
+
+ for (cachelib = bmain->cache_library.first; cachelib; cachelib = cachelib->id.next) {
+ if (PTC_cachelib_read_sample_hair_dynamics(scene, frame, cachelib, ob, psys) != PTC_READ_SAMPLE_INVALID)
+ return true;
+ }
+ return false;
+}
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index e4eac01..1177107 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -34,18 +34,19 @@
#include "DNA_scene_types.h"
#include "DNA_object_types.h"
#include "DNA_meshdata_types.h"
+#include "DNA_particle_types.h"
#include "BLI_utildefines.h"
#include "BLI_math.h"
#include "BLI_edgehash.h"
#include "BLI_linklist.h"
+#include "BKE_cache_library.h"
#include "BKE_cdderivedmesh.h"
#include "BKE_cloth.h"
#include "BKE_effect.h"
#include "BKE_global.h"
#include "BKE_modifier.h"
-#include "BKE_pointcache.h"
#include "BPH_mass_spring.h"
@@ -126,9 +127,6 @@ 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)
@@ -304,35 +302,16 @@ void bvhselftree_update_from_cloth(ClothModifierData *clmd, int 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;
}
@@ -448,99 +427,65 @@ static DerivedMesh *cloth_to_triangles(DerivedMesh *dm)
************************************************/
void clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, DerivedMesh *dm, float (*vertexCos)[3])
{
- PointCache *cache;
- PTCacheID pid;
- float timescale;
- int framenr, startframe, endframe;
- int cache_result;
+ const int startframe = scene->r.sfra;
+ int framenr;
+ bool cache_result;
clmd->scene= scene; /* nice to pass on later :) */
framenr= (int)scene->r.cfra;
- cache= clmd->point_cache;
- BKE_ptcache_id_from_cloth(&pid, ob, clmd);
- BKE_ptcache_id_time(&pid, scene, framenr, &startframe, &endframe, ×cale);
- clmd->sim_parms->timescale= timescale;
+ clmd->sim_parms->timescale = 1.0f;
if (clmd->sim_parms->reset || (clmd->clothObject && dm->getNumVerts(dm) != clmd->clothObject->numverts)) {
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
clmd->sim_parms->dt = clmd->sim_parms->timescale / clmd->sim_parms->stepsPerFrame;
- /* simulation is only active during a specific period */
- if (framenr < startframe) {
- BKE_ptcache_invalidate(cache);
- return;
- }
- else if (framenr > endframe) {
- framenr= endframe;
- }
-
/* initialize simulation data if it didn't exist already */
if (!do_init_cloth(ob, clmd, dm, framenr))
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;
+ cloth_from_object(ob, clmd, dm, framenr, true);
+ BKE_cloth_solver_set_positions(clmd);
+ clmd->clothObject->last_frame = framenr;
return;
}
/* try to read from cache */
- cache_result = BKE_ptcache_read(&pid, (float)framenr+scene->r.subframe);
+ cache_result = false;
+ if (clmd->hairdata) {
+ ParticleSystem *psys;
+ /* horrible */
+ for (psys = ob->particlesystem.first; psys; psys = psys->next) {
+ if (psys->clmd == clmd)
+ break;
+ }
+
+ if (psys)
+ cache_result = BKE_cache_read_hair_dynamics(G.main, scene, scene->r.cfra, ob, psys);
+ }
+ else {
+ cache_result = BKE_cache_read_cloth(G.main, scene, scene->r.cfra, ob, clmd);
+ }
- if (cache_result == PTCACHE_READ_EXACT || cache_result == PTCACHE_READ_INTERPOLATED) {
- BPH_cloth_solver_set_positions(clmd);
+ if (cache_result) {
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) {
- BPH_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;
- }
-
- if (framenr!=clmd->clothObject->last_frame+1)
- return;
-
- /* if on second frame, write cache for first frame */
- if (cache->simframe == startfr
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list