[Bf-blender-cvs] [35b3ef36fcd] refactor-mesh-remove-pointers: Merge branch 'refactor-mesh-hide-generic' into refactor-mesh-remove-pointers

Hans Goudey noreply at git.blender.org
Sun Jul 31 18:27:53 CEST 2022


Commit: 35b3ef36fcd125c479eb8ba5fd531fd5a7715b80
Author: Hans Goudey
Date:   Sun Jul 31 10:44:36 2022 -0500
Branches: refactor-mesh-remove-pointers
https://developer.blender.org/rB35b3ef36fcd125c479eb8ba5fd531fd5a7715b80

Merge branch 'refactor-mesh-hide-generic' into refactor-mesh-remove-pointers

===================================================================



===================================================================

diff --cc source/blender/editors/sculpt_paint/curves_sculpt_add.cc
index 844b91d97f5,f6539284f74..12d3d9d663e
--- a/source/blender/editors/sculpt_paint/curves_sculpt_add.cc
+++ b/source/blender/editors/sculpt_paint/curves_sculpt_add.cc
@@@ -134,12 -136,10 +138,16 @@@ struct AddOperationExecutor 
        return;
      }
      surface_eval_ = BKE_object_get_evaluated_mesh(surface_ob_eval_);
 +    surface_vertices_eval_ = bke::mesh_vertices(*surface_eval_);
 +    surface_loops_eval_ = bke::mesh_loops(*surface_eval_);
 +    surface_looptris_eval_ = {BKE_mesh_runtime_looptri_ensure(surface_eval_),
 +                              BKE_mesh_runtime_looptri_len(surface_eval_)};
 +    BKE_bvhtree_from_mesh_get(&surface_bvh_eval_, surface_eval_, BVHTREE_FROM_LOOPTRI, 2);
 +    BLI_SCOPED_DEFER([&]() { free_bvhtree_from_mesh(&surface_bvh_eval_); });
+     if (surface_eval_->totpoly == 0) {
+       report_empty_evaluated_surface(stroke_extension.reports);
+       return;
+     }
  
      curves_sculpt_ = ctx_.scene->toolsettings->curves_sculpt;
      brush_ = BKE_paint_brush_for_read(&curves_sculpt_->paint);
diff --cc source/blender/editors/sculpt_paint/curves_sculpt_slide.cc
index a3f7d46255d,ebdff8a6c4b..ccb0bd69c51
--- a/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc
+++ b/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc
@@@ -168,8 -166,12 +168,10 @@@ struct SlideOperationExecutor 
  
      surface_ob_orig_ = curves_id_orig_->surface;
      surface_orig_ = static_cast<Mesh *>(surface_ob_orig_->data);
