diff options
author | Sybren A. Stüvel <sybren@stuvel.eu> | 2018-06-19 12:33:48 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2018-06-19 12:49:56 +0300 |
commit | 8f922b30b0f92f16d096cb0be60cd85d8376807a (patch) | |
tree | 5af7b784ffc4bec426ae5c27c21572917f88b579 /source/blender | |
parent | caaf4e5a37119a4b479efaa8d9f00f0298646a25 (diff) |
RigidBodyWorld: copy ptcache from evaluated scene back to original scene
This makes it possible to perform re-evaluation of the scene without
having to re-run the simulation.
The CoW → Orig copy is only performed when the depsgraph is active, so
as to not influence the current scene while rendering in the background.
Alternatively, we could have the CoW copy share the cache with the
original to prevent too much copying of cache data. This will be faster,
but I'm not sure whether we can reliably check the DEG_is_active()
status at CoW copy creation time.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/rigidbody.c | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index 60ae37da09a..eec0e8b387d 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -1691,6 +1691,27 @@ void BKE_rigidbody_do_simulation(Depsgraph *depsgraph, Scene *scene, float ctime #endif /* WITH_BULLET */ + +/* Copy the pointcache from the evaluated to the original scene. + * This allows the re-evaluation of the original scene to use the + * physics cache. + */ +static void rigidbody_copy_cache_to_orig(Scene *scene_eval) +{ + if ((scene_eval->id.tag & LIB_TAG_COPIED_ON_WRITE) == 0) { + /* Scene is already an original, this function is a no-op. */ + return; + } + + Scene *scene_orig = (Scene *)DEG_get_original_id(&scene_eval->id); + RigidBodyWorld *rbw_orig = scene_orig->rigidbody_world; + RigidBodyWorld *rbw_eval = scene_eval->rigidbody_world; + + BKE_ptcache_free_list(&rbw_orig->ptcaches); + rbw_orig->pointcache = BKE_ptcache_copy_list(&rbw_orig->ptcaches, &rbw_eval->ptcaches, LIB_ID_COPY_CACHES); +} + + /* -------------------- */ /* Depsgraph evaluation */ @@ -1710,10 +1731,18 @@ void BKE_rigidbody_eval_simulation(Depsgraph *depsgraph, { float ctime = DEG_get_ctime(depsgraph); DEG_debug_print_eval_time(depsgraph, __func__, scene->id.name, scene, ctime); + /* evaluate rigidbody sim */ - if (BKE_scene_check_rigidbody_active(scene)) { - BKE_rigidbody_do_simulation(depsgraph, scene, ctime); + if (!BKE_scene_check_rigidbody_active(scene)) { + return; + } + BKE_rigidbody_do_simulation(depsgraph, scene, ctime); + + /* Make sure re-evaluation can use the cache from this simulation */ + if (!DEG_is_active(depsgraph)) { + return; } + rigidbody_copy_cache_to_orig(scene); } void BKE_rigidbody_object_sync_transforms(Depsgraph *depsgraph, |