Commit Graph

233 Commits

Author SHA1 Message Date
Alberto Pilotto
e96e300099 Geometry Nodes: align sockets in Replace String and Slice string nodes
This is similar to f19f260ca8.

Pull Request: https://projects.blender.org/blender/blender/pulls/139219
2025-05-21 18:01:06 +02:00
Jacques Lucke
c55ffb5258 Nodes: improve implicit inputs
This improves implicit node inputs in multiple ways:
* Fix crash when switching a group input socket type from e.g. vector to
  integer, while the default input is set to "position". Now, the default input
  type is reset automatically if it's invalid.
* Add Left/Right Handle as possible implicit vector inputs (next to Position and
  Normal). Those were the only ones that we used internally that were not
  exposed yet.
* When creating a new group input from an existing socket, also initialize the
  default input based on the socket. E.g. when grouping a `Set Position` node,
  the `Position` input of the group will now also use the position attribute by
  default.

In addition to these user-level changes, some internal changes were done too:
* Use unified `NodeDefaultInputType` in node declaration instead of function
  pointers which were hard to propagate to node groups.
* Use a new reusable `socket_type_supports_default_input_type` function in rna
  to filter the list of possible input items.

Pull Request: https://projects.blender.org/blender/blender/pulls/139139
2025-05-20 17:54:49 +02:00
Colin Basnett
39c2f01b51 Nodes: add Bit Math node
This adds a new Bit Math node which supports the following operations: `and`,
`or`, `xor`, `not`, `shift` and `rotate`.

For the `shift` and `rotate` operations, a posititive shift is a left shift and
a negative shift is a right shift.

Currently, the node always works on 32-bit integers which is what Geometry Nodes
uses internally for integers. If required, this can be extended to work on other
bit widths in the future.

The need for this came up every now and then. It can be useful when encoding
specific bits in integer attributes (for efficiency or because the geometry is
exported to other software that expects a certain format). Also, this node is
useful for some people doing crazy but fun things with Geometry Nodes like
emulating hardware. Even if the use-cases are not common, if they arise, it's
hard to work around and the cost of having this node is quite low for us.

Co-authored-by: Charlie Jolly <charliejolly@noreply.localhost>

Pull Request: https://projects.blender.org/blender/blender/pulls/138290
2025-05-19 18:03:05 +02:00
Jacques Lucke
23d5ae7da5 Refactor: Nodes: decentralize node storage blend read/write
Previously, whenever a node had a non-trivial storage struct, there would have
to be code for it in `node.cc`. Now there is a general callback that new node
types can use to implement their blend read/write behavior.

Some existing nodes were converted to use this decentralized method. However,
some older nodes can't use it in the same way, because the node types were
introduced before there were node idnames. It's also somewhat hard to reason
about special cases that versioning code might have for these nodes, so they
remain unchanged.

The node callback only writes the non-trivial data, while the main node storage
struct is written automatically by relying on `bNodeType::storagename`. This
simplifies the callback in many cases or makes it unnecessary for trivial types.

Some nodes have specific handling for forward-compatibility. This
forward-compatibility code is kept in `node.cc` for now, because it also affects
the main storage struct and therefore has to be changed before that struct is
written.

Pull Request: https://projects.blender.org/blender/blender/pulls/138722
2025-05-13 07:00:03 +02:00
Guillermo Venegas
858abf43c3 Refactor: UI: Replace uiItemFullR with class method uiLayout::prop
This converts the public `uiItemFullR` function to an object oriented
API (an overload of `uiLayout::prop`), matching the python API.
This reduces the difference between the C++ API with the python version,
its also helps while converting code from python to C++ code (or vice-versa),
making it almost seamless.

Part of: #117604

Pull Request: https://projects.blender.org/blender/blender/pulls/138683
2025-05-10 03:39:31 +02:00
Guillermo Venegas
dafdced6ab Refactor: UI: Replace uiItemR with class method uiLayout::prop
This converts the public `uiItemR` function to an object oriented
API (`uiLayout::prop`), matching the python API.
This reduces the difference between the C++ API with the python version,
its also helps while converting code from python to C++ code (or vice-versa),
making it almost seamless.

