GPv3: Add initial dopesheet support #108807

Merged
Falk David merged 36 commits from filedescriptor/blender:gpv3-initial-dopesheet-support into main 2023-07-12 10:32:18 +02:00
Member

This PR adds basic support for viewing layers and keyframes (cels) in the grease pencil dopsheet for the new grease pencil data-type.
Resolves #108508

This PR adds basic support for viewing layers and keyframes (cels) in the grease pencil dopsheet for the new grease pencil data-type. Resolves #108508
Falk David added this to the Grease Pencil project 2023-06-09 15:39:43 +02:00
Falk David removed this from the Grease Pencil project 2023-06-09 15:40:20 +02:00
Hans Goudey changed title from WIP: GPv3: Add initial dopesheet support. to WIP: GPv3: Add initial dopesheet support 2023-06-12 18:10:59 +02:00

Channels are currently showing up in the dopesheet, but their names are not displayed, and nothing else is implemented yet.
Image

Channels are currently showing up in the dopesheet, but their names are not displayed, and nothing else is implemented yet. ![Image](../../attachments/8a50c8c3-0934-4749-b739-35e1df811ab3)

@filedescriptor We need to add new enum types or structures, in order to integrate the grease pencil layers as channels. So far I've got these name changes :

(<type>)            <old_name>       -> <new_name_legacy> | <new_name_gpv3>
(eAnim_KeyType)     ALE_GPFRAME      -> ALE_GPFRAME       | ALE_CEL
(eAnim_ChannelType) ANIMTYPE_GPLAYER -> ANIMTYPE_GPLAYER  | ANIMTYPE_GREASE_PENCIL_LAYER
(bAnimChannelType)  ACF_GPL          -> ACF_GPL_LEGACY    | ACF_GPL

Should we set specific rules ? For example, should we put _legacy at the end of each legacy-related type ?
Also, I am not sure in which case we should refer to cel. For now, it's only for key type, but we could also have ANIMTYPE_CEL (for the channel type), since there is ANIMTYPE_FCURVE.

@filedescriptor We need to add new enum types or structures, in order to integrate the grease pencil layers as channels. So far I've got these name changes : ``` (<type>) <old_name> -> <new_name_legacy> | <new_name_gpv3> (eAnim_KeyType) ALE_GPFRAME -> ALE_GPFRAME | ALE_CEL (eAnim_ChannelType) ANIMTYPE_GPLAYER -> ANIMTYPE_GPLAYER | ANIMTYPE_GREASE_PENCIL_LAYER (bAnimChannelType) ACF_GPL -> ACF_GPL_LEGACY | ACF_GPL ``` Should we set specific rules ? For example, should we put `_legacy` at the end of each legacy-related type ? Also, I am not sure in which case we should refer to `cel`. For now, it's only for key type, but we could also have `ANIMTYPE_CEL` (for the channel type), since there is `ANIMTYPE_FCURVE`.
Author
Member

@amelief I think just having the keytype be ALE_CEL makes sense to me. Technically the whole channel are zero or more cels so using cel for that (singular) would feel off.

I agree with the renaming you did. Don't bother with renaming too much to _legacy now. As long as there are no name conflicts, I would just do that at a later point and keep it to a minimum now.

@amelief I think just having the keytype be `ALE_CEL` makes sense to me. Technically the whole channel are zero or more `cels` so using `cel` for that (singular) would feel off. I agree with the renaming you did. Don't bother with renaming too much to `_legacy` now. As long as there are no name conflicts, I would just do that at a later point and keep it to a minimum now.
Falk David changed title from WIP: GPv3: Add initial dopesheet support to GPv3: Add initial dopesheet support 2023-06-28 18:14:05 +02:00
Author
Member

@blender-bot build

@blender-bot build

The layers are now subchannels of the grease pencil datablock, and expansion is fixed.

dopesheet.png

The layers are now subchannels of the grease pencil datablock, and expansion is fixed. ![dopesheet.png](/attachments/c0964a23-83e9-45eb-8c57-da790b07d840)
Falk David reviewed 2023-07-03 10:53:21 +02:00
Falk David left a comment
Author
Member

Some code style and naming remarks.

