Commit Graph

705 Commits

Author SHA1 Message Date
Bastien Montagne
e08b91f6be Merge branch 'blender-v4.3-release' 2024-10-16 16:46:53 +02:00
Lukas Tönne
297b97f2df Fix #128769: GPv3: Interpolate tool takes selection into account
This makes it so the stroke selection is taken into account by the
interpolation tool.

This does NOT use the selection _order_, just limits interpolation by
index to the selection. The result will be the subset of selected
strokes, excluding non-selected strokes, which is closer to the GPv2
behavior.

The `sample_curve_attribute` function was using the target curve index
for both the src and dst curves. This worked when all the curves are
interpolated, but with selections the dst curve is generally not the
same index as the src curve. The `from_curve_indices` array must be
passed along as well to retrieve the correct source index.

Pull Request: https://projects.blender.org/blender/blender/pulls/129096
2024-10-16 16:41:06 +02:00
Campbell Barton
0d138ec986 Merge branch 'blender-v4.3-release' 2024-10-16 21:08:07 +11:00
Falk David
29b884903a Fix #128914: GPv3: Crash applying modifier to all frames
The issue was that the `merge_layers` function assumed that the
`src_grease_pencil` always returns a drawing when calling
`get_eval_drawing` which can return `nullptr`.

The fix makes sure to check that the `src_drawing` exists.

Pull Request: https://projects.blender.org/blender/blender/pulls/129074
2024-10-16 10:22:58 +02:00
Jeroen Bakker
d1ccebffd0 Cleanup: make format 2024-10-15 08:58:29 +02:00
Campbell Barton
eb36125218 Unbreak build from missing include 2024-10-15 16:20:53 +11:00
Campbell Barton
77b523d317 Fix #128920: Crash calculating geometry nodes that use UV unwrap
Regression in [0], missing null check.

[0]: 788bc5158e
2024-10-14 11:46:34 +11:00
Iliya Katueshenock
6487fc96dd Fix #126024: Separate Geometry nodes does not propagate grease pencil materials
Pull Request: https://projects.blender.org/blender/blender/pulls/128664
2024-10-08 00:27:34 +02:00
Jacques Lucke
99d73565d6 Geometry Nodes: optimize gathering attributes to fix regression
This fixes #127629. It's still a bit slower than it used to be when there are
lots of instances, but that fixes the main bottleneck that was introduced in
#116582. The issue was that we iterated over all attributes of all instances,
but it should only be necessary to iterate over the instances of each unique
geometry only once.

There is still quite some optimization potential in the Realize Instances code
for the case when realizing lots of instances. Especially the code to gather all
geometries that should be realized can still be made more efficient by reducing
redundant work and using multi-threading.

Pull Request: https://projects.blender.org/blender/blender/pulls/128699
2024-10-07 22:18:44 +02:00
Jacques Lucke
9fc0d50846 Cleanup: encapsulate check for whether attribute is built-in 2024-10-07 14:10:38 +02:00
Campbell Barton
4fa3dc0dd4 Cleanup: spelling in comments, use uppercase tags 2024-10-03 12:11:52 +10:00
Campbell Barton
0f3fdd25bc Cleanup: various non-functional changes for C++
- Remove redundant parenthesis
- Use strings macros
- NULL -> nullptr
2024-10-02 15:47:05 +10:00
Campbell Barton
b3a9ca2ac2 Cleanup: remove unused variable 2024-10-01 09:54:29 +10:00
Jacques Lucke
ee348d2bff Fix: missing grease pencil data after duplicate elements or realizing instancecs 2024-09-30 18:31:36 +02:00
Falk David
53b9594ee2 Geometry Nodes: Add "Merge Layers" node
This patch improves working with grease pencil layers in geometry nodes.
* Allow layers to have duplicate names in geometry nodes. In original data, unique names are enforced.
  * This allows e.g. duplicating layers and then merging them by name in the end.
  * It also resolves a big serial bottleneck when working with many grease pencil layers in geometry nodes. Enforcing unique names is inefficient.
* New `Merge Layers` node that can merge multiple layers by name or by a custom group id.
* Applying a grease pencil modifier now first merges all layers with the same name to ensure all names are unique.

Co-authored-by: Jacques Lucke <jacques@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/127873
2024-09-27 13:17:18 +02:00
Jacques Lucke
5c3d215bfc Fix: Geometry Nodes: support Material Selection node for curves
The material handling on curves was not super strong yet because there was not a
lot of need for it. However, now with Grease Pencil it's much more likely that
material selections are used on curves.

