5.4.16 • Published 15 days ago

@r2u/react-ar-components v5.4.16

Weekly downloads
191
License
SEE LICENSE IN LI...
Repository
github
Last release
15 days ago

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

paramdescriptiondefault
model-viewer default paramsPlease refer to model-viewer documentation''
ref*React RefObject to get/set properties of ModelViewerundefined
classNameReact ClassName, same as HTML classundefined
styleobject containing custom CSS classes to customize this componentundefined
childrenReact component to nest inside model-viewerundefined
componentDidMountfunction to handle mount event() => undefined
onClickfunction to handle click event() => undefined
pandetermines if the model will have pan interactiontrue

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

<ModelViewer ref={React.createRef()} {...props} />
activateAR
paramdescriptiontypedefaultApp
glburl of the GLB file for Android devicesstring''SceneViewer
usdzurl of the USDZ file for iOS devicesstring''QuickLook
titleDisplay title of object on model cardstringundefinedSceneViewer
shareTextString to display when sharing AR experiencestringundefinedBoth
soundURL to play as sound when model is placedstringundefinedSceneViewer
linkLink to show on model cardstringundefinedSceneViewer
scaledetermines if model allows rescale'fixed' \| 'resizable''fixed'Both
placementdetermines the plane to render the model'floor' \| 'wall'floorSceneViewer
disableOcclusionSceneViewer object blending disablingbooleanfalseSceneViewer
hashFallbackNew window.location.hash when AR cannot loadstring#no-ar-fallbackSceneViewer
activateWebXR
paramdescriptiontypedefault
model.glbUrl of the model's GLB filestringundefined
model.nameDisplay title of object on model cardstringundefined
model.descriptionDisplay text of object on model cardstring''
model.urlLink to show on model cardstring''
model.placementDetermines plane on which the model will be rendered'floor' \| 'wall'undefined
model.resizableDetermines if model allows rescalebooleanundefined
beforeCloseFunction called before ending the experience*(container: HTMLElement) => voiddefaultBeforeClose
callToActionEnable CTA on AR experienceCallToActionundefined

*: 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

5.4.16

15 days ago

5.4.15

1 year ago

5.4.14

2 years ago

5.4.13

2 years ago

5.4.12

2 years ago

5.4.11

2 years ago

5.4.9

2 years ago

5.4.10

2 years ago

5.4.8

3 years ago

5.4.7

3 years ago

5.4.6

3 years ago

5.4.5

3 years ago

5.4.4

3 years ago

5.4.3

3 years ago

5.4.2

3 years ago

5.4.1

3 years ago

5.4.0

3 years ago

5.3.1

3 years ago

5.3.0

3 years ago

5.2.5

3 years ago

5.2.4

3 years ago

5.2.3

3 years ago

5.2.2

3 years ago

5.2.1

3 years ago

5.1.2

3 years ago

5.2.0

3 years ago

5.1.1

3 years ago

5.1.0

3 years ago

5.0.5

3 years ago

5.0.4

3 years ago

5.0.3

3 years ago

5.0.2

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

4.15.1

3 years ago

4.15.0

3 years ago

4.14.0

3 years ago

4.12.0

3 years ago

4.13.0

3 years ago

4.11.0

3 years ago

4.10.0

3 years ago

4.9.4

3 years ago

4.9.5

3 years ago

4.9.3

3 years ago

4.9.2

3 years ago

4.9.1

3 years ago

4.9.0

3 years ago

4.8.12

3 years ago

4.8.11

3 years ago

4.8.10

3 years ago

4.8.9

3 years ago

4.8.8

3 years ago

4.8.7

3 years ago

4.8.6

3 years ago

4.8.5

3 years ago

4.8.3

3 years ago

4.8.2

3 years ago

4.8.1

3 years ago

4.8.0

3 years ago

4.7.0

3 years ago

4.6.0

3 years ago

4.5.0

4 years ago

4.5.1

4 years ago

4.4.3

4 years ago

4.4.2

4 years ago

4.4.1

4 years ago