-     surface_looptris_orig_ = {BKE_mesh_runtime_looptri_ensure(surface_orig_),
-                               BKE_mesh_runtime_looptri_len(surface_orig_)};
+     if (surface_orig_->totpoly == 0) {
+       report_empty_original_surface(stroke_extension.reports);
+       return;
+     }
 -    surface_looptris_orig_ = {BKE_mesh_runtime_looptri_ensure(surface_orig_),
 -                              BKE_mesh_runtime_looptri_len(surface_orig_)};
      surface_uv_map_orig_ =
          bke::mesh_attributes(*surface_orig_).lookup<float2>(uv_map_name, ATTR_DOMAIN_CORNER);
      if (surface_uv_map_orig_.is_empty()) {
@@@ -191,10 -193,12 +193,15 @@@
      if (surface_eval_ == nullptr) {
        return;
      }
 +    surface_looptris_eval_ = {BKE_mesh_runtime_looptri_ensure(surface_eval_),
 +                              BKE_mesh_runtime_looptri_len(surface_eval_)};
 +    surface_vertices_eval_ = bke::mesh_vertices(*surface_eval_);
 +    surface_loops_eval_ = bke::mesh_loops(*surface_eval_);
+     if (surface_eval_->totpoly == 0) {
+       report_empty_evaluated_surface(stroke_extension.reports);
+       return;
+     }
 -    surface_looptris_eval_ = {BKE_mesh_runtime_looptri_ensure(surface_eval_),
 -                              BKE_mesh_runtime_looptri_len(surface_eval_)};
++
      surface_uv_map_eval_ =
          bke::mesh_attributes(*surface_eval_).lookup<float2>(uv_map_name, ATTR_DOMAIN_CORNER);
      if (surface_uv_map_eval_.is_empty()) {
diff --cc source/blender/editors/sculpt_paint/sculpt.c
index dcfe0124b54,20cc48f3d83..72a761c0ccf
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@@ -597,11 -602,11 +602,11 @@@ void SCULPT_visibility_sync_all_vertex_
  {
    if (BKE_pbvh_type(ss->pbvh) == PBVH_FACES) {
      for (int i = 0; i < ss->totfaces; i++) {
 -      MPoly *poly = &ss->mpoly[i];
 +      const MPoly *poly = &ss->mpoly[i];
        bool poly_visible = true;
        for (int l = 0; l < poly->totloop; l++) {
 -        MLoop *loop = &ss->mloop[poly->loopstart + l];
 +        const MLoop *loop = &ss->mloop[poly->loopstart + l];
-         if (!SCULPT_vertex_visible_get(ss, (int)loop->v)) {
+         if (!SCULPT_vertex_visible_get(ss, BKE_pbvh_make_vref(loop->v))) {
            poly_visible = false;
          }
        }
diff --cc source/blender/editors/sculpt_paint/sculpt_expand.c
index 3fe753e94ea,4eb9f93445f..4a9689d1367
--- a/source/blender/editors/sculpt_paint/sculpt_expand.c
+++ b/source/blender/editors/sculpt_paint/sculpt_expand.c
@@@ -666,19 -691,21 +691,21 @@@ static float *sculpt_expand_diagonals_f
  
    /* Propagate the falloff increasing the value by 1 each time a new vertex is visited. */
    Mesh *mesh = ob->data;
-   const MLoop *loops = BKE_mesh_loops(mesh);
    while (!BLI_gsqueue_is_empty(queue)) {
-     int v_next;
+     PBVHVertRef v_next;
      BLI_gsqueue_pop(queue, &v_next);
-     for (int j = 0; j < ss->pmap[v_next].count; j++) {
-       const MPoly *p = &ss->mpoly[ss->pmap[v_next].indices[j]];
+ 
+     int v_next_i = BKE_pbvh_vertex_to_index(ss->pbvh, v_next);
+ 
+     for (int j = 0; j < ss->pmap[v_next_i].count; j++) {
+       MPoly *p = &ss->mpoly[ss->pmap[v_next_i].indices[j]];
        for (int l = 0; l < p->totloop; l++) {
-         const int neighbor_v = loops[p->loopstart + l].v;
-         if (BLI_BITMAP_TEST(visited_vertices, neighbor_v)) {
 -        const PBVHVertRef neighbor_v = BKE_pbvh_make_vref(mesh->mloop[p->loopstart + l].v);
++        const PBVHVertRef neighbor_v = BKE_pbvh_make_vref(ss->mloop[p->loopstart + l].v);
+         if (BLI_BITMAP_TEST(visited_vertices, neighbor_v.i)) {
            continue;
          }
-         dists[neighbor_v] = dists[v_next] + 1.0f;
-         BLI_BITMAP_ENABLE(visited_vertices, neighbor_v);
+         dists[neighbor_v.i] = dists[v_next_i] + 1.0f;
+         BLI_BITMAP_ENABLE(visited_vertices, neighbor_v.i);
          BLI_gsqueue_push(queue, &neighbor_v);
        }
      }
diff --cc source/blender/geometry/GEO_add_curves_on_mesh.hh
index 68c8dc5b76b,2d2ba89a18f..abe32382195
--- a/source/blender/geometry/GEO_add_curves_on_mesh.hh
+++ b/source/blender/geometry/GEO_add_curves_on_mesh.hh
@@@ -45,10 -51,11 +51,15 @@@ struct AddCurvesOnMeshOutputs 
  /**
   * Generate new curves on a mesh surface with the given inputs. Existing curves stay intact.
   */
- void add_curves_on_mesh(bke::CurvesGeometry &curves, const AddCurvesOnMeshInputs &inputs);
+ AddCurvesOnMeshOutputs add_curves_on_mesh(bke::CurvesGeometry &curves,
+                                           const AddCurvesOnMeshInputs &inputs);
+ 
+ float3 compute_surface_point_normal(const MLoopTri &looptri,
+                                     const float3 &bary_coord,
+                                     const Span<float3> corner_normals);
  
 +float3 compute_surface_point_normal(const MLoopTri &looptri,
 +                                    const float3 &bary_coord,
 +                                    const Span<float3> corner_normals);
 +
  }  // namespace blender::geometry
diff --cc source/blender/io/alembic/intern/abc_reader_mesh.cc
index 1c4080689d2,bacc1f06599..002fcbdf20c
--- a/source/blender/io/alembic/intern/abc_reader_mesh.cc
+++ b/source/blender/io/alembic/intern/abc_reader_mesh.cc
@@@ -921,7 -914,15 +909,13 @@@ static void read_edge_creases(Mesh *mes
      return;
    }
  
 -  MEdge *edges = mesh->medge;
 -  const int totedge = mesh->totedge;
 -
 -  EdgeHash *edge_hash = BLI_edgehash_new_ex(__func__, mesh->totedge);
 +  MutableSpan<MEdge> edges = blender::bke::mesh_edges_for_write(*mesh);
++  EdgeHash *edge_hash = BLI_edgehash_new_ex(__func__, edges.size());
+ 
 -  for (int i = 0; i < totedge; i++) {
++  for (const int i : edges.index_range()) {
+     MEdge *edge = &edges[i];
+     BLI_edgehash_insert(edge_hash, edge->v1, edge->v2, edge);
+   }
  
    for (int i = 0, s = 0, e = indices->size(); i < e; i += 2, s++) {
      int v1 = (*indices)[i];
diff --cc source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc
index c9189248842,a5edc6c4b3f..0402919acc5
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc
@@@ -179,14 -179,15 +179,15 @@@ Mesh *create_line_mesh(const float3 sta
  
    Mesh *mesh = BKE_mesh_new_nomain(count, count - 1, 0, 0, 0);
    BKE_id_material_eval_ensure_default_slot(&mesh->id);
 -  MutableSpan<MVert> verts{mesh->mvert, mesh->totvert};
 -  MutableSpan<MEdge> edges{mesh->medge, mesh->totedge};
 +  MutableSpan<MVert> vertices = bke::mesh_vertices_for_write(*mesh);
 +  MutableSpan<MEdge> edges = bke::mesh_edges_for_write(*mesh);
  
    threading::parallel_invoke(
+       1024 < count,
        [&]() {
 -        threading::parallel_for(verts.index_range(), 4096, [&](IndexRange range) {
 +        threading::parallel_for(vertices.index_range(), 4096, [&](IndexRange range) {
            for (const int i : range) {
 -            copy_v3_v3(verts[i].co, start + delta * i);
 +            copy_v3_v3(vertices[i].co, start + delta * i);
            }
          });
        },
diff --cc source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc
index bc641b1b264,85facf1e758..132af44dab1
--- 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
@@@ -265,20 -301,22 +301,22 @@@ static Mesh *create_uv_sphere_mesh(cons
                                     sphere_corner_total(segments, rings),
                                     sphere_face_total(segments, rings));
    BKE_id_material_eval_ensure_default_slot(&mesh->id);
 -  MutableSpan<MVert> verts{mesh->mvert, mesh->totvert};
 -  MutableSpan<MLoop> loops{mesh->mloop, mesh->totloop};
 -  MutableSpan<MEdge> edges{mesh->medge, mesh->totedge};
 -  MutableSpan<MPoly> polys{mesh->mpoly, mesh->totpoly};
 +  MutableSpan<MVert> vertices = bke::mesh_vertices_for_write(*mesh);
 +  MutableSpan<MEdge> edges = bke::mesh_edges_for_write(*mesh);
 +  MutableSpan<MPoly> polygons = bke::mesh_polygons_for_write(*mesh);
 +  MutableSpan<MLoop> loops = bke::mesh_loops_for_write(*mesh);
  
-   MutableSpan vert_normals{(float3 *)BKE_mesh_vertex_normals_for_write(mesh), mesh->totvert};
-   calculate_sphere_vertex_data(vertices, vert_normals, radius, segments, rings);
-   BKE_mesh_vertex_normals_clear_dirty(mesh);
- 
-   calculate_sphere_edge_indices(edges, segments, rings);
- 
-   calculate_sphere_faces(loops, polygons, segments, rings);
- 
-   calculate_sphere_uvs(mesh, segments, rings);
+   threading::parallel_invoke(
+       1024 < segments * rings,
+       [&]() {
+         MutableSpan vert_normals{(float3 *)BK

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list