GPv3: Python API for frame, drawing and drawing attributes #124787

Merged
Falk David merged 22 commits from filedescriptor/blender:gpv3-drawing-python-api into main 2024-07-26 16:30:21 +02:00
Member

This is a PR that is built on top of #122094 (thanks to @SietseB for the initial work).

Adds the following properties and functions:

  • layer.frames,
  • layer.frames.new(frame_number)
  • layer.frames.remove(frame_number)
  • layer.frames.copy(from, to)
  • frame = layer.get_frame_at(frame_number)
  • frame.drawing
  • frame.frame_number
  • frame.select: the selection state of the keyframe in the dope sheet
  • frame.keyframe_type
  • drawing = frame.drawing
  • drawing.type (DRAWING/REFERENCE)
  • drawing.user_count: The number of keyframes that use this drawing
  • drawing.attributes: attribute read/write access to the drawing data

To be able to access attributes on drawings, a new AttributeOwnerType::GreasePencilDrawing is added.
The API in BKE_attributes.h is updated to handle this type.

In rna_attributes.cc, there is a new rna_def_attribute_group_grease_pencil_drawing that defines the attribute group. For this to work, it also defines its own rna callback functions.

This is a PR that is built on top of #122094 (thanks to @SietseB for the initial work). Adds the following properties and functions: * `layer.frames`, * `layer.frames.new(frame_number)` * `layer.frames.remove(frame_number)` * `layer.frames.copy(from, to)` * `frame = layer.get_frame_at(frame_number)` * `frame.drawing` * `frame.frame_number` * `frame.select`: the selection state of the keyframe in the dope sheet * `frame.keyframe_type` * `drawing = frame.drawing` * `drawing.type` (`DRAWING`/`REFERENCE`) * `drawing.user_count`: The number of keyframes that use this drawing * `drawing.attributes`: attribute read/write access to the drawing data To be able to access attributes on drawings, a new `AttributeOwnerType::GreasePencilDrawing` is added. The API in `BKE_attributes.h` is updated to handle this type. In `rna_attributes.cc`, there is a new `rna_def_attribute_group_grease_pencil_drawing` that defines the attribute group. For this to work, it also defines its own rna callback functions.
Falk David added 3 commits 2024-07-16 14:59:50 +02:00
Attribute API for grease pencil drawings
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
89893905e8
Falk David added this to the Grease Pencil project 2024-07-16 14:59:56 +02:00
Falk David requested review from Bastien Montagne 2024-07-16 15:04:22 +02:00
Falk David requested review from Jacques Lucke 2024-07-16 15:04:30 +02:00
Falk David requested review from Hans Goudey 2024-07-16 15:04:36 +02:00
Author
Member

@blender-bot build

@blender-bot build
Lukas Tönne approved these changes 2024-07-16 16:14:34 +02:00
Lukas Tönne left a comment
Member

Just some cleanup comments.

