118 Commits

Author SHA1 Message Date
Jacques Lucke
894d9883b1 Cleanup: Geometry Nodes: use cache mutex for lazy function graph generation
This is a more standard way to handle caches and avoids the need for
a custom double checked lock.

Pull Request: https://projects.blender.org/blender/blender/pulls/147345
2025-10-07 10:46:59 +02:00
Iliya Katushenock
2d6a4da01a Cleanup: Improve description of asserton related to topology cache
Pull Request: https://projects.blender.org/blender/blender/pulls/145248
2025-09-29 16:55:28 +02:00
Jacques Lucke
60a416bea4 Geometry Nodes: improve socket shapes for bundle and closure nodes
Previously, the closure and bundle nodes were a bit restrictive when it comes to
socket shapes. Especially the bundle nodes did not support customizing the
socket shape at all, so they always worked with dynamic values. This was
problematic, because it meant that e.g. the outputs of the Separate Bundle node
looked like they couldn't be used as single values, and other similar issues.

With this patch, the following is supported (a few aspects were supported before
but now it all fits better together): * Support manually selecting socket shapes
in Combine Bundle, Separate Bundle, Closure Input, Closure Output and Evaluate
Closure nodes. * Automatic inferencing of shapes in all these nodes, as long as
the socket shape is set to "auto". * A new "Define Signature" option can be
enabled in the nodes. If enabled, linked nodes will also sync the socket shapes
from that node. In the future, we also want to add support for naming the
signature.

Pull Request: https://projects.blender.org/blender/blender/pulls/145550
2025-09-27 14:58:43 +02:00
Jacques Lucke
b186e60759 Nodes: support node output visibility inferencing
Currently, only the visibility of input sockets can be changed dynamically based
on other menu inputs. However, under some circumstances, it can also be useful
to hide certain outputs. For example, the built-in Curve Arc primitive node does
that.

This patch adds support for automatic detection of unused outputs. How to detect
unused outputs is less straight forward compared to inputs. This patch uses the
rule that an output is unused if it always outputs a "fallback value" (typically
0) irrespective of the currently used inputs. If the output is independent of
all inputs, it stays visible though.

There is a new small utility node called "Enable Output". It replaces a value
with it's fallback value unless it is disabled. This simplifies setting up
unused outputs. In theory, a normal switch node can also be used, but that is
less usable and the user will have to hardcode the fallback value for each type
which is not something that is explicitly exposed yet.

Supporting dynamic output visibility is also a prerequisite for exposing some
menu node options as sockets (e.g. in the Arc node).

Pull Request: https://projects.blender.org/blender/blender/pulls/140856
2025-09-27 10:09:48 +02:00
Jacques Lucke
32c301e3cf Shader Nodes: support repeat zones, closures and bundles
This adds a function that can turn an existing `bNodeTree` into an inlined one.
The new node tree has all node groups, repeat zones, closures and bundles
inlined. So it's just a flat tree that ideally can be consumed easily by render
engines. As part of the process, it also does constant folding.

The goal is to support more advanced features from geometry nodes (repeat zones,
etc.) in shader nodes which the evaluator is more limited because it has to be
able to run on the GPU. Creating an inlined `bNodeTree` is likely the most
direct way to get but may also be limiting in the future. Since this is a fairly
local change, it's likely still worth it to support these features in all render
engines without having to make their evaluators significantly more complex.

Some limitations apply here that do not apply in Geometry Nodes. For example,
the iterations count in a repeat zone has to be a constant after constant
folding.

There is also a `Test Inlining Shader Nodes` operator that creates the inlined
tree and creates a group node for it. This is just for testing purposes.

#145811 will make this functionality available to the Python API as well so that
external renderers can use it too.
2025-09-09 16:15:43 +02:00
Jacques Lucke
890ab23e0d Refactor: Nodes: return pointer instead of reference from in/output_by_identifier
This makes it possible to use these methods in cases where it's not guaranteed
that the identifier exists on a node.
2025-07-31 21:58:58 +02:00
Campbell Barton
996210999b Cleanup: use C style comments for descriptive text, doxygen doc-strings
Also replace add-hoc groups in BKE_collision.h with doxy groups.
2025-07-22 11:59:43 +10:00
Habib Gahbiche
7f668be362 Nodes: rename "Hide" to "Collapse"
Design task: https://projects.blender.org/blender/blender/issues/139158

