Commit Graph

4839 Commits

Author SHA1 Message Date
Campbell Barton
7456d716f4 Fix #120811: Loop cut crash with symmetry enabled
Resolve regression introduced in [0].

[0]: 7f1b70ac50
2024-05-07 17:02:03 +10:00
Christoph Lendenfeld
08de3fa0b6 Anim: extract constant variables out of sorting loop
No functional changes expected.

This PR extracts the `IndexRange` of the `BeztMap` span and its `size()` call out
of the sorting loop. Doing this removes one `if` condition within the loop and gives a
small performance boost.
(Before: 0.93ms, After: 0.65ms average run of `sort_time_beztmaps`)

Pull Request: https://projects.blender.org/blender/blender/pulls/121267
2024-04-30 15:14:49 +02:00
Christoph Lendenfeld
c6c7d3d8c4 Anim: Graph Editor - use Map to update TransInfo pointers instead of searching
This is a performance improvement when moving a bunch
of keys on the same `FCurve` in heavy scenes.

When moving keys in such a way that the `BezTriple` array of the FCurve
has to be sorted, the pointers of `TransInfo` also have to be  updated.
This used to happen by doing a nested loop over all `BeztMap` and all `TransData2D`.
There was a bit of optimization with the
`blender::Vector<bool> adjusted` which stored if a `TransData2D` has been fixed yet.
But in general the complexity was still `BeztMap.size() * TransData.size()`.

There are two optimizations that can be done here.
* Skip any BeztMap if `old_index == new_index`.
If the Key is not going to move any pointers to it will still be valid.
* Use a `Map<float *, int>` built beforehand to quickly get
the `TransData2D` that needs updating instead of searching.
The `int` in this case is the index to the `TransData2D` array.

Doing this reduces the complexity to `BeztMap.size() + TransData.size()`.

Measurements of `beztmap_to_data`
| - | Before | After |
| - | - | - |
| Moving 1 key of 1 FCurve | ~24000 ns | ~5800ns |
| Moving ~1000 keys of 1 FCurve | 17ms | 0.02ms |

Measurements of `remake_graph_transdata`
| - | Before | After |
| - | - | - |
| Moving 1 key of 279 FCurves | 290ms | 22ms |
| Moving ~300 keys of 279 FCurves | 82 **SECONDS** | 80ms |

Test file used
https://download.blender.org/ftp/sybren/animation-rigging/heavy_mocap_test.blend

The deeper technical explanation.
`TransInfo` has an array of `TransData`.
`TransData` has pointers to the float arrays of a `BezTriple`.
The `BezTriple` array is sorted by swapping data,
meaning the `TransData` will now point to the wrong data in the array.
This has to be updated and we can do that by using the `BeztMap`.
This is all under the assumption that `BeztMap` is sorted in the exact
same way as `BezTriple` otherwise this method will fail.
But by doing it the same way, we can know at which
index the `BezTriple` is before and after sorting.
Now we just need to find the corresponding `TransData`.
That can be done by comparing pointers. The `BeztMap` stores the
`BezTriple` it represents and from it we can
get the pointers to its `vec` 0, 1 and 2. (key and handles)

Pull Request: https://projects.blender.org/blender/blender/pulls/120816
2024-04-30 10:46:48 +02:00
Christoph Lendenfeld
8b852f2ac2 Refactor: rename beztmap_to_data
No functional changes.

This just renames the function `beztmap_to_data` to
`update_transdata_bezt_pointers` to better represent what it is doing.

Pull Request: https://projects.blender.org/blender/blender/pulls/121125
2024-04-26 14:06:42 +02:00
Laurynas Duburas
12df5a68ba Curves: support transforming Bezier handles in edit mode
Allows user to transform Bezier handles.

Pull Request: https://projects.blender.org/blender/blender/pulls/120222
2024-04-26 09:32:26 +02:00
Christoph Lendenfeld
c464426475 Refactor: swap handle logic in Graph Editor transform code
This PR changes the `swap_handles` variable of the
`BeztMap` from `short` to `bool`.
The only reason it was a `short` was so that 0 could be
interpreted as "not checked" within the sorting loop.
Instead, I moved the checking for swapping to a separate loop.
That means the `BeztMap` array needs to be traversed one more time,
but given sorting might already do that multiple times that won't be
a performance issue
(plus we don't have the `if` within the sorting loop potentially messing up branch prediction).

In addition to that this PR also removes `prev_ipo` and
`current_ipo` from the `BeztMap` struct. Those were never used.

This is also partly a fix to restore 3.6 behavior.
With the move to C++, `swap_handles` was never initalized,
so the logic ` if (bezm->swap_handles == 0)` would always be false.
That resulted in the following behavior when
**rotating a bunch of keys 180deg** around their common center.

Pull Request: https://projects.blender.org/blender/blender/pulls/121076
2024-04-25 16:52:16 +02:00
Hans Goudey
ab3f05d3ec Cleanup: Move sculpt_transform.cc to C++ namespace 2024-04-24 08:19:57 -04:00
John Swenson
cff532e134 VSE: Implement Snapping to Markers
This patch adds the ability to snap strips to markers. Previously, there
only existed options to snap to hold offsets and the current frame.

This snap type works identically to other snapping options by checking
for the relevant bit (here `SEQ_SNAP_TO_MARKERS`) and adding the marker
frame numbers to `snap_data->target_snap_points` within
`seq_snap_target_points_build()`.

To enable `seq_get_snap_target_points_count()` to have access to marker
information, the current Scene object is now passed to the function.

Pull Request: https://projects.blender.org/blender/blender/pulls/120450
2024-04-23 01:54:14 +02:00
Laurynas Duburas
3d9519544d Transform: support properly transforming implicitly shared curves positions
The issue was that the transform code kept non-const pointers into the
position arrays of `CurvesGeometry` for an extended period if time and
changed the positions through those pointers. This is not safe, because
the underlying position array may become shared (e.g. with the
corresponding evaluated object), in which case it's not allowed to change
the position array anymore without making a copy.

Generally, the scope at which some code has multiple access to data
should be as small as possible to avoid this kind of issue.

The solution is to store the positions that are modified by the transform
code in a new array and to copy those back into the `CurvesGeometry`
in one go. This way, the program scope in which the positions may be
modified is more obvious and much smaller.

Pull Request: https://projects.blender.org/blender/blender/pulls/120824
2024-04-22 20:02:52 +02:00
Campbell Barton
fd589fdca4 Cleanup: various non functional C++ changes 2024-04-20 13:46:14 +10:00
Germano Cavalcante
f5f05c99c9 Fix: Snap with 'Backface Culling' skipping edges and vertices of faces in edit mode
After 1c77779160, the snap logic in Edit Mode became the same as in
Object Mode, so Backface Culling started to ignore edges and vertices
of faces seen from behind.
2024-04-19 09:47:49 -03:00
Germano Cavalcante
3fc29d8080 Fix #120239: Snap in edit mode is ignoring some self elements
Fix snapping issues caused by commit 1c77779160, where a mesh
representing the edited mesh was introduced.

Mesh snap to vertex now works in the following order:
- Snap to vertices of visible triangles
- Snap to vertices of loose edges
- Snap to loose vertices

The problem arises because in editing mode, faces whose vertices are
being transformed are ignored, marked as hidden in the snap, resulting
in the loss of some vertices in triangles.

The solution involves considering the edges and vertices of hidden
faces as loose elements since, despite being connected to faces, they
are still visible to snap. Two new types of BVHTree were created for
this purpose:

- BVHTREE_FROM_LOOSEVERTS_NO_HIDDEN
- BVHTREE_FROM_LOOSEEDGES_NO_HIDDEN

This modification addresses two related issues:
- snapping in edit mode to vertices and edges of a face being
  transformed
- snapping to mesh with hidden loose elements

Optionally, the first issue could be tackled separately by generating
BVHTrees within the snap system itself and storing them in a
`SnapCache_EditMesh *em_cache`, then passing this cache as a parameter
to the `snap_object_mesh` function.

Pull Request: https://projects.blender.org/blender/blender/pulls/120270
2024-04-18 16:48:19 +02:00
Germano Cavalcante
93e47ad9a8 Fix #120744: Shrink/Fatten Even with Alt not working
Continuation of 3d6bb6ce04

This 'alt' hotkey is captured in the modal map
`TFM_MODAL_PASSTHROUGH_NAVIGATE` in order to appear in the header.
But this modal map is not necessary.
2024-04-17 12:25:00 -03:00
Damien Picard
c306677119 I18n: extract and disambiguate a few messages
Extract
- Statuses for the external text editor
- Newly created enum node item
- Newly created plane track data
- Newly created custom orientation data
- Operator names in drag and drop menu (need to use operator's
  translation context)
- GN attribute statistic node inputs

Disambiguate
- Single-letter colors: A and B can mean Alpha and Blue, or simply A
  and B as in two operands in an operation
- Dissolve: issue reported by Tamar Mebonia in #43295
- Translate in the User Preferences. This introduces a new
  BLT_I18NCONTEXT_EDITOR_PREFERENCES ("Preferences") translation
  context
- Planar (reported by deathblood)
  This one is incomplete, because there is currently no way to
  disambiguate presets or GN fields. I don't see how either could be
  achieved cleanly.
  The former would need to define the context inside the preset and
  evaluate the file prior to showing it in the presets menu, which
  sound bad.
  The latter would need to introduce an additional string inside
  `FieldInput`s, which would be controversial given how little it
  would be used.

Remove
- Unused translation `iface_("%s")` in toolbar
- Remove obsolete N_() tags in a few node descriptions.

Pull Request: https://projects.blender.org/blender/blender/pulls/119065
2024-04-15 12:02:17 +02:00
Christoph Lendenfeld
fb22ee6f0c Refactor: BeztMap Array to C++ Vector
Instead of using `MEM_callocN` to create an array of `BeztMap`
use a `blender::Vector`. This has the advantage that we don't need to worry about
freeing the memory.
In addition to that it can be passed as a `Span`, removing the need to pass the
length as a separate argument.
Doing that also allows to use the C++ syntax for `for` loops.

This also gives a small performance boost
| Before | After |
| - | - |
| 288ms | 260ms |

Pull Request: https://projects.blender.org/blender/blender/pulls/120507
2024-04-11 11:47:15 +02:00
Amelie Fondevilla
d0d4bf2068 Fix #118509: GPv3: frames disappear during transform in the timeline
While selecting and transforming multiple grease pencil frames in the
timeline, frames would sometimes disappear. This happened when the
transformation overlapped, meaning when a frame replaced another moving
one in the timeline. The frames transformation was happening in place
and in series, and thus leaded to the initial position of the frame to
be removed, even if it was occupied by a freshly transformed framed.

This commit fixes the issue by storing two separate maps in the
transform data structure instead of one, one map to store the static
data, meaning the frames that are not affected by the transform, and
another one for the moving data, meaning the frames that are affected by
the transform.

Some changes were made to account for the potential duplication of the
frames (move + duplicate):
* the map of the duplicated frames was renamed to a more explicit name,
* when a duplication occurs, the original frame is stored in the static
  frames map, and the duplicate is stored in the moving frames map,
* thus the check for the duplicate flag of the operator is now done at
  the init step of the transform, instead of the update step, so that
  the maps are initialized accordingly.

Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/119337
2024-04-09 16:44:34 +02:00
Christoph Lendenfeld
8a79212031 Anim: thread remake_graph_transdata
On animations with high key counts, `remake_graph_transdata`
takes most of the compute time when moving keys.
This patch threads the loop over FCurves in that function to speed things up.

Test file with 10.000 keys per F-Curve
| - | Before | After |
| - | - | - |
| Moving 1 key of each FCurve |  ~2200ms | ~285ms |
| Moving a single key | ~0.70ms | ~0.72ms |

As demonstrated in the measurements, this speeds up the
case of modifying a lot of data, while not impacting the case
of modifying very little data.
The measurements were taken on an 8c/16t CPU.
The higher the thread count, the better the performance gain.

Measurements of `remake_graph_transdata` using the following test file.
https://download.blender.org/ftp/sybren/animation-rigging/heavy_mocap_test.blend

Pull Request: https://projects.blender.org/blender/blender/pulls/119497
2024-04-09 11:46:05 +02:00
Germano Cavalcante
727979c1a8 Fix #120366: Snap to Grid is affected by geometry occlusion
To maintain the previous and more useful behavior, disable the
occlusion test in the snap to gird.
2024-04-07 11:23:55 -03:00
Germano Cavalcante
115a925ffe Fix: Incremental snap not matching grid resolution
Caused by f0479e915f

`t->snap_spatial` is still required for Incremental snap.
2024-04-07 10:26:21 -03:00
Germano Cavalcante
1180a25c23 Fix #120245: Grid snap not working when constraining axis before moving
`sctx->grid.size` was only updated while the constraint was not
enabled.

This was causing division by zero.
2024-04-04 11:42:27 -03:00
Campbell Barton
7e9f7320e4 Cleanup: spelling in comments & comment blocks 2024-04-04 11:26:28 +11:00
Campbell Barton
52ce8d408f Cleanup: use const arguments & variables 2024-04-04 10:55:10 +11:00
Hans Goudey
935666a622 Fix #120104: Snap ignores evaluated geometry bounds
Previously the bounds were accessed on the original object.
That used to implicitly get the evaluated geometry's bounds,
but now that is an explicit choice.
2024-04-01 11:01:19 -04:00
Germano Cavalcante
ea3f938c07 Fix #120109: Grid snap crash when locking axis before base selection
The functionality of snap with constraints relies on the position of
the transformed object.

Previously, snap to grid with constraints was restricted to the Move
operation.
Consequently, the 'Set Snap Base' mode, as well as other transformation
modes, failed to compute the moved position.
As a result, it lacked support for snap to grid with constraints and
would even crash under such circumstances.

The solution involves eliminating the reliance on the Move operator and
instead calculating the position based on mouse position.
2024-04-01 11:22:03 -03:00
Campbell Barton
4365d0496a Cleanup: use a const pointer for unit-settings 2024-03-29 16:37:36 +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
Germano Cavalcante
5bdfec8d67 Fix: unhandled empty Optional in 'bounds_min_max()'
Continuation of fcfce8f69f
2024-03-28 18:59:33 -03:00
Campbell Barton
b2e00d1285 Cleanup: use const pointer arguments 2024-03-28 20:57:50 +11:00
Hans Goudey
c28db1f0a0 Cleanup: Use C++ namespace for object editors module
Move the public functions from the editors/object (`ED_object.hh`)
header to the `blender::ed::object` namespace, and move all of the
implementation files to the namespace too. This provides better code
completion, makes it easier to use other C++ code, removes unnecessary
redundancy and verbosity from local uses of public functions, and more
cleanly separates different modules.

See the diff in `ED_object.hh` for the main renaming changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/119947
2024-03-28 01:30:38 +01:00
Germano Cavalcante
f0479e915f Transform: Implement Snap to Grid mode
Addresses two improvements to `Snap to Grid` as suggested in #73993:
- Make 'Absolute Grid Snapping' a new Snap Mode
- Snap to Grid in Non-Side View performed at ground level

Implementation details:

- Snap to Grid has no cursor symbol, unless we are in `Set Snap Base`
  mode. Similar to the previous 'Absolute Grid Snap' behavior.
- In Non-Side view, Snap to Grid is performed at ground level.
- If `Snap Base` is `Closest`, Snap to Grid uses the transform pivot
  point instead. Similar to the previous 'Absolute Grid Snap' behavior.
- The "Absolute Grid Snap" option has been removed.

Pull Request: https://projects.blender.org/blender/blender/pulls/116109
2024-03-27 13:17:24 +01:00
Campbell Barton
155dae94d7 Cleanup: code-comments, use doxygen formatting & spelling corrections
Also move some function doc-strings from the implementation
to their declarations.
2024-03-26 17:55:20 +11:00
Germano Cavalcante
f66cb1e635 UI: rename 'Snap With' and 'Snap To' to 'Snap Base' and 'Snap Target'
Since the `Set Snap Base` feature has been implemented, it would be
convenient to reflect the use of the term `Snap Base` in other areas in
the UI.

Pull Request: https://projects.blender.org/blender/blender/pulls/119723
2024-03-25 13:35:52 +01:00
Hans Goudey
3805974b6f Refactor: Use C++ array for edit mesh looptris
Pull Request: https://projects.blender.org/blender/blender/pulls/119829
2024-03-23 17:43:38 +01:00
Hans Goudey
8b514bccd1 Cleanup: Move remaining GPU headers to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/119807
2024-03-23 01:24:18 +01:00
Brecht Van Lommel
b0b0510dbf Refactor: Access paint brush through accessor function
This will be used for brush assets in the future.

Ref #119801
2024-03-22 20:54:09 +01:00
Christoph Lendenfeld
6a55a126e9 Anim: Only sort FCurves that need it
Before this PR the sorting function would receive all FCurves from
the `anim_data` ListBase and sort them + recalculate the handles.

Considering we are already checking
IF an `FCurve` needs sorting we might as well use
that and limit the sorting to FCurves that actually need it.
Doing that gives the following performance uplift.

| - | Before | After |
| - | - | - |
| Moving 1 key only | 109ms | 0.72ms |
| Moving 1 key of each FCurve | ~2000ms | ~2000ms |

Pull Request: https://projects.blender.org/blender/blender/pulls/119735
2024-03-21 15:11:19 +01:00
Christoph Lendenfeld
adef64db06 Refactor: BeztMap struct
No functional changes.

The `BeztMap` struct is used when sorting Keyframes during transformations
in the Graph Editor.

Things that were changed:
* Removed unneeded `newIndex`. This was just the index of the
`BeztMap` in the array, which we already have since we iterate with a for loop.
* Access the `BezTriple` array by index instead of pointer offsets.
This makes it a bit easier to see what's happening.
* Renamed struct members to clarify their use.
* Remove forward declaration of certain variables (e.g. loop counter vars)

Pull Request: https://projects.blender.org/blender/blender/pulls/119733
2024-03-21 11:50:51 +01:00
Germano Cavalcante
24be7bd99e Fix #119716: snap in curve editing when mesh is generated by Geometry Nodes
In these cases, the Mesh is defined as an instance of the object.
These instances need to be ignored when in edit mode.
2024-03-20 23:46:55 -03:00
Campbell Barton
57dd9c21d3 Cleanup: spelling in comments 2024-03-21 10:02:53 +11:00
Germano Cavalcante
247524bb35 Fix: UV Edge Slide sometimes fails to detect correct direction
In this case, the situation in which edges share faces connected to
each other could fail as it could pass through a slide edge.
2024-03-15 10:37:59 -03:00
Campbell Barton
09666e1498 Fix #119387: Precision transform fails to activate
Regression in [0] caused precision fail to activate in the graph editor
and when pressing shift then control (#119395).

[0]: 060174cf14
2024-03-14 11:20:19 +11:00
Germano Cavalcante
f6a581e28a UV: Vert and Edge Slide UI improvements
Changes:
- Add Vert Slide and Edge Slide to 'UV -> Transform' menu.
- Add a separator for Vert Slide and Edge Slide in the context menu.
- Don't display the "Correct UVs" option in the Redo menu of UV Editor.
2024-03-13 12:16:19 -03:00
Germano Cavalcante
31745a53f4 Cleanup: early return & avoid compare strings unnecessarily
`transform_poll_property` can be smarter in the conditions.
2024-03-13 12:16:18 -03:00
Germano Cavalcante
a56a975760 UV: Enable 'Set Snap Base' feature
Just like for objects in 3D View, UVs can also benefit from the
`Set Snap Base` feature (key `B`).
2024-03-12 14:35:52 -03:00
Hans Goudey
c24568ed5c Cleanup: Use trailing underscores for private members 2024-03-12 09:50:32 -04:00
Melissa
aaadb5005e UV: Support Edge and Vert Slide
This commit adapts the existing Edge Slide and Vert Slide to work with
UVs as well.

It addresses [0] for the addition of an edge slide tool to the UV
Editor.

This feature allows users to slide UVs towards adjacent edges,
providing more convenient ways to edit UV maps.

[0]: https://blender.community/c/rightclickselect/66dbbc

Pull Request: https://projects.blender.org/blender/blender/pulls/119041
2024-03-12 10:15:55 -03:00
Germano Cavalcante
e0c26a19e6 Fix #119305: Edge slide is not working properly
This is a improved solution compared to 20dbcd8814

Caused by 930b11b0fe.

When checking edges that share faces between them, the `find_best_dir`
method cannot use edges that were added in the current loop.
2024-03-12 00:29:00 -03:00
Germano Cavalcante
976a8012d1 Fix: wrong conditional check in 'transform_mesh_edge_slide_data_create' 2024-03-11 12:25:06 -03:00
Germano Cavalcante
fcfce8f69f Fix: unhandled empty Optional in 'bounds_min_max()'
Snap for meshes without vertices raised an error in debug build.
2024-03-11 12:25:06 -03:00
Hans Goudey
f6f767b879 Cleanup: Rename "me_eval" to "mesh_eval"
Similar to 854cdd1180
2024-03-11 11:21:18 -04:00