GPv3 : Transform action for grease pencil frames. #110743

Merged
Amélie Fondevilla merged 43 commits from amelief/blender:gpv3-move-keyframe into main 2023-08-10 12:57:39 +02:00

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 functions and structures in the grease pencil API :

  • move_frames to move a set of frames given a map of key transformations (overwrites frames),
  • the structure LayerTransData that stores in the layer runtime some useful data for the frames transformation,
  • initialize_trans_data, reset_trans_data, update_trans_data and apply_trans_data to manipulate the transform data at layer level.
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 functions and structures in the grease pencil API : - `move_frames` to move a set of frames given a map of key transformations (overwrites frames), - the structure `LayerTransData` that stores in the layer runtime some useful data for the frames transformation, - `initialize_trans_data`, `reset_trans_data`, `update_trans_data` and `apply_trans_data` to manipulate the transform data at layer level.
Author
Member

Note: this is still WIP because right now we have the issue that the move function may delete frames that were going to be moved afterwards.

Example :
The frame map is { (f0: d0), (f1:d1) }
Let's say we want to move (f1:d1) to f0, and (f0:d0) to f2.
We move (f1:d1) to f0, the map becomes { (f0:d1) }, and now we cannot move (f0,d0) anymore because it is not in the map.

Note: this is still WIP because right now we have the issue that the move function may delete frames that were going to be moved afterwards. Example : The frame map is `{ (f0: d0), (f1:d1) }` Let's say we want to move `(f1:d1)` to `f0`, and `(f0:d0)` to `f2`. We move `(f1:d1)` to `f0`, the map becomes `{ (f0:d1) }`, and now we cannot move `(f0,d0)` anymore because it is not in the map.
Amélie Fondevilla added this to the Grease Pencil project 2023-08-03 09:34:30 +02:00
Amélie Fondevilla force-pushed gpv3-move-keyframe from 551feddb65 to 42ca4bb57b 2023-08-07 18:20:41 +02:00 Compare
Amélie Fondevilla force-pushed gpv3-move-keyframe from 42ca4bb57b to f95e6ebfcc 2023-08-08 11:16:05 +02:00 Compare
Amélie Fondevilla changed title from WIP: GPv3 : Transform action for grease pencil frames. to GPv3 : Transform action for grease pencil frames. 2023-08-08 17:13:15 +02:00
Amélie Fondevilla requested review from Falk David 2023-08-08 17:13:28 +02:00
Falk David requested changes 2023-08-08 19:01:41 +02:00
Falk David left a comment
Member

Some more comments

Some more comments
@ -192,6 +192,16 @@ class LayerMask : public ::GreasePencilLayerMask {
~LayerMask();
};
struct LayerTransData {
Member

LayerTransformData

`LayerTransformData`
amelief marked this conversation as resolved
@ -195,0 +195,4 @@
struct LayerTransData {
enum FrameTransformationStatus { TRANS_CLEAR, TRANS_INIT, TRANS_RUNNING };
Map<int, int> trans_map;
Member

To avoid having the type in the name, maybe something like frames_destination would work better.
And this should have a docstring.

To avoid having the type in the name, maybe something like `frames_destination` would work better. And this should have a `docstring`.
amelief marked this conversation as resolved
@ -1576,0 +1586,4 @@
/* Remove all frames that have a mapping. */
for (const int frame_number : trans_frame_numbers.keys()) {
layer.remove_frame(frame_number);
}
Member

drawings_indices_to_check_for_deletion

`drawings_indices_to_check_for_deletion`
amelief marked this conversation as resolved
@ -48,0 +105,4 @@
switch (trans_data.status) {
case LayerTransData::TRANS_INIT:
/* The transdata was only initialized. No transformation was applied yet.
Member

Maybe instead of the switch with ATTR_FALLTHROUGH just use two ifs:

if (trans_data.status == LayerTransData::TRANS_INIT) {
  ...
}
if (trans_data.status == LayerTransData::TRANS_RUNNING) {
  ...
}
Maybe instead of the `switch` with `ATTR_FALLTHROUGH` just use two `if`s: ``` if (trans_data.status == LayerTransData::TRANS_INIT) { ... } if (trans_data.status == LayerTransData::TRANS_RUNNING) { ... } ```
amelief marked this conversation as resolved
Falk David requested changes 2023-08-09 16:22:42 +02:00
Falk David left a comment
Member

I added some comments for how the code should be changed to use the new remove functions.

I added some comments for how the code should be changed to use the new remove functions.
@ -1576,0 +1607,4 @@
GreasePencilDrawingBase *drawing_base = this->drawings(frame_to_overwrite.drawing_index);
if (drawing_base->type == GP_DRAWING) {
reinterpret_cast<GreasePencilDrawing *>(drawing_base)->wrap().remove_user();
drawing_indices_to_check_for_deletion.append(frame_to_overwrite.drawing_index);
Member

This is no longer needed.

This is no longer needed.
amelief marked this conversation as resolved
@ -1576,0 +1616,4 @@
}
/* Remove drawings if they have no more users. */
for (const int drawing_index : drawing_indices_to_check_for_deletion) {
Member

This can now just call this->remove_drawings_with_no_users()

This can now just call `this->remove_drawings_with_no_users()`
amelief marked this conversation as resolved
@ -43,8 +44,125 @@ struct tGPFtransdata {
float loc[3]; /* #td->val and #td->loc share the same pointer. */
};
int *sdata; /* pointer to gpf->framenum */
void *extra{};
Member

Is this used?

Is this used?
amelief marked this conversation as resolved
Iliya Katushenock reviewed 2023-08-09 16:28:12 +02:00
@ -761,0 +765,4 @@
return -1;
}
SortedKeysIterator frame_number_it = std::next(this->sorted_keys().begin(), frame_key);
if (std::next(frame_number_it) == this->sorted_keys().end()) {

frame_number_it == this->sorted_keys().last()?

`frame_number_it == this->sorted_keys().last()`?
Member

*frame_number_it == this->sorted_keys().last() would work, yea. Maybe that's a bit nicer

`*frame_number_it == this->sorted_keys().last()` would work, yea. Maybe that's a bit nicer
amelief marked this conversation as resolved
Amélie Fondevilla force-pushed gpv3-move-keyframe from 1c08651ef5 to 99090c1521 2023-08-09 16:58:22 +02:00 Compare
Amélie Fondevilla force-pushed gpv3-move-keyframe from 99090c1521 to 8407bcc8e5 2023-08-09 17:19:48 +02:00 Compare
Falk David requested changes 2023-08-09 17:51:45 +02:00
Falk David left a comment
Member

Few more comments.

Few more comments.
@ -1604,2 +1606,4 @@
}
void GreasePencil::move_frames(blender::bke::greasepencil::Layer &layer,
const blender::Map<int, int> &trans_frame_numbers)
Member

trans_frame_numbers -> frame_number_destinations
Same in the header.

`trans_frame_numbers` -> `frame_number_destinations` Same in the header.
amelief marked this conversation as resolved
@ -1606,0 +1610,4 @@
{
using namespace blender;
/* Clear the frames' data. */
Member

Comment looks out-of-date?

Comment looks out-of-date?
amelief marked this conversation as resolved
@ -619,0 +866,4 @@
if ((t->state == TRANS_RUNNING) && ((td->flag & TD_GREASE_PENCIL_FRAME) != 0)) {
using namespace blender::bke::greasepencil;
grease_pencil_layer_update_trans_data(*static_cast<Layer *>(td->extra),
Member

Since there is only one occurrence, I'd remove the using namespace here and just use blender::bke::greasepencil::Layer

Since there is only one occurrence, I'd remove the `using namespace` here and just use `blender::bke::greasepencil::Layer`
amelief marked this conversation as resolved
@ -640,0 +902,4 @@
if (ale->type != ANIMTYPE_GREASE_PENCIL_LAYER) {
continue;
}
grease_pencil_layer_reset_trans_data(*static_cast<Layer *>(ale->data));
Member

Same as above.

Same as above.
amelief marked this conversation as resolved
Amélie Fondevilla added 3 commits 2023-08-09 18:05:20 +02:00
Falk David approved these changes 2023-08-10 10:54:45 +02:00
Falk David left a comment
Member

Looks good to me!

Looks good to me!
Amélie Fondevilla merged commit 09d2108bf5 into main 2023-08-10 12:57:39 +02:00
Amélie Fondevilla deleted branch gpv3-move-keyframe 2023-08-10 12:57:41 +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#110743
No description provided.