[Bf-blender-cvs] [8429f01d8cf] temp-geometry-nodes-evaluator-refactor: fix attribute search
Jacques Lucke
noreply at git.blender.org
Wed Sep 7 17:29:53 CEST 2022
Commit: 8429f01d8cfd3c5af972ea6b8468daca62124731
Author: Jacques Lucke
Date: Wed Sep 7 17:29:44 2022 +0200
Branches: temp-geometry-nodes-evaluator-refactor
https://developer.blender.org/rB8429f01d8cfd3c5af972ea6b8468daca62124731
fix attribute search
===================================================================
M source/blender/editors/space_node/node_draw.cc
M source/blender/editors/space_node/node_geometry_attribute_search.cc
M source/blender/editors/space_node/node_intern.hh
M source/blender/nodes/NOD_geometry_nodes_log.hh
M source/blender/nodes/intern/geometry_nodes_log.cc
===================================================================
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index f770e766522..58738449d4b 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -326,7 +326,7 @@ float2 node_from_view(const bNode &node, const float2 &co)
return result;
}
-static GeoTreeLog *get_geo_tree_log(SpaceNode &snode)
+static nodes::geo_eval_log::GeoTreeLog *get_geo_tree_log(SpaceNode &snode)
{
using namespace blender;
using namespace blender::nodes;
@@ -391,8 +391,8 @@ static bool node_socket_has_tooltip(const bNodeTree *ntree, const bNodeSocket *s
return false;
}
-static blender::nodes::geo_eval_log::ValueLog *find_socket_value_log(
- GeoTreeLog &tree_log, const bNodeSocket &query_socket)
+nodes::geo_eval_log::ValueLog *find_socket_value_log(GeoTreeLog &tree_log,
+ const bNodeSocket &query_socket)
{
using namespace blender::nodes::geo_eval_log;
tree_log.ensure_socket_values();
diff --git a/source/blender/editors/space_node/node_geometry_attribute_search.cc b/source/blender/editors/space_node/node_geometry_attribute_search.cc
index f63adefa5f6..d65647aead0 100644
--- a/source/blender/editors/space_node/node_geometry_attribute_search.cc
+++ b/source/blender/editors/space_node/node_geometry_attribute_search.cc
@@ -14,6 +14,7 @@
#include "DNA_space_types.h"
#include "BKE_context.h"
+#include "BKE_node_runtime.hh"
#include "BKE_node_tree_update.h"
#include "BKE_object.h"
@@ -49,6 +50,8 @@ BLI_STATIC_ASSERT(std::is_trivially_destructible_v<AttributeSearchData>, "");
static Vector<const GeometryAttributeInfo *> get_attribute_info_from_context(
const bContext &C, AttributeSearchData &data)
{
+ using namespace nodes::geo_eval_log;
+
SpaceNode *snode = CTX_wm_space_node(&C);
if (!snode) {
BLI_assert_unreachable();
@@ -64,41 +67,47 @@ static Vector<const GeometryAttributeInfo *> get_attribute_info_from_context(
BLI_assert_unreachable();
return {};
}
+ GeoTreeLog *tree_log = GeoModifierLog::get_tree_log_for_node_editor(*snode);
+ if (tree_log == nullptr) {
+ return {};
+ }
/* For the attribute input node, collect attribute information from all nodes in the group. */
if (node->type == GEO_NODE_INPUT_NAMED_ATTRIBUTE) {
- // const geo_log::TreeLog *tree_log = geo_log::ModifierLog::find_tree_by_node_editor_context(
- // *snode);
- // if (tree_log == nullptr) {
- // return {};
- // }
-
+ tree_log->ensure_existing_attributes();
Vector<const GeometryAttributeInfo *> attributes;
- // Set<StringRef> names;
- // tree_log->foreach_node_log([&](const geo_log::NodeLog &node_log) {
- // for (const geo_log::SocketLog &socket_log : node_log.input_logs()) {
- // const geo_log::ValueLog *value_log = socket_log.value();
- // if (const geo_log::GeometryInfoLog *geo_value_log =
- // dynamic_cast<const geo_log::GeometryInfoLog *>(value_log)) {
- // for (const GeometryAttributeInfo &attribute : geo_value_log->attributes()) {
- // if (bke::allow_procedural_attribute_access(attribute.name)) {
- // if (names.add(attribute.name)) {
- // attributes.append(&attribute);
- // }
- // }
- // }
- // }
- // }
- // });
+ for (const GeometryAttributeInfo *attribute : tree_log->existing_attributes) {
+ if (bke::allow_procedural_attribute_access(attribute->name)) {
+ attributes.append(attribute);
+ }
+ }
return attributes;
}
- return {};
- // const geo_log::NodeLog *node_log = geo_log::ModifierLog::find_node_by_node_editor_context(
- // *snode, data.node_name);
- // if (node_log == nullptr) {
- // return {};
- // }
- // return node_log->lookup_available_attributes();
+ GeoNodeLog *node_log = tree_log->nodes.lookup_ptr(node->name);
+ if (node_log == nullptr) {
+ return {};
+ }
+ Set<StringRef> names;
+ Vector<const GeometryAttributeInfo *> attributes;
+ for (const bNodeSocket *input_socket : node->input_sockets()) {
+ if (input_socket->type != SOCK_GEOMETRY) {
+ continue;
+ }
+ const ValueLog *value_log = find_socket_value_log(*tree_log, *input_socket);
+ if (value_log == nullptr) {
+ continue;
+ }
+ if (const GeometryInfoLog *geo_log = dynamic_cast<const GeometryInfoLog *>(value_log)) {
+ for (const GeometryAttributeInfo &attribute : geo_log->attributes) {
+ if (bke::allow_procedural_attribute_access(attribute.name)) {
+ if (names.add(attribute.name)) {
+ attributes.append(&attribute);
+ }
+ }
+ }
+ }
+ }
+ return attributes;
}
static void attribute_search_update_fn(
diff --git a/source/blender/editors/space_node/node_intern.hh b/source/blender/editors/space_node/node_intern.hh
index 456cbf5064d..da0f3589c3f 100644
--- a/source/blender/editors/space_node/node_intern.hh
+++ b/source/blender/editors/space_node/node_intern.hh
@@ -31,6 +31,11 @@ struct wmGizmoGroupType;
struct wmKeyConfig;
struct wmWindow;
+namespace blender::nodes::geo_eval_log {
+class ValueLog;
+class GeoTreeLog;
+} // namespace blender::nodes::geo_eval_log
+
/* Outside of blender namespace to avoid Python documentation build error with `ctypes`. */
extern "C" {
extern const char *node_context_dir[];
@@ -150,6 +155,9 @@ void node_socket_add_tooltip(const bNodeTree &ntree,
const bNodeSocket &sock,
uiLayout &layout);
+nodes::geo_eval_log::ValueLog *find_socket_value_log(nodes::geo_eval_log::GeoTreeLog &tree_log,
+ const bNodeSocket &query_socket);
+
/**
* Sort nodes by selection: unselected nodes first, then selected,
* then the active node at the very end. Relative order is kept intact.
diff --git a/source/blender/nodes/NOD_geometry_nodes_log.hh b/source/blender/nodes/NOD_geometry_nodes_log.hh
index eebde2a7c85..a56ea39e98c 100644
--- a/source/blender/nodes/NOD_geometry_nodes_log.hh
+++ b/source/blender/nodes/NOD_geometry_nodes_log.hh
@@ -16,6 +16,9 @@
#include "DNA_node_types.h"
+struct SpaceNode;
+struct NodesModifierData;
+
namespace blender::nodes::geo_eval_log {
using fn::GField;
@@ -149,12 +152,14 @@ class GeoTreeLog {
bool reduced_node_run_times_ = false;
bool reduced_socket_values_ = false;
bool reduced_viewer_node_logs_ = false;
+ bool reduced_existing_attributes_ = false;
public:
Map<std::string, GeoNodeLog> nodes;
Map<std::string, ViewerNodeLog *, 0> viewer_node_logs;
Vector<NodeWarning> all_warnings;
std::chrono::nanoseconds run_time_sum{0};
+ Vector<const GeometryAttributeInfo *> existing_attributes;
GeoTreeLog(GeoModifierLog *modifier_log, Vector<GeoTreeLogger *> tree_loggers)
: modifier_log_(modifier_log), tree_loggers_(std::move(tree_loggers))
@@ -165,6 +170,7 @@ class GeoTreeLog {
void ensure_node_run_time();
void ensure_socket_values();
void ensure_viewer_node_logs();
+ void ensure_existing_attributes();
};
class GeoModifierLog {
@@ -179,7 +185,15 @@ class GeoModifierLog {
public:
GeoTreeLogger &get_local_tree_logger(const ContextStack &context_stack);
- GeoTreeLog &get_tree_log(const ContextStackHash &context_stack);
+ GeoTreeLog &get_tree_log(const ContextStackHash &context_stack_hash);
+
+ struct ObjectAndModifier {
+ const Object *object;
+ const NodesModifierData *nmd;
+ };
+
+ static std::optional<ObjectAndModifier> get_modifier_for_node_editor(const SpaceNode &snode);
+ static GeoTreeLog *get_tree_log_for_node_editor(const SpaceNode &snode);
};
} // namespace blender::nodes::geo_eval_log
diff --git a/source/blender/nodes/intern/geometry_nodes_log.cc b/source/blender/nodes/intern/geometry_nodes_log.cc
index 6aecd052968..97e6c3a2af3 100644
--- a/source/blender/nodes/intern/geometry_nodes_log.cc
+++ b/source/blender/nodes/intern/geometry_nodes_log.cc
@@ -8,6 +8,9 @@
#include "FN_field_cpp_type.hh"
+#include "DNA_modifier_types.h"
+#include "DNA_space_types.h"
+
namespace blender::nodes::geo_eval_log {
using fn::FieldInput;
@@ -254,6 +257,38 @@ void GeoTreeLog::ensure_viewer_node_logs()
reduced_viewer_node_logs_ = true;
}
+void GeoTreeLog::ensure_existing_attributes()
+{
+ if (reduced_existing_attributes_) {
+ return;
+ }
+ this->ensure_socket_values();
+
+ Set<StringRef> names;
+
+ auto handle_value_log = [&](const ValueLog &value_log) {
+ const GeometryInfoLog *geo_log = dynamic_cast<const GeometryInfoLog *>(&value_log);
+ if (geo_log == nullptr) {
+ return;
+ }
+ for (const GeometryAttributeInfo &attribute : geo_log->attributes) {
+ if (names.add(attribute.name)) {
+ this->existing_attributes.append(&attribute);
+ }
+ }
+ };
+
+ for (const GeoNodeLog &node_log : this->nodes.values()) {
+ for (const ValueLog *value_log : node_log.input_values_.values()) {
+ handle_value_log(*value_log);
+ }
+ for (const ValueLog *value_log : node_log.output_values_.values()) {
+ handle_value_log(*value_log);
+ }
+ }
+ reduced_existing_attributes_ = true;
+}
+
GeoTreeLogger &GeoModifierLog::get_local_tree_logger(const ContextStack &context_stack)
{
LocalData &local_data = data_per_thread_.local();
@@ -296,4 +331,69 @@ GeoTreeLog &GeoModifierLog::get_tree_log(const ContextStackHash &context_stack_h
return reduced_tree_log;
}
+std::optional<GeoModifierLog::ObjectAndModifier> GeoModifierLog::get_modifier_for_node_editor(
+ const SpaceNode &snode)
+{
+ if (snode.id == nullptr) {
+ return std::nullopt;
+ }
+ if (GS(snode.id->name) != ID_OB) {
+ return std::nullopt;
+ }
+ const Object *object = reinterpret_cast<Object *>(snode.id);
+ const NodesModifierData *used_modifier = nullptr;
+ if (snode.flag & SNODE_PIN) {
+ LISTBASE_FOREACH (const ModifierData *, md, &object->modifiers) {
+ if (md->type == eModifierType_Nodes) {
+ const NodesModifierData *nmd = reinterpret_cast<const NodesModifierData *>(md);
+ /* Would be good to store the name of the pinned modifier in the nod
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list