Commit Graph

524 Commits

Author SHA1 Message Date
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
Hans Goudey
be0b08f6f8 Fix #121621: Memory leak with new node description
Error in 6176e66636
The description wasn't copied to new node trees, and it wasn't freed.
2024-05-09 09:35:02 -04:00
Jacques Lucke
6176e66636 Nodes: add node group description
This allows node groups to have a description that is shown in the add menu
or when hovering over the node header.

This new description is stored in `bNodeTree.description`. Unfortunately, it
conflicts a bit with `ID.asset_data.description`. The difference is that the latter
only exists for assets. However, it makes sense for node groups to have
descriptions even if they are not assets (just like `static` functions in C++ should
also be able to have comments). In some cases, node groups are also generated
by addons for a specific purpose. Those should still have a description without
being reusable to make it easier to understand for users.

The solution here is to use the asset description if the node group is an asset,
and to use `bNodeTree.description` otherwise. The description is synced
automatically when marking or clearing assets.

A side benefit of this solution is that appended node group assets can keep their
description, which is currently always lost.

Pull Request: https://projects.blender.org/blender/blender/pulls/121334
2024-05-08 11:25:00 +02:00
Campbell Barton
9918488bb1 Cleanup: use uppercase tags, following own style guide 2024-05-03 11:33:21 +10:00
Bastien Montagne
ec350a6115 BKE ID copy: Pass new owner ID when possible.
Advanced ID copying code can now take a `new_owner_id` ID pointer parameter,
and use it to set the relevant 'loopback' pointer to its owner ID by the
copy code itself.

Besides avoiding the need for all code copying embedded IDs to set the
loopback pointer themselves, this also means that `lib_id` copying code
itself does not need to use `IDWALK_IGNORE_MISSING_OWNER_ID` anymore.

This change is not expected to have any effect in current codebase.
2024-05-02 17:17:04 +02:00
Bastien Montagne
eb9bec54ad IDType owner ID accessor: Add option to skip relationship sanity checks.
While currently, all cases where `BKE_id_owner_get` is called are
'safe', there are some points in code where the pointers ensureing the
relationship between an embedded ID and its owner are not (fully) valid.

This new option (`false` by default) allows to skip the debug asserts
ensuring the sanity of these 'owner <-> embedded' ID pointers in the
relevant `owner_pointer_get` callbacks.

This change is not expected to have any effect in current codebase.
2024-05-02 17:17:03 +02:00
Jacques Lucke
5bc949b4a7 Fix: avoid tagging file as modified when clicking in node editor 2024-05-02 01:43:45 +02:00
Jacques Lucke
17cc5d694c Fix #121214: invalid owner_tree pointer when node tree is overridden 2024-05-01 21:29:04 +02:00
Iliya Katueshenock
5fa98aa0fd Cleanup: Camel case for node size enum items
Pull Request: https://projects.blender.org/blender/blender/pulls/121297
2024-05-01 15:27:34 +02:00
Jacques Lucke
176c6ef329 Geometry Nodes: unify menu switch with other nodes with dynamic sockets
This changes the menu switch socket to use the socket-items system
(`NOD_socket_items.hh`) that is already used by the simulation zone, repeat
zone, bake node and index switch node. By using this system, the per-node
boilerplate can be removed significantly. This is especially important as we
plan to have dynamic socket amounts in more nodes in the future.

There are some user visible changes which make the node more consistent with
others:
* Move the menu items list into the properties panel as in 0c585a1b8a.
* Add an extend socket.
* Duplicating a menu item keeps the name of the old one.

There is also a (backward compatible) change in the Python API: It's now
possible to directly access `node.enum_items` and `node.active_index` instead of
having to use `node.enum_definition.enum_items`. This is consistent with the
other nodes. For backward compatibility, `node.enum_definition` still exists,
but simply returns the node itself.

Many API functions from `NodeEnumDefinition` like
`NodeEnumDefinition::remove_item` have been removed. Those are not used anymore
and are unnecessary boilerplate. If ever necessary, they can be implemented back
in terms of the socket-items system.

The socket-items system had to be extended a little bit to support the case for
the menu switch node where each socket item has a name but no type. Previously,
there was the case without name and type in the index switch node, and the case
with both in the bake node and zones. The system was trivial to extend to this
case.

Pull Request: https://projects.blender.org/blender/blender/pulls/121234
2024-04-30 10:19:32 +02:00
Bastien Montagne
f933dae207 BKE_lib_query: Add a partial ID usage iterator system.
The idea is to allow iterating over e.g. all ID usages of a node from a
whole nodetree, using the same generic handling as existing 'whole ID'
`foreach_id` code.

This is necessary in some cases wher a sub-data needs to processed
independently from any 'owner ID', e.g. in some copy/paste handling.

