Asset Browser: add more info about selected asset to context #86270

Closed
opened 2021-03-04 15:01:35 +01:00 by Sybren A. Stüvel · 6 comments

The pose library needs to temporarily load a pose Action. This can be done with the context manager implemented in D10612: PyAPI: add bpy.types.BlendFile.temp_data for temporary library loading:

with bpy.types.BlendData.temp_data() as temp_data:
    with temp_data.libraries.load(asset_library_file) as (data_from, data_to):
        data_to.actions = [pose_asset_name]

    pose.apply_pose_from_action(data_to.actions[0])

(for the pose.apply_pose_from_action() function, see D10578)

This requires three things that currently aren't available in the Asset Browser's context, though:

  • The library file containing the selected asset,
  • the name of the selected asset, and
  • the ID datablock type of the selected asset, so that it can be checked in a poll() function.

The goal of this task is to add this info to the context.


#86270-asset-info-in-context.zip

This ZIP contains three blend files:

  • asset_library/pose_assets.blend: contains a bunch of pose assets
  • example_file.blend: the file to open. It auto-registers //asset_library as asset library, and shows the asset browser in the top right corner. It has a panel that prints the contents of the context to the terminal whenever it's redrawn.
  • character.blend: contains the rigged character "Bob the Bar" used in the other two files.
The pose library needs to temporarily load a pose Action. This can be done with the context manager implemented in [D10612: PyAPI: add bpy.types.BlendFile.temp_data for temporary library loading](https://archive.blender.org/developer/D10612): ``` with bpy.types.BlendData.temp_data() as temp_data: with temp_data.libraries.load(asset_library_file) as (data_from, data_to): data_to.actions = [pose_asset_name] pose.apply_pose_from_action(data_to.actions[0]) ``` (for the `pose.apply_pose_from_action()` function, see [D10578](https://archive.blender.org/developer/D10578)) This requires three things that currently aren't available in the Asset Browser's context, though: - The library file containing the selected asset, - the name of the selected asset, and - the ID datablock type of the selected asset, so that it can be checked in a `poll()` function. The goal of this task is to add this info to the context. ------------------ [#86270-asset-info-in-context.zip](https://archive.blender.org/developer/F9866104/T86270-asset-info-in-context.zip) This ZIP contains three blend files: - `asset_library/pose_assets.blend`: contains a bunch of pose assets - `example_file.blend`: **the file to open**. It auto-registers `//asset_library` as asset library, and shows the asset browser in the top right corner. It has a panel that prints the contents of the context to the terminal whenever it's redrawn. - `character.blend`: contains the rigged character "Bob the Bar" used in the other two files.
Campbell Barton was assigned by Sybren A. Stüvel 2021-03-04 15:01:35 +01:00
Author
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Author
Member

Added subscriber: @dr.sybren

Added subscriber: @dr.sybren
Member

Added subscriber: @JulianEisel

Added subscriber: @JulianEisel
Member

I've done a number of changes in the asset-browser-poselib branch, and I think this is addressed now.
Note that this context doesn't only matter for the Asset Browser, but also for the asset view UI template.

Newly added:

  • CTX_wm_asset_library(): Gives the asset library (AssetLibraryReference) of the workspace, for the regular UI to use; the Asset Browser overrides it with its own.
  • CTX_wm_asset_handle(): The active asset handle, the asset view template sets this for operators and menus spawned from it to use; the Asset Browser sets it too.
    I'm not happy about the current AssetHandle design, it's just a wrapper around a FileDirEntry, which is how we store the asset information currently. Instead it could be an opaque handle with an API to query info (path relative to the library, name, preview, etc.). I have ideas for this but it needs a number of changes and is part of further work.

The ID type of an asset can be gotten with FileDirEntry.blentype.

I've done a number of changes in the `asset-browser-poselib` branch, and I think this is addressed now. Note that this context doesn't only matter for the Asset Browser, but also for the asset view UI template. Newly added: * `CTX_wm_asset_library()`: Gives the asset library (`AssetLibraryReference`) of the workspace, for the regular UI to use; the Asset Browser overrides it with its own. * `CTX_wm_asset_handle()`: The active asset handle, the asset view template sets this for operators and menus spawned from it to use; the Asset Browser sets it too. I'm not happy about the current `AssetHandle` design, it's just a wrapper around a `FileDirEntry`, which is how we store the asset information currently. Instead it could be an opaque handle with an API to query info (path relative to the library, name, preview, etc.). I have [ideas ](https://hackmd.io/@blender-asset-browser/B19v6heSO) for this but it needs a number of changes and is part of further work. The ID type of an asset can be gotten with `FileDirEntry.blentype`.
Author
Member

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Author
Member

Marking as Resolved as the work has landed in master.

Marking as Resolved as the work has landed in master.
Brecht Van Lommel added the
Interest
Asset Browser
label 2023-02-11 01:39:28 +01:00
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
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#86270
No description provided.