GPv3: Insert grease pencil keyframe from the dopesheet #110649

Merged
Amélie Fondevilla merged 23 commits from amelief/blender:gpv3-insert-keyframe into main 2023-08-02 14:56:24 +02:00

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.

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.
Author
Member

Note: There is a TODO left in insert_duplicate_frame, because we need to add a user to the drawing if the function is called with the do_instance option. We need #110579 to do so.

However, this option is never called for this insert keyframe operator. Thus, I don't think it is needed to land this PR.
I we want to land this PR before 110579, we could remove the option in this function for clarity.

Note: There is a TODO left in `insert_duplicate_frame`, because we need to add a user to the drawing if the function is called with the `do_instance` option. We need #110579 to do so. However, this option is never called for this insert keyframe operator. Thus, I don't think it is needed to land this PR. I we want to land this PR before 110579, we could remove the option in this function for clarity.
Amélie Fondevilla added this to the Grease Pencil project 2023-07-31 12:43:25 +02:00
Amélie Fondevilla requested review from Falk David 2023-07-31 12:43:36 +02:00
Falk David requested changes 2023-08-01 12:50:14 +02:00
Falk David left a comment
Member

First pass.

First pass.
@ -1344,2 +1344,4 @@
}
void GreasePencil::add_duplicate_drawings(
const int add_num, const blender::bke::greasepencil::Drawing &duplicated_drawing)
Member

add_num -> duplicate_num
duplicated_drawing -> drawing (since this is the drawing to be duplicated not the actually duplicated one)

`add_num` -> `duplicate_num` `duplicated_drawing` -> `drawing` (since this is the drawing to be duplicated not the actually duplicated one)
amelief marked this conversation as resolved
@ -1359,2 +1373,4 @@
}
bool GreasePencil::insert_duplicate_frame(blender::bke::greasepencil::Layer &layer,
const GreasePencilFrame &duplicated_frame,
Member

duplicated_frame -> frame

`duplicated_frame` -> `frame`
amelief marked this conversation as resolved
@ -1361,0 +1381,4 @@
const int drawing_index = do_instance ? duplicated_frame.drawing_index :
int(this->drawings().size());
const int duration = 0;
Member

Shouldn't this get the duration from the duplicate_frame?

Shouldn't this get the duration from the `duplicate_frame`?
Author
Member

Agree. I had to change the function so that it takes an index instead of directly the frame to be duplicated. I think now it works, though.

Agree. I had to change the function so that it takes an index instead of directly the frame to be duplicated. I think now it works, though.
amelief marked this conversation as resolved
@ -1361,0 +1390,4 @@
frame->type = duplicated_frame.type;
const GreasePencilDrawingBase *drawing_base = this->drawings()[duplicated_frame.drawing_index];
Member

Can use a new API here this->drawings(duplicated_frame.drawing_index). Tiny bit nicer.

Can use a new API here `this->drawings(duplicated_frame.drawing_index)`. Tiny bit nicer.
amelief marked this conversation as resolved
@ -1361,0 +1391,4 @@
frame->type = duplicated_frame.type;
const GreasePencilDrawingBase *drawing_base = this->drawings()[duplicated_frame.drawing_index];
BLI_assert_msg((drawing_base->type == GP_DRAWING),
Member

I think instead of the assert here I would prefer a switch that has a TODO comment for the GP_DRAWING_REFERENCE case and does nothing.

I think instead of the `assert` here I would prefer a `switch` that has a `TODO` comment for the `GP_DRAWING_REFERENCE` case and does nothing.
amelief marked this conversation as resolved
@ -768,0 +777,4 @@
using namespace blender::bke::greasepencil;
Layer *layer = static_cast<Layer *>(ale->data);
GreasePencil *grease_pencil = reinterpret_cast<GreasePencil *>(ale->id);
const int frame_number = ac->scene->r.cfra;
Member

Even if it's a bit longer, I would prefer this to be current_frame_number. Makes the rest more readable imho.

Even if it's a bit longer, I would prefer this to be `current_frame_number`. Makes the rest more readable imho.
amelief marked this conversation as resolved
@ -768,0 +780,4 @@
const int frame_number = ac->scene->r.cfra;
if (layer->frames().contains(frame_number)) {
/* A frame already exists at the current frame number. */
Member

This comment can be removed with the change suggested above.

This comment can be removed with the change suggested above.
amelief marked this conversation as resolved
@ -768,0 +788,4 @@
if (hold_previous) {
const GreasePencilFrame *active_frame = layer->frame_at(frame_number);
if ((active_frame == nullptr) || (active_frame->is_null())) {
/* There is no active frame to hold to, or it's a null frame. */
Member

/* There is no active frame to hold to, or it's a null frame. Therefore just insert a blank frame. */

`/* There is no active frame to hold to, or it's a null frame. Therefore just insert a blank frame. */`
amelief marked this conversation as resolved
Amélie Fondevilla force-pushed gpv3-insert-keyframe from 898eaec510 to f6a49de5fc 2023-08-01 16:24:52 +02:00 Compare
Falk David requested changes 2023-08-01 17:08:27 +02:00
Falk David left a comment
Member

One more thing I noticed.

One more thing I noticed.
@ -768,0 +805,4 @@
}
if (changed) {
layer->tag_frames_map_keys_changed();
Member

the layer.add_frame function will do the tagging already. I think this is not needed.

the `layer.add_frame` function will do the tagging already. I think this is not needed.
amelief marked this conversation as resolved
Falk David requested changes 2023-08-01 17:08:28 +02:00
Falk David left a comment
Member

One more thing I noticed.

One more thing I noticed.
Falk David requested changes 2023-08-01 17:45:43 +02:00
Falk David left a comment
Member

Second pass :)

Second pass :)
@ -1406,0 +1436,4 @@
const int duplicate_frame_number,
const bool do_instance)
{
using namespace blender;
Member

using namespace blender::bke::greasepencil; here so we can use Drawing below.

`using namespace blender::bke::greasepencil;` here so we can use `Drawing` below.
amelief marked this conversation as resolved
@ -1406,0 +1438,4 @@
{
using namespace blender;
BLI_assert(layer.frames().contains(frame_number));
Member

Rather than asserting here, I think we can return false. I don't think we should crash here if the frame_number isn't found.

Rather than asserting here, I think we can return `false`. I don't think we should crash here if the `frame_number` isn't found.
amelief marked this conversation as resolved
@ -1406,0 +1454,4 @@
const GreasePencilDrawingBase *drawing_base = this->drawings(frame.drawing_index);
switch (drawing_base->type) {
case GP_DRAWING: {
const GreasePencilDrawing *drawing = reinterpret_cast<const GreasePencilDrawing *>(
Member

Can be directly Drawing &drawing = reinterpret_cast<const GreasePencilDrawing *>(drawing_base)->wrap();

Can be directly `Drawing &drawing = reinterpret_cast<const GreasePencilDrawing *>(drawing_base)->wrap();`
amelief marked this conversation as resolved
@ -1406,0 +1457,4 @@
const GreasePencilDrawing *drawing = reinterpret_cast<const GreasePencilDrawing *>(
drawing_base);
if (do_instance) {
/* TODO : add user to the drawing. */
Member

drawing.add_user(); (needs a rebase with main)

`drawing.add_user();` (needs a rebase with `main`)
amelief marked this conversation as resolved
@ -1406,0 +1460,4 @@
/* TODO : add user to the drawing. */
}
else {
this->add_duplicate_drawings(1, drawing->wrap());
Member

This should have a comment saying that the inserted frame already points to this duplicated drawing, because the index was set to int(this->drawings().size()).

This should have a comment saying that the inserted frame already points to this duplicated drawing, because the index was set to `int(this->drawings().size())`.
amelief marked this conversation as resolved
Amélie Fondevilla force-pushed gpv3-insert-keyframe from 0c6313e538 to 44523a27e1 2023-08-02 11:05:06 +02:00 Compare
Falk David approved these changes 2023-08-02 11:55:35 +02:00
Falk David left a comment
Member

Some final small comments, but otherwise this looks good.

Some final small comments, but otherwise this looks good.
@ -34,6 +37,8 @@
#include "BKE_fcurve.h"
#include "BKE_global.h"
#include "BKE_gpencil_legacy.h"
#include "BKE_grease_pencil.h"
Member

Don't think this header needs to be included.

Don't think this header needs to be included.
amelief marked this conversation as resolved
@ -481,10 +481,17 @@ typedef struct GreasePencil {
void remove_layer(blender::bke::greasepencil::Layer &layer);
void add_empty_drawings(int add_num);
void add_duplicate_drawings(int add_num,
Member

duplicate_num and Drawing &drawing

`duplicate_num` and `Drawing &drawing`
amelief marked this conversation as resolved
Amélie Fondevilla force-pushed gpv3-insert-keyframe from 61fcbdcb00 to 33fc703589 2023-08-02 14:36:53 +02:00 Compare
Amélie Fondevilla merged commit fd75695bed into main 2023-08-02 14:56:24 +02:00
Amélie Fondevilla deleted branch gpv3-insert-keyframe 2023-08-02 14:56:26 +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
2 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#110649
No description provided.