Viro3DSceneNavigator
Viro3DSceneNavigator is the entry point for applications that want to render a 3D Scene (<ViroScene>) in a non AR/VR fashion. Please see the Scene Navigation Guide for more information on how to properly navigate between scenes.
Example use:
import React from 'react';
import { Viro3DSceneNavigator } from '@reactvision/react-viro';
import MyScene from './MyScene';
function ViroSceneNav() {
return (
<Viro3DSceneNavigator
initialScene={{ scene: MyStartScene }}
/>
);
}
Props
initialScene (* required)
| Type | Description |
|---|---|
| { scene: React.Component } | The initial scene to display for your application on application start. |
bloomEnabled
| Type | Description |
|---|---|
| boolean | Enable or disable bloom. Bloom adds a soft glow to bright areas in scene, simulating the way bright highlights appear to the human eye. To make an object bloom, this property must be enabled, and the objects's threshold for bloom must be set via its material's bloomThreshold property. |
debug
| Type | Description |
|---|---|
| boolean | Used to enable the Dev menu on Android Nougat devices with Cardboard. |
hdrEnabled
| Type | Description |
|---|---|
| boolean | When HDR rendering is enabled, Viro uses a deeper color space and renders to a floating point texture, then applies a tone-mapping algorithm to preserve fine details in both bright and dark regions of the scene. If HDR is disabled, then features like Bloom and PBR will not work, and tone-mapping will be disabled. HDR is not supported on all devices. |
onExitViro
| Type | Description |
|---|---|
| Function | Called if the user presses the "X" button to exit. |
pbrEnabled
| Type | Description |
|---|---|
| boolean | Enable or disable physically-based rendering. Physically based rendering, or PBR, produces more realistic lighting results for your scenes, and provides a more intuitive workflow for artists. To use PBR, this property must be enabled, and materials must use the physicallyBased lighting model. PBR is controlled by a variety of properties, see PBR for details. |
shadowsEnabled
| Type | Description |
|---|---|
| boolean | Enable or disable rendering dynamic shadows. If shadows are disabled here, shadow casting lights will simply not cast a shadow. |
viroAppProps
| Type | Description |
|---|---|
| Object | A Javascript object containing properties for this Viro app. This can be used to pass in properties from native if you're using a hybrid application. |
virtualCamera (web, 3.3.0+)
| Type | Description |
|---|---|
boolean | { target?: [number, number, number]; orbitCenter?: () => [number, number, number] | null; fieldOfView?: number; onReady?: (controls) => void } | Web only, opt-in. Lets the viewer move the point of view with the mouse, two fingers or the keys: right-drag turns the view in place, Alt with right-drag orbits, middle drag or Shift with left drag pans, the wheel or a pinch zooms, and once a click has given the view focus, W A S D or the arrow keys walk, E and Q move up and down, and Shift runs. A primary click or a single finger still reaches the scene. It drives a camera node of its own, which stands aside while the scene makes one of its own ViroCameras active. target is the point it starts looking at (default [0, 0, -1]), fieldOfView is degrees across the longer side (default 90, the renderer's), and onReady receives reset(), lookFrom(position, target), pose() and setFieldOfView(degrees). Also on ViroSceneNavigator. See ViroARSceneNavigator → virtualCamera. |
onWebRendererError (web, 3.3.0+)
| Type | Description |
|---|---|
(error: unknown) => void | Web only. Called when the renderer cannot start. With @reactvision/viro-web-renderer 1.4.0 the error is a ViroWebGLUnavailableError whose reason is "unsupported" (no WebGL2) or "context-lost". The navigator also shows a message over the canvas instead of leaving it blank. ViroVRSceneNavigator passes it through. |
Methods
The following functions are available on the Viro3DSceneNavigator component. You can get the handle to the Viro3DSceneNavigator in 2 ways:
- Use the built-in React Native
refproperty to grab a reference - From your
ViroScene. EachViroSceneadded to aViro3DSceneNavigatorprovides its parent navigator in the variable:this.props.sceneNavigator.
Web, 3.2.2+: push, pop, pop(n), jump and replace work on web, and initialScene takes passProps. Only the top scene of the stack is mounted: native keeps the others, but nothing on web can show them while they are covered. They used to warn and do nothing. A lost WebGL context recovers by mounting the scene again on a new renderer.
Web, 3.2.3+: project, unproject, takeScreenshot, startVideoRecording and stopVideoRecording work, and the ref exposes sceneNavigator. Capture behaviour is the same as on ViroARSceneNavigator: saveToCameraRoll downloads the file, url is an object URL, and video carries no audio, which is a current limitation: web records the canvas only, because recording the microphone would need a separate browser permission prompt. No follow-up is planned yet. recenterTracking is present but does nothing, because there is no headset.
push({ scene: ViroARScene, passProps: Object })
Push the given scene onto scene stack, displaying the scene to the user
| Argument | Type | Description |
|---|---|---|
| scene | ViroScene | Scene that will be pushed onto the stack and displayed to the user |
| passProps | Object | Props to pass to the rendered scene |
pop()
Pop the top most scene of the stack, effectively going back to the previous scene.
pop(n: number)
Go back n scenes at once. If n is equal to 1 this is equivalent to calling pop().
jump({ scene: ViroARScene, passProps: Object })
Move to the given scene in the stack, removing it from its current position in the stack and placing it on top, thereby displaying it to the user. If the scene is not already on the stack, this method pushes the scene to the top of the stack, displaying it to the user. This is best used in applications where the user jumps between a set of scenes frequently.
| Argument | Type | Description |
|---|---|---|
| scene | ViroScene | Scene that will be moved or pushed to the top of the stack and displayed to the user |
| passProps | Object | Props to pass to the rendered scene |
replace({ scene: ViroARScene, passProps: Object })
Replace the currently displayed scene (the scene at the top of the stack) with the given scene, displaying it to the user. This leaves the remainder of the stack unchanged.
| Argument | Type | Description |
|---|---|---|
| scene | ViroScene | Scene that will replace the scene at the top of stack and be displayed to the user |
| passProps | Object | Props to pass to the rendered scene |
recenterTracking()
Reorients the virtual world such that directly forward of the user is [0, 0, -1] by rotating the scene by the user's y-rotation.
Web, 3.2.3+: the method is present but does nothing, because there is no headset to re-zero.
async project(point: array)
Takes a 3D world position and returns { screenPosition }, a 2D vector in the navigator's pixels. See ViroARSceneNavigator → project. Web, 3.2.3+: works.
async unproject(point: array)
Takes a screen position plus a 0–1 depth and returns { position } in world space. See ViroARSceneNavigator → unproject. Web, 3.2.3+: works, with the same known limitation: the far plane is fixed at 50 m, so unproject depth is off in scenes that reach past that.
async takeScreenshot(fileName: string, saveToCameraRoll: bool)
Takes a screenshot of the navigator. See ViroARSceneNavigator → takeScreenshot. Web, 3.2.3+: works; saveToCameraRoll downloads the file.
startVideoRecording(fileName: string, saveToCameraRoll: bool, onError: func)
Starts a recording of the navigator. See ViroARSceneNavigator → startVideoRecording. Web, 3.2.3+: works; video carries no audio, which is a current limitation (canvas only; recording the microphone would need a separate browser permission prompt). No follow-up is planned yet.
async stopVideoRecording()
Stops the recording and returns { success, url, errorCode }.
Updated 3 days ago