Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_set_id.cc
| Show All 30 Lines | static void set_id_in_component(GeometryComponent &component, | ||||
| const Field<int> &id_field) | const Field<int> &id_field) | ||||
| { | { | ||||
| GeometryComponentFieldContext field_context{component, ATTR_DOMAIN_POINT}; | GeometryComponentFieldContext field_context{component, ATTR_DOMAIN_POINT}; | ||||
| const int domain_size = component.attribute_domain_size(ATTR_DOMAIN_POINT); | const int domain_size = component.attribute_domain_size(ATTR_DOMAIN_POINT); | ||||
| if (domain_size == 0) { | if (domain_size == 0) { | ||||
| return; | return; | ||||
| } | } | ||||
| fn::FieldEvaluator selection_evaluator{field_context, domain_size}; | fn::FieldEvaluator evaluator{field_context, domain_size}; | ||||
| selection_evaluator.add(selection_field); | evaluator.set_selection(selection_field); | ||||
| selection_evaluator.evaluate(); | |||||
| const IndexMask selection = selection_evaluator.get_evaluated_as_mask(0); | |||||
| /* Since adding the ID attribute can change the result of the field evaluation (the random value | /* Since adding the ID attribute can change the result of the field evaluation (the random value | ||||
| * node uses the index if the ID is unavailable), make sure that it isn't added before evaluating | * node uses the index if the ID is unavailable), make sure that it isn't added before evaluating | ||||
| * the field. However, as an optimization, use a faster code path when it already exists. */ | * the field. However, as an optimization, use a faster code path when it already exists. */ | ||||
| fn::FieldEvaluator id_evaluator{field_context, &selection}; | |||||
| if (component.attribute_exists("id")) { | if (component.attribute_exists("id")) { | ||||
| OutputAttribute_Typed<int> id_attribute = component.attribute_try_get_for_output_only<int>( | OutputAttribute_Typed<int> id_attribute = component.attribute_try_get_for_output_only<int>( | ||||
| "id", ATTR_DOMAIN_POINT); | "id", ATTR_DOMAIN_POINT); | ||||
| id_evaluator.add_with_destination(id_field, id_attribute.varray()); | evaluator.add_with_destination(id_field, id_attribute.varray()); | ||||
| id_evaluator.evaluate(); | evaluator.evaluate(); | ||||
| id_attribute.save(); | id_attribute.save(); | ||||
| } | } | ||||
| else { | else { | ||||
| id_evaluator.add(id_field); | evaluator.add(id_field); | ||||
| id_evaluator.evaluate(); | evaluator.evaluate(); | ||||
| const VArray<int> &result_ids = id_evaluator.get_evaluated<int>(0); | const IndexMask selection = evaluator.get_evaluated_selection_as_mask(); | ||||
| const VArray<int> &result_ids = evaluator.get_evaluated<int>(0); | |||||
| OutputAttribute_Typed<int> id_attribute = component.attribute_try_get_for_output_only<int>( | OutputAttribute_Typed<int> id_attribute = component.attribute_try_get_for_output_only<int>( | ||||
| "id", ATTR_DOMAIN_POINT); | "id", ATTR_DOMAIN_POINT); | ||||
| result_ids.materialize(selection, id_attribute.as_span()); | result_ids.materialize(selection, id_attribute.as_span()); | ||||
| id_attribute.save(); | id_attribute.save(); | ||||
| } | } | ||||
| } | } | ||||
| static void node_geo_exec(GeoNodeExecParams params) | static void node_geo_exec(GeoNodeExecParams params) | ||||
| Show All 30 Lines | |||||