Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-3d-model-view

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-3d-model-view

React Native plugin for showing .obj, .dae and .scn models.

  • 1.1.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
46
increased by39.39%
Maintainers
1
Weekly downloads
 
Created
Source

react-native-3d-model-view

npm version npm downloads

A React Native view for displaying .obj, .dae and .scn models either on screen or in AR (iOS devices with A9 or later processors only).

Example Project: https://github.com/BonnierNews/react-native-3d-model-view/tree/master/example

Getting started

$ yarn add react-native-3d-model-view

and then

$ react-native link react-3d-model-view

The lib also have peer dependencies of react-native-zip-archive, react-native-fetch-blob and react-native-fs. Make sure that you yarn add and react-native link them to.

Usage

Model view

import ModelView from 'react-native-3d-model-view'

<ModelView
  source={{ zip: 'https://github.com/BonnierNews/react-native-3d-model-view/blob/master/example/obj/Hamburger.zip?raw=true' }}
  onLoadModelStart={this.onLoadModelStart}
  onLoadModelSuccess={this.onLoadModelSuccess}
  onLoadModelError={this.onLoadModelError} />

AR Model view

import ARModelView, { ModelTypes } from 'react-native-3d-model-view'

<ARModelView
  source={{ zip: 'https://github.com/BonnierNews/react-native-3d-model-view/blob/master/example/obj/Hamburger.zip?raw=true' }}
  onLoadModelStart={this.onLoadModelStart}
  onLoadModelSuccess={this.onLoadModelSuccess}
  onLoadModelError={this.onLoadModelError}
  onStart={this.onStart}
  onSurfaceFound={this.onSurfaceFound}
  onSurfaceLost={this.onSurfaceLost}
  onSessionInterupted={this.onSessionInterupted}
  onSessionInteruptedEnded={this.onSessionInteruptedEnded}
  onPlaceObjectSuccess={this.onPlaceObjectSuccess}
  onPlaceObjectError={this.onPlaceObjectError}
  onTrackingQualityInfo={this.onTrackingQualityInfo} />

Source

