This is an experimental project that wraps native 3D APIs with react native components to build mobile VR experiences for react native. It is intended to run on an iPhone with a head mounted case such as Google Cardboard
- Currently iOS only (depends on the SceneKit framework)
NOTE This project is incomplete, and highly experimental.
-
clone the project
-
install dependencies
yarn install
-
Run
yarn run ios
to try it in the simulator
The simulator allows you to mouse drag on the view to simulate head movement.
- open
ios/reactnativevr.xcodeproj
and select your usb connected iOS device to run on. For more details on how to do this follow this tutorial starting at Step 3.
In the examples
directory there are some basic scenes that demonstrate the library.
Demonstrates creating and positioning geometry, adding textures, and adding simple animations.
Demonstrates a VR menu that links to 360 degree videos.
The root view of a VR scene. All other components should be nested inside the VR view. This view can be positioned with flexbox like any other react native view.
Whether or not to show the interactivity pointer. Default is false.
Whether or not to show the developer bar at the bottom of the VR view. Currently this only has a single button which will allow you to turn on the camera of the iOS device so you can see the real world while in VR. (currently only works with a real device not the simulator)
Groups a set of components and controls their positioning, rotation, and scale
Position of the group in 3D space. Any axis can be left out and will be defaulted to 0. Example:
<Group position={{x: 1}} />`
<Group position={{x: 1, y: 1, z: -1}} />
Rotation of the group around the x, y and z axes. Values should be specified as a number in degrees. Any axis can be left out and will be defaulted to 0. Example:
<Group rotation={{ x: 180 }} />
<Group rotation={{ y: -180, z: 45 }} />
Scale of the group in each of the x, y and z axes. Can be an object of each axis or a number that should apply to all axes. Any axis can be left out and will be defaulted to 1. Example:
<Group scale={{ x: 2 }} />
// scales "2" in the x axis and "1" in the y and z axes
<Group scale={4} />
// scales the group by 4 in three axes
Shapes include all geometry and text components. Each shape has it's own specific props but they all share some set of common props.
The shape components include
Box
Sphere
Plane
Floor
Text
Shape components also accept all the properties for <Group />
.
position
rotation
scale
...as well as the following:
URL for the texture to apply to the shape
Determines the cullMode for the shape texture rendering. (see SceneKit docs)
Determines if the texture for the shape should be rendered on both the front and back surfaces of a shape, or the inside and the outside of a closed shape. (see SceneKit docs)
Color of the shape
When the is enabled, and the user points at a shape, a progress bar on the pointer starts to fill. After it fills, this callback is triggered.
A shape component. Accepts all the shape properties as well as
length: number
width: number
height: number
A shape component. Accepts all the shape properties as well as
radius: number
A shape component that renders a 2d plane. Accepts all the shape properties as well as
width: number
height: number
A shape component that renders a 2d plane that extends infinitely. Accepts all the shape properties as well as
reflectivity: number
between 0 and 1
A shape component that render 2d text. Accepts all the shape properties as well as
value: string
String for the textfontSize: number
Size of the texttruncation: string(none|left|right|middle)
alignment: string(natural|left|right|center|justified)
A clip from the original demonstration at Instacart HQ. Sorry the video is not longer, this is all that survived.