WIP: Refactor: GPv3: Frames API #121403

Closed
Falk David wants to merge 9 commits from filedescriptor/blender:gpv3-refactor-frames-api into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

The GPv3 API for frames was less than ideal.

Problems:

  • The drawing array was exposed through the public API leading to issues where the user count of drawings could get out of sync. E.g. Layer::add_frame and Layer::remove_frame potentially changes the user count of drawings, but doesn't actually update them (because the layer cannot access the drawings array).
  • Using drawing indices as a way to reference drawings is extremly fragile. If the drawing array changes in any way, indices become invalid.

Solution:

  • Don't expose the drawing array to the public API. Similar to how the user interacts with grease pencil, drawings are always "attached" to keyframes.
  • Drawings are always read/created/deleted through the keyframe API:
    • To create a drawing, use Drawing *drawing = grease_pencil.insert_frame(layer, ...).
    • To remove drawings, remove the keyframes grease_pencil.remove_frames(...). Drawings with no users (keyframes) get deleted.
    • duplicate_keys(...) to duplicate drawings, remap_keys(...), etc.
  • Drawings shouldn't be accessed using the drawings array. Instead, we use the get_drawing_at, get_editable_drawing_at API to retrieve drawings on layers at a specific time.

Resolves #120221.

The GPv3 API for frames was less than ideal. Problems: * The drawing array was exposed through the public API leading to issues where the user count of drawings could get out of sync. E.g. `Layer::add_frame` and `Layer::remove_frame` potentially changes the user count of drawings, but doesn't actually update them (because the layer cannot access the drawings array). * Using drawing indices as a way to reference drawings is extremly fragile. If the drawing array changes in any way, indices become invalid. Solution: * Don't expose the drawing array to the public API. Similar to how the user interacts with grease pencil, drawings are always "attached" to keyframes. * Drawings are always read/created/deleted through the keyframe API: * To create a drawing, use `Drawing *drawing = grease_pencil.insert_frame(layer, ...)`. * To remove drawings, remove the keyframes `grease_pencil.remove_frames(...)`. Drawings with no users (keyframes) get deleted. * `duplicate_keys(...)` to duplicate drawings, `remap_keys(...)`, etc. * Drawings shouldn't be accessed using the `drawings` array. Instead, we use the `get_drawing_at`, `get_editable_drawing_at` API to retrieve drawings on layers at a specific time. Resolves #120221.
Falk David added 4 commits 2024-05-03 17:47:21 +02:00
Falk David added 3 commits 2024-05-03 17:54:02 +02:00
Hans Goudey reviewed 2024-05-03 18:19:15 +02:00
Hans Goudey left a comment
Member

I don't really understand the changes to the API. But the assignment operators and move constructor for Drawing look good to me

I don't really understand the changes to the API. But the assignment operators and move constructor for `Drawing` look good to me
@ -71,6 +71,9 @@ class Drawing : public ::GreasePencilDrawing {
public:
Drawing();
Member

Typically the order is to keep assignment after constructors:

  CurvesGeometry();
  CurvesGeometry(int point_num, int curve_num);
  CurvesGeometry(const CurvesGeometry &other);
  CurvesGeometry(CurvesGeometry &&other);
  CurvesGeometry &operator=(const CurvesGeometry &other);
  CurvesGeometry &operator=(CurvesGeometry &&other);
  ~CurvesGeometry();
Typically the order is to keep assignment after constructors: ``` CurvesGeometry(); CurvesGeometry(int point_num, int curve_num); CurvesGeometry(const CurvesGeometry &other); CurvesGeometry(CurvesGeometry &&other); CurvesGeometry &operator=(const CurvesGeometry &other); CurvesGeometry &operator=(CurvesGeometry &&other); ~CurvesGeometry();
filedescriptor marked this conversation as resolved
@ -315,6 +315,39 @@ Drawing::Drawing(const Drawing &other)
this->runtime->curve_texture_matrices = other.runtime->curve_texture_matrices;
}
Drawing &Drawing::operator=(const Drawing &other)
Member

Order can change here too

Order can change here too
filedescriptor marked this conversation as resolved
@ -318,0 +328,4 @@
Drawing::Drawing(Drawing &&other)
{
this->base.type = other.base.type;
other.base.type = 0;
Member

Would be better to use the enum type here I think

Would be better to use the enum type here I think
Author
Member

We're just clearing the data here, so I think using the enum is a bit missleading.

We're just clearing the data here, so I think using the enum is a bit missleading.
Member

I don't think it's misleading. The only reason we aren't required by the type system to use the enum type is that DNA is stuck in C rather than C++. If the value of type in the "cleared" Drawing is important, then the enum type should be used. Otherwise the type just shouldn't be reset at all.

I don't think it's misleading. The only reason we aren't required by the type system to use the enum type is that DNA is stuck in C rather than C++. If the value of `type` in the "cleared" `Drawing` is important, then the enum type should be used. Otherwise the type just shouldn't be reset at all.
filedescriptor marked this conversation as resolved
Falk David added 1 commit 2024-05-03 18:34:25 +02:00
Falk David added 1 commit 2024-05-06 11:21:12 +02:00
Author
Member

Most of these changes have been committed as individual commits.

Most of these changes have been committed as individual commits.
Falk David closed this pull request 2024-05-14 15:36:43 +02:00

Pull request closed

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#121403
No description provided.