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

@r2u/react-ar-components

v5.4.16

Published

React components for Augmented Reality on the web.

Downloads

232

Readme

React AR Components

React components for Augmented Reality on the web.

Components

  • ModelViewer: used to interact with a 3D model on the browser (desktop)
  • WebXROverlay: DOM overlay used during a WebXR session (Chrome browser on mobile)

Methods

  • activateAR: tries to open a GLB model on SceneViewer or a USDZ model on quicklook
  • activateWebXR: tries to open a GLB model using WebXR, having activateAR as a fallback
ModelViewer

Attention: This component needs the importing of @google/model-viewer. We suggest it by adding the script to the page HTML, but it's also possible to add via NPM. Please refer to the model-viewer documentation

| param | description | default | | ----------------------------- | -------------------------------------------------------------------------- | ----------------- | | model-viewer default params | Please refer to model-viewer documentation | '' | | ref* | React RefObject to get/set properties of ModelViewer | undefined | | className | React ClassName, same as HTML class | undefined | | style | object containing custom CSS classes to customize this component | undefined | | children | React component to nest inside model-viewer | undefined | | componentDidMount | function to handle mount event | () => undefined | | onClick | function to handle click event | () => undefined | | pan | determines if the model will have pan interaction | true |

*: Prop required to make this wrapper work. Can be passed as follows:

<ModelViewer ref={React.createRef()} {...props} />
activateAR

| param | description | type | default | App | | ------------------ | -------------------------------------------- | ------------------------ | ----------------- | ----------- | | glb | url of the GLB file for Android devices | string | '' | SceneViewer | | usdz | url of the USDZ file for iOS devices | string | '' | QuickLook | | title | Display title of object on model card | string | undefined | SceneViewer | | shareText | String to display when sharing AR experience | string | undefined | Both | | sound | URL to play as sound when model is placed | string | undefined | SceneViewer | | link | Link to show on model card | string | undefined | SceneViewer | | scale | determines if model allows rescale | 'fixed' \| 'resizable' | 'fixed' | Both | | placement | determines the plane to render the model | 'floor' \| 'wall' | floor | SceneViewer | | disableOcclusion | SceneViewer object blending disabling | boolean | false | SceneViewer | | hashFallback | New window.location.hash when AR cannot load | string | #no-ar-fallback | SceneViewer |

activateWebXR

| param | description | type | default | | ------------------ | -------------------------------------------- | ------------------------ | ----------------- | | model.glb | Url of the model's GLB file | string | undefined | | model.name | Display title of object on model card | string | undefined | | model.description| Display text of object on model card | string | '' | | model.url | Link to show on model card | string | '' | | model.placement | Determines plane on which the model will be rendered | 'floor' \| 'wall' | undefined | | model.resizable | Determines if model allows rescale | boolean| undefined | | beforeClose | Function called before ending the experience* | (container: HTMLElement) => void | defaultBeforeClose | | callToAction | Enable CTA on AR experience | CallToAction | undefined |

*: If provided, beforeClose function MUST eventually dispatch the event r2u-webxr-close for the WebXR session to end properly.

Examples

activateAR
import React, { createRef } from 'react'
import ReactDOM from 'react-dom'

import '@google/model-viewer'

import { ModelViewer, activateAR } from '@r2u/react-ar-components'
import type { ModelViewerElement } from '@r2u/react-ar-components'

import style from './style.module.css'

const App: React.FC = () => {
  const usdz = 'http://localhost:8080/mesh_01000.usdz'
  const glb = 'http://localhost:8080/mesh_01000.glb'
  const imageUrl = 'https://via.placeholder.com/150'
  const viewerRef = createRef<ModelViewerElement>()

  return (
    <div>
      <div>
        <h1>AR</h1>
        <button type="button" onClick={() => activateAR({ glb, usdz })}>
          View in 3D
        </button>
      </div>
      <div>
        <h1>ModelViewer</h1>
        <ModelViewer
          ref={viewerRef}
          src={glb}
          alt="3D model"
          style={style}
          poster={imageUrl}
        />
      </div>
    </div>
  )
}

ReactDOM.render(<App />, document.getElementById('root'))
activateWebXR
import React from 'react'

import { activateWebXR } from '@r2u/react-ar-components'


const App: React.FC = () => {

  const model = {
    resizable: true,
    name: 'Chair',
    description: 'Comfy chair',
    glb:
      'http://localhost:8080/mesh_01000.glb',
    url: 'https://google.com',
    placement: 'floor',
  }

  return (
    <div>
      <h1>WebXR</h1>
      <button type="button" onClick={() => activateWebXR({ model })}>
        Floor
      </button>
    </div>
  )
}

ReactDOM.render(<App />, document.getElementById('root'))

Testing

make start
  • Access http://localhost:8080
  • Or expose local port if testing on another device or on mobile
    • Eg: npx localtunnel --port 8080
    • Access exposed link
  • Test banner.html

Analyze bundle size

React App build

yarn install
yarn build:app --analyze

Visit http://localhost:8888

SDK build

yarn install
yarn build:sdk --analyze

Visit http://localhost:8888