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:
authorJacques Lucke <jacques@blender.org>2021-07-05 11:46:00 +0300
committerJacques Lucke <jacques@blender.org>2021-07-05 11:46:36 +0300
commit9009ac2c3d62e0d30d96b8d35ff5ff620cfe053b (patch)
treeb5b25b36ed769fcdc707aa4d6efd1146fb54621d /source/blender/modifiers
parent04313f1bb5ff89168099cdc03d1855ae5118d29c (diff)
Geometry Nodes: new Viewer node
This adds a viewer node similar to the one in the compositor. The icon in the headers of nodes is removed because it served the same purpose and is not necessary anymore. Node outputs can be connected to the active viewer using ctrl+shift+LMB, just like in the compositor. Right now this collides with the shortcut used in the node wrangler addon, which will be changed separately. As of now, the viewed geometry is only visible in the spreadsheet. Viewport visualization will be added separately. There are a couple of benefits of using a viewer node compared to the old approach with the icon in the node header: * Better support for nodes that have more than one geometry output. * It's more consistent with the compositor. * If attributes become decoupled from geometry in the future, the viewer can have a separate input for the attribute to visualize. * The viewer node could potentially have visualization settings. * Allows to keep "visualization points" around by having multiple viewer nodes. * Less visual clutter in node headers. Differential Revision: https://developer.blender.org/D11470
Diffstat (limited to 'source/blender/modifiers')
-rw-r--r--source/blender/modifiers/intern/MOD_nodes.cc30
-rw-r--r--source/blender/modifiers/intern/MOD_nodes_evaluator.cc32
-rw-r--r--source/blender/modifiers/intern/MOD_nodes_evaluator.hh6
3 files changed, 46 insertions, 22 deletions
diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc
index f7f7c7b0276..76eec76acb4 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -768,22 +768,6 @@ static Vector<SpaceSpreadsheet *> find_spreadsheet_editors(Main *bmain)
using PreviewSocketMap = blender::MultiValueMap<DSocket, uint64_t>;
-static DSocket try_find_preview_socket_in_node(const DNode node)
-{
- for (const SocketRef *socket : node->outputs()) {
- if (socket->bsocket()->type == SOCK_GEOMETRY) {
- return {node.context(), socket};
- }
- }
- for (const SocketRef *socket : node->inputs()) {
- if (socket->bsocket()->type == SOCK_GEOMETRY &&
- (socket->bsocket()->flag & SOCK_MULTI_INPUT) == 0) {
- return {node.context(), socket};
- }
- }
- return {};
-}
-
static DSocket try_get_socket_to_preview_for_spreadsheet(SpaceSpreadsheet *sspreadsheet,
NodesModifierData *nmd,
const ModifierEvalContext *ctx,
@@ -839,7 +823,17 @@ static DSocket try_get_socket_to_preview_for_spreadsheet(SpaceSpreadsheet *sspre
const NodeTreeRef &tree_ref = context->tree();
for (const NodeRef *node_ref : tree_ref.nodes()) {
if (node_ref->name() == last_context->node_name) {
- return try_find_preview_socket_in_node({context, node_ref});
+ const DNode viewer_node{context, node_ref};
+ DSocket socket_to_view;
+ viewer_node.input(0).foreach_origin_socket(
+ [&](const DSocket socket) { socket_to_view = socket; });
+ if (!socket_to_view) {
+ return {};
+ }
+ bNodeSocket *bsocket = socket_to_view->bsocket();
+ if (bsocket->type == SOCK_GEOMETRY && bsocket->flag != SOCK_MULTI_INPUT) {
+ return socket_to_view;
+ }
}
}
return {};
@@ -975,6 +969,8 @@ static GeometrySet compute_geometry(const DerivedNodeTree &tree,
blender::modifiers::geometry_nodes::GeometryNodesEvaluationParams eval_params;
eval_params.input_values = group_inputs;
eval_params.output_sockets = group_outputs;
+ eval_params.force_compute_sockets.extend(preview_sockets.keys().begin(),
+ preview_sockets.keys().end());
eval_params.mf_by_node = &mf_by_node;
eval_params.modifier_ = nmd;
eval_params.depsgraph = ctx->depsgraph;
diff --git a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
index 8314a443ba6..205bfa34465 100644
--- a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
+++ b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
@@ -404,6 +404,9 @@ class GeometryNodesEvaluator {
for (const DInputSocket &socket : params_.output_sockets) {
nodes_to_check.push(socket.node());
}
+ for (const DSocket &socket : params_.force_compute_sockets) {
+ nodes_to_check.push(socket.node());
+ }
/* Use the local allocator because the states do not need to outlive the evaluator. */
LinearAllocator<> &allocator = local_allocators_.local();
while (!nodes_to_check.is_empty()) {
@@ -501,7 +504,8 @@ class GeometryNodesEvaluator {
},
{});
if (output_state.potential_users == 0) {
- /* If it does not have any potential users, it is unused. */
+ /* If it does not have any potential users, it is unused. It might become required again in
+ * `schedule_initial_nodes`. */
output_state.output_usage = ValueUsage::Unused;
}
}
@@ -576,6 +580,20 @@ class GeometryNodesEvaluator {
this->set_input_required(locked_node, socket);
});
}
+ for (const DSocket socket : params_.force_compute_sockets) {
+ const DNode node = socket.node();
+ NodeState &node_state = this->get_node_state(node);
+ this->with_locked_node(node, node_state, [&](LockedNode &locked_node) {
+ if (socket->is_input()) {
+ this->set_input_required(locked_node, DInputSocket(socket));
+ }
+ else {
+ OutputState &output_state = node_state.outputs[socket->index()];
+ output_state.output_usage = ValueUsage::Required;
+ this->schedule_node(locked_node);
+ }
+ });
+ }
}
void schedule_node(LockedNode &locked_node)
@@ -1124,10 +1142,14 @@ class GeometryNodesEvaluator {
this->with_locked_node(node, node_state, [&](LockedNode &locked_node) {
output_state.potential_users -= 1;
if (output_state.potential_users == 0) {
- /* The output socket has no users anymore. */
- output_state.output_usage = ValueUsage::Unused;
- /* Schedule the origin node in case it wants to set its inputs as unused as well. */
- this->schedule_node(locked_node);
+ /* The socket might be required even though the output is not used by other sockets. That
+ * can happen when the socket is forced to be computed. */
+ if (output_state.output_usage != ValueUsage::Required) {
+ /* The output socket has no users anymore. */
+ output_state.output_usage = ValueUsage::Unused;
+ /* Schedule the origin node in case it wants to set its inputs as unused as well. */
+ this->schedule_node(locked_node);
+ }
}
});
}
diff --git a/source/blender/modifiers/intern/MOD_nodes_evaluator.hh b/source/blender/modifiers/intern/MOD_nodes_evaluator.hh
index 84249e4244e..58eb6a4cd0b 100644
--- a/source/blender/modifiers/intern/MOD_nodes_evaluator.hh
+++ b/source/blender/modifiers/intern/MOD_nodes_evaluator.hh
@@ -38,6 +38,12 @@ struct GeometryNodesEvaluationParams {
Map<DOutputSocket, GMutablePointer> input_values;
Vector<DInputSocket> output_sockets;
+ /* These sockets will be computed but are not part of the output. Their value can be retrieved in
+ * `log_socket_value_fn`. These sockets are not part of `output_sockets` because then the
+ * evaluator would have to keep the socket values in memory until the end, which might not be
+ * necessary in all cases. Sometimes `log_socket_value_fn` might just want to look at the value
+ * and then it can be freed. */
+ Vector<DSocket> force_compute_sockets;
nodes::MultiFunctionByNode *mf_by_node;
const NodesModifierData *modifier_;
Depsgraph *depsgraph;