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!
This commit is contained in:
Bastien Montagne 2018-12-07 15:45:53 +01:00
parent 38ef3d6b91
commit de491abf99
Notes: blender-bot 2023-02-14 19:24:20 +01:00
Referenced by commit 64c8d72ef1, Modifiers: Use object passed to evaluation
Referenced by issue #59162, to_mesh(..., True, calc_undeformed=True) calculates deformed anyway since de491ab
Referenced by issue #58237, Exporters: Curve Modifier not applied when "apply modifiers" are selected
Referenced by issue blender/blender-addons#58856, Python: "to_mesh" broken in 2.8
27 changed files with 210 additions and 140 deletions

View File

@ -105,7 +105,8 @@ void BKE_shrinkwrap_free_tree(struct ShrinkwrapTreeData *data);
/* Implementation of the Shrinkwrap modifier */
void shrinkwrapModifier_deform(
struct ShrinkwrapModifierData *smd, struct Scene *scene, struct Object *ob, struct Mesh *mesh,
struct ShrinkwrapModifierData *smd, const struct ModifierEvalContext *ctx,
struct Scene *scene, struct Object *ob, struct Mesh *mesh,
struct MDeformVert *dvert, const int defgrp_index, float (*vertexCos)[3], int numVerts);
/*

View File

@ -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 */

View File

