GPv3: Python API: GreasePencilFrame #116045

Open
opened 2023-12-11 16:43:35 +01:00 by Falk David · 8 comments
Member

We need a Python API for the GreasePencilFrame. See GreasePencilFrame in DNA_grease_pencil_types.h and class Layer in BKE_grease_pencil.hh

The layer needs a collection property:

  • Add a new collection property frames in rna_def_grease_pencil_layer.
  • This will need a custom collection iterator that iterates over the layer.frames(). Use the sorted_keys() cache so that the collection returns the elements sorted by the scene time.

The GreasePencilFrame should have

  • a pointer drawing to a GreasePencilDrawing (which can just be a stub for now).
  • a property for the keyframe time
  • a property with the selection status
We need a Python API for the `GreasePencilFrame`. See `GreasePencilFrame` in `DNA_grease_pencil_types.h` and `class Layer` in `BKE_grease_pencil.hh` The layer needs a collection property: * Add a new collection property `frames` in `rna_def_grease_pencil_layer`. * This will need a custom collection iterator that iterates over the `layer.frames()`. Use the `sorted_keys()` cache so that the collection returns the elements sorted by the scene time. The `GreasePencilFrame` should have * a pointer `drawing` to a `GreasePencilDrawing` (which can just be a stub for now). * a property for the keyframe time * a property with the selection status
Falk David added the
Type
To Do
label 2023-12-11 16:43:35 +01:00
Falk David added this to the Grease Pencil project 2023-12-11 16:43:43 +01:00

Given what we talked, could i take care of this as a first step?

Given what we talked, could i take care of this as a first step?
Author
Member

@mewslore Yes :)

@mewslore Yes :)

Alright, I'm forking the repository and I'll work from there. Is there anything else i should take into account?

Alright, I'm forking the repository and I'll work from there. Is there anything else i should take into account?
Author
Member

@mews6 If you haven't already, then this is good to read https://wiki.blender.org/wiki/Tools/Pull_Requests

@mews6 If you haven't already, then this is good to read https://wiki.blender.org/wiki/Tools/Pull_Requests

Alright, it's been a while, and i took a break to celebrate the holidays with my family (which is why i've been so silent as of late, sorry for that). However, i already took a look into the documentation of the existing Python API and i've been reading the files you suggested. And there's a few questions i have before coding anything:

  • Where would we locate the class? classes inside of files with other information is a thing that happens in Blender's souce code, so i'm not sure if there is already a place where this class should be. Would it share a file with other classes?

  • When you mention "a pointer drawing to a GreasePencilDrawing" are we talking about an actual pointer from C/C++?

  • Given the fact that we're making a pointer towards an instance of GreasePencilDrawing, could this code be merged without that class existing? If not, then could drawing be a null? (which i'd imagine could be the case if this code can be merged without it)

I'll probably keep asking either here or in the chat when i run into trouble. But for now, those are my main questions.

Alright, it's been a while, and i took a break to celebrate the holidays with my family (which is why i've been so silent as of late, sorry for that). However, i already [took a look into the documentation of the existing Python API](https://docs.blender.org/api/current/index.html) and i've been reading the files you suggested. And there's a few questions i have before coding anything: - Where would we locate the class? classes inside of files with other information is a thing that happens in Blender's souce code, so i'm not sure if there is already a place where this class should be. Would it share a file with other classes? - When you mention "a pointer `drawing` to a `GreasePencilDrawing`" are we talking about an actual pointer from C/C++? - Given the fact that we're making a pointer towards an instance of `GreasePencilDrawing`, could this code be merged without that class existing? If not, then could `drawing` be a null? (which i'd imagine could be the case if this code can be merged without it) I'll probably keep asking either here or in the chat when i run into trouble. But for now, those are my main questions.
Author
Member

@mews6 Welcome back :) (no need to apologize!)

  • If you mean the Layer class then the location is blender/source/blender/blenkernel/BKE_grease_pencil.hh:333 (here).
  • Good question. I should have clarified a bit. I'm talking about an RNA pointer. See here for an existing example. The string that is used in RNA_def_property_struct_type is the name of the RNA struct defined with RNA_def_struct_sdna (here).
  • There is a C++ struct GreasePencilDrawing in blender/source/blender/makesdna/DNA_grease_pencil_types.h (here). But what I mean with "this can be a stub for now" is that you just define GreasePencilDrawing using RNA_def_struct_sdna (see how it's done for the RNA for layers) but not add any props etc. to it. It can just be an empty container for now.
@mews6 Welcome back :) (no need to apologize!) * If you mean the `Layer` class then the location is `blender/source/blender/blenkernel/BKE_grease_pencil.hh:333` ([here](https://projects.blender.org/blender/blender/src/commit/4dad262dbe892e169b0caa8f6d6c6ae41a46eb02/source/blender/blenkernel/BKE_grease_pencil.hh#L333)). * Good question. I should have clarified a bit. I'm talking about an RNA pointer. See [here](https://projects.blender.org/blender/blender/src/commit/4dad262dbe892e169b0caa8f6d6c6ae41a46eb02/source/blender/makesrna/intern/rna_grease_pencil.cc#L238) for an existing example. The string that is used in `RNA_def_property_struct_type` is the name of the RNA struct defined with `RNA_def_struct_sdna` ([here](https://projects.blender.org/blender/blender/src/commit/4dad262dbe892e169b0caa8f6d6c6ae41a46eb02/source/blender/makesrna/intern/rna_grease_pencil.cc#L182)). * There is a C++ struct `GreasePencilDrawing` in `blender/source/blender/makesdna/DNA_grease_pencil_types.h` ([here](https://projects.blender.org/blender/blender/src/commit/4dad262dbe892e169b0caa8f6d6c6ae41a46eb02/source/blender/makesdna/DNA_grease_pencil_types.h#L100)). But what I mean with "this can be a stub for now" is that you just define `GreasePencilDrawing` using `RNA_def_struct_sdna` (see how it's done for the RNA for layers) but not add any props etc. to it. It can just be an empty container for now.

I already have a few things coded, but i'm hesitant to commit them because they don't compile as of now. One of the things i've noticed is that the functions that manage iterations in rna_def_grease_pencil.cc generally recieve a parameter by reference called CollectionPropertyIterator *iter. I'm a bit confused over this structure, and i'm not sure where this variable is coming from. An example of this structure being asked for can be seen here. As my code currently stands, I'm trying to define this kind of function for the collection property that is being defined for GreasePencilFrame, but I'm not sure where could i find the values being asked for there, this might affect our code in this specific project given we need a custom collection iterator and this might interact with it. How does this specific piece of code work?

I already have a few things coded, but i'm hesitant to commit them because they don't compile as of now. One of the things i've noticed is that the functions that manage iterations in `rna_def_grease_pencil.cc` generally recieve a parameter by reference called `CollectionPropertyIterator *iter`. I'm a bit confused over this structure, and i'm not sure where this variable is coming from. An example of this structure being asked for can be seen [here](https://projects.blender.org/blender/blender/src/commit/4dad262dbe892e169b0caa8f6d6c6ae41a46eb02/source/blender/makesrna/intern/rna_grease_pencil.cc#L156). As my code currently stands, I'm trying to define this kind of function for the collection property that is being defined for `GreasePencilFrame`, but I'm not sure where could i find the values being asked for there, this might affect our code in this specific project given we need a custom collection iterator and this might interact with it. How does this specific piece of code work?
Author
Member

@mews6 Hello!
First, let me point out that it's OK to create a PR that doesn't compile yet :) Just make sure to prepend WIP: to the title. Makes it easier to see where the issue might be. It also makes it clear to others that there is work being done on this task!

Now to answer the question about the collection property. When using RNA_def_property_collection_funcs, we're defining the callbacks that can be found in the CollectionPropertyRNA struct. PropCollectionBeginFunc, PropCollectionNextFunc etc. These callbacks are called with the CollectionPropertyIterator as the first argument. It's basically the struct that manages the iteration. It keeps track of what the current item is, etc. etc.
Now in our case, I think we can mostly use the rna_iterator_array_* functions that exist already. Because we want to iterate over the sorted_keys array. So e.g. our begin callback would first call rna_iterator_array_begin with all the array information of sorted_keys. Then it would use rna_iterator_array_get to get the current item. This would be the FramesMapKey that we can pass into the frames() map to get the GreasePencilFrame. The other callbacks would works similarly. Calling the rna_iterator_array_* callback, get the key, return the frame.
Hope that helps!

EDIT: I realized that the begin callback doesn't need to return anything, so just calling rna_iterator_array_begin will be enough. But the get callback will need to get the frame. Anyway, you get the idea.

@mews6 Hello! First, let me point out that it's OK to create a PR that doesn't compile yet :) Just make sure to prepend `WIP: ` to the title. Makes it easier to see where the issue might be. It also makes it clear to others that there is work being done on this task! Now to answer the question about the collection property. When using `RNA_def_property_collection_funcs`, we're defining the callbacks that can be found in the `CollectionPropertyRNA` struct. `PropCollectionBeginFunc`, `PropCollectionNextFunc` etc. These callbacks are called with the `CollectionPropertyIterator` as the first argument. It's basically the struct that manages the iteration. It keeps track of what the current item is, etc. etc. Now in our case, I think we can mostly use the `rna_iterator_array_*` functions that exist already. Because we want to iterate over the `sorted_keys` array. So e.g. our `begin` callback would first call `rna_iterator_array_begin` with all the array information of `sorted_keys`. Then it would use `rna_iterator_array_get` to get the current item. This would be the `FramesMapKey` that we can pass into the `frames()` map to get the `GreasePencilFrame`. The other callbacks would works similarly. Calling the `rna_iterator_array_*` callback, get the key, return the frame. Hope that helps! EDIT: I realized that the `begin` callback doesn't need to return anything, so just calling `rna_iterator_array_begin` will be enough. But the `get` callback will need to get the frame. Anyway, you get the idea.
Sign in to join this conversation.
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#116045
No description provided.