The patch is larger than one might expect at first, because we have to pass more
information into the field context in many places, because the materials are
stored on `Curves` and not `CurvesGeometry`.

Related to #128109.

Pull Request: https://projects.blender.org/blender/blender/pulls/128182
2024-09-26 16:22:06 +02:00
Jacques Lucke
6810084a47 Attributes: improve API to iterate over attributes
This improve the API in multiple aspects:
* No need for an additional `lookup` call to get the current attribute. This
  would internally iterate over all attributes again. This leads to O(n^2)
  behavior. Note that there are still other reasons for O(n^2) behavior when
  processing attributes (where n is the number of attributes).
* Remove the need to return a value from the iteration code to indicate that the
  iteration should continue. This is now the default behavior. The iteration can
  still be stopped by calling `iter.stop()`.
* Easier access to `is_builtin` property.
* Iterator callback only has a single parameter instead of two (of which one is
  sometimes unused).

Pull Request: https://projects.blender.org/blender/blender/pulls/128128
2024-09-26 12:59:00 +02:00
Jacques Lucke
6e5e01e630 Geometry Nodes: new For Each Geometry Element zone
This adds a new type of zone to Geometry Nodes that allows executing some nodes
for each element in a geometry.

## Features

* The `Selection` input allows iterating over a subset of elements on the set
  domain.
* Fields passed into the input node are available as single values inside of the
  zone.
* The input geometry can be split up into separate (completely independent)
  geometries for each element (on all domains except face corner).
* New attributes can be created on the input geometry by outputting a single
  value from each iteration.
* New geometries can be generated in each iteration.
    * All of these geometries are joined to form the final output.
    * Attributes from the input geometry are propagated to the output
      geometries.

## Evaluation

The evaluation strategy is similar to the one used for repeat zones. Namely, it
dynamically builds a `lazy_function::Graph` once it knows how many iterations
are necessary. It contains a separate node for each iteration. The inputs for
each iteration are hardcoded into the graph. The outputs of each iteration a
passed to a separate lazy-function that reduces all the values down to the final
outputs. This final output can have a huge number of inputs and that is not
ideal for multi-threading yet, but that can still be improved in the future.

## Performance

There is a non-neglilible amount of overhead for each iteration. The overhead is
way larger than the per-element overhead when just doing field evaluation.
Therefore, normal field evaluation should be preferred when possible. That can
partially still be optimized if there is only some number crunching going on in
the zone but that optimization is not implemented yet.

However, processing many small geometries (e.g. each hair of a character
separately) will likely **always be slower** than working on fewer larger
geoemtries. The additional flexibility you get by processing each element
separately comes at the cost that Blender can't optimize the operation as well.
For node groups that need to handle lots of geometry elements, we recommend
trying to design the node setup so that iteration over tiny sub-geometries is
not required.

An opposite point is true as well though. It can be faster to process more
medium sized geometries in parallel than fewer very large geometries because of
more multi-threading opportunities. The exact threshold between tiny, medium and
large geometries depends on a lot of factors though.

Overall, this initial version of the new zone does not implement all
optimization opportunities yet, but the points mentioned above will still hold
true later.

Pull Request: https://projects.blender.org/blender/blender/pulls/127331
2024-09-24 11:52:02 +02:00
Falk David
3c8d4becc8 Cleanup: GPv3: Return reference from GreasePencil::layer() functions
Since we only assert and never return `nullptr`, it's better to just return a reference.
The access into the span already asserts anyway.

Pull Request: https://projects.blender.org/blender/blender/pulls/128025
2024-09-23 13:54:02 +02:00
Campbell Barton
0d8149d4ff Cleanup: various non-functional changes
- Use const pointers.
- Avoid shadowing variables.
- Remove redundant check.
2024-09-21 23:01:59 +10:00
Lukasz Czyz
788bc5158e UV: add support for the SLIM unwrapping algorithm
Integrate an existing implementation of the SLIM unwrapping algorithm
into Blender. More info about SLIM here:
https://igl.ethz.ch/projects/slim/

This commit is based on the integration code written by Aurel Gruber
for Blender 2.7x (unfinished and never merged with the main branch).

This commit is based on Aurel's code, rebased and further improved.

Details:

- Unwrap has been moved into a sub-menu,
  slim unwrapping is exposed as: "Minimum Stretch".
- Live unwrap with SLIM refines the solutions using a timer.
- When using SLIM there are options to:
  - Set the number of iterations.
  - Weight the influence using vertex weights.
- SLIM can be disabled using the `WITH_UV_SLIM` build option.

Co-authored-by: Aurel Gruber <aurel.gruber@infix.ch>

Ref !114545
2024-09-21 16:48:53 +10:00
Hans Goudey
079a8b395e Geometry Nodes: Optimize realize instances for single component inputs
Previously when there was a single mesh/curve/point cloud/grease pencil
input, the code would still do a deep copy of the entire geometry. Not
only does this waste time and memory usage, it also inhibits the
benefits of the shared cache system, causing normals and other derived
data to be recalculated more than necessary.

This commit makes the realize instance node "free" in those cases.
When the instance has a non-identity transform it only copies and
transforms the positions; the rest of the geometry is untouched.

For the implementation it was simpler to still copy the ID data-block
and rely on implicit sharing to avoid the expense of copying attributes.
That's because we don't have access to the original geometry set
components after all the preprocessing has happened.

Pull Request: https://projects.blender.org/blender/blender/pulls/127867
2024-09-21 04:27:39 +02:00
Campbell Barton
ef098befcb Cleanup: use DEG2RADF macro for clarity 2024-09-21 10:58:20 +10:00
Jacques Lucke
2976520525 Geometry Nodes: transform grease pencil layers instead of points
Transforming the layers instead of points is way more efficient and usually has
the same effect visually. Therefore, it is the better standard behavior.

The main problem with this right now is that layer transforms are stored
as separate location/rotation/scale, so shearing is not supported. This will have
to be solved separately.

Pull Request: https://projects.blender.org/blender/blender/pulls/127757
2024-09-17 17:57:20 +02:00
Hans Goudey
13f179a9c0 Cleanup: Add utility function to sum offset indices group sizes
I've done this a few times and would have benefited from a utility
function for it, apparently it's done in a few more places too. The
utilities aren't multithreaded for now, it doesn't seem important
and often multithreading happens at a different level of the call
stack anyway.

Pull Request: https://projects.blender.org/blender/blender/pulls/127517
2024-09-12 20:28:35 +02:00
Jacques Lucke
bde6f888e2 Geometry Nodes: speedup joining many geometries
Joining many geometries was O(n^2) because of deduplication of the same
components was not done using a map. My test file that generates 1000
stars in a repeat zone got 10x faster, but it's possible to create a file for any
speedup.
2024-09-12 17:49:21 +02:00
Jacques Lucke
7fc7462890 Fix #127448: mesh boolean node stops gizmos from working
The issue is that the boolean node did not propagate edit data and thus lost
information about gizmos. Now the boolean node propagates edit data from
all geometry inputs.

Pull Request: https://projects.blender.org/blender/blender/pulls/127457
2024-09-11 17:20:51 +02:00
Jacques Lucke
8182f684be Fix #127054: crash due to integer overflow in Resample Curves node
This adds a variant of `accumulate_counts_to_offsets` which checks for
overflows. The hot loop stays essentially the same, it just uses a `int64_t`
instead of `int` for the counter now. For now the error state is returned by
using an `std::optional`. Alternatives could be to throw `std::overflow_error`
or to use some Result/Expected type in the future.

Obviously, there are more places that should handle this kind of error. It's
also not obvious how to propagate that error further up yet so that we can
display e.g. a warning in the node. That decision should be applicable to other
nodes too. For now, there is no warning on the node.

Pull Request: https://projects.blender.org/blender/blender/pulls/127184
2024-09-11 16:12:47 +02:00
Campbell Barton
e00fed43e6 Cleanup: redundant struct declarations 2024-09-11 16:25:25 +10:00
Lukas Tönne
81fdae07ef Fix #125922: GPv3 interpolate tool copies curve attributes as well
Interpolate tool was only mixing point attributes, leaving the
output curves without most curve attributes. Now the interpolate_curves
functions actually copy or mix curve attributes as well.

Only float-based attributes are interpolated for now to avoid
meaningless values for material indices, boolean flags, etc. Other
attribute types are simply copied from the first curve in each pair.

Pull Request: https://projects.blender.org/blender/blender/pulls/127350
2024-09-10 17:53:23 +02:00
Iliya Katueshenock
957330043f Refactor: Attributes: support different source and destination domains in propagation utilities
Pull Request: https://projects.blender.org/blender/blender/pulls/127026
2024-09-10 12:59:03 +02:00
Jacques Lucke
2ddc574ad9 Fix #127233: performance regression with new attribute filters
When I first developed the attribute filters they were just a `FunctionRef`
and thus could be stored by value in this struct. Now that they are a
virtual type, that is not possible anymore.
2024-09-07 19:04:54 +02:00
Jacques Lucke
871b25b219 Geometry: generalize attribute filters beyond just for anonymous attributes
This introduces the concept of an #AttributeFilter. It's used to tell a geometry
algorithm which attributes it should process/propagate and which can be ignored.

We already had something similar before named
`AnonymousAttributePropagationInfo`. However, as the name implies, this was
specific to anonymous attributes. This had some downsides:
* A lot of code had to be aware of the concept of anonymous attributes even if
  it did nothing special with anonymous attributes.
* For non-anonymous attributes we often had a separate `Set<std::string> skip`
  parameter. It's not nice to have to pass two kinds of filters around and to
  have to construct a `Set<std::string>` in many cases.

`AttributeFilter` solves both of these downsides.

Technically, `AttributeFilter` could also just be a `FunctionRef<bool(StringRef
attribute_name)>`, but that also has some issues:
* The `bool` return value is often ambiguous, i.e. it's not clear if it means
  that the attribute should be processed or not. Using an enum works better.
* Passing function refs around and combining them works, but can very easily
  lead to dangling references.
* The default value of a `FunctionRef` is "empty", i.e. it can't be called. It's
  generally more nice to not have a special case for the default value. Now the
  default `AttributeFilter` propagates all attributes without any extra handling
  on the call-site.

Pull Request: https://projects.blender.org/blender/blender/pulls/127155
2024-09-05 11:33:35 +02:00
Jacques Lucke
89ae1ba38a Attributes: remove AttributeIDRef in favor of just using strings
Previously, the `AttributeIDRef` wrapper was needed because it also had to
contain a pointer to an `AnonymousAttributeID`. However, since
b279a6d703 this is not necessary anymore.
Therefore we can use "raw" `StringRef` now which reduces the mental overhead
when working with attributes and also simplifies code.

Pull Request: https://projects.blender.org/blender/blender/pulls/127140
2024-09-04 16:13:03 +02:00
Jacques Lucke
d38b7286e9 Cleanup: use StringRef instead of std::string in a few places 2024-09-04 13:07:25 +02:00
Hans Goudey
43a96d6b8d Fix: Compile error from missing includes after attribute ID refactor
b279a6d703
2024-09-03 10:43:07 -04:00
Jacques Lucke
b279a6d703 Refactor: Geometry Nodes: remove AnonymousAttributeID in favor of just strings
This removes `AnonymousAttributeID` which was "attached" to every anonymous
attribute before. It adds more complexity than is justified for its
functionality.

It was originally introduced to keep the reference count of the anonymous
attribute so that it can be deleted automatically when the attribute is not
referenced anymore. For quite some time we have had deterministic attribute
life-times though which don't rely on the reference count anymore.

Anonymous attributes are sometimes shown in the UI as "friendly looking" string
like `"UV Map" from Cube`. Some information necessary for this was also stored
in `AnonymousAttributeID`. However, this can also be solved differently.
Specifically, this functionality has now been added directly to
`AttributeFieldInput`.

This refactor also allows removing `AttributeIDRef` which was mainly introduced
because we had to keep the `AnonymousAttributeID` attached with the attribute
name. Just using simple string types to identify attributes can reduce the
mental overhead quite significantly. This will be done as a separate refactor
though.

Pull Request: https://projects.blender.org/blender/blender/pulls/127081
2024-09-03 15:38:51 +02:00
Bastien Montagne
bb24677a76 Cleanup: Rename CustomData_copy to CustomData_initi_from.
And same for the `copy_layout` function. These functions do not free any
potentially existing data in destination, but expect it to be uninitialized.
Hopefully these new names will make it more clear and avoid bugs like #122160.
2024-08-26 19:11:02 +02:00
Jacques Lucke
7dbff95070 Fix #126450: crash in Sample UV Surface node 2024-08-19 21:01:15 +02:00
Lukas Tönne
4e6dff2995 Cleanup: Use boolean operator to combine booleans instead of bitwise OR
There is a reason for the bitwise operator but it's not explained:
The attribute_foreach function callback has side-effects that the
compiler does not know about (everything is const). Simply replacing
the bitwise operator will cause the second term to be skipped, which
breaks tests due to missing attributes.

Now the term is explicitly evaluated first, then combined with actual
boolean operator.

Pull Request: https://projects.blender.org/blender/blender/pulls/126366
2024-08-15 15:05:02 +02:00
Hans Goudey
2449b12e67 Fix #125929: Add curves creates 1-segment too short curves
Caused by 5e96934ef6.
2024-08-13 12:11:58 -04:00
Hans Goudey
4349d6b766 Fix #126101: Crash with lines generated by geometry nodes grid node
The grid geometry creation incorrectly tagged the mesh with no loose edges
or vertices, breaking invariants of the caches that are relied on elsewhere.
2024-08-09 13:49:06 -04:00
Campbell Barton
c071030ac3 Cleanup: spelling in comments 2024-08-04 13:45:06 +10:00
Falk David
3a43493d85 Curves: Smooth bézier positions function
This adds a `geometry::smooth_curve_positions` function that
smoothes both bézier curves and all the other curve types.

Bézier curves are smoothed by joining the handle and control
points into a flat array, then using the 1D gaussian algorithm
and writing the resulting positions back into the left and right
handle positions as well as the control points. In general,
this works reasonably well and is similar to the results of the
other curve types.

Pull Request: https://projects.blender.org/blender/blender/pulls/125496
2024-07-30 10:25:19 +02:00
Falk David
017c8742cb Fix: GPv3: Crash in realize instances node
This was reported by the studio. When opening one of the lighting
files in 4.3, Blender would crash.

The realize instance task for grease pencil needs to copy all the
layer attributes to the target geometry. When creating the
`dst_attribute_writers` using `lookup_or_add_for_write_only_span`
the `bke::AttrDomain::Point` was used when it should have been
`bke::AttrDomain::Layer`.

Pull Request: https://projects.blender.org/blender/blender/pulls/125603
2024-07-29 15:17:38 +02:00
Campbell Barton
8418ec4952 CMake: include headers in source lists 2024-07-25 11:24:11 +10:00
Campbell Barton
f5ec03698c License headers: add SPDX headers 2024-07-20 13:55:45 +10:00
Jesse Yurkovich
ec4fc2d34a CMake: Modernize the optional TBB dependency
This continues the cmake modernization effort and introduces support for
allowing our optional dependencies to integrate properly. TBB is added
here as it's proven troublesome to maintain correctly.

Currently the only Blender project which uses the TBB headers directly
is `blenlib`.  However, all downstream projects which require blenlib as
their dependency, and wish to properly make use of its threading
facilities, needed to define various TBB items in their CMake files. Not
only is this unnecessary and arcane, but several projects didn't do this
and ended up not using threading as well as producing ODR violations
along the way[1].

This PR makes TBB a modern dependency and exposes it PUBLIC'ly from
`blenlib`.  All downstream projects which depend on blenlib will now
receive everything they require from TBB automatically. This includes
the `WITH_TBB` define, the headers, and the library itself.

[1] blender/blender@05241f47f5

Pull Request: https://projects.blender.org/blender/blender/pulls/124916
2024-07-19 23:30:56 +02:00
Lukas Tönne
0a70096a5b GPv3: Interpolate Tool
Interpolation tool for strokes ported from GPv2.

Adds a new operator that inserts a new frame with interpolated curves.
The source curves are taken from the previous/next keyframe.

Co-authored-by: Hans Goudey <hans@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/122155
2024-07-12 15:59:56 +02:00
Lukas Tönne
d0089e6fe1 GPv3: Automerge feature for joining curve endpoints by distance
This implements the _automerge_ feature which finds nearby end points
during stroke draw and merges the new curve with existing strokes.

New utility functions are added in `geometry` for slightly generalized
functionality. The `curves_merge_endpoints` takes an index map that
describes how to connect curves by index. It performs a topological sort
and reorders connected curves into contiguous ranges. This can be used
with an arbitrary number of connected curves. The tool feature itself
only uses a single curve, based on 2D end point positions.

Unit tests have been added for the curve merge utility function.

Pull Request: https://projects.blender.org/blender/blender/pulls/124459
2024-07-12 11:21:23 +02:00