1280 Commits

Author SHA1 Message Date
tariqsulley
68fecf9fa9 Fix #147606: Spin tool causes immediate crash
Resolve regression in [0], remove unintended trailing space passed to
BMO_op_initf, causing a crash when the spin tool was activated.

Ref !147674

[0]: 83097400f0
2025-10-09 05:29:34 +00:00
Campbell Barton
62d72bd0b5 UV: initial implementation of UV sync select
Support sync selection in the UV editor, with face-corner selection,
so it's possible to select individual UV vertices/edges in the UV editor
without UV's attached to the same underlying edge also becoming selected.

There is limited support for maintaining the UV selection when selecting
from the 3D viewport, common operations such as picking &
box/circle/lasso select support this, however other selection operations
such as "Select Random" or "Select Similar" will clear this data,
causing all UV's connected to selected mesh elements to become selected.
We may add support for additional operators as needed.

Details:

- UV Sync Selection is now enabled by default.
- In edit-mode the UV selection is stored in BMLoop/BMFace which are
  written to custom-data layers when converted to a Mesh.
- To avoid unnecessary overhead - this data is created on demand.
  Operators may clear this data - selecting all or none do so,
  as there is no reason to store this data for a uniform selection.
- The Python API includes functions to synchronize the selection to/from
  UV's as well as flushing based on the mode.
- Python scripts that manipulate the selection will either need to clear
  this synchronized state or maintain it.

See:
- Design task: #78393.
- Implementation task: #131642.

Ref !138197
2025-10-07 01:41:16 +00:00
tariqsulley
83097400f0 Fix #116565: Spinning tool creates duplicates with flipped normals
The Spin operator generated faces with flipped normals because
extrude_face_region always flipped the input faces.
A new skip input flip option was added to extrude_face_region,
allowing the operator to preserve the original orientation when
needed and avoid creating duplicates with flipped normals.

Ref !146203
2025-10-03 06:35:43 +00:00
Hans Goudey
a68d39e9d9 Cleanup: Formatting
Run `make format` after the library update in the previous commit.
2025-10-02 12:55:42 -04:00
Campbell Barton
b78c5fadf3 Cleanup: various non functional changes for C++ 2025-10-01 23:22:44 +00:00
Campbell Barton
a59be80d38 Fix #146836: Auto merge not working in edit mode
Regression in [0] removed checks for indices referencing themselves
which need to be kept but can still be used as targets.

Restore this logic as well as fixing another problem (#147022)
where auto-merge would not merge into the nearest vertex, this
was especially noticeable then the threshold was set to a large value
but would happen at smaller values too.

[0]: bdae3e28a2
2025-09-30 17:37:17 +10:00
tariqsulley
0cf6c32ffd Fix #121129: Crash in bmesh.ops.create_uvsphere if U/V unspecified
Prevent zero U/V segments which caused a crash in
sin_cos_from_fraction from integer divide-by-zero.

Ref !146811
2025-09-26 13:45:14 +10:00
Hans Goudey
fd76bfdd46 Fix #146350: Mesh edit "reverse/rotate colors" crash
MeshRuntime was null but required by the implementation
of the attribute API. This code is much hackier than necessary
anyway and should just use BMesh CustomData directly rather
than trying to be clever.

Also part of #122398.

Pull Request: https://projects.blender.org/blender/blender/pulls/146674
2025-09-24 17:10:48 +02:00
Campbell Barton
f313540686 Cleanup: rename flushing functions for clarity
It wasn't clear how `*_flush` and `*_flush_mode` were different,
rename `*_flush` to `*_flush_from_verts`.
2025-09-24 14:26:28 +10:00
Campbell Barton
d857c48216 Cleanup: replace select/deselect flush functions with a select argument
The naming was confusing as only some selection flushing functions
were intended to be used when elements had been selected or de-selected.

Replace these with a single function that takes a "select" argument.
2025-09-21 20:32:27 +10:00
Campbell Barton
198eb638b2 Cleanup: use full sentences in bmo_removedoubles.cc 2025-09-20 15:18:18 +10:00
Campbell Barton
6de94ee013 Cleanup: merge loops in weld-vertices
Avoid looking up vertex mappings twice.
2025-09-20 15:11:49 +10:00
Campbell Barton
f5c7a1286d Cleanup: avoid a redundant iteration for weld-vertices 2025-09-20 15:01:51 +10:00
Campbell Barton
93cc17dd72 Fix #78916: unpredictable results with merge by distance
The merge by distance operator now has an optional merge centroid
option, when it is enabled, groups of merged vertices are averaged
and moved to their centroid position.

This allows for more predictable results in cases where vertices that
form loops would have otherwise collapsed unevenly and ended up with
jagged lines.

Ref !146478
2025-09-20 12:55:05 +10:00
Campbell Barton
bdae3e28a2 Modeling: use the central vertex when finding duplicates
Previously the method of picking the "target" duplicate wasn't
deterministic from a user perspective.

The behavior has been changed so:

- For a cluster of 3 or more vertices,
  use the vertex closest to the centroid.
- For a cluster of 2 use the lowest index.

This mitigates #78916, solving some cases where clusters have a
central vertex although can't be considered fixed as the 2 vertex
case doesn't work so well.

Added a BLI_kdtree_{N}d_calc_duplicates_cb function that lets the
caller choose the index to keep from a cluster of duplicates.

Refactored from !145851.

Ref !146492

Co-authored-by: tariqsulley <tariqsulley3c@gmail.com>
2025-09-20 12:42:06 +10:00
Campbell Barton
20bea06f4a Revert "Fix #78916: unpredictable results with merge by distance"
This reverts commit 69e27b4855.

Own oversight in the approach since this modified vertices from a
bmesh operator intended to "find" duplicates.
2025-09-19 16:22:35 +10:00
tariqsulley
69e27b4855 Fix #78916: unpredictable results with merge by distance
The previous implementation used KDTree duplicate search with
BLI_kdtree_3d_calc_duplicates_fast(). The survivor was always
one of the input vertices, not the centroid of the cluster.

This caused cases where merging a line of vertices did not
collapse to their average position, resulting in jagged loops.

Now vertices within the threshold are clustered, their centroid
is computed, and the chosen survivor is snapped to this centroid.
This ensures predictable and consistent merge results.

Ref !145851
2025-09-19 15:09:14 +10:00
Campbell Barton
d1b76b6554 Cleanup: only use "r_" prefix for return arguments
Ref !146253
2025-09-14 11:08:50 +00:00
luz paz
afbdf50b85 Cleanup: Fix typos in bmo_join_triangles.cc
Fix spelling "mergable" -> "mergeable"
Found via codespell

Signed-off-by: luz paz <luzpaz@proton.me>
Pull Request: https://projects.blender.org/blender/blender/pulls/145812
2025-09-09 08:50:29 +02:00
Hans Goudey
dce7626b6b Cleanup: Remove unused CustomData interpolation "subweights" argument
This argument is always passed as null. Removing it simplifies the
transition to `AttributeStorage`. Nowadays it seems that most more
complicated interpolation needs are not handled directly by the
CustomData system.

Pull Request: https://projects.blender.org/blender/blender/pulls/145197
2025-08-27 00:02:20 +02:00
Campbell Barton
a27b309009 Modeling: add "Connected" support for auto-merge
Support limiting the merge by connected geometry.
This is useful for operations such as bevel where it's not desirable
for the merge to connect isolated surfaces.

Accessible from the Python API, no user visible changes.

Ref !144036
2025-08-08 13:04:42 +10:00
Campbell Barton
cccc2c77c5 Cleanup: consistent for C-style comment blocks 2025-08-08 07:37:33 +10:00
Campbell Barton
0858f68d3c Fix #143905: Creating a face between two edges can make a bow-tie quad
The check that triangles from a quad point away from each other wasn't
sufficient to avoid creating bow-tie quads.

Resolve by picking the most planar triangle pair.
2025-08-07 13:01:36 +10:00
Campbell Barton
e8501d2f54 Cleanup: grammar corrections, minor improvements to wording
Also back-tick quote some code references in comments
to differentiate them from English text.
2025-08-06 00:20:39 +00:00
Campbell Barton
d72e7f9d6e Cleanup: only handle selection when BM_mesh_esubdivide uses selection
While all callers currently operate on the selection, the function
supports other header-flags, so check the selection is being used
before updating & flushing the selection.
2025-08-02 04:41:40 +00:00
Campbell Barton
2c27d2be54 Cleanup: grammar corrections, minor improvements to wording 2025-08-01 21:41:24 +10:00
Campbell Barton
f3e4b45115 Cleanup: typos in code comments 2025-07-31 06:17:48 +00:00
Campbell Barton
5e3db5fbb0 Cleanup: consistent use of back-ticks in code-comments 2025-07-23 20:59:16 +10:00
Campbell Barton
50f60dbe2d Fix #142633: Crash calling bmesh.ops.split from Python
The bmesh.ops.split operator could include deleted edges as the keys
for `boundary_map`.

Resolve by replacing deleted edges with so the same edge is used for
the key & value, needed so the boundary_map can access the entire
boundary, even when it's source edges have been deleted.
2025-07-23 09:30:48 +00:00
Hans Goudey
14e2876b73 Core: Replace BLI_buffer.hh with blender::Vector
The C++ Vector container has the benefits of the older C type,
along with improved performance, better type and memory safety,
and significantly improved ergonomics.

Pull Request: https://projects.blender.org/blender/blender/pulls/141759
2025-07-13 17:13:59 +02:00
Campbell Barton
ec8751f826 Cleanup: white-space around C-style comment blocks
Also use C++ style comments for disabling code.
2025-07-13 21:58:53 +10:00
Jason C. Wenger
065313eabe Fix edge dissolve behavior with face-split
Correct problem where face split inadvertently triggered the
un-triangulate detection logic in places due to freshly added diagonals.

Defer face split until after tagging is complete so the new edges don't
interfere with edge counting.

Ref !141511
2025-07-08 10:33:25 +00:00
Jason C. Wenger
014be23586 Fix #141351: Default edge dissolve angle leaves many verts undissolved
Adjust angle threshold defaults to dissolve verts as before,
while preserving selected geometry.

The new behavior works as follows:

- If a dissolve terminates on an edge loop or the the corner vert of a
  face, do the dissolve.
- If a set of dissolve edges (either a chain, or a set of 3+ edges)
  crosses a loop cut, do the dissolve.
- If a chain of dissolve edges touch the corner of an unselected face,
  and then leave in a different direction without crossing a loop cut,
  preserve that vert. Just because the selection touches it doesn't mean
  it should be altered.
- If a dissolve edge is separating two triangles,
  then the face join creates a quad. Users generally prefer
  and strive to create meshes that contain quads.
  Instead of destructively dissolving the corners of the quad and
  automatically turning it to a triangle or wire,
  instead prefer to preserve the quad.

Ref !141097
2025-07-04 20:14:55 +10:00
Campbell Barton
4dba0113fd Fix #140396: bmesh.ops.dissolve_edges fails to dissolve vertices
Add an optional init function which operators

An alternative to [0] which missed Python API support (causing #140451).
While that could be resolved, tracking which "slots" have been set
would have to be flagged on every map/hash insertion which seems
excessive and is prone to bmesh operators failing if the flag is ever
missed. Prefer a simpler init function so dissolve edges doesn't have
a zero threshold.

Also support multi-line comment blocks in the generated API docs.

[0]: bd3a66a416
2025-06-18 04:42:42 +00:00
Bastien Montagne
c605c71a96 Fix #140451: Revert "Fix #140396: bmesh.ops.dissolve_edges fails to dissolve vertices"
The BMesh python API was fully broken by this commit.

While the fix seems to be reasonably simple, it is safer for now to revert
the faulty commit, as the breakage is fairly impactful for people using 4.5
and/or 5.0 daily builds.

This reverts commit bd3a66a416.
2025-06-16 16:18:41 +02:00
Campbell Barton
bd3a66a416 Fix #140396: bmesh.ops.dissolve_edges fails to dissolve vertices
Support flagging BMesh operator slots as being used so it's possible
to use a non-zero fallback value for the edge-dissolve angle threshold.
2025-06-15 19:12:50 +10:00
Jason C. Wenger
8277d7e037 Fix crash dissolving two adjacent edges of a quad
Restore the BM_vert_is_edge_pair(v) check that was present prior to
!134017. In that PR, the edge pair check was moved up, to a previous
iteration pass, that checked the angle thresholds. However, even though
pairs were checked before, the process of performing edge merges might
change a neighboring vert such that it is no longer an edge pair.
Therefore it is necessary to check a second time.

Resolves regression in [0].

[0]: e418f7b1f1
2025-06-08 19:34:51 +10:00
Jason C. Wenger
bfbc9c804c Fix bug in dissolve edges that was introduced in 4.4
A bug that was introduced in !131645 where the number of verts eligible
for dissolve was reduced, to prevent dissolving unrelated verts.

That PR changed the code to only do the dissolve check on verts at the
ends of selected edges, which solved bug #109765. However, this didn't
properly account for dissolving only one edge in a chain in a face pair.

This could result in cases where one of the vertices should be checked
but wasn't - if it wasn't selected.

Now when an edge is dissolved, each of its verts is checked,
and if it's in a chain, the VERT_MARK tag is moved down the
chain until it finds its natural endpoint.

Ref !139959.
2025-06-07 12:35:38 +10:00
Campbell Barton
628f1e08d0 Fix edge dissolve leaving visible edges connected to hidden vertices
Visible edges should always have both vertices visible.
When dissolving, hide any edges which become connected to hidden
vertices.
2025-06-05 05:33:51 +00:00
Jason C. Wenger
e418f7b1f1 Modeling: add an angle threshold that affects vertex dissolve
When dissolving an edge merges faces, use an angle threshold before
dissolving vertices from the face which have become chains as reult
of the merge (connected to 2 edges).

Also fix edge-flag handling when dissolving multiple edges
from a chain into a single edge, previously flags from the
resulting edge was effectively random.
Now flags from all edges are merged.

Resolves #100184.

Ref !134017
2025-06-05 05:33:49 +00:00
Hans Goudey
77b14f2dcb Cleanup: Grammar: Fallback vs. fall back
The former is a noun or adjective, the latter is a verb.
2025-06-02 17:13:56 -04:00
Brecht Van Lommel
f165c75e14 Refactor: Add various DNA_*_enums.h and DNA_*_types.h files
* Move colorband and theme DNA to own headers
* Move some anim, curve, modifier and space enums to new headers
* Move data transfer enums to DNA
* Duplicate imbuf proxy and GPU backend enums

For a few reasons:
* Reduce number of includes in DNA headers
* Don't define enums used in DNA outside of DNA
* Move theme settings to separate header for userdef_default_theme.c
* Prepare for using default initializers in DNA headers. (#134531)

Pull Request: https://projects.blender.org/blender/blender/pulls/138831
2025-05-20 13:26:43 +02:00
Campbell Barton
43af16a4c1 Cleanup: spelling in comments, correct comment block formatting
Also use doxygen comments more consistently.
2025-05-01 11:44:33 +10:00
Campbell Barton
c90e8bae0b Cleanup: spelling in comments & replace some use of single quotes
Previously spell checker ignored text in single quotes however this
meant incorrect spelling was ignored in text where it shouldn't have
been.

In cases single quotes were used for literal strings
(such as variables, code & compiler flags),
replace these with back-ticks.

In cases they were used for UI labels,
replace these with double quotes.

In cases they were used to reference symbols,
replace them with doxygens symbol link syntax (leading hash).

Apply some spelling corrections & tweaks (for check_spelling_* targets).
2025-04-26 11:17:13 +00:00
Brecht Van Lommel
fb2ba20b67 Refactor: Use more typed MEM_calloc<> and MEM_malloc<>
Pull Request: https://projects.blender.org/blender/blender/pulls/137822
2025-04-22 11:22:18 +02:00
Brecht Van Lommel
637c6497e9 Refactor: Use more typed MEM_calloc<>, avoid unnecessary size_t cast
Handle some cases that were missed in previous refactor. And eliminate
unnecessary size_t casts as these could hide issues.

Pull Request: https://projects.blender.org/blender/blender/pulls/137404
2025-04-21 17:59:41 +02:00
Campbell Barton
3933f45f52 Cleanup: move doc-strings to declarations
Move into headers or to the top of the function body for internal
implementation details, in some cases remove duplicate doc-strings.
2025-04-18 22:58:36 +10:00
Jason C. Wenger
4e37bd8c65 Fix #70977: Dissolve can create duplicate faces
Prevent dissolve leaving duplicate faces when dissolving edges.

Also use the builtin reuse of duplicate faces provided by BM_face_join()
instead of doing it manually.

Ref: !137634
2025-04-17 12:14:49 +10:00
Jason C. Wenger
7c79c303b8 BMesh: maintain the active face if the active face when joining faces
Whenever faces are merged, resetting the active face is bad.
Do it centrally instead of relying on each caller to fix it.

Ref !137535
2025-04-16 13:34:47 +10:00
Jason C. Wenger
702efd6846 BMesh: add a BM_faces_join() to return a duplicate face (if found)
Every call to BM_faces_join and BM_faces_join_pair has been adjusted to
provide the new face pointer, and a BLI_assert_msg has been added so
that doubles are now consistently identified and flagged as a problem.
BM_faces_join is now also capable of automatically reusing a double
when it is found. This new behavior is currently unused at this point.
Future patch-sets will begin to use it, allowing simplification of
calling functions.

Ref: !137406
2025-04-15 11:03:15 +00:00