import {
AmbientLight, DAY, Daylight, MOONLIT, defineEnvironment, DirectionalLight, Environment, HemisphereLight, Lamp, LightBeam,
PointLight, SpotLight, useDaylight, WindowPane,
} from "@apricotjs/react-native";
import type { DaylightKey, DaylightNow, StudioOptions } from "@apricotjs/react-native";Light components add to the scene's look. With look="none" they are the only lights. intensity, position and target accept plain or shared values, so lights can move and dim every frame.
Lights#
| Component | Light |
|---|---|
AmbientLight |
From everywhere, with no shading. Lifts shadows evenly |
HemisphereLight |
One colour from above, another bounced from below. Soft outdoor light |
DirectionalLight |
Sunlight: parallel rays from position towards target |
PointLight |
A bulb: light in every direction from position |
SpotLight |
A cone of light from position towards target |
| Prop | Type | Default | Description |
|---|---|---|---|
color |
colour | "#ffffff" |
Colour of the light. HemisphereLight uses sky instead |
intensity |
number or shared value |
1 |
Brightness |
sky |
colour | "#ffffff" |
HemisphereLight: the colour from above |
ground |
colour | "#8a7a6a" |
HemisphereLight: the colour from below |
position |
Vec3 or shared value |
[3, 5, 4] directional, [0, 2, 0] point, [0, 4, 2] spot |
Where the light is |
target |
Vec3 or shared value |
[0, 0, 0] |
DirectionalLight, SpotLight: the point it shines towards |
castShadow |
boolean | automatic | DirectionalLight: true makes it the light that casts shadows, false never |
distance |
number | 0 (no limit) |
PointLight, SpotLight: how far it reaches. At 0 it fades with distance |
angle |
radians | 0.5 |
SpotLight: half-angle of the cone |
penumbra |
0–1 | 0.3 |
SpotLight: softness of the cone's edge |
ref |
Ref<SceneObject> |
The three.js light |
In a scene with shadows, the brightest directional light casts them unless one has castShadow.
Lamp#
A light that comes from a thing: a table lamp's bulb, a candle, a screen. It moves with what holds it, so put it inside a <Placeable> or a <Group> with the lamp's model. It fades on and off and can glow. Lamps cast no shadows.
<Scene lamps> sets how many lamps light the scene at once. The default is 0, so lamps only glow until you set it. When more lamps are on than that, the brightest light the scene and the others only glow.
| Prop | Type | Default | Description |
|---|---|---|---|
position |
Vec3 |
[0, 0, 0] |
Where the bulb is, in its parent's space |
on |
boolean | "dark" |
true |
"dark": on as it gets dark, with the scene's <Daylight> (always on without one) |
transition |
seconds | 0.6 |
How long it takes to come on or go off |
color |
colour | "#ffc98a" (a warm bulb) |
Colour of the light |
intensity |
candela | 1.5 |
Brightness when on |
distance |
metres | 3 |
How far it reaches |
glow |
metres | 0 (none) |
Radius of a soft glow round the bulb while it is on |
ref |
Ref<SceneObject> |
The lamp's object |
LightBeam#
A beam of light through dusty air: sunlight slanting in through a window, a spotlight's cone on a stage. It is a soft, see-through volume, brightest where the light comes in and fading along its length and at its edges.
| Prop | Type | Default | Description |
|---|---|---|---|
from |
Vec3 |
required | The middle of where the light comes in (the window) |
size |
[width, height] |
required | The opening, in metres. The beam keeps its shape |
to |
Vec3 |
The middle of where it lands: its length and slant. Not needed with sun |
|
facing |
Vec3 |
level, towards to |
The way the opening faces into the room. A window in a wall facing −x is [-1, 0, 0] |
sun |
boolean |
false |
Follows <Daylight>: along the sun's (or moon's) rays, in its colour, as bright as it is, and only while it shines on the opening's side |
bounds |
[minX, minZ, maxX, maxZ] |
the floor only | With sun: the walls the light may land on |
floor |
metres | 0 |
With sun: the floor's height |
color |
colour | a warm sunlight | Colour of the light |
intensity |
number | 1 |
Brightness at its start (with sun, at the sun's brightest) |
reach |
0–1 | 1 |
How far along it the light lasts before fading out |
ref |
Ref<SceneObject> |
The beam's object |
The beam lights only the air. For the bright patch on the floor, a light must really shine that way (<Daylight>'s sun or a <DirectionalLight> through the window), with shadows so walls block it elsewhere.
WindowPane#
The glass of a window seen from inside: bright with the day outside, deep blue at night, following <Daylight> (always day without one). It casts no shadow.
| Prop | Type | Default | Description |
|---|---|---|---|
size |
[width, height] |
required | The glass, in metres. It is a centimetre thick along its own z: rotate it into the wall |
day |
colour | "#ffdca3" |
How it glows by day |
night |
colour | "#2b3566" |
How it looks at night |
position |
Vec3 or shared value |
[0, 0, 0] |
Where the middle of the glass is |
rotation |
Vec3 or shared value |
[0, 0, 0] |
Euler angles in radians |
ref |
Ref<SceneObject> |
The glass |
Environment#
Sets what metals and glossy materials reflect, while mounted. A change of name, sky or boxes fades between environments. rotation, intensity and the boxes can change every frame.
| Prop | Type | Default | Description |
|---|---|---|---|
name |
string |
"studio", "soft", "sunset", "night", or a name from defineEnvironment |
|
sky |
[ceiling, horizon, floor] colours |
Instead of name: the gradient of your own studio |
|
boxes |
SoftBox[] |
Instead of name: the soft boxes of your own studio |
|
intensity |
number or shared value |
1 |
Brightness multiplier |
rotation |
number or shared value (radians) |
0 |
Turns the studio around the vertical axis |
transition |
seconds | 0.6 |
How long a change of name, sky or boxes fades. 0 is instant |
<Scene environment="…"> sets the starting environment; <Environment> changes it later.
<Environment name={night ? "night" : "studio"} rotation={swipeAngle} />defineEnvironment(name, options: StudioOptions)#
Registers a studio by name.
StudioOptions field |
Type | Description |
|---|---|---|
sky |
[ceiling, horizon, floor] colours |
The gradient around the object |
boxes |
SoftBox[] |
The highlights. Studios of up to six switch instantly; a studio with more takes a moment to set up |
intensity |
number | Overall brightness (default 1) |
SoftBox field |
Type | Description |
|---|---|---|
direction |
[x, y, z] |
From the object towards the box, world space. +z is towards the default camera |
size |
[halfWidth, halfHeight] |
In radians |
intensity |
number | Brightness; above 1 for highlights |
color |
colour | Default white |
Built-in environments:
| Name | Look |
|---|---|
studio |
Dark grey studio: key box above and in front, tall strips on both sides, a soft top light, a faint rim behind, a dim fill from the camera side |
soft |
Light and even: pale products, white phones, soft paint |
sunset |
A low warm sun behind and to the side, an orange horizon, a cool sky |
night |
Dark, with coloured neon strips on the sides and a thin light above |
Daylight#
Sun, sky light and background for a time of day. Use it with look="none". With an environment, reflections dim at night.
| Prop | Type | Default | Description |
|---|---|---|---|
time |
number or shared value |
required | Hour, 0–24 (13.5 is half past one). Plain values animate; shared values are followed exactly |
transition |
seconds | 1.5 |
How long a plain change of time takes |
background |
boolean | true |
Sets the background and fog to the sky colour (never on a transparent scene) |
north |
radians | 0 |
Turns the compass: where the sun rises (0: east is +x) |
keys |
DaylightKey[] |
DAY |
The day's colours. Replace them for another mood |
strength |
{ sun?, sky? } |
{ sun: 1, sky: 1 } |
Multiplies the sun's and the sky's brightness. For interiors, see Lighting a room |
sunrise, sunset |
hours | 6, 19 |
When the sun comes up and goes down |
<Scene look="none" environment="soft" fog shadows>
<Daylight time={night ? 21 : 13} />
</Scene>MOONLIT is DAY with nights you can see by (a bright moon and a deep blue sky), for outdoor places without lamps: <Daylight keys={MOONLIT}>. DAY's nights are nearly black, for rooms that light their own.
DAY has keys at 0, 5.5, 6.5, 9, 13, 17, 18.8 and 20 hours. A DaylightKey is { hour, sun, sunIntensity, sky, ground, fillIntensity, background, reflections }. Values are interpolated between keys.
Around sunrise and sunset the sun's direct light fades out and the moon's fades in, so shadows don't jump across the scene.
useDaylight()#
Returns a function that reads the light of the scene's <Daylight> now, or null without one. Call it in useFrame for anything that should follow the time of day.
DaylightNow field |
Description |
|---|---|
hour |
The hour shown (easing towards time after a plain change) |
dark |
0 by day to 1 at night: rises over the hour before sunset, falls over the hour after sunrise |
level |
The sun's (or moon's) brightness, 0 to 1 of the brightest in the keys |
direct |
How much light comes straight from the sun or moon, 0–1 |
sunDirection |
Unit vector towards the sun (or moon) |
sun, sunIntensity, sky, ground, fillIntensity, background, reflections |
The current colours and intensities |
Shadows per object#
With <Scene shadows>, meshes cast and receive, flat ones (floors) only receive, and see-through ones do neither. Override per object with castShadow, receiveShadow and shadowOnly (not drawn, only casting) on shapes, Mesh, Merged, Model and Instances. For three.js objects of your own, setShadow(object, { cast, receive, only }) from @apricotjs/core does the same.