stalgiag / p5.xr

a library that helps turn p5.js sketches into immersive experiences using WebXR
GNU Lesser General Public License v2.1
117 stars 25 forks source link

Reusing XRSession in P5LIVE for Live Coding in immersive-ar and immersive-vr Sessions #237

Closed TiborUdvari closed 1 month ago

TiborUdvari commented 1 month ago

When entering an immersive-ar or immersive-vr session, there is a noticeable delay of a few seconds, which interrupts the user flow. While this is acceptable for most user experiences, it becomes cumbersome in live coding environments, where immediate feedback is crucial.

Current Problem

Typically, a new XR session is created at the start of every p5.js sketch. In live coding scenarios, like with P5LIVE (which runs p5 sketches in an iframe), the frequent session resets slow down the feedback loop. This results in a frustrating experience, as every time the sketch is restarted, the XR session also needs to be recreated.

Proposed Solution

The goal is to initiate the XRSession only once and reuse it throughout the live coding session, even when the sketch restarts. In P5LIVE, the sketch runs in an iframe, and code can be hoisted to the parent frame that contains both the editor and the sketch. Using this mechanism, we can maintain the XRSession even when the p5 session restarts.

Goal

For now, the solution will be focused on making it work with P5LIVE, as it has the structure (iframe hoisting) needed to reuse the XRSession effectively. Once the session is started, the user should be able to live code without ever having to manually press the Enter/Exit XR button again.

TiborUdvari commented 1 month ago

Relevant discussion in the P5 LIVE repo https://github.com/ffd8/P5LIVE/issues/95