GPencil: New support for Asset Manager #104413

Closed
Antonio Vazquez wants to merge 10 commits from antoniov/blender:temp-asset-lite into main

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

A new operator has been added to create an asset base on one of the next option:

Active Layer.
All Layers.
All Layers Separated
Active Frame (Active Layer).
Active Frame (All Layers).
Selected Frames.
Selected Strokes.
Selected Points.
The menu uses Create Assetinstead of Mark Asset because the asset is created as new datablock and not reuse existing data.

To import asset, set the grease pencil object where you want import in Edit mode.

Also new asset preview for Grease Pencil has been added.

A new operator has been added to create an asset base on one of the next option: Active Layer. All Layers. All Layers Separated Active Frame (Active Layer). Active Frame (All Layers). Selected Frames. Selected Strokes. Selected Points. The menu uses Create Assetinstead of Mark Asset because the asset is created as new datablock and not reuse existing data. To import asset, set the grease pencil object where you want import in Edit mode. Also new asset preview for Grease Pencil has been added.
Antonio Vazquez added 1 commit 2023-02-07 18:06:54 +01:00
Antonio Vazquez requested review from Matias Mendiola 2023-02-07 18:08:11 +01:00
Antonio Vazquez changed title from WIP: GPencil New support for Asset Manager to GPencil New support for Asset Manager 2023-02-07 18:10:51 +01:00
Antonio Vazquez added the
Module
Grease Pencil
label 2023-02-07 19:23:23 +01:00
Antonio Vazquez requested review from Julian Eisel 2023-02-08 16:18:50 +01:00
Antonio Vazquez requested review from Falk David 2023-02-08 16:18:58 +01:00
Antonio Vazquez changed title from GPencil New support for Asset Manager to GPencil: New support for Asset Manager 2023-02-08 16:21:26 +01:00
Antonio Vazquez self-assigned this 2023-02-09 13:03:06 +01:00
Antonio Vazquez added this to the Grease Pencil project 2023-02-09 15:33:41 +01:00
Julian Eisel requested changes 2023-02-14 18:28:02 +01:00
Julian Eisel left a comment
Member
  • Important: With this patch grease pencil assets are still an experimental feature. Changes in ED_asset_types.h and asset_type.cc are needed to change this.
  • [from previous review] Why does this only work in edit mode? I'd really expect this to work in object mode as well, creating a new object. This should be all that's needed: https://hastebin.com/share/abapepunah.diff
  • [from previous review] The name used for the assets currently is not great. It's just a bunch of xxx.001, xxx.002, ... named assets. It's not clear that this is because it's based on existing grease pencil data in the file, and so it's unexpected that the first asset already has the .001 suffix. I'd suggest to append something based on what the asset was created from (layer, keyframes, strokes, points). For example by appending the layer name, the term "stroke", "point", etc. When created from (key?)frames, would the frame number be useful to have in the name?
  • The if (is_gpencil) kind of logic in the preview rendering isn't great. This is fragile and a maintenance problem. Suggested some changes to avoid this.

Some of these points are left open from the previous review still.

- Important: With this patch grease pencil assets are still an experimental feature. Changes in `ED_asset_types.h` and `asset_type.cc` are needed to change this. - [from previous review] Why does this only work in edit mode? I'd really expect this to work in object mode as well, creating a new object. This should be all that's needed: https://hastebin.com/share/abapepunah.diff - [from previous review] The name used for the assets currently is not great. It's just a bunch of xxx.001, xxx.002, ... named assets. It's not clear that this is because it's based on existing grease pencil data in the file, and so it's unexpected that the first asset already has the .001 suffix. I'd suggest to append something based on what the asset was created from (layer, keyframes, strokes, points). For example by appending the layer name, the term "stroke", "point", etc. When created from (key?)frames, would the frame number be useful to have in the name? - The `if (is_gpencil)` kind of logic in the preview rendering isn't great. This is fragile and a maintenance problem. Suggested some changes to avoid this. Some of these points are left open from the previous review still.
@ -5223,6 +5224,26 @@ class VIEW3D_MT_edit_gpencil_point(Menu):
layout.menu("VIEW3D_MT_gpencil_vertex_group")
class VIEW3D_MT_edit_gpencil_asset(Menu):
Member

Not sure if I forgot to note this earlier or if you intentionally didn't change it. Rather than an Asset menu, this can live under Grease Pencil > Create Asset, similar to how there is Object > Asset in object mode.

