VR: Python API for Controller Interaction #77137

Closed
opened 2020-05-28 18:48:25 +02:00 by Julian Eisel · 8 comments
Member

VR: Python API for Controller Interaction

We want to provide Python developers with sufficient tools to build their own VR experiences. That means the Python API needs to give access to devices (including controllers), but in a way that is as little device and platform dependent as possible.
It's probably best to first think about how we want the Python API to look like, before thinking about the internal C/C++ code design. The former has big impact on the latter.

About the OpenXR input and haptics design

  • OpenXR tries to give much control to the applications using it, in a way that does not set any restrictions on the device design.
  • Therefore, it tries to operate on an abstract level. E.g. rather than addressing a controller button as "A" it's addressed by a custom, abstract action "teleport".
  • These abstract actions are entirely defined by the application and bound to higher level controller events identified with a path for a semantic path tree, e.g. "/user/hand/right/input/trigger/click".
  • These paths are defined in device specific interaction profiles as part of the OpenXR definition. OpenXR runtimes (e.g. Monado, Oculus or WinMR) may however change these, e.g. depending on a custom user configuration.

Assessment for Blender

The level of abstraction in OpenXR seems very appropriate for a Python API too. It provides sufficient flexibility and device independence for Add-ons. So rather than doing much work in C/C++ to deal with the OpenXR design, the principal design could be forwarded to the Python API.

  • As more devices become available via OpenXR (e.g. a quite different kind of controller, like the Logitech VR Ink), changes in C/C++ code are not needed for an Add-on to use it.

OpenXR actions could be nicely integrated with the Blender design. Rather than specifying an action directly, an operator name could be specified. The C code could then automatically invoke an operator upon an action event.
Since OpenXR and the OpenXR runtime define the interaction profiles (mapping of physical buttons to higher level concepts like "trigger"), Blender should not do any additional mapping (e.g. no custom key-maps within Blender).


Proposal

OpenXR actions have to be created and assigned to an action-set at a specific point during VR session start. So Add-ons need to be able to hook into that to create their own actions. This could be done with an application handler . E.g. bpy.app.handlers.xr_session_start.

With that handler, creating actions could look like this:

@persistent
def action_set_setup_hander():
    # Action set for this add-on.

action_set = bpy.types.XrAction.create_action_set(name="Foo Add-on Actions")


action = action_set.add_action(binding="/user/hand/right/input/trigger/click", operator="view3d.vr_addon_teleport")
action.some_enum_operator_option = 'ENUM_VALUE'

We'll probably need a way to drive modal operators through OpenXR actions too. This could be defined in a similar fashion, a proposal for that is a todo.

Haptics
Without extensions, the only haptic feedback supported by OpenXR is vibration. The OpenXR action for this can be created automatically, so Add-ons can trigger this on demand:

# ... regular operator code
bpy.types.XrHaptics.vibrate(duration=300, intensity='LOW')

NOTE: This task doesn't cover all parts of the eventually needed controller API.

# VR: Python API for Controller Interaction We want to provide Python developers with sufficient tools to build their own VR experiences. That means the Python API needs to give access to devices (including controllers), but in a way that is as little device and platform dependent as possible. It's probably best to first think about how we want the Python API to look like, before thinking about the internal C/C++ code design. The former has big impact on the latter. **About the OpenXR input and haptics design** * OpenXR tries to give much control to the applications using it, in a way that does not set any restrictions on the device design. * Therefore, it tries to operate on an abstract level. E.g. rather than addressing a controller button as "A" it's addressed by a custom, abstract action "teleport". * These abstract actions are entirely defined by the application and bound to higher level controller events identified with a path for a semantic path tree, e.g. `"/user/hand/right/input/trigger/click"`. * These paths are defined in device specific interaction profiles as part of the OpenXR definition. OpenXR runtimes (e.g. Monado, Oculus or WinMR) may however change these, e.g. depending on a custom user configuration. **Assessment for Blender** The level of abstraction in OpenXR seems very appropriate for a Python API too. It provides sufficient flexibility and device independence for Add-ons. So rather than doing much work in C/C++ to deal with the OpenXR design, the principal design could be forwarded to the Python API. - > As more devices become available via OpenXR (e.g. a quite different kind of controller, like the Logitech VR Ink), changes in C/C++ code are not needed for an Add-on to use it. OpenXR actions could be nicely integrated with the Blender design. Rather than specifying an action directly, an operator name could be specified. The C code could then automatically invoke an operator upon an action event. Since OpenXR and the OpenXR runtime define the interaction profiles (mapping of physical buttons to higher level concepts like "trigger"), Blender should not do any additional mapping (e.g. no custom key-maps within Blender). ---- ## Proposal OpenXR actions have to be created and assigned to an action-set at a specific point during VR session start. So Add-ons need to be able to hook into that to create their own actions. This could be done with an [application handler ](https://docs.blender.org/api/current/bpy.app.handlers.html). E.g. `bpy.app.handlers.xr_session_start`. With that handler, creating actions could look like this: ```lang=Python @persistent def action_set_setup_hander(): # Action set for this add-on. ``` action_set = bpy.types.XrAction.create_action_set(name="Foo Add-on Actions") ``` ``` action = action_set.add_action(binding="/user/hand/right/input/trigger/click", operator="view3d.vr_addon_teleport") action.some_enum_operator_option = 'ENUM_VALUE' ``` ``` We'll probably need a way to drive modal operators through OpenXR actions too. This could be defined in a similar fashion, a proposal for that is a todo. **Haptics** Without extensions, the only haptic feedback supported by OpenXR is vibration. The OpenXR action for this can be created automatically, so Add-ons can trigger this on demand: ```lang=Python # ... regular operator code bpy.types.XrHaptics.vibrate(duration=300, intensity='LOW') ``` NOTE: This task doesn't cover all parts of the eventually needed controller API.
Author
Member

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

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

Added subscribers: @JulianEisel, @PeterK-4

Added subscribers: @JulianEisel, @PeterK-4
Julian Eisel changed title from = VR: Python API for Controller Interaction to VR: Python API for Controller Interaction 2020-05-28 18:50:33 +02:00
Member

Added subscriber: @nfauvet

Added subscriber: @nfauvet
Member

Added subscriber: @JorgeBernalMartinez

Added subscriber: @JorgeBernalMartinez
Peter Klimenko was assigned by Julian Eisel 2020-06-14 14:31:24 +02:00

Added subscriber: @JeffreyKlug

Added subscriber: @JeffreyKlug
Contributor

Added subscriber: @RedMser

Added subscriber: @RedMser
Member

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'

Added subscriber: @satishgoda1

Added subscriber: @satishgoda1
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
7 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#77137
No description provided.