Commit Graph

525 Commits

Author SHA1 Message Date
Dalai Felinto
3f13471d65 GPv3: Resample Curve node
Reviewed as part of !113581.
2023-10-12 12:25:39 +02:00
Hans Goudey
7507251071 Cleanup: Extract attribute function to copy values from group to group
Use the typical combination of an "array utils" function used by an
attribute interpolation function. This helps moves us towards having
a more centralized implementaiton of attribute propagation that can
be changed and optimized more easily.
2023-10-09 15:23:48 +02:00
Jacques Lucke
63b39c5aeb Merge branch 'blender-v4.0-release' 2023-10-09 11:46:45 +02:00
Iliya Katueshenock
26346464e0 Fix #110666: Copy built-in attributes for masked curves type conversion
Curve type conversion can cause changing of some curves size.
Also, changing of curve type can cause deletion of unnecessary
built-in attributes and creating new ones. All of this make sense
only for converted curves. Others, unselected, should simply make
copy all old attributes, both built-in and not. This fix simply replaces
the last copy from incorrect only non-built-in, to a correct one,
for all attributes.

Pull Request: https://projects.blender.org/blender/blender/pulls/110683
2023-10-09 10:44:35 +02:00
Iliya Katueshenock
ceb8d34319 Cleanup: reduce template usage in join geometries code
Pull Request: https://projects.blender.org/blender/blender/pulls/110436
2023-10-08 19:10:14 +02:00
Jacques Lucke
144a5aa512 Cleanup: replace use of std::iota with more specific function
`iota` is name that has no meaning, it's not an acronym or initialism.
It's usually very cryptic when I come across it. Replacing it with a
specialized function makes the code more readible.
2023-10-06 23:01:16 +02:00
Hans Goudey
4cbcaf51cb Cleanup: Use "vert" term consistently in mesh randomization debug code
In this area the contraction is usally used. It's nice to be consistent.
2023-10-06 16:50:52 -04:00
Hans Goudey
36f7d33121 Fix: False positive geometry randomization in split edges node
See cc7da09c1b.

