diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2018-12-07 17:45:53 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2018-12-07 20:55:08 +0300 |
commit | de491abf996281785391b18b3547d1bff305355f (patch) | |
tree | 9f6f13c1a48658353f2c4a5ea4885f324daf1b95 /source/blender/blenkernel/intern | |
parent | 38ef3d6b91e128c93557991cb8cb9911c9b21f90 (diff) |
Fix modifiers evaluation outside of depsgraph/CoW context.
Fix T58237: Exporters: Curve Modifier not applied when "apply modifiers" are selected.
Fix T58856: Python: "to_mesh" broken in 2.8.
...And many other cases... ;)
Thing is, we need target IDs to always be evaluated ones (at least I
cannot see any case where having orig ones is desired effect here).
Depsgraph/Cow system ensures us that when modifiers are evaluated by it,
but they can also be called outside of this context, e.g. when doing
binding, or object conversion...
So we need to ensure in modifiers code that we actually are always
working with eval data for those targets.
Note that I did not touch to physics modifiers, those are a bit touchy
and rather not 'fix' something there until proven broken!
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/shrinkwrap.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c index 87193df3b49..ee35876f2a3 100644 --- a/source/blender/blenkernel/intern/shrinkwrap.c +++ b/source/blender/blenkernel/intern/shrinkwrap.c @@ -60,6 +60,8 @@ #include "BKE_subsurf.h" #include "BKE_mesh_runtime.h" +#include "DEG_depsgraph_query.h" + #include "MEM_guardedalloc.h" #include "BLI_strict_flags.h" @@ -91,8 +93,9 @@ typedef struct ShrinkwrapCalcData { struct SpaceTransform local2target; //transform to move between local and target space struct ShrinkwrapTreeData *tree; // mesh BVH tree data - float keepDist; //Distance to keep above target surface (units are in local space) + struct Object *aux_target; + float keepDist; //Distance to keep above target surface (units are in local space) } ShrinkwrapCalcData; typedef struct ShrinkwrapCalcCBData { @@ -658,11 +661,11 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc) } } - if (calc->smd->auxTarget) { - auxMesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(calc->smd->auxTarget, &auxMesh_free); + if (calc->aux_target) { + auxMesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(calc->aux_target, &auxMesh_free); if (!auxMesh) return; - BLI_SPACE_TRANSFORM_SETUP(&local2aux, calc->ob, calc->smd->auxTarget); + BLI_SPACE_TRANSFORM_SETUP(&local2aux, calc->ob, calc->aux_target); } if (BKE_shrinkwrap_init_tree(&aux_tree_stack, auxMesh, calc->smd->shrinkType, calc->smd->shrinkMode, false)) { @@ -1273,8 +1276,10 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) } /* Main shrinkwrap function */ -void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, struct Scene *scene, Object *ob, Mesh *mesh, - MDeformVert *dvert, const int defgrp_index, float (*vertexCos)[3], int numVerts) +void shrinkwrapModifier_deform( + ShrinkwrapModifierData *smd, const ModifierEvalContext *ctx, + struct Scene *scene, Object *ob, Mesh *mesh, + MDeformVert *dvert, const int defgrp_index, float (*vertexCos)[3], int numVerts) { DerivedMesh *ss_mesh = NULL; @@ -1295,17 +1300,19 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, struct Scene *scene, calc.vgroup = defgrp_index; calc.invert_vgroup = (smd->shrinkOpts & MOD_SHRINKWRAP_INVERT_VGROUP) != 0; - if (smd->target) { - calc.target = BKE_modifier_get_evaluated_mesh_from_evaluated_object(smd->target, &target_free); + if (smd->target != NULL) { + Object *ob_target = DEG_get_evaluated_object(ctx->depsgraph, smd->target); + calc.target = BKE_modifier_get_evaluated_mesh_from_evaluated_object(ob_target, &target_free); /* TODO there might be several "bugs" on non-uniform scales matrixs * because it will no longer be nearest surface, not sphere projection * because space has been deformed */ - BLI_SPACE_TRANSFORM_SETUP(&calc.local2target, ob, smd->target); + BLI_SPACE_TRANSFORM_SETUP(&calc.local2target, ob, ob_target); /* TODO: smd->keepDist is in global units.. must change to local */ calc.keepDist = smd->keepDist; } + calc.aux_target = DEG_get_evaluated_object(ctx->depsgraph, smd->auxTarget); if (mesh != NULL && smd->shrinkType == MOD_SHRINKWRAP_PROJECT) { /* Setup arrays to get vertexs positions, normals and deform weights */ |