import { CAMERA_VIEWS, CameraRig, FitCamera, FollowCamera } from "@apricotjs/react-native";
import type { CameraRigHandle, CameraView, FollowOptions, Inset, OrbitOptions } from "@apricotjs/react-native";One camera controller per scene. Without one, the camera stays where <Scene camera> put it. All angles on this page are in degrees except where noted.
FitCamera#
Keeps a flat area fully in view at any screen size. It moves the camera along its line of sight until size fits, and again after every resize. Use it for cards, single objects and hero screens.
| Prop | Type | Default | Description |
|---|---|---|---|
size |
[width, height] |
required | The area to keep on screen, facing the camera, in units |
margin |
number | 0.1 |
Space around it, as a fraction |
target |
Vec3 |
[0, 0, 0] |
The point looked at |
The camera keeps the direction and fov it was given in <Scene camera>.
CameraRig#
Places the camera on an orbit around a subject and flies between views along arcs. Put it inside the object to frame (a <Model>, <Group> or shape). Without a distance, it backs off until the subject fits the free part of the screen.
| Prop | Type | Default | Description |
|---|---|---|---|
view |
string | CameraView |
"three-quarter" |
A built-in name, a name from views, or a view object. Changing it flies there |
views |
Record<string, CameraView> |
Your own named views | |
transition |
seconds | 0.9 |
How long a change of view, inset or framed subject takes. A new src on the parent <Model> counts as a new subject. 0 cuts |
inset |
Inset |
none | Points covered by UI on each side. The subject is framed in the rest |
margin |
number | 0.1 |
Extra room around the subject, as a fraction |
subject |
Object3D | null |
the parent | What to frame. A ref's object works: subject={room} with <Group ref={setRoom}>. shadowOnly objects are left out. null frames nothing, so views need a distance and usually a target |
follow |
ref or Object3D | null |
A moving object the orbit's centre eases after (a train, a runner) | |
followStiffness |
number | 3 |
How tightly it follows, per second |
drift |
degrees per second | 0 |
Slowly circles the subject. Pauses while a finger is on the scene |
sway |
boolean | { degrees?, period? } |
false |
Swings slowly back and forth round the view instead of circling. degrees either way (default 12), period in seconds there and back (default 12). Stops while a finger turns the camera, then swings on from there |
fit |
"box" | "footprint" | { footprint: object } | [width, height, depth] |
"box" |
What is fitted in frame. See fit |
keepDistance |
boolean |
false |
Keeps the distance fitted for the first view for later ones, so changing view doesn't zoom |
orbit |
boolean | OrbitOptions |
false |
Drag to turn, pinch to zoom (wheel on the web). Taps still work |
onOrbitStart |
() => void |
A finger went down on the scene. Use it to stop a ScrollView scrolling on iOS |
|
onTurnStart |
() => void |
The fingers moved further than a tap, or pinched | |
onOrbitEnd |
({ moved }) => void |
All fingers lifted. moved is how far they moved, in points |
|
ref |
Ref<CameraRigHandle> |
flyTo and jumpTo |
fit#
| Value | Fits in frame |
|---|---|
"box" |
The subject's whole box |
"footprint" |
The subject's floor plan only. A room with tall walls frames at the same scale as a flat island of the same size |
{ footprint: object } |
That object's floor plan, such as an island's tile. Palm fronds reaching past it don't make it frame smaller |
[width, height, depth] |
A box of that size where the subject stands, so different subjects frame at one scale |
Pass objects themselves (kept in state from a ref callback), not refs.
CameraView#
| Field | Type | Description |
|---|---|---|
azimuth |
degrees | Around the vertical axis. 0 is in front (+z), 90 on the left (+x) |
elevation |
degrees | Above the horizon. 90 looks straight down |
distance |
units | From the target. Default: fit the subject |
target |
Vec3 |
The point looked at. Default: the subject's centre, the followed object, or else where the camera looks now |
position |
Vec3 |
Places the camera exactly instead of using angles |
fov |
degrees | Field of view for this view |
CAMERA_VIEWS#
| Name | Azimuth | Elevation |
|---|---|---|
front |
0 | 8 |
back |
180 | 8 |
left |
90 | 8 |
right |
−90 | 8 |
top |
0 | 90 |
three-quarter |
35 | 16 |
OrbitOptions#
| Field | Type | Default | Description |
|---|---|---|---|
turn |
degrees | all the way round | How far the camera may turn either way from the view's azimuth |
azimuth |
[from, to] degrees |
none | Fixed limits whatever the view: [-76, 4] keeps the back of a cut-away room out of sight. With turn too, it stays within both |
elevation |
[lowest, highest] degrees |
[0, 85] |
Limits above the horizon. The default keeps the camera above the floor |
zoom |
[nearest, farthest] | false |
[0.5, 2] |
Fractions of the view's distance. false turns pinch off |
speed |
number | 1 |
1 turns 180° for a drag across the whole canvas |
inertia |
boolean | true |
Keeps turning after a flick, slowing down |
returnAfter |
seconds | none (stays) | Flies back to the view this long after the last touch |
Inset#
{ top?, bottom?, left?, right? } in points.
CameraRigHandle#
| Method | Description |
|---|---|
flyTo(view, seconds?) |
Flies to a view (name or object) over seconds (default: transition) |
jumpTo(view) |
Puts the camera at a view at once |
Setting view to the value it already has does nothing. Use flyTo to return after the user orbited.
For distant views the rig widens the camera's far plane to five times the distance. It never narrows it.
FollowCamera#
A chase camera behind and above a target. It eases after the target and looks a little ahead. It is made for <Vehicle> and ignores the target's pitch. Options are read once, at mount. Place it after the target in the tree.
| Prop | Type | Default | Description |
|---|---|---|---|
target |
RefObject<SceneObject | null> |
required | The object to chase, such as a <Vehicle ref> |
distance |
units | 6 |
Behind the target |
height |
units | 2.6 |
Above the target |
lookAhead |
[ahead, up] |
[3, 0.6] |
The point looked at, relative to the target |
stiffness |
per second | 4 |
How quickly it catches up; higher is stiffer |