WIP: GreasePencilFrame API #116045 #118439

Draft
Jaime Torres wants to merge 9 commits from mews6/blender:grease-pencil-frame-api into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
First-time contributor

WIP for the GreasePencilFrame API described in issue #116045 . I'm pretty new to this codebase and this code Does not compile yet, so please, if you notice any problem on this patch, let me know so i can correct it. The initial patch has a few of the definitions required for this project, but also some things missing. I'll be working on it as we figure out what works and what doesn't. I'll keep updating this description as we figure out goals and limitations.

@filedescriptor

WIP for the GreasePencilFrame API described in issue #116045 . I'm pretty new to this codebase and this code **Does not compile yet**, so please, if you notice any problem on this patch, let me know so i can correct it. The initial patch has a few of the definitions required for this project, but also some things missing. I'll be working on it as we figure out what works and what doesn't. I'll keep updating this description as we figure out goals and limitations. @filedescriptor
Jaime Torres added 3 commits 2024-02-18 22:52:23 +01:00
Jaime Torres requested review from Falk David 2024-02-18 22:54:55 +01:00
casey-bianco-davis added this to the Grease Pencil project 2024-02-19 01:56:13 +01:00
casey-bianco-davis added the
Interest
Grease Pencil
label 2024-02-19 01:56:29 +01:00
Falk David requested changes 2024-02-19 11:51:28 +01:00
Falk David left a comment
Member

Added some comments that should help.

Added some comments that should help.
@ -158,0 +163,4 @@
// TODO
// blender::Span<Frame *> frame = grease_pencil
blender::Span<Frames *> frames = grease_pencil->frames();
Member

What you want here are the frames in the layer.

Layer &layer = static_cast<GreasePencilLayer *>(ptr->data)->wrap();
blender::Span<FramesMapKey> sorted_keys = layer.sorted_keys();

Note: Because the callback has been defined on a property that's a "GreasePencilLayer", the ptr->data points to this type. That's how you get the layer.

What you want here are the frames in the layer. ``` Layer &layer = static_cast<GreasePencilLayer *>(ptr->data)->wrap(); blender::Span<FramesMapKey> sorted_keys = layer.sorted_keys(); ``` Note: Because the callback has been defined on a property that's a "GreasePencilLayer", the `ptr->data` points to this type. That's how you get the layer.
@ -158,0 +168,4 @@
}
static void rna_iterator_grease_pencil_frames_end(CollectionPropertyIterator *iter,
PointerRNA *ptr)
Member

