ViroCameraTexture

Binds a live device camera feed to a material's texture so any geometry can display a real-time camera view. New in v2.56.0.

ViroCameraTexture binds a live device camera feed to a named material's diffuse texture, allowing any geometry to display a real-time camera view (mirror surfaces, picture-in-picture, VR selfie). Unlike frontCameraEnabled on ViroARSceneNavigator — which replaces the full-screen AR background — ViroCameraTexture keeps back-camera AR tracking active while painting the camera feed onto a surface.

Import

import { ViroCameraTexture } from "@reactvision/react-viro";

Props

material

TypeDescription
stringName of a material (created via ViroMaterials.createMaterials) whose diffuse texture will be bound to the live camera feed. Typically use the "Constant" lighting model.

cameraPosition

TypeDescription
"front" | "back"Which device camera to bind to the texture.

paused

TypeDescription
booleanPause/resume the camera feed.

onCameraReady

TypeDescription
() => voidFired when the camera feed is ready and bound to the material.

A ref may be attached to the component (see example).

Example

import {
  ViroMaterials,
  ViroQuad,
  ViroCameraTexture,
} from "@reactvision/react-viro";

ViroMaterials.createMaterials({
  mirrorMat: { lightingModel: "Constant" },
});

function MirrorScene() {
  const cameraRef = useRef(null);

  return (
    <ViroARScene>
      <ViroCameraTexture
        ref={cameraRef}
        material="mirrorMat"
        cameraPosition="front"
        paused={false}
        onCameraReady={() => console.log("Camera ready")}
      />
      <ViroQuad
        width={0.54}
        height={0.96}
        position={[0, 0, -1]}
        materials={["mirrorMat"]}
      />
    </ViroARScene>
  );
}

Key differences vs frontCameraEnabled

frontCameraEnabledViroCameraTexture
Camera feedAR session background (full screen)Material texture on any geometry
AR trackingWorld-locked (gravity)Back camera AR still active
Typical useSelfie AR, face effectsMirror surfaces, picture-in-picture, VR selfie
PlatformiOS + AndroidiOS + Android

Platform Support

PlatformSupported
iOS
Android

See also

  • ViroARSceneNavigatorfrontCameraEnabled for full-screen front-camera AR.