56#include "RNA_prototypes.hh"
78 if (socket.identifier == identifier) {
101 label, (
node->id) ?
node->id->name + 2 :
IFACE_(
"Missing Data-Block"), label_maxncpy);
151 const char **r_disabled_hint)
153 if (!
node->typeinfo->poll(
node->typeinfo, nodetree, r_disabled_hint)) {
182 const char **r_disabled_hint)
187 if (grouptree ==
nullptr) {
191 if (nodetree == grouptree) {
192 if (r_disabled_hint) {
193 *r_disabled_hint =
RPT_(
"Nesting a node group inside of itself is not allowed");
197 if (nodetree->
type != grouptree->
type) {
198 if (r_disabled_hint) {
199 *r_disabled_hint =
RPT_(
"Node group has different type");
204 for (
const bNode *
node : grouptree->all_nodes()) {
205 if (
node->typeinfo->poll_instance &&
206 !
node->typeinfo->poll_instance(
node, nodetree, r_disabled_hint))
219 const int item_index = tree_interface.find_item_index(io_socket.
item);
224 if (
node.id ==
nullptr) {
245 const int item_index = tree_interface.find_item_index(io_socket.
item);
250 if (
node.id ==
nullptr) {
273 const std::optional<StructureType> structure_type,
280 const UString name(io_socket.name());
285 datatype = base_typeinfo->
type;
301 .dimensions(value.dimensions)
312 .dimensions(value.dimensions)
319 decl = &
b.add_socket<
decl::Color>(name, identifier, in_out).default_value(value.value);
328 decl = &
b.add_socket<
decl::Bool>(name, identifier, in_out).default_value(value.value);
440 decl->description(io_socket.description());
446 if (structure_type) {
447 decl->structure_type(*structure_type);
460 bool layout_added =
false;
461 auto add_layout_if_needed = [&]() {
463 if (
node.typeinfo->draw_buttons) {
464 if (is_root && !layout_added) {
465 b.add_default_layout();
472 switch (item->item_type) {
478 add_layout_if_needed();
481 group, io_socket, structure_type_by_socket.
lookup_try(&io_socket), in_out,
b);
485 add_layout_if_needed();
487 auto &panel_b =
b.add_panel(
UString(io_panel.name()), io_panel.identifier)
488 .description(io_panel.description())
491 panel_b,
node, group, structure_type_by_socket, io_panel,
false);
497 add_layout_if_needed();
503 if (
node ==
nullptr) {
529 group->ensure_interface_cache();
533 structure_type_by_socket.
reserve(group->interface_items().size());
539 structure_type_by_socket.
add(inputs[i], input_structure_types[i]);
546 structure_type_by_socket.
add(outputs[i], output_structure_types[i].type);
569 data->label_size = 20;
575 bke::bNodeType *ntype = MEM_new<bke::bNodeType>(
"frame node type");
581 "Collect related nodes together in a common area. Useful for organization when the "
582 "re-usability of a node group is not required";
604 if (
node ==
nullptr) {
610 .idname(socket_idname.
c_str())
613 .idname(socket_idname.
c_str())
626 const char **r_disabled_hint)
631 if (r_disabled_hint) {
632 *r_disabled_hint =
"Socket type not found";
638 if (r_disabled_hint) {
639 *r_disabled_hint =
"Socket type not supported";
649 bke::bNodeType *ntype = MEM_new<bke::bNodeType>(
"frame node type");
655 "A single-socket organization tool that supports one input and multiple outputs";
667 int node_i = std::numeric_limits<int>::max();
678 if (this->node_i == other.
node_i) {
681 return this->node_i < other.
node_i;
687 ntree->ensure_topology_cache();
689 const Span<bNode *> all_reroute_nodes = ntree->nodes_by_type(
"NodeReroute"_ustr);
692 for (
const bNode *reroute : all_reroute_nodes) {
693 reroute_nodes.
add(reroute->index());
703 for (
const bNode *src_reroute : all_reroute_nodes) {
704 const int src_reroute_i = reroute_nodes.
index_of(src_reroute->index());
706 src_reroute->output_sockets().first()->directly_linked_sockets())
708 const bNode &dst_node = dst_socket->owner_node();
709 if (!dst_node.is_reroute()) {
712 const int dst_reroute_i = reroute_nodes.
index_of(dst_node.index());
713 reroutes_groups.
join(src_reroute_i, dst_reroute_i);
718 for (
const int reroute_i : reroute_nodes.
index_range()) {
719 const int root_reroute_i = reroutes_groups.
find_root(reroute_i);
720 reroute_groups.
add(root_reroute_i);
733 for (
const bNodeLink *link : ntree->all_links()) {
734 const bNode *src_node = link->fromnode;
735 const bNode *dst_node = link->tonode;
737 if (src_node->is_reroute() == dst_node->is_reroute()) {
741 if (!dst_node->is_reroute()) {
742 const int src_reroute_i = reroute_nodes.
index_of(src_node->index());
743 const int src_reroute_root_i = reroutes_groups.
find_root(src_reroute_i);
744 const int src_reroute_group_i = reroute_groups.
index_of(src_reroute_root_i);
747 if (reroute_group_dst_type_priority[src_reroute_group_i] > type_priority) {
751 reroute_group_dst_type_priority[src_reroute_group_i] = type_priority;
756 dst_type_by_reroute_group[src_reroute_group_i] = dst_socket->
typeinfo;
761 const int dst_reroute_i = reroute_nodes.
index_of(dst_node->index());
762 const int dst_reroute_root_i = reroutes_groups.
find_root(dst_reroute_i);
763 const int dst_reroute_group_i = reroute_groups.
index_of(dst_reroute_root_i);
768 src_type_by_reroute_group[dst_reroute_group_i] = src_socket->
typeinfo;
772 for (
const int reroute_i : reroute_nodes.
index_range()) {
773 const int reroute_root_i = reroutes_groups.
find_root(reroute_i);
774 const int reroute_group_i = reroute_groups.
index_of(reroute_root_i);
777 if (dst_type_by_reroute_group[reroute_group_i] !=
nullptr) {
778 reroute_type = dst_type_by_reroute_group[reroute_group_i];
780 if (src_type_by_reroute_group[reroute_group_i] !=
nullptr) {
781 reroute_type = src_type_by_reroute_group[reroute_group_i];
784 if (reroute_type ==
nullptr) {
785 const int root_node_index = reroute_nodes[reroute_root_i];
786 const bNode &root_reroute = *all_nodes[root_node_index];
788 reroute_type = root_socket->
typeinfo;
791 const int reroute_index = reroute_nodes[reroute_i];
792 bNode &reroute_node = *all_nodes[reroute_index];
803 ntree.ensure_topology_cache();
806 for (
const bNodeLink *link : socket->directly_linked_links()) {
807 nodes_to_check.
push(link->tonode);
810 while (!nodes_to_check.
is_empty()) {
811 const bNode *next_node = nodes_to_check.
pop();
812 for (
const bNodeSocket *socket : next_node->output_sockets()) {
813 for (
const bNodeLink *link : socket->directly_linked_links()) {
819 nodes_to_check.
push(link->tonode);
836 if (
node ==
nullptr) {
842 b.use_custom_socket_order();
843 b.allow_any_socket_order();
844 b.add_default_layout();
846 .idname(socket_idname.
c_str())
850 .idname(socket_idname.
c_str())
853 .align_with_previous();
894 const char **r_disabled_hint)
899 if (r_disabled_hint) {
900 *r_disabled_hint =
"Socket type not found";
906 if (r_disabled_hint) {
907 *r_disabled_hint =
"Socket type not supported";
917 params.
set_output(
"Value"_ustr, std::move(input_value));
922 using NodeOperation::NodeOperation;
927 const Result &input = this->
get_input(
"Value");
946 ntype->
ui_name =
"Implicit Conversion";
947 ntype->
ui_description =
"Implicitly convert the input value to a fixed socket type";
982 const bNodeTree *node_tree =
b.tree_or_null();
983 if (node_tree ==
nullptr) {
1013 const bNodeTree *node_tree =
b.tree_or_null();
1014 if (node_tree ==
nullptr) {
1057 item.set_selected(
false);
1085 item.set_selected(
false);
1112 ntype->
ui_name =
"Group Input";
1114 "Expose connected data from inside a node group as inputs to its interface";
1151 if (group_outputs[0]->type !=
SOCK_RGBA) {
1154 row.
icon = ICON_STATUS_ERROR;
1155 row.
tooltip =
TIP_(
"Node group's first output must be a color output");
1156 parameters.
rows.append(std::move(row));
1160 if (group_outputs.
size() > 1) {
1163 row.
icon = ICON_STATUS_WARNING;
1164 row.
tooltip =
TIP_(
"Only the first output is considered while the rest are ignored");
1165 parameters.
rows.append(std::move(row));
1174 if (group_output_nodes.
size() <= 1) {
1182 row.
icon = ICON_STATUS_ERROR;
1183 row.
tooltip =
TIP_(
"There are multiple group output nodes and this one is not active");
1184 params.
rows.append(std::move(row));
1194 ntype->
ui_name =
"Group Output";
1195 ntype->
ui_description =
"Output data from inside of a node group";
1212 data->textbox_state_node.visible_lines = 5;
1213 data->textbox_state_panel.visible_lines = 5;
1227 NodeComment *dst_data = MEM_new<NodeComment>(__func__, src_data);
#define NODE_CLASS_OUTPUT
#define NODE_CLASS_INTERFACE
#define NODE_CLASS_CONVERTER
#define NODE_CLASS_PATTERN
#define NODE_CLASS_GEOMETRY
#define NODE_GROUP_OUTPUT
#define NODE_CLASS_DISTORT
#define NODE_CLASS_OP_VECTOR
#define NODE_CLASS_LAYOUT
#define NODE_CLASS_OP_COLOR
#define NODE_CLASS_OP_FILTER
#define NODE_CLASS_ATTRIBUTE
#define NODE_CLASS_TEXTURE
#define NODE_CLASS_SHADER
#define NODE_CLASS_SCRIPT
#define ID_IS_LINKED(_id)
Read Blender memory allocation and freeing.
T join(const T x, const T y)
std::optional< Value > lookup_try(const Key &key) const
bool add(const Key &key, const Value &value)
constexpr int64_t size() const
constexpr IndexRange index_range() const
void push(const T &value)
constexpr const char * c_str() const
StringRefNull ref() const
int64_t index_of(const Key &key) const
IndexRange index_range() const
std::unique_ptr< nodes::StructureTypeInterface > structure_type_interface
constexpr bool is_empty() const
constexpr int64_t size() const
void copy_utf8_truncated(char *dst, int64_t dst_size) const
Result & get_result(StringRef identifier)
Result & get_input(StringRef identifier) const
BaseSocketDeclarationBuilder & socket_name_ptr(PointerRNA ptr, StringRef property_name)
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
bool skip_updating_sockets
bool use_custom_socket_order
StructureType structure_type
std::function< void(bNode &node, bNodeSocket &socket, const char *data_path)> init_socket_fn
std::string default_value
#define storage(slot, qualifiers)
T & get_item_as(bNodeTreeInterfaceItem &item)
T & get_socket_data_as(bNodeTreeInterfaceSocket &item)
bNodeTreeInterfaceSocket * add_interface_socket_from_node(bNodeTree &ntree, const bNode &from_node, const bNodeSocket &from_sock, std::optional< StringRef > name=std::nullopt, std::optional< eNodeSocketInOut > in_out=std::nullopt)
bool node_is_connected_to_output(const bNodeTree &ntree, const bNode &node)
bool node_group_poll(const bNodeTree *nodetree, const bNodeTree *grouptree, const char **r_disabled_hint)
void node_register_type(bNodeType &ntype)
void node_type_base(bNodeType &ntype, UString idname, std::optional< int16_t > legacy_type=std::nullopt)
bNodeSocketType * node_socket_type_find(StringRef idname)
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
void node_tree_interface_draw(bContext &C, ui::Layout &layout, bNodeTree &tree)
EulerXYZBase< float > EulerXYZ
static void group_input_declare(NodeDeclarationBuilder &b)
static std::function< ID *(const bNode &node)> get_default_id_getter(const bNodeTreeInterface &tree_interface, const bNodeTreeInterfaceSocket &io_socket)
static void node_group_input_layout(ui::Layout &layout, bContext *C, PointerRNA *ptr)
void update_node_declaration_and_sockets(bNodeTree &ntree, bNode &node, Main *bmain)
void node_group_declare(NodeDeclarationBuilder &b)
static bool group_input_insert_link(bke::NodeInsertLinkParams ¶ms)
static bool group_output_insert_link(bke::NodeInsertLinkParams ¶ms)
static void group_output_declare(NodeDeclarationBuilder &b)
static std::function< void(bNode &node, bNodeSocket &socket, const char *data_path)> get_init_socket_fn(const bNodeTreeInterface &tree_interface, const bNodeTreeInterfaceSocket &io_socket)
static void node_group_output_layout(ui::Layout &layout, bContext *C, PointerRNA *ptr)
static BaseSocketDeclarationBuilder & build_interface_socket_declaration(const bNodeTree &tree, const bNodeTreeInterfaceSocket &io_socket, const std::optional< StructureType > structure_type, const eNodeSocketInOut in_out, DeclarationListBuilder &b)
static void node_group_declare_panel_recursive(DeclarationListBuilder &b, const bNode &node, const bNodeTree &group, const Map< const bNodeTreeInterfaceSocket *, StructureType > &structure_type_by_socket, const bNodeTreeInterfacePanel &io_parent_panel, const bool is_root)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
size_t size_t size_t BLI_snprintf_utf8(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
static void node_frame_init(bNodeTree *, bNode *node)
static bool node_implicit_conversion_poll_instance(const bNode *node, const bNodeTree *nodetree, const char **r_disabled_hint)
char * STRNCPY(char(&dst)[N], const char *src)
ID * DEG_get_original_id(ID *id)
static void node_reroute_init(bNodeTree *, bNode *node)
void register_node_type_group_input()
int node_group_ui_class(const bNode *node)
static void node_implicit_conversion_declare(nodes::NodeDeclarationBuilder &b)
std::string node_group_ui_description(const bNode &node)
bNodeSocket * node_group_output_find_socket(bNode *node, const StringRef identifier)
void node_group_label(const bNodeTree *, const bNode *node, char *label, int label_maxncpy)
bNodeSocket * node_group_find_output_socket(bNode *groupnode, const StringRef identifier)
static compositor::NodeOperation * node_implicit_conversion_compositor_operation(compositor::Context &context, const bNode &node)
static void node_comment_layout_ex(ui::Layout &layout, bContext *, PointerRNA *ptr)
static void node_implicit_conversion_geo_exec(nodes::GeoNodeExecParams params)
static void get_compositor_group_output_extra_info(blender::nodes::NodeExtraInfoParams ¶meters)
static void node_comment_copy(bNodeTree *, bNode *dst_node, const bNode *src_node)
@ NODE_INTERFACE_PANEL_DEFAULT_CLOSED
VecBase< float, 4 > float4
void register_node_type_reroute()
void register_node_type_frame()
static void node_comment_blend_read(bNodeTree &, bNode &node, BlendDataReader &reader)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
static bNodeSocket * find_matching_socket(ListBaseT< bNodeSocket > &sockets, StringRef identifier)
VecBase< int32_t, 3 > int3
static void node_implicit_conversion_init(bNodeTree *, bNode *node)
static void node_comment_blend_write(const bNodeTree &, const bNode &node, BlendWriter &writer)
static void node_group_output_extra_info(nodes::NodeExtraInfoParams ¶ms)
void register_node_type_group_output()
BMesh const char void * data
bool RNA_enum_name(const EnumPropertyItem *item, const int value, const char **r_name)
static void node_comment_free(bNode *node)
SpaceNode * CTX_wm_space_node(const bContext *C)
void register_node_type_implicit_conversion()
static void node_implicit_conversion_layout(ui::Layout &layout, bContext *, PointerRNA *ptr)
static bool node_reroute_poll_instance(const bNode *node, const bNodeTree *nodetree, const char **r_disabled_hint)
static void node_reroute_declare(nodes::NodeDeclarationBuilder &b)
static void node_comment_init(bNodeTree *, bNode *node)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
void ntree_update_reroute_nodes(bNodeTree *ntree)
ID_Type GS(const char *name)
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
char * BLI_strdup_null(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_MALLOC
const EnumPropertyItem rna_enum_node_socket_data_type_items[]
void node_free_standard_storage(bNode *node)
@ NODE_INTERFACE_SOCKET_COMPACT
@ NODE_INTERFACE_SOCKET_HIDE_VALUE
@ NODE_INTERFACE_SOCKET_OPTIONAL_LABEL
@ NODE_INTERFACE_SOCKET_OUTPUT
@ NODE_INTERFACE_SOCKET_PANEL_TOGGLE
@ NODE_INTERFACE_SOCKET_MENU_EXPANDED
@ NODE_INTERFACE_SOCKET_INPUT
VecBase< float, 3 > float3
bNodeSocket * node_group_find_input_socket(bNode *groupnode, const StringRef identifier)
bNodeSocket * node_group_input_find_socket(bNode *node, const StringRef identifier)
static void node_implicit_conversion_label(const bNodeTree *, const bNode *node, char *label, int label_maxncpy)
bool node_group_poll_instance(const bNode *node, const bNodeTree *nodetree, const char **r_disabled_hint)
void BLO_read_string(BlendDataReader *reader, char **ptr_p)
void register_node_type_comment()
void write_string(const char *data)
struct AssetMetaData * asset_data
RerouteTargetPriority()=default
bool operator>(const RerouteTargetPriority other)
RerouteTargetPriority(const bNodeSocket &socket)
struct bNodeTree * edittree
struct bNodeTree * nodetree
bke::bNodeSocketType * typeinfo
NodeTreeInterfaceItemType item_type
NodeTreeInterfaceSocketFlag flag
bNodeTreeInterfaceItem item
NodeDefaultInputType default_input
bNodeTreeInterfacePanel root_panel
bke::bNodeTreeType * typeinfo
bNodeTreeInterface tree_interface
bke::bNodeTreeRuntime * runtime
ListBaseT< bNodeSocket > outputs
ListBaseT< bNodeSocket > inputs
static constexpr int _160
static constexpr int _200
void(*) interface_init_socket(ID *id, const bNodeTreeInterfaceSocket *interface_socket, bNode *node, bNodeSocket *socket, StringRefNull data_path)
bool(*) valid_socket_type(bNodeTreeType *ntreetype, bNodeSocketType *socket_type)
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
NodeBlendWriteFunction blend_write_storage_content
std::string ui_description
NodeBlendDataReadFunction blend_data_read_storage_content
void(*) labelfunc(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
NodeGetCompositorOperationFunction get_compositor_operation
NodeExtraInfoFunction get_extra_info
NodeGeometryExecFunction geometry_node_execute
void(*) draw_buttons_ex(ui::Layout &, bContext *C, PointerRNA *ptr)
void(*) initfunc(bNodeTree *ntree, bNode *node)
const char * enum_name_legacy
NodeDeclareFunction declare
void(*) free_self(bNodeType *ntype)
bool(*) insert_link(NodeInsertLinkParams ¶ms)
bool(*) poll_instance(const bNode *node, const bNodeTree *nodetree, const char **r_disabled_hint)
void use_property_decorate_set(bool is_decorate)
void textbox_with_state(PointerRNA *ptr, StringRefNull propname, TextboxState *textbox_state, std::optional< StringRefNull > name_opt=std::nullopt, std::optional< StringRefNull > placeholder=std::nullopt)
void use_property_split_set(bool is_sep)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)