[Bf-blender-cvs] [8f922b30b0f] blender2.8: RigidBodyWorld: copy ptcache from evaluated scene back to original scene

Sybren A. Stüvel noreply at git.blender.org
Tue Jun 19 11:50:47 CEST 2018


Commit: 8f922b30b0f92f16d096cb0be60cd85d8376807a
Author: Sybren A. Stüvel
Date:   Tue Jun 19 11:33:48 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB8f922b30b0f92f16d096cb0be60cd85d8376807a

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.

===================================================================

M	source/blender/blenkernel/intern/rigidbody.c

===================================================================

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,



More information about the Bf-blender-cvs mailing list