[Bf-blender-cvs] [21997966941] ui-asset-view-template: Geometry Nodes: Don't create empty components when realizing instances

Hans Goudey noreply at git.blender.org
Sun Mar 21 16:11:59 CET 2021


Commit: 2199796694187cf25de1f48494b0cb4e930bfc92
Author: Hans Goudey
Date:   Thu Mar 18 16:32:49 2021 -0400
Branches: ui-asset-view-template
https://developer.blender.org/rB2199796694187cf25de1f48494b0cb4e930bfc92

Geometry Nodes: Don't create empty components when realizing instances

Previously even if the input goemetry set had no point cloud or no mesh
instances, `geometry_set_realize_instances` would create empty data.
This isn't necessarily bad, but it can complicate things down the line if
there are a bunch of empty components getting passed around.

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

M	source/blender/blenkernel/intern/geometry_set_instances.cc

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

diff --git a/source/blender/blenkernel/intern/geometry_set_instances.cc b/source/blender/blenkernel/intern/geometry_set_instances.cc
index ce54ec7911f..24a402ac545 100644
--- a/source/blender/blenkernel/intern/geometry_set_instances.cc
+++ b/source/blender/blenkernel/intern/geometry_set_instances.cc
@@ -230,6 +230,11 @@ static Mesh *join_mesh_topology_and_builtin_attributes(Span<GeometryInstanceGrou
     }
   }
 
+  /* Don't create an empty mesh. */
+  if ((totverts + totloops + totedges + totpolys) == 0) {
+    return nullptr;
+  }
+
   Mesh *new_mesh = BKE_mesh_new_nomain(totverts, totedges, 0, totloops, totpolys);
   /* Copy settings from the first input geometry set with a mesh. */
   for (const GeometryInstanceGroup &set_group : set_groups) {
@@ -366,6 +371,9 @@ static void join_instance_groups_mesh(Span<GeometryInstanceGroup> set_groups,
 {
   Mesh *new_mesh = join_mesh_topology_and_builtin_attributes(set_groups,
                                                              convert_points_to_vertices);
+  if (new_mesh == nullptr) {
+    return;
+  }
 
   MeshComponent &dst_component = result.get_component_for_write<MeshComponent>();
   dst_component.replace(new_mesh);
@@ -397,6 +405,9 @@ static void join_instance_groups_pointcloud(Span<GeometryInstanceGroup> set_grou
       totpoint += component.attribute_domain_size(ATTR_DOMAIN_POINT);
     }
   }
+  if (totpoint == 0) {
+    return;
+  }
 
   PointCloudComponent &dst_component = result.get_component_for_write<PointCloudComponent>();
   PointCloud *pointcloud = BKE_pointcloud_new_nomain(totpoint);



More information about the Bf-blender-cvs mailing list