Refactor: Retrieve node operator asset with property #110018
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
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#110018
Loading…
Reference in New Issue
No description provided.
Delete Branch "HooglyBoogly/blender:node-group-operator-path-prop"
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?
In order to more reliably pass the asset to the operator, use operator
properties making up the asset path instead of using a context pointer.
This is required to support the quick favorites menu, shortcuts, and
to draw operator inputs in the redo panel. In all of those situations
the original context isn't available. This also feels safer, since we
rely less on storing pointers to data with a less-defined lifetime.
Loading all asset libraries (possibly 1000s of assets) just to get a single asset doesn't sound like a good idea. For the node add menu and such we accept that, but only because we keep requiring quick access to them (this should be improved still though, so that unused assets are freed or garbage collected somehow). It also supports asynchronous loading, which isn't handled properly by the operator.
The operator could expect the library in question to be loaded already (
static AssetLibrary::foreach_loaded()
can be used then). Or we let the operator know about the asset library as well and let the asset system load the library in a smarter way. For example by temporarily loading the asset library, or making it possible to load a single asset representation from a library.I think all asset libraries will already be loaded already anyway (by
build_catalog_tree
), in order for the operator to be displayed in the menu in the first place. So I don't think this changes anything. Am I missing something?Where you call the operator the all asset library was already read, or at least is in the process of reading, yes. But this may not be the case when the operator is called from the quick favorites, for example. And there it will likely break still, since the operator invokes async loading of the library, but doesn't wait until the assets are actually loaded. If the operator does any loading (and I guess it has to if we want this to work from the quick favorites), it needs to wait until the asset is found or the loading completed.
Setting to changes requested because of the given reasons.
Okay, that makes sense, thanks. In menus, crucially this asset will already be loaded if it's displayed. But yeah, if you call the operator through quick favorites or shortcuts right when you enter the mode before the asset is loaded, the call would fail.
I guess you're suggesting the operator call wait until the asset is loaded? That sounds reasonable to me!
As for accomplishing that, I'm not quite sure. Theoretically, to execute the operator, the asset isn't even necessary since we already have the node group's full path. But there is currently no way to "ensure imported" without the asset, because that behavior is tied to the
AssetRepresentation
class. So there are two options I think:AssetRepresentation::get_local_id()
, but that hasn't been foolproof in my testing anyway, and we haveBLO_LIBLINK_APPEND_LOCAL_ID_REUSE
for that anyway.I think I prefer option 1. How about you?
Yes, although we could also load some temporary representation of the imported asset and replace that with the real one once done.
I think we need a design where you can request any asset to be imported through the asset system. The asset system design foresees non-ID assets and assets that are not loaded from disk, for example that need to be downloaded from a web server. So simple file path based link/append is too limiting.
So I guess (2) will be needed either way, since importing an asset may be an expensive operation that should be done asynchronously. And I think that means we still require an
AssetRepresentation
. How exactly we get that needs to be defined still, I see a few ways. I also thought earlier that we could assume the library is already loaded, but yeah, that won't work as mentioned.Everything you say makes sense, we shouldn't make it too hard to add support for operator node groups that are stored in the cloud sometime in the future.
I'd appreciate some more specific advice about how this should move forward though; I'm not sure who you imagine working on that more generalized "import asset based on non-asset-representation-path in a blocking way" feature, or where it fits into the existing asset code.
Hans Goudey referenced this pull request2023-07-13 19:50:36 +02:00
Hans Goudey referenced this pull request2023-07-13 19:52:05 +02:00
Discussed this in the node module meeting-- I added a different warning for when the asset wasn't found and asset libraries are still loading:
Asset loading is unfinished
. The operator just returns early in that case. In the end users a bit more flexibility this way anyway.The absolute asset path may be okay, but it can still break as an asset library gets moved around, or in future project libraries, etc. It also won't work once we support assets that are not on disk (online asset libraries).
I think for now the best thing to is to use
AssetWeakReference
, which should be pretty simple:asset.make_weak_reference()
eAssetLibraryType
, asset library identifier and relative asset identifier).AssetWeakReference
and gets the full path usingAssetLibraryService::resolve_asset_weak_reference_to_full_path()
(which probably has to be wrapped into astatic AssetLibrary::resolve_asset_weak_reference_to_full_path()
).ASSET_LIBRARY_LOCAL
, just using the relative asset identifier and comparing that againstasset->get_identifier().full_path()
should work.Longer term I hope we can simply replace this by a URI, but for now this is the closest and most future proof thing we have.
Thanks for the clear description, that was very helpful. I've implemented what you described now.
Alright, LGTM now!