Commit Graph

647 Commits

Author SHA1 Message Date
Hans Goudey
7daf5a9483 Merge branch 'blender-v4.2-release' 2024-06-06 17:19:17 -04:00
Hans Goudey
b5022828d6 Fix #122849: Curve to mesh node crash with non-point builtin attributes
If the mesh has a curve builtin attribute that's not stored on the point domain,
the creation of the attribute will fail and it can't be interpolated. Possibly this
could be supported somehow, by averaging all the values in the curve's points
or so, but for now just avoid the crash.
2024-06-06 17:18:45 -04:00
Falk David
a40a4ccb2f GPv3: Draw Tool: Make "Simplify" option a screen space threshold
Previously, the "Simplify" option was a world space distance threshold.
This meant that zooming in and out of the view changed the way
this option behaved. There were complaints from artists about this.

This change improves two things:
* The simplify algorithm uses the screen space coordinates rather than the
  3D positions.
* The UI setting is in pixels making it much easier to tweak (no need
  for values in the 1e-4 range).

Pull Request: https://projects.blender.org/blender/blender/pulls/122719
2024-06-05 15:06:49 +02:00
Hans Goudey
c4fc19f064 Cleanup: Use reference argument for BKE_mesh_copy_for_eval 2024-05-20 13:18:24 -04:00
Falk David
7006eb4805 Cleanup: GPv3: Rename add_layer to duplicate_layer
There was an overloaded version of `add_layer` that took
a const reference to a source layer. The function would
duplicate that layer.

The function name `add_layer` was a bit confusing in this
case. Calling it `duplicate_layer` makes it a bit clearer.
2024-05-13 17:44:10 +02:00
Falk David
737572ed88 Cleanup: GPv3: Use GreasePencil::layer function instead of GreasePencil::layers
This also ensures that there is an assert that checks
for valid indices before accessing the span of layers.
2024-05-08 12:35:06 +02:00
Falk David
bba4555526 Refactor: GPv3: Remove get_eval_grease_pencil_layer_drawing* functions
As part of #121565.

To avoid using drawing indices outside of the internal grease pencil API,
this refactor adds the functions `GreasePencil::get_eval_drawing` to replace
the `get_eval_grease_pencil_layer_drawing*` functions.

Pull Request: https://projects.blender.org/blender/blender/pulls/121567
2024-05-08 12:27:40 +02:00
Iliya Katueshenock
4e3af58885 Cleanup: Avoid unnecessary copies of VArray
Cleanup to avoid unnecessary copies of VArray. This
requires ref-qualifier overloads of dereference operator
of attribute reader and some move operators and constructor
overloads in the code.

Pull Request: https://projects.blender.org/blender/blender/pulls/118437
2024-05-07 04:02:17 +02:00
Jacques Lucke
2a765858d8 Cleanup: quiet warning 2024-05-06 15:45:18 +02:00
Arye Ramaty
1db538683d Geometry Nodes: add selection and depth options to Realize Instances node
Previously, the Realize Instances node would always realize everything in the geometry.
Now it's possible to more selectively realize parts of the geometry:
* One can choose which top level instances should be realized.
* The realization depth can be controlled per top-level instance. For example, if there are
  5 top level instances, each of which contains 10 other instances, it's now possible to
  realize only one level so that one ends up with 50 instances.

Pull Request: https://projects.blender.org/blender/blender/pulls/116582
2024-05-03 12:47:59 +02:00
Campbell Barton
c9dba4d31f Cleanup: use const variables & argument, remove duplicate include 2024-04-29 09:09:44 +10:00
Campbell Barton
c0def6c93d Cleanup: spelling in comments 2024-04-27 11:58:02 +10:00
Campbell Barton
56f80ebbcd UV: avoid small allocations in PackIsland::finalize_geometry
Use the memory arena for convex vertices as well as the index buffer.
2024-04-26 13:55:37 +10:00
Lukas Tönne
91f1f3fc06 GPv3: Implementation of sculpt mode tools
This implements all the sculpt tools in Grease Pencil 3.

UI changes in the 3D view header and keymap entries for sculpt mode are
still minimal, more entries should be added once the relevant operators
are supported.