Part of: #117604

Pull Request: https://projects.blender.org/blender/blender/pulls/138617
2025-05-08 20:45:37 +02:00
Guillermo Venegas
2d896877d1 Refactor: UI: Replace uiLayoutColumn with class method uiLayout::column
This converts the public `uiLayoutColumn` function to an object oriented
API (`uiLayout::column`), matching the python API.
This reduces the difference between the C++ API with the python version,
its also helps while converting code from python to C++ code (or vice-versa),
making it almost seamless.

`uiLayout::column` now returns an `uiLayout` reference instead of a pointer.
New calls to this method should use references too.

Pull Request: https://projects.blender.org/blender/blender/pulls/138034
2025-04-26 21:07:34 +02:00
Hans Goudey
f19f260ca8 Nodes: Align inputs and outputs on some function nodes
Adjust 9 rotation and matrix nodes.
In some cases this helps to clarify the node's purpose.

Pull Request: https://projects.blender.org/blender/blender/pulls/137672
2025-04-17 17:17:19 +02:00
quackarooni
8a869c20e9 Geometry Nodes: Match String node
Adds "Starts With", "Ends With", and "Compare" string operations as a
standalone node.

Pull Request: https://projects.blender.org/blender/blender/pulls/136021
2025-04-03 02:57:39 +02:00
Pasang Bomjan
95acb63f5f UI: Nodes: Add placeholder for text button in the String input node
Pull Request: https://projects.blender.org/blender/blender/pulls/135907
2025-03-31 21:07:47 +02:00
Bastien Montagne
78969aaff8 Cleanup: nodes: Replace 'void' MEM_[cm]allocN with templated, type-safe MEM_[cm]allocN<T>.
The main issue of 'type-less' standard C allocations is that there is no check on
allocated type possible.

This is a serious source of annoyance (and crashes) when making some
low-level structs non-trivial, as tracking down all usages of these
structs in higher-level other structs and their allocation is... really
painful.

MEM_[cm]allocN<T> templates on the other hand do check that the
given type is trivial, at build time (static assert), which makes such issue...
trivial to catch.

NOTE: New code should strive to use MEM_new (i.e. allocation and
construction) as much as possible, even for trivial PoD types.

Pull Request: https://projects.blender.org/blender/blender/pulls/135855
2025-03-12 12:15:33 +01:00
Bastien Montagne
dd168a35c5 Refactor: Replace MEM_cnew with a type-aware template version of MEM_callocN.
The general idea is to keep the 'old', C-style MEM_callocN signature, and slowly
replace most of its usages with the new, C++-style type-safer template version.

* `MEM_cnew<T>` allocation version is renamed to `MEM_callocN<T>`.
* `MEM_cnew_array<T>` allocation version is renamed to `MEM_calloc_arrayN<T>`.
* `MEM_cnew<T>` duplicate version is renamed to `MEM_dupallocN<T>`.

Similar templates type-safe version of `MEM_mallocN` will be added soon
as well.

Following discussions in !134452.

NOTE: For now static type checking in `MEM_callocN` and related are slightly
different for Windows MSVC. This compiler seems to consider structs using the
`DNA_DEFINE_CXX_METHODS` macro as non-trivial (likely because their default
copy constructors are deleted). So using checks on trivially
constructible/destructible instead on this compiler/system.

Pull Request: https://projects.blender.org/blender/blender/pulls/134771
2025-03-05 16:35:09 +01:00
илья _
119fc054f8 Cleanup: BKE: Nodes: Pass-by-reference
Restriction of the nodes api to clearly define never-null function arguments.
Side effects: some assertions and null-check (with early return) were removed.
On the caller side is ensured to never derefer null to pass argument (mainly in RNA).
In addition, one pointer argument now actually a return type.

By-reference return types instead of pointers going to be separate kind of
change since also imply of cleaning up variables created from reference.

Also good future improvement would be to mark a copy-constructor as
explicit for DNA node types.