The source prop on both ModelView and ARView can either be a url to a server (e.g. http://example.com/yourmodel.obj) or a local path (use require). The source object can either consist of a zip prop or a model and a texture prop. Examples:

source={{
  zip: 'https://github.com/BonnierNews/react-native-3d-model-view/blob/master/example/obj/Hamburger.zip?raw=true'
}}

or

source={{
  zip: require('../obj/Hamburger.zip')
}}

or

source={{
  model: 'https://github.com/BonnierNews/react-native-3d-model-view/blob/master/example/obj/Hamburger.obj?raw=true',
  texture: 'https://github.com/BonnierNews/react-native-3d-model-view/blob/master/example/obj/Hamburger.png?raw=true'
}}

or

source={{
  model: require('../obj/Hamburger.obj'),
  texture: require('../obj/Hamburger.png')
}}

The lib will assume that the unzipped folder result will have the same name as the .zip (e.g. Hamburger.zip => Hamburger). This might not always be the case, then you can set the name of the unzipped folder:

source={{
  zip: 'https://github.com/BonnierNews/react-native-3d-model-view/blob/master/example/obj/Archive.zip?raw=true',
  unzippedFolderName: 'Hamburger'
}}

NOTE: File types

WaveFront (.obj) and Collada (.dae) is supported on both Android and iOS. SceneKit (.scn) is supported on iOS. Collada models with animations is autoplayed.

NOTE: Using require

To require .obj, .dae, .scn or .zip files you need to add a rn-cli.config.js to the root of your project with minimum this config:

module.exports = {
  getAssetExts: () => [ 'obj', 'dae', 'scn', 'zip' ]
}

See more in the example project.

NOTE: SceneKit compressed scenes

SceneKit and Collade files needs to be "SceneKit compressed scenes" on iOS. Compress with this shell command

$ /Applications/Xcode.app/Contents/Developer/usr/bin/scntool --convert InFile.dae --format c3d --output OutFile.dae --force-y-up --force-interleaved --look-for-pvrtc-image

More info: developer.apple.com and stackoverflow.com

Components

ModelView

View for displaying .obj, .dae or .scn (iOS only) on screen with SceneKit or OpenGL.

Props
PropTypeDefaultNote
sourceobjectnullCan either consist of a zip prop or a model and a texture prop. All three can either be a url string ("http://...") or you can use require to reference a local path. The .zip archive should contain both the object and the texture. Can also contain unzippedFolderName for setting the unzipped folder name (see more above).
scalenumber1Scale of the model.
autoPlaybooleantrueShould animated models play on mount.
Events
Event NameReturnsNotes
onLoadModelStartnullLoading model has started.
onLoadModelSuccessnullLoading model has succeeded.
onLoadModelErrorErrorFailed loading model.
onAnimationStartnullAnimated model has started animating.
onAnimationStopnullAnimated model has stopped animating.
onAnimationUpdateeventAnimated model animation update. Get progress from event.nativeEvent.progress
Methods

Use ref={modelView => {this.modelView = modelView}} to be able to call the methods listed below.

Method NameReturnsNotes
startAnimationnullStart playing animated model.
stopAnimationnullStops playing animated model.
setProgress(float)nullSet animation progress of animated model (allowed values: 0-1).

ARModelView

View for displaying .obj, .dae or .scn in augmented reality (iOS devices with A9 or later processors only).

Props
PropTypeDefaultNote
sourceobjectnullCan either consist of a zip prop or a model and a texture prop. All three can either be a url string ("http://...") or you can use require to reference a local path. The .zip archive should contain both the object and the texture. Can also contain unzippedFolderName for setting the unzipped folder name (see more above).
scalenumber1Scale of the model.
autoPlaybooleantrueShould animated models play on mount.
miniaturebooleanfalseShows the model in a miniature mode.
miniatureScalefloat0.2The scale of the model in miniature mode.
placeOpacityfloat0.2The opacity of the model when placing.
Events
Event NameReturnsNotes
onLoadModelStartnullLoading model has started.
onLoadModelSuccessnullLoading model has succeeded.
onLoadModelErrorErrorFailed loading model.
onAnimationStartnullAnimated model has started animating.
onAnimationStopnullAnimated model has stopped animating.
onAnimationUpdateeventAnimated model animation update. Get progress from event.nativeEvent.progress
onStartnull
onSurfaceFoundnull
onSurfaceLostnull
onSessionInteruptednull
onSessionInteruptedEndednull
onPlaceObjectSuccessnull
onPlaceObjectErrornull
onTrackingQualityInfo{id: number, presentation: string, recommendation: stringThe current info about the tracking quality.
onTapObjectnullCalled when tapped an object in the AR scene.
onTapViewnullCalled when tapped the screen but no object was hit by the tap.
Methods

Use ref={arView => {this.arView = arView}} to be able to call the methods listed below.

Method NameReturnsNotes
startAnimationnullStart playing animated model.
stopAnimationnullStops playing animated model.
setProgress(float)nullSet animation progress of animated model (allowed values: 0-1).
restartnullRestarts the ARKit session.
getSnapshot(boolean)PromiseSave a print screen of the current AR session. Boolean determines if the image should be saved to the Photo Library of the device. The promise return the url of the saved image.

Native modules

Manager

Manager for common actions needed for the ModelView.

Method NameReturnsNotes
clearDownloadedFilesnullRemoves all downloaded model assets from the device. Should be called when exiting the app

ARManager

Manager for common actions needed for the ARModelView.

Method NameReturnsNotes
clearDownloadedFilesnullRemoves all downloaded model assets from the device. Should be called when exiting the app
checkIfARSupported(callback)nullCheck if ARKit is supported on the current device. Callback params is a boolean saying if it is supported or not.

Contributing

If you find a bug or would like to request a new feature, just open an issue. You are also welcome to submit pull requests and contribute to the project.

Thanks

License

The MIT License (MIT)

Copyright (c) 2017 Johan Kasperi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Package last updated on 23 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc