Commit Graph

286 Commits

Author SHA1 Message Date
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
Hans Goudey
77a7671f54 Cleanup: Avoid writing sculpt session runtime pointer to files
`SculptSession` is a runtime struct that should really be stored in
`ObjectRuntime` instead of `Object`. Writing pointers to it in files
is misleading because the struct itself isn't serialized.

Pull Request: https://projects.blender.org/blender/blender/pulls/129233
2024-10-31 17:48:57 +01:00
Campbell Barton
7a9d3e9973 Fix crash framing the camera to geometry in mesh edit-mode 2024-10-31 18:45:38 +11:00
Campbell Barton
f69fbb41c1 Fix #129225: Crash in modifiers & constraints with invalid enum values
Even though this is generally avoided, drivers don't prevent
invalid values being set. Further files from branches or files
written in the future may contain enum values not yet known.

Resolve by range checking enum values which are used to index arrays.
2024-10-22 15:56:58 +11:00
Falk David
1906446716 Fix: GPv3: Newly added objects don't have the Use Lights setting set
The issue was that the code checked for the `OB_GPENCIL_LEGACY`
type instead of `OB_GREASE_PENCIL`.
2024-10-18 18:09:10 +02:00
Lukas Tönne
5c57e24fea Cleanup: GPv3: Remove unused BKE functions from GPv2
Removes unused GPv2 functions in blenkernel.

Notes:
-  Functions for layer masks are still in use, but annotations never
  have layer masks in the first place. Would be good to remove the data
  structures so we can remove the functions too.
- Some multi-frame edit functions are also still nominally used, but
multi-frame editing is not an active feature for annotations. This
  should also be removed.

Pull Request: https://projects.blender.org/blender/blender/pulls/128709
2024-10-09 10:27:45 +02:00
Falk David
5f5b1b83d0 GPv3: Rename mode enum names and python identifiers
This renames the mode identifiers to be consistent with e.g. the context mode identifiers and other names used for the new Grease Pencil.

For `object.mode`:
* `PAINT_GPENCIL` -> `PAINT_GREASE_PENCIL`
* `SCULPT_GPENCIL` -> `SCULPT_GREASE_PENCIL`
* `VERTEX_GPENCIL` -> `VERTEX_GREASE_PENCIL`
* `WEIGHT_GPENCIL` -> `WEIGHT_GREASE_PENCIL`

For the internal `ob->mode` flag:
* `OB_MODE_PAINT_GPENCIL_LEGACY` -> `OB_MODE_PAINT_GREASE_PENCIL`
* `OB_MODE_SCULPT_GPENCIL_LEGACY` -> `OB_MODE_SCULPT_GREASE_PENCIL`
* `OB_MODE_VERTEX_GPENCIL_LEGACY` -> `OB_MODE_VERTEX_GREASE_PENCIL`
* `OB_MODE_WEIGHT_GPENCIL_LEGACY` -> `OB_MODE_WEIGHT_GREASE_PENCIL`

Resolves #127374.

Pull Request: https://projects.blender.org/blender/blender/pulls/128604
2024-10-04 19:20:00 +02:00
Bastien Montagne
22477956e2 Refactor: Move BPY main/public extern headers to proper C++ ones.
Pull Request: https://projects.blender.org/blender/blender/pulls/128081
2024-09-25 18:04:33 +02:00
Nathan Vegdahl
4bfa0de388 Anim: update some uses of listbases of fcurves
Because we're moving to layered actions, which don't store their
fcurves in a list base, we need to update the places that assume the old
listbase-based structure.

This commit addresses the low-hanging fruit where code was previously
using the `LISTBASE_FOREACH` macro on a listbase of fcurves and it was
fairly obvious how to correctly update the code with minimal changes.
Other cases that either weren't immediately obvious or required
non-trivial code changes (or both) have been left for future PRs.
Additionally, uses of the list base that didn't use `LISTBASE_FOREACH`
were not investigated as part of this PR, whether trivial to update or
not.

Ref: #123424
Pull Request: https://projects.blender.org/blender/blender/pulls/127920
2024-09-24 09:59:48 +02:00
Sybren A. Stüvel
3fdc9e9637 Refactor: convert BKE_action.h to C++
Move the contents of `BKE_action.h` into `BKE_action.hh` and remove
C-isms.

