[Bf-blender-cvs] [54b650bc297] refactor-mesh-remove-pointers: Merge branch 'master' into refactor-mesh-remove-pointers

Hans Goudey noreply at git.blender.org
Wed Aug 31 20:32:41 CEST 2022


Commit: 54b650bc297cce00a44da527f7e63e07c4d7e21f
Author: Hans Goudey
Date:   Wed Aug 31 12:40:18 2022 -0500
Branches: refactor-mesh-remove-pointers
https://developer.blender.org/rB54b650bc297cce00a44da527f7e63e07c4d7e21f

Merge branch 'master' into refactor-mesh-remove-pointers

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



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

diff --cc source/blender/blenkernel/BKE_mesh.h
index 7e36f0e5b31,ec6799ee995..0adcbd74e31
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@@ -6,16 -6,13 +6,20 @@@
   * \ingroup bke
   */
  
+ #include "DNA_mesh_types.h"
+ 
+ #include "BKE_customdata.h"
+ #include "BKE_mesh_types.h"
  #include "BLI_compiler_attrs.h"
 +#include "BLI_compiler_compat.h"
  #include "BLI_utildefines.h"
  
 +#include "DNA_mesh_types.h"
 +#include "DNA_meshdata_types.h"
 +
 +#include "BKE_customdata.h"
 +#include "BKE_mesh_types.h"
 +
  struct BLI_Stack;
  struct BMesh;
  struct BMeshCreateParams;
@@@ -1026,103 -1022,30 +1030,127 @@@ char *BKE_mesh_debug_info(const struct 
  void BKE_mesh_debug_print(const struct Mesh *me) ATTR_NONNULL(1);
  #endif
  
+ /**
+  * \return The material index for each polygon. May be null.
+  * \note In C++ code, prefer using the attribute API (#MutableAttributeAccessor)/
+  */
+ BLI_INLINE const int *BKE_mesh_material_indices(const Mesh *mesh)
+ {
+   return (const int *)CustomData_get_layer_named(&mesh->pdata, CD_PROP_INT32, "material_index");
+ }
+ 
+ /**
+  * \return The material index for each polygon. Create the layer if it doesn't exist.
+  * \note In C++ code, prefer using the attribute API (#MutableAttributeAccessor)/
+  */
+ BLI_INLINE int *BKE_mesh_material_indices_for_write(Mesh *mesh)
+ {
+   int *indices = (int *)CustomData_duplicate_referenced_layer_named(
+       &mesh->pdata, CD_PROP_INT32, "material_index", mesh->totpoly);
+   if (indices) {
+     return indices;
+   }
+   return (int *)CustomData_add_layer_named(
+       &mesh->pdata, CD_PROP_INT32, CD_SET_DEFAULT, NULL, mesh->totpoly, "material_index");
+ }
+ 
 +BLI_INLINE const MVert *BKE_mesh_vertices(const Mesh *mesh)
 +{
 +  return (const MVert *)CustomData_get_layer(&mesh->vdata, CD_MVERT);
 +}
 +BLI_INLINE MVert *BKE_mesh_vertices_for_write(Mesh *mesh)
 +{
 +  return (MVert *)CustomData_duplicate_referenced_layer(&mesh->vdata, CD_MVERT, mesh->totvert);
 +}
 +
 +BLI_INLINE const MEdge *BKE_mesh_edges(const Mesh *mesh)
 +{
 +  return (const MEdge *)CustomData_get_layer(&mesh->edata, CD_MEDGE);
 +}
 +BLI_INLINE MEdge *BKE_mesh_edges_for_write(Mesh *mesh)
 +{
 +  return (MEdge *)CustomData_duplicate_referenced_layer(&mesh->edata, CD_MEDGE, mesh->totedge);
 +}
 +
 +BLI_INLINE const MPoly *BKE_mesh_polygons(const Mesh *mesh)
 +{
 +  return (const MPoly *)CustomData_get_layer(&mesh->pdata, CD_MPOLY);
 +}
 +BLI_INLINE MPoly *BKE_mesh_polygons_for_write(Mesh *mesh)
 +{
 +  return (MPoly *)CustomData_duplicate_referenced_layer(&mesh->pdata, CD_MPOLY, mesh->totpoly);
 +}
 +
 +BLI_INLINE const MLoop *BKE_mesh_loops(const Mesh *mesh)
 +{
 +  return (const MLoop *)CustomData_get_layer(&mesh->ldata, CD_MLOOP);
 +}
 +BLI_INLINE MLoop *BKE_mesh_loops_for_write(Mesh *mesh)
 +{
 +  return (MLoop *)CustomData_duplicate_referenced_layer(&mesh->ldata, CD_MLOOP, mesh->totloop);
 +}
 +
 +BLI_INLINE const MDeformVert *BKE_mesh_deform_verts(const Mesh *mesh)
 +{
 +  return (const MDeformVert *)CustomData_get_layer(&mesh->vdata, CD_MDEFORMVERT);
 +}
 +BLI_INLINE MDeformVert *BKE_mesh_deform_verts_for_write(Mesh *mesh)
 +{
 +  MDeformVert *dvert = (MDeformVert *)CustomData_duplicate_referenced_layer(
 +      &mesh->vdata, CD_MDEFORMVERT, mesh->totvert);
 +  if (dvert) {
 +    return dvert;
 +  }
 +  return (MDeformVert *)CustomData_add_layer(
-       &mesh->vdata, CD_MDEFORMVERT, CD_CALLOC, NULL, mesh->totvert);
++      &mesh->vdata, CD_MDEFORMVERT, CD_SET_DEFAULT, NULL, mesh->totvert);
 +}
 +
 +#ifdef __cplusplus
 +}
 +#endif
 +
  #ifdef __cplusplus
 +
 +#  include "BLI_span.hh"
 +
 +namespace blender::bke {
 +
 +inline Span<MVert> mesh_vertices(const Mesh &mesh)
 +{
 +  return {BKE_mesh_vertices(&mesh), mesh.totvert};
 +}
 +inline MutableSpan<MVert> mesh_vertices_for_write(Mesh &mesh)
 +{
 +  return {BKE_mesh_vertices_for_write(&mesh), mesh.totvert};
 +}
 +
 +inline Span<MEdge> mesh_edges(const Mesh &mesh)
 +{
 +  return {BKE_mesh_edges(&mesh), mesh.totedge};
  }
 +inline MutableSpan<MEdge> mesh_edges_for_write(Mesh &mesh)
 +{
 +  return {BKE_mesh_edges_for_write(&mesh), mesh.totedge};
 +}
 +
 +inline Span<MPoly> mesh_polygons(const Mesh &mesh)
 +{
 +  return {BKE_mesh_polygons(&mesh), mesh.totpoly};
 +}
 +inline MutableSpan<MPoly> mesh_polygons_for_write(Mesh &mesh)
 +{
 +  return {BKE_mesh_polygons_for_write(&mesh), mesh.totpoly};
 +}
 +
 +inline Span<MLoop> mesh_loops(const Mesh &mesh)
 +{
 +  return {BKE_mesh_loops(&mesh), mesh.totloop};
 +}
 +inline MutableSpan<MLoop> mesh_loops_for_write(Mesh &mesh)
 +{
 +  return {BKE_mesh_loops_for_write(&mesh), mesh.totloop};
 +}
 +
 +}  // namespace blender::bke
 +
  #endif
diff --cc source/blender/blenkernel/intern/gpencil_geom.cc
index 453028ae9d8,ce2e106c664..26d9e9051f2
--- a/source/blender/blenkernel/intern/gpencil_geom.cc
+++ b/source/blender/blenkernel/intern/gpencil_geom.cc
@@@ -2712,8 -2711,11 +2715,11 @@@ bool BKE_gpencil_convert_mesh(Main *bma
      bGPDframe *gpf_fill = BKE_gpencil_layer_frame_get(
          gpl_fill, scene->r.cfra + frame_offset, GP_GETFRAME_ADD_NEW);
      int i;
+ 
+     const VArray<int> mesh_material_indices = mesh_attributes(*me_eval).lookup_or_default<int>(
+         "material_index", ATTR_DOMAIN_FACE, 0);
      for (i = 0; i < mpoly_len; i++) {
 -      const MPoly *mp = &mpoly[i];
 +      const MPoly *mp = &polys[i];
  
        /* Find material. */
        int mat_idx = 0;
diff --cc source/blender/blenkernel/intern/mesh_boolean_convert.cc
index 6c85417a1b5,fb4a9248d8d..fe9c5023c15
--- a/source/blender/blenkernel/intern/mesh_boolean_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_boolean_convert.cc
@@@ -732,10 -728,11 +738,13 @@@ static Mesh *imesh_to_mesh(IMesh *im, M
  
    /* Set the loopstart and totloop for each output poly,
     * and set the vertices in the appropriate loops. */
+   bke::SpanAttributeWriter<int> dst_material_indices =
+       bke::mesh_attributes_for_write(*result).lookup_or_add_for_write_only_span<int>(
+           "material_index", ATTR_DOMAIN_FACE);
    int cur_loop_index = 0;
 -  MLoop *l = result->mloop;
 +  MutableSpan<MLoop> dst_loops = bke::mesh_loops_for_write(*result);
 +  MutableSpan<MPoly> dst_polys = bke::mesh_polygons_for_write(*result);
 +  MLoop *l = dst_loops.data();
    for (int fi : im->face_index_range()) {
      const Face *f = im->face(fi);
      const Mesh *orig_me;
diff --cc source/blender/blenkernel/intern/mesh_convert.cc
index f44197faf71,393d54bb03e..794077d7b00
--- a/source/blender/blenkernel/intern/mesh_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_convert.cc
@@@ -678,8 -682,9 +684,7 @@@ void BKE_mesh_from_pointcloud(const Poi
        &pointcloud->pdata, &me->vdata, CD_MASK_PROP_ALL, CD_DUPLICATE, pointcloud->totpoint);
  
    /* Convert the Position attribute to a mesh vertex. */
-   (MVert *)CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, nullptr, me->totvert);
 -  me->mvert = (MVert *)CustomData_add_layer(
 -      &me->vdata, CD_MVERT, CD_SET_DEFAULT, nullptr, me->totvert);
--  CustomData_update_typemap(&me->vdata);
++  CustomData_add_layer(&me->vdata, CD_MVERT, CD_SET_DEFAULT, nullptr, me->totvert);
  
    const int layer_idx = CustomData_get_named_layer_index(
        &me->vdata, CD_PROP_FLOAT3, POINTCLOUD_ATTR_POSITION);
diff --cc source/blender/blenkernel/intern/mesh_normals.cc
index c5baf30b047,f90a2e1b887..240d8e8124e
--- a/source/blender/blenkernel/intern/mesh_normals.cc
+++ b/source/blender/blenkernel/intern/mesh_normals.cc
@@@ -2061,24 -2054,20 +2061,24 @@@ static void mesh_set_custom_normals(Mes
    }
    else {
      clnors = (short(*)[2])CustomData_add_layer(
-         &mesh->ldata, CD_CUSTOMLOOPNORMAL, CD_CALLOC, nullptr, numloops);
+         &mesh->ldata, CD_CUSTOMLOOPNORMAL, CD_SET_DEFAULT, nullptr, numloops);
    }
 +  const Span<MVert> verts = blender::bke::mesh_vertices(*mesh);
 +  MutableSpan<MEdge> edges = blender::bke::mesh_edges_for_write(*mesh);
 +  const Span<MPoly> polys = blender::bke::mesh_polygons(*mesh);
 +  const Span<MLoop> loops = blender::bke::mesh_loops(*mesh);
  
 -  mesh_normals_loop_custom_set(mesh->mvert,
 +  mesh_normals_loop_custom_set(verts.data(),
                                 BKE_mesh_vertex_normals_ensure(mesh),
 -                               mesh->totvert,
 -                               mesh->medge,
 -                               mesh->totedge,
 -                               mesh->mloop,
 +                               verts.size(),
 +                               edges.data(),
 +                               edges.size(),
 +                               loops.data(),
                                 r_custom_nors,
 -                               mesh->totloop,
 -                               mesh->mpoly,
 +                               loops.size(),
 +                               polys.data(),
                                 BKE_mesh_poly_normals_ensure(mesh),
 -                               mesh->totpoly,
 +                               polys.size(),
                                 clnors,
                                 use_vertices);
  }
diff --cc source/blender/blenkernel/intern/particle_system.c
index 6dd6b0455d0,254cea0bd8b..14c4691413d
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@@ -3322,11 -3322,12 +3322,10 @@@ static void hair_create_input_mesh(Part
    mesh = *r_mesh;
    if (!mesh) {
      *r_mesh = mesh = BKE_mesh_new_nomain(totpoint, totedge, 0, 0, 0);
-     CustomData_add_layer(&mesh->vdata, CD_MDEFORMVERT, CD_CALLOC, NULL, mesh->totvert);
 -    CustomData_add_layer(&mesh->vdata, CD_MDEFORMVERT, CD_SET_DEFAULT, NULL, mesh->totvert);
 -    BKE_mesh_update_customdata_pointers(mesh, false);
    }
 -  mvert = mesh->mvert;
 -  medge = mesh->medge;
 -  dvert = mesh->dvert;
 +  mvert = BKE_mesh_vertices_for_write(mesh);
 +  medge = BKE_mesh_edges_for_write(mesh);
 +  dvert = BKE_mesh_deform_verts_for_write(mesh);
  
    if (psys->clmd->hairdata == NULL) {
      psys->clmd->hairdata = MEM_mallocN(sizeof(ClothHairData) * totpoint, "hair data");
diff --cc source/blender/blenkernel/intern/subdiv_ccg_material.c
index a351da695b6,9095a628418..e84a5b6ca46
-

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list