diff options
author | Jacques Lucke <jacques@blender.org> | 2021-12-06 21:05:29 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-12-06 21:13:24 +0300 |
commit | 2d4c7fa896ab4a6de163cd33746b54e67c7f8bac (patch) | |
tree | 71a0839f33a68172b15594dc76b83fe05315c273 /source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_area.cc | |
parent | 2814740f5be86fc389ba82ffbb3a40c43f47a9f5 (diff) |
Geometry Nodes: reduce code duplication with new GeometyrFieldInput
Most of our field inputs are currently specific to geometry. This patch introduces
a new `GeometryFieldInput` that reduces the overhead of adding new geometry
field input.
Differential Revision: https://developer.blender.org/D13489
Diffstat (limited to 'source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_area.cc')
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_area.cc | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_area.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_area.cc index d3605cd87e5..538b9e9682d 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_area.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_area.cc @@ -47,25 +47,20 @@ static VArray<float> construct_face_area_gvarray(const MeshComponent &component, VArray<float>::ForFunc(mesh->totpoly, area_fn), ATTR_DOMAIN_FACE, domain); } -class FaceAreaFieldInput final : public fn::FieldInput { +class FaceAreaFieldInput final : public GeometryFieldInput { public: - FaceAreaFieldInput() : fn::FieldInput(CPPType::get<float>(), "Face Area Field") + FaceAreaFieldInput() : GeometryFieldInput(CPPType::get<float>(), "Face Area Field") { category_ = Category::Generated; } - GVArray get_varray_for_context(const fn::FieldContext &context, - IndexMask UNUSED(mask), - ResourceScope &UNUSED(scope)) const final + GVArray get_varray_for_context(const GeometryComponent &component, + const AttributeDomain domain, + IndexMask UNUSED(mask)) const final { - if (const GeometryComponentFieldContext *geometry_context = - dynamic_cast<const GeometryComponentFieldContext *>(&context)) { - const GeometryComponent &component = geometry_context->geometry_component(); - const AttributeDomain domain = geometry_context->domain(); - if (component.type() == GEO_COMPONENT_TYPE_MESH) { - const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component); - return construct_face_area_gvarray(mesh_component, domain); - } + if (component.type() == GEO_COMPONENT_TYPE_MESH) { + const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component); + return construct_face_area_gvarray(mesh_component, domain); } return {}; } |