14 Commits

Author SHA1 Message Date
Hans Goudey
c01d4a4ee6 Refactor: Deduplicate position transform utilities
The pattern of transforming many position vectors at once is quite
common, both with separate source and result arrays, and when modifying
an array in place. In some cases at least we used a separate function
with a consistent name across files, but there were also many duplicate
parallel transform implementations.

This commit adds these utilities to the BLI_math_matrix.hh API and uses
them where many positions from contiguous arrays are transformed at
once. While there might be a more ideal location for these utilities,
it's consistent with 3936d7a93e, and certainly better
than duplicating them.

This also reduces binary size of my build by 15 KB.

Pull Request: https://projects.blender.org/blender/blender/pulls/145352
2025-08-28 19:27:17 +02:00
Jacques Lucke
3ce212b9ac Fix #139981: volume transform crash with bad matrix 2025-06-09 09:09:18 +02:00
Hans Goudey
448d3d04d9 Cleanup: Unify and clean up mesh transform & translation functions
Use C++ types, move to C++ header, use them consistently in the
geometry transform function.
2025-03-28 11:36:39 -04:00
Jacques Lucke
ce4a152c64 Geometry: avoid invalidating caches when transforming by identity
Transforming e.g. a mesh can invalidate caches like bvh trees. Therefore,
if it can be skipped, it should be skipped.
2025-03-27 19:41:30 +01:00
Hans Goudey
eb7df01ef3 Cleanup: Reduce unnecessary includes in curves headers
Pull Request: https://projects.blender.org/blender/blender/pulls/132925
2025-01-10 23:31:49 +01:00
Lukas Tönne
0d8f040c8b Fix #130945: Grease Pencil: Crazyspace support in sculpt mode
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
2024-12-09 12:33:44 +01: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
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
Jacques Lucke
24dc9a21b1 Geometry Nodes: support attaching gizmos to input values
This adds support for attaching gizmos for input values. The goal is to make it
easier for users to set input values intuitively in the 3D viewport.

We went through multiple different possible designs until we settled on the one
implemented here. We picked it for it's flexibility and ease of use when using
geometry node assets. The core principle in the design is that **gizmos are
attached to existing input values instead of being the input value themselves**.
This actually fits the existing concept of gizmos in Blender well, but may be a
bit unintutitive in a node setup at first. The attachment is done using links in
the node editor.

The most basic usage of the node is to link a Value node to the new Linear Gizmo
node. This attaches the gizmo to the input value and allows you to change it
from the 3D view. The attachment is indicated by the gizmo icon in the sockets
which are controlled by a gizmo as well as the back-link (notice the double
link) when the gizmo is active.

The core principle makes it straight forward to control the same node setup from
the 3D view with gizmos, or by manually changing input values, or by driving the
input values procedurally.

If the input value is controlled indirectly by other inputs, it's often possible
to **automatically propagate** the gizmo to the actual input.

Backpropagation does not work for all nodes, although more nodes can be
supported over time.

This patch adds the first three gizmo nodes which cover common use cases:
* **Linear Gizmo**: Creates a gizmo that controls a float or integer value using
  a linear movement of e.g. an arrow in the 3D viewport.
* **Dial Gizmo**: Creates a circular gizmo in the 3D viewport that can be
  rotated to change the attached angle input.
* **Transform Gizmo**: Creates a simple gizmo for location, rotation and scale.

In the future, more built-in gizmos and potentially the ability for custom
gizmos could be added.

All gizmo nodes have a **Transform** geometry output. Using it is optional but
it is recommended when the gizmo is used to control inputs that affect a
geometry. When it is used, Blender will automatically transform the gizmos
together with the geometry that they control. To achieve this, the output should
be merged with the generated geometry using the *Join Geometry* node. The data
contained in *Transform* output is not visible geometry, but just internal
information that helps Blender to give a better user experience when using
gizmos.

The gizmo nodes have a multi-input socket. This allows **controlling multiple
values** with the same gizmo.

Only a small set of **gizmo shapes** is supported initially. It might be
extended in the future but one goal is to give the gizmos used by different node
group assets a familiar look and feel. A similar constraint exists for
**colors**. Currently, one can choose from a fixed set of colors which can be
modified in the theme settings.

The set of **visible gizmos** is determined by a multiple factors because it's
not really feasible to show all possible gizmos at all times. To see any of the
geometry nodes gizmos, the "Active Modifier" option has to be enabled in the
"Viewport Gizmos" popover. Then all gizmos are drawn for which at least one of
the following is true:
* The gizmo controls an input of the active modifier of the active object.
* The gizmo controls a value in a selected node in an open node editor.
* The gizmo controls a pinned value in an open node editor. Pinning works by
  clicking the gizmo icon next to the value.

Pull Request: https://projects.blender.org/blender/blender/pulls/112677
2024-07-10 16:18:47 +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
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
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
Campbell Barton
0933e21750 Cleanup: unused includes in source/blender/geometry
Remove 13 includes.
2024-02-13 19:21:03 +11:00
Jacques Lucke
fcc17780a8 Geometry Nodes: extract geometry transform functions to separate file 2024-02-01 13:18:39 +01:00