From f94164d89629f0d2ce8c3ef76db72541687b5e9c Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Mon, 27 Sep 2021 13:22:44 -0500 Subject: 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. --- .../geometry/nodes/node_geo_material_assign.cc | 31 +++++++++++----------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'source/blender') 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("Geometry"); - geometry_set = geometry_set_realize_instances(geometry_set); - - if (geometry_set.has()) { - MeshComponent &mesh_component = geometry_set.get_component_for_write(); - 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 &mesh_component = geometry_set.get_component_for_write(); + 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)); } -- cgit v1.2.3