Commit Graph

312 Commits

Author SHA1 Message Date
Bastien Montagne
f6a9f082e9 Core: Add data-level support for new 'system IDprops' storage for Blender 4.5 forward compatibility with 5.0 blendfiles
This mainly adds DNA level IDProp storage for system properties, their
handling in data management code, and the forward-versioning code
copying back content from system properties into 'all-in-one' single
IDProperties storage, for data types that will support both in Blender
5.0.

There is no user-facing changes expected here.

Part of #123232.

Pull Request: https://projects.blender.org/blender/blender/pulls/139257
2025-06-06 11:49:54 +02:00
Campbell Barton
98c0a6c8fe Cleanup: resolve unused variable warning in release builds 2025-05-23 09:20:11 +10:00
Brecht Van Lommel
ee1a460f42 Revert "Refactor: Add and use MEMCPY_STRUCT_AFTER_CHECKED"
Needs more review, see #138830.

This reverts commit 5ac631d02b.
2025-05-20 17:32:49 +02:00
Brecht Van Lommel
5ac631d02b Refactor: Add and use MEMCPY_STRUCT_AFTER_CHECKED
Check if either the memory is zero or already matches the default value,
and copy. This simplifies a common pattern to a single line.

Preparing for default initializers in DNA (#134531).

Pull Request: https://projects.blender.org/blender/blender/pulls/138830
2025-05-20 13:27:08 +02:00
Campbell Barton
7883412cde Cleanup: rename Curve::type -> ob_type, remove BKE_curve_type_get
It's not common for object data to reference it's object type
so name the struct member to make this clear.

Also remove BKE_curve_type_get which is no longer needed.
2025-05-20 10:11:56 +00:00
Campbell Barton
8fea423e00 Fix #139133: Crash entering edit mode for curve/text objects
- Make Curve::type the source of truth for the curve type,
  instead of Curve::vfont, since it's possible for this to be
  set to null from RNA which effectively changed it's type.
  See #138730.

- Update objects to match the curve type on file read.

  Without this, an object may link to a curve in another file which
  can be replaced by a curve data-block of a different type.

  Note that updating the object type was already being done
  when reloading library data and setting object data,
  just not on file load.

Ref !139137
2025-05-20 19:28:49 +10:00
Bastien Montagne
3957b4a11f Cleanup: Improve documentation of BKE_object/collection_duplicate functions.
No functional change expected here.
2025-05-19 20:16:43 +02:00
Hans Goudey
8ac48880e7 Point Cloud: Move "Random" default primitive creation to operator
Previously all new point clouds created in the main database would
have the random 400 points. Now that's only the point cloud created
from the add menu.

Similar to f98d74c80d.

Pull Request: https://projects.blender.org/blender/blender/pulls/138685
2025-05-10 02:24:18 +02:00
Hans Goudey
f90e448c6a Cleanup: Use blender::Mutex for various static mutexes
Change almost all `static ThreadMutex` to `static blender::Mutex`.
See b7a1325c3c.

Pull Request: https://projects.blender.org/blender/blender/pulls/138556
2025-05-07 19:32:00 +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
Jacques Lucke
e8d1491e62 Refactor: Depsgraph: simplify query API further
* Remove `DEG_get_evaluated_object` in favor of `DEG_get_evaluated`.
* Remove `DEG_is_original_object` in favor of `DEG_is_original`.
* Remove `DEG_is_evaluated_object` in favor of `DEG_is_evaluated`.

Pull Request: https://projects.blender.org/blender/blender/pulls/138317
2025-05-02 15:08:29 +02:00
Hans Goudey
600380cd98 Fix #137794: Ignore curve radius for legacy curve object bounds
Caused by 06f6d77979.

Legacy curve objects have not taken the radius into account in the
past. Better to stick with that behavior and only affect the new
curve object type. This only affects non-instanced legacy curve
objects; generally generated curves are presented to the depsgraph
iterator as the new object type.

Pull Request: https://projects.blender.org/blender/blender/pulls/137852
2025-04-29 16:16:44 +02:00
Hans Goudey
685894b665 Cleanup: Use Span argument for KeyBlock conversion function 2025-04-22 09:39:52 -04:00
Brecht Van Lommel
388a21e260 Refactor: Eliminate various void pointers passed to MEM_freeN
It's safer to pass a type so that it can be checked if delete should be
used instead. Also changes a few void pointer casts to const_cast so that
if the data becomes typed it's an error.

Pull Request: https://projects.blender.org/blender/blender/pulls/137404
2025-04-21 17:59:41 +02:00
Jacques Lucke
f442c86197 Depsgraph: improve type safety when getting evaluated or original ID
The goal here is to avoid having to cast to and from `ID` when getting the
evaluated or original ID using the depsgraph API, which is often verbose and not
type safe. To solve this, there are now `DEG_get_original` and
`DEG_get_evaluated` methods which are templated on the type and use a new
`is_ID_v` static type check to make sure it's only used with valid types.

This allows removing quite some verbosity on all the call sites. I also removed
`DEG_get_original_object`, because that does not have to be a special case
anymore.

Pull Request: https://projects.blender.org/blender/blender/pulls/137629
2025-04-17 13:09:20 +02:00
Johnny Matthews
633b8d30db Fix #135071: Vertex Parenting: Provide Index Access Options
When using vertex parenting, an option for using the parent object
final evaluated indices is exposed in the Object Properties: Relations
panel. This allows the calculation of the parent vertex position to
ignore the the CD_ORIGINDEX layer and instead use the final indices
that may have been altered by the node tree evaluation.

The indices that will be used for the vertex parenting are also exposed
to the UI in the same panel, allowing them to be altered after the
vertex parent has been created.
2025-03-21 23:43:48 +01:00
Bastien Montagne
7aced80eec Cleanup: blenkernel: 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/136134
2025-03-20 11:25:19 +01:00
Campbell Barton
126cfbeb82 Refactor: rename bPoseChannel::size to scale
Match the name of the RNA as well as Object::scale, also rename
associated flags.

Ref !136151
2025-03-19 22:12:47 +00:00
Brecht Van Lommel
9526fe9993 Refactor: Add BKE_mesh_new_from_object argument to ignore subdivision
Pull Request: https://projects.blender.org/blender/blender/pulls/135895
2025-03-19 14:08:37 +01:00
Campbell Barton
b77d77af40 Refactor: add utility object & pchan setters, respecting protected flags
Add "set" functions for location, scale & rotation that leave
protected channels untouched.

Ref !136104
2025-03-18 20:36:57 +11:00
Clément Foucault
e08c64d68e Cleanup: DRW: Remove DrawData
These have been replaced by better alternatives overtime.

Pull Request: https://projects.blender.org/blender/blender/pulls/136073
2025-03-17 15:16:07 +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
Christoph Lendenfeld
6e4413d50f Merge branch 'blender-v4.4-release' 2025-02-25 12:14:52 +01:00
Christoph Lendenfeld
5100a80f7f Fix #110650: Drivers not removed if removing their container
This applies to modifiers, constraints and shape keys.
Any driver on such data was not removed with it,
leaving invalid drivers on objects.

With this patch, the drivers are removed, but animation is left untouched.
This is because animation might be reused somewhere else and we don't
want to introduce potential side effects there.

This also adds unit tests for the fixed cases

Pull Request: https://projects.blender.org/blender/blender/pulls/134511
2025-02-25 12:11:15 +01:00
Pratik Borhade
d961f8f9ec Grease Pencil: Remove legacy object type references
Remove GP legacy obtype and unused functions
Few hidden bugs are fixed with that:
- Outliner drag-drop for GP material/effect elements now works
- Correct stats are shown in status bar.

Pull Request: https://projects.blender.org/blender/blender/pulls/133957
2025-02-25 10:46:27 +01:00
Hans Goudey
947658d1b2 Refactor: Simplify CustomData functions by requiring ImplicitSharingInfo
Previously we generally expected CustomData layers to have implicit
sharing info, but we didn't require it. This PR clarifies that we do
require layers with non-null data to have implicit sharing info. This
generally makes code simpler because we don't have to have a separate
code path for non-shared layers. For example, it makes the "totelem"
arguments for layer freeing functions unnecessary, since shared data
knows how to free itself. Those arguments are removed in this PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/134578
2025-02-17 19:44:54 +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
fc1fe4e78c Cleanup: Rename object materials "test" functions
"test" wasn't descriptive. Rename that part to "sync_length".
Also expose documentation from the function implementation
to describe what the functions do.

Pull Request: https://projects.blender.org/blender/blender/pulls/134058
2025-02-04 17:46:08 +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
Falk David
d413b0064f Cleanup: Move BKE_material.h to C++
The `BKE_material.h` is only renamed to `.hh` to preserve
the history of the file. Changes to the file are done in
the following commit.
2025-01-09 18:11:46 +01:00
Philipp Oeser
5d8ba173c4 Fix #132629: Generating asset previews for grease pencil is broken
Reason is that `BKE_camera_view_frame_fit_to_scene` cannot handle grease
pencil data [it used to, that was once added in 80d0b68290 but lost in
the switch to GPv3 (see 5c57e24fea)].

So to resolve, add back support for grease pencil in
`BKE_camera_view_frame_fit_to_scene` which is similar to what we do for
getting the bounding box.

Pull Request: https://projects.blender.org/blender/blender/pulls/132733
2025-01-07 13:09:30 +01:00
Hans Goudey
c62a032fab Cleanup: Use C++ math API for some object dimensions and bounds functions
To enable a fix and further cleanup in this area.
2024-12-20 19:29:18 -05:00
Jacques Lucke
95852bf42b Fix #107882: subdivided mesh not available on curve
The type check there should not be necessary anymore nowadays. It looks like it
might have been necessary when it was introduced in
eed45d2a23. Back then the object was still passed
into `BKE_mesh_wrapper_ensure_subdivision`.

Pull Request: https://projects.blender.org/blender/blender/pulls/131857
2024-12-17 15:34:16 +01:00
Sybren A. Stüvel
efd2e762f7 Refactor: Core, give the IDWALK_CB_… enum an explicit name
Give the `IDWALK_CB_…` enum an explicit name:
`LibraryForeachIDCallbackFlag`. This way the flags are type-safe, and
it's known where values come from. This is much preferred (at least by
me) to just having `int flags`.

