USD: basic support for on_import USD hooks #117822

Merged
Michael Kowalski merged 2 commits from makowalski/blender:usd-import-hooks into main 2024-02-05 14:26:11 +01:00

Added support for defining an on_import() function in
bpy.types.USDHook subclasses. If on_import() is defined
on a given USD hook, it will be invoked in import_endjob().

The implementation closely follows the existing design of
export hooks. USDHook.on_import() takes as an argument
an instance of an internally defined USDSceneImportContext
class which provides an accessor to the USD stage.

Also updated the USDHook documentation with an example
on_import() callback implementation.

Testing

The attached usd_hook add-on provides a basic (somewhat
contrived) example of an on_import() implementation which
creates a Text object in the scene to display the root layer
custom data. Examples of USDZ files with custom data can
be found on the quick-look page.

Added support for defining an on_import() function in bpy.types.USDHook subclasses. If on_import() is defined on a given USD hook, it will be invoked in import_endjob(). The implementation closely follows the existing design of export hooks. USDHook.on_import() takes as an argument an instance of an internally defined USDSceneImportContext class which provides an accessor to the USD stage. Also updated the USDHook documentation with an example on_import() callback implementation. ### Testing The attached `usd_hook` add-on provides a basic (somewhat contrived) example of an `on_import()` implementation which creates a Text object in the scene to display the root layer custom data. Examples of USDZ files with custom data can be found on the [quick-look page.](https://developer.apple.com/augmented-reality/quick-look/)
Michael Kowalski added the
Interest
USD
Interest
Pipeline & IO
labels 2024-02-05 03:46:08 +01:00
Michael Kowalski added 1 commit 2024-02-05 03:46:18 +01:00
USD: basic support for on_import USD hooks
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
4c7a4788aa
Added support for defining an on_import() function in
bpy.types.USDHook subclasses.  If on_import() is defined
on a given USD hook, it will be invoked in import_endjob().

Also updated the USDHook documentation with an example
on_import() callback implementation.
Michael Kowalski added this to the USD project 2024-02-05 03:46:50 +01:00
Michael Kowalski requested review from Jesse Yurkovich 2024-02-05 04:07:58 +01:00
Michael Kowalski requested review from Brecht Van Lommel 2024-02-05 04:08:21 +01:00
Author
Member

@blender-bot build

@blender-bot build
Author
Member

@Matt-McLin for visibility.

@brecht @deadpin I know there are only a couple of days left in Bcon2, but this is a relatively small, localized patch and hopefully can be included in 4.1. However, I would understand if you feel there is insufficient time to review this.

@Matt-McLin for visibility. @brecht @deadpin I know there are only a couple of days left in Bcon2, but this is a relatively small, localized patch and hopefully can be included in 4.1. However, I would understand if you feel there is insufficient time to review this.
Michael Kowalski added 1 commit 2024-02-05 04:42:42 +01:00
Jesse Yurkovich approved these changes 2024-02-05 05:08:44 +01:00
Jesse Yurkovich left a comment
Member

I'm fine with this going in for 4.1. It seems to work as advertised and the only comments I have pre-date this patch to when hooks were initially added.

  • It seems as through the True/False return value for the hooks aren't really used? Returning False has no real impact it seems.
  • There's a memory leak if a hook is added but never unregistered. This wouldn't typically happen for a real addons but would when running in the script editor or similar. We can fix this up as a separate bug fix.
I'm fine with this going in for 4.1. It seems to work as advertised and the only comments I have pre-date this patch to when hooks were initially added. - It seems as through the True/False return value for the hooks aren't really used? Returning False has no real impact it seems. - There's a memory leak if a hook is added but never unregistered. This wouldn't typically happen for a real addons but would when running in the script editor or similar. We can fix this up as a separate bug fix.
Brecht Van Lommel approved these changes 2024-02-05 12:03:10 +01:00
Author
Member
  • It seems as through the True/False return value for the hooks aren't really used? Returning False has no real impact it seems.

You are correct. The intent was to future-proof hook implementations to allow for use cases when the return value could matter as the USD hook API evolves. The return value could be helpful for recognizing when the hook function is a no-op so that the IO code can provide fallback behavior (e.g., if a user-specified material conversion hook does nothing, the USD import code could still convert the standard USD Preview Surface material by default). But this is something we can certainly discuss.

Thanks so much for the reviews!

> - It seems as through the True/False return value for the hooks aren't really used? Returning False has no real impact it seems. You are correct. The intent was to future-proof hook implementations to allow for use cases when the return value could matter as the USD hook API evolves. The return value could be helpful for recognizing when the hook function is a no-op so that the IO code can provide fallback behavior (e.g., if a user-specified material conversion hook does nothing, the USD import code could still convert the standard USD Preview Surface material by default). But this is something we can certainly discuss. Thanks so much for the reviews!
Michael Kowalski merged commit ecbf3385c5 into main 2024-02-05 14:26:11 +01:00
Michael Kowalski deleted branch usd-import-hooks 2024-02-05 14:26:13 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
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 & 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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
Asset System
Module
Asset System
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
3 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#117822
No description provided.