[Bf-blender-cvs] [91dd29fd45d] master: Attributes: Allow calling "finish" on empty accessors

Hans Goudey noreply at git.blender.org
Wed Sep 21 20:18:06 CEST 2022


Commit: 91dd29fd45d190728f29cc2f6cf9cd5549392f61
Author: Hans Goudey
Date:   Wed Sep 21 13:17:05 2022 -0500
Branches: master
https://developer.blender.org/rB91dd29fd45d190728f29cc2f6cf9cd5549392f61

Attributes: Allow calling "finish" on empty accessors

This removes some boilerplate when creating many optional attributes.

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

M	source/blender/blenkernel/BKE_attribute.hh
M	source/blender/bmesh/intern/bmesh_mesh_convert.cc
M	source/blender/geometry/intern/realize_instances.cc
M	source/blender/nodes/geometry/nodes/node_geo_distribute_points_on_faces.cc

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

diff --git a/source/blender/blenkernel/BKE_attribute.hh b/source/blender/blenkernel/BKE_attribute.hh
index 97a8a91d0e4..7b13b8a2b09 100644
--- a/source/blender/blenkernel/BKE_attribute.hh
+++ b/source/blender/blenkernel/BKE_attribute.hh
@@ -264,7 +264,9 @@ template<typename T> struct SpanAttributeWriter {
    */
   void finish()
   {
-    this->span.save();
+    if (this->span.varray()) {
+      this->span.save();
+    }
     if (this->tag_modified_fn) {
       this->tag_modified_fn();
     }
@@ -339,7 +341,9 @@ struct GSpanAttributeWriter {
 
   void finish()
   {
-    this->span.save();
+    if (this->span.varray()) {
+      this->span.save();
+    }
     if (this->tag_modified_fn) {
       this->tag_modified_fn();
     }
diff --git a/source/blender/bmesh/intern/bmesh_mesh_convert.cc b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
index 6f1552e6a0f..399d5e1517b 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_convert.cc
+++ b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
@@ -1368,21 +1368,12 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks *
   }
   bm->elem_index_dirty &= ~(BM_FACE | BM_LOOP);
 
-  if (material_index_attribute) {
-    material_index_attribute.finish();
-  }
-
   assert_bmesh_has_no_mesh_only_attributes(*bm);
 
-  if (hide_vert_attribute) {
-    hide_vert_attribute.finish();
-  }
-  if (hide_edge_attribute) {
-    hide_edge_attribute.finish();
-  }
-  if (hide_poly_attribute) {
-    hide_poly_attribute.finish();
-  }
+  material_index_attribute.finish();
+  hide_vert_attribute.finish();
+  hide_edge_attribute.finish();
+  hide_poly_attribute.finish();
 
   me->cd_flag = BM_mesh_cd_flag_from_bmesh(bm);
 }
diff --git a/source/blender/geometry/intern/realize_instances.cc b/source/blender/geometry/intern/realize_instances.cc
index 29a9f51c0a7..8133a685eb8 100644
--- a/source/blender/geometry/intern/realize_instances.cc
+++ b/source/blender/geometry/intern/realize_instances.cc
@@ -782,9 +782,7 @@ static void execute_realize_pointcloud_tasks(const RealizeInstancesOptions &opti
     dst_attribute.finish();
   }
   positions.finish();
-  if (point_ids) {
-    point_ids.finish();
-  }
+  point_ids.finish();
 }
 
 /** \} */
@@ -1107,12 +1105,8 @@ static void execute_realize_mesh_tasks(const RealizeInstancesOptions &options,
   for (GSpanAttributeWriter &dst_attribute : dst_attribute_writers) {
     dst_attribute.finish();
   }
-  if (vertex_ids) {
-    vertex_ids.finish();
-  }
-  if (material_indices) {
-    material_indices.finish();
-  }
+  vertex_ids.finish();
+  material_indices.finish();
 }
 
 /** \} */
@@ -1406,19 +1400,11 @@ static void execute_realize_curve_tasks(const RealizeInstancesOptions &options,
   for (GSpanAttributeWriter &dst_attribute : dst_attribute_writers) {
     dst_attribute.finish();
   }
-  if (point_ids) {
-    point_ids.finish();
-  }
-  if (radius) {
-    radius.finish();
-  }
-  if (resolution) {
-    resolution.finish();
-  }
-  if (all_curves_info.create_handle_postion_attributes) {
-    handle_left.finish();
-    handle_right.finish();
-  }
+  point_ids.finish();
+  radius.finish();
+  resolution.finish();
+  handle_left.finish();
+  handle_right.finish();
 }
 
 /** \} */
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 a007f6afcc7..cdcb16985ac 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
@@ -382,13 +382,8 @@ BLI_NOINLINE static void compute_attribute_outputs(const Mesh &mesh,
   }
 
   ids.finish();
-
-  if (normals) {
-    normals.finish();
-  }
-  if (rotations) {
-    rotations.finish();
-  }
+  normals.finish();
+  rotations.finish();
 }
 
 static Array<float> calc_full_density_factors_with_selection(const Mesh &mesh,



More information about the Bf-blender-cvs mailing list