Fix depsgraph to compute more accurate links for collision & force.
[blender.git] / source / blender / modifiers / intern / MOD_dynamicpaint.c
index edf959f42c6dfbd1f10575321d0eef6ac5346195..bde20e56748e3ee3f93dc403743bda5a4362cec6 100644 (file)
@@ -114,6 +114,11 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
        return dm;
 }
 
+static bool is_brush_cb(Object *UNUSED(ob), ModifierData *pmd)
+{
+       return ((DynamicPaintModifierData*)pmd)->brush != NULL;
+}
+
 static void updateDepgraph(ModifierData *md, DagForest *forest,
                            struct Main *UNUSED(bmain),
                            struct Scene *scene,
@@ -124,16 +129,13 @@ static void updateDepgraph(ModifierData *md, DagForest *forest,
 
        /* add relation from canvases to all brush objects */
        if (pmd && pmd->canvas) {
-               Base *base = scene->base.first;
-
-               for (; base; base = base->next) {
-                       DynamicPaintModifierData *pmd2 =
-                               (DynamicPaintModifierData *)modifiers_findByType(base->object, eModifierType_DynamicPaint);
-
-                       if (pmd2 && pmd2->brush && ob != base->object) {
-                               DagNode *brushNode = dag_get_node(forest, base->object);
-                               dag_add_relation(forest, brushNode, obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Dynamic Paint Brush");
+               for (DynamicPaintSurface *surface = pmd->canvas->surfaces.first; surface; surface = surface->next) {
+                       if (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP) {
+                               dag_add_forcefield_relations(forest, scene, ob, obNode, surface->effector_weights, true, 0, "Dynamic Paint Field");
                        }
+
+                       /* Actual code uses custom loop over group/scene without layer checks in dynamicPaint_doStep */
+                       dag_add_collision_relations(forest, scene, ob, obNode, surface->brush_group, -1, eModifierType_DynamicPaint, is_brush_cb, false, "Dynamic Paint Brush");
                }
        }
 }
@@ -147,13 +149,13 @@ static void updateDepsgraph(ModifierData *md,
        DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md;
        /* Add relation from canvases to all brush objects. */
        if (pmd->canvas != NULL) {
-               Base *base = scene->base.first;
-               for (; base; base = base->next) {
-                       DynamicPaintModifierData *pmd2 =
-                               (DynamicPaintModifierData *)modifiers_findByType(base->object, eModifierType_DynamicPaint);
-                       if (pmd2 && pmd2->brush && ob != base->object) {
-                               DEG_add_object_relation(node, base->object, DEG_OB_COMP_TRANSFORM, "Dynamic Paint Brush");
+               for (DynamicPaintSurface *surface = pmd->canvas->surfaces.first; surface; surface = surface->next) {
+                       if (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP) {
+                               DEG_add_forcefield_relations(node, scene, ob, surface->effector_weights, true, 0, "Dynamic Paint Field");
                        }
+
+                       /* Actual code uses custom loop over group/scene without layer checks in dynamicPaint_doStep */
+                       DEG_add_collision_relations(node, scene, ob, surface->brush_group, -1, eModifierType_DynamicPaint, is_brush_cb, false, "Dynamic Paint Brush");
                }
        }
 }