No functional changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/127407
2024-09-10 14:55:47 +02:00
Hans Goudey
220cf67172 Cleanup: Improve object argument name
These functions expect an evaluated object which wasn't clear.
2024-08-15 13:09:28 -04:00
Jacques Lucke
5861b078f7 Core: rename ID.flag and ID.tag values
Previously, values for `ID.flag` and `ID.tag` used the prefixes `LIB_` and
`LIB_TAG` respectively. This was somewhat confusing because it's not really
related to libraries in general. This patch changes the prefix to `ID_FLAG_` and
`ID_TAG_`. This makes it more obvious what they correspond to, simplifying code.

Pull Request: https://projects.blender.org/blender/blender/pulls/125811
2024-08-07 12:12:17 +02:00
Bastien Montagne
80948f43ca Refactor: BLO: Add array size parameter to BLO_read_pointer_array.
For some reason this was the only one of these 'read array' functions
with no such parameter.
2024-07-31 16:55:29 +02:00
Hans Goudey
a26819ad88 Fix #125400: Copy modifier to selected ignores modifier pinning
If we encounter this problem again it's probably worth extracting this
modifier addition to a helper function.
2024-07-29 10:19:18 -04:00
Falk David
0f42f277b7 Grease Pencil: Remove legacy modifiers
This removes the legacy Grease Pencil modifiers from the code.
These should have already been inaccessible from the UI and hidden from
the user. The modifiers have been reimplemented for the new GPv3
data structure.

On top of the modifier code, some other related things have been
removed as well:
 * Operators related to the legacy modifiers.
 * Keymaps for the legacy modifier operators.
 * Some bits of code that used modifier functions.

Some code has to be kept, because it is still used:
 * The core line art code, which is used by the new line art modifier. It's
    moved to `modifiers/lineart`.
 * The DNA structs for the legacy modifiers. They are still needed for
    conversion.
 * A few kernel functions for the modifiers are kept (also for conversion).

Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/125102
2024-07-29 10:37:29 +02:00
Sergey Sharybin
c309479912 Fix: Changing sculpt multires level erases sculpt changes
The code which is responsible for applying data from coordinate grids to
displacement grids could be run as part of modifier evaluation, hence
using the safe version of accessing mesh data was returning a nullptr.

Pull Request: https://projects.blender.org/blender/blender/pulls/123907
2024-06-28 16:36:56 +02:00
Jacques Lucke
e72730d763 Fix: assert when switching to sculpt mode
This is an alternative fix to #123524.

This is necessary, because `sculpt_update_object` is run after
the mesh is evaluated, but before the geometry depsgraph operation
is done. Only after this depsgraph node is done, `DEG_object_geometry_is_evaluated`
will return true.

This approach of `unchecked` methods has been preferred for now
over moving the call to `BKE_sculpt_update_object_after_eval`
to a separate depsgraph node or after depsgraph evaluation.
2024-06-21 15:19:10 +02:00
Jacques Lucke
ada367a0e9 Fix #119589: use-after-free when accessing not-fully-evaluated object geometry
While the evaluated result is not well defined, we expect Blender to not crash
when there are dependency cycles.