Uses of `0` have been replaced with `IDWALK_CB_NOP` as that has the same
value and is of the right type.

One invalid use of `IDWALK_NOP` was detected by this change, and is
replaced by `IDWALK_CB_NOP`.

This change might be incomplete; I gave the enum a name, fixed the
compiler errors, and then also updated assignments like `int cb_flag =
cb_data->cb_flag`. I might have missed some assignments to `int` though.

No functional changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/131865
2024-12-13 17:32:24 +01:00
Sybren A. Stüvel
7d5143e94c Revert "Refactor: Core, give the IDWALK_… enums an explicit name"
This reverts commit 3ef748789d. It was
landed too hastily, my apologies.

Pull Request: https://projects.blender.org/blender/blender/pulls/131813
2024-12-12 20:03:27 +01:00
Sybren A. Stüvel
3ef748789d Refactor: Core, give the IDWALK_… enums an explicit name
Two commits that basically do the same thing for two `enum`s: give
them a name.

- the `IDWALK_…` enum → `LibraryForeachIDFlag`.
- the `IDWALK_CB_…` enum → `LibraryForeachIDCallbackFlag`.

This way the flags are type-safe, and it's known where values come
from. This is much preferred (at least by me) to just having `int
flags`.

Uses of `0` have been replaced with `IDWALK_NOP` and `IDWALK_CB_NOP`,
as those have the same value and are of the right type.

One invalid use of `IDWALK_NOP` was detected by this change, and is
replaced by `IDWALK_CB_NOP`. And another one in the opposite
direction.

This change might be incomplete; I gave the enum a name, fixed the
compiler errors, and then also updated assignments like `int cb_flag =
cb_data->cb_flag`. I might have missed some assignments to `int`
though.

No functional changes.

----------

I intend to land this PR as its two separate commits. I just put them in the same PR so the buildbot can handle them in one go, and we don't have a stack of highly relatled PRs.

In the future this could also apply to the `IDWALK_RET_…` enum. This one I left out, though, because a proper cleanup there would also have to include their ambiguity on whether they are bitflags (like the enums in this PR) or not. Their values and the code in `BKE_lib_query_foreachid_process()` implies they are bitflags, but in practice they are never or'ed together and just used as discrete values.

Pull Request: https://projects.blender.org/blender/blender/pulls/131803
2024-12-12 17:28:28 +01:00
Hans Goudey
953c4f1599 Cleanup: Remove references to legacy Grease Pencil object
These are converted on startup to the new type. There are still
some references left, mostly where it looked like there still needs
to be changes to properly deal with the new object type.
2024-11-27 09:17:16 -05:00
Hans Goudey
fdb1bec6c8 Fix #130811, #130842: Non-mesh object edit mode crash evaluated mesh
The "is edit mode" checks in the draw module have been simplified
to just check the object mode. We need to be a bit more careful to
avoid retrieving the original mesh from a non-mesh object.

