Commit: d7da51b7277252d887cd93b1ac26bfe4ee25ad44 Author: Kévin Dietrich Date: Sat Jan 9 04:37:53 2016 +0100 Branches: master https://developer.blender.org/rBd7da51b7277252d887cd93b1ac26bfe4ee25ad44
Smoke, Dynamic Paint: de-duplicate object subframe update function. As in the title. In the smoke version, there was also an extra 'for_render' parameter that wasn't used, and wasn't used by the callers either, so it was removed altogether. Reviewers: brecht Reviewed By: brecht Subscribers: brecht Differential Revision: https://developer.blender.org/D1718 =================================================================== M source/blender/blenkernel/BKE_object.h M source/blender/blenkernel/BKE_smoke.h M source/blender/blenkernel/intern/dynamicpaint.c M source/blender/blenkernel/intern/object.c M source/blender/blenkernel/intern/smoke.c M source/blender/modifiers/intern/MOD_smoke.c =================================================================== diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index af3185b..d6635f8 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -49,6 +49,8 @@ struct RigidBodyWorld; struct HookModifierData; struct ModifierData; +enum ModifierType; + void BKE_object_workob_clear(struct Object *workob); void BKE_object_workob_calc_parent(struct Scene *scene, struct Object *ob, struct Object *workob); @@ -266,6 +268,10 @@ struct KDTree *BKE_object_as_kdtree(struct Object *ob, int *r_tot); bool BKE_object_modifier_use_time(struct Object *ob, struct ModifierData *md); +bool BKE_object_modifier_update_subframe(struct Scene *scene, struct Object *ob, bool update_mesh, + int parent_recursion, float frame, + enum ModifierType type); + #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/BKE_smoke.h b/source/blender/blenkernel/BKE_smoke.h index 07d156c..20366f0 100644 --- a/source/blender/blenkernel/BKE_smoke.h +++ b/source/blender/blenkernel/BKE_smoke.h @@ -35,7 +35,7 @@ typedef float (*bresenham_callback)(float *result, float *input, int res[3], int *pixel, float *tRay, float correct); -struct DerivedMesh *smokeModifier_do(struct SmokeModifierData *smd, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm, bool for_render); +struct DerivedMesh *smokeModifier_do(struct SmokeModifierData *smd, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm); void smoke_reallocate_fluid(struct SmokeDomainSettings *sds, float dx, int res[3], int free_old); void smoke_reallocate_highres_fluid(struct SmokeDomainSettings *sds, float dx, int res[3], int free_old); diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 0a9a7a3..67a6d06 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -103,8 +103,6 @@ static int neighY[8] = {0, 1, 1, 1, 0, -1, -1, -1}; /* subframe_updateObject() flags */ #define SUBFRAME_RECURSION 5 -#define UPDATE_MESH (1 << 1) -#define UPDATE_EVERYTHING (UPDATE_MESH) // | UPDATE_PARENTS /* surface_getBrushFlags() return vals */ #define BRUSH_USES_VELOCITY (1 << 0) /* brush mesh raycast status */ @@ -484,93 +482,6 @@ static float mixColors(float a_color[3], float a_weight, const float b_color[3], return (1.0f - factor) * a_weight + factor * b_weight; } -/* set "ignore cache" flag for all caches on this object */ -static void object_cacheIgnoreClear(Object *ob, int state) -{ - ListBase pidlist; - PTCacheID *pid; - BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0); - - for (pid = pidlist.first; pid; pid = pid->next) { - if (pid->cache) { - if (state) - pid->cache->flag |= PTCACHE_IGNORE_CLEAR; - else - pid->cache->flag &= ~PTCACHE_IGNORE_CLEAR; - } - } - - BLI_freelistN(&pidlist); -} - -static int subframe_updateObject(Scene *scene, Object *ob, int flags, int parent_recursion, float frame) -{ - DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)modifiers_findByType(ob, eModifierType_DynamicPaint); - bConstraint *con; - - /* if other is dynamic paint canvas, don't update */ - if (pmd && pmd->canvas) - return 1; - - /* if object has parents, update them too */ - if (parent_recursion) { - int recursion = parent_recursion - 1; - int is_canvas = 0; - if (ob->parent) is_canvas += subframe_updateObject(scene, ob->parent, 0, recursion, frame); - if (ob->track) is_canvas += subframe_updateObject(scene, ob->track, 0, recursion, frame); - - /* skip subframe if object is parented - * to vertex of a dynamic paint canvas */ - if (is_canvas && (ob->partype == PARVERT1 || ob->partype == PARVERT3)) - return 0; - - /* also update constraint targets */ - for (con = ob->constraints.first; con; con = con->next) { - const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); - ListBase targets = {NULL, NULL}; - - if (cti && cti->get_constraint_targets) { - bConstraintTarget *ct; - cti->get_constraint_targets(con, &targets); - for (ct = targets.first; ct; ct = ct->next) { - if (ct->tar) - subframe_updateObject(scene, ct->tar, 0, recursion, frame); - } - /* free temp targets */ - if (cti->flush_constraint_targets) - cti->flush_constraint_targets(con, &targets, 0); - } - } - } - - /* was originally OB_RECALC_ALL - TODO - which flags are really needed??? */ - ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME; - BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, frame, ADT_RECALC_ANIM); - if (flags & UPDATE_MESH) { - /* ignore cache clear during subframe updates - * to not mess up cache validity */ - object_cacheIgnoreClear(ob, 1); - BKE_object_handle_update(G.main->eval_ctx, scene, ob); - object_cacheIgnoreClear(ob, 0); - } - else - BKE_object_where_is_calc_time(scene, ob, frame); - - /* for curve following objects, parented curve has to be updated too */ - if (ob->type == OB_CURVE) { - Curve *cu = ob->data; - BKE_animsys_evaluate_animdata(scene, &cu->id, cu->adt, frame, ADT_RECALC_ANIM); - } - /* and armatures... */ - if (ob->type == OB_ARMATURE) { - bArmature *arm = ob->data; - BKE_animsys_evaluate_animdata(scene, &arm->id, arm->adt, frame, ADT_RECALC_ANIM); - BKE_pose_where_is(scene, ob); - } - - return 0; -} - static void scene_setSubframe(Scene *scene, float subframe) { /* dynamic paint subframes must be done on previous frame */ @@ -3156,7 +3067,7 @@ static void dynamicPaint_brushMeshCalculateVelocity(Scene *scene, Object *ob, Dy scene->r.cfra = prev_fra; scene->r.subframe = prev_sfra; - subframe_updateObject(scene, ob, UPDATE_EVERYTHING, SUBFRAME_RECURSION, BKE_scene_frame_get(scene)); + BKE_object_modifier_update_subframe(scene, ob, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); dm_p = CDDM_copy(brush->dm); numOfVerts_p = dm_p->getNumVerts(dm_p); mvert_p = dm_p->getVertArray(dm_p); @@ -3166,7 +3077,7 @@ static void dynamicPaint_brushMeshCalculateVelocity(Scene *scene, Object *ob, Dy scene->r.cfra = cur_fra; scene->r.subframe = cur_sfra; - subframe_updateObject(scene, ob, UPDATE_EVERYTHING, SUBFRAME_RECURSION, BKE_scene_frame_get(scene)); + BKE_object_modifier_update_subframe(scene, ob, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); dm_c = brush->dm; numOfVerts_c = dm_c->getNumVerts(dm_c); mvert_c = dm_p->getVertArray(dm_c); @@ -3216,13 +3127,13 @@ static void dynamicPaint_brushObjectCalculateVelocity(Scene *scene, Object *ob, /* previous frame dm */ scene->r.cfra = prev_fra; scene->r.subframe = prev_sfra; - subframe_updateObject(scene, ob, 0, SUBFRAME_RECURSION, BKE_scene_frame_get(scene)); + BKE_object_modifier_update_subframe(scene, ob, false, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); copy_m4_m4(prev_obmat, ob->obmat); /* current frame dm */ scene->r.cfra = cur_fra; scene->r.subframe = cur_sfra; - subframe_updateObject(scene, ob, 0, SUBFRAME_RECURSION, BKE_scene_frame_get(scene)); + BKE_object_modifier_update_subframe(scene, ob, false, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); /* calculate speed */ mul_m4_v3(prev_obmat, prev_loc); @@ -4947,7 +4858,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su /* update object data on this subframe */ if (subframe) { scene_setSubframe(scene, subframe); - subframe_updateObject(scene, brushObj, UPDATE_EVERYTHING, SUBFRAME_RECURSION, BKE_scene_frame_get(scene)); + BKE_object_modifier_update_subframe(scene, brushObj, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); } /* Prepare materials if required */ if (brush_usesMaterial(brush, scene)) @@ -4981,7 +4892,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su if (subframe) { scene->r.cfra = scene_frame; scene->r.subframe = scene_subframe; - subframe_updateObject(scene, brushObj, UPDATE_EVERYTHING, SUBFRAME_RECURSION, BKE_scene_frame_get(scene)); + BKE_object_modifier_update_subframe(scene, brushObj, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); } /* process special brush effects, like smudge */ diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index b448bec..ba7daee 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -4099,3 +4099,105 @@ bool BKE_object_modifier_use_time(Object *ob, ModifierData *md) return false; } + +/* set "ignore cache" flag for all caches on this object */ +static void object_cacheIgnoreClear(Object *ob, int state) +{ + ListBase pidlist; + PTCacheID *pid; + BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0); + + for (pid = pidlist.first; pid; pid = pid->next) { + if (pid->cache) { + if (state) + pid->cache->flag |= PTCACHE_IGNORE_CLEAR; + else + pid->cache->flag &= ~PTCACHE_IGNORE_CLEAR; + } + } + + BLI_freelistN(&pidlist); +} + +/* Note: this function should eventually be replaced by depsgraph functionality. + * Avoid calling this in new code unless there is a very good reason for it! + */ +bool BKE_object_modifier_update_subframe(Scene *scene, Object *ob, bool update_mesh, + int parent_recursion, float frame, + ModifierType type) +{ + ModifierData *md = modifiers_findByType(ob, type); + bConstraint *con; + + if (type == eModifierType_DynamicPaint) { + DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md; + + /* if other is dynamic paint canvas, don't update */ + if (pmd && pmd->canvas) + return true; + } + else if (type == eModifierType_Smoke) { + SmokeModifierData *smd = (SmokeModifierData *)md; + + if (smd && (smd->type & MOD_SMOKE_TYPE_DOMAIN) != 0) + return true; + } + + /* if object has parents, update them too */ + if (parent_recursion) { + int recursion = parent_recursion - @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list [email protected] http://lists.blender.org/mailman/listinfo/bf-blender-cvs