Pull Request: https://projects.blender.org/blender/blender/pulls/134627
2025-02-19 13:44:11 +01:00
Brecht Van Lommel
315d07bd12 Cleanup: Various clang-tidy warnings in nodes
Pull Request: https://projects.blender.org/blender/blender/pulls/133734
2025-01-31 17:03:18 +01:00
Brecht Van Lommel
e0479e2fb4 Geometry Nodes: Use OpenColorIO for luminance
Color to grayscale conversions should take into account the colorspace,
and these are considered to be in scene linear colorspace.

No change with the default configuration.

Pull Request: https://projects.blender.org/blender/blender/pulls/133368
2025-01-21 18:05:56 +01:00
Jacques Lucke
476b7ded9e Nodes: make explicit legacy type optional
This makes specifying a legacy type for new node types optional (e.g.
`GEO_NODE_MESH_TO_CURVE`). Instead, only the `idname` is used as a stable
identifier for node types. So there is less redundancy for now.

This change helps with the decentralized definition of nodes and reduces the
number minimum number of files that need to be changed for a new node from 5 to
4. It especially helps when multiple nodes are worked on at the same time,
because the legacy type definition was very prone to have merge conflicts.

For compatibility reasons and because it's still used by existing code, the
`legacy_type` is not removed. All existing nodes keep their current
`legacy_type`. New nodes will receive an auto-incremented legacy type. It's
still necessary to give nodes unique legacy types, because some code checks if
two nodes have the same type by comparing their `legacy_type`. These types only
have to be unique at run-time though. Some randomness is used to avoid depending
on stable generated legacy types accidentally.

Pull Request: https://projects.blender.org/blender/blender/pulls/133044
2025-01-14 14:39:36 +01:00
Jacques Lucke
b32a5882c1 Cleanup: Nodes: move node class parameter out of node_type_base
The node class is hardly important enough (especially compared to the other parameters)
that it is justified to have to pass it to `node_type_base`.

Pull Request: https://projects.blender.org/blender/blender/pulls/133021
2025-01-14 11:03:28 +01:00
Hans Goudey
f2c9fccee0 Cleanup: Move legacy node integer types defines to separate header
Moving these defines to a separate header makes their "legacy" status
more obvious. This commit just adds the include wherever necessary.

Followup to 971c96a92c.

Pull Request: https://projects.blender.org/blender/blender/pulls/132875
2025-01-09 20:03:08 +01:00
Jacques Lucke
0fa4c6da18 Refactor: Nodes: avoid using NOD_static_types.hh when creating node types
This removes the second to last usage of `NOD_static_types.hh` which we intend
to remove. A nice benefit is that the idname is now finally more explicit when a
node is registered. Previously it was difficult to search for the definition of
a node in the code when one had only the idname, which is the main identifier
for nodes.

The main change is in `node_type_base`.

Pull Request: https://projects.blender.org/blender/blender/pulls/132815
2025-01-09 12:19:57 +01:00
Hans Goudey
2afd946ba6 Refactor: Nodes: Move UI name out of NOD_static_types.h header
As part of an effort to remove this header, reducing the need for macro/
include magic and making node definitions more independent, move
the node UI name and description definitions to each node's file.
The UI name, description, and idname are also moved to std::string
instead of char arrays.

Similar to b43e2168e3.

Pull Request: https://projects.blender.org/blender/blender/pulls/132708
2025-01-08 18:07:11 +01:00
Ray Molenkamp
5783950ac5 Revert: 0dc484f9cc bf_rna modernisation
This caused build errors on the docs builder, I can't seem to reproduce
locally, so revert for now and have another look at some point in the
future.

Sadly as these changes usually go, this took 5c515e26bb and
2f0fc7fc9f with it as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/132559
2025-01-02 19:56:24 +01:00
Campbell Barton
f417c7ad2c Cleanup: sort cmake file lists 2025-01-02 15:11:21 +11:00
Ray Molenkamp
0dc484f9cc Cleanup: CMake: Modernize bf_rna dependencies
Pretty straightforward

