Mesh: Remove unnecessary mesh position copying #105756
|
@ -743,11 +743,9 @@ static GeometrySet curve_calc_modifiers_post(Depsgraph *depsgraph,
|
|||
Mesh *mesh = geometry_set.get_mesh_for_write();
|
||||
|
||||
if (mti->type == eModifierTypeType_OnlyDeform) {
|
||||
int totvert;
|
||||
float(*vertex_coords)[3] = BKE_mesh_vert_coords_alloc(mesh, &totvert);
|
||||
mti->deformVerts(md, &mectx_deform, mesh, vertex_coords, totvert);
|
||||
BKE_mesh_vert_coords_apply(mesh, vertex_coords);
|
||||
MEM_freeN(vertex_coords);
|
||||
mti->deformVerts(
|
||||
md, &mectx_deform, mesh, BKE_mesh_vert_positions_for_write(mesh), mesh->totvert);
|
||||
sixthat marked this conversation as resolved
|
||||
BKE_mesh_tag_positions_changed(mesh);
|
||||
}
|
||||
else {
|
||||
Mesh *output_mesh = mti->modifyMesh(md, &mectx_apply, mesh);
|
||||
|
|
|
@ -685,11 +685,9 @@ void BKE_mball_data_update(Depsgraph *depsgraph, Scene *scene, Object *ob)
|
|||
mesh->totcol = mball->totcol;
|
||||
|
||||
if (ob->parent && ob->parent->type == OB_LATTICE && ob->partype == PARSKEL) {
|
||||
int verts_num;
|
||||
float(*positions)[3] = BKE_mesh_vert_coords_alloc(mesh, &verts_num);
|
||||
BKE_lattice_deform_coords(ob->parent, ob, positions, verts_num, 0, nullptr, 1.0f);
|
||||
BKE_mesh_vert_coords_apply(mesh, positions);
|
||||
MEM_freeN(positions);
|
||||
BKE_lattice_deform_coords(
|
||||
ob->parent, ob, BKE_mesh_vert_positions_for_write(mesh), mesh->totvert, 0, nullptr, 1.0f);
|
||||
BKE_mesh_tag_positions_changed(mesh);
|
||||
}
|
||||
|
||||
ob->runtime.geometry_set_eval = new GeometrySet(GeometrySet::create_with_mesh(mesh));
|
||||
|
|
|
@ -262,9 +262,8 @@ void BKE_mesh_remap_find_best_match_from_mesh(const float (*vert_positions_dst)[
|
|||
float best_match = FLT_MAX, match;
|
||||
|
||||
const int numverts_src = me_src->totvert;
|
||||
float(*vcos_src)[3] = BKE_mesh_vert_coords_alloc(me_src, nullptr);
|
||||
|
||||
mesh_calc_eigen_matrix(nullptr, (const float(*)[3])vcos_src, numverts_src, mat_src);
|
||||
const float(*vcos_src)[3] = BKE_mesh_vert_positions(me_src);
|
||||
mesh_calc_eigen_matrix(nullptr, vcos_src, numverts_src, mat_src);
|
||||
mesh_calc_eigen_matrix(vert_positions_dst, nullptr, numverts_dst, mat_dst);
|
||||
|
||||
BLI_space_transform_global_from_matrices(r_space_transform, mat_dst, mat_src);
|
||||
|
@ -289,8 +288,6 @@ void BKE_mesh_remap_find_best_match_from_mesh(const float (*vert_positions_dst)[
|
|||
}
|
||||
|
||||
BLI_space_transform_global_from_matrices(r_space_transform, best_mat_dst, mat_src);
|
||||
|
||||
MEM_freeN(vcos_src);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
@ -516,7 +513,7 @@ void BKE_mesh_remap_calc_verts_from_mesh(const int mode,
|
|||
}
|
||||
else if (ELEM(mode, MREMAP_MODE_VERT_EDGE_NEAREST, MREMAP_MODE_VERT_EDGEINTERP_NEAREST)) {
|
||||
const blender::Span<MEdge> edges_src = me_src->edges();
|
||||
float(*vcos_src)[3] = BKE_mesh_vert_coords_alloc(me_src, nullptr);
|
||||
const float(*vcos_src)[3] = BKE_mesh_vert_positions(me_src);
|
||||
|
||||
BKE_bvhtree_from_mesh_get(&treedata, me_src, BVHTREE_FROM_EDGES, 2);
|
||||
nearest.index = -1;
|
||||
|
@ -561,8 +558,6 @@ void BKE_mesh_remap_calc_verts_from_mesh(const int mode,
|
|||
BKE_mesh_remap_item_define_invalid(r_map, i);
|
||||
}
|
||||
}
|
||||
|
||||
MEM_freeN(vcos_src);
|
||||
}
|
||||
else if (ELEM(mode,
|
||||
MREMAP_MODE_VERT_POLY_NEAREST,
|
||||
|
@ -570,7 +565,7 @@ void BKE_mesh_remap_calc_verts_from_mesh(const int mode,
|
|||
MREMAP_MODE_VERT_POLYINTERP_VNORPROJ)) {
|
||||
const blender::Span<MPoly> polys_src = me_src->polys();
|
||||
const blender::Span<MLoop> loops_src = me_src->loops();
|
||||
float(*vcos_src)[3] = BKE_mesh_vert_coords_alloc(me_src, nullptr);
|
||||
const float(*vcos_src)[3] = BKE_mesh_vert_positions(me_src);
|
||||
const blender::Span<blender::float3> vert_normals_dst = me_dst->vert_normals();
|
||||
|
||||
size_t tmp_buff_size = MREMAP_DEFAULT_BUFSIZE;
|
||||
|
@ -598,7 +593,7 @@ void BKE_mesh_remap_calc_verts_from_mesh(const int mode,
|
|||
const MLoopTri *lt = &treedata.looptri[rayhit.index];
|
||||
const int sources_num = mesh_remap_interp_poly_data_get(polys_src[lt->poly],
|
||||
loops_src,
|
||||
(const float(*)[3])vcos_src,
|
||||
vcos_src,
|
||||
rayhit.co,
|
||||
&tmp_buff_size,
|
||||
&vcos,
|
||||
|
@ -635,7 +630,7 @@ void BKE_mesh_remap_calc_verts_from_mesh(const int mode,
|
|||
int index;
|
||||
mesh_remap_interp_poly_data_get(polys_src[lt->poly],
|
||||
loops_src,
|
||||
(const float(*)[3])vcos_src,
|
||||
vcos_src,
|
||||
nearest.co,
|
||||
&tmp_buff_size,
|
||||
&vcos,
|
||||
|
@ -650,7 +645,7 @@ void BKE_mesh_remap_calc_verts_from_mesh(const int mode,
|
|||
else if (mode == MREMAP_MODE_VERT_POLYINTERP_NEAREST) {
|
||||
const int sources_num = mesh_remap_interp_poly_data_get(polys_src[lt->poly],
|
||||
loops_src,
|
||||
(const float(*)[3])vcos_src,
|
||||
vcos_src,
|
||||
nearest.co,
|
||||
&tmp_buff_size,
|
||||
&vcos,
|
||||
|
@ -670,7 +665,6 @@ void BKE_mesh_remap_calc_verts_from_mesh(const int mode,
|
|||
}
|
||||
}
|
||||
|
||||
MEM_freeN(vcos_src);
|
||||
MEM_freeN(vcos);
|
||||
MEM_freeN(indices);
|
||||
MEM_freeN(weights);
|
||||
|
@ -721,7 +715,7 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode,
|
|||
if (mode == MREMAP_MODE_EDGE_VERT_NEAREST) {
|
||||
const int num_verts_src = me_src->totvert;
|
||||
const blender::Span<MEdge> edges_src = me_src->edges();
|
||||
float(*vcos_src)[3] = BKE_mesh_vert_coords_alloc(me_src, nullptr);
|
||||
const float(*vcos_src)[3] = BKE_mesh_vert_positions(me_src);
|
||||
|
||||
MeshElemMap *vert_to_edge_src_map;
|
||||
int *vert_to_edge_src_map_mem;
|
||||
|
@ -840,7 +834,6 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode,
|
|||
}
|
||||
}
|
||||
|
||||
MEM_freeN(vcos_src);
|
||||
MEM_freeN(v_dst_to_src_map);
|
||||
MEM_freeN(vert_to_edge_src_map);
|
||||
MEM_freeN(vert_to_edge_src_map_mem);
|
||||
|
@ -874,7 +867,7 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode,
|
|||
const blender::Span<MEdge> edges_src = me_src->edges();
|
||||
const blender::Span<MPoly> polys_src = me_src->polys();
|
||||
const blender::Span<MLoop> loops_src = me_src->loops();
|
||||
float(*vcos_src)[3] = BKE_mesh_vert_coords_alloc(me_src, nullptr);
|
||||
const float(*vcos_src)[3] = BKE_mesh_vert_positions(me_src);
|
||||
|
||||
BKE_bvhtree_from_mesh_get(&treedata, me_src, BVHTREE_FROM_LOOPTRI, 2);
|
||||
|
||||
|
@ -900,8 +893,8 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode,
|
|||
|
||||
for (; nloops--; ml_src++) {
|
||||
const MEdge *edge_src = &edges_src[ml_src->e];
|
||||
float *co1_src = vcos_src[edge_src->v1];
|
||||
float *co2_src = vcos_src[edge_src->v2];
|
||||
const float *co1_src = vcos_src[edge_src->v1];
|
||||
const float *co2_src = vcos_src[edge_src->v2];
|
||||
float co_src[3];
|
||||
float dist_sq;
|
||||
|
||||
|
@ -921,8 +914,6 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode,
|
|||
BKE_mesh_remap_item_define_invalid(r_map, i);
|
||||
}
|
||||
}
|
||||
|
||||
MEM_freeN(vcos_src);
|
||||
}
|
||||
else if (mode == MREMAP_MODE_EDGE_EDGEINTERP_VNORPROJ) {
|
||||
const int num_rays_min = 5, num_rays_max = 100;
|
||||
|
@ -1308,7 +1299,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
|
|||
|
||||
const blender::Span<blender::float3> positions_src = me_src->vert_positions();
|
||||
const int num_verts_src = me_src->totvert;
|
||||
float(*vcos_src)[3] = nullptr;
|
||||
const float(*vcos_src)[3] = nullptr;
|
||||
const blender::Span<MEdge> edges_src = me_src->edges();
|
||||
const blender::Span<MPoly> polys_src = me_src->polys();
|
||||
const blender::Span<MLoop> loops_src = me_src->loops();
|
||||
|
@ -1328,7 +1319,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
|
|||
size_t islands_res_buff_size = MREMAP_DEFAULT_BUFSIZE;
|
||||
|
||||
if (!use_from_vert) {
|
||||
vcos_src = BKE_mesh_vert_coords_alloc(me_src, nullptr);
|
||||
vcos_src = BKE_mesh_vert_positions(me_src);
|
||||
|
||||
vcos_interp = static_cast<float(*)[3]>(
|
||||
MEM_mallocN(sizeof(*vcos_interp) * buff_size_interp, __func__));
|
||||
|
@ -2041,7 +2032,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
|
|||
if (mode == MREMAP_MODE_LOOP_POLY_NEAREST) {
|
||||
mesh_remap_interp_poly_data_get(poly,
|
||||
loops_src,
|
||||
(const float(*)[3])vcos_src,
|
||||
vcos_src,
|
||||
hit_co,
|
||||
&buff_size_interp,
|
||||
&vcos_interp,
|
||||
|
@ -2060,18 +2051,17 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
|
|||
&full_weight);
|
||||
}
|
||||
else {
|
||||
const int sources_num = mesh_remap_interp_poly_data_get(
|
||||
poly,
|
||||
loops_src,
|
||||
(const float(*)[3])vcos_src,
|
||||
hit_co,
|
||||
&buff_size_interp,
|
||||
&vcos_interp,
|
||||
true,
|
||||
&indices_interp,
|
||||
&weights_interp,
|
||||
true,
|
||||
nullptr);
|
||||
const int sources_num = mesh_remap_interp_poly_data_get(poly,
|
||||
loops_src,
|
||||
vcos_src,
|
||||
hit_co,
|
||||
&buff_size_interp,
|
||||
&vcos_interp,
|
||||
true,
|
||||
&indices_interp,
|
||||
&weights_interp,
|
||||
true,
|
||||
nullptr);
|
||||
|
||||
mesh_remap_item_define(r_map,
|
||||
lidx_dst,
|
||||
|
@ -2113,9 +2103,6 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
|
|||
BLI_astar_solution_free(&as_solution);
|
||||
}
|
||||
|
||||
if (vcos_src) {
|
||||
MEM_freeN(vcos_src);
|
||||
}
|
||||
if (vert_to_loop_map_src) {
|
||||
MEM_freeN(vert_to_loop_map_src);
|
||||
}
|
||||
|
|
|
@ -2204,10 +2204,8 @@ static PBVH *build_pbvh_from_regular_mesh(Object *ob, Mesh *me_eval_deform, bool
|
|||
|
||||
const bool is_deformed = check_sculpt_object_deformed(ob, true);
|
||||
if (is_deformed && me_eval_deform != nullptr) {
|
||||
int totvert;
|
||||
float(*v_cos)[3] = BKE_mesh_vert_coords_alloc(me_eval_deform, &totvert);
|
||||
BKE_pbvh_vert_coords_apply(pbvh, v_cos, totvert);
|
||||
MEM_freeN(v_cos);
|
||||
BKE_pbvh_vert_coords_apply(
|
||||
pbvh, BKE_mesh_vert_positions(me_eval_deform), me_eval_deform->totvert);
|
||||
}
|
||||
|
||||
return pbvh;
|
||||
|
|
|
@ -1530,7 +1530,6 @@ void BKE_shrinkwrap_mesh_nearest_surface_deform(bContext *C, Object *ob_source,
|
|||
Scene *sce = CTX_data_scene(C);
|
||||
ShrinkwrapModifierData ssmd = {{nullptr}};
|
||||
ModifierEvalContext ctx = {depsgraph, ob_source, ModifierApplyFlag(0)};
|
||||
int totvert;
|
||||
|
||||
ssmd.target = ob_target;
|
||||
ssmd.shrinkType = MOD_SHRINKWRAP_NEAREST_SURFACE;
|
||||
|
@ -1538,13 +1537,17 @@ void BKE_shrinkwrap_mesh_nearest_surface_deform(bContext *C, Object *ob_source,
|
|||
ssmd.keepDist = 0.0f;
|
||||
|
||||
Mesh *src_me = static_cast<Mesh *>(ob_source->data);
|
||||
float(*vertexCos)[3] = BKE_mesh_vert_coords_alloc(src_me, &totvert);
|
||||
|
||||
shrinkwrapModifier_deform(&ssmd, &ctx, sce, ob_source, src_me, nullptr, -1, vertexCos, totvert);
|
||||
|
||||
BKE_mesh_vert_coords_apply(src_me, vertexCos);
|
||||
|
||||
MEM_freeN(vertexCos);
|
||||
shrinkwrapModifier_deform(&ssmd,
|
||||
&ctx,
|
||||
sce,
|
||||
ob_source,
|
||||
src_me,
|
||||
nullptr,
|
||||
-1,
|
||||
BKE_mesh_vert_positions_for_write(src_me),
|
||||
src_me->totvert);
|
||||
sixthat marked this conversation as resolved
Hans Goudey
commented
Same here Same here
|
||||
BKE_mesh_tag_positions_changed(src_me);
|
||||
}
|
||||
|
||||
void BKE_shrinkwrap_remesh_target_project(Mesh *src_me, Mesh *target_me, Object *ob_target)
|
||||
|
|
|
@ -516,12 +516,11 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
|
|||
|
||||
/* Get our vertex coordinates. */
|
||||
if (index_num != verts_num) {
|
||||
float(*tv_cos)[3] = BKE_mesh_vert_coords_alloc(mesh, nullptr);
|
||||
const float(*tv_cos)[3] = BKE_mesh_vert_positions(mesh);
|
||||
v_cos = static_cast<float(*)[3]>(MEM_malloc_arrayN(index_num, sizeof(float[3]), __func__));
|
||||
for (i = 0; i < index_num; i++) {
|
||||
copy_v3_v3(v_cos[i], tv_cos[indices[i]]);
|
||||
}
|
||||
MEM_freeN(tv_cos);
|
||||
}
|
||||
else {
|
||||
v_cos = BKE_mesh_vert_coords_alloc(mesh, nullptr);
|
||||
|
|
Loading…
Reference in New Issue
This needs a call to
BKE_mesh_tag_positions_changed
, otherwise various caches that depend on mesh positions won't be properly updated after the deformation.