Not sure if I forgot to note this earlier or if you intentionally didn't change it. Rather than an *Asset* menu, this can live under *Grease Pencil > Create Asset*, similar to how there is *Object > Asset* in object mode.
@ -5226,0 +5230,4 @@
def draw(self, _context):
layout = self.layout
layout.operator("gpencil.asset_create", text="Active Layer").source = 'LAYER'
Member

I think you can use layout.operator_enum() here.

I think you can use `layout.operator_enum()` here.
@ -2212,3 +2227,3 @@
read_ma = BKE_object_material_get(ob, i + 1);
/* Material names are like "MAMaterial.001" */
if (STREQ(name, &read_ma->id.name[2])) {
if ((read_ma) && (STREQ(name, &read_ma->id.name[2]))) {
Member

Is this necessary for this patch or a general fix?

Is this necessary for this patch or a general fix?
@ -0,0 +400,4 @@
void GPENCIL_OT_asset_create(wmOperatorType *ot)
{
static const EnumPropertyItem mode_types[] = {
Member

sources?

`sources`?
JulianEisel marked this conversation as resolved
@ -0,0 +405,4 @@
"LAYER",
0,
"Active Layer",
"Copy the strokes of the active layer into a new grease pencil asset."},
Member

None of the descriptions should end with a period.

None of the descriptions should end with a period.
JulianEisel marked this conversation as resolved
@ -0,0 +415,4 @@
"LAYERS_SPLIT",
0,
"All Layers Separated",
"Create an asset by layer."},
Member

This description isn't clear to me. Does this create one asset for each layer? In that case I suggest: "Create multiple grease pencil assets, one for each layer"

This description isn't clear to me. Does this create one asset for each layer? In that case I suggest: "Create multiple grease pencil assets, one for each layer"
JulianEisel marked this conversation as resolved
@ -0,0 +421,4 @@
"KEYFRAME",
0,
"Active Keyframe (Active Layer)",
"Create asset using active keyframe for active layer"},
Member

This and the following descriptions should read "Create an asset...".

In fact this and the following descriptions aren't clear to me either, they just repeat the operator name and the enum item name. I like what you did above, it actually explains what it's doing, like:
"Copy the strokes of [something something] into a new grease pencil asset".

This and the following descriptions should read "Create ***an*** asset...". In fact this and the following descriptions aren't clear to me either, they just repeat the operator name and the enum item name. I like what you did above, it actually explains what it's doing, like: *"Copy the strokes of [something something] into a new grease pencil asset"*.
@ -0,0 +741,4 @@
/* Asset GP data block. */
tgpa->gpd_asset = (bGPdata *)id;
tgpa->asset_strokes.clear();
Member

Shouldn't be needed, the vector is default constructed cleanly.

Shouldn't be needed, the vector is default constructed cleanly.
@ -0,0 +753,4 @@
/* check context */
op->customdata = tgpa = static_cast<tGPDasset *>(gpencil_session_init_asset_import(C, op));
op->customdata = tgpa;
Member

Why is this setting customdata twice?

Why is this setting customdata twice?
Member

In fact, there doesn't seem to be a need to use customdata at all? This just makes it hard to follow where/how the data is used. It's meant to make data available throughout multiple callbacks.

Just return a tGPDasset pointer and pass it to the functions that need it, rather than doing that indirectly via op->customdata. Bonus points for using std::unique_ptr, then you're guaranteed to be leak-free :)

In fact, there doesn't seem to be a need to use `customdata` at all? This just makes it hard to follow where/how the data is used. It's meant to make data available throughout multiple callbacks. Just return a `tGPDasset` pointer and pass it to the functions that need it, rather than doing that indirectly via `op->customdata`. Bonus points for using `std::unique_ptr`, then you're guaranteed to be leak-free :)
@ -0,0 +772,4 @@
/* Try to initialize context data needed. */
if (!gpencil_asset_import_init(C, op)) {
if (op->customdata) {
MEM_delete(op->customdata);
Member

MEM_delete() on a void pointer doesn't make sense, it shouldn't even compile. Committed 4126284e46 so this is a compiler error on all platforms in future.

`MEM_delete()` on a void pointer doesn't make sense, it shouldn't even compile. Committed 4126284e46 so this is a compiler error on all platforms in future.
@ -0,0 +784,4 @@
/* Load of the strokes in the target data block. */
if (!gpencil_asset_append_strokes(tgpa)) {
gpencil_asset_import_exit(C, op);
Member

This tags the depsgraph and sends notifiers... stuff that should only be done when data actually changes, not when cancelling an operation without having made changes. In this case a simple freeing of data should be sufficient.

And if you use std::unique_ptr you don't even need to free the data manually ;)

This tags the depsgraph and sends notifiers... stuff that should only be done when data actually changes, not when cancelling an operation without having made changes. In this case a simple freeing of data should be sufficient. And if you use `std::unique_ptr` you don't even need to free the data manually ;)
@ -0,0 +785,4 @@
/* Load of the strokes in the target data block. */
if (!gpencil_asset_append_strokes(tgpa)) {
gpencil_asset_import_exit(C, op);
return OPERATOR_CANCELLED;
Member

Is this really cancelling the operation? It seems gpencil_asset_append_strokes() only returns false if the grease pencil asset is empty. In this case I would just display an info report to give the user some feedback, and return OPERATOR_FINISHED.

Is this really cancelling the operation? It seems `gpencil_asset_append_strokes()` only returns false if the grease pencil asset is empty. In this case I would just display an info report to give the user some feedback, and return `OPERATOR_FINISHED`.
@ -0,0 +804,4 @@
/* identifiers */
ot->name = "Grease Pencil Import Asset";
ot->idname = "GPENCIL_OT_asset_import";
ot->description = "Import Asset into existing grease pencil object";
Member

Suggest: "Add strokes from a grease pencil asset to an existing grease pencil object".

Suggest: *"Add strokes from a grease pencil asset to an existing grease pencil object"*.
JulianEisel marked this conversation as resolved
@ -0,0 +815,4 @@
/* Properties. */
WM_operator_properties_id_lookup(ot, true);
PropertyRNA *prop = RNA_def_enum(ot->srna, "type", rna_enum_id_type_items, 0, "Type", "");
Member

Should probably be PROP_HIDDEN | PROP_SKIP_SAVE.

Should probably be `PROP_HIDDEN | PROP_SKIP_SAVE`.
Member

Actually, seems like this operator can only be used for ID_GD? Why make the type optional then?

Actually, seems like this operator can only be used for `ID_GD`? Why make the type optional then?
@ -855,4 +890,2 @@
preview_data.pr_main = preview_main;
/* Act on a copy. */
preview_data.object = (Object *)preview->id_copy;
preview_data.cfra = preview->scene->r.cfra;
Member

This change means the frame isn't set anymore for non grease pencil object.

This change means the frame isn't set anymore for non grease pencil object.
@ -806,6 +811,11 @@ static Scene *object_preview_scene_create(const struct ObjectPreviewData *previe
Depsgraph **r_depsgraph)
{
Scene *scene = BKE_scene_add(preview_data->pr_main, "Object preview scene");
const bool is_gpencil = (preview_data->object == nullptr ||
Member

Such a check is super fragile. If somebody adds another case where preview_data->object is null, this will just assume we're rendering for grease pencil.

Such a check is super fragile. If somebody adds another case where `preview_data->object` is null, this will just assume we're rendering for grease pencil.
@ -821,0 +833,4 @@
}
else {
/* Grease pencil draw engine needs an object to draw the datablock. */
ob_gpencil_temp = BKE_object_add_for_data(preview_data->pr_main,
Member

I would create this wrapper object in duplicate_ids(), just like we do it for instance empties there. Technically it's not thread safe, but I think it's fine not to copy the grease pencil data, and just create a wrapper object. We do the same for objects (the object data isn't copied I think) and collections (the collection itself isn't copied). This is also to avoid the memory and performance costs of the copies, this can be quite complex data.

I would create this wrapper object in `duplicate_ids()`, just like we do it for instance empties there. Technically it's not thread safe, but I think it's fine not to copy the grease pencil data, and just create a wrapper object. We do the same for objects (the object data isn't copied I think) and collections (the collection itself isn't copied). This is also to avoid the memory and performance costs of the copies, this can be quite complex data.
@ -821,0 +844,4 @@
/* Copy the materials to get full color previews. */
const short *materials_len_p = BKE_id_material_len_p(preview_data->datablock);
if (materials_len_p && *materials_len_p > 0) {
BKE_object_materials_test(preview_data->pr_main, ob_gpencil_temp, preview_data->datablock);
Member

I think this material copying can be done for all previews, not just grease pencil ones. Avoids the grease pencil specific handling.

I think this material copying can be done for all previews, not just grease pencil ones. Avoids the grease pencil specific handling.
JulianEisel marked this conversation as resolved
@ -862,0 +909,4 @@
f_min :
preview->scene->r.cfra;
preview_data.cfra = framenum;
}
Member

I think this bit of grease pencil specific code is fine to have here. But why this logic instead of a simple CLAMP()? Or better even, C++ std::clamp().

I think this bit of grease pencil specific code is fine to have here. But why this logic instead of a simple `CLAMP()`? Or better even, C++ `std::clamp()`.
@ -1034,6 +1086,7 @@ static void action_preview_render(IconPreview *preview, IconPreviewSize *preview
/** \} */
/* -------------------------------------------------------------------- */
Member

Unnecessary change.

Unnecessary change.
@ -627,3 +627,3 @@
{
ID_Type id_type = view3d_drop_id_in_main_region_poll_get_id_type(C, drag, event);
if (id_type && OB_DATA_SUPPORT_ID(id_type)) {
if (id_type && OB_DATA_SUPPORT_ID(id_type) && (id_type != ID_GD)) {
Member

Avoid these sneaky exceptions. If you want the grease pencil dropbox to have priority, adding it first should work.

Avoid these sneaky exceptions. If you want the grease pencil dropbox to have priority, adding it first should work.
Antonio Vazquez added 6 commits 2023-02-15 17:31:24 +01:00

Some notes about the menu:

  1. The ellipsis "..." In "Create Asset..." is not needed because there is no extra popup or window after. Just use "Create Asset"

  2. A better place in the Grease Pencil menu for "Create Asset" is just above "Duplicate" menu and separated by lines.

image

  1. The stroke and point context menus are using a different name for the menu (Create Grease Pencil Asset) which is redundant, we are already editing a Grease Pencil object. Use "Create Asset" like in the Grease Pencil menu. Also the menu placement should be above "Duplicate" menu.
Some notes about the menu: 1. The ellipsis "..." In "Create Asset..." is not needed because there is no extra popup or window after. Just use "Create Asset" 2. A better place in the Grease Pencil menu for *"Create Asset"* is just above "Duplicate" menu and separated by lines. ![image](/attachments/121ff715-e6c5-442a-858e-f1297436a253) 3. The stroke and point context menus are using a different name for the menu (*Create Grease Pencil Asset*) which is redundant, we are already editing a Grease Pencil object. Use "Create Asset" like in the Grease Pencil menu. Also the menu placement should be above "Duplicate" menu.
Matias Mendiola requested changes 2023-02-17 22:20:19 +01:00
@ -5161,2 +5161,4 @@
# Remove
layout.menu("VIEW3D_MT_edit_gpencil_delete")
# Assets
layout.menu("VIEW3D_MT_edit_gpencil_asset", text="Create Asset...")

The ellipsis "..." are not needed because there is no extra popup or window after. Rename to "Create Asset" and also move it above "Duplicate" menu adding separators.

The ellipsis *"..."* are not needed because there is no extra popup or window after. Rename to *"Create Asset"* and also move it above "Duplicate" menu adding separators.
antoniov marked this conversation as resolved
@ -7479,1 +7489,4 @@
# Assets
col.separator()
col.operator_menu_enum("gpencil.asset_create", "source", text="Create Grease Pencil Asset")

Rename to "Create Asset" like in the Grease Pencil menu. Also the menu placement should be above "Duplicate" menu.

Rename to "Create Asset" like in the Grease Pencil menu. Also the menu placement should be above "Duplicate" menu.
antoniov marked this conversation as resolved
Antonio Vazquez added 2 commits 2023-02-18 12:46:57 +01:00
Antonio Vazquez added 1 commit 2023-02-18 13:55:31 +01:00
83b440e8da Remove ID type check
Changing operator order works.
Author
Member

@filedescriptor I was thinking that GP 3.0 and the new Drawing datablock would solve automatically a lot of the Asset workflow, maybe we would need to add more features but the main idea would work. In any case, the internal details would be very different.

What do you think of this PR? maybe we would hold it and adapt later?

@filedescriptor I was thinking that GP 3.0 and the new Drawing datablock would solve automatically a lot of the Asset workflow, maybe we would need to add more features but the main idea would work. In any case, the internal details would be very different. What do you think of this PR? maybe we would hold it and adapt later?
Member

@antoniov Yes it's probably best to put this on hold. If we decide to land this now, we might get many issues trying to not break the assets for GP 3.0.

In GP 3.0 this will likely become much easier to implement, yes.

@antoniov Yes it's probably best to put this on hold. If we decide to land this now, we might get many issues trying to not break the assets for GP 3.0. In GP 3.0 this will likely become much easier to implement, yes.
Author
Member

This patch will be replaced by GP 3.0

This patch will be replaced by GP 3.0
Antonio Vazquez closed this pull request 2023-03-21 15:22:06 +01:00
Antonio Vazquez removed this from the Grease Pencil project 2023-03-21 16:04:12 +01:00

Pull request closed

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