Commit Graph

69 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
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
YimingWu d296c66ab1 GPv3: Show Line Art options in Object > Add menu
The Object > Add > Grease Pencil menu will now show Scene/Collection/Object Line Art
options.

Pull Request: https://projects.blender.org/blender/blender/pulls/118833
2024-02-28 16:20:48 +01:00
Pratik Borhade 203f5f9f09 GPv3: Autolock inactive layers
Port legacy `autolock_layers` property to gpv3

Pull Request: https://projects.blender.org/blender/blender/pulls/118323
2024-02-18 07:32:56 +01:00
Bastien Montagne 9be522d480 GPv3: Add low-level `resize_drawings` function. 2024-02-15 10:19:50 +01:00
Hans Goudey b19bd19660 Cleanup: Make format 2024-02-07 11:45:59 -05: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 7e7165b085 GPv3: Basic vertex group operators
Adds vertex groups and basic operator support to the `GreasePencil` data
block.

Vertex groups in the `GreasePencil` ID are used as the source of truth
for vertex groups names and ordering in the UI. Individual drawings also
have vertex group lists, but they should not be modified directly by
users or the API. The main purpose of storing vertex group names in in a
drawing's `CurveGeometry` is to make it self-contained, so that vertex
weights can be associated with names without requiring the
`GreasePencil` parent data.

Vertex group operators are implemented generically for some ID types.
Grease Pencil needs its own handling in these operators. After
manipulating `vertex_group_names` the `validate_drawing_vertex_groups`
utility function should be called to ensure that drawings only contain a
true subset of the `GreasePencil` data block.

Operators for assigning/removing/selecting/deselecting vertices are also
implemented here. To avoid putting grease pencil logic into the generic
`object_deform.cc` file a number of utility functions have been added in
`BKE_grease_pencil_vgroup.hh`.

Fixes #117337

Pull Request: https://projects.blender.org/blender/blender/pulls/117476
2024-01-31 17:45:59 +01:00
Campbell Barton a3b4078be3 Cleanup: spelling in comments 2024-01-18 10:39:24 +11:00
Falk David 35e8959d77 GPv3: Add function to get the index of a layer 2024-01-15 17:01:54 +01:00
Falk David 1b65faddd0 Cleanup: GPv3: Require layer when retrieving a drawing
This cleanup changes the `layer` parameter in `get_drawing_at` and `get_editable_drawing_at` to a reference.
This makes it clear that the layer is required for this function.
2024-01-09 18:34:36 +01:00
Falk David 89947aac1c Cleanup: Non-const version of `get_active_layer` 2023-12-21 11:09:23 +01:00
Hans Goudey 19001c9e6c Cleanup: Move attribute domain enum to C++ header, use enum class
Each value is now out of the global namespace, so they can be shorter
and easier to read. Most of this commit just adds the necessary casting
and namespace specification. `enum class` can be forward declared since
it has a specified size. We will make use of that in the next commit.
2023-12-20 13:25:28 -05:00
Campbell Barton 53a51d2148 Cleanup: use color after doxygen parameters 2023-12-17 16:04:40 +11:00
Falk David 3a743018b1 Fix: GPv3: Wrong location in `paint_init_pivot`
The `paint_init_pivot` calculates the `location` based
on the midpoint of the bounds of the object. For grease pencil
the bounds depend on the current frame (for original data).

This fixes the issue by making the `bounds_min_max` function
dependent on the `frame` and by introducing a `bounds_min_max_eval`
for evaluated data.
2023-11-27 15:06:38 +01:00
Falk David 91db8fc5a0 GPv3: Multi-frame editing
Adds a new scene tool setting `use_grease_pencil_multi_frame_editing`.

The `foreach_*_drawing` functions are moved to the `ed::greasepencil` namespace in the editor, since they are now context sensitive and depend on the toolsetting. They are now named `retrieve_editable_drawings` and `retrieve_visible_drawings` and return
an array of drawings instead of calling a callback function.

Pull Request: https://projects.blender.org/blender/blender/pulls/114283
2023-11-02 17:10:59 +01:00
Dalai Felinto f312be62ea GPv3: Named Layer Selection field
This field supports either a Layer, or a Layer Group name as input,
and outputs a selection.

The nodes that use this should add the name to the list of Named
Dependencies of the node-tree.

Ref !113908.
2023-10-23 15:49:34 +02:00
Douglas Paul f5c9acc154 GPv3: Reimplement how customdata is updated when layers are re-ordered
Instead of calculating the expected insertion index for a customdata entry being moved, this implementation just records the initial layer indices so that it can compare them with the final indices to determine how the customdata entries need to be re-arranged.

Also simplifies the `add_layer` function and adds an implementation that just takes a `name` and adds a new layer with that name to the root group.

Pull Request: https://projects.blender.org/blender/blender/pulls/113962
2023-10-21 16:47:17 +02: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 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
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 f43426f0de GPv3: Rename layer domain to just "Layer"
We had a short discussion on this change. "Grease Pencil Layer" is
just a bit too long, especially in the UI. Even though "Layer" might be
ambiguous, it shouldn't be in the context of geometry nodes. There are
currently no other "Layers" and if there were, using the same domain
name could be fine (just like we reuse the point domain for e.g. vertices
in meshes and control points in curves).

This also renames the internal enum to `ATTR_DOMAIN_LAYER`

Pull Request: https://projects.blender.org/blender/blender/pulls/113589
2023-10-12 13:54:32 +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 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
Campbell Barton 4fc5d287ac Cleanup: doxygen parameters, blank comment lines 2023-09-08 16:53:30 +10:00
Julian Eisel 4c8847ec4f Cleanup: Remove `extern "C"` from DNA headers
`extern "C"` did not actually have an effect here since it only impacts
name mangling of functions, not structs (or other class types). Now this
can get in the way when we add C++ blocks with functions , e.g.
templates are not allowed in code with C-linkage.

Most of these were added in ad4b7741db, even though it was known that
this doesn't have any impact. Reason was because developers thought they
would have to add that to all direct and indirect includes to be able to
use a header in C++ (a common misconception). Now with most files
compiled in C++, it's obvious that this isn't the case.

Pull Request: https://projects.blender.org/blender/blender/pulls/111926
2023-09-04 15:59:40 +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 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
Harley Acheson 0e977a38bc Cleanup: Make format
Formatting changes resulting from Make Format
2023-08-16 14:15:54 -07: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
Falk David 969de5135a GPv3: Re-evaluate on frame change
This makes it so the `GreasePencil` geometry gets updated on a time
change.
The frame at which the object gets evaluated is stored in runtime as
`eval_frame`. This is for example used to calculate the bounding box
of the geometry as well as invalidating the batch cache for different
frames.

Pull Request: https://projects.blender.org/blender/blender/pulls/111137
2023-08-15 17:31:11 +02:00
Campbell Barton e955c94ed3 License Headers: Set copyright to "Blender Authors", add AUTHORS
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.

While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.

Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.

Some directories in `./intern/` have also been excluded:

- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.

An "AUTHORS" file has been added, using the chromium projects authors
file as a template.

Design task: #110784

Ref !110783.
2023-08-16 00:20:26 +10:00
Amelie Fondevilla 09d2108bf5 GPv3 : Transform action for grease pencil frames.
Implementation of the transform action for grease pencil frames, which enables translating and scaling grease pencil frames in the dopesheet.

This patch adds the following in the grease pencil API :
 - `move_frames`  to move a set of frames given a map of key transformations (with overwrite), and
 -  the structure `LayerTransformData` that stores in the layer runtime some useful data for the frames transformation.

Co-authored-by: Falk David <falk@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/110743
2023-08-10 12:57:32 +02:00
Falk David 827a71fe7e GPv3: Refactor: replace `remove_frame_at` function
Instead of removing frames one by one, the `GreasePencil::remove_frames`
function now expects a span of frame numbers, replacing the
`GreasePencil::remove_frame_at` function.
Now, when drawings need to be deleted, we shrink the array only once.

Pull Request: https://projects.blender.org/blender/blender/pulls/110957
2023-08-09 16:12:45 +02:00
Pratik Borhade 6e66125f34 GPv3: New is_layer_active function
New Grease Pencil function to determine whether the layer
is active.

Pull Request: https://projects.blender.org/blender/blender/pulls/110890
2023-08-08 11:26:22 +02:00
Amelie Fondevilla 655b2b6c2c GPv3: Delete grease pencil frames
Implementation of the delete frame operator for grease pencil channels.
Changes in the GreasePencil::remove_frame_at function so that it returns a boolean.

Pull Request: https://projects.blender.org/blender/blender/pulls/110746
2023-08-03 11:49:14 +02:00
Amelie Fondevilla fd75695bed GPv3: Insert grease pencil keyframe from the dopesheet
Adaptation of the operator `ACTION_OT_keyframe_insert` to take into account grease pencil channels.
Grease pencil keyframes can now be inserted in blank mode, or in additive mode (duplicate the current frame in the new keyframe).

Two API functions were added :
 * `add_duplicate_drawings` which copies the data of a drawing to creates a duplicate, and
 * `insert_duplicate_frame` which creates a duplicate frame of an existing one either by copy or instance.

The additive mode option is also added to the UI.

The Layer method `frame_key_at` previously private was set to public.

Pull Request: https://projects.blender.org/blender/blender/pulls/110649
2023-08-02 14:56:18 +02:00
Falk David de8ce4e34b GPv3: Add user count to drawings
Adds a user count to drawings to track how many frames use the drawing.
If the user count hits `0` the drawing should be deleted.

Also adds a function to delete a frame in a layer. This will
decrement the user count of the drawing and delete it if there are no
users left. This is consistent with the way GPv2 worked.

Pull Request: https://projects.blender.org/blender/blender/pulls/110579
2023-08-01 17:04:39 +02:00
Falk David 187545109a Cleanup: GPv3 drawings API
This cleans up the API a bit to make things more readable.
No functional changes.
2023-07-28 16:32:42 +02:00
Amelie Fondevilla 0c07fb50c8 GPv3: Keyframe on-click selection
Implementation of the click-selection operator of keyframes in the dopesheet, along with its alternatives : deselect all when no frames is hit, extend selection with shift, column selection with alt, select all keyframes on current channel with ctrl+alt.

Includes the new following API functions :
 * `select_frame_at` : selects a frame in a layer at a specific time (if such frame exists),
 * `select_all_frames` : selects all frames of a layer,
 * `select_layer_channel` : selects a layer, and sets it as active (if layer is not null, otherwise the active layer is set null),
 * `layer_has_frame_selected` : checks if any of the frames in the layer is selected.

Pull Request: https://projects.blender.org/blender/blender/pulls/110492
2023-07-26 17:59:09 +02:00
Falk David 71837fcb04 GPv3: Add `get_editable_drawing_at` function
This function returns an editable drawing for a given layer at a specific scene time.

Pull Request: https://projects.blender.org/blender/blender/pulls/110295
2023-07-20 12:53:38 +02:00
Falk David f2f0426980 GPv3: Refactor root_group to be a pointer in DNA
This turns the embedded group into a pointer.

Note: Older files will not load the grease pencil v3 object properly after this.
The objects will not have any layers in them.

Pull Request: https://projects.blender.org/blender/blender/pulls/110007
2023-07-13 18:24:19 +02:00