Pose Library: temporarily load Action asset #86183

Closed
opened 2021-03-02 10:22:27 +01:00 by Sybren A. Stüvel · 10 comments

The Pose Library system is going to perform the following steps:

  1. Given the active asset in the Asset Browser, load the associated datablock as non-main temp datablock.
  2. Apply the pose in that datablock by evaluating it (#86159 and #86160).
  3. Free the datablock.

This task is about implementing steps 1. and 3.

The idea behind the current pose library project is that its behaviour is seen from Blender's perspective as "custom use" of an asset; this means it's simply implemented in Python in a way that add-ons could also use. For now it's probably the simplest to have two functions exposed in RNA for respectively steps 1 and 3, so that Python code can use it.

By temporarily loading the Action datablock, pollution of the main database is prevented. At some point it'll be nice to have some form of caching, which is what #86184 is about.

The Pose Library system is going to perform the following steps: 1. Given the active asset in the Asset Browser, load the associated datablock as non-main temp datablock. 2. Apply the pose in that datablock by evaluating it (#86159 and #86160). 3. Free the datablock. This task is about implementing steps 1. and 3. The idea behind the current pose library project is that its behaviour is seen from Blender's perspective as "custom use" of an asset; this means it's simply implemented in Python in a way that add-ons could also use. For now it's probably the simplest to have two functions exposed in RNA for respectively steps 1 and 3, so that Python code can use it. By temporarily loading the Action datablock, pollution of the main database is prevented. At some point it'll be nice to have some form of caching, which is what #86184 is about.
Campbell Barton was assigned by Sybren A. Stüvel 2021-03-02 10:22:27 +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

Added subscriber: @mont29

Added subscriber: @mont29

#Core module should have been tagged here, this falls directly under its umbrella.

While I am not especially thrilled to add even more complexity to ID management, I can see how this might be useful... But it should be fully decoupled/isolated from data in Main data-base. Would suggest the following requirements:

  • Loaded IDs must be put in their own temp Main container.
  • Loaded IDs must be properly poisoned (with a new tag?) to prevent them from ever being linked in any way by IDs from actual Main data-base.
    • This implies adding checks in several places for that poison tag (RNA ID pointer assignment, ID template?, ...).
    • Not sure how this plays with your point 2. above? Do you intend to use Depsgraph for this evaluation, or some fully independent code?
  • Loaded IDs must not use session_uuid (we do not want them to increase this global counter).
  • As suggested by @ideasman42, this should be exposed as a context manager in Python API (similar to the one we already have to parse and link IDs from .blend libraries).
*#Core module should have been tagged here, this falls directly under its umbrella.* While I am not especially thrilled to add even more complexity to ID management, I can see how this might be useful... But it should be fully decoupled/isolated from data in Main data-base. Would suggest the following requirements: - Loaded IDs must be put in their own temp `Main` container. - Loaded IDs must be properly poisoned (with a new tag?) to prevent them from ever being linked in any way by IDs from actual Main data-base. - This implies adding checks in several places for that poison tag (RNA ID pointer assignment, ID template?, ...). - *Not sure how this plays with your point 2. above? Do you intend to use Depsgraph for this evaluation, or some fully independent code?* - Loaded IDs must not use `session_uuid` *(we do not want them to increase this global counter)*. - As suggested by @ideasman42, this should be exposed as a context manager in Python API (similar to the one we already have to parse and link IDs from .blend libraries).
Author
Member

Core module should have been tagged here, this falls directly under its umbrella.

You're right, thanks for doing so.

Not sure how this plays with your point 2. above? Do you intend to use Depsgraph for this evaluation, or some fully independent code?

I intend to use the animation system FCurve evaluation functions for this, and not the depsgraph:

void BKE_pose_apply_action(struct Object *ob,
                           struct bAction *action,
                           struct AnimationEvalContext *anim_eval_context)
{
  bPose *pose = ob->pose;

  GSet *selected_bone_names = NULL;
  const bool limit_to_selected_bones = pose_apply_find_selected_bones(pose, &selected_bone_names);

  if (limit_to_selected_bones) {
    pose_apply_disable_fcurves_for_unselected_bones(action, selected_bone_names);
  }

  /* Apply the Action. */
  PointerRNA pose_owner_ptr;
  RNA_id_pointer_create(&ob->id, &pose_owner_ptr);
  animsys_evaluate_action(&pose_owner_ptr, action, &anim_eval_context, false);

  if (limit_to_selected_bones) {
    pose_apply_restore_fcurves(action);
  }

  BLI_gset_free(selected_bone_names, NULL);
}

this should be exposed as a context manager in Python API

I agree, although it probably shouldn't be the only available API for this. It should be possible to do something like this in a modal operator:

  • temp-load an Action datablock
  • apply the pose with various blend parameters, based on user input
  • repeat the previous step until the user confirms or cancels
  • unload the temp datablock

Of course I agree with everything else you wrote that I didn't quote here.

> Core module should have been tagged here, this falls directly under its umbrella. You're right, thanks for doing so. > Not sure how this plays with your point 2. above? Do you intend to use Depsgraph for this evaluation, or some fully independent code? I intend to use the animation system FCurve evaluation functions for this, and not the depsgraph: ``` void BKE_pose_apply_action(struct Object *ob, struct bAction *action, struct AnimationEvalContext *anim_eval_context) { bPose *pose = ob->pose; GSet *selected_bone_names = NULL; const bool limit_to_selected_bones = pose_apply_find_selected_bones(pose, &selected_bone_names); if (limit_to_selected_bones) { pose_apply_disable_fcurves_for_unselected_bones(action, selected_bone_names); } /* Apply the Action. */ PointerRNA pose_owner_ptr; RNA_id_pointer_create(&ob->id, &pose_owner_ptr); animsys_evaluate_action(&pose_owner_ptr, action, &anim_eval_context, false); if (limit_to_selected_bones) { pose_apply_restore_fcurves(action); } BLI_gset_free(selected_bone_names, NULL); } ``` > this should be exposed as a context manager in Python API I agree, although it probably shouldn't be the only available API for this. It should be possible to do something like this in a modal operator: - temp-load an Action datablock - apply the pose with various blend parameters, based on user input - repeat the previous step until the user confirms or cancels - unload the temp datablock Of course I agree with everything else you wrote that I didn't quote here.

In #86183#1122464, @dr.sybren wrote:

Not sure how this plays with your point 2. above? Do you intend to use Depsgraph for this evaluation, or some fully independent code?

I intend to use the animation system FCurve evaluation functions for this, and not the depsgraph:

void BKE_pose_apply_action(struct Object *ob,
                           struct bAction *action,
                           struct AnimationEvalContext *anim_eval_context)

OK then this should play nicely with action being fully outside of current Main data-base.

this should be exposed as a context manager in Python API

I agree, although it probably shouldn't be the only available API for this. It should be possible to do something like this in a modal operator:

  • temp-load an Action datablock
  • apply the pose with various blend parameters, based on user input
  • repeat the previous step until the user confirms or cancels
  • unload the temp datablock

This should be doable with a context manager too? I mean, one can still open() a file, do whatever with the returned value, and close it themselves right?

I would keep it hidden/advanced way to deal with it though (so just having to explicitly call __enter__() and __exit__() functions).

One could even argue that the underlying code should be the one to be smart here, caching the libs, so that re-creating the context would be almost for free?

> In #86183#1122464, @dr.sybren wrote: >> Not sure how this plays with your point 2. above? Do you intend to use Depsgraph for this evaluation, or some fully independent code? > I intend to use the animation system FCurve evaluation functions for this, and not the depsgraph: > > ``` > void BKE_pose_apply_action(struct Object *ob, > struct bAction *action, > struct AnimationEvalContext *anim_eval_context) OK then this should play nicely with action being fully outside of current Main data-base. >> this should be exposed as a context manager in Python API > I agree, although it probably shouldn't be the only available API for this. It should be possible to do something like this in a modal operator: > - temp-load an Action datablock > - apply the pose with various blend parameters, based on user input > - repeat the previous step until the user confirms or cancels > - unload the temp datablock This should be doable with a context manager too? I mean, one can still `open()` a file, do whatever with the returned value, and close it themselves right? I would keep it hidden/advanced way to deal with it though (so just having to explicitly call `__enter__()` and `__exit__()` functions). One could even argue that the underlying code should be the one to be smart here, caching the libs, so that re-creating the context would be almost for free?

On a side note, I don't think we should lock ourselves to Actions for PoseLib here. Can imagine similar needs/processes for e.g. pre-visualizing a texture in a shader, or a whole shader on an object, etc.?

On a side note, I don't think we should lock ourselves to Actions for PoseLib here. Can imagine similar needs/processes for e.g. pre-visualizing a texture in a shader, or a whole shader on an object, etc.?
Author
Member

In #86183#1122541, @mont29 wrote:
This should be doable with a context manager too? I mean, one can still open() a file, do whatever with the returned value, and close it themselves right?

Yes, but that's because open() returns an object that can be used both as a file and as a context manager. This isn't a property of context managers in general.

I would keep it hidden/advanced way to deal with it though (so just having to explicitly call __enter__() and __exit__() functions).

I'm afraid that that'll produce some nasty mistakes, as I don't expect people to understand which parameters exactly to pass to __exit()__ under which conditions. That could be solved with proper documentation & examples, though.

One could even argue that the underlying code should be the one to be smart here, caching the libs, so that re-creating the context would be almost for free?

For sure, that's what I wrote #86184 (Asset System: cache temp-loaded datablocks) for ;-)

> In #86183#1122541, @mont29 wrote: > This should be doable with a context manager too? I mean, one can still `open()` a file, do whatever with the returned value, and close it themselves right? Yes, but that's because `open()` returns an object that can be used both as a file and as a context manager. This isn't a property of context managers in general. > I would keep it hidden/advanced way to deal with it though (so just having to explicitly call `__enter__()` and `__exit__()` functions). I'm afraid that that'll produce some nasty mistakes, as I don't expect people to understand which parameters exactly to pass to `__exit()__` under which conditions. That could be solved with proper documentation & examples, though. > One could even argue that the underlying code should be the one to be smart here, caching the libs, so that re-creating the context would be almost for free? For sure, that's what I wrote #86184 (Asset System: cache temp-loaded datablocks) for ;-)
Author
Member

With D10736: BLO: Functions for temporarily loading a single datablock having landed in master, this task is complete.

With [D10736: BLO: Functions for temporarily loading a single datablock](https://archive.blender.org/developer/D10736) having landed in master, this task is complete.
Author
Member

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
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#86183
No description provided.