Just some cleanup comments.
@ -1018,6 +1018,9 @@ inline bool GreasePencil::has_active_group() const
return (this->active_node != nullptr) && (this->active_node->wrap().is_group());
}
bool BKE_grease_pencil_drawing_attribute_required(const GreasePencilDrawing * /*drawing*/,
Member

remove comment

remove comment
filedescriptor marked this conversation as resolved
@ -712,3 +744,1 @@
static void rna_AttributeGroup_update_active_color(Main * /*bmain*/,
Scene * /*scene*/,
PointerRNA *ptr)
static void rna_AttributeGroupID_update_active_color(Main * /*bmain*/,
Member

Should probably be moved in the ID section above

Should probably be moved in the `ID` section above
filedescriptor marked this conversation as resolved
@ -1465,0 +1624,4 @@
prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "Attribute");
RNA_def_property_ui_text(prop, "Active Attribute", "Active attribute");
RNA_def_property_pointer_funcs(prop,
Member

Does this need a poll function? I think right now you could call this with an arbitrary drawing from different geometry and it would still try to set the active layer by name. Not a huge issue i guess, but maybe should be handled.

Does this need a poll function? I think right now you could call this with an arbitrary drawing from different geometry and it would still try to set the active layer by name. Not a huge issue i guess, but maybe should be handled.
Author
Member

Hm not sure I follow. What would the poll function do?

Hm not sure I follow. What would the poll function do?
Member

It would check if the attribute layer given as a parameter is actually owned by the drawing, and cancel if not (rather than try and find a layer with the same name).

It would check if the attribute layer given as a parameter is actually owned by the drawing, and cancel if not (rather than try and find a layer with the same name).
filedescriptor marked this conversation as resolved
Falk David added 2 commits 2024-07-18 11:09:28 +02:00
Falk David added 1 commit 2024-07-18 11:12:29 +02:00
Falk David added 1 commit 2024-07-18 11:23:07 +02:00
Jacques Lucke requested changes 2024-07-19 11:31:20 +02:00
Jacques Lucke left a comment
Member

Didn't finish the review yet, will have a closer look soon!

Didn't finish the review yet, will have a closer look soon!
@ -819,0 +907,4 @@
static bool rna_AttributeGroupGreasePencilDrawing_active_poll(PointerRNA *ptr,
const PointerRNA value)
{
AttributeOwner owner = owner_from_attribute_pointer_rna(&value);
Member
In file included from /home/jacques/blender/build_debug/source/blender/makesrna/intern/rna_attribute_gen.cc:36:
/home/jacques/blender/blender/source/blender/makesrna/intern/rna_attribute.cc: In function ‘bool rna_AttributeGroupGreasePencilDrawing_active_poll(PointerRNA*, PointerRNA)’:
/home/jacques/blender/blender/source/blender/makesrna/intern/rna_attribute.cc:910:59: error: invalid conversion from ‘const PointerRNA*’ to ‘PointerRNA*’ [-fpermissive]
  910 |   AttributeOwner owner = owner_from_attribute_pointer_rna(&value);
      |                                                           ^~~~~~
      |                                                           |
      |                                                           const PointerRNA*
/home/jacques/blender/blender/source/blender/makesrna/intern/rna_attribute.cc:187:68: note:   initializing argument 1 of ‘AttributeOwner owner_from_attribute_pointer_rna(PointerRNA*)’
  187 | static AttributeOwner owner_from_attribute_pointer_rna(PointerRNA *ptr)
      |                                                        ~~~~~~~~~~~~^~~
``` In file included from /home/jacques/blender/build_debug/source/blender/makesrna/intern/rna_attribute_gen.cc:36: /home/jacques/blender/blender/source/blender/makesrna/intern/rna_attribute.cc: In function ‘bool rna_AttributeGroupGreasePencilDrawing_active_poll(PointerRNA*, PointerRNA)’: /home/jacques/blender/blender/source/blender/makesrna/intern/rna_attribute.cc:910:59: error: invalid conversion from ‘const PointerRNA*’ to ‘PointerRNA*’ [-fpermissive] 910 | AttributeOwner owner = owner_from_attribute_pointer_rna(&value); | ^~~~~~ | | | const PointerRNA* /home/jacques/blender/blender/source/blender/makesrna/intern/rna_attribute.cc:187:68: note: initializing argument 1 of ‘AttributeOwner owner_from_attribute_pointer_rna(PointerRNA*)’ 187 | static AttributeOwner owner_from_attribute_pointer_rna(PointerRNA *ptr) | ~~~~~~~~~~~~^~~ ```
Author
Member

Sorry about that, fixed now.

Sorry about that, fixed now.
filedescriptor marked this conversation as resolved
Falk David added 2 commits 2024-07-19 11:53:45 +02:00
Falk David requested review from Jacques Lucke 2024-07-19 11:53:53 +02:00
Falk David added 1 commit 2024-07-22 15:09:37 +02:00
Jacques Lucke approved these changes 2024-07-22 16:24:58 +02:00
Jacques Lucke left a comment
Member

LGTM and also works in my basic tests.

The main thing that confused me at first was that instance_drawing didn't lead to a drawing of type REFERENCE, but that then made sense given the data model. I don't really have any specific recommendation that could avoid this initial confusion unfortunately.

@blender-bot build

LGTM and also works in my basic tests. The main thing that confused me at first was that `instance_drawing` didn't lead to a drawing of type `REFERENCE`, but that then made sense given the data model. I don't really have any specific recommendation that could avoid this initial confusion unfortunately. @blender-bot build
Falk David added 2 commits 2024-07-22 17:37:00 +02:00
Add API to get the user count of a drawing
All checks were successful
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
d5d345d70b
Author
Member

@blender-bot build

@blender-bot build
Falk David added 1 commit 2024-07-22 17:49:42 +02:00
Falk David force-pushed gpv3-drawing-python-api from 4c03e2b718 to cb8af52555 2024-07-22 17:50:44 +02:00 Compare
Falk David added 1 commit 2024-07-23 13:59:17 +02:00
Bastien Montagne requested changes 2024-07-23 17:36:22 +02:00
Dismissed
Bastien Montagne left a comment
Owner

From code side of thing it looks essentially good to me, besides a few comments below.

Would be good to have some python-based tests of this API as part of the PR though?

From code side of thing it looks essentially good to me, besides a few comments below. Would be good to have some python-based tests of this API as part of the PR though?
@ -1465,0 +1638,4 @@
nullptr,
"rna_AttributeGroupGreasePencilDrawing_active_poll");
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_UNLINK);
RNA_def_property_update(prop, 0, "rna_AttributeGroupID_update_active");

I find it weird to use a function named rna_AttributeGroupID_update_active for non-ID-owned attribute data?

Would suggest to either rename that one to a generic rna_AttributeGroup_update_activename, or to add a rna_AttributeGroupGreasePencilDrawing_update_active one (which could then call rna_AttributeGroupID_update_active if it's fine to do so)?

I find it weird to use a function named `rna_AttributeGroupID_update_active` for non-ID-owned attribute data? Would suggest to either rename that one to a generic `rna_AttributeGroup_update_active`name, or to add a `rna_AttributeGroupGreasePencilDrawing_update_active` one (which could then call `rna_AttributeGroupID_update_active` if it's fine to do so)?
filedescriptor marked this conversation as resolved
@ -77,0 +243,4 @@
return frame_number;
}
static void rna_Frame_frame_number_index_range(

Not sure I understand why you need to define and use this callback?

Not sure I understand why you need to define and use this callback?
filedescriptor marked this conversation as resolved
@ -545,0 +833,4 @@
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)

Usually API definition should go into its own RNA file (rna_grease_pencil_api.cc)?

Usually API definition should go into its own RNA file (`rna_grease_pencil_api.cc`)?
Author
Member

Does this mean I should add a file+function for frames, layer, layers, layer_mask, layer_group ?

Does this mean I should add a file+function for `frames`, `layer`, `layers`, `layer_mask`, `layer_group` ?

yes, one new file, and then move all the rna_def_xxx_api() functions there (they are also usually name RNA_api_xxx, see e.g. rna_mesh_api.cc and its RNA_api_mesh() definition function.

These API definition functions are also declared in the rna_internal.hh file.

yes, one new file, and then move all the `rna_def_xxx_api()` functions there (they are also usually name `RNA_api_xxx`, see e.g. `rna_mesh_api.cc` and its `RNA_api_mesh()` definition function. These API definition functions are also declared in the `rna_internal.hh` file.
filedescriptor marked this conversation as resolved
Falk David added 3 commits 2024-07-25 16:15:42 +02:00
Falk David requested review from Bastien Montagne 2024-07-25 16:17:10 +02:00
Bastien Montagne requested changes 2024-07-25 18:00:59 +02:00
Dismissed
Bastien Montagne left a comment
Owner

...

...
Falk David added 3 commits 2024-07-26 11:39:03 +02:00
Falk David requested review from Bastien Montagne 2024-07-26 11:39:29 +02:00
Bastien Montagne approved these changes 2024-07-26 12:58:24 +02:00
Bastien Montagne left a comment
Owner

LGTM

LGTM
Falk David added 1 commit 2024-07-26 15:59:10 +02:00
Merge branch 'main' into gpv3-drawing-python-api
Some checks failed
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
35f0102c36
Author
Member

@blender-bot build

@blender-bot build
Falk David added 1 commit 2024-07-26 16:04:23 +02:00
Falk David merged commit 6f050fecfb into main 2024-07-26 16:30:21 +02:00
Falk David deleted branch gpv3-drawing-python-api 2024-07-26 16:30:28 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
4 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#124787
No description provided.