Renaming includes:
- UI description
- Python operator description
- Code (Enums, function names and variables)

Unchanged:
- Python API
  - `bpy.ops.node.hide_toggle()`
  - `node.hide`
- Python operators / scripts

The reasoning is that improved naming is not enough reason to break
backward compatibility for Python API.

Pull Request: https://projects.blender.org/blender/blender/pulls/141038
2025-06-30 15:28:19 +02:00
Jacques Lucke
7b7c630018 Refactor: Nodes: use structure type inferencing for field links
The goal here is to reduce our reliance on the existing field inferencing code
and use the new and more general structure inferencing code instead.

This patch changes patch refactors link drawing so that whether links are drawn
dashed does not depend on field inferencing anymore. Same for the invalid field
links.

I don't expect that this changes the drawing of any existing links. It just
makes it easier to fully remove the old field inferencing in the future.

Pull Request: https://projects.blender.org/blender/blender/pulls/140869
2025-06-24 07:25:15 +02:00
Habib Gahbiche
bd61e69be5 Compositor: make compositor node trees reusable
This is part of the short term roadmap goal of simplifying the
compositor workflow
(see https://projects.blender.org/blender/blender/issues/134214).
The problem is that many users don't know how to get started with
compositing in Blender, even when they have used Blender for other
areas, e.g. modeling.

Note: although the solution makes compositor node trees reusable
accross blend files, this is a nice side effect and not the main goal
of the PR.

This PR implements a "New" button that creates a new compositing node
tree, and manages trees as IDs. This has following advantages:
- Consistent with other node editors and other parts of Blender,
therefore making it easier to getting started with compositing if users
are familiar with shading or geometry nodes
- Give users the ability to reuse the compositing node tree by linking
or appending it.

Note: The parameter "Use Nodes" is still present in this PR, but will
be removed (in a backward compatible way) in a follow up PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/135223
2025-06-10 17:46:55 +02:00
Jacques Lucke
152471ffdb Geometry Nodes: support structure types in closures
This adds support for specifying structure types on closures. The main immediate
benefit is that this makes it possible to use fields with closures (without
having incorrect warnings in the UI).

A closure zone behaves very similar to a node group with respect to structure
type inferencing. The structure types can be inferenced fully automatically, or
the user can specify them manually on the closure inputs. On the evaluate
closure zone, the user has to specify the structure types of the inputs and
outputs explicitly (or leave them as dynamic).

Working on this, I was a bit surprised that `get_output_socket_shape` depended
on the field state. Is that a left-over? It feels like it shouldn't be necessary
since the socket shape shouldn't depend on field inferencing anymore. I removed
that now and couldn't see a difference yet.

The operator that creates a closure zone from an evaluate closure node copies
the input structure types already. Beyond that, there is no automatic syncing of
the structure types yet. The structure types only affect the UI and not what's
actually done during evaluation.

Pull Request: https://projects.blender.org/blender/blender/pulls/139713
2025-06-10 12:25:51 +02:00
Hans Goudey
b80f1f5322 Geometry Nodes: Socket structure type and display changes
Implementation of #127106.
This is just a visual representation of the field/single/grid
status of sockets to make the workflow more intuitive. With
a visual representation for volume grid sockets, volume features
should be unblocked for further development. The structure type
will also be used to distinguish list sockets in the interface.

Group input nodes now have a "Structure Type" option instead of
the existing "Single Value Only". Usually the auto option should be
enough, but in some cases where the inferencing cannot (yet) make
a clear determination, it can be helpful to choose a specific type.

The new visualization and the group input structure type option
are hidden behind a new experimental option for now.

Pull Request: https://projects.blender.org/blender/blender/pulls/134811
2025-05-28 02:33:47 +02:00
Jacques Lucke
1307137f27 Nodes: clarify socket visibility methods
Node sockets have many different aspects that affect their visibility and
whether they are grayed out. This patch cleans up the methods used to check if
sockets are visible and adds descriptions that should make it more obvious which
ones should be used.

This also fixes a few places where the wrong method was used which is more
obvious now.

Pull Request: https://projects.blender.org/blender/blender/pulls/139251
2025-05-23 06:10:03 +02:00
Jacques Lucke
47e84f1486 Cleanup: Nodes: remove unused method 2025-05-22 06:06:54 +02:00
Jacques Lucke
5457cca3de Nodes: auto-hide unused inputs if usage depends on menu
Previously, when a socket was detected to be unused, it was just grayed out.
This patch adds support for automatically hiding unused sockets based on this
convention: Menu inputs control visibility while other inputs only control
whether something is grayed out.

More specifically, an input is visible if any of these conditions is met:
* It affects the output currently.
* It never affects the output. In this case its usage does not depend on any
  menu input.
* It is used if all non-menu inputs are considered to be unknown.

In the future, we could support customizing which inputs are allowed to control
visibility. For now it's good to use the convention that Blender generally
follows itself.

As before, panels are grayed out if they only contain grayed out sockets and
panels are hidden when they don't contain any visible sockets.

Hiding inputs works in group nodes, the Geometry Nodes modifier and node
operators. In theory it will work for all node tree types, but since only
Geometry Nodes supports the Menu Switch node currently, this patch currently
only makes a difference there.

The implementation reuses the existing `SocketUsageInferencer` with a different
sets of inputs. So no new core-inferencing logic was needed.

Design task: #132706.

Pull Request: https://projects.blender.org/blender/blender/pulls/138186
2025-05-22 04:48:43 +02:00
Jacques Lucke
f3294bbd06 Nodes: improve drawing with invalid zone links
Previously, whenever the zone detection algorithm could not find a result, zones
were just not drawn at all. This can be very confusing because it's not
necessarily obvious that something is wrong in this case.

Now, invalid zones and links that made them invalid have an error.

Note, we can't generally detect the "valid part" of zones when there are invalid
links, because it's ambiguous which links are valid. However, the solution here
is to remember the last valid zones, and to look at which links would invalidate
those. Since the zone-detection results in runtime-only data currently, the
error won't show when reopening the file for now.

Implementation wise, this works by keeping a potentially outdated version of the
last valid zones around, even when the zone detection failed. For that to work,
I had to change some node pointers to node identifiers in the zone structs, so
that it is safe to access them even if the nodes have been removed.

Pull Request: https://projects.blender.org/blender/blender/pulls/139044
2025-05-19 17:25:36 +02:00
Jacques Lucke
4a760c1a70 Nodes: show link errors directly on link
Previously, we had shown link errors on the target node as part of the node
warning system. While better than not showing any information about invalid
links (as was the state before that), it's still not ideal because it's easy to
miss when just looking at the link.

This patch adds an error icon in the middle of the invalid link. When hovering
over it, it shows the error text. When the middle of the link is not in view but
part of the link is, then the error icon will also stay visible.

Pull Request: https://projects.blender.org/blender/blender/pulls/138529
2025-05-09 04:06:00 +02:00
Jacques Lucke
b7a1325c3c BLI: use blender::Mutex by default which wraps tbb::mutex
This patch adds a new `BLI_mutex.hh` header which adds `blender::Mutex` as alias
for either `tbb::mutex` or `std::mutex` depending on whether TBB is enabled.

Description copied from the patch:
```
/**
 * blender::Mutex should be used as the default mutex in Blender. It implements a subset of the API
 * of std::mutex but has overall better guaranteed properties. It can be used with RAII helpers
 * like std::lock_guard. However, it is not compatible with e.g. std::condition_variable. So one
 * still has to use std::mutex for that case.
 *
 * The mutex provided by TBB has these properties:
 * - It's as fast as a spin-lock in the non-contended case, i.e. when no other thread is trying to
 *   lock the mutex at the same time.
 * - In the contended case, it spins a couple of times but then blocks to avoid draining system
 *   resources by spinning for a long time.
 * - It's only 1 byte large, compared to e.g. 40 bytes when using the std::mutex of GCC. This makes
 *   it more feasible to have many smaller mutexes which can improve scalability of algorithms
 *   compared to using fewer larger mutexes. Also it just reduces "memory slop" across Blender.
 * - It is *not* a fair mutex, i.e. it's not guaranteed that a thread will ever be able to lock the
 *   mutex when there are always more than one threads that try to lock it. In the majority of
 *   cases, using a fair mutex just causes extra overhead without any benefit. std::mutex is not
 *   guaranteed to be fair either.
 */
 ```

The performance benchmark suggests that the impact is negilible in almost
all cases. The only benchmarks that show interesting behavior are the once
testing foreach zones in Geometry Nodes. These tests are explicitly testing
overhead, which I still have to reduce over time. So it's not unexpected that
changing the mutex has an impact there. What's interesting is that on macos the
performance improves a lot while on linux it gets worse. Since that overhead
should eventually be removed almost entirely, I don't really consider that
blocking.

Links:
* Documentation of different mutex flavors in TBB:
  https://www.intel.com/content/www/us/en/docs/onetbb/developer-guide-api-reference/2021-12/mutex-flavors.html
* Older implementation of a similar mutex by me:
  https://archive.blender.org/developer/differential/0016/0016711/index.html
* Interesting read regarding how a mutex can be this small:
  https://webkit.org/blog/6161/locking-in-webkit/

Pull Request: https://projects.blender.org/blender/blender/pulls/138370
2025-05-07 04:53:16 +02:00
Campbell Barton
720b00ae50 Cleanup: use doxygen comments in BKE, consistent comment blocks
Also remove doxygen comment use for comments in the functions body.
2025-04-22 06:13:33 +00:00
Campbell Barton
aa4f717b41 Docs: add missing \file blocks to blenlib & blenkernel 2025-03-29 15:18:50 +11:00
Jacques Lucke
51904839ac Fix #135948: Geometry Nodes: support evaluating undefined custom group nodes
The main reason that didn't work before because undefined custom node groups
have the undefined `bNodeType` (and thus are ignored in various places) but are
actually still groups that can be evaluated. The fix is just to handle custom
node groups a bit more explicitly.

In the future, we may want to have a separate "undefined custom group"
`bNodetype`, but that might a be a bit bigger project.

Pull Request: https://projects.blender.org/blender/blender/pulls/135974
2025-03-14 18:31:29 +01:00
Hans Goudey
9cade06f5f Refactor: Nodes: Use Map instead of GHash for compositor previews
Replace `bNodeInstanceHash` with a `Map`. Move it to the node tree
runtime data. Simplify some code by removing the tag from the hash
value and collecting unused previews directly. Then just remove a
bunch of code that's now unused.

Note that texture node previews haven't been working for a while
anyway, and the experimental shader node previews seem to use
a different system (this one is a remnant of Blender Internal).

Pull Request: https://projects.blender.org/blender/blender/pulls/135310
2025-03-03 14:04:20 +01:00
Falk David
2822777f13 Nodes: support boolean inputs as toggles in panel headers
Adds the option to create a boolean socket that can be used as a panel toggle.
This allows creating simpler and more compact node group UIs when a panel
can be "disabled".

The toggle input is a normal input socket that is just drawn a bit differently in
the UI. Whether a boolean is a toggle input or not does not affect evaluation.

Also see #133936 for guides on how to add and remove panel toggles.

Pull Request: https://projects.blender.org/blender/blender/pulls/133936
2025-02-28 19:07:02 +01:00
Jacques Lucke
3baac1992a Fix: Nodes: handle undefined nodes more gracefully
Found while checking #134193.
2025-02-07 13:26:24 +01:00
Hans Goudey
c2fd4eb9cc Cleanup: Deduplicate custom VectorSet identifier hash and equality
Add `CustomIDVectorSet` for this purpose.
Based on code from Jacques in #133778.

Pull Request: https://projects.blender.org/blender/blender/pulls/133821
2025-01-30 19:51:40 +01:00
Jacques Lucke
80441190c6 Nodes: automatically gray out input values that don't affect the output
This patch automatically grays out input values which can't affect the output
currently. It works with inputs of group nodes, geometry nodes modifiers and
node tools.

To achieve this, it analyses the node tree and partially evaluates it to figure
out which group inputs are currently not linked to an output or are disabled by e.g.
some switch node.

Original proposal: https://devtalk.blender.org/t/dynamic-socket-visibility/31874
Related info in blog post:
https://code.blender.org/2023/11/geometry-nodes-workshop-november-2023/#dynamic-socket-visibility

Follow up task for designing a UI that allows hiding sockets: #132706

Limitations:
* The inferencing does not update correctly when a socket starts being
  animated/driven. I haven't found a good way to invalidate the cache in a good
  way reliably yet. It's only a very short term problem though. It fixes itself
  after the next modification of the node tree and is only noticeable when
  animating some specific sockets such as the switch node condition.
* Whether a socket is grayed out is not exposed in the Python API yet. That will
  be done separately.
* Only a partial evaluation is done to determine if an input affects an output.
  There should be no cases where a socket is found to be unused when it can actually
  affect the output. However, there can be cases where a socket is inferenced to be used
  even if it is not due to some complex condition. Depending on the exact circumstances,
  this can either be improved or the condition in the node tree should be simplified.

Pull Request: https://projects.blender.org/blender/blender/pulls/132219
2025-01-21 12:53:24 +01:00
Jacques Lucke
259c98fa72 Nodes: add utility method to check node type
The `bNode.type_legacy` is still used in many places to check if a node is a
specific type. However, going forward it's better to rely more on the idname
than on this legacy integer type. Some more information is available in #132858.

The added utility method can be used like so:
`node->is_type("GeometryNodeMenuSwitch")`. Previously one would have written
`node->type_legacy == GEO_NODE_MENU_SWITCH`. The `is_type` method internally
checks that the passed in string is a valid node identifier to make it more
likely that we catch typos early.

Pull Request: https://projects.blender.org/blender/blender/pulls/132863
2025-01-09 16:59:47 +01:00
Jacques Lucke
971c96a92c Nodes: rename integer type of nodes to type_legacy
The new description for `bNode.type_legacy`:
```
  /**
   * Legacy integer type for nodes. It does not uniquely identify a node type, only the `idname`
   * does that. For example, all custom nodes use #NODE_CUSTOM but do have different idnames.
   * This is mainly kept for compatibility reasons.
   *
   * Currently, this type is also used in many parts of Blender, but that should slowly be phased
   * out by either relying on idnames, accessor methods like `node.is_reroute()`.
   *
   * A main benefit of this integer type over using idnames currently is that integer comparison is
   * much cheaper than string comparison, especially if many idnames have the same prefix (e.g.
   * "GeometryNode"). Eventually, we could introduce cheap-to-compare runtime identifier for node
   * types. That could mean e.g. using `ustring` for idnames (where string comparison is just
   * pointer comparison), or using a run-time generated integer that is automatically assigned when
   * node types are registered.
   */
```

Pull Request: https://projects.blender.org/blender/blender/pulls/132858
2025-01-09 15:28:57 +01:00
Brecht Van Lommel
920e709069 Refactor: Make header files more clangd and clang-tidy friendly
When using clangd or running clang-tidy on headers there are
currently many errors. These are noisy in IDEs, make auto fixes
impossible, and break features like code completion, refactoring
and navigation.

This makes source/blender headers work by themselves, which is
generally the goal anyway. But #includes and forward declarations
were often incomplete.

* Add #includes and forward declarations
* Add IWYU pragma: export in a few places
* Remove some unused #includes (but there are many more)
* Tweak ShaderCreateInfo macros to work better with clangd

Some types of headers still have errors, these could be fixed or
worked around with more investigation. Mostly preprocessor
template headers like NOD_static_types.h.

Note that that disabling WITH_UNITY_BUILD is required for clangd to
work properly, otherwise compile_commands.json does not contain
the information for the relevant source files.

For more details see the developer docs:
https://developer.blender.org/docs/handbook/tooling/clangd/

Pull Request: https://projects.blender.org/blender/blender/pulls/132608
2025-01-07 12:39:13 +01:00
Jacques Lucke
748d98dff2 Nodes: add utility method to get ranges of socket indices
The `socket->index_in_tree()` method provides a unique index for that socket
in the node tree (it's a cached runtime value). By construction, all input/output
sockets of a node have consecutive numbers, but this (sometimes useful) fact
is currently not exposed in the API.

This patch adds new `input_socket_indices_in_tree` and
`output_socket_indices_in_tree` methods to get the range of indices for all
inputs or outputs of a node.
2024-12-23 15:16:30 +01:00
Jacques Lucke
8bec7dce35 Nodes: avoid O(n^2) when looking up interface input indices
Previously, the code was O(n^2) because it iterated over all interface sockets,
and for each it tried to find the corresponding index by iterating over all
inputs again. Now, a `VectorSet` is used to make finding the index `O(1)`. The
new utility function may also be useful elsewhere.

Pull Request: https://projects.blender.org/blender/blender/pulls/132272
2024-12-23 15:01:07 +01:00
Hans Goudey
42fc3922aa Cleanup: Move node ID hash utilities to bke namespace 2024-12-22 10:52:08 -05:00
Hans Goudey
87a1984b96 Cleanup: Rename node "totr" to "draw_bounds"
Pull Request: https://projects.blender.org/blender/blender/pulls/131864
2024-12-13 16:51:56 +01:00
Hans Goudey
f8b914e004 Cleanup: Remove unused node preview variables
These were only written to, never read.
2024-12-13 10:27:11 -05:00
Hans Goudey
da8ecea151 Refactor: Nodes: Move socket field status to array
Instead of storing an optional in the runtime data of each node,
move the field status for the socket to an array in the node tree's
runtime data. This wasn't possible before because selecting nodes
reordered nodes which caused too much cache recomputation.

The benefit is having less geometry-nodes specific data in the
node socket runtime struct, and a slight move to a more data-
oriented storage format.

Pull Request: https://projects.blender.org/blender/blender/pulls/131822
2024-12-12 23:52:39 +01:00
Hans Goudey
4bf34d9591 Nodes: Simplify location storage, remove hidden offfsets
Currently each node's position is stored in the coordinate space of
its parent. To find the location of a node on the canvas, we have to
apply the translation of each of its parents. Also, nodes have hidden
"offset" values used while transforming frame nodes. Together,
those made the system much more complicated than necessary,
and they made the Python API ineffective.

This commit removes usage of the offset values and moves nodes
to be stored in the "global" space of the node canvas. It also resolves
some weird behavior when resizing frame nodes, and fixes a few bugs.

The change is forward compatible, so we still write files with nodes in
the old parent-space format. In 5.0 the conversion when writing can be
removed. The existing Python API also stays the same. A new
"location_absolute" property gives node locations in global space,
and changing the old property also moves the child nodes of frames.

Resolves #92458, #72904.

Pull Request: https://projects.blender.org/blender/blender/pulls/131335
2024-12-11 21:06:41 +01:00
Jacques Lucke
b36bf15e28 Geometry Nodes: improve detecting data-block dependencies
Previously, the data-block dependencies were always detected in
`update_depsgraph` in `MOD_nodes.cc`. This would only be called when something
called `DEG_relations_tag_update` before. We don't want to trigger a depsgraph
rebuild after each operation in the node editor, as that would be expensive.
However, that also meant that we often had to add data-block dependencies that
are not actually used, but might be used if the user changed e.g. a link. A
typical example for that is a object socket that has a default value, but the
socket is also linked.

Now, the dependencies referenced by the node tree are collected by the node tree
update code which runs after all changes. This way we can detect whether the
dependencies have changed. Only if they have changed, a depsgraph rebuild is
triggered. This now allows also taking into account the mute status of nodes and
whether an input is linked.

There are still more things that could be taken into account. Most obviously
whether a node is connected to an output. This can be done later. The most
tricky aspect here is probably that we also have to consider all viewer nodes as
output, because at the time the node runs, it's not known which viewer will
actually be used (which depends on other editors).

This also cleans up some special cases we had for e.g. the scene time node where
we always had to trigger a depsgraph rebuild when it was added/removed because
of its time dependence. This is now part of a more general system.

This fixes #109219.

Pull Request: https://projects.blender.org/blender/blender/pulls/131446
2024-12-05 18:02:14 +01:00
Jacques Lucke
a239bfc4dd Refactor: Nodes: improve drawing of nodes based on node declaration
The main goal is to simplify adding support for nested node panels. The patch
makes use of the updated recursive node declarations introduced in
6ffc585fb8.

The main changes are:
* Rewritten node drawing in a way that makes ui design decisions like panel
  visibility and margins more explicit. Especially the handling of margins is
  much better now imo. Previously, it was very hard to change the margin for
  specific cases without accidentally breaking other situations. Now each
  possible case has an explicit margin. This needs a few more lines of code but
  is much easier to work with.
* Rewritten node drawing in panel (sidebar + material properties) using the new
  ways to iterate over the declaration.
* It's possible to add custom layouts at any point in the node declaration now.
  This also replaces the need for having a `draw_buttons` callback for panels.

Pull Request: https://projects.blender.org/blender/blender/pulls/128822
2024-10-11 12:20:58 +02:00
Jacques Lucke
67c7485bfd Refactor: Geometry Nodes: improve lifetime analysis for anonymous attributes
This refactors the lifetime analysis of anonymous attributes in geometry nodes.
The refactor has a couple of goals:
* Use a better and simpler abstraction that can be used when building the
  lazy-function graph. We currently have a bunch of duplicate code to handle
  "field source" and "caller propagation" attributes. This is now unified so
  that one only has to worry about one kind of "reference sets".
* Make the abstraction compatible with handling bundles and closures in case we
  want to support them in the future. Both types can contain geometries and
  fields so they need to be taken into account when determining lifetimes.
* Make more parts independent of the concept of "anonymous attributes". In
  theory, there could be more kinds of referenced data whose lifetimes need to
  be managed. I don't have any concrete plans for adding any though.

At its core, deterministic anonymous attributes still work the same they have
been since they became deterministic [0]. Even the generated lazy-function graph
is still pretty much or even exactly the same as before.

The patch renames `AnonymousAttributeSet` to the more general
`GeometryNodesReferenceSet` which is more. This also makes more places
independent of the concept of anonymous attributes. Functionally, this still the
same though. It's only used in the internals of geometry nodes nowadays. Most
code just gets an `AttributeFilter` that is based on it.

[0]: https://archive.blender.org/developer/D16858

Pull Request: https://projects.blender.org/blender/blender/pulls/128667
2024-10-07 12:59:39 +02:00
Jacques Lucke
35bb4f4711 Geometry Nodes: support accessing repeat zone lazy-function graph from Python
The tricky thing here is that this graph is only generated while geometry nodes
is evaluated and is generally only stored temporarily. To make it accessible via
Python, the accessor method will cause a reevaluation specifically to log the
generated graph.
2024-09-15 00:56:53 +02:00
Jacques Lucke
24f7b7a8fb Cleanup: Nodes: reduce coupling between socket shape and field state
Previously, the inferencing result was only stored in the socket shape.
However, that was conflicting with experiments where the socket shape and
the field state was not related.
2024-08-20 16:15:59 +02:00
Iliya Katueshenock
1b67be14c6 Cleanup: BKE: Nodes: Functions renaming
Use snake style naming for all the kernel nodes functions.
Omit kernel prefix in the names since of the using namespace.
Use full forms of the terms
('iter' -> 'iterator', 'ntree' -> 'node_tree', 'rem' -> 'remove', ...).

Pull Request: https://projects.blender.org/blender/blender/pulls/126416
2024-08-19 20:27:37 +02:00
Jacques Lucke
24dc9a21b1 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
Jacques Lucke
d367b6e4a2 Nodes: add non-const owner_tree access 2024-06-28 12:44:44 +02:00
Campbell Barton
7f7648c6ed Cleanup: spelling in code comments & minor edits
- Use uppercase NOTE: tags.
- Correct bNote -> bNode.
- Use colon after parameters.
- Use doxy-style doc-strings.
2024-06-06 09:55:13 +10:00
Jacques Lucke
399f6a1c60 Nodes: add descriptions for why links are invalid
Blender shows invalid links in red in the node editor. However, it's not always
obvious why some links don't work, especially for beginners. This patch adds
additional information for every invalid link on the node that it links to.

The following error messages are added:
* Invalid link because of missing implicit conversions.
* Link cycle in node tree.
* A link from a field to a socket that does not support fields.
* Using the same menu on multiple Menu Switch nodes.

Currently, there are some per tree-type special cases in the link validation code.
In the future, this should be moved to tree type specific callbacks.

Pull Request: https://projects.blender.org/blender/blender/pulls/121976
2024-05-23 14:31:16 +02:00
Iliya Katueshenock
75d17b1db5 Cleanup: Move BKE_node to namespace
Move all header file into namespace.
Unnecessary namespaces was removed from implementations file.
Part of forward declarations in header was moved in the top part
of file just to do not have a lot of separate namespaces.

Pull Request: https://projects.blender.org/blender/blender/pulls/121637
2024-05-13 16:07:12 +02:00
Iliya Katueshenock
942ca6be6d Fix #120071: quadratic complexity for dangling reroute check
To know if link is connected to dangling reroute and can be skipped
as value-less, we need to know if reroute is dangling. This requires
graph traversal. Currently this is done by non-recursive iteration.
But this can lead quadratic complexity for some of the cases.
Other way is to make this linear while cache building.

Pull Request: https://projects.blender.org/blender/blender/pulls/120375
2024-04-08 16:19:40 +02:00
Hans Goudey
fc0d8ba012 Cleanup: Remove C++ ifdef checks in C++ headers
Pull Request: https://projects.blender.org/blender/blender/pulls/119900
2024-03-26 04:56:03 +01:00
Campbell Barton
6f6a6ace39 Cleanup: redundant forward declarations of structs 2024-03-08 11:31:11 +11:00