This refactors how a geometry nodes node tree is converted to a lazy-function graph. Previously, all nodes were inserted into a single graph. This was fine because every node was evaluated at most once per node group evaluation. However, loops (#108896) break this assumption since now nodes may be evaluated multiple times and thus a single flat graph does not work anymore. Now, a separate lazy-function is build for every zone which gives us much more flexibility for what can happen in a zone. Right now, the change only applies to simulation zones since that's the only kind of zone we have. Technically, those zones could be inlined, but turning them into a separate lazy-function also does not hurt and makes it possible to test this refactor without implementing loops first. Also, having them as separate functions might help in the future if we integrate a substep loop directly into the simulation zone. The most tricky part here is to just link everything up correctly, especially with respect to deterministic anonymous attribute lifetimes. Fortunately, correctness can be checked visually by looking at the generated graphs. The logging/viewer system also had to be refactored a bit, because now there can be multiple different `ComputeContext` in a single node tree. Each zone is in a separate `ComputeContext`. To make it work, the `ViewerPath` system now explicitly supports zones and drawing code will look up the right logger for showing inspection data. No functional changes are expected, except that the spreadsheet now shows "Simulation Zone" in the context path if the viewer is in a simulation.
72 lines
2.2 KiB
C++
72 lines
2.2 KiB
C++
/* SPDX-FileCopyrightText: 2023 Blender Foundation
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#pragma once
|
|
|
|
#include <optional>
|
|
|
|
#include "BLI_string_ref.hh"
|
|
#include "BLI_vector.hh"
|
|
|
|
#include "BKE_viewer_path.h"
|
|
|
|
struct Main;
|
|
struct SpaceNode;
|
|
struct bNode;
|
|
struct bContext;
|
|
struct Object;
|
|
|
|
namespace blender::ed::viewer_path {
|
|
|
|
/**
|
|
* Activates the given node in the context provided by the editor. This indirectly updates all
|
|
* non-pinned viewer paths in other editors (spreadsheet and 3d view).
|
|
*/
|
|
void activate_geometry_node(Main &bmain, SpaceNode &snode, bNode &node);
|
|
|
|
/**
|
|
* Returns the object referenced by the viewer path. This only returns something if the viewer path
|
|
* *only* contains the object and nothing more.
|
|
*/
|
|
Object *parse_object_only(const ViewerPath &viewer_path);
|
|
|
|
/**
|
|
* Represents a parsed #ViewerPath for easier consumption.
|
|
*/
|
|
struct ViewerPathForGeometryNodesViewer {
|
|
Object *object;
|
|
blender::StringRefNull modifier_name;
|
|
/* Contains only group node and simulation zone elements. */
|
|
blender::Vector<const ViewerPathElem *> node_path;
|
|
int32_t viewer_node_id;
|
|
};
|
|
|
|
/**
|
|
* Parses a #ViewerPath into a #ViewerPathForGeometryNodesViewer or returns none if that does not
|
|
* work.
|
|
*/
|
|
std::optional<ViewerPathForGeometryNodesViewer> parse_geometry_nodes_viewer(
|
|
const ViewerPath &viewer_path);
|
|
|
|
/**
|
|
* Finds the node referenced by the #ViewerPath within the provided editor. If no node is
|
|
* referenced, null is returned. When two different editors show the same node group but in a
|
|
* different context, it's possible that the same node is active in one editor but not the other.
|
|
*/
|
|
bNode *find_geometry_nodes_viewer(const ViewerPath &viewer_path, SpaceNode &snode);
|
|
|
|
/**
|
|
* Checks if the node referenced by the viewer path and its entire context still exists. The node
|
|
* does not have to be visible for this to return true.
|
|
*/
|
|
bool exists_geometry_nodes_viewer(const ViewerPathForGeometryNodesViewer &parsed_viewer_path);
|
|
|
|
/**
|
|
* Checks if the node referenced by the viewer and its entire context is still active, i.e. some
|
|
* editor is showing it.
|
|
*/
|
|
bool is_active_geometry_nodes_viewer(const bContext &C, const ViewerPath &viewer_path);
|
|
|
|
} // namespace blender::ed::viewer_path
|