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

ratk

v0.3.0

Published

WebXR mixed reality utilities library

Downloads

182

Readme

Reality Accelerator Toolkit

npm version language npm download license

The Reality Accelerator Toolkit is a comprehensive WebXR utilities library that simplifies the integration of mixed reality features in WebXR applications. Compatible with the three.js 3D library, it bridges the gap between the low-level WebXR APIs and the higher-level APIs offered by three.js. Designed for extensibility, it enables the management of detected planes, meshes, anchors, and real-world hit test targets, translating them seamlessly to Object3D instances in the three.js scene.

Features

  • 🚀 Seamless integration with three.js for enhanced 3D application development.
  • 🌐 Automatic detection and update of planes, meshes and anchors in the scene.
  • 🎯 Translation of real-world hit test targets to Object3D instances in three.js.

Getting Started

Prerequisites

Installation

To install the package via NPM, run:

$ npm install ratk

Usage

Each section below details how to use different features of the toolkit.

RATK Setup

  1. Setting Up AR Button: Request a WebXR session with specified features.
import { ARButton } from 'ratk';
const renderer = /* Three.js WebGLRenderer */;
const arButton = document.getElementById('ar-button');

ARButton.convertToARButton(arButton, renderer, {
  sessionInit: {
    requiredFeatures: ['hit-test', 'plane-detection', 'mesh-detection', 'anchors'],
    optionalFeatures: [],
  },
});
  1. Initializing RATK: Integrate RATK's root object with your scene. Update it in the render loop.
// Import the library
import { RealityAccelerator } from 'ratk';
const ratk = new RealityAccelerator(renderer.xr);
const scene = /* Three.js Scene object */;
scene.add(ratk.root);

function render() {
	ratk.update();
}

Anchors

  • Creating Anchors: Define position and orientation, then attach objects.

    const ratk = /* RealityAccelerator instance */;
    const anchorPosition = new Vector3(1, 2, 3);
    const anchorQuaternion = new Quaternion(0, 0, 0, 1);
    
    ratk.createAnchor(anchorPosition, anchorQuaternion, isPersistent)
      .then((anchor /* RATK Anchor object extends Object3D */) => {
        // Attach a new THREE.Mesh to the anchor
        anchor.add(new THREE.Mesh(geometry, material));
      });
  • Recovering Anchors: Access persistent anchors from previous sessions.

    ratk.restorePersistentAnchors().then(() => {
    	ratk.anchors.forEach((anchor) => {
    		// Process each recovered anchor
    		anchor.add(new THREE.Mesh(geometry, material));
    	});
    });

Planes

  • Processing Planes: Define a hook to handle new planes.

    ratk.onPlaneAdded = (plane /* extends Object3D */) => {
    	if (plane.semanticLabel === 'wall art') {
    		const mesh = plane.planeMesh; // Three.js Plane Mesh
    		mesh.material = new MeshBasicMaterial(/_ parameters _/);
    		// Additional plane processing
    	}
    };
  • Alternatively, access planes directly from the RATK instance:

    ratk.planes.forEach((plane) => {
    	// Process each plane
    });

Meshes

  • Processing Meshes: Define a hook to handle new meshes.

    ratk.onMeshAdded = (rmesh /* extends Object3D */) => {
      const meshMesh = rmesh.meshMesh; /* reconstructed Three.js Mesh */
      meshMesh.material = new MeshBasicMaterial(...);
      meshMesh.geometry.computeBoundingBox();
    
      // put a text label on top of the mesh
      const semanticLabel = new Text();
      meshMesh.add(semanticLabel);
      semanticLabel.text = mesh.semanticLabel;
      semanticLabel.sync();
      semanticLabel.position.y = meshMesh.geometry.boundingBox.max.y;
    };
  • Alternatively, access meshes directly from the RATK instance:

    ratk.meshes.forEach((rmesh) => {
    	// Process each mesh
    });

Hit Testing

  • Controller Hit-Testing: Create HitTestTarget from controller with offset transform

    const ratk = /* RealityAccelerator instance */;
    const offsetPosition = new Vector3(0, 0, 0);
    const offsetQuaternion = new Quaternion(0, 0, 0, 1);
    
    ratk
      .createHitTestTargetFromControllerSpace(
        handedness,
        offsetPosition,
        offsetQuaternion,
      )
      .then((hitTestTarget /* extends Object3D */) => {
        hitTestTarget.add(
          new Mesh(...),
        );
      });
  • Alternatively, conduct hit-testing from viewer space:

    ratk.createHitTestTargetFromViewerSpace(
      offsetPosition,
      offsetQuaternion,
    ).then(...);

Documentation

Contributing

Please read CONTRIBUTING.md for details on how to contribute to the project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.