- Remove any bf_rna paths from INC
- Add a dependency though LIB when missing

context: https://devtalk.blender.org/t/cmake-cleanup/30260

Pull Request: https://projects.blender.org/blender/blender/pulls/132413
2024-12-31 18:23:25 +01:00
Ray Molenkamp
4dcef4421c Cleanup: CMake: Modernize bf_functions dependencies
Pretty straightforward

- Remove any bf_functions paths from INC
- Add a dependency though LIB when missing

context: https://devtalk.blender.org/t/cmake-cleanup/30260

Pull Request: https://projects.blender.org/blender/blender/pulls/132335
2024-12-25 19:46:31 +01:00
Ray Molenkamp
c331c6b50e Cleanup: CMake: Modernize bf_blentranslation dependencies
Pretty straightforward

- Remove any bf_blentranslation paths from INC
- Add a dependency though LIB when missing

context: https://devtalk.blender.org/t/cmake-cleanup/30260

Pull Request: https://projects.blender.org/blender/blender/pulls/132311
2024-12-25 17:40:25 +01:00
Ray Molenkamp
54604efdfd Cleanup: CMake: Modernize bf_windowmanager dependencies
Pretty straightforward

- Remove any bf_windowmanager paths from INC
- Add a dependency though LIB when missing

context: https://devtalk.blender.org/t/cmake-cleanup/30260

Pull Request: https://projects.blender.org/blender/blender/pulls/132310
2024-12-24 22:40:38 +01:00
SensArice
1098f434b0 Geometry Nodes: Find in String node
Add a node that finds the number of times a substring occurs in a string,
and the position of the start of the first match.

See the PR description for more rational and details.

Pull Request: https://projects.blender.org/blender/blender/pulls/129270
2024-12-24 17:12:19 +01:00
Ray Molenkamp
a7c39896c6 Cleanup: CMake: Modernize bf_blenkernel dependencies
Pretty straightforward

- Remove any bf_blenkernel paths from INC
- Add a dependency though LIB when missing

context: https://devtalk.blender.org/t/cmake-cleanup/30260

Pull Request: https://projects.blender.org/blender/blender/pulls/132282
2024-12-23 20:08:37 +01:00
Hans Goudey
b43e2168e3 Refactor: Nodes: Remove legacy enum name from NOD_static_types.h
A followup for 5e7f3e5c84.

Make the NOD_static_types.h file less important by moving `enum_name_legacy`
to be defined in the register function of every node. This helps our gradual transition
away from this file.

Also add a fallback to the node idname so that newly added nodes no longer need
to define the string value.

Pull Request: https://projects.blender.org/blender/blender/pulls/132131
2024-12-19 18:12:05 +01:00
Hans Goudey
21aef81714 Cleanup: Use StringRef and std::optional for UI string arguments
- Gives O(1) access to string length in more cases
- Convenient string manipulation functions
- Clarify difference between "no string" and "empty string"
- Avoid the need for raw pointers in the API
- Shows which API string arguments are optional

Pull Request: https://projects.blender.org/blender/blender/pulls/131473
2024-12-06 14:08:10 +01:00
Damien Picard
5f52c5ce46 Fix: I18n: Integer Math node title used wrong translation context
The integer math node items used the proper translation context, but
not the translation for the node label.

Reported by ziweidao.

Pull Request: https://projects.blender.org/blender/blender/pulls/130225
2024-11-13 13:53:57 +01:00
Damien Picard
edcc5e0e87 I18n: Translate and disambiguate a few messages
Translate
- Extract Grease Pencil modifier subpanel header messages.

Disambiguate
- Integer Math node operation (same as other existing math nodes).

Pull Request: https://projects.blender.org/blender/blender/pulls/128715
2024-11-04 11:15:48 +01:00
Campbell Barton
a9b977d256 Cleanup: sort CMake file lists 2024-10-03 14:46:26 +10:00
quackarooni
44fbd69317 Function Node: Value to String Integer subtype
This patch adds an `Integer` type to the Value to String node.
This allows for converting integer inputs into string outputs without
any loss of precision. Something which the original implementation is
not able to do.

