From c8ee70c96200548699a2d038a93208c5723f91e7 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Sun, 25 Sep 2022 19:16:53 +0200 Subject: Geometry Nodes: decentralize implicit input definitions Previously, all implicit inputs where stored in a centralized place. Now the information which nodes have which implicit inputs is stored in the nodes directly. --- source/blender/nodes/NOD_node_declaration.hh | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'source/blender/nodes/NOD_node_declaration.hh') diff --git a/source/blender/nodes/NOD_node_declaration.hh b/source/blender/nodes/NOD_node_declaration.hh index 42755b2e8dd..13f8af4ddf5 100644 --- a/source/blender/nodes/NOD_node_declaration.hh +++ b/source/blender/nodes/NOD_node_declaration.hh @@ -65,6 +65,8 @@ struct FieldInferencingInterface { Vector outputs; }; +using ImplicitInputValueFn = std::function; + /** * Describes a single input or output socket. This is subclassed for different socket types. */ @@ -103,6 +105,10 @@ class SocketDeclaration { /** Utility method to make the socket available if there is a straightforward way to do so. */ std::function make_available_fn_; + /** Some input sockets can have non-trivial values in the case when they are unlinked. This + * callback computes the default input of a values in geometry nodes when nothing is linked. */ + std::unique_ptr implicit_input_fn_; + friend NodeDeclarationBuilder; template friend class SocketDeclarationBuilder; @@ -140,6 +146,11 @@ class SocketDeclaration { bool compositor_skip_realization() const; bool compositor_expects_single_value() const; + const ImplicitInputValueFn *implicit_input_fn() const + { + return implicit_input_fn_.get(); + } + protected: void set_common_flags(bNodeSocket &socket) const; bool matches_common_data(const bNodeSocket &socket) const; @@ -225,10 +236,11 @@ class SocketDeclarationBuilder : public BaseSocketDeclarationBuilder { } /** The input supports a field and is a field by default when nothing is connected. */ - Self &implicit_field() + Self &implicit_field(ImplicitInputValueFn fn) { this->hide_value(); decl_->input_field_type_ = InputSocketFieldType::Implicit; + decl_->implicit_input_fn_ = std::make_unique(std::move(fn)); return *(Self *)this; } @@ -348,6 +360,13 @@ class NodeDeclarationBuilder { eNodeSocketInOut in_out); }; +namespace implicit_field_inputs { +void position(const bNode &node, void *r_value); +void normal(const bNode &node, void *r_value); +void index(const bNode &node, void *r_value); +void id_or_index(const bNode &node, void *r_value); +} // namespace implicit_field_inputs + /* -------------------------------------------------------------------- */ /** \name #OutputFieldDependency Inline Methods * \{ */ -- cgit v1.2.3