diff options
author | Jacques Lucke <mail@jlucke.com> | 2019-12-31 16:17:44 +0300 |
---|---|---|
committer | Jacques Lucke <mail@jlucke.com> | 2019-12-31 16:17:44 +0300 |
commit | 36221652a4d9ef3ab7fe0f87939b1a3d9660325c (patch) | |
tree | a36c951e79d89fb3847a5ee0ea3cd2caa4012cd4 | |
parent | 7ed83e0bee3899a74d14eafeb30cd4c0e7f08a83 (diff) |
rename various types and variables
20 files changed, 1237 insertions, 1234 deletions
diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt index 4bd7e4f3c68..19034a59133 100644 --- a/source/blender/functions/CMakeLists.txt +++ b/source/blender/functions/CMakeLists.txt @@ -30,11 +30,11 @@ set(SRC intern/multi_functions/sampling_util.cc intern/multi_functions/surface_hook.cc intern/multi_functions/vectorize.cc - intern/inlined_tree_multi_function_network/builder.cc - intern/inlined_tree_multi_function_network/generate.cc - intern/inlined_tree_multi_function_network/mappings_nodes.cc - intern/inlined_tree_multi_function_network/mappings_sockets.cc - intern/inlined_tree_multi_function_network/mappings.cc + intern/node_tree_multi_function_network/builder.cc + intern/node_tree_multi_function_network/generate.cc + intern/node_tree_multi_function_network/mappings_nodes.cc + intern/node_tree_multi_function_network/mappings_sockets.cc + intern/node_tree_multi_function_network/mappings.cc intern/attributes_block_container.cc intern/attributes_ref.cc intern/cpp_type.cc @@ -64,8 +64,8 @@ set(SRC FN_multi_function_param_type.h FN_multi_function.h FN_multi_functions.h - FN_inlined_tree_multi_function_network_generation.h - FN_inlined_tree_multi_function_network.h + FN_node_tree_multi_function_network_generation.h + FN_node_tree_multi_function_network.h FN_node_tree.h intern/multi_functions/customizable.h @@ -77,8 +77,8 @@ set(SRC intern/multi_functions/surface_hook.h intern/multi_functions/util.h intern/multi_functions/vectorize.h - intern/inlined_tree_multi_function_network/builder.h - intern/inlined_tree_multi_function_network/mappings.h + intern/node_tree_multi_function_network/builder.h + intern/node_tree_multi_function_network/mappings.h intern/cpp_types.h ) diff --git a/source/blender/functions/FN_inlined_tree_multi_function_network.h b/source/blender/functions/FN_inlined_tree_multi_function_network.h deleted file mode 100644 index c2fa36ac2b4..00000000000 --- a/source/blender/functions/FN_inlined_tree_multi_function_network.h +++ /dev/null @@ -1,187 +0,0 @@ -#ifndef __FN_VTREE_MULTI_FUNCTION_NETWORK_H__ -#define __FN_VTREE_MULTI_FUNCTION_NETWORK_H__ - -#include "FN_node_tree.h" - -#include "BLI_multi_map.h" - -#include "FN_multi_function_network.h" - -namespace FN { - -using BLI::MultiMap; - -#define InlinedTreeMFSocketMap_UNMAPPED UINT_MAX -#define InlinedTreeMFSocketMap_MULTIMAPPED (UINT_MAX - 1) - -class InlinedTreeMFSocketMap { - private: - /* An input xsocket can be mapped to multiple sockets. - * An output xsocket can be mapped to at most one socket. - */ - const InlinedNodeTree *m_inlined_tree; - const MFNetwork *m_network; - Array<uint> m_single_socket_by_xsocket; - MultiMap<uint, uint> m_multiple_inputs_by_xsocket; - Array<uint> m_xsocket_by_socket; - - public: - InlinedTreeMFSocketMap(const InlinedNodeTree &inlined_tree, - const MFNetwork &network, - Array<uint> single_socket_by_xsocket, - MultiMap<uint, uint> multiple_inputs_by_xsocket, - Array<uint> xsocket_by_socket) - : m_inlined_tree(&inlined_tree), - m_network(&network), - m_single_socket_by_xsocket(std::move(single_socket_by_xsocket)), - m_multiple_inputs_by_xsocket(std::move(multiple_inputs_by_xsocket)), - m_xsocket_by_socket(std::move(xsocket_by_socket)) - { - } - - bool is_mapped(const XSocket &xsocket) const - { - return m_single_socket_by_xsocket[xsocket.id()] < InlinedTreeMFSocketMap_MULTIMAPPED; - } - - bool is_mapped(const MFSocket &socket) const - { - return m_xsocket_by_socket[socket.id()] != InlinedTreeMFSocketMap_UNMAPPED; - } - - const MFInputSocket &lookup_singly_mapped_input_socket(const XInputSocket &xsocket) const - { - BLI_assert(this->lookup_socket(xsocket).size() == 1); - uint mapped_id = m_single_socket_by_xsocket[xsocket.id()]; - return m_network->socket_by_id(mapped_id).as_input(); - } - - Vector<const MFInputSocket *> lookup_socket(const XInputSocket &xsocket) const - { - uint id = xsocket.id(); - uint mapped_value = m_single_socket_by_xsocket[id]; - switch (mapped_value) { - case InlinedTreeMFSocketMap_UNMAPPED: { - return {}; - } - case InlinedTreeMFSocketMap_MULTIMAPPED: { - Vector<const MFInputSocket *> sockets; - for (uint mapped_id : m_multiple_inputs_by_xsocket.lookup(id)) { - sockets.append(&m_network->socket_by_id(mapped_id).as_input()); - } - return sockets; - } - default: { - uint mapped_id = mapped_value; - const MFInputSocket &socket = m_network->socket_by_id(mapped_id).as_input(); - return {&socket}; - } - } - } - - const MFOutputSocket &lookup_socket(const XOutputSocket &xsocket) const - { - uint mapped_id = m_single_socket_by_xsocket[xsocket.id()]; - return m_network->socket_by_id(mapped_id).as_output(); - } - - const XInputSocket &lookup_xsocket(const MFInputSocket &socket) const - { - uint mapped_id = m_xsocket_by_socket[socket.id()]; - return m_inlined_tree->socket_by_id(mapped_id).as_input(); - } - - const XOutputSocket &lookup_xsocket(const MFOutputSocket &socket) const - { - uint mapped_id = m_xsocket_by_socket[socket.id()]; - return m_inlined_tree->socket_by_id(mapped_id).as_output(); - } -}; - -class InlinedTreeMFNetwork { - private: - const InlinedNodeTree &m_inlined_tree; - std::unique_ptr<MFNetwork> m_network; - InlinedTreeMFSocketMap m_socket_map; - - public: - InlinedTreeMFNetwork(const InlinedNodeTree &inlined_tree, - std::unique_ptr<MFNetwork> network, - InlinedTreeMFSocketMap socket_map) - : m_inlined_tree(inlined_tree), - m_network(std::move(network)), - m_socket_map(std::move(socket_map)) - { - } - - const InlinedNodeTree &inlined_tree() const - { - return m_inlined_tree; - } - - const MFNetwork &network() const - { - return *m_network; - } - - bool is_mapped(const XSocket &xsocket) const - { - return m_socket_map.is_mapped(xsocket); - } - - bool is_mapped(const MFSocket &socket) const - { - return m_socket_map.is_mapped(socket); - } - - const MFInputSocket &lookup_dummy_socket(const XInputSocket &xsocket) const - { - const MFInputSocket &socket = m_socket_map.lookup_singly_mapped_input_socket(xsocket); - BLI_assert(socket.node().is_dummy()); - return socket; - } - - const MFOutputSocket &lookup_dummy_socket(const XOutputSocket &xsocket) const - { - const MFOutputSocket &socket = this->lookup_socket(xsocket); - BLI_assert(socket.node().is_dummy()); - return socket; - } - - const MFOutputSocket &lookup_socket(const XOutputSocket &xsocket) const - { - return m_socket_map.lookup_socket(xsocket); - } - - const XInputSocket &lookup_xsocket(const MFInputSocket &socket) const - { - return m_socket_map.lookup_xsocket(socket); - } - - const XOutputSocket &lookup_xsocket(const MFOutputSocket &socket) const - { - return m_socket_map.lookup_xsocket(socket); - } - - void lookup_dummy_sockets(ArrayRef<const XOutputSocket *> xsockets, - MutableArrayRef<const MFOutputSocket *> r_result) const - { - BLI_assert(xsockets.size() == r_result.size()); - for (uint i : xsockets.index_iterator()) { - r_result[i] = &this->lookup_socket(*xsockets[i]); - } - } - - void lookup_dummy_sockets(ArrayRef<const XInputSocket *> xsockets, - MutableArrayRef<const MFInputSocket *> r_result) const - { - BLI_assert(xsockets.size() == r_result.size()); - for (uint i : xsockets.index_iterator()) { - r_result[i] = &this->lookup_dummy_socket(*xsockets[i]); - } - } -}; - -} // namespace FN - -#endif /* __FN_VTREE_MULTI_FUNCTION_NETWORK_H__ */ diff --git a/source/blender/functions/FN_inlined_tree_multi_function_network_generation.h b/source/blender/functions/FN_inlined_tree_multi_function_network_generation.h deleted file mode 100644 index 1c9f612719b..00000000000 --- a/source/blender/functions/FN_inlined_tree_multi_function_network_generation.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef __FN_VTREE_MULTI_FUNCTION_NETWORK_GENERATION_H__ -#define __FN_VTREE_MULTI_FUNCTION_NETWORK_GENERATION_H__ - -#include "FN_inlined_tree_multi_function_network.h" -#include "BLI_resource_collector.h" -#include "intern/multi_functions/network.h" - -namespace FN { - -using BLI::ResourceCollector; - -std::unique_ptr<InlinedTreeMFNetwork> generate_inlined_tree_multi_function_network( - const InlinedNodeTree &inlined_tree, ResourceCollector &resources); - -std::unique_ptr<MF_EvaluateNetwork> generate_inlined_tree_multi_function( - const InlinedNodeTree &inlined_tree, ResourceCollector &resources); - -} // namespace FN - -#endif /* __FN_VTREE_MULTI_FUNCTION_NETWORK_GENERATION_H__ */ diff --git a/source/blender/functions/FN_multi_function_dependencies.h b/source/blender/functions/FN_multi_function_dependencies.h index f34dc24074b..faa8be55776 100644 --- a/source/blender/functions/FN_multi_function_dependencies.h +++ b/source/blender/functions/FN_multi_function_dependencies.h @@ -12,18 +12,18 @@ namespace FN { using BLI::Set; -inline Set<Object *> get_objects_used_by_sockets(const InlinedNodeTree &inlined_tree) +inline Set<Object *> get_objects_used_by_sockets(const FunctionNodeTree &function_tree) { Set<Object *> objects; - for (const XSocket *xsocket : inlined_tree.all_sockets()) { - if (xsocket->idname() == "fn_ObjectSocket") { - Object *object = (Object *)RNA_pointer_get(xsocket->rna(), "value").data; + for (const FSocket *fsocket : function_tree.all_sockets()) { + if (fsocket->idname() == "fn_ObjectSocket") { + Object *object = (Object *)RNA_pointer_get(fsocket->rna(), "value").data; if (object != nullptr) { objects.add(object); } } } - for (const XGroupInput *group_input : inlined_tree.all_group_inputs()) { + for (const FGroupInput *group_input : function_tree.all_group_inputs()) { if (group_input->vsocket().idname() == "fn_ObjectSocket") { Object *object = (Object *)RNA_pointer_get(group_input->vsocket().rna(), "value").data; if (object != nullptr) { @@ -34,18 +34,18 @@ inline Set<Object *> get_objects_used_by_sockets(const InlinedNodeTree &inlined_ return objects; } -inline Set<Image *> get_images_used_by_sockets(const InlinedNodeTree &inlined_tree) +inline Set<Image *> get_images_used_by_sockets(const FunctionNodeTree &function_tree) { Set<Image *> images; - for (const XSocket *xsocket : inlined_tree.all_sockets()) { - if (xsocket->idname() == "fn_ImageSocket") { - Image *image = (Image *)RNA_pointer_get(xsocket->rna(), "value").data; + for (const FSocket *fsocket : function_tree.all_sockets()) { + if (fsocket->idname() == "fn_ImageSocket") { + Image *image = (Image *)RNA_pointer_get(fsocket->rna(), "value").data; if (image != nullptr) { images.add(image); } } } - for (const XGroupInput *group_input : inlined_tree.all_group_inputs()) { + for (const FGroupInput *group_input : function_tree.all_group_inputs()) { if (group_input->vsocket().idname() == "fn_ImageSocket") { Image *image = (Image *)RNA_pointer_get(group_input->vsocket().rna(), "value").data; if (image != nullptr) { @@ -57,12 +57,12 @@ inline Set<Image *> get_images_used_by_sockets(const InlinedNodeTree &inlined_tr } inline void add_ids_used_by_nodes(IDHandleLookup &id_handle_lookup, - const InlinedNodeTree &inlined_tree) + const FunctionNodeTree &function_tree) { - for (Object *object : get_objects_used_by_sockets(inlined_tree)) { + for (Object *object : get_objects_used_by_sockets(function_tree)) { id_handle_lookup.add(object->id); } - for (Image *image : get_images_used_by_sockets(inlined_tree)) { + for (Image *image : get_images_used_by_sockets(function_tree)) { id_handle_lookup.add(image->id); } } diff --git a/source/blender/functions/FN_node_tree.h b/source/blender/functions/FN_node_tree.h index d6018824ce6..e5bdef2b476 100644 --- a/source/blender/functions/FN_node_tree.h +++ b/source/blender/functions/FN_node_tree.h @@ -22,34 +22,34 @@ using BLI::StringRef; using BLI::StringRefNull; using BLI::Vector; -class XNode; -class XParentNode; -class XSocket; -class XInputSocket; -class XOutputSocket; -class XGroupInput; -class InlinedNodeTree; - -class XSocket : BLI::NonCopyable, BLI::NonMovable { +class FNode; +class FParentNode; +class FSocket; +class FInputSocket; +class FOutputSocket; +class FGroupInput; +class FunctionNodeTree; + +class FSocket : BLI::NonCopyable, BLI::NonMovable { protected: - XNode *m_node; + FNode *m_node; const VSocket *m_vsocket; bool m_is_input; /* Input and output sockets share the same id-space. */ uint m_id; - friend InlinedNodeTree; + friend FunctionNodeTree; public: - const XNode &node() const; + const FNode &node() const; uint id() const; bool is_input() const; bool is_output() const; - const XSocket &as_base() const; - const XInputSocket &as_input() const; - const XOutputSocket &as_output() const; + const FSocket &as_base() const; + const FInputSocket &as_input() const; + const FOutputSocket &as_output() const; PointerRNA *rna() const; StringRefNull idname() const; @@ -58,74 +58,74 @@ class XSocket : BLI::NonCopyable, BLI::NonMovable { uint index() const; }; -class XInputSocket : public XSocket { +class FInputSocket : public FSocket { private: - Vector<XOutputSocket *> m_linked_sockets; - Vector<XGroupInput *> m_linked_group_inputs; + Vector<FOutputSocket *> m_linked_sockets; + Vector<FGroupInput *> m_linked_group_inputs; - friend InlinedNodeTree; + friend FunctionNodeTree; public: const VInputSocket &vsocket() const; - ArrayRef<const XOutputSocket *> linked_sockets() const; - ArrayRef<const XGroupInput *> linked_group_inputs() const; + ArrayRef<const FOutputSocket *> linked_sockets() const; + ArrayRef<const FGroupInput *> linked_group_inputs() const; bool is_linked() const; }; -class XOutputSocket : public XSocket { +class FOutputSocket : public FSocket { private: - Vector<XInputSocket *> m_linked_sockets; + Vector<FInputSocket *> m_linked_sockets; - friend InlinedNodeTree; + friend FunctionNodeTree; public: const VOutputSocket &vsocket() const; - ArrayRef<const XInputSocket *> linked_sockets() const; + ArrayRef<const FInputSocket *> linked_sockets() const; }; -class XGroupInput : BLI::NonCopyable, BLI::NonMovable { +class FGroupInput : BLI::NonCopyable, BLI::NonMovable { private: const VInputSocket *m_vsocket; - XParentNode *m_parent; - Vector<XInputSocket *> m_linked_sockets; + FParentNode *m_parent; + Vector<FInputSocket *> m_linked_sockets; uint m_id; - friend InlinedNodeTree; + friend FunctionNodeTree; public: const VInputSocket &vsocket() const; - const XParentNode *parent() const; - ArrayRef<const XInputSocket *> linked_sockets() const; + const FParentNode *parent() const; + ArrayRef<const FInputSocket *> linked_sockets() const; uint id() const; }; -class XNode : BLI::NonCopyable, BLI::NonMovable { +class FNode : BLI::NonCopyable, BLI::NonMovable { private: const VNode *m_vnode; - XParentNode *m_parent; + FParentNode *m_parent; - Vector<XInputSocket *> m_inputs; - Vector<XOutputSocket *> m_outputs; + Vector<FInputSocket *> m_inputs; + Vector<FOutputSocket *> m_outputs; /* Uniquely identifies this node in the inlined node tree. */ uint m_id; - friend InlinedNodeTree; + friend FunctionNodeTree; void destruct_with_sockets(); public: const VNode &vnode() const; - const XParentNode *parent() const; + const FParentNode *parent() const; - ArrayRef<const XInputSocket *> inputs() const; - ArrayRef<const XOutputSocket *> outputs() const; + ArrayRef<const FInputSocket *> inputs() const; + ArrayRef<const FOutputSocket *> outputs() const; - const XInputSocket &input(uint index) const; - const XOutputSocket &output(uint index) const; - const XInputSocket &input(uint index, StringRef expected_name) const; - const XOutputSocket &output(uint index, StringRef expected_name) const; + const FInputSocket &input(uint index) const; + const FOutputSocket &output(uint index) const; + const FInputSocket &input(uint index, StringRef expected_name) const; + const FOutputSocket &output(uint index, StringRef expected_name) const; uint id() const; @@ -133,317 +133,317 @@ class XNode : BLI::NonCopyable, BLI::NonMovable { StringRefNull idname() const; StringRefNull name() const; - const XInputSocket *input_with_name_prefix(StringRef name_prefix) const; + const FInputSocket *input_with_name_prefix(StringRef name_prefix) const; }; -class XParentNode : BLI::NonCopyable, BLI::NonMovable { +class FParentNode : BLI::NonCopyable, BLI::NonMovable { private: const VNode *m_vnode; - XParentNode *m_parent; + FParentNode *m_parent; uint m_id; - friend InlinedNodeTree; + friend FunctionNodeTree; public: - const XParentNode *parent() const; + const FParentNode *parent() const; const VNode &vnode() const; uint id() const; }; using BTreeVTreeMap = Map<bNodeTree *, std::unique_ptr<const VirtualNodeTree>>; -class InlinedNodeTree : BLI::NonCopyable, BLI::NonMovable { +class FunctionNodeTree : BLI::NonCopyable, BLI::NonMovable { private: BLI::MonotonicAllocator<> m_allocator; bNodeTree *m_btree; - Vector<XNode *> m_node_by_id; - Vector<XGroupInput *> m_group_inputs; - Vector<XParentNode *> m_parent_nodes; + Vector<FNode *> m_node_by_id; + Vector<FGroupInput *> m_group_inputs; + Vector<FParentNode *> m_parent_nodes; - Vector<XSocket *> m_sockets_by_id; - Vector<XInputSocket *> m_input_sockets; - Vector<XOutputSocket *> m_output_sockets; + Vector<FSocket *> m_sockets_by_id; + Vector<FInputSocket *> m_input_sockets; + Vector<FOutputSocket *> m_output_sockets; - StringMap<Vector<XNode *>> m_nodes_by_idname; + StringMap<Vector<FNode *>> m_nodes_by_idname; public: - InlinedNodeTree(bNodeTree *btree, BTreeVTreeMap &vtrees); - ~InlinedNodeTree(); + FunctionNodeTree(bNodeTree *btree, BTreeVTreeMap &vtrees); + ~FunctionNodeTree(); std::string to_dot() const; void to_dot__clipboard() const; - const XSocket &socket_by_id(uint id) const; + const FSocket &socket_by_id(uint id) const; uint socket_count() const; uint node_count() const; - ArrayRef<const XSocket *> all_sockets() const; - ArrayRef<const XNode *> all_nodes() const; - ArrayRef<const XInputSocket *> all_input_sockets() const; - ArrayRef<const XOutputSocket *> all_output_sockets() const; - ArrayRef<const XGroupInput *> all_group_inputs() const; - ArrayRef<const XNode *> nodes_with_idname(StringRef idname) const; + ArrayRef<const FSocket *> all_sockets() const; + ArrayRef<const FNode *> all_nodes() const; + ArrayRef<const FInputSocket *> all_input_sockets() const; + ArrayRef<const FOutputSocket *> all_output_sockets() const; + ArrayRef<const FGroupInput *> all_group_inputs() const; + ArrayRef<const FNode *> nodes_with_idname(StringRef idname) const; private: - void expand_groups(Vector<XNode *> &all_nodes, - Vector<XGroupInput *> &all_group_inputs, - Vector<XParentNode *> &all_parent_nodes, + void expand_groups(Vector<FNode *> &all_nodes, + Vector<FGroupInput *> &all_group_inputs, + Vector<FParentNode *> &all_parent_nodes, BTreeVTreeMap &vtrees); - void expand_group_node(XNode &group_node, - Vector<XNode *> &all_nodes, - Vector<XGroupInput *> &all_group_inputs, - Vector<XParentNode *> &all_parent_nodes, + void expand_group_node(FNode &group_node, + Vector<FNode *> &all_nodes, + Vector<FGroupInput *> &all_group_inputs, + Vector<FParentNode *> &all_parent_nodes, BTreeVTreeMap &vtrees); - void expand_group__group_inputs_for_unlinked_inputs(XNode &group_node, - Vector<XGroupInput *> &all_group_inputs); + void expand_group__group_inputs_for_unlinked_inputs(FNode &group_node, + Vector<FGroupInput *> &all_group_inputs); void expand_group__relink_inputs(const VirtualNodeTree &vtree, - ArrayRef<XNode *> new_xnodes_by_id, - XNode &group_node); + ArrayRef<FNode *> new_fnodes_by_id, + FNode &group_node); void expand_group__relink_outputs(const VirtualNodeTree &vtree, - ArrayRef<XNode *> new_xnodes_by_id, - XNode &group_node); + ArrayRef<FNode *> new_fnodes_by_id, + FNode &group_node); void insert_linked_nodes_for_vtree_in_id_order(const VirtualNodeTree &vtree, - Vector<XNode *> &all_nodes, - XParentNode *parent); - XNode &create_node(const VNode &vnode, - XParentNode *parent, - MutableArrayRef<XSocket *> sockets_map); - void remove_expanded_groups_and_interfaces(Vector<XNode *> &all_nodes); - void store_tree_in_this_and_init_ids(Vector<XNode *> &&all_nodes, - Vector<XGroupInput *> &&all_group_inputs, - Vector<XParentNode *> &&all_parent_nodes); + Vector<FNode *> &all_nodes, + FParentNode *parent); + FNode &create_node(const VNode &vnode, + FParentNode *parent, + MutableArrayRef<FSocket *> sockets_map); + void remove_expanded_groups_and_interfaces(Vector<FNode *> &all_nodes); + void store_tree_in_this_and_init_ids(Vector<FNode *> &&all_nodes, + Vector<FGroupInput *> &&all_group_inputs, + Vector<FParentNode *> &&all_parent_nodes); }; /* Inline functions ********************************************/ -inline const VNode &XNode::vnode() const +inline const VNode &FNode::vnode() const { return *m_vnode; } -inline const XParentNode *XNode::parent() const +inline const FParentNode *FNode::parent() const { return m_parent; } -inline ArrayRef<const XInputSocket *> XNode::inputs() const +inline ArrayRef<const FInputSocket *> FNode::inputs() const { return m_inputs.as_ref(); } -inline ArrayRef<const XOutputSocket *> XNode::outputs() const +inline ArrayRef<const FOutputSocket *> FNode::outputs() const { return m_outputs.as_ref(); } -inline const XInputSocket &XNode::input(uint index) const +inline const FInputSocket &FNode::input(uint index) const { return *m_inputs[index]; } -inline const XOutputSocket &XNode::output(uint index) const +inline const FOutputSocket &FNode::output(uint index) const { return *m_outputs[index]; } -inline const XInputSocket &XNode::input(uint index, StringRef expected_name) const +inline const FInputSocket &FNode::input(uint index, StringRef expected_name) const { BLI_assert(m_inputs[index]->name() == expected_name); UNUSED_VARS_NDEBUG(expected_name); return *m_inputs[index]; } -inline const XOutputSocket &XNode::output(uint index, StringRef expected_name) const +inline const FOutputSocket &FNode::output(uint index, StringRef expected_name) const { BLI_assert(m_outputs[index]->name() == expected_name); UNUSED_VARS_NDEBUG(expected_name); return *m_outputs[index]; } -inline uint XNode::id() const +inline uint FNode::id() const { return m_id; } -inline PointerRNA *XNode::rna() const +inline PointerRNA *FNode::rna() const { return m_vnode->rna(); } -inline StringRefNull XNode::idname() const +inline StringRefNull FNode::idname() const { return m_vnode->idname(); } -inline StringRefNull XNode::name() const +inline StringRefNull FNode::name() const { return m_vnode->name(); } -inline const XParentNode *XParentNode::parent() const +inline const FParentNode *FParentNode::parent() const { return m_parent; } -inline const VNode &XParentNode::vnode() const +inline const VNode &FParentNode::vnode() const { return *m_vnode; } -inline uint XParentNode::id() const +inline uint FParentNode::id() const { return m_id; } -inline const XNode &XSocket::node() const +inline const FNode &FSocket::node() const { return *m_node; } -inline uint XSocket::id() const +inline uint FSocket::id() const { return m_id; } -inline bool XSocket::is_input() const +inline bool FSocket::is_input() const { return m_is_input; } -inline bool XSocket::is_output() const +inline bool FSocket::is_output() const { return !m_is_input; } -inline const XSocket &XSocket::as_base() const +inline const FSocket &FSocket::as_base() const { return *this; } -inline const XInputSocket &XSocket::as_input() const +inline const FInputSocket &FSocket::as_input() const { BLI_assert(this->is_input()); - return *(const XInputSocket *)this; + return *(const FInputSocket *)this; } -inline const XOutputSocket &XSocket::as_output() const +inline const FOutputSocket &FSocket::as_output() const { BLI_assert(this->is_output()); - return *(const XOutputSocket *)this; + return *(const FOutputSocket *)this; } -inline PointerRNA *XSocket::rna() const +inline PointerRNA *FSocket::rna() const { return m_vsocket->rna(); } -inline StringRefNull XSocket::idname() const +inline StringRefNull FSocket::idname() const { return m_vsocket->idname(); } -inline StringRefNull XSocket::name() const +inline StringRefNull FSocket::name() const { return m_vsocket->name(); } -inline uint XSocket::index() const +inline uint FSocket::index() const { return m_vsocket->index(); } -inline const VInputSocket &XInputSocket::vsocket() const +inline const VInputSocket &FInputSocket::vsocket() const { return m_vsocket->as_input(); } -inline ArrayRef<const XOutputSocket *> XInputSocket::linked_sockets() const +inline ArrayRef<const FOutputSocket *> FInputSocket::linked_sockets() const { return m_linked_sockets.as_ref(); } -inline ArrayRef<const XGroupInput *> XInputSocket::linked_group_inputs() const +inline ArrayRef<const FGroupInput *> FInputSocket::linked_group_inputs() const { return m_linked_group_inputs.as_ref(); } -inline bool XInputSocket::is_linked() const +inline bool FInputSocket::is_linked() const { return m_linked_sockets.size() > 0 || m_linked_group_inputs.size() > 0; } -inline const VOutputSocket &XOutputSocket::vsocket() const +inline const VOutputSocket &FOutputSocket::vsocket() const { return m_vsocket->as_output(); } -inline ArrayRef<const XInputSocket *> XOutputSocket::linked_sockets() const +inline ArrayRef<const FInputSocket *> FOutputSocket::linked_sockets() const { return m_linked_sockets.as_ref(); } -inline const VInputSocket &XGroupInput::vsocket() const +inline const VInputSocket &FGroupInput::vsocket() const { return *m_vsocket; } -inline const XParentNode *XGroupInput::parent() const +inline const FParentNode *FGroupInput::parent() const { return m_parent; } -inline ArrayRef<const XInputSocket *> XGroupInput::linked_sockets() const +inline ArrayRef<const FInputSocket *> FGroupInput::linked_sockets() const { return m_linked_sockets.as_ref(); } -inline uint XGroupInput::id() const +inline uint FGroupInput::id() const { return m_id; } -inline const XSocket &InlinedNodeTree::socket_by_id(uint id) const +inline const FSocket &FunctionNodeTree::socket_by_id(uint id) const { return *m_sockets_by_id[id]; } -inline uint InlinedNodeTree::socket_count() const +inline uint FunctionNodeTree::socket_count() const { return m_sockets_by_id.size(); } -inline uint InlinedNodeTree::node_count() const +inline uint FunctionNodeTree::node_count() const { return m_node_by_id.size(); } -inline ArrayRef<const XSocket *> InlinedNodeTree::all_sockets() const +inline ArrayRef<const FSocket *> FunctionNodeTree::all_sockets() const { return m_sockets_by_id.as_ref(); } -inline ArrayRef<const XNode *> InlinedNodeTree::all_nodes() const +inline ArrayRef<const FNode *> FunctionNodeTree::all_nodes() const { return m_node_by_id.as_ref(); } -inline ArrayRef<const XInputSocket *> InlinedNodeTree::all_input_sockets() const +inline ArrayRef<const FInputSocket *> FunctionNodeTree::all_input_sockets() const { return m_input_sockets.as_ref(); } -inline ArrayRef<const XOutputSocket *> InlinedNodeTree::all_output_sockets() const +inline ArrayRef<const FOutputSocket *> FunctionNodeTree::all_output_sockets() const { return m_output_sockets.as_ref(); } -inline ArrayRef<const XGroupInput *> InlinedNodeTree::all_group_inputs() const +inline ArrayRef<const FGroupInput *> FunctionNodeTree::all_group_inputs() const { return m_group_inputs.as_ref(); } -inline ArrayRef<const XNode *> InlinedNodeTree::nodes_with_idname(StringRef idname) const +inline ArrayRef<const FNode *> FunctionNodeTree::nodes_with_idname(StringRef idname) const { auto *nodes = m_nodes_by_idname.lookup_ptr(idname); if (nodes == nullptr) { diff --git a/source/blender/functions/FN_node_tree_multi_function_network.h b/source/blender/functions/FN_node_tree_multi_function_network.h new file mode 100644 index 00000000000..4316068349e --- /dev/null +++ b/source/blender/functions/FN_node_tree_multi_function_network.h @@ -0,0 +1,187 @@ +#ifndef __FN_VTREE_MULTI_FUNCTION_NETWORK_H__ +#define __FN_VTREE_MULTI_FUNCTION_NETWORK_H__ + +#include "FN_node_tree.h" + +#include "BLI_multi_map.h" + +#include "FN_multi_function_network.h" + +namespace FN { + +using BLI::MultiMap; + +#define InlinedTreeMFSocketMap_UNMAPPED UINT_MAX +#define InlinedTreeMFSocketMap_MULTIMAPPED (UINT_MAX - 1) + +class InlinedTreeMFSocketMap { + private: + /* An input fsocket can be mapped to multiple sockets. + * An output fsocket can be mapped to at most one socket. + */ + const FunctionNodeTree *m_function_tree; + const MFNetwork *m_network; + Array<uint> m_single_socket_by_fsocket; + MultiMap<uint, uint> m_multiple_inputs_by_fsocket; + Array<uint> m_fsocket_by_socket; + + public: + InlinedTreeMFSocketMap(const FunctionNodeTree &function_tree, + const MFNetwork &network, + Array<uint> single_socket_by_fsocket, + MultiMap<uint, uint> multiple_inputs_by_fsocket, + Array<uint> fsocket_by_socket) + : m_function_tree(&function_tree), + m_network(&network), + m_single_socket_by_fsocket(std::move(single_socket_by_fsocket)), + m_multiple_inputs_by_fsocket(std::move(multiple_inputs_by_fsocket)), + m_fsocket_by_socket(std::move(fsocket_by_socket)) + { + } + + bool is_mapped(const FSocket &fsocket) const + { + return m_single_socket_by_fsocket[fsocket.id()] < InlinedTreeMFSocketMap_MULTIMAPPED; + } + + bool is_mapped(const MFSocket &socket) const + { + return m_fsocket_by_socket[socket.id()] != InlinedTreeMFSocketMap_UNMAPPED; + } + + const MFInputSocket &lookup_singly_mapped_input_socket(const FInputSocket &fsocket) const + { + BLI_assert(this->lookup_socket(fsocket).size() == 1); + uint mapped_id = m_single_socket_by_fsocket[fsocket.id()]; + return m_network->socket_by_id(mapped_id).as_input(); + } + + Vector<const MFInputSocket *> lookup_socket(const FInputSocket &fsocket) const + { + uint id = fsocket.id(); + uint mapped_value = m_single_socket_by_fsocket[id]; + switch (mapped_value) { + case InlinedTreeMFSocketMap_UNMAPPED: { + return {}; + } + case InlinedTreeMFSocketMap_MULTIMAPPED: { + Vector<const MFInputSocket *> sockets; + for (uint mapped_id : m_multiple_inputs_by_fsocket.lookup(id)) { + sockets.append(&m_network->socket_by_id(mapped_id).as_input()); + } + return sockets; + } + default: { + uint mapped_id = mapped_value; + const MFInputSocket &socket = m_network->socket_by_id(mapped_id).as_input(); + return {&socket}; + } + } + } + + const MFOutputSocket &lookup_socket(const FOutputSocket &fsocket) const + { + uint mapped_id = m_single_socket_by_fsocket[fsocket.id()]; + return m_network->socket_by_id(mapped_id).as_output(); + } + + const FInputSocket &lookup_fsocket(const MFInputSocket &socket) const + { + uint mapped_id = m_fsocket_by_socket[socket.id()]; + return m_function_tree->socket_by_id(mapped_id).as_input(); + } + + const FOutputSocket &lookup_fsocket(const MFOutputSocket &socket) const + { + uint mapped_id = m_fsocket_by_socket[socket.id()]; + return m_function_tree->socket_by_id(mapped_id).as_output(); + } +}; + +class FunctionTreeMFNetwork { + private: + const FunctionNodeTree &m_function_tree; + std::unique_ptr<MFNetwork> m_network; + InlinedTreeMFSocketMap m_socket_map; + + public: + FunctionTreeMFNetwork(const FunctionNodeTree &function_tree, + std::unique_ptr<MFNetwork> network, + InlinedTreeMFSocketMap socket_map) + : m_function_tree(function_tree), + m_network(std::move(network)), + m_socket_map(std::move(socket_map)) + { + } + + const FunctionNodeTree &function_tree() const + { + return m_function_tree; + } + + const MFNetwork &network() const + { + return *m_network; + } + + bool is_mapped(const FSocket &fsocket) const + { + return m_socket_map.is_mapped(fsocket); + } + + bool is_mapped(const MFSocket &socket) const + { + return m_socket_map.is_mapped(socket); + } + + const MFInputSocket &lookup_dummy_socket(const FInputSocket &fsocket) const + { + const MFInputSocket &socket = m_socket_map.lookup_singly_mapped_input_socket(fsocket); + BLI_assert(socket.node().is_dummy()); + return socket; + } + + const MFOutputSocket &lookup_dummy_socket(const FOutputSocket &fsocket) const + { + const MFOutputSocket &socket = this->lookup_socket(fsocket); + BLI_assert(socket.node().is_dummy()); + return socket; + } + + const MFOutputSocket &lookup_socket(const FOutputSocket &fsocket) const + { + return m_socket_map.lookup_socket(fsocket); + } + + const FInputSocket &lookup_fsocket(const MFInputSocket &socket) const + { + return m_socket_map.lookup_fsocket(socket); + } + + const FOutputSocket &lookup_fsocket(const MFOutputSocket &socket) const + { + return m_socket_map.lookup_fsocket(socket); + } + + void lookup_dummy_sockets(ArrayRef<const FOutputSocket *> fsockets, + MutableArrayRef<const MFOutputSocket *> r_result) const + { + BLI_assert(fsockets.size() == r_result.size()); + for (uint i : fsockets.index_iterator()) { + r_result[i] = &this->lookup_socket(*fsockets[i]); + } + } + + void lookup_dummy_sockets(ArrayRef<const FInputSocket *> fsockets, + MutableArrayRef<const MFInputSocket *> r_result) const + { + BLI_assert(fsockets.size() == r_result.size()); + for (uint i : fsockets.index_iterator()) { + r_result[i] = &this->lookup_dummy_socket(*fsockets[i]); + } + } +}; + +} // namespace FN + +#endif /* __FN_VTREE_MULTI_FUNCTION_NETWORK_H__ */ diff --git a/source/blender/functions/FN_node_tree_multi_function_network_generation.h b/source/blender/functions/FN_node_tree_multi_function_network_generation.h new file mode 100644 index 00000000000..993595a303a --- /dev/null +++ b/source/blender/functions/FN_node_tree_multi_function_network_generation.h @@ -0,0 +1,20 @@ +#ifndef __FN_VTREE_MULTI_FUNCTION_NETWORK_GENERATION_H__ +#define __FN_VTREE_MULTI_FUNCTION_NETWORK_GENERATION_H__ + +#include "FN_node_tree_multi_function_network.h" +#include "BLI_resource_collector.h" +#include "intern/multi_functions/network.h" + +namespace FN { + +using BLI::ResourceCollector; + +std::unique_ptr<FunctionTreeMFNetwork> generate_node_tree_multi_function_network( + const FunctionNodeTree &function_tree, ResourceCollector &resources); + +std::unique_ptr<MF_EvaluateNetwork> generate_node_tree_multi_function( + const FunctionNodeTree &function_tree, ResourceCollector &resources); + +} // namespace FN + +#endif /* __FN_VTREE_MULTI_FUNCTION_NETWORK_GENERATION_H__ */ diff --git a/source/blender/functions/intern/inlined_tree_multi_function_network/builder.cc b/source/blender/functions/intern/inlined_tree_multi_function_network/builder.cc deleted file mode 100644 index 2341a757e88..00000000000 --- a/source/blender/functions/intern/inlined_tree_multi_function_network/builder.cc +++ /dev/null @@ -1,238 +0,0 @@ -#include "builder.h" - -namespace FN { - -using BLI::ScopedVector; - -InlinedTreeMFNetworkBuilder::InlinedTreeMFNetworkBuilder( - const InlinedNodeTree &inlined_tree, - const PreprocessedVTreeMFData &preprocessed_inlined_tree_data, - const VTreeMultiFunctionMappings &inlined_tree_mappings, - ResourceCollector &resources) - : m_inlined_tree(inlined_tree), - m_preprocessed_inlined_tree_data(preprocessed_inlined_tree_data), - m_inlined_tree_mappings(inlined_tree_mappings), - m_resources(resources), - m_single_socket_by_xsocket(inlined_tree.socket_count(), InlinedTreeMFSocketMap_UNMAPPED), - m_builder(BLI::make_unique<MFNetworkBuilder>()) -{ -} - -MFBuilderFunctionNode &InlinedTreeMFNetworkBuilder::add_function(const MultiFunction &function) -{ - return m_builder->add_function(function); -} - -MFBuilderFunctionNode &InlinedTreeMFNetworkBuilder::add_function(const MultiFunction &function, - const XNode &xnode) -{ - MFBuilderFunctionNode &node = m_builder->add_function(function); - this->map_data_sockets(xnode, node); - return node; -} - -MFBuilderDummyNode &InlinedTreeMFNetworkBuilder::add_dummy(const XNode &xnode) -{ - ScopedVector<MFDataType> input_types; - ScopedVector<StringRef> input_names; - for (const XInputSocket *xsocket : xnode.inputs()) { - Optional<MFDataType> data_type = this->try_get_data_type(*xsocket); - if (data_type.has_value()) { - input_types.append(data_type.value()); - input_names.append(xsocket->name()); - } - } - - ScopedVector<MFDataType> output_types; - ScopedVector<StringRef> output_names; - for (const XOutputSocket *xsocket : xnode.outputs()) { - Optional<MFDataType> data_type = this->try_get_data_type(*xsocket); - if (data_type.has_value()) { - output_types.append(data_type.value()); - output_names.append(xsocket->name()); - } - } - - MFBuilderDummyNode &node = m_builder->add_dummy( - xnode.name(), input_types, output_types, input_names, output_names); - this->map_data_sockets(xnode, node); - return node; -} - -void InlinedTreeMFNetworkBuilder::map_data_sockets(const XNode &xnode, MFBuilderNode &node) -{ - uint data_inputs = 0; - for (const XInputSocket *xsocket : xnode.inputs()) { - if (this->is_data_socket(*xsocket)) { - this->map_sockets(*xsocket, *node.inputs()[data_inputs]); - data_inputs++; - } - } - - uint data_outputs = 0; - for (const XOutputSocket *xsocket : xnode.outputs()) { - if (this->is_data_socket(*xsocket)) { - this->map_sockets(*xsocket, *node.outputs()[data_outputs]); - data_outputs++; - } - } -} - -void InlinedTreeMFNetworkBuilder::assert_xnode_is_mapped_correctly(const XNode &xnode) const -{ - UNUSED_VARS_NDEBUG(xnode); -#ifdef DEBUG - this->assert_data_sockets_are_mapped_correctly(xnode.inputs().cast<const XSocket *>()); - this->assert_data_sockets_are_mapped_correctly(xnode.outputs().cast<const XSocket *>()); -#endif -} - -void InlinedTreeMFNetworkBuilder::assert_data_sockets_are_mapped_correctly( - ArrayRef<const XSocket *> xsockets) const -{ - for (const XSocket *xsocket : xsockets) { - if (this->is_data_socket(*xsocket)) { - this->assert_xsocket_is_mapped_correctly(*xsocket); - } - } -} - -void InlinedTreeMFNetworkBuilder::assert_xsocket_is_mapped_correctly(const XSocket &xsocket) const -{ - BLI_assert(this->xsocket_is_mapped(xsocket)); - MFDataType xsocket_type = this->try_get_data_type(xsocket).value(); - UNUSED_VARS_NDEBUG(xsocket_type); - - if (xsocket.is_input()) { - for (MFBuilderInputSocket *socket : this->lookup_socket(xsocket.as_input())) { - MFDataType socket_type = socket->data_type(); - BLI_assert(socket_type == xsocket_type); - UNUSED_VARS_NDEBUG(socket_type); - } - } - else { - MFBuilderSocket &socket = this->lookup_socket(xsocket.as_output()); - MFDataType socket_type = socket.data_type(); - BLI_assert(socket_type == xsocket_type); - UNUSED_VARS_NDEBUG(socket_type); - } -} - -bool InlinedTreeMFNetworkBuilder::has_data_sockets(const XNode &xnode) const -{ - for (const XInputSocket *xsocket : xnode.inputs()) { - if (this->is_data_socket(*xsocket)) { - return true; - } - } - for (const XOutputSocket *xsocket : xnode.outputs()) { - if (this->is_data_socket(*xsocket)) { - return true; - } - } - return false; -} - -const CPPType &InlinedTreeMFNetworkBuilder::cpp_type_from_property(const XNode &xnode, - StringRefNull prop_name) const -{ - char *type_name = RNA_string_get_alloc(xnode.rna(), prop_name.data(), nullptr, 0); - const CPPType &type = this->cpp_type_by_name(type_name); - MEM_freeN(type_name); - return type; -} - -MFDataType InlinedTreeMFNetworkBuilder::data_type_from_property(const XNode &xnode, - StringRefNull prop_name) const -{ - char *type_name = RNA_string_get_alloc(xnode.rna(), prop_name.data(), nullptr, 0); - MFDataType type = m_inlined_tree_mappings.data_type_by_type_name.lookup(type_name); - MEM_freeN(type_name); - return type; -} - -Vector<bool> VNodeMFNetworkBuilder::get_list_base_variadic_states(StringRefNull prop_name) -{ - Vector<bool> states; - RNA_BEGIN (m_xnode.rna(), itemptr, prop_name.data()) { - int state = RNA_enum_get(&itemptr, "state"); - if (state == 0) { - /* single value case */ - states.append(false); - } - else if (state == 1) { - /* list case */ - states.append(true); - } - else { - BLI_assert(false); - } - } - RNA_END; - return states; -} - -void VNodeMFNetworkBuilder::set_matching_fn(const MultiFunction &fn) -{ - MFBuilderFunctionNode &node = m_network_builder.add_function(fn); - m_network_builder.map_data_sockets(m_xnode, node); -} - -const MultiFunction &VNodeMFNetworkBuilder::get_vectorized_function( - const MultiFunction &base_function, ArrayRef<const char *> is_vectorized_prop_names) -{ - ScopedVector<bool> input_is_vectorized; - for (const char *prop_name : is_vectorized_prop_names) { - char state[5]; - RNA_string_get(m_xnode.rna(), prop_name, state); - BLI_assert(STREQ(state, "BASE") || STREQ(state, "LIST")); - - bool is_vectorized = STREQ(state, "LIST"); - input_is_vectorized.append(is_vectorized); - } - - if (input_is_vectorized.contains(true)) { - return this->construct_fn<MF_SimpleVectorize>(base_function, input_is_vectorized); - } - else { - return base_function; - } -} - -std::unique_ptr<InlinedTreeMFNetwork> InlinedTreeMFNetworkBuilder::build() -{ - // m_builder->to_dot__clipboard(); - - auto network = BLI::make_unique<MFNetwork>(std::move(m_builder)); - - Array<uint> xsocket_by_socket(network->socket_ids().size(), InlinedTreeMFSocketMap_UNMAPPED); - for (uint xsocket_id : m_single_socket_by_xsocket.index_iterator()) { - switch (m_single_socket_by_xsocket[xsocket_id]) { - case InlinedTreeMFSocketMap_UNMAPPED: { - break; - } - case InlinedTreeMFSocketMap_MULTIMAPPED: { - for (uint socket_id : m_multiple_inputs_by_xsocket.lookup(xsocket_id)) { - xsocket_by_socket[socket_id] = xsocket_id; - } - break; - } - default: { - uint socket_id = m_single_socket_by_xsocket[xsocket_id]; - xsocket_by_socket[socket_id] = xsocket_id; - break; - } - } - } - - InlinedTreeMFSocketMap socket_map(m_inlined_tree, - *network, - std::move(m_single_socket_by_xsocket), - std::move(m_multiple_inputs_by_xsocket), - std::move(xsocket_by_socket)); - - return BLI::make_unique<InlinedTreeMFNetwork>( - m_inlined_tree, std::move(network), std::move(socket_map)); -} - -} // namespace FN diff --git a/source/blender/functions/intern/node_tree.cc b/source/blender/functions/intern/node_tree.cc index 3bce7eeaaf4..a3d2a6d8cab 100644 --- a/source/blender/functions/intern/node_tree.cc +++ b/source/blender/functions/intern/node_tree.cc @@ -76,44 +76,44 @@ static bool is_group_node(const VNode &vnode) return vnode.idname() == "fn_GroupNode"; } -InlinedNodeTree::~InlinedNodeTree() +FunctionNodeTree::~FunctionNodeTree() { - for (XNode *xnode : m_node_by_id) { - xnode->~XNode(); + for (FNode *fnode : m_node_by_id) { + fnode->~FNode(); } - for (XGroupInput *xgroup_input : m_group_inputs) { - xgroup_input->~XGroupInput(); + for (FGroupInput *xgroup_input : m_group_inputs) { + xgroup_input->~FGroupInput(); } - for (XParentNode *xparent_node : m_parent_nodes) { - xparent_node->~XParentNode(); + for (FParentNode *xparent_node : m_parent_nodes) { + xparent_node->~FParentNode(); } - for (XInputSocket *xsocket : m_input_sockets) { - xsocket->~XInputSocket(); + for (FInputSocket *fsocket : m_input_sockets) { + fsocket->~FInputSocket(); } - for (XOutputSocket *xsocket : m_output_sockets) { - xsocket->~XOutputSocket(); + for (FOutputSocket *fsocket : m_output_sockets) { + fsocket->~FOutputSocket(); } } -void XNode::destruct_with_sockets() +void FNode::destruct_with_sockets() { - for (XInputSocket *socket : m_inputs) { - socket->~XInputSocket(); + for (FInputSocket *socket : m_inputs) { + socket->~FInputSocket(); } - for (XOutputSocket *socket : m_outputs) { - socket->~XOutputSocket(); + for (FOutputSocket *socket : m_outputs) { + socket->~FOutputSocket(); } - this->~XNode(); + this->~FNode(); } -BLI_NOINLINE InlinedNodeTree::InlinedNodeTree(bNodeTree *btree, BTreeVTreeMap &vtrees) +BLI_NOINLINE FunctionNodeTree::FunctionNodeTree(bNodeTree *btree, BTreeVTreeMap &vtrees) : m_btree(btree) { const VirtualNodeTree &main_vtree = get_vtree(vtrees, btree); - Vector<XNode *> all_nodes; - Vector<XGroupInput *> all_group_inputs; - Vector<XParentNode *> all_parent_nodes; + Vector<FNode *> all_nodes; + Vector<FGroupInput *> all_group_inputs; + Vector<FParentNode *> all_parent_nodes; this->insert_linked_nodes_for_vtree_in_id_order(main_vtree, all_nodes, nullptr); this->expand_groups(all_nodes, all_group_inputs, all_parent_nodes, vtrees); @@ -122,24 +122,24 @@ BLI_NOINLINE InlinedNodeTree::InlinedNodeTree(bNodeTree *btree, BTreeVTreeMap &v std::move(all_nodes), std::move(all_group_inputs), std::move(all_parent_nodes)); } -BLI_NOINLINE void InlinedNodeTree::expand_groups(Vector<XNode *> &all_nodes, - Vector<XGroupInput *> &all_group_inputs, - Vector<XParentNode *> &all_parent_nodes, - BTreeVTreeMap &vtrees) +BLI_NOINLINE void FunctionNodeTree::expand_groups(Vector<FNode *> &all_nodes, + Vector<FGroupInput *> &all_group_inputs, + Vector<FParentNode *> &all_parent_nodes, + BTreeVTreeMap &vtrees) { for (uint i = 0; i < all_nodes.size(); i++) { - XNode ¤t_node = *all_nodes[i]; + FNode ¤t_node = *all_nodes[i]; if (is_group_node(*current_node.m_vnode)) { this->expand_group_node(current_node, all_nodes, all_group_inputs, all_parent_nodes, vtrees); } } } -BLI_NOINLINE void InlinedNodeTree::expand_group_node(XNode &group_node, - Vector<XNode *> &all_nodes, - Vector<XGroupInput *> &all_group_inputs, - Vector<XParentNode *> &all_parent_nodes, - BTreeVTreeMap &vtrees) +BLI_NOINLINE void FunctionNodeTree::expand_group_node(FNode &group_node, + Vector<FNode *> &all_nodes, + Vector<FGroupInput *> &all_group_inputs, + Vector<FParentNode *> &all_parent_nodes, + BTreeVTreeMap &vtrees) { BLI_assert(is_group_node(*group_node.m_vnode)); const VNode &group_vnode = *group_node.m_vnode; @@ -150,25 +150,25 @@ BLI_NOINLINE void InlinedNodeTree::expand_group_node(XNode &group_node, const VirtualNodeTree &vtree = get_vtree(vtrees, btree); - XParentNode &sub_parent = *m_allocator.construct<XParentNode>().release(); + FParentNode &sub_parent = *m_allocator.construct<FParentNode>().release(); sub_parent.m_id = all_parent_nodes.append_and_get_index(&sub_parent); sub_parent.m_parent = group_node.m_parent; sub_parent.m_vnode = &group_vnode; this->insert_linked_nodes_for_vtree_in_id_order(vtree, all_nodes, &sub_parent); - ArrayRef<XNode *> new_xnodes_by_id = all_nodes.as_ref().take_back(vtree.nodes().size()); + ArrayRef<FNode *> new_fnodes_by_id = all_nodes.as_ref().take_back(vtree.nodes().size()); this->expand_group__group_inputs_for_unlinked_inputs(group_node, all_group_inputs); - this->expand_group__relink_inputs(vtree, new_xnodes_by_id, group_node); - this->expand_group__relink_outputs(vtree, new_xnodes_by_id, group_node); + this->expand_group__relink_inputs(vtree, new_fnodes_by_id, group_node); + this->expand_group__relink_outputs(vtree, new_fnodes_by_id, group_node); } -BLI_NOINLINE void InlinedNodeTree::expand_group__group_inputs_for_unlinked_inputs( - XNode &group_node, Vector<XGroupInput *> &all_group_inputs) +BLI_NOINLINE void FunctionNodeTree::expand_group__group_inputs_for_unlinked_inputs( + FNode &group_node, Vector<FGroupInput *> &all_group_inputs) { - for (XInputSocket *input_socket : group_node.m_inputs) { + for (FInputSocket *input_socket : group_node.m_inputs) { if (!input_socket->is_linked()) { - XGroupInput &group_input = *m_allocator.construct<XGroupInput>().release(); + FGroupInput &group_input = *m_allocator.construct<FGroupInput>().release(); group_input.m_id = all_group_inputs.append_and_get_index(&group_input); group_input.m_vsocket = &input_socket->m_vsocket->as_input(); group_input.m_parent = group_node.m_parent; @@ -179,38 +179,38 @@ BLI_NOINLINE void InlinedNodeTree::expand_group__group_inputs_for_unlinked_input } } -BLI_NOINLINE void InlinedNodeTree::expand_group__relink_inputs(const VirtualNodeTree &vtree, - ArrayRef<XNode *> new_xnodes_by_id, - XNode &group_node) +BLI_NOINLINE void FunctionNodeTree::expand_group__relink_inputs(const VirtualNodeTree &vtree, + ArrayRef<FNode *> new_fnodes_by_id, + FNode &group_node) { Vector<const VOutputSocket *> group_inputs = get_group_inputs(vtree); for (uint input_index : group_inputs.index_iterator()) { const VOutputSocket *inside_interface_vsocket = group_inputs[input_index]; const VNode &inside_interface_vnode = inside_interface_vsocket->node(); - XNode *inside_interface_xnode = new_xnodes_by_id[inside_interface_vnode.id()]; + FNode *inside_interface_fnode = new_fnodes_by_id[inside_interface_vnode.id()]; - XOutputSocket &inside_interface = - *inside_interface_xnode->m_outputs[inside_interface_vsocket->index()]; - XInputSocket &outside_interface = *group_node.m_inputs[input_index]; + FOutputSocket &inside_interface = + *inside_interface_fnode->m_outputs[inside_interface_vsocket->index()]; + FInputSocket &outside_interface = *group_node.m_inputs[input_index]; - for (XOutputSocket *outside_connected : outside_interface.m_linked_sockets) { + for (FOutputSocket *outside_connected : outside_interface.m_linked_sockets) { outside_connected->m_linked_sockets.remove_first_occurrence_and_reorder(&outside_interface); } - for (XGroupInput *outside_connected : outside_interface.m_linked_group_inputs) { + for (FGroupInput *outside_connected : outside_interface.m_linked_group_inputs) { outside_connected->m_linked_sockets.remove_first_occurrence_and_reorder(&outside_interface); } - for (XInputSocket *inside_connected : inside_interface.m_linked_sockets) { + for (FInputSocket *inside_connected : inside_interface.m_linked_sockets) { inside_connected->m_linked_sockets.remove_first_occurrence_and_reorder(&inside_interface); - for (XOutputSocket *outside_connected : outside_interface.m_linked_sockets) { + for (FOutputSocket *outside_connected : outside_interface.m_linked_sockets) { inside_connected->m_linked_sockets.append(outside_connected); outside_connected->m_linked_sockets.append(inside_connected); } - for (XGroupInput *outside_connected : outside_interface.m_linked_group_inputs) { + for (FGroupInput *outside_connected : outside_interface.m_linked_group_inputs) { inside_connected->m_linked_group_inputs.append(outside_connected); outside_connected->m_linked_sockets.append(inside_connected); } @@ -222,40 +222,39 @@ BLI_NOINLINE void InlinedNodeTree::expand_group__relink_inputs(const VirtualNode } } -BLI_NOINLINE void InlinedNodeTree::expand_group__relink_outputs(const VirtualNodeTree &vtree, - ArrayRef<XNode *> new_xnodes_by_id, - XNode &group_node) +BLI_NOINLINE void FunctionNodeTree::expand_group__relink_outputs( + const VirtualNodeTree &vtree, ArrayRef<FNode *> new_fnodes_by_id, FNode &group_node) { Vector<const VInputSocket *> group_outputs = get_group_outputs(vtree); for (uint output_index : group_outputs.index_iterator()) { const VInputSocket *inside_interface_vsocket = group_outputs[output_index]; const VNode &inside_interface_vnode = inside_interface_vsocket->node(); - XNode *inside_interface_xnode = new_xnodes_by_id[inside_interface_vnode.id()]; + FNode *inside_interface_fnode = new_fnodes_by_id[inside_interface_vnode.id()]; - XInputSocket &inside_interface = - *inside_interface_xnode->m_inputs[inside_interface_vsocket->index()]; - XOutputSocket &outside_interface = *group_node.m_outputs[output_index]; + FInputSocket &inside_interface = + *inside_interface_fnode->m_inputs[inside_interface_vsocket->index()]; + FOutputSocket &outside_interface = *group_node.m_outputs[output_index]; - for (XOutputSocket *inside_connected : inside_interface.m_linked_sockets) { + for (FOutputSocket *inside_connected : inside_interface.m_linked_sockets) { inside_connected->m_linked_sockets.remove_first_occurrence_and_reorder(&inside_interface); - for (XInputSocket *outside_connected : outside_interface.m_linked_sockets) { + for (FInputSocket *outside_connected : outside_interface.m_linked_sockets) { inside_connected->m_linked_sockets.append(outside_connected); outside_connected->m_linked_sockets.append(inside_connected); } } - for (XGroupInput *inside_connected : inside_interface.m_linked_group_inputs) { + for (FGroupInput *inside_connected : inside_interface.m_linked_group_inputs) { inside_connected->m_linked_sockets.remove_first_occurrence_and_reorder(&inside_interface); - for (XInputSocket *outside_connected : outside_interface.m_linked_sockets) { + for (FInputSocket *outside_connected : outside_interface.m_linked_sockets) { inside_connected->m_linked_sockets.append(outside_connected); outside_connected->m_linked_group_inputs.append(inside_connected); } } - for (XInputSocket *outside_connected : outside_interface.m_linked_sockets) { + for (FInputSocket *outside_connected : outside_interface.m_linked_sockets) { outside_connected->m_linked_sockets.remove_first_occurrence_and_reorder(&outside_interface); } @@ -264,23 +263,23 @@ BLI_NOINLINE void InlinedNodeTree::expand_group__relink_outputs(const VirtualNod } } -BLI_NOINLINE void InlinedNodeTree::insert_linked_nodes_for_vtree_in_id_order( - const VirtualNodeTree &vtree, Vector<XNode *> &all_nodes, XParentNode *parent) +BLI_NOINLINE void FunctionNodeTree::insert_linked_nodes_for_vtree_in_id_order( + const VirtualNodeTree &vtree, Vector<FNode *> &all_nodes, FParentNode *parent) { - BLI::LargeScopedArray<XSocket *> sockets_map(vtree.socket_count()); + BLI::LargeScopedArray<FSocket *> sockets_map(vtree.socket_count()); /* Insert nodes of group. */ for (const VNode *vnode : vtree.nodes()) { - XNode &node = this->create_node(*vnode, parent, sockets_map); + FNode &node = this->create_node(*vnode, parent, sockets_map); all_nodes.append(&node); } /* Insert links of group. */ for (const VNode *vnode : vtree.nodes()) { for (const VInputSocket *to_vsocket : vnode->inputs()) { - XInputSocket *to_socket = (XInputSocket *)sockets_map[to_vsocket->id()]; + FInputSocket *to_socket = (FInputSocket *)sockets_map[to_vsocket->id()]; for (const VOutputSocket *from_vsocket : to_vsocket->linked_sockets()) { - XOutputSocket *from_socket = (XOutputSocket *)sockets_map[from_vsocket->id()]; + FOutputSocket *from_socket = (FOutputSocket *)sockets_map[from_vsocket->id()]; to_socket->m_linked_sockets.append(from_socket); from_socket->m_linked_sockets.append(to_socket); } @@ -288,17 +287,17 @@ BLI_NOINLINE void InlinedNodeTree::insert_linked_nodes_for_vtree_in_id_order( } } -BLI_NOINLINE XNode &InlinedNodeTree::create_node(const VNode &vnode, - XParentNode *parent, - MutableArrayRef<XSocket *> sockets_map) +BLI_NOINLINE FNode &FunctionNodeTree::create_node(const VNode &vnode, + FParentNode *parent, + MutableArrayRef<FSocket *> sockets_map) { - XNode &new_node = *m_allocator.construct<XNode>().release(); + FNode &new_node = *m_allocator.construct<FNode>().release(); new_node.m_vnode = &vnode; new_node.m_parent = parent; new_node.m_id = UINT32_MAX; for (const VInputSocket *vsocket : vnode.inputs()) { - XInputSocket &new_socket = *m_allocator.construct<XInputSocket>().release(); + FInputSocket &new_socket = *m_allocator.construct<FInputSocket>().release(); new_socket.m_vsocket = vsocket; new_socket.m_node = &new_node; new_socket.m_id = UINT32_MAX; @@ -309,7 +308,7 @@ BLI_NOINLINE XNode &InlinedNodeTree::create_node(const VNode &vnode, } for (const VOutputSocket *vsocket : vnode.outputs()) { - XOutputSocket &new_socket = *m_allocator.construct<XOutputSocket>().release(); + FOutputSocket &new_socket = *m_allocator.construct<FOutputSocket>().release(); new_socket.m_vsocket = vsocket; new_socket.m_node = &new_node; new_socket.m_id = UINT32_MAX; @@ -322,11 +321,11 @@ BLI_NOINLINE XNode &InlinedNodeTree::create_node(const VNode &vnode, return new_node; } -BLI_NOINLINE void InlinedNodeTree::remove_expanded_groups_and_interfaces( - Vector<XNode *> &all_nodes) +BLI_NOINLINE void FunctionNodeTree::remove_expanded_groups_and_interfaces( + Vector<FNode *> &all_nodes) { for (int i = 0; i < all_nodes.size(); i++) { - XNode *current_node = all_nodes[i]; + FNode *current_node = all_nodes[i]; if (is_group_node(current_node->vnode()) || (is_interface_node(current_node->vnode()) && current_node->parent() != nullptr)) { all_nodes.remove_and_reorder(i); @@ -336,41 +335,41 @@ BLI_NOINLINE void InlinedNodeTree::remove_expanded_groups_and_interfaces( } } -BLI_NOINLINE void InlinedNodeTree::store_tree_in_this_and_init_ids( - Vector<XNode *> &&all_nodes, - Vector<XGroupInput *> &&all_group_inputs, - Vector<XParentNode *> &&all_parent_nodes) +BLI_NOINLINE void FunctionNodeTree::store_tree_in_this_and_init_ids( + Vector<FNode *> &&all_nodes, + Vector<FGroupInput *> &&all_group_inputs, + Vector<FParentNode *> &&all_parent_nodes) { m_node_by_id = std::move(all_nodes); m_group_inputs = std::move(all_group_inputs); m_parent_nodes = std::move(all_parent_nodes); for (uint node_index : m_node_by_id.index_iterator()) { - XNode *xnode = m_node_by_id[node_index]; - xnode->m_id = node_index; + FNode *fnode = m_node_by_id[node_index]; + fnode->m_id = node_index; - if (m_nodes_by_idname.contains(xnode->idname())) { - m_nodes_by_idname.lookup(xnode->idname()).append(xnode); + if (m_nodes_by_idname.contains(fnode->idname())) { + m_nodes_by_idname.lookup(fnode->idname()).append(fnode); } else { - m_nodes_by_idname.add_new(xnode->idname(), {xnode}); + m_nodes_by_idname.add_new(fnode->idname(), {fnode}); } - for (XInputSocket *xsocket : xnode->m_inputs) { - xsocket->m_id = m_sockets_by_id.append_and_get_index(xsocket); - m_input_sockets.append(xsocket); + for (FInputSocket *fsocket : fnode->m_inputs) { + fsocket->m_id = m_sockets_by_id.append_and_get_index(fsocket); + m_input_sockets.append(fsocket); } - for (XOutputSocket *xsocket : xnode->m_outputs) { - xsocket->m_id = m_sockets_by_id.append_and_get_index(xsocket); - m_output_sockets.append(xsocket); + for (FOutputSocket *fsocket : fnode->m_outputs) { + fsocket->m_id = m_sockets_by_id.append_and_get_index(fsocket); + m_output_sockets.append(fsocket); } } } static BLI::DotExport::Cluster *get_cluster_for_parent( BLI::DotExport::DirectedGraph &graph, - Map<const XParentNode *, BLI::DotExport::Cluster *> &clusters, - const XParentNode *parent) + Map<const FParentNode *, BLI::DotExport::Cluster *> &clusters, + const FParentNode *parent) { if (parent == nullptr) { return nullptr; @@ -390,39 +389,39 @@ static BLI::DotExport::Cluster *get_cluster_for_parent( } } -std::string InlinedNodeTree::to_dot() const +std::string FunctionNodeTree::to_dot() const { BLI::DotExport::DirectedGraph digraph; digraph.set_rankdir(BLI::DotExport::Attr_rankdir::LeftToRight); - Map<const XNode *, BLI::DotExport::Utils::NodeWithSocketsWrapper> dot_nodes; - Map<const XGroupInput *, BLI::DotExport::Utils::NodeWithSocketsWrapper> dot_group_inputs; - Map<const XParentNode *, BLI::DotExport::Cluster *> dot_clusters; + Map<const FNode *, BLI::DotExport::Utils::NodeWithSocketsWrapper> dot_nodes; + Map<const FGroupInput *, BLI::DotExport::Utils::NodeWithSocketsWrapper> dot_group_inputs; + Map<const FParentNode *, BLI::DotExport::Cluster *> dot_clusters; - for (const XNode *xnode : m_node_by_id) { + for (const FNode *fnode : m_node_by_id) { auto &dot_node = digraph.new_node(""); dot_node.set_attribute("bgcolor", "white"); dot_node.set_attribute("style", "filled"); Vector<std::string> input_names; - for (const XInputSocket *input : xnode->inputs()) { + for (const FInputSocket *input : fnode->inputs()) { input_names.append(input->m_vsocket->name()); } Vector<std::string> output_names; - for (const XOutputSocket *output : xnode->outputs()) { + for (const FOutputSocket *output : fnode->outputs()) { output_names.append(output->m_vsocket->name()); } - dot_nodes.add_new(xnode, + dot_nodes.add_new(fnode, BLI::DotExport::Utils::NodeWithSocketsWrapper( - dot_node, xnode->vnode().name(), input_names, output_names)); + dot_node, fnode->vnode().name(), input_names, output_names)); BLI::DotExport::Cluster *cluster = get_cluster_for_parent( - digraph, dot_clusters, xnode->parent()); + digraph, dot_clusters, fnode->parent()); dot_node.set_parent_cluster(cluster); - for (const XInputSocket *input : xnode->inputs()) { - for (const XGroupInput *group_input : input->linked_group_inputs()) { + for (const FInputSocket *input : fnode->inputs()) { + for (const FGroupInput *group_input : input->linked_group_inputs()) { if (!dot_group_inputs.contains(group_input)) { auto &dot_group_input_node = digraph.new_node(""); dot_group_input_node.set_attribute("bgcolor", "white"); @@ -443,23 +442,23 @@ std::string InlinedNodeTree::to_dot() const } } - for (const XNode *to_xnode : m_node_by_id) { - auto to_dot_node = dot_nodes.lookup(to_xnode); + for (const FNode *to_fnode : m_node_by_id) { + auto to_dot_node = dot_nodes.lookup(to_fnode); - for (const XInputSocket *to_xsocket : to_xnode->inputs()) { - for (const XOutputSocket *from_xsocket : to_xsocket->linked_sockets()) { - const XNode *from_xnode = &from_xsocket->node(); + for (const FInputSocket *to_fsocket : to_fnode->inputs()) { + for (const FOutputSocket *from_fsocket : to_fsocket->linked_sockets()) { + const FNode *from_fnode = &from_fsocket->node(); - auto from_dot_node = dot_nodes.lookup(from_xnode); + auto from_dot_node = dot_nodes.lookup(from_fnode); - digraph.new_edge(from_dot_node.output(from_xsocket->vsocket().index()), - to_dot_node.input(to_xsocket->vsocket().index())); + digraph.new_edge(from_dot_node.output(from_fsocket->vsocket().index()), + to_dot_node.input(to_fsocket->vsocket().index())); } - for (const XGroupInput *group_input : to_xsocket->linked_group_inputs()) { + for (const FGroupInput *group_input : to_fsocket->linked_group_inputs()) { auto from_dot_node = dot_group_inputs.lookup(group_input); digraph.new_edge(from_dot_node.output(0), - to_dot_node.input(to_xsocket->vsocket().index())); + to_dot_node.input(to_fsocket->vsocket().index())); } } } @@ -468,17 +467,17 @@ std::string InlinedNodeTree::to_dot() const return digraph.to_dot_string(); } -void InlinedNodeTree::to_dot__clipboard() const +void FunctionNodeTree::to_dot__clipboard() const { std::string dot = this->to_dot(); WM_clipboard_text_set(dot.c_str(), false); } -const XInputSocket *XNode::input_with_name_prefix(StringRef name_prefix) const +const FInputSocket *FNode::input_with_name_prefix(StringRef name_prefix) const { - for (const XInputSocket *xsocket : m_inputs) { - if (xsocket->name().startswith(name_prefix)) { - return xsocket; + for (const FInputSocket *fsocket : m_inputs) { + if (fsocket->name().startswith(name_prefix)) { + return fsocket; } } return nullptr; diff --git a/source/blender/functions/intern/node_tree_multi_function_network/builder.cc b/source/blender/functions/intern/node_tree_multi_function_network/builder.cc new file mode 100644 index 00000000000..4cfacb924b5 --- /dev/null +++ b/source/blender/functions/intern/node_tree_multi_function_network/builder.cc @@ -0,0 +1,238 @@ +#include "builder.h" + +namespace FN { + +using BLI::ScopedVector; + +FunctionTreeMFNetworkBuilder::FunctionTreeMFNetworkBuilder( + const FunctionNodeTree &function_tree, + const PreprocessedVTreeMFData &preprocessed_function_tree_data, + const VTreeMultiFunctionMappings &function_tree_mappings, + ResourceCollector &resources) + : m_function_tree(function_tree), + m_preprocessed_function_tree_data(preprocessed_function_tree_data), + m_function_tree_mappings(function_tree_mappings), + m_resources(resources), + m_single_socket_by_fsocket(function_tree.socket_count(), InlinedTreeMFSocketMap_UNMAPPED), + m_builder(BLI::make_unique<MFNetworkBuilder>()) +{ +} + +MFBuilderFunctionNode &FunctionTreeMFNetworkBuilder::add_function(const MultiFunction &function) +{ + return m_builder->add_function(function); +} + +MFBuilderFunctionNode &FunctionTreeMFNetworkBuilder::add_function(const MultiFunction &function, + const FNode &fnode) +{ + MFBuilderFunctionNode &node = m_builder->add_function(function); + this->map_data_sockets(fnode, node); + return node; +} + +MFBuilderDummyNode &FunctionTreeMFNetworkBuilder::add_dummy(const FNode &fnode) +{ + ScopedVector<MFDataType> input_types; + ScopedVector<StringRef> input_names; + for (const FInputSocket *fsocket : fnode.inputs()) { + Optional<MFDataType> data_type = this->try_get_data_type(*fsocket); + if (data_type.has_value()) { + input_types.append(data_type.value()); + input_names.append(fsocket->name()); + } + } + + ScopedVector<MFDataType> output_types; + ScopedVector<StringRef> output_names; + for (const FOutputSocket *fsocket : fnode.outputs()) { + Optional<MFDataType> data_type = this->try_get_data_type(*fsocket); + if (data_type.has_value()) { + output_types.append(data_type.value()); + output_names.append(fsocket->name()); + } + } + + MFBuilderDummyNode &node = m_builder->add_dummy( + fnode.name(), input_types, output_types, input_names, output_names); + this->map_data_sockets(fnode, node); + return node; +} + +void FunctionTreeMFNetworkBuilder::map_data_sockets(const FNode &fnode, MFBuilderNode &node) +{ + uint data_inputs = 0; + for (const FInputSocket *fsocket : fnode.inputs()) { + if (this->is_data_socket(*fsocket)) { + this->map_sockets(*fsocket, *node.inputs()[data_inputs]); + data_inputs++; + } + } + + uint data_outputs = 0; + for (const FOutputSocket *fsocket : fnode.outputs()) { + if (this->is_data_socket(*fsocket)) { + this->map_sockets(*fsocket, *node.outputs()[data_outputs]); + data_outputs++; + } + } +} + +void FunctionTreeMFNetworkBuilder::assert_fnode_is_mapped_correctly(const FNode &fnode) const +{ + UNUSED_VARS_NDEBUG(fnode); +#ifdef DEBUG + this->assert_data_sockets_are_mapped_correctly(fnode.inputs().cast<const FSocket *>()); + this->assert_data_sockets_are_mapped_correctly(fnode.outputs().cast<const FSocket *>()); +#endif +} + +void FunctionTreeMFNetworkBuilder::assert_data_sockets_are_mapped_correctly( + ArrayRef<const FSocket *> fsockets) const +{ + for (const FSocket *fsocket : fsockets) { + if (this->is_data_socket(*fsocket)) { + this->assert_fsocket_is_mapped_correctly(*fsocket); + } + } +} + +void FunctionTreeMFNetworkBuilder::assert_fsocket_is_mapped_correctly(const FSocket &fsocket) const +{ + BLI_assert(this->fsocket_is_mapped(fsocket)); + MFDataType fsocket_type = this->try_get_data_type(fsocket).value(); + UNUSED_VARS_NDEBUG(fsocket_type); + + if (fsocket.is_input()) { + for (MFBuilderInputSocket *socket : this->lookup_socket(fsocket.as_input())) { + MFDataType socket_type = socket->data_type(); + BLI_assert(socket_type == fsocket_type); + UNUSED_VARS_NDEBUG(socket_type); + } + } + else { + MFBuilderSocket &socket = this->lookup_socket(fsocket.as_output()); + MFDataType socket_type = socket.data_type(); + BLI_assert(socket_type == fsocket_type); + UNUSED_VARS_NDEBUG(socket_type); + } +} + +bool FunctionTreeMFNetworkBuilder::has_data_sockets(const FNode &fnode) const +{ + for (const FInputSocket *fsocket : fnode.inputs()) { + if (this->is_data_socket(*fsocket)) { + return true; + } + } + for (const FOutputSocket *fsocket : fnode.outputs()) { + if (this->is_data_socket(*fsocket)) { + return true; + } + } + return false; +} + +const CPPType &FunctionTreeMFNetworkBuilder::cpp_type_from_property(const FNode &fnode, + StringRefNull prop_name) const +{ + char *type_name = RNA_string_get_alloc(fnode.rna(), prop_name.data(), nullptr, 0); + const CPPType &type = this->cpp_type_by_name(type_name); + MEM_freeN(type_name); + return type; +} + +MFDataType FunctionTreeMFNetworkBuilder::data_type_from_property(const FNode &fnode, + StringRefNull prop_name) const +{ + char *type_name = RNA_string_get_alloc(fnode.rna(), prop_name.data(), nullptr, 0); + MFDataType type = m_function_tree_mappings.data_type_by_type_name.lookup(type_name); + MEM_freeN(type_name); + return type; +} + +Vector<bool> FNodeMFNetworkBuilder::get_list_base_variadic_states(StringRefNull prop_name) +{ + Vector<bool> states; + RNA_BEGIN (m_fnode.rna(), itemptr, prop_name.data()) { + int state = RNA_enum_get(&itemptr, "state"); + if (state == 0) { + /* single value case */ + states.append(false); + } + else if (state == 1) { + /* list case */ + states.append(true); + } + else { + BLI_assert(false); + } + } + RNA_END; + return states; +} + +void FNodeMFNetworkBuilder::set_matching_fn(const MultiFunction &fn) +{ + MFBuilderFunctionNode &node = m_network_builder.add_function(fn); + m_network_builder.map_data_sockets(m_fnode, node); +} + +const MultiFunction &FNodeMFNetworkBuilder::get_vectorized_function( + const MultiFunction &base_function, ArrayRef<const char *> is_vectorized_prop_names) +{ + ScopedVector<bool> input_is_vectorized; + for (const char *prop_name : is_vectorized_prop_names) { + char state[5]; + RNA_string_get(m_fnode.rna(), prop_name, state); + BLI_assert(STREQ(state, "BASE") || STREQ(state, "LIST")); + + bool is_vectorized = STREQ(state, "LIST"); + input_is_vectorized.append(is_vectorized); + } + + if (input_is_vectorized.contains(true)) { + return this->construct_fn<MF_SimpleVectorize>(base_function, input_is_vectorized); + } + else { + return base_function; + } +} + +std::unique_ptr<FunctionTreeMFNetwork> FunctionTreeMFNetworkBuilder::build() +{ + // m_builder->to_dot__clipboard(); + + auto network = BLI::make_unique<MFNetwork>(std::move(m_builder)); + + Array<uint> fsocket_by_socket(network->socket_ids().size(), InlinedTreeMFSocketMap_UNMAPPED); + for (uint fsocket_id : m_single_socket_by_fsocket.index_iterator()) { + switch (m_single_socket_by_fsocket[fsocket_id]) { + case InlinedTreeMFSocketMap_UNMAPPED: { + break; + } + case InlinedTreeMFSocketMap_MULTIMAPPED: { + for (uint socket_id : m_multiple_inputs_by_fsocket.lookup(fsocket_id)) { + fsocket_by_socket[socket_id] = fsocket_id; + } + break; + } + default: { + uint socket_id = m_single_socket_by_fsocket[fsocket_id]; + fsocket_by_socket[socket_id] = fsocket_id; + break; + } + } + } + + InlinedTreeMFSocketMap socket_map(m_function_tree, + *network, + std::move(m_single_socket_by_fsocket), + std::move(m_multiple_inputs_by_fsocket), + std::move(fsocket_by_socket)); + + return BLI::make_unique<FunctionTreeMFNetwork>( + m_function_tree, std::move(network), std::move(socket_map)); +} + +} // namespace FN diff --git a/source/blender/functions/intern/inlined_tree_multi_function_network/builder.h b/source/blender/functions/intern/node_tree_multi_function_network/builder.h index 934edf8d0f7..f5c2f06c33a 100644 --- a/source/blender/functions/intern/inlined_tree_multi_function_network/builder.h +++ b/source/blender/functions/intern/node_tree_multi_function_network/builder.h @@ -1,6 +1,6 @@ #pragma once -#include "FN_inlined_tree_multi_function_network.h" +#include "FN_node_tree_multi_function_network.h" #include "FN_multi_functions.h" #include "BLI_multi_map.h" @@ -14,76 +14,76 @@ using BLI::MultiMap; class PreprocessedVTreeMFData { private: - Array<Optional<MFDataType>> m_data_type_by_xsocket_id; + Array<Optional<MFDataType>> m_data_type_by_fsocket_id; Array<Optional<MFDataType>> m_data_type_by_group_input_id; public: - PreprocessedVTreeMFData(const InlinedNodeTree &inlined_tree) + PreprocessedVTreeMFData(const FunctionNodeTree &function_tree) { - auto &mappings = get_inlined_tree_multi_function_mappings(); + auto &mappings = get_function_tree_multi_function_mappings(); - m_data_type_by_xsocket_id = Array<Optional<MFDataType>>(inlined_tree.socket_count()); - for (const XSocket *xsocket : inlined_tree.all_sockets()) { - m_data_type_by_xsocket_id[xsocket->id()] = mappings.data_type_by_idname.try_lookup( - xsocket->idname()); + m_data_type_by_fsocket_id = Array<Optional<MFDataType>>(function_tree.socket_count()); + for (const FSocket *fsocket : function_tree.all_sockets()) { + m_data_type_by_fsocket_id[fsocket->id()] = mappings.data_type_by_idname.try_lookup( + fsocket->idname()); } m_data_type_by_group_input_id = Array<Optional<MFDataType>>( - inlined_tree.all_group_inputs().size()); - for (const XGroupInput *group_input : inlined_tree.all_group_inputs()) { + function_tree.all_group_inputs().size()); + for (const FGroupInput *group_input : function_tree.all_group_inputs()) { m_data_type_by_group_input_id[group_input->id()] = mappings.data_type_by_idname.try_lookup( group_input->vsocket().idname()); } } - Optional<MFDataType> try_lookup_data_type(const XSocket &xsocket) const + Optional<MFDataType> try_lookup_data_type(const FSocket &fsocket) const { - return m_data_type_by_xsocket_id[xsocket.id()]; + return m_data_type_by_fsocket_id[fsocket.id()]; } - MFDataType lookup_data_type(const XSocket &xsocket) const + MFDataType lookup_data_type(const FSocket &fsocket) const { - return m_data_type_by_xsocket_id[xsocket.id()].value(); + return m_data_type_by_fsocket_id[fsocket.id()].value(); } - bool is_data_socket(const XSocket &xsocket) const + bool is_data_socket(const FSocket &fsocket) const { - return m_data_type_by_xsocket_id[xsocket.id()].has_value(); + return m_data_type_by_fsocket_id[fsocket.id()].has_value(); } - bool is_data_group_input(const XGroupInput &group_input) const + bool is_data_group_input(const FGroupInput &group_input) const { return m_data_type_by_group_input_id[group_input.id()].has_value(); } }; -class InlinedTreeMFNetworkBuilder : BLI::NonCopyable, BLI::NonMovable { +class FunctionTreeMFNetworkBuilder : BLI::NonCopyable, BLI::NonMovable { private: - const InlinedNodeTree &m_inlined_tree; - const PreprocessedVTreeMFData &m_preprocessed_inlined_tree_data; - const VTreeMultiFunctionMappings &m_inlined_tree_mappings; + const FunctionNodeTree &m_function_tree; + const PreprocessedVTreeMFData &m_preprocessed_function_tree_data; + const VTreeMultiFunctionMappings &m_function_tree_mappings; ResourceCollector &m_resources; - /* By default store mapping between xsockets and builder sockets in an array. - * Input xsockets can be mapped to multiple new sockets. So fallback to a multimap in this case. + /* By default store mapping between fsockets and builder sockets in an array. + * Input fsockets can be mapped to multiple new sockets. So fallback to a multimap in this case. */ - Array<uint> m_single_socket_by_xsocket; - MultiMap<uint, uint> m_multiple_inputs_by_xsocket; + Array<uint> m_single_socket_by_fsocket; + MultiMap<uint, uint> m_multiple_inputs_by_fsocket; static constexpr intptr_t MULTI_MAP_INDICATOR = 1; - Map<const XGroupInput *, MFBuilderOutputSocket *> m_group_inputs_mapping; + Map<const FGroupInput *, MFBuilderOutputSocket *> m_group_inputs_mapping; std::unique_ptr<MFNetworkBuilder> m_builder; public: - InlinedTreeMFNetworkBuilder(const InlinedNodeTree &inlined_tree, - const PreprocessedVTreeMFData &preprocessed_inlined_tree_data, - const VTreeMultiFunctionMappings &inlined_tree_mappings, - ResourceCollector &resources); + FunctionTreeMFNetworkBuilder(const FunctionNodeTree &function_tree, + const PreprocessedVTreeMFData &preprocessed_function_tree_data, + const VTreeMultiFunctionMappings &function_tree_mappings, + ResourceCollector &resources); - const InlinedNodeTree &inlined_tree() const + const FunctionNodeTree &function_tree() const { - return m_inlined_tree; + return m_function_tree; } ResourceCollector &resources() @@ -93,14 +93,14 @@ class InlinedTreeMFNetworkBuilder : BLI::NonCopyable, BLI::NonMovable { const VTreeMultiFunctionMappings &vtree_multi_function_mappings() const { - return m_inlined_tree_mappings; + return m_function_tree_mappings; } MFBuilderFunctionNode &add_function(const MultiFunction &function); - MFBuilderFunctionNode &add_function(const MultiFunction &function, const XNode &xnode); + MFBuilderFunctionNode &add_function(const MultiFunction &function, const FNode &fnode); - MFBuilderDummyNode &add_dummy(const XNode &xnode); + MFBuilderDummyNode &add_dummy(const FNode &fnode); MFBuilderDummyNode &add_dummy(StringRef name, ArrayRef<MFDataType> input_types, @@ -133,119 +133,119 @@ class InlinedTreeMFNetworkBuilder : BLI::NonCopyable, BLI::NonMovable { return *fn; } - Optional<MFDataType> try_get_data_type(const XSocket &xsocket) const + Optional<MFDataType> try_get_data_type(const FSocket &fsocket) const { - return m_preprocessed_inlined_tree_data.try_lookup_data_type(xsocket); + return m_preprocessed_function_tree_data.try_lookup_data_type(fsocket); } - bool is_data_socket(const XSocket &xsocket) const + bool is_data_socket(const FSocket &fsocket) const { - return m_preprocessed_inlined_tree_data.is_data_socket(xsocket); + return m_preprocessed_function_tree_data.is_data_socket(fsocket); } - bool is_data_group_input(const XGroupInput &group_input) const + bool is_data_group_input(const FGroupInput &group_input) const { - return m_preprocessed_inlined_tree_data.is_data_group_input(group_input); + return m_preprocessed_function_tree_data.is_data_group_input(group_input); } - void map_data_sockets(const XNode &xnode, MFBuilderNode &node); + void map_data_sockets(const FNode &fnode, MFBuilderNode &node); - void map_sockets(const XInputSocket &xsocket, MFBuilderInputSocket &socket) + void map_sockets(const FInputSocket &fsocket, MFBuilderInputSocket &socket) { - switch (m_single_socket_by_xsocket[xsocket.id()]) { + switch (m_single_socket_by_fsocket[fsocket.id()]) { case InlinedTreeMFSocketMap_UNMAPPED: { - m_single_socket_by_xsocket[xsocket.id()] = socket.id(); + m_single_socket_by_fsocket[fsocket.id()] = socket.id(); break; } case InlinedTreeMFSocketMap_MULTIMAPPED: { - BLI_assert(!m_multiple_inputs_by_xsocket.lookup(xsocket.id()).contains(socket.id())); - m_multiple_inputs_by_xsocket.add(xsocket.id(), socket.id()); + BLI_assert(!m_multiple_inputs_by_fsocket.lookup(fsocket.id()).contains(socket.id())); + m_multiple_inputs_by_fsocket.add(fsocket.id(), socket.id()); break; } default: { - uint already_inserted_id = m_single_socket_by_xsocket[xsocket.id()]; + uint already_inserted_id = m_single_socket_by_fsocket[fsocket.id()]; BLI_assert(already_inserted_id != socket.id()); - m_multiple_inputs_by_xsocket.add_multiple_new(xsocket.id(), + m_multiple_inputs_by_fsocket.add_multiple_new(fsocket.id(), {already_inserted_id, socket.id()}); - m_single_socket_by_xsocket[xsocket.id()] = InlinedTreeMFSocketMap_MULTIMAPPED; + m_single_socket_by_fsocket[fsocket.id()] = InlinedTreeMFSocketMap_MULTIMAPPED; break; } } } - void map_sockets(const XOutputSocket &xsocket, MFBuilderOutputSocket &socket) + void map_sockets(const FOutputSocket &fsocket, MFBuilderOutputSocket &socket) { - BLI_assert(m_single_socket_by_xsocket[xsocket.id()] == InlinedTreeMFSocketMap_UNMAPPED); - m_single_socket_by_xsocket[xsocket.id()] = socket.id(); + BLI_assert(m_single_socket_by_fsocket[fsocket.id()] == InlinedTreeMFSocketMap_UNMAPPED); + m_single_socket_by_fsocket[fsocket.id()] = socket.id(); } - void map_sockets(ArrayRef<const XInputSocket *> xsockets, + void map_sockets(ArrayRef<const FInputSocket *> fsockets, ArrayRef<MFBuilderInputSocket *> sockets) { - BLI_assert(xsockets.size() == sockets.size()); - for (uint i : xsockets.index_iterator()) { - this->map_sockets(*xsockets[i], *sockets[i]); + BLI_assert(fsockets.size() == sockets.size()); + for (uint i : fsockets.index_iterator()) { + this->map_sockets(*fsockets[i], *sockets[i]); } } - void map_sockets(ArrayRef<const XOutputSocket *> xsockets, + void map_sockets(ArrayRef<const FOutputSocket *> fsockets, ArrayRef<MFBuilderOutputSocket *> sockets) { - BLI_assert(xsockets.size() == sockets.size()); - for (uint i : xsockets.index_iterator()) { - this->map_sockets(*xsockets[i], *sockets[i]); + BLI_assert(fsockets.size() == sockets.size()); + for (uint i : fsockets.index_iterator()) { + this->map_sockets(*fsockets[i], *sockets[i]); } } - void map_group_input(const XGroupInput &group_input, MFBuilderOutputSocket &socket) + void map_group_input(const FGroupInput &group_input, MFBuilderOutputSocket &socket) { m_group_inputs_mapping.add_new(&group_input, &socket); } - MFBuilderOutputSocket &lookup_group_input(const XGroupInput &group_input) const + MFBuilderOutputSocket &lookup_group_input(const FGroupInput &group_input) const { return *m_group_inputs_mapping.lookup(&group_input); } - bool xsocket_is_mapped(const XSocket &xsocket) const + bool fsocket_is_mapped(const FSocket &fsocket) const { - return m_single_socket_by_xsocket[xsocket.id()] != InlinedTreeMFSocketMap_UNMAPPED; + return m_single_socket_by_fsocket[fsocket.id()] != InlinedTreeMFSocketMap_UNMAPPED; } - void assert_xnode_is_mapped_correctly(const XNode &xnode) const; - void assert_data_sockets_are_mapped_correctly(ArrayRef<const XSocket *> xsockets) const; - void assert_xsocket_is_mapped_correctly(const XSocket &xsocket) const; + void assert_fnode_is_mapped_correctly(const FNode &fnode) const; + void assert_data_sockets_are_mapped_correctly(ArrayRef<const FSocket *> fsockets) const; + void assert_fsocket_is_mapped_correctly(const FSocket &fsocket) const; - bool has_data_sockets(const XNode &xnode) const; + bool has_data_sockets(const FNode &fnode) const; - MFBuilderSocket &lookup_single_socket(const XSocket &xsocket) const + MFBuilderSocket &lookup_single_socket(const FSocket &fsocket) const { - uint mapped_id = m_single_socket_by_xsocket[xsocket.id()]; + uint mapped_id = m_single_socket_by_fsocket[fsocket.id()]; BLI_assert( !ELEM(mapped_id, InlinedTreeMFSocketMap_MULTIMAPPED, InlinedTreeMFSocketMap_UNMAPPED)); return *m_builder->sockets_by_id()[mapped_id]; } - MFBuilderOutputSocket &lookup_socket(const XOutputSocket &xsocket) const + MFBuilderOutputSocket &lookup_socket(const FOutputSocket &fsocket) const { - return this->lookup_single_socket(xsocket.as_base()).as_output(); + return this->lookup_single_socket(fsocket.as_base()).as_output(); } - Vector<MFBuilderInputSocket *> lookup_socket(const XInputSocket &xsocket) const + Vector<MFBuilderInputSocket *> lookup_socket(const FInputSocket &fsocket) const { Vector<MFBuilderInputSocket *> sockets; - switch (m_single_socket_by_xsocket[xsocket.id()]) { + switch (m_single_socket_by_fsocket[fsocket.id()]) { case InlinedTreeMFSocketMap_UNMAPPED: { break; } case InlinedTreeMFSocketMap_MULTIMAPPED: { - for (uint mapped_id : m_multiple_inputs_by_xsocket.lookup(xsocket.id())) { + for (uint mapped_id : m_multiple_inputs_by_fsocket.lookup(fsocket.id())) { sockets.append(&m_builder->sockets_by_id()[mapped_id]->as_input()); } break; } default: { - uint mapped_id = m_single_socket_by_xsocket[xsocket.id()]; + uint mapped_id = m_single_socket_by_fsocket[fsocket.id()]; sockets.append(&m_builder->sockets_by_id()[mapped_id]->as_input()); break; } @@ -255,23 +255,23 @@ class InlinedTreeMFNetworkBuilder : BLI::NonCopyable, BLI::NonMovable { const CPPType &cpp_type_by_name(StringRef name) const { - return *m_inlined_tree_mappings.cpp_type_by_type_name.lookup(name); + return *m_function_tree_mappings.cpp_type_by_type_name.lookup(name); } - const CPPType &cpp_type_from_property(const XNode &xnode, StringRefNull prop_name) const; - MFDataType data_type_from_property(const XNode &xnode, StringRefNull prop_name) const; + const CPPType &cpp_type_from_property(const FNode &fnode, StringRefNull prop_name) const; + MFDataType data_type_from_property(const FNode &fnode, StringRefNull prop_name) const; - std::unique_ptr<InlinedTreeMFNetwork> build(); + std::unique_ptr<FunctionTreeMFNetwork> build(); }; class VSocketMFNetworkBuilder { private: - InlinedTreeMFNetworkBuilder &m_network_builder; + FunctionTreeMFNetworkBuilder &m_network_builder; const VSocket &m_vsocket; MFBuilderOutputSocket *m_socket_to_build = nullptr; public: - VSocketMFNetworkBuilder(InlinedTreeMFNetworkBuilder &network_builder, const VSocket &vsocket) + VSocketMFNetworkBuilder(FunctionTreeMFNetworkBuilder &network_builder, const VSocket &vsocket) : m_network_builder(network_builder), m_vsocket(vsocket) { } @@ -292,7 +292,7 @@ class VSocketMFNetworkBuilder { return m_vsocket.rna(); } - InlinedTreeMFNetworkBuilder &network_builder() + FunctionTreeMFNetworkBuilder &network_builder() { return m_network_builder; } @@ -316,45 +316,45 @@ class VSocketMFNetworkBuilder { } }; -class VNodeMFNetworkBuilder { +class FNodeMFNetworkBuilder { private: - InlinedTreeMFNetworkBuilder &m_network_builder; - const XNode &m_xnode; + FunctionTreeMFNetworkBuilder &m_network_builder; + const FNode &m_fnode; public: - VNodeMFNetworkBuilder(InlinedTreeMFNetworkBuilder &network_builder, const XNode &xnode) - : m_network_builder(network_builder), m_xnode(xnode) + FNodeMFNetworkBuilder(FunctionTreeMFNetworkBuilder &network_builder, const FNode &fnode) + : m_network_builder(network_builder), m_fnode(fnode) { } - InlinedTreeMFNetworkBuilder &network_builder() + FunctionTreeMFNetworkBuilder &network_builder() { return m_network_builder; } - const XNode &xnode() const + const FNode &fnode() const { - return m_xnode; + return m_fnode; } PointerRNA *rna() { - return m_xnode.rna(); + return m_fnode.rna(); } const CPPType &cpp_type_from_property(StringRefNull prop_name) { - return m_network_builder.cpp_type_from_property(m_xnode, prop_name); + return m_network_builder.cpp_type_from_property(m_fnode, prop_name); } MFDataType data_type_from_property(StringRefNull prop_name) { - return m_network_builder.data_type_from_property(m_xnode, prop_name); + return m_network_builder.data_type_from_property(m_fnode, prop_name); } std::string string_from_property(StringRefNull prop_name) { - char *str_ptr = RNA_string_get_alloc(m_xnode.rna(), prop_name.data(), nullptr, 0); + char *str_ptr = RNA_string_get_alloc(m_fnode.rna(), prop_name.data(), nullptr, 0); std::string str = str_ptr; MEM_freeN(str_ptr); return str; diff --git a/source/blender/functions/intern/inlined_tree_multi_function_network/generate.cc b/source/blender/functions/intern/node_tree_multi_function_network/generate.cc index a64d7d69354..dd19a64b15a 100644 --- a/source/blender/functions/intern/inlined_tree_multi_function_network/generate.cc +++ b/source/blender/functions/intern/node_tree_multi_function_network/generate.cc @@ -1,4 +1,4 @@ -#include "FN_inlined_tree_multi_function_network_generation.h" +#include "FN_node_tree_multi_function_network_generation.h" #include "FN_multi_functions.h" #include "BLI_math_cxx.h" @@ -10,29 +10,29 @@ namespace FN { -static bool insert_nodes(InlinedTreeMFNetworkBuilder &builder, +static bool insert_nodes(FunctionTreeMFNetworkBuilder &builder, const VTreeMultiFunctionMappings &mappings) { - const InlinedNodeTree &inlined_tree = builder.inlined_tree(); + const FunctionNodeTree &function_tree = builder.function_tree(); - for (const XNode *xnode : inlined_tree.all_nodes()) { - StringRef idname = xnode->idname(); - const InsertVNodeFunction *inserter = mappings.xnode_inserters.lookup_ptr(idname); + for (const FNode *fnode : function_tree.all_nodes()) { + StringRef idname = fnode->idname(); + const InsertVNodeFunction *inserter = mappings.fnode_inserters.lookup_ptr(idname); if (inserter != nullptr) { - VNodeMFNetworkBuilder xnode_builder{builder, *xnode}; + FNodeMFNetworkBuilder fnode_builder{builder, *fnode}; - (*inserter)(xnode_builder); - builder.assert_xnode_is_mapped_correctly(*xnode); + (*inserter)(fnode_builder); + builder.assert_fnode_is_mapped_correctly(*fnode); } - else if (builder.has_data_sockets(*xnode)) { - builder.add_dummy(*xnode); + else if (builder.has_data_sockets(*fnode)) { + builder.add_dummy(*fnode); } } - for (const XGroupInput *group_input : inlined_tree.all_group_inputs()) { + for (const FGroupInput *group_input : function_tree.all_group_inputs()) { VSocketMFNetworkBuilder socket_builder{builder, group_input->vsocket()}; - const InsertVSocketFunction *inserter = mappings.xsocket_inserters.lookup_ptr( + const InsertVSocketFunction *inserter = mappings.fsocket_inserters.lookup_ptr( group_input->vsocket().idname()); if (inserter != nullptr) { (*inserter)(socket_builder); @@ -43,16 +43,16 @@ static bool insert_nodes(InlinedTreeMFNetworkBuilder &builder, return true; } -static bool insert_links(InlinedTreeMFNetworkBuilder &builder, +static bool insert_links(FunctionTreeMFNetworkBuilder &builder, const VTreeMultiFunctionMappings &mappings) { - for (const XInputSocket *to_xsocket : builder.inlined_tree().all_input_sockets()) { - if (!builder.is_data_socket(*to_xsocket)) { + for (const FInputSocket *to_fsocket : builder.function_tree().all_input_sockets()) { + if (!builder.is_data_socket(*to_fsocket)) { continue; } - ArrayRef<const XOutputSocket *> origin_sockets = to_xsocket->linked_sockets(); - ArrayRef<const XGroupInput *> origin_group_inputs = to_xsocket->linked_group_inputs(); + ArrayRef<const FOutputSocket *> origin_sockets = to_fsocket->linked_sockets(); + ArrayRef<const FGroupInput *> origin_group_inputs = to_fsocket->linked_group_inputs(); if (origin_sockets.size() + origin_group_inputs.size() != 1) { continue; } @@ -75,7 +75,7 @@ static bool insert_links(InlinedTreeMFNetworkBuilder &builder, from_idname = origin_group_inputs[0]->vsocket().idname(); } - Vector<MFBuilderInputSocket *> to_sockets = builder.lookup_socket(*to_xsocket); + Vector<MFBuilderInputSocket *> to_sockets = builder.lookup_socket(*to_fsocket); BLI_assert(to_sockets.size() >= 1); MFDataType from_type = from_socket->data_type(); @@ -83,7 +83,7 @@ static bool insert_links(InlinedTreeMFNetworkBuilder &builder, if (from_type != to_type) { const InsertImplicitConversionFunction *inserter = mappings.conversion_inserters.lookup_ptr( - {from_idname, to_xsocket->idname()}); + {from_idname, to_fsocket->idname()}); if (inserter == nullptr) { return false; } @@ -100,43 +100,43 @@ static bool insert_links(InlinedTreeMFNetworkBuilder &builder, return true; } -static bool insert_unlinked_inputs(InlinedTreeMFNetworkBuilder &builder, +static bool insert_unlinked_inputs(FunctionTreeMFNetworkBuilder &builder, const VTreeMultiFunctionMappings &mappings) { - Vector<const XInputSocket *> unlinked_data_inputs; - for (const XInputSocket *xsocket : builder.inlined_tree().all_input_sockets()) { - if (builder.is_data_socket(*xsocket)) { - if (!xsocket->is_linked()) { - unlinked_data_inputs.append(xsocket); + Vector<const FInputSocket *> unlinked_data_inputs; + for (const FInputSocket *fsocket : builder.function_tree().all_input_sockets()) { + if (builder.is_data_socket(*fsocket)) { + if (!fsocket->is_linked()) { + unlinked_data_inputs.append(fsocket); } } } - for (const XInputSocket *xsocket : unlinked_data_inputs) { - const InsertVSocketFunction *inserter = mappings.xsocket_inserters.lookup_ptr( - xsocket->idname()); + for (const FInputSocket *fsocket : unlinked_data_inputs) { + const InsertVSocketFunction *inserter = mappings.fsocket_inserters.lookup_ptr( + fsocket->idname()); if (inserter == nullptr) { return false; } - VSocketMFNetworkBuilder xsocket_builder{builder, xsocket->vsocket()}; - (*inserter)(xsocket_builder); - for (MFBuilderInputSocket *to_socket : builder.lookup_socket(*xsocket)) { - builder.add_link(xsocket_builder.built_socket(), *to_socket); + VSocketMFNetworkBuilder fsocket_builder{builder, fsocket->vsocket()}; + (*inserter)(fsocket_builder); + for (MFBuilderInputSocket *to_socket : builder.lookup_socket(*fsocket)) { + builder.add_link(fsocket_builder.built_socket(), *to_socket); } } return true; } -std::unique_ptr<InlinedTreeMFNetwork> generate_inlined_tree_multi_function_network( - const InlinedNodeTree &inlined_tree, ResourceCollector &resources) +std::unique_ptr<FunctionTreeMFNetwork> generate_node_tree_multi_function_network( + const FunctionNodeTree &function_tree, ResourceCollector &resources) { - const VTreeMultiFunctionMappings &mappings = get_inlined_tree_multi_function_mappings(); - PreprocessedVTreeMFData preprocessed_data{inlined_tree}; + const VTreeMultiFunctionMappings &mappings = get_function_tree_multi_function_mappings(); + PreprocessedVTreeMFData preprocessed_data{function_tree}; - InlinedTreeMFNetworkBuilder builder(inlined_tree, preprocessed_data, mappings, resources); + FunctionTreeMFNetworkBuilder builder(function_tree, preprocessed_data, mappings, resources); if (!insert_nodes(builder, mappings)) { BLI_assert(false); } @@ -147,11 +147,11 @@ std::unique_ptr<InlinedTreeMFNetwork> generate_inlined_tree_multi_function_netwo BLI_assert(false); } - auto inlined_tree_network = builder.build(); - return inlined_tree_network; + auto function_tree_network = builder.build(); + return function_tree_network; } -static bool cmp_group_interface_nodes(const XNode *a, const XNode *b) +static bool cmp_group_interface_nodes(const FNode *a, const FNode *b) { int a_index = RNA_int_get(a->rna(), "sort_index"); int b_index = RNA_int_get(b->rna(), "sort_index"); @@ -163,27 +163,27 @@ static bool cmp_group_interface_nodes(const XNode *a, const XNode *b) return BLI_strcasecmp(a->name().data(), b->name().data()) == -1; } -std::unique_ptr<MF_EvaluateNetwork> generate_inlined_tree_multi_function( - const InlinedNodeTree &inlined_tree, ResourceCollector &resources) +std::unique_ptr<MF_EvaluateNetwork> generate_node_tree_multi_function( + const FunctionNodeTree &function_tree, ResourceCollector &resources) { - std::unique_ptr<InlinedTreeMFNetwork> network = generate_inlined_tree_multi_function_network( - inlined_tree, resources); + std::unique_ptr<FunctionTreeMFNetwork> network = generate_node_tree_multi_function_network( + function_tree, resources); - Vector<const XNode *> input_xnodes = inlined_tree.nodes_with_idname("fn_GroupInputNode"); - Vector<const XNode *> output_xnodes = inlined_tree.nodes_with_idname("fn_GroupOutputNode"); + Vector<const FNode *> input_fnodes = function_tree.nodes_with_idname("fn_GroupInputNode"); + Vector<const FNode *> output_fnodes = function_tree.nodes_with_idname("fn_GroupOutputNode"); - std::sort(input_xnodes.begin(), input_xnodes.end(), cmp_group_interface_nodes); - std::sort(output_xnodes.begin(), output_xnodes.end(), cmp_group_interface_nodes); + std::sort(input_fnodes.begin(), input_fnodes.end(), cmp_group_interface_nodes); + std::sort(output_fnodes.begin(), output_fnodes.end(), cmp_group_interface_nodes); Vector<const MFOutputSocket *> function_inputs; Vector<const MFInputSocket *> function_outputs; - for (const XNode *xnode : input_xnodes) { - function_inputs.append(&network->lookup_dummy_socket(xnode->output(0))); + for (const FNode *fnode : input_fnodes) { + function_inputs.append(&network->lookup_dummy_socket(fnode->output(0))); } - for (const XNode *xnode : output_xnodes) { - function_outputs.append(&network->lookup_dummy_socket(xnode->input(0))); + for (const FNode *fnode : output_fnodes) { + function_outputs.append(&network->lookup_dummy_socket(fnode->input(0))); } auto function = BLI::make_unique<MF_EvaluateNetwork>(std::move(function_inputs), diff --git a/source/blender/functions/intern/inlined_tree_multi_function_network/mappings.cc b/source/blender/functions/intern/node_tree_multi_function_network/mappings.cc index 852467dfac4..c0eea08ceb6 100644 --- a/source/blender/functions/intern/inlined_tree_multi_function_network/mappings.cc +++ b/source/blender/functions/intern/node_tree_multi_function_network/mappings.cc @@ -7,11 +7,11 @@ namespace FN { -BLI_LAZY_INIT_REF(const VTreeMultiFunctionMappings, get_inlined_tree_multi_function_mappings) +BLI_LAZY_INIT_REF(const VTreeMultiFunctionMappings, get_function_tree_multi_function_mappings) { auto mappings = BLI::make_unique<VTreeMultiFunctionMappings>(); - add_inlined_tree_socket_mapping_info(*mappings); - add_inlined_tree_node_mapping_info(*mappings); + add_function_tree_socket_mapping_info(*mappings); + add_function_tree_node_mapping_info(*mappings); return mappings; } diff --git a/source/blender/functions/intern/inlined_tree_multi_function_network/mappings.h b/source/blender/functions/intern/node_tree_multi_function_network/mappings.h index 6058151e926..8a377bd9744 100644 --- a/source/blender/functions/intern/inlined_tree_multi_function_network/mappings.h +++ b/source/blender/functions/intern/node_tree_multi_function_network/mappings.h @@ -4,7 +4,7 @@ #include "BLI_string_map.h" #include "BLI_resource_collector.h" -#include "FN_inlined_tree_multi_function_network.h" +#include "FN_node_tree_multi_function_network.h" namespace FN { @@ -13,29 +13,29 @@ using BLI::ResourceCollector; using BLI::StringMap; struct VTreeMultiFunctionMappings; -class InlinedTreeMFNetworkBuilder; -class VNodeMFNetworkBuilder; +class FunctionTreeMFNetworkBuilder; +class FNodeMFNetworkBuilder; class VSocketMFNetworkBuilder; -using InsertVNodeFunction = std::function<void(VNodeMFNetworkBuilder &builder)>; +using InsertVNodeFunction = std::function<void(FNodeMFNetworkBuilder &builder)>; using InsertVSocketFunction = std::function<void(VSocketMFNetworkBuilder &builder)>; using InsertImplicitConversionFunction = std::function<std::pair<MFBuilderInputSocket *, MFBuilderOutputSocket *>( - InlinedTreeMFNetworkBuilder &builder)>; + FunctionTreeMFNetworkBuilder &builder)>; struct VTreeMultiFunctionMappings { StringMap<MFDataType> data_type_by_idname; StringMap<const CPPType *> cpp_type_by_type_name; StringMap<MFDataType> data_type_by_type_name; Map<const CPPType *, std::string> type_name_from_cpp_type; - StringMap<InsertVNodeFunction> xnode_inserters; - StringMap<InsertVSocketFunction> xsocket_inserters; + StringMap<InsertVNodeFunction> fnode_inserters; + StringMap<InsertVSocketFunction> fsocket_inserters; Map<std::pair<std::string, std::string>, InsertImplicitConversionFunction> conversion_inserters; }; -void add_inlined_tree_socket_mapping_info(VTreeMultiFunctionMappings &mappings); -void add_inlined_tree_node_mapping_info(VTreeMultiFunctionMappings &mappings); +void add_function_tree_socket_mapping_info(VTreeMultiFunctionMappings &mappings); +void add_function_tree_node_mapping_info(VTreeMultiFunctionMappings &mappings); -const VTreeMultiFunctionMappings &get_inlined_tree_multi_function_mappings(); +const VTreeMultiFunctionMappings &get_function_tree_multi_function_mappings(); } // namespace FN diff --git a/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc b/source/blender/functions/intern/node_tree_multi_function_network/mappings_nodes.cc index 32b9879d5b8..910264fe075 100644 --- a/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc +++ b/source/blender/functions/intern/node_tree_multi_function_network/mappings_nodes.cc @@ -2,7 +2,7 @@ #include "builder.h" #include "FN_multi_functions.h" -#include "FN_inlined_tree_multi_function_network_generation.h" +#include "FN_node_tree_multi_function_network_generation.h" #include "BLI_math_cxx.h" @@ -11,93 +11,93 @@ namespace FN { using BLI::float3; -static void INSERT_combine_color(VNodeMFNetworkBuilder &builder) +static void INSERT_combine_color(FNodeMFNetworkBuilder &builder) { builder.set_vectorized_constructed_matching_fn<MF_CombineColor>( {"use_list__red", "use_list__green", "use_list__blue", "use_list__alpha"}); } -static void INSERT_separate_color(VNodeMFNetworkBuilder &builder) +static void INSERT_separate_color(FNodeMFNetworkBuilder &builder) { builder.set_vectorized_constructed_matching_fn<MF_SeparateColor>({"use_list__color"}); } -static void INSERT_combine_vector(VNodeMFNetworkBuilder &builder) +static void INSERT_combine_vector(FNodeMFNetworkBuilder &builder) { builder.set_vectorized_constructed_matching_fn<MF_CombineVector>( {"use_list__x", "use_list__y", "use_list__z"}); } -static void INSERT_separate_vector(VNodeMFNetworkBuilder &builder) +static void INSERT_separate_vector(FNodeMFNetworkBuilder &builder) { builder.set_vectorized_constructed_matching_fn<MF_SeparateVector>({"use_list__vector"}); } -static void INSERT_vector_from_value(VNodeMFNetworkBuilder &builder) +static void INSERT_vector_from_value(FNodeMFNetworkBuilder &builder) { builder.set_vectorized_constructed_matching_fn<MF_VectorFromValue>({"use_list__value"}); } -static void INSERT_list_length(VNodeMFNetworkBuilder &builder) +static void INSERT_list_length(FNodeMFNetworkBuilder &builder) { const CPPType &type = builder.cpp_type_from_property("active_type"); builder.set_constructed_matching_fn<MF_ListLength>(type); } -static void INSERT_get_list_element(VNodeMFNetworkBuilder &builder) +static void INSERT_get_list_element(FNodeMFNetworkBuilder &builder) { const CPPType &type = builder.cpp_type_from_property("active_type"); builder.set_constructed_matching_fn<MF_GetListElement>(type); } -static void INSERT_get_list_elements(VNodeMFNetworkBuilder &builder) +static void INSERT_get_list_elements(FNodeMFNetworkBuilder &builder) { const CPPType &type = builder.cpp_type_from_property("active_type"); builder.set_constructed_matching_fn<MF_GetListElements>(type); } -static void INSERT_pack_list(VNodeMFNetworkBuilder &builder) +static void INSERT_pack_list(FNodeMFNetworkBuilder &builder) { const CPPType &type = builder.cpp_type_from_property("active_type"); Vector<bool> list_states = builder.get_list_base_variadic_states("variadic"); builder.set_constructed_matching_fn<MF_PackList>(type, list_states); } -static void INSERT_object_location(VNodeMFNetworkBuilder &builder) +static void INSERT_object_location(FNodeMFNetworkBuilder &builder) { builder.set_constructed_matching_fn<MF_ObjectWorldLocation>(); } -static void INSERT_object_mesh_info(VNodeMFNetworkBuilder &builder) +static void INSERT_object_mesh_info(FNodeMFNetworkBuilder &builder) { builder.set_constructed_matching_fn<MF_ObjectVertexPositions>(); } -static void INSERT_get_position_on_surface(VNodeMFNetworkBuilder &builder) +static void INSERT_get_position_on_surface(FNodeMFNetworkBuilder &builder) { builder.set_vectorized_constructed_matching_fn<MF_GetPositionOnSurface>( {"use_list__surface_hook"}); } -static void INSERT_get_normal_on_surface(VNodeMFNetworkBuilder &builder) +static void INSERT_get_normal_on_surface(FNodeMFNetworkBuilder &builder) { builder.set_vectorized_constructed_matching_fn<MF_GetNormalOnSurface>( {"use_list__surface_hook"}); } -static void INSERT_get_weight_on_surface(VNodeMFNetworkBuilder &builder) +static void INSERT_get_weight_on_surface(FNodeMFNetworkBuilder &builder) { builder.set_vectorized_constructed_matching_fn<MF_GetWeightOnSurface>( {"use_list__surface_hook", "use_list__vertex_group_name"}); } -static void INSERT_get_image_color_on_surface(VNodeMFNetworkBuilder &builder) +static void INSERT_get_image_color_on_surface(FNodeMFNetworkBuilder &builder) { builder.set_vectorized_constructed_matching_fn<MF_GetImageColorOnSurface>( {"use_list__surface_hook", "use_list__image"}); } -static void INSERT_switch(VNodeMFNetworkBuilder &builder) +static void INSERT_switch(FNodeMFNetworkBuilder &builder) { MFDataType type = builder.data_type_from_property("data_type"); switch (type.category()) { @@ -112,7 +112,7 @@ static void INSERT_switch(VNodeMFNetworkBuilder &builder) } } -static void INSERT_select(VNodeMFNetworkBuilder &builder) +static void INSERT_select(FNodeMFNetworkBuilder &builder) { MFDataType type = builder.data_type_from_property("data_type"); uint inputs = RNA_collection_length(builder.rna(), "input_items"); @@ -128,17 +128,17 @@ static void INSERT_select(VNodeMFNetworkBuilder &builder) } } -static void INSERT_text_length(VNodeMFNetworkBuilder &builder) +static void INSERT_text_length(FNodeMFNetworkBuilder &builder) { builder.set_constructed_matching_fn<MF_TextLength>(); } -static void INSERT_vertex_info(VNodeMFNetworkBuilder &builder) +static void INSERT_vertex_info(FNodeMFNetworkBuilder &builder) { builder.set_constructed_matching_fn<MF_ContextVertexPosition>(); } -static void INSERT_float_range(VNodeMFNetworkBuilder &builder) +static void INSERT_float_range(FNodeMFNetworkBuilder &builder) { int mode = RNA_enum_get(builder.rna(), "mode"); switch (mode) { @@ -155,7 +155,7 @@ static void INSERT_float_range(VNodeMFNetworkBuilder &builder) } } -static void INSERT_time_info(VNodeMFNetworkBuilder &builder) +static void INSERT_time_info(FNodeMFNetworkBuilder &builder) { builder.set_constructed_matching_fn<MF_ContextCurrentFrame>(); } @@ -180,12 +180,12 @@ vectorize_function_1in_1out(FuncT func) } template<typename InT, typename OutT, typename FuncT> -static void build_math_fn_1in_1out(VNodeMFNetworkBuilder &builder, FuncT func) +static void build_math_fn_1in_1out(FNodeMFNetworkBuilder &builder, FuncT func) { auto fn = vectorize_function_1in_1out<InT, OutT>(func); builder.set_vectorized_constructed_matching_fn<MF_Custom_In1_Out1<InT, OutT>>( - {"use_list"}, builder.xnode().name(), fn); + {"use_list"}, builder.fnode().name(), fn); } template<typename InT1, typename InT2, typename OutT, typename FuncT> @@ -226,15 +226,15 @@ vectorize_function_2in_1out(FuncT func) } template<typename InT1, typename InT2, typename OutT, typename FuncT> -static void build_math_fn_in2_out1(VNodeMFNetworkBuilder &builder, FuncT func) +static void build_math_fn_in2_out1(FNodeMFNetworkBuilder &builder, FuncT func) { auto fn = vectorize_function_2in_1out<InT1, InT2, OutT>(func); builder.set_vectorized_constructed_matching_fn<MF_Custom_In2_Out1<InT1, InT2, OutT>>( - {"use_list__a", "use_list__b"}, builder.xnode().name(), fn); + {"use_list__a", "use_list__b"}, builder.fnode().name(), fn); } template<typename T, typename FuncT> -static void build_variadic_math_fn(VNodeMFNetworkBuilder &builder, FuncT func, T default_value) +static void build_variadic_math_fn(FNodeMFNetworkBuilder &builder, FuncT func, T default_value) { auto fn = vectorize_function_2in_1out<T, T, T>(func); @@ -244,7 +244,7 @@ static void build_variadic_math_fn(VNodeMFNetworkBuilder &builder, FuncT func, T } else { const MultiFunction &base_fn = builder.construct_fn<MF_VariadicMath<T>>( - builder.xnode().name(), list_states.size(), fn); + builder.fnode().name(), list_states.size(), fn); if (list_states.contains(true)) { builder.set_constructed_matching_fn<MF_SimpleVectorize>(base_fn, list_states); } @@ -254,165 +254,165 @@ static void build_variadic_math_fn(VNodeMFNetworkBuilder &builder, FuncT func, T } } -static void INSERT_add_floats(VNodeMFNetworkBuilder &builder) +static void INSERT_add_floats(FNodeMFNetworkBuilder &builder) { build_variadic_math_fn( builder, [](float a, float b) -> float { return a + b; }, 0.0f); } -static void INSERT_multiply_floats(VNodeMFNetworkBuilder &builder) +static void INSERT_multiply_floats(FNodeMFNetworkBuilder &builder) { build_variadic_math_fn( builder, [](float a, float b) -> float { return a * b; }, 1.0f); } -static void INSERT_minimum_floats(VNodeMFNetworkBuilder &builder) +static void INSERT_minimum_floats(FNodeMFNetworkBuilder &builder) { build_variadic_math_fn( builder, [](float a, float b) -> float { return std::min(a, b); }, 0.0f); } -static void INSERT_maximum_floats(VNodeMFNetworkBuilder &builder) +static void INSERT_maximum_floats(FNodeMFNetworkBuilder &builder) { build_variadic_math_fn( builder, [](float a, float b) -> float { return std::max(a, b); }, 0.0f); } -static void INSERT_subtract_floats(VNodeMFNetworkBuilder &builder) +static void INSERT_subtract_floats(FNodeMFNetworkBuilder &builder) { build_math_fn_in2_out1<float, float, float>(builder, [](float a, float b) -> float { return a - b; }); } -static void INSERT_divide_floats(VNodeMFNetworkBuilder &builder) +static void INSERT_divide_floats(FNodeMFNetworkBuilder &builder) { build_math_fn_in2_out1<float, float, float>( builder, [](float a, float b) -> float { return (b != 0.0f) ? a / b : 0.0f; }); } -static void INSERT_power_floats(VNodeMFNetworkBuilder &builder) +static void INSERT_power_floats(FNodeMFNetworkBuilder &builder) { build_math_fn_in2_out1<float, float, float>(builder, [](float a, float b) -> float { return (a >= 0.0f) ? (float)std::pow(a, b) : 0.0f; }); } -static void INSERT_sqrt_float(VNodeMFNetworkBuilder &builder) +static void INSERT_sqrt_float(FNodeMFNetworkBuilder &builder) { build_math_fn_1in_1out<float, float>( builder, [](float a) -> float { return (a >= 0.0f) ? (float)std::sqrt(a) : 0.0f; }); } -static void INSERT_abs_float(VNodeMFNetworkBuilder &builder) +static void INSERT_abs_float(FNodeMFNetworkBuilder &builder) { build_math_fn_1in_1out<float, float>(builder, [](float a) -> float { return std::abs(a); }); } -static void INSERT_sine_float(VNodeMFNetworkBuilder &builder) +static void INSERT_sine_float(FNodeMFNetworkBuilder &builder) { build_math_fn_1in_1out<float, float>(builder, [](float a) -> float { return std::sin(a); }); } -static void INSERT_cosine_float(VNodeMFNetworkBuilder &builder) +static void INSERT_cosine_float(FNodeMFNetworkBuilder &builder) { build_math_fn_1in_1out<float, float>(builder, [](float a) -> float { return std::cos(a); }); } -static void INSERT_add_vectors(VNodeMFNetworkBuilder &builder) +static void INSERT_add_vectors(FNodeMFNetworkBuilder &builder) { build_variadic_math_fn( builder, [](float3 a, float3 b) -> float3 { return a + b; }, float3(0, 0, 0)); } -static void INSERT_multiply_vectors(VNodeMFNetworkBuilder &builder) +static void INSERT_multiply_vectors(FNodeMFNetworkBuilder &builder) { build_variadic_math_fn( builder, [](float3 a, float3 b) -> float3 { return a * b; }, float3(1, 1, 1)); } -static void INSERT_subtract_vectors(VNodeMFNetworkBuilder &builder) +static void INSERT_subtract_vectors(FNodeMFNetworkBuilder &builder) { build_math_fn_in2_out1<float3, float3, float3>( builder, [](float3 a, float3 b) -> float3 { return a - b; }); } -static void INSERT_divide_vectors(VNodeMFNetworkBuilder &builder) +static void INSERT_divide_vectors(FNodeMFNetworkBuilder &builder) { build_math_fn_in2_out1<float3, float3, float3>(builder, float3::safe_divide); } -static void INSERT_vector_cross_product(VNodeMFNetworkBuilder &builder) +static void INSERT_vector_cross_product(FNodeMFNetworkBuilder &builder) { build_math_fn_in2_out1<float3, float3, float3>(builder, float3::cross_high_precision); } -static void INSERT_reflect_vector(VNodeMFNetworkBuilder &builder) +static void INSERT_reflect_vector(FNodeMFNetworkBuilder &builder) { build_math_fn_in2_out1<float3, float3, float3>( builder, [](float3 a, float3 b) { return a.reflected(b.normalized()); }); } -static void INSERT_project_vector(VNodeMFNetworkBuilder &builder) +static void INSERT_project_vector(FNodeMFNetworkBuilder &builder) { build_math_fn_in2_out1<float3, float3, float3>(builder, float3::project); } -static void INSERT_vector_dot_product(VNodeMFNetworkBuilder &builder) +static void INSERT_vector_dot_product(FNodeMFNetworkBuilder &builder) { build_math_fn_in2_out1<float3, float3, float>(builder, float3::dot); } -static void INSERT_vector_distance(VNodeMFNetworkBuilder &builder) +static void INSERT_vector_distance(FNodeMFNetworkBuilder &builder) { build_math_fn_in2_out1<float3, float3, float>(builder, float3::distance); } -static void INSERT_multiply_vector_with_float(VNodeMFNetworkBuilder &builder) +static void INSERT_multiply_vector_with_float(FNodeMFNetworkBuilder &builder) { build_math_fn_in2_out1<float3, float, float3>(builder, [](float3 a, float b) { return a * b; }); } -static void INSERT_boolean_and(VNodeMFNetworkBuilder &builder) +static void INSERT_boolean_and(FNodeMFNetworkBuilder &builder) { build_variadic_math_fn( builder, [](bool a, bool b) { return a && b; }, true); } -static void INSERT_boolean_or(VNodeMFNetworkBuilder &builder) +static void INSERT_boolean_or(FNodeMFNetworkBuilder &builder) { build_variadic_math_fn( builder, [](bool a, bool b) { return a || b; }, false); } -static void INSERT_boolean_not(VNodeMFNetworkBuilder &builder) +static void INSERT_boolean_not(FNodeMFNetworkBuilder &builder) { build_math_fn_1in_1out<bool, bool>(builder, [](bool a) -> bool { return !a; }); } -static void INSERT_less_than_float(VNodeMFNetworkBuilder &builder) +static void INSERT_less_than_float(FNodeMFNetworkBuilder &builder) { build_math_fn_in2_out1<float, float, bool>(builder, [](float a, float b) -> bool { return a < b; }); } -static void INSERT_greater_than_float(VNodeMFNetworkBuilder &builder) +static void INSERT_greater_than_float(FNodeMFNetworkBuilder &builder) { build_math_fn_in2_out1<float, float, bool>(builder, [](float a, float b) -> bool { return a > b; }); } -static void INSERT_perlin_noise(VNodeMFNetworkBuilder &builder) +static void INSERT_perlin_noise(FNodeMFNetworkBuilder &builder) { builder.set_constructed_matching_fn<MF_PerlinNoise>(); } -static void INSERT_get_particle_attribute(VNodeMFNetworkBuilder &builder) +static void INSERT_get_particle_attribute(FNodeMFNetworkBuilder &builder) { const CPPType &type = builder.cpp_type_from_property("attribute_type"); builder.set_constructed_matching_fn<MF_ParticleAttribute>(type); } -static void INSERT_closest_surface_hook_on_object(VNodeMFNetworkBuilder &builder) +static void INSERT_closest_surface_hook_on_object(FNodeMFNetworkBuilder &builder) { const MultiFunction &main_fn = builder.construct_fn<MF_ClosestSurfaceHookOnObject>(); const MultiFunction &position_fn = builder.construct_fn<MF_GetPositionOnSurface>(); @@ -421,7 +421,7 @@ static void INSERT_closest_surface_hook_on_object(VNodeMFNetworkBuilder &builder const MultiFunction &vectorized_main_fn = builder.get_vectorized_function( main_fn, {"use_list__object", "use_list__position"}); - InlinedTreeMFNetworkBuilder &network_builder = builder.network_builder(); + FunctionTreeMFNetworkBuilder &network_builder = builder.network_builder(); MFBuilderFunctionNode *main_node, *position_node, *normal_node; @@ -445,37 +445,37 @@ static void INSERT_closest_surface_hook_on_object(VNodeMFNetworkBuilder &builder network_builder.add_link(main_node->output(0), position_node->input(0)); network_builder.add_link(main_node->output(0), normal_node->input(0)); - const XNode &xnode = builder.xnode(); - network_builder.map_sockets(xnode.inputs(), main_node->inputs()); - network_builder.map_sockets(xnode.output(0), main_node->output(0)); - network_builder.map_sockets(xnode.output(1), position_node->output(0)); - network_builder.map_sockets(xnode.output(2), normal_node->output(0)); + const FNode &fnode = builder.fnode(); + network_builder.map_sockets(fnode.inputs(), main_node->inputs()); + network_builder.map_sockets(fnode.output(0), main_node->output(0)); + network_builder.map_sockets(fnode.output(1), position_node->output(0)); + network_builder.map_sockets(fnode.output(2), normal_node->output(0)); } -static void INSERT_clamp_float(VNodeMFNetworkBuilder &builder) +static void INSERT_clamp_float(FNodeMFNetworkBuilder &builder) { builder.set_constructed_matching_fn<MF_Clamp>(false); } -static void INSERT_map_range(VNodeMFNetworkBuilder &builder) +static void INSERT_map_range(FNodeMFNetworkBuilder &builder) { bool clamp = RNA_boolean_get(builder.rna(), "clamp"); builder.set_constructed_matching_fn<MF_MapRange>(clamp); } -static void INSERT_random_float(VNodeMFNetworkBuilder &builder) +static void INSERT_random_float(FNodeMFNetworkBuilder &builder) { uint node_seed = (uint)RNA_int_get(builder.rna(), "node_seed"); builder.set_constructed_matching_fn<MF_RandomFloat>(node_seed); } -static void INSERT_random_floats(VNodeMFNetworkBuilder &builder) +static void INSERT_random_floats(FNodeMFNetworkBuilder &builder) { uint node_seed = (uint)RNA_int_get(builder.rna(), "node_seed"); builder.set_constructed_matching_fn<MF_RandomFloats>(node_seed); } -static void INSERT_random_vector(VNodeMFNetworkBuilder &builder) +static void INSERT_random_vector(FNodeMFNetworkBuilder &builder) { uint node_seed = (uint)RNA_int_get(builder.rna(), "node_seed"); RandomVectorMode::Enum mode = (RandomVectorMode::Enum)RNA_enum_get(builder.rna(), "mode"); @@ -483,148 +483,148 @@ static void INSERT_random_vector(VNodeMFNetworkBuilder &builder) {"use_list__factor", "use_list__seed"}, node_seed, mode); } -static void INSERT_random_vectors(VNodeMFNetworkBuilder &builder) +static void INSERT_random_vectors(FNodeMFNetworkBuilder &builder) { uint node_seed = (uint)RNA_int_get(builder.rna(), "node_seed"); RandomVectorMode::Enum mode = (RandomVectorMode::Enum)RNA_enum_get(builder.rna(), "mode"); builder.set_constructed_matching_fn<MF_RandomVectors>(node_seed, mode); } -static void INSERT_value(VNodeMFNetworkBuilder &builder) +static void INSERT_value(FNodeMFNetworkBuilder &builder) { - const XOutputSocket &xsocket = builder.xnode().output(0); - const VSocket &vsocket = xsocket.vsocket(); - InlinedTreeMFNetworkBuilder &network_builder = builder.network_builder(); + const FOutputSocket &fsocket = builder.fnode().output(0); + const VSocket &vsocket = fsocket.vsocket(); + FunctionTreeMFNetworkBuilder &network_builder = builder.network_builder(); VSocketMFNetworkBuilder socket_builder{network_builder, vsocket}; - auto &inserter = network_builder.vtree_multi_function_mappings().xsocket_inserters.lookup( + auto &inserter = network_builder.vtree_multi_function_mappings().fsocket_inserters.lookup( vsocket.idname()); inserter(socket_builder); MFBuilderOutputSocket &built_socket = socket_builder.built_socket(); - network_builder.map_sockets(xsocket, built_socket); + network_builder.map_sockets(fsocket, built_socket); } -static void INSERT_emitter_time_info(VNodeMFNetworkBuilder &builder) +static void INSERT_emitter_time_info(FNodeMFNetworkBuilder &builder) { builder.set_constructed_matching_fn<MF_EmitterTimeInfo>(); } -static void INSERT_sample_object_surface(VNodeMFNetworkBuilder &builder) +static void INSERT_sample_object_surface(FNodeMFNetworkBuilder &builder) { int value = RNA_enum_get(builder.rna(), "weight_mode"); builder.set_constructed_matching_fn<MF_SampleObjectSurface>(value == 1); } -static void INSERT_find_non_close_points(VNodeMFNetworkBuilder &builder) +static void INSERT_find_non_close_points(FNodeMFNetworkBuilder &builder) { builder.set_constructed_matching_fn<MF_FindNonClosePoints>(); } -static void INSERT_join_text_list(VNodeMFNetworkBuilder &builder) +static void INSERT_join_text_list(FNodeMFNetworkBuilder &builder) { builder.set_constructed_matching_fn<MF_JoinTextList>(); } -static void INSERT_node_instance_identifier(VNodeMFNetworkBuilder &builder) +static void INSERT_node_instance_identifier(FNodeMFNetworkBuilder &builder) { - const XNode &xnode = builder.xnode(); + const FNode &fnode = builder.fnode(); std::string identifier = ""; - for (const FN::XParentNode *parent = xnode.parent(); parent; parent = parent->parent()) { + for (const FN::FParentNode *parent = fnode.parent(); parent; parent = parent->parent()) { identifier = parent->vnode().name() + "/" + identifier; } - identifier = "/nodeid/" + identifier + xnode.name(); + identifier = "/nodeid/" + identifier + fnode.name(); std::cout << identifier << "\n"; builder.set_constructed_matching_fn<MF_ConstantValue<std::string>>(std::move(identifier)); } -static void INSERT_event_filter_end_time(VNodeMFNetworkBuilder &builder) +static void INSERT_event_filter_end_time(FNodeMFNetworkBuilder &builder) { builder.set_constructed_matching_fn<MF_EventFilterEndTime>(); } -static void INSERT_event_filter_duration(VNodeMFNetworkBuilder &builder) +static void INSERT_event_filter_duration(FNodeMFNetworkBuilder &builder) { builder.set_constructed_matching_fn<MF_EventFilterDuration>(); } -void add_inlined_tree_node_mapping_info(VTreeMultiFunctionMappings &mappings) -{ - mappings.xnode_inserters.add_new("fn_CombineColorNode", INSERT_combine_color); - mappings.xnode_inserters.add_new("fn_SeparateColorNode", INSERT_separate_color); - mappings.xnode_inserters.add_new("fn_CombineVectorNode", INSERT_combine_vector); - mappings.xnode_inserters.add_new("fn_SeparateVectorNode", INSERT_separate_vector); - mappings.xnode_inserters.add_new("fn_VectorFromValueNode", INSERT_vector_from_value); - mappings.xnode_inserters.add_new("fn_SwitchNode", INSERT_switch); - mappings.xnode_inserters.add_new("fn_SelectNode", INSERT_select); - mappings.xnode_inserters.add_new("fn_ListLengthNode", INSERT_list_length); - mappings.xnode_inserters.add_new("fn_PackListNode", INSERT_pack_list); - mappings.xnode_inserters.add_new("fn_GetListElementNode", INSERT_get_list_element); - mappings.xnode_inserters.add_new("fn_GetListElementsNode", INSERT_get_list_elements); - mappings.xnode_inserters.add_new("fn_ObjectTransformsNode", INSERT_object_location); - mappings.xnode_inserters.add_new("fn_ObjectMeshNode", INSERT_object_mesh_info); - mappings.xnode_inserters.add_new("fn_GetPositionOnSurfaceNode", INSERT_get_position_on_surface); - mappings.xnode_inserters.add_new("fn_GetNormalOnSurfaceNode", INSERT_get_normal_on_surface); - mappings.xnode_inserters.add_new("fn_GetWeightOnSurfaceNode", INSERT_get_weight_on_surface); - mappings.xnode_inserters.add_new("fn_GetImageColorOnSurfaceNode", +void add_function_tree_node_mapping_info(VTreeMultiFunctionMappings &mappings) +{ + mappings.fnode_inserters.add_new("fn_CombineColorNode", INSERT_combine_color); + mappings.fnode_inserters.add_new("fn_SeparateColorNode", INSERT_separate_color); + mappings.fnode_inserters.add_new("fn_CombineVectorNode", INSERT_combine_vector); + mappings.fnode_inserters.add_new("fn_SeparateVectorNode", INSERT_separate_vector); + mappings.fnode_inserters.add_new("fn_VectorFromValueNode", INSERT_vector_from_value); + mappings.fnode_inserters.add_new("fn_SwitchNode", INSERT_switch); + mappings.fnode_inserters.add_new("fn_SelectNode", INSERT_select); + mappings.fnode_inserters.add_new("fn_ListLengthNode", INSERT_list_length); + mappings.fnode_inserters.add_new("fn_PackListNode", INSERT_pack_list); + mappings.fnode_inserters.add_new("fn_GetListElementNode", INSERT_get_list_element); + mappings.fnode_inserters.add_new("fn_GetListElementsNode", INSERT_get_list_elements); + mappings.fnode_inserters.add_new("fn_ObjectTransformsNode", INSERT_object_location); + mappings.fnode_inserters.add_new("fn_ObjectMeshNode", INSERT_object_mesh_info); + mappings.fnode_inserters.add_new("fn_GetPositionOnSurfaceNode", INSERT_get_position_on_surface); + mappings.fnode_inserters.add_new("fn_GetNormalOnSurfaceNode", INSERT_get_normal_on_surface); + mappings.fnode_inserters.add_new("fn_GetWeightOnSurfaceNode", INSERT_get_weight_on_surface); + mappings.fnode_inserters.add_new("fn_GetImageColorOnSurfaceNode", INSERT_get_image_color_on_surface); - mappings.xnode_inserters.add_new("fn_TextLengthNode", INSERT_text_length); - mappings.xnode_inserters.add_new("fn_VertexInfoNode", INSERT_vertex_info); - mappings.xnode_inserters.add_new("fn_FloatRangeNode", INSERT_float_range); - mappings.xnode_inserters.add_new("fn_TimeInfoNode", INSERT_time_info); - mappings.xnode_inserters.add_new("fn_LessThanFloatNode", INSERT_less_than_float); - mappings.xnode_inserters.add_new("fn_GreaterThanFloatNode", INSERT_greater_than_float); - mappings.xnode_inserters.add_new("fn_PerlinNoiseNode", INSERT_perlin_noise); - mappings.xnode_inserters.add_new("fn_GetParticleAttributeNode", INSERT_get_particle_attribute); - mappings.xnode_inserters.add_new("fn_ClosestLocationOnObjectNode", + mappings.fnode_inserters.add_new("fn_TextLengthNode", INSERT_text_length); + mappings.fnode_inserters.add_new("fn_VertexInfoNode", INSERT_vertex_info); + mappings.fnode_inserters.add_new("fn_FloatRangeNode", INSERT_float_range); + mappings.fnode_inserters.add_new("fn_TimeInfoNode", INSERT_time_info); + mappings.fnode_inserters.add_new("fn_LessThanFloatNode", INSERT_less_than_float); + mappings.fnode_inserters.add_new("fn_GreaterThanFloatNode", INSERT_greater_than_float); + mappings.fnode_inserters.add_new("fn_PerlinNoiseNode", INSERT_perlin_noise); + mappings.fnode_inserters.add_new("fn_GetParticleAttributeNode", INSERT_get_particle_attribute); + mappings.fnode_inserters.add_new("fn_ClosestLocationOnObjectNode", INSERT_closest_surface_hook_on_object); - mappings.xnode_inserters.add_new("fn_MapRangeNode", INSERT_map_range); - mappings.xnode_inserters.add_new("fn_FloatClampNode", INSERT_clamp_float); - mappings.xnode_inserters.add_new("fn_RandomFloatNode", INSERT_random_float); - mappings.xnode_inserters.add_new("fn_RandomFloatsNode", INSERT_random_floats); - mappings.xnode_inserters.add_new("fn_RandomVectorNode", INSERT_random_vector); - mappings.xnode_inserters.add_new("fn_RandomVectorsNode", INSERT_random_vectors); - mappings.xnode_inserters.add_new("fn_ValueNode", INSERT_value); - mappings.xnode_inserters.add_new("fn_EmitterTimeInfoNode", INSERT_emitter_time_info); - mappings.xnode_inserters.add_new("fn_SampleObjectSurfaceNode", INSERT_sample_object_surface); - mappings.xnode_inserters.add_new("fn_FindNonClosePointsNode", INSERT_find_non_close_points); - - mappings.xnode_inserters.add_new("fn_AddFloatsNode", INSERT_add_floats); - mappings.xnode_inserters.add_new("fn_MultiplyFloatsNode", INSERT_multiply_floats); - mappings.xnode_inserters.add_new("fn_MinimumFloatsNode", INSERT_minimum_floats); - mappings.xnode_inserters.add_new("fn_MaximumFloatsNode", INSERT_maximum_floats); - - mappings.xnode_inserters.add_new("fn_SubtractFloatsNode", INSERT_subtract_floats); - mappings.xnode_inserters.add_new("fn_DivideFloatsNode", INSERT_divide_floats); - mappings.xnode_inserters.add_new("fn_PowerFloatsNode", INSERT_power_floats); - - mappings.xnode_inserters.add_new("fn_SqrtFloatNode", INSERT_sqrt_float); - mappings.xnode_inserters.add_new("fn_AbsoluteFloatNode", INSERT_abs_float); - mappings.xnode_inserters.add_new("fn_SineFloatNode", INSERT_sine_float); - mappings.xnode_inserters.add_new("fn_CosineFloatNode", INSERT_cosine_float); - - mappings.xnode_inserters.add_new("fn_AddVectorsNode", INSERT_add_vectors); - mappings.xnode_inserters.add_new("fn_SubtractVectorsNode", INSERT_subtract_vectors); - mappings.xnode_inserters.add_new("fn_MultiplyVectorsNode", INSERT_multiply_vectors); - mappings.xnode_inserters.add_new("fn_DivideVectorsNode", INSERT_divide_vectors); - - mappings.xnode_inserters.add_new("fn_VectorCrossProductNode", INSERT_vector_cross_product); - mappings.xnode_inserters.add_new("fn_ReflectVectorNode", INSERT_reflect_vector); - mappings.xnode_inserters.add_new("fn_ProjectVectorNode", INSERT_project_vector); - mappings.xnode_inserters.add_new("fn_VectorDotProductNode", INSERT_vector_dot_product); - mappings.xnode_inserters.add_new("fn_VectorDistanceNode", INSERT_vector_distance); - mappings.xnode_inserters.add_new("fn_MultiplyVectorWithFloatNode", + mappings.fnode_inserters.add_new("fn_MapRangeNode", INSERT_map_range); + mappings.fnode_inserters.add_new("fn_FloatClampNode", INSERT_clamp_float); + mappings.fnode_inserters.add_new("fn_RandomFloatNode", INSERT_random_float); + mappings.fnode_inserters.add_new("fn_RandomFloatsNode", INSERT_random_floats); + mappings.fnode_inserters.add_new("fn_RandomVectorNode", INSERT_random_vector); + mappings.fnode_inserters.add_new("fn_RandomVectorsNode", INSERT_random_vectors); + mappings.fnode_inserters.add_new("fn_ValueNode", INSERT_value); + mappings.fnode_inserters.add_new("fn_EmitterTimeInfoNode", INSERT_emitter_time_info); + mappings.fnode_inserters.add_new("fn_SampleObjectSurfaceNode", INSERT_sample_object_surface); + mappings.fnode_inserters.add_new("fn_FindNonClosePointsNode", INSERT_find_non_close_points); + + mappings.fnode_inserters.add_new("fn_AddFloatsNode", INSERT_add_floats); + mappings.fnode_inserters.add_new("fn_MultiplyFloatsNode", INSERT_multiply_floats); + mappings.fnode_inserters.add_new("fn_MinimumFloatsNode", INSERT_minimum_floats); + mappings.fnode_inserters.add_new("fn_MaximumFloatsNode", INSERT_maximum_floats); + + mappings.fnode_inserters.add_new("fn_SubtractFloatsNode", INSERT_subtract_floats); + mappings.fnode_inserters.add_new("fn_DivideFloatsNode", INSERT_divide_floats); + mappings.fnode_inserters.add_new("fn_PowerFloatsNode", INSERT_power_floats); + + mappings.fnode_inserters.add_new("fn_SqrtFloatNode", INSERT_sqrt_float); + mappings.fnode_inserters.add_new("fn_AbsoluteFloatNode", INSERT_abs_float); + mappings.fnode_inserters.add_new("fn_SineFloatNode", INSERT_sine_float); + mappings.fnode_inserters.add_new("fn_CosineFloatNode", INSERT_cosine_float); + + mappings.fnode_inserters.add_new("fn_AddVectorsNode", INSERT_add_vectors); + mappings.fnode_inserters.add_new("fn_SubtractVectorsNode", INSERT_subtract_vectors); + mappings.fnode_inserters.add_new("fn_MultiplyVectorsNode", INSERT_multiply_vectors); + mappings.fnode_inserters.add_new("fn_DivideVectorsNode", INSERT_divide_vectors); + + mappings.fnode_inserters.add_new("fn_VectorCrossProductNode", INSERT_vector_cross_product); + mappings.fnode_inserters.add_new("fn_ReflectVectorNode", INSERT_reflect_vector); + mappings.fnode_inserters.add_new("fn_ProjectVectorNode", INSERT_project_vector); + mappings.fnode_inserters.add_new("fn_VectorDotProductNode", INSERT_vector_dot_product); + mappings.fnode_inserters.add_new("fn_VectorDistanceNode", INSERT_vector_distance); + mappings.fnode_inserters.add_new("fn_MultiplyVectorWithFloatNode", INSERT_multiply_vector_with_float); - mappings.xnode_inserters.add_new("fn_BooleanAndNode", INSERT_boolean_and); - mappings.xnode_inserters.add_new("fn_BooleanOrNode", INSERT_boolean_or); - mappings.xnode_inserters.add_new("fn_BooleanNotNode", INSERT_boolean_not); + mappings.fnode_inserters.add_new("fn_BooleanAndNode", INSERT_boolean_and); + mappings.fnode_inserters.add_new("fn_BooleanOrNode", INSERT_boolean_or); + mappings.fnode_inserters.add_new("fn_BooleanNotNode", INSERT_boolean_not); - mappings.xnode_inserters.add_new("fn_JoinTextListNode", INSERT_join_text_list); - mappings.xnode_inserters.add_new("fn_NodeInstanceIdentifierNode", + mappings.fnode_inserters.add_new("fn_JoinTextListNode", INSERT_join_text_list); + mappings.fnode_inserters.add_new("fn_NodeInstanceIdentifierNode", INSERT_node_instance_identifier); - mappings.xnode_inserters.add_new("fn_EventFilterEndTimeNode", INSERT_event_filter_end_time); - mappings.xnode_inserters.add_new("fn_EventFilterDurationNode", INSERT_event_filter_duration); + mappings.fnode_inserters.add_new("fn_EventFilterEndTimeNode", INSERT_event_filter_end_time); + mappings.fnode_inserters.add_new("fn_EventFilterDurationNode", INSERT_event_filter_duration); } }; // namespace FN diff --git a/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_sockets.cc b/source/blender/functions/intern/node_tree_multi_function_network/mappings_sockets.cc index 22a70899d1c..11c4a1cd225 100644 --- a/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_sockets.cc +++ b/source/blender/functions/intern/node_tree_multi_function_network/mappings_sockets.cc @@ -90,7 +90,7 @@ template<typename T> static void INSERT_empty_list_socket(VSocketMFNetworkBuilde template<typename FromT, typename ToT> static std::pair<MFBuilderInputSocket *, MFBuilderOutputSocket *> INSERT_convert( - InlinedTreeMFNetworkBuilder &builder) + FunctionTreeMFNetworkBuilder &builder) { const MultiFunction &fn = builder.construct_fn<FN::MF_Convert<FromT, ToT>>(); MFBuilderFunctionNode &node = builder.add_function(fn); @@ -99,7 +99,7 @@ static std::pair<MFBuilderInputSocket *, MFBuilderOutputSocket *> INSERT_convert template<typename FromT, typename ToT> static std::pair<MFBuilderInputSocket *, MFBuilderOutputSocket *> INSERT_convert_list( - InlinedTreeMFNetworkBuilder &builder) + FunctionTreeMFNetworkBuilder &builder) { const MultiFunction &fn = builder.construct_fn<FN::MF_ConvertList<FromT, ToT>>(); MFBuilderFunctionNode &node = builder.add_function(fn); @@ -108,7 +108,7 @@ static std::pair<MFBuilderInputSocket *, MFBuilderOutputSocket *> INSERT_convert template<typename T> static std::pair<MFBuilderInputSocket *, MFBuilderOutputSocket *> INSERT_element_to_list( - InlinedTreeMFNetworkBuilder &builder) + FunctionTreeMFNetworkBuilder &builder) { const MultiFunction &fn = builder.construct_fn<FN::MF_SingleElementList<T>>(); MFBuilderFunctionNode &node = builder.add_function(fn); @@ -130,8 +130,8 @@ static void add_basic_type(VTreeMultiFunctionMappings &mappings, mappings.data_type_by_idname.add_new(list_idname, MFDataType::ForVector<T>()); mappings.data_type_by_type_name.add_new(base_name, MFDataType::ForSingle<T>()); mappings.data_type_by_type_name.add_new(list_name, MFDataType::ForVector<T>()); - mappings.xsocket_inserters.add_new(base_idname, base_inserter); - mappings.xsocket_inserters.add_new(list_idname, INSERT_empty_list_socket<T>); + mappings.fsocket_inserters.add_new(base_idname, base_inserter); + mappings.fsocket_inserters.add_new(list_idname, INSERT_empty_list_socket<T>); mappings.conversion_inserters.add_new({base_idname, list_idname}, INSERT_element_to_list<T>); mappings.type_name_from_cpp_type.add_new(&CPP_TYPE<T>(), base_name); } @@ -169,7 +169,7 @@ static void add_bidirectional_implicit_conversion(VTreeMultiFunctionMappings &ma add_implicit_conversion<T2, T1>(mappings); } -void add_inlined_tree_socket_mapping_info(VTreeMultiFunctionMappings &mappings) +void add_function_tree_socket_mapping_info(VTreeMultiFunctionMappings &mappings) { add_basic_type<float>(mappings, "Float", INSERT_float_socket); add_basic_type<BLI::float3>(mappings, "Vector", INSERT_vector_socket); diff --git a/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc b/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc index 03de3caa92c..3be31a74ef7 100644 --- a/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc +++ b/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc @@ -1,6 +1,6 @@ #include "DNA_modifier_types.h" -#include "FN_inlined_tree_multi_function_network_generation.h" +#include "FN_node_tree_multi_function_network_generation.h" #include "FN_multi_functions.h" #include "FN_multi_function_common_contexts.h" #include "FN_multi_function_dependencies.h" @@ -18,7 +18,7 @@ using BLI::float3; using BLI::IndexRange; using BLI::LargeScopedVector; using BLI::Vector; -using FN::InlinedNodeTree; +using FN::FunctionNodeTree; using FN::MFContext; using FN::MFContextBuilder; using FN::MFInputSocket; @@ -46,10 +46,10 @@ void MOD_functiondeform_do(FunctionDeformModifierData *fdmd, bNodeTree *btree = (bNodeTree *)DEG_get_original_id((ID *)fdmd->function_tree); FN::BTreeVTreeMap vtrees; - InlinedNodeTree inlined_tree(btree, vtrees); + FunctionNodeTree function_tree(btree, vtrees); BLI::ResourceCollector resources; - auto function = FN::generate_inlined_tree_multi_function(inlined_tree, resources); + auto function = FN::generate_node_tree_multi_function(function_tree, resources); MFParamsBuilder params_builder(*function, numVerts); params_builder.add_readonly_single_input(ArrayRef<float3>((float3 *)vertexCos, numVerts)); @@ -68,7 +68,7 @@ void MOD_functiondeform_do(FunctionDeformModifierData *fdmd, vertex_positions_context.positions = ArrayRef<float3>((float3 *)vertexCos, numVerts); BKE::IDHandleLookup id_handle_lookup; - FN::add_ids_used_by_nodes(id_handle_lookup, inlined_tree); + FN::add_ids_used_by_nodes(id_handle_lookup, function_tree); BKE::IDDataCache id_data_cache; diff --git a/source/blender/modifiers/intern/MOD_functionpoints_cxx.cc b/source/blender/modifiers/intern/MOD_functionpoints_cxx.cc index 03c53bb5866..8ea620b5194 100644 --- a/source/blender/modifiers/intern/MOD_functionpoints_cxx.cc +++ b/source/blender/modifiers/intern/MOD_functionpoints_cxx.cc @@ -8,7 +8,7 @@ #include "BLI_math.h" -#include "FN_inlined_tree_multi_function_network_generation.h" +#include "FN_node_tree_multi_function_network_generation.h" #include "FN_multi_functions.h" #include "FN_multi_function_common_contexts.h" #include "FN_multi_function_dependencies.h" @@ -21,7 +21,7 @@ using BLI::ArrayRef; using BLI::float3; using BLI::IndexRange; using BLI::Vector; -using FN::InlinedNodeTree; +using FN::FunctionNodeTree; using FN::MFContext; using FN::MFInputSocket; using FN::MFOutputSocket; @@ -42,10 +42,10 @@ Mesh *MOD_functionpoints_do(FunctionPointsModifierData *fpmd, bNodeTree *btree = (bNodeTree *)DEG_get_original_id((ID *)fpmd->function_tree); FN::BTreeVTreeMap vtrees; - InlinedNodeTree inlined_tree(btree, vtrees); + FunctionNodeTree function_tree(btree, vtrees); BLI::ResourceCollector resources; - auto function = FN::generate_inlined_tree_multi_function(inlined_tree, resources); + auto function = FN::generate_node_tree_multi_function(function_tree, resources); MFParamsBuilder params_builder(*function, 1); params_builder.add_readonly_single_input(&fpmd->control1); @@ -58,7 +58,7 @@ Mesh *MOD_functionpoints_do(FunctionPointsModifierData *fpmd, time_context.time = DEG_get_ctime(ctx->depsgraph); BKE::IDHandleLookup id_handle_lookup; - FN::add_ids_used_by_nodes(id_handle_lookup, inlined_tree); + FN::add_ids_used_by_nodes(id_handle_lookup, function_tree); BKE::IDDataCache id_data_cache; diff --git a/source/blender/simulations/bparticles/node_frontend.cpp b/source/blender/simulations/bparticles/node_frontend.cpp index 71c3761e700..0ef45748d26 100644 --- a/source/blender/simulations/bparticles/node_frontend.cpp +++ b/source/blender/simulations/bparticles/node_frontend.cpp @@ -13,7 +13,7 @@ #include "FN_node_tree.h" #include "FN_multi_functions.h" #include "FN_generic_tuple.h" -#include "FN_inlined_tree_multi_function_network_generation.h" +#include "FN_node_tree_multi_function_network_generation.h" #include "FN_multi_function_common_contexts.h" #include "FN_multi_function_dependencies.h" @@ -37,25 +37,25 @@ using BLI::ScopedVector; using BLI::Set; using FN::AttributesInfoBuilder; using FN::CPPType; -using FN::InlinedTreeMFNetwork; +using FN::FGroupInput; +using FN::FInputSocket; +using FN::FNode; +using FN::FOutputSocket; +using FN::FSocket; +using FN::FunctionTreeMFNetwork; using FN::MFInputSocket; using FN::MFOutputSocket; using FN::MultiFunction; using FN::NamedGenericTupleRef; -using FN::XGroupInput; -using FN::XInputSocket; -using FN::XNode; -using FN::XOutputSocket; -using FN::XSocket; static StringRef particle_system_idname = "fn_ParticleSystemNode"; static StringRef combine_influences_idname = "fn_CombineInfluencesNode"; -class InlinedTreeData; +class FunctionTreeData; class InfluencesCollector; -class XSocketActionBuilder; +class FSocketActionBuilder; -using ActionParserCallback = std::function<void(XSocketActionBuilder &builder)>; +using ActionParserCallback = std::function<void(FSocketActionBuilder &builder)>; StringMap<ActionParserCallback> &get_action_parsers(); class InfluencesCollector { @@ -67,34 +67,34 @@ class InfluencesCollector { StringMap<AttributesInfoBuilder *> m_attributes; }; -class InlinedTreeData { +class FunctionTreeData { private: /* Keep this at the beginning, so that it is destructed last. */ ResourceCollector m_resources; - InlinedTreeMFNetwork &m_inlined_tree_data_graph; + FunctionTreeMFNetwork &m_function_tree_data_graph; IDDataCache m_id_data_cache; IDHandleLookup m_id_handle_lookup; public: - InlinedTreeData(InlinedTreeMFNetwork &inlined_tree_data) - : m_inlined_tree_data_graph(inlined_tree_data) + FunctionTreeData(FunctionTreeMFNetwork &function_tree_data) + : m_function_tree_data_graph(function_tree_data) { - FN::add_ids_used_by_nodes(m_id_handle_lookup, inlined_tree_data.inlined_tree()); + FN::add_ids_used_by_nodes(m_id_handle_lookup, function_tree_data.function_tree()); } - const InlinedNodeTree &inlined_tree() + const FunctionNodeTree &function_tree() { - return m_inlined_tree_data_graph.inlined_tree(); + return m_function_tree_data_graph.function_tree(); } const FN::MFNetwork &data_graph() { - return m_inlined_tree_data_graph.network(); + return m_function_tree_data_graph.network(); } - const InlinedTreeMFNetwork &inlined_tree_data_graph() + const FunctionTreeMFNetwork &function_tree_data_graph() { - return m_inlined_tree_data_graph; + return m_function_tree_data_graph; } IDHandleLookup &id_handle_lookup() @@ -115,14 +115,14 @@ class InlinedTreeData { return *value; } - ParticleFunction *particle_function_for_all_inputs(const XNode &xnode) + ParticleFunction *particle_function_for_all_inputs(const FNode &fnode) { Vector<const MFInputSocket *> sockets_to_compute; Vector<std::string> names_to_compute; - for (const XInputSocket *xsocket : xnode.inputs()) { - if (m_inlined_tree_data_graph.is_mapped(*xsocket)) { - sockets_to_compute.append(&m_inlined_tree_data_graph.lookup_dummy_socket(*xsocket)); - names_to_compute.append(xsocket->name()); + for (const FInputSocket *fsocket : fnode.inputs()) { + if (m_function_tree_data_graph.is_mapped(*fsocket)) { + sockets_to_compute.append(&m_function_tree_data_graph.lookup_dummy_socket(*fsocket)); + names_to_compute.append(fsocket->name()); } } @@ -130,14 +130,14 @@ class InlinedTreeData { std::move(names_to_compute)); } - ParticleFunction *particle_function_for_inputs(const XNode &xnode, ArrayRef<uint> input_indices) + ParticleFunction *particle_function_for_inputs(const FNode &fnode, ArrayRef<uint> input_indices) { Vector<const MFInputSocket *> sockets_to_compute; Vector<std::string> names_to_compute; for (uint i : input_indices) { - const MFInputSocket &socket = m_inlined_tree_data_graph.lookup_dummy_socket(xnode.input(i)); + const MFInputSocket &socket = m_function_tree_data_graph.lookup_dummy_socket(fnode.input(i)); sockets_to_compute.append(&socket); - names_to_compute.append(xnode.input(i).name()); + names_to_compute.append(fnode.input(i).name()); } return this->particle_function_for_sockets(std::move(sockets_to_compute), @@ -156,21 +156,21 @@ class InlinedTreeData { return &particle_fn; } - Optional<NamedGenericTupleRef> compute_inputs(const XNode &xnode, ArrayRef<uint> input_indices) + Optional<NamedGenericTupleRef> compute_inputs(const FNode &fnode, ArrayRef<uint> input_indices) { - const MultiFunction *fn = this->function_for_inputs(xnode, input_indices); + const MultiFunction *fn = this->function_for_inputs(fnode, input_indices); if (fn == nullptr) { return {}; } if (fn->uses_element_context<FN::ParticleAttributesContext>()) { - std::cout << "Inputs may not depend on particle attributes: " << xnode.name() << "\n"; + std::cout << "Inputs may not depend on particle attributes: " << fnode.name() << "\n"; return {}; } Vector<const CPPType *> computed_types; for (uint i : input_indices) { FN::MFDataType data_type = - m_inlined_tree_data_graph.lookup_dummy_socket(xnode.input(i)).data_type(); + m_function_tree_data_graph.lookup_dummy_socket(fnode.input(i)).data_type(); BLI_assert(data_type.is_single()); computed_types.append(&data_type.single__cpp_type()); } @@ -195,7 +195,7 @@ class InlinedTreeData { Vector<std::string> computed_names; for (uint i : input_indices) { - computed_names.append(xnode.input(i).name()); + computed_names.append(fnode.input(i).name()); } auto &name_provider = this->construct<FN::CustomGenericTupleNameProvider>( @@ -205,43 +205,43 @@ class InlinedTreeData { return named_tuple_ref; } - Optional<NamedGenericTupleRef> compute_all_data_inputs(const XNode &xnode) + Optional<NamedGenericTupleRef> compute_all_data_inputs(const FNode &fnode) { ScopedVector<uint> data_input_indices; - for (uint i : xnode.inputs().index_iterator()) { - if (m_inlined_tree_data_graph.is_mapped(xnode.input(i))) { + for (uint i : fnode.inputs().index_iterator()) { + if (m_function_tree_data_graph.is_mapped(fnode.input(i))) { data_input_indices.append(i); } } - return this->compute_inputs(xnode, data_input_indices); + return this->compute_inputs(fnode, data_input_indices); } - ArrayRef<std::string> find_target_system_names(const XOutputSocket &output_xsocket) + ArrayRef<std::string> find_target_system_names(const FOutputSocket &output_fsocket) { - VectorSet<const XNode *> system_xnodes; - this->find_target_system_nodes__recursive(output_xsocket, system_xnodes); + VectorSet<const FNode *> system_fnodes; + this->find_target_system_nodes__recursive(output_fsocket, system_fnodes); auto &system_names = this->construct<Vector<std::string>>(__func__); - for (const XNode *xnode : system_xnodes) { - system_names.append(xnode->name()); + for (const FNode *fnode : system_fnodes) { + system_names.append(fnode->name()); } return system_names; } ParticleAction *build_action(InfluencesCollector &collector, - const XInputSocket &start, + const FInputSocket &start, ArrayRef<std::string> system_names); ParticleAction &build_action_list(InfluencesCollector &collector, - const XNode &start_xnode, + const FNode &start_fnode, StringRef name, ArrayRef<std::string> system_names) { - Vector<const XInputSocket *> execute_sockets = this->find_execute_sockets(start_xnode, name); + Vector<const FInputSocket *> execute_sockets = this->find_execute_sockets(start_fnode, name); Vector<ParticleAction *> actions; - for (const XInputSocket *socket : execute_sockets) { + for (const FInputSocket *socket : execute_sockets) { ParticleAction *action = this->build_action(collector, *socket, system_names); if (action != nullptr) { actions.append(action); @@ -251,15 +251,15 @@ class InlinedTreeData { return sequence; } - const FN::MultiFunction *function_for_inputs(const XNode &xnode, ArrayRef<uint> input_indices) + const FN::MultiFunction *function_for_inputs(const FNode &fnode, ArrayRef<uint> input_indices) { Vector<const MFInputSocket *> sockets_to_compute; for (uint index : input_indices) { sockets_to_compute.append( - &m_inlined_tree_data_graph.lookup_dummy_socket(xnode.input(index))); + &m_function_tree_data_graph.lookup_dummy_socket(fnode.input(index))); } - if (m_inlined_tree_data_graph.network().find_dummy_dependencies(sockets_to_compute).size() > + if (m_function_tree_data_graph.network().find_dummy_dependencies(sockets_to_compute).size() > 0) { return nullptr; } @@ -296,45 +296,45 @@ class InlinedTreeData { } private: - Vector<const XNode *> find_target_system_nodes(const XOutputSocket &xsocket) + Vector<const FNode *> find_target_system_nodes(const FOutputSocket &fsocket) { - VectorSet<const XNode *> type_nodes; - find_target_system_nodes__recursive(xsocket, type_nodes); - return Vector<const XNode *>(type_nodes); + VectorSet<const FNode *> type_nodes; + find_target_system_nodes__recursive(fsocket, type_nodes); + return Vector<const FNode *>(type_nodes); } - void find_target_system_nodes__recursive(const XOutputSocket &output_xsocket, - VectorSet<const XNode *> &r_nodes) + void find_target_system_nodes__recursive(const FOutputSocket &output_fsocket, + VectorSet<const FNode *> &r_nodes) { - for (const XInputSocket *connected : output_xsocket.linked_sockets()) { - const XNode &connected_xnode = connected->node(); - if (connected_xnode.idname() == particle_system_idname) { - r_nodes.add(&connected_xnode); + for (const FInputSocket *connected : output_fsocket.linked_sockets()) { + const FNode &connected_fnode = connected->node(); + if (connected_fnode.idname() == particle_system_idname) { + r_nodes.add(&connected_fnode); } - else if (connected_xnode.idname() == combine_influences_idname) { - find_target_system_nodes__recursive(connected_xnode.output(0), r_nodes); + else if (connected_fnode.idname() == combine_influences_idname) { + find_target_system_nodes__recursive(connected_fnode.output(0), r_nodes); } } } - Vector<const XInputSocket *> find_execute_sockets(const XNode &xnode, StringRef name_prefix) + Vector<const FInputSocket *> find_execute_sockets(const FNode &fnode, StringRef name_prefix) { int first_index = -1; - for (const XInputSocket *xsocket : xnode.inputs()) { - if (xsocket->name() == name_prefix) { - first_index = xsocket->index(); + for (const FInputSocket *fsocket : fnode.inputs()) { + if (fsocket->name() == name_prefix) { + first_index = fsocket->index(); break; } } BLI_assert(first_index >= 0); - Vector<const XInputSocket *> execute_sockets; - for (const XInputSocket *xsocket : xnode.inputs().drop_front(first_index)) { - if (xsocket->idname() == "fn_OperatorSocket") { + Vector<const FInputSocket *> execute_sockets; + for (const FInputSocket *fsocket : fnode.inputs().drop_front(first_index)) { + if (fsocket->idname() == "fn_OperatorSocket") { break; } else { - execute_sockets.append(xsocket); + execute_sockets.append(fsocket); } } @@ -342,22 +342,22 @@ class InlinedTreeData { } }; -class XSocketActionBuilder { +class FSocketActionBuilder { private: InfluencesCollector &m_influences_collector; - InlinedTreeData &m_inlined_tree_data; - const XSocket &m_execute_xsocket; + FunctionTreeData &m_function_tree_data; + const FSocket &m_execute_fsocket; ArrayRef<std::string> m_system_names; ParticleAction *m_built_action = nullptr; public: - XSocketActionBuilder(InfluencesCollector &influences_collector, - InlinedTreeData &inlined_tree_data, - const XSocket &execute_xsocket, + FSocketActionBuilder(InfluencesCollector &influences_collector, + FunctionTreeData &function_tree_data, + const FSocket &execute_fsocket, ArrayRef<std::string> system_names) : m_influences_collector(influences_collector), - m_inlined_tree_data(inlined_tree_data), - m_execute_xsocket(execute_xsocket), + m_function_tree_data(function_tree_data), + m_execute_fsocket(execute_fsocket), m_system_names(system_names) { } @@ -367,9 +367,9 @@ class XSocketActionBuilder { return m_built_action; } - const XSocket &xsocket() const + const FSocket &fsocket() const { - return m_execute_xsocket; + return m_execute_fsocket; } ArrayRef<std::string> system_names() const @@ -377,17 +377,17 @@ class XSocketActionBuilder { return m_system_names; } - const CPPType &base_type_of(const XInputSocket &xsocket) const + const CPPType &base_type_of(const FInputSocket &fsocket) const { - return m_inlined_tree_data.inlined_tree_data_graph() - .lookup_dummy_socket(xsocket) + return m_function_tree_data.function_tree_data_graph() + .lookup_dummy_socket(fsocket) .data_type() .single__cpp_type(); } template<typename T, typename... Args> T &construct(Args &&... args) { - return m_inlined_tree_data.construct<T>("construct action", std::forward<Args>(args)...); + return m_function_tree_data.construct<T>("construct action", std::forward<Args>(args)...); } template<typename T, typename... Args> T &set_constructed(Args &&... args) @@ -405,50 +405,52 @@ class XSocketActionBuilder { ParticleFunction *particle_function_for_all_inputs() { - return m_inlined_tree_data.particle_function_for_all_inputs(m_execute_xsocket.node()); + return m_function_tree_data.particle_function_for_all_inputs(m_execute_fsocket.node()); } ParticleFunction *particle_function_for_inputs(ArrayRef<uint> input_indices) { - return m_inlined_tree_data.particle_function_for_inputs(m_execute_xsocket.node(), - input_indices); + return m_function_tree_data.particle_function_for_inputs(m_execute_fsocket.node(), + input_indices); } const MultiFunction *function_for_inputs(ArrayRef<uint> input_indices) { - return m_inlined_tree_data.function_for_inputs(m_execute_xsocket.node(), input_indices); + return m_function_tree_data.function_for_inputs(m_execute_fsocket.node(), input_indices); } - FN::MFDataType data_type_of_input(const XInputSocket &xsocket) + FN::MFDataType data_type_of_input(const FInputSocket &fsocket) { - return m_inlined_tree_data.inlined_tree_data_graph().lookup_dummy_socket(xsocket).data_type(); + return m_function_tree_data.function_tree_data_graph() + .lookup_dummy_socket(fsocket) + .data_type(); } PointerRNA *node_rna() { - return m_execute_xsocket.node().rna(); + return m_execute_fsocket.node().rna(); } ParticleAction &build_input_action_list(StringRef name, ArrayRef<std::string> system_names) { - return m_inlined_tree_data.build_action_list( - m_influences_collector, m_execute_xsocket.node(), name, system_names); + return m_function_tree_data.build_action_list( + m_influences_collector, m_execute_fsocket.node(), name, system_names); } ArrayRef<std::string> find_system_target_names(uint output_index, StringRef expected_name) { - const XOutputSocket &xsocket = m_execute_xsocket.node().output(output_index, expected_name); - return m_inlined_tree_data.find_target_system_names(xsocket); + const FOutputSocket &fsocket = m_execute_fsocket.node().output(output_index, expected_name); + return m_function_tree_data.find_target_system_names(fsocket); } Optional<NamedGenericTupleRef> compute_all_data_inputs() { - return m_inlined_tree_data.compute_all_data_inputs(m_execute_xsocket.node()); + return m_function_tree_data.compute_all_data_inputs(m_execute_fsocket.node()); } Optional<NamedGenericTupleRef> compute_inputs(ArrayRef<uint> input_indices) { - return m_inlined_tree_data.compute_inputs(m_execute_xsocket.node(), input_indices); + return m_function_tree_data.compute_inputs(m_execute_fsocket.node(), input_indices); } template<typename T> @@ -467,7 +469,7 @@ class XSocketActionBuilder { m_influences_collector.m_attributes.foreach_key( [&](StringRef name) { system_names.append(name); }); - return m_inlined_tree_data.try_add_attribute( + return m_function_tree_data.try_add_attribute( m_influences_collector, system_names, name, type, default_value); } @@ -476,30 +478,30 @@ class XSocketActionBuilder { const CPPType &type, const void *default_value = nullptr) { - return m_inlined_tree_data.try_add_attribute( + return m_function_tree_data.try_add_attribute( m_influences_collector, system_names, name, type, default_value); } IDHandleLookup &id_handle_lookup() { - return m_inlined_tree_data.id_handle_lookup(); + return m_function_tree_data.id_handle_lookup(); } BKE::IDDataCache &id_data_cache() { - return m_inlined_tree_data.id_data_cache(); + return m_function_tree_data.id_data_cache(); } }; -ParticleAction *InlinedTreeData::build_action(InfluencesCollector &collector, - const XInputSocket &start, - ArrayRef<std::string> system_names) +ParticleAction *FunctionTreeData::build_action(InfluencesCollector &collector, + const FInputSocket &start, + ArrayRef<std::string> system_names) { if (start.linked_sockets().size() != 1) { return nullptr; } - const XSocket &execute_socket = *start.linked_sockets()[0]; + const FSocket &execute_socket = *start.linked_sockets()[0]; if (execute_socket.idname() != "fn_ExecuteSocket") { return nullptr; } @@ -511,17 +513,17 @@ ParticleAction *InlinedTreeData::build_action(InfluencesCollector &collector, return nullptr; } - XSocketActionBuilder builder{collector, *this, execute_socket, system_names}; + FSocketActionBuilder builder{collector, *this, execute_socket, system_names}; (*parser)(builder); return builder.built_action(); } -static void ACTION_spawn(XSocketActionBuilder &builder) +static void ACTION_spawn(FSocketActionBuilder &builder) { - const XNode &xnode = builder.xsocket().node(); - const XInputSocket &first_execute_socket = *xnode.input_with_name_prefix("Execute on Birth"); - ArrayRef<const XInputSocket *> data_inputs = xnode.inputs().take_front( + const FNode &fnode = builder.fsocket().node(); + const FInputSocket &first_execute_socket = *fnode.input_with_name_prefix("Execute on Birth"); + ArrayRef<const FInputSocket *> data_inputs = fnode.inputs().take_front( first_execute_socket.index()); ArrayRef<uint> input_indices = IndexRange(data_inputs.size()).as_array_ref(); const ParticleFunction *inputs_fn = builder.particle_function_for_inputs(input_indices); @@ -536,12 +538,12 @@ static void ACTION_spawn(XSocketActionBuilder &builder) } Vector<std::string> attribute_names; - for (const XInputSocket *xsocket : data_inputs) { - StringRef attribute_name = xsocket->name(); + for (const FInputSocket *fsocket : data_inputs) { + StringRef attribute_name = fsocket->name(); attribute_names.append(attribute_name); const CPPType *attribute_type = nullptr; - FN::MFDataType data_type = builder.data_type_of_input(*xsocket); + FN::MFDataType data_type = builder.data_type_of_input(*fsocket); if (data_type.is_single()) { attribute_type = &data_type.single__cpp_type(); } @@ -561,7 +563,7 @@ static void ACTION_spawn(XSocketActionBuilder &builder) system_names, *inputs_fn, std::move(attribute_names), action); } -static void ACTION_condition(XSocketActionBuilder &builder) +static void ACTION_condition(FSocketActionBuilder &builder) { ParticleFunction *inputs_fn = builder.particle_function_for_all_inputs(); if (inputs_fn == nullptr) { @@ -575,7 +577,7 @@ static void ACTION_condition(XSocketActionBuilder &builder) builder.set_constructed<ConditionAction>(*inputs_fn, action_true, action_false); } -static void ACTION_set_attribute(XSocketActionBuilder &builder) +static void ACTION_set_attribute(FSocketActionBuilder &builder) { Optional<NamedGenericTupleRef> values = builder.compute_inputs({0}); if (!values.has_value()) { @@ -587,7 +589,7 @@ static void ACTION_set_attribute(XSocketActionBuilder &builder) return; } - const CPPType &attribute_type = builder.base_type_of(builder.xsocket().node().input(1)); + const CPPType &attribute_type = builder.base_type_of(builder.fsocket().node().input(1)); std::string attribute_name = values->relocate_out<std::string>(0, "Name"); bool attribute_added = builder.try_add_attribute_to_affected_particles(attribute_name, @@ -599,7 +601,7 @@ static void ACTION_set_attribute(XSocketActionBuilder &builder) builder.set_constructed<SetAttributeAction>(attribute_name, attribute_type, *inputs_fn); } -static void ACTION_multi_execute(XSocketActionBuilder &builder) +static void ACTION_multi_execute(FSocketActionBuilder &builder) { ParticleAction &action = builder.build_input_action_list("Execute", builder.system_names()); builder.set(action); @@ -615,55 +617,55 @@ BLI_LAZY_INIT(StringMap<ActionParserCallback>, get_action_parsers) return map; } -class XNodeInfluencesBuilder { +class FNodeInfluencesBuilder { private: InfluencesCollector &m_influences_collector; - InlinedTreeData &m_inlined_tree_data; + FunctionTreeData &m_function_tree_data; WorldTransition &m_world_transition; - const XNode &m_xnode; + const FNode &m_fnode; public: - XNodeInfluencesBuilder(InfluencesCollector &influences_collector, - InlinedTreeData &inlined_tree_data, + FNodeInfluencesBuilder(InfluencesCollector &influences_collector, + FunctionTreeData &function_tree_data, WorldTransition &world_transition, - const XNode &xnode) + const FNode &fnode) : m_influences_collector(influences_collector), - m_inlined_tree_data(inlined_tree_data), + m_function_tree_data(function_tree_data), m_world_transition(world_transition), - m_xnode(xnode) + m_fnode(fnode) { } - const XNode &xnode() const + const FNode &fnode() const { - return m_xnode; + return m_fnode; } Optional<NamedGenericTupleRef> compute_all_data_inputs() { - return m_inlined_tree_data.compute_all_data_inputs(m_xnode); + return m_function_tree_data.compute_all_data_inputs(m_fnode); } Optional<NamedGenericTupleRef> compute_inputs(ArrayRef<uint> input_indices) { - return m_inlined_tree_data.compute_inputs(m_xnode, input_indices); + return m_function_tree_data.compute_inputs(m_fnode, input_indices); } const MultiFunction *function_for_inputs(ArrayRef<uint> input_indices) { - return m_inlined_tree_data.function_for_inputs(m_xnode, input_indices); + return m_function_tree_data.function_for_inputs(m_fnode, input_indices); } ParticleAction &build_action_list(StringRef name, ArrayRef<std::string> system_names) { - return m_inlined_tree_data.build_action_list( - m_influences_collector, m_xnode, name, system_names); + return m_function_tree_data.build_action_list( + m_influences_collector, m_fnode, name, system_names); } ArrayRef<std::string> find_target_system_names(uint output_index, StringRef expected_name) { - return m_inlined_tree_data.find_target_system_names( - m_xnode.output(output_index, expected_name)); + return m_function_tree_data.find_target_system_names( + m_fnode.output(output_index, expected_name)); } WorldTransition &world_transition() @@ -673,7 +675,7 @@ class XNodeInfluencesBuilder { template<typename T, typename... Args> T &construct(Args &&... args) { - return m_inlined_tree_data.construct<T>(__func__, std::forward<Args>(args)...); + return m_function_tree_data.construct<T>(__func__, std::forward<Args>(args)...); } void add_emitter(Emitter &emitter) @@ -706,10 +708,10 @@ class XNodeInfluencesBuilder { { std::stringstream ss; ss << "private/node"; - for (const FN::XParentNode *parent = m_xnode.parent(); parent; parent = parent->parent()) { + for (const FN::FParentNode *parent = m_fnode.parent(); parent; parent = parent->parent()) { ss << "/" << parent->vnode().name(); } - ss << "/" << m_xnode.name(); + ss << "/" << m_fnode.name(); std::string identifier = ss.str(); return identifier; @@ -717,27 +719,29 @@ class XNodeInfluencesBuilder { IDHandleLookup &id_handle_lookup() { - return m_inlined_tree_data.id_handle_lookup(); + return m_function_tree_data.id_handle_lookup(); } BKE::IDDataCache &id_data_cache() { - return m_inlined_tree_data.id_data_cache(); + return m_function_tree_data.id_data_cache(); } PointerRNA *node_rna() { - return m_xnode.rna(); + return m_fnode.rna(); } ParticleFunction *particle_function_for_all_inputs() { - return m_inlined_tree_data.particle_function_for_all_inputs(m_xnode); + return m_function_tree_data.particle_function_for_all_inputs(m_fnode); } - FN::MFDataType data_type_of_input(const XInputSocket &xsocket) + FN::MFDataType data_type_of_input(const FInputSocket &fsocket) { - return m_inlined_tree_data.inlined_tree_data_graph().lookup_dummy_socket(xsocket).data_type(); + return m_function_tree_data.function_tree_data_graph() + .lookup_dummy_socket(fsocket) + .data_type(); } template<typename T> @@ -752,14 +756,14 @@ class XNodeInfluencesBuilder { const CPPType &type, const void *default_value = nullptr) { - return m_inlined_tree_data.try_add_attribute( + return m_function_tree_data.try_add_attribute( m_influences_collector, system_names, name, type, default_value); } }; -using ParseNodeCallback = std::function<void(XNodeInfluencesBuilder &builder)>; +using ParseNodeCallback = std::function<void(FNodeInfluencesBuilder &builder)>; -static void PARSE_point_emitter(XNodeInfluencesBuilder &builder) +static void PARSE_point_emitter(FNodeInfluencesBuilder &builder) { Optional<NamedGenericTupleRef> inputs = builder.compute_all_data_inputs(); if (!inputs.has_value()) { @@ -784,11 +788,11 @@ static void PARSE_point_emitter(XNodeInfluencesBuilder &builder) builder.add_emitter(emitter); } -static void PARSE_custom_emitter(XNodeInfluencesBuilder &builder) +static void PARSE_custom_emitter(FNodeInfluencesBuilder &builder) { - const XNode &xnode = builder.xnode(); - const XInputSocket &first_execute_socket = *xnode.input_with_name_prefix("Execute on Birth"); - ArrayRef<const XInputSocket *> data_inputs = xnode.inputs().take_front( + const FNode &fnode = builder.fnode(); + const FInputSocket &first_execute_socket = *fnode.input_with_name_prefix("Execute on Birth"); + ArrayRef<const FInputSocket *> data_inputs = fnode.inputs().take_front( first_execute_socket.index()); ArrayRef<uint> input_indices = IndexRange(data_inputs.size()).as_array_ref(); const MultiFunction *emitter_function = builder.function_for_inputs(input_indices); @@ -799,7 +803,7 @@ static void PARSE_custom_emitter(XNodeInfluencesBuilder &builder) ArrayRef<std::string> system_names = builder.find_target_system_names(0, "Emitter"); Vector<std::string> attribute_names; - for (const XInputSocket *socket : data_inputs) { + for (const FInputSocket *socket : data_inputs) { StringRef attribute_name = socket->name(); attribute_names.append(attribute_name); const CPPType *attribute_type = nullptr; @@ -864,7 +868,7 @@ static Vector<float> compute_emitter_vertex_weights(PointerRNA *node_rna, return vertex_weights; } -static void PARSE_mesh_emitter(XNodeInfluencesBuilder &builder) +static void PARSE_mesh_emitter(FNodeInfluencesBuilder &builder) { Optional<NamedGenericTupleRef> inputs = builder.compute_all_data_inputs(); if (!inputs.has_value()) { @@ -894,7 +898,7 @@ static void PARSE_mesh_emitter(XNodeInfluencesBuilder &builder) builder.add_emitter(emitter); } -static void PARSE_custom_force(XNodeInfluencesBuilder &builder) +static void PARSE_custom_force(FNodeInfluencesBuilder &builder) { ParticleFunction *inputs_fn = builder.particle_function_for_all_inputs(); if (inputs_fn == nullptr) { @@ -906,7 +910,7 @@ static void PARSE_custom_force(XNodeInfluencesBuilder &builder) builder.add_force(system_names, force); } -static void PARSE_age_reached_event(XNodeInfluencesBuilder &builder) +static void PARSE_age_reached_event(FNodeInfluencesBuilder &builder) { ParticleFunction *inputs_fn = builder.particle_function_for_all_inputs(); if (inputs_fn == nullptr) { @@ -927,7 +931,7 @@ static void PARSE_age_reached_event(XNodeInfluencesBuilder &builder) builder.add_event(system_names, event); } -static void PARSE_trails(XNodeInfluencesBuilder &builder) +static void PARSE_trails(FNodeInfluencesBuilder &builder) { ArrayRef<std::string> main_system_names = builder.find_target_system_names(0, "Main System"); ArrayRef<std::string> trail_system_names = builder.find_target_system_names(1, "Trail System"); @@ -946,7 +950,7 @@ static void PARSE_trails(XNodeInfluencesBuilder &builder) builder.add_offset_handler(main_system_names, offset_handler); } -static void PARSE_initial_grid_emitter(XNodeInfluencesBuilder &builder) +static void PARSE_initial_grid_emitter(FNodeInfluencesBuilder &builder) { Optional<NamedGenericTupleRef> inputs = builder.compute_all_data_inputs(); if (!inputs.has_value()) { @@ -967,7 +971,7 @@ static void PARSE_initial_grid_emitter(XNodeInfluencesBuilder &builder) builder.add_emitter(emitter); } -static void PARSE_mesh_collision(XNodeInfluencesBuilder &builder) +static void PARSE_mesh_collision(FNodeInfluencesBuilder &builder) { ParticleFunction *inputs_fn = builder.particle_function_for_all_inputs(); if (inputs_fn == nullptr) { @@ -1004,7 +1008,7 @@ static void PARSE_mesh_collision(XNodeInfluencesBuilder &builder) builder.add_event(system_names, event); } -static void PARSE_size_over_time(XNodeInfluencesBuilder &builder) +static void PARSE_size_over_time(FNodeInfluencesBuilder &builder) { ParticleFunction *inputs_fn = builder.particle_function_for_all_inputs(); if (inputs_fn == nullptr) { @@ -1016,7 +1020,7 @@ static void PARSE_size_over_time(XNodeInfluencesBuilder &builder) builder.add_offset_handler(system_names, offset_handler); } -static void PARSE_custom_event(XNodeInfluencesBuilder &builder) +static void PARSE_custom_event(FNodeInfluencesBuilder &builder) { ParticleFunction *inputs_fn = builder.particle_function_for_all_inputs(); if (inputs_fn == nullptr) { @@ -1030,7 +1034,7 @@ static void PARSE_custom_event(XNodeInfluencesBuilder &builder) builder.add_event(system_names, event); } -static void PARSE_always_execute(XNodeInfluencesBuilder &builder) +static void PARSE_always_execute(FNodeInfluencesBuilder &builder) { ArrayRef<std::string> system_names = builder.find_target_system_names(0, "Influence"); ParticleAction &action = builder.build_action_list("Execute", system_names); @@ -1056,7 +1060,7 @@ BLI_LAZY_INIT_STATIC(StringMap<ParseNodeCallback>, get_node_parsers) return map; } -static void collect_influences(InlinedTreeData &inlined_tree_data, +static void collect_influences(FunctionTreeData &function_tree_data, WorldTransition &world_transition, Vector<std::string> &r_system_names, InfluencesCollector &collector, @@ -1066,9 +1070,9 @@ static void collect_influences(InlinedTreeData &inlined_tree_data, StringMap<ParseNodeCallback> &parsers = get_node_parsers(); - for (const XNode *xnode : - inlined_tree_data.inlined_tree().nodes_with_idname(particle_system_idname)) { - StringRef name = xnode->name(); + for (const FNode *fnode : + function_tree_data.function_tree().nodes_with_idname(particle_system_idname)) { + StringRef name = fnode->name(); r_system_names.append(name); AttributesInfoBuilder *attributes = new AttributesInfoBuilder(); @@ -1084,19 +1088,19 @@ static void collect_influences(InlinedTreeData &inlined_tree_data, collector.m_attributes.add_new(name, attributes); } - for (const XNode *xnode : inlined_tree_data.inlined_tree().all_nodes()) { - StringRef idname = xnode->idname(); + for (const FNode *fnode : function_tree_data.function_tree().all_nodes()) { + StringRef idname = fnode->idname(); ParseNodeCallback *callback = parsers.lookup_ptr(idname); if (callback != nullptr) { - XNodeInfluencesBuilder builder{collector, inlined_tree_data, world_transition, *xnode}; + FNodeInfluencesBuilder builder{collector, function_tree_data, world_transition, *fnode}; (*callback)(builder); } } for (std::string &system_name : r_system_names) { ArrayRef<Force *> forces = collector.m_forces.lookup_default(system_name); - EulerIntegrator &integrator = inlined_tree_data.construct<EulerIntegrator>("integrator", - forces); + EulerIntegrator &integrator = function_tree_data.construct<EulerIntegrator>("integrator", + forces); r_integrators.add_new(system_name, &integrator); } @@ -1104,13 +1108,13 @@ static void collect_influences(InlinedTreeData &inlined_tree_data, class NodeTreeStepSimulator : public StepSimulator { private: - FN::BTreeVTreeMap m_inlined_trees; - InlinedNodeTree m_inlined_tree; + FN::BTreeVTreeMap m_function_trees; + FunctionNodeTree m_function_tree; public: - NodeTreeStepSimulator(bNodeTree *btree) : m_inlined_tree(btree, m_inlined_trees) + NodeTreeStepSimulator(bNodeTree *btree) : m_function_tree(btree, m_function_trees) { - // m_inlined_tree.to_dot__clipboard(); + // m_function_tree.to_dot__clipboard(); } void simulate(SimulationState &simulation_state) override @@ -1122,18 +1126,18 @@ class NodeTreeStepSimulator : public StepSimulator { ParticlesState &particles_state = simulation_state.particles(); ResourceCollector resources; - std::unique_ptr<InlinedTreeMFNetwork> data_graph = - FN::generate_inlined_tree_multi_function_network(m_inlined_tree, resources); + std::unique_ptr<FunctionTreeMFNetwork> data_graph = + FN::generate_node_tree_multi_function_network(m_function_tree, resources); if (data_graph.get() == nullptr) { return; } - InlinedTreeData inlined_tree_data(*data_graph); + FunctionTreeData function_tree_data(*data_graph); Vector<std::string> system_names; StringMap<Integrator *> integrators; InfluencesCollector influences_collector; collect_influences( - inlined_tree_data, world_transition, system_names, influences_collector, integrators); + function_tree_data, world_transition, system_names, influences_collector, integrators); auto &containers = particles_state.particle_containers(); diff --git a/source/blender/simulations/bparticles/node_frontend.hpp b/source/blender/simulations/bparticles/node_frontend.hpp index b126ba68ab9..14e6df82f8e 100644 --- a/source/blender/simulations/bparticles/node_frontend.hpp +++ b/source/blender/simulations/bparticles/node_frontend.hpp @@ -7,7 +7,7 @@ namespace BParticles { -using FN::InlinedNodeTree; +using FN::FunctionNodeTree; std::unique_ptr<StepSimulator> simulator_from_node_tree(bNodeTree *btree); |