This issue becomes evident at values greater than `2 ^ 24` or
`16,777,216`, where the precision loss is high enough that the float
implementation starts skipping certain integers.

Pull Request: https://projects.blender.org/blender/blender/pulls/128362
2024-09-30 23:10:41 +02:00
Colin Basnett
22d78c5a8e Geometry Nodes: add Matrix Determinant node
Pull Request: https://projects.blender.org/blender/blender/pulls/128212
2024-09-30 21:30:10 +02:00
Jacques Lucke
675606cbce Fix: wrong enum type in integer math node 2024-09-30 15:40:27 +02:00
Jacques Lucke
1b31a44935 Geometry Nodes: support inverse evaluation for Integer Math node for gizmos 2024-09-30 14:00:32 +02:00
Brady Johnston
e25405aeb7 Geometry Nodes: improve input labels on Integer Math node
This brings the labels for the Power operation on the integer math node
to align with the regular math node.

Pull Request: https://projects.blender.org/blender/blender/pulls/128222
2024-09-27 11:56:05 +02:00
Charlie Jolly
c0a864aaa3 Fix #128102: Integer Math division has only float precision
The additional division modes were implemented with float
division then rounding to match float > int conversion in
existing float to int node.

As pointed out in the bug report the precision here is limited.

This patch replaces the float division with integer math which
increases the precision to much higher numbers.
Divide Round by due to the way it is calculated has less precision
than Divide Floor and Divide Ceil.

Pull Request: https://projects.blender.org/blender/blender/pulls/128123
2024-09-26 14:44:09 +02:00
Jacques Lucke
a6d5652043 Geometry Nodes: use placeholder instead of label in some string sockets
This makes the input field much wider. I enabled this for most string sockets
except for a few where it is important to see the label even if the user has
inserted a string already (usually because there is more than one string input).

Pull Request: https://projects.blender.org/blender/blender/pulls/127992
2024-09-24 18:22:32 +02:00
Charlie Jolly
bf04513dec Geometry Nodes: new Integer Math node
Provide building block support for integer operations.

Manipulation of integer based data should not be limited to using float math nodes.
Using float math comes with accuracy issues for larger integers and requires unnecessary
type conversions.

The node also adds some integer specific operations like GCM and LCD.

Pull Request: https://projects.blender.org/blender/blender/pulls/110735
2024-09-23 15:01:31 +02:00
Charlie Jolly
294994e4b9 Geometry Nodes: new Hash Value node
This node hashes various types into an integer. Note that hashes
cannot generally used as unique identifiers because they are not
guaranteed to be unique. It can be used to generate somewhat
stable randomness though in cases where White Noise does not
offer enough flexibility.

It uses hash functions from BLI_noise.hh. These are also used in
the White Noise node.

Pull Request: https://projects.blender.org/blender/blender/pulls/110769
2024-08-30 16:42:29 +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
9816dba416 Fix: compilation with clang on linux 2024-07-10 17:47:26 +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
Crax97
5afd84b960 Fix #122763: ensure Vector socket is the default on 'Transform Point'
Ensure that the input socket `Vector` on node `Transform Point` is marked as the default socket.

Pull Request: https://projects.blender.org/blender/blender/pulls/123042
2024-06-14 12:45:58 +02:00
Damien Picard
b37d121e0a 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
Iliya Katueshenock
1904e2fc8d Geometry Nodes: treat rotation as vector data type in link-drag-search in some nodes
If there is implicit conversion between rotation and vector type, so these search items
make sense.

Pull Request: https://projects.blender.org/blender/blender/pulls/121754
2024-05-20 20:30:52 +02:00
Jacques Lucke
861cb8622d Geometry Nodes: change Location to Translation in Combine/Separate Transform nodes
Based on the context, both names can make sense, however "translation"
seems to be the more correct term and general here.

Pull Request: https://projects.blender.org/blender/blender/pulls/121656
2024-05-18 15:48:04 +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