Commit Graph

900 Commits

Author SHA1 Message Date
Campbell Barton
b27459dbd8 Fix #137456: Select shortest path can double-back on itself
The corner-cost bias used when calculating the shortest path meant
the path could cross over itself.

Resolve by tagging vertices as well as edges to prevent stepping across
vertices used by edges that have been added to the heap.
2025-04-29 11:52:01 +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
388a21e260 Refactor: Eliminate various void pointers passed to MEM_freeN
It's safer to pass a type so that it can be checked if delete should be
used instead. Also changes a few void pointer casts to const_cast so that
if the data becomes typed it's an error.

Pull Request: https://projects.blender.org/blender/blender/pulls/137404
2025-04-21 17:59:41 +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
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
Jesse Yurkovich
f60c528c48 Cleanup: Fix one-definition-rule violations for various structs
This fixes most "One Definition Rule" violations inside blender proper
resulting from duplicate structures of the same name. The fixes were
made similar to that of !135491. See also #120444 for how this has come
up in the past.

These were found by using the following compile options:
-flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing

Note: There are still various ODR issues remaining that require
more / different fixes than what was done here.

Pull Request: https://projects.blender.org/blender/blender/pulls/136371
2025-04-04 21:05:16 +02:00
Campbell Barton
d60bbbbe63 Fix #136280: Select shortest path crashes in the UV editor 2025-04-01 21:16:08 +11:00
Jason C. Wenger
80a38bb1e4 Fix #120770: poor un-subdivide performance with disconnected geometry
- Refactor tagging logic into a function to remove duplicate code

  The two phases of tagging were identical logic just with the variables
  and tag values swapped. This change ensures the two loops use matching
  behavior.

- Adjust iteration to prevent restarting from the beginning of the mesh
  after each island.

- Simplify and speed iteration tests.

  testing to ensure v->e is non-null is redundant - verts with no edges
  would never have passed `bm_vert_dissolve_fan_test` in the first
  place, so can't be tagged as `VERT_INDEX_INIT`.
  Re-testing `bm_vert_dissolve_fan_test(v)` is redundant - it was
  checked above, and during tagging, the topology does not change.
  Topology only changes later, after tagging is complete.
  Therefore it's guaranteed to return the same result as the first time.

- Simplify loop logic, rename vars for clarity

  offset and nth were constants, and depth was what causes alternation.
  However none of that math is necessary - it can simply be done with
  call order.

  'seek_a' and 'seek_b' were renamed to what they actually are - lists
  of verts that are tagged for collapse and ignore, respectively.

  Further, by checking if any verts were tagged during the first
  iteration pass, the second iteration pass can be avoided entirely if
  it will perform no work.

Ref: !135212
2025-02-27 15:53:12 +11:00
Campbell Barton
51113085de Cleanup: remove disabled BMWalker logic for un-subdivide
This isn't going to be enabled and made the in-lined tagging more
difficult to follow.
2025-02-27 15:53:12 +11:00
Brecht Van Lommel
37b95783fa Cleanup: Various clang-tidy warnings in bmesh
Pull Request: https://projects.blender.org/blender/blender/pulls/133734
2025-01-31 17:03:17 +01:00
Brecht Van Lommel
920e709069 Refactor: Make header files more clangd and clang-tidy friendly
When using clangd or running clang-tidy on headers there are
currently many errors. These are noisy in IDEs, make auto fixes
impossible, and break features like code completion, refactoring
and navigation.

This makes source/blender headers work by themselves, which is
generally the goal anyway. But #includes and forward declarations
were often incomplete.

* Add #includes and forward declarations
* Add IWYU pragma: export in a few places
* Remove some unused #includes (but there are many more)
* Tweak ShaderCreateInfo macros to work better with clangd

Some types of headers still have errors, these could be fixed or
worked around with more investigation. Mostly preprocessor
template headers like NOD_static_types.h.

Note that that disabling WITH_UNITY_BUILD is required for clangd to
work properly, otherwise compile_commands.json does not contain
the information for the relevant source files.

For more details see the developer docs:
https://developer.blender.org/docs/handbook/tooling/clangd/

Pull Request: https://projects.blender.org/blender/blender/pulls/132608
2025-01-07 12:39:13 +01:00
Hans Goudey
31964ef5ca Cleanup: Move BLI_kdopbvh to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/132031
2024-12-17 21:04:55 +01: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
Campbell Barton
b9f055459a Cleanup: ensure trailing space around comment blocks 2024-11-27 19:01:00 +11:00
Campbell Barton
0de8ae8046 Cleanup: spelling in comments 2024-11-25 13:24:46 +11:00
Hans Goudey
c497d5c3fa Refactor: Move quad triangulation function to blenlib
Make this available for a Mesh-based triangulation implementation
implemented elsewhere. Part of #112264.
2024-11-21 08:30:28 -05:00
Campbell Barton
c5272e7857 Cleanup: various non functional changes 2024-11-07 18:21:07 +11:00
Rob-Blair
dd334faa58 Fix #125024: Bevel offset - eliminate divide by 0.
From Rob Blair's PR https://projects.blender.org/blender/blender/pulls/126309 .
In the code that clamps the bevel amount, the existing code could get
a denominator of 0 (from a tangent of a certain angle).
This code uses a different calculation (diagram in the PR) that clamps
when the projections of four specific edges onto another edge consumes
the whole length of that edge.
2024-10-30 08:21:51 -04:00
Howard Trickey
eba2aff295 Revert "Rob-Blair-ready" - committed before tests ready.
This reverts commit 8b94e21976.
2024-10-22 14:57:56 +02:00
Howard Trickey
8b94e21976 Rob-Blair-ready
Copying PR 126309 from Rob-Blair so that I can try to make the tests pass.

Co-authored-by: Rob-Blair <Rob.Blair@Verizon.net>
Pull Request: https://projects.blender.org/blender/blender/pulls/129313
2024-10-22 14:52:30 +02:00
Jesse Yurkovich
1dbf75ff52 Cleanup: Remove BLI_array macros in bmesh edgenet
This replaces the older dynamic c array macros with blender::Vector in
bmesh_polygon_edgenet. This is the only remaining use of the old array
machinery and removal of `BLI_array.h / .c` can happen immediately
afterwards.

See #103343

Pull Request: https://projects.blender.org/blender/blender/pulls/119975
2024-09-21 23:59:14 +02:00
Mike93
cc5ed48cd3 Modifiers: Add custom attribute weight support to bevel modifier
As of 2a56403cb0, bevel weight data is stored as a generic
attribute. The bevel modifier is currently hard-coded to use the
`bevel_weight_edge` attribute as the data source for the weights.
This commit adds a string textbox where the user can specify alternate
attributes for the bevel's edge weights.

The string name field is added as a search button which provides a list
of all attributes in the original mesh. This is meant to work similarly
to geometry nodes, so mismatched attribute data types and domains are
automatically converted/interpolated as necessary. Attributes created
by previous modifiers can also be used, but they won't appear in the
search menu.

Co-authored-by: Hans Goudey <hans@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/117366
2024-09-05 17:15:34 +02:00
Campbell Barton
ff3949426c Cleanup: spelling in comments 2024-09-02 16:55:19 +10:00
Jesse Yurkovich
cb79df9343 Cleanup: Formatting
Pull Request: https://projects.blender.org/blender/blender/pulls/127063
2024-09-02 05:55:13 +02:00
Howard Trickey
8549bc94de Fix #126511: Crash when Bevel + Mark Seam or Sharp
The code for marking seams or sharp in a bevel was nonsense
for terminal edges (beveled edges that are the only beveled
edge at a vertex). It was written assuming that either the
number of segments is 1 or there is a mesh ADJ pattern, which
is not the case if there is a terminal edge with segments > 1.
The immediate fix for infinite loops is to project against trying
to execute this code for terminal edges.
Also made current code clearer and removed duplication.
It is a future TODO to make it do something sensible for terminal
edges instead of a no-op. Incidentally I notice that it also doesn't
work for mitered booleans, but it won't infinite loop in that case.
To fix both of these cases, we should try to count boundary vertices
to skip rather than edges to skip.
2024-09-01 19:21:12 -04:00
Campbell Barton
9a9df2aad7 Cleanup: use BM_DISK_EDGE_NEXT macro 2024-08-26 11:50:12 +10:00
Philipp Oeser
8b3beeee82 Fix #124836: Triangulate modifier changed behavior with custom normals
This reverts commit f3c32a36bc and the two followups.

The commit caused issues with both the operator and the modifier.

The operator could be fixed, for the modifier this needs deeper
investigation (see #124836 for a bit more info on this).

Until a better solution is found it is just better to go back to
previous behavior.

Reintroduces  #103562 for now

Pull Request: https://projects.blender.org/blender/blender/pulls/125499
2024-07-28 10:27:29 +02:00
Philipp Oeser
f3c32a36bc Fix #103562: preserve custom normals in BM_mesh_triangulate
`BM_mesh_triangulate` is used in exporters (when the "Triangulate"
option is ON), the `Triangulate` modifier and currently also in the
`Triangulate` geometry node (even though there are plans to change this,
see !112264)

So in practice, exporters (Alembic/FBX/OBJ/Collada) were breaking
custom normals for game pipelines (unless everything was triangulated
beforehand).

This change builds upon 93c8955a72 (uses the use
`BM_custom_loop_normals_to_vector_layer` /
`BM_custom_loop_normals_from_vector_layer` pair of calls).

In the case of the `Triangulate` modifier, this had its own try at
preserving custom normals in 7d0fcaa69a  -- doing very similar
things but as an option -- this is now removed (so it is always done,
which fits into "interpolate custom data if it's there" design that we have
nowadays).

NOTE: the "Triangulate Faces" operator already did the same
Pull Request: https://projects.blender.org/blender/blender/pulls/121871
2024-05-23 17:33:40 +02:00
Philipp Oeser
e816b481e0 Fix #121004: bmesh.ops.dissolve_limit wrong in certain cases
Exposed by 6c774feba2

`BM_mesh_decimate_dissolve_ex` sets up `DelimitData` with layer offset
(start), size and end so that `bm_edge_is_contiguous_loop_cd_all` can
check a range of edges for being contiguous.

The way `cd_loop_offset_end` is calculated is wrong though, it does not
take the actual start into account (this has to be added to fix the
bug). When it is wrong, it can happen that start and end are the same,
so no check actually takes place and no delimiting edges are found.

It seems that prior to 6c774feba2 the customdata layer always had an
offset of zero, so never really showed in practice (at least I couldnt
make it break in 3.4), but after 6c774feba2 we can at least observe the
following:
- when creating a bmesh, an offset would to the uv layer would still be
zero in my tests
- however, as soon as we iterate loops of a face (as done in the
report), we get an additional layer `CD_BM_ELEM_PYPTR`
- this then changes the offset
- `BM_uv_map_get_offsets_from_layer` seems to do the right thing afaict

So to resolve, just add the "start" offset to the end, to get the right
range.

NOTE: there is a very similar `DelimitData` used in
`bmesh.ops.join_triangles` and the way in which `bm_edge_delimit_cdata`
sets up te range is exactly like what this PR proposes.

Pull Request: https://projects.blender.org/blender/blender/pulls/121033
2024-04-26 07:47:57 +02: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
Campbell Barton
5c87dfd269 Cleanup: use BLI_time_ prefix for time functions
Also use the term "now" instead of "check" for clarity.
2024-02-15 13:15:56 +11:00
Campbell Barton
3f8cd44485 Cleanup: move BLI_strict_flags.h last, not that it should be kept last
Also add a note in the header why it should be kept last.
2024-02-14 13:40:31 +11:00
Campbell Barton
38023283ac Cleanup: unused includes in source/blender/bmesh
Remove 26 includes.
2024-02-13 19:21:03 +11:00
Hans Goudey
c87e51790d Cleanup: Make format 2024-01-31 22:01:30 -05:00
Hans Goudey
fac27b1b6b Cleanup: Replace most used of SWAP macro with std::swap
Also remove / replace use of the math vector double swapping functions.
2024-01-31 21:12:16 -05:00
Hans Goudey
961783c444 Cleanup: Move BKE_deform.h to C++ 2024-01-29 19:04:13 -05:00
Hans Goudey
d02d6ec4e5 Cleanup: Remove unnecessary keywords in C++ headers 2024-01-24 11:46:39 -05:00
Hans Goudey
99f9084bee Cleanup: Replace some CLAMP macros with C++ functions
Pull Request: https://projects.blender.org/blender/blender/pulls/117460
2024-01-23 21:10:33 +01:00
Campbell Barton
0ce1102147 Cleanup: replace incorrect use of UUID with UID in bmesh_region_match
Follow up to 311ca3e6af.
2024-01-23 13:22:04 +11:00
Jacques Lucke
4b47b46f9c Cleanup: rename PIL to BLI
The term `PIL` stands for "platform independent library." It exists since the `Initial Revision`
commit from 2002. Nowadays, we generally just use the `BLI` (blenlib) prefix for such code
and the `PIL` prefix feels more confusing then useful. Therefore, this patch renames the
`PIL` to `BLI`.

Pull Request: https://projects.blender.org/blender/blender/pulls/117325
2024-01-19 14:32:28 +01:00
Hans Goudey
d6cfd7d1f4 Cleanup: Remove unnecessary keywords from C++ headers
- Remove unnecessary `struct`
- Use `using` instead of `typedef`
- Remove `void` from `(void)` as function arguments
2024-01-04 15:07:48 -05:00
Brecht Van Lommel
d377ef2543 Clang Format: bump to version 17
Along with the 4.1 libraries upgrade, we are bumping the clang-format
version from 8-12 to 17. This affects quite a few files.

If not already the case, you may consider pointing your IDE to the
clang-format binary bundled with the Blender precompiled libraries.
2024-01-03 13:38:14 +01:00
Hans Goudey
854d7afa1e Cleanup: Use FunctionRef instead of std::function
This is clearer about the lack of need for ownership of callback
data and can be faster as well.
2023-12-30 20:16:03 -05:00
Campbell Barton
225fc6fca7 Cleanup: spelling in comments, correct outdated comment 2023-12-17 16:04:38 +11:00
Campbell Barton
22d65bad95 Cleanup: pass BMesh by pointer instead of reference
The version of BM_elem_attrs_copy that took a map used a reference
the version without a map didn't, which is fairly confusing.

Pass by pointer now unless this is part of a wider refactor
to move to references everywhere.
2023-12-10 22:12:34 +11:00
Campbell Barton
9d9764c1c9 Cleanup: remove redundant define checks
Also reformat checks to quiet warnings so they don't read as empty
define checks.
2023-12-07 10:39:03 +11:00
Brecht Van Lommel
e06561a27a Build: replace Blender specific DEBUG by standard NDEBUG
NDEBUG is part of the C standard and disables asserts. Only this will
now be used to decide if asserts are enabled.

DEBUG was a Blender specific define, that has now been removed.

_DEBUG is a Visual Studio define for builds in Debug configuration.
Blender defines this for all platforms. This is still used in a few
places in the draw code, and in external libraries Bullet and Mantaflow.

Pull Request: https://projects.blender.org/blender/blender/pulls/115774
2023-12-06 16:05:14 +01:00
Hans Goudey
32776880a0 Cleanup: BMesh: Add function for copying within the same BMesh
For now it has the same implementation as the function that allows
passing separate source and destination custom data formats. But
copying to the same format can potentially be much simpler.
2023-12-05 22:09:36 -05:00
Hans Goudey
7a96c4672c Cleanup: Move BMesh headers to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/115817
2023-12-05 23:01:12 +01:00
Campbell Barton
a385a98e8e Cleanup: spelling in comments 2023-11-29 15:56:17 +11:00