Home

Awesome

LogXR

npm version language npm download license

A debugging utility that makes it easy to view console logs in WebXR experiences. LogXR provides developers with a simple and straightforward way to debug and troubleshoot their WebXR applications, giving them clarity and insight into the console output. The library is designed to be lightweight and versatile, offering a wide range of customization options for the appearance and behavior of the XR console. Currently, LogXR only supports Three.js, with support for Babylon.js coming soon.

Features

Demo App

A demo app has been built using Three.js to showcase LogXR in action. You can check out the demo app at https://felixtrz.github.io/logxr/ to see how LogXR works and to get a feel for its capabilities.

This demo app is a great resource for developers who are considering using LogXR in their projects. It provides a hands-on experience with the library, and will give you a better understanding of how it works and what it can do.

Installation

To install LogXR, simply run the following command in your terminal:

npm install logxr

Or if you prefer using Yarn:

$ yarn add logxr

Usage

Using LogXR is simple. First, import the package in your WebXR project:

import { XRConsoleFactory } from 'logxr';

NOTE: LogXR requires Three.js as a peer dependency, make sure to have a recent version installed. Babylon.js support is coming soon! 🚀

Then, create an instance of the XR console:

const xrConsole = XRConsoleFactory.getInstance().createConsole({
	pixelWidth: 1024,
	pixelHeight: 512,
	actualWidth: 2,
	actualHeight: 1,
});

The xrConsole object created extends THREE.Object3D, and can be used as such. After a console is set up, simply use console.log() as usual, and the logs will be intercepted and reflected on the xrConsole.

API Reference

The following classes are exported by LogXR, and are available for use in your WebXR projects:

XRConsoleFactory

The XRConsoleFactory class provides a factory method to create instances of XRConsole, and manage the message queue that all instances of XRConsole read from.

Properties

maxNumMessages

maxNumMessages: number;

Gets or sets the maximum number of messages that can be stored by the XRConsoleFactory. The default value is 100.

Methods

static getInstance(): XRConsoleFactory

static getInstance(): XRConsoleFactory

Gets a singleton instance of the XRConsoleFactory.

createConsole(options: XRConsoleOptions): XRConsole

createConsole(options: XRConsoleOptions): XRConsole

Creates a new instance of XRConsole with the specified options.

getMessages(messageTypes: MessageType[], count: number): Message[]

getMessages(messageTypes: MessageType[], count: number): Message[]

Gets the messages in the message queue that match the specified message types. The number of messages returned is limited by the count parameter.

XRConsole

The XRConsole class represents the XR console and provides the necessary functionality for rendering console logs in a WebXR environment.

Properties

panelMesh: Mesh

The panelMesh property represents the mesh object that serves as the panel for the console.

needsUpdate: boolean

The needsUpdate property is a flag that indicates whether the console canvas needs to be updated.

Methods

constructor(options?: XRConsoleOptions)

constructor(options?: XRConsoleOptions)

Creates a new instance of the XR console with the specified options.

render()

render(): void

Renders the console to the canvas.

XRConsoleOptions

The XRConsoleOptions interface represents a set of options that can be passed to the XRConsole constructor to customize its appearance and behavior.

Properties

MessageType

The MessageType enumeration is used to specify the type of messages that should be displayed in the XR console.

Values

License

MIT License © 2023 Felix Zhang