GPencil: New support for Asset Manager #104413
No reviewers
Labels
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
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#104413
Loading…
Reference in New Issue
No description provided.
Delete Branch "antoniov/blender:temp-asset-lite"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
WIP: GPencil New support for Asset Managerto GPencil New support for Asset ManagerGPencil New support for Asset Managerto GPencil: New support for Asset ManagerED_asset_types.h
andasset_type.cc
are needed to change this.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):
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'
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]))) {
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[] = {
sources
?@ -0,0 +405,4 @@
"LAYER",
0,
"Active Layer",
"Copy the strokes of the active layer into a new grease pencil asset."},
None of the descriptions should end with a period.
@ -0,0 +415,4 @@
"LAYERS_SPLIT",
0,
"All Layers Separated",
"Create an asset by 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"
@ -0,0 +421,4 @@
"KEYFRAME",
0,
"Active Keyframe (Active Layer)",
"Create asset using active keyframe for active layer"},
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();
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;
Why is this setting customdata twice?
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 viaop->customdata
. Bonus points for usingstd::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);
MEM_delete()
on a void pointer doesn't make sense, it shouldn't even compile. Committed4126284e46
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);
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;
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 returnOPERATOR_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";
Suggest: "Add strokes from a grease pencil asset to an existing grease pencil object".
@ -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", "");
Should probably be
PROP_HIDDEN | PROP_SKIP_SAVE
.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;
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 ||
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,
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);
I think this material copying can be done for all previews, not just grease pencil ones. Avoids the grease pencil specific handling.
@ -862,0 +909,4 @@
f_min :
preview->scene->r.cfra;
preview_data.cfra = framenum;
}
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
/** \} */
/* -------------------------------------------------------------------- */
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)) {
Avoid these sneaky exceptions. If you want the grease pencil dropbox to have priority, adding it first should work.
Some notes about the menu:
The ellipsis "..." In "Create Asset..." is not needed because there is no extra popup or window after. Just use "Create Asset"
A better place in the Grease Pencil menu for "Create Asset" is just above "Duplicate" menu and separated by lines.
@ -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.
@ -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.
@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?
@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.
This patch will be replaced by GP 3.0
Pull request closed