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.
This commit is contained in:
Hans Goudey 2021-09-27 13:22:44 -05:00
parent 5d70a4d7ee
commit f94164d896
Notes: blender-bot 2023-02-14 10:29:30 +01:00
Referenced by commit 44e4f077a9, Geometry Nodes: Run nodes once on unique instance data
1 changed files with 13 additions and 14 deletions

View File

@ -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);
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};
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) {
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);
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);
assign_material_to_faces(*mesh, selection, material);
}
}
}
});
params.set_output("Geometry", std::move(geometry_set));
}