npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

xrkeys

v0.1.1

Published

Super performant WebXR keyboard

Downloads

13

Readme

XRKeys

npm version language license

A highly performant and plug-and-play WebXR keyboard library for Three.js applications. XRKeys empowers your WebXR applications with typing capabilities at the minimal expense of just two draw calls, while eliminating the need for extra setup such as loading fonts for the keyboard.

Features

  • 🔌 Plug-and-Play: No need for extra setup like loading fonts for the keyboard. Just install and use it right away.
  • ⚡️ High Performance: Requires only 2 drawcalls, minimal impact on performance of your WebXR applications.
  • 🌍 Three.js Compatible: Specifically built for Three.js WebXR applications.

Demo App

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

This demo app is a great resource for developers who are considering using XRKeys 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 XRKeys, simply run the following command in your terminal:

$ npm install xrkeys

Or if you prefer using Yarn:

$ yarn add xrkeys

Usage

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

import XRKeys from 'xrkeys';

NOTE: NOTE: XRKeys requires Three.js as a peer dependency, make sure to have a recent version installed.

Then, create an instance of the XR keyboard:

const keyboard = await XRKeys.create();

The XRKeys object created extends THREE.Group, and can be used as such. Setup the keyboard and add it to your scene:

// listen for keypress events
keyboard.addEventListener('keypress', (e) => {
	console.log('Key pressed: ' + e.key);
});

// you can bind a custom function to the enter key
keyboard.onEnter = (text) => {
	console.log('Entered text: ' + text);
};

scene.add(keyboard);

Update the keyboard in your render loop:

function render() {
	// update the keyboard with a target ray and a pressing flag
	const targetRaySpace = renderer.xr.getController(0);
	keyboard.update(targetRaySpace, triggerIsPressed);

	// you can also access the keyboard's text content anytime
	console.log(keyboard.text);
}

API Reference

XRKeysConfig type

XRKeysConfig is an object type that can have the following optional properties:

  • path?: string: Path override for custom keyboard model.
  • keyMaskOffset?: number: Z Offset for the key mask.
  • hoverColor?: string: Color of the key mask when hovered.
  • pressedColor?: string: Color of the key mask when pressed.

XRKeys class

XRKeys is a class that extends THREE.Group.

Properties

  • activeKeyboard: THREE.Mesh: Returns the active keyboard mesh.
  • activeKeysetIndex: number: Returns the index of the active keyset.
  • text: string: Returns the text inputted using the keyboard.
  • onEnter: (text: string) => void: Callback function called when the Enter key is pressed.

Methods

  • static create(config?: XRKeysConfig): Promise<XRKeys>: Static method that creates and returns a promise that resolves to an XRKeys instance. Takes an optional XRKeysConfig object as a parameter.
  • update(targetRaySpace: THREE.Object3D, pressed: boolean): void: Method to update the keyboard based on the target ray space and whether a key is being pressed.

License

MIT License © 2023 Felix Zhang