Splitting edges only potentially affects the order of edges and
vertices. Face corner vertex and edge indices are affected, but their
order isn't affected, and faces aren't affected at all. This didn't
cause problems, but correcting it shows users they can rely on
these consistencies after this operation.
2023-10-06 16:46:49 -04:00
Jacques Lucke
57e914fc8a Cleanup: move join geometry functionality to separate file
This allows us to reuse the functionality more easily.
2023-10-06 18:31:44 +02:00
Hans Goudey
b5b0a296b6 Cleanup: Else after return in curves trim 2023-10-06 10:11:16 +02:00
Jacques Lucke
63e1d06233 Geometry Nodes: add utility for debug randomization of instances
Also see cc7da09c1b.
2023-09-30 16:29:08 +02:00
Jacques Lucke
bafc952f97 Cleanup: Geometry Nodes: pass selection by varray instead of field 2023-09-30 16:27:25 +02:00
Jacques Lucke
08aa71bfc9 Merge branch 'blender-v4.0-release' 2023-09-30 12:40:25 +02:00
Jacques Lucke
cc7da09c1b Geometry: add utility to check for bad geometry element index dependence
Sometimes .blend files have compatibility issues between Blender versions,
because .blend files depended on the specific order of geometry elements
generated by some nodes/modifiers (#112746, #113018). While we make
guarantees about the order in some places, that is relatively rare, because it
makes future improvements much harder. The functionality in this patch
makes it easier for users to notice when they depend on things that are not
expected to be stable between Blender builds.

This is achieved by adding a new global flag which indicates whether some
algorithms should randomize their output. The functionality can be toggled
on or off by searching for `Set Geometry Randomization`. If there are no
differences (or acceptable minor ones) when the flag is on or off, one can
be reasonably sure that one does not on unspecified behavior (can't be 100%
sure though, because randomization might be missing in some places). If
there are big differences, one should consider fixing the file before it comes
to an actual breakage in the next Blender version.

Currently, the setting is only available when `Developer Extras` is turned on,
because the setting is in no menu.

With this patch, if we get bug reports with compatibility issues caused by
depending on indices, one of the following three cases should always apply:
* We actually accidentally broke something, which requires a fix commit.
* Turning on geometry randomization shows that the .blend file depends on
  things it shouldn't depend on. In this case the user has to fix the file.
* We are missing geometry randomization somewhere, which requires a fix
  commit.

Pull Request: https://projects.blender.org/blender/blender/pulls/113030
2023-09-29 21:44:36 +02:00
Iliya Katueshenock
6c14764f32 Fix #112933: Fix codegen issue on MSVC 17.7
MSVC 17.7 generates bad code in some lambda's, this has been reported
upstream [1], and a workaround has been suggested by MS in the form of
turning the inliner off. In consultation with the geo nodes people this
was deemed a passable solution, there was only a single call to this
method so performance wasn't a concern, so no special care had to be
taken to single out just the problematic MSVC versions.

If this bug pops up in other parts of our code where performance IS a
concern a more delicate approach may be required.

[1] https://developercommunity.visualstudio.com/t/10448291

Pull Request: https://projects.blender.org/blender/blender/pulls/112616
2023-09-29 16:57:02 +02:00
Germano Cavalcante
48204b630c Fix #112909, #112922: Weld modifier crashes in some situations
The weld modifier was experiencing crashes due to the `switch_to`
variable occasionally pointing to a collapsed corner.

The encumbrance of the code implementation utilizing `switch_to` was
proving to be problematic as it was escalating the complexity of
maintenance. 

To resolve the issue, a code rewrite was conducted.

The new implementation uses a `loop_next` in place of `switch_to` for
skipping corners.

This modification streamlined the code and improved its stability.

However, this solution does come with minor drawbacks. There is a small
increase in memory consumption and the corner group detection process
is now slightly more computational intensive.

Also the test files need to be updated.
2023-09-27 13:00:06 -03:00
Campbell Barton
e38ff7c06d Cleanup: use C++ comments for disabled code 2023-09-25 17:06:04 +10:00
Campbell Barton
5fbcb4c27e Cleanup: remove spaces from commented arguments
Also use local enums for `MA_BM_*` in versioning code.
2023-09-22 12:21:18 +10:00
Brecht Van Lommel
89b3249c14 UV: when finding the best packing method, use area as tie breaker
When multiple packing methods results in effectively the same bounds,
prefer the packer that uses the smallest area. When all islands can
easily fit this is usually the box packer instead of alpaca. The zigzag
method of the latter has a tendendcy to take up more area and rotate
islands.

Fix #110724: smart UV project unnecessarily rotates islands

Pull Request: https://projects.blender.org/blender/blender/pulls/112295
2023-09-14 18:57:26 +02:00
Brecht Van Lommel
d4cc0d02cb UV: disable best fit rotation of all islands at end of UV packing
This has a tendency to place islands diagonally in the image which is
not usually wanted, even if it's maximimizing the number of pixels for
the island.

Fix #109906: UV unwrap packs island diagonally instead of straight

Pull Request: https://projects.blender.org/blender/blender/pulls/112295
2023-09-14 18:57:26 +02:00
Campbell Barton
b7f3e0d84e Cleanup: spelling & punctuation in comments
Also remove some unhelpful/redundant comments.
2023-09-14 13:25:24 +10:00
Hans Goudey
dd9f196c2e Mesh: Pre-fill loose verts and bounds cache of line primitive
On a Ryzen 7950x, saves about 30 ms of work every frame where a 10
million vertex line is rebuild from scratch.
2023-09-11 16:52:45 -04:00
Hans Goudey
7344c7875a Geometry: Move mesh primitives from nodes to geometry module
This makes the code reusable in a few more places,
particularly by tests for a new boolean implementation
also defined in the geometry module.

It also makes the way some primitives are reused among
different nodes a bit clearer.

Pull Request: https://projects.blender.org/blender/blender/pulls/112255
2023-09-11 22:49:41 +02:00
Hans Goudey
67aad1f72d Cleanup: Remove unused includes in cuboid primitive 2023-09-11 16:13:39 -04:00
Campbell Barton
d897fd34cb UV: restore internal solver state variable
Removed in [0] however I think it helps track the state,
so restore the state and assertions.

[0]: 8ace65e3c6
2023-09-08 23:09:51 +10:00
Campbell Barton
a4aa5adf44 Fix #110729: Unwrap angle based fails with seams
Regression [0] which merged index assignment into an earlier loop.
This caused the indices to be overwritten by p_chart_abf_solve
causing unwrap to fail.

[0]: 8ace65e3c6
2023-09-08 22:30:14 +10:00
Hans Goudey
2cc3a63216 Cleanup: Remove mesh validation assert in mesh code
These asserts are helpful for development, but are too expensive and
strict to live permanently in debug builds.

Resolves #112035
2023-09-06 15:37:35 -04:00
Hans Goudey
fa34992def Cleanup: Remove unnecessary includes from C++ data structure headers
The hash tables and vector blenlib headers were pulling many more
headers than they actually need, including the C base math header,
our C string API header, and the StringRef header. All of this
potentially slows down compilation and polutes autocomplete
with unrelated information.

Also remove the `ListBase` constructor for `Vector`. It wasn't used
much, and making it easy to use `ListBase` isn't worth it for the
same reasons mentioned above.

It turns out a lot of files depended on indirect includes of
`BLI_string.h` and `BLI_listbase.h`, so those are fixed here.

Pull Request: https://projects.blender.org/blender/blender/pulls/111801
2023-09-01 21:37:11 +02:00
Campbell Barton
4a42f2b07c Cleanup: spelling 2023-08-31 10:38:13 +10:00
Hans Goudey
7c57eb42d7 Fix #111582: Delete geometry node incorrectly marks no loose vertices
The logic for telling when there are no loose edges or vertices was
incorrect.
2023-08-30 18:16:22 -04:00
Hans Goudey
4e94db97e2 Mesh: Add three cached topology maps
Add three cached topology maps to `Mesh`, to avoid computations when
mesh data isn't changed. Choosing the right maps to cache is a bit
arbitrary, but generally we have to start somewhere. The limiting
factor is memory usage (all the new caches combined have a
comparable footprint to a UV map).

For now, the caches added are:
- Vertex to face corner
- Vertex to face
- Face corner to face

These caches are used in quite a few places already;
- Face corner normal calculation
- UV value merging
- Setting sharp edges from face angles
- Data transfer modifier
- Voxel remesh attribute remapping
- Sculpt mode painting
- Sculpt mode normal calculation
- Vertex paint mode
- Split edges geometry node
- Mesh topology geometry nodes

Caching topology maps means they don't have to be rebuilt every time
they're used. Meshes copied but without topology changes can share
the cache, further reducing re-computations. For example, FPS with a
large mesh using the "Corners of Vertex" node went from 1.8 to 2.3.
Entering sculpt mode is slightly faster too.

There is some obvious work for future commits:
- Use caches in attribute domain interpolation
- More multithreading of second phase of map building
- Update/build caches eagerly in some geometry nodes

Pull Request: https://projects.blender.org/blender/blender/pulls/107816
2023-08-30 23:41:59 +02:00
Hans Goudey
f41dc90925 Mesh: Rewrite split edges algorithm
The new split edges code from e83f46ea76 started the use of
Mesh rather than BMesh as a performance improvement. However, the code
contained a complex loop used for de-duplicating edges that gave invalid
indices in some circumstances. That was fixed by b226c115e2,
but in turn that commit caused loose edges to be skipped. That was
fixed by 111e378366, however that caused another crash.

Long story short, the code is quite complex and the existing algorithm,
while an improvement from the original, is fiddly. For example, instead
of working with just the input and output states, it adjusted topology
data for an intermediate state halfway through the change.

Fixes #109236

**Goals**
- Only use topology maps from the input mesh. This should work better
  with future topology caching improvements (See !107816).
- Run de-duplication in a per-edge context to allow parallelization.
- Optimize for real world use cases when there is merging of new edges.
- Improve readability by making each step's inputs clear, improving naming,
  and separating functions.
- Improve handling of loose edges.
- Reuse existing edges for the first new split edges, simplifying
  edge attribute propagation.

**Timing**
I tested performance with a Ryzen 7950x and a grid with 4 million faces
with different random portions of the mesh selected.

| Selection | Before (ms) | After (ms) | Change |
| --------- | ----------- | ---------- | ------ |
| 100%      | 1869.4      | 351.8      | 5.3x  |
| 50%       | 1636.0      | 356.0      | 4.6x  |
| 10%       | 1148.8      | 238.2      | 4.8x  |

| 4 Million Face Grid             | 10%  | 50%  | 100% |
| ------------------------------- | ---- | ---- | ---- |
| `vert_selection_from_edge`      | 2.7  | 4.1  | 4.3  |
| `selection_to_bit_vector`       | 0.7  | 3.9  | 0.2  |
| `vert_to_corner_map`            | 22.3 | 22.5 | 22.4 |
| `edge_to_corner_map`            | 47.7 | 47.6 | 47.6 |
| `corner_to_face_map`            | 3.3  | 3.3  | 3.3  |
| `calc_all_corner_groups`        | 21.0 | 44.1 | 38.3 |
| `calc_vert_ranges_per_old_vert` | 3.0  | 7.4  | 7.9  |
| `update_corner_verts`           | 2.8  | 12.7 | 15.5 |
| `calc_new_edges`                | 28.8 | 44.1 | 35.5 |
| `update_unselected_edges`       | 9.8  | 9.3  | 0.0  |
| `propagate_edge_attributes`     | 35.7 | 51.3 | 61.7 |
| `propagate_vert_attributes`     | 24.0 | 27.0 | 31.7 |
| `propagate_vert_attributes`     | 24.2 | 29.7 | 36.9 |

**Tests**
New regression tests have been committed separately. Existing
tests were updated since the new code gives different indices.
2023-08-30 14:23:42 +02:00
Hans Goudey
7563b96945 Geometry Nodes: Avoid attribute copy in simple case of points to curves
When the final curve point indices are in the same order as the input
points, and there are many curves, avoid copying point domain
attributes, by generalizing the existing check from the mesh
to curve conversion node.

Pull Request: https://projects.blender.org/blender/blender/pulls/111662
2023-08-29 20:12:47 +02:00
Harley Acheson
1e0ddab5b8 Cleanup: Make format
Just formatting changes in mesh_merge_by_distance.cc
2023-08-28 21:38:38 -07:00
Hans Goudey
df7f22d28e Cleanup: Simplify mesh primitive grid and cuboid quad creation
Fill face offsets in one multithreaded loop with an offset indices
utility function instead of keeping track of the index and setting
the offset for each face.
2023-08-28 21:57:22 -04:00
Germano Cavalcante
a0c5467b7d Fix #111592: Merge modifier may crash in some cases
The count of faces destroyed could be wrong when more than one groups
of vertices on the same face resulted in the face collapsing.

The solution is to break the loop on the first collapsed face
detection.

Caused by 6ec842c43c.
2023-08-28 14:33:48 -03:00
Campbell Barton
33a05725be Cleanup: spelling in comments 2023-08-21 10:05:45 +10:00
Campbell Barton
c713c70781 CMake: quiet uninitialized warnings 2023-08-17 11:53:56 +10:00
Aras Pranckevicius
2f060706a4 Cleanup: fewer BLI_color.hh et al includes
Include counts of some headers while making full blender build:
- BLI_color.hh 1771 -> 1718
- BLI_math_color.h 1828 -> 1783
- BLI_math_vector.hh 496 -> 405
- BLI_index_mask.hh 1341 -> 1267
- BLI_task.hh 958 -> 903
- BLI_generic_virtual_array.hh 509 -> 435
- IMB_colormanagement.h 437 -> 130
- GPU_texture.h 806 -> 780
- FN_multi_function.hh 331 -> 257

Note: DNA_node_tree_interface_types.h needs color include only
for the currently unused (but soon to be used) socket_color function.
Future step is to figure out how to include
DNA_node_tree_interface_types.h less.

Pull Request: #111113
2023-08-16 14:48:53 +03:00
Campbell Barton
e955c94ed3 License Headers: Set copyright to "Blender Authors", add AUTHORS
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.

While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.

Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.

Some directories in `./intern/` have also been excluded:

- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.

An "AUTHORS" file has been added, using the chromium projects authors
file as a template.

Design task: #110784

Ref !110783.
2023-08-16 00:20:26 +10:00
Campbell Barton
12538b75e9 Cleanup: unused but set variable warning 2023-08-12 16:29:48 +10:00
Germano Cavalcante
6ec842c43c Merge by Distance: Redo face split code
The split face code relied a lot of the edges added to the weld context.

But with 113004687d, some edges are removed from context. And even more
edges can be removed (reducing loops and arrays).

Removing the dependence on edges decreases the array and time spent in
loops.

Furthermore, the corner edge array should not be needed for the
merge by distance operation.

So this commit redoes the face/loops iterator which previously
needed the `loop_next` member to skip loops depending on the previous
one (possibly linked to the edge whose vertex will be merged) and now
uses the `switch_to` member to switch loops instead of skipping and
depend on the former.
2023-08-11 16:23:52 -03:00
Aras Pranckevicius
d973355b3a Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).

