2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2008 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup spnode
|
|
|
|
|
* \brief higher level node drawing for the node editor.
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
|
2021-12-06 16:50:44 -05:00
|
|
|
#include <iomanip>
|
|
|
|
|
|
2021-02-11 01:16:17 -06:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2019-02-27 12:34:56 +11:00
|
|
|
#include "DNA_light_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_linestyle_types.h"
|
2013-03-18 16:34:57 +00:00
|
|
|
#include "DNA_material_types.h"
|
2022-09-13 08:44:26 +02:00
|
|
|
#include "DNA_modifier_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_node_types.h"
|
2008-12-24 10:33:10 +00:00
|
|
|
#include "DNA_screen_types.h"
|
2013-03-18 16:34:57 +00:00
|
|
|
#include "DNA_space_types.h"
|
2021-12-05 17:12:25 -05:00
|
|
|
#include "DNA_text_types.h"
|
2013-03-18 16:34:57 +00:00
|
|
|
#include "DNA_texture_types.h"
|
|
|
|
|
#include "DNA_world_types.h"
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2021-12-14 11:19:47 -06:00
|
|
|
#include "BLI_array.hh"
|
2023-07-11 22:36:10 +02:00
|
|
|
#include "BLI_bounds.hh"
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
#include "BLI_convexhull_2d.h"
|
2024-10-11 12:20:58 +02:00
|
|
|
#include "BLI_function_ref.hh"
|
2025-02-11 16:59:42 +01:00
|
|
|
#include "BLI_listbase.h"
|
2021-02-16 17:15:08 -06:00
|
|
|
#include "BLI_map.hh"
|
2025-01-10 23:31:49 +01:00
|
|
|
#include "BLI_math_matrix.hh"
|
|
|
|
|
#include "BLI_math_quaternion.hh"
|
2021-03-11 18:53:29 +01:00
|
|
|
#include "BLI_set.hh"
|
2021-02-16 17:15:08 -06:00
|
|
|
#include "BLI_span.hh"
|
2023-09-01 21:37:11 +02:00
|
|
|
#include "BLI_string.h"
|
2021-02-16 17:15:08 -06:00
|
|
|
#include "BLI_string_ref.hh"
|
|
|
|
|
#include "BLI_vector.hh"
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2024-02-09 18:59:42 +01:00
|
|
|
#include "BLT_translation.hh"
|
2012-03-17 14:42:44 +00:00
|
|
|
|
2025-04-14 17:47:56 +02:00
|
|
|
#include "BKE_compute_context_cache.hh"
|
2022-09-13 08:44:26 +02:00
|
|
|
#include "BKE_compute_contexts.hh"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_context.hh"
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
#include "BKE_curves.hh"
|
2024-02-10 18:25:14 +01:00
|
|
|
#include "BKE_global.hh"
|
2024-01-20 19:17:36 +01:00
|
|
|
#include "BKE_idtype.hh"
|
2024-01-15 12:44:04 -05:00
|
|
|
#include "BKE_lib_id.hh"
|
2025-02-07 17:47:16 +01:00
|
|
|
#include "BKE_library.hh"
|
2023-12-01 19:43:16 +01:00
|
|
|
#include "BKE_main.hh"
|
2025-01-14 16:26:54 +01:00
|
|
|
#include "BKE_main_invariants.hh"
|
2023-05-15 15:14:22 +02:00
|
|
|
#include "BKE_node.hh"
|
2024-05-05 09:30:02 +02:00
|
|
|
#include "BKE_node_enum.hh"
|
2025-01-09 20:03:08 +01:00
|
|
|
#include "BKE_node_legacy_types.hh"
|
2022-09-13 08:44:26 +02:00
|
|
|
#include "BKE_node_runtime.hh"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_node_tree_update.hh"
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
#include "BKE_node_tree_zones.hh"
|
2023-10-09 23:41:53 +02:00
|
|
|
#include "BKE_object.hh"
|
2024-02-10 19:16:25 +01:00
|
|
|
#include "BKE_scene.hh"
|
2024-02-09 10:19:24 +01:00
|
|
|
#include "BKE_scene_runtime.hh"
|
2024-11-21 19:34:53 +01:00
|
|
|
#include "BKE_screen.hh"
|
2022-12-14 18:48:13 +01:00
|
|
|
#include "BKE_type_conversions.hh"
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2024-01-18 22:50:23 +02:00
|
|
|
#include "IMB_imbuf.hh"
|
2023-07-17 20:13:52 +02:00
|
|
|
|
2023-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph.hh"
|
2017-06-08 10:14:53 +02:00
|
|
|
|
2024-01-31 14:04:56 -05:00
|
|
|
#include "BLF_api.hh"
|
2013-03-18 16:34:57 +00:00
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "BIF_glutil.hh"
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2024-03-23 01:24:18 +01:00
|
|
|
#include "GPU_framebuffer.hh"
|
|
|
|
|
#include "GPU_immediate.hh"
|
|
|
|
|
#include "GPU_immediate_util.hh"
|
|
|
|
|
#include "GPU_matrix.hh"
|
|
|
|
|
#include "GPU_state.hh"
|
|
|
|
|
#include "GPU_viewport.hh"
|
2016-10-14 23:45:55 -04:00
|
|
|
|
2023-08-04 23:11:22 +02:00
|
|
|
#include "WM_api.hh"
|
|
|
|
|
#include "WM_types.hh"
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "ED_gpencil_legacy.hh"
|
2023-01-03 20:02:01 -05:00
|
|
|
#include "ED_node.hh"
|
2023-08-08 17:36:06 +02:00
|
|
|
#include "ED_node_preview.hh"
|
2023-08-04 23:11:22 +02:00
|
|
|
#include "ED_screen.hh"
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "ED_space_api.hh"
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
#include "ED_viewer_path.hh"
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2021-10-26 11:05:01 -05:00
|
|
|
#include "UI_interface.hh"
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "UI_resources.hh"
|
|
|
|
|
#include "UI_view2d.hh"
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
#include "RNA_access.hh"
|
2024-07-10 18:30:02 +02:00
|
|
|
#include "RNA_prototypes.hh"
|
2009-09-16 18:59:13 +00:00
|
|
|
|
Geometry Nodes: support attaching gizmos to input values
This adds support for attaching gizmos for input values. The goal is to make it
easier for users to set input values intuitively in the 3D viewport.
We went through multiple different possible designs until we settled on the one
implemented here. We picked it for it's flexibility and ease of use when using
geometry node assets. The core principle in the design is that **gizmos are
attached to existing input values instead of being the input value themselves**.
This actually fits the existing concept of gizmos in Blender well, but may be a
bit unintutitive in a node setup at first. The attachment is done using links in
the node editor.
The most basic usage of the node is to link a Value node to the new Linear Gizmo
node. This attaches the gizmo to the input value and allows you to change it
from the 3D view. The attachment is indicated by the gizmo icon in the sockets
which are controlled by a gizmo as well as the back-link (notice the double
link) when the gizmo is active.
The core principle makes it straight forward to control the same node setup from
the 3D view with gizmos, or by manually changing input values, or by driving the
input values procedurally.
If the input value is controlled indirectly by other inputs, it's often possible
to **automatically propagate** the gizmo to the actual input.
Backpropagation does not work for all nodes, although more nodes can be
supported over time.
This patch adds the first three gizmo nodes which cover common use cases:
* **Linear Gizmo**: Creates a gizmo that controls a float or integer value using
a linear movement of e.g. an arrow in the 3D viewport.
* **Dial Gizmo**: Creates a circular gizmo in the 3D viewport that can be
rotated to change the attached angle input.
* **Transform Gizmo**: Creates a simple gizmo for location, rotation and scale.
In the future, more built-in gizmos and potentially the ability for custom
gizmos could be added.
All gizmo nodes have a **Transform** geometry output. Using it is optional but
it is recommended when the gizmo is used to control inputs that affect a
geometry. When it is used, Blender will automatically transform the gizmos
together with the geometry that they control. To achieve this, the output should
be merged with the generated geometry using the *Join Geometry* node. The data
contained in *Transform* output is not visible geometry, but just internal
information that helps Blender to give a better user experience when using
gizmos.
The gizmo nodes have a multi-input socket. This allows **controlling multiple
values** with the same gizmo.
Only a small set of **gizmo shapes** is supported initially. It might be
extended in the future but one goal is to give the gizmos used by different node
group assets a familiar look and feel. A similar constraint exists for
**colors**. Currently, one can choose from a fixed set of colors which can be
modified in the theme settings.
The set of **visible gizmos** is determined by a multiple factors because it's
not really feasible to show all possible gizmos at all times. To see any of the
geometry nodes gizmos, the "Active Modifier" option has to be enabled in the
"Viewport Gizmos" popover. Then all gizmos are drawn for which at least one of
the following is true:
* The gizmo controls an input of the active modifier of the active object.
* The gizmo controls a value in a selected node in an open node editor.
* The gizmo controls a pinned value in an open node editor. Pinning works by
clicking the gizmo icon next to the value.
Pull Request: https://projects.blender.org/blender/blender/pulls/112677
2024-07-10 16:18:47 +02:00
|
|
|
#include "NOD_geometry_nodes_gizmos.hh"
|
2022-09-13 08:44:26 +02:00
|
|
|
#include "NOD_geometry_nodes_log.hh"
|
2021-09-24 17:02:51 +02:00
|
|
|
#include "NOD_node_declaration.hh"
|
2023-12-05 15:57:40 +01:00
|
|
|
#include "NOD_node_extra_info.hh"
|
2022-06-03 09:57:37 +02:00
|
|
|
#include "NOD_socket_declarations_geometry.hh"
|
2021-07-07 11:20:19 +02:00
|
|
|
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
#include "GEO_fillet_curves.hh"
|
|
|
|
|
|
2021-11-12 12:12:27 -06:00
|
|
|
#include "node_intern.hh" /* own include */
|
2014-11-28 15:50:43 +01:00
|
|
|
|
2022-09-17 01:50:55 +02:00
|
|
|
#include <fmt/format.h>
|
Cleanup: fewer iostreams related includes from BLI/BKE headers
Including <iostream> or similar headers is quite expensive, since it
also pulls in things like <locale> and so on. In many BLI headers,
iostreams are only used to implement some sort of "debug print",
or an operator<< for ostream.
Change some of the commonly used places to instead include <iosfwd>,
which is the standard way of forward-declaring iostreams related
classes, and move the actual debug-print / operator<< implementations
into .cc files.
This is not done for templated classes though (it would be possible
to provide explicit operator<< instantiations somewhere in the
source file, but that would lead to hard-to-figure-out linker error
whenever someone would add a different template type). There, where
possible, I changed from full <iostream> include to only the needed
<ostream> part.
For Span<T>, I just removed print_as_lines since it's not used by
anything. It could be moved into a .cc file using a similar approach
as above if needed.
Doing full blender build changes include counts this way:
- <iostream> 1986 -> 978
- <sstream> 2880 -> 925
It does not affect the total build time much though, mostly because
towards the end of it there's just several CPU cores finishing
compiling OpenVDB related source files.
Pull Request: https://projects.blender.org/blender/blender/pulls/111046
2023-08-11 12:27:56 +03:00
|
|
|
#include <sstream>
|
2022-09-17 01:50:55 +02:00
|
|
|
|
2022-09-13 08:44:26 +02:00
|
|
|
namespace geo_log = blender::nodes::geo_eval_log;
|
2023-06-20 10:25:41 +02:00
|
|
|
using blender::bke::bNodeTreeZone;
|
|
|
|
|
using blender::bke::bNodeTreeZones;
|
2023-08-08 17:36:06 +02:00
|
|
|
using blender::ed::space_node::NestedTreePreviews;
|
2023-12-05 15:57:40 +01:00
|
|
|
using blender::nodes::NodeExtraInfoRow;
|
2022-09-13 08:44:26 +02:00
|
|
|
|
2025-01-09 12:17:45 -05:00
|
|
|
namespace blender::ed::space_node {
|
|
|
|
|
|
2022-09-13 08:44:26 +02:00
|
|
|
/**
|
|
|
|
|
* This is passed to many functions which draw the node editor.
|
|
|
|
|
*/
|
|
|
|
|
struct TreeDrawContext {
|
2024-11-14 16:04:33 +01:00
|
|
|
Main *bmain;
|
|
|
|
|
wmWindow *window;
|
|
|
|
|
Scene *scene;
|
|
|
|
|
ARegion *region;
|
|
|
|
|
Depsgraph *depsgraph;
|
|
|
|
|
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
/**
|
|
|
|
|
* Whether a viewer node is active in geometry nodes can not be determined by a flag on the node
|
|
|
|
|
* alone. That's because if the node group with the viewer is used multiple times, it's only
|
|
|
|
|
* active in one of these cases.
|
|
|
|
|
* The active node is cached here to avoid doing the more expensive check for every viewer node
|
|
|
|
|
* in the tree.
|
|
|
|
|
*/
|
|
|
|
|
const bNode *active_geometry_nodes_viewer = nullptr;
|
2022-09-13 08:44:26 +02:00
|
|
|
/**
|
|
|
|
|
* Geometry nodes logs various data during execution. The logged data that corresponds to the
|
|
|
|
|
* currently drawn node tree can be retrieved from the log below.
|
|
|
|
|
*/
|
2025-04-09 09:53:48 +02:00
|
|
|
geo_log::ContextualGeoTreeLogs tree_logs;
|
2023-08-08 17:36:06 +02:00
|
|
|
|
|
|
|
|
NestedTreePreviews *nested_group_infos = nullptr;
|
2022-11-23 14:34:31 +02:00
|
|
|
/**
|
2024-12-17 13:00:50 +01:00
|
|
|
* True if there is an active compositor using the node tree, false otherwise.
|
2022-11-23 14:34:31 +02:00
|
|
|
*/
|
2024-12-17 13:00:50 +01:00
|
|
|
bool used_by_compositor = false;
|
2024-02-09 10:19:24 +01:00
|
|
|
|
2025-01-09 12:17:45 -05:00
|
|
|
Map<bNodeInstanceKey, timeit::Nanoseconds> *compositor_per_node_execution_time = nullptr;
|
2024-06-05 10:02:37 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Label for reroute nodes that is derived from upstream reroute nodes.
|
|
|
|
|
*/
|
2025-01-09 12:17:45 -05:00
|
|
|
Map<const bNode *, StringRef> reroute_auto_labels;
|
2022-09-13 08:44:26 +02:00
|
|
|
};
|
|
|
|
|
|
2025-01-09 12:17:45 -05:00
|
|
|
float grid_size_get()
|
2013-11-06 17:46:32 +00:00
|
|
|
{
|
2023-08-29 06:33:21 +02:00
|
|
|
return NODE_GRID_STEP_SIZE;
|
2013-11-06 17:46:32 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-09 12:17:45 -05:00
|
|
|
void tree_update(const bContext *C)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2013-03-18 16:34:57 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2013-04-24 20:19:01 +00:00
|
|
|
if (snode) {
|
2021-12-03 16:25:17 -05:00
|
|
|
snode_set_context(*C);
|
2013-04-24 20:19:01 +00:00
|
|
|
|
2023-08-30 12:37:21 +02:00
|
|
|
if (snode->nodetree) {
|
|
|
|
|
id_us_ensure_real(&snode->nodetree->id);
|
|
|
|
|
}
|
2013-04-24 20:19:01 +00:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* id is supposed to contain a node tree */
|
|
|
|
|
static bNodeTree *node_tree_from_ID(ID *id)
|
2009-09-16 18:59:13 +00:00
|
|
|
{
|
2013-03-18 16:34:57 +00:00
|
|
|
if (id) {
|
2020-04-16 12:06:01 +02:00
|
|
|
if (GS(id->name) == ID_NT) {
|
|
|
|
|
return (bNodeTree *)id;
|
|
|
|
|
}
|
2025-01-09 12:17:45 -05:00
|
|
|
return bke::node_tree_from_id(id);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-16 10:55:10 -06:00
|
|
|
return nullptr;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2009-09-16 18:59:13 +00:00
|
|
|
|
2025-01-09 12:17:45 -05:00
|
|
|
void tag_update_id(ID *id)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
|
|
|
|
bNodeTree *ntree = node_tree_from_ID(id);
|
2021-02-16 10:55:10 -06:00
|
|
|
if (id == nullptr || ntree == nullptr) {
|
2013-03-18 16:34:57 +00:00
|
|
|
return;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* TODO(sergey): With the new dependency graph it should be just enough to only tag ntree itself.
|
|
|
|
|
* All the users of this tree will have update flushed from the tree. */
|
2017-06-08 10:14:53 +02:00
|
|
|
DEG_id_tag_update(&ntree->id, 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
if (ntree->type == NTREE_SHADER) {
|
2017-06-08 10:14:53 +02:00
|
|
|
DEG_id_tag_update(id, 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (GS(id->name) == ID_MA) {
|
2013-06-24 22:41:33 +00:00
|
|
|
WM_main_add_notifier(NC_MATERIAL | ND_SHADING, id);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
else if (GS(id->name) == ID_LA) {
|
2013-06-24 22:41:33 +00:00
|
|
|
WM_main_add_notifier(NC_LAMP | ND_LIGHTING, id);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
else if (GS(id->name) == ID_WO) {
|
2013-06-24 22:41:33 +00:00
|
|
|
WM_main_add_notifier(NC_WORLD | ND_WORLD, id);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2009-09-16 18:59:13 +00:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
else if (ntree->type == NTREE_COMPOSIT) {
|
2012-07-09 19:58:36 +00:00
|
|
|
WM_main_add_notifier(NC_SCENE | ND_NODES, id);
|
2012-10-21 05:46:41 +00:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
else if (ntree->type == NTREE_TEXTURE) {
|
2017-06-08 10:14:53 +02:00
|
|
|
DEG_id_tag_update(id, 0);
|
2012-07-09 19:58:36 +00:00
|
|
|
WM_main_add_notifier(NC_TEXTURE | ND_NODES, id);
|
2009-09-16 18:59:13 +00:00
|
|
|
}
|
2020-12-02 13:25:25 +01:00
|
|
|
else if (ntree->type == NTREE_GEOMETRY) {
|
|
|
|
|
WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, id);
|
|
|
|
|
}
|
2014-08-27 09:49:31 +10:00
|
|
|
else if (id == &ntree->id) {
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Node groups. */
|
2017-06-08 10:14:53 +02:00
|
|
|
DEG_id_tag_update(id, 0);
|
2014-08-22 15:51:15 +02:00
|
|
|
}
|
2009-09-16 18:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
2024-04-22 19:48:57 +02:00
|
|
|
static std::string node_socket_get_tooltip(const SpaceNode *snode,
|
|
|
|
|
const bNodeTree &ntree,
|
|
|
|
|
const bNodeSocket &socket);
|
|
|
|
|
|
2023-03-06 14:24:36 +01:00
|
|
|
static const char *node_socket_get_translation_context(const bNodeSocket &socket)
|
|
|
|
|
{
|
|
|
|
|
/* The node is not explicitly defined. */
|
|
|
|
|
if (socket.runtime->declaration == nullptr) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-16 23:48:43 +01:00
|
|
|
const std::optional<std::string> &translation_context =
|
|
|
|
|
socket.runtime->declaration->translation_context;
|
2023-03-06 14:24:36 +01:00
|
|
|
|
|
|
|
|
/* Default context. */
|
2024-11-16 23:48:43 +01:00
|
|
|
if (!translation_context.has_value()) {
|
2023-03-06 14:24:36 +01:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-16 23:48:43 +01:00
|
|
|
return translation_context->c_str();
|
2023-03-06 14:24:36 +01:00
|
|
|
}
|
|
|
|
|
|
2024-04-11 00:36:31 +02:00
|
|
|
static void node_socket_add_tooltip_in_node_editor(const bNodeSocket &sock, uiLayout &layout);
|
2022-09-13 08:44:26 +02:00
|
|
|
|
2022-12-01 17:55:33 -06:00
|
|
|
/** Return true when \a a should be behind \a b and false otherwise. */
|
|
|
|
|
static bool compare_node_depth(const bNode *a, const bNode *b)
|
2012-05-22 14:13:33 +00:00
|
|
|
{
|
|
|
|
|
/* These tell if either the node or any of the parent nodes is selected.
|
2021-02-17 13:34:49 -06:00
|
|
|
* A selected parent means an unselected node is also in foreground! */
|
2015-04-20 23:37:04 +10:00
|
|
|
bool a_select = (a->flag & NODE_SELECT) != 0, b_select = (b->flag & NODE_SELECT) != 0;
|
|
|
|
|
bool a_active = (a->flag & NODE_ACTIVE) != 0, b_active = (b->flag & NODE_ACTIVE) != 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* If one is an ancestor of the other. */
|
2019-01-15 23:24:20 +11:00
|
|
|
/* XXX there might be a better sorting algorithm for stable topological sort,
|
2021-02-17 13:34:49 -06:00
|
|
|
* this is O(n^2) worst case. */
|
2020-09-08 17:19:58 +02:00
|
|
|
for (bNode *parent = a->parent; parent; parent = parent->parent) {
|
2021-02-17 13:34:49 -06:00
|
|
|
/* If B is an ancestor, it is always behind A. */
|
2019-03-26 21:16:47 +11:00
|
|
|
if (parent == b) {
|
2022-12-01 17:55:33 -06:00
|
|
|
return false;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Any selected ancestor moves the node forward. */
|
2019-03-26 21:16:47 +11:00
|
|
|
if (parent->flag & NODE_ACTIVE) {
|
2021-02-16 10:55:10 -06:00
|
|
|
a_active = true;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
if (parent->flag & NODE_SELECT) {
|
2021-02-16 10:55:10 -06:00
|
|
|
a_select = true;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
2020-09-08 17:19:58 +02:00
|
|
|
for (bNode *parent = b->parent; parent; parent = parent->parent) {
|
2021-02-17 13:34:49 -06:00
|
|
|
/* If A is an ancestor, it is always behind B. */
|
2019-03-26 21:16:47 +11:00
|
|
|
if (parent == a) {
|
2022-12-01 17:55:33 -06:00
|
|
|
return true;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Any selected ancestor moves the node forward. */
|
2019-03-26 21:16:47 +11:00
|
|
|
if (parent->flag & NODE_ACTIVE) {
|
2021-02-16 10:55:10 -06:00
|
|
|
b_active = true;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
if (parent->flag & NODE_SELECT) {
|
2021-02-16 10:55:10 -06:00
|
|
|
b_select = true;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* One of the nodes is in the background and the other not. */
|
2019-03-26 21:16:47 +11:00
|
|
|
if ((a->flag & NODE_BACKGROUND) && !(b->flag & NODE_BACKGROUND)) {
|
2020-09-02 19:10:18 +02:00
|
|
|
return true;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2022-12-01 17:55:33 -06:00
|
|
|
if ((b->flag & NODE_BACKGROUND) && !(a->flag & NODE_BACKGROUND)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* One has a higher selection state (active > selected > nothing). */
|
2022-12-01 17:55:33 -06:00
|
|
|
if (a_active && !b_active) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (b_active && !a_active) {
|
2020-09-02 19:10:18 +02:00
|
|
|
return true;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2020-07-03 17:20:08 +02:00
|
|
|
if (!b_select && (a_active || a_select)) {
|
2022-12-01 17:55:33 -06:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!a_select && (b_active || b_select)) {
|
2020-09-02 19:10:18 +02:00
|
|
|
return true;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-09-02 19:10:18 +02:00
|
|
|
return false;
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
2023-10-10 10:57:51 +02:00
|
|
|
void tree_draw_order_update(bNodeTree &ntree)
|
2012-05-22 14:13:33 +00:00
|
|
|
{
|
2022-12-01 14:53:27 -06:00
|
|
|
Array<bNode *> sort_nodes = ntree.all_nodes();
|
2024-01-18 16:11:17 -05:00
|
|
|
std::sort(sort_nodes.begin(), sort_nodes.end(), [](bNode *a, bNode *b) {
|
|
|
|
|
return a->ui_order < b->ui_order;
|
|
|
|
|
});
|
2022-12-01 17:55:33 -06:00
|
|
|
std::stable_sort(sort_nodes.begin(), sort_nodes.end(), compare_node_depth);
|
2023-10-10 10:57:51 +02:00
|
|
|
for (const int i : sort_nodes.index_range()) {
|
|
|
|
|
sort_nodes[i]->ui_order = i;
|
2022-12-01 14:53:27 -06:00
|
|
|
}
|
2023-10-10 10:57:51 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-10-10 10:57:51 +02:00
|
|
|
Array<bNode *> tree_draw_order_calc_nodes(bNodeTree &ntree)
|
|
|
|
|
{
|
|
|
|
|
Array<bNode *> nodes = ntree.all_nodes();
|
|
|
|
|
if (nodes.is_empty()) {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
std::sort(nodes.begin(), nodes.end(), [](const bNode *a, const bNode *b) {
|
|
|
|
|
return a->ui_order < b->ui_order;
|
|
|
|
|
});
|
|
|
|
|
return nodes;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-10-10 10:57:51 +02:00
|
|
|
Array<bNode *> tree_draw_order_calc_nodes_reversed(bNodeTree &ntree)
|
|
|
|
|
{
|
|
|
|
|
Array<bNode *> nodes = ntree.all_nodes();
|
|
|
|
|
if (nodes.is_empty()) {
|
|
|
|
|
return {};
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
2023-10-10 10:57:51 +02:00
|
|
|
std::sort(nodes.begin(), nodes.end(), [](const bNode *a, const bNode *b) {
|
|
|
|
|
return a->ui_order > b->ui_order;
|
|
|
|
|
});
|
|
|
|
|
return nodes;
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
2023-01-02 17:37:26 -05:00
|
|
|
static Array<uiBlock *> node_uiblocks_init(const bContext &C, const Span<bNode *> nodes)
|
2010-01-12 07:07:51 +00:00
|
|
|
{
|
2021-12-14 11:19:47 -06:00
|
|
|
Array<uiBlock *> blocks(nodes.size());
|
2024-11-14 16:04:33 +01:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Add node uiBlocks in drawing order - prevents events going to overlapping nodes. */
|
2024-11-14 16:04:33 +01:00
|
|
|
Scene *scene = CTX_data_scene(&C);
|
|
|
|
|
wmWindow *window = CTX_wm_window(&C);
|
|
|
|
|
ARegion *region = CTX_wm_region(&C);
|
2021-12-14 11:19:47 -06:00
|
|
|
for (const int i : nodes.index_range()) {
|
2024-06-19 11:20:51 +02:00
|
|
|
const bNode &node = *nodes[i];
|
|
|
|
|
std::string block_name = "node_" + std::string(node.name);
|
2025-03-31 00:36:46 +02:00
|
|
|
uiBlock *block = UI_block_begin(
|
|
|
|
|
&C, scene, window, region, std::move(block_name), blender::ui::EmbossType::Emboss);
|
2024-06-19 11:20:51 +02:00
|
|
|
blocks[node.index()] = block;
|
2023-01-03 20:02:01 -05:00
|
|
|
/* This cancels events for background nodes. */
|
2024-06-19 11:20:51 +02:00
|
|
|
UI_block_flag_enable(block, UI_BLOCK_CLIP_EVENTS);
|
2010-01-12 07:07:51 +00:00
|
|
|
}
|
2021-12-14 11:19:47 -06:00
|
|
|
|
|
|
|
|
return blocks;
|
2010-01-12 07:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
2024-12-11 21:06:41 +01:00
|
|
|
float2 node_to_view(const float2 &co)
|
Holiday coding log :)
Nice formatted version (pictures soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability
Short list of main changes:
- Transparent region option (over main region), added code to blend in/out such panels.
- Min size window now 640 x 480
- Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake.
- Macbook retina support, use command line --no-native-pixels to disable it
- Timeline Marker label was drawing wrong
- Trackpad and magic mouse: supports zoom (hold ctrl)
- Fix for splash position: removed ghost function and made window size update after creation immediate
- Fast undo buffer save now adds UI as well. Could be checked for regular file save even...
Quit.blend and temp file saving use this now.
- Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)"
- New Userpref option "Keep Session" - this always saves quit.blend, and loads on start.
This allows keeping UI and data without actual saves, until you actually save.
When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header)
- Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v).
Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards.
- User preferences (themes, keymaps, user settings) now can be saved as a separate file.
Old option is called "Save Startup File" the new one "Save User Settings".
To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still.
- OSX: fixed bug that stopped giving mouse events outside window.
This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
|
|
|
{
|
2024-12-11 21:06:41 +01:00
|
|
|
return co * UI_SCALE_FAC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static rctf node_to_rect(const bNode &node)
|
|
|
|
|
{
|
|
|
|
|
rctf rect{};
|
|
|
|
|
rect.xmin = node.location[0];
|
|
|
|
|
rect.ymin = node.location[1] - node.height;
|
|
|
|
|
rect.xmax = node.location[0] + node.width;
|
|
|
|
|
rect.ymax = node.location[1];
|
|
|
|
|
return rect;
|
Holiday coding log :)
Nice formatted version (pictures soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability
Short list of main changes:
- Transparent region option (over main region), added code to blend in/out such panels.
- Min size window now 640 x 480
- Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake.
- Macbook retina support, use command line --no-native-pixels to disable it
- Timeline Marker label was drawing wrong
- Trackpad and magic mouse: supports zoom (hold ctrl)
- Fix for splash position: removed ghost function and made window size update after creation immediate
- Fast undo buffer save now adds UI as well. Could be checked for regular file save even...
Quit.blend and temp file saving use this now.
- Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)"
- New Userpref option "Keep Session" - this always saves quit.blend, and loads on start.
This allows keeping UI and data without actual saves, until you actually save.
When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header)
- Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v).
Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards.
- User preferences (themes, keymaps, user settings) now can be saved as a separate file.
Old option is called "Save Startup File" the new one "Save User Settings".
To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still.
- OSX: fixed bug that stopped giving mouse events outside window.
This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
void node_to_updated_rect(const bNode &node, rctf &r_rect)
|
2015-08-01 16:16:16 +02:00
|
|
|
{
|
2024-12-11 21:06:41 +01:00
|
|
|
r_rect = node_to_rect(node);
|
|
|
|
|
BLI_rctf_mul(&r_rect, UI_SCALE_FAC);
|
2015-08-01 16:16:16 +02:00
|
|
|
}
|
|
|
|
|
|
2024-12-11 21:06:41 +01:00
|
|
|
float2 node_from_view(const float2 &co)
|
Holiday coding log :)
Nice formatted version (pictures soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability
Short list of main changes:
- Transparent region option (over main region), added code to blend in/out such panels.
- Min size window now 640 x 480
- Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake.
- Macbook retina support, use command line --no-native-pixels to disable it
- Timeline Marker label was drawing wrong
- Trackpad and magic mouse: supports zoom (hold ctrl)
- Fix for splash position: removed ghost function and made window size update after creation immediate
- Fast undo buffer save now adds UI as well. Could be checked for regular file save even...
Quit.blend and temp file saving use this now.
- Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)"
- New Userpref option "Keep Session" - this always saves quit.blend, and loads on start.
This allows keeping UI and data without actual saves, until you actually save.
When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header)
- Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v).
Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards.
- User preferences (themes, keymaps, user settings) now can be saved as a separate file.
Old option is called "Save Startup File" the new one "Save User Settings".
To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still.
- OSX: fixed bug that stopped giving mouse events outside window.
This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
|
|
|
{
|
2024-12-11 21:06:41 +01:00
|
|
|
return co / UI_SCALE_FAC;
|
Holiday coding log :)
Nice formatted version (pictures soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability
Short list of main changes:
- Transparent region option (over main region), added code to blend in/out such panels.
- Min size window now 640 x 480
- Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake.
- Macbook retina support, use command line --no-native-pixels to disable it
- Timeline Marker label was drawing wrong
- Trackpad and magic mouse: supports zoom (hold ctrl)
- Fix for splash position: removed ghost function and made window size update after creation immediate
- Fast undo buffer save now adds UI as well. Could be checked for regular file save even...
Quit.blend and temp file saving use this now.
- Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)"
- New Userpref option "Keep Session" - this always saves quit.blend, and loads on start.
This allows keeping UI and data without actual saves, until you actually save.
When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header)
- Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v).
Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards.
- User preferences (themes, keymaps, user settings) now can be saved as a separate file.
Old option is called "Save Startup File" the new one "Save User Settings".
To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still.
- OSX: fixed bug that stopped giving mouse events outside window.
This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
|
|
|
}
|
|
|
|
|
|
2023-08-30 12:37:21 +02:00
|
|
|
static bool is_node_panels_supported(const bNode &node)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2023-08-30 12:37:21 +02:00
|
|
|
return node.declaration() && node.declaration()->use_custom_socket_order;
|
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2023-08-30 12:37:21 +02:00
|
|
|
/* Draw UI for options, buttons, and previews. */
|
2023-09-20 17:54:18 +02:00
|
|
|
static bool node_update_basis_buttons(const bContext &C,
|
|
|
|
|
bNodeTree &ntree,
|
|
|
|
|
bNode &node,
|
2024-10-11 12:20:58 +02:00
|
|
|
blender::FunctionRef<nodes::DrawNodeLayoutFn> draw_buttons,
|
2023-09-20 17:54:18 +02:00
|
|
|
uiBlock &block,
|
|
|
|
|
int &dy)
|
2023-08-30 12:37:21 +02:00
|
|
|
{
|
|
|
|
|
/* Buttons rect? */
|
2023-09-20 17:54:18 +02:00
|
|
|
const bool node_options = draw_buttons && (node.flag & NODE_OPTIONS);
|
2023-08-30 12:37:21 +02:00
|
|
|
if (!node_options) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-24 16:45:32 +01:00
|
|
|
PointerRNA nodeptr = RNA_pointer_create_discrete(&ntree.id, &RNA_Node, &node);
|
2021-12-17 08:03:47 -06:00
|
|
|
|
2021-08-27 11:25:30 -07:00
|
|
|
/* Round the node origin because text contents are always pixel-aligned. */
|
2024-12-11 21:06:41 +01:00
|
|
|
const float2 loc = math::round(node_to_view(node.location));
|
2021-08-27 11:25:30 -07:00
|
|
|
|
2023-09-27 18:03:37 +02:00
|
|
|
dy -= NODE_DYS / 4;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-30 12:37:21 +02:00
|
|
|
uiLayout *layout = UI_block_layout(&block,
|
|
|
|
|
UI_LAYOUT_VERTICAL,
|
|
|
|
|
UI_LAYOUT_PANEL,
|
|
|
|
|
loc.x + NODE_DYS,
|
|
|
|
|
dy,
|
|
|
|
|
NODE_WIDTH(node) - NODE_DY,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
UI_style_get_dpi());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-01-17 12:17:49 +01:00
|
|
|
if (node.is_muted()) {
|
2023-08-30 12:37:21 +02:00
|
|
|
uiLayoutSetActive(layout, false);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-30 12:37:21 +02:00
|
|
|
uiLayoutSetContextPointer(layout, "node", &nodeptr);
|
|
|
|
|
|
2023-09-20 17:54:18 +02:00
|
|
|
draw_buttons(layout, (bContext *)&C, &nodeptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-30 12:37:21 +02:00
|
|
|
UI_block_align_end(&block);
|
2020-09-08 17:19:58 +02:00
|
|
|
int buty;
|
2023-08-30 12:37:21 +02:00
|
|
|
UI_block_layout_resolve(&block, nullptr, &buty);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-09-27 18:03:37 +02:00
|
|
|
dy = buty - NODE_DYS / 4;
|
2023-08-30 12:37:21 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-09-20 17:43:19 +02:00
|
|
|
const char *node_socket_get_label(const bNodeSocket *socket, const char *panel_label)
|
2023-09-19 15:34:59 +02:00
|
|
|
{
|
2023-10-12 17:51:37 +02:00
|
|
|
/* Get the short label if possible. This is used when grouping sockets under panels,
|
|
|
|
|
* to avoid redundancy in the label. */
|
2025-03-05 11:17:50 +01:00
|
|
|
const std::optional<StringRefNull> socket_short_label = bke::node_socket_short_label(*socket);
|
2023-09-19 15:34:59 +02:00
|
|
|
const char *socket_translation_context = node_socket_get_translation_context(*socket);
|
2023-10-12 17:51:37 +02:00
|
|
|
|
2024-12-02 19:24:07 +01:00
|
|
|
if (socket_short_label.has_value()) {
|
|
|
|
|
return CTX_IFACE_(socket_translation_context, socket_short_label->c_str());
|
2023-10-12 17:51:37 +02:00
|
|
|
}
|
|
|
|
|
|
2025-03-05 11:17:50 +01:00
|
|
|
const StringRefNull socket_label = bke::node_socket_label(*socket);
|
2024-12-02 19:24:07 +01:00
|
|
|
const char *translated_socket_label = CTX_IFACE_(socket_translation_context,
|
|
|
|
|
socket_label.c_str());
|
2023-09-19 15:34:59 +02:00
|
|
|
|
|
|
|
|
/* Shorten socket label if it begins with the panel label. */
|
2023-09-21 14:02:22 -04:00
|
|
|
if (panel_label) {
|
|
|
|
|
const int len_prefix = strlen(panel_label);
|
|
|
|
|
if (STREQLEN(translated_socket_label, panel_label, len_prefix) &&
|
|
|
|
|
translated_socket_label[len_prefix] == ' ')
|
|
|
|
|
{
|
|
|
|
|
return translated_socket_label + len_prefix + 1;
|
|
|
|
|
}
|
2023-09-19 15:34:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Full label. */
|
|
|
|
|
return translated_socket_label;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-30 12:37:21 +02:00
|
|
|
static bool node_update_basis_socket(const bContext &C,
|
|
|
|
|
bNodeTree &ntree,
|
|
|
|
|
bNode &node,
|
2023-09-19 15:34:59 +02:00
|
|
|
const char *panel_label,
|
2023-09-14 16:08:04 +02:00
|
|
|
bNodeSocket *input_socket,
|
|
|
|
|
bNodeSocket *output_socket,
|
2023-08-30 12:37:21 +02:00
|
|
|
uiBlock &block,
|
|
|
|
|
const int &locx,
|
|
|
|
|
int &locy)
|
|
|
|
|
{
|
2023-09-19 10:47:21 +02:00
|
|
|
if ((!input_socket || !input_socket->is_visible()) &&
|
|
|
|
|
(!output_socket || !output_socket->is_visible()))
|
2023-09-14 16:08:04 +02:00
|
|
|
{
|
2023-08-30 12:37:21 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-30 12:37:21 +02:00
|
|
|
const int topy = locy;
|
|
|
|
|
|
|
|
|
|
/* Add the half the height of a multi-input socket to cursor Y
|
|
|
|
|
* to account for the increased height of the taller sockets. */
|
2023-09-14 16:08:04 +02:00
|
|
|
const bool is_multi_input = (input_socket ? input_socket->flag & SOCK_MULTI_INPUT : false);
|
2023-08-30 12:37:21 +02:00
|
|
|
const float multi_input_socket_offset = is_multi_input ?
|
2023-09-14 16:08:04 +02:00
|
|
|
std::max(input_socket->runtime->total_inputs - 2,
|
|
|
|
|
0) *
|
2023-08-30 12:37:21 +02:00
|
|
|
NODE_MULTI_INPUT_LINK_GAP :
|
|
|
|
|
0.0f;
|
|
|
|
|
locy -= multi_input_socket_offset * 0.5f;
|
|
|
|
|
|
|
|
|
|
uiLayout *layout = UI_block_layout(&block,
|
|
|
|
|
UI_LAYOUT_VERTICAL,
|
|
|
|
|
UI_LAYOUT_PANEL,
|
|
|
|
|
locx + NODE_DYS,
|
|
|
|
|
locy,
|
|
|
|
|
NODE_WIDTH(node) - NODE_DY,
|
|
|
|
|
NODE_DY,
|
|
|
|
|
0,
|
|
|
|
|
UI_style_get_dpi());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-01-17 12:17:49 +01:00
|
|
|
if (node.is_muted()) {
|
2023-08-30 12:37:21 +02:00
|
|
|
uiLayoutSetActive(layout, false);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-30 12:37:21 +02:00
|
|
|
uiLayout *row = uiLayoutRow(layout, true);
|
2025-01-24 16:45:32 +01:00
|
|
|
PointerRNA nodeptr = RNA_pointer_create_discrete(&ntree.id, &RNA_Node, &node);
|
2023-09-14 16:08:04 +02:00
|
|
|
uiLayoutSetContextPointer(row, "node", &nodeptr);
|
|
|
|
|
|
|
|
|
|
if (input_socket) {
|
|
|
|
|
/* Context pointers for current node and socket. */
|
2025-01-24 16:45:32 +01:00
|
|
|
PointerRNA sockptr = RNA_pointer_create_discrete(&ntree.id, &RNA_NodeSocket, input_socket);
|
2023-09-14 16:08:04 +02:00
|
|
|
uiLayoutSetContextPointer(row, "socket", &sockptr);
|
|
|
|
|
|
|
|
|
|
uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_EXPAND);
|
|
|
|
|
|
2023-09-19 15:34:59 +02:00
|
|
|
input_socket->typeinfo->draw(
|
|
|
|
|
(bContext *)&C, row, &sockptr, &nodeptr, node_socket_get_label(input_socket, panel_label));
|
2023-09-14 16:08:04 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Context pointers for current node and socket. */
|
2025-01-24 16:45:32 +01:00
|
|
|
PointerRNA sockptr = RNA_pointer_create_discrete(&ntree.id, &RNA_NodeSocket, output_socket);
|
2023-09-14 16:08:04 +02:00
|
|
|
uiLayoutSetContextPointer(row, "socket", &sockptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-09-14 16:08:04 +02:00
|
|
|
/* Align output buttons to the right. */
|
|
|
|
|
uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT);
|
UI: Add support for showing socket descriptions in tooltips
Currently, hovering over a socket itself shows no tooltip at all, while
hovering over its value field shows "Default value", which is not helpful.
This patch therefore implements socket tooltips following the proposal at
https://blender.community/c/rightclickselect/2Qgbbc/.
A lot of the basic functionality was already implemented for Geometry Nodes,
where hovering over the socket itself shows introspection info.
This patch extends this by:
- Supporting dynamic tooltips on labels, which is important for good tooltip
coverage in a socket's region of the node.
- Adding a function to setting a dynamic tooltip for an entire uiLayout, which
avoids needing to set it manually for a wide variety of socket types.
- Hiding the property label field in a tooltip when dynamic tooltip is also
provided. If really needed, this label can be restored through the dynamic
tooltip, but in all current cases the label is actually pointless anyways
since the dynamic tooltip gives more accurate and specific information.
- Adding dynamic tooltips to a socket's UI layout row if it has a description
configured, both in the Node Editor as well as in the Material Properties.
Note that the patch does not add any actual tooltip content yet, just the
infrastructure to show them. By default, sockets without a description still
show the old "Default value" tooltip.
For an example of how to add socket descriptions, check the Cylinder node
in the Geometry Nodes.
Differential Revision: https://developer.blender.org/D9967
2022-04-11 02:02:12 +02:00
|
|
|
|
2023-09-14 16:08:04 +02:00
|
|
|
output_socket->typeinfo->draw((bContext *)&C,
|
|
|
|
|
row,
|
|
|
|
|
&sockptr,
|
|
|
|
|
&nodeptr,
|
2023-09-19 15:34:59 +02:00
|
|
|
node_socket_get_label(output_socket, panel_label));
|
2023-09-14 16:08:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (input_socket) {
|
2024-04-11 00:36:31 +02:00
|
|
|
node_socket_add_tooltip_in_node_editor(*input_socket, *row);
|
2023-09-14 16:08:04 +02:00
|
|
|
/* Round the socket location to stop it from jiggling. */
|
|
|
|
|
input_socket->runtime->location = float2(round(locx), round(locy - NODE_DYS));
|
|
|
|
|
}
|
|
|
|
|
if (output_socket) {
|
2024-04-11 00:36:31 +02:00
|
|
|
node_socket_add_tooltip_in_node_editor(*output_socket, *row);
|
2023-09-14 16:08:04 +02:00
|
|
|
/* Round the socket location to stop it from jiggling. */
|
|
|
|
|
output_socket->runtime->location = float2(round(locx + NODE_WIDTH(node)),
|
|
|
|
|
round(locy - NODE_DYS));
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-30 12:37:21 +02:00
|
|
|
UI_block_align_end(&block);
|
2023-09-14 16:08:04 +02:00
|
|
|
|
2023-08-30 12:37:21 +02:00
|
|
|
int buty;
|
|
|
|
|
UI_block_layout_resolve(&block, nullptr, &buty);
|
|
|
|
|
/* Ensure minimum socket height in case layout is empty. */
|
|
|
|
|
buty = min_ii(buty, topy - NODE_DY);
|
|
|
|
|
locy = buty - multi_input_socket_offset * 0.5;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
namespace flat_item {
|
2024-09-12 17:38:51 +02:00
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
enum class Type {
|
|
|
|
|
Socket,
|
|
|
|
|
Separator,
|
|
|
|
|
Layout,
|
|
|
|
|
PanelHeader,
|
|
|
|
|
PanelContentBegin,
|
|
|
|
|
PanelContentEnd,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Socket {
|
|
|
|
|
static constexpr Type type = Type::Socket;
|
2023-09-14 16:08:04 +02:00
|
|
|
bNodeSocket *input = nullptr;
|
|
|
|
|
bNodeSocket *output = nullptr;
|
|
|
|
|
const nodes::PanelDeclaration *panel_decl = nullptr;
|
2024-10-11 12:20:58 +02:00
|
|
|
};
|
|
|
|
|
struct Separator {
|
|
|
|
|
static constexpr Type type = Type::Separator;
|
|
|
|
|
};
|
|
|
|
|
struct PanelHeader {
|
|
|
|
|
static constexpr Type type = Type::PanelHeader;
|
|
|
|
|
const nodes::PanelDeclaration *decl;
|
2025-02-28 19:07:02 +01:00
|
|
|
/** Optional input that is drawn in the header. */
|
|
|
|
|
bNodeSocket *input = nullptr;
|
2024-10-11 12:20:58 +02:00
|
|
|
};
|
|
|
|
|
struct PanelContentBegin {
|
|
|
|
|
static constexpr Type type = Type::PanelContentBegin;
|
|
|
|
|
const nodes::PanelDeclaration *decl;
|
|
|
|
|
};
|
|
|
|
|
struct PanelContentEnd {
|
|
|
|
|
static constexpr Type type = Type::PanelContentEnd;
|
|
|
|
|
const nodes::PanelDeclaration *decl;
|
|
|
|
|
};
|
|
|
|
|
struct Layout {
|
|
|
|
|
static constexpr Type type = Type::Layout;
|
|
|
|
|
const nodes::LayoutDeclaration *decl;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace flat_item
|
|
|
|
|
|
|
|
|
|
struct FlatNodeItem {
|
|
|
|
|
std::variant<flat_item::Socket,
|
|
|
|
|
flat_item::Separator,
|
|
|
|
|
flat_item::PanelHeader,
|
|
|
|
|
flat_item::PanelContentBegin,
|
|
|
|
|
flat_item::PanelContentEnd,
|
|
|
|
|
flat_item::Layout>
|
|
|
|
|
item;
|
|
|
|
|
|
|
|
|
|
flat_item::Type type() const
|
2023-09-14 16:08:04 +02:00
|
|
|
{
|
2024-10-11 12:20:58 +02:00
|
|
|
return std::visit([](auto &&item) { return item.type; }, this->item);
|
2023-09-14 16:08:04 +02:00
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
};
|
2023-09-14 16:08:04 +02:00
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
static void determine_potentially_visible_panels_recursive(
|
|
|
|
|
const bNode &node, const nodes::PanelDeclaration &panel_decl, MutableSpan<bool> r_result)
|
|
|
|
|
{
|
|
|
|
|
bool potentially_visible = false;
|
|
|
|
|
for (const nodes::ItemDeclaration *item_decl : panel_decl.items) {
|
|
|
|
|
if (const auto *socket_decl = dynamic_cast<const nodes::SocketDeclaration *>(item_decl)) {
|
|
|
|
|
const bNodeSocket &socket = node.socket_by_decl(*socket_decl);
|
|
|
|
|
potentially_visible |= socket.is_visible();
|
|
|
|
|
}
|
|
|
|
|
else if (const auto *sub_panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl))
|
|
|
|
|
{
|
|
|
|
|
determine_potentially_visible_panels_recursive(node, *sub_panel_decl, r_result);
|
|
|
|
|
potentially_visible |= r_result[sub_panel_decl->index];
|
|
|
|
|
}
|
2024-09-12 17:38:51 +02:00
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
r_result[panel_decl.index] = potentially_visible;
|
|
|
|
|
}
|
2024-09-12 17:38:51 +02:00
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
/**
|
|
|
|
|
* A panel is potentially visible if it contains any socket that is available and not hidden.
|
|
|
|
|
*/
|
|
|
|
|
static void determine_potentially_visible_panels(const bNode &node, MutableSpan<bool> r_result)
|
|
|
|
|
{
|
|
|
|
|
for (const nodes::ItemDeclaration *item_decl : node.declaration()->root_items) {
|
|
|
|
|
if (const auto *panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl)) {
|
|
|
|
|
determine_potentially_visible_panels_recursive(node, *panel_decl, r_result);
|
|
|
|
|
}
|
2023-09-14 16:08:04 +02:00
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
}
|
2023-09-14 16:08:04 +02:00
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
static void determine_visible_panels_impl_recursive(const bNode &node,
|
|
|
|
|
const nodes::PanelDeclaration &panel_decl,
|
|
|
|
|
const Span<bool> potentially_visible_states,
|
|
|
|
|
MutableSpan<bool> r_result)
|
|
|
|
|
{
|
|
|
|
|
if (!potentially_visible_states[panel_decl.index]) {
|
2024-11-27 19:01:00 +11:00
|
|
|
/* This panel does not contain any visible sockets. */
|
2024-10-11 12:20:58 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
r_result[panel_decl.index] = true;
|
|
|
|
|
const bNodePanelState &panel_state = node.panel_states_array[panel_decl.index];
|
|
|
|
|
if (panel_state.is_collapsed()) {
|
2024-10-15 16:09:00 +11:00
|
|
|
/* The sub-panels can't be visible if this panel is collapsed. */
|
2024-10-11 12:20:58 +02:00
|
|
|
return;
|
2023-09-14 16:08:04 +02:00
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
for (const nodes::ItemDeclaration *item_decl : panel_decl.items) {
|
|
|
|
|
if (const auto *sub_panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl)) {
|
|
|
|
|
determine_visible_panels_impl_recursive(
|
|
|
|
|
node, *sub_panel_decl, potentially_visible_states, r_result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-12 17:38:51 +02:00
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
static void determine_visible_panels_impl(const bNode &node,
|
|
|
|
|
const Span<bool> potentially_visible_states,
|
|
|
|
|
MutableSpan<bool> r_result)
|
|
|
|
|
{
|
|
|
|
|
for (const nodes::ItemDeclaration *item_decl : node.declaration()->root_items) {
|
|
|
|
|
if (const auto *panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl)) {
|
|
|
|
|
determine_visible_panels_impl_recursive(
|
|
|
|
|
node, *panel_decl, potentially_visible_states, r_result);
|
|
|
|
|
}
|
2024-09-12 17:38:51 +02:00
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
}
|
2023-09-14 16:08:04 +02:00
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
/**
|
|
|
|
|
* A panel is visible if all of the following are true:
|
|
|
|
|
* - All parent panels are visible and not collapsed.
|
|
|
|
|
* - The panel contains any visible sockets.
|
2023-09-14 16:08:04 +02:00
|
|
|
*/
|
2024-10-11 12:20:58 +02:00
|
|
|
static void determine_visible_panels(const bNode &node, MutableSpan<bool> r_visibility_states)
|
2023-09-14 16:08:04 +02:00
|
|
|
{
|
2024-10-11 12:20:58 +02:00
|
|
|
Array<bool> potentially_visible_states(r_visibility_states.size(), false);
|
|
|
|
|
determine_potentially_visible_panels(node, potentially_visible_states);
|
|
|
|
|
determine_visible_panels_impl(node, potentially_visible_states, r_visibility_states);
|
|
|
|
|
}
|
2023-09-14 16:08:04 +02:00
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
static void add_flat_items_for_socket(bNode &node,
|
|
|
|
|
const nodes::SocketDeclaration &socket_decl,
|
|
|
|
|
const nodes::PanelDeclaration *panel_decl,
|
2025-01-20 22:53:10 +01:00
|
|
|
const nodes::SocketDeclaration *prev_socket_decl,
|
2024-10-11 12:20:58 +02:00
|
|
|
Vector<FlatNodeItem> &r_items)
|
|
|
|
|
{
|
|
|
|
|
bNodeSocket &socket = node.socket_by_decl(socket_decl);
|
2024-12-03 10:08:59 +01:00
|
|
|
if (!socket.is_visible()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-01-20 22:53:10 +01:00
|
|
|
if (socket_decl.align_with_previous_socket) {
|
|
|
|
|
if (!prev_socket_decl || !node.socket_by_decl(*prev_socket_decl).is_visible()) {
|
|
|
|
|
r_items.append({flat_item::Socket()});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2024-10-11 12:20:58 +02:00
|
|
|
r_items.append({flat_item::Socket()});
|
|
|
|
|
}
|
|
|
|
|
flat_item::Socket &item = std::get<flat_item::Socket>(r_items.last().item);
|
|
|
|
|
if (socket_decl.in_out == SOCK_IN) {
|
|
|
|
|
BLI_assert(!item.input);
|
|
|
|
|
item.input = &socket;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_assert(!item.output);
|
|
|
|
|
item.output = &socket;
|
|
|
|
|
}
|
|
|
|
|
item.panel_decl = panel_decl;
|
|
|
|
|
}
|
2023-09-14 16:08:04 +02:00
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
static void add_flat_items_for_separator(Vector<FlatNodeItem> &r_items)
|
|
|
|
|
{
|
|
|
|
|
r_items.append({flat_item::Separator()});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void add_flat_items_for_layout(const bNode &node,
|
|
|
|
|
const nodes::LayoutDeclaration &layout_decl,
|
|
|
|
|
Vector<FlatNodeItem> &r_items)
|
|
|
|
|
{
|
|
|
|
|
if (!(node.flag & NODE_OPTIONS)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
r_items.append({flat_item::Layout{&layout_decl}});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void add_flat_items_for_panel(bNode &node,
|
|
|
|
|
const nodes::PanelDeclaration &panel_decl,
|
|
|
|
|
const Span<bool> panel_visibility,
|
|
|
|
|
Vector<FlatNodeItem> &r_items)
|
|
|
|
|
{
|
|
|
|
|
if (!panel_visibility[panel_decl.index]) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-02-28 19:07:02 +01:00
|
|
|
flat_item::PanelHeader header_item;
|
|
|
|
|
header_item.decl = &panel_decl;
|
|
|
|
|
const nodes::SocketDeclaration *panel_input_decl = panel_decl.panel_input_decl();
|
|
|
|
|
if (panel_input_decl) {
|
|
|
|
|
header_item.input = &node.socket_by_decl(*panel_input_decl);
|
|
|
|
|
}
|
|
|
|
|
r_items.append({header_item});
|
|
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
const bNodePanelState &panel_state = node.panel_states_array[panel_decl.index];
|
|
|
|
|
if (panel_state.is_collapsed()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
r_items.append({flat_item::PanelContentBegin{&panel_decl}});
|
2025-01-20 22:53:10 +01:00
|
|
|
const nodes::SocketDeclaration *prev_socket_decl = nullptr;
|
2024-10-11 12:20:58 +02:00
|
|
|
for (const nodes::ItemDeclaration *item_decl : panel_decl.items) {
|
2025-02-28 19:07:02 +01:00
|
|
|
if (item_decl == panel_input_decl) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
if (const auto *socket_decl = dynamic_cast<const nodes::SocketDeclaration *>(item_decl)) {
|
2025-01-20 22:53:10 +01:00
|
|
|
add_flat_items_for_socket(node, *socket_decl, &panel_decl, prev_socket_decl, r_items);
|
|
|
|
|
prev_socket_decl = socket_decl;
|
2023-09-14 16:08:04 +02:00
|
|
|
}
|
2025-01-20 22:53:10 +01:00
|
|
|
else {
|
|
|
|
|
if (const auto *sub_panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl)) {
|
|
|
|
|
add_flat_items_for_panel(node, *sub_panel_decl, panel_visibility, r_items);
|
|
|
|
|
}
|
|
|
|
|
else if (dynamic_cast<const nodes::SeparatorDeclaration *>(item_decl)) {
|
|
|
|
|
add_flat_items_for_separator(r_items);
|
|
|
|
|
}
|
|
|
|
|
else if (const auto *layout_decl = dynamic_cast<const nodes::LayoutDeclaration *>(item_decl))
|
|
|
|
|
{
|
|
|
|
|
add_flat_items_for_layout(node, *layout_decl, r_items);
|
|
|
|
|
}
|
|
|
|
|
prev_socket_decl = nullptr;
|
2024-09-12 17:38:51 +02:00
|
|
|
}
|
2023-09-14 16:08:04 +02:00
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
r_items.append({flat_item::PanelContentEnd{&panel_decl}});
|
2023-09-14 16:08:04 +02:00
|
|
|
}
|
|
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
/**
|
|
|
|
|
* Flattens the visible panels, sockets etc. of the node into a list that is then used to draw it.
|
|
|
|
|
*/
|
|
|
|
|
static Vector<FlatNodeItem> make_flat_node_items(bNode &node)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(is_node_panels_supported(node));
|
|
|
|
|
BLI_assert(node.runtime->panels.size() == node.num_panel_states);
|
2023-09-27 11:48:40 +02:00
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
const int panels_num = node.num_panel_states;
|
|
|
|
|
Array<bool> panel_visibility(panels_num, false);
|
|
|
|
|
determine_visible_panels(node, panel_visibility);
|
2023-09-27 11:48:40 +02:00
|
|
|
|
2025-01-20 22:53:10 +01:00
|
|
|
const nodes::SocketDeclaration *prev_socket_decl = nullptr;
|
|
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
Vector<FlatNodeItem> items;
|
|
|
|
|
for (const nodes::ItemDeclaration *item_decl : node.declaration()->root_items) {
|
|
|
|
|
if (const auto *socket_decl = dynamic_cast<const nodes::SocketDeclaration *>(item_decl)) {
|
2025-01-20 22:53:10 +01:00
|
|
|
add_flat_items_for_socket(node, *socket_decl, nullptr, prev_socket_decl, items);
|
|
|
|
|
prev_socket_decl = socket_decl;
|
2023-09-27 11:48:40 +02:00
|
|
|
}
|
2025-01-20 22:53:10 +01:00
|
|
|
else {
|
|
|
|
|
if (const auto *panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl)) {
|
|
|
|
|
add_flat_items_for_panel(node, *panel_decl, panel_visibility, items);
|
|
|
|
|
}
|
|
|
|
|
else if (dynamic_cast<const nodes::SeparatorDeclaration *>(item_decl)) {
|
|
|
|
|
add_flat_items_for_separator(items);
|
|
|
|
|
}
|
|
|
|
|
else if (const auto *layout_decl = dynamic_cast<const nodes::LayoutDeclaration *>(item_decl))
|
|
|
|
|
{
|
|
|
|
|
add_flat_items_for_layout(node, *layout_decl, items);
|
|
|
|
|
}
|
|
|
|
|
prev_socket_decl = nullptr;
|
2024-10-11 12:20:58 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return items;
|
|
|
|
|
}
|
2023-08-30 12:37:21 +02:00
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
/** Get the height of an empty node body. */
|
|
|
|
|
static float get_margin_empty()
|
|
|
|
|
{
|
|
|
|
|
return NODE_DYS;
|
|
|
|
|
}
|
2023-09-06 10:34:18 +02:00
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
/** Get the margin between the node header and the first item. */
|
|
|
|
|
static float get_margin_from_top(const Span<FlatNodeItem> items)
|
|
|
|
|
{
|
|
|
|
|
const FlatNodeItem &first_item = items[0];
|
|
|
|
|
const flat_item::Type first_item_type = first_item.type();
|
|
|
|
|
switch (first_item_type) {
|
|
|
|
|
case flat_item::Type::Socket:
|
|
|
|
|
return 2 * NODE_ITEM_SPACING_Y;
|
|
|
|
|
case flat_item::Type::Separator:
|
|
|
|
|
return NODE_ITEM_SPACING_Y / 2;
|
|
|
|
|
case flat_item::Type::Layout:
|
|
|
|
|
return 3 * NODE_ITEM_SPACING_Y;
|
|
|
|
|
case flat_item::Type::PanelHeader:
|
|
|
|
|
return 4 * NODE_ITEM_SPACING_Y;
|
|
|
|
|
case flat_item::Type::PanelContentBegin:
|
|
|
|
|
case flat_item::Type::PanelContentEnd:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
BLI_assert_unreachable();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Get the margin between the last item and the node bottom. */
|
|
|
|
|
static float get_margin_to_bottom(const Span<FlatNodeItem> items)
|
|
|
|
|
{
|
|
|
|
|
const FlatNodeItem &last_item = items.last();
|
|
|
|
|
const flat_item::Type last_item_type = last_item.type();
|
|
|
|
|
switch (last_item_type) {
|
|
|
|
|
case flat_item::Type::Socket:
|
2024-12-02 15:28:26 +01:00
|
|
|
return 2 * NODE_ITEM_SPACING_Y;
|
2024-10-11 12:20:58 +02:00
|
|
|
case flat_item::Type::Separator:
|
|
|
|
|
return NODE_ITEM_SPACING_Y;
|
|
|
|
|
case flat_item::Type::Layout:
|
|
|
|
|
return 5 * NODE_ITEM_SPACING_Y;
|
|
|
|
|
case flat_item::Type::PanelHeader:
|
|
|
|
|
return 4 * NODE_ITEM_SPACING_Y;
|
|
|
|
|
case flat_item::Type::PanelContentBegin:
|
|
|
|
|
break;
|
|
|
|
|
case flat_item::Type::PanelContentEnd:
|
2024-10-11 13:38:49 +02:00
|
|
|
return 1 * NODE_ITEM_SPACING_Y;
|
2024-10-11 12:20:58 +02:00
|
|
|
}
|
|
|
|
|
BLI_assert_unreachable();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Get the margin between two consecutive items. */
|
|
|
|
|
static float get_margin_between_elements(const Span<FlatNodeItem> items, const int next_index)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(next_index >= 1);
|
|
|
|
|
const FlatNodeItem &prev = items[next_index - 1];
|
|
|
|
|
const FlatNodeItem &next = items[next_index];
|
|
|
|
|
using flat_item::Type;
|
|
|
|
|
const Type prev_type = prev.type();
|
|
|
|
|
const Type next_type = next.type();
|
|
|
|
|
|
|
|
|
|
/* Handle all cases explicitly. This simplifies modifying the margins for specific cases
|
|
|
|
|
* without breaking other cases significantly. */
|
|
|
|
|
switch (prev_type) {
|
|
|
|
|
case Type::Socket: {
|
|
|
|
|
switch (next_type) {
|
|
|
|
|
case Type::Socket:
|
|
|
|
|
return NODE_ITEM_SPACING_Y;
|
|
|
|
|
case Type::Separator:
|
|
|
|
|
return 0;
|
|
|
|
|
case Type::Layout:
|
|
|
|
|
return 2 * NODE_ITEM_SPACING_Y;
|
|
|
|
|
case Type::PanelHeader:
|
2024-10-11 13:38:49 +02:00
|
|
|
return 3 * NODE_ITEM_SPACING_Y;
|
2024-10-11 12:20:58 +02:00
|
|
|
case Type::PanelContentBegin:
|
|
|
|
|
break;
|
|
|
|
|
case Type::PanelContentEnd:
|
|
|
|
|
return 2 * NODE_ITEM_SPACING_Y;
|
2024-03-11 14:08:59 +01:00
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Type::Layout: {
|
|
|
|
|
switch (next_type) {
|
|
|
|
|
case Type::Socket:
|
|
|
|
|
return 2 * NODE_ITEM_SPACING_Y;
|
|
|
|
|
case Type::Separator:
|
|
|
|
|
return 0;
|
|
|
|
|
case Type::Layout:
|
|
|
|
|
return NODE_ITEM_SPACING_Y;
|
|
|
|
|
case Type::PanelHeader:
|
|
|
|
|
return 3 * NODE_ITEM_SPACING_Y;
|
|
|
|
|
case Type::PanelContentBegin:
|
|
|
|
|
break;
|
|
|
|
|
case Type::PanelContentEnd:
|
|
|
|
|
return 2 * NODE_ITEM_SPACING_Y;
|
2023-09-28 11:24:48 +02:00
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
break;
|
2023-09-27 11:48:40 +02:00
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
case Type::Separator: {
|
|
|
|
|
switch (next_type) {
|
|
|
|
|
case Type::Socket:
|
|
|
|
|
return 2 * NODE_ITEM_SPACING_Y;
|
|
|
|
|
case Type::Separator:
|
|
|
|
|
return NODE_ITEM_SPACING_Y;
|
|
|
|
|
case Type::Layout:
|
|
|
|
|
return NODE_ITEM_SPACING_Y;
|
|
|
|
|
case Type::PanelHeader:
|
|
|
|
|
return NODE_ITEM_SPACING_Y;
|
|
|
|
|
case Type::PanelContentBegin:
|
|
|
|
|
break;
|
|
|
|
|
case Type::PanelContentEnd:
|
|
|
|
|
return NODE_ITEM_SPACING_Y;
|
2023-09-27 11:48:40 +02:00
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Type::PanelHeader: {
|
|
|
|
|
switch (next_type) {
|
|
|
|
|
case Type::Socket:
|
|
|
|
|
return 4 * NODE_ITEM_SPACING_Y;
|
|
|
|
|
case Type::Separator:
|
|
|
|
|
return 3 * NODE_ITEM_SPACING_Y;
|
|
|
|
|
case Type::Layout:
|
|
|
|
|
return 3 * NODE_ITEM_SPACING_Y;
|
|
|
|
|
case Type::PanelHeader:
|
|
|
|
|
return 5 * NODE_ITEM_SPACING_Y;
|
|
|
|
|
case Type::PanelContentBegin:
|
|
|
|
|
return 3 * NODE_ITEM_SPACING_Y;
|
|
|
|
|
case Type::PanelContentEnd:
|
2024-10-11 13:38:49 +02:00
|
|
|
return 3 * NODE_ITEM_SPACING_Y;
|
2023-09-27 11:48:40 +02:00
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
break;
|
2023-09-27 11:48:40 +02:00
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
case Type::PanelContentBegin: {
|
|
|
|
|
switch (next_type) {
|
|
|
|
|
case Type::Socket:
|
|
|
|
|
return 2 * NODE_ITEM_SPACING_Y;
|
|
|
|
|
case Type::Separator:
|
|
|
|
|
return NODE_ITEM_SPACING_Y;
|
|
|
|
|
case Type::Layout:
|
|
|
|
|
return 2 * NODE_ITEM_SPACING_Y;
|
|
|
|
|
case Type::PanelHeader:
|
|
|
|
|
return 3 * NODE_ITEM_SPACING_Y;
|
|
|
|
|
case Type::PanelContentBegin:
|
|
|
|
|
break;
|
|
|
|
|
case Type::PanelContentEnd:
|
|
|
|
|
return NODE_ITEM_SPACING_Y;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2024-09-12 17:38:51 +02:00
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
case Type::PanelContentEnd: {
|
|
|
|
|
switch (next_type) {
|
|
|
|
|
case Type::Socket:
|
|
|
|
|
return NODE_ITEM_SPACING_Y;
|
|
|
|
|
case Type::Separator:
|
|
|
|
|
return NODE_ITEM_SPACING_Y;
|
|
|
|
|
case Type::Layout:
|
|
|
|
|
return NODE_ITEM_SPACING_Y;
|
|
|
|
|
case Type::PanelHeader:
|
|
|
|
|
return 3 * NODE_ITEM_SPACING_Y;
|
|
|
|
|
case Type::PanelContentBegin:
|
|
|
|
|
break;
|
|
|
|
|
case Type::PanelContentEnd:
|
2024-10-11 13:38:49 +02:00
|
|
|
return 0;
|
2024-10-11 12:20:58 +02:00
|
|
|
}
|
|
|
|
|
break;
|
2023-09-27 11:48:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
BLI_assert_unreachable();
|
|
|
|
|
return 0.0f;
|
2023-09-27 11:48:40 +02:00
|
|
|
}
|
2023-09-06 10:34:18 +02:00
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
/** Tags all the sockets in the panel as collapsed and updates their positions. */
|
|
|
|
|
static void mark_sockets_collapsed_recursive(bNode &node,
|
|
|
|
|
const int node_left_x,
|
|
|
|
|
const nodes::PanelDeclaration &visible_panel_decl,
|
|
|
|
|
const nodes::PanelDeclaration &panel_decl)
|
|
|
|
|
{
|
|
|
|
|
const bke::bNodePanelRuntime &visible_panel_runtime =
|
|
|
|
|
node.runtime->panels[visible_panel_decl.index];
|
|
|
|
|
for (const nodes::ItemDeclaration *item_decl : panel_decl.items) {
|
|
|
|
|
if (const auto *socket_decl = dynamic_cast<const nodes::SocketDeclaration *>(item_decl)) {
|
|
|
|
|
bNodeSocket &socket = node.socket_by_decl(*socket_decl);
|
|
|
|
|
const int socket_x = socket.in_out == SOCK_IN ? node_left_x : node_left_x + NODE_WIDTH(node);
|
|
|
|
|
socket.runtime->location = math::round(
|
|
|
|
|
float2(socket_x, *visible_panel_runtime.header_center_y));
|
|
|
|
|
socket.flag |= SOCK_PANEL_COLLAPSED;
|
2023-09-27 11:48:40 +02:00
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
else if (const auto *sub_panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl))
|
|
|
|
|
{
|
|
|
|
|
mark_sockets_collapsed_recursive(node, node_left_x, visible_panel_decl, *sub_panel_decl);
|
2023-08-30 12:37:21 +02:00
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
}
|
|
|
|
|
}
|
2023-09-27 11:48:40 +02:00
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
static void update_collapsed_sockets_recursive(bNode &node,
|
|
|
|
|
const int node_left_x,
|
|
|
|
|
const nodes::PanelDeclaration &panel_decl)
|
|
|
|
|
{
|
|
|
|
|
const bNodePanelState &panel_state = node.panel_states_array[panel_decl.index];
|
|
|
|
|
const bke::bNodePanelRuntime &panel_runtime = node.runtime->panels[panel_decl.index];
|
|
|
|
|
const bool is_open = panel_runtime.header_center_y.has_value() && !panel_state.is_collapsed();
|
|
|
|
|
if (!is_open) {
|
|
|
|
|
mark_sockets_collapsed_recursive(node, node_left_x, panel_decl, panel_decl);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (const nodes::ItemDeclaration *item_decl : panel_decl.items) {
|
|
|
|
|
if (const auto *sub_panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl)) {
|
|
|
|
|
update_collapsed_sockets_recursive(node, node_left_x, *sub_panel_decl);
|
2023-09-14 16:08:04 +02:00
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
}
|
|
|
|
|
}
|
2023-08-30 12:37:21 +02:00
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
/**
|
|
|
|
|
* Finds all collapsed sockets and updates them based on the visible parent panel that contains
|
|
|
|
|
* them.
|
|
|
|
|
*/
|
|
|
|
|
static void update_collapsed_sockets(bNode &node, const int node_left_x)
|
|
|
|
|
{
|
|
|
|
|
for (const nodes::ItemDeclaration *item_decl : node.declaration()->root_items) {
|
|
|
|
|
if (const auto *panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl)) {
|
|
|
|
|
update_collapsed_sockets_recursive(node, node_left_x, *panel_decl);
|
2019-03-28 17:39:54 +01:00
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tag the innermost panel that goes to the very end of the node. The background color of that
|
|
|
|
|
* panel is extended to fill the entire rest of the node.
|
|
|
|
|
*/
|
|
|
|
|
static void tag_final_panel(bNode &node, const Span<FlatNodeItem> items)
|
|
|
|
|
{
|
|
|
|
|
const flat_item::PanelContentEnd *final_panel = nullptr;
|
|
|
|
|
for (int item_i = items.size() - 1; item_i >= 0; item_i--) {
|
|
|
|
|
const FlatNodeItem &item = items[item_i];
|
|
|
|
|
if (const auto *panel_item = std::get_if<flat_item::PanelContentEnd>(&item.item)) {
|
|
|
|
|
final_panel = panel_item;
|
2024-09-12 17:38:51 +02:00
|
|
|
}
|
2023-09-14 16:08:04 +02:00
|
|
|
else {
|
2024-10-11 12:20:58 +02:00
|
|
|
break;
|
2023-09-14 16:08:04 +02:00
|
|
|
}
|
2023-09-27 11:48:40 +02:00
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
if (final_panel) {
|
|
|
|
|
bke::bNodePanelRuntime &final_panel_runtime = node.runtime->panels[final_panel->decl->index];
|
|
|
|
|
final_panel_runtime.content_extent->fill_node_end = true;
|
2023-08-30 12:37:21 +02:00
|
|
|
}
|
2023-09-28 11:24:48 +02:00
|
|
|
}
|
2023-09-27 11:48:40 +02:00
|
|
|
|
|
|
|
|
/* Advanced drawing with panels and arbitrary input/output ordering. */
|
|
|
|
|
static void node_update_basis_from_declaration(
|
|
|
|
|
const bContext &C, bNodeTree &ntree, bNode &node, uiBlock &block, const int locx, int &locy)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(is_node_panels_supported(node));
|
|
|
|
|
BLI_assert(node.runtime->panels.size() == node.num_panel_states);
|
|
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
/* Reset states. */
|
|
|
|
|
for (bke::bNodePanelRuntime &panel_runtime : node.runtime->panels) {
|
|
|
|
|
panel_runtime.header_center_y.reset();
|
|
|
|
|
panel_runtime.content_extent.reset();
|
2025-02-28 19:07:02 +01:00
|
|
|
panel_runtime.input_socket = nullptr;
|
2024-10-11 12:20:58 +02:00
|
|
|
}
|
|
|
|
|
for (bNodeSocket *socket : node.input_sockets()) {
|
|
|
|
|
socket->flag &= ~SOCK_PANEL_COLLAPSED;
|
|
|
|
|
}
|
|
|
|
|
for (bNodeSocket *socket : node.output_sockets()) {
|
|
|
|
|
socket->flag &= ~SOCK_PANEL_COLLAPSED;
|
2024-09-24 11:52:02 +02:00
|
|
|
}
|
|
|
|
|
|
2024-11-27 19:01:00 +11:00
|
|
|
/* Gather flattened list of items in the node. */
|
2024-10-11 12:20:58 +02:00
|
|
|
const Vector<FlatNodeItem> flat_items = make_flat_node_items(node);
|
|
|
|
|
if (flat_items.is_empty()) {
|
|
|
|
|
const float margin = get_margin_empty();
|
|
|
|
|
locy -= margin;
|
|
|
|
|
return;
|
2023-09-11 14:40:31 +02:00
|
|
|
}
|
|
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
for (const int item_i : flat_items.index_range()) {
|
|
|
|
|
/* Apply margins. This should be the only place that applies margins between elements so that
|
2024-11-27 19:01:00 +11:00
|
|
|
* it is easy change later on. */
|
2024-10-11 12:20:58 +02:00
|
|
|
if (item_i == 0) {
|
|
|
|
|
const float margin = get_margin_from_top(flat_items);
|
|
|
|
|
locy -= margin;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
const float margin = get_margin_between_elements(flat_items, item_i);
|
|
|
|
|
locy -= margin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const FlatNodeItem &item_variant = flat_items[item_i];
|
|
|
|
|
std::visit(
|
|
|
|
|
[&](const auto &item) {
|
|
|
|
|
using ItemT = std::decay_t<decltype(item)>;
|
|
|
|
|
if constexpr (std::is_same_v<ItemT, flat_item::Socket>) {
|
|
|
|
|
bNodeSocket *input_socket = item.input;
|
|
|
|
|
bNodeSocket *output_socket = item.output;
|
|
|
|
|
const nodes::PanelDeclaration *panel_decl = item.panel_decl;
|
|
|
|
|
const char *parent_label = panel_decl ? panel_decl->name.c_str() : "";
|
|
|
|
|
node_update_basis_socket(
|
|
|
|
|
C, ntree, node, parent_label, input_socket, output_socket, block, locx, locy);
|
|
|
|
|
}
|
|
|
|
|
else if constexpr (std::is_same_v<ItemT, flat_item::Layout>) {
|
|
|
|
|
const nodes::LayoutDeclaration &decl = *item.decl;
|
|
|
|
|
/* Round the node origin because text contents are always pixel-aligned. */
|
2024-12-11 21:06:41 +01:00
|
|
|
const float2 loc = math::round(node_to_view(node.location));
|
2024-10-11 12:20:58 +02:00
|
|
|
uiLayout *layout = UI_block_layout(&block,
|
|
|
|
|
UI_LAYOUT_VERTICAL,
|
|
|
|
|
UI_LAYOUT_PANEL,
|
|
|
|
|
loc.x + NODE_DYS,
|
|
|
|
|
locy,
|
|
|
|
|
NODE_WIDTH(node) - NODE_DY,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
UI_style_get_dpi());
|
2025-01-17 12:17:49 +01:00
|
|
|
if (node.is_muted()) {
|
2024-10-11 12:20:58 +02:00
|
|
|
uiLayoutSetActive(layout, false);
|
|
|
|
|
}
|
2025-01-24 16:45:32 +01:00
|
|
|
PointerRNA node_ptr = RNA_pointer_create_discrete(&ntree.id, &RNA_Node, &node);
|
2024-10-11 12:20:58 +02:00
|
|
|
uiLayoutSetContextPointer(layout, "node", &node_ptr);
|
|
|
|
|
decl.draw(layout, const_cast<bContext *>(&C), &node_ptr);
|
|
|
|
|
UI_block_align_end(&block);
|
|
|
|
|
int buty;
|
|
|
|
|
UI_block_layout_resolve(&block, nullptr, &buty);
|
|
|
|
|
locy = buty;
|
|
|
|
|
}
|
|
|
|
|
else if constexpr (std::is_same_v<ItemT, flat_item::Separator>) {
|
|
|
|
|
uiLayout *layout = UI_block_layout(&block,
|
|
|
|
|
UI_LAYOUT_VERTICAL,
|
|
|
|
|
UI_LAYOUT_PANEL,
|
|
|
|
|
locx + NODE_DYS,
|
|
|
|
|
locy,
|
|
|
|
|
NODE_WIDTH(node) - NODE_DY,
|
|
|
|
|
NODE_DY,
|
|
|
|
|
0,
|
|
|
|
|
UI_style_get_dpi());
|
|
|
|
|
uiItemS_ex(layout, 1.0, LayoutSeparatorType::Line);
|
|
|
|
|
UI_block_layout_resolve(&block, nullptr, nullptr);
|
|
|
|
|
}
|
|
|
|
|
else if constexpr (std::is_same_v<ItemT, flat_item::PanelHeader>) {
|
|
|
|
|
const nodes::PanelDeclaration &node_decl = *item.decl;
|
|
|
|
|
bke::bNodePanelRuntime &panel_runtime = node.runtime->panels[node_decl.index];
|
|
|
|
|
const float panel_header_height = NODE_DYS;
|
|
|
|
|
locy -= panel_header_height / 2;
|
|
|
|
|
panel_runtime.header_center_y = locy;
|
|
|
|
|
locy -= panel_header_height / 2;
|
2025-02-28 19:07:02 +01:00
|
|
|
bNodeSocket *input_socket = item.input;
|
|
|
|
|
if (input_socket) {
|
|
|
|
|
panel_runtime.input_socket = input_socket;
|
|
|
|
|
input_socket->runtime->location = float2(locx, *panel_runtime.header_center_y);
|
|
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
}
|
|
|
|
|
else if constexpr (std::is_same_v<ItemT, flat_item::PanelContentBegin>) {
|
|
|
|
|
const nodes::PanelDeclaration &node_decl = *item.decl;
|
|
|
|
|
bke::bNodePanelRuntime &panel_runtime = node.runtime->panels[node_decl.index];
|
|
|
|
|
panel_runtime.content_extent.emplace();
|
|
|
|
|
panel_runtime.content_extent->max_y = locy;
|
|
|
|
|
}
|
|
|
|
|
else if constexpr (std::is_same_v<ItemT, flat_item::PanelContentEnd>) {
|
|
|
|
|
const nodes::PanelDeclaration &node_decl = *item.decl;
|
|
|
|
|
bke::bNodePanelRuntime &panel_runtime = node.runtime->panels[node_decl.index];
|
|
|
|
|
panel_runtime.content_extent->min_y = locy;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
item_variant.item);
|
2023-08-30 12:37:21 +02:00
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
|
|
|
|
|
const float bottom_margin = get_margin_to_bottom(flat_items);
|
|
|
|
|
locy -= bottom_margin;
|
|
|
|
|
|
|
|
|
|
update_collapsed_sockets(node, locx);
|
|
|
|
|
tag_final_panel(node, flat_items);
|
2023-08-30 12:37:21 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-30 12:37:21 +02:00
|
|
|
/* Conventional drawing in outputs/buttons/inputs order. */
|
|
|
|
|
static void node_update_basis_from_socket_lists(
|
|
|
|
|
const bContext &C, bNodeTree &ntree, bNode &node, uiBlock &block, const int locx, int &locy)
|
|
|
|
|
{
|
2024-03-22 09:09:47 +01:00
|
|
|
/* Space at the top. */
|
|
|
|
|
locy -= NODE_DYS / 2;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-30 12:37:21 +02:00
|
|
|
/* Output sockets. */
|
|
|
|
|
bool add_output_space = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-30 12:37:21 +02:00
|
|
|
for (bNodeSocket *socket : node.output_sockets()) {
|
|
|
|
|
/* Clear flag, conventional drawing does not support panels. */
|
|
|
|
|
socket->flag &= ~SOCK_PANEL_COLLAPSED;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-09-19 15:34:59 +02:00
|
|
|
if (node_update_basis_socket(C, ntree, node, nullptr, nullptr, socket, block, locx, locy)) {
|
2023-08-30 12:37:21 +02:00
|
|
|
if (socket->next) {
|
2023-09-20 11:56:40 +02:00
|
|
|
locy -= NODE_ITEM_SPACING_Y;
|
2021-02-11 01:16:17 -06:00
|
|
|
}
|
2023-08-30 12:37:21 +02:00
|
|
|
add_output_space = true;
|
2021-02-11 01:16:17 -06:00
|
|
|
}
|
2023-08-30 12:37:21 +02:00
|
|
|
}
|
2021-02-11 01:16:17 -06:00
|
|
|
|
2023-08-30 12:37:21 +02:00
|
|
|
if (add_output_space) {
|
|
|
|
|
locy -= NODE_DY / 4;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-03-22 09:09:47 +01:00
|
|
|
const bool add_button_space = node_update_basis_buttons(
|
|
|
|
|
C, ntree, node, node.typeinfo->draw_buttons, block, locy);
|
|
|
|
|
|
|
|
|
|
bool add_input_space = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-30 12:37:21 +02:00
|
|
|
/* Input sockets. */
|
|
|
|
|
for (bNodeSocket *socket : node.input_sockets()) {
|
|
|
|
|
/* Clear flag, conventional drawing does not support panels. */
|
|
|
|
|
socket->flag &= ~SOCK_PANEL_COLLAPSED;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-09-19 15:34:59 +02:00
|
|
|
if (node_update_basis_socket(C, ntree, node, nullptr, socket, nullptr, block, locx, locy)) {
|
2023-08-30 12:37:21 +02:00
|
|
|
if (socket->next) {
|
2023-09-20 11:56:40 +02:00
|
|
|
locy -= NODE_ITEM_SPACING_Y;
|
2023-08-30 12:37:21 +02:00
|
|
|
}
|
2024-03-22 09:09:47 +01:00
|
|
|
add_input_space = true;
|
2023-08-30 12:37:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-03-22 09:09:47 +01:00
|
|
|
/* Little bit of padding at the bottom. */
|
|
|
|
|
if (add_input_space || add_button_space) {
|
2023-08-30 12:37:21 +02:00
|
|
|
locy -= NODE_DYS / 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-30 12:37:21 +02:00
|
|
|
/**
|
|
|
|
|
* Based on settings and sockets in node, set drawing rect info.
|
|
|
|
|
*/
|
|
|
|
|
static void node_update_basis(const bContext &C,
|
|
|
|
|
const TreeDrawContext & /*tree_draw_ctx*/,
|
|
|
|
|
bNodeTree &ntree,
|
|
|
|
|
bNode &node,
|
|
|
|
|
uiBlock &block)
|
|
|
|
|
{
|
|
|
|
|
/* Round the node origin because text contents are always pixel-aligned. */
|
2024-12-11 21:06:41 +01:00
|
|
|
const float2 loc = math::round(node_to_view(node.location));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-30 12:37:21 +02:00
|
|
|
int dy = loc.y;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-30 12:37:21 +02:00
|
|
|
/* Header. */
|
|
|
|
|
dy -= NODE_DY;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-30 12:37:21 +02:00
|
|
|
if (is_node_panels_supported(node)) {
|
|
|
|
|
node_update_basis_from_declaration(C, ntree, node, block, loc.x, dy);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2023-08-30 12:37:21 +02:00
|
|
|
else {
|
|
|
|
|
node_update_basis_from_socket_lists(C, ntree, node, block, loc.x, dy);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-12-13 16:51:56 +01:00
|
|
|
node.runtime->draw_bounds.xmin = loc.x;
|
|
|
|
|
node.runtime->draw_bounds.xmax = loc.x + NODE_WIDTH(node);
|
|
|
|
|
node.runtime->draw_bounds.ymax = loc.y;
|
|
|
|
|
node.runtime->draw_bounds.ymin = min_ff(dy, loc.y - 2 * NODE_DY);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-22 17:49:06 +00:00
|
|
|
/* Set the block bounds to clip mouse events from underlying nodes.
|
2021-02-17 13:34:49 -06:00
|
|
|
* Add a margin for sockets on each side. */
|
2021-12-14 11:19:47 -06:00
|
|
|
UI_block_bounds_set_explicit(&block,
|
2024-12-13 16:51:56 +01:00
|
|
|
node.runtime->draw_bounds.xmin - NODE_SOCKSIZE,
|
|
|
|
|
node.runtime->draw_bounds.ymin,
|
|
|
|
|
node.runtime->draw_bounds.xmax + NODE_SOCKSIZE,
|
|
|
|
|
node.runtime->draw_bounds.ymax);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/**
|
|
|
|
|
* Based on settings in node, sets drawing rect info.
|
|
|
|
|
*/
|
2023-03-19 07:03:01 +01:00
|
|
|
static void node_update_hidden(bNode &node, uiBlock &block)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2020-09-08 17:19:58 +02:00
|
|
|
int totin = 0, totout = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-08-27 11:25:30 -07:00
|
|
|
/* Round the node origin because text contents are always pixel-aligned. */
|
2024-12-11 21:06:41 +01:00
|
|
|
const float2 loc = math::round(node_to_view(node.location));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Calculate minimal radius. */
|
2023-01-02 17:55:32 -05:00
|
|
|
for (const bNodeSocket *socket : node.input_sockets()) {
|
2023-09-19 10:47:21 +02:00
|
|
|
if (socket->is_visible()) {
|
2008-12-24 10:33:10 +00:00
|
|
|
totin++;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
}
|
2023-01-02 17:55:32 -05:00
|
|
|
for (const bNodeSocket *socket : node.output_sockets()) {
|
2023-09-19 10:47:21 +02:00
|
|
|
if (socket->is_visible()) {
|
2008-12-24 10:33:10 +00:00
|
|
|
totout++;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-09-08 17:19:58 +02:00
|
|
|
float hiddenrad = HIDDEN_RAD;
|
2024-01-22 15:58:18 +01:00
|
|
|
float tot = std::max(totin, totout);
|
2012-07-09 19:58:36 +00:00
|
|
|
if (tot > 4) {
|
2022-09-25 18:33:28 +10:00
|
|
|
hiddenrad += 5.0f * float(tot - 4);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-12-13 16:51:56 +01:00
|
|
|
node.runtime->draw_bounds.xmin = loc.x;
|
|
|
|
|
node.runtime->draw_bounds.xmax = loc.x + max_ff(NODE_WIDTH(node), 2 * hiddenrad);
|
|
|
|
|
node.runtime->draw_bounds.ymax = loc.y + (hiddenrad - 0.5f * NODE_DY);
|
|
|
|
|
node.runtime->draw_bounds.ymin = node.runtime->draw_bounds.ymax - 2 * hiddenrad;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Output sockets. */
|
2022-09-25 18:33:28 +10:00
|
|
|
float rad = float(M_PI) / (1.0f + float(totout));
|
2020-09-08 17:19:58 +02:00
|
|
|
float drad = rad;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-02 17:55:32 -05:00
|
|
|
for (bNodeSocket *socket : node.output_sockets()) {
|
2023-09-19 10:47:21 +02:00
|
|
|
if (socket->is_visible()) {
|
2021-08-27 11:25:30 -07:00
|
|
|
/* Round the socket location to stop it from jiggling. */
|
2023-03-19 07:03:01 +01:00
|
|
|
socket->runtime->location = {
|
2024-12-13 16:51:56 +01:00
|
|
|
round(node.runtime->draw_bounds.xmax - hiddenrad + sinf(rad) * hiddenrad),
|
|
|
|
|
round(node.runtime->draw_bounds.ymin + hiddenrad + cosf(rad) * hiddenrad)};
|
2012-07-09 19:58:36 +00:00
|
|
|
rad += drad;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Input sockets. */
|
2022-09-25 18:33:28 +10:00
|
|
|
rad = drad = -float(M_PI) / (1.0f + float(totin));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-02 17:55:32 -05:00
|
|
|
for (bNodeSocket *socket : node.input_sockets()) {
|
2023-09-19 10:47:21 +02:00
|
|
|
if (socket->is_visible()) {
|
2021-08-27 11:25:30 -07:00
|
|
|
/* Round the socket location to stop it from jiggling. */
|
2023-03-19 07:03:01 +01:00
|
|
|
socket->runtime->location = {
|
2024-12-13 16:51:56 +01:00
|
|
|
round(node.runtime->draw_bounds.xmin + hiddenrad + sinf(rad) * hiddenrad),
|
|
|
|
|
round(node.runtime->draw_bounds.ymin + hiddenrad + cosf(rad) * hiddenrad)};
|
2012-07-09 19:58:36 +00:00
|
|
|
rad += drad;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2011-11-22 17:49:06 +00:00
|
|
|
/* Set the block bounds to clip mouse events from underlying nodes.
|
2021-02-17 13:34:49 -06:00
|
|
|
* Add a margin for sockets on each side. */
|
2021-12-14 11:19:47 -06:00
|
|
|
UI_block_bounds_set_explicit(&block,
|
2024-12-13 16:51:56 +01:00
|
|
|
node.runtime->draw_bounds.xmin - NODE_SOCKSIZE,
|
|
|
|
|
node.runtime->draw_bounds.ymin,
|
|
|
|
|
node.runtime->draw_bounds.xmax + NODE_SOCKSIZE,
|
|
|
|
|
node.runtime->draw_bounds.ymax);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
static int node_get_colorid(TreeDrawContext &tree_draw_ctx, const bNode &node)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2022-02-07 15:29:16 +00:00
|
|
|
const int nclass = (node.typeinfo->ui_class == nullptr) ? node.typeinfo->nclass :
|
|
|
|
|
node.typeinfo->ui_class(&node);
|
|
|
|
|
switch (nclass) {
|
2013-12-01 21:30:04 +01:00
|
|
|
case NODE_CLASS_INPUT:
|
|
|
|
|
return TH_NODE_INPUT;
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
case NODE_CLASS_OUTPUT: {
|
2025-01-09 15:28:57 +01:00
|
|
|
if (node.type_legacy == GEO_NODE_VIEWER) {
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
return &node == tree_draw_ctx.active_geometry_nodes_viewer ? TH_NODE_OUTPUT : TH_NODE;
|
|
|
|
|
}
|
2024-08-30 13:19:53 +02:00
|
|
|
const bool is_output_node = (node.flag & NODE_DO_OUTPUT) ||
|
2025-01-09 15:28:57 +01:00
|
|
|
(node.type_legacy == CMP_NODE_OUTPUT_FILE);
|
2024-08-30 13:19:53 +02:00
|
|
|
return is_output_node ? TH_NODE_OUTPUT : TH_NODE;
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
}
|
2021-08-23 16:23:58 +02:00
|
|
|
case NODE_CLASS_CONVERTER:
|
|
|
|
|
return TH_NODE_CONVERTER;
|
2013-12-01 21:30:04 +01:00
|
|
|
case NODE_CLASS_OP_COLOR:
|
|
|
|
|
return TH_NODE_COLOR;
|
|
|
|
|
case NODE_CLASS_OP_VECTOR:
|
|
|
|
|
return TH_NODE_VECTOR;
|
|
|
|
|
case NODE_CLASS_OP_FILTER:
|
|
|
|
|
return TH_NODE_FILTER;
|
2013-01-19 04:20:53 +00:00
|
|
|
case NODE_CLASS_GROUP:
|
|
|
|
|
return TH_NODE_GROUP;
|
2013-03-18 16:34:57 +00:00
|
|
|
case NODE_CLASS_INTERFACE:
|
|
|
|
|
return TH_NODE_INTERFACE;
|
2013-01-19 04:20:53 +00:00
|
|
|
case NODE_CLASS_MATTE:
|
|
|
|
|
return TH_NODE_MATTE;
|
|
|
|
|
case NODE_CLASS_DISTORT:
|
|
|
|
|
return TH_NODE_DISTORT;
|
2013-12-01 21:30:04 +01:00
|
|
|
case NODE_CLASS_TEXTURE:
|
|
|
|
|
return TH_NODE_TEXTURE;
|
|
|
|
|
case NODE_CLASS_SHADER:
|
|
|
|
|
return TH_NODE_SHADER;
|
|
|
|
|
case NODE_CLASS_SCRIPT:
|
|
|
|
|
return TH_NODE_SCRIPT;
|
|
|
|
|
case NODE_CLASS_PATTERN:
|
|
|
|
|
return TH_NODE_PATTERN;
|
|
|
|
|
case NODE_CLASS_LAYOUT:
|
|
|
|
|
return TH_NODE_LAYOUT;
|
2020-12-01 10:28:29 -05:00
|
|
|
case NODE_CLASS_GEOMETRY:
|
|
|
|
|
return TH_NODE_GEOMETRY;
|
|
|
|
|
case NODE_CLASS_ATTRIBUTE:
|
|
|
|
|
return TH_NODE_ATTRIBUTE;
|
2013-01-19 04:20:53 +00:00
|
|
|
default:
|
|
|
|
|
return TH_NODE;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-01 09:29:56 +01:00
|
|
|
static void node_draw_mute_line(const bContext &C,
|
|
|
|
|
const View2D &v2d,
|
|
|
|
|
const SpaceNode &snode,
|
|
|
|
|
const bNode &node)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2020-08-16 15:38:34 +02:00
|
|
|
GPU_blend(GPU_BLEND_ALPHA);
|
2011-11-20 16:38:23 +00:00
|
|
|
|
2023-01-09 23:29:58 -05:00
|
|
|
for (const bNodeLink &link : node.internal_links()) {
|
2025-02-19 13:44:11 +01:00
|
|
|
if (!bke::node_link_is_hidden(link)) {
|
2023-11-01 09:29:56 +01:00
|
|
|
node_draw_link_bezier(C, v2d, snode, link, TH_WIRE_INNER, TH_WIRE_INNER, TH_WIRE, false);
|
2022-08-23 10:35:38 +02:00
|
|
|
}
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2011-11-20 16:38:23 +00:00
|
|
|
|
2020-08-16 15:38:34 +02:00
|
|
|
GPU_blend(GPU_BLEND_NONE);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
2024-04-22 19:48:57 +02:00
|
|
|
static void node_socket_tooltip_set(uiBlock &block,
|
|
|
|
|
const int socket_index_in_tree,
|
|
|
|
|
const float2 location,
|
|
|
|
|
const float2 size)
|
|
|
|
|
{
|
|
|
|
|
/* Ideally sockets themselves should be buttons, but they aren't currently. So add an invisible
|
|
|
|
|
* button on top of them for the tooltip. */
|
|
|
|
|
uiBut *but = uiDefIconBut(&block,
|
2024-12-04 21:56:38 +01:00
|
|
|
UI_BTYPE_LABEL,
|
2024-04-22 19:48:57 +02:00
|
|
|
0,
|
|
|
|
|
ICON_NONE,
|
|
|
|
|
location.x - size.x / 2.0f,
|
|
|
|
|
location.y - size.y / 2.0f,
|
|
|
|
|
size.x,
|
|
|
|
|
size.y,
|
|
|
|
|
nullptr,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
2025-02-14 15:12:48 -05:00
|
|
|
std::nullopt);
|
2024-04-22 19:48:57 +02:00
|
|
|
UI_but_func_tooltip_set(
|
|
|
|
|
but,
|
2025-02-14 15:12:48 -05:00
|
|
|
[](bContext *C, void *argN, const StringRef /*tip*/) {
|
2024-04-22 19:48:57 +02:00
|
|
|
const SpaceNode &snode = *CTX_wm_space_node(C);
|
|
|
|
|
const bNodeTree &ntree = *snode.edittree;
|
|
|
|
|
const int index_in_tree = POINTER_AS_INT(argN);
|
|
|
|
|
ntree.ensure_topology_cache();
|
|
|
|
|
return node_socket_get_tooltip(&snode, ntree, *ntree.all_sockets()[index_in_tree]);
|
|
|
|
|
},
|
|
|
|
|
POINTER_FROM_INT(socket_index_in_tree),
|
|
|
|
|
nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-24 13:01:24 -06:00
|
|
|
static const float virtual_node_socket_outline_color[4] = {0.5, 0.5, 0.5, 1.0};
|
|
|
|
|
|
|
|
|
|
static void node_socket_outline_color_get(const bool selected,
|
|
|
|
|
const int socket_type,
|
|
|
|
|
float r_outline_color[4])
|
2020-04-16 15:09:49 +02:00
|
|
|
{
|
|
|
|
|
if (selected) {
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
UI_GetThemeColor4fv(TH_ACTIVE, r_outline_color);
|
2020-04-16 15:09:49 +02:00
|
|
|
}
|
2022-06-23 12:22:23 -05:00
|
|
|
else if (socket_type == SOCK_CUSTOM) {
|
|
|
|
|
/* Until there is a better place for per socket color,
|
2023-10-19 18:53:16 +11:00
|
|
|
* the outline color for virtual sockets is set here. */
|
2022-06-23 12:22:23 -05:00
|
|
|
copy_v4_v4(r_outline_color, virtual_node_socket_outline_color);
|
|
|
|
|
}
|
2020-04-16 15:09:49 +02:00
|
|
|
else {
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
UI_GetThemeColor4fv(TH_WIRE, r_outline_color);
|
2022-09-01 19:46:19 +02:00
|
|
|
r_outline_color[3] = 1.0f;
|
2020-04-16 15:09:49 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-01 09:29:56 +01:00
|
|
|
void node_socket_color_get(const bContext &C,
|
|
|
|
|
const bNodeTree &ntree,
|
|
|
|
|
PointerRNA &node_ptr,
|
|
|
|
|
const bNodeSocket &sock,
|
|
|
|
|
float r_color[4])
|
2020-04-16 15:09:49 +02:00
|
|
|
{
|
2023-11-01 09:29:56 +01:00
|
|
|
if (!sock.typeinfo->draw_color) {
|
2023-11-06 10:47:32 +01:00
|
|
|
/* Fallback to the simple variant. If not defined either, fallback to a magenta color. */
|
|
|
|
|
if (sock.typeinfo->draw_color_simple) {
|
|
|
|
|
sock.typeinfo->draw_color_simple(sock.typeinfo, r_color);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
copy_v4_v4(r_color, float4(1.0f, 0.0f, 1.0f, 1.0f));
|
|
|
|
|
}
|
2023-11-01 09:29:56 +01:00
|
|
|
return;
|
2023-09-21 11:25:55 +02:00
|
|
|
}
|
2023-11-01 09:29:56 +01:00
|
|
|
|
|
|
|
|
BLI_assert(RNA_struct_is_a(node_ptr.type, &RNA_Node));
|
2025-01-24 16:45:32 +01:00
|
|
|
PointerRNA ptr = RNA_pointer_create_discrete(
|
2023-11-01 09:29:56 +01:00
|
|
|
&const_cast<ID &>(ntree.id), &RNA_NodeSocket, &const_cast<bNodeSocket &>(sock));
|
|
|
|
|
sock.typeinfo->draw_color((bContext *)&C, &ptr, &node_ptr, r_color);
|
2020-04-16 15:09:49 +02:00
|
|
|
}
|
|
|
|
|
|
2022-12-14 18:48:13 +01:00
|
|
|
static void create_inspection_string_for_generic_value(const bNodeSocket &socket,
|
|
|
|
|
const GPointer value,
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::memory_buffer &buf)
|
2021-07-14 11:16:43 +02:00
|
|
|
{
|
2022-04-28 15:05:56 -05:00
|
|
|
auto id_to_inspection_string = [&](const ID *id, const short idcode) {
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", id ? id->name + 2 : TIP_("None"));
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::format_to(fmt::appender(buf), " (");
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_(BKE_idtype_idcode_to_name(idcode)));
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::format_to(fmt::appender(buf), ")");
|
2021-07-14 11:16:43 +02:00
|
|
|
};
|
|
|
|
|
|
2022-12-14 18:48:13 +01:00
|
|
|
const CPPType &value_type = *value.type();
|
2021-11-23 14:47:25 +01:00
|
|
|
const void *buffer = value.get();
|
2022-12-14 18:48:13 +01:00
|
|
|
if (value_type.is<Object *>()) {
|
2022-04-28 15:05:56 -05:00
|
|
|
id_to_inspection_string(*static_cast<const ID *const *>(buffer), ID_OB);
|
2022-12-14 18:48:13 +01:00
|
|
|
return;
|
2021-07-14 11:16:43 +02:00
|
|
|
}
|
2022-12-29 12:01:32 -05:00
|
|
|
if (value_type.is<Material *>()) {
|
2022-04-28 15:05:56 -05:00
|
|
|
id_to_inspection_string(*static_cast<const ID *const *>(buffer), ID_MA);
|
2022-12-14 18:48:13 +01:00
|
|
|
return;
|
2021-07-14 11:16:43 +02:00
|
|
|
}
|
2022-12-29 12:01:32 -05:00
|
|
|
if (value_type.is<Tex *>()) {
|
2022-04-28 15:05:56 -05:00
|
|
|
id_to_inspection_string(*static_cast<const ID *const *>(buffer), ID_TE);
|
2022-12-14 18:48:13 +01:00
|
|
|
return;
|
2021-07-14 11:16:43 +02:00
|
|
|
}
|
2022-12-29 12:01:32 -05:00
|
|
|
if (value_type.is<Image *>()) {
|
2022-04-28 15:05:56 -05:00
|
|
|
id_to_inspection_string(*static_cast<const ID *const *>(buffer), ID_IM);
|
2022-12-14 18:48:13 +01:00
|
|
|
return;
|
2021-10-14 14:18:24 +01:00
|
|
|
}
|
2022-12-29 12:01:32 -05:00
|
|
|
if (value_type.is<Collection *>()) {
|
2022-04-28 15:05:56 -05:00
|
|
|
id_to_inspection_string(*static_cast<const ID *const *>(buffer), ID_GR);
|
2022-12-14 18:48:13 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const CPPType &socket_type = *socket.typeinfo->base_cpp_type;
|
2024-05-05 09:30:02 +02:00
|
|
|
|
|
|
|
|
if (socket.type == SOCK_MENU) {
|
|
|
|
|
if (!value_type.is<int>()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const int item_identifier = *static_cast<const int *>(buffer);
|
|
|
|
|
const auto *socket_storage = socket.default_value_typed<bNodeSocketValueMenu>();
|
|
|
|
|
if (!socket_storage->enum_items) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (socket_storage->has_conflict()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const bke::RuntimeNodeEnumItem *enum_item =
|
|
|
|
|
socket_storage->enum_items->find_item_by_identifier(item_identifier);
|
|
|
|
|
if (!enum_item) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), fmt::runtime(TIP_("{} (Menu)")), enum_item->name);
|
2024-05-05 09:30:02 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-14 18:48:13 +01:00
|
|
|
const bke::DataTypeConversions &convert = bke::get_implicit_type_conversions();
|
2022-12-16 19:39:14 +01:00
|
|
|
if (value_type != socket_type) {
|
|
|
|
|
if (!convert.is_convertible(value_type, socket_type)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-11-23 14:47:25 +01:00
|
|
|
}
|
2022-12-14 18:48:13 +01:00
|
|
|
BUFFER_FOR_CPP_TYPE_VALUE(socket_type, socket_value);
|
2022-12-16 19:39:14 +01:00
|
|
|
/* This will just copy the value if the types are equal. */
|
2022-12-14 18:48:13 +01:00
|
|
|
convert.convert_to_uninitialized(value_type, socket_type, buffer, socket_value);
|
|
|
|
|
BLI_SCOPED_DEFER([&]() { socket_type.destruct(socket_value); });
|
|
|
|
|
|
|
|
|
|
if (socket_type.is<int>()) {
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(
|
|
|
|
|
fmt::appender(buf), fmt::runtime(TIP_("{} (Integer)")), *static_cast<int *>(socket_value));
|
2021-11-23 14:47:25 +01:00
|
|
|
}
|
2022-12-14 18:48:13 +01:00
|
|
|
else if (socket_type.is<float>()) {
|
2024-02-27 20:38:41 +01:00
|
|
|
const float float_value = *static_cast<float *>(socket_value);
|
|
|
|
|
/* Above that threshold floats can't represent fractions anymore. */
|
|
|
|
|
if (std::abs(float_value) > (1 << 24)) {
|
|
|
|
|
/* Use higher precision to display correct integer value instead of one that is rounded to
|
|
|
|
|
* fewer significant digits. */
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), fmt::runtime(TIP_("{:.10} (Float)")), float_value);
|
2024-02-27 20:38:41 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), fmt::runtime(TIP_("{} (Float)")), float_value);
|
2024-02-27 20:38:41 +01:00
|
|
|
}
|
2021-11-23 14:47:25 +01:00
|
|
|
}
|
2022-12-14 18:48:13 +01:00
|
|
|
else if (socket_type.is<blender::float3>()) {
|
2022-09-17 01:50:55 +02:00
|
|
|
const blender::float3 &vector = *static_cast<blender::float3 *>(socket_value);
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf),
|
|
|
|
|
fmt::runtime(TIP_("({}, {}, {}) (Vector)")),
|
|
|
|
|
vector.x,
|
|
|
|
|
vector.y,
|
|
|
|
|
vector.z);
|
2021-11-23 14:47:25 +01:00
|
|
|
}
|
2022-12-14 18:48:13 +01:00
|
|
|
else if (socket_type.is<blender::ColorGeometry4f>()) {
|
|
|
|
|
const blender::ColorGeometry4f &color = *static_cast<blender::ColorGeometry4f *>(socket_value);
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf),
|
|
|
|
|
fmt::runtime(TIP_("({}, {}, {}, {}) (Color)")),
|
|
|
|
|
color.r,
|
|
|
|
|
color.g,
|
|
|
|
|
color.b,
|
|
|
|
|
color.a);
|
2022-11-12 14:22:36 +01:00
|
|
|
}
|
2023-07-13 13:21:46 +02:00
|
|
|
else if (socket_type.is<math::Quaternion>()) {
|
|
|
|
|
const math::Quaternion &rotation = *static_cast<math::Quaternion *>(socket_value);
|
|
|
|
|
const math::EulerXYZ euler = math::to_euler(rotation);
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::format_to(fmt::appender(buf),
|
I18n: extract and disambiguate a few messages
Extract
- Add to Quick Favorites tooltip.
- "Mask", the name of a newly created mask (DATA_).
- "New" in the context of the new mask ID button.
- A few strings using BLI_STR_UTF8_ defines were not extracted.
Take the special characters out of the translation macros.
- "External" menu items from the filebrowser's Files context
menu (right-click on a file). These items were already extracted,
but not translated.
Improve
- Separate formatted error message "%s is not compatible with
["the specified", "any"] 'refresh' options" into two messages.
Disambiguate
- Use Action context for new F-modifiers' names. This is already used
for the "type" operator prop.
- Translate ImportHelper's default confirmation text using the
Operator context, as it uses the operator name which is extracted
with this context.
- "Scale" can be a noun, the scale of something, or a verb, to scale
something. The latter mostly uses the Operator context, so apply
this context to verbs, and the default contexts to nouns.
- "Scale Influence" can mean "Influence on Scale" (tracking
stabilization) and "to Scale the Influence" (dynamic paint canvas).
- "Object Line Art" as type of Line Art to add, as opposed to the
active object's Line Art settings.
- Float to Integer node: use NodeTree context for the node label, as
this is already extracted and used for the enum.
Do not translate
- Sequencer labels containing only a string formatting field.
Some issues reported by Gabriel Gazzán and Ye Gui.
Pull Request: https://projects.blender.org/blender/blender/pulls/122283
2024-05-27 19:33:35 +02:00
|
|
|
("({}" BLI_STR_UTF8_DEGREE_SIGN ", {}" BLI_STR_UTF8_DEGREE_SIGN
|
|
|
|
|
", {}" BLI_STR_UTF8_DEGREE_SIGN ")"),
|
2024-05-09 09:31:04 -04:00
|
|
|
euler.x().degree(),
|
|
|
|
|
euler.y().degree(),
|
|
|
|
|
euler.z().degree());
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_("(Rotation)"));
|
2023-07-13 13:21:46 +02:00
|
|
|
}
|
2022-12-14 18:48:13 +01:00
|
|
|
else if (socket_type.is<bool>()) {
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::format_to(fmt::appender(buf),
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::runtime(TIP_("{} (Boolean)")),
|
2024-05-09 09:31:04 -04:00
|
|
|
((*static_cast<bool *>(socket_value)) ? TIP_("True") : TIP_("False")));
|
2021-07-14 11:16:43 +02:00
|
|
|
}
|
2024-02-13 18:59:36 +01:00
|
|
|
else if (socket_type.is<float4x4>()) {
|
2024-04-11 17:27:21 +02:00
|
|
|
/* Transpose to be able to print row by row. */
|
|
|
|
|
const float4x4 value = math::transpose(*static_cast<const float4x4 *>(socket_value));
|
2024-05-09 09:31:04 -04:00
|
|
|
std::stringstream ss;
|
2024-02-13 18:59:36 +01:00
|
|
|
ss << value[0] << ",\n";
|
|
|
|
|
ss << value[1] << ",\n";
|
|
|
|
|
ss << value[2] << ",\n";
|
|
|
|
|
ss << value[3] << ",\n";
|
2024-05-09 09:31:04 -04:00
|
|
|
buf.append(ss.str());
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_("(Matrix)"));
|
2024-02-13 18:59:36 +01:00
|
|
|
}
|
2021-07-14 11:16:43 +02:00
|
|
|
}
|
|
|
|
|
|
2022-12-14 18:48:13 +01:00
|
|
|
static void create_inspection_string_for_field_info(const bNodeSocket &socket,
|
|
|
|
|
const geo_log::FieldInfoLog &value_log,
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::memory_buffer &buf)
|
2021-10-26 12:48:29 +02:00
|
|
|
{
|
2022-12-14 18:48:13 +01:00
|
|
|
const CPPType &socket_type = *socket.typeinfo->base_cpp_type;
|
2022-09-13 08:44:26 +02:00
|
|
|
const Span<std::string> input_tooltips = value_log.input_tooltips;
|
2021-10-26 12:48:29 +02:00
|
|
|
|
|
|
|
|
if (input_tooltips.is_empty()) {
|
2022-09-13 08:44:26 +02:00
|
|
|
/* Should have been logged as constant value. */
|
|
|
|
|
BLI_assert_unreachable();
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_("Value has not been logged"));
|
2021-10-26 12:48:29 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2022-12-14 18:48:13 +01:00
|
|
|
if (socket_type.is<int>()) {
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_("Integer field based on:"));
|
2021-10-26 12:48:29 +02:00
|
|
|
}
|
2022-12-14 18:48:13 +01:00
|
|
|
else if (socket_type.is<float>()) {
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_("Float field based on:"));
|
2021-10-26 12:48:29 +02:00
|
|
|
}
|
2022-12-14 18:48:13 +01:00
|
|
|
else if (socket_type.is<blender::float3>()) {
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_("Vector field based on:"));
|
2021-10-26 12:48:29 +02:00
|
|
|
}
|
2022-12-14 18:48:13 +01:00
|
|
|
else if (socket_type.is<bool>()) {
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_("Boolean field based on:"));
|
2021-10-26 12:48:29 +02:00
|
|
|
}
|
2022-12-14 18:48:13 +01:00
|
|
|
else if (socket_type.is<std::string>()) {
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_("String field based on:"));
|
2021-10-26 12:48:29 +02:00
|
|
|
}
|
2022-12-14 18:48:13 +01:00
|
|
|
else if (socket_type.is<blender::ColorGeometry4f>()) {
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_("Color field based on:"));
|
2021-10-26 12:48:29 +02:00
|
|
|
}
|
2023-07-13 13:21:46 +02:00
|
|
|
else if (socket_type.is<math::Quaternion>()) {
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_("Rotation field based on:"));
|
2023-07-13 13:21:46 +02:00
|
|
|
}
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::format_to(fmt::appender(buf), "\n");
|
2021-10-26 12:48:29 +02:00
|
|
|
|
|
|
|
|
for (const int i : input_tooltips.index_range()) {
|
2025-02-06 17:47:52 +01:00
|
|
|
const blender::StringRef tooltip = input_tooltips[i];
|
|
|
|
|
fmt::format_to(fmt::appender(buf), fmt::runtime(TIP_("\u2022 {}")), TIP_(tooltip));
|
2021-10-26 12:48:29 +02:00
|
|
|
if (i < input_tooltips.size() - 1) {
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::format_to(fmt::appender(buf), ".\n");
|
2021-10-26 12:48:29 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-13 08:44:26 +02:00
|
|
|
static void create_inspection_string_for_geometry_info(const geo_log::GeometryInfoLog &value_log,
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::memory_buffer &buf)
|
2021-07-14 11:16:43 +02:00
|
|
|
{
|
|
|
|
|
auto to_string = [](int value) {
|
2023-03-02 17:38:36 +01:00
|
|
|
char str[BLI_STR_FORMAT_INT32_GROUPED_SIZE];
|
2021-07-14 11:16:43 +02:00
|
|
|
BLI_str_format_int_grouped(str, value);
|
|
|
|
|
return std::string(str);
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-28 12:05:58 +02:00
|
|
|
if (value_log.grid_info) {
|
|
|
|
|
const geo_log::GeometryInfoLog::GridInfo &grid_info = *value_log.grid_info;
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(
|
|
|
|
|
fmt::appender(buf), "{}", grid_info.is_empty ? TIP_("Empty Grid") : TIP_("\u2022 Grid"));
|
2024-05-28 12:05:58 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Span<bke::GeometryComponent::Type> component_types = value_log.component_types;
|
|
|
|
|
if (component_types.is_empty()) {
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_("Empty Geometry"));
|
2024-05-28 12:05:58 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_("Geometry:"));
|
2024-07-09 17:03:54 +02:00
|
|
|
if (!value_log.name.empty()) {
|
|
|
|
|
fmt::format_to(fmt::appender(buf), " \"{}\"", value_log.name);
|
|
|
|
|
}
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::format_to(fmt::appender(buf), "\n");
|
2023-06-15 22:18:28 +02:00
|
|
|
for (bke::GeometryComponent::Type type : component_types) {
|
2021-07-14 11:16:43 +02:00
|
|
|
switch (type) {
|
2023-06-15 22:18:28 +02:00
|
|
|
case bke::GeometryComponent::Type::Mesh: {
|
2022-09-13 08:44:26 +02:00
|
|
|
const geo_log::GeometryInfoLog::MeshInfo &mesh_info = *value_log.mesh_info;
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::format_to(fmt::appender(buf),
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::runtime(TIP_("\u2022 Mesh: {} vertices, {} edges, {} faces")),
|
2024-05-09 09:31:04 -04:00
|
|
|
to_string(mesh_info.verts_num),
|
|
|
|
|
to_string(mesh_info.edges_num),
|
|
|
|
|
to_string(mesh_info.faces_num));
|
2021-07-14 11:16:43 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2023-06-15 22:18:28 +02:00
|
|
|
case bke::GeometryComponent::Type::PointCloud: {
|
2022-09-13 08:44:26 +02:00
|
|
|
const geo_log::GeometryInfoLog::PointCloudInfo &pointcloud_info =
|
2021-07-14 11:16:43 +02:00
|
|
|
*value_log.pointcloud_info;
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::format_to(fmt::appender(buf),
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::runtime(TIP_("\u2022 Point Cloud: {} points")),
|
2024-05-09 09:31:04 -04:00
|
|
|
to_string(pointcloud_info.points_num));
|
2021-07-14 11:16:43 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2023-06-15 22:18:28 +02:00
|
|
|
case bke::GeometryComponent::Type::Curve: {
|
2022-09-13 08:44:26 +02:00
|
|
|
const geo_log::GeometryInfoLog::CurveInfo &curve_info = *value_log.curve_info;
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::format_to(fmt::appender(buf),
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::runtime(TIP_("\u2022 Curve: {} points, {} splines")),
|
2024-05-09 09:31:04 -04:00
|
|
|
to_string(curve_info.points_num),
|
|
|
|
|
to_string(curve_info.splines_num));
|
2021-07-14 11:16:43 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2023-06-15 22:18:28 +02:00
|
|
|
case bke::GeometryComponent::Type::Instance: {
|
2022-09-13 08:44:26 +02:00
|
|
|
const geo_log::GeometryInfoLog::InstancesInfo &instances_info = *value_log.instances_info;
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::format_to(fmt::appender(buf),
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::runtime(TIP_("\u2022 Instances: {}")),
|
2024-05-09 09:31:04 -04:00
|
|
|
to_string(instances_info.instances_num));
|
2021-07-14 11:16:43 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2023-06-15 22:18:28 +02:00
|
|
|
case bke::GeometryComponent::Type::Volume: {
|
2024-05-28 12:05:58 +02:00
|
|
|
const geo_log::GeometryInfoLog::VolumeInfo &volume_info = *value_log.volume_info;
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf),
|
|
|
|
|
fmt::runtime(TIP_("\u2022 Volume: {} grids")),
|
|
|
|
|
volume_info.grids_num);
|
2021-07-14 11:16:43 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2023-06-15 22:18:28 +02:00
|
|
|
case bke::GeometryComponent::Type::Edit: {
|
2022-07-22 15:39:41 +02:00
|
|
|
if (value_log.edit_data_info.has_value()) {
|
2022-09-13 08:44:26 +02:00
|
|
|
const geo_log::GeometryInfoLog::EditDataInfo &edit_info = *value_log.edit_data_info;
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::format_to(fmt::appender(buf),
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::runtime(TIP_("\u2022 Edit: {}, {}, {}")),
|
2024-05-09 09:31:04 -04:00
|
|
|
edit_info.has_deformed_positions ? TIP_("positions") :
|
|
|
|
|
TIP_("no positions"),
|
Geometry Nodes: support attaching gizmos to input values
This adds support for attaching gizmos for input values. The goal is to make it
easier for users to set input values intuitively in the 3D viewport.
We went through multiple different possible designs until we settled on the one
implemented here. We picked it for it's flexibility and ease of use when using
geometry node assets. The core principle in the design is that **gizmos are
attached to existing input values instead of being the input value themselves**.
This actually fits the existing concept of gizmos in Blender well, but may be a
bit unintutitive in a node setup at first. The attachment is done using links in
the node editor.
The most basic usage of the node is to link a Value node to the new Linear Gizmo
node. This attaches the gizmo to the input value and allows you to change it
from the 3D view. The attachment is indicated by the gizmo icon in the sockets
which are controlled by a gizmo as well as the back-link (notice the double
link) when the gizmo is active.
The core principle makes it straight forward to control the same node setup from
the 3D view with gizmos, or by manually changing input values, or by driving the
input values procedurally.
If the input value is controlled indirectly by other inputs, it's often possible
to **automatically propagate** the gizmo to the actual input.
Backpropagation does not work for all nodes, although more nodes can be
supported over time.
This patch adds the first three gizmo nodes which cover common use cases:
* **Linear Gizmo**: Creates a gizmo that controls a float or integer value using
a linear movement of e.g. an arrow in the 3D viewport.
* **Dial Gizmo**: Creates a circular gizmo in the 3D viewport that can be
rotated to change the attached angle input.
* **Transform Gizmo**: Creates a simple gizmo for location, rotation and scale.
In the future, more built-in gizmos and potentially the ability for custom
gizmos could be added.
All gizmo nodes have a **Transform** geometry output. Using it is optional but
it is recommended when the gizmo is used to control inputs that affect a
geometry. When it is used, Blender will automatically transform the gizmos
together with the geometry that they control. To achieve this, the output should
be merged with the generated geometry using the *Join Geometry* node. The data
contained in *Transform* output is not visible geometry, but just internal
information that helps Blender to give a better user experience when using
gizmos.
The gizmo nodes have a multi-input socket. This allows **controlling multiple
values** with the same gizmo.
Only a small set of **gizmo shapes** is supported initially. It might be
extended in the future but one goal is to give the gizmos used by different node
group assets a familiar look and feel. A similar constraint exists for
**colors**. Currently, one can choose from a fixed set of colors which can be
modified in the theme settings.
The set of **visible gizmos** is determined by a multiple factors because it's
not really feasible to show all possible gizmos at all times. To see any of the
geometry nodes gizmos, the "Active Modifier" option has to be enabled in the
"Viewport Gizmos" popover. Then all gizmos are drawn for which at least one of
the following is true:
* The gizmo controls an input of the active modifier of the active object.
* The gizmo controls a value in a selected node in an open node editor.
* The gizmo controls a pinned value in an open node editor. Pinning works by
clicking the gizmo icon next to the value.
Pull Request: https://projects.blender.org/blender/blender/pulls/112677
2024-07-10 16:18:47 +02:00
|
|
|
edit_info.has_deform_matrices ? TIP_("matrices") : TIP_("no matrices"),
|
|
|
|
|
edit_info.gizmo_transforms_num > 0 ? TIP_("gizmos") : TIP_("no gizmos"));
|
2022-07-22 15:39:41 +02:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-07-26 13:59:37 +02:00
|
|
|
case bke::GeometryComponent::Type::GreasePencil: {
|
2024-06-17 13:50:41 +02:00
|
|
|
const geo_log::GeometryInfoLog::GreasePencilInfo &grease_pencil_info =
|
|
|
|
|
*value_log.grease_pencil_info;
|
|
|
|
|
fmt::format_to(fmt::appender(buf),
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::runtime(TIP_("\u2022 Grease Pencil: {} layers")),
|
2024-06-17 13:50:41 +02:00
|
|
|
to_string(grease_pencil_info.layers_num));
|
|
|
|
|
break;
|
2023-07-26 13:59:37 +02:00
|
|
|
}
|
2021-07-14 11:16:43 +02:00
|
|
|
}
|
2023-01-17 19:25:26 -06:00
|
|
|
if (type != component_types.last()) {
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::format_to(fmt::appender(buf), ".\n");
|
2023-01-17 19:25:26 -06:00
|
|
|
}
|
2021-07-14 11:16:43 +02:00
|
|
|
}
|
2023-01-17 19:25:26 -06:00
|
|
|
}
|
2022-06-03 09:57:37 +02:00
|
|
|
|
2024-05-09 09:31:04 -04:00
|
|
|
static void create_inspection_string_for_geometry_socket(fmt::memory_buffer &buf,
|
2024-04-11 17:52:59 +02:00
|
|
|
const nodes::decl::Geometry *socket_decl)
|
2023-01-17 19:25:26 -06:00
|
|
|
{
|
2022-06-03 09:57:37 +02:00
|
|
|
/* If the geometry declaration is null, as is the case for input to group output,
|
|
|
|
|
* or it is an output socket don't show supported types. */
|
2022-12-29 14:55:27 -05:00
|
|
|
if (socket_decl == nullptr || socket_decl->in_out == SOCK_OUT) {
|
2022-06-03 09:57:37 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-15 22:18:28 +02:00
|
|
|
Span<bke::GeometryComponent::Type> supported_types = socket_decl->supported_types();
|
2022-06-03 09:57:37 +02:00
|
|
|
if (supported_types.is_empty()) {
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_("Supported: All Types"));
|
2022-06-03 09:57:37 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_("Supported: "));
|
2023-06-15 22:18:28 +02:00
|
|
|
for (bke::GeometryComponent::Type type : supported_types) {
|
2022-06-03 09:57:37 +02:00
|
|
|
switch (type) {
|
2023-06-15 22:18:28 +02:00
|
|
|
case bke::GeometryComponent::Type::Mesh: {
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_("Mesh"));
|
2022-06-03 09:57:37 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2023-06-15 22:18:28 +02:00
|
|
|
case bke::GeometryComponent::Type::PointCloud: {
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_("Point Cloud"));
|
2022-06-03 09:57:37 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2023-06-15 22:18:28 +02:00
|
|
|
case bke::GeometryComponent::Type::Curve: {
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_("Curve"));
|
2022-06-03 09:57:37 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2023-06-15 22:18:28 +02:00
|
|
|
case bke::GeometryComponent::Type::Instance: {
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_("Instances"));
|
2022-06-03 09:57:37 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2023-06-15 22:18:28 +02:00
|
|
|
case bke::GeometryComponent::Type::Volume: {
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", CTX_TIP_(BLT_I18NCONTEXT_ID_ID, "Volume"));
|
2022-06-03 09:57:37 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2023-06-15 22:18:28 +02:00
|
|
|
case bke::GeometryComponent::Type::Edit: {
|
2022-07-22 15:39:41 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2023-07-26 13:59:37 +02:00
|
|
|
case bke::GeometryComponent::Type::GreasePencil: {
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_("Grease Pencil"));
|
2023-07-26 13:59:37 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2022-06-03 09:57:37 +02:00
|
|
|
}
|
2023-01-17 19:25:26 -06:00
|
|
|
if (type != supported_types.last()) {
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::format_to(fmt::appender(buf), ", ");
|
2023-01-17 19:25:26 -06:00
|
|
|
}
|
2022-06-03 09:57:37 +02:00
|
|
|
}
|
2021-07-14 11:16:43 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-03 15:44:06 +02:00
|
|
|
static void create_inspection_string_for_bundle(const geo_log::BundleValueLog &value_log,
|
|
|
|
|
fmt::memory_buffer &buf)
|
|
|
|
|
{
|
|
|
|
|
if (value_log.items.is_empty()) {
|
|
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_("Empty Bundle"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_("Bundle values:\n"));
|
|
|
|
|
for (const geo_log::BundleValueLog::Item &item : value_log.items) {
|
|
|
|
|
fmt::format_to(fmt::appender(buf),
|
|
|
|
|
fmt::runtime("\u2022 \"{}\" ({})\n"),
|
|
|
|
|
item.key.identifiers().first(),
|
|
|
|
|
TIP_(item.type->label));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void create_inspection_string_for_closure(const geo_log::ClosureValueLog &value_log,
|
|
|
|
|
fmt::memory_buffer &buf)
|
|
|
|
|
{
|
|
|
|
|
if (value_log.inputs.is_empty() && value_log.outputs.is_empty()) {
|
|
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_("Empty Closure"));
|
|
|
|
|
}
|
|
|
|
|
if (!value_log.inputs.is_empty()) {
|
|
|
|
|
fmt::format_to(fmt::appender(buf), "{}:\n", TIP_("Inputs"));
|
|
|
|
|
for (const geo_log::ClosureValueLog::Item &item : value_log.inputs) {
|
|
|
|
|
fmt::format_to(fmt::appender(buf),
|
|
|
|
|
fmt::runtime("\u2022 {} ({})\n"),
|
|
|
|
|
item.key.identifiers().first(),
|
|
|
|
|
IFACE_(item.type->label));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!value_log.outputs.is_empty()) {
|
|
|
|
|
fmt::format_to(fmt::appender(buf), "{}:\n", TIP_("Outputs"));
|
|
|
|
|
for (const geo_log::ClosureValueLog::Item &item : value_log.outputs) {
|
|
|
|
|
fmt::format_to(fmt::appender(buf),
|
|
|
|
|
fmt::runtime("\u2022 {} ({})\n"),
|
|
|
|
|
item.key.identifiers().first(),
|
|
|
|
|
IFACE_(item.type->label));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-24 17:03:55 +02:00
|
|
|
static void create_inspection_string_for_default_socket_value(const bNodeSocket &socket,
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::memory_buffer &buf)
|
2024-04-24 17:03:55 +02:00
|
|
|
{
|
|
|
|
|
if (!socket.is_input()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-04-25 10:48:06 +02:00
|
|
|
if (socket.is_multi_input()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-05-13 15:48:15 +02:00
|
|
|
if (socket.owner_node().is_reroute()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-04-25 10:48:06 +02:00
|
|
|
const Span<const bNodeSocket *> connected_sockets = socket.directly_linked_sockets();
|
|
|
|
|
if (!connected_sockets.is_empty() && !connected_sockets[0]->owner_node().is_dangling_reroute()) {
|
2024-04-24 17:03:55 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (const nodes::SocketDeclaration *socket_decl = socket.runtime->declaration) {
|
|
|
|
|
if (socket_decl->input_field_type == nodes::InputSocketFieldType::Implicit) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (socket.typeinfo->base_cpp_type == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const CPPType &value_type = *socket.typeinfo->base_cpp_type;
|
|
|
|
|
BUFFER_FOR_CPP_TYPE_VALUE(value_type, socket_value);
|
|
|
|
|
socket.typeinfo->get_base_cpp_value(socket.default_value, socket_value);
|
2024-05-09 09:31:04 -04:00
|
|
|
create_inspection_string_for_generic_value(socket, GPointer(value_type, socket_value), buf);
|
2024-04-24 17:03:55 +02:00
|
|
|
value_type.destruct(socket_value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-11 17:52:59 +02:00
|
|
|
static std::optional<std::string> create_description_inspection_string(const bNodeSocket &socket)
|
|
|
|
|
{
|
|
|
|
|
if (socket.runtime->declaration == nullptr) {
|
2025-01-27 14:30:30 +01:00
|
|
|
if (socket.description[0]) {
|
|
|
|
|
return socket.description;
|
|
|
|
|
}
|
2024-04-11 17:52:59 +02:00
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
const blender::nodes::SocketDeclaration &socket_decl = *socket.runtime->declaration;
|
|
|
|
|
blender::StringRefNull description = socket_decl.description;
|
|
|
|
|
if (description.is_empty()) {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-06 17:47:52 +01:00
|
|
|
return TIP_(description);
|
2024-04-11 17:52:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static std::optional<std::string> create_log_inspection_string(geo_log::GeoTreeLog *geo_tree_log,
|
|
|
|
|
const bNodeSocket &socket)
|
2021-07-14 11:16:43 +02:00
|
|
|
{
|
2024-04-11 17:52:59 +02:00
|
|
|
if (geo_tree_log == nullptr) {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
2022-12-14 18:48:13 +01:00
|
|
|
if (socket.typeinfo->base_cpp_type == nullptr) {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-11 17:52:59 +02:00
|
|
|
geo_tree_log->ensure_socket_values();
|
2025-01-09 12:17:45 -05:00
|
|
|
geo_log::ValueLog *value_log = geo_tree_log->find_socket_value_log(socket);
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::memory_buffer buf;
|
2021-07-14 11:16:43 +02:00
|
|
|
if (const geo_log::GenericValueLog *generic_value_log =
|
|
|
|
|
dynamic_cast<const geo_log::GenericValueLog *>(value_log))
|
|
|
|
|
{
|
2024-05-09 09:31:04 -04:00
|
|
|
create_inspection_string_for_generic_value(socket, generic_value_log->value, buf);
|
2021-07-14 11:16:43 +02:00
|
|
|
}
|
2025-03-07 17:54:26 +01:00
|
|
|
else if (const geo_log::StringLog *string_log = dynamic_cast<const geo_log::StringLog *>(
|
|
|
|
|
value_log))
|
|
|
|
|
{
|
|
|
|
|
if (string_log->truncated) {
|
|
|
|
|
fmt::format_to(fmt::appender(buf), fmt::runtime(TIP_("{}... (String)")), string_log->value);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fmt::format_to(fmt::appender(buf), fmt::runtime(TIP_("{} (String)")), string_log->value);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-13 08:44:26 +02:00
|
|
|
else if (const geo_log::FieldInfoLog *gfield_value_log =
|
|
|
|
|
dynamic_cast<const geo_log::FieldInfoLog *>(value_log))
|
|
|
|
|
{
|
2024-05-09 09:31:04 -04:00
|
|
|
create_inspection_string_for_field_info(socket, *gfield_value_log, buf);
|
2021-10-26 12:48:29 +02:00
|
|
|
}
|
2022-09-13 08:44:26 +02:00
|
|
|
else if (const geo_log::GeometryInfoLog *geo_value_log =
|
|
|
|
|
dynamic_cast<const geo_log::GeometryInfoLog *>(value_log))
|
|
|
|
|
{
|
2024-05-09 09:31:04 -04:00
|
|
|
create_inspection_string_for_geometry_info(*geo_value_log, buf);
|
2023-01-17 19:25:26 -06:00
|
|
|
}
|
2025-04-03 15:44:06 +02:00
|
|
|
else if (const geo_log::BundleValueLog *bundle_value_log =
|
|
|
|
|
dynamic_cast<const geo_log::BundleValueLog *>(value_log))
|
|
|
|
|
{
|
|
|
|
|
create_inspection_string_for_bundle(*bundle_value_log, buf);
|
|
|
|
|
}
|
|
|
|
|
else if (const geo_log::ClosureValueLog *closure_value_log =
|
|
|
|
|
dynamic_cast<const geo_log::ClosureValueLog *>(value_log))
|
|
|
|
|
{
|
|
|
|
|
create_inspection_string_for_closure(*closure_value_log, buf);
|
|
|
|
|
}
|
2023-01-17 19:25:26 -06:00
|
|
|
|
2024-05-09 09:31:04 -04:00
|
|
|
std::string str = fmt::to_string(buf);
|
2024-04-11 17:52:59 +02:00
|
|
|
if (str.empty()) {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static std::optional<std::string> create_declaration_inspection_string(const bNodeSocket &socket)
|
|
|
|
|
{
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::memory_buffer buf;
|
2023-01-17 19:25:26 -06:00
|
|
|
if (const nodes::decl::Geometry *socket_decl = dynamic_cast<const nodes::decl::Geometry *>(
|
|
|
|
|
socket.runtime->declaration))
|
|
|
|
|
{
|
2024-05-09 09:31:04 -04:00
|
|
|
create_inspection_string_for_geometry_socket(buf, socket_decl);
|
2021-07-14 11:16:43 +02:00
|
|
|
}
|
|
|
|
|
|
2024-05-09 09:31:04 -04:00
|
|
|
std::string str = fmt::to_string(buf);
|
2022-09-13 08:44:26 +02:00
|
|
|
if (str.empty()) {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
return str;
|
2021-07-14 11:16:43 +02:00
|
|
|
}
|
|
|
|
|
|
2024-04-22 19:48:57 +02:00
|
|
|
static Vector<std::string> lines_of_text(std::string text)
|
|
|
|
|
{
|
|
|
|
|
Vector<std::string> result;
|
|
|
|
|
std::istringstream text_stream(text);
|
|
|
|
|
for (std::string line; std::getline(text_stream, line);) {
|
|
|
|
|
result.append(line);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static std::optional<std::string> create_multi_input_log_inspection_string(
|
2025-04-09 09:53:48 +02:00
|
|
|
const bNodeSocket &socket, TreeDrawContext &tree_draw_ctx)
|
2024-04-22 19:48:57 +02:00
|
|
|
{
|
|
|
|
|
if (!socket.is_multi_input()) {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector<std::pair<int, std::string>, 8> numerated_info;
|
|
|
|
|
|
|
|
|
|
const Span<const bNodeLink *> connected_links = socket.directly_linked_links();
|
|
|
|
|
for (const int index : connected_links.index_range()) {
|
|
|
|
|
const bNodeLink *link = connected_links[index];
|
|
|
|
|
const int connection_number = index + 1;
|
|
|
|
|
if (!link->is_used()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (!(link->flag & NODE_LINK_VALID)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (link->fromnode->is_dangling_reroute()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
const bNodeSocket &connected_socket = *link->fromsock;
|
2025-04-09 09:53:48 +02:00
|
|
|
geo_log::GeoTreeLog *geo_tree_log = tree_draw_ctx.tree_logs.get_main_tree_log(
|
|
|
|
|
connected_socket);
|
2024-04-22 19:48:57 +02:00
|
|
|
const std::optional<std::string> input_log = create_log_inspection_string(geo_tree_log,
|
|
|
|
|
connected_socket);
|
|
|
|
|
if (!input_log.has_value()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
numerated_info.append({connection_number, std::move(*input_log)});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (numerated_info.is_empty()) {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::memory_buffer buf;
|
2024-04-22 19:48:57 +02:00
|
|
|
for (const std::pair<int, std::string> &info : numerated_info) {
|
|
|
|
|
const Vector<std::string> lines = lines_of_text(info.second);
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", info.first);
|
|
|
|
|
fmt::format_to(fmt::appender(buf), ". ");
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", lines.first());
|
2024-04-22 19:48:57 +02:00
|
|
|
for (const std::string &line : lines.as_span().drop_front(1)) {
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::format_to(fmt::appender(buf), "\n {}", line);
|
2024-04-22 19:48:57 +02:00
|
|
|
}
|
|
|
|
|
if (&info != &numerated_info.last()) {
|
2024-05-09 09:31:04 -04:00
|
|
|
buf.append(StringRef(".\n"));
|
2024-04-22 19:48:57 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-09 09:31:04 -04:00
|
|
|
const std::string str = fmt::to_string(buf);
|
2024-04-22 19:48:57 +02:00
|
|
|
if (str.empty()) {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-24 17:03:55 +02:00
|
|
|
static std::optional<std::string> create_default_value_inspection_string(const bNodeSocket &socket)
|
|
|
|
|
{
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::memory_buffer buf;
|
|
|
|
|
create_inspection_string_for_default_socket_value(socket, buf);
|
2024-04-24 17:03:55 +02:00
|
|
|
|
2024-05-09 09:31:04 -04:00
|
|
|
std::string str = fmt::to_string(buf);
|
2024-04-24 17:03:55 +02:00
|
|
|
if (str.empty()) {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-25 10:48:06 +02:00
|
|
|
static const bNodeSocket *target_for_reroute(const bNodeSocket &reroute_output)
|
|
|
|
|
{
|
|
|
|
|
const bNodeSocket *output = &reroute_output;
|
|
|
|
|
Set<const bNode *> visited_nodes;
|
|
|
|
|
visited_nodes.add(&reroute_output.owner_node());
|
|
|
|
|
while (true) {
|
|
|
|
|
const Span<const bNodeSocket *> linked_sockets = output->directly_linked_sockets();
|
|
|
|
|
if (linked_sockets.size() != 1) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
const bNode &target_node = linked_sockets[0]->owner_node();
|
|
|
|
|
if (!visited_nodes.add(&target_node)) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
if (!target_node.is_dangling_reroute()) {
|
|
|
|
|
return linked_sockets[0];
|
|
|
|
|
}
|
|
|
|
|
output = target_node.output_sockets()[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static std::optional<std::string> create_dangling_reroute_inspection_string(
|
|
|
|
|
const bNodeTree &ntree, const bNodeSocket &socket)
|
|
|
|
|
{
|
|
|
|
|
if (ntree.type != NTREE_GEOMETRY) {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bNode &node = socket.owner_node();
|
|
|
|
|
if (!node.is_dangling_reroute()) {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bNodeSocket &output_socket = *node.output_sockets()[0];
|
|
|
|
|
const bNodeSocket *target_socket = target_for_reroute(output_socket);
|
|
|
|
|
|
|
|
|
|
if (target_socket == nullptr) {
|
|
|
|
|
if (!output_socket.directly_linked_sockets().is_empty()) {
|
|
|
|
|
return TIP_("Dangling reroute is ignored by all targets");
|
|
|
|
|
}
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (target_socket->is_multi_input()) {
|
|
|
|
|
return TIP_("Dangling reroute branch is ignored by multi input socket");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::memory_buffer buf;
|
|
|
|
|
create_inspection_string_for_default_socket_value(*target_socket, buf);
|
|
|
|
|
std::string str = fmt::to_string(buf);
|
|
|
|
|
if (str.empty()) {
|
2024-04-25 10:48:06 +02:00
|
|
|
return TIP_("Dangling reroute is ignored");
|
|
|
|
|
}
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::format_to(fmt::appender(buf), ".\n\n");
|
|
|
|
|
fmt::format_to(fmt::appender(buf),
|
2024-11-20 10:41:29 +01:00
|
|
|
"{}",
|
2024-05-09 09:31:04 -04:00
|
|
|
TIP_("Dangling reroute is ignored, default value of target socket is used"));
|
|
|
|
|
return str;
|
2024-04-25 10:48:06 +02:00
|
|
|
}
|
|
|
|
|
|
2024-01-26 14:39:05 -05:00
|
|
|
static std::string node_socket_get_tooltip(const SpaceNode *snode,
|
|
|
|
|
const bNodeTree &ntree,
|
|
|
|
|
const bNodeSocket &socket)
|
UI: Add support for showing socket descriptions in tooltips
Currently, hovering over a socket itself shows no tooltip at all, while
hovering over its value field shows "Default value", which is not helpful.
This patch therefore implements socket tooltips following the proposal at
https://blender.community/c/rightclickselect/2Qgbbc/.
A lot of the basic functionality was already implemented for Geometry Nodes,
where hovering over the socket itself shows introspection info.
This patch extends this by:
- Supporting dynamic tooltips on labels, which is important for good tooltip
coverage in a socket's region of the node.
- Adding a function to setting a dynamic tooltip for an entire uiLayout, which
avoids needing to set it manually for a wide variety of socket types.
- Hiding the property label field in a tooltip when dynamic tooltip is also
provided. If really needed, this label can be restored through the dynamic
tooltip, but in all current cases the label is actually pointless anyways
since the dynamic tooltip gives more accurate and specific information.
- Adding dynamic tooltips to a socket's UI layout row if it has a description
configured, both in the Node Editor as well as in the Material Properties.
Note that the patch does not add any actual tooltip content yet, just the
infrastructure to show them. By default, sockets without a description still
show the old "Default value" tooltip.
For an example of how to add socket descriptions, check the Cylinder node
in the Geometry Nodes.
Differential Revision: https://developer.blender.org/D9967
2022-04-11 02:02:12 +02:00
|
|
|
{
|
2022-09-13 08:44:26 +02:00
|
|
|
TreeDrawContext tree_draw_ctx;
|
|
|
|
|
if (snode != nullptr) {
|
2023-01-02 16:45:49 -05:00
|
|
|
if (ntree.type == NTREE_GEOMETRY) {
|
2025-04-09 09:53:48 +02:00
|
|
|
tree_draw_ctx.tree_logs = geo_log::GeoModifierLog::get_contextual_tree_logs(*snode);
|
2022-09-13 08:44:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-09 09:53:48 +02:00
|
|
|
geo_log::GeoTreeLog *geo_tree_log = tree_draw_ctx.tree_logs.get_main_tree_log(socket);
|
Geometry Nodes: make evaluation and logging system aware of zones
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.
2023-06-20 09:50:44 +02:00
|
|
|
|
2024-04-11 17:52:59 +02:00
|
|
|
Vector<std::string> inspection_strings;
|
|
|
|
|
|
|
|
|
|
if (std::optional<std::string> info = create_description_inspection_string(socket)) {
|
|
|
|
|
inspection_strings.append(std::move(*info));
|
|
|
|
|
}
|
|
|
|
|
if (std::optional<std::string> info = create_log_inspection_string(geo_tree_log, socket)) {
|
|
|
|
|
inspection_strings.append(std::move(*info));
|
|
|
|
|
}
|
2024-04-25 10:48:06 +02:00
|
|
|
else if (std::optional<std::string> info = create_dangling_reroute_inspection_string(ntree,
|
|
|
|
|
socket))
|
|
|
|
|
{
|
|
|
|
|
inspection_strings.append(std::move(*info));
|
|
|
|
|
}
|
2024-04-24 17:03:55 +02:00
|
|
|
else if (std::optional<std::string> info = create_default_value_inspection_string(socket)) {
|
|
|
|
|
inspection_strings.append(std::move(*info));
|
|
|
|
|
}
|
2024-04-22 19:48:57 +02:00
|
|
|
else if (std::optional<std::string> info = create_multi_input_log_inspection_string(
|
2025-04-09 09:53:48 +02:00
|
|
|
socket, tree_draw_ctx))
|
2024-04-22 19:48:57 +02:00
|
|
|
{
|
|
|
|
|
inspection_strings.append(std::move(*info));
|
|
|
|
|
}
|
2024-04-11 17:52:59 +02:00
|
|
|
if (std::optional<std::string> info = create_declaration_inspection_string(socket)) {
|
|
|
|
|
inspection_strings.append(std::move(*info));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::stringstream output;
|
|
|
|
|
for (const std::string &info : inspection_strings) {
|
|
|
|
|
output << info;
|
|
|
|
|
if (&info != &inspection_strings.last()) {
|
UI: Add support for showing socket descriptions in tooltips
Currently, hovering over a socket itself shows no tooltip at all, while
hovering over its value field shows "Default value", which is not helpful.
This patch therefore implements socket tooltips following the proposal at
https://blender.community/c/rightclickselect/2Qgbbc/.
A lot of the basic functionality was already implemented for Geometry Nodes,
where hovering over the socket itself shows introspection info.
This patch extends this by:
- Supporting dynamic tooltips on labels, which is important for good tooltip
coverage in a socket's region of the node.
- Adding a function to setting a dynamic tooltip for an entire uiLayout, which
avoids needing to set it manually for a wide variety of socket types.
- Hiding the property label field in a tooltip when dynamic tooltip is also
provided. If really needed, this label can be restored through the dynamic
tooltip, but in all current cases the label is actually pointless anyways
since the dynamic tooltip gives more accurate and specific information.
- Adding dynamic tooltips to a socket's UI layout row if it has a description
configured, both in the Node Editor as well as in the Material Properties.
Note that the patch does not add any actual tooltip content yet, just the
infrastructure to show them. By default, sockets without a description still
show the old "Default value" tooltip.
For an example of how to add socket descriptions, check the Cylinder node
in the Geometry Nodes.
Differential Revision: https://developer.blender.org/D9967
2022-04-11 02:02:12 +02:00
|
|
|
output << ".\n\n";
|
|
|
|
|
}
|
2024-04-11 17:52:59 +02:00
|
|
|
}
|
UI: Add support for showing socket descriptions in tooltips
Currently, hovering over a socket itself shows no tooltip at all, while
hovering over its value field shows "Default value", which is not helpful.
This patch therefore implements socket tooltips following the proposal at
https://blender.community/c/rightclickselect/2Qgbbc/.
A lot of the basic functionality was already implemented for Geometry Nodes,
where hovering over the socket itself shows introspection info.
This patch extends this by:
- Supporting dynamic tooltips on labels, which is important for good tooltip
coverage in a socket's region of the node.
- Adding a function to setting a dynamic tooltip for an entire uiLayout, which
avoids needing to set it manually for a wide variety of socket types.
- Hiding the property label field in a tooltip when dynamic tooltip is also
provided. If really needed, this label can be restored through the dynamic
tooltip, but in all current cases the label is actually pointless anyways
since the dynamic tooltip gives more accurate and specific information.
- Adding dynamic tooltips to a socket's UI layout row if it has a description
configured, both in the Node Editor as well as in the Material Properties.
Note that the patch does not add any actual tooltip content yet, just the
infrastructure to show them. By default, sockets without a description still
show the old "Default value" tooltip.
For an example of how to add socket descriptions, check the Cylinder node
in the Geometry Nodes.
Differential Revision: https://developer.blender.org/D9967
2022-04-11 02:02:12 +02:00
|
|
|
|
2024-04-11 17:52:59 +02:00
|
|
|
if (inspection_strings.is_empty()) {
|
2024-05-24 11:39:08 +02:00
|
|
|
const bool is_extend = StringRef(socket.idname) == "NodeSocketVirtual";
|
2024-04-11 19:16:07 +02:00
|
|
|
const bNode &node = socket.owner_node();
|
|
|
|
|
if (node.is_reroute()) {
|
2025-03-05 11:17:50 +01:00
|
|
|
output << bke::node_label(ntree, node);
|
2024-04-11 19:16:07 +02:00
|
|
|
}
|
2024-05-24 11:39:08 +02:00
|
|
|
else if (is_extend) {
|
|
|
|
|
output << TIP_("Connect a link to create a new socket");
|
|
|
|
|
}
|
2024-04-11 19:16:07 +02:00
|
|
|
else {
|
2025-03-05 11:17:50 +01:00
|
|
|
output << bke::node_socket_label(socket);
|
2024-04-11 19:16:07 +02:00
|
|
|
}
|
2024-04-11 17:52:59 +02:00
|
|
|
|
2024-05-24 11:39:08 +02:00
|
|
|
if (ntree.type == NTREE_GEOMETRY && !is_extend) {
|
2024-04-11 17:52:59 +02:00
|
|
|
output << ".\n\n";
|
2022-12-29 19:36:15 +01:00
|
|
|
output << TIP_(
|
|
|
|
|
"Unknown socket value. Either the socket was not used or its value was not logged "
|
|
|
|
|
"during the last evaluation");
|
UI: Add support for showing socket descriptions in tooltips
Currently, hovering over a socket itself shows no tooltip at all, while
hovering over its value field shows "Default value", which is not helpful.
This patch therefore implements socket tooltips following the proposal at
https://blender.community/c/rightclickselect/2Qgbbc/.
A lot of the basic functionality was already implemented for Geometry Nodes,
where hovering over the socket itself shows introspection info.
This patch extends this by:
- Supporting dynamic tooltips on labels, which is important for good tooltip
coverage in a socket's region of the node.
- Adding a function to setting a dynamic tooltip for an entire uiLayout, which
avoids needing to set it manually for a wide variety of socket types.
- Hiding the property label field in a tooltip when dynamic tooltip is also
provided. If really needed, this label can be restored through the dynamic
tooltip, but in all current cases the label is actually pointless anyways
since the dynamic tooltip gives more accurate and specific information.
- Adding dynamic tooltips to a socket's UI layout row if it has a description
configured, both in the Node Editor as well as in the Material Properties.
Note that the patch does not add any actual tooltip content yet, just the
infrastructure to show them. By default, sockets without a description still
show the old "Default value" tooltip.
For an example of how to add socket descriptions, check the Cylinder node
in the Geometry Nodes.
Differential Revision: https://developer.blender.org/D9967
2022-04-11 02:02:12 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-26 14:39:05 -05:00
|
|
|
return output.str();
|
UI: Add support for showing socket descriptions in tooltips
Currently, hovering over a socket itself shows no tooltip at all, while
hovering over its value field shows "Default value", which is not helpful.
This patch therefore implements socket tooltips following the proposal at
https://blender.community/c/rightclickselect/2Qgbbc/.
A lot of the basic functionality was already implemented for Geometry Nodes,
where hovering over the socket itself shows introspection info.
This patch extends this by:
- Supporting dynamic tooltips on labels, which is important for good tooltip
coverage in a socket's region of the node.
- Adding a function to setting a dynamic tooltip for an entire uiLayout, which
avoids needing to set it manually for a wide variety of socket types.
- Hiding the property label field in a tooltip when dynamic tooltip is also
provided. If really needed, this label can be restored through the dynamic
tooltip, but in all current cases the label is actually pointless anyways
since the dynamic tooltip gives more accurate and specific information.
- Adding dynamic tooltips to a socket's UI layout row if it has a description
configured, both in the Node Editor as well as in the Material Properties.
Note that the patch does not add any actual tooltip content yet, just the
infrastructure to show them. By default, sockets without a description still
show the old "Default value" tooltip.
For an example of how to add socket descriptions, check the Cylinder node
in the Geometry Nodes.
Differential Revision: https://developer.blender.org/D9967
2022-04-11 02:02:12 +02:00
|
|
|
}
|
|
|
|
|
|
2024-04-11 00:36:31 +02:00
|
|
|
static void node_socket_add_tooltip_in_node_editor(const bNodeSocket &sock, uiLayout &layout)
|
2023-01-02 16:45:49 -05:00
|
|
|
{
|
|
|
|
|
uiLayoutSetTooltipFunc(
|
|
|
|
|
&layout,
|
2025-02-14 15:12:48 -05:00
|
|
|
[](bContext *C, void *argN, const StringRef /*tip*/) {
|
2023-01-02 16:45:49 -05:00
|
|
|
const SpaceNode &snode = *CTX_wm_space_node(C);
|
|
|
|
|
const bNodeTree &ntree = *snode.edittree;
|
|
|
|
|
const int index_in_tree = POINTER_AS_INT(argN);
|
|
|
|
|
ntree.ensure_topology_cache();
|
|
|
|
|
return node_socket_get_tooltip(&snode, ntree, *ntree.all_sockets()[index_in_tree]);
|
|
|
|
|
},
|
|
|
|
|
POINTER_FROM_INT(sock.index_in_tree()),
|
|
|
|
|
nullptr,
|
|
|
|
|
nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void node_socket_add_tooltip(const bNodeTree &ntree, const bNodeSocket &sock, uiLayout &layout)
|
UI: Add support for showing socket descriptions in tooltips
Currently, hovering over a socket itself shows no tooltip at all, while
hovering over its value field shows "Default value", which is not helpful.
This patch therefore implements socket tooltips following the proposal at
https://blender.community/c/rightclickselect/2Qgbbc/.
A lot of the basic functionality was already implemented for Geometry Nodes,
where hovering over the socket itself shows introspection info.
This patch extends this by:
- Supporting dynamic tooltips on labels, which is important for good tooltip
coverage in a socket's region of the node.
- Adding a function to setting a dynamic tooltip for an entire uiLayout, which
avoids needing to set it manually for a wide variety of socket types.
- Hiding the property label field in a tooltip when dynamic tooltip is also
provided. If really needed, this label can be restored through the dynamic
tooltip, but in all current cases the label is actually pointless anyways
since the dynamic tooltip gives more accurate and specific information.
- Adding dynamic tooltips to a socket's UI layout row if it has a description
configured, both in the Node Editor as well as in the Material Properties.
Note that the patch does not add any actual tooltip content yet, just the
infrastructure to show them. By default, sockets without a description still
show the old "Default value" tooltip.
For an example of how to add socket descriptions, check the Cylinder node
in the Geometry Nodes.
Differential Revision: https://developer.blender.org/D9967
2022-04-11 02:02:12 +02:00
|
|
|
{
|
2023-01-02 16:45:49 -05:00
|
|
|
struct SocketTooltipData {
|
|
|
|
|
const bNodeTree *ntree;
|
|
|
|
|
const bNodeSocket *socket;
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-05 16:35:09 +01:00
|
|
|
SocketTooltipData *data = MEM_callocN<SocketTooltipData>(__func__);
|
2023-01-02 16:45:49 -05:00
|
|
|
data->ntree = &ntree;
|
|
|
|
|
data->socket = &sock;
|
UI: Add support for showing socket descriptions in tooltips
Currently, hovering over a socket itself shows no tooltip at all, while
hovering over its value field shows "Default value", which is not helpful.
This patch therefore implements socket tooltips following the proposal at
https://blender.community/c/rightclickselect/2Qgbbc/.
A lot of the basic functionality was already implemented for Geometry Nodes,
where hovering over the socket itself shows introspection info.
This patch extends this by:
- Supporting dynamic tooltips on labels, which is important for good tooltip
coverage in a socket's region of the node.
- Adding a function to setting a dynamic tooltip for an entire uiLayout, which
avoids needing to set it manually for a wide variety of socket types.
- Hiding the property label field in a tooltip when dynamic tooltip is also
provided. If really needed, this label can be restored through the dynamic
tooltip, but in all current cases the label is actually pointless anyways
since the dynamic tooltip gives more accurate and specific information.
- Adding dynamic tooltips to a socket's UI layout row if it has a description
configured, both in the Node Editor as well as in the Material Properties.
Note that the patch does not add any actual tooltip content yet, just the
infrastructure to show them. By default, sockets without a description still
show the old "Default value" tooltip.
For an example of how to add socket descriptions, check the Cylinder node
in the Geometry Nodes.
Differential Revision: https://developer.blender.org/D9967
2022-04-11 02:02:12 +02:00
|
|
|
|
|
|
|
|
uiLayoutSetTooltipFunc(
|
2023-01-02 16:45:49 -05:00
|
|
|
&layout,
|
2025-02-14 15:12:48 -05:00
|
|
|
[](bContext *C, void *argN, const StringRef /*tip*/) {
|
2022-09-13 08:44:26 +02:00
|
|
|
SocketTooltipData *data = static_cast<SocketTooltipData *>(argN);
|
2023-01-02 16:45:49 -05:00
|
|
|
const SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
return node_socket_get_tooltip(snode, *data->ntree, *data->socket);
|
UI: Add support for showing socket descriptions in tooltips
Currently, hovering over a socket itself shows no tooltip at all, while
hovering over its value field shows "Default value", which is not helpful.
This patch therefore implements socket tooltips following the proposal at
https://blender.community/c/rightclickselect/2Qgbbc/.
A lot of the basic functionality was already implemented for Geometry Nodes,
where hovering over the socket itself shows introspection info.
This patch extends this by:
- Supporting dynamic tooltips on labels, which is important for good tooltip
coverage in a socket's region of the node.
- Adding a function to setting a dynamic tooltip for an entire uiLayout, which
avoids needing to set it manually for a wide variety of socket types.
- Hiding the property label field in a tooltip when dynamic tooltip is also
provided. If really needed, this label can be restored through the dynamic
tooltip, but in all current cases the label is actually pointless anyways
since the dynamic tooltip gives more accurate and specific information.
- Adding dynamic tooltips to a socket's UI layout row if it has a description
configured, both in the Node Editor as well as in the Material Properties.
Note that the patch does not add any actual tooltip content yet, just the
infrastructure to show them. By default, sockets without a description still
show the old "Default value" tooltip.
For an example of how to add socket descriptions, check the Cylinder node
in the Geometry Nodes.
Differential Revision: https://developer.blender.org/D9967
2022-04-11 02:02:12 +02:00
|
|
|
},
|
|
|
|
|
data,
|
|
|
|
|
MEM_dupallocN,
|
|
|
|
|
MEM_freeN);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-23 16:42:38 +01:00
|
|
|
#define NODE_SOCKET_OUTLINE U.pixelsize
|
2020-04-16 15:09:49 +02:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
void node_socket_draw(bNodeSocket *sock, const rcti *rect, const float color[4], float scale)
|
2020-04-16 15:09:49 +02:00
|
|
|
{
|
2024-11-23 16:42:38 +01:00
|
|
|
const float radius = NODE_SOCKSIZE * scale;
|
|
|
|
|
const float2 center = {BLI_rcti_cent_x_fl(rect), BLI_rcti_cent_y_fl(rect)};
|
|
|
|
|
const rctf draw_rect = {
|
|
|
|
|
center.x - radius,
|
|
|
|
|
center.x + radius,
|
|
|
|
|
center.y - radius,
|
|
|
|
|
center.y + radius,
|
|
|
|
|
};
|
2025-03-27 20:33:59 +01:00
|
|
|
|
|
|
|
|
ColorTheme4f outline_color;
|
|
|
|
|
node_socket_outline_color_get(sock->flag & SELECT, sock->type, outline_color);
|
2020-04-16 15:09:49 +02:00
|
|
|
|
2024-11-23 16:42:38 +01:00
|
|
|
node_draw_nodesocket(&draw_rect,
|
|
|
|
|
color,
|
|
|
|
|
outline_color,
|
|
|
|
|
NODE_SOCKET_OUTLINE * scale,
|
|
|
|
|
sock->display_shape,
|
|
|
|
|
1.0 / scale);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
2024-06-05 10:02:37 +02:00
|
|
|
/** Some elements of the node UI are hidden, when they get too small. */
|
|
|
|
|
#define NODE_TREE_SCALE_SMALL 0.2f
|
|
|
|
|
|
|
|
|
|
/** The node tree scales both with the view and with the UI. */
|
|
|
|
|
static float node_tree_view_scale(const SpaceNode &snode)
|
|
|
|
|
{
|
|
|
|
|
return (1.0f / snode.runtime->aspect) * UI_SCALE_FAC;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-23 16:42:38 +01:00
|
|
|
/* Some elements of the node tree like labels or node sockets are hardly visible when zoomed
|
|
|
|
|
* out and can slow down the drawing quite a bit.
|
|
|
|
|
* This function can be used to check if it's worth to draw those details and return
|
|
|
|
|
* early. */
|
|
|
|
|
static bool draw_node_details(const SpaceNode &snode)
|
|
|
|
|
{
|
|
|
|
|
return node_tree_view_scale(snode) > NODE_TREE_SCALE_SMALL * UI_INV_SCALE_FAC;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-19 11:37:35 +10:00
|
|
|
static void node_draw_preview_background(rctf *rect)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2018-07-18 00:12:21 +02:00
|
|
|
GPUVertFormat *format = immVertexFormat();
|
|
|
|
|
uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-08-18 16:12:56 +02:00
|
|
|
immBindBuiltinProgram(GPU_SHADER_2D_CHECKER);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-08-18 16:12:56 +02:00
|
|
|
/* Drawing the checkerboard. */
|
|
|
|
|
const float checker_dark = UI_ALPHA_CHECKER_DARK / 255.0f;
|
|
|
|
|
const float checker_light = UI_ALPHA_CHECKER_LIGHT / 255.0f;
|
|
|
|
|
immUniform4f("color1", checker_dark, checker_dark, checker_dark, 1.0f);
|
|
|
|
|
immUniform4f("color2", checker_light, checker_light, checker_light, 1.0f);
|
|
|
|
|
immUniform1i("size", 8);
|
2016-11-08 11:10:47 -05:00
|
|
|
immRectf(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
|
|
|
|
|
immUnbindProgram();
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Not a callback. */
|
2024-09-26 15:02:59 +10:00
|
|
|
static void node_draw_preview(const Scene *scene, ImBuf *preview, const rctf *prv)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
|
|
|
|
float xrect = BLI_rctf_size_x(prv);
|
|
|
|
|
float yrect = BLI_rctf_size_y(prv);
|
2023-07-17 20:13:52 +02:00
|
|
|
float xscale = xrect / float(preview->x);
|
|
|
|
|
float yscale = yrect / float(preview->y);
|
2013-03-18 16:34:57 +00:00
|
|
|
float scale;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Uniform scale and offset. */
|
2020-09-08 17:19:58 +02:00
|
|
|
rctf draw_rect = *prv;
|
2013-03-18 16:34:57 +00:00
|
|
|
if (xscale < yscale) {
|
2023-07-17 20:13:52 +02:00
|
|
|
float offset = 0.5f * (yrect - float(preview->y) * xscale);
|
2013-03-18 16:34:57 +00:00
|
|
|
draw_rect.ymin += offset;
|
|
|
|
|
draw_rect.ymax -= offset;
|
|
|
|
|
scale = xscale;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2023-07-17 20:13:52 +02:00
|
|
|
float offset = 0.5f * (xrect - float(preview->x) * yscale);
|
2013-03-18 16:34:57 +00:00
|
|
|
draw_rect.xmin += offset;
|
|
|
|
|
draw_rect.xmax -= offset;
|
|
|
|
|
scale = yscale;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-08-19 11:37:35 +10:00
|
|
|
node_draw_preview_background(&draw_rect);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-08-16 15:38:34 +02:00
|
|
|
GPU_blend(GPU_BLEND_ALPHA);
|
2024-04-27 11:57:36 +10:00
|
|
|
/* Pre-multiply graphics. */
|
2020-08-16 15:38:34 +02:00
|
|
|
GPU_blend(GPU_BLEND_ALPHA);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-17 20:13:52 +02:00
|
|
|
ED_draw_imbuf(preview,
|
|
|
|
|
draw_rect.xmin,
|
|
|
|
|
draw_rect.ymin,
|
|
|
|
|
false,
|
|
|
|
|
&scene->view_settings,
|
|
|
|
|
&scene->display_settings,
|
|
|
|
|
scale,
|
|
|
|
|
scale);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-08-16 15:38:34 +02:00
|
|
|
GPU_blend(GPU_BLEND_NONE);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-13 09:54:02 +10:00
|
|
|
float black[4] = {0.0f, 0.0f, 0.0f, 1.0f};
|
2023-07-12 16:14:12 +02:00
|
|
|
UI_draw_roundbox_corner_set(UI_CNR_ALL);
|
|
|
|
|
const float outline_width = 1.0f;
|
|
|
|
|
draw_rect.xmin -= outline_width;
|
|
|
|
|
draw_rect.xmax += outline_width;
|
|
|
|
|
draw_rect.ymin -= outline_width;
|
|
|
|
|
draw_rect.ymax += outline_width;
|
|
|
|
|
UI_draw_roundbox_4fv(&draw_rect, false, BASIS_RAD / 2, black);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Common handle function for operator buttons that need to select the node first. */
|
2022-09-02 14:21:35 -05:00
|
|
|
static void node_toggle_button_cb(bContext *C, void *node_argv, void *op_argv)
|
2011-12-18 12:51:50 +00:00
|
|
|
{
|
2023-01-02 17:37:26 -05:00
|
|
|
SpaceNode &snode = *CTX_wm_space_node(C);
|
|
|
|
|
bNodeTree &node_tree = *snode.edittree;
|
|
|
|
|
bNode &node = *node_tree.node_by_id(POINTER_AS_INT(node_argv));
|
2011-12-18 12:51:50 +00:00
|
|
|
const char *opname = (const char *)op_argv;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Select & activate only the button's node. */
|
2023-01-02 17:37:26 -05:00
|
|
|
node_select_single(*C, node);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2022-03-11 22:49:47 +11:00
|
|
|
WM_operator_name_call(C, opname, WM_OP_INVOKE_DEFAULT, nullptr, nullptr);
|
2011-12-18 12:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-05 17:12:25 -05:00
|
|
|
static void node_draw_shadow(const SpaceNode &snode,
|
|
|
|
|
const bNode &node,
|
|
|
|
|
const float radius,
|
|
|
|
|
const float alpha)
|
2012-05-22 14:13:33 +00:00
|
|
|
{
|
2024-12-13 16:51:56 +01:00
|
|
|
const rctf &rct = node.runtime->draw_bounds;
|
2014-11-09 21:20:40 +01:00
|
|
|
UI_draw_roundbox_corner_set(UI_CNR_ALL);
|
2023-11-24 22:50:20 +01:00
|
|
|
|
|
|
|
|
const float shadow_width = 0.6f * U.widget_unit;
|
|
|
|
|
const float shadow_alpha = 0.5f * alpha;
|
|
|
|
|
|
|
|
|
|
ui_draw_dropshadow(&rct, radius, shadow_width, snode.runtime->aspect, shadow_alpha);
|
|
|
|
|
|
|
|
|
|
/* Outline emphasis. Slight darkening _inside_ the outline. */
|
|
|
|
|
const float color[4] = {0.0f, 0.0f, 0.0f, 0.4f};
|
|
|
|
|
rctf rect{};
|
|
|
|
|
rect.xmin = rct.xmin - 0.5f;
|
|
|
|
|
rect.xmax = rct.xmax + 0.5f;
|
|
|
|
|
rect.ymin = rct.ymin - 0.5f;
|
|
|
|
|
rect.ymax = rct.ymax + 0.5f;
|
|
|
|
|
UI_draw_roundbox_4fv(&rect, false, radius + 0.5f, color);
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
2024-11-23 16:42:38 +01:00
|
|
|
static void node_draw_socket(const bContext &C,
|
|
|
|
|
const bNodeTree &ntree,
|
|
|
|
|
const bNode &node,
|
|
|
|
|
PointerRNA &node_ptr,
|
|
|
|
|
uiBlock &block,
|
|
|
|
|
const bNodeSocket &sock,
|
|
|
|
|
const float outline_thickness,
|
|
|
|
|
const bool selected,
|
|
|
|
|
const float aspect)
|
2016-10-15 02:49:00 -04:00
|
|
|
{
|
2024-11-23 16:42:38 +01:00
|
|
|
const float half_width = NODE_SOCKSIZE;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-11-23 16:42:38 +01:00
|
|
|
const bool multi_socket = (sock.flag & SOCK_MULTI_INPUT) && !(node.flag & NODE_HIDDEN);
|
|
|
|
|
float half_height = multi_socket ? node_socket_calculate_height(sock) : half_width;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-11-23 16:42:38 +01:00
|
|
|
ColorTheme4f socket_color;
|
|
|
|
|
ColorTheme4f outline_color;
|
|
|
|
|
node_socket_color_get(C, ntree, node_ptr, sock, socket_color);
|
|
|
|
|
node_socket_outline_color_get(selected, sock.type, outline_color);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-11-23 16:42:38 +01:00
|
|
|
const float2 socket_location = sock.runtime->location;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-11-23 16:42:38 +01:00
|
|
|
const rctf rect = {
|
|
|
|
|
socket_location.x - half_width,
|
|
|
|
|
socket_location.x + half_width,
|
|
|
|
|
socket_location.y - half_height,
|
|
|
|
|
socket_location.y + half_height,
|
|
|
|
|
};
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-11-23 16:42:38 +01:00
|
|
|
node_draw_nodesocket(
|
|
|
|
|
&rect, socket_color, outline_color, outline_thickness, sock.display_shape, aspect);
|
2023-11-01 09:29:56 +01:00
|
|
|
|
2024-11-23 16:42:38 +01:00
|
|
|
node_socket_tooltip_set(
|
|
|
|
|
block, sock.index_in_tree(), socket_location, float2(2.0f * half_width, 2.0f * half_height));
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-01-09 12:12:50 -05:00
|
|
|
static void node_draw_sockets(const bContext &C,
|
|
|
|
|
uiBlock &block,
|
|
|
|
|
const SpaceNode &snode,
|
|
|
|
|
const bNodeTree &ntree,
|
|
|
|
|
const bNode &node)
|
2024-11-23 16:42:38 +01:00
|
|
|
{
|
|
|
|
|
if (!draw_node_details(snode)) {
|
|
|
|
|
return;
|
2016-10-15 02:49:00 -04:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-11-23 16:42:38 +01:00
|
|
|
if (node.input_sockets().is_empty() && node.output_sockets().is_empty()) {
|
|
|
|
|
return;
|
2016-10-15 02:49:00 -04:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-01-24 16:45:32 +01:00
|
|
|
PointerRNA nodeptr = RNA_pointer_create_discrete(
|
2024-11-23 16:42:38 +01:00
|
|
|
const_cast<ID *>(&ntree.id), &RNA_Node, const_cast<bNode *>(&node));
|
2019-08-23 09:03:57 +10:00
|
|
|
|
2024-11-23 16:42:38 +01:00
|
|
|
const float outline_thickness = NODE_SOCKET_OUTLINE;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-11-23 16:42:38 +01:00
|
|
|
nodesocket_batch_start();
|
|
|
|
|
/* Input sockets. */
|
|
|
|
|
for (const bNodeSocket *sock : node.input_sockets()) {
|
|
|
|
|
if (!node.is_socket_icon_drawn(*sock)) {
|
|
|
|
|
continue;
|
2016-10-15 02:49:00 -04:00
|
|
|
}
|
2024-11-23 16:42:38 +01:00
|
|
|
const bool selected = (sock->flag & SELECT);
|
|
|
|
|
node_draw_socket(
|
|
|
|
|
C, ntree, node, nodeptr, block, *sock, outline_thickness, selected, snode.runtime->aspect);
|
2016-10-15 02:49:00 -04:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-11-23 16:42:38 +01:00
|
|
|
/* Output sockets. */
|
|
|
|
|
for (const bNodeSocket *sock : node.output_sockets()) {
|
|
|
|
|
if (!node.is_socket_icon_drawn(*sock)) {
|
2021-02-11 01:16:17 -06:00
|
|
|
continue;
|
|
|
|
|
}
|
2024-11-23 16:42:38 +01:00
|
|
|
const bool selected = (sock->flag & SELECT);
|
|
|
|
|
node_draw_socket(
|
|
|
|
|
C, ntree, node, nodeptr, block, *sock, outline_thickness, selected, snode.runtime->aspect);
|
2021-02-11 01:16:17 -06:00
|
|
|
}
|
2024-11-23 16:42:38 +01:00
|
|
|
nodesocket_batch_end();
|
2016-10-15 02:49:00 -04:00
|
|
|
}
|
|
|
|
|
|
2023-08-30 12:37:21 +02:00
|
|
|
static void node_panel_toggle_button_cb(bContext *C, void *panel_state_argv, void *ntree_argv)
|
|
|
|
|
{
|
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
bNodePanelState *panel_state = static_cast<bNodePanelState *>(panel_state_argv);
|
|
|
|
|
bNodeTree *ntree = static_cast<bNodeTree *>(ntree_argv);
|
|
|
|
|
|
|
|
|
|
panel_state->flag ^= NODE_PANEL_COLLAPSED;
|
|
|
|
|
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*bmain, ntree->id);
|
2023-08-30 12:37:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Draw panel backgrounds first, so other node elements can be rendered on top. */
|
2024-10-11 12:20:58 +02:00
|
|
|
static void node_draw_panels_background(const bNode &node)
|
2023-08-30 12:37:21 +02:00
|
|
|
{
|
|
|
|
|
BLI_assert(is_node_panels_supported(node));
|
|
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
float panel_color[4];
|
2024-11-26 17:01:14 +01:00
|
|
|
UI_GetThemeColor4fv(TH_PANEL_SUB_BACK, panel_color);
|
|
|
|
|
/* Increase contrast in nodes a bit. */
|
|
|
|
|
panel_color[3] *= 1.5f;
|
2024-12-13 16:51:56 +01:00
|
|
|
const rctf &draw_bounds = node.runtime->draw_bounds;
|
2023-08-30 12:37:21 +02:00
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
const nodes::PanelDeclaration *final_panel_decl = nullptr;
|
2023-09-07 15:07:06 +02:00
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
const nodes::NodeDeclaration &node_decl = *node.declaration();
|
|
|
|
|
for (const int panel_i : node_decl.panels.index_range()) {
|
|
|
|
|
const nodes::PanelDeclaration &panel_decl = *node_decl.panels[panel_i];
|
|
|
|
|
const bke::bNodePanelRuntime &panel_runtime = node.runtime->panels[panel_i];
|
|
|
|
|
if (!panel_runtime.content_extent.has_value()) {
|
2023-08-30 12:37:21 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
2024-12-13 16:51:56 +01:00
|
|
|
const rctf content_rect = {draw_bounds.xmin,
|
|
|
|
|
draw_bounds.xmax,
|
2024-10-11 12:20:58 +02:00
|
|
|
panel_runtime.content_extent->min_y,
|
|
|
|
|
panel_runtime.content_extent->max_y};
|
2023-08-30 12:37:21 +02:00
|
|
|
UI_draw_roundbox_corner_set(UI_CNR_NONE);
|
2024-10-11 12:20:58 +02:00
|
|
|
UI_draw_roundbox_4fv(&content_rect, true, BASIS_RAD, panel_color);
|
|
|
|
|
if (panel_runtime.content_extent->fill_node_end) {
|
|
|
|
|
final_panel_decl = &panel_decl;
|
|
|
|
|
}
|
2023-08-30 12:37:21 +02:00
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
if (final_panel_decl) {
|
|
|
|
|
const bke::bNodePanelRuntime &final_panel_runtime =
|
|
|
|
|
node.runtime->panels[final_panel_decl->index];
|
2024-12-13 16:51:56 +01:00
|
|
|
const rctf content_rect = {draw_bounds.xmin,
|
|
|
|
|
draw_bounds.xmax,
|
|
|
|
|
draw_bounds.ymin,
|
|
|
|
|
final_panel_runtime.content_extent->min_y};
|
2023-09-07 15:07:06 +02:00
|
|
|
UI_draw_roundbox_corner_set(UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT);
|
2024-10-11 12:20:58 +02:00
|
|
|
const int repeats = final_panel_decl->depth() + 1;
|
|
|
|
|
for ([[maybe_unused]] const int i : IndexRange(repeats)) {
|
|
|
|
|
UI_draw_roundbox_4fv(&content_rect, true, BASIS_RAD, panel_color);
|
|
|
|
|
}
|
2023-09-07 15:07:06 +02:00
|
|
|
}
|
2023-08-30 12:37:21 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-21 12:53:24 +01:00
|
|
|
/**
|
|
|
|
|
* Note that this is different from #panel_has_input_affecting_node_output in how it treats output
|
|
|
|
|
* sockets. Within the node UI, the panel should not be grayed out if it has an output socket.
|
|
|
|
|
* However, the sidebar only shows inputs, so output sockets should be ignored.
|
|
|
|
|
*/
|
|
|
|
|
static bool panel_has_only_inactive_inputs(const bNode &node,
|
|
|
|
|
const nodes::PanelDeclaration &panel_decl)
|
|
|
|
|
{
|
|
|
|
|
for (const nodes::ItemDeclaration *item_decl : panel_decl.items) {
|
|
|
|
|
if (const auto *socket_decl = dynamic_cast<const nodes::SocketDeclaration *>(item_decl)) {
|
|
|
|
|
if (socket_decl->in_out == SOCK_OUT) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
const bNodeSocket &socket = node.socket_by_decl(*socket_decl);
|
|
|
|
|
if (socket.affects_node_output()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (const auto *sub_panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl))
|
|
|
|
|
{
|
|
|
|
|
if (!panel_has_only_inactive_inputs(node, *sub_panel_decl)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-30 12:37:21 +02:00
|
|
|
static void node_draw_panels(bNodeTree &ntree, const bNode &node, uiBlock &block)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(is_node_panels_supported(node));
|
2024-12-13 16:51:56 +01:00
|
|
|
const rctf &draw_bounds = node.runtime->draw_bounds;
|
2024-10-11 12:20:58 +02:00
|
|
|
|
|
|
|
|
const nodes::NodeDeclaration &node_decl = *node.declaration();
|
|
|
|
|
for (const int panel_i : node_decl.panels.index_range()) {
|
|
|
|
|
const nodes::PanelDeclaration &panel_decl = *node_decl.panels[panel_i];
|
|
|
|
|
const bke::bNodePanelRuntime &panel_runtime = node.runtime->panels[panel_i];
|
2025-02-28 19:07:02 +01:00
|
|
|
bNodeSocket *input_socket = panel_runtime.input_socket;
|
2024-10-11 12:20:58 +02:00
|
|
|
const bNodePanelState &panel_state = node.panel_states_array[panel_i];
|
|
|
|
|
if (!panel_runtime.header_center_y.has_value()) {
|
2023-08-30 12:37:21 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-13 16:51:56 +01:00
|
|
|
const rctf header_rect = {draw_bounds.xmin,
|
|
|
|
|
draw_bounds.xmax,
|
2024-10-11 12:20:58 +02:00
|
|
|
*panel_runtime.header_center_y - NODE_DYS,
|
|
|
|
|
*panel_runtime.header_center_y + NODE_DYS};
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(&block, blender::ui::EmbossType::None);
|
2023-08-30 12:37:21 +02:00
|
|
|
|
2025-02-28 19:07:02 +01:00
|
|
|
/* Invisible button covering the entire header for collapsing/expanding. */
|
|
|
|
|
const int header_but_margin = NODE_MARGIN_X / 3;
|
|
|
|
|
uiBut *toggle_action_but = uiDefIconBut(
|
|
|
|
|
&block,
|
|
|
|
|
UI_BTYPE_BUT_TOGGLE,
|
|
|
|
|
0,
|
|
|
|
|
ICON_NONE,
|
|
|
|
|
header_rect.xmin + header_but_margin,
|
|
|
|
|
header_rect.ymin,
|
|
|
|
|
std::max(int(header_rect.xmax - header_rect.xmin - 2 * header_but_margin), 0),
|
|
|
|
|
header_rect.ymax - header_rect.ymin,
|
|
|
|
|
nullptr,
|
|
|
|
|
0.0f,
|
|
|
|
|
0.0f,
|
|
|
|
|
panel_decl.description.c_str());
|
|
|
|
|
UI_but_func_pushed_state_set(
|
|
|
|
|
toggle_action_but, [&panel_state](const uiBut &) { return panel_state.is_collapsed(); });
|
|
|
|
|
UI_but_func_set(toggle_action_but,
|
|
|
|
|
node_panel_toggle_button_cb,
|
|
|
|
|
const_cast<bNodePanelState *>(&panel_state),
|
|
|
|
|
&ntree);
|
|
|
|
|
|
2023-08-30 12:37:21 +02:00
|
|
|
/* Collapse/expand icon. */
|
|
|
|
|
const int but_size = U.widget_unit * 0.8f;
|
2025-02-28 19:07:02 +01:00
|
|
|
const int but_padding = NODE_MARGIN_X / 4;
|
|
|
|
|
int offsetx = draw_bounds.xmin + (NODE_MARGIN_X / 3);
|
2023-08-30 12:37:21 +02:00
|
|
|
uiDefIconBut(&block,
|
2025-02-28 19:07:02 +01:00
|
|
|
UI_BTYPE_LABEL,
|
2023-08-30 12:37:21 +02:00
|
|
|
0,
|
2024-10-11 12:20:58 +02:00
|
|
|
panel_state.is_collapsed() ? ICON_RIGHTARROW : ICON_DOWNARROW_HLT,
|
2025-02-28 19:07:02 +01:00
|
|
|
offsetx,
|
2024-10-11 12:20:58 +02:00
|
|
|
*panel_runtime.header_center_y - but_size / 2,
|
2023-08-30 12:37:21 +02:00
|
|
|
but_size,
|
|
|
|
|
but_size,
|
|
|
|
|
nullptr,
|
|
|
|
|
0.0f,
|
|
|
|
|
0.0f,
|
|
|
|
|
"");
|
2025-02-28 19:07:02 +01:00
|
|
|
offsetx += but_size + but_padding;
|
|
|
|
|
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(&block, blender::ui::EmbossType::Emboss);
|
2025-02-28 19:07:02 +01:00
|
|
|
|
|
|
|
|
/* Panel toggle. */
|
|
|
|
|
if (input_socket && !input_socket->is_logically_linked()) {
|
|
|
|
|
PointerRNA socket_ptr = RNA_pointer_create_discrete(
|
|
|
|
|
&ntree.id, &RNA_NodeSocket, input_socket);
|
|
|
|
|
uiDefButR(&block,
|
|
|
|
|
UI_BTYPE_CHECKBOX,
|
|
|
|
|
-1,
|
|
|
|
|
"",
|
|
|
|
|
offsetx,
|
|
|
|
|
int(*panel_runtime.header_center_y - NODE_DYS),
|
|
|
|
|
UI_UNIT_X,
|
|
|
|
|
NODE_DY,
|
|
|
|
|
&socket_ptr,
|
|
|
|
|
"default_value",
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
"");
|
|
|
|
|
offsetx += UI_UNIT_X;
|
|
|
|
|
}
|
2023-08-30 12:37:21 +02:00
|
|
|
|
|
|
|
|
/* Panel label. */
|
2024-12-13 16:51:56 +01:00
|
|
|
uiBut *label_but = uiDefBut(
|
|
|
|
|
&block,
|
|
|
|
|
UI_BTYPE_LABEL,
|
|
|
|
|
0,
|
2025-02-06 17:47:52 +01:00
|
|
|
IFACE_(panel_decl.name),
|
2025-02-28 19:07:02 +01:00
|
|
|
offsetx,
|
2024-12-13 16:51:56 +01:00
|
|
|
int(*panel_runtime.header_center_y - NODE_DYS),
|
|
|
|
|
short(draw_bounds.xmax - draw_bounds.xmin - (30.0f * UI_SCALE_FAC)),
|
2025-01-09 12:12:50 -05:00
|
|
|
NODE_DY,
|
2024-12-13 16:51:56 +01:00
|
|
|
nullptr,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
"");
|
2025-01-21 12:53:24 +01:00
|
|
|
|
|
|
|
|
const bool only_inactive_inputs = panel_has_only_inactive_inputs(node, panel_decl);
|
|
|
|
|
if (node.is_muted() || only_inactive_inputs) {
|
2024-10-11 12:20:58 +02:00
|
|
|
UI_but_flag_enable(label_but, UI_BUT_INACTIVE);
|
2023-08-30 12:37:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-07 11:20:19 +02:00
|
|
|
static geo_log::NodeWarningType node_error_highest_priority(Span<geo_log::NodeWarning> warnings)
|
2021-02-16 17:15:08 -06:00
|
|
|
{
|
2024-09-30 21:17:43 +02:00
|
|
|
int highest_priority = 0;
|
2021-07-07 11:20:19 +02:00
|
|
|
geo_log::NodeWarningType highest_priority_type = geo_log::NodeWarningType::Info;
|
|
|
|
|
for (const geo_log::NodeWarning &warning : warnings) {
|
2024-09-30 21:17:43 +02:00
|
|
|
const int priority = node_warning_type_severity(warning.type);
|
2021-02-16 17:15:08 -06:00
|
|
|
if (priority > highest_priority) {
|
|
|
|
|
highest_priority = priority;
|
|
|
|
|
highest_priority_type = warning.type;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return highest_priority_type;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-07 11:20:19 +02:00
|
|
|
struct NodeErrorsTooltipData {
|
|
|
|
|
Span<geo_log::NodeWarning> warnings;
|
|
|
|
|
};
|
|
|
|
|
|
2025-02-14 15:12:48 -05:00
|
|
|
static std::string node_errors_tooltip_fn(bContext * /*C*/, void *argN, const StringRef /*tip*/)
|
2021-02-16 17:15:08 -06:00
|
|
|
{
|
2021-07-07 11:20:19 +02:00
|
|
|
NodeErrorsTooltipData &data = *(NodeErrorsTooltipData *)argN;
|
2021-02-16 17:15:08 -06:00
|
|
|
|
|
|
|
|
std::string complete_string;
|
|
|
|
|
|
2021-07-07 11:20:19 +02:00
|
|
|
for (const geo_log::NodeWarning &warning : data.warnings.drop_back(1)) {
|
2021-02-16 17:15:08 -06:00
|
|
|
complete_string += warning.message;
|
2021-03-03 12:58:33 -06:00
|
|
|
/* Adding the period is not ideal for multi-line messages, but it is consistent
|
|
|
|
|
* with other tooltip implementations in Blender, so it is added here. */
|
|
|
|
|
complete_string += '.';
|
2021-02-16 17:15:08 -06:00
|
|
|
complete_string += '\n';
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-03 12:58:33 -06:00
|
|
|
/* Let the tooltip system automatically add the last period. */
|
2021-07-07 11:20:19 +02:00
|
|
|
complete_string += data.warnings.last().message;
|
2021-02-16 17:15:08 -06:00
|
|
|
|
2024-01-26 14:39:05 -05:00
|
|
|
return complete_string;
|
2021-02-16 17:15:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define NODE_HEADER_ICON_SIZE (0.8f * U.widget_unit)
|
|
|
|
|
|
2023-01-02 17:37:26 -05:00
|
|
|
static void node_add_unsupported_compositor_operation_error_message_button(const bNode &node,
|
2022-11-23 15:05:34 +02:00
|
|
|
uiBlock &block,
|
|
|
|
|
const rctf &rect,
|
|
|
|
|
float &icon_offset)
|
2022-11-23 14:34:31 +02:00
|
|
|
{
|
|
|
|
|
icon_offset -= NODE_HEADER_ICON_SIZE;
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(&block, blender::ui::EmbossType::None);
|
2022-11-23 14:34:31 +02:00
|
|
|
uiDefIconBut(&block,
|
|
|
|
|
UI_BTYPE_BUT,
|
|
|
|
|
0,
|
|
|
|
|
ICON_ERROR,
|
|
|
|
|
icon_offset,
|
|
|
|
|
rect.ymax - NODE_DY,
|
|
|
|
|
NODE_HEADER_ICON_SIZE,
|
|
|
|
|
UI_UNIT_Y,
|
|
|
|
|
nullptr,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
2024-12-17 13:00:50 +01:00
|
|
|
TIP_(node.typeinfo->compositor_unsupported_message));
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(&block, blender::ui::EmbossType::Emboss);
|
2022-11-23 14:34:31 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-02 17:37:26 -05:00
|
|
|
static void node_add_error_message_button(const TreeDrawContext &tree_draw_ctx,
|
|
|
|
|
const bNode &node,
|
2022-09-13 08:44:26 +02:00
|
|
|
uiBlock &block,
|
|
|
|
|
const rctf &rect,
|
|
|
|
|
float &icon_offset)
|
2021-02-16 17:15:08 -06:00
|
|
|
{
|
2024-12-17 13:00:50 +01:00
|
|
|
if (tree_draw_ctx.used_by_compositor && node.typeinfo->compositor_unsupported_message) {
|
2022-11-23 15:05:34 +02:00
|
|
|
node_add_unsupported_compositor_operation_error_message_button(node, block, rect, icon_offset);
|
2022-11-23 14:34:31 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
Geometry Nodes: make evaluation and logging system aware of zones
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.
2023-06-20 09:50:44 +02:00
|
|
|
geo_log::GeoTreeLog *geo_tree_log = [&]() -> geo_log::GeoTreeLog * {
|
2023-06-20 10:25:41 +02:00
|
|
|
const bNodeTreeZones *zones = node.owner_tree().zones();
|
Geometry Nodes: make evaluation and logging system aware of zones
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.
2023-06-20 09:50:44 +02:00
|
|
|
if (!zones) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2023-06-20 10:25:41 +02:00
|
|
|
const bNodeTreeZone *zone = zones->get_zone_by_node(node.identifier);
|
2023-09-27 11:09:39 +02:00
|
|
|
if (zone && ELEM(&node, zone->input_node, zone->output_node)) {
|
|
|
|
|
zone = zone->parent_zone;
|
|
|
|
|
}
|
2025-04-09 09:53:48 +02:00
|
|
|
return tree_draw_ctx.tree_logs.get_main_tree_log(zone);
|
Geometry Nodes: make evaluation and logging system aware of zones
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.
2023-06-20 09:50:44 +02:00
|
|
|
}();
|
|
|
|
|
|
2022-09-13 08:44:26 +02:00
|
|
|
Span<geo_log::NodeWarning> warnings;
|
Geometry Nodes: make evaluation and logging system aware of zones
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.
2023-06-20 09:50:44 +02:00
|
|
|
if (geo_tree_log) {
|
|
|
|
|
geo_log::GeoNodeLog *node_log = geo_tree_log->nodes.lookup_ptr(node.identifier);
|
2022-09-13 08:44:26 +02:00
|
|
|
if (node_log != nullptr) {
|
|
|
|
|
warnings = node_log->warnings;
|
|
|
|
|
}
|
2021-07-07 11:20:19 +02:00
|
|
|
}
|
|
|
|
|
if (warnings.is_empty()) {
|
2021-02-16 17:15:08 -06:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-07 11:20:19 +02:00
|
|
|
const geo_log::NodeWarningType display_type = node_error_highest_priority(warnings);
|
2022-09-13 08:44:26 +02:00
|
|
|
NodeErrorsTooltipData *tooltip_data = MEM_new<NodeErrorsTooltipData>(__func__);
|
|
|
|
|
tooltip_data->warnings = warnings;
|
2021-02-16 17:15:08 -06:00
|
|
|
|
|
|
|
|
icon_offset -= NODE_HEADER_ICON_SIZE;
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(&block, blender::ui::EmbossType::None);
|
2021-12-14 11:19:47 -06:00
|
|
|
uiBut *but = uiDefIconBut(&block,
|
2021-02-16 17:15:08 -06:00
|
|
|
UI_BTYPE_BUT,
|
|
|
|
|
0,
|
2024-09-30 21:17:43 +02:00
|
|
|
geo_log::node_warning_type_icon(display_type),
|
2021-02-16 17:15:08 -06:00
|
|
|
icon_offset,
|
|
|
|
|
rect.ymax - NODE_DY,
|
|
|
|
|
NODE_HEADER_ICON_SIZE,
|
|
|
|
|
UI_UNIT_Y,
|
|
|
|
|
nullptr,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
nullptr);
|
2022-09-13 08:44:26 +02:00
|
|
|
UI_but_func_tooltip_set(but, node_errors_tooltip_fn, tooltip_data, [](void *arg) {
|
|
|
|
|
MEM_delete(static_cast<NodeErrorsTooltipData *>(arg));
|
|
|
|
|
});
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(&block, blender::ui::EmbossType::Emboss);
|
2021-02-16 17:15:08 -06:00
|
|
|
}
|
|
|
|
|
|
2024-02-09 10:19:24 +01:00
|
|
|
static std::optional<std::chrono::nanoseconds> geo_node_get_execution_time(
|
|
|
|
|
const TreeDrawContext &tree_draw_ctx, const SpaceNode &snode, const bNode &node)
|
2021-11-23 17:37:31 +01:00
|
|
|
{
|
2024-02-09 10:19:24 +01:00
|
|
|
const bNodeTree &ntree = *snode.edittree;
|
|
|
|
|
|
Geometry Nodes: make evaluation and logging system aware of zones
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.
2023-06-20 09:50:44 +02:00
|
|
|
geo_log::GeoTreeLog *tree_log = [&]() -> geo_log::GeoTreeLog * {
|
2023-06-20 10:25:41 +02:00
|
|
|
const bNodeTreeZones *zones = ntree.zones();
|
Geometry Nodes: make evaluation and logging system aware of zones
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.
2023-06-20 09:50:44 +02:00
|
|
|
if (!zones) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2023-06-20 10:25:41 +02:00
|
|
|
const bNodeTreeZone *zone = zones->get_zone_by_node(node.identifier);
|
2024-09-24 11:52:02 +02:00
|
|
|
if (zone && ELEM(&node, zone->input_node, zone->output_node)) {
|
|
|
|
|
zone = zone->parent_zone;
|
|
|
|
|
}
|
2025-04-09 09:53:48 +02:00
|
|
|
return tree_draw_ctx.tree_logs.get_main_tree_log(zone);
|
Geometry Nodes: make evaluation and logging system aware of zones
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.
2023-06-20 09:50:44 +02:00
|
|
|
}();
|
|
|
|
|
|
2022-09-13 08:44:26 +02:00
|
|
|
if (tree_log == nullptr) {
|
|
|
|
|
return std::nullopt;
|
2021-11-23 17:37:31 +01:00
|
|
|
}
|
2025-01-17 12:17:49 +01:00
|
|
|
if (node.is_group_output()) {
|
2024-09-16 12:07:52 +02:00
|
|
|
return tree_log->execution_time;
|
2021-11-23 17:37:31 +01:00
|
|
|
}
|
2022-12-29 12:01:32 -05:00
|
|
|
if (node.is_frame()) {
|
2021-11-23 17:37:31 +01:00
|
|
|
/* Could be cached in the future if this recursive code turns out to be slow. */
|
2022-09-13 08:44:26 +02:00
|
|
|
std::chrono::nanoseconds run_time{0};
|
|
|
|
|
bool found_node = false;
|
2021-11-23 17:37:31 +01:00
|
|
|
|
2022-11-21 16:10:05 +01:00
|
|
|
for (const bNode *tnode : node.direct_children_in_frame()) {
|
|
|
|
|
if (tnode->is_frame()) {
|
2024-02-09 10:19:24 +01:00
|
|
|
std::optional<std::chrono::nanoseconds> sub_frame_run_time = geo_node_get_execution_time(
|
|
|
|
|
tree_draw_ctx, snode, *tnode);
|
2022-09-13 08:44:26 +02:00
|
|
|
if (sub_frame_run_time.has_value()) {
|
|
|
|
|
run_time += *sub_frame_run_time;
|
|
|
|
|
found_node = true;
|
|
|
|
|
}
|
2021-11-23 17:37:31 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2022-12-01 14:53:27 -06:00
|
|
|
if (const geo_log::GeoNodeLog *node_log = tree_log->nodes.lookup_ptr_as(tnode->identifier))
|
|
|
|
|
{
|
2022-09-13 08:44:26 +02:00
|
|
|
found_node = true;
|
2024-09-16 12:07:52 +02:00
|
|
|
run_time += node_log->execution_time;
|
2022-09-13 08:44:26 +02:00
|
|
|
}
|
2021-11-23 17:37:31 +01:00
|
|
|
}
|
|
|
|
|
}
|
2022-09-13 08:44:26 +02:00
|
|
|
if (found_node) {
|
|
|
|
|
return run_time;
|
|
|
|
|
}
|
|
|
|
|
return std::nullopt;
|
2021-11-23 17:37:31 +01:00
|
|
|
}
|
2022-12-01 14:53:27 -06:00
|
|
|
if (const geo_log::GeoNodeLog *node_log = tree_log->nodes.lookup_ptr(node.identifier)) {
|
2024-09-16 12:07:52 +02:00
|
|
|
return node_log->execution_time;
|
2021-11-23 17:37:31 +01:00
|
|
|
}
|
2022-09-13 08:44:26 +02:00
|
|
|
return std::nullopt;
|
2021-11-23 17:37:31 +01:00
|
|
|
}
|
|
|
|
|
|
2024-02-09 10:19:24 +01:00
|
|
|
/* Create node key instance, assuming the node comes from the currently edited node tree. */
|
|
|
|
|
static bNodeInstanceKey current_node_instance_key(const SpaceNode &snode, const bNode &node)
|
|
|
|
|
{
|
|
|
|
|
const bNodeTreePath *path = static_cast<const bNodeTreePath *>(snode.treepath.last);
|
|
|
|
|
|
|
|
|
|
/* Some code in this file checks for the non-null elements of the tree path. However, if we did
|
|
|
|
|
* iterate into a node it is expected that there is a tree, and it should be in the path.
|
|
|
|
|
* Otherwise something else went wrong. */
|
|
|
|
|
BLI_assert(path);
|
|
|
|
|
|
|
|
|
|
/* Assume that the currently editing tree is the last in the path. */
|
|
|
|
|
BLI_assert(snode.edittree == path->nodetree);
|
|
|
|
|
|
2024-08-19 20:27:37 +02:00
|
|
|
return bke::node_instance_key(path->parent_key, snode.edittree, &node);
|
2024-02-09 10:19:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static std::optional<std::chrono::nanoseconds> compositor_accumulate_frame_node_execution_time(
|
|
|
|
|
const TreeDrawContext &tree_draw_ctx, const SpaceNode &snode, const bNode &node)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(tree_draw_ctx.compositor_per_node_execution_time);
|
|
|
|
|
|
|
|
|
|
timeit::Nanoseconds frame_execution_time(0);
|
|
|
|
|
bool has_any_execution_time = false;
|
|
|
|
|
|
|
|
|
|
for (const bNode *current_node : node.direct_children_in_frame()) {
|
|
|
|
|
const bNodeInstanceKey key = current_node_instance_key(snode, *current_node);
|
|
|
|
|
if (const timeit::Nanoseconds *node_execution_time =
|
|
|
|
|
tree_draw_ctx.compositor_per_node_execution_time->lookup_ptr(key))
|
|
|
|
|
{
|
|
|
|
|
frame_execution_time += *node_execution_time;
|
|
|
|
|
has_any_execution_time = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!has_any_execution_time) {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return frame_execution_time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static std::optional<std::chrono::nanoseconds> compositor_node_get_execution_time(
|
|
|
|
|
const TreeDrawContext &tree_draw_ctx, const SpaceNode &snode, const bNode &node)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(tree_draw_ctx.compositor_per_node_execution_time);
|
|
|
|
|
|
|
|
|
|
/* For the frame nodes accumulate execution time of its children. */
|
|
|
|
|
if (node.is_frame()) {
|
|
|
|
|
return compositor_accumulate_frame_node_execution_time(tree_draw_ctx, snode, node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* For other nodes simply lookup execution time.
|
|
|
|
|
* The group node instances have their own entries in the execution times map. */
|
|
|
|
|
const bNodeInstanceKey key = current_node_instance_key(snode, node);
|
|
|
|
|
if (const timeit::Nanoseconds *execution_time =
|
|
|
|
|
tree_draw_ctx.compositor_per_node_execution_time->lookup_ptr(key))
|
|
|
|
|
{
|
|
|
|
|
return *execution_time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static std::optional<std::chrono::nanoseconds> node_get_execution_time(
|
|
|
|
|
const TreeDrawContext &tree_draw_ctx, const SpaceNode &snode, const bNode &node)
|
|
|
|
|
{
|
|
|
|
|
switch (snode.edittree->type) {
|
|
|
|
|
case NTREE_GEOMETRY:
|
|
|
|
|
return geo_node_get_execution_time(tree_draw_ctx, snode, node);
|
|
|
|
|
case NTREE_COMPOSIT:
|
|
|
|
|
return compositor_node_get_execution_time(tree_draw_ctx, snode, node);
|
2025-01-09 12:12:50 -05:00
|
|
|
default:
|
|
|
|
|
return std::nullopt;
|
2024-02-09 10:19:24 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-13 08:44:26 +02:00
|
|
|
static std::string node_get_execution_time_label(TreeDrawContext &tree_draw_ctx,
|
|
|
|
|
const SpaceNode &snode,
|
|
|
|
|
const bNode &node)
|
2021-11-23 17:37:31 +01:00
|
|
|
{
|
2022-09-13 08:44:26 +02:00
|
|
|
const std::optional<std::chrono::nanoseconds> exec_time = node_get_execution_time(
|
2024-02-09 10:19:24 +01:00
|
|
|
tree_draw_ctx, snode, node);
|
2021-11-23 17:37:31 +01:00
|
|
|
|
2022-09-13 08:44:26 +02:00
|
|
|
if (!exec_time.has_value()) {
|
2021-11-23 17:37:31 +01:00
|
|
|
return std::string("");
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-13 08:44:26 +02:00
|
|
|
const uint64_t exec_time_us =
|
|
|
|
|
std::chrono::duration_cast<std::chrono::microseconds>(*exec_time).count();
|
2021-11-23 17:37:31 +01:00
|
|
|
|
|
|
|
|
/* Don't show time if execution time is 0 microseconds. */
|
|
|
|
|
if (exec_time_us == 0) {
|
|
|
|
|
return std::string("-");
|
|
|
|
|
}
|
2021-11-23 12:49:45 -05:00
|
|
|
if (exec_time_us < 100) {
|
2021-11-23 17:37:31 +01:00
|
|
|
return std::string("< 0.1 ms");
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-23 12:49:45 -05:00
|
|
|
int precision = 0;
|
|
|
|
|
/* Show decimal if value is below 1ms */
|
|
|
|
|
if (exec_time_us < 1000) {
|
|
|
|
|
precision = 2;
|
2021-11-23 17:37:31 +01:00
|
|
|
}
|
2021-11-23 12:49:45 -05:00
|
|
|
else if (exec_time_us < 10000) {
|
|
|
|
|
precision = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::stringstream stream;
|
|
|
|
|
stream << std::fixed << std::setprecision(precision) << (exec_time_us / 1000.0f);
|
|
|
|
|
return stream.str() + " ms";
|
2021-11-23 17:37:31 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-14 16:31:09 +02:00
|
|
|
struct NamedAttributeTooltipArg {
|
2022-09-17 12:08:43 +02:00
|
|
|
Map<StringRefNull, geo_log::NamedAttributeUsage> usage_by_attribute;
|
2021-11-23 17:37:31 +01:00
|
|
|
};
|
|
|
|
|
|
2025-02-14 15:12:48 -05:00
|
|
|
static std::string named_attribute_tooltip(bContext * /*C*/, void *argN, const StringRef /*tip*/)
|
2022-04-14 16:31:09 +02:00
|
|
|
{
|
|
|
|
|
NamedAttributeTooltipArg &arg = *static_cast<NamedAttributeTooltipArg *>(argN);
|
|
|
|
|
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::memory_buffer buf;
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", TIP_("Accessed named attributes:"));
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::format_to(fmt::appender(buf), "\n");
|
2022-04-25 16:00:43 +02:00
|
|
|
|
|
|
|
|
struct NameWithUsage {
|
|
|
|
|
StringRefNull name;
|
2022-09-13 08:44:26 +02:00
|
|
|
geo_log::NamedAttributeUsage usage;
|
2022-04-25 16:00:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Vector<NameWithUsage> sorted_used_attribute;
|
2022-04-14 16:31:09 +02:00
|
|
|
for (auto &&item : arg.usage_by_attribute.items()) {
|
|
|
|
|
sorted_used_attribute.append({item.key, item.value});
|
|
|
|
|
}
|
2022-04-25 16:00:43 +02:00
|
|
|
std::sort(sorted_used_attribute.begin(),
|
|
|
|
|
sorted_used_attribute.end(),
|
|
|
|
|
[](const NameWithUsage &a, const NameWithUsage &b) {
|
2024-03-12 17:31:02 +01:00
|
|
|
return BLI_strcasecmp_natural(a.name.c_str(), b.name.c_str()) < 0;
|
2022-04-25 16:00:43 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for (const NameWithUsage &attribute : sorted_used_attribute) {
|
|
|
|
|
const StringRefNull name = attribute.name;
|
2022-09-13 08:44:26 +02:00
|
|
|
const geo_log::NamedAttributeUsage usage = attribute.usage;
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), fmt::runtime(TIP_(" \u2022 \"{}\": ")), name);
|
2022-04-14 16:31:09 +02:00
|
|
|
Vector<std::string> usages;
|
2022-09-13 08:44:26 +02:00
|
|
|
if ((usage & geo_log::NamedAttributeUsage::Read) != geo_log::NamedAttributeUsage::None) {
|
2022-04-14 16:31:09 +02:00
|
|
|
usages.append(TIP_("read"));
|
|
|
|
|
}
|
2022-09-13 08:44:26 +02:00
|
|
|
if ((usage & geo_log::NamedAttributeUsage::Write) != geo_log::NamedAttributeUsage::None) {
|
2022-04-14 16:31:09 +02:00
|
|
|
usages.append(TIP_("write"));
|
|
|
|
|
}
|
2022-09-13 08:44:26 +02:00
|
|
|
if ((usage & geo_log::NamedAttributeUsage::Remove) != geo_log::NamedAttributeUsage::None) {
|
2022-04-14 16:31:09 +02:00
|
|
|
usages.append(TIP_("remove"));
|
|
|
|
|
}
|
|
|
|
|
for (const int i : usages.index_range()) {
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(fmt::appender(buf), "{}", usages[i]);
|
2022-04-14 16:31:09 +02:00
|
|
|
if (i < usages.size() - 1) {
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::format_to(fmt::appender(buf), ", ");
|
2022-04-14 16:31:09 +02:00
|
|
|
}
|
|
|
|
|
}
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::format_to(fmt::appender(buf), "\n");
|
2022-04-14 16:31:09 +02:00
|
|
|
}
|
2024-05-09 09:31:04 -04:00
|
|
|
fmt::format_to(fmt::appender(buf), "\n");
|
2024-11-20 10:41:29 +01:00
|
|
|
fmt::format_to(
|
|
|
|
|
fmt::appender(buf),
|
|
|
|
|
fmt::runtime(TIP_("Attributes with these names used within the group may conflict with "
|
|
|
|
|
"existing attributes")));
|
2024-05-09 09:31:04 -04:00
|
|
|
return fmt::to_string(buf);
|
2022-04-14 16:31:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NodeExtraInfoRow row_from_used_named_attribute(
|
2022-09-17 12:08:43 +02:00
|
|
|
const Map<StringRefNull, geo_log::NamedAttributeUsage> &usage_by_attribute_name)
|
2022-04-14 16:31:09 +02:00
|
|
|
{
|
2022-04-25 16:28:21 +02:00
|
|
|
const int attributes_num = usage_by_attribute_name.size();
|
|
|
|
|
|
2022-04-14 16:31:09 +02:00
|
|
|
NodeExtraInfoRow row;
|
2022-04-25 16:28:21 +02:00
|
|
|
row.text = std::to_string(attributes_num) +
|
2024-01-11 19:49:03 +01:00
|
|
|
(attributes_num == 1 ? RPT_(" Named Attribute") : RPT_(" Named Attributes"));
|
2022-04-14 16:31:09 +02:00
|
|
|
row.icon = ICON_SPREADSHEET;
|
|
|
|
|
row.tooltip_fn = named_attribute_tooltip;
|
|
|
|
|
row.tooltip_fn_arg = new NamedAttributeTooltipArg{usage_by_attribute_name};
|
|
|
|
|
row.tooltip_fn_free_arg = [](void *arg) { delete static_cast<NamedAttributeTooltipArg *>(arg); };
|
|
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-13 08:44:26 +02:00
|
|
|
static std::optional<NodeExtraInfoRow> node_get_accessed_attributes_row(
|
|
|
|
|
TreeDrawContext &tree_draw_ctx, const bNode &node)
|
2022-04-14 16:31:09 +02:00
|
|
|
{
|
2025-04-09 09:53:48 +02:00
|
|
|
geo_log::GeoTreeLog *geo_tree_log = tree_draw_ctx.tree_logs.get_main_tree_log(node);
|
Geometry Nodes: make evaluation and logging system aware of zones
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.
2023-06-20 09:50:44 +02:00
|
|
|
if (geo_tree_log == nullptr) {
|
2022-09-13 08:44:26 +02:00
|
|
|
return std::nullopt;
|
2022-04-14 16:31:09 +02:00
|
|
|
}
|
2025-01-09 15:28:57 +01:00
|
|
|
if (ELEM(node.type_legacy,
|
2022-04-14 16:31:09 +02:00
|
|
|
GEO_NODE_STORE_NAMED_ATTRIBUTE,
|
|
|
|
|
GEO_NODE_REMOVE_ATTRIBUTE,
|
|
|
|
|
GEO_NODE_INPUT_NAMED_ATTRIBUTE))
|
|
|
|
|
{
|
|
|
|
|
/* Only show the overlay when the name is passed in from somewhere else. */
|
2023-01-02 17:55:32 -05:00
|
|
|
for (const bNodeSocket *socket : node.input_sockets()) {
|
2022-04-14 16:31:09 +02:00
|
|
|
if (STREQ(socket->name, "Name")) {
|
2022-09-13 08:44:26 +02:00
|
|
|
if (!socket->is_directly_linked()) {
|
2022-04-14 16:31:09 +02:00
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
Geometry Nodes: make evaluation and logging system aware of zones
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.
2023-06-20 09:50:44 +02:00
|
|
|
geo_tree_log->ensure_used_named_attributes();
|
|
|
|
|
geo_log::GeoNodeLog *node_log = geo_tree_log->nodes.lookup_ptr(node.identifier);
|
2022-09-13 08:44:26 +02:00
|
|
|
if (node_log == nullptr) {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
if (node_log->used_named_attributes.is_empty()) {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
return row_from_used_named_attribute(node_log->used_named_attributes);
|
2022-04-14 16:31:09 +02:00
|
|
|
}
|
|
|
|
|
|
2024-02-09 10:19:24 +01:00
|
|
|
static std::optional<NodeExtraInfoRow> node_get_execution_time_label_row(
|
|
|
|
|
TreeDrawContext &tree_draw_ctx, const SpaceNode &snode, const bNode &node)
|
|
|
|
|
{
|
|
|
|
|
NodeExtraInfoRow row;
|
|
|
|
|
row.text = node_get_execution_time_label(tree_draw_ctx, snode, node);
|
|
|
|
|
if (row.text.empty()) {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
row.tooltip = TIP_(
|
|
|
|
|
"The execution time from the node tree's latest evaluation. For frame and group "
|
|
|
|
|
"nodes, the time for all sub-nodes");
|
|
|
|
|
row.icon = ICON_PREVIEW_RANGE;
|
|
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void node_get_compositor_extra_info(TreeDrawContext &tree_draw_ctx,
|
|
|
|
|
const SpaceNode &snode,
|
|
|
|
|
const bNode &node,
|
|
|
|
|
Vector<NodeExtraInfoRow> &rows)
|
|
|
|
|
{
|
|
|
|
|
if (snode.overlay.flag & SN_OVERLAY_SHOW_TIMINGS) {
|
|
|
|
|
std::optional<NodeExtraInfoRow> row = node_get_execution_time_label_row(
|
|
|
|
|
tree_draw_ctx, snode, node);
|
|
|
|
|
if (row.has_value()) {
|
|
|
|
|
rows.append(std::move(*row));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-23 14:31:16 +02:00
|
|
|
static void node_get_invalid_links_extra_info(const SpaceNode &snode,
|
|
|
|
|
const bNode &node,
|
|
|
|
|
Vector<NodeExtraInfoRow> &rows)
|
|
|
|
|
{
|
|
|
|
|
const bNodeTree &tree = *snode.edittree;
|
|
|
|
|
const Span<bke::NodeLinkError> link_errors = tree.runtime->link_errors_by_target_node.lookup(
|
|
|
|
|
node.identifier);
|
|
|
|
|
if (link_errors.is_empty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
NodeExtraInfoRow row;
|
|
|
|
|
row.text = IFACE_("Invalid Link");
|
|
|
|
|
|
2025-02-14 15:12:48 -05:00
|
|
|
row.tooltip_fn = [](bContext *C, void *arg, const StringRef /*tip*/) {
|
2024-05-23 14:31:16 +02:00
|
|
|
const bNodeTree &tree = *CTX_wm_space_node(C)->edittree;
|
|
|
|
|
const bNode &node = *static_cast<const bNode *>(arg);
|
|
|
|
|
const Span<bke::NodeLinkError> link_errors = tree.runtime->link_errors_by_target_node.lookup(
|
|
|
|
|
node.identifier);
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
Set<StringRef> already_added_errors;
|
|
|
|
|
for (const int i : link_errors.index_range()) {
|
|
|
|
|
const StringRefNull tooltip = link_errors[i].tooltip;
|
|
|
|
|
if (already_added_errors.add_as(tooltip)) {
|
|
|
|
|
ss << "\u2022 " << tooltip << "\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ss << "\n";
|
|
|
|
|
ss << "Any invalid links are highlighted";
|
|
|
|
|
return ss.str();
|
|
|
|
|
};
|
|
|
|
|
row.tooltip_fn_arg = const_cast<bNode *>(&node);
|
|
|
|
|
row.icon = ICON_ERROR;
|
|
|
|
|
rows.append(std::move(row));
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-05 15:57:40 +01:00
|
|
|
static Vector<NodeExtraInfoRow> node_get_extra_info(const bContext &C,
|
|
|
|
|
TreeDrawContext &tree_draw_ctx,
|
2022-09-13 08:44:26 +02:00
|
|
|
const SpaceNode &snode,
|
|
|
|
|
const bNode &node)
|
2021-11-23 17:37:31 +01:00
|
|
|
{
|
|
|
|
|
Vector<NodeExtraInfoRow> rows;
|
2023-12-05 15:57:40 +01:00
|
|
|
|
|
|
|
|
if (node.typeinfo->get_extra_info) {
|
|
|
|
|
nodes::NodeExtraInfoParams params{rows, node, C};
|
|
|
|
|
node.typeinfo->get_extra_info(params);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-06 19:08:01 +01:00
|
|
|
if (node.typeinfo->deprecation_notice) {
|
|
|
|
|
NodeExtraInfoRow row;
|
|
|
|
|
row.text = IFACE_("Deprecated");
|
|
|
|
|
row.icon = ICON_INFO;
|
|
|
|
|
row.tooltip = TIP_(node.typeinfo->deprecation_notice);
|
|
|
|
|
rows.append(std::move(row));
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-23 14:31:16 +02:00
|
|
|
node_get_invalid_links_extra_info(snode, node, rows);
|
|
|
|
|
|
2024-02-09 10:19:24 +01:00
|
|
|
if (snode.edittree->type == NTREE_COMPOSIT) {
|
|
|
|
|
node_get_compositor_extra_info(tree_draw_ctx, snode, node, rows);
|
|
|
|
|
return rows;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-18 15:07:15 +02:00
|
|
|
if (!(snode.edittree->type == NTREE_GEOMETRY)) {
|
2024-02-09 10:19:24 +01:00
|
|
|
/* Currently geometry and compositor nodes are the only nodes to have extra info per nodes. */
|
2021-11-23 17:37:31 +01:00
|
|
|
return rows;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-18 15:07:15 +02:00
|
|
|
if (snode.overlay.flag & SN_OVERLAY_SHOW_NAMED_ATTRIBUTES) {
|
2022-09-13 08:44:26 +02:00
|
|
|
if (std::optional<NodeExtraInfoRow> row = node_get_accessed_attributes_row(tree_draw_ctx,
|
2024-01-02 18:12:54 +01:00
|
|
|
node))
|
|
|
|
|
{
|
2022-04-25 16:03:34 +02:00
|
|
|
rows.append(std::move(*row));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-18 15:07:15 +02:00
|
|
|
if (snode.overlay.flag & SN_OVERLAY_SHOW_TIMINGS &&
|
2021-12-03 16:25:17 -05:00
|
|
|
(ELEM(node.typeinfo->nclass, NODE_CLASS_GEOMETRY, NODE_CLASS_GROUP, NODE_CLASS_ATTRIBUTE) ||
|
2025-01-09 15:28:57 +01:00
|
|
|
ELEM(node.type_legacy,
|
2024-09-24 11:52:02 +02:00
|
|
|
NODE_FRAME,
|
|
|
|
|
NODE_GROUP_OUTPUT,
|
|
|
|
|
GEO_NODE_SIMULATION_OUTPUT,
|
|
|
|
|
GEO_NODE_REPEAT_OUTPUT,
|
2025-04-03 15:44:06 +02:00
|
|
|
GEO_NODE_FOREACH_GEOMETRY_ELEMENT_OUTPUT,
|
|
|
|
|
GEO_NODE_EVALUATE_CLOSURE)))
|
2021-12-03 16:25:17 -05:00
|
|
|
{
|
2024-02-09 10:19:24 +01:00
|
|
|
std::optional<NodeExtraInfoRow> row = node_get_execution_time_label_row(
|
|
|
|
|
tree_draw_ctx, snode, node);
|
|
|
|
|
if (row.has_value()) {
|
|
|
|
|
rows.append(std::move(*row));
|
2021-11-23 17:37:31 +01:00
|
|
|
}
|
|
|
|
|
}
|
2022-09-13 08:44:26 +02:00
|
|
|
|
2025-04-09 09:53:48 +02:00
|
|
|
geo_log::GeoTreeLog *tree_log = tree_draw_ctx.tree_logs.get_main_tree_log(node);
|
2023-07-18 15:07:15 +02:00
|
|
|
|
|
|
|
|
if (tree_log) {
|
|
|
|
|
tree_log->ensure_debug_messages();
|
|
|
|
|
const geo_log::GeoNodeLog *node_log = tree_log->nodes.lookup_ptr(node.identifier);
|
|
|
|
|
if (node_log != nullptr) {
|
|
|
|
|
for (const StringRef message : node_log->debug_messages) {
|
|
|
|
|
NodeExtraInfoRow row;
|
|
|
|
|
row.text = message;
|
|
|
|
|
row.icon = ICON_INFO;
|
|
|
|
|
rows.append(std::move(row));
|
2022-09-13 08:44:26 +02:00
|
|
|
}
|
2021-11-24 13:39:09 +01:00
|
|
|
}
|
|
|
|
|
}
|
2022-04-14 16:31:09 +02:00
|
|
|
|
2021-11-23 17:37:31 +01:00
|
|
|
return rows;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
static void node_draw_extra_info_row(const bNode &node,
|
2021-12-14 11:19:47 -06:00
|
|
|
uiBlock &block,
|
2021-12-03 16:25:17 -05:00
|
|
|
const rctf &rect,
|
2021-11-23 17:37:31 +01:00
|
|
|
const int row,
|
|
|
|
|
const NodeExtraInfoRow &extra_info_row)
|
|
|
|
|
{
|
2023-03-17 04:19:05 +01:00
|
|
|
const float but_icon_left = rect.xmin + 6.0f * UI_SCALE_FAC;
|
2022-04-25 16:28:21 +02:00
|
|
|
const float but_icon_width = NODE_HEADER_ICON_SIZE * 0.8f;
|
|
|
|
|
const float but_icon_right = but_icon_left + but_icon_width;
|
|
|
|
|
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(&block, blender::ui::EmbossType::None);
|
2021-12-14 11:19:47 -06:00
|
|
|
uiBut *but_icon = uiDefIconBut(&block,
|
2021-11-23 17:37:31 +01:00
|
|
|
UI_BTYPE_BUT,
|
|
|
|
|
0,
|
|
|
|
|
extra_info_row.icon,
|
2022-09-25 18:33:28 +10:00
|
|
|
int(but_icon_left),
|
2023-03-17 04:19:05 +01:00
|
|
|
int(rect.ymin + row * (20.0f * UI_SCALE_FAC)),
|
2022-04-25 16:28:21 +02:00
|
|
|
but_icon_width,
|
2021-11-23 17:37:31 +01:00
|
|
|
UI_UNIT_Y,
|
|
|
|
|
nullptr,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
extra_info_row.tooltip);
|
2022-04-15 11:59:02 -05:00
|
|
|
if (extra_info_row.tooltip_fn != nullptr) {
|
2022-04-14 16:31:09 +02:00
|
|
|
UI_but_func_tooltip_set(but_icon,
|
|
|
|
|
extra_info_row.tooltip_fn,
|
|
|
|
|
extra_info_row.tooltip_fn_arg,
|
|
|
|
|
extra_info_row.tooltip_fn_free_arg);
|
|
|
|
|
}
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(&block, blender::ui::EmbossType::Emboss);
|
2022-04-25 16:28:21 +02:00
|
|
|
|
2023-03-17 04:19:05 +01:00
|
|
|
const float but_text_left = but_icon_right + 6.0f * UI_SCALE_FAC;
|
2022-04-25 16:28:21 +02:00
|
|
|
const float but_text_right = rect.xmax;
|
|
|
|
|
const float but_text_width = but_text_right - but_text_left;
|
|
|
|
|
|
|
|
|
|
uiBut *but_text = uiDefBut(&block,
|
|
|
|
|
UI_BTYPE_LABEL,
|
|
|
|
|
0,
|
|
|
|
|
extra_info_row.text.c_str(),
|
2022-09-25 18:33:28 +10:00
|
|
|
int(but_text_left),
|
2023-03-17 04:19:05 +01:00
|
|
|
int(rect.ymin + row * (20.0f * UI_SCALE_FAC)),
|
2022-09-25 18:33:28 +10:00
|
|
|
short(but_text_width),
|
2025-01-09 12:12:50 -05:00
|
|
|
NODE_DY,
|
2022-04-25 16:28:21 +02:00
|
|
|
nullptr,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
2024-05-19 14:41:19 +02:00
|
|
|
extra_info_row.tooltip);
|
|
|
|
|
|
|
|
|
|
if (extra_info_row.tooltip_fn != nullptr) {
|
2024-05-21 16:39:18 +02:00
|
|
|
/* Don't pass tooltip free function because it's already used on the uiBut above. */
|
|
|
|
|
UI_but_func_tooltip_set(
|
|
|
|
|
but_text, extra_info_row.tooltip_fn, extra_info_row.tooltip_fn_arg, nullptr);
|
2024-05-19 14:41:19 +02:00
|
|
|
}
|
2022-04-25 16:28:21 +02:00
|
|
|
|
2025-01-17 12:17:49 +01:00
|
|
|
if (node.is_muted()) {
|
2022-04-14 16:31:09 +02:00
|
|
|
UI_but_flag_enable(but_text, UI_BUT_INACTIVE);
|
2021-11-23 17:37:31 +01:00
|
|
|
UI_but_flag_enable(but_icon, UI_BUT_INACTIVE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-14 09:37:03 +02:00
|
|
|
static void node_draw_extra_info_panel_back(const bNode &node, const rctf &extra_info_rect)
|
|
|
|
|
{
|
2024-12-13 16:51:56 +01:00
|
|
|
const rctf &node_rect = node.runtime->draw_bounds;
|
2023-10-14 09:37:03 +02:00
|
|
|
rctf panel_back_rect = extra_info_rect;
|
2023-10-19 18:53:16 +11:00
|
|
|
/* Extend the panel behind hidden nodes to accommodate the large rounded corners. */
|
2023-10-14 09:37:03 +02:00
|
|
|
if (node.flag & NODE_HIDDEN) {
|
|
|
|
|
panel_back_rect.ymin = BLI_rctf_cent_y(&node_rect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ColorTheme4f color;
|
2025-01-17 12:17:49 +01:00
|
|
|
if (node.is_muted()) {
|
2023-10-14 09:37:03 +02:00
|
|
|
UI_GetThemeColorBlend4f(TH_BACK, TH_NODE, 0.2f, color);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
UI_GetThemeColorBlend4f(TH_BACK, TH_NODE, 0.75f, color);
|
|
|
|
|
}
|
|
|
|
|
color.a -= 0.35f;
|
|
|
|
|
|
|
|
|
|
ColorTheme4f color_outline;
|
|
|
|
|
UI_GetThemeColorBlendShade4fv(TH_BACK, TH_NODE, 0.4f, -20, color_outline);
|
|
|
|
|
|
|
|
|
|
const float outline_width = U.pixelsize;
|
|
|
|
|
BLI_rctf_pad(&panel_back_rect, outline_width, outline_width);
|
|
|
|
|
|
|
|
|
|
UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT);
|
|
|
|
|
UI_draw_roundbox_4fv_ex(
|
|
|
|
|
&panel_back_rect, color, nullptr, 0.0f, color_outline, outline_width, BASIS_RAD);
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-05 15:57:40 +01:00
|
|
|
static void node_draw_extra_info_panel(const bContext &C,
|
2023-07-17 20:13:52 +02:00
|
|
|
TreeDrawContext &tree_draw_ctx,
|
2022-09-13 08:44:26 +02:00
|
|
|
const SpaceNode &snode,
|
|
|
|
|
const bNode &node,
|
2023-07-17 20:13:52 +02:00
|
|
|
ImBuf *preview,
|
2022-09-13 08:44:26 +02:00
|
|
|
uiBlock &block)
|
2021-11-23 17:37:31 +01:00
|
|
|
{
|
2023-12-05 15:57:40 +01:00
|
|
|
const Scene *scene = CTX_data_scene(&C);
|
2023-07-18 15:07:15 +02:00
|
|
|
if (!(snode.overlay.flag & SN_OVERLAY_SHOW_OVERLAYS)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-08-08 17:36:06 +02:00
|
|
|
if (preview && !(preview->x > 0 && preview->y > 0)) {
|
2023-08-09 11:20:04 +10:00
|
|
|
/* If the preview has an non-drawable size, just don't draw it. */
|
2023-08-08 17:36:06 +02:00
|
|
|
preview = nullptr;
|
|
|
|
|
}
|
2023-12-05 15:57:40 +01:00
|
|
|
Vector<NodeExtraInfoRow> extra_info_rows = node_get_extra_info(C, tree_draw_ctx, snode, node);
|
2023-12-11 13:54:57 -05:00
|
|
|
if (extra_info_rows.is_empty() && !preview) {
|
2021-11-23 17:37:31 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-13 16:51:56 +01:00
|
|
|
const rctf &rct = node.runtime->draw_bounds;
|
2021-11-23 17:37:31 +01:00
|
|
|
rctf extra_info_rect;
|
|
|
|
|
|
2023-01-02 17:55:32 -05:00
|
|
|
if (node.is_frame()) {
|
2021-12-03 16:25:17 -05:00
|
|
|
extra_info_rect.xmin = rct.xmin;
|
2023-03-17 04:19:05 +01:00
|
|
|
extra_info_rect.xmax = rct.xmin + 95.0f * UI_SCALE_FAC;
|
|
|
|
|
extra_info_rect.ymin = rct.ymin + 2.0f * UI_SCALE_FAC;
|
|
|
|
|
extra_info_rect.ymax = rct.ymin + 2.0f * UI_SCALE_FAC;
|
2021-11-23 17:37:31 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2023-10-14 09:37:03 +02:00
|
|
|
const float padding = 3.0f * UI_SCALE_FAC;
|
2023-07-12 16:14:12 +02:00
|
|
|
|
2023-10-14 09:37:03 +02:00
|
|
|
extra_info_rect.xmin = rct.xmin + padding;
|
|
|
|
|
extra_info_rect.xmax = rct.xmax - padding;
|
2021-12-03 16:25:17 -05:00
|
|
|
extra_info_rect.ymin = rct.ymax;
|
2023-03-17 04:19:05 +01:00
|
|
|
extra_info_rect.ymax = rct.ymax + extra_info_rows.size() * (20.0f * UI_SCALE_FAC);
|
2023-10-14 09:37:03 +02:00
|
|
|
|
|
|
|
|
float preview_height = 0.0f;
|
|
|
|
|
rctf preview_rect;
|
2023-07-12 16:14:12 +02:00
|
|
|
if (preview) {
|
2023-10-14 09:37:03 +02:00
|
|
|
const float width = BLI_rctf_size_x(&extra_info_rect);
|
2023-07-17 20:13:52 +02:00
|
|
|
if (preview->x > preview->y) {
|
2023-10-14 09:37:03 +02:00
|
|
|
preview_height = (width - 2.0f * padding) * float(preview->y) / float(preview->x) +
|
|
|
|
|
2.0f * padding;
|
|
|
|
|
preview_rect.ymin = extra_info_rect.ymin + padding;
|
|
|
|
|
preview_rect.ymax = extra_info_rect.ymin + preview_height - padding;
|
|
|
|
|
preview_rect.xmin = extra_info_rect.xmin + padding;
|
|
|
|
|
preview_rect.xmax = extra_info_rect.xmax - padding;
|
2023-07-12 16:14:12 +02:00
|
|
|
extra_info_rect.ymax += preview_height;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
preview_height = width;
|
2023-10-14 09:37:03 +02:00
|
|
|
const float preview_width = (width - 2.0f * padding) * float(preview->x) /
|
2023-07-17 20:13:52 +02:00
|
|
|
float(preview->y) +
|
2023-10-14 09:37:03 +02:00
|
|
|
2.0f * padding;
|
|
|
|
|
preview_rect.ymin = extra_info_rect.ymin + padding;
|
|
|
|
|
preview_rect.ymax = extra_info_rect.ymin + preview_height - padding;
|
|
|
|
|
preview_rect.xmin = extra_info_rect.xmin + padding + (width - preview_width) / 2;
|
|
|
|
|
preview_rect.xmax = extra_info_rect.xmax - padding - (width - preview_width) / 2;
|
2023-07-12 16:14:12 +02:00
|
|
|
extra_info_rect.ymax += preview_height;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-23 17:37:31 +01:00
|
|
|
|
2023-10-14 09:37:03 +02:00
|
|
|
node_draw_extra_info_panel_back(node, extra_info_rect);
|
2023-07-12 16:14:12 +02:00
|
|
|
|
|
|
|
|
if (preview) {
|
2023-07-17 20:13:52 +02:00
|
|
|
node_draw_preview(scene, preview, &preview_rect);
|
2023-07-12 16:14:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Resize the rect to draw the textual infos on top of the preview. */
|
|
|
|
|
extra_info_rect.ymin += preview_height;
|
2021-11-23 17:37:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int row : extra_info_rows.index_range()) {
|
2021-12-14 11:19:47 -06:00
|
|
|
node_draw_extra_info_row(node, block, extra_info_rect, row, extra_info_rows[row]);
|
2021-11-23 17:37:31 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-29 18:35:26 +01:00
|
|
|
static short get_viewer_shortcut_icon(const bNode &node)
|
|
|
|
|
{
|
2025-03-14 11:26:57 +01:00
|
|
|
BLI_assert(node.is_type("CompositorNodeViewer") || node.is_type("GeometryNodeViewer"));
|
2025-01-29 18:35:26 +01:00
|
|
|
switch (node.custom1) {
|
|
|
|
|
case NODE_VIEWER_SHORTCUT_NONE:
|
|
|
|
|
/* No change by default. */
|
|
|
|
|
return node.typeinfo->ui_icon;
|
|
|
|
|
case NODE_VIEWER_SHORCTUT_SLOT_1:
|
|
|
|
|
return ICON_EVENT_ONEKEY;
|
|
|
|
|
case NODE_VIEWER_SHORCTUT_SLOT_2:
|
|
|
|
|
return ICON_EVENT_TWOKEY;
|
|
|
|
|
case NODE_VIEWER_SHORCTUT_SLOT_3:
|
|
|
|
|
return ICON_EVENT_THREEKEY;
|
|
|
|
|
case NODE_VIEWER_SHORCTUT_SLOT_4:
|
|
|
|
|
return ICON_EVENT_FOURKEY;
|
|
|
|
|
case NODE_VIEWER_SHORCTUT_SLOT_5:
|
|
|
|
|
return ICON_EVENT_FIVEKEY;
|
|
|
|
|
case NODE_VIEWER_SHORCTUT_SLOT_6:
|
|
|
|
|
return ICON_EVENT_SIXKEY;
|
|
|
|
|
case NODE_VIEWER_SHORCTUT_SLOT_7:
|
|
|
|
|
return ICON_EVENT_SEVENKEY;
|
|
|
|
|
case NODE_VIEWER_SHORCTUT_SLOT_8:
|
|
|
|
|
return ICON_EVENT_EIGHTKEY;
|
|
|
|
|
case NODE_VIEWER_SHORCTUT_SLOT_9:
|
|
|
|
|
return ICON_EVENT_NINEKEY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return node.typeinfo->ui_icon;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-25 09:25:17 +01:00
|
|
|
/* Returns true if the given node has an undefined type, a missing group node tree, or is
|
|
|
|
|
* unsupported in the given node tree. */
|
|
|
|
|
static bool node_undefined_or_unsupported(const bNodeTree &node_tree, const bNode &node)
|
|
|
|
|
{
|
|
|
|
|
if (node.typeinfo == &bke::NodeTypeUndefined) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *disabled_hint = nullptr;
|
|
|
|
|
if (!node.typeinfo->poll(node.typeinfo, &node_tree, &disabled_hint)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (node.is_group()) {
|
|
|
|
|
const ID *group_tree = node.id;
|
|
|
|
|
if (group_tree == nullptr) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!ID_IS_LINKED(group_tree)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if ((group_tree->tag & ID_TAG_MISSING) == 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
static void node_draw_basis(const bContext &C,
|
2022-09-13 08:44:26 +02:00
|
|
|
TreeDrawContext &tree_draw_ctx,
|
2021-12-03 16:25:17 -05:00
|
|
|
const View2D &v2d,
|
|
|
|
|
const SpaceNode &snode,
|
|
|
|
|
bNodeTree &ntree,
|
2023-01-02 17:37:26 -05:00
|
|
|
const bNode &node,
|
2021-12-14 11:19:47 -06:00
|
|
|
uiBlock &block,
|
2013-03-18 16:34:57 +00:00
|
|
|
bNodeInstanceKey key)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2021-02-16 17:15:08 -06:00
|
|
|
const float iconbutw = NODE_HEADER_ICON_SIZE;
|
2023-08-09 14:04:11 +02:00
|
|
|
const bool show_preview = (snode.overlay.flag & SN_OVERLAY_SHOW_OVERLAYS) &&
|
|
|
|
|
(snode.overlay.flag & SN_OVERLAY_SHOW_PREVIEWS) &&
|
2023-08-08 17:36:06 +02:00
|
|
|
(node.flag & NODE_PREVIEW) &&
|
2024-12-13 11:21:39 +11:00
|
|
|
(USER_EXPERIMENTAL_TEST(&U, use_shader_node_previews) ||
|
2023-08-08 17:36:06 +02:00
|
|
|
ntree.type != NTREE_SHADER);
|
2020-09-08 17:19:58 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Skip if out of view. */
|
2024-12-13 16:51:56 +01:00
|
|
|
rctf rect_with_preview = node.runtime->draw_bounds;
|
2023-08-08 17:36:06 +02:00
|
|
|
if (show_preview) {
|
2023-07-12 16:14:12 +02:00
|
|
|
rect_with_preview.ymax += NODE_WIDTH(node);
|
|
|
|
|
}
|
|
|
|
|
if (BLI_rctf_isect(&rect_with_preview, &v2d.cur, nullptr) == false) {
|
2024-11-14 16:04:33 +01:00
|
|
|
UI_block_end_ex(&C,
|
|
|
|
|
tree_draw_ctx.bmain,
|
|
|
|
|
tree_draw_ctx.window,
|
|
|
|
|
tree_draw_ctx.scene,
|
|
|
|
|
tree_draw_ctx.region,
|
|
|
|
|
tree_draw_ctx.depsgraph,
|
|
|
|
|
&block);
|
2010-06-14 07:02:11 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Shadow. */
|
2025-01-09 15:28:57 +01:00
|
|
|
if (!bke::all_zone_node_types().contains(node.type_legacy)) {
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
node_draw_shadow(snode, node, BASIS_RAD, 1.0f);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-12-13 16:51:56 +01:00
|
|
|
const rctf &rct = node.runtime->draw_bounds;
|
2020-09-08 17:19:58 +02:00
|
|
|
float color[4];
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
int color_id = node_get_colorid(tree_draw_ctx, node);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-27 19:07:23 -06:00
|
|
|
GPU_line_width(1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-08 17:36:06 +02:00
|
|
|
/* Overlay atop the node. */
|
|
|
|
|
{
|
|
|
|
|
bool drawn_with_previews = false;
|
|
|
|
|
|
|
|
|
|
if (show_preview) {
|
2025-03-03 14:04:20 +01:00
|
|
|
Map<bNodeInstanceKey, bke::bNodePreview> *previews_compo =
|
|
|
|
|
static_cast<Map<bNodeInstanceKey, bke::bNodePreview> *>(
|
|
|
|
|
CTX_data_pointer_get(&C, "node_previews").data);
|
2023-08-08 17:36:06 +02:00
|
|
|
NestedTreePreviews *previews_shader = tree_draw_ctx.nested_group_infos;
|
|
|
|
|
|
|
|
|
|
if (previews_shader) {
|
|
|
|
|
ImBuf *preview = node_preview_acquire_ibuf(ntree, *previews_shader, node);
|
2023-12-05 15:57:40 +01:00
|
|
|
node_draw_extra_info_panel(C, tree_draw_ctx, snode, node, preview, block);
|
2023-08-08 17:36:06 +02:00
|
|
|
node_release_preview_ibuf(*previews_shader);
|
|
|
|
|
drawn_with_previews = true;
|
|
|
|
|
}
|
|
|
|
|
else if (previews_compo) {
|
2025-03-03 14:04:20 +01:00
|
|
|
if (bke::bNodePreview *preview_compositor = previews_compo->lookup_ptr(key)) {
|
2023-08-08 17:36:06 +02:00
|
|
|
node_draw_extra_info_panel(
|
2023-12-05 15:57:40 +01:00
|
|
|
C, tree_draw_ctx, snode, node, preview_compositor->ibuf, block);
|
2023-08-08 17:36:06 +02:00
|
|
|
drawn_with_previews = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (drawn_with_previews == false) {
|
2023-12-05 15:57:40 +01:00
|
|
|
node_draw_extra_info_panel(C, tree_draw_ctx, snode, node, nullptr, block);
|
2023-07-12 16:14:12 +02:00
|
|
|
}
|
|
|
|
|
}
|
2021-11-23 17:37:31 +01:00
|
|
|
|
2024-03-22 09:15:00 +01:00
|
|
|
const float padding = 0.5f;
|
|
|
|
|
const float corner_radius = BASIS_RAD + padding;
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
/* Header. */
|
2021-02-16 10:55:10 -06:00
|
|
|
{
|
2024-03-22 09:15:00 +01:00
|
|
|
/* Add some padding to prevent transparent gaps with the outline. */
|
2021-02-16 10:55:10 -06:00
|
|
|
const rctf rect = {
|
2024-03-22 09:15:00 +01:00
|
|
|
rct.xmin - padding,
|
|
|
|
|
rct.xmax + padding,
|
|
|
|
|
rct.ymax - NODE_DY - padding,
|
|
|
|
|
rct.ymax + padding,
|
2021-02-16 10:55:10 -06:00
|
|
|
};
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
|
|
|
|
|
float color_header[4];
|
|
|
|
|
|
|
|
|
|
/* Muted nodes get a mix of the background with the node color. */
|
2025-01-17 12:17:49 +01:00
|
|
|
if (node.is_muted()) {
|
2021-10-27 01:24:19 +02:00
|
|
|
UI_GetThemeColorBlend4f(TH_BACK, color_id, 0.1f, color_header);
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2021-10-27 01:24:19 +02:00
|
|
|
UI_GetThemeColorBlend4f(TH_NODE, color_id, 0.4f, color_header);
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT);
|
2024-03-22 09:15:00 +01:00
|
|
|
UI_draw_roundbox_4fv(&rect, true, corner_radius, color_header);
|
2021-02-16 10:55:10 -06:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Show/hide icons. */
|
2021-12-03 16:25:17 -05:00
|
|
|
float iconofs = rct.xmax - 0.35f * U.widget_unit;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-01-17 12:17:49 +01:00
|
|
|
/* Group edit. This icon should be the first for the node groups. Note that we intentionally
|
|
|
|
|
* don't check for NODE_GROUP_CUSTOM here. */
|
2025-01-09 15:28:57 +01:00
|
|
|
if (node.type_legacy == NODE_GROUP) {
|
2012-07-09 19:58:36 +00:00
|
|
|
iconofs -= iconbutw;
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(&block, blender::ui::EmbossType::None);
|
2021-12-14 11:19:47 -06:00
|
|
|
uiBut *but = uiDefIconBut(&block,
|
2020-11-30 13:56:46 -05:00
|
|
|
UI_BTYPE_BUT_TOGGLE,
|
2021-02-24 14:53:37 -06:00
|
|
|
0,
|
2023-09-08 14:22:06 +02:00
|
|
|
ICON_NODETREE,
|
2020-11-30 13:56:46 -05:00
|
|
|
iconofs,
|
2021-12-03 16:25:17 -05:00
|
|
|
rct.ymax - NODE_DY,
|
2020-11-30 13:56:46 -05:00
|
|
|
iconbutw,
|
|
|
|
|
UI_UNIT_Y,
|
2021-02-16 10:55:10 -06:00
|
|
|
nullptr,
|
2020-11-30 13:56:46 -05:00
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
"");
|
2023-01-02 17:37:26 -05:00
|
|
|
UI_but_func_set(but,
|
|
|
|
|
node_toggle_button_cb,
|
|
|
|
|
POINTER_FROM_INT(node.identifier),
|
2023-09-08 14:22:06 +02:00
|
|
|
(void *)"NODE_OT_group_edit");
|
|
|
|
|
if (node.id) {
|
|
|
|
|
UI_but_icon_indicator_number_set(but, ID_REAL_USERS(node.id));
|
|
|
|
|
}
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(&block, blender::ui::EmbossType::Emboss);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2023-09-08 14:22:06 +02:00
|
|
|
/* Preview. */
|
|
|
|
|
if (node_is_previewable(snode, ntree, node)) {
|
2024-09-05 19:51:31 +02:00
|
|
|
const bool is_active = node.flag & NODE_PREVIEW;
|
2012-07-09 19:58:36 +00:00
|
|
|
iconofs -= iconbutw;
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(&block, blender::ui::EmbossType::None);
|
2021-12-14 11:19:47 -06:00
|
|
|
uiBut *but = uiDefIconBut(&block,
|
2020-11-30 13:56:46 -05:00
|
|
|
UI_BTYPE_BUT_TOGGLE,
|
2021-02-24 14:53:37 -06:00
|
|
|
0,
|
2024-09-05 19:51:31 +02:00
|
|
|
is_active ? ICON_HIDE_OFF : ICON_HIDE_ON,
|
2020-11-30 13:56:46 -05:00
|
|
|
iconofs,
|
2021-12-03 16:25:17 -05:00
|
|
|
rct.ymax - NODE_DY,
|
2020-11-30 13:56:46 -05:00
|
|
|
iconbutw,
|
|
|
|
|
UI_UNIT_Y,
|
2021-02-16 10:55:10 -06:00
|
|
|
nullptr,
|
2020-11-30 13:56:46 -05:00
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
"");
|
2023-01-02 17:37:26 -05:00
|
|
|
UI_but_func_set(but,
|
|
|
|
|
node_toggle_button_cb,
|
|
|
|
|
POINTER_FROM_INT(node.identifier),
|
2023-09-08 14:22:06 +02:00
|
|
|
(void *)"NODE_OT_preview_toggle");
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(&block, blender::ui::EmbossType::Emboss);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2025-01-09 15:28:57 +01:00
|
|
|
if (ELEM(node.type_legacy, NODE_CUSTOM, NODE_CUSTOM_GROUP) &&
|
|
|
|
|
node.typeinfo->ui_icon != ICON_NONE)
|
|
|
|
|
{
|
2020-03-16 18:25:23 +01:00
|
|
|
iconofs -= iconbutw;
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(&block, blender::ui::EmbossType::None);
|
2021-12-14 11:19:47 -06:00
|
|
|
uiDefIconBut(&block,
|
2020-03-16 18:25:23 +01:00
|
|
|
UI_BTYPE_BUT,
|
|
|
|
|
0,
|
2021-12-03 16:25:17 -05:00
|
|
|
node.typeinfo->ui_icon,
|
2020-03-16 18:25:23 +01:00
|
|
|
iconofs,
|
2021-12-03 16:25:17 -05:00
|
|
|
rct.ymax - NODE_DY,
|
2020-03-16 18:25:23 +01:00
|
|
|
iconbutw,
|
|
|
|
|
UI_UNIT_Y,
|
2021-02-16 10:55:10 -06:00
|
|
|
nullptr,
|
2020-03-16 18:25:23 +01:00
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
"");
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(&block, blender::ui::EmbossType::Emboss);
|
2020-03-16 18:25:23 +01:00
|
|
|
}
|
2025-01-09 15:28:57 +01:00
|
|
|
if (node.type_legacy == GEO_NODE_VIEWER) {
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
const bool is_active = &node == tree_draw_ctx.active_geometry_nodes_viewer;
|
|
|
|
|
iconofs -= iconbutw;
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(&block, blender::ui::EmbossType::None);
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
uiBut *but = uiDefIconBut(&block,
|
|
|
|
|
UI_BTYPE_BUT,
|
|
|
|
|
0,
|
|
|
|
|
is_active ? ICON_HIDE_OFF : ICON_HIDE_ON,
|
|
|
|
|
iconofs,
|
|
|
|
|
rct.ymax - NODE_DY,
|
|
|
|
|
iconbutw,
|
|
|
|
|
UI_UNIT_Y,
|
|
|
|
|
nullptr,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
"");
|
|
|
|
|
/* Selection implicitly activates the node. */
|
2025-03-14 11:26:57 +01:00
|
|
|
const char *operator_idname = is_active ? "NODE_OT_deactivate_viewer" :
|
|
|
|
|
"NODE_OT_activate_viewer";
|
2023-01-02 17:37:26 -05:00
|
|
|
UI_but_func_set(
|
|
|
|
|
but, node_toggle_button_cb, POINTER_FROM_INT(node.identifier), (void *)operator_idname);
|
2025-03-14 11:26:57 +01:00
|
|
|
|
|
|
|
|
short shortcut_icon = get_viewer_shortcut_icon(node);
|
|
|
|
|
uiDefIconBut(&block,
|
|
|
|
|
UI_BTYPE_BUT,
|
|
|
|
|
0,
|
|
|
|
|
shortcut_icon,
|
|
|
|
|
iconofs - 1.2 * iconbutw,
|
|
|
|
|
rct.ymax - NODE_DY,
|
|
|
|
|
iconbutw,
|
|
|
|
|
UI_UNIT_Y,
|
|
|
|
|
nullptr,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
"");
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(&block, blender::ui::EmbossType::Emboss);
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
}
|
2025-01-29 18:35:26 +01:00
|
|
|
/* Viewer node shortcuts. */
|
|
|
|
|
if (node.is_type("CompositorNodeViewer")) {
|
|
|
|
|
short shortcut_icon = get_viewer_shortcut_icon(node);
|
|
|
|
|
iconofs -= iconbutw;
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(&block, blender::ui::EmbossType::None);
|
2025-01-29 18:35:26 +01:00
|
|
|
uiDefIconBut(&block,
|
|
|
|
|
UI_BTYPE_BUT,
|
|
|
|
|
0,
|
|
|
|
|
shortcut_icon,
|
|
|
|
|
iconofs,
|
|
|
|
|
rct.ymax - NODE_DY,
|
|
|
|
|
iconbutw,
|
|
|
|
|
UI_UNIT_Y,
|
|
|
|
|
nullptr,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
"");
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(&block, blender::ui::EmbossType::Emboss);
|
2025-01-29 18:35:26 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-13 08:44:26 +02:00
|
|
|
node_add_error_message_button(tree_draw_ctx, node, block, rct, iconofs);
|
2021-02-16 17:15:08 -06:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Title. */
|
2021-12-03 16:25:17 -05:00
|
|
|
if (node.flag & SELECT) {
|
2017-02-14 13:00:22 +01:00
|
|
|
UI_GetThemeColor4fv(TH_SELECT, color);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
UI_GetThemeColorBlendShade4fv(TH_SELECT, color_id, 0.4f, 10, color);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
/* Collapse/expand icon. */
|
2011-12-18 12:51:50 +00:00
|
|
|
{
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
const int but_size = U.widget_unit * 0.8f;
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(&block, blender::ui::EmbossType::None);
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
|
2021-12-14 11:19:47 -06:00
|
|
|
uiBut *but = uiDefIconBut(&block,
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
UI_BTYPE_BUT_TOGGLE,
|
|
|
|
|
0,
|
|
|
|
|
ICON_DOWNARROW_HLT,
|
2021-12-03 16:25:17 -05:00
|
|
|
rct.xmin + (NODE_MARGIN_X / 3),
|
|
|
|
|
rct.ymax - NODE_DY / 2.2f - but_size / 2,
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
but_size,
|
|
|
|
|
but_size,
|
|
|
|
|
nullptr,
|
|
|
|
|
0.0f,
|
|
|
|
|
0.0f,
|
|
|
|
|
"");
|
|
|
|
|
|
2023-01-02 17:37:26 -05:00
|
|
|
UI_but_func_set(but,
|
|
|
|
|
node_toggle_button_cb,
|
|
|
|
|
POINTER_FROM_INT(node.identifier),
|
|
|
|
|
(void *)"NODE_OT_hide_toggle");
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(&block, blender::ui::EmbossType::Emboss);
|
2011-12-18 12:51:50 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-03-05 11:17:50 +01:00
|
|
|
const std::string showname = bke::node_label(ntree, node);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-14 11:19:47 -06:00
|
|
|
uiBut *but = uiDefBut(&block,
|
2019-03-28 17:39:54 +01:00
|
|
|
UI_BTYPE_LABEL,
|
|
|
|
|
0,
|
|
|
|
|
showname,
|
2022-09-25 18:33:28 +10:00
|
|
|
int(rct.xmin + NODE_MARGIN_X + 0.4f),
|
|
|
|
|
int(rct.ymax - NODE_DY),
|
2024-11-25 22:34:21 +01:00
|
|
|
short(iconofs - rct.xmin - NODE_MARGIN_X),
|
2025-01-09 12:12:50 -05:00
|
|
|
NODE_DY,
|
2021-02-16 10:55:10 -06:00
|
|
|
nullptr,
|
2019-03-28 17:39:54 +01:00
|
|
|
0,
|
|
|
|
|
0,
|
2025-01-08 16:34:41 +01:00
|
|
|
TIP_(node.typeinfo->ui_description.c_str()));
|
2024-05-08 11:25:00 +02:00
|
|
|
UI_but_func_tooltip_set(
|
|
|
|
|
but,
|
2025-02-14 15:12:48 -05:00
|
|
|
[](bContext * /*C*/, void *arg, const StringRef tip) -> std::string {
|
2024-05-08 11:25:00 +02:00
|
|
|
const bNode &node = *static_cast<const bNode *>(arg);
|
|
|
|
|
if (node.typeinfo->ui_description_fn) {
|
|
|
|
|
return node.typeinfo->ui_description_fn(node);
|
|
|
|
|
}
|
2025-02-14 15:12:48 -05:00
|
|
|
return tip;
|
2024-05-08 11:25:00 +02:00
|
|
|
},
|
|
|
|
|
const_cast<bNode *>(&node),
|
|
|
|
|
nullptr);
|
2024-04-26 16:29:46 +02:00
|
|
|
|
2025-01-17 12:17:49 +01:00
|
|
|
if (node.is_muted()) {
|
2019-01-15 23:24:20 +11:00
|
|
|
UI_but_flag_enable(but, UI_BUT_INACTIVE);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
/* Wire across the node when muted/disabled. */
|
2025-01-17 12:17:49 +01:00
|
|
|
if (node.is_muted()) {
|
2023-11-01 09:29:56 +01:00
|
|
|
node_draw_mute_line(C, v2d, snode, node);
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Body. */
|
2024-03-22 09:15:00 +01:00
|
|
|
const float outline_width = U.pixelsize;
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
{
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Use warning color to indicate undefined types. */
|
2025-03-25 09:25:17 +01:00
|
|
|
if (node_undefined_or_unsupported(ntree, node)) {
|
2021-10-27 01:24:19 +02:00
|
|
|
UI_GetThemeColorBlend4f(TH_REDALERT, TH_NODE, 0.4f, color);
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
}
|
|
|
|
|
/* Muted nodes get a mix of the background with the node color. */
|
2025-01-17 12:17:49 +01:00
|
|
|
else if (node.is_muted()) {
|
2021-10-27 01:24:19 +02:00
|
|
|
UI_GetThemeColorBlend4f(TH_BACK, TH_NODE, 0.2f, color);
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
}
|
2021-12-03 16:25:17 -05:00
|
|
|
else if (node.flag & NODE_CUSTOM_COLOR) {
|
|
|
|
|
rgba_float_args_set(color, node.color[0], node.color[1], node.color[2], 1.0f);
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
UI_GetThemeColor4fv(TH_NODE, color);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
/* Draw selected nodes fully opaque. */
|
2021-12-03 16:25:17 -05:00
|
|
|
if (node.flag & SELECT) {
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
color[3] = 1.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Draw muted nodes slightly transparent so the wires inside are visible. */
|
2025-01-17 12:17:49 +01:00
|
|
|
if (node.is_muted()) {
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
color[3] -= 0.2f;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-22 09:15:00 +01:00
|
|
|
/* Add some padding to prevent transparent gaps with the outline. */
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
const rctf rect = {
|
2024-03-22 09:15:00 +01:00
|
|
|
rct.xmin - padding,
|
|
|
|
|
rct.xmax + padding,
|
|
|
|
|
rct.ymin - padding,
|
|
|
|
|
rct.ymax - (NODE_DY + outline_width) + padding,
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
UI_draw_roundbox_corner_set(UI_CNR_BOTTOM_LEFT | UI_CNR_BOTTOM_RIGHT);
|
2024-03-22 09:15:00 +01:00
|
|
|
UI_draw_roundbox_4fv(&rect, true, corner_radius, color);
|
2023-08-30 12:37:21 +02:00
|
|
|
|
|
|
|
|
if (is_node_panels_supported(node)) {
|
2024-10-11 12:20:58 +02:00
|
|
|
node_draw_panels_background(node);
|
2023-08-30 12:37:21 +02:00
|
|
|
}
|
2019-03-28 17:39:54 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
/* Header underline. */
|
2021-02-16 10:55:10 -06:00
|
|
|
{
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
float color_underline[4];
|
|
|
|
|
|
2025-01-17 12:17:49 +01:00
|
|
|
if (node.is_muted()) {
|
2024-03-22 09:15:00 +01:00
|
|
|
UI_GetThemeColorBlend4f(TH_BACK, color_id, 0.05f, color_underline);
|
2022-09-01 19:46:19 +02:00
|
|
|
color_underline[3] = 1.0f;
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2021-10-27 04:33:12 +02:00
|
|
|
UI_GetThemeColorBlend4f(TH_BACK, color_id, 0.2f, color_underline);
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-16 10:55:10 -06:00
|
|
|
const rctf rect = {
|
2021-12-03 16:25:17 -05:00
|
|
|
rct.xmin,
|
|
|
|
|
rct.xmax,
|
|
|
|
|
rct.ymax - (NODE_DY + outline_width),
|
|
|
|
|
rct.ymax - NODE_DY,
|
2021-02-16 10:55:10 -06:00
|
|
|
};
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
|
|
|
|
|
UI_draw_roundbox_corner_set(UI_CNR_NONE);
|
|
|
|
|
UI_draw_roundbox_4fv(&rect, true, 0.0f, color_underline);
|
2021-02-16 10:55:10 -06:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
/* Outline. */
|
|
|
|
|
{
|
|
|
|
|
const rctf rect = {
|
2021-12-03 16:25:17 -05:00
|
|
|
rct.xmin - outline_width,
|
|
|
|
|
rct.xmax + outline_width,
|
|
|
|
|
rct.ymin - outline_width,
|
|
|
|
|
rct.ymax + outline_width,
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
};
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
/* Color the outline according to active, selected, or undefined status. */
|
|
|
|
|
float color_outline[4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
if (node.flag & SELECT) {
|
|
|
|
|
UI_GetThemeColor4fv((node.flag & NODE_ACTIVE) ? TH_ACTIVE : TH_SELECT, color_outline);
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
}
|
2025-03-25 09:25:17 +01:00
|
|
|
else if (node_undefined_or_unsupported(ntree, node)) {
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
UI_GetThemeColor4fv(TH_REDALERT, color_outline);
|
|
|
|
|
}
|
2025-01-09 15:28:57 +01:00
|
|
|
else if (const bke::bNodeZoneType *zone_type = bke::zone_type_by_node_type(node.type_legacy)) {
|
2023-09-20 14:40:56 +02:00
|
|
|
UI_GetThemeColor4fv(zone_type->theme_id, color_outline);
|
2023-07-11 22:36:10 +02:00
|
|
|
color_outline[3] = 1.0f;
|
|
|
|
|
}
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
else {
|
|
|
|
|
UI_GetThemeColorBlendShade4fv(TH_BACK, TH_NODE, 0.4f, -20, color_outline);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UI_draw_roundbox_corner_set(UI_CNR_ALL);
|
2022-01-31 12:31:07 -05:00
|
|
|
UI_draw_roundbox_4fv(&rect, false, BASIS_RAD + outline_width, color_outline);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-11-18 21:21:10 +01:00
|
|
|
/* Skip slow socket drawing if zoom is small. */
|
2024-11-23 16:42:38 +01:00
|
|
|
if (draw_node_details(snode)) {
|
|
|
|
|
node_draw_sockets(C, block, snode, ntree, node);
|
2023-08-30 12:37:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (is_node_panels_supported(node)) {
|
|
|
|
|
node_draw_panels(ntree, node, block);
|
2021-11-18 21:21:10 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-11-14 16:04:33 +01:00
|
|
|
UI_block_end_ex(&C,
|
|
|
|
|
tree_draw_ctx.bmain,
|
|
|
|
|
tree_draw_ctx.window,
|
|
|
|
|
tree_draw_ctx.scene,
|
|
|
|
|
tree_draw_ctx.region,
|
|
|
|
|
tree_draw_ctx.depsgraph,
|
|
|
|
|
&block);
|
2021-12-14 11:19:47 -06:00
|
|
|
UI_block_draw(&C, &block);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-14 11:19:47 -06:00
|
|
|
static void node_draw_hidden(const bContext &C,
|
2022-09-13 08:44:26 +02:00
|
|
|
TreeDrawContext &tree_draw_ctx,
|
2021-12-14 11:19:47 -06:00
|
|
|
const View2D &v2d,
|
|
|
|
|
const SpaceNode &snode,
|
|
|
|
|
bNodeTree &ntree,
|
|
|
|
|
bNode &node,
|
|
|
|
|
uiBlock &block)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2024-12-13 16:51:56 +01:00
|
|
|
const rctf &rct = node.runtime->draw_bounds;
|
2021-12-03 16:25:17 -05:00
|
|
|
float centy = BLI_rctf_cent_y(&rct);
|
|
|
|
|
float hiddenrad = BLI_rctf_size_y(&rct) / 2.0f;
|
2020-09-08 17:19:58 +02:00
|
|
|
|
|
|
|
|
float scale;
|
2021-12-03 16:25:17 -05:00
|
|
|
UI_view2d_scale_get(&v2d, &scale, nullptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
const int color_id = node_get_colorid(tree_draw_ctx, node);
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
|
2023-12-05 15:57:40 +01:00
|
|
|
node_draw_extra_info_panel(C, tree_draw_ctx, snode, node, nullptr, block);
|
2022-04-25 16:39:13 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Shadow. */
|
2012-06-01 14:42:21 +00:00
|
|
|
node_draw_shadow(snode, node, hiddenrad, 1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
/* Wire across the node when muted/disabled. */
|
2025-01-17 12:17:49 +01:00
|
|
|
if (node.is_muted()) {
|
2023-11-01 09:29:56 +01:00
|
|
|
node_draw_mute_line(C, v2d, snode, node);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
/* Body. */
|
|
|
|
|
float color[4];
|
|
|
|
|
{
|
2025-03-25 09:25:17 +01:00
|
|
|
if (node_undefined_or_unsupported(ntree, node)) {
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
/* Use warning color to indicate undefined types. */
|
2021-10-27 01:24:19 +02:00
|
|
|
UI_GetThemeColorBlend4f(TH_REDALERT, TH_NODE, 0.4f, color);
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
}
|
2025-01-17 12:17:49 +01:00
|
|
|
else if (node.is_muted()) {
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
/* Muted nodes get a mix of the background with the node color. */
|
|
|
|
|
UI_GetThemeColorBlendShade4fv(TH_BACK, color_id, 0.1f, 0, color);
|
|
|
|
|
}
|
2021-12-03 16:25:17 -05:00
|
|
|
else if (node.flag & NODE_CUSTOM_COLOR) {
|
|
|
|
|
rgba_float_args_set(color, node.color[0], node.color[1], node.color[2], 1.0f);
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2021-10-27 01:24:19 +02:00
|
|
|
UI_GetThemeColorBlend4f(TH_NODE, color_id, 0.4f, color);
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
/* Draw selected nodes fully opaque. */
|
2021-12-03 16:25:17 -05:00
|
|
|
if (node.flag & SELECT) {
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
color[3] = 1.0f;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
/* Draw muted nodes slightly transparent so the wires inside are visible. */
|
2025-01-17 12:17:49 +01:00
|
|
|
if (node.is_muted()) {
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
color[3] -= 0.2f;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-03-22 09:15:00 +01:00
|
|
|
/* Add some padding to prevent transparent gaps with the outline. */
|
|
|
|
|
const float padding = 0.5f;
|
|
|
|
|
const rctf rect = {
|
|
|
|
|
rct.xmin - padding,
|
|
|
|
|
rct.xmax + padding,
|
|
|
|
|
rct.ymin - padding,
|
|
|
|
|
rct.ymax + padding,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
UI_draw_roundbox_4fv(&rect, true, hiddenrad + padding, color);
|
2013-03-22 13:53:58 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Title. */
|
2021-12-03 16:25:17 -05:00
|
|
|
if (node.flag & SELECT) {
|
2017-02-14 13:00:22 +01:00
|
|
|
UI_GetThemeColor4fv(TH_SELECT, color);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
UI_GetThemeColorBlendShade4fv(TH_SELECT, color_id, 0.4f, 10, color);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
/* Collapse/expand icon. */
|
2011-12-18 12:51:50 +00:00
|
|
|
{
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
const int but_size = U.widget_unit * 1.0f;
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(&block, blender::ui::EmbossType::None);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-14 11:19:47 -06:00
|
|
|
uiBut *but = uiDefIconBut(&block,
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
UI_BTYPE_BUT_TOGGLE,
|
|
|
|
|
0,
|
|
|
|
|
ICON_RIGHTARROW,
|
2021-12-03 16:25:17 -05:00
|
|
|
rct.xmin + (NODE_MARGIN_X / 3),
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
centy - but_size / 2,
|
|
|
|
|
but_size,
|
|
|
|
|
but_size,
|
|
|
|
|
nullptr,
|
|
|
|
|
0.0f,
|
|
|
|
|
0.0f,
|
|
|
|
|
"");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-02 17:37:26 -05:00
|
|
|
UI_but_func_set(but,
|
|
|
|
|
node_toggle_button_cb,
|
|
|
|
|
POINTER_FROM_INT(node.identifier),
|
|
|
|
|
(void *)"NODE_OT_hide_toggle");
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(&block, blender::ui::EmbossType::Emboss);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-03-05 11:17:50 +01:00
|
|
|
const std::string showname = bke::node_label(ntree, node);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-14 11:19:47 -06:00
|
|
|
uiBut *but = uiDefBut(&block,
|
2019-04-02 16:39:48 +02:00
|
|
|
UI_BTYPE_LABEL,
|
|
|
|
|
0,
|
|
|
|
|
showname,
|
2021-12-03 16:25:17 -05:00
|
|
|
round_fl_to_int(rct.xmin + NODE_MARGIN_X),
|
2019-04-02 16:39:48 +02:00
|
|
|
round_fl_to_int(centy - NODE_DY * 0.5f),
|
2024-11-25 23:29:42 +01:00
|
|
|
short(BLI_rctf_size_x(&rct) - (2 * U.widget_unit)),
|
2025-01-09 12:12:50 -05:00
|
|
|
NODE_DY,
|
2021-02-16 10:55:10 -06:00
|
|
|
nullptr,
|
2019-04-02 16:39:48 +02:00
|
|
|
0,
|
|
|
|
|
0,
|
2025-01-08 16:34:41 +01:00
|
|
|
TIP_(node.typeinfo->ui_description.c_str()));
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
|
|
|
|
|
/* Outline. */
|
|
|
|
|
{
|
2024-03-22 09:15:00 +01:00
|
|
|
const float outline_width = U.pixelsize;
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
const rctf rect = {
|
2021-12-03 16:25:17 -05:00
|
|
|
rct.xmin - outline_width,
|
|
|
|
|
rct.xmax + outline_width,
|
|
|
|
|
rct.ymin - outline_width,
|
|
|
|
|
rct.ymax + outline_width,
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Color the outline according to active, selected, or undefined status. */
|
|
|
|
|
float color_outline[4];
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
if (node.flag & SELECT) {
|
|
|
|
|
UI_GetThemeColor4fv((node.flag & NODE_ACTIVE) ? TH_ACTIVE : TH_SELECT, color_outline);
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
}
|
2025-03-25 09:25:17 +01:00
|
|
|
else if (node_undefined_or_unsupported(ntree, node)) {
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
UI_GetThemeColor4fv(TH_REDALERT, color_outline);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
UI_GetThemeColorBlendShade4fv(TH_BACK, TH_NODE, 0.4f, -20, color_outline);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UI_draw_roundbox_corner_set(UI_CNR_ALL);
|
2024-03-22 09:15:00 +01:00
|
|
|
UI_draw_roundbox_4fv(&rect, false, hiddenrad + outline_width, color_outline);
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-17 12:17:49 +01:00
|
|
|
if (node.is_muted()) {
|
2019-04-02 16:39:48 +02:00
|
|
|
UI_but_flag_enable(but, UI_BUT_INACTIVE);
|
2012-10-21 05:46:41 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Scale widget thing. */
|
2018-07-18 00:12:21 +02:00
|
|
|
uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
GPU_blend(GPU_BLEND_ALPHA);
|
2022-09-01 09:31:07 -03:00
|
|
|
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
immUniformThemeColorShadeAlpha(TH_TEXT, -40, -180);
|
2021-11-03 16:50:43 +01:00
|
|
|
float dx = 0.5f * U.widget_unit;
|
2021-12-03 16:25:17 -05:00
|
|
|
const float dx2 = 0.15f * U.widget_unit * snode.runtime->aspect;
|
2021-11-03 16:50:43 +01:00
|
|
|
const float dy = 0.2f * U.widget_unit;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
immBegin(GPU_PRIM_LINES, 4);
|
2021-12-03 16:25:17 -05:00
|
|
|
immVertex2f(pos, rct.xmax - dx, centy - dy);
|
|
|
|
|
immVertex2f(pos, rct.xmax - dx, centy + dy);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
immVertex2f(pos, rct.xmax - dx - dx2, centy - dy);
|
|
|
|
|
immVertex2f(pos, rct.xmax - dx - dx2, centy + dy);
|
2017-03-06 20:29:09 -03:00
|
|
|
immEnd();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
immUniformThemeColorShadeAlpha(TH_TEXT, 0, -180);
|
2021-12-03 16:25:17 -05:00
|
|
|
dx -= snode.runtime->aspect;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
immBegin(GPU_PRIM_LINES, 4);
|
2021-12-03 16:25:17 -05:00
|
|
|
immVertex2f(pos, rct.xmax - dx, centy - dy);
|
|
|
|
|
immVertex2f(pos, rct.xmax - dx, centy + dy);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
immVertex2f(pos, rct.xmax - dx - dx2, centy - dy);
|
|
|
|
|
immVertex2f(pos, rct.xmax - dx - dx2, centy + dy);
|
2017-03-06 20:29:09 -03:00
|
|
|
immEnd();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-03-06 20:29:09 -03:00
|
|
|
immUnbindProgram();
|
Node Editor: Style update to nodes
This patch changes how nodes look visually, in an attempt to fix a number of issues:
* The header background is currently drawn using a theme color fully opaque, this limits the colors we can use because the node name/label is drawn on top.
* Hard-coded transparency makes nodes hard to read. The node backdrop already has alpha so if the user wants it they can set it. This patch uses alpha from the theme.
* Better muted status indicator, instead of simply making everything transparent and the wires inside red, draw a red outline around the node, darken the header and backdrop.
* On muted nodes, display wires behind the backdrop to not interfere with text/widgets inside the node.
Nodes:
* Darken header to improve readability of node label.
* Draw a line under the header
* Thicker outline.
* Do not hard-code transparency on nodes, use the theme's node backdrop alpha component.
* Use angle icon instead of triangle (to be consistent with the [[ https://developer.blender.org/D12814 | changes ]] to panels)
Style adjustment to sockets drawing:
* Do not hard-code the socket outline color to black, use `TH_WIRE` instead
* Do not use `TH_TEXT_HI` for selected sockets, use `TH_ACTIVE` (active node outline)
* Do not draw sockets background transparent on muted nodes.
* Thicker outline to help contrast and readability
{F11496707, size=full}
Reviewed By: #user_interface, HooglyBoogly
Differential Revision: https://developer.blender.org/D12884
2021-10-26 20:07:26 +02:00
|
|
|
GPU_blend(GPU_BLEND_NONE);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-11-23 16:42:38 +01:00
|
|
|
node_draw_sockets(C, block, snode, ntree, node);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-11-14 16:04:33 +01:00
|
|
|
UI_block_end_ex(&C,
|
|
|
|
|
tree_draw_ctx.bmain,
|
|
|
|
|
tree_draw_ctx.window,
|
|
|
|
|
tree_draw_ctx.scene,
|
|
|
|
|
tree_draw_ctx.region,
|
|
|
|
|
tree_draw_ctx.depsgraph,
|
|
|
|
|
&block);
|
2021-12-14 11:19:47 -06:00
|
|
|
UI_block_draw(&C, &block);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-03 11:05:59 -05:00
|
|
|
int node_get_resize_cursor(NodeResizeDirection directions)
|
2012-05-22 14:13:33 +00:00
|
|
|
{
|
2019-03-26 21:16:47 +11:00
|
|
|
if (directions == 0) {
|
2019-09-26 14:31:48 +02:00
|
|
|
return WM_CURSOR_DEFAULT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2020-07-03 17:20:08 +02:00
|
|
|
if ((directions & ~(NODE_RESIZE_TOP | NODE_RESIZE_BOTTOM)) == 0) {
|
2019-09-26 14:31:48 +02:00
|
|
|
return WM_CURSOR_Y_MOVE;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2020-07-03 17:20:08 +02:00
|
|
|
if ((directions & ~(NODE_RESIZE_RIGHT | NODE_RESIZE_LEFT)) == 0) {
|
2019-09-26 14:31:48 +02:00
|
|
|
return WM_CURSOR_X_MOVE;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2020-07-03 17:20:08 +02:00
|
|
|
return WM_CURSOR_EDIT;
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
2023-01-03 13:34:51 -05:00
|
|
|
static const bNode *find_node_under_cursor(SpaceNode &snode, const float2 &cursor)
|
|
|
|
|
{
|
2023-10-10 10:57:51 +02:00
|
|
|
for (const bNode *node : tree_draw_order_calc_nodes_reversed(*snode.edittree)) {
|
2024-12-13 16:51:56 +01:00
|
|
|
if (BLI_rctf_isect_pt(&node->runtime->draw_bounds, cursor[0], cursor[1])) {
|
2023-10-10 10:57:51 +02:00
|
|
|
return node;
|
2023-01-03 13:34:51 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-25 15:23:31 +01:00
|
|
|
void node_set_cursor(wmWindow &win, ARegion ®ion, SpaceNode &snode, const float2 &cursor)
|
2012-05-22 14:13:33 +00:00
|
|
|
{
|
2021-12-03 16:25:17 -05:00
|
|
|
const bNodeTree *ntree = snode.edittree;
|
|
|
|
|
if (ntree == nullptr) {
|
|
|
|
|
WM_cursor_set(&win, WM_CURSOR_DEFAULT);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-11-25 15:23:31 +01:00
|
|
|
if (node_find_indicated_socket(snode, region, cursor, SOCK_IN | SOCK_OUT)) {
|
2021-12-03 16:25:17 -05:00
|
|
|
WM_cursor_set(&win, WM_CURSOR_DEFAULT);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-01-03 13:34:51 -05:00
|
|
|
const bNode *node = find_node_under_cursor(snode, cursor);
|
|
|
|
|
if (!node) {
|
|
|
|
|
WM_cursor_set(&win, WM_CURSOR_DEFAULT);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-06-03 12:45:12 +02:00
|
|
|
const NodeResizeDirection dir = node_get_resize_direction(snode, node, cursor[0], cursor[1]);
|
2023-01-03 13:34:51 -05:00
|
|
|
if (node->is_frame() && dir == NODE_RESIZE_NONE) {
|
|
|
|
|
/* Indicate that frame nodes can be moved/selected on their borders. */
|
2023-06-03 12:45:12 +02:00
|
|
|
const rctf frame_inside = node_frame_rect_inside(snode, *node);
|
2023-01-03 13:34:51 -05:00
|
|
|
if (!BLI_rctf_isect_pt(&frame_inside, cursor[0], cursor[1])) {
|
|
|
|
|
WM_cursor_set(&win, WM_CURSOR_NSEW_SCROLL);
|
|
|
|
|
return;
|
2022-01-05 12:32:00 +01:00
|
|
|
}
|
2023-01-03 13:34:51 -05:00
|
|
|
WM_cursor_set(&win, WM_CURSOR_DEFAULT);
|
|
|
|
|
return;
|
2021-12-03 16:25:17 -05:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-03 13:34:51 -05:00
|
|
|
WM_cursor_set(&win, node_get_resize_cursor(dir));
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
static void count_multi_input_socket_links(bNodeTree &ntree, SpaceNode &snode)
|
2021-02-11 01:16:17 -06:00
|
|
|
{
|
2023-01-02 17:55:32 -05:00
|
|
|
for (bNode *node : ntree.all_nodes()) {
|
|
|
|
|
for (bNodeSocket *socket : node->input_sockets()) {
|
|
|
|
|
if (socket->is_multi_input()) {
|
|
|
|
|
socket->runtime->total_inputs = socket->directly_linked_links().size();
|
|
|
|
|
}
|
2021-06-14 10:04:32 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* Count temporary links going into this socket. */
|
2021-12-03 16:25:17 -05:00
|
|
|
if (snode.runtime->linkdrag) {
|
2022-12-29 14:09:58 -05:00
|
|
|
for (const bNodeLink &link : snode.runtime->linkdrag->links) {
|
|
|
|
|
if (link.tosock && (link.tosock->flag & SOCK_MULTI_INPUT)) {
|
2023-01-02 17:55:32 -05:00
|
|
|
link.tosock->runtime->total_inputs++;
|
2021-02-11 01:16:17 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 18:24:22 +01:00
|
|
|
static float frame_node_label_height(const NodeFrame &frame_data)
|
|
|
|
|
{
|
2023-03-17 04:19:05 +01:00
|
|
|
return frame_data.label_size * UI_SCALE_FAC;
|
2023-03-10 18:24:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define NODE_FRAME_MARGIN (1.5f * U.widget_unit)
|
|
|
|
|
|
2024-12-11 21:06:41 +01:00
|
|
|
/**
|
|
|
|
|
* Does a bounding box update by iterating over all children.
|
2021-12-05 16:45:41 -05:00
|
|
|
* Not ideal to do this in every draw call, but doing as transform callback doesn't work,
|
2024-12-11 21:06:41 +01:00
|
|
|
* since the frame node automatic size depends on the size of each node which is only calculated
|
|
|
|
|
* while drawing.
|
|
|
|
|
*/
|
|
|
|
|
static rctf calc_node_frame_dimensions(bNode &node)
|
2021-12-05 16:45:41 -05:00
|
|
|
{
|
2024-12-11 21:06:41 +01:00
|
|
|
if (!node.is_frame()) {
|
2024-12-13 16:51:56 +01:00
|
|
|
return node.runtime->draw_bounds;
|
2024-12-11 21:06:41 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-05 16:45:41 -05:00
|
|
|
NodeFrame *data = (NodeFrame *)node.storage;
|
|
|
|
|
|
2023-03-10 18:24:22 +01:00
|
|
|
const float margin = NODE_FRAME_MARGIN;
|
|
|
|
|
const float has_label = node.label[0] != '\0';
|
|
|
|
|
|
|
|
|
|
const float label_height = frame_node_label_height(*data);
|
2023-03-27 12:08:14 +11:00
|
|
|
/* Add an additional 25% to account for the glyphs descender.
|
|
|
|
|
* This works well in most cases. */
|
2023-03-10 18:24:22 +01:00
|
|
|
const float margin_top = 0.5f * margin + (has_label ? 1.25f * label_height : 0.5f * margin);
|
|
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Initialize rect from current frame size. */
|
2021-12-05 16:45:41 -05:00
|
|
|
rctf rect;
|
2021-12-08 09:44:02 -05:00
|
|
|
node_to_updated_rect(node, rect);
|
2021-12-05 16:45:41 -05:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Frame can be resized manually only if shrinking is disabled or no children are attached. */
|
2021-12-05 16:45:41 -05:00
|
|
|
data->flag |= NODE_FRAME_RESIZEABLE;
|
2023-01-03 20:02:01 -05:00
|
|
|
/* For shrinking bounding box, initialize the rect from first child node. */
|
2021-12-05 16:45:41 -05:00
|
|
|
bool bbinit = (data->flag & NODE_FRAME_SHRINK);
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Fit bounding box to all children. */
|
2024-12-11 21:06:41 +01:00
|
|
|
for (bNode *child : node.direct_children_in_frame()) {
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Add margin to node rect. */
|
2024-12-11 21:06:41 +01:00
|
|
|
rctf noderect = calc_node_frame_dimensions(*child);
|
2021-12-05 16:45:41 -05:00
|
|
|
noderect.xmin -= margin;
|
|
|
|
|
noderect.xmax += margin;
|
|
|
|
|
noderect.ymin -= margin;
|
2023-03-10 18:24:22 +01:00
|
|
|
noderect.ymax += margin_top;
|
2021-12-05 16:45:41 -05:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* First child initializes frame. */
|
2021-12-05 16:45:41 -05:00
|
|
|
if (bbinit) {
|
|
|
|
|
bbinit = false;
|
|
|
|
|
rect = noderect;
|
|
|
|
|
data->flag &= ~NODE_FRAME_RESIZEABLE;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_rctf_union(&rect, &noderect);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Now adjust the frame size from view-space bounding box. */
|
2024-12-11 21:06:41 +01:00
|
|
|
const float2 min = node_from_view({rect.xmin, rect.ymin});
|
|
|
|
|
const float2 max = node_from_view({rect.xmax, rect.ymax});
|
|
|
|
|
node.location[0] = min.x;
|
|
|
|
|
node.location[1] = max.y;
|
|
|
|
|
node.width = max.x - min.x;
|
|
|
|
|
node.height = max.y - min.y;
|
2021-12-05 16:45:41 -05:00
|
|
|
|
2024-12-13 16:51:56 +01:00
|
|
|
node.runtime->draw_bounds = rect;
|
2024-12-11 21:06:41 +01:00
|
|
|
return rect;
|
2021-12-05 16:45:41 -05:00
|
|
|
}
|
|
|
|
|
|
2023-03-19 07:03:01 +01:00
|
|
|
static void reroute_node_prepare_for_draw(bNode &node)
|
2021-12-05 16:45:41 -05:00
|
|
|
{
|
2024-12-11 21:06:41 +01:00
|
|
|
const float2 loc = node_to_view(node.location);
|
2021-12-05 16:45:41 -05:00
|
|
|
|
2024-11-23 16:42:38 +01:00
|
|
|
/* When the node is hidden, the input and output socket are both in the same place. */
|
2023-03-19 07:03:01 +01:00
|
|
|
node.input_socket(0).runtime->location = loc;
|
|
|
|
|
node.output_socket(0).runtime->location = loc;
|
2021-12-05 16:45:41 -05:00
|
|
|
|
2024-11-23 16:42:38 +01:00
|
|
|
const float radius = NODE_SOCKSIZE;
|
|
|
|
|
node.width = radius * 2;
|
2024-12-13 16:51:56 +01:00
|
|
|
node.runtime->draw_bounds.xmin = loc.x - radius;
|
|
|
|
|
node.runtime->draw_bounds.xmax = loc.x + radius;
|
|
|
|
|
node.runtime->draw_bounds.ymax = loc.y + radius;
|
|
|
|
|
node.runtime->draw_bounds.ymin = loc.y - radius;
|
2021-12-05 16:45:41 -05:00
|
|
|
}
|
|
|
|
|
|
2021-12-14 11:19:47 -06:00
|
|
|
static void node_update_nodetree(const bContext &C,
|
2022-09-13 08:44:26 +02:00
|
|
|
TreeDrawContext &tree_draw_ctx,
|
2021-12-14 11:19:47 -06:00
|
|
|
bNodeTree &ntree,
|
|
|
|
|
Span<bNode *> nodes,
|
2023-03-19 07:03:01 +01:00
|
|
|
Span<uiBlock *> blocks)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Make sure socket "used" tags are correct, for displaying value buttons. */
|
2021-12-03 16:25:17 -05:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(&C);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
count_multi_input_socket_links(ntree, *snode);
|
2021-02-11 01:16:17 -06:00
|
|
|
|
2021-12-14 11:19:47 -06:00
|
|
|
for (const int i : nodes.index_range()) {
|
|
|
|
|
bNode &node = *nodes[i];
|
2024-06-19 11:20:51 +02:00
|
|
|
uiBlock &block = *blocks[node.index()];
|
2023-01-02 17:55:32 -05:00
|
|
|
if (node.is_frame()) {
|
2024-12-13 16:51:56 +01:00
|
|
|
/* Frame sizes are calculated after all other nodes have calculating their #draw_bounds. */
|
2021-12-18 13:27:05 -06:00
|
|
|
continue;
|
2021-12-05 16:45:41 -05:00
|
|
|
}
|
2021-12-18 13:27:05 -06:00
|
|
|
|
2023-01-02 17:55:32 -05:00
|
|
|
if (node.is_reroute()) {
|
2023-03-19 07:03:01 +01:00
|
|
|
reroute_node_prepare_for_draw(node);
|
2021-12-05 16:45:41 -05:00
|
|
|
}
|
|
|
|
|
else {
|
2021-12-14 11:19:47 -06:00
|
|
|
if (node.flag & NODE_HIDDEN) {
|
2023-03-19 07:03:01 +01:00
|
|
|
node_update_hidden(node, block);
|
2021-12-05 16:45:41 -05:00
|
|
|
}
|
|
|
|
|
else {
|
2023-03-19 07:03:01 +01:00
|
|
|
node_update_basis(C, tree_draw_ctx, ntree, node, block);
|
2021-12-05 16:45:41 -05:00
|
|
|
}
|
|
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2021-12-18 13:27:05 -06:00
|
|
|
|
2024-12-11 21:06:41 +01:00
|
|
|
/* Now calculate the size of frame nodes, which can depend on the size of other nodes. */
|
|
|
|
|
for (bNode *frame : ntree.root_frames()) {
|
|
|
|
|
calc_node_frame_dimensions(*frame);
|
2021-12-18 13:27:05 -06:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
static void frame_node_draw_label(TreeDrawContext &tree_draw_ctx,
|
|
|
|
|
const bNodeTree &ntree,
|
2021-12-11 09:51:53 -06:00
|
|
|
const bNode &node,
|
|
|
|
|
const SpaceNode &snode)
|
2021-12-05 17:12:25 -05:00
|
|
|
{
|
|
|
|
|
const float aspect = snode.runtime->aspect;
|
|
|
|
|
/* XXX font id is crap design */
|
2024-07-19 21:57:49 +02:00
|
|
|
const int fontid = UI_style_get()->widget.uifont_id;
|
2021-12-11 09:51:53 -06:00
|
|
|
const NodeFrame *data = (const NodeFrame *)node.storage;
|
2021-12-05 17:12:25 -05:00
|
|
|
const float font_size = data->label_size / aspect;
|
|
|
|
|
|
2025-03-05 11:17:50 +01:00
|
|
|
const std::string label = bke::node_label(ntree, node);
|
2021-12-05 17:12:25 -05:00
|
|
|
|
|
|
|
|
BLF_enable(fontid, BLF_ASPECT);
|
|
|
|
|
BLF_aspect(fontid, aspect, aspect, 1.0f);
|
2023-03-17 04:19:05 +01:00
|
|
|
BLF_size(fontid, font_size * UI_SCALE_FAC);
|
2021-12-05 17:12:25 -05:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Title color. */
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
int color_id = node_get_colorid(tree_draw_ctx, node);
|
2021-12-05 17:12:25 -05:00
|
|
|
uchar color[3];
|
|
|
|
|
UI_GetThemeColorBlendShade3ubv(TH_TEXT, color_id, 0.4f, 10, color);
|
|
|
|
|
BLF_color3ubv(fontid, color);
|
|
|
|
|
|
2023-03-10 18:24:22 +01:00
|
|
|
const float margin = NODE_FRAME_MARGIN;
|
2025-03-05 11:17:50 +01:00
|
|
|
const float width = BLF_width(fontid, label.c_str(), label.size());
|
2023-03-10 18:24:22 +01:00
|
|
|
const int label_height = frame_node_label_height(*data);
|
2021-12-05 17:12:25 -05:00
|
|
|
|
2024-12-13 16:51:56 +01:00
|
|
|
const rctf &rct = node.runtime->draw_bounds;
|
2023-03-10 18:24:22 +01:00
|
|
|
const float label_x = BLI_rctf_cent_x(&rct) - (0.5f * width);
|
|
|
|
|
const float label_y = rct.ymax - label_height - (0.5f * margin);
|
2021-12-05 17:12:25 -05:00
|
|
|
|
2023-03-10 18:24:22 +01:00
|
|
|
/* Label. */
|
2021-12-05 17:12:25 -05:00
|
|
|
const bool has_label = node.label[0] != '\0';
|
|
|
|
|
if (has_label) {
|
2023-03-10 18:24:22 +01:00
|
|
|
BLF_position(fontid, label_x, label_y, 0);
|
2025-03-05 11:17:50 +01:00
|
|
|
BLF_draw(fontid, label.c_str(), label.size());
|
2021-12-05 17:12:25 -05:00
|
|
|
}
|
|
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Draw text body. */
|
2021-12-05 17:12:25 -05:00
|
|
|
if (node.id) {
|
2021-12-11 09:51:53 -06:00
|
|
|
const Text *text = (const Text *)node.id;
|
2021-12-05 17:12:25 -05:00
|
|
|
const int line_height_max = BLF_height_max(fontid);
|
|
|
|
|
const float line_spacing = (line_height_max * aspect);
|
2023-03-04 07:12:14 +01:00
|
|
|
const float line_width = (BLI_rctf_size_x(&rct) - 2 * margin) / aspect;
|
2021-12-05 17:12:25 -05:00
|
|
|
|
2023-03-10 18:24:22 +01:00
|
|
|
const float x = rct.xmin + margin;
|
|
|
|
|
float y = rct.ymax - label_height - (has_label ? line_spacing + margin : 0);
|
2021-12-05 17:12:25 -05:00
|
|
|
|
2023-03-10 18:24:22 +01:00
|
|
|
const int y_min = rct.ymin + margin;
|
2021-12-05 17:12:25 -05:00
|
|
|
|
|
|
|
|
BLF_enable(fontid, BLF_CLIPPING | BLF_WORD_WRAP);
|
2023-03-04 07:12:14 +01:00
|
|
|
BLF_clipping(fontid, rct.xmin, rct.ymin + margin, rct.xmax, rct.ymax);
|
2021-12-05 17:12:25 -05:00
|
|
|
|
|
|
|
|
BLF_wordwrap(fontid, line_width);
|
|
|
|
|
|
2021-12-11 09:51:53 -06:00
|
|
|
LISTBASE_FOREACH (const TextLine *, line, &text->lines) {
|
2021-12-05 17:12:25 -05:00
|
|
|
if (line->line[0]) {
|
|
|
|
|
BLF_position(fontid, x, y, 0);
|
2022-12-13 16:44:13 -06:00
|
|
|
ResultBLF info;
|
2024-03-28 04:02:13 +01:00
|
|
|
BLF_draw(fontid, line->line, line->len, &info);
|
2021-12-05 17:12:25 -05:00
|
|
|
y -= line_spacing * info.lines;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
y -= line_spacing;
|
|
|
|
|
}
|
|
|
|
|
if (y < y_min) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLF_disable(fontid, BLF_CLIPPING | BLF_WORD_WRAP);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLF_disable(fontid, BLF_ASPECT);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-29 12:13:40 +02:00
|
|
|
static void frame_node_draw_background(const ARegion ®ion,
|
|
|
|
|
const SpaceNode &snode,
|
|
|
|
|
const bNode &node)
|
2021-12-05 17:12:25 -05:00
|
|
|
{
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Skip if out of view. */
|
2024-12-13 16:51:56 +01:00
|
|
|
if (BLI_rctf_isect(&node.runtime->draw_bounds, ®ion.v2d.cur, nullptr) == false) {
|
2021-12-05 17:12:25 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float color[4];
|
|
|
|
|
UI_GetThemeColor4fv(TH_NODE_FRAME, color);
|
|
|
|
|
const float alpha = color[3];
|
|
|
|
|
|
|
|
|
|
node_draw_shadow(snode, node, BASIS_RAD, alpha);
|
|
|
|
|
|
|
|
|
|
if (node.flag & NODE_CUSTOM_COLOR) {
|
|
|
|
|
rgba_float_args_set(color, node.color[0], node.color[1], node.color[2], alpha);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
UI_GetThemeColor4fv(TH_NODE_FRAME, color);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-13 16:51:56 +01:00
|
|
|
const rctf &rct = node.runtime->draw_bounds;
|
2021-12-05 17:12:25 -05:00
|
|
|
UI_draw_roundbox_corner_set(UI_CNR_ALL);
|
|
|
|
|
UI_draw_roundbox_4fv(&rct, true, BASIS_RAD, color);
|
|
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Outline active and selected emphasis. */
|
2021-12-05 17:12:25 -05:00
|
|
|
if (node.flag & SELECT) {
|
|
|
|
|
if (node.flag & NODE_ACTIVE) {
|
|
|
|
|
UI_GetThemeColorShadeAlpha4fv(TH_ACTIVE, 0, -40, color);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
UI_GetThemeColorShadeAlpha4fv(TH_SELECT, 0, -40, color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UI_draw_roundbox_aa(&rct, false, BASIS_RAD, color);
|
|
|
|
|
}
|
2024-08-29 12:13:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void frame_node_draw_overlay(const bContext &C,
|
|
|
|
|
TreeDrawContext &tree_draw_ctx,
|
|
|
|
|
const ARegion ®ion,
|
|
|
|
|
const SpaceNode &snode,
|
|
|
|
|
const bNodeTree &ntree,
|
|
|
|
|
const bNode &node,
|
|
|
|
|
uiBlock &block)
|
|
|
|
|
{
|
|
|
|
|
/* Skip if out of view. */
|
2024-12-13 16:51:56 +01:00
|
|
|
if (BLI_rctf_isect(&node.runtime->draw_bounds, ®ion.v2d.cur, nullptr) == false) {
|
2024-11-14 16:04:33 +01:00
|
|
|
UI_block_end_ex(&C,
|
|
|
|
|
tree_draw_ctx.bmain,
|
|
|
|
|
tree_draw_ctx.window,
|
|
|
|
|
tree_draw_ctx.scene,
|
|
|
|
|
tree_draw_ctx.region,
|
|
|
|
|
tree_draw_ctx.depsgraph,
|
|
|
|
|
&block);
|
2024-08-29 12:13:40 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2021-12-05 17:12:25 -05:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Label and text. */
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
frame_node_draw_label(tree_draw_ctx, ntree, node, snode);
|
2021-12-05 17:12:25 -05:00
|
|
|
|
2023-12-05 15:57:40 +01:00
|
|
|
node_draw_extra_info_panel(C, tree_draw_ctx, snode, node, nullptr, block);
|
2021-12-05 17:12:25 -05:00
|
|
|
|
2024-11-14 16:04:33 +01:00
|
|
|
UI_block_end_ex(&C,
|
|
|
|
|
tree_draw_ctx.bmain,
|
|
|
|
|
tree_draw_ctx.window,
|
|
|
|
|
tree_draw_ctx.scene,
|
|
|
|
|
tree_draw_ctx.region,
|
|
|
|
|
tree_draw_ctx.depsgraph,
|
|
|
|
|
&block);
|
2021-12-14 11:19:47 -06:00
|
|
|
UI_block_draw(&C, &block);
|
2021-12-05 17:12:25 -05:00
|
|
|
}
|
|
|
|
|
|
Geometry Nodes: support attaching gizmos to input values
This adds support for attaching gizmos for input values. The goal is to make it
easier for users to set input values intuitively in the 3D viewport.
We went through multiple different possible designs until we settled on the one
implemented here. We picked it for it's flexibility and ease of use when using
geometry node assets. The core principle in the design is that **gizmos are
attached to existing input values instead of being the input value themselves**.
This actually fits the existing concept of gizmos in Blender well, but may be a
bit unintutitive in a node setup at first. The attachment is done using links in
the node editor.
The most basic usage of the node is to link a Value node to the new Linear Gizmo
node. This attaches the gizmo to the input value and allows you to change it
from the 3D view. The attachment is indicated by the gizmo icon in the sockets
which are controlled by a gizmo as well as the back-link (notice the double
link) when the gizmo is active.
The core principle makes it straight forward to control the same node setup from
the 3D view with gizmos, or by manually changing input values, or by driving the
input values procedurally.
If the input value is controlled indirectly by other inputs, it's often possible
to **automatically propagate** the gizmo to the actual input.
Backpropagation does not work for all nodes, although more nodes can be
supported over time.
This patch adds the first three gizmo nodes which cover common use cases:
* **Linear Gizmo**: Creates a gizmo that controls a float or integer value using
a linear movement of e.g. an arrow in the 3D viewport.
* **Dial Gizmo**: Creates a circular gizmo in the 3D viewport that can be
rotated to change the attached angle input.
* **Transform Gizmo**: Creates a simple gizmo for location, rotation and scale.
In the future, more built-in gizmos and potentially the ability for custom
gizmos could be added.
All gizmo nodes have a **Transform** geometry output. Using it is optional but
it is recommended when the gizmo is used to control inputs that affect a
geometry. When it is used, Blender will automatically transform the gizmos
together with the geometry that they control. To achieve this, the output should
be merged with the generated geometry using the *Join Geometry* node. The data
contained in *Transform* output is not visible geometry, but just internal
information that helps Blender to give a better user experience when using
gizmos.
The gizmo nodes have a multi-input socket. This allows **controlling multiple
values** with the same gizmo.
Only a small set of **gizmo shapes** is supported initially. It might be
extended in the future but one goal is to give the gizmos used by different node
group assets a familiar look and feel. A similar constraint exists for
**colors**. Currently, one can choose from a fixed set of colors which can be
modified in the theme settings.
The set of **visible gizmos** is determined by a multiple factors because it's
not really feasible to show all possible gizmos at all times. To see any of the
geometry nodes gizmos, the "Active Modifier" option has to be enabled in the
"Viewport Gizmos" popover. Then all gizmos are drawn for which at least one of
the following is true:
* The gizmo controls an input of the active modifier of the active object.
* The gizmo controls a value in a selected node in an open node editor.
* The gizmo controls a pinned value in an open node editor. Pinning works by
clicking the gizmo icon next to the value.
Pull Request: https://projects.blender.org/blender/blender/pulls/112677
2024-07-10 16:18:47 +02:00
|
|
|
static Set<const bNodeSocket *> find_sockets_on_active_gizmo_paths(const bContext &C,
|
|
|
|
|
const SpaceNode &snode)
|
|
|
|
|
{
|
|
|
|
|
const std::optional<ed::space_node::ObjectAndModifier> object_and_modifier =
|
|
|
|
|
ed::space_node::get_modifier_for_node_editor(snode);
|
|
|
|
|
if (!object_and_modifier) {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
snode.edittree->ensure_topology_cache();
|
|
|
|
|
|
2025-04-14 17:47:56 +02:00
|
|
|
bke::ComputeContextCache compute_context_cache;
|
2024-07-14 18:55:43 +10:00
|
|
|
/* Compute the compute context hash for the current node tree path. */
|
2025-04-14 17:47:56 +02:00
|
|
|
const ComputeContext &root_compute_context = compute_context_cache.for_modifier(
|
|
|
|
|
nullptr, *object_and_modifier->nmd);
|
|
|
|
|
const std::optional<const ComputeContext *> current_compute_context =
|
|
|
|
|
ed::space_node::compute_context_for_tree_path(
|
|
|
|
|
snode, compute_context_cache, &root_compute_context);
|
|
|
|
|
if (!current_compute_context.has_value()) {
|
Geometry Nodes: support attaching gizmos to input values
This adds support for attaching gizmos for input values. The goal is to make it
easier for users to set input values intuitively in the 3D viewport.
We went through multiple different possible designs until we settled on the one
implemented here. We picked it for it's flexibility and ease of use when using
geometry node assets. The core principle in the design is that **gizmos are
attached to existing input values instead of being the input value themselves**.
This actually fits the existing concept of gizmos in Blender well, but may be a
bit unintutitive in a node setup at first. The attachment is done using links in
the node editor.
The most basic usage of the node is to link a Value node to the new Linear Gizmo
node. This attaches the gizmo to the input value and allows you to change it
from the 3D view. The attachment is indicated by the gizmo icon in the sockets
which are controlled by a gizmo as well as the back-link (notice the double
link) when the gizmo is active.
The core principle makes it straight forward to control the same node setup from
the 3D view with gizmos, or by manually changing input values, or by driving the
input values procedurally.
If the input value is controlled indirectly by other inputs, it's often possible
to **automatically propagate** the gizmo to the actual input.
Backpropagation does not work for all nodes, although more nodes can be
supported over time.
This patch adds the first three gizmo nodes which cover common use cases:
* **Linear Gizmo**: Creates a gizmo that controls a float or integer value using
a linear movement of e.g. an arrow in the 3D viewport.
* **Dial Gizmo**: Creates a circular gizmo in the 3D viewport that can be
rotated to change the attached angle input.
* **Transform Gizmo**: Creates a simple gizmo for location, rotation and scale.
In the future, more built-in gizmos and potentially the ability for custom
gizmos could be added.
All gizmo nodes have a **Transform** geometry output. Using it is optional but
it is recommended when the gizmo is used to control inputs that affect a
geometry. When it is used, Blender will automatically transform the gizmos
together with the geometry that they control. To achieve this, the output should
be merged with the generated geometry using the *Join Geometry* node. The data
contained in *Transform* output is not visible geometry, but just internal
information that helps Blender to give a better user experience when using
gizmos.
The gizmo nodes have a multi-input socket. This allows **controlling multiple
values** with the same gizmo.
Only a small set of **gizmo shapes** is supported initially. It might be
extended in the future but one goal is to give the gizmos used by different node
group assets a familiar look and feel. A similar constraint exists for
**colors**. Currently, one can choose from a fixed set of colors which can be
modified in the theme settings.
The set of **visible gizmos** is determined by a multiple factors because it's
not really feasible to show all possible gizmos at all times. To see any of the
geometry nodes gizmos, the "Active Modifier" option has to be enabled in the
"Viewport Gizmos" popover. Then all gizmos are drawn for which at least one of
the following is true:
* The gizmo controls an input of the active modifier of the active object.
* The gizmo controls a value in a selected node in an open node editor.
* The gizmo controls a pinned value in an open node editor. Pinning works by
clicking the gizmo icon next to the value.
Pull Request: https://projects.blender.org/blender/blender/pulls/112677
2024-07-10 16:18:47 +02:00
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Set<const bNodeSocket *> sockets_on_gizmo_paths;
|
|
|
|
|
|
|
|
|
|
nodes::gizmos::foreach_active_gizmo(
|
|
|
|
|
C,
|
2025-04-14 17:47:56 +02:00
|
|
|
compute_context_cache,
|
Geometry Nodes: support attaching gizmos to input values
This adds support for attaching gizmos for input values. The goal is to make it
easier for users to set input values intuitively in the 3D viewport.
We went through multiple different possible designs until we settled on the one
implemented here. We picked it for it's flexibility and ease of use when using
geometry node assets. The core principle in the design is that **gizmos are
attached to existing input values instead of being the input value themselves**.
This actually fits the existing concept of gizmos in Blender well, but may be a
bit unintutitive in a node setup at first. The attachment is done using links in
the node editor.
The most basic usage of the node is to link a Value node to the new Linear Gizmo
node. This attaches the gizmo to the input value and allows you to change it
from the 3D view. The attachment is indicated by the gizmo icon in the sockets
which are controlled by a gizmo as well as the back-link (notice the double
link) when the gizmo is active.
The core principle makes it straight forward to control the same node setup from
the 3D view with gizmos, or by manually changing input values, or by driving the
input values procedurally.
If the input value is controlled indirectly by other inputs, it's often possible
to **automatically propagate** the gizmo to the actual input.
Backpropagation does not work for all nodes, although more nodes can be
supported over time.
This patch adds the first three gizmo nodes which cover common use cases:
* **Linear Gizmo**: Creates a gizmo that controls a float or integer value using
a linear movement of e.g. an arrow in the 3D viewport.
* **Dial Gizmo**: Creates a circular gizmo in the 3D viewport that can be
rotated to change the attached angle input.
* **Transform Gizmo**: Creates a simple gizmo for location, rotation and scale.
In the future, more built-in gizmos and potentially the ability for custom
gizmos could be added.
All gizmo nodes have a **Transform** geometry output. Using it is optional but
it is recommended when the gizmo is used to control inputs that affect a
geometry. When it is used, Blender will automatically transform the gizmos
together with the geometry that they control. To achieve this, the output should
be merged with the generated geometry using the *Join Geometry* node. The data
contained in *Transform* output is not visible geometry, but just internal
information that helps Blender to give a better user experience when using
gizmos.
The gizmo nodes have a multi-input socket. This allows **controlling multiple
values** with the same gizmo.
Only a small set of **gizmo shapes** is supported initially. It might be
extended in the future but one goal is to give the gizmos used by different node
group assets a familiar look and feel. A similar constraint exists for
**colors**. Currently, one can choose from a fixed set of colors which can be
modified in the theme settings.
The set of **visible gizmos** is determined by a multiple factors because it's
not really feasible to show all possible gizmos at all times. To see any of the
geometry nodes gizmos, the "Active Modifier" option has to be enabled in the
"Viewport Gizmos" popover. Then all gizmos are drawn for which at least one of
the following is true:
* The gizmo controls an input of the active modifier of the active object.
* The gizmo controls a value in a selected node in an open node editor.
* The gizmo controls a pinned value in an open node editor. Pinning works by
clicking the gizmo icon next to the value.
Pull Request: https://projects.blender.org/blender/blender/pulls/112677
2024-07-10 16:18:47 +02:00
|
|
|
[&](const Object &gizmo_object,
|
|
|
|
|
const NodesModifierData &gizmo_nmd,
|
|
|
|
|
const ComputeContext &gizmo_context,
|
|
|
|
|
const bNode &gizmo_node,
|
|
|
|
|
const bNodeSocket &gizmo_socket) {
|
|
|
|
|
if (&gizmo_object != object_and_modifier->object) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (&gizmo_nmd != object_and_modifier->nmd) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
nodes::gizmos::foreach_socket_on_gizmo_path(
|
|
|
|
|
gizmo_context,
|
|
|
|
|
gizmo_node,
|
|
|
|
|
gizmo_socket,
|
|
|
|
|
[&](const ComputeContext &compute_context,
|
|
|
|
|
const bNodeSocket &socket,
|
|
|
|
|
const nodes::inverse_eval::ElemVariant & /*elem*/) {
|
2025-04-14 17:47:56 +02:00
|
|
|
if (compute_context.hash() == (*current_compute_context)->hash()) {
|
Geometry Nodes: support attaching gizmos to input values
This adds support for attaching gizmos for input values. The goal is to make it
easier for users to set input values intuitively in the 3D viewport.
We went through multiple different possible designs until we settled on the one
implemented here. We picked it for it's flexibility and ease of use when using
geometry node assets. The core principle in the design is that **gizmos are
attached to existing input values instead of being the input value themselves**.
This actually fits the existing concept of gizmos in Blender well, but may be a
bit unintutitive in a node setup at first. The attachment is done using links in
the node editor.
The most basic usage of the node is to link a Value node to the new Linear Gizmo
node. This attaches the gizmo to the input value and allows you to change it
from the 3D view. The attachment is indicated by the gizmo icon in the sockets
which are controlled by a gizmo as well as the back-link (notice the double
link) when the gizmo is active.
The core principle makes it straight forward to control the same node setup from
the 3D view with gizmos, or by manually changing input values, or by driving the
input values procedurally.
If the input value is controlled indirectly by other inputs, it's often possible
to **automatically propagate** the gizmo to the actual input.
Backpropagation does not work for all nodes, although more nodes can be
supported over time.
This patch adds the first three gizmo nodes which cover common use cases:
* **Linear Gizmo**: Creates a gizmo that controls a float or integer value using
a linear movement of e.g. an arrow in the 3D viewport.
* **Dial Gizmo**: Creates a circular gizmo in the 3D viewport that can be
rotated to change the attached angle input.
* **Transform Gizmo**: Creates a simple gizmo for location, rotation and scale.
In the future, more built-in gizmos and potentially the ability for custom
gizmos could be added.
All gizmo nodes have a **Transform** geometry output. Using it is optional but
it is recommended when the gizmo is used to control inputs that affect a
geometry. When it is used, Blender will automatically transform the gizmos
together with the geometry that they control. To achieve this, the output should
be merged with the generated geometry using the *Join Geometry* node. The data
contained in *Transform* output is not visible geometry, but just internal
information that helps Blender to give a better user experience when using
gizmos.
The gizmo nodes have a multi-input socket. This allows **controlling multiple
values** with the same gizmo.
Only a small set of **gizmo shapes** is supported initially. It might be
extended in the future but one goal is to give the gizmos used by different node
group assets a familiar look and feel. A similar constraint exists for
**colors**. Currently, one can choose from a fixed set of colors which can be
modified in the theme settings.
The set of **visible gizmos** is determined by a multiple factors because it's
not really feasible to show all possible gizmos at all times. To see any of the
geometry nodes gizmos, the "Active Modifier" option has to be enabled in the
"Viewport Gizmos" popover. Then all gizmos are drawn for which at least one of
the following is true:
* The gizmo controls an input of the active modifier of the active object.
* The gizmo controls a value in a selected node in an open node editor.
* The gizmo controls a pinned value in an open node editor. Pinning works by
clicking the gizmo icon next to the value.
Pull Request: https://projects.blender.org/blender/blender/pulls/112677
2024-07-10 16:18:47 +02:00
|
|
|
sockets_on_gizmo_paths.add(&socket);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return sockets_on_gizmo_paths;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-05 10:02:37 +02:00
|
|
|
/**
|
|
|
|
|
* Returns the reroute node linked to the input of the given reroute, if there is one.
|
|
|
|
|
*/
|
|
|
|
|
static const bNode *reroute_node_get_linked_reroute(const bNode &reroute)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(reroute.is_reroute());
|
|
|
|
|
|
|
|
|
|
const bNodeSocket *input_socket = reroute.input_sockets().first();
|
|
|
|
|
if (input_socket->directly_linked_links().is_empty()) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
const bNodeLink *input_link = input_socket->directly_linked_links().first();
|
|
|
|
|
const bNode *from_node = input_link->fromnode;
|
|
|
|
|
return from_node->is_reroute() ? from_node : nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The auto label overlay displays a label on reroute nodes based on the user-defined label of a
|
|
|
|
|
* linked reroute upstream.
|
|
|
|
|
*/
|
2025-01-09 12:07:53 -05:00
|
|
|
static StringRef reroute_node_get_auto_label(TreeDrawContext &tree_draw_ctx,
|
|
|
|
|
const bNode &src_reroute)
|
2024-06-05 10:02:37 +02:00
|
|
|
{
|
|
|
|
|
BLI_assert(src_reroute.is_reroute());
|
|
|
|
|
|
|
|
|
|
if (src_reroute.label[0] != '\0') {
|
2025-01-09 12:07:53 -05:00
|
|
|
return src_reroute.label;
|
2024-06-05 10:02:37 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-09 12:07:53 -05:00
|
|
|
Map<const bNode *, StringRef> &reroute_auto_labels = tree_draw_ctx.reroute_auto_labels;
|
2024-06-05 10:02:37 +02:00
|
|
|
|
2025-01-09 12:07:53 -05:00
|
|
|
StringRef label;
|
2024-06-05 10:02:37 +02:00
|
|
|
Vector<const bNode *> reroute_path;
|
|
|
|
|
|
|
|
|
|
/* Traverse reroute path backwards until label, non-reroute node or link-cycle is found. */
|
|
|
|
|
for (const bNode *reroute = &src_reroute; reroute;
|
|
|
|
|
reroute = reroute_node_get_linked_reroute(*reroute))
|
|
|
|
|
{
|
|
|
|
|
reroute_path.append(reroute);
|
2025-01-09 12:07:53 -05:00
|
|
|
if (const StringRef *label_ptr = reroute_auto_labels.lookup_ptr(reroute)) {
|
2024-06-05 10:02:37 +02:00
|
|
|
label = *label_ptr;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (reroute->label[0] != '\0') {
|
|
|
|
|
label = reroute->label;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
/* This makes sure that the loop eventually ends even if there are link-cycles. */
|
|
|
|
|
reroute_auto_labels.add(reroute, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Remember the label for each node on the path to avoid recomputing it. */
|
|
|
|
|
for (const bNode *reroute : reroute_path) {
|
|
|
|
|
reroute_auto_labels.add_overwrite(reroute, label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return label;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-23 16:42:38 +01:00
|
|
|
static void reroute_node_draw_body(const bContext &C,
|
|
|
|
|
const SpaceNode &snode,
|
|
|
|
|
const bNodeTree &ntree,
|
|
|
|
|
const bNode &node,
|
|
|
|
|
uiBlock &block,
|
|
|
|
|
const bool selected)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(node.is_reroute());
|
|
|
|
|
|
|
|
|
|
bNodeSocket &sock = *static_cast<bNodeSocket *>(node.inputs.first);
|
|
|
|
|
|
2025-01-24 16:45:32 +01:00
|
|
|
PointerRNA nodeptr = RNA_pointer_create_discrete(
|
2024-11-23 16:42:38 +01:00
|
|
|
const_cast<ID *>(&ntree.id), &RNA_Node, const_cast<bNode *>(&node));
|
|
|
|
|
|
|
|
|
|
ColorTheme4f socket_color;
|
|
|
|
|
ColorTheme4f outline_color;
|
|
|
|
|
|
|
|
|
|
node_socket_color_get(C, ntree, nodeptr, sock, socket_color);
|
|
|
|
|
node_socket_outline_color_get(selected, sock.type, outline_color);
|
|
|
|
|
|
2024-12-13 16:51:56 +01:00
|
|
|
node_draw_nodesocket(&node.runtime->draw_bounds,
|
2024-11-23 16:42:38 +01:00
|
|
|
socket_color,
|
|
|
|
|
outline_color,
|
|
|
|
|
NODE_SOCKET_OUTLINE,
|
|
|
|
|
sock.display_shape,
|
|
|
|
|
snode.runtime->aspect);
|
|
|
|
|
|
2024-12-13 16:51:56 +01:00
|
|
|
const float2 location = float2(BLI_rctf_cent_x(&node.runtime->draw_bounds),
|
|
|
|
|
BLI_rctf_cent_y(&node.runtime->draw_bounds));
|
|
|
|
|
const float2 size = float2(BLI_rctf_size_x(&node.runtime->draw_bounds),
|
|
|
|
|
BLI_rctf_size_y(&node.runtime->draw_bounds));
|
2024-11-23 16:42:38 +01:00
|
|
|
node_socket_tooltip_set(block, sock.index_in_tree(), location, size);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-05 10:02:37 +02:00
|
|
|
static void reroute_node_draw_label(TreeDrawContext &tree_draw_ctx,
|
|
|
|
|
const SpaceNode &snode,
|
|
|
|
|
const bNode &node,
|
|
|
|
|
uiBlock &block)
|
|
|
|
|
{
|
|
|
|
|
const bool has_label = node.label[0] != '\0';
|
|
|
|
|
const bool use_auto_label = !has_label && (snode.overlay.flag & SN_OVERLAY_SHOW_OVERLAYS) &&
|
|
|
|
|
(snode.overlay.flag & SN_OVERLAY_SHOW_REROUTE_AUTO_LABELS);
|
|
|
|
|
|
|
|
|
|
if (!has_label && !use_auto_label) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Don't show the automatic label, when being zoomed out. */
|
2024-11-23 16:42:38 +01:00
|
|
|
if (!has_label && !draw_node_details(snode)) {
|
2024-06-05 10:02:37 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-09 12:07:53 -05:00
|
|
|
const StringRef text = has_label ? node.label : reroute_node_get_auto_label(tree_draw_ctx, node);
|
|
|
|
|
if (text.is_empty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-06-05 10:02:37 +02:00
|
|
|
|
|
|
|
|
const short width = 512;
|
2024-12-13 16:51:56 +01:00
|
|
|
const int x = BLI_rctf_cent_x(&node.runtime->draw_bounds) - (width / 2);
|
|
|
|
|
const int y = node.runtime->draw_bounds.ymax;
|
2024-06-05 10:02:37 +02:00
|
|
|
|
|
|
|
|
uiBut *label_but = uiDefBut(
|
2025-02-14 15:12:48 -05:00
|
|
|
&block, UI_BTYPE_LABEL, 0, text, x, y, width, NODE_DY, nullptr, 0, 0, std::nullopt);
|
2024-06-05 10:02:37 +02:00
|
|
|
|
|
|
|
|
UI_but_drawflag_disable(label_but, UI_BUT_TEXT_LEFT);
|
|
|
|
|
|
|
|
|
|
if (use_auto_label && !(node.flag & NODE_SELECT)) {
|
|
|
|
|
UI_but_flag_enable(label_but, UI_BUT_INACTIVE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void reroute_node_draw(const bContext &C,
|
|
|
|
|
TreeDrawContext &tree_draw_ctx,
|
|
|
|
|
ARegion ®ion,
|
|
|
|
|
const SpaceNode &snode,
|
|
|
|
|
bNodeTree &ntree,
|
|
|
|
|
const bNode &node,
|
|
|
|
|
uiBlock &block)
|
2021-12-05 17:12:25 -05:00
|
|
|
{
|
2024-12-13 16:51:56 +01:00
|
|
|
const rctf &rct = node.runtime->draw_bounds;
|
2024-11-23 16:42:38 +01:00
|
|
|
const View2D &v2d = region.v2d;
|
|
|
|
|
|
|
|
|
|
/* Skip if out of view. */
|
|
|
|
|
if (rct.xmax < v2d.cur.xmin || rct.xmin > v2d.cur.xmax || rct.ymax < v2d.cur.ymin ||
|
2024-12-13 16:51:56 +01:00
|
|
|
node.runtime->draw_bounds.ymin > v2d.cur.ymax)
|
2022-11-18 12:46:20 +01:00
|
|
|
{
|
2024-11-14 16:04:33 +01:00
|
|
|
UI_block_end_ex(&C,
|
|
|
|
|
tree_draw_ctx.bmain,
|
|
|
|
|
tree_draw_ctx.window,
|
|
|
|
|
tree_draw_ctx.scene,
|
|
|
|
|
tree_draw_ctx.region,
|
|
|
|
|
tree_draw_ctx.depsgraph,
|
|
|
|
|
&block);
|
2021-12-05 17:12:25 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-23 16:42:38 +01:00
|
|
|
if (draw_node_details(snode)) {
|
|
|
|
|
reroute_node_draw_label(tree_draw_ctx, snode, node, block);
|
|
|
|
|
}
|
2021-12-05 17:12:25 -05:00
|
|
|
|
2024-11-23 16:42:38 +01:00
|
|
|
/* Only draw the input socket, since all sockets are at the same location. */
|
|
|
|
|
const bool selected = node.flag & NODE_SELECT;
|
|
|
|
|
reroute_node_draw_body(C, snode, ntree, node, block, selected);
|
2021-12-05 17:12:25 -05:00
|
|
|
|
2024-11-14 16:04:33 +01:00
|
|
|
UI_block_end_ex(&C,
|
|
|
|
|
tree_draw_ctx.bmain,
|
|
|
|
|
tree_draw_ctx.window,
|
|
|
|
|
tree_draw_ctx.scene,
|
|
|
|
|
tree_draw_ctx.region,
|
|
|
|
|
tree_draw_ctx.depsgraph,
|
|
|
|
|
&block);
|
2021-12-14 11:19:47 -06:00
|
|
|
UI_block_draw(&C, &block);
|
2021-12-05 17:12:25 -05:00
|
|
|
}
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
static void node_draw(const bContext &C,
|
2022-09-13 08:44:26 +02:00
|
|
|
TreeDrawContext &tree_draw_ctx,
|
2021-12-03 16:25:17 -05:00
|
|
|
ARegion ®ion,
|
2021-12-05 17:12:25 -05:00
|
|
|
const SpaceNode &snode,
|
2021-12-03 16:25:17 -05:00
|
|
|
bNodeTree &ntree,
|
|
|
|
|
bNode &node,
|
2021-12-14 11:19:47 -06:00
|
|
|
uiBlock &block,
|
2013-03-18 16:34:57 +00:00
|
|
|
bNodeInstanceKey key)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2023-01-02 17:55:32 -05:00
|
|
|
if (node.is_frame()) {
|
2024-06-15 19:51:15 +02:00
|
|
|
/* Should have been drawn before already. */
|
|
|
|
|
BLI_assert_unreachable();
|
2021-12-05 17:12:25 -05:00
|
|
|
}
|
2023-01-02 17:55:32 -05:00
|
|
|
else if (node.is_reroute()) {
|
2024-06-05 10:02:37 +02:00
|
|
|
reroute_node_draw(C, tree_draw_ctx, region, snode, ntree, node, block);
|
2021-12-05 17:12:25 -05:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
const View2D &v2d = region.v2d;
|
|
|
|
|
if (node.flag & NODE_HIDDEN) {
|
2023-03-19 07:03:01 +01:00
|
|
|
node_draw_hidden(C, tree_draw_ctx, v2d, snode, ntree, node, block);
|
2021-12-05 17:12:25 -05:00
|
|
|
}
|
|
|
|
|
else {
|
2023-03-19 07:03:01 +01:00
|
|
|
node_draw_basis(C, tree_draw_ctx, v2d, snode, ntree, node, block, key);
|
2021-12-05 17:12:25 -05:00
|
|
|
}
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
static void add_rect_corner_positions(Vector<float2> &positions, const rctf &rect)
|
|
|
|
|
{
|
|
|
|
|
positions.append({rect.xmin, rect.ymin});
|
|
|
|
|
positions.append({rect.xmin, rect.ymax});
|
|
|
|
|
positions.append({rect.xmax, rect.ymin});
|
|
|
|
|
positions.append({rect.xmax, rect.ymax});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void find_bounds_by_zone_recursive(const SpaceNode &snode,
|
2023-06-20 10:25:41 +02:00
|
|
|
const bNodeTreeZone &zone,
|
2024-10-05 12:03:55 +02:00
|
|
|
const Span<const bNodeTreeZone *> all_zones,
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
MutableSpan<Vector<float2>> r_bounds_by_zone)
|
|
|
|
|
{
|
|
|
|
|
const float node_padding = UI_UNIT_X;
|
|
|
|
|
const float zone_padding = 0.3f * UI_UNIT_X;
|
|
|
|
|
|
|
|
|
|
Vector<float2> &bounds = r_bounds_by_zone[zone.index];
|
|
|
|
|
if (!bounds.is_empty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector<float2> possible_bounds;
|
2023-06-20 10:25:41 +02:00
|
|
|
for (const bNodeTreeZone *child_zone : zone.child_zones) {
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
find_bounds_by_zone_recursive(snode, *child_zone, all_zones, r_bounds_by_zone);
|
|
|
|
|
const Span<float2> child_bounds = r_bounds_by_zone[child_zone->index];
|
|
|
|
|
for (const float2 &pos : child_bounds) {
|
|
|
|
|
rctf rect;
|
|
|
|
|
BLI_rctf_init_pt_radius(&rect, pos, zone_padding);
|
|
|
|
|
add_rect_corner_positions(possible_bounds, rect);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (const bNode *child_node : zone.child_nodes) {
|
2024-12-13 16:51:56 +01:00
|
|
|
rctf rect = child_node->runtime->draw_bounds;
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
BLI_rctf_pad(&rect, node_padding, node_padding);
|
|
|
|
|
add_rect_corner_positions(possible_bounds, rect);
|
|
|
|
|
}
|
|
|
|
|
if (zone.input_node) {
|
2024-12-13 16:51:56 +01:00
|
|
|
const rctf &draw_bounds = zone.input_node->runtime->draw_bounds;
|
|
|
|
|
rctf rect = draw_bounds;
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
BLI_rctf_pad(&rect, node_padding, node_padding);
|
2024-12-13 16:51:56 +01:00
|
|
|
rect.xmin = math::interpolate(draw_bounds.xmin, draw_bounds.xmax, 0.25f);
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
add_rect_corner_positions(possible_bounds, rect);
|
|
|
|
|
}
|
|
|
|
|
if (zone.output_node) {
|
2024-12-13 16:51:56 +01:00
|
|
|
const rctf &draw_bounds = zone.output_node->runtime->draw_bounds;
|
|
|
|
|
rctf rect = draw_bounds;
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
BLI_rctf_pad(&rect, node_padding, node_padding);
|
2024-12-13 16:51:56 +01:00
|
|
|
rect.xmax = math::interpolate(draw_bounds.xmin, draw_bounds.xmax, 0.75f);
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
add_rect_corner_positions(possible_bounds, rect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (snode.runtime->linkdrag) {
|
|
|
|
|
for (const bNodeLink &link : snode.runtime->linkdrag->links) {
|
|
|
|
|
if (link.fromnode == nullptr) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2023-06-16 10:44:47 +02:00
|
|
|
if (zone.contains_node_recursively(*link.fromnode) && zone.output_node != link.fromnode) {
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
const float2 pos = node_link_bezier_points_dragged(snode, link)[3];
|
|
|
|
|
rctf rect;
|
|
|
|
|
BLI_rctf_init_pt_radius(&rect, pos, node_padding);
|
|
|
|
|
add_rect_corner_positions(possible_bounds, rect);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector<int> convex_indices(possible_bounds.size());
|
|
|
|
|
const int convex_positions_num = BLI_convexhull_2d(
|
|
|
|
|
reinterpret_cast<float(*)[2]>(possible_bounds.data()),
|
|
|
|
|
possible_bounds.size(),
|
|
|
|
|
convex_indices.data());
|
|
|
|
|
convex_indices.resize(convex_positions_num);
|
|
|
|
|
|
|
|
|
|
for (const int i : convex_indices) {
|
|
|
|
|
bounds.append(possible_bounds[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-15 19:51:15 +02:00
|
|
|
static void node_draw_zones_and_frames(const bContext &C,
|
|
|
|
|
TreeDrawContext &tree_draw_ctx,
|
|
|
|
|
const ARegion ®ion,
|
|
|
|
|
const SpaceNode &snode,
|
|
|
|
|
const bNodeTree &ntree,
|
|
|
|
|
Span<uiBlock *> blocks)
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
{
|
2023-06-20 10:25:41 +02:00
|
|
|
const bNodeTreeZones *zones = ntree.zones();
|
2024-07-07 11:16:50 +02:00
|
|
|
const int zones_num = zones ? zones->zones.size() : 0;
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
|
2024-07-07 11:16:50 +02:00
|
|
|
Array<Vector<float2>> bounds_by_zone(zones_num);
|
|
|
|
|
Array<bke::CurvesGeometry> fillet_curve_by_zone(zones_num);
|
2023-07-11 22:36:10 +02:00
|
|
|
/* Bounding box area of zones is used to determine draw order. */
|
2024-07-07 11:16:50 +02:00
|
|
|
Array<float> bounding_box_width_by_zone(zones_num);
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
|
2024-07-07 11:16:50 +02:00
|
|
|
for (const int zone_i : IndexRange(zones_num)) {
|
2023-06-20 10:25:41 +02:00
|
|
|
const bNodeTreeZone &zone = *zones->zones[zone_i];
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
|
|
|
|
|
find_bounds_by_zone_recursive(snode, zone, zones->zones, bounds_by_zone);
|
|
|
|
|
const Span<float2> boundary_positions = bounds_by_zone[zone_i];
|
|
|
|
|
const int boundary_positions_num = boundary_positions.size();
|
|
|
|
|
|
2023-07-11 22:36:10 +02:00
|
|
|
const Bounds<float2> bounding_box = *bounds::min_max(boundary_positions);
|
2024-06-15 19:51:15 +02:00
|
|
|
const float bounding_box_width = bounding_box.max.x - bounding_box.min.x;
|
|
|
|
|
bounding_box_width_by_zone[zone_i] = bounding_box_width;
|
2023-07-11 22:36:10 +02:00
|
|
|
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
bke::CurvesGeometry boundary_curve(boundary_positions_num, 1);
|
|
|
|
|
boundary_curve.cyclic_for_write().first() = true;
|
|
|
|
|
boundary_curve.fill_curve_types(CURVE_TYPE_POLY);
|
|
|
|
|
MutableSpan<float3> boundary_curve_positions = boundary_curve.positions_for_write();
|
|
|
|
|
boundary_curve.offsets_for_write().copy_from({0, boundary_positions_num});
|
|
|
|
|
for (const int i : boundary_positions.index_range()) {
|
|
|
|
|
boundary_curve_positions[i] = float3(boundary_positions[i], 0.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fillet_curve_by_zone[zone_i] = geometry::fillet_curves_poly(
|
|
|
|
|
boundary_curve,
|
|
|
|
|
IndexRange(1),
|
|
|
|
|
VArray<float>::ForSingle(BASIS_RAD, boundary_positions_num),
|
|
|
|
|
VArray<int>::ForSingle(5, boundary_positions_num),
|
|
|
|
|
true,
|
|
|
|
|
{});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const View2D &v2d = region.v2d;
|
|
|
|
|
float scale;
|
|
|
|
|
UI_view2d_scale_get(&v2d, &scale, nullptr);
|
|
|
|
|
float line_width = 1.0f * scale;
|
|
|
|
|
float viewport[4] = {};
|
|
|
|
|
GPU_viewport_size_get_f(viewport);
|
2023-07-11 22:36:10 +02:00
|
|
|
|
|
|
|
|
const auto get_theme_id = [&](const int zone_i) {
|
|
|
|
|
const bNode *node = zones->zones[zone_i]->output_node;
|
2025-01-09 15:28:57 +01:00
|
|
|
return bke::zone_type_by_node_type(node->type_legacy)->theme_id;
|
2023-07-11 22:36:10 +02:00
|
|
|
};
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
|
|
|
|
|
const uint pos = GPU_vertformat_attr_add(
|
|
|
|
|
immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
|
|
|
|
|
|
2024-06-15 19:51:15 +02:00
|
|
|
using ZoneOrNode = std::variant<const bNodeTreeZone *, const bNode *>;
|
|
|
|
|
Vector<ZoneOrNode> draw_order;
|
2024-07-07 11:16:50 +02:00
|
|
|
for (const int zone_i : IndexRange(zones_num)) {
|
2024-10-05 12:03:55 +02:00
|
|
|
draw_order.append(zones->zones[zone_i]);
|
2024-06-15 19:51:15 +02:00
|
|
|
}
|
|
|
|
|
for (const bNode *node : ntree.all_nodes()) {
|
|
|
|
|
if (node->flag & NODE_BACKGROUND) {
|
|
|
|
|
draw_order.append(node);
|
|
|
|
|
}
|
2023-07-11 22:36:10 +02:00
|
|
|
}
|
2024-06-15 19:51:15 +02:00
|
|
|
auto get_zone_or_node_width = [&](const ZoneOrNode &zone_or_node) {
|
|
|
|
|
if (const bNodeTreeZone *const *zone_p = std::get_if<const bNodeTreeZone *>(&zone_or_node)) {
|
|
|
|
|
const bNodeTreeZone &zone = **zone_p;
|
|
|
|
|
return bounding_box_width_by_zone[zone.index];
|
|
|
|
|
}
|
|
|
|
|
if (const bNode *const *node_p = std::get_if<const bNode *>(&zone_or_node)) {
|
|
|
|
|
const bNode &node = **node_p;
|
2024-12-13 16:51:56 +01:00
|
|
|
return BLI_rctf_size_x(&node.runtime->draw_bounds);
|
2024-06-15 19:51:15 +02:00
|
|
|
}
|
|
|
|
|
BLI_assert_unreachable();
|
|
|
|
|
return 0.0f;
|
|
|
|
|
};
|
|
|
|
|
std::sort(draw_order.begin(), draw_order.end(), [&](const ZoneOrNode &a, const ZoneOrNode &b) {
|
2023-07-11 22:36:10 +02:00
|
|
|
/* Draw zones with smaller bounding box on top to make them visible. */
|
2024-06-15 19:51:15 +02:00
|
|
|
return get_zone_or_node_width(a) > get_zone_or_node_width(b);
|
2023-07-11 22:36:10 +02:00
|
|
|
});
|
|
|
|
|
|
2024-06-15 19:51:15 +02:00
|
|
|
for (const ZoneOrNode &zone_or_node : draw_order) {
|
|
|
|
|
if (const bNodeTreeZone *const *zone_p = std::get_if<const bNodeTreeZone *>(&zone_or_node)) {
|
|
|
|
|
const bNodeTreeZone &zone = **zone_p;
|
|
|
|
|
const int zone_i = zone.index;
|
|
|
|
|
float zone_color[4];
|
|
|
|
|
UI_GetThemeColor4fv(get_theme_id(zone_i), zone_color);
|
|
|
|
|
if (zone_color[3] == 0.0f) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
const Span<float3> fillet_boundary_positions = fillet_curve_by_zone[zone_i].positions();
|
|
|
|
|
/* Draw the background. */
|
|
|
|
|
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
|
|
|
|
|
immUniformThemeColorBlend(TH_BACK, get_theme_id(zone_i), zone_color[3]);
|
|
|
|
|
|
|
|
|
|
immBegin(GPU_PRIM_TRI_FAN, fillet_boundary_positions.size() + 1);
|
|
|
|
|
for (const float3 &p : fillet_boundary_positions) {
|
|
|
|
|
immVertex3fv(pos, p);
|
|
|
|
|
}
|
|
|
|
|
immVertex3fv(pos, fillet_boundary_positions[0]);
|
|
|
|
|
immEnd();
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
|
2024-06-15 19:51:15 +02:00
|
|
|
immUnbindProgram();
|
|
|
|
|
}
|
|
|
|
|
if (const bNode *const *node_p = std::get_if<const bNode *>(&zone_or_node)) {
|
|
|
|
|
const bNode &node = **node_p;
|
2024-08-29 12:13:40 +02:00
|
|
|
frame_node_draw_background(region, snode, node);
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-14 20:39:00 +02:00
|
|
|
GPU_blend(GPU_BLEND_ALPHA);
|
|
|
|
|
|
2024-06-15 19:51:15 +02:00
|
|
|
/* Draw all the contour lines after to prevent them from getting hidden by overlapping zones. */
|
|
|
|
|
for (const ZoneOrNode &zone_or_node : draw_order) {
|
|
|
|
|
const bNodeTreeZone *const *zone_p = std::get_if<const bNodeTreeZone *>(&zone_or_node);
|
|
|
|
|
if (!zone_p) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
const bNodeTreeZone &zone = **zone_p;
|
|
|
|
|
const int zone_i = zone.index;
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
const Span<float3> fillet_boundary_positions = fillet_curve_by_zone[zone_i].positions();
|
|
|
|
|
/* Draw the contour lines. */
|
|
|
|
|
immBindBuiltinProgram(GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR);
|
|
|
|
|
|
|
|
|
|
immUniform2fv("viewportSize", &viewport[2]);
|
|
|
|
|
immUniform1f("lineWidth", line_width * U.pixelsize);
|
|
|
|
|
|
2023-07-11 22:36:10 +02:00
|
|
|
immUniformThemeColorAlpha(get_theme_id(zone_i), 1.0f);
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
immBegin(GPU_PRIM_LINE_STRIP, fillet_boundary_positions.size() + 1);
|
|
|
|
|
for (const float3 &p : fillet_boundary_positions) {
|
|
|
|
|
immVertex3fv(pos, p);
|
|
|
|
|
}
|
|
|
|
|
immVertex3fv(pos, fillet_boundary_positions[0]);
|
|
|
|
|
immEnd();
|
|
|
|
|
|
|
|
|
|
immUnbindProgram();
|
|
|
|
|
}
|
2024-06-14 20:39:00 +02:00
|
|
|
|
|
|
|
|
GPU_blend(GPU_BLEND_NONE);
|
2024-08-29 12:13:40 +02:00
|
|
|
|
|
|
|
|
/* Draw text on frame nodes. */
|
|
|
|
|
for (const ZoneOrNode &zone_or_node : draw_order) {
|
|
|
|
|
if (const bNode *const *node_p = std::get_if<const bNode *>(&zone_or_node)) {
|
|
|
|
|
const bNode &node = **node_p;
|
|
|
|
|
frame_node_draw_overlay(C, tree_draw_ctx, region, snode, ntree, node, *blocks[node.index()]);
|
|
|
|
|
}
|
|
|
|
|
}
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
}
|
|
|
|
|
|
2012-08-12 19:35:47 +00:00
|
|
|
#define USE_DRAW_TOT_UPDATE
|
|
|
|
|
|
2021-12-05 17:12:25 -05:00
|
|
|
static void node_draw_nodetree(const bContext &C,
|
2022-09-13 08:44:26 +02:00
|
|
|
TreeDrawContext &tree_draw_ctx,
|
2021-12-05 17:12:25 -05:00
|
|
|
ARegion ®ion,
|
|
|
|
|
SpaceNode &snode,
|
|
|
|
|
bNodeTree &ntree,
|
2021-12-14 11:19:47 -06:00
|
|
|
Span<bNode *> nodes,
|
|
|
|
|
Span<uiBlock *> blocks,
|
2021-12-05 17:12:25 -05:00
|
|
|
bNodeInstanceKey parent_key)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2012-08-12 19:35:47 +00:00
|
|
|
#ifdef USE_DRAW_TOT_UPDATE
|
2021-12-14 11:19:47 -06:00
|
|
|
BLI_rctf_init_minmax(®ion.v2d.tot);
|
2012-08-12 19:35:47 +00:00
|
|
|
#endif
|
|
|
|
|
|
2021-12-14 11:19:47 -06:00
|
|
|
for (const int i : nodes.index_range()) {
|
2012-08-12 19:35:47 +00:00
|
|
|
#ifdef USE_DRAW_TOT_UPDATE
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Unrelated to background nodes, update the v2d->tot,
|
|
|
|
|
* can be anywhere before we draw the scroll bars. */
|
2024-12-13 16:51:56 +01:00
|
|
|
BLI_rctf_union(®ion.v2d.tot, &nodes[i]->runtime->draw_bounds);
|
2012-08-12 19:35:47 +00:00
|
|
|
#endif
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Node lines. */
|
2020-08-16 15:38:34 +02:00
|
|
|
GPU_blend(GPU_BLEND_ALPHA);
|
2018-04-05 15:43:07 +02:00
|
|
|
nodelink_batch_start(snode);
|
2021-02-11 01:16:17 -06:00
|
|
|
|
2023-06-16 10:37:18 +02:00
|
|
|
for (const bNodeLink *link : ntree.all_links()) {
|
2025-02-19 13:44:11 +01:00
|
|
|
if (!bke::node_link_is_hidden(*link) && !bke::node_link_is_selected(*link)) {
|
2023-11-01 09:29:56 +01:00
|
|
|
node_draw_link(C, region.v2d, snode, *link, false);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2022-02-28 15:52:00 -05:00
|
|
|
|
|
|
|
|
/* Draw selected node links after the unselected ones, so they are shown on top. */
|
2023-06-16 10:37:18 +02:00
|
|
|
for (const bNodeLink *link : ntree.all_links()) {
|
2025-02-19 13:44:11 +01:00
|
|
|
if (!bke::node_link_is_hidden(*link) && bke::node_link_is_selected(*link)) {
|
2023-11-01 09:29:56 +01:00
|
|
|
node_draw_link(C, region.v2d, snode, *link, true);
|
2022-02-28 15:52:00 -05:00
|
|
|
}
|
|
|
|
|
}
|
2022-02-28 18:05:12 -05:00
|
|
|
|
2018-04-05 15:43:07 +02:00
|
|
|
nodelink_batch_end(snode);
|
2020-08-16 15:38:34 +02:00
|
|
|
GPU_blend(GPU_BLEND_NONE);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Draw foreground nodes, last nodes in front. */
|
2021-12-14 11:19:47 -06:00
|
|
|
for (const int i : nodes.index_range()) {
|
2024-06-19 11:20:51 +02:00
|
|
|
bNode &node = *nodes[i];
|
|
|
|
|
if (node.flag & NODE_BACKGROUND) {
|
2024-06-15 19:51:15 +02:00
|
|
|
/* Background nodes are drawn before mixed with zones already. */
|
2012-05-22 14:13:33 +00:00
|
|
|
continue;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-08-19 20:27:37 +02:00
|
|
|
const bNodeInstanceKey key = bke::node_instance_key(parent_key, &ntree, &node);
|
2024-06-19 11:20:51 +02:00
|
|
|
node_draw(C, tree_draw_ctx, region, snode, ntree, node, *blocks[node.index()], key);
|
2011-02-21 13:47:49 +00:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-14 19:19:47 +05:30
|
|
|
/* Draw the breadcrumb on the top of the editor. */
|
2021-10-26 11:05:01 -05:00
|
|
|
static void draw_tree_path(const bContext &C, ARegion ®ion)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2021-10-26 11:05:01 -05:00
|
|
|
GPU_matrix_push_projection();
|
|
|
|
|
wmOrtho2_region_pixelspace(®ion);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2021-10-26 11:05:01 -05:00
|
|
|
const rcti *rect = ED_region_visible_rect(®ion);
|
|
|
|
|
|
|
|
|
|
const uiStyle *style = UI_style_get_dpi();
|
2023-03-17 04:19:05 +01:00
|
|
|
const float padding_x = 16 * UI_SCALE_FAC;
|
2021-10-26 11:05:01 -05:00
|
|
|
const int x = rect->xmin + padding_x;
|
|
|
|
|
const int y = region.winy - UI_UNIT_Y * 0.6f;
|
|
|
|
|
const int width = BLI_rcti_size_x(rect) - 2 * padding_x;
|
|
|
|
|
|
2025-03-31 00:36:46 +02:00
|
|
|
uiBlock *block = UI_block_begin(&C, ®ion, __func__, blender::ui::EmbossType::None);
|
2021-10-26 11:05:01 -05:00
|
|
|
uiLayout *layout = UI_block_layout(
|
|
|
|
|
block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, x, y, width, 1, 0, style);
|
|
|
|
|
|
2022-12-13 16:44:13 -06:00
|
|
|
const Vector<ui::ContextPathItem> context_path = ed::space_node::context_path_for_space_node(C);
|
2021-10-26 11:05:01 -05:00
|
|
|
ui::template_breadcrumbs(*layout, context_path);
|
|
|
|
|
|
|
|
|
|
UI_block_layout_resolve(block, nullptr, nullptr);
|
|
|
|
|
UI_block_end(&C, block);
|
|
|
|
|
UI_block_draw(&C, block);
|
|
|
|
|
|
|
|
|
|
GPU_matrix_pop_projection();
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
static void snode_setup_v2d(SpaceNode &snode, ARegion ®ion, const float2 ¢er)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2021-12-03 16:25:17 -05:00
|
|
|
View2D &v2d = region.v2d;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Shift view to node tree center. */
|
2021-12-03 16:25:17 -05:00
|
|
|
UI_view2d_center_set(&v2d, center[0], center[1]);
|
|
|
|
|
UI_view2d_view_ortho(&v2d);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2022-09-25 18:33:28 +10:00
|
|
|
snode.runtime->aspect = BLI_rctf_size_x(&v2d.cur) / float(region.winx);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-23 10:15:13 +02:00
|
|
|
/* Similar to DRW_is_viewport_compositor_enabled() in `draw_manager.cc` but checks all 3D views. */
|
2024-12-17 13:00:50 +01:00
|
|
|
static bool compositor_is_in_use(const bContext &context)
|
2022-11-23 14:34:31 +02:00
|
|
|
{
|
|
|
|
|
const Scene *scene = CTX_data_scene(&context);
|
|
|
|
|
if (!scene->use_nodes) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!scene->nodetree) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-09 17:47:06 +02:00
|
|
|
wmWindowManager *wm = CTX_wm_manager(&context);
|
|
|
|
|
LISTBASE_FOREACH (const wmWindow *, win, &wm->windows) {
|
|
|
|
|
const bScreen *screen = WM_window_get_active_screen(win);
|
2023-01-02 17:37:26 -05:00
|
|
|
LISTBASE_FOREACH (const ScrArea *, area, &screen->areabase) {
|
2023-06-09 17:47:06 +02:00
|
|
|
const SpaceLink &space = *static_cast<const SpaceLink *>(area->spacedata.first);
|
|
|
|
|
if (space.spacetype == SPACE_VIEW3D) {
|
|
|
|
|
const View3D &view_3d = reinterpret_cast<const View3D &>(space);
|
2022-11-23 14:34:31 +02:00
|
|
|
|
|
|
|
|
if (view_3d.shading.use_compositor == V3D_SHADING_USE_COMPOSITOR_DISABLED) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(view_3d.shading.type >= OB_MATERIAL)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
static void draw_nodetree(const bContext &C,
|
|
|
|
|
ARegion ®ion,
|
|
|
|
|
bNodeTree &ntree,
|
2013-03-18 16:34:57 +00:00
|
|
|
bNodeInstanceKey parent_key)
|
|
|
|
|
{
|
2021-12-03 16:25:17 -05:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(&C);
|
2022-09-02 15:22:48 -05:00
|
|
|
ntree.ensure_topology_cache();
|
2017-05-15 13:47:48 +02:00
|
|
|
|
2023-10-10 10:57:51 +02:00
|
|
|
Array<bNode *> nodes = tree_draw_order_calc_nodes(ntree);
|
2021-12-14 11:19:47 -06:00
|
|
|
|
|
|
|
|
Array<uiBlock *> blocks = node_uiblocks_init(C, nodes);
|
2017-05-15 13:47:48 +02:00
|
|
|
|
2022-09-13 08:44:26 +02:00
|
|
|
TreeDrawContext tree_draw_ctx;
|
2024-11-14 16:04:33 +01:00
|
|
|
tree_draw_ctx.bmain = CTX_data_main(&C);
|
|
|
|
|
tree_draw_ctx.window = CTX_wm_window(&C);
|
|
|
|
|
tree_draw_ctx.scene = CTX_data_scene(&C);
|
|
|
|
|
tree_draw_ctx.region = CTX_wm_region(&C);
|
|
|
|
|
tree_draw_ctx.depsgraph = CTX_data_depsgraph_pointer(&C);
|
Geometry Nodes: support attaching gizmos to input values
This adds support for attaching gizmos for input values. The goal is to make it
easier for users to set input values intuitively in the 3D viewport.
We went through multiple different possible designs until we settled on the one
implemented here. We picked it for it's flexibility and ease of use when using
geometry node assets. The core principle in the design is that **gizmos are
attached to existing input values instead of being the input value themselves**.
This actually fits the existing concept of gizmos in Blender well, but may be a
bit unintutitive in a node setup at first. The attachment is done using links in
the node editor.
The most basic usage of the node is to link a Value node to the new Linear Gizmo
node. This attaches the gizmo to the input value and allows you to change it
from the 3D view. The attachment is indicated by the gizmo icon in the sockets
which are controlled by a gizmo as well as the back-link (notice the double
link) when the gizmo is active.
The core principle makes it straight forward to control the same node setup from
the 3D view with gizmos, or by manually changing input values, or by driving the
input values procedurally.
If the input value is controlled indirectly by other inputs, it's often possible
to **automatically propagate** the gizmo to the actual input.
Backpropagation does not work for all nodes, although more nodes can be
supported over time.
This patch adds the first three gizmo nodes which cover common use cases:
* **Linear Gizmo**: Creates a gizmo that controls a float or integer value using
a linear movement of e.g. an arrow in the 3D viewport.
* **Dial Gizmo**: Creates a circular gizmo in the 3D viewport that can be
rotated to change the attached angle input.
* **Transform Gizmo**: Creates a simple gizmo for location, rotation and scale.
In the future, more built-in gizmos and potentially the ability for custom
gizmos could be added.
All gizmo nodes have a **Transform** geometry output. Using it is optional but
it is recommended when the gizmo is used to control inputs that affect a
geometry. When it is used, Blender will automatically transform the gizmos
together with the geometry that they control. To achieve this, the output should
be merged with the generated geometry using the *Join Geometry* node. The data
contained in *Transform* output is not visible geometry, but just internal
information that helps Blender to give a better user experience when using
gizmos.
The gizmo nodes have a multi-input socket. This allows **controlling multiple
values** with the same gizmo.
Only a small set of **gizmo shapes** is supported initially. It might be
extended in the future but one goal is to give the gizmos used by different node
group assets a familiar look and feel. A similar constraint exists for
**colors**. Currently, one can choose from a fixed set of colors which can be
modified in the theme settings.
The set of **visible gizmos** is determined by a multiple factors because it's
not really feasible to show all possible gizmos at all times. To see any of the
geometry nodes gizmos, the "Active Modifier" option has to be enabled in the
"Viewport Gizmos" popover. Then all gizmos are drawn for which at least one of
the following is true:
* The gizmo controls an input of the active modifier of the active object.
* The gizmo controls a value in a selected node in an open node editor.
* The gizmo controls a pinned value in an open node editor. Pinning works by
clicking the gizmo icon next to the value.
Pull Request: https://projects.blender.org/blender/blender/pulls/112677
2024-07-10 16:18:47 +02:00
|
|
|
|
|
|
|
|
BLI_SCOPED_DEFER([&]() { ntree.runtime->sockets_on_active_gizmo_paths.clear(); });
|
2022-09-13 08:44:26 +02:00
|
|
|
if (ntree.type == NTREE_GEOMETRY) {
|
2025-04-09 09:53:48 +02:00
|
|
|
tree_draw_ctx.tree_logs = geo_log::GeoModifierLog::get_contextual_tree_logs(*snode);
|
|
|
|
|
tree_draw_ctx.tree_logs.foreach_tree_log([&](geo_log::GeoTreeLog &log) {
|
2025-04-10 08:56:02 +02:00
|
|
|
log.ensure_node_warnings(*tree_draw_ctx.bmain);
|
2025-04-09 09:53:48 +02:00
|
|
|
log.ensure_execution_times();
|
|
|
|
|
});
|
2022-12-13 16:44:13 -06:00
|
|
|
const WorkSpace *workspace = CTX_wm_workspace(&C);
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
tree_draw_ctx.active_geometry_nodes_viewer = viewer_path::find_geometry_nodes_viewer(
|
|
|
|
|
workspace->viewer_path, *snode);
|
Geometry Nodes: support attaching gizmos to input values
This adds support for attaching gizmos for input values. The goal is to make it
easier for users to set input values intuitively in the 3D viewport.
We went through multiple different possible designs until we settled on the one
implemented here. We picked it for it's flexibility and ease of use when using
geometry node assets. The core principle in the design is that **gizmos are
attached to existing input values instead of being the input value themselves**.
This actually fits the existing concept of gizmos in Blender well, but may be a
bit unintutitive in a node setup at first. The attachment is done using links in
the node editor.
The most basic usage of the node is to link a Value node to the new Linear Gizmo
node. This attaches the gizmo to the input value and allows you to change it
from the 3D view. The attachment is indicated by the gizmo icon in the sockets
which are controlled by a gizmo as well as the back-link (notice the double
link) when the gizmo is active.
The core principle makes it straight forward to control the same node setup from
the 3D view with gizmos, or by manually changing input values, or by driving the
input values procedurally.
If the input value is controlled indirectly by other inputs, it's often possible
to **automatically propagate** the gizmo to the actual input.
Backpropagation does not work for all nodes, although more nodes can be
supported over time.
This patch adds the first three gizmo nodes which cover common use cases:
* **Linear Gizmo**: Creates a gizmo that controls a float or integer value using
a linear movement of e.g. an arrow in the 3D viewport.
* **Dial Gizmo**: Creates a circular gizmo in the 3D viewport that can be
rotated to change the attached angle input.
* **Transform Gizmo**: Creates a simple gizmo for location, rotation and scale.
In the future, more built-in gizmos and potentially the ability for custom
gizmos could be added.
All gizmo nodes have a **Transform** geometry output. Using it is optional but
it is recommended when the gizmo is used to control inputs that affect a
geometry. When it is used, Blender will automatically transform the gizmos
together with the geometry that they control. To achieve this, the output should
be merged with the generated geometry using the *Join Geometry* node. The data
contained in *Transform* output is not visible geometry, but just internal
information that helps Blender to give a better user experience when using
gizmos.
The gizmo nodes have a multi-input socket. This allows **controlling multiple
values** with the same gizmo.
Only a small set of **gizmo shapes** is supported initially. It might be
extended in the future but one goal is to give the gizmos used by different node
group assets a familiar look and feel. A similar constraint exists for
**colors**. Currently, one can choose from a fixed set of colors which can be
modified in the theme settings.
The set of **visible gizmos** is determined by a multiple factors because it's
not really feasible to show all possible gizmos at all times. To see any of the
geometry nodes gizmos, the "Active Modifier" option has to be enabled in the
"Viewport Gizmos" popover. Then all gizmos are drawn for which at least one of
the following is true:
* The gizmo controls an input of the active modifier of the active object.
* The gizmo controls a value in a selected node in an open node editor.
* The gizmo controls a pinned value in an open node editor. Pinning works by
clicking the gizmo icon next to the value.
Pull Request: https://projects.blender.org/blender/blender/pulls/112677
2024-07-10 16:18:47 +02:00
|
|
|
|
|
|
|
|
/* This set of socket is used when drawing links to determine which links should use the
|
|
|
|
|
* special gizmo drawing. */
|
|
|
|
|
ntree.runtime->sockets_on_active_gizmo_paths = find_sockets_on_active_gizmo_paths(C, *snode);
|
2022-09-13 08:44:26 +02:00
|
|
|
}
|
2022-11-23 14:34:31 +02:00
|
|
|
else if (ntree.type == NTREE_COMPOSIT) {
|
2024-02-09 10:19:24 +01:00
|
|
|
const Scene *scene = CTX_data_scene(&C);
|
2024-12-17 13:00:50 +01:00
|
|
|
tree_draw_ctx.used_by_compositor = compositor_is_in_use(C);
|
2024-02-09 10:19:24 +01:00
|
|
|
tree_draw_ctx.compositor_per_node_execution_time =
|
|
|
|
|
&scene->runtime->compositor.per_node_execution_time;
|
2022-11-23 14:34:31 +02:00
|
|
|
}
|
2024-12-13 11:21:39 +11:00
|
|
|
else if (ntree.type == NTREE_SHADER && USER_EXPERIMENTAL_TEST(&U, use_shader_node_previews) &&
|
2023-08-08 17:36:06 +02:00
|
|
|
BKE_scene_uses_shader_previews(CTX_data_scene(&C)) &&
|
2023-08-09 14:04:11 +02:00
|
|
|
snode->overlay.flag & SN_OVERLAY_SHOW_OVERLAYS &&
|
|
|
|
|
snode->overlay.flag & SN_OVERLAY_SHOW_PREVIEWS)
|
2023-08-08 17:36:06 +02:00
|
|
|
{
|
|
|
|
|
tree_draw_ctx.nested_group_infos = get_nested_previews(C, *snode);
|
|
|
|
|
}
|
2023-03-19 07:03:01 +01:00
|
|
|
|
|
|
|
|
node_update_nodetree(C, tree_draw_ctx, ntree, nodes, blocks);
|
2024-06-15 19:51:15 +02:00
|
|
|
node_draw_zones_and_frames(C, tree_draw_ctx, region, *snode, ntree, blocks);
|
2023-03-19 07:03:01 +01:00
|
|
|
node_draw_nodetree(C, tree_draw_ctx, region, *snode, ntree, nodes, blocks, parent_key);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-08 11:43:52 +02:00
|
|
|
/**
|
2021-10-12 17:52:35 +11:00
|
|
|
* Make the background slightly brighter to indicate that users are inside a node-group.
|
2021-10-08 16:01:49 +02:00
|
|
|
*/
|
2021-12-03 16:25:17 -05:00
|
|
|
static void draw_background_color(const SpaceNode &snode)
|
2021-10-08 11:43:52 +02:00
|
|
|
{
|
2021-10-11 09:32:29 +02:00
|
|
|
const int max_tree_length = 3;
|
2021-10-08 11:43:52 +02:00
|
|
|
const float bright_factor = 0.25f;
|
|
|
|
|
|
2021-10-11 09:32:29 +02:00
|
|
|
/* We ignore the first element of the path since it is the top-most tree and it doesn't need to
|
|
|
|
|
* be brighter. We also set a cap to how many levels we want to set apart, to avoid the
|
|
|
|
|
* background from getting too bright. */
|
2021-12-03 16:25:17 -05:00
|
|
|
const int clamped_tree_path_length = BLI_listbase_count_at_most(&snode.treepath,
|
2021-10-11 09:32:29 +02:00
|
|
|
max_tree_length);
|
|
|
|
|
const int depth = max_ii(0, clamped_tree_path_length - 1);
|
2021-10-08 16:01:49 +02:00
|
|
|
|
2021-10-08 11:43:52 +02:00
|
|
|
float color[3];
|
|
|
|
|
UI_GetThemeColor3fv(TH_BACK, color);
|
|
|
|
|
mul_v3_fl(color, 1.0f + bright_factor * depth);
|
|
|
|
|
GPU_clear_color(color[0], color[1], color[2], 1.0);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
void node_draw_space(const bContext &C, ARegion ®ion)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2021-12-03 16:25:17 -05:00
|
|
|
wmWindow *win = CTX_wm_window(&C);
|
|
|
|
|
SpaceNode &snode = *CTX_wm_space_node(&C);
|
|
|
|
|
View2D &v2d = region.v2d;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2021-07-26 12:32:42 +10:00
|
|
|
/* Setup off-screen buffers. */
|
2021-12-03 16:25:17 -05:00
|
|
|
GPUViewport *viewport = WM_draw_region_get_viewport(®ion);
|
2020-08-18 14:43:18 +02:00
|
|
|
|
|
|
|
|
GPUFrameBuffer *framebuffer_overlay = GPU_viewport_framebuffer_overlay_get(viewport);
|
|
|
|
|
GPU_framebuffer_bind_no_srgb(framebuffer_overlay);
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
UI_view2d_view_ortho(&v2d);
|
2021-10-08 11:43:52 +02:00
|
|
|
draw_background_color(snode);
|
2020-08-20 16:38:34 +02:00
|
|
|
GPU_depth_test(GPU_DEPTH_NONE);
|
2020-08-23 11:11:27 +02:00
|
|
|
GPU_scissor_test(true);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 15:04:29 +11:00
|
|
|
/* XXX `snode->runtime->cursor` set in coordinate-space for placing new nodes,
|
|
|
|
|
* used for drawing noodles too. */
|
2021-12-03 16:25:17 -05:00
|
|
|
UI_view2d_region_to_view(®ion.v2d,
|
|
|
|
|
win->eventstate->xy[0] - region.winrct.xmin,
|
|
|
|
|
win->eventstate->xy[1] - region.winrct.ymin,
|
|
|
|
|
&snode.runtime->cursor[0],
|
|
|
|
|
&snode.runtime->cursor[1]);
|
2023-03-17 04:19:05 +01:00
|
|
|
snode.runtime->cursor[0] /= UI_SCALE_FAC;
|
|
|
|
|
snode.runtime->cursor[1] /= UI_SCALE_FAC;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
ED_region_draw_cb_draw(&C, ®ion, REGION_DRAW_PRE_VIEW);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Only set once. */
|
2020-08-16 15:38:34 +02:00
|
|
|
GPU_blend(GPU_BLEND_ALPHA);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Nodes. */
|
2013-03-18 16:34:57 +00:00
|
|
|
snode_set_context(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-26 13:03:09 -05:00
|
|
|
const int grid_levels = UI_GetThemeValueType(TH_NODE_GRID_LEVELS, SPACE_NODE);
|
2021-12-03 16:25:17 -05:00
|
|
|
UI_view2d_dot_grid_draw(&v2d, TH_GRID, NODE_GRID_STEP_SIZE, grid_levels);
|
2021-10-26 13:03:09 -05:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Draw parent node trees. */
|
2021-12-03 16:25:17 -05:00
|
|
|
if (snode.treepath.last) {
|
|
|
|
|
bNodeTreePath *path = (bNodeTreePath *)snode.treepath.last;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Update tree path name (drawn in the bottom left). */
|
2021-12-03 16:25:17 -05:00
|
|
|
ID *name_id = (path->nodetree && path->nodetree != snode.nodetree) ? &path->nodetree->id :
|
|
|
|
|
snode.id;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-04-01 14:36:44 +02:00
|
|
|
if (name_id && UNLIKELY(!STREQ(path->display_name, name_id->name + 2))) {
|
2023-05-09 12:50:37 +10:00
|
|
|
STRNCPY(path->display_name, name_id->name + 2);
|
2015-01-25 01:59:49 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Current View2D center, will be set temporarily for parent node trees. */
|
2022-09-02 14:09:32 -05:00
|
|
|
float2 center;
|
|
|
|
|
UI_view2d_center_get(&v2d, ¢er.x, ¢er.y);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Store new view center in path and current edit tree. */
|
2013-04-17 17:12:12 +00:00
|
|
|
copy_v2_v2(path->view_center, center);
|
2021-12-03 16:25:17 -05:00
|
|
|
if (snode.edittree) {
|
|
|
|
|
copy_v2_v2(snode.edittree->view_center, center);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Top-level edit tree. */
|
2020-11-30 13:56:46 -05:00
|
|
|
bNodeTree *ntree = path->nodetree;
|
2013-04-17 17:12:12 +00:00
|
|
|
if (ntree) {
|
2020-03-06 16:56:42 +01:00
|
|
|
snode_setup_v2d(snode, region, center);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Backdrop. */
|
2020-03-06 16:56:42 +01:00
|
|
|
draw_nodespace_back_pix(C, region, snode, path->parent_key);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-05-29 22:06:59 +10:00
|
|
|
{
|
|
|
|
|
float original_proj[4][4];
|
2018-07-15 15:27:15 +02:00
|
|
|
GPU_matrix_projection_get(original_proj);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-15 15:27:15 +02:00
|
|
|
GPU_matrix_push();
|
|
|
|
|
GPU_matrix_identity_set();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
wmOrtho2_pixelspace(region.winx, region.winy);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-11-21 19:34:53 +01:00
|
|
|
WM_gizmomap_draw(region.runtime->gizmo_map, &C, WM_GIZMOMAP_DRAWSTEP_2D);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-15 15:27:15 +02:00
|
|
|
GPU_matrix_pop();
|
|
|
|
|
GPU_matrix_projection_set(original_proj);
|
2017-05-29 22:06:59 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
draw_nodetree(C, region, *ntree, path->parent_key);
|
2013-04-17 17:12:12 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Temporary links. */
|
2020-08-16 15:38:34 +02:00
|
|
|
GPU_blend(GPU_BLEND_ALPHA);
|
2018-06-27 19:07:23 -06:00
|
|
|
GPU_line_smooth(true);
|
2021-12-03 16:25:17 -05:00
|
|
|
if (snode.runtime->linkdrag) {
|
2022-12-29 14:09:58 -05:00
|
|
|
for (const bNodeLink &link : snode.runtime->linkdrag->links) {
|
2023-11-01 09:29:56 +01:00
|
|
|
node_draw_link_dragged(C, v2d, snode, link);
|
2012-10-21 05:46:41 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-06-27 19:07:23 -06:00
|
|
|
GPU_line_smooth(false);
|
2020-08-16 15:38:34 +02:00
|
|
|
GPU_blend(GPU_BLEND_NONE);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
if (snode.overlay.flag & SN_OVERLAY_SHOW_OVERLAYS && snode.flag & SNODE_SHOW_GPENCIL) {
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Draw grease-pencil annotations. */
|
2021-12-03 16:25:17 -05:00
|
|
|
ED_annotation_draw_view2d(&C, true);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Backdrop. */
|
2024-05-13 16:07:12 +02:00
|
|
|
draw_nodespace_back_pix(C, region, snode, bke::NODE_INSTANCE_KEY_NONE);
|
2012-05-15 12:40:43 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
ED_region_draw_cb_draw(&C, ®ion, REGION_DRAW_POST_VIEW);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Reset view matrix. */
|
2021-12-03 16:25:17 -05:00
|
|
|
UI_view2d_view_restore(&C);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
if (snode.overlay.flag & SN_OVERLAY_SHOW_OVERLAYS) {
|
|
|
|
|
if (snode.flag & SNODE_SHOW_GPENCIL && snode.treepath.last) {
|
2021-02-05 16:23:34 +11:00
|
|
|
/* Draw grease-pencil (screen strokes, and also paint-buffer). */
|
2021-12-03 16:25:17 -05:00
|
|
|
ED_annotation_draw_view2d(&C, false);
|
2012-12-17 02:34:53 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-01 21:45:41 -05:00
|
|
|
/* Draw context path. */
|
2021-12-03 16:25:17 -05:00
|
|
|
if (snode.overlay.flag & SN_OVERLAY_SHOW_PATH && snode.edittree) {
|
|
|
|
|
draw_tree_path(C, region);
|
2021-12-01 21:45:41 -05:00
|
|
|
}
|
2021-10-26 11:05:01 -05:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-17 13:34:49 -06:00
|
|
|
/* Scrollers. */
|
2021-12-03 16:25:17 -05:00
|
|
|
UI_view2d_scrollers_draw(&v2d, nullptr);
|
2008-12-26 13:11:04 +00:00
|
|
|
}
|
2022-01-20 10:36:56 -06:00
|
|
|
|
|
|
|
|
} // namespace blender::ed::space_node
|