Commit Graph

3730 Commits

Author SHA1 Message Date
Campbell Barton
f7ce3a23fe Cleanup: quiet GCC parentheses warning 2024-12-13 09:01:54 +11: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
YimingWu
bda221ef2e Fix #131711: Grease Pencil: Null check when getting material passes
The material returned by `BKE_object_material_get` could be nullptr when
the material is somehow not a grease pencil material and this situation
needs to be handled. This is likely caused by faulty file from previous
verisons.

Pull Request: https://projects.blender.org/blender/blender/pulls/131714
2024-12-12 17:04:21 +01:00
Jacques Lucke
54f8ef12d8 Fix: crash when using subdiv modifier on curves
This only affected the drawing of the modifier UI, not the actual evaluation.

There was a missing check for the object type before retrieving the data from it.
2024-12-12 14:23:54 +01:00
Hans Goudey
50585b8131 Fix #131749: Missing text for operator buttons
Missing change of nullptr to std::nullopt after a recent cleanup.
2024-12-11 10:07:59 -05:00
Hans Goudey
363bc88ee7 Cleanup: Remove unnecessary unique_ptr usage for Line Art runtime
There is no need for this to be a unique pointer, the set can just be
stored directly.

Pull Request: https://projects.blender.org/blender/blender/pulls/131632
2024-12-10 22:05:54 +01:00
Hans Goudey
7baa22b49d Cleanup: Correct usage of std::unique_ptr in Line Art code
`.release()` is technically fine but semantically wrong here. First,
release is meant to take ownership from the unique_ptr, meaning
at best it's "weird" to not do anything with the pointer afterwards.
Second, the runtime struct with the unique_ptr was just default
constructed, which means the unique_ptr will be empty anyway.
2024-12-10 22:05:53 +01:00
Hans Goudey
7c97088fb2 Cleanup: Use proper type instead of void for line art runtime struct 2024-12-10 22:05:53 +01:00
Hans Goudey
282dd0c5c0 Cleanup: Fix copyright year in MOD_lineart.hh 2024-12-10 22:05:53 +01:00
Hans Goudey
03fd5fc58e Cleanup: Various C++ cleanups in MOD_lineart.hh
- C++ headers shouldn't have everything inside of `extern "C"`
- `typedef` and `struct` keywords are unnecessary in C++
2024-12-10 22:05:53 +01:00
Jacques Lucke
53ea147a51 Fix #131598: avoid relying on node tree update code being run before dependency graph is build
This avoids assuming that `BKE_ntree_update_main` has run on a node tree before
the depsgraph is build. The update code already finds the dependencies to
determine if a relations update is necessary or not. To avoid detecting these
dependencies again (which requires iterating over all the nested nodes), they
were cached on the node group so that they can be used when the depsgraph is
build.

