Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/nodes/intern')
-rw-r--r--source/blender/nodes/intern/derived_node_tree.cc139
-rw-r--r--source/blender/nodes/intern/geometry_nodes_eval_log.cc32
-rw-r--r--source/blender/nodes/intern/node_common.cc15
-rw-r--r--source/blender/nodes/intern/node_geometry_exec.cc51
-rw-r--r--source/blender/nodes/intern/node_multi_function.cc8
-rw-r--r--source/blender/nodes/intern/node_tree_ref.cc678
-rw-r--r--source/blender/nodes/intern/node_util.c2
7 files changed, 146 insertions, 779 deletions
diff --git a/source/blender/nodes/intern/derived_node_tree.cc b/source/blender/nodes/intern/derived_node_tree.cc
index e589da09b16..e8e0f0fa61c 100644
--- a/source/blender/nodes/intern/derived_node_tree.cc
+++ b/source/blender/nodes/intern/derived_node_tree.cc
@@ -2,38 +2,38 @@
#include "NOD_derived_node_tree.hh"
+#include "BKE_node.h"
+
#include "BLI_dot_export.hh"
namespace blender::nodes {
-DerivedNodeTree::DerivedNodeTree(bNodeTree &btree, NodeTreeRefMap &node_tree_refs)
+DerivedNodeTree::DerivedNodeTree(const bNodeTree &btree)
{
/* Construct all possible contexts immediately. This is significantly cheaper than inlining all
* node groups. If it still becomes a performance issue in the future, contexts could be
* constructed lazily when they are needed. */
- root_context_ = &this->construct_context_recursively(nullptr, nullptr, btree, node_tree_refs);
+ root_context_ = &this->construct_context_recursively(nullptr, nullptr, btree);
}
DTreeContext &DerivedNodeTree::construct_context_recursively(DTreeContext *parent_context,
- const NodeRef *parent_node,
- bNodeTree &btree,
- NodeTreeRefMap &node_tree_refs)
+ const bNode *parent_node,
+ const bNodeTree &btree)
{
+ btree.ensure_topology_cache();
DTreeContext &context = *allocator_.construct<DTreeContext>().release();
context.parent_context_ = parent_context;
context.parent_node_ = parent_node;
context.derived_tree_ = this;
- context.tree_ = &get_tree_ref_from_map(node_tree_refs, btree);
- used_node_tree_refs_.add(context.tree_);
+ context.btree_ = &btree;
+ used_btrees_.add(context.btree_);
- for (const NodeRef *node : context.tree_->nodes()) {
- if (node->is_group_node()) {
- bNode *bnode = node->bnode();
+ for (const bNode *bnode : context.btree_->all_nodes()) {
+ if (bnode->is_group()) {
bNodeTree *child_btree = reinterpret_cast<bNodeTree *>(bnode->id);
if (child_btree != nullptr) {
- DTreeContext &child = this->construct_context_recursively(
- &context, node, *child_btree, node_tree_refs);
- context.children_.add_new(node, &child);
+ DTreeContext &child = this->construct_context_recursively(&context, bnode, *child_btree);
+ context.children_.add_new(bnode, &child);
}
}
}
@@ -57,8 +57,8 @@ void DerivedNodeTree::destruct_context_recursively(DTreeContext *context)
bool DerivedNodeTree::has_link_cycles() const
{
- for (const NodeTreeRef *tree_ref : used_node_tree_refs_) {
- if (tree_ref->has_link_cycles()) {
+ for (const bNodeTree *btree : used_btrees_) {
+ if (btree->has_link_cycle()) {
return true;
}
}
@@ -67,8 +67,8 @@ bool DerivedNodeTree::has_link_cycles() const
bool DerivedNodeTree::has_undefined_nodes_or_sockets() const
{
- for (const NodeTreeRef *tree_ref : used_node_tree_refs_) {
- if (tree_ref->has_undefined_nodes_or_sockets()) {
+ for (const bNodeTree *btree : used_btrees_) {
+ if (btree->has_undefined_nodes_or_sockets()) {
return true;
}
}
@@ -83,8 +83,8 @@ void DerivedNodeTree::foreach_node(FunctionRef<void(DNode)> callback) const
void DerivedNodeTree::foreach_node_in_context_recursive(const DTreeContext &context,
FunctionRef<void(DNode)> callback) const
{
- for (const NodeRef *node_ref : context.tree_->nodes()) {
- callback(DNode(&context, node_ref));
+ for (const bNode *bnode : context.btree_->all_nodes()) {
+ callback(DNode(&context, bnode));
}
for (const DTreeContext *child_context : context.children_.values()) {
this->foreach_node_in_context_recursive(*child_context, callback);
@@ -94,32 +94,32 @@ void DerivedNodeTree::foreach_node_in_context_recursive(const DTreeContext &cont
DOutputSocket DInputSocket::get_corresponding_group_node_output() const
{
BLI_assert(*this);
- BLI_assert(socket_ref_->node().is_group_output_node());
- BLI_assert(socket_ref_->index() < socket_ref_->node().inputs().size() - 1);
+ BLI_assert(bsocket_->owner_node().is_group_output());
+ BLI_assert(bsocket_->index() < bsocket_->owner_node().input_sockets().size() - 1);
const DTreeContext *parent_context = context_->parent_context();
- const NodeRef *parent_node = context_->parent_node();
+ const bNode *parent_node = context_->parent_node();
BLI_assert(parent_context != nullptr);
BLI_assert(parent_node != nullptr);
- const int socket_index = socket_ref_->index();
- return {parent_context, &parent_node->output(socket_index)};
+ const int socket_index = bsocket_->index();
+ return {parent_context, &parent_node->output_socket(socket_index)};
}
Vector<DOutputSocket> DInputSocket::get_corresponding_group_input_sockets() const
{
BLI_assert(*this);
- BLI_assert(socket_ref_->node().is_group_node());
+ BLI_assert(bsocket_->owner_node().is_group());
- const DTreeContext *child_context = context_->child_context(socket_ref_->node());
+ const DTreeContext *child_context = context_->child_context(bsocket_->owner_node());
BLI_assert(child_context != nullptr);
- const NodeTreeRef &child_tree = child_context->tree();
- Span<const NodeRef *> group_input_nodes = child_tree.nodes_by_type("NodeGroupInput");
- const int socket_index = socket_ref_->index();
+ const bNodeTree &child_tree = child_context->btree();
+ Span<const bNode *> group_input_nodes = child_tree.nodes_by_type("NodeGroupInput");
+ const int socket_index = bsocket_->index();
Vector<DOutputSocket> sockets;
- for (const NodeRef *group_input_node : group_input_nodes) {
- sockets.append(DOutputSocket(child_context, &group_input_node->output(socket_index)));
+ for (const bNode *group_input_node : group_input_nodes) {
+ sockets.append(DOutputSocket(child_context, &group_input_node->output_socket(socket_index)));
}
return sockets;
}
@@ -127,36 +127,36 @@ Vector<DOutputSocket> DInputSocket::get_corresponding_group_input_sockets() cons
DInputSocket DOutputSocket::get_corresponding_group_node_input() const
{
BLI_assert(*this);
- BLI_assert(socket_ref_->node().is_group_input_node());
- BLI_assert(socket_ref_->index() < socket_ref_->node().outputs().size() - 1);
+ BLI_assert(bsocket_->owner_node().is_group_input());
+ BLI_assert(bsocket_->index() < bsocket_->owner_node().output_sockets().size() - 1);
const DTreeContext *parent_context = context_->parent_context();
- const NodeRef *parent_node = context_->parent_node();
+ const bNode *parent_node = context_->parent_node();
BLI_assert(parent_context != nullptr);
BLI_assert(parent_node != nullptr);
- const int socket_index = socket_ref_->index();
- return {parent_context, &parent_node->input(socket_index)};
+ const int socket_index = bsocket_->index();
+ return {parent_context, &parent_node->input_socket(socket_index)};
}
DInputSocket DOutputSocket::get_active_corresponding_group_output_socket() const
{
BLI_assert(*this);
- BLI_assert(socket_ref_->node().is_group_node());
+ BLI_assert(bsocket_->owner_node().is_group());
- const DTreeContext *child_context = context_->child_context(socket_ref_->node());
+ const DTreeContext *child_context = context_->child_context(bsocket_->owner_node());
if (child_context == nullptr) {
/* Can happen when the group node references a non-existent group (e.g. when the group is
* linked but the original file is not found). */
return {};
}
- const NodeTreeRef &child_tree = child_context->tree();
- Span<const NodeRef *> group_output_nodes = child_tree.nodes_by_type("NodeGroupOutput");
- const int socket_index = socket_ref_->index();
- for (const NodeRef *group_output_node : group_output_nodes) {
- if (group_output_node->bnode()->flag & NODE_DO_OUTPUT || group_output_nodes.size() == 1) {
- return {child_context, &group_output_node->input(socket_index)};
+ const bNodeTree &child_tree = child_context->btree();
+ Span<const bNode *> group_output_nodes = child_tree.nodes_by_type("NodeGroupOutput");
+ const int socket_index = bsocket_->index();
+ for (const bNode *group_output_node : group_output_nodes) {
+ if (group_output_node->flag & NODE_DO_OUTPUT || group_output_nodes.size() == 1) {
+ return {child_context, &group_output_node->input_socket(socket_index)};
}
}
return {};
@@ -165,11 +165,11 @@ DInputSocket DOutputSocket::get_active_corresponding_group_output_socket() const
void DInputSocket::foreach_origin_socket(FunctionRef<void(DSocket)> origin_fn) const
{
BLI_assert(*this);
- for (const OutputSocketRef *linked_socket : socket_ref_->as_input().logically_linked_sockets()) {
- const NodeRef &linked_node = linked_socket->node();
+ for (const bNodeSocket *linked_socket : bsocket_->logically_linked_sockets()) {
+ const bNode &linked_node = linked_socket->owner_node();
DOutputSocket linked_dsocket{context_, linked_socket};
- if (linked_node.is_group_input_node()) {
+ if (linked_node.is_group_input()) {
if (context_->is_root()) {
/* This is a group input in the root node group. */
origin_fn(linked_dsocket);
@@ -187,7 +187,7 @@ void DInputSocket::foreach_origin_socket(FunctionRef<void(DSocket)> origin_fn) c
}
}
}
- else if (linked_node.is_group_node()) {
+ else if (linked_node.is_group()) {
DInputSocket socket_in_group = linked_dsocket.get_active_corresponding_group_output_socket();
if (socket_in_group) {
if (socket_in_group->is_logically_linked()) {
@@ -217,16 +217,16 @@ void DOutputSocket::foreach_target_socket(ForeachTargetSocketFn target_fn) const
void DOutputSocket::foreach_target_socket(ForeachTargetSocketFn target_fn,
TargetSocketPathInfo &path_info) const
{
- for (const LinkRef *link : socket_ref_->as_output().directly_linked_links()) {
+ for (const bNodeLink *link : bsocket_->directly_linked_links()) {
if (link->is_muted()) {
continue;
}
- const DInputSocket &linked_socket{context_, &link->to()};
+ const DInputSocket &linked_socket{context_, link->tosock};
if (!linked_socket->is_available()) {
continue;
}
const DNode linked_node = linked_socket.node();
- if (linked_node->is_reroute_node()) {
+ if (linked_node->is_reroute()) {
const DInputSocket reroute_input = linked_socket;
const DOutputSocket reroute_output = linked_node.output(0);
path_info.sockets.append(reroute_input);
@@ -236,18 +236,18 @@ void DOutputSocket::foreach_target_socket(ForeachTargetSocketFn target_fn,
path_info.sockets.pop_last();
}
else if (linked_node->is_muted()) {
- for (const InternalLinkRef *internal_link : linked_node->internal_links()) {
- if (&internal_link->from() != linked_socket.socket_ref()) {
+ for (const bNodeLink *internal_link : linked_node->internal_links_span()) {
+ if (internal_link->fromsock != linked_socket.bsocket()) {
continue;
}
/* The internal link only forwards the first incoming link. */
- if (linked_socket->is_multi_input_socket()) {
+ if (linked_socket->is_multi_input()) {
if (linked_socket->directly_linked_links()[0] != link) {
continue;
}
}
const DInputSocket mute_input = linked_socket;
- const DOutputSocket mute_output{context_, &internal_link->to()};
+ const DOutputSocket mute_output{context_, internal_link->tosock};
path_info.sockets.append(mute_input);
path_info.sockets.append(mute_output);
mute_output.foreach_target_socket(target_fn, path_info);
@@ -255,8 +255,8 @@ void DOutputSocket::foreach_target_socket(ForeachTargetSocketFn target_fn,
path_info.sockets.pop_last();
}
}
- else if (linked_node->is_group_output_node()) {
- if (linked_node.node_ref() != context_->tree().group_output_node()) {
+ else if (linked_node->is_group_output()) {
+ if (linked_node.bnode() != context_->btree().group_output_node()) {
continue;
}
if (context_->is_root()) {
@@ -276,7 +276,7 @@ void DOutputSocket::foreach_target_socket(ForeachTargetSocketFn target_fn,
path_info.sockets.pop_last();
}
}
- else if (linked_node->is_group_node()) {
+ else if (linked_node->is_group()) {
/* Follow the links within the nested node group. */
path_info.sockets.append(linked_socket);
const Vector<DOutputSocket> sockets_in_group =
@@ -310,7 +310,8 @@ static dot::Cluster *get_dot_cluster_for_context(
}
dot::Cluster *parent_cluster = get_dot_cluster_for_context(
digraph, parent_context, dot_clusters);
- std::string cluster_name = context->tree().name() + " / " + context->parent_node()->name();
+ std::string cluster_name = StringRef(context->btree().id.name + 2) + " / " +
+ context->parent_node()->name;
dot::Cluster &cluster = digraph.new_cluster(cluster_name);
cluster.set_parent_cluster(parent_cluster);
return &cluster;
@@ -328,11 +329,11 @@ std::string DerivedNodeTree::to_dot() const
this->foreach_node([&](DNode node) {
/* Ignore nodes that should not show up in the final output. */
- if (node->is_muted() || node->is_group_node() || node->is_reroute_node() || node->is_frame()) {
+ if (node->is_muted() || node->is_group() || node->is_reroute() || node->is_frame()) {
return;
}
if (!node.context()->is_root()) {
- if (node->is_group_input_node() || node->is_group_output_node()) {
+ if (node->is_group_input() || node->is_group_output()) {
return;
}
}
@@ -345,22 +346,22 @@ std::string DerivedNodeTree::to_dot() const
Vector<std::string> input_names;
Vector<std::string> output_names;
- for (const InputSocketRef *socket : node->inputs()) {
+ for (const bNodeSocket *socket : node->input_sockets()) {
if (socket->is_available()) {
- input_names.append(socket->name());
+ input_names.append(socket->name);
}
}
- for (const OutputSocketRef *socket : node->outputs()) {
+ for (const bNodeSocket *socket : node->output_sockets()) {
if (socket->is_available()) {
- output_names.append(socket->name());
+ output_names.append(socket->name);
}
}
dot::NodeWithSocketsRef dot_node_with_sockets = dot::NodeWithSocketsRef(
- dot_node, node->name(), input_names, output_names);
+ dot_node, node->name, input_names, output_names);
int input_index = 0;
- for (const InputSocketRef *socket : node->inputs()) {
+ for (const bNodeSocket *socket : node->input_sockets()) {
if (socket->is_available()) {
dot_input_sockets.add_new(DInputSocket{node.context(), socket},
dot_node_with_sockets.input(input_index));
@@ -368,7 +369,7 @@ std::string DerivedNodeTree::to_dot() const
}
}
int output_index = 0;
- for (const OutputSocketRef *socket : node->outputs()) {
+ for (const bNodeSocket *socket : node->output_sockets()) {
if (socket->is_available()) {
dot_output_sockets.add_new(DOutputSocket{node.context(), socket},
dot_node_with_sockets.output(output_index));
@@ -392,7 +393,7 @@ std::string DerivedNodeTree::to_dot() const
}
}
dot::Node &dot_node = *dot_floating_inputs.lookup_or_add_cb(from_socket, [&]() {
- dot::Node &dot_node = digraph.new_node(from_socket->name());
+ dot::Node &dot_node = digraph.new_node(from_socket->name);
dot_node.set_background_color("white");
dot_node.set_shape(dot::Attr_shape::Ellipse);
dot_node.set_parent_cluster(
diff --git a/source/blender/nodes/intern/geometry_nodes_eval_log.cc b/source/blender/nodes/intern/geometry_nodes_eval_log.cc
index 85dfdf03b82..89bfa5834e8 100644
--- a/source/blender/nodes/intern/geometry_nodes_eval_log.cc
+++ b/source/blender/nodes/intern/geometry_nodes_eval_log.cc
@@ -2,6 +2,7 @@
#include "NOD_geometry_nodes_eval_log.hh"
+#include "BKE_curves.hh"
#include "BKE_geometry_set_instances.hh"
#include "DNA_modifier_types.h"
@@ -88,17 +89,17 @@ TreeLog &ModifierLog::lookup_or_add_tree_log(LogByTreeContext &log_by_tree_conte
destruct_ptr<TreeLog> owned_tree_log = allocator_.construct<TreeLog>();
tree_log = owned_tree_log.get();
log_by_tree_context.add_new(&tree_context, tree_log);
- parent_log.child_logs_.add_new(tree_context.parent_node()->name(), std::move(owned_tree_log));
+ parent_log.child_logs_.add_new(tree_context.parent_node()->name, std::move(owned_tree_log));
return *tree_log;
}
NodeLog &ModifierLog::lookup_or_add_node_log(LogByTreeContext &log_by_tree_context, DNode node)
{
TreeLog &tree_log = this->lookup_or_add_tree_log(log_by_tree_context, *node.context());
- NodeLog &node_log = *tree_log.node_logs_.lookup_or_add_cb(node->name(), [&]() {
+ NodeLog &node_log = *tree_log.node_logs_.lookup_or_add_cb(node->name, [&]() {
destruct_ptr<NodeLog> node_log = allocator_.construct<NodeLog>();
- node_log->input_logs_.resize(node->inputs().size());
- node_log->output_logs_.resize(node->outputs().size());
+ node_log->input_logs_.resize(node->input_sockets().size());
+ node_log->output_logs_.resize(node->output_sockets().size());
return node_log;
});
return node_log;
@@ -228,7 +229,7 @@ GeometryValueLog::GeometryValueLog(const GeometrySet &geometry_set, bool log_ful
all_component_types,
true,
[&](const bke::AttributeIDRef &attribute_id,
- const AttributeMetaData &meta_data,
+ const bke::AttributeMetaData &meta_data,
const GeometryComponent &UNUSED(component)) {
if (attribute_id.is_named() && names.add(attribute_id.name())) {
this->attributes_.append({attribute_id.name(), meta_data.domain, meta_data.data_type});
@@ -241,21 +242,21 @@ GeometryValueLog::GeometryValueLog(const GeometrySet &geometry_set, bool log_ful
case GEO_COMPONENT_TYPE_MESH: {
const MeshComponent &mesh_component = *(const MeshComponent *)component;
MeshInfo &info = this->mesh_info.emplace();
- info.verts_num = mesh_component.attribute_domain_num(ATTR_DOMAIN_POINT);
- info.edges_num = mesh_component.attribute_domain_num(ATTR_DOMAIN_EDGE);
- info.faces_num = mesh_component.attribute_domain_num(ATTR_DOMAIN_FACE);
+ info.verts_num = mesh_component.attribute_domain_size(ATTR_DOMAIN_POINT);
+ info.edges_num = mesh_component.attribute_domain_size(ATTR_DOMAIN_EDGE);
+ info.faces_num = mesh_component.attribute_domain_size(ATTR_DOMAIN_FACE);
break;
}
case GEO_COMPONENT_TYPE_CURVE: {
const CurveComponent &curve_component = *(const CurveComponent *)component;
CurveInfo &info = this->curve_info.emplace();
- info.splines_num = curve_component.attribute_domain_num(ATTR_DOMAIN_CURVE);
+ info.splines_num = curve_component.attribute_domain_size(ATTR_DOMAIN_CURVE);
break;
}
case GEO_COMPONENT_TYPE_POINT_CLOUD: {
const PointCloudComponent &pointcloud_component = *(const PointCloudComponent *)component;
PointCloudInfo &info = this->pointcloud_info.emplace();
- info.points_num = pointcloud_component.attribute_domain_num(ATTR_DOMAIN_POINT);
+ info.points_num = pointcloud_component.attribute_domain_size(ATTR_DOMAIN_POINT);
break;
}
case GEO_COMPONENT_TYPE_INSTANCES: {
@@ -264,6 +265,17 @@ GeometryValueLog::GeometryValueLog(const GeometrySet &geometry_set, bool log_ful
info.instances_num = instances_component.instances_num();
break;
}
+ case GEO_COMPONENT_TYPE_EDIT: {
+ const GeometryComponentEditData &edit_component = *(
+ const GeometryComponentEditData *)component;
+ if (const bke::CurvesEditHints *curve_edit_hints =
+ edit_component.curves_edit_hints_.get()) {
+ EditDataInfo &info = this->edit_data_info.emplace();
+ info.has_deform_matrices = curve_edit_hints->deform_mats.has_value();
+ info.has_deformed_positions = curve_edit_hints->positions.has_value();
+ }
+ break;
+ }
case GEO_COMPONENT_TYPE_VOLUME: {
break;
}
diff --git a/source/blender/nodes/intern/node_common.cc b/source/blender/nodes/intern/node_common.cc
index b7c5f9570e4..6402ec3f3d6 100644
--- a/source/blender/nodes/intern/node_common.cc
+++ b/source/blender/nodes/intern/node_common.cc
@@ -37,6 +37,7 @@ using blender::MultiValueMap;
using blender::Set;
using blender::Stack;
using blender::StringRef;
+using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name Node Group
@@ -160,6 +161,7 @@ static void group_verify_socket_list(bNodeTree &node_tree,
const bool ensure_extend_socket_exists)
{
ListBase old_sockets = verify_lb;
+ Vector<bNodeSocket *> ordered_old_sockets = old_sockets;
BLI_listbase_clear(&verify_lb);
LISTBASE_FOREACH (const bNodeSocket *, interface_socket, &interface_sockets) {
@@ -193,6 +195,19 @@ static void group_verify_socket_list(bNodeTree &node_tree,
LISTBASE_FOREACH_MUTABLE (bNodeSocket *, unused_socket, &old_sockets) {
nodeRemoveSocket(&node_tree, &node, unused_socket);
}
+
+ {
+ /* Check if new sockets match the old sockets. */
+ int index;
+ LISTBASE_FOREACH_INDEX (bNodeSocket *, new_socket, &verify_lb, index) {
+ if (index < ordered_old_sockets.size()) {
+ if (ordered_old_sockets[index] != new_socket) {
+ BKE_ntree_update_tag_interface(&node_tree);
+ break;
+ }
+ }
+ }
+ }
}
void node_group_update(struct bNodeTree *ntree, struct bNode *node)
diff --git a/source/blender/nodes/intern/node_geometry_exec.cc b/source/blender/nodes/intern/node_geometry_exec.cc
index 56e9c9f0496..953dce035c2 100644
--- a/source/blender/nodes/intern/node_geometry_exec.cc
+++ b/source/blender/nodes/intern/node_geometry_exec.cc
@@ -4,6 +4,7 @@
#include "DEG_depsgraph_query.h"
+#include "BKE_curves.hh"
#include "BKE_type_conversions.hh"
#include "NOD_geometry_exec.hh"
@@ -37,7 +38,7 @@ void GeoNodeExecParams::check_input_geometry_set(StringRef identifier,
const GeometrySet &geometry_set) const
{
const SocketDeclaration &decl =
- *provider_->dnode->input_by_identifier(identifier).bsocket()->runtime->declaration;
+ *provider_->dnode->input_by_identifier(identifier).runtime->declaration;
const decl::Geometry *geo_decl = dynamic_cast<const decl::Geometry *>(&decl);
if (geo_decl == nullptr) {
return;
@@ -94,16 +95,32 @@ void GeoNodeExecParams::check_input_geometry_set(StringRef identifier,
message += TIP_("Curve");
break;
}
+ case GEO_COMPONENT_TYPE_EDIT: {
+ continue;
+ }
}
this->error_message_add(NodeWarningType::Info, std::move(message));
}
}
+void GeoNodeExecParams::check_output_geometry_set(const GeometrySet &geometry_set) const
+{
+ UNUSED_VARS_NDEBUG(geometry_set);
+#ifdef DEBUG
+ if (const bke::CurvesEditHints *curve_edit_hints =
+ geometry_set.get_curve_edit_hints_for_read()) {
+ /* If this is not valid, it's likely that the number of stored deformed points does not match
+ * the number of points in the original data. */
+ BLI_assert(curve_edit_hints->is_valid());
+ }
+#endif
+}
+
const bNodeSocket *GeoNodeExecParams::find_available_socket(const StringRef name) const
{
- for (const InputSocketRef *socket : provider_->dnode->inputs()) {
- if (socket->is_available() && socket->name() == name) {
- return socket->bsocket();
+ for (const bNodeSocket *socket : provider_->dnode->runtime->inputs) {
+ if (socket->is_available() && socket->name == name) {
+ return socket;
}
}
@@ -123,10 +140,10 @@ void GeoNodeExecParams::set_default_remaining_outputs()
void GeoNodeExecParams::check_input_access(StringRef identifier,
const CPPType *requested_type) const
{
- bNodeSocket *found_socket = nullptr;
- for (const InputSocketRef *socket : provider_->dnode->inputs()) {
- if (socket->identifier() == identifier) {
- found_socket = socket->bsocket();
+ const bNodeSocket *found_socket = nullptr;
+ for (const bNodeSocket *socket : provider_->dnode->input_sockets()) {
+ if (socket->identifier == identifier) {
+ found_socket = socket;
break;
}
}
@@ -134,9 +151,9 @@ void GeoNodeExecParams::check_input_access(StringRef identifier,
if (found_socket == nullptr) {
std::cout << "Did not find an input socket with the identifier '" << identifier << "'.\n";
std::cout << "Possible identifiers are: ";
- for (const InputSocketRef *socket : provider_->dnode->inputs()) {
+ for (const bNodeSocket *socket : provider_->dnode->input_sockets()) {
if (socket->is_available()) {
- std::cout << "'" << socket->identifier() << "', ";
+ std::cout << "'" << socket->identifier << "', ";
}
}
std::cout << "\n";
@@ -165,10 +182,10 @@ void GeoNodeExecParams::check_input_access(StringRef identifier,
void GeoNodeExecParams::check_output_access(StringRef identifier, const CPPType &value_type) const
{
- bNodeSocket *found_socket = nullptr;
- for (const OutputSocketRef *socket : provider_->dnode->outputs()) {
- if (socket->identifier() == identifier) {
- found_socket = socket->bsocket();
+ const bNodeSocket *found_socket = nullptr;
+ for (const bNodeSocket *socket : provider_->dnode->output_sockets()) {
+ if (socket->identifier == identifier) {
+ found_socket = socket;
break;
}
}
@@ -176,9 +193,9 @@ void GeoNodeExecParams::check_output_access(StringRef identifier, const CPPType
if (found_socket == nullptr) {
std::cout << "Did not find an output socket with the identifier '" << identifier << "'.\n";
std::cout << "Possible identifiers are: ";
- for (const OutputSocketRef *socket : provider_->dnode->outputs()) {
- if (socket->is_available()) {
- std::cout << "'" << socket->identifier() << "', ";
+ for (const bNodeSocket *socket : provider_->dnode->output_sockets()) {
+ if (!(socket->flag & SOCK_UNAVAIL)) {
+ std::cout << "'" << socket->identifier << "', ";
}
}
std::cout << "\n";
diff --git a/source/blender/nodes/intern/node_multi_function.cc b/source/blender/nodes/intern/node_multi_function.cc
index 13bfdfbfac1..1f8397923e9 100644
--- a/source/blender/nodes/intern/node_multi_function.cc
+++ b/source/blender/nodes/intern/node_multi_function.cc
@@ -2,14 +2,14 @@
#include "NOD_multi_function.hh"
+#include "BKE_node.h"
+
namespace blender::nodes {
NodeMultiFunctions::NodeMultiFunctions(const DerivedNodeTree &tree)
{
- for (const NodeTreeRef *tree_ref : tree.used_node_tree_refs()) {
- bNodeTree *btree = tree_ref->btree();
- for (const NodeRef *node : tree_ref->nodes()) {
- bNode *bnode = node->bnode();
+ for (const bNodeTree *btree : tree.used_btrees()) {
+ for (const bNode *bnode : btree->all_nodes()) {
if (bnode->typeinfo->build_multi_function == nullptr) {
continue;
}
diff --git a/source/blender/nodes/intern/node_tree_ref.cc b/source/blender/nodes/intern/node_tree_ref.cc
deleted file mode 100644
index 64a8690a869..00000000000
--- a/source/blender/nodes/intern/node_tree_ref.cc
+++ /dev/null
@@ -1,678 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-
-#include <mutex>
-
-#include "NOD_node_tree_ref.hh"
-
-#include "BLI_dot_export.hh"
-#include "BLI_stack.hh"
-
-#include "RNA_prototypes.h"
-
-namespace blender::nodes {
-
-NodeTreeRef::NodeTreeRef(bNodeTree *btree) : btree_(btree)
-{
- Map<bNode *, NodeRef *> node_mapping;
-
- LISTBASE_FOREACH (bNode *, bnode, &btree->nodes) {
- NodeRef &node = *allocator_.construct<NodeRef>().release();
-
- node.tree_ = this;
- node.bnode_ = bnode;
- node.id_ = nodes_by_id_.append_and_get_index(&node);
-
- LISTBASE_FOREACH (bNodeSocket *, bsocket, &bnode->inputs) {
- InputSocketRef &socket = *allocator_.construct<InputSocketRef>().release();
- socket.node_ = &node;
- socket.index_ = node.inputs_.append_and_get_index(&socket);
- socket.is_input_ = true;
- socket.bsocket_ = bsocket;
- socket.id_ = sockets_by_id_.append_and_get_index(&socket);
- }
-
- LISTBASE_FOREACH (bNodeSocket *, bsocket, &bnode->outputs) {
- OutputSocketRef &socket = *allocator_.construct<OutputSocketRef>().release();
- socket.node_ = &node;
- socket.index_ = node.outputs_.append_and_get_index(&socket);
- socket.is_input_ = false;
- socket.bsocket_ = bsocket;
- socket.id_ = sockets_by_id_.append_and_get_index(&socket);
- }
-
- LISTBASE_FOREACH (bNodeLink *, blink, &bnode->internal_links) {
- InternalLinkRef &internal_link = *allocator_.construct<InternalLinkRef>().release();
- internal_link.blink_ = blink;
- for (InputSocketRef *socket_ref : node.inputs_) {
- if (socket_ref->bsocket_ == blink->fromsock) {
- internal_link.from_ = socket_ref;
- break;
- }
- }
- for (OutputSocketRef *socket_ref : node.outputs_) {
- if (socket_ref->bsocket_ == blink->tosock) {
- internal_link.to_ = socket_ref;
- break;
- }
- }
- BLI_assert(internal_link.from_ != nullptr);
- BLI_assert(internal_link.to_ != nullptr);
- node.internal_links_.append(&internal_link);
- }
-
- input_sockets_.extend(node.inputs_.as_span());
- output_sockets_.extend(node.outputs_.as_span());
-
- node_mapping.add_new(bnode, &node);
- }
-
- LISTBASE_FOREACH (bNodeLink *, blink, &btree->links) {
- OutputSocketRef &from_socket = this->find_output_socket(
- node_mapping, blink->fromnode, blink->fromsock);
- InputSocketRef &to_socket = this->find_input_socket(
- node_mapping, blink->tonode, blink->tosock);
-
- LinkRef &link = *allocator_.construct<LinkRef>().release();
- link.from_ = &from_socket;
- link.to_ = &to_socket;
- link.blink_ = blink;
-
- links_.append(&link);
-
- from_socket.directly_linked_links_.append(&link);
- to_socket.directly_linked_links_.append(&link);
- }
-
- for (InputSocketRef *input_socket : input_sockets_) {
- if (input_socket->is_multi_input_socket()) {
- std::sort(input_socket->directly_linked_links_.begin(),
- input_socket->directly_linked_links_.end(),
- [&](const LinkRef *a, const LinkRef *b) -> bool {
- int index_a = a->blink()->multi_input_socket_index;
- int index_b = b->blink()->multi_input_socket_index;
- return index_a > index_b;
- });
- }
- }
-
- this->create_socket_identifier_maps();
- this->create_linked_socket_caches();
-
- for (NodeRef *node : nodes_by_id_) {
- const bNodeType *nodetype = node->bnode_->typeinfo;
- nodes_by_type_.add(nodetype, node);
- }
-
- const Span<const NodeRef *> group_output_nodes = this->nodes_by_type("NodeGroupOutput");
- if (group_output_nodes.is_empty()) {
- group_output_node_ = nullptr;
- }
- else if (group_output_nodes.size() == 1) {
- group_output_node_ = group_output_nodes.first();
- }
- else {
- for (const NodeRef *group_output : group_output_nodes) {
- if (group_output->bnode_->flag & NODE_DO_OUTPUT) {
- group_output_node_ = group_output;
- break;
- }
- }
- }
-}
-
-NodeTreeRef::~NodeTreeRef()
-{
- /* The destructor has to be called manually, because these types are allocated in a linear
- * allocator. */
- for (NodeRef *node : nodes_by_id_) {
- node->~NodeRef();
- }
- for (InputSocketRef *socket : input_sockets_) {
- socket->~InputSocketRef();
- }
- for (OutputSocketRef *socket : output_sockets_) {
- socket->~OutputSocketRef();
- }
- for (LinkRef *link : links_) {
- link->~LinkRef();
- }
-}
-
-InputSocketRef &NodeTreeRef::find_input_socket(Map<bNode *, NodeRef *> &node_mapping,
- bNode *bnode,
- bNodeSocket *bsocket)
-{
- NodeRef *node = node_mapping.lookup(bnode);
- for (InputSocketRef *socket : node->inputs_) {
- if (socket->bsocket_ == bsocket) {
- return *socket;
- }
- }
- BLI_assert_unreachable();
- return *node->inputs_[0];
-}
-
-OutputSocketRef &NodeTreeRef::find_output_socket(Map<bNode *, NodeRef *> &node_mapping,
- bNode *bnode,
- bNodeSocket *bsocket)
-{
- NodeRef *node = node_mapping.lookup(bnode);
- for (OutputSocketRef *socket : node->outputs_) {
- if (socket->bsocket_ == bsocket) {
- return *socket;
- }
- }
- BLI_assert_unreachable();
- return *node->outputs_[0];
-}
-
-void NodeTreeRef::create_linked_socket_caches()
-{
- for (InputSocketRef *socket : input_sockets_) {
- /* Find directly linked socket based on incident links. */
- Vector<const SocketRef *> directly_linked_sockets;
- for (LinkRef *link : socket->directly_linked_links_) {
- directly_linked_sockets.append(link->from_);
- }
- socket->directly_linked_sockets_ = allocator_.construct_array_copy(
- directly_linked_sockets.as_span());
-
- /* Find logically linked sockets. */
- Vector<const SocketRef *> logically_linked_sockets;
- Vector<const SocketRef *> logically_linked_skipped_sockets;
- Vector<const InputSocketRef *> seen_sockets_stack;
- socket->foreach_logical_origin(
- [&](const OutputSocketRef &origin) { logically_linked_sockets.append(&origin); },
- [&](const SocketRef &socket) { logically_linked_skipped_sockets.append(&socket); },
- false,
- seen_sockets_stack);
- if (logically_linked_sockets == directly_linked_sockets) {
- socket->logically_linked_sockets_ = socket->directly_linked_sockets_;
- }
- else {
- socket->logically_linked_sockets_ = allocator_.construct_array_copy(
- logically_linked_sockets.as_span());
- }
- socket->logically_linked_skipped_sockets_ = allocator_.construct_array_copy(
- logically_linked_skipped_sockets.as_span());
- }
-
- for (OutputSocketRef *socket : output_sockets_) {
- /* Find directly linked socket based on incident links. */
- Vector<const SocketRef *> directly_linked_sockets;
- for (LinkRef *link : socket->directly_linked_links_) {
- directly_linked_sockets.append(link->to_);
- }
- socket->directly_linked_sockets_ = allocator_.construct_array_copy(
- directly_linked_sockets.as_span());
-
- /* Find logically linked sockets. */
- Vector<const SocketRef *> logically_linked_sockets;
- Vector<const SocketRef *> logically_linked_skipped_sockets;
- Vector<const OutputSocketRef *> handled_sockets;
- socket->foreach_logical_target(
- [&](const InputSocketRef &target) { logically_linked_sockets.append(&target); },
- [&](const SocketRef &socket) { logically_linked_skipped_sockets.append(&socket); },
- handled_sockets);
- if (logically_linked_sockets == directly_linked_sockets) {
- socket->logically_linked_sockets_ = socket->directly_linked_sockets_;
- }
- else {
- socket->logically_linked_sockets_ = allocator_.construct_array_copy(
- logically_linked_sockets.as_span());
- }
- socket->logically_linked_skipped_sockets_ = allocator_.construct_array_copy(
- logically_linked_skipped_sockets.as_span());
- }
-}
-
-void InputSocketRef::foreach_logical_origin(
- FunctionRef<void(const OutputSocketRef &)> origin_fn,
- FunctionRef<void(const SocketRef &)> skipped_fn,
- bool only_follow_first_input_link,
- Vector<const InputSocketRef *> &seen_sockets_stack) const
-{
- /* Protect against loops. */
- if (seen_sockets_stack.contains(this)) {
- return;
- }
- seen_sockets_stack.append(this);
-
- Span<const LinkRef *> links_to_check = this->directly_linked_links();
- if (only_follow_first_input_link) {
- links_to_check = links_to_check.take_front(1);
- }
- for (const LinkRef *link : links_to_check) {
- if (link->is_muted()) {
- continue;
- }
- const OutputSocketRef &origin = link->from();
- const NodeRef &origin_node = origin.node();
- if (!origin.is_available()) {
- /* Non available sockets are ignored. */
- }
- else if (origin_node.is_reroute_node()) {
- const InputSocketRef &reroute_input = origin_node.input(0);
- const OutputSocketRef &reroute_output = origin_node.output(0);
- skipped_fn.call_safe(reroute_input);
- skipped_fn.call_safe(reroute_output);
- reroute_input.foreach_logical_origin(origin_fn, skipped_fn, false, seen_sockets_stack);
- }
- else if (origin_node.is_muted()) {
- for (const InternalLinkRef *internal_link : origin_node.internal_links()) {
- if (&internal_link->to() == &origin) {
- const InputSocketRef &mute_input = internal_link->from();
- skipped_fn.call_safe(origin);
- skipped_fn.call_safe(mute_input);
- mute_input.foreach_logical_origin(origin_fn, skipped_fn, true, seen_sockets_stack);
- }
- }
- }
- else {
- origin_fn(origin);
- }
- }
-
- seen_sockets_stack.pop_last();
-}
-
-void OutputSocketRef::foreach_logical_target(
- FunctionRef<void(const InputSocketRef &)> target_fn,
- FunctionRef<void(const SocketRef &)> skipped_fn,
- Vector<const OutputSocketRef *> &seen_sockets_stack) const
-{
- /* Protect against loops. */
- if (seen_sockets_stack.contains(this)) {
- return;
- }
- seen_sockets_stack.append(this);
-
- for (const LinkRef *link : this->directly_linked_links()) {
- if (link->is_muted()) {
- continue;
- }
- const InputSocketRef &target = link->to();
- const NodeRef &target_node = target.node();
- if (!target.is_available()) {
- /* Non available sockets are ignored. */
- }
- else if (target_node.is_reroute_node()) {
- const OutputSocketRef &reroute_output = target_node.output(0);
- skipped_fn.call_safe(target);
- skipped_fn.call_safe(reroute_output);
- reroute_output.foreach_logical_target(target_fn, skipped_fn, seen_sockets_stack);
- }
- else if (target_node.is_muted()) {
- skipped_fn.call_safe(target);
- for (const InternalLinkRef *internal_link : target_node.internal_links()) {
- if (&internal_link->from() == &target) {
- /* The internal link only forwards the first incoming link. */
- if (target.is_multi_input_socket()) {
- if (target.directly_linked_links()[0] != link) {
- continue;
- }
- }
- const OutputSocketRef &mute_output = internal_link->to();
- skipped_fn.call_safe(target);
- skipped_fn.call_safe(mute_output);
- mute_output.foreach_logical_target(target_fn, skipped_fn, seen_sockets_stack);
- }
- }
- }
- else {
- target_fn(target);
- }
- }
-
- seen_sockets_stack.pop_last();
-}
-
-namespace {
-struct SocketByIdentifierMap {
- SocketIndexByIdentifierMap *map = nullptr;
- std::unique_ptr<SocketIndexByIdentifierMap> owned_map;
-};
-} // namespace
-
-static std::unique_ptr<SocketIndexByIdentifierMap> create_identifier_map(const ListBase &sockets)
-{
- std::unique_ptr<SocketIndexByIdentifierMap> map = std::make_unique<SocketIndexByIdentifierMap>();
- int index;
- LISTBASE_FOREACH_INDEX (bNodeSocket *, socket, &sockets, index) {
- map->add_new(socket->identifier, index);
- }
- return map;
-}
-
-/* This function is not threadsafe. */
-static SocketByIdentifierMap get_or_create_identifier_map(
- const bNode &node, const ListBase &sockets, const bNodeSocketTemplate *sockets_template)
-{
- SocketByIdentifierMap map;
- if (sockets_template == nullptr) {
- if (BLI_listbase_is_empty(&sockets)) {
- static SocketIndexByIdentifierMap empty_map;
- map.map = &empty_map;
- }
- else if (node.type == NODE_REROUTE) {
- if (&node.inputs == &sockets) {
- static SocketIndexByIdentifierMap reroute_input_map = [] {
- SocketIndexByIdentifierMap map;
- map.add_new("Input", 0);
- return map;
- }();
- map.map = &reroute_input_map;
- }
- else {
- static SocketIndexByIdentifierMap reroute_output_map = [] {
- SocketIndexByIdentifierMap map;
- map.add_new("Output", 0);
- return map;
- }();
- map.map = &reroute_output_map;
- }
- }
- else {
- /* The node has a dynamic amount of sockets. Therefore we need to create a new map. */
- map.owned_map = create_identifier_map(sockets);
- map.map = &*map.owned_map;
- }
- }
- else {
- /* Cache only one map for nodes that have the same sockets. */
- static Map<const bNodeSocketTemplate *, std::unique_ptr<SocketIndexByIdentifierMap>> maps;
- map.map = &*maps.lookup_or_add_cb(sockets_template,
- [&]() { return create_identifier_map(sockets); });
- }
- return map;
-}
-
-void NodeTreeRef::create_socket_identifier_maps()
-{
- /* `get_or_create_identifier_map` is not threadsafe, therefore we have to hold a lock here. */
- static std::mutex mutex;
- std::lock_guard lock{mutex};
-
- for (NodeRef *node : nodes_by_id_) {
- bNode &bnode = *node->bnode_;
- SocketByIdentifierMap inputs_map = get_or_create_identifier_map(
- bnode, bnode.inputs, bnode.typeinfo->inputs);
- SocketByIdentifierMap outputs_map = get_or_create_identifier_map(
- bnode, bnode.outputs, bnode.typeinfo->outputs);
- node->input_index_by_identifier_ = inputs_map.map;
- node->output_index_by_identifier_ = outputs_map.map;
- if (inputs_map.owned_map) {
- owned_identifier_maps_.append(std::move(inputs_map.owned_map));
- }
- if (outputs_map.owned_map) {
- owned_identifier_maps_.append(std::move(outputs_map.owned_map));
- }
- }
-}
-
-static bool has_link_cycles_recursive(const NodeRef &node,
- MutableSpan<bool> visited,
- MutableSpan<bool> is_in_stack)
-{
- const int node_id = node.id();
- if (is_in_stack[node_id]) {
- return true;
- }
- if (visited[node_id]) {
- return false;
- }
-
- visited[node_id] = true;
- is_in_stack[node_id] = true;
-
- for (const OutputSocketRef *from_socket : node.outputs()) {
- if (!from_socket->is_available()) {
- continue;
- }
- for (const InputSocketRef *to_socket : from_socket->directly_linked_sockets()) {
- if (!to_socket->is_available()) {
- continue;
- }
- const NodeRef &to_node = to_socket->node();
- if (has_link_cycles_recursive(to_node, visited, is_in_stack)) {
- return true;
- }
- }
- }
-
- is_in_stack[node_id] = false;
- return false;
-}
-
-bool NodeTreeRef::has_link_cycles() const
-{
- const int node_amount = nodes_by_id_.size();
- Array<bool> visited(node_amount, false);
- Array<bool> is_in_stack(node_amount, false);
-
- for (const NodeRef *node : nodes_by_id_) {
- if (has_link_cycles_recursive(*node, visited, is_in_stack)) {
- return true;
- }
- }
- return false;
-}
-
-bool NodeTreeRef::has_undefined_nodes_or_sockets() const
-{
- for (const NodeRef *node : nodes_by_id_) {
- if (node->is_undefined()) {
- return true;
- }
- }
- for (const SocketRef *socket : sockets_by_id_) {
- if (socket->is_undefined()) {
- return true;
- }
- }
- return false;
-}
-
-bool NodeRef::any_input_is_directly_linked() const
-{
- for (const SocketRef *socket : inputs_) {
- if (!socket->directly_linked_sockets().is_empty()) {
- return true;
- }
- }
- return false;
-}
-
-bool NodeRef::any_output_is_directly_linked() const
-{
- for (const SocketRef *socket : outputs_) {
- if (!socket->directly_linked_sockets().is_empty()) {
- return true;
- }
- }
- return false;
-}
-
-bool NodeRef::any_socket_is_directly_linked(eNodeSocketInOut in_out) const
-{
- if (in_out == SOCK_IN) {
- return this->any_input_is_directly_linked();
- }
- return this->any_output_is_directly_linked();
-}
-
-struct ToposortNodeState {
- bool is_done = false;
- bool is_in_stack = false;
-};
-
-static void toposort_from_start_node(const NodeTreeRef::ToposortDirection direction,
- const NodeRef &start_node,
- MutableSpan<ToposortNodeState> node_states,
- NodeTreeRef::ToposortResult &result)
-{
- struct Item {
- const NodeRef *node;
- /* Index of the next socket that is checked in the depth-first search. */
- int socket_index = 0;
- /* Link index in the next socket that is checked in the depth-first search. */
- int link_index = 0;
- };
-
- /* Do a depth-first search to sort nodes topologically. */
- Stack<Item, 64> nodes_to_check;
- nodes_to_check.push({&start_node});
- while (!nodes_to_check.is_empty()) {
- Item &item = nodes_to_check.peek();
- const NodeRef &node = *item.node;
- const Span<const SocketRef *> sockets = node.sockets(
- direction == NodeTreeRef::ToposortDirection::LeftToRight ? SOCK_IN : SOCK_OUT);
-
- while (true) {
- if (item.socket_index == sockets.size()) {
- /* All sockets have already been visited. */
- break;
- }
- const SocketRef &socket = *sockets[item.socket_index];
- const Span<const SocketRef *> linked_sockets = socket.directly_linked_sockets();
- if (item.link_index == linked_sockets.size()) {
- /* All links connected to this socket have already been visited. */
- item.socket_index++;
- item.link_index = 0;
- continue;
- }
- const SocketRef &linked_socket = *linked_sockets[item.link_index];
- const NodeRef &linked_node = linked_socket.node();
- ToposortNodeState &linked_node_state = node_states[linked_node.id()];
- if (linked_node_state.is_done) {
- /* The linked node has already been visited. */
- item.link_index++;
- continue;
- }
- if (linked_node_state.is_in_stack) {
- result.has_cycle = true;
- }
- else {
- nodes_to_check.push({&linked_node});
- linked_node_state.is_in_stack = true;
- }
- break;
- }
-
- /* If no other element has been pushed, the current node can be pushed to the sorted list. */
- if (&item == &nodes_to_check.peek()) {
- ToposortNodeState &node_state = node_states[node.id()];
- node_state.is_done = true;
- node_state.is_in_stack = false;
- result.sorted_nodes.append(&node);
- nodes_to_check.pop();
- }
- }
-}
-
-NodeTreeRef::ToposortResult NodeTreeRef::toposort(const ToposortDirection direction) const
-{
- ToposortResult result;
- result.sorted_nodes.reserve(nodes_by_id_.size());
-
- Array<ToposortNodeState> node_states(nodes_by_id_.size());
-
- for (const NodeRef *node : nodes_by_id_) {
- if (node_states[node->id()].is_done) {
- /* Ignore nodes that are done already. */
- continue;
- }
- if (node->any_socket_is_directly_linked(
- direction == ToposortDirection::LeftToRight ? SOCK_OUT : SOCK_IN)) {
- /* Ignore non-start nodes. */
- continue;
- }
-
- toposort_from_start_node(direction, *node, node_states, result);
- }
-
- /* Check if the loop above forgot some nodes because there is a cycle. */
- if (result.sorted_nodes.size() < nodes_by_id_.size()) {
- result.has_cycle = true;
- for (const NodeRef *node : nodes_by_id_) {
- if (node_states[node->id()].is_done) {
- /* Ignore nodes that are done already. */
- continue;
- }
- /* Start toposort at this node which is somewhere in the middle of a loop. */
- toposort_from_start_node(direction, *node, node_states, result);
- }
- }
-
- BLI_assert(result.sorted_nodes.size() == nodes_by_id_.size());
- return result;
-}
-
-const NodeRef *NodeTreeRef::find_node(const bNode &bnode) const
-{
- for (const NodeRef *node : this->nodes_by_type(bnode.typeinfo)) {
- if (node->bnode_ == &bnode) {
- return node;
- }
- }
- return nullptr;
-}
-
-std::string NodeTreeRef::to_dot() const
-{
- dot::DirectedGraph digraph;
- digraph.set_rankdir(dot::Attr_rankdir::LeftToRight);
-
- Map<const NodeRef *, dot::NodeWithSocketsRef> dot_nodes;
-
- for (const NodeRef *node : nodes_by_id_) {
- dot::Node &dot_node = digraph.new_node("");
- dot_node.set_background_color("white");
-
- Vector<std::string> input_names;
- Vector<std::string> output_names;
- for (const InputSocketRef *socket : node->inputs()) {
- input_names.append(socket->name());
- }
- for (const OutputSocketRef *socket : node->outputs()) {
- output_names.append(socket->name());
- }
-
- dot_nodes.add_new(node,
- dot::NodeWithSocketsRef(dot_node, node->name(), input_names, output_names));
- }
-
- for (const OutputSocketRef *from_socket : output_sockets_) {
- for (const InputSocketRef *to_socket : from_socket->directly_linked_sockets()) {
- dot::NodeWithSocketsRef &from_dot_node = dot_nodes.lookup(&from_socket->node());
- dot::NodeWithSocketsRef &to_dot_node = dot_nodes.lookup(&to_socket->node());
-
- digraph.new_edge(from_dot_node.output(from_socket->index()),
- to_dot_node.input(to_socket->index()));
- }
- }
-
- return digraph.to_dot_string();
-}
-
-const NodeTreeRef &get_tree_ref_from_map(NodeTreeRefMap &node_tree_refs, bNodeTree &btree)
-{
- return *node_tree_refs.lookup_or_add_cb(&btree,
- [&]() { return std::make_unique<NodeTreeRef>(&btree); });
-}
-
-PointerRNA NodeRef::rna() const
-{
- PointerRNA rna;
- RNA_pointer_create(&tree_->btree()->id, &RNA_Node, bnode_, &rna);
- return rna;
-}
-
-PointerRNA SocketRef::rna() const
-{
- PointerRNA rna;
- RNA_pointer_create(&this->tree().btree()->id, &RNA_NodeSocket, bsocket_, &rna);
- return rna;
-}
-
-} // namespace blender::nodes
diff --git a/source/blender/nodes/intern/node_util.c b/source/blender/nodes/intern/node_util.c
index e8be093c606..ddab455509d 100644
--- a/source/blender/nodes/intern/node_util.c
+++ b/source/blender/nodes/intern/node_util.c
@@ -200,7 +200,7 @@ void node_math_label(const bNodeTree *UNUSED(ntree), const bNode *node, char *la
if (!enum_label) {
name = "Unknown";
}
- BLI_strncpy(label, IFACE_(name), maxlen);
+ BLI_strncpy(label, CTX_IFACE_(BLT_I18NCONTEXT_ID_NODETREE, name), maxlen);
}
void node_vector_math_label(const bNodeTree *UNUSED(ntree),