Looking-Glass / looking-glass-webxr

WebXR for Looking Glass displays
https://docs.lookingglassfactory.com/developer-tools/webxr
Apache License 2.0
66 stars 16 forks source link

Looking Glass WebXR Library

The Looking Glass WebXR Library provides a WebXR API for targeting Looking Glass displays, this means that any 3D web framework that supports WebXR will work with the Looking Glass WebXR library. Ready to turn the internet holographic? Let's have some fun!

Looking Glass WebXR works in Chromium based browsers and Firefox, though we recommend chrome-based browsers for best performance. Safari is not currently supported.

We've tested our WebXR Library with the following WebGL frameworks. If you use one and don't see it here, reach out on discord! We'd love to support as many as possible, it's likely yours may work too!

Requirements

In order to use WebXR:

How it works

The LookingGlassWebXRPolyfill implements the WebXR override and allows you to target Looking Glass displays.

To view a WebXR project on your Looking Glass, visit one of the demos and then click the Enter Looking Glass button. This will open up a small pop-up window. Drag this window over to your Looking Glass display and then double click to have the hologram display properly.

Note: On MacOS systems you must have Chrome or Firefox be in windowed mode, and not running in Fullscreen. Running in full screen will cause the window to open in a new tab instead of a new window.

Installation

Using NPM/Yarn

You can import the Looking Glass WebXR library by running the following command in your web project.

npm install @lookingglass/webxr

or, if you use the yarn package manager.

yarn install @lookingglass/webxr

Import the library

To get started import LookingGlassWebXRPolyfill

import { LookingGlassWebXRPolyfill } from "@lookingglass/webxr"

or you can also use a <script> tag:

<script type="module">
  import { LookingGlassWebXRPolyfill } from "https://unpkg.com/@lookingglass/webxr@0.3.0/dist/@lookingglass/bundle/webxr.js"
</script>

Initialize LookingGlassWebXRPolyfill

After you have the library properly installed and imported into your project, all you have to do is is instantiate LookingGlassWebXRPolyfill and you're done!

import { LookingGlassWebXRPolyfill } from "@lookingglass/webxr"

new LookingGlassWebXRPolyfill()

You should now see an "Enter Looking Glass" button in your scene. You can optionally pass in your own defaults for all the view controls:

new LookingGlassWebXRPolyfill({
  tileHeight: 512,
  numViews: 45,
  targetY: 0,
  targetZ: 0,
  targetDiam: 3,
  fovy: (14 * Math.PI) / 180
})

Since Looking Glass WebXR is engine agnostic there are a few settings that will be the same regardless of what 3D engine you're working with. Here are all the possible properties you can pass into LookingGlassWebXRPolyfill:

Updating the view

In some cases you may need to update the view controls after instatiating:

const lookingGlassWebXR = new LookingGlassWebXRPolyfill({
  tileHeight: 512,
  numViews: 45,
  targetY: 0,
  targetZ: 0,
  targetDiam: 3,
  fovy: (14 * Math.PI) / 180
})

// ...

// Use the update() method
lookingGlassWebXR.update({
  numViews: 80
})

You can also update the config values by importing LookingGlassConfig and declaring it as follows, this can be handy if you want to modify the camera from a separate file where you're declaring the polyfill in.

 let config = LookingGlassConfig
 config.trackballX = Math.PI / 2

Contributing

The Looking Glass WebXR Library is open source and originally developed by Kai Ninomiya. We're excited to support the open-source community! If you'd like to contribute, please feel free to make a pull request.