However, since the update code does not run in all necessary cases yet
(#131598), this does not work currently. This patch fixes the situation by
removing the optimization of not having to find all dependencies again when the
depsgraph is build.

This optimization can be introduced again after we can be more sure that the
node tree update code runs whenever the node tree changes (which is what #131665
tries, but requires more discussion).

Pull Request: https://projects.blender.org/blender/blender/pulls/131685
2024-12-10 17:52:44 +01:00
YimingWu
7f8b811a42 Fix #131681: Grease Pencil: Build modifier concurrent mode div by zero
There could be strokes that have zero lengths (a dot), in this case a
NaN factor was given to the final build function, leading to invalid
index when accessing arrays. Now `get_stroke_factor` will return either
0.0f or 1.0f (depending on input factor) when stroke has zero total
length.

Pull Request: https://projects.blender.org/blender/blender/pulls/131683
2024-12-10 17:19:10 +01:00
Falk David
b0c3836280 Cleanup: Grease Pencil: Use ensure_vertex_group kernel function
Use the `bke::greasepencil::ensure_vertex_group` function instead
of a local static copy of the same function.
2024-12-10 11:53:55 +01:00
Lukas Tönne
c77933e748 Fix potentially incorrect index when looking up layer hints for GP crazyspace
The layer mask used by the armature modifier can be incomplete, in which case
the indices may not match the edit hints list of layer data. The actual
layer index must be used instead.

Also fixes a build error on Win64 ARM which cannot compile a parallel_for_each
over an index range.

Pull Request: https://projects.blender.org/blender/blender/pulls/131620
2024-12-09 17:05:42 +01:00
Jacques Lucke
205d480219 Fix #131598: handle missing linked data blocks in Geometry Nodes modifier 2024-12-09 13:42:47 +01:00
Lukas Tönne
0d8f040c8b Fix #130945: Grease Pencil: Crazyspace support in sculpt mode
Grease Pencil v3 did not have crazyspace support yet. Without this sculpting on
deformed geometry (e.g. on top of an armature modifier) will yield incorrect
offsets because the tool writes to original data based on deformed positions.

This patch adds computation of local deformation matrices which are stored in
the `GeometryComponentEditData`. Those matrices are then used to convert local
deformation of the evaluated geometry back to a deformation of the original
geometry. All the relevant sculpt tools support the crazyspace correction now,
using the `compute_orig_delta` helper function.

Computing the deformation matrices should happen alongside modifier evaluation
for any deforming modifier. This has been implemented for the armature modifier,
others can be added.

A fallback implementation for curves could also be added for modifiers that
don't have an easy way to calculate local transformation. A "natural"
orientation for both the original and deformed positions is calculated, then the
difference yields deform matrices. For meshes the approach is to use the surface
normal and a stable tangent space. For curves the common local coordinate frame
based on parallel transport might be used.

Currently crazyspace correction for the _Clone_ tool does not work because of
#131496.

Pull Request: https://projects.blender.org/blender/blender/pulls/131499
2024-12-09 12:33:44 +01:00
YimingWu
4cf82e62a4 Fix #131530: LineArt: Fix crash when copying empty object_dependencies
Line Art modifier `runtime->object_dependencies` can be empty when first
loaded, this can be triggered when loading as library overrides. This
fix guards this kind of situation.

Pull Request: https://projects.blender.org/blender/blender/pulls/131591
2024-12-09 09:55:43 +01:00
Hans Goudey
1b3955bc91 Fix #131574: Crash displaying modifier vertex group UI
Caused by 21aef81714.
2024-12-08 10:41:18 -05: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
Jacques Lucke
b36bf15e28 Geometry Nodes: improve detecting data-block dependencies
Previously, the data-block dependencies were always detected in
`update_depsgraph` in `MOD_nodes.cc`. This would only be called when something
called `DEG_relations_tag_update` before. We don't want to trigger a depsgraph
rebuild after each operation in the node editor, as that would be expensive.
However, that also meant that we often had to add data-block dependencies that
are not actually used, but might be used if the user changed e.g. a link. A
typical example for that is a object socket that has a default value, but the
socket is also linked.

Now, the dependencies referenced by the node tree are collected by the node tree
update code which runs after all changes. This way we can detect whether the
dependencies have changed. Only if they have changed, a depsgraph rebuild is
triggered. This now allows also taking into account the mute status of nodes and
whether an input is linked.

There are still more things that could be taken into account. Most obviously
whether a node is connected to an output. This can be done later. The most
tricky aspect here is probably that we also have to consider all viewer nodes as
output, because at the time the node runs, it's not known which viewer will
actually be used (which depends on other editors).

This also cleans up some special cases we had for e.g. the scene time node where
we always had to trigger a depsgraph rebuild when it was added/removed because
of its time dependence. This is now part of a more general system.

This fixes #109219.

Pull Request: https://projects.blender.org/blender/blender/pulls/131446
2024-12-05 18:02:14 +01:00
Jacques Lucke
5926654756 Fix: Geometry Nodes: crash when accessing runtime data while baking
Some editors are not redrawn while baking, but the properties editor currently
is and therefore needs this special check.

Eventually, we should rename or split the `is_rendering` flag to make it
more obvious that it also means baking.
2024-12-04 20:00:37 +01:00
Hans Goudey
22c13cfd28 Cleanup: Avoid reformatting geometry nodes property names, use fmt 2024-12-04 12:38:00 -05:00
Hans Goudey
af79b4e7b5 Cleanup: Use constexpr for geometry nodes string, avoid .c_str() 2024-12-04 12:38:00 -05:00
Hans Goudey
f9b627d29c Mesh: Move custom normals to a generic attribute
Move `CD_CUSTOMLOOPNORMAL` to the newly added
`CD_PROP_INT16_2D` generic attribute type. This is similar to
previous commits moving specific custom data types.

The attribute name is `custom_normal`. When the attribute with
that name is on the face corner domain, the code will interpret it
as stored in the existing deformation-invariant spherical coordinate
space.

The API remains the same, with the additional opportunity to edit
custom normal data as an attribute directly (which admittedly is fairly
unintuitive currently).

See #130484.

Pull Request: https://projects.blender.org/blender/blender/pulls/130689
2024-12-04 16:06:36 +01:00
Hans Goudey
024d7d12e2 Mesh: Move BVH storage to shared cache system
Avoid rebuilding BVH trees when meshes are copied.
Similar to the other uses of the shared cache system,
this can arbitrarily improve performance when meshes
are copied but not deformed and BVH building is the
main bottleneck. In a simple test file I got a 6x speedup.

The amount of code is also reduced and the system is
much simpler overall-- built out of common threading
patterns like `SharedCache` with its double-checked lock.
RAII is used in a few places to simplify memory management
too.

The downside is storing more `SharedCache` items in the
mesh runtime struct. That has a slight cost when copying
a small mesh many times, but we have ideas to improve that
in the future anyway (#104327).

Pull Request: https://projects.blender.org/blender/blender/pulls/130865
2024-12-04 00:17:17 +01:00
Pratik Borhade
74f212fae2 Fix #130922: GN: Hide empty panel in modifier UI
`interace_panel_has_socket` should return true when panel has
at least a socket of type input or hidden in modifier. That way, panel
drawing code won't be executed.

Pull Request: https://projects.blender.org/blender/blender/pulls/130958
2024-12-01 07:37:06 +01:00
YimingWu
73b7e8e256 Fix #131049: Line Art: Prevent stroke generation in locked target layer
Line art will not be able to insert any drawings into a locked target
layer, this fix prevent such situation from crashing Blender.

Pull Request: https://projects.blender.org/blender/blender/pulls/131073
2024-11-29 06:08:19 +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
YimingWu
00f61f0913 Fix #130904: Grease Pencil: Build modifier additive mode issues
Grease pencil build modifier additive mode has two problems that is
causing crashes and wrong build result when drawing in additive mode:

- Not assigning `dst_to_src_curve` for previously built curves.
- The way `previous_drawing` was acquired was wrong, this gives a zero
  stroke count for additive build mode, which prevented the crash while
  not in drawing mode (not on key frame), but is in fact incorrect for
  the algorithm.

This PR handles these problems and additive mode now works correctly
and without crashes while drawing new frames.

Pull Request: https://projects.blender.org/blender/blender/pulls/130952
2024-11-26 11:00:48 +01:00
Bastien Montagne
4bf5a2f5cb Cleanup: PointerRNA: Remove 'C-style' zero-initializations.
These are useless now that PointerRNA has explicit default values, and
become a problem when real constructors are added to this struct. Simply
use the default empty value initialization instead.

Pull Request: https://projects.blender.org/blender/blender/pulls/130927
2024-11-25 19:09:56 +01:00
YimingWu
5628c4f587 Fix: Grease Pencil: Ensure no bezier curves for offset modifier
Ensure no bezier curves for offset modifier, this makes it consistent
with the rest of the grease pencil modifiers for now and we will make
bezier support for the rest of the modifiers later.

Pull Request: https://projects.blender.org/blender/blender/pulls/130901
2024-11-25 13:31:04 +01:00
YimingWu
a3bdd0ce70 Fix #130691: Grease Pencil offset modifier missing position change tag
A `drawing.tag_positions_changed();` is needed after deforming strokes,
otherwise viewport will use outdated drawing batches.

Pull Request: https://projects.blender.org/blender/blender/pulls/130900
2024-11-25 12:37:11 +01:00
Campbell Barton
0de8ae8046 Cleanup: spelling in comments 2024-11-25 13:24:46 +11:00
YimingWu
d37a855973 Fix #130569: Grease Pencil tint modifier should use gradient alpha
Grease pencil tint modifier in gradient mode did not do alpha mix with
the original stroke color, making original color completely black even
when gradient color has alpha. Now fixed.

Pull Request: https://projects.blender.org/blender/blender/pulls/130575
2024-11-21 13:42:02 +01:00
Jacques Lucke
e62aa986b2 Format: use fmt::format correctly with runtime format strings
The `fmt::format` can process the format string at compile time. Currently, we
don't seem to be using that as we don't use `FMT_STRING`. Starting with C++20,
that will be the default though, and one has to explicitly opt out in places
where the string is not known at compile time using `fmt::runtime(...)`.
Currently, our code does not compile as C++20 because of that. Unfortunately, we
have many places with runtime format strings, because of i18n.

Pull Request: https://projects.blender.org/blender/blender/pulls/130392
2024-11-20 10:41:29 +01:00
ernst-ellert
73a3ebea56 Fix #129389: Lineart modifier updates when camera changes
The bug occurred when the user changed the camera of the scene.
The lineart modifier was not updating when changing the camera, but only
when changing other elements in the scene or moving the camera.

This is resolved by adding a depsgraph update for scene parameters, such
as when changing the camera.

Testing:
Add two cameras, add a Grease Pencil Collection Line Art, go into camera
perspective view and then switch to the other camera.
The Grease Pencil Line Art now updates automatically.

Co-authored-by: YimingWu <chengdulittlea@noreply.localhost>
Pull Request: https://projects.blender.org/blender/blender/pulls/129935
2024-11-20 04:47:05 +01:00
Iliya Katueshenock
ae0ab14716 Cleanup: BLI: Binary search first_if and last_if utils
Cleanup to simplify code by using common terms like _first_ and _last_ in context
of predicate applying in a range just like we do for spans and range containers.

Pull Request: https://projects.blender.org/blender/blender/pulls/130380
2024-11-19 11:05:57 +01:00
YimingWu
911ccac5f8 Fix #130198: GPv3 build modifier timing for nature drawing speed
GPv3 build modifier in "Nature Drawing Speed" mode didn't finish
building a frame when the time it took to draw those strokes by hand is
greater than the frame duration. Previous fix #129894 is only effective
for "Number of Frames" build mode. This fix moved the timing scaling
into `get_build_factor` and `get_factor_from_draw_speed` for more
granulated control in different modes.

Pull Request: https://projects.blender.org/blender/blender/pulls/130199
2024-11-19 05:16:16 +01:00
Sean Kim
c88c2bfda9 Cleanup: Convert BKE_multires.hh enum to enum class
Pull Request: https://projects.blender.org/blender/blender/pulls/130363
2024-11-16 23:16:37 +01:00
Hans Goudey
0684639e1b Cleanup: Grease Pencil: Remove indirect includes from headers
To avoid unnecessary header parsing during compilation.

Pull Request: https://projects.blender.org/blender/blender/pulls/130285
2024-11-14 22:07:19 +01:00
Falk David
9dfcc506fc Merge branch 'blender-v4.3-release' 2024-11-12 18:56:59 +01:00
YimingWu
2e82f95237 Fix: LineArt: Cache mechanism fixes
The cache mechanism for line art is changed during migration to GPv3,
however the code path failed to handle following cases which could lead
to a few problems:

- Line art cache isn't deleted after last line art modifier because it
  coule be hidden, causing memory leaks.
- A modifier inside a multiple line art modifier sequence that doesn't
  use cache would prematurely delete line art cache, causing subsequent
  line art modifier to give empty result.
- When the first line art modifier is hidden (in viewport/render), the
  cache is not created correctly, leading to crashes.

Now the new code logic addresses these problems properly by:

- Making sure the last visible line art modifier deletes cache.
- Giving a fresh cache pointer for modifiers that doesn't use global
  cache.
- Line art cache is correctly ensured when there are modifiers that
  are hidden

Pull Request: https://projects.blender.org/blender/blender/pulls/129953
2024-11-12 18:51:45 +01: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
Falk David
c8211b23c7 Refactor: Add CurvesGeometry::is_empty() function
Previously, some places used `curves.points_num() == 0` some other
places `curves.curves_num() == 0` to check if the geometry is empty.

Rather than having these two ways, add an `is_empty()` function
that replaces all these different checks.

Also update the curves geometry tests to use this function.

Pull Request: https://projects.blender.org/blender/blender/pulls/130168
2024-11-12 14:46:24 +01:00
Lukas Tönne
dbbacbffaf Merge branch 'blender-v4.3-release' 2024-11-11 17:12:17 +01:00
YimingWu
37ec4b5430 Fix #129883: GPv3: Build modifier frame timing is not correct
When the duration of a frame is shorter than the build time specified in
the modifier, build modifier should shorten the build time to allow the
frame to be fully built within the frame duration. This fix made the
timing behaviour the same as GPv2.

Pull Request: https://projects.blender.org/blender/blender/pulls/129894
2024-11-11 16:53:39 +01:00
Falk David
2a129f8762 Merge branch 'blender-v4.3-release' 2024-11-11 11:02:35 +01:00
Falk David
01db47b82c Fix #129766: GPv3: Fallback to "frames" mode in build modifier for natural drawing speed
The issue was that if the `delta_time` attribute didn't exist, the drawing
would appear immediatley.
In case we don't have any drawing speed information, the fix
makes it so that we fallback to use the number of frames
to build the strokes.

Pull Request: https://projects.blender.org/blender/blender/pulls/130035
2024-11-11 10:39:23 +01:00