This is a pre-requirement for proper fix of nodes copy/paste (see
e.g. #120103).

Pull Request: https://projects.blender.org/blender/blender/pulls/121018
2024-04-28 17:35:02 +02:00
Brecht Van Lommel
15b9ae5436 Refactor: Use typed functions for blend file data reading
This makes the read and write API functions match more closely, and adds
asserts to check that the data size is as expected.

There are still a few places remaining that use BLO_read_data_address
and similar generic functions, these should eventually be replaced as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/120994
2024-04-24 17:01:22 +02:00
Jacques Lucke
5f3ad33f38 Geometry Nodes: decentralize headers for some nodes
`NOD_zone_socket_items.hh` contained code for different nodes. It's better to
split this into headers per node, because that scales better. Also it helps to
keep the code for each individual node more closely together.

Pull Request: https://projects.blender.org/blender/blender/pulls/120945
2024-04-23 11:13:27 +02:00
Lukas Stockner
cc541f2c07 UI: Add Wavelength unit for scene-independent nanometer-scale inputs
Currently this is only used for the Wavelength node, but it will also be relevant for the Thin Film Interference support in the Principled BSDF.

Pull Request: https://projects.blender.org/blender/blender/pulls/120900
2024-04-22 13:10:16 +02:00
Bastien Montagne
fda3900722 BKE node: Add a new in_lib function to create nodetrees within a library.
While not common, some places of the code (like readfile versionning)
may have to generate new IDs for linked data.
2024-04-16 18:01:15 +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
Lukas Tönne
ee1714136e Fix #119554: Remove links to and from unsupported socket types
#114401 added forward compatibility code to remove unsupported socket
types and avoid crashing with unknown default_value data. However, this
did not update link pointers (which haven't been read at that point),
so the tree can end up with dangling pointers.

To fix this, removal of unsupported sockets is moved further back to a
point where links have been read and can be fixed accordingly.

Ported to main from #119630

Pull Request: https://projects.blender.org/blender/blender/pulls/119650
2024-04-06 11:23:53 +02:00
Jacques Lucke
7400927ada Fix #120084: custom group node remains undefined after registering node type 2024-04-02 16:07:48 +02:00
Hans Goudey
e0567eadbd Cleanup: Use FunctionRef for IDProperty iteration callback
Avoid the need for a seaprate user_data argument.
2024-03-26 15:39:39 -04:00
Hans Goudey
efee753e8f Cleanup: Move BKE_idprop.h to C++ 2024-03-26 13:07:04 -04:00
Hans Goudey
f41ab9abc1 Cleanup: Combine BKE_idprop C and C++ headers
In preparation for moving the whole BKE_idprop.h to C++.
To keep the git history intact we remove the newer smaller file.
2024-03-26 13:07:04 -04:00
Hans Goudey
1681e55114 Geometry Nodes: Add 8-bit integer attribute type to store attribute node
We already expose two other types that don't have a directly
corresponding socket type-- float2 and byte colors. This also solves
the inability to write to the nurbs_order attribute in geometry nodes.

Fixes #119843

Pull Request: https://projects.blender.org/blender/blender/pulls/119879
2024-03-25 23:04:11 +01:00
Jacques Lucke
3ad4ea81d1 Nodes: rename multi_input_socket_index to multi_input_sort_id
For historical reasons, the `multi_input_socket_index` was actually reversed
(large index comes first). This patch renames it to `multi_input_sort_id` and
adds a comment. This new name makes it less confusing that the id is reversed.

Pull Request: https://projects.blender.org/blender/blender/pulls/119652
2024-03-19 13:42:09 +01:00
Jacques Lucke
b33ec06283 Merge branch 'blender-v4.1-release' 2024-03-11 19:18:07 +01:00
Iliya Katushenock
bca31c3846 Fix: handle cyclic links when detecting dangling reroutes
Fix of error from 95810eec8f

Pull Request: https://projects.blender.org/blender/blender/pulls/119335
2024-03-11 19:17:27 +01:00
Hans Goudey
744f3b2823 Cleanup: Grammar in comments: Fix uses of "own"
"Own" (the adjective) cannot be used on its own. It should be combined
with something like "its own", "our own",  "her own", or "the object's own".
It also isn't used separately to mean something like "separate".

Also, "its own" is correct instead of "it's own" which is a misues of the verb.
2024-03-07 16:23:35 -05:00
Bastien Montagne
a681f5d896 Core: Add proper support to add or copy IDs into libraries.
Seems to work OK in basic cases, but needs more work when copying
outside of Main at least.

Note: There is no behavioral changes expected from this commit.

Note that there are at least two known usecases for this change:
* Liboverrides, as with recursive resync and proxies conversion it
  often ends up creating 'virtual' linked data that does not actually
  exists in the library blend files.
* Complex versionning code (`do_versions_after_setup`) when it needs
  to create new IDs (currently handling linked data that way is just not
  supported!).

Implements #107847.
2024-03-06 17:05:10 +01:00
Omar Emara
d6b1d00a0f Cleanup: Use enums instead of numbers for Glare node 2024-03-05 11:51:52 +02:00
Bastien Montagne
de5451b112 Cleanup: Move BKE_anim_data header to be fully C++. 2024-02-28 11:51:03 +01:00
Hans Goudey
c7bea0af1a Cleanup: Add missing fast access to matrix socket base CPPType 2024-02-19 21:49:43 -05:00
Brecht Van Lommel
0f2064bc3b Revert changes from main commits that were merged into blender-v4.1-release
The last good commit was 4bf6a2e564.
2024-02-19 15:59:59 +01:00
Bastien Montagne
df0efda0d6 Refactor: IDTypeInfo: Add info about 'potentially used IDTypes'.
This data was 'hidden' away in a util in
`lib_query.cc`, which made it hard to discover and keep up-to-date.

However, as shown by e.g. #108407, critical low-level features in ID
management code, such as remapping, now rely on this information being
valid.

Also simplify `BKE_library_id_can_use_filter_id` and
`BKE_library_id_can_use_idtype` to make them more generic, relying on
IDTypeInfo to retrieve IDtype-specific info.

No behavioral changes expected here.
2024-02-15 19:45:10 +01:00
Campbell Barton
5c87dfd269 Cleanup: use BLI_time_ prefix for time functions
Also use the term "now" instead of "check" for clarity.
2024-02-15 13:15:56 +11:00
Campbell Barton
aa6ab9caf9 Cleanup: various non-functional changes for C++ 2024-02-14 13:56:58 +11:00
Hans Goudey
1cfe9dd08c Geometry Nodes: Matrix socket type, attribute type, and initial nodes
Implements the design from #116067.
The socket type is called "Matrix" but it is often referred to as "Transform"
when that's what it is semantically. The attribute type is "4x4 Matrix" since
that's a lower level choice. Currently matrix sockets are always passed
around internally as `float4x4`, but that can be optimized in the future
when smaller types would give the same behavior.

A new "Matrix" utilities category has the following set of initial nodes"
- **Combine Transform**
- **Separate Transform**
- **Multiply Matrices**
- **Transform Direction**
- **Transform Vector**
- **Invert Matrix**
- **Transpose Matrix**

The nodes and socket type are behind an experimental flag for now,
which will give us time to make sure it's the right set of initial nodes.
The viewer node overlay doesn't support matrices-- they aren't supported
for rendering in general. They also aren't supported in the modifier interface
currently. But they are supported in the spreadsheet, where the value is
displayed in a tooltip.

Pull Request: https://projects.blender.org/blender/blender/pulls/116166
2024-02-13 18:59:36 +01:00
Bastien Montagne
54618dbae3 Cleanup: Make BKE_global.h a Cpp header. 2024-02-10 18:25:14 +01:00
Bastien Montagne
a9b2cf8ce6 Cleanup: Move BKE_path.h to CPP header. 2024-02-09 19:23:03 +01:00
Bastien Montagne
45e7827898 Clenup: Move BLT headers to Cpp.
Noisy but fairly straight forward.
2024-02-09 18:59:42 +01:00
Lukas Tönne
5ad49f4142 Geometry Nodes: Menu Switch Node
This patch adds support for _Menu Switch_ nodes and enum definitions in
node trees more generally. The design is based on the outcome of the
[2022 Nodes Workshop](https://code.blender.org/2022/11/geometry-nodes-workshop-2022/#menu-switch).

The _Menu Switch_ node is an advanced version of the _Switch_ node which
has a customizable **menu input socket** instead of a simple boolean.
The _items_ of this menu are owned by the node itself. Each item has a
name and description and unique identifier that is used internally. A
menu _socket_ represents a concrete value out of the list of items.

To enable selection of an enum value for unconnected sockets the menu is
presented as a dropdown list like built-in enums. When the socket is
connected a shared pointer to the enum definition is propagated along
links and stored in socket default values. This allows node groups to
expose a menu from an internal menu switch as a parameter. The enum
definition is a runtime copy of the enum items in DNA that allows
sharing.

A menu socket can have multiple connections, which can lead to
ambiguity. If two or more different menu source nodes are connected to a
socket it gets marked as _undefined_. Any connection to an undefined
menu socket is invalid as a hint to users that there is a problem. A
warning/error is also shown on nodes with undefined menu sockets.

At runtime the value of a menu socket is the simple integer identifier.
This can also be a field in geometry nodes. The identifier is unique
within each enum definition, and it is persistent even when items are
added, removed, or changed. Changing the name of an item does not affect
the internal identifier, so users can rename enum items without breaking
existing input values. This also persists if, for example, a linked node
group is temporarily unavailable.

Pull Request: https://projects.blender.org/blender/blender/pulls/113445
2024-01-26 12:40:01 +01:00
Lukas Tönne
f72dbc1ef8 Fix #117422: Move undefined type removal behind after-linking-versioning
There are still node versioning bits running after linking, for example
`version_geometry_nodes_replace_transfer_attribute_node`. This code
relies on node types being untouched at that point.

Move the unknown node type replacement from `ntreeSetTypes` into the
`ntreeUpdateAllNew` function. This is called _after_ late versioning.

Pull Request: https://projects.blender.org/blender/blender/pulls/117441
2024-01-23 15:15:08 +01:00
Jacques Lucke
311ca3e6af Core: rename Session UUID to Session UID
`UUID` generally stands for "universally unique identifier". The session identifier that
we use is neither universally unique, nor does it follow the standard. Therefor, the term
"session uuid" is confusing and should be replaced.

In #116888 we briefly talked about a better name and ended up with "session uid".
The reason for "uid" instead of "id" is that the latter is a very overloaded term in Blender
already.

This patch changes all uses of "uuid" to "uid" where it's used in the context of a
"session uid". It's not always trivial to see whether a specific mention of "uuid" refers
to an actual uuid or something else. Therefore, I might have missed some renames.
I can't think of an automated way to differentiate the case.

BMesh also uses the term "uuid" sometimes in a the wrong context (e.g. `UUIDFaceStepItem`)
but there it also does not mean "session uid", so it's *not* changed by this patch.

Pull Request: https://projects.blender.org/blender/blender/pulls/117350
2024-01-22 13:47:13 +01:00
Bastien Montagne
af5731ce03 Cleanup: Move BKE_idtype.h to Cpp header BKE_idtype.hh 2024-01-20 19:17:36 +01:00
Aras Pranckevicius
a705259b4b Cleanup: move imbuf .h files to .hh 2024-01-19 20:29:38 +01:00
Jacques Lucke
4b47b46f9c Cleanup: rename PIL to BLI
The term `PIL` stands for "platform independent library." It exists since the `Initial Revision`
commit from 2002. Nowadays, we generally just use the `BLI` (blenlib) prefix for such code
and the `PIL` prefix feels more confusing then useful. Therefore, this patch renames the
`PIL` to `BLI`.

Pull Request: https://projects.blender.org/blender/blender/pulls/117325
2024-01-19 14:32:28 +01:00
Jacques Lucke
d25274ee63 Cleanup: rename IDCacheKey.offset_in_ID to identifier
The name `offset_in_ID` is very misleading since it does not have to be an offset at all,
it just has to be some unique value. Often it's also a hash or a constant value depending
on the use.

Pull Request: https://projects.blender.org/blender/blender/pulls/117306
2024-01-18 22:50:40 +01:00
Hans Goudey
85842b0ef3 Fix: Display newly added node in front
The ui order needs to be higher than the other nodes before the
nodes are sorted later.
2024-01-18 16:13:00 -05:00
Bastien Montagne
03c1cc4310 Cleanup: Move BKE_lib_query header to Cpp era. 2024-01-18 12:21:19 +01:00
Lukas Tönne
83d3ba8a58 Fix #116477: Node group sockets with subtypes have broken idnames
Loading pre-4.0.20 node groups with sockets using subtypes causes
broken socket identifiers. This is because the node tree interface now
expects sockets to use the base identifiers ("NodeSocketFloat" instead
of "NodeSocketFloatFactor" etc.).

To correct this the conversion code now replaces socket idnames that
include a subtype suffix with their base names. This fix is also applied
to files between versions 4.0.20 and 4.1.10, where the socket types
may have been converted incorrectly.

Pull Request: https://projects.blender.org/blender/blender/pulls/117133
2024-01-16 15:32:33 +01:00
Hans Goudey
3e76a1a6c2 Cleanup: Move BKE_lib_id.h to C++ 2024-01-15 12:44:14 -05:00
Lukas Tönne
7981b35064 Fix #114582: Replace unknown node types with an 'undefined' node
When loading an unknown node type from a newer Blender version, the node
storage data cannot be properly loaded. Re-saving the file will then
crash if saving with the same node type idname, since new Blender
versions cannot find the expected storage data.

Loading in older versions should replace unknown node types with a dummy
"Undefined" node that will get loaded as NodeTypeUndefined in newer
versions as well. Custom node types are exempted from this since they
store all data as generic ID properties and can always be fully
serialized.

This is a revised version of the initial attempt in #114803.
Doing the node type fix in the after-linking stage ensures that
versioning code can change outdated node types which might otherwise get
removed by this type check.

Pull Request: https://projects.blender.org/blender/blender/pulls/116908
2024-01-09 18:29:33 +01:00