PointerRNA *ptr -> PointerRNA * /*ptr*/ (because it's unused)

`PointerRNA *ptr` -> `PointerRNA * /*ptr*/` (because it's unused)
filedescriptor marked this conversation as resolved
@ -158,0 +171,4 @@
PointerRNA *ptr)
{
using namespace blender::bke::greasepencil;
// TODO
Member
rna_iterator_array_end(iter);
``` rna_iterator_array_end(iter); ```
filedescriptor marked this conversation as resolved
@ -158,0 +179,4 @@
{
// TODO
GreasePencil *grease_pencil = rna_grease_pencil(ptr);
return grease_pencil->frames().size();
Member
Layer &layer = static_cast<GreasePencilLayer *>(ptr->data)->wrap();
return layer.frames().size();
``` Layer &layer = static_cast<GreasePencilLayer *>(ptr->data)->wrap(); return layer.frames().size(); ```
@ -158,0 +186,4 @@
PointerRNA *ptr)
{
using namespace blender::bke::greasepencil;
// TODO
Member

We're iterating over the keys, so get the key from the iterator but then lookup the frame in the frames and return that.

FramesMapKey key = *rna_iterator_array_get(iter);

Layer &layer = static_cast<GreasePencilLayer *>(ptr->data)->wrap();
return layer.frames().lookup_ptr(key);
We're iterating over the keys, so get the key from the iterator but then lookup the frame in the frames and return that. ``` FramesMapKey key = *rna_iterator_array_get(iter); Layer &layer = static_cast<GreasePencilLayer *>(ptr->data)->wrap(); return layer.frames().lookup_ptr(key); ```
@ -178,0 +216,4 @@
srna = RNA_def_struct(brna, "GreasePencilFrame", nullptr);
RNA_def_struct_sdna(srna, "GreasePencilFrame");
RNA_def_struct_ui_text(srna, "Grease Pencil Frame", "Collection of frames");
Member

"Collection of frames" -> "A Grease Pencil keyframe"

`"Collection of frames"` -> `"A Grease Pencil keyframe"`
@ -178,0 +217,4 @@
srna = RNA_def_struct(brna, "GreasePencilFrame", nullptr);
RNA_def_struct_sdna(srna, "GreasePencilFrame");
RNA_def_struct_ui_text(srna, "Grease Pencil Frame", "Collection of frames");
RNA_def_struct_path_func(srna, "rna_GreasePencilFrame_path");
Member

This is not needed AFAIK

This is not needed AFAIK
@ -178,0 +221,4 @@
// GreasePencilDrawing stub. TODO
RNA_def_property(prop, "drawing", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "GreasePencilDrawing");
Member

The GreasePencilDrawing type is not defined.
You need to add a function rna_def_grease_pencil_drawing that defines it:

static void rna_def_grease_pencil_drawing(BlenderRNA *brna)
{
  StructRNA *srna;
  PropertyRNA *prop;

  srna = RNA_def_struct(brna, "GreasePencilDrawing", nullptr);
  RNA_def_struct_sdna(srna, "GreasePencilDrawing");
}

Make sure to call this function to define the type in RNA_def_grease_pencil (same for rna_def_grease_pencil_frame)

The `GreasePencilDrawing` type is not defined. You need to add a function `rna_def_grease_pencil_drawing` that defines it: ``` static void rna_def_grease_pencil_drawing(BlenderRNA *brna) { StructRNA *srna; PropertyRNA *prop; srna = RNA_def_struct(brna, "GreasePencilDrawing", nullptr); RNA_def_struct_sdna(srna, "GreasePencilDrawing"); } ``` Make sure to call this function to define the type in `RNA_def_grease_pencil` (same for `rna_def_grease_pencil_frame`)
filedescriptor marked this conversation as resolved
@ -227,6 +290,21 @@ static void rna_def_grease_pencil_layer(BlenderRNA *brna)
RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_grease_pencil_update");
}
static void rna_def_grease_pencil_frames_api(BlenderRNA *brna, PropertyRNA *cprop)
Member

This is not needed for this PR.

This is not needed for this PR.
Jaime Torres added 2 commits 2024-02-19 21:59:49 +01:00
Author
First-time contributor

Just implemented your suggestions. I'll be on the lookout for any more problems. Also, for the properties required of GreasePencilFrame (a selection status and the keyframe time), if I get the structure correctly, I'm imagining that we should put them in rna_def_grease_pencil_drawing, Are they going to be defined through RNA_def_property in the same vein as GreasePencilDrawing? I'm looking at a few other places in this file where we seem to reference whether or not something is selected, such as in this line:

9be14b3bce/source/blender/makesrna/intern/rna_grease_pencil.cc (L322)

but there is no attribute defined for selection, would this suffice for GreasePencilFrame?

Just implemented your suggestions. I'll be on the lookout for any more problems. Also, for the properties required of GreasePencilFrame (a selection status and the keyframe time), if I get the structure correctly, I'm imagining that we should put them in `rna_def_grease_pencil_drawing`, Are they going to be defined through `RNA_def_property` in the same vein as `GreasePencilDrawing`? I'm looking at a few other places in this file where we seem to reference whether or not something is selected, such as in this line: https://projects.blender.org/blender/blender/src/commit/9be14b3bce3c95d18324ad2e3ce22c1f768db0f7/source/blender/makesrna/intern/rna_grease_pencil.cc#L322 but there is no attribute defined for selection, would this suffice for GreasePencilFrame?
Member

if I get the structure correctly, I'm imagining that we should put them in rna_def_grease_pencil_drawing

No, they should go in rna_def_grease_pencil_frame since that's where everything on the frame goes.

> if I get the structure correctly, I'm imagining that we should put them in `rna_def_grease_pencil_drawing` No, they should go in `rna_def_grease_pencil_frame` since that's where everything on the frame goes.
Jaime Torres added 1 commit 2024-02-21 22:39:15 +01:00
Jaime Torres added 1 commit 2024-02-21 23:03:44 +01:00
Author
First-time contributor

Another little question, what do we mean for a property for the keyframe time on this issue? looking into the way stuff is organized on DNA_grease_pencil_types.h i see that for GreasePencilFrame int drawing_index is defined as an "Index into the GreasePencil->drawings array.". Do you refer to this property when referring to keyframe time? Also could this be implemented like how Frame Number is defined in rna_gpencil_legacy.cc or is there any other considerations for it?

Another little question, what do we mean for `a property for the keyframe time` on this issue? looking into the way stuff is organized on `DNA_grease_pencil_types.h` i see that for GreasePencilFrame `int drawing_index` is defined as an "Index into the GreasePencil->drawings array.". Do you refer to this property when referring to keyframe time? Also could this be implemented like how `Frame Number` is defined in `rna_gpencil_legacy.cc` or is there any other considerations for it?
Member

@mews6 Ah I see, in the current API, the frame_number was a property on the frame that indicates the start time of that keyframe. With the new data model, the frame doesn't actually know about what its start time is. The layer now holds that information. So I think we shouldn't add this property to the frame.

@mews6 Ah I see, in the current API, the `frame_number` was a property on the frame that indicates the start time of that keyframe. With the new data model, the frame doesn't actually know about what its start time is. The layer now holds that information. So I think we shouldn't add this property to the frame.
Falk David requested changes 2024-02-22 10:44:04 +01:00
@ -158,0 +163,4 @@
// TODO
Layer &layer = static_cast<GreasePencilLayer *>(ptr->data)->wrap();
blender::Span<FramesMapKey> sorted_keys = layer.sorted_keys();
Member

Don't forget the rna_iterator_array_begin(iter, sorted_keys.data(), sizeof(FramesMapKey), sorted_keys.size(), false, nullptr);

Don't forget the `rna_iterator_array_begin(iter, sorted_keys.data(), sizeof(FramesMapKey), sorted_keys.size(), false, nullptr);`
filedescriptor marked this conversation as resolved
@ -178,0 +229,4 @@
RNA_def_struct_ui_text(srna, "Grease Pencil Frame", "A Grease Pencil keyframe");
RNA_def_struct_path_func(srna, "rna_GreasePencilFrame_path");
// GreasePencilDrawing stub. TODO
Member

Comment can be removed now.

Comment can be removed now.
@ -188,0 +256,4 @@
prop = RNA_def_property(srna, "frames", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, "GreasePencilFrame");
RNA_def_property_collection_funcs(prop,
"rna_iterator_grease_pencil_frames_begin", // TODO
Member

// TODO can be removed now it looks like.

`// TODO` can be removed now it looks like.
First-time contributor

Hi @mews6 .

Glad to see you here! 🦊

Hi @mews6 . Glad to see you here! 🦊
Jaime Torres added 1 commit 2024-02-23 06:11:36 +01:00
Jaime Torres added 1 commit 2024-02-25 23:49:22 +01:00
Author
First-time contributor

Just added the call you told me to, also removed TODO comments .

Just added the call you told me to, also removed TODO comments .
Falk David requested changes 2024-02-26 10:45:55 +01:00
Falk David left a comment
Member

Got a comment about rna_iterator_grease_pencil_frames_end.
Have you tested this with all the changes yet? Does it compile for you?

Got a comment about `rna_iterator_grease_pencil_frames_end`. Have you tested this with all the changes yet? Does it compile for you?
@ -158,0 +169,4 @@
iter, sorted_keys.data(), sizeof(FramesMapKey), sorted_keys.size(), false, nullptr);
}
static void rna_iterator_grease_pencil_frames_end(CollectionPropertyIterator *iter,
Member

Since this function doesn't do anything but call rna_iterator_array_end, you don't need it.
For RNA_def_property_collection_funcs, just use the "rna_iterator_array_end" callback directly.

Since this function doesn't do anything but call `rna_iterator_array_end`, you don't need it. For `RNA_def_property_collection_funcs`, just use the `"rna_iterator_array_end"` callback directly.
This pull request has changes conflicting with the target branch.
  • source/blender/makesrna/intern/rna_grease_pencil.cc

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u grease-pencil-frame-api:mews6-grease-pencil-frame-api
git checkout mews6-grease-pencil-frame-api
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#118439
No description provided.