3427 Commits

Author SHA1 Message Date
Aras Pranckevicius
facb17b0e3 Cleanup: BLI ENUM_OPERATORS cleanup/robustness
BLI code for enums that are meant to be used as "bit flags" defined
an ENUM_OPERATORS macro in BLI_utildefines.h. This cleans up things
related to said macro:

- Move it out into a separate BLI_enum_flags.hh header, instead of
  "random bag of things" that is the current place,
- Update it to no longer need manual indication of highest individual
  bit value. This originally was added in a31a87f89 (2020 Oct), in
  order to silence some UBSan warnings that were coming
  from GPU related structures (looking at current GPU code, I don't
  think this is happening anymore). However, that caused actual
  user-visible bugs due to incorrectly specified max. enum bit value,
  and today 14% of all usages have incorrect highest individual
  bit value spelled out.
    - I have reviewed all usages of operator ~ and none of them are
      used for directly producing a DNA-serialized value; all the
      usages are for masking out other bits for which the new ~
      behavior that just flips all bits is fine.
- Make the macro define flag_is_set() function to ease check of bits
  that are set in C++ enum class cases; update existing cases to use
  that instead of three other ways that were used.

Pull Request: https://projects.blender.org/blender/blender/pulls/148230
2025-10-17 12:57:50 +02:00
Hans Goudey
1d372bdc8b Refactor: Split CustomData attribute and newer attribute headers
Avoid including DNA_customdata_types.h everywhere we include the
attributes header. Over time the older attribute header should be
used less and less.

Part of #122398

Pull Request: https://projects.blender.org/blender/blender/pulls/147980
2025-10-13 15:38:26 +02:00
Howard Trickey
d58afb615c Fix #147718: Bevel accuracy at small scale.
There was a bug in the move_weld_profile_planes function where
it would only move the profile plane involved in a "weld" if
certain vectors were not too small (less than BEVEL_EPSILON in
length). The intent of the code was just to avoid problems with
zero length normals (post normalization), and the normalize_v3
function indicates that with an exact 0.0f return, so there was
no need for an epsilon test.
The example file in the issue had a small-scale model (100 times
smaller than typical), which ended up causing the old code to
prevent moving the profile plane to where it belongs.

Pull Request: https://projects.blender.org/blender/blender/pulls/147898
2025-10-12 02:03:46 +02:00
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
f222916c38 Cleanup: simplify BM_attribute_stored_in_bmesh_builtin 2025-10-08 15:39:26 +11:00
Campbell Barton
f4308aa2d0 UV: remove per-UV-map selection data
Replace per UV map selection with a single UV selection for all UV's.
This uses the same data as UV sync select, meaning that it's no longer
possible to keep a different selection when sync-select is disabled.

There is a minor improvement to functionality - previously not possible
to de-select a single face surrounding by selected faces.
Now this is possible because true face selection is supported.

The selection from the active UV-map is converted to use the shared
selection data.

Ref !147523

Co-authored-by: Hans Goudey <hans@blender.org>
2025-10-08 15:05:20 +11:00
Campbell Barton
377e3cfca5 Cleanup: use a define for BMUVOffsets that doesn't reference any layers
Reduce the number of places that need to be updated when struct members
change and reduces the binary size a little.
2025-10-08 14:56:43 +11:00
Campbell Barton
a6a8fc9619 Fix: crash creating a BMesh when some UV selection layers are missing
Error in !138197, while all UV selection layers should exist,
don't crash if some are missing.
2025-10-08 11:20:31 +11: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
Campbell Barton
d990026fd6 PyAPI: add option for BMesh.select_flush_mode() to flush down
Support optionally flushing down:
- faces -> edges & verts.
- edges -> verts.

For C++ selection logic flushing down is avoided as it's an extra step
and instead, selection logic must take care to de-select edges/faces
before selection, so any shared vertices or edges are selected.

Flushing down means scripts can set the selection on faces or edges,
then flush this to all other elements without being concerned with
the order they have been set.

Ref !147351
2025-10-04 22:45:42 +10:00
Campbell Barton
fb5707ce41 Cleanup: use enum class for bmesh selection flush flags 2025-10-04 22:45:42 +10: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
tariqsulley
04a499bc5a Fix #147150: Crash when trying to merge vertex and edge
The operator passed edges into BM_edge_exists, which asserts both
inputs must be vertices. Mixed selections are now rejected with an
error message, preventing the assert and crash.

Ref !147239
2025-10-03 15:17:59 +10: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
1884e049e8 Fix #147088: Crash copying custom-normal in face + vertex selection mode
The logic to copy custom normals checked for selection but didn't
account for the selection-history failing to initialize any
custom-normal loops.

Resolve by using the regular selection if the selection-history
cannot be used as a source for loop-normals.

Ref !147087
2025-10-01 03:40:07 +00:00
Campbell Barton
2fd3b557d8 Refactor: move logic for creating custom-normal arrays into functions
Also add `BM_loop_normal_editdata_array_init_with_htype`
(needed to fix #146515).

Ref !147087
2025-10-01 03:40:04 +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
Campbell Barton
2f3e6e69df Cleanup: rename BM_mesh_{validate=>is_valid}
The term validate is often used to make the data valid
(e.g. BKE_mesh_validate) where is this only checks the mesh is valid.
2025-09-25 11:22:23 +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
16118be339 Cleanup: typos, copy/paste error 2025-09-23 09:42:48 +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
4a6268e092 Cleanup: various non functional changes for C++ 2025-09-20 16:28:02 +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
Campbell Barton
62906cb6f4 Cleanup: use a boolean for BMesh::use_toolflags
Bit-fields don't have any advantage in this case, use a boolean.
2025-09-11 14:40:13 +10: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
b465504ee2 Fix #145108: Split selection removes edges
Regression [0] (likely a copy/paste error).

[0]: 50f60dbe2d
2025-08-26 17:22:53 +10:00
Jason C. Wenger
001a2b3f4d Fix #144383: Limited dissolve creates duplicate faces
Use of BM_faces_join_pair can result in an invalid mesh with doubled
faces. [0] added an assert to identify when this could occur.

This case has been inspected, and allowing the auto-join logic in
BM_faces_join_pair() to delete the doubled face does not negatively
impact iteration or processing:

1. The eheap and eheap_table used here deal only with edges, not faces.
2. Loop iteration is unchanged.
   A conversion to use of BM_ITER_MESH_MUTABLE is not applicable because
   the iteration is done on the edge heap, not the mesh.
3. The recomputation of the face normals of each combined face still
   works properly.

Ref !144653

[0]: 702efd6846
2025-08-26 13:27:34 +10:00
Campbell Barton
3f7f475c1c Docs: correct doc-string 2025-08-26 02:14:28 +00:00
Piotr Makal
7e4defbf3b Fix: Performance regression when using bevel and subdivision modifier
PR https://projects.blender.org/blender/blender/pulls/144233.
Fix #142296 performance regression caused by merging UV positions
based on face area weights, replacing it with mean average weights
computation. The former method resulted in higher probability in making
subdivision cache invalid between frame updates and thus causing expensive
recreation of blender::bke::subdiv::OpenSubdiv_Evaluator object.
While this fix isn't directly answering a question why specific UV position
updates would cause this reevaluation of subdivision object, it fixes
the performance regression caused by #139595 PR.
2025-08-24 08:59:47 -04:00
Campbell Barton
fb28091671 Cleanup: quiet array-bounds GCC warning 2025-08-21 02:05:32 +00:00
Campbell Barton
3a8a379ea2 Cleanup: use camel-case/pascal-case for struct names 2025-08-20 11:01:13 +10: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
ff10f7803e Cleanup: correct comment 2025-08-08 07:36:32 +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
Hans Goudey
3724ebeaa6 Refactor: Extract BMesh attribute lookup function
This is the second time I've needed a function to find an attribute by
name on all attribute domains, with a third time coming soon. It seems
time to put this in a BMesh header.

Pull Request: https://projects.blender.org/blender/blender/pulls/144039
2025-08-06 13:40:51 +02: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
Hans Goudey
f5f9c4f444 Fix #143450: Bevel modifier crash with free normals
If the BMesh already has a "custom_normal" attribute with the wrong
type, the call to `BM_lnorspace_update` won't be able to add the
attribute with the expected name, and the bevel code ends up using an
invalid offset to access the data.

For the fix, first just guard against that case. But also make sure the
harden normals functionality still works when the input mesh has free
normals. They will no be converted to tangent space normals as
necessary, in bevel and in other BMesh code that requires that
custom normal storage format.

Pull Request: https://projects.blender.org/blender/blender/pulls/143489
2025-08-05 04:45:49 +02: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