diff options
author | Antonio Vazquez <blendergit@gmail.com> | 2022-03-14 18:10:03 +0300 |
---|---|---|
committer | Antonio Vazquez <blendergit@gmail.com> | 2022-03-14 18:13:59 +0300 |
commit | cff6eb65804da3a06bde3c9152bec26e01a24992 (patch) | |
tree | b3d49cf7281568000695116fe990828660ed48c0 /source | |
parent | 8c4ddd5dde3a5f5ae0375c71e379e0fac287e3e6 (diff) |
Cleanup: Remove duplicate Bake modifier code
This patch remove all duplicate code for the same Bake modifier logic.
Still some modifiers need custom bake functions and cannot use this generic bake.
Diffstat (limited to 'source')
17 files changed, 64 insertions, 175 deletions
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c b/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c index 88ba6b6285d..e766615101a 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c @@ -7,19 +7,21 @@ #include <stdio.h> -#include "BLI_utildefines.h" - +#include "BLI_blenlib.h" #include "BLI_math_vector.h" +#include "BLI_utildefines.h" #include "DNA_gpencil_modifier_types.h" #include "DNA_gpencil_types.h" #include "DNA_material_types.h" #include "DNA_meshdata_types.h" #include "DNA_object_types.h" +#include "DNA_scene_types.h" #include "BKE_deform.h" #include "BKE_gpencil_modifier.h" #include "BKE_material.h" +#include "BKE_scene.h" #include "MOD_gpencil_modifiertypes.h" #include "MOD_gpencil_util.h" @@ -168,3 +170,29 @@ float get_modifier_point_weight(MDeformVert *dvert, bool inverse, int def_nr) return weight; } + +void generic_bake_deform_stroke( + Depsgraph *depsgraph, GpencilModifierData *md, Object *ob, const bool retime, gpBakeCb bake_cb) +{ + Scene *scene = DEG_get_evaluated_scene(depsgraph); + bGPdata *gpd = ob->data; + int oldframe = (int)DEG_get_ctime(depsgraph); + + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { + if (retime) { + CFRA = gpf->framenum; + BKE_scene_graph_update_for_newframe(depsgraph); + } + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { + bake_cb(md, depsgraph, ob, gpl, gpf, gps); + } + } + } + + /* Return frame state and DB to original state. */ + if (retime) { + CFRA = oldframe; + BKE_scene_graph_update_for_newframe(depsgraph); + } +} diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.h b/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.h index ce77ded421a..e7301b4d910 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.h +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.h @@ -7,10 +7,13 @@ #pragma once +struct Depsgraph; +struct GpencilModifierData; struct MDeformVert; struct Material; struct Object; struct bGPDlayer; +struct bGPDframe; struct bGPDstroke; /** @@ -33,3 +36,18 @@ bool is_stroke_affected_by_modifier(struct Object *ob, * Verify if valid vertex group *and return weight. */ float get_modifier_point_weight(struct MDeformVert *dvert, bool inverse, int def_nr); +/** + * Generic bake function for deformStroke. + */ +typedef void (*gpBakeCb)(struct GpencilModifierData *md_, + struct Depsgraph *depsgraph_, + struct Object *ob_, + struct bGPDlayer *gpl_, + struct bGPDframe *gpf_, + struct bGPDstroke *gps_); + +void generic_bake_deform_stroke(struct Depsgraph *depsgraph, + struct GpencilModifierData *md, + struct Object *ob, + const bool retime, + gpBakeCb bake_cb); diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilarmature.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilarmature.c index 4ef48680029..f5ecce69129 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencilarmature.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilarmature.c @@ -42,6 +42,7 @@ #include "MOD_gpencil_modifiertypes.h" #include "MOD_gpencil_ui_common.h" +#include "MOD_gpencil_util.h" #include "DEG_depsgraph.h" #include "DEG_depsgraph_build.h" @@ -118,35 +119,14 @@ static void bakeModifier(Main *UNUSED(bmain), GpencilModifierData *md, Object *ob) { - Scene *scene = DEG_get_evaluated_scene(depsgraph); Object *object_eval = DEG_get_evaluated_object(depsgraph, ob); ArmatureGpencilModifierData *mmd = (ArmatureGpencilModifierData *)md; GpencilModifierData *md_eval = BKE_gpencil_modifiers_findby_name(object_eval, md->name); - bGPdata *gpd = (bGPdata *)ob->data; - int oldframe = (int)DEG_get_ctime(depsgraph); if (mmd->object == NULL) { return; } - - LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { - LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { - /* apply armature effects on this frame - * NOTE: this assumes that we don't want armature animation on non-keyframed frames - */ - CFRA = gpf->framenum; - BKE_scene_graph_update_for_newframe(depsgraph); - - /* compute armature effects on this frame */ - LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { - deformStroke(md_eval, depsgraph, object_eval, gpl, gpf, gps); - } - } - } - - /* return frame state and DB to original state */ - CFRA = oldframe; - BKE_scene_graph_update_for_newframe(depsgraph); + generic_bake_deform_stroke(depsgraph, md_eval, object_eval, true, deformStroke); } static bool isDisabled(GpencilModifierData *md, int UNUSED(userRenderParams)) diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilcolor.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilcolor.c index 5906b4aa094..792def30812 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencilcolor.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilcolor.c @@ -148,15 +148,7 @@ static void bakeModifier(Main *UNUSED(bmain), GpencilModifierData *md, Object *ob) { - bGPdata *gpd = ob->data; - - LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { - LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { - LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { - deformStroke(md, depsgraph, ob, gpl, gpf, gps); - } - } - } + generic_bake_deform_stroke(depsgraph, md, ob, false, deformStroke); } static void freeData(GpencilModifierData *md) diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilhook.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilhook.c index deac2b17498..bc0464cb4f9 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencilhook.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilhook.c @@ -267,32 +267,12 @@ static void bakeModifier(Main *UNUSED(bmain), Object *ob) { HookGpencilModifierData *mmd = (HookGpencilModifierData *)md; - Scene *scene = DEG_get_evaluated_scene(depsgraph); - bGPdata *gpd = ob->data; - int oldframe = (int)DEG_get_ctime(depsgraph); if (mmd->object == NULL) { return; } - LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { - LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { - /* apply hook effects on this frame - * NOTE: this assumes that we don't want hook animation on non-keyframed frames - */ - CFRA = gpf->framenum; - BKE_scene_graph_update_for_newframe(depsgraph); - - /* compute hook effects on this frame */ - LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { - deformStroke(md, depsgraph, ob, gpl, gpf, gps); - } - } - } - - /* return frame state and DB to original state */ - CFRA = oldframe; - BKE_scene_graph_update_for_newframe(depsgraph); + generic_bake_deform_stroke(depsgraph, md, ob, true, deformStroke); } static void freeData(GpencilModifierData *md) diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencillength.c b/source/blender/gpencil_modifiers/intern/MOD_gpencillength.c index 2d139645911..c92c062348c 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencillength.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencillength.c @@ -239,16 +239,7 @@ static void bakeModifier(Main *UNUSED(bmain), GpencilModifierData *md, Object *ob) { - - bGPdata *gpd = ob->data; - - LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { - LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { - LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { - deformStroke(md, depsgraph, ob, gpl, gpf, gps); - } - } - } + generic_bake_deform_stroke(depsgraph, md, ob, false, deformStroke); } static void foreachIDLink(GpencilModifierData *md, Object *ob, IDWalkFunc walk, void *userData) diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilnoise.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilnoise.c index 179dcccdbe4..fcf1e28c6da 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencilnoise.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilnoise.c @@ -252,15 +252,7 @@ static void bakeModifier(struct Main *UNUSED(bmain), GpencilModifierData *md, Object *ob) { - bGPdata *gpd = ob->data; - - LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { - LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { - LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { - deformStroke(md, depsgraph, ob, gpl, gpf, gps); - } - } - } + generic_bake_deform_stroke(depsgraph, md, ob, false, deformStroke); } static void foreachIDLink(GpencilModifierData *md, Object *ob, IDWalkFunc walk, void *userData) diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpenciloffset.c b/source/blender/gpencil_modifiers/intern/MOD_gpenciloffset.c index 95c3f2c161f..4fe92ab925d 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpenciloffset.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpenciloffset.c @@ -166,15 +166,7 @@ static void bakeModifier(struct Main *UNUSED(bmain), GpencilModifierData *md, Object *ob) { - bGPdata *gpd = ob->data; - - LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { - LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { - LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { - deformStroke(md, depsgraph, ob, gpl, gpf, gps); - } - } - } + generic_bake_deform_stroke(depsgraph, md, ob, false, deformStroke); } static void foreachIDLink(GpencilModifierData *md, Object *ob, IDWalkFunc walk, void *userData) diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c index dc41679cfc7..b964b143a0f 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c @@ -181,15 +181,7 @@ static void bakeModifier(Main *UNUSED(bmain), GpencilModifierData *md, Object *ob) { - bGPdata *gpd = ob->data; - - LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { - LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { - LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { - deformStroke(md, depsgraph, ob, gpl, gpf, gps); - } - } - } + generic_bake_deform_stroke(depsgraph, md, ob, false, deformStroke); } static void freeData(GpencilModifierData *md) diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilsimplify.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilsimplify.c index f94b5d05291..e7dfdfee8d2 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencilsimplify.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilsimplify.c @@ -105,15 +105,7 @@ static void bakeModifier(struct Main *UNUSED(bmain), GpencilModifierData *md, Object *ob) { - bGPdata *gpd = ob->data; - - LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { - LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { - LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { - deformStroke(md, depsgraph, ob, gpl, gpf, gps); - } - } - } + generic_bake_deform_stroke(depsgraph, md, ob, false, deformStroke); } static void foreachIDLink(GpencilModifierData *md, Object *ob, IDWalkFunc walk, void *userData) diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilsmooth.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilsmooth.c index 274c19a6d95..f8201eb6b4f 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencilsmooth.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilsmooth.c @@ -140,15 +140,7 @@ static void bakeModifier(struct Main *UNUSED(bmain), GpencilModifierData *md, Object *ob) { - bGPdata *gpd = ob->data; - - LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { - LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { - LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { - deformStroke(md, depsgraph, ob, gpl, gpf, gps); - } - } - } + generic_bake_deform_stroke(depsgraph, md, ob, false, deformStroke); } static void freeData(GpencilModifierData *md) diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilsubdiv.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilsubdiv.c index dcec2865f29..73f8dada971 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencilsubdiv.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilsubdiv.c @@ -86,15 +86,7 @@ static void bakeModifier(struct Main *UNUSED(bmain), GpencilModifierData *md, Object *ob) { - bGPdata *gpd = ob->data; - - LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { - LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { - LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { - deformStroke(md, depsgraph, ob, gpl, gpf, gps); - } - } - } + generic_bake_deform_stroke(depsgraph, md, ob, false, deformStroke); } static void foreachIDLink(GpencilModifierData *md, Object *ob, IDWalkFunc walk, void *userData) diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpenciltexture.c b/source/blender/gpencil_modifiers/intern/MOD_gpenciltexture.c index a70bfadba14..5c8c65b9f97 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpenciltexture.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpenciltexture.c @@ -119,15 +119,7 @@ static void bakeModifier(struct Main *UNUSED(bmain), GpencilModifierData *md, Object *ob) { - bGPdata *gpd = ob->data; - - LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { - LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { - LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { - deformStroke(md, depsgraph, ob, gpl, gpf, gps); - } - } - } + generic_bake_deform_stroke(depsgraph, md, ob, false, deformStroke); } static void foreachIDLink(GpencilModifierData *md, Object *ob, IDWalkFunc walk, void *userData) diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c index 283d3f8a894..3ddb508d58a 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c @@ -149,15 +149,7 @@ static void bakeModifier(struct Main *UNUSED(bmain), GpencilModifierData *md, Object *ob) { - bGPdata *gpd = ob->data; - - LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { - LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { - LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { - deformStroke(md, depsgraph, ob, gpl, gpf, gps); - } - } - } + generic_bake_deform_stroke(depsgraph, md, ob, false, deformStroke); } static void foreachIDLink(GpencilModifierData *md, Object *ob, IDWalkFunc walk, void *userData) diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpenciltint.c b/source/blender/gpencil_modifiers/intern/MOD_gpenciltint.c index c594b042643..8fa14496616 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpenciltint.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpenciltint.c @@ -261,32 +261,12 @@ static void bakeModifier(Main *UNUSED(bmain), Object *ob) { TintGpencilModifierData *mmd = (TintGpencilModifierData *)md; - Scene *scene = DEG_get_evaluated_scene(depsgraph); - bGPdata *gpd = ob->data; - int oldframe = (int)DEG_get_ctime(depsgraph); if ((mmd->type == GP_TINT_GRADIENT) && (mmd->object == NULL)) { return; } - LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { - LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { - /* apply effects on this frame - * NOTE: this assumes that we don't want animation on non-keyframed frames - */ - CFRA = gpf->framenum; - BKE_scene_graph_update_for_newframe(depsgraph); - - /* compute effects on this frame */ - LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { - deformStroke(md, depsgraph, ob, gpl, gpf, gps); - } - } - } - - /* return frame state and DB to original state */ - CFRA = oldframe; - BKE_scene_graph_update_for_newframe(depsgraph); + generic_bake_deform_stroke(depsgraph, md, ob, true, deformStroke); } static void freeData(GpencilModifierData *md) diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilweight_angle.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilweight_angle.c index fe35c7036a9..e90408b1a94 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencilweight_angle.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilweight_angle.c @@ -152,15 +152,7 @@ static void bakeModifier(struct Main *UNUSED(bmain), GpencilModifierData *md, Object *ob) { - bGPdata *gpd = ob->data; - - LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { - LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { - LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { - deformStroke(md, depsgraph, ob, gpl, gpf, gps); - } - } - } + generic_bake_deform_stroke(depsgraph, md, ob, false, deformStroke); } static void foreachIDLink(GpencilModifierData *md, Object *ob, IDWalkFunc walk, void *userData) diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilweight_proximity.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilweight_proximity.c index 1fd48b536be..d2c31591a98 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencilweight_proximity.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilweight_proximity.c @@ -152,15 +152,7 @@ static void bakeModifier(struct Main *UNUSED(bmain), GpencilModifierData *md, Object *ob) { - bGPdata *gpd = ob->data; - - LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { - LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { - LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { - deformStroke(md, depsgraph, ob, gpl, gpf, gps); - } - } - } + generic_bake_deform_stroke(depsgraph, md, ob, false, deformStroke); } static void foreachIDLink(GpencilModifierData *md, Object *ob, IDWalkFunc walk, void *userData) |