Commit Graph

891 Commits

Author SHA1 Message Date
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
Hans Goudey
3d57bc4397 Cleanup: Move several blenkernel headers to C++
Mostly focus on areas where we're already using C++ features,
where combining C and C++ APIs is getting in the way.

Pull Request: https://projects.blender.org/blender/blender/pulls/114972
2023-11-16 11:41:55 +01:00
Jeroen Bakker
b56382b38a Cleanup: Make format 2023-11-07 08:04:17 +01:00
Campbell Barton
611930e5a8 Cleanup: use std::min/max instead of MIN2/MAX2 macros 2023-11-07 16:33:19 +11:00
Jesse Yurkovich
abb6e9471f Fix #113993: Bevel cutoff intersection type crash
Own mistake in d47ceb53f8

The old calls to `BLI_array_staticdeclare` were deceptive. Because no
appends were done after declaration, to actually use the array, the
variables remained null. Effectively `nullptr` was always being passed
in here.

Pull Request: https://projects.blender.org/blender/blender/pulls/114049
2023-10-24 00:29:46 +02:00
Hans Goudey
e52b269283 Cleanup: Use simpler copying with begin iterator and count 2023-10-20 20:07:02 +02:00
Hans Goudey
89e3ba4e25 Mesh: Replace auto smooth with node group
Design task: #93551

This PR replaces the auto smooth option with a geometry nodes modifier
that sets the sharp edge attribute. This solves a fair number of long-
standing problems related to auto smooth, simplifies the process of
normal computation, and allows Blender to automatically choose between
face, vertex, and face corner normals based on the sharp edge and face
attributes.

Versioning adds a geometry node group to objects with meshes that had
auto-smooth enabled. The modifier can be applied, which also improves
performance.

Auto smooth is now unnecessary to get a combination of sharp and smooth
edges. In general workflows are changed a bit. Separate procedural and
destructive workflows are available. Custom normals can be used
immediately without turning on the removed auto smooth option.

**Procedural**

The node group asset "Smooth by Angle" is the main way to set sharp
normals based on the edge angle. It can be accessed directly in the add
modifier menu. Of course the modifier can be reordered, muted, or
applied like any other, or changed internally like any geometry nodes
modifier.

**Destructive**
Often the sharp edges don't need to be dynamic. This can give better
performance since edge angles don't need to be recalculated. In edit
mode the two operators "Select Sharp Edges" and "Mark Sharp" can be
used. In other modes, the "Shade Smooth by Angle" controls the edge
sharpness directly.

### Breaking API Changes
- `use_auto_smooth` is removed. Face corner normals are now used
  automatically   if there are mixed smooth vs. not smooth tags. Meshes
  now always use custom normals if they exist.
- In Cycles, the lack of the separate auto smooth state makes normals look
  triangulated when all faces are shaded smooth.
- `auto_smooth_angle` is removed. Replaced by a modifier (or operator)
  controlling the sharp edge attribute. This means the mesh itself
  (without an object) doesn't know anything about automatically smoothing
  by angle anymore.
- `create_normals_split`, `calc_normals_split`, and `free_normals_split`
  are removed, and are replaced by the simpler `Mesh.corner_normals`
  collection property. Since it gives access to the normals cache, it
  is automatically updated when relevant data changes.

Addons are updated here: https://projects.blender.org/blender/blender-addons/pulls/104609

### Tests
- `geo_node_curves_test_deform_curves_on_surface` has slightly different
   results because face corner normals are used instead of interpolated
   vertex normals.
- `bf_wavefront_obj_tests` has different export results for one file
  which mixed sharp and smooth faces without turning on auto smooth.
- `cycles_mesh_cpu` has one object which is completely flat shaded.
  Previously every edge was split before rendering, now it looks triangulated.

Pull Request: https://projects.blender.org/blender/blender/pulls/108014
2023-10-20 16:54:08 +02:00
Campbell Barton
91ec9bc5a7 Cleanup: don't use DOXYGEN blocks for inline comments 2023-10-11 10:49:07 +11:00
Jesse Yurkovich
d47ceb53f8 Cleanup: Replace usage of old BLI_array macros with C++ types
This replaces the older dynamic c arrays with blender::Vector as
appropriate. Many files required minimal changes and the before/after
are quite similar.

There's 3 remaining usages of the old machinery but those will require
more involved changes and design.

See #103343

Pull Request: https://projects.blender.org/blender/blender/pulls/110981
2023-10-06 03:02:17 +02:00
Peng Yan
dcb2c0bdf6 BMesh: remove redundant calculation from BMesh bisect
Besides being a redundant calculation,
reducing stack memory usage is generally worthwhile.

Ref !113153.
2023-10-04 15:25:07 +11:00