0.1.17 • Published 1 year ago

react-native-ar-viewer v0.1.17

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

react-native-ar-viewer

npm version

AR viewer for react native that uses Sceneform on Android and ARKit on iOS

Installation

npm install react-native-ar-viewer

Android

Required AR features:

  • Add the following to your AndroidManifest.xml:
<meta-data android:name="com.google.ar.core" android:value="required" tools:replace="android:value" />
  • If you already have <meta-data android:name="com.google.ar.core" android:value="required" /> don't forget to add the tools:replace="android:value" attribute.

  • Check that your <manifest> tag contains xmlns:tools="http://schemas.android.com/tools" attribute.

iOS

  • Remember to add NSCameraUsageDescription entry in your Info.plist with a text explaining why you request camera permission.

  • In XCode file tree, go to Pods > Development pods > react-native-ar-viewer, right-click on "Add Files to Pods"... Then select the environment.skybox folder in your node_modules/react-native-ar-viewer/ios folder. In add file window, check "react-native-ar-viewer-ARViewerBundle". It should appear with a blue icon on the file tree. Check if res.hdr is present inside, if not, add it manually. It should look like that: npm.io

File formats

The viewer only supports USDZ files for iOS and GLB for Android. Other formats may work, but are not officialy supported.

Usage

You should download your model locally using for example React Native File System in order to run the viewer on iOS. Android supports natively file URL (https:// instead of file://)

import { ArViewerView } from "react-native-ar-viewer";
import { Platform } from 'react-native';
// ...

<ArViewerView 
    style={{flex: 1}}
    model={Platform.OS === 'android' ? 'dice.glb' : 'dice.usdz'}
    lightEstimation
    manageDepth
    allowRotate
    allowScale
    allowTranslate
    disableInstantPlacement
    onStarted={() => console.log('started')}
    onEnded={() => console.log('ended')}
    onModelPlaced={() => console.log('model displayed')}
    onModelRemoved={() => console.log('model not visible anymore')}
    planeOrientation="both" />

Props

PropTypeDescriptionRequired
modelstringEnables ambient light estimation (see below)Yes
lightEstimationboolEnables ambient light estimation (see below)No
manageDepthboolEnables depth estimation and occlusion (only iOS, see below)No
allowRotateboolAllows to rotate modelNo
allowScaleboolAllows to scale modelNo
allowTranslateboolAllows to translate modelNo
disableInstructionsboolDisables instructions viewNo
disableInstantPlacementboolDisables placement on loadNo
planeOrientation"horizontal", "vertical", "both" or "none"Sets plane orientation (default: both)No

lightEstimation:

WithWithout
npm.ionpm.io

manageDepth:

WithWithout
npm.ionpm.io

Others:

allowRotateallowScaleplaneOrientation: both
npm.ionpm.ionpm.io

Events

PropParameterDescription
onStartednoneTriggers on AR session started
onEndednoneTriggers on AR session ended
onModelPlacednoneTriggers when model is placed
onModelRemovednoneTriggers when model is removed
onError{ message: string }Triggers on any error and returns an object containing the error message

Commands

Commands are sent using refs like the following example:

  // ...
  const ref = React.useRef() as React.MutableRefObject<ArViewerView>;
  
  const reset = () => {
    ref.current?.reset();
  };
  
  return (
    <ArViewerView
      model={yourModel}
      ref={ref} />
  );
  // ...
CommandArgsReturnDescription
reset()nonevoidRemoves model from plane
rotate()x, y, zvoidManually rotates the model using yaw as x, pitch as y and roll as z in degrees
takeScreenshot()nonePromise<String>Takes a screenshot of the current view (camera + model) and returns a base64 jpeg string as a promise

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

0.1.17

1 year ago

0.1.16

1 year ago

0.1.15

2 years ago

0.1.14

2 years ago

0.1.13

2 years ago

0.1.12

2 years ago

0.1.11

2 years ago

0.1.10

2 years ago

0.1.9

2 years ago