However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.

This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.

Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
  to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).

Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.

Pull Request #110944
2023-08-10 14:51:40 +03:00
Germano Cavalcante
262b67d61d Fix Weld modifier generating invalid mesh
Bug identified in #110942.

In cases where the last corners of a polygon are out of context, the
`weld_iter_loop_of_poly_next` iterator skips these corners.

This means that some corners of the resulting mesh do not have the
value set, which can even result in infinite loops.

The solution was not simple. The iterator had to be practically redone
to not use the `loop_end` member (which caused the problem).

Fortunately the code is more simplified with this change.
2023-08-09 15:38:37 -03:00
Hans Goudey
dc7979a056 Cleanup: Make geometry set naming more consistent
Remove the "_for_read" suffix from methods to get geometry and geometry
components. That should be considered the default, so the suffix just
adds unnecessary text. This is consistent with the attribute API and
various implicit sharing data access methods.

Use "from_mesh" instead of "create_with_mesh". This is consistent with
the recently used naming for the `IndexMask` API.

Pull Request: https://projects.blender.org/blender/blender/pulls/110738
2023-08-03 17:09:18 +02:00
Campbell Barton
8c8ff6b85b Cleanup: spelling in comments, use C-style comments 2023-08-03 09:44:28 +10:00
Hans Goudey
731d296f35 Cleanup: Move mesh related blenkernel headers to C++
See #103343

Pull Request: https://projects.blender.org/blender/blender/pulls/110730
2023-08-02 22:14:18 +02:00
Hans Goudey
40de15d521 Mesh: Move flip faces function to blenkernel
The aim is to replace the `BKE_mesh_faces_flip` functions with
this newer C++ function using the attribute API. But that is must
be called by RNA, so move this to blenkernel to avoid a circular
dependency between the geometry module and RNA.
2023-08-01 13:08:59 -04:00
Iliya Katueshenock
803589ca5a Fix #110485: Mesh to curve node incorrect implicit sharing crash
Regression caused by 301f13191b.
To share attribute arrays, domain sizes should be the same.

Pull Request: https://projects.blender.org/blender/blender/pulls/110487
2023-08-01 03:53:01 +02:00
Chris Blackbourn
fc2ee7d912 Cleanup: improve uv packing inline comments 2023-07-31 16:49:38 +08:00