Commit: 7fb57e9e6d36ebe2b921e6fd6bfb706c0796915a Author: Hans Goudey Date: Sat Nov 26 20:44:51 2022 -0600 Branches: refactor-mesh-position-generic https://developer.blender.org/rB7fb57e9e6d36ebe2b921e6fd6bfb706c0796915a
Merge branch 'master' into refactor-mesh-position-generic =================================================================== =================================================================== diff --cc source/blender/blenkernel/BKE_mesh.h index 700274a7872,577107149ee..934847ae925 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@@ -431,6 -437,15 +438,11 @@@ bool BKE_mesh_vertex_normals_are_dirty( */ bool BKE_mesh_poly_normals_are_dirty(const struct Mesh *mesh); + void BKE_mesh_calc_poly_normal(const struct MPoly *mpoly, + const struct MLoop *loopstart, - const struct MVert *mvarray, ++ const float (*positions)[3], + float r_no[3]); -void BKE_mesh_calc_poly_normal_coords(const struct MPoly *mpoly, - const struct MLoop *loopstart, - const float (*vertex_coords)[3], - float r_no[3]); + /** * Calculate face normals directly into a result array. * @@@ -693,13 -708,9 +705,9 @@@ void BKE_mesh_set_custom_normals_from_v /* *** mesh_evaluate.cc *** */ - void BKE_mesh_calc_poly_normal(const struct MPoly *mpoly, - const struct MLoop *loopstart, - const float (*positions)[3], - float r_no[3]); void BKE_mesh_calc_poly_center(const struct MPoly *mpoly, const struct MLoop *loopstart, - const struct MVert *mvarray, + const float (*positions)[3], float r_cent[3]); /* NOTE: passing poly-normal is only a speedup so we can skip calculating it. */ float BKE_mesh_calc_poly_area(const struct MPoly *mpoly, diff --cc source/blender/blenkernel/BKE_mesh_legacy_convert.h index 27932852b98,e46942aa9e9..97234ccd139 --- a/source/blender/blenkernel/BKE_mesh_legacy_convert.h +++ b/source/blender/blenkernel/BKE_mesh_legacy_convert.h @@@ -86,13 -82,9 +86,16 @@@ void BKE_mesh_legacy_convert_material_i */ void BKE_mesh_legacy_convert_mpoly_to_material_indices(struct Mesh *mesh); + /** Convert from runtime loose edge cache to legacy edge flag. */ + void BKE_mesh_legacy_convert_loose_edges_to_flag(struct Mesh *mesh); + +struct MVert *BKE_mesh_legacy_convert_positions_to_verts( + Mesh *mesh, + blender::ResourceScope &temp_arrays_for_convert, + blender::Vector<CustomDataLayer, 16> &vert_layers_to_write); + +void BKE_mesh_legacy_convert_verts_to_positions(Mesh *mesh); + #endif /** diff --cc source/blender/blenkernel/intern/mesh.cc index d148fc42ff0,02d375bd782..9a13e3b5293 --- a/source/blender/blenkernel/intern/mesh.cc +++ b/source/blender/blenkernel/intern/mesh.cc @@@ -259,16 -263,8 +260,17 @@@ static void mesh_blend_write(BlendWrite ".select_edge", ".select_poly"}); + mesh->mvert = BKE_mesh_legacy_convert_positions_to_verts( + mesh, temp_arrays_for_legacy_format, vert_layers); + BKE_mesh_legacy_convert_hide_layers_to_flags(mesh); + BKE_mesh_legacy_convert_selection_layers_to_flags(mesh); + BKE_mesh_legacy_convert_material_indices_to_mpoly(mesh); + BKE_mesh_legacy_bevel_weight_from_layers(mesh); + BKE_mesh_legacy_face_set_from_generic(mesh, poly_layers); + BKE_mesh_legacy_edge_crease_from_layers(mesh); ++ BKE_mesh_legacy_convert_loose_edges_to_flag(mesh); + /* Set deprecated mesh data pointers for forward compatibility. */ - mesh->mvert = const_cast<MVert *>(mesh->verts().data()); mesh->medge = const_cast<MEdge *>(mesh->edges().data()); mesh->mpoly = const_cast<MPoly *>(mesh->polys().data()); mesh->mloop = const_cast<MLoop *>(mesh->loops().data()); diff --cc source/blender/blenkernel/intern/mesh_evaluate.cc index 1c7087e0014,de080c9dff2..ca2580838b7 --- a/source/blender/blenkernel/intern/mesh_evaluate.cc +++ b/source/blender/blenkernel/intern/mesh_evaluate.cc @@@ -39,65 -38,9 +39,9 @@@ using blender::VArray /** \name Polygon Calculations * \{ */ - /* - * COMPUTE POLY NORMAL - * - * Computes the normal of a planar - * polygon See Graphics Gems for - * computing newell normal. - */ - static void mesh_calc_ngon_normal(const MPoly *mpoly, - const MLoop *loopstart, - const float (*positions)[3], - float normal[3]) - { - const int nverts = mpoly->totloop; - const float *v_prev = positions[loopstart[nverts - 1].v]; - const float *v_curr; - - zero_v3(normal); - - /* Newell's Method */ - for (int i = 0; i < nverts; i++) { - v_curr = positions[loopstart[i].v]; - add_newell_cross_v3_v3v3(normal, v_prev, v_curr); - v_prev = v_curr; - } - - if (UNLIKELY(normalize_v3(normal) == 0.0f)) { - normal[2] = 1.0f; /* other axis set to 0.0 */ - } - } - - void BKE_mesh_calc_poly_normal(const MPoly *mpoly, - const MLoop *loopstart, - const float (*positions)[3], - float r_no[3]) - { - if (mpoly->totloop > 4) { - mesh_calc_ngon_normal(mpoly, loopstart, positions, r_no); - } - else if (mpoly->totloop == 3) { - normal_tri_v3( - r_no, positions[loopstart[0].v], positions[loopstart[1].v], positions[loopstart[2].v]); - } - else if (mpoly->totloop == 4) { - normal_quad_v3(r_no, - positions[loopstart[0].v], - positions[loopstart[1].v], - positions[loopstart[2].v], - positions[loopstart[3].v]); - } - else { /* horrible, two sided face! */ - r_no[0] = 0.0; - r_no[1] = 0.0; - r_no[2] = 1.0; - } - } - static void mesh_calc_ngon_center(const MPoly *mpoly, const MLoop *loopstart, - const MVert *mvert, + const float (*positions)[3], float cent[3]) { const float w = 1.0f / float(mpoly->totloop); @@@ -229,7 -171,7 +173,7 @@@ static float UNUSED_FUNCTION(mesh_calc_ */ static float mesh_calc_poly_volume_centroid_with_reference_center(const MPoly *mpoly, const MLoop *loopstart, - const float (*positions)[3], - const MVert *mvarray, ++ const Span<float3> positions, const float reference_center[3], float r_cent[3]) { @@@ -351,10 -293,10 +295,10 @@@ void BKE_mesh_poly_edgebitmap_insert(ui bool BKE_mesh_center_median(const Mesh *me, float r_cent[3]) { - const Span<MVert> verts = me->verts(); + const Span<float3> positions = me->positions(); zero_v3(r_cent); - for (const float3 &position : positions) { - add_v3_v3(r_cent, position); - for (const MVert &vert : verts) { - add_v3_v3(r_cent, vert.co); ++ for (const int i : positions.index_range()) { ++ add_v3_v3(r_cent, positions[i]); } /* otherwise we get NAN for 0 verts */ if (me->totvert) { @@@ -437,7 -378,7 +381,7 @@@ bool BKE_mesh_center_of_volume(const Me float poly_volume; float total_volume = 0.0f; float poly_cent[3]; - const float(*positions)[3] = BKE_mesh_positions(me); - const MVert *verts = BKE_mesh_verts(me); ++ const Span<float3> positions = me->positions(); const MPoly *polys = BKE_mesh_polys(me); const MLoop *loops = BKE_mesh_loops(me); diff --cc source/blender/blenkernel/intern/mesh_legacy_convert.cc index 7f203252bc8,1673e972a32..d3e93484784 --- a/source/blender/blenkernel/intern/mesh_legacy_convert.cc +++ b/source/blender/blenkernel/intern/mesh_legacy_convert.cc @@@ -1553,52 -1541,29 +1548,79 @@@ void BKE_mesh_legacy_convert_flags_to_s /** \} */ + /* -------------------------------------------------------------------- */ + /** \name Loose Edges + * \{ */ + + void BKE_mesh_legacy_convert_loose_edges_to_flag(Mesh *mesh) + { + using namespace blender; + using namespace blender::bke; + + const LooseEdgeCache &loose_edges = mesh->loose_edges(); + MutableSpan<MEdge> edges = mesh->edges_for_write(); + threading::parallel_for(edges.index_range(), 4096, [&](const IndexRange range) { + if (loose_edges.count == 0) { + for (const int64_t i : range) { + edges[i].flag &= ~ME_LOOSEEDGE; + } + } + else { + for (const int64_t i : range) { + SET_FLAG_FROM_TEST(edges[i].flag, loose_edges.is_loose_bits[i], ME_LOOSEEDGE); + } + } + }); + } + + /** \} */ ++ +/* -------------------------------------------------------------------- */ +/** \name Vertex and Position Conversion + * \{ */ + +MVert *BKE_mesh_legacy_convert_positions_to_verts( + Mesh *mesh, + blender::ResourceScope &temp_arrays_for_convert, + blender::Vector<CustomDataLayer, 16> &vert_layers_to_write) +{ + using namespace blender; + + const Span<float3> positions = mesh->positions(); + + CustomDataLayer mvert_layer{}; + mvert_layer.type = CD_MVERT; + MutableSpan<MVert> verts = temp_arrays_for_convert.construct<Array<MVert>>(mesh->totvert); + mvert_layer.data = verts.data(); + + threading::parallel_for(verts.index_range(), 2048, [&](IndexRange range) { + for (const int i : range) { + copy_v3_v3(verts[i].co_legacy, positions[i]); + } + }); + + vert_layers_to_write.append(mvert_layer); + return verts.data(); +} + +void BKE_mesh_legacy_convert_verts_to_positions(Mesh *mesh) +{ + using namespace blender; + using namespace blender::bke; + + const Span<MVert> verts(static_cast<MVert *>(CustomData_get_layer(&mesh->vdata, CD_MVERT)), + mesh->totvert); + MutableSpan<float3> positions( + static_cast<float3 *>(CustomData_add_layer_named( + @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs