Commit Graph

3334 Commits

Author SHA1 Message Date
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
b3dfde88f3 Cleanup: spelling in comments (check_spelling_* target)
Also uppercase acronyms: API, UTF & ASCII.
2025-05-17 10:17:37 +10:00
Hans Goudey
a224ba806d Mesh: Rewrite face corner normals calculation
This PR intends to replace the current face corner normals calculation.
Compared to the existing code it has a few benefits:
- It's much easier to understand.
- It doesn't require edges, ideally helping to remove them from caches
  and eventually to make them optional.
- It is completely multithreaded using the vert to face map, which is
  already used for vertex normals and domain interpolation. The previous
  code has a significant single threaded portion that scales with the
  size of the mesh.
- Lower peak memory usage: It doesn't require a temporary edge to corner
  map, the corner to face map, or a corner domain sized bit vector.
- The code sorting corners around a vertex should be easy to reuse.
- It's over twice as fast. On a test file with custom normals I observe
  an overall FPS increase of 2.56x, from 37 to 95.

Pull Request: https://projects.blender.org/blender/blender/pulls/138013
2025-05-14 15:35:48 +02:00
Jacques Lucke
e8d1491e62 Refactor: Depsgraph: simplify query API further
* Remove `DEG_get_evaluated_object` in favor of `DEG_get_evaluated`.
* Remove `DEG_is_original_object` in favor of `DEG_is_original`.
* Remove `DEG_is_evaluated_object` in favor of `DEG_is_evaluated`.

Pull Request: https://projects.blender.org/blender/blender/pulls/138317
2025-05-02 15:08:29 +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
18ba7d1f86 Cleanup: use const arguments for UV checking functions 2025-04-30 12:54:29 +10:00
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
Campbell Barton
5ff7ffe31b Cleanup: use colon after doxygen parameters 2025-04-29 05:04:36 +00: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
Campbell Barton
8ccdea1934 Cleanup: typos & references to variable names from recent refactor 2025-04-24 02:43:52 +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
d061b00455 Refactor: Eliminate various unsafe memcpy and memset
Some of these already have warnings with clang-tidy, others are more
safe in case these structs get (copy) constructors in the future.

Pull Request: https://projects.blender.org/blender/blender/pulls/137404
2025-04-21 17:59:41 +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
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
486711d685 BMesh: skip recomputing custom-data when face join uses an existing face
If `f_new` is a double of an existing face and the existing face is
being reused, then the existing face already has custom-data and
multi-res data and etc.

There's also a good case to be made that custom or multireas data on the
existing face might be that way because it was hand-edited by the user,
and therefore it's superior to anything we'd interpolate or copy from
faces being removed.

Change BM_faces_join() to not waste time doing that.

Ref: !137537
2025-04-16 13:18:20 +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
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
Campbell Barton
f43b8afdd7 Cleanup: move sync-select checks into uv_select_* functions
uv_select_all_perform had split the UV_SYNC_SELECTION
case into a separate block which complicated changes in this area.

Now each UV select function handles the sync-select case.

Also make UV's const when only used for comparison.
2025-03-29 14:51:17 +11:00
Campbell Barton
12e17e2477 Cleanup: use const arguments, variables 2025-03-28 00:59:11 +00:00
Campbell Barton
78c3f6a1ee Cleanup: adjust order of terms for BMesh UV map function calls
Order more generic terms first for better ordering, more useful
completion.
2025-03-13 15:23:46 +11:00
Campbell Barton
571bab615c UV: skip adding UV data layers when sync-select is used
When sync select is enabled, the data layers aren't accessed
so there is no need to add them.

Also skip adding a "pin" layer when clearing pinned UV's.
2025-03-13 14:40:56 +11:00
Campbell Barton
13b4da2568 Docs: update bmesh_class.hh header
- Minor corrections & clarifications.
- Use doxygen docs.
2025-03-13 13:41:19 +11:00
Campbell Barton
6ef7dae8ef Cleanup: spelling in comments (make check_spelling_*) 2025-03-13 13:41:17 +11:00
Campbell Barton
5b856ba447 Merge branch 'blender-v4.4-release' 2025-03-06 10:35:59 +11:00
Campbell Barton
b85fc32cae Cleanup: spelling & repeated words in comments
Address warnings from check_spelling.py
2025-03-06 10:33:21 +11:00
Sean Kim
a9a98c9a60 Cleanup: Remove unused bmesh_log.hh functions
Pull Request: https://projects.blender.org/blender/blender/pulls/135474
2025-03-05 22:59:05 +01:00
Bastien Montagne
dd168a35c5 Refactor: Replace MEM_cnew with a type-aware template version of MEM_callocN.
The general idea is to keep the 'old', C-style MEM_callocN signature, and slowly
replace most of its usages with the new, C++-style type-safer template version.

* `MEM_cnew<T>` allocation version is renamed to `MEM_callocN<T>`.
* `MEM_cnew_array<T>` allocation version is renamed to `MEM_calloc_arrayN<T>`.
* `MEM_cnew<T>` duplicate version is renamed to `MEM_dupallocN<T>`.

Similar templates type-safe version of `MEM_mallocN` will be added soon
as well.

Following discussions in !134452.

NOTE: For now static type checking in `MEM_callocN` and related are slightly
different for Windows MSVC. This compiler seems to consider structs using the
`DNA_DEFINE_CXX_METHODS` macro as non-trivial (likely because their default
copy constructors are deleted). So using checks on trivially
constructible/destructible instead on this compiler/system.

Pull Request: https://projects.blender.org/blender/blender/pulls/134771
2025-03-05 16:35:09 +01:00
Sean Kim
584f15cc33 Cleanup: Convert BLI_mempool to blender::Pool in bmesh_log.cc
* Adds an `allocated_` prefixed `Vector` to track all used pointers so
  everything can be deconstructed when `BMLogEntry` is freed.

Pull Request: https://projects.blender.org/blender/blender/pulls/135415
2025-03-04 01:37:46 +01:00
Sean Kim
34eec790b5 Cleanup: Update bmesh_log.hh documentation
Pull Request: https://projects.blender.org/blender/blender/pulls/135339
2025-03-03 17:45:46 +01:00
Hans Goudey
aafcc5d3b9 Cleanup: Use references, nodiscard, for BMesh partial update 2025-03-01 18:02:30 -05:00
Hans Goudey
64c3fd7b1c Cleanup: Use Vector, BitVector for BMesh partial update struct
Avoid reimplementing amortized growth, and generally make
the code friendlier with the improved BitVector class.
2025-03-01 17:47:55 -05:00
Sean Kim
de3c473ebb Cleanup: Various non-functional changes for bmesh_log.cc
* Uses const where possible
* Joins declaration with assignment
* Use std::array where possible instead of C-style array
* Use float3 instead of C-style array for position and normal
* Reduces scope of variables where possible

Pull Request: https://projects.blender.org/blender/blender/pulls/135336
2025-03-01 07:06:55 +01:00
Sean Kim
e6384bcce6 Cleanup: Switch GHash for blender::Map for bmesh_log.cc
This commit changes usages of `GHash` inside `bmesh_log.cc` into their
equivalent `blender::Map` declarations and functions.

Additionally, some debug functions are put inside a NDEBUG section
instead of being kept in a broken state behind `#if 0`

Pull Request: https://projects.blender.org/blender/blender/pulls/135276
2025-03-01 05:13:32 +01:00
Campbell Barton
0fa74fc4af Merge branch 'blender-v4.4-release' 2025-02-27 15:54:48 +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
Jason C. Wenger
59d72a8f7d Mesh: grid-fill now supports replacing existing faces
The existing behavior of the grid fill operator requires a loop of
boundary or wire edges to be selected. This algorithm tries to fit a
grid of quads into the edge loop. It also works if you select two of the
four 'rails' of an edge loop.

This new behavior allows running grid fill after selecting faces.
If the algorithm sees that a set of faces are selected, it separates
all the faces, and then attempts to grid from their exterior boundary
using the exact same logic it normally uses for interior boundaries.
This all assumes the user has selected a set of faces with an outside
border that works with grid fill. (has one clear exterior loop with an
even number of edges) If not, grid fill will halt, and notify the user
of the error, exactly the way that it already did before.
Once the grid fill is complete and successful,
the existing faces which were replaced get deleted.

UVs (including at UV island boundaries) are interpolated properly,
as are custom-data on verts, edges, faces, and face corners.
At the edges of the selection, the edges/faces/face corners that are
selected contribute, but the custom-data outside the selection does not.

This also resolves non-deterministic behavior.
The previous behavior of `edbm_grid_fill_prepare` found the vertex with
the largest angle, then walked the edge loop until it found one out of
the three best remaining corners. This established one edge of the grid
area, and the second edge was found by symmetry.
However, the direction that the algorithm walked the loop
(and therefore which second corner was found) was essentially arbitrary.

The new behavior first finds the vert with the largest angle,
then finds the vert with the second largest angle,
(after excluding the diagonally opposite corner from the first vert),
and selects the edge between those two verts.

Ref !129318.
2025-02-18 12:40:00 +11:00
Jason C. Wenger
6ca324e790 Fix BMesh split-op failing to output boundary & isovert_map slots
These were defined but never written to.

Part of !129318.
2025-02-18 12:24:01 +11:00
Jason C. Wenger
6a4e7edf8a Fix BMesh split-op failing to output boundary & isovert_map slots
These were defined but never written to.

Part of !129318.
2025-02-18 12:09:05 +11:00
Hans Goudey
947658d1b2 Refactor: Simplify CustomData functions by requiring ImplicitSharingInfo
Previously we generally expected CustomData layers to have implicit
sharing info, but we didn't require it. This PR clarifies that we do
require layers with non-null data to have implicit sharing info. This
generally makes code simpler because we don't have to have a separate
code path for non-shared layers. For example, it makes the "totelem"
arguments for layer freeing functions unnecessary, since shared data
knows how to free itself. Those arguments are removed in this PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/134578
2025-02-17 19:44:54 +01:00
Hans Goudey
c1c67c918e Refactor: Various C++ cleanups to object data transform
Make `XFormObjectData` a real virtual struct instead of using
C style over-allocation. Use C++ arrays and math types.
2025-02-16 20:31:09 -05:00
Hans Goudey
4727dfd627 Cleanup: Remove unnecessary const qualifiers in function declarations 2025-02-14 14:32:57 -05:00
Brecht Van Lommel
c7a33a62a2 Cleanup: Directly include DNA_userdef_types.h and BLI_listbase.h
Instead of relying on them being included indirectly.

Pull Request: https://projects.blender.org/blender/blender/pulls/134406
2025-02-12 23:01:08 +01:00
Hans Goudey
54dc692d7b Refactor: Use StringRef for attribute API and BMesh CustomData functions
Replace `const char *` with `StringRef` for the API in `BKE_attribute.h`.
The benefits are slightly simpler code and possibly slightly improved
performance through avoiding the need to measure string length.

Pull Request: https://projects.blender.org/blender/blender/pulls/134183
2025-02-06 21:38:19 +01: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
Campbell Barton
c86d3b429e Cleanup: spelling in comments 2025-01-30 14:18:40 +11:00