The evaluation of one object often takes the evaluated geometry of another
object into account. This works fine if the other object is already fully
evaluated. However, if there is a dependency cycle, the other object may not be
evaluated already. Currently, we have no way to check for this and were mostly
just relying on luck that the other objects geometry is in some valid state
(even if it's not the fully evaluated geometry).

This patch adds the ability to explicitly check if an objects geometry is fully
evaluated already, so that it can be accessed by other objects. If there are not
dependency cycles, this should always be true. If not, it may be false
sometimes, and in this case the other objects geometry should be ignored. The
same also applies to the object transforms and the geometry of a collection.

For that, new functions are added in `DEG_depsgraph_query.hh`. Those should be
used whenever accessing another objects or collections object during depsgraph
evaluation. More similar functions may be added in the future.
```
bool DEG_object_geometry_is_evaluated(const Object &object);
bool DEG_object_transform_is_evaluated(const Object &object);
bool DEG_collection_geometry_is_evaluated(const Collection &collection);
```

To determine if the these components are fully evaluated, a reference to the
corresponding depsgraph is needed. A possible solution to that is to pass the
depsgraph through the call stack to these functions. While possible, there are a
couple of annoyances. For one, the parameter would need to be added in many new
places. I don't have an exact number, but it's like 50 or so. Another
complication is that under some circumstances, multiple depsgraphs may have to
be passed around, for example when evaluating node tools (also see
`GeoNodesOperatorDepsgraphs`).

To simplify the patch and other code in the future, a different route is taken
where the depsgraph pointer is added to `ID_Runtime`, making it readily
accessible similar to the `ID.orig_id`. The depsgraph pointer is set in the same
place where the `orig_id` is set.

As a nice side benefit, this also improves the situation in simple cases like
having two cubes with a boolean modifier and they union each other.

Pull Request: https://projects.blender.org/blender/blender/pulls/123444
2024-06-20 15:24:38 +02:00
Hans Goudey
a6ecfe2f79 Cleanup: Rename DerivedMesh.cc and header
After recent commits, the .cc file is only used for actual object data
evaluation in the depsgraph, and the header is only used for the old
DerivedMesh data structure that's still being phased out.
2024-05-20 13:11:18 -04:00
Sybren A. Stüvel
6212c3c374 Fix #121161: Regression: Frame Selected Includes Hidden Bones
Refactor `BKE_armature_min_max()` so that it calls `BKE_pose_minmax(ob,
use_hidden=false)`. The former took neither bone visibility nor custom
bone shapes into account when computing the bounding box. Now these two
are unified, fixing the regression.

`BKE_armature_min_max()` is now basically a thin wrapper that uses more
modern C++ types in its signature. This will be cleaned up in a
follow-up refactor commit.

Another difference is that these functions return the AABB in different
coordinate spaces (object vs. world). This isn't done entirely correctly
(just transforming the two extreme points), but in a way that is
symmetrical with `BKE_object_minmax()`.

Pull Request: https://projects.blender.org/blender/blender/pulls/121739
2024-05-13 15:42:33 +02: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
Hans Goudey
809ed077ac Cleanup: Use const in some modifier related functions 2024-04-30 16:02:08 -04: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
Hans Goudey
d95b1f120b Mesh: Store BMEditMesh in shared pointer
The main motivation for this is that it's part of a fix for #113377,
where I want to propagate the edit mesh pointers through copied
meshes in modifiers and geometry nodes, instead of just setting the
edit mesh pointer at the end of the modifier stack. That would have
two main benefits:
1. We avoid the need to write to the evaluated mesh, after evaluation
  which means it can be shared directly among evaluated objects.
2. When an object's mesh is completely replaced by the mesh from another
   object during evaluation (with the object info node), the final edit
   mesh pointer will not be "wrong", allowing us to skip index-mapped
   GPU data extraction.

Beyond that, using a shared pointer just makes things more automatic.
Handling of edit mesh data is already complicated enough, this way some
of the worry and complexity can be handled by RAII.

One thing to keep in mind is that the edit mesh's BMesh is still freed
manually with `EDBM_mesh_free_data` when leaving edit mode. I figured
that was a more conservative approach for now. Maybe eventually that
could be handled automatically with RAII too.

Pull Request: https://projects.blender.org/blender/blender/pulls/120276
2024-04-18 13:52:20 +02:00
Campbell Barton
b03332a055 Cleanup: use BLI_assert_msg instead of checking string literals 2024-04-03 14:27:54 +11:00
Hans Goudey
82b88f130a Cleanup: Use const for evaluated cage meshes and related data
Also access the evaluated deform mesh with a function rather than
directly from object runtime data. The goal is to make it easier to use
implicit sharing for these meshes and to improve overall const
correctness.
2024-03-28 18:57:57 -04:00
Hans Goudey
931206d3dc Cleanup: Rename mesh face deformed edit position variables
Use standard naming similar to their `Mesh` counterparts.
2024-03-28 18:28:35 -04:00