diff options
-rw-r--r-- | release/scripts/startup/nodeitems_builtins.py | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_node.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/node.cc | 1 | ||||
-rw-r--r-- | source/blender/functions/FN_field.hh | 9 | ||||
-rw-r--r-- | source/blender/nodes/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/nodes/NOD_geometry.h | 1 | ||||
-rw-r--r-- | source/blender/nodes/NOD_static_types.h | 1 | ||||
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_index.cc | 60 |
8 files changed, 72 insertions, 3 deletions
diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py index 196968d9770..f03f86818e5 100644 --- a/release/scripts/startup/nodeitems_builtins.py +++ b/release/scripts/startup/nodeitems_builtins.py @@ -545,6 +545,7 @@ geometry_node_categories = [ NodeItem("GeometryNodeInputMaterial"), NodeItem("GeometryNodeIsViewport"), NodeItem("GeometryNodePosition"), + NodeItem("GeometryNodeIndex"), ]), GeometryNodeCategory("GEO_MATERIAL", "Material", items=[ NodeItem("GeometryNodeMaterialAssign"), diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index f4642cd42b2..8aa92ef6671 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -1485,6 +1485,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree, #define GEO_NODE_CURVE_FILL 1075 #define GEO_NODE_POSITION 1076 #define GEO_NODE_SET_POSITION 1077 +#define GEO_NODE_INDEX 1078 /** \} */ diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index cb2e39bd10a..72c5bb93772 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -5174,6 +5174,7 @@ static void registerGeometryNodes() register_node_type_geo_delete_geometry(); register_node_type_geo_edge_split(); register_node_type_geo_input_material(); + register_node_type_geo_index(); register_node_type_geo_is_viewport(); register_node_type_geo_join_geometry(); register_node_type_geo_material_assign(); diff --git a/source/blender/functions/FN_field.hh b/source/blender/functions/FN_field.hh index 744345fd339..d639b355ab9 100644 --- a/source/blender/functions/FN_field.hh +++ b/source/blender/functions/FN_field.hh @@ -266,6 +266,8 @@ class FieldEvaluator : NonMovable, NonCopyable { private: struct OutputPointerInfo { void *dst = nullptr; + /* When a destination virtual array is provided for an input, this is + * unnecessary, otherwise this is used to construct the required virtual array. */ void (*set)(void *dst, const GVArray &varray, ResourceScope &scope) = nullptr; }; @@ -297,7 +299,7 @@ class FieldEvaluator : NonMovable, NonCopyable { return field_index; } - /** Same as above but typed. */ + /** Same as #add_with_destination but typed. */ template<typename T> int add_with_destination(Field<T> field, VMutableArray<T> &dst) { GVMutableArray &generic_dst_hint = scope_.construct<GVMutableArray_For_VMutableArray<T>>( @@ -309,6 +311,7 @@ class FieldEvaluator : NonMovable, NonCopyable { * \param field: Field to add to the evaluator. * \param varray_ptr: Once #evaluate is called, the resulting virtual array will be will be * assigned to the given position. + * \return Index of the field in the evaluator which can be used in the #get_evaluated methods. */ template<typename T> int add(Field<T> field, const VArray<T> **varray_ptr) { @@ -322,7 +325,7 @@ class FieldEvaluator : NonMovable, NonCopyable { } /** - * \return Index of the field in the evaluator. Can be used in the #get_evaluated methods. + * \return Index of the field in the evaluator which can be used in the #get_evaluated methods. */ int add(GField field) { @@ -337,7 +340,7 @@ class FieldEvaluator : NonMovable, NonCopyable { */ void evaluate() { - BLI_assert_msg(!is_evaluated_, "Cannot evaluate twice."); + BLI_assert_msg(!is_evaluated_, "Cannot evaluate fields twice."); Array<const GField *> fields(fields_to_evaluate_.size()); for (const int i : fields_to_evaluate_.index_range()) { fields[i] = &fields_to_evaluate_[i]; diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt index 0c0cf644f7d..0bf796b48b4 100644 --- a/source/blender/nodes/CMakeLists.txt +++ b/source/blender/nodes/CMakeLists.txt @@ -186,6 +186,7 @@ set(SRC geometry/nodes/node_geo_delete_geometry.cc geometry/nodes/node_geo_edge_split.cc geometry/nodes/node_geo_input_material.cc + geometry/nodes/node_geo_index.cc geometry/nodes/node_geo_is_viewport.cc geometry/nodes/node_geo_join_geometry.cc geometry/nodes/node_geo_material_assign.cc diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h index d59555b2667..375ba635e48 100644 --- a/source/blender/nodes/NOD_geometry.h +++ b/source/blender/nodes/NOD_geometry.h @@ -72,6 +72,7 @@ void register_node_type_geo_curve_trim(void); void register_node_type_geo_delete_geometry(void); void register_node_type_geo_edge_split(void); void register_node_type_geo_input_material(void); +void register_node_type_geo_index(void); void register_node_type_geo_is_viewport(void); void register_node_type_geo_join_geometry(void); void register_node_type_geo_material_assign(void); diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h index 23d3748a333..335842ecae2 100644 --- a/source/blender/nodes/NOD_static_types.h +++ b/source/blender/nodes/NOD_static_types.h @@ -313,6 +313,7 @@ DefNode(GeometryNode, GEO_NODE_CURVE_TRIM, def_geo_curve_trim, "CURVE_TRIM", Cur DefNode(GeometryNode, GEO_NODE_DELETE_GEOMETRY, 0, "DELETE_GEOMETRY", DeleteGeometry, "Delete Geometry", "") DefNode(GeometryNode, GEO_NODE_EDGE_SPLIT, 0, "EDGE_SPLIT", EdgeSplit, "Edge Split", "") DefNode(GeometryNode, GEO_NODE_INPUT_MATERIAL, def_geo_input_material, "INPUT_MATERIAL", InputMaterial, "Material", "") +DefNode(GeometryNode, GEO_NODE_INDEX, 0, "INDEX", Index, "Index", "") DefNode(GeometryNode, GEO_NODE_IS_VIEWPORT, 0, "IS_VIEWPORT", IsViewport, "Is Viewport", "") DefNode(GeometryNode, GEO_NODE_JOIN_GEOMETRY, 0, "JOIN_GEOMETRY", JoinGeometry, "Join Geometry", "") DefNode(GeometryNode, GEO_NODE_MATERIAL_ASSIGN, 0, "MATERIAL_ASSIGN", MaterialAssign, "Material Assign", "") diff --git a/source/blender/nodes/geometry/nodes/node_geo_index.cc b/source/blender/nodes/geometry/nodes/node_geo_index.cc new file mode 100644 index 00000000000..037c3c92191 --- /dev/null +++ b/source/blender/nodes/geometry/nodes/node_geo_index.cc @@ -0,0 +1,60 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "node_geometry_util.hh" + +namespace blender::nodes { + +static void geo_node_index_declare(NodeDeclarationBuilder &b) +{ + b.add_output<decl::Int>("Index"); +} + +class IndexContextFieldSource final : public fn::ContextFieldSource { + public: + IndexContextFieldSource() : ContextFieldSource(CPPType::get<int>(), "Index") + { + } + + const GVArray *try_get_varray_for_context(const fn::FieldContext &UNUSED(context), + IndexMask mask, + ResourceScope &scope) const final + { + /* TODO: Investigate a similar method to IndexRange::as_span() */ + auto index_func = [](int i) { return i; }; + return &scope.construct< + fn::GVArray_For_EmbeddedVArray<int, VArray_For_Func<int, decltype(index_func)>>>( + __func__, mask.min_array_size(), mask.min_array_size(), index_func); + } +}; + +static void geo_node_index_exec(GeoNodeExecParams params) +{ + Field<int> index_field{std::make_shared<IndexContextFieldSource>()}; + params.set_output("Index", std::move(index_field)); +} + +} // namespace blender::nodes + +void register_node_type_geo_index() +{ + static bNodeType ntype; + + geo_node_type_base(&ntype, GEO_NODE_INDEX, "Index", NODE_CLASS_INPUT, 0); + ntype.geometry_node_execute = blender::nodes::geo_node_index_exec; + ntype.declare = blender::nodes::geo_node_index_declare; + nodeRegisterType(&ntype); +} |