Sitemap

WebXR Guide

7 min readJul 7, 2023

--

This is my recent presentation. And I will share it with some comments.

Press enter or click to view image in full size
1/24

Today I am going to share very funny topics;

WebXR

You know, Meta and Apple invested a lot of resources in this field; Some people here don’t have headsets or never experience it.

But it doesn’t matter; Today I will just make a simple introduction about it.

Press enter or click to view image in full size
2/24

Here are agendas

Press enter or click to view image in full size
3/24

In the 1940s, the first computer was born in the world. At that time, the computer was still huge, and the interface looks so old style, and we can only get specific information from the different colors of lights;

A few years later, major companies(like IBM) entered the personal computer market;

That’s the computer’s appearance we are seen now. we use the mouse and keyboard and a big display.

In the new century, we have an iPad with a touch screen, which is one of the great inventions in human history; Von Neumann model, the input and output are perfectly combined on one display On the screen; it brings us a lot of innovative interactions;

In the last ten years, humans are still looking for the next generation of computers; maybe headsets will be one.

Why?

Press enter or click to view image in full size
4/24

Let’s talk about “XR”

Some people are willing to use X to represent anything; Because we know there are VR, AR;

And also with the new generation headsets, we created the MR(mixed-reality); Via The Video See-Through technology, we cannot only see the display graph, but we can also see the outside world graph from the camera located in the headset.

Press enter or click to view image in full size
5/24

The biggest difference from XR; It gives us is the immersive experience;

The first part: we could experience the visual 3d graph and spatial audio; That’s one part of `reality`

The second part: Our interaction is not simply a button, but will dynamically combine the position of our physical space and the position of the device, so it will respond according to our actions;

After talking about XR, maybe you get to know what webXR is by its name;

Press enter or click to view image in full size
6/24

Then let’s talk about WebXR;

WebXR means us to develop web applications in the browser of XR OS;

Introduction to the WebXR API

Press enter or click to view image in full size
7/24

The first thing we do with any new API is to determine its compatibility; we can do this by

if ("xr" in window.navigator) {
/* WebXR can be used! */
} else {
/* WebXR isn't available */
}

After judging, we just need to start;

among them, XRSession is a very important concept;

In the session, we can access some basic WebXR APi and change some common properties;

we can requestSessionenter our VR mode;

navigator.xr.requestSession('immersive-vr').then(onSessionStarted)
Press enter or click to view image in full size
8/24

There are two modes in XRSession;

inline can be in normal mode, that is, our pages will be displayed according to the execution method of the browser. For example, the Weibo we browse normally can be displayed normally on Zhihu

immersive-vr is our expected VR mode, we will enter a three-dimensional scene, it depends on how we realize;

Press enter or click to view image in full size
9/24

In XRSession, we can implement some operations on WebXR API, such as:

It helps us to detect it in AR or VR mode (environmentBlendMode)

renderState: describing how the user’s environment which should be rendered

inputSources: I will talk about it later

requestAnimationFrame: schedules a callback to be executed the next time

Next is what we need to focus on WebGL;

Press enter or click to view image in full size
10/24

the WebXR API itself does not include a 3D graphics API, it must be used in conjunction with the WebGL API (or the more modern WebGPU API);

therefore, if we want to in-depth application development, WebGL learning is definitely inevitable;

Press enter or click to view image in full size
11/24

XRSpace In WebXR;

a “space (XRSpace)” represents a set of 3D coordinate systems in virtual space, and its origin corresponds to a position in the physical real world, so “space” can serve as a link between digital virtual space and physical reality The role of spatial association; with it, we can better handle our interactions; both from the controller and the headset itself;

Get JackPu’s stories in your inbox

Join Medium for free to get updates from this writer.

Let me make an example;

Press enter or click to view image in full size
12/24

When we implement web chess, we can control chess pieces according to mouse clicks, mouseover, and other events;

if we want to implement a three-dimensional chessboard placed in front of us, we want to realize chess moves, what should the interactive information be like?

The next step is also very important; how do we handle interaction;

Press enter or click to view image in full size
13/24

We know the Von Neumann architecture;

VR also has many sources of interaction, for example, we often have two controllers; before the first time, the headset is also one of the interactive devices we need to track; With increasing precision, our hands will also become the objects we interact with;

Press enter or click to view image in full size
14/24

This is Oculus quest pro controller. There is some press button and a joystick, And also there is a touch area; It could be very complex;

Press enter or click to view image in full size
15/24

Through the above figure, we can simply compare how we realize the binding of events;

Press enter or click to view image in full size
16/24

In addition to the APIs introduced above, you can also learn about the following if you are interested

XRFrame: access to the information needed in order to render a single frame

XRPose: a position and orientation in the 3D space,

XRViewport: it provides properties used to describe the size and position of the current viewport

How do we start it?

Press enter or click to view image in full size
17/24

How do we develop the basic API introduced earlier; I have some small tips to share

1 Web project initialization (PWA is better); because it is a Web project, we can use our favorite technical scaffolding or engineering, what Webpack/TS/Eslnt ​​can be freely matched; if you want to publish the application to the Quest store, it is best Use some auxiliary tools of PWA; I wrote an article about Oculus and PWA before, you can take a look;

2 WebGL is the core, so we’d better choose a suitable WebGL framework (Three.js, Babylon.js), writing native code is really cumbersome;

3 Initialize WebXR and process XRFrame (you can also choose the WebXR framework); this is what we all need to do, with the help of documentation, refer to WebXR Sample to help you understand them;

4 Testing and real machine debugging; in any case, it must be tested on a real machine;

I will show you a video demo;

https://drive.google.com/file/d/1Ib_ztIKZekv48eVPICYbPIE44cwPgBD_/view?resourcekey

Press enter or click to view image in full size
19/24

We usually develop, we can use webxr-api-emulator to do some interactive processing;(simulation)

if we are debugging on the real machine;

Press enter or click to view image in full size
20/24

We can use adb reversethe command to perform localhost proxy; of course, other proxy network tools are also available; because the API of WebXR can only localhost work under HTTPS;

Press enter or click to view image in full size
21/24

After the development is complete, you can of course publish your own application, don’t forget to package PWA and APK packages;

Some useful tools:

  • @bubblewrap/cli
  • Oculus Platform Utility
  • PWA on Oculus Quest2
Press enter or click to view image in full size
22/24

Here I also briefly compare the similarities and differences between traditional Web and WebXR development; mainly

WebXR is more graphically related to development

We use many model files (bx,gLTE,obj)

It will be more complicated to handle the interaction

Press enter or click to view image in full size
23/24

Although the development of WebXR is very difficult, due to the natural cross-platform compatibility of the Web, as well as the out-of-the-box feature without installation, I believe that there must be a world of its own in the future;

Press enter or click to view image in full size

Thanks. I just make a brief share about WebXR; There is one tip for you.The most of APIs are under-experimental. And We cannot guarantee that Oculus or App will support them well. So if you are interested in it; maybe you could explore more by yourself. Because three are so less helpful documents. Anyway, we can know what our web developers can do if the XR moment is coming.

[Chinses Version]

Read More:

--

--