diff options
author | Jacques Lucke <jacques@blender.org> | 2021-12-14 17:40:16 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-12-14 17:40:27 +0300 |
commit | 8e2c9f2dd3118bfdb69ccf0ab2b9f968a854aae4 (patch) | |
tree | 7ec789b5e980a9ed572671c3c130db2d125b49de /source/blender/functions/FN_field.hh | |
parent | b44a500988f3d6aea631d17ca383c8ced55e4371 (diff) |
Geometry Nodes: simplify using selection when evaluating fields
We often had to use two `FieldEvaluator` instances to first evaluate
the selection and then the remaining fields. Now both can be done
with a single `FieldEvaluator`. This results in less boilerplate code in
many cases.
Performance is not affected by this change. In a separate patch we
could improve performance by reusing evaluated sub-fields that are
used by the selection and the other fields.
Differential Revision: https://developer.blender.org/D13571
Diffstat (limited to 'source/blender/functions/FN_field.hh')
-rw-r--r-- | source/blender/functions/FN_field.hh | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/source/blender/functions/FN_field.hh b/source/blender/functions/FN_field.hh index cf96eff62bd..a591aaed34a 100644 --- a/source/blender/functions/FN_field.hh +++ b/source/blender/functions/FN_field.hh @@ -313,6 +313,9 @@ class FieldEvaluator : NonMovable, NonCopyable { Vector<OutputPointerInfo> output_pointer_infos_; bool is_evaluated_ = false; + Field<bool> selection_field_; + IndexMask selection_mask_; + public: /** Takes #mask by pointer because the mask has to live longer than the evaluator. */ FieldEvaluator(const FieldContext &context, const IndexMask *mask) @@ -333,6 +336,18 @@ class FieldEvaluator : NonMovable, NonCopyable { } /** + * The selection field is evaluated first to determine which indices of the other fields should + * be evaluated. Calling this method multiple times will just replace the previously set + * selection field. Only the elements selected by both this selection and the selection provided + * in the constructor are calculated. If no selection field is set, it is assumed that all + * indices passed to the constructor are selected. + */ + void set_selection(Field<bool> selection) + { + selection_field_ = std::move(selection); + } + + /** * \param field: Field to add to the evaluator. * \param dst: Mutable virtual array that the evaluated result for this field is be written into. */ @@ -403,6 +418,8 @@ class FieldEvaluator : NonMovable, NonCopyable { return this->get_evaluated(field_index).typed<T>(); } + IndexMask get_evaluated_selection_as_mask(); + /** * Retrieve the output of an evaluated boolean field and convert it to a mask, which can be used * to avoid calculations for unnecessary elements later on. The evaluator will own the indices in |