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

react-8thwall-aframe

v1.0.3

Published

A React library for integrating 8th Wall WebAR

Downloads

19

Readme

react-8thwall-aframe

A lightweight package to integrate 8th Wall WebAR capabilities into React applications. This package streamlines the process of including necessary scripts, managing script loading states, and registering A-Frame components, making it easier to create engaging WebAR experiences in React apps.

react-8thwall-aframe Demo

Features

  • Easy integration of 8th Wall and other 3d scripts in React applications
  • Hooks for managing WebAR script loading states and Aframe component registration
  • Built-in support for custom Draco compressed gltf/glb models
  • TypeScript batteries included 🔋

Watch Demo on YouTube

Installation

npm install react-8thwall-aframe

Usage

1. XR8Scripts Component

The XR8Scripts component should be placed in the of your document to load all necessary 8th Wall scripts. Example usage in Nextjs 14 (app router):

import type { Metadata } from 'next';
import { Inter } from 'next/font/google';
import './globals.css';
import { XR8Scripts } from 'react-8thwall-aframe';

const inter = Inter({ subsets: ['latin'] });

export const metadata: Metadata = {
  title: 'Create Next App',
  description: 'Generated by create next app',
};

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode,
}>) {
  return (
    <html lang='en'>
      <head>
        <XR8Scripts xr8ApiKey='' /> // include the api key
      </head>
      <body className={inter.className}>{children}</body>
    </html>
  );
}

2. useXR8Ready Hook

The useXR8Ready hook checks if the 8th Wall scripts are loaded and the Draco loader is initialized.

import { useXR8Ready } from 'react-8thwall';

function ARComponent() {
  const { xrReady, dracoReady, error } = useXR8Ready();

  if (error) return <div>Error: {error.message}</div>;
  if (!xrReady || !dracoReady) return <div>Loading AR...</div>;

  return <div>{/* the view along with the aframe scene */}</div>;
}

3. useAFrameComponents Hook

The useAFrameComponents hook allows you to register custom A-Frame components easily. It follows a naming convention where the key in the components object is the name of the component (in kebab-case) as it will be used in A-Frame, and the value is the component object itself.

import { useAFrameComponents } from 'react-8thwall';

const sampleComponent = {
  init: function () {
    // Your component initialization logic
  },
  update: function () {
    // Logic for when component data changes
  },
  // Other A-Frame component lifecycle methods
};

function ARScene() {
  const components = {
    'sample-component': sampleComponent,
    // Add other components here, following the 'component-name': componentObject pattern
  };
  const componentsRegistered = useAFrameComponents(components);

  if (!componentsRegistered) {
    return <div>Loading components...</div>;
  }

  return (
    <a-scene>
      <a-entity sample-component></a-entity>
    </a-scene>
  );
}

Examples

This repository includes a sample Next.js 14 project demonstrating how to use react-8thwall-aframe library in a React application. To run the example:

  1. Clone this repository
  2. Navigate to the example directory: cd react-8thwall-aframe/example
  3. Install dependencies: npm install
  4. Start the development server: npm run dev

Note: You'll need to provide your own 8th Wall API key in the example project's layout.js file and add the domain to list of authorised domains for the self-hosted project in 8thwall editor.

Here are some examples of available using react-8thwall-aframe:

  1. Animation Sample: Explore 8th Wall WebAR animations in React
  2. Custom Component: Learn how to create custom A-Frame components
  3. Interaction Example: Discover interactive WebAR experiences

Each of these examples demonstrates different aspects of WebAR development using react-8thwall-aframe, showcasing the package's capabilities in creating engaging and interactive AR content.

API Reference

XR8Scripts

Props:

  • xr8ApiKey (required): Your 8th Wall API key
  • remoteJsChannel (optional): Channel for remote debugging
  • aframeVersion (optional): Specify A-Frame version (default: '1.3.0')
  • aframeExtrasVersion (optional): Specify A-Frame Extras version (default: '6.1.1')

useXR8Ready

Parameters:

  • customPath (optional): Custom path for Draco decoder

Returns an object with:

  • xrReady: Boolean indicating if XR scripts are ready
  • dracoReady: Boolean indicating if Draco loader is ready
  • error: Error object if an error occurred, null otherwise

useAFrameComponents

Parameters:

  • components: An object where keys are component names and values are component definitions

Returns:

  • true when components are registered

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

ISC