Commit Graph

24926 Commits

Author SHA1 Message Date
Sybren A. Stüvel
7cd3f2aabb Refactor: Anim, prepare for slotted Action support to quaternion eval
Refactor to prepare for slotted action support to the evaluation of
quaternion F-Curves.

Since slotted Actions store F-Curves in an array, you cannot iterate over
them any more via the `ListBase` pointer `fcurve.next`. Quaternion
evaluation code has been refactored to work on a span of F-Curves instead
of just getting the first one.

For now, slotted Actions just evaluate their first slot only. A future
commit will add a slot handle parameter to evaluate the correct slot.
2024-09-13 12:34:48 +02:00
casey bianco-davis
1df3388fae GPv3: Create weights on draw for new strokes.
Implements the legacy  `weight_data_add` button for GPv3.

Note: This PR properly accounts for the bone's transformation when applying so that the stroke does not appear to teleport after drawing, unlike the legacy system.

Pull Request: https://projects.blender.org/blender/blender/pulls/119302
2024-09-13 11:15:31 +02:00
Campbell Barton
81e2ccbf2b Cleanup: spelling in comments 2024-09-13 10:56:26 +10:00
Hans Goudey
d64f62e4fa Sculpt: Update BVH node bounds in deformation loops
Updating the node bounds just after deforming the vertices in the
node is faster because the position data is still fresh in CPU caches.
Updating it later on means all the other nodes have been processed
in the meantime which will evict that position data from the caches.

This results in a 1.11x improvement in the brush benchmark timing,
from 0.495s to 0.438s on a Ryzen 7950x (best of 5 runs).

As part of the change, the update tagging has completely moved
to each brush implementation. This continues the process of
making each brush more independent.

Part of #118145.

Pull Request: https://projects.blender.org/blender/blender/pulls/127536
2024-09-12 23:45:52 +02:00
Hans Goudey
dd9b3e4fac Refactor: Sculpt: Remove vertex to face map from SculptSession
Just retrieve it from the mesh as necessary, it's already cached there.
Part of #118145.
2024-09-12 15:47:11 -04:00
Hans Goudey
43476712cf Refactor: Sculpt: Remove SculptSession mesh topology array references
Part of #118145.
2024-09-12 15:36:58 -04:00
Hans Goudey
e751b512ce Refactor: Sculpt: Remove SculptSession Depsgraph pointer
Part of #118145.
2024-09-12 15:32:45 -04:00
Hans Goudey
a19760678e Fix: Crash running sculpt brush performance benchmark
The normals were not allocated before the brush code starts, which is
necessary to store the initial normals in the undo step, among other
things. Previously normals were calculated as part of building the PBVH.
That doesn't make sense anymore because that process shouldn't change
the mesh. For now just add the recalculation in a code path called by
`BKE_sculpt_update_object_for_edit`, called at the beginning of each
stroke, and other places.
2024-09-12 14:51:34 -04:00
Hans Goudey
13f179a9c0 Cleanup: Add utility function to sum offset indices group sizes
I've done this a few times and would have benefited from a utility
function for it, apparently it's done in a few more places too. The
utilities aren't multithreaded for now, it doesn't seem important
and often multithreading happens at a different level of the call
stack anyway.

Pull Request: https://projects.blender.org/blender/blender/pulls/127517
2024-09-12 20:28:35 +02:00
Falk David
f68910092b GPv3: Parent armature with empty weights
Implements setting the armature parent and generating
vertex groups for the bones in the armature.

Note: This does not implement the `Envelope` or `Automatic Weights` options.

