Collapsing curves to a single point when just resampling is unexpected. This
patch changes it so that non-zero-length curves keep at least one segment.
The fix is fairly straight forward, but a bunch of additional code is added to
support the legacy option to avoid breaking backward compatibility.
Pull Request: https://projects.blender.org/blender/blender/pulls/133659
Selection mask is included in the stroke interpolation tool in
297b97f2df, however sometimes there will
be mismatches for when start/end curve count isn't the same. This fix
ensures that the interpolation operator only works on the max amount of
curves that can fit in both start and end side of the interpolation.
Pull Request: https://projects.blender.org/blender/blender/pulls/134484
Previously, there was a `StringRef.copy` method which would copy the string into
the given buffer. However, it was not defined for the case when the buffer was
too small. It moved the responsibility of making sure the buffer is large enough
to the caller.
Unfortunately, in practice that easily hides bugs in builds without asserts
which don't come up in testing much. Now, the method is replaced with
`StringRef.copy_utf8_truncated` which has much more well defined semantics and
also makes sure that the string remains valid utf-8.
This also renames `unsafe_copy` to `copy_unsafe` to make the naming more similar
to `copy_utf8_truncated`.
Pull Request: https://projects.blender.org/blender/blender/pulls/133677
The interpolate tool was using a linear re-sampling of the curves, which changes
non-uniform point distributions can causes unexpected shifts in points along the
curve, even very close to an input stroke (mix factor ~0 or ~1).
This patch adds an alternative interpolation function with explicit segment
indices and fractions, which can then be computed by the interpolation tool.
The point segment factors are chosen such that each point of the input strokes
has an exact matching point in the interpolation. When the factor is close to
0 or 1 the shape of the curve thus matches the respective input exactly.
This approach is more similar to what GPv2 did, except instead of sub-dividing
each segment it simply generates a _local_ uniform sample to fit more points
into the same segment. These extra points are colinear at the extremes of the
mix factor range, so the curve matches the input curves visually.
Pull Request: https://projects.blender.org/blender/blender/pulls/130594
The hardcoded value doesn't work well with real scale human heads for
example (was already adjusted once in a76b5d3a07).
The result for too high values is a complete "freeze" of the whole curve
(since the solution from e7606139ba has the problem that it keeps
running into max iterations of the collision solver).
As long as no better solver is implemented, it is better to have an
adjustable value (to work on differently sizes objects) to not run into
the above issue (same as the old particle hair system had) and show it
in sculptmode next to the button which enables collision.
This is done per `Curves` (same as the flag
`CV_SCULPT_COLLISION_ENABLED`), similar to symmetry settings
[alternatively, it could be part of `BrushCurvesSculptSettings` but I
think it makes more sense in Curves] and then passed on to the
`CurvesConstraintSolver`.
Includes versioning code (to set the default for old files).
Pull Request: https://projects.blender.org/blender/blender/pulls/132997
Propagating string attributes isn't supported in many places currently,
the split edges node is not an exception, so skip those attributes as
necessary.
Followup to 80f5b3ad21 which was just
plain wrong. Somehow I missed the whole point and set auto handle types
instead of aligned. In a more thorough dive into this area, there was
some weird structural decisions making things harder than they should be.
This commit slightly simplifies the way the first and last handle of a
segment are set, moving it all to happen in one place and making the
processing of the last cyclic segment a bit simpler. The resulting
handles are aligned if possible.
Pull Request: https://projects.blender.org/blender/blender/pulls/133070
In order to copy vertex group weights when subdividing strokes the
groups (`bDeformGroup`) must be created in advance, so that the attribute
wrappers correctly write to `CD_MDEFORMVERT` layer instead of creating simple
`CD_PROP_FLOAT` layers.
In addition the subdivision function must take care to fully write the
destination arrays, since initial values must be considered uninitialized (this
is obfuscated for simple CustomData arrays but breaks with more complex
attributes that use a buffer). In order to ensure fully defined destination
buffers without additional copies, the `finish` call to attribute writers is
postponed until the unselected attribute values have also been copied from input
buffers and all the values are properly defined.
Pull Request: https://projects.blender.org/blender/blender/pulls/132854
The `smooth_curve_attribute` function smoothes individual
ranges of points that are selected within a stroke.
When smoothing a single range, the `gaussian_blur_1D` function
shouldn't treat this range as cyclic.
Instead, we check if the entire curve is selected and only use
the `cyclic` boolean in this case. For ranges, we always
treat them as non-cyclic.
Pull Request: https://projects.blender.org/blender/blender/pulls/132850
Implicit sharing dramatically reduces the cost of coping geometry
which is extremely helpful for read-only and slight modification.
But case of Sort Elements node implies a total rewrite of whole domain,
so implicit sharing only adds redundant cost for write access. This fix
uses kernel API to create domains without attributes, manually forcing
implicit sharing for offset indices and uses kernel attribute copy
functions to force sharing for all attributes when this is possible.
In all other cases new attributes are created from scratch and copied
as re-ordered only once.
In attached example file shown the difference depend on the number of
attributes on the mesh, benchmark result:
| Attributes | Before | After |
| ---------- | ------ | ----- |
| 1 | 2 ms | 1.5 ms |
| 5 | 5 ms | 4 ms |
| 10 | 9 ms | 6 ms |
| 50 | 45 ms | 30 ms |
| 100 | 89 ms | 59 ms |
Pull Request: https://projects.blender.org/blender/blender/pulls/117910
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
Caused by 84c7684871.
Previously we could count on adding the attributes to the result mesh
not failing. Now, since the vertex group names are copied, they might
fail because a name would cause the attribute to already exist with a
float type on the point domain, which might not match the most
complex domain/type we'd use otherwise.
The fix is to only create attributes as vertex groups if the domain and
type combination from all the input meshes is correct.
Pull Request: https://projects.blender.org/blender/blender/pulls/132506
I had written a comment years ago mentioning that this behavior would be
preferrable, but I mistakenly assumed it was complicated to implement.
It turns out the sampled points subdividing a Bezier segment will have
symmetric "aligned" handle positions. Generally it's better to keep the
handles aligned where possible since the editing experience is a bit better.
In geometry nodes this shouldn't make an important difference because
the handle types are changed as necessary for in the set handle position
node.
Pull Request: https://projects.blender.org/blender/blender/pulls/132204
The realize instances code didn't have a way to use the existing
`#BuiltinAttributeProvider::default_value()`s to initialize attributes that
have to be created.
Now this writes default values of builtin attributes to the curve `attribute_fallbacks`.
Removes the need for the code to explicitly write the `resolution` and
`nurbs_weight`.
The other attributes that are written explicitly (like `radius`) don't have
builtin default values unfortunately. Ideally those would also just be provided
by the respective `BuiltinAttributeProvider`.
Pull Request: https://projects.blender.org/blender/blender/pulls/131799
Currently the realize instances code (which is also used by the join
geometry node) always creates generic attributes instead of vertex
groups. The expectation was that vertex groups would be replaced
by some form of generic attribute sooner rather than later. However,
it's clear that won't happen for some time, and this issue causes users
a lot of trouble. This commit preserves the vertex groups through the
operation. Any attribute name that was a vertex group on any of the
input meshes will become a vertex group in the result.
In the code this is a simple change because the attribute writer
abstraction allows writing to vertex groups as if the were just like
other contiguous arrays. In the future we could optimize the code
specifically for vertex groups.
This resolves the "bug" part of #99197 where the nodes remove vertex
groups. However, this doesn't change the fact that generating
primitive meshes in geometry nodes won't create vertex groups.
In general the property editor settings on the original mesh have
no effect on meshes created from scratch in geometry nodes.
Pull Request: https://projects.blender.org/blender/blender/pulls/131692
Grease Pencil v3 did not have crazyspace support yet. Without this sculpting on
deformed geometry (e.g. on top of an armature modifier) will yield incorrect
offsets because the tool writes to original data based on deformed positions.
This patch adds computation of local deformation matrices which are stored in
the `GeometryComponentEditData`. Those matrices are then used to convert local
deformation of the evaluated geometry back to a deformation of the original
geometry. All the relevant sculpt tools support the crazyspace correction now,
using the `compute_orig_delta` helper function.
Computing the deformation matrices should happen alongside modifier evaluation
for any deforming modifier. This has been implemented for the armature modifier,
others can be added.
A fallback implementation for curves could also be added for modifiers that
don't have an easy way to calculate local transformation. A "natural"
orientation for both the original and deformed positions is calculated, then the
difference yields deform matrices. For meshes the approach is to use the surface
normal and a stable tangent space. For curves the common local coordinate frame
based on parallel transport might be used.
Currently crazyspace correction for the _Clone_ tool does not work because of
#131496.
Pull Request: https://projects.blender.org/blender/blender/pulls/131499
Avoid rebuilding BVH trees when meshes are copied.
Similar to the other uses of the shared cache system,
this can arbitrarily improve performance when meshes
are copied but not deformed and BVH building is the
main bottleneck. In a simple test file I got a 6x speedup.
The amount of code is also reduced and the system is
much simpler overall-- built out of common threading
patterns like `SharedCache` with its double-checked lock.
RAII is used in a few places to simplify memory management
too.
The downside is storing more `SharedCache` items in the
mesh runtime struct. That has a slight cost when copying
a small mesh many times, but we have ideas to improve that
in the future anyway (#104327).
Pull Request: https://projects.blender.org/blender/blender/pulls/130865
I'm not quite sure what was wrong about the old implementation, but it was confusing
because it also depended on the user counts of drawings and other more high level
functions like `duplicate_layer`.
This fix just reimplements the functionality using the grease pencil API that we use in
more places in geometry nodes.
Pull Request: https://projects.blender.org/blender/blender/pulls/131291
Add a Mesh implementation of triangulation, which is currently just
implemented for BMesh. The main benefit of this is performance and
decreased memory usage. The benefit is especially large because the
node currently converts to BMesh, triangulates, and then converts back.
But the BMesh implementation is entirely single threaded, so it will
always be much slower.
The new implementation uses the principle of "never just process a
single element at a time" but it also tries to avoid processing _too_
many elements at once, to decrease the size of temporary buffers.
Practically that means the work is organized into chunks of selected
faces, but within each chunk, each task is done in a separate loop.
Arguably I went a bit far with some optimizations, and some of the
complexity isn't necessary, but I hope everything is clear anyway.
Unlike some other Mesh ports like the extrude node or the split edges
code, this generates a new mesh. I still go back and forth on that
aspect, but reusing the same mesh would have required reallocating
face attributes from scratch anyway. Implicit sharing is used to
avoid copying vertex attributes though.
The result mesh is reorganized a bit. Unselected face data comes first,
then selected triangles, then triangulated NGons, then triangulated
quads. This makes attribute interpolation and internal calculations
more efficient.
The "Minimum Vertices" socket is replaced with versioning. In the new
implementation it would have an impact on code complexity, and for a
builtin "atomic" node it makes more sense as part of the selection.
The performance difference depends on the number of CPU threads, the
number of attributes, and the selection size. As all of those numbers
go up, the benefit will grow. The "modes" also affect the performance,
obviously.
With a Ryzen 7950x, I tested performance in a few situations (in ms):
| | Selection | Before | After | Change |
| -------------------------- | --------- | ------ | ----- | ------ |
| 1.4 m quads (fixed) | 50% | 1533 | 15.9 | 96x |
| 10 m quads (shortest) | 100% | 9700 | 165.0 | 59x |
| 1 m 10-side Ngons (beauty) | 90% | 3785 | 115.9 | 33x |
| 1 m quads many attributes | 100% | 54600 | 332.3 | 164x |
In follow-up commits, I'll move other areas to use mesh triangulation
instead of BMesh. This is the last geometry node using BMesh besides
the Ico Sphere primitive.
Pull Request: https://projects.blender.org/blender/blender/pulls/112264
There is not really a good definition for what an "attribute kind". There are
many possibilities, it could include domain, type, geometry type, default value,
usage, ...
So it's better not to use this generic name. With the current name, one always
has to look at the definition again to be sure what it contains and what it does
not.
The name `AttributeDomainAndType` is way more explicit and does not have the
same problems. It's a bit longer, but that does not seem to be a problem in the
places where we use it.
Pull Request: https://projects.blender.org/blender/blender/pulls/130505
The length modifier was not handling 2 point curves correctly.
This change does two things:
1) Fix the crash by copying the original indices for 2 point curves into `dst_to_src_point`.
2) Fallback to `extend_curves_straight` for extending 2 point curves.
Pull Request: https://projects.blender.org/blender/blender/pulls/130122
Previously, some places used `curves.points_num() == 0` some other
places `curves.curves_num() == 0` to check if the geometry is empty.
Rather than having these two ways, add an `is_empty()` function
that replaces all these different checks.
Also update the curves geometry tests to use this function.
Pull Request: https://projects.blender.org/blender/blender/pulls/130168
In `execute_realize_grease_pencil_tasks` we create a new `GreasePencil`
but don't copy the parameters of (one of) the source grease pencils.
The fix adds `BKE_grease_pencil_copy_parameters` to copy the parameters
of the last src grease pencil.
Note: `BKE_grease_pencil_copy_parameters` copies the materials array. We
might want to remove this and always do the copy of this using a separate
function because some callers need their own way of copying them.
Pull Request: https://projects.blender.org/blender/blender/pulls/129977
Interpolating these attributes as integer values isn't meaningful or
helpful and is potentially problematic. So far I'd guess this is unlikely
to happen in practice which is why it probably hasn't been noticed yet.
Fixes part of #129691.
Pull Request: https://projects.blender.org/blender/blender/pulls/129809
Only retrieve a mutable copy of the attribute if we're actually able to change it.
If topology changes and there are no IDs, we can't mix the attribute and we
should avoid retrieving it in case it's shared. This is more of a hypothetical
change, I didn't actually observe a real world performance change.
Pull Request: https://projects.blender.org/blender/blender/pulls/129811
The 4x4 matrix type has a larger alignment requirement of 16 bytes
than the default, but it was stored in a generic vector of bytes. There
are a few solutions that reduce the memory reuse in this code path--
the chosen solution uses a custom allocator which always allocates
with an alignment that should be large enough for anything.
Generally I think this resampling loop could be rewritten to be a bit
simpler, avoiding these problems in the first place. Some performance
testing would show whether this "fancy" memory use between types
and loop structure is actually worth it. For now though, just correcting
the existing logic seems like the best choice.
Pull Request: https://projects.blender.org/blender/blender/pulls/129628
Unwrapping warned that a non 0/1 boolean value was being set.
Initialize all members of PVert since they would be accessed
when duplicating a PVert causing the uninitialized memory to be read.