Skip to content

Commit

Permalink
fix(documentation): improve documentation
Browse files Browse the repository at this point in the history
Summary:
- update readme to include detailed use case examples
- add description to example landing page
- bump version to 0.3.0

Reviewed By: cabanier

Differential Revision:
D51245383

Privacy Context Container: L1179008

fbshipit-source-id: 842eedf22bfe8eb55e9d597ad4bb91b79ca3f7e0
  • Loading branch information
felixtrz authored and facebook-github-bot committed Nov 13, 2023
1 parent 18c8542 commit f150f94
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 36 deletions.
162 changes: 140 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,174 @@
[![npm download](https://badgen.net/npm/dw/ratk)](https://www.npmjs.com/package/ratk)
[![license](https://badgen.net/github/license/meta-quest/reality-accelerator-toolkit)](/LICENSE.md)

Reality Accelerator Toolkit is a WebXR utilities library designed to simplify the integration of mixed reality features in [WebXR](https://immersiveweb.dev/) applications. It is currently compatible with the [three.js](https://threejs.org/) 3D library and aims to bridge the gap between low-level WebXR APIs and higher-level APIs provided by three.js. The library is built with the intent to be extensible and compatible with other 3D libraries in the future. It is designed to manage detected planes, anchors, and real-world hit test targets, and to automatically translate them to Object3D instances in the three.js scene, making it easier for developers to access and utilize them.
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](https://threejs.org/) 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
- 🌐 Automatic tracking and updating of detected planes and anchors
- 🎯 Real-world hit test target translation to Object3D instances in the three.js scene
- 🛠️ Extensible design for future compatibility with other 3D libraries
- 🚀 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

three.js (latest version recommended)
- **Peer dependency**: three.js (latest version recommended): [three.js Documentation](https://threejs.org/docs/)

### Installation

Install the package via NPM:
To install the package via NPM, run:

```bash
$ npm install ratk
```

### Usage
## 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.

```js
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: [],
},
});
```

2. **Initializing RATK**: Integrate RATK's root object with your scene. Update it in the render loop.

```js
// Import the library
import { RealityAccelerator } from 'ratk';

// Create a new Reality Accelerator instance from three.js WebXRManager
const ratk = new RealityAccelerator(renderer.xr);

// Add all tracked plane and anchor objects to three.js scene
const scene = /* Three.js Scene object */;
scene.add(ratk.root);

// Update the Reality Accelerator in your render loop
render() {
ratk.update();
function render() {
ratk.update();
}
```

## Documentation

### API Reference

API documentation can be found [here](https://meta-quest.github.io/reality-accelerator-toolkit).
### Anchors

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

```js
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.

```js
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.

```js
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:

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

### Meshes

- **Processing Meshes**: Define a hook to handle new meshes.

```js
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:

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

### Hit Testing

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

```js
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:

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

### Example
## Documentation

An example application utilizing this library can be found [here](https://meta-quest.github.io/reality-accelerator-toolkit/example). Its source code is located in the [example](./example/) directory.
- **API Reference**: [RATK API Documentation](https://meta-quest.github.io/reality-accelerator-toolkit).
- **Example Application**: [Example WebXR Application](https://meta-quest.github.io/reality-accelerator-toolkit/example) ([Source Code](./example/)).

## Contributing

Expand Down
69 changes: 58 additions & 11 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
LICENSE file in the root directory of this source tree.
-->

<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
Expand All @@ -14,18 +14,65 @@
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<title>RATK Demo</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
line-height: 1.2;
}
ul {
list-style-type: none;
padding: 0;
}
li {
background: #f9f9f9;
padding: 5px;
margin-bottom: 5px;
border-radius: 5px;
}
strong {
font-weight: bold;
}
</style>
</head>
<body style="margin: 0">
<div id="scene-container" style="display: block"></div>
<button
id="ar-button"
style="position: fixed; top: 10px; left: 10px"
></button>
<button
id="web-launch-button"
style="position: fixed; top: 10px; left: 10px; display: none"
>
OPEN ON META QUEST
</button>
<div style="position: fixed; top: 10px; left: 10px">
<h1>Reality Accelerator Toolkit Demo</h1>

<ul>
<li>
<strong>Visualizing Tracked Planes and Meshes:</strong>
Displays wireframe outlines of real-world planes and meshes.
</li>

<li>
<strong>Interactive Hit-Testing:</strong>
Allows users to conduct hit tests against physical space.
</li>

<li>
<strong>Persistent Anchors Creation:</strong>
Enables users to create persistent markers in the MR space, shown as
green blocks.
</li>

<li>
<strong>Recovering Previous Session Anchors:</strong>
Recovers and displays markers from previous sessions, shown as red
blocks.
</li>
</ul>

<p>
<strong>How to use:</strong> Press trigger to generate marker at target,
press grip to erase all saved markers
</p>

<button id="ar-button"></button>
<button id="web-launch-button" style="display: none">
OPEN ON META QUEST
</button>
</div>
</body>
</html>
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ratk",
"version": "0.2.1",
"version": "0.3.0",
"description": "WebXR mixed reality utilities library",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down

0 comments on commit f150f94

Please sign in to comment.