Pull Request: https://projects.blender.org/blender/blender/pulls/127515
2024-09-12 20:25:27 +02:00
Hans Goudey
1e22f364f8 Sculpt: Replace automasking sculpt attribute API usage
Current the automasking code stores temporary data as geometry
attributes (except for multires where that doesn't work) in order to
persist the cached factors for cavity and occlusion accross multiple
strokes. However, the benefits of this aren't clear, compared to
improving the performance of these calculations. It's also the last
usage of the sculpt attribute API which we plan to remove. The system
is also hard to understand, to make a more solid cache of automasking
values it would be better to start from scratch.

This commit removes the sculpt attribute API and the automasking stroke
ID system, and moves the cached factors to be cached per stroke rather
than more permanently.

Pull Request: https://projects.blender.org/blender/blender/pulls/127470
2024-09-12 20:06:21 +02:00
Jacques Lucke
bde6f888e2 Geometry Nodes: speedup joining many geometries
Joining many geometries was O(n^2) because of deduplication of the same
components was not done using a map. My test file that generates 1000
stars in a repeat zone got 10x faster, but it's possible to create a file for any
speedup.
2024-09-12 17:49:21 +02:00
Hans Goudey
5ff4e5fcb9 Sculpt: Avoid rebuilding draw vertex buffers for visibility changes
Use the possibility from ad7d7212c1
to make changes to visibility a bit snappier.
2024-09-12 11:39:55 -04:00
Lukas Tönne
49965841bb Fix: GPv3: Armature deform using the wrong vertex group list
Grease Pencil armature deformation has to use the correct
`vertex_group_names` list from the `Curves` (i.e. drawings) rather than
the names from its parent `GreasePencil` data block.

The ancient armature deformation code used a `defbase` list (`ListBase`
of type `bDeformGroup`) from the object via `BKE_id_defgroup_list_get`.
This function does not have enough information to determine the correct
vertex groups for GPv3, and it's use inside supposedly generic code is
highly questionable.

This patch removes the `defbase` lookup inside
`armature_deform_coords_impl` and instead passes an explicit list of
vertex group names to be used for resolving indices. We already have
context in every place this is called to determine the correct vertex
groups, without having to make assumptions down the line based on just
the object type.

Pull Request: https://projects.blender.org/blender/blender/pulls/127509
2024-09-12 17:35:35 +02:00
Sybren A. Stüvel
367cceaab8 Anim: Make it possible to enter/exit NLA tweak mode on slotted Actions
Properly track Action and Slot assignment when entering/exiting NLA
tweak mode.

This doesn't properly sync the length of the NLA strip when exiting
tweak mode. This and more NLA work is tracked at #127489.

Pull Request: https://projects.blender.org/blender/blender/pulls/127498
2024-09-12 16:48:02 +02:00
Sybren A. Stüvel
3417934eff Anim: add Action Slot assignment to NLA strip
For an NLA strip to use a slotted Action, it needs to specify which slot
to use in that action. This is now handled by two new properties on the
strip in DNA & RNA: `action_slot_handle` and `action_slot_name`.

These serve the same purpose as their counterparts on the `AnimData`
struct.

Note that this commit does NOT add NLA evaluation support for slotted
Actions. It merely allows assigning them. Evaluation, tweak mode
support, etc. will be implemented in future commits.

Pull Request: https://projects.blender.org/blender/blender/pulls/127359
2024-09-12 14:08:16 +02:00
Hans Goudey
b2d201cbea Cleanup: Remove outdated SubdivCCG masks assert
Missed in 1618448abd.
2024-09-11 16:35:14 -04:00
Sean Kim
ab5ce3061a Fix #127357: Expand operator crashes when cursor is not on mesh
Prior to 0df133559c, the `active_vert_` property was only ever
invalidated if the entire `SculptSession` was refreshed, even if the
cursor moved off of the mesh or if the underlying mesh type changed.

The Sculpt Expand operator was dependent on this value not being cleared
to still behave in a reasonable way from a user perspective

This commit introduces a new variable, `last_active_vert_` and
corresponding accessor methods to `SculptSession` to specifically fix
this usecase. When the active vert is cleared, if it had a valid value,
we store it in the new `last_active_vert_` variable.

Pull Request: https://projects.blender.org/blender/blender/pulls/127433
2024-09-11 19:48:31 +02:00
Hans Goudey
1618448abd Sculpt: Store multires grids data in separate arrays
For `SubdivCCG`, replace the dynamic array-of-struct data with separate
arrays for positions, normals, and masks. This decreases memory
bandwidth requirements for loops that only access one of these arrays.
It also significantly simplifies data access, making it more similar
to mesh data where it can just be accessed with indices.

In a simple test this change speeds up the multires sculpt brush
benchmark by 32%. It also slightly reduced BVH build time by about 12%.

In practice this means completely replacing usage of `CCGElem` for
`SubdivCCG`. The struct is still used in the older subsurf baking code
though. Removing that is a much trickier task that doesn't have short
term benefits.

Part of #118145.

Pull Request: https://projects.blender.org/blender/blender/pulls/127262
2024-09-11 15:54:46 +02:00
Jacques Lucke
e18aa65973 Fix: quit.blend is not saved as recovery file
This was broken in efb511a76d. The memfile-undo step always had
this flag set, but the non-memfile file-write did not.
2024-09-11 14:38:04 +02:00
Sergey Sharybin
a9208e9f8e Fix #126825: Crash on duplicating child collection of liboverride hierarchy
Pass CollectionChild explicitly, so the duplication code is not confused
about where the to copy light linking settings from.

Pull Request: https://projects.blender.org/blender/blender/pulls/127237
2024-09-11 11:19:23 +02:00
Campbell Barton
e00fed43e6 Cleanup: redundant struct declarations 2024-09-11 16:25:25 +10:00
Hans Goudey
853269aeb0 Sculpt: Make multires BVH build similar to mesh
Structure the multires grids PBVH build to be similar to meshes,
splitting face indices into groups instead of grid indices. This
removes one step of indexing, decreases the amount of temporary
data, and allows sharing the majority of the implementation with
the mesh BVH build.

In a test file with 4 million faces at multires level 1, this reduced
BVH build time from 149 to 70 ms. The improvement will be
significantly lower for higher subdivision levels.

Pull Request: https://projects.blender.org/blender/blender/pulls/127429
2024-09-10 22:46:04 +02:00
Iliya Katueshenock
0b7090ca37 BKE: Utilities to create curves and point clouds without attributes
Same as #118297.

Pull Request: https://projects.blender.org/blender/blender/pulls/120368
2024-09-10 21:48:59 +02:00
Hans Goudey
a4b42daf80 Refactor: Sculpt: General cleanups to ensure PBVH function 2024-09-10 15:39:03 -04:00
Hans Goudey
7cd6b7175f Sculpt: Parallelize max face size reduction during grid BVH build 2024-09-10 15:29:53 -04:00
Hans Goudey
883568c0b1 Cleanup: Improve face size variable name 2024-09-10 15:29:53 -04:00
Hans Goudey
8cd80b0fac Cleanup: Correct comment and add note
I think the limit is unnecessary because I can't think of a good
reason for it and there is no reasoning in the git history.
2024-09-10 15:29:53 -04:00
Falk David
942499382d GPv3: Vertex Paint Mode
This adds the vertex paint mode and all of the tools
from GPv2:
 * Average
 * Blur
 * Draw
 * Replace
 * Smear

Pull Request: https://projects.blender.org/blender/blender/pulls/125674
2024-09-10 18:56:31 +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
Sybren A. Stüvel
636d83fbea Refactor: convert BKE_nla.h to C++
Rename `BKE_nla.h` to `BKE_nla.hh` and remove C-isms.

No functional changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/127395
2024-09-10 13:41:01 +02:00
Iliya Katueshenock
957330043f Refactor: Attributes: support different source and destination domains in propagation utilities
Pull Request: https://projects.blender.org/blender/blender/pulls/127026
2024-09-10 12:59:03 +02:00
Sybren A. Stüvel
ed0cfe7312 Anim: fix crash drawing Action groups when built without Action Slots
Fix a crash that happens when drawing Action groups in the dope sheet, when
Blender is built without experimental features (hence without Action
slots) and it has loaded a blend file with slotted Actions.

Basically a pointer needs to be set to `nullptr` when reading such a file,
as it ensures that the rest of the code treats the group as "from a legacy
Action".

Pull Request: https://projects.blender.org/blender/blender/pulls/127339
2024-09-10 10:59:29 +02:00
Hans Goudey
dc4ff79f64 Cleanup: Formatting
VS Code doesn't stage the whitespace changes apparently.
2024-09-09 09:56:13 -04:00
Hans Goudey
6462216ef7 Cleanup: Sculpt: Simplify arguments to BVH build function
Pass the already partitioned span face indices rather than the full
array and separate start and end indices.
2024-09-09 09:50:00 -04:00
Hans Goudey
eee34de007 Sculpt: Simplify and optimize BVH build node partitioning
Use `std::partition` instead of implementing something similar
ourselves. This is much easier to understand, and it's also much
faster and requires less memory during the build.

I observed a change in the runtime building a 16 million face
BVH from 492 to 389 ms, a 1.27x improvement (with a Ryzen
7950x).

`std::partition` is not multithreaded. I expect there would be
some improvement from multithreading this, at least for the
first few splits.

Currently this only applies to Mesh sculpting.

Pull Request: https://projects.blender.org/blender/blender/pulls/127332
2024-09-09 15:16:28 +02:00
Hans Goudey
1bc0ec1b80 Sculpt: Improve mesh BVH build time by storing less temporary data
Each time the face bounds are used after they're initially computed, we
recompute the center of the bounds. We only use the actual bounds to
calculate the bounds of each node to decide how it should be split.
This commit changes to store the bounds centers instead, and just use
the full bounds as a type for the parallel reduction.

In a test with a 16 million face grid on a Ryzen 7840U, I observed a
1.28x decrease in BVH build time, from 1072 to 836 ms.

I didn't apply a similar change to multires grids BVH building because
it's not clear the same bottleneck exists due to the lower ratio of
"primitives" (grids) to final subdivided vertices.
2024-09-08 16:54:51 -04:00
Hans Goudey
2952498724 Cleanup: Sculpt: Add debug timing for multires BVH build 2024-09-06 12:13:04 -04:00
Sybren A. Stüvel
fe96a0c3f6 Anim: fix crash when writing empty action groups
It was just a missing 'else' clause around some should-have-been-
conditional code.

Pull Request: https://projects.blender.org/blender/blender/pulls/127241
2024-09-06 14:33:57 +02:00
Campbell Barton
2954323c2d Fix missing depsgraph tags after removing an object from a collection
Follow up to fix for #127213, resolving the bug in other contexts.
2024-09-06 12:05:33 +10:00
Hans Goudey
e05d55f4c9 Cleanup: Remove unnecessary PBVH free function
Just call `reset()` directly instead.
2024-09-05 14:51:19 -04:00
Hans Goudey
c6e426fc8f Refactor: Sculpt: Pass object to sculpt session free function 2024-09-05 14:46:35 -04:00
Hans Goudey
d33e708343 Refactor: Sculpt: Use function to access PBVH
Part of #118145.
In the future we want to move the ownership of the BVH tree to the
original mesh rather than `SculptSession`, in order to persist it
across some more general non-topology changing operations like
node tools. The first step of that change is replacing all places
that used `SculptSession::pbvh` for access with a function.
2024-09-05 14:16:40 -04:00
Hans Goudey
4c8e1fbeca Cleanup: Reduce indentation in sculpt object update function 2024-09-05 14:07:16 -04:00
Hans Goudey
39e653d479 Cleanup: Sculpt: Add geometry index accessor functions to node structs
Add `.faces()`, `.verts()`,`.all_verts()`, and `.grids()` functions to nodes.
Don't change BMesh data access yet. More complex const correctness
makes that situation more difficult.

Pull Request: https://projects.blender.org/blender/blender/pulls/127201
2024-09-05 20:07:03 +02:00
Hans Goudey
5e63435e74 Sculpt: Store faces instead of triangles in BVH
Currently each sculpt BVH node stores the indices of its triangles.
It also stores triangles of vertex indices local to the node, and also
potentially the indices of the face corners in the node.

The problem with this is that the leaf nodes store plenty of redundant
information. The triangles in each face aren't split up between multiple
nodes, so storing triangle instead of face indices is unnecesssary. For
the local vertex triangles, there is also duplicate information-- twice
the number of indices as necessary for quad meshes. We also often need
a node's faces, which is currently done with a triangle to face map
using 4 bytes per triangle.

This "double storage" results in extra processing too. For example,
during BVH builds we need to combine twice the number of "Bounds"
objects for a quad mesh. And we have to recalculate a node's face
indices every time we want them.

This commit replaces the PBVH triangle indices with face indices, and
replaces the local vertex triangles array by using a `VectorSet` to store
each node's vertex indices. This results in significant performance and
memory usage improvements.

|                   | Before   | After    | Improvement |
| ----------------- | -------- | -------- | ----------- |
| BVH build time    | 1.29 s   | 0.552 s  | 2.3x        |
| Brush stroke time | 3.57 s   | 2.52 s   | 1.4x        |
| Memory usage      | 4.14 GiB | 3.66 GiB | 1.3x        |

All testing is done with a 16 million vertex grid and a Ryzen 7950x.

My guess is that the brush stroke time is improved by the added sorting
of node vertex indices, and by the overall increase in memory bandwidth
availability for mesh data. Personally I'm pleasantly surprised by the
whole improvement, since I usually try to avoid hash table data
structures for this sort of use case. But a lookup into this set ends up
just being a boolean and with an array lookup, so it's quite cheap.

Pull Request: https://projects.blender.org/blender/blender/pulls/127162
2024-09-05 16:21:43 +02:00
Jacques Lucke
871b25b219 Geometry: generalize attribute filters beyond just for anonymous attributes
This introduces the concept of an #AttributeFilter. It's used to tell a geometry
algorithm which attributes it should process/propagate and which can be ignored.

We already had something similar before named
`AnonymousAttributePropagationInfo`. However, as the name implies, this was
specific to anonymous attributes. This had some downsides:
* A lot of code had to be aware of the concept of anonymous attributes even if
  it did nothing special with anonymous attributes.
* For non-anonymous attributes we often had a separate `Set<std::string> skip`
  parameter. It's not nice to have to pass two kinds of filters around and to
  have to construct a `Set<std::string>` in many cases.

`AttributeFilter` solves both of these downsides.

Technically, `AttributeFilter` could also just be a `FunctionRef<bool(StringRef
attribute_name)>`, but that also has some issues:
* The `bool` return value is often ambiguous, i.e. it's not clear if it means
  that the attribute should be processed or not. Using an enum works better.
* Passing function refs around and combining them works, but can very easily
  lead to dangling references.
* The default value of a `FunctionRef` is "empty", i.e. it can't be called. It's
  generally more nice to not have a special case for the default value. Now the
  default `AttributeFilter` propagates all attributes without any extra handling
  on the call-site.

Pull Request: https://projects.blender.org/blender/blender/pulls/127155
2024-09-05 11:33:35 +02:00
Christoph Lendenfeld
a661a7bf89 Refactor: Move Pose code out of the kernel
Move the functions
* `BKE_pose_apply_action_selected_bones`
* `BKE_pose_apply_action_all_bones`
* and `BKE_pose_apply_action_blend`

out of the blender kernel and into animrig.

This will allow solving #126969 without having to include
animrig code in the blender kernel.

Pull Request: https://projects.blender.org/blender/blender/pulls/126978
2024-09-05 10:41:34 +02:00
Campbell Barton
acde253b9d Fix invalid MeshRuntime::deformed_only for evaluated edit-meshes
Between 2.93 & 3.2 a regression was introduced where evaluated
meshes from the modifier stack would always have their deformed_only
value set to false.

Resolve by enabling for meshes returned by
BKE_mesh_wrapper_from_editmesh and ensure the value is kept when the
modifier duplicates the cage mesh.

Resolves #123138.
2024-09-05 15:56:39 +10:00
Hans Goudey
c6fe321718 Fix: Sculpt: Data race saving BMesh node original data
Replace modification of vertex indices with a VectorSet for local
index calculation, allowing proper parallelization of the saving.
2024-09-04 21:35:37 -04:00