From 5c80543c4366ee52bcc9d436c8fd7a740f7bbd9e Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Fri, 1 Apr 2022 08:40:45 -0500 Subject: Cleanup: Move geometry set fields to a separate header This commit moves declarations that depend on `FN_field.hh` out of `BKE_geometry_set.hh` into `BKE_geometry_fields.hh`. This helps to reduce the number of areas that need to depend on the functions module, which recently came in in review of D11591. In the future we may have a library of standard field inputs in order to make composing algorithms easier, so it makes sense to have a header that could contain them and some basic related utilities relating the concepts of geometry and fields. Reducing use of unnecessary headers may also reduce compilation time. Differential Revision: https://developer.blender.org/D14517 --- source/blender/blenkernel/BKE_geometry_fields.hh | 165 +++++++++++++++++++++ source/blender/blenkernel/BKE_geometry_set.hh | 154 ------------------- source/blender/blenkernel/CMakeLists.txt | 1 + .../blender/blenkernel/intern/attribute_access.cc | 1 + .../blenkernel/intern/geometry_component_curves.cc | 1 + .../blenkernel/intern/geometry_component_mesh.cc | 1 + source/blender/blenkernel/intern/geometry_set.cc | 1 + source/blender/editors/space_node/node_draw.cc | 1 + .../spreadsheet_data_source_geometry.cc | 1 + source/blender/modifiers/intern/MOD_nodes.cc | 1 + source/blender/nodes/NOD_geometry_exec.hh | 1 + .../blender/nodes/NOD_geometry_nodes_eval_log.hh | 2 + 12 files changed, 176 insertions(+), 154 deletions(-) create mode 100644 source/blender/blenkernel/BKE_geometry_fields.hh diff --git a/source/blender/blenkernel/BKE_geometry_fields.hh b/source/blender/blenkernel/BKE_geometry_fields.hh new file mode 100644 index 00000000000..36b382feb5f --- /dev/null +++ b/source/blender/blenkernel/BKE_geometry_fields.hh @@ -0,0 +1,165 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#pragma once + +/** \file + * \ingroup bke + * + * Common field utilities and field definitions for geometry components. + */ + +#include "BKE_geometry_set.hh" + +#include "FN_field.hh" + +namespace blender::bke { + +class GeometryComponentFieldContext : public fn::FieldContext { + private: + const GeometryComponent &component_; + const AttributeDomain domain_; + + public: + GeometryComponentFieldContext(const GeometryComponent &component, const AttributeDomain domain) + : component_(component), domain_(domain) + { + } + + const GeometryComponent &geometry_component() const + { + return component_; + } + + AttributeDomain domain() const + { + return domain_; + } +}; + +class GeometryFieldInput : public fn::FieldInput { + public: + using fn::FieldInput::FieldInput; + + GVArray get_varray_for_context(const fn::FieldContext &context, + IndexMask mask, + ResourceScope &scope) const override; + + virtual GVArray get_varray_for_context(const GeometryComponent &component, + AttributeDomain domain, + IndexMask mask) const = 0; +}; + +class AttributeFieldInput : public GeometryFieldInput { + private: + std::string name_; + + public: + AttributeFieldInput(std::string name, const CPPType &type) + : GeometryFieldInput(type, name), name_(std::move(name)) + { + category_ = Category::NamedAttribute; + } + + template static fn::Field Create(std::string name) + { + const CPPType &type = CPPType::get(); + auto field_input = std::make_shared(std::move(name), type); + return fn::Field{field_input}; + } + + StringRefNull attribute_name() const + { + return name_; + } + + GVArray get_varray_for_context(const GeometryComponent &component, + AttributeDomain domain, + IndexMask mask) const override; + + std::string socket_inspection_name() const override; + + uint64_t hash() const override; + bool is_equal_to(const fn::FieldNode &other) const override; +}; + +class IDAttributeFieldInput : public GeometryFieldInput { + public: + IDAttributeFieldInput() : GeometryFieldInput(CPPType::get()) + { + category_ = Category::Generated; + } + + GVArray get_varray_for_context(const GeometryComponent &component, + AttributeDomain domain, + IndexMask mask) const override; + + std::string socket_inspection_name() const override; + + uint64_t hash() const override; + bool is_equal_to(const fn::FieldNode &other) const override; +}; + +VArray curve_normals_varray(const CurveComponent &component, const AttributeDomain domain); + +VArray mesh_normals_varray(const MeshComponent &mesh_component, + const Mesh &mesh, + const IndexMask mask, + const AttributeDomain domain); + +class NormalFieldInput : public GeometryFieldInput { + public: + NormalFieldInput() : GeometryFieldInput(CPPType::get()) + { + category_ = Category::Generated; + } + + GVArray get_varray_for_context(const GeometryComponent &component, + const AttributeDomain domain, + IndexMask mask) const override; + + std::string socket_inspection_name() const override; + + uint64_t hash() const override; + bool is_equal_to(const fn::FieldNode &other) const override; +}; + +class AnonymousAttributeFieldInput : public GeometryFieldInput { + private: + /** + * A strong reference is required to make sure that the referenced attribute is not removed + * automatically. + */ + StrongAnonymousAttributeID anonymous_id_; + std::string producer_name_; + + public: + AnonymousAttributeFieldInput(StrongAnonymousAttributeID anonymous_id, + const CPPType &type, + std::string producer_name) + : GeometryFieldInput(type, anonymous_id.debug_name()), + anonymous_id_(std::move(anonymous_id)), + producer_name_(producer_name) + { + category_ = Category::AnonymousAttribute; + } + + template + static fn::Field Create(StrongAnonymousAttributeID anonymous_id, std::string producer_name) + { + const CPPType &type = CPPType::get(); + auto field_input = std::make_shared( + std::move(anonymous_id), type, std::move(producer_name)); + return fn::Field{field_input}; + } + + GVArray get_varray_for_context(const GeometryComponent &component, + AttributeDomain domain, + IndexMask mask) const override; + + std::string socket_inspection_name() const override; + + uint64_t hash() const override; + bool is_equal_to(const fn::FieldNode &other) const override; +}; + +} // namespace blender::bke diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh index bd392057436..559007d1aee 100644 --- a/source/blender/blenkernel/BKE_geometry_set.hh +++ b/source/blender/blenkernel/BKE_geometry_set.hh @@ -22,8 +22,6 @@ #include "BKE_attribute_access.hh" #include "BKE_geometry_set.h" -#include "FN_field.hh" - struct Curves; struct Collection; struct Curve; @@ -1019,155 +1017,3 @@ class VolumeComponent : public GeometryComponent { static constexpr inline GeometryComponentType static_type = GEO_COMPONENT_TYPE_VOLUME; }; - -namespace blender::bke { - -class GeometryComponentFieldContext : public fn::FieldContext { - private: - const GeometryComponent &component_; - const AttributeDomain domain_; - - public: - GeometryComponentFieldContext(const GeometryComponent &component, const AttributeDomain domain) - : component_(component), domain_(domain) - { - } - - const GeometryComponent &geometry_component() const - { - return component_; - } - - AttributeDomain domain() const - { - return domain_; - } -}; - -class GeometryFieldInput : public fn::FieldInput { - public: - using fn::FieldInput::FieldInput; - - GVArray get_varray_for_context(const fn::FieldContext &context, - IndexMask mask, - ResourceScope &scope) const override; - - virtual GVArray get_varray_for_context(const GeometryComponent &component, - AttributeDomain domain, - IndexMask mask) const = 0; -}; - -class AttributeFieldInput : public GeometryFieldInput { - private: - std::string name_; - - public: - AttributeFieldInput(std::string name, const CPPType &type) - : GeometryFieldInput(type, name), name_(std::move(name)) - { - category_ = Category::NamedAttribute; - } - - template static fn::Field Create(std::string name) - { - const CPPType &type = CPPType::get(); - auto field_input = std::make_shared(std::move(name), type); - return fn::Field{field_input}; - } - - StringRefNull attribute_name() const - { - return name_; - } - - GVArray get_varray_for_context(const GeometryComponent &component, - AttributeDomain domain, - IndexMask mask) const override; - - std::string socket_inspection_name() const override; - - uint64_t hash() const override; - bool is_equal_to(const fn::FieldNode &other) const override; -}; - -class IDAttributeFieldInput : public GeometryFieldInput { - public: - IDAttributeFieldInput() : GeometryFieldInput(CPPType::get()) - { - category_ = Category::Generated; - } - - GVArray get_varray_for_context(const GeometryComponent &component, - AttributeDomain domain, - IndexMask mask) const override; - - std::string socket_inspection_name() const override; - - uint64_t hash() const override; - bool is_equal_to(const fn::FieldNode &other) const override; -}; - -VArray curve_normals_varray(const CurveComponent &component, const AttributeDomain domain); - -VArray mesh_normals_varray(const MeshComponent &mesh_component, - const Mesh &mesh, - const IndexMask mask, - const AttributeDomain domain); - -class NormalFieldInput : public GeometryFieldInput { - public: - NormalFieldInput() : GeometryFieldInput(CPPType::get()) - { - category_ = Category::Generated; - } - - GVArray get_varray_for_context(const GeometryComponent &component, - const AttributeDomain domain, - IndexMask mask) const override; - - std::string socket_inspection_name() const override; - - uint64_t hash() const override; - bool is_equal_to(const fn::FieldNode &other) const override; -}; - -class AnonymousAttributeFieldInput : public GeometryFieldInput { - private: - /** - * A strong reference is required to make sure that the referenced attribute is not removed - * automatically. - */ - StrongAnonymousAttributeID anonymous_id_; - std::string producer_name_; - - public: - AnonymousAttributeFieldInput(StrongAnonymousAttributeID anonymous_id, - const CPPType &type, - std::string producer_name) - : GeometryFieldInput(type, anonymous_id.debug_name()), - anonymous_id_(std::move(anonymous_id)), - producer_name_(producer_name) - { - category_ = Category::AnonymousAttribute; - } - - template - static fn::Field Create(StrongAnonymousAttributeID anonymous_id, std::string producer_name) - { - const CPPType &type = CPPType::get(); - auto field_input = std::make_shared( - std::move(anonymous_id), type, std::move(producer_name)); - return fn::Field{field_input}; - } - - GVArray get_varray_for_context(const GeometryComponent &component, - AttributeDomain domain, - IndexMask mask) const override; - - std::string socket_inspection_name() const override; - - uint64_t hash() const override; - bool is_equal_to(const fn::FieldNode &other) const override; -}; - -} // namespace blender::bke diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 0c1601eeece..3be1c4b1278 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -370,6 +370,7 @@ set(SRC BKE_fcurve_driver.h BKE_fluid.h BKE_freestyle.h + BKE_geometry_fields.hh BKE_geometry_set.h BKE_geometry_set.hh BKE_geometry_set_instances.hh diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc index 8fbab8dde25..d0420b4170a 100644 --- a/source/blender/blenkernel/intern/attribute_access.cc +++ b/source/blender/blenkernel/intern/attribute_access.cc @@ -6,6 +6,7 @@ #include "BKE_attribute_math.hh" #include "BKE_customdata.h" #include "BKE_deform.h" +#include "BKE_geometry_fields.hh" #include "BKE_geometry_set.hh" #include "BKE_mesh.h" #include "BKE_pointcloud.h" diff --git a/source/blender/blenkernel/intern/geometry_component_curves.cc b/source/blender/blenkernel/intern/geometry_component_curves.cc index 27689d70c77..b5771cc063f 100644 --- a/source/blender/blenkernel/intern/geometry_component_curves.cc +++ b/source/blender/blenkernel/intern/geometry_component_curves.cc @@ -9,6 +9,7 @@ #include "BKE_attribute_math.hh" #include "BKE_curve.h" #include "BKE_curves.hh" +#include "BKE_geometry_fields.hh" #include "BKE_geometry_set.hh" #include "BKE_lib_id.h" #include "BKE_spline.hh" diff --git a/source/blender/blenkernel/intern/geometry_component_mesh.cc b/source/blender/blenkernel/intern/geometry_component_mesh.cc index 2bfe984462c..f5ed21af19a 100644 --- a/source/blender/blenkernel/intern/geometry_component_mesh.cc +++ b/source/blender/blenkernel/intern/geometry_component_mesh.cc @@ -10,6 +10,7 @@ #include "BKE_attribute_access.hh" #include "BKE_attribute_math.hh" #include "BKE_deform.h" +#include "BKE_geometry_fields.hh" #include "BKE_geometry_set.hh" #include "BKE_lib_id.h" #include "BKE_mesh.h" diff --git a/source/blender/blenkernel/intern/geometry_set.cc b/source/blender/blenkernel/intern/geometry_set.cc index 0eece6e9ad0..0b08acf92a3 100644 --- a/source/blender/blenkernel/intern/geometry_set.cc +++ b/source/blender/blenkernel/intern/geometry_set.cc @@ -8,6 +8,7 @@ #include "BKE_attribute.h" #include "BKE_attribute_access.hh" #include "BKE_curves.hh" +#include "BKE_geometry_fields.hh" #include "BKE_geometry_set.hh" #include "BKE_lib_id.h" #include "BKE_mesh.h" diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index d39304284ad..4ab81bac9aa 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -69,6 +69,7 @@ #include "NOD_geometry_nodes_eval_log.hh" #include "NOD_node_declaration.hh" +#include "FN_field.hh" #include "FN_field_cpp_type.hh" #include "node_intern.hh" /* own include */ diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc b/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc index 0ad64db1b6d..4afa70d9ef6 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc @@ -4,6 +4,7 @@ #include "BKE_context.h" #include "BKE_editmesh.h" +#include "BKE_geometry_fields.hh" #include "BKE_global.h" #include "BKE_lib_id.h" #include "BKE_mesh.h" diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc index 182405652a6..89d7868831d 100644 --- a/source/blender/modifiers/intern/MOD_nodes.cc +++ b/source/blender/modifiers/intern/MOD_nodes.cc @@ -36,6 +36,7 @@ #include "BKE_attribute_math.hh" #include "BKE_customdata.h" +#include "BKE_geometry_fields.hh" #include "BKE_geometry_set_instances.hh" #include "BKE_global.h" #include "BKE_idprop.h" diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh index dc0965f5d71..96a1904abdd 100644 --- a/source/blender/nodes/NOD_geometry_exec.hh +++ b/source/blender/nodes/NOD_geometry_exec.hh @@ -6,6 +6,7 @@ #include "FN_multi_function_builder.hh" #include "BKE_attribute_access.hh" +#include "BKE_geometry_fields.hh" #include "BKE_geometry_set.hh" #include "BKE_geometry_set_instances.hh" diff --git a/source/blender/nodes/NOD_geometry_nodes_eval_log.hh b/source/blender/nodes/NOD_geometry_nodes_eval_log.hh index 19103b82fcf..16332be5179 100644 --- a/source/blender/nodes/NOD_geometry_nodes_eval_log.hh +++ b/source/blender/nodes/NOD_geometry_nodes_eval_log.hh @@ -26,6 +26,8 @@ #include "NOD_derived_node_tree.hh" +#include "FN_field.hh" + #include struct SpaceNode; -- cgit v1.2.3