From 2d4c7fa896ab4a6de163cd33746b54e67c7f8bac Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Mon, 6 Dec 2021 19:05:29 +0100 Subject: 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 --- source/blender/nodes/NOD_geometry_exec.hh | 1 + .../nodes/node_geo_curve_endpoint_selection.cc | 80 ++++++++++------------ .../nodes/node_geo_curve_handle_type_selection.cc | 44 ++++++------ .../nodes/node_geo_curve_spline_parameter.cc | 79 ++++++++------------- .../nodes/node_geo_input_mesh_edge_vertices.cc | 42 +++++------- .../nodes/node_geo_input_mesh_face_area.cc | 21 +++--- .../nodes/node_geo_input_mesh_face_neighbors.cc | 43 +++++------- .../nodes/node_geo_input_mesh_vertex_neighbors.cc | 42 +++++------- .../nodes/geometry/nodes/node_geo_input_normal.cc | 45 +++++------- .../geometry/nodes/node_geo_input_spline_length.cc | 50 +++++--------- .../nodes/geometry/nodes/node_geo_input_tangent.cc | 26 +++---- .../geometry/nodes/node_geo_material_selection.cc | 51 +++++++------- 12 files changed, 212 insertions(+), 312 deletions(-) (limited to 'source/blender/nodes') diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh index f15f5abcb4e..7e8c3551f33 100644 --- a/source/blender/nodes/NOD_geometry_exec.hh +++ b/source/blender/nodes/NOD_geometry_exec.hh @@ -38,6 +38,7 @@ using bke::AttributeFieldInput; using bke::AttributeIDRef; using bke::geometry_set_realize_instances; using bke::GeometryComponentFieldContext; +using bke::GeometryFieldInput; using bke::OutputAttribute; using bke::OutputAttribute_Typed; using bke::ReadAttributeLookup; diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_endpoint_selection.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_endpoint_selection.cc index c756185e4ed..fc407414667 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_endpoint_selection.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_endpoint_selection.cc @@ -51,69 +51,61 @@ static void select_by_spline(const int start, const int end, MutableSpan r r_selection.slice(size - end_use, end_use).fill(true); } -class EndpointFieldInput final : public fn::FieldInput { +class EndpointFieldInput final : public GeometryFieldInput { Field start_size_; Field end_size_; public: EndpointFieldInput(Field start_size, Field end_size) - : FieldInput(CPPType::get(), "Endpoint Selection node"), + : GeometryFieldInput(CPPType::get(), "Endpoint Selection node"), start_size_(start_size), end_size_(end_size) { 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(&context)) { + if (component.type() != GEO_COMPONENT_TYPE_CURVE || domain != ATTR_DOMAIN_POINT) { + return nullptr; + } - const GeometryComponent &component = geometry_context->geometry_component(); - const AttributeDomain domain = geometry_context->domain(); - if (component.type() != GEO_COMPONENT_TYPE_CURVE || domain != ATTR_DOMAIN_POINT) { - return nullptr; - } + const CurveComponent &curve_component = static_cast(component); + const CurveEval *curve = curve_component.get_for_read(); - const CurveComponent &curve_component = static_cast(component); - const CurveEval *curve = curve_component.get_for_read(); + Array control_point_offsets = curve->control_point_offsets(); - Array control_point_offsets = curve->control_point_offsets(); + if (curve == nullptr || control_point_offsets.last() == 0) { + return nullptr; + } - if (curve == nullptr || control_point_offsets.last() == 0) { - return nullptr; + GeometryComponentFieldContext size_context{curve_component, ATTR_DOMAIN_CURVE}; + fn::FieldEvaluator evaluator{size_context, curve->splines().size()}; + evaluator.add(start_size_); + evaluator.add(end_size_); + evaluator.evaluate(); + const VArray &start_size = evaluator.get_evaluated(0); + const VArray &end_size = evaluator.get_evaluated(1); + + const int point_size = control_point_offsets.last(); + Array selection(point_size, false); + int current_point = 0; + MutableSpan selection_span = selection.as_mutable_span(); + for (int i : IndexRange(curve->splines().size())) { + const SplinePtr &spline = curve->splines()[i]; + if (start_size[i] <= 0 && end_size[i] <= 0) { + selection_span.slice(current_point, spline->size()).fill(false); } - - GeometryComponentFieldContext size_context{curve_component, ATTR_DOMAIN_CURVE}; - fn::FieldEvaluator evaluator{size_context, curve->splines().size()}; - evaluator.add(start_size_); - evaluator.add(end_size_); - evaluator.evaluate(); - const VArray &start_size = evaluator.get_evaluated(0); - const VArray &end_size = evaluator.get_evaluated(1); - - const int point_size = control_point_offsets.last(); - Array selection(point_size, false); - int current_point = 0; - MutableSpan selection_span = selection.as_mutable_span(); - for (int i : IndexRange(curve->splines().size())) { - const SplinePtr &spline = curve->splines()[i]; - if (start_size[i] <= 0 && end_size[i] <= 0) { - selection_span.slice(current_point, spline->size()).fill(false); - } - else { - int start_use = std::max(start_size[i], 0); - int end_use = std::max(end_size[i], 0); - select_by_spline( - start_use, end_use, selection_span.slice(current_point, spline->size())); - } - current_point += spline->size(); + else { + int start_use = std::max(start_size[i], 0); + int end_use = std::max(end_size[i], 0); + select_by_spline(start_use, end_use, selection_span.slice(current_point, spline->size())); } - return VArray::ForContainer(std::move(selection)); + current_point += spline->size(); } - return {}; + return VArray::ForContainer(std::move(selection)); }; uint64_t hash() const override diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_handle_type_selection.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_handle_type_selection.cc index 2a53f7a3f82..a4b080b11e7 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_handle_type_selection.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_handle_type_selection.cc @@ -83,44 +83,40 @@ static void select_by_handle_type(const CurveEval &curve, } } -class HandleTypeFieldInput final : public fn::FieldInput { +class HandleTypeFieldInput final : public GeometryFieldInput { BezierSpline::HandleType type_; GeometryNodeCurveHandleMode mode_; public: HandleTypeFieldInput(BezierSpline::HandleType type, GeometryNodeCurveHandleMode mode) - : FieldInput(CPPType::get(), "Handle Type Selection node"), type_(type), mode_(mode) + : GeometryFieldInput(CPPType::get(), "Handle Type Selection node"), + type_(type), + mode_(mode) { category_ = Category::Generated; } - GVArray get_varray_for_context(const fn::FieldContext &context, - IndexMask mask, - ResourceScope &UNUSED(scope)) const final + GVArray get_varray_for_context(const GeometryComponent &component, + const AttributeDomain domain, + IndexMask mask) const final { - if (const GeometryComponentFieldContext *geometry_context = - dynamic_cast(&context)) { - - const GeometryComponent &component = geometry_context->geometry_component(); - const AttributeDomain domain = geometry_context->domain(); - if (component.type() != GEO_COMPONENT_TYPE_CURVE) { - return {}; - } + if (component.type() != GEO_COMPONENT_TYPE_CURVE) { + return {}; + } - const CurveComponent &curve_component = static_cast(component); - const CurveEval *curve = curve_component.get_for_read(); - if (curve == nullptr) { - return {}; - } + const CurveComponent &curve_component = static_cast(component); + const CurveEval *curve = curve_component.get_for_read(); + if (curve == nullptr) { + return {}; + } - if (domain == ATTR_DOMAIN_POINT) { - Array selection(mask.min_array_size()); - select_by_handle_type(*curve, type_, mode_, selection); - return VArray::ForContainer(std::move(selection)); - } + if (domain == ATTR_DOMAIN_POINT) { + Array selection(mask.min_array_size()); + select_by_handle_type(*curve, type_, mode_, selection); + return VArray::ForContainer(std::move(selection)); } return {}; - }; + } uint64_t hash() const override { diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc index ed5805a158b..de352d217ed 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc @@ -202,29 +202,22 @@ static VArray construct_index_on_spline_varray(const CurveEval &curve, return {}; } -class CurveParameterFieldInput final : public fn::FieldInput { +class CurveParameterFieldInput final : public GeometryFieldInput { public: - CurveParameterFieldInput() : fn::FieldInput(CPPType::get(), "Curve Parameter node") + CurveParameterFieldInput() : GeometryFieldInput(CPPType::get(), "Curve Parameter node") { category_ = Category::Generated; } - GVArray get_varray_for_context(const fn::FieldContext &context, - IndexMask mask, - ResourceScope &UNUSED(scope)) const final + GVArray get_varray_for_context(const GeometryComponent &component, + const AttributeDomain domain, + IndexMask mask) const final { - if (const GeometryComponentFieldContext *geometry_context = - dynamic_cast(&context)) { - - const GeometryComponent &component = geometry_context->geometry_component(); - const AttributeDomain domain = geometry_context->domain(); - - if (component.type() == GEO_COMPONENT_TYPE_CURVE) { - const CurveComponent &curve_component = static_cast(component); - const CurveEval *curve = curve_component.get_for_read(); - if (curve) { - return construct_curve_parameter_varray(*curve, mask, domain); - } + if (component.type() == GEO_COMPONENT_TYPE_CURVE) { + const CurveComponent &curve_component = static_cast(component); + const CurveEval *curve = curve_component.get_for_read(); + if (curve) { + return construct_curve_parameter_varray(*curve, mask, domain); } } return {}; @@ -242,28 +235,22 @@ class CurveParameterFieldInput final : public fn::FieldInput { } }; -class CurveLengthFieldInput final : public fn::FieldInput { +class CurveLengthFieldInput final : public GeometryFieldInput { public: - CurveLengthFieldInput() : fn::FieldInput(CPPType::get(), "Curve Length node") + CurveLengthFieldInput() : GeometryFieldInput(CPPType::get(), "Curve Length node") { category_ = Category::Generated; } - GVArray get_varray_for_context(const fn::FieldContext &context, - IndexMask mask, - ResourceScope &UNUSED(scope)) const final + GVArray get_varray_for_context(const GeometryComponent &component, + const AttributeDomain domain, + IndexMask mask) const final { - if (const GeometryComponentFieldContext *geometry_context = - dynamic_cast(&context)) { - - const GeometryComponent &component = geometry_context->geometry_component(); - const AttributeDomain domain = geometry_context->domain(); - if (component.type() == GEO_COMPONENT_TYPE_CURVE) { - const CurveComponent &curve_component = static_cast(component); - const CurveEval *curve = curve_component.get_for_read(); - if (curve) { - return construct_curve_length_varray(*curve, mask, domain); - } + if (component.type() == GEO_COMPONENT_TYPE_CURVE) { + const CurveComponent &curve_component = static_cast(component); + const CurveEval *curve = curve_component.get_for_read(); + if (curve) { + return construct_curve_length_varray(*curve, mask, domain); } } return {}; @@ -281,28 +268,22 @@ class CurveLengthFieldInput final : public fn::FieldInput { } }; -class IndexOnSplineFieldInput final : public fn::FieldInput { +class IndexOnSplineFieldInput final : public GeometryFieldInput { public: - IndexOnSplineFieldInput() : fn::FieldInput(CPPType::get(), "Spline Index") + IndexOnSplineFieldInput() : GeometryFieldInput(CPPType::get(), "Spline Index") { category_ = Category::Generated; } - GVArray get_varray_for_context(const fn::FieldContext &context, - IndexMask mask, - ResourceScope &UNUSED(scope)) const final + GVArray get_varray_for_context(const GeometryComponent &component, + const AttributeDomain domain, + IndexMask mask) const final { - if (const GeometryComponentFieldContext *geometry_context = - dynamic_cast(&context)) { - - const GeometryComponent &component = geometry_context->geometry_component(); - const AttributeDomain domain = geometry_context->domain(); - if (component.type() == GEO_COMPONENT_TYPE_CURVE) { - const CurveComponent &curve_component = static_cast(component); - const CurveEval *curve = curve_component.get_for_read(); - if (curve) { - return construct_index_on_spline_varray(*curve, mask, domain); - } + if (component.type() == GEO_COMPONENT_TYPE_CURVE) { + const CurveComponent &curve_component = static_cast(component); + const CurveEval *curve = curve_component.get_for_read(); + if (curve) { + return construct_index_on_spline_varray(*curve, mask, domain); } } return {}; diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_vertices.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_vertices.cc index a9385b50600..5ca9ed969c7 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_vertices.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_vertices.cc @@ -61,29 +61,24 @@ static VArray construct_edge_vertices_gvarray(const MeshComponent &componen return {}; } -class EdgeVerticesFieldInput final : public fn::FieldInput { +class EdgeVerticesFieldInput final : public GeometryFieldInput { private: VertexNumber vertex_; public: EdgeVerticesFieldInput(VertexNumber vertex) - : fn::FieldInput(CPPType::get(), "Edge Vertices Field"), vertex_(vertex) + : GeometryFieldInput(CPPType::get(), "Edge Vertices Field"), vertex_(vertex) { 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(&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(component); - return construct_edge_vertices_gvarray(mesh_component, vertex_, domain); - } + if (component.type() == GEO_COMPONENT_TYPE_MESH) { + const MeshComponent &mesh_component = static_cast(component); + return construct_edge_vertices_gvarray(mesh_component, vertex_, domain); } return {}; } @@ -128,29 +123,24 @@ static VArray construct_edge_positions_gvarray(const MeshComponent &comp domain); } -class EdgePositionFieldInput final : public fn::FieldInput { +class EdgePositionFieldInput final : public GeometryFieldInput { private: VertexNumber vertex_; public: EdgePositionFieldInput(VertexNumber vertex) - : fn::FieldInput(CPPType::get(), "Edge Position Field"), vertex_(vertex) + : GeometryFieldInput(CPPType::get(), "Edge Position Field"), vertex_(vertex) { 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(&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(component); - return construct_edge_positions_gvarray(mesh_component, vertex_, domain); - } + if (component.type() == GEO_COMPONENT_TYPE_MESH) { + const MeshComponent &mesh_component = static_cast(component); + return construct_edge_positions_gvarray(mesh_component, vertex_, domain); } return {}; } 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 construct_face_area_gvarray(const MeshComponent &component, VArray::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(), "Face Area Field") + FaceAreaFieldInput() : GeometryFieldInput(CPPType::get(), "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(&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(component); - return construct_face_area_gvarray(mesh_component, domain); - } + if (component.type() == GEO_COMPONENT_TYPE_MESH) { + const MeshComponent &mesh_component = static_cast(component); + return construct_face_area_gvarray(mesh_component, domain); } return {}; } diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_neighbors.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_neighbors.cc index 8f3cf623fe9..80bb25dc7ca 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_neighbors.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_neighbors.cc @@ -58,25 +58,21 @@ static VArray construct_neighbor_count_gvarray(const MeshComponent &compone VArray::ForContainer(std::move(poly_count)), ATTR_DOMAIN_FACE, domain); } -class FaceNeighborCountFieldInput final : public fn::FieldInput { +class FaceNeighborCountFieldInput final : public GeometryFieldInput { public: - FaceNeighborCountFieldInput() : fn::FieldInput(CPPType::get(), "Face Neighbor Count Field") + FaceNeighborCountFieldInput() + : GeometryFieldInput(CPPType::get(), "Face Neighbor Count 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(&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(component); - return construct_neighbor_count_gvarray(mesh_component, domain); - } + if (component.type() == GEO_COMPONENT_TYPE_MESH) { + const MeshComponent &mesh_component = static_cast(component); + return construct_neighbor_count_gvarray(mesh_component, domain); } return {}; } @@ -108,25 +104,20 @@ static VArray construct_vertex_count_gvarray(const MeshComponent &component domain); } -class FaceVertexCountFieldInput final : public fn::FieldInput { +class FaceVertexCountFieldInput final : public GeometryFieldInput { public: - FaceVertexCountFieldInput() : fn::FieldInput(CPPType::get(), "Vertex Count Field") + FaceVertexCountFieldInput() : GeometryFieldInput(CPPType::get(), "Vertex Count 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(&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(component); - return construct_vertex_count_gvarray(mesh_component, domain); - } + if (component.type() == GEO_COMPONENT_TYPE_MESH) { + const MeshComponent &mesh_component = static_cast(component); + return construct_vertex_count_gvarray(mesh_component, domain); } return {}; } diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_vertex_neighbors.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_vertex_neighbors.cc index edc265acb00..05140c92205 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_vertex_neighbors.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_vertex_neighbors.cc @@ -52,25 +52,20 @@ static VArray construct_vertex_count_gvarray(const MeshComponent &component return {}; } -class VertexCountFieldInput final : public fn::FieldInput { +class VertexCountFieldInput final : public GeometryFieldInput { public: - VertexCountFieldInput() : fn::FieldInput(CPPType::get(), "Vertex Count Field") + VertexCountFieldInput() : GeometryFieldInput(CPPType::get(), "Vertex Count 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(&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(component); - return construct_vertex_count_gvarray(mesh_component, domain); - } + if (component.type() == GEO_COMPONENT_TYPE_MESH) { + const MeshComponent &mesh_component = static_cast(component); + return construct_vertex_count_gvarray(mesh_component, domain); } return {}; } @@ -106,25 +101,20 @@ static VArray construct_face_count_gvarray(const MeshComponent &component, return {}; } -class VertexFaceCountFieldInput final : public fn::FieldInput { +class VertexFaceCountFieldInput final : public GeometryFieldInput { public: - VertexFaceCountFieldInput() : fn::FieldInput(CPPType::get(), "Vertex Face Count Field") + VertexFaceCountFieldInput() : GeometryFieldInput(CPPType::get(), "Vertex Face Count 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(&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(component); - return construct_face_count_gvarray(mesh_component, domain); - } + if (component.type() == GEO_COMPONENT_TYPE_MESH) { + const MeshComponent &mesh_component = static_cast(component); + return construct_face_count_gvarray(mesh_component, domain); } return {}; } diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_normal.cc b/source/blender/nodes/geometry/nodes/node_geo_input_normal.cc index 6e63354a31a..1cc508d9d9d 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_input_normal.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_input_normal.cc @@ -93,8 +93,7 @@ static VArray mesh_vertex_normals(const Mesh &mesh, static VArray construct_mesh_normals_gvarray(const MeshComponent &mesh_component, const Mesh &mesh, const IndexMask mask, - const AttributeDomain domain, - ResourceScope &UNUSED(scope)) + const AttributeDomain domain) { Span verts{mesh.mvert, mesh.totvert}; Span edges{mesh.medge, mesh.totedge}; @@ -199,8 +198,7 @@ static Array curve_normal_point_domain(const CurveEval &curve) } static VArray construct_curve_normal_gvarray(const CurveComponent &component, - const AttributeDomain domain, - ResourceScope &UNUSED(scope)) + const AttributeDomain domain) { const CurveEval *curve = component.get_for_read(); if (curve == nullptr) { @@ -231,36 +229,29 @@ static VArray construct_curve_normal_gvarray(const CurveComponent &compo return nullptr; } -class NormalFieldInput final : public fn::FieldInput { +class NormalFieldInput final : public GeometryFieldInput { public: - NormalFieldInput() : fn::FieldInput(CPPType::get(), "Normal node") + NormalFieldInput() : GeometryFieldInput(CPPType::get(), "Normal node") { category_ = Category::Generated; } - GVArray get_varray_for_context(const fn::FieldContext &context, - IndexMask mask, - ResourceScope &scope) const final + GVArray get_varray_for_context(const GeometryComponent &component, + const AttributeDomain domain, + IndexMask mask) const final { - if (const GeometryComponentFieldContext *geometry_context = - dynamic_cast(&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(component); - const Mesh *mesh = mesh_component.get_for_read(); - if (mesh == nullptr) { - return {}; - } - - return construct_mesh_normals_gvarray(mesh_component, *mesh, mask, domain, scope); - } - if (component.type() == GEO_COMPONENT_TYPE_CURVE) { - const CurveComponent &curve_component = static_cast(component); - return construct_curve_normal_gvarray(curve_component, domain, scope); + if (component.type() == GEO_COMPONENT_TYPE_MESH) { + const MeshComponent &mesh_component = static_cast(component); + const Mesh *mesh = mesh_component.get_for_read(); + if (mesh == nullptr) { + return {}; } + + return construct_mesh_normals_gvarray(mesh_component, *mesh, mask, domain); + } + if (component.type() == GEO_COMPONENT_TYPE_CURVE) { + const CurveComponent &curve_component = static_cast(component); + return construct_curve_normal_gvarray(curve_component, domain); } return {}; } diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_spline_length.cc b/source/blender/nodes/geometry/nodes/node_geo_input_spline_length.cc index 226d50543f8..810d6e2fddd 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_input_spline_length.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_input_spline_length.cc @@ -31,8 +31,7 @@ static void node_declare(NodeDeclarationBuilder &b) */ static VArray construct_spline_length_gvarray(const CurveComponent &component, - const AttributeDomain domain, - ResourceScope &UNUSED(scope)) + const AttributeDomain domain) { const CurveEval *curve = component.get_for_read(); if (curve == nullptr) { @@ -54,26 +53,20 @@ static VArray construct_spline_length_gvarray(const CurveComponent &compo return {}; } -class SplineLengthFieldInput final : public fn::FieldInput { +class SplineLengthFieldInput final : public GeometryFieldInput { public: - SplineLengthFieldInput() : fn::FieldInput(CPPType::get(), "Spline Length node") + SplineLengthFieldInput() : GeometryFieldInput(CPPType::get(), "Spline Length node") { category_ = Category::Generated; } - GVArray get_varray_for_context(const fn::FieldContext &context, - IndexMask UNUSED(mask), - ResourceScope &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(&context)) { - - const GeometryComponent &component = geometry_context->geometry_component(); - const AttributeDomain domain = geometry_context->domain(); - if (component.type() == GEO_COMPONENT_TYPE_CURVE) { - const CurveComponent &curve_component = static_cast(component); - return construct_spline_length_gvarray(curve_component, domain, scope); - } + if (component.type() == GEO_COMPONENT_TYPE_CURVE) { + const CurveComponent &curve_component = static_cast(component); + return construct_spline_length_gvarray(curve_component, domain); } return {}; } @@ -95,8 +88,7 @@ class SplineLengthFieldInput final : public fn::FieldInput { */ static VArray construct_spline_count_gvarray(const CurveComponent &component, - const AttributeDomain domain, - ResourceScope &UNUSED(scope)) + const AttributeDomain domain) { const CurveEval *curve = component.get_for_read(); if (curve == nullptr) { @@ -118,26 +110,20 @@ static VArray construct_spline_count_gvarray(const CurveComponent &componen return {}; } -class SplineCountFieldInput final : public fn::FieldInput { +class SplineCountFieldInput final : public GeometryFieldInput { public: - SplineCountFieldInput() : fn::FieldInput(CPPType::get(), "Spline Point Count") + SplineCountFieldInput() : GeometryFieldInput(CPPType::get(), "Spline Point Count") { category_ = Category::Generated; } - GVArray get_varray_for_context(const fn::FieldContext &context, - IndexMask UNUSED(mask), - ResourceScope &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(&context)) { - - const GeometryComponent &component = geometry_context->geometry_component(); - const AttributeDomain domain = geometry_context->domain(); - if (component.type() == GEO_COMPONENT_TYPE_CURVE) { - const CurveComponent &curve_component = static_cast(component); - return construct_spline_count_gvarray(curve_component, domain, scope); - } + if (component.type() == GEO_COMPONENT_TYPE_CURVE) { + const CurveComponent &curve_component = static_cast(component); + return construct_spline_count_gvarray(curve_component, domain); } return {}; } diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_tangent.cc b/source/blender/nodes/geometry/nodes/node_geo_input_tangent.cc index 0502f64ecb7..86f882df3cd 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_input_tangent.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_input_tangent.cc @@ -85,8 +85,7 @@ static Array curve_tangent_point_domain(const CurveEval &curve) } static VArray construct_curve_tangent_gvarray(const CurveComponent &component, - const AttributeDomain domain, - ResourceScope &UNUSED(scope)) + const AttributeDomain domain) { const CurveEval *curve = component.get_for_read(); if (curve == nullptr) { @@ -118,27 +117,20 @@ static VArray construct_curve_tangent_gvarray(const CurveComponent &comp return nullptr; } -class TangentFieldInput final : public fn::FieldInput { +class TangentFieldInput final : public GeometryFieldInput { public: - TangentFieldInput() : fn::FieldInput(CPPType::get(), "Tangent node") + TangentFieldInput() : GeometryFieldInput(CPPType::get(), "Tangent node") { category_ = Category::Generated; } - GVArray get_varray_for_context(const fn::FieldContext &context, - IndexMask UNUSED(mask), - ResourceScope &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(&context)) { - - const GeometryComponent &component = geometry_context->geometry_component(); - const AttributeDomain domain = geometry_context->domain(); - - if (component.type() == GEO_COMPONENT_TYPE_CURVE) { - const CurveComponent &curve_component = static_cast(component); - return construct_curve_tangent_gvarray(curve_component, domain, scope); - } + if (component.type() == GEO_COMPONENT_TYPE_CURVE) { + const CurveComponent &curve_component = static_cast(component); + return construct_curve_tangent_gvarray(curve_component, domain); } return {}; } diff --git a/source/blender/nodes/geometry/nodes/node_geo_material_selection.cc b/source/blender/nodes/geometry/nodes/node_geo_material_selection.cc index 948565b62f0..2aad68e7c25 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_material_selection.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_material_selection.cc @@ -54,44 +54,39 @@ static void select_mesh_by_material(const Mesh &mesh, }); } -class MaterialSelectionFieldInput final : public fn::FieldInput { +class MaterialSelectionFieldInput final : public GeometryFieldInput { Material *material_; public: MaterialSelectionFieldInput(Material *material) - : fn::FieldInput(CPPType::get(), "Material Selection node"), material_(material) + : GeometryFieldInput(CPPType::get(), "Material Selection node"), material_(material) { category_ = Category::Generated; } - GVArray get_varray_for_context(const fn::FieldContext &context, - IndexMask mask, - ResourceScope &UNUSED(scope)) const final + GVArray get_varray_for_context(const GeometryComponent &component, + const AttributeDomain domain, + IndexMask mask) const final { - if (const GeometryComponentFieldContext *geometry_context = - dynamic_cast(&context)) { - const GeometryComponent &component = geometry_context->geometry_component(); - const AttributeDomain domain = geometry_context->domain(); - if (component.type() != GEO_COMPONENT_TYPE_MESH) { - return {}; - } - const MeshComponent &mesh_component = static_cast(component); - const Mesh *mesh = mesh_component.get_for_read(); - if (mesh == nullptr) { - return {}; - } - - if (domain == ATTR_DOMAIN_FACE) { - Array selection(mask.min_array_size()); - select_mesh_by_material(*mesh, material_, mask, selection); - return VArray::ForContainer(std::move(selection)); - } - - Array selection(mesh->totpoly); - select_mesh_by_material(*mesh, material_, IndexMask(mesh->totpoly), selection); - return mesh_component.attribute_try_adapt_domain( - VArray::ForContainer(std::move(selection)), ATTR_DOMAIN_FACE, domain); + if (component.type() != GEO_COMPONENT_TYPE_MESH) { + return {}; } + const MeshComponent &mesh_component = static_cast(component); + const Mesh *mesh = mesh_component.get_for_read(); + if (mesh == nullptr) { + return {}; + } + + if (domain == ATTR_DOMAIN_FACE) { + Array selection(mask.min_array_size()); + select_mesh_by_material(*mesh, material_, mask, selection); + return VArray::ForContainer(std::move(selection)); + } + + Array selection(mesh->totpoly); + select_mesh_by_material(*mesh, material_, IndexMask(mesh->totpoly), selection); + return mesh_component.attribute_try_adapt_domain( + VArray::ForContainer(std::move(selection)), ATTR_DOMAIN_FACE, domain); return nullptr; } -- cgit v1.2.3