Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--intern/cycles/blender/mesh.cpp18
m---------release/datafiles/locale0
m---------release/scripts/addons0
-rw-r--r--release/scripts/startup/bl_ui/properties_data_mesh.py2
-rw-r--r--source/blender/blenkernel/BKE_DerivedMesh.h8
-rw-r--r--source/blender/blenkernel/BKE_bvhutils.h9
-rw-r--r--source/blender/blenkernel/BKE_collision.h7
-rw-r--r--source/blender/blenkernel/BKE_key.h3
-rw-r--r--source/blender/blenkernel/BKE_mesh.h51
-rw-r--r--source/blender/blenkernel/BKE_mesh_fair.h6
-rw-r--r--source/blender/blenkernel/BKE_mesh_legacy_convert.h11
-rw-r--r--source/blender/blenkernel/BKE_mesh_mapping.h8
-rw-r--r--source/blender/blenkernel/BKE_mesh_remap.h13
-rw-r--r--source/blender/blenkernel/BKE_mesh_sample.hh2
-rw-r--r--source/blender/blenkernel/BKE_mesh_tangent.h4
-rw-r--r--source/blender/blenkernel/BKE_mesh_types.h2
-rw-r--r--source/blender/blenkernel/BKE_multires.h4
-rw-r--r--source/blender/blenkernel/BKE_paint.h3
-rw-r--r--source/blender/blenkernel/BKE_particle.h3
-rw-r--r--source/blender/blenkernel/BKE_pbvh.h19
-rw-r--r--source/blender/blenkernel/BKE_subdiv.h2
-rw-r--r--source/blender/blenkernel/BKE_subdiv_mesh.h3
-rw-r--r--source/blender/blenkernel/BKE_volume_to_mesh.hh2
-rw-r--r--source/blender/blenkernel/intern/DerivedMesh.cc38
-rw-r--r--source/blender/blenkernel/intern/attribute.cc3
-rw-r--r--source/blender/blenkernel/intern/attribute_access_intern.hh3
-rw-r--r--source/blender/blenkernel/intern/bvhutils.cc122
-rw-r--r--source/blender/blenkernel/intern/cdderivedmesh.c12
-rw-r--r--source/blender/blenkernel/intern/cloth.c21
-rw-r--r--source/blender/blenkernel/intern/collision.c72
-rw-r--r--source/blender/blenkernel/intern/constraint.c5
-rw-r--r--source/blender/blenkernel/intern/crazyspace.cc8
-rw-r--r--source/blender/blenkernel/intern/curve_to_mesh_convert.cc13
-rw-r--r--source/blender/blenkernel/intern/customdata.cc13
-rw-r--r--source/blender/blenkernel/intern/data_transfer.c28
-rw-r--r--source/blender/blenkernel/intern/dynamicpaint.c104
-rw-r--r--source/blender/blenkernel/intern/effect.c10
-rw-r--r--source/blender/blenkernel/intern/fluid.c92
-rw-r--r--source/blender/blenkernel/intern/geometry_component_mesh.cc33
-rw-r--r--source/blender/blenkernel/intern/gpencil_geom.cc19
-rw-r--r--source/blender/blenkernel/intern/key.c42
-rw-r--r--source/blender/blenkernel/intern/mball_tessellate.cc11
-rw-r--r--source/blender/blenkernel/intern/mesh.cc113
-rw-r--r--source/blender/blenkernel/intern/mesh_boolean_convert.cc61
-rw-r--r--source/blender/blenkernel/intern/mesh_convert.cc50
-rw-r--r--source/blender/blenkernel/intern/mesh_evaluate.cc141
-rw-r--r--source/blender/blenkernel/intern/mesh_fair.cc19
-rw-r--r--source/blender/blenkernel/intern/mesh_iterators.cc41
-rw-r--r--source/blender/blenkernel/intern/mesh_legacy_convert.cc89
-rw-r--r--source/blender/blenkernel/intern/mesh_mapping.cc15
-rw-r--r--source/blender/blenkernel/intern/mesh_merge.c20
-rw-r--r--source/blender/blenkernel/intern/mesh_mirror.c34
-rw-r--r--source/blender/blenkernel/intern/mesh_normals.cc116
-rw-r--r--source/blender/blenkernel/intern/mesh_remap.c103
-rw-r--r--source/blender/blenkernel/intern/mesh_remesh_voxel.cc45
-rw-r--r--source/blender/blenkernel/intern/mesh_runtime.cc13
-rw-r--r--source/blender/blenkernel/intern/mesh_sample.cc36
-rw-r--r--source/blender/blenkernel/intern/mesh_tangent.cc52
-rw-r--r--source/blender/blenkernel/intern/mesh_tessellate.cc62
-rw-r--r--source/blender/blenkernel/intern/mesh_validate.cc24
-rw-r--r--source/blender/blenkernel/intern/mesh_wrapper.cc11
-rw-r--r--source/blender/blenkernel/intern/modifier.cc4
-rw-r--r--source/blender/blenkernel/intern/multires.cc5
-rw-r--r--source/blender/blenkernel/intern/multires_reshape.h3
-rw-r--r--source/blender/blenkernel/intern/multires_reshape_apply_base.c17
-rw-r--r--source/blender/blenkernel/intern/multires_reshape_subdivide.c10
-rw-r--r--source/blender/blenkernel/intern/multires_reshape_util.c8
-rw-r--r--source/blender/blenkernel/intern/object.cc34
-rw-r--r--source/blender/blenkernel/intern/object_dupli.cc34
-rw-r--r--source/blender/blenkernel/intern/paint.cc23
-rw-r--r--source/blender/blenkernel/intern/particle.c59
-rw-r--r--source/blender/blenkernel/intern/particle_distribute.c69
-rw-r--r--source/blender/blenkernel/intern/particle_system.c35
-rw-r--r--source/blender/blenkernel/intern/pbvh.c88
-rw-r--r--source/blender/blenkernel/intern/pbvh_intern.h5
-rw-r--r--source/blender/blenkernel/intern/rigidbody.c27
-rw-r--r--source/blender/blenkernel/intern/shrinkwrap.cc47
-rw-r--r--source/blender/blenkernel/intern/softbody.c156
-rw-r--r--source/blender/blenkernel/intern/subdiv_converter_mesh.c4
-rw-r--r--source/blender/blenkernel/intern/subdiv_eval.c6
-rw-r--r--source/blender/blenkernel/intern/subdiv_mesh.cc96
-rw-r--r--source/blender/blenkernel/intern/subsurf_ccg.c24
-rw-r--r--source/blender/blenkernel/intern/volume_to_mesh.cc9
-rw-r--r--source/blender/blenloader/intern/versioning_250.c4
-rw-r--r--source/blender/blenloader/intern/versioning_290.c2
-rw-r--r--source/blender/blenloader/intern/versioning_400.cc1
-rw-r--r--source/blender/bmesh/intern/bmesh_mesh_convert.cc45
-rw-r--r--source/blender/bmesh/intern/bmesh_mesh_convert.h4
-rw-r--r--source/blender/draw/DRW_pbvh.h3
-rw-r--r--source/blender/draw/intern/draw_cache_extract_mesh.cc6
-rw-r--r--source/blender/draw/intern/draw_cache_extract_mesh_render_data.cc4
-rw-r--r--source/blender/draw/intern/draw_cache_impl_subdivision.cc35
-rw-r--r--source/blender/draw/intern/draw_pbvh.cc5
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh.hh9
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_points.cc1
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edge_fac.cc8
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc1
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_angle.cc21
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_area.cc3
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_pos.cc6
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_mesh_analysis.cc35
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc20
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_select_idx.cc1
-rw-r--r--source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_tan.cc7
-rw-r--r--source/blender/editors/armature/armature_skinning.c4
-rw-r--r--source/blender/editors/armature/meshlaplacian.c9
-rw-r--r--source/blender/editors/curves/intern/curves_ops.cc50
-rw-r--r--source/blender/editors/include/ED_view3d.h12
-rw-r--r--source/blender/editors/mesh/editface.cc4
-rw-r--r--source/blender/editors/mesh/mesh_data.cc10
-rw-r--r--source/blender/editors/mesh/mesh_mirror.c4
-rw-r--r--source/blender/editors/mesh/meshtools.cc68
-rw-r--r--source/blender/editors/object/object_bake_api.c2
-rw-r--r--source/blender/editors/object/object_modifier.cc29
-rw-r--r--source/blender/editors/object/object_remesh.cc7
-rw-r--r--source/blender/editors/object/object_vgroup.cc33
-rw-r--r--source/blender/editors/physics/particle_edit.c26
-rw-r--r--source/blender/editors/physics/particle_object.c15
-rw-r--r--source/blender/editors/sculpt_paint/curves_sculpt_add.cc12
-rw-r--r--source/blender/editors/sculpt_paint/curves_sculpt_puff.cc10
-rw-r--r--source/blender/editors/sculpt_paint/curves_sculpt_slide.cc14
-rw-r--r--source/blender/editors/sculpt_paint/paint_hide.c8
-rw-r--r--source/blender/editors/sculpt_paint/paint_image_proj.c56
-rw-r--r--source/blender/editors/sculpt_paint/paint_mask.c12
-rw-r--r--source/blender/editors/sculpt_paint/paint_utils.c4
-rw-r--r--source/blender/editors/sculpt_paint/paint_vertex.cc12
-rw-r--r--source/blender/editors/sculpt_paint/sculpt.cc33
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_boundary.c12
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_brush_types.c46
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_cloth.c10
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_dyntopo.c2
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_face_set.cc10
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_filter_mesh.c2
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_geodesic.c23
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_intern.h2
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_multiplane_scrape.c2
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_paint_image.cc26
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_pose.c2
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_smooth.c6
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_transform.c4
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_undo.c22
-rw-r--r--source/blender/editors/space_view3d/drawobject.c14
-rw-r--r--source/blender/editors/space_view3d/view3d_iterators.cc20
-rw-r--r--source/blender/editors/space_view3d/view3d_select.cc3
-rw-r--r--source/blender/editors/transform/transform_snap_object.cc27
-rw-r--r--source/blender/editors/uvedit/uvedit_unwrap_ops.c12
-rw-r--r--source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp23
-rw-r--r--source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp27
-rw-r--r--source/blender/geometry/intern/add_curves_on_mesh.cc8
-rw-r--r--source/blender/geometry/intern/mesh_merge_by_distance.cc44
-rw-r--r--source/blender/geometry/intern/mesh_primitive_cuboid.cc14
-rw-r--r--source/blender/geometry/intern/mesh_to_curve_convert.cc17
-rw-r--r--source/blender/geometry/intern/mesh_to_volume.cc12
-rw-r--r--source/blender/geometry/intern/realize_instances.cc23
-rw-r--r--source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c13
-rw-r--r--source/blender/gpu/intern/gpu_shader_builder_stubs.cc3
-rw-r--r--source/blender/io/alembic/exporter/abc_writer_hair.cc8
-rw-r--r--source/blender/io/alembic/exporter/abc_writer_mesh.cc4
-rw-r--r--source/blender/io/alembic/intern/abc_customdata.h5
-rw-r--r--source/blender/io/alembic/intern/abc_reader_mesh.cc16
-rw-r--r--source/blender/io/collada/GeometryExporter.cpp30
-rw-r--r--source/blender/io/collada/MeshImporter.cpp10
-rw-r--r--source/blender/io/stl/importer/stl_import_mesh.cc8
-rw-r--r--source/blender/io/usd/intern/usd_reader_mesh.cc7
-rw-r--r--source/blender/io/usd/intern/usd_writer_mesh.cc7
-rw-r--r--source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc11
-rw-r--r--source/blender/io/wavefront_obj/importer/obj_import_mesh.cc4
-rw-r--r--source/blender/io/wavefront_obj/tests/obj_importer_tests.cc6
-rw-r--r--source/blender/makesdna/DNA_customdata_types.h4
-rw-r--r--source/blender/makesdna/DNA_mesh_types.h14
-rw-r--r--source/blender/makesdna/DNA_meshdata_types.h19
-rw-r--r--source/blender/makesdna/DNA_modifier_types.h16
-rw-r--r--source/blender/makesdna/intern/dna_rename_defs.h1
-rw-r--r--source/blender/makesrna/intern/rna_mesh.c49
-rw-r--r--source/blender/makesrna/intern/rna_particle.c15
-rw-r--r--source/blender/modifiers/intern/MOD_array.c55
-rw-r--r--source/blender/modifiers/intern/MOD_boolean.cc7
-rw-r--r--source/blender/modifiers/intern/MOD_build.c9
-rw-r--r--source/blender/modifiers/intern/MOD_collision.c25
-rw-r--r--source/blender/modifiers/intern/MOD_datatransfer.cc6
-rw-r--r--source/blender/modifiers/intern/MOD_displace.c4
-rw-r--r--source/blender/modifiers/intern/MOD_explode.c42
-rw-r--r--source/blender/modifiers/intern/MOD_mask.cc16
-rw-r--r--source/blender/modifiers/intern/MOD_meshcache.c16
-rw-r--r--source/blender/modifiers/intern/MOD_meshsequencecache.cc7
-rw-r--r--source/blender/modifiers/intern/MOD_multires.cc4
-rw-r--r--source/blender/modifiers/intern/MOD_normal_edit.cc25
-rw-r--r--source/blender/modifiers/intern/MOD_ocean.c20
-rw-r--r--source/blender/modifiers/intern/MOD_particleinstance.c30
-rw-r--r--source/blender/modifiers/intern/MOD_remesh.c10
-rw-r--r--source/blender/modifiers/intern/MOD_screw.c70
-rw-r--r--source/blender/modifiers/intern/MOD_shrinkwrap.c6
-rw-r--r--source/blender/modifiers/intern/MOD_skin.c62
-rw-r--r--source/blender/modifiers/intern/MOD_solidify_extrude.c65
-rw-r--r--source/blender/modifiers/intern/MOD_solidify_nonmanifold.c20
-rw-r--r--source/blender/modifiers/intern/MOD_surface.c17
-rw-r--r--source/blender/modifiers/intern/MOD_surfacedeform.c4
-rw-r--r--source/blender/modifiers/intern/MOD_util.cc10
-rw-r--r--source/blender/modifiers/intern/MOD_weighted_normal.cc32
-rw-r--r--source/blender/modifiers/intern/MOD_weightvg_util.c2
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_convex_hull.cc7
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc4
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc16
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc22
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc16
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_dual_mesh.cc18
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc11
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc39
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_angle.cc38
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_vertices.cc8
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_area.cc7
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_is_planar.cc6
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc6
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc18
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_grid.cc14
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc6
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc12
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_sample_nearest.cc11
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_scale_elements.cc14
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_set_position.cc28
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_uv_pack_islands.cc4
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_uv_unwrap.cc4
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_volume_to_mesh.cc4
-rw-r--r--source/blender/python/mathutils/mathutils_bvhtree.c4
-rw-r--r--source/blender/render/intern/bake.c42
-rw-r--r--source/blender/render/intern/multires_bake.c18
-rw-r--r--source/blender/render/intern/texture_margin.cc8
-rw-r--r--source/blender/render/intern/texture_pointdensity.c7
-rw-r--r--source/blender/simulation/intern/hair_volume.cpp4
m---------source/tools0
230 files changed, 2336 insertions, 2579 deletions
diff --git a/intern/cycles/blender/mesh.cpp b/intern/cycles/blender/mesh.cpp
index fbc470cada4..fa4ddc24f56 100644
--- a/intern/cycles/blender/mesh.cpp
+++ b/intern/cycles/blender/mesh.cpp
@@ -681,7 +681,7 @@ static void attr_create_pointiness(Scene *scene, Mesh *mesh, BL::Mesh &b_mesh, b
if (num_verts == 0) {
return;
}
- const MVert *verts = static_cast<const MVert *>(b_mesh.vertices[0].ptr.data);
+ const float(*positions)[3] = static_cast<const float(*)[3]>(b_mesh.vertices[0].ptr.data);
/* STEP 1: Find out duplicated vertices and point duplicates to a single
* original vertex.
@@ -767,10 +767,8 @@ static void attr_create_pointiness(Scene *scene, Mesh *mesh, BL::Mesh &b_mesh, b
continue;
}
visited_edges.insert(v0, v1);
- const MVert &b_vert_0 = verts[v0];
- const MVert &b_vert_1 = verts[v1];
- float3 co0 = make_float3(b_vert_0.co[0], b_vert_0.co[1], b_vert_0.co[2]);
- float3 co1 = make_float3(b_vert_1.co[0], b_vert_1.co[1], b_vert_1.co[2]);
+ float3 co0 = make_float3(positions[v0][0], positions[v0][1], positions[v0][2]);
+ float3 co1 = make_float3(positions[v1][0], positions[v1][1], positions[v1][2]);
float3 edge = normalize(co1 - co0);
edge_accum[v0] += edge;
edge_accum[v1] += -edge;
@@ -921,7 +919,7 @@ static void create_mesh(Scene *scene,
return;
}
- const MVert *verts = static_cast<const MVert *>(b_mesh.vertices[0].ptr.data);
+ const float(*positions)[3] = static_cast<const float(*)[3]>(b_mesh.vertices[0].ptr.data);
if (!subdivision) {
numtris = numfaces;
@@ -944,8 +942,7 @@ static void create_mesh(Scene *scene,
/* create vertex coordinates and normals */
for (int i = 0; i < numverts; i++) {
- const MVert &b_vert = verts[i];
- mesh->add_vertex(make_float3(b_vert.co[0], b_vert.co[1], b_vert.co[2]));
+ mesh->add_vertex(make_float3(positions[i][0], positions[i][1], positions[i][2]));
}
AttributeSet &attributes = (subdivision) ? mesh->subd_attributes : mesh->attributes;
@@ -1253,14 +1250,13 @@ void BlenderSync::sync_mesh_motion(BL::Depsgraph b_depsgraph,
float3 *mP = attr_mP->data_float3() + motion_step * numverts;
float3 *mN = (attr_mN) ? attr_mN->data_float3() + motion_step * numverts : NULL;
- const MVert *verts = static_cast<const MVert *>(b_mesh.vertices[0].ptr.data);
+ const float(*positions)[3] = static_cast<const float(*)[3]>(b_mesh.vertices[0].ptr.data);
/* NOTE: We don't copy more that existing amount of vertices to prevent
* possible memory corruption.
*/
for (int i = 0; i < std::min<size_t>(b_verts_num, numverts); i++) {
- const MVert &b_vert = verts[i];
- mP[i] = make_float3(b_vert.co[0], b_vert.co[1], b_vert.co[2]);
+ mP[i] = make_float3(positions[i][0], positions[i][1], positions[i][2]);
}
if (mN) {
const float(*b_vert_normals)[3] = static_cast<const float(*)[3]>(
diff --git a/release/datafiles/locale b/release/datafiles/locale
-Subproject fe221a8bc934385d9f302c46a5c7cbeacddafe3
+Subproject 7be7aff5a18c550465b3f7634539ed4168af7c5
diff --git a/release/scripts/addons b/release/scripts/addons
-Subproject 5a818af95080cccf04dfa8317f0e966bff515c6
+Subproject c226f867affd12881533a54c8c90ac6eebfaca6
diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py
index fdc9b4572d3..567fdbf2dce 100644
--- a/release/scripts/startup/bl_ui/properties_data_mesh.py
+++ b/release/scripts/startup/bl_ui/properties_data_mesh.py
@@ -593,7 +593,7 @@ class DATA_PT_mesh_attributes(MeshButtonsPanel, Panel):
colliding_names = []
for collection in (
# Built-in names.
- {"position": None, "shade_smooth": None, "normal": None, "crease": None},
+ {"shade_smooth": None, "normal": None, "crease": None},
mesh.attributes,
mesh.uv_layers,
None if ob is None else ob.vertex_groups,
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h
index cb9c4256e33..967f9ea240c 100644
--- a/source/blender/blenkernel/BKE_DerivedMesh.h
+++ b/source/blender/blenkernel/BKE_DerivedMesh.h
@@ -61,7 +61,6 @@ struct CustomData_MeshMasks;
struct Depsgraph;
struct MEdge;
struct MFace;
-struct MVert;
struct Mesh;
struct ModifierData;
struct Object;
@@ -125,7 +124,10 @@ struct DerivedMesh {
* and freed on the next ->release(). consider using getVert/Edge/Face if
* you are only interested in a few verts/edges/faces.
*/
- struct MVert *(*getVertArray)(DerivedMesh *dm);
+ /**
+ * \warning The real return type is `float(*)[3]`.
+ */
+ float *(*getVertArray)(DerivedMesh *dm);
struct MEdge *(*getEdgeArray)(DerivedMesh *dm);
struct MLoop *(*getLoopArray)(DerivedMesh *dm);
struct MPoly *(*getPolyArray)(DerivedMesh *dm);
@@ -133,7 +135,7 @@ struct DerivedMesh {
/** Copy all verts/edges/faces from the derived mesh into
* *{vert/edge/face}_r (must point to a buffer large enough)
*/
- void (*copyVertArray)(DerivedMesh *dm, struct MVert *r_vert);
+ void (*copyVertArray)(DerivedMesh *dm, float (*r_positions)[3]);
void (*copyEdgeArray)(DerivedMesh *dm, struct MEdge *r_edge);
void (*copyLoopArray)(DerivedMesh *dm, struct MLoop *r_loop);
void (*copyPolyArray)(DerivedMesh *dm, struct MPoly *r_poly);
diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h
index a0a6ac58c58..bf4d99a9fac 100644
--- a/source/blender/blenkernel/BKE_bvhutils.h
+++ b/source/blender/blenkernel/BKE_bvhutils.h
@@ -24,7 +24,6 @@ extern "C" {
struct BMEditMesh;
struct MFace;
-struct MVert;
struct Mesh;
struct PointCloud;
@@ -58,7 +57,7 @@ typedef struct BVHTreeFromMesh {
BVHTree_RayCastCallback raycast_callback;
/* Vertex array, so that callbacks have instant access to data. */
- const struct MVert *vert;
+ const float (*positions)[3];
const float (*vert_normals)[3];
const struct MEdge *edge;
const struct MFace *face;
@@ -121,7 +120,7 @@ BVHTree *bvhtree_from_editmesh_verts_ex(BVHTreeFromEditMesh *data,
* (else will be computed from mask).
*/
BVHTree *bvhtree_from_mesh_verts_ex(struct BVHTreeFromMesh *data,
- const struct MVert *vert,
+ const float (*positions)[3],
int verts_num,
const BLI_bitmap *verts_mask,
int verts_num_active,
@@ -152,7 +151,7 @@ BVHTree *bvhtree_from_editmesh_edges_ex(BVHTreeFromEditMesh *data,
* (else will be computed from mask).
*/
BVHTree *bvhtree_from_mesh_edges_ex(struct BVHTreeFromMesh *data,
- const struct MVert *vert,
+ const float (*positions)[3],
const struct MEdge *edge,
int edges_num,
const BLI_bitmap *edges_mask,
@@ -179,7 +178,7 @@ BVHTree *bvhtree_from_editmesh_looptri_ex(BVHTreeFromEditMesh *data,
* Builds a BVH-tree where nodes are the looptri faces of the given mesh.
*/
BVHTree *bvhtree_from_mesh_looptri_ex(struct BVHTreeFromMesh *data,
- const struct MVert *vert,
+ const float (*positions)[3],
const struct MLoop *mloop,
const struct MLoopTri *looptri,
int looptri_num,
diff --git a/source/blender/blenkernel/BKE_collision.h b/source/blender/blenkernel/BKE_collision.h
index c390d0a8802..1aaddebed91 100644
--- a/source/blender/blenkernel/BKE_collision.h
+++ b/source/blender/blenkernel/BKE_collision.h
@@ -14,7 +14,6 @@ struct BVHTree;
struct Collection;
struct CollisionModifierData;
struct Depsgraph;
-struct MVert;
struct MVertTri;
struct Object;
struct Scene;
@@ -88,13 +87,13 @@ typedef struct FaceCollPair {
// used in modifier.cc from collision.c
/////////////////////////////////////////////////
-struct BVHTree *bvhtree_build_from_mvert(const struct MVert *mvert,
+struct BVHTree *bvhtree_build_from_mvert(const float (*positions)[3],
const struct MVertTri *tri,
int tri_num,
float epsilon);
void bvhtree_update_from_mvert(struct BVHTree *bvhtree,
- const struct MVert *mvert,
- const struct MVert *mvert_moving,
+ const float (*positions)[3],
+ const float (*positions_moving)[3],
const struct MVertTri *tri,
int tri_num,
bool moving);
diff --git a/source/blender/blenkernel/BKE_key.h b/source/blender/blenkernel/BKE_key.h
index 6cae56b775f..5bad3c19920 100644
--- a/source/blender/blenkernel/BKE_key.h
+++ b/source/blender/blenkernel/BKE_key.h
@@ -13,7 +13,6 @@ struct Lattice;
struct ListBase;
struct Main;
struct Mesh;
-struct MVert;
struct Object;
/* Kernel prototypes */
@@ -132,7 +131,7 @@ void BKE_keyblock_update_from_mesh(const struct Mesh *me, struct KeyBlock *kb);
void BKE_keyblock_convert_from_mesh(const struct Mesh *me,
const struct Key *key,
struct KeyBlock *kb);
-void BKE_keyblock_convert_to_mesh(const struct KeyBlock *kb, struct MVert *mvert, int totvert);
+void BKE_keyblock_convert_to_mesh(const struct KeyBlock *kb, float (*positions)[3], int totvert);
/**
* Computes normals (vertices, polygons and/or loops ones) of given mesh for given shape key.
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 8f6786d4113..ebc3c31c08b 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -38,7 +38,6 @@ struct MLoop;
struct MLoopTri;
struct MLoopUV;
struct MPoly;
-struct MVert;
struct Main;
struct MemArena;
struct Mesh;
@@ -185,6 +184,8 @@ struct Mesh *BKE_mesh_new_nomain_from_curve(const struct Object *ob);
struct Mesh *BKE_mesh_new_nomain_from_curve_displist(const struct Object *ob,
const struct ListBase *dispbase);
+bool BKE_mesh_attribute_required(const char *name);
+
bool BKE_mesh_ensure_facemap_customdata(struct Mesh *me);
bool BKE_mesh_clear_facemap_customdata(struct Mesh *me);
@@ -336,7 +337,7 @@ void BKE_mesh_vert_coords_apply(struct Mesh *mesh, const float (*vert_coords)[3]
*/
void BKE_mesh_recalc_looptri(const struct MLoop *mloop,
const struct MPoly *mpoly,
- const struct MVert *mvert,
+ const float (*positions)[3],
int totloop,
int totpoly,
struct MLoopTri *mlooptri);
@@ -350,7 +351,7 @@ void BKE_mesh_recalc_looptri(const struct MLoop *mloop,
*/
void BKE_mesh_recalc_looptri_with_normals(const struct MLoop *mloop,
const struct MPoly *mpoly,
- const struct MVert *mvert,
+ const float (*positions)[3],
int totloop,
int totpoly,
struct MLoopTri *mlooptri,
@@ -452,7 +453,7 @@ bool BKE_mesh_poly_normals_are_dirty(const struct Mesh *mesh);
* \note Usually #BKE_mesh_poly_normals_ensure is the preferred way to access face normals,
* since they may already be calculated and cached on the mesh.
*/
-void BKE_mesh_calc_normals_poly(const struct MVert *mvert,
+void BKE_mesh_calc_normals_poly(const float (*positions)[3],
int mvert_len,
const struct MLoop *mloop,
int mloop_len,
@@ -466,7 +467,7 @@ void BKE_mesh_calc_normals_poly(const struct MVert *mvert,
* \note Usually #BKE_mesh_vertex_normals_ensure is the preferred way to access vertex normals,
* since they may already be calculated and cached on the mesh.
*/
-void BKE_mesh_calc_normals_poly_and_vertex(const struct MVert *mvert,
+void BKE_mesh_calc_normals_poly_and_vertex(const float (*positions)[3],
int mvert_len,
const struct MLoop *mloop,
int mloop_len,
@@ -488,7 +489,7 @@ void BKE_mesh_calc_normals(struct Mesh *me);
* Called after calculating all modifiers.
*/
void BKE_mesh_ensure_normals_for_display(struct Mesh *mesh);
-void BKE_mesh_calc_normals_looptri(const struct MVert *mverts,
+void BKE_mesh_calc_normals_looptri(const float (*positions)[3],
int numVerts,
const struct MLoop *mloop,
const struct MLoopTri *looptri,
@@ -510,7 +511,7 @@ void BKE_mesh_loop_manifold_fan_around_vert_next(const struct MLoop *mloops,
* Used when defining an empty custom loop normals data layer,
* to keep same shading as with auto-smooth!
*/
-void BKE_edges_sharp_from_angle_set(const struct MVert *mverts,
+void BKE_edges_sharp_from_angle_set(const float (*positions)[3],
int numVerts,
struct MEdge *medges,
int numEdges,
@@ -631,7 +632,7 @@ void BKE_lnor_space_custom_normal_to_data(MLoopNorSpace *lnor_space,
* Useful to materialize sharp edges (or non-smooth faces) without actually modifying the geometry
* (splitting edges).
*/
-void BKE_mesh_normals_loop_split(const struct MVert *mverts,
+void BKE_mesh_normals_loop_split(const float (*positions)[3],
const float (*vert_normals)[3],
int numVerts,
const struct MEdge *medges,
@@ -648,7 +649,7 @@ void BKE_mesh_normals_loop_split(const struct MVert *mverts,
short (*clnors_data)[2],
int *r_loop_to_poly);
-void BKE_mesh_normals_loop_custom_set(const struct MVert *mverts,
+void BKE_mesh_normals_loop_custom_set(const float (*positions)[3],
const float (*vert_normals)[3],
int numVerts,
struct MEdge *medges,
@@ -660,7 +661,7 @@ void BKE_mesh_normals_loop_custom_set(const struct MVert *mverts,
const float (*polynors)[3],
int numPolys,
short (*r_clnors_data)[2]);
-void BKE_mesh_normals_loop_custom_from_verts_set(const struct MVert *mverts,
+void BKE_mesh_normals_loop_custom_from_verts_set(const float (*positions)[3],
const float (*vert_normals)[3],
float (*r_custom_vertnors)[3],
int numVerts,
@@ -723,7 +724,7 @@ void BKE_mesh_set_custom_normals_from_verts(struct Mesh *mesh, float (*r_custom_
void BKE_mesh_calc_poly_normal(const struct MPoly *mpoly,
const struct MLoop *loopstart,
- const struct MVert *mvarray,
+ const float (*positions)[3],
float r_no[3]);
void BKE_mesh_calc_poly_normal_coords(const struct MPoly *mpoly,
const struct MLoop *loopstart,
@@ -731,17 +732,17 @@ void BKE_mesh_calc_poly_normal_coords(const struct MPoly *mpoly,
float r_no[3]);
void BKE_mesh_calc_poly_center(const struct MPoly *mpoly,
const struct MLoop *loopstart,
- const struct MVert *mvarray,
+ const float (*positions)[3],
float r_cent[3]);
/* NOTE: passing poly-normal is only a speedup so we can skip calculating it. */
float BKE_mesh_calc_poly_area(const struct MPoly *mpoly,
const struct MLoop *loopstart,
- const struct MVert *mvarray);
+ const float (*positions)[3]);
float BKE_mesh_calc_area(const struct Mesh *me);
float BKE_mesh_calc_poly_uv_area(const struct MPoly *mpoly, const struct MLoopUV *uv_array);
void BKE_mesh_calc_poly_angles(const struct MPoly *mpoly,
const struct MLoop *loopstart,
- const struct MVert *mvarray,
+ const float (*positions)[3],
float angles[]);
void BKE_mesh_poly_edgehash_insert(struct EdgeHash *ehash,
@@ -771,7 +772,7 @@ bool BKE_mesh_center_of_volume(const struct Mesh *me, float r_cent[3]);
* \param r_volume: Volume (unsigned).
* \param r_center: Center of mass.
*/
-void BKE_mesh_calc_volume(const struct MVert *mverts,
+void BKE_mesh_calc_volume(const float (*positions)[3],
int mverts_num,
const struct MLoopTri *mlooptri,
int looptri_num,
@@ -930,7 +931,7 @@ bool BKE_mesh_validate_material_indices(struct Mesh *me);
* by importers that load normals (for example).
*/
bool BKE_mesh_validate_arrays(struct Mesh *me,
- struct MVert *mverts,
+ float (*positions)[3],
unsigned int totvert,
struct MEdge *medges,
unsigned int totedge,
@@ -1035,13 +1036,14 @@ BLI_INLINE int *BKE_mesh_material_indices_for_write(Mesh *mesh)
&mesh->pdata, CD_PROP_INT32, CD_SET_DEFAULT, NULL, mesh->totpoly, "material_index");
}
-BLI_INLINE const MVert *BKE_mesh_verts(const Mesh *mesh)
+BLI_INLINE const float (*BKE_mesh_positions(const Mesh *mesh))[3]
{
- return (const MVert *)CustomData_get_layer(&mesh->vdata, CD_MVERT);
+ return (const float(*)[3])CustomData_get_layer_named(&mesh->vdata, CD_PROP_FLOAT3, "position");
}
-BLI_INLINE MVert *BKE_mesh_verts_for_write(Mesh *mesh)
+BLI_INLINE float (*BKE_mesh_positions_for_write(Mesh *mesh))[3]
{
- return (MVert *)CustomData_duplicate_referenced_layer(&mesh->vdata, CD_MVERT, mesh->totvert);
+ return (float(*)[3])CustomData_duplicate_referenced_layer_named(
+ &mesh->vdata, CD_PROP_FLOAT3, "position", mesh->totvert);
}
BLI_INLINE const MEdge *BKE_mesh_edges(const Mesh *mesh)
@@ -1092,15 +1094,16 @@ BLI_INLINE MDeformVert *BKE_mesh_deform_verts_for_write(Mesh *mesh)
#ifdef __cplusplus
+# include "BLI_math_vec_types.hh"
# include "BLI_span.hh"
-inline blender::Span<MVert> Mesh::verts() const
+inline blender::Span<blender::float3> Mesh::positions() const
{
- return {BKE_mesh_verts(this), this->totvert};
+ return {reinterpret_cast<const blender::float3 *>(BKE_mesh_positions(this)), this->totvert};
}
-inline blender::MutableSpan<MVert> Mesh::verts_for_write()
+inline blender::MutableSpan<blender::float3> Mesh::positions_for_write()
{
- return {BKE_mesh_verts_for_write(this), this->totvert};
+ return {reinterpret_cast<blender::float3 *>(BKE_mesh_positions_for_write(this)), this->totvert};
}
inline blender::Span<MEdge> Mesh::edges() const
diff --git a/source/blender/blenkernel/BKE_mesh_fair.h b/source/blender/blenkernel/BKE_mesh_fair.h
index 9d94c692858..e5b92b795c0 100644
--- a/source/blender/blenkernel/BKE_mesh_fair.h
+++ b/source/blender/blenkernel/BKE_mesh_fair.h
@@ -29,10 +29,10 @@ void BKE_bmesh_prefair_and_fair_verts(struct BMesh *bm,
bool *affect_verts,
eMeshFairingDepth depth);
-/* This function can optionally use the MVert coordinates of deform_mverts to read and write the
- * fairing result. When NULL, the function will use mesh->mverts directly. */
+/* This function can optionally use the vertex coordinates of deform_mverts to read and write the
+ * fairing result. When NULL, the function will use mesh positions directly. */
void BKE_mesh_prefair_and_fair_verts(struct Mesh *mesh,
- struct MVert *deform_mverts,
+ float (*deform_positions)[3],
bool *affect_verts,
eMeshFairingDepth depth);
diff --git a/source/blender/blenkernel/BKE_mesh_legacy_convert.h b/source/blender/blenkernel/BKE_mesh_legacy_convert.h
index 5eae7bf3b22..27932852b98 100644
--- a/source/blender/blenkernel/BKE_mesh_legacy_convert.h
+++ b/source/blender/blenkernel/BKE_mesh_legacy_convert.h
@@ -10,10 +10,14 @@
#include "BLI_utildefines.h"
#ifdef __cplusplus
+# include "BLI_resource_scope.hh"
# include "BLI_span.hh"
+# include "BLI_vector.hh"
# include "DNA_customdata_types.h"
#endif
+#include "DNA_customdata_types.h"
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -82,6 +86,13 @@ void BKE_mesh_legacy_convert_material_indices_to_mpoly(struct Mesh *mesh);
*/
void BKE_mesh_legacy_convert_mpoly_to_material_indices(struct Mesh *mesh);
+struct MVert *BKE_mesh_legacy_convert_positions_to_verts(
+ Mesh *mesh,
+ blender::ResourceScope &temp_arrays_for_convert,
+ blender::Vector<CustomDataLayer, 16> &vert_layers_to_write);
+
+void BKE_mesh_legacy_convert_verts_to_positions(Mesh *mesh);
+
#endif
/**
diff --git a/source/blender/blenkernel/BKE_mesh_mapping.h b/source/blender/blenkernel/BKE_mesh_mapping.h
index 705158bec0b..1d1dc3d2c6b 100644
--- a/source/blender/blenkernel/BKE_mesh_mapping.h
+++ b/source/blender/blenkernel/BKE_mesh_mapping.h
@@ -19,7 +19,6 @@ struct MLoop;
struct MLoopTri;
struct MLoopUV;
struct MPoly;
-struct MVert;
/* UvVertMap */
#define STD_UV_CONNECT_LIMIT 0.0001f
@@ -146,7 +145,6 @@ void BKE_mesh_vert_loop_map_create(MeshElemMap **r_map,
*/
void BKE_mesh_vert_looptri_map_create(MeshElemMap **r_map,
int **r_mem,
- const struct MVert *mvert,
int totvert,
const struct MLoopTri *mlooptri,
int totlooptri,
@@ -260,7 +258,7 @@ void BKE_mesh_loop_islands_add(MeshIslandStore *island_store,
int num_innercut_items,
int *innercut_item_indices);
-typedef bool (*MeshRemapIslandsCalc)(const struct MVert *verts,
+typedef bool (*MeshRemapIslandsCalc)(const float (*positions)[3],
int totvert,
const struct MEdge *edges,
int totedge,
@@ -277,7 +275,7 @@ typedef bool (*MeshRemapIslandsCalc)(const struct MVert *verts,
* Calculate 'generic' UV islands, i.e. based only on actual geometry data (edge seams),
* not some UV layers coordinates.
*/
-bool BKE_mesh_calc_islands_loop_poly_edgeseam(const struct MVert *verts,
+bool BKE_mesh_calc_islands_loop_poly_edgeseam(const float (*positions)[3],
int totvert,
const struct MEdge *edges,
int totedge,
@@ -300,7 +298,7 @@ bool BKE_mesh_calc_islands_loop_poly_edgeseam(const struct MVert *verts,
* Not sure it would be worth the more complex code, though,
* those loops are supposed to be really quick to do.
*/
-bool BKE_mesh_calc_islands_loop_poly_uvmap(struct MVert *verts,
+bool BKE_mesh_calc_islands_loop_poly_uvmap(float (*positions)[3],
int totvert,
struct MEdge *edges,
int totedge,
diff --git a/source/blender/blenkernel/BKE_mesh_remap.h b/source/blender/blenkernel/BKE_mesh_remap.h
index efbf542c831..06cf45f570a 100644
--- a/source/blender/blenkernel/BKE_mesh_remap.h
+++ b/source/blender/blenkernel/BKE_mesh_remap.h
@@ -12,7 +12,6 @@ extern "C" {
struct CustomData;
struct CustomData_MeshMasks;
-struct MVert;
struct MemArena;
struct Mesh;
@@ -158,14 +157,14 @@ void BKE_mesh_remap_calc_source_cddata_masks_from_map_modes(
* in favor of a global good matching.
*/
float BKE_mesh_remap_calc_difference_from_mesh(const struct SpaceTransform *space_transform,
- const struct MVert *verts_dst,
+ const float (*positions_dst)[3],
int numverts_dst,
struct Mesh *me_src);
/**
* Set r_space_transform so that best bbox of dst matches best bbox of src.
*/
-void BKE_mesh_remap_find_best_match_from_mesh(const struct MVert *verts_dst,
+void BKE_mesh_remap_find_best_match_from_mesh(const float (*positions_dst)[3],
int numverts_dst,
struct Mesh *me_src,
struct SpaceTransform *r_space_transform);
@@ -174,7 +173,7 @@ void BKE_mesh_remap_calc_verts_from_mesh(int mode,
const struct SpaceTransform *space_transform,
float max_dist,
float ray_radius,
- const struct MVert *verts_dst,
+ const float (*positions_dst)[3],
int numverts_dst,
bool dirty_nors_dst,
struct Mesh *me_src,
@@ -185,7 +184,7 @@ void BKE_mesh_remap_calc_edges_from_mesh(int mode,
const struct SpaceTransform *space_transform,
float max_dist,
float ray_radius,
- const struct MVert *verts_dst,
+ const float (*positions_dst)[3],
int numverts_dst,
const struct MEdge *edges_dst,
int numedges_dst,
@@ -199,7 +198,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(int mode,
float max_dist,
float ray_radius,
struct Mesh *mesh_dst,
- const struct MVert *verts_dst,
+ const float (*positions_dst)[3],
int numverts_dst,
const struct MEdge *edges_dst,
int numedges_dst,
@@ -221,7 +220,7 @@ void BKE_mesh_remap_calc_polys_from_mesh(int mode,
float max_dist,
float ray_radius,
const struct Mesh *mesh_dst,
- const struct MVert *verts_dst,
+ const float (*positions_dst)[3],
const struct MLoop *loops_dst,
const struct MPoly *polys_dst,
int numpolys_dst,
diff --git a/source/blender/blenkernel/BKE_mesh_sample.hh b/source/blender/blenkernel/BKE_mesh_sample.hh
index 94dc52d5ec9..2cb27aa598f 100644
--- a/source/blender/blenkernel/BKE_mesh_sample.hh
+++ b/source/blender/blenkernel/BKE_mesh_sample.hh
@@ -127,7 +127,7 @@ int sample_surface_points_projected(
Vector<int> &r_looptri_indices,
Vector<float3> &r_positions);
-float3 compute_bary_coord_in_triangle(Span<MVert> verts,
+float3 compute_bary_coord_in_triangle(Span<float3> positions,
Span<MLoop> loops,
const MLoopTri &looptri,
const float3 &position);
diff --git a/source/blender/blenkernel/BKE_mesh_tangent.h b/source/blender/blenkernel/BKE_mesh_tangent.h
index 58142653a90..1610d0e3027 100644
--- a/source/blender/blenkernel/BKE_mesh_tangent.h
+++ b/source/blender/blenkernel/BKE_mesh_tangent.h
@@ -17,7 +17,7 @@ struct ReportList;
* split normals can be used to recreate the full tangent space.
* NOTE: * The mesh should be made of only tris and quads!
*/
-void BKE_mesh_calc_loop_tangent_single_ex(const struct MVert *mverts,
+void BKE_mesh_calc_loop_tangent_single_ex(const float (*positions)[3],
int numVerts,
const struct MLoop *mloops,
float (*r_looptangent)[4],
@@ -41,7 +41,7 @@ void BKE_mesh_calc_loop_tangent_single(struct Mesh *mesh,
/**
* See: #BKE_editmesh_loop_tangent_calc (matching logic).
*/
-void BKE_mesh_calc_loop_tangent_ex(const struct MVert *mvert,
+void BKE_mesh_calc_loop_tangent_ex(const float (*positions)[3],
const struct MPoly *mpoly,
uint mpoly_len,
const struct MLoop *mloop,
diff --git a/source/blender/blenkernel/BKE_mesh_types.h b/source/blender/blenkernel/BKE_mesh_types.h
index 80f61086052..5ce1a517d88 100644
--- a/source/blender/blenkernel/BKE_mesh_types.h
+++ b/source/blender/blenkernel/BKE_mesh_types.h
@@ -41,7 +41,7 @@ typedef enum eMeshBatchDirtyMode {
/** #MeshRuntime.wrapper_type */
typedef enum eMeshWrapperType {
- /** Use mesh data (#Mesh.mvert, #Mesh.medge, #Mesh.mloop, #Mesh.mpoly). */
+ /** Use mesh data (#Mesh.positions(), #Mesh.medge, #Mesh.mloop, #Mesh.mpoly). */
ME_WRAPPER_TYPE_MDATA = 0,
/** Use edit-mesh data (#Mesh.edit_mesh, #MeshRuntime.edit_data). */
ME_WRAPPER_TYPE_BMESH = 1,
diff --git a/source/blender/blenkernel/BKE_multires.h b/source/blender/blenkernel/BKE_multires.h
index 53dfaf953ea..640e2d70e79 100644
--- a/source/blender/blenkernel/BKE_multires.h
+++ b/source/blender/blenkernel/BKE_multires.h
@@ -27,7 +27,6 @@ struct SubdivCCG;
struct MLoop;
struct MLoopTri;
struct MPoly;
-struct MVert;
/**
* Delete mesh mdisps and grid paint masks.
@@ -156,8 +155,7 @@ void old_mdisps_bilinear(float out[3], float (*disps)[3], int st, float u, float
/**
* Find per-corner coordinate with given per-face UV coord.
*/
-int mdisp_rot_face_to_crn(struct MVert *mvert,
- struct MPoly *mpoly,
+int mdisp_rot_face_to_crn(struct MPoly *mpoly,
struct MLoop *mloop,
const struct MLoopTri *lt,
int face_side,
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 434255b2d9c..3722bd41f1d 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -39,7 +39,6 @@ struct ImageUser;
struct ListBase;
struct MLoop;
struct MLoopTri;
-struct MVert;
struct Main;
struct Mesh;
struct MeshElemMap;
@@ -572,7 +571,7 @@ typedef struct SculptSession {
struct Depsgraph *depsgraph;
/* These are always assigned to base mesh data when using PBVH_FACES and PBVH_GRIDS. */
- struct MVert *mvert;
+ float (*positions)[3];
const struct MPoly *mpoly;
const struct MLoop *mloop;
diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h
index 05b9aca7544..e1bead54a5c 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -36,7 +36,6 @@ struct LinkNode;
struct MCol;
struct MFace;
struct MTFace;
-struct MVert;
struct Main;
struct ModifierData;
struct Object;
@@ -583,7 +582,7 @@ void psys_get_texture(struct ParticleSimulationData *sim,
* Interpolate a location on a face based on face coordinates.
*/
void psys_interpolate_face(struct Mesh *mesh,
- const struct MVert *mvert,
+ const float (*positions)[3],
const float (*vert_normals)[3],
struct MFace *mface,
struct MTFace *tface,
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 4badd1bc269..05cde99e276 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -32,7 +32,6 @@ struct IsectRayPrecalc;
struct MLoop;
struct MLoopTri;
struct MPoly;
-struct MVert;
struct Mesh;
struct MeshElemMap;
struct PBVH;
@@ -250,7 +249,7 @@ void BKE_pbvh_build_mesh(PBVH *pbvh,
struct Mesh *mesh,
const struct MPoly *mpoly,
const struct MLoop *mloop,
- struct MVert *verts,
+ float (*positions)[3],
int totvert,
struct CustomData *vdata,
struct CustomData *ldata,
@@ -457,10 +456,7 @@ void BKE_pbvh_node_get_grids(PBVH *pbvh,
int *gridsize,
struct CCGElem ***r_griddata);
void BKE_pbvh_node_num_verts(PBVH *pbvh, PBVHNode *node, int *r_uniquevert, int *r_totvert);
-void BKE_pbvh_node_get_verts(PBVH *pbvh,
- PBVHNode *node,
- const int **r_vert_indices,
- struct MVert **r_verts);
+const int *BKE_pbvh_node_get_vert_indices(PBVHNode *node);
void BKE_pbvh_node_get_loops(PBVH *pbvh,
PBVHNode *node,
const int **r_loop_indices,
@@ -561,12 +557,13 @@ typedef struct PBVHVertexIter {
int gridsize;
/* mesh */
- struct MVert *mverts;
+ float (*mesh_positions)[3];
float (*vert_normals)[3];
const bool *hide_vert;
int totvert;
const int *vert_indices;
float *vmask;
+ bool is_mesh;
/* bmesh */
struct GSetIterator bm_unique_verts;
@@ -576,7 +573,6 @@ typedef struct PBVHVertexIter {
/* result: these are all computed in the macro, but we assume
* that compiler optimization's will skip the ones we don't use */
- struct MVert *mvert;
struct BMVert *bm_vert;
float *co;
float *no;
@@ -621,8 +617,7 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
} \
} \
} \
- else if (vi.mverts) { \
- vi.mvert = &vi.mverts[vi.vert_indices[vi.gx]]; \
+ else if (vi.mesh_positions) { \
if (vi.respect_hide) { \
vi.visible = !(vi.hide_vert && vi.hide_vert[vi.vert_indices[vi.gx]]); \
if (mode == PBVH_ITER_UNIQUE && !vi.visible) { \
@@ -632,7 +627,7 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
else { \
BLI_assert(vi.visible); \
} \
- vi.co = vi.mvert->co; \
+ vi.co = vi.mesh_positions[vi.vert_indices[vi.gx]]; \
vi.no = vi.vert_normals[vi.vert_indices[vi.gx]]; \
vi.index = vi.vertex.i = vi.vert_indices[vi.i]; \
if (vi.vmask) { \
@@ -697,7 +692,7 @@ void BKE_pbvh_parallel_range_settings(struct TaskParallelSettings *settings,
bool use_threading,
int totnode);
-struct MVert *BKE_pbvh_get_verts(const PBVH *pbvh);
+float (*BKE_pbvh_get_positions(const PBVH *pbvh))[3];
const float (*BKE_pbvh_get_vert_normals(const PBVH *pbvh))[3];
const bool *BKE_pbvh_get_vert_hide(const PBVH *pbvh);
bool *BKE_pbvh_get_vert_hide_for_write(PBVH *pbvh);
diff --git a/source/blender/blenkernel/BKE_subdiv.h b/source/blender/blenkernel/BKE_subdiv.h
index 5a6e8cbb64a..af738c85a5c 100644
--- a/source/blender/blenkernel/BKE_subdiv.h
+++ b/source/blender/blenkernel/BKE_subdiv.h
@@ -94,7 +94,7 @@ typedef struct SubdivStats {
double topology_refiner_creation_time;
/* Total time spent in BKE_subdiv_to_mesh(). */
double subdiv_to_mesh_time;
- /* Geometry (MVert and co) creation time during SUBDIV_TYO_MESH. */
+ /* Geometry (mesh vertices) creation time during SUBDIV_TYO_MESH. */
double subdiv_to_mesh_geometry_time;
/* Time spent on evaluator creation from topology refiner. */
double evaluator_creation_time;
diff --git a/source/blender/blenkernel/BKE_subdiv_mesh.h b/source/blender/blenkernel/BKE_subdiv_mesh.h
index 49c45efafe0..d1ccc60061c 100644
--- a/source/blender/blenkernel/BKE_subdiv_mesh.h
+++ b/source/blender/blenkernel/BKE_subdiv_mesh.h
@@ -16,7 +16,6 @@ extern "C" {
struct Mesh;
struct MeshElemMap;
struct MEdge;
-struct MVert;
struct Subdiv;
typedef struct SubdivToMeshSettings {
@@ -39,7 +38,7 @@ struct Mesh *BKE_subdiv_to_mesh(struct Subdiv *subdiv,
/* Interpolate a position along the `coarse_edge` at the relative `u` coordinate. If `is_simple` is
* false, this will perform a B-Spline interpolation using the edge neighbors, otherwise a linear
* interpolation will be done base on the edge vertices. */
-void BKE_subdiv_mesh_interpolate_position_on_edge(const struct MVert *coarse_verts,
+void BKE_subdiv_mesh_interpolate_position_on_edge(const float (*coarse_positions)[3],
const struct MEdge *coarse_edges,
const struct MeshElemMap *vert_to_edge_map,
int coarse_edge_index,
diff --git a/source/blender/blenkernel/BKE_volume_to_mesh.hh b/source/blender/blenkernel/BKE_volume_to_mesh.hh
index 9a3ab1000ea..cc2945edab1 100644
--- a/source/blender/blenkernel/BKE_volume_to_mesh.hh
+++ b/source/blender/blenkernel/BKE_volume_to_mesh.hh
@@ -62,7 +62,7 @@ void fill_mesh_from_openvdb_data(const Span<openvdb::Vec3s> vdb_verts,
int vert_offset,
int poly_offset,
int loop_offset,
- MutableSpan<MVert> verts,
+ MutableSpan<float3> positions,
MutableSpan<MPoly> polys,
MutableSpan<MLoop> loops);
diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc
index bfdfc447baf..2730873c7e8 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.cc
+++ b/source/blender/blenkernel/intern/DerivedMesh.cc
@@ -92,18 +92,19 @@ static void editbmesh_calc_modifier_final_normals_or_defer(
/* -------------------------------------------------------------------- */
-static MVert *dm_getVertArray(DerivedMesh *dm)
+static float *dm_getVertArray(DerivedMesh *dm)
{
- MVert *mvert = (MVert *)CustomData_get_layer(&dm->vertData, CD_MVERT);
+ float(*positions)[3] = (float(*)[3])CustomData_get_layer_named(
+ &dm->vertData, CD_PROP_FLOAT3, "position");
- if (!mvert) {
- mvert = (MVert *)CustomData_add_layer(
- &dm->vertData, CD_MVERT, CD_SET_DEFAULT, nullptr, dm->getNumVerts(dm));
- CustomData_set_layer_flag(&dm->vertData, CD_MVERT, CD_FLAG_TEMPORARY);
- dm->copyVertArray(dm, mvert);
+ if (!positions) {
+ positions = (float(*)[3])CustomData_add_layer_named(
+ &dm->vertData, CD_PROP_FLOAT3, CD_SET_DEFAULT, nullptr, dm->getNumVerts(dm), "position");
+ CustomData_set_layer_flag(&dm->vertData, CD_PROP_FLOAT3, CD_FLAG_TEMPORARY);
+ dm->copyVertArray(dm, positions);
}
- return mvert;
+ return (float *)positions;
}
static MEdge *dm_getEdgeArray(DerivedMesh *dm)
@@ -350,10 +351,6 @@ static void mesh_set_only_copy(Mesh *mesh, const CustomData_MeshMasks *mask)
void *DM_get_vert_data_layer(DerivedMesh *dm, int type)
{
- if (type == CD_MVERT) {
- return dm->getVertArray(dm);
- }
-
return CustomData_get_layer(&dm->vertData, type);
}
@@ -673,10 +670,8 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
BLI_assert((mesh_input->id.tag & LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT) == 0);
- /* Deformed vertex locations array. Deform only modifier need this type of
- * float array rather than MVert*. Tracked along with mesh_final as an
- * optimization to avoid copying coordinates back and forth if there are
- * multiple sequential deform only modifiers. */
+ /* TODO: Remove use of "deformed_verts" in mesh modifier stack since mesh positions are now in a
+ * contiguous array. */
float(*deformed_verts)[3] = nullptr;
int num_deformed_verts = mesh_input->totvert;
bool isPrevDeform = false;
@@ -1931,9 +1926,9 @@ void mesh_get_mapped_verts_coords(Mesh *me_eval, float (*r_cos)[3], const int to
MEM_freeN(userData.vertex_visit);
}
else {
- const Span<MVert> verts = me_eval->verts();
+ const Span<float3> positions = me_eval->positions();
for (int i = 0; i < totcos; i++) {
- copy_v3_v3(r_cos[i], verts[i].co);
+ copy_v3_v3(r_cos[i], positions[i]);
}
}
}
@@ -1946,7 +1941,7 @@ static void mesh_init_origspace(Mesh *mesh)
CD_ORIGSPACE_MLOOP);
const int numpoly = mesh->totpoly;
// const int numloop = mesh->totloop;
- const Span<MVert> verts = mesh->verts();
+ const Span<float3> positions = mesh->positions();
const Span<MPoly> polys = mesh->polys();
const Span<MLoop> loops = mesh->loops();
@@ -1971,12 +1966,13 @@ static void mesh_init_origspace(Mesh *mesh)
float min[2] = {FLT_MAX, FLT_MAX}, max[2] = {-FLT_MAX, -FLT_MAX};
float translate[2], scale[2];
- BKE_mesh_calc_poly_normal(mp, l, verts.data(), p_nor);
+ BKE_mesh_calc_poly_normal(
+ mp, l, reinterpret_cast<const float(*)[3]>(positions.data()), p_nor);
axis_dominant_v3_to_m3(mat, p_nor);
vcos_2d.resize(mp->totloop);
for (j = 0; j < mp->totloop; j++, l++) {
- mul_v3_m3v3(co, mat, verts[l->v].co);
+ mul_v3_m3v3(co, mat, positions[l->v]);
copy_v2_v2(vcos_2d[j], co);
for (k = 0; k < 2; k++) {
diff --git a/source/blender/blenkernel/intern/attribute.cc b/source/blender/blenkernel/intern/attribute.cc
index 80647362826..69c219fdd10 100644
--- a/source/blender/blenkernel/intern/attribute.cc
+++ b/source/blender/blenkernel/intern/attribute.cc
@@ -31,6 +31,7 @@
#include "BKE_curves.hh"
#include "BKE_customdata.h"
#include "BKE_editmesh.h"
+#include "BKE_mesh.h"
#include "BKE_pointcloud.h"
#include "BKE_report.h"
@@ -456,6 +457,8 @@ bool BKE_id_attribute_required(const ID *id, const char *name)
return BKE_pointcloud_attribute_required((const PointCloud *)id, name);
case ID_CV:
return BKE_curves_attribute_required((const Curves *)id, name);
+ case ID_ME:
+ return BKE_mesh_attribute_required(name);
default:
return false;
}
diff --git a/source/blender/blenkernel/intern/attribute_access_intern.hh b/source/blender/blenkernel/intern/attribute_access_intern.hh
index 33d415f1e0e..d2579e47b4d 100644
--- a/source/blender/blenkernel/intern/attribute_access_intern.hh
+++ b/source/blender/blenkernel/intern/attribute_access_intern.hh
@@ -220,8 +220,7 @@ template<typename T> GVMutableArray make_array_write_attribute(void *data, const
/**
* This provider is used to provide access to builtin attributes. It supports making internal types
- * available as different types. For example, the vertex position attribute is stored as part of
- * the #MVert struct, but is exposed as float3 attribute.
+ * available as different types.
*
* It also supports named builtin attributes, and will look up attributes in #CustomData by name
* if the stored type is the same as the attribute type.
diff --git a/source/blender/blenkernel/intern/bvhutils.cc b/source/blender/blenkernel/intern/bvhutils.cc
index afc3e525143..bb536188c9e 100644
--- a/source/blender/blenkernel/intern/bvhutils.cc
+++ b/source/blender/blenkernel/intern/bvhutils.cc
@@ -28,6 +28,7 @@
#include "MEM_guardedalloc.h"
+using blender::float3;
using blender::Span;
using blender::VArray;
@@ -233,14 +234,14 @@ static void mesh_faces_nearest_point(void *userdata,
BVHTreeNearest *nearest)
{
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
- const MVert *vert = data->vert;
+ const float(*positions)[3] = data->positions;
const MFace *face = data->face + index;
const float *t0, *t1, *t2, *t3;
- t0 = vert[face->v1].co;
- t1 = vert[face->v2].co;
- t2 = vert[face->v3].co;
- t3 = face->v4 ? vert[face->v4].co : nullptr;
+ t0 = positions[face->v1];
+ t1 = positions[face->v2];
+ t2 = positions[face->v3];
+ t3 = face->v4 ? positions[face->v4] : nullptr;
do {
float nearest_tmp[3], dist_sq;
@@ -268,12 +269,12 @@ static void mesh_looptri_nearest_point(void *userdata,
BVHTreeNearest *nearest)
{
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
- const MVert *vert = data->vert;
+ const float(*positions)[3] = data->positions;
const MLoopTri *lt = &data->looptri[index];
const float *vtri_co[3] = {
- vert[data->loop[lt->tri[0]].v].co,
- vert[data->loop[lt->tri[1]].v].co,
- vert[data->loop[lt->tri[2]].v].co,
+ positions[data->loop[lt->tri[0]].v],
+ positions[data->loop[lt->tri[1]].v],
+ positions[data->loop[lt->tri[2]].v],
};
float nearest_tmp[3], dist_sq;
@@ -329,14 +330,14 @@ static void mesh_faces_spherecast(void *userdata,
BVHTreeRayHit *hit)
{
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
- const MVert *vert = data->vert;
+ const float(*positions)[3] = data->positions;
const MFace *face = &data->face[index];
const float *t0, *t1, *t2, *t3;
- t0 = vert[face->v1].co;
- t1 = vert[face->v2].co;
- t2 = vert[face->v3].co;
- t3 = face->v4 ? vert[face->v4].co : nullptr;
+ t0 = positions[face->v1];
+ t1 = positions[face->v2];
+ t2 = positions[face->v3];
+ t3 = face->v4 ? positions[face->v4] : nullptr;
do {
float dist;
@@ -368,12 +369,12 @@ static void mesh_looptri_spherecast(void *userdata,
BVHTreeRayHit *hit)
{
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
- const MVert *vert = data->vert;
+ const float(*positions)[3] = data->positions;
const MLoopTri *lt = &data->looptri[index];
const float *vtri_co[3] = {
- vert[data->loop[lt->tri[0]].v].co,
- vert[data->loop[lt->tri[1]].v].co,
- vert[data->loop[lt->tri[2]].v].co,
+ positions[data->loop[lt->tri[0]].v],
+ positions[data->loop[lt->tri[1]].v],
+ positions[data->loop[lt->tri[2]].v],
};
float dist;
@@ -438,13 +439,13 @@ static void mesh_edges_nearest_point(void *userdata,
BVHTreeNearest *nearest)
{
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
- const MVert *vert = data->vert;
+ const float(*positions)[3] = data->positions;
const MEdge *edge = data->edge + index;
float nearest_tmp[3], dist_sq;
const float *t0, *t1;
- t0 = vert[edge->v1].co;
- t1 = vert[edge->v2].co;
+ t0 = positions[edge->v1];
+ t1 = positions[edge->v2];
closest_to_line_segment_v3(nearest_tmp, co, t0, t1);
dist_sq = len_squared_v3v3(nearest_tmp, co);
@@ -503,7 +504,7 @@ static void mesh_verts_spherecast(void *userdata,
BVHTreeRayHit *hit)
{
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
- const float *v = data->vert[index].co;
+ const float *v = data->positions[index];
mesh_verts_spherecast_do(index, v, ray, hit);
}
@@ -520,15 +521,15 @@ static void mesh_edges_spherecast(void *userdata,
BVHTreeRayHit *hit)
{
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
- const MVert *vert = data->vert;
+ const float(*positions)[3] = data->positions;
const MEdge *edge = &data->edge[index];
const float radius_sq = square_f(ray->radius);
float dist;
const float *v1, *v2, *r1;
float r2[3], i1[3], i2[3];
- v1 = vert[edge->v1].co;
- v2 = vert[edge->v2].co;
+ v1 = positions[edge->v1];
+ v2 = positions[edge->v2];
/* In case we get a zero-length edge, handle it as a point! */
if (equals_v3v3(v1, v2)) {
@@ -571,7 +572,7 @@ static void mesh_edges_spherecast(void *userdata,
static void bvhtree_from_mesh_setup_data(BVHTree *tree,
const BVHCacheType bvh_cache_type,
- const MVert *vert,
+ const float (*positions)[3],
const MEdge *edge,
const MFace *face,
const MLoop *loop,
@@ -583,7 +584,7 @@ static void bvhtree_from_mesh_setup_data(BVHTree *tree,
r_data->tree = tree;
- r_data->vert = vert;
+ r_data->positions = reinterpret_cast<const float(*)[3]>(positions);
r_data->edge = edge;
r_data->face = face;
r_data->loop = loop;
@@ -701,7 +702,7 @@ static BVHTree *bvhtree_from_editmesh_verts_create_tree(float epsilon,
static BVHTree *bvhtree_from_mesh_verts_create_tree(float epsilon,
int tree_type,
int axis,
- const MVert *vert,
+ const float (*positions)[3],
const int verts_num,
const BLI_bitmap *verts_mask,
int verts_num_active)
@@ -723,7 +724,7 @@ static BVHTree *bvhtree_from_mesh_verts_create_tree(float epsilon,
if (verts_mask && !BLI_BITMAP_TEST_BOOL(verts_mask, i)) {
continue;
}
- BLI_bvhtree_insert(tree, i, vert[i].co, 1);
+ BLI_bvhtree_insert(tree, i, positions[i], 1);
}
BLI_assert(BLI_bvhtree_get_len(tree) == verts_num_active);
}
@@ -760,7 +761,7 @@ BVHTree *bvhtree_from_editmesh_verts(
}
BVHTree *bvhtree_from_mesh_verts_ex(BVHTreeFromMesh *data,
- const MVert *vert,
+ const float (*positions)[3],
const int verts_num,
const BLI_bitmap *verts_mask,
int verts_num_active,
@@ -770,14 +771,14 @@ BVHTree *bvhtree_from_mesh_verts_ex(BVHTreeFromMesh *data,
{
BVHTree *tree = nullptr;
tree = bvhtree_from_mesh_verts_create_tree(
- epsilon, tree_type, axis, vert, verts_num, verts_mask, verts_num_active);
+ epsilon, tree_type, axis, positions, verts_num, verts_mask, verts_num_active);
bvhtree_balance(tree, false);
if (data) {
/* Setup BVHTreeFromMesh */
bvhtree_from_mesh_setup_data(
- tree, BVHTREE_FROM_VERTS, vert, nullptr, nullptr, nullptr, nullptr, nullptr, data);
+ tree, BVHTREE_FROM_VERTS, positions, nullptr, nullptr, nullptr, nullptr, nullptr, data);
}
return tree;
@@ -828,7 +829,7 @@ static BVHTree *bvhtree_from_editmesh_edges_create_tree(float epsilon,
return tree;
}
-static BVHTree *bvhtree_from_mesh_edges_create_tree(const MVert *vert,
+static BVHTree *bvhtree_from_mesh_edges_create_tree(const float (*positions)[3],
const MEdge *edge,
const int edge_num,
const BLI_bitmap *edges_mask,
@@ -855,8 +856,8 @@ static BVHTree *bvhtree_from_mesh_edges_create_tree(const MVert *vert,
continue;
}
float co[2][3];
- copy_v3_v3(co[0], vert[edge[i].v1].co);
- copy_v3_v3(co[1], vert[edge[i].v2].co);
+ copy_v3_v3(co[0], positions[edge[i].v1]);
+ copy_v3_v3(co[1], positions[edge[i].v2]);
BLI_bvhtree_insert(tree, i, co[0], 2);
}
@@ -894,7 +895,7 @@ BVHTree *bvhtree_from_editmesh_edges(
}
BVHTree *bvhtree_from_mesh_edges_ex(BVHTreeFromMesh *data,
- const MVert *vert,
+ const float (*positions)[3],
const MEdge *edge,
const int edges_num,
const BLI_bitmap *edges_mask,
@@ -905,14 +906,14 @@ BVHTree *bvhtree_from_mesh_edges_ex(BVHTreeFromMesh *data,
{
BVHTree *tree = nullptr;
tree = bvhtree_from_mesh_edges_create_tree(
- vert, edge, edges_num, edges_mask, edges_num_active, epsilon, tree_type, axis);
+ positions, edge, edges_num, edges_mask, edges_num_active, epsilon, tree_type, axis);
bvhtree_balance(tree, false);
if (data) {
/* Setup BVHTreeFromMesh */
bvhtree_from_mesh_setup_data(
- tree, BVHTREE_FROM_EDGES, vert, edge, nullptr, nullptr, nullptr, nullptr, data);
+ tree, BVHTREE_FROM_EDGES, positions, edge, nullptr, nullptr, nullptr, nullptr, data);
}
return tree;
@@ -927,7 +928,7 @@ BVHTree *bvhtree_from_mesh_edges_ex(BVHTreeFromMesh *data,
static BVHTree *bvhtree_from_mesh_faces_create_tree(float epsilon,
int tree_type,
int axis,
- const MVert *vert,
+ const float (*positions)[3],
const MFace *face,
const int faces_num,
const BLI_bitmap *faces_mask,
@@ -947,18 +948,18 @@ static BVHTree *bvhtree_from_mesh_faces_create_tree(float epsilon,
// printf("%s: building BVH, total=%d\n", __func__, numFaces);
tree = BLI_bvhtree_new(faces_num_active, epsilon, tree_type, axis);
if (tree) {
- if (vert && face) {
+ if (positions && face) {
for (int i = 0; i < faces_num; i++) {
float co[4][3];
if (faces_mask && !BLI_BITMAP_TEST_BOOL(faces_mask, i)) {
continue;
}
- copy_v3_v3(co[0], vert[face[i].v1].co);
- copy_v3_v3(co[1], vert[face[i].v2].co);
- copy_v3_v3(co[2], vert[face[i].v3].co);
+ copy_v3_v3(co[0], positions[face[i].v1]);
+ copy_v3_v3(co[1], positions[face[i].v2]);
+ copy_v3_v3(co[2], positions[face[i].v3]);
if (face[i].v4) {
- copy_v3_v3(co[3], vert[face[i].v4].co);
+ copy_v3_v3(co[3], positions[face[i].v4]);
}
BLI_bvhtree_insert(tree, i, co[0], face[i].v4 ? 4 : 3);
@@ -1029,7 +1030,7 @@ static BVHTree *bvhtree_from_editmesh_looptri_create_tree(float epsilon,
static BVHTree *bvhtree_from_mesh_looptri_create_tree(float epsilon,
int tree_type,
int axis,
- const MVert *vert,
+ const float (*positions)[3],
const MLoop *mloop,
const MLoopTri *looptri,
const int looptri_num,
@@ -1050,16 +1051,16 @@ static BVHTree *bvhtree_from_mesh_looptri_create_tree(float epsilon,
// printf("%s: building BVH, total=%d\n", __func__, numFaces);
tree = BLI_bvhtree_new(looptri_num_active, epsilon, tree_type, axis);
if (tree) {
- if (vert && looptri) {
+ if (positions && looptri) {
for (int i = 0; i < looptri_num; i++) {
float co[3][3];
if (looptri_mask && !BLI_BITMAP_TEST_BOOL(looptri_mask, i)) {
continue;
}
- copy_v3_v3(co[0], vert[mloop[looptri[i].tri[0]].v].co);
- copy_v3_v3(co[1], vert[mloop[looptri[i].tri[1]].v].co);
- copy_v3_v3(co[2], vert[mloop[looptri[i].tri[2]].v].co);
+ copy_v3_v3(co[0], positions[mloop[looptri[i].tri[0]].v]);
+ copy_v3_v3(co[1], positions[mloop[looptri[i].tri[1]].v]);
+ copy_v3_v3(co[2], positions[mloop[looptri[i].tri[2]].v]);
BLI_bvhtree_insert(tree, i, co[0], 3);
}
@@ -1101,7 +1102,7 @@ BVHTree *bvhtree_from_editmesh_looptri(
}
BVHTree *bvhtree_from_mesh_looptri_ex(BVHTreeFromMesh *data,
- const struct MVert *vert,
+ const float (*positions)[3],
const struct MLoop *mloop,
const struct MLoopTri *looptri,
const int looptri_num,
@@ -1115,7 +1116,7 @@ BVHTree *bvhtree_from_mesh_looptri_ex(BVHTreeFromMesh *data,
tree = bvhtree_from_mesh_looptri_create_tree(epsilon,
tree_type,
axis,
- vert,
+ positions,
mloop,
looptri,
looptri_num,
@@ -1127,7 +1128,7 @@ BVHTree *bvhtree_from_mesh_looptri_ex(BVHTreeFromMesh *data,
if (data) {
/* Setup BVHTreeFromMesh */
bvhtree_from_mesh_setup_data(
- tree, BVHTREE_FROM_LOOPTRI, vert, nullptr, nullptr, mloop, looptri, nullptr, data);
+ tree, BVHTREE_FROM_LOOPTRI, positions, nullptr, nullptr, mloop, looptri, nullptr, data);
}
return tree;
@@ -1135,7 +1136,6 @@ BVHTree *bvhtree_from_mesh_looptri_ex(BVHTreeFromMesh *data,
static BLI_bitmap *loose_verts_map_get(const MEdge *medge,
int edges_num,
- const MVert * /*mvert*/,
int verts_num,
int *r_loose_vert_num)
{
@@ -1229,14 +1229,15 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data,
looptri = BKE_mesh_runtime_looptri_ensure(mesh);
looptri_len = BKE_mesh_runtime_looptri_len(mesh);
}
- const Span<MVert> verts = mesh->verts();
+ const Span<float3> positions = mesh->positions();
+ const float(*c_positions)[3] = reinterpret_cast<const float(*)[3]>(positions.data());
const Span<MEdge> edges = mesh->edges();
const Span<MLoop> loops = mesh->loops();
/* Setup BVHTreeFromMesh */
bvhtree_from_mesh_setup_data(nullptr,
bvh_cache_type,
- verts.data(),
+ c_positions,
edges.data(),
(const MFace *)CustomData_get_layer(&mesh->fdata, CD_MFACE),
loops.data(),
@@ -1262,12 +1263,11 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data,
switch (bvh_cache_type) {
case BVHTREE_FROM_LOOSEVERTS:
- mask = loose_verts_map_get(
- edges.data(), mesh->totedge, verts.data(), mesh->totvert, &mask_bits_act_len);
+ mask = loose_verts_map_get(edges.data(), mesh->totedge, mesh->totvert, &mask_bits_act_len);
ATTR_FALLTHROUGH;
case BVHTREE_FROM_VERTS:
data->tree = bvhtree_from_mesh_verts_create_tree(
- 0.0f, tree_type, 6, verts.data(), mesh->totvert, mask, mask_bits_act_len);
+ 0.0f, tree_type, 6, c_positions, mesh->totvert, mask, mask_bits_act_len);
break;
case BVHTREE_FROM_LOOSEEDGES:
@@ -1275,7 +1275,7 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data,
ATTR_FALLTHROUGH;
case BVHTREE_FROM_EDGES:
data->tree = bvhtree_from_mesh_edges_create_tree(
- verts.data(), edges.data(), mesh->totedge, mask, mask_bits_act_len, 0.0f, tree_type, 6);
+ c_positions, edges.data(), mesh->totedge, mask, mask_bits_act_len, 0.0f, tree_type, 6);
break;
case BVHTREE_FROM_FACES:
@@ -1284,7 +1284,7 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data,
0.0f,
tree_type,
6,
- verts.data(),
+ c_positions,
(const MFace *)CustomData_get_layer(&mesh->fdata, CD_MFACE),
mesh->totface,
nullptr,
@@ -1304,7 +1304,7 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data,
data->tree = bvhtree_from_mesh_looptri_create_tree(0.0f,
tree_type,
6,
- verts.data(),
+ c_positions,
loops.data(),
looptri,
looptri_len,
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index 41993764c0c..55153d8331d 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -38,7 +38,7 @@ typedef struct {
/* these point to data in the DerivedMesh custom data layers,
* they are only here for efficiency and convenience */
- MVert *mvert;
+ float (*positions)[3];
const float (*vert_normals)[3];
MEdge *medge;
MFace *mface;
@@ -75,10 +75,10 @@ static int cdDM_getNumPolys(DerivedMesh *dm)
return dm->numPolyData;
}
-static void cdDM_copyVertArray(DerivedMesh *dm, MVert *r_vert)
+static void cdDM_copyVertArray(DerivedMesh *dm, float (*r_positions)[3])
{
CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
- memcpy(r_vert, cddm->mvert, sizeof(*r_vert) * dm->numVertData);
+ memcpy(r_positions, cddm->positions, sizeof(float[3]) * dm->numVertData);
}
static void cdDM_copyEdgeArray(DerivedMesh *dm, MEdge *r_edge)
@@ -103,7 +103,7 @@ static void cdDM_getVertCo(DerivedMesh *dm, int index, float r_co[3])
{
CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
- copy_v3_v3(r_co, cddm->mvert[index].co);
+ copy_v3_v3(r_co, cddm->positions[index]);
}
static void cdDM_getVertNo(DerivedMesh *dm, int index, float r_no[3])
@@ -122,7 +122,7 @@ static void cdDM_recalc_looptri(DerivedMesh *dm)
BLI_assert(totpoly == 0 || cddm->dm.looptris.array_wip != NULL);
BKE_mesh_recalc_looptri(
- cddm->mloop, cddm->mpoly, cddm->mvert, totloop, totpoly, cddm->dm.looptris.array_wip);
+ cddm->mloop, cddm->mpoly, cddm->positions, totloop, totpoly, cddm->dm.looptris.array_wip);
BLI_assert(cddm->dm.looptris.array == NULL);
atomic_cas_ptr(
@@ -217,7 +217,7 @@ static DerivedMesh *cdDM_from_mesh_ex(Mesh *mesh,
CustomData_merge(&mesh->ldata, &dm->loopData, cddata_masks.lmask, alloctype, mesh->totloop);
CustomData_merge(&mesh->pdata, &dm->polyData, cddata_masks.pmask, alloctype, mesh->totpoly);
- cddm->mvert = CustomData_get_layer(&dm->vertData, CD_MVERT);
+ cddm->positions = CustomData_get_layer_named(&dm->vertData, CD_PROP_FLOAT3, "position");
/* Though this may be an unnecessary calculation, simply retrieving the layer may return nothing
* or dirty normals. */
cddm->vert_normals = BKE_mesh_vertex_normals_ensure(mesh);
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index 88ba50fe901..57f9db5b104 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -251,14 +251,13 @@ static int do_step_cloth(
ClothVertex *verts = NULL;
Cloth *cloth;
ListBase *effectors = NULL;
- MVert *mvert;
uint i = 0;
int ret = 0;
bool vert_mass_changed = false;
cloth = clmd->clothObject;
verts = cloth->verts;
- mvert = BKE_mesh_verts_for_write(result);
+ const float(*positions)[3] = BKE_mesh_positions(result);
vert_mass_changed = verts->mass != clmd->sim_parms->mass;
/* force any pinned verts to their constrained location. */
@@ -268,7 +267,7 @@ static int do_step_cloth(
copy_v3_v3(verts->txold, verts->x);
/* Get the current position. */
- copy_v3_v3(verts->xconst, mvert[i].co);
+ copy_v3_v3(verts->xconst, positions[i]);
mul_m4_v3(ob->object_to_world, verts->xconst);
if (vert_mass_changed) {
@@ -754,14 +753,14 @@ static bool cloth_from_object(
shapekey_rest = CustomData_get_layer(&mesh->vdata, CD_CLOTH_ORCO);
}
- MVert *mvert = BKE_mesh_verts_for_write(mesh);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
verts = clmd->clothObject->verts;
/* set initial values */
for (i = 0; i < mesh->totvert; i++, verts++) {
if (first) {
- copy_v3_v3(verts->x, mvert[i].co);
+ copy_v3_v3(verts->x, positions[i]);
mul_m4_v3(ob->object_to_world, verts->x);
@@ -1149,12 +1148,12 @@ static void cloth_update_springs(ClothModifierData *clmd)
static void cloth_update_verts(Object *ob, ClothModifierData *clmd, Mesh *mesh)
{
uint i = 0;
- const MVert *mvert = BKE_mesh_verts(mesh);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
ClothVertex *verts = clmd->clothObject->verts;
/* vertex count is already ensured to match */
for (i = 0; i < mesh->totvert; i++, verts++) {
- copy_v3_v3(verts->xrest, mvert[i].co);
+ copy_v3_v3(verts->xrest, positions[i]);
mul_m4_v3(ob->object_to_world, verts->xrest);
}
}
@@ -1164,11 +1163,11 @@ static Mesh *cloth_make_rest_mesh(ClothModifierData *clmd, Mesh *mesh)
{
Mesh *new_mesh = BKE_mesh_copy_for_eval(mesh, false);
ClothVertex *verts = clmd->clothObject->verts;
- MVert *mvert = BKE_mesh_verts_for_write(mesh);
+ float(*positions)[3] = BKE_mesh_positions_for_write(mesh);
/* vertex count is already ensured to match */
- for (uint i = 0; i < mesh->totvert; i++, verts++) {
- copy_v3_v3(mvert[i].co, verts->xrest);
+ for (int i = 0; i < mesh->totvert; i++, verts++) {
+ copy_v3_v3(positions[i], verts->xrest);
}
BKE_mesh_tag_coords_changed(new_mesh);
@@ -1383,7 +1382,7 @@ static bool find_internal_spring_target_vertex(BVHTreeFromMesh *treedata,
float co[3], no[3], new_co[3];
float radius;
- copy_v3_v3(co, treedata->vert[v_idx].co);
+ copy_v3_v3(co, treedata->positions[v_idx]);
negate_v3_v3(no, treedata->vert_normals[v_idx]);
float vec_len = sin(max_diversion);
diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c
index 2acdc6543b5..b9d5be62306 100644
--- a/source/blender/blenkernel/intern/collision.c
+++ b/source/blender/blenkernel/intern/collision.c
@@ -72,16 +72,16 @@ void collision_move_object(CollisionModifierData *collmd,
/* the collider doesn't move this frame */
if (collmd->is_static) {
for (i = 0; i < collmd->mvert_num; i++) {
- zero_v3(collmd->current_v[i].co);
+ zero_v3(collmd->current_v[i]);
}
return;
}
for (i = 0; i < collmd->mvert_num; i++) {
- interp_v3_v3v3(collmd->current_x[i].co, collmd->x[i].co, collmd->xnew[i].co, prevstep);
- interp_v3_v3v3(collmd->current_xnew[i].co, collmd->x[i].co, collmd->xnew[i].co, step);
- sub_v3_v3v3(collmd->current_v[i].co, collmd->current_xnew[i].co, collmd->current_x[i].co);
+ interp_v3_v3v3(collmd->current_x[i], collmd->x[i], collmd->xnew[i], prevstep);
+ interp_v3_v3v3(collmd->current_xnew[i], collmd->x[i], collmd->xnew[i], step);
+ sub_v3_v3v3(collmd->current_v[i], collmd->current_xnew[i], collmd->current_x[i]);
}
bvhtree_update_from_mvert(collmd->bvhtree,
@@ -92,7 +92,7 @@ void collision_move_object(CollisionModifierData *collmd,
moving_bvh);
}
-BVHTree *bvhtree_build_from_mvert(const MVert *mvert,
+BVHTree *bvhtree_build_from_mvert(const float (*positions)[3],
const struct MVertTri *tri,
int tri_num,
float epsilon)
@@ -105,9 +105,9 @@ BVHTree *bvhtree_build_from_mvert(const MVert *mvert,
for (i = 0, vt = tri; i < tri_num; i++, vt++) {
float co[3][3];
- copy_v3_v3(co[0], mvert[vt->tri[0]].co);
- copy_v3_v3(co[1], mvert[vt->tri[1]].co);
- copy_v3_v3(co[2], mvert[vt->tri[2]].co);
+ copy_v3_v3(co[0], positions[vt->tri[0]]);
+ copy_v3_v3(co[1], positions[vt->tri[1]]);
+ copy_v3_v3(co[2], positions[vt->tri[2]]);
BLI_bvhtree_insert(tree, i, co[0], 3);
}
@@ -119,18 +119,18 @@ BVHTree *bvhtree_build_from_mvert(const MVert *mvert,
}
void bvhtree_update_from_mvert(BVHTree *bvhtree,
- const MVert *mvert,
- const MVert *mvert_moving,
+ const float (*positions)[3],
+ const float (*positions_moving)[3],
const MVertTri *tri,
int tri_num,
bool moving)
{
- if ((bvhtree == NULL) || (mvert == NULL)) {
+ if ((bvhtree == NULL) || (positions == NULL)) {
return;
}
- if (mvert_moving == NULL) {
+ if (positions_moving == NULL) {
moving = false;
}
@@ -140,17 +140,17 @@ void bvhtree_update_from_mvert(BVHTree *bvhtree,
float co[3][3];
bool ret;
- copy_v3_v3(co[0], mvert[vt->tri[0]].co);
- copy_v3_v3(co[1], mvert[vt->tri[1]].co);
- copy_v3_v3(co[2], mvert[vt->tri[2]].co);
+ copy_v3_v3(co[0], positions[vt->tri[0]]);
+ copy_v3_v3(co[1], positions[vt->tri[1]]);
+ copy_v3_v3(co[2], positions[vt->tri[2]]);
/* copy new locations into array */
if (moving) {
float co_moving[3][3];
/* update moving positions */
- copy_v3_v3(co_moving[0], mvert_moving[vt->tri[0]].co);
- copy_v3_v3(co_moving[1], mvert_moving[vt->tri[1]].co);
- copy_v3_v3(co_moving[2], mvert_moving[vt->tri[2]].co);
+ copy_v3_v3(co_moving[0], positions_moving[vt->tri[0]]);
+ copy_v3_v3(co_moving[1], positions_moving[vt->tri[1]]);
+ copy_v3_v3(co_moving[2], positions_moving[vt->tri[2]]);
ret = BLI_bvhtree_update_node(bvhtree, i, &co[0][0], &co_moving[0][0], 3);
}
@@ -709,17 +709,17 @@ static int cloth_collision_response_static(ClothModifierData *clmd,
}
collision_compute_barycentric(collpair->pb,
- collmd->current_xnew[collpair->bp1].co,
- collmd->current_xnew[collpair->bp2].co,
- collmd->current_xnew[collpair->bp3].co,
+ collmd->current_xnew[collpair->bp1],
+ collmd->current_xnew[collpair->bp2],
+ collmd->current_xnew[collpair->bp3],
&u1,
&u2,
&u3);
collision_interpolateOnTriangle(v2,
- collmd->current_v[collpair->bp1].co,
- collmd->current_v[collpair->bp2].co,
- collmd->current_v[collpair->bp3].co,
+ collmd->current_v[collpair->bp1],
+ collmd->current_v[collpair->bp2],
+ collmd->current_v[collpair->bp3],
u1,
u2,
u3);
@@ -1025,9 +1025,9 @@ static void cloth_collision(void *__restrict userdata,
distance = compute_collision_point_tri_tri(verts1[tri_a->tri[0]].tx,
verts1[tri_a->tri[1]].tx,
verts1[tri_a->tri[2]].tx,
- collmd->current_xnew[tri_b->tri[0]].co,
- collmd->current_xnew[tri_b->tri[1]].co,
- collmd->current_xnew[tri_b->tri[2]].co,
+ collmd->current_xnew[tri_b->tri[0]],
+ collmd->current_xnew[tri_b->tri[1]],
+ collmd->current_xnew[tri_b->tri[2]],
data->culling,
data->use_normal,
pa,
@@ -1183,9 +1183,9 @@ static void hair_collision(void *__restrict userdata,
/* Compute distance and normal. */
distance = compute_collision_point_edge_tri(verts1[edge_coll->v1].tx,
verts1[edge_coll->v2].tx,
- collmd->current_x[tri_coll->tri[0]].co,
- collmd->current_x[tri_coll->tri[1]].co,
- collmd->current_x[tri_coll->tri[2]].co,
+ collmd->current_x[tri_coll->tri[0]],
+ collmd->current_x[tri_coll->tri[1]],
+ collmd->current_x[tri_coll->tri[2]],
data->culling,
data->use_normal,
pa,
@@ -1720,17 +1720,17 @@ void collision_get_collider_velocity(float vel_old[3],
/* compute barycentric coordinates */
collision_compute_barycentric(collpair->pb,
- collmd->current_x[collpair->bp1].co,
- collmd->current_x[collpair->bp2].co,
- collmd->current_x[collpair->bp3].co,
+ collmd->current_x[collpair->bp1],
+ collmd->current_x[collpair->bp2],
+ collmd->current_x[collpair->bp3],
&u1,
&u2,
&u3);
collision_interpolateOnTriangle(vel_new,
- collmd->current_v[collpair->bp1].co,
- collmd->current_v[collpair->bp2].co,
- collmd->current_v[collpair->bp3].co,
+ collmd->current_v[collpair->bp1],
+ collmd->current_v[collpair->bp2],
+ collmd->current_v[collpair->bp3],
u1,
u2,
u3);
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index bcc4ad0cb55..8288f1e491d 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -548,7 +548,7 @@ static void contarget_get_mesh_mat(Object *ob, const char *substring, float mat[
else if (me_eval) {
const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(me_eval);
const MDeformVert *dvert = CustomData_get_layer(&me_eval->vdata, CD_MDEFORMVERT);
- const MVert *verts = BKE_mesh_verts(me_eval);
+ const float(*positions)[3] = BKE_mesh_positions(me_eval);
int numVerts = me_eval->totvert;
/* check that dvert is a valid pointers (just in case) */
@@ -557,11 +557,10 @@ static void contarget_get_mesh_mat(Object *ob, const char *substring, float mat[
/* get the average of all verts with that are in the vertex-group */
for (int i = 0; i < numVerts; i++) {
const MDeformVert *dv = &dvert[i];
- const MVert *mv = &verts[i];
const MDeformWeight *dw = BKE_defvert_find_index(dv, defgroup);
if (dw && dw->weight > 0.0f) {
- madd_v3_v3fl(vec, mv->co, dw->weight);
+ madd_v3_v3fl(vec, positions[i], dw->weight);
madd_v3_v3fl(normal, vert_normals[i], dw->weight);
weightsum += dw->weight;
}
diff --git a/source/blender/blenkernel/intern/crazyspace.cc b/source/blender/blenkernel/intern/crazyspace.cc
index f83c321c4ae..c1f4cb92d32 100644
--- a/source/blender/blenkernel/intern/crazyspace.cc
+++ b/source/blender/blenkernel/intern/crazyspace.cc
@@ -188,7 +188,7 @@ void BKE_crazyspace_set_quats_mesh(Mesh *me,
BLI_bitmap *vert_tag = BLI_BITMAP_NEW(me->totvert, __func__);
/* first store two sets of tangent vectors in vertices, we derive it just from the face-edges */
- const Span<MVert> verts = me->verts();
+ const Span<float3> positions = me->positions();
const Span<MPoly> polys = me->polys();
const Span<MLoop> loops = me->loops();
@@ -214,9 +214,9 @@ void BKE_crazyspace_set_quats_mesh(Mesh *me,
co_next = origcos[ml_next->v];
}
else {
- co_prev = verts[ml_prev->v].co;
- co_curr = verts[ml_curr->v].co;
- co_next = verts[ml_next->v].co;
+ co_prev = positions[ml_prev->v];
+ co_curr = positions[ml_curr->v];
+ co_next = positions[ml_next->v];
}
set_crazy_vertex_quat(
diff --git a/source/blender/blenkernel/intern/curve_to_mesh_convert.cc b/source/blender/blenkernel/intern/curve_to_mesh_convert.cc
index 3a86068d8e8..26c56df3e81 100644
--- a/source/blender/blenkernel/intern/curve_to_mesh_convert.cc
+++ b/source/blender/blenkernel/intern/curve_to_mesh_convert.cc
@@ -191,7 +191,7 @@ static void fill_mesh_positions(const int main_point_num,
const Span<float3> tangents,
const Span<float3> normals,
const Span<float> radii,
- MutableSpan<MVert> mesh_positions)
+ MutableSpan<float3> mesh_positions)
{
if (profile_point_num == 1) {
for (const int i_ring : IndexRange(main_point_num)) {
@@ -200,9 +200,7 @@ static void fill_mesh_positions(const int main_point_num,
if (!radii.is_empty()) {
point_matrix.apply_scale(radii[i_ring]);
}
-
- MVert &vert = mesh_positions[i_ring];
- copy_v3_v3(vert.co, point_matrix * profile_positions.first());
+ mesh_positions[i_ring] = point_matrix * profile_positions.first();
}
}
else {
@@ -215,8 +213,7 @@ static void fill_mesh_positions(const int main_point_num,
const int ring_vert_start = i_ring * profile_point_num;
for (const int i_profile : IndexRange(profile_point_num)) {
- MVert &vert = mesh_positions[ring_vert_start + i_profile];
- copy_v3_v3(vert.co, point_matrix * profile_positions[i_profile]);
+ mesh_positions[ring_vert_start + i_profile] = point_matrix * profile_positions[i_profile];
}
}
}
@@ -644,7 +641,7 @@ Mesh *curve_to_mesh_sweep(const CurvesGeometry &main,
offsets.vert.last(), offsets.edge.last(), 0, offsets.loop.last(), offsets.poly.last());
mesh->flag |= ME_AUTOSMOOTH;
mesh->smoothresh = DEG2RADF(180.0f);
- MutableSpan<MVert> verts = mesh->verts_for_write();
+ MutableSpan<float3> positions = mesh->positions_for_write();
MutableSpan<MEdge> edges = mesh->edges_for_write();
MutableSpan<MPoly> polys = mesh->polys_for_write();
MutableSpan<MLoop> loops = mesh->loops_for_write();
@@ -692,7 +689,7 @@ Mesh *curve_to_mesh_sweep(const CurvesGeometry &main,
tangents.slice(info.main_points),
normals.slice(info.main_points),
radii.is_empty() ? radii : radii.slice(info.main_points),
- verts.slice(info.vert_range));
+ positions.slice(info.vert_range));
});
if (profile.curve_type_counts()[CURVE_TYPE_BEZIER] > 0) {
diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc
index 84aa2207400..198d794b249 100644
--- a/source/blender/blenkernel/intern/customdata.cc
+++ b/source/blender/blenkernel/intern/customdata.cc
@@ -1639,7 +1639,7 @@ static void layerInterp_propbool(const void **sources,
}
static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
- /* 0: CD_MVERT */
+ /* 0: CD_MVERT */ /* DEPRECATED */
{sizeof(MVert), "MVert", 1, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
/* 1: CD_MSTICKY */ /* DEPRECATED */
{sizeof(float[2]), "", 1, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
@@ -2107,22 +2107,22 @@ static const char *LAYERTYPENAMES[CD_NUMTYPES] = {
};
const CustomData_MeshMasks CD_MASK_BAREMESH = {
- /* vmask */ CD_MASK_MVERT,
+ /* vmask */ CD_MASK_PROP_FLOAT3,
/* emask */ CD_MASK_MEDGE,
/* fmask */ 0,
/* pmask */ CD_MASK_MPOLY | CD_MASK_FACEMAP,
/* lmask */ CD_MASK_MLOOP,
};
const CustomData_MeshMasks CD_MASK_BAREMESH_ORIGINDEX = {
- /* vmask */ CD_MASK_MVERT | CD_MASK_ORIGINDEX,
+ /* vmask */ CD_MASK_PROP_FLOAT3 | CD_MASK_ORIGINDEX,
/* emask */ CD_MASK_MEDGE | CD_MASK_ORIGINDEX,
/* fmask */ 0,
/* pmask */ CD_MASK_MPOLY | CD_MASK_FACEMAP | CD_MASK_ORIGINDEX,
/* lmask */ CD_MASK_MLOOP,
};
const CustomData_MeshMasks CD_MASK_MESH = {
- /* vmask */ (CD_MASK_MVERT | CD_MASK_MDEFORMVERT | CD_MASK_MVERT_SKIN | CD_MASK_PAINT_MASK |
- CD_MASK_PROP_ALL | CD_MASK_CREASE | CD_MASK_BWEIGHT),
+ /* vmask */ (CD_MASK_PROP_FLOAT3 | CD_MASK_MDEFORMVERT | CD_MASK_MVERT_SKIN |
+ CD_MASK_PAINT_MASK | CD_MASK_PROP_ALL | CD_MASK_CREASE | CD_MASK_BWEIGHT),
/* emask */
(CD_MASK_MEDGE | CD_MASK_FREESTYLE_EDGE | CD_MASK_PROP_ALL | CD_MASK_BWEIGHT | CD_MASK_CREASE),
/* fmask */ 0,
@@ -2158,7 +2158,7 @@ const CustomData_MeshMasks CD_MASK_BMESH = {
CD_MASK_PROP_ALL),
};
const CustomData_MeshMasks CD_MASK_EVERYTHING = {
- /* vmask */ (CD_MASK_MVERT | CD_MASK_BM_ELEM_PYPTR | CD_MASK_ORIGINDEX | CD_MASK_MDEFORMVERT |
+ /* vmask */ (CD_MASK_BM_ELEM_PYPTR | CD_MASK_ORIGINDEX | CD_MASK_MDEFORMVERT |
CD_MASK_BWEIGHT | CD_MASK_MVERT_SKIN | CD_MASK_ORCO | CD_MASK_CLOTH_ORCO |
CD_MASK_SHAPEKEY | CD_MASK_SHAPE_KEYINDEX | CD_MASK_PAINT_MASK |
CD_MASK_PROP_ALL | CD_MASK_CREASE),
@@ -2374,6 +2374,7 @@ bool CustomData_merge(const CustomData *source,
static bool attribute_stored_in_bmesh_flag(const StringRef name)
{
return ELEM(name,
+ "position",
".hide_vert",
".hide_edge",
".hide_poly",
diff --git a/source/blender/blenkernel/intern/data_transfer.c b/source/blender/blenkernel/intern/data_transfer.c
index e6afca11b40..8de22195674 100644
--- a/source/blender/blenkernel/intern/data_transfer.c
+++ b/source/blender/blenkernel/intern/data_transfer.c
@@ -257,7 +257,7 @@ static void data_transfer_dtdata_type_preprocess(Mesh *me_src,
if (dtdata_type == DT_TYPE_LNOR) {
/* Compute custom normals into regular loop normals, which will be used for the transfer. */
- const MVert *verts_dst = BKE_mesh_verts(me_dst);
+ const float(*positions_dst)[3] = BKE_mesh_positions(me_dst);
const int num_verts_dst = me_dst->totvert;
const MEdge *edges_dst = BKE_mesh_edges(me_dst);
const int num_edges_dst = me_dst->totedge;
@@ -286,7 +286,7 @@ static void data_transfer_dtdata_type_preprocess(Mesh *me_src,
CustomData_set_layer_flag(ldata_dst, CD_NORMAL, CD_FLAG_TEMPORARY);
}
if (dirty_nors_dst || do_loop_nors_dst) {
- BKE_mesh_normals_loop_split(verts_dst,
+ BKE_mesh_normals_loop_split(positions_dst,
BKE_mesh_vertex_normals_ensure(me_dst),
num_verts_dst,
edges_dst,
@@ -319,7 +319,7 @@ static void data_transfer_dtdata_type_postprocess(Object *UNUSED(ob_src),
}
/* Bake edited destination loop normals into custom normals again. */
- const MVert *verts_dst = BKE_mesh_verts(me_dst);
+ const float(*positions_dst)[3] = BKE_mesh_positions(me_dst);
const int num_verts_dst = me_dst->totvert;
MEdge *edges_dst = BKE_mesh_edges_for_write(me_dst);
const int num_edges_dst = me_dst->totedge;
@@ -339,7 +339,7 @@ static void data_transfer_dtdata_type_postprocess(Object *UNUSED(ob_src),
}
/* Note loop_nors_dst contains our custom normals as transferred from source... */
- BKE_mesh_normals_loop_custom_set(verts_dst,
+ BKE_mesh_normals_loop_custom_set(positions_dst,
BKE_mesh_vertex_normals_ensure(me_dst),
num_verts_dst,
edges_dst,
@@ -927,7 +927,7 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map,
}
if (cddata_type == CD_FAKE_SHAPEKEY) {
/* TODO: leaving shape-keys aside for now, quite specific case,
- * since we can't access them from #MVert :/ */
+ * since we can't access them from mesh vertices :/ */
return false;
}
}
@@ -1309,7 +1309,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph,
}
BKE_mesh_remap_find_best_match_from_mesh(
- BKE_mesh_verts(me_dst), me_dst->totvert, me_src, space_transform);
+ BKE_mesh_positions(me_dst), me_dst->totvert, me_src, space_transform);
}
/* Check all possible data types.
@@ -1337,7 +1337,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph,
}
if (DT_DATATYPE_IS_VERT(dtdata_type)) {
- MVert *verts_dst = BKE_mesh_verts_for_write(me_dst);
+ float(*positions_dst)[3] = BKE_mesh_positions_for_write(me_dst);
const int num_verts_dst = me_dst->totvert;
if (!geom_map_init[VDATA]) {
@@ -1376,7 +1376,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph,
space_transform,
max_distance,
ray_radius,
- verts_dst,
+ positions_dst,
num_verts_dst,
dirty_nors_dst,
me_src,
@@ -1419,7 +1419,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph,
}
}
if (DT_DATATYPE_IS_EDGE(dtdata_type)) {
- const MVert *verts_dst = BKE_mesh_verts_for_write(me_dst);
+ const float(*positions_dst)[3] = BKE_mesh_positions_for_write(me_dst);
const int num_verts_dst = me_dst->totvert;
const MEdge *edges_dst = BKE_mesh_edges(me_dst);
const int num_edges_dst = me_dst->totedge;
@@ -1453,7 +1453,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph,
space_transform,
max_distance,
ray_radius,
- verts_dst,
+ positions_dst,
num_verts_dst,
edges_dst,
num_edges_dst,
@@ -1498,7 +1498,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph,
}
}
if (DT_DATATYPE_IS_LOOP(dtdata_type)) {
- const MVert *verts_dst = BKE_mesh_verts(me_dst);
+ const float(*positions_dst)[3] = BKE_mesh_positions(me_dst);
const int num_verts_dst = me_dst->totvert;
const MEdge *edges_dst = BKE_mesh_edges(me_dst);
const int num_edges_dst = me_dst->totedge;
@@ -1540,7 +1540,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph,
max_distance,
ray_radius,
me_dst,
- verts_dst,
+ positions_dst,
num_verts_dst,
edges_dst,
num_edges_dst,
@@ -1593,7 +1593,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph,
}
}
if (DT_DATATYPE_IS_POLY(dtdata_type)) {
- const MVert *verts_dst = BKE_mesh_verts(me_dst);
+ const float(*positions_dst)[3] = BKE_mesh_positions(me_dst);
const int num_verts_dst = me_dst->totvert;
const MPoly *polys_dst = BKE_mesh_polys(me_dst);
const int num_polys_dst = me_dst->totpoly;
@@ -1630,7 +1630,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph,
max_distance,
ray_radius,
me_dst,
- verts_dst,
+ positions_dst,
loops_dst,
polys_dst,
num_polys_dst,
diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c
index e0ae3f42be6..5cc1da276d5 100644
--- a/source/blender/blenkernel/intern/dynamicpaint.c
+++ b/source/blender/blenkernel/intern/dynamicpaint.c
@@ -201,7 +201,7 @@ typedef struct PaintBakeData {
* 3 float dir vec + 1 float str */
float *brush_velocity;
/** copy of previous frame vertices. used to observe surface movement. */
- MVert *prev_verts;
+ float (*prev_positions)[3];
/** Previous frame object matrix. */
float prev_obmat[4][4];
/** flag to check if surface was cleared/reset -> have to redo velocity etc. */
@@ -900,8 +900,8 @@ static void free_bakeData(PaintSurfaceData *data)
if (bData->grid) {
freeGrid(data);
}
- if (bData->prev_verts) {
- MEM_freeN(bData->prev_verts);
+ if (bData->prev_positions) {
+ MEM_freeN(bData->prev_positions);
}
if (bData->velocity) {
MEM_freeN(bData->velocity);
@@ -1774,7 +1774,7 @@ typedef struct DynamicPaintModifierApplyData {
const DynamicPaintSurface *surface;
Object *ob;
- MVert *mvert;
+ float (*positions)[3];
const float (*vert_normals)[3];
const MLoop *mloop;
const MPoly *mpoly;
@@ -1791,13 +1791,11 @@ static void dynamic_paint_apply_surface_displace_cb(void *__restrict userdata,
const DynamicPaintModifierApplyData *data = userdata;
const DynamicPaintSurface *surface = data->surface;
- MVert *mvert = data->mvert;
const float *value = (float *)surface->data->type_data;
const float val = value[i] * surface->disp_factor;
- /* same as 'mvert[i].co[0] -= normal[0] * val' etc. */
- madd_v3_v3fl(mvert[i].co, data->vert_normals[i], -val);
+ madd_v3_v3fl(data->positions[i], data->vert_normals[i], -val);
}
/* apply displacing vertex surface to the derived mesh */
@@ -1811,11 +1809,11 @@ static void dynamicPaint_applySurfaceDisplace(DynamicPaintSurface *surface, Mesh
/* displace paint */
if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE) {
- MVert *mvert = BKE_mesh_verts_for_write(result);
+ float(*positions)[3] = BKE_mesh_positions_for_write(result);
DynamicPaintModifierApplyData data = {
.surface = surface,
- .mvert = mvert,
+ .positions = positions,
.vert_normals = BKE_mesh_vertex_normals_ensure(result),
};
TaskParallelSettings settings;
@@ -1882,9 +1880,8 @@ static void dynamic_paint_apply_surface_wave_cb(void *__restrict userdata,
const DynamicPaintModifierApplyData *data = userdata;
PaintWavePoint *wPoint = (PaintWavePoint *)data->surface->data->type_data;
- MVert *mvert = data->mvert;
- madd_v3_v3fl(mvert[i].co, data->vert_normals[i], wPoint[i].height);
+ madd_v3_v3fl(data->positions[i], data->vert_normals[i], wPoint[i].height);
}
/*
@@ -2010,11 +2007,11 @@ static Mesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, Object *
}
/* wave simulation */
else if (surface->type == MOD_DPAINT_SURFACE_T_WAVE) {
- MVert *mvert = BKE_mesh_verts_for_write(result);
+ float(*positions)[3] = BKE_mesh_positions_for_write(result);
DynamicPaintModifierApplyData data = {
.surface = surface,
- .mvert = mvert,
+ .positions = positions,
.vert_normals = BKE_mesh_vertex_normals_ensure(result),
};
TaskParallelSettings settings;
@@ -2961,7 +2958,6 @@ int dynamicPaint_createUVSurface(Scene *scene,
BKE_mesh_vert_looptri_map_create(&vert_to_looptri_map,
&vert_to_looptri_map_mem,
- BKE_mesh_verts_for_write(mesh),
mesh->totvert,
mlooptri,
tottri,
@@ -3413,16 +3409,16 @@ static void mesh_tris_spherecast_dp(void *userdata,
BVHTreeRayHit *hit)
{
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
- const MVert *vert = data->vert;
+ const float(*positions)[3] = data->positions;
const MLoopTri *mlooptri = data->looptri;
const MLoop *mloop = data->loop;
const float *t0, *t1, *t2;
float dist;
- t0 = vert[mloop[mlooptri[index].tri[0]].v].co;
- t1 = vert[mloop[mlooptri[index].tri[1]].v].co;
- t2 = vert[mloop[mlooptri[index].tri[2]].v].co;
+ t0 = positions[mloop[mlooptri[index].tri[0]].v];
+ t1 = positions[mloop[mlooptri[index].tri[1]].v];
+ t2 = positions[mloop[mlooptri[index].tri[2]].v];
dist = bvhtree_ray_tri_intersection(ray, hit->dist, t0, t1, t2);
@@ -3445,15 +3441,15 @@ static void mesh_tris_nearest_point_dp(void *userdata,
BVHTreeNearest *nearest)
{
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
- const MVert *vert = data->vert;
+ const float(*positions)[3] = data->positions;
const MLoopTri *mlooptri = data->looptri;
const MLoop *mloop = data->loop;
float nearest_tmp[3], dist_sq;
const float *t0, *t1, *t2;
- t0 = vert[mloop[mlooptri[index].tri[0]].v].co;
- t1 = vert[mloop[mlooptri[index].tri[1]].v].co;
- t2 = vert[mloop[mlooptri[index].tri[2]].v].co;
+ t0 = positions[mloop[mlooptri[index].tri[0]].v];
+ t1 = positions[mloop[mlooptri[index].tri[1]].v];
+ t2 = positions[mloop[mlooptri[index].tri[2]].v];
closest_on_tri_to_point_v3(nearest_tmp, co, t0, t1, t2);
dist_sq = len_squared_v3v3(co, nearest_tmp);
@@ -3709,8 +3705,8 @@ static bool meshBrush_boundsIntersect(Bounds3D *b1,
typedef struct DynamicPaintBrushVelocityData {
Vec3f *brush_vel;
- const MVert *mvert_p;
- const MVert *mvert_c;
+ const float (*positions_p)[3];
+ const float (*positions_c)[3];
float (*obmat)[4];
float (*prev_obmat)[4];
@@ -3726,8 +3722,8 @@ static void dynamic_paint_brush_velocity_compute_cb(void *__restrict userdata,
Vec3f *brush_vel = data->brush_vel;
- const MVert *mvert_p = data->mvert_p;
- const MVert *mvert_c = data->mvert_c;
+ const float(*positions_p)[3] = data->positions_p;
+ const float(*positions_c)[3] = data->positions_c;
float(*obmat)[4] = data->obmat;
float(*prev_obmat)[4] = data->prev_obmat;
@@ -3736,10 +3732,10 @@ static void dynamic_paint_brush_velocity_compute_cb(void *__restrict userdata,
float p1[3], p2[3];
- copy_v3_v3(p1, mvert_p[i].co);
+ copy_v3_v3(p1, positions_p[i]);
mul_m4_v3(prev_obmat, p1);
- copy_v3_v3(p2, mvert_c[i].co);
+ copy_v3_v3(p2, positions_c[i]);
mul_m4_v3(obmat, p2);
sub_v3_v3v3(brush_vel[i].v, p2, p1);
@@ -3755,7 +3751,6 @@ static void dynamicPaint_brushMeshCalculateVelocity(Depsgraph *depsgraph,
{
float prev_obmat[4][4];
Mesh *mesh_p, *mesh_c;
- MVert *mvert_p, *mvert_c;
int numOfVerts_p, numOfVerts_c;
float cur_sfra = scene->r.subframe;
@@ -3782,7 +3777,7 @@ static void dynamicPaint_brushMeshCalculateVelocity(Depsgraph *depsgraph,
mesh_p = BKE_mesh_copy_for_eval(dynamicPaint_brush_mesh_get(brush), false);
numOfVerts_p = mesh_p->totvert;
- mvert_p = BKE_mesh_verts_for_write(mesh_p);
+ float(*positions_p)[3] = BKE_mesh_positions_for_write(mesh_p);
copy_m4_m4(prev_obmat, ob->object_to_world);
/* current frame mesh */
@@ -3798,7 +3793,7 @@ static void dynamicPaint_brushMeshCalculateVelocity(Depsgraph *depsgraph,
eModifierType_DynamicPaint);
mesh_c = dynamicPaint_brush_mesh_get(brush);
numOfVerts_c = mesh_c->totvert;
- mvert_c = BKE_mesh_verts_for_write(mesh_c);
+ float(*positions_c)[3] = BKE_mesh_positions_for_write(mesh_c);
(*brushVel) = (struct Vec3f *)MEM_mallocN(numOfVerts_c * sizeof(Vec3f),
"Dynamic Paint brush velocity");
@@ -3808,14 +3803,14 @@ static void dynamicPaint_brushMeshCalculateVelocity(Depsgraph *depsgraph,
/* if mesh is constructive -> num of verts has changed, only use current frame derived mesh */
if (numOfVerts_p != numOfVerts_c) {
- mvert_p = mvert_c;
+ positions_p = positions_c;
}
/* calculate speed */
DynamicPaintBrushVelocityData data = {
.brush_vel = *brushVel,
- .mvert_p = mvert_p,
- .mvert_c = mvert_c,
+ .positions_p = positions_p,
+ .positions_c = positions_c,
.obmat = ob->object_to_world,
.prev_obmat = prev_obmat,
.timescale = timescale,
@@ -3886,7 +3881,7 @@ typedef struct DynamicPaintPaintData {
const int c_index;
Mesh *mesh;
- const MVert *mvert;
+ const float (*positions)[3];
const MLoop *mloop;
const MLoopTri *mlooptri;
const float brush_radius;
@@ -3919,7 +3914,7 @@ static void dynamic_paint_paint_mesh_cell_point_cb_ex(
const float timescale = data->timescale;
const int c_index = data->c_index;
- const MVert *mvert = data->mvert;
+ const float(*positions)[3] = data->positions;
const MLoop *mloop = data->mloop;
const MLoopTri *mlooptri = data->mlooptri;
const float brush_radius = data->brush_radius;
@@ -4000,7 +3995,7 @@ static void dynamic_paint_paint_mesh_cell_point_cb_ex(
};
float dot;
- normal_tri_v3(hit.no, mvert[vtri[0]].co, mvert[vtri[1]].co, mvert[vtri[2]].co);
+ normal_tri_v3(hit.no, positions[vtri[0]], positions[vtri[1]], positions[vtri[2]]);
dot = dot_v3v3(ray_dir, hit.no);
/* If ray and hit face normal are facing same direction
@@ -4149,7 +4144,7 @@ static void dynamic_paint_paint_mesh_cell_point_cb_ex(
const int v3 = mloop[mlooptri[hitTri].tri[2]].v;
/* calculate barycentric weights for hit point */
- interp_weights_tri_v3(weights, mvert[v1].co, mvert[v2].co, mvert[v3].co, hitCoord);
+ interp_weights_tri_v3(weights, positions[v1], positions[v2], positions[v3], hitCoord);
/* Simple check based on brush surface velocity,
* TODO: perhaps implement something that handles volume movement as well. */
@@ -4245,7 +4240,6 @@ static bool dynamicPaint_paintMesh(Depsgraph *depsgraph,
PaintBakeData *bData = sData->bData;
Mesh *mesh = NULL;
Vec3f *brushVelocity = NULL;
- MVert *mvert = NULL;
const MLoopTri *mlooptri = NULL;
const MLoop *mloop = NULL;
@@ -4269,7 +4263,7 @@ static bool dynamicPaint_paintMesh(Depsgraph *depsgraph,
VolumeGrid *grid = bData->grid;
mesh = BKE_mesh_copy_for_eval(brush_mesh, false);
- mvert = BKE_mesh_verts_for_write(mesh);
+ float(*positions)[3] = BKE_mesh_positions_for_write(mesh);
const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(mesh);
mlooptri = BKE_mesh_runtime_looptri_ensure(mesh);
mloop = BKE_mesh_loops(mesh);
@@ -4279,8 +4273,8 @@ static bool dynamicPaint_paintMesh(Depsgraph *depsgraph,
* (Faster than transforming per surface point
* coordinates and normals to object space) */
for (ii = 0; ii < numOfVerts; ii++) {
- mul_m4_v3(brushOb->object_to_world, mvert[ii].co);
- boundInsert(&mesh_bb, mvert[ii].co);
+ mul_m4_v3(brushOb->object_to_world, positions[ii]);
+ boundInsert(&mesh_bb, positions[ii]);
/* for proximity project calculate average normal */
if (brush->flags & MOD_DPAINT_PROX_PROJECT && brush->collision != MOD_DPAINT_COL_VOLUME) {
@@ -4325,7 +4319,7 @@ static bool dynamicPaint_paintMesh(Depsgraph *depsgraph,
.timescale = timescale,
.c_index = c_index,
.mesh = mesh,
- .mvert = mvert,
+ .positions = positions,
.mloop = mloop,
.mlooptri = mlooptri,
.brush_radius = brush_radius,
@@ -4758,7 +4752,7 @@ static bool dynamicPaint_paintSinglePoint(
}
const Mesh *brush_mesh = dynamicPaint_brush_mesh_get(brush);
- const MVert *mvert = BKE_mesh_verts(brush_mesh);
+ const float(*positions)[3] = BKE_mesh_positions(brush_mesh);
/*
* Loop through every surface point
@@ -4769,7 +4763,7 @@ static bool dynamicPaint_paintSinglePoint(
.brushOb = brushOb,
.scene = scene,
.timescale = timescale,
- .mvert = mvert,
+ .positions = positions,
.brush_radius = brush_radius,
.brushVelocity = &brushVel,
.pointCoord = pointCoord,
@@ -5861,11 +5855,11 @@ static bool dynamicPaint_surfaceHasMoved(DynamicPaintSurface *surface, Object *o
PaintSurfaceData *sData = surface->data;
PaintBakeData *bData = sData->bData;
Mesh *mesh = dynamicPaint_canvas_mesh_get(surface->canvas);
- const MVert *mvert = BKE_mesh_verts(mesh);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
int numOfVerts = mesh->totvert;
- if (!bData->prev_verts) {
+ if (!bData->prev_positions) {
return true;
}
@@ -5876,7 +5870,7 @@ static bool dynamicPaint_surfaceHasMoved(DynamicPaintSurface *surface, Object *o
/* vertices */
for (int i = 0; i < numOfVerts; i++) {
- if (!equals_v3v3(bData->prev_verts[i].co, mvert[i].co)) {
+ if (!equals_v3v3(bData->prev_positions[i], positions[i])) {
return true;
}
}
@@ -5889,7 +5883,7 @@ typedef struct DynamicPaintGenerateBakeData {
const DynamicPaintSurface *surface;
Object *ob;
- const MVert *mvert;
+ const float (*positions)[3];
const float (*vert_normals)[3];
const Vec3f *canvas_verts;
@@ -6021,7 +6015,7 @@ static bool dynamicPaint_generateBakeData(DynamicPaintSurface *surface,
const bool do_accel_data = (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP) != 0;
int canvasNumOfVerts = mesh->totvert;
- const MVert *mvert = BKE_mesh_verts(mesh);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
Vec3f *canvas_verts;
if (bData) {
@@ -6067,8 +6061,8 @@ static bool dynamicPaint_generateBakeData(DynamicPaintSurface *surface,
bData->s_num = MEM_mallocN(sData->total_points * sizeof(uint), "Dynamic Paint bData s_num");
bData->realCoord = (struct Vec3f *)MEM_mallocN(surface_totalSamples(surface) * sizeof(Vec3f),
"Dynamic Paint point coords");
- bData->prev_verts = MEM_mallocN(canvasNumOfVerts * sizeof(MVert),
- "Dynamic Paint bData prev_verts");
+ bData->prev_positions = MEM_mallocN(canvasNumOfVerts * sizeof(float[3]),
+ "Dynamic Paint bData prev_positions");
/* if any allocation failed, free everything */
if (!bData->bNormal || !bData->s_pos || !bData->s_num || !bData->realCoord || !canvas_verts) {
@@ -6112,7 +6106,7 @@ static bool dynamicPaint_generateBakeData(DynamicPaintSurface *surface,
*/
bData->mesh_bounds.valid = false;
for (index = 0; index < canvasNumOfVerts; index++) {
- copy_v3_v3(canvas_verts[index].v, mvert[index].co);
+ copy_v3_v3(canvas_verts[index].v, positions[index]);
mul_m4_v3(ob->object_to_world, canvas_verts[index].v);
boundInsert(&bData->mesh_bounds, canvas_verts[index].v);
}
@@ -6123,7 +6117,7 @@ static bool dynamicPaint_generateBakeData(DynamicPaintSurface *surface,
DynamicPaintGenerateBakeData data = {
.surface = surface,
.ob = ob,
- .mvert = mvert,
+ .positions = positions,
.vert_normals = BKE_mesh_vertex_normals_ensure(mesh),
.canvas_verts = canvas_verts,
.do_velocity_data = do_velocity_data,
@@ -6144,7 +6138,7 @@ static bool dynamicPaint_generateBakeData(DynamicPaintSurface *surface,
/* Copy current frame vertices to check against in next frame */
copy_m4_m4(bData->prev_obmat, ob->object_to_world);
- memcpy(bData->prev_verts, mvert, canvasNumOfVerts * sizeof(MVert));
+ memcpy(bData->prev_positions, positions, canvasNumOfVerts * sizeof(float[3]));
bData->clear = 0;
diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c
index c2ae4efbde8..3222b9857bf 100644
--- a/source/blender/blenkernel/intern/effect.c
+++ b/source/blender/blenkernel/intern/effect.c
@@ -663,9 +663,9 @@ bool closest_point_on_surface(SurfaceModifierData *surmd,
const MLoop *mloop = surmd->bvhtree->loop;
const MLoopTri *lt = &surmd->bvhtree->looptri[nearest.index];
- copy_v3_v3(surface_vel, surmd->v[mloop[lt->tri[0]].v].co);
- add_v3_v3(surface_vel, surmd->v[mloop[lt->tri[1]].v].co);
- add_v3_v3(surface_vel, surmd->v[mloop[lt->tri[2]].v].co);
+ copy_v3_v3(surface_vel, surmd->v[mloop[lt->tri[0]].v]);
+ add_v3_v3(surface_vel, surmd->v[mloop[lt->tri[1]].v]);
+ add_v3_v3(surface_vel, surmd->v[mloop[lt->tri[2]].v]);
mul_v3_fl(surface_vel, (1.0f / 3.0f));
}
@@ -701,10 +701,10 @@ bool get_effector_data(EffectorCache *eff,
else if (eff->pd && eff->pd->shape == PFIELD_SHAPE_POINTS) {
/* TODO: hair and points object support */
const Mesh *me_eval = BKE_object_get_evaluated_mesh(eff->ob);
- const MVert *verts = BKE_mesh_verts(me_eval);
+ const float(*positions)[3] = BKE_mesh_positions(me_eval);
const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(me_eval);
if (me_eval != NULL) {
- copy_v3_v3(efd->loc, verts[*efd->index].co);
+ copy_v3_v3(efd->loc, positions[*efd->index]);
copy_v3_v3(efd->nor, vert_normals[*efd->index]);
mul_m4_v3(eff->ob->object_to_world, efd->loc);
diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c
index c72f498cd5a..adba303f2b0 100644
--- a/source/blender/blenkernel/intern/fluid.c
+++ b/source/blender/blenkernel/intern/fluid.c
@@ -404,7 +404,7 @@ static void manta_set_domain_from_mesh(FluidDomainSettings *fds,
float min[3] = {FLT_MAX, FLT_MAX, FLT_MAX}, max[3] = {-FLT_MAX, -FLT_MAX, -FLT_MAX};
float size[3];
- MVert *verts = BKE_mesh_verts_for_write(me);
+ float(*positions)[3] = BKE_mesh_positions_for_write(me);
float scale = 0.0;
int res;
@@ -412,7 +412,7 @@ static void manta_set_domain_from_mesh(FluidDomainSettings *fds,
/* Set minimum and maximum coordinates of BB. */
for (i = 0; i < me->totvert; i++) {
- minmax_v3v3_v3(min, max, verts[i].co);
+ minmax_v3v3_v3(min, max, positions[i]);
}
/* Set domain bounds. */
@@ -840,7 +840,7 @@ BLI_INLINE void apply_effector_fields(FluidEffectorSettings *UNUSED(fes),
}
static void update_velocities(FluidEffectorSettings *fes,
- const MVert *mvert,
+ const float (*positions)[3],
const MLoop *mloop,
const MLoopTri *mlooptri,
float *velocity_map,
@@ -870,7 +870,7 @@ static void update_velocities(FluidEffectorSettings *fes,
v1 = mloop[mlooptri[f_index].tri[0]].v;
v2 = mloop[mlooptri[f_index].tri[1]].v;
v3 = mloop[mlooptri[f_index].tri[2]].v;
- interp_weights_tri_v3(weights, mvert[v1].co, mvert[v2].co, mvert[v3].co, nearest.co);
+ interp_weights_tri_v3(weights, positions[v1], positions[v2], positions[v3], nearest.co);
/* Apply object velocity. */
float hit_vel[3];
@@ -937,7 +937,7 @@ static void update_velocities(FluidEffectorSettings *fes,
typedef struct ObstaclesFromDMData {
FluidEffectorSettings *fes;
- const MVert *mvert;
+ const float (*positions)[3];
const MLoop *mloop;
const MLoopTri *mlooptri;
@@ -972,7 +972,7 @@ static void obstacles_from_mesh_task_cb(void *__restrict userdata,
/* Calculate object velocities. Result in bb->velocity. */
update_velocities(data->fes,
- data->mvert,
+ data->positions,
data->mloop,
data->mlooptri,
bb->velocity,
@@ -1005,7 +1005,7 @@ static void obstacles_from_mesh(Object *coll_ob,
bool has_velocity = false;
Mesh *me = BKE_mesh_copy_for_eval(fes->mesh, false);
- MVert *verts = BKE_mesh_verts_for_write(me);
+ float(*positions)[3] = BKE_mesh_positions_for_write(me);
int min[3], max[3], res[3];
@@ -1036,11 +1036,11 @@ static void obstacles_from_mesh(Object *coll_ob,
float co[3];
/* Vertex position. */
- mul_m4_v3(coll_ob->object_to_world, verts[i].co);
- manta_pos_to_cell(fds, verts[i].co);
+ mul_m4_v3(coll_ob->object_to_world, positions[i]);
+ manta_pos_to_cell(fds, positions[i]);
/* Vertex velocity. */
- add_v3fl_v3fl_v3i(co, verts[i].co, fds->shift);
+ add_v3fl_v3fl_v3i(co, positions[i], fds->shift);
if (has_velocity) {
sub_v3_v3v3(&vert_vel[i * 3], co, &fes->verts_old[i * 3]);
mul_v3_fl(&vert_vel[i * 3], 1.0f / dt);
@@ -1048,7 +1048,7 @@ static void obstacles_from_mesh(Object *coll_ob,
copy_v3_v3(&fes->verts_old[i * 3], co);
/* Calculate emission map bounds. */
- bb_boundInsert(bb, verts[i].co);
+ bb_boundInsert(bb, positions[i]);
}
/* Set emission map.
@@ -1070,7 +1070,7 @@ static void obstacles_from_mesh(Object *coll_ob,
ObstaclesFromDMData data = {
.fes = fes,
- .mvert = verts,
+ .positions = positions,
.mloop = mloop,
.mlooptri = looptri,
.tree = &tree_data,
@@ -1784,7 +1784,7 @@ static void update_distances(int index,
}
static void sample_mesh(FluidFlowSettings *ffs,
- const MVert *mvert,
+ const float (*positions)[3],
const float (*vert_normals)[3],
const MLoop *mloop,
const MLoopTri *mlooptri,
@@ -1872,7 +1872,7 @@ static void sample_mesh(FluidFlowSettings *ffs,
v1 = mloop[mlooptri[f_index].tri[0]].v;
v2 = mloop[mlooptri[f_index].tri[1]].v;
v3 = mloop[mlooptri[f_index].tri[2]].v;
- interp_weights_tri_v3(weights, mvert[v1].co, mvert[v2].co, mvert[v3].co, nearest.co);
+ interp_weights_tri_v3(weights, positions[v1], positions[v2], positions[v3], nearest.co);
/* Compute emission strength for smoke flow. */
if (is_gas_flow) {
@@ -1978,7 +1978,7 @@ typedef struct EmitFromDMData {
FluidDomainSettings *fds;
FluidFlowSettings *ffs;
- const MVert *mvert;
+ const float (*positions)[3];
const float (*vert_normals)[3];
const MLoop *mloop;
const MLoopTri *mlooptri;
@@ -2012,7 +2012,7 @@ static void emit_from_mesh_task_cb(void *__restrict userdata,
* Result in bb->influence. Also computes initial velocities. Result in bb->velocity. */
if (ELEM(data->ffs->behavior, FLUID_FLOW_BEHAVIOR_GEOMETRY, FLUID_FLOW_BEHAVIOR_INFLOW)) {
sample_mesh(data->ffs,
- data->mvert,
+ data->positions,
data->vert_normals,
data->mloop,
data->mlooptri,
@@ -2062,7 +2062,7 @@ static void emit_from_mesh(
/* Copy mesh for thread safety as we modify it.
* Main issue is its VertArray being modified, then replaced and freed. */
Mesh *me = BKE_mesh_copy_for_eval(ffs->mesh, false);
- MVert *verts = BKE_mesh_verts_for_write(me);
+ float(*positions)[3] = BKE_mesh_positions_for_write(me);
const MLoop *mloop = BKE_mesh_loops(me);
const MLoopTri *mlooptri = BKE_mesh_runtime_looptri_ensure(me);
@@ -2091,8 +2091,8 @@ static void emit_from_mesh(
float(*vert_normals)[3] = BKE_mesh_vertex_normals_for_write(me);
for (i = 0; i < numverts; i++) {
/* Vertex position. */
- mul_m4_v3(flow_ob->object_to_world, verts[i].co);
- manta_pos_to_cell(fds, verts[i].co);
+ mul_m4_v3(flow_ob->object_to_world, positions[i]);
+ manta_pos_to_cell(fds, positions[i]);
/* Vertex normal. */
mul_mat3_m4_v3(flow_ob->object_to_world, vert_normals[i]);
@@ -2102,7 +2102,7 @@ static void emit_from_mesh(
/* Vertex velocity. */
if (ffs->flags & FLUID_FLOW_INITVELOCITY) {
float co[3];
- add_v3fl_v3fl_v3i(co, verts[i].co, fds->shift);
+ add_v3fl_v3fl_v3i(co, positions[i], fds->shift);
if (has_velocity) {
sub_v3_v3v3(&vert_vel[i * 3], co, &ffs->verts_old[i * 3]);
mul_v3_fl(&vert_vel[i * 3], 1.0 / dt);
@@ -2111,7 +2111,7 @@ static void emit_from_mesh(
}
/* Calculate emission map bounds. */
- bb_boundInsert(bb, verts[i].co);
+ bb_boundInsert(bb, positions[i]);
}
mul_m4_v3(flow_ob->object_to_world, flow_center);
manta_pos_to_cell(fds, flow_center);
@@ -2136,7 +2136,7 @@ static void emit_from_mesh(
EmitFromDMData data = {
.fds = fds,
.ffs = ffs,
- .mvert = verts,
+ .positions = positions,
.vert_normals = vert_normals,
.mloop = mloop,
.mlooptri = mlooptri,
@@ -3204,7 +3204,6 @@ static Mesh *create_liquid_geometry(FluidDomainSettings *fds,
Object *ob)
{
Mesh *me;
- MVert *mverts;
MPoly *mpolys;
MLoop *mloops;
float min[3];
@@ -3248,7 +3247,7 @@ static Mesh *create_liquid_geometry(FluidDomainSettings *fds,
if (!me) {
return NULL;
}
- mverts = BKE_mesh_verts_for_write(me);
+ float(*positions)[3] = BKE_mesh_positions_for_write(me);
mpolys = BKE_mesh_polys_for_write(me);
mloops = BKE_mesh_loops_for_write(me);
@@ -3285,30 +3284,30 @@ static Mesh *create_liquid_geometry(FluidDomainSettings *fds,
}
/* Loop for vertices and normals. */
- for (i = 0; i < num_verts; i++, mverts++) {
+ for (i = 0; i < num_verts; i++) {
/* Vertices (data is normalized cube around domain origin). */
- mverts->co[0] = manta_liquid_get_vertex_x_at(fds->fluid, i);
- mverts->co[1] = manta_liquid_get_vertex_y_at(fds->fluid, i);
- mverts->co[2] = manta_liquid_get_vertex_z_at(fds->fluid, i);
+ positions[i][0] = manta_liquid_get_vertex_x_at(fds->fluid, i);
+ positions[i][1] = manta_liquid_get_vertex_y_at(fds->fluid, i);
+ positions[i][2] = manta_liquid_get_vertex_z_at(fds->fluid, i);
/* Adjust coordinates from Mantaflow to match viewport scaling. */
float tmp[3] = {(float)fds->res[0], (float)fds->res[1], (float)fds->res[2]};
/* Scale to unit cube around 0. */
mul_v3_fl(tmp, fds->mesh_scale * 0.5f);
- sub_v3_v3(mverts->co, tmp);
+ sub_v3_v3(positions[i], tmp);
/* Apply scaling of domain object. */
- mul_v3_fl(mverts->co, fds->dx / fds->mesh_scale);
+ mul_v3_fl(positions[i], fds->dx / fds->mesh_scale);
- mul_v3_v3(mverts->co, co_scale);
- add_v3_v3(mverts->co, co_offset);
+ mul_v3_v3(positions[i], co_scale);
+ add_v3_v3(positions[i], co_offset);
# ifdef DEBUG_PRINT
/* Debugging: Print coordinates of vertices. */
- printf("mverts->co[0]: %f, mverts->co[1]: %f, mverts->co[2]: %f\n",
- mverts->co[0],
- mverts->co[1],
- mverts->co[2]);
+ printf("positions[i][0]: %f, positions[i][1]: %f, positions[i][2]: %f\n",
+ positions[i][0],
+ positions[i][1],
+ positions[i][2]);
# endif
# ifdef DEBUG_PRINT
@@ -3364,7 +3363,6 @@ static Mesh *create_liquid_geometry(FluidDomainSettings *fds,
static Mesh *create_smoke_geometry(FluidDomainSettings *fds, Mesh *orgmesh, Object *ob)
{
Mesh *result;
- MVert *mverts;
MPoly *mpolys;
MLoop *mloops;
float min[3];
@@ -3384,7 +3382,7 @@ static Mesh *create_smoke_geometry(FluidDomainSettings *fds, Mesh *orgmesh, Obje
}
result = BKE_mesh_new_nomain(num_verts, 0, 0, num_faces * 4, num_faces);
- mverts = BKE_mesh_verts_for_write(result);
+ float(*positions)[3] = BKE_mesh_positions_for_write(result);
mpolys = BKE_mesh_polys_for_write(result);
mloops = BKE_mesh_loops_for_write(result);
@@ -3395,36 +3393,36 @@ static Mesh *create_smoke_geometry(FluidDomainSettings *fds, Mesh *orgmesh, Obje
/* Set vertices of smoke BB. Especially important, when BB changes (adaptive domain). */
/* Top slab */
- co = mverts[0].co;
+ co = positions[0];
co[0] = min[0];
co[1] = min[1];
co[2] = max[2];
- co = mverts[1].co;
+ co = positions[1];
co[0] = max[0];
co[1] = min[1];
co[2] = max[2];
- co = mverts[2].co;
+ co = positions[2];
co[0] = max[0];
co[1] = max[1];
co[2] = max[2];
- co = mverts[3].co;
+ co = positions[3];
co[0] = min[0];
co[1] = max[1];
co[2] = max[2];
/* Bottom slab. */
- co = mverts[4].co;
+ co = positions[4];
co[0] = min[0];
co[1] = min[1];
co[2] = min[2];
- co = mverts[5].co;
+ co = positions[5];
co[0] = max[0];
co[1] = min[1];
co[2] = min[2];
- co = mverts[6].co;
+ co = positions[6];
co[0] = max[0];
co[1] = max[1];
co[2] = min[2];
- co = mverts[7].co;
+ co = positions[7];
co[0] = min[0];
co[1] = max[1];
co[2] = min[2];
@@ -3495,7 +3493,7 @@ static Mesh *create_smoke_geometry(FluidDomainSettings *fds, Mesh *orgmesh, Obje
mul_mat3_m4_v3(ob->world_to_object, fds->obj_shift_f);
/* Apply shift to vertices. */
for (int i = 0; i < num_verts; i++) {
- add_v3_v3(mverts[i].co, fds->obj_shift_f);
+ add_v3_v3(positions[i], fds->obj_shift_f);
}
}
diff --git a/source/blender/blenkernel/intern/geometry_component_mesh.cc b/source/blender/blenkernel/intern/geometry_component_mesh.cc
index d148d59a48b..4efa54169ac 100644
--- a/source/blender/blenkernel/intern/geometry_component_mesh.cc
+++ b/source/blender/blenkernel/intern/geometry_component_mesh.cc
@@ -902,16 +902,6 @@ static GVMutableArray make_derived_write_attribute(void *data, const int domain_
MutableSpan<StructT>((StructT *)data, domain_num));
}
-static float3 get_vertex_position(const MVert &vert)
-{
- return float3(vert.co);
-}
-
-static void set_vertex_position(MVert &vert, float3 position)
-{
- copy_v3_v3(vert.co, position);
-}
-
static void tag_component_positions_changed(void *owner)
{
Mesh *mesh = static_cast<Mesh *>(owner);
@@ -1228,18 +1218,17 @@ static ComponentAttributeProviders create_attribute_providers_for_mesh()
#undef MAKE_CONST_CUSTOM_DATA_GETTER
#undef MAKE_MUTABLE_CUSTOM_DATA_GETTER
- static BuiltinCustomDataLayerProvider position(
- "position",
- ATTR_DOMAIN_POINT,
- CD_PROP_FLOAT3,
- CD_MVERT,
- BuiltinAttributeProvider::NonCreatable,
- BuiltinAttributeProvider::Writable,
- BuiltinAttributeProvider::NonDeletable,
- point_access,
- make_derived_read_attribute<MVert, float3, get_vertex_position>,
- make_derived_write_attribute<MVert, float3, get_vertex_position, set_vertex_position>,
- tag_component_positions_changed);
+ static BuiltinCustomDataLayerProvider position("position",
+ ATTR_DOMAIN_POINT,
+ CD_PROP_FLOAT3,
+ CD_PROP_FLOAT3,
+ BuiltinAttributeProvider::NonCreatable,
+ BuiltinAttributeProvider::Writable,
+ BuiltinAttributeProvider::NonDeletable,
+ point_access,
+ make_array_read_attribute<float3>,
+ make_array_write_attribute<float3>,
+ tag_component_positions_changed);
static NormalAttributeProvider normal;
diff --git a/source/blender/blenkernel/intern/gpencil_geom.cc b/source/blender/blenkernel/intern/gpencil_geom.cc
index 9297663b157..b866ad4d8a8 100644
--- a/source/blender/blenkernel/intern/gpencil_geom.cc
+++ b/source/blender/blenkernel/intern/gpencil_geom.cc
@@ -2471,7 +2471,7 @@ static void gpencil_generate_edgeloops(Object *ob,
if (me->totedge == 0) {
return;
}
- const Span<MVert> verts = me->verts();
+ const Span<float3> positions = me->positions();
const Span<MEdge> edges = me->edges();
const Span<MDeformVert> dverts = me->deform_verts();
const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(me);
@@ -2488,18 +2488,16 @@ static void gpencil_generate_edgeloops(Object *ob,
for (int i = 0; i < me->totedge; i++) {
const MEdge *ed = &edges[i];
gped = &gp_edges[i];
- const MVert *mv1 = &verts[ed->v1];
copy_v3_v3(gped->n1, vert_normals[ed->v1]);
gped->v1 = ed->v1;
- copy_v3_v3(gped->v1_co, mv1->co);
+ copy_v3_v3(gped->v1_co, positions[ed->v1]);
- const MVert *mv2 = &verts[ed->v2];
copy_v3_v3(gped->n2, vert_normals[ed->v2]);
gped->v2 = ed->v2;
- copy_v3_v3(gped->v2_co, mv2->co);
+ copy_v3_v3(gped->v2_co, positions[ed->v2]);
- sub_v3_v3v3(gped->vec, mv1->co, mv2->co);
+ sub_v3_v3v3(gped->vec, positions[ed->v1], positions[ed->v2]);
/* If use seams, mark as done if not a seam. */
if ((use_seams) && ((ed->flag & ME_SEAM) == 0)) {
@@ -2559,13 +2557,11 @@ static void gpencil_generate_edgeloops(Object *ob,
float fpt[3];
for (int i = 0; i < array_len + 1; i++) {
int vertex_index = i == 0 ? gp_edges[stroke[0]].v1 : gp_edges[stroke[i - 1]].v2;
- const MVert *mv = &verts[vertex_index];
-
/* Add segment. */
bGPDspoint *pt = &gps_stroke->points[i];
copy_v3_v3(fpt, vert_normals[vertex_index]);
mul_v3_v3fl(fpt, fpt, offset);
- add_v3_v3v3(&pt->x, mv->co, fpt);
+ add_v3_v3v3(&pt->x, positions[vertex_index], fpt);
mul_m4_v3(matrix, &pt->x);
pt->pressure = 1.0f;
@@ -2683,7 +2679,7 @@ bool BKE_gpencil_convert_mesh(Main *bmain,
/* Use evaluated data to get mesh with all modifiers on top. */
Object *ob_eval = (Object *)DEG_get_evaluated_object(depsgraph, ob_mesh);
const Mesh *me_eval = BKE_object_get_evaluated_mesh(ob_eval);
- const Span<MVert> verts = me_eval->verts();
+ const Span<float3> positions = me_eval->positions();
const Span<MPoly> polys = me_eval->polys();
const Span<MLoop> loops = me_eval->loops();
int mpoly_len = me_eval->totpoly;
@@ -2758,10 +2754,9 @@ bool BKE_gpencil_convert_mesh(Main *bmain,
/* Add points to strokes. */
for (int j = 0; j < mp->totloop; j++) {
const MLoop *ml = &loops[mp->loopstart + j];
- const MVert *mv = &verts[ml->v];
bGPDspoint *pt = &gps_fill->points[j];
- copy_v3_v3(&pt->x, mv->co);
+ copy_v3_v3(&pt->x, positions[ml->v]);
mul_m4_v3(matrix, &pt->x);
pt->pressure = 1.0f;
pt->strength = 1.0f;
diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c
index 2ba81c54872..010b45f4778 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -1507,7 +1507,6 @@ static void do_latt_key(Object *ob, Key *key, char *out, const int tot)
}
}
-static void keyblock_data_convert_to_mesh(const float (*fp)[3], MVert *mvert, const int totvert);
static void keyblock_data_convert_to_lattice(const float (*fp)[3],
BPoint *bpoint,
const int totpoint);
@@ -1607,9 +1606,9 @@ float *BKE_key_evaluate_object_ex(
switch (GS(obdata->name)) {
case ID_ME: {
Mesh *mesh = (Mesh *)obdata;
- MVert *verts = BKE_mesh_verts_for_write(mesh);
+ const float(*positions)[3] = BKE_mesh_positions_for_write(mesh);
const int totvert = min_ii(tot, mesh->totvert);
- keyblock_data_convert_to_mesh((const float(*)[3])out, verts, totvert);
+ memcpy(out, positions, sizeof(float[3]) * totvert);
break;
}
case ID_LT: {
@@ -2184,21 +2183,15 @@ void BKE_keyblock_convert_to_curve(KeyBlock *kb, Curve *UNUSED(cu), ListBase *nu
void BKE_keyblock_update_from_mesh(const Mesh *me, KeyBlock *kb)
{
- float(*fp)[3];
- int a, tot;
-
BLI_assert(me->totvert == kb->totelem);
- tot = me->totvert;
+ const int tot = me->totvert;
if (tot == 0) {
return;
}
- const MVert *mvert = BKE_mesh_verts(me);
- fp = kb->data;
- for (a = 0; a < tot; a++, fp++, mvert++) {
- copy_v3_v3(*fp, mvert->co);
- }
+ const float(*positions)[3] = BKE_mesh_positions(me);
+ memcpy(kb->data, positions, sizeof(float[3]) * tot);
}
void BKE_keyblock_convert_from_mesh(const Mesh *me, const Key *key, KeyBlock *kb)
@@ -2217,19 +2210,10 @@ void BKE_keyblock_convert_from_mesh(const Mesh *me, const Key *key, KeyBlock *kb
BKE_keyblock_update_from_mesh(me, kb);
}
-static void keyblock_data_convert_to_mesh(const float (*fp)[3], MVert *mvert, const int totvert)
+void BKE_keyblock_convert_to_mesh(const KeyBlock *kb, float (*positions)[3], const int totvert)
{
- for (int i = 0; i < totvert; i++, fp++, mvert++) {
- copy_v3_v3(mvert->co, *fp);
- }
-}
-
-void BKE_keyblock_convert_to_mesh(const KeyBlock *kb, MVert *mvert, const int totvert)
-{
- const float(*fp)[3] = kb->data;
const int tot = min_ii(kb->totelem, totvert);
-
- keyblock_data_convert_to_mesh(fp, mvert, tot);
+ memcpy(kb->data, positions, sizeof(float[3]) * tot);
}
void BKE_keyblock_mesh_calc_normals(const KeyBlock *kb,
@@ -2242,8 +2226,8 @@ void BKE_keyblock_mesh_calc_normals(const KeyBlock *kb,
return;
}
- MVert *verts = MEM_dupallocN(BKE_mesh_verts(mesh));
- BKE_keyblock_convert_to_mesh(kb, verts, mesh->totvert);
+ float(*positions)[3] = MEM_dupallocN(BKE_mesh_positions(mesh));
+ BKE_keyblock_convert_to_mesh(kb, positions, mesh->totvert);
const MEdge *edges = BKE_mesh_edges(mesh);
const MPoly *polys = BKE_mesh_polys(mesh);
const MLoop *loops = BKE_mesh_loops(mesh);
@@ -2268,10 +2252,10 @@ void BKE_keyblock_mesh_calc_normals(const KeyBlock *kb,
if (poly_normals_needed) {
BKE_mesh_calc_normals_poly(
- verts, mesh->totvert, loops, mesh->totloop, polys, mesh->totpoly, poly_normals);
+ positions, mesh->totvert, loops, mesh->totloop, polys, mesh->totpoly, poly_normals);
}
if (vert_normals_needed) {
- BKE_mesh_calc_normals_poly_and_vertex(verts,
+ BKE_mesh_calc_normals_poly_and_vertex(positions,
mesh->totvert,
loops,
mesh->totloop,
@@ -2282,7 +2266,7 @@ void BKE_keyblock_mesh_calc_normals(const KeyBlock *kb,
}
if (loop_normals_needed) {
short(*clnors)[2] = CustomData_get_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL); /* May be NULL. */
- BKE_mesh_normals_loop_split(verts,
+ BKE_mesh_normals_loop_split(positions,
vert_normals,
mesh->totvert,
edges,
@@ -2306,7 +2290,7 @@ void BKE_keyblock_mesh_calc_normals(const KeyBlock *kb,
if (free_poly_normals) {
MEM_freeN(poly_normals);
}
- MEM_freeN(verts);
+ MEM_freeN(positions);
}
/************************* raw coords ************************/
diff --git a/source/blender/blenkernel/intern/mball_tessellate.cc b/source/blender/blenkernel/intern/mball_tessellate.cc
index f8a64a7cd8b..85c7504e61e 100644
--- a/source/blender/blenkernel/intern/mball_tessellate.cc
+++ b/source/blender/blenkernel/intern/mball_tessellate.cc
@@ -1462,13 +1462,10 @@ Mesh *BKE_mball_polygonize(Depsgraph *depsgraph, Scene *scene, Object *ob)
Mesh *mesh = (Mesh *)BKE_id_new_nomain(ID_ME, ((ID *)ob->data)->name + 2);
- mesh->totvert = int(process.curvertex);
- MVert *mvert = static_cast<MVert *>(
- CustomData_add_layer(&mesh->vdata, CD_MVERT, CD_CONSTRUCT, nullptr, mesh->totvert));
- for (int i = 0; i < mesh->totvert; i++) {
- copy_v3_v3(mvert[i].co, process.co[i]);
- }
- MEM_freeN(process.co);
+ mesh->totvert = (int)process.curvertex;
+ CustomData_add_layer_named(
+ &mesh->vdata, CD_PROP_FLOAT3, CD_ASSIGN, process.co, mesh->totvert, "position");
+ process.co = nullptr;
mesh->totpoly = int(process.curindex);
MPoly *mpoly = static_cast<MPoly *>(
diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc
index 2d613f24a0a..888f66b4193 100644
--- a/source/blender/blenkernel/intern/mesh.cc
+++ b/source/blender/blenkernel/intern/mesh.cc
@@ -18,6 +18,7 @@
#include "DNA_object_types.h"
#include "BLI_bit_vector.hh"
+#include "BLI_bounds.hh"
#include "BLI_edgehash.h"
#include "BLI_endian_switch.h"
#include "BLI_ghash.h"
@@ -28,6 +29,7 @@
#include "BLI_math.h"
#include "BLI_math_vector.hh"
#include "BLI_memarena.h"
+#include "BLI_resource_scope.hh"
#include "BLI_span.hh"
#include "BLI_string.h"
#include "BLI_task.hh"
@@ -231,6 +233,7 @@ static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address
Vector<CustomDataLayer, 16> edge_layers;
Vector<CustomDataLayer, 16> loop_layers;
Vector<CustomDataLayer, 16> poly_layers;
+ blender::ResourceScope temp_arrays_for_legacy_format;
/* cache only - don't write */
mesh->mface = nullptr;
@@ -255,23 +258,26 @@ static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address
else {
Set<std::string> names_to_skip;
if (!BLO_write_is_undo(writer)) {
- BKE_mesh_legacy_convert_hide_layers_to_flags(mesh);
- BKE_mesh_legacy_convert_selection_layers_to_flags(mesh);
- BKE_mesh_legacy_convert_material_indices_to_mpoly(mesh);
- BKE_mesh_legacy_bevel_weight_from_layers(mesh);
- BKE_mesh_legacy_face_set_from_generic(mesh, poly_layers);
- BKE_mesh_legacy_edge_crease_from_layers(mesh);
/* When converting to the old mesh format, don't save redundant attributes. */
names_to_skip.add_multiple_new({".hide_vert",
".hide_edge",
".hide_poly",
+ "position",
"material_index",
".select_vert",
".select_edge",
".select_poly"});
+ mesh->mvert = BKE_mesh_legacy_convert_positions_to_verts(
+ mesh, temp_arrays_for_legacy_format, vert_layers);
+ BKE_mesh_legacy_convert_hide_layers_to_flags(mesh);
+ BKE_mesh_legacy_convert_selection_layers_to_flags(mesh);
+ BKE_mesh_legacy_convert_material_indices_to_mpoly(mesh);
+ BKE_mesh_legacy_bevel_weight_from_layers(mesh);
+ BKE_mesh_legacy_face_set_from_generic(mesh, poly_layers);
+ BKE_mesh_legacy_edge_crease_from_layers(mesh);
+
/* Set deprecated mesh data pointers for forward compatibility. */
- mesh->mvert = const_cast<MVert *>(mesh->verts().data());
mesh->medge = const_cast<MEdge *>(mesh->edges().data());
mesh->mpoly = const_cast<MPoly *>(mesh->polys().data());
mesh->mloop = const_cast<MLoop *>(mesh->loops().data());
@@ -478,9 +484,8 @@ static int customdata_compare(
const float thresh_sq = thresh * thresh;
CustomDataLayer *l1, *l2;
int layer_count1 = 0, layer_count2 = 0, j;
- const uint64_t cd_mask_non_generic = CD_MASK_MVERT | CD_MASK_MEDGE | CD_MASK_MPOLY |
- CD_MASK_MLOOPUV | CD_MASK_PROP_BYTE_COLOR |
- CD_MASK_MDEFORMVERT;
+ const uint64_t cd_mask_non_generic = CD_MASK_MEDGE | CD_MASK_MPOLY | CD_MASK_MLOOPUV |
+ CD_MASK_PROP_BYTE_COLOR | CD_MASK_MDEFORMVERT;
const uint64_t cd_mask_all_attr = CD_MASK_PROP_ALL | cd_mask_non_generic;
const Span<MLoop> loops_1 = m1->loops();
const Span<MLoop> loops_2 = m2->loops();
@@ -518,22 +523,6 @@ static int customdata_compare(
/* At this point `l1` and `l2` have the same name and type, so they should be compared. */
switch (l1->type) {
-
- case CD_MVERT: {
- MVert *v1 = (MVert *)l1->data;
- MVert *v2 = (MVert *)l2->data;
- int vtot = m1->totvert;
-
- for (j = 0; j < vtot; j++, v1++, v2++) {
- for (int k = 0; k < 3; k++) {
- if (compare_threshold_relative(v1->co[k], v2->co[k], thresh)) {
- return MESHCMP_VERTCOMISMATCH;
- }
- }
- }
- break;
- }
-
/* We're order-agnostic for edges here. */
case CD_MEDGE: {
MEdge *e1 = (MEdge *)l1->data;
@@ -776,6 +765,11 @@ const char *BKE_mesh_cmp(Mesh *me1, Mesh *me2, float thresh)
return nullptr;
}
+bool BKE_mesh_attribute_required(const char *name)
+{
+ return StringRef(name) == "position";
+}
+
void BKE_mesh_ensure_skin_customdata(Mesh *me)
{
BMesh *bm = me->edit_mesh ? me->edit_mesh->bm : nullptr;
@@ -922,8 +916,9 @@ Mesh *BKE_mesh_add(Main *bmain, const char *name)
/* Custom data layer functions; those assume that totXXX are set correctly. */
static void mesh_ensure_cdlayers_primary(Mesh *mesh, bool do_tessface)
{
- if (!CustomData_get_layer(&mesh->vdata, CD_MVERT)) {
- CustomData_add_layer(&mesh->vdata, CD_MVERT, CD_SET_DEFAULT, nullptr, mesh->totvert);
+ if (!CustomData_get_layer_named(&mesh->vdata, CD_PROP_FLOAT3, "position")) {
+ CustomData_add_layer_named(
+ &mesh->vdata, CD_PROP_FLOAT3, CD_CONSTRUCT, nullptr, mesh->totvert, "position");
}
if (!CustomData_get_layer(&mesh->edata, CD_MEDGE)) {
CustomData_add_layer(&mesh->edata, CD_MEDGE, CD_SET_DEFAULT, nullptr, mesh->totedge);
@@ -1268,12 +1263,12 @@ float (*BKE_mesh_orco_verts_get(Object *ob))[3]
/* Get appropriate vertex coordinates */
float(*vcos)[3] = (float(*)[3])MEM_calloc_arrayN(me->totvert, sizeof(*vcos), "orco mesh");
- const Span<MVert> verts = tme->verts();
+ const Span<float3> positions = tme->positions();
int totvert = min_ii(tme->totvert, me->totvert);
for (int a = 0; a < totvert; a++) {
- copy_v3_v3(vcos[a], verts[a].co);
+ copy_v3_v3(vcos[a], positions[a]);
}
return vcos;
@@ -1519,43 +1514,23 @@ void BKE_mesh_looptri_get_real_edges(const Mesh *mesh, const MLoopTri *looptri,
bool BKE_mesh_minmax(const Mesh *me, float r_min[3], float r_max[3])
{
using namespace blender;
- if (me->totvert == 0) {
+ std::optional<bounds::MinMaxResult<float3>> result = bounds::min_max(me->positions());
+ if (!result) {
return false;
}
- struct Result {
- float3 min;
- float3 max;
- };
- const Span<MVert> verts = me->verts();
-
- const Result minmax = threading::parallel_reduce(
- verts.index_range(),
- 1024,
- Result{float3(FLT_MAX), float3(-FLT_MAX)},
- [verts](IndexRange range, const Result &init) {
- Result result = init;
- for (const int i : range) {
- math::min_max(float3(verts[i].co), result.min, result.max);
- }
- return result;
- },
- [](const Result &a, const Result &b) {
- return Result{math::min(a.min, b.min), math::max(a.max, b.max)};
- });
-
- copy_v3_v3(r_min, math::min(minmax.min, float3(r_min)));
- copy_v3_v3(r_max, math::max(minmax.max, float3(r_max)));
+ copy_v3_v3(r_min, math::min(result->min, float3(r_min)));
+ copy_v3_v3(r_max, math::max(result->max, float3(r_max)));
return true;
}
void BKE_mesh_transform(Mesh *me, const float mat[4][4], bool do_keys)
{
- MutableSpan<MVert> verts = me->verts_for_write();
+ MutableSpan<float3> positions = me->positions_for_write();
- for (MVert &vert : verts) {
- mul_m4_v3(mat, vert.co);
+ for (float3 &position : positions) {
+ mul_m4_v3(mat, position);
}
if (do_keys && me->key) {
@@ -1586,9 +1561,9 @@ void BKE_mesh_transform(Mesh *me, const float mat[4][4], bool do_keys)
void BKE_mesh_translate(Mesh *me, const float offset[3], const bool do_keys)
{
- MutableSpan<MVert> verts = me->verts_for_write();
- for (MVert &vert : verts) {
- add_v3_v3(vert.co, offset);
+ MutableSpan<float3> positions = me->positions_for_write();
+ for (float3 &position : positions) {
+ position += offset;
}
int i;
@@ -1762,9 +1737,9 @@ float (*BKE_mesh_vert_coords_alloc(const Mesh *mesh, int *r_vert_len))[3]
void BKE_mesh_vert_coords_apply(Mesh *mesh, const float (*vert_coords)[3])
{
- MutableSpan<MVert> verts = mesh->verts_for_write();
- for (const int i : verts.index_range()) {
- copy_v3_v3(verts[i].co, vert_coords[i]);
+ MutableSpan<float3> positions = mesh->positions_for_write();
+ for (const int i : positions.index_range()) {
+ copy_v3_v3(positions[i], vert_coords[i]);
}
BKE_mesh_tag_coords_changed(mesh);
}
@@ -1773,9 +1748,9 @@ void BKE_mesh_vert_coords_apply_with_mat4(Mesh *mesh,
const float (*vert_coords)[3],
const float mat[4][4])
{
- MutableSpan<MVert> verts = mesh->verts_for_write();
- for (const int i : verts.index_range()) {
- mul_v3_m4v3(verts[i].co, mat, vert_coords[i]);
+ MutableSpan<float3> positions = mesh->positions_for_write();
+ for (const int i : positions.index_range()) {
+ mul_v3_m4v3(positions[i], mat, vert_coords[i]);
}
BKE_mesh_tag_coords_changed(mesh);
}
@@ -1811,14 +1786,14 @@ void BKE_mesh_calc_normals_split_ex(Mesh *mesh,
/* may be nullptr */
clnors = (short(*)[2])CustomData_get_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL);
- const Span<MVert> verts = mesh->verts();
+ const Span<float3> positions = mesh->positions();
const Span<MEdge> edges = mesh->edges();
const Span<MPoly> polys = mesh->polys();
const Span<MLoop> loops = mesh->loops();
- BKE_mesh_normals_loop_split(verts.data(),
+ BKE_mesh_normals_loop_split(reinterpret_cast<const float(*)[3]>(positions.data()),
BKE_mesh_vertex_normals_ensure(mesh),
- verts.size(),
+ positions.size(),
edges.data(),
edges.size(),
loops.data(),
diff --git a/source/blender/blenkernel/intern/mesh_boolean_convert.cc b/source/blender/blenkernel/intern/mesh_boolean_convert.cc
index 360c7da2ae2..62f73eb4626 100644
--- a/source/blender/blenkernel/intern/mesh_boolean_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_boolean_convert.cc
@@ -102,16 +102,16 @@ class MeshesToIMeshInfo {
const Mesh **r_orig_mesh,
int *r_orig_mesh_index,
int *r_index_in_orig_mesh) const;
- const MVert *input_mvert_for_orig_index(int orig_index,
- const Mesh **r_orig_mesh,
- int *r_index_in_orig_mesh) const;
+ void input_mvert_for_orig_index(int orig_index,
+ const Mesh **r_orig_mesh,
+ int *r_index_in_orig_mesh) const;
const MEdge *input_medge_for_orig_index(int orig_index,
const Mesh **r_orig_mesh,
int *r_index_in_orig_mesh) const;
};
/* Given an index `imesh_v` in the `IMesh`, return the index of the
- * input `Mesh` that contained the `MVert` that it came from. */
+ * input `Mesh` that contained the vertex that it came from. */
int MeshesToIMeshInfo::input_mesh_for_imesh_vert(int imesh_v) const
{
int n = int(mesh_vert_offset.size());
@@ -124,7 +124,7 @@ int MeshesToIMeshInfo::input_mesh_for_imesh_vert(int imesh_v) const
}
/* Given an index `imesh_e` used as an original index in the `IMesh`,
- * return the index of the input `Mesh` that contained the `MVert` that it came from. */
+ * return the index of the input `Mesh` that contained the vertex that it came from. */
int MeshesToIMeshInfo::input_mesh_for_imesh_edge(int imesh_e) const
{
int n = int(mesh_edge_offset.size());
@@ -180,26 +180,23 @@ const MPoly *MeshesToIMeshInfo::input_mpoly_for_orig_index(int orig_index,
/* Given an index of an original vertex in the `IMesh`, find out the input
* `Mesh` that it came from and return it in `*r_orig_mesh`.
- * Also find the index of the `MVert` in that `Mesh` and return it in
+ * Also find the index of the vertex in that `Mesh` and return it in
* `*r_index_in_orig_mesh`. */
-const MVert *MeshesToIMeshInfo::input_mvert_for_orig_index(int orig_index,
- const Mesh **r_orig_mesh,
- int *r_index_in_orig_mesh) const
+void MeshesToIMeshInfo::input_mvert_for_orig_index(int orig_index,
+ const Mesh **r_orig_mesh,
+ int *r_index_in_orig_mesh) const
{
int orig_mesh_index = input_mesh_for_imesh_vert(orig_index);
BLI_assert(0 <= orig_mesh_index && orig_mesh_index < meshes.size());
const Mesh *me = meshes[orig_mesh_index];
- const Span<MVert> verts = me->verts();
int index_in_mesh = orig_index - mesh_vert_offset[orig_mesh_index];
BLI_assert(0 <= index_in_mesh && index_in_mesh < me->totvert);
- const MVert *mv = &verts[index_in_mesh];
if (r_orig_mesh) {
*r_orig_mesh = me;
}
if (r_index_in_orig_mesh) {
*r_index_in_orig_mesh = index_in_mesh;
}
- return mv;
}
/* Similarly for edges. */
@@ -229,7 +226,7 @@ const MEdge *MeshesToIMeshInfo::input_medge_for_orig_index(int orig_index,
* first Mesh. To do this transformation, we also need the transformation
* obmats corresponding to the Meshes, so they are in the `obmats` argument.
* The 'original' indexes in the IMesh are the indexes you get by
- * a scheme that offsets each MVert, MEdge, and MPoly index by the sum of the
+ * a scheme that offsets each vertex, MEdge, and MPoly index by the sum of the
* vertices, edges, and polys in the preceding Meshes in the mesh span.
* The `*r_info class` is filled in with information needed to make the
* correspondence between the Mesh MVerts/MPolys and the IMesh Verts/Faces.
@@ -287,7 +284,7 @@ static IMesh meshes_to_imesh(Span<const Mesh *> meshes,
const float4x4 inv_target_mat = clean_transform(target_transform).inverted();
/* For each input `Mesh`, make `Vert`s and `Face`s for the corresponding
- * `MVert`s and `MPoly`s, and keep track of the original indices (using the
+ * vertices and `MPoly`s, and keep track of the original indices (using the
* concatenating offset scheme) inside the `Vert`s and `Face`s.
* When making `Face`s, we also put in the original indices for `MEdge`s that
* make up the `MPoly`s using the same scheme. */
@@ -309,7 +306,7 @@ static IMesh meshes_to_imesh(Span<const Mesh *> meshes,
bool need_face_flip = r_info->has_negative_transform[mi] != r_info->has_negative_transform[0];
Vector<Vert *> verts(me->totvert);
- const Span<MVert> mesh_verts = me->verts();
+ const Span<float3> mesh_positions = me->positions();
const Span<MPoly> polys = me->polys();
const Span<MLoop> loops = me->loops();
@@ -318,10 +315,9 @@ static IMesh meshes_to_imesh(Span<const Mesh *> meshes,
* for example when the first mesh is already in the target space. (Note the logic
* directly above, which uses an identity matrix with a null input transform). */
if (obmats[mi] == nullptr) {
- threading::parallel_for(mesh_verts.index_range(), 2048, [&](IndexRange range) {
- float3 co;
+ threading::parallel_for(mesh_positions.index_range(), 2048, [&](IndexRange range) {
for (int i : range) {
- co = float3(mesh_verts[i].co);
+ float3 co = mesh_positions[i];
mpq3 mco = mpq3(co.x, co.y, co.z);
double3 dco(mco[0].get_d(), mco[1].get_d(), mco[2].get_d());
verts[i] = new Vert(mco, dco, NO_INDEX, i);
@@ -329,17 +325,16 @@ static IMesh meshes_to_imesh(Span<const Mesh *> meshes,
});
}
else {
- threading::parallel_for(mesh_verts.index_range(), 2048, [&](IndexRange range) {
- float3 co;
+ threading::parallel_for(mesh_positions.index_range(), 2048, [&](IndexRange range) {
for (int i : range) {
- co = r_info->to_target_transform[mi] * float3(mesh_verts[i].co);
+ float3 co = r_info->to_target_transform[mi] * mesh_positions[i];
mpq3 mco = mpq3(co.x, co.y, co.z);
double3 dco(mco[0].get_d(), mco[1].get_d(), mco[2].get_d());
verts[i] = new Vert(mco, dco, NO_INDEX, i);
}
});
}
- for (int i : mesh_verts.index_range()) {
+ for (int i : mesh_positions.index_range()) {
r_info->mesh_to_imesh_vert[v] = arena.add_or_find_vert(verts[i]);
++v;
}
@@ -384,9 +379,7 @@ static void copy_vert_attributes(Mesh *dest_mesh,
const CustomData *source_cd = &orig_me->vdata;
for (int source_layer_i = 0; source_layer_i < source_cd->totlayer; ++source_layer_i) {
int ty = source_cd->layers[source_layer_i].type;
- /* The (first) CD_MVERT layer is the same as dest_mesh->vdata, so we've
- * already set the coordinate to the right value. */
- if (ty == CD_MVERT) {
+ if (StringRef(source_cd->layers->name) == "position") {
continue;
}
const char *name = source_cd->layers[source_layer_i].name;
@@ -556,16 +549,19 @@ static void get_poly2d_cos(const Mesh *me,
const float4x4 &trans_mat,
float r_axis_mat[3][3])
{
- const Span<MVert> verts = me->verts();
+ const Span<float3> positions = me->positions();
const Span<MLoop> loops = me->loops();
const Span<MLoop> poly_loops = loops.slice(mp->loopstart, mp->totloop);
/* Project coordinates to 2d in cos_2d, using normal as projection axis. */
float axis_dominant[3];
- BKE_mesh_calc_poly_normal(mp, &loops[mp->loopstart], verts.data(), axis_dominant);
+ BKE_mesh_calc_poly_normal(mp,
+ &loops[mp->loopstart],
+ reinterpret_cast<const float(*)[3]>(positions.data()),
+ axis_dominant);
axis_dominant_v3_to_m3(r_axis_mat, axis_dominant);
for (const int i : poly_loops.index_range()) {
- float3 co = verts[poly_loops[i].v].co;
+ float3 co = positions[poly_loops[i].v];
co = trans_mat * co;
mul_v2_m3v3(cos_2d[i], r_axis_mat, co);
}
@@ -602,7 +598,7 @@ static void copy_or_interp_loop_attributes(Mesh *dest_mesh,
get_poly2d_cos(orig_me, orig_mp, cos_2d, mim.to_target_transform[orig_me_index], axis_mat);
}
CustomData *target_cd = &dest_mesh->ldata;
- const Span<MVert> dst_verts = dest_mesh->verts();
+ const Span<float3> dst_positions = dest_mesh->positions();
const Span<MLoop> dst_loops = dest_mesh->loops();
for (int i = 0; i < mp->totloop; ++i) {
int loop_index = mp->loopstart + i;
@@ -613,7 +609,7 @@ static void copy_or_interp_loop_attributes(Mesh *dest_mesh,
* The coordinate needs to be projected into 2d, just like the interpolating polygon's
* coordinates were. The `dest_mesh` coordinates are already in object 0 local space. */
float co[2];
- mul_v2_m3v3(co, axis_mat, dst_verts[dst_loops[loop_index].v].co);
+ mul_v2_m3v3(co, axis_mat, dst_positions[dst_loops[loop_index].v]);
interp_weights_poly_v2(weights.data(), cos_2d, orig_mp->totloop, co);
}
for (int source_layer_i = 0; source_layer_i < source_cd->totlayer; ++source_layer_i) {
@@ -716,7 +712,7 @@ static Mesh *imesh_to_mesh(IMesh *im, MeshesToIMeshInfo &mim)
merge_vertex_loop_poly_customdata_layers(result, mim);
/* Set the vertex coordinate values and other data. */
- MutableSpan<MVert> verts = result->verts_for_write();
+ MutableSpan<float3> positions = result->positions_for_write();
for (int vi : im->vert_index_range()) {
const Vert *v = im->vert(vi);
if (v->orig != NO_INDEX) {
@@ -725,8 +721,7 @@ static Mesh *imesh_to_mesh(IMesh *im, MeshesToIMeshInfo &mim)
mim.input_mvert_for_orig_index(v->orig, &orig_me, &index_in_orig_me);
copy_vert_attributes(result, orig_me, vi, index_in_orig_me);
}
- MVert *mv = &verts[vi];
- copy_v3fl_v3db(mv->co, v->co);
+ copy_v3fl_v3db(positions[vi], v->co);
}
/* Set the loopstart and totloop for each output poly,
diff --git a/source/blender/blenkernel/intern/mesh_convert.cc b/source/blender/blenkernel/intern/mesh_convert.cc
index 2255038a991..3d77c5985c0 100644
--- a/source/blender/blenkernel/intern/mesh_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_convert.cc
@@ -186,12 +186,11 @@ static Mesh *mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBase *dispba
}
Mesh *mesh = BKE_mesh_new_nomain(totvert, totedge, 0, totloop, totpoly);
- MutableSpan<MVert> verts = mesh->verts_for_write();
+ MutableSpan<float3> positions = mesh->positions_for_write();
MutableSpan<MEdge> edges = mesh->edges_for_write();
MutableSpan<MPoly> polys = mesh->polys_for_write();
MutableSpan<MLoop> loops = mesh->loops_for_write();
- MVert *mvert = verts.data();
MEdge *medge = edges.data();
MPoly *mpoly = polys.data();
MLoop *mloop = loops.data();
@@ -212,10 +211,9 @@ static Mesh *mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBase *dispba
a = dl->parts * dl->nr;
data = dl->verts;
while (a--) {
- copy_v3_v3(mvert->co, data);
+ copy_v3_v3(positions[vertcount], data);
data += 3;
vertcount++;
- mvert++;
}
for (a = 0; a < dl->parts; a++) {
@@ -235,10 +233,9 @@ static Mesh *mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBase *dispba
a = dl->parts * dl->nr;
data = dl->verts;
while (a--) {
- copy_v3_v3(mvert->co, data);
+ copy_v3_v3(positions[vertcount], data);
data += 3;
vertcount++;
- mvert++;
}
for (a = 0; a < dl->parts; a++) {
@@ -262,10 +259,9 @@ static Mesh *mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBase *dispba
a = dl->nr;
data = dl->verts;
while (a--) {
- copy_v3_v3(mvert->co, data);
+ copy_v3_v3(positions[vertcount], data);
data += 3;
vertcount++;
- mvert++;
}
a = dl->parts;
@@ -298,10 +294,9 @@ static Mesh *mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBase *dispba
a = dl->parts * dl->nr;
data = dl->verts;
while (a--) {
- copy_v3_v3(mvert->co, data);
+ copy_v3_v3(positions[vertcount], data);
data += 3;
vertcount++;
- mvert++;
}
for (a = 0; a < dl->parts; a++) {
@@ -458,7 +453,7 @@ static void appendPolyLineVert(ListBase *lb, uint index)
void BKE_mesh_to_curve_nurblist(const Mesh *me, ListBase *nurblist, const int edge_users_test)
{
- const Span<MVert> verts = me->verts();
+ const Span<float3> positions = me->positions();
const Span<MEdge> mesh_edges = me->edges();
const Span<MPoly> polys = me->polys();
const Span<MLoop> loops = me->loops();
@@ -590,7 +585,7 @@ void BKE_mesh_to_curve_nurblist(const Mesh *me, ListBase *nurblist, const int ed
/* add points */
vl = (VertLink *)polyline.first;
for (i = 0, bp = nu->bp; i < totpoly; i++, bp++, vl = (VertLink *)vl->next) {
- copy_v3_v3(bp->vec, verts[vl->index].co);
+ copy_v3_v3(bp->vec, positions[vl->index]);
bp->f1 = SELECT;
bp->radius = bp->weight = 1.0;
}
@@ -681,25 +676,8 @@ void BKE_mesh_from_pointcloud(const PointCloud *pointcloud, Mesh *me)
me->totvert = pointcloud->totpoint;
- /* Merge over all attributes. */
CustomData_merge(
&pointcloud->pdata, &me->vdata, CD_MASK_PROP_ALL, CD_DUPLICATE, pointcloud->totpoint);
-
- /* Convert the Position attribute to a mesh vertex. */
- CustomData_add_layer(&me->vdata, CD_MVERT, CD_SET_DEFAULT, nullptr, me->totvert);
-
- const int layer_idx = CustomData_get_named_layer_index(
- &me->vdata, CD_PROP_FLOAT3, POINTCLOUD_ATTR_POSITION);
- CustomDataLayer *pos_layer = &me->vdata.layers[layer_idx];
- float(*positions)[3] = (float(*)[3])pos_layer->data;
-
- MutableSpan<MVert> verts = me->verts_for_write();
- for (int i = 0; i < me->totvert; i++) {
- copy_v3_v3(verts[i].co, positions[i]);
- }
-
- /* Delete Position attribute since it is now in vertex coordinates. */
- CustomData_free_layer(&me->vdata, CD_PROP_FLOAT3, me->totvert, layer_idx);
}
void BKE_mesh_edges_set_draw_render(Mesh *mesh)
@@ -1172,8 +1150,8 @@ Mesh *BKE_mesh_create_derived_for_modifier(struct Depsgraph *depsgraph,
if (build_shapekey_layers && me->key &&
(kb = (KeyBlock *)BLI_findlink(&me->key->block, ob_eval->shapenr - 1))) {
- MutableSpan<MVert> verts = me->verts_for_write();
- BKE_keyblock_convert_to_mesh(kb, verts.data(), me->totvert);
+ MutableSpan<float3> verts = me->positions_for_write();
+ BKE_keyblock_convert_to_mesh(kb, reinterpret_cast<float(*)[3]>(verts.data()), me->totvert);
}
Mesh *mesh_temp = (Mesh *)BKE_id_copy_ex(nullptr, &me->id, nullptr, LIB_ID_COPY_LOCALIZE);
@@ -1354,8 +1332,7 @@ void BKE_mesh_nomain_to_meshkey(Mesh *mesh_src, Mesh *mesh_dst, KeyBlock *kb)
{
BLI_assert(mesh_src->id.tag & LIB_TAG_NO_MAIN);
- int a, totvert = mesh_src->totvert;
- float *fp;
+ const int totvert = mesh_src->totvert;
if (totvert == 0 || mesh_dst->totvert == 0 || mesh_dst->totvert != totvert) {
return;
@@ -1366,10 +1343,5 @@ void BKE_mesh_nomain_to_meshkey(Mesh *mesh_src, Mesh *mesh_dst, KeyBlock *kb)
}
kb->data = MEM_malloc_arrayN(mesh_dst->key->elemsize, mesh_dst->totvert, "kb->data");
kb->totelem = totvert;
-
- fp = (float *)kb->data;
- const Span<MVert> verts = mesh_src->verts();
- for (a = 0; a < kb->totelem; a++, fp += 3) {
- copy_v3_v3(fp, verts[a].co);
- }
+ MutableSpan(static_cast<float3 *>(kb->data), kb->totelem).copy_from(mesh_src->positions());
}
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.cc b/source/blender/blenkernel/intern/mesh_evaluate.cc
index 9a199c9c768..7ee76c8ba5a 100644
--- a/source/blender/blenkernel/intern/mesh_evaluate.cc
+++ b/source/blender/blenkernel/intern/mesh_evaluate.cc
@@ -30,6 +30,7 @@
#include "BKE_mesh.h"
#include "BKE_multires.h"
+using blender::float3;
using blender::MutableSpan;
using blender::Span;
using blender::VArray;
@@ -47,18 +48,18 @@ using blender::VArray;
*/
static void mesh_calc_ngon_normal(const MPoly *mpoly,
const MLoop *loopstart,
- const MVert *mvert,
+ const float (*positions)[3],
float normal[3])
{
const int nverts = mpoly->totloop;
- const float *v_prev = mvert[loopstart[nverts - 1].v].co;
+ const float *v_prev = positions[loopstart[nverts - 1].v];
const float *v_curr;
zero_v3(normal);
/* Newell's Method */
for (int i = 0; i < nverts; i++) {
- v_curr = mvert[loopstart[i].v].co;
+ v_curr = positions[loopstart[i].v];
add_newell_cross_v3_v3v3(normal, v_prev, v_curr);
v_prev = v_curr;
}
@@ -70,22 +71,22 @@ static void mesh_calc_ngon_normal(const MPoly *mpoly,
void BKE_mesh_calc_poly_normal(const MPoly *mpoly,
const MLoop *loopstart,
- const MVert *mvarray,
+ const float (*positions)[3],
float r_no[3])
{
if (mpoly->totloop > 4) {
- mesh_calc_ngon_normal(mpoly, loopstart, mvarray, r_no);
+ mesh_calc_ngon_normal(mpoly, loopstart, positions, r_no);
}
else if (mpoly->totloop == 3) {
normal_tri_v3(
- r_no, mvarray[loopstart[0].v].co, mvarray[loopstart[1].v].co, mvarray[loopstart[2].v].co);
+ r_no, positions[loopstart[0].v], positions[loopstart[1].v], positions[loopstart[2].v]);
}
else if (mpoly->totloop == 4) {
normal_quad_v3(r_no,
- mvarray[loopstart[0].v].co,
- mvarray[loopstart[1].v].co,
- mvarray[loopstart[2].v].co,
- mvarray[loopstart[3].v].co);
+ positions[loopstart[0].v],
+ positions[loopstart[1].v],
+ positions[loopstart[2].v],
+ positions[loopstart[3].v]);
}
else { /* horrible, two sided face! */
r_no[0] = 0.0;
@@ -147,7 +148,7 @@ void BKE_mesh_calc_poly_normal_coords(const MPoly *mpoly,
static void mesh_calc_ngon_center(const MPoly *mpoly,
const MLoop *loopstart,
- const MVert *mvert,
+ const float (*positions)[3],
float cent[3])
{
const float w = 1.0f / float(mpoly->totloop);
@@ -155,38 +156,38 @@ static void mesh_calc_ngon_center(const MPoly *mpoly,
zero_v3(cent);
for (int i = 0; i < mpoly->totloop; i++) {
- madd_v3_v3fl(cent, mvert[(loopstart++)->v].co, w);
+ madd_v3_v3fl(cent, positions[(loopstart++)->v], w);
}
}
void BKE_mesh_calc_poly_center(const MPoly *mpoly,
const MLoop *loopstart,
- const MVert *mvarray,
+ const float (*positions)[3],
float r_cent[3])
{
if (mpoly->totloop == 3) {
- mid_v3_v3v3v3(r_cent,
- mvarray[loopstart[0].v].co,
- mvarray[loopstart[1].v].co,
- mvarray[loopstart[2].v].co);
+ mid_v3_v3v3v3(
+ r_cent, positions[loopstart[0].v], positions[loopstart[1].v], positions[loopstart[2].v]);
}
else if (mpoly->totloop == 4) {
mid_v3_v3v3v3v3(r_cent,
- mvarray[loopstart[0].v].co,
- mvarray[loopstart[1].v].co,
- mvarray[loopstart[2].v].co,
- mvarray[loopstart[3].v].co);
+ positions[loopstart[0].v],
+ positions[loopstart[1].v],
+ positions[loopstart[2].v],
+ positions[loopstart[3].v]);
}
else {
- mesh_calc_ngon_center(mpoly, loopstart, mvarray, r_cent);
+ mesh_calc_ngon_center(mpoly, loopstart, positions, r_cent);
}
}
-float BKE_mesh_calc_poly_area(const MPoly *mpoly, const MLoop *loopstart, const MVert *mvarray)
+float BKE_mesh_calc_poly_area(const MPoly *mpoly,
+ const MLoop *loopstart,
+ const float (*positions)[3])
{
if (mpoly->totloop == 3) {
return area_tri_v3(
- mvarray[loopstart[0].v].co, mvarray[loopstart[1].v].co, mvarray[loopstart[2].v].co);
+ positions[loopstart[0].v], positions[loopstart[1].v], positions[loopstart[2].v]);
}
const MLoop *l_iter = loopstart;
@@ -194,7 +195,7 @@ float BKE_mesh_calc_poly_area(const MPoly *mpoly, const MLoop *loopstart, const
/* pack vertex cos into an array for area_poly_v3 */
for (int i = 0; i < mpoly->totloop; i++, l_iter++) {
- copy_v3_v3(vertexcos[i], mvarray[l_iter->v].co);
+ copy_v3_v3(vertexcos[i], positions[l_iter->v]);
}
/* finally calculate the area */
@@ -205,13 +206,14 @@ float BKE_mesh_calc_poly_area(const MPoly *mpoly, const MLoop *loopstart, const
float BKE_mesh_calc_area(const Mesh *me)
{
- const Span<MVert> verts = me->verts();
+ const Span<float3> positions = me->positions();
const Span<MPoly> polys = me->polys();
const Span<MLoop> loops = me->loops();
float total_area = 0.0f;
for (const MPoly &poly : polys) {
- total_area += BKE_mesh_calc_poly_area(&poly, &loops[poly.loopstart], verts.data());
+ total_area += BKE_mesh_calc_poly_area(
+ &poly, &loops[poly.loopstart], reinterpret_cast<const float(*)[3]>(positions.data()));
}
return total_area;
}
@@ -236,7 +238,7 @@ float BKE_mesh_calc_poly_uv_area(const MPoly *mpoly, const MLoopUV *uv_array)
static float UNUSED_FUNCTION(mesh_calc_poly_volume_centroid)(const MPoly *mpoly,
const MLoop *loopstart,
- const MVert *mvarray,
+ const float (*positions)[3],
float r_cent[3])
{
const float *v_pivot, *v_step1;
@@ -244,11 +246,11 @@ static float UNUSED_FUNCTION(mesh_calc_poly_volume_centroid)(const MPoly *mpoly,
zero_v3(r_cent);
- v_pivot = mvarray[loopstart[0].v].co;
- v_step1 = mvarray[loopstart[1].v].co;
+ v_pivot = positions[loopstart[0].v];
+ v_step1 = positions[loopstart[1].v];
for (int i = 2; i < mpoly->totloop; i++) {
- const float *v_step2 = mvarray[loopstart[i].v].co;
+ const float *v_step2 = positions[loopstart[i].v];
/* Calculate the 6x volume of the tetrahedron formed by the 3 vertices
* of the triangle and the origin as the fourth vertex */
@@ -278,7 +280,7 @@ static float UNUSED_FUNCTION(mesh_calc_poly_volume_centroid)(const MPoly *mpoly,
*/
static float mesh_calc_poly_volume_centroid_with_reference_center(const MPoly *mpoly,
const MLoop *loopstart,
- const MVert *mvarray,
+ const float (*positions)[3],
const float reference_center[3],
float r_cent[3])
{
@@ -286,11 +288,11 @@ static float mesh_calc_poly_volume_centroid_with_reference_center(const MPoly *m
float v_pivot[3], v_step1[3];
float total_volume = 0.0f;
zero_v3(r_cent);
- sub_v3_v3v3(v_pivot, mvarray[loopstart[0].v].co, reference_center);
- sub_v3_v3v3(v_step1, mvarray[loopstart[1].v].co, reference_center);
+ sub_v3_v3v3(v_pivot, positions[loopstart[0].v], reference_center);
+ sub_v3_v3v3(v_step1, positions[loopstart[1].v], reference_center);
for (int i = 2; i < mpoly->totloop; i++) {
float v_step2[3];
- sub_v3_v3v3(v_step2, mvarray[loopstart[i].v].co, reference_center);
+ sub_v3_v3v3(v_step2, positions[loopstart[i].v], reference_center);
const float tetra_volume = volume_tri_tetrahedron_signed_v3_6x(v_pivot, v_step1, v_step2);
total_volume += tetra_volume;
for (uint j = 0; j < 3; j++) {
@@ -309,19 +311,19 @@ static float mesh_calc_poly_volume_centroid_with_reference_center(const MPoly *m
*/
static float mesh_calc_poly_area_centroid(const MPoly *mpoly,
const MLoop *loopstart,
- const MVert *mvarray,
+ const float (*positions)[3],
float r_cent[3])
{
float total_area = 0.0f;
float v1[3], v2[3], v3[3], normal[3], tri_cent[3];
- BKE_mesh_calc_poly_normal(mpoly, loopstart, mvarray, normal);
- copy_v3_v3(v1, mvarray[loopstart[0].v].co);
- copy_v3_v3(v2, mvarray[loopstart[1].v].co);
+ BKE_mesh_calc_poly_normal(mpoly, loopstart, positions, normal);
+ copy_v3_v3(v1, positions[loopstart[0].v]);
+ copy_v3_v3(v2, positions[loopstart[1].v]);
zero_v3(r_cent);
for (int i = 2; i < mpoly->totloop; i++) {
- copy_v3_v3(v3, mvarray[loopstart[i].v].co);
+ copy_v3_v3(v3, positions[loopstart[i].v]);
float tri_area = area_tri_signed_v3(v1, v2, v3, normal);
total_area += tri_area;
@@ -339,7 +341,7 @@ static float mesh_calc_poly_area_centroid(const MPoly *mpoly,
void BKE_mesh_calc_poly_angles(const MPoly *mpoly,
const MLoop *loopstart,
- const MVert *mvarray,
+ const float (*positions)[3],
float angles[])
{
float nor_prev[3];
@@ -348,11 +350,11 @@ void BKE_mesh_calc_poly_angles(const MPoly *mpoly,
int i_this = mpoly->totloop - 1;
int i_next = 0;
- sub_v3_v3v3(nor_prev, mvarray[loopstart[i_this - 1].v].co, mvarray[loopstart[i_this].v].co);
+ sub_v3_v3v3(nor_prev, positions[loopstart[i_this - 1].v], positions[loopstart[i_this].v]);
normalize_v3(nor_prev);
while (i_next < mpoly->totloop) {
- sub_v3_v3v3(nor_next, mvarray[loopstart[i_this].v].co, mvarray[loopstart[i_next].v].co);
+ sub_v3_v3v3(nor_next, positions[loopstart[i_this].v], positions[loopstart[i_next].v]);
normalize_v3(nor_next);
angles[i_this] = angle_normalized_v3v3(nor_prev, nor_next);
@@ -400,10 +402,10 @@ void BKE_mesh_poly_edgebitmap_insert(uint *edge_bitmap, const MPoly *mp, const M
bool BKE_mesh_center_median(const Mesh *me, float r_cent[3])
{
- const Span<MVert> verts = me->verts();
+ const Span<float3> positions = me->positions();
zero_v3(r_cent);
- for (const MVert &vert : verts) {
- add_v3_v3(r_cent, vert.co);
+ for (const float3 &position : positions) {
+ add_v3_v3(r_cent, position);
}
/* otherwise we get NAN for 0 verts */
if (me->totvert) {
@@ -415,14 +417,14 @@ bool BKE_mesh_center_median(const Mesh *me, float r_cent[3])
bool BKE_mesh_center_median_from_polys(const Mesh *me, float r_cent[3])
{
int tot = 0;
- const Span<MVert> verts = me->verts();
+ const Span<float3> positions = me->positions();
const Span<MPoly> polys = me->polys();
const Span<MLoop> loops = me->loops();
zero_v3(r_cent);
for (const MPoly &poly : polys) {
int loopend = poly.loopstart + poly.totloop;
for (int j = poly.loopstart; j < loopend; j++) {
- add_v3_v3(r_cent, verts[loops[j].v].co);
+ add_v3_v3(r_cent, positions[loops[j].v]);
}
tot += poly.totloop;
}
@@ -452,7 +454,7 @@ bool BKE_mesh_center_of_surface(const Mesh *me, float r_cent[3])
float poly_area;
float total_area = 0.0f;
float poly_cent[3];
- const MVert *verts = BKE_mesh_verts(me);
+ const float(*positions)[3] = BKE_mesh_positions(me);
const MPoly *polys = BKE_mesh_polys(me);
const MLoop *loops = BKE_mesh_loops(me);
@@ -460,7 +462,8 @@ bool BKE_mesh_center_of_surface(const Mesh *me, float r_cent[3])
/* calculate a weighted average of polygon centroids */
for (mpoly = polys; i--; mpoly++) {
- poly_area = mesh_calc_poly_area_centroid(mpoly, loops + mpoly->loopstart, verts, poly_cent);
+ poly_area = mesh_calc_poly_area_centroid(
+ mpoly, loops + mpoly->loopstart, positions, poly_cent);
madd_v3_v3fl(r_cent, poly_cent, poly_area);
total_area += poly_area;
@@ -485,7 +488,7 @@ bool BKE_mesh_center_of_volume(const Mesh *me, float r_cent[3])
float poly_volume;
float total_volume = 0.0f;
float poly_cent[3];
- const MVert *verts = BKE_mesh_verts(me);
+ const float(*positions)[3] = BKE_mesh_positions(me);
const MPoly *polys = BKE_mesh_polys(me);
const MLoop *loops = BKE_mesh_loops(me);
@@ -498,7 +501,7 @@ bool BKE_mesh_center_of_volume(const Mesh *me, float r_cent[3])
/* calculate a weighted average of polyhedron centroids */
for (mpoly = polys; i--; mpoly++) {
poly_volume = mesh_calc_poly_volume_centroid_with_reference_center(
- mpoly, loops + mpoly->loopstart, verts, init_cent, poly_cent);
+ mpoly, loops + mpoly->loopstart, positions, init_cent, poly_cent);
/* poly_cent is already volume-weighted, so no need to multiply by the volume */
add_v3_v3(r_cent, poly_cent);
@@ -527,7 +530,7 @@ bool BKE_mesh_center_of_volume(const Mesh *me, float r_cent[3])
/** \name Mesh Volume Calculation
* \{ */
-static bool mesh_calc_center_centroid_ex(const MVert *mverts,
+static bool mesh_calc_center_centroid_ex(const float (*positions)[3],
int /*mverts_num*/,
const MLoopTri *looptri,
int looptri_num,
@@ -545,15 +548,15 @@ static bool mesh_calc_center_centroid_ex(const MVert *mverts,
const MLoopTri *lt;
int i;
for (i = 0, lt = looptri; i < looptri_num; i++, lt++) {
- const MVert *v1 = &mverts[mloop[lt->tri[0]].v];
- const MVert *v2 = &mverts[mloop[lt->tri[1]].v];
- const MVert *v3 = &mverts[mloop[lt->tri[2]].v];
+ const float *v1 = positions[mloop[lt->tri[0]].v];
+ const float *v2 = positions[mloop[lt->tri[1]].v];
+ const float *v3 = positions[mloop[lt->tri[2]].v];
float area;
- area = area_tri_v3(v1->co, v2->co, v3->co);
- madd_v3_v3fl(r_center, v1->co, area);
- madd_v3_v3fl(r_center, v2->co, area);
- madd_v3_v3fl(r_center, v3->co, area);
+ area = area_tri_v3(v1, v2, v3);
+ madd_v3_v3fl(r_center, v1, area);
+ madd_v3_v3fl(r_center, v2, area);
+ madd_v3_v3fl(r_center, v3, area);
totweight += area;
}
if (totweight == 0.0f) {
@@ -565,7 +568,7 @@ static bool mesh_calc_center_centroid_ex(const MVert *mverts,
return true;
}
-void BKE_mesh_calc_volume(const MVert *mverts,
+void BKE_mesh_calc_volume(const float (*positions)[3],
const int mverts_num,
const MLoopTri *looptri,
const int looptri_num,
@@ -589,27 +592,27 @@ void BKE_mesh_calc_volume(const MVert *mverts,
return;
}
- if (!mesh_calc_center_centroid_ex(mverts, mverts_num, looptri, looptri_num, mloop, center)) {
+ if (!mesh_calc_center_centroid_ex(positions, mverts_num, looptri, looptri_num, mloop, center)) {
return;
}
totvol = 0.0f;
for (i = 0, lt = looptri; i < looptri_num; i++, lt++) {
- const MVert *v1 = &mverts[mloop[lt->tri[0]].v];
- const MVert *v2 = &mverts[mloop[lt->tri[1]].v];
- const MVert *v3 = &mverts[mloop[lt->tri[2]].v];
+ const float *v1 = positions[mloop[lt->tri[0]].v];
+ const float *v2 = positions[mloop[lt->tri[1]].v];
+ const float *v3 = positions[mloop[lt->tri[2]].v];
float vol;
- vol = volume_tetrahedron_signed_v3(center, v1->co, v2->co, v3->co);
+ vol = volume_tetrahedron_signed_v3(center, v1, v2, v3);
if (r_volume) {
totvol += vol;
}
if (r_center) {
/* averaging factor 1/3 is applied in the end */
- madd_v3_v3fl(r_center, v1->co, vol);
- madd_v3_v3fl(r_center, v2->co, vol);
- madd_v3_v3fl(r_center, v3->co, vol);
+ madd_v3_v3fl(r_center, v1, vol);
+ madd_v3_v3fl(r_center, v2, vol);
+ madd_v3_v3fl(r_center, v3, vol);
}
}
diff --git a/source/blender/blenkernel/intern/mesh_fair.cc b/source/blender/blenkernel/intern/mesh_fair.cc
index 960e6c43103..0d865275a7f 100644
--- a/source/blender/blenkernel/intern/mesh_fair.cc
+++ b/source/blender/blenkernel/intern/mesh_fair.cc
@@ -27,6 +27,7 @@
#include "eigen_capi.h"
using blender::Array;
+using blender::float3;
using blender::Map;
using blender::MutableSpan;
using blender::Span;
@@ -191,12 +192,12 @@ class FairingContext {
class MeshFairingContext : public FairingContext {
public:
- MeshFairingContext(Mesh *mesh, MVert *deform_mverts)
+ MeshFairingContext(Mesh *mesh, MutableSpan<float3> deform_positions)
{
totvert_ = mesh->totvert;
totloop_ = mesh->totloop;
- MutableSpan<MVert> verts = mesh->verts_for_write();
+ MutableSpan<float3> positions = mesh->positions_for_write();
medge_ = mesh->edges();
mpoly_ = mesh->polys();
mloop_ = mesh->loops();
@@ -210,14 +211,14 @@ class MeshFairingContext : public FairingContext {
/* Deformation coords. */
co_.reserve(mesh->totvert);
- if (deform_mverts) {
+ if (!deform_positions.is_empty()) {
for (int i = 0; i < mesh->totvert; i++) {
- co_[i] = deform_mverts[i].co;
+ co_[i] = deform_positions[i];
}
}
else {
for (int i = 0; i < mesh->totvert; i++) {
- co_[i] = verts[i].co;
+ co_[i] = positions[i];
}
}
@@ -466,11 +467,15 @@ static void prefair_and_fair_verts(FairingContext *fairing_context,
}
void BKE_mesh_prefair_and_fair_verts(struct Mesh *mesh,
- struct MVert *deform_mverts,
+ float (*deform_positions)[3],
bool *affect_verts,
const eMeshFairingDepth depth)
{
- MeshFairingContext *fairing_context = new MeshFairingContext(mesh, deform_mverts);
+ MutableSpan<float3> deform_positions_span;
+ if (deform_positions) {
+ deform_positions_span = {reinterpret_cast<float3 *>(deform_positions), mesh->totvert};
+ }
+ MeshFairingContext *fairing_context = new MeshFairingContext(mesh, deform_positions_span);
prefair_and_fair_verts(fairing_context, affect_verts, depth);
delete fairing_context;
}
diff --git a/source/blender/blenkernel/intern/mesh_iterators.cc b/source/blender/blenkernel/intern/mesh_iterators.cc
index a99e9b2348d..393ce479f8a 100644
--- a/source/blender/blenkernel/intern/mesh_iterators.cc
+++ b/source/blender/blenkernel/intern/mesh_iterators.cc
@@ -65,26 +65,26 @@ void BKE_mesh_foreach_mapped_vert(
}
}
else {
- const MVert *mv = BKE_mesh_verts(mesh);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
const int *index = static_cast<const int *>(CustomData_get_layer(&mesh->vdata, CD_ORIGINDEX));
const float(*vert_normals)[3] = (flag & MESH_FOREACH_USE_NORMAL) ?
BKE_mesh_vertex_normals_ensure(mesh) :
nullptr;
if (index) {
- for (int i = 0; i < mesh->totvert; i++, mv++) {
+ for (int i = 0; i < mesh->totvert; i++) {
const float *no = (flag & MESH_FOREACH_USE_NORMAL) ? vert_normals[i] : nullptr;
const int orig = *index++;
if (orig == ORIGINDEX_NONE) {
continue;
}
- func(userData, orig, mv->co, no);
+ func(userData, orig, positions[i], no);
}
}
else {
- for (int i = 0; i < mesh->totvert; i++, mv++) {
+ for (int i = 0; i < mesh->totvert; i++) {
const float *no = (flag & MESH_FOREACH_USE_NORMAL) ? vert_normals[i] : nullptr;
- func(userData, i, mv->co, no);
+ func(userData, i, positions[i], no);
}
}
}
@@ -120,7 +120,7 @@ void BKE_mesh_foreach_mapped_edge(
}
}
else {
- const MVert *mv = BKE_mesh_verts(mesh);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
const MEdge *med = BKE_mesh_edges(mesh);
const int *index = static_cast<const int *>(CustomData_get_layer(&mesh->edata, CD_ORIGINDEX));
@@ -130,12 +130,12 @@ void BKE_mesh_foreach_mapped_edge(
if (orig == ORIGINDEX_NONE) {
continue;
}
- func(userData, orig, mv[med->v1].co, mv[med->v2].co);
+ func(userData, orig, positions[med->v1], positions[med->v2]);
}
}
else if (mesh->totedge == tot_edges) {
for (int i = 0; i < mesh->totedge; i++, med++) {
- func(userData, i, mv[med->v1].co, mv[med->v2].co);
+ func(userData, i, positions[med->v1], positions[med->v2]);
}
}
}
@@ -190,7 +190,7 @@ void BKE_mesh_foreach_mapped_loop(Mesh *mesh,
CustomData_get_layer(&mesh->ldata, CD_NORMAL)) :
nullptr;
- const MVert *mv = BKE_mesh_verts(mesh);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
const MLoop *ml = BKE_mesh_loops(mesh);
const MPoly *mp = BKE_mesh_polys(mesh);
const int *v_index = static_cast<const int *>(
@@ -208,7 +208,7 @@ void BKE_mesh_foreach_mapped_loop(Mesh *mesh,
if (ELEM(ORIGINDEX_NONE, v_idx, f_idx)) {
continue;
}
- func(userData, v_idx, f_idx, mv[ml->v].co, no);
+ func(userData, v_idx, f_idx, positions[ml->v], no);
}
}
}
@@ -218,7 +218,7 @@ void BKE_mesh_foreach_mapped_loop(Mesh *mesh,
const int v_idx = ml->v;
const int f_idx = p_idx;
const float *no = lnors ? *lnors++ : nullptr;
- func(userData, v_idx, f_idx, mv[ml->v].co, no);
+ func(userData, v_idx, f_idx, positions[ml->v], no);
}
}
}
@@ -265,7 +265,7 @@ void BKE_mesh_foreach_mapped_face_center(
}
}
else {
- const MVert *mvert = BKE_mesh_verts(mesh);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
const MPoly *mp = BKE_mesh_polys(mesh);
const MLoop *loops = BKE_mesh_loops(mesh);
const MLoop *ml;
@@ -281,9 +281,9 @@ void BKE_mesh_foreach_mapped_face_center(
}
float cent[3];
ml = &loops[mp->loopstart];
- BKE_mesh_calc_poly_center(mp, ml, mvert, cent);
+ BKE_mesh_calc_poly_center(mp, ml, positions, cent);
if (flag & MESH_FOREACH_USE_NORMAL) {
- BKE_mesh_calc_poly_normal(mp, ml, mvert, no);
+ BKE_mesh_calc_poly_normal(mp, ml, positions, no);
}
func(userData, orig, cent, no);
}
@@ -292,9 +292,9 @@ void BKE_mesh_foreach_mapped_face_center(
for (int i = 0; i < mesh->totpoly; i++, mp++) {
float cent[3];
ml = &loops[mp->loopstart];
- BKE_mesh_calc_poly_center(mp, ml, mvert, cent);
+ BKE_mesh_calc_poly_center(mp, ml, positions, cent);
if (flag & MESH_FOREACH_USE_NORMAL) {
- BKE_mesh_calc_poly_normal(mp, ml, mvert, no);
+ BKE_mesh_calc_poly_normal(mp, ml, positions, no);
}
func(userData, i, cent, no);
}
@@ -308,11 +308,10 @@ void BKE_mesh_foreach_mapped_subdiv_face_center(
void *userData,
MeshForeachFlag flag)
{
- const MVert *verts = BKE_mesh_verts(mesh);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
const MPoly *mp = BKE_mesh_polys(mesh);
const MLoop *loops = BKE_mesh_loops(mesh);
const MLoop *ml;
- const MVert *mv;
const float(*vert_normals)[3] = (flag & MESH_FOREACH_USE_NORMAL) ?
BKE_mesh_vertex_normals_ensure(mesh) :
nullptr;
@@ -328,11 +327,10 @@ void BKE_mesh_foreach_mapped_subdiv_face_center(
}
ml = &loops[mp->loopstart];
for (int j = 0; j < mp->totloop; j++, ml++) {
- mv = &verts[ml->v];
if (BLI_BITMAP_TEST(facedot_tags, ml->v)) {
func(userData,
orig,
- mv->co,
+ positions[ml->v],
(flag & MESH_FOREACH_USE_NORMAL) ? vert_normals[ml->v] : nullptr);
}
}
@@ -342,11 +340,10 @@ void BKE_mesh_foreach_mapped_subdiv_face_center(
for (int i = 0; i < mesh->totpoly; i++, mp++) {
ml = &loops[mp->loopstart];
for (int j = 0; j < mp->totloop; j++, ml++) {
- mv = &verts[ml->v];
if (BLI_BITMAP_TEST(facedot_tags, ml->v)) {
func(userData,
i,
- mv->co,
+ positions[ml->v],
(flag & MESH_FOREACH_USE_NORMAL) ? vert_normals[ml->v] : nullptr);
}
}
diff --git a/source/blender/blenkernel/intern/mesh_legacy_convert.cc b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
index 23426f8c087..7f203252bc8 100644
--- a/source/blender/blenkernel/intern/mesh_legacy_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
@@ -17,8 +17,10 @@
#include "BLI_edgehash.h"
#include "BLI_math.h"
+#include "BLI_math_vec_types.hh"
#include "BLI_memarena.h"
#include "BLI_polyfill_2d.h"
+#include "BLI_resource_scope.hh"
#include "BLI_task.hh"
#include "BLI_utildefines.h"
@@ -29,6 +31,9 @@
#include "BKE_mesh_legacy_convert.h"
#include "BKE_multires.h"
+using blender::MutableSpan;
+using blender::Span;
+
/* -------------------------------------------------------------------- */
/** \name Legacy Edge Calculation
* \{ */
@@ -212,7 +217,8 @@ void BKE_mesh_calc_edges_legacy(Mesh *me, const bool use_old)
using namespace blender;
MEdge *medge;
int totedge = 0;
- const Span<MVert> verts = me->verts();
+ const Span<MVert> verts(static_cast<const MVert *>(CustomData_get_layer(&me->vdata, CD_MVERT)),
+ me->totvert);
const Span<MPoly> polys = me->polys();
MutableSpan<MLoop> loops = me->loops_for_write();
@@ -253,7 +259,8 @@ void BKE_mesh_do_versions_cd_flag_init(Mesh *mesh)
return;
}
- const Span<MVert> verts = mesh->verts();
+ const Span<MVert> verts(static_cast<const MVert *>(CustomData_get_layer(&mesh->vdata, CD_MVERT)),
+ mesh->totvert);
const Span<MEdge> edges = mesh->edges();
for (const MVert &vert : verts) {
@@ -939,7 +946,7 @@ int BKE_mesh_mface_index_validate(MFace *mface, CustomData *fdata, int mfindex,
static int mesh_tessface_calc(CustomData *fdata,
CustomData *ldata,
CustomData *pdata,
- MVert *mvert,
+ float (*positions)[3],
int totface,
int totloop,
int totpoly)
@@ -1069,9 +1076,9 @@ static int mesh_tessface_calc(CustomData *fdata,
/* Calculate the normal, flipped: to get a positive 2D cross product. */
ml = mloop + mp_loopstart;
- co_prev = mvert[ml[mp_totloop - 1].v].co;
+ co_prev = positions[ml[mp_totloop - 1].v];
for (j = 0; j < mp_totloop; j++, ml++) {
- co_curr = mvert[ml->v].co;
+ co_curr = positions[ml->v];
add_newell_cross_v3_v3v3(normal, co_prev, co_curr);
co_prev = co_curr;
}
@@ -1084,7 +1091,7 @@ static int mesh_tessface_calc(CustomData *fdata,
ml = mloop + mp_loopstart;
for (j = 0; j < mp_totloop; j++, ml++) {
- mul_v2_m3v3(projverts[j], axis_mat, mvert[ml->v].co);
+ mul_v2_m3v3(projverts[j], axis_mat, positions[ml->v]);
}
BLI_polyfill_calc_arena(projverts, mp_totloop, 1, tris, arena);
@@ -1186,7 +1193,7 @@ void BKE_mesh_tessface_calc(Mesh *mesh)
mesh->totface = mesh_tessface_calc(&mesh->fdata,
&mesh->ldata,
&mesh->pdata,
- BKE_mesh_verts_for_write(mesh),
+ BKE_mesh_positions_for_write(mesh),
mesh->totface,
mesh->totloop,
mesh->totpoly);
@@ -1240,7 +1247,7 @@ void BKE_mesh_legacy_face_set_to_generic(Mesh *mesh)
void BKE_mesh_legacy_bevel_weight_from_layers(Mesh *mesh)
{
using namespace blender;
- MutableSpan<MVert> verts = mesh->verts_for_write();
+ MutableSpan<MVert> verts(mesh->mvert, mesh->totvert);
if (const float *weights = static_cast<const float *>(
CustomData_get_layer(&mesh->vdata, CD_BWEIGHT))) {
mesh->cd_flag |= ME_CDFLAG_VERT_BWEIGHT;
@@ -1273,7 +1280,7 @@ void BKE_mesh_legacy_bevel_weight_from_layers(Mesh *mesh)
void BKE_mesh_legacy_bevel_weight_to_layers(Mesh *mesh)
{
using namespace blender;
- const Span<MVert> verts = mesh->verts();
+ const Span<MVert> verts(mesh->mvert, mesh->totvert);
if (mesh->cd_flag & ME_CDFLAG_VERT_BWEIGHT) {
float *weights = static_cast<float *>(
CustomData_add_layer(&mesh->vdata, CD_BWEIGHT, CD_CONSTRUCT, nullptr, verts.size()));
@@ -1342,7 +1349,7 @@ void BKE_mesh_legacy_convert_hide_layers_to_flags(Mesh *mesh)
using namespace blender::bke;
const AttributeAccessor attributes = mesh->attributes();
- MutableSpan<MVert> verts = mesh->verts_for_write();
+ MutableSpan<MVert> verts(mesh->mvert, mesh->totvert);
const VArray<bool> hide_vert = attributes.lookup_or_default<bool>(
".hide_vert", ATTR_DOMAIN_POINT, false);
threading::parallel_for(verts.index_range(), 4096, [&](IndexRange range) {
@@ -1376,7 +1383,7 @@ void BKE_mesh_legacy_convert_flags_to_hide_layers(Mesh *mesh)
using namespace blender::bke;
MutableAttributeAccessor attributes = mesh->attributes_for_write();
- const Span<MVert> verts = mesh->verts();
+ const Span<MVert> verts(mesh->mvert, mesh->totvert);
if (std::any_of(verts.begin(), verts.end(), [](const MVert &vert) {
return vert.flag_legacy & ME_HIDE;
})) {
@@ -1469,7 +1476,7 @@ void BKE_mesh_legacy_convert_selection_layers_to_flags(Mesh *mesh)
using namespace blender::bke;
const AttributeAccessor attributes = mesh->attributes();
- MutableSpan<MVert> verts = mesh->verts_for_write();
+ MutableSpan<MVert> verts(mesh->mvert, mesh->totvert);
const VArray<bool> select_vert = attributes.lookup_or_default<bool>(
".select_vert", ATTR_DOMAIN_POINT, false);
threading::parallel_for(verts.index_range(), 4096, [&](IndexRange range) {
@@ -1503,7 +1510,7 @@ void BKE_mesh_legacy_convert_flags_to_selection_layers(Mesh *mesh)
using namespace blender::bke;
MutableAttributeAccessor attributes = mesh->attributes_for_write();
- const Span<MVert> verts = mesh->verts();
+ const Span<MVert> verts(mesh->mvert, mesh->totvert);
if (std::any_of(verts.begin(), verts.end(), [](const MVert &vert) {
return vert.flag_legacy & SELECT;
})) {
@@ -1511,7 +1518,7 @@ void BKE_mesh_legacy_convert_flags_to_selection_layers(Mesh *mesh)
".select_vert", ATTR_DOMAIN_POINT);
threading::parallel_for(verts.index_range(), 4096, [&](IndexRange range) {
for (const int i : range) {
- select_vert.span[i] = (verts[i].flag_legacy & SELECT) != 0;
+ select_vert.span[i] = verts[i].flag_legacy & SELECT;
}
});
select_vert.finish();
@@ -1524,7 +1531,7 @@ void BKE_mesh_legacy_convert_flags_to_selection_layers(Mesh *mesh)
".select_edge", ATTR_DOMAIN_EDGE);
threading::parallel_for(edges.index_range(), 4096, [&](IndexRange range) {
for (const int i : range) {
- select_edge.span[i] = (edges[i].flag & SELECT) != 0;
+ select_edge.span[i] = edges[i].flag & SELECT;
}
});
select_edge.finish();
@@ -1537,7 +1544,7 @@ void BKE_mesh_legacy_convert_flags_to_selection_layers(Mesh *mesh)
".select_poly", ATTR_DOMAIN_FACE);
threading::parallel_for(polys.index_range(), 4096, [&](IndexRange range) {
for (const int i : range) {
- select_poly.span[i] = (polys[i].flag & ME_FACE_SEL) != 0;
+ select_poly.span[i] = polys[i].flag & ME_FACE_SEL;
}
});
select_poly.finish();
@@ -1545,3 +1552,53 @@ void BKE_mesh_legacy_convert_flags_to_selection_layers(Mesh *mesh)
}
/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Vertex and Position Conversion
+ * \{ */
+
+MVert *BKE_mesh_legacy_convert_positions_to_verts(
+ Mesh *mesh,
+ blender::ResourceScope &temp_arrays_for_convert,
+ blender::Vector<CustomDataLayer, 16> &vert_layers_to_write)
+{
+ using namespace blender;
+
+ const Span<float3> positions = mesh->positions();
+
+ CustomDataLayer mvert_layer{};
+ mvert_layer.type = CD_MVERT;
+ MutableSpan<MVert> verts = temp_arrays_for_convert.construct<Array<MVert>>(mesh->totvert);
+ mvert_layer.data = verts.data();
+
+ threading::parallel_for(verts.index_range(), 2048, [&](IndexRange range) {
+ for (const int i : range) {
+ copy_v3_v3(verts[i].co_legacy, positions[i]);
+ }
+ });
+
+ vert_layers_to_write.append(mvert_layer);
+ return verts.data();
+}
+
+void BKE_mesh_legacy_convert_verts_to_positions(Mesh *mesh)
+{
+ using namespace blender;
+ using namespace blender::bke;
+
+ const Span<MVert> verts(static_cast<MVert *>(CustomData_get_layer(&mesh->vdata, CD_MVERT)),
+ mesh->totvert);
+ MutableSpan<float3> positions(
+ static_cast<float3 *>(CustomData_add_layer_named(
+ &mesh->vdata, CD_PROP_FLOAT3, CD_CONSTRUCT, nullptr, mesh->totvert, "position")),
+ mesh->totvert);
+ threading::parallel_for(verts.index_range(), 2048, [&](IndexRange range) {
+ for (const int i : range) {
+ positions[i] = verts[i].co_legacy;
+ }
+ });
+
+ CustomData_free_layers(&mesh->vdata, CD_MVERT, mesh->totvert);
+}
+
+/** \} */
diff --git a/source/blender/blenkernel/intern/mesh_mapping.cc b/source/blender/blenkernel/intern/mesh_mapping.cc
index ed4ae94da7f..d289df75371 100644
--- a/source/blender/blenkernel/intern/mesh_mapping.cc
+++ b/source/blender/blenkernel/intern/mesh_mapping.cc
@@ -262,7 +262,6 @@ void BKE_mesh_vert_loop_map_create(MeshElemMap **r_map,
void BKE_mesh_vert_looptri_map_create(MeshElemMap **r_map,
int **r_mem,
- const MVert * /*mvert*/,
const int totvert,
const MLoopTri *mlooptri,
const int totlooptri,
@@ -1021,9 +1020,7 @@ static bool mesh_check_island_boundary_uv(const MPoly * /*mp*/,
return (me->flag & ME_SEAM) != 0;
}
-static bool mesh_calc_islands_loop_poly_uv(const MVert * /*verts*/,
- const int /*totvert*/,
- const MEdge *edges,
+static bool mesh_calc_islands_loop_poly_uv(const MEdge *edges,
const int totedge,
const MPoly *polys,
const int totpoly,
@@ -1171,7 +1168,7 @@ static bool mesh_calc_islands_loop_poly_uv(const MVert * /*verts*/,
return true;
}
-bool BKE_mesh_calc_islands_loop_poly_edgeseam(const MVert *verts,
+bool BKE_mesh_calc_islands_loop_poly_edgeseam(const float (*positions)[3],
const int totvert,
const MEdge *edges,
const int totedge,
@@ -1181,11 +1178,12 @@ bool BKE_mesh_calc_islands_loop_poly_edgeseam(const MVert *verts,
const int totloop,
MeshIslandStore *r_island_store)
{
+ UNUSED_VARS(positions, totvert);
return mesh_calc_islands_loop_poly_uv(
- verts, totvert, edges, totedge, polys, totpoly, loops, totloop, nullptr, r_island_store);
+ edges, totedge, polys, totpoly, loops, totloop, nullptr, r_island_store);
}
-bool BKE_mesh_calc_islands_loop_poly_uvmap(MVert *verts,
+bool BKE_mesh_calc_islands_loop_poly_uvmap(float (*positions)[3],
const int totvert,
MEdge *edges,
const int totedge,
@@ -1196,9 +1194,10 @@ bool BKE_mesh_calc_islands_loop_poly_uvmap(MVert *verts,
const MLoopUV *luvs,
MeshIslandStore *r_island_store)
{
+ UNUSED_VARS(positions, totvert);
BLI_assert(luvs != nullptr);
return mesh_calc_islands_loop_poly_uv(
- verts, totvert, edges, totedge, polys, totpoly, loops, totloop, luvs, r_island_store);
+ edges, totedge, polys, totpoly, loops, totloop, luvs, r_island_store);
}
/** \} */
diff --git a/source/blender/blenkernel/intern/mesh_merge.c b/source/blender/blenkernel/intern/mesh_merge.c
index 9c0e3c1bf59..fbc4ac3d208 100644
--- a/source/blender/blenkernel/intern/mesh_merge.c
+++ b/source/blender/blenkernel/intern/mesh_merge.c
@@ -14,6 +14,7 @@
#include "BLI_bitmap.h"
#include "BLI_edgehash.h"
#include "BLI_ghash.h"
+#include "BLI_math_vector.h"
#include "BLI_utildefines.h"
#include "BLI_utildefines_stack.h"
@@ -203,18 +204,14 @@ Mesh *BKE_mesh_merge_verts(Mesh *mesh,
const int totedge = mesh->totedge;
const int totloop = mesh->totloop;
const int totpoly = mesh->totpoly;
- const MVert *src_verts = BKE_mesh_verts(mesh);
const MEdge *src_edges = BKE_mesh_edges(mesh);
const MPoly *src_polys = BKE_mesh_polys(mesh);
const MLoop *src_loops = BKE_mesh_loops(mesh);
const int totvert_final = totvert - tot_vtargetmap;
- const MVert *mv;
- MVert *mvert = MEM_malloc_arrayN(totvert_final, sizeof(*mvert), __func__);
int *oldv = MEM_malloc_arrayN(totvert_final, sizeof(*oldv), __func__);
int *newv = MEM_malloc_arrayN(totvert, sizeof(*newv), __func__);
- STACK_DECLARE(mvert);
STACK_DECLARE(oldv);
/* NOTE: create (totedge + totloop) elements because partially invalid polys due to merge may
@@ -256,18 +253,15 @@ Mesh *BKE_mesh_merge_verts(Mesh *mesh,
STACK_INIT(oldl, totloop);
STACK_INIT(oldp, totpoly);
- STACK_INIT(mvert, totvert_final);
STACK_INIT(medge, totedge);
STACK_INIT(mloop, totloop);
STACK_INIT(mpoly, totpoly);
/* fill newv with destination vertex indices */
- mv = src_verts;
c = 0;
- for (i = 0; i < totvert; i++, mv++) {
+ for (i = 0; i < totvert; i++) {
if (vtargetmap[i] == -1) {
STACK_PUSH(oldv, i);
- STACK_PUSH(mvert, *mv);
newv[i] = c++;
}
else {
@@ -347,7 +341,6 @@ Mesh *BKE_mesh_merge_verts(Mesh *mesh,
BLI_bitmap *vert_tag = BLI_BITMAP_NEW(mesh->totvert, __func__);
mp = src_polys;
- mv = src_verts;
for (i = 0; i < totpoly; i++, mp++) {
MPoly *mp_new;
@@ -571,7 +564,7 @@ Mesh *BKE_mesh_merge_verts(Mesh *mesh,
/* Create new cddm. */
result = BKE_mesh_new_nomain_from_template(
- mesh, STACK_SIZE(mvert), STACK_SIZE(medge), 0, STACK_SIZE(mloop), STACK_SIZE(mpoly));
+ mesh, totvert_final, STACK_SIZE(medge), 0, STACK_SIZE(mloop), STACK_SIZE(mpoly));
/* Update edge indices and copy customdata. */
MEdge *new_med = medge;
@@ -598,8 +591,7 @@ Mesh *BKE_mesh_merge_verts(Mesh *mesh,
}
/* Copy vertex customdata. */
- mv = mvert;
- for (i = 0; i < result->totvert; i++, mv++) {
+ for (i = 0; i < result->totvert; i++) {
CustomData_copy_data(&mesh->vdata, &result->vdata, oldv[i], i, 1);
}
@@ -610,9 +602,6 @@ Mesh *BKE_mesh_merge_verts(Mesh *mesh,
}
/* Copy over data. #CustomData_add_layer can do this, need to look it up. */
- if (STACK_SIZE(mvert)) {
- memcpy(BKE_mesh_verts_for_write(result), mvert, sizeof(MVert) * STACK_SIZE(mvert));
- }
if (STACK_SIZE(medge)) {
memcpy(BKE_mesh_edges_for_write(result), medge, sizeof(MEdge) * STACK_SIZE(medge));
}
@@ -623,7 +612,6 @@ Mesh *BKE_mesh_merge_verts(Mesh *mesh,
memcpy(BKE_mesh_polys_for_write(result), mpoly, sizeof(MPoly) * STACK_SIZE(mpoly));
}
- MEM_freeN(mvert);
MEM_freeN(medge);
MEM_freeN(mloop);
MEM_freeN(mpoly);
diff --git a/source/blender/blenkernel/intern/mesh_mirror.c b/source/blender/blenkernel/intern/mesh_mirror.c
index ce3fc5d99c8..3968e6a01ff 100644
--- a/source/blender/blenkernel/intern/mesh_mirror.c
+++ b/source/blender/blenkernel/intern/mesh_mirror.c
@@ -131,7 +131,6 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd,
(axis == 2 && mmd->flag & MOD_MIR_BISECT_AXIS_Z));
Mesh *result;
- MVert *mv, *mv_prev;
MEdge *me;
MLoop *ml;
MPoly *mp;
@@ -209,9 +208,11 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd,
CustomData_copy_data(&mesh->pdata, &result->pdata, 0, 0, maxPolys);
/* Subdivision-surface for eg won't have mesh data in the custom-data arrays.
- * Now add #MVert/#MEdge/#MPoly layers. */
- if (!CustomData_has_layer(&mesh->vdata, CD_MVERT)) {
- memcpy(BKE_mesh_verts_for_write(result), BKE_mesh_verts(mesh), sizeof(MVert) * mesh->totvert);
+ * Now add position/#MEdge/#MPoly layers. */
+ if (BKE_mesh_positions(mesh) != NULL) {
+ memcpy(BKE_mesh_positions_for_write(result),
+ BKE_mesh_positions(mesh),
+ sizeof(float[3]) * mesh->totvert);
}
if (!CustomData_has_layer(&mesh->edata, CD_MEDGE)) {
memcpy(BKE_mesh_edges_for_write(result), BKE_mesh_edges(mesh), sizeof(MEdge) * mesh->totedge);
@@ -237,10 +238,11 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd,
}
/* mirror vertex coordinates */
- mv_prev = BKE_mesh_verts_for_write(result);
- mv = mv_prev + maxVerts;
- for (i = 0; i < maxVerts; i++, mv++, mv_prev++) {
- mul_m4_v3(mtx, mv->co);
+ float(*positions)[3] = BKE_mesh_positions_for_write(result);
+ for (i = 0; i < maxVerts; i++) {
+ const int vert_index_prev = i;
+ const int vert_index = maxVerts + i;
+ mul_m4_v3(mtx, positions[vert_index]);
if (do_vtargetmap) {
/* Compare location of the original and mirrored vertex,
@@ -257,13 +259,14 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd,
* old, incorrect behavior of merging the source vertex into its copy.
*/
if (use_correct_order_on_merge) {
- if (UNLIKELY(len_squared_v3v3(mv_prev->co, mv->co) < tolerance_sq)) {
+ if (UNLIKELY(len_squared_v3v3(positions[vert_index_prev], positions[vert_index]) <
+ tolerance_sq)) {
*vtmap_b = i;
tot_vtargetmap++;
/* average location */
- mid_v3_v3v3(mv->co, mv_prev->co, mv->co);
- copy_v3_v3(mv_prev->co, mv->co);
+ mid_v3_v3v3(positions[vert_index], positions[vert_index_prev], positions[vert_index]);
+ copy_v3_v3(positions[vert_index_prev], positions[vert_index]);
}
else {
*vtmap_b = -1;
@@ -273,13 +276,14 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd,
*vtmap_a = -1;
}
else {
- if (UNLIKELY(len_squared_v3v3(mv_prev->co, mv->co) < tolerance_sq)) {
+ if (UNLIKELY(len_squared_v3v3(positions[vert_index_prev], positions[vert_index]) <
+ tolerance_sq)) {
*vtmap_a = maxVerts + i;
tot_vtargetmap++;
/* average location */
- mid_v3_v3v3(mv->co, mv_prev->co, mv->co);
- copy_v3_v3(mv_prev->co, mv->co);
+ mid_v3_v3v3(positions[vert_index], positions[vert_index_prev], positions[vert_index]);
+ copy_v3_v3(positions[vert_index_prev], positions[vert_index]);
}
else {
*vtmap_a = -1;
@@ -405,7 +409,7 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd,
/* calculate custom normals into loop_normals, then mirror first half into second half */
- BKE_mesh_normals_loop_split(BKE_mesh_verts(result),
+ BKE_mesh_normals_loop_split(BKE_mesh_positions(result),
BKE_mesh_vertex_normals_ensure(result),
result->totvert,
BKE_mesh_edges(result),
diff --git a/source/blender/blenkernel/intern/mesh_normals.cc b/source/blender/blenkernel/intern/mesh_normals.cc
index ebb5a72d137..f59f147e24d 100644
--- a/source/blender/blenkernel/intern/mesh_normals.cc
+++ b/source/blender/blenkernel/intern/mesh_normals.cc
@@ -37,6 +37,7 @@
#include "atomic_ops.h"
using blender::BitVector;
+using blender::float3;
using blender::MutableSpan;
using blender::Span;
@@ -171,7 +172,7 @@ void BKE_mesh_assert_normals_dirty_or_calculated(const Mesh *mesh)
* \{ */
struct MeshCalcNormalsData_Poly {
- const MVert *mvert;
+ const float (*positions)[3];
const MLoop *mloop;
const MPoly *mpoly;
@@ -185,10 +186,10 @@ static void mesh_calc_normals_poly_fn(void *__restrict userdata,
{
const MeshCalcNormalsData_Poly *data = (MeshCalcNormalsData_Poly *)userdata;
const MPoly *mp = &data->mpoly[pidx];
- BKE_mesh_calc_poly_normal(mp, data->mloop + mp->loopstart, data->mvert, data->pnors[pidx]);
+ BKE_mesh_calc_poly_normal(mp, data->mloop + mp->loopstart, data->positions, data->pnors[pidx]);
}
-void BKE_mesh_calc_normals_poly(const MVert *mvert,
+void BKE_mesh_calc_normals_poly(const float (*positions)[3],
int /*mvert_len*/,
const MLoop *mloop,
int /*mloop_len*/,
@@ -205,7 +206,7 @@ void BKE_mesh_calc_normals_poly(const MVert *mvert,
MeshCalcNormalsData_Poly data = {};
data.mpoly = mpoly;
data.mloop = mloop;
- data.mvert = mvert;
+ data.positions = positions;
data.pnors = r_poly_normals;
BLI_task_parallel_range(0, mpoly_len, &data, mesh_calc_normals_poly_fn, &settings);
@@ -221,7 +222,7 @@ void BKE_mesh_calc_normals_poly(const MVert *mvert,
* \{ */
struct MeshCalcNormalsData_PolyAndVertex {
- const MVert *mvert;
+ const float (*positions)[3];
const MLoop *mloop;
const MPoly *mpoly;
@@ -238,7 +239,7 @@ static void mesh_calc_normals_poly_and_vertex_accum_fn(void *__restrict userdata
const MeshCalcNormalsData_PolyAndVertex *data = (MeshCalcNormalsData_PolyAndVertex *)userdata;
const MPoly *mp = &data->mpoly[pidx];
const MLoop *ml = &data->mloop[mp->loopstart];
- const MVert *mverts = data->mvert;
+ const float(*positions)[3] = data->positions;
float(*vnors)[3] = data->vnors;
float pnor_temp[3];
@@ -251,9 +252,9 @@ static void mesh_calc_normals_poly_and_vertex_accum_fn(void *__restrict userdata
{
zero_v3(pnor);
/* Newell's Method */
- const float *v_curr = mverts[ml[i_end].v].co;
+ const float *v_curr = positions[ml[i_end].v];
for (int i_next = 0; i_next <= i_end; i_next++) {
- const float *v_next = mverts[ml[i_next].v].co;
+ const float *v_next = positions[ml[i_next].v];
add_newell_cross_v3_v3v3(pnor, v_curr, v_next);
v_curr = v_next;
}
@@ -266,13 +267,13 @@ static void mesh_calc_normals_poly_and_vertex_accum_fn(void *__restrict userdata
/* Inline version of #accumulate_vertex_normals_poly_v3. */
{
float edvec_prev[3], edvec_next[3], edvec_end[3];
- const float *v_curr = mverts[ml[i_end].v].co;
- sub_v3_v3v3(edvec_prev, mverts[ml[i_end - 1].v].co, v_curr);
+ const float *v_curr = positions[ml[i_end].v];
+ sub_v3_v3v3(edvec_prev, positions[ml[i_end - 1].v], v_curr);
normalize_v3(edvec_prev);
copy_v3_v3(edvec_end, edvec_prev);
for (int i_next = 0, i_curr = i_end; i_next <= i_end; i_curr = i_next++) {
- const float *v_next = mverts[ml[i_next].v].co;
+ const float *v_next = positions[ml[i_next].v];
/* Skip an extra normalization by reusing the first calculated edge. */
if (i_next != i_end) {
@@ -299,16 +300,15 @@ static void mesh_calc_normals_poly_and_vertex_finalize_fn(
{
MeshCalcNormalsData_PolyAndVertex *data = (MeshCalcNormalsData_PolyAndVertex *)userdata;
- const MVert *mv = &data->mvert[vidx];
float *no = data->vnors[vidx];
if (UNLIKELY(normalize_v3(no) == 0.0f)) {
/* Following Mesh convention; we use vertex coordinate itself for normal in this case. */
- normalize_v3_v3(no, mv->co);
+ normalize_v3_v3(no, data->positions[vidx]);
}
}
-void BKE_mesh_calc_normals_poly_and_vertex(const MVert *mvert,
+void BKE_mesh_calc_normals_poly_and_vertex(const float (*positions)[3],
const int mvert_len,
const MLoop *mloop,
const int /*mloop_len*/,
@@ -326,7 +326,7 @@ void BKE_mesh_calc_normals_poly_and_vertex(const MVert *mvert,
MeshCalcNormalsData_PolyAndVertex data = {};
data.mpoly = mpoly;
data.mloop = mloop;
- data.mvert = mvert;
+ data.positions = positions;
data.pnors = r_poly_normals;
data.vnors = r_vert_normals;
@@ -368,15 +368,15 @@ const float (*BKE_mesh_vertex_normals_ensure(const Mesh *mesh))[3]
/* Isolate task because a mutex is locked and computing normals is multi-threaded. */
blender::threading::isolate_task([&]() {
Mesh &mesh_mutable = *const_cast<Mesh *>(mesh);
- const Span<MVert> verts = mesh_mutable.verts();
+ const Span<float3> positions = mesh_mutable.positions();
const Span<MPoly> polys = mesh_mutable.polys();
const Span<MLoop> loops = mesh_mutable.loops();
vert_normals = BKE_mesh_vertex_normals_for_write(&mesh_mutable);
poly_normals = BKE_mesh_poly_normals_for_write(&mesh_mutable);
- BKE_mesh_calc_normals_poly_and_vertex(verts.data(),
- verts.size(),
+ BKE_mesh_calc_normals_poly_and_vertex(reinterpret_cast<const float(*)[3]>(positions.data()),
+ positions.size(),
loops.data(),
loops.size(),
polys.data(),
@@ -413,14 +413,14 @@ const float (*BKE_mesh_poly_normals_ensure(const Mesh *mesh))[3]
/* Isolate task because a mutex is locked and computing normals is multi-threaded. */
blender::threading::isolate_task([&]() {
Mesh &mesh_mutable = *const_cast<Mesh *>(mesh);
- const Span<MVert> verts = mesh_mutable.verts();
+ const Span<float3> positions = mesh_mutable.positions();
const Span<MPoly> polys = mesh_mutable.polys();
const Span<MLoop> loops = mesh_mutable.loops();
poly_normals = BKE_mesh_poly_normals_for_write(&mesh_mutable);
- BKE_mesh_calc_normals_poly(verts.data(),
- verts.size(),
+ BKE_mesh_calc_normals_poly(reinterpret_cast<const float(*)[3]>(positions.data()),
+ positions.size(),
loops.data(),
loops.size(),
polys.data(),
@@ -464,7 +464,7 @@ void BKE_mesh_calc_normals(Mesh *mesh)
#endif
}
-void BKE_mesh_calc_normals_looptri(const MVert *mverts,
+void BKE_mesh_calc_normals_looptri(const float (*positions)[3],
int numVerts,
const MLoop *mloop,
const MLoopTri *looptri,
@@ -489,24 +489,23 @@ void BKE_mesh_calc_normals_looptri(const MVert *mverts,
mloop[lt->tri[2]].v,
};
- normal_tri_v3(f_no, mverts[vtri[0]].co, mverts[vtri[1]].co, mverts[vtri[2]].co);
+ normal_tri_v3(f_no, positions[vtri[0]], positions[vtri[1]], positions[vtri[2]]);
accumulate_vertex_normals_tri_v3(tnorms[vtri[0]],
tnorms[vtri[1]],
tnorms[vtri[2]],
f_no,
- mverts[vtri[0]].co,
- mverts[vtri[1]].co,
- mverts[vtri[2]].co);
+ positions[vtri[0]],
+ positions[vtri[1]],
+ positions[vtri[2]]);
}
/* Following Mesh convention; we use vertex coordinate itself for normal in this case. */
for (int i = 0; i < numVerts; i++) {
- const MVert *mv = &mverts[i];
float *no = tnorms[i];
if (UNLIKELY(normalize_v3(no) == 0.0f)) {
- normalize_v3_v3(no, mv->co);
+ normalize_v3_v3(no, positions[i]);
}
}
@@ -813,7 +812,7 @@ struct LoopSplitTaskDataCommon {
short (*clnors_data)[2];
/* Read-only. */
- const MVert *mverts;
+ const float (*positions)[3];
const MEdge *medges;
const MLoop *mloops;
const MPoly *mpolys;
@@ -939,7 +938,7 @@ static void mesh_edges_sharp_tag(LoopSplitTaskDataCommon *data,
}
}
-void BKE_edges_sharp_from_angle_set(const struct MVert *mverts,
+void BKE_edges_sharp_from_angle_set(const float (*positions)[3],
const int /*numVerts*/,
struct MEdge *medges,
const int numEdges,
@@ -963,7 +962,7 @@ void BKE_edges_sharp_from_angle_set(const struct MVert *mverts,
int *loop_to_poly = (int *)MEM_malloc_arrayN(size_t(numLoops), sizeof(*loop_to_poly), __func__);
LoopSplitTaskDataCommon common_data = {};
- common_data.mverts = mverts;
+ common_data.positions = positions;
common_data.medges = medges;
common_data.mloops = mloops;
common_data.mpolys = mpolys;
@@ -1031,7 +1030,7 @@ static void split_loop_nor_single_do(LoopSplitTaskDataCommon *common_data, LoopS
MLoopNorSpaceArray *lnors_spacearr = common_data->lnors_spacearr;
const short(*clnors_data)[2] = common_data->clnors_data;
- const MVert *mverts = common_data->mverts;
+ const float(*positions)[3] = common_data->positions;
const MEdge *medges = common_data->medges;
const float(*polynors)[3] = common_data->polynors;
@@ -1064,17 +1063,17 @@ static void split_loop_nor_single_do(LoopSplitTaskDataCommon *common_data, LoopS
float vec_curr[3], vec_prev[3];
const uint mv_pivot_index = ml_curr->v; /* The vertex we are "fanning" around! */
- const MVert *mv_pivot = &mverts[mv_pivot_index];
+ const float *mv_pivot = positions[mv_pivot_index];
const MEdge *me_curr = &medges[ml_curr->e];
- const MVert *mv_2 = (me_curr->v1 == mv_pivot_index) ? &mverts[me_curr->v2] :
- &mverts[me_curr->v1];
+ const float *mv_2 = (me_curr->v1 == mv_pivot_index) ? positions[me_curr->v2] :
+ positions[me_curr->v1];
const MEdge *me_prev = &medges[ml_prev->e];
- const MVert *mv_3 = (me_prev->v1 == mv_pivot_index) ? &mverts[me_prev->v2] :
- &mverts[me_prev->v1];
+ const float *mv_3 = (me_prev->v1 == mv_pivot_index) ? positions[me_prev->v2] :
+ positions[me_prev->v1];
- sub_v3_v3v3(vec_curr, mv_2->co, mv_pivot->co);
+ sub_v3_v3v3(vec_curr, mv_2, mv_pivot);
normalize_v3(vec_curr);
- sub_v3_v3v3(vec_prev, mv_3->co, mv_pivot->co);
+ sub_v3_v3v3(vec_prev, mv_3, mv_pivot);
normalize_v3(vec_prev);
BKE_lnor_space_define(lnor_space, *lnor, vec_curr, vec_prev, nullptr);
@@ -1093,7 +1092,7 @@ static void split_loop_nor_fan_do(LoopSplitTaskDataCommon *common_data, LoopSpli
float(*loopnors)[3] = common_data->loopnors;
short(*clnors_data)[2] = common_data->clnors_data;
- const MVert *mverts = common_data->mverts;
+ const float(*positions)[3] = common_data->positions;
const MEdge *medges = common_data->medges;
const MLoop *mloops = common_data->mloops;
const MPoly *mpolys = common_data->mpolys;
@@ -1121,7 +1120,7 @@ static void split_loop_nor_fan_do(LoopSplitTaskDataCommon *common_data, LoopSpli
* number of sharp edges per vertex, I doubt the additional memory usage would be worth it,
* especially as it should not be a common case in real-life meshes anyway). */
const uint mv_pivot_index = ml_curr->v; /* The vertex we are "fanning" around! */
- const MVert *mv_pivot = &mverts[mv_pivot_index];
+ const float *mv_pivot = positions[mv_pivot_index];
/* `ml_curr` would be mlfan_prev if we needed that one. */
const MEdge *me_org = &medges[ml_curr->e];
@@ -1157,9 +1156,10 @@ static void split_loop_nor_fan_do(LoopSplitTaskDataCommon *common_data, LoopSpli
/* Only need to compute previous edge's vector once, then we can just reuse old current one! */
{
- const MVert *mv_2 = (me_org->v1 == mv_pivot_index) ? &mverts[me_org->v2] : &mverts[me_org->v1];
+ const float *mv_2 = (me_org->v1 == mv_pivot_index) ? positions[me_org->v2] :
+ positions[me_org->v1];
- sub_v3_v3v3(vec_org, mv_2->co, mv_pivot->co);
+ sub_v3_v3v3(vec_org, mv_2, mv_pivot);
normalize_v3(vec_org);
copy_v3_v3(vec_prev, vec_org);
@@ -1178,10 +1178,10 @@ static void split_loop_nor_fan_do(LoopSplitTaskDataCommon *common_data, LoopSpli
* given the fact that this code should not be called that much in real-life meshes.
*/
{
- const MVert *mv_2 = (me_curr->v1 == mv_pivot_index) ? &mverts[me_curr->v2] :
- &mverts[me_curr->v1];
+ const float *mv_2 = (me_curr->v1 == mv_pivot_index) ? positions[me_curr->v2] :
+ positions[me_curr->v1];
- sub_v3_v3v3(vec_curr, mv_2->co, mv_pivot->co);
+ sub_v3_v3v3(vec_curr, mv_2, mv_pivot);
normalize_v3(vec_curr);
}
@@ -1599,7 +1599,7 @@ static void loop_split_generator(TaskPool *pool, LoopSplitTaskDataCommon *common
#endif
}
-void BKE_mesh_normals_loop_split(const MVert *mverts,
+void BKE_mesh_normals_loop_split(const float (*positions)[3],
const float (*vert_normals)[3],
const int /*numVerts*/,
const MEdge *medges,
@@ -1694,7 +1694,7 @@ void BKE_mesh_normals_loop_split(const MVert *mverts,
common_data.lnors_spacearr = r_lnors_spacearr;
common_data.loopnors = r_loopnors;
common_data.clnors_data = clnors_data;
- common_data.mverts = mverts;
+ common_data.positions = positions;
common_data.medges = medges;
common_data.mloops = mloops;
common_data.mpolys = mpolys;
@@ -1752,7 +1752,7 @@ void BKE_mesh_normals_loop_split(const MVert *mverts,
* r_custom_loopnors is expected to have normalized normals, or zero ones,
* in which case they will be replaced by default loop/vertex normal.
*/
-static void mesh_normals_loop_custom_set(const MVert *mverts,
+static void mesh_normals_loop_custom_set(const float (*positions)[3],
const float (*vert_normals)[3],
const int numVerts,
MEdge *medges,
@@ -1784,7 +1784,7 @@ static void mesh_normals_loop_custom_set(const MVert *mverts,
BLI_SMALLSTACK_DECLARE(clnors_data, short *);
/* Compute current lnor spacearr. */
- BKE_mesh_normals_loop_split(mverts,
+ BKE_mesh_normals_loop_split(positions,
vert_normals,
numVerts,
medges,
@@ -1907,7 +1907,7 @@ static void mesh_normals_loop_custom_set(const MVert *mverts,
/* And now, recompute our new auto lnors and lnor spacearr! */
BKE_lnor_spacearr_clear(&lnors_spacearr);
- BKE_mesh_normals_loop_split(mverts,
+ BKE_mesh_normals_loop_split(positions,
vert_normals,
numVerts,
medges,
@@ -1988,7 +1988,7 @@ static void mesh_normals_loop_custom_set(const MVert *mverts,
BKE_lnor_spacearr_free(&lnors_spacearr);
}
-void BKE_mesh_normals_loop_custom_set(const MVert *mverts,
+void BKE_mesh_normals_loop_custom_set(const float (*positions)[3],
const float (*vert_normals)[3],
const int numVerts,
MEdge *medges,
@@ -2001,7 +2001,7 @@ void BKE_mesh_normals_loop_custom_set(const MVert *mverts,
const int numPolys,
short (*r_clnors_data)[2])
{
- mesh_normals_loop_custom_set(mverts,
+ mesh_normals_loop_custom_set(positions,
vert_normals,
numVerts,
medges,
@@ -2016,7 +2016,7 @@ void BKE_mesh_normals_loop_custom_set(const MVert *mverts,
false);
}
-void BKE_mesh_normals_loop_custom_from_verts_set(const MVert *mverts,
+void BKE_mesh_normals_loop_custom_from_verts_set(const float (*positions)[3],
const float (*vert_normals)[3],
float (*r_custom_vertnors)[3],
const int numVerts,
@@ -2029,7 +2029,7 @@ void BKE_mesh_normals_loop_custom_from_verts_set(const MVert *mverts,
const int numPolys,
short (*r_clnors_data)[2])
{
- mesh_normals_loop_custom_set(mverts,
+ mesh_normals_loop_custom_set(positions,
vert_normals,
numVerts,
medges,
@@ -2057,14 +2057,14 @@ static void mesh_set_custom_normals(Mesh *mesh, float (*r_custom_nors)[3], const
clnors = (short(*)[2])CustomData_add_layer(
&mesh->ldata, CD_CUSTOMLOOPNORMAL, CD_SET_DEFAULT, nullptr, numloops);
}
- const Span<MVert> verts = mesh->verts();
+ const Span<float3> positions = mesh->positions();
MutableSpan<MEdge> edges = mesh->edges_for_write();
const Span<MPoly> polys = mesh->polys();
const Span<MLoop> loops = mesh->loops();
- mesh_normals_loop_custom_set(verts.data(),
+ mesh_normals_loop_custom_set(reinterpret_cast<const float(*)[3]>(positions.data()),
BKE_mesh_vertex_normals_ensure(mesh),
- verts.size(),
+ positions.size(),
edges.data(),
edges.size(),
loops.data(),
diff --git a/source/blender/blenkernel/intern/mesh_remap.c b/source/blender/blenkernel/intern/mesh_remap.c
index 90798ea593d..6d7c79ddbfc 100644
--- a/source/blender/blenkernel/intern/mesh_remap.c
+++ b/source/blender/blenkernel/intern/mesh_remap.c
@@ -110,7 +110,7 @@ static bool mesh_remap_bvhtree_query_raycast(BVHTreeFromMesh *treedata,
* \{ */
float BKE_mesh_remap_calc_difference_from_mesh(const SpaceTransform *space_transform,
- const MVert *verts_dst,
+ const float (*positions_dst)[3],
const int numverts_dst,
Mesh *me_src)
{
@@ -127,7 +127,7 @@ float BKE_mesh_remap_calc_difference_from_mesh(const SpaceTransform *space_trans
for (i = 0; i < numverts_dst; i++) {
float tmp_co[3];
- copy_v3_v3(tmp_co, verts_dst[i].co);
+ copy_v3_v3(tmp_co, positions_dst[i]);
/* Convert the vertex to tree coordinates, if needed. */
if (space_transform) {
@@ -164,7 +164,7 @@ float BKE_mesh_remap_calc_difference_from_mesh(const SpaceTransform *space_trans
* axes in those cases. We default to dummy generated orthogonal vectors in this case,
* instead of using eigen vectors.
*/
-static void mesh_calc_eigen_matrix(const MVert *verts,
+static void mesh_calc_eigen_matrix(const float (*positions)[3],
const float (*vcos)[3],
const int numverts,
float r_mat[4][4])
@@ -176,13 +176,12 @@ static void mesh_calc_eigen_matrix(const MVert *verts,
bool eigen_success;
int i;
- if (verts) {
- const MVert *mv;
+ if (positions) {
float(*co)[3];
cos = MEM_mallocN(sizeof(*cos) * (size_t)numverts, __func__);
- for (i = 0, co = cos, mv = verts; i < numverts; i++, co++, mv++) {
- copy_v3_v3(*co, mv->co);
+ for (i = 0, co = cos; i < numverts; i++, co++) {
+ copy_v3_v3(*co, positions[i]);
}
/* TODO(sergey): For until we officially drop all compilers which
* doesn't handle casting correct we use workaround to avoid explicit
@@ -244,7 +243,7 @@ static void mesh_calc_eigen_matrix(const MVert *verts,
copy_v3_v3(r_mat[3], center);
}
-void BKE_mesh_remap_find_best_match_from_mesh(const MVert *verts_dst,
+void BKE_mesh_remap_find_best_match_from_mesh(const float (*positions_dst)[3],
const int numverts_dst,
Mesh *me_src,
SpaceTransform *r_space_transform)
@@ -270,11 +269,11 @@ void BKE_mesh_remap_find_best_match_from_mesh(const MVert *verts_dst,
float(*vcos_src)[3] = BKE_mesh_vert_coords_alloc(me_src, NULL);
mesh_calc_eigen_matrix(NULL, (const float(*)[3])vcos_src, numverts_src, mat_src);
- mesh_calc_eigen_matrix(verts_dst, NULL, numverts_dst, mat_dst);
+ mesh_calc_eigen_matrix(positions_dst, NULL, numverts_dst, mat_dst);
BLI_space_transform_global_from_matrices(r_space_transform, mat_dst, mat_src);
match = BKE_mesh_remap_calc_difference_from_mesh(
- r_space_transform, verts_dst, numverts_dst, me_src);
+ r_space_transform, positions_dst, numverts_dst, me_src);
best_match = match;
copy_m4_m4(best_mat_dst, mat_dst);
@@ -286,7 +285,7 @@ void BKE_mesh_remap_find_best_match_from_mesh(const MVert *verts_dst,
BLI_space_transform_global_from_matrices(r_space_transform, mat_dst, mat_src);
match = BKE_mesh_remap_calc_difference_from_mesh(
- r_space_transform, verts_dst, numverts_dst, me_src);
+ r_space_transform, positions_dst, numverts_dst, me_src);
if (match < best_match) {
best_match = match;
copy_m4_m4(best_mat_dst, mat_dst);
@@ -469,7 +468,7 @@ void BKE_mesh_remap_calc_verts_from_mesh(const int mode,
const SpaceTransform *space_transform,
const float max_dist,
const float ray_radius,
- const MVert *verts_dst,
+ const float (*positions_dst)[3],
const int numverts_dst,
const bool UNUSED(dirty_nors_dst),
Mesh *me_src,
@@ -502,7 +501,7 @@ void BKE_mesh_remap_calc_verts_from_mesh(const int mode,
nearest.index = -1;
for (i = 0; i < numverts_dst; i++) {
- copy_v3_v3(tmp_co, verts_dst[i].co);
+ copy_v3_v3(tmp_co, positions_dst[i]);
/* Convert the vertex to tree coordinates, if needed. */
if (space_transform) {
@@ -527,7 +526,7 @@ void BKE_mesh_remap_calc_verts_from_mesh(const int mode,
nearest.index = -1;
for (i = 0; i < numverts_dst; i++) {
- copy_v3_v3(tmp_co, verts_dst[i].co);
+ copy_v3_v3(tmp_co, positions_dst[i]);
/* Convert the vertex to tree coordinates, if needed. */
if (space_transform) {
@@ -587,7 +586,7 @@ void BKE_mesh_remap_calc_verts_from_mesh(const int mode,
if (mode == MREMAP_MODE_VERT_POLYINTERP_VNORPROJ) {
for (i = 0; i < numverts_dst; i++) {
- copy_v3_v3(tmp_co, verts_dst[i].co);
+ copy_v3_v3(tmp_co, positions_dst[i]);
copy_v3_v3(tmp_no, vert_normals_dst[i]);
/* Convert the vertex to tree coordinates, if needed. */
@@ -624,7 +623,7 @@ void BKE_mesh_remap_calc_verts_from_mesh(const int mode,
nearest.index = -1;
for (i = 0; i < numverts_dst; i++) {
- copy_v3_v3(tmp_co, verts_dst[i].co);
+ copy_v3_v3(tmp_co, positions_dst[i]);
/* Convert the vertex to tree coordinates, if needed. */
if (space_transform) {
@@ -693,7 +692,7 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode,
const SpaceTransform *space_transform,
const float max_dist,
const float ray_radius,
- const MVert *verts_dst,
+ const float (*positions_dst)[3],
const int numverts_dst,
const MEdge *edges_dst,
const int numedges_dst,
@@ -762,7 +761,7 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode,
/* Compute closest verts only once! */
if (v_dst_to_src_map[vidx_dst].hit_dist == -1.0f) {
- copy_v3_v3(tmp_co, verts_dst[vidx_dst].co);
+ copy_v3_v3(tmp_co, positions_dst[vidx_dst]);
/* Convert the vertex to tree coordinates, if needed. */
if (space_transform) {
@@ -800,7 +799,7 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode,
const MEdge *e_src = &edges_src[*eidx_src];
const float *other_co_src = vcos_src[BKE_mesh_edge_other_vert(e_src, vidx_src)];
const float *other_co_dst =
- verts_dst[BKE_mesh_edge_other_vert(e_dst, (int)vidx_dst)].co;
+ positions_dst[BKE_mesh_edge_other_vert(e_dst, (int)vidx_dst)];
const float totdist = first_dist + len_v3v3(other_co_src, other_co_dst);
if (totdist < best_totdist) {
@@ -813,8 +812,8 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode,
if (best_eidx_src >= 0) {
const float *co1_src = vcos_src[edges_src[best_eidx_src].v1];
const float *co2_src = vcos_src[edges_src[best_eidx_src].v2];
- const float *co1_dst = verts_dst[e_dst->v1].co;
- const float *co2_dst = verts_dst[e_dst->v2].co;
+ const float *co1_dst = positions_dst[e_dst->v1];
+ const float *co2_dst = positions_dst[e_dst->v2];
float co_src[3], co_dst[3];
/* TODO: would need an isect_seg_seg_v3(), actually! */
@@ -855,7 +854,8 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode,
nearest.index = -1;
for (i = 0; i < numedges_dst; i++) {
- interp_v3_v3v3(tmp_co, verts_dst[edges_dst[i].v1].co, verts_dst[edges_dst[i].v2].co, 0.5f);
+ interp_v3_v3v3(
+ tmp_co, positions_dst[edges_dst[i].v1], positions_dst[edges_dst[i].v2], 0.5f);
/* Convert the vertex to tree coordinates, if needed. */
if (space_transform) {
@@ -881,7 +881,8 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode,
BKE_bvhtree_from_mesh_get(&treedata, me_src, BVHTREE_FROM_LOOPTRI, 2);
for (i = 0; i < numedges_dst; i++) {
- interp_v3_v3v3(tmp_co, verts_dst[edges_dst[i].v1].co, verts_dst[edges_dst[i].v2].co, 0.5f);
+ interp_v3_v3v3(
+ tmp_co, positions_dst[edges_dst[i].v1], positions_dst[edges_dst[i].v2], 0.5f);
/* Convert the vertex to tree coordinates, if needed. */
if (space_transform) {
@@ -953,8 +954,8 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode,
int sources_num = 0;
int j;
- copy_v3_v3(v1_co, verts_dst[me->v1].co);
- copy_v3_v3(v2_co, verts_dst[me->v2].co);
+ copy_v3_v3(v1_co, positions_dst[me->v1]);
+ copy_v3_v3(v2_co, positions_dst[me->v2]);
copy_v3_v3(v1_no, vert_normals_dst[me->v1]);
copy_v3_v3(v2_no, vert_normals_dst[me->v2]);
@@ -1041,7 +1042,7 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode,
static void mesh_island_to_astar_graph_edge_process(MeshIslandStore *islands,
const int island_index,
BLI_AStarGraph *as_graph,
- const MVert *verts,
+ const float (*positions)[3],
const MPoly *polys,
const MLoop *loops,
const int edge_idx,
@@ -1074,7 +1075,7 @@ static void mesh_island_to_astar_graph_edge_process(MeshIslandStore *islands,
}
if (poly_status[pidx_isld] == POLY_UNSET) {
- BKE_mesh_calc_poly_center(mp, &loops[mp->loopstart], verts, poly_centers[pidx_isld]);
+ BKE_mesh_calc_poly_center(mp, &loops[mp->loopstart], positions, poly_centers[pidx_isld]);
BLI_astar_node_init(as_graph, pidx_isld, poly_centers[pidx_isld]);
poly_status[pidx_isld] = POLY_CENTER_INIT;
}
@@ -1099,7 +1100,7 @@ static void mesh_island_to_astar_graph_edge_process(MeshIslandStore *islands,
static void mesh_island_to_astar_graph(MeshIslandStore *islands,
const int island_index,
- const MVert *verts,
+ const float (*positions)[3],
MeshElemMap *edge_to_poly_map,
const int numedges,
const MLoop *loops,
@@ -1138,7 +1139,7 @@ static void mesh_island_to_astar_graph(MeshIslandStore *islands,
mesh_island_to_astar_graph_edge_process(islands,
island_index,
r_as_graph,
- verts,
+ positions,
polys,
loops,
island_einnercut_map->indices[i],
@@ -1170,7 +1171,7 @@ static void mesh_island_to_astar_graph(MeshIslandStore *islands,
mesh_island_to_astar_graph_edge_process(islands,
island_index,
r_as_graph,
- verts,
+ positions,
polys,
loops,
(int)ml->e,
@@ -1229,7 +1230,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
const float max_dist,
const float ray_radius,
Mesh *mesh_dst,
- const MVert *verts_dst,
+ const float (*positions_dst)[3],
const int numverts_dst,
const MEdge *edges_dst,
const int numedges_dst,
@@ -1302,7 +1303,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
/* Unlike above, those are one-to-one mappings, simpler! */
int *loop_to_poly_map_src = NULL;
- const MVert *verts_src = BKE_mesh_verts(me_src);
+ const float(*positions_src)[3] = BKE_mesh_positions(me_src);
const int num_verts_src = me_src->totvert;
float(*vcos_src)[3] = NULL;
const MEdge *edges_src = BKE_mesh_edges(me_src);
@@ -1358,7 +1359,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
CustomData_set_layer_flag(ldata_dst, CD_NORMAL, CD_FLAG_TEMPORARY);
}
if (dirty_nors_dst || do_loop_nors_dst) {
- BKE_mesh_normals_loop_split(verts_dst,
+ BKE_mesh_normals_loop_split(positions_dst,
BKE_mesh_vertex_normals_ensure(mesh_dst),
numverts_dst,
edges_dst,
@@ -1425,7 +1426,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
plidx_src++, lidx_src++) {
loop_to_poly_map_src[lidx_src] = pidx_src;
}
- BKE_mesh_calc_poly_center(mp_src, ml_src, verts_src, poly_cents_src[pidx_src]);
+ BKE_mesh_calc_poly_center(mp_src, ml_src, positions_src, poly_cents_src[pidx_src]);
}
}
@@ -1438,7 +1439,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
/* First, generate the islands, if possible. */
if (gen_islands_src) {
- use_islands = gen_islands_src(verts_src,
+ use_islands = gen_islands_src(positions_src,
num_verts_src,
edges_src,
num_edges_src,
@@ -1476,7 +1477,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
for (tindex = 0; tindex < num_trees; tindex++) {
mesh_island_to_astar_graph(use_islands ? &island_store : NULL,
tindex,
- verts_src,
+ positions_src,
edge_to_poly_map_src,
num_edges_src,
loops_src,
@@ -1507,7 +1508,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
}
}
bvhtree_from_mesh_verts_ex(&treedata[tindex],
- verts_src,
+ positions_src,
num_verts_src,
verts_active,
num_verts_active,
@@ -1543,7 +1544,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
}
}
bvhtree_from_mesh_looptri_ex(&treedata[tindex],
- verts_src,
+ positions_src,
loops_src,
looptri_src,
num_looptri_src,
@@ -1599,7 +1600,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
if (use_from_vert) {
MeshElemMap *vert_to_refelem_map_src = NULL;
- copy_v3_v3(tmp_co, verts_dst[ml_dst->v].co);
+ copy_v3_v3(tmp_co, positions_dst[ml_dst->v]);
nearest.index = -1;
/* Convert the vertex to tree coordinates, if needed. */
@@ -1662,7 +1663,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
if (!pcent_dst_valid) {
BKE_mesh_calc_poly_center(
- mp_dst, &loops_dst[mp_dst->loopstart], verts_dst, pcent_dst);
+ mp_dst, &loops_dst[mp_dst->loopstart], positions_dst, pcent_dst);
pcent_dst_valid = true;
}
pcent_src = poly_cents_src[pidx_src];
@@ -1708,7 +1709,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
int n = (ray_radius > 0.0f) ? MREMAP_RAYCAST_APPROXIMATE_NR : 1;
float w = 1.0f;
- copy_v3_v3(tmp_co, verts_dst[ml_dst->v].co);
+ copy_v3_v3(tmp_co, positions_dst[ml_dst->v]);
copy_v3_v3(tmp_no, loop_nors_dst[plidx_dst + mp_dst->loopstart]);
/* We do our transform here, since we may do several raycast/nearest queries. */
@@ -1736,7 +1737,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
* is null, it means none of its loop mapped to this source island,
* hence we can skip it later.
*/
- copy_v3_v3(tmp_co, verts_dst[ml_dst->v].co);
+ copy_v3_v3(tmp_co, positions_dst[ml_dst->v]);
nearest.index = -1;
/* Convert the vertex to tree coordinates, if needed. */
@@ -1762,7 +1763,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
}
}
else { /* Nearest poly either to use all its loops/verts or just closest one. */
- copy_v3_v3(tmp_co, verts_dst[ml_dst->v].co);
+ copy_v3_v3(tmp_co, positions_dst[ml_dst->v]);
nearest.index = -1;
/* Convert the vertex to tree coordinates, if needed. */
@@ -1892,7 +1893,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
float best_dist_sq = FLT_MAX;
ml_dst = &loops_dst[lidx_dst];
- copy_v3_v3(tmp_co, verts_dst[ml_dst->v].co);
+ copy_v3_v3(tmp_co, positions_dst[ml_dst->v]);
/* We do our transform here,
* since we may do several raycast/nearest queries. */
@@ -1905,7 +1906,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
mp_src = &polys_src[pidx_src];
ml_src = &loops_src[mp_src->loopstart];
for (j = 0; j < mp_src->totloop; j++, ml_src++) {
- const float dist_sq = len_squared_v3v3(verts_src[ml_src->v].co, tmp_co);
+ const float dist_sq = len_squared_v3v3(positions_src[ml_src->v], tmp_co);
if (dist_sq < best_dist_sq) {
best_dist_sq = dist_sq;
lidx_src = mp_src->loopstart + j;
@@ -1984,7 +1985,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
int j;
ml_dst = &loops_dst[lidx_dst];
- copy_v3_v3(tmp_co, verts_dst[ml_dst->v].co);
+ copy_v3_v3(tmp_co, positions_dst[ml_dst->v]);
/* We do our transform here,
* since we may do several raycast/nearest queries. */
@@ -2151,7 +2152,7 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode,
const float max_dist,
const float ray_radius,
const Mesh *mesh_dst,
- const MVert *verts_dst,
+ const float (*positions_dst)[3],
const MLoop *loops_dst,
const MPoly *polys_dst,
const int numpolys_dst,
@@ -2192,7 +2193,7 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode,
for (i = 0; i < numpolys_dst; i++) {
const MPoly *mp = &polys_dst[i];
- BKE_mesh_calc_poly_center(mp, &loops_dst[mp->loopstart], verts_dst, tmp_co);
+ BKE_mesh_calc_poly_center(mp, &loops_dst[mp->loopstart], positions_dst, tmp_co);
/* Convert the vertex to tree coordinates, if needed. */
if (space_transform) {
@@ -2217,7 +2218,7 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode,
for (i = 0; i < numpolys_dst; i++) {
const MPoly *mp = &polys_dst[i];
- BKE_mesh_calc_poly_center(mp, &loops_dst[mp->loopstart], verts_dst, tmp_co);
+ BKE_mesh_calc_poly_center(mp, &loops_dst[mp->loopstart], positions_dst, tmp_co);
copy_v3_v3(tmp_no, poly_nors_dst[i]);
/* Convert the vertex to tree coordinates, if needed. */
@@ -2277,7 +2278,7 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode,
const int tris_num = mp->totloop - 2;
int j;
- BKE_mesh_calc_poly_center(mp, &loops_dst[mp->loopstart], verts_dst, pcent_dst);
+ BKE_mesh_calc_poly_center(mp, &loops_dst[mp->loopstart], positions_dst, pcent_dst);
copy_v3_v3(tmp_no, poly_nors_dst[i]);
/* We do our transform here, else it'd be redone by raycast helper for each ray, ugh! */
@@ -2305,7 +2306,7 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode,
for (j = 0; j < mp->totloop; j++) {
const MLoop *ml = &loops_dst[j + mp->loopstart];
- copy_v3_v3(tmp_co, verts_dst[ml->v].co);
+ copy_v3_v3(tmp_co, positions_dst[ml->v]);
if (space_transform) {
BLI_space_transform_apply(space_transform, tmp_co);
}
diff --git a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc
index 0887e26148a..d3b690a34bb 100644
--- a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc
+++ b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc
@@ -63,7 +63,7 @@ static Mesh *remesh_quadriflow(const Mesh *input_mesh,
void (*update_cb)(void *, float progress, int *cancel),
void *update_cb_data)
{
- const Span<MVert> input_verts = input_mesh->verts();
+ const Span<float3> input_positions = input_mesh->positions();
const Span<MLoop> input_loops = input_mesh->loops();
const MLoopTri *looptri = BKE_mesh_runtime_looptri_ensure(input_mesh);
@@ -75,13 +75,8 @@ static Mesh *remesh_quadriflow(const Mesh *input_mesh,
const int totfaces = BKE_mesh_runtime_looptri_len(input_mesh);
const int totverts = input_mesh->totvert;
- Array<float3> verts(totverts);
Array<int> faces(totfaces * 3);
- for (const int i : IndexRange(totverts)) {
- verts[i] = input_verts[i].co;
- }
-
for (const int i : IndexRange(totfaces)) {
MVertTri &vt = verttri[i];
faces[i * 3] = vt.tri[0];
@@ -94,7 +89,7 @@ static Mesh *remesh_quadriflow(const Mesh *input_mesh,
qrd.totfaces = totfaces;
qrd.totverts = totverts;
- qrd.verts = (float *)verts.data();
+ qrd.verts = (float *)input_positions.data();
qrd.faces = faces.data();
qrd.target_faces = target_faces;
@@ -127,13 +122,11 @@ static Mesh *remesh_quadriflow(const Mesh *input_mesh,
/* Construct the new output mesh */
Mesh *mesh = BKE_mesh_new_nomain(qrd.out_totverts, 0, 0, qrd.out_totfaces * 4, qrd.out_totfaces);
BKE_mesh_copy_parameters(mesh, input_mesh);
- MutableSpan<MVert> mesh_verts = mesh->verts_for_write();
MutableSpan<MPoly> polys = mesh->polys_for_write();
MutableSpan<MLoop> loops = mesh->loops_for_write();
- for (const int i : IndexRange(qrd.out_totverts)) {
- copy_v3_v3(mesh_verts[i].co, &qrd.out_verts[i * 3]);
- }
+ mesh->positions_for_write().copy_from(
+ Span(reinterpret_cast<float3 *>(qrd.out_verts), qrd.out_totverts));
for (const int i : IndexRange(qrd.out_totfaces)) {
MPoly &poly = polys[i];
@@ -193,7 +186,7 @@ Mesh *BKE_mesh_remesh_quadriflow(const Mesh *mesh,
static openvdb::FloatGrid::Ptr remesh_voxel_level_set_create(const Mesh *mesh,
const float voxel_size)
{
- const Span<MVert> verts = mesh->verts();
+ const Span<float3> positions = mesh->positions();
const Span<MLoop> loops = mesh->loops();
const Span<MLoopTri> looptris = mesh->looptris();
@@ -201,7 +194,7 @@ static openvdb::FloatGrid::Ptr remesh_voxel_level_set_create(const Mesh *mesh,
std::vector<openvdb::Vec3I> triangles(looptris.size());
for (const int i : IndexRange(mesh->totvert)) {
- const float3 co = verts[i].co;
+ const float3 &co = positions[i];
points[i] = openvdb::Vec3s(co.x, co.y, co.z);
}
@@ -232,12 +225,12 @@ static Mesh *remesh_voxel_volume_to_mesh(const openvdb::FloatGrid::Ptr level_set
Mesh *mesh = BKE_mesh_new_nomain(
vertices.size(), 0, 0, quads.size() * 4 + tris.size() * 3, quads.size() + tris.size());
- MutableSpan<MVert> mesh_verts = mesh->verts_for_write();
+ MutableSpan<float3> mesh_positions = mesh->positions_for_write();
MutableSpan<MPoly> mesh_polys = mesh->polys_for_write();
MutableSpan<MLoop> mesh_loops = mesh->loops_for_write();
- for (const int i : mesh_verts.index_range()) {
- copy_v3_v3(mesh_verts[i].co, float3(vertices[i].x(), vertices[i].y(), vertices[i].z()));
+ for (const int i : mesh_positions.index_range()) {
+ mesh_positions[i] = float3(vertices[i].x(), vertices[i].y(), vertices[i].z());
}
for (const int i : IndexRange(quads.size())) {
@@ -288,7 +281,7 @@ void BKE_mesh_remesh_reproject_paint_mask(Mesh *target, const Mesh *source)
{
BVHTreeFromMesh bvhtree = {nullptr};
BKE_bvhtree_from_mesh_get(&bvhtree, source, BVHTREE_FROM_VERTS, 2);
- const MVert *target_verts = (const MVert *)CustomData_get_layer(&target->vdata, CD_MVERT);
+ const Span<float3> target_positions = target->positions();
const float *source_mask = (const float *)CustomData_get_layer(&source->vdata, CD_PAINT_MASK);
if (source_mask == nullptr) {
return;
@@ -305,13 +298,11 @@ void BKE_mesh_remesh_reproject_paint_mask(Mesh *target, const Mesh *source)
blender::threading::parallel_for(IndexRange(target->totvert), 4096, [&](const IndexRange range) {
for (const int i : range) {
- float from_co[3];
BVHTreeNearest nearest;
nearest.index = -1;
nearest.dist_sq = FLT_MAX;
- copy_v3_v3(from_co, target_verts[i].co);
BLI_bvhtree_find_nearest(
- bvhtree.tree, from_co, &nearest, bvhtree.nearest_callback, &bvhtree);
+ bvhtree.tree, target_positions[i], &nearest, bvhtree.nearest_callback, &bvhtree);
if (nearest.index != -1) {
target_mask[i] = source_mask[nearest.index];
}
@@ -327,7 +318,7 @@ void BKE_remesh_reproject_sculpt_face_sets(Mesh *target, const Mesh *source)
const AttributeAccessor src_attributes = source->attributes();
MutableAttributeAccessor dst_attributes = target->attributes_for_write();
const MPoly *target_polys = (const MPoly *)CustomData_get_layer(&target->pdata, CD_MPOLY);
- const MVert *target_verts = (const MVert *)CustomData_get_layer(&target->vdata, CD_MVERT);
+ const Span<float3> target_positions = target->positions();
const MLoop *target_loops = (const MLoop *)CustomData_get_layer(&target->ldata, CD_MLOOP);
const VArray<int> src_face_sets = src_attributes.lookup<int>(".sculpt_face_set",
@@ -355,7 +346,10 @@ void BKE_remesh_reproject_sculpt_face_sets(Mesh *target, const Mesh *source)
nearest.index = -1;
nearest.dist_sq = FLT_MAX;
const MPoly *mpoly = &target_polys[i];
- BKE_mesh_calc_poly_center(mpoly, &target_loops[mpoly->loopstart], target_verts, from_co);
+ BKE_mesh_calc_poly_center(mpoly,
+ &target_loops[mpoly->loopstart],
+ reinterpret_cast<const float(*)[3]>(target_positions.data()),
+ from_co);
BLI_bvhtree_find_nearest(
bvhtree.tree, from_co, &nearest, bvhtree.nearest_callback, &bvhtree);
if (nearest.index != -1) {
@@ -374,6 +368,7 @@ void BKE_remesh_reproject_vertex_paint(Mesh *target, const Mesh *source)
{
BVHTreeFromMesh bvhtree = {nullptr};
BKE_bvhtree_from_mesh_get(&bvhtree, source, BVHTREE_FROM_VERTS, 2);
+ const Span<float3> target_positions = target->positions();
int i = 0;
const CustomDataLayer *layer;
@@ -403,7 +398,6 @@ void BKE_remesh_reproject_vertex_paint(Mesh *target, const Mesh *source)
size_t data_size = CustomData_sizeof(layer->type);
void *target_data = target_cdata->layers[layer_i].data;
void *source_data = layer->data;
- MVert *target_verts = (MVert *)CustomData_get_layer(&target->vdata, CD_MVERT);
if (domain == ATTR_DOMAIN_POINT) {
blender::threading::parallel_for(
@@ -413,8 +407,7 @@ void BKE_remesh_reproject_vertex_paint(Mesh *target, const Mesh *source)
nearest.index = -1;
nearest.dist_sq = FLT_MAX;
BLI_bvhtree_find_nearest(
- bvhtree.tree, target_verts[i].co, &nearest, bvhtree.nearest_callback, &bvhtree);
-
+ bvhtree.tree, target_positions[i], &nearest, bvhtree.nearest_callback, &bvhtree);
if (nearest.index != -1) {
memcpy(POINTER_OFFSET(target_data, size_t(i) * data_size),
POINTER_OFFSET(source_data, size_t(nearest.index) * data_size),
@@ -450,7 +443,7 @@ void BKE_remesh_reproject_vertex_paint(Mesh *target, const Mesh *source)
nearest.index = -1;
nearest.dist_sq = FLT_MAX;
BLI_bvhtree_find_nearest(
- bvhtree.tree, target_verts[i].co, &nearest, bvhtree.nearest_callback, &bvhtree);
+ bvhtree.tree, target_positions[i], &nearest, bvhtree.nearest_callback, &bvhtree);
if (nearest.index == -1) {
continue;
diff --git a/source/blender/blenkernel/intern/mesh_runtime.cc b/source/blender/blenkernel/intern/mesh_runtime.cc
index e90a298ad8d..86e8eff1bf1 100644
--- a/source/blender/blenkernel/intern/mesh_runtime.cc
+++ b/source/blender/blenkernel/intern/mesh_runtime.cc
@@ -24,6 +24,7 @@
#include "BKE_shrinkwrap.h"
#include "BKE_subdiv_ccg.h"
+using blender::float3;
using blender::MutableSpan;
using blender::Span;
@@ -94,14 +95,14 @@ void BKE_mesh_runtime_looptri_recalc(Mesh *mesh)
{
mesh_ensure_looptri_data(mesh);
BLI_assert(mesh->totpoly == 0 || mesh->runtime->looptris.array_wip != nullptr);
- const Span<MVert> verts = mesh->verts();
+ const Span<float3> positions = mesh->positions();
const Span<MPoly> polys = mesh->polys();
const Span<MLoop> loops = mesh->loops();
if (!BKE_mesh_poly_normals_are_dirty(mesh)) {
BKE_mesh_recalc_looptri_with_normals(loops.data(),
polys.data(),
- verts.data(),
+ reinterpret_cast<const float(*)[3]>(positions.data()),
mesh->totloop,
mesh->totpoly,
mesh->runtime->looptris.array_wip,
@@ -110,7 +111,7 @@ void BKE_mesh_runtime_looptri_recalc(Mesh *mesh)
else {
BKE_mesh_recalc_looptri(loops.data(),
polys.data(),
- verts.data(),
+ reinterpret_cast<const float(*)[3]>(positions.data()),
mesh->totloop,
mesh->totpoly,
mesh->runtime->looptris.array_wip);
@@ -292,7 +293,7 @@ bool BKE_mesh_runtime_is_valid(Mesh *me_eval)
printf("MESH: %s\n", me_eval->id.name + 2);
}
- MutableSpan<MVert> verts = me_eval->verts_for_write();
+ MutableSpan<float3> positions = me_eval->positions_for_write();
MutableSpan<MEdge> edges = me_eval->edges_for_write();
MutableSpan<MPoly> polys = me_eval->polys_for_write();
MutableSpan<MLoop> loops = me_eval->loops_for_write();
@@ -313,8 +314,8 @@ bool BKE_mesh_runtime_is_valid(Mesh *me_eval)
is_valid &= BKE_mesh_validate_arrays(
me_eval,
- verts.data(),
- verts.size(),
+ reinterpret_cast<float(*)[3]>(positions.data()),
+ positions.size(),
edges.data(),
edges.size(),
static_cast<MFace *>(CustomData_get_layer(&me_eval->fdata, CD_MFACE)),
diff --git a/source/blender/blenkernel/intern/mesh_sample.cc b/source/blender/blenkernel/intern/mesh_sample.cc
index ed7ae8113a7..005986cb767 100644
--- a/source/blender/blenkernel/intern/mesh_sample.cc
+++ b/source/blender/blenkernel/intern/mesh_sample.cc
@@ -156,7 +156,7 @@ Span<float3> MeshAttributeInterpolator::ensure_barycentric_coords()
}
bary_coords_.reinitialize(mask_.min_array_size());
- const Span<MVert> verts = mesh_->verts();
+ const Span<float3> positions = mesh_->positions();
const Span<MLoop> loops = mesh_->loops();
const Span<MLoopTri> looptris = mesh_->looptris();
@@ -169,9 +169,9 @@ Span<float3> MeshAttributeInterpolator::ensure_barycentric_coords()
const int v2_index = loops[looptri.tri[2]].v;
interp_weights_tri_v3(bary_coords_[i],
- verts[v0_index].co,
- verts[v1_index].co,
- verts[v2_index].co,
+ positions[v0_index],
+ positions[v1_index],
+ positions[v2_index],
positions_[i]);
}
return bary_coords_;
@@ -185,7 +185,7 @@ Span<float3> MeshAttributeInterpolator::ensure_nearest_weights()
}
nearest_weights_.reinitialize(mask_.min_array_size());
- const Span<MVert> verts = mesh_->verts();
+ const Span<float3> positions = mesh_->positions();
const Span<MLoop> loops = mesh_->loops();
const Span<MLoopTri> looptris = mesh_->looptris();
@@ -197,9 +197,9 @@ Span<float3> MeshAttributeInterpolator::ensure_nearest_weights()
const int v1_index = loops[looptri.tri[1]].v;
const int v2_index = loops[looptri.tri[2]].v;
- const float d0 = len_squared_v3v3(positions_[i], verts[v0_index].co);
- const float d1 = len_squared_v3v3(positions_[i], verts[v1_index].co);
- const float d2 = len_squared_v3v3(positions_[i], verts[v2_index].co);
+ const float d0 = len_squared_v3v3(positions_[i], positions[v0_index]);
+ const float d1 = len_squared_v3v3(positions_[i], positions[v1_index]);
+ const float d2 = len_squared_v3v3(positions_[i], positions[v2_index]);
nearest_weights_[i] = MIN3_PAIR(d0, d1, d2, float3(1, 0, 0), float3(0, 1, 0), float3(0, 0, 1));
}
@@ -258,7 +258,7 @@ int sample_surface_points_spherical(RandomNumberGenerator &rng,
Vector<int> &r_looptri_indices,
Vector<float3> &r_positions)
{
- const Span<MVert> verts = mesh.verts();
+ const Span<float3> positions = mesh.positions();
const Span<MLoop> loops = mesh.loops();
const Span<MLoopTri> looptris = mesh.looptris();
@@ -272,9 +272,9 @@ int sample_surface_points_spherical(RandomNumberGenerator &rng,
for (const int looptri_index : looptri_indices_to_sample) {
const MLoopTri &looptri = looptris[looptri_index];
- const float3 &v0 = verts[loops[looptri.tri[0]].v].co;
- const float3 &v1 = verts[loops[looptri.tri[1]].v].co;
- const float3 &v2 = verts[loops[looptri.tri[2]].v].co;
+ const float3 &v0 = positions[loops[looptri.tri[0]].v];
+ const float3 &v1 = positions[loops[looptri.tri[1]].v];
+ const float3 &v2 = positions[loops[looptri.tri[2]].v];
const float looptri_area = area_tri_v3(v0, v1, v2);
@@ -355,7 +355,7 @@ int sample_surface_points_projected(
Vector<int> &r_looptri_indices,
Vector<float3> &r_positions)
{
- const Span<MVert> verts = mesh.verts();
+ const Span<float3> positions = mesh.positions();
const Span<MLoop> loops = mesh.loops();
const Span<MLoopTri> looptris = mesh.looptris();
@@ -398,7 +398,7 @@ int sample_surface_points_projected(
const float3 pos = ray_hit.co;
const float3 bary_coords = compute_bary_coord_in_triangle(
- verts, loops, looptris[looptri_index], pos);
+ positions, loops, looptris[looptri_index], pos);
r_positions.append(pos);
r_bary_coords.append(bary_coords);
@@ -408,14 +408,14 @@ int sample_surface_points_projected(
return point_count;
}
-float3 compute_bary_coord_in_triangle(const Span<MVert> verts,
+float3 compute_bary_coord_in_triangle(const Span<float3> positions,
const Span<MLoop> loops,
const MLoopTri &looptri,
const float3 &position)
{
- const float3 &v0 = verts[loops[looptri.tri[0]].v].co;
- const float3 &v1 = verts[loops[looptri.tri[1]].v].co;
- const float3 &v2 = verts[loops[looptri.tri[2]].v].co;
+ const float3 &v0 = positions[loops[looptri.tri[0]].v];
+ const float3 &v1 = positions[loops[looptri.tri[1]].v];
+ const float3 &v2 = positions[loops[looptri.tri[2]].v];
float3 bary_coords;
interp_weights_tri_v3(bary_coords, v0, v1, v2, position);
return bary_coords;
diff --git a/source/blender/blenkernel/intern/mesh_tangent.cc b/source/blender/blenkernel/intern/mesh_tangent.cc
index 49ea23a1552..56e731c3adf 100644
--- a/source/blender/blenkernel/intern/mesh_tangent.cc
+++ b/source/blender/blenkernel/intern/mesh_tangent.cc
@@ -47,7 +47,7 @@ struct BKEMeshToTangent {
mikk::float3 GetPosition(const uint face_num, const uint vert_num)
{
const uint loop_idx = uint(mpolys[face_num].loopstart) + vert_num;
- return mikk::float3(mverts[mloops[loop_idx].v].co);
+ return mikk::float3(positions[mloops[loop_idx].v]);
}
mikk::float3 GetTexCoord(const uint face_num, const uint vert_num)
@@ -67,16 +67,16 @@ struct BKEMeshToTangent {
copy_v4_fl4(p_res, T.x, T.y, T.z, orientation ? 1.0f : -1.0f);
}
- const MPoly *mpolys; /* faces */
- const MLoop *mloops; /* faces vertices */
- const MVert *mverts; /* vertices */
- const MLoopUV *luvs; /* texture coordinates */
- const float (*lnors)[3]; /* loops' normals */
- float (*tangents)[4]; /* output tangents */
- int num_polys; /* number of polygons */
+ const MPoly *mpolys; /* faces */
+ const MLoop *mloops; /* faces vertices */
+ const float (*positions)[3]; /* vertices */
+ const MLoopUV *luvs; /* texture coordinates */
+ const float (*lnors)[3]; /* loops' normals */
+ float (*tangents)[4]; /* output tangents */
+ int num_polys; /* number of polygons */
};
-void BKE_mesh_calc_loop_tangent_single_ex(const MVert *mverts,
+void BKE_mesh_calc_loop_tangent_single_ex(const float (*positions)[3],
const int /*numVerts*/,
const MLoop *mloops,
float (*r_looptangent)[4],
@@ -91,7 +91,7 @@ void BKE_mesh_calc_loop_tangent_single_ex(const MVert *mverts,
BKEMeshToTangent mesh_to_tangent;
mesh_to_tangent.mpolys = mpolys;
mesh_to_tangent.mloops = mloops;
- mesh_to_tangent.mverts = mverts;
+ mesh_to_tangent.positions = positions;
mesh_to_tangent.luvs = loopuvs;
mesh_to_tangent.lnors = loopnors;
mesh_to_tangent.tangents = r_looptangent;
@@ -141,7 +141,7 @@ void BKE_mesh_calc_loop_tangent_single(Mesh *mesh,
return;
}
- BKE_mesh_calc_loop_tangent_single_ex(BKE_mesh_verts(mesh),
+ BKE_mesh_calc_loop_tangent_single_ex(BKE_mesh_positions(mesh),
mesh->totvert,
BKE_mesh_loops(mesh),
r_looptangents,
@@ -213,7 +213,7 @@ struct SGLSLMeshToTangent {
{
const MLoopTri *lt;
uint loop_index = GetLoop(face_num, vert_num, lt);
- return mikk::float3(mvert[mloop[loop_index].v].co);
+ return mikk::float3(positions[mloop[loop_index].v]);
}
mikk::float3 GetTexCoord(const uint face_num, const uint vert_num)
@@ -246,18 +246,18 @@ struct SGLSLMeshToTangent {
float normal[3];
if (mp->totloop == 4) {
normal_quad_v3(normal,
- mvert[mloop[mp->loopstart + 0].v].co,
- mvert[mloop[mp->loopstart + 1].v].co,
- mvert[mloop[mp->loopstart + 2].v].co,
- mvert[mloop[mp->loopstart + 3].v].co);
+ positions[mloop[mp->loopstart + 0].v],
+ positions[mloop[mp->loopstart + 1].v],
+ positions[mloop[mp->loopstart + 2].v],
+ positions[mloop[mp->loopstart + 3].v]);
}
else
#endif
{
normal_tri_v3(normal,
- mvert[mloop[lt->tri[0]].v].co,
- mvert[mloop[lt->tri[1]].v].co,
- mvert[mloop[lt->tri[2]].v].co);
+ positions[mloop[lt->tri[0]].v],
+ positions[mloop[lt->tri[1]].v],
+ positions[mloop[lt->tri[2]].v]);
}
return mikk::float3(normal);
}
@@ -275,10 +275,10 @@ struct SGLSLMeshToTangent {
const float (*precomputedFaceNormals)[3];
const float (*precomputedLoopNormals)[3];
const MLoopTri *looptri;
- const MLoopUV *mloopuv; /* texture coordinates */
- const MPoly *mpoly; /* indices */
- const MLoop *mloop; /* indices */
- const MVert *mvert; /* vertex coordinates */
+ const MLoopUV *mloopuv; /* texture coordinates */
+ const MPoly *mpoly; /* indices */
+ const MLoop *mloop; /* indices */
+ const float (*positions)[3]; /* vertex coordinates */
const float (*vert_normals)[3];
const float (*orco)[3];
float (*tangent)[4]; /* destination */
@@ -385,7 +385,7 @@ void BKE_mesh_calc_loop_tangent_step_0(const CustomData *loopData,
}
}
-void BKE_mesh_calc_loop_tangent_ex(const MVert *mvert,
+void BKE_mesh_calc_loop_tangent_ex(const float (*positions)[3],
const MPoly *mpoly,
const uint mpoly_len,
const MLoop *mloop,
@@ -490,7 +490,7 @@ void BKE_mesh_calc_loop_tangent_ex(const MVert *mvert,
mesh2tangent->face_as_quad_map = face_as_quad_map;
mesh2tangent->num_face_as_quad_map = num_face_as_quad_map;
#endif
- mesh2tangent->mvert = mvert;
+ mesh2tangent->positions = positions;
mesh2tangent->vert_normals = vert_normals;
mesh2tangent->mpoly = mpoly;
mesh2tangent->mloop = mloop;
@@ -573,7 +573,7 @@ void BKE_mesh_calc_loop_tangents(Mesh *me_eval,
/* TODO(@campbellbarton): store in Mesh.runtime to avoid recalculation. */
short tangent_mask = 0;
BKE_mesh_calc_loop_tangent_ex(
- BKE_mesh_verts(me_eval),
+ BKE_mesh_positions(me_eval),
BKE_mesh_polys(me_eval),
uint(me_eval->totpoly),
BKE_mesh_loops(me_eval),
diff --git a/source/blender/blenkernel/intern/mesh_tessellate.cc b/source/blender/blenkernel/intern/mesh_tessellate.cc
index df83743634c..eaef90dec9b 100644
--- a/source/blender/blenkernel/intern/mesh_tessellate.cc
+++ b/source/blender/blenkernel/intern/mesh_tessellate.cc
@@ -42,7 +42,7 @@
*/
BLI_INLINE void mesh_calc_tessellation_for_face_impl(const MLoop *mloop,
const MPoly *mpoly,
- const MVert *mvert,
+ const float (*positions)[3],
uint poly_index,
MLoopTri *mlt,
MemArena **pf_arena_p,
@@ -72,17 +72,17 @@ BLI_INLINE void mesh_calc_tessellation_for_face_impl(const MLoop *mloop,
if (UNLIKELY(face_normal ? is_quad_flip_v3_first_third_fast_with_normal(
/* Simpler calculation (using the normal). */
- mvert[mloop[mlt_a->tri[0]].v].co,
- mvert[mloop[mlt_a->tri[1]].v].co,
- mvert[mloop[mlt_a->tri[2]].v].co,
- mvert[mloop[mlt_b->tri[2]].v].co,
+ positions[mloop[mlt_a->tri[0]].v],
+ positions[mloop[mlt_a->tri[1]].v],
+ positions[mloop[mlt_a->tri[2]].v],
+ positions[mloop[mlt_b->tri[2]].v],
normal_precalc) :
is_quad_flip_v3_first_third_fast(
/* Expensive calculation (no normal). */
- mvert[mloop[mlt_a->tri[0]].v].co,
- mvert[mloop[mlt_a->tri[1]].v].co,
- mvert[mloop[mlt_a->tri[2]].v].co,
- mvert[mloop[mlt_b->tri[2]].v].co))) {
+ positions[mloop[mlt_a->tri[0]].v],
+ positions[mloop[mlt_a->tri[1]].v],
+ positions[mloop[mlt_a->tri[2]].v],
+ positions[mloop[mlt_b->tri[2]].v]))) {
/* Flip out of degenerate 0-2 state. */
mlt_a->tri[2] = mlt_b->tri[2];
mlt_b->tri[0] = mlt_a->tri[1];
@@ -102,9 +102,9 @@ BLI_INLINE void mesh_calc_tessellation_for_face_impl(const MLoop *mloop,
/* Calc normal, flipped: to get a positive 2D cross product. */
ml = mloop + mp_loopstart;
- co_prev = mvert[ml[mp_totloop - 1].v].co;
+ co_prev = positions[ml[mp_totloop - 1].v];
for (uint j = 0; j < mp_totloop; j++, ml++) {
- co_curr = mvert[ml->v].co;
+ co_curr = positions[ml->v];
add_newell_cross_v3_v3v3(normal, co_prev, co_curr);
co_prev = co_curr;
}
@@ -131,7 +131,7 @@ BLI_INLINE void mesh_calc_tessellation_for_face_impl(const MLoop *mloop,
ml = mloop + mp_loopstart;
for (uint j = 0; j < mp_totloop; j++, ml++) {
- mul_v2_m3v3(projverts[j], axis_mat, mvert[ml->v].co);
+ mul_v2_m3v3(projverts[j], axis_mat, positions[ml->v]);
}
BLI_polyfill_calc_arena(projverts, mp_totloop, 1, tris, pf_arena);
@@ -152,30 +152,30 @@ BLI_INLINE void mesh_calc_tessellation_for_face_impl(const MLoop *mloop,
static void mesh_calc_tessellation_for_face(const MLoop *mloop,
const MPoly *mpoly,
- const MVert *mvert,
+ const float (*positions)[3],
uint poly_index,
MLoopTri *mlt,
MemArena **pf_arena_p)
{
mesh_calc_tessellation_for_face_impl(
- mloop, mpoly, mvert, poly_index, mlt, pf_arena_p, false, nullptr);
+ mloop, mpoly, positions, poly_index, mlt, pf_arena_p, false, nullptr);
}
static void mesh_calc_tessellation_for_face_with_normal(const MLoop *mloop,
const MPoly *mpoly,
- const MVert *mvert,
+ const float (*positions)[3],
uint poly_index,
MLoopTri *mlt,
MemArena **pf_arena_p,
const float normal_precalc[3])
{
mesh_calc_tessellation_for_face_impl(
- mloop, mpoly, mvert, poly_index, mlt, pf_arena_p, true, normal_precalc);
+ mloop, mpoly, positions, poly_index, mlt, pf_arena_p, true, normal_precalc);
}
static void mesh_recalc_looptri__single_threaded(const MLoop *mloop,
const MPoly *mpoly,
- const MVert *mvert,
+ const float (*positions)[3],
int totloop,
int totpoly,
MLoopTri *mlooptri,
@@ -189,7 +189,7 @@ static void mesh_recalc_looptri__single_threaded(const MLoop *mloop,
for (uint poly_index = 0; poly_index < uint(totpoly); poly_index++, mp++) {
mesh_calc_tessellation_for_face_with_normal(mloop,
mpoly,
- mvert,
+ positions,
poly_index,
&mlooptri[tri_index],
&pf_arena,
@@ -200,7 +200,7 @@ static void mesh_recalc_looptri__single_threaded(const MLoop *mloop,
else {
for (uint poly_index = 0; poly_index < uint(totpoly); poly_index++, mp++) {
mesh_calc_tessellation_for_face(
- mloop, mpoly, mvert, poly_index, &mlooptri[tri_index], &pf_arena);
+ mloop, mpoly, positions, poly_index, &mlooptri[tri_index], &pf_arena);
tri_index += uint(mp->totloop - 2);
}
}
@@ -216,7 +216,7 @@ static void mesh_recalc_looptri__single_threaded(const MLoop *mloop,
struct TessellationUserData {
const MLoop *mloop;
const MPoly *mpoly;
- const MVert *mvert;
+ const float (*positions)[3];
/** Output array. */
MLoopTri *mlooptri;
@@ -238,7 +238,7 @@ static void mesh_calc_tessellation_for_face_fn(void *__restrict userdata,
const int tri_index = poly_to_tri_count(index, data->mpoly[index].loopstart);
mesh_calc_tessellation_for_face_impl(data->mloop,
data->mpoly,
- data->mvert,
+ data->positions,
uint(index),
&data->mlooptri[tri_index],
&tls_data->pf_arena,
@@ -255,7 +255,7 @@ static void mesh_calc_tessellation_for_face_with_normal_fn(void *__restrict user
const int tri_index = poly_to_tri_count(index, data->mpoly[index].loopstart);
mesh_calc_tessellation_for_face_impl(data->mloop,
data->mpoly,
- data->mvert,
+ data->positions,
uint(index),
&data->mlooptri[tri_index],
&tls_data->pf_arena,
@@ -274,7 +274,7 @@ static void mesh_calc_tessellation_for_face_free_fn(const void *__restrict /*use
static void mesh_recalc_looptri__multi_threaded(const MLoop *mloop,
const MPoly *mpoly,
- const MVert *mvert,
+ const float (*positions)[3],
int /*totloop*/,
int totpoly,
MLoopTri *mlooptri,
@@ -286,7 +286,7 @@ static void mesh_recalc_looptri__multi_threaded(const MLoop *mloop,
};
data.mloop = mloop;
data.mpoly = mpoly;
- data.mvert = mvert;
+ data.positions = positions;
data.mlooptri = mlooptri;
data.poly_normals = poly_normals;
@@ -308,22 +308,24 @@ static void mesh_recalc_looptri__multi_threaded(const MLoop *mloop,
void BKE_mesh_recalc_looptri(const MLoop *mloop,
const MPoly *mpoly,
- const MVert *mvert,
+ const float (*positions)[3],
int totloop,
int totpoly,
MLoopTri *mlooptri)
{
if (totloop < MESH_FACE_TESSELLATE_THREADED_LIMIT) {
- mesh_recalc_looptri__single_threaded(mloop, mpoly, mvert, totloop, totpoly, mlooptri, nullptr);
+ mesh_recalc_looptri__single_threaded(
+ mloop, mpoly, positions, totloop, totpoly, mlooptri, nullptr);
}
else {
- mesh_recalc_looptri__multi_threaded(mloop, mpoly, mvert, totloop, totpoly, mlooptri, nullptr);
+ mesh_recalc_looptri__multi_threaded(
+ mloop, mpoly, positions, totloop, totpoly, mlooptri, nullptr);
}
}
void BKE_mesh_recalc_looptri_with_normals(const MLoop *mloop,
const MPoly *mpoly,
- const MVert *mvert,
+ const float (*positions)[3],
int totloop,
int totpoly,
MLoopTri *mlooptri,
@@ -332,11 +334,11 @@ void BKE_mesh_recalc_looptri_with_normals(const MLoop *mloop,
BLI_assert(poly_normals != nullptr);
if (totloop < MESH_FACE_TESSELLATE_THREADED_LIMIT) {
mesh_recalc_looptri__single_threaded(
- mloop, mpoly, mvert, totloop, totpoly, mlooptri, poly_normals);
+ mloop, mpoly, positions, totloop, totpoly, mlooptri, poly_normals);
}
else {
mesh_recalc_looptri__multi_threaded(
- mloop, mpoly, mvert, totloop, totpoly, mlooptri, poly_normals);
+ mloop, mpoly, positions, totloop, totpoly, mlooptri, poly_normals);
}
}
diff --git a/source/blender/blenkernel/intern/mesh_validate.cc b/source/blender/blenkernel/intern/mesh_validate.cc
index 9cd3b6e9e9e..d77ba8de767 100644
--- a/source/blender/blenkernel/intern/mesh_validate.cc
+++ b/source/blender/blenkernel/intern/mesh_validate.cc
@@ -33,6 +33,7 @@
#include "MEM_guardedalloc.h"
+using blender::float3;
using blender::MutableSpan;
using blender::Span;
@@ -206,7 +207,7 @@ static int search_polyloop_cmp(const void *v1, const void *v2)
/* NOLINTNEXTLINE: readability-function-size */
bool BKE_mesh_validate_arrays(Mesh *mesh,
- MVert *mverts,
+ float (*positions)[3],
uint totvert,
MEdge *medges,
uint totedge,
@@ -246,7 +247,6 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
mesh->attributes_for_write().lookup_for_write<int>("material_index");
blender::MutableVArraySpan<int> material_indices_span(material_indices.varray);
- MVert *mv = mverts;
MEdge *me;
MLoop *ml;
MPoly *mp;
@@ -303,15 +303,15 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
vert_normals = BKE_mesh_vertex_normals_ensure(mesh);
}
- for (i = 0; i < totvert; i++, mv++) {
+ for (i = 0; i < totvert; i++) {
bool fix_normal = true;
for (j = 0; j < 3; j++) {
- if (!isfinite(mv->co[j])) {
+ if (!isfinite(positions[i][j])) {
PRINT_ERR("\tVertex %u: has invalid coordinate", i);
if (do_fixes) {
- zero_v3(mv->co);
+ zero_v3(positions[i]);
fix_flag.verts = true;
}
@@ -333,7 +333,7 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
* although it's also possible degenerate/opposite faces accumulate to a zero vector.
* To detect this a full normal recalculation would be needed, which is out of scope
* for a basic validity check (see "Vertex Normal" in the doc-string). */
- if (!is_zero_v3(mv->co)) {
+ if (!is_zero_v3(positions[i])) {
PRINT_ERR("\tVertex %u: has zero normal, assuming Z-up normal", i);
if (do_fixes) {
float *normal = (float *)vert_normals[i];
@@ -1067,14 +1067,14 @@ bool BKE_mesh_validate(Mesh *me, const bool do_verbose, const bool cddata_check_
do_verbose,
true,
&changed);
- MutableSpan<MVert> verts = me->verts_for_write();
+ MutableSpan<float3> positions = me->positions_for_write();
MutableSpan<MEdge> edges = me->edges_for_write();
MutableSpan<MPoly> polys = me->polys_for_write();
MutableSpan<MLoop> loops = me->loops_for_write();
BKE_mesh_validate_arrays(me,
- verts.data(),
- verts.size(),
+ reinterpret_cast<float(*)[3]>(positions.data()),
+ positions.size(),
edges.data(),
edges.size(),
(MFace *)CustomData_get_layer(&me->fdata, CD_MFACE),
@@ -1120,14 +1120,14 @@ bool BKE_mesh_is_valid(Mesh *me)
do_fixes,
&changed);
- MutableSpan<MVert> verts = me->verts_for_write();
+ MutableSpan<float3> positions = me->positions_for_write();
MutableSpan<MEdge> edges = me->edges_for_write();
MutableSpan<MPoly> polys = me->polys_for_write();
MutableSpan<MLoop> loops = me->loops_for_write();
is_valid &= BKE_mesh_validate_arrays(me,
- verts.data(),
- verts.size(),
+ reinterpret_cast<float(*)[3]>(positions.data()),
+ positions.size(),
edges.data(),
edges.size(),
(MFace *)CustomData_get_layer(&me->fdata, CD_MFACE),
diff --git a/source/blender/blenkernel/intern/mesh_wrapper.cc b/source/blender/blenkernel/intern/mesh_wrapper.cc
index 61a95fb4d0e..620bafa4b46 100644
--- a/source/blender/blenkernel/intern/mesh_wrapper.cc
+++ b/source/blender/blenkernel/intern/mesh_wrapper.cc
@@ -7,7 +7,7 @@
* output of a modified mesh.
*
* This API handles the case when the modifier stack outputs a mesh which does not have
- * #Mesh data (#MPoly, #MLoop, #MEdge, #MVert).
+ * #Mesh data (#MPoly, #MLoop, #MEdge, etc).
* Currently this is used so the resulting mesh can have #BMEditMesh data,
* postponing the converting until it's needed or avoiding conversion entirely
* which can be an expensive operation.
@@ -46,6 +46,7 @@
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"
+using blender::float3;
using blender::Span;
Mesh *BKE_mesh_wrapper_from_editmesh_with_coords(BMEditMesh *em,
@@ -192,9 +193,9 @@ void BKE_mesh_wrapper_vert_coords_copy(const Mesh *me,
case ME_WRAPPER_TYPE_MDATA:
case ME_WRAPPER_TYPE_SUBD: {
BLI_assert(vert_coords_len <= me->totvert);
- const Span<MVert> verts = me->verts();
+ const Span<float3> positions = me->positions();
for (int i = 0; i < vert_coords_len; i++) {
- copy_v3_v3(vert_coords[i], verts[i].co);
+ copy_v3_v3(vert_coords[i], positions[i]);
}
return;
}
@@ -230,9 +231,9 @@ void BKE_mesh_wrapper_vert_coords_copy_with_mat4(const Mesh *me,
case ME_WRAPPER_TYPE_MDATA:
case ME_WRAPPER_TYPE_SUBD: {
BLI_assert(vert_coords_len == me->totvert);
- const Span<MVert> verts = me->verts();
+ const Span<float3> positions = me->positions();
for (int i = 0; i < vert_coords_len; i++) {
- mul_v3_m4v3(vert_coords[i], mat, verts[i].co);
+ mul_v3_m4v3(vert_coords[i], mat, positions[i]);
}
return;
}
diff --git a/source/blender/blenkernel/intern/modifier.cc b/source/blender/blenkernel/intern/modifier.cc
index 92a7c778b68..50c9c13a9ac 100644
--- a/source/blender/blenkernel/intern/modifier.cc
+++ b/source/blender/blenkernel/intern/modifier.cc
@@ -1189,8 +1189,8 @@ void BKE_modifier_blend_write(BlendWriter *writer, const ID *id_owner, ListBase
CollisionModifierData *collmd = (CollisionModifierData *)md;
/* TODO: CollisionModifier should use pointcache
* + have proper reset events before enabling this. */
- writestruct(wd, DATA, MVert, collmd->numverts, collmd->x);
- writestruct(wd, DATA, MVert, collmd->numverts, collmd->xnew);
+ writestruct(wd, DATA, float[3], collmd->numverts, collmd->x);
+ writestruct(wd, DATA, float[3], collmd->numverts, collmd->xnew);
writestruct(wd, DATA, MFace, collmd->numfaces, collmd->mfaces);
#endif
}
diff --git a/source/blender/blenkernel/intern/multires.cc b/source/blender/blenkernel/intern/multires.cc
index 5ff9602650e..e20cdfd54ff 100644
--- a/source/blender/blenkernel/intern/multires.cc
+++ b/source/blender/blenkernel/intern/multires.cc
@@ -1522,8 +1522,7 @@ void multiresModifier_ensure_external_read(struct Mesh *mesh, const MultiresModi
/***************** Multires interpolation stuff *****************/
-int mdisp_rot_face_to_crn(struct MVert * /*mvert*/,
- struct MPoly *mpoly,
+int mdisp_rot_face_to_crn(struct MPoly *mpoly,
struct MLoop * /*mloop*/,
const struct MLoopTri * /*lt*/,
const int face_side,
@@ -1603,7 +1602,7 @@ int mdisp_rot_face_to_crn(struct MVert * /*mvert*/,
float mindist = FLT_MAX;
for (i = 0; i < mpoly->totloop; i++) {
- float len = len_v3v3(nullptr, mvert[mloop[mpoly->loopstart + i].v].co);
+ float len = len_v3v3(nullptr, positions[mloop[mpoly->loopstart + i].v].co);
if (len < mindist) {
mindist = len;
minS = i;
diff --git a/source/blender/blenkernel/intern/multires_reshape.h b/source/blender/blenkernel/intern/multires_reshape.h
index f27618b2145..1aa20cb7f48 100644
--- a/source/blender/blenkernel/intern/multires_reshape.h
+++ b/source/blender/blenkernel/intern/multires_reshape.h
@@ -19,7 +19,6 @@ struct Mesh;
struct MLoop;
struct MPoly;
struct MultiresModifierData;
-struct MVert;
struct Object;
struct Subdiv;
struct SubdivCCG;
@@ -34,7 +33,7 @@ typedef struct MultiresReshapeContext {
/* Base mesh from original object.
* NOTE: Does NOT include any leading modifiers in it. */
struct Mesh *base_mesh;
- const struct MVert *base_verts;
+ const float (*base_positions)[3];
const struct MEdge *base_edges;
const struct MPoly *base_polys;
const struct MLoop *base_loops;
diff --git a/source/blender/blenkernel/intern/multires_reshape_apply_base.c b/source/blender/blenkernel/intern/multires_reshape_apply_base.c
index 81b0abbdcf5..8eed2484cca 100644
--- a/source/blender/blenkernel/intern/multires_reshape_apply_base.c
+++ b/source/blender/blenkernel/intern/multires_reshape_apply_base.c
@@ -30,14 +30,13 @@
void multires_reshape_apply_base_update_mesh_coords(MultiresReshapeContext *reshape_context)
{
Mesh *base_mesh = reshape_context->base_mesh;
- MVert *base_verts = BKE_mesh_verts_for_write(base_mesh);
+ float(*base_positions)[3] = BKE_mesh_positions_for_write(base_mesh);
/* Update the context in case the vertices were duplicated. */
- reshape_context->base_verts = base_verts;
+ reshape_context->base_positions = base_positions;
const MLoop *mloop = reshape_context->base_loops;
for (int loop_index = 0; loop_index < base_mesh->totloop; ++loop_index) {
const MLoop *loop = &mloop[loop_index];
- MVert *vert = &base_verts[loop->v];
GridCoord grid_coord;
grid_coord.grid_index = loop_index;
@@ -53,7 +52,7 @@ void multires_reshape_apply_base_update_mesh_coords(MultiresReshapeContext *resh
float D[3];
mul_v3_m3v3(D, tangent_matrix, grid_element.displacement);
- add_v3_v3v3(vert->co, P, D);
+ add_v3_v3v3(base_positions[loop->v], P, D);
}
}
@@ -69,9 +68,9 @@ static float v3_dist_from_plane(const float v[3], const float center[3], const f
void multires_reshape_apply_base_refit_base_mesh(MultiresReshapeContext *reshape_context)
{
Mesh *base_mesh = reshape_context->base_mesh;
- MVert *base_verts = BKE_mesh_verts_for_write(base_mesh);
+ float(*base_positions)[3] = BKE_mesh_positions_for_write(base_mesh);
/* Update the context in case the vertices were duplicated. */
- reshape_context->base_verts = base_verts;
+ reshape_context->base_positions = base_positions;
MeshElemMap *pmap;
int *pmap_mem;
BKE_mesh_vert_poly_map_create(&pmap,
@@ -85,7 +84,7 @@ void multires_reshape_apply_base_refit_base_mesh(MultiresReshapeContext *reshape
float(*origco)[3] = MEM_calloc_arrayN(
base_mesh->totvert, sizeof(float[3]), "multires apply base origco");
for (int i = 0; i < base_mesh->totvert; i++) {
- copy_v3_v3(origco[i], base_verts[i].co);
+ copy_v3_v3(origco[i], base_positions[i]);
}
for (int i = 0; i < base_mesh->totvert; i++) {
@@ -148,10 +147,10 @@ void multires_reshape_apply_base_refit_base_mesh(MultiresReshapeContext *reshape
normalize_v3(avg_no);
/* Push vertex away from the plane. */
- const float dist = v3_dist_from_plane(base_verts[i].co, center, avg_no);
+ const float dist = v3_dist_from_plane(base_positions[i], center, avg_no);
copy_v3_v3(push, avg_no);
mul_v3_fl(push, dist);
- add_v3_v3(base_verts[i].co, push);
+ add_v3_v3(base_positions[i], push);
}
MEM_freeN(origco);
diff --git a/source/blender/blenkernel/intern/multires_reshape_subdivide.c b/source/blender/blenkernel/intern/multires_reshape_subdivide.c
index effea2467bc..19e9b15c435 100644
--- a/source/blender/blenkernel/intern/multires_reshape_subdivide.c
+++ b/source/blender/blenkernel/intern/multires_reshape_subdivide.c
@@ -28,7 +28,7 @@
static void multires_subdivide_create_object_space_linear_grids(Mesh *mesh)
{
- const MVert *verts = BKE_mesh_verts(mesh);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
const MPoly *polys = BKE_mesh_polys(mesh);
const MLoop *loops = BKE_mesh_loops(mesh);
@@ -37,7 +37,7 @@ static void multires_subdivide_create_object_space_linear_grids(Mesh *mesh)
for (int p = 0; p < totpoly; p++) {
const MPoly *poly = &polys[p];
float poly_center[3];
- BKE_mesh_calc_poly_center(poly, &loops[poly->loopstart], verts, poly_center);
+ BKE_mesh_calc_poly_center(poly, &loops[poly->loopstart], positions, poly_center);
for (int l = 0; l < poly->totloop; l++) {
const int loop_index = poly->loopstart + l;
@@ -53,9 +53,9 @@ static void multires_subdivide_create_object_space_linear_grids(Mesh *mesh)
const MLoop *loop_prev = &loops[prev_loop_index];
copy_v3_v3(disps[0], poly_center);
- mid_v3_v3v3(disps[1], verts[loop->v].co, verts[loop_next->v].co);
- mid_v3_v3v3(disps[2], verts[loop->v].co, verts[loop_prev->v].co);
- copy_v3_v3(disps[3], verts[loop->v].co);
+ mid_v3_v3v3(disps[1], positions[loop->v], positions[loop_next->v]);
+ mid_v3_v3v3(disps[2], positions[loop->v], positions[loop_prev->v]);
+ copy_v3_v3(disps[3], positions[loop->v]);
}
}
}
diff --git a/source/blender/blenkernel/intern/multires_reshape_util.c b/source/blender/blenkernel/intern/multires_reshape_util.c
index 4fc1217158c..40e767f2211 100644
--- a/source/blender/blenkernel/intern/multires_reshape_util.c
+++ b/source/blender/blenkernel/intern/multires_reshape_util.c
@@ -152,7 +152,7 @@ bool multires_reshape_context_create_from_base_mesh(MultiresReshapeContext *resh
reshape_context->mmd = mmd;
reshape_context->base_mesh = base_mesh;
- reshape_context->base_verts = BKE_mesh_verts(base_mesh);
+ reshape_context->base_positions = BKE_mesh_positions(base_mesh);
reshape_context->base_edges = BKE_mesh_edges(base_mesh);
reshape_context->base_polys = BKE_mesh_polys(base_mesh);
reshape_context->base_loops = BKE_mesh_loops(base_mesh);
@@ -189,7 +189,7 @@ bool multires_reshape_context_create_from_object(MultiresReshapeContext *reshape
reshape_context->mmd = mmd;
reshape_context->base_mesh = base_mesh;
- reshape_context->base_verts = BKE_mesh_verts(base_mesh);
+ reshape_context->base_positions = BKE_mesh_positions(base_mesh);
reshape_context->base_edges = BKE_mesh_edges(base_mesh);
reshape_context->base_polys = BKE_mesh_polys(base_mesh);
reshape_context->base_loops = BKE_mesh_loops(base_mesh);
@@ -221,7 +221,7 @@ bool multires_reshape_context_create_from_ccg(MultiresReshapeContext *reshape_co
context_zero(reshape_context);
reshape_context->base_mesh = base_mesh;
- reshape_context->base_verts = BKE_mesh_verts(base_mesh);
+ reshape_context->base_positions = BKE_mesh_positions(base_mesh);
reshape_context->base_edges = BKE_mesh_edges(base_mesh);
reshape_context->base_polys = BKE_mesh_polys(base_mesh);
reshape_context->base_loops = BKE_mesh_loops(base_mesh);
@@ -268,7 +268,7 @@ bool multires_reshape_context_create_from_subdiv(MultiresReshapeContext *reshape
reshape_context->mmd = mmd;
reshape_context->base_mesh = base_mesh;
- reshape_context->base_verts = BKE_mesh_verts(base_mesh);
+ reshape_context->base_positions = BKE_mesh_positions(base_mesh);
reshape_context->base_edges = BKE_mesh_edges(base_mesh);
reshape_context->base_polys = BKE_mesh_polys(base_mesh);
reshape_context->base_loops = BKE_mesh_loops(base_mesh);
diff --git a/source/blender/blenkernel/intern/object.cc b/source/blender/blenkernel/intern/object.cc
index 9085a54d86f..a3feb862e17 100644
--- a/source/blender/blenkernel/intern/object.cc
+++ b/source/blender/blenkernel/intern/object.cc
@@ -3237,7 +3237,7 @@ static void give_parvert(Object *par, int nr, float vec[3])
BKE_object_get_evaluated_mesh(par);
if (me_eval) {
- const MVert *verts = BKE_mesh_verts(me_eval);
+ const Span<float3> positions = me_eval->positions();
int count = 0;
int numVerts = me_eval->totvert;
@@ -3271,14 +3271,14 @@ static void give_parvert(Object *par, int nr, float vec[3])
/* Get the average of all verts with (original index == nr). */
for (int i = 0; i < numVerts; i++) {
if (index[i] == nr) {
- add_v3_v3(vec, verts[i].co);
+ add_v3_v3(vec, positions[i]);
count++;
}
}
}
else {
if (nr < numVerts) {
- add_v3_v3(vec, verts[nr].co);
+ add_v3_v3(vec, positions[nr]);
count++;
}
}
@@ -3292,7 +3292,7 @@ static void give_parvert(Object *par, int nr, float vec[3])
else {
/* use first index if its out of range */
if (me_eval->totvert) {
- copy_v3_v3(vec, verts[0].co);
+ copy_v3_v3(vec, positions[0]);
}
}
}
@@ -4177,10 +4177,9 @@ void BKE_object_foreach_display_point(Object *ob,
float3 co;
if (mesh_eval != nullptr) {
- const MVert *verts = BKE_mesh_verts(mesh_eval);
- const int totvert = mesh_eval->totvert;
- for (int i = 0; i < totvert; i++) {
- mul_v3_m4v3(co, obmat, verts[i].co);
+ const Span<float3> positions = mesh_eval->positions();
+ for (const int i : positions.index_range()) {
+ mul_v3_m4v3(co, obmat, positions[i]);
func_cb(co, user_data);
}
}
@@ -4805,8 +4804,9 @@ bool BKE_object_shapekey_remove(Main *bmain, Object *ob, KeyBlock *kb)
switch (ob->type) {
case OB_MESH: {
Mesh *mesh = (Mesh *)ob->data;
- MutableSpan<MVert> verts = mesh->verts_for_write();
- BKE_keyblock_convert_to_mesh(key->refkey, verts.data(), mesh->totvert);
+ MutableSpan<float3> verts = mesh->positions_for_write();
+ BKE_keyblock_convert_to_mesh(
+ key->refkey, reinterpret_cast<float(*)[3]>(verts.data()), mesh->totvert);
break;
}
case OB_CURVES_LEGACY:
@@ -5304,31 +5304,31 @@ KDTree_3d *BKE_object_as_kdtree(Object *ob, int *r_tot)
const int *index;
if (me_eval && (index = (const int *)CustomData_get_layer(&me_eval->vdata, CD_ORIGINDEX))) {
- const Span<MVert> verts = me->verts();
+ const Span<float3> positions = me->positions();
/* Tree over-allocates in case where some verts have #ORIGINDEX_NONE. */
tot = 0;
- tree = BLI_kdtree_3d_new(verts.size());
+ tree = BLI_kdtree_3d_new(positions.size());
/* We don't how many verts from the DM we can use. */
- for (i = 0; i < verts.size(); i++) {
+ for (i = 0; i < positions.size(); i++) {
if (index[i] != ORIGINDEX_NONE) {
float co[3];
- mul_v3_m4v3(co, ob->object_to_world, verts[i].co);
+ mul_v3_m4v3(co, ob->object_to_world, positions[i]);
BLI_kdtree_3d_insert(tree, index[i], co);
tot++;
}
}
}
else {
- const Span<MVert> verts = me->verts();
+ const Span<float3> positions = me->positions();
- tot = verts.size();
+ tot = positions.size();
tree = BLI_kdtree_3d_new(tot);
for (i = 0; i < tot; i++) {
float co[3];
- mul_v3_m4v3(co, ob->object_to_world, verts[i].co);
+ mul_v3_m4v3(co, ob->object_to_world, positions[i]);
BLI_kdtree_3d_insert(tree, i, co);
}
}
diff --git a/source/blender/blenkernel/intern/object_dupli.cc b/source/blender/blenkernel/intern/object_dupli.cc
index 5efd44c620b..e69849cdbff 100644
--- a/source/blender/blenkernel/intern/object_dupli.cc
+++ b/source/blender/blenkernel/intern/object_dupli.cc
@@ -515,7 +515,7 @@ struct VertexDupliData_Mesh {
VertexDupliData_Params params;
int totvert;
- const MVert *mvert;
+ Span<float3> positions;
const float (*vert_normals)[3];
const float (*orco)[3];
@@ -606,7 +606,6 @@ static void make_child_duplis_verts_from_mesh(const DupliContext *ctx,
VertexDupliData_Mesh *vdd = (VertexDupliData_Mesh *)userdata;
const bool use_rotation = vdd->params.use_rotation;
- const MVert *mvert = vdd->mvert;
const int totvert = vdd->totvert;
invert_m4_m4(inst_ob->world_to_object, inst_ob->object_to_world);
@@ -615,8 +614,13 @@ static void make_child_duplis_verts_from_mesh(const DupliContext *ctx,
mul_m4_m4m4(child_imat, inst_ob->world_to_object, ctx->object->object_to_world);
for (int i = 0; i < totvert; i++) {
- DupliObject *dob = vertex_dupli(
- vdd->params.ctx, inst_ob, child_imat, i, mvert[i].co, vdd->vert_normals[i], use_rotation);
+ DupliObject *dob = vertex_dupli(vdd->params.ctx,
+ inst_ob,
+ child_imat,
+ i,
+ vdd->positions[i],
+ vdd->vert_normals[i],
+ use_rotation);
if (vdd->orco) {
copy_v3_v3(dob->orco, vdd->orco[i]);
}
@@ -692,7 +696,7 @@ static void make_duplis_verts(const DupliContext *ctx)
VertexDupliData_Mesh vdd{};
vdd.params = vdd_params;
vdd.totvert = me_eval->totvert;
- vdd.mvert = me_eval->verts().data();
+ vdd.positions = me_eval->positions();
vdd.vert_normals = BKE_mesh_vertex_normals_ensure(me_eval);
vdd.orco = (const float(*)[3])CustomData_get_layer(&me_eval->vdata, CD_ORCO);
@@ -1018,7 +1022,7 @@ struct FaceDupliData_Mesh {
int totface;
const MPoly *mpoly;
const MLoop *mloop;
- const MVert *mvert;
+ Span<float3> positions;
const float (*orco)[3];
const MLoopUV *mloopuv;
};
@@ -1117,14 +1121,14 @@ static DupliObject *face_dupli_from_mesh(const DupliContext *ctx,
/* Mesh variables. */
const MPoly *mpoly,
const MLoop *mloopstart,
- const MVert *mvert)
+ const Span<float3> positions)
{
const int coords_len = mpoly->totloop;
Array<float3, 64> coords(coords_len);
const MLoop *ml = mloopstart;
for (int i = 0; i < coords_len; i++, ml++) {
- coords[i] = float3(mvert[ml->v].co);
+ coords[i] = positions[ml->v];
}
return face_dupli(ctx, inst_ob, child_imat, index, use_scale, scale_fac, coords);
@@ -1168,7 +1172,6 @@ static void make_child_duplis_faces_from_mesh(const DupliContext *ctx,
FaceDupliData_Mesh *fdd = (FaceDupliData_Mesh *)userdata;
const MPoly *mpoly = fdd->mpoly, *mp;
const MLoop *mloop = fdd->mloop;
- const MVert *mvert = fdd->mvert;
const float(*orco)[3] = fdd->orco;
const MLoopUV *mloopuv = fdd->mloopuv;
const int totface = fdd->totface;
@@ -1184,8 +1187,15 @@ static void make_child_duplis_faces_from_mesh(const DupliContext *ctx,
for (a = 0, mp = mpoly; a < totface; a++, mp++) {
const MLoop *loopstart = mloop + mp->loopstart;
- DupliObject *dob = face_dupli_from_mesh(
- fdd->params.ctx, inst_ob, child_imat, a, use_scale, scale_fac, mp, loopstart, mvert);
+ DupliObject *dob = face_dupli_from_mesh(fdd->params.ctx,
+ inst_ob,
+ child_imat,
+ a,
+ use_scale,
+ scale_fac,
+ mp,
+ loopstart,
+ fdd->positions);
const float w = 1.0f / float(mp->totloop);
if (orco) {
@@ -1274,7 +1284,7 @@ static void make_duplis_faces(const DupliContext *ctx)
fdd.totface = me_eval->totpoly;
fdd.mpoly = me_eval->polys().data();
fdd.mloop = me_eval->loops().data();
- fdd.mvert = me_eval->verts().data();
+ fdd.positions = me_eval->positions();
fdd.mloopuv = (uv_idx != -1) ? (const MLoopUV *)CustomData_get_layer_n(
&me_eval->ldata, CD_MLOOPUV, uv_idx) :
nullptr;
diff --git a/source/blender/blenkernel/intern/paint.cc b/source/blender/blenkernel/intern/paint.cc
index a39e53662aa..25be7b3754e 100644
--- a/source/blender/blenkernel/intern/paint.cc
+++ b/source/blender/blenkernel/intern/paint.cc
@@ -67,6 +67,10 @@
#include "bmesh.h"
+using blender::float3;
+using blender::MutableSpan;
+using blender::Span;
+
static void sculpt_attribute_update_refs(Object *ob);
static SculptAttribute *sculpt_attribute_ensure_ex(Object *ob,
eAttrDomain domain,
@@ -77,9 +81,6 @@ static SculptAttribute *sculpt_attribute_ensure_ex(Object *ob,
bool flat_array_for_bmesh);
void sculptsession_bmesh_add_layers(Object *ob);
-using blender::MutableSpan;
-using blender::Span;
-
static void palette_init_data(ID *id)
{
Palette *palette = (Palette *)id;
@@ -1696,7 +1697,7 @@ static void sculpt_update_object(
/* These are assigned to the base mesh in Multires. This is needed because Face Sets operators
* and tools use the Face Sets data from the base mesh when Multires is active. */
- ss->mvert = BKE_mesh_verts_for_write(me);
+ ss->positions = BKE_mesh_positions_for_write(me);
ss->mpoly = BKE_mesh_polys(me);
ss->mloop = BKE_mesh_loops(me);
}
@@ -1704,7 +1705,7 @@ static void sculpt_update_object(
ss->totvert = me->totvert;
ss->totpoly = me->totpoly;
ss->totfaces = me->totpoly;
- ss->mvert = BKE_mesh_verts_for_write(me);
+ ss->positions = BKE_mesh_positions_for_write(me);
ss->mpoly = BKE_mesh_polys(me);
ss->mloop = BKE_mesh_loops(me);
ss->multires.active = false;
@@ -2193,21 +2194,25 @@ static PBVH *build_pbvh_from_regular_mesh(Object *ob, Mesh *me_eval_deform, bool
PBVH *pbvh = BKE_pbvh_new(PBVH_FACES);
BKE_pbvh_respect_hide_set(pbvh, respect_hide);
- MutableSpan<MVert> verts = me->verts_for_write();
+ MutableSpan<float3> positions = me->positions_for_write();
const Span<MPoly> polys = me->polys();
const Span<MLoop> loops = me->loops();
MLoopTri *looptri = static_cast<MLoopTri *>(
MEM_malloc_arrayN(looptris_num, sizeof(*looptri), __func__));
- BKE_mesh_recalc_looptri(
- loops.data(), polys.data(), verts.data(), me->totloop, me->totpoly, looptri);
+ BKE_mesh_recalc_looptri(loops.data(),
+ polys.data(),
+ reinterpret_cast<const float(*)[3]>(positions.data()),
+ me->totloop,
+ me->totpoly,
+ looptri);
BKE_pbvh_build_mesh(pbvh,
me,
polys.data(),
loops.data(),
- verts.data(),
+ reinterpret_cast<float(*)[3]>(positions.data()),
me->totvert,
&me->vdata,
&me->ldata,
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index 6a277295efd..abda1ea8176 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -1266,7 +1266,7 @@ typedef struct ParticleInterpolationData {
HairKey *hkey[2];
Mesh *mesh;
- MVert *mvert[2];
+ float *positions[2];
int keyed;
ParticleKey *kkey[2];
@@ -1426,9 +1426,9 @@ static void init_particle_interpolation(Object *ob,
pind->dietime = (key + pa->totkey - 1)->time;
if (pind->mesh) {
- MVert *verts = BKE_mesh_verts_for_write(pind->mesh);
- pind->mvert[0] = &verts[pa->hair_index];
- pind->mvert[1] = pind->mvert[0] + 1;
+ float(*positions)[3] = BKE_mesh_positions_for_write(pind->mesh);
+ pind->positions[0] = positions[pa->hair_index];
+ pind->positions[1] = positions[pa->hair_index + 1];
}
}
}
@@ -1446,9 +1446,9 @@ static void hair_to_particle(ParticleKey *key, HairKey *hkey)
key->time = hkey->time;
}
-static void mvert_to_particle(ParticleKey *key, MVert *mvert, HairKey *hkey)
+static void mvert_to_particle(ParticleKey *key, float position[3], HairKey *hkey)
{
- copy_v3_v3(key->co, mvert->co);
+ copy_v3_v3(key->co, position);
key->time = hkey->time;
}
@@ -1546,7 +1546,7 @@ static void do_particle_interpolation(ParticleSystem *psys,
while (pind->hkey[1]->time < real_t) {
pind->hkey[1]++;
- pind->mvert[1]++;
+ pind->positions[1] += 3;
}
pind->hkey[0] = pind->hkey[1] - 1;
@@ -1558,9 +1558,9 @@ static void do_particle_interpolation(ParticleSystem *psys,
edit_to_particle(keys + 2, pind->ekey[1]);
}
else if (pind->mesh) {
- pind->mvert[0] = pind->mvert[1] - 1;
- mvert_to_particle(keys + 1, pind->mvert[0], pind->hkey[0]);
- mvert_to_particle(keys + 2, pind->mvert[1], pind->hkey[1]);
+ pind->positions[0] = pind->positions[1] - 3;
+ mvert_to_particle(keys + 1, pind->positions[0], pind->hkey[0]);
+ mvert_to_particle(keys + 2, pind->positions[1], pind->hkey[1]);
}
else if (pind->keyed) {
memcpy(keys + 1, pind->kkey[0], sizeof(ParticleKey));
@@ -1586,10 +1586,10 @@ static void do_particle_interpolation(ParticleSystem *psys,
}
else if (pind->mesh) {
if (pind->hkey[0] != pa->hair) {
- mvert_to_particle(keys, pind->mvert[0] - 1, pind->hkey[0] - 1);
+ mvert_to_particle(keys, pind->positions[0] - 3, pind->hkey[0] - 3);
}
else {
- mvert_to_particle(keys, pind->mvert[0], pind->hkey[0]);
+ mvert_to_particle(keys, pind->positions[0], pind->hkey[0]);
}
}
else {
@@ -1611,10 +1611,10 @@ static void do_particle_interpolation(ParticleSystem *psys,
}
else if (pind->mesh) {
if (pind->hkey[1] != pa->hair + pa->totkey - 1) {
- mvert_to_particle(keys + 3, pind->mvert[1] + 1, pind->hkey[1] + 1);
+ mvert_to_particle(keys + 3, pind->positions[1] + 3, pind->hkey[1] + 3);
}
else {
- mvert_to_particle(keys + 3, pind->mvert[1], pind->hkey[1]);
+ mvert_to_particle(keys + 3, pind->positions[1], pind->hkey[1]);
}
}
else {
@@ -1692,7 +1692,7 @@ static void interpolate_pathcache(ParticleCacheKey *first, float t, ParticleCach
/************************************************/
void psys_interpolate_face(Mesh *mesh,
- const MVert *mvert,
+ const float (*positions)[3],
const float (*vert_normals)[3],
MFace *mface,
MTFace *tface,
@@ -1711,16 +1711,16 @@ void psys_interpolate_face(Mesh *mesh,
float tuv[4][2];
const float *o1, *o2, *o3, *o4;
- v1 = mvert[mface->v1].co;
- v2 = mvert[mface->v2].co;
- v3 = mvert[mface->v3].co;
+ v1 = positions[mface->v1];
+ v2 = positions[mface->v2];
+ v3 = positions[mface->v3];
copy_v3_v3(n1, vert_normals[mface->v1]);
copy_v3_v3(n2, vert_normals[mface->v2]);
copy_v3_v3(n3, vert_normals[mface->v3]);
if (mface->v4) {
- v4 = mvert[mface->v4].co;
+ v4 = positions[mface->v4];
copy_v3_v3(n4, vert_normals[mface->v4]);
interp_v3_v3v3v3v3(vec, v1, v2, v3, v4, w);
@@ -2147,8 +2147,8 @@ void psys_particle_on_dm(Mesh *mesh_final,
const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(mesh_final);
if (from == PART_FROM_VERT) {
- const MVert *verts = BKE_mesh_verts(mesh_final);
- copy_v3_v3(vec, verts[mapindex].co);
+ const float(*positions)[3] = BKE_mesh_positions(mesh_final);
+ copy_v3_v3(vec, positions[mapindex]);
if (nor) {
copy_v3_v3(nor, vert_normals[mapindex]);
@@ -2172,11 +2172,10 @@ void psys_particle_on_dm(Mesh *mesh_final,
else { /* PART_FROM_FACE / PART_FROM_VOLUME */
MFace *mface;
MTFace *mtface;
- MVert *mvert;
MFace *mfaces = CustomData_get_layer(&mesh_final->fdata, CD_MFACE);
mface = &mfaces[mapindex];
- mvert = BKE_mesh_verts_for_write(mesh_final);
+ const float(*positions)[3] = BKE_mesh_positions(mesh_final);
mtface = CustomData_get_layer(&mesh_final->fdata, CD_MTFACE);
if (mtface) {
@@ -2185,7 +2184,7 @@ void psys_particle_on_dm(Mesh *mesh_final,
if (from == PART_FROM_VOLUME) {
psys_interpolate_face(mesh_final,
- mvert,
+ positions,
vert_normals,
mface,
mtface,
@@ -2208,7 +2207,7 @@ void psys_particle_on_dm(Mesh *mesh_final,
}
else {
psys_interpolate_face(mesh_final,
- mvert,
+ positions,
vert_normals,
mface,
mtface,
@@ -3654,7 +3653,7 @@ static void psys_cache_edit_paths_iter(void *__restrict iter_data_v,
BKE_defvert_weight_to_rgb(ca->col, pind.hkey[1]->weight);
}
else {
- /* WARNING: copied from 'do_particle_interpolation' (without 'mvert' array stepping) */
+ /* WARNING: copied from 'do_particle_interpolation' (without 'vertex' array stepping) */
float real_t;
if (result.time < 0.0f) {
real_t = -result.time;
@@ -3892,10 +3891,10 @@ static void psys_face_mat(Object *ob, Mesh *mesh, ParticleData *pa, float mat[4]
}
}
else {
- const MVert *verts = BKE_mesh_verts(mesh);
- copy_v3_v3(v[0], verts[mface->v1].co);
- copy_v3_v3(v[1], verts[mface->v2].co);
- copy_v3_v3(v[2], verts[mface->v3].co);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
+ copy_v3_v3(v[0], positions[mface->v1]);
+ copy_v3_v3(v[1], positions[mface->v2]);
+ copy_v3_v3(v[2], positions[mface->v3]);
}
triatomat(v[0], v[1], v[2], (osface) ? osface->uv : NULL, mat);
diff --git a/source/blender/blenkernel/intern/particle_distribute.c b/source/blender/blenkernel/intern/particle_distribute.c
index 0301b83a043..4e759157da0 100644
--- a/source/blender/blenkernel/intern/particle_distribute.c
+++ b/source/blender/blenkernel/intern/particle_distribute.c
@@ -98,18 +98,15 @@ static void distribute_grid(Mesh *mesh, ParticleSystem *psys)
{
ParticleData *pa = NULL;
float min[3], max[3], delta[3], d;
- MVert *mv, *mvert = BKE_mesh_verts_for_write(mesh);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
int totvert = mesh->totvert, from = psys->part->from;
int i, j, k, p, res = psys->part->grid_res, size[3], axis;
/* find bounding box of dm */
if (totvert > 0) {
- mv = mvert;
- copy_v3_v3(min, mv->co);
- copy_v3_v3(max, mv->co);
- mv++;
- for (i = 1; i < totvert; i++, mv++) {
- minmax_v3v3_v3(min, max, mv->co);
+ INIT_MINMAX(min, max);
+ for (i = 1; i < totvert; i++) {
+ minmax_v3v3_v3(min, max, positions[i]);
}
}
else {
@@ -163,8 +160,8 @@ static void distribute_grid(Mesh *mesh, ParticleSystem *psys)
min[1] -= d / 2.0f;
min[2] -= d / 2.0f;
- for (i = 0, mv = mvert; i < totvert; i++, mv++) {
- sub_v3_v3v3(vec, mv->co, min);
+ for (i = 0; i < totvert; i++) {
+ sub_v3_v3v3(vec, positions[i], min);
vec[0] /= delta[0];
vec[1] /= delta[1];
vec[2] /= delta[2];
@@ -221,9 +218,9 @@ static void distribute_grid(Mesh *mesh, ParticleSystem *psys)
for (i = 0; i < totface; i++, mface++) {
ParticleData *pa1 = NULL, *pa2 = NULL;
- copy_v3_v3(v1, mvert[mface->v1].co);
- copy_v3_v3(v2, mvert[mface->v2].co);
- copy_v3_v3(v3, mvert[mface->v3].co);
+ copy_v3_v3(v1, positions[mface->v1]);
+ copy_v3_v3(v2, positions[mface->v2]);
+ copy_v3_v3(v3, positions[mface->v3]);
bool intersects_tri = isect_ray_tri_watertight_v3(
co1, &isect_precalc, v1, v2, v3, &lambda, NULL);
@@ -232,7 +229,7 @@ static void distribute_grid(Mesh *mesh, ParticleSystem *psys)
}
if (mface->v4 && (!intersects_tri || from == PART_FROM_VOLUME)) {
- copy_v3_v3(v4, mvert[mface->v4].co);
+ copy_v3_v3(v4, positions[mface->v4]);
if (isect_ray_tri_watertight_v3(co1, &isect_precalc, v1, v3, v4, &lambda, NULL)) {
pa2 = (pa + (int)(lambda * size[a]) * a0mul);
@@ -570,14 +567,15 @@ static void distribute_from_volume_exec(ParticleTask *thread, ParticleData *pa,
{
ParticleThreadContext *ctx = thread->ctx;
Mesh *mesh = ctx->mesh;
- float *v1, *v2, *v3, *v4, nor[3], co[3];
+ const float *v1, *v2, *v3, *v4;
+ float nor[3], co[3];
float cur_d, min_d, randu, randv;
int distr = ctx->distr;
int i, intersect, tot;
int rng_skip_tot = PSYS_RND_DIST_SKIP; /* count how many rng_* calls won't need skipping */
MFace *mface;
- MVert *mvert = BKE_mesh_verts_for_write(mesh);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
pa->num = i = ctx->index[p];
MFace *mfaces = (MFace *)CustomData_get_layer(&mesh->fdata, CD_MFACE);
@@ -614,8 +612,18 @@ static void distribute_from_volume_exec(ParticleTask *thread, ParticleData *pa,
/* experimental */
tot = mesh->totface;
- psys_interpolate_face(
- mesh, mvert, BKE_mesh_vertex_normals_ensure(mesh), mface, 0, 0, pa->fuv, co, nor, 0, 0, 0);
+ psys_interpolate_face(mesh,
+ positions,
+ BKE_mesh_vertex_normals_ensure(mesh),
+ mface,
+ 0,
+ 0,
+ pa->fuv,
+ co,
+ nor,
+ 0,
+ 0,
+ 0);
normalize_v3(nor);
negate_v3(nor);
@@ -628,9 +636,9 @@ static void distribute_from_volume_exec(ParticleTask *thread, ParticleData *pa,
continue;
}
- v1 = mvert[mface->v1].co;
- v2 = mvert[mface->v2].co;
- v3 = mvert[mface->v3].co;
+ v1 = positions[mface->v1];
+ v2 = positions[mface->v2];
+ v3 = positions[mface->v3];
if (isect_ray_tri_v3(co, nor, v2, v3, v1, &cur_d, NULL)) {
if (cur_d < min_d) {
@@ -640,7 +648,7 @@ static void distribute_from_volume_exec(ParticleTask *thread, ParticleData *pa,
}
}
if (mface->v4) {
- v4 = mvert[mface->v4].co;
+ v4 = positions[mface->v4];
if (isect_ray_tri_v3(co, nor, v4, v1, v3, &cur_d, NULL)) {
if (cur_d < min_d) {
@@ -993,7 +1001,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx,
BKE_mesh_orco_ensure(ob, mesh);
if (from == PART_FROM_VERT) {
- MVert *mv = BKE_mesh_verts_for_write(mesh);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
const float(*orcodata)[3] = CustomData_get_layer(&mesh->vdata, CD_ORCO);
int totvert = mesh->totvert;
@@ -1005,7 +1013,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx,
BKE_mesh_orco_verts_transform(ob->data, &co, 1, 1);
}
else {
- copy_v3_v3(co, mv[p].co);
+ copy_v3_v3(co, positions[p]);
}
BLI_kdtree_3d_insert(tree, p, co);
}
@@ -1040,7 +1048,6 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx,
/* Calculate weights from face areas */
if ((part->flag & PART_EDISTR || children) && from != PART_FROM_VERT) {
- MVert *v1, *v2, *v3, *v4;
float totarea = 0.0f, co1[3], co2[3], co3[3], co4[3];
const float(*orcodata)[3];
@@ -1064,16 +1071,12 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx,
}
}
else {
- MVert *verts = BKE_mesh_verts_for_write(mesh);
- v1 = &verts[mf->v1];
- v2 = &verts[mf->v2];
- v3 = &verts[mf->v3];
- copy_v3_v3(co1, v1->co);
- copy_v3_v3(co2, v2->co);
- copy_v3_v3(co3, v3->co);
+ const float(*positions)[3] = BKE_mesh_positions_for_write(mesh);
+ copy_v3_v3(co1, positions[mf->v1]);
+ copy_v3_v3(co2, positions[mf->v2]);
+ copy_v3_v3(co3, positions[mf->v3]);
if (mf->v4) {
- v4 = &verts[mf->v4];
- copy_v3_v3(co4, v4->co);
+ copy_v3_v3(co4, positions[mf->v4]);
}
}
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index d97a217a734..bd854a427d0 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -2779,18 +2779,18 @@ void BKE_psys_collision_neartest_cb(void *userdata,
ParticleCollision *col = (ParticleCollision *)userdata;
ParticleCollisionElement pce;
const MVertTri *vt = &col->md->tri[index];
- MVert *x = col->md->x;
- MVert *v = col->md->current_v;
+ float(*x)[3] = col->md->x;
+ float(*v)[3] = col->md->current_v;
float t = hit->dist / col->original_ray_length;
int collision = 0;
- pce.x[0] = x[vt->tri[0]].co;
- pce.x[1] = x[vt->tri[1]].co;
- pce.x[2] = x[vt->tri[2]].co;
+ pce.x[0] = x[vt->tri[0]];
+ pce.x[1] = x[vt->tri[1]];
+ pce.x[2] = x[vt->tri[2]];
- pce.v[0] = v[vt->tri[0]].co;
- pce.v[1] = v[vt->tri[1]].co;
- pce.v[2] = v[vt->tri[2]].co;
+ pce.v[0] = v[vt->tri[0]];
+ pce.v[1] = v[vt->tri[1]];
+ pce.v[2] = v[vt->tri[2]];
pce.tot = 3;
pce.inside = 0;
@@ -3307,7 +3307,6 @@ static void hair_create_input_mesh(ParticleSimulationData *sim,
ParticleSystem *psys = sim->psys;
ParticleSettings *part = psys->part;
Mesh *mesh;
- MVert *mvert;
MEdge *medge;
MDeformVert *dvert;
HairKey *key;
@@ -3321,7 +3320,7 @@ static void hair_create_input_mesh(ParticleSimulationData *sim,
if (!mesh) {
*r_mesh = mesh = BKE_mesh_new_nomain(totpoint, totedge, 0, 0, 0);
}
- mvert = BKE_mesh_verts_for_write(mesh);
+ float(*positions)[3] = BKE_mesh_positions_for_write(mesh);
medge = BKE_mesh_edges_for_write(mesh);
dvert = BKE_mesh_deform_verts_for_write(mesh);
@@ -3345,6 +3344,8 @@ static void hair_create_input_mesh(ParticleSimulationData *sim,
psys->clmd->sim_parms->vgroup_mass = 1;
+ int vert_index = 0;
+
/* XXX placeholder for more flexible future hair settings */
hair_radius = part->size;
@@ -3383,16 +3384,16 @@ static void hair_create_input_mesh(ParticleSimulationData *sim,
hair->radius = hair_radius;
hair->bending_stiffness = bending_stiffness;
- add_v3_v3v3(mvert->co, co, co);
- sub_v3_v3(mvert->co, co_next);
- mul_m4_v3(hairmat, mvert->co);
+ add_v3_v3v3(positions[vert_index], co, co);
+ sub_v3_v3(positions[vert_index], co_next);
+ mul_m4_v3(hairmat, positions[vert_index]);
medge->v1 = pa->hair_index - 1;
medge->v2 = pa->hair_index;
dvert = hair_set_pinning(dvert, 1.0f);
- mvert++;
+ vert_index++;
medge++;
}
@@ -3404,8 +3405,8 @@ static void hair_create_input_mesh(ParticleSimulationData *sim,
hair->radius = hair_radius;
hair->bending_stiffness = bending_stiffness;
- copy_v3_v3(mvert->co, co);
- mul_m4_v3(hairmat, mvert->co);
+ copy_v3_v3(positions[vert_index], co);
+ mul_m4_v3(hairmat, positions[vert_index]);
if (k) {
medge->v1 = pa->hair_index + k - 1;
@@ -3420,7 +3421,7 @@ static void hair_create_input_mesh(ParticleSimulationData *sim,
dvert = hair_set_pinning(dvert, 1.0f);
}
- mvert++;
+ vert_index++;
if (k) {
medge++;
}
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 24ea2de98f6..726f8a723c0 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -586,7 +586,7 @@ static void pbvh_draw_args_init(PBVH *pbvh, PBVH_GPU_Args *args, PBVHNode *node)
args->grid_hidden = pbvh->grid_hidden;
args->face_sets_color_default = pbvh->face_sets_color_default;
args->face_sets_color_seed = pbvh->face_sets_color_seed;
- args->mvert = pbvh->verts;
+ args->mesh_positions = pbvh->mesh_positions;
args->mloop = pbvh->mloop;
args->mpoly = pbvh->mpoly;
args->mlooptri = pbvh->looptri;
@@ -717,7 +717,7 @@ void BKE_pbvh_build_mesh(PBVH *pbvh,
Mesh *mesh,
const MPoly *mpoly,
const MLoop *mloop,
- MVert *verts,
+ float (*positions)[3],
int totvert,
struct CustomData *vdata,
struct CustomData *ldata,
@@ -736,7 +736,7 @@ void BKE_pbvh_build_mesh(PBVH *pbvh,
&mesh->pdata, CD_PROP_INT32, "material_index");
pbvh->mloop = mloop;
pbvh->looptri = looptri;
- pbvh->verts = verts;
+ pbvh->mesh_positions = positions;
BKE_mesh_vertex_normals_ensure(mesh);
pbvh->vert_normals = BKE_mesh_vertex_normals_for_write(mesh);
pbvh->hide_vert = (bool *)CustomData_get_layer_named(&mesh->vdata, CD_PROP_BOOL, ".hide_vert");
@@ -763,7 +763,7 @@ void BKE_pbvh_build_mesh(PBVH *pbvh,
BB_reset((BB *)bbc);
for (int j = 0; j < sides; j++) {
- BB_expand((BB *)bbc, verts[pbvh->mloop[lt->tri[j]].v].co);
+ BB_expand((BB *)bbc, positions[pbvh->mloop[lt->tri[j]].v]);
}
BBC_update_centroid(bbc);
@@ -952,10 +952,10 @@ void BKE_pbvh_free(PBVH *pbvh)
}
if (pbvh->deformed) {
- if (pbvh->verts) {
+ if (pbvh->mesh_positions) {
/* if pbvh was deformed, new memory was allocated for verts/faces -- free it */
- MEM_freeN((void *)pbvh->verts);
+ MEM_freeN((void *)pbvh->mesh_positions);
}
}
@@ -1318,7 +1318,7 @@ static void pbvh_update_normals_accum_task_cb(void *__restrict userdata,
/* Face normal and mask */
if (lt->poly != mpoly_prev) {
const MPoly *mp = &pbvh->mpoly[lt->poly];
- BKE_mesh_calc_poly_normal(mp, &pbvh->mloop[mp->loopstart], pbvh->verts, fn);
+ BKE_mesh_calc_poly_normal(mp, &pbvh->mloop[mp->loopstart], pbvh->mesh_positions, fn);
mpoly_prev = lt->poly;
}
@@ -1729,11 +1729,9 @@ void BKE_pbvh_update_vertex_data(PBVH *pbvh, int flag)
static void pbvh_faces_node_visibility_update(PBVH *pbvh, PBVHNode *node)
{
- MVert *mvert;
- const int *vert_indices;
int totvert, i;
BKE_pbvh_node_num_verts(pbvh, node, NULL, &totvert);
- BKE_pbvh_node_get_verts(pbvh, node, &vert_indices, &mvert);
+ const int *vert_indices = BKE_pbvh_node_get_vert_indices(node);
if (pbvh->hide_vert == NULL) {
BKE_pbvh_node_fully_hidden_set(node, false);
@@ -2111,18 +2109,9 @@ void BKE_pbvh_node_get_loops(PBVH *pbvh,
}
}
-void BKE_pbvh_node_get_verts(PBVH *pbvh,
- PBVHNode *node,
- const int **r_vert_indices,
- MVert **r_verts)
+const int *BKE_pbvh_node_get_vert_indices(PBVHNode *node)
{
- if (r_vert_indices) {
- *r_vert_indices = node->vert_indices;
- }
-
- if (r_verts) {
- *r_verts = pbvh->verts;
- }
+ return node->vert_indices;
}
void BKE_pbvh_node_num_verts(PBVH *pbvh, PBVHNode *node, int *r_uniquevert, int *r_totvert)
@@ -2433,7 +2422,7 @@ static bool pbvh_faces_node_raycast(PBVH *pbvh,
int *r_active_face_index,
float *r_face_normal)
{
- const MVert *vert = pbvh->verts;
+ const float(*positions)[3] = pbvh->mesh_positions;
const MLoop *mloop = pbvh->mloop;
const int *faces = node->prim_indices;
int totface = node->totprim;
@@ -2457,9 +2446,9 @@ static bool pbvh_faces_node_raycast(PBVH *pbvh,
}
else {
/* intersect with current coordinates */
- co[0] = vert[mloop[lt->tri[0]].v].co;
- co[1] = vert[mloop[lt->tri[1]].v].co;
- co[2] = vert[mloop[lt->tri[2]].v].co;
+ co[0] = positions[mloop[lt->tri[0]].v];
+ co[1] = positions[mloop[lt->tri[1]].v];
+ co[2] = positions[mloop[lt->tri[2]].v];
}
if (ray_face_intersection_tri(ray_start, isect_precalc, co[0], co[1], co[2], depth)) {
@@ -2743,7 +2732,7 @@ static bool pbvh_faces_node_nearest_to_ray(PBVH *pbvh,
float *depth,
float *dist_sq)
{
- const MVert *vert = pbvh->verts;
+ const float(*positions)[3] = pbvh->mesh_positions;
const MLoop *mloop = pbvh->mloop;
const int *faces = node->prim_indices;
int i, totface = node->totprim;
@@ -2771,9 +2760,9 @@ static bool pbvh_faces_node_nearest_to_ray(PBVH *pbvh,
/* intersect with current coordinates */
hit |= ray_face_nearest_tri(ray_start,
ray_normal,
- vert[mloop[lt->tri[0]].v].co,
- vert[mloop[lt->tri[1]].v].co,
- vert[mloop[lt->tri[2]].v].co,
+ positions[mloop[lt->tri[0]].v],
+ positions[mloop[lt->tri[1]].v],
+ positions[mloop[lt->tri[2]].v],
depth,
dist_sq);
}
@@ -3094,15 +3083,9 @@ float (*BKE_pbvh_vert_coords_alloc(PBVH *pbvh))[3]
{
float(*vertCos)[3] = NULL;
- if (pbvh->verts) {
- MVert *mvert = pbvh->verts;
-
- vertCos = MEM_callocN(3 * pbvh->totvert * sizeof(float), "BKE_pbvh_get_vertCoords");
- float *co = (float *)vertCos;
-
- for (int a = 0; a < pbvh->totvert; a++, mvert++, co += 3) {
- copy_v3_v3(co, mvert->co);
- }
+ if (pbvh->mesh_positions) {
+ vertCos = MEM_malloc_arrayN(pbvh->totvert, sizeof(float[3]), __func__);
+ memcpy(vertCos, pbvh->mesh_positions, sizeof(float[3]) * pbvh->totvert);
}
return vertCos;
@@ -3116,12 +3099,12 @@ void BKE_pbvh_vert_coords_apply(PBVH *pbvh, const float (*vertCos)[3], const int
}
if (!pbvh->deformed) {
- if (pbvh->verts) {
+ if (pbvh->mesh_positions) {
/* if pbvh is not already deformed, verts/faces points to the */
/* original data and applying new coords to this arrays would lead to */
/* unneeded deformation -- duplicate verts/faces to avoid this */
- pbvh->verts = MEM_dupallocN(pbvh->verts);
+ pbvh->mesh_positions = MEM_dupallocN(pbvh->mesh_positions);
/* No need to dupalloc pbvh->looptri, this one is 'totally owned' by pbvh,
* it's never some mesh data. */
@@ -3129,20 +3112,20 @@ void BKE_pbvh_vert_coords_apply(PBVH *pbvh, const float (*vertCos)[3], const int
}
}
- if (pbvh->verts) {
- MVert *mvert = pbvh->verts;
+ if (pbvh->mesh_positions) {
+ float(*positions)[3] = pbvh->mesh_positions;
/* copy new verts coords */
- for (int a = 0; a < pbvh->totvert; a++, mvert++) {
+ for (int a = 0; a < pbvh->totvert; a++) {
/* no need for float comparison here (memory is exactly equal or not) */
- if (memcmp(mvert->co, vertCos[a], sizeof(float[3])) != 0) {
- copy_v3_v3(mvert->co, vertCos[a]);
+ if (memcmp(positions[a], vertCos[a], sizeof(float[3])) != 0) {
+ copy_v3_v3(positions[a], vertCos[a]);
BKE_pbvh_vert_tag_update_normal(pbvh, BKE_pbvh_make_vref(a));
}
}
/* coordinates are new -- normals should also be updated */
BKE_mesh_calc_normals_looptri(
- pbvh->verts, pbvh->totvert, pbvh->mloop, pbvh->looptri, pbvh->totprim, NULL);
+ pbvh->mesh_positions, pbvh->totvert, pbvh->mloop, pbvh->looptri, pbvh->totprim, NULL);
for (int a = 0; a < pbvh->totnode; a++) {
BKE_pbvh_node_mark_update(&pbvh->nodes[a]);
@@ -3244,15 +3227,13 @@ void BKE_pbvh_node_color_buffer_free(PBVH *pbvh)
void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int mode)
{
struct CCGElem **grids;
- struct MVert *verts;
- const int *vert_indices;
int *grid_indices;
int totgrid, gridsize, uniq_verts, totvert;
vi->grid = NULL;
vi->no = NULL;
vi->fno = NULL;
- vi->mvert = NULL;
+ vi->mesh_positions = NULL;
vi->vertex.i = 0LL;
vi->respect_hide = pbvh->respect_hide;
@@ -3263,7 +3244,7 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
BKE_pbvh_node_get_grids(pbvh, node, &grid_indices, &totgrid, NULL, &gridsize, &grids);
BKE_pbvh_node_num_verts(pbvh, node, &uniq_verts, &totvert);
- BKE_pbvh_node_get_verts(pbvh, node, &vert_indices, &verts);
+ const int *vert_indices = BKE_pbvh_node_get_vert_indices(node);
vi->key = pbvh->gridkey;
vi->grids = grids;
@@ -3278,7 +3259,8 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
vi->totvert = uniq_verts;
}
vi->vert_indices = vert_indices;
- vi->mverts = verts;
+ vi->mesh_positions = pbvh->mesh_positions;
+ vi->is_mesh = pbvh->mesh_positions != NULL;
if (pbvh->header.type == PBVH_BMESH) {
BLI_gsetIterator_init(&vi->bm_unique_verts, node->bm_unique_verts);
@@ -3364,10 +3346,10 @@ void BKE_pbvh_parallel_range_settings(TaskParallelSettings *settings,
settings->use_threading = use_threading && totnode > 1;
}
-MVert *BKE_pbvh_get_verts(const PBVH *pbvh)
+float (*BKE_pbvh_get_positions(const PBVH *pbvh))[3]
{
BLI_assert(pbvh->header.type == PBVH_FACES);
- return pbvh->verts;
+ return pbvh->mesh_positions;
}
const float (*BKE_pbvh_get_vert_normals(const PBVH *pbvh))[3]
diff --git a/source/blender/blenkernel/intern/pbvh_intern.h b/source/blender/blenkernel/intern/pbvh_intern.h
index 368a9ffa1ea..4b3b0e9b213 100644
--- a/source/blender/blenkernel/intern/pbvh_intern.h
+++ b/source/blender/blenkernel/intern/pbvh_intern.h
@@ -15,7 +15,6 @@ extern "C" {
struct MLoop;
struct MLoopTri;
struct MPoly;
-struct MVert;
/* Axis-aligned bounding box */
typedef struct {
@@ -56,7 +55,7 @@ struct PBVHNode {
int *prim_indices;
unsigned int totprim; /* Number of primitives inside prim_indices. */
- /* Array of indices into the mesh's MVert array. Contains the
+ /* Array of indices into the mesh's vertex array. Contains the
* indices of all vertices used by faces that are within this
* node's bounding box.
*
@@ -157,7 +156,7 @@ struct PBVH {
/* NOTE: Normals are not `const` because they can be updated for drawing by sculpt code. */
float (*vert_normals)[3];
bool *hide_vert;
- struct MVert *verts;
+ float (*mesh_positions)[3];
const struct MPoly *mpoly;
bool *hide_poly;
/** Material indices. Only valid for polygon meshes. */
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 5e91b23bce3..05cb4895e6e 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -359,12 +359,12 @@ static rbCollisionShape *rigidbody_get_shape_convexhull_from_mesh(Object *ob,
{
rbCollisionShape *shape = NULL;
Mesh *mesh = NULL;
- MVert *mvert = NULL;
+ float(*positions)[3] = NULL;
int totvert = 0;
if (ob->type == OB_MESH && ob->data) {
mesh = rigidbody_get_mesh(ob);
- mvert = (mesh) ? BKE_mesh_verts_for_write(mesh) : NULL;
+ positions = (mesh) ? BKE_mesh_positions_for_write(mesh) : NULL;
totvert = (mesh) ? mesh->totvert : 0;
}
else {
@@ -372,7 +372,8 @@ static rbCollisionShape *rigidbody_get_shape_convexhull_from_mesh(Object *ob,
}
if (totvert) {
- shape = RB_shape_new_convex_hull((float *)mvert, sizeof(MVert), totvert, margin, can_embed);
+ shape = RB_shape_new_convex_hull(
+ (float *)positions, sizeof(float[3]), totvert, margin, can_embed);
}
else {
CLOG_ERROR(&LOG, "no vertices to define Convex Hull collision shape with");
@@ -401,7 +402,7 @@ static rbCollisionShape *rigidbody_get_shape_trimesh_from_mesh(Object *ob)
return NULL;
}
- const MVert *mvert = BKE_mesh_verts(mesh);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
totvert = mesh->totvert;
looptri = BKE_mesh_runtime_looptri_ensure(mesh);
tottri = BKE_mesh_runtime_looptri_len(mesh);
@@ -419,12 +420,12 @@ static rbCollisionShape *rigidbody_get_shape_trimesh_from_mesh(Object *ob)
/* init mesh data for collision shape */
mdata = RB_trimesh_data_new(tottri, totvert);
- RB_trimesh_add_vertices(mdata, (float *)mvert, totvert, sizeof(MVert));
+ RB_trimesh_add_vertices(mdata, (float *)positions, totvert, sizeof(float[3]));
/* loop over all faces, adding them as triangles to the collision shape
* (so for some faces, more than triangle will get added)
*/
- if (mvert && looptri) {
+ if (positions && looptri) {
for (i = 0; i < tottri; i++) {
/* add first triangle - verts 1,2,3 */
const MLoopTri *lt = &looptri[i];
@@ -676,14 +677,14 @@ void BKE_rigidbody_calc_volume(Object *ob, float *r_vol)
return;
}
- const MVert *mvert = BKE_mesh_verts(mesh);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
totvert = mesh->totvert;
lt = BKE_mesh_runtime_looptri_ensure(mesh);
tottri = BKE_mesh_runtime_looptri_len(mesh);
const MLoop *mloop = BKE_mesh_loops(mesh);
if (totvert > 0 && tottri > 0) {
- BKE_mesh_calc_volume(mvert, totvert, lt, tottri, mloop, &volume, NULL);
+ BKE_mesh_calc_volume(positions, totvert, lt, tottri, mloop, &volume, NULL);
const float volume_scale = mat4_to_volume_scale(ob->object_to_world);
volume *= fabsf(volume_scale);
}
@@ -750,14 +751,14 @@ void BKE_rigidbody_calc_center_of_mass(Object *ob, float r_center[3])
return;
}
- const MVert *mvert = BKE_mesh_verts(mesh);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
totvert = mesh->totvert;
looptri = BKE_mesh_runtime_looptri_ensure(mesh);
tottri = BKE_mesh_runtime_looptri_len(mesh);
const MLoop *mloop = BKE_mesh_loops(mesh);
if (totvert > 0 && tottri > 0) {
- BKE_mesh_calc_volume(mvert, totvert, looptri, tottri, mloop, NULL, r_center);
+ BKE_mesh_calc_volume(positions, totvert, looptri, tottri, mloop, NULL, r_center);
}
}
break;
@@ -1673,14 +1674,14 @@ static void rigidbody_update_sim_ob(Depsgraph *depsgraph, Object *ob, RigidBodyO
if (rbo->shape == RB_SHAPE_TRIMESH && rbo->flag & RBO_FLAG_USE_DEFORM) {
Mesh *mesh = ob->runtime.mesh_deform_eval;
if (mesh) {
- MVert *mvert = BKE_mesh_verts_for_write(mesh);
+ float(*positions)[3] = BKE_mesh_positions_for_write(mesh);
int totvert = mesh->totvert;
const BoundBox *bb = BKE_object_boundbox_get(ob);
RB_shape_trimesh_update(rbo->shared->physics_shape,
- (float *)mvert,
+ (float *)positions,
totvert,
- sizeof(MVert),
+ sizeof(float[3]),
bb->vec[0],
bb->vec[6]);
}
diff --git a/source/blender/blenkernel/intern/shrinkwrap.cc b/source/blender/blenkernel/intern/shrinkwrap.cc
index 65226a5db9d..298b7b3da0a 100644
--- a/source/blender/blenkernel/intern/shrinkwrap.cc
+++ b/source/blender/blenkernel/intern/shrinkwrap.cc
@@ -59,7 +59,7 @@ struct ShrinkwrapCalcData {
Object *ob; /* object we are applying shrinkwrap to */
- MVert *vert; /* Array of verts being projected. */
+ float (*positions)[3]; /* Array of verts being projected. */
const float (*vert_normals)[3];
/* Vertices being shrink-wrapped. */
float (*vertexCos)[3];
@@ -193,7 +193,7 @@ static void merge_vert_dir(ShrinkwrapBoundaryVertData *vdata,
static ShrinkwrapBoundaryData *shrinkwrap_build_boundary_data(Mesh *mesh)
{
- const MVert *mvert = BKE_mesh_verts(mesh);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
const MEdge *medge = BKE_mesh_edges(mesh);
const MLoop *mloop = BKE_mesh_loops(mesh);
@@ -290,7 +290,7 @@ static ShrinkwrapBoundaryData *shrinkwrap_build_boundary_data(Mesh *mesh)
const MEdge *edge = &medge[i];
float dir[3];
- sub_v3_v3v3(dir, mvert[edge->v2].co, mvert[edge->v1].co);
+ sub_v3_v3v3(dir, positions[edge->v2], positions[edge->v1]);
normalize_v3(dir);
merge_vert_dir(boundary_verts, vert_status, vert_boundary_id[edge->v1], dir, 1);
@@ -359,8 +359,8 @@ static void shrinkwrap_calc_nearest_vertex_cb_ex(void *__restrict userdata,
}
/* Convert the vertex to tree coordinates */
- if (calc->vert) {
- copy_v3_v3(tmp_co, calc->vert[i].co);
+ if (calc->positions) {
+ copy_v3_v3(tmp_co, calc->positions[i]);
}
else {
copy_v3_v3(tmp_co, co);
@@ -521,12 +521,12 @@ static void shrinkwrap_calc_normal_projection_cb_ex(void *__restrict userdata,
return;
}
- if (calc->vert != nullptr && calc->smd->projAxis == MOD_SHRINKWRAP_PROJECT_OVER_NORMAL) {
- /* calc->vert contains verts from evaluated mesh. */
+ if (calc->positions != nullptr && calc->smd->projAxis == MOD_SHRINKWRAP_PROJECT_OVER_NORMAL) {
+ /* calc->positions contains verts from evaluated mesh. */
/* These coordinates are deformed by vertexCos only for normal projection
* (to get correct normals) for other cases calc->verts contains undeformed coordinates and
* vertexCos should be used */
- copy_v3_v3(tmp_co, calc->vert[i].co);
+ copy_v3_v3(tmp_co, calc->positions[i]);
copy_v3_v3(tmp_no, calc->vert_normals[i]);
}
else {
@@ -642,7 +642,7 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc)
/* Prepare data to retrieve the direction in which we should project each vertex */
if (calc->smd->projAxis == MOD_SHRINKWRAP_PROJECT_OVER_NORMAL) {
- if (calc->vert == nullptr) {
+ if (calc->positions == nullptr) {
return;
}
}
@@ -938,7 +938,7 @@ static void target_project_edge(const ShrinkwrapTreeData *tree,
{
const BVHTreeFromMesh *data = &tree->treeData;
const MEdge *edge = &data->edge[eidx];
- const float *vedge_co[2] = {data->vert[edge->v1].co, data->vert[edge->v2].co};
+ const float *vedge_co[2] = {data->positions[edge->v1], data->positions[edge->v2]};
#ifdef TRACE_TARGET_PROJECT
printf("EDGE %d (%.3f,%.3f,%.3f) (%.3f,%.3f,%.3f)\n",
@@ -1016,9 +1016,8 @@ static void mesh_looptri_target_project(void *userdata,
const MLoopTri *lt = &data->looptri[index];
const MLoop *loop[3] = {
&data->loop[lt->tri[0]], &data->loop[lt->tri[1]], &data->loop[lt->tri[2]]};
- const MVert *vtri[3] = {
- &data->vert[loop[0]->v], &data->vert[loop[1]->v], &data->vert[loop[2]->v]};
- const float *vtri_co[3] = {vtri[0]->co, vtri[1]->co, vtri[2]->co};
+ const float *vtri_co[3] = {
+ data->positions[loop[0]->v], data->positions[loop[1]->v], data->positions[loop[2]->v]};
float raw_hit_co[3], hit_co[3], hit_no[3], dist_sq, vtri_no[3][3];
/* First find the closest point and bail out if it's worse than the current solution. */
@@ -1120,8 +1119,8 @@ static void shrinkwrap_calc_nearest_surface_point_cb_ex(void *__restrict userdat
}
/* Convert the vertex to tree coordinates */
- if (calc->vert) {
- copy_v3_v3(tmp_co, calc->vert[i].co);
+ if (calc->positions) {
+ copy_v3_v3(tmp_co, calc->positions[i]);
}
else {
copy_v3_v3(tmp_co, co);
@@ -1206,9 +1205,9 @@ void BKE_shrinkwrap_compute_smooth_normal(const ShrinkwrapTreeData *tree,
}
interp_weights_tri_v3(w,
- treeData->vert[vert_indices[0]].co,
- treeData->vert[vert_indices[1]].co,
- treeData->vert[vert_indices[2]].co,
+ treeData->positions[vert_indices[0]],
+ treeData->positions[vert_indices[1]],
+ treeData->positions[vert_indices[2]],
tmp_co);
/* Interpolate using weights. */
@@ -1409,8 +1408,8 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd,
calc.aux_target = DEG_get_evaluated_object(ctx->depsgraph, smd->auxTarget);
if (mesh != nullptr && smd->shrinkType == MOD_SHRINKWRAP_PROJECT) {
- /* Setup arrays to get vertices position, normals and deform weights. */
- calc.vert = BKE_mesh_verts_for_write(mesh);
+ /* Setup arrays to get vertexs positions, normals and deform weights */
+ calc.positions = BKE_mesh_positions_for_write(mesh);
calc.vert_normals = BKE_mesh_vertex_normals_ensure(mesh);
/* Using vertices positions/normals as if a subsurface was applied */
@@ -1430,11 +1429,11 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd,
(ob->mode & OB_MODE_EDIT) ? SUBSURF_IN_EDIT_MODE : SubsurfFlags(0));
if (ss_mesh) {
- calc.vert = static_cast<MVert *>(ss_mesh->getVertDataArray(ss_mesh, CD_MVERT));
- if (calc.vert) {
+ calc.positions = reinterpret_cast<float(*)[3]>(ss_mesh->getVertArray(ss_mesh));
+ if (calc.positions) {
/* TRICKY: this code assumes subsurface will have the transformed original vertices
* in their original order at the end of the vert array. */
- calc.vert = calc.vert + ss_mesh->getNumVerts(ss_mesh) - dm->getNumVerts(dm);
+ calc.positions = calc.positions + ss_mesh->getNumVerts(ss_mesh) - dm->getNumVerts(dm);
}
}
@@ -1575,7 +1574,7 @@ void BKE_shrinkwrap_remesh_target_project(Mesh *src_me, Mesh *target_me, Object
calc.vgroup = -1;
calc.target = target_me;
calc.keepDist = ssmd.keepDist;
- calc.vert = BKE_mesh_verts_for_write(src_me);
+ calc.positions = BKE_mesh_positions_for_write(src_me);
BLI_SPACE_TRANSFORM_SETUP(&calc.local2target, ob_target, ob_target);
ShrinkwrapTreeData tree;
diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c
index efe423ccfc5..70ed7a6b14c 100644
--- a/source/blender/blenkernel/intern/softbody.c
+++ b/source/blender/blenkernel/intern/softbody.c
@@ -255,8 +255,8 @@ typedef struct ccdf_minmax {
typedef struct ccd_Mesh {
int mvert_num, tri_num;
- const MVert *mvert;
- const MVert *mprevvert;
+ const float (*positions)[3];
+ const float (*positions_prev)[3];
const MVertTri *tri;
int safety;
ccdf_minmax *mima;
@@ -290,20 +290,20 @@ static ccd_Mesh *ccd_mesh_make(Object *ob)
pccd_M->safety = CCD_SAFETY;
pccd_M->bbmin[0] = pccd_M->bbmin[1] = pccd_M->bbmin[2] = 1e30f;
pccd_M->bbmax[0] = pccd_M->bbmax[1] = pccd_M->bbmax[2] = -1e30f;
- pccd_M->mprevvert = NULL;
+ pccd_M->positions_prev = NULL;
/* Blow it up with force-field ranges. */
hull = max_ff(ob->pd->pdef_sbift, ob->pd->pdef_sboft);
/* Allocate and copy verts. */
- pccd_M->mvert = MEM_dupallocN(cmd->xnew);
+ pccd_M->positions = MEM_dupallocN(cmd->xnew);
/* note that xnew coords are already in global space, */
/* determine the ortho BB */
for (i = 0; i < pccd_M->mvert_num; i++) {
const float *v;
/* evaluate limits */
- v = pccd_M->mvert[i].co;
+ v = pccd_M->positions[i];
pccd_M->bbmin[0] = min_ff(pccd_M->bbmin[0], v[0] - hull);
pccd_M->bbmin[1] = min_ff(pccd_M->bbmin[1], v[1] - hull);
pccd_M->bbmin[2] = min_ff(pccd_M->bbmin[2], v[2] - hull);
@@ -325,7 +325,7 @@ static ccd_Mesh *ccd_mesh_make(Object *ob)
mima->minx = mima->miny = mima->minz = 1e30f;
mima->maxx = mima->maxy = mima->maxz = -1e30f;
- v = pccd_M->mvert[vt->tri[0]].co;
+ v = pccd_M->positions[vt->tri[0]];
mima->minx = min_ff(mima->minx, v[0] - hull);
mima->miny = min_ff(mima->miny, v[1] - hull);
mima->minz = min_ff(mima->minz, v[2] - hull);
@@ -333,7 +333,7 @@ static ccd_Mesh *ccd_mesh_make(Object *ob)
mima->maxy = max_ff(mima->maxy, v[1] + hull);
mima->maxz = max_ff(mima->maxz, v[2] + hull);
- v = pccd_M->mvert[vt->tri[1]].co;
+ v = pccd_M->positions[vt->tri[1]];
mima->minx = min_ff(mima->minx, v[0] - hull);
mima->miny = min_ff(mima->miny, v[1] - hull);
mima->minz = min_ff(mima->minz, v[2] - hull);
@@ -341,7 +341,7 @@ static ccd_Mesh *ccd_mesh_make(Object *ob)
mima->maxy = max_ff(mima->maxy, v[1] + hull);
mima->maxz = max_ff(mima->maxz, v[2] + hull);
- v = pccd_M->mvert[vt->tri[2]].co;
+ v = pccd_M->positions[vt->tri[2]];
mima->minx = min_ff(mima->minx, v[0] - hull);
mima->miny = min_ff(mima->miny, v[1] - hull);
mima->minz = min_ff(mima->minz, v[2] - hull);
@@ -381,19 +381,19 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M)
hull = max_ff(ob->pd->pdef_sbift, ob->pd->pdef_sboft);
/* rotate current to previous */
- if (pccd_M->mprevvert) {
- MEM_freeN((void *)pccd_M->mprevvert);
+ if (pccd_M->positions_prev) {
+ MEM_freeN((void *)pccd_M->positions_prev);
}
- pccd_M->mprevvert = pccd_M->mvert;
+ pccd_M->positions_prev = pccd_M->positions;
/* Allocate and copy verts. */
- pccd_M->mvert = MEM_dupallocN(cmd->xnew);
+ pccd_M->positions = MEM_dupallocN(cmd->xnew);
/* note that xnew coords are already in global space, */
/* determine the ortho BB */
for (i = 0; i < pccd_M->mvert_num; i++) {
const float *v;
/* evaluate limits */
- v = pccd_M->mvert[i].co;
+ v = pccd_M->positions[i];
pccd_M->bbmin[0] = min_ff(pccd_M->bbmin[0], v[0] - hull);
pccd_M->bbmin[1] = min_ff(pccd_M->bbmin[1], v[1] - hull);
pccd_M->bbmin[2] = min_ff(pccd_M->bbmin[2], v[2] - hull);
@@ -403,7 +403,7 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M)
pccd_M->bbmax[2] = max_ff(pccd_M->bbmax[2], v[2] + hull);
/* evaluate limits */
- v = pccd_M->mprevvert[i].co;
+ v = pccd_M->positions_prev[i];
pccd_M->bbmin[0] = min_ff(pccd_M->bbmin[0], v[0] - hull);
pccd_M->bbmin[1] = min_ff(pccd_M->bbmin[1], v[1] - hull);
pccd_M->bbmin[2] = min_ff(pccd_M->bbmin[2], v[2] - hull);
@@ -420,8 +420,8 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M)
mima->minx = mima->miny = mima->minz = 1e30f;
mima->maxx = mima->maxy = mima->maxz = -1e30f;
- /* mvert */
- v = pccd_M->mvert[vt->tri[0]].co;
+ /* positions */
+ v = pccd_M->positions[vt->tri[0]];
mima->minx = min_ff(mima->minx, v[0] - hull);
mima->miny = min_ff(mima->miny, v[1] - hull);
mima->minz = min_ff(mima->minz, v[2] - hull);
@@ -429,7 +429,7 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M)
mima->maxy = max_ff(mima->maxy, v[1] + hull);
mima->maxz = max_ff(mima->maxz, v[2] + hull);
- v = pccd_M->mvert[vt->tri[1]].co;
+ v = pccd_M->positions[vt->tri[1]];
mima->minx = min_ff(mima->minx, v[0] - hull);
mima->miny = min_ff(mima->miny, v[1] - hull);
mima->minz = min_ff(mima->minz, v[2] - hull);
@@ -437,7 +437,7 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M)
mima->maxy = max_ff(mima->maxy, v[1] + hull);
mima->maxz = max_ff(mima->maxz, v[2] + hull);
- v = pccd_M->mvert[vt->tri[2]].co;
+ v = pccd_M->positions[vt->tri[2]];
mima->minx = min_ff(mima->minx, v[0] - hull);
mima->miny = min_ff(mima->miny, v[1] - hull);
mima->minz = min_ff(mima->minz, v[2] - hull);
@@ -445,8 +445,8 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M)
mima->maxy = max_ff(mima->maxy, v[1] + hull);
mima->maxz = max_ff(mima->maxz, v[2] + hull);
- /* mprevvert */
- v = pccd_M->mprevvert[vt->tri[0]].co;
+ /* positions_prev */
+ v = pccd_M->positions_prev[vt->tri[0]];
mima->minx = min_ff(mima->minx, v[0] - hull);
mima->miny = min_ff(mima->miny, v[1] - hull);
mima->minz = min_ff(mima->minz, v[2] - hull);
@@ -454,7 +454,7 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M)
mima->maxy = max_ff(mima->maxy, v[1] + hull);
mima->maxz = max_ff(mima->maxz, v[2] + hull);
- v = pccd_M->mprevvert[vt->tri[1]].co;
+ v = pccd_M->positions_prev[vt->tri[1]];
mima->minx = min_ff(mima->minx, v[0] - hull);
mima->miny = min_ff(mima->miny, v[1] - hull);
mima->minz = min_ff(mima->minz, v[2] - hull);
@@ -462,7 +462,7 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M)
mima->maxy = max_ff(mima->maxy, v[1] + hull);
mima->maxz = max_ff(mima->maxz, v[2] + hull);
- v = pccd_M->mprevvert[vt->tri[2]].co;
+ v = pccd_M->positions_prev[vt->tri[2]];
mima->minx = min_ff(mima->minx, v[0] - hull);
mima->miny = min_ff(mima->miny, v[1] - hull);
mima->minz = min_ff(mima->minz, v[2] - hull);
@@ -476,10 +476,10 @@ static void ccd_mesh_free(ccd_Mesh *ccdm)
{
/* Make sure we're not nuking objects we don't know. */
if (ccdm && (ccdm->safety == CCD_SAFETY)) {
- MEM_freeN((void *)ccdm->mvert);
+ MEM_freeN((void *)ccdm->positions);
MEM_freeN((void *)ccdm->tri);
- if (ccdm->mprevvert) {
- MEM_freeN((void *)ccdm->mprevvert);
+ if (ccdm->positions_prev) {
+ MEM_freeN((void *)ccdm->positions_prev);
}
MEM_freeN(ccdm->mima);
MEM_freeN(ccdm);
@@ -1068,12 +1068,12 @@ static int sb_detect_face_pointCached(const float face_v1[3],
{
/* only with deflecting set */
if (ob->pd && ob->pd->deflect) {
- const MVert *mvert = NULL;
- const MVert *mprevvert = NULL;
+ const float(*positions)[3] = NULL;
+ const float(*positions_prev)[3] = NULL;
if (ccdm) {
- mvert = ccdm->mvert;
+ positions = ccdm->positions;
a = ccdm->mvert_num;
- mprevvert = ccdm->mprevvert;
+ positions_prev = ccdm->positions_prev;
outerfacethickness = ob->pd->pdef_sboft;
if ((aabbmax[0] < ccdm->bbmin[0]) || (aabbmax[1] < ccdm->bbmin[1]) ||
(aabbmax[2] < ccdm->bbmin[2]) || (aabbmin[0] > ccdm->bbmax[0]) ||
@@ -1091,12 +1091,12 @@ static int sb_detect_face_pointCached(const float face_v1[3],
}
/* Use mesh. */
- if (mvert) {
+ if (positions) {
while (a) {
- copy_v3_v3(nv1, mvert[a - 1].co);
- if (mprevvert) {
+ copy_v3_v3(nv1, positions[a - 1]);
+ if (positions_prev) {
mul_v3_fl(nv1, time);
- madd_v3_v3fl(nv1, mprevvert[a - 1].co, 1.0f - time);
+ madd_v3_v3fl(nv1, positions_prev[a - 1], 1.0f - time);
}
/* Origin to face_v2. */
sub_v3_v3(nv1, face_v2);
@@ -1120,7 +1120,7 @@ static int sb_detect_face_pointCached(const float face_v1[3],
}
a--;
} /* while (a) */
- } /* if (mvert) */
+ } /* if (positions) */
} /* if (ob->pd && ob->pd->deflect) */
BLI_ghashIterator_step(ihash);
}
@@ -1160,15 +1160,15 @@ static int sb_detect_face_collisionCached(const float face_v1[3],
{
/* only with deflecting set */
if (ob->pd && ob->pd->deflect) {
- const MVert *mvert = NULL;
- const MVert *mprevvert = NULL;
+ const float(*positions)[3] = NULL;
+ const float(*positions_prev)[3] = NULL;
const MVertTri *vt = NULL;
const ccdf_minmax *mima = NULL;
if (ccdm) {
- mvert = ccdm->mvert;
+ positions = ccdm->positions;
vt = ccdm->tri;
- mprevvert = ccdm->mprevvert;
+ positions_prev = ccdm->positions_prev;
mima = ccdm->mima;
a = ccdm->tri_num;
@@ -1197,21 +1197,21 @@ static int sb_detect_face_collisionCached(const float face_v1[3],
continue;
}
- if (mvert) {
+ if (positions) {
- copy_v3_v3(nv1, mvert[vt->tri[0]].co);
- copy_v3_v3(nv2, mvert[vt->tri[1]].co);
- copy_v3_v3(nv3, mvert[vt->tri[2]].co);
+ copy_v3_v3(nv1, positions[vt->tri[0]]);
+ copy_v3_v3(nv2, positions[vt->tri[1]]);
+ copy_v3_v3(nv3, positions[vt->tri[2]]);
- if (mprevvert) {
+ if (positions_prev) {
mul_v3_fl(nv1, time);
- madd_v3_v3fl(nv1, mprevvert[vt->tri[0]].co, 1.0f - time);
+ madd_v3_v3fl(nv1, positions_prev[vt->tri[0]], 1.0f - time);
mul_v3_fl(nv2, time);
- madd_v3_v3fl(nv2, mprevvert[vt->tri[1]].co, 1.0f - time);
+ madd_v3_v3fl(nv2, positions_prev[vt->tri[1]], 1.0f - time);
mul_v3_fl(nv3, time);
- madd_v3_v3fl(nv3, mprevvert[vt->tri[2]].co, 1.0f - time);
+ madd_v3_v3fl(nv3, positions_prev[vt->tri[2]], 1.0f - time);
}
}
@@ -1336,14 +1336,14 @@ static int sb_detect_edge_collisionCached(const float edge_v1[3],
{
/* only with deflecting set */
if (ob->pd && ob->pd->deflect) {
- const MVert *mvert = NULL;
- const MVert *mprevvert = NULL;
+ const float(*positions)[3] = NULL;
+ const float(*positions_prev)[3] = NULL;
const MVertTri *vt = NULL;
const ccdf_minmax *mima = NULL;
if (ccdm) {
- mvert = ccdm->mvert;
- mprevvert = ccdm->mprevvert;
+ positions = ccdm->positions;
+ positions_prev = ccdm->positions_prev;
vt = ccdm->tri;
mima = ccdm->mima;
a = ccdm->tri_num;
@@ -1373,21 +1373,21 @@ static int sb_detect_edge_collisionCached(const float edge_v1[3],
continue;
}
- if (mvert) {
+ if (positions) {
- copy_v3_v3(nv1, mvert[vt->tri[0]].co);
- copy_v3_v3(nv2, mvert[vt->tri[1]].co);
- copy_v3_v3(nv3, mvert[vt->tri[2]].co);
+ copy_v3_v3(nv1, positions[vt->tri[0]]);
+ copy_v3_v3(nv2, positions[vt->tri[1]]);
+ copy_v3_v3(nv3, positions[vt->tri[2]]);
- if (mprevvert) {
+ if (positions_prev) {
mul_v3_fl(nv1, time);
- madd_v3_v3fl(nv1, mprevvert[vt->tri[0]].co, 1.0f - time);
+ madd_v3_v3fl(nv1, positions_prev[vt->tri[0]], 1.0f - time);
mul_v3_fl(nv2, time);
- madd_v3_v3fl(nv2, mprevvert[vt->tri[1]].co, 1.0f - time);
+ madd_v3_v3fl(nv2, positions_prev[vt->tri[1]], 1.0f - time);
mul_v3_fl(nv3, time);
- madd_v3_v3fl(nv3, mprevvert[vt->tri[2]].co, 1.0f - time);
+ madd_v3_v3fl(nv3, positions_prev[vt->tri[2]], 1.0f - time);
}
}
@@ -1635,14 +1635,14 @@ static int sb_detect_vertex_collisionCached(float opco[3],
{
/* only with deflecting set */
if (ob->pd && ob->pd->deflect) {
- const MVert *mvert = NULL;
- const MVert *mprevvert = NULL;
+ const float(*positions)[3] = NULL;
+ const float(*positions_prev)[3] = NULL;
const MVertTri *vt = NULL;
const ccdf_minmax *mima = NULL;
if (ccdm) {
- mvert = ccdm->mvert;
- mprevvert = ccdm->mprevvert;
+ positions = ccdm->positions;
+ positions_prev = ccdm->positions_prev;
vt = ccdm->tri;
mima = ccdm->mima;
a = ccdm->tri_num;
@@ -1686,30 +1686,30 @@ static int sb_detect_vertex_collisionCached(float opco[3],
continue;
}
- if (mvert) {
+ if (positions) {
- copy_v3_v3(nv1, mvert[vt->tri[0]].co);
- copy_v3_v3(nv2, mvert[vt->tri[1]].co);
- copy_v3_v3(nv3, mvert[vt->tri[2]].co);
+ copy_v3_v3(nv1, positions[vt->tri[0]]);
+ copy_v3_v3(nv2, positions[vt->tri[1]]);
+ copy_v3_v3(nv3, positions[vt->tri[2]]);
- if (mprevvert) {
+ if (positions_prev) {
/* Grab the average speed of the collider vertices before we spoil nvX
* humm could be done once a SB steps but then we' need to store that too
* since the AABB reduced probability to get here drastically
* it might be a nice tradeoff CPU <--> memory.
*/
- sub_v3_v3v3(vv1, nv1, mprevvert[vt->tri[0]].co);
- sub_v3_v3v3(vv2, nv2, mprevvert[vt->tri[1]].co);
- sub_v3_v3v3(vv3, nv3, mprevvert[vt->tri[2]].co);
+ sub_v3_v3v3(vv1, nv1, positions_prev[vt->tri[0]]);
+ sub_v3_v3v3(vv2, nv2, positions_prev[vt->tri[1]]);
+ sub_v3_v3v3(vv3, nv3, positions_prev[vt->tri[2]]);
mul_v3_fl(nv1, time);
- madd_v3_v3fl(nv1, mprevvert[vt->tri[0]].co, 1.0f - time);
+ madd_v3_v3fl(nv1, positions_prev[vt->tri[0]], 1.0f - time);
mul_v3_fl(nv2, time);
- madd_v3_v3fl(nv2, mprevvert[vt->tri[1]].co, 1.0f - time);
+ madd_v3_v3fl(nv2, positions_prev[vt->tri[1]], 1.0f - time);
mul_v3_fl(nv3, time);
- madd_v3_v3fl(nv3, mprevvert[vt->tri[2]].co, 1.0f - time);
+ madd_v3_v3fl(nv3, positions_prev[vt->tri[2]], 1.0f - time);
}
}
@@ -1743,7 +1743,7 @@ static int sb_detect_vertex_collisionCached(float opco[3],
deflected = 2;
}
}
- if ((mprevvert) && (*damp > 0.0f)) {
+ if ((positions_prev) && (*damp > 0.0f)) {
choose_winner(ve, opco, nv1, nv2, nv3, vv1, vv2, vv3);
add_v3_v3(avel, ve);
cavel++;
@@ -2632,7 +2632,7 @@ static void springs_from_mesh(Object *ob)
BodyPoint *bp;
int a;
float scale = 1.0f;
- const MVert *verts = BKE_mesh_verts(me);
+ const float(*positions)[3] = BKE_mesh_positions(me);
sb = ob->soft;
if (me && sb) {
@@ -2643,7 +2643,7 @@ static void springs_from_mesh(Object *ob)
if (me->totvert) {
bp = ob->soft->bpoint;
for (a = 0; a < me->totvert; a++, bp++) {
- copy_v3_v3(bp->origS, verts[a].co);
+ copy_v3_v3(bp->origS, positions[a]);
mul_m4_v3(ob->object_to_world, bp->origS);
}
}
@@ -2755,7 +2755,7 @@ static void mesh_faces_to_scratch(Object *ob)
MLoopTri *looptri, *lt;
BodyFace *bodyface;
int a;
- const MVert *verts = BKE_mesh_verts(me);
+ const float(*positions)[3] = BKE_mesh_positions(me);
const MPoly *polys = BKE_mesh_polys(me);
const MLoop *loops = BKE_mesh_loops(me);
@@ -2763,7 +2763,7 @@ static void mesh_faces_to_scratch(Object *ob)
sb->scratch->totface = poly_to_tri_count(me->totpoly, me->totloop);
looptri = lt = MEM_mallocN(sizeof(*looptri) * sb->scratch->totface, __func__);
- BKE_mesh_recalc_looptri(loops, polys, verts, me->totloop, me->totpoly, looptri);
+ BKE_mesh_recalc_looptri(loops, polys, positions, me->totloop, me->totpoly, looptri);
bodyface = sb->scratch->bodyface = MEM_mallocN(sizeof(BodyFace) * sb->scratch->totface,
"SB_body_Faces");
diff --git a/source/blender/blenkernel/intern/subdiv_converter_mesh.c b/source/blender/blenkernel/intern/subdiv_converter_mesh.c
index aabed2cea28..2ae8f7dd534 100644
--- a/source/blender/blenkernel/intern/subdiv_converter_mesh.c
+++ b/source/blender/blenkernel/intern/subdiv_converter_mesh.c
@@ -34,7 +34,7 @@
typedef struct ConverterStorage {
SubdivSettings settings;
const Mesh *mesh;
- const MVert *verts;
+ const float (*positions)[3];
const MEdge *edges;
const MPoly *polys;
const MLoop *loops;
@@ -395,7 +395,7 @@ static void init_user_data(OpenSubdiv_Converter *converter,
ConverterStorage *user_data = MEM_mallocN(sizeof(ConverterStorage), __func__);
user_data->settings = *settings;
user_data->mesh = mesh;
- user_data->verts = BKE_mesh_verts(mesh);
+ user_data->positions = BKE_mesh_positions(mesh);
user_data->edges = BKE_mesh_edges(mesh);
user_data->polys = BKE_mesh_polys(mesh);
user_data->loops = BKE_mesh_loops(mesh);
diff --git a/source/blender/blenkernel/intern/subdiv_eval.c b/source/blender/blenkernel/intern/subdiv_eval.c
index e6f24aa6ff8..97c8d08589b 100644
--- a/source/blender/blenkernel/intern/subdiv_eval.c
+++ b/source/blender/blenkernel/intern/subdiv_eval.c
@@ -81,7 +81,8 @@ static void set_coarse_positions(Subdiv *subdiv,
const Mesh *mesh,
const float (*coarse_vertex_cos)[3])
{
- const MVert *mvert = BKE_mesh_verts(mesh);
+ const float (*positions)[3]
+ = BKE_mesh_positions(mesh);
const MPoly *mpoly = BKE_mesh_polys(mesh);
const MLoop *mloop = BKE_mesh_loops(mesh);
/* Mark vertices which needs new coordinates. */
@@ -109,8 +110,7 @@ static void set_coarse_positions(Subdiv *subdiv,
vertex_co = coarse_vertex_cos[vertex_index];
}
else {
- const MVert *vertex = &mvert[vertex_index];
- vertex_co = vertex->co;
+ vertex_co = positions[vertex_index];
}
copy_v3_v3(&buffer[manifold_vertex_index][0], vertex_co);
manifold_vertex_index++;
diff --git a/source/blender/blenkernel/intern/subdiv_mesh.cc b/source/blender/blenkernel/intern/subdiv_mesh.cc
index e1c434f2b2e..b9b8382058d 100644
--- a/source/blender/blenkernel/intern/subdiv_mesh.cc
+++ b/source/blender/blenkernel/intern/subdiv_mesh.cc
@@ -28,6 +28,7 @@
#include "MEM_guardedalloc.h"
+using blender::float3;
using blender::Span;
/* -------------------------------------------------------------------- */
@@ -37,14 +38,14 @@ using blender::Span;
struct SubdivMeshContext {
const SubdivToMeshSettings *settings;
const Mesh *coarse_mesh;
- const MVert *coarse_verts;
+ const float (*coarse_positions)[3];
const MEdge *coarse_edges;
const MPoly *coarse_polys;
const MLoop *coarse_loops;
Subdiv *subdiv;
Mesh *subdiv_mesh;
- MVert *subdiv_verts;
+ float3 *subdiv_positions;
MEdge *subdiv_edges;
MPoly *subdiv_polys;
MLoop *subdiv_loops;
@@ -83,7 +84,7 @@ static void subdiv_mesh_ctx_cache_uv_layers(SubdivMeshContext *ctx)
static void subdiv_mesh_ctx_cache_custom_data_layers(SubdivMeshContext *ctx)
{
Mesh *subdiv_mesh = ctx->subdiv_mesh;
- ctx->subdiv_verts = BKE_mesh_verts_for_write(subdiv_mesh);
+ ctx->subdiv_positions = subdiv_mesh->positions_for_write().data();
ctx->subdiv_edges = BKE_mesh_edges_for_write(subdiv_mesh);
ctx->subdiv_polys = BKE_mesh_polys_for_write(subdiv_mesh);
ctx->subdiv_loops = BKE_mesh_loops_for_write(subdiv_mesh);
@@ -485,18 +486,17 @@ static void subdiv_accumulate_vertex_displacement(SubdivMeshContext *ctx,
const int ptex_face_index,
const float u,
const float v,
- MVert *subdiv_vert)
+ const int subdiv_vertex_index)
{
/* Accumulate displacement. */
Subdiv *subdiv = ctx->subdiv;
- const int subdiv_vertex_index = subdiv_vert - ctx->subdiv_verts;
float dummy_P[3], dPdu[3], dPdv[3], D[3];
BKE_subdiv_eval_limit_point_and_derivatives(subdiv, ptex_face_index, u, v, dummy_P, dPdu, dPdv);
/* NOTE: The subdivided mesh is allocated in this module, and its vertices are kept at zero
* locations as a default calloc(). */
BKE_subdiv_eval_displacement(subdiv, ptex_face_index, u, v, dPdu, dPdv, D);
- add_v3_v3(subdiv_vert->co, D);
+ ctx->subdiv_positions[subdiv_vertex_index] += D;
if (ctx->accumulated_counters) {
++ctx->accumulated_counters[subdiv_vertex_index];
@@ -541,23 +541,20 @@ static bool subdiv_mesh_topology_info(const SubdivForeachContext *foreach_contex
* \{ */
static void subdiv_vertex_data_copy(const SubdivMeshContext *ctx,
- const MVert *coarse_vertex,
- MVert *subdiv_vertex)
+ const int coarse_vertex_index,
+ const int subdiv_vertex_index)
{
const Mesh *coarse_mesh = ctx->coarse_mesh;
- const int coarse_vertex_index = coarse_vertex - ctx->coarse_verts;
- const int subdiv_vertex_index = subdiv_vertex - ctx->subdiv_verts;
CustomData_copy_data(
&coarse_mesh->vdata, &ctx->subdiv_mesh->vdata, coarse_vertex_index, subdiv_vertex_index, 1);
}
static void subdiv_vertex_data_interpolate(const SubdivMeshContext *ctx,
- MVert *subdiv_vertex,
+ const int subdiv_vertex_index,
const VerticesForInterpolation *vertex_interpolation,
const float u,
const float v)
{
- const int subdiv_vertex_index = subdiv_vertex - ctx->subdiv_verts;
const float weights[4] = {(1.0f - u) * (1.0f - v), u * (1.0f - v), u * v, (1.0f - u) * v};
CustomData_interp(vertex_interpolation->vertex_data,
&ctx->subdiv_mesh->vdata,
@@ -575,23 +572,23 @@ static void evaluate_vertex_and_apply_displacement_copy(const SubdivMeshContext
const int ptex_face_index,
const float u,
const float v,
- const MVert *coarse_vert,
- MVert *subdiv_vert)
+ const int coarse_vertex_index,
+ const int subdiv_vertex_index)
{
- const int subdiv_vertex_index = subdiv_vert - ctx->subdiv_verts;
+ float3 &subdiv_position = ctx->subdiv_positions[subdiv_vertex_index];
/* Displacement is accumulated in subdiv vertex position.
* Needs to be backed up before copying data from original vertex. */
float D[3] = {0.0f, 0.0f, 0.0f};
if (ctx->have_displacement) {
const float inv_num_accumulated = 1.0f / ctx->accumulated_counters[subdiv_vertex_index];
- copy_v3_v3(D, subdiv_vert->co);
+ copy_v3_v3(D, subdiv_position);
mul_v3_fl(D, inv_num_accumulated);
}
/* Copy custom data and evaluate position. */
- subdiv_vertex_data_copy(ctx, coarse_vert, subdiv_vert);
- BKE_subdiv_eval_limit_point(ctx->subdiv, ptex_face_index, u, v, subdiv_vert->co);
+ subdiv_vertex_data_copy(ctx, coarse_vertex_index, subdiv_vertex_index);
+ BKE_subdiv_eval_limit_point(ctx->subdiv, ptex_face_index, u, v, subdiv_position);
/* Apply displacement. */
- add_v3_v3(subdiv_vert->co, D);
+ subdiv_position += D;
/* Evaluate undeformed texture coordinate. */
subdiv_vertex_orco_evaluate(ctx, ptex_face_index, u, v, subdiv_vertex_index);
/* Remove face-dot flag. This can happen if there is more than one subsurf modifier. */
@@ -604,22 +601,22 @@ static void evaluate_vertex_and_apply_displacement_interpolate(
const float u,
const float v,
VerticesForInterpolation *vertex_interpolation,
- MVert *subdiv_vert)
+ const int subdiv_vertex_index)
{
- const int subdiv_vertex_index = subdiv_vert - ctx->subdiv_verts;
+ float3 &subdiv_position = ctx->subdiv_positions[subdiv_vertex_index];
/* Displacement is accumulated in subdiv vertex position.
* Needs to be backed up before copying data from original vertex. */
float D[3] = {0.0f, 0.0f, 0.0f};
if (ctx->have_displacement) {
const float inv_num_accumulated = 1.0f / ctx->accumulated_counters[subdiv_vertex_index];
- copy_v3_v3(D, subdiv_vert->co);
+ copy_v3_v3(D, subdiv_position);
mul_v3_fl(D, inv_num_accumulated);
}
/* Interpolate custom data and evaluate position. */
- subdiv_vertex_data_interpolate(ctx, subdiv_vert, vertex_interpolation, u, v);
- BKE_subdiv_eval_limit_point(ctx->subdiv, ptex_face_index, u, v, subdiv_vert->co);
+ subdiv_vertex_data_interpolate(ctx, subdiv_vertex_index, vertex_interpolation, u, v);
+ BKE_subdiv_eval_limit_point(ctx->subdiv, ptex_face_index, u, v, subdiv_position);
/* Apply displacement. */
- add_v3_v3(subdiv_vert->co, D);
+ add_v3_v3(subdiv_position, D);
/* Evaluate undeformed texture coordinate. */
subdiv_vertex_orco_evaluate(ctx, ptex_face_index, u, v, subdiv_vertex_index);
}
@@ -633,8 +630,7 @@ static void subdiv_mesh_vertex_displacement_every_corner_or_edge(
const int subdiv_vertex_index)
{
SubdivMeshContext *ctx = static_cast<SubdivMeshContext *>(foreach_context->user_data);
- MVert *subdiv_vert = &ctx->subdiv_verts[subdiv_vertex_index];
- subdiv_accumulate_vertex_displacement(ctx, ptex_face_index, u, v, subdiv_vert);
+ subdiv_accumulate_vertex_displacement(ctx, ptex_face_index, u, v, subdiv_vertex_index);
}
static void subdiv_mesh_vertex_displacement_every_corner(
@@ -678,10 +674,8 @@ static void subdiv_mesh_vertex_corner(const SubdivForeachContext *foreach_contex
{
BLI_assert(coarse_vertex_index != ORIGINDEX_NONE);
SubdivMeshContext *ctx = static_cast<SubdivMeshContext *>(foreach_context->user_data);
- const MVert *coarse_vert = &ctx->coarse_verts[coarse_vertex_index];
- MVert *subdiv_vert = &ctx->subdiv_verts[subdiv_vertex_index];
evaluate_vertex_and_apply_displacement_copy(
- ctx, ptex_face_index, u, v, coarse_vert, subdiv_vert);
+ ctx, ptex_face_index, u, v, coarse_vertex_index, subdiv_vertex_index);
}
static void subdiv_mesh_ensure_vertex_interpolation(SubdivMeshContext *ctx,
@@ -725,10 +719,9 @@ static void subdiv_mesh_vertex_edge(const SubdivForeachContext *foreach_context,
SubdivMeshContext *ctx = static_cast<SubdivMeshContext *>(foreach_context->user_data);
SubdivMeshTLS *tls = static_cast<SubdivMeshTLS *>(tls_v);
const MPoly *coarse_poly = &ctx->coarse_polys[coarse_poly_index];
- MVert *subdiv_vert = &ctx->subdiv_verts[subdiv_vertex_index];
subdiv_mesh_ensure_vertex_interpolation(ctx, tls, coarse_poly, coarse_corner);
evaluate_vertex_and_apply_displacement_interpolate(
- ctx, ptex_face_index, u, v, &tls->vertex_interpolation, subdiv_vert);
+ ctx, ptex_face_index, u, v, &tls->vertex_interpolation, subdiv_vertex_index);
}
static bool subdiv_mesh_is_center_vertex(const MPoly *coarse_poly, const float u, const float v)
@@ -771,10 +764,10 @@ static void subdiv_mesh_vertex_inner(const SubdivForeachContext *foreach_context
Subdiv *subdiv = ctx->subdiv;
const MPoly *coarse_poly = &ctx->coarse_polys[coarse_poly_index];
Mesh *subdiv_mesh = ctx->subdiv_mesh;
- MVert *subdiv_vert = &ctx->subdiv_verts[subdiv_vertex_index];
+ float3 &subdiv_position = ctx->subdiv_positions[subdiv_vertex_index];
subdiv_mesh_ensure_vertex_interpolation(ctx, tls, coarse_poly, coarse_corner);
- subdiv_vertex_data_interpolate(ctx, subdiv_vert, &tls->vertex_interpolation, u, v);
- BKE_subdiv_eval_final_point(subdiv, ptex_face_index, u, v, subdiv_vert->co);
+ subdiv_vertex_data_interpolate(ctx, subdiv_vertex_index, &tls->vertex_interpolation, u, v);
+ BKE_subdiv_eval_final_point(subdiv, ptex_face_index, u, v, subdiv_position);
subdiv_mesh_tag_center_vertex(coarse_poly, subdiv_vertex_index, u, v, subdiv_mesh);
subdiv_vertex_orco_evaluate(ctx, ptex_face_index, u, v, subdiv_vertex_index);
}
@@ -965,9 +958,7 @@ static void subdiv_mesh_vertex_loose(const SubdivForeachContext *foreach_context
const int subdiv_vertex_index)
{
SubdivMeshContext *ctx = static_cast<SubdivMeshContext *>(foreach_context->user_data);
- const MVert *coarse_vertex = &ctx->coarse_verts[coarse_vertex_index];
- MVert *subdiv_vertex = &ctx->subdiv_verts[subdiv_vertex_index];
- subdiv_vertex_data_copy(ctx, coarse_vertex, subdiv_vertex);
+ subdiv_vertex_data_copy(ctx, coarse_vertex_index, subdiv_vertex_index);
}
/* Get neighbor edges of the given one.
@@ -1011,21 +1002,21 @@ static void find_edge_neighbors(const MEdge *coarse_edges,
}
}
-static void points_for_loose_edges_interpolation_get(const MVert *coarse_mvert,
+static void points_for_loose_edges_interpolation_get(const float (*coarse_positions)[3],
const MEdge *coarse_edge,
const MEdge *neighbors[2],
float points_r[4][3])
{
/* Middle points corresponds to the edge. */
- copy_v3_v3(points_r[1], coarse_mvert[coarse_edge->v1].co);
- copy_v3_v3(points_r[2], coarse_mvert[coarse_edge->v2].co);
+ copy_v3_v3(points_r[1], coarse_positions[coarse_edge->v1]);
+ copy_v3_v3(points_r[2], coarse_positions[coarse_edge->v2]);
/* Start point, duplicate from edge start if no neighbor. */
if (neighbors[0] != nullptr) {
if (neighbors[0]->v1 == coarse_edge->v1) {
- copy_v3_v3(points_r[0], coarse_mvert[neighbors[0]->v2].co);
+ copy_v3_v3(points_r[0], coarse_positions[neighbors[0]->v2]);
}
else {
- copy_v3_v3(points_r[0], coarse_mvert[neighbors[0]->v1].co);
+ copy_v3_v3(points_r[0], coarse_positions[neighbors[0]->v1]);
}
}
else {
@@ -1035,10 +1026,10 @@ static void points_for_loose_edges_interpolation_get(const MVert *coarse_mvert,
/* End point, duplicate from edge end if no neighbor. */
if (neighbors[1] != nullptr) {
if (neighbors[1]->v1 == coarse_edge->v2) {
- copy_v3_v3(points_r[3], coarse_mvert[neighbors[1]->v2].co);
+ copy_v3_v3(points_r[3], coarse_positions[neighbors[1]->v2]);
}
else {
- copy_v3_v3(points_r[3], coarse_mvert[neighbors[1]->v1].co);
+ copy_v3_v3(points_r[3], coarse_positions[neighbors[1]->v1]);
}
}
else {
@@ -1047,7 +1038,7 @@ static void points_for_loose_edges_interpolation_get(const MVert *coarse_mvert,
}
}
-void BKE_subdiv_mesh_interpolate_position_on_edge(const MVert *coarse_verts,
+void BKE_subdiv_mesh_interpolate_position_on_edge(const float (*coarse_positions)[3],
const MEdge *coarse_edges,
const MeshElemMap *vert_to_edge_map,
const int coarse_edge_index,
@@ -1057,16 +1048,14 @@ void BKE_subdiv_mesh_interpolate_position_on_edge(const MVert *coarse_verts,
{
const MEdge *coarse_edge = &coarse_edges[coarse_edge_index];
if (is_simple) {
- const MVert *vert_1 = &coarse_verts[coarse_edge->v1];
- const MVert *vert_2 = &coarse_verts[coarse_edge->v2];
- interp_v3_v3v3(pos_r, vert_1->co, vert_2->co, u);
+ interp_v3_v3v3(pos_r, coarse_positions[coarse_edge->v1], coarse_positions[coarse_edge->v2], u);
}
else {
/* Find neighbors of the coarse edge. */
const MEdge *neighbors[2];
find_edge_neighbors(coarse_edges, vert_to_edge_map, coarse_edge_index, neighbors);
float points[4][3];
- points_for_loose_edges_interpolation_get(coarse_verts, coarse_edge, neighbors, points);
+ points_for_loose_edges_interpolation_get(coarse_positions, coarse_edge, neighbors, points);
float weights[4];
key_curve_position_weights(u, weights, KEY_BSPLINE);
interp_v3_v3v3v3v3(pos_r, points[0], points[1], points[2], points[3], weights);
@@ -1127,14 +1116,13 @@ static void subdiv_mesh_vertex_of_loose_edge(const SubdivForeachContext *foreach
subdiv_mesh_vertex_of_loose_edge_interpolate(ctx, coarse_edge, u, subdiv_vertex_index);
}
/* Interpolate coordinate. */
- MVert *subdiv_vertex = &ctx->subdiv_verts[subdiv_vertex_index];
- BKE_subdiv_mesh_interpolate_position_on_edge(ctx->coarse_verts,
+ BKE_subdiv_mesh_interpolate_position_on_edge(ctx->coarse_positions,
ctx->coarse_edges,
ctx->vert_to_edge_map,
coarse_edge_index,
is_simple,
u,
- subdiv_vertex->co);
+ ctx->subdiv_positions[subdiv_vertex_index]);
}
/** \} */
@@ -1195,7 +1183,7 @@ Mesh *BKE_subdiv_to_mesh(Subdiv *subdiv,
subdiv_context.settings = settings;
subdiv_context.coarse_mesh = coarse_mesh;
- subdiv_context.coarse_verts = BKE_mesh_verts(coarse_mesh);
+ subdiv_context.coarse_positions = BKE_mesh_positions(coarse_mesh);
subdiv_context.coarse_edges = BKE_mesh_edges(coarse_mesh);
subdiv_context.coarse_polys = BKE_mesh_polys(coarse_mesh);
subdiv_context.coarse_loops = BKE_mesh_loops(coarse_mesh);
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index 80fb637b76e..acfec5b3122 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -562,9 +562,8 @@ static void ss_sync_ccg_from_derivedmesh(CCGSubSurf *ss,
CCGVertHDL *fVerts = NULL;
BLI_array_declare(fVerts);
#endif
- MVert *mvert = dm->getVertArray(dm);
+ float(*positions)[3] = (float(*)[3])dm->getVertArray(dm);
MEdge *medge = dm->getEdgeArray(dm);
- MVert *mv;
MEdge *me;
MLoop *mloop = dm->getLoopArray(dm), *ml;
MPoly *mpoly = dm->getPolyArray(dm), *mp;
@@ -575,16 +574,15 @@ static void ss_sync_ccg_from_derivedmesh(CCGSubSurf *ss,
ccgSubSurf_initFullSync(ss);
- mv = mvert;
index = (int *)dm->getVertDataArray(dm, CD_ORIGINDEX);
- for (i = 0; i < totvert; i++, mv++) {
+ for (i = 0; i < totvert; i++) {
CCGVert *v;
if (vertexCos) {
ccgSubSurf_syncVert(ss, POINTER_FROM_INT(i), vertexCos[i], 0, &v);
}
else {
- ccgSubSurf_syncVert(ss, POINTER_FROM_INT(i), mv->co, 0, &v);
+ ccgSubSurf_syncVert(ss, POINTER_FROM_INT(i), positions[i], 0, &v);
}
((int *)ccgSubSurf_getVertUserData(ss, v))[1] = (index) ? *index++ : i;
@@ -877,12 +875,12 @@ static void ccgDM_getFinalVertNo(DerivedMesh *dm, int vertNum, float r_no[3])
}
/* utility function */
-BLI_INLINE void ccgDM_to_MVert(MVert *mv, const CCGKey *key, CCGElem *elem)
+BLI_INLINE void ccgDM_to_MVert(float mv[3], const CCGKey *key, CCGElem *elem)
{
- copy_v3_v3(mv->co, CCG_elem_co(key, elem));
+ copy_v3_v3(mv, CCG_elem_co(key, elem));
}
-static void ccgDM_copyFinalVertArray(DerivedMesh *dm, MVert *mvert)
+static void ccgDM_copyFinalVertArray(DerivedMesh *dm, float (*r_positions)[3])
{
CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm;
CCGSubSurf *ss = ccgdm->ss;
@@ -902,12 +900,12 @@ static void ccgDM_copyFinalVertArray(DerivedMesh *dm, MVert *mvert)
int x, y, S, numVerts = ccgSubSurf_getFaceNumVerts(f);
vd = ccgSubSurf_getFaceCenterData(f);
- ccgDM_to_MVert(&mvert[i++], &key, vd);
+ ccgDM_to_MVert(r_positions[i++], &key, vd);
for (S = 0; S < numVerts; S++) {
for (x = 1; x < gridSize - 1; x++) {
vd = ccgSubSurf_getFaceGridEdgeData(ss, f, S, x);
- ccgDM_to_MVert(&mvert[i++], &key, vd);
+ ccgDM_to_MVert(r_positions[i++], &key, vd);
}
}
@@ -915,7 +913,7 @@ static void ccgDM_copyFinalVertArray(DerivedMesh *dm, MVert *mvert)
for (y = 1; y < gridSize - 1; y++) {
for (x = 1; x < gridSize - 1; x++) {
vd = ccgSubSurf_getFaceGridData(ss, f, S, x, y);
- ccgDM_to_MVert(&mvert[i++], &key, vd);
+ ccgDM_to_MVert(r_positions[i++], &key, vd);
}
}
}
@@ -931,7 +929,7 @@ static void ccgDM_copyFinalVertArray(DerivedMesh *dm, MVert *mvert)
* unit length. This is most likely caused by edges with no faces which are now zeroed out,
* see comment in: `ccgSubSurf__calcVertNormals()`. */
vd = ccgSubSurf_getEdgeData(ss, e, x);
- ccgDM_to_MVert(&mvert[i++], &key, vd);
+ ccgDM_to_MVert(r_positions[i++], &key, vd);
}
}
@@ -940,7 +938,7 @@ static void ccgDM_copyFinalVertArray(DerivedMesh *dm, MVert *mvert)
CCGVert *v = ccgdm->vertMap[index].vert;
vd = ccgSubSurf_getVertData(ss, v);
- ccgDM_to_MVert(&mvert[i++], &key, vd);
+ ccgDM_to_MVert(r_positions[i++], &key, vd);
}
}
diff --git a/source/blender/blenkernel/intern/volume_to_mesh.cc b/source/blender/blenkernel/intern/volume_to_mesh.cc
index f3bb8726b4f..bc038734eda 100644
--- a/source/blender/blenkernel/intern/volume_to_mesh.cc
+++ b/source/blender/blenkernel/intern/volume_to_mesh.cc
@@ -113,15 +113,12 @@ void fill_mesh_from_openvdb_data(const Span<openvdb::Vec3s> vdb_verts,
const int vert_offset,
const int poly_offset,
const int loop_offset,
- MutableSpan<MVert> verts,
+ MutableSpan<float3> positions,
MutableSpan<MPoly> polys,
MutableSpan<MLoop> loops)
{
/* Write vertices. */
- for (const int i : vdb_verts.index_range()) {
- const blender::float3 co = blender::float3(vdb_verts[i].asV());
- copy_v3_v3(verts[vert_offset + i].co, co);
- }
+ positions.slice(vert_offset, vdb_verts.size()).copy_from(vdb_verts.cast<float3>());
/* Write triangles. */
for (const int i : vdb_tris.index_range()) {
@@ -178,7 +175,7 @@ Mesh *volume_to_mesh(const openvdb::GridBase &grid,
0,
0,
0,
- mesh->verts_for_write(),
+ mesh->positions_for_write(),
mesh->polys_for_write(),
mesh->loops_for_write());
diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c
index 0b543ad735b..328d8654a94 100644
--- a/source/blender/blenloader/intern/versioning_250.c
+++ b/source/blender/blenloader/intern/versioning_250.c
@@ -996,9 +996,9 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain)
if ((key = blo_do_versions_newlibadr(fd, lib, me->key)) && key->refkey) {
data = key->refkey->data;
tot = MIN2(me->totvert, key->refkey->totelem);
- MVert *verts = BKE_mesh_verts_for_write(me);
+ MVert *verts = (MVert *)CustomData_get_layer(&me->vdata, CD_MVERT);
for (a = 0; a < tot; a++, data += 3) {
- copy_v3_v3(verts[a].co, data);
+ copy_v3_v3(verts[a].co_legacy, data);
}
}
}
diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c
index b8161a9dc40..4a175f3ae98 100644
--- a/source/blender/blenloader/intern/versioning_290.c
+++ b/source/blender/blenloader/intern/versioning_290.c
@@ -822,7 +822,7 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
if (mp->totloop == 2) {
bool changed;
BKE_mesh_validate_arrays(me,
- BKE_mesh_verts_for_write(me),
+ BKE_mesh_positions_for_write(me),
me->totvert,
BKE_mesh_edges_for_write(me),
me->totedge,
diff --git a/source/blender/blenloader/intern/versioning_400.cc b/source/blender/blenloader/intern/versioning_400.cc
index 2616bb890a3..f8d4ffb776e 100644
--- a/source/blender/blenloader/intern/versioning_400.cc
+++ b/source/blender/blenloader/intern/versioning_400.cc
@@ -27,6 +27,7 @@ static void version_mesh_legacy_to_struct_of_array_format(Mesh &mesh)
BKE_mesh_legacy_bevel_weight_to_layers(&mesh);
BKE_mesh_legacy_face_set_to_generic(&mesh);
BKE_mesh_legacy_edge_crease_to_layers(&mesh);
+ BKE_mesh_legacy_convert_verts_to_positions(&mesh);
}
void blo_do_versions_400(FileData * /*fd*/, Library * /*lib*/, Main *bmain)
diff --git a/source/blender/bmesh/intern/bmesh_mesh_convert.cc b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
index d65cac08db8..369e828f260 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_convert.cc
+++ b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
@@ -37,7 +37,7 @@
* But basics are as follows.
*
* - Vertex locations (possibly modified from initial active key-block)
- * are copied directly into #MVert.co
+ * are copied directly into the mesh position attribute.
* (special confusing note that these may be restored later, when editing the 'Basis', read on).
* - if the 'Key' is relative, and the active key-block is the basis for ANY other key-blocks -
* get an array of offsets between the new vertex locations and the original shape key
@@ -105,6 +105,7 @@
static CLG_LogRef LOG = {"bmesh.mesh.convert"};
using blender::Array;
+using blender::float3;
using blender::IndexRange;
using blender::MutableSpan;
using blender::Span;
@@ -303,11 +304,11 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar
const int *material_indices = (const int *)CustomData_get_layer_named(
&me->pdata, CD_PROP_INT32, "material_index");
- Span<MVert> mvert = me->verts();
+ const Span<float3> positions = me->positions();
Array<BMVert *> vtable(me->totvert);
- for (const int i : mvert.index_range()) {
+ for (const int i : positions.index_range()) {
BMVert *v = vtable[i] = BM_vert_create(
- bm, keyco ? keyco[i] : mvert[i].co, nullptr, BM_CREATE_SKIP_CD);
+ bm, keyco ? keyco[i] : positions[i], nullptr, BM_CREATE_SKIP_CD);
BM_elem_index_set(v, i); /* set_ok */
if (hide_vert && hide_vert[i]) {
@@ -614,16 +615,16 @@ static int bm_to_mesh_shape_layer_index_from_kb(BMesh *bm, KeyBlock *currkey)
*
* \param bm: The source BMesh.
* \param key: The destination key.
- * \param mvert: The destination vertex array (in some situations it's coordinates are updated).
+ * \param positions: The destination vertex array (in some situations its coordinates are updated).
* \param active_shapekey_to_mvert: When editing a non-basis shape key, the coordinates for the
- * basis are typically copied into the `mvert` array since it makes sense for the meshes
+ * basis are typically copied into the `positions` array since it makes sense for the meshes
* vertex coordinates to match the "Basis" key.
- * When enabled, skip this step and copy #BMVert.co directly to #MVert.co,
+ * When enabled, skip this step and copy #BMVert.co directly to the mesh position.
* See #BMeshToMeshParams.active_shapekey_to_mvert doc-string.
*/
static void bm_to_mesh_shape(BMesh *bm,
Key *key,
- MutableSpan<MVert> mvert,
+ MutableSpan<float3> positions,
const bool active_shapekey_to_mvert)
{
KeyBlock *actkey = static_cast<KeyBlock *>(BLI_findlink(&key->block, bm->shapenr - 1));
@@ -685,7 +686,7 @@ static void bm_to_mesh_shape(BMesh *bm,
/* Check the vertex existed when entering edit-mode (otherwise don't apply an offset). */
if (keyi != ORIGINDEX_NONE) {
float *co_orig = (float *)BM_ELEM_CD_GET_VOID_P(eve, cd_shape_offset);
- /* Could use 'eve->co' or the destination #MVert.co, they're the same at this point. */
+ /* Could use 'eve->co' or the destination position, they're the same at this point. */
sub_v3_v3v3(ofs[i], eve->co, co_orig);
}
else {
@@ -703,7 +704,7 @@ static void bm_to_mesh_shape(BMesh *bm,
* while users might not notice since the shape-key is applied in the viewport,
* exporters for example may still use the underlying coordinates, see: T30771 & T96135.
*
- * Needed when editing any shape that isn't the (`key->refkey`), the vertices in `me->mvert`
+ * Needed when editing any shape that isn't the (`key->refkey`), the vertices in mesh positions
* currently have vertex coordinates set from the current-shape (initialized from #BMVert.co).
* In this case it's important to overwrite these coordinates with the basis-keys coordinates. */
bool update_vertex_coords_from_refkey = false;
@@ -755,7 +756,7 @@ static void bm_to_mesh_shape(BMesh *bm,
keyi = BM_ELEM_CD_GET_INT(eve, cd_shape_keyindex_offset);
if (keyi != ORIGINDEX_NONE) {
float *co_refkey = (float *)BM_ELEM_CD_GET_VOID_P(eve, cd_shape_offset_refkey);
- copy_v3_v3(mvert[i].co, co_refkey);
+ copy_v3_v3(positions[i], co_refkey);
}
}
}
@@ -863,6 +864,7 @@ static void write_fn_to_attribute(blender::bke::MutableAttributeAccessor attribu
static void assert_bmesh_has_no_mesh_only_attributes(const BMesh &bm)
{
(void)bm; /* Unused in the release builds. */
+ BLI_assert(CustomData_get_layer_named(&bm.vdata, CD_PROP_FLOAT3, "position") == nullptr);
/* The "hide" attributes are stored as flags on #BMesh. */
BLI_assert(CustomData_get_layer_named(&bm.vdata, CD_PROP_BOOL, ".hide_vert") == nullptr);
@@ -941,6 +943,7 @@ static void convert_bmesh_selection_flags_to_mesh_attributes(BMesh &bm,
void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMeshParams *params)
{
+ using namespace blender;
BMVert *v, *eve;
BMEdge *e;
BMFace *f;
@@ -977,11 +980,12 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh
CustomData_copy(&bm->pdata, &me->pdata, mask.pmask, CD_SET_DEFAULT, me->totpoly);
}
- CustomData_add_layer(&me->vdata, CD_MVERT, CD_SET_DEFAULT, nullptr, me->totvert);
+ CustomData_add_layer_named(
+ &me->vdata, CD_PROP_FLOAT3, CD_CONSTRUCT, nullptr, me->totvert, "position");
CustomData_add_layer(&me->edata, CD_MEDGE, CD_SET_DEFAULT, nullptr, me->totedge);
CustomData_add_layer(&me->ldata, CD_MLOOP, CD_SET_DEFAULT, nullptr, me->totloop);
CustomData_add_layer(&me->pdata, CD_MPOLY, CD_SET_DEFAULT, nullptr, me->totpoly);
- MutableSpan<MVert> mvert = me->verts_for_write();
+ MutableSpan<float3> positions = me->positions_for_write();
MutableSpan<MEdge> medge = me->edges_for_write();
MutableSpan<MPoly> mpoly = me->polys_for_write();
MutableSpan<MLoop> mloop = me->loops_for_write();
@@ -1000,7 +1004,7 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh
i = 0;
BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
- copy_v3_v3(mvert[i].co, v->co);
+ copy_v3_v3(positions[i], v->co);
if (BM_elem_flag_test(v, BM_ELEM_HIDDEN)) {
need_hide_vert = true;
@@ -1189,7 +1193,7 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh
}
if (me->key) {
- bm_to_mesh_shape(bm, me->key, mvert, params->active_shapekey_to_mvert);
+ bm_to_mesh_shape(bm, me->key, positions, params->active_shapekey_to_mvert);
}
/* Run this even when shape keys aren't used since it may be used for hooks or vertex parents. */
@@ -1226,7 +1230,10 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks *
me->totloop = bm->totloop;
me->totpoly = bm->totface;
- CustomData_add_layer(&me->vdata, CD_MVERT, CD_SET_DEFAULT, nullptr, bm->totvert);
+ if (!CustomData_get_layer_named(&me->vdata, CD_PROP_FLOAT3, "position")) {
+ CustomData_add_layer_named(
+ &me->vdata, CD_PROP_FLOAT3, CD_CONSTRUCT, nullptr, bm->totvert, "position");
+ }
CustomData_add_layer(&me->edata, CD_MEDGE, CD_SET_DEFAULT, nullptr, bm->totedge);
CustomData_add_layer(&me->ldata, CD_MLOOP, CD_SET_DEFAULT, nullptr, bm->totloop);
CustomData_add_layer(&me->pdata, CD_MPOLY, CD_SET_DEFAULT, nullptr, bm->totface);
@@ -1247,7 +1254,7 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks *
BMVert *eve;
BMEdge *eed;
BMFace *efa;
- MutableSpan<MVert> mvert = me->verts_for_write();
+ MutableSpan<float3> positions = me->positions_for_write();
MutableSpan<MEdge> medge = me->edges_for_write();
MutableSpan<MPoly> mpoly = me->polys_for_write();
MutableSpan<MLoop> loops = me->loops_for_write();
@@ -1265,9 +1272,7 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks *
bke::SpanAttributeWriter<bool> hide_vert_attribute;
bke::SpanAttributeWriter<bool> select_vert_attribute;
BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
- MVert *mv = &mvert[i];
-
- copy_v3_v3(mv->co, eve->co);
+ copy_v3_v3(positions[i], eve->co);
BM_elem_index_set(eve, i); /* set_inline */
diff --git a/source/blender/bmesh/intern/bmesh_mesh_convert.h b/source/blender/bmesh/intern/bmesh_mesh_convert.h
index 3f8e9e3dfef..f4c551e9137 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_convert.h
+++ b/source/blender/bmesh/intern/bmesh_mesh_convert.h
@@ -51,8 +51,8 @@ struct BMeshToMeshParams {
*/
bool update_shapekey_indices;
/**
- * Instead of copying the basis shape-key into the #MVert array,
- * copy the #BMVert.co directly to #MVert.co (used for reading undo data).
+ * Instead of copying the basis shape-key into the position array,
+ * copy the #BMVert.co directly to the #Mesh position (used for reading undo data).
*/
bool active_shapekey_to_mvert;
struct CustomData_MeshMasks cd_mask_extra;
diff --git a/source/blender/draw/DRW_pbvh.h b/source/blender/draw/DRW_pbvh.h
index ffd4b92d87b..55f4658f55f 100644
--- a/source/blender/draw/DRW_pbvh.h
+++ b/source/blender/draw/DRW_pbvh.h
@@ -27,7 +27,6 @@ struct Object;
struct Mesh;
struct MLoopTri;
struct CustomData;
-struct MVert;
struct MEdge;
struct MLoop;
struct MPoly;
@@ -41,7 +40,7 @@ typedef struct PBVH_GPU_Args {
struct BMesh *bm;
const struct Mesh *me;
- const struct MVert *mvert;
+ const float (*mesh_positions)[3];
const struct MLoop *mloop;
const struct MPoly *mpoly;
int mesh_verts_num, mesh_faces_num, mesh_grids_num;
diff --git a/source/blender/draw/intern/draw_cache_extract_mesh.cc b/source/blender/draw/intern/draw_cache_extract_mesh.cc
index f533904f355..8ac14c7917b 100644
--- a/source/blender/draw/intern/draw_cache_extract_mesh.cc
+++ b/source/blender/draw/intern/draw_cache_extract_mesh.cc
@@ -368,11 +368,9 @@ static void extract_range_iter_lvert_mesh(void *__restrict userdata,
const ExtractorIterData *data = static_cast<ExtractorIterData *>(userdata);
const MeshRenderData *mr = data->mr;
- const int lvert_index = data->loose_elems[iter];
- const MVert *mv = &((const MVert *)data->elems)[lvert_index];
for (const ExtractorRunData &run_data : data->extractors) {
run_data.extractor->iter_lvert_mesh(
- mr, mv, iter, POINTER_OFFSET(extract_data, run_data.data_offset));
+ mr, iter, POINTER_OFFSET(extract_data, run_data.data_offset));
}
}
@@ -406,7 +404,7 @@ BLI_INLINE void extract_task_range_run_iter(const MeshRenderData *mr,
break;
case MR_ITER_LVERT:
range_data.loose_elems = mr->lverts;
- range_data.elems = is_mesh ? mr->mvert : (void *)mr->bm->vtable;
+ range_data.elems = is_mesh ? mr->positions : (void *)mr->bm->vtable;
func = is_mesh ? extract_range_iter_lvert_mesh : extract_range_iter_lvert_bm;
stop = mr->vert_loose_len;
break;
diff --git a/source/blender/draw/intern/draw_cache_extract_mesh_render_data.cc b/source/blender/draw/intern/draw_cache_extract_mesh_render_data.cc
index f606701ed09..f4ef11ac252 100644
--- a/source/blender/draw/intern/draw_cache_extract_mesh_render_data.cc
+++ b/source/blender/draw/intern/draw_cache_extract_mesh_render_data.cc
@@ -362,7 +362,7 @@ void mesh_render_data_update_normals(MeshRenderData *mr, const eMRDataType data_
MEM_mallocN(sizeof(*mr->loop_normals) * mr->loop_len, __func__));
short(*clnors)[2] = static_cast<short(*)[2]>(
CustomData_get_layer(&mr->me->ldata, CD_CUSTOMLOOPNORMAL));
- BKE_mesh_normals_loop_split(mr->mvert,
+ BKE_mesh_normals_loop_split(reinterpret_cast<const float(*)[3]>(mr->positions),
mr->vert_normals,
mr->vert_len,
mr->medge,
@@ -551,7 +551,7 @@ MeshRenderData *mesh_render_data_create(Object *object,
mr->poly_len = mr->me->totpoly;
mr->tri_len = poly_to_tri_count(mr->poly_len, mr->loop_len);
- mr->mvert = BKE_mesh_verts(mr->me);
+ mr->positions = mr->me->positions().data();
mr->medge = BKE_mesh_edges(mr->me);
mr->mpoly = BKE_mesh_polys(mr->me);
mr->mloop = BKE_mesh_loops(mr->me);
diff --git a/source/blender/draw/intern/draw_cache_impl_subdivision.cc b/source/blender/draw/intern/draw_cache_impl_subdivision.cc
index 6a9e6c126e9..e31ac72c94d 100644
--- a/source/blender/draw/intern/draw_cache_impl_subdivision.cc
+++ b/source/blender/draw/intern/draw_cache_impl_subdivision.cc
@@ -2159,7 +2159,7 @@ void DRW_subdivide_loose_geom(DRWSubdivCache *subdiv_cache, MeshBufferCache *cac
int subd_vert_offset = 0;
/* Subdivide each loose coarse edge. */
- const Span<MVert> coarse_verts = coarse_mesh->verts();
+ const Span<float3> coarse_positions = coarse_mesh->positions();
const Span<MEdge> coarse_edges = coarse_mesh->edges();
int *vert_to_edge_buffer;
@@ -2183,13 +2183,14 @@ void DRW_subdivide_loose_geom(DRWSubdivCache *subdiv_cache, MeshBufferCache *cac
DRWSubdivLooseVertex &subd_v1 = loose_subd_verts[subd_vert_offset];
subd_v1.coarse_vertex_index = (i == 0) ? coarse_edge->v1 : -1u;
const float u1 = i * inv_resolution_1;
- BKE_subdiv_mesh_interpolate_position_on_edge(coarse_verts.data(),
- coarse_edges.data(),
- vert_to_edge_map,
- coarse_edge_index,
- is_simple,
- u1,
- subd_v1.co);
+ BKE_subdiv_mesh_interpolate_position_on_edge(
+ reinterpret_cast<const float(*)[3]>(coarse_positions.data()),
+ coarse_edges.data(),
+ vert_to_edge_map,
+ coarse_edge_index,
+ is_simple,
+ u1,
+ subd_v1.co);
subd_edge.loose_subdiv_v1_index = subd_vert_offset++;
@@ -2197,13 +2198,14 @@ void DRW_subdivide_loose_geom(DRWSubdivCache *subdiv_cache, MeshBufferCache *cac
DRWSubdivLooseVertex &subd_v2 = loose_subd_verts[subd_vert_offset];
subd_v2.coarse_vertex_index = ((i + 1) == resolution - 1) ? coarse_edge->v2 : -1u;
const float u2 = (i + 1) * inv_resolution_1;
- BKE_subdiv_mesh_interpolate_position_on_edge(coarse_verts.data(),
- coarse_edges.data(),
- vert_to_edge_map,
- coarse_edge_index,
- is_simple,
- u2,
- subd_v2.co);
+ BKE_subdiv_mesh_interpolate_position_on_edge(
+ reinterpret_cast<const float(*)[3]>(coarse_positions.data()),
+ coarse_edges.data(),
+ vert_to_edge_map,
+ coarse_edge_index,
+ is_simple,
+ u2,
+ subd_v2.co);
subd_edge.loose_subdiv_v2_index = subd_vert_offset++;
}
@@ -2215,11 +2217,10 @@ void DRW_subdivide_loose_geom(DRWSubdivCache *subdiv_cache, MeshBufferCache *cac
/* Copy the remaining loose_verts. */
for (int i = 0; i < coarse_loose_vert_len; i++) {
const int coarse_vertex_index = cache->loose_geom.verts[i];
- const MVert &coarse_vertex = coarse_verts[coarse_vertex_index];
DRWSubdivLooseVertex &subd_v = loose_subd_verts[subd_vert_offset++];
subd_v.coarse_vertex_index = cache->loose_geom.verts[i];
- copy_v3_v3(subd_v.co, coarse_vertex.co);
+ copy_v3_v3(subd_v.co, coarse_positions[coarse_vertex_index]);
}
subdiv_cache->loose_geom.edges = loose_subd_edges;
diff --git a/source/blender/draw/intern/draw_pbvh.cc b/source/blender/draw/intern/draw_pbvh.cc
index 6c504e63511..0294e230e33 100644
--- a/source/blender/draw/intern/draw_pbvh.cc
+++ b/source/blender/draw/intern/draw_pbvh.cc
@@ -305,7 +305,7 @@ struct PBVHBatches {
if (!(mp->flag & ME_SMOOTH)) {
smooth = true;
- BKE_mesh_calc_poly_normal(mp, args->mloop + mp->loopstart, args->mvert, fno);
+ BKE_mesh_calc_poly_normal(mp, args->mloop + mp->loopstart, args->mesh_positions, fno);
normal_float_to_short_v3(no, fno);
}
else {
@@ -542,7 +542,8 @@ struct PBVHBatches {
case CD_PBVH_CO_TYPE:
foreach_faces(
[&](int /*buffer_i*/, int /*tri_i*/, int vertex_i, const MLoopTri * /*tri*/) {
- *static_cast<float3 *>(GPU_vertbuf_raw_step(&access)) = args->mvert[vertex_i].co;
+ *static_cast<float3 *>(
+ GPU_vertbuf_raw_step(&access)) = args->mesh_positions[vertex_i];
});
break;
case CD_PBVH_NO_TYPE:
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh.hh b/source/blender/draw/intern/mesh_extractors/extract_mesh.hh
index c6230e2695e..c6ab90474de 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh.hh
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh.hh
@@ -9,6 +9,8 @@
#pragma once
+#include "BLI_math_vec_types.hh"
+
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
@@ -72,7 +74,7 @@ struct MeshRenderData {
int freestyle_face_ofs;
/** Mesh */
Mesh *me;
- const MVert *mvert;
+ const blender::float3 *positions;
const MEdge *medge;
const MLoop *mloop;
const MPoly *mpoly;
@@ -267,10 +269,7 @@ using ExtractLVertBMeshFn = void(const MeshRenderData *mr,
const BMVert *eve,
int lvert_index,
void *data);
-using ExtractLVertMeshFn = void(const MeshRenderData *mr,
- const MVert *mv,
- int lvert_index,
- void *data);
+using ExtractLVertMeshFn = void(const MeshRenderData *mr, int lvert_index, void *data);
using ExtractLooseGeomSubdivFn = void(const DRWSubdivCache *subdiv_cache,
const MeshRenderData *mr,
void *buffer,
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_points.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_points.cc
index e84f122d03e..d5e8447ff64 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_points.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_points.cc
@@ -113,7 +113,6 @@ static void extract_points_iter_lvert_bm(const MeshRenderData *mr,
}
static void extract_points_iter_lvert_mesh(const MeshRenderData *mr,
- const MVert * /*mv*/,
const int lvert_index,
void *_userdata)
{
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edge_fac.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edge_fac.cc
index de1f5181ac5..b6bb3426e03 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edge_fac.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edge_fac.cc
@@ -131,10 +131,10 @@ static void extract_edge_fac_iter_poly_mesh(const MeshRenderData *mr,
const int ml_index_last = mp->totloop + mp->loopstart - 1;
const int ml_index_other = (ml_index == ml_index_last) ? mp->loopstart : (ml_index + 1);
const MLoop *ml_next = &mr->mloop[ml_index_other];
- const MVert *v1 = &mr->mvert[ml->v];
- const MVert *v2 = &mr->mvert[ml_next->v];
- float ratio = loop_edge_factor_get(
- mr->poly_normals[mp_index], v1->co, mr->vert_normals[ml->v], v2->co);
+ float ratio = loop_edge_factor_get(mr->poly_normals[mp_index],
+ mr->positions[ml->v],
+ mr->vert_normals[ml->v],
+ mr->positions[ml_next->v]);
data->vbo_data[ml_index] = ratio * 253 + 1;
}
else {
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc
index 31dc2fdff6a..80365d9da15 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc
@@ -223,7 +223,6 @@ static void extract_edit_data_iter_lvert_bm(const MeshRenderData *mr,
}
static void extract_edit_data_iter_lvert_mesh(const MeshRenderData *mr,
- const MVert * /*mv*/,
const int lvert_index,
void *_data)
{
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_angle.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_angle.cc
index 492756f30bb..43a4e37d34d 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_angle.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_angle.cc
@@ -167,15 +167,16 @@ static void extract_edituv_stretch_angle_iter_poly_mesh(const MeshRenderData *mr
float(*auv)[2] = data->auv, *last_auv = data->last_auv;
float(*av)[3] = data->av, *last_av = data->last_av;
int l_next = ml_index + 1;
- const MVert *v, *v_next;
if (ml_index == mp->loopstart) {
/* First loop in face. */
const int ml_index_last = ml_index_end - 1;
const int l_next_tmp = mp->loopstart;
- v = &mr->mvert[mr->mloop[ml_index_last].v];
- v_next = &mr->mvert[mr->mloop[l_next_tmp].v];
- compute_normalize_edge_vectors(
- auv, av, data->luv[ml_index_last].uv, data->luv[l_next_tmp].uv, v->co, v_next->co);
+ compute_normalize_edge_vectors(auv,
+ av,
+ data->luv[ml_index_last].uv,
+ data->luv[l_next_tmp].uv,
+ mr->positions[mr->mloop[ml_index_last].v],
+ mr->positions[mr->mloop[l_next_tmp].v]);
/* Save last edge. */
copy_v2_v2(last_auv, auv[1]);
copy_v3_v3(last_av, av[1]);
@@ -190,10 +191,12 @@ static void extract_edituv_stretch_angle_iter_poly_mesh(const MeshRenderData *mr
copy_v3_v3(av[1], last_av);
}
else {
- v = &mr->mvert[mr->mloop[ml_index].v];
- v_next = &mr->mvert[mr->mloop[l_next].v];
- compute_normalize_edge_vectors(
- auv, av, data->luv[ml_index].uv, data->luv[l_next].uv, v->co, v_next->co);
+ compute_normalize_edge_vectors(auv,
+ av,
+ data->luv[ml_index].uv,
+ data->luv[l_next].uv,
+ mr->positions[mr->mloop[ml_index].v],
+ mr->positions[mr->mloop[l_next].v]);
}
edituv_get_edituv_stretch_angle(auv, av, &data->vbo_data[ml_index]);
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_area.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_area.cc
index 7c96fbd6a99..b4aaef4f211 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_area.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edituv_stretch_area.cc
@@ -75,7 +75,8 @@ static void compute_area_ratio(const MeshRenderData *mr,
const MLoopUV *uv_data = (const MLoopUV *)CustomData_get_layer(&mr->me->ldata, CD_MLOOPUV);
const MPoly *mp = mr->mpoly;
for (int mp_index = 0; mp_index < mr->poly_len; mp_index++, mp++) {
- float area = BKE_mesh_calc_poly_area(mp, &mr->mloop[mp->loopstart], mr->mvert);
+ float area = BKE_mesh_calc_poly_area(
+ mp, &mr->mloop[mp->loopstart], reinterpret_cast<const float(*)[3]>(mr->positions));
float uvarea = BKE_mesh_calc_poly_uv_area(mp, uv_data);
tot_area += area;
tot_uv_area += uvarea;
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_pos.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_pos.cc
index d43eb6117df..03e70dc7ef7 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_pos.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_fdots_pos.cc
@@ -75,7 +75,6 @@ static void extract_fdots_pos_iter_poly_mesh(const MeshRenderData *mr,
float *co = center[mp_index];
zero_v3(co);
- const MVert *mvert = mr->mvert;
const MLoop *mloop = mr->mloop;
const BLI_bitmap *facedot_tags = mr->me->runtime->subsurf_face_dot_tags;
@@ -84,13 +83,12 @@ static void extract_fdots_pos_iter_poly_mesh(const MeshRenderData *mr,
const MLoop *ml = &mloop[ml_index];
if (mr->use_subsurf_fdots) {
if (BLI_BITMAP_TEST(facedot_tags, ml->v)) {
- copy_v3_v3(center[mp_index], mvert[ml->v].co);
+ copy_v3_v3(center[mp_index], mr->positions[ml->v]);
break;
}
}
else {
- const MVert *mv = &mvert[ml->v];
- add_v3_v3(center[mp_index], mv->co);
+ add_v3_v3(center[mp_index], mr->positions[ml->v]);
}
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_mesh_analysis.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_mesh_analysis.cc
index d0d97054448..78443f164ef 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_mesh_analysis.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_mesh_analysis.cc
@@ -217,9 +217,9 @@ static void statvis_calc_thickness(const MeshRenderData *mr, float *r_thickness)
const MLoopTri *mlooptri = mr->mlooptri;
for (int i = 0; i < mr->tri_len; i++, mlooptri++) {
const int index = mlooptri->poly;
- const float *cos[3] = {mr->mvert[mr->mloop[mlooptri->tri[0]].v].co,
- mr->mvert[mr->mloop[mlooptri->tri[1]].v].co,
- mr->mvert[mr->mloop[mlooptri->tri[2]].v].co};
+ const float *cos[3] = {mr->positions[mr->mloop[mlooptri->tri[0]].v],
+ mr->positions[mr->mloop[mlooptri->tri[1]].v],
+ mr->positions[mr->mloop[mlooptri->tri[2]].v]};
float ray_co[3];
float ray_no[3];
@@ -259,7 +259,7 @@ static void statvis_calc_thickness(const MeshRenderData *mr, float *r_thickness)
}
struct BVHTree_OverlapData {
- const MVert *verts;
+ const float3 *positions;
const MLoop *loops;
const MLoopTri *mlooptri;
float epsilon;
@@ -276,12 +276,12 @@ static bool bvh_overlap_cb(void *userdata, int index_a, int index_b, int /*threa
return false;
}
- const float *tri_a_co[3] = {data->verts[data->loops[tri_a->tri[0]].v].co,
- data->verts[data->loops[tri_a->tri[1]].v].co,
- data->verts[data->loops[tri_a->tri[2]].v].co};
- const float *tri_b_co[3] = {data->verts[data->loops[tri_b->tri[0]].v].co,
- data->verts[data->loops[tri_b->tri[1]].v].co,
- data->verts[data->loops[tri_b->tri[2]].v].co};
+ const float *tri_a_co[3] = {data->positions[data->loops[tri_a->tri[0]].v],
+ data->positions[data->loops[tri_a->tri[1]].v],
+ data->positions[data->loops[tri_a->tri[2]].v]};
+ const float *tri_b_co[3] = {data->positions[data->loops[tri_b->tri[0]].v],
+ data->positions[data->loops[tri_b->tri[1]].v],
+ data->positions[data->loops[tri_b->tri[2]].v]};
float ix_pair[2][3];
int verts_shared = 0;
@@ -342,7 +342,7 @@ static void statvis_calc_intersect(const MeshRenderData *mr, float *r_intersect)
BVHTree *tree = BKE_bvhtree_from_mesh_get(&treeData, mr->me, BVHTREE_FROM_LOOPTRI, 4);
struct BVHTree_OverlapData data = {nullptr};
- data.verts = mr->mvert;
+ data.positions = mr->positions;
data.loops = mr->mloop;
data.mlooptri = mr->mlooptri;
data.epsilon = BLI_bvhtree_get_epsilon(tree);
@@ -454,9 +454,9 @@ static void statvis_calc_distort(const MeshRenderData *mr, float *r_distort)
const MLoop *l_next = &mr->mloop[mp->loopstart + (i + 1) % mp->totloop];
float no_corner[3];
normal_tri_v3(no_corner,
- mr->mvert[l_prev->v].co,
- mr->mvert[l_curr->v].co,
- mr->mvert[l_next->v].co);
+ mr->positions[l_prev->v],
+ mr->positions[l_curr->v],
+ mr->positions[l_next->v]);
/* simple way to detect (what is most likely) concave */
if (dot_v3v3(f_no, no_corner) < 0.0f) {
negate_v3(no_corner);
@@ -534,8 +534,6 @@ static void statvis_calc_sharp(const MeshRenderData *mr, float *r_sharp)
for (int i = 0; i < mp->totloop; i++) {
const MLoop *l_curr = &mr->mloop[mp->loopstart + (i + 0) % mp->totloop];
const MLoop *l_next = &mr->mloop[mp->loopstart + (i + 1) % mp->totloop];
- const MVert *v_curr = &mr->mvert[l_curr->v];
- const MVert *v_next = &mr->mvert[l_next->v];
float angle;
void **pval;
bool value_is_init = BLI_edgehash_ensure_p(eh, l_curr->v, l_next->v, &pval);
@@ -548,7 +546,10 @@ static void statvis_calc_sharp(const MeshRenderData *mr, float *r_sharp)
const float *f1_no = mr->poly_normals[mp_index];
const float *f2_no = static_cast<const float *>(*pval);
angle = angle_normalized_v3v3(f1_no, f2_no);
- angle = is_edge_convex_v3(v_curr->co, v_next->co, f1_no, f2_no) ? angle : -angle;
+ angle = is_edge_convex_v3(
+ mr->positions[l_curr->v], mr->positions[l_next->v], f1_no, f2_no) ?
+ angle :
+ -angle;
/* Tag as manifold. */
*pval = nullptr;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc
index 30b4f808487..fef3b911fcf 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc
@@ -95,9 +95,8 @@ static void extract_pos_nor_iter_poly_mesh(const MeshRenderData *mr,
const MLoop *ml = &mloop[ml_index];
PosNorLoop *vert = &data->vbo_data[ml_index];
- const MVert *mv = &mr->mvert[ml->v];
const bool vert_hidden = mr->hide_vert && mr->hide_vert[ml->v];
- copy_v3_v3(vert->pos, mv->co);
+ copy_v3_v3(vert->pos, mr->positions[ml->v]);
vert->nor = data->normals[ml->v].low;
/* Flag for paint mode overlay. */
if (poly_hidden || vert_hidden ||
@@ -136,8 +135,8 @@ static void extract_pos_nor_iter_ledge_mesh(const MeshRenderData *mr,
MeshExtract_PosNor_Data *data = static_cast<MeshExtract_PosNor_Data *>(_data);
const int ml_index = mr->loop_len + ledge_index * 2;
PosNorLoop *vert = &data->vbo_data[ml_index];
- copy_v3_v3(vert[0].pos, mr->mvert[med->v1].co);
- copy_v3_v3(vert[1].pos, mr->mvert[med->v2].co);
+ copy_v3_v3(vert[0].pos, mr->positions[med->v1]);
+ copy_v3_v3(vert[1].pos, mr->positions[med->v2]);
vert[0].nor = data->normals[med->v1].low;
vert[1].nor = data->normals[med->v2].low;
}
@@ -157,7 +156,6 @@ static void extract_pos_nor_iter_lvert_bm(const MeshRenderData *mr,
}
static void extract_pos_nor_iter_lvert_mesh(const MeshRenderData *mr,
- const MVert *mv,
const int lvert_index,
void *_data)
{
@@ -167,7 +165,7 @@ static void extract_pos_nor_iter_lvert_mesh(const MeshRenderData *mr,
const int ml_index = offset + lvert_index;
const int v_index = mr->lverts[lvert_index];
PosNorLoop *vert = &data->vbo_data[ml_index];
- copy_v3_v3(vert->pos, mv->co);
+ copy_v3_v3(vert->pos, mr->positions[v_index]);
vert->nor = data->normals[v_index].low;
}
@@ -442,8 +440,7 @@ static void extract_pos_nor_hq_iter_poly_mesh(const MeshRenderData *mr,
const bool vert_hidden = mr->hide_vert && mr->hide_vert[ml->v];
PosNorHQLoop *vert = &data->vbo_data[ml_index];
- const MVert *mv = &mr->mvert[ml->v];
- copy_v3_v3(vert->pos, mv->co);
+ copy_v3_v3(vert->pos, mr->positions[ml->v]);
copy_v3_v3_short(vert->nor, data->normals[ml->v].high);
/* Flag for paint mode overlay. */
@@ -484,8 +481,8 @@ static void extract_pos_nor_hq_iter_ledge_mesh(const MeshRenderData *mr,
MeshExtract_PosNorHQ_Data *data = static_cast<MeshExtract_PosNorHQ_Data *>(_data);
const int ml_index = mr->loop_len + ledge_index * 2;
PosNorHQLoop *vert = &data->vbo_data[ml_index];
- copy_v3_v3(vert[0].pos, mr->mvert[med->v1].co);
- copy_v3_v3(vert[1].pos, mr->mvert[med->v2].co);
+ copy_v3_v3(vert[0].pos, mr->positions[med->v1]);
+ copy_v3_v3(vert[1].pos, mr->positions[med->v2]);
copy_v3_v3_short(vert[0].nor, data->normals[med->v1].high);
vert[0].nor[3] = 0;
copy_v3_v3_short(vert[1].nor, data->normals[med->v2].high);
@@ -508,7 +505,6 @@ static void extract_pos_nor_hq_iter_lvert_bm(const MeshRenderData *mr,
}
static void extract_pos_nor_hq_iter_lvert_mesh(const MeshRenderData *mr,
- const MVert *mv,
const int lvert_index,
void *_data)
{
@@ -518,7 +514,7 @@ static void extract_pos_nor_hq_iter_lvert_mesh(const MeshRenderData *mr,
const int ml_index = offset + lvert_index;
const int v_index = mr->lverts[lvert_index];
PosNorHQLoop *vert = &data->vbo_data[ml_index];
- copy_v3_v3(vert->pos, mv->co);
+ copy_v3_v3(vert->pos, mr->positions[v_index]);
copy_v3_v3_short(vert->nor, data->normals[v_index].high);
vert->nor[3] = 0;
}
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_select_idx.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_select_idx.cc
index 5c196a67d0b..fd02c642a5b 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_select_idx.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_select_idx.cc
@@ -169,7 +169,6 @@ static void extract_vert_idx_iter_ledge_mesh(const MeshRenderData *mr,
}
static void extract_vert_idx_iter_lvert_mesh(const MeshRenderData *mr,
- const MVert * /*mv*/,
const int lvert_index,
void *data)
{
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_tan.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_tan.cc
index 6f0c98c684b..87622c360a6 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_tan.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_tan.cc
@@ -88,9 +88,8 @@ static void extract_tan_init_common(const MeshRenderData *mr,
}
}
else {
- const MVert *mv = mr->mvert;
- for (int v = 0; v < mr->vert_len; v++, mv++) {
- copy_v3_v3(orco[v], mv->co);
+ for (int v = 0; v < mr->vert_len; v++) {
+ copy_v3_v3(orco[v], mr->positions[v]);
}
}
BKE_mesh_orco_verts_transform(mr->me, orco, mr->vert_len, 0);
@@ -114,7 +113,7 @@ static void extract_tan_init_common(const MeshRenderData *mr,
&tangent_mask);
}
else {
- BKE_mesh_calc_loop_tangent_ex(mr->mvert,
+ BKE_mesh_calc_loop_tangent_ex(reinterpret_cast<const float(*)[3]>(mr->positions),
mr->mpoly,
mr->poly_len,
mr->mloop,
diff --git a/source/blender/editors/armature/armature_skinning.c b/source/blender/editors/armature/armature_skinning.c
index 3c9c8cf05b3..562b2fad3dd 100644
--- a/source/blender/editors/armature/armature_skinning.c
+++ b/source/blender/editors/armature/armature_skinning.c
@@ -409,10 +409,10 @@ static void add_verts_to_dgroups(ReportList *reports,
}
/* transform verts to global space */
- const MVert *mesh_verts = BKE_mesh_verts(mesh);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
for (int i = 0; i < mesh->totvert; i++) {
if (!vertsfilled) {
- copy_v3_v3(verts[i], mesh_verts[i].co);
+ copy_v3_v3(verts[i], positions[i]);
}
mul_m4_v3(ob->object_to_world, verts[i]);
}
diff --git a/source/blender/editors/armature/meshlaplacian.c b/source/blender/editors/armature/meshlaplacian.c
index dfb9e8a79fa..c6175597f65 100644
--- a/source/blender/editors/armature/meshlaplacian.c
+++ b/source/blender/editors/armature/meshlaplacian.c
@@ -652,7 +652,7 @@ void heat_bone_weighting(Object *ob,
int a, tris_num, j, bbone, firstsegment, lastsegment;
bool use_topology = (me->editflag & ME_EDIT_MIRROR_TOPO) != 0;
- const MVert *mesh_verts = BKE_mesh_verts(me);
+ const float(*mesh_positions)[3] = BKE_mesh_positions(me);
const MPoly *polys = BKE_mesh_polys(me);
const MLoop *loops = BKE_mesh_loops(me);
bool use_vert_sel = (me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0;
@@ -700,7 +700,7 @@ void heat_bone_weighting(Object *ob,
sys->heat.tris_num = poly_to_tri_count(me->totpoly, me->totloop);
mlooptri = MEM_mallocN(sizeof(*sys->heat.mlooptri) * sys->heat.tris_num, __func__);
- BKE_mesh_recalc_looptri(loops, polys, mesh_verts, me->totloop, me->totpoly, mlooptri);
+ BKE_mesh_recalc_looptri(loops, polys, mesh_positions, me->totloop, me->totpoly, mlooptri);
sys->heat.mlooptri = mlooptri;
sys->heat.mloop = loops;
@@ -1753,7 +1753,6 @@ void ED_mesh_deform_bind_callback(Object *object,
MeshDeformModifierData *mmd_orig = (MeshDeformModifierData *)BKE_modifier_get_original(
object, &mmd->modifier);
MeshDeformBind mdb;
- const MVert *mvert;
int a;
waitcursor(1);
@@ -1773,9 +1772,9 @@ void ED_mesh_deform_bind_callback(Object *object,
mdb.cagecos = MEM_callocN(sizeof(*mdb.cagecos) * mdb.cage_verts_num, "MeshDeformBindCos");
copy_m4_m4(mdb.cagemat, cagemat);
- mvert = BKE_mesh_verts(mdb.cagemesh);
+ const float(*positions)[3] = BKE_mesh_positions(mdb.cagemesh);
for (a = 0; a < mdb.cage_verts_num; a++) {
- copy_v3_v3(mdb.cagecos[a], mvert[a].co);
+ copy_v3_v3(mdb.cagecos[a], positions[a]);
}
for (a = 0; a < mdb.verts_num; a++) {
mul_v3_m4v3(mdb.vertexcos[a], mdb.cagemat, vertexcos + a * 3);
diff --git a/source/blender/editors/curves/intern/curves_ops.cc b/source/blender/editors/curves/intern/curves_ops.cc
index 1d2b1264477..d7520fc3a21 100644
--- a/source/blender/editors/curves/intern/curves_ops.cc
+++ b/source/blender/editors/curves/intern/curves_ops.cc
@@ -139,7 +139,7 @@ using bke::CurvesGeometry;
namespace convert_to_particle_system {
-static int find_mface_for_root_position(const Span<MVert> verts,
+static int find_mface_for_root_position(const Span<float3> positions,
const MFace *mface,
const Span<int> possible_mface_indices,
const float3 &root_pos)
@@ -157,9 +157,9 @@ static int find_mface_for_root_position(const Span<MVert> verts,
float3 point_in_triangle;
closest_on_tri_to_point_v3(point_in_triangle,
root_pos,
- verts[possible_mface.v1].co,
- verts[possible_mface.v2].co,
- verts[possible_mface.v3].co);
+ positions[possible_mface.v1],
+ positions[possible_mface.v2],
+ positions[possible_mface.v3]);
const float distance_sq = len_squared_v3v3(root_pos, point_in_triangle);
if (distance_sq < best_distance_sq) {
best_distance_sq = distance_sq;
@@ -171,9 +171,9 @@ static int find_mface_for_root_position(const Span<MVert> verts,
float3 point_in_triangle;
closest_on_tri_to_point_v3(point_in_triangle,
root_pos,
- verts[possible_mface.v1].co,
- verts[possible_mface.v3].co,
- verts[possible_mface.v4].co);
+ positions[possible_mface.v1],
+ positions[possible_mface.v3],
+ positions[possible_mface.v4]);
const float distance_sq = len_squared_v3v3(root_pos, point_in_triangle);
if (distance_sq < best_distance_sq) {
best_distance_sq = distance_sq;
@@ -187,22 +187,22 @@ static int find_mface_for_root_position(const Span<MVert> verts,
/**
* \return Barycentric coordinates in the #MFace.
*/
-static float4 compute_mface_weights_for_position(const Span<MVert> verts,
+static float4 compute_mface_weights_for_position(const Span<float3> positions,
const MFace &mface,
const float3 &position)
{
float4 mface_weights;
if (mface.v4) {
- float mface_verts_su[4][3];
- copy_v3_v3(mface_verts_su[0], verts[mface.v1].co);
- copy_v3_v3(mface_verts_su[1], verts[mface.v2].co);
- copy_v3_v3(mface_verts_su[2], verts[mface.v3].co);
- copy_v3_v3(mface_verts_su[3], verts[mface.v4].co);
- interp_weights_poly_v3(mface_weights, mface_verts_su, 4, position);
+ float mface_positions_su[4][3];
+ copy_v3_v3(mface_positions_su[0], positions[mface.v1]);
+ copy_v3_v3(mface_positions_su[1], positions[mface.v2]);
+ copy_v3_v3(mface_positions_su[2], positions[mface.v3]);
+ copy_v3_v3(mface_positions_su[3], positions[mface.v4]);
+ interp_weights_poly_v3(mface_weights, mface_positions_su, 4, position);
}
else {
interp_weights_tri_v3(
- mface_weights, verts[mface.v1].co, verts[mface.v2].co, verts[mface.v3].co, position);
+ mface_weights, positions[mface.v1], positions[mface.v2], positions[mface.v3], position);
mface_weights[3] = 0.0f;
}
return mface_weights;
@@ -285,7 +285,7 @@ static void try_convert_single_object(Object &curves_ob,
const bke::CurvesSurfaceTransforms transforms{curves_ob, &surface_ob};
const MFace *mfaces = (const MFace *)CustomData_get_layer(&surface_me.fdata, CD_MFACE);
- const Span<MVert> verts = surface_me.verts();
+ const Span<float3> positions = surface_me.positions();
for (const int new_hair_i : IndexRange(hair_num)) {
const int curve_i = new_hair_i;
@@ -305,10 +305,10 @@ static void try_convert_single_object(Object &curves_ob,
const int poly_i = looptri.poly;
const int mface_i = find_mface_for_root_position(
- verts, mfaces, poly_to_mface_map[poly_i], root_pos_su);
+ positions, mfaces, poly_to_mface_map[poly_i], root_pos_su);
const MFace &mface = mfaces[mface_i];
- const float4 mface_weights = compute_mface_weights_for_position(verts, mface, root_pos_su);
+ const float4 mface_weights = compute_mface_weights_for_position(positions, mface, root_pos_su);
ParticleData &particle = particles[new_hair_i];
const int num_keys = points.size();
@@ -542,7 +542,7 @@ static void snap_curves_to_surface_exec_object(Object &curves_ob,
CurvesGeometry &curves = CurvesGeometry::wrap(curves_id.geometry);
const Mesh &surface_mesh = *static_cast<const Mesh *>(surface_ob.data);
- const Span<MVert> verts = surface_mesh.verts();
+ const Span<float3> surface_positions = surface_mesh.positions();
const Span<MLoop> loops = surface_mesh.loops();
const Span<MLoopTri> surface_looptris = surface_mesh.looptris();
VArraySpan<float2> surface_uv_map;
@@ -602,9 +602,9 @@ static void snap_curves_to_surface_exec_object(Object &curves_ob,
const float2 &uv0 = surface_uv_map[corner0];
const float2 &uv1 = surface_uv_map[corner1];
const float2 &uv2 = surface_uv_map[corner2];
- const float3 &p0_su = verts[loops[corner0].v].co;
- const float3 &p1_su = verts[loops[corner1].v].co;
- const float3 &p2_su = verts[loops[corner2].v].co;
+ const float3 &p0_su = surface_positions[loops[corner0].v];
+ const float3 &p1_su = surface_positions[loops[corner1].v];
+ const float3 &p2_su = surface_positions[loops[corner2].v];
float3 bary_coords;
interp_weights_tri_v3(bary_coords, p0_su, p1_su, p2_su, new_first_point_pos_su);
const float2 uv = attribute_math::mix3(bary_coords, uv0, uv1, uv2);
@@ -638,9 +638,9 @@ static void snap_curves_to_surface_exec_object(Object &curves_ob,
const MLoopTri &looptri = *lookup_result.looptri;
const float3 &bary_coords = lookup_result.bary_weights;
- const float3 &p0_su = verts[loops[looptri.tri[0]].v].co;
- const float3 &p1_su = verts[loops[looptri.tri[1]].v].co;
- const float3 &p2_su = verts[loops[looptri.tri[2]].v].co;
+ const float3 &p0_su = surface_positions[loops[looptri.tri[0]].v];
+ const float3 &p1_su = surface_positions[loops[looptri.tri[1]].v];
+ const float3 &p2_su = surface_positions[loops[looptri.tri[2]].v];
float3 new_first_point_pos_su;
interp_v3_v3v3v3(new_first_point_pos_su, p0_su, p1_su, p2_su, bary_coords);
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index 52aa5f56fee..f475eeee335 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -30,7 +30,6 @@ struct Depsgraph;
struct EditBone;
struct GPUSelectResult;
struct ID;
-struct MVert;
struct Main;
struct MetaElem;
struct Nurb;
@@ -355,11 +354,12 @@ void ED_view3d_cursor_snap_draw_util(struct RegionView3D *rv3d,
/* foreach iterators */
-void meshobject_foreachScreenVert(
- struct ViewContext *vc,
- void (*func)(void *userData, struct MVert *eve, const float screen_co[2], int index),
- void *userData,
- eV3DProjTest clip_flag);
+void meshobject_foreachScreenVert(struct ViewContext *vc,
+ void (*func)(void *userData,
+ const float screen_co[2],
+ int index),
+ void *userData,
+ eV3DProjTest clip_flag);
void mesh_foreachScreenVert(
struct ViewContext *vc,
void (*func)(void *userData, struct BMVert *eve, const float screen_co[2], int index),
diff --git a/source/blender/editors/mesh/editface.cc b/source/blender/editors/mesh/editface.cc
index 1c6d1747516..6451c6e2bf9 100644
--- a/source/blender/editors/mesh/editface.cc
+++ b/source/blender/editors/mesh/editface.cc
@@ -385,7 +385,7 @@ bool paintface_minmax(Object *ob, float r_min[3], float r_max[3])
copy_m3_m4(bmat, ob->object_to_world);
- const Span<MVert> verts = me->verts();
+ const Span<float3> positions = me->positions();
const Span<MPoly> polys = me->polys();
const Span<MLoop> loops = me->loops();
bke::AttributeAccessor attributes = me->attributes();
@@ -402,7 +402,7 @@ bool paintface_minmax(Object *ob, float r_min[3], float r_max[3])
const MPoly &poly = polys[i];
const MLoop *ml = &loops[poly.loopstart];
for (int b = 0; b < poly.totloop; b++, ml++) {
- mul_v3_m3v3(vec, bmat, verts[ml->v].co);
+ mul_v3_m3v3(vec, bmat, positions[ml->v]);
add_v3_v3v3(vec, vec, ob->object_to_world[3]);
minmax_v3v3_v3(r_min, r_max, vec);
}
diff --git a/source/blender/editors/mesh/mesh_data.cc b/source/blender/editors/mesh/mesh_data.cc
index 9901f4e1836..01cb1951c93 100644
--- a/source/blender/editors/mesh/mesh_data.cc
+++ b/source/blender/editors/mesh/mesh_data.cc
@@ -45,6 +45,7 @@
#include "mesh_intern.h" /* own include */
using blender::Array;
+using blender::float3;
using blender::MutableSpan;
using blender::Span;
@@ -798,12 +799,12 @@ static int mesh_customdata_custom_splitnormals_add_exec(bContext *C, wmOperator
/* Tag edges as sharp according to smooth threshold if needed,
* to preserve auto-smooth shading. */
if (me->flag & ME_AUTOSMOOTH) {
- const Span<MVert> verts = me->verts();
+ const Span<float3> verts = me->positions();
MutableSpan<MEdge> edges = me->edges_for_write();
const Span<MPoly> polys = me->polys();
const Span<MLoop> loops = me->loops();
- BKE_edges_sharp_from_angle_set(verts.data(),
+ BKE_edges_sharp_from_angle_set(reinterpret_cast<const float(*)[3]>(verts.data()),
verts.size(),
edges.data(),
edges.size(),
@@ -1144,8 +1145,9 @@ static void mesh_add_verts(Mesh *mesh, int len)
CustomData_copy(&mesh->vdata, &vdata, CD_MASK_MESH.vmask, CD_SET_DEFAULT, totvert);
CustomData_copy_data(&mesh->vdata, &vdata, 0, 0, mesh->totvert);
- if (!CustomData_has_layer(&vdata, CD_MVERT)) {
- CustomData_add_layer(&vdata, CD_MVERT, CD_SET_DEFAULT, nullptr, totvert);
+ if (!CustomData_get_layer_named(&vdata, CD_PROP_FLOAT3, "position")) {
+ CustomData_add_layer_named(
+ &vdata, CD_PROP_FLOAT3, CD_SET_DEFAULT, nullptr, totvert, "position");
}
CustomData_free(&mesh->vdata, mesh->totvert);
diff --git a/source/blender/editors/mesh/mesh_mirror.c b/source/blender/editors/mesh/mesh_mirror.c
index ad5a5d362f1..38a518cbd5b 100644
--- a/source/blender/editors/mesh/mesh_mirror.c
+++ b/source/blender/editors/mesh/mesh_mirror.c
@@ -55,9 +55,9 @@ void ED_mesh_mirror_spatial_table_begin(Object *ob, BMEditMesh *em, Mesh *me_eva
}
}
else {
- const MVert *verts = BKE_mesh_verts(me_eval ? me_eval : me);
+ const float(*positions)[3] = BKE_mesh_positions(me_eval ? me_eval : me);
for (int i = 0; i < totvert; i++) {
- BLI_kdtree_3d_insert(MirrKdStore.tree, i, verts[i].co);
+ BLI_kdtree_3d_insert(MirrKdStore.tree, i, positions[i]);
}
}
diff --git a/source/blender/editors/mesh/meshtools.cc b/source/blender/editors/mesh/meshtools.cc
index 147c26e521f..cdfee0fb069 100644
--- a/source/blender/editors/mesh/meshtools.cc
+++ b/source/blender/editors/mesh/meshtools.cc
@@ -55,6 +55,7 @@
#include "WM_api.h"
#include "WM_types.h"
+using blender::float3;
using blender::MutableSpan;
using blender::Span;
@@ -71,7 +72,7 @@ static void join_mesh_single(Depsgraph *depsgraph,
Object *ob_dst,
Object *ob_src,
const float imat[4][4],
- MVert **mvert_pp,
+ float3 **positions_pp,
MEdge **medge_pp,
MLoop **mloop_pp,
MPoly **mpoly_pp,
@@ -96,7 +97,7 @@ static void join_mesh_single(Depsgraph *depsgraph,
int a, b;
Mesh *me = static_cast<Mesh *>(ob_src->data);
- MVert *mvert = *mvert_pp;
+ float3 *positions = *positions_pp;
MEdge *medge = *medge_pp;
MLoop *mloop = *mloop_pp;
MPoly *mpoly = *mpoly_pp;
@@ -135,8 +136,8 @@ static void join_mesh_single(Depsgraph *depsgraph,
mul_m4_m4m4(cmat, imat, ob_src->object_to_world);
/* transform vertex coordinates into new space */
- for (a = 0; a < me->totvert; a++, mvert++) {
- mul_m4_v3(cmat, mvert->co);
+ for (a = 0; a < me->totvert; a++) {
+ mul_m4_v3(cmat, positions[a]);
}
/* For each shape-key in destination mesh:
@@ -164,8 +165,8 @@ static void join_mesh_single(Depsgraph *depsgraph,
}
else {
/* Copy this mesh's vertex coordinates to the destination shape-key. */
- for (a = 0, mvert = *mvert_pp; a < me->totvert; a++, cos++, mvert++) {
- copy_v3_v3(*cos, mvert->co);
+ for (a = 0; a < me->totvert; a++, cos++) {
+ copy_v3_v3(*cos, positions[a]);
}
}
}
@@ -192,8 +193,8 @@ static void join_mesh_single(Depsgraph *depsgraph,
}
else {
/* Copy base-coordinates to the destination shape-key. */
- for (a = 0, mvert = *mvert_pp; a < me->totvert; a++, cos++, mvert++) {
- copy_v3_v3(*cos, mvert->co);
+ for (a = 0; a < me->totvert; a++, cos++) {
+ copy_v3_v3(*cos, positions[a]);
}
}
}
@@ -287,7 +288,7 @@ static void join_mesh_single(Depsgraph *depsgraph,
/* these are used for relinking (cannot be set earlier, or else reattaching goes wrong) */
*vertofs += me->totvert;
- *mvert_pp += me->totvert;
+ *positions_pp += me->totvert;
*edgeofs += me->totedge;
*medge_pp += me->totedge;
*loopofs += me->totloop;
@@ -330,7 +331,6 @@ int ED_mesh_join_objects_exec(bContext *C, wmOperator *op)
Object *ob = CTX_data_active_object(C);
Material **matar = nullptr, *ma;
Mesh *me;
- MVert *mvert = nullptr;
MEdge *medge = nullptr;
MPoly *mpoly = nullptr;
MLoop *mloop = nullptr;
@@ -582,7 +582,8 @@ int ED_mesh_join_objects_exec(bContext *C, wmOperator *op)
CustomData_reset(&ldata);
CustomData_reset(&pdata);
- mvert = (MVert *)CustomData_add_layer(&vdata, CD_MVERT, CD_SET_DEFAULT, nullptr, totvert);
+ float3 *positions = (float3 *)CustomData_add_layer_named(
+ &vdata, CD_PROP_FLOAT3, CD_SET_DEFAULT, nullptr, totvert, "position");
medge = (MEdge *)CustomData_add_layer(&edata, CD_MEDGE, CD_SET_DEFAULT, nullptr, totedge);
mloop = (MLoop *)CustomData_add_layer(&ldata, CD_MLOOP, CD_SET_DEFAULT, nullptr, totloop);
mpoly = (MPoly *)CustomData_add_layer(&pdata, CD_MPOLY, CD_SET_DEFAULT, nullptr, totpoly);
@@ -607,7 +608,7 @@ int ED_mesh_join_objects_exec(bContext *C, wmOperator *op)
ob,
ob,
imat,
- &mvert,
+ &positions,
&medge,
&mloop,
&mpoly,
@@ -641,7 +642,7 @@ int ED_mesh_join_objects_exec(bContext *C, wmOperator *op)
ob,
ob_iter,
imat,
- &mvert,
+ &positions,
&medge,
&mloop,
&mpoly,
@@ -901,13 +902,13 @@ static bool ed_mesh_mirror_topo_table_update(Object *ob, Mesh *me_eval)
static int mesh_get_x_mirror_vert_spatial(Object *ob, Mesh *me_eval, int index)
{
Mesh *me = static_cast<Mesh *>(ob->data);
- const Span<MVert> verts = me_eval ? me_eval->verts() : me->verts();
+ const Span<float3> positions = me_eval ? me_eval->positions() : me->positions();
float vec[3];
- vec[0] = -verts[index].co[0];
- vec[1] = verts[index].co[1];
- vec[2] = verts[index].co[2];
+ vec[0] = -positions[index][0];
+ vec[1] = positions[index][1];
+ vec[2] = positions[index][2];
return ED_mesh_mirror_spatial_table_lookup(ob, nullptr, me_eval, vec);
}
@@ -1123,7 +1124,6 @@ static bool mirror_facecmp(const void *a, const void *b)
int *mesh_get_x_mirror_faces(Object *ob, BMEditMesh *em, Mesh *me_eval)
{
Mesh *me = static_cast<Mesh *>(ob->data);
- const MVert *mv;
MFace mirrormf, *mf, *hashmf;
GHash *fhash;
int *mirrorverts, *mirrorfaces;
@@ -1138,13 +1138,13 @@ int *mesh_get_x_mirror_faces(Object *ob, BMEditMesh *em, Mesh *me_eval)
mirrorverts = static_cast<int *>(MEM_callocN(sizeof(int) * totvert, "MirrorVerts"));
mirrorfaces = static_cast<int *>(MEM_callocN(sizeof(int[2]) * totface, "MirrorFaces"));
- const Span<MVert> verts = me_eval ? me_eval->verts() : me->verts();
+ const Span<float3> positions = me_eval ? me_eval->positions() : me->positions();
MFace *mface = (MFace *)CustomData_get_layer(&(me_eval ? me_eval : me)->fdata, CD_MFACE);
ED_mesh_mirror_spatial_table_begin(ob, em, me_eval);
- for (a = 0, mv = verts.data(); a < totvert; a++, mv++) {
- mirrorverts[a] = mesh_get_x_mirror_vert(ob, me_eval, a, use_topology);
+ for (const int i : positions.index_range()) {
+ mirrorverts[i] = mesh_get_x_mirror_vert(ob, me_eval, i, use_topology);
}
ED_mesh_mirror_spatial_table_end(ob);
@@ -1225,7 +1225,7 @@ static void ed_mesh_pick_face_vert__mpoly_find(
const float mval[2],
/* mesh data (evaluated) */
const MPoly *mp,
- const MVert *mvert,
+ const Span<float3> positions,
const MLoop *mloop,
/* return values */
float *r_len_best,
@@ -1236,8 +1236,8 @@ static void ed_mesh_pick_face_vert__mpoly_find(
for (ml = &mloop[mp->loopstart]; j--; ml++) {
float sco[2];
const int v_idx = ml->v;
- const float *co = mvert[v_idx].co;
- if (ED_view3d_project_float_object(region, co, sco, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
+ if (ED_view3d_project_float_object(region, positions[v_idx], sco, V3D_PROJ_TEST_NOP) ==
+ V3D_PROJ_RET_OK) {
const float len_test = len_manhattan_v2v2(mval, sco);
if (len_test < *r_len_best) {
*r_len_best = len_test;
@@ -1270,7 +1270,7 @@ bool ED_mesh_pick_face_vert(
const float mval_f[2] = {float(mval[0]), float(mval[1])};
float len_best = FLT_MAX;
- const Span<MVert> verts = me_eval->verts();
+ const Span<float3> positions = me_eval->positions();
const Span<MPoly> polys = me_eval->polys();
const Span<MLoop> loops = me_eval->loops();
@@ -1281,19 +1281,14 @@ bool ED_mesh_pick_face_vert(
for (const int i : polys.index_range()) {
if (index_mp_to_orig[i] == poly_index) {
ed_mesh_pick_face_vert__mpoly_find(
- region, mval_f, &polys[i], verts.data(), loops.data(), &len_best, &v_idx_best);
+ region, mval_f, &polys[i], positions, loops.data(), &len_best, &v_idx_best);
}
}
}
else {
if (poly_index < polys.size()) {
- ed_mesh_pick_face_vert__mpoly_find(region,
- mval_f,
- &polys[poly_index],
- verts.data(),
- loops.data(),
- &len_best,
- &v_idx_best);
+ ed_mesh_pick_face_vert__mpoly_find(
+ region, mval_f, &polys[poly_index], positions, loops.data(), &len_best, &v_idx_best);
}
}
@@ -1322,7 +1317,7 @@ bool ED_mesh_pick_face_vert(
* \return boolean true == Found
*/
struct VertPickData {
- const MVert *mvert;
+ Span<float3> positions;
const bool *hide_vert;
const float *mval_f; /* [2] */
ARegion *region;
@@ -1397,7 +1392,7 @@ bool ED_mesh_pick_vert(
/* find the vert closest to 'mval' */
const float mval_f[2] = {float(mval[0]), float(mval[1])};
- VertPickData data = {nullptr};
+ VertPickData data{};
ED_view3d_init_mats_rv3d(ob, rv3d);
@@ -1406,8 +1401,7 @@ bool ED_mesh_pick_vert(
}
/* setup data */
- const Span<MVert> verts = me->verts();
- data.mvert = verts.data();
+ data.positions = me->positions();
data.region = region;
data.mval_f = mval_f;
data.len_best = FLT_MAX;
diff --git a/source/blender/editors/object/object_bake_api.c b/source/blender/editors/object/object_bake_api.c
index e69ccf5a50d..6a415427558 100644
--- a/source/blender/editors/object/object_bake_api.c
+++ b/source/blender/editors/object/object_bake_api.c
@@ -1032,7 +1032,7 @@ static void bake_targets_populate_pixels_color_attributes(BakeTargets *targets,
const MLoop *loops = BKE_mesh_loops(me_eval);
BKE_mesh_recalc_looptri(loops,
BKE_mesh_polys(me_eval),
- BKE_mesh_verts(me_eval),
+ BKE_mesh_positions(me_eval),
me_eval->totloop,
me_eval->totpoly,
looptri);
diff --git a/source/blender/editors/object/object_modifier.cc b/source/blender/editors/object/object_modifier.cc
index 67399717c72..013bbbf7e55 100644
--- a/source/blender/editors/object/object_modifier.cc
+++ b/source/blender/editors/object/object_modifier.cc
@@ -93,6 +93,7 @@
#include "object_intern.h"
+using blender::float3;
using blender::Span;
static void modifier_skin_customdata_delete(struct Object *ob);
@@ -590,13 +591,13 @@ bool ED_object_modifier_convert_psys_to_mesh(ReportList * /*reports*/,
me->totvert = verts_num;
me->totedge = edges_num;
- CustomData_add_layer(&me->vdata, CD_MVERT, CD_SET_DEFAULT, nullptr, verts_num);
+ CustomData_add_layer_named(
+ &me->vdata, CD_PROP_FLOAT3, CD_CONSTRUCT, nullptr, verts_num, "position");
CustomData_add_layer(&me->edata, CD_MEDGE, CD_SET_DEFAULT, nullptr, edges_num);
CustomData_add_layer(&me->fdata, CD_MFACE, CD_SET_DEFAULT, nullptr, 0);
- blender::MutableSpan<MVert> verts = me->verts_for_write();
+ blender::MutableSpan<float3> positions = me->positions_for_write();
blender::MutableSpan<MEdge> edges = me->edges_for_write();
- MVert *mvert = verts.data();
MEdge *medge = edges.data();
bke::MutableAttributeAccessor attributes = me->attributes_for_write();
@@ -610,7 +611,7 @@ bool ED_object_modifier_convert_psys_to_mesh(ReportList * /*reports*/,
ParticleCacheKey *key = cache[a];
int kmax = key->segments;
for (int k = 0; k <= kmax; k++, key++, cvert++, vert_index++) {
- copy_v3_v3(mvert[vert_index].co, key->co);
+ positions[vert_index] = key->co;
if (k) {
medge->v1 = cvert - 1;
medge->v2 = cvert;
@@ -629,7 +630,7 @@ bool ED_object_modifier_convert_psys_to_mesh(ReportList * /*reports*/,
ParticleCacheKey *key = cache[a];
int kmax = key->segments;
for (int k = 0; k <= kmax; k++, key++, cvert++, vert_index++) {
- copy_v3_v3(mvert[vert_index].co, key->co);
+ copy_v3_v3(positions[vert_index], key->co);
if (k) {
medge->v1 = cvert - 1;
medge->v2 = cvert;
@@ -2659,7 +2660,7 @@ void OBJECT_OT_skin_radii_equalize(wmOperatorType *ot)
}
static void skin_armature_bone_create(Object *skin_ob,
- const MVert *mvert,
+ const Span<float3> positions,
const MEdge *medge,
bArmature *arm,
BLI_bitmap *edges_visited,
@@ -2686,8 +2687,8 @@ static void skin_armature_bone_create(Object *skin_ob,
bone->flag |= BONE_CONNECTED;
}
- copy_v3_v3(bone->head, mvert[parent_v].co);
- copy_v3_v3(bone->tail, mvert[v].co);
+ copy_v3_v3(bone->head, positions[parent_v]);
+ copy_v3_v3(bone->tail, positions[v]);
bone->rad_head = bone->rad_tail = 0.25;
BLI_snprintf(bone->name, sizeof(bone->name), "Bone.%.2d", endx);
@@ -2698,14 +2699,14 @@ static void skin_armature_bone_create(Object *skin_ob,
ED_vgroup_vert_add(skin_ob, dg, v, 1, WEIGHT_REPLACE);
}
- skin_armature_bone_create(skin_ob, mvert, medge, arm, edges_visited, emap, bone, v);
+ skin_armature_bone_create(skin_ob, positions, medge, arm, edges_visited, emap, bone, v);
}
}
static Object *modifier_skin_armature_create(Depsgraph *depsgraph, Main *bmain, Object *skin_ob)
{
Mesh *me = static_cast<Mesh *>(skin_ob->data);
- const Span<MVert> me_verts = me->verts();
+ const Span<float3> me_positions = me->positions();
const Span<MEdge> me_edges = me->edges();
Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
@@ -2713,7 +2714,7 @@ static Object *modifier_skin_armature_create(Depsgraph *depsgraph, Main *bmain,
const Mesh *me_eval_deform = mesh_get_eval_deform(
depsgraph, scene_eval, ob_eval, &CD_MASK_BAREMESH);
- const Span<MVert> verts_eval = me_eval_deform->verts();
+ const Span<float3> positions_eval = me_eval_deform->positions();
/* add vertex weights to original mesh */
CustomData_add_layer(&me->vdata, CD_MDEFORMVERT, CD_SET_DEFAULT, nullptr, me->totvert);
@@ -2748,8 +2749,8 @@ static Object *modifier_skin_armature_create(Depsgraph *depsgraph, Main *bmain,
if (emap[v].count > 1) {
bone = ED_armature_ebone_add(arm, "Bone");
- copy_v3_v3(bone->head, me_verts[v].co);
- copy_v3_v3(bone->tail, me_verts[v].co);
+ copy_v3_v3(bone->head, me_positions[v]);
+ copy_v3_v3(bone->tail, me_positions[v]);
bone->head[1] = 1.0f;
bone->rad_head = bone->rad_tail = 0.25;
@@ -2757,7 +2758,7 @@ static Object *modifier_skin_armature_create(Depsgraph *depsgraph, Main *bmain,
if (emap[v].count >= 1) {
skin_armature_bone_create(
- skin_ob, verts_eval.data(), me_edges.data(), arm, edges_visited, emap, bone, v);
+ skin_ob, positions_eval, me_edges.data(), arm, edges_visited, emap, bone, v);
}
}
}
diff --git a/source/blender/editors/object/object_remesh.cc b/source/blender/editors/object/object_remesh.cc
index b9acf5ae27b..8c133dfecfa 100644
--- a/source/blender/editors/object/object_remesh.cc
+++ b/source/blender/editors/object/object_remesh.cc
@@ -73,6 +73,7 @@
#include "object_intern.h" /* own include */
+using blender::float3;
using blender::IndexRange;
using blender::Span;
@@ -681,7 +682,7 @@ static bool mesh_is_manifold_consistent(Mesh *mesh)
* check that the direction of the faces are consistent and doesn't suddenly
* flip
*/
- const Span<MVert> verts = mesh->verts();
+ const Span<float3> positions = mesh->positions();
const Span<MEdge> edges = mesh->edges();
const Span<MLoop> loops = mesh->loops();
@@ -719,9 +720,7 @@ static bool mesh_is_manifold_consistent(Mesh *mesh)
break;
}
/* Check for zero length edges */
- const MVert &v1 = verts[edges[i].v1];
- const MVert &v2 = verts[edges[i].v2];
- if (compare_v3v3(v1.co, v2.co, 1e-4f)) {
+ if (compare_v3v3(positions[edges[i].v1], positions[edges[i].v2], 1e-4f)) {
is_manifold_consistent = false;
break;
}
diff --git a/source/blender/editors/object/object_vgroup.cc b/source/blender/editors/object/object_vgroup.cc
index d3bdf8ca4d3..72b9b1b839c 100644
--- a/source/blender/editors/object/object_vgroup.cc
+++ b/source/blender/editors/object/object_vgroup.cc
@@ -68,6 +68,7 @@
#include "object_intern.h"
+using blender::float3;
using blender::MutableSpan;
using blender::Span;
@@ -1286,12 +1287,12 @@ static blender::Vector<int> getSurroundingVerts(Mesh *me, int vert)
* coord is the place the average is stored,
* points is the point cloud, count is the number of points in the cloud.
*/
-static void getSingleCoordinate(MVert *points, int count, float coord[3])
+static void getSingleCoordinate(float3 *points, int count, float coord[3])
{
int i;
zero_v3(coord);
for (i = 0; i < count; i++) {
- add_v3_v3(coord, points[i].co);
+ add_v3_v3(coord, points[i]);
}
mul_v3_fl(coord, 1.0f / count);
}
@@ -1357,7 +1358,7 @@ static void moveCloserToDistanceFromPlane(Depsgraph *depsgraph,
Mesh *me_deform;
MDeformWeight *dw, *dw_eval;
- MVert m;
+ float3 m;
MDeformVert *dvert = me->deform_verts_for_write().data() + index;
MDeformVert *dvert_eval = mesh_eval->deform_verts_for_write().data() + index;
int totweight = dvert->totweight;
@@ -1382,9 +1383,9 @@ static void moveCloserToDistanceFromPlane(Depsgraph *depsgraph,
do {
wasChange = false;
me_deform = mesh_get_eval_deform(depsgraph, scene_eval, object_eval, &CD_MASK_BAREMESH);
- const Span<MVert> verts = me_deform->verts();
- m = verts[index];
- copy_v3_v3(oldPos, m.co);
+ const Span<float3> positions = me_deform->positions();
+ m = positions[index];
+ copy_v3_v3(oldPos, m);
distToStart = dot_v3v3(norm, oldPos) + d;
if (distToBe == originalDistToBe) {
@@ -1425,9 +1426,8 @@ static void moveCloserToDistanceFromPlane(Depsgraph *depsgraph,
}
dw_eval->weight = dw->weight;
me_deform = mesh_get_eval_deform(depsgraph, scene_eval, object_eval, &CD_MASK_BAREMESH);
- m = verts[index];
- getVerticalAndHorizontalChange(
- norm, d, coord, oldPos, distToStart, m.co, changes, dists, i);
+ m = positions[index];
+ getVerticalAndHorizontalChange(norm, d, coord, oldPos, distToStart, m, changes, dists, i);
dw->weight = oldw;
dw_eval->weight = oldw;
if (!k) {
@@ -1531,28 +1531,27 @@ static void vgroup_fix(
int i;
Mesh *me = static_cast<Mesh *>(ob->data);
- MVert *mvert = me->verts_for_write().data();
if (!(me->editflag & ME_EDIT_PAINT_VERT_SEL)) {
return;
}
const bke::AttributeAccessor attributes = me->attributes();
const VArray<bool> select_vert = attributes.lookup_or_default<bool>(
".select_vert", ATTR_DOMAIN_POINT, false);
- for (i = 0; i < me->totvert && mvert; i++, mvert++) {
+ for (i = 0; i < me->totvert; i++) {
if (select_vert[i]) {
blender::Vector<int> verts = getSurroundingVerts(me, i);
const int count = verts.size();
if (!verts.is_empty()) {
- MVert m;
- MVert *p = static_cast<MVert *>(MEM_callocN(sizeof(MVert) * (count), "deformedPoints"));
+ float3 m;
+ float3 *p = static_cast<float3 *>(MEM_callocN(sizeof(float3) * (count), "deformedPoints"));
int k;
Mesh *me_deform = mesh_get_eval_deform(
depsgraph, scene_eval, object_eval, &CD_MASK_BAREMESH);
- const Span<MVert> verts_deform = me_deform->verts();
+ const Span<float3> positions_deform = me_deform->positions();
k = count;
while (k--) {
- p[k] = verts_deform[verts[k]];
+ p[k] = positions_deform[verts[k]];
}
if (count >= 3) {
@@ -1560,8 +1559,8 @@ static void vgroup_fix(
float coord[3];
float norm[3];
getSingleCoordinate(p, count, coord);
- m = verts_deform[i];
- sub_v3_v3v3(norm, m.co, coord);
+ m = positions_deform[i];
+ sub_v3_v3v3(norm, m, coord);
mag = normalize_v3(norm);
if (mag) { /* zeros fix */
d = -dot_v3v3(norm, coord);
diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c
index 22295c260e2..c4871f1e9f4 100644
--- a/source/blender/editors/physics/particle_edit.c
+++ b/source/blender/editors/physics/particle_edit.c
@@ -1452,28 +1452,23 @@ void recalc_emitter_field(Depsgraph *UNUSED(depsgraph), Object *UNUSED(ob), Part
vec = edit->emitter_cosnos;
nor = vec + 3;
- const MVert *verts = BKE_mesh_verts(mesh);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(mesh);
MFace *mfaces = (MFace *)CustomData_get_layer(&mesh->fdata, CD_MFACE);
for (i = 0; i < totface; i++, vec += 6, nor += 6) {
MFace *mface = &mfaces[i];
- const MVert *mvert;
- mvert = &verts[mface->v1];
- copy_v3_v3(vec, mvert->co);
+ copy_v3_v3(vec, positions[mface->v1]);
copy_v3_v3(nor, vert_normals[mface->v1]);
- mvert = &verts[mface->v2];
- add_v3_v3v3(vec, vec, mvert->co);
+ add_v3_v3v3(vec, vec, positions[mface->v2]);
add_v3_v3(nor, vert_normals[mface->v2]);
- mvert = &verts[mface->v3];
- add_v3_v3v3(vec, vec, mvert->co);
+ add_v3_v3v3(vec, vec, positions[mface->v3]);
add_v3_v3(nor, vert_normals[mface->v3]);
if (mface->v4) {
- mvert = &verts[mface->v4];
- add_v3_v3v3(vec, vec, mvert->co);
+ add_v3_v3v3(vec, vec, positions[mface->v4]);
add_v3_v3(nor, vert_normals[mface->v4]);
mul_v3_fl(vec, 0.25);
@@ -4142,7 +4137,6 @@ static int particle_intersect_mesh(Depsgraph *depsgraph,
float *ipoint)
{
MFace *mface = NULL;
- MVert *mvert = NULL;
int i, totface, intersect = 0;
float cur_d, cur_uv[2], v1[3], v2[3], v3[3], v4[3], min[3], max[3], p_min[3], p_max[3];
float cur_ipoint[3];
@@ -4180,7 +4174,7 @@ static int particle_intersect_mesh(Depsgraph *depsgraph,
totface = mesh->totface;
mface = (MFace *)CustomData_get_layer(&mesh->fdata, CD_MFACE);
- mvert = BKE_mesh_verts_for_write(mesh);
+ float(*positions)[3] = BKE_mesh_positions_for_write(mesh);
/* lets intersect the faces */
for (i = 0; i < totface; i++, mface++) {
@@ -4193,11 +4187,11 @@ static int particle_intersect_mesh(Depsgraph *depsgraph,
}
}
else {
- copy_v3_v3(v1, mvert[mface->v1].co);
- copy_v3_v3(v2, mvert[mface->v2].co);
- copy_v3_v3(v3, mvert[mface->v3].co);
+ copy_v3_v3(v1, positions[mface->v1]);
+ copy_v3_v3(v2, positions[mface->v2]);
+ copy_v3_v3(v3, positions[mface->v3]);
if (mface->v4) {
- copy_v3_v3(v4, mvert[mface->v4].co);
+ copy_v3_v3(v4, positions[mface->v4]);
}
}
diff --git a/source/blender/editors/physics/particle_object.c b/source/blender/editors/physics/particle_object.c
index 852156f9403..0ee93da70a1 100644
--- a/source/blender/editors/physics/particle_object.c
+++ b/source/blender/editors/physics/particle_object.c
@@ -707,7 +707,6 @@ static bool remap_hair_emitter(Depsgraph *depsgraph,
BVHTreeFromMesh bvhtree = {NULL};
MFace *mface = NULL, *mf;
const MEdge *medge = NULL, *me;
- MVert *mvert;
Mesh *mesh, *target_mesh;
int numverts;
int k;
@@ -752,11 +751,11 @@ static bool remap_hair_emitter(Depsgraph *depsgraph,
BKE_mesh_tessface_ensure(mesh);
numverts = mesh->totvert;
- mvert = BKE_mesh_verts_for_write(mesh);
+ float(*positions)[3] = BKE_mesh_positions_for_write(mesh);
/* convert to global coordinates */
for (int i = 0; i < numverts; i++) {
- mul_m4_v3(to_mat, mvert[i].co);
+ mul_m4_v3(to_mat, positions[i]);
}
if (mesh->totface != 0) {
@@ -803,11 +802,11 @@ static bool remap_hair_emitter(Depsgraph *depsgraph,
mf = &mface[nearest.index];
- copy_v3_v3(v[0], mvert[mf->v1].co);
- copy_v3_v3(v[1], mvert[mf->v2].co);
- copy_v3_v3(v[2], mvert[mf->v3].co);
+ copy_v3_v3(v[0], positions[mf->v1]);
+ copy_v3_v3(v[1], positions[mf->v2]);
+ copy_v3_v3(v[2], positions[mf->v3]);
if (mf->v4) {
- copy_v3_v3(v[3], mvert[mf->v4].co);
+ copy_v3_v3(v[3], positions[mf->v4]);
interp_weights_poly_v3(tpa->fuv, v, 4, nearest.co);
}
else {
@@ -827,7 +826,7 @@ static bool remap_hair_emitter(Depsgraph *depsgraph,
else {
me = &medge[nearest.index];
- tpa->fuv[1] = line_point_factor_v3(nearest.co, mvert[me->v1].co, mvert[me->v2].co);
+ tpa->fuv[1] = line_point_factor_v3(nearest.co, positions[me->v1], positions[me->v2]);
tpa->fuv[0] = 1.0f - tpa->fuv[1];
tpa->fuv[2] = tpa->fuv[3] = 0.0f;
tpa->foffset = 0.0f;
diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_add.cc b/source/blender/editors/sculpt_paint/curves_sculpt_add.cc
index 0d2c2d3f0c9..322cdd1d8eb 100644
--- a/source/blender/editors/sculpt_paint/curves_sculpt_add.cc
+++ b/source/blender/editors/sculpt_paint/curves_sculpt_add.cc
@@ -90,7 +90,7 @@ struct AddOperationExecutor {
Object *surface_ob_eval_ = nullptr;
Mesh *surface_eval_ = nullptr;
- Span<MVert> surface_verts_eval_;
+ Span<float3> surface_positions_eval_;
Span<MLoop> surface_loops_eval_;
Span<MLoopTri> surface_looptris_eval_;
VArraySpan<float2> surface_uv_map_eval_;
@@ -142,7 +142,7 @@ struct AddOperationExecutor {
report_empty_evaluated_surface(stroke_extension.reports);
return;
}
- surface_verts_eval_ = surface_eval_->verts();
+ surface_positions_eval_ = surface_eval_->positions();
surface_loops_eval_ = surface_eval_->loops();
surface_looptris_eval_ = surface_eval_->looptris();
BKE_bvhtree_from_mesh_get(&surface_bvh_eval_, surface_eval_, BVHTREE_FROM_LOOPTRI, 2);
@@ -295,7 +295,7 @@ struct AddOperationExecutor {
const MLoopTri &looptri = surface_looptris_eval_[looptri_index];
const float3 brush_pos_su = ray_hit.co;
const float3 bary_coords = bke::mesh_surface_sample::compute_bary_coord_in_triangle(
- surface_verts_eval_, surface_loops_eval_, looptri, brush_pos_su);
+ surface_positions_eval_, surface_loops_eval_, looptri, brush_pos_su);
const float2 uv = bke::mesh_surface_sample::sample_corner_attrribute_with_bary_coords(
bary_coords, looptri, surface_uv_map_eval_);
@@ -420,9 +420,9 @@ struct AddOperationExecutor {
brush_radius_su,
[&](const int index, const float3 & /*co*/, const float /*dist_sq*/) {
const MLoopTri &looptri = surface_looptris_eval_[index];
- const float3 v0_su = surface_verts_eval_[surface_loops_eval_[looptri.tri[0]].v].co;
- const float3 v1_su = surface_verts_eval_[surface_loops_eval_[looptri.tri[1]].v].co;
- const float3 v2_su = surface_verts_eval_[surface_loops_eval_[looptri.tri[2]].v].co;
+ const float3 &v0_su = surface_positions_eval_[surface_loops_eval_[looptri.tri[0]].v];
+ const float3 &v1_su = surface_positions_eval_[surface_loops_eval_[looptri.tri[1]].v];
+ const float3 &v2_su = surface_positions_eval_[surface_loops_eval_[looptri.tri[2]].v];
float3 normal_su;
normal_tri_v3(normal_su, v0_su, v1_su, v2_su);
if (math::dot(normal_su, view_direction_su) >= 0.0f) {
diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_puff.cc b/source/blender/editors/sculpt_paint/curves_sculpt_puff.cc
index b4e949106e7..465d3e4c0d1 100644
--- a/source/blender/editors/sculpt_paint/curves_sculpt_puff.cc
+++ b/source/blender/editors/sculpt_paint/curves_sculpt_puff.cc
@@ -70,7 +70,7 @@ struct PuffOperationExecutor {
Object *surface_ob_ = nullptr;
Mesh *surface_ = nullptr;
- Span<MVert> surface_verts_;
+ Span<float3> surface_positions_;
Span<MLoop> surface_loops_;
Span<MLoopTri> surface_looptris_;
Span<float3> corner_normals_su_;
@@ -119,7 +119,7 @@ struct PuffOperationExecutor {
reinterpret_cast<const float3 *>(CustomData_get_layer(&surface_->ldata, CD_NORMAL)),
surface_->totloop};
- surface_verts_ = surface_->verts();
+ surface_positions_ = surface_->positions();
surface_loops_ = surface_->loops();
surface_looptris_ = surface_->looptris();
BKE_bvhtree_from_mesh_get(&surface_bvh_, surface_, BVHTREE_FROM_LOOPTRI, 2);
@@ -291,9 +291,9 @@ struct PuffOperationExecutor {
const MLoopTri &looptri = surface_looptris_[nearest.index];
const float3 closest_pos_su = nearest.co;
- const float3 &v0_su = surface_verts_[surface_loops_[looptri.tri[0]].v].co;
- const float3 &v1_su = surface_verts_[surface_loops_[looptri.tri[1]].v].co;
- const float3 &v2_su = surface_verts_[surface_loops_[looptri.tri[2]].v].co;
+ const float3 &v0_su = surface_positions_[surface_loops_[looptri.tri[0]].v];
+ const float3 &v1_su = surface_positions_[surface_loops_[looptri.tri[1]].v];
+ const float3 &v2_su = surface_positions_[surface_loops_[looptri.tri[2]].v];
float3 bary_coords;
interp_weights_tri_v3(bary_coords, v0_su, v1_su, v2_su, closest_pos_su);
const float3 normal_su = geometry::compute_surface_point_normal(
diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc b/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc
index ae89bc1c58b..199efab86a6 100644
--- a/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc
+++ b/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc
@@ -104,7 +104,7 @@ struct SlideOperationExecutor {
Object *surface_ob_eval_ = nullptr;
Mesh *surface_eval_ = nullptr;
- Span<MVert> surface_verts_eval_;
+ Span<float3> surface_positions_eval_;
Span<MLoop> surface_loops_eval_;
Span<MLoopTri> surface_looptris_eval_;
VArraySpan<float2> surface_uv_map_eval_;
@@ -197,7 +197,7 @@ struct SlideOperationExecutor {
return;
}
surface_looptris_eval_ = surface_eval_->looptris();
- surface_verts_eval_ = surface_eval_->verts();
+ surface_positions_eval_ = surface_eval_->positions();
surface_loops_eval_ = surface_eval_->loops();
surface_uv_map_eval_ = surface_eval_->attributes().lookup<float2>(uv_map_name,
ATTR_DOMAIN_CORNER);
@@ -313,7 +313,7 @@ struct SlideOperationExecutor {
{
const float4x4 brush_transform_inv = brush_transform.inverted();
- const Span<MVert> verts_orig_su = surface_orig_->verts();
+ const Span<float3> positions_orig_su = surface_orig_->positions();
const Span<MLoop> loops_orig = surface_orig_->loops();
MutableSpan<float3> positions_orig_cu = curves_orig_->positions_for_write();
@@ -377,7 +377,7 @@ struct SlideOperationExecutor {
/* Compute the uv of the new surface position on the evaluated mesh. */
const MLoopTri &looptri_eval = surface_looptris_eval_[looptri_index_eval];
const float3 bary_weights_eval = bke::mesh_surface_sample::compute_bary_coord_in_triangle(
- surface_verts_eval_, surface_loops_eval_, looptri_eval, hit_pos_eval_su);
+ surface_positions_eval_, surface_loops_eval_, looptri_eval, hit_pos_eval_su);
const float2 uv = attribute_math::mix3(bary_weights_eval,
surface_uv_map_eval_[looptri_eval.tri[0]],
surface_uv_map_eval_[looptri_eval.tri[1]],
@@ -404,9 +404,9 @@ struct SlideOperationExecutor {
const float3 new_first_pos_orig_cu =
transforms_.surface_to_curves *
attribute_math::mix3<float3>(bary_weights_orig,
- verts_orig_su[loops_orig[looptri_orig.tri[0]].v].co,
- verts_orig_su[loops_orig[looptri_orig.tri[1]].v].co,
- verts_orig_su[loops_orig[looptri_orig.tri[2]].v].co);
+ positions_orig_su[loops_orig[looptri_orig.tri[0]].v],
+ positions_orig_su[loops_orig[looptri_orig.tri[1]].v],
+ positions_orig_su[loops_orig[looptri_orig.tri[2]].v]);
/* Actually transform curve points. */
const float4x4 slide_transform = this->get_slide_transform(
diff --git a/source/blender/editors/sculpt_paint/paint_hide.c b/source/blender/editors/sculpt_paint/paint_hide.c
index 9e435ee0748..83be327fc38 100644
--- a/source/blender/editors/sculpt_paint/paint_hide.c
+++ b/source/blender/editors/sculpt_paint/paint_hide.c
@@ -68,14 +68,13 @@ static void partialvis_update_mesh(Object *ob,
float planes[4][4])
{
Mesh *me = ob->data;
- MVert *mvert;
+ const float(*positions)[3] = BKE_pbvh_get_positions(pbvh);
const float *paint_mask;
- const int *vert_indices;
int totvert, i;
bool any_changed = false, any_visible = false;
BKE_pbvh_node_num_verts(pbvh, node, NULL, &totvert);
- BKE_pbvh_node_get_verts(pbvh, node, &vert_indices, &mvert);
+ const int *vert_indices = BKE_pbvh_node_get_vert_indices(node);
paint_mask = CustomData_get_layer(&me->vdata, CD_PAINT_MASK);
bool *hide_vert = CustomData_get_layer_named(&me->vdata, CD_PROP_BOOL, ".hide_vert");
@@ -87,11 +86,10 @@ static void partialvis_update_mesh(Object *ob,
SCULPT_undo_push_node(ob, node, SCULPT_UNDO_HIDDEN);
for (i = 0; i < totvert; i++) {
- MVert *v = &mvert[vert_indices[i]];
float vmask = paint_mask ? paint_mask[vert_indices[i]] : 0;
/* Hide vertex if in the hide volume. */
- if (is_effected(area, planes, v->co, vmask)) {
+ if (is_effected(area, planes, positions[vert_indices[i]], vmask)) {
hide_vert[vert_indices[i]] = (action == PARTIALVIS_HIDE);
any_changed = true;
}
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index c85044bf915..47f1e7ec160 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -412,7 +412,7 @@ typedef struct ProjPaintState {
int totedge_eval;
int totvert_eval;
- const MVert *mvert_eval;
+ const float (*positions_eval)[3];
const float (*vert_normals)[3];
const MEdge *medge_eval;
const MPoly *mpoly_eval;
@@ -920,9 +920,9 @@ static bool project_bucket_point_occluded(const ProjPaintState *ps,
if (do_clip) {
const float *vtri_co[3] = {
- ps->mvert_eval[ps->mloop_eval[lt->tri[0]].v].co,
- ps->mvert_eval[ps->mloop_eval[lt->tri[1]].v].co,
- ps->mvert_eval[ps->mloop_eval[lt->tri[2]].v].co,
+ ps->positions_eval[ps->mloop_eval[lt->tri[0]].v],
+ ps->positions_eval[ps->mloop_eval[lt->tri[1]].v],
+ ps->positions_eval[ps->mloop_eval[lt->tri[2]].v],
};
isect_ret = project_paint_occlude_ptv_clip(
pixelScreenCo, UNPACK3(vtri_ss), UNPACK3(vtri_co), w, ps->is_ortho, ps->rv3d);
@@ -1734,9 +1734,9 @@ static float project_paint_uvpixel_mask(const ProjPaintState *ps,
/* In case the normalizing per pixel isn't optimal,
* we could cache or access from evaluated mesh. */
normal_tri_v3(no,
- ps->mvert_eval[lt_vtri[0]].co,
- ps->mvert_eval[lt_vtri[1]].co,
- ps->mvert_eval[lt_vtri[2]].co);
+ ps->positions_eval[lt_vtri[0]],
+ ps->positions_eval[lt_vtri[1]],
+ ps->positions_eval[lt_vtri[2]]);
}
if (UNLIKELY(ps->is_flip_object)) {
@@ -1751,9 +1751,9 @@ static float project_paint_uvpixel_mask(const ProjPaintState *ps,
/* Annoying but for the perspective view we need to get the pixels location in 3D space :/ */
float viewDirPersp[3];
const float *co1, *co2, *co3;
- co1 = ps->mvert_eval[lt_vtri[0]].co;
- co2 = ps->mvert_eval[lt_vtri[1]].co;
- co3 = ps->mvert_eval[lt_vtri[2]].co;
+ co1 = ps->positions_eval[lt_vtri[0]];
+ co2 = ps->positions_eval[lt_vtri[1]];
+ co3 = ps->positions_eval[lt_vtri[2]];
/* Get the direction from the viewPoint to the pixel and normalize */
viewDirPersp[0] = (ps->viewPos[0] - (w[0] * co1[0] + w[1] * co2[0] + w[2] * co3[0]));
@@ -3027,9 +3027,9 @@ static void project_paint_face_init(const ProjPaintState *ps,
const bool do_backfacecull = ps->do_backfacecull;
const bool do_clip = RV3D_CLIPPING_ENABLED(ps->v3d, ps->rv3d);
- vCo[0] = ps->mvert_eval[lt_vtri[0]].co;
- vCo[1] = ps->mvert_eval[lt_vtri[1]].co;
- vCo[2] = ps->mvert_eval[lt_vtri[2]].co;
+ vCo[0] = ps->positions_eval[lt_vtri[0]];
+ vCo[1] = ps->positions_eval[lt_vtri[1]];
+ vCo[2] = ps->positions_eval[lt_vtri[2]];
/* Use lt_uv_pxoffset instead of lt_tri_uv so we can offset the UV half a pixel
* this is done so we can avoid offsetting all the pixels by 0.5 which causes
@@ -3126,9 +3126,9 @@ static void project_paint_face_init(const ProjPaintState *ps,
* because it is a relatively expensive operation. */
if (do_clip || do_3d_mapping) {
interp_v3_v3v3v3(wco,
- ps->mvert_eval[lt_vtri[0]].co,
- ps->mvert_eval[lt_vtri[1]].co,
- ps->mvert_eval[lt_vtri[2]].co,
+ ps->positions_eval[lt_vtri[0]],
+ ps->positions_eval[lt_vtri[1]],
+ ps->positions_eval[lt_vtri[2]],
w);
if (do_clip && ED_view3d_clipping_test(ps->rv3d, wco, true)) {
/* Watch out that no code below this needs to run */
@@ -3789,7 +3789,6 @@ static void proj_paint_state_viewport_init(ProjPaintState *ps, const char symmet
static void proj_paint_state_screen_coords_init(ProjPaintState *ps, const int diameter)
{
- const MVert *mv;
float *projScreenCo;
float projMargin;
int a;
@@ -3800,8 +3799,8 @@ static void proj_paint_state_screen_coords_init(ProjPaintState *ps, const int di
projScreenCo = *ps->screenCoords;
if (ps->is_ortho) {
- for (a = 0, mv = ps->mvert_eval; a < ps->totvert_eval; a++, mv++, projScreenCo += 4) {
- mul_v3_m4v3(projScreenCo, ps->projectMat, mv->co);
+ for (a = 0; a < ps->totvert_eval; a++, projScreenCo += 4) {
+ mul_v3_m4v3(projScreenCo, ps->projectMat, ps->positions_eval[a]);
/* screen space, not clamped */
projScreenCo[0] = (float)(ps->winx * 0.5f) + (ps->winx * 0.5f) * projScreenCo[0];
@@ -3810,8 +3809,8 @@ static void proj_paint_state_screen_coords_init(ProjPaintState *ps, const int di
}
}
else {
- for (a = 0, mv = ps->mvert_eval; a < ps->totvert_eval; a++, mv++, projScreenCo += 4) {
- copy_v3_v3(projScreenCo, mv->co);
+ for (a = 0; a < ps->totvert_eval; a++, projScreenCo += 4) {
+ copy_v3_v3(projScreenCo, ps->positions_eval[a]);
projScreenCo[3] = 1.0f;
mul_m4_v4(ps->projectMat, projScreenCo);
@@ -3880,7 +3879,7 @@ static void proj_paint_state_cavity_init(ProjPaintState *ps)
for (a = 0, me = ps->medge_eval; a < ps->totedge_eval; a++, me++) {
float e[3];
- sub_v3_v3v3(e, ps->mvert_eval[me->v1].co, ps->mvert_eval[me->v2].co);
+ sub_v3_v3v3(e, ps->positions_eval[me->v1], ps->positions_eval[me->v2]);
normalize_v3(e);
add_v3_v3(edges[me->v2], e);
counter[me->v2]++;
@@ -3951,13 +3950,12 @@ static void proj_paint_state_vert_flags_init(ProjPaintState *ps)
{
if (ps->do_backfacecull && ps->do_mask_normal) {
float viewDirPersp[3];
- const MVert *mv;
float no[3];
int a;
ps->vertFlags = MEM_callocN(sizeof(char) * ps->totvert_eval, "paint-vertFlags");
- for (a = 0, mv = ps->mvert_eval; a < ps->totvert_eval; a++, mv++) {
+ for (a = 0; a < ps->totvert_eval; a++) {
copy_v3_v3(no, ps->vert_normals[a]);
if (UNLIKELY(ps->is_flip_object)) {
negate_v3(no);
@@ -3970,7 +3968,7 @@ static void proj_paint_state_vert_flags_init(ProjPaintState *ps)
}
}
else {
- sub_v3_v3v3(viewDirPersp, ps->viewPos, mv->co);
+ sub_v3_v3v3(viewDirPersp, ps->viewPos, ps->positions_eval[a]);
normalize_v3(viewDirPersp);
if (UNLIKELY(ps->is_flip_object)) {
negate_v3(viewDirPersp);
@@ -4057,7 +4055,7 @@ static bool proj_paint_state_mesh_eval_init(const bContext *C, ProjPaintState *p
}
ps->mat_array[totmat - 1] = NULL;
- ps->mvert_eval = BKE_mesh_verts(ps->me_eval);
+ ps->positions_eval = BKE_mesh_positions(ps->me_eval);
ps->vert_normals = BKE_mesh_vertex_normals_ensure(ps->me_eval);
if (ps->do_mask_cavity) {
ps->medge_eval = BKE_mesh_edges(ps->me_eval);
@@ -5670,9 +5668,9 @@ static bool project_paint_op(void *state, const float lastpos[2], const float po
UnifiedPaintSettings *ups = &ps->scene->toolsettings->unified_paint_settings;
interp_v3_v3v3v3(world,
- ps->mvert_eval[lt_vtri[0]].co,
- ps->mvert_eval[lt_vtri[1]].co,
- ps->mvert_eval[lt_vtri[2]].co,
+ ps->positions_eval[lt_vtri[0]],
+ ps->positions_eval[lt_vtri[1]],
+ ps->positions_eval[lt_vtri[2]],
w);
ups->average_stroke_counter++;
diff --git a/source/blender/editors/sculpt_paint/paint_mask.c b/source/blender/editors/sculpt_paint/paint_mask.c
index ce7db91571c..82ed4418362 100644
--- a/source/blender/editors/sculpt_paint/paint_mask.c
+++ b/source/blender/editors/sculpt_paint/paint_mask.c
@@ -1137,7 +1137,7 @@ static void sculpt_gesture_trim_geometry_generate(SculptGestureContext *sgcontex
const float(*ob_imat)[4] = vc->obact->world_to_object;
/* Write vertices coordinates for the front face. */
- MVert *verts = BKE_mesh_verts_for_write(trim_operation->mesh);
+ float(*positions)[3] = BKE_mesh_positions_for_write(trim_operation->mesh);
float depth_point[3];
madd_v3_v3v3fl(depth_point, shape_origin, shape_normal, depth_front);
for (int i = 0; i < tot_screen_points; i++) {
@@ -1149,7 +1149,7 @@ static void sculpt_gesture_trim_geometry_generate(SculptGestureContext *sgcontex
ED_view3d_win_to_3d_on_plane(region, shape_plane, screen_points[i], false, new_point);
madd_v3_v3fl(new_point, shape_normal, depth_front);
}
- mul_v3_m4v3(verts[i].co, ob_imat, new_point);
+ mul_v3_m4v3(positions[i], ob_imat, new_point);
mul_v3_m4v3(trim_operation->true_mesh_co[i], ob_imat, new_point);
}
@@ -1164,7 +1164,7 @@ static void sculpt_gesture_trim_geometry_generate(SculptGestureContext *sgcontex
ED_view3d_win_to_3d_on_plane(region, shape_plane, screen_points[i], false, new_point);
madd_v3_v3fl(new_point, shape_normal, depth_back);
}
- mul_v3_m4v3(verts[i + tot_screen_points].co, ob_imat, new_point);
+ mul_v3_m4v3(positions[i + tot_screen_points], ob_imat, new_point);
mul_v3_m4v3(trim_operation->true_mesh_co[i + tot_screen_points], ob_imat, new_point);
}
@@ -1346,9 +1346,9 @@ static void sculpt_gesture_trim_apply_for_symmetry_pass(bContext *UNUSED(C),
{
SculptGestureTrimOperation *trim_operation = (SculptGestureTrimOperation *)sgcontext->operation;
Mesh *trim_mesh = trim_operation->mesh;
- MVert *verts = BKE_mesh_verts_for_write(trim_mesh);
+ float(*positions)[3] = BKE_mesh_positions_for_write(trim_mesh);
for (int i = 0; i < trim_mesh->totvert; i++) {
- flip_v3_v3(verts[i].co, trim_operation->true_mesh_co[i], sgcontext->symmpass);
+ flip_v3_v3(positions[i], trim_operation->true_mesh_co[i], sgcontext->symmpass);
}
sculpt_gesture_trim_normals_update(sgcontext);
sculpt_gesture_apply_trim(sgcontext);
@@ -1457,7 +1457,7 @@ static void project_line_gesture_apply_task_cb(void *__restrict userdata,
continue;
}
add_v3_v3(vd.co, disp);
- if (vd.mvert) {
+ if (vd.mesh_positions) {
BKE_pbvh_vert_tag_update_normal(sgcontext->ss->pbvh, vd.vertex);
}
any_updated = true;
diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c
index f87ca073c82..a33fa3b45ae 100644
--- a/source/blender/editors/sculpt_paint/paint_utils.c
+++ b/source/blender/editors/sculpt_paint/paint_utils.c
@@ -288,7 +288,7 @@ static void imapaint_pick_uv(
const MLoopTri *lt = BKE_mesh_runtime_looptri_ensure(me_eval);
const int tottri = BKE_mesh_runtime_looptri_len(me_eval);
- const MVert *mvert = BKE_mesh_verts(me_eval);
+ const float(*positions)[3] = BKE_mesh_positions(me_eval);
const MLoop *mloop = BKE_mesh_loops(me_eval);
const int *index_mp_to_orig = CustomData_get_layer(&me_eval->pdata, CD_ORIGINDEX);
@@ -317,7 +317,7 @@ static void imapaint_pick_uv(
float tri_co[3][3];
for (int j = 3; j--;) {
- copy_v3_v3(tri_co[j], mvert[mloop[lt->tri[j]].v].co);
+ copy_v3_v3(tri_co[j], positions[mloop[lt->tri[j]].v]);
}
if (mode == PAINT_CANVAS_SOURCE_MATERIAL) {
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.cc b/source/blender/editors/sculpt_paint/paint_vertex.cc
index 8758d3fa83f..f9f22173c05 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.cc
+++ b/source/blender/editors/sculpt_paint/paint_vertex.cc
@@ -2065,7 +2065,7 @@ static void do_wpaint_brush_smear_task_cb_ex(void *__restrict userdata,
* Otherwise, take the current vert. */
const int v_index = has_grids ? ss->mloop[vd.grid_indices[vd.g]].v : vd.vert_indices[vd.i];
const float grid_alpha = has_grids ? 1.0f / vd.gridsize : 1.0f;
- const MVert *mv_curr = &ss->mvert[v_index];
+ const float3 &mv_curr = ss->positions[v_index];
/* If the vertex is selected */
if (!(use_face_sel || use_vert_sel) || select_vert[v_index]) {
@@ -2092,11 +2092,11 @@ static void do_wpaint_brush_smear_task_cb_ex(void *__restrict userdata,
for (int k = 0; k < mp->totloop; k++, ml_other++) {
const uint v_other_index = ml_other->v;
if (v_other_index != v_index) {
- const MVert *mv_other = &ss->mvert[v_other_index];
+ const float3 &mv_other = ss->positions[v_other_index];
/* Get the direction from the selected vert to the neighbor. */
float other_dir[3];
- sub_v3_v3v3(other_dir, mv_curr->co, mv_other->co);
+ sub_v3_v3v3(other_dir, mv_curr, mv_other);
project_plane_v3_v3v3(other_dir, other_dir, cache->view_normal);
normalize_v3(other_dir);
@@ -3302,7 +3302,7 @@ static void do_vpaint_brush_smear(bContext *C,
const int v_index = has_grids ? ss->mloop[vd.grid_indices[vd.g]].v :
vd.vert_indices[vd.i];
const float grid_alpha = has_grids ? 1.0f / vd.gridsize : 1.0f;
- const MVert *mv_curr = &ss->mvert[v_index];
+ const float3 &mv_curr = &ss->positions[v_index];
/* if the vertex is selected for painting. */
if (!use_vert_sel || select_vert[v_index]) {
@@ -3339,12 +3339,12 @@ static void do_vpaint_brush_smear(bContext *C,
for (int k = 0; k < mp->totloop; k++, ml_other++) {
const uint v_other_index = ml_other->v;
if (v_other_index != v_index) {
- const MVert *mv_other = &ss->mvert[v_other_index];
+ const float3 &mv_other = &ss->positions[v_other_index];
/* Get the direction from the
* selected vert to the neighbor. */
float other_dir[3];
- sub_v3_v3v3(other_dir, mv_curr->co, mv_other->co);
+ sub_v3_v3v3(other_dir, mv_curr, mv_other);
project_plane_v3_v3v3(other_dir, other_dir, cache->view_normal);
normalize_v3(other_dir);
diff --git a/source/blender/editors/sculpt_paint/sculpt.cc b/source/blender/editors/sculpt_paint/sculpt.cc
index 684fcdbff9e..3021e058719 100644
--- a/source/blender/editors/sculpt_paint/sculpt.cc
+++ b/source/blender/editors/sculpt_paint/sculpt.cc
@@ -106,10 +106,10 @@ const float *SCULPT_vertex_co_get(SculptSession *ss, PBVHVertRef vertex)
switch (BKE_pbvh_type(ss->pbvh)) {
case PBVH_FACES: {
if (ss->shapekey_active || ss->deform_modifiers_active) {
- const MVert *mverts = BKE_pbvh_get_verts(ss->pbvh);
- return mverts[vertex.i].co;
+ const float(*positions)[3] = BKE_pbvh_get_positions(ss->pbvh);
+ return positions[vertex.i];
}
- return ss->mvert[vertex.i].co;
+ return ss->positions[vertex.i];
}
case PBVH_BMESH:
return ((BMVert *)vertex.i)->co;
@@ -185,12 +185,12 @@ const float *SCULPT_vertex_co_for_grab_active_get(SculptSession *ss, PBVHVertRef
if (BKE_pbvh_type(ss->pbvh) == PBVH_FACES) {
/* Always grab active shape key if the sculpt happens on shapekey. */
if (ss->shapekey_active) {
- const MVert *mverts = BKE_pbvh_get_verts(ss->pbvh);
- return mverts[vertex.i].co;
+ const float(*positions)[3] = BKE_pbvh_get_positions(ss->pbvh);
+ return positions[vertex.i];
}
/* Sculpting on the base mesh. */
- return ss->mvert[vertex.i].co;
+ return ss->positions[vertex.i];
}
/* Everything else, such as sculpting on multires. */
@@ -271,14 +271,14 @@ void SCULPT_active_vertex_normal_get(SculptSession *ss, float normal[3])
SCULPT_vertex_normal_get(ss, SCULPT_active_vertex_get(ss), normal);
}
-MVert *SCULPT_mesh_deformed_mverts_get(SculptSession *ss)
+float (*SCULPT_mesh_deformed_positions_get(SculptSession *ss))[3]
{
switch (BKE_pbvh_type(ss->pbvh)) {
case PBVH_FACES:
if (ss->shapekey_active || ss->deform_modifiers_active) {
- return BKE_pbvh_get_verts(ss->pbvh);
+ return BKE_pbvh_get_positions(ss->pbvh);
}
- return ss->mvert;
+ return ss->positions;
case PBVH_BMESH:
case PBVH_GRIDS:
return nullptr;
@@ -1500,7 +1500,7 @@ static void paint_mesh_restore_co_task_cb(void *__restrict userdata,
else {
copy_v3_v3(vd.fno, orig_data.no);
}
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -3134,7 +3134,7 @@ static void do_gravity_task_cb_ex(void *__restrict userdata,
mul_v3_v3fl(proxy[vd.i], offset, fade);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -3202,12 +3202,7 @@ void SCULPT_vertcos_to_key(Object *ob, KeyBlock *kb, const float (*vertCos)[3])
/* Modifying of basis key should update mesh. */
if (kb == me->key->refkey) {
- MVert *verts = BKE_mesh_verts_for_write(me);
-
- for (a = 0; a < me->totvert; a++) {
- copy_v3_v3(verts[a].co, vertCos[a]);
- }
- BKE_mesh_tag_coords_changed(me);
+ BKE_mesh_vert_coords_apply(me, vertCos);
}
/* Apply new coords on active key block, no need to re-allocate kb->data here! */
@@ -3636,9 +3631,9 @@ static void sculpt_flush_pbvhvert_deform(Object *ob, PBVHVertexIter *vd)
copy_v3_v3(ss->deform_cos[index], vd->co);
copy_v3_v3(ss->orig_cos[index], newco);
- MVert *verts = BKE_mesh_verts_for_write(me);
+ float(*positions)[3] = BKE_mesh_positions_for_write(me);
if (!ss->shapekey_active) {
- copy_v3_v3(verts[index].co, newco);
+ copy_v3_v3(positions[index], newco);
}
}
diff --git a/source/blender/editors/sculpt_paint/sculpt_boundary.c b/source/blender/editors/sculpt_paint/sculpt_boundary.c
index 355f260ae11..bd8f678182f 100644
--- a/source/blender/editors/sculpt_paint/sculpt_boundary.c
+++ b/source/blender/editors/sculpt_paint/sculpt_boundary.c
@@ -700,7 +700,7 @@ static void do_boundary_brush_bend_task_cb_ex(void *__restrict userdata,
angle * boundary->edit_info[vd.index].strength_factor * mask * automask);
add_v3_v3(target_co, boundary->bend.pivot_positions[vd.index]);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -751,7 +751,7 @@ static void do_boundary_brush_slide_task_cb_ex(void *__restrict userdata,
boundary->edit_info[vd.index].strength_factor * disp * mask * automask *
strength);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -802,7 +802,7 @@ static void do_boundary_brush_inflate_task_cb_ex(void *__restrict userdata,
boundary->edit_info[vd.index].strength_factor * disp * mask * automask *
strength);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -850,7 +850,7 @@ static void do_boundary_brush_grab_task_cb_ex(void *__restrict userdata,
ss->cache->grab_delta_symmetry,
boundary->edit_info[vd.index].strength_factor * mask * automask * strength);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -909,7 +909,7 @@ static void do_boundary_brush_twist_task_cb_ex(void *__restrict userdata,
angle * mask * automask * boundary->edit_info[vd.index].strength_factor);
add_v3_v3(target_co, boundary->twist.pivot_position);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -968,7 +968,7 @@ static void do_boundary_brush_smooth_task_cb_ex(void *__restrict userdata,
madd_v3_v3v3fl(
target_co, vd.co, disp, boundary->edit_info[vd.index].strength_factor * mask * strength);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
diff --git a/source/blender/editors/sculpt_paint/sculpt_brush_types.c b/source/blender/editors/sculpt_paint/sculpt_brush_types.c
index 666fa884e03..c24bdba662a 100644
--- a/source/blender/editors/sculpt_paint/sculpt_brush_types.c
+++ b/source/blender/editors/sculpt_paint/sculpt_brush_types.c
@@ -279,7 +279,7 @@ static void do_draw_brush_task_cb_ex(void *__restrict userdata,
mul_v3_v3fl(proxy[vd.i], offset, fade);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -384,7 +384,7 @@ static void do_fill_brush_task_cb_ex(void *__restrict userdata,
mul_v3_v3fl(proxy[vd.i], val, fade);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -489,7 +489,7 @@ static void do_scrape_brush_task_cb_ex(void *__restrict userdata,
mul_v3_v3fl(proxy[vd.i], val, fade);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -614,7 +614,7 @@ static void do_clay_thumb_brush_task_cb_ex(void *__restrict userdata,
mul_v3_v3fl(proxy[vd.i], val, fade);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -776,7 +776,7 @@ static void do_flatten_brush_task_cb_ex(void *__restrict userdata,
mul_v3_v3fl(proxy[vd.i], val, fade);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -940,7 +940,7 @@ static void do_clay_brush_task_cb_ex(void *__restrict userdata,
mul_v3_v3fl(proxy[vd.i], val, fade);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -1074,7 +1074,7 @@ static void do_clay_strips_brush_task_cb_ex(void *__restrict userdata,
mul_v3_v3fl(proxy[vd.i], val, fade);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -1283,7 +1283,7 @@ static void do_snake_hook_brush_task_cb_ex(void *__restrict userdata,
copy_v3_v3(proxy[vd.i], disp);
}
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -1376,7 +1376,7 @@ static void do_thumb_brush_task_cb_ex(void *__restrict userdata,
mul_v3_v3fl(proxy[vd.i], cono, fade);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -1462,7 +1462,7 @@ static void do_rotate_brush_task_cb_ex(void *__restrict userdata,
add_v3_v3(proxy[vd.i], ss->cache->location);
sub_v3_v3(proxy[vd.i], orig_data.co);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -1586,7 +1586,7 @@ static void do_layer_brush_task_cb_ex(void *__restrict userdata,
SCULPT_clip(sd, ss, vd.co, final_co);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -1666,7 +1666,7 @@ static void do_inflate_brush_task_cb_ex(void *__restrict userdata,
mul_v3_fl(val, fade * ss->cache->radius);
mul_v3_v3v3(proxy[vd.i], val, ss->cache->scale);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -1732,7 +1732,7 @@ static void do_nudge_brush_task_cb_ex(void *__restrict userdata,
mul_v3_v3fl(proxy[vd.i], cono, fade);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -1833,7 +1833,7 @@ static void do_crease_brush_task_cb_ex(void *__restrict userdata,
add_v3_v3v3(proxy[vd.i], val1, val2);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -1959,7 +1959,7 @@ static void do_pinch_brush_task_cb_ex(void *__restrict userdata,
}
mul_v3_v3fl(proxy[vd.i], disp_center, fade);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -2075,7 +2075,7 @@ static void do_grab_brush_task_cb_ex(void *__restrict userdata,
mul_v3_v3fl(proxy[vd.i], grab_delta, fade);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -2190,7 +2190,7 @@ static void do_elastic_deform_brush_task_cb_ex(void *__restrict userdata,
copy_v3_v3(proxy[vd.i], final_disp);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -2275,7 +2275,7 @@ static void do_draw_sharp_brush_task_cb_ex(void *__restrict userdata,
mul_v3_v3fl(proxy[vd.i], offset, fade);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -2395,7 +2395,7 @@ static void do_topology_slide_task_cb_ex(void *__restrict userdata,
mul_v3_v3fl(proxy[vd.i], final_disp, fade);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -2528,7 +2528,7 @@ static void do_topology_relax_task_cb_ex(void *__restrict userdata,
&automask_data);
SCULPT_relax_vertex(ss, &vd, fade * bstrength, false, vd.co);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -2616,7 +2616,7 @@ static void do_displacement_eraser_brush_task_cb_ex(void *__restrict userdata,
sub_v3_v3v3(disp, limit_co, vd.co);
mul_v3_v3fl(proxy[vd.i], disp, fade);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -2735,7 +2735,7 @@ static void do_displacement_smear_brush_task_cb_ex(void *__restrict userdata,
add_v3_v3v3(new_co, ss->cache->limit_surface_co[vd.index], interp_limit_surface_disp);
interp_v3_v3v3(vd.co, vd.co, new_co, fade);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -2863,7 +2863,7 @@ static void do_topology_rake_bmesh_task_cb_ex(void *__restrict userdata,
SCULPT_clip(sd, ss, vd.co, val);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
diff --git a/source/blender/editors/sculpt_paint/sculpt_cloth.c b/source/blender/editors/sculpt_paint/sculpt_cloth.c
index cf7e1d027f7..a5c469ca3a0 100644
--- a/source/blender/editors/sculpt_paint/sculpt_cloth.c
+++ b/source/blender/editors/sculpt_paint/sculpt_cloth.c
@@ -635,12 +635,12 @@ static void cloth_brush_collision_cb(void *userdata,
ClothBrushCollision *col = (ClothBrushCollision *)userdata;
CollisionModifierData *col_data = col->col_data;
MVertTri *verttri = &col_data->tri[index];
- MVert *mverts = col_data->x;
+ float(*positions)[3] = col_data->x;
float *tri[3], no[3], co[3];
- tri[0] = mverts[verttri->tri[0]].co;
- tri[1] = mverts[verttri->tri[1]].co;
- tri[2] = mverts[verttri->tri[2]].co;
+ tri[0] = positions[verttri->tri[0]];
+ tri[1] = positions[verttri->tri[1]];
+ tri[2] = positions[verttri->tri[2]];
float dist = 0.0f;
bool tri_hit = isect_ray_tri_watertight_v3(
@@ -783,7 +783,7 @@ static void do_cloth_brush_solve_simulation_task_cb_ex(
copy_v3_v3(vd.co, cloth_sim->pos[vd.index]);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
diff --git a/source/blender/editors/sculpt_paint/sculpt_dyntopo.c b/source/blender/editors/sculpt_paint/sculpt_dyntopo.c
index 388f4111555..192a4545e94 100644
--- a/source/blender/editors/sculpt_paint/sculpt_dyntopo.c
+++ b/source/blender/editors/sculpt_paint/sculpt_dyntopo.c
@@ -314,7 +314,7 @@ enum eDynTopoWarnFlag SCULPT_dynamic_topology_check(Scene *scene, Object *ob)
UNUSED_VARS_NDEBUG(ss);
for (int i = 0; i < CD_NUMTYPES; i++) {
- if (!ELEM(i, CD_MVERT, CD_MEDGE, CD_MFACE, CD_MLOOP, CD_MPOLY, CD_PAINT_MASK, CD_ORIGINDEX)) {
+ if (!ELEM(i, CD_MEDGE, CD_MFACE, CD_MLOOP, CD_MPOLY, CD_PAINT_MASK, CD_ORIGINDEX)) {
if (CustomData_has_layer(&me->vdata, i)) {
flag |= DYNTOPO_WARN_VDATA;
}
diff --git a/source/blender/editors/sculpt_paint/sculpt_face_set.cc b/source/blender/editors/sculpt_paint/sculpt_face_set.cc
index 40835172be9..fc373e63521 100644
--- a/source/blender/editors/sculpt_paint/sculpt_face_set.cc
+++ b/source/blender/editors/sculpt_paint/sculpt_face_set.cc
@@ -120,7 +120,7 @@ static void do_draw_face_sets_brush_task_cb_ex(void *__restrict userdata,
ss, &test, data->brush->falloff_shape);
const int thread_id = BLI_task_parallel_thread_id(tls);
- MVert *mvert = SCULPT_mesh_deformed_mverts_get(ss);
+ const float(*positions)[3] = SCULPT_mesh_deformed_positions_get(ss);
AutomaskingNodeData automask_data;
SCULPT_automasking_node_begin(
data->ob, ss, ss->cache->automasking, &automask_data, data->nodes[n]);
@@ -134,7 +134,7 @@ static void do_draw_face_sets_brush_task_cb_ex(void *__restrict userdata,
const MPoly *p = &ss->mpoly[vert_map->indices[j]];
float poly_center[3];
- BKE_mesh_calc_poly_center(p, &ss->mloop[p->loopstart], mvert, poly_center);
+ BKE_mesh_calc_poly_center(p, &ss->mloop[p->loopstart], positions, poly_center);
if (!sculpt_brush_test_sq_fn(&test, poly_center)) {
continue;
@@ -230,7 +230,7 @@ static void do_relax_face_sets_brush_task_cb_ex(void *__restrict userdata,
&automask_data);
SCULPT_relax_vertex(ss, &vd, fade * bstrength, relax_face_sets, vd.co);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -1242,8 +1242,8 @@ static void sculpt_face_set_edit_fair_face_set(Object *ob,
SCULPT_vertex_has_unique_face_set(ss, vertex);
}
- MVert *mvert = SCULPT_mesh_deformed_mverts_get(ss);
- BKE_mesh_prefair_and_fair_verts(mesh, mvert, fair_verts, fair_order);
+ float(*positions)[3] = SCULPT_mesh_deformed_positions_get(ss);
+ BKE_mesh_prefair_and_fair_verts(mesh, positions, fair_verts, fair_order);
MEM_freeN(fair_verts);
}
diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c b/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c
index c158cf33f6d..5468f520f19 100644
--- a/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c
+++ b/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c
@@ -529,7 +529,7 @@ static void mesh_filter_task_cb(void *__restrict userdata,
add_v3_v3v3(final_pos, orig_co, disp);
}
copy_v3_v3(vd.co, final_pos);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
diff --git a/source/blender/editors/sculpt_paint/sculpt_geodesic.c b/source/blender/editors/sculpt_paint/sculpt_geodesic.c
index 5d74853be8c..0a5d2949ef0 100644
--- a/source/blender/editors/sculpt_paint/sculpt_geodesic.c
+++ b/source/blender/editors/sculpt_paint/sculpt_geodesic.c
@@ -34,8 +34,12 @@
#define SCULPT_GEODESIC_VERTEX_NONE -1
/* Propagate distance from v1 and v2 to v0. */
-static bool sculpt_geodesic_mesh_test_dist_add(
- MVert *mvert, const int v0, const int v1, const int v2, float *dists, GSet *initial_verts)
+static bool sculpt_geodesic_mesh_test_dist_add(const float (*positions)[3],
+ const int v0,
+ const int v1,
+ const int v2,
+ float *dists,
+ GSet *initial_verts)
{
if (BLI_gset_haskey(initial_verts, POINTER_FROM_INT(v0))) {
return false;
@@ -53,11 +57,11 @@ static bool sculpt_geodesic_mesh_test_dist_add(
return false;
}
dist0 = geodesic_distance_propagate_across_triangle(
- mvert[v0].co, mvert[v1].co, mvert[v2].co, dists[v1], dists[v2]);
+ positions[v0], positions[v1], positions[v2], dists[v1], dists[v2]);
}
else {
float vec[3];
- sub_v3_v3v3(vec, mvert[v1].co, mvert[v0].co);
+ sub_v3_v3v3(vec, positions[v1], positions[v0]);
dist0 = dists[v1] + len_v3(vec);
}
@@ -81,7 +85,7 @@ static float *SCULPT_geodesic_mesh_create(Object *ob,
const float limit_radius_sq = limit_radius * limit_radius;
- MVert *verts = SCULPT_mesh_deformed_mverts_get(ss);
+ float(*positions)[3] = SCULPT_mesh_deformed_positions_get(ss);
const MEdge *edges = BKE_mesh_edges(mesh);
const MPoly *polys = BKE_mesh_polys(mesh);
const MLoop *loops = BKE_mesh_loops(mesh);
@@ -135,9 +139,9 @@ static float *SCULPT_geodesic_mesh_create(Object *ob,
* number of vertices (usually just 1 or 2). */
GSET_ITER (gs_iter, initial_verts) {
const int v = POINTER_AS_INT(BLI_gsetIterator_getKey(&gs_iter));
- float *v_co = verts[v].co;
+ float *v_co = positions[v];
for (int i = 0; i < totvert; i++) {
- if (len_squared_v3v3(v_co, verts[i].co) <= limit_radius_sq) {
+ if (len_squared_v3v3(v_co, positions[i]) <= limit_radius_sq) {
BLI_BITMAP_ENABLE(affected_vertex, i);
}
}
@@ -167,7 +171,7 @@ static float *SCULPT_geodesic_mesh_create(Object *ob,
SWAP(int, v1, v2);
}
sculpt_geodesic_mesh_test_dist_add(
- verts, v2, v1, SCULPT_GEODESIC_VERTEX_NONE, dists, initial_verts);
+ positions, v2, v1, SCULPT_GEODESIC_VERTEX_NONE, dists, initial_verts);
}
if (ss->epmap[e].count != 0) {
@@ -184,7 +188,8 @@ static float *SCULPT_geodesic_mesh_create(Object *ob,
if (ELEM(v_other, v1, v2)) {
continue;
}
- if (sculpt_geodesic_mesh_test_dist_add(verts, v_other, v1, v2, dists, initial_verts)) {
+ if (sculpt_geodesic_mesh_test_dist_add(
+ positions, v_other, v1, v2, dists, initial_verts)) {
for (int edge_map_index = 0; edge_map_index < ss->vemap[v_other].count;
edge_map_index++) {
const int e_other = ss->vemap[v_other].indices[edge_map_index];
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index 852b3c2719a..a06d6348a7d 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -991,7 +991,7 @@ void SCULPT_active_vertex_normal_get(SculptSession *ss, float normal[3]);
/* Returns PBVH deformed vertices array if shape keys or deform modifiers are used, otherwise
* returns mesh original vertices array. */
-struct MVert *SCULPT_mesh_deformed_mverts_get(SculptSession *ss);
+float (*SCULPT_mesh_deformed_positions_get(SculptSession *ss))[3];
/* Fake Neighbors */
diff --git a/source/blender/editors/sculpt_paint/sculpt_multiplane_scrape.c b/source/blender/editors/sculpt_paint/sculpt_multiplane_scrape.c
index fd8f5b8945c..ccee7814f83 100644
--- a/source/blender/editors/sculpt_paint/sculpt_multiplane_scrape.c
+++ b/source/blender/editors/sculpt_paint/sculpt_multiplane_scrape.c
@@ -201,7 +201,7 @@ static void do_multiplane_scrape_brush_task_cb_ex(void *__restrict userdata,
mul_v3_v3fl(proxy[vd.i], val, fade);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
diff --git a/source/blender/editors/sculpt_paint/sculpt_paint_image.cc b/source/blender/editors/sculpt_paint/sculpt_paint_image.cc
index d3b3100458d..12f1104b403 100644
--- a/source/blender/editors/sculpt_paint/sculpt_paint_image.cc
+++ b/source/blender/editors/sculpt_paint/sculpt_paint_image.cc
@@ -124,7 +124,7 @@ template<typename ImageBuffer> class PaintingKernel {
SculptSession *ss;
const Brush *brush;
const int thread_id;
- const MVert *mvert;
+ const float (*positions_)[3];
float4 brush_color;
float brush_strength;
@@ -139,8 +139,8 @@ template<typename ImageBuffer> class PaintingKernel {
explicit PaintingKernel(SculptSession *ss,
const Brush *brush,
const int thread_id,
- const MVert *mvert)
- : ss(ss), brush(brush), thread_id(thread_id), mvert(mvert)
+ const float (*positions)[3])
+ : ss(ss), brush(brush), thread_id(thread_id), positions_(positions)
{
init_brush_strength();
init_brush_test();
@@ -259,9 +259,9 @@ template<typename ImageBuffer> class PaintingKernel {
barycentric_weights.y,
1.0f - barycentric_weights.x - barycentric_weights.y);
interp_v3_v3v3v3(result,
- mvert[vert_indices[0]].co,
- mvert[vert_indices[1]].co,
- mvert[vert_indices[2]].co,
+ positions_[vert_indices[0]],
+ positions_[vert_indices[1]],
+ positions_[vert_indices[2]],
barycentric);
return result;
}
@@ -269,7 +269,7 @@ template<typename ImageBuffer> class PaintingKernel {
static std::vector<bool> init_triangle_brush_test(SculptSession *ss,
Triangles &triangles,
- const MVert *mvert)
+ const float (*positions)[3])
{
std::vector<bool> brush_test(triangles.size());
SculptBrushTest test;
@@ -283,10 +283,10 @@ static std::vector<bool> init_triangle_brush_test(SculptSession *ss,
for (int triangle_index = 0; triangle_index < triangles.size(); triangle_index++) {
TrianglePaintInput &triangle = triangles.get_paint_input(triangle_index);
- float3 triangle_min_bounds(mvert[triangle.vert_indices[0]].co);
+ float3 triangle_min_bounds(positions[triangle.vert_indices[0]]);
float3 triangle_max_bounds(triangle_min_bounds);
for (int i = 1; i < 3; i++) {
- const float3 &pos = mvert[triangle.vert_indices[i]].co;
+ const float3 &pos = positions[triangle.vert_indices[i]];
triangle_min_bounds.x = min_ff(triangle_min_bounds.x, pos.x);
triangle_min_bounds.y = min_ff(triangle_min_bounds.y, pos.y);
triangle_min_bounds.z = min_ff(triangle_min_bounds.z, pos.z);
@@ -312,12 +312,12 @@ static void do_paint_pixels(void *__restrict userdata,
NodeData &node_data = BKE_pbvh_pixels_node_data_get(*node);
const int thread_id = BLI_task_parallel_thread_id(tls);
- MVert *mvert = SCULPT_mesh_deformed_mverts_get(ss);
+ const float(*positions)[3] = SCULPT_mesh_deformed_positions_get(ss);
- std::vector<bool> brush_test = init_triangle_brush_test(ss, node_data.triangles, mvert);
+ std::vector<bool> brush_test = init_triangle_brush_test(ss, node_data.triangles, positions);
- PaintingKernel<ImageBufferFloat4> kernel_float4(ss, brush, thread_id, mvert);
- PaintingKernel<ImageBufferByte4> kernel_byte4(ss, brush, thread_id, mvert);
+ PaintingKernel<ImageBufferFloat4> kernel_float4(ss, brush, thread_id, positions);
+ PaintingKernel<ImageBufferByte4> kernel_byte4(ss, brush, thread_id, positions);
AutomaskingNodeData automask_data;
SCULPT_automasking_node_begin(ob, ss, ss->cache->automasking, &automask_data, data->nodes[n]);
diff --git a/source/blender/editors/sculpt_paint/sculpt_pose.c b/source/blender/editors/sculpt_paint/sculpt_pose.c
index 5f671c1f0e1..389a548fb2d 100644
--- a/source/blender/editors/sculpt_paint/sculpt_pose.c
+++ b/source/blender/editors/sculpt_paint/sculpt_pose.c
@@ -193,7 +193,7 @@ static void do_pose_brush_task_cb_ex(void *__restrict userdata,
float *target_co = SCULPT_brush_deform_target_vertex_co_get(ss, brush->deform_target, &vd);
copy_v3_v3(target_co, final_pos);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
diff --git a/source/blender/editors/sculpt_paint/sculpt_smooth.c b/source/blender/editors/sculpt_paint/sculpt_smooth.c
index 09b1c69da45..5af8381f6da 100644
--- a/source/blender/editors/sculpt_paint/sculpt_smooth.c
+++ b/source/blender/editors/sculpt_paint/sculpt_smooth.c
@@ -221,7 +221,7 @@ static void do_enhance_details_brush_task_cb_ex(void *__restrict userdata,
madd_v3_v3v3fl(disp, vd.co, ss->cache->detail_directions[vd.index], fade);
SCULPT_clip(sd, ss, vd.co, disp);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -319,7 +319,7 @@ static void do_smooth_brush_task_cb_ex(void *__restrict userdata,
sub_v3_v3v3(val, avg, vd.co);
madd_v3_v3v3fl(val, vd.co, val, fade);
SCULPT_clip(sd, ss, vd.co, val);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -489,7 +489,7 @@ static void SCULPT_do_surface_smooth_brush_laplacian_task_cb_ex(
SCULPT_surface_smooth_laplacian_step(
ss, disp, vd.co, ss->cache->surface_smooth_laplacian_disp, vd.vertex, orig_data.co, alpha);
madd_v3_v3fl(vd.co, disp, clamp_f(fade, 0.0f, 1.0f));
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
diff --git a/source/blender/editors/sculpt_paint/sculpt_transform.c b/source/blender/editors/sculpt_paint/sculpt_transform.c
index 0463e8adbaf..b8ee3404159 100644
--- a/source/blender/editors/sculpt_paint/sculpt_transform.c
+++ b/source/blender/editors/sculpt_paint/sculpt_transform.c
@@ -173,7 +173,7 @@ static void sculpt_transform_task_cb(void *__restrict userdata,
mul_v3_fl(disp, 1.0f - fade);
add_v3_v3v3(vd.co, start_co, disp);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
@@ -247,7 +247,7 @@ static void sculpt_elastic_transform_task_cb(void *__restrict userdata,
copy_v3_v3(proxy[vd.i], final_disp);
- if (vd.mvert) {
+ if (vd.is_mesh) {
BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
}
}
diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c
index 833f62d4955..de0935a0e22 100644
--- a/source/blender/editors/sculpt_paint/sculpt_undo.c
+++ b/source/blender/editors/sculpt_paint/sculpt_undo.c
@@ -319,9 +319,8 @@ static void update_cb_partial(PBVHNode *node, void *userdata)
BKE_pbvh_node_mark_update(node);
}
int verts_num;
- const int *vert_indices;
BKE_pbvh_node_num_verts(data->pbvh, node, NULL, &verts_num);
- BKE_pbvh_node_get_verts(data->pbvh, node, &vert_indices, NULL);
+ const int *vert_indices = BKE_pbvh_node_get_vert_indices(node);
if (data->modified_mask_verts != NULL) {
for (int i = 0; i < verts_num; i++) {
if (data->modified_mask_verts[vert_indices[i]]) {
@@ -380,7 +379,6 @@ static bool sculpt_undo_restore_coords(bContext *C, Depsgraph *depsgraph, Sculpt
Object *ob = BKE_view_layer_active_object_get(view_layer);
SculptSession *ss = ob->sculpt;
SubdivCCG *subdiv_ccg = ss->subdiv_ccg;
- MVert *mvert;
int *index;
if (unode->maxvert) {
@@ -406,7 +404,7 @@ static bool sculpt_undo_restore_coords(bContext *C, Depsgraph *depsgraph, Sculpt
/* No need for float comparison here (memory is exactly equal or not). */
index = unode->index;
- mvert = ss->mvert;
+ float(*positions)[3] = ss->positions;
if (ss->shapekey_active) {
float(*vertCos)[3];
@@ -433,7 +431,7 @@ static bool sculpt_undo_restore_coords(bContext *C, Depsgraph *depsgraph, Sculpt
/* Propagate new coords to keyblock. */
SCULPT_vertcos_to_key(ob, ss->shapekey_active, vertCos);
- /* PBVH uses its own mvert array, so coords should be */
+ /* PBVH uses its own vertex array, so coords should be */
/* propagated to PBVH here. */
BKE_pbvh_vert_coords_apply(ss->pbvh, vertCos, ss->shapekey_active->totelem);
@@ -443,20 +441,20 @@ static bool sculpt_undo_restore_coords(bContext *C, Depsgraph *depsgraph, Sculpt
if (unode->orig_co) {
if (ss->deform_modifiers_active) {
for (int i = 0; i < unode->totvert; i++) {
- sculpt_undo_restore_deformed(ss, unode, i, index[i], mvert[index[i]].co);
+ sculpt_undo_restore_deformed(ss, unode, i, index[i], positions[index[i]]);
BKE_pbvh_vert_tag_update_normal(ss->pbvh, BKE_pbvh_make_vref(index[i]));
}
}
else {
for (int i = 0; i < unode->totvert; i++) {
- swap_v3_v3(mvert[index[i]].co, unode->orig_co[i]);
+ swap_v3_v3(positions[index[i]], unode->orig_co[i]);
BKE_pbvh_vert_tag_update_normal(ss->pbvh, BKE_pbvh_make_vref(index[i]));
}
}
}
else {
for (int i = 0; i < unode->totvert; i++) {
- swap_v3_v3(mvert[index[i]].co, unode->co[i]);
+ swap_v3_v3(positions[index[i]], unode->co[i]);
BKE_pbvh_vert_tag_update_normal(ss->pbvh, BKE_pbvh_make_vref(index[i]));
}
}
@@ -1422,12 +1420,10 @@ static void sculpt_undo_store_hidden(Object *ob, SculptUndoNode *unode)
/* Already stored during allocation. */
}
else {
- MVert *mvert;
- const int *vert_indices;
int allvert;
BKE_pbvh_node_num_verts(pbvh, node, NULL, &allvert);
- BKE_pbvh_node_get_verts(pbvh, node, &vert_indices, &mvert);
+ const int *vert_indices = BKE_pbvh_node_get_vert_indices(node);
for (int i = 0; i < allvert; i++) {
BLI_BITMAP_SET(unode->vert_hidden, i, hide_vert[vert_indices[i]]);
}
@@ -1637,11 +1633,11 @@ SculptUndoNode *SCULPT_undo_push_node(Object *ob, PBVHNode *node, SculptUndoType
memcpy(unode->grids, grids, sizeof(int) * totgrid);
}
else {
- const int *vert_indices, *loop_indices;
+ const int *loop_indices;
int allvert, allloop;
BKE_pbvh_node_num_verts(ss->pbvh, unode->node, NULL, &allvert);
- BKE_pbvh_node_get_verts(ss->pbvh, node, &vert_indices, NULL);
+ const int *vert_indices = BKE_pbvh_node_get_vert_indices(node);
memcpy(unode->index, vert_indices, sizeof(int) * allvert);
if (unode->loop_index) {
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 6370d56ae8c..2b503733e81 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -69,7 +69,7 @@ void ED_draw_object_facemap(Depsgraph *depsgraph,
if (facemap_data) {
GPU_blend(GPU_BLEND_ALPHA);
- const MVert *verts = BKE_mesh_verts(me);
+ const float(*positions)[3] = BKE_mesh_positions(me);
const MPoly *polys = BKE_mesh_polys(me);
const MLoop *loops = BKE_mesh_loops(me);
@@ -100,9 +100,9 @@ void ED_draw_object_facemap(Depsgraph *depsgraph,
for (mp = polys, i = 0; i < mpoly_len; i++, mp++) {
if (facemap_data[i] == facemap) {
for (int j = 2; j < mp->totloop; j++) {
- copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), verts[loops[mlt->tri[0]].v].co);
- copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), verts[loops[mlt->tri[1]].v].co);
- copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), verts[loops[mlt->tri[2]].v].co);
+ copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), positions[loops[mlt->tri[0]].v]);
+ copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), positions[loops[mlt->tri[1]].v]);
+ copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), positions[loops[mlt->tri[2]].v]);
vbo_len_used += 3;
mlt++;
}
@@ -120,9 +120,9 @@ void ED_draw_object_facemap(Depsgraph *depsgraph,
const MLoop *ml_a = ml_start + 1;
const MLoop *ml_b = ml_start + 2;
for (int j = 2; j < mp->totloop; j++) {
- copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), verts[ml_start->v].co);
- copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), verts[ml_a->v].co);
- copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), verts[ml_b->v].co);
+ copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), positions[ml_start->v]);
+ copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), positions[ml_a->v]);
+ copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), positions[ml_b->v]);
vbo_len_used += 3;
ml_a++;
diff --git a/source/blender/editors/space_view3d/view3d_iterators.cc b/source/blender/editors/space_view3d/view3d_iterators.cc
index aaa817ec00c..145183f5f54 100644
--- a/source/blender/editors/space_view3d/view3d_iterators.cc
+++ b/source/blender/editors/space_view3d/view3d_iterators.cc
@@ -203,10 +203,10 @@ static bool view3d_project_segment_to_screen_with_clip_tag(const ARegion *region
* \{ */
struct foreachScreenObjectVert_userData {
- void (*func)(void *userData, MVert *mv, const float screen_co[2], int index);
+ void (*func)(void *userData, const float screen_co[2], int index);
void *userData;
ViewContext vc;
- MVert *verts;
+ float (*positions)[3];
const bool *hide_vert;
eV3DProjTest clip_flag;
};
@@ -269,7 +269,6 @@ static void meshobject_foreachScreenVert__mapFunc(void *userData,
if (data->hide_vert && data->hide_vert[index]) {
return;
}
- MVert *mv = &data->verts[index];
float screen_co[2];
@@ -278,14 +277,15 @@ static void meshobject_foreachScreenVert__mapFunc(void *userData,
return;
}
- data->func(data->userData, mv, screen_co, index);
+ data->func(data->userData, screen_co, index);
}
-void meshobject_foreachScreenVert(
- ViewContext *vc,
- void (*func)(void *userData, MVert *eve, const float screen_co[2], int index),
- void *userData,
- eV3DProjTest clip_flag)
+void meshobject_foreachScreenVert(ViewContext *vc,
+ void (*func)(void *userData,
+ const float screen_co[2],
+ int index),
+ void *userData,
+ eV3DProjTest clip_flag)
{
BLI_assert((clip_flag & V3D_PROJ_TEST_CLIP_CONTENT) == 0);
foreachScreenObjectVert_userData data;
@@ -302,7 +302,7 @@ void meshobject_foreachScreenVert(
data.func = func;
data.userData = userData;
data.clip_flag = clip_flag;
- data.verts = BKE_mesh_verts_for_write((Mesh *)vc->obact->data);
+ data.positions = BKE_mesh_positions_for_write((Mesh *)vc->obact->data);
data.hide_vert = (const bool *)CustomData_get_layer_named(
&me->vdata, CD_PROP_BOOL, ".hide_vert");
diff --git a/source/blender/editors/space_view3d/view3d_select.cc b/source/blender/editors/space_view3d/view3d_select.cc
index 48a3cb386fd..39ad6eb835a 100644
--- a/source/blender/editors/space_view3d/view3d_select.cc
+++ b/source/blender/editors/space_view3d/view3d_select.cc
@@ -1170,7 +1170,6 @@ struct LassoSelectUserData_ForMeshVert {
blender::MutableSpan<bool> select_vert;
};
static void do_lasso_select_meshobject__doSelectVert(void *userData,
- MVert * /*mv*/,
const float screen_co[2],
int index)
{
@@ -3205,7 +3204,6 @@ struct BoxSelectUserData_ForMeshVert {
blender::MutableSpan<bool> select_vert;
};
static void do_paintvert_box_select__doSelectVert(void *userData,
- MVert * /*mv*/,
const float screen_co[2],
int index)
{
@@ -4225,7 +4223,6 @@ struct CircleSelectUserData_ForMeshVert {
blender::MutableSpan<bool> select_vert;
};
static void paint_vertsel_circle_select_doSelectVert(void *userData,
- MVert * /*mv*/,
const float screen_co[2],
int index)
{
diff --git a/source/blender/editors/transform/transform_snap_object.cc b/source/blender/editors/transform/transform_snap_object.cc
index 87c467d44d8..598b3f7f1b7 100644
--- a/source/blender/editors/transform/transform_snap_object.cc
+++ b/source/blender/editors/transform/transform_snap_object.cc
@@ -240,7 +240,7 @@ static void snap_object_data_mesh_get(SnapObjectContext *sctx,
bool use_hide,
BVHTreeFromMesh *r_treedata)
{
- const Span<MVert> verts = me_eval->verts();
+ const Span<float3> positions = me_eval->positions();
const Span<MPoly> polys = me_eval->polys();
const Span<MLoop> loops = me_eval->loops();
@@ -253,13 +253,12 @@ static void snap_object_data_mesh_get(SnapObjectContext *sctx,
BKE_bvhtree_from_mesh_get(
r_treedata, me_eval, use_hide ? BVHTREE_FROM_LOOPTRI_NO_HIDDEN : BVHTREE_FROM_LOOPTRI, 4);
- BLI_assert(r_treedata->vert == verts.data());
- BLI_assert(!verts.data() || r_treedata->vert_normals);
- BLI_assert(r_treedata->loop == loops.data());
- BLI_assert(!polys.data() || r_treedata->looptri);
- BLI_assert(!r_treedata->tree || r_treedata->looptri);
+ BLI_assert(r_treedata.vert == positions.data());
+ BLI_assert(!positions.data() || r_treedata.vert_normals);
+ BLI_assert(r_treedata.loop == loops.data());
+ BLI_assert(!polys.data() || r_treedata.looptri);
- UNUSED_VARS_NDEBUG(verts, polys, loops);
+ UNUSED_VARS_NDEBUG(positions, polys, loops);
}
/* Searches for the #Mesh_Runtime associated with the object that is most likely to be updated due
@@ -622,12 +621,12 @@ static void mesh_looptri_raycast_backface_culling_cb(void *userdata,
BVHTreeRayHit *hit)
{
const BVHTreeFromMesh *data = (BVHTreeFromMesh *)userdata;
- const MVert *vert = data->vert;
+ const float(*positions)[3] = data->positions;
const MLoopTri *lt = &data->looptri[index];
const float *vtri_co[3] = {
- vert[data->loop[lt->tri[0]].v].co,
- vert[data->loop[lt->tri[1]].v].co,
- vert[data->loop[lt->tri[2]].v].co,
+ positions[data->loop[lt->tri[0]].v],
+ positions[data->loop[lt->tri[1]].v],
+ positions[data->loop[lt->tri[2]].v],
};
float dist = bvhtree_ray_tri_intersection(ray, hit->dist, UNPACK3(vtri_co));
@@ -1426,7 +1425,7 @@ struct Nearest2dUserData {
BMesh *bm;
};
struct {
- const MVert *vert;
+ const float (*positions)[3];
const float (*vert_normals)[3];
const MEdge *edge; /* only used for #BVHTreeFromMeshEdges */
const MLoop *loop;
@@ -1440,7 +1439,7 @@ struct Nearest2dUserData {
static void cb_mvert_co_get(const int index, const Nearest2dUserData *data, const float **r_co)
{
- *r_co = data->vert[index].co;
+ *r_co = data->positions[index];
}
static void cb_bvert_co_get(const int index, const Nearest2dUserData *data, const float **r_co)
@@ -1715,7 +1714,7 @@ static void nearest2d_data_init_mesh(const Mesh *mesh,
r_nearest2d->get_tri_verts_index = cb_mlooptri_verts_get;
r_nearest2d->get_tri_edges_index = cb_mlooptri_edges_get;
- r_nearest2d->vert = mesh->verts().data();
+ r_nearest2d->positions = BKE_mesh_positions(mesh);
r_nearest2d->vert_normals = BKE_mesh_vertex_normals_ensure(mesh);
r_nearest2d->edge = mesh->edges().data();
r_nearest2d->loop = mesh->loops().data();
diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
index 071f1c44c6b..c4022375d4c 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@ -596,7 +596,7 @@ static ParamHandle *construct_param_handle_subsurfed(const Scene *scene,
/* holds original indices for subsurfed mesh */
const int *origVertIndices, *origEdgeIndices, *origPolyIndices;
/* Holds vertices of subsurfed mesh */
- MVert *subsurfedVerts;
+ float(*subsurfedPositions)[3];
MEdge *subsurfedEdges;
MPoly *subsurfedPolys;
MLoop *subsurfedLoops;
@@ -641,7 +641,7 @@ static ParamHandle *construct_param_handle_subsurfed(const Scene *scene,
}
/* get the derived data */
- subsurfedVerts = derivedMesh->getVertArray(derivedMesh);
+ subsurfedPositions = (float(*)[3])derivedMesh->getVertArray(derivedMesh);
subsurfedEdges = derivedMesh->getEdgeArray(derivedMesh);
subsurfedPolys = derivedMesh->getPolyArray(derivedMesh);
subsurfedLoops = derivedMesh->getLoopArray(derivedMesh);
@@ -703,10 +703,10 @@ static ParamHandle *construct_param_handle_subsurfed(const Scene *scene,
vkeys[2] = (ParamKey)mloop[2].v;
vkeys[3] = (ParamKey)mloop[3].v;
- co[0] = subsurfedVerts[mloop[0].v].co;
- co[1] = subsurfedVerts[mloop[1].v].co;
- co[2] = subsurfedVerts[mloop[2].v].co;
- co[3] = subsurfedVerts[mloop[3].v].co;
+ co[0] = subsurfedPositions[mloop[0].v];
+ co[1] = subsurfedPositions[mloop[1].v];
+ co[2] = subsurfedPositions[mloop[2].v];
+ co[3] = subsurfedPositions[mloop[3].v];
/* This is where all the magic is done.
* If the vertex exists in the, we pass the original uv pointer to the solver, thus
diff --git a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
index 53c2b1d235b..c37beba2b6f 100644
--- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
+++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
@@ -14,6 +14,7 @@
#include <sstream>
+using blender::float3;
using blender::Span;
namespace Freestyle {
@@ -401,15 +402,19 @@ void BlenderFileLoader::insertShapeNode(Object *ob, Mesh *me, int id)
{
char *name = ob->id.name + 2;
- const Span<MVert> mesh_verts = me->verts();
+ const Span<float3> mesh_positions = me->positions();
const Span<MPoly> mesh_polys = me->polys();
const Span<MLoop> mesh_loops = me->loops();
// Compute loop triangles
int tottri = poly_to_tri_count(me->totpoly, me->totloop);
MLoopTri *mlooptri = (MLoopTri *)MEM_malloc_arrayN(tottri, sizeof(*mlooptri), __func__);
- BKE_mesh_recalc_looptri(
- mesh_loops.data(), mesh_polys.data(), mesh_verts.data(), me->totloop, me->totpoly, mlooptri);
+ BKE_mesh_recalc_looptri(mesh_loops.data(),
+ mesh_polys.data(),
+ reinterpret_cast<const float(*)[3]>(mesh_positions.data()),
+ me->totloop,
+ me->totpoly,
+ mlooptri);
// Compute loop normals
BKE_mesh_calc_normals_split(me);
@@ -444,9 +449,9 @@ void BlenderFileLoader::insertShapeNode(Object *ob, Mesh *me, int id)
for (int a = 0; a < tottri; a++) {
const MLoopTri *lt = &mlooptri[a];
- copy_v3_v3(v1, mesh_verts[mesh_loops[lt->tri[0]].v].co);
- copy_v3_v3(v2, mesh_verts[mesh_loops[lt->tri[1]].v].co);
- copy_v3_v3(v3, mesh_verts[mesh_loops[lt->tri[2]].v].co);
+ copy_v3_v3(v1, mesh_positions[mesh_loops[lt->tri[0]].v]);
+ copy_v3_v3(v2, mesh_positions[mesh_loops[lt->tri[1]].v]);
+ copy_v3_v3(v3, mesh_positions[mesh_loops[lt->tri[2]].v]);
mul_m4_v3(obmat, v1);
mul_m4_v3(obmat, v2);
@@ -517,9 +522,9 @@ void BlenderFileLoader::insertShapeNode(Object *ob, Mesh *me, int id)
const MPoly *mp = &mesh_polys[lt->poly];
Material *mat = BKE_object_material_get(ob, material_indices[lt->poly] + 1);
- copy_v3_v3(v1, mesh_verts[mesh_loops[lt->tri[0]].v].co);
- copy_v3_v3(v2, mesh_verts[mesh_loops[lt->tri[1]].v].co);
- copy_v3_v3(v3, mesh_verts[mesh_loops[lt->tri[2]].v].co);
+ copy_v3_v3(v1, mesh_positions[mesh_loops[lt->tri[0]].v]);
+ copy_v3_v3(v2, mesh_positions[mesh_loops[lt->tri[1]].v]);
+ copy_v3_v3(v3, mesh_positions[mesh_loops[lt->tri[2]].v]);
mul_m4_v3(obmat, v1);
mul_m4_v3(obmat, v2);
diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
index 64e7be5169c..ee3731ca07c 100644
--- a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
+++ b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
@@ -55,6 +55,8 @@
#include <climits>
+using blender::float3;
+
namespace Freestyle {
const char *BlenderStrokeRenderer::uvNames[] = {"along_stroke", "along_stroke_tips"};
@@ -577,8 +579,8 @@ void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex)
mesh->totloop = group->totloop;
mesh->totcol = group->materials.size();
- MVert *verts = (MVert *)CustomData_add_layer(
- &mesh->vdata, CD_MVERT, CD_SET_DEFAULT, nullptr, mesh->totvert);
+ float3 *mesh_positions = (float3 *)CustomData_add_layer_named(
+ &mesh->vdata, CD_PROP_FLOAT3, CD_SET_DEFAULT, nullptr, mesh->totvert, "position");
MEdge *edges = (MEdge *)CustomData_add_layer(
&mesh->edata, CD_MEDGE, CD_SET_DEFAULT, nullptr, mesh->totedge);
MPoly *polys = (MPoly *)CustomData_add_layer(
@@ -664,19 +666,17 @@ void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex)
else {
if (!visible) {
// first vertex
- verts->co[0] = svRep[0]->point2d()[0];
- verts->co[1] = svRep[0]->point2d()[1];
- verts->co[2] = get_stroke_vertex_z();
+ mesh_positions[vertex_index][0] = svRep[0]->point2d()[0];
+ mesh_positions[vertex_index][1] = svRep[0]->point2d()[1];
+ mesh_positions[vertex_index][2] = get_stroke_vertex_z();
- ++verts;
++vertex_index;
// second vertex
- verts->co[0] = svRep[1]->point2d()[0];
- verts->co[1] = svRep[1]->point2d()[1];
- verts->co[2] = get_stroke_vertex_z();
+ mesh_positions[vertex_index][0] = svRep[1]->point2d()[0];
+ mesh_positions[vertex_index][1] = svRep[1]->point2d()[1];
+ mesh_positions[vertex_index][2] = get_stroke_vertex_z();
- ++verts;
++vertex_index;
// first edge
@@ -688,10 +688,9 @@ void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex)
visible = true;
// vertex
- verts->co[0] = svRep[2]->point2d()[0];
- verts->co[1] = svRep[2]->point2d()[1];
- verts->co[2] = get_stroke_vertex_z();
- ++verts;
+ mesh_positions[vertex_index][0] = svRep[2]->point2d()[0];
+ mesh_positions[vertex_index][1] = svRep[2]->point2d()[1];
+ mesh_positions[vertex_index][2] = get_stroke_vertex_z();
++vertex_index;
// edges
diff --git a/source/blender/geometry/intern/add_curves_on_mesh.cc b/source/blender/geometry/intern/add_curves_on_mesh.cc
index a03c9b994a9..805f302894f 100644
--- a/source/blender/geometry/intern/add_curves_on_mesh.cc
+++ b/source/blender/geometry/intern/add_curves_on_mesh.cc
@@ -245,7 +245,7 @@ AddCurvesOnMeshOutputs add_curves_on_mesh(CurvesGeometry &curves,
Vector<float2> used_uvs;
/* Find faces that the passed in uvs belong to. */
- const Span<MVert> surface_verts = inputs.surface->verts();
+ const Span<float3> surface_positions = inputs.surface->positions();
const Span<MLoop> surface_loops = inputs.surface->loops();
for (const int i : inputs.uvs.index_range()) {
const float2 &uv = inputs.uvs[i];
@@ -259,9 +259,9 @@ AddCurvesOnMeshOutputs add_curves_on_mesh(CurvesGeometry &curves,
looptris.append(&looptri);
const float3 root_position_su = attribute_math::mix3<float3>(
result.bary_weights,
- surface_verts[surface_loops[looptri.tri[0]].v].co,
- surface_verts[surface_loops[looptri.tri[1]].v].co,
- surface_verts[surface_loops[looptri.tri[2]].v].co);
+ surface_positions[surface_loops[looptri.tri[0]].v],
+ surface_positions[surface_loops[looptri.tri[1]].v],
+ surface_positions[surface_loops[looptri.tri[2]].v]);
root_positions_cu.append(inputs.transforms->surface_to_curves * root_position_su);
used_uvs.append(uv);
}
diff --git a/source/blender/geometry/intern/mesh_merge_by_distance.cc b/source/blender/geometry/intern/mesh_merge_by_distance.cc
index 288fd407641..e5622a345d1 100644
--- a/source/blender/geometry/intern/mesh_merge_by_distance.cc
+++ b/source/blender/geometry/intern/mesh_merge_by_distance.cc
@@ -1228,10 +1228,6 @@ static void customdata_weld(
int src_i, dest_i;
int j;
- float co[3] = {0.0f, 0.0f, 0.0f};
-#ifdef USE_WELD_NORMALS
- float no[3] = {0.0f, 0.0f, 0.0f};
-#endif
short flag = 0;
/* interpolates a layer at a time */
@@ -1254,20 +1250,7 @@ static void customdata_weld(
/* if we found a matching layer, add the data */
if (dest->layers[dest_i].type == type) {
void *src_data = source->layers[src_i].data;
-
- if (type == CD_MVERT) {
- for (j = 0; j < count; j++) {
- MVert *mv_src = &((MVert *)src_data)[src_indices[j]];
- add_v3_v3(co, mv_src->co);
-#ifdef USE_WELD_NORMALS
- short *mv_src_no = mv_src->no;
- no[0] += mv_src_no[0];
- no[1] += mv_src_no[1];
- no[2] += mv_src_no[2];
-#endif
- }
- }
- else if (type == CD_MEDGE) {
+ if (type == CD_MEDGE) {
for (j = 0; j < count; j++) {
MEdge *me_src = &((MEdge *)src_data)[src_indices[j]];
flag |= me_src->flag;
@@ -1303,20 +1286,7 @@ static void customdata_weld(
for (dest_i = 0; dest_i < dest->totlayer; dest_i++) {
CustomDataLayer *layer_dst = &dest->layers[dest_i];
const int type = layer_dst->type;
- if (type == CD_MVERT) {
- MVert *mv = &((MVert *)layer_dst->data)[dest_index];
- mul_v3_fl(co, fac);
-
- copy_v3_v3(mv->co, co);
-#ifdef USE_WELD_NORMALS
- mul_v3_fl(no, fac);
- short *mv_no = mv->no;
- mv_no[0] = short(no[0]);
- mv_no[1] = short(no[1]);
- mv_no[2] = short(no[2]);
-#endif
- }
- else if (type == CD_MEDGE) {
+ if (type == CD_MEDGE) {
MEdge *me = &((MEdge *)layer_dst->data)[dest_index];
me->flag = flag;
}
@@ -1552,9 +1522,9 @@ std::optional<Mesh *> mesh_merge_by_distance_all(const Mesh &mesh,
KDTree_3d *tree = BLI_kdtree_3d_new(selection.size());
- const Span<MVert> verts = mesh.verts();
+ const Span<float3> positions = mesh.positions();
for (const int i : selection) {
- BLI_kdtree_3d_insert(tree, i, verts[i].co);
+ BLI_kdtree_3d_insert(tree, i, positions[i]);
}
BLI_kdtree_3d_balance(tree);
@@ -1579,7 +1549,7 @@ std::optional<Mesh *> mesh_merge_by_distance_connected(const Mesh &mesh,
const float merge_distance,
const bool only_loose_edges)
{
- const Span<MVert> verts = mesh.verts();
+ const Span<float3> positions = mesh.positions();
const Span<MEdge> edges = mesh.edges();
int vert_kill_len = 0;
@@ -1590,9 +1560,9 @@ std::optional<Mesh *> mesh_merge_by_distance_connected(const Mesh &mesh,
Array<WeldVertexCluster> vert_clusters(mesh.totvert);
- for (const int i : verts.index_range()) {
+ for (const int i : positions.index_range()) {
WeldVertexCluster &vc = vert_clusters[i];
- copy_v3_v3(vc.co, verts[i].co);
+ copy_v3_v3(vc.co, positions[i]);
vc.merged_verts = 0;
}
const float merge_dist_sq = square_f(merge_distance);
diff --git a/source/blender/geometry/intern/mesh_primitive_cuboid.cc b/source/blender/geometry/intern/mesh_primitive_cuboid.cc
index a014c488a3b..d32c7ce7b02 100644
--- a/source/blender/geometry/intern/mesh_primitive_cuboid.cc
+++ b/source/blender/geometry/intern/mesh_primitive_cuboid.cc
@@ -54,7 +54,7 @@ struct CuboidConfig {
}
};
-static void calculate_verts(const CuboidConfig &config, MutableSpan<MVert> verts)
+static void calculate_positions(const CuboidConfig &config, MutableSpan<float3> positions)
{
const float z_bottom = -config.size.z / 2.0f;
const float z_delta = config.size.z / config.edges_z;
@@ -75,7 +75,7 @@ static void calculate_verts(const CuboidConfig &config, MutableSpan<MVert> verts
const float y_pos = y_front + y_delta * y;
for (const int x : IndexRange(config.verts_x)) {
const float x_pos = x_left + x_delta * x;
- copy_v3_v3(verts[vert_index++].co, float3(x_pos, y_pos, z_pos));
+ copy_v3_v3(positions[vert_index++], float3(x_pos, y_pos, z_pos));
}
}
}
@@ -87,7 +87,7 @@ static void calculate_verts(const CuboidConfig &config, MutableSpan<MVert> verts
const float z_pos = z_bottom + z_delta * z;
for (const int x : IndexRange(config.verts_x)) {
const float x_pos = x_left + x_delta * x;
- copy_v3_v3(verts[vert_index++].co, float3(x_pos, y_pos, z_pos));
+ copy_v3_v3(positions[vert_index++], float3(x_pos, y_pos, z_pos));
}
}
else {
@@ -95,9 +95,9 @@ static void calculate_verts(const CuboidConfig &config, MutableSpan<MVert> verts
const float x_pos = x_left;
const float y_pos = y_front + y_delta * y;
const float z_pos = z_bottom + z_delta * z;
- copy_v3_v3(verts[vert_index++].co, float3(x_pos, y_pos, z_pos));
+ copy_v3_v3(positions[vert_index++], float3(x_pos, y_pos, z_pos));
const float x_pos2 = x_left + x_delta * config.edges_x;
- copy_v3_v3(verts[vert_index++].co, float3(x_pos2, y_pos, z_pos));
+ copy_v3_v3(positions[vert_index++], float3(x_pos2, y_pos, z_pos));
}
}
}
@@ -405,11 +405,11 @@ Mesh *create_cuboid_mesh(const float3 &size,
Mesh *mesh = BKE_mesh_new_nomain(
config.vertex_count, 0, 0, config.loop_count, config.poly_count);
- MutableSpan<MVert> verts = mesh->verts_for_write();
+ MutableSpan<float3> positions = mesh->positions_for_write();
MutableSpan<MPoly> polys = mesh->polys_for_write();
MutableSpan<MLoop> loops = mesh->loops_for_write();
- calculate_verts(config, verts);
+ calculate_positions(config, positions);
calculate_polys(config, polys, loops);
BKE_mesh_calc_edges(mesh, false, false);
diff --git a/source/blender/geometry/intern/mesh_to_curve_convert.cc b/source/blender/geometry/intern/mesh_to_curve_convert.cc
index c2a9b16c8b6..e283ee48a3b 100644
--- a/source/blender/geometry/intern/mesh_to_curve_convert.cc
+++ b/source/blender/geometry/intern/mesh_to_curve_convert.cc
@@ -76,7 +76,7 @@ struct CurveFromEdgesOutput {
IndexRange cyclic_curves;
};
-static CurveFromEdgesOutput edges_to_curve_point_indices(Span<MVert> verts,
+static CurveFromEdgesOutput edges_to_curve_point_indices(const int verts_num,
Span<std::pair<int, int>> edges)
{
Vector<int> vert_indices;
@@ -84,22 +84,22 @@ static CurveFromEdgesOutput edges_to_curve_point_indices(Span<MVert> verts,
Vector<int> curve_offsets;
/* Compute the number of edges connecting to each vertex. */
- Array<int> neighbor_count(verts.size(), 0);
+ Array<int> neighbor_count(verts_num, 0);
for (const std::pair<int, int> &edge : edges) {
neighbor_count[edge.first]++;
neighbor_count[edge.second]++;
}
/* Compute an offset into the array of neighbor edges based on the counts. */
- Array<int> neighbor_offsets(verts.size());
+ Array<int> neighbor_offsets(verts_num);
int start = 0;
- for (const int i : verts.index_range()) {
+ for (const int i : IndexRange(verts_num)) {
neighbor_offsets[i] = start;
start += neighbor_count[i];
}
/* Use as an index into the "neighbor group" for each vertex. */
- Array<int> used_slots(verts.size(), 0);
+ Array<int> used_slots(verts_num, 0);
/* Calculate the indices of each vertex's neighboring edges. */
Array<int> neighbors(edges.size() * 2);
for (const int i : edges.index_range()) {
@@ -114,7 +114,7 @@ static CurveFromEdgesOutput edges_to_curve_point_indices(Span<MVert> verts,
/* Now use the neighbor group offsets calculated above as a count used edges at each vertex. */
Array<int> unused_edges = std::move(used_slots);
- for (const int start_vert : verts.index_range()) {
+ for (const int start_vert : IndexRange(verts_num)) {
/* The vertex will be part of a cyclic curve. */
if (neighbor_count[start_vert] == 2) {
continue;
@@ -162,7 +162,7 @@ static CurveFromEdgesOutput edges_to_curve_point_indices(Span<MVert> verts,
const int cyclic_start = curve_offsets.size();
/* All remaining edges are part of cyclic curves (we skipped vertices with two edges before). */
- for (const int start_vert : verts.index_range()) {
+ for (const int start_vert : IndexRange(verts_num)) {
if (unused_edges[start_vert] != 2) {
continue;
}
@@ -212,8 +212,7 @@ static Vector<std::pair<int, int>> get_selected_edges(const Mesh &mesh, const In
bke::CurvesGeometry mesh_to_curve_convert(const Mesh &mesh, const IndexMask selection)
{
Vector<std::pair<int, int>> selected_edges = get_selected_edges(mesh, selection);
- const Span<MVert> verts = mesh.verts();
- CurveFromEdgesOutput output = edges_to_curve_point_indices(verts, selected_edges);
+ CurveFromEdgesOutput output = edges_to_curve_point_indices(mesh.totvert, selected_edges);
return create_curve_from_vert_indices(
mesh, output.vert_indices, output.curve_offsets, output.cyclic_curves);
diff --git a/source/blender/geometry/intern/mesh_to_volume.cc b/source/blender/geometry/intern/mesh_to_volume.cc
index b6025f8f1a9..ff321ddf057 100644
--- a/source/blender/geometry/intern/mesh_to_volume.cc
+++ b/source/blender/geometry/intern/mesh_to_volume.cc
@@ -16,7 +16,7 @@ namespace blender::geometry {
/* This class follows the MeshDataAdapter interface from openvdb. */
class OpenVDBMeshAdapter {
private:
- Span<MVert> verts_;
+ Span<float3> positions_;
Span<MLoop> loops_;
Span<MLoopTri> looptris_;
float4x4 transform_;
@@ -30,7 +30,10 @@ class OpenVDBMeshAdapter {
};
OpenVDBMeshAdapter::OpenVDBMeshAdapter(const Mesh &mesh, float4x4 transform)
- : verts_(mesh.verts()), loops_(mesh.loops()), looptris_(mesh.looptris()), transform_(transform)
+ : positions_(mesh.positions()),
+ loops_(mesh.loops()),
+ looptris_(mesh.looptris()),
+ transform_(transform)
{
}
@@ -41,7 +44,7 @@ size_t OpenVDBMeshAdapter::polygonCount() const
size_t OpenVDBMeshAdapter::pointCount() const
{
- return size_t(verts_.size());
+ return size_t(positions_.size());
}
size_t OpenVDBMeshAdapter::vertexCount(size_t /*polygon_index*/) const
@@ -55,8 +58,7 @@ void OpenVDBMeshAdapter::getIndexSpacePoint(size_t polygon_index,
openvdb::Vec3d &pos) const
{
const MLoopTri &looptri = looptris_[polygon_index];
- const MVert &vertex = verts_[loops_[looptri.tri[vertex_index]].v];
- const float3 transformed_co = transform_ * float3(vertex.co);
+ const float3 transformed_co = transform_ * positions_[loops_[looptri.tri[vertex_index]].v];
pos = &transformed_co.x;
}
diff --git a/source/blender/geometry/intern/realize_instances.cc b/source/blender/geometry/intern/realize_instances.cc
index 2d9c23df348..1619c81fb90 100644
--- a/source/blender/geometry/intern/realize_instances.cc
+++ b/source/blender/geometry/intern/realize_instances.cc
@@ -100,7 +100,7 @@ struct MeshElementStartIndices {
struct MeshRealizeInfo {
const Mesh *mesh = nullptr;
- Span<MVert> verts;
+ Span<float3> positions;
Span<MEdge> edges;
Span<MPoly> polys;
Span<MLoop> loops;
@@ -865,7 +865,7 @@ static AllMeshesInfo preprocess_meshes(const GeometrySet &geometry_set,
MeshRealizeInfo &mesh_info = info.realize_info[mesh_index];
const Mesh *mesh = info.order[mesh_index];
mesh_info.mesh = mesh;
- mesh_info.verts = mesh->verts();
+ mesh_info.positions = mesh->positions();
mesh_info.edges = mesh->edges();
mesh_info.polys = mesh->polys();
mesh_info.loops = mesh->loops();
@@ -911,7 +911,7 @@ static void execute_realize_mesh_task(const RealizeInstancesOptions &options,
const RealizeMeshTask &task,
const OrderedAttributes &ordered_attributes,
MutableSpan<GSpanAttributeWriter> dst_attribute_writers,
- MutableSpan<MVert> all_dst_verts,
+ MutableSpan<float3> all_dst_positions,
MutableSpan<MEdge> all_dst_edges,
MutableSpan<MPoly> all_dst_polys,
MutableSpan<MLoop> all_dst_loops,
@@ -921,27 +921,24 @@ static void execute_realize_mesh_task(const RealizeInstancesOptions &options,
const MeshRealizeInfo &mesh_info = *task.mesh_info;
const Mesh &mesh = *mesh_info.mesh;
- const Span<MVert> src_verts = mesh_info.verts;
+ const Span<float3> src_positions = mesh_info.positions;
const Span<MEdge> src_edges = mesh_info.edges;
const Span<MPoly> src_polys = mesh_info.polys;
const Span<MLoop> src_loops = mesh_info.loops;
- const IndexRange dst_vert_range(task.start_indices.vertex, src_verts.size());
+ const IndexRange dst_vert_range(task.start_indices.vertex, src_positions.size());
const IndexRange dst_edge_range(task.start_indices.edge, src_edges.size());
const IndexRange dst_poly_range(task.start_indices.poly, src_polys.size());
const IndexRange dst_loop_range(task.start_indices.loop, src_loops.size());
- MutableSpan<MVert> dst_verts = all_dst_verts.slice(dst_vert_range);
+ MutableSpan<float3> dst_positions = all_dst_positions.slice(dst_vert_range);
MutableSpan<MEdge> dst_edges = all_dst_edges.slice(dst_edge_range);
MutableSpan<MPoly> dst_polys = all_dst_polys.slice(dst_poly_range);
MutableSpan<MLoop> dst_loops = all_dst_loops.slice(dst_loop_range);
- threading::parallel_for(src_verts.index_range(), 1024, [&](const IndexRange vert_range) {
+ threading::parallel_for(src_positions.index_range(), 1024, [&](const IndexRange vert_range) {
for (const int i : vert_range) {
- const MVert &src_vert = src_verts[i];
- MVert &dst_vert = dst_verts[i];
- dst_vert = src_vert;
- copy_v3_v3(dst_vert.co, task.transform * float3(src_vert.co));
+ dst_positions[i] = task.transform * src_positions[i];
}
});
threading::parallel_for(src_edges.index_range(), 1024, [&](const IndexRange edge_range) {
@@ -1047,7 +1044,7 @@ static void execute_realize_mesh_tasks(const RealizeInstancesOptions &options,
MeshComponent &dst_component = r_realized_geometry.get_component_for_write<MeshComponent>();
dst_component.replace(dst_mesh);
bke::MutableAttributeAccessor dst_attributes = dst_mesh->attributes_for_write();
- MutableSpan<MVert> dst_verts = dst_mesh->verts_for_write();
+ MutableSpan<float3> dst_positions = dst_mesh->positions_for_write();
MutableSpan<MEdge> dst_edges = dst_mesh->edges_for_write();
MutableSpan<MPoly> dst_polys = dst_mesh->polys_for_write();
MutableSpan<MLoop> dst_loops = dst_mesh->loops_for_write();
@@ -1096,7 +1093,7 @@ static void execute_realize_mesh_tasks(const RealizeInstancesOptions &options,
task,
ordered_attributes,
dst_attribute_writers,
- dst_verts,
+ dst_positions,
dst_edges,
dst_polys,
dst_loops,
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
index 4b5c40c0e38..61771fdf821 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@ -1411,7 +1411,7 @@ typedef struct LineartEdgeNeighbor {
} LineartEdgeNeighbor;
typedef struct VertData {
- const MVert *mvert;
+ const float (*positions)[3];
LineartVert *v_arr;
double (*model_view)[4];
double (*model_view_proj)[4];
@@ -1422,10 +1422,9 @@ static void lineart_mvert_transform_task(void *__restrict userdata,
const TaskParallelTLS *__restrict UNUSED(tls))
{
VertData *vert_task_data = (VertData *)userdata;
- const MVert *m_v = &vert_task_data->mvert[i];
double co[4];
LineartVert *v = &vert_task_data->v_arr[i];
- copy_v3db_v3fl(co, m_v->co);
+ copy_v3db_v3fl(co, vert_task_data->positions[i]);
mul_v3_m4v3_db(v->gloc, vert_task_data->model_view, co);
mul_v4_m4v3_db(v->fbcoord, vert_task_data->model_view_proj, co);
v->index = i;
@@ -1844,6 +1843,7 @@ static void lineart_triangle_adjacent_assign(LineartTriangle *tri,
typedef struct TriData {
LineartObjectInfo *ob_info;
+ const float (*positions)[3];
const MLoopTri *mlooptri;
const int *material_indices;
LineartVert *vert_arr;
@@ -1859,6 +1859,7 @@ static void lineart_load_tri_task(void *__restrict userdata,
TriData *tri_task_data = (TriData *)userdata;
Mesh *me = tri_task_data->ob_info->original_me;
LineartObjectInfo *ob_info = tri_task_data->ob_info;
+ const float(*positions)[3] = tri_task_data->positions;
const MLoopTri *mlooptri = &tri_task_data->mlooptri[i];
const int *material_indices = tri_task_data->material_indices;
LineartVert *vert_arr = tri_task_data->vert_arr;
@@ -1896,8 +1897,7 @@ static void lineart_load_tri_task(void *__restrict userdata,
double gn[3];
float no[3];
- const MVert *verts = BKE_mesh_verts(me);
- normal_tri_v3(no, verts[v1].co, verts[v2].co, verts[v3].co);
+ normal_tri_v3(no, positions[v1], positions[v2], positions[v3]);
copy_v3db_v3fl(gn, no);
mul_v3_mat3_m4v3_db(tri->gn, ob_info->normal, gn);
normalize_v3_db(tri->gn);
@@ -2088,7 +2088,7 @@ static void lineart_geometry_object_load(LineartObjectInfo *ob_info,
vert_settings.min_iter_per_thread = 4000;
VertData vert_data;
- vert_data.mvert = BKE_mesh_verts(me);
+ vert_data.positions = BKE_mesh_positions(me);
vert_data.v_arr = la_v_arr;
vert_data.model_view = ob_info->model_view;
vert_data.model_view_proj = ob_info->model_view_proj;
@@ -2105,6 +2105,7 @@ static void lineart_geometry_object_load(LineartObjectInfo *ob_info,
TriData tri_data;
tri_data.ob_info = ob_info;
+ tri_data.positions = BKE_mesh_positions(me);
tri_data.mlooptri = mlooptri;
tri_data.material_indices = material_indices;
tri_data.vert_arr = la_v_arr;
diff --git a/source/blender/gpu/intern/gpu_shader_builder_stubs.cc b/source/blender/gpu/intern/gpu_shader_builder_stubs.cc
index 65bda7ba858..90df0621aaf 100644
--- a/source/blender/gpu/intern/gpu_shader_builder_stubs.cc
+++ b/source/blender/gpu/intern/gpu_shader_builder_stubs.cc
@@ -171,9 +171,10 @@ bool paint_is_grid_face_hidden(const uint * /*grid_hidden*/,
* \{ */
void BKE_mesh_calc_poly_normal(const struct MPoly * /*mpoly*/,
const struct MLoop * /*loopstart*/,
- const struct MVert * /*mvarray*/,
+ const float (*positions)[3],
float UNUSED(r_no[3]))
{
+ UNUSED_VARS(positions);
BLI_assert_unreachable();
}
diff --git a/source/blender/io/alembic/exporter/abc_writer_hair.cc b/source/blender/io/alembic/exporter/abc_writer_hair.cc
index 13136372c56..8dc7d37e692 100644
--- a/source/blender/io/alembic/exporter/abc_writer_hair.cc
+++ b/source/blender/io/alembic/exporter/abc_writer_hair.cc
@@ -122,7 +122,7 @@ void ABCHairWriter::write_hair_sample(const HierarchyContext &context,
MTFace *mtface = (MTFace *)CustomData_get_layer(&mesh->fdata, CD_MTFACE);
MFace *mface = (MFace *)CustomData_get_layer(&mesh->fdata, CD_MFACE);
- const MVert *mverts = BKE_mesh_verts(mesh);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(mesh);
if ((!mtface || !mface) && !uv_warning_shown_) {
@@ -162,7 +162,7 @@ void ABCHairWriter::write_hair_sample(const HierarchyContext &context,
uv_values.emplace_back(r_uv[0], r_uv[1]);
psys_interpolate_face(mesh,
- mverts,
+ positions,
vert_normals,
face,
tface,
@@ -245,7 +245,7 @@ void ABCHairWriter::write_hair_child_sample(const HierarchyContext &context,
MFace *mface = (MFace *)CustomData_get_layer(&mesh->fdata, CD_MFACE);
MTFace *mtface = (MTFace *)CustomData_get_layer(&mesh->fdata, CD_MTFACE);
- const MVert *mverts = BKE_mesh_verts(mesh);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(mesh);
ParticleSystem *psys = context.particle_system;
@@ -279,7 +279,7 @@ void ABCHairWriter::write_hair_child_sample(const HierarchyContext &context,
uv_values.emplace_back(r_uv[0], r_uv[1]);
psys_interpolate_face(mesh,
- mverts,
+ positions,
vert_normals,
face,
tface,
diff --git a/source/blender/io/alembic/exporter/abc_writer_mesh.cc b/source/blender/io/alembic/exporter/abc_writer_mesh.cc
index 084d26198bc..f03ff52376e 100644
--- a/source/blender/io/alembic/exporter/abc_writer_mesh.cc
+++ b/source/blender/io/alembic/exporter/abc_writer_mesh.cc
@@ -436,9 +436,9 @@ static void get_vertices(struct Mesh *mesh, std::vector<Imath::V3f> &points)
points.clear();
points.resize(mesh->totvert);
- const Span<MVert> verts = mesh->verts();
+ const Span<float3> positions = mesh->positions();
for (int i = 0, e = mesh->totvert; i < e; i++) {
- copy_yup_from_zup(points[i].getValue(), verts[i].co);
+ copy_yup_from_zup(points[i].getValue(), positions[i]);
}
}
diff --git a/source/blender/io/alembic/intern/abc_customdata.h b/source/blender/io/alembic/intern/abc_customdata.h
index 0ddba866016..ed96d427689 100644
--- a/source/blender/io/alembic/intern/abc_customdata.h
+++ b/source/blender/io/alembic/intern/abc_customdata.h
@@ -6,6 +6,8 @@
* \ingroup balembic
*/
+#include "BLI_math_vec_types.hh"
+
#include <Alembic/Abc/All.h>
#include <Alembic/AbcGeom/All.h>
@@ -15,7 +17,6 @@ struct CustomData;
struct MLoop;
struct MLoopUV;
struct MPoly;
-struct MVert;
struct Mesh;
using Alembic::Abc::ICompoundProperty;
@@ -34,7 +35,7 @@ struct CDStreamConfig {
MPoly *mpoly;
int totpoly;
- MVert *mvert;
+ float3 *positions;
int totvert;
MLoopUV *mloopuv;
diff --git a/source/blender/io/alembic/intern/abc_reader_mesh.cc b/source/blender/io/alembic/intern/abc_reader_mesh.cc
index 2531bd62609..58b7a28c419 100644
--- a/source/blender/io/alembic/intern/abc_reader_mesh.cc
+++ b/source/blender/io/alembic/intern/abc_reader_mesh.cc
@@ -122,31 +122,30 @@ struct AbcMeshData {
UInt32ArraySamplePtr uvs_indices;
};
-static void read_mverts_interp(MVert *mverts,
+static void read_mverts_interp(float3 *mesh_positions,
const P3fArraySamplePtr &positions,
const P3fArraySamplePtr &ceil_positions,
const double weight)
{
float tmp[3];
for (int i = 0; i < positions->size(); i++) {
- MVert &mvert = mverts[i];
const Imath::V3f &floor_pos = (*positions)[i];
const Imath::V3f &ceil_pos = (*ceil_positions)[i];
interp_v3_v3v3(tmp, floor_pos.getValue(), ceil_pos.getValue(), float(weight));
- copy_zup_from_yup(mvert.co, tmp);
+ copy_zup_from_yup(mesh_positions[i], tmp);
}
}
static void read_mverts(CDStreamConfig &config, const AbcMeshData &mesh_data)
{
- MVert *mverts = config.mvert;
+ float3 *mesh_positions = config.positions;
const P3fArraySamplePtr &positions = mesh_data.positions;
if (config.use_vertex_interpolation && config.weight != 0.0f &&
mesh_data.ceil_positions != nullptr &&
mesh_data.ceil_positions->size() == positions->size()) {
- read_mverts_interp(mverts, positions, mesh_data.ceil_positions, config.weight);
+ read_mverts_interp(mesh_positions, positions, mesh_data.ceil_positions, config.weight);
return;
}
@@ -155,12 +154,11 @@ static void read_mverts(CDStreamConfig &config, const AbcMeshData &mesh_data)
void read_mverts(Mesh &mesh, const P3fArraySamplePtr positions, const N3fArraySamplePtr normals)
{
- MutableSpan<MVert> verts = mesh.verts_for_write();
+ MutableSpan<float3> mesh_positions = mesh.positions_for_write();
for (int i = 0; i < positions->size(); i++) {
- MVert &mvert = verts[i];
Imath::V3f pos_in = (*positions)[i];
- copy_zup_from_yup(mvert.co, pos_in.getValue());
+ copy_zup_from_yup(mesh_positions[i], pos_in.getValue());
}
if (normals) {
float(*vert_normals)[3] = BKE_mesh_vertex_normals_for_write(&mesh);
@@ -517,7 +515,7 @@ CDStreamConfig get_config(Mesh *mesh, const bool use_vertex_interpolation)
{
CDStreamConfig config;
config.mesh = mesh;
- config.mvert = mesh->verts_for_write().data();
+ config.positions = mesh->positions_for_write().data();
config.mloop = mesh->loops_for_write().data();
config.mpoly = mesh->polys_for_write().data();
config.totvert = mesh->totvert;
diff --git a/source/blender/io/collada/GeometryExporter.cpp b/source/blender/io/collada/GeometryExporter.cpp
index f6f9026481c..385cf5fefc3 100644
--- a/source/blender/io/collada/GeometryExporter.cpp
+++ b/source/blender/io/collada/GeometryExporter.cpp
@@ -27,6 +27,7 @@
#include "collada_internal.h"
#include "collada_utils.h"
+using blender::float3;
using blender::Span;
void GeometryExporter::exportGeom()
@@ -119,12 +120,13 @@ void GeometryExporter::operator()(Object *ob)
if (this->export_settings.get_include_shapekeys()) {
Key *key = BKE_key_from_object(ob);
if (key) {
- blender::MutableSpan<MVert> verts = me->verts_for_write();
+ blender::MutableSpan<float3> positions = me->positions_for_write();
KeyBlock *kb = (KeyBlock *)key->block.first;
/* skip the basis */
kb = kb->next;
for (; kb; kb = kb->next) {
- BKE_keyblock_convert_to_mesh(kb, verts.data(), me->totvert);
+ BKE_keyblock_convert_to_mesh(
+ kb, reinterpret_cast<float(*)[3]>(positions.data()), me->totvert);
export_key_mesh(ob, me, kb);
}
}
@@ -434,13 +436,13 @@ void GeometryExporter::create_mesh_primitive_list(short material_index,
void GeometryExporter::createVertsSource(std::string geom_id, Mesh *me)
{
- const Span<MVert> verts = me->verts();
+ const Span<float3> positions = me->positions();
COLLADASW::FloatSourceF source(mSW);
source.setId(getIdBySemantics(geom_id, COLLADASW::InputSemantic::POSITION));
source.setArrayId(getIdBySemantics(geom_id, COLLADASW::InputSemantic::POSITION) +
ARRAY_ID_SUFFIX);
- source.setAccessorCount(verts.size());
+ source.setAccessorCount(positions.size());
source.setAccessorStride(3);
COLLADASW::SourceBase::ParameterNameList &param = source.getParameterNameList();
@@ -451,13 +453,15 @@ void GeometryExporter::createVertsSource(std::string geom_id, Mesh *me)
* count = ""> */
source.prepareToAppendValues();
/* appends data to <float_array> */
- for (const int i : verts.index_range()) {
+ for (const int i : positions.index_range()) {
Vector co;
if (export_settings.get_apply_global_orientation()) {
- bc_add_global_transform(co, verts[i].co, export_settings.get_global_transform());
+ float co_c[3];
+ copy_v3_v3(co_c, positions[i]);
+ bc_add_global_transform(co, co_c, export_settings.get_global_transform());
}
else {
- copy_v3_v3(co, verts[i].co);
+ copy_v3_v3(co, positions[i]);
}
source.appendValues(co[0], co[1], co[2]);
}
@@ -577,11 +581,6 @@ bool operator<(const Normal &a, const Normal &b)
void GeometryExporter::createNormalsSource(std::string geom_id, Mesh *me, std::vector<Normal> &nor)
{
-#if 0
- int totverts = dm->getNumVerts(dm);
- MVert *verts = dm->getVertArray(dm);
-#endif
-
COLLADASW::FloatSourceF source(mSW);
source.setId(getIdBySemantics(geom_id, COLLADASW::InputSemantic::NORMAL));
source.setArrayId(getIdBySemantics(geom_id, COLLADASW::InputSemantic::NORMAL) + ARRAY_ID_SUFFIX);
@@ -615,7 +614,7 @@ void GeometryExporter::create_normals(std::vector<Normal> &normals,
std::map<Normal, uint> shared_normal_indices;
int last_normal_index = -1;
- const Span<MVert> verts = me->verts();
+ const Span<float3> positions = me->positions();
const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(me);
const Span<MPoly> polys = me->polys();
const Span<MLoop> loops = me->loops();
@@ -636,7 +635,10 @@ void GeometryExporter::create_normals(std::vector<Normal> &normals,
/* For flat faces use face normal as vertex normal: */
float vector[3];
- BKE_mesh_calc_poly_normal(mpoly, &loops[mpoly->loopstart], verts.data(), vector);
+ BKE_mesh_calc_poly_normal(mpoly,
+ &loops[mpoly->loopstart],
+ reinterpret_cast<const float(*)[3]>(positions.data()),
+ vector);
Normal n = {vector[0], vector[1], vector[2]};
normals.push_back(n);
diff --git a/source/blender/io/collada/MeshImporter.cpp b/source/blender/io/collada/MeshImporter.cpp
index 1a28adf50a5..6c566d9172f 100644
--- a/source/blender/io/collada/MeshImporter.cpp
+++ b/source/blender/io/collada/MeshImporter.cpp
@@ -33,6 +33,7 @@
#include "MeshImporter.h"
#include "collada_utils.h"
+using blender::float3;
using blender::MutableSpan;
/* get node name, or fall back to original id if not present (name is optional) */
@@ -349,10 +350,11 @@ void MeshImporter::read_vertices(COLLADAFW::Mesh *mesh, Mesh *me)
}
me->totvert = pos.getFloatValues()->getCount() / stride;
- CustomData_add_layer(&me->vdata, CD_MVERT, CD_SET_DEFAULT, nullptr, me->totvert);
- MutableSpan<MVert> verts = me->verts_for_write();
- for (const int i : verts.index_range()) {
- get_vector(verts[i].co, pos, i, stride);
+ CustomData_add_layer_named(
+ &me->vdata, CD_PROP_FLOAT3, CD_CONSTRUCT, nullptr, me->totvert, "position");
+ MutableSpan<float3> positions = me->positions_for_write();
+ for (const int i : positions.index_range()) {
+ get_vector(positions[i], pos, i, stride);
}
}
diff --git a/source/blender/io/stl/importer/stl_import_mesh.cc b/source/blender/io/stl/importer/stl_import_mesh.cc
index de993cd2f27..b8ebba380ef 100644
--- a/source/blender/io/stl/importer/stl_import_mesh.cc
+++ b/source/blender/io/stl/importer/stl_import_mesh.cc
@@ -76,11 +76,9 @@ Mesh *STLMeshHelper::to_mesh(Main *bmain, char *mesh_name)
id_us_min(&mesh->id);
mesh->totvert = verts_.size();
- CustomData_add_layer(&mesh->vdata, CD_MVERT, CD_SET_DEFAULT, nullptr, mesh->totvert);
- MutableSpan<MVert> verts = mesh->verts_for_write();
- for (int i = 0; i < mesh->totvert; i++) {
- copy_v3_v3(verts[i].co, verts_[i]);
- }
+ CustomData_add_layer_named(
+ &mesh->vdata, CD_PROP_FLOAT3, CD_CONSTRUCT, nullptr, mesh->totvert, "position");
+ mesh->positions_for_write().copy_from(verts_);
mesh->totpoly = tris_.size();
mesh->totloop = tris_.size() * 3;
diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc
index 8138f38fcad..a1d365609ab 100644
--- a/source/blender/io/usd/intern/usd_reader_mesh.cc
+++ b/source/blender/io/usd/intern/usd_reader_mesh.cc
@@ -699,12 +699,9 @@ void USDMeshReader::read_mesh_sample(ImportSettings *settings,
* in code that expect this data to be there. */
if (new_mesh || (settings->read_flag & MOD_MESHSEQ_READ_VERT) != 0) {
- MutableSpan<MVert> verts = mesh->verts_for_write();
+ MutableSpan<float3> verts = mesh->positions_for_write();
for (int i = 0; i < positions_.size(); i++) {
- MVert &mvert = verts[i];
- mvert.co[0] = positions_[i][0];
- mvert.co[1] = positions_[i][1];
- mvert.co[2] = positions_[i][2];
+ verts[i] = {positions_[i][0], positions_[i][1], positions_[i][2]};
}
read_vertex_creases(mesh, motionSampleTime);
diff --git a/source/blender/io/usd/intern/usd_writer_mesh.cc b/source/blender/io/usd/intern/usd_writer_mesh.cc
index e7d79e888e4..0314119fb0f 100644
--- a/source/blender/io/usd/intern/usd_writer_mesh.cc
+++ b/source/blender/io/usd/intern/usd_writer_mesh.cc
@@ -249,9 +249,10 @@ static void get_vertices(const Mesh *mesh, USDMeshData &usd_mesh_data)
{
usd_mesh_data.points.reserve(mesh->totvert);
- const Span<MVert> verts = mesh->verts();
- for (const int i : verts.index_range()) {
- usd_mesh_data.points.push_back(pxr::GfVec3f(verts[i].co));
+ const Span<float3> positions = mesh->positions();
+ for (const int i : positions.index_range()) {
+ const float3 &position = positions[i];
+ usd_mesh_data.points.push_back(pxr::GfVec3f(position.x, position.y, position.z));
}
}
diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
index a95f917869b..696c3456731 100644
--- a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
+++ b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
@@ -268,8 +268,8 @@ const char *OBJMesh::get_object_material_name(const int16_t mat_nr) const
float3 OBJMesh::calc_vertex_coords(const int vert_index, const float global_scale) const
{
float3 r_coords;
- const Span<MVert> verts = export_mesh_eval_->verts();
- copy_v3_v3(r_coords, verts[vert_index].co);
+ const Span<float3> positions = export_mesh_eval_->positions();
+ copy_v3_v3(r_coords, positions[vert_index]);
mul_m4_v3(world_and_axes_transform_, r_coords);
mul_v3_fl(r_coords, global_scale);
return r_coords;
@@ -355,11 +355,14 @@ Span<int> OBJMesh::calc_poly_uv_indices(const int poly_index) const
float3 OBJMesh::calc_poly_normal(const int poly_index) const
{
float3 r_poly_normal;
- const Span<MVert> verts = export_mesh_eval_->verts();
+ const Span<float3> positions = export_mesh_eval_->positions();
const Span<MPoly> polys = export_mesh_eval_->polys();
const Span<MLoop> loops = export_mesh_eval_->loops();
const MPoly &poly = polys[poly_index];
- BKE_mesh_calc_poly_normal(&poly, &loops[poly.loopstart], verts.data(), r_poly_normal);
+ BKE_mesh_calc_poly_normal(&poly,
+ &loops[poly.loopstart],
+ reinterpret_cast<const float(*)[3]>(positions.data()),
+ r_poly_normal);
mul_m3_v3(world_and_axes_normal_transform_, r_poly_normal);
normalize_v3(r_poly_normal);
return r_poly_normal;
diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc
index 56ad7fd4563..2204d061a1e 100644
--- a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc
+++ b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc
@@ -154,7 +154,7 @@ void MeshFromGeometry::fixup_invalid_faces()
void MeshFromGeometry::create_vertices(Mesh *mesh)
{
- MutableSpan<MVert> verts = mesh->verts_for_write();
+ MutableSpan<float3> positions = mesh->positions_for_write();
/* Go through all the global vertex indices from min to max,
* checking which ones are actually and building a global->local
* index mapping. Write out the used vertex positions into the Mesh
@@ -168,7 +168,7 @@ void MeshFromGeometry::create_vertices(Mesh *mesh)
}
int local_vi = int(mesh_geometry_.global_to_local_vertices_.size());
BLI_assert(local_vi >= 0 && local_vi < mesh->totvert);
- copy_v3_v3(verts[local_vi].co, global_vertices_.vertices[vi]);
+ copy_v3_v3(positions[local_vi], global_vertices_.vertices[vi]);
mesh_geometry_.global_to_local_vertices_.add_new(vi, local_vi);
}
}
diff --git a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc
index f459e1ab1bd..89f4e64c787 100644
--- a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc
+++ b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc
@@ -101,9 +101,9 @@ class obj_importer_test : public BlendfileLoadingBaseTest {
EXPECT_EQ(mesh->totedge, exp.mesh_totedge_or_curve_endp);
EXPECT_EQ(mesh->totpoly, exp.mesh_totpoly_or_curve_order);
EXPECT_EQ(mesh->totloop, exp.mesh_totloop_or_curve_cyclic);
- const Span<MVert> verts = mesh->verts();
- EXPECT_V3_NEAR(verts.first().co, exp.vert_first, 0.0001f);
- EXPECT_V3_NEAR(verts.last().co, exp.vert_last, 0.0001f);
+ const Span<float3> positions = mesh->positions();
+ EXPECT_V3_NEAR(positions.first(), exp.vert_first, 0.0001f);
+ EXPECT_V3_NEAR(positions.last(), exp.vert_last, 0.0001f);
const float3 *lnors = (const float3 *)CustomData_get_layer(&mesh->ldata, CD_NORMAL);
float3 normal_first = lnors != nullptr ? lnors[0] : float3(0, 0, 0);
EXPECT_V3_NEAR(normal_first, exp.normal_first, 0.0001f);
diff --git a/source/blender/makesdna/DNA_customdata_types.h b/source/blender/makesdna/DNA_customdata_types.h
index 0355ed3febe..124df373c5d 100644
--- a/source/blender/makesdna/DNA_customdata_types.h
+++ b/source/blender/makesdna/DNA_customdata_types.h
@@ -88,8 +88,8 @@ typedef enum eCustomDataType {
*/
CD_AUTO_FROM_NAME = -1,
- CD_MVERT = 0,
#ifdef DNA_DEPRECATED_ALLOW
+ CD_MVERT = 0, /* DEPRECATED */
CD_MSTICKY = 1, /* DEPRECATED */
#endif
CD_MDEFORMVERT = 2,
@@ -159,7 +159,7 @@ typedef enum eCustomDataType {
} eCustomDataType;
/* Bits for eCustomDataMask */
-#define CD_MASK_MVERT (1 << CD_MVERT)
+// #define CD_MASK_MVERT (1 << CD_MVERT) /* DEPRECATED */
// #define CD_MASK_MSTICKY (1 << CD_MSTICKY) /* DEPRECATED */
#define CD_MASK_MDEFORMVERT (1 << CD_MDEFORMVERT)
#define CD_MASK_MEDGE (1 << CD_MEDGE)
diff --git a/source/blender/makesdna/DNA_mesh_types.h b/source/blender/makesdna/DNA_mesh_types.h
index 3f951583741..39253aafa7c 100644
--- a/source/blender/makesdna/DNA_mesh_types.h
+++ b/source/blender/makesdna/DNA_mesh_types.h
@@ -13,6 +13,10 @@
#include "DNA_meshdata_types.h"
#include "DNA_session_uuid_types.h"
+#ifdef __cplusplus
+# include "BLI_math_vec_types.hh"
+#endif
+
/** Workaround to forward-declare C++ type in C header. */
#ifdef __cplusplus
namespace blender {
@@ -40,7 +44,6 @@ struct MCol;
struct MEdge;
struct MFace;
struct MLoopTri;
-struct MVert;
struct Material;
typedef struct Mesh {
@@ -61,7 +64,7 @@ typedef struct Mesh {
*/
struct Material **mat;
- /** The number of vertices (#MVert) in the mesh, and the size of #vdata. */
+ /** The number of vertices in the mesh, and the size of #vdata. */
int totvert;
/** The number of edges (#MEdge) in the mesh, and the size of #edata. */
int totedge;
@@ -210,12 +213,11 @@ typedef struct Mesh {
MeshRuntimeHandle *runtime;
#ifdef __cplusplus
/**
- * Array of vertex positions (and various other data). Edges and faces are defined by indices
- * into this array.
+ * Array of vertex positions. Edges and faces are defined by indices into this array.
*/
- blender::Span<MVert> verts() const;
+ blender::Span<blender::float3> positions() const;
/** Write access to vertex data. */
- blender::MutableSpan<MVert> verts_for_write();
+ blender::MutableSpan<blender::float3> positions_for_write();
/**
* Array of edges, containing vertex indices. For simple triangle or quad meshes, edges could be
* calculated from the #MPoly and #MLoop arrays, however, edges need to be stored explicitly to
diff --git a/source/blender/makesdna/DNA_meshdata_types.h b/source/blender/makesdna/DNA_meshdata_types.h
index f1c2dcaae68..1950e4d5e3b 100644
--- a/source/blender/makesdna/DNA_meshdata_types.h
+++ b/source/blender/makesdna/DNA_meshdata_types.h
@@ -19,12 +19,11 @@ extern "C" {
* \{ */
/**
- * Mesh Vertices.
- *
- * Typically accessed from #Mesh.verts()
+ * Deprecated mesh vertex data structure. Now stored with generic attributes.
*/
+#ifdef DNA_DEPRECATED_ALLOW
typedef struct MVert {
- float co[3];
+ float co_legacy[3];
/**
* Deprecated flag for storing hide status and selection, which are now stored in separate
* generic attributes. Kept for file read and write.
@@ -38,8 +37,6 @@ typedef struct MVert {
} MVert;
/** #MVert.flag */
-
-#ifdef DNA_DEPRECATED_ALLOW
enum {
/** Deprecated selection status. Now stored in ".select_vert" attribute. */
/* SELECT = (1 << 0), */
@@ -111,7 +108,7 @@ enum {
* Typically accessed with #Mesh.loops().
*/
typedef struct MLoop {
- /** Vertex index into an #MVert array. */
+ /** Vertex index. */
unsigned int v;
/** Edge index into an #MEdge array. */
unsigned int e;
@@ -152,7 +149,7 @@ enum {
/**
* #MLoopTri's are lightweight triangulation data,
* for functionality that doesn't support ngons (#MPoly).
- * This is cache data created from (#MPoly, #MLoop & #MVert arrays).
+ * This is cache data created from (#MPoly, #MLoop & position arrays).
* There is no attempt to maintain this data's validity over time,
* any changes to the underlying mesh invalidate the #MLoopTri array,
* which will need to be re-calculated.
@@ -179,9 +176,9 @@ enum {
*
* // access vertex locations.
* float *vtri_co[3] = {
- * mvert[mloop[lt->tri[0]].v].co,
- * mvert[mloop[lt->tri[1]].v].co,
- * mvert[mloop[lt->tri[2]].v].co,
+ * positions[mloop[lt->tri[0]].v],
+ * positions[mloop[lt->tri[1]].v],
+ * positions[mloop[lt->tri[2]].v],
* };
*
* // access UV coordinates (works for all loop data, vertex colors... etc).
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index c4180071352..465dae89ad1 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -849,17 +849,17 @@ typedef struct CollisionModifierData {
ModifierData modifier;
/** Position at the beginning of the frame. */
- struct MVert *x;
+ float (*x)[3];
/** Position at the end of the frame. */
- struct MVert *xnew;
+ float (*xnew)[3];
/** Unused at the moment, but was discussed during sprint. */
- struct MVert *xold;
+ float (*xold)[3];
/** New position at the actual inter-frame step. */
- struct MVert *current_xnew;
+ float (*current_xnew)[3];
/** Position at the actual inter-frame step. */
- struct MVert *current_x;
+ float (*current_x)[3];
/** (xnew - x) at the actual inter-frame step. */
- struct MVert *current_v;
+ float (*current_v)[3];
struct MVertTri *tri;
@@ -879,9 +879,9 @@ typedef struct SurfaceModifierData {
ModifierData modifier;
/** Old position. */
- struct MVert *x;
+ float (*x)[3];
/** Velocity. */
- struct MVert *v;
+ float (*v)[3];
struct Mesh *mesh;
diff --git a/source/blender/makesdna/intern/dna_rename_defs.h b/source/blender/makesdna/intern/dna_rename_defs.h
index afc907b7780..4b810f9a536 100644
--- a/source/blender/makesdna/intern/dna_rename_defs.h
+++ b/source/blender/makesdna/intern/dna_rename_defs.h
@@ -102,6 +102,7 @@ DNA_STRUCT_RENAME_ELEM(Object_Runtime, crazyspace_num_verts, crazyspace_verts_nu
DNA_STRUCT_RENAME_ELEM(MEdge, bweight, bweight_legacy)
DNA_STRUCT_RENAME_ELEM(MEdge, crease, crease_legacy)
DNA_STRUCT_RENAME_ELEM(MPoly, mat_nr, mat_nr_legacy)
+DNA_STRUCT_RENAME_ELEM(MVert, co, co_legacy)
DNA_STRUCT_RENAME_ELEM(MVert, bweight, bweight_legacy)
DNA_STRUCT_RENAME_ELEM(MVert, flag, flag_legacy)
DNA_STRUCT_RENAME_ELEM(ParticleSettings, child_nbr, child_percent)
diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c
index f13132b5b7c..9d28666b8a0 100644
--- a/source/blender/makesrna/intern/rna_mesh.c
+++ b/source/blender/makesrna/intern/rna_mesh.c
@@ -365,8 +365,8 @@ static void rna_Mesh_update_positions_tag(Main *bmain, Scene *scene, PointerRNA
static int rna_MeshVertex_index_get(PointerRNA *ptr)
{
const Mesh *mesh = rna_mesh(ptr);
- const MVert *vert = (MVert *)ptr->data;
- const int index = (int)(vert - BKE_mesh_verts(mesh));
+ const float(*position)[3] = (const float(*)[3])ptr->data;
+ const int index = (int)(position - BKE_mesh_positions(mesh));
BLI_assert(index >= 0);
BLI_assert(index < mesh->totvert);
return index;
@@ -439,6 +439,16 @@ int rna_Mesh_loop_triangles_lookup_int(PointerRNA *ptr, int index, PointerRNA *r
return true;
}
+static void rna_MeshVertex_co_get(PointerRNA *ptr, float *value)
+{
+ copy_v3_v3(value, (const float *)ptr->data);
+}
+
+static void rna_MeshVertex_co_set(PointerRNA *ptr, const float *value)
+{
+ copy_v3_v3((float *)ptr->data, value);
+}
+
static void rna_MeshVertex_normal_get(PointerRNA *ptr, float *value)
{
Mesh *mesh = rna_mesh(ptr);
@@ -618,9 +628,9 @@ static void rna_MeshPolygon_normal_get(PointerRNA *ptr, float *values)
{
Mesh *me = rna_mesh(ptr);
MPoly *mp = (MPoly *)ptr->data;
- const MVert *verts = BKE_mesh_verts(me);
+ const float(*positions)[3] = BKE_mesh_positions(me);
const MLoop *loops = BKE_mesh_loops(me);
- BKE_mesh_calc_poly_normal(mp, loops + mp->loopstart, verts, values);
+ BKE_mesh_calc_poly_normal(mp, loops + mp->loopstart, positions, values);
}
static bool rna_MeshPolygon_hide_get(PointerRNA *ptr)
@@ -695,18 +705,18 @@ static void rna_MeshPolygon_center_get(PointerRNA *ptr, float *values)
{
Mesh *me = rna_mesh(ptr);
MPoly *mp = (MPoly *)ptr->data;
- const MVert *verts = BKE_mesh_verts(me);
+ const float(*positions)[3] = BKE_mesh_positions(me);
const MLoop *loops = BKE_mesh_loops(me);
- BKE_mesh_calc_poly_center(mp, loops + mp->loopstart, verts, values);
+ BKE_mesh_calc_poly_center(mp, loops + mp->loopstart, positions, values);
}
static float rna_MeshPolygon_area_get(PointerRNA *ptr)
{
Mesh *me = (Mesh *)ptr->owner_id;
MPoly *mp = (MPoly *)ptr->data;
- const MVert *verts = BKE_mesh_verts(me);
+ const float(*positions)[3] = BKE_mesh_positions(me);
const MLoop *loops = BKE_mesh_loops(me);
- return BKE_mesh_calc_poly_area(mp, loops + mp->loopstart, verts);
+ return BKE_mesh_calc_poly_area(mp, loops + mp->loopstart, positions);
}
static void rna_MeshPolygon_flip(ID *id, MPoly *mp)
@@ -733,13 +743,13 @@ static void rna_MeshLoopTriangle_normal_get(PointerRNA *ptr, float *values)
{
Mesh *me = rna_mesh(ptr);
MLoopTri *lt = (MLoopTri *)ptr->data;
- const MVert *verts = BKE_mesh_verts(me);
+ const float(*positions)[3] = BKE_mesh_positions(me);
const MLoop *loops = BKE_mesh_loops(me);
uint v1 = loops[lt->tri[0]].v;
uint v2 = loops[lt->tri[1]].v;
uint v3 = loops[lt->tri[2]].v;
- normal_tri_v3(values, verts[v1].co, verts[v2].co, verts[v3].co);
+ normal_tri_v3(values, positions[v1], positions[v2], positions[v3]);
}
static void rna_MeshLoopTriangle_split_normals_get(PointerRNA *ptr, float *values)
@@ -764,12 +774,12 @@ static float rna_MeshLoopTriangle_area_get(PointerRNA *ptr)
{
Mesh *me = rna_mesh(ptr);
MLoopTri *lt = (MLoopTri *)ptr->data;
- const MVert *verts = BKE_mesh_verts(me);
+ const float(*positions)[3] = BKE_mesh_positions(me);
const MLoop *loops = BKE_mesh_loops(me);
uint v1 = loops[lt->tri[0]].v;
uint v2 = loops[lt->tri[1]].v;
uint v3 = loops[lt->tri[2]].v;
- return area_tri_v3(verts[v1].co, verts[v2].co, verts[v3].co);
+ return area_tri_v3(positions[v1], positions[v2], positions[v3]);
}
static void rna_MeshLoopColor_color_get(PointerRNA *ptr, float *values)
@@ -835,19 +845,19 @@ static void rna_MeshVertex_groups_begin(CollectionPropertyIterator *iter, Pointe
static void rna_MeshVertex_undeformed_co_get(PointerRNA *ptr, float values[3])
{
Mesh *me = rna_mesh(ptr);
- MVert *mvert = (MVert *)ptr->data;
+ const float *position = (const float *)ptr->data;
const float(*orco)[3] = CustomData_get_layer(&me->vdata, CD_ORCO);
if (orco) {
const int index = rna_MeshVertex_index_get(ptr);
- /* orco is normalized to 0..1, we do inverse to match mvert->co */
+ /* orco is normalized to 0..1, we do inverse to match the vertex position */
float loc[3], size[3];
BKE_mesh_texspace_get(me->texcomesh ? me->texcomesh : me, loc, size);
madd_v3_v3v3v3(values, loc, orco[index], size);
}
else {
- copy_v3_v3(values, mvert->co);
+ copy_v3_v3(values, position);
}
}
@@ -1637,7 +1647,7 @@ static void rna_Mesh_vertices_begin(CollectionPropertyIterator *iter, PointerRNA
{
Mesh *mesh = rna_mesh(ptr);
rna_iterator_array_begin(
- iter, BKE_mesh_verts_for_write(mesh), sizeof(MVert), mesh->totvert, false, NULL);
+ iter, BKE_mesh_positions_for_write(mesh), sizeof(float[3]), mesh->totvert, false, NULL);
}
static int rna_Mesh_vertices_length(PointerRNA *ptr)
{
@@ -1652,7 +1662,7 @@ int rna_Mesh_vertices_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr)
}
r_ptr->owner_id = &mesh->id;
r_ptr->type = &RNA_MeshVertex;
- r_ptr->data = &BKE_mesh_verts_for_write(mesh)[index];
+ r_ptr->data = &BKE_mesh_positions_for_write(mesh)[index];
return true;
}
@@ -2230,13 +2240,14 @@ static void rna_def_mvert(BlenderRNA *brna)
PropertyRNA *prop;
srna = RNA_def_struct(brna, "MeshVertex", NULL);
- RNA_def_struct_sdna(srna, "MVert");
RNA_def_struct_ui_text(srna, "Mesh Vertex", "Vertex in a Mesh data-block");
RNA_def_struct_path_func(srna, "rna_MeshVertex_path");
RNA_def_struct_ui_icon(srna, ICON_VERTEXSEL);
prop = RNA_def_property(srna, "co", PROP_FLOAT, PROP_TRANSLATION);
- RNA_def_property_ui_text(prop, "Location", "");
+ RNA_def_property_array(prop, 3);
+ RNA_def_property_float_funcs(prop, "rna_MeshVertex_co_get", "rna_MeshVertex_co_set", NULL);
+ RNA_def_property_ui_text(prop, "Position", "");
RNA_def_property_update(prop, 0, "rna_Mesh_update_positions_tag");
prop = RNA_def_property(srna, "normal", PROP_FLOAT, PROP_DIRECTION);
diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c
index a56e7d28ef7..17433ffc23e 100644
--- a/source/blender/makesrna/intern/rna_particle.c
+++ b/source/blender/makesrna/intern/rna_particle.c
@@ -212,10 +212,9 @@ static void rna_ParticleHairKey_location_object_get(PointerRNA *ptr, float *valu
if (pa) {
Mesh *hair_mesh = (psmd->psys->flag & PSYS_HAIR_DYNAMICS) ? psmd->psys->hair_out_mesh : NULL;
- const MVert *verts = BKE_mesh_verts(hair_mesh);
+ const float(*positions)[3] = BKE_mesh_positions(hair_mesh);
if (hair_mesh) {
- const MVert *mv = &verts[pa->hair_index + (hkey - pa->hair)];
- copy_v3_v3(values, mv->co);
+ copy_v3_v3(values, positions[pa->hair_index + (hkey - pa->hair)]);
}
else {
float hairmat[4][4];
@@ -279,9 +278,8 @@ static void hair_key_location_object_set(HairKey *hair_key,
if (hair_key_index == -1) {
return;
}
- MVert *verts = BKE_mesh_verts_for_write(hair_mesh);
- MVert *mv = &verts[particle->hair_index + (hair_key_index)];
- copy_v3_v3(mv->co, src_co);
+ float(*positions)[3] = BKE_mesh_positions_for_write(hair_mesh);
+ copy_v3_v3(positions[particle->hair_index + (hair_key_index)], src_co);
return;
}
@@ -324,9 +322,8 @@ static void rna_ParticleHairKey_co_object(HairKey *hairkey,
NULL;
if (particle) {
if (hair_mesh) {
- const MVert *verts = BKE_mesh_verts(hair_mesh);
- const MVert *mv = &verts[particle->hair_index + (hairkey - particle->hair)];
- copy_v3_v3(n_co, mv->co);
+ const float(*positions)[3] = BKE_mesh_positions(hair_mesh);
+ copy_v3_v3(n_co, positions[particle->hair_index + (hairkey - particle->hair)]);
}
else {
float hairmat[4][4];
diff --git a/source/blender/modifiers/intern/MOD_array.c b/source/blender/modifiers/intern/MOD_array.c
index 2d725af7fe4..a09756b03aa 100644
--- a/source/blender/modifiers/intern/MOD_array.c
+++ b/source/blender/modifiers/intern/MOD_array.c
@@ -125,15 +125,15 @@ static int svert_sum_cmp(const void *e1, const void *e2)
}
static void svert_from_mvert(SortVertsElem *sv,
- const MVert *mv,
+ const float (*positions)[3],
const int i_begin,
const int i_end)
{
int i;
- for (i = i_begin; i < i_end; i++, sv++, mv++) {
+ for (i = i_begin; i < i_end; i++, sv++) {
sv->vertex_num = i;
- copy_v3_v3(sv->co, mv->co);
- sv->sum_co = sum_v3(mv->co);
+ copy_v3_v3(sv->co, positions[i]);
+ sv->sum_co = sum_v3(positions[i]);
}
}
@@ -145,7 +145,7 @@ static void svert_from_mvert(SortVertsElem *sv,
* The `int doubles_map[verts_source_num]` array must have been allocated by caller.
*/
static void dm_mvert_map_doubles(int *doubles_map,
- const MVert *mverts,
+ const float (*positions)[3],
const int target_start,
const int target_verts_num,
const int source_start,
@@ -166,10 +166,10 @@ static void dm_mvert_map_doubles(int *doubles_map,
sorted_verts_source = MEM_malloc_arrayN(source_verts_num, sizeof(SortVertsElem), __func__);
/* Copy target vertices index and cos into SortVertsElem array */
- svert_from_mvert(sorted_verts_target, mverts + target_start, target_start, target_end);
+ svert_from_mvert(sorted_verts_target, positions, target_start, target_end);
/* Copy source vertices index and cos into SortVertsElem array */
- svert_from_mvert(sorted_verts_source, mverts + source_start, source_start, source_end);
+ svert_from_mvert(sorted_verts_source, positions, source_start, source_end);
/* sort arrays according to sum of vertex coordinates (sumco) */
qsort(sorted_verts_target, target_verts_num, sizeof(SortVertsElem), svert_sum_cmp);
@@ -237,8 +237,8 @@ static void dm_mvert_map_doubles(int *doubles_map,
* then there will be no mapping at all for this source. */
while (best_target_vertex != -1 &&
!ELEM(doubles_map[best_target_vertex], -1, best_target_vertex)) {
- if (compare_len_v3v3(mverts[sve_source->vertex_num].co,
- mverts[doubles_map[best_target_vertex]].co,
+ if (compare_len_v3v3(positions[sve_source->vertex_num],
+ positions[doubles_map[best_target_vertex]],
dist)) {
best_target_vertex = doubles_map[best_target_vertex];
}
@@ -275,11 +275,10 @@ static void mesh_merge_transform(Mesh *result,
{
int *index_orig;
int i;
- MVert *mv;
MEdge *me;
MLoop *ml;
MPoly *mp;
- MVert *result_verts = BKE_mesh_verts_for_write(result);
+ float(*result_positions)[3] = BKE_mesh_positions_for_write(result);
MEdge *result_edges = BKE_mesh_edges_for_write(result);
MPoly *result_polys = BKE_mesh_polys_for_write(result);
MLoop *result_loops = BKE_mesh_loops_for_write(result);
@@ -289,10 +288,8 @@ static void mesh_merge_transform(Mesh *result,
CustomData_copy_data(&cap_mesh->ldata, &result->ldata, 0, cap_loops_index, cap_nloops);
CustomData_copy_data(&cap_mesh->pdata, &result->pdata, 0, cap_polys_index, cap_npolys);
- mv = result_verts + cap_verts_index;
-
- for (i = 0; i < cap_nverts; i++, mv++) {
- mul_m4_v3(cap_offset, mv->co);
+ for (i = 0; i < cap_nverts; i++) {
+ mul_m4_v3(cap_offset, result_positions[cap_verts_index + i]);
}
/* We have to correct normals too, if we do not tag them as dirty later! */
@@ -428,7 +425,6 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
/* Build up offset array, accumulating all settings options. */
unit_m4(offset);
- const MVert *src_verts = BKE_mesh_verts(mesh);
const MEdge *src_edges = BKE_mesh_edges(mesh);
const MPoly *src_polys = BKE_mesh_polys(mesh);
const MLoop *src_loops = BKE_mesh_loops(mesh);
@@ -439,12 +435,8 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
if (amd->offset_type & MOD_ARR_OFF_RELATIVE) {
float min[3], max[3];
- const MVert *src_mv;
-
INIT_MINMAX(min, max);
- for (src_mv = src_verts, j = chunk_nverts; j--; src_mv++) {
- minmax_v3v3_v3(min, max, src_mv->co);
- }
+ BKE_mesh_minmax(mesh, min, max);
for (j = 3; j--;) {
offset[3][j] += amd->scale[j] * (max[j] - min[j]);
@@ -541,7 +533,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
/* Initialize a result dm */
result = BKE_mesh_new_nomain_from_template(
mesh, result_nverts, result_nedges, 0, result_nloops, result_npolys);
- MVert *result_verts = BKE_mesh_verts_for_write(result);
+ float(*result_positions)[3] = BKE_mesh_positions_for_write(result);
MEdge *result_edges = BKE_mesh_edges_for_write(result);
MPoly *result_polys = BKE_mesh_polys_for_write(result);
MLoop *result_loops = BKE_mesh_loops_for_write(result);
@@ -559,10 +551,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
CustomData_copy_data(&mesh->pdata, &result->pdata, 0, 0, chunk_npolys);
/* Subdivision-surface for eg won't have mesh data in the custom-data arrays.
- * Now add #MVert/#MEdge/#MPoly layers. */
- if (!CustomData_has_layer(&mesh->vdata, CD_MVERT)) {
- memcpy(result_verts, src_verts, sizeof(MVert) * mesh->totvert);
- }
+ * Now add #position/#MEdge/#MPoly layers. */
if (!CustomData_has_layer(&mesh->edata, CD_MEDGE)) {
memcpy(result_edges, src_edges, sizeof(MEdge) * mesh->totedge);
}
@@ -599,7 +588,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
/* apply offset to all new verts */
for (i = 0; i < chunk_nverts; i++) {
const int i_dst = vert_offset + i;
- mul_m4_v3(current_offset, result_verts[i_dst].co);
+ mul_m4_v3(current_offset, result_positions[i_dst]);
/* We have to correct normals too, if we do not tag them as dirty! */
if (!use_recalc_normals) {
@@ -643,8 +632,8 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
while (target != -1 && !ELEM(full_doubles_map[target], -1, target)) {
/* If target is already mapped, we only follow that mapping if final target remains
* close enough from current vert (otherwise no mapping at all). */
- if (compare_len_v3v3(result_verts[this_chunk_index].co,
- result_verts[full_doubles_map[target]].co,
+ if (compare_len_v3v3(result_positions[this_chunk_index],
+ result_positions[full_doubles_map[target]],
amd->merge_dist)) {
target = full_doubles_map[target];
}
@@ -658,7 +647,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
}
else {
dm_mvert_map_doubles(full_doubles_map,
- result_verts,
+ result_positions,
(c - 1) * chunk_nverts,
chunk_nverts,
c * chunk_nverts,
@@ -696,7 +685,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
if (use_merge && (amd->flags & MOD_ARR_MERGEFINAL) && (count > 1)) {
/* Merge first and last copies */
dm_mvert_map_doubles(full_doubles_map,
- result_verts,
+ result_positions,
last_chunk_start,
last_chunk_nverts,
first_chunk_start,
@@ -726,7 +715,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
/* Identify doubles with first chunk */
if (use_merge) {
dm_mvert_map_doubles(full_doubles_map,
- result_verts,
+ result_positions,
first_chunk_start,
first_chunk_nverts,
start_cap_start,
@@ -756,7 +745,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
/* Identify doubles with last chunk */
if (use_merge) {
dm_mvert_map_doubles(full_doubles_map,
- result_verts,
+ result_positions,
last_chunk_start,
last_chunk_nverts,
end_cap_start,
diff --git a/source/blender/modifiers/intern/MOD_boolean.cc b/source/blender/modifiers/intern/MOD_boolean.cc
index 21f05158e8b..9924968ea88 100644
--- a/source/blender/modifiers/intern/MOD_boolean.cc
+++ b/source/blender/modifiers/intern/MOD_boolean.cc
@@ -62,6 +62,7 @@
#endif
using blender::Array;
+using blender::float3;
using blender::float4x4;
using blender::IndexRange;
using blender::MutableSpan;
@@ -142,9 +143,9 @@ static Mesh *get_quick_mesh(
invert_m4_m4(imat, ob_self->object_to_world);
mul_m4_m4m4(omat, imat, ob_operand_ob->object_to_world);
- MutableSpan<MVert> verts = result->verts_for_write();
- for (const int i : verts.index_range()) {
- mul_m4_v3(omat, verts[i].co);
+ MutableSpan<float3> positions = result->positions_for_write();
+ for (const int i : positions.index_range()) {
+ mul_m4_v3(omat, positions[i]);
}
BKE_mesh_tag_coords_changed(result);
diff --git a/source/blender/modifiers/intern/MOD_build.c b/source/blender/modifiers/intern/MOD_build.c
index 78724d6a2a1..c6bda4a707b 100644
--- a/source/blender/modifiers/intern/MOD_build.c
+++ b/source/blender/modifiers/intern/MOD_build.c
@@ -75,7 +75,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, struct
const int vert_src_num = mesh->totvert;
const int edge_src_num = mesh->totedge;
const int poly_src_num = mesh->totpoly;
- const MVert *mvert_src = BKE_mesh_verts(mesh);
const MEdge *medge_src = BKE_mesh_edges(mesh);
const MPoly *mpoly_src = BKE_mesh_polys(mesh);
const MLoop *mloop_src = BKE_mesh_loops(mesh);
@@ -202,23 +201,15 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, struct
/* now we know the number of verts, edges and faces, we can create the mesh. */
result = BKE_mesh_new_nomain_from_template(
mesh, BLI_ghash_len(vertHash), BLI_ghash_len(edgeHash), 0, loops_dst_num, faces_dst_num);
- MVert *result_verts = BKE_mesh_verts_for_write(result);
MEdge *result_edges = BKE_mesh_edges_for_write(result);
MPoly *result_polys = BKE_mesh_polys_for_write(result);
MLoop *result_loops = BKE_mesh_loops_for_write(result);
/* copy the vertices across */
GHASH_ITER (gh_iter, vertHash) {
- MVert source;
- MVert *dest;
int oldIndex = POINTER_AS_INT(BLI_ghashIterator_getKey(&gh_iter));
int newIndex = POINTER_AS_INT(BLI_ghashIterator_getValue(&gh_iter));
-
- source = mvert_src[oldIndex];
- dest = &result_verts[newIndex];
-
CustomData_copy_data(&mesh->vdata, &result->vdata, oldIndex, newIndex, 1);
- *dest = source;
}
/* copy the edges across, remapping indices */
diff --git a/source/blender/modifiers/intern/MOD_collision.c b/source/blender/modifiers/intern/MOD_collision.c
index 82faf08b349..c98c5ce6c65 100644
--- a/source/blender/modifiers/intern/MOD_collision.c
+++ b/source/blender/modifiers/intern/MOD_collision.c
@@ -93,7 +93,6 @@ static void deformVerts(ModifierData *md,
{
CollisionModifierData *collmd = (CollisionModifierData *)md;
Mesh *mesh_src;
- MVert *tempVert = NULL;
Object *ob = ctx->object;
/* If collision is disabled, free the stale data and exit. */
@@ -145,11 +144,11 @@ static void deformVerts(ModifierData *md,
if (collmd->time_xnew == -1000) { /* first time */
- collmd->x = MEM_dupallocN(BKE_mesh_verts(mesh_src)); /* frame start position */
+ collmd->x = MEM_dupallocN(BKE_mesh_positions(mesh_src)); /* frame start position */
for (uint i = 0; i < mvert_num; i++) {
/* we save global positions */
- mul_m4_v3(ob->object_to_world, collmd->x[i].co);
+ mul_m4_v3(ob->object_to_world, collmd->x[i]);
}
collmd->xnew = MEM_dupallocN(collmd->x); /* Frame end position. */
@@ -177,25 +176,25 @@ static void deformVerts(ModifierData *md,
}
else if (mvert_num == collmd->mvert_num) {
/* put positions to old positions */
- tempVert = collmd->x;
+ float(*temp)[3] = collmd->x;
collmd->x = collmd->xnew;
- collmd->xnew = tempVert;
+ collmd->xnew = temp;
collmd->time_x = collmd->time_xnew;
- memcpy(collmd->xnew, BKE_mesh_verts(mesh_src), mvert_num * sizeof(MVert));
+ memcpy(collmd->xnew, BKE_mesh_positions(mesh_src), mvert_num * sizeof(float[3]));
bool is_static = true;
for (uint i = 0; i < mvert_num; i++) {
/* we save global positions */
- mul_m4_v3(ob->object_to_world, collmd->xnew[i].co);
+ mul_m4_v3(ob->object_to_world, collmd->xnew[i]);
/* detect motion */
- is_static = is_static && equals_v3v3(collmd->x[i].co, collmd->xnew[i].co);
+ is_static = is_static && equals_v3v3(collmd->x[i], collmd->xnew[i]);
}
- memcpy(collmd->current_xnew, collmd->x, mvert_num * sizeof(MVert));
- memcpy(collmd->current_x, collmd->x, mvert_num * sizeof(MVert));
+ memcpy(collmd->current_xnew, collmd->x, mvert_num * sizeof(float[3]));
+ memcpy(collmd->current_x, collmd->x, mvert_num * sizeof(float[3]));
/* check if GUI setting has changed for bvh */
if (collmd->bvhtree) {
@@ -265,9 +264,9 @@ static void blendRead(BlendDataReader *UNUSED(reader), ModifierData *md)
collmd->xnew = newdataadr(fd, collmd->xnew);
collmd->mfaces = newdataadr(fd, collmd->mfaces);
- collmd->current_x = MEM_calloc_arrayN(collmd->mvert_num, sizeof(MVert), "current_x");
- collmd->current_xnew = MEM_calloc_arrayN(collmd->mvert_num, sizeof(MVert), "current_xnew");
- collmd->current_v = MEM_calloc_arrayN(collmd->mvert_num, sizeof(MVert), "current_v");
+ collmd->current_x = MEM_calloc_arrayN(collmd->mvert_num, sizeof(float[3]), "current_x");
+ collmd->current_xnew = MEM_calloc_arrayN(collmd->mvert_num, sizeof(float[3]), "current_xnew");
+ collmd->current_v = MEM_calloc_arrayN(collmd->mvert_num, sizeof(float[3]), "current_v");
#endif
collmd->x = NULL;
diff --git a/source/blender/modifiers/intern/MOD_datatransfer.cc b/source/blender/modifiers/intern/MOD_datatransfer.cc
index 25e8eb8fa20..494ea23d7e2 100644
--- a/source/blender/modifiers/intern/MOD_datatransfer.cc
+++ b/source/blender/modifiers/intern/MOD_datatransfer.cc
@@ -175,12 +175,12 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
BLI_SPACE_TRANSFORM_SETUP(space_transform, ctx->object, ob_source);
}
- const MVert *me_verts = BKE_mesh_verts(me);
+ const float(*me_positions)[3] = BKE_mesh_positions(me);
const MEdge *me_edges = BKE_mesh_edges(me);
- const MVert *result_verts = BKE_mesh_verts(result);
+ const float(*result_positions)[3] = BKE_mesh_positions(result);
const MEdge *result_edges = BKE_mesh_edges(result);
- if (((result == me) || (me_verts == result_verts) || (me_edges == result_edges)) &&
+ if (((result == me) || (me_positions == result_positions) || (me_edges == result_edges)) &&
(dtmd->data_types & DT_TYPES_AFFECT_MESH)) {
/* We need to duplicate data here, otherwise setting custom normals, edges' sharpness, etc.,
* could modify org mesh, see T43671. */
diff --git a/source/blender/modifiers/intern/MOD_displace.c b/source/blender/modifiers/intern/MOD_displace.c
index fc12a9c2aad..6436bf29bdc 100644
--- a/source/blender/modifiers/intern/MOD_displace.c
+++ b/source/blender/modifiers/intern/MOD_displace.c
@@ -157,7 +157,6 @@ typedef struct DisplaceUserdata {
float (*tex_co)[3];
float (*vertexCos)[3];
float local_mat[4][4];
- MVert *mvert;
const float (*vert_normals)[3];
float (*vert_clnors)[3];
} DisplaceUserdata;
@@ -267,7 +266,6 @@ static void displaceModifier_do(DisplaceModifierData *dmd,
const int verts_num)
{
Object *ob = ctx->object;
- MVert *mvert;
const MDeformVert *dvert;
int direction = dmd->direction;
int defgrp_index;
@@ -284,7 +282,6 @@ static void displaceModifier_do(DisplaceModifierData *dmd,
return;
}
- mvert = BKE_mesh_verts_for_write(mesh);
MOD_get_vgroup(ob, mesh, dmd->defgrp_name, &dvert, &defgrp_index);
if (defgrp_index >= 0 && dvert == NULL) {
@@ -337,7 +334,6 @@ static void displaceModifier_do(DisplaceModifierData *dmd,
data.tex_co = tex_co;
data.vertexCos = vertexCos;
copy_m4_m4(data.local_mat, local_mat);
- data.mvert = mvert;
if (direction == MOD_DISP_DIR_NOR) {
data.vert_normals = BKE_mesh_vertex_normals_ensure(mesh);
}
diff --git a/source/blender/modifiers/intern/MOD_explode.c b/source/blender/modifiers/intern/MOD_explode.c
index b0806fed91c..7d2bf5f65bb 100644
--- a/source/blender/modifiers/intern/MOD_explode.c
+++ b/source/blender/modifiers/intern/MOD_explode.c
@@ -91,7 +91,6 @@ static void createFacepa(ExplodeModifierData *emd, ParticleSystemModifierData *p
{
ParticleSystem *psys = psmd->psys;
MFace *fa = NULL, *mface = NULL;
- MVert *mvert = NULL;
ParticleData *pa;
KDTree_3d *tree;
RNG *rng;
@@ -100,7 +99,7 @@ static void createFacepa(ExplodeModifierData *emd, ParticleSystemModifierData *p
int i, p, v1, v2, v3, v4 = 0;
const bool invert_vgroup = (emd->flag & eExplodeFlag_INVERT_VGROUP) != 0;
- mvert = BKE_mesh_verts_for_write(mesh);
+ float(*positions)[3] = BKE_mesh_positions_for_write(mesh);
mface = (MFace *)CustomData_get_layer(&mesh->fdata, CD_MFACE);
totvert = mesh->totvert;
totface = mesh->totface;
@@ -160,10 +159,10 @@ static void createFacepa(ExplodeModifierData *emd, ParticleSystemModifierData *p
/* set face-particle-indexes to nearest particle to face center */
for (i = 0, fa = mface; i < totface; i++, fa++) {
- add_v3_v3v3(center, mvert[fa->v1].co, mvert[fa->v2].co);
- add_v3_v3(center, mvert[fa->v3].co);
+ add_v3_v3v3(center, positions[fa->v1], positions[fa->v2]);
+ add_v3_v3(center, positions[fa->v3]);
if (fa->v4) {
- add_v3_v3(center, mvert[fa->v4].co);
+ add_v3_v3(center, positions[fa->v4]);
mul_v3_fl(center, 0.25);
}
else {
@@ -641,7 +640,7 @@ static Mesh *cutEdges(ExplodeModifierData *emd, Mesh *mesh)
Mesh *split_m;
MFace *mf = NULL, *df1 = NULL;
MFace *mface = CustomData_get_layer(&mesh->fdata, CD_MFACE);
- MVert *dupve, *mv;
+ float *dupve;
EdgeHash *edgehash;
EdgeHashIterator *ehi;
int totvert = mesh->totvert;
@@ -730,18 +729,11 @@ static Mesh *cutEdges(ExplodeModifierData *emd, Mesh *mesh)
layers_num = CustomData_number_of_layers(&split_m->fdata, CD_MTFACE);
- const MVert *mesh_verts = BKE_mesh_verts(mesh);
- MVert *split_m_verts = BKE_mesh_verts_for_write(split_m);
+ float(*split_m_positions)[3] = BKE_mesh_positions_for_write(split_m);
/* copy new faces & verts (is it really this painful with custom data??) */
for (i = 0; i < totvert; i++) {
- MVert source;
- MVert *dest;
- source = mesh_verts[i];
- dest = &split_m_verts[i];
-
CustomData_copy_data(&mesh->vdata, &split_m->vdata, i, i, 1);
- *dest = source;
}
/* override original facepa (original pointer is saved in caller function) */
@@ -759,16 +751,13 @@ static Mesh *cutEdges(ExplodeModifierData *emd, Mesh *mesh)
for (; !BLI_edgehashIterator_isDone(ehi); BLI_edgehashIterator_step(ehi)) {
BLI_edgehashIterator_getKey(ehi, &ed_v1, &ed_v2);
esplit = POINTER_AS_INT(BLI_edgehashIterator_getValue(ehi));
- mv = &split_m_verts[ed_v2];
- dupve = &split_m_verts[esplit];
CustomData_copy_data(&split_m->vdata, &split_m->vdata, ed_v2, esplit, 1);
- *dupve = *mv;
-
- mv = &split_m_verts[ed_v1];
+ dupve = split_m_positions[esplit];
+ copy_v3_v3(dupve, split_m_positions[ed_v2]);
- mid_v3_v3v3(dupve->co, dupve->co, mv->co);
+ mid_v3_v3v3(dupve, dupve, split_m_positions[ed_v1]);
}
BLI_edgehashIterator_free(ehi);
@@ -989,26 +978,23 @@ static Mesh *explodeMesh(ExplodeModifierData *emd,
psys_sim_data_init(&sim);
- const MVert *mesh_verts = BKE_mesh_verts(mesh);
- MVert *explode_verts = BKE_mesh_verts_for_write(explode);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
+ float(*explode_positions)[3] = BKE_mesh_positions_for_write(explode);
/* duplicate & displace vertices */
ehi = BLI_edgehashIterator_new(vertpahash);
for (; !BLI_edgehashIterator_isDone(ehi); BLI_edgehashIterator_step(ehi)) {
- MVert source;
- MVert *dest;
/* get particle + vertex from hash */
BLI_edgehashIterator_getKey(ehi, &ed_v1, &ed_v2);
ed_v2 -= totvert;
v = POINTER_AS_INT(BLI_edgehashIterator_getValue(ehi));
- source = mesh_verts[ed_v1];
- dest = &explode_verts[v];
+ copy_v3_v3(explode_positions[v], positions[ed_v1]);
CustomData_copy_data(&mesh->vdata, &explode->vdata, ed_v1, v, 1);
- *dest = source;
+ copy_v3_v3(explode_positions[v], positions[ed_v1]);
if (ed_v2 != totpart) {
/* get particle */
@@ -1019,7 +1005,7 @@ static Mesh *explodeMesh(ExplodeModifierData *emd,
state.time = ctime;
psys_get_particle_state(&sim, ed_v2, &state, 1);
- vertco = explode_verts[v].co;
+ vertco = explode_positions[v];
mul_m4_v3(ctx->object->object_to_world, vertco);
sub_v3_v3(vertco, birth.co);
diff --git a/source/blender/modifiers/intern/MOD_mask.cc b/source/blender/modifiers/intern/MOD_mask.cc
index 659a1625079..3ae300d22cf 100644
--- a/source/blender/modifiers/intern/MOD_mask.cc
+++ b/source/blender/modifiers/intern/MOD_mask.cc
@@ -49,6 +49,7 @@
#include "BLI_vector.hh"
using blender::Array;
+using blender::float3;
using blender::IndexRange;
using blender::ListBaseWrapper;
using blender::MutableSpan;
@@ -336,19 +337,12 @@ static void copy_masked_verts_to_new_mesh(const Mesh &src_mesh,
Span<int> vertex_map)
{
BLI_assert(src_mesh.totvert == vertex_map.size());
- const Span<MVert> src_verts = src_mesh.verts();
- MutableSpan<MVert> dst_verts = dst_mesh.verts_for_write();
-
for (const int i_src : vertex_map.index_range()) {
const int i_dst = vertex_map[i_src];
if (i_dst == -1) {
continue;
}
- const MVert &v_src = src_verts[i_src];
- MVert &v_dst = dst_verts[i_dst];
-
- v_dst = v_src;
CustomData_copy_data(&src_mesh.vdata, &dst_mesh.vdata, i_src, i_dst, 1);
}
}
@@ -374,11 +368,10 @@ static void add_interp_verts_copy_edges_to_new_mesh(const Mesh &src_mesh,
uint verts_add_num,
MutableSpan<int> r_edge_map)
{
+ using namespace blender;
BLI_assert(src_mesh.totvert == vertex_mask.size());
BLI_assert(src_mesh.totedge == r_edge_map.size());
- const Span<MVert> src_verts = src_mesh.verts();
const Span<MEdge> src_edges = src_mesh.edges();
- MutableSpan<MVert> dst_verts = dst_mesh.verts_for_write();
MutableSpan<MEdge> dst_edges = dst_mesh.edges_for_write();
uint vert_index = dst_mesh.totvert - verts_add_num;
@@ -418,11 +411,6 @@ static void add_interp_verts_copy_edges_to_new_mesh(const Mesh &src_mesh,
float weights[2] = {1.0f - fac, fac};
CustomData_interp(
&src_mesh.vdata, &dst_mesh.vdata, (int *)&e_src.v1, weights, nullptr, 2, vert_index);
- MVert &v = dst_verts[vert_index];
- const MVert &v1 = src_verts[e_src.v1];
- const MVert &v2 = src_verts[e_src.v2];
-
- interp_v3_v3v3(v.co, v1.co, v2.co, fac);
vert_index++;
}
}
diff --git a/source/blender/modifiers/intern/MOD_meshcache.c b/source/blender/modifiers/intern/MOD_meshcache.c
index 822da40edb7..43757c0e95d 100644
--- a/source/blender/modifiers/intern/MOD_meshcache.c
+++ b/source/blender/modifiers/intern/MOD_meshcache.c
@@ -176,17 +176,8 @@ static void meshcache_do(MeshCacheModifierData *mcmd,
BKE_modifier_set_error(ob, &mcmd->modifier, "'Integrate' requires faces");
}
else {
- /* the moons align! */
- int i;
-
- float(*vertexCos_Source)[3] = MEM_malloc_arrayN(
- verts_num, sizeof(*vertexCos_Source), __func__);
float(*vertexCos_New)[3] = MEM_malloc_arrayN(verts_num, sizeof(*vertexCos_New), __func__);
- const MVert *mv = BKE_mesh_verts(me);
-
- for (i = 0; i < verts_num; i++, mv++) {
- copy_v3_v3(vertexCos_Source[i], mv->co);
- }
+ const float(*positions)[3] = BKE_mesh_positions(me);
BKE_mesh_calc_relative_deform(
BKE_mesh_polys(me),
@@ -194,8 +185,8 @@ static void meshcache_do(MeshCacheModifierData *mcmd,
BKE_mesh_loops(me),
me->totvert,
- (const float(*)[3])vertexCos_Source, /* From the original Mesh. */
- (const float(*)[3])vertexCos_Real, /* the input we've been given (shape keys!) */
+ (const float(*)[3])positions, /* From the original Mesh. */
+ (const float(*)[3])vertexCos_Real, /* the input we've been given (shape keys!) */
(const float(*)[3])vertexCos, /* The result of this modifier. */
vertexCos_New /* The result of this function. */
@@ -204,7 +195,6 @@ static void meshcache_do(MeshCacheModifierData *mcmd,
/* write the corrected locations back into the result */
memcpy(vertexCos, vertexCos_New, sizeof(*vertexCos) * verts_num);
- MEM_freeN(vertexCos_Source);
MEM_freeN(vertexCos_New);
}
}
diff --git a/source/blender/modifiers/intern/MOD_meshsequencecache.cc b/source/blender/modifiers/intern/MOD_meshsequencecache.cc
index 13931179b35..6da6dd46507 100644
--- a/source/blender/modifiers/intern/MOD_meshsequencecache.cc
+++ b/source/blender/modifiers/intern/MOD_meshsequencecache.cc
@@ -60,6 +60,7 @@
# include "usd.h"
#endif
+using blender::float3;
using blender::Span;
static void initData(ModifierData *md)
@@ -176,17 +177,17 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
}
if (me != nullptr) {
- const Span<MVert> mesh_verts = mesh->verts();
+ const Span<float3> mesh_positions = mesh->positions();
const Span<MEdge> mesh_edges = mesh->edges();
const Span<MPoly> mesh_polys = mesh->polys();
- const Span<MVert> me_verts = me->verts();
+ const Span<float3> me_positions = me->positions();
const Span<MEdge> me_edges = me->edges();
const Span<MPoly> me_polys = me->polys();
/* TODO(sybren+bastien): possibly check relevant custom data layers (UV/color depending on
* flags) and duplicate those too.
* XXX(Hans): This probably isn't true anymore with various CoW improvements, etc. */
- if ((me_verts.data() == mesh_verts.data()) || (me_edges.data() == mesh_edges.data()) ||
+ if ((me_positions.data() == mesh_positions.data()) || (me_edges.data() == mesh_edges.data()) ||
(me_polys.data() == mesh_polys.data())) {
/* We need to duplicate data here, otherwise we'll modify org mesh, see T51701. */
mesh = reinterpret_cast<Mesh *>(
diff --git a/source/blender/modifiers/intern/MOD_multires.cc b/source/blender/modifiers/intern/MOD_multires.cc
index 2bc3763c46b..8c594b061fa 100644
--- a/source/blender/modifiers/intern/MOD_multires.cc
+++ b/source/blender/modifiers/intern/MOD_multires.cc
@@ -219,7 +219,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
mesh->flag & ME_AUTOSMOOTH &&
CustomData_has_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL);
/* NOTE: Orco needs final coordinates on CPU side, which are expected to be
- * accessible via MVert. For this reason we do not evaluate multires to
+ * accessible via mesh vertices. For this reason we do not evaluate multires to
* grids when orco is requested. */
const bool for_orco = (ctx->flag & MOD_APPLY_ORCO) != 0;
/* Needed when rendering or baking will in sculpt mode. */
@@ -244,7 +244,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
sculpt_session->multires.level = mmd->sculptlvl;
sculpt_session->totvert = mesh->totvert;
sculpt_session->totpoly = mesh->totpoly;
- sculpt_session->mvert = nullptr;
+ sculpt_session->positions = nullptr;
sculpt_session->mpoly = nullptr;
sculpt_session->mloop = nullptr;
}
diff --git a/source/blender/modifiers/intern/MOD_normal_edit.cc b/source/blender/modifiers/intern/MOD_normal_edit.cc
index 7d422826cf8..9a1a10f086c 100644
--- a/source/blender/modifiers/intern/MOD_normal_edit.cc
+++ b/source/blender/modifiers/intern/MOD_normal_edit.cc
@@ -47,16 +47,17 @@ static void generate_vert_coordinates(Mesh *mesh,
float (*r_cos)[3],
float r_size[3])
{
+ using namespace blender;
float min_co[3], max_co[3];
float diff[3];
bool do_diff = false;
INIT_MINMAX(min_co, max_co);
- const MVert *mv = BKE_mesh_verts(mesh);
- for (int i = 0; i < mesh->totvert; i++, mv++) {
- copy_v3_v3(r_cos[i], mv->co);
- if (r_size != nullptr && ob_center == nullptr) {
+ const Span<float3> positions = mesh->positions();
+ for (int i = 0; i < mesh->totvert; i++) {
+ copy_v3_v3(r_cos[i], positions[i]);
+ if (r_size != NULL && ob_center == NULL) {
minmax_v3v3_v3(min_co, max_co, r_cos[i]);
}
}
@@ -221,7 +222,7 @@ static void normalEditModifier_do_radial(NormalEditModifierData *enmd,
const MDeformVert *dvert,
const int defgrp_index,
const bool use_invert_vgroup,
- const MVert *mvert,
+ const float (*positions)[3],
const int verts_num,
MEdge *medge,
const int edges_num,
@@ -329,7 +330,7 @@ static void normalEditModifier_do_radial(NormalEditModifierData *enmd,
BKE_mesh_normals_tag_dirty(mesh);
}
- BKE_mesh_normals_loop_custom_set(mvert,
+ BKE_mesh_normals_loop_custom_set(positions,
BKE_mesh_vertex_normals_ensure(mesh),
verts_num,
medge,
@@ -360,7 +361,7 @@ static void normalEditModifier_do_directional(NormalEditModifierData *enmd,
const MDeformVert *dvert,
const int defgrp_index,
const bool use_invert_vgroup,
- const MVert *mvert,
+ const float (*positions)[3],
const int verts_num,
MEdge *medge,
const int edges_num,
@@ -445,7 +446,7 @@ static void normalEditModifier_do_directional(NormalEditModifierData *enmd,
BKE_mesh_normals_tag_dirty(mesh);
}
- BKE_mesh_normals_loop_custom_set(mvert,
+ BKE_mesh_normals_loop_custom_set(positions,
BKE_mesh_vertex_normals_ensure(mesh),
verts_num,
medge,
@@ -527,7 +528,7 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd,
const int edges_num = result->totedge;
const int loops_num = result->totloop;
const int polys_num = result->totpoly;
- const MVert *verts = BKE_mesh_verts(result);
+ const float(*positions)[3] = BKE_mesh_positions(result);
MEdge *edges = BKE_mesh_edges_for_write(result);
const MPoly *polys = BKE_mesh_polys(result);
MLoop *loops = BKE_mesh_loops_for_write(result);
@@ -549,7 +550,7 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd,
loopnors = static_cast<float(*)[3]>(
MEM_malloc_arrayN(size_t(loops_num), sizeof(*loopnors), __func__));
- BKE_mesh_normals_loop_split(verts,
+ BKE_mesh_normals_loop_split(positions,
vert_normals,
verts_num,
edges,
@@ -588,7 +589,7 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd,
dvert,
defgrp_index,
use_invert_vgroup,
- verts,
+ positions,
verts_num,
edges,
edges_num,
@@ -611,7 +612,7 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd,
dvert,
defgrp_index,
use_invert_vgroup,
- verts,
+ positions,
verts_num,
edges,
edges_num,
diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c
index bee1bd7795a..c4531f13fe3 100644
--- a/source/blender/modifiers/intern/MOD_ocean.c
+++ b/source/blender/modifiers/intern/MOD_ocean.c
@@ -154,7 +154,7 @@ static bool dependsOnNormals(ModifierData *md)
#ifdef WITH_OCEANSIM
typedef struct GenerateOceanGeometryData {
- MVert *mverts;
+ float (*positions)[3];
MPoly *mpolys;
MLoop *mloops;
MLoopUV *mloopuvs;
@@ -175,7 +175,7 @@ static void generate_ocean_geometry_verts(void *__restrict userdata,
for (x = 0; x <= gogd->res_x; x++) {
const int i = y * (gogd->res_x + 1) + x;
- float *co = gogd->mverts[i].co;
+ float *co = gogd->positions[i];
co[0] = gogd->ox + (x * gogd->sx);
co[1] = gogd->oy + (y * gogd->sy);
co[2] = 0.0f;
@@ -270,7 +270,7 @@ static Mesh *generate_ocean_geometry(OceanModifierData *omd, Mesh *mesh_orig, co
result = BKE_mesh_new_nomain(verts_num, 0, 0, polys_num * 4, polys_num);
BKE_mesh_copy_parameters_for_eval(result, mesh_orig);
- gogd.mverts = BKE_mesh_verts_for_write(result);
+ gogd.positions = BKE_mesh_positions_for_write(result);
gogd.mpolys = BKE_mesh_polys_for_write(result);
gogd.mloops = BKE_mesh_loops_for_write(result);
@@ -363,15 +363,15 @@ static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mes
CLAMP(cfra_for_cache, omd->bakestart, omd->bakeend);
cfra_for_cache -= omd->bakestart; /* shift to 0 based */
- MVert *verts = BKE_mesh_verts_for_write(result);
- MPoly *polys = BKE_mesh_polys_for_write(result);
+ float(*positions)[3] = BKE_mesh_positions_for_write(result);
+ const MPoly *polys = BKE_mesh_polys(result);
/* add vcols before displacement - allows lookup based on position */
if (omd->flag & MOD_OCEAN_GENERATE_FOAM) {
const int polys_num = result->totpoly;
const int loops_num = result->totloop;
- MLoop *mloops = BKE_mesh_loops_for_write(result);
+ const MLoop *mloops = BKE_mesh_loops(result);
MLoopCol *mloopcols = CustomData_add_layer_named(
&result->ldata, CD_PROP_BYTE_COLOR, CD_SET_DEFAULT, NULL, loops_num, omd->foamlayername);
@@ -386,10 +386,10 @@ static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mes
}
if (mloopcols) { /* unlikely to fail */
- MPoly *mp;
+ const MPoly *mp;
for (i = 0, mp = polys; i < polys_num; i++, mp++) {
- MLoop *ml = &mloops[mp->loopstart];
+ const MLoop *ml = &mloops[mp->loopstart];
MLoopCol *mlcol = &mloopcols[mp->loopstart];
MLoopCol *mlcolspray = NULL;
@@ -398,7 +398,7 @@ static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mes
}
for (j = mp->totloop; j--; ml++, mlcol++) {
- const float *vco = verts[ml->v].co;
+ const float *vco = positions[ml->v];
const float u = OCEAN_CO(size_co_inv, vco[0]);
const float v = OCEAN_CO(size_co_inv, vco[1]);
float foam;
@@ -446,7 +446,7 @@ static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mes
const int verts_num = result->totvert;
for (i = 0; i < verts_num; i++) {
- float *vco = verts[i].co;
+ float *vco = positions[i];
const float u = OCEAN_CO(size_co_inv, vco[0]);
const float v = OCEAN_CO(size_co_inv, vco[1]);
diff --git a/source/blender/modifiers/intern/MOD_particleinstance.c b/source/blender/modifiers/intern/MOD_particleinstance.c
index 46e14dd6bfb..349c850b145 100644
--- a/source/blender/modifiers/intern/MOD_particleinstance.c
+++ b/source/blender/modifiers/intern/MOD_particleinstance.c
@@ -315,10 +315,9 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
result = BKE_mesh_new_nomain_from_template(mesh, maxvert, maxedge, 0, maxloop, maxpoly);
- const MVert *orig_mvert = BKE_mesh_verts(mesh);
const MPoly *orig_mpoly = BKE_mesh_polys(mesh);
const MLoop *orig_mloop = BKE_mesh_loops(mesh);
- MVert *mvert = BKE_mesh_verts_for_write(result);
+ float(*positions)[3] = BKE_mesh_positions_for_write(result);
MEdge *edges = BKE_mesh_edges_for_write(result);
MPoly *mpoly = BKE_mesh_polys_for_write(result);
MLoop *mloop = BKE_mesh_loops_for_write(result);
@@ -349,13 +348,9 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
/* set vertices coordinates */
for (k = 0; k < totvert; k++) {
ParticleKey state;
- const MVert *inMV;
int vindex = p_skip * totvert + k;
- MVert *mv = mvert + vindex;
- inMV = orig_mvert + k;
- CustomData_copy_data(&mesh->vdata, &result->vdata, k, p_skip * totvert + k, 1);
- *mv = *inMV;
+ CustomData_copy_data(&mesh->vdata, &result->vdata, k, vindex, 1);
if (vert_part_index != NULL) {
vert_part_index[vindex] = p;
@@ -365,10 +360,10 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
}
/* Change orientation based on object trackflag. */
- copy_v3_v3(temp_co, mv->co);
- mv->co[axis] = temp_co[track];
- mv->co[(axis + 1) % 3] = temp_co[(track + 1) % 3];
- mv->co[(axis + 2) % 3] = temp_co[(track + 2) % 3];
+ copy_v3_v3(temp_co, positions[vindex]);
+ positions[vindex][axis] = temp_co[track];
+ positions[vindex][(axis + 1) % 3] = temp_co[(track + 1) % 3];
+ positions[vindex][(axis + 2) % 3] = temp_co[(track + 2) % 3];
/* get particle state */
if ((psys->flag & (PSYS_HAIR_DONE | PSYS_KEYED) || psys->pointcache->flag & PTCACHE_BAKED) &&
@@ -382,13 +377,14 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
state.time = pimd->position * (1.0f - ran);
}
else {
- state.time = (mv->co[axis] - min_co) / (max_co - min_co) * pimd->position * (1.0f - ran);
+ state.time = (positions[vindex][axis] - min_co) / (max_co - min_co) * pimd->position *
+ (1.0f - ran);
if (trackneg) {
state.time = 1.0f - state.time;
}
- mv->co[axis] = 0.0;
+ positions[vindex][axis] = 0.0;
}
psys_get_particle_on_path(&sim, p, &state, 1);
@@ -462,13 +458,13 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
psys_get_particle_state(&sim, p, &state, 1);
}
- mul_qt_v3(state.rot, mv->co);
+ mul_qt_v3(state.rot, positions[vindex]);
if (pimd->flag & eParticleInstanceFlag_UseSize) {
- mul_v3_fl(mv->co, size[p]);
+ mul_v3_fl(positions[vindex], size[p]);
}
- add_v3_v3(mv->co, state.co);
+ add_v3_v3(positions[vindex], state.co);
- mul_m4_v3(spacemat, mv->co);
+ mul_m4_v3(spacemat, positions[vindex]);
}
/* Create edges and adjust edge vertex indices. */
diff --git a/source/blender/modifiers/intern/MOD_remesh.c b/source/blender/modifiers/intern/MOD_remesh.c
index d6241fcb290..20da79897c9 100644
--- a/source/blender/modifiers/intern/MOD_remesh.c
+++ b/source/blender/modifiers/intern/MOD_remesh.c
@@ -60,8 +60,8 @@ static void init_dualcon_mesh(DualConInput *input, Mesh *mesh)
{
memset(input, 0, sizeof(DualConInput));
- input->co = (void *)BKE_mesh_verts(mesh);
- input->co_stride = sizeof(MVert);
+ input->co = (void *)BKE_mesh_positions(mesh);
+ input->co_stride = sizeof(float[3]);
input->totco = mesh->totvert;
input->mloop = (void *)BKE_mesh_loops(mesh);
@@ -79,7 +79,7 @@ static void init_dualcon_mesh(DualConInput *input, Mesh *mesh)
* keep track of the current elements */
typedef struct {
Mesh *mesh;
- MVert *verts;
+ float (*positions)[3];
MPoly *polys;
MLoop *loops;
int curvert, curface;
@@ -95,7 +95,7 @@ static void *dualcon_alloc_output(int totvert, int totquad)
}
output->mesh = BKE_mesh_new_nomain(totvert, 0, 0, 4 * totquad, totquad);
- output->verts = BKE_mesh_verts_for_write(output->mesh);
+ output->positions = BKE_mesh_positions_for_write(output->mesh);
output->polys = BKE_mesh_polys_for_write(output->mesh);
output->loops = BKE_mesh_loops_for_write(output->mesh);
@@ -108,7 +108,7 @@ static void dualcon_add_vert(void *output_v, const float co[3])
BLI_assert(output->curvert < output->mesh->totvert);
- copy_v3_v3(output->verts[output->curvert].co, co);
+ copy_v3_v3(output->positions[output->curvert], co);
output->curvert++;
}
diff --git a/source/blender/modifiers/intern/MOD_screw.c b/source/blender/modifiers/intern/MOD_screw.c
index 4ba274dbd8a..14cf79bb06e 100644
--- a/source/blender/modifiers/intern/MOD_screw.c
+++ b/source/blender/modifiers/intern/MOD_screw.c
@@ -116,7 +116,7 @@ static void screwvert_iter_step(ScrewVertIter *iter)
}
static Mesh *mesh_remove_doubles_on_axis(Mesh *result,
- MVert *mvert_new,
+ float (*positions_new)[3],
const uint totvert,
const uint step_tot,
const float axis_vec[3],
@@ -132,18 +132,18 @@ static Mesh *mesh_remove_doubles_on_axis(Mesh *result,
float axis_co[3];
if (use_offset) {
float offset_co[3];
- sub_v3_v3v3(offset_co, mvert_new[i].co, axis_offset);
+ sub_v3_v3v3(offset_co, positions_new[i], axis_offset);
project_v3_v3v3_normalized(axis_co, offset_co, axis_vec);
add_v3_v3(axis_co, axis_offset);
}
else {
- project_v3_v3v3_normalized(axis_co, mvert_new[i].co, axis_vec);
+ project_v3_v3v3_normalized(axis_co, positions_new[i], axis_vec);
}
- const float dist_sq = len_squared_v3v3(axis_co, mvert_new[i].co);
+ const float dist_sq = len_squared_v3v3(axis_co, positions_new[i]);
if (dist_sq <= merge_threshold_sq) {
BLI_BITMAP_ENABLE(vert_tag, i);
tot_doubles += 1;
- copy_v3_v3(mvert_new[i].co, axis_co);
+ copy_v3_v3(positions_new[i], axis_co);
}
}
@@ -242,8 +242,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
MPoly *mp_new;
MLoop *ml_new;
MEdge *med_new, *med_new_firstloop;
- MVert *mv_new, *mv_new_base;
- const MVert *mv_orig;
Object *ob_axis = ltmd->ob_axis;
ScrewVertConnect *vc, *vc_tmp, *vert_connect = NULL;
@@ -383,12 +381,12 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
result = BKE_mesh_new_nomain_from_template(
mesh, (int)maxVerts, (int)maxEdges, 0, (int)maxPolys * 4, (int)maxPolys);
- const MVert *mvert_orig = BKE_mesh_verts(mesh);
+ const float(*positions_orig)[3] = BKE_mesh_positions(mesh);
const MEdge *medge_orig = BKE_mesh_edges(mesh);
const MPoly *mpoly_orig = BKE_mesh_polys(mesh);
const MLoop *mloop_orig = BKE_mesh_loops(mesh);
- MVert *mvert_new = BKE_mesh_verts_for_write(result);
+ float(*positions_new)[3] = BKE_mesh_positions_for_write(result);
MEdge *medge_new = BKE_mesh_edges_for_write(result);
MPoly *mpoly_new = BKE_mesh_polys_for_write(result);
MLoop *mloop_new = BKE_mesh_loops_for_write(result);
@@ -413,8 +411,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
}
if (ltmd->flag & MOD_SCREW_UV_STRETCH_V) {
- for (i = 0, mv_orig = mvert_orig; i < totvert; i++, mv_orig++) {
- const float v = dist_signed_squared_to_plane_v3(mv_orig->co, uv_axis_plane);
+ for (i = 0; i < totvert; i++) {
+ const float v = dist_signed_squared_to_plane_v3(positions_orig[i], uv_axis_plane);
uv_v_minmax[0] = min_ff(v, uv_v_minmax[0]);
uv_v_minmax[1] = max_ff(v, uv_v_minmax[1]);
}
@@ -428,9 +426,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
/* Set the locations of the first set of verts */
- mv_new = mvert_new;
- mv_orig = mvert_orig;
-
BLI_bitmap *vert_tag = BLI_BITMAP_NEW(totvert, __func__);
/* Copy the first set of edges */
@@ -441,7 +436,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
med_new->v2 = med_orig->v2;
med_new->flag = med_orig->flag & ~ME_LOOSEEDGE;
- /* Tag #MVert as not loose. */
+ /* Tag vertex as not loose. */
BLI_BITMAP_ENABLE(vert_tag, med_orig->v1);
BLI_BITMAP_ENABLE(vert_tag, med_orig->v2);
}
@@ -506,14 +501,13 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
// printf("\n\n\n\n\nStarting Modifier\n");
/* set edge users */
med_new = medge_new;
- mv_new = mvert_new;
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];
- vc->co[1] = mv_new->co[1] = mv_orig->co[1];
- vc->co[2] = mv_new->co[2] = mv_orig->co[2];
+ for (i = 0; i < totvert; i++, vc++) {
+ vc->co[0] = positions_new[i][0] = positions_orig[i][0];
+ vc->co[1] = positions_new[i][1] = positions_orig[i][1];
+ vc->co[2] = positions_new[i][2] = positions_orig[i][2];
vc->flag = 0;
vc->e[0] = vc->e[1] = NULL;
@@ -528,10 +522,10 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
}
}
else {
- for (i = 0; i < totvert; i++, mv_new++, mv_orig++, vc++) {
- vc->co[0] = mv_new->co[0] = mv_orig->co[0];
- vc->co[1] = mv_new->co[1] = mv_orig->co[1];
- vc->co[2] = mv_new->co[2] = mv_orig->co[2];
+ for (i = 0; i < totvert; i++, vc++) {
+ vc->co[0] = positions_new[i][0] = positions_orig[i][0];
+ vc->co[1] = positions_new[i][1] = positions_orig[i][1];
+ vc->co[2] = positions_new[i][2] = positions_orig[i][2];
vc->flag = 0;
vc->e[0] = vc->e[1] = NULL;
@@ -758,11 +752,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
}
}
else {
- mv_orig = mvert_orig;
- mv_new = mvert_new;
-
- for (i = 0; i < totvert; i++, mv_new++, mv_orig++) {
- copy_v3_v3(mv_new->co, mv_orig->co);
+ for (i = 0; i < totvert; i++) {
+ copy_v3_v3(positions_new[i], positions_orig[i]);
}
}
/* done with edge connectivity based normal flipping */
@@ -790,25 +781,24 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
/* copy a slice */
CustomData_copy_data(&mesh->vdata, &result->vdata, 0, (int)varray_stride, (int)totvert);
- mv_new_base = mvert_new;
- mv_new = &mvert_new[varray_stride]; /* advance to the next slice */
+ for (j = 0; j < totvert; j++) {
+ const int vert_index_new = (int)varray_stride + (int)j;
- for (j = 0; j < totvert; j++, mv_new_base++, mv_new++) {
/* set location */
- copy_v3_v3(mv_new->co, mv_new_base->co);
+ copy_v3_v3(positions_new[vert_index_new], positions_new[j]);
/* only need to set these if using non cleared memory */
// mv_new->mat_nr = mv_new->flag = 0;
if (ob_axis != NULL) {
- sub_v3_v3(mv_new->co, mtx_tx[3]);
+ sub_v3_v3(positions_new[vert_index_new], mtx_tx[3]);
- mul_m4_v3(mat, mv_new->co);
+ mul_m4_v3(mat, positions_new[vert_index_new]);
- add_v3_v3(mv_new->co, mtx_tx[3]);
+ add_v3_v3(positions_new[vert_index_new], mtx_tx[3]);
}
else {
- mul_m4_v3(mat, mv_new->co);
+ mul_m4_v3(mat, positions_new[vert_index_new]);
}
/* add the new edge */
@@ -879,8 +869,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
}
if (has_mloop_orig == false && mloopuv_layers_tot) {
- uv_v_offset_a = dist_signed_to_plane_v3(mvert_new[medge_new[i].v1].co, uv_axis_plane);
- uv_v_offset_b = dist_signed_to_plane_v3(mvert_new[medge_new[i].v2].co, uv_axis_plane);
+ uv_v_offset_a = dist_signed_to_plane_v3(positions_new[medge_new[i].v1], uv_axis_plane);
+ uv_v_offset_b = dist_signed_to_plane_v3(positions_new[medge_new[i].v2], uv_axis_plane);
if (ltmd->flag & MOD_SCREW_UV_STRETCH_V) {
uv_v_offset_a = (uv_v_offset_a - uv_v_minmax[0]) * uv_v_range_inv;
@@ -1037,7 +1027,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
if (do_remove_doubles) {
result = mesh_remove_doubles_on_axis(result,
- mvert_new,
+ positions_new,
totvert,
step_tot,
axis_vec,
diff --git a/source/blender/modifiers/intern/MOD_shrinkwrap.c b/source/blender/modifiers/intern/MOD_shrinkwrap.c
index df8b9d53a2f..b5e66a1af79 100644
--- a/source/blender/modifiers/intern/MOD_shrinkwrap.c
+++ b/source/blender/modifiers/intern/MOD_shrinkwrap.c
@@ -56,12 +56,6 @@ static void requiredDataMask(ModifierData *md, CustomData_MeshMasks *r_cddata_ma
if (smd->vgroup_name[0] != '\0') {
r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
}
-
- if ((smd->shrinkType == MOD_SHRINKWRAP_PROJECT) &&
- (smd->projAxis == MOD_SHRINKWRAP_PROJECT_OVER_NORMAL)) {
- /* XXX Really? These should always be present, always... */
- r_cddata_masks->vmask |= CD_MASK_MVERT;
- }
}
static bool isDisabled(const struct Scene *UNUSED(scene),
diff --git a/source/blender/modifiers/intern/MOD_skin.c b/source/blender/modifiers/intern/MOD_skin.c
index 897a25711cd..992035c5cc1 100644
--- a/source/blender/modifiers/intern/MOD_skin.c
+++ b/source/blender/modifiers/intern/MOD_skin.c
@@ -132,12 +132,12 @@ typedef enum {
} SkinNodeFlag;
typedef struct Frame {
- /* Index in the MVert array */
+ /* Index in the vertex array */
BMVert *verts[4];
/* Location of each corner */
float co[4][3];
/* Indicates which corners have been merged with another
- * frame's corner (so they share an MVert index) */
+ * frame's corner (so they share a vertex index) */
struct {
/* Merge to target frame/corner (no merge if frame is null) */
struct Frame *frame;
@@ -520,7 +520,7 @@ static float half_v2(const float v[2])
static void end_node_frames(int v,
SkinNode *skin_nodes,
- const MVert *mvert,
+ const float (*positions)[3],
const MVertSkin *nodes,
const MeshElemMap *emap,
EMat *emat)
@@ -540,8 +540,8 @@ static void end_node_frames(int v,
mat[0][2] = mat[1][0] = mat[2][1] = 1;
/* Caps */
- create_frame(&skin_nodes[v].frames[0], mvert[v].co, rad, mat, avg);
- create_frame(&skin_nodes[v].frames[1], mvert[v].co, rad, mat, -avg);
+ create_frame(&skin_nodes[v].frames[0], positions[v], rad, mat, avg);
+ create_frame(&skin_nodes[v].frames[1], positions[v], rad, mat, -avg);
}
else {
/* For nodes with an incoming edge, create a single (capped) frame */
@@ -557,7 +557,7 @@ static void end_node_frames(int v,
Frame *frame = &skin_nodes[v].frames[0];
/* End frame */
- create_frame(frame, mvert[v].co, rad, mat, 0);
+ create_frame(frame, positions[v], rad, mat, 0);
/* The caps might need to have their normals inverted. So check if they
* need to be flipped when creating faces. */
@@ -605,7 +605,7 @@ static int connection_node_mat(float mat[3][3], int v, const MeshElemMap *emap,
static void connection_node_frames(int v,
SkinNode *skin_nodes,
- const MVert *mvert,
+ const float (*positions)[3],
const MVertSkin *nodes,
const MeshElemMap *emap,
EMat *emat)
@@ -630,14 +630,14 @@ static void connection_node_frames(int v,
if (e1->origin != v) {
negate_v3(mat[0]);
}
- create_frame(&skin_nodes[v].frames[0], mvert[v].co, rad, mat, avg);
+ create_frame(&skin_nodes[v].frames[0], positions[v], rad, mat, avg);
skin_nodes[v].seam_edges[0] = emap[v].indices[0];
copy_m3_m3(mat, e2->mat);
if (e2->origin != v) {
negate_v3(mat[0]);
}
- create_frame(&skin_nodes[v].frames[1], mvert[v].co, rad, mat, avg);
+ create_frame(&skin_nodes[v].frames[1], positions[v], rad, mat, avg);
skin_nodes[v].seam_edges[1] = emap[v].indices[1];
return;
@@ -645,11 +645,14 @@ static void connection_node_frames(int v,
/* Build regular frame */
node_frames_init(&skin_nodes[v], 1);
- create_frame(&skin_nodes[v].frames[0], mvert[v].co, rad, mat, 0);
+ create_frame(&skin_nodes[v].frames[0], positions[v], rad, mat, 0);
}
-static SkinNode *build_frames(
- const MVert *mvert, int verts_num, const MVertSkin *nodes, const MeshElemMap *emap, EMat *emat)
+static SkinNode *build_frames(const float (*positions)[3],
+ int verts_num,
+ const MVertSkin *nodes,
+ const MeshElemMap *emap,
+ EMat *emat)
{
SkinNode *skin_nodes;
int v;
@@ -658,10 +661,10 @@ static SkinNode *build_frames(
for (v = 0; v < verts_num; v++) {
if (emap[v].count <= 1) {
- end_node_frames(v, skin_nodes, mvert, nodes, emap, emat);
+ end_node_frames(v, skin_nodes, positions, nodes, emap, emat);
}
else if (emap[v].count == 2) {
- connection_node_frames(v, skin_nodes, mvert, nodes, emap, emat);
+ connection_node_frames(v, skin_nodes, positions, nodes, emap, emat);
}
else {
/* Branch node generates no frames */
@@ -714,7 +717,7 @@ static void build_emats_stack(BLI_Stack *stack,
const MeshElemMap *emap,
const MEdge *medge,
const MVertSkin *vs,
- const MVert *mvert)
+ const float (*positions)[3])
{
EdgeStackElem stack_elem;
float axis[3], angle;
@@ -741,11 +744,11 @@ static void build_emats_stack(BLI_Stack *stack,
/* If parent is a branch node, start a new edge chain */
if (parent_is_branch) {
- calc_edge_mat(emat[e].mat, mvert[parent_v].co, mvert[v].co);
+ calc_edge_mat(emat[e].mat, positions[parent_v], positions[v]);
}
else {
/* Build edge matrix guided by parent matrix */
- sub_v3_v3v3(emat[e].mat[0], mvert[v].co, mvert[parent_v].co);
+ sub_v3_v3v3(emat[e].mat[0], positions[v], positions[parent_v]);
normalize_v3(emat[e].mat[0]);
angle = angle_normalized_v3v3(stack_elem.mat[0], emat[e].mat[0]);
cross_v3_v3v3(axis, stack_elem.mat[0], emat[e].mat[0]);
@@ -765,7 +768,7 @@ static void build_emats_stack(BLI_Stack *stack,
}
static EMat *build_edge_mats(const MVertSkin *vs,
- const MVert *mvert,
+ const float (*positions)[3],
const int verts_num,
const MEdge *medge,
const MeshElemMap *emap,
@@ -789,7 +792,7 @@ static EMat *build_edge_mats(const MVertSkin *vs,
if (vs[v].flag & MVERT_SKIN_ROOT) {
if (emap[v].count >= 1) {
const MEdge *e = &medge[emap[v].indices[0]];
- calc_edge_mat(stack_elem.mat, mvert[v].co, mvert[BKE_mesh_edge_other_vert(e, v)].co);
+ calc_edge_mat(stack_elem.mat, positions[v], positions[BKE_mesh_edge_other_vert(e, v)]);
stack_elem.parent_v = v;
/* Add adjacent edges to stack */
@@ -809,7 +812,7 @@ static EMat *build_edge_mats(const MVertSkin *vs,
}
while (!BLI_stack_is_empty(stack)) {
- build_emats_stack(stack, visited_e, emat, emap, medge, vs, mvert);
+ build_emats_stack(stack, visited_e, emat, emap, medge, vs, positions);
}
MEM_freeN(visited_e);
@@ -825,7 +828,7 @@ static EMat *build_edge_mats(const MVertSkin *vs,
* nodes, at least two intermediate frames are required. (This avoids
* having any special cases for dealing with sharing a frame between
* two hulls.) */
-static int calc_edge_subdivisions(const MVert *mvert,
+static int calc_edge_subdivisions(const float (*positions)[3],
const MVertSkin *nodes,
const MEdge *e,
const int *degree)
@@ -855,7 +858,7 @@ static int calc_edge_subdivisions(const MVert *mvert,
if (avg_radius != 0.0f) {
/* possible (but unlikely) that we overflow INT_MAX */
float subdivisions_num_fl;
- const float edge_len = len_v3v3(mvert[e->v1].co, mvert[e->v2].co);
+ const float edge_len = len_v3v3(positions[e->v1], positions[e->v2]);
subdivisions_num_fl = (edge_len / avg_radius);
if (subdivisions_num_fl < NUM_SUBDIVISIONS_MAX) {
subdivisions_num = (int)subdivisions_num_fl;
@@ -889,7 +892,7 @@ static Mesh *subdivide_base(const Mesh *orig)
float radrat;
const MVertSkin *orignode = CustomData_get_layer(&orig->vdata, CD_MVERT_SKIN);
- const MVert *origvert = BKE_mesh_verts(orig);
+ const float(*orig_positions)[3] = BKE_mesh_positions(orig);
const MEdge *origedge = BKE_mesh_edges(orig);
const MDeformVert *origdvert = BKE_mesh_deform_verts(orig);
int orig_vert_num = orig->totvert;
@@ -905,7 +908,7 @@ static Mesh *subdivide_base(const Mesh *orig)
/* Per edge, store how many subdivisions are needed */
int *edge_subd = MEM_calloc_arrayN((uint)orig_edge_num, sizeof(int), "edge_subd");
for (i = 0, subd_num = 0; i < orig_edge_num; i++) {
- edge_subd[i] += calc_edge_subdivisions(origvert, orignode, &origedge[i], degree);
+ edge_subd[i] += calc_edge_subdivisions(orig_positions, orignode, &origedge[i], degree);
BLI_assert(edge_subd[i] >= 0);
subd_num += edge_subd[i];
}
@@ -916,7 +919,7 @@ static Mesh *subdivide_base(const Mesh *orig)
Mesh *result = BKE_mesh_new_nomain_from_template(
orig, orig_vert_num + subd_num, orig_edge_num + subd_num, 0, 0, 0);
- MVert *outvert = BKE_mesh_verts_for_write(result);
+ float(*out_positions)[3] = BKE_mesh_positions_for_write(result);
MEdge *outedge = BKE_mesh_edges_for_write(result);
MVertSkin *outnode = CustomData_get_layer(&result->vdata, CD_MVERT_SKIN);
MDeformVert *outdvert = NULL;
@@ -978,7 +981,7 @@ static Mesh *subdivide_base(const Mesh *orig)
float t = powf(r, radrat);
/* Interpolate vertex coord */
- interp_v3_v3v3(outvert[v].co, outvert[e->v1].co, outvert[e->v2].co, t);
+ interp_v3_v3v3(out_positions[v], out_positions[e->v1], out_positions[e->v2], t);
/* Interpolate skin radii */
interp_v3_v3v3(outnode[v].radius, orignode[e->v1].radius, orignode[e->v2].radius, t);
@@ -1910,7 +1913,6 @@ static Mesh *base_skin(Mesh *origmesh, SkinModifierData *smd, eSkinErrorFlag *r_
SkinNode *skin_nodes;
MeshElemMap *emap;
int *emapmem;
- const MVert *mvert;
const MEdge *medge;
const MDeformVert *dvert;
int verts_num, edges_num;
@@ -1918,7 +1920,7 @@ static Mesh *base_skin(Mesh *origmesh, SkinModifierData *smd, eSkinErrorFlag *r_
nodes = CustomData_get_layer(&origmesh->vdata, CD_MVERT_SKIN);
- mvert = BKE_mesh_verts(origmesh);
+ const float(*positions)[3] = BKE_mesh_positions(origmesh);
dvert = BKE_mesh_deform_verts(origmesh);
medge = BKE_mesh_edges(origmesh);
verts_num = origmesh->totvert;
@@ -1926,8 +1928,8 @@ static Mesh *base_skin(Mesh *origmesh, SkinModifierData *smd, eSkinErrorFlag *r_
BKE_mesh_vert_edge_map_create(&emap, &emapmem, medge, verts_num, edges_num);
- emat = build_edge_mats(nodes, mvert, verts_num, medge, emap, edges_num, &has_valid_root);
- skin_nodes = build_frames(mvert, verts_num, nodes, emap, emat);
+ emat = build_edge_mats(nodes, positions, verts_num, medge, emap, edges_num, &has_valid_root);
+ skin_nodes = build_frames(positions, verts_num, nodes, emap, emat);
MEM_freeN(emat);
emat = NULL;
diff --git a/source/blender/modifiers/intern/MOD_solidify_extrude.c b/source/blender/modifiers/intern/MOD_solidify_extrude.c
index 08e9569bd95..5908a13e93c 100644
--- a/source/blender/modifiers/intern/MOD_solidify_extrude.c
+++ b/source/blender/modifiers/intern/MOD_solidify_extrude.c
@@ -215,7 +215,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
MOD_get_vgroup(ctx->object, mesh, smd->defgrp_name, &dvert, &defgrp_index);
- const MVert *orig_mvert = BKE_mesh_verts(mesh);
+ const float(*orig_positions)[3] = BKE_mesh_positions(mesh);
const MEdge *orig_medge = BKE_mesh_edges(mesh);
const MPoly *orig_mpoly = BKE_mesh_polys(mesh);
const MLoop *orig_mloop = BKE_mesh_loops(mesh);
@@ -335,7 +335,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
(int)((loops_num * stride) + newLoops),
(int)((polys_num * stride) + newPolys));
- MVert *mvert = BKE_mesh_verts_for_write(result);
+ float(*positions)[3] = BKE_mesh_positions_for_write(result);
MEdge *medge = BKE_mesh_edges_for_write(result);
MPoly *mpoly = BKE_mesh_polys_for_write(result);
MLoop *mloop = BKE_mesh_loops_for_write(result);
@@ -398,7 +398,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
if (((ofs_new >= ofs_orig) == do_flip) == test) { \
i_end = verts_num; \
do_shell_align = true; \
- mv = mvert; \
+ vert_index = 0; \
} \
else { \
if (do_shell) { \
@@ -409,7 +409,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
i_end = newVerts; \
do_shell_align = false; \
} \
- mv = &mvert[verts_num]; \
+ vert_index = verts_num; \
} \
(void)0
@@ -495,7 +495,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
vert_lens = MEM_malloc_arrayN(verts_num, sizeof(float), "vert_lens");
copy_vn_fl(vert_lens, (int)verts_num, FLT_MAX);
for (uint i = 0; i < edges_num; i++) {
- const float ed_len_sq = len_squared_v3v3(mvert[medge[i].v1].co, mvert[medge[i].v2].co);
+ const float ed_len_sq = len_squared_v3v3(positions[medge[i].v1], positions[medge[i].v2]);
vert_lens[medge[i].v1] = min_ff(vert_lens[medge[i].v1], ed_len_sq);
vert_lens[medge[i].v2] = min_ff(vert_lens[medge[i].v2], ed_len_sq);
}
@@ -547,7 +547,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
!ELEM(edge_user_pairs[i][1], INVALID_UNUSED, INVALID_PAIR)) {
const float *n0 = poly_nors[edge_user_pairs[i][0]];
const float *n1 = poly_nors[edge_user_pairs[i][1]];
- sub_v3_v3v3(e, orig_mvert[ed->v1].co, orig_mvert[ed->v2].co);
+ sub_v3_v3v3(e, orig_positions[ed->v1], orig_positions[ed->v2]);
normalize_v3(e);
const float angle = angle_signed_on_axis_v3v3_v3(n0, n1, e);
if (do_angle_clamp) {
@@ -571,10 +571,10 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
ofs_new_vgroup = ofs_new;
- MVert *mv;
+ uint vert_index;
INIT_VERT_ARRAY_OFFSETS(false);
- for (i_orig = 0; i_orig < i_end; i_orig++, mv++) {
+ for (i_orig = 0; i_orig < i_end; i_orig++, vert_index++) {
const uint i = do_shell_align ? i_orig : new_vert_arr[i_orig];
if (dvert) {
const MDeformVert *dv = &dvert[i];
@@ -608,10 +608,10 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
}
}
if (vert_nors) {
- madd_v3_v3fl(mv->co, vert_nors[i], ofs_new_vgroup);
+ madd_v3_v3fl(positions[vert_index], vert_nors[i], ofs_new_vgroup);
}
else {
- madd_v3_v3fl(mv->co, mesh_vert_normals[i], ofs_new_vgroup);
+ madd_v3_v3fl(positions[vert_index], mesh_vert_normals[i], ofs_new_vgroup);
}
}
}
@@ -623,10 +623,10 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
ofs_new_vgroup = ofs_orig;
/* as above but swapped */
- MVert *mv;
+ uint vert_index;
INIT_VERT_ARRAY_OFFSETS(true);
- for (i_orig = 0; i_orig < i_end; i_orig++, mv++) {
+ for (i_orig = 0; i_orig < i_end; i_orig++, vert_index++) {
const uint i = do_shell_align ? i_orig : new_vert_arr[i_orig];
if (dvert) {
const MDeformVert *dv = &dvert[i];
@@ -660,10 +660,10 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
}
}
if (vert_nors) {
- madd_v3_v3fl(mv->co, vert_nors[i], ofs_new_vgroup);
+ madd_v3_v3fl(positions[vert_index], vert_nors[i], ofs_new_vgroup);
}
else {
- madd_v3_v3fl(mv->co, mesh_vert_normals[i], ofs_new_vgroup);
+ madd_v3_v3fl(positions[vert_index], mesh_vert_normals[i], ofs_new_vgroup);
}
}
}
@@ -713,8 +713,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
if (vert_nors == NULL) {
vert_nors = MEM_malloc_arrayN(verts_num, sizeof(float[3]), "mod_solid_vno");
- const MVert *mv;
- for (i = 0, mv = mvert; i < verts_num; i++, mv++) {
+ for (i = 0; i < verts_num; i++) {
copy_v3_v3(vert_nors[i], mesh_vert_normals[i]);
}
}
@@ -730,12 +729,12 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
const MLoop *ml = &mloop[mp->loopstart];
- sub_v3_v3v3(nor_prev, mvert[ml[i_curr - 1].v].co, mvert[ml[i_curr].v].co);
+ sub_v3_v3v3(nor_prev, positions[ml[i_curr - 1].v], positions[ml[i_curr].v]);
normalize_v3(nor_prev);
while (i_next < mp->totloop) {
float angle;
- sub_v3_v3v3(nor_next, mvert[ml[i_curr].v].co, mvert[ml[i_next].v].co);
+ sub_v3_v3v3(nor_next, positions[ml[i_curr].v], positions[ml[i_next].v]);
normalize_v3(nor_next);
angle = angle_normalized_v3v3(nor_prev, nor_next);
@@ -847,7 +846,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
vert_angs[ed->v2] = max_ff(vert_angs[ed->v2], angle);
}
if (do_bevel_convex) {
- sub_v3_v3v3(e, orig_mvert[ed->v1].co, orig_mvert[ed->v2].co);
+ sub_v3_v3v3(e, orig_positions[ed->v1], orig_positions[ed->v2]);
normalize_v3(e);
edge_angs[i] = angle_signed_on_axis_v3v3_v3(n0, n1, e);
if (!do_rim) {
@@ -867,7 +866,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
const float offset_sq = offset * offset;
copy_vn_fl(vert_lens_sq, (int)verts_num, FLT_MAX);
for (i = 0; i < edges_num; i++) {
- const float ed_len = len_squared_v3v3(mvert[medge[i].v1].co, mvert[medge[i].v2].co);
+ const float ed_len = len_squared_v3v3(positions[medge[i].v1], positions[medge[i].v2]);
vert_lens_sq[medge[i].v1] = min_ff(vert_lens_sq[medge[i].v1], ed_len);
vert_lens_sq[medge[i].v2] = min_ff(vert_lens_sq[medge[i].v2], ed_len);
}
@@ -926,14 +925,15 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
uint i_orig, i_end;
bool do_shell_align;
- MVert *mv;
+ uint vert_index;
INIT_VERT_ARRAY_OFFSETS(false);
- for (i_orig = 0; i_orig < i_end; i_orig++, mv++) {
+ for (i_orig = 0; i_orig < i_end; i_orig++, vert_index++) {
const uint i_other = do_shell_align ? i_orig : new_vert_arr[i_orig];
if (vert_accum[i_other]) { /* zero if unselected */
- madd_v3_v3fl(
- mv->co, vert_nors[i_other], ofs_new * (vert_angles[i_other] / vert_accum[i_other]));
+ madd_v3_v3fl(positions[vert_index],
+ vert_nors[i_other],
+ ofs_new * (vert_angles[i_other] / vert_accum[i_other]));
}
}
}
@@ -943,14 +943,15 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
bool do_shell_align;
/* same as above but swapped, intentional use of 'ofs_new' */
- MVert *mv;
+ uint vert_index;
INIT_VERT_ARRAY_OFFSETS(true);
- for (i_orig = 0; i_orig < i_end; i_orig++, mv++) {
+ for (i_orig = 0; i_orig < i_end; i_orig++, vert_index++) {
const uint i_other = do_shell_align ? i_orig : new_vert_arr[i_orig];
if (vert_accum[i_other]) { /* zero if unselected */
- madd_v3_v3fl(
- mv->co, vert_nors[i_other], ofs_orig * (vert_angles[i_other] / vert_accum[i_other]));
+ madd_v3_v3fl(positions[vert_index],
+ vert_nors[i_other],
+ ofs_orig * (vert_angles[i_other] / vert_accum[i_other]));
}
}
}
@@ -1157,10 +1158,10 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
#ifdef SOLIDIFY_SIDE_NORMALS
if (do_side_normals) {
normal_quad_v3(nor,
- mvert[ml[j - 4].v].co,
- mvert[ml[j - 3].v].co,
- mvert[ml[j - 2].v].co,
- mvert[ml[j - 1].v].co);
+ positions[ml[j - 4].v],
+ positions[ml[j - 3].v],
+ positions[ml[j - 2].v],
+ positions[ml[j - 1].v]);
add_v3_v3(edge_vert_nos[ed->v1], nor);
add_v3_v3(edge_vert_nos[ed->v2], nor);
diff --git a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
index 9d0b5c30b5e..9c96de884cb 100644
--- a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
+++ b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
@@ -184,7 +184,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
const bool do_flat_faces = dvert && (smd->flag & MOD_SOLIDIFY_NONMANIFOLD_FLAT_FACES);
- const MVert *orig_mvert = BKE_mesh_verts(mesh);
+ const float(*orig_positions)[3] = BKE_mesh_positions(mesh);
const MEdge *orig_medge = BKE_mesh_edges(mesh);
const MPoly *orig_mpoly = BKE_mesh_polys(mesh);
const MLoop *orig_mloop = BKE_mesh_loops(mesh);
@@ -220,7 +220,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
if (len_squared_v3(poly_nors[i]) < 0.5f) {
const MEdge *e = orig_medge + orig_mloop[mp->loopstart].e;
float edgedir[3];
- sub_v3_v3v3(edgedir, orig_mvert[e->v2].co, orig_mvert[e->v1].co);
+ sub_v3_v3v3(edgedir, orig_positions[e->v2], orig_positions[e->v1]);
if (fabsf(edgedir[2]) < fabsf(edgedir[1])) {
poly_nors[i][2] = 1.0f;
}
@@ -293,9 +293,9 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
verts_num, sizeof(*orig_mvert_co), "orig_mvert_co in solidify");
/* Fill in the original vertex positions. */
for (uint i = 0; i < verts_num; i++) {
- orig_mvert_co[i][0] = orig_mvert[i].co[0];
- orig_mvert_co[i][1] = orig_mvert[i].co[1];
- orig_mvert_co[i][2] = orig_mvert[i].co[2];
+ orig_mvert_co[i][0] = orig_positions[i][0];
+ orig_mvert_co[i][1] = orig_positions[i][1];
+ orig_mvert_co[i][2] = orig_positions[i][2];
}
/* Create edge to #NewEdgeRef map. */
@@ -1398,9 +1398,8 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
}
}
- const MVert *mv = orig_mvert;
gs_ptr = orig_vert_groups_arr;
- for (uint i = 0; i < verts_num; i++, mv++, gs_ptr++) {
+ for (uint i = 0; i < verts_num; i++, gs_ptr++) {
if (*gs_ptr) {
EdgeGroup *g = *gs_ptr;
for (uint j = 0; g->valid; j++, g++) {
@@ -1962,7 +1961,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
(int)(new_loops_num),
(int)(new_polys_num));
- MVert *mvert = BKE_mesh_verts_for_write(result);
+ float(*positions)[3] = BKE_mesh_positions_for_write(result);
MEdge *medge = BKE_mesh_edges_for_write(result);
MPoly *mpoly = BKE_mesh_polys_for_write(result);
MLoop *mloop = BKE_mesh_loops_for_write(result);
@@ -2005,7 +2004,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
for (uint j = 0; g->valid; j++, g++) {
if (g->new_vert != MOD_SOLIDIFY_EMPTY_TAG) {
CustomData_copy_data(&mesh->vdata, &result->vdata, (int)i, (int)g->new_vert, 1);
- copy_v3_v3(mvert[g->new_vert].co, g->co);
+ copy_v3_v3(positions[g->new_vert], g->co);
}
}
}
@@ -2115,8 +2114,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
/* Make boundary edges/faces. */
{
gs_ptr = orig_vert_groups_arr;
- const MVert *mv = orig_mvert;
- for (uint i = 0; i < verts_num; i++, gs_ptr++, mv++) {
+ for (uint i = 0; i < verts_num; i++, gs_ptr++) {
EdgeGroup *gs = *gs_ptr;
if (gs) {
EdgeGroup *g = gs;
diff --git a/source/blender/modifiers/intern/MOD_surface.c b/source/blender/modifiers/intern/MOD_surface.c
index a34d66f394b..98f2715d5e4 100644
--- a/source/blender/modifiers/intern/MOD_surface.c
+++ b/source/blender/modifiers/intern/MOD_surface.c
@@ -125,7 +125,6 @@ static void deformVerts(ModifierData *md,
if (surmd->mesh) {
uint mesh_verts_num = 0, i = 0;
int init = 0;
- MVert *x, *v;
BKE_mesh_vert_coords_apply(surmd->mesh, vertexCos);
@@ -142,8 +141,8 @@ static void deformVerts(ModifierData *md,
surmd->v = NULL;
}
- surmd->x = MEM_calloc_arrayN(mesh_verts_num, sizeof(MVert), "MVert");
- surmd->v = MEM_calloc_arrayN(mesh_verts_num, sizeof(MVert), "MVert");
+ surmd->x = MEM_calloc_arrayN(mesh_verts_num, sizeof(float[3]), __func__);
+ surmd->v = MEM_calloc_arrayN(mesh_verts_num, sizeof(float[3]), __func__);
surmd->verts_num = mesh_verts_num;
@@ -151,19 +150,19 @@ static void deformVerts(ModifierData *md,
}
/* convert to global coordinates and calculate velocity */
- MVert *verts = BKE_mesh_verts_for_write(surmd->mesh);
- for (i = 0, x = surmd->x, v = surmd->v; i < mesh_verts_num; i++, x++, v++) {
- float *vec = verts[i].co;
+ float(*positions)[3] = BKE_mesh_positions_for_write(surmd->mesh);
+ for (i = 0; i < mesh_verts_num; i++) {
+ float *vec = positions[i];
mul_m4_v3(ctx->object->object_to_world, vec);
if (init) {
- v->co[0] = v->co[1] = v->co[2] = 0.0f;
+ surmd->v[i][0] = surmd->v[i][1] = surmd->v[i][2] = 0.0f;
}
else {
- sub_v3_v3v3(v->co, vec, x->co);
+ sub_v3_v3v3(surmd->v[i], vec, surmd->x[i]);
}
- copy_v3_v3(x->co, vec);
+ copy_v3_v3(surmd->x[i], vec);
}
surmd->cfra = cfra;
diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.c b/source/blender/modifiers/intern/MOD_surfacedeform.c
index 6a9321a78a2..7dd84375519 100644
--- a/source/blender/modifiers/intern/MOD_surfacedeform.c
+++ b/source/blender/modifiers/intern/MOD_surfacedeform.c
@@ -1169,7 +1169,7 @@ static bool surfacedeformBind(Object *ob,
Mesh *mesh)
{
BVHTreeFromMesh treeData = {NULL};
- const MVert *mvert = BKE_mesh_verts(target);
+ const float(*positions)[3] = BKE_mesh_positions(target);
const MPoly *mpoly = BKE_mesh_polys(target);
const MEdge *medge = BKE_mesh_edges(target);
const MLoop *mloop = BKE_mesh_loops(target);
@@ -1268,7 +1268,7 @@ static bool surfacedeformBind(Object *ob,
invert_m4_m4(data.imat, smd_orig->mat);
for (int i = 0; i < target_verts_num; i++) {
- mul_v3_m4v3(data.targetCos[i], smd_orig->mat, mvert[i].co);
+ mul_v3_m4v3(data.targetCos[i], smd_orig->mat, positions[i]);
}
TaskParallelSettings settings;
diff --git a/source/blender/modifiers/intern/MOD_util.cc b/source/blender/modifiers/intern/MOD_util.cc
index a94fc6732a0..b72bd32b54e 100644
--- a/source/blender/modifiers/intern/MOD_util.cc
+++ b/source/blender/modifiers/intern/MOD_util.cc
@@ -131,17 +131,17 @@ void MOD_get_texture_coords(MappingInfoModifierData *dmd,
texmapping = MOD_DISP_MAP_LOCAL;
}
- const MVert *mv = BKE_mesh_verts(mesh);
- for (i = 0; i < verts_num; i++, mv++, r_texco++) {
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
+ for (i = 0; i < verts_num; i++, r_texco++) {
switch (texmapping) {
case MOD_DISP_MAP_LOCAL:
- copy_v3_v3(*r_texco, cos != nullptr ? *cos : mv->co);
+ copy_v3_v3(*r_texco, cos != nullptr ? *cos : positions[i]);
break;
case MOD_DISP_MAP_GLOBAL:
- mul_v3_m4v3(*r_texco, ob->object_to_world, cos != nullptr ? *cos : mv->co);
+ mul_v3_m4v3(*r_texco, ob->object_to_world, cos != nullptr ? *cos : positions[i]);
break;
case MOD_DISP_MAP_OBJECT:
- mul_v3_m4v3(*r_texco, ob->object_to_world, cos != nullptr ? *cos : mv->co);
+ mul_v3_m4v3(*r_texco, ob->object_to_world, cos != nullptr ? *cos : positions[i]);
mul_m4_v3(mapref_imat, *r_texco);
break;
}
diff --git a/source/blender/modifiers/intern/MOD_weighted_normal.cc b/source/blender/modifiers/intern/MOD_weighted_normal.cc
index 1ebd5423d39..d9beb83b327 100644
--- a/source/blender/modifiers/intern/MOD_weighted_normal.cc
+++ b/source/blender/modifiers/intern/MOD_weighted_normal.cc
@@ -71,7 +71,7 @@ struct WeightedNormalData {
int loops_num;
int polys_num;
- const MVert *mvert;
+ const float (*positions)[3];
const float (*vert_normals)[3];
MEdge *medge;
@@ -186,7 +186,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
const int loops_num = wn_data->loops_num;
const int polys_num = wn_data->polys_num;
- const MVert *mvert = wn_data->mvert;
+ const float(*positions)[3] = wn_data->positions;
MEdge *medge = wn_data->medge;
const MLoop *mloop = wn_data->mloop;
@@ -222,7 +222,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
* we do not actually care about computed loop_normals for now... */
loop_normals = static_cast<float(*)[3]>(
MEM_calloc_arrayN(size_t(loops_num), sizeof(*loop_normals), __func__));
- BKE_mesh_normals_loop_split(mvert,
+ BKE_mesh_normals_loop_split(positions,
wn_data->vert_normals,
verts_num,
medge,
@@ -356,7 +356,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
}
}
- BKE_mesh_normals_loop_custom_set(mvert,
+ BKE_mesh_normals_loop_custom_set(positions,
wn_data->vert_normals,
verts_num,
medge,
@@ -387,7 +387,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
copy_v3_v3(vert_normals[mv_index], items_data[mv_index].normal);
}
- BKE_mesh_normals_loop_custom_from_verts_set(mvert,
+ BKE_mesh_normals_loop_custom_from_verts_set(positions,
wn_data->vert_normals,
vert_normals,
verts_num,
@@ -406,7 +406,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
loop_normals = static_cast<float(*)[3]>(
MEM_calloc_arrayN(size_t(loops_num), sizeof(*loop_normals), __func__));
- BKE_mesh_normals_loop_split(mvert,
+ BKE_mesh_normals_loop_split(positions,
wn_data->vert_normals,
verts_num,
medge,
@@ -430,7 +430,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
}
}
- BKE_mesh_normals_loop_custom_set(mvert,
+ BKE_mesh_normals_loop_custom_set(positions,
wn_data->vert_normals,
verts_num,
medge,
@@ -455,7 +455,7 @@ static void wn_face_area(WeightedNormalModifierData *wnmd, WeightedNormalData *w
{
const int polys_num = wn_data->polys_num;
- const MVert *mvert = wn_data->mvert;
+ const float(*positions)[3] = wn_data->positions;
const MLoop *mloop = wn_data->mloop;
const MPoly *mpoly = wn_data->mpoly;
@@ -467,7 +467,7 @@ static void wn_face_area(WeightedNormalModifierData *wnmd, WeightedNormalData *w
ModePair *f_area = face_area;
for (mp_index = 0, mp = mpoly; mp_index < polys_num; mp_index++, mp++, f_area++) {
- f_area->val = BKE_mesh_calc_poly_area(mp, &mloop[mp->loopstart], mvert);
+ f_area->val = BKE_mesh_calc_poly_area(mp, &mloop[mp->loopstart], positions);
f_area->index = mp_index;
}
@@ -482,7 +482,7 @@ static void wn_corner_angle(WeightedNormalModifierData *wnmd, WeightedNormalData
const int loops_num = wn_data->loops_num;
const int polys_num = wn_data->polys_num;
- const MVert *mvert = wn_data->mvert;
+ const float(*positions)[3] = wn_data->positions;
const MLoop *mloop = wn_data->mloop;
const MPoly *mpoly = wn_data->mpoly;
@@ -500,7 +500,7 @@ static void wn_corner_angle(WeightedNormalModifierData *wnmd, WeightedNormalData
float *index_angle = static_cast<float *>(
MEM_malloc_arrayN(size_t(mp->totloop), sizeof(*index_angle), __func__));
- BKE_mesh_calc_poly_angles(mp, ml_start, mvert, index_angle);
+ BKE_mesh_calc_poly_angles(mp, ml_start, positions, index_angle);
ModePair *c_angl = &corner_angle[mp->loopstart];
float *angl = index_angle;
@@ -526,7 +526,7 @@ static void wn_face_with_angle(WeightedNormalModifierData *wnmd, WeightedNormalD
const int loops_num = wn_data->loops_num;
const int polys_num = wn_data->polys_num;
- const MVert *mvert = wn_data->mvert;
+ const float(*positions)[3] = wn_data->positions;
const MLoop *mloop = wn_data->mloop;
const MPoly *mpoly = wn_data->mpoly;
@@ -542,10 +542,10 @@ static void wn_face_with_angle(WeightedNormalModifierData *wnmd, WeightedNormalD
for (mp_index = 0, mp = mpoly; mp_index < polys_num; mp_index++, mp++) {
const MLoop *ml_start = &mloop[mp->loopstart];
- float face_area = BKE_mesh_calc_poly_area(mp, ml_start, mvert);
+ float face_area = BKE_mesh_calc_poly_area(mp, ml_start, positions);
float *index_angle = static_cast<float *>(
MEM_malloc_arrayN(size_t(mp->totloop), sizeof(*index_angle), __func__));
- BKE_mesh_calc_poly_angles(mp, ml_start, mvert, index_angle);
+ BKE_mesh_calc_poly_angles(mp, ml_start, positions, index_angle);
ModePair *cmbnd = &combined[mp->loopstart];
float *angl = index_angle;
@@ -595,7 +595,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
const int edges_num = result->totedge;
const int loops_num = result->totloop;
const int polys_num = result->totpoly;
- const MVert *mvert = BKE_mesh_verts(result);
+ const float(*positions)[3] = BKE_mesh_positions(result);
MEdge *medge = BKE_mesh_edges_for_write(result);
const MPoly *mpoly = BKE_mesh_polys(result);
const MLoop *mloop = BKE_mesh_loops(result);
@@ -639,7 +639,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
wn_data.loops_num = loops_num;
wn_data.polys_num = polys_num;
- wn_data.mvert = mvert;
+ wn_data.positions = positions;
wn_data.vert_normals = BKE_mesh_vertex_normals_ensure(result);
wn_data.medge = medge;
diff --git a/source/blender/modifiers/intern/MOD_weightvg_util.c b/source/blender/modifiers/intern/MOD_weightvg_util.c
index 3302384568b..b15b9cf75f1 100644
--- a/source/blender/modifiers/intern/MOD_weightvg_util.c
+++ b/source/blender/modifiers/intern/MOD_weightvg_util.c
@@ -140,7 +140,7 @@ void weightvg_do_mask(const ModifierEvalContext *ctx,
/* Use new generic get_texture_coords, but do not modify our DNA struct for it...
* XXX Why use a ModifierData stuff here ? Why not a simple, generic struct for parameters?
* What e.g. if a modifier wants to use several textures?
- * Why use only v_co, and not MVert (or both)?
+ * Why use only v_co, and not mesh positions (or both)?
*/
t_map.texture = texture;
t_map.map_object = tex_map_object;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_convex_hull.cc b/source/blender/nodes/geometry/nodes/node_geo_convex_hull.cc
index 278d7c4bd24..2e0556024ea 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_convex_hull.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_convex_hull.cc
@@ -46,11 +46,10 @@ static Mesh *hull_from_bullet(const Mesh *mesh, Span<float3> coords)
}
/* Copy vertices. */
- MutableSpan<MVert> dst_verts = result->verts_for_write();
+ MutableSpan<float3> dst_positions = result->positions_for_write();
for (const int i : IndexRange(verts_num)) {
- float co[3];
int original_index;
- plConvexHullGetVertex(hull, i, co, &original_index);
+ plConvexHullGetVertex(hull, i, dst_positions[i], &original_index);
if (original_index >= 0 && original_index < coords.size()) {
# if 0 /* Disabled because it only works for meshes, not predictable enough. */
@@ -59,8 +58,6 @@ static Mesh *hull_from_bullet(const Mesh *mesh, Span<float3> coords)
CustomData_copy_data(&mesh->vdata, &result->vdata, int(original_index), int(i), 1);
}
# endif
- /* Copy the position of the original point. */
- copy_v3_v3(dst_verts[i].co, co);
}
else {
BLI_assert_msg(0, "Unexpected new vertex in hull output");
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc
index a14661b4a50..9a45466be19 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc
@@ -79,13 +79,13 @@ static Mesh *cdt_to_mesh(const meshintersect::CDT_result<double> &result)
}
Mesh *mesh = BKE_mesh_new_nomain(vert_len, edge_len, 0, loop_len, poly_len);
- MutableSpan<MVert> verts = mesh->verts_for_write();
+ MutableSpan<float3> positions = mesh->positions_for_write();
MutableSpan<MEdge> edges = mesh->edges_for_write();
MutableSpan<MPoly> polys = mesh->polys_for_write();
MutableSpan<MLoop> loops = mesh->loops_for_write();
for (const int i : IndexRange(result.vert.size())) {
- copy_v3_v3(verts[i].co, float3(float(result.vert[i].x), float(result.vert[i].y), 0.0f));
+ positions[i] = float3(float(result.vert[i].x), float(result.vert[i].y), 0.0f);
}
for (const int i : IndexRange(result.edge.size())) {
edges[i].v1 = result.edge[i].first;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc b/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc
index dabd2a1a9f2..7a63aa59509 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc
@@ -66,10 +66,10 @@ static void deform_curves(const CurvesGeometry &curves,
const float4x4 curves_to_surface = surface_to_curves.inverted();
- const Span<MVert> surface_verts_old = surface_mesh_old.verts();
+ const Span<float3> surface_positions_old = surface_mesh_old.positions();
const Span<MLoop> surface_loops_old = surface_mesh_old.loops();
- const Span<MVert> surface_verts_new = surface_mesh_new.verts();
+ const Span<float3> surface_positions_new = surface_mesh_new.positions();
const Span<MLoop> surface_loops_new = surface_mesh_new.loops();
threading::parallel_for(curves.curves_range(), 256, [&](const IndexRange range) {
@@ -118,14 +118,14 @@ static void deform_curves(const CurvesGeometry &curves,
const float3 normal_new = math::normalize(
mix3(bary_weights_new, normal_0_new, normal_1_new, normal_2_new));
- const float3 &pos_0_old = surface_verts_old[vert_0_old].co;
- const float3 &pos_1_old = surface_verts_old[vert_1_old].co;
- const float3 &pos_2_old = surface_verts_old[vert_2_old].co;
+ const float3 &pos_0_old = surface_positions_old[vert_0_old];
+ const float3 &pos_1_old = surface_positions_old[vert_1_old];
+ const float3 &pos_2_old = surface_positions_old[vert_2_old];
const float3 pos_old = mix3(bary_weights_old, pos_0_old, pos_1_old, pos_2_old);
- const float3 &pos_0_new = surface_verts_new[vert_0_new].co;
- const float3 &pos_1_new = surface_verts_new[vert_1_new].co;
- const float3 &pos_2_new = surface_verts_new[vert_2_new].co;
+ const float3 &pos_0_new = surface_positions_new[vert_0_new];
+ const float3 &pos_1_new = surface_positions_new[vert_1_new];
+ const float3 &pos_2_new = surface_positions_new[vert_2_new];
const float3 pos_new = mix3(bary_weights_new, pos_0_new, pos_1_new, pos_2_new);
/* The translation is just the difference between the old and new position on the surface. */
diff --git a/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc b/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc
index 8ed97f2019f..bccf0cd46ce 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc
@@ -153,23 +153,6 @@ static void copy_face_corner_attributes(const Map<AttributeIDRef, AttributeKind>
attributes, src_attributes, dst_attributes, ATTR_DOMAIN_CORNER, IndexMask(indices));
}
-static void copy_masked_verts_to_new_mesh(const Mesh &src_mesh,
- Mesh &dst_mesh,
- Span<int> vertex_map)
-{
- BLI_assert(src_mesh.totvert == vertex_map.size());
- const Span<MVert> src_verts = src_mesh.verts();
- MutableSpan<MVert> dst_verts = dst_mesh.verts_for_write();
-
- for (const int i_src : vertex_map.index_range()) {
- const int i_dst = vertex_map[i_src];
- if (i_dst == -1) {
- continue;
- }
- dst_verts[i_dst] = src_verts[i_src];
- }
-}
-
static void copy_masked_edges_to_new_mesh(const Mesh &src_mesh, Mesh &dst_mesh, Span<int> edge_map)
{
BLI_assert(src_mesh.totedge == edge_map.size());
@@ -891,7 +874,6 @@ static void do_mesh_separation(GeometrySet &geometry_set,
selected_polys_num);
/* Copy the selected parts of the mesh over to the new mesh. */
- copy_masked_verts_to_new_mesh(mesh_in, *mesh_out, vertex_map);
copy_masked_edges_to_new_mesh(mesh_in, *mesh_out, vertex_map, edge_map);
copy_masked_polys_to_new_mesh(
mesh_in, *mesh_out, vertex_map, edge_map, selected_poly_indices, new_loop_starts);
@@ -968,7 +950,7 @@ static void do_mesh_separation(GeometrySet &geometry_set,
selected_polys_num);
/* Copy the selected parts of the mesh over to the new mesh. */
- mesh_out->verts_for_write().copy_from(mesh_in.verts());
+ mesh_out->positions_for_write().copy_from(mesh_in.positions());
copy_masked_edges_to_new_mesh(mesh_in, *mesh_out, edge_map);
copy_masked_polys_to_new_mesh(
mesh_in, *mesh_out, edge_map, selected_poly_indices, new_loop_starts);
@@ -1029,7 +1011,7 @@ static void do_mesh_separation(GeometrySet &geometry_set,
&mesh_in, mesh_in.totvert, mesh_in.totedge, 0, selected_loops_num, selected_polys_num);
/* Copy the selected parts of the mesh over to the new mesh. */
- mesh_out->verts_for_write().copy_from(mesh_in.verts());
+ mesh_out->positions_for_write().copy_from(mesh_in.positions());
mesh_out->edges_for_write().copy_from(mesh_in.edges());
copy_masked_polys_to_new_mesh(mesh_in, *mesh_out, selected_poly_indices, new_loop_starts);
diff --git a/source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc b/source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc
index 7c9501608a3..8d23be28928 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc
@@ -105,7 +105,7 @@ static void sample_mesh_surface(const Mesh &mesh,
Vector<float3> &r_bary_coords,
Vector<int> &r_looptri_indices)
{
- const Span<MVert> verts = mesh.verts();
+ const Span<float3> positions = mesh.positions();
const Span<MLoop> loops = mesh.loops();
const Span<MLoopTri> looptris = mesh.looptris();
@@ -117,9 +117,9 @@ static void sample_mesh_surface(const Mesh &mesh,
const int v0_index = loops[v0_loop].v;
const int v1_index = loops[v1_loop].v;
const int v2_index = loops[v2_loop].v;
- const float3 v0_pos = verts[v0_index].co;
- const float3 v1_pos = verts[v1_index].co;
- const float3 v2_pos = verts[v2_index].co;
+ const float3 v0_pos = positions[v0_index];
+ const float3 v1_pos = positions[v1_index];
+ const float3 v2_pos = positions[v2_index];
float looptri_density_factor = 1.0f;
if (!density_factors.is_empty()) {
@@ -348,7 +348,7 @@ BLI_NOINLINE static void compute_attribute_outputs(const Mesh &mesh,
attribute_outputs.rotation_id.get(), ATTR_DOMAIN_POINT);
}
- const Span<MVert> verts = mesh.verts();
+ const Span<float3> positions = mesh.positions();
const Span<MLoop> loops = mesh.loops();
const Span<MLoopTri> looptris = mesh.looptris();
@@ -360,9 +360,9 @@ BLI_NOINLINE static void compute_attribute_outputs(const Mesh &mesh,
const int v0_index = loops[looptri.tri[0]].v;
const int v1_index = loops[looptri.tri[1]].v;
const int v2_index = loops[looptri.tri[2]].v;
- const float3 v0_pos = verts[v0_index].co;
- const float3 v1_pos = verts[v1_index].co;
- const float3 v2_pos = verts[v2_index].co;
+ const float3 v0_pos = positions[v0_index];
+ const float3 v1_pos = positions[v1_index];
+ const float3 v2_pos = positions[v2_index];
ids.span[i] = noise::hash(noise::hash_float(bary_coord), looptri_index);
diff --git a/source/blender/nodes/geometry/nodes/node_geo_dual_mesh.cc b/source/blender/nodes/geometry/nodes/node_geo_dual_mesh.cc
index 9b1c13bf563..bf018e1e04f 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_dual_mesh.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_dual_mesh.cc
@@ -627,7 +627,7 @@ static void calc_dual_mesh(GeometrySet &geometry_set,
const bool keep_boundaries)
{
const Mesh &mesh_in = *in_component.get_for_read();
- const Span<MVert> src_verts = mesh_in.verts();
+ const Span<float3> src_positions = mesh_in.positions();
const Span<MEdge> src_edges = mesh_in.edges();
const Span<MPoly> src_polys = mesh_in.polys();
const Span<MLoop> src_loops = mesh_in.loops();
@@ -695,8 +695,10 @@ static void calc_dual_mesh(GeometrySet &geometry_set,
Vector<float3> vertex_positions(mesh_in.totpoly);
for (const int i : IndexRange(mesh_in.totpoly)) {
const MPoly &poly = src_polys[i];
- BKE_mesh_calc_poly_center(
- &poly, &src_loops[poly.loopstart], src_verts.data(), vertex_positions[i]);
+ BKE_mesh_calc_poly_center(&poly,
+ &src_loops[poly.loopstart],
+ reinterpret_cast<const float(*)[3]>(src_positions.data()),
+ vertex_positions[i]);
}
Array<int> boundary_edge_midpoint_index;
@@ -706,9 +708,8 @@ static void calc_dual_mesh(GeometrySet &geometry_set,
/* We need to add vertices at the centers of boundary edges. */
for (const int i : IndexRange(mesh_in.totedge)) {
if (edge_types[i] == EdgeType::Boundary) {
- float3 mid;
const MEdge &edge = src_edges[i];
- mid_v3_v3v3(mid, src_verts[edge.v1].co, src_verts[edge.v2].co);
+ const float3 mid = math::midpoint(src_positions[edge.v1], src_positions[edge.v2]);
boundary_edge_midpoint_index[i] = vertex_positions.size();
vertex_positions.append(mid);
}
@@ -859,7 +860,7 @@ static void calc_dual_mesh(GeometrySet &geometry_set,
new_to_old_face_corners_map.append(sorted_corners.first());
boundary_vertex_to_relevant_face_map.append(
std::pair(loop_indices.last(), last_face_center));
- vertex_positions.append(src_verts[i].co);
+ vertex_positions.append(src_positions[i]);
const int boundary_vertex = loop_indices.last();
add_edge(src_edges,
edge1,
@@ -913,7 +914,7 @@ static void calc_dual_mesh(GeometrySet &geometry_set,
mesh_in.attributes(),
mesh_out->attributes_for_write());
- MutableSpan<MVert> dst_verts = mesh_out->verts_for_write();
+ mesh_out->positions_for_write().copy_from(vertex_positions);
MutableSpan<MEdge> dst_edges = mesh_out->edges_for_write();
MutableSpan<MPoly> dst_polys = mesh_out->polys_for_write();
MutableSpan<MLoop> dst_loops = mesh_out->loops_for_write();
@@ -928,9 +929,6 @@ static void calc_dual_mesh(GeometrySet &geometry_set,
dst_loops[i].v = loops[i];
dst_loops[i].e = loop_edges[i];
}
- for (const int i : IndexRange(mesh_out->totvert)) {
- copy_v3_v3(dst_verts[i].co, vertex_positions[i]);
- }
dst_edges.copy_from(new_edges);
geometry_set.replace_mesh(mesh_out);
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc b/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc
index f048ec11f77..891f50c6a2c 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc
@@ -514,7 +514,6 @@ static void duplicate_faces(GeometrySet &geometry_set,
geometry_set.keep_only_during_modify({GEO_COMPONENT_TYPE_MESH});
const Mesh &mesh = *geometry_set.get_mesh_for_read();
- const Span<MVert> verts = mesh.verts();
const Span<MEdge> edges = mesh.edges();
const Span<MPoly> polys = mesh.polys();
const Span<MLoop> loops = mesh.loops();
@@ -539,12 +538,11 @@ static void duplicate_faces(GeometrySet &geometry_set,
offsets[selection.size()] = total_polys;
Mesh *new_mesh = BKE_mesh_new_nomain(total_loops, total_loops, 0, total_loops, total_polys);
- MutableSpan<MVert> new_verts = new_mesh->verts_for_write();
MutableSpan<MEdge> new_edges = new_mesh->edges_for_write();
MutableSpan<MPoly> new_polys = new_mesh->polys_for_write();
MutableSpan<MLoop> new_loops = new_mesh->loops_for_write();
- Array<int> vert_mapping(new_verts.size());
+ Array<int> vert_mapping(new_mesh->totvert);
Array<int> edge_mapping(new_edges.size());
Array<int> loop_mapping(new_loops.size());
@@ -560,7 +558,6 @@ static void duplicate_faces(GeometrySet &geometry_set,
for (const int i_loops : IndexRange(source.totloop)) {
const MLoop &current_loop = loops[source.loopstart + i_loops];
loop_mapping[loop_index] = source.loopstart + i_loops;
- new_verts[loop_index] = verts[current_loop.v];
vert_mapping[loop_index] = current_loop.v;
new_edges[loop_index] = edges[current_loop.e];
edge_mapping[loop_index] = current_loop.e;
@@ -886,10 +883,9 @@ static void duplicate_points_mesh(GeometrySet &geometry_set,
const IndexAttributes &attribute_outputs)
{
const Mesh &mesh = *geometry_set.get_mesh_for_read();
- const Span<MVert> src_verts = mesh.verts();
bke::MeshFieldContext field_context{mesh, ATTR_DOMAIN_POINT};
- FieldEvaluator evaluator{field_context, src_verts.size()};
+ FieldEvaluator evaluator{field_context, mesh.totvert};
evaluator.add(count_field);
evaluator.set_selection(selection_field);
evaluator.evaluate();
@@ -899,9 +895,6 @@ static void duplicate_points_mesh(GeometrySet &geometry_set,
Array<int> offsets = accumulate_counts_to_offsets(selection, counts);
Mesh *new_mesh = BKE_mesh_new_nomain(offsets.last(), 0, 0, 0, 0);
- MutableSpan<MVert> dst_verts = new_mesh->verts_for_write();
-
- threaded_slice_fill(offsets.as_span(), selection, src_verts, dst_verts);
copy_attributes_without_id(geometry_set,
GEO_COMPONENT_TYPE_MESH,
diff --git a/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc b/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc
index 0062abba909..9bb824dbf7f 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc
@@ -230,7 +230,7 @@ static void extrude_mesh_vertices(Mesh &mesh,
const IndexRange new_vert_range{orig_vert_size, selection.size()};
const IndexRange new_edge_range{orig_edge_size, selection.size()};
- MutableSpan<MVert> new_verts = mesh.verts_for_write().slice(new_vert_range);
+ MutableSpan<float3> new_positions = mesh.positions_for_write().slice(new_vert_range);
MutableSpan<MEdge> new_edges = mesh.edges_for_write().slice(new_edge_range);
for (const int i_selection : selection.index_range()) {
@@ -274,8 +274,7 @@ static void extrude_mesh_vertices(Mesh &mesh,
devirtualize_varray(offsets, [&](const auto offsets) {
threading::parallel_for(selection.index_range(), 1024, [&](const IndexRange range) {
for (const int i : range) {
- const float3 offset = offsets[selection[i]];
- add_v3_v3(new_verts[i].co, offset);
+ new_positions[i] += offsets[selection[i]];
}
});
});
@@ -599,19 +598,19 @@ static void extrude_mesh_edges(Mesh &mesh,
return true;
});
- MutableSpan<MVert> new_verts = mesh.verts_for_write().slice(new_vert_range);
+ MutableSpan<float3> new_positions = mesh.positions_for_write().slice(new_vert_range);
if (edge_offsets.is_single()) {
const float3 offset = edge_offsets.get_internal_single();
- threading::parallel_for(new_verts.index_range(), 1024, [&](const IndexRange range) {
+ threading::parallel_for(new_positions.index_range(), 1024, [&](const IndexRange range) {
for (const int i : range) {
- add_v3_v3(new_verts[i].co, offset);
+ new_positions[i] += offset;
}
});
}
else {
- threading::parallel_for(new_verts.index_range(), 1024, [&](const IndexRange range) {
+ threading::parallel_for(new_positions.index_range(), 1024, [&](const IndexRange range) {
for (const int i : range) {
- add_v3_v3(new_verts[i].co, vert_offsets[new_vert_indices[i]]);
+ new_positions[i] += vert_offsets[new_vert_indices[i]];
}
});
}
@@ -976,15 +975,19 @@ static void extrude_mesh_face_regions(Mesh &mesh,
/* Translate vertices based on the offset. If the vertex is used by a selected edge, it will
* have been duplicated and only the new vertex should use the offset. Otherwise the vertex might
* still need an offset, but it was reused on the inside of a region of extruded faces. */
- MutableSpan<MVert> verts = mesh.verts_for_write();
+ MutableSpan<float3> positions = mesh.positions_for_write();
if (poly_offsets.is_single()) {
const float3 offset = poly_offsets.get_internal_single();
threading::parallel_for(
IndexRange(all_selected_verts.size()), 1024, [&](const IndexRange range) {
for (const int i_orig : all_selected_verts.as_span().slice(range)) {
const int i_new = new_vert_indices.index_of_try(i_orig);
- MVert &vert = verts[(i_new == -1) ? i_orig : new_vert_range[i_new]];
- add_v3_v3(vert.co, offset);
+ if (i_new == -1) {
+ positions[i_orig] += offset;
+ }
+ else {
+ positions[new_vert_range[i_new]] += offset;
+ }
}
});
}
@@ -994,8 +997,12 @@ static void extrude_mesh_face_regions(Mesh &mesh,
for (const int i_orig : all_selected_verts.as_span().slice(range)) {
const int i_new = new_vert_indices.index_of_try(i_orig);
const float3 offset = vert_offsets[i_orig];
- MVert &vert = verts[(i_new == -1) ? i_orig : new_vert_range[i_new]];
- add_v3_v3(vert.co, offset);
+ if (i_new == -1) {
+ positions[i_orig] += offset;
+ }
+ else {
+ positions[new_vert_range[i_new]] += offset;
+ }
}
});
}
@@ -1078,7 +1085,7 @@ static void extrude_individual_mesh_faces(Mesh &mesh,
side_poly_range.size(),
side_loop_range.size());
- MutableSpan<MVert> new_verts = mesh.verts_for_write().slice(new_vert_range);
+ MutableSpan<float3> new_positions = mesh.positions_for_write().slice(new_vert_range);
MutableSpan<MEdge> edges = mesh.edges_for_write();
MutableSpan<MEdge> connect_edges = edges.slice(connect_edge_range);
MutableSpan<MEdge> duplicate_edges = edges.slice(duplicate_edge_range);
@@ -1258,8 +1265,8 @@ static void extrude_individual_mesh_faces(Mesh &mesh,
threading::parallel_for(poly_selection.index_range(), 1024, [&](const IndexRange range) {
for (const int i_selection : range) {
const IndexRange poly_corner_range = selected_corner_range(index_offsets, i_selection);
- for (MVert &vert : new_verts.slice(poly_corner_range)) {
- add_v3_v3(vert.co, poly_offset[poly_selection[i_selection]]);
+ for (float3 &position : new_positions.slice(poly_corner_range)) {
+ position += poly_offset[poly_selection[i_selection]];
}
}
});
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_angle.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_angle.cc
index 29730ab8dc4..c0ccd2f2570 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_angle.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_angle.cc
@@ -64,20 +64,27 @@ class AngleFieldInput final : public bke::MeshFieldInput {
const eAttrDomain domain,
const IndexMask /*mask*/) const final
{
- const Span<MVert> verts = mesh.verts();
+ const Span<float3> positions = mesh.positions();
const Span<MPoly> polys = mesh.polys();
const Span<MLoop> loops = mesh.loops();
Array<EdgeMapEntry> edge_map = create_edge_map(polys, loops, mesh.totedge);
- auto angle_fn = [edge_map = std::move(edge_map), verts, polys, loops](const int i) -> float {
+ auto angle_fn =
+ [edge_map = std::move(edge_map), positions, polys, loops](const int i) -> float {
if (edge_map[i].face_count != 2) {
return 0.0f;
}
const MPoly &mpoly_1 = polys[edge_map[i].face_index_1];
const MPoly &mpoly_2 = polys[edge_map[i].face_index_2];
float3 normal_1, normal_2;
- BKE_mesh_calc_poly_normal(&mpoly_1, &loops[mpoly_1.loopstart], verts.data(), normal_1);
- BKE_mesh_calc_poly_normal(&mpoly_2, &loops[mpoly_2.loopstart], verts.data(), normal_2);
+ BKE_mesh_calc_poly_normal(&mpoly_1,
+ &loops[mpoly_1.loopstart],
+ reinterpret_cast<const float(*)[3]>(positions.data()),
+ normal_1);
+ BKE_mesh_calc_poly_normal(&mpoly_2,
+ &loops[mpoly_2.loopstart],
+ reinterpret_cast<const float(*)[3]>(positions.data()),
+ normal_2);
return angle_normalized_v3v3(normal_1, normal_2);
};
@@ -113,14 +120,14 @@ class SignedAngleFieldInput final : public bke::MeshFieldInput {
const eAttrDomain domain,
const IndexMask /*mask*/) const final
{
- const Span<MVert> verts = mesh.verts();
+ const Span<float3> positions = mesh.positions();
const Span<MEdge> edges = mesh.edges();
const Span<MPoly> polys = mesh.polys();
const Span<MLoop> loops = mesh.loops();
Array<EdgeMapEntry> edge_map = create_edge_map(polys, loops, mesh.totedge);
auto angle_fn =
- [edge_map = std::move(edge_map), verts, edges, polys, loops](const int i) -> float {
+ [edge_map = std::move(edge_map), positions, edges, polys, loops](const int i) -> float {
if (edge_map[i].face_count != 2) {
return 0.0f;
}
@@ -129,18 +136,25 @@ class SignedAngleFieldInput final : public bke::MeshFieldInput {
/* Find the normals of the 2 polys. */
float3 poly_1_normal, poly_2_normal;
- BKE_mesh_calc_poly_normal(&mpoly_1, &loops[mpoly_1.loopstart], verts.data(), poly_1_normal);
- BKE_mesh_calc_poly_normal(&mpoly_2, &loops[mpoly_2.loopstart], verts.data(), poly_2_normal);
+ BKE_mesh_calc_poly_normal(&mpoly_1,
+ &loops[mpoly_1.loopstart],
+ reinterpret_cast<const float(*)[3]>(positions.data()),
+ poly_1_normal);
+ BKE_mesh_calc_poly_normal(&mpoly_2,
+ &loops[mpoly_2.loopstart],
+ reinterpret_cast<const float(*)[3]>(positions.data()),
+ poly_2_normal);
/* Find the centerpoint of the axis edge */
- const float3 edge_centerpoint = (float3(verts[edges[i].v1].co) +
- float3(verts[edges[i].v2].co)) *
- 0.5f;
+ const float3 edge_centerpoint = (positions[edges[i].v1] + positions[edges[i].v2]) * 0.5f;
/* Get the centerpoint of poly 2 and subtract the edge centerpoint to get a tangent
* normal for poly 2. */
float3 poly_center_2;
- BKE_mesh_calc_poly_center(&mpoly_2, &loops[mpoly_2.loopstart], verts.data(), poly_center_2);
+ BKE_mesh_calc_poly_center(&mpoly_2,
+ &loops[mpoly_2.loopstart],
+ reinterpret_cast<const float(*)[3]>(positions.data()),
+ poly_center_2);
const float3 poly_2_tangent = math::normalize(poly_center_2 - edge_centerpoint);
const float concavity = math::dot(poly_1_normal, poly_2_tangent);
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_vertices.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_vertices.cc
index 513ddd76055..aaf9b1aedb0 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_vertices.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_vertices.cc
@@ -83,19 +83,19 @@ static VArray<float3> construct_edge_positions_gvarray(const Mesh &mesh,
const VertNumber vertex,
const eAttrDomain domain)
{
- const Span<MVert> verts = mesh.verts();
+ const Span<float3> positions = mesh.positions();
const Span<MEdge> edges = mesh.edges();
if (vertex == VertNumber::V1) {
return mesh.attributes().adapt_domain<float3>(
- VArray<float3>::ForFunc(edges.size(),
- [verts, edges](const int i) { return verts[edges[i].v1].co; }),
+ VArray<float3>::ForFunc(
+ edges.size(), [positions, edges](const int i) { return positions[edges[i].v1]; }),
ATTR_DOMAIN_EDGE,
domain);
}
return mesh.attributes().adapt_domain<float3>(
VArray<float3>::ForFunc(edges.size(),
- [verts, edges](const int i) { return verts[edges[i].v2].co; }),
+ [positions, edges](const int i) { return positions[edges[i].v2]; }),
ATTR_DOMAIN_EDGE,
domain);
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_area.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_area.cc
index aec1c27a4fc..4e4bb3de17f 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_area.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_area.cc
@@ -18,13 +18,14 @@ static void node_declare(NodeDeclarationBuilder &b)
static VArray<float> construct_face_area_varray(const Mesh &mesh, const eAttrDomain domain)
{
- const Span<MVert> verts = mesh.verts();
+ const Span<float3> positions = mesh.positions();
const Span<MPoly> polys = mesh.polys();
const Span<MLoop> loops = mesh.loops();
- auto area_fn = [verts, polys, loops](const int i) -> float {
+ auto area_fn = [positions, polys, loops](const int i) -> float {
const MPoly &poly = polys[i];
- return BKE_mesh_calc_poly_area(&poly, &loops[poly.loopstart], verts.data());
+ return BKE_mesh_calc_poly_area(
+ &poly, &loops[poly.loopstart], reinterpret_cast<const float(*)[3]>(positions.data()));
};
return mesh.attributes().adapt_domain<float>(
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_is_planar.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_is_planar.cc
index 7b084995fc3..0bd1cf968df 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_is_planar.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_is_planar.cc
@@ -37,7 +37,7 @@ class PlanarFieldInput final : public bke::MeshFieldInput {
const eAttrDomain domain,
IndexMask /*mask*/) const final
{
- const Span<MVert> verts = mesh.verts();
+ const Span<float3> positions = mesh.positions();
const Span<MPoly> polys = mesh.polys();
const Span<MLoop> loops = mesh.loops();
const Span<float3> poly_normals{
@@ -49,7 +49,7 @@ class PlanarFieldInput final : public bke::MeshFieldInput {
evaluator.evaluate();
const VArray<float> thresholds = evaluator.get_evaluated<float>(0);
- auto planar_fn = [verts, polys, loops, thresholds, poly_normals](const int i) -> bool {
+ auto planar_fn = [positions, polys, loops, thresholds, poly_normals](const int i) -> bool {
const MPoly &poly = polys[i];
if (poly.totloop <= 3) {
return true;
@@ -61,7 +61,7 @@ class PlanarFieldInput final : public bke::MeshFieldInput {
float max = -FLT_MAX;
for (const int i_loop : poly_loops.index_range()) {
- const float3 vert = verts[poly_loops[i_loop].v].co;
+ const float3 &vert = positions[poly_loops[i_loop].v];
float dot = math::dot(reference_normal, vert);
if (dot > max) {
max = dot;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc
index 14f38efbd42..956da402dd3 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc
@@ -109,7 +109,7 @@ static Mesh *create_circle_mesh(const float radius,
circle_corner_total(fill_type, verts_num),
circle_face_total(fill_type, verts_num));
BKE_id_material_eval_ensure_default_slot(&mesh->id);
- MutableSpan<MVert> verts = mesh->verts_for_write();
+ MutableSpan<float3> positions = mesh->positions_for_write();
MutableSpan<MEdge> edges = mesh->edges_for_write();
MutableSpan<MPoly> polys = mesh->polys_for_write();
MutableSpan<MLoop> loops = mesh->loops_for_write();
@@ -118,10 +118,10 @@ static Mesh *create_circle_mesh(const float radius,
const float angle_delta = 2.0f * (M_PI / float(verts_num));
for (const int i : IndexRange(verts_num)) {
const float angle = i * angle_delta;
- copy_v3_v3(verts[i].co, float3(std::cos(angle) * radius, std::sin(angle) * radius, 0.0f));
+ positions[i] = float3(std::cos(angle) * radius, std::sin(angle) * radius, 0.0f);
}
if (fill_type == GEO_NODE_MESH_CIRCLE_FILL_TRIANGLE_FAN) {
- copy_v3_v3(verts.last().co, float3(0));
+ positions.last() = float3(0);
}
/* Create outer edges. */
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc
index dca91d2dc61..7653d57ee70 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc
@@ -255,7 +255,7 @@ int ConeConfig::calculate_total_corners()
return corner_total;
}
-static void calculate_cone_verts(const MutableSpan<MVert> &verts, const ConeConfig &config)
+static void calculate_cone_verts(const MutableSpan<float3> positions, const ConeConfig &config)
{
Array<float2> circle(config.circle_segments);
const float angle_delta = 2.0f * (M_PI / float(config.circle_segments));
@@ -270,7 +270,7 @@ static void calculate_cone_verts(const MutableSpan<MVert> &verts, const ConeConf
/* Top cone tip or triangle fan center. */
if (config.top_has_center_vert) {
- copy_v3_fl3(verts[vert_index++].co, 0.0f, 0.0f, config.height);
+ positions[vert_index++] = {0.0f, 0.0f, config.height};
}
/* Top fill including the outer edge of the fill. */
@@ -281,7 +281,7 @@ static void calculate_cone_verts(const MutableSpan<MVert> &verts, const ConeConf
for (const int j : IndexRange(config.circle_segments)) {
const float x = circle[j].x * top_fill_radius;
const float y = circle[j].y * top_fill_radius;
- copy_v3_fl3(verts[vert_index++].co, x, y, config.height);
+ positions[vert_index++] = {x, y, config.height};
}
}
}
@@ -296,7 +296,7 @@ static void calculate_cone_verts(const MutableSpan<MVert> &verts, const ConeConf
for (const int j : IndexRange(config.circle_segments)) {
const float x = circle[j].x * ring_radius;
const float y = circle[j].y * ring_radius;
- copy_v3_fl3(verts[vert_index++].co, x, y, ring_height);
+ positions[vert_index++] = {x, y, ring_height};
}
}
@@ -308,14 +308,14 @@ static void calculate_cone_verts(const MutableSpan<MVert> &verts, const ConeConf
for (const int j : IndexRange(config.circle_segments)) {
const float x = circle[j].x * bottom_fill_radius;
const float y = circle[j].y * bottom_fill_radius;
- copy_v3_fl3(verts[vert_index++].co, x, y, -config.height);
+ positions[vert_index++] = {x, y, -config.height};
}
}
}
/* Bottom cone tip or triangle fan center. */
if (config.bottom_has_center_vert) {
- copy_v3_fl3(verts[vert_index++].co, 0.0f, 0.0f, -config.height);
+ positions[vert_index++] = {0.0f, 0.0f, -config.height};
}
}
@@ -654,7 +654,7 @@ static Mesh *create_vertex_mesh()
{
/* Returns a mesh with a single vertex at the origin. */
Mesh *mesh = BKE_mesh_new_nomain(1, 0, 0, 0, 0);
- copy_v3_fl3(mesh->verts_for_write().first().co, 0.0f, 0.0f, 0.0f);
+ mesh->positions_for_write().first() = float3(0);
return mesh;
}
@@ -686,12 +686,12 @@ Mesh *create_cylinder_or_cone_mesh(const float radius_top,
config.tot_verts, config.tot_edges, 0, config.tot_corners, config.tot_faces);
BKE_id_material_eval_ensure_default_slot(&mesh->id);
- MutableSpan<MVert> verts = mesh->verts_for_write();
+ MutableSpan<float3> positions = mesh->positions_for_write();
MutableSpan<MEdge> edges = mesh->edges_for_write();
MutableSpan<MPoly> polys = mesh->polys_for_write();
MutableSpan<MLoop> loops = mesh->loops_for_write();
- calculate_cone_verts(verts, config);
+ calculate_cone_verts(positions, config);
calculate_cone_edges(edges, config);
calculate_cone_faces(loops, polys, config);
calculate_cone_uvs(mesh, config);
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_grid.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_grid.cc
index e8ee057ee5c..dd84ae0e8ad 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_grid.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_grid.cc
@@ -16,7 +16,7 @@
namespace blender::nodes {
static void calculate_uvs(
- Mesh *mesh, Span<MVert> verts, Span<MLoop> loops, const float size_x, const float size_y)
+ Mesh *mesh, Span<float3> positions, Span<MLoop> loops, const float size_x, const float size_y)
{
MutableAttributeAccessor attributes = mesh->attributes_for_write();
@@ -27,7 +27,7 @@ static void calculate_uvs(
const float dy = (size_y == 0.0f) ? 0.0f : 1.0f / size_y;
threading::parallel_for(loops.index_range(), 1024, [&](IndexRange range) {
for (const int i : range) {
- const float3 &co = verts[loops[i].v].co;
+ const float3 &co = positions[loops[i].v];
uv_attribute.span[i].x = (co.x + size_x * 0.5f) * dx;
uv_attribute.span[i].y = (co.y + size_y * 0.5f) * dy;
}
@@ -49,7 +49,7 @@ Mesh *create_grid_mesh(const int verts_x,
0,
edges_x * edges_y * 4,
edges_x * edges_y);
- MutableSpan<MVert> verts = mesh->verts_for_write();
+ MutableSpan<float3> positions = mesh->positions_for_write();
MutableSpan<MEdge> edges = mesh->edges_for_write();
MutableSpan<MPoly> polys = mesh->polys_for_write();
MutableSpan<MLoop> loops = mesh->loops_for_write();
@@ -65,9 +65,9 @@ Mesh *create_grid_mesh(const int verts_x,
threading::parallel_for(IndexRange(verts_y), 512, [&](IndexRange y_range) {
for (const int y : y_range) {
const int vert_index = y_offset + y;
- verts[vert_index].co[0] = (x - x_shift) * dx;
- verts[vert_index].co[1] = (y - y_shift) * dy;
- verts[vert_index].co[2] = 0.0f;
+ positions[vert_index].x = (x - x_shift) * dx;
+ positions[vert_index].y = (y - y_shift) * dy;
+ positions[vert_index].z = 0.0f;
}
});
}
@@ -141,7 +141,7 @@ Mesh *create_grid_mesh(const int verts_x,
});
if (mesh->totpoly != 0) {
- calculate_uvs(mesh, verts, loops, size_x, size_y);
+ calculate_uvs(mesh, positions, loops, size_x, size_y);
}
return mesh;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc
index 51a4f36507e..79a98b67d9c 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc
@@ -179,15 +179,15 @@ Mesh *create_line_mesh(const float3 start, const float3 delta, const int count)
Mesh *mesh = BKE_mesh_new_nomain(count, count - 1, 0, 0, 0);
BKE_id_material_eval_ensure_default_slot(&mesh->id);
- MutableSpan<MVert> verts = mesh->verts_for_write();
+ MutableSpan<float3> positions = mesh->positions_for_write();
MutableSpan<MEdge> edges = mesh->edges_for_write();
threading::parallel_invoke(
1024 < count,
[&]() {
- threading::parallel_for(verts.index_range(), 4096, [&](IndexRange range) {
+ threading::parallel_for(positions.index_range(), 4096, [&](IndexRange range) {
for (const int i : range) {
- copy_v3_v3(verts[i].co, start + delta * i);
+ positions[i] = start + delta * i;
}
});
},
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc
index cfa1c477b28..f29e21436e0 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc
@@ -63,7 +63,7 @@ static int sphere_face_total(const int segments, const int rings)
* Also calculate vertex normals here, since the calculation is trivial, and it allows avoiding the
* calculation later, if it's necessary. The vertex normals are just the normalized positions.
*/
-BLI_NOINLINE static void calculate_sphere_vertex_data(MutableSpan<MVert> verts,
+BLI_NOINLINE static void calculate_sphere_vertex_data(MutableSpan<float3> positions,
MutableSpan<float3> vert_normals,
const float radius,
const int segments,
@@ -83,7 +83,7 @@ BLI_NOINLINE static void calculate_sphere_vertex_data(MutableSpan<MVert> verts,
segment_sines[segment] = std::sin(phi);
}
- copy_v3_v3(verts[0].co, float3(0.0f, 0.0f, radius));
+ positions[0] = float3(0.0f, 0.0f, radius);
vert_normals.first() = float3(0.0f, 0.0f, 1.0f);
int vert_index = 1;
@@ -94,13 +94,13 @@ BLI_NOINLINE static void calculate_sphere_vertex_data(MutableSpan<MVert> verts,
for (const int segment : IndexRange(1, segments)) {
const float x = sin_theta * segment_cosines[segment];
const float y = sin_theta * segment_sines[segment];
- copy_v3_v3(verts[vert_index].co, float3(x, y, z) * radius);
+ positions[vert_index] = float3(x, y, z) * radius;
vert_normals[vert_index] = float3(x, y, z);
vert_index++;
}
}
- copy_v3_v3(verts.last().co, float3(0.0f, 0.0f, -radius));
+ positions.last() = float3(0.0f, 0.0f, -radius);
vert_normals.last() = float3(0.0f, 0.0f, -1.0f);
}
@@ -301,7 +301,7 @@ static Mesh *create_uv_sphere_mesh(const float radius, const int segments, const
sphere_corner_total(segments, rings),
sphere_face_total(segments, rings));
BKE_id_material_eval_ensure_default_slot(&mesh->id);
- MutableSpan<MVert> verts = mesh->verts_for_write();
+ MutableSpan<float3> positions = mesh->positions_for_write();
MutableSpan<MEdge> edges = mesh->edges_for_write();
MutableSpan<MPoly> polys = mesh->polys_for_write();
MutableSpan<MLoop> loops = mesh->loops_for_write();
@@ -311,7 +311,7 @@ static Mesh *create_uv_sphere_mesh(const float radius, const int segments, const
[&]() {
MutableSpan vert_normals{
reinterpret_cast<float3 *>(BKE_mesh_vertex_normals_for_write(mesh)), mesh->totvert};
- calculate_sphere_vertex_data(verts, vert_normals, radius, segments, rings);
+ calculate_sphere_vertex_data(positions, vert_normals, radius, segments, rings);
BKE_mesh_vertex_normals_clear_dirty(mesh);
},
[&]() { calculate_sphere_edge_indices(edges, segments, rings); },
diff --git a/source/blender/nodes/geometry/nodes/node_geo_sample_nearest.cc b/source/blender/nodes/geometry/nodes/node_geo_sample_nearest.cc
index 7028b013dc6..b7142bc8521 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_sample_nearest.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_sample_nearest.cc
@@ -163,7 +163,7 @@ static void get_closest_mesh_corners(const Mesh &mesh,
const MutableSpan<float> r_distances_sq,
const MutableSpan<float3> r_positions)
{
- const Span<MVert> verts = mesh.verts();
+ const Span<float3> mesh_positions = mesh.positions();
const Span<MPoly> polys = mesh.polys();
const Span<MLoop> loops = mesh.loops();
@@ -178,24 +178,23 @@ static void get_closest_mesh_corners(const Mesh &mesh,
/* Find the closest vertex in the polygon. */
float min_distance_sq = FLT_MAX;
- const MVert *closest_mvert;
+ int closest_vert_index = 0;
int closest_loop_index = 0;
for (const int loop_index : IndexRange(poly.loopstart, poly.totloop)) {
const MLoop &loop = loops[loop_index];
const int vertex_index = loop.v;
- const MVert &mvert = verts[vertex_index];
- const float distance_sq = math::distance_squared(position, float3(mvert.co));
+ const float distance_sq = math::distance_squared(position, mesh_positions[vertex_index]);
if (distance_sq < min_distance_sq) {
min_distance_sq = distance_sq;
closest_loop_index = loop_index;
- closest_mvert = &mvert;
+ closest_vert_index = vertex_index;
}
}
if (!r_corner_indices.is_empty()) {
r_corner_indices[i] = closest_loop_index;
}
if (!r_positions.is_empty()) {
- r_positions[i] = closest_mvert->co;
+ r_positions[i] = mesh_positions[closest_vert_index];
}
if (!r_distances_sq.is_empty()) {
r_distances_sq[i] = min_distance_sq;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_scale_elements.cc b/source/blender/nodes/geometry/nodes/node_geo_scale_elements.cc
index 5f1baa23511..dbce3dfe2b0 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_scale_elements.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_scale_elements.cc
@@ -157,7 +157,7 @@ static void scale_vertex_islands_uniformly(Mesh &mesh,
const UniformScaleParams &params,
const GetVertexIndicesFn get_vertex_indices)
{
- MutableSpan<MVert> verts = mesh.verts_for_write();
+ MutableSpan<float3> positions = mesh.positions_for_write();
const Span<MEdge> edges = mesh.edges();
const Span<MPoly> polys = mesh.polys();
const Span<MLoop> loops = mesh.loops();
@@ -182,10 +182,7 @@ static void scale_vertex_islands_uniformly(Mesh &mesh,
center *= f;
for (const int vert_index : vertex_indices) {
- MVert &vert = verts[vert_index];
- const float3 old_position = vert.co;
- const float3 new_position = transform_with_uniform_scale(old_position, center, scale);
- copy_v3_v3(vert.co, new_position);
+ positions[vert_index] = transform_with_uniform_scale(positions[vert_index], center, scale);
}
}
});
@@ -198,7 +195,7 @@ static void scale_vertex_islands_on_axis(Mesh &mesh,
const AxisScaleParams &params,
const GetVertexIndicesFn get_vertex_indices)
{
- MutableSpan<MVert> verts = mesh.verts_for_write();
+ MutableSpan<float3> positions = mesh.positions_for_write();
const Span<MEdge> edges = mesh.edges();
const Span<MPoly> polys = mesh.polys();
const Span<MLoop> loops = mesh.loops();
@@ -231,10 +228,7 @@ static void scale_vertex_islands_on_axis(Mesh &mesh,
const float4x4 transform = create_single_axis_transform(center, axis, scale);
for (const int vert_index : vertex_indices) {
- MVert &vert = verts[vert_index];
- const float3 old_position = vert.co;
- const float3 new_position = transform * old_position;
- copy_v3_v3(vert.co, new_position);
+ positions[vert_index] = transform * positions[vert_index];
}
}
});
diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_position.cc b/source/blender/nodes/geometry/nodes/node_geo_set_position.cc
index e243fe3614c..50739b83a61 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_set_position.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_set_position.cc
@@ -34,34 +34,6 @@ static void set_computed_position_and_offset(GeometryComponent &component,
const int grain_size = 10000;
switch (component.type()) {
- case GEO_COMPONENT_TYPE_MESH: {
- Mesh *mesh = static_cast<MeshComponent &>(component).get_for_write();
- MutableSpan<MVert> verts = mesh->verts_for_write();
- if (in_positions.is_same(positions.varray)) {
- devirtualize_varray(in_offsets, [&](const auto in_offsets) {
- threading::parallel_for(
- selection.index_range(), grain_size, [&](const IndexRange range) {
- for (const int i : selection.slice(range)) {
- const float3 offset = in_offsets[i];
- add_v3_v3(verts[i].co, offset);
- }
- });
- });
- }
- else {
- devirtualize_varray2(
- in_positions, in_offsets, [&](const auto in_positions, const auto in_offsets) {
- threading::parallel_for(
- selection.index_range(), grain_size, [&](const IndexRange range) {
- for (const int i : selection.slice(range)) {
- const float3 new_position = in_positions[i] + in_offsets[i];
- copy_v3_v3(verts[i].co, new_position);
- }
- });
- });
- }
- break;
- }
case GEO_COMPONENT_TYPE_CURVE: {
CurveComponent &curve_component = static_cast<CurveComponent &>(component);
Curves &curves_id = *curve_component.get_for_write();
diff --git a/source/blender/nodes/geometry/nodes/node_geo_uv_pack_islands.cc b/source/blender/nodes/geometry/nodes/node_geo_uv_pack_islands.cc
index c2d27cffa93..e02348e9c44 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_uv_pack_islands.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_uv_pack_islands.cc
@@ -37,7 +37,7 @@ static VArray<float3> construct_uv_gvarray(const Mesh &mesh,
const float margin,
const eAttrDomain domain)
{
- const Span<MVert> verts = mesh.verts();
+ const Span<float3> positions = mesh.positions();
const Span<MPoly> polys = mesh.polys();
const Span<MLoop> loops = mesh.loops();
@@ -67,7 +67,7 @@ static VArray<float3> construct_uv_gvarray(const Mesh &mesh,
for (const int i : IndexRange(mp.totloop)) {
const MLoop &ml = loops[mp.loopstart + i];
mp_vkeys[i] = ml.v;
- mp_co[i] = verts[ml.v].co;
+ mp_co[i] = positions[ml.v];
mp_uv[i] = uv[mp.loopstart + i];
mp_pin[i] = false;
mp_select[i] = false;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_uv_unwrap.cc b/source/blender/nodes/geometry/nodes/node_geo_uv_unwrap.cc
index eff3b969250..4136c21e58d 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_uv_unwrap.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_uv_unwrap.cc
@@ -62,7 +62,7 @@ static VArray<float3> construct_uv_gvarray(const Mesh &mesh,
const GeometryNodeUVUnwrapMethod method,
const eAttrDomain domain)
{
- const Span<MVert> verts = mesh.verts();
+ const Span<float3> positions = mesh.positions();
const Span<MEdge> edges = mesh.edges();
const Span<MPoly> polys = mesh.polys();
const Span<MLoop> loops = mesh.loops();
@@ -95,7 +95,7 @@ static VArray<float3> construct_uv_gvarray(const Mesh &mesh,
for (const int i : IndexRange(mp.totloop)) {
const MLoop &ml = loops[mp.loopstart + i];
mp_vkeys[i] = ml.v;
- mp_co[i] = verts[ml.v].co;
+ mp_co[i] = positions[ml.v];
mp_uv[i] = uv[mp.loopstart + i];
mp_pin[i] = false;
mp_select[i] = false;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_volume_to_mesh.cc b/source/blender/nodes/geometry/nodes/node_geo_volume_to_mesh.cc
index c076a6c08f3..309b03a1d44 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_volume_to_mesh.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_volume_to_mesh.cc
@@ -123,7 +123,7 @@ static Mesh *create_mesh_from_volume_grids(Span<openvdb::GridBase::ConstPtr> gri
Mesh *mesh = BKE_mesh_new_nomain(vert_offset, 0, 0, loop_offset, poly_offset);
BKE_id_material_eval_ensure_default_slot(&mesh->id);
- MutableSpan<MVert> verts = mesh->verts_for_write();
+ MutableSpan<float3> positions = mesh->positions_for_write();
MutableSpan<MPoly> polys = mesh->polys_for_write();
MutableSpan<MLoop> loops = mesh->loops_for_write();
@@ -135,7 +135,7 @@ static Mesh *create_mesh_from_volume_grids(Span<openvdb::GridBase::ConstPtr> gri
vert_offsets[i],
poly_offsets[i],
loop_offsets[i],
- verts,
+ positions,
polys,
loops);
}
diff --git a/source/blender/python/mathutils/mathutils_bvhtree.c b/source/blender/python/mathutils/mathutils_bvhtree.c
index 7b6c444515b..9410fb36371 100644
--- a/source/blender/python/mathutils/mathutils_bvhtree.c
+++ b/source/blender/python/mathutils/mathutils_bvhtree.c
@@ -1148,9 +1148,9 @@ static PyObject *C_BVHTree_FromObject(PyObject *UNUSED(cls), PyObject *args, PyO
coords = MEM_mallocN(sizeof(*coords) * (size_t)coords_len, __func__);
tris = MEM_mallocN(sizeof(*tris) * (size_t)tris_len, __func__);
- const MVert *verts = BKE_mesh_verts(mesh);
+ const float(*positions)[3] = BKE_mesh_positions(mesh);
for (int i = 0; i < mesh->totvert; i++) {
- copy_v3_v3(coords[i], verts[i].co);
+ copy_v3_v3(coords[i], positions[i]);
}
mloop = BKE_mesh_loops(mesh);
diff --git a/source/blender/render/intern/bake.c b/source/blender/render/intern/bake.c
index d9f7f9fa0af..8e413d3b80a 100644
--- a/source/blender/render/intern/bake.c
+++ b/source/blender/render/intern/bake.c
@@ -92,7 +92,7 @@ typedef struct TSpace {
} TSpace;
typedef struct TriTessFace {
- const MVert *mverts[3];
+ const float *positions[3];
const float *vert_normals[3];
const TSpace *tspace[3];
const float *loop_normal[3];
@@ -194,9 +194,9 @@ static void calc_point_from_barycentric_cage(TriTessFace *triangles_low,
triangle[1] = &triangles_cage[primitive_id];
for (i = 0; i < 2; i++) {
- copy_v3_v3(data[i][0], triangle[i]->mverts[0]->co);
- copy_v3_v3(data[i][1], triangle[i]->mverts[1]->co);
- copy_v3_v3(data[i][2], triangle[i]->mverts[2]->co);
+ copy_v3_v3(data[i][0], triangle[i]->positions[0]);
+ copy_v3_v3(data[i][1], triangle[i]->positions[1]);
+ copy_v3_v3(data[i][2], triangle[i]->positions[2]);
interp_barycentric_tri_v3(data[i], u, v, coord[i]);
}
@@ -236,9 +236,9 @@ static void calc_point_from_barycentric_extrusion(TriTessFace *triangles,
TriTessFace *triangle = &triangles[primitive_id];
is_smooth = triangle->is_smooth || is_cage;
- copy_v3_v3(data[0], triangle->mverts[0]->co);
- copy_v3_v3(data[1], triangle->mverts[1]->co);
- copy_v3_v3(data[2], triangle->mverts[2]->co);
+ copy_v3_v3(data[0], triangle->positions[0]);
+ copy_v3_v3(data[1], triangle->positions[1]);
+ copy_v3_v3(data[2], triangle->positions[2]);
interp_barycentric_tri_v3(data, u, v, coord);
@@ -393,8 +393,8 @@ static bool cast_ray_highpoly(BVHTreeFromMesh *treeData,
/* compute position differentials on low poly object */
float duco_low[3], dvco_low[3], dxco[3], dyco[3];
- sub_v3_v3v3(duco_low, triangle_low->mverts[0]->co, triangle_low->mverts[2]->co);
- sub_v3_v3v3(dvco_low, triangle_low->mverts[1]->co, triangle_low->mverts[2]->co);
+ sub_v3_v3v3(duco_low, triangle_low->positions[0], triangle_low->positions[2]);
+ sub_v3_v3v3(dvco_low, triangle_low->positions[1], triangle_low->positions[2]);
mul_v3_v3fl(dxco, duco_low, pixel_low->du_dx);
madd_v3_v3fl(dxco, dvco_low, pixel_low->dv_dx);
@@ -415,9 +415,9 @@ static bool cast_ray_highpoly(BVHTreeFromMesh *treeData,
/* compute barycentric differentials from position differentials */
barycentric_differentials_from_position(hits[hit_mesh].co,
- triangle_high->mverts[0]->co,
- triangle_high->mverts[1]->co,
- triangle_high->mverts[2]->co,
+ triangle_high->positions[0],
+ triangle_high->positions[1],
+ triangle_high->positions[2],
dxco,
dyco,
triangle_high->normal,
@@ -459,7 +459,7 @@ static TriTessFace *mesh_calc_tri_tessface(Mesh *me, bool tangent, Mesh *me_eval
uint mpoly_prev = UINT_MAX;
float no[3];
- const MVert *verts = BKE_mesh_verts(me);
+ const float(*positions)[3] = BKE_mesh_positions(me);
const MPoly *polys = BKE_mesh_polys(me);
const MLoop *loops = BKE_mesh_loops(me);
@@ -473,10 +473,10 @@ static TriTessFace *mesh_calc_tri_tessface(Mesh *me, bool tangent, Mesh *me_eval
if (precomputed_normals != NULL) {
BKE_mesh_recalc_looptri_with_normals(
- loops, polys, verts, me->totloop, me->totpoly, looptri, precomputed_normals);
+ loops, polys, positions, me->totloop, me->totpoly, looptri, precomputed_normals);
}
else {
- BKE_mesh_recalc_looptri(loops, polys, verts, me->totloop, me->totpoly, looptri);
+ BKE_mesh_recalc_looptri(loops, polys, positions, me->totloop, me->totpoly, looptri);
}
const TSpace *tspace = NULL;
@@ -497,9 +497,9 @@ static TriTessFace *mesh_calc_tri_tessface(Mesh *me, bool tangent, Mesh *me_eval
const MLoopTri *lt = &looptri[i];
const MPoly *mp = &polys[lt->poly];
- triangles[i].mverts[0] = &verts[loops[lt->tri[0]].v];
- triangles[i].mverts[1] = &verts[loops[lt->tri[1]].v];
- triangles[i].mverts[2] = &verts[loops[lt->tri[2]].v];
+ triangles[i].positions[0] = positions[loops[lt->tri[0]].v];
+ triangles[i].positions[1] = positions[loops[lt->tri[1]].v];
+ triangles[i].positions[2] = positions[loops[lt->tri[2]].v];
triangles[i].vert_normals[0] = vert_normals[loops[lt->tri[0]].v];
triangles[i].vert_normals[1] = vert_normals[loops[lt->tri[1]].v];
triangles[i].vert_normals[2] = vert_normals[loops[lt->tri[2]].v];
@@ -519,7 +519,7 @@ static TriTessFace *mesh_calc_tri_tessface(Mesh *me, bool tangent, Mesh *me_eval
if (calculate_normal) {
if (lt->poly != mpoly_prev) {
- BKE_mesh_calc_poly_normal(mp, &loops[mp->loopstart], verts, no);
+ BKE_mesh_calc_poly_normal(mp, &loops[mp->loopstart], positions, no);
mpoly_prev = lt->poly;
}
copy_v3_v3(triangles[i].normal, no);
@@ -741,10 +741,10 @@ void RE_bake_pixels_populate(Mesh *me,
const int tottri = poly_to_tri_count(me->totpoly, me->totloop);
MLoopTri *looptri = MEM_mallocN(sizeof(*looptri) * tottri, __func__);
- const MVert *verts = BKE_mesh_verts(me);
+ const float(*positions)[3] = BKE_mesh_positions(me);
const MPoly *polys = BKE_mesh_polys(me);
const MLoop *loops = BKE_mesh_loops(me);
- BKE_mesh_recalc_looptri(loops, polys, verts, me->totloop, me->totpoly, looptri);
+ BKE_mesh_recalc_looptri(loops, polys, positions, me->totloop, me->totpoly, looptri);
const int *material_indices = BKE_mesh_material_indices(me);
const int materials_num = targets->materials_num;
diff --git a/source/blender/render/intern/multires_bake.c b/source/blender/render/intern/multires_bake.c
index cfb91e86ad9..706f6558506 100644
--- a/source/blender/render/intern/multires_bake.c
+++ b/source/blender/render/intern/multires_bake.c
@@ -60,7 +60,7 @@ typedef struct MultiresBakeResult {
} MultiresBakeResult;
typedef struct {
- MVert *mvert;
+ const float (*positions)[3];
const float (*vert_normals)[3];
MPoly *mpoly;
const int *material_indices;
@@ -125,7 +125,7 @@ static void multiresbake_get_normal(const MResolvePixelData *data,
copy_v3_v3(r_normal, data->precomputed_normals[poly_index]);
}
else {
- BKE_mesh_calc_poly_normal(mp, &data->mloop[mp->loopstart], data->mvert, r_normal);
+ BKE_mesh_calc_poly_normal(mp, &data->mloop[mp->loopstart], data->positions, r_normal);
}
}
}
@@ -472,7 +472,7 @@ static void do_multires_bake(MultiresBakeRender *bkr,
MultiresBakeThread *handles;
MultiresBakeQueue queue;
- MVert *mvert = dm->getVertArray(dm);
+ const float(*positions)[3] = (float(*)[3])dm->getVertArray(dm);
MPoly *mpoly = dm->getPolyArray(dm);
MLoop *mloop = dm->getLoopArray(dm);
MLoopUV *mloopuv = dm->getLoopDataArray(dm, CD_MLOOPUV);
@@ -485,9 +485,8 @@ static void do_multires_bake(MultiresBakeRender *bkr,
Mesh *temp_mesh = BKE_mesh_new_nomain(
dm->getNumVerts(dm), dm->getNumEdges(dm), 0, dm->getNumLoops(dm), dm->getNumPolys(dm));
- memcpy(BKE_mesh_verts_for_write(temp_mesh),
- dm->getVertArray(dm),
- temp_mesh->totvert * sizeof(MVert));
+ memcpy(
+ BKE_mesh_positions_for_write(temp_mesh), positions, temp_mesh->totvert * sizeof(float[3]));
memcpy(BKE_mesh_edges_for_write(temp_mesh),
dm->getEdgeArray(dm),
temp_mesh->totedge * sizeof(MEdge));
@@ -503,7 +502,7 @@ static void do_multires_bake(MultiresBakeRender *bkr,
if (require_tangent) {
if (CustomData_get_layer_index(&dm->loopData, CD_TANGENT) == -1) {
BKE_mesh_calc_loop_tangent_ex(
- dm->getVertArray(dm),
+ positions,
dm->getPolyArray(dm),
dm->getNumPolys(dm),
dm->getLoopArray(dm),
@@ -555,7 +554,7 @@ static void do_multires_bake(MultiresBakeRender *bkr,
handle->data.mpoly = mpoly;
handle->data.material_indices = CustomData_get_layer_named(
&dm->polyData, CD_PROP_INT32, "material_index");
- handle->data.mvert = mvert;
+ handle->data.positions = positions;
handle->data.vert_normals = vert_normals;
handle->data.mloopuv = mloopuv;
BKE_image_get_tile_uv(ima, tile->tile_number, handle->data.uv_offset);
@@ -674,8 +673,7 @@ static void get_ccgdm_data(DerivedMesh *lodm,
mpoly = lodm->getPolyArray(lodm) + poly_index;
g_index = grid_offset[poly_index];
- S = mdisp_rot_face_to_crn(lodm->getVertArray(lodm),
- mpoly,
+ S = mdisp_rot_face_to_crn(mpoly,
lodm->getLoopArray(lodm),
lt,
face_side,
diff --git a/source/blender/render/intern/texture_margin.cc b/source/blender/render/intern/texture_margin.cc
index 3366111ed33..109e32875c5 100644
--- a/source/blender/render/intern/texture_margin.cc
+++ b/source/blender/render/intern/texture_margin.cc
@@ -515,8 +515,12 @@ static void generate_margin(ImBuf *ibuf,
tottri = poly_to_tri_count(me->totpoly, me->totloop);
looptri_mem = static_cast<MLoopTri *>(MEM_mallocN(sizeof(*looptri) * tottri, __func__));
- BKE_mesh_recalc_looptri(
- mloop, mpoly, me->verts().data(), me->totloop, me->totpoly, looptri_mem);
+ BKE_mesh_recalc_looptri(mloop,
+ mpoly,
+ reinterpret_cast<const float(*)[3]>(me->positions().data()),
+ me->totloop,
+ me->totpoly,
+ looptri_mem);
looptri = looptri_mem;
}
else {
diff --git a/source/blender/render/intern/texture_pointdensity.c b/source/blender/render/intern/texture_pointdensity.c
index 09173aaa0e3..5b716f87eaf 100644
--- a/source/blender/render/intern/texture_pointdensity.c
+++ b/source/blender/render/intern/texture_pointdensity.c
@@ -361,7 +361,6 @@ static void pointdensity_cache_object(PointDensity *pd, Object *ob)
{
float *data_color;
int i;
- const MVert *mvert = NULL, *mv;
Mesh *mesh = ob->data;
#if 0 /* UNUSED */
@@ -377,7 +376,7 @@ static void pointdensity_cache_object(PointDensity *pd, Object *ob)
}
#endif
- mvert = BKE_mesh_verts(mesh); /* local object space */
+ const float(*positions)[3] = BKE_mesh_positions(mesh); /* local object space */
pd->totpoints = mesh->totvert;
if (pd->totpoints == 0) {
return;
@@ -387,10 +386,10 @@ static void pointdensity_cache_object(PointDensity *pd, Object *ob)
alloc_point_data(pd);
point_data_pointers(pd, NULL, NULL, &data_color);
- for (i = 0, mv = mvert; i < pd->totpoints; i++, mv++) {
+ for (i = 0; i < pd->totpoints; i++) {
float co[3];
- copy_v3_v3(co, mv->co);
+ copy_v3_v3(co, positions[i]);
switch (pd->ob_cache_space) {
case TEX_PD_OBJECTSPACE:
diff --git a/source/blender/simulation/intern/hair_volume.cpp b/source/blender/simulation/intern/hair_volume.cpp
index 97042f433c2..3e221aa8588 100644
--- a/source/blender/simulation/intern/hair_volume.cpp
+++ b/source/blender/simulation/intern/hair_volume.cpp
@@ -1215,8 +1215,8 @@ static HairGridVert *hair_volume_create_collision_grid(ClothModifierData *clmd,
colliders = BKE_collider_cache_create(depsgraph, NULL, NULL);
if (colliders && collfac > 0.0f) {
for (col = colliders->first; col; col = col->next) {
- MVert *loc0 = col->collmd->x;
- MVert *loc1 = col->collmd->xnew;
+ float3 *loc0 = col->collmd->x;
+ float3 *loc1 = col->collmd->xnew;
float vel[3];
float weights[8];
int di, dj, dk;
diff --git a/source/tools b/source/tools
-Subproject dfa16042bf7149475ad318d29a8202d969982ab
+Subproject 2a541f164a222ef7bcd036d37687738acee8d94