Implement Asset Traits #105808

Open
opened 2023-03-15 19:41:19 +01:00 by Julian Eisel · 5 comments
Member

Asset traits would be keywords that are stored in the asset metadata, and provide information about the type of an asset. For example {"ID", "Node Tree", "Geometry Nodes"}, or {"ID", "Brush", "Sculpt Mode"}. Unlike tags, they are managed by Blender or add-ons, not by the user.

Comprehensive design task: #105807


Implementation

  • Store list of traits in AssetMetaData
  • RNA access
  • File read/write
  • Index read/write
  • Code to add/remove traits
  • IDTypeInfo.refine_asset_traits() callback?
  • Versioning for old assets?
  • Make ID type a runtime only trait? (Can be cheaply read from the ID type)
  • Optimized lookups in a hash inside AssetRepresentation?

Plenty of code can be copied from tags.

Asset traits would be keywords that are stored in the asset metadata, and provide information about the type of an asset. For example `{"ID", "Node Tree", "Geometry Nodes"}`, or `{"ID", "Brush", "Sculpt Mode"}`. Unlike tags, they are managed by Blender or add-ons, not by the user. Comprehensive design task: #105807 ---- ## Implementation - [ ] Store list of traits in `AssetMetaData` - [ ] RNA access - [ ] File read/write - [ ] Index read/write - [ ] Code to add/remove traits - [ ] `IDTypeInfo.refine_asset_traits()` callback? - [ ] Versioning for old assets? - [ ] Make ID type a runtime only trait? (Can be cheaply read from the ID type) - [ ] Optimized lookups in a hash inside `AssetRepresentation`? Plenty of code can be copied from tags.
Julian Eisel added the
Type
To Do
label 2023-03-15 19:41:19 +01:00
Author
Member

@Harley wanted to look into implementing the basics for this.

@Harley wanted to look into implementing the basics for this.
Harley Acheson was assigned by Julian Eisel 2023-03-15 19:44:04 +01:00
Julian Eisel added this to the Brush Assets & Asset Shelf project 2023-03-15 19:44:11 +01:00
Julian Eisel added the
Module
Pipeline, Assets & IO
Interest
Asset Browser
labels 2023-03-15 19:44:28 +01:00
Member

PR #105841 should be doing the first five items, string list of traits in AssetMetaData,
RNA access, File read/write, Index read/write, Code to add/remove traits.

It currently displays in the interface somewhat identically to "tags" so have "add" and "remove" that we (I assume) don't need or want. But I needed that for testing so assume it can be removed once confirmed correct. Currently unclear on the rest of the TODO items, but will take a look around to see if any make sense to me.

PR #105841 should be doing the first five items, string list of traits in AssetMetaData, RNA access, File read/write, Index read/write, Code to add/remove traits. It currently displays in the interface somewhat identically to "tags" so have "add" and "remove" that we (I assume) don't need or want. But I needed that for testing so assume it can be removed once confirmed correct. Currently unclear on the rest of the TODO items, but will take a look around to see if any make sense to me.
Author
Member

Clarification for the remaining points:

  • IDTypeInfo.refine_asset_traits() callback?

I'd imagine an API to enable something like this:

void brush_asset_refine_asset_traits(ID *id, AssetTraitList *traits)
{
  /* Trait "ID" and "Brush" are already added. */
  
  /* Note that a brush may support multiple modes. */

  if (/* supports sculpt mode */ ...) {
    AS_asset_trait_ensure(traits, N_("Sculpt"));
  }
  if (/* supports texture paint mode */...) {
    AS_asset_trait_ensure(traits, N_("Texture Paint"));
  }
}

Actually, this callback should be defined in AssetTypeInfo, not IDTypeInfo.

It's not entirely clear when this would be called, I think for now doing it when marking as asset is enough. Doing it on file save for every asset would be the most reliable. But would rather avoid having to do that for potentially 100s of assets on every save.

  • Versioning for old assets?

There's the question if we should add asset traits for existing assets in versioning. E.g. "Object" and "ID" for object assets. Open question still. It's easy to add this later also.

  • Make ID type a runtime only trait? (Can be cheaply read from the ID type)

Currently the "ID" and id type traits are redundant. All asset must be IDs and the ID type is read from the .blend file anyway. So instead of storing this in the asset metadata itself, we can just create these traits when loading an asset library.

  • Optimized lookups in a hash inside AssetRepresentation?

In future I expect we'll often want to do lookups inside the traits, since they give crucial type information. A list lookup is rather slow and scales bad, so we should use a hash map. This may not be entirely trivial to add though, let's first get the basics working and merged.

Clarification for the remaining points: > - [ ] `IDTypeInfo.refine_asset_traits()` callback? I'd imagine an API to enable something like this: ```C void brush_asset_refine_asset_traits(ID *id, AssetTraitList *traits) { /* Trait "ID" and "Brush" are already added. */ /* Note that a brush may support multiple modes. */ if (/* supports sculpt mode */ ...) { AS_asset_trait_ensure(traits, N_("Sculpt")); } if (/* supports texture paint mode */...) { AS_asset_trait_ensure(traits, N_("Texture Paint")); } } ``` Actually, this callback should be defined in `AssetTypeInfo`, not `IDTypeInfo`. It's not entirely clear when this would be called, I think for now doing it when marking as asset is enough. Doing it on file save for every asset would be the most reliable. But would rather avoid having to do that for potentially 100s of assets on every save. > - [ ] Versioning for old assets? There's the question if we should add asset traits for existing assets in versioning. E.g. "Object" and "ID" for object assets. Open question still. It's easy to add this later also. > - [ ] Make ID type a runtime only trait? (Can be cheaply read from the ID type) Currently the "ID" and id type traits are redundant. All asset must be IDs and the ID type is read from the .blend file anyway. So instead of storing this in the asset metadata itself, we can just create these traits when loading an asset library. > - [ ] Optimized lookups in a hash inside `AssetRepresentation`? In future I expect we'll often want to do lookups inside the traits, since they give crucial type information. A list lookup is rather slow and scales bad, so we should use a hash map. This may not be entirely trivial to add though, let's first get the basics working and merged.
Member

Hmmm... that forced me to learn about object ID and IDTypeInfo. Yikes.

I might be misunderstanding you about the "ID" trait, but right now my PR will add things like the following:

Add a "Cube" and get the following traits

  • ID
  • Object
  • Cube
  • Mesh

Add a "Collection"

  • ID
  • Collection

Add a "Charge Forcefield"

  • ID
  • Object
  • Charge
  • Empty
Hmmm... that forced me to learn about object ID and IDTypeInfo. Yikes. I might be misunderstanding you about the "ID" trait, but right now my PR will add things like the following: Add a "Cube" and get the following traits * ID * Object * Cube * Mesh Add a "Collection" * ID * Collection Add a "Charge Forcefield" * ID * Object * Charge * Empty
Author
Member

Sorry, I didn't mean to imply that you should already add such callbacks. I'd say we add them on a as needed basis.

I guess the nodes team would want to add some traits to identify the type of node tree (e.g. to display the geometry nodes icon in the asset browser), and to identify node group assets that can be used as modifiers.
For brush assets we will need this to determine which modes a brush can be used in, and to filter by that.

Sorry, I didn't mean to imply that you should already add such callbacks. I'd say we add them on a as needed basis. I guess the nodes team would want to add some traits to identify the type of node tree (e.g. to display the geometry nodes icon in the asset browser), and to identify node group assets that can be used as modifiers. For brush assets we will need this to determine which modes a brush can be used in, and to filter by that.
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 Assignees
2 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#105808
No description provided.