Cleanup: More clear name in surface deform modifier

Make it explicit that counter is about target mesh.

Use DNA rename for it so that the files stay compatible.

Also renamed some purely runtime fields to replace `t`
prefix with `target` as the short `t` is super easy
to miss.

Differential Revision: https://developer.blender.org/D14835
This commit is contained in:
Sergey Sharybin 2022-05-03 17:19:53 +02:00
parent 2d80f814cc
commit aa1fb4204d
4 changed files with 29 additions and 19 deletions

View File

@ -632,7 +632,7 @@
.falloff = 4.0f, \
.mesh_verts_num = 0, \
.bind_verts_num = 0, \
.polys_num = 0, \
.target_polys_num = 0, \
.flags = 0, \
.mat = _DNA_DEFAULT_UNIT_M4, \
.strength = 1.0f, \

View File

@ -2223,7 +2223,8 @@ typedef struct SurfaceDeformModifierData {
/** Vertex bind data. */
SDefVert *verts;
float falloff;
unsigned int mesh_verts_num, bind_verts_num, polys_num;
unsigned int mesh_verts_num, bind_verts_num;
unsigned int target_polys_num;
int flags;
float mat[4][4];
float strength;

View File

@ -106,7 +106,7 @@ DNA_STRUCT_RENAME_ELEM(SDefBind, numverts, verts_num)
DNA_STRUCT_RENAME_ELEM(SDefVert, numbinds, binds_num)
DNA_STRUCT_RENAME_ELEM(SpaceSeq, overlay_type, overlay_frame_type)
DNA_STRUCT_RENAME_ELEM(SurfaceDeformModifierData, num_mesh_verts, mesh_verts_num)
DNA_STRUCT_RENAME_ELEM(SurfaceDeformModifierData, numpoly, polys_num)
DNA_STRUCT_RENAME_ELEM(SurfaceDeformModifierData, numpoly, target_polys_num)
DNA_STRUCT_RENAME_ELEM(SurfaceDeformModifierData, numverts, bind_verts_num)
DNA_STRUCT_RENAME_ELEM(SurfaceModifierData, numverts, verts_num)
DNA_STRUCT_RENAME_ELEM(Text, name, filepath)

View File

@ -1166,8 +1166,8 @@ static bool surfacedeformBind(Object *ob,
SurfaceDeformModifierData *smd_eval,
float (*vertexCos)[3],
uint verts_num,
uint tpolys_num,
uint tverts_num,
uint target_polys_num,
uint target_verts_num,
Mesh *target,
Mesh *mesh)
{
@ -1182,7 +1182,7 @@ static bool surfacedeformBind(Object *ob,
SDefAdjacency *adj_array;
SDefEdgePolys *edge_polys;
vert_edges = MEM_calloc_arrayN(tverts_num, sizeof(*vert_edges), "SDefVertEdgeMap");
vert_edges = MEM_calloc_arrayN(target_verts_num, sizeof(*vert_edges), "SDefVertEdgeMap");
if (vert_edges == NULL) {
BKE_modifier_set_error(ob, (ModifierData *)smd_eval, "Out of memory");
return false;
@ -1220,7 +1220,7 @@ static bool surfacedeformBind(Object *ob,
}
adj_result = buildAdjacencyMap(
mpoly, medge, mloop, tpolys_num, tedges_num, vert_edges, adj_array, edge_polys);
mpoly, medge, mloop, target_polys_num, tedges_num, vert_edges, adj_array, edge_polys);
if (adj_result == MOD_SDEF_BIND_RESULT_NONMANY_ERR) {
BKE_modifier_set_error(
@ -1233,7 +1233,7 @@ static bool surfacedeformBind(Object *ob,
}
smd_orig->mesh_verts_num = verts_num;
smd_orig->polys_num = tpolys_num;
smd_orig->target_polys_num = target_polys_num;
int defgrp_index;
MDeformVert *dvert;
@ -1249,7 +1249,8 @@ static bool surfacedeformBind(Object *ob,
.medge = medge,
.mloop = mloop,
.looptri = BKE_mesh_runtime_looptri_ensure(target),
.targetCos = MEM_malloc_arrayN(tverts_num, sizeof(float[3]), "SDefTargetBindVertArray"),
.targetCos = MEM_malloc_arrayN(
target_verts_num, sizeof(float[3]), "SDefTargetBindVertArray"),
.bind_verts = smd_orig->verts,
.vertexCos = vertexCos,
.falloff = smd_orig->falloff,
@ -1268,7 +1269,7 @@ static bool surfacedeformBind(Object *ob,
invert_m4_m4(data.imat, smd_orig->mat);
for (int i = 0; i < tverts_num; i++) {
for (int i = 0; i < target_verts_num; i++) {
mul_v3_m4v3(data.targetCos[i], smd_orig->mat, mvert[i].co);
}
@ -1431,7 +1432,7 @@ static void surfacedeformModifier_do(ModifierData *md,
{
SurfaceDeformModifierData *smd = (SurfaceDeformModifierData *)md;
Mesh *target;
uint tverts_num, tpolys_num;
uint target_verts_num, target_polys_num;
/* Exit function if bind flag is not set (free bind data if any). */
if (!(smd->flags & MOD_SDEF_BIND)) {
@ -1453,8 +1454,8 @@ static void surfacedeformModifier_do(ModifierData *md,
return;
}
tverts_num = BKE_mesh_wrapper_vert_len(target);
tpolys_num = BKE_mesh_wrapper_poly_len(target);
target_verts_num = BKE_mesh_wrapper_vert_len(target);
target_polys_num = BKE_mesh_wrapper_poly_len(target);
/* If not bound, execute bind. */
if (smd->verts == NULL) {
@ -1473,8 +1474,15 @@ static void surfacedeformModifier_do(ModifierData *md,
/* Avoid converting edit-mesh data, binding is an exception. */
BKE_mesh_wrapper_ensure_mdata(target);
if (!surfacedeformBind(
ob, smd_orig, smd, vertexCos, verts_num, tpolys_num, tverts_num, target, mesh)) {
if (!surfacedeformBind(ob,
smd_orig,
smd,
vertexCos,
verts_num,
target_polys_num,
target_verts_num,
target,
mesh)) {
smd->flags &= ~MOD_SDEF_BIND;
}
/* Early abort, this is binding 'call', no need to perform whole evaluation. */
@ -1487,9 +1495,9 @@ static void surfacedeformModifier_do(ModifierData *md,
ob, md, "Vertices changed from %u to %u", smd->mesh_verts_num, verts_num);
return;
}
if (smd->polys_num != tpolys_num) {
if (smd->target_polys_num != target_polys_num) {
BKE_modifier_set_error(
ob, md, "Target polygons changed from %u to %u", smd->polys_num, tpolys_num);
ob, md, "Target polygons changed from %u to %u", smd->target_polys_num, target_polys_num);
return;
}
@ -1507,7 +1515,7 @@ static void surfacedeformModifier_do(ModifierData *md,
/* Actual vertex location update starts here */
SDefDeformData data = {
.bind_verts = smd->verts,
.targetCos = MEM_malloc_arrayN(tverts_num, sizeof(float[3]), "SDefTargetVertArray"),
.targetCos = MEM_malloc_arrayN(target_verts_num, sizeof(float[3]), "SDefTargetVertArray"),
.vertexCos = vertexCos,
.dvert = dvert,
.defgrp_index = defgrp_index,
@ -1516,7 +1524,8 @@ static void surfacedeformModifier_do(ModifierData *md,
};
if (data.targetCos != NULL) {
BKE_mesh_wrapper_vert_coords_copy_with_mat4(target, data.targetCos, tverts_num, smd->mat);
BKE_mesh_wrapper_vert_coords_copy_with_mat4(
target, data.targetCos, target_verts_num, smd->mat);
TaskParallelSettings settings;
BLI_parallel_range_settings_defaults(&settings);