Commit Graph

2042 Commits

Author SHA1 Message Date
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
18ba7d1f86 Cleanup: use const arguments for UV checking functions 2025-04-30 12:54:29 +10: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
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
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
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
6ef7dae8ef Cleanup: spelling in comments (make check_spelling_*) 2025-03-13 13:41:17 +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
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
8d97330482 Cleanup: clarify naming for BMesh tangent calculation functions
The newly added "tangent_pair" calculation functions meant the names
didn't read well in some cases, use this style of naming for clarity:

- BM_face_calc_tangent_from_*
- BM_face_calc_tangent_pair_from_*
2025-01-17 15:28:32 +11:00
Campbell Barton
c7104f5392 Fix #96535: Incorrect extrude direction with two faces of a cube
It was possible two quads at right-angles to each other would accumulate
a "tangent" that was co-linear with the it's normal.

Resolve this by calculating two tangents for each face, then using the
accumulated tangent that's least co-linear with the accumulated normal.
2025-01-17 15:17:06 +11:00
Campbell Barton
a586b537af Cleanup: various non-functional changes in C++ 2025-01-17 11:54:43 +11:00
Campbell Barton
bb92a6fbef Fix BMesh quad tangent calculation failure to normalize
This impacted the Python method BMFace.calc_tangent_edge_pair()
2025-01-17 11:31:28 +11:00
Campbell Barton
372ecb847f Fix #108658: Geometry with non-finite coordinates crashes bevel 2025-01-10 16:30:52 +11: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
Campbell Barton
d2d754be3f Cleanup: spelling in comments (make check_spelling*)
- Back-tick quote math expressions so differentiate them
  from English.
- Use doxygen code blocks for TEX expressions.
2025-01-04 16:26:39 +11:00
Hans Goudey
3d0988a719 Cleanup: Move some math C-API usage to C++ API
Mostly part of an attempt to remove some of the lesser-used
parts of the C math API.
2024-12-20 21:46:59 +01:00
Hans Goudey
c5ba8bd7c2 Fix #125098: uv_seam attribute not accessible procedurally
When moving UV seams from special custom data types to attributes,
I considered them similar to mesh selection or visibility which are
"internal" attributes that aren't accessible procedurally and are
hidden from the UI. In retrospect that was the wrong decision; users
expect UV seams to behave more like bevel weights, and that makes sense.

This PR makes UV seams accessible in modifiers (geometry nodes) by
removing the leading period from the attribute name that indicated their
internal status.

The change of the attribute name is a breaking change of the API to some
extent, even though it's technically only mesh data. To mitigate that
issue, the `mesh.attributes["name"]` lookup function is modified to
support both the old and new names. Versioning code renames the
attribute to the new name when loading older files, and renames the
new name to the old name when saving files. That handling will be
removed as a breaking change in 5.0.

Pull Request: https://projects.blender.org/blender/blender/pulls/129803
2024-12-20 16:47:15 +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
160e76cd9d Cleanup: remove unused function BM_mesh_active_elem_index_get
Getting the active index without knowing the element type
doesn't seem to have any practical use.
2024-10-30 15:47:43 +11:00
Campbell Barton
6fae671aa4 Merge branch 'blender-v4.3-release' 2024-10-29 22:48:37 +11:00
Campbell Barton
3f6707efd0 Fix #129401: BMesh.clear() causes crash on garbage collection 2024-10-29 22:47:35 +11:00
Jason C. Wenger
dc57693b0c Modeling: add support for merging triangles with reference to topology
A new parameter, topology influence, is added that causes the
join_triangles operator to prioritize edge joins that create quads with
sensible geometry relative to existing quads, instead of selecting the
'flattest' and 'squarest' next pair and then leaving leftover triangles
with no partners to merge with.

This produces its best results with the face and shape thresholds set to
180 degrees (no hard limits as a restriction against merging) and
topology influence somewhere between 100-130%, depending on the mesh.
Too low and many parallelograms and triangles are left, too high and the
algorithm tries too hard and starts making errors.

Note that both quads already present in the selection, as well as the
quads that are generated during the operator, will influence the
topology around them. This allows the modeler to manually merge a few
quads in key areas of the mesh, as a hint to the algorithm, indicating
what result they way they want to see, and the algorithm will then take
those quads into account and try to build around them according to the
modeler's guidance.

A new checkbox to leave only the remaining triangles selected has also
been added. This helps users visualize what remains to be fixed.

Ref !128610
2024-10-10 17:28:59 +11: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
Hans Goudey
22cf74d23b Cleanup: Use C++ Array for dependent shape key data
Avoids manual memory management and potentially avoids
an allocation with the inline buffer.
2024-09-16 12:46:54 -04:00