Modifiers: Use object passed to evaluation

This was wrong and violating design to force modifiers to query
evaluated objects and IDs. It is up to the caller to make sure
the object is properly evaluatable.

Effectively, reverting changes from de491abf99 (and possibly
other related changes).
This commit is contained in:
Sergey Sharybin 2019-03-26 11:25:07 +01:00
parent a2a571987c
commit 64c8d72ef1
Notes: blender-bot 2023-02-14 09:19:09 +01:00
Referenced by commit 59f6371a85, Fix T63252: Bind in Mesh Deform Modifier fails
Referenced by issue #63252, Bind in Mesh Deform Modifier fails
23 changed files with 45 additions and 46 deletions

View File

@ -107,7 +107,7 @@ static void deformVerts(
MOD_previous_vcos_store(md, vertexCos); /* if next modifier needs original vertices */
armature_deform_verts(DEG_get_evaluated_object(ctx->depsgraph, amd->object), ctx->object, mesh, vertexCos, NULL,
armature_deform_verts(amd->object, ctx->object, mesh, vertexCos, NULL,
numVerts, amd->deformflag, (float(*)[3])amd->prevCos, amd->defgrp_name, NULL);
/* free cache */
@ -126,7 +126,7 @@ static void deformVertsEM(
MOD_previous_vcos_store(md, vertexCos); /* if next modifier needs original vertices */
armature_deform_verts(DEG_get_evaluated_object(ctx->depsgraph, amd->object), ctx->object, mesh_src, vertexCos, NULL,
armature_deform_verts(amd->object, ctx->object, mesh_src, vertexCos, NULL,
numVerts, amd->deformflag, (float(*)[3])amd->prevCos, amd->defgrp_name, NULL);
/* free cache */
@ -148,7 +148,7 @@ static void deformMatricesEM(
ArmatureModifierData *amd = (ArmatureModifierData *) md;
Mesh *mesh_src = MOD_deform_mesh_eval_get(ctx->object, em, mesh, NULL, numVerts, false, false);
armature_deform_verts(DEG_get_evaluated_object(ctx->depsgraph, amd->object), ctx->object, mesh_src, vertexCos, defMats,
armature_deform_verts(amd->object, ctx->object, mesh_src, vertexCos, defMats,
numVerts, amd->deformflag, NULL, amd->defgrp_name, NULL);
if (mesh_src != mesh) {
@ -163,7 +163,7 @@ static void deformMatrices(
ArmatureModifierData *amd = (ArmatureModifierData *) md;
Mesh *mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, NULL, numVerts, false, false);
armature_deform_verts(DEG_get_evaluated_object(ctx->depsgraph, amd->object), ctx->object, mesh_src, vertexCos, defMats,
armature_deform_verts(amd->object, ctx->object, mesh_src, vertexCos, defMats,
numVerts, amd->deformflag, NULL, amd->defgrp_name, NULL);
if (mesh_src != mesh) {

View File

@ -374,7 +374,7 @@ static Mesh *arrayModifier_doArray(
count = amd->count;
Object *start_cap_ob = DEG_get_evaluated_object(ctx->depsgraph, amd->start_cap);
Object *start_cap_ob = amd->start_cap;
if (start_cap_ob && start_cap_ob != ctx->object && start_cap_ob->type == OB_MESH) {
vgroup_start_cap_remap = BKE_object_defgroup_index_map_create(
start_cap_ob, ctx->object, &vgroup_start_cap_remap_len);
@ -387,7 +387,7 @@ static Mesh *arrayModifier_doArray(
start_cap_npolys = start_cap_mesh->totpoly;
}
}
Object *end_cap_ob = DEG_get_evaluated_object(ctx->depsgraph, amd->end_cap);
Object *end_cap_ob = amd->end_cap;
if (end_cap_ob && end_cap_ob != ctx->object && end_cap_ob->type == OB_MESH) {
vgroup_end_cap_remap = BKE_object_defgroup_index_map_create(
end_cap_ob, ctx->object, &vgroup_end_cap_remap_len);
@ -433,7 +433,7 @@ static Mesh *arrayModifier_doArray(
else
unit_m4(obinv);
mul_m4_series(result_mat, offset, obinv, DEG_get_evaluated_object(ctx->depsgraph, amd->offset_ob)->obmat);
mul_m4_series(result_mat, offset, obinv, amd->offset_ob->obmat);
copy_m4_m4(offset, result_mat);
}
@ -442,7 +442,7 @@ static Mesh *arrayModifier_doArray(
offset_has_scale = !is_one_v3(scale);
if (amd->fit_type == MOD_ARR_FITCURVE && amd->curve_ob != NULL) {
Object *curve_ob = DEG_get_evaluated_object(ctx->depsgraph, amd->curve_ob);
Object *curve_ob = amd->curve_ob;
Curve *cu = curve_ob->data;
if (cu) {
CurveCache *curve_cache = curve_ob->runtime.curve_cache;

View File

@ -163,7 +163,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
return result;
}
Object *other = DEG_get_evaluated_object(ctx->depsgraph, bmd->object);
Object *other = bmd->object;
mesh_other = BKE_modifier_get_evaluated_mesh_from_evaluated_object(other, false);
if (mesh_other) {
Object *object = ctx->object;

View File

@ -95,7 +95,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
}
static void sphere_do(
CastModifierData *cmd, const ModifierEvalContext *ctx,
CastModifierData *cmd, const ModifierEvalContext *UNUSED(ctx),
Object *ob, Mesh *mesh,
float (*vertexCos)[3], int numVerts)
{
@ -119,7 +119,7 @@ static void sphere_do(
if (type == MOD_CAST_TYPE_CYLINDER)
flag &= ~MOD_CAST_Z;
ctrl_ob = DEG_get_evaluated_object(ctx->depsgraph, cmd->object);
ctrl_ob = cmd->object;
/* spherify's center is {0, 0, 0} (the ob's own center in its local
* space), by default, but if the user defined a control object,
@ -217,7 +217,7 @@ static void sphere_do(
}
static void cuboid_do(
CastModifierData *cmd, const ModifierEvalContext *ctx,
CastModifierData *cmd, const ModifierEvalContext *UNUSED(ctx),
Object *ob, Mesh *mesh,
float (*vertexCos)[3], int numVerts)
{
@ -236,7 +236,7 @@ static void cuboid_do(
flag = cmd->flag;
ctrl_ob = DEG_get_evaluated_object(ctx->depsgraph, cmd->object);
ctrl_ob = cmd->object;
/* now we check which options the user wants */

View File

@ -115,7 +115,7 @@ static void deformVerts(
/* silly that defaxis and curve_deform_verts are off by 1
* but leave for now to save having to call do_versions */
curve_deform_verts(DEG_get_evaluated_object(ctx->depsgraph, cmd->object), ctx->object,
curve_deform_verts(cmd->object, ctx->object,
vertexCos, numVerts, dvert, defgrp_index, cmd->defaxis - 1);
if (!ELEM(mesh_src, NULL, mesh)) {

View File

@ -160,7 +160,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
/* Only used to check wehther we are operating on org data or not... */
Mesh *me = ctx->object->data;
Object *ob_source = DEG_get_evaluated_object(ctx->depsgraph, dtmd->ob_source);
Object *ob_source = dtmd->ob_source;
const bool invert_vgroup = (dtmd->flags & MOD_DATATRANSFER_INVERT_VGROUP) != 0;

View File

@ -290,7 +290,7 @@ static void displaceModifier_do(
mvert = mesh->mvert;
MOD_get_vgroup(ob, mesh, dmd->defgrp_name, &dvert, &defgrp_index);
Tex *tex_target = (Tex *)DEG_get_evaluated_id(ctx->depsgraph, &dmd->texture->id);
Tex *tex_target = dmd->texture;
if (tex_target != NULL) {
tex_co = MEM_calloc_arrayN((size_t)numVerts, sizeof(*tex_co),
"displaceModifier_do tex_co");

View File

@ -248,11 +248,11 @@ static void hook_co_apply(struct HookData_cb *hd, const int j)
}
static void deformVerts_do(
HookModifierData *hmd, const ModifierEvalContext *ctx,
HookModifierData *hmd, const ModifierEvalContext *UNUSED(ctx),
Object *ob, Mesh *mesh,
float (*vertexCos)[3], int numVerts)
{
Object *ob_target = DEG_get_evaluated_object(ctx->depsgraph, hmd->object);
Object *ob_target = hmd->object;
bPoseChannel *pchan = BKE_pose_channel_find_name(ob_target->pose, hmd->subtarget);
float dmat[4][4];
int i, *index_pt;

View File

@ -94,7 +94,7 @@ static void deformVerts(
MOD_previous_vcos_store(md, vertexCos); /* if next modifier needs original vertices */
lattice_deform_verts(DEG_get_evaluated_object(ctx->depsgraph, lmd->object), ctx->object, mesh_src,
lattice_deform_verts(lmd->object, ctx->object, mesh_src,
vertexCos, numVerts, lmd->name, lmd->strength);
if (!ELEM(mesh_src, NULL, mesh)) {

View File

@ -127,7 +127,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
/* if mode is to use selected armature bones, aggregate the bone groups */
if (mmd->mode == MOD_MASK_MODE_ARM) { /* --- using selected bones --- */
Object *oba = DEG_get_evaluated_object(ctx->depsgraph, mmd->ob_arm);
Object *oba = mmd->ob_arm;
bPoseChannel *pchan;
bDeformGroup *def;
bool *bone_select_array;

View File

@ -296,7 +296,7 @@ static void meshdeformModifier_do(
*
* We'll support this case once granular dependency graph is landed.
*/
Object *ob_target = DEG_get_evaluated_object(ctx->depsgraph, mmd->object);
Object *ob_target = mmd->object;
cagemesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(ob_target, false);
#if 0 /* This shall not be needed if we always get evaluated target object... */
if (cagemesh == NULL && mmd->bindcagecos == NULL && ob == DEG_get_original_object(ob)) {

View File

@ -130,7 +130,7 @@ static Mesh *doBiscetOnMirrorPlane(
static Mesh *doMirrorOnAxis(
MirrorModifierData *mmd,
const ModifierEvalContext *ctx,
const ModifierEvalContext *UNUSED(ctx),
Object *ob,
const Mesh *mesh,
int axis)
@ -159,7 +159,7 @@ static Mesh *doMirrorOnAxis(
unit_m4(mtx);
mtx[axis][axis] = -1.0f;
Object *mirror_ob = DEG_get_evaluated_object(ctx->depsgraph, mmd->mirror_ob);
Object *mirror_ob = mmd->mirror_ob;
if (mirror_ob != NULL) {
float tmp[4][4];
float itmp[4][4];

View File

@ -192,7 +192,7 @@ static bool polygons_check_flip(
}
static void normalEditModifier_do_radial(
NormalEditModifierData *enmd, const ModifierEvalContext *ctx,
NormalEditModifierData *enmd, const ModifierEvalContext *UNUSED(ctx),
Object *ob, Mesh *mesh,
short (*clnors)[2], float (*loopnors)[3], float (*polynors)[3],
const short mix_mode, const float mix_factor, const float mix_limit,
@ -200,7 +200,7 @@ static void normalEditModifier_do_radial(
MVert *mvert, const int num_verts, MEdge *medge, const int num_edges,
MLoop *mloop, const int num_loops, MPoly *mpoly, const int num_polys)
{
Object *ob_target = DEG_get_evaluated_object(ctx->depsgraph, enmd->target);
Object *ob_target = enmd->target;
const bool do_polynors_fix = (enmd->flag & MOD_NORMALEDIT_NO_POLYNORS_FIX) == 0;
int i;
@ -296,7 +296,7 @@ static void normalEditModifier_do_radial(
}
static void normalEditModifier_do_directional(
NormalEditModifierData *enmd, const ModifierEvalContext *ctx,
NormalEditModifierData *enmd, const ModifierEvalContext *UNUSED(ctx),
Object *ob, Mesh *mesh,
short (*clnors)[2], float (*loopnors)[3], float (*polynors)[3],
const short mix_mode, const float mix_factor, const float mix_limit,
@ -304,7 +304,7 @@ static void normalEditModifier_do_directional(
MVert *mvert, const int num_verts, MEdge *medge, const int num_edges,
MLoop *mloop, const int num_loops, MPoly *mpoly, const int num_polys)
{
Object *ob_target = DEG_get_evaluated_object(ctx->depsgraph, enmd->target);
Object *ob_target = enmd->target;
const bool do_polynors_fix = (enmd->flag & MOD_NORMALEDIT_NO_POLYNORS_FIX) == 0;
const bool use_parallel_normals = (enmd->flag & MOD_NORMALEDIT_USE_DIRECTION_PARALLEL) != 0;

View File

@ -236,7 +236,7 @@ static Mesh *applyModifier(
MEdge *medge_orig, *med_orig, *med_new, *med_new_firstloop, *medge_new;
MVert *mvert_new, *mvert_orig, *mv_orig, *mv_new, *mv_new_base;
Object *ob_axis = DEG_get_evaluated_object(ctx->depsgraph, ltmd->ob_axis);
Object *ob_axis = ltmd->ob_axis;
ScrewVertConnect *vc, *vc_tmp, *vert_connect = NULL;

View File

@ -178,7 +178,7 @@ static void simpleDeform_bend(const float factor, const int axis, const float dc
/* simple deform modifier */
static void SimpleDeformModifier_do(
SimpleDeformModifierData *smd, const ModifierEvalContext *ctx,
SimpleDeformModifierData *smd, const ModifierEvalContext *UNUSED(ctx),
struct Object *ob, struct Mesh *mesh,
float (*vertexCos)[3], int numVerts)
{
@ -222,7 +222,7 @@ static void SimpleDeformModifier_do(
/* Calculate matrixs do convert between coordinate spaces */
if (smd->origin != NULL) {
transf = &tmp_transf;
BLI_SPACE_TRANSFORM_SETUP(transf, ob, DEG_get_evaluated_object(ctx->depsgraph, smd->origin));
BLI_SPACE_TRANSFORM_SETUP(transf, ob, smd->origin);
}
/* Update limits if needed */

View File

@ -1124,7 +1124,7 @@ static void deformVert(
static void surfacedeformModifier_do(
ModifierData *md,
const ModifierEvalContext *ctx,
const ModifierEvalContext *UNUSED(ctx),
float (*vertexCos)[3], unsigned int numverts, Object *ob)
{
SurfaceDeformModifierData *smd = (SurfaceDeformModifierData *)md;
@ -1147,7 +1147,7 @@ static void surfacedeformModifier_do(
return;
}
Object *ob_target = DEG_get_evaluated_object(ctx->depsgraph, smd->target);
Object *ob_target = smd->target;
target = BKE_modifier_get_evaluated_mesh_from_evaluated_object(ob_target, false);
#if 0 /* Should not be needed anymore since we always get that mesh from eval object ? */
if (target == NULL && smd->verts == NULL && ob == DEG_get_original_object(ob)) {

View File

@ -59,7 +59,7 @@
void MOD_init_texture(MappingInfoModifierData *dmd, const ModifierEvalContext *ctx)
{
Tex *tex = (Tex *)DEG_get_evaluated_id(ctx->depsgraph, &dmd->texture->id);
Tex *tex = dmd->texture;
if (tex == NULL) {
return;
@ -74,7 +74,7 @@ void MOD_init_texture(MappingInfoModifierData *dmd, const ModifierEvalContext *c
/** \param cos: may be NULL, in which case we use directly mesh vertices' coordinates. */
void MOD_get_texture_coords(
MappingInfoModifierData *dmd,
const ModifierEvalContext *ctx,
const ModifierEvalContext *UNUSED(ctx),
Object *ob,
Mesh *mesh,
float (*cos)[3],
@ -87,7 +87,7 @@ void MOD_get_texture_coords(
if (texmapping == MOD_DISP_MAP_OBJECT) {
if (dmd->map_object != NULL) {
Object *map_object = DEG_get_evaluated_object(ctx->depsgraph, dmd->map_object);
Object *map_object = dmd->map_object;
invert_m4_m4(mapob_imat, map_object->obmat);
}
else {/* if there is no map object, default to local */

View File

@ -109,7 +109,7 @@ typedef struct Projector {
static Mesh *uvprojectModifier_do(
UVProjectModifierData *umd,
const ModifierEvalContext *ctx,
const ModifierEvalContext *UNUSED(ctx),
Object *ob, Mesh *mesh)
{
float (*coords)[3], (*co)[3];
@ -128,7 +128,7 @@ static Mesh *uvprojectModifier_do(
for (i = 0; i < umd->num_projectors; ++i) {
if (umd->projectors[i] != NULL) {
projectors[num_projectors++].ob = DEG_get_evaluated_object(ctx->depsgraph, umd->projectors[i]);
projectors[num_projectors++].ob = umd->projectors[i];
}
}

View File

@ -161,8 +161,8 @@ static Mesh *applyModifier(
}
/* make sure anything moving UVs is available */
matrix_from_obj_pchan(mat_src, DEG_get_evaluated_object(ctx->depsgraph, umd->object_src), umd->bone_src);
matrix_from_obj_pchan(mat_dst, DEG_get_evaluated_object(ctx->depsgraph, umd->object_dst), umd->bone_dst);
matrix_from_obj_pchan(mat_src, umd->object_src, umd->bone_src);
matrix_from_obj_pchan(mat_dst, umd->object_dst, umd->bone_dst);
invert_m4_m4(imat_dst, mat_dst);
mul_m4_m4m4(warp_mat, imat_dst, mat_src);

View File

@ -189,8 +189,8 @@ static void warpModifier_do(
invert_m4_m4(obinv, ob->obmat);
mul_m4_m4m4(mat_from, obinv, DEG_get_evaluated_object(ctx->depsgraph, wmd->object_from)->obmat);
mul_m4_m4m4(mat_to, obinv, DEG_get_evaluated_object(ctx->depsgraph, wmd->object_to)->obmat);
mul_m4_m4m4(mat_from, obinv, wmd->object_from->obmat);
mul_m4_m4m4(mat_to, obinv, wmd->object_to->obmat);
invert_m4_m4(tmat, mat_from); // swap?
mul_m4_m4m4(mat_final, tmat, mat_to);
@ -211,7 +211,7 @@ static void warpModifier_do(
}
weight = strength;
Tex *tex_target = (Tex *)DEG_get_evaluated_id(ctx->depsgraph, &wmd->texture->id);
Tex *tex_target = wmd->texture;
if (mesh != NULL && tex_target != NULL) {
tex_co = MEM_malloc_arrayN(numVerts, sizeof(*tex_co), "warpModifier_do tex_co");
MOD_get_texture_coords((MappingInfoModifierData *)wmd, ctx, ob, mesh, vertexCos, tex_co);

View File

@ -167,7 +167,7 @@ static void waveModifier_do(
float mat[4][4];
/* get the control object's location in local coordinates */
invert_m4_m4(ob->imat, ob->obmat);
mul_m4_m4m4(mat, ob->imat, DEG_get_evaluated_object(ctx->depsgraph, wmd->objectcenter)->obmat);
mul_m4_m4m4(mat, ob->imat, wmd->objectcenter->obmat);
wmd->startx = mat[3][0];
wmd->starty = mat[3][1];
@ -191,7 +191,7 @@ static void waveModifier_do(
}
}
Tex *tex_target = (Tex *)DEG_get_evaluated_id(ctx->depsgraph, &wmd->texture->id);
Tex *tex_target = wmd->texture;
if (mesh != NULL && tex_target != NULL) {
tex_co = MEM_malloc_arrayN(numVerts, sizeof(*tex_co), "waveModifier_do tex_co");
MOD_get_texture_coords((MappingInfoModifierData *)wmd, ctx, ob, mesh, vertexCos, tex_co);

View File

@ -127,7 +127,6 @@ void weightvg_do_mask(
/* If we want to mask vgroup weights from a texture. */
if (texture != NULL) {
texture = (Tex *)DEG_get_evaluated_id(ctx->depsgraph, &texture->id);
/* The texture coordinates. */
float (*tex_co)[3];
/* See mapping note below... */

View File

@ -398,7 +398,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
}
/* Get our target object. */
obr = DEG_get_evaluated_object(ctx->depsgraph, wmd->proximity_ob_target);
obr = wmd->proximity_ob_target;
if (obr == NULL) {
return mesh;
}