Assets: add function to copy asset data to another ID #108547
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
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#108547
Loading…
Reference in New Issue
No description provided.
Delete Branch "dr.sybren/blender:pr/asset-data-copy-to-id"
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?
Add a function
some_id.asset_data.copy_to_id(other_id)
to copy the assetdata from one data-block to another. This is intended to be used in the
pose library, when updating a pose by simply creating a new asset and
having that replace the old one.
This is intentionally taking a copy, even though the above use case could
have sufficed with a higher-level 'move' function. By exposing this as a
copy, it can be used in a wider range of situations, from whatever Python
code wants to use it. This could include copying the asset data from the
active asset to all the other selected ones.
Any pre-existing asset data is freed before the copy is assigned. The
target ID MUST be marked as asset for this function to work. Clearing
the asset status by assigning
None
is not allowed. This will keep theAPI clear, and ensures that marking & clearing is done via their respective
functions.
In the attached blend file, just press the 'Play' button in the text editor to see the code in effect. And then see the intentional error, comment out the line, see another intentional error, etc. This is the script in that blend file:
I wonder if
some_id.asset_data.copy_to_id(other_id)
is "the right way" around for this (not strongly against it though). I'd expect that I call a function on the ID I want to modify, not the one I want to get the value from. Esp given that this is also how I mark/clear an asset.We could also make
ID.asset_data
editable, and do a deep copy in the setter callback. I guess that would be the expected behavior when doingone_id.asset_data = other_id.asset_data
?@ -340,1 +343,4 @@
void rna_AssetMetaData_copy_to_id(AssetMetaData *self, ReportList *reports, ID *destination)
{
if (destination == NULL) {
For an RNA callback this has a bit too much knowledge/logic for my taste, I'd prefer having this in some
ED_asset_xxx()
function. Similar to how we haveED_asset_mark_id()
/ED_asset_clear_id()
.The advantage of this approach is that
source.asset_data.copy_to_id(dest)
works regardless of whetherdest
is an asset or not, and it can only work whensource
already has asset data. This seemed like good preconditions to me. The alternativedest.asset_data.copy_from(source.asset_data)
implies thatdest
would have to be marked as asset first, which might also involve rendering the preview image. That implication falls away when using direct assignment,dest.asset_data = source.asset_data
. I have no strong feelings about this either, except that it would be a bit more work ;-)Fair, I'll move the code to an
ED_xxx
function.Is it though? I think it's pretty much the same thing, just in a RNA setter for
ID.asset_data
.Thinking some more about this, what I'm unsure about is if this way of "marking" or "clearing" an asset is future proof. What if this process involves more than just setting/getting the metadata? E.g. I could imagine we'd want to call some callback or app handler when marking/clearing an asset.
So we could say setting it to
None
is not valid, or setting it on an ID that is not marked as asset.Agreed, I've updated the code, PR description, and attached blend file for this.
Nice, I think this is the way to go.