HomeGuidesAPI ReferenceChangelogDiscussions
Hire a ReactVision Expert 🛠️Launch Studio 🖥️Sponsor on GitHub ❤️Log In
Guides

ViroCamera

A stationary look around camera through which the user views the world. More than 1 camera may be placed within a scene.

Web, 3.2.3+: releasing the camera returns to the default camera, never to an earlier one. Camera reads and drag work under a perspective ViroCamera in a 3D scene. Under an orthographic projection in a 3D scene they are a known web limitation: the web cannot work out the camera's pose there.

Web, 3.3.0+: camera reads and drag also work while the camera is the point of view in live AR. As on native, the scene is drawn from the camera node's position with the device's rotation on top, and that is the pose reads report. In 3.2.3 they did not work there. fieldOfView applies on web from 3.3.0 (see below).

📷

Where the camera sits no longer matters (3.0.3+). On React Native 0.86, a ViroCamera mounted between its siblings (not as the last child), remounted with a new key, or rendered conditionally mid-scene could leave the scene on its default camera, drawing with the wrong projection and orthographicScale. From 3.0.3, ViroScene and ViroARScene attach the active camera wherever it sits in the tree, including one that mounts later. When the active camera stops being active or unmounts, the scene returns to its default camera. On iOS, run pod install and rebuild to pick this up.

Example use:
<ViroCamera
  position={[0, 0, 0]}
  rotation={[45, 0, 0]}
  active={true} 
/>

Props

active (* required)

TypeDescription
booleanIf true, sets the corresponding camera as the active one from which we render the world. Setting more than one active camera within a scene will result in undefined behavior.

animation

type ViroAnimation = {
  name: string,
  delay: number,
  loop: boolean,
  onStart: Function,
  onFinish: Function,
  run: boolean,
}
TypeDescription
ViroAnimationA collection of parameters that determine if this component should animate. For more information on animated components please see our Animation Guide.

fieldOfView

TypeDescription
numberSet the field of view for this camera, along the major (larger) axis. Field of view is an angle that determines how wide or narrow the camera lens is when rendering the scene.This value sets the field of view, in degrees, for the major axis. The major axis is the axis with the larger dimension: the X axis in landscape mode, or the Y axis in portrait mode. By specifying the field of view in terms of the major axis, Viro can keep the field of view consistent upon orientation changes, when the major/minor axes swap. The minor axis field of view is automatically computed from the major axis field of view and the viewport.This value is ignored on VR and AR platforms, where the FOV is fixed by the VR headset or the AR camera. Else, in non-VR (360 mode) the FOV defaults to 90.

Web, 3.3.0+: works in 3D scenes, across the viewport's longer side, as on native. In AR the device camera's field of view applies. Needs @reactvision/viro-web-renderer 1.4.0; on 1.3.0 the default is kept.

position

TypeDescription
[number, number, number]Cartesian position of the camera in 3D world space, specified as [x, y, z].

rotation

TypeDescription
[number, number, number]Cartesian rotation of the camera in 3D world space, specified as [x, y, z].

Methods

setNativeProps(nativeProps)

A wrapper function around the native component's setNativeProps which allow users to set values on the native component without changing state/setting props and re-rendering. Refer to the React Native documentation on Direct Manipulation for more information.

ParameterTypeDescription
nativePropsobjectan object where the keys are the properties to set and the values are the values to set
componentRef.setNativeProps({ position: [0, 0, -1] });