This commit improves the "get pre-modified mesh" function with
better comments and checks that reflect the relatively recent cases
where the original and evaluated geometry data types don't match.
It's always called with a mesh object too.

Pull Request: https://projects.blender.org/blender/blender/pulls/130850
2024-11-24 17:43:55 +01:00
Clément Foucault
08ed51d5db Cleanup: BKE: Const correctness for BKE_object_dimensions_get 2024-11-24 15:29:26 +01:00
Hans Goudey
839108f623 Fix #113377: Pass edit mesh pointer through modifiers
Currently replacing the Mesh during evaluation with the object info node
can cause us to use invalid original indices when the source object is
in edit mode. This is really a more fundamental problem though: we have
no way to tell whether an evaluated mesh actually corresponds to the
object's original mesh.

This commit changes to explicitly propagating the edit mesh pointer
through copied and changed meshes during modifier and nodes evaluation,
instead of just blindly copying the edit mode pointer from the original
mesh to the evaluated mesh. A benefit of not writing to the evaluated
mesh means it can be shared, potentially offering a future performance
improvement for uses of the object info node.

When we detect an invalid correspondence between the evaluated/original
meshes, we skip extracting the cage mesh's data and skip extracting edit
mesh data from the evaluated object.

This commit also moves the source of "object is in edit mode" truth in
the draw module from whether the evaluated mesh has an edit mode pointer
to the object's mode flag. That's a simplification that's also helpful
to reduce the strong linking between BMesh and edit mode.

Pull Request: https://projects.blender.org/blender/blender/pulls/120999
2024-11-21 16:42:00 +01:00
Hans Goudey
97be9b603b Cleanup: Grease Pencil: Remove unnecessary legacy modifier writing
Since all legacy Grease Pencil modifier are converted to regular modifiers
in versioning, we should never be in a position where we need to write the
old modifiers anymore.

Pull Request: https://projects.blender.org/blender/blender/pulls/130388
2024-11-18 14:33:20 +01:00
Hans Goudey
f879d23237 Cleanup: Use const for evaluated pre-modified mesh accessor
Conceptually this shouldn't be changed after it's created for the
first time.
2024-11-14 15:45:44 -05:00
Bastien Montagne
b325142d17 Merge branch 'blender-v4.3-release' 2024-11-12 16:55:40 +01:00
Bastien Montagne
0b3a7cbe69 Cleanup: Move BKE_image.h and related headers to C++.
NOTE: This also required some changes to Cycles code itself, who is now
directly including `BKE_image.hh` instead of declaring a few prototypes
of these functions in its `blender/utils.h` header (due to C++ functions
names mangling, this was not working anymore).

Pull Request: https://projects.blender.org/blender/blender/pulls/130174
2024-11-12 16:53:54 +01:00
Hans Goudey
312052112a Cleanup: Remove references to legacy Grease Pencil type
See #123468.

Pull Request: https://projects.blender.org/blender/blender/pulls/130151
2024-11-11 19:11:03 +01:00
Bastien Montagne
b1d044bfb8 Merge branch 'blender-v4.3-release' 2024-11-11 16:17:04 +01:00
Bastien Montagne
ac75e37c8e Fix #130113: Copying Object ID never copies its preview.
This was added 7 years ago as 'safe' preservation of previous behavior,
when ID copying was refactored and more control was added over its
behavior.

However, it was never removed since then, even though `NO_PREVIEW` flag
has been part of the `LOCALIZE` copying behavior since many years.

So time to remove this enforced bahevior and use the API as designed. If
this causes new issues, they will have to be fixed in code calling the
ID copy API (most likely by simply adding the `NO_PREVIEW` flag to the
copy options).
2024-11-11 16:13:37 +01:00
Hans Goudey
9a30cb0c1e Cleanup: Remove unused grease pencil legacy kernel functions
Also remove the bounds from DNA since it was just runtime data
and was no longer referenced.

See #123468.
2024-11-02 23:16:04 +01:00
Campbell Barton
15c207a294 Merge branch 'blender-v4.3-release' 2024-11-02 17:34:00 +11:00
Campbell Barton
4df285ccd5 Cleanup: move function comments into headers or implementation notes
For C/C++ doc-strings should be located in headers,
move function comments into the headers, in some cases merging
with existing doc-strings, in other cases, moving implementation
notes into the function body.
2024-11-02 17:27:09 +11:00