[Bf-blender-cvs] [c2110213ca7] blender2.8: Physics: update softbody and dynamic paint to get colliders from depsgraph.

Brecht Van Lommel noreply at git.blender.org
Mon Jun 25 17:19:04 CEST 2018


Commit: c2110213ca7a6b8ba2392cf6e8f5a61b7ba4b554
Author: Brecht Van Lommel
Date:   Mon Jun 25 14:21:15 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBc2110213ca7a6b8ba2392cf6e8f5a61b7ba4b554

Physics: update softbody and dynamic paint to get colliders from depsgraph.

Because looping over the scene is unsafe and slow.

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

M	source/blender/blenkernel/BKE_collection.h
M	source/blender/blenkernel/intern/collection.c
M	source/blender/blenkernel/intern/collision.c
M	source/blender/blenkernel/intern/dynamicpaint.c
M	source/blender/blenkernel/intern/effect.c
M	source/blender/blenkernel/intern/softbody.c
M	source/blender/depsgraph/intern/depsgraph_physics.cc

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

diff --git a/source/blender/blenkernel/BKE_collection.h b/source/blender/blenkernel/BKE_collection.h
index f543286d01e..175ee61c690 100644
--- a/source/blender/blenkernel/BKE_collection.h
+++ b/source/blender/blenkernel/BKE_collection.h
@@ -96,10 +96,7 @@ bool BKE_collection_object_cyclic_check(struct Main *bmain, struct Object *objec
 struct ListBase BKE_collection_object_cache_get(struct Collection *collection);
 void BKE_collection_object_cache_free(struct Collection *collection);
 
-struct Base *BKE_collection_or_layer_objects(const struct Depsgraph *depsgraph,
-                                             const struct Scene *scene,
-                                             const struct ViewLayer *view_layer,
-                                             struct Collection *collection);
+struct Base *BKE_collection_or_layer_objects(const struct ViewLayer *view_layer, struct Collection *collection);
 
 /* Editing. */
 
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index 8a3d27ca790..1d9cc9bb8d0 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -364,36 +364,13 @@ void BKE_collection_object_cache_free(Collection *collection)
 	collection_object_cache_free(collection);
 }
 
-Base *BKE_collection_or_layer_objects(const Depsgraph *depsgraph,
-                                      const Scene *scene,
-                                      const ViewLayer *view_layer,
-                                      Collection *collection)
+Base *BKE_collection_or_layer_objects(const ViewLayer *view_layer, Collection *collection)
 {
-	// TODO: this is used by physics to get objects from a collection, but the
-	// the physics systems are not all using the depsgraph correctly which means
-	// we try different things. Instead we should explicitly get evaluated or
-	// non-evaluated data and always have the depsgraph available when needed
-
 	if (collection) {
 		return BKE_collection_object_cache_get(collection).first;
 	}
-	else if (depsgraph) {
-		view_layer = DEG_get_evaluated_view_layer(depsgraph);
-
-		if (view_layer) {
-			return FIRSTBASE(view_layer);
-		}
-		else {
-			view_layer = DEG_get_input_view_layer(depsgraph);
-			return FIRSTBASE(view_layer);
-		}
-	}
-	else if (view_layer) {
-		return FIRSTBASE(view_layer);
-	}
 	else {
-		/* depsgraph is NULL during deg build */
-		return FIRSTBASE(BKE_view_layer_context_active_PLACEHOLDER(scene));
+		return FIRSTBASE(view_layer);
 	}
 }
 
diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c
index 1debdbb847e..a734e140932 100644
--- a/source/blender/blenkernel/intern/collision.c
+++ b/source/blender/blenkernel/intern/collision.c
@@ -518,7 +518,7 @@ static void add_collision_object(ListBase *relations, Object *ob, int level, uns
 ListBase *BKE_collision_relations_create(Depsgraph *depsgraph, Collection *collection, unsigned int modifier_type)
 {
 	ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
-	Base *base = BKE_collection_or_layer_objects(NULL, NULL, view_layer, collection);
+	Base *base = BKE_collection_or_layer_objects(view_layer, collection);
 	const bool for_render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
 	const int base_flag = (for_render) ? BASE_ENABLED_RENDER : BASE_ENABLED_VIEWPORT;
 
@@ -548,6 +548,7 @@ Object **BKE_collision_objects_create(Depsgraph *depsgraph, Object *self, Collec
 	ListBase *relations = DEG_get_collision_relations(depsgraph, collection, modifier_type);
 
 	if (!relations) {
+		*numcollobj = 0;
 		return NULL;
 	}
 
diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c
index 0d694a4d25c..c1bdfc42a05 100644
--- a/source/blender/blenkernel/intern/dynamicpaint.c
+++ b/source/blender/blenkernel/intern/dynamicpaint.c
@@ -56,6 +56,7 @@
 #include "BKE_armature.h"
 #include "BKE_bvhutils.h"   /* bvh tree */
 #include "BKE_collection.h"
+#include "BKE_collision.h"
 #include "BKE_colorband.h"
 #include "BKE_cdderivedmesh.h"
 #include "BKE_constraint.h"
@@ -490,28 +491,17 @@ static void scene_setSubframe(Scene *scene, float subframe)
 	scene->r.subframe = subframe;
 }
 
-static int surface_getBrushFlags(DynamicPaintSurface *surface, const Depsgraph *depsgraph)
+static int surface_getBrushFlags(DynamicPaintSurface *surface, Depsgraph *depsgraph)
 {
-	Base *base = BKE_collection_or_layer_objects(depsgraph, NULL, NULL, surface->brush_group);
-	Object *brushObj = NULL;
-	ModifierData *md = NULL;
+	unsigned int numobjects;
+	Object **objects = BKE_collision_objects_create(depsgraph, NULL, surface->brush_group, &numobjects, eModifierType_DynamicPaint);
 
 	int flags = 0;
 
-	while (base) {
-		brushObj = NULL;
+	for (int i = 0; i < numobjects; i++) {
+		Object *brushObj = objects[i];
 
-		/* select object */
-		brushObj = base->object;
-
-		/* next item */
-		base = base->next;
-
-		if (!brushObj) {
-			continue;
-		}
-
-		md = modifiers_findByType(brushObj, eModifierType_DynamicPaint);
+		ModifierData *md = modifiers_findByType(brushObj, eModifierType_DynamicPaint);
 		if (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) {
 			DynamicPaintModifierData *pmd2 = (DynamicPaintModifierData *)md;
 
@@ -524,6 +514,8 @@ static int surface_getBrushFlags(DynamicPaintSurface *surface, const Depsgraph *
 		}
 	}
 
+	BKE_collision_objects_free(objects);
+
 	return flags;
 }
 
@@ -5758,7 +5750,7 @@ static void dynamic_paint_generate_bake_data_cb(
 	}
 }
 
-static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, const Depsgraph *depsgraph, Object *ob)
+static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Depsgraph *depsgraph, Object *ob)
 {
 	PaintSurfaceData *sData = surface->data;
 	PaintBakeData *bData = sData->bData;
@@ -5911,29 +5903,18 @@ static int dynamicPaint_doStep(
 	 * Loop through surface's target paint objects and do painting
 	 */
 	{
-		Object *brushObj = NULL;
-		ModifierData *md = NULL;
-		Base *base = BKE_collection_or_layer_objects(depsgraph, NULL, NULL, surface->brush_group);
+		unsigned int numobjects;
+		Object **objects = BKE_collision_objects_create(depsgraph, NULL, surface->brush_group, &numobjects, eModifierType_DynamicPaint);
 
 		/* backup current scene frame */
 		int scene_frame = scene->r.cfra;
 		float scene_subframe = scene->r.subframe;
 
-		while (base) {
-			brushObj = NULL;
-			/* select object */
-			brushObj = base->object;
-
-			/* next item */
-			base = base->next;
-
-			if (!brushObj) {
-				/* skip item */
-				continue;
-			}
+		for (int i = 0; i < numobjects; i++) {
+			Object *brushObj = objects[i];
 
 			/* check if target has an active dp modifier	*/
-			md = modifiers_findByType(brushObj, eModifierType_DynamicPaint);
+			ModifierData *md = modifiers_findByType(brushObj, eModifierType_DynamicPaint);
 			if (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) {
 				DynamicPaintModifierData *pmd2 = (DynamicPaintModifierData *)md;
 				/* make sure we're dealing with a brush	*/
@@ -5995,6 +5976,8 @@ static int dynamicPaint_doStep(
 				}
 			}
 		}
+
+		BKE_collision_objects_free(objects);
 	}
 
 	/* surfaces operations that use adjacency data */
diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c
index a3a766b2d1d..bb4cf1c5753 100644
--- a/source/blender/blenkernel/intern/effect.c
+++ b/source/blender/blenkernel/intern/effect.c
@@ -228,7 +228,7 @@ ListBase *BKE_effector_relations_create(
         ViewLayer *view_layer,
         Collection *collection)
 {
-	Base *base = BKE_collection_or_layer_objects(NULL, NULL, view_layer, collection);
+	Base *base = BKE_collection_or_layer_objects(view_layer, collection);
 	const bool for_render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
 	const int base_flag = (for_render) ? BASE_ENABLED_RENDER : BASE_ENABLED_VIEWPORT;
 
diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c
index 7a8dbeed031..49280821667 100644
--- a/source/blender/blenkernel/intern/softbody.c
+++ b/source/blender/blenkernel/intern/softbody.c
@@ -72,6 +72,7 @@ variables on the UI for now
 #include "BLI_threads.h"
 
 #include "BKE_collection.h"
+#include "BKE_collision.h"
 #include "BKE_curve.h"
 #include "BKE_effect.h"
 #include "BKE_global.h"
@@ -521,20 +522,18 @@ static void ccd_build_deflector_hash(Depsgraph *depsgraph, Collection *collectio
 {
 	if (!hash) return;
 
-	/* Explicit collision collection. */
-	Base *base = BKE_collection_or_layer_objects(depsgraph, NULL, NULL, collection);
+	unsigned int numobjects;
+	Object **objects = BKE_collision_objects_create(depsgraph, vertexowner, collection, &numobjects, eModifierType_Collision);
 
-	for (; base; base = base->next) {
-		/* Only proceed for mesh object in same layer. */
-		if (base->object->type == OB_MESH) {
-			Object *ob = base->object;
-			if (ob == vertexowner) {
-				/* If vertexowner is given  we don't want to check collision with owner object. */
-				continue;
-			}
+	for (int i = 0; i < numobjects; i++) {
+		Object *ob = objects[i];
+
+		if (ob->type == OB_MESH) {
 			ccd_build_deflector_hash_single(hash, ob);
 		}
 	}
+
+	BKE_collision_objects_free(objects);
 }
 
 static void ccd_update_deflector_hash_single(GHash *hash, Object *ob)
@@ -554,23 +553,19 @@ static void ccd_update_deflector_hash(Depsgraph *depsgraph, Collection *collecti
 {
 	if ((!hash) || (!vertexowner)) return;
 
-	/* Explicit collision collection. */
-	Base *base = BKE_collection_or_layer_objects(depsgraph, NULL, NULL, collection);
+	unsigned int numobjects;
+	Object **objects = BKE_collision_objects_create(depsgraph, vertexowner, collection, &numobjects, eModifierType_Collision);
 
-	for (; base; base = base->next) {
-		/* Only proceed for mesh object in same layer. */
-		if (base->object->type == OB_MESH) {
-			Object *ob = base->object;
-			if (ob == vertexowner) {
-				/* If vertexowner is given  we don't want to check collision with owner object. */
-				continue;
-			}
+	for (int i = 0; i < numobjects; i++) {
+		Object *ob = objects[i];
 
+		if (ob->type == OB_MESH) {
 			ccd_update_deflector_hash_single(h

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list