[Bf-blender-cvs] [f94164d8962] master: Geometry Nodes: Do not realize instances in the material assign node

Hans Goudey noreply at git.blender.org
Mon Sep 27 20:22:56 CEST 2021


Commit: f94164d89629f0d2ce8c3ef76db72541687b5e9c
Author: Hans Goudey
Date:   Mon Sep 27 13:22:44 2021 -0500
Branches: master
https://developer.blender.org/rBf94164d89629f0d2ce8c3ef76db72541687b5e9c

Geometry Nodes: Do not realize instances in the material assign node

Only run the node once for every unique geometry set in the input's
instance heirarchy. This can massively improve performance when
there are many instances, but it will mean that the result is the same
for every instance. For the previous behavior, a "Realize Instances"
node can be used before this one.

This node can be changed without versioning since the old material
assign node was already deprecated and replaced.

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

M	source/blender/nodes/geometry/nodes/node_geo_material_assign.cc

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

diff --git a/source/blender/nodes/geometry/nodes/node_geo_material_assign.cc b/source/blender/nodes/geometry/nodes/node_geo_material_assign.cc
index 2a4481d5404..780994996ae 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_material_assign.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_material_assign.cc
@@ -64,23 +64,22 @@ static void geo_node_material_assign_exec(GeoNodeExecParams params)
 
   GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
 
-  geometry_set = geometry_set_realize_instances(geometry_set);
-
-  if (geometry_set.has<MeshComponent>()) {
-    MeshComponent &mesh_component = geometry_set.get_component_for_write<MeshComponent>();
-    Mesh *mesh = mesh_component.get_for_write();
-    if (mesh != nullptr) {
-
-      GeometryComponentFieldContext field_context{mesh_component, ATTR_DOMAIN_FACE};
-
-      fn::FieldEvaluator selection_evaluator{field_context, mesh->totpoly};
-      selection_evaluator.add(selection_field);
-      selection_evaluator.evaluate();
-      const IndexMask selection = selection_evaluator.get_evaluated_as_mask(0);
-
-      assign_material_to_faces(*mesh, selection, material);
+  geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
+    if (geometry_set.has<MeshComponent>()) {
+      MeshComponent &mesh_component = geometry_set.get_component_for_write<MeshComponent>();
+      Mesh *mesh = mesh_component.get_for_write();
+      if (mesh != nullptr) {
+        GeometryComponentFieldContext field_context{mesh_component, ATTR_DOMAIN_FACE};
+
+        fn::FieldEvaluator selection_evaluator{field_context, mesh->totpoly};
+        selection_evaluator.add(selection_field);
+        selection_evaluator.evaluate();
+        const IndexMask selection = selection_evaluator.get_evaluated_as_mask(0);
+
+        assign_material_to_faces(*mesh, selection, material);
+      }
     }
-  }
+  });
 
   params.set_output("Geometry", std::move(geometry_set));
 }



More information about the Bf-blender-cvs mailing list