diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index 1050a75e48c..b0c8f47a3a7 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -316,24 +316,10 @@ 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 *polys, const float (*vert_positions)[3], + int totvert, int totloop, int totpoly, struct MLoopTri *mlooptri); -/** - * A version of #BKE_mesh_recalc_looptri which takes pre-calculated polygon normals - * (used to avoid having to calculate the face normal for NGON tessellation). - * - * \note Only use this function if normals have already been calculated, there is no need - * to calculate normals just to use this function as it will cause the normals for triangles - * to be calculated which aren't needed for tessellation. - */ -void BKE_mesh_recalc_looptri_with_normals(const struct MLoop *mloop, - const struct MPoly *polys, - const float (*vert_positions)[3], - int totloop, - int totpoly, - struct MLoopTri *mlooptri, - const float (*poly_normals)[3]); /* *** mesh_normals.cc *** */ @@ -409,63 +395,17 @@ bool BKE_mesh_vert_normals_are_dirty(const struct Mesh *mesh); */ bool BKE_mesh_poly_normals_are_dirty(const struct Mesh *mesh); -void BKE_mesh_calc_poly_normal(const struct MPoly *polys, - const struct MLoop *loopstart, +void BKE_mesh_calc_poly_normal(const struct MLoop *poly_loops, + int poly_size, const float (*vert_positions)[3], + int verts_num, float r_no[3]); -/** - * Calculate face normals directly into a result array. - * - * \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 float (*vert_positions)[3], - int mvert_len, - const struct MLoop *mloop, - int mloop_len, - const struct MPoly *polys, - int polys_len, - float (*r_poly_normals)[3]); - -/** - * Calculate face and vertex normals directly into result arrays. - * - * \note Usually #BKE_mesh_vert_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 float (*vert_positions)[3], - int mvert_len, - const struct MLoop *mloop, - int mloop_len, - const struct MPoly *polys, - int polys_len, - float (*r_poly_normals)[3], - float (*r_vert_normals)[3]); - /** * Called after calculating all modifiers. */ void BKE_mesh_ensure_normals_for_display(struct Mesh *mesh); -/** - * Define sharp edges as needed to mimic 'autosmooth' from angle threshold. - * - * Used when defining an empty custom loop normals data layer, - * to keep same shading as with auto-smooth! - * - * \param sharp_faces: Optional array used to mark specific faces for sharp shading. - */ -void BKE_edges_sharp_from_angle_set(int numEdges, - const struct MLoop *mloops, - int numLoops, - const struct MPoly *polys, - const float (*poly_normals)[3], - const bool *sharp_faces, - int numPolys, - float split_angle, - bool *sharp_edges); - /** * References a contiguous loop-fan with normal offset vars. */ @@ -569,66 +509,6 @@ void BKE_lnor_space_custom_normal_to_data(const MLoopNorSpace *lnor_space, const float custom_lnor[3], short r_clnor_data[2]); -/* Medium-level custom normals functions. */ - -/** - * Compute split normals, i.e. vertex normals associated with each poly (hence 'loop normals'). - * Useful to materialize sharp edges (or non-smooth faces) without actually modifying the geometry - * (splitting edges). - * - * \param loop_to_poly_map: Optional pre-created map from loops to their polygon. - * \param sharp_faces: Optional array used to mark specific faces for sharp shading. - * \param sharp_edges: Optional array of sharp edge tags, used to split the evaluated normals on - * each side of the edge. - */ -void BKE_mesh_normals_loop_split(const float (*vert_positions)[3], - const float (*vert_normals)[3], - int numVerts, - const struct MEdge *edges, - int numEdges, - const struct MLoop *mloops, - float (*r_loop_normals)[3], - int numLoops, - const struct MPoly *polys, - const float (*poly_normals)[3], - int numPolys, - bool use_split_normals, - float split_angle, - const bool *sharp_edges, - const bool *sharp_faces, - const int *loop_to_poly_map, - MLoopNorSpaceArray *r_lnors_spacearr, - short (*clnors_data)[2]); - -void BKE_mesh_normals_loop_custom_set(const float (*vert_positions)[3], - const float (*vert_normals)[3], - int numVerts, - const struct MEdge *edges, - int numEdges, - const struct MLoop *mloops, - float (*r_custom_loop_normals)[3], - int numLoops, - const struct MPoly *polys, - const float (*poly_normals)[3], - const bool *sharp_faces, - int numPolys, - bool *sharp_edges, - short (*r_clnors_data)[2]); -void BKE_mesh_normals_loop_custom_from_verts_set(const float (*vert_positions)[3], - const float (*vert_normals)[3], - float (*r_custom_vert_normals)[3], - int numVerts, - const struct MEdge *edges, - int numEdges, - const struct MLoop *mloops, - int numLoops, - const struct MPoly *polys, - const float (*poly_normals)[3], - const bool *sharp_faces, - int numPolys, - bool *sharp_edges, - short (*r_clnors_data)[2]); - /** * Computes average per-vertex normals from given custom loop normals. * @@ -660,7 +540,7 @@ void BKE_mesh_calc_normals_split_ex(struct Mesh *mesh, /** * Higher level functions hiding most of the code needed around call to - * #BKE_mesh_normals_loop_custom_set(). + * #normals_loop_custom_set(). * * \param r_custom_loop_normals: is not const, since code will replace zero_v3 normals there * with automatically computed vectors. @@ -668,7 +548,7 @@ void BKE_mesh_calc_normals_split_ex(struct Mesh *mesh, void BKE_mesh_set_custom_normals(struct Mesh *mesh, float (*r_custom_loop_normals)[3]); /** * Higher level functions hiding most of the code needed around call to - * #BKE_mesh_normals_loop_custom_from_verts_set(). + * #normals_loop_custom_set_from_verts(). * * \param r_custom_vert_normals: is not const, since code will replace zero_v3 normals there * with automatically computed vectors. @@ -677,25 +557,22 @@ void BKE_mesh_set_custom_normals_from_verts(struct Mesh *mesh, float (*r_custom_ /* *** mesh_evaluate.cc *** */ -void BKE_mesh_calc_poly_center(const struct MPoly *poly, - const struct MLoop *loopstart, +void BKE_mesh_calc_poly_center(const struct MLoop *poly_loops, + int poly_size, const float (*vert_positions)[3], + int verts_num, 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 *poly, - const struct MLoop *loopstart, - const float (*vert_positions)[3]); +float BKE_mesh_calc_poly_area(const struct MLoop *poly_loops, + int poly_size, + const float (*vert_positions)[3], + int verts_num); float BKE_mesh_calc_area(const struct Mesh *me); -void BKE_mesh_calc_poly_angles(const struct MPoly *poly, - const struct MLoop *loopstart, - const float (*vert_positions)[3], - float angles[]); void BKE_mesh_poly_edgehash_insert(struct EdgeHash *ehash, - const struct MPoly *mp, + const struct MPoly *poly, const struct MLoop *mloop); void BKE_mesh_poly_edgebitmap_insert(unsigned int *edge_bitmap, - const struct MPoly *mp, + const struct MPoly *poly, const struct MLoop *mloop); bool BKE_mesh_center_median(const struct Mesh *me, float r_cent[3]); @@ -988,73 +865,4 @@ BLI_INLINE MDeformVert *BKE_mesh_deform_verts_for_write(Mesh *mesh) } #endif -#ifdef __cplusplus - -# include "BLI_math_vector_types.hh" -# include "BLI_span.hh" - -inline blender::Span Mesh::vert_positions() const -{ - return {reinterpret_cast(BKE_mesh_vert_positions(this)), this->totvert}; -} -inline blender::MutableSpan Mesh::vert_positions_for_write() -{ - return {reinterpret_cast(BKE_mesh_vert_positions_for_write(this)), - this->totvert}; -} - -inline blender::Span Mesh::edges() const -{ - return {BKE_mesh_edges(this), this->totedge}; -} -inline blender::MutableSpan Mesh::edges_for_write() -{ - return {BKE_mesh_edges_for_write(this), this->totedge}; -} - -inline blender::Span Mesh::polys() const -{ - return {BKE_mesh_polys(this), this->totpoly}; -} -inline blender::MutableSpan Mesh::polys_for_write() -{ - return {BKE_mesh_polys_for_write(this), this->totpoly}; -} - -inline blender::Span Mesh::loops() const -{ - return {BKE_mesh_loops(this), this->totloop}; -} -inline blender::MutableSpan Mesh::loops_for_write() -{ - return {BKE_mesh_loops_for_write(this), this->totloop}; -} - -inline blender::Span Mesh::deform_verts() const -{ - const MDeformVert *dverts = BKE_mesh_deform_verts(this); - if (!dverts) { - return {}; - } - return {dverts, this->totvert}; -} -inline blender::MutableSpan Mesh::deform_verts_for_write() -{ - return {BKE_mesh_deform_verts_for_write(this), this->totvert}; -} - -inline blender::Span Mesh::poly_normals() const -{ - return {reinterpret_cast(BKE_mesh_poly_normals_ensure(this)), - this->totpoly}; -} - -inline blender::Span Mesh::vert_normals() const -{ - return {reinterpret_cast(BKE_mesh_vert_normals_ensure(this)), - this->totvert}; -} - -#endif - /** \} */ diff --git a/source/blender/blenkernel/BKE_mesh.hh b/source/blender/blenkernel/BKE_mesh.hh new file mode 100644 index 00000000000..bc024b605b1 --- /dev/null +++ b/source/blender/blenkernel/BKE_mesh.hh @@ -0,0 +1,211 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later. */ + +#pragma once + +/** \file + * \ingroup bke + */ + +#include "BKE_mesh.h" + +namespace blender::bke::mesh { + +/* -------------------------------------------------------------------- */ +/** \name Polygon Data Evaluation + * \{ */ + +/** Calculate the up direction for the polygon, depending on its winding direction. */ +float3 poly_normal_calc(Span vert_positions, Span poly_loops); + +/** + * Calculate tessellation into #MLoopTri which exist only for this purpose. + */ +void looptris_calc(Span vert_positions, + Span polys, + Span loops, + MutableSpan looptris); +/** + * A version of #looptris_calc which takes pre-calculated polygon normals + * (used to avoid having to calculate the face normal for NGON tessellation). + * + * \note Only use this function if normals have already been calculated, there is no need + * to calculate normals just to use this function. + */ +void looptris_calc_with_normals(Span vert_positions, + Span polys, + Span loops, + Span poly_normals, + MutableSpan looptris); + +/** Calculate the average position of the vertices in the polygon. */ +float3 poly_center_calc(Span vert_positions, Span poly_loops); + +/** Calculate the surface area of the polygon described by the indexed vertices. */ +float poly_area_calc(Span vert_positions, Span poly_loops); + +/** Calculate the angles at each of the polygons's corners. */ +void poly_angles_calc(Span vert_positions, + Span poly_loops, + MutableSpan angles); + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Medium-Level Normals Calculation + * \{ */ + +/** + * Calculate face normals directly into a result array. + * + * \note Usually #Mesh::poly_normals() is the preferred way to access face normals, + * since they may already be calculated and cached on the mesh. + */ +void normals_calc_polys(Span vert_positions, + Span polys, + Span loops, + MutableSpan poly_normals); + +/** + * Calculate face and vertex normals directly into result arrays. + * + * \note Usually #Mesh::vert_normals() is the preferred way to access vertex normals, + * since they may already be calculated and cached on the mesh. + */ +void normals_calc_poly_vert(Span vert_positions, + Span polys, + Span loops, + MutableSpan poly_normals, + MutableSpan vert_normals); + +/** + * Compute split normals, i.e. vertex normals associated with each poly (hence 'loop normals'). + * Useful to materialize sharp edges (or non-smooth faces) without actually modifying the geometry + * (splitting edges). + * + * \param loop_to_poly_map: Optional pre-created map from loops to their polygon. + * \param sharp_edges: Optional array of sharp edge tags, used to split the evaluated normals on + * each side of the edge. + */ +void normals_calc_loop(Span vert_positions, + Span edges, + Span polys, + Span loops, + Span loop_to_poly_map, + Span vert_normals, + Span poly_normals, + const bool *sharp_edges, + const bool *sharp_faces, + bool use_split_normals, + float split_angle, + short (*clnors_data)[2], + MLoopNorSpaceArray *r_lnors_spacearr, + MutableSpan r_loop_normals); + +void normals_loop_custom_set(Span vert_positions, + Span edges, + Span polys, + Span loops, + Span vert_normals, + Span poly_normals, + const bool *sharp_faces, + MutableSpan sharp_edges, + MutableSpan r_custom_loop_normals, + short (*r_clnors_data)[2]); + +void normals_loop_custom_set_from_verts(Span vert_positions, + Span edges, + Span polys, + Span loops, + Span vert_normals, + Span poly_normals, + const bool *sharp_faces, + MutableSpan sharp_edges, + MutableSpan r_custom_vert_normals, + short (*r_clnors_data)[2]); + +/** + * Define sharp edges as needed to mimic 'autosmooth' from angle threshold. + * + * Used when defining an empty custom loop normals data layer, + * to keep same shading as with auto-smooth! + * + * \param sharp_faces: Optional array used to mark specific faces for sharp shading. + */ +void edges_sharp_from_angle_set(Span polys, + Span loops, + Span poly_normals, + const bool *sharp_faces, + const float split_angle, + MutableSpan sharp_edges); + +} // namespace blender::bke::mesh + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Inline Mesh Data Access + * \{ */ + +inline blender::Span Mesh::vert_positions() const +{ + return {reinterpret_cast(BKE_mesh_vert_positions(this)), this->totvert}; +} +inline blender::MutableSpan Mesh::vert_positions_for_write() +{ + return {reinterpret_cast(BKE_mesh_vert_positions_for_write(this)), + this->totvert}; +} + +inline blender::Span Mesh::edges() const +{ + return {BKE_mesh_edges(this), this->totedge}; +} +inline blender::MutableSpan Mesh::edges_for_write() +{ + return {BKE_mesh_edges_for_write(this), this->totedge}; +} + +inline blender::Span Mesh::polys() const +{ + return {BKE_mesh_polys(this), this->totpoly}; +} +inline blender::MutableSpan Mesh::polys_for_write() +{ + return {BKE_mesh_polys_for_write(this), this->totpoly}; +} + +inline blender::Span Mesh::loops() const +{ + return {BKE_mesh_loops(this), this->totloop}; +} +inline blender::MutableSpan Mesh::loops_for_write() +{ + return {BKE_mesh_loops_for_write(this), this->totloop}; +} + +inline blender::Span Mesh::deform_verts() const +{ + const MDeformVert *dverts = BKE_mesh_deform_verts(this); + if (!dverts) { + return {}; + } + return {dverts, this->totvert}; +} +inline blender::MutableSpan Mesh::deform_verts_for_write() +{ + return {BKE_mesh_deform_verts_for_write(this), this->totvert}; +} + +inline blender::Span Mesh::poly_normals() const +{ + return {reinterpret_cast(BKE_mesh_poly_normals_ensure(this)), + this->totpoly}; +} + +inline blender::Span Mesh::vert_normals() const +{ + return {reinterpret_cast(BKE_mesh_vert_normals_ensure(this)), + this->totvert}; +} + +/** \} */ diff --git a/source/blender/blenkernel/BKE_mesh_remap.h b/source/blender/blenkernel/BKE_mesh_remap.h index 7508821860c..0d3098f0c38 100644 --- a/source/blender/blenkernel/BKE_mesh_remap.h +++ b/source/blender/blenkernel/BKE_mesh_remap.h @@ -221,6 +221,7 @@ void BKE_mesh_remap_calc_polys_from_mesh(int mode, float ray_radius, const struct Mesh *mesh_dst, const float (*vert_positions_dst)[3], + int numverts_dst, const struct MLoop *loops_dst, const struct MPoly *polys_dst, int numpolys_dst, diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index eeb9c5be9ed..4387f567cd3 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -420,6 +420,7 @@ set(SRC BKE_mball.h BKE_mball_tessellate.h BKE_mesh.h + BKE_mesh.hh BKE_mesh_boolean_convert.hh BKE_mesh_fair.h BKE_mesh_iterators.h diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc index 61ca1b81771..2468b40f889 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.cc +++ b/source/blender/blenkernel/intern/DerivedMesh.cc @@ -42,7 +42,7 @@ #include "BKE_layer.h" #include "BKE_lib_id.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_iterators.h" #include "BKE_mesh_mapping.h" #include "BKE_mesh_runtime.h" @@ -1914,14 +1914,15 @@ static void mesh_init_origspace(Mesh *mesh) } else { const MLoop *l = &loops[poly.loopstart]; - float p_nor[3], co[3]; + float co[3]; float mat[3][3]; float min[2] = {FLT_MAX, FLT_MAX}, max[2] = {-FLT_MAX, -FLT_MAX}; float translate[2], scale[2]; - BKE_mesh_calc_poly_normal( - &poly, l, reinterpret_cast(positions.data()), p_nor); + const float3 p_nor = blender::bke::mesh::poly_normal_calc( + positions, loops.slice(poly.loopstart, poly.totloop)); + axis_dominant_v3_to_m3(mat, p_nor); vcos_2d.resize(poly.totloop); diff --git a/source/blender/blenkernel/intern/attribute.cc b/source/blender/blenkernel/intern/attribute.cc index 32d12e1af17..755998cd218 100644 --- a/source/blender/blenkernel/intern/attribute.cc +++ b/source/blender/blenkernel/intern/attribute.cc @@ -31,7 +31,7 @@ #include "BKE_curves.hh" #include "BKE_customdata.h" #include "BKE_editmesh.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_pointcloud.h" #include "BKE_report.h" diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc index 5996fd5f7ea..27357ad0f75 100644 --- a/source/blender/blenkernel/intern/attribute_access.cc +++ b/source/blender/blenkernel/intern/attribute_access.cc @@ -6,7 +6,7 @@ #include "BKE_customdata.h" #include "BKE_deform.h" #include "BKE_geometry_set.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_pointcloud.h" #include "BKE_type_conversions.hh" diff --git a/source/blender/blenkernel/intern/bvhutils.cc b/source/blender/blenkernel/intern/bvhutils.cc index 5a9d008ed88..feb2577e09f 100644 --- a/source/blender/blenkernel/intern/bvhutils.cc +++ b/source/blender/blenkernel/intern/bvhutils.cc @@ -24,7 +24,7 @@ #include "BKE_attribute.hh" #include "BKE_bvhutils.h" #include "BKE_editmesh.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "MEM_guardedalloc.h" diff --git a/source/blender/blenkernel/intern/cdderivedmesh.cc b/source/blender/blenkernel/intern/cdderivedmesh.cc index 37ad64f7f21..327a7d13ada 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.cc +++ b/source/blender/blenkernel/intern/cdderivedmesh.cc @@ -20,7 +20,7 @@ #include "BKE_cdderivedmesh.h" #include "BKE_curve.h" #include "BKE_editmesh.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_object.h" #include "BKE_paint.h" @@ -121,12 +121,11 @@ static void cdDM_recalc_looptri(DerivedMesh *dm) DM_ensure_looptri_data(dm); BLI_assert(totpoly == 0 || cddm->dm.looptris.array_wip != NULL); - BKE_mesh_recalc_looptri(cddm->mloop, - cddm->mpoly, - cddm->vert_positions, - totloop, - totpoly, - cddm->dm.looptris.array_wip); + blender::bke::mesh::looptris_calc( + {reinterpret_cast(cddm->vert_positions), dm->numVertData}, + {cddm->mpoly, totpoly}, + {cddm->mloop, totloop}, + {dm->looptris.array_wip, dm->looptris.num}); BLI_assert(cddm->dm.looptris.array == NULL); atomic_cas_ptr( diff --git a/source/blender/blenkernel/intern/cloth.cc b/source/blender/blenkernel/intern/cloth.cc index ae7ebb8f96f..cb007cce765 100644 --- a/source/blender/blenkernel/intern/cloth.cc +++ b/source/blender/blenkernel/intern/cloth.cc @@ -27,7 +27,7 @@ #include "BKE_effect.h" #include "BKE_global.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_modifier.h" #include "BKE_pointcache.h" diff --git a/source/blender/blenkernel/intern/crazyspace.cc b/source/blender/blenkernel/intern/crazyspace.cc index dc9dfc9f199..0f1cd0a2f06 100644 --- a/source/blender/blenkernel/intern/crazyspace.cc +++ b/source/blender/blenkernel/intern/crazyspace.cc @@ -24,7 +24,7 @@ #include "BKE_editmesh.h" #include "BKE_geometry_set.hh" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_wrapper.h" #include "BKE_modifier.h" #include "BKE_multires.h" diff --git a/source/blender/blenkernel/intern/curve_to_mesh_convert.cc b/source/blender/blenkernel/intern/curve_to_mesh_convert.cc index 33b20b85a45..d90da24f2b2 100644 --- a/source/blender/blenkernel/intern/curve_to_mesh_convert.cc +++ b/source/blender/blenkernel/intern/curve_to_mesh_convert.cc @@ -12,7 +12,7 @@ #include "BKE_curves.hh" #include "BKE_geometry_set.hh" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_curve_to_mesh.hh" diff --git a/source/blender/blenkernel/intern/data_transfer.cc b/source/blender/blenkernel/intern/data_transfer.cc index 303124d4106..3074d53083d 100644 --- a/source/blender/blenkernel/intern/data_transfer.cc +++ b/source/blender/blenkernel/intern/data_transfer.cc @@ -24,7 +24,7 @@ #include "BKE_customdata.h" #include "BKE_data_transfer.h" #include "BKE_deform.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_mesh_remap.h" #include "BKE_mesh_runtime.h" @@ -351,12 +351,6 @@ 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 float(*positions_dst)[3] = BKE_mesh_vert_positions(me_dst); - const int num_verts_dst = me_dst->totvert; - const blender::Span edges_dst = me_dst->edges(); - const blender::Span polys_dst = me_dst->polys(); - const blender::Span loops_dst = me_dst->loops(); CustomData *ldata_dst = &me_dst->ldata; const bool use_split_nors_dst = (me_dst->flag & ME_AUTOSMOOTH) != 0; @@ -366,17 +360,16 @@ static void data_transfer_dtdata_type_preprocess(Mesh *me_src, BLI_assert(CustomData_get_layer(&me_src->ldata, CD_NORMAL) != nullptr); (void)me_src; - float(*loop_nors_dst)[3]; short(*custom_nors_dst)[2] = static_cast( CustomData_get_layer_for_write(ldata_dst, CD_CUSTOMLOOPNORMAL, me_dst->totloop)); /* Cache loop nors into a temp CDLayer. */ - loop_nors_dst = static_cast( + blender::float3 *loop_nors_dst = static_cast( CustomData_get_layer_for_write(ldata_dst, CD_NORMAL, me_dst->totloop)); const bool do_loop_nors_dst = (loop_nors_dst == nullptr); if (do_loop_nors_dst) { - loop_nors_dst = static_cast( - CustomData_add_layer(ldata_dst, CD_NORMAL, CD_SET_DEFAULT, nullptr, loops_dst.size())); + loop_nors_dst = static_cast( + CustomData_add_layer(ldata_dst, CD_NORMAL, CD_SET_DEFAULT, nullptr, me_dst->totloop)); CustomData_set_layer_flag(ldata_dst, CD_NORMAL, CD_FLAG_TEMPORARY); } if (dirty_nors_dst || do_loop_nors_dst) { @@ -384,24 +377,20 @@ static void data_transfer_dtdata_type_preprocess(Mesh *me_src, CustomData_get_layer_named(&me_dst->edata, CD_PROP_BOOL, "sharp_edge")); const bool *sharp_faces = static_cast( CustomData_get_layer_named(&me_dst->pdata, CD_PROP_BOOL, "sharp_face")); - BKE_mesh_normals_loop_split(positions_dst, - BKE_mesh_vert_normals_ensure(me_dst), - num_verts_dst, - edges_dst.data(), - edges_dst.size(), - loops_dst.data(), - loop_nors_dst, - loops_dst.size(), - polys_dst.data(), - BKE_mesh_poly_normals_ensure(me_dst), - polys_dst.size(), - use_split_nors_dst, - split_angle_dst, - sharp_edges, - sharp_faces, - nullptr, - nullptr, - custom_nors_dst); + blender::bke::mesh::normals_calc_loop(me_dst->vert_positions(), + me_dst->edges(), + me_dst->polys(), + me_dst->loops(), + {}, + me_dst->vert_normals(), + me_dst->poly_normals(), + sharp_edges, + sharp_faces, + use_split_nors_dst, + split_angle_dst, + custom_nors_dst, + nullptr, + {loop_nors_dst, me_dst->totloop}); } } } @@ -418,47 +407,35 @@ static void data_transfer_dtdata_type_postprocess(Object * /*ob_src*/, if (!changed) { return; } - /* Bake edited destination loop normals into custom normals again. */ - const float(*positions_dst)[3] = BKE_mesh_vert_positions(me_dst); - const int num_verts_dst = me_dst->totvert; - const blender::Span edges_dst = me_dst->edges(); - blender::MutableSpan polys_dst = me_dst->polys_for_write(); - blender::MutableSpan loops_dst = me_dst->loops_for_write(); - CustomData *ldata_dst = &me_dst->ldata; - const float(*poly_nors_dst)[3] = BKE_mesh_poly_normals_ensure(me_dst); - float(*loop_nors_dst)[3] = static_cast( + blender::float3 *loop_nors_dst = static_cast( CustomData_get_layer_for_write(ldata_dst, CD_NORMAL, me_dst->totloop)); short(*custom_nors_dst)[2] = static_cast( CustomData_get_layer_for_write(ldata_dst, CD_CUSTOMLOOPNORMAL, me_dst->totloop)); if (!custom_nors_dst) { custom_nors_dst = static_cast(CustomData_add_layer( - ldata_dst, CD_CUSTOMLOOPNORMAL, CD_SET_DEFAULT, nullptr, loops_dst.size())); + ldata_dst, CD_CUSTOMLOOPNORMAL, CD_SET_DEFAULT, nullptr, me_dst->totloop)); } bke::MutableAttributeAccessor attributes = me_dst->attributes_for_write(); bke::SpanAttributeWriter sharp_edges = attributes.lookup_or_add_for_write_span( "sharp_edge", ATTR_DOMAIN_EDGE); - + const bool *sharp_faces = static_cast( + CustomData_get_layer_named(&me_dst->pdata, CD_PROP_BOOL, "sharp_face")); /* Note loop_nors_dst contains our custom normals as transferred from source... */ - BKE_mesh_normals_loop_custom_set(positions_dst, - BKE_mesh_vert_normals_ensure(me_dst), - num_verts_dst, - edges_dst.data(), - edges_dst.size(), - loops_dst.data(), - loop_nors_dst, - loops_dst.size(), - polys_dst.data(), - poly_nors_dst, - static_cast(CustomData_get_layer_named( - &me_dst->pdata, CD_PROP_BOOL, "sharp_face")), - polys_dst.size(), - sharp_edges.span.data(), - custom_nors_dst); + blender::bke::mesh::normals_loop_custom_set(me_dst->vert_positions(), + me_dst->edges(), + me_dst->polys(), + me_dst->loops(), + me_dst->vert_normals(), + me_dst->poly_normals(), + sharp_faces, + sharp_edges.span, + {loop_nors_dst, me_dst->totloop}, + custom_nors_dst); sharp_edges.finish(); } } @@ -1715,6 +1692,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, ray_radius, me_dst, positions_dst, + num_verts_dst, loops_dst.data(), polys_dst.data(), polys_dst.size(), diff --git a/source/blender/blenkernel/intern/deform.cc b/source/blender/blenkernel/intern/deform.cc index 15d37d13f30..362fcd56339 100644 --- a/source/blender/blenkernel/intern/deform.cc +++ b/source/blender/blenkernel/intern/deform.cc @@ -31,7 +31,7 @@ #include "BKE_customdata.h" #include "BKE_data_transfer.h" #include "BKE_deform.h" /* own include */ -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_object.h" #include "BKE_object_deform.h" diff --git a/source/blender/blenkernel/intern/displist.cc b/source/blender/blenkernel/intern/displist.cc index 6500cf830b2..738e657ecfa 100644 --- a/source/blender/blenkernel/intern/displist.cc +++ b/source/blender/blenkernel/intern/displist.cc @@ -36,7 +36,7 @@ #include "BKE_key.h" #include "BKE_lib_id.h" #include "BKE_mball.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_object.h" #include "BKE_vfont.h" diff --git a/source/blender/blenkernel/intern/dynamicpaint.cc b/source/blender/blenkernel/intern/dynamicpaint.cc index 514ab046b87..18957ca243b 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.cc +++ b/source/blender/blenkernel/intern/dynamicpaint.cc @@ -48,7 +48,7 @@ #include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_mesh_runtime.h" #include "BKE_modifier.h" diff --git a/source/blender/blenkernel/intern/editmesh.cc b/source/blender/blenkernel/intern/editmesh.cc index b586b4110f2..108852ad94d 100644 --- a/source/blender/blenkernel/intern/editmesh.cc +++ b/source/blender/blenkernel/intern/editmesh.cc @@ -19,7 +19,7 @@ #include "BKE_editmesh.h" #include "BKE_editmesh_cache.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_iterators.h" #include "BKE_mesh_wrapper.h" #include "BKE_object.h" diff --git a/source/blender/blenkernel/intern/editmesh_tangent.cc b/source/blender/blenkernel/intern/editmesh_tangent.cc index 6af839585f7..3c30a46c25f 100644 --- a/source/blender/blenkernel/intern/editmesh_tangent.cc +++ b/source/blender/blenkernel/intern/editmesh_tangent.cc @@ -14,7 +14,7 @@ #include "BKE_customdata.h" #include "BKE_editmesh.h" #include "BKE_editmesh_tangent.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_tangent.h" /* for utility functions */ #include "MEM_guardedalloc.h" diff --git a/source/blender/blenkernel/intern/fluid.cc b/source/blender/blenkernel/intern/fluid.cc index 130d02a7cd9..df50b1bce9f 100644 --- a/source/blender/blenkernel/intern/fluid.cc +++ b/source/blender/blenkernel/intern/fluid.cc @@ -56,7 +56,7 @@ # include "BKE_colortools.h" # include "BKE_customdata.h" # include "BKE_deform.h" -# include "BKE_mesh.h" +# include "BKE_mesh.hh" # include "BKE_mesh_runtime.h" # include "BKE_object.h" # include "BKE_particle.h" diff --git a/source/blender/blenkernel/intern/geometry_component_mesh.cc b/source/blender/blenkernel/intern/geometry_component_mesh.cc index 23c2bb3cc71..b5bc08039b2 100644 --- a/source/blender/blenkernel/intern/geometry_component_mesh.cc +++ b/source/blender/blenkernel/intern/geometry_component_mesh.cc @@ -12,7 +12,7 @@ #include "BKE_geometry_fields.hh" #include "BKE_geometry_set.hh" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "FN_multi_function_builder.hh" diff --git a/source/blender/blenkernel/intern/geometry_fields.cc b/source/blender/blenkernel/intern/geometry_fields.cc index fd07f7eceab..64a000ca4cf 100644 --- a/source/blender/blenkernel/intern/geometry_fields.cc +++ b/source/blender/blenkernel/intern/geometry_fields.cc @@ -7,7 +7,7 @@ #include "BKE_geometry_fields.hh" #include "BKE_geometry_set.hh" #include "BKE_instances.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_pointcloud.h" #include "BKE_type_conversions.hh" diff --git a/source/blender/blenkernel/intern/geometry_set.cc b/source/blender/blenkernel/intern/geometry_set.cc index 2417f8e2f73..3f5fadbe636 100644 --- a/source/blender/blenkernel/intern/geometry_set.cc +++ b/source/blender/blenkernel/intern/geometry_set.cc @@ -11,7 +11,7 @@ #include "BKE_geometry_set.hh" #include "BKE_instances.hh" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_wrapper.h" #include "BKE_modifier.h" #include "BKE_pointcloud.h" diff --git a/source/blender/blenkernel/intern/geometry_set_instances.cc b/source/blender/blenkernel/intern/geometry_set_instances.cc index 63f5ffe2740..e99efc19276 100644 --- a/source/blender/blenkernel/intern/geometry_set_instances.cc +++ b/source/blender/blenkernel/intern/geometry_set_instances.cc @@ -4,7 +4,7 @@ #include "BKE_geometry_set_instances.hh" #include "BKE_instances.hh" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_wrapper.h" #include "BKE_modifier.h" #include "BKE_pointcloud.h" diff --git a/source/blender/blenkernel/intern/gpencil_geom.cc b/source/blender/blenkernel/intern/gpencil_geom.cc index 3a7ba981aa6..7473d2b2c03 100644 --- a/source/blender/blenkernel/intern/gpencil_geom.cc +++ b/source/blender/blenkernel/intern/gpencil_geom.cc @@ -43,7 +43,7 @@ #include "BKE_gpencil_geom.h" #include "BKE_main.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "DEG_depsgraph_query.h" diff --git a/source/blender/blenkernel/intern/key.cc b/source/blender/blenkernel/intern/key.cc index 832fc3f1ece..ae29e681d50 100644 --- a/source/blender/blenkernel/intern/key.cc +++ b/source/blender/blenkernel/intern/key.cc @@ -42,7 +42,7 @@ #include "BKE_lib_id.h" #include "BKE_lib_query.h" #include "BKE_main.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_scene.h" #include "RNA_access.h" @@ -2258,23 +2258,19 @@ void BKE_keyblock_mesh_calc_normals(const KeyBlock *kb, } if (poly_normals_needed) { - BKE_mesh_calc_normals_poly(positions, - mesh->totvert, - loops.data(), - loops.size(), - polys.data(), - polys.size(), - poly_normals); + blender::bke::mesh::normals_calc_polys( + {reinterpret_cast(positions), mesh->totvert}, + polys, + loops, + {reinterpret_cast(poly_normals), polys.size()}); } if (vert_normals_needed) { - BKE_mesh_calc_normals_poly_and_vertex(positions, - mesh->totvert, - loops.data(), - loops.size(), - polys.data(), - polys.size(), - poly_normals, - vert_normals); + blender::bke::mesh::normals_calc_poly_vert( + {reinterpret_cast(positions), mesh->totvert}, + polys, + loops, + {reinterpret_cast(poly_normals), polys.size()}, + {reinterpret_cast(vert_normals), mesh->totvert}); } if (loop_normals_needed) { short(*clnors)[2] = static_cast(CustomData_get_layer_for_write( @@ -2283,24 +2279,21 @@ void BKE_keyblock_mesh_calc_normals(const KeyBlock *kb, CustomData_get_layer_named(&mesh->edata, CD_PROP_BOOL, "sharp_edge")); const bool *sharp_faces = static_cast( CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, "sharp_face")); - BKE_mesh_normals_loop_split(positions, - vert_normals, - mesh->totvert, - edges.data(), - mesh->totedge, - loops.data(), - r_loop_normals, - loops.size(), - polys.data(), - poly_normals, - polys.size(), - (mesh->flag & ME_AUTOSMOOTH) != 0, - mesh->smoothresh, - sharp_edges, - sharp_faces, - nullptr, - nullptr, - clnors); + blender::bke::mesh::normals_calc_loop( + {reinterpret_cast(positions), mesh->totvert}, + edges, + polys, + loops, + {}, + {reinterpret_cast(vert_normals), mesh->totvert}, + {reinterpret_cast(poly_normals), polys.size()}, + sharp_edges, + sharp_faces, + (mesh->flag & ME_AUTOSMOOTH) != 0, + mesh->smoothresh, + clnors, + nullptr, + {reinterpret_cast(r_loop_normals), loops.size()}); } if (free_vert_normals) { diff --git a/source/blender/blenkernel/intern/lib_remap_test.cc b/source/blender/blenkernel/intern/lib_remap_test.cc index d0175590047..43644eccb90 100644 --- a/source/blender/blenkernel/intern/lib_remap_test.cc +++ b/source/blender/blenkernel/intern/lib_remap_test.cc @@ -20,7 +20,7 @@ #include "BKE_lib_id.h" #include "BKE_lib_remap.h" #include "BKE_main.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_node.h" #include "BKE_object.h" #include "BKE_scene.h" diff --git a/source/blender/blenkernel/intern/material.cc b/source/blender/blenkernel/intern/material.cc index 070df777625..e9d61f4b549 100644 --- a/source/blender/blenkernel/intern/material.cc +++ b/source/blender/blenkernel/intern/material.cc @@ -56,7 +56,7 @@ #include "BKE_lib_query.h" #include "BKE_main.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_node.h" #include "BKE_node_runtime.hh" #include "BKE_object.h" diff --git a/source/blender/blenkernel/intern/mball.cc b/source/blender/blenkernel/intern/mball.cc index 3a5e3104b86..14065661367 100644 --- a/source/blender/blenkernel/intern/mball.cc +++ b/source/blender/blenkernel/intern/mball.cc @@ -48,7 +48,7 @@ #include "BKE_material.h" #include "BKE_mball.h" #include "BKE_mball_tessellate.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "BKE_scene.h" diff --git a/source/blender/blenkernel/intern/mball_tessellate.cc b/source/blender/blenkernel/intern/mball_tessellate.cc index c4f7178445b..e3b3ff2f637 100644 --- a/source/blender/blenkernel/intern/mball_tessellate.cc +++ b/source/blender/blenkernel/intern/mball_tessellate.cc @@ -30,7 +30,7 @@ #include "BKE_global.h" #include "BKE_lib_id.h" #include "BKE_mball_tessellate.h" /* own include */ -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "BKE_scene.h" diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc index 8beb5bdd04d..53dae345f36 100644 --- a/source/blender/blenkernel/intern/mesh.cc +++ b/source/blender/blenkernel/intern/mesh.cc @@ -50,7 +50,7 @@ #include "BKE_lib_query.h" #include "BKE_main.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_legacy_convert.h" #include "BKE_mesh_runtime.h" #include "BKE_mesh_wrapper.h" @@ -1854,29 +1854,22 @@ void BKE_mesh_calc_normals_split_ex(Mesh *mesh, CustomData_get_layer_named(&mesh->edata, CD_PROP_BOOL, "sharp_edge")); const bool *sharp_faces = static_cast( CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, "sharp_face")); - const Span positions = mesh->vert_positions(); - const Span edges = mesh->edges(); - const Span polys = mesh->polys(); - const Span loops = mesh->loops(); - BKE_mesh_normals_loop_split(reinterpret_cast(positions.data()), - BKE_mesh_vert_normals_ensure(mesh), - positions.size(), - edges.data(), - edges.size(), - loops.data(), - r_corner_normals, - loops.size(), - polys.data(), - BKE_mesh_poly_normals_ensure(mesh), - polys.size(), - use_split_normals, - split_angle, - sharp_edges, - sharp_faces, - nullptr, - r_lnors_spacearr, - clnors); + blender::bke::mesh::normals_calc_loop( + mesh->vert_positions(), + mesh->edges(), + mesh->polys(), + mesh->loops(), + {}, + mesh->vert_normals(), + mesh->poly_normals(), + sharp_edges, + sharp_faces, + use_split_normals, + split_angle, + clnors, + nullptr, + {reinterpret_cast(r_corner_normals), mesh->totloop}); } void BKE_mesh_calc_normals_split(Mesh *mesh) diff --git a/source/blender/blenkernel/intern/mesh_boolean_convert.cc b/source/blender/blenkernel/intern/mesh_boolean_convert.cc index 6aa9c55f223..089cb6a5332 100644 --- a/source/blender/blenkernel/intern/mesh_boolean_convert.cc +++ b/source/blender/blenkernel/intern/mesh_boolean_convert.cc @@ -12,7 +12,7 @@ #include "BKE_attribute.hh" #include "BKE_customdata.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_boolean_convert.hh" #include "BLI_alloca.h" @@ -547,11 +547,7 @@ static void get_poly2d_cos(const Mesh *me, const Span poly_loops = loops.slice(poly->loopstart, poly->totloop); /* Project coordinates to 2d in cos_2d, using normal as projection axis. */ - float axis_dominant[3]; - BKE_mesh_calc_poly_normal(poly, - &loops[poly->loopstart], - reinterpret_cast(positions.data()), - axis_dominant); + const float3 axis_dominant = bke::mesh::poly_normal_calc(positions, poly_loops); axis_dominant_v3_to_m3(r_axis_mat, axis_dominant); for (const int i : poly_loops.index_range()) { float3 co = positions[poly_loops[i].v]; diff --git a/source/blender/blenkernel/intern/mesh_calc_edges.cc b/source/blender/blenkernel/intern/mesh_calc_edges.cc index f186d89a4e5..e407559fd36 100644 --- a/source/blender/blenkernel/intern/mesh_calc_edges.cc +++ b/source/blender/blenkernel/intern/mesh_calc_edges.cc @@ -15,7 +15,7 @@ #include "BKE_attribute.hh" #include "BKE_customdata.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" namespace blender::bke::calc_edges { diff --git a/source/blender/blenkernel/intern/mesh_convert.cc b/source/blender/blenkernel/intern/mesh_convert.cc index e287109d47d..cfc6ba8fedf 100644 --- a/source/blender/blenkernel/intern/mesh_convert.cc +++ b/source/blender/blenkernel/intern/mesh_convert.cc @@ -40,7 +40,7 @@ #include "BKE_main.h" #include "BKE_material.h" #include "BKE_mball.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_mesh_wrapper.h" #include "BKE_modifier.h" diff --git a/source/blender/blenkernel/intern/mesh_debug.cc b/source/blender/blenkernel/intern/mesh_debug.cc index 6cf237a7c8c..04204f8ed93 100644 --- a/source/blender/blenkernel/intern/mesh_debug.cc +++ b/source/blender/blenkernel/intern/mesh_debug.cc @@ -23,7 +23,7 @@ # include "BKE_customdata.h" -# include "BKE_mesh.h" +# include "BKE_mesh.hh" # include "BLI_dynstr.h" diff --git a/source/blender/blenkernel/intern/mesh_evaluate.cc b/source/blender/blenkernel/intern/mesh_evaluate.cc index dbd39740cbf..f669487ce91 100644 --- a/source/blender/blenkernel/intern/mesh_evaluate.cc +++ b/source/blender/blenkernel/intern/mesh_evaluate.cc @@ -24,10 +24,9 @@ #include "BLI_utildefines.h" #include "BLI_virtual_array.hh" -#include "BKE_customdata.h" - #include "BKE_attribute.hh" -#include "BKE_mesh.h" +#include "BKE_customdata.h" +#include "BKE_mesh.hh" #include "BKE_multires.h" using blender::float3; @@ -39,65 +38,81 @@ using blender::VArray; /** \name Polygon Calculations * \{ */ -static void mesh_calc_ngon_center(const MPoly *poly, - const MLoop *loopstart, - const float (*positions)[3], - float cent[3]) +namespace blender::bke::mesh { + +static float3 poly_center_calc_ngon(const Span vert_positions, + const Span poly_loops) { - const float w = 1.0f / float(poly->totloop); + const float w = 1.0f / float(poly_loops.size()); - zero_v3(cent); - - for (int i = 0; i < poly->totloop; i++) { - madd_v3_v3fl(cent, positions[(loopstart++)->v], w); + float3 center(0); + for (const int i : poly_loops.index_range()) { + center += vert_positions[poly_loops[i].v] * w; } + return center; } -void BKE_mesh_calc_poly_center(const MPoly *poly, - const MLoop *loopstart, +float3 poly_center_calc(const Span vert_positions, const Span poly_loops) +{ + if (poly_loops.size() == 3) { + float3 center; + mid_v3_v3v3v3(center, + vert_positions[poly_loops[0].v], + vert_positions[poly_loops[1].v], + vert_positions[poly_loops[2].v]); + return center; + } + if (poly_loops.size() == 4) { + float3 center; + mid_v3_v3v3v3v3(center, + vert_positions[poly_loops[0].v], + vert_positions[poly_loops[1].v], + vert_positions[poly_loops[2].v], + vert_positions[poly_loops[3].v]); + return center; + } + return poly_center_calc_ngon(vert_positions, poly_loops); +} + +} // namespace blender::bke::mesh + +void BKE_mesh_calc_poly_center(const MLoop *poly_loops, + const int poly_size, const float (*vert_positions)[3], + const int verts_num, float r_cent[3]) { - if (poly->totloop == 3) { - mid_v3_v3v3v3(r_cent, - vert_positions[loopstart[0].v], - vert_positions[loopstart[1].v], - vert_positions[loopstart[2].v]); - } - else if (poly->totloop == 4) { - mid_v3_v3v3v3v3(r_cent, - vert_positions[loopstart[0].v], - vert_positions[loopstart[1].v], - vert_positions[loopstart[2].v], - vert_positions[loopstart[3].v]); - } - else { - mesh_calc_ngon_center(poly, loopstart, vert_positions, r_cent); - } + copy_v3_v3(r_cent, + blender::bke::mesh::poly_center_calc( + {reinterpret_cast(vert_positions), verts_num}, + {poly_loops, poly_size})); } -float BKE_mesh_calc_poly_area(const MPoly *poly, - const MLoop *loopstart, - const float (*vert_positions)[3]) +namespace blender::bke::mesh { + +float poly_area_calc(const Span vert_positions, const Span poly_loops) { - if (poly->totloop == 3) { - return area_tri_v3(vert_positions[loopstart[0].v], - vert_positions[loopstart[1].v], - vert_positions[loopstart[2].v]); + if (poly_loops.size() == 3) { + return area_tri_v3(vert_positions[poly_loops[0].v], + vert_positions[poly_loops[1].v], + vert_positions[poly_loops[2].v]); } - - const MLoop *l_iter = loopstart; - float(*vertexcos)[3] = (float(*)[3])BLI_array_alloca(vertexcos, size_t(poly->totloop)); - - /* pack vertex cos into an array for area_poly_v3 */ - for (int i = 0; i < poly->totloop; i++, l_iter++) { - copy_v3_v3(vertexcos[i], vert_positions[l_iter->v]); + Array poly_coords(poly_loops.size()); + for (const int i : poly_loops.index_range()) { + poly_coords[i] = vert_positions[poly_loops[i].v]; } + return area_poly_v3((const float(*)[3])poly_coords.data(), poly_loops.size()); +} - /* finally calculate the area */ - float area = area_poly_v3((const float(*)[3])vertexcos, uint(poly->totloop)); +} // namespace blender::bke::mesh - return area; +float BKE_mesh_calc_poly_area(const MLoop *poly_loops, + const int poly_size, + const float (*vert_positions)[3], + const int verts_num) +{ + return blender::bke::mesh::poly_area_calc( + {reinterpret_cast(vert_positions), verts_num}, {poly_loops, poly_size}); } float BKE_mesh_calc_area(const Mesh *me) @@ -108,14 +123,14 @@ float BKE_mesh_calc_area(const Mesh *me) float total_area = 0.0f; for (const MPoly &poly : polys) { - total_area += BKE_mesh_calc_poly_area( - &poly, &loops[poly.loopstart], reinterpret_cast(positions.data())); + total_area += blender::bke::mesh::poly_area_calc(positions, + loops.slice(poly.loopstart, poly.totloop)); } return total_area; } -static float UNUSED_FUNCTION(mesh_calc_poly_volume_centroid)(const MPoly *poly, - const MLoop *loopstart, +static float UNUSED_FUNCTION(mesh_calc_poly_volume_centroid)(const MLoop *poly_loops, + const int poly_size, const float (*positions)[3], float r_cent[3]) { @@ -124,11 +139,11 @@ static float UNUSED_FUNCTION(mesh_calc_poly_volume_centroid)(const MPoly *poly, zero_v3(r_cent); - v_pivot = positions[loopstart[0].v]; - v_step1 = positions[loopstart[1].v]; + v_pivot = positions[poly_loops[0].v]; + v_step1 = positions[poly_loops[1].v]; - for (int i = 2; i < poly->totloop; i++) { - const float *v_step2 = positions[loopstart[i].v]; + for (int i = 2; i < poly_size; i++) { + const float *v_step2 = positions[poly_loops[i].v]; /* Calculate the 6x volume of the tetrahedron formed by the 3 vertices * of the triangle and the origin as the fourth vertex */ @@ -151,26 +166,27 @@ static float UNUSED_FUNCTION(mesh_calc_poly_volume_centroid)(const MPoly *poly, return total_volume; } +namespace blender::bke::mesh { + /** * A version of mesh_calc_poly_volume_centroid that takes an initial reference center, * use this to increase numeric stability as the quality of the result becomes * very low quality as the value moves away from 0.0, see: #65986. */ -static float mesh_calc_poly_volume_centroid_with_reference_center(const MPoly *poly, - const MLoop *loopstart, - const Span positions, - const float reference_center[3], +static float mesh_calc_poly_volume_centroid_with_reference_center(const Span positions, + const Span poly_loops, + const float3 &reference_center, float r_cent[3]) { /* See: mesh_calc_poly_volume_centroid for comments. */ float v_pivot[3], v_step1[3]; float total_volume = 0.0f; zero_v3(r_cent); - 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 < poly->totloop; i++) { + sub_v3_v3v3(v_pivot, positions[poly_loops[0].v], reference_center); + sub_v3_v3v3(v_step1, positions[poly_loops[1].v], reference_center); + for (int i = 2; i < poly_loops.size(); i++) { float v_step2[3]; - sub_v3_v3v3(v_step2, positions[loopstart[i].v], reference_center); + sub_v3_v3v3(v_step2, positions[poly_loops[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++) { @@ -187,21 +203,22 @@ static float mesh_calc_poly_volume_centroid_with_reference_center(const MPoly *p * - This has the advantage over #mesh_calc_poly_volume_centroid * that it doesn't depend on solid geometry, instead it weights the surface by volume. */ -static float mesh_calc_poly_area_centroid(const MPoly *poly, - const MLoop *loopstart, - const float (*positions)[3], - float r_cent[3]) +static float poly_area_centroid_calc(const Span positions, + const Span poly_loops, + float r_cent[3]) { float total_area = 0.0f; - float v1[3], v2[3], v3[3], normal[3], tri_cent[3]; + float v1[3], v2[3], v3[3], tri_cent[3]; + + const float3 normal = blender::bke::mesh::poly_normal_calc(positions, poly_loops); + + copy_v3_v3(v1, positions[poly_loops[0].v]); + copy_v3_v3(v2, positions[poly_loops[1].v]); - BKE_mesh_calc_poly_normal(poly, 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 < poly->totloop; i++) { - copy_v3_v3(v3, positions[loopstart[i].v]); + for (int i = 2; i < poly_loops.size(); i++) { + copy_v3_v3(v3, positions[poly_loops[i].v]); float tri_area = area_tri_signed_v3(v1, v2, v3, normal); total_area += tri_area; @@ -217,24 +234,23 @@ static float mesh_calc_poly_area_centroid(const MPoly *poly, return total_area; } -void BKE_mesh_calc_poly_angles(const MPoly *poly, - const MLoop *loopstart, - const float (*vert_positions)[3], - float angles[]) +void poly_angles_calc(const Span vert_positions, + const Span poly_loops, + MutableSpan angles) { float nor_prev[3]; float nor_next[3]; - int i_this = poly->totloop - 1; + int i_this = poly_loops.size() - 1; int i_next = 0; sub_v3_v3v3( - nor_prev, vert_positions[loopstart[i_this - 1].v], vert_positions[loopstart[i_this].v]); + nor_prev, vert_positions[poly_loops[i_this - 1].v], vert_positions[poly_loops[i_this].v]); normalize_v3(nor_prev); - while (i_next < poly->totloop) { + while (i_next < poly_loops.size()) { sub_v3_v3v3( - nor_next, vert_positions[loopstart[i_this].v], vert_positions[loopstart[i_next].v]); + nor_next, vert_positions[poly_loops[i_this].v], vert_positions[poly_loops[i_next].v]); normalize_v3(nor_next); angles[i_this] = angle_normalized_v3v3(nor_prev, nor_next); @@ -245,6 +261,8 @@ void BKE_mesh_calc_poly_angles(const MPoly *poly, } } +} // namespace blender::bke::mesh + void BKE_mesh_poly_edgehash_insert(EdgeHash *ehash, const MPoly *poly, const MLoop *mloop) { const MLoop *ml, *ml_next; @@ -332,7 +350,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 float(*positions)[3] = BKE_mesh_vert_positions(me); + const Span positions = me->vert_positions(); const blender::Span polys = me->polys(); const blender::Span loops = me->loops(); @@ -340,8 +358,8 @@ bool BKE_mesh_center_of_surface(const Mesh *me, float r_cent[3]) /* calculate a weighted average of polygon centroids */ for (const int i : polys.index_range()) { - poly_area = mesh_calc_poly_area_centroid( - &polys[i], &loops[polys[i].loopstart], positions, poly_cent); + poly_area = blender::bke::mesh::poly_area_centroid_calc( + positions, loops.slice(polys[i].loopstart, polys[i].totloop), poly_cent); madd_v3_v3fl(r_cent, poly_cent, poly_area); total_area += poly_area; @@ -376,8 +394,8 @@ bool BKE_mesh_center_of_volume(const Mesh *me, float r_cent[3]) /* calculate a weighted average of polyhedron centroids */ for (const int i : polys.index_range()) { - poly_volume = mesh_calc_poly_volume_centroid_with_reference_center( - &polys[i], &loops[polys[i].loopstart], positions, init_cent, poly_cent); + poly_volume = blender::bke::mesh::mesh_calc_poly_volume_centroid_with_reference_center( + positions, loops.slice(polys[i].loopstart, polys[i].totloop), 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); diff --git a/source/blender/blenkernel/intern/mesh_fair.cc b/source/blender/blenkernel/intern/mesh_fair.cc index 419be52afe0..b7e5fdc8104 100644 --- a/source/blender/blenkernel/intern/mesh_fair.cc +++ b/source/blender/blenkernel/intern/mesh_fair.cc @@ -16,7 +16,7 @@ #include "BKE_lib_id.h" #include "BKE_lib_query.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_fair.h" #include "BKE_mesh_mapping.h" diff --git a/source/blender/blenkernel/intern/mesh_iterators.cc b/source/blender/blenkernel/intern/mesh_iterators.cc index 0dc3d77cb8e..501783a8b0b 100644 --- a/source/blender/blenkernel/intern/mesh_iterators.cc +++ b/source/blender/blenkernel/intern/mesh_iterators.cc @@ -12,7 +12,7 @@ #include "BKE_customdata.h" #include "BKE_editmesh.h" #include "BKE_editmesh_cache.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_iterators.h" #include "BLI_bitmap.h" @@ -233,6 +233,7 @@ void BKE_mesh_foreach_mapped_face_center( void *userData, MeshForeachFlag flag) { + using namespace blender; if (mesh->edit_mesh != nullptr && mesh->runtime->edit_data != nullptr) { BMEditMesh *em = mesh->edit_mesh; BMesh *bm = em->bm; @@ -267,11 +268,9 @@ void BKE_mesh_foreach_mapped_face_center( } } else { - const float(*positions)[3] = BKE_mesh_vert_positions(mesh); + const blender::Span positions = mesh->vert_positions(); const blender::Span polys = mesh->polys(); const blender::Span loops = mesh->loops(); - float _no_buf[3]; - float *no = (flag & MESH_FOREACH_USE_NORMAL) ? _no_buf : nullptr; const int *index = static_cast(CustomData_get_layer(&mesh->pdata, CD_ORIGINDEX)); if (index) { @@ -280,22 +279,28 @@ void BKE_mesh_foreach_mapped_face_center( if (orig == ORIGINDEX_NONE) { continue; } - float cent[3]; - BKE_mesh_calc_poly_center(&polys[i], &loops[polys[i].loopstart], positions, cent); + const Span poly_loops = loops.slice(polys[i].loopstart, polys[i].totloop); + const float3 center = bke::mesh::poly_center_calc(positions, poly_loops); if (flag & MESH_FOREACH_USE_NORMAL) { - BKE_mesh_calc_poly_normal(&polys[i], &loops[polys[i].loopstart], positions, no); + const float3 normal = bke::mesh::poly_normal_calc(positions, poly_loops); + func(userData, orig, center, normal); + } + else { + func(userData, orig, center, nullptr); } - func(userData, orig, cent, no); } } else { for (const int i : polys.index_range()) { - float cent[3]; - BKE_mesh_calc_poly_center(&polys[i], &loops[polys[i].loopstart], positions, cent); + const Span poly_loops = loops.slice(polys[i].loopstart, polys[i].totloop); + const float3 center = bke::mesh::poly_center_calc(positions, poly_loops); if (flag & MESH_FOREACH_USE_NORMAL) { - BKE_mesh_calc_poly_normal(&polys[i], &loops[polys[i].loopstart], positions, no); + const float3 normal = bke::mesh::poly_normal_calc(positions, poly_loops); + func(userData, i, center, normal); + } + else { + func(userData, i, center, nullptr); } - func(userData, i, cent, no); } } } diff --git a/source/blender/blenkernel/intern/mesh_legacy_convert.cc b/source/blender/blenkernel/intern/mesh_legacy_convert.cc index 66d02bc3a95..1f11c3b4e8d 100644 --- a/source/blender/blenkernel/intern/mesh_legacy_convert.cc +++ b/source/blender/blenkernel/intern/mesh_legacy_convert.cc @@ -27,7 +27,7 @@ #include "BKE_attribute.hh" #include "BKE_customdata.h" #include "BKE_global.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_legacy_convert.h" #include "BKE_multires.h" diff --git a/source/blender/blenkernel/intern/mesh_merge_customdata.cc b/source/blender/blenkernel/intern/mesh_merge_customdata.cc index 5cba0c5ecce..b0eaa53d345 100644 --- a/source/blender/blenkernel/intern/mesh_merge_customdata.cc +++ b/source/blender/blenkernel/intern/mesh_merge_customdata.cc @@ -15,7 +15,7 @@ #include "BLI_utildefines.h" #include "BKE_customdata.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BLI_memarena.h" diff --git a/source/blender/blenkernel/intern/mesh_mirror.cc b/source/blender/blenkernel/intern/mesh_mirror.cc index 1baa7f97b3e..3d8ea9223a6 100644 --- a/source/blender/blenkernel/intern/mesh_mirror.cc +++ b/source/blender/blenkernel/intern/mesh_mirror.cc @@ -5,6 +5,7 @@ * \ingroup bke */ +#include "BLI_array.hh" #include "BLI_math.h" #include "DNA_mesh_types.h" @@ -14,7 +15,7 @@ #include "BKE_deform.h" #include "BKE_lib_id.h" #include "BKE_lib_query.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mirror.h" #include "BKE_modifier.h" @@ -372,8 +373,7 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd, /* handle custom split normals */ if (ob->type == OB_MESH && (((Mesh *)ob->data)->flag & ME_AUTOSMOOTH) && CustomData_has_layer(&result->ldata, CD_CUSTOMLOOPNORMAL) && result->totpoly > 0) { - float(*loop_normals)[3] = static_cast( - MEM_calloc_arrayN(size_t(result->totloop), sizeof(*loop_normals), __func__)); + blender::Array loop_normals(result_loops.size()); CustomData *ldata = &result->ldata; short(*clnors)[2] = static_cast( CustomData_get_layer_for_write(ldata, CD_CUSTOMLOOPNORMAL, result->totloop)); @@ -391,24 +391,20 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd, CustomData_get_layer_named(&result->edata, CD_PROP_BOOL, "sharp_edge")); const bool *sharp_faces = static_cast( CustomData_get_layer_named(&result->pdata, CD_PROP_BOOL, "sharp_face")); - BKE_mesh_normals_loop_split(BKE_mesh_vert_positions(result), - BKE_mesh_vert_normals_ensure(result), - result->totvert, - result_edges.data(), - result_edges.size(), - result_loops.data(), - loop_normals, - result_loops.size(), - result_polys.data(), - BKE_mesh_poly_normals_ensure(result), - result_polys.size(), - true, - result->smoothresh, - sharp_edges, - sharp_faces, - nullptr, - &lnors_spacearr, - clnors); + blender::bke::mesh::normals_calc_loop(result->vert_positions(), + result_edges, + result_polys, + result_loops, + {}, + result->vert_normals(), + result->poly_normals(), + sharp_edges, + sharp_faces, + true, + result->smoothresh, + clnors, + &lnors_spacearr, + loop_normals); /* mirroring has to account for loops being reversed in polys in second half */ for (const int i : src_polys.index_range()) { @@ -427,7 +423,6 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd, } } - MEM_freeN(loop_normals); BKE_lnor_spacearr_free(&lnors_spacearr); } diff --git a/source/blender/blenkernel/intern/mesh_normals.cc b/source/blender/blenkernel/intern/mesh_normals.cc index da36b298673..1e4da06c76a 100644 --- a/source/blender/blenkernel/intern/mesh_normals.cc +++ b/source/blender/blenkernel/intern/mesh_normals.cc @@ -21,7 +21,7 @@ #include "BLI_linklist.h" #include "BLI_linklist_stack.h" #include "BLI_math.h" -#include "BLI_math_vector_types.hh" +#include "BLI_math_vector.hh" #include "BLI_memarena.h" #include "BLI_span.hh" #include "BLI_stack.h" @@ -34,7 +34,7 @@ #include "BKE_customdata.h" #include "BKE_editmesh_cache.h" #include "BKE_global.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "atomic_ops.h" @@ -158,6 +158,8 @@ bool BKE_mesh_poly_normals_are_dirty(const Mesh *mesh) /** \name Mesh Normal Calculation (Polygons) * \{ */ +namespace blender::bke::mesh { + /* * COMPUTE POLY NORMAL * @@ -165,88 +167,77 @@ bool BKE_mesh_poly_normals_are_dirty(const Mesh *mesh) * polygon See Graphics Gems for * computing newell normal. */ -static void mesh_calc_ngon_normal(const MPoly *poly, - const MLoop *loopstart, - const float (*positions)[3], - float r_normal[3]) +static float3 normal_calc_ngon(const Span vert_positions, const Span poly_loops) { - const int nverts = poly->totloop; - const float *v_prev = positions[loopstart[nverts - 1].v]; - const float *v_curr; - - zero_v3(r_normal); + float3 normal(0); /* Newell's Method */ - for (int i = 0; i < nverts; i++) { - v_curr = positions[loopstart[i].v]; - add_newell_cross_v3_v3v3(r_normal, v_prev, v_curr); + const float *v_prev = vert_positions[poly_loops.last().v]; + for (const int i : poly_loops.index_range()) { + const float *v_curr = vert_positions[poly_loops[i].v]; + add_newell_cross_v3_v3v3(normal, v_prev, v_curr); v_prev = v_curr; } - if (UNLIKELY(normalize_v3(r_normal) == 0.0f)) { - r_normal[2] = 1.0f; /* other axis set to 0.0 */ + if (UNLIKELY(normalize_v3(normal) == 0.0f)) { + normal[2] = 1.0f; /* other axis set to 0.0 */ } + + return normal; } -void BKE_mesh_calc_poly_normal(const MPoly *poly, - const MLoop *loopstart, +float3 poly_normal_calc(const Span vert_positions, const Span poly_loops) +{ + if (poly_loops.size() > 4) { + return normal_calc_ngon(vert_positions, poly_loops); + } + if (poly_loops.size() == 3) { + return math::normal_tri(vert_positions[poly_loops[0].v], + vert_positions[poly_loops[1].v], + vert_positions[poly_loops[2].v]); + } + if (poly_loops.size() == 4) { + float3 normal; + normal_quad_v3(normal, + vert_positions[poly_loops[0].v], + vert_positions[poly_loops[1].v], + vert_positions[poly_loops[2].v], + vert_positions[poly_loops[3].v]); + return normal; + } + /* horrible, two sided face! */ + return float3(0); +} + +} // namespace blender::bke::mesh + +void BKE_mesh_calc_poly_normal(const MLoop *poly_loops, + const int poly_size, const float (*vert_positions)[3], + const int verts_num, float r_no[3]) { - if (poly->totloop > 4) { - mesh_calc_ngon_normal(poly, loopstart, vert_positions, r_no); - } - else if (poly->totloop == 3) { - normal_tri_v3(r_no, - vert_positions[loopstart[0].v], - vert_positions[loopstart[1].v], - vert_positions[loopstart[2].v]); - } - else if (poly->totloop == 4) { - normal_quad_v3(r_no, - vert_positions[loopstart[0].v], - vert_positions[loopstart[1].v], - vert_positions[loopstart[2].v], - vert_positions[loopstart[3].v]); - } - else { /* horrible, two sided face! */ - r_no[0] = 0.0; - r_no[1] = 0.0; - r_no[2] = 1.0; - } + copy_v3_v3(r_no, + blender::bke::mesh::poly_normal_calc( + {reinterpret_cast(vert_positions), verts_num}, + {poly_loops, poly_size})); } -static void calculate_normals_poly(const Span positions, - const Span polys, - const Span loops, - MutableSpan poly_normals) +namespace blender::bke::mesh { + +void normals_calc_polys(const Span positions, + const Span polys, + const Span loops, + MutableSpan poly_normals) { - using namespace blender; threading::parallel_for(polys.index_range(), 1024, [&](const IndexRange range) { - for (const int poly_i : range) { - const MPoly &poly = polys[poly_i]; - BKE_mesh_calc_poly_normal(&poly, - &loops[poly.loopstart], - reinterpret_cast(positions.data()), - poly_normals[poly_i]); + for (const int i : range) { + const MPoly &poly = polys[i]; + poly_normals[i] = poly_normal_calc(positions, loops.slice(poly.loopstart, poly.totloop)); } }); } -void BKE_mesh_calc_normals_poly(const float (*vert_positions)[3], - const int verts_num, - const MLoop *mloop, - const int mloop_len, - const MPoly *polys, - int polys_len, - float (*r_poly_normals)[3]) -{ - calculate_normals_poly({reinterpret_cast(vert_positions), verts_num}, - {polys, polys_len}, - {mloop, mloop_len}, - {reinterpret_cast(r_poly_normals), polys_len}); -} - /** \} */ /* -------------------------------------------------------------------- */ @@ -256,13 +247,12 @@ void BKE_mesh_calc_normals_poly(const float (*vert_positions)[3], * meshes can slow down high-poly meshes. For details on performance, see D11993. * \{ */ -static void calculate_normals_poly_and_vert(const Span positions, - const Span polys, - const Span loops, - MutableSpan poly_normals, - MutableSpan vert_normals) +void normals_calc_poly_vert(const Span positions, + const Span polys, + const Span loops, + MutableSpan poly_normals, + MutableSpan vert_normals) { - using namespace blender; /* Zero the vertex normal array for accumulation. */ { @@ -281,7 +271,7 @@ static void calculate_normals_poly_and_vert(const Span positions, const int i_end = poly.totloop - 1; /* Polygon Normal and edge-vector. */ - /* Inline version of #BKE_mesh_calc_poly_normal, also does edge-vectors. */ + /* Inline version of #poly_normal_calc, also does edge-vectors. */ { zero_v3(pnor); /* Newell's Method */ @@ -346,21 +336,7 @@ static void calculate_normals_poly_and_vert(const Span positions, } } -void BKE_mesh_calc_normals_poly_and_vertex(const float (*vert_positions)[3], - const int mvert_len, - const MLoop *mloop, - const int mloop_len, - const MPoly *polys, - const int polys_len, - float (*r_poly_normals)[3], - float (*r_vert_normals)[3]) -{ - calculate_normals_poly_and_vert({reinterpret_cast(vert_positions), mvert_len}, - {polys, polys_len}, - {mloop, mloop_len}, - {reinterpret_cast(r_poly_normals), polys_len}, - {reinterpret_cast(r_vert_normals), mvert_len}); -} +} // namespace blender::bke::mesh /** \} */ @@ -397,15 +373,12 @@ const float (*BKE_mesh_vert_normals_ensure(const Mesh *mesh))[3] vert_normals = BKE_mesh_vert_normals_for_write(&mesh_mutable); poly_normals = BKE_mesh_poly_normals_for_write(&mesh_mutable); - - BKE_mesh_calc_normals_poly_and_vertex(reinterpret_cast(positions.data()), - positions.size(), - loops.data(), - loops.size(), - polys.data(), - polys.size(), - poly_normals, - vert_normals); + blender::bke::mesh::normals_calc_poly_vert( + positions, + polys, + loops, + {reinterpret_cast(poly_normals), mesh->totpoly}, + {reinterpret_cast(vert_normals), mesh->totvert}); BKE_mesh_vert_normals_clear_dirty(&mesh_mutable); BKE_mesh_poly_normals_clear_dirty(&mesh_mutable); @@ -441,14 +414,8 @@ const float (*BKE_mesh_poly_normals_ensure(const Mesh *mesh))[3] const Span loops = mesh_mutable.loops(); poly_normals = BKE_mesh_poly_normals_for_write(&mesh_mutable); - - BKE_mesh_calc_normals_poly(reinterpret_cast(positions.data()), - positions.size(), - loops.data(), - loops.size(), - polys.data(), - polys.size(), - poly_normals); + blender::bke::mesh::normals_calc_polys( + positions, polys, loops, {reinterpret_cast(poly_normals), mesh->totvert}); BKE_mesh_poly_normals_clear_dirty(&mesh_mutable); }); @@ -788,6 +755,8 @@ struct LoopSplitTaskDataCommon { /* See comment about edge_to_loops below. */ #define IS_EDGE_SHARP(_e2l) ELEM((_e2l)[1], INDEX_UNSET, INDEX_INVALID) +namespace blender::bke::mesh { + static void mesh_edges_sharp_tag(const Span polys, const Span loops, const Span loop_to_poly_map, @@ -799,7 +768,6 @@ static void mesh_edges_sharp_tag(const Span polys, MutableSpan edge_to_loops, MutableSpan r_sharp_edges) { - using namespace blender; const float split_angle_cos = check_angle ? cosf(split_angle) : -1.0f; auto poly_is_smooth = [&](const int poly_i) { return sharp_faces.is_empty() || !sharp_faces[poly_i]; @@ -860,40 +828,34 @@ static void mesh_edges_sharp_tag(const Span polys, } } -void BKE_edges_sharp_from_angle_set(const int numEdges, - const MLoop *mloops, - const int numLoops, - const MPoly *polys, - const float (*poly_normals)[3], - const bool *sharp_faces, - const int numPolys, - const float split_angle, - bool *sharp_edges) +void edges_sharp_from_angle_set(const Span polys, + const Span loops, + const Span poly_normals, + const bool *sharp_faces, + const float split_angle, + MutableSpan sharp_edges) { - using namespace blender; - using namespace blender::bke; if (split_angle >= float(M_PI)) { /* Nothing to do! */ return; } - /* Mapping edge -> loops. See #BKE_mesh_normals_loop_split for details. */ - Array edge_to_loops(numEdges, int2(0)); + /* Mapping edge -> loops. See #bke::mesh::normals_calc_loop for details. */ + Array edge_to_loops(sharp_edges.size(), int2(0)); /* Simple mapping from a loop to its polygon index. */ - const Array loop_to_poly = mesh_topology::build_loop_to_poly_map({polys, numPolys}, - numLoops); + const Array loop_to_poly = mesh_topology::build_loop_to_poly_map(polys, loops.size()); - mesh_edges_sharp_tag({polys, numPolys}, - {mloops, numLoops}, + mesh_edges_sharp_tag(polys, + loops, loop_to_poly, - {reinterpret_cast(poly_normals), numPolys}, - Span(sharp_faces, sharp_faces ? numPolys : 0), - Span(sharp_edges, numEdges), + poly_normals, + Span(sharp_faces, sharp_faces ? polys.size() : 0), + sharp_edges, true, split_angle, edge_to_loops, - {sharp_edges, numEdges}); + sharp_edges); } static void loop_manifold_fan_around_vert_next(const Span loops, @@ -1304,8 +1266,6 @@ static bool loop_split_generator_check_cyclic_smooth_fan(const Span mloop static void loop_split_generator(TaskPool *pool, LoopSplitTaskDataCommon *common_data) { - using namespace blender; - using namespace blender::bke; MLoopNorSpaceArray *lnors_spacearr = common_data->lnors_spacearr; const Span loops = common_data->loops; @@ -1440,27 +1400,21 @@ static void loop_split_generator(TaskPool *pool, LoopSplitTaskDataCommon *common } } -void BKE_mesh_normals_loop_split(const float (*vert_positions)[3], - const float (*vert_normals)[3], - const int numVerts, - const MEdge *edges, - const int numEdges, - const MLoop *mloops, - float (*r_loop_normals)[3], - const int numLoops, - const MPoly *polys, - const float (*poly_normals)[3], - const int numPolys, - const bool use_split_normals, - const float split_angle, - const bool *sharp_edges, - const bool *sharp_faces, - const int *loop_to_poly_map, - MLoopNorSpaceArray *r_lnors_spacearr, - short (*clnors_data)[2]) +void normals_calc_loop(const Span vert_positions, + const Span edges, + const Span polys, + const Span loops, + const Span loop_to_poly_map, + const Span vert_normals, + const Span poly_normals, + const bool *sharp_edges, + const bool *sharp_faces, + bool use_split_normals, + float split_angle, + short (*clnors_data)[2], + MLoopNorSpaceArray *r_lnors_spacearr, + MutableSpan r_loop_normals) { - using namespace blender; - using namespace blender::bke; /* For now this is not supported. * If we do not use split normals, we do not generate anything fancy! */ BLI_assert(use_split_normals || !(r_lnors_spacearr)); @@ -1472,12 +1426,10 @@ void BKE_mesh_normals_loop_split(const float (*vert_positions)[3], * since we may want to use loop_normals even when mesh's 'autosmooth' is disabled * (see e.g. mesh mapping code). As usual, we could handle that on case-by-case basis, * but simpler to keep it well confined here. */ - int poly_index; - - for (poly_index = 0; poly_index < numPolys; poly_index++) { - const MPoly &poly = polys[poly_index]; - int ml_index = poly.loopstart; - const int ml_index_end = ml_index + poly.totloop; + for (const int poly_index : polys.index_range()) { + const MPoly *poly = &polys[poly_index]; + int ml_index = poly->loopstart; + const int ml_index_end = ml_index + poly->totloop; const bool is_poly_flat = sharp_faces && sharp_faces[poly_index]; for (; ml_index < ml_index_end; ml_index++) { @@ -1485,7 +1437,7 @@ void BKE_mesh_normals_loop_split(const float (*vert_positions)[3], copy_v3_v3(r_loop_normals[ml_index], poly_normals[poly_index]); } else { - copy_v3_v3(r_loop_normals[ml_index], vert_normals[mloops[ml_index].v]); + copy_v3_v3(r_loop_normals[ml_index], vert_normals[loops[ml_index].v]); } } } @@ -1506,17 +1458,17 @@ void BKE_mesh_normals_loop_split(const float (*vert_positions)[3], * However, if needed, we can store the negated value of loop index instead of INDEX_INVALID * to retrieve the real value later in code). * Note also that loose edges always have both values set to 0! */ - Array edge_to_loops(numEdges, int2(0)); + Array edge_to_loops(edges.size(), int2(0)); /* Simple mapping from a loop to its polygon index. */ Span loop_to_poly; Array local_loop_to_poly_map; - if (loop_to_poly_map) { - loop_to_poly = {loop_to_poly_map, numLoops}; + if (loop_to_poly_map.is_empty()) { + local_loop_to_poly_map = mesh_topology::build_loop_to_poly_map(polys, loops.size()); + loop_to_poly = local_loop_to_poly_map; } else { - local_loop_to_poly_map = mesh_topology::build_loop_to_poly_map({polys, numPolys}, numLoops); - loop_to_poly = local_loop_to_poly_map; + loop_to_poly = loop_to_poly_map; } /* When using custom loop normals, disable the angle feature! */ @@ -1533,28 +1485,27 @@ void BKE_mesh_normals_loop_split(const float (*vert_positions)[3], r_lnors_spacearr = &_lnors_spacearr; } if (r_lnors_spacearr) { - BKE_lnor_spacearr_init(r_lnors_spacearr, numLoops, MLNOR_SPACEARR_LOOP_INDEX); + BKE_lnor_spacearr_init(r_lnors_spacearr, loops.size(), MLNOR_SPACEARR_LOOP_INDEX); } - const Span loops(mloops, numLoops); - /* Init data common to all tasks. */ LoopSplitTaskDataCommon common_data; common_data.lnors_spacearr = r_lnors_spacearr; - common_data.loop_normals = {reinterpret_cast(r_loop_normals), numLoops}; - common_data.clnors_data = {reinterpret_cast(clnors_data), clnors_data ? numLoops : 0}; - common_data.positions = {reinterpret_cast(vert_positions), numVerts}; - common_data.edges = {edges, numEdges}; - common_data.polys = {polys, numPolys}; + common_data.loop_normals = r_loop_normals; + common_data.clnors_data = {reinterpret_cast(clnors_data), + clnors_data ? loops.size() : 0}; + common_data.positions = vert_positions; + common_data.edges = edges; + common_data.polys = polys; common_data.loops = loops; common_data.edge_to_loops = edge_to_loops; common_data.loop_to_poly = loop_to_poly; - common_data.poly_normals = {reinterpret_cast(poly_normals), numPolys}; - common_data.vert_normals = {reinterpret_cast(vert_normals), numVerts}; + common_data.poly_normals = poly_normals; + common_data.vert_normals = vert_normals; /* Pre-populate all loop normals as if their verts were all smooth. * This way we don't have to compute those later! */ - threading::parallel_for(IndexRange(numPolys), 1024, [&](const IndexRange range) { + threading::parallel_for(polys.index_range(), 1024, [&](const IndexRange range) { for (const int poly_i : range) { const MPoly &poly = polys[poly_i]; for (const int loop_i : IndexRange(poly.loopstart, poly.totloop)) { @@ -1564,18 +1515,18 @@ void BKE_mesh_normals_loop_split(const float (*vert_positions)[3], }); /* This first loop check which edges are actually smooth, and compute edge vectors. */ - mesh_edges_sharp_tag({polys, numPolys}, + mesh_edges_sharp_tag(polys, loops, loop_to_poly, - {reinterpret_cast(poly_normals), numPolys}, - Span(sharp_faces, sharp_faces ? numPolys : 0), - Span(sharp_edges, sharp_edges ? numEdges : 0), + poly_normals, + Span(sharp_faces, sharp_faces ? polys.size() : 0), + Span(sharp_edges, sharp_edges ? edges.size() : 0), check_angle, split_angle, edge_to_loops, {}); - if (numLoops < LOOP_SPLIT_TASK_BLOCK_SIZE * 8) { + if (loops.size() < LOOP_SPLIT_TASK_BLOCK_SIZE * 8) { /* Not enough loops to be worth the whole threading overhead. */ loop_split_generator(nullptr, &common_data); } @@ -1609,36 +1560,28 @@ void BKE_mesh_normals_loop_split(const float (*vert_positions)[3], * r_custom_loop_normals 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 float (*positions)[3], - const float (*vert_normals)[3], - const int numVerts, - const MEdge *edges, - const int numEdges, - const MLoop *mloops, - float (*r_custom_loop_normals)[3], - const int numLoops, - const MPoly *polys, - const float (*poly_normals)[3], + +static void mesh_normals_loop_custom_set(Span positions, + Span edges, + Span polys, + Span loops, + Span vert_normals, + Span poly_normals, const bool *sharp_faces, - const int numPolys, + const bool use_vertices, + MutableSpan r_custom_loop_normals, MutableSpan sharp_edges, - short (*r_clnors_data)[2], - const bool use_vertices) + short (*r_clnors_data)[2]) { - using namespace blender; - using namespace blender::bke; - /* We *may* make that poor #BKE_mesh_normals_loop_split() even more complex by making it handling - * that feature too, would probably be more efficient in absolute. - * However, this function *is not* performance-critical, since it is mostly expected to be called - * by io add-ons when importing custom normals, and modifier - * (and perhaps from some editing tools later?). - * So better to keep some simplicity here, and just call #BKE_mesh_normals_loop_split() twice! */ + /* We *may* make that poor #bke::mesh::normals_calc_loop() even more complex by making it + * handling that feature too, would probably be more efficient in absolute. However, this + * function *is not* performance-critical, since it is mostly expected to be called by io add-ons + * when importing custom normals, and modifier (and perhaps from some editing tools later?). So + * better to keep some simplicity here, and just call #bke::mesh::normals_calc_loop() twice! */ MLoopNorSpaceArray lnors_spacearr = {nullptr}; - BitVector<> done_loops(numLoops, false); - float(*loop_normals)[3] = (float(*)[3])MEM_calloc_arrayN( - size_t(numLoops), sizeof(*loop_normals), __func__); - const Array loop_to_poly = mesh_topology::build_loop_to_poly_map({polys, numPolys}, - numLoops); + BitVector<> done_loops(loops.size(), false); + Array loop_normals(loops.size()); + const Array loop_to_poly = mesh_topology::build_loop_to_poly_map(polys, loops.size()); /* In this case we always consider split nors as ON, * and do not want to use angle to define smooth fans! */ const bool use_split_normals = true; @@ -1647,35 +1590,31 @@ static void mesh_normals_loop_custom_set(const float (*positions)[3], BLI_SMALLSTACK_DECLARE(clnors_data, short *); /* Compute current lnor spacearr. */ - BKE_mesh_normals_loop_split(positions, - vert_normals, - numVerts, - edges, - numEdges, - mloops, - loop_normals, - numLoops, - polys, - poly_normals, - numPolys, - use_split_normals, - split_angle, - sharp_edges.data(), - sharp_faces, - loop_to_poly.data(), - &lnors_spacearr, - nullptr); + normals_calc_loop(positions, + edges, + polys, + loops, + loop_to_poly, + vert_normals, + poly_normals, + sharp_edges.data(), + sharp_faces, + use_split_normals, + split_angle, + r_clnors_data, + &lnors_spacearr, + loop_normals); /* Set all given zero vectors to their default value. */ if (use_vertices) { - for (int i = 0; i < numVerts; i++) { + for (const int i : positions.index_range()) { if (is_zero_v3(r_custom_loop_normals[i])) { copy_v3_v3(r_custom_loop_normals[i], vert_normals[i]); } } } else { - for (int i = 0; i < numLoops; i++) { + for (const int i : loops.index_range()) { if (is_zero_v3(r_custom_loop_normals[i])) { copy_v3_v3(r_custom_loop_normals[i], loop_normals[i]); } @@ -1686,7 +1625,7 @@ static void mesh_normals_loop_custom_set(const float (*positions)[3], /* Now, check each current smooth fan (one lnor space per smooth fan!), * and if all its matching custom loop_normals are not (enough) equal, add sharp edges as needed. - * This way, next time we run BKE_mesh_normals_loop_split(), we'll get lnor spacearr/smooth fans + * This way, next time we run bke::mesh::normals_calc_loop(), we'll get lnor spacearr/smooth fans * matching given custom loop_normals. * Note this code *will never* unsharp edges! And quite obviously, * when we set custom normals per vertices, running this is absolutely useless. */ @@ -1694,7 +1633,7 @@ static void mesh_normals_loop_custom_set(const float (*positions)[3], done_loops.fill(true); } else { - for (int i = 0; i < numLoops; i++) { + for (const int i : loops.index_range()) { if (!lnors_spacearr.lspacearr[i]) { /* This should not happen in theory, but in some rare case (probably ugly geometry) * we can get some nullptr loopspacearr at this point. :/ @@ -1712,7 +1651,7 @@ static void mesh_normals_loop_custom_set(const float (*positions)[3], /* Notes: * - In case of mono-loop smooth fan, we have nothing to do. * - Loops in this linklist are ordered (in reversed order compared to how they were - * discovered by BKE_mesh_normals_loop_split(), but this is not a problem). + * discovered by bke::mesh::normals_calc_loop(), but this is not a problem). * Which means if we find a mismatching clnor, * we know all remaining loops will have to be in a new, different smooth fan/lnor space. * - In smooth fan case, we compare each clnor against a ref one, @@ -1723,13 +1662,13 @@ static void mesh_normals_loop_custom_set(const float (*positions)[3], continue; } - LinkNode *loops = lnors_spacearr.lspacearr[i]->loops; + LinkNode *loop_link = lnors_spacearr.lspacearr[i]->loops; const MLoop *prev_ml = nullptr; const float *org_nor = nullptr; - while (loops) { - const int lidx = POINTER_AS_INT(loops->link); - const MLoop *ml = &mloops[lidx]; + while (loop_link) { + const int lidx = POINTER_AS_INT(loop_link->link); + const MLoop *ml = &loops[lidx]; const int nidx = lidx; float *nor = r_custom_loop_normals[nidx]; @@ -1743,14 +1682,14 @@ static void mesh_normals_loop_custom_set(const float (*positions)[3], * since we do not allow reversed winding in a same smooth fan. */ const MPoly &poly = polys[loop_to_poly[lidx]]; const MLoop *mlp = - &mloops[(lidx == poly.loopstart) ? poly.loopstart + poly.totloop - 1 : lidx - 1]; + &loops[(lidx == poly.loopstart) ? poly.loopstart + poly.totloop - 1 : lidx - 1]; sharp_edges[(prev_ml->e == mlp->e) ? prev_ml->e : ml->e] = true; org_nor = nor; } prev_ml = ml; - loops = loops->next; + loop_link = loop_link->next; done_loops[lidx].set(); } @@ -1758,17 +1697,17 @@ static void mesh_normals_loop_custom_set(const float (*positions)[3], * otherwise we may miss some sharp edges here! * This is just a simplified version of above while loop. * See #45984. */ - loops = lnors_spacearr.lspacearr[i]->loops; - if (loops && org_nor) { - const int lidx = POINTER_AS_INT(loops->link); - const MLoop *ml = &mloops[lidx]; + loop_link = lnors_spacearr.lspacearr[i]->loops; + if (loop_link && org_nor) { + const int lidx = POINTER_AS_INT(loop_link->link); + const MLoop *ml = &loops[lidx]; const int nidx = lidx; float *nor = r_custom_loop_normals[nidx]; if (dot_v3v3(org_nor, nor) < LNOR_SPACE_TRIGO_THRESHOLD) { const MPoly &poly = polys[loop_to_poly[lidx]]; const MLoop *mlp = - &mloops[(lidx == poly.loopstart) ? poly.loopstart + poly.totloop - 1 : lidx - 1]; + &loops[(lidx == poly.loopstart) ? poly.loopstart + poly.totloop - 1 : lidx - 1]; sharp_edges[(prev_ml->e == mlp->e) ? prev_ml->e : ml->e] = true; } } @@ -1776,29 +1715,25 @@ static void mesh_normals_loop_custom_set(const float (*positions)[3], /* And now, recompute our new auto `loop_normals` and lnor spacearr! */ BKE_lnor_spacearr_clear(&lnors_spacearr); - BKE_mesh_normals_loop_split(positions, - vert_normals, - numVerts, - edges, - numEdges, - mloops, - loop_normals, - numLoops, - polys, - poly_normals, - numPolys, - use_split_normals, - split_angle, - sharp_edges.data(), - sharp_faces, - loop_to_poly.data(), - &lnors_spacearr, - nullptr); + normals_calc_loop(positions, + edges, + polys, + loops, + loop_to_poly, + vert_normals, + poly_normals, + sharp_edges.data(), + sharp_faces, + use_split_normals, + split_angle, + r_clnors_data, + &lnors_spacearr, + loop_normals); } /* And we just have to convert plain object-space custom normals to our * lnor space-encoded ones. */ - for (int i = 0; i < numLoops; i++) { + for (const int i : loops.index_range()) { if (!lnors_spacearr.lspacearr[i]) { done_loops[i].reset(); if (G.debug & G_DEBUG) { @@ -1812,10 +1747,10 @@ static void mesh_normals_loop_custom_set(const float (*positions)[3], /* Note we accumulate and average all custom normals in current smooth fan, * to avoid getting different clnors data (tiny differences in plain custom normals can * give rather huge differences in computed 2D factors). */ - LinkNode *loops = lnors_spacearr.lspacearr[i]->loops; + LinkNode *loop_link = lnors_spacearr.lspacearr[i]->loops; if (lnors_spacearr.lspacearr[i]->flags & MLNOR_SPACE_IS_SINGLE) { - BLI_assert(POINTER_AS_INT(loops) == i); - const int nidx = use_vertices ? int(mloops[i].v) : i; + BLI_assert(POINTER_AS_INT(loop_link) == i); + const int nidx = use_vertices ? int(loops[i].v) : i; float *nor = r_custom_loop_normals[nidx]; BKE_lnor_space_custom_normal_to_data(lnors_spacearr.lspacearr[i], nor, r_clnors_data[i]); @@ -1827,16 +1762,16 @@ static void mesh_normals_loop_custom_set(const float (*positions)[3], short clnor_data_tmp[2], *clnor_data; zero_v3(avg_nor); - while (loops) { - const int lidx = POINTER_AS_INT(loops->link); - const int nidx = use_vertices ? int(mloops[lidx].v) : lidx; + while (loop_link) { + const int lidx = POINTER_AS_INT(loop_link->link); + const int nidx = use_vertices ? int(loops[lidx].v) : lidx; float *nor = r_custom_loop_normals[nidx]; avg_nor_count++; add_v3_v3(avg_nor, nor); BLI_SMALLSTACK_PUSH(clnors_data, (short *)r_clnors_data[lidx]); - loops = loops->next; + loop_link = loop_link->next; done_loops[lidx].reset(); } @@ -1851,78 +1786,59 @@ static void mesh_normals_loop_custom_set(const float (*positions)[3], } } - MEM_freeN(loop_normals); BKE_lnor_spacearr_free(&lnors_spacearr); } -void BKE_mesh_normals_loop_custom_set(const float (*vert_positions)[3], - const float (*vert_normals)[3], - const int numVerts, - const MEdge *edges, - const int numEdges, - const MLoop *mloops, - float (*r_custom_loop_normals)[3], - const int numLoops, - const MPoly *polys, - const float (*poly_normals)[3], - const bool *sharp_faces, - const int numPolys, - bool *sharp_edges, - short (*r_clnors_data)[2]) +void normals_loop_custom_set(const Span vert_positions, + const Span edges, + const Span polys, + const Span loops, + const Span vert_normals, + const Span poly_normals, + const bool *sharp_faces, + MutableSpan sharp_edges, + MutableSpan r_custom_loop_normals, + short (*r_clnors_data)[2]) { mesh_normals_loop_custom_set(vert_positions, - vert_normals, - numVerts, edges, - numEdges, - mloops, - r_custom_loop_normals, - numLoops, polys, + loops, + vert_normals, poly_normals, sharp_faces, - numPolys, - {sharp_edges, numEdges}, - r_clnors_data, - false); + false, + r_custom_loop_normals, + sharp_edges, + r_clnors_data); } -void BKE_mesh_normals_loop_custom_from_verts_set(const float (*vert_positions)[3], - const float (*vert_normals)[3], - float (*r_custom_vert_normals)[3], - const int numVerts, - const MEdge *edges, - const int numEdges, - const MLoop *mloops, - const int numLoops, - const MPoly *polys, - const float (*poly_normals)[3], - const bool *sharp_faces, - const int numPolys, - bool *sharp_edges, - short (*r_clnors_data)[2]) +void normals_loop_custom_set_from_verts(const Span vert_positions, + const Span edges, + const Span polys, + const Span loops, + const Span vert_normals, + const Span poly_normals, + const bool *sharp_faces, + MutableSpan sharp_edges, + MutableSpan r_custom_vert_normals, + short (*r_clnors_data)[2]) { mesh_normals_loop_custom_set(vert_positions, - vert_normals, - numVerts, edges, - numEdges, - mloops, - r_custom_vert_normals, - numLoops, polys, + loops, + vert_normals, poly_normals, sharp_faces, - numPolys, - {sharp_edges, numEdges}, - r_clnors_data, - true); + true, + r_custom_vert_normals, + sharp_edges, + r_clnors_data); } static void mesh_set_custom_normals(Mesh *mesh, float (*r_custom_nors)[3], const bool use_vertices) { - using namespace blender; - using namespace blender::bke; short(*clnors)[2]; const int numloops = mesh->totloop; @@ -1935,41 +1851,38 @@ 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 positions = mesh->vert_positions(); - MutableSpan edges = mesh->edges_for_write(); - const Span polys = mesh->polys(); - const Span loops = mesh->loops(); MutableAttributeAccessor attributes = mesh->attributes_for_write(); SpanAttributeWriter sharp_edges = attributes.lookup_or_add_for_write_span( "sharp_edge", ATTR_DOMAIN_EDGE); const bool *sharp_faces = static_cast( CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, "sharp_face")); - mesh_normals_loop_custom_set(reinterpret_cast(positions.data()), - BKE_mesh_vert_normals_ensure(mesh), - positions.size(), - edges.data(), - edges.size(), - loops.data(), - r_custom_nors, - loops.size(), - polys.data(), - BKE_mesh_poly_normals_ensure(mesh), + + mesh_normals_loop_custom_set(mesh->vert_positions(), + mesh->edges(), + mesh->polys(), + mesh->loops(), + mesh->vert_normals(), + mesh->poly_normals(), sharp_faces, - polys.size(), + use_vertices, + {reinterpret_cast(r_custom_nors), + use_vertices ? mesh->totvert : mesh->totloop}, sharp_edges.span, - clnors, - use_vertices); + clnors); + sharp_edges.finish(); } +} // namespace blender::bke::mesh + void BKE_mesh_set_custom_normals(Mesh *mesh, float (*r_custom_loop_normals)[3]) { - mesh_set_custom_normals(mesh, r_custom_loop_normals, false); + blender::bke::mesh::mesh_set_custom_normals(mesh, r_custom_loop_normals, false); } void BKE_mesh_set_custom_normals_from_verts(Mesh *mesh, float (*r_custom_vert_normals)[3]) { - mesh_set_custom_normals(mesh, r_custom_vert_normals, true); + blender::bke::mesh::mesh_set_custom_normals(mesh, r_custom_vert_normals, true); } void BKE_mesh_normals_loop_to_vertex(const int numVerts, diff --git a/source/blender/blenkernel/intern/mesh_remap.cc b/source/blender/blenkernel/intern/mesh_remap.cc index 733f649a4d6..4e4a7aa12b2 100644 --- a/source/blender/blenkernel/intern/mesh_remap.cc +++ b/source/blender/blenkernel/intern/mesh_remap.cc @@ -26,7 +26,7 @@ #include "BKE_bvhutils.h" #include "BKE_customdata.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_mesh_remap.h" /* own include */ #include "BKE_mesh_runtime.h" @@ -1043,9 +1043,9 @@ 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 float (*positions)[3], - const MPoly *polys, - const MLoop *loops, + const blender::Span positions, + const blender::Span polys, + const blender::Span loops, const int edge_idx, BLI_bitmap *done_edges, MeshElemMap *edge_to_poly_map, @@ -1075,7 +1075,9 @@ static void mesh_island_to_astar_graph_edge_process(MeshIslandStore *islands, } if (poly_status[pidx_isld] == POLY_UNSET) { - BKE_mesh_calc_poly_center(&poly, &loops[poly.loopstart], positions, poly_centers[pidx_isld]); + copy_v3_v3(poly_centers[pidx_isld], + blender::bke::mesh::poly_center_calc(positions, + loops.slice(poly.loopstart, poly.totloop))); BLI_astar_node_init(as_graph, pidx_isld, poly_centers[pidx_isld]); poly_status[pidx_isld] = POLY_CENTER_INIT; } @@ -1100,11 +1102,11 @@ 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 float (*positions)[3], + const blender::Span positions, MeshElemMap *edge_to_poly_map, const int numedges, - const MLoop *loops, - const MPoly *polys, + const blender::Span polys, + const blender::Span loops, const int numpolys, BLI_AStarGraph *r_as_graph) { @@ -1289,7 +1291,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, const float(*poly_nors_dst)[3] = nullptr; float(*loop_nors_dst)[3] = nullptr; - float(*poly_cents_src)[3] = nullptr; + blender::Array poly_cents_src; MeshElemMap *vert_to_loop_map_src = nullptr; int *vert_to_loop_map_src_buff = nullptr; @@ -1303,7 +1305,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 = nullptr; - const float(*positions_src)[3] = BKE_mesh_vert_positions(me_src); + const blender::Span positions_src = me_src->vert_positions(); const int num_verts_src = me_src->totvert; float(*vcos_src)[3] = nullptr; const blender::Span edges_src = me_src->edges(); @@ -1363,24 +1365,21 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, CustomData_get_layer_named(&mesh_dst->edata, CD_PROP_BOOL, "sharp_edge")); const bool *sharp_faces = static_cast( CustomData_get_layer_named(&mesh_dst->pdata, CD_PROP_BOOL, "sharp_face")); - BKE_mesh_normals_loop_split(vert_positions_dst, - BKE_mesh_vert_normals_ensure(mesh_dst), - numverts_dst, - edges_dst, - numedges_dst, - loops_dst, - loop_nors_dst, - numloops_dst, - polys_dst, - poly_nors_dst, - numpolys_dst, - use_split_nors_dst, - split_angle_dst, - sharp_edges, - sharp_faces, - nullptr, - nullptr, - custom_nors_dst); + blender::bke::mesh::normals_calc_loop( + {reinterpret_cast(vert_positions_dst), numverts_dst}, + {edges_dst, numedges_dst}, + {polys_dst, numpolys_dst}, + {loops_dst, numloops_dst}, + {}, + mesh_dst->vert_normals(), + mesh_dst->poly_normals(), + sharp_edges, + sharp_faces, + use_split_nors_dst, + split_angle_dst, + custom_nors_dst, + nullptr, + {reinterpret_cast(loop_nors_dst), numloops_dst}); } } if (need_pnors_src || need_lnors_src) { @@ -1425,8 +1424,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, if (use_from_vert) { loop_to_poly_map_src = static_cast( MEM_mallocN(sizeof(*loop_to_poly_map_src) * size_t(loops_src.size()), __func__)); - poly_cents_src = static_cast( - MEM_mallocN(sizeof(*poly_cents_src) * size_t(polys_src.size()), __func__)); + poly_cents_src.reinitialize(polys_src.size()); for (pidx_src = 0; pidx_src < polys_src.size(); pidx_src++) { const MPoly &poly = polys_src[pidx_src]; ml_src = &loops_src[poly.loopstart]; @@ -1434,7 +1432,8 @@ 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(&poly, ml_src, positions_src, poly_cents_src[pidx_src]); + poly_cents_src[pidx_src] = blender::bke::mesh::poly_center_calc( + positions_src, loops_src.slice(poly.loopstart, poly.totloop)); } } @@ -1449,7 +1448,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, if (gen_islands_src) { const bool *uv_seams = static_cast( CustomData_get_layer_named(&me_src->edata, CD_PROP_BOOL, ".uv_seam")); - use_islands = gen_islands_src(positions_src, + use_islands = gen_islands_src(reinterpret_cast(positions_src.data()), num_verts_src, edges_src.data(), int(edges_src.size()), @@ -1493,8 +1492,8 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, positions_src, edge_to_poly_map_src, int(edges_src.size()), - loops_src.data(), - polys_src.data(), + polys_src, + loops_src, int(polys_src.size()), &as_graphdata[tindex]); } @@ -1520,7 +1519,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, } } bvhtree_from_mesh_verts_ex(&treedata[tindex], - positions_src, + reinterpret_cast(positions_src.data()), num_verts_src, verts_active, num_verts_active, @@ -1550,7 +1549,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, } } bvhtree_from_mesh_looptri_ex(&treedata[tindex], - positions_src, + reinterpret_cast(positions_src.data()), loops_src.data(), looptris_src.data(), int(looptris_src.size()), @@ -1580,7 +1579,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, /* Only in use_from_vert case, we may need polys' centers as fallback * in case we cannot decide which corner to use from normals only. */ - float pcent_dst[3]; + blender::float3 pcent_dst; bool pcent_dst_valid = false; if (mode == MREMAP_MODE_LOOP_NEAREST_POLYNOR) { @@ -1668,8 +1667,10 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, ml_src = &loops_src[poly.loopstart]; if (!pcent_dst_valid) { - BKE_mesh_calc_poly_center( - mp_dst, &loops_dst[mp_dst->loopstart], vert_positions_dst, pcent_dst); + pcent_dst = blender::bke::mesh::poly_center_calc( + {reinterpret_cast(vert_positions_dst), + numverts_dst}, + {&loops_dst[mp_dst->loopstart], mp_dst->totloop}); pcent_dst_valid = true; } pcent_src = poly_cents_src[pidx_src]; @@ -2139,9 +2140,6 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, if (loop_to_poly_map_src) { MEM_freeN(loop_to_poly_map_src); } - if (poly_cents_src) { - MEM_freeN(poly_cents_src); - } if (vcos_interp) { MEM_freeN(vcos_interp); } @@ -2160,6 +2158,7 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode, const float ray_radius, const Mesh *mesh_dst, const float (*vert_positions_dst)[3], + const int numverts_dst, const MLoop *loops_dst, const MPoly *polys_dst, const int numpolys_dst, @@ -2169,7 +2168,7 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode, const float full_weight = 1.0f; const float max_dist_sq = max_dist * max_dist; const float(*poly_nors_dst)[3] = nullptr; - float tmp_co[3], tmp_no[3]; + blender::float3 tmp_co, tmp_no; int i; BLI_assert(mode & MREMAP_MODE_POLY); @@ -2199,8 +2198,9 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode, for (i = 0; i < numpolys_dst; i++) { const MPoly &poly = polys_dst[i]; - - BKE_mesh_calc_poly_center(&poly, &loops_dst[poly.loopstart], vert_positions_dst, tmp_co); + tmp_co = blender::bke::mesh::poly_center_calc( + {reinterpret_cast(vert_positions_dst), numverts_dst}, + {&loops_dst[poly.loopstart], poly.totloop}); /* Convert the vertex to tree coordinates, if needed. */ if (space_transform) { @@ -2225,7 +2225,9 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode, for (i = 0; i < numpolys_dst; i++) { const MPoly &poly = polys_dst[i]; - BKE_mesh_calc_poly_center(&poly, &loops_dst[poly.loopstart], vert_positions_dst, tmp_co); + tmp_co = blender::bke::mesh::poly_center_calc( + {reinterpret_cast(vert_positions_dst), numverts_dst}, + {&loops_dst[poly.loopstart], poly.totloop}); copy_v3_v3(tmp_no, poly_nors_dst[i]); /* Convert the vertex to tree coordinates, if needed. */ @@ -2277,7 +2279,7 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode, int tot_rays, done_rays = 0; float poly_area_2d_inv, done_area = 0.0f; - float pcent_dst[3]; + blender::float3 pcent_dst; float to_pnor_2d_mat[3][3], from_pnor_2d_mat[3][3]; float poly_dst_2d_min[2], poly_dst_2d_max[2], poly_dst_2d_z; float poly_dst_2d_size[2]; @@ -2288,8 +2290,10 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode, const int tris_num = poly.totloop - 2; int j; - BKE_mesh_calc_poly_center( - &poly, &loops_dst[poly.loopstart], vert_positions_dst, pcent_dst); + pcent_dst = blender::bke::mesh::poly_center_calc( + {reinterpret_cast(vert_positions_dst), numverts_dst}, + {&loops_dst[poly.loopstart], poly.totloop}); + 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! */ diff --git a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc index 61eb63d00b3..a3a57b165e8 100644 --- a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc +++ b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc @@ -30,7 +30,7 @@ #include "BKE_customdata.h" #include "BKE_editmesh.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_mesh_remesh_voxel.h" /* own include */ #include "BKE_mesh_runtime.h" @@ -338,15 +338,12 @@ void BKE_remesh_reproject_sculpt_face_sets(Mesh *target, const Mesh *source) blender::threading::parallel_for(IndexRange(target->totpoly), 2048, [&](const IndexRange range) { for (const int i : range) { - float from_co[3]; BVHTreeNearest nearest; nearest.index = -1; nearest.dist_sq = FLT_MAX; const MPoly &poly = target_polys[i]; - BKE_mesh_calc_poly_center(&poly, - &target_loops[poly.loopstart], - reinterpret_cast(target_positions.data()), - from_co); + const float3 from_co = mesh::poly_center_calc( + target_positions, target_loops.slice(poly.loopstart, poly.totloop)); BLI_bvhtree_find_nearest( bvhtree.tree, from_co, &nearest, bvhtree.nearest_callback, &bvhtree); if (nearest.index != -1) { diff --git a/source/blender/blenkernel/intern/mesh_runtime.cc b/source/blender/blenkernel/intern/mesh_runtime.cc index 8a8970b1905..65a001f71fd 100644 --- a/source/blender/blenkernel/intern/mesh_runtime.cc +++ b/source/blender/blenkernel/intern/mesh_runtime.cc @@ -20,7 +20,7 @@ #include "BKE_bvhutils.h" #include "BKE_editmesh_cache.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_shrinkwrap.h" #include "BKE_subdiv_ccg.h" @@ -152,21 +152,11 @@ blender::Span Mesh::looptris() const r_data.reinitialize(poly_to_tri_count(polys.size(), loops.size())); if (BKE_mesh_poly_normals_are_dirty(this)) { - BKE_mesh_recalc_looptri(loops.data(), - polys.data(), - reinterpret_cast(positions.data()), - loops.size(), - polys.size(), - r_data.data()); + blender::bke::mesh::looptris_calc(positions, polys, loops, r_data); } else { - BKE_mesh_recalc_looptri_with_normals(loops.data(), - polys.data(), - reinterpret_cast(positions.data()), - loops.size(), - polys.size(), - r_data.data(), - BKE_mesh_poly_normals_ensure(this)); + blender::bke::mesh::looptris_calc_with_normals( + positions, polys, loops, this->poly_normals(), r_data); } }); diff --git a/source/blender/blenkernel/intern/mesh_sample.cc b/source/blender/blenkernel/intern/mesh_sample.cc index 316fa41e16f..3fe710d1d69 100644 --- a/source/blender/blenkernel/intern/mesh_sample.cc +++ b/source/blender/blenkernel/intern/mesh_sample.cc @@ -2,7 +2,7 @@ #include "BKE_attribute_math.hh" #include "BKE_bvhutils.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_mesh_sample.hh" diff --git a/source/blender/blenkernel/intern/mesh_tangent.cc b/source/blender/blenkernel/intern/mesh_tangent.cc index 9bb18f72507..54389b98971 100644 --- a/source/blender/blenkernel/intern/mesh_tangent.cc +++ b/source/blender/blenkernel/intern/mesh_tangent.cc @@ -20,7 +20,7 @@ #include "BKE_attribute.hh" #include "BKE_customdata.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_mesh_tangent.h" #include "BKE_report.h" diff --git a/source/blender/blenkernel/intern/mesh_tessellate.cc b/source/blender/blenkernel/intern/mesh_tessellate.cc index 4d3898b70ac..32d267befc2 100644 --- a/source/blender/blenkernel/intern/mesh_tessellate.cc +++ b/source/blender/blenkernel/intern/mesh_tessellate.cc @@ -10,24 +10,18 @@ * \see bmesh_mesh_tessellate.c for the #BMesh equivalent of this file. */ -#include - -#include "MEM_guardedalloc.h" - -#include "DNA_mesh_types.h" -#include "DNA_meshdata_types.h" - +#include "BLI_enumerable_thread_specific.hh" #include "BLI_math.h" #include "BLI_memarena.h" #include "BLI_polyfill_2d.h" #include "BLI_task.h" -#include "BLI_utildefines.h" -#include "BKE_customdata.h" -#include "BKE_mesh.h" /* Own include. */ +#include "BKE_mesh.hh" #include "BLI_strict_flags.h" +namespace blender::bke::mesh { + /** Compared against total loops. */ #define MESH_FACE_TESSELLATE_THREADED_LIMIT 4096 @@ -40,9 +34,9 @@ /** * \param face_normal: This will be optimized out as a constant. */ -BLI_INLINE void mesh_calc_tessellation_for_face_impl(const MLoop *mloop, - const MPoly *polys, - const float (*positions)[3], +BLI_INLINE void mesh_calc_tessellation_for_face_impl(const Span mloop, + const Span polys, + const Span positions, uint poly_index, MLoopTri *mlt, MemArena **pf_arena_p, @@ -101,7 +95,7 @@ BLI_INLINE void mesh_calc_tessellation_for_face_impl(const MLoop *mloop, zero_v3(normal); /* Calc normal, flipped: to get a positive 2D cross product. */ - ml = mloop + mp_loopstart; + ml = mloop.data() + mp_loopstart; co_prev = positions[ml[mp_totloop - 1].v]; for (uint j = 0; j < mp_totloop; j++, ml++) { co_curr = positions[ml->v]; @@ -129,7 +123,7 @@ BLI_INLINE void mesh_calc_tessellation_for_face_impl(const MLoop *mloop, float(*projverts)[2] = static_cast( BLI_memarena_alloc(pf_arena, sizeof(*projverts) * size_t(mp_totloop))); - ml = mloop + mp_loopstart; + ml = mloop.data() + mp_loopstart; for (uint j = 0; j < mp_totloop; j++, ml++) { mul_v2_m3v3(projverts[j], axis_mat, positions[ml->v]); } @@ -150,9 +144,9 @@ BLI_INLINE void mesh_calc_tessellation_for_face_impl(const MLoop *mloop, #undef ML_TO_MLT } -static void mesh_calc_tessellation_for_face(const MLoop *mloop, - const MPoly *polys, - const float (*positions)[3], +static void mesh_calc_tessellation_for_face(const Span mloop, + const Span polys, + const Span positions, uint poly_index, MLoopTri *mlt, MemArena **pf_arena_p) @@ -161,9 +155,9 @@ static void mesh_calc_tessellation_for_face(const MLoop *mloop, mloop, polys, positions, poly_index, mlt, pf_arena_p, false, nullptr); } -static void mesh_calc_tessellation_for_face_with_normal(const MLoop *mloop, - const MPoly *polys, - const float (*positions)[3], +static void mesh_calc_tessellation_for_face_with_normal(const Span mloop, + const Span polys, + const Span positions, uint poly_index, MLoopTri *mlt, MemArena **pf_arena_p, @@ -173,16 +167,16 @@ static void mesh_calc_tessellation_for_face_with_normal(const MLoop *mloop, mloop, polys, positions, poly_index, mlt, pf_arena_p, true, normal_precalc); } -static void mesh_recalc_looptri__single_threaded(const MLoop *mloop, - const MPoly *polys, - const float (*positions)[3], +static void mesh_recalc_looptri__single_threaded(const Span mloop, + const Span polys, + const Span positions, int totloop, int totpoly, MLoopTri *mlooptri, const float (*poly_normals)[3]) { MemArena *pf_arena = nullptr; - const MPoly *poly = polys; + const MPoly *poly = polys.data(); uint tri_index = 0; if (poly_normals != nullptr) { @@ -214,12 +208,12 @@ static void mesh_recalc_looptri__single_threaded(const MLoop *mloop, } struct TessellationUserData { - const MLoop *mloop; - const MPoly *polys; - const float (*positions)[3]; + Span mloop; + Span polys; + Span positions; /** Output array. */ - MLoopTri *mlooptri; + MutableSpan mlooptri; /** Optional pre-calculated polygon normals array. */ const float (*poly_normals)[3]; @@ -272,23 +266,31 @@ 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 *polys, - const float (*positions)[3], - int /*totloop*/, - int totpoly, - MLoopTri *mlooptri, - const float (*poly_normals)[3]) +static void looptris_calc_all(const Span positions, + const Span polys, + const Span loops, + const Span poly_normals, + MutableSpan looptris) { + if (loops.size() < MESH_FACE_TESSELLATE_THREADED_LIMIT) { + mesh_recalc_looptri__single_threaded(loops, + polys, + positions, + int(loops.size()), + int(polys.size()), + looptris.data(), + reinterpret_cast(poly_normals.data())); + return; + } struct TessellationUserTLS tls_data_dummy = {nullptr}; struct TessellationUserData data { }; - data.mloop = mloop; + data.mloop = loops; data.polys = polys; data.positions = positions; - data.mlooptri = mlooptri; - data.poly_normals = poly_normals; + data.mlooptri = looptris; + data.poly_normals = reinterpret_cast(poly_normals.data()); TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); @@ -299,47 +301,46 @@ static void mesh_recalc_looptri__multi_threaded(const MLoop *mloop, settings.func_free = mesh_calc_tessellation_for_face_free_fn; BLI_task_parallel_range(0, - totpoly, + int(polys.size()), &data, - poly_normals ? mesh_calc_tessellation_for_face_with_normal_fn : - mesh_calc_tessellation_for_face_fn, + data.poly_normals ? mesh_calc_tessellation_for_face_with_normal_fn : + mesh_calc_tessellation_for_face_fn, &settings); } +void looptris_calc(const Span vert_positions, + const Span polys, + const Span loops, + MutableSpan looptris) +{ + looptris_calc_all(vert_positions, polys, loops, {}, looptris); +} + +void looptris_calc_with_normals(const Span vert_positions, + const Span polys, + const Span loops, + const Span poly_normals, + MutableSpan looptris) +{ + BLI_assert(!poly_normals.is_empty()); + looptris_calc_all(vert_positions, polys, loops, poly_normals, looptris); +} + +} // namespace blender::bke::mesh + void BKE_mesh_recalc_looptri(const MLoop *mloop, const MPoly *polys, const float (*vert_positions)[3], + int totvert, int totloop, int totpoly, MLoopTri *mlooptri) { - if (totloop < MESH_FACE_TESSELLATE_THREADED_LIMIT) { - mesh_recalc_looptri__single_threaded( - mloop, polys, vert_positions, totloop, totpoly, mlooptri, nullptr); - } - else { - mesh_recalc_looptri__multi_threaded( - mloop, polys, vert_positions, totloop, totpoly, mlooptri, nullptr); - } -} - -void BKE_mesh_recalc_looptri_with_normals(const MLoop *mloop, - const MPoly *polys, - const float (*vert_positions)[3], - int totloop, - int totpoly, - MLoopTri *mlooptri, - const float (*poly_normals)[3]) -{ - BLI_assert(poly_normals != nullptr); - if (totloop < MESH_FACE_TESSELLATE_THREADED_LIMIT) { - mesh_recalc_looptri__single_threaded( - mloop, polys, vert_positions, totloop, totpoly, mlooptri, poly_normals); - } - else { - mesh_recalc_looptri__multi_threaded( - mloop, polys, vert_positions, totloop, totpoly, mlooptri, poly_normals); - } + blender::bke::mesh::looptris_calc( + {reinterpret_cast(vert_positions), totvert}, + {polys, totpoly}, + {mloop, totloop}, + {mlooptri, poly_to_tri_count(totpoly, totloop)}); } /** \} */ diff --git a/source/blender/blenkernel/intern/mesh_validate.cc b/source/blender/blenkernel/intern/mesh_validate.cc index 7f329e2eb68..0e408438496 100644 --- a/source/blender/blenkernel/intern/mesh_validate.cc +++ b/source/blender/blenkernel/intern/mesh_validate.cc @@ -27,7 +27,7 @@ #include "BKE_attribute.hh" #include "BKE_customdata.h" #include "BKE_deform.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "DEG_depsgraph.h" diff --git a/source/blender/blenkernel/intern/mesh_wrapper.cc b/source/blender/blenkernel/intern/mesh_wrapper.cc index a7e5d999cf6..63792623c56 100644 --- a/source/blender/blenkernel/intern/mesh_wrapper.cc +++ b/source/blender/blenkernel/intern/mesh_wrapper.cc @@ -34,7 +34,7 @@ #include "BKE_editmesh.h" #include "BKE_editmesh_cache.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_mesh_wrapper.h" #include "BKE_modifier.h" diff --git a/source/blender/blenkernel/intern/modifier.cc b/source/blender/blenkernel/intern/modifier.cc index 5b09b59fdb4..5e7580e28cf 100644 --- a/source/blender/blenkernel/intern/modifier.cc +++ b/source/blender/blenkernel/intern/modifier.cc @@ -54,7 +54,7 @@ #include "BKE_key.h" #include "BKE_lib_id.h" #include "BKE_lib_query.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_wrapper.h" #include "BKE_multires.h" #include "BKE_object.h" diff --git a/source/blender/blenkernel/intern/multires.cc b/source/blender/blenkernel/intern/multires.cc index a2adcfccc94..f7dfc4e17e5 100644 --- a/source/blender/blenkernel/intern/multires.cc +++ b/source/blender/blenkernel/intern/multires.cc @@ -24,7 +24,7 @@ #include "BKE_ccg.h" #include "BKE_cdderivedmesh.h" #include "BKE_editmesh.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_mesh_runtime.h" #include "BKE_modifier.h" diff --git a/source/blender/blenkernel/intern/multires_reshape.cc b/source/blender/blenkernel/intern/multires_reshape.cc index d4e842dc10c..7dae4f8c543 100644 --- a/source/blender/blenkernel/intern/multires_reshape.cc +++ b/source/blender/blenkernel/intern/multires_reshape.cc @@ -14,7 +14,7 @@ #include "BKE_customdata.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_modifier.h" #include "BKE_multires.h" diff --git a/source/blender/blenkernel/intern/multires_reshape_apply_base.cc b/source/blender/blenkernel/intern/multires_reshape_apply_base.cc index e1efb8f0dfd..46a990c6e07 100644 --- a/source/blender/blenkernel/intern/multires_reshape_apply_base.cc +++ b/source/blender/blenkernel/intern/multires_reshape_apply_base.cc @@ -19,7 +19,7 @@ #include "BKE_customdata.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_mesh_runtime.h" #include "BKE_multires.h" @@ -114,16 +114,10 @@ void multires_reshape_apply_base_refit_base_mesh(MultiresReshapeContext *reshape /* Find normal. */ for (int j = 0; j < pmap[i].count; j++) { const MPoly &poly = reshape_context->base_polys[pmap[i].indices[j]]; - MPoly fake_poly; - float no[3]; - /* Set up poly, loops, and coords in order to call BKE_mesh_calc_poly_normal(). */ - fake_poly.totloop = poly.totloop; - fake_poly.loopstart = 0; - MLoop *fake_loops = static_cast( - MEM_malloc_arrayN(poly.totloop, sizeof(MLoop), __func__)); - float(*fake_co)[3] = static_cast( - MEM_malloc_arrayN(poly.totloop, sizeof(float[3]), __func__)); + /* Set up poly, loops, and coords in order to call #bke::mesh::poly_normal_calc(). */ + blender::Array fake_loops(poly.totloop); + blender::Array fake_co(poly.totloop); for (int k = 0; k < poly.totloop; k++) { const int vndx = reshape_context->base_loops[poly.loopstart + k].v; @@ -138,10 +132,7 @@ void multires_reshape_apply_base_refit_base_mesh(MultiresReshapeContext *reshape } } - BKE_mesh_calc_poly_normal(&fake_poly, fake_loops, (const float(*)[3])fake_co, no); - MEM_freeN(fake_loops); - MEM_freeN(fake_co); - + const blender::float3 no = blender::bke::mesh::poly_normal_calc(fake_co, fake_loops); add_v3_v3(avg_no, no); } normalize_v3(avg_no); diff --git a/source/blender/blenkernel/intern/multires_reshape_subdivide.cc b/source/blender/blenkernel/intern/multires_reshape_subdivide.cc index d29a820352f..1d23f81def8 100644 --- a/source/blender/blenkernel/intern/multires_reshape_subdivide.cc +++ b/source/blender/blenkernel/intern/multires_reshape_subdivide.cc @@ -14,7 +14,7 @@ #include "BKE_customdata.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_modifier.h" #include "BKE_multires.h" @@ -28,7 +28,9 @@ static void multires_subdivide_create_object_space_linear_grids(Mesh *mesh) { - const float(*positions)[3] = BKE_mesh_vert_positions(mesh); + using namespace blender; + using namespace blender::bke; + const Span positions = mesh->vert_positions(); const blender::Span polys = mesh->polys(); const blender::Span loops = mesh->loops(); @@ -36,8 +38,8 @@ static void multires_subdivide_create_object_space_linear_grids(Mesh *mesh) CustomData_get_layer_for_write(&mesh->ldata, CD_MDISPS, mesh->totloop)); for (const int p : polys.index_range()) { const MPoly &poly = polys[p]; - float poly_center[3]; - BKE_mesh_calc_poly_center(&poly, &loops[poly.loopstart], positions, poly_center); + const float3 poly_center = mesh::poly_center_calc(positions, + loops.slice(poly.loopstart, poly.totloop)); for (int l = 0; l < poly.totloop; l++) { const int loop_index = poly.loopstart + l; diff --git a/source/blender/blenkernel/intern/multires_reshape_util.cc b/source/blender/blenkernel/intern/multires_reshape_util.cc index c803c5ca478..aea8f8a3ca6 100644 --- a/source/blender/blenkernel/intern/multires_reshape_util.cc +++ b/source/blender/blenkernel/intern/multires_reshape_util.cc @@ -18,7 +18,7 @@ #include "BLI_task.h" #include "BKE_customdata.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_multires.h" #include "BKE_subdiv.h" diff --git a/source/blender/blenkernel/intern/multires_subdiv.cc b/source/blender/blenkernel/intern/multires_subdiv.cc index 704d3fde1f1..b4cddcc53bf 100644 --- a/source/blender/blenkernel/intern/multires_subdiv.cc +++ b/source/blender/blenkernel/intern/multires_subdiv.cc @@ -12,7 +12,7 @@ #include "BLI_utildefines.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_multires.h" #include "BKE_subdiv.h" diff --git a/source/blender/blenkernel/intern/multires_unsubdivide.cc b/source/blender/blenkernel/intern/multires_unsubdivide.cc index 49793ce44b6..f96516ba52c 100644 --- a/source/blender/blenkernel/intern/multires_unsubdivide.cc +++ b/source/blender/blenkernel/intern/multires_unsubdivide.cc @@ -20,7 +20,7 @@ #include "BKE_customdata.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_modifier.h" #include "BKE_multires.h" diff --git a/source/blender/blenkernel/intern/object.cc b/source/blender/blenkernel/intern/object.cc index 32524c92c04..54273ce31f8 100644 --- a/source/blender/blenkernel/intern/object.cc +++ b/source/blender/blenkernel/intern/object.cc @@ -105,7 +105,7 @@ #include "BKE_main.h" #include "BKE_material.h" #include "BKE_mball.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_wrapper.h" #include "BKE_modifier.h" #include "BKE_multires.h" diff --git a/source/blender/blenkernel/intern/object_dupli.cc b/source/blender/blenkernel/intern/object_dupli.cc index fb967ac9129..7a7027a7e95 100644 --- a/source/blender/blenkernel/intern/object_dupli.cc +++ b/source/blender/blenkernel/intern/object_dupli.cc @@ -44,7 +44,7 @@ #include "BKE_instances.hh" #include "BKE_lattice.h" #include "BKE_main.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_iterators.h" #include "BKE_mesh_runtime.h" #include "BKE_modifier.h" diff --git a/source/blender/blenkernel/intern/object_update.cc b/source/blender/blenkernel/intern/object_update.cc index ca513599ccc..dcc1f309ab5 100644 --- a/source/blender/blenkernel/intern/object_update.cc +++ b/source/blender/blenkernel/intern/object_update.cc @@ -38,7 +38,7 @@ #include "BKE_light.h" #include "BKE_material.h" #include "BKE_mball.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "BKE_particle.h" #include "BKE_pointcache.h" diff --git a/source/blender/blenkernel/intern/paint.cc b/source/blender/blenkernel/intern/paint.cc index 943f6902868..6760eb469a3 100644 --- a/source/blender/blenkernel/intern/paint.cc +++ b/source/blender/blenkernel/intern/paint.cc @@ -46,7 +46,7 @@ #include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_mesh_runtime.h" #include "BKE_modifier.h" @@ -2188,12 +2188,7 @@ static PBVH *build_pbvh_from_regular_mesh(Object *ob, Mesh *me_eval_deform, bool MLoopTri *looptri = static_cast( MEM_malloc_arrayN(looptris_num, sizeof(*looptri), __func__)); - BKE_mesh_recalc_looptri(loops.data(), - polys.data(), - reinterpret_cast(positions.data()), - me->totloop, - me->totpoly, - looptri); + blender::bke::mesh::looptris_calc(positions, polys, loops, {looptri, looptris_num}); BKE_pbvh_build_mesh(pbvh, me, diff --git a/source/blender/blenkernel/intern/particle.cc b/source/blender/blenkernel/intern/particle.cc index 48150c7dcaf..c3d49fc8bec 100644 --- a/source/blender/blenkernel/intern/particle.cc +++ b/source/blender/blenkernel/intern/particle.cc @@ -58,7 +58,7 @@ #include "BKE_lib_query.h" #include "BKE_main.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_legacy_convert.h" #include "BKE_mesh_runtime.h" #include "BKE_modifier.h" diff --git a/source/blender/blenkernel/intern/pbvh.cc b/source/blender/blenkernel/intern/pbvh.cc index 6837fcd3d8c..3ff3e19742b 100644 --- a/source/blender/blenkernel/intern/pbvh.cc +++ b/source/blender/blenkernel/intern/pbvh.cc @@ -20,7 +20,7 @@ #include "BKE_attribute.h" #include "BKE_ccg.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_paint.h" #include "BKE_pbvh.h" @@ -1409,7 +1409,7 @@ static void pbvh_update_normals_accum_task_cb(void *__restrict userdata, if (node->flag & PBVH_UpdateNormals) { uint mpoly_prev = UINT_MAX; - float fn[3]; + blender::float3 fn; const int *faces = node->prim_indices; const int totface = node->totprim; @@ -1426,7 +1426,9 @@ static void pbvh_update_normals_accum_task_cb(void *__restrict userdata, /* Face normal and mask */ if (lt->poly != mpoly_prev) { const MPoly &poly = pbvh->polys[lt->poly]; - BKE_mesh_calc_poly_normal(&poly, &pbvh->mloop[poly.loopstart], pbvh->vert_positions, fn); + fn = blender::bke::mesh::poly_normal_calc( + {reinterpret_cast(pbvh->vert_positions), pbvh->totvert}, + {&pbvh->mloop[poly.loopstart], poly.totloop}); mpoly_prev = lt->poly; } diff --git a/source/blender/blenkernel/intern/pbvh_colors.cc b/source/blender/blenkernel/intern/pbvh_colors.cc index 03c15b007be..73a32dea777 100644 --- a/source/blender/blenkernel/intern/pbvh_colors.cc +++ b/source/blender/blenkernel/intern/pbvh_colors.cc @@ -21,7 +21,7 @@ #include "BKE_attribute.h" #include "BKE_ccg.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_paint.h" #include "BKE_pbvh.h" diff --git a/source/blender/blenkernel/intern/pbvh_pixels.cc b/source/blender/blenkernel/intern/pbvh_pixels.cc index 5149ca1c56f..0a3f485610f 100644 --- a/source/blender/blenkernel/intern/pbvh_pixels.cc +++ b/source/blender/blenkernel/intern/pbvh_pixels.cc @@ -3,7 +3,7 @@ #include "BKE_attribute.hh" #include "BKE_customdata.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_pbvh.h" #include "BKE_pbvh_pixels.hh" diff --git a/source/blender/blenkernel/intern/shrinkwrap.cc b/source/blender/blenkernel/intern/shrinkwrap.cc index 92531e10499..002b9d3b21e 100644 --- a/source/blender/blenkernel/intern/shrinkwrap.cc +++ b/source/blender/blenkernel/intern/shrinkwrap.cc @@ -33,7 +33,7 @@ #include "BKE_deform.h" #include "BKE_editmesh.h" -#include "BKE_mesh.h" /* for OMP limits. */ +#include "BKE_mesh.hh" /* for OMP limits. */ #include "BKE_mesh_runtime.h" #include "BKE_mesh_wrapper.h" #include "BKE_subsurf.h" diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 013574dae10..92beefcbc2d 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -2759,7 +2759,8 @@ 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, vert_positions, me->totloop, me->totpoly, looptri); + BKE_mesh_recalc_looptri( + loops, polys, vert_positions, me->totvert, 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_ccg.cc b/source/blender/blenkernel/intern/subdiv_ccg.cc index 72225f7a364..a1b779d07e6 100644 --- a/source/blender/blenkernel/intern/subdiv_ccg.cc +++ b/source/blender/blenkernel/intern/subdiv_ccg.cc @@ -20,7 +20,7 @@ #include "BKE_DerivedMesh.h" #include "BKE_ccg.h" #include "BKE_global.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_subdiv.h" #include "BKE_subdiv_eval.h" diff --git a/source/blender/blenkernel/intern/subdiv_ccg_mask.cc b/source/blender/blenkernel/intern/subdiv_ccg_mask.cc index 68ad6a2d7f9..5d57378a870 100644 --- a/source/blender/blenkernel/intern/subdiv_ccg_mask.cc +++ b/source/blender/blenkernel/intern/subdiv_ccg_mask.cc @@ -17,7 +17,7 @@ #include "BLI_utildefines.h" #include "BKE_customdata.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_subdiv.h" #include "MEM_guardedalloc.h" diff --git a/source/blender/blenkernel/intern/subdiv_ccg_material.cc b/source/blender/blenkernel/intern/subdiv_ccg_material.cc index a690da515ed..a0e450d5697 100644 --- a/source/blender/blenkernel/intern/subdiv_ccg_material.cc +++ b/source/blender/blenkernel/intern/subdiv_ccg_material.cc @@ -5,7 +5,7 @@ * \ingroup bke */ -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_subdiv_ccg.h" #include "MEM_guardedalloc.h" diff --git a/source/blender/blenkernel/intern/subdiv_converter_mesh.cc b/source/blender/blenkernel/intern/subdiv_converter_mesh.cc index aefa53cc04f..b28fe42b1c5 100644 --- a/source/blender/blenkernel/intern/subdiv_converter_mesh.cc +++ b/source/blender/blenkernel/intern/subdiv_converter_mesh.cc @@ -16,7 +16,7 @@ #include "BLI_utildefines.h" #include "BKE_customdata.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_subdiv.h" diff --git a/source/blender/blenkernel/intern/subdiv_displacement_multires.cc b/source/blender/blenkernel/intern/subdiv_displacement_multires.cc index 59309541493..3cd73902d64 100644 --- a/source/blender/blenkernel/intern/subdiv_displacement_multires.cc +++ b/source/blender/blenkernel/intern/subdiv_displacement_multires.cc @@ -18,7 +18,7 @@ #include "BLI_utildefines.h" #include "BKE_customdata.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_multires.h" #include "BKE_subdiv_eval.h" diff --git a/source/blender/blenkernel/intern/subdiv_eval.cc b/source/blender/blenkernel/intern/subdiv_eval.cc index e1e13b10f5c..8dac6807872 100644 --- a/source/blender/blenkernel/intern/subdiv_eval.cc +++ b/source/blender/blenkernel/intern/subdiv_eval.cc @@ -16,7 +16,7 @@ #include "BLI_utildefines.h" #include "BKE_customdata.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_subdiv.h" #include "MEM_guardedalloc.h" diff --git a/source/blender/blenkernel/intern/subdiv_foreach.cc b/source/blender/blenkernel/intern/subdiv_foreach.cc index 3f9126f53e9..8231f0e7ca0 100644 --- a/source/blender/blenkernel/intern/subdiv_foreach.cc +++ b/source/blender/blenkernel/intern/subdiv_foreach.cc @@ -18,7 +18,7 @@ #include "BKE_customdata.h" #include "BKE_key.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_subdiv.h" #include "BKE_subdiv_mesh.hh" diff --git a/source/blender/blenkernel/intern/subdiv_mesh.cc b/source/blender/blenkernel/intern/subdiv_mesh.cc index 39e10fb03e6..5db8b815b33 100644 --- a/source/blender/blenkernel/intern/subdiv_mesh.cc +++ b/source/blender/blenkernel/intern/subdiv_mesh.cc @@ -21,7 +21,7 @@ #include "BKE_customdata.h" #include "BKE_key.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_subdiv.h" #include "BKE_subdiv_eval.h" diff --git a/source/blender/blenkernel/intern/subdiv_modifier.cc b/source/blender/blenkernel/intern/subdiv_modifier.cc index 60d55af215c..504dc8e5b29 100644 --- a/source/blender/blenkernel/intern/subdiv_modifier.cc +++ b/source/blender/blenkernel/intern/subdiv_modifier.cc @@ -11,7 +11,7 @@ #include "DNA_scene_types.h" #include "DNA_userdef_types.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_subdiv.h" diff --git a/source/blender/blenkernel/intern/subsurf_ccg.cc b/source/blender/blenkernel/intern/subsurf_ccg.cc index 923dd7a7788..b1e3374749f 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.cc +++ b/source/blender/blenkernel/intern/subsurf_ccg.cc @@ -33,7 +33,7 @@ #include "BKE_ccg.h" #include "BKE_cdderivedmesh.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_modifier.h" #include "BKE_multires.h" diff --git a/source/blender/blenkernel/intern/volume_to_mesh.cc b/source/blender/blenkernel/intern/volume_to_mesh.cc index 6395376bd14..9c64277525c 100644 --- a/source/blender/blenkernel/intern/volume_to_mesh.cc +++ b/source/blender/blenkernel/intern/volume_to_mesh.cc @@ -10,7 +10,7 @@ #include "DNA_meshdata_types.h" #include "DNA_volume_types.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_volume.h" #ifdef WITH_OPENVDB diff --git a/source/blender/blenloader/intern/readfile.cc b/source/blender/blenloader/intern/readfile.cc index c49a9ddcb82..80d8232156b 100644 --- a/source/blender/blenloader/intern/readfile.cc +++ b/source/blender/blenloader/intern/readfile.cc @@ -75,7 +75,7 @@ #include "BKE_main.h" /* for Main */ #include "BKE_main_idmap.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_node.h" /* for tree type defines */ #include "BKE_object.h" diff --git a/source/blender/blenloader/intern/versioning_290.cc b/source/blender/blenloader/intern/versioning_290.cc index 8af830e6e32..7ba73dcb575 100644 --- a/source/blender/blenloader/intern/versioning_290.cc +++ b/source/blender/blenloader/intern/versioning_290.cc @@ -48,7 +48,7 @@ #include "BKE_gpencil.h" #include "BKE_lib_id.h" #include "BKE_main.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_multires.h" #include "BKE_node.h" diff --git a/source/blender/blenloader/intern/versioning_300.cc b/source/blender/blenloader/intern/versioning_300.cc index 9b827c86df8..c4db901141e 100644 --- a/source/blender/blenloader/intern/versioning_300.cc +++ b/source/blender/blenloader/intern/versioning_300.cc @@ -63,7 +63,7 @@ #include "BKE_lib_override.h" #include "BKE_main.h" #include "BKE_main_namemap.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_node.h" #include "BKE_screen.h" diff --git a/source/blender/blenloader/intern/versioning_defaults.cc b/source/blender/blenloader/intern/versioning_defaults.cc index a0dca0e01cd..ebe954a1b4f 100644 --- a/source/blender/blenloader/intern/versioning_defaults.cc +++ b/source/blender/blenloader/intern/versioning_defaults.cc @@ -49,7 +49,7 @@ #include "BKE_main.h" #include "BKE_main_namemap.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_node.h" #include "BKE_node_runtime.hh" #include "BKE_node_tree_update.h" diff --git a/source/blender/bmesh/intern/bmesh_mesh.cc b/source/blender/bmesh/intern/bmesh_mesh.cc index d8fe0c36108..db70182fa27 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.cc +++ b/source/blender/bmesh/intern/bmesh_mesh.cc @@ -16,7 +16,7 @@ #include "BLI_utildefines.h" #include "BKE_customdata.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "bmesh.h" diff --git a/source/blender/bmesh/intern/bmesh_mesh_convert.cc b/source/blender/bmesh/intern/bmesh_mesh_convert.cc index 7267a86e432..6a0516eb5b2 100644 --- a/source/blender/bmesh/intern/bmesh_mesh_convert.cc +++ b/source/blender/bmesh/intern/bmesh_mesh_convert.cc @@ -89,7 +89,7 @@ #include "BKE_attribute.hh" #include "BKE_customdata.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_multires.h" diff --git a/source/blender/bmesh/intern/bmesh_mesh_normals.cc b/source/blender/bmesh/intern/bmesh_mesh_normals.cc index 28164eaec7a..6f0f7af7a6b 100644 --- a/source/blender/bmesh/intern/bmesh_mesh_normals.cc +++ b/source/blender/bmesh/intern/bmesh_mesh_normals.cc @@ -22,7 +22,7 @@ #include "BKE_customdata.h" #include "BKE_editmesh.h" #include "BKE_global.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "intern/bmesh_private.h" @@ -1053,7 +1053,7 @@ static void bm_mesh_loops_calc_normals_for_vert_without_clnors( } /** - * BMesh version of BKE_mesh_normals_loop_split() in `mesh_evaluate.cc` + * BMesh version of bke::mesh::normals_calc_loop() in `mesh_evaluate.cc` * Will use first clnors_data array, and fallback to cd_loop_clnors_offset * (use nullptr and -1 to not use clnors). * @@ -1404,7 +1404,7 @@ static bool bm_mesh_loops_split_lnor_fans(BMesh *bm, /* Notes: * * In case of mono-loop smooth fan, we have nothing to do. * * Loops in this linklist are ordered (in reversed order compared to how they were - * discovered by BKE_mesh_normals_loop_split(), but this is not a problem). + * discovered by bke::mesh::normals_calc_loop(), but this is not a problem). * Which means if we find a mismatching clnor, * we know all remaining loops will have to be in a new, different smooth fan/lnor space. * * In smooth fan case, we compare each clnor against a ref one, diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc index 6625c99f157..ba29cab1599 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc @@ -75,7 +75,7 @@ #include "BKE_mask.h" #include "BKE_material.h" #include "BKE_mball.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_movieclip.h" #include "BKE_node.h" diff --git a/source/blender/draw/engines/overlay/overlay_extra.cc b/source/blender/draw/engines/overlay/overlay_extra.cc index d645c75dce2..13feaf708aa 100644 --- a/source/blender/draw/engines/overlay/overlay_extra.cc +++ b/source/blender/draw/engines/overlay/overlay_extra.cc @@ -15,7 +15,7 @@ #include "BKE_curve.h" #include "BKE_global.h" #include "BKE_mball.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_movieclip.h" #include "BKE_object.h" 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 6fba9eed4e9..d32523a574f 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 @@ -17,7 +17,7 @@ #include "BKE_attribute.hh" #include "BKE_editmesh.h" #include "BKE_editmesh_cache.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "GPU_batch.h" @@ -363,30 +363,25 @@ void mesh_render_data_update_normals(MeshRenderData *mr, const eMRDataType data_ mr->poly_normals = mr->me->poly_normals(); } if (((data_flag & MR_DATA_LOOP_NOR) && is_auto_smooth) || (data_flag & MR_DATA_TAN_LOOP_NOR)) { - mr->loop_normals = static_cast( - MEM_mallocN(sizeof(*mr->loop_normals) * mr->loop_len, __func__)); + mr->loop_normals.reinitialize(mr->loops.size()); short(*clnors)[2] = static_cast( CustomData_get_layer_for_write(&mr->me->ldata, CD_CUSTOMLOOPNORMAL, mr->me->totloop)); const bool *sharp_edges = static_cast( CustomData_get_layer_named(&mr->me->edata, CD_PROP_BOOL, "sharp_edge")); - BKE_mesh_normals_loop_split(reinterpret_cast(mr->vert_positions.data()), - reinterpret_cast(mr->vert_normals.data()), - mr->vert_positions.size(), - mr->edges.data(), - mr->edges.size(), - mr->loops.data(), - mr->loop_normals, - mr->loops.size(), - mr->polys.data(), - reinterpret_cast(mr->poly_normals.data()), - mr->polys.size(), - is_auto_smooth, - split_angle, - sharp_edges, - mr->sharp_faces, - nullptr, - nullptr, - clnors); + blender::bke::mesh::normals_calc_loop(mr->vert_positions, + mr->edges, + mr->polys, + mr->loops, + {}, + mr->vert_normals, + mr->poly_normals, + sharp_edges, + mr->sharp_faces, + is_auto_smooth, + split_angle, + clnors, + nullptr, + mr->loop_normals); } } else { @@ -406,8 +401,7 @@ void mesh_render_data_update_normals(MeshRenderData *mr, const eMRDataType data_ poly_normals = mr->bm_poly_normals; } - mr->loop_normals = static_cast( - MEM_mallocN(sizeof(*mr->loop_normals) * mr->loop_len, __func__)); + mr->loop_normals.reinitialize(mr->loop_len); const int clnors_offset = CustomData_get_offset(&mr->bm->ldata, CD_CUSTOMLOOPNORMAL); BM_loops_calc_normal_vcos(mr->bm, vert_coords, @@ -415,7 +409,7 @@ void mesh_render_data_update_normals(MeshRenderData *mr, const eMRDataType data_ poly_normals, is_auto_smooth, split_angle, - mr->loop_normals, + reinterpret_cast(mr->loop_normals.data()), nullptr, nullptr, clnors_offset, @@ -443,7 +437,7 @@ MeshRenderData *mesh_render_data_create(Object *object, const bool do_uvedit, const ToolSettings *ts) { - MeshRenderData *mr = static_cast(MEM_callocN(sizeof(*mr), __func__)); + MeshRenderData *mr = MEM_new(__func__); mr->toolsettings = ts; mr->mat_len = mesh_render_mat_len_get(object, me); @@ -596,13 +590,12 @@ MeshRenderData *mesh_render_data_create(Object *object, void mesh_render_data_free(MeshRenderData *mr) { - MEM_SAFE_FREE(mr->loop_normals); /* Loose geometry are owned by #MeshBufferCache. */ mr->ledges = nullptr; mr->lverts = nullptr; - MEM_freeN(mr); + MEM_delete(mr); } /** \} */ diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.cc b/source/blender/draw/intern/draw_cache_impl_mesh.cc index f8077882c12..980b9856491 100644 --- a/source/blender/draw/intern/draw_cache_impl_mesh.cc +++ b/source/blender/draw/intern/draw_cache_impl_mesh.cc @@ -36,7 +36,7 @@ #include "BKE_editmesh.h" #include "BKE_editmesh_cache.h" #include "BKE_editmesh_tangent.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_mesh_tangent.h" #include "BKE_modifier.h" diff --git a/source/blender/draw/intern/draw_cache_impl_subdivision.cc b/source/blender/draw/intern/draw_cache_impl_subdivision.cc index bba4ecd050a..2f0dd84af8c 100644 --- a/source/blender/draw/intern/draw_cache_impl_subdivision.cc +++ b/source/blender/draw/intern/draw_cache_impl_subdivision.cc @@ -9,7 +9,7 @@ #include "BKE_attribute.hh" #include "BKE_editmesh.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_modifier.h" #include "BKE_object.h" diff --git a/source/blender/draw/intern/draw_manager_data.cc b/source/blender/draw/intern/draw_manager_data.cc index dd89a40fbf6..8255e2034a7 100644 --- a/source/blender/draw/intern/draw_manager_data.cc +++ b/source/blender/draw/intern/draw_manager_data.cc @@ -15,7 +15,7 @@ #include "BKE_duplilist.h" #include "BKE_global.h" #include "BKE_image.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "BKE_paint.h" #include "BKE_pbvh.h" diff --git a/source/blender/draw/intern/draw_manager_text.cc b/source/blender/draw/intern/draw_manager_text.cc index c61ff7d4beb..6ebcf72db3a 100644 --- a/source/blender/draw/intern/draw_manager_text.cc +++ b/source/blender/draw/intern/draw_manager_text.cc @@ -15,7 +15,7 @@ #include "BKE_editmesh.h" #include "BKE_editmesh_cache.h" #include "BKE_global.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_unit.h" #include "DNA_mesh_types.h" diff --git a/source/blender/draw/intern/draw_pbvh.cc b/source/blender/draw/intern/draw_pbvh.cc index 490b5dc9cf9..a5f2461f06c 100644 --- a/source/blender/draw/intern/draw_pbvh.cc +++ b/source/blender/draw/intern/draw_pbvh.cc @@ -36,7 +36,7 @@ #include "BKE_attribute.h" #include "BKE_ccg.h" #include "BKE_customdata.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_paint.h" #include "BKE_pbvh.h" #include "BKE_subdiv_ccg.h" @@ -345,9 +345,9 @@ struct PBVHBatches { flat = sharp_faces && sharp_faces[tri->poly]; if (flat) { const MPoly &poly = args->polys[tri->poly]; - float fno[3]; - BKE_mesh_calc_poly_normal( - &poly, args->mloop + poly.loopstart, args->vert_positions, fno); + const float3 fno = blender::bke::mesh::poly_normal_calc( + {reinterpret_cast(args->vert_positions), args->mesh_verts_num}, + {&args->mloop[poly.loopstart], poly.totloop}); normal_float_to_short_v3(no, fno); } } diff --git a/source/blender/draw/intern/draw_volume.cc b/source/blender/draw/intern/draw_volume.cc index c26b6949f3c..7d9825ef825 100644 --- a/source/blender/draw/intern/draw_volume.cc +++ b/source/blender/draw/intern/draw_volume.cc @@ -15,7 +15,7 @@ #include "BKE_fluid.h" #include "BKE_global.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_volume.h" #include "BKE_volume_render.h" diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh.hh b/source/blender/draw/intern/mesh_extractors/extract_mesh.hh index bab2123dc11..7991e7b256c 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh.hh +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh.hh @@ -95,7 +95,7 @@ struct MeshRenderData { const bool *select_edge; const bool *select_poly; const bool *sharp_faces; - float (*loop_normals)[3]; + blender::Array loop_normals; int *lverts, *ledges; const char *active_color_name; diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc index 5e7b292a0d3..20e90dc249f 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc @@ -15,7 +15,7 @@ #include "BKE_attribute.h" #include "BKE_attribute.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "draw_attributes.hh" #include "draw_subdivision.h" 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 9e0a149d181..014c5ed63e6 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 @@ -7,7 +7,7 @@ #include "MEM_guardedalloc.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BLI_math_vector_types.hh" 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 a34681486c5..8566a07d764 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 @@ -9,7 +9,7 @@ #include "MEM_guardedalloc.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "extract_mesh.hh" @@ -77,10 +77,8 @@ static void compute_area_ratio(const MeshRenderData *mr, const float2 *uv_data = (const float2 *)CustomData_get_layer(&mr->me->ldata, CD_PROP_FLOAT2); for (int poly_index = 0; poly_index < mr->poly_len; poly_index++) { const MPoly &poly = mr->polys[poly_index]; - float area = BKE_mesh_calc_poly_area( - &poly, - &mr->loops[poly.loopstart], - reinterpret_cast(mr->vert_positions.data())); + const float area = bke::mesh::poly_area_calc(mr->vert_positions, + mr->loops.slice(poly.loopstart, poly.totloop)); float uvarea = area_poly_v2(reinterpret_cast(&uv_data[poly.loopstart]), poly.totloop); tot_area += area; diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_lnor.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_lnor.cc index cefd6438477..bd15573d859 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_lnor.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_lnor.cc @@ -41,7 +41,7 @@ static void extract_lnor_iter_poly_bm(const MeshRenderData *mr, l_iter = l_first = BM_FACE_FIRST_LOOP(f); do { const int l_index = BM_elem_index_get(l_iter); - if (mr->loop_normals) { + if (!mr->loop_normals.is_empty()) { (*(GPUPackedNormal **)data)[l_index] = GPU_normal_convert_i10_v3(mr->loop_normals[l_index]); } else { @@ -68,7 +68,7 @@ static void extract_lnor_iter_poly_mesh(const MeshRenderData *mr, for (int ml_index = poly->loopstart; ml_index < ml_index_end; ml_index += 1) { const MLoop *ml = &mr->loops[ml_index]; GPUPackedNormal *lnor_data = &(*(GPUPackedNormal **)data)[ml_index]; - if (mr->loop_normals) { + if (!mr->loop_normals.is_empty()) { *lnor_data = GPU_normal_convert_i10_v3(mr->loop_normals[ml_index]); } else if (mr->sharp_faces && mr->sharp_faces[poly_index]) { @@ -167,7 +167,7 @@ static void extract_lnor_hq_iter_poly_bm(const MeshRenderData *mr, l_iter = l_first = BM_FACE_FIRST_LOOP(f); do { const int l_index = BM_elem_index_get(l_iter); - if (mr->loop_normals) { + if (!mr->loop_normals.is_empty()) { normal_float_to_short_v3(&(*(gpuHQNor **)data)[l_index].x, mr->loop_normals[l_index]); } else { @@ -192,7 +192,7 @@ static void extract_lnor_hq_iter_poly_mesh(const MeshRenderData *mr, for (int ml_index = poly->loopstart; ml_index < ml_index_end; ml_index += 1) { const MLoop *ml = &mr->loops[ml_index]; gpuHQNor *lnor_data = &(*(gpuHQNor **)data)[ml_index]; - if (mr->loop_normals) { + if (!mr->loop_normals.is_empty()) { normal_float_to_short_v3(&lnor_data->x, mr->loop_normals[ml_index]); } else if (mr->sharp_faces && mr->sharp_faces[poly_index]) { diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_sculpt_data.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_sculpt_data.cc index fb4319558e0..163ebf3a2f8 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_sculpt_data.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_sculpt_data.cc @@ -9,7 +9,7 @@ #include "BLI_string.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_paint.h" #include "draw_subdivision.h" 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 24fd7e9abd6..e7da5722f56 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 @@ -11,7 +11,7 @@ #include "BKE_editmesh.h" #include "BKE_editmesh_tangent.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_tangent.h" #include "extract_mesh.hh" @@ -107,7 +107,7 @@ static void extract_tan_init_common(const MeshRenderData *mr, r_tangent_names, tan_len, reinterpret_cast(mr->poly_normals.data()), - mr->loop_normals, + reinterpret_cast(mr->loop_normals.data()), orco, r_loop_data, mr->loop_len, @@ -127,7 +127,7 @@ static void extract_tan_init_common(const MeshRenderData *mr, tan_len, reinterpret_cast(mr->vert_normals.data()), reinterpret_cast(mr->poly_normals.data()), - mr->loop_normals, + reinterpret_cast(mr->loop_normals.data()), orco, r_loop_data, mr->loops.size(), diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_weights.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_weights.cc index d7d3fc6b3f5..7a88e2308d2 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_weights.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_weights.cc @@ -8,7 +8,7 @@ #include "MEM_guardedalloc.h" #include "BKE_deform.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "draw_subdivision.h" #include "extract_mesh.hh" diff --git a/source/blender/editors/armature/meshlaplacian.cc b/source/blender/editors/armature/meshlaplacian.cc index 01b1bdebe20..6e21a9004b8 100644 --- a/source/blender/editors/armature/meshlaplacian.cc +++ b/source/blender/editors/armature/meshlaplacian.cc @@ -20,7 +20,7 @@ #include "BLT_translation.h" #include "BKE_bvhutils.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_mesh_wrapper.h" #include "BKE_modifier.h" @@ -656,7 +656,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 float(*vert_positions)[3] = BKE_mesh_vert_positions(me); + const blender::Span vert_positions = me->vert_positions(); const blender::Span polys = me->polys(); const blender::Span loops = me->loops(); bool use_vert_sel = (me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0; @@ -705,8 +705,7 @@ void heat_bone_weighting(Object *ob, mlooptri = static_cast( MEM_mallocN(sizeof(*sys->heat.mlooptri) * sys->heat.tris_num, __func__)); - BKE_mesh_recalc_looptri( - loops.data(), polys.data(), vert_positions, me->totloop, me->totpoly, mlooptri); + blender::bke::mesh::looptris_calc(vert_positions, polys, loops, {mlooptri, sys->heat.tris_num}); sys->heat.mlooptri = mlooptri; sys->heat.loops = loops; diff --git a/source/blender/editors/curves/intern/curves_ops.cc b/source/blender/editors/curves/intern/curves_ops.cc index a05ecfcaed3..7e267b93101 100644 --- a/source/blender/editors/curves/intern/curves_ops.cc +++ b/source/blender/editors/curves/intern/curves_ops.cc @@ -30,7 +30,7 @@ #include "BKE_geometry_set.hh" #include "BKE_layer.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_legacy_convert.h" #include "BKE_mesh_runtime.h" #include "BKE_object.h" diff --git a/source/blender/editors/geometry/geometry_attributes.cc b/source/blender/editors/geometry/geometry_attributes.cc index 516d67220cb..3a218e7c500 100644 --- a/source/blender/editors/geometry/geometry_attributes.cc +++ b/source/blender/editors/geometry/geometry_attributes.cc @@ -16,7 +16,7 @@ #include "BKE_deform.h" #include "BKE_geometry_set.hh" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object_deform.h" #include "BKE_paint.h" #include "BKE_report.h" diff --git a/source/blender/editors/mesh/editface.cc b/source/blender/editors/mesh/editface.cc index 27d0c6808c8..afc6510f48c 100644 --- a/source/blender/editors/mesh/editface.cc +++ b/source/blender/editors/mesh/editface.cc @@ -23,7 +23,7 @@ #include "BKE_context.h" #include "BKE_customdata.h" #include "BKE_global.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "ED_mesh.h" diff --git a/source/blender/editors/mesh/editmesh_attribute.cc b/source/blender/editors/mesh/editmesh_attribute.cc index 8594f3ebc1c..f9a8d551abd 100644 --- a/source/blender/editors/mesh/editmesh_attribute.cc +++ b/source/blender/editors/mesh/editmesh_attribute.cc @@ -11,7 +11,7 @@ #include "BKE_context.h" #include "BKE_editmesh.h" #include "BKE_layer.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_report.h" #include "BKE_type_conversions.hh" diff --git a/source/blender/editors/mesh/editmesh_knife_project.cc b/source/blender/editors/mesh/editmesh_knife_project.cc index 4487c7a413a..eb073eb211c 100644 --- a/source/blender/editors/mesh/editmesh_knife_project.cc +++ b/source/blender/editors/mesh/editmesh_knife_project.cc @@ -18,7 +18,7 @@ #include "BKE_editmesh.h" #include "BKE_layer.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_object.h" #include "BKE_report.h" diff --git a/source/blender/editors/mesh/editmesh_mask_extract.cc b/source/blender/editors/mesh/editmesh_mask_extract.cc index 8dc08f233e9..c1e1bbc2adf 100644 --- a/source/blender/editors/mesh/editmesh_mask_extract.cc +++ b/source/blender/editors/mesh/editmesh_mask_extract.cc @@ -17,7 +17,7 @@ #include "BKE_editmesh.h" #include "BKE_layer.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_paint.h" #include "BKE_report.h" diff --git a/source/blender/editors/mesh/editmesh_select.cc b/source/blender/editors/mesh/editmesh_select.cc index 94c2e3352b3..2c1c3f9f80c 100644 --- a/source/blender/editors/mesh/editmesh_select.cc +++ b/source/blender/editors/mesh/editmesh_select.cc @@ -24,7 +24,7 @@ #include "BKE_editmesh.h" #include "BKE_editmesh_cache.h" #include "BKE_layer.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_report.h" #include "WM_api.h" diff --git a/source/blender/editors/mesh/editmesh_tools.cc b/source/blender/editors/mesh/editmesh_tools.cc index 9de10bb7d28..8a634e465c9 100644 --- a/source/blender/editors/mesh/editmesh_tools.cc +++ b/source/blender/editors/mesh/editmesh_tools.cc @@ -38,7 +38,7 @@ #include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "BKE_report.h" #include "BKE_texture.h" diff --git a/source/blender/editors/mesh/editmesh_undo.cc b/source/blender/editors/mesh/editmesh_undo.cc index 9401fd3027d..a31f90d5c60 100644 --- a/source/blender/editors/mesh/editmesh_undo.cc +++ b/source/blender/editors/mesh/editmesh_undo.cc @@ -26,7 +26,7 @@ #include "BKE_layer.h" #include "BKE_lib_id.h" #include "BKE_main.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "BKE_undo_system.h" diff --git a/source/blender/editors/mesh/mesh_data.cc b/source/blender/editors/mesh/mesh_data.cc index 17d106e70cf..f763314a2d8 100644 --- a/source/blender/editors/mesh/mesh_data.cc +++ b/source/blender/editors/mesh/mesh_data.cc @@ -23,7 +23,7 @@ #include "BKE_context.h" #include "BKE_customdata.h" #include "BKE_editmesh.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_report.h" @@ -795,22 +795,17 @@ 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 polys = me->polys(); - const Span loops = me->loops(); bke::MutableAttributeAccessor attributes = me->attributes_for_write(); bke::SpanAttributeWriter sharp_edges = attributes.lookup_or_add_for_write_span( "sharp_edge", ATTR_DOMAIN_EDGE); const bool *sharp_faces = static_cast( CustomData_get_layer_named(&me->pdata, CD_PROP_BOOL, "sharp_face")); - BKE_edges_sharp_from_angle_set(me->totedge, - loops.data(), - loops.size(), - polys.data(), - BKE_mesh_poly_normals_ensure(me), - sharp_faces, - polys.size(), - me->smoothresh, - sharp_edges.span.data()); + bke::mesh::edges_sharp_from_angle_set(me->polys(), + me->loops(), + me->poly_normals(), + sharp_faces, + me->smoothresh, + sharp_edges.span); sharp_edges.finish(); } @@ -1477,15 +1472,8 @@ void ED_mesh_split_faces(Mesh *mesh) Array sharp_edges(mesh->totedge); mesh_sharp_edges.materialize(sharp_edges); - BKE_edges_sharp_from_angle_set(mesh->totedge, - loops.data(), - loops.size(), - polys.data(), - BKE_mesh_poly_normals_ensure(mesh), - sharp_faces, - polys.size(), - split_angle, - sharp_edges.data()); + bke::mesh::edges_sharp_from_angle_set( + polys, loops, mesh->poly_normals(), sharp_faces, split_angle, sharp_edges); threading::parallel_for(polys.index_range(), 1024, [&](const IndexRange range) { for (const int poly_i : range) { diff --git a/source/blender/editors/mesh/mesh_mirror.cc b/source/blender/editors/mesh/mesh_mirror.cc index ee5b03d0c59..30cff1f95d3 100644 --- a/source/blender/editors/mesh/mesh_mirror.cc +++ b/source/blender/editors/mesh/mesh_mirror.cc @@ -15,7 +15,7 @@ #include "DNA_object_types.h" #include "BKE_editmesh.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BLI_kdtree.h" #include "ED_mesh.h" diff --git a/source/blender/editors/mesh/meshtools.cc b/source/blender/editors/mesh/meshtools.cc index 71fdf1b5ad1..d13a33c48bd 100644 --- a/source/blender/editors/mesh/meshtools.cc +++ b/source/blender/editors/mesh/meshtools.cc @@ -33,7 +33,7 @@ #include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_iterators.h" #include "BKE_mesh_runtime.h" #include "BKE_multires.h" diff --git a/source/blender/editors/object/object_add.cc b/source/blender/editors/object/object_add.cc index ab69c3fe20f..901e4fb6cc7 100644 --- a/source/blender/editors/object/object_add.cc +++ b/source/blender/editors/object/object_add.cc @@ -71,7 +71,7 @@ #include "BKE_main.h" #include "BKE_material.h" #include "BKE_mball.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_nla.h" #include "BKE_node.h" diff --git a/source/blender/editors/object/object_bake.cc b/source/blender/editors/object/object_bake.cc index 74c11c44619..04516352399 100644 --- a/source/blender/editors/object/object_bake.cc +++ b/source/blender/editors/object/object_bake.cc @@ -28,7 +28,7 @@ #include "BKE_global.h" #include "BKE_image.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_multires.h" #include "BKE_report.h" diff --git a/source/blender/editors/object/object_bake_api.cc b/source/blender/editors/object/object_bake_api.cc index 9b4bfdae137..2b689adc9d0 100644 --- a/source/blender/editors/object/object_bake_api.cc +++ b/source/blender/editors/object/object_bake_api.cc @@ -32,7 +32,7 @@ #include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_modifier.h" #include "BKE_node.h" @@ -1034,12 +1034,8 @@ static void bake_targets_populate_pixels_color_attributes(BakeTargets *targets, MLoopTri *looptri = static_cast(MEM_mallocN(sizeof(*looptri) * tottri, __func__)); const blender::Span loops = me_eval->loops(); - BKE_mesh_recalc_looptri(loops.data(), - me_eval->polys().data(), - BKE_mesh_vert_positions(me_eval), - me_eval->totloop, - me_eval->totpoly, - looptri); + blender::bke::mesh::looptris_calc( + me_eval->vert_positions(), me_eval->polys(), loops, {looptri, tottri}); /* For mapping back to original mesh in case there are modifiers. */ const int *vert_origindex = static_cast( diff --git a/source/blender/editors/object/object_data_transform.cc b/source/blender/editors/object/object_data_transform.cc index 8e236f8e966..f4f7a9d1a64 100644 --- a/source/blender/editors/object/object_data_transform.cc +++ b/source/blender/editors/object/object_data_transform.cc @@ -35,7 +35,7 @@ #include "BKE_key.h" #include "BKE_lattice.h" #include "BKE_mball.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_scene.h" #include "bmesh.h" diff --git a/source/blender/editors/object/object_edit.cc b/source/blender/editors/object/object_edit.cc index f595258d1ba..1fde31fe415 100644 --- a/source/blender/editors/object/object_edit.cc +++ b/source/blender/editors/object/object_edit.cc @@ -56,7 +56,7 @@ #include "BKE_main.h" #include "BKE_material.h" #include "BKE_mball.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_object.h" #include "BKE_paint.h" diff --git a/source/blender/editors/object/object_modifier.cc b/source/blender/editors/object/object_modifier.cc index 8cfe7b4a63a..d37325e0457 100644 --- a/source/blender/editors/object/object_modifier.cc +++ b/source/blender/editors/object/object_modifier.cc @@ -55,7 +55,7 @@ #include "BKE_main.h" #include "BKE_material.h" #include "BKE_mball.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_mesh_runtime.h" #include "BKE_modifier.h" diff --git a/source/blender/editors/object/object_remesh.cc b/source/blender/editors/object/object_remesh.cc index b76af724e62..987f652dc84 100644 --- a/source/blender/editors/object/object_remesh.cc +++ b/source/blender/editors/object/object_remesh.cc @@ -31,7 +31,7 @@ #include "BKE_global.h" #include "BKE_lib_id.h" #include "BKE_main.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mirror.h" #include "BKE_mesh_remesh_voxel.h" #include "BKE_mesh_runtime.h" diff --git a/source/blender/editors/object/object_transform.cc b/source/blender/editors/object/object_transform.cc index 9cb4f29bb5b..6d061239aaf 100644 --- a/source/blender/editors/object/object_transform.cc +++ b/source/blender/editors/object/object_transform.cc @@ -43,7 +43,7 @@ #include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_mball.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_multires.h" #include "BKE_object.h" #include "BKE_pointcloud.h" diff --git a/source/blender/editors/object/object_vgroup.cc b/source/blender/editors/object/object_vgroup.cc index 9cf1ff916fc..775b945bb1d 100644 --- a/source/blender/editors/object/object_vgroup.cc +++ b/source/blender/editors/object/object_vgroup.cc @@ -38,7 +38,7 @@ #include "BKE_editmesh.h" #include "BKE_lattice.h" #include "BKE_layer.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_mesh_runtime.h" #include "BKE_modifier.h" diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_add.cc b/source/blender/editors/sculpt_paint/curves_sculpt_add.cc index 432309a5e72..bb12782cad5 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_add.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_add.cc @@ -20,7 +20,7 @@ #include "BKE_curves.hh" #include "BKE_curves_utils.hh" #include "BKE_geometry_set.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_mesh_sample.hh" #include "BKE_modifier.h" diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_comb.cc b/source/blender/editors/sculpt_paint/curves_sculpt_comb.cc index 79c175caf5f..79b308626e1 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_comb.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_comb.cc @@ -23,7 +23,7 @@ #include "BKE_crazyspace.hh" #include "BKE_curves.hh" #include "BKE_geometry_set.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_paint.h" diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_delete.cc b/source/blender/editors/sculpt_paint/curves_sculpt_delete.cc index 3b2e9d5735c..a8c8501f07c 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_delete.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_delete.cc @@ -19,7 +19,7 @@ #include "BKE_bvhutils.h" #include "BKE_context.h" #include "BKE_curves.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_paint.h" diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_density.cc b/source/blender/editors/sculpt_paint/curves_sculpt_density.cc index cbdaaab4dc5..4149934341e 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_density.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_density.cc @@ -7,7 +7,7 @@ #include "BKE_bvhutils.h" #include "BKE_context.h" #include "BKE_geometry_set.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_mesh_sample.hh" #include "BKE_modifier.h" diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_puff.cc b/source/blender/editors/sculpt_paint/curves_sculpt_puff.cc index 26af897c0bf..f0745ef3d0d 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_puff.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_puff.cc @@ -5,7 +5,7 @@ #include "BKE_bvhutils.h" #include "BKE_context.h" #include "BKE_crazyspace.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "ED_screen.h" diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc b/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc index 20036994452..b4ce8ebc295 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc @@ -15,7 +15,7 @@ #include "BKE_bvhutils.h" #include "BKE_context.h" #include "BKE_curves.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_sample.hh" #include "BKE_object.h" #include "BKE_paint.h" diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_snake_hook.cc b/source/blender/editors/sculpt_paint/curves_sculpt_snake_hook.cc index 6c70b491265..13fc169a0e7 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_snake_hook.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_snake_hook.cc @@ -20,7 +20,7 @@ #include "BKE_bvhutils.h" #include "BKE_context.h" #include "BKE_curves.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_paint.h" diff --git a/source/blender/editors/sculpt_paint/paint_hide.cc b/source/blender/editors/sculpt_paint/paint_hide.cc index 6a5acfccb62..9526beee2b1 100644 --- a/source/blender/editors/sculpt_paint/paint_hide.cc +++ b/source/blender/editors/sculpt_paint/paint_hide.cc @@ -19,7 +19,7 @@ #include "BKE_ccg.h" #include "BKE_context.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_multires.h" #include "BKE_paint.h" #include "BKE_pbvh.h" diff --git a/source/blender/editors/sculpt_paint/paint_image.cc b/source/blender/editors/sculpt_paint/paint_image.cc index bedf7b588b2..964b9de69e6 100644 --- a/source/blender/editors/sculpt_paint/paint_image.cc +++ b/source/blender/editors/sculpt_paint/paint_image.cc @@ -33,7 +33,7 @@ #include "BKE_image.h" #include "BKE_main.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_node_runtime.hh" #include "BKE_object.h" #include "BKE_paint.h" diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.cc b/source/blender/editors/sculpt_paint/paint_image_proj.cc index 14f7067b15a..8777feef1cd 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.cc +++ b/source/blender/editors/sculpt_paint/paint_image_proj.cc @@ -60,7 +60,7 @@ #include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_mesh_runtime.h" #include "BKE_node.h" diff --git a/source/blender/editors/sculpt_paint/paint_mask.cc b/source/blender/editors/sculpt_paint/paint_mask.cc index d06dc91af68..1f98c0fecb5 100644 --- a/source/blender/editors/sculpt_paint/paint_mask.cc +++ b/source/blender/editors/sculpt_paint/paint_mask.cc @@ -28,7 +28,7 @@ #include "BKE_ccg.h" #include "BKE_context.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_multires.h" #include "BKE_paint.h" #include "BKE_pbvh.h" diff --git a/source/blender/editors/sculpt_paint/paint_vertex.cc b/source/blender/editors/sculpt_paint/paint_vertex.cc index e18b9274c5e..70ebd7fc077 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.cc +++ b/source/blender/editors/sculpt_paint/paint_vertex.cc @@ -38,7 +38,7 @@ #include "BKE_deform.h" #include "BKE_editmesh.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_object.h" #include "BKE_object_deform.h" diff --git a/source/blender/editors/sculpt_paint/paint_vertex_color_ops.cc b/source/blender/editors/sculpt_paint/paint_vertex_color_ops.cc index 49fbff114f1..92f3f79a44e 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_color_ops.cc +++ b/source/blender/editors/sculpt_paint/paint_vertex_color_ops.cc @@ -21,7 +21,7 @@ #include "BKE_context.h" #include "BKE_deform.h" #include "BKE_geometry_set.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "DEG_depsgraph.h" diff --git a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc index a40c4a38178..e0a0b8a5be8 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc +++ b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc @@ -23,7 +23,7 @@ #include "BKE_colortools.h" #include "BKE_context.h" #include "BKE_deform.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_iterators.h" #include "BKE_mesh_runtime.h" #include "BKE_modifier.h" diff --git a/source/blender/editors/sculpt_paint/sculpt.cc b/source/blender/editors/sculpt_paint/sculpt.cc index 077a16cf4df..668fc4312ff 100644 --- a/source/blender/editors/sculpt_paint/sculpt.cc +++ b/source/blender/editors/sculpt_paint/sculpt.cc @@ -42,7 +42,7 @@ #include "BKE_key.h" #include "BKE_lib_id.h" #include "BKE_main.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_modifier.h" #include "BKE_multires.h" diff --git a/source/blender/editors/sculpt_paint/sculpt_automasking.cc b/source/blender/editors/sculpt_paint/sculpt_automasking.cc index d7f1e0def14..c7df5d6d92b 100644 --- a/source/blender/editors/sculpt_paint/sculpt_automasking.cc +++ b/source/blender/editors/sculpt_paint/sculpt_automasking.cc @@ -24,7 +24,7 @@ #include "BKE_brush.h" #include "BKE_colortools.h" #include "BKE_context.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_object.h" #include "BKE_paint.h" diff --git a/source/blender/editors/sculpt_paint/sculpt_dyntopo.cc b/source/blender/editors/sculpt_paint/sculpt_dyntopo.cc index 570e2e1cab3..b5f5ad85776 100644 --- a/source/blender/editors/sculpt_paint/sculpt_dyntopo.cc +++ b/source/blender/editors/sculpt_paint/sculpt_dyntopo.cc @@ -19,7 +19,7 @@ #include "BKE_context.h" #include "BKE_global.h" #include "BKE_main.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_object.h" #include "BKE_paint.h" diff --git a/source/blender/editors/sculpt_paint/sculpt_expand.cc b/source/blender/editors/sculpt_paint/sculpt_expand.cc index 32c79f302a1..a8f2634151f 100644 --- a/source/blender/editors/sculpt_paint/sculpt_expand.cc +++ b/source/blender/editors/sculpt_paint/sculpt_expand.cc @@ -25,7 +25,7 @@ #include "BKE_colortools.h" #include "BKE_context.h" #include "BKE_image.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_paint.h" #include "BKE_pbvh.h" diff --git a/source/blender/editors/sculpt_paint/sculpt_face_set.cc b/source/blender/editors/sculpt_paint/sculpt_face_set.cc index 535e881a716..81a86b3c001 100644 --- a/source/blender/editors/sculpt_paint/sculpt_face_set.cc +++ b/source/blender/editors/sculpt_paint/sculpt_face_set.cc @@ -34,7 +34,7 @@ #include "BKE_colortools.h" #include "BKE_context.h" #include "BKE_customdata.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_fair.h" #include "BKE_mesh_mapping.h" #include "BKE_object.h" @@ -113,6 +113,7 @@ static void do_draw_face_sets_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls) { + using namespace blender; SculptThreadedTaskData *data = static_cast(userdata); SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; @@ -125,7 +126,10 @@ 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); - const float(*positions)[3] = SCULPT_mesh_deformed_positions_get(ss); + const Span positions( + reinterpret_cast(SCULPT_mesh_deformed_positions_get(ss)), + SCULPT_vertex_count_get(ss)); + const Span loops(ss->mloop, data->me->totloop); AutomaskingNodeData automask_data; SCULPT_automasking_node_begin( data->ob, ss, ss->cache->automasking, &automask_data, data->nodes[n]); @@ -139,8 +143,8 @@ static void do_draw_face_sets_brush_task_cb_ex(void *__restrict userdata, for (int j = 0; j < ss->pmap[vd.index].count; j++) { const MPoly &poly = ss->polys[vert_map->indices[j]]; - float poly_center[3]; - BKE_mesh_calc_poly_center(&poly, &ss->mloop[poly.loopstart], positions, poly_center); + const float3 poly_center = bke::mesh::poly_center_calc( + positions, loops.slice(poly.loopstart, poly.totloop)); if (!sculpt_brush_test_sq_fn(&test, poly_center)) { continue; diff --git a/source/blender/editors/sculpt_paint/sculpt_geodesic.cc b/source/blender/editors/sculpt_paint/sculpt_geodesic.cc index 762cb8cabbe..33fc931fca8 100644 --- a/source/blender/editors/sculpt_paint/sculpt_geodesic.cc +++ b/source/blender/editors/sculpt_paint/sculpt_geodesic.cc @@ -21,7 +21,7 @@ #include "BKE_ccg.h" #include "BKE_context.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_object.h" #include "BKE_paint.h" diff --git a/source/blender/editors/sculpt_paint/sculpt_ops.cc b/source/blender/editors/sculpt_paint/sculpt_ops.cc index 9a975fb5ced..255e24dd571 100644 --- a/source/blender/editors/sculpt_paint/sculpt_ops.cc +++ b/source/blender/editors/sculpt_paint/sculpt_ops.cc @@ -32,7 +32,7 @@ #include "BKE_context.h" #include "BKE_layer.h" #include "BKE_main.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mirror.h" #include "BKE_modifier.h" #include "BKE_multires.h" diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.cc b/source/blender/editors/sculpt_paint/sculpt_undo.cc index cba8a1b4690..05d60982780 100644 --- a/source/blender/editors/sculpt_paint/sculpt_undo.cc +++ b/source/blender/editors/sculpt_paint/sculpt_undo.cc @@ -55,7 +55,7 @@ #include "BKE_key.h" #include "BKE_layer.h" #include "BKE_main.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_multires.h" #include "BKE_object.h" diff --git a/source/blender/editors/space_info/info_stats.cc b/source/blender/editors/space_info/info_stats.cc index 6fc3229f948..49117e500a5 100644 --- a/source/blender/editors/space_info/info_stats.cc +++ b/source/blender/editors/space_info/info_stats.cc @@ -40,7 +40,7 @@ #include "BKE_key.h" #include "BKE_layer.h" #include "BKE_main.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "BKE_paint.h" #include "BKE_particle.h" diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc b/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc index b95efed52a3..e0c2a6852af 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc @@ -13,7 +13,7 @@ #include "BKE_global.h" #include "BKE_instances.hh" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_wrapper.h" #include "BKE_modifier.h" #include "BKE_volume.h" diff --git a/source/blender/editors/space_view3d/drawobject.cc b/source/blender/editors/space_view3d/drawobject.cc index b7d016e3040..835b2d6d0d0 100644 --- a/source/blender/editors/space_view3d/drawobject.cc +++ b/source/blender/editors/space_view3d/drawobject.cc @@ -16,7 +16,7 @@ #include "BKE_customdata.h" #include "BKE_editmesh.h" #include "BKE_global.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_object.h" diff --git a/source/blender/editors/space_view3d/space_view3d.cc b/source/blender/editors/space_view3d/space_view3d.cc index 475d8ee124f..52236ca436c 100644 --- a/source/blender/editors/space_view3d/space_view3d.cc +++ b/source/blender/editors/space_view3d/space_view3d.cc @@ -41,7 +41,7 @@ #include "BKE_lib_remap.h" #include "BKE_main.h" #include "BKE_mball.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "BKE_scene.h" #include "BKE_screen.h" diff --git a/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.cc b/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.cc index b3310f6084b..83ea8310e45 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.cc +++ b/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.cc @@ -22,7 +22,7 @@ #include "BKE_editmesh_cache.h" #include "BKE_global.h" #include "BKE_layer.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" diff --git a/source/blender/editors/space_view3d/view3d_iterators.cc b/source/blender/editors/space_view3d/view3d_iterators.cc index e7e8eb5b275..3cd9d3c9d52 100644 --- a/source/blender/editors/space_view3d/view3d_iterators.cc +++ b/source/blender/editors/space_view3d/view3d_iterators.cc @@ -23,7 +23,7 @@ #include "BKE_curve.h" #include "BKE_displist.h" #include "BKE_editmesh.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_iterators.h" #include "BKE_mesh_runtime.h" #include "BKE_mesh_wrapper.h" diff --git a/source/blender/editors/space_view3d/view3d_select.cc b/source/blender/editors/space_view3d/view3d_select.cc index 09f916428d1..751b181bd3f 100644 --- a/source/blender/editors/space_view3d/view3d_select.cc +++ b/source/blender/editors/space_view3d/view3d_select.cc @@ -53,7 +53,7 @@ #include "BKE_editmesh.h" #include "BKE_layer.h" #include "BKE_mball.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "BKE_paint.h" #include "BKE_scene.h" diff --git a/source/blender/editors/transform/transform_snap_object.cc b/source/blender/editors/transform/transform_snap_object.cc index d50b95899b4..e4c30900929 100644 --- a/source/blender/editors/transform/transform_snap_object.cc +++ b/source/blender/editors/transform/transform_snap_object.cc @@ -34,7 +34,7 @@ #include "BKE_geometry_set.h" #include "BKE_global.h" #include "BKE_layer.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_mesh_wrapper.h" #include "BKE_object.h" diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.cc b/source/blender/editors/uvedit/uvedit_unwrap_ops.cc index 52df0876733..5e209937517 100644 --- a/source/blender/editors/uvedit/uvedit_unwrap_ops.cc +++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.cc @@ -39,7 +39,7 @@ #include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_report.h" #include "BKE_scene.h" #include "BKE_subdiv.h" diff --git a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp index eac5de3b150..3b9670a9d9b 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp +++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp @@ -10,6 +10,7 @@ #include "BKE_attribute.hh" #include "BKE_global.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include @@ -410,12 +411,7 @@ void BlenderFileLoader::insertShapeNode(Object *ob, Mesh *me, int id) // 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(), - reinterpret_cast(vert_positions.data()), - me->totloop, - me->totpoly, - mlooptri); + blender::bke::mesh::looptris_calc(vert_positions, mesh_polys, mesh_loops, {mlooptri, tottri}); // Compute loop normals BKE_mesh_calc_normals_split(me); diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp index 40f49b458f4..6403eb47dde 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp +++ b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp @@ -35,7 +35,7 @@ #include "BKE_lib_id.h" /* free_libblock */ #include "BKE_main.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_node.h" #include "BKE_node_tree_update.h" #include "BKE_object.h" diff --git a/source/blender/geometry/intern/add_curves_on_mesh.cc b/source/blender/geometry/intern/add_curves_on_mesh.cc index aee002c49cd..ec066307f76 100644 --- a/source/blender/geometry/intern/add_curves_on_mesh.cc +++ b/source/blender/geometry/intern/add_curves_on_mesh.cc @@ -5,7 +5,7 @@ #include "BLI_task.hh" #include "BKE_attribute_math.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_sample.hh" #include "GEO_add_curves_on_mesh.hh" diff --git a/source/blender/geometry/intern/mesh_merge_by_distance.cc b/source/blender/geometry/intern/mesh_merge_by_distance.cc index cd3188c63b5..ebd2883abdc 100644 --- a/source/blender/geometry/intern/mesh_merge_by_distance.cc +++ b/source/blender/geometry/intern/mesh_merge_by_distance.cc @@ -13,7 +13,7 @@ #include "DNA_meshdata_types.h" #include "BKE_customdata.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "GEO_mesh_merge_by_distance.hh" diff --git a/source/blender/geometry/intern/mesh_primitive_cuboid.cc b/source/blender/geometry/intern/mesh_primitive_cuboid.cc index ab2dc2e8c0a..6032b19ac25 100644 --- a/source/blender/geometry/intern/mesh_primitive_cuboid.cc +++ b/source/blender/geometry/intern/mesh_primitive_cuboid.cc @@ -8,7 +8,7 @@ #include "DNA_meshdata_types.h" #include "BKE_geometry_set.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "GEO_mesh_primitive_cuboid.hh" diff --git a/source/blender/geometry/intern/mesh_split_edges.cc b/source/blender/geometry/intern/mesh_split_edges.cc index 91b28652bbe..27664154e34 100644 --- a/source/blender/geometry/intern/mesh_split_edges.cc +++ b/source/blender/geometry/intern/mesh_split_edges.cc @@ -6,7 +6,7 @@ #include "BKE_attribute.hh" #include "BKE_attribute_math.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "GEO_mesh_split_edges.hh" diff --git a/source/blender/geometry/intern/mesh_to_curve_convert.cc b/source/blender/geometry/intern/mesh_to_curve_convert.cc index 22c925a1310..e3b630c37b0 100644 --- a/source/blender/geometry/intern/mesh_to_curve_convert.cc +++ b/source/blender/geometry/intern/mesh_to_curve_convert.cc @@ -12,7 +12,7 @@ #include "BKE_attribute_math.hh" #include "BKE_curves.hh" #include "BKE_geometry_set.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "GEO_mesh_to_curve.hh" diff --git a/source/blender/geometry/intern/mesh_to_volume.cc b/source/blender/geometry/intern/mesh_to_volume.cc index ba3b47f47ad..d098f6ce584 100644 --- a/source/blender/geometry/intern/mesh_to_volume.cc +++ b/source/blender/geometry/intern/mesh_to_volume.cc @@ -2,7 +2,7 @@ #include "BLI_math_matrix.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_volume.h" diff --git a/source/blender/geometry/intern/realize_instances.cc b/source/blender/geometry/intern/realize_instances.cc index 142e62ca8ec..3a6b92c6e93 100644 --- a/source/blender/geometry/intern/realize_instances.cc +++ b/source/blender/geometry/intern/realize_instances.cc @@ -19,7 +19,7 @@ #include "BKE_geometry_set_instances.hh" #include "BKE_instances.hh" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_pointcloud.h" #include "BKE_type_conversions.hh" diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.cc b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.cc index c0890df8aea..8926c92f252 100644 --- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.cc +++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.cc @@ -32,7 +32,7 @@ #include "BKE_gpencil_modifier.h" #include "BKE_lib_id.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_mesh_runtime.h" #include "BKE_object.h" diff --git a/source/blender/gpu/intern/gpu_shader_builder_stubs.cc b/source/blender/gpu/intern/gpu_shader_builder_stubs.cc index bbd71d4e3fe..2c08d0f4061 100644 --- a/source/blender/gpu/intern/gpu_shader_builder_stubs.cc +++ b/source/blender/gpu/intern/gpu_shader_builder_stubs.cc @@ -16,7 +16,7 @@ #include "BKE_customdata.h" #include "BKE_global.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_node.h" #include "BKE_paint.h" #include "BKE_pbvh.h" @@ -146,14 +146,6 @@ bool paint_is_grid_face_hidden(const uint * /*grid_hidden*/, /* -------------------------------------------------------------------- */ /** \name Stubs of BKE_mesh.h * \{ */ -void BKE_mesh_calc_poly_normal(const struct MPoly * /*polys*/, - const struct MLoop * /*loopstart*/, - const float (*vert_positions)[3], - float[3] /*col*/) -{ - UNUSED_VARS(vert_positions); - BLI_assert_unreachable(); -} void BKE_mesh_looptri_get_real_edges(const struct MEdge * /*edges*/, const struct MLoop * /*loops*/, diff --git a/source/blender/io/alembic/exporter/abc_writer_curves.cc b/source/blender/io/alembic/exporter/abc_writer_curves.cc index e5e8053d7d3..03cd6e2120a 100644 --- a/source/blender/io/alembic/exporter/abc_writer_curves.cc +++ b/source/blender/io/alembic/exporter/abc_writer_curves.cc @@ -12,7 +12,7 @@ #include "DNA_object_types.h" #include "BKE_curve.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "CLG_log.h" diff --git a/source/blender/io/alembic/exporter/abc_writer_hair.cc b/source/blender/io/alembic/exporter/abc_writer_hair.cc index 9b043cf0583..127ca959dbe 100644 --- a/source/blender/io/alembic/exporter/abc_writer_hair.cc +++ b/source/blender/io/alembic/exporter/abc_writer_hair.cc @@ -17,7 +17,7 @@ #include "BLI_math_geom.h" #include "BKE_customdata.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_legacy_convert.h" #include "BKE_mesh_runtime.h" #include "BKE_particle.h" diff --git a/source/blender/io/alembic/exporter/abc_writer_mball.cc b/source/blender/io/alembic/exporter/abc_writer_mball.cc index e1d4e9c7494..d92e3ed6bd4 100644 --- a/source/blender/io/alembic/exporter/abc_writer_mball.cc +++ b/source/blender/io/alembic/exporter/abc_writer_mball.cc @@ -12,7 +12,7 @@ #include "BKE_displist.h" #include "BKE_lib_id.h" #include "BKE_mball.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "DNA_mesh_types.h" diff --git a/source/blender/io/alembic/exporter/abc_writer_mesh.cc b/source/blender/io/alembic/exporter/abc_writer_mesh.cc index 312aff79191..af619db9417 100644 --- a/source/blender/io/alembic/exporter/abc_writer_mesh.cc +++ b/source/blender/io/alembic/exporter/abc_writer_mesh.cc @@ -16,7 +16,7 @@ #include "BKE_customdata.h" #include "BKE_lib_id.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_object.h" diff --git a/source/blender/io/alembic/intern/abc_customdata.cc b/source/blender/io/alembic/intern/abc_customdata.cc index c39619d7aff..dd048ee8dd4 100644 --- a/source/blender/io/alembic/intern/abc_customdata.cc +++ b/source/blender/io/alembic/intern/abc_customdata.cc @@ -20,7 +20,7 @@ #include "BLI_utildefines.h" #include "BKE_customdata.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" /* NOTE: for now only UVs and Vertex Colors are supported for streaming. * Although Alembic only allows for a single UV layer per {I|O}Schema, and does diff --git a/source/blender/io/alembic/intern/abc_reader_curves.cc b/source/blender/io/alembic/intern/abc_reader_curves.cc index 24bdae3ac50..e898b932e3f 100644 --- a/source/blender/io/alembic/intern/abc_reader_curves.cc +++ b/source/blender/io/alembic/intern/abc_reader_curves.cc @@ -20,7 +20,7 @@ #include "BLI_listbase.h" #include "BKE_curve.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" using Alembic::Abc::FloatArraySamplePtr; diff --git a/source/blender/io/alembic/intern/abc_reader_mesh.cc b/source/blender/io/alembic/intern/abc_reader_mesh.cc index 3789b656468..681930d97cf 100644 --- a/source/blender/io/alembic/intern/abc_reader_mesh.cc +++ b/source/blender/io/alembic/intern/abc_reader_mesh.cc @@ -29,7 +29,7 @@ #include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_object.h" diff --git a/source/blender/io/alembic/intern/abc_reader_points.cc b/source/blender/io/alembic/intern/abc_reader_points.cc index 85dad608d89..5588cb54cc4 100644 --- a/source/blender/io/alembic/intern/abc_reader_points.cc +++ b/source/blender/io/alembic/intern/abc_reader_points.cc @@ -15,7 +15,7 @@ #include "DNA_object_types.h" #include "BKE_customdata.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" using Alembic::AbcGeom::kWrapExisting; diff --git a/source/blender/io/collada/ArmatureExporter.cpp b/source/blender/io/collada/ArmatureExporter.cpp index 3cc98917116..57686d2181f 100644 --- a/source/blender/io/collada/ArmatureExporter.cpp +++ b/source/blender/io/collada/ArmatureExporter.cpp @@ -16,7 +16,7 @@ #include "BKE_action.h" #include "BKE_armature.h" #include "BKE_global.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "ED_armature.h" diff --git a/source/blender/io/collada/ControllerExporter.cpp b/source/blender/io/collada/ControllerExporter.cpp index 62bcdc5bf4c..994ffb00084 100644 --- a/source/blender/io/collada/ControllerExporter.cpp +++ b/source/blender/io/collada/ControllerExporter.cpp @@ -19,7 +19,7 @@ #include "BKE_global.h" #include "BKE_idprop.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "ED_armature.h" diff --git a/source/blender/io/collada/EffectExporter.cpp b/source/blender/io/collada/EffectExporter.cpp index d53f8c0997c..2f796a14818 100644 --- a/source/blender/io/collada/EffectExporter.cpp +++ b/source/blender/io/collada/EffectExporter.cpp @@ -23,7 +23,7 @@ #include "BKE_collection.h" #include "BKE_customdata.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" static std::string getActiveUVLayerName(Object *ob) { diff --git a/source/blender/io/collada/GeometryExporter.cpp b/source/blender/io/collada/GeometryExporter.cpp index fd6f66187c4..59038c41863 100644 --- a/source/blender/io/collada/GeometryExporter.cpp +++ b/source/blender/io/collada/GeometryExporter.cpp @@ -23,7 +23,7 @@ #include "BKE_global.h" #include "BKE_lib_id.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "collada_internal.h" #include "collada_utils.h" @@ -643,11 +643,8 @@ void GeometryExporter::create_normals(std::vector &normals, if (!use_vert_normals) { /* For flat faces use face normal as vertex normal: */ - float vector[3]; - BKE_mesh_calc_poly_normal(poly, - &loops[poly->loopstart], - reinterpret_cast(positions.data()), - vector); + const float3 vector = blender::bke::mesh::poly_normal_calc( + positions, loops.slice(poly->loopstart, poly->totloop)); Normal n = {vector[0], vector[1], vector[2]}; normals.push_back(n); diff --git a/source/blender/io/collada/ImageExporter.cpp b/source/blender/io/collada/ImageExporter.cpp index 070eb36de31..a5c14ec3377 100644 --- a/source/blender/io/collada/ImageExporter.cpp +++ b/source/blender/io/collada/ImageExporter.cpp @@ -16,7 +16,7 @@ #include "BKE_image.h" #include "BKE_image_format.h" #include "BKE_main.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BLI_fileops.h" #include "BLI_path_util.h" diff --git a/source/blender/io/collada/MeshImporter.cpp b/source/blender/io/collada/MeshImporter.cpp index 110ad37384c..1a2bf5ea9ec 100644 --- a/source/blender/io/collada/MeshImporter.cpp +++ b/source/blender/io/collada/MeshImporter.cpp @@ -22,7 +22,7 @@ #include "BKE_global.h" #include "BKE_lib_id.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "BLI_edgehash.h" diff --git a/source/blender/io/collada/collada_utils.cpp b/source/blender/io/collada/collada_utils.cpp index a71fbd50a2e..6b6afdfda2f 100644 --- a/source/blender/io/collada/collada_utils.cpp +++ b/source/blender/io/collada/collada_utils.cpp @@ -39,7 +39,7 @@ #include "BKE_layer.h" #include "BKE_lib_id.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_legacy_convert.h" #include "BKE_mesh_runtime.h" #include "BKE_node.h" diff --git a/source/blender/io/ply/exporter/ply_export_load_plydata.cc b/source/blender/io/ply/exporter/ply_export_load_plydata.cc index 959efe41bf6..6cf09474d61 100644 --- a/source/blender/io/ply/exporter/ply_export_load_plydata.cc +++ b/source/blender/io/ply/exporter/ply_export_load_plydata.cc @@ -9,7 +9,7 @@ #include "BKE_attribute.hh" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_object.h" diff --git a/source/blender/io/ply/importer/ply_import.cc b/source/blender/io/ply/importer/ply_import.cc index 45d07b006fd..6454c021701 100644 --- a/source/blender/io/ply/importer/ply_import.cc +++ b/source/blender/io/ply/importer/ply_import.cc @@ -6,7 +6,7 @@ #include "BKE_layer.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "BKE_report.h" diff --git a/source/blender/io/ply/importer/ply_import_mesh.cc b/source/blender/io/ply/importer/ply_import_mesh.cc index 49a99e458e1..a34cca48c83 100644 --- a/source/blender/io/ply/importer/ply_import_mesh.cc +++ b/source/blender/io/ply/importer/ply_import_mesh.cc @@ -7,7 +7,7 @@ #include "BKE_attribute.h" #include "BKE_attribute.hh" #include "BKE_customdata.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "GEO_mesh_merge_by_distance.hh" diff --git a/source/blender/io/ply/tests/io_ply_importer_test.cc b/source/blender/io/ply/tests/io_ply_importer_test.cc index 32ba55f1eaa..c3e01727fae 100644 --- a/source/blender/io/ply/tests/io_ply_importer_test.cc +++ b/source/blender/io/ply/tests/io_ply_importer_test.cc @@ -3,7 +3,7 @@ #include "tests/blendfile_loading_base_test.h" #include "BKE_attribute.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "BLO_readfile.h" diff --git a/source/blender/io/stl/importer/stl_import.cc b/source/blender/io/stl/importer/stl_import.cc index e5fde6658ab..2f32b9270f3 100644 --- a/source/blender/io/stl/importer/stl_import.cc +++ b/source/blender/io/stl/importer/stl_import.cc @@ -8,7 +8,7 @@ #include "BKE_customdata.h" #include "BKE_layer.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "DNA_collection_types.h" diff --git a/source/blender/io/stl/importer/stl_import_ascii_reader.cc b/source/blender/io/stl/importer/stl_import_ascii_reader.cc index 6a976a2fd2c..8bfe4924cc5 100644 --- a/source/blender/io/stl/importer/stl_import_ascii_reader.cc +++ b/source/blender/io/stl/importer/stl_import_ascii_reader.cc @@ -7,7 +7,7 @@ #include #include -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BLI_fileops.hh" #include "BLI_memory_utils.hh" diff --git a/source/blender/io/stl/importer/stl_import_binary_reader.cc b/source/blender/io/stl/importer/stl_import_binary_reader.cc index fb9dcea0a1d..26d9e3406e7 100644 --- a/source/blender/io/stl/importer/stl_import_binary_reader.cc +++ b/source/blender/io/stl/importer/stl_import_binary_reader.cc @@ -8,7 +8,7 @@ #include #include "BKE_main.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BLI_array.hh" #include "BLI_memory_utils.hh" diff --git a/source/blender/io/stl/importer/stl_import_mesh.cc b/source/blender/io/stl/importer/stl_import_mesh.cc index 3a87c4e3559..43aac4333e8 100644 --- a/source/blender/io/stl/importer/stl_import_mesh.cc +++ b/source/blender/io/stl/importer/stl_import_mesh.cc @@ -7,7 +7,7 @@ #include "BKE_customdata.h" #include "BKE_lib_id.h" #include "BKE_main.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BLI_array.hh" #include "BLI_math_vector.h" diff --git a/source/blender/io/usd/intern/usd_reader_curve.cc b/source/blender/io/usd/intern/usd_reader_curve.cc index 32bbfc83c17..e967b258ae9 100644 --- a/source/blender/io/usd/intern/usd_reader_curve.cc +++ b/source/blender/io/usd/intern/usd_reader_curve.cc @@ -5,7 +5,7 @@ #include "usd_reader_curve.h" #include "BKE_curve.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "BLI_listbase.h" diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc index 88aeeac3314..920795d03fb 100644 --- a/source/blender/io/usd/intern/usd_reader_mesh.cc +++ b/source/blender/io/usd/intern/usd_reader_mesh.cc @@ -10,7 +10,7 @@ #include "BKE_customdata.h" #include "BKE_main.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "BLI_math.h" diff --git a/source/blender/io/usd/intern/usd_reader_nurbs.cc b/source/blender/io/usd/intern/usd_reader_nurbs.cc index 8e070dea915..7e644632980 100644 --- a/source/blender/io/usd/intern/usd_reader_nurbs.cc +++ b/source/blender/io/usd/intern/usd_reader_nurbs.cc @@ -5,7 +5,7 @@ #include "usd_reader_nurbs.h" #include "BKE_curve.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "BLI_listbase.h" diff --git a/source/blender/io/usd/intern/usd_reader_shape.cc b/source/blender/io/usd/intern/usd_reader_shape.cc index 3ebddedf208..58ef6d5cd36 100644 --- a/source/blender/io/usd/intern/usd_reader_shape.cc +++ b/source/blender/io/usd/intern/usd_reader_shape.cc @@ -2,7 +2,7 @@ * Copyright 2023 Nvidia. All rights reserved. */ #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_object.h" diff --git a/source/blender/io/usd/intern/usd_writer_mesh.cc b/source/blender/io/usd/intern/usd_writer_mesh.cc index 6dd1ec80ae8..7d770c7e8eb 100644 --- a/source/blender/io/usd/intern/usd_writer_mesh.cc +++ b/source/blender/io/usd/intern/usd_writer_mesh.cc @@ -18,7 +18,7 @@ #include "BKE_customdata.h" #include "BKE_lib_id.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_wrapper.h" #include "BKE_modifier.h" #include "BKE_object.h" diff --git a/source/blender/io/usd/intern/usd_writer_metaball.cc b/source/blender/io/usd/intern/usd_writer_metaball.cc index b83dd191869..e42da192b61 100644 --- a/source/blender/io/usd/intern/usd_writer_metaball.cc +++ b/source/blender/io/usd/intern/usd_writer_metaball.cc @@ -12,7 +12,7 @@ #include "BKE_displist.h" #include "BKE_lib_id.h" #include "BKE_mball.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "DNA_mesh_types.h" diff --git a/source/blender/io/usd/tests/usd_export_test.cc b/source/blender/io/usd/tests/usd_export_test.cc index 580e65a378b..fe9d35254ca 100644 --- a/source/blender/io/usd/tests/usd_export_test.cc +++ b/source/blender/io/usd/tests/usd_export_test.cc @@ -21,7 +21,7 @@ #include "BKE_context.h" #include "BKE_lib_id.h" #include "BKE_main.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_node.h" #include "BLI_fileops.h" #include "BLI_math.h" diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc b/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc index 6957e07dadd..8ae878f2222 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc @@ -9,7 +9,7 @@ #include "BKE_attribute.hh" #include "BKE_blender_version.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BLI_color.hh" #include "BLI_enumerable_thread_specific.hh" 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 0696ac29137..53c82330f74 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc @@ -9,7 +9,7 @@ #include "BKE_deform.h" #include "BKE_lib_id.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_object.h" @@ -361,12 +361,9 @@ Span 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 MPoly &poly = mesh_polys_[poly_index]; - BKE_mesh_calc_poly_normal(&poly, - &mesh_loops_[poly.loopstart], - reinterpret_cast(mesh_positions_.data()), - r_poly_normal); + float3 r_poly_normal = bke::mesh::poly_normal_calc( + mesh_positions_, mesh_loops_.slice(poly.loopstart, poly.totloop)); 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/importer_mesh_utils.cc b/source/blender/io/wavefront_obj/importer/importer_mesh_utils.cc index 204237088ab..19fe1465e85 100644 --- a/source/blender/io/wavefront_obj/importer/importer_mesh_utils.cc +++ b/source/blender/io/wavefront_obj/importer/importer_mesh_utils.cc @@ -4,7 +4,7 @@ * \ingroup obj */ -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "BLI_delaunay_2d.h" 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 c572e465aa6..5a24020d0e4 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc @@ -12,7 +12,7 @@ #include "BKE_customdata.h" #include "BKE_deform.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_node_tree_update.h" #include "BKE_object.h" #include "BKE_object_deform.h" 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 62998a51d76..1fbafef84cb 100644 --- a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc @@ -9,7 +9,7 @@ #include "BKE_customdata.h" #include "BKE_main.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "BKE_scene.h" diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index 5330b7f9957..4253df23793 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -630,7 +630,8 @@ static void rna_MeshPolygon_normal_get(PointerRNA *ptr, float *values) MPoly *poly = (MPoly *)ptr->data; const float(*positions)[3] = BKE_mesh_vert_positions(me); const MLoop *loops = BKE_mesh_loops(me); - BKE_mesh_calc_poly_normal(poly, loops + poly->loopstart, positions, values); + BKE_mesh_calc_poly_normal( + &loops[poly->loopstart], poly->totloop, positions, me->totvert, values); } static bool rna_MeshPolygon_hide_get(PointerRNA *ptr) @@ -733,7 +734,8 @@ static void rna_MeshPolygon_center_get(PointerRNA *ptr, float *values) MPoly *poly = (MPoly *)ptr->data; const float(*positions)[3] = BKE_mesh_vert_positions(me); const MLoop *loops = BKE_mesh_loops(me); - BKE_mesh_calc_poly_center(poly, loops + poly->loopstart, positions, values); + BKE_mesh_calc_poly_center( + &loops[poly->loopstart], poly->totloop, positions, me->totvert, values); } static float rna_MeshPolygon_area_get(PointerRNA *ptr) @@ -742,7 +744,7 @@ static float rna_MeshPolygon_area_get(PointerRNA *ptr) MPoly *poly = (MPoly *)ptr->data; const float(*positions)[3] = BKE_mesh_vert_positions(me); const MLoop *loops = BKE_mesh_loops(me); - return BKE_mesh_calc_poly_area(poly, loops + poly->loopstart, positions); + return BKE_mesh_calc_poly_area(&loops[poly->loopstart], poly->totloop, positions, me->totvert); } static void rna_MeshPolygon_flip(ID *id, MPoly *poly) diff --git a/source/blender/modifiers/intern/MOD_array.cc b/source/blender/modifiers/intern/MOD_array.cc index 9368b1014a3..a392c933fd3 100644 --- a/source/blender/modifiers/intern/MOD_array.cc +++ b/source/blender/modifiers/intern/MOD_array.cc @@ -31,7 +31,7 @@ #include "BKE_displist.h" #include "BKE_lib_id.h" #include "BKE_lib_query.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_object_deform.h" #include "BKE_screen.h" diff --git a/source/blender/modifiers/intern/MOD_boolean.cc b/source/blender/modifiers/intern/MOD_boolean.cc index 2be77dc6245..6bc7c045de6 100644 --- a/source/blender/modifiers/intern/MOD_boolean.cc +++ b/source/blender/modifiers/intern/MOD_boolean.cc @@ -32,7 +32,7 @@ #include "BKE_lib_id.h" #include "BKE_lib_query.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_boolean_convert.hh" #include "BKE_mesh_wrapper.h" #include "BKE_modifier.h" diff --git a/source/blender/modifiers/intern/MOD_build.cc b/source/blender/modifiers/intern/MOD_build.cc index 7b77b443d76..e4c28530bc1 100644 --- a/source/blender/modifiers/intern/MOD_build.cc +++ b/source/blender/modifiers/intern/MOD_build.cc @@ -24,7 +24,7 @@ #include "DEG_depsgraph_query.h" #include "BKE_context.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_particle.h" #include "BKE_scene.h" diff --git a/source/blender/modifiers/intern/MOD_correctivesmooth.cc b/source/blender/modifiers/intern/MOD_correctivesmooth.cc index ae1b3eb4a6f..7dfbe03ca84 100644 --- a/source/blender/modifiers/intern/MOD_correctivesmooth.cc +++ b/source/blender/modifiers/intern/MOD_correctivesmooth.cc @@ -26,7 +26,7 @@ #include "BKE_deform.h" #include "BKE_editmesh.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_wrapper.h" #include "BKE_screen.h" diff --git a/source/blender/modifiers/intern/MOD_datatransfer.cc b/source/blender/modifiers/intern/MOD_datatransfer.cc index 4bb36d9a791..fbce7ef6da9 100644 --- a/source/blender/modifiers/intern/MOD_datatransfer.cc +++ b/source/blender/modifiers/intern/MOD_datatransfer.cc @@ -22,7 +22,7 @@ #include "BKE_data_transfer.h" #include "BKE_lib_id.h" #include "BKE_lib_query.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_mesh_remap.h" #include "BKE_modifier.h" diff --git a/source/blender/modifiers/intern/MOD_displace.cc b/source/blender/modifiers/intern/MOD_displace.cc index 796bf63e79d..e3b3bd656a0 100644 --- a/source/blender/modifiers/intern/MOD_displace.cc +++ b/source/blender/modifiers/intern/MOD_displace.cc @@ -25,7 +25,7 @@ #include "BKE_image.h" #include "BKE_lib_id.h" #include "BKE_lib_query.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_wrapper.h" #include "BKE_modifier.h" #include "BKE_object.h" diff --git a/source/blender/modifiers/intern/MOD_explode.cc b/source/blender/modifiers/intern/MOD_explode.cc index 2e6a6847c79..40a8a8c99b1 100644 --- a/source/blender/modifiers/intern/MOD_explode.cc +++ b/source/blender/modifiers/intern/MOD_explode.cc @@ -27,7 +27,7 @@ #include "BKE_deform.h" #include "BKE_lattice.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_legacy_convert.h" #include "BKE_modifier.h" #include "BKE_particle.h" diff --git a/source/blender/modifiers/intern/MOD_laplaciandeform.cc b/source/blender/modifiers/intern/MOD_laplaciandeform.cc index 63947d5fd34..bc329d3e5bc 100644 --- a/source/blender/modifiers/intern/MOD_laplaciandeform.cc +++ b/source/blender/modifiers/intern/MOD_laplaciandeform.cc @@ -24,7 +24,7 @@ #include "BKE_deform.h" #include "BKE_editmesh.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_mesh_runtime.h" #include "BKE_mesh_wrapper.h" diff --git a/source/blender/modifiers/intern/MOD_laplaciansmooth.cc b/source/blender/modifiers/intern/MOD_laplaciansmooth.cc index 9577e10c0a3..7422f8d09bd 100644 --- a/source/blender/modifiers/intern/MOD_laplaciansmooth.cc +++ b/source/blender/modifiers/intern/MOD_laplaciansmooth.cc @@ -23,7 +23,7 @@ #include "BKE_deform.h" #include "BKE_editmesh.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_wrapper.h" #include "BKE_modifier.h" #include "BKE_screen.h" diff --git a/source/blender/modifiers/intern/MOD_mask.cc b/source/blender/modifiers/intern/MOD_mask.cc index af8739eec12..eddd3b09633 100644 --- a/source/blender/modifiers/intern/MOD_mask.cc +++ b/source/blender/modifiers/intern/MOD_mask.cc @@ -29,7 +29,7 @@ #include "BKE_customdata.h" #include "BKE_deform.h" #include "BKE_lib_query.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_screen.h" diff --git a/source/blender/modifiers/intern/MOD_meshsequencecache.cc b/source/blender/modifiers/intern/MOD_meshsequencecache.cc index e323c592b44..8e6a96f9945 100644 --- a/source/blender/modifiers/intern/MOD_meshsequencecache.cc +++ b/source/blender/modifiers/intern/MOD_meshsequencecache.cc @@ -26,7 +26,7 @@ #include "BKE_cachefile.h" #include "BKE_context.h" #include "BKE_lib_query.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_object.h" #include "BKE_scene.h" #include "BKE_screen.h" diff --git a/source/blender/modifiers/intern/MOD_multires.cc b/source/blender/modifiers/intern/MOD_multires.cc index 91a5c5bd102..528c5aee889 100644 --- a/source/blender/modifiers/intern/MOD_multires.cc +++ b/source/blender/modifiers/intern/MOD_multires.cc @@ -21,7 +21,7 @@ #include "BKE_cdderivedmesh.h" #include "BKE_context.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_multires.h" #include "BKE_paint.h" diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc index e4474d3b5ea..e0a3226eaf9 100644 --- a/source/blender/modifiers/intern/MOD_nodes.cc +++ b/source/blender/modifiers/intern/MOD_nodes.cc @@ -46,7 +46,7 @@ #include "BKE_lib_id.h" #include "BKE_lib_query.h" #include "BKE_main.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_node_runtime.hh" #include "BKE_node_tree_update.h" diff --git a/source/blender/modifiers/intern/MOD_normal_edit.cc b/source/blender/modifiers/intern/MOD_normal_edit.cc index 6ec413bc109..ec13844fbac 100644 --- a/source/blender/modifiers/intern/MOD_normal_edit.cc +++ b/source/blender/modifiers/intern/MOD_normal_edit.cc @@ -26,7 +26,7 @@ #include "BKE_deform.h" #include "BKE_lib_id.h" #include "BKE_lib_query.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_screen.h" #include "UI_interface.h" @@ -126,12 +126,12 @@ static void mix_normals(const float mix_factor, const short mix_mode, const int verts_num, const blender::Span loops, - float (*nos_old)[3], - float (*nos_new)[3]) + blender::float3 *nos_old, + blender::float3 *nos_new) { /* Mix with org normals... */ float *facs = nullptr, *wfac; - float(*no_new)[3], (*no_old)[3]; + blender::float3 *no_new, *no_old; int i; if (dvert) { @@ -174,7 +174,7 @@ static void mix_normals(const float mix_factor, /* Check poly normals and new loop normals are compatible, otherwise flip polygons * (and invert matching poly normals). */ static bool polygons_check_flip(blender::MutableSpan loops, - float (*nos)[3], + blender::float3 *nos, CustomData *ldata, const blender::Span polys, float (*poly_normals)[3]) @@ -186,11 +186,9 @@ static bool polygons_check_flip(blender::MutableSpan loops, for (const int i : polys.index_range()) { const MPoly &poly = polys[i]; float norsum[3] = {0.0f}; - float(*no)[3]; - int j; - for (j = 0, no = &nos[poly.loopstart]; j < poly.totloop; j++, no++) { - add_v3_v3(norsum, *no); + for (const int64_t j : blender::IndexRange(poly.loopstart, poly.totloop)) { + add_v3_v3(norsum, nos[j]); } if (!normalize_v3(norsum)) { @@ -199,7 +197,8 @@ static bool polygons_check_flip(blender::MutableSpan loops, /* If average of new loop normals is opposed to polygon normal, flip polygon. */ if (dot_v3v3(poly_normals[i], norsum) < 0.0f) { - BKE_mesh_polygon_flip_ex(&poly, loops.data(), ldata, nos, mdisp, true); + BKE_mesh_polygon_flip_ex( + &poly, loops.data(), ldata, reinterpret_cast(nos), mdisp, true); negate_v3(poly_normals[i]); flipped = true; } @@ -213,35 +212,32 @@ static void normalEditModifier_do_radial(NormalEditModifierData *enmd, Object *ob, Mesh *mesh, short (*clnors)[2], - float (*loop_normals)[3], - const float (*poly_normals)[3], + blender::MutableSpan loop_normals, + blender::Span poly_normals, const short mix_mode, const float mix_factor, const float mix_limit, const MDeformVert *dvert, const int defgrp_index, const bool use_invert_vgroup, - const float (*vert_positions)[3], - const int verts_num, + blender::Span vert_positions, const blender::Span edges, - bool *sharp_edges, + blender::MutableSpan sharp_edges, blender::MutableSpan loops, const blender::Span polys) { Object *ob_target = enmd->target; const bool do_polynors_fix = (enmd->flag & MOD_NORMALEDIT_NO_POLYNORS_FIX) == 0; - int i; float(*cos)[3] = static_cast( - MEM_malloc_arrayN(size_t(verts_num), sizeof(*cos), __func__)); - float(*nos)[3] = static_cast( - MEM_malloc_arrayN(size_t(loops.size()), sizeof(*nos), __func__)); + MEM_malloc_arrayN(size_t(vert_positions.size()), sizeof(*cos), __func__)); + blender::Array nos(loops.size()); float size[3]; - BLI_bitmap *done_verts = BLI_BITMAP_NEW(size_t(verts_num), __func__); + BLI_bitmap *done_verts = BLI_BITMAP_NEW(size_t(vert_positions.size()), __func__); - generate_vert_coordinates(mesh, ob, ob_target, enmd->offset, verts_num, cos, size); + generate_vert_coordinates(mesh, ob, ob_target, enmd->offset, vert_positions.size(), cos, size); /** * size gives us our spheroid coefficients `(A, B, C)`. @@ -279,12 +275,9 @@ static void normalEditModifier_do_radial(NormalEditModifierData *enmd, const float m2 = (b * b) / (a * a); const float n2 = (c * c) / (a * a); - const MLoop *ml; - float(*no)[3]; - /* We reuse cos to now store the ellipsoid-normal of the verts! */ - for (i = loops.size(), ml = loops.data(), no = nos; i--; ml++, no++) { - const int vidx = ml->v; + for (const int64_t i : loops.index_range()) { + const int vidx = loops[i].v; float *co = cos[vidx]; if (!BLI_BITMAP_TEST(done_verts, vidx)) { @@ -302,48 +295,43 @@ static void normalEditModifier_do_radial(NormalEditModifierData *enmd, BLI_BITMAP_ENABLE(done_verts, vidx); } - copy_v3_v3(*no, co); + nos[i] = co; } } - if (loop_normals) { + if (!loop_normals.is_empty()) { mix_normals(mix_factor, dvert, defgrp_index, use_invert_vgroup, mix_limit, mix_mode, - verts_num, + vert_positions.size(), loops, - loop_normals, - nos); + loop_normals.data(), + nos.data()); } if (do_polynors_fix && polygons_check_flip( - loops, nos, &mesh->ldata, polys, BKE_mesh_poly_normals_for_write(mesh))) { + loops, nos.data(), &mesh->ldata, polys, BKE_mesh_poly_normals_for_write(mesh))) { /* We need to recompute vertex normals! */ BKE_mesh_normals_tag_dirty(mesh); } const bool *sharp_faces = static_cast( CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, "sharp_face")); - BKE_mesh_normals_loop_custom_set(vert_positions, - BKE_mesh_vert_normals_ensure(mesh), - verts_num, - edges.data(), - edges.size(), - loops.data(), - nos, - loops.size(), - polys.data(), - poly_normals, - sharp_faces, - polys.size(), - sharp_edges, - clnors); + blender::bke::mesh::normals_loop_custom_set(vert_positions, + edges, + polys, + loops, + mesh->vert_normals(), + poly_normals, + sharp_faces, + sharp_edges, + nos, + clnors); MEM_freeN(cos); - MEM_freeN(nos); MEM_freeN(done_verts); } @@ -352,18 +340,17 @@ static void normalEditModifier_do_directional(NormalEditModifierData *enmd, Object *ob, Mesh *mesh, short (*clnors)[2], - float (*loop_normals)[3], - const float (*poly_normals)[3], + blender::MutableSpan loop_normals, + const blender::Span poly_normals, const short mix_mode, const float mix_factor, const float mix_limit, const MDeformVert *dvert, const int defgrp_index, const bool use_invert_vgroup, - const float (*positions)[3], - const int verts_num, + const blender::Span positions, const blender::Span edges, - bool *sharp_edges, + blender::MutableSpan sharp_edges, blender::MutableSpan loops, const blender::Span polys) { @@ -372,8 +359,7 @@ static void normalEditModifier_do_directional(NormalEditModifierData *enmd, const bool do_polynors_fix = (enmd->flag & MOD_NORMALEDIT_NO_POLYNORS_FIX) == 0; const bool use_parallel_normals = (enmd->flag & MOD_NORMALEDIT_USE_DIRECTION_PARALLEL) != 0; - float(*nos)[3] = static_cast( - MEM_malloc_arrayN(loops.size(), sizeof(*nos), __func__)); + blender::Array nos(loops.size()); float target_co[3]; int i; @@ -397,16 +383,14 @@ static void normalEditModifier_do_directional(NormalEditModifierData *enmd, } else { float(*cos)[3] = static_cast( - MEM_malloc_arrayN(size_t(verts_num), sizeof(*cos), __func__)); - generate_vert_coordinates(mesh, ob, ob_target, nullptr, verts_num, cos, nullptr); + MEM_malloc_arrayN(size_t(positions.size()), sizeof(*cos), __func__)); + generate_vert_coordinates(mesh, ob, ob_target, nullptr, positions.size(), cos, nullptr); - BLI_bitmap *done_verts = BLI_BITMAP_NEW(size_t(verts_num), __func__); - const MLoop *ml; - float(*no)[3]; + BLI_bitmap *done_verts = BLI_BITMAP_NEW(size_t(positions.size()), __func__); /* We reuse cos to now store the 'to target' normal of the verts! */ - for (i = loops.size(), no = nos, ml = loops.data(); i--; no++, ml++) { - const int vidx = ml->v; + for (const int64_t i : loops.index_range()) { + const int vidx = loops[i].v; float *co = cos[vidx]; if (!BLI_BITMAP_TEST(done_verts, vidx)) { @@ -415,50 +399,43 @@ static void normalEditModifier_do_directional(NormalEditModifierData *enmd, BLI_BITMAP_ENABLE(done_verts, vidx); } - - copy_v3_v3(*no, co); + nos[i] = co; } MEM_freeN(done_verts); MEM_freeN(cos); } - if (loop_normals) { + if (!loop_normals.is_empty()) { mix_normals(mix_factor, dvert, defgrp_index, use_invert_vgroup, mix_limit, mix_mode, - verts_num, + positions.size(), loops, - loop_normals, - nos); + loop_normals.data(), + nos.data()); } if (do_polynors_fix && polygons_check_flip( - loops, nos, &mesh->ldata, polys, BKE_mesh_poly_normals_for_write(mesh))) { + loops, nos.data(), &mesh->ldata, polys, BKE_mesh_poly_normals_for_write(mesh))) { BKE_mesh_normals_tag_dirty(mesh); } const bool *sharp_faces = static_cast( CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, "sharp_face")); - BKE_mesh_normals_loop_custom_set(positions, - BKE_mesh_vert_normals_ensure(mesh), - verts_num, - edges.data(), - edges.size(), - loops.data(), - nos, - loops.size(), - polys.data(), - poly_normals, - sharp_faces, - polys.size(), - sharp_edges, - clnors); - - MEM_freeN(nos); + blender::bke::mesh::normals_loop_custom_set(positions, + edges, + polys, + loops, + mesh->vert_normals(), + poly_normals, + sharp_faces, + sharp_edges, + nos, + clnors); } static bool is_valid_target(NormalEditModifierData *enmd) @@ -524,8 +501,7 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, result = mesh; } - const int verts_num = result->totvert; - const float(*positions)[3] = BKE_mesh_vert_positions(result); + const blender::Span positions = result->vert_positions(); const blender::Span edges = result->edges(); const blender::Span polys = result->polys(); blender::MutableSpan loops = result->loops_for_write(); @@ -533,12 +509,12 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, int defgrp_index; const MDeformVert *dvert; - float(*loop_normals)[3] = nullptr; + blender::Array loop_normals; CustomData *ldata = &result->ldata; - const float(*vert_normals)[3] = BKE_mesh_vert_normals_ensure(result); - const float(*poly_normals)[3] = BKE_mesh_poly_normals_ensure(result); + const blender::Span vert_normals = result->vert_normals(); + const blender::Span poly_normals = result->poly_normals(); bke::MutableAttributeAccessor attributes = result->attributes_for_write(); bke::SpanAttributeWriter sharp_edges = attributes.lookup_or_add_for_write_span( @@ -549,28 +525,23 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, if (use_current_clnors) { clnors = static_cast( CustomData_get_layer_for_write(ldata, CD_CUSTOMLOOPNORMAL, loops.size())); - loop_normals = static_cast( - MEM_malloc_arrayN(loops.size(), sizeof(*loop_normals), __func__)); + loop_normals.reinitialize(loops.size()); const bool *sharp_faces = static_cast( CustomData_get_layer_named(&result->pdata, CD_PROP_BOOL, "sharp_face")); - BKE_mesh_normals_loop_split(positions, - vert_normals, - verts_num, - edges.data(), - edges.size(), - loops.data(), - loop_normals, - loops.size(), - polys.data(), - poly_normals, - polys.size(), - true, - result->smoothresh, - sharp_edges.span.data(), - sharp_faces, - nullptr, - nullptr, - clnors); + blender::bke::mesh::normals_calc_loop(positions, + edges, + polys, + loops, + {}, + vert_normals, + poly_normals, + sharp_edges.span.data(), + sharp_faces, + true, + result->smoothresh, + clnors, + nullptr, + loop_normals); } if (clnors == nullptr) { @@ -595,9 +566,8 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, defgrp_index, use_invert_vgroup, positions, - verts_num, edges, - sharp_edges.span.data(), + sharp_edges.span, loops, polys); } @@ -616,15 +586,12 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, defgrp_index, use_invert_vgroup, positions, - verts_num, edges, - sharp_edges.span.data(), + sharp_edges.span, loops, polys); } - MEM_SAFE_FREE(loop_normals); - result->runtime->is_original_bmesh = false; sharp_edges.finish(); diff --git a/source/blender/modifiers/intern/MOD_ocean.cc b/source/blender/modifiers/intern/MOD_ocean.cc index 401165a8efe..f42db9dbfbb 100644 --- a/source/blender/modifiers/intern/MOD_ocean.cc +++ b/source/blender/modifiers/intern/MOD_ocean.cc @@ -24,7 +24,7 @@ #include "BKE_context.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_ocean.h" #include "BKE_screen.h" diff --git a/source/blender/modifiers/intern/MOD_particleinstance.cc b/source/blender/modifiers/intern/MOD_particleinstance.cc index 3d0b0275651..c1e07497598 100644 --- a/source/blender/modifiers/intern/MOD_particleinstance.cc +++ b/source/blender/modifiers/intern/MOD_particleinstance.cc @@ -25,7 +25,7 @@ #include "BKE_effect.h" #include "BKE_lattice.h" #include "BKE_lib_query.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_particle.h" #include "BKE_pointcache.h" diff --git a/source/blender/modifiers/intern/MOD_particlesystem.cc b/source/blender/modifiers/intern/MOD_particlesystem.cc index bf19553378f..85ca594d991 100644 --- a/source/blender/modifiers/intern/MOD_particlesystem.cc +++ b/source/blender/modifiers/intern/MOD_particlesystem.cc @@ -20,7 +20,7 @@ #include "BKE_context.h" #include "BKE_editmesh.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_legacy_convert.h" #include "BKE_modifier.h" #include "BKE_particle.h" diff --git a/source/blender/modifiers/intern/MOD_remesh.cc b/source/blender/modifiers/intern/MOD_remesh.cc index eef079e2fa7..9d6ca28759f 100644 --- a/source/blender/modifiers/intern/MOD_remesh.cc +++ b/source/blender/modifiers/intern/MOD_remesh.cc @@ -21,7 +21,7 @@ #include "DNA_screen_types.h" #include "BKE_context.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_remesh_voxel.h" #include "BKE_mesh_runtime.h" #include "BKE_screen.h" diff --git a/source/blender/modifiers/intern/MOD_screw.cc b/source/blender/modifiers/intern/MOD_screw.cc index f49ec7d759f..df9e81dbbdc 100644 --- a/source/blender/modifiers/intern/MOD_screw.cc +++ b/source/blender/modifiers/intern/MOD_screw.cc @@ -26,7 +26,7 @@ #include "BKE_context.h" #include "BKE_lib_id.h" #include "BKE_lib_query.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_screen.h" #include "UI_interface.h" diff --git a/source/blender/modifiers/intern/MOD_skin.cc b/source/blender/modifiers/intern/MOD_skin.cc index f03e37ac730..16ed235ff52 100644 --- a/source/blender/modifiers/intern/MOD_skin.cc +++ b/source/blender/modifiers/intern/MOD_skin.cc @@ -59,7 +59,7 @@ #include "BKE_context.h" #include "BKE_deform.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_modifier.h" #include "BKE_screen.h" diff --git a/source/blender/modifiers/intern/MOD_smooth.cc b/source/blender/modifiers/intern/MOD_smooth.cc index 6dade62048b..6582bcd4f70 100644 --- a/source/blender/modifiers/intern/MOD_smooth.cc +++ b/source/blender/modifiers/intern/MOD_smooth.cc @@ -23,7 +23,7 @@ #include "BKE_deform.h" #include "BKE_editmesh.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_wrapper.h" #include "BKE_particle.h" #include "BKE_screen.h" diff --git a/source/blender/modifiers/intern/MOD_solidify_extrude.cc b/source/blender/modifiers/intern/MOD_solidify_extrude.cc index 98d25be8641..65c82e8c85f 100644 --- a/source/blender/modifiers/intern/MOD_solidify_extrude.cc +++ b/source/blender/modifiers/intern/MOD_solidify_extrude.cc @@ -17,7 +17,7 @@ #include "MEM_guardedalloc.h" #include "BKE_deform.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_particle.h" #include "MOD_modifiertypes.h" @@ -715,7 +715,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex } for (const int64_t i : blender::IndexRange(polys_num)) { - /* #BKE_mesh_calc_poly_angles logic is inlined here */ + /* #bke::mesh::poly_angles_calc logic is inlined here */ float nor_prev[3]; float nor_next[3]; diff --git a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.cc b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.cc index e158c1d74ec..e370753cb3b 100644 --- a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.cc +++ b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.cc @@ -15,7 +15,7 @@ #include "MEM_guardedalloc.h" #include "BKE_deform.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_particle.h" #include "MOD_modifiertypes.h" diff --git a/source/blender/modifiers/intern/MOD_subsurf.cc b/source/blender/modifiers/intern/MOD_subsurf.cc index 412db630ee9..88a456944bb 100644 --- a/source/blender/modifiers/intern/MOD_subsurf.cc +++ b/source/blender/modifiers/intern/MOD_subsurf.cc @@ -24,7 +24,7 @@ #include "BKE_context.h" #include "BKE_editmesh.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_scene.h" #include "BKE_screen.h" #include "BKE_subdiv.h" diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.cc b/source/blender/modifiers/intern/MOD_surfacedeform.cc index 030c1694694..d13a15e724b 100644 --- a/source/blender/modifiers/intern/MOD_surfacedeform.cc +++ b/source/blender/modifiers/intern/MOD_surfacedeform.cc @@ -24,7 +24,7 @@ #include "BKE_editmesh.h" #include "BKE_lib_id.h" #include "BKE_lib_query.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_mesh_wrapper.h" #include "BKE_modifier.h" diff --git a/source/blender/modifiers/intern/MOD_triangulate.cc b/source/blender/modifiers/intern/MOD_triangulate.cc index 66ffce98c65..04726f47a5a 100644 --- a/source/blender/modifiers/intern/MOD_triangulate.cc +++ b/source/blender/modifiers/intern/MOD_triangulate.cc @@ -19,7 +19,7 @@ #include "DNA_screen_types.h" #include "BKE_context.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_screen.h" diff --git a/source/blender/modifiers/intern/MOD_util.cc b/source/blender/modifiers/intern/MOD_util.cc index 4c8663277ab..a5c15420f28 100644 --- a/source/blender/modifiers/intern/MOD_util.cc +++ b/source/blender/modifiers/intern/MOD_util.cc @@ -26,7 +26,7 @@ #include "BKE_image.h" #include "BKE_lattice.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_wrapper.h" #include "BKE_object.h" diff --git a/source/blender/modifiers/intern/MOD_uvproject.cc b/source/blender/modifiers/intern/MOD_uvproject.cc index 92bd0bd77e6..25d07f52abd 100644 --- a/source/blender/modifiers/intern/MOD_uvproject.cc +++ b/source/blender/modifiers/intern/MOD_uvproject.cc @@ -25,7 +25,7 @@ #include "BKE_context.h" #include "BKE_lib_query.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_screen.h" #include "UI_interface.h" @@ -180,6 +180,7 @@ static Mesh *uvprojectModifier_do(UVProjectModifierData *umd, mul_mat3_m4_v3(projectors[i].ob->object_to_world, projectors[i].normal); } + const blender::Span positions = mesh->vert_positions(); const blender::Span polys = mesh->polys(); const blender::Span loops = mesh->loops(); @@ -225,13 +226,13 @@ static Mesh *uvprojectModifier_do(UVProjectModifierData *umd, } else { /* multiple projectors, select the closest to face normal direction */ - float face_no[3]; int j; Projector *best_projector; float best_dot; /* get the untransformed face normal */ - BKE_mesh_calc_poly_normal(&poly, &loops[poly.loopstart], (const float(*)[3])coords, face_no); + const blender::float3 face_no = blender::bke::mesh::poly_normal_calc( + positions, loops.slice(poly.loopstart, poly.totloop)); /* find the projector which the face points at most directly * (projector normal with largest dot product is best) diff --git a/source/blender/modifiers/intern/MOD_uvwarp.cc b/source/blender/modifiers/intern/MOD_uvwarp.cc index 4d664adfc3d..0c4c559c69b 100644 --- a/source/blender/modifiers/intern/MOD_uvwarp.cc +++ b/source/blender/modifiers/intern/MOD_uvwarp.cc @@ -23,7 +23,7 @@ #include "BKE_context.h" #include "BKE_deform.h" #include "BKE_lib_query.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_screen.h" diff --git a/source/blender/modifiers/intern/MOD_volume_to_mesh.cc b/source/blender/modifiers/intern/MOD_volume_to_mesh.cc index f6714aa1476..abc6b5a5a88 100644 --- a/source/blender/modifiers/intern/MOD_volume_to_mesh.cc +++ b/source/blender/modifiers/intern/MOD_volume_to_mesh.cc @@ -7,7 +7,7 @@ #include #include "BKE_lib_query.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_volume.h" #include "BKE_volume_to_mesh.hh" diff --git a/source/blender/modifiers/intern/MOD_wave.cc b/source/blender/modifiers/intern/MOD_wave.cc index 360915a022b..f3e636aafbf 100644 --- a/source/blender/modifiers/intern/MOD_wave.cc +++ b/source/blender/modifiers/intern/MOD_wave.cc @@ -24,7 +24,7 @@ #include "BKE_editmesh_cache.h" #include "BKE_lib_id.h" #include "BKE_lib_query.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_wrapper.h" #include "BKE_scene.h" #include "BKE_screen.h" diff --git a/source/blender/modifiers/intern/MOD_weighted_normal.cc b/source/blender/modifiers/intern/MOD_weighted_normal.cc index afa9e27a9d1..6c8776d3a3d 100644 --- a/source/blender/modifiers/intern/MOD_weighted_normal.cc +++ b/source/blender/modifiers/intern/MOD_weighted_normal.cc @@ -23,7 +23,7 @@ #include "BKE_context.h" #include "BKE_deform.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_screen.h" @@ -70,10 +70,10 @@ struct WeightedNormalDataAggregateItem { struct WeightedNormalData { int verts_num; - const float (*vert_positions)[3]; - const float (*vert_normals)[3]; + blender::Span vert_positions; + blender::Span vert_normals; blender::Span edges; - bool *sharp_edges; + blender::MutableSpan sharp_edges; blender::Span loops; blender::Span loop_to_poly; @@ -82,7 +82,7 @@ struct WeightedNormalData { float split_angle; blender::Span polys; - const float (*poly_normals)[3]; + blender::Span poly_normals; const bool *sharp_faces; const int *poly_strength; @@ -131,7 +131,7 @@ static void aggregate_item_normal(WeightedNormalModifierData *wnmd, const float curr_val, const bool use_face_influence) { - const float(*poly_normals)[3] = wn_data->poly_normals; + const blender::Span poly_normals = wn_data->poly_normals; const MDeformVert *dvert = wn_data->dvert; const int defgrp_index = wn_data->defgrp_index; @@ -184,7 +184,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, using namespace blender; const int verts_num = wn_data->verts_num; - const float(*positions)[3] = wn_data->vert_positions; + const blender::Span positions = wn_data->vert_positions; const blender::Span edges = wn_data->edges; const blender::Span polys = wn_data->polys; const blender::Span loops = wn_data->loops; @@ -192,7 +192,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, short(*clnors)[2] = wn_data->clnors; const Span loop_to_poly = wn_data->loop_to_poly; - const float(*poly_normals)[3] = wn_data->poly_normals; + const blender::Span poly_normals = wn_data->poly_normals; const int *poly_strength = wn_data->poly_strength; const MDeformVert *dvert = wn_data->dvert; @@ -209,7 +209,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, poly_strength != nullptr; const bool has_vgroup = dvert != nullptr; - float(*loop_normals)[3] = nullptr; + blender::Array loop_normals; WeightedNormalDataAggregateItem *items_data = nullptr; int items_num = 0; @@ -218,26 +218,21 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, /* This will give us loop normal spaces, * we do not actually care about computed loop_normals for now... */ - loop_normals = static_cast( - MEM_calloc_arrayN(size_t(loops.size()), sizeof(*loop_normals), __func__)); - BKE_mesh_normals_loop_split(positions, - wn_data->vert_normals, - verts_num, - edges.data(), - edges.size(), - loops.data(), - loop_normals, - loops.size(), - polys.data(), - poly_normals, - polys.size(), - true, - split_angle, - wn_data->sharp_edges, - wn_data->sharp_faces, - loop_to_poly.data(), - &lnors_spacearr, - has_clnors ? clnors : nullptr); + loop_normals.reinitialize(loops.size()); + bke::mesh::normals_calc_loop(positions, + edges, + polys, + loops, + loop_to_poly, + wn_data->vert_normals, + wn_data->poly_normals, + wn_data->sharp_edges.data(), + wn_data->sharp_faces, + true, + split_angle, + has_clnors ? clnors : nullptr, + &lnors_spacearr, + loop_normals); items_num = lnors_spacearr.spaces_num; items_data = static_cast( @@ -349,20 +344,16 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, } } - BKE_mesh_normals_loop_custom_set(positions, - wn_data->vert_normals, - verts_num, - edges.data(), - edges.size(), - loops.data(), - loop_normals, - loops.size(), - polys.data(), - poly_normals, - wn_data->sharp_faces, - polys.size(), - wn_data->sharp_edges, - clnors); + blender::bke::mesh::normals_loop_custom_set(positions, + edges, + polys, + loops, + wn_data->vert_normals, + poly_normals, + wn_data->sharp_faces, + wn_data->sharp_edges, + loop_normals, + clnors); } else { /* TODO: Ideally, we could add an option to `BKE_mesh_normals_loop_custom_[from_verts_]set()` @@ -374,53 +365,40 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, /* NOTE: in theory, we could avoid this extra allocation & copying... * But think we can live with it for now, * and it makes code simpler & cleaner. */ - float(*vert_normals)[3] = static_cast( - MEM_calloc_arrayN(size_t(verts_num), sizeof(*loop_normals), __func__)); + blender::Array vert_normals; for (int ml_index = 0; ml_index < loops.size(); ml_index++) { const int mv_index = loops[ml_index].v; copy_v3_v3(vert_normals[mv_index], items_data[mv_index].normal); } - BKE_mesh_normals_loop_custom_from_verts_set(positions, - wn_data->vert_normals, - vert_normals, - verts_num, - edges.data(), - edges.size(), - loops.data(), - loops.size(), - polys.data(), - poly_normals, - wn_data->sharp_faces, - polys.size(), - wn_data->sharp_edges, - clnors); - - MEM_freeN(vert_normals); + blender::bke::mesh::normals_loop_custom_set_from_verts(positions, + edges, + polys, + loops, + wn_data->vert_normals, + poly_normals, + wn_data->sharp_faces, + wn_data->sharp_edges, + vert_normals, + clnors); } else { - loop_normals = static_cast( - MEM_calloc_arrayN(size_t(loops.size()), sizeof(*loop_normals), __func__)); - - BKE_mesh_normals_loop_split(positions, - wn_data->vert_normals, - verts_num, - edges.data(), - edges.size(), - loops.data(), - loop_normals, - loops.size(), - polys.data(), - poly_normals, - polys.size(), - true, - split_angle, - wn_data->sharp_edges, - wn_data->sharp_faces, - loop_to_poly.data(), - nullptr, - has_clnors ? clnors : nullptr); + loop_normals.reinitialize(loops.size()); + blender::bke::mesh::normals_calc_loop(positions, + edges, + polys, + loops, + loop_to_poly, + wn_data->vert_normals, + poly_normals, + wn_data->sharp_edges.data(), + wn_data->sharp_faces, + true, + split_angle, + has_clnors ? clnors : nullptr, + nullptr, + loop_normals); for (int ml_index = 0; ml_index < loops.size(); ml_index++) { const int item_index = loops[ml_index].v; @@ -428,33 +406,27 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, copy_v3_v3(loop_normals[ml_index], items_data[item_index].normal); } } - - BKE_mesh_normals_loop_custom_set(positions, - wn_data->vert_normals, - verts_num, - edges.data(), - edges.size(), - loops.data(), - loop_normals, - loops.size(), - polys.data(), - poly_normals, - wn_data->sharp_faces, - polys.size(), - wn_data->sharp_edges, - clnors); + blender::bke::mesh::normals_loop_custom_set(positions, + edges, + polys, + loops, + wn_data->vert_normals, + poly_normals, + wn_data->sharp_faces, + wn_data->sharp_edges, + loop_normals, + clnors); } } if (keep_sharp) { BKE_lnor_spacearr_free(&lnors_spacearr); } - MEM_SAFE_FREE(loop_normals); } static void wn_face_area(WeightedNormalModifierData *wnmd, WeightedNormalData *wn_data) { - const float(*positions)[3] = wn_data->vert_positions; + const blender::Span positions = wn_data->vert_positions; const blender::Span polys = wn_data->polys; const blender::Span loops = wn_data->loops; @@ -463,7 +435,8 @@ static void wn_face_area(WeightedNormalModifierData *wnmd, WeightedNormalData *w ModePair *f_area = face_area; for (const int i : polys.index_range()) { - f_area[i].val = BKE_mesh_calc_poly_area(&polys[i], &loops[polys[i].loopstart], positions); + f_area[i].val = blender::bke::mesh::poly_area_calc( + positions, loops.slice(polys[i].loopstart, polys[i].totloop)); f_area[i].index = i; } @@ -475,7 +448,7 @@ static void wn_face_area(WeightedNormalModifierData *wnmd, WeightedNormalData *w static void wn_corner_angle(WeightedNormalModifierData *wnmd, WeightedNormalData *wn_data) { - const float(*positions)[3] = wn_data->vert_positions; + const blender::Span positions = wn_data->vert_positions; const blender::Span polys = wn_data->polys; const blender::Span loops = wn_data->loops; @@ -486,7 +459,8 @@ static void wn_corner_angle(WeightedNormalModifierData *wnmd, WeightedNormalData const MPoly &poly = polys[i]; float *index_angle = static_cast( MEM_malloc_arrayN(poly.totloop, sizeof(*index_angle), __func__)); - BKE_mesh_calc_poly_angles(&poly, &loops[poly.loopstart], positions, index_angle); + blender::bke::mesh::poly_angles_calc( + positions, loops.slice(poly.loopstart, poly.totloop), {index_angle, poly.totloop}); ModePair *c_angl = &corner_angle[poly.loopstart]; float *angl = index_angle; @@ -506,7 +480,7 @@ static void wn_corner_angle(WeightedNormalModifierData *wnmd, WeightedNormalData static void wn_face_with_angle(WeightedNormalModifierData *wnmd, WeightedNormalData *wn_data) { - const float(*positions)[3] = wn_data->vert_positions; + const blender::Span positions = wn_data->vert_positions; const blender::Span polys = wn_data->polys; const blender::Span loops = wn_data->loops; @@ -515,10 +489,11 @@ static void wn_face_with_angle(WeightedNormalModifierData *wnmd, WeightedNormalD for (const int i : polys.index_range()) { const MPoly &poly = polys[i]; - float face_area = BKE_mesh_calc_poly_area(&poly, &loops[poly.loopstart], positions); + const blender::Span poly_loops = loops.slice(poly.loopstart, poly.totloop); + const float face_area = blender::bke::mesh::poly_area_calc(positions, poly_loops); float *index_angle = static_cast( MEM_malloc_arrayN(size_t(poly.totloop), sizeof(*index_angle), __func__)); - BKE_mesh_calc_poly_angles(&poly, &loops[poly.loopstart], positions, index_angle); + blender::bke::mesh::poly_angles_calc(positions, poly_loops, {index_angle, poly.totloop}); ModePair *cmbnd = &combined[poly.loopstart]; float *angl = index_angle; @@ -563,7 +538,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * result = (Mesh *)BKE_id_copy_ex(nullptr, &mesh->id, nullptr, LIB_ID_COPY_LOCALIZE); const int verts_num = result->totvert; - const float(*positions)[3] = BKE_mesh_vert_positions(result); + const blender::Span positions = mesh->vert_positions(); const blender::Span edges = mesh->edges(); const blender::Span polys = mesh->polys(); const blender::Span loops = mesh->loops(); @@ -612,9 +587,9 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * wn_data.verts_num = verts_num; wn_data.vert_positions = positions; - wn_data.vert_normals = BKE_mesh_vert_normals_ensure(result); + wn_data.vert_normals = result->vert_normals(); wn_data.edges = edges; - wn_data.sharp_edges = sharp_edges.span.data(); + wn_data.sharp_edges = sharp_edges.span; wn_data.loops = loops; wn_data.loop_to_poly = loop_to_poly_map; @@ -623,7 +598,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * wn_data.split_angle = split_angle; wn_data.polys = polys; - wn_data.poly_normals = BKE_mesh_poly_normals_ensure(mesh); + wn_data.poly_normals = mesh->poly_normals(); wn_data.sharp_faces = static_cast( CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, "sharp_face")); wn_data.poly_strength = static_cast(CustomData_get_layer_named( diff --git a/source/blender/modifiers/intern/MOD_weightvgedit.cc b/source/blender/modifiers/intern/MOD_weightvgedit.cc index e8a2795aa79..e5b0e830fe9 100644 --- a/source/blender/modifiers/intern/MOD_weightvgedit.cc +++ b/source/blender/modifiers/intern/MOD_weightvgedit.cc @@ -27,7 +27,7 @@ #include "BKE_context.h" #include "BKE_deform.h" #include "BKE_lib_query.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_screen.h" #include "BKE_texture.h" /* Texture masking. */ diff --git a/source/blender/modifiers/intern/MOD_weightvgmix.cc b/source/blender/modifiers/intern/MOD_weightvgmix.cc index c766d117db8..370eff8b8de 100644 --- a/source/blender/modifiers/intern/MOD_weightvgmix.cc +++ b/source/blender/modifiers/intern/MOD_weightvgmix.cc @@ -23,7 +23,7 @@ #include "BKE_customdata.h" #include "BKE_deform.h" #include "BKE_lib_query.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_modifier.h" #include "BKE_screen.h" #include "BKE_texture.h" /* Texture masking. */ diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.cc b/source/blender/modifiers/intern/MOD_weightvgproximity.cc index 917311f68d1..270283b0f30 100644 --- a/source/blender/modifiers/intern/MOD_weightvgproximity.cc +++ b/source/blender/modifiers/intern/MOD_weightvgproximity.cc @@ -31,7 +31,7 @@ #include "BKE_deform.h" #include "BKE_lib_id.h" #include "BKE_lib_query.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_wrapper.h" #include "BKE_modifier.h" #include "BKE_screen.h" diff --git a/source/blender/nodes/geometry/node_geometry_util.cc b/source/blender/nodes/geometry/node_geometry_util.cc index 516a1994efc..6ba11d3620e 100644 --- a/source/blender/nodes/geometry/node_geometry_util.cc +++ b/source/blender/nodes/geometry/node_geometry_util.cc @@ -6,7 +6,7 @@ #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_pointcloud.h" diff --git a/source/blender/nodes/geometry/nodes/node_geo_blur_attribute.cc b/source/blender/nodes/geometry/nodes/node_geo_blur_attribute.cc index 77bfa7a2b58..4c2a1336e02 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_blur_attribute.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_blur_attribute.cc @@ -15,7 +15,7 @@ #include "BKE_attribute_math.hh" #include "BKE_curves.hh" #include "BKE_geometry_fields.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "UI_interface.h" 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 7bdba586d6d..0866074ebab 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_convex_hull.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_convex_hull.cc @@ -6,7 +6,7 @@ #include "BKE_curves.hh" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "node_geometry_util.hh" 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 8a77f2cf207..c64259a8f00 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc @@ -8,7 +8,7 @@ #include "DNA_meshdata_types.h" #include "BKE_curves.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BLI_task.hh" 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 24c3526087e..f7279cdfe7e 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 @@ -4,7 +4,7 @@ #include "BKE_curves.hh" #include "BKE_editmesh.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_mesh_wrapper.h" #include "BKE_modifier.h" 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 a152293259d..f89945f89ee 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc @@ -14,7 +14,7 @@ #include "BKE_curves.hh" #include "BKE_customdata.h" #include "BKE_instances.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_pointcloud.h" #include "node_geometry_util.hh" 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 0e459566d47..3ba718f211a 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 @@ -12,7 +12,7 @@ #include "BKE_attribute_math.hh" #include "BKE_bvhutils.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_mesh_sample.hh" #include "BKE_pointcloud.h" 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 00271b053c1..207e30992ef 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_dual_mesh.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_dual_mesh.cc @@ -7,7 +7,7 @@ #include "DNA_meshdata_types.h" #include "BKE_attribute_math.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "node_geometry_util.hh" @@ -678,10 +678,8 @@ static Mesh *calc_dual_mesh(const Mesh &src_mesh, Vector vert_positions(src_mesh.totpoly); for (const int i : src_polys.index_range()) { const MPoly &poly = src_polys[i]; - BKE_mesh_calc_poly_center(&poly, - &src_loops[poly.loopstart], - reinterpret_cast(src_positions.data()), - vert_positions[i]); + vert_positions[i] = bke::mesh::poly_center_calc(src_positions, + src_loops.slice(poly.loopstart, poly.totloop)); } Array boundary_edge_midpoint_index; 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 7d4d3cf6f71..d2efdbbddcc 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc @@ -14,7 +14,7 @@ #include "BKE_attribute_math.hh" #include "BKE_curves.hh" #include "BKE_instances.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_pointcloud.h" #include "node_geometry_util.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_edge_paths_to_selection.cc b/source/blender/nodes/geometry/nodes/node_geo_edge_paths_to_selection.cc index d9a9b7fdcfe..dc705914919 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_edge_paths_to_selection.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_edge_paths_to_selection.cc @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ #include "BKE_attribute_math.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BLI_map.hh" #include "BLI_set.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_edges_to_face_groups.cc b/source/blender/nodes/geometry/nodes/node_geo_edges_to_face_groups.cc index b89ad0dfd14..cc27c4e9fe3 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_edges_to_face_groups.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_edges_to_face_groups.cc @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BLI_atomic_disjoint_set.hh" 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 5010d68859f..c1afbf2a0fa 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc @@ -9,7 +9,7 @@ #include "DNA_meshdata_types.h" #include "BKE_attribute_math.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BKE_mesh_runtime.h" diff --git a/source/blender/nodes/geometry/nodes/node_geo_flip_faces.cc b/source/blender/nodes/geometry/nodes/node_geo_flip_faces.cc index 9d5e9390d5b..14e2449d80d 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_flip_faces.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_flip_faces.cc @@ -2,7 +2,7 @@ #include "BLI_task.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_attribute_math.hh" 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 9f3a355498c..e2e20237470 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 @@ -6,7 +6,7 @@ #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "node_geometry_util.hh" @@ -79,15 +79,10 @@ class AngleFieldInput final : public bke::MeshFieldInput { } const MPoly &poly_1 = polys[edge_map[i].face_index_1]; const MPoly &poly_2 = polys[edge_map[i].face_index_2]; - float3 normal_1, normal_2; - BKE_mesh_calc_poly_normal(&poly_1, - &loops[poly_1.loopstart], - reinterpret_cast(positions.data()), - normal_1); - BKE_mesh_calc_poly_normal(&poly_2, - &loops[poly_2.loopstart], - reinterpret_cast(positions.data()), - normal_2); + const float3 normal_1 = bke::mesh::poly_normal_calc( + positions, loops.slice(poly_1.loopstart, poly_1.totloop)); + const float3 normal_2 = bke::mesh::poly_normal_calc( + positions, loops.slice(poly_2.loopstart, poly_2.totloop)); return angle_normalized_v3v3(normal_1, normal_2); }; @@ -138,26 +133,18 @@ class SignedAngleFieldInput final : public bke::MeshFieldInput { const MPoly &poly_2 = polys[edge_map[i].face_index_2]; /* Find the normals of the 2 polys. */ - float3 poly_1_normal, poly_2_normal; - BKE_mesh_calc_poly_normal(&poly_1, - &loops[poly_1.loopstart], - reinterpret_cast(positions.data()), - poly_1_normal); - BKE_mesh_calc_poly_normal(&poly_2, - &loops[poly_2.loopstart], - reinterpret_cast(positions.data()), - poly_2_normal); + const float3 poly_1_normal = bke::mesh::poly_normal_calc( + positions, loops.slice(poly_1.loopstart, poly_1.totloop)); + const float3 poly_2_normal = bke::mesh::poly_normal_calc( + positions, loops.slice(poly_2.loopstart, poly_2.totloop)); /* Find the centerpoint of the axis edge */ 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(&poly_2, - &loops[poly_2.loopstart], - reinterpret_cast(positions.data()), - poly_center_2); + const float3 poly_center_2 = bke::mesh::poly_center_calc( + positions, loops.slice(poly_2.loopstart, poly_2.totloop)); 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_neighbors.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_neighbors.cc index 97c950988e7..9fc5b361b5a 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_neighbors.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_neighbors.cc @@ -3,7 +3,7 @@ #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "node_geometry_util.hh" 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 667beeefd2f..01211d32435 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 @@ -3,7 +3,7 @@ #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "node_geometry_util.hh" 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 d9f5f4b82a3..d8aeac6df8f 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 @@ -3,7 +3,7 @@ #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "node_geometry_util.hh" @@ -24,8 +24,7 @@ static VArray construct_face_area_varray(const Mesh &mesh, const eAttrDom 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], reinterpret_cast(positions.data())); + return bke::mesh::poly_area_calc(positions, loops.slice(poly.loopstart, poly.totloop)); }; return mesh.attributes().adapt_domain( 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 61fad459561..71ab9ab3018 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 @@ -5,7 +5,7 @@ #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "node_geometry_util.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_neighbors.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_neighbors.cc index f1724ef4a41..a4b71941c23 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_neighbors.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_neighbors.cc @@ -3,7 +3,7 @@ #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "node_geometry_util.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_island.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_island.cc index d2a66986abd..59c52da20e7 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_island.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_island.cc @@ -3,7 +3,7 @@ #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BLI_atomic_disjoint_set.hh" #include "BLI_task.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_vertex_neighbors.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_vertex_neighbors.cc index 5b1b32c7b9c..2fb8e4f54fa 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_vertex_neighbors.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_vertex_neighbors.cc @@ -3,7 +3,7 @@ #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "node_geometry_util.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_shortest_edge_paths.cc b/source/blender/nodes/geometry/nodes/node_geo_input_shortest_edge_paths.cc index 2eb41ea7435..ce3d460540b 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_input_shortest_edge_paths.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_input_shortest_edge_paths.cc @@ -7,7 +7,7 @@ #include "BLI_set.hh" #include "BLI_task.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "node_geometry_util.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_face_group_boundaries.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_face_group_boundaries.cc index a2befdb31b2..90f7677f456 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_face_group_boundaries.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_face_group_boundaries.cc @@ -3,7 +3,7 @@ #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "node_geometry_util.hh" 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 c228bece849..d85d153972e 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 @@ -4,7 +4,7 @@ #include "DNA_meshdata_types.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "UI_interface.h" #include "UI_resources.h" 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 a30d08922f6..3145211d1d8 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 @@ -4,7 +4,7 @@ #include "DNA_meshdata_types.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "UI_interface.h" #include "UI_resources.h" diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc index 88fb4c72b1a..3af830562d9 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cube.cc @@ -4,7 +4,7 @@ #include "DNA_meshdata_types.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "GEO_mesh_primitive_cuboid.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cylinder.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cylinder.cc index bc651cdb652..5c6f206f04d 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cylinder.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cylinder.cc @@ -4,7 +4,7 @@ #include "DNA_meshdata_types.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "UI_interface.h" #include "UI_resources.h" 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 a1bf4dcbc7e..2d366debda7 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 @@ -6,7 +6,7 @@ #include "DNA_meshdata_types.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "UI_interface.h" #include "UI_resources.h" diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc index d1387ca5cdc..dd5def9c706 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc @@ -4,7 +4,7 @@ #include "BKE_lib_id.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "bmesh.h" 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 12cb9f81d12..416076cf486 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 @@ -7,7 +7,7 @@ #include "BLI_task.hh" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "UI_interface.h" #include "UI_resources.h" 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 d10abd8d2f2..41a48e7bc73 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 @@ -6,7 +6,7 @@ #include "DNA_meshdata_types.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "UI_interface.h" #include "UI_resources.h" diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_subdivide.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_subdivide.cc index c4ef7f8944f..2fbb3438401 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_subdivide.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_subdivide.cc @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_subdiv.h" #include "BKE_subdiv_mesh.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_to_volume.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_to_volume.cc index 6c0e7b4fa7e..117971602a4 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_to_volume.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_to_volume.cc @@ -4,7 +4,7 @@ #include "node_geometry_util.hh" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_mesh_wrapper.h" #include "BKE_object.h" diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_corners_of_face.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_corners_of_face.cc index 55c70095236..9d359848bc6 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_corners_of_face.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_corners_of_face.cc @@ -2,7 +2,7 @@ #include "BLI_task.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "node_geometry_util.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_corners_of_vertex.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_corners_of_vertex.cc index 81608271d5b..2a115560d7e 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_corners_of_vertex.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_corners_of_vertex.cc @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BLI_task.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_edges_of_corner.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_edges_of_corner.cc index 833f5f26f6c..ecec64c0950 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_edges_of_corner.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_edges_of_corner.cc @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BLI_task.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_edges_of_vertex.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_edges_of_vertex.cc index 8fd1ffa5148..e4a30e506c9 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_edges_of_vertex.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_edges_of_vertex.cc @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BLI_task.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_face_of_corner.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_face_of_corner.cc index 4a7b1bbfbdb..c572a52a93d 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_face_of_corner.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_face_of_corner.cc @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "node_geometry_util.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_offset_corner_in_face.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_offset_corner_in_face.cc index d4e6aa6e4ef..45b21836acc 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_offset_corner_in_face.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_offset_corner_in_face.cc @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "BLI_task.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_vertex_of_corner.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_vertex_of_corner.cc index 8f631c87311..59ce296b1e7 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_vertex_of_corner.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_vertex_of_corner.cc @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BLI_task.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_points_to_vertices.cc b/source/blender/nodes/geometry/nodes/node_geo_points_to_vertices.cc index 6a7dc3bb59a..92ac14046ec 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_points_to_vertices.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_points_to_vertices.cc @@ -5,7 +5,7 @@ #include "DNA_pointcloud_types.h" #include "BKE_attribute_math.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "node_geometry_util.hh" 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 abe5be3c182..e8de583d6e6 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_sample_nearest.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_sample_nearest.cc @@ -3,7 +3,7 @@ #include "DNA_pointcloud_types.h" #include "BKE_bvhutils.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "UI_interface.h" diff --git a/source/blender/nodes/geometry/nodes/node_geo_sample_nearest_surface.cc b/source/blender/nodes/geometry/nodes/node_geo_sample_nearest_surface.cc index 092689b6b3b..65946ee947f 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_sample_nearest_surface.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_sample_nearest_surface.cc @@ -5,7 +5,7 @@ #include "BKE_attribute_math.hh" #include "BKE_bvhutils.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_sample.hh" #include "UI_interface.h" diff --git a/source/blender/nodes/geometry/nodes/node_geo_sample_uv_surface.cc b/source/blender/nodes/geometry/nodes/node_geo_sample_uv_surface.cc index 2da0e088598..41cf26b38c2 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_sample_uv_surface.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_sample_uv_surface.cc @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ #include "BKE_attribute_math.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_type_conversions.hh" #include "UI_interface.h" 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 cd0342ffedb..819084cb9fa 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_scale_elements.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_scale_elements.cc @@ -13,7 +13,7 @@ #include "UI_interface.h" #include "UI_resources.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "node_geometry_util.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_material.cc b/source/blender/nodes/geometry/nodes/node_geo_set_material.cc index aa2930cfed9..0222515b9a4 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_set_material.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_set_material.cc @@ -12,7 +12,7 @@ #include "DNA_volume_types.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" namespace blender::nodes::node_geo_set_material_cc { 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 2f13bc1f591..57781534d63 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_set_position.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_set_position.cc @@ -8,7 +8,7 @@ #include "DNA_meshdata_types.h" #include "BKE_curves.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "node_geometry_util.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc b/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc index 69d82f0cb4e..a762ba3a658 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc @@ -7,7 +7,7 @@ #include "DNA_modifier_types.h" #include "BKE_attribute.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_subdiv.h" #include "BKE_subdiv_mesh.hh" diff --git a/source/blender/nodes/geometry/nodes/node_geo_transform_geometry.cc b/source/blender/nodes/geometry/nodes/node_geo_transform_geometry.cc index 7704c94b76a..7eac7bc87aa 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_transform_geometry.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_transform_geometry.cc @@ -14,7 +14,7 @@ #include "BKE_curves.hh" #include "BKE_instances.hh" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_pointcloud.h" #include "BKE_volume.h" diff --git a/source/blender/nodes/geometry/nodes/node_geo_triangulate.cc b/source/blender/nodes/geometry/nodes/node_geo_triangulate.cc index eb22ebb3045..09ecb34ddbb 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_triangulate.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_triangulate.cc @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ #include "BKE_customdata.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "bmesh.h" #include "bmesh_tools.h" 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 6b6b0209e82..d6a31c9133e 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 @@ -5,7 +5,7 @@ #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "node_geometry_util.hh" 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 4e27ce15f47..492decd8eb9 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_uv_unwrap.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_uv_unwrap.cc @@ -5,7 +5,7 @@ #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "UI_interface.h" #include "UI_resources.h" diff --git a/source/blender/nodes/geometry/nodes/node_geo_volume_cube.cc b/source/blender/nodes/geometry/nodes/node_geo_volume_cube.cc index d88940edefd..c7a3e7d9651 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_volume_cube.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_volume_cube.cc @@ -15,7 +15,7 @@ #include "BKE_geometry_set.hh" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_volume.h" namespace blender::nodes::node_geo_volume_cube_cc { 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 04ce9cfcf0b..77bf69d187c 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 @@ -10,7 +10,7 @@ #include "BKE_lib_id.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_volume.h" #include "BKE_volume_to_mesh.hh" diff --git a/source/blender/python/mathutils/mathutils_bvhtree.cc b/source/blender/python/mathutils/mathutils_bvhtree.cc index 6bb68802d7d..b3d92708169 100644 --- a/source/blender/python/mathutils/mathutils_bvhtree.cc +++ b/source/blender/python/mathutils/mathutils_bvhtree.cc @@ -34,7 +34,7 @@ # include "BKE_customdata.h" # include "BKE_editmesh_bvh.h" # include "BKE_lib_id.h" -# include "BKE_mesh.h" +# include "BKE_mesh.hh" # include "BKE_mesh_runtime.h" # include "DEG_depsgraph_query.h" diff --git a/source/blender/render/intern/bake.cc b/source/blender/render/intern/bake.cc index b70de0fd141..92edab87232 100644 --- a/source/blender/render/intern/bake.cc +++ b/source/blender/render/intern/bake.cc @@ -61,7 +61,7 @@ #include "BKE_customdata.h" #include "BKE_image.h" #include "BKE_lib_id.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_runtime.h" #include "BKE_mesh_tangent.h" #include "BKE_node.h" @@ -460,9 +460,9 @@ static TriTessFace *mesh_calc_tri_tessface(Mesh *me, bool tangent, Mesh *me_eval /* calculate normal for each polygon only once */ uint mpoly_prev = UINT_MAX; - float no[3]; + blender::float3 no; - const float(*positions)[3] = BKE_mesh_vert_positions(me); + const blender::Span positions = me->vert_positions(); const blender::Span polys = me->polys(); const blender::Span loops = me->loops(); const bke::AttributeAccessor attributes = me->attributes(); @@ -472,23 +472,18 @@ static TriTessFace *mesh_calc_tri_tessface(Mesh *me, bool tangent, Mesh *me_eval looptri = static_cast(MEM_mallocN(sizeof(*looptri) * tottri, __func__)); triangles = static_cast(MEM_callocN(sizeof(TriTessFace) * tottri, __func__)); - const float(*precomputed_normals)[3] = BKE_mesh_poly_normals_are_dirty(me) ? - nullptr : - BKE_mesh_poly_normals_ensure(me); - const bool calculate_normal = precomputed_normals ? false : true; + const bool calculate_normal = BKE_mesh_poly_normals_are_dirty(me); + blender::Span precomputed_normals; + if (!calculate_normal) { + precomputed_normals = me->poly_normals(); + } - if (precomputed_normals != nullptr) { - BKE_mesh_recalc_looptri_with_normals(loops.data(), - polys.data(), - positions, - me->totloop, - me->totpoly, - looptri, - precomputed_normals); + if (!precomputed_normals.is_empty()) { + blender::bke::mesh::looptris_calc_with_normals( + positions, polys, loops, precomputed_normals, {looptri, tottri}); } else { - BKE_mesh_recalc_looptri( - loops.data(), polys.data(), positions, me->totloop, me->totpoly, looptri); + blender::bke::mesh::looptris_calc(positions, polys, loops, {looptri, tottri}); } const TSpace *tspace = nullptr; @@ -532,7 +527,8 @@ 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(&poly, &loops[poly.loopstart], positions, no); + no = blender::bke::mesh::poly_normal_calc(positions, + loops.slice(poly.loopstart, poly.totloop)); mpoly_prev = lt->poly; } copy_v3_v3(triangles[i].normal, no); @@ -755,11 +751,8 @@ void RE_bake_pixels_populate(Mesh *me, const int tottri = poly_to_tri_count(me->totpoly, me->totloop); MLoopTri *looptri = static_cast(MEM_mallocN(sizeof(*looptri) * tottri, __func__)); - const float(*positions)[3] = BKE_mesh_vert_positions(me); - const blender::Span polys = me->polys(); - const blender::Span loops = me->loops(); - BKE_mesh_recalc_looptri( - loops.data(), polys.data(), positions, me->totloop, me->totpoly, looptri); + blender::bke::mesh::looptris_calc( + me->vert_positions(), me->polys(), me->loops(), {looptri, tottri}); 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.cc b/source/blender/render/intern/multires_bake.cc index 1185dd971bd..c6c754bfe28 100644 --- a/source/blender/render/intern/multires_bake.cc +++ b/source/blender/render/intern/multires_bake.cc @@ -24,7 +24,7 @@ #include "BKE_image.h" #include "BKE_lib_id.h" #include "BKE_material.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_tangent.h" #include "BKE_modifier.h" #include "BKE_multires.h" @@ -62,6 +62,7 @@ struct MultiresBakeResult { struct MResolvePixelData { const float (*vert_positions)[3]; const float (*vert_normals)[3]; + int verts_num; const MPoly *polys; const int *material_indices; const bool *sharp_faces; @@ -126,8 +127,11 @@ static void multiresbake_get_normal(const MResolvePixelData *data, copy_v3_v3(r_normal, data->precomputed_normals[poly_index]); } else { - BKE_mesh_calc_poly_normal( - &poly, &data->mloop[poly.loopstart], data->vert_positions, r_normal); + copy_v3_v3( + r_normal, + blender::bke::mesh::poly_normal_calc( + {reinterpret_cast(data->vert_positions), data->verts_num}, + {&data->mloop[poly.loopstart], poly.totloop})); } } } @@ -557,6 +561,7 @@ static void do_multires_bake(MultiresBakeRender *bkr, CustomData_get_layer_named(&dm->polyData, CD_PROP_BOOL, "sharp_face")); handle->data.vert_positions = positions; handle->data.vert_normals = vert_normals; + handle->data.verts_num = dm->getNumVerts(dm); handle->data.mloopuv = mloopuv; BKE_image_get_tile_uv(ima, tile->tile_number, handle->data.uv_offset); handle->data.mlooptri = mlooptri; diff --git a/source/blender/render/intern/texture_margin.cc b/source/blender/render/intern/texture_margin.cc index 09761b16149..f99e895d303 100644 --- a/source/blender/render/intern/texture_margin.cc +++ b/source/blender/render/intern/texture_margin.cc @@ -13,7 +13,7 @@ #include "BKE_DerivedMesh.h" #include "BKE_customdata.h" -#include "BKE_mesh.h" +#include "BKE_mesh.hh" #include "BKE_mesh_mapping.h" #include "DNA_mesh_types.h" @@ -515,12 +515,8 @@ static void generate_margin(ImBuf *ibuf, tottri = poly_to_tri_count(me->totpoly, me->totloop); looptri_mem = static_cast(MEM_mallocN(sizeof(*looptri) * tottri, __func__)); - BKE_mesh_recalc_looptri(mloop, - polys, - reinterpret_cast(me->vert_positions().data()), - me->totloop, - me->totpoly, - looptri_mem); + bke::mesh::looptris_calc( + me->vert_positions(), me->polys(), me->loops(), {looptri_mem, tottri}); looptri = looptri_mem; } else {