A set of utility functions and a shared base class
`GreasePencilStrokeOperationCommon` for sculpt operations has been added
to make individual operations less verbose.
The `GreasePencilStrokeParams` struct bundles common arguments to reduce
the amount of boilerplate code. The `foreach_editable_drawing` utility
function takes care of setting up the parameters and finding the right
drawings, so the tool only has to modify the data. Common features like
tracking mouse movement and inverting brush influence are handled by the
common base class.

Most operations are then relatively simple, with the exception of the
Grab and Clone operations.
- __Grab__ stores a stroke mask and weights on initialization of the
  stroke, rather than working with the usual selection mask.
- __Clone__ needs access to the clipboard, which requires exposing the
  clipboard in the editor API.

Pull Request: https://projects.blender.org/blender/blender/pulls/120508
2024-04-25 20:20:27 +02:00
Campbell Barton
cb164dabab Cleanup: avoid redundant call to BLI_heap_clear
Add an assertion that the heap is always cleared.
2024-04-25 23:21:32 +10:00
Jacques Lucke
3f2c4db951 Curves: support more curve type conversion options in edit mode
This adds a new `Handles` checkbox to the conversion operator that
affects how the conversion works in the following cases:
`Bezier -> Catmull Rom / Poly / Nurbs` and `Catmull Rom -> Nurbs`.
If enabled, three control points are added for each original control
point, otherwise only one.

-----

The images show the effect of the toggle. The top result is always the one with handles and the bottom one without.
* `Bezier -> Poly`
  ![image](/attachments/c4833568-fb8a-415e-b4fc-a8af2002ded8)
* `Bezier -> Catmull Rom`
  ![image](/attachments/df62e4c0-1a88-4f04-aa82-506bc40765a2)
* `Bezier -> Nurbs`
  ![image](/attachments/3b78d49d-c840-4c15-a342-050fb1f5c3f5)
* `Catmull Rom -> Nurbs`
  ![image](/attachments/de9a4c08-d442-4f97-a0e0-6393b0f0e6de)

Pull Request: https://projects.blender.org/blender/blender/pulls/120423
2024-04-25 10:56:43 +02:00
Campbell Barton
7337d97e13 Fix #120231: Unwrap can crash with shape_method='CONVEX'
There was no check for a convex hull with 1-2 points,
causing unwrap to crash on degenerate faces.

Regression caused by [0] (fix for #115061), which hid this bug.

[0]: 0053de6556
2024-04-25 18:02:33 +10:00
Hans Goudey
7dad324845 Fix: Lite build error after recent commit
Mistake in 0c3763ddda
2024-04-23 13:49:30 -04:00
Hans Goudey
0c3763ddda Geometry Nodes: Add SDF grid boolean nodes
Add a simple node to compute the intersection, difference, or union
between SDF grids. This should be the first new use case for the
new volume grid nodes that wasn't possible before.

For naming and multi-inputs, the node uses the same design as the
mesh boolean node. We considered splitting each operation into a
separate node, but though most users considered these different
"modes" of the same operation.

One thing to keep in mind is that it's important for the grids to
have exactly the same transform. If they have different transforms,
the second grid must be resampled to match the first, because the
OpenVDB CSG tools have that requirement. Resampling is expensive
(for SDF grids it means a grid -> mesh -> grid round trip) and should
be avoided.

Pull Request: https://projects.blender.org/blender/blender/pulls/118879
2024-04-23 14:48:59 +02:00
Campbell Barton
fd589fdca4 Cleanup: various non functional C++ changes 2024-04-20 13:46:14 +10:00
Hans Goudey
d95b1f120b Mesh: Store BMEditMesh in shared pointer
The main motivation for this is that it's part of a fix for #113377,
where I want to propagate the edit mesh pointers through copied
meshes in modifiers and geometry nodes, instead of just setting the
edit mesh pointer at the end of the modifier stack. That would have
two main benefits:
1. We avoid the need to write to the evaluated mesh, after evaluation
  which means it can be shared directly among evaluated objects.
2. When an object's mesh is completely replaced by the mesh from another
   object during evaluation (with the object info node), the final edit
   mesh pointer will not be "wrong", allowing us to skip index-mapped
   GPU data extraction.

Beyond that, using a shared pointer just makes things more automatic.
Handling of edit mesh data is already complicated enough, this way some
of the worry and complexity can be handled by RAII.

One thing to keep in mind is that the edit mesh's BMesh is still freed
manually with `EDBM_mesh_free_data` when leaving edit mode. I figured
that was a more conservative approach for now. Maybe eventually that
could be handled automatically with RAII too.

Pull Request: https://projects.blender.org/blender/blender/pulls/120276
2024-04-18 13:52:20 +02:00
Campbell Barton
cf37424203 Cleanup: use const pointers, quiet cppcheck unreadVariable warning 2024-04-17 11:36:38 +10:00
Hans Goudey
3744b54790 Cleanup: Fix location of #pragma once in some headers 2024-04-12 12:52:51 -04:00
Jacques Lucke
f771f83029 Geometry Nodes: better support for tiny triangles in reverse uv sampling
The reverse uv sampling operation generally fails when there the sample position
is within more than one uv triangle. Unfortunately, the combination of limited
floating point accuracy and very small triangle areas caused this case
sometimes, even if the triangles don't actually overlap. This happens relatively
rarely, but if it does, it causes annoying artifacts. The solution is to only
detect these kinds of overlapping triangles if they have a certain minimum size
and to be more relaxed otherwise.

Pull Request: https://projects.blender.org/blender/blender/pulls/120408
2024-04-11 17:15:55 +02:00
Hans Goudey
e7339bdd5f Geometry: Use implicit sharing for deformed positions
Avoid copying the positions array into the evaluated edit hints array
that's used to support editing with deformed positions when there is
a topology-changing procedural operation. In a simple test in sculpt
mode with 706k curve points, memory usage went from 78 to 70 MB.

This adds more duplication would be ideal, mainly because retrieving
the data with write access and making implicit sharing info for arbitrary
arrays aren't abstracted by implicit sharing utilities. It may be possible
to improve both of those aspects, either now or in the future.

Pull Request: https://projects.blender.org/blender/blender/pulls/120146
2024-04-03 14:14:34 +02:00
Campbell Barton
686605a6dd Cleanup: declare arrays as const where possible 2024-03-28 22:57:57 +11:00
Campbell Barton
b2e00d1285 Cleanup: use const pointer arguments 2024-03-28 20:57:50 +11:00
Falk David
f8ef2b3e78 Curves: Add simplify_curve_attribute function
Compute an index masks of points to remove to simplify the curve attribute using the Ramer-Douglas-Peucker algorithm.

The Ramer-Douglas-Peucker algorithm finds a set of points in a polyline to remove so that the overall shape of the polyline is similar. How similar can be controlled by the distance `epsilon`.

The function takes a `GSpan` so it can be used with any attribute (that has a type `float`, `float2`, or `float3`).

Pull Request: https://projects.blender.org/blender/blender/pulls/118560
2024-03-26 15:28:11 +01: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
57dd9c21d3 Cleanup: spelling in comments 2024-03-21 10:02:53 +11:00
Jacques Lucke
b99c1abc3a BLI: speedup memory bandwidth bound tasks by reducing threading
This improves performance by **reducing** the amounts of threads used for tasks
which require a high memory bandwidth.

This works because the underlying hardware has a certain maximum memory
bandwidth. If that is used up by a few threads already, any additional threads
wanting to use a lot of memory will just cause more contention which actually
slows things down. By reducing the number of threads that can perform certain
tasks, the remaining threads are also not locked up doing work that they can't
do efficiently. It's best if there is enough scheduled work so that these tasks
can do more compute intensive tasks instead.

To use this new functionality, one has to put the parallel code in question into
a `threading::memory_bandwidth_bound_task(...)` block. Additionally, one also
has to provide a (very) rough approximation for how many bytes are accessed. If
the number is low, the number of threads shouldn't be reduced because it's
likely that all touched memory can be in L3 cache which generally has a much
higher bandwidth than main memory.

The exact number of threads that are allowed to do bandwidth bound tasks at the
same time is generally highly context and hardware dependent. It's also not
really possible to measure reliably because it depends on so many static and
dynamic factors. The thread count is now hardcoded to 8. It seems that this many
threads are easily capable of maxing out the bandwidth capacity.

With this technique I can measure surprisingly good performance improvements:
* Generating a 3000x3000 grid: 133ms -> 103ms.
* Generating a mesh line with 100'000'000 vertices: 212ms -> 189ms.
* Realize mesh instances resulting in ~27'000'000 vertices: 460ms -> 305ms.

In all of these cases, only 8 instead of 24 threads are used. The remaining
threads are idle in these cases, but they could do other work if available.

Pull Request: https://projects.blender.org/blender/blender/pulls/118939
2024-03-19 18:23:56 +01:00
Hans Goudey
15c060548a Fix: Build error in lite build after boolean change 2024-03-14 18:50:25 -04:00
Hans Goudey
972c52feb9 Cleanup: Use enum class for boolean operation
Similar to the recently introduced `Solver` enum. This is just friendlier
and doesn't require including `DNA_node_types.h` in the geometry
module header. There's no strong benefit to declaring these enums in
DNA in practice.
2024-03-14 17:24:27 -04:00
Howard Trickey
e3f030cce6 Geometry Nodes: Add float solver to mesh boolean node
This adds a "Solver" option to the geo boolean node, with the options
Exact and Float.
The current geo boolean node only uses the Exact solver.
This adds the ability to use the faster original floating point boolean solver.
The float solver has issues with coplanar and other coincident geometry,
but is generally much faster than the Exact solver, and users have asked
for this option (which is available in the Boolean Modifier and edit mode
boolean tool).

Like the modifier, the Float solver needs to convert the Mesh to BMesh,
do the operation, and then convert back to Mesh. It also has to do it
iteratively if more than two operands are supplied.

This is the first of a planned series of commits that will add a
new exact boolean solver, based on the Ember paper, as a solver option.
Ember will be much faster than the current exact solver, but may still not
be as fast as float, and also will not handle some non-volume-enclosing
inputs as well as Float, so it is likely that the Float solver will always remain.
We may eventually retire the old Exact Solver, however.

This commit also prepares for more sensible code in the future by
changing the internal enum names for the solvers to better reflect the
algorithms used: Fast -> Float, and Exact -> Mesh_Arr (which means
"Mesh Arrangments, the name of the paper upon which the current
exact solver is based).

Co-authored-by: Howard Trickey <trickey@google.com>
Co-authored-by: Hans Goudey <hans@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/119294
2024-03-14 20:49:57 +01:00
Falk David
986577f4ce Merge branch 'blender-v4.1-release' 2024-03-12 14:59:23 +01:00
Iliya Katueshenock
29ff84352f Fix #118905: Geometry Nodes: GP3 component and face corner in separate geometry node
Pull Request: https://projects.blender.org/blender/blender/pulls/118916
2024-03-12 14:41:23 +01:00
Howard Trickey
17b2ff6119 Refactor: rename files mesh_boolean_convert to mesh_boolean.
A follow-up to previous commit that moved these files to geometry.
The _convert suffix made sense at one point but is now just confusing.
2024-03-12 07:00:33 -04:00
Howard Trickey
70fa3becad Refactor: Move mesh_boolean_convert from blenkernel to geometry.
Header file is renamed to GEO_mesh_boolean_convert.cc and
files that included it are updated to use that path.
This is in preparation for bigger changes to the internal
boolean API, which make more sense as a "geometry" API
than a kernel API.

Pull Request: https://projects.blender.org/blender/blender/pulls/119336
2024-03-11 18:17:57 +01:00
Jacques Lucke
0a430fb8cb Geometry: speedup reverse UV sampler
This implements a new internal data structure for reverse uv sampling.
Being better than the previous one was not particularly hard, because it
was never really optimized and used a very simple approach. I found the
new implementation to be about 10-20x faster in my tests. Simon was
able to reproduce an comparable speedups in production files.

The speed-up is mainly achieved by a better memory layout and better
multi-threading during construction. The lookup performance is mostly the
same as before.

Like the old data structure, the new one also splits the uv space into
uniformly sized cells.  The size of the cells is based on the number of
triangles. Then it sorts all triangles into the rows that they touch. Finally,
it creates a flat array for each row that contains the triangle indices
contained in each cell.

There are still ways to optimize this further, but for now this is a good
improvement already.

Pull Request: https://projects.blender.org/blender/blender/pulls/118772
2024-02-29 16:42:36 +01:00
Falk David
f872520025 Fix: Curves: Crash in resample_to_count
The `std::all_of` function wasn't used correcty.
Also, the last value of `dst_offsets` was always 0
(because the offsets were still counts at this point)
so the fix also makes sure the last value
is never included in the check.
2024-02-29 15:08:42 +01:00
Falk David
584d26106a Curves: Provide resample functions that don't depend on field evaluation
This splits the core part of `resample_to_uniform` into it's own function, so that it doesn't depend on field evaluation.

From there, new versions of `resample_to_count`, `resample_to_length`, and `resample_to_evaluated` are provided.

Pull Request: https://projects.blender.org/blender/blender/pulls/118551
2024-02-29 12:51:15 +01:00
Hans Goudey
bea33a6be9 Geometry Nodes: Add volume grid creation nodes
Add three nodes to the currently experimental volume grid nodes:
- **Mesh to Density Grid**
- **Mesh to SDF Grid**
- **Points to SDF Grid**

These nodes are just wrappers over basic OpenVDB utilities.
The difference from existing volume nodes is that they output
a grid directly instead of a geometry set.

See the design here: https://devtalk.blender.org/t/volumes-in-geometry-nodes-proposal/31917

Pull Request: https://projects.blender.org/blender/blender/pulls/118761
2024-02-28 22:15:10 +01:00
Hans Goudey
d338261c55 Cleanup: Pass Span by value
Also pass Span instead of `const Array &`
and use parantheses for BLI includes.
2024-02-27 23:09:54 -05:00
Campbell Barton
a9803765dc Cleanup: remove colon after "return" doxy command 2024-02-28 12:13:17 +11:00
Iliya Katueshenock
6872963e4f Fix #118748: Geometry Nodes: Skip any processing of string attributes
String attributes are not handled correctly (or at all) by geometry nodes
currently because their storage is very inefficient and will likely have to
change in the future anyway. Elsewhere processing string attributes was
explicitly disabled. That was missing in these cases.

Pull Request: https://projects.blender.org/blender/blender/pulls/118802
2024-02-27 23:33:04 +01:00
Hans Goudey
5e96934ef6 Cleanup: Tweaks in add_curves_on_mesh.cc
- Use standard (copy & pasted) linear interpolation utility
- Use helper variable for attributes
- Make some other names a bit simpler
- Remove unnecessary variable
2024-02-27 14:42:12 -05:00
XDzZyq
999dfce736 Sculpt: Add interpolate radius option for curve radius
Add the option to interpolate the radius from nearby curves and
add a fallback radius for when interpolation is turned off or when
there are no neighbors.

Resolves #117101

Pull Request: https://projects.blender.org/blender/blender/pulls/118339
2024-02-27 18:22:03 +01:00
Hans Goudey
9d349896a7 Cleanup: Remove BKE_mesh.hh include from mesh_to_volume.cc
Avoid rebuilding this file when changing BKE_mesh.hh, since it's very slow.
Instead pass the necessary data directly as spans.
2024-02-26 15:04:28 -05:00
Jacques Lucke
d45e6ab0a1 Cleanup: add fmtlib dependency in some modules
This makes it easier to just use e.g. `fmt::println` in these modules.
2024-02-26 12:53:35 +01:00
Hans Goudey
6099252dd4 Instances: Move transforms to attribute
Similar to 2e6223d90f, but potentially 16 times more effective.
The new attribute is named "instance_transform". It isn't displayed in the
spreadsheet since that wouldn't really be useful. This simplifies a lot of
code since it doesn't have to handle transforms specially anymore. But
complexity is added in the store named attribute node and attribute input
node to keep the old "position" attribute working for compatibility.

Pull Request: https://projects.blender.org/blender/blender/pulls/118531
2024-02-22 17:57:09 +01:00