Cleanup: Rename variable in mesh modifier evaluation
`mesh_final` isn't really the final mesh but the "current" mesh. Adding the extra word here isn't helpful. This also helps to reduce the size of the diff in #119968 where the mesh variables have much smaller scopes.
This commit is contained in:
@@ -321,7 +321,7 @@ static void mesh_calc_modifiers(Depsgraph &depsgraph,
|
||||
/* Input mesh shouldn't be modified. */
|
||||
Mesh &mesh_input = *static_cast<Mesh *>(ob.data);
|
||||
/* The final mesh is the result of calculating all enabled modifiers. */
|
||||
Mesh *mesh_final = nullptr;
|
||||
Mesh *mesh = nullptr;
|
||||
/* The result of calculating all leading deform modifiers. */
|
||||
Mesh *mesh_deform = nullptr;
|
||||
/* This geometry set contains the non-mesh data that might be generated by modifiers. */
|
||||
@@ -371,11 +371,11 @@ static void mesh_calc_modifiers(Depsgraph &depsgraph,
|
||||
BKE_modifiers_clear_errors(&ob);
|
||||
|
||||
if (ob.modifier_flag & OB_MODIFIER_FLAG_ADD_REST_POSITION) {
|
||||
if (mesh_final == nullptr) {
|
||||
mesh_final = BKE_mesh_copy_for_eval(mesh_input);
|
||||
ASSERT_IS_VALID_MESH(mesh_final);
|
||||
if (mesh == nullptr) {
|
||||
mesh = BKE_mesh_copy_for_eval(mesh_input);
|
||||
ASSERT_IS_VALID_MESH(mesh);
|
||||
}
|
||||
set_rest_position(*mesh_final);
|
||||
set_rest_position(*mesh);
|
||||
}
|
||||
|
||||
/* Apply all leading deform modifiers. */
|
||||
@@ -389,20 +389,20 @@ static void mesh_calc_modifiers(Depsgraph &depsgraph,
|
||||
|
||||
if (mti->type == ModifierTypeType::OnlyDeform && !sculpt_dyntopo) {
|
||||
ScopedModifierTimer modifier_timer{*md};
|
||||
if (!mesh_final) {
|
||||
mesh_final = BKE_mesh_copy_for_eval(mesh_input);
|
||||
ASSERT_IS_VALID_MESH(mesh_final);
|
||||
if (!mesh) {
|
||||
mesh = BKE_mesh_copy_for_eval(mesh_input);
|
||||
ASSERT_IS_VALID_MESH(mesh);
|
||||
}
|
||||
|
||||
if (mti->required_data_mask) {
|
||||
CustomData_MeshMasks mask{};
|
||||
mti->required_data_mask(md, &mask);
|
||||
if (mask.vmask & CD_MASK_ORCO) {
|
||||
add_orco_mesh(ob, nullptr, *mesh_final, nullptr, CD_ORCO);
|
||||
add_orco_mesh(ob, nullptr, *mesh, nullptr, CD_ORCO);
|
||||
}
|
||||
}
|
||||
|
||||
BKE_modifier_deform_verts(md, &mectx, mesh_final, mesh_final->vert_positions_for_write());
|
||||
BKE_modifier_deform_verts(md, &mectx, mesh, mesh->vert_positions_for_write());
|
||||
}
|
||||
else {
|
||||
break;
|
||||
@@ -413,7 +413,7 @@ static void mesh_calc_modifiers(Depsgraph &depsgraph,
|
||||
* places that wish to use the original mesh but with deformed
|
||||
* coordinates (like vertex paint). */
|
||||
if (r_deform) {
|
||||
mesh_deform = BKE_mesh_copy_for_eval(mesh_final ? *mesh_final : mesh_input);
|
||||
mesh_deform = BKE_mesh_copy_for_eval(mesh ? *mesh : mesh_input);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -475,24 +475,24 @@ static void mesh_calc_modifiers(Depsgraph &depsgraph,
|
||||
ScopedModifierTimer modifier_timer{*md};
|
||||
|
||||
/* Add orco mesh as layer if needed by this modifier. */
|
||||
if (mesh_final && mesh_orco && mti->required_data_mask) {
|
||||
if (mesh && mesh_orco && mti->required_data_mask) {
|
||||
CustomData_MeshMasks mask = {0};
|
||||
mti->required_data_mask(md, &mask);
|
||||
if (mask.vmask & CD_MASK_ORCO) {
|
||||
add_orco_mesh(ob, nullptr, *mesh_final, mesh_orco, CD_ORCO);
|
||||
add_orco_mesh(ob, nullptr, *mesh, mesh_orco, CD_ORCO);
|
||||
}
|
||||
}
|
||||
|
||||
if (mti->type == ModifierTypeType::OnlyDeform) {
|
||||
if (!mesh_final) {
|
||||
mesh_final = BKE_mesh_copy_for_eval(mesh_input);
|
||||
ASSERT_IS_VALID_MESH(mesh_final);
|
||||
if (!mesh) {
|
||||
mesh = BKE_mesh_copy_for_eval(mesh_input);
|
||||
ASSERT_IS_VALID_MESH(mesh);
|
||||
}
|
||||
BKE_modifier_deform_verts(md, &mectx, mesh_final, mesh_final->vert_positions_for_write());
|
||||
BKE_modifier_deform_verts(md, &mectx, mesh, mesh->vert_positions_for_write());
|
||||
}
|
||||
else {
|
||||
bool check_for_needs_mapping = false;
|
||||
if (mesh_final != nullptr) {
|
||||
if (mesh != nullptr) {
|
||||
if (have_non_onlydeform_modifiers_applied == false) {
|
||||
/* If we only deformed, we won't have initialized #CD_ORIGINDEX.
|
||||
* as this is the only part of the function that initializes mapping. */
|
||||
@@ -500,8 +500,8 @@ static void mesh_calc_modifiers(Depsgraph &depsgraph,
|
||||
}
|
||||
}
|
||||
else {
|
||||
mesh_final = BKE_mesh_copy_for_eval(mesh_input);
|
||||
ASSERT_IS_VALID_MESH(mesh_final);
|
||||
mesh = BKE_mesh_copy_for_eval(mesh_input);
|
||||
ASSERT_IS_VALID_MESH(mesh);
|
||||
check_for_needs_mapping = true;
|
||||
}
|
||||
|
||||
@@ -522,26 +522,23 @@ static void mesh_calc_modifiers(Depsgraph &depsgraph,
|
||||
((nextmask.vmask | nextmask.emask | nextmask.pmask) & CD_MASK_ORIGINDEX))
|
||||
{
|
||||
/* calc */
|
||||
CustomData_add_layer(
|
||||
&mesh_final->vert_data, CD_ORIGINDEX, CD_CONSTRUCT, mesh_final->verts_num);
|
||||
CustomData_add_layer(
|
||||
&mesh_final->edge_data, CD_ORIGINDEX, CD_CONSTRUCT, mesh_final->edges_num);
|
||||
CustomData_add_layer(
|
||||
&mesh_final->face_data, CD_ORIGINDEX, CD_CONSTRUCT, mesh_final->faces_num);
|
||||
CustomData_add_layer(&mesh->vert_data, CD_ORIGINDEX, CD_CONSTRUCT, mesh->verts_num);
|
||||
CustomData_add_layer(&mesh->edge_data, CD_ORIGINDEX, CD_CONSTRUCT, mesh->edges_num);
|
||||
CustomData_add_layer(&mesh->face_data, CD_ORIGINDEX, CD_CONSTRUCT, mesh->faces_num);
|
||||
|
||||
/* Not worth parallelizing this,
|
||||
* gives less than 0.1% overall speedup in best of best cases... */
|
||||
range_vn_i((int *)CustomData_get_layer_for_write(
|
||||
&mesh_final->vert_data, CD_ORIGINDEX, mesh_final->verts_num),
|
||||
mesh_final->verts_num,
|
||||
&mesh->vert_data, CD_ORIGINDEX, mesh->verts_num),
|
||||
mesh->verts_num,
|
||||
0);
|
||||
range_vn_i((int *)CustomData_get_layer_for_write(
|
||||
&mesh_final->edge_data, CD_ORIGINDEX, mesh_final->edges_num),
|
||||
mesh_final->edges_num,
|
||||
&mesh->edge_data, CD_ORIGINDEX, mesh->edges_num),
|
||||
mesh->edges_num,
|
||||
0);
|
||||
range_vn_i((int *)CustomData_get_layer_for_write(
|
||||
&mesh_final->face_data, CD_ORIGINDEX, mesh_final->faces_num),
|
||||
mesh_final->faces_num,
|
||||
&mesh->face_data, CD_ORIGINDEX, mesh->faces_num),
|
||||
mesh->faces_num,
|
||||
0);
|
||||
}
|
||||
}
|
||||
@@ -556,35 +553,32 @@ static void mesh_calc_modifiers(Depsgraph &depsgraph,
|
||||
mask.emask |= CD_MASK_ORIGINDEX;
|
||||
mask.pmask |= CD_MASK_ORIGINDEX;
|
||||
}
|
||||
mesh_set_only_copy(mesh_final, &mask);
|
||||
mesh_set_only_copy(mesh, &mask);
|
||||
|
||||
/* add cloth rest shape key if needed */
|
||||
if (mask.vmask & CD_MASK_CLOTH_ORCO) {
|
||||
add_orco_mesh(ob, nullptr, *mesh_final, mesh_orco, CD_CLOTH_ORCO);
|
||||
add_orco_mesh(ob, nullptr, *mesh, mesh_orco, CD_CLOTH_ORCO);
|
||||
}
|
||||
|
||||
/* add an origspace layer if needed */
|
||||
if ((md_datamask->mask.lmask) & CD_MASK_ORIGSPACE_MLOOP) {
|
||||
if (!CustomData_has_layer(&mesh_final->corner_data, CD_ORIGSPACE_MLOOP)) {
|
||||
CustomData_add_layer(&mesh_final->corner_data,
|
||||
CD_ORIGSPACE_MLOOP,
|
||||
CD_SET_DEFAULT,
|
||||
mesh_final->corners_num);
|
||||
mesh_init_origspace(*mesh_final);
|
||||
if (!CustomData_has_layer(&mesh->corner_data, CD_ORIGSPACE_MLOOP)) {
|
||||
CustomData_add_layer(
|
||||
&mesh->corner_data, CD_ORIGSPACE_MLOOP, CD_SET_DEFAULT, mesh->corners_num);
|
||||
mesh_init_origspace(*mesh);
|
||||
}
|
||||
}
|
||||
|
||||
Mesh *mesh_next = modifier_modify_mesh_and_geometry_set(
|
||||
md, mectx, mesh_final, geometry_set_final);
|
||||
Mesh *mesh_next = modifier_modify_mesh_and_geometry_set(md, mectx, mesh, geometry_set_final);
|
||||
ASSERT_IS_VALID_MESH(mesh_next);
|
||||
|
||||
if (mesh_next) {
|
||||
/* if the modifier returned a new mesh, release the old one */
|
||||
if (mesh_final != mesh_next) {
|
||||
BLI_assert(mesh_final != &mesh_input);
|
||||
BKE_id_free(nullptr, mesh_final);
|
||||
if (mesh != mesh_next) {
|
||||
BLI_assert(mesh != &mesh_input);
|
||||
BKE_id_free(nullptr, mesh);
|
||||
}
|
||||
mesh_final = mesh_next;
|
||||
mesh = mesh_next;
|
||||
}
|
||||
|
||||
/* create an orco mesh in parallel */
|
||||
@@ -646,7 +640,7 @@ static void mesh_calc_modifiers(Depsgraph &depsgraph,
|
||||
}
|
||||
}
|
||||
|
||||
mesh_final->runtime->deformed_only = false;
|
||||
mesh->runtime->deformed_only = false;
|
||||
}
|
||||
|
||||
if (sculpt_mode && md->type == eModifierType_Multires) {
|
||||
@@ -660,25 +654,25 @@ static void mesh_calc_modifiers(Depsgraph &depsgraph,
|
||||
BKE_modifier_free_temporary_data(md);
|
||||
}
|
||||
|
||||
if (mesh_final == nullptr) {
|
||||
if (mesh == nullptr) {
|
||||
if (allow_shared_mesh) {
|
||||
mesh_final = &mesh_input;
|
||||
mesh = &mesh_input;
|
||||
}
|
||||
else {
|
||||
mesh_final = BKE_mesh_copy_for_eval(mesh_input);
|
||||
mesh = BKE_mesh_copy_for_eval(mesh_input);
|
||||
}
|
||||
}
|
||||
|
||||
/* Denotes whether the object which the modifier stack came from owns the mesh or whether the
|
||||
* mesh is shared across multiple objects since there are no effective modifiers. */
|
||||
const bool is_own_mesh = (mesh_final != &mesh_input);
|
||||
const bool is_own_mesh = (mesh != &mesh_input);
|
||||
|
||||
/* Add orco coordinates to final and deformed mesh if requested. */
|
||||
if (final_datamask.vmask & CD_MASK_ORCO) {
|
||||
/* No need in ORCO layer if the mesh was not deformed or modified: undeformed mesh in this case
|
||||
* matches input mesh. */
|
||||
if (is_own_mesh) {
|
||||
add_orco_mesh(ob, nullptr, *mesh_final, mesh_orco, CD_ORCO);
|
||||
add_orco_mesh(ob, nullptr, *mesh, mesh_orco, CD_ORCO);
|
||||
}
|
||||
|
||||
if (mesh_deform) {
|
||||
@@ -695,11 +689,11 @@ static void mesh_calc_modifiers(Depsgraph &depsgraph,
|
||||
|
||||
/* Remove temporary data layer only needed for modifier evaluation.
|
||||
* Save some memory, and ensure GPU subdivision does not need to deal with this. */
|
||||
CustomData_free_layers(&mesh_final->vert_data, CD_CLOTH_ORCO, mesh_final->verts_num);
|
||||
CustomData_free_layers(&mesh->vert_data, CD_CLOTH_ORCO, mesh->verts_num);
|
||||
|
||||
/* Compute normals. */
|
||||
if (is_own_mesh) {
|
||||
mesh_calc_finalize(mesh_input, *mesh_final);
|
||||
mesh_calc_finalize(mesh_input, *mesh);
|
||||
}
|
||||
else {
|
||||
MeshRuntime *runtime = mesh_input.runtime;
|
||||
@@ -709,24 +703,24 @@ static void mesh_calc_modifiers(Depsgraph &depsgraph,
|
||||
/* Not yet finalized by any instance, do it now
|
||||
* Isolate since computing normals is multithreaded and we are holding a lock. */
|
||||
threading::isolate_task([&] {
|
||||
mesh_final = BKE_mesh_copy_for_eval(mesh_input);
|
||||
mesh_calc_finalize(mesh_input, *mesh_final);
|
||||
runtime->mesh_eval = mesh_final;
|
||||
mesh = BKE_mesh_copy_for_eval(mesh_input);
|
||||
mesh_calc_finalize(mesh_input, *mesh);
|
||||
runtime->mesh_eval = mesh;
|
||||
});
|
||||
}
|
||||
else {
|
||||
/* Already finalized by another instance, reuse. */
|
||||
mesh_final = runtime->mesh_eval;
|
||||
mesh = runtime->mesh_eval;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Already finalized by another instance, reuse. */
|
||||
mesh_final = runtime->mesh_eval;
|
||||
mesh = runtime->mesh_eval;
|
||||
}
|
||||
}
|
||||
|
||||
/* Return final mesh */
|
||||
*r_final = mesh_final;
|
||||
*r_final = mesh;
|
||||
if (r_deform) {
|
||||
*r_deform = mesh_deform;
|
||||
}
|
||||
@@ -816,12 +810,12 @@ static void editbmesh_calc_modifiers(Depsgraph &depsgraph,
|
||||
CDMaskLink *md_datamask = datamasks;
|
||||
CustomData_MeshMasks append_mask = CD_MASK_BAREMESH;
|
||||
|
||||
Mesh *mesh_final = BKE_mesh_wrapper_from_editmesh(
|
||||
Mesh *mesh = BKE_mesh_wrapper_from_editmesh(
|
||||
mesh_input.runtime->edit_mesh, &final_datamask, &mesh_input);
|
||||
|
||||
int cageIndex = BKE_modifiers_get_cage_index(&scene, &ob, nullptr, true);
|
||||
if (r_cage && cageIndex == -1) {
|
||||
mesh_cage = mesh_final;
|
||||
mesh_cage = mesh;
|
||||
}
|
||||
|
||||
/* The mesh from edit mode should not have any original index layers already, since those
|
||||
@@ -834,8 +828,8 @@ static void editbmesh_calc_modifiers(Depsgraph &depsgraph,
|
||||
BKE_modifiers_clear_errors(&ob);
|
||||
|
||||
if (ob.modifier_flag & OB_MODIFIER_FLAG_ADD_REST_POSITION) {
|
||||
BKE_mesh_wrapper_ensure_mdata(mesh_final);
|
||||
set_rest_position(*mesh_final);
|
||||
BKE_mesh_wrapper_ensure_mdata(mesh);
|
||||
set_rest_position(*mesh);
|
||||
}
|
||||
|
||||
bool non_deform_modifier_applied = false;
|
||||
@@ -852,20 +846,20 @@ static void editbmesh_calc_modifiers(Depsgraph &depsgraph,
|
||||
CustomData_MeshMasks mask = {0};
|
||||
mti->required_data_mask(md, &mask);
|
||||
if (mask.vmask & CD_MASK_ORCO) {
|
||||
add_orco_mesh(ob, &em_input, *mesh_final, mesh_orco, CD_ORCO);
|
||||
add_orco_mesh(ob, &em_input, *mesh, mesh_orco, CD_ORCO);
|
||||
}
|
||||
}
|
||||
|
||||
if (mesh_final == mesh_cage) {
|
||||
if (mesh == mesh_cage) {
|
||||
/* If the cage mesh has already been assigned, we have passed the cage index in the modifier
|
||||
* list. If the cage and final meshes are still the same, duplicate the final mesh so the
|
||||
* cage mesh isn't modified anymore. */
|
||||
mesh_final = BKE_mesh_copy_for_eval(*mesh_final);
|
||||
mesh = BKE_mesh_copy_for_eval(*mesh);
|
||||
if (mesh_cage->runtime->edit_mesh) {
|
||||
mesh_final->runtime->edit_mesh = mesh_cage->runtime->edit_mesh;
|
||||
mesh_final->runtime->is_original_bmesh = true;
|
||||
mesh->runtime->edit_mesh = mesh_cage->runtime->edit_mesh;
|
||||
mesh->runtime->is_original_bmesh = true;
|
||||
if (mesh_cage->runtime->edit_data) {
|
||||
mesh_final->runtime->edit_data = std::make_unique<EditMeshData>(
|
||||
mesh->runtime->edit_data = std::make_unique<EditMeshData>(
|
||||
*mesh_cage->runtime->edit_data);
|
||||
}
|
||||
}
|
||||
@@ -873,17 +867,14 @@ static void editbmesh_calc_modifiers(Depsgraph &depsgraph,
|
||||
|
||||
if (mti->type == ModifierTypeType::OnlyDeform) {
|
||||
if (mti->deform_verts_EM) {
|
||||
BKE_modifier_deform_vertsEM(md,
|
||||
&mectx,
|
||||
&em_input,
|
||||
mesh_final,
|
||||
mesh_wrapper_vert_coords_ensure_for_write(mesh_final));
|
||||
BKE_mesh_wrapper_tag_positions_changed(mesh_final);
|
||||
BKE_modifier_deform_vertsEM(
|
||||
md, &mectx, &em_input, mesh, mesh_wrapper_vert_coords_ensure_for_write(mesh));
|
||||
BKE_mesh_wrapper_tag_positions_changed(mesh);
|
||||
}
|
||||
else {
|
||||
BKE_mesh_wrapper_ensure_mdata(mesh_final);
|
||||
BKE_modifier_deform_verts(md, &mectx, mesh_final, mesh_final->vert_positions_for_write());
|
||||
mesh_final->tag_positions_changed();
|
||||
BKE_mesh_wrapper_ensure_mdata(mesh);
|
||||
BKE_modifier_deform_verts(md, &mectx, mesh, mesh->vert_positions_for_write());
|
||||
mesh->tag_positions_changed();
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -923,33 +914,30 @@ static void editbmesh_calc_modifiers(Depsgraph &depsgraph,
|
||||
mask.emask |= CD_MASK_ORIGINDEX;
|
||||
mask.pmask |= CD_MASK_ORIGINDEX;
|
||||
|
||||
mesh_set_only_copy(mesh_final, &mask);
|
||||
mesh_set_only_copy(mesh, &mask);
|
||||
|
||||
if (mask.lmask & CD_MASK_ORIGSPACE_MLOOP) {
|
||||
if (!CustomData_has_layer(&mesh_final->corner_data, CD_ORIGSPACE_MLOOP)) {
|
||||
CustomData_add_layer(&mesh_final->corner_data,
|
||||
CD_ORIGSPACE_MLOOP,
|
||||
CD_SET_DEFAULT,
|
||||
mesh_final->corners_num);
|
||||
mesh_init_origspace(*mesh_final);
|
||||
if (!CustomData_has_layer(&mesh->corner_data, CD_ORIGSPACE_MLOOP)) {
|
||||
CustomData_add_layer(
|
||||
&mesh->corner_data, CD_ORIGSPACE_MLOOP, CD_SET_DEFAULT, mesh->corners_num);
|
||||
mesh_init_origspace(*mesh);
|
||||
}
|
||||
}
|
||||
|
||||
Mesh *mesh_next = modifier_modify_mesh_and_geometry_set(
|
||||
md, mectx, mesh_final, geometry_set_final);
|
||||
Mesh *mesh_next = modifier_modify_mesh_and_geometry_set(md, mectx, mesh, geometry_set_final);
|
||||
ASSERT_IS_VALID_MESH(mesh_next);
|
||||
|
||||
if (mesh_next) {
|
||||
if (mesh_final != mesh_next) {
|
||||
BKE_id_free(nullptr, mesh_final);
|
||||
if (mesh != mesh_next) {
|
||||
BKE_id_free(nullptr, mesh);
|
||||
}
|
||||
mesh_final = mesh_next;
|
||||
mesh = mesh_next;
|
||||
}
|
||||
mesh_final->runtime->deformed_only = false;
|
||||
mesh->runtime->deformed_only = false;
|
||||
}
|
||||
|
||||
if (r_cage && i == cageIndex) {
|
||||
mesh_cage = mesh_final;
|
||||
mesh_cage = mesh;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -958,9 +946,9 @@ static void editbmesh_calc_modifiers(Depsgraph &depsgraph,
|
||||
/* Add orco coordinates to final and deformed mesh if requested. */
|
||||
if (final_datamask.vmask & CD_MASK_ORCO) {
|
||||
/* FIXME(@ideasman42): avoid the need to convert to mesh data just to add an orco layer. */
|
||||
BKE_mesh_wrapper_ensure_mdata(mesh_final);
|
||||
BKE_mesh_wrapper_ensure_mdata(mesh);
|
||||
|
||||
add_orco_mesh(ob, &em_input, *mesh_final, mesh_orco, CD_ORCO);
|
||||
add_orco_mesh(ob, &em_input, *mesh, mesh_orco, CD_ORCO);
|
||||
}
|
||||
|
||||
if (mesh_orco) {
|
||||
@@ -968,7 +956,7 @@ static void editbmesh_calc_modifiers(Depsgraph &depsgraph,
|
||||
}
|
||||
|
||||
/* Return final mesh. */
|
||||
*r_final = mesh_final;
|
||||
*r_final = mesh;
|
||||
if (r_cage) {
|
||||
*r_cage = mesh_cage;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user