@ -49,6 +49,8 @@
#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "DEG_depsgraph_query.h"
#include "bmesh.h"
#include "bmesh_tools.h"
@ -121,7 +123,7 @@ static void deformVerts(
MOD_previous_vcos_store(md, vertexCos); /* if next modifier needs original vertices */
armature_deform_verts(amd->object, ctx->object, mesh, vertexCos, NULL,
armature_deform_verts(DEG_get_evaluated_object(ctx->depsgraph, amd->object), ctx->object, mesh, vertexCos, NULL,
numVerts, amd->deformflag, (float(*)[3])amd->prevCos, amd->defgrp_name, NULL);
/* free cache */
@ -140,7 +142,7 @@ static void deformVertsEM(
MOD_previous_vcos_store(md, vertexCos); /* if next modifier needs original vertices */
armature_deform_verts(amd->object, ctx->object, mesh_src, vertexCos, NULL,
armature_deform_verts(DEG_get_evaluated_object(ctx->depsgraph, amd->object), ctx->object, mesh_src, vertexCos, NULL,
numVerts, amd->deformflag, (float(*)[3])amd->prevCos, amd->defgrp_name, NULL);
/* free cache */
@ -162,8 +164,8 @@ 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(amd->object, ctx->object, mesh_src, vertexCos, defMats, numVerts,
amd->deformflag, NULL, amd->defgrp_name, NULL);
armature_deform_verts(DEG_get_evaluated_object(ctx->depsgraph, amd->object), ctx->object, mesh_src, vertexCos, defMats,
numVerts, amd->deformflag, NULL, amd->defgrp_name, NULL);
if (mesh_src != mesh) {
BKE_id_free(NULL, mesh_src);
@ -177,8 +179,8 @@ 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(amd->object, ctx->object, mesh_src, vertexCos, defMats, numVerts,
amd->deformflag, NULL, amd->defgrp_name, NULL);
armature_deform_verts(DEG_get_evaluated_object(ctx->depsgraph, amd->object), ctx->object, mesh_src, vertexCos, defMats,
numVerts, amd->deformflag, NULL, amd->defgrp_name, NULL);
if (mesh_src != mesh) {
BKE_id_free(NULL, mesh_src);

View File

@ -57,6 +57,7 @@
#include "MOD_util.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"
static void initData(ModifierData *md)
{
@ -364,7 +365,7 @@ static Mesh *arrayModifier_doArray(
const bool use_merge = (amd->flags & MOD_ARR_MERGE) != 0;
const bool use_recalc_normals = (mesh->runtime.cd_dirty_vert & CD_MASK_NORMAL) || use_merge;
const bool use_offset_ob = ((amd->offset_type & MOD_ARR_OFF_OBJ) && amd->offset_ob);
const bool use_offset_ob = ((amd->offset_type & MOD_ARR_OFF_OBJ) && amd->offset_ob != NULL);
int start_cap_nverts = 0, start_cap_nedges = 0, start_cap_npolys = 0, start_cap_nloops = 0;
int end_cap_nverts = 0, end_cap_nedges = 0, end_cap_npolys = 0, end_cap_nloops = 0;
@ -387,11 +388,12 @@ static Mesh *arrayModifier_doArray(
count = amd->count;
if (amd->start_cap && amd->start_cap != ctx->object && amd->start_cap->type == OB_MESH) {
Object *start_cap_ob = DEG_get_evaluated_object(ctx->depsgraph, 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(
amd->start_cap, ctx->object, &vgroup_start_cap_remap_len);
start_cap_ob, ctx->object, &vgroup_start_cap_remap_len);
start_cap_mesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(amd->start_cap, &start_cap_mesh_free);
start_cap_mesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(start_cap_ob, &start_cap_mesh_free);
if (start_cap_mesh) {
start_cap_nverts = start_cap_mesh->totvert;
start_cap_nedges = start_cap_mesh->totedge;
@ -399,11 +401,12 @@ static Mesh *arrayModifier_doArray(
start_cap_npolys = start_cap_mesh->totpoly;
}
}
if (amd->end_cap && amd->end_cap != ctx->object && amd->end_cap->type == OB_MESH) {
Object *end_cap_ob = DEG_get_evaluated_object(ctx->depsgraph, 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(
amd->end_cap, ctx->object, &vgroup_end_cap_remap_len);
end_cap_ob, ctx->object, &vgroup_end_cap_remap_len);
end_cap_mesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(amd->end_cap, &end_cap_mesh_free);
end_cap_mesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(end_cap_ob, &end_cap_mesh_free);
if (end_cap_mesh) {
end_cap_nverts = end_cap_mesh->totvert;
end_cap_nedges = end_cap_mesh->totedge;
@ -444,8 +447,7 @@ static Mesh *arrayModifier_doArray(
else
unit_m4(obinv);
mul_m4_series(result_mat, offset,
obinv, amd->offset_ob->obmat);
mul_m4_series(result_mat, offset, obinv, DEG_get_evaluated_object(ctx->depsgraph, amd->offset_ob)->obmat);
copy_m4_m4(offset, result_mat);
}
@ -453,12 +455,13 @@ static Mesh *arrayModifier_doArray(
mat4_to_size(scale, offset);
offset_has_scale = !is_one_v3(scale);
if (amd->fit_type == MOD_ARR_FITCURVE && amd->curve_ob) {
Curve *cu = amd->curve_ob->data;
if (amd->fit_type == MOD_ARR_FITCURVE && amd->curve_ob != NULL) {
Object *curve_ob = DEG_get_evaluated_object(ctx->depsgraph, amd->curve_ob);
Curve *cu = curve_ob->data;
if (cu) {
CurveCache *curve_cache = amd->curve_ob->runtime.curve_cache;
CurveCache *curve_cache = curve_ob->runtime.curve_cache;
if (curve_cache != NULL && curve_cache->path != NULL) {
float scale_fac = mat4_to_scale(amd->curve_ob->obmat);
float scale_fac = mat4_to_scale(curve_ob->obmat);
length = scale_fac * curve_cache->path->totdist;
}
}

View File

@ -176,15 +176,14 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
Mesh *mesh_other;
bool mesh_other_free;
if (!bmd->object) {
if (bmd->object == NULL) {
return result;
}
Object *ob_eval = DEG_get_evaluated_object(ctx->depsgraph, bmd->object);
mesh_other = BKE_modifier_get_evaluated_mesh_from_evaluated_object(ob_eval, &mesh_other_free);
Object *other = DEG_get_evaluated_object(ctx->depsgraph, bmd->object);
mesh_other = BKE_modifier_get_evaluated_mesh_from_evaluated_object(other, &mesh_other_free);
if (mesh_other) {
Object *object = ctx->object;
Object *other = bmd->object;
/* when one of objects is empty (has got no faces) we could speed up
* calculation a bit returning one of objects' derived meshes (or empty one)
@ -266,6 +265,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
short *material_remap = BLI_array_alloca(material_remap, ob_src_totcol ? ob_src_totcol : 1);
/* Using original (not evaluated) object here since we are writing to it. */
/* XXX Pretty sure comment above is fully wrong now with CoW & co ? */
BKE_material_remap_object_calc(ctx->object, other, material_remap);
BMFace *efa;

View File

@ -48,6 +48,8 @@
#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "DEG_depsgraph_query.h"
#include "MOD_util.h"
static void initData(ModifierData *md)
@ -105,7 +107,8 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
}
static void sphere_do(
CastModifierData *cmd, Object *ob, Mesh *mesh,
CastModifierData *cmd, const ModifierEvalContext *ctx,
Object *ob, Mesh *mesh,
float (*vertexCos)[3], int numVerts)
{
MDeformVert *dvert = NULL;
@ -128,7 +131,7 @@ static void sphere_do(
if (type == MOD_CAST_TYPE_CYLINDER)
flag &= ~MOD_CAST_Z;
ctrl_ob = cmd->object;
ctrl_ob = DEG_get_evaluated_object(ctx->depsgraph, 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,
@ -226,7 +229,8 @@ static void sphere_do(
}
static void cuboid_do(
CastModifierData *cmd, Object *ob, Mesh *mesh,
CastModifierData *cmd, const ModifierEvalContext *ctx,
Object *ob, Mesh *mesh,
float (*vertexCos)[3], int numVerts)
{
MDeformVert *dvert = NULL;
@ -244,7 +248,7 @@ static void cuboid_do(
flag = cmd->flag;
ctrl_ob = cmd->object;
ctrl_ob = DEG_get_evaluated_object(ctx->depsgraph, cmd->object);
/* now we check which options the user wants */
@ -437,10 +441,10 @@ static void deformVerts(
}
if (cmd->type == MOD_CAST_TYPE_CUBOID) {
cuboid_do(cmd, ctx->object, mesh_src, vertexCos, numVerts);
cuboid_do(cmd, ctx, ctx->object, mesh_src, vertexCos, numVerts);
}
else { /* MOD_CAST_TYPE_SPHERE or MOD_CAST_TYPE_CYLINDER */
sphere_do(cmd, ctx->object, mesh_src, vertexCos, numVerts);
sphere_do(cmd, ctx, ctx->object, mesh_src, vertexCos, numVerts);
}
if (!ELEM(mesh_src, NULL, mesh)) {
@ -459,10 +463,10 @@ static void deformVertsEM(
BLI_assert(mesh_src->totvert == numVerts);
if (cmd->type == MOD_CAST_TYPE_CUBOID) {
cuboid_do(cmd, ctx->object, mesh_src, vertexCos, numVerts);
cuboid_do(cmd, ctx, ctx->object, mesh_src, vertexCos, numVerts);
}
else { /* MOD_CAST_TYPE_SPHERE or MOD_CAST_TYPE_CYLINDER */
sphere_do(cmd, ctx->object, mesh_src, vertexCos, numVerts);
sphere_do(cmd, ctx, ctx->object, mesh_src, vertexCos, numVerts);
}
if (mesh_src != mesh) {

View File

@ -49,6 +49,7 @@
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_build.h"
#include "DEG_depsgraph_query.h"
#include "MOD_modifiertypes.h"
#include "MOD_util.h"
@ -125,7 +126,8 @@ 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(cmd->object, ctx->object, vertexCos, numVerts, dvert, defgrp_index, cmd->defaxis - 1);
curve_deform_verts(DEG_get_evaluated_object(ctx->depsgraph, cmd->object), ctx->object,
vertexCos, numVerts, dvert, defgrp_index, cmd->defaxis - 1);
if (!ELEM(mesh_src, NULL, mesh)) {
BKE_id_free(NULL, mesh_src);

View File

@ -166,6 +166,8 @@ 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);
const bool invert_vgroup = (dtmd->flags & MOD_DATATRANSFER_INVERT_VGROUP) != 0;
const float max_dist = (dtmd->flags & MOD_DATATRANSFER_MAP_MAXDIST) ? dtmd->map_max_distance : FLT_MAX;
@ -174,7 +176,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
SpaceTransform *space_transform = (dtmd->flags & MOD_DATATRANSFER_OBSRC_TRANSFORM) ? &space_transform_data : NULL;
if (space_transform) {
BLI_SPACE_TRANSFORM_SETUP(space_transform, ctx->object, dtmd->ob_source);
BLI_SPACE_TRANSFORM_SETUP(space_transform, ctx->object, ob_source);
}
if (((result == me) || (me->mvert == result->mvert) || (me->medge == result->medge)) &&
@ -194,7 +196,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
BKE_reports_init(&reports, RPT_STORE);
/* Note: no islands precision for now here. */
BKE_object_data_transfer_ex(ctx->depsgraph, scene, dtmd->ob_source, ctx->object, result, dtmd->data_types, false,
BKE_object_data_transfer_ex(ctx->depsgraph, scene, ob_source, ctx->object, result, dtmd->data_types, false,
dtmd->vmap_mode, dtmd->emap_mode, dtmd->lmap_mode, dtmd->pmap_mode,
space_transform, false, max_dist, dtmd->map_ray_radius, 0.0f,
dtmd->layers_select_src, dtmd->layers_select_dst,
@ -206,7 +208,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
else if ((dtmd->data_types & DT_TYPE_LNOR) && !(me->flag & ME_AUTOSMOOTH)) {
modifier_setError((ModifierData *)dtmd, "Enable 'Auto Smooth' option in mesh settings");
}
else if (result->totvert > HIGH_POLY_WARNING || ((Mesh *)(dtmd->ob_source->data))->totvert > HIGH_POLY_WARNING) {
else if (result->totvert > HIGH_POLY_WARNING || ((Mesh *)(ob_source->data))->totvert > HIGH_POLY_WARNING) {
modifier_setError(md, "You are using a rather high poly as source or destination, computation might be slow");
}

View File

@ -171,6 +171,7 @@ typedef struct DisplaceUserdata {
int defgrp_index;
int direction;
bool use_global_direction;
Tex *tex_target;
float (*tex_co)[3];
float (*vertexCos)[3];
float local_mat[4][4];
@ -209,9 +210,9 @@ static void displaceModifier_do_task(
}
}
if (dmd->texture) {
if (data->tex_target) {
texres.nor = NULL;
BKE_texture_get_value_ex(data->scene, dmd->texture, tex_co[iter], &texres, data->pool, false);
BKE_texture_get_value_ex(data->scene, data->tex_target, tex_co[iter], &texres, data->pool, false);
delta = texres.tin - dmd->midlevel;
}
else {
@ -282,7 +283,6 @@ static void displaceModifier_do(
Mesh *mesh, float (*vertexCos)[3], const int numVerts)
{
Object *ob = ctx->object;
Depsgraph *depsgraph = ctx->depsgraph;
MVert *mvert;
MDeformVert *dvert;
int direction = dmd->direction;
@ -293,18 +293,19 @@ static void displaceModifier_do(
float local_mat[4][4] = {{0}};
const bool use_global_direction = dmd->space == MOD_DISP_SPACE_GLOBAL;
if (!dmd->texture && dmd->direction == MOD_DISP_DIR_RGB_XYZ) return;
if (dmd->texture == NULL && dmd->direction == MOD_DISP_DIR_RGB_XYZ) return;
if (dmd->strength == 0.0f) return;
mvert = mesh->mvert;
MOD_get_vgroup(ob, mesh, dmd->defgrp_name, &dvert, &defgrp_index);
if (dmd->texture) {
Tex *tex_target = (Tex *)DEG_get_evaluated_id(ctx->depsgraph, &dmd->texture->id);
if (tex_target != NULL) {
tex_co = MEM_calloc_arrayN((size_t)numVerts, sizeof(*tex_co),
"displaceModifier_do tex_co");
MOD_get_texture_coords((MappingInfoModifierData *)dmd, ob, mesh, vertexCos, tex_co);
MOD_get_texture_coords((MappingInfoModifierData *)dmd, ctx, ob, mesh, vertexCos, tex_co);
MOD_init_texture(depsgraph, dmd->texture);
MOD_init_texture((MappingInfoModifierData *)dmd, ctx);
}
else {
tex_co = NULL;
@ -343,14 +344,15 @@ static void displaceModifier_do(
data.defgrp_index = defgrp_index;
data.direction = direction;
data.use_global_direction = use_global_direction;
data.tex_target = tex_target;
data.tex_co = tex_co;
data.vertexCos = vertexCos;
copy_m4_m4(data.local_mat, local_mat);
data.mvert = mvert;
data.vert_clnors = vert_clnors;
if (dmd->texture != NULL) {
if (tex_target != NULL) {
data.pool = BKE_image_pool_new();
BKE_texture_fetch_images_for_pool(dmd->texture, data.pool);
BKE_texture_fetch_images_for_pool(tex_target, data.pool);
}
ParallelRangeSettings settings;
BLI_parallel_range_settings_defaults(&settings);

View File

@ -49,6 +49,8 @@
#include "BKE_deform.h"
#include "BKE_colortools.h"
#include "DEG_depsgraph_query.h"
#include "MEM_guardedalloc.h"
#include "MOD_util.h"
@ -252,10 +254,12 @@ static void hook_co_apply(struct HookData_cb *hd, const int j)
}
static void deformVerts_do(
HookModifierData *hmd, Object *ob, Mesh *mesh,
HookModifierData *hmd, const ModifierEvalContext *ctx,
Object *ob, Mesh *mesh,
float (*vertexCos)[3], int numVerts)
{
bPoseChannel *pchan = BKE_pose_channel_find_name(hmd->object->pose, hmd->subtarget);
Object *ob_target = DEG_get_evaluated_object(ctx->depsgraph, hmd->object);
bPoseChannel *pchan = BKE_pose_channel_find_name(ob_target->pose, hmd->subtarget);
float dmat[4][4];
int i, *index_pt;
struct HookData_cb hd;
@ -295,11 +299,11 @@ static void deformVerts_do(
/* get world-space matrix of target, corrected for the space the verts are in */
if (hmd->subtarget[0] && pchan) {
/* bone target if there's a matching pose-channel */
mul_m4_m4m4(dmat, hmd->object->obmat, pchan->pose_mat);
mul_m4_m4m4(dmat, ob_target->obmat, pchan->pose_mat);
}
else {
/* just object target */
copy_m4_m4(dmat, hmd->object->obmat);
copy_m4_m4(dmat, ob_target->obmat);
}
invert_m4_m4(ob->imat, ob->obmat);
mul_m4_series(hd.mat, ob->imat, dmat, hmd->parentinv);
@ -356,7 +360,7 @@ static void deformVerts(
HookModifierData *hmd = (HookModifierData *)md;
Mesh *mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, NULL, numVerts, false, false);
deformVerts_do(hmd, ctx->object, mesh_src, vertexCos, numVerts);
deformVerts_do(hmd, ctx, ctx->object, mesh_src, vertexCos, numVerts);
if (!ELEM(mesh_src, NULL, mesh)) {
BKE_id_free(NULL, mesh_src);
@ -371,7 +375,7 @@ static void deformVertsEM(
HookModifierData *hmd = (HookModifierData *)md;
Mesh *mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, NULL, numVerts, false, false);
deformVerts_do(hmd, ctx->object, mesh_src, vertexCos, numVerts);
deformVerts_do(hmd, ctx, ctx->object, mesh_src, vertexCos, numVerts);
if (!ELEM(mesh_src, NULL, mesh)) {
BKE_id_free(NULL, mesh_src);

View File

@ -46,6 +46,8 @@
#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "DEG_depsgraph_query.h"
#include "MEM_guardedalloc.h"
#include "MOD_util.h"
@ -104,7 +106,7 @@ static void deformVerts(
MOD_previous_vcos_store(md, vertexCos); /* if next modifier needs original vertices */
lattice_deform_verts(lmd->object, ctx->object, mesh_src,
lattice_deform_verts(DEG_get_evaluated_object(ctx->depsgraph, lmd->object), ctx->object, mesh_src,
vertexCos, numVerts, lmd->name, lmd->strength);
if (!ELEM(mesh_src, NULL, mesh)) {

View File

@ -54,6 +54,7 @@
#include "BKE_deform.h"
#include "DEG_depsgraph_build.h"
#include "DEG_depsgraph_query.h"
#include "MOD_modifiertypes.h"
@ -137,7 +138,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 = mmd->ob_arm;
Object *oba = DEG_get_evaluated_object(ctx->depsgraph, mmd->ob_arm);
bPoseChannel *pchan;
bDeformGroup *def;
bool *bone_select_array;

View File

@ -295,7 +295,7 @@ static void meshdeformModifier_do(
static int recursive_bind_sentinel = 0;
if (!mmd->object || (!mmd->bindcagecos && !mmd->bindfunc))
if (mmd->object == NULL || (mmd->bindcagecos == NULL && mmd->bindfunc == NULL))
return;
/* Get cage mesh.
@ -308,21 +308,23 @@ static void meshdeformModifier_do(
*
* We'll support this case once granular dependency graph is landed.
*/
cagemesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(mmd->object, &free_cagemesh);
Object *ob_target = DEG_get_evaluated_object(ctx->depsgraph, mmd->object);
cagemesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(ob_target, &free_cagemesh);
#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)) {
/* Special case, binding happens outside of depsgraph evaluation, so we can build our own
* target mesh if needed. */
cagemesh = mesh_create_eval_final_view(ctx->depsgraph, DEG_get_input_scene(ctx->depsgraph), mmd->object, 0);
free_cagemesh = cagemesh != NULL;
}
#endif
if (cagemesh == NULL) {
modifier_setError(md, "Cannot get mesh from cage object");
return;
}
/* compute matrices to go in and out of cage object space */
invert_m4_m4(imat, mmd->object->obmat);
invert_m4_m4(imat, ob_target->obmat);
mul_m4_m4m4(cagemat, imat, ob->obmat);
mul_m4_m4m4(cmat, mmd->bindmat, cagemat);
invert_m4_m4(iobmat, cmat);

View File

@ -51,6 +51,7 @@
#include "MEM_guardedalloc.h"
#include "DEG_depsgraph_build.h"
#include "DEG_depsgraph_query.h"
#include "MOD_modifiertypes.h"
@ -85,6 +86,7 @@ static Mesh *doBiscetOnMirrorPlane(
MirrorModifierData *mmd,
Object *ob,
const Mesh *mesh,
Object *mirror_ob,
int axis,
float mirrormat[4][4])
{
@ -114,10 +116,10 @@ static Mesh *doBiscetOnMirrorPlane(
float plane_no[3];
copy_v3_v3(plane_no, mirrormat[axis]);
if (mmd->mirror_ob) {
if (mirror_ob != NULL) {
float tmp[4][4];
invert_m4_m4(tmp, ob->obmat);
mul_m4_m4m4(tmp, tmp, mmd->mirror_ob->obmat);
mul_m4_m4m4(tmp, tmp, mirror_ob->obmat);
copy_v3_v3(plane_no, tmp[axis]);
copy_v3_v3(plane_co, tmp[3]);
@ -151,6 +153,7 @@ static Mesh *doBiscetOnMirrorPlane(
static Mesh *doMirrorOnAxis(
MirrorModifierData *mmd,
const ModifierEvalContext *ctx,
Object *ob,
const Mesh *mesh,
int axis)
@ -178,13 +181,14 @@ static Mesh *doMirrorOnAxis(
unit_m4(mtx);
mtx[axis][axis] = -1.0f;
if (mmd->mirror_ob) {
Object *mirror_ob = DEG_get_evaluated_object(ctx->depsgraph, mmd->mirror_ob);
if (mirror_ob != NULL) {
float tmp[4][4];
float itmp[4][4];
/* tmp is a transform from coords relative to the object's own origin,
* to coords relative to the mirror object origin */
invert_m4_m4(tmp, mmd->mirror_ob->obmat);
invert_m4_m4(tmp, mirror_ob->obmat);
mul_m4_m4m4(tmp, tmp, ob->obmat);
/* itmp is the reverse transform back to origin-relative coordinates */
@ -200,7 +204,7 @@ static Mesh *doMirrorOnAxis(
Mesh *mesh_bisect = NULL;
if (do_bisect) {
mesh_bisect = doBiscetOnMirrorPlane(mmd, ob, mesh, axis, mtx);
mesh_bisect = doBiscetOnMirrorPlane(mmd, ob, mesh, mirror_ob, axis, mtx);
mesh = mesh_bisect;
}
@ -382,18 +386,18 @@ static Mesh *doMirrorOnAxis(
}
static Mesh *mirrorModifier__doMirror(
MirrorModifierData *mmd,
MirrorModifierData *mmd, const ModifierEvalContext *ctx,
Object *ob, Mesh *mesh)
{
Mesh *result = mesh;
/* check which axes have been toggled and mirror accordingly */
if (mmd->flag & MOD_MIR_AXIS_X) {
result = doMirrorOnAxis(mmd, ob, result, 0);
result = doMirrorOnAxis(mmd, ctx, ob, result, 0);
}
if (mmd->flag & MOD_MIR_AXIS_Y) {
Mesh *tmp = result;
result = doMirrorOnAxis(mmd, ob, result, 1);
result = doMirrorOnAxis(mmd, ctx, ob, result, 1);
if (tmp != mesh) {
/* free intermediate results */
BKE_id_free(NULL, tmp);
@ -401,7 +405,7 @@ static Mesh *mirrorModifier__doMirror(
}
if (mmd->flag & MOD_MIR_AXIS_Z) {
Mesh *tmp = result;
result = doMirrorOnAxis(mmd, ob, result, 2);
result = doMirrorOnAxis(mmd, ctx, ob, result, 2);
if (tmp != mesh) {
/* free intermediate results */
BKE_id_free(NULL, tmp);
@ -418,7 +422,7 @@ static Mesh *applyModifier(
Mesh *result;
MirrorModifierData *mmd = (MirrorModifierData *) md;
result = mirrorModifier__doMirror(mmd, ctx->object, mesh);
result = mirrorModifier__doMirror(mmd, ctx, ctx->object, mesh);
if (result != mesh) {
result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;

View File

@ -42,6 +42,8 @@
#include "BKE_mesh.h"
#include "BKE_deform.h"
#include "DEG_depsgraph_query.h"
#include "MOD_util.h"
@ -193,13 +195,16 @@ static bool polygons_check_flip(
}
static void normalEditModifier_do_radial(
NormalEditModifierData *enmd, Object *ob, Mesh *mesh,
NormalEditModifierData *enmd, const ModifierEvalContext *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,
MDeformVert *dvert, const int defgrp_index, const bool use_invert_vgroup,
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);
const bool do_polynors_fix = (enmd->flag & MOD_NORMALEDIT_NO_POLYNORS_FIX) == 0;
int i;
@ -209,7 +214,7 @@ static void normalEditModifier_do_radial(
BLI_bitmap *done_verts = BLI_BITMAP_NEW((size_t)num_verts, __func__);
generate_vert_coordinates(mesh, ob, enmd->target, enmd->offset, num_verts, cos, size);
generate_vert_coordinates(mesh, ob, ob_target, enmd->offset, num_verts, cos, size);
/**
* size gives us our spheroid coefficients ``(A, B, C)``.
@ -294,13 +299,16 @@ static void normalEditModifier_do_radial(
}
static void normalEditModifier_do_directional(
NormalEditModifierData *enmd, Object *ob, Mesh *mesh,
NormalEditModifierData *enmd, const ModifierEvalContext *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,
MDeformVert *dvert, const int defgrp_index, const bool use_invert_vgroup,
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);
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;
@ -313,7 +321,7 @@ static void normalEditModifier_do_directional(
float mat[4][4];
invert_m4_m4(mat, ob->obmat);
mul_m4_m4m4(mat, mat, enmd->target->obmat);
mul_m4_m4m4(mat, mat, ob_target->obmat);
copy_v3_v3(target_co, mat[3]);
if (use_parallel_normals) {
@ -328,7 +336,7 @@ static void normalEditModifier_do_directional(
}
else {
float (*cos)[3] = MEM_malloc_arrayN((size_t)num_verts, sizeof(*cos), __func__);
generate_vert_coordinates(mesh, ob, enmd->target, NULL, num_verts, cos, NULL);
generate_vert_coordinates(mesh, ob, ob_target, NULL, num_verts, cos, NULL);
BLI_bitmap *done_verts = BLI_BITMAP_NEW((size_t)num_verts, __func__);
MLoop *ml;
@ -380,7 +388,8 @@ static bool is_valid_target(NormalEditModifierData *enmd)
return false;
}
static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, Object *ob, Mesh *mesh)
static Mesh *normalEditModifier_do(
NormalEditModifierData *enmd, const ModifierEvalContext *ctx, Object *ob, Mesh *mesh)
{
const bool use_invert_vgroup = ((enmd->flag & MOD_NORMALEDIT_INVERT_VGROUP) != 0);
const bool use_current_clnors = !((enmd->mix_mode == MOD_NORMALEDIT_MIX_COPY) &&
@ -474,13 +483,13 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, Object *ob, Mes
if (enmd->mode == MOD_NORMALEDIT_MODE_RADIAL) {
normalEditModifier_do_radial(
enmd, ob, result, clnors, loopnors, polynors,
enmd, ctx, ob, result, clnors, loopnors, polynors,
enmd->mix_mode, enmd->mix_factor, enmd->mix_limit, dvert, defgrp_index, use_invert_vgroup,
mvert, num_verts, medge, num_edges, mloop, num_loops, mpoly, num_polys);
}
else if (enmd->mode == MOD_NORMALEDIT_MODE_DIRECTIONAL) {
normalEditModifier_do_directional(
enmd, ob, result, clnors, loopnors, polynors,
enmd, ctx, ob, result, clnors, loopnors, polynors,
enmd->mix_mode, enmd->mix_factor, enmd->mix_limit, dvert, defgrp_index, use_invert_vgroup,
mvert, num_verts, medge, num_edges, mloop, num_loops, mpoly, num_polys);
}
@ -542,7 +551,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
{
return normalEditModifier_do((NormalEditModifierData *)md, ctx->object, mesh);
return normalEditModifier_do((NormalEditModifierData *)md, ctx, ctx->object, mesh);
}
ModifierTypeInfo modifierType_NormalEdit = {

View File

@ -49,6 +49,7 @@
#include "BKE_mesh.h"
#include "DEG_depsgraph_build.h"
#include "DEG_depsgraph_query.h"
#include "MOD_modifiertypes.h"
#include "MEM_guardedalloc.h"
@ -245,6 +246,8 @@ 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);
ScrewVertConnect *vc, *vc_tmp, *vert_connect = NULL;
const char mpoly_flag = (ltmd->flag & MOD_SCREW_SMOOTH_SHADING) ? ME_SMOOTH : 0;
@ -270,10 +273,10 @@ static Mesh *applyModifier(
axis_vec[ltmd->axis] = 1.0f;
if (ltmd->ob_axis) {
if (ob_axis != NULL) {
/* calc the matrix relative to the axis object */
invert_m4_m4(mtx_tmp_a, ctx->object->obmat);
copy_m4_m4(mtx_tx_inv, ltmd->ob_axis->obmat);
copy_m4_m4(mtx_tx_inv, ob_axis->obmat);
mul_m4_m4m4(mtx_tx, mtx_tmp_a, mtx_tx_inv);
/* calc the axis vec */
@ -508,7 +511,7 @@ static Mesh *applyModifier(
med_new = medge_new;
mv_new = mvert_new;
if (ltmd->ob_axis) {
if (ob_axis != NULL) {
/*mtx_tx is initialized early on */
for (i = 0; i < totvert; i++, mv_new++, mv_orig++, vc++) {
vc->co[0] = mv_new->co[0] = mv_orig->co[0];
@ -839,7 +842,7 @@ static Mesh *applyModifier(
/* Rotation Matrix */
step_angle = (angle / (float)(step_tot - (!close))) * (float)step;
if (ltmd->ob_axis) {
if (ob_axis != NULL) {
axis_angle_normalized_to_mat3(mat3, axis_vec, step_angle);
}
else {
@ -871,7 +874,7 @@ static Mesh *applyModifier(
/* only need to set these if using non cleared memory */
/*mv_new->mat_nr = mv_new->flag = 0;*/
if (ltmd->ob_axis) {
if (ob_axis != NULL) {
sub_v3_v3(mv_new->co, mtx_tx[3]);
mul_m4_v3(mat, mv_new->co);
@ -1098,7 +1101,7 @@ static Mesh *applyModifier(
Mesh *result_prev = result;
result = mesh_remove_doubles_on_axis(
result, mvert_new, totvert, step_tot,
axis_vec, ltmd->ob_axis ? mtx_tx[3] : NULL, ltmd->merge_dist);
axis_vec, ob_axis != NULL ? mtx_tx[3] : NULL, ltmd->merge_dist);
if (result != result_prev) {
result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
}

View File

@ -118,7 +118,7 @@ static void deformVerts(
int defgrp_index = -1;
MOD_get_vgroup(ctx->object, mesh_src, swmd->vgroup_name, &dvert, &defgrp_index);
shrinkwrapModifier_deform(swmd, scene, ctx->object, mesh_src, dvert, defgrp_index, vertexCos, numVerts);
shrinkwrapModifier_deform(swmd, ctx, scene, ctx->object, mesh_src, dvert, defgrp_index, vertexCos, numVerts);
if (!ELEM(mesh_src, NULL, mesh)) {
BKE_id_free(NULL, mesh_src);
@ -138,7 +138,7 @@ static void deformVertsEM(
int defgrp_index = -1;
MOD_get_vgroup(ctx->object, mesh_src, swmd->vgroup_name, &dvert, &defgrp_index);
shrinkwrapModifier_deform(swmd, scene, ctx->object, mesh_src, dvert, defgrp_index, vertexCos, numVerts);
shrinkwrapModifier_deform(swmd, ctx, scene, ctx->object, mesh_src, dvert, defgrp_index, vertexCos, numVerts);
if (!ELEM(mesh_src, NULL, mesh)) {
BKE_id_free(NULL, mesh_src);

View File

@ -46,6 +46,8 @@
#include "BKE_modifier.h"
#include "BKE_deform.h"
#include "DEG_depsgraph_query.h"
#include "MOD_util.h"
#include "bmesh.h"
@ -186,7 +188,8 @@ static void simpleDeform_bend(const float factor, const int axis, const float dc
/* simple deform modifier */
static void SimpleDeformModifier_do(
SimpleDeformModifierData *smd, struct Object *ob, struct Mesh *mesh,
SimpleDeformModifierData *smd, const ModifierEvalContext *ctx,
struct Object *ob, struct Mesh *mesh,
float (*vertexCos)[3], int numVerts)
{
const float base_limit[2] = {0.0f, 0.0f};
@ -227,9 +230,9 @@ static void SimpleDeformModifier_do(
smd->limit[0] = min_ff(smd->limit[0], smd->limit[1]); /* Upper limit >= than lower limit */
/* Calculate matrixs do convert between coordinate spaces */
if (smd->origin) {
if (smd->origin != NULL) {
transf = &tmp_transf;
BLI_SPACE_TRANSFORM_SETUP(transf, ob, smd->origin);
BLI_SPACE_TRANSFORM_SETUP(transf, ob, DEG_get_evaluated_object(ctx->depsgraph, smd->origin));
}
/* Update limits if needed */
@ -394,7 +397,7 @@ static void deformVerts(
mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, NULL, numVerts, false, false);
}
SimpleDeformModifier_do(sdmd, ctx->object, mesh_src, vertexCos, numVerts);
SimpleDeformModifier_do(sdmd, ctx, ctx->object, mesh_src, vertexCos, numVerts);
if (!ELEM(mesh_src, NULL, mesh)) {
BKE_id_free(NULL, mesh_src);
@ -416,7 +419,7 @@ static void deformVertsEM(
mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, NULL, numVerts, false, false);
}
SimpleDeformModifier_do(sdmd, ctx->object, mesh_src, vertexCos, numVerts);
SimpleDeformModifier_do(sdmd, ctx, ctx->object, mesh_src, vertexCos, numVerts);
if (!ELEM(mesh_src, NULL, mesh)) {
BKE_id_free(NULL, mesh_src);

View File

@ -1125,13 +1125,16 @@ static void surfacedeformModifier_do(
return;
}
target = BKE_modifier_get_evaluated_mesh_from_evaluated_object(smd->target, &free_target);
Object *ob_target = DEG_get_evaluated_object(ctx->depsgraph, smd->target);
target = BKE_modifier_get_evaluated_mesh_from_evaluated_object(ob_target, &free_target);
#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)) {
/* Special case, binding happens outside of depsgraph evaluation, so we can build our own
* target mesh if needed. */
target = mesh_create_eval_final_view(ctx->depsgraph, DEG_get_input_scene(ctx->depsgraph), smd->target, 0);
free_target = target != NULL;
}
#endif
if (!target) {
modifier_setError(md, "No valid target mesh");
return;
@ -1152,7 +1155,7 @@ static void surfacedeformModifier_do(
float tmp_mat[4][4];
invert_m4_m4(tmp_mat, ob->obmat);
mul_m4_m4m4(smd->mat, tmp_mat, smd->target->obmat);
mul_m4_m4m4(smd->mat, tmp_mat, ob_target->obmat);
if (!surfacedeformBind(smd, vertexCos, numverts, tnumpoly, tnumverts, target)) {
smd->flags &= ~MOD_SDEF_BIND;
@ -1223,7 +1226,7 @@ static bool isDisabled(const Scene *UNUSED(scene), ModifierData *md, bool UNUSED
{
SurfaceDeformModifierData *smd = (SurfaceDeformModifierData *)md;
return !smd->target && !(smd->verts && !(smd->flags & MOD_SDEF_BIND));
return smd->target == NULL && !(smd->verts != NULL && !(smd->flags & MOD_SDEF_BIND));
}
ModifierTypeInfo modifierType_SurfaceDeform = {

View File

@ -63,13 +63,16 @@
#include "bmesh.h"
void MOD_init_texture(const Depsgraph *depsgraph, Tex *tex)
void MOD_init_texture(MappingInfoModifierData *dmd, const ModifierEvalContext *ctx)
{
if (!tex)
Tex *tex = (Tex *)DEG_get_evaluated_id(ctx->depsgraph, &dmd->texture->id);
if (tex == NULL) {
return;
}
if (tex->ima && BKE_image_is_animated(tex->ima)) {
BKE_image_user_frame_calc(&tex->iuser, DEG_get_ctime(depsgraph));
BKE_image_user_frame_calc(&tex->iuser, DEG_get_ctime(ctx->depsgraph));
}
}
@ -77,6 +80,7 @@ void MOD_init_texture(const Depsgraph *depsgraph, Tex *tex)
/** \param cos may be NULL, in which case we use directly mesh vertices' coordinates. */
void MOD_get_texture_coords(
MappingInfoModifierData *dmd,
const ModifierEvalContext *ctx,
Object *ob,
Mesh *mesh,
float (*cos)[3],
@ -88,10 +92,13 @@ void MOD_get_texture_coords(
float mapob_imat[4][4];
if (texmapping == MOD_DISP_MAP_OBJECT) {
if (dmd->map_object)
invert_m4_m4(mapob_imat, dmd->map_object->obmat);
else /* if there is no map object, default to local */
if (dmd->map_object != NULL) {
Object *map_object = DEG_get_evaluated_object(ctx->depsgraph, dmd->map_object);
invert_m4_m4(mapob_imat, map_object->obmat);
}
else {/* if there is no map object, default to local */
texmapping = MOD_DISP_MAP_LOCAL;
}
}
/* UVs need special handling, since they come from faces */

View File

@ -33,17 +33,18 @@
#include "DEG_depsgraph_build.h"
struct Depsgraph;
struct MDeformVert;
struct Mesh;
struct ModifierData;
struct ModifierEvalContext;
struct Object;
struct Scene;
struct Tex;
void MOD_init_texture(const struct Depsgraph *depsgraph, struct Tex *texture);
void MOD_init_texture(struct MappingInfoModifierData *dmd, const struct ModifierEvalContext *ctx);
void MOD_get_texture_coords(
struct MappingInfoModifierData *dmd,
const struct ModifierEvalContext *ctx,
struct Object *ob,
struct Mesh *mesh,
float (*cos)[3],

View File

@ -125,6 +125,7 @@ typedef struct Projector {
static Mesh *uvprojectModifier_do(
UVProjectModifierData *umd,
const ModifierEvalContext *ctx,
Object *ob, Mesh *mesh)
{
float (*coords)[3], (*co)[3];
@ -141,11 +142,14 @@ static Mesh *uvprojectModifier_do(
float scay = umd->scaley ? umd->scaley : 1.0f;
int free_uci = 0;
for (i = 0; i < umd->num_projectors; ++i)
if (umd->projectors[i])
projectors[num_projectors++].ob = umd->projectors[i];
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]);
}
}
if (num_projectors == 0) return mesh;
if (num_projectors == 0)
return mesh;
/* make sure there are UV Maps available */
@ -317,7 +321,7 @@ static Mesh *applyModifier(
Mesh *result;
UVProjectModifierData *umd = (UVProjectModifierData *) md;
result = uvprojectModifier_do(umd, ctx->object, mesh);
result = uvprojectModifier_do(umd, ctx, ctx->object, mesh);
return result;
}

View File

@ -40,6 +40,8 @@
#include "BKE_library_query.h"
#include "BKE_modifier.h"
#include "DEG_depsgraph_query.h"
#include "MOD_util.h"
@ -167,8 +169,8 @@ static Mesh *applyModifier(
}
/* make sure anything moving UVs is available */
matrix_from_obj_pchan(mat_src, umd->object_src, umd->bone_src);
matrix_from_obj_pchan(mat_dst, umd->object_dst, umd->bone_dst);
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);
invert_m4_m4(imat_dst, mat_dst);
mul_m4_m4m4(warp_mat, imat_dst, mat_src);

View File

@ -160,7 +160,6 @@ static void warpModifier_do(
Mesh *mesh, float (*vertexCos)[3], int numVerts)
{
Object *ob = ctx->object;
Depsgraph *depsgraph = ctx->depsgraph;
float obinv[4][4];
float mat_from[4][4];
float mat_from_inv[4][4];
@ -196,8 +195,8 @@ static void warpModifier_do(
invert_m4_m4(obinv, ob->obmat);
mul_m4_m4m4(mat_from, obinv, wmd->object_from->obmat);
mul_m4_m4m4(mat_to, obinv, wmd->object_to->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);
invert_m4_m4(tmat, mat_from); // swap?
mul_m4_m4m4(mat_final, tmat, mat_to);
@ -218,11 +217,12 @@ static void warpModifier_do(
}
weight = strength;
if (mesh != NULL && wmd->texture) {
Tex *tex_target = (Tex *)DEG_get_evaluated_id(ctx->depsgraph, &wmd->texture->id);
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, ob, mesh, vertexCos, tex_co);
MOD_get_texture_coords((MappingInfoModifierData *)wmd, ctx, ob, mesh, vertexCos, tex_co);
MOD_init_texture(depsgraph, wmd->texture);
MOD_init_texture((MappingInfoModifierData *)wmd, ctx);
}
for (i = 0; i < numVerts; i++) {
@ -279,7 +279,7 @@ static void warpModifier_do(
struct Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
TexResult texres;
texres.nor = NULL;
BKE_texture_get_value(scene, wmd->texture, tex_co[i], &texres, false);
BKE_texture_get_value(scene, tex_target, tex_co[i], &texres, false);
fac *= texres.tin;
}

View File

@ -157,7 +157,7 @@ static bool dependsOnNormals(ModifierData *md)
static void waveModifier_do(
WaveModifierData *md,
Depsgraph *depsgraph,
const ModifierEvalContext *ctx,
Object *ob, Mesh *mesh,
float (*vertexCos)[3], int numVerts)
{
@ -165,7 +165,7 @@ static void waveModifier_do(
MVert *mvert = NULL;
MDeformVert *dvert;
int defgrp_index;
float ctime = DEG_get_ctime(depsgraph);
float ctime = DEG_get_ctime(ctx->depsgraph);
float minfac = (float)(1.0 / exp(wmd->width * wmd->narrow * wmd->width * wmd->narrow));
float lifefac = wmd->height;
float (*tex_co)[3] = NULL;
@ -177,11 +177,11 @@ static void waveModifier_do(
mvert = mesh->mvert;
}
if (wmd->objectcenter) {
if (wmd->objectcenter != NULL) {
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, wmd->objectcenter->obmat);
mul_m4_m4m4(mat, ob->imat, DEG_get_evaluated_object(ctx->depsgraph, wmd->objectcenter)->obmat);
wmd->startx = mat[3][0];
wmd->starty = mat[3][1];
@ -205,11 +205,12 @@ static void waveModifier_do(
}
}
if (mesh != NULL && wmd->texture) {
Tex *tex_target = (Tex *)DEG_get_evaluated_id(ctx->depsgraph, &wmd->texture->id);
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, ob, mesh, vertexCos, tex_co);
MOD_get_texture_coords((MappingInfoModifierData *)wmd, ctx, ob, mesh, vertexCos, tex_co);
MOD_init_texture(depsgraph, wmd->texture);
MOD_init_texture((MappingInfoModifierData *)wmd, ctx);
}
if (lifefac != 0.0f) {
@ -279,11 +280,11 @@ static void waveModifier_do(
amplit = (float)(1.0f / expf(amplit * amplit) - minfac);
/*apply texture*/
if (wmd->texture) {
Scene *scene = DEG_get_evaluated_scene(depsgraph);
if (tex_target) {
Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
TexResult texres;
texres.nor = NULL;
BKE_texture_get_value(scene, wmd->texture, tex_co[i], &texres, false);
BKE_texture_get_value(scene, tex_target, tex_co[i], &texres, false);
amplit *= texres.tin;
}
@ -329,7 +330,7 @@ static void deformVerts(
mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, NULL, numVerts, false, false);
}
waveModifier_do(wmd, ctx->depsgraph, ctx->object, mesh_src, vertexCos, numVerts);
waveModifier_do(wmd, ctx, ctx->object, mesh_src, vertexCos, numVerts);
if (!ELEM(mesh_src, NULL, mesh)) {
BKE_id_free(NULL, mesh_src);
@ -351,7 +352,7 @@ static void deformVertsEM(
mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, NULL, numVerts, false, false);
}
waveModifier_do(wmd, ctx->depsgraph, ctx->object, mesh_src, vertexCos, numVerts);
waveModifier_do(wmd, ctx, ctx->object, mesh_src, vertexCos, numVerts);
if (!ELEM(mesh_src, NULL, mesh)) {
BKE_id_free(NULL, mesh_src);

View File

@ -47,6 +47,7 @@
#include "BKE_texture.h" /* Texture masking. */
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"
#include "MEM_guardedalloc.h"
#include "MOD_util.h"
@ -124,7 +125,6 @@ void weightvg_do_mask(
Scene *scene, Tex *texture, const int tex_use_channel, const int tex_mapping,
Object *tex_map_object, const char *tex_uvlayer_name)
{
Depsgraph *depsgraph = ctx->depsgraph;
int ref_didx;
int i;
@ -132,7 +132,8 @@ void weightvg_do_mask(
if (fact == 0.0f) return;
/* If we want to mask vgroup weights from a texture. */
if (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... */
@ -150,9 +151,9 @@ void weightvg_do_mask(
t_map.texmapping = tex_mapping;
tex_co = MEM_calloc_arrayN(numVerts, sizeof(*tex_co), "WeightVG Modifier, TEX mode, tex_co");
MOD_get_texture_coords(&t_map, ob, mesh, NULL, tex_co);
MOD_get_texture_coords(&t_map, ctx, ob, mesh, NULL, tex_co);
MOD_init_texture(depsgraph, texture);
MOD_init_texture(&t_map, ctx);
/* For each weight (vertex), make the mix between org and new weights. */
for (i = 0; i < num; ++i) {

View File

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