Commit Graph

89 Commits

Author SHA1 Message Date
Falk David 8512a608a4 GPv3: Onion Skinning
Implements the GPv2 onion skinning functionality.

There are no functional changes exept for the `use_ghosts_always`
option, which has been removed. This was used to show onion
skinning in the final render.

Pull Request: https://projects.blender.org/blender/blender/pulls/119792
2024-04-03 15:34: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
Lukas Tönne d7c718dfd4 GPv3: Texture offset modifier
Port of the GPv2 texture modifier for transforming UVs of stroke points.

Pull Request: https://projects.blender.org/blender/blender/pulls/119050
2024-03-29 21:42:30 +01:00
casey bianco-davis 20b614ab8e GPv3: Fill texture coordinates system
This is implements the system texture coordinates for GPv3.

This pull request adds:
- System for storing and viewing texture coordinates.
- Texture coordinates are convert when covering from legacy to GPv3,
   (Tested with object and layer transformation)
- Textures are set to the drawing plane.

Pull Request: https://projects.blender.org/blender/blender/pulls/119303
2024-03-21 16:07:18 +01:00
Falk David 6a320524b9 Fix: GPv3: Function `use_masks` returns wrong value
This fixes an issue where the `use_masks` functions on layers
and groups returned the wrong value.
The issue was that the root group doesn't have this flag set
which then propagates to all the layers and groups.
To fix this we invert the `GP_LAYER_TREE_NODE_USE_MASKS` flag (now called `GP_LAYER_TREE_NODE_HIDE_MASKS`).

The API still uses the `use_masks` function.
2024-03-14 15:25:23 +01:00
Falk David a5229ed125 GPv3: Add layer masks operators and UI
Layer masks were partly already there. This PR completes the implementation and expose them through the UI.

This also adds three operators to:
- add a layer mask
- remove a layer mask
- reorder layer masks

Note: These are not used by the renderer yet. Will be done in a following PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/119433
2024-03-14 14:07:37 +01:00
Falk David a07a558ac5 GPv3: Add view layer name property
This adds the `viewlayername` property to grease pencil v3 layers.
It's exposed as `viewlayer_render` in python.

Note: this is not used in the renderer yet. Will be used in a following PR.
Pull Request: https://projects.blender.org/blender/blender/pulls/119422
2024-03-14 10:15:07 +01:00
Hans Goudey d9a1e906f5 Cleanup: GPv3: Add specific header for legacy conversion functions
Similar to `BKE_curve_legacy_convert.hh` and `BKE_mesh_legacy_convert.hh`

Pull Request: https://projects.blender.org/blender/blender/pulls/118390
2024-02-16 17:49:42 +01:00
Hans Goudey 44e695192a Cleanup: Make format 2024-02-16 11:35:54 -05:00
Falk David 8bca19ed12 GPv3: Layer Adjustment Conversion
This converts the "Layer Adjustments" from GPv2 into modifier setups in GPv3.

They include:
* Layer tint
* Layer thickness offset
* Thickness factor (for the entire object)

Both the "layer tint" and the "thickness factor" are converted using the existing modifiers.

Because the thickness modifier uses a factor instead of an offset, the "layer thickness offset" is converted to a geometry nodes modifier setup for each layer that adds an offset value to the radii instead of multiplying by a factor.

Pull Request: https://projects.blender.org/blender/blender/pulls/118149
2024-02-16 17:17:19 +01:00
Bastien Montagne 9275d40934 GPv3: Minor Refactor of conversion code.
Essentially move the Object-handling logic also into
`bke::greasepencil::convert::`. This code will also be needed for
automatic conversion on fileread etc.

It also helps to keep all the conversion logic in one place (especially
since there is going to be way more done at object level - modifiers,
animation, etc.).

Pull Request: https://projects.blender.org/blender/blender/pulls/118384
2024-02-16 16:29:31 +01:00
Bastien Montagne 13887fc427 GPv3: Add assignement operator to `LayerGroup` class. 2024-02-15 10:19:50 +01:00
Campbell Barton 3dbbc013de Cleanup: spelling in comments 2024-02-10 22:35:35 +11:00
Falk David 0a45acbe3b GPv3: Layer Parenting/Transforms
This implements layer parenting and layer transforms.

* Adds a new "Transform" panel in the object-data properties with the (local) translation, rotation and scale.
* Adds a new "Relations" panel with the parent property (and also bone name in case the parent is an armature).
* When converting from GPv2 to GPv3, the parent and transforms are converted too.
* Bone names are updated if they are renamed in the armature.

Implementation details:
* The positions in the drawings are always in layer space. During extraction, we transform the positions to object space. Note that this could be optimized further and done in the render engine itself.
* This means that e.g. the selection code (which needs to know where the positions are on screen) now takes this transform into account.
* The layer transform is calculated when accessed (from the location, rotation, scale properties).
* Code that needs to know where the positions are on screen now takes this new transform into account.

Pull Request: https://projects.blender.org/blender/blender/pulls/117247
2024-02-07 16:28:14 +01:00
Lukas Tönne ee9a0f6014 GPv3: Handle vertex groups in the GPv2 conversion operator
Copies vertex group names from the GPv2 object to the new GPv3 GreasePencil data block.
Copies only those names to the drawings that are actually used by any of the strokes.
Updates group indices in `MDeformVert` data to point to local Drawing groups.

Pull Request: https://projects.blender.org/blender/blender/pulls/117860
2024-02-06 12:36:17 +01:00
Campbell Barton be7f89a9f5 Cleanup: spelling in comments 2024-01-29 11:47:42 +11:00
Bastien Montagne f1d4c35f4d GPV3: Refactor the 'dna processing' code when reading/writing blendfile.
GreasePencil v3 requires some additional processing on its data before
writing to blendfile, and after reading from it.

Extract this from generic `read/write` code, and put it into dedicated
callbacks in Cpp classes that need it (layer groups and leaves
currently).

NOTE: Work done while exploring possibility to use 'memfile' read/write
code for GP editmode undo (!117072), but ended up taking a different
approach for it, so this PR is purely a 'no expected changes in behavior'
refactor at this point.

Pull Request: https://projects.blender.org/blender/blender/pulls/117413
2024-01-22 17:44:44 +01:00
Falk David b6ed5eea8d GPv3: Return std::optional from `frame_key_at`
Previously, `frame_key_at` would return `-1` for when it couldn't find
a key for the given frame.
This could lead to issues though, because `-1` is a valid key (it is a valid scene frame number).

This changes the API to return an optional instead. This makes it very clear
when no key was found, and should make it less error prone.
2024-01-19 14:58:07 +01:00
Falk David 049e48b431 GPv3: Add curve plane normal cache
This adds a cache to read a normal vector for a plane that (roughly) fits a curve.
If the curve lies on a plane, the vector always point along this plane normal, otherwise it's an approximation.
The cache is lazily calculated and invalidated when the positions are tagged for a change.
2024-01-17 14:09:42 +01:00
Antonio Vazquez c964b79edf GPv3: Copy Materials to Selected operator
Conversion of GPv2 operator to duplicate materials between grease pencil objects.

Pull Request: https://projects.blender.org/blender/blender/pulls/115535
2024-01-12 11:20:35 +01:00
Falk David da78dd47e3 Fix #116343: Drawing on frame with auto-keying off gives error
When drawing on a frame that didn't have a keyframe, but did have a drawing,
Blender would report that there was no drawing to draw on.
The issue was some faulty logic on the invoke of the drawing code.

Now, this properly checks if a new frame needs to be inserted and
only reports an error in case auto-key is off and there is no drawing.

Pull Request: https://projects.blender.org/blender/blender/pulls/116417
2023-12-21 12:10:50 +01:00
Hans Goudey d8497e48e1 Cleanup: Use `is_empty()` instead of `size() == 0` 2023-12-11 15:47:11 -05:00
Hans Goudey 14e3523ac2 Refactor: Further improvements to geometry bounds
Implement the next phases of bounds improvement design #96968.
Mainly the following changes:

Don't use `Object.runtime.bb` for performance caching volume bounds.
This is redundant with the cache in most geometry data-block types.
Instead, this becomes `Object.runtime.bounds_eval`, and is only used
where it's actually needed: syncing the bounds from the evaluated
geometry in the active depsgraph to the original object.

Remove all redundant functions to access geometry bounds with an
Object argument. These make the whole design confusing, since they
access geometry bounds at an object level.

Use `std::optional<Bounds<float3>>` to pass and store bounds instead
of an allocated `BoundBox` struct. This uses less space, avoids
small heap allocations, and generally simplifies code, since we
usually only want the min and max anyway.

After this, to avoid performance regressions, we should also cache
bounds in volumes, and maybe the legacy curve and GP data types
(though it might not be worth the effort for those legacy types).

Pull Request: https://projects.blender.org/blender/blender/pulls/114933
2023-11-27 16:14:49 +01:00
Falk David 8dc9a9a0e3 Fix: GPv3: Uninitialized runtime variable
The `eval_frame` was not initialized to a default value,
causing a crash in some situations on windows.
This at least avoids a crash even if the outcome of
whatever uses the `eval_frame` might not be correct.
2023-11-27 15:06:38 +01:00
Antonio Vazquez 00b04e1030 GPv3: Fix Remove Material Slot and Unused Slots
There was two problems because these operators were not supported in GPv3:

* If you remove the slot, the material was not reassigned and the material index attribute could get a wrong index. This also affected the unused slots.
* The Unused Materials operator was executed, but it was doing nothing because there was not support for new GPv3 object.

This PR adds support for new Grease Pencil object.

Pull Request: https://projects.blender.org/blender/blender/pulls/114850
2023-11-17 10:37:56 +01:00
Falk David e433a8eaaf GPv3: Replace find API with `find_node_by_name`
Instead of having two APIs (`find_layer_by_name` +
`find_layer_group_by_name`) replace them with a single API
`find_node_by_name`.
This returns a `TreeNode` but the caller can easily check if it's a
layer or a group.
2023-10-20 19:05:31 +02:00
Falk David f6c8ddda26 GPv3: Add `is_child_of` function
Adds a new API to check if a node is a child of a group.
2023-10-20 18:51:22 +02:00
Hans Goudey 1cbd0f5a85 Refactor: Improve access to object data bounds
Currently object bounds (`object.runtime.bb`) are lazily initialized
when accessed. This access happens from arbitrary threads, and
is unprotected by a mutex. This can cause access to stale data at
best, and crashes at worst. Eager calculation is meant to keep this
working, but it's fragile.

Since e8f4010611, geometry bounds are cached in the geometry
itself, which makes this object-level cache redundant. So, it's clearer
to build the  `BoundBox` from those cached bounds and return it by
value, without interacting with the object's cached bounding box.

The code change is is mostly a move from `const BoundBox *` to
`std::optional<BoundBox>`. This is only one step of a larger change
described in #96968. Followup steps would include switching to
a simpler and smaller `Bounds` type, removing redundant object-
level access, and eventually removing `object.runtime.bb`.

Access of bounds from the object for mesh, curves, and point cloud
objects should now be thread-safe. Other object types still lazily
initialize the object `BoundBox` cache since they don't have
a data-level cache.

Pull Request: https://projects.blender.org/blender/blender/pulls/113465
2023-10-19 14:18:40 +02:00
Falk David 26816931c4 Fix: GPv3: Remap materials
Also fixes a crash when moving the first material of the default Grease Pencil Suzanne down by one.

Pull Request: https://projects.blender.org/blender/blender/pulls/113855
2023-10-19 13:19:41 +02:00
Falk David a89bb7632a GPv3: Separate/Delete Geometry node
This implements deleting a selection of layers on a grease pencil geometry.

Pull Request: https://projects.blender.org/blender/blender/pulls/113828
2023-10-18 11:54:56 +02:00
Falk David bc0e5cf8bd Cleanup: GPv3: Use helper to duplicate drawings 2023-10-18 11:27:01 +02:00
Falk David 74facf9841 GPv3: Add wrapper class for DrawingReference
Adds a simple C++ wrapper so we don't have to use
`MEM_dupallocN`, `MEM_freeN` etc.
2023-10-18 11:27:01 +02:00
Falk David f59827de74 GPv3: Add API to copy and add a layer
This adds a core API to add a new layer by copying a source layer.
2023-10-17 15:41:50 +02:00
Harley Acheson 651d6eb229 Cleanup: Make format
Formatting changes resulting from Make Format
2023-10-12 08:04:53 -07:00
Falk David 49b21eba11 GPv3: Support crazyspace in selection code
This adds `GreasePencilEditHints` and correctly implements
`crazyspace::get_evaluated_grease_pencil_drawing_deformation`
to support querying the deformation of points after evaluation.
This is needed for users to properly select points in edit mode while
seeing the effects of the modifiers.

Pull Request: https://projects.blender.org/blender/blender/pulls/113586
2023-10-12 15:42:04 +02:00
Falk David 3931a54e08 GPv3: Initial Geometry Nodes support
This implements the core changes for this design: https://devtalk.blender.org/t/grease-pencil-integration-into-geometry-nodes/31220

The changes include:
* Add `CustomData` for layer attributes
* Add attribute support for the `GreasePencilComponent` to read/write layer attributes. Also introduces a `Layer` domain.
* Implement a `GreasePencilLayerFieldContext` and make `GeometryFieldContext` work with grease pencil layers.
* Implement `Set Position` node for `Grease Pencil`.

Note: These changes are only accessible/visible with the `Grease Pencil 3.0` experimental flag enabled.
Co-authored-by: Jacques Lucke <jacques@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/112535
2023-10-10 16:49:30 +02:00
Falk David e7e1ec55d2 GPv3: Add `DrawingTransforms`
This makes sure that when the object is transformed, the painting code will take that
transformation into account.

Resolves #113424.

Pull Request: https://projects.blender.org/blender/blender/pulls/113442
2023-10-09 12:42:01 +02:00
Falk David 7e87435cf4 GPv3: Initial drawing tool
This PR implements an initial drawing tool that can already be used for testing.
While this is not fully feature complete (compared to the current grease pencil draw tool) the following is already implemented:

* Pressure support for radius and opacity.
* Material color and vertex color support.
* New active smoothing algorithm based on curve fitting.
* Simplify algorithm as a post-process step.

Some deliberate limitations include:
* The drawing plane is always the front plane. Drawing on surfaces is also not supported.
*

The current approach has not been optimized for performance yet. The goal was to have a straightforward implementation
first and then focus on performance later.

There are numerous parameters in the code that are hard-coded for now. These should be exposed at some point, potentially as user settings.

Pull Request: https://projects.blender.org/blender/blender/pulls/110093
2023-10-06 10:49:54 +02:00
Falk David 16e195a111 Cleanup: GPv3 layer tree manipulations
In preparation of https://projects.blender.org/blender/blender/pulls/112535, we need to make sure all layer tree manipulations are in functions on the `GreasePencil` struct so we can keep the `CustomData` for layers in sync with the layer tree.

 This PR makes sure that all the functions that change the layer tree in any way are `protected` on the `LayerGroup` class. The `GreasePencil` struct is declared `friend` with `LayerGroup`.

We also cleanup and remove a lot of code duplication between layers and layer groups and try to write functions in a generic way for `TreeNode` (both layers and layer groups are tree nodes).

Pull Request: https://projects.blender.org/blender/blender/pulls/112837
2023-09-25 12:11:18 +02:00
Hans Goudey 0fd0539f04 Cleanup: Rename grease pencil function to access layer at index
The plural was confusing when only one layer was returned.
2023-09-20 08:39:30 -04:00
Hans Goudey 774b9607c9 Cleanup: Resolve const correctness in grease pencil API
It was possible to access a mutable drawing from a const GreasePencil
object. This sort of mistake is possible because DNA requires using raw
pointers.
2023-09-20 08:28:08 -04:00
Amelie Fondevilla 127eee87ce GPv3: Duplicate keyframes
Implementation of the duplicate and move operator for grease pencil frames.

The `ACTION_OT_duplicate` operator now creates duplicates of the selected frames and stores them in the layer runtime data.
The `TRANSFORM_OT_transform` operator is updated to take care of these duplicated frames.

Pull Request: https://projects.blender.org/blender/blender/pulls/111051
2023-09-12 12:07:15 +02:00
Falk David b66c0676b4 GPv3: Move dopesheet channels
This will allow to move selected channels to
Top/Bottom/Up/Down in the list.

Co-authored by: Pratik Borhade <pratikborhade302@gmail.com>

Pull Request: https://projects.blender.org/blender/blender/pulls/111009
2023-09-11 13:07:48 +02:00
Pratik Borhade faff3d1d15 Cleanup: Comment style
Pull Request: https://projects.blender.org/blender/blender/pulls/111509
2023-08-25 11:14:19 +02:00
Amelie Fondevilla 3dc93d6e38 GPv3: Display layer groups in grease pencil dopesheet
This patch adds a new type of channel for grease pencil layer groups, which works as an expandable summary channel of layers inside the group.

Pull Request: https://projects.blender.org/blender/blender/pulls/111015
2023-08-21 10:51:00 +02:00
Falk David 24082ceecc Cleanup: GPv3: Constructors and destructors
The `TreeNode`, `Layer` and `LayerGroup` constructors and destructors
had some inconsistencies. Now the code is a bit more clean and shared.
2023-08-18 15:06:18 +02:00
Falk David d06a6105a7 Fix: GPv3: `TreeNode::is_locked()` function
The function returned `true` for the root node, which it shouldn't.
2023-08-18 12:44:11 +02:00
Falk David 725f1dbf2d Revert: GPv3: DNA rename of `name`
Partially reverts b14a0ee57e.

Instead of renaming the DNA field, use namespaces in C++ to resolve
name collisions (which is the reason this change was done
in the first place).
2023-08-18 12:44:11 +02:00
Falk David 5aacbf6c81 Fix: GPv3: Crash because of missing null check
There was a missing null check in the `TreeNode::name()`
function.
2023-08-17 14:41:26 +02:00
Falk David b14a0ee57e Cleanup: GPv3: Refactor usage of `TreeNode`
Some functionality of `Layer`s and `LayerGroup`s can be shared. This is why the `TreeNode` class exists. It encapsulates all the common methods both `Layer`s and `LayerGroup`s should have.

Up until now, the usage of `TreeNode` was not consistent and often the layers would just access the base c-struct directly.

This refactor makes it so that all of the functions affecting only the `TreeNode` are moved to the `TreeNode` class and only implemented there.

For example, renaming a layer is really just renaming the node. Therefor there shouldn't even be a `rename_layer` and `rename_layer_group` function. These were combined into a `rename_node` function.

Pull Request: https://projects.blender.org/blender/blender/pulls/111177
2023-08-16 16:18:26 +02:00