Commit Graph

41 Commits

Author SHA1 Message Date
Jacques Lucke
7075bbc176 Fix #148179: missing node group description in packed asset
The asset meta data containing the description was not packed and hence the
description was lost.

Pull Request: https://projects.blender.org/blender/blender/pulls/148221
2025-10-16 19:19:40 +02:00
Jacques Lucke
66dd8beef3 Fix #147037: copying node referencing packed id does not work
The solution is to remember the deep hash of the copied data-block pointers
instead of just relying on the library file path.

Pull Request: https://projects.blender.org/blender/blender/pulls/147275
2025-10-08 19:39:53 +02:00
Bastien Montagne
a6cea64b3a Fix #147461: Implement packed data support for generic ID copy-paste.
Adding support for packed IDs in the PartialWriteContext was completely
missed in initial work...

This somewhat complexifies the handling of libraries in
PartialWriteContext, as packed IDs need to be handled in specific ways.

It also exposes `bke::library::ensure_archive_library` as a public function,
to avoid duplicating this complex logic of finding or creating a new
archive library for a given ID.

Finally, prevent attempts to copy a packed ID for now, as pasting them
is not supported (linking/appending these directly is not supported).

Pull Request: https://projects.blender.org/blender/blender/pulls/147468
2025-10-07 16:11:47 +02:00
Bastien Montagne
258f449783 Refactor: Library: Be explicit about runtime data copied with ID copying.
Note that this commit keeps the same behavior as before this commit,
except for the newly introduced vector of archived libraries, which is
reset to empty. This behavior may have to be further tweaked still.

Root of the issue was from original commit enabling Library ID copying
(87a4c0d3a8), but the later move to an allocated runtime pointer
using a copy constructor in 87a4c0d3a8 made this behavior even
more confusing/hidden.

In general, what is re-used/copied in runtime data should be explicit,
such that by default new data can be assumed reset to their default
value there in the copy ID.
2025-10-03 17:16:32 +02:00
Campbell Barton
9ebc02fc99 Cleanup: spelling, repeated words (make check_spelling_*) 2025-09-26 22:00:27 +10:00
Jacques Lucke
4e4976804e Core: Add packed linked data-blocks
This adds support for packed linked data. This is a key part of an improved
asset workflow in Blender.

Packed IDs remain considered as linked data (i.e. they cannot be edited),
but they are stored in the current blendfile. This means that they:
* Are not lost in case the library data becomes unavailable.
* Are not changed in case the library data is updated.

These packed IDs are de-duplicated across blend-files, so e.g. if a shot
file and several of its dependencies all use the same util geometry node,
there will be a single copy of that geometry node in the shot file.

In case there are several versions of a same ID (e.g. linked at different
moments from a same library, which has been modified in-between), there
will be several packed IDs.

Name collisions are averted by storing these packed IDs into a new type of
'archive' libraries (and their namespaces). These libraries:
* Only contain packed IDs.
* Are owned and managed by their 'real' library data-block, called an
  'archive parent'.

For more in-depth, technical design: #132167
UI/UX design: #140870

Co-authored-by: Bastien Montagne <bastien@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/133801
2025-09-26 10:53:40 +02:00
Brecht Van Lommel
a4e9e4869d Refactor: Add foreach_working_space_color to ID type
Left for future work:
* Freestyle modifiers, dynamic paint, legacy texture mapping
* Editor colors: should be changed to sRGB?
* Studio light preferences: also sRGB, though less clear

Pull Request: https://projects.blender.org/blender/blender/pulls/145476
2025-09-05 19:03:32 +02:00
Bastien Montagne
7c7c68fd7a Refactor: Cleanup Library FileData handling.
Add an explicit 'is owning' tag for libraries' FileData pointer, and
factorize code cleaning it up into a small util function.

Also allows to get rid of the weird ugly exception case in `link_end`
code for the 'root' library filedata, which is usually owned by caller
code and should not be freed here.

Pull Request: https://projects.blender.org/blender/blender/pulls/142723
2025-07-21 17:59:17 +02:00
Brecht Van Lommel
4653b65f7c Logging: Add DEBUG, TRACE severity, replace numeric levels
The numeric levels have no obvious meaning. This removes the distinction
between severity and levels, instead there is a single list of named levels
with defined meaning.

Debug means information that's mainly useful for developers, and trace is for
very verbose code execution tracing.

Pull Request: https://projects.blender.org/blender/blender/pulls/140244
2025-07-09 20:59:26 +02:00
Brecht Van Lommel
8d8e61fefd Logging: Change various categories and log levels
* Remove bke, ed and wm prefixes
* Add prefixes like: geom, object, blend, lib.
* Shorten some category names
* A few log level changes to improve --log-level info output

Pull Request: https://projects.blender.org/blender/blender/pulls/140244
2025-07-09 20:59:26 +02:00
Jacques Lucke
e09ccc9b35 Core: add templated version of BKE_id_new_nomain to reduce explicit casting
This adds a version of `BKE_id_new_nomain` that takes the ID type parameter as
template argument. This allows the function the return the newly created ID with
the correct type, removing the need to use `static_cast` on the call-site.

To make this work, I added a static `id_type` member to every ID struct. This
can also be used to create a similar API for other id management functions in
future patches.

```cpp
// Old
Mesh *mesh = static_cast<Mesh *>(BKE_id_new_nomain(ID_ME, "Mesh"));

// New
Mesh *mesh = BKE_id_new_nomain<Mesh>("Mesh");
```

Pull Request: https://projects.blender.org/blender/blender/pulls/138383
2025-05-05 18:41:03 +02:00
Bastien Montagne
16e552298c Refactor: Core: ID's 'namemap' used to generate unique ID names.
Note: This commit is essentially non-behavioral change, expect in some
fairly rare edge cases.

This commit does a few things:
* Move the whole BKE_main_namemap code to modern C++.
* Split API calls to work with the global namemap, or the local ones.
* Simplify and make the code easier to follow and understand.
* Reduce 'default' memory usage by using growing BitVector for numeric
  suffix management, instead of a fixed 1K items.
* Fix inconsistent handling of 'same base name and numeric suffix,
  different name' issues (e.g. 'Foo.1' and 'Foo.001'), see
  `re_create_equivalent_numeric_suffixes` new unittest.
* Fix completely broken handling of `global` namemaps. This was
  (probably!) OK so far because of their currently very limited
  use-cases.

It also adds a few minor improvements to existing behavior (essentially
in exotic rare edge cases):
* Names that get too long are now only shortened by one char at a time,
  trying to modify the requested base name as little as possible.
* Names that are short, but for which all the manageable numeric suffixes
  are already in use, are extended with an (increasing)  number, instead
  of being shortened.

This work also allowed to detect a few (apparently harmless?) bugs in
existing code, which have been fixed already in 4.4 and main, or in this
commit as well when they depend on changes in namemap code itself.

About performances: This commit introduces a minor slow-down. Some tests
heavily relying on this code (like `bl_id_management` and `blendkernel`
e.g.) get slightly slower (resp. about 1% and 5%). This seems to come
mostly from the added complexity to handle correctly multiple different
names with the same base and numeric suffix value ('Foo.1' and
'Foo.001', but also in the global namemap context where IDs from
different libraries can have the same name).

Pull Request: https://projects.blender.org/blender/blender/pulls/135199
2025-02-28 17:58:58 +01:00
Bastien Montagne
87a4c0d3a8 Refactor: Make Library.runtime an allocated pointer.
Move `Library.runtime` to be a pointer, move the related
`LibraryRuntime` struct to `BKE_library.hh`. Similar to e.g.
Mesh.runtime, that pointer is expected to always be valid, and is
allocated at readtime or when creating a new Library ID.

Related smaller changes:
* Write code now uses standard ID writing codepath for Library IDs too.
  * Runtime pointer is reset to nullptr before writing.
* Looking up a library by its absolute path is now handled through a
  dedicated utils, `search_filepath_abs`, instead of using
  `BLI_findstring`.

Pull Request: https://projects.blender.org/blender/blender/pulls/134188
2025-02-07 17:47:16 +01:00
Hans Goudey
7d6e098ca1 Cleanup: Remove unused includes in blenkernel
Pull Request: https://projects.blender.org/blender/blender/pulls/133688
2025-01-28 15:27:34 +01:00
Bastien Montagne
dbadc1c71c Fix part of #128420: invalid handling of full orphaned libraries in management code.
Reset the 'hierarchy index' runtime `temp_index` value for all library IDs.
This prevent the assert to be triggered when trying to rebuild libraries
hierarchy and there are some orphaned (i.e. not used by anything) library IDs
around.
2024-10-08 17:02:51 +02:00
Jacques Lucke
d74d8ceb23 Cleanup: move BKE_packedFile.h to C++
Part of #103343.
2024-08-08 15:13:20 +02:00
Bastien Montagne
a882d289fe Cleanup: Unused vars in non-assert release builds. 2024-07-03 15:14:18 +02:00
Bastien Montagne
ce84e5f1a2 Core: Make Library IDs copyable.
There is no behavioral change expected from this commit.

This is a requirement for incoming rewrite of the PartialWrite code
(see #122061 and !122118).

Pull Request: https://projects.blender.org/blender/blender/pulls/122118
2024-07-01 15:26:31 +02:00
Bastien Montagne
6426de4489 Core: IDManagement: Refactor how 'never unused' IDs are defined.
A few ID types are considered as 'never unused' in Blender (UI related
ones, the Libraries and the Scenes). Local IDs of this type are always
considered as used, even if no other ID links to them.

This was previously fairly weekly defined and implemented (mainly in the
writefile code and the 'tag unused' libquery functions).

This commit formalize this characteristic of ID types by adding a new
`IDTYPE_FLAGS_NEVER_UNUSED` flag, and using this in the few places in
the code that handle unused IDs.
2024-05-24 17:43:22 +02:00
Jacques Lucke
936fb7488e Cleanup: move runtime data to Library.runtime
Having a better separation between runtime and non-runtime data makes
it easier to reason about the code.

Pull Request: https://projects.blender.org/blender/blender/pulls/120271
2024-04-08 13:08:36 +02:00
Campbell Barton
a8cc6bb75b Cleanup: spelling in comments 2024-02-26 10:23:52 +11:00
Bastien Montagne
b42dc08452 Merge branch 'blender-v4.1-release' 2024-02-22 19:56:59 +01:00
Bastien Montagne
1dca5af712 Core: Libraries: Fix library parenting when libraries are deleted.
So far, when deleting a library (either explicitely, or through e.g.
relocation), its dependencies would get a `nullptr` parent, and
therefore become 'directly used' libraries.

This commit adds a new util to rebuild the libraries hieararchy, and
calls it when a Library ID is deleted.

NOTE: While logic is somewhat similar to what liboverride resync does to
sort the libraries by indirect levels
(`lib_override_libraries_index_define`), there are some key differences
here, notably the fact that if a library has a valid `parent` pointer,
it is not replaced, even if a 'better' parent (less indirect library)
could be found.
2024-02-22 19:25:59 +01: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
9e4129feeb Cleanup: unused includes in source/blender/blenkernel
Remove 397 includes.
2024-02-13 11:32:38 +11: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
Bastien Montagne
af5731ce03 Cleanup: Move BKE_idtype.h to Cpp header BKE_idtype.hh 2024-01-20 19:17:36 +01:00
Bastien Montagne
03c1cc4310 Cleanup: Move BKE_lib_query header to Cpp era. 2024-01-18 12:21:19 +01:00
Hans Goudey
3e76a1a6c2 Cleanup: Move BKE_lib_id.h to C++ 2024-01-15 12:44:14 -05:00
Bastien Montagne
fa25a286d8 Refactor: BKE: Move BKE_library header to full CPP. 2023-12-05 11:53:55 +01:00
Bastien Montagne
3acb64e7ac BKE_main: move header to be a fully CPP one.
Pull Request: https://projects.blender.org/blender/blender/pulls/115681
2023-12-01 20:38:54 +01:00
Bastien Montagne
dad1eea511 Move BKE_main_idmap and BKE_main_namemap to be fully cpp headers.
NOTE: `BKE_main.h` is currently used by `writeffmpeg.c`, so not trivial
to make it a full CPP header file for now.

Pull Request: https://projects.blender.org/blender/blender/pulls/115485
2023-11-27 18:09:27 +01:00
Damien Picard
e3fc935349 I18n: disambiguate and extract a few messages
Extract:
- Sculpt filter types from the Sculpt menu. Some of these types use a
  custom label, different  from those defined in the operator RNA,
  which was never extracted.
- "Today" and "Yesterday" from the file browser modification date.
- All name_plural from IDs, as these are used in the UI to list which
  data block is to be removed, when calling outliner.orphans_purge.

Disambiguate:
- "Area", meaning the measurement of a surface as opposed to a place.

Some messages reported by Satoshi Yamasaki in #43295.

Pull Request: https://projects.blender.org/blender/blender/pulls/113912
2023-10-19 21:39:58 +02:00
Bastien Montagne
1a4225d746 Fix (studio-reported) missing clearing of 'need resync' library tag.
The `Library.tag` data is supposed to be runtime only, so needs to be
cleared when reading data from blendfile.

This fixes the 'need resync' status of a library staying around forever
once set, annoying visual warning in the Outliner.
2023-09-06 17:14:46 +02:00
Bastien Montagne
b53c7a804a Readfile: Replace the 'lib_link' specific code by generic usage of foreach_id.
The `lib_link` callback cannot always be fully replaced/removed, as in
some case it is also doing some validation checks, or data editing based
on the result of lib_linking internal ID pointers.

The callback has been renamed for that purpose, from `read_lib` to
`read_after_liblink`. It is now called after all ID pointers have been
fully lib-linked for the current ID, but still before the call to
`do_versions_after_linking`.

This change should not have any behavioral effect. Although in theory
the side-effect of this commit (to split lib linking itself, and the
validation/further processing code) into two completely separated steps
could have some effects, in practice none are expected, and tests did
not show any changes in behavior either..

Part of implementing #105134: Removal of readfile's lib_link & expand code.
2023-08-24 16:33:31 +02:00
Bastien Montagne
8bb5916183 Readfile: Replace the 'expand' specific code by generic usage of foreach_id.
The `expand` callback is 'trivial' to replace, since it is only iterating
over ID pointers and calling a callback.

The only change in behavior here is that some pointers that were not
processed previously will now be.

In practice this is not expected to have any real effect (usually
the IDs used by these pointers would have been expanded through other
usages anyway). But it may solve a few corner cases, undocumented issues
though.

Part of implementing #105134: Removal of readfile's lib_link & expand code.
2023-08-23 16:44:56 +02:00
Bastien Montagne
7a0a406ff8 Core: foreach_id: add optional support for deprecated ID pointers.
This commit adds a new option flag to the lib_query foreach_id code,
which will make deprecated ID pointers to be processed as well.

NOTE: Currently there is no report to the callbakcs about the fact that
it is processing a deprecated ID. This can be easily added later if it
becomes necessary.

Part of implementing #105134: Removal of readfile's lib_link & expand code.
2023-08-22 17:47:57 +02:00
Campbell Barton
246292f486 Cleanup: various non-functional changes (mainly for C++)
- Remove redundant void, struct.
- Remove redundant parenthesis.
- Use STR_ELEM(..)
- Use function style casts.
2023-07-20 11:55:34 +10:00
Jacques Lucke
129f78eee7 Blenkernel: move to C++
Also see #103343.

Couldn't move two files yet:
* `softbody.c`: The corresponding regression test fails. It seems like the
  conversion to C++ changes floating point accuracy, but it's not clear where that happens exactly.
* `writeffmpeg.c`: Is a bit more complex to convert because of the static array in `av_err2str`.

Pull Request: https://projects.blender.org/blender/blender/pulls/110182
2023-07-17 10:46:26 +02:00