Some code style and naming remarks.
@ -3454,3 +3489,3 @@
short *r_type)
{
bGPdata *gpd = (bGPdata *)ale->data;
GreasePencil *gpd = (GreasePencil *)ale->data;
Author
Member

I like to be explicit and use grease_pencil as a variable name for the data-block.

I like to be explicit and use `grease_pencil` as a variable name for the data-block.
amelief marked this conversation as resolved
@ -3550,0 +3636,4 @@
/* name for grease pencil layer entries */
static void acf_gpl_name(bAnimListElem *ale, char *name)
{
GreasePencilLayer *gpl = (GreasePencilLayer *)ale->data;
Author
Member

gpl -> layer

`gpl` -> `layer`
amelief marked this conversation as resolved
@ -3550,0 +3639,4 @@
GreasePencilLayer *gpl = (GreasePencilLayer *)ale->data;
if (gpl && name) {
BLI_strncpy(name, gpl->base.name, ANIM_CHAN_NAME_SIZE);
Author
Member

Instead of directly accessing the name pointer, here I would do layer->wrap().name(). (might also need to add .c_str())

Instead of directly accessing the name pointer, here I would do `layer->wrap().name()`. (might also need to add `.c_str()`)
amelief marked this conversation as resolved
@ -3553,3 +3662,3 @@
short *r_type)
{
bGPDlayer *gpl = (bGPDlayer *)ale->data;
GreasePencilLayer *gpl = (GreasePencilLayer *)ale->data;
Author
Member

gpl -> layer

`gpl` -> `layer`
amelief marked this conversation as resolved
@ -975,2 +977,4 @@
break;
}
case ANIMTYPE_GREASE_PENCIL_LAYER: {
GreasePencilLayer *gpl = (GreasePencilLayer *)data;
Author
Member

gpl -> layer

`gpl` -> `layer`
amelief marked this conversation as resolved
@ -1788,0 +1805,4 @@
{
size_t items = 0;
using namespace blender;
Author
Member

This should be at the top of the function.

This should be at the top of the function.
amelief marked this conversation as resolved
@ -1788,0 +1807,4 @@
using namespace blender;
/* add data block container */
Author
Member

-> /* Add data block container. */
Comments should be capitalized and ending in a period :)
Also check other comments.

-> `/* Add data block container. */` Comments should be capitalized and ending in a period :) Also check other comments.
amelief marked this conversation as resolved
@ -700,1 +707,4 @@
void draw_cels_channel(AnimKeylistDrawList *draw_list,
bDopeSheet */*ads*/,
GreasePencilLayer *gpl,
Author
Member

gpl -> layer

`gpl` -> `layer`
amelief marked this conversation as resolved
@ -504,0 +533,4 @@
/* Node updater callback used for building ActKeyColumns from GPencil frames */
static void nupdate_ak_cel(ActKeyColumn *ak, void * /*data*/)
{
// TODO : Cel *cel = static_cast<Cel *> data;
Author
Member

Commented out code should be removed.
Maybe add a TODO comment for updating the selection.

Commented out code should be removed. Maybe add a TODO comment for updating the selection.
amelief marked this conversation as resolved
@ -1113,0 +1167,4 @@
using namespace blender::bke::greasepencil;
const Layer &layer = gpl->wrap();
for (auto item : layer.frames().items()) {
Cel cel{item.key, item.value};
Author
Member

We tend to initialize structs explicitly in other areas. More like this:

Cel cel;
cel.frame_number = item.key;
cel.frame = item.value;
We tend to initialize structs explicitly in other areas. More like this: ``` Cel cel; cel.frame_number = item.key; cel.frame = item.value; ```
amelief marked this conversation as resolved
@ -94,0 +96,4 @@
/* Cel-framed channels */
void draw_cels_channel(struct AnimKeylistDrawList *draw_list,
struct bDopeSheet *ads,
struct GreasePencilLayer *gpl,
Author
Member

gpl -> layer

`gpl` -> `layer`
amelief marked this conversation as resolved
@ -181,0 +182,4 @@
/* Cels */
void cels_to_keylist(struct AnimData *adt,
struct GreasePencilLayer *gpl,
Author
Member

gpl -> layer

`gpl` -> `layer`
amelief marked this conversation as resolved
Falk David requested review from Sybren A. Stüvel 2023-07-03 17:09:06 +02:00
Sybren A. Stüvel added the
Module
Animation & Rigging
label 2023-07-03 17:09:51 +02:00
Sybren A. Stüvel requested changes 2023-07-03 17:28:46 +02:00
Sybren A. Stüvel left a comment
Member

The code looks decent to me, left a few minor notes inline.

As for the functionality, how do I add a GPv3 object? With GPv3 disabled in the experimental features I can add a regular GP object and animate it, and then I see the keys in the dopesheet. But when I enable GPv3 in the prefs, then create a new object, and then try to animate it, I don't see any keys. Not sure if I'm testing wrong or whether there's something wrong in the code, hence my questions ;-)

The code looks decent to me, left a few minor notes inline. As for the functionality, how do I add a GPv3 object? With GPv3 disabled in the experimental features I can add a regular GP object and animate it, and then I see the keys in the dopesheet. But when I enable GPv3 in the prefs, then create a new object, and then try to animate it, I don't see any keys. Not sure if I'm testing wrong or whether there's something wrong in the code, hence my questions ;-)
@ -1109,3 +1120,3 @@
/* Check for selected nodes. */
if (fcu->rna_path &&
BLI_str_quoted_substr(fcu->rna_path, "nodes[", node_name, sizeof(node_name))) {
BLI_str_quoted_substr(fcu->rna_path, "nodes[", node_name, sizeof(node_name)))

Please keep formatting changes out of a functional PR.

Please keep formatting changes out of a functional PR.
amelief marked this conversation as resolved
@ -3505,2 +3595,2 @@
if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items)) {
items = animdata_filter_gpencil(ac, anim_data, data, filter_mode);
if (U.experimental.use_grease_pencil_version3) {
if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items)) {

What is the reason to repeat the same condition inside both clauses of the if (U.experimental....)? Wouldn't it make more sense to swap those and remove the duplication?

What is the reason to repeat the same condition inside both clauses of the `if (U.experimental....)`? Wouldn't it make more sense to swap those and remove the duplication?
amelief marked this conversation as resolved
@ -318,2 +319,3 @@
if (ctx->show_ipo && actkeyblock_is_valid(ab) &&
(ab->block.flag & ACTKEYBLOCK_FLAG_NON_BEZIER)) {
(ab->block.flag & ACTKEYBLOCK_FLAG_NON_BEZIER))
{

Same as above, keep out formatting changes.

Same as above, keep out formatting changes.
amelief marked this conversation as resolved
@ -54,6 +55,12 @@ BLI_INLINE bool is_cfra_lt(const float a, const float b)
/* --------------- */
/* Just for GreasePencil for now. */

Better to explain what it is first, rather than where it's used. The fact that it has a GreasePencilFrame in there already hints at that this is for GP.

Better to explain what it is first, rather than where it's used. The fact that it has a `GreasePencilFrame` in there already hints at that this is for GP.
amelief marked this conversation as resolved
@ -504,0 +533,4 @@
/* Node updater callback used for building ActKeyColumns from GPencil frames */
static void nupdate_ak_cel(ActKeyColumn *ak, void * /*data*/)
{
// TODO : Update cel selection

Is this to be done in a future commit? Or will this PR be expanded for this?

Is this to be done in a future commit? Or will this PR be expanded for this?

It's planned for a future commit, I guess, as we do not have cel selection at all right now.

It's planned for a future commit, I guess, as we do not have cel selection at all right now.

Actually, don't mind my last comment, we do have selection and type, I am just gonna do these TODOs in this PR :)

Actually, don't mind my last comment, we do have selection and type, I am just gonna do these TODOs in this PR :)
amelief marked this conversation as resolved
@ -1113,0 +1158,4 @@
using namespace blender::bke::greasepencil;
const Layer &layer = gpl->wrap();
for (auto item : layer.frames().items()) {
Cel cel;

It might be a good idea to use Cel cel = {}; or something along those lines. That way if there's ever a new field added to the struct, it'll be initialised to zero. Alternatively add a constructor that simply takes the two arguments; then the addition of a field will simply break the build in places where it's forgotten.

It might be a good idea to use `Cel cel = {};` or something along those lines. That way if there's ever a new field added to the struct, it'll be initialised to zero. Alternatively add a constructor that simply takes the two arguments; then the addition of a field will simply break the build in places where it's forgotten.
amelief marked this conversation as resolved
Amélie Fondevilla force-pushed gpv3-initial-dopesheet-support from 286a055938 to 266f63e7a0 2023-07-04 10:35:37 +02:00 Compare
Falk David requested review from Sybren A. Stüvel 2023-07-04 16:51:08 +02:00
Amélie Fondevilla force-pushed gpv3-initial-dopesheet-support from 99de7b9176 to 08a50d3dfb 2023-07-05 12:38:24 +02:00 Compare

For me this code crashes as soon as I try and draw something with GP. This might have something to do with it:

blender/source/blender/editors/sculpt_paint/grease_pencil_paint.cc:63:28: runtime error: member access within null pointer of type 'GreasePencilRuntimeHandle' (aka 'blender::bke::GreasePencilRuntime')
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior blender/source/blender/editors/sculpt_paint/grease_pencil_paint.cc:63:28 in 

This is with the GP3 experimental flag enabled, restarted Blender, created a new '2D Animation' file, and dragged in the viewport.

For me this code crashes as soon as I try and draw something with GP. This might have something to do with it: ``` blender/source/blender/editors/sculpt_paint/grease_pencil_paint.cc:63:28: runtime error: member access within null pointer of type 'GreasePencilRuntimeHandle' (aka 'blender::bke::GreasePencilRuntime') SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior blender/source/blender/editors/sculpt_paint/grease_pencil_paint.cc:63:28 in ``` This is with the GP3 experimental flag enabled, restarted Blender, created a new '2D Animation' file, and dragged in the viewport.
Author
Member

@dr.sybren The 2D Animation template does not convert the legacy grease pencil object to a grease pencil 3 object yet. The versioning is just not implemented since it's still experimental. You'll have to create a new file and the object yourself (with Shift + A > Grease Pencil > ... ).
Or you can create a GP2 object, then enable the flag and then manually convert it to GP3 with Object > Convert > Grease Pencil.

@dr.sybren The 2D Animation template does not convert the legacy grease pencil object to a grease pencil 3 object yet. The versioning is just not implemented since it's still experimental. You'll have to create a new file and the object yourself (with `Shift + A > Grease Pencil > ...` ). Or you can create a GP2 object, then enable the flag and then manually convert it to GP3 with `Object > Convert > Grease Pencil`.
Sybren A. Stüvel approved these changes 2023-07-11 17:04:10 +02:00
Sybren A. Stüvel left a comment
Member

LGTM, just two remarks that can be handled when landing.

LGTM, just two remarks that can be handled when landing.
@ -3460,0 +3508,4 @@
return GREASE_PENCIL_ANIM_CHANNEL_EXPANDED;
default:
/* This shouldn't happen */

In that case, maybe a BLI_assert_msg() would be in order?

In that case, maybe a `BLI_assert_msg()` would be in order?
amelief marked this conversation as resolved
@ -3571,0 +3646,4 @@
/* Name property for grease pencil layer entries */
static bool acf_gpl_name_prop(bAnimListElem *ale, PointerRNA *r_ptr, PropertyRNA **r_prop)
{
if (ale->data) {

I think it'll be simpler to invert the condition & return early.

  if (ale->data == nullptr) {
    return false;
  }
  // the rest fo the function
I think it'll be simpler to invert the condition & return early. ```c if (ale->data == nullptr) { return false; } // the rest fo the function ```
amelief marked this conversation as resolved
@ -967,3 +969,3 @@
}
case ANIMTYPE_GPLAYER: {
bGPDlayer *gpl = (bGPDlayer *)data;
bGPDlayer *layer = (bGPDlayer *)data;

I like how this got renamed as well, so that there is not two gpl variables with different semantics.

I like how this got renamed as well, so that there is not two `gpl` variables with different semantics.

I like that you pointed out this specific spot, because I renamed the legacy one, when I should have renamed the gpv3 one instead. 😅 I will change that, and check all the other renamed variables. You remark is still valid though, and I agree.

I like that you pointed out this specific spot, because I renamed the legacy one, when I should have renamed the gpv3 one instead. 😅 I will change that, and check all the other renamed variables. You remark is still valid though, and I agree.
amelief marked this conversation as resolved
@ -701,0 +711,4 @@
GreasePencilLayer *layer,
float ypos,
float yscale_fac,
int saction_flag)

the float and int params can be const I think.

the `float` and `int` params can be `const` I think.
amelief marked this conversation as resolved
Amélie Fondevilla force-pushed gpv3-initial-dopesheet-support from 4ef3c56ead to 60130d7f03 2023-07-11 17:56:18 +02:00 Compare
Falk David merged commit 09f8f4d049 into main 2023-07-12 10:32:18 +02:00
Falk David deleted branch gpv3-initial-dopesheet-support 2023-07-12 10:32:19 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#108807
No description provided.