sky
Sky configuration — type, time of day, day/night cycle, procedural parameters, presets, explicit sun direction.
require("@builtin::modules.api.engine.sky") -- sky (also available as global 'sky')
The sky namespace: 30 functions.
globals/sky/describeDrawn
sky.describeDrawn() -> SkyDescription
The description of the drawn sky from engine state alone: the drawn
material, the hour of a sky that has one, and the direction toward the sun
the scene is lit from. members is empty.
Returns SkyDescription — A SkyDescription.
local d = sky.describeDrawn()
globals/sky/drawn
sky.drawn() -> DrawnSky?
The sky drawn now, as a table of three fields: entity, the id of the
entity whose Sky row is in force; source, the AssetRef<sky> that row
was written for (the outermost registered sky over the application that
wrote it; nil for a hand-placed component's row or a raw row); and
description, { material?, timeOfDay?, sunDirection?, members, notice? }:
the material it draws, the hour it draws, the unit direction toward the sun
the scene is lit from, each top-level member's source by id and what its
members state about their settings (the description that sky registered,
else one built from engine state with members empty). Nil when no row is
in force: the scene has no sky.
Returns DrawnSky? — { entity, source?, description }, or nil.
local drawn = sky.drawn(); if drawn then print(drawn.description.timeOfDay) end
globals/sky/drawnGradient
sky.drawnGradient() -> { [string]: { number } }?
The sky gradient drawn now, as a table of three colours, each a list
of three numbers { r, g, b } from 0 to 1: zenith, the colour straight
up; horizon, the colour at the horizon; ground, the colour below it.
They are the colours the writer of the row in force draws at the hour it
draws (a procedural backdrop's after its night and dawn tints), else the
colours the row states. Nil when no row is in force.
Returns { [string]: { number } }? — { zenith, horizon, ground }, or nil.
local g = sky.drawnGradient(); if g then print(g.zenith[1]) end
globals/sky/forgetRow
sky.forgetRow(entityId: string)
Forget the writer of an entity's row: the row has left with the entity or been removed. On the next frame, once the engine draws the sky that stands after it, every light that follows the sky is oriented by that sky; with no sky drawn, they are left as they are.
Parameters
entityIdstring— The entity that carried the row.
sky.forgetRow(e.id)
globals/sky/get
sky.get() -> { [string]: any }
Get all current sky configuration as a table. Returns the
same fields as sky.set accepts, plus read-only fields like
material_name, type and authored_by (the id of the entity
whose Sky row is in force, nil when no row stands). While a ProceduralSky draws the sky, its fields are
that component's values. Color values are returned as positional
arrays [r, g, b].
Returns { [string]: any } — Full sky configuration table.
local cfg = sky.get(); print(cfg.time_of_day)
globals/sky/getTimeOfDay
sky.getTimeOfDay() -> number
Get the current time of day in hours (0-24): the timeOfDay of
the ProceduralSky drawing the sky while one does.
Returns number — Current time of day.
local t = sky.getTimeOfDay()
globals/sky/orientFollower
sky.orientFollower(entityId: string)
Orient the directional light on entityId from the sky drawn now,
when the row in force was written by a sky that drives the sun. A light
that starts following the sky (lighting.followSky) is oriented here at
once.
Parameters
entityIdstring— The entity carrying the light.
sky.orientFollower(sunId)
globals/sky/preset
sky.preset(name: string)
Apply a named sky preset. Available: clear_day, sunset,
sunrise, overcast, night, studio, none. While a
ProceduralSky draws the sky, clear_day through night are applied
as that component's own preset, which sets its look, its time of day
and the sun under it. Raises a Luau error for unrecognized names —
wrap in pcall if uncertain.
Parameters
namestring— Preset name (case-sensitive).
sky.preset("sunset")
globals/sky/registerSky
sky.registerSky(owner: string, skyAsset: any?, describe: ((owner: string) -> SkyDescription)?)
Register an application that composes a sky, by its owner, so the drawn sky answers with the asset and the description of that application while a row written under its owner is in force.
Parameters
ownerstring— The application's owner.skyAssetany(optional) — The applied asset.describe((owner: string) -> SkyDescription)(optional) — Describes the sky the application puts in force, given its owner; nil describes it from engine state (sky.describeDrawn).
sky.registerSky(owner, self, function(o) return self:describeSky(o) end)
globals/sky/set
sky.set(opts: SkyOpts)
Configure the scene's sky. All fields are optional — only
provided fields are updated. While a ProceduralSky draws the sky,
its fields (time_of_day, auto_cycle, cycle_speed,
sync_sun_to_light, exposure, the colours and the sun, star, moon
and haze parameters) are written onto that component, so the sun, the
sky material and the picture change with them. Color fields accept
both named {x=r, y=g, z=b} and positional {r, g, b} forms.
color is an alias for solid_color.
Parameters
optsSkyOpts— Sky configuration properties.
sky.set({ type = "procedural", time_of_day = 14, sync_sun_to_light = true })
globals/sky/setSunDirection
sky.setSunDirection(dir: SkyColor)
Set an explicit sun direction and disable time-based sun
positioning. When the scene's sun keeps its fields elsewhere
(lighting.setLightWriter), the direction goes to its writer. Otherwise
the sky configuration takes it directly and the directional light is
updated to match.
Parameters
dirSkyColor— Normalized sun direction vector.
sky.setSunDirection({ 0.5, -1, 0.3 })
globals/sky/setTimeOfDay
sky.setTimeOfDay(time: number)
Set the time of day (0-24 hours). 0 = midnight, 6 = sunrise,
12 = noon, 18 = sunset. When the sky drawn now was written by an applied
asset, the hour lands on that asset as appliedSystem.write lands it: on
the owner that states it, else as its live value. While a
ProceduralSky draws the sky, its timeOfDay is set, which places the
sun and, with syncSunToLight on, orients and colours the scene's
directional light. Otherwise the sky configuration takes it directly.
Parameters
timenumber— Time of day in hours.
sky.setTimeOfDay(18.5)
globals/sky/unregisterSky
sky.unregisterSky(owner: string)
Withdraw a sky application's registration.
Parameters
ownerstring— The application's owner.
sky.unregisterSky(owner)
globals/sky/writeRow
sky.writeRow(entityId: string, fields: { [string]: any }, writer: SkyWriter?)
Write the Sky row on an entity and record who wrote it. The row is
the sky the engine draws once it is the row in force; a backdrop states
{ asset } (the asset of its application), a sky type that writes on an
application's entity states { asset, owner }. Nothing is written on the
entity beside the row.
Parameters
entityIdstring— The entity carrying the row.fields{ [string]: any }— The row's fields, asecs.Skytakes them.writerSkyWriter(optional) —{ asset?, owner?, orient? }.
sky.writeRow(e.id, { skyType = "procedural", timeOfDay = 9 }, { asset = ctx.asset.guid })
globals/sky/writerOf
sky.writerOf(entityId: string) -> SkyWriter?
Who wrote the Sky row on an entity, as sky.writeRow recorded it:
{ asset?, owner? }. Nil for a row sky.writeRow did not write (a
hand-placed component's, a raw row).
Parameters
entityIdstring— The entity carrying the row.
Returns SkyWriter? — The writer, or nil.
local w = sky.writerOf(sky.drawn().entity)
typed/builtin//modules/api/engine/sky/sky/describeDrawn
sky.describeDrawn() -> SkyDescription
The description of the drawn sky from engine state alone: the drawn
material, the hour of a sky that has one, and the direction toward the sun
the scene is lit from. members is empty.
Returns SkyDescription — A SkyDescription.
local d = sky.describeDrawn()
typed/builtin//modules/api/engine/sky/sky/drawn
sky.drawn() -> DrawnSky?
The sky drawn now, as a table of three fields: entity, the id of the
entity whose Sky row is in force; source, the AssetRef<sky> that row
was written for (the outermost registered sky over the application that
wrote it; nil for a hand-placed component's row or a raw row); and
description, { material?, timeOfDay?, sunDirection?, members, notice? }:
the material it draws, the hour it draws, the unit direction toward the sun
the scene is lit from, each top-level member's source by id and what its
members state about their settings (the description that sky registered,
else one built from engine state with members empty). Nil when no row is
in force: the scene has no sky.
Returns DrawnSky? — { entity, source?, description }, or nil.
local drawn = sky.drawn(); if drawn then print(drawn.description.timeOfDay) end
typed/builtin//modules/api/engine/sky/sky/drawnGradient
sky.drawnGradient() -> { [string]: { number } }?
The sky gradient drawn now, as a table of three colours, each a list
of three numbers { r, g, b } from 0 to 1: zenith, the colour straight
up; horizon, the colour at the horizon; ground, the colour below it.
They are the colours the writer of the row in force draws at the hour it
draws (a procedural backdrop's after its night and dawn tints), else the
colours the row states. Nil when no row is in force.
Returns { [string]: { number } }? — { zenith, horizon, ground }, or nil.
local g = sky.drawnGradient(); if g then print(g.zenith[1]) end
typed/builtin//modules/api/engine/sky/sky/forgetRow
sky.forgetRow(entityId: string)
Forget the writer of an entity's row: the row has left with the entity or been removed. On the next frame, once the engine draws the sky that stands after it, every light that follows the sky is oriented by that sky; with no sky drawn, they are left as they are.
Parameters
entityIdstring— The entity that carried the row.
sky.forgetRow(e.id)
typed/builtin//modules/api/engine/sky/sky/get
sky.get() -> { [string]: any }
Get all current sky configuration as a table. Returns the
same fields as sky.set accepts, plus read-only fields like
material_name, type and authored_by (the id of the entity
whose Sky row is in force, nil when no row stands). While a ProceduralSky draws the sky, its fields are
that component's values. Color values are returned as positional
arrays [r, g, b].
Returns { [string]: any } — Full sky configuration table.
local cfg = sky.get(); print(cfg.time_of_day)
typed/builtin//modules/api/engine/sky/sky/getTimeOfDay
sky.getTimeOfDay() -> number
Get the current time of day in hours (0-24): the timeOfDay of
the ProceduralSky drawing the sky while one does.
Returns number — Current time of day.
local t = sky.getTimeOfDay()
typed/builtin//modules/api/engine/sky/sky/orientFollower
sky.orientFollower(entityId: string)
Orient the directional light on entityId from the sky drawn now,
when the row in force was written by a sky that drives the sun. A light
that starts following the sky (lighting.followSky) is oriented here at
once.
Parameters
entityIdstring— The entity carrying the light.
sky.orientFollower(sunId)
typed/builtin//modules/api/engine/sky/sky/preset
sky.preset(name: string)
Apply a named sky preset. Available: clear_day, sunset,
sunrise, overcast, night, studio, none. While a
ProceduralSky draws the sky, clear_day through night are applied
as that component's own preset, which sets its look, its time of day
and the sun under it. Raises a Luau error for unrecognized names —
wrap in pcall if uncertain.
Parameters
namestring— Preset name (case-sensitive).
sky.preset("sunset")
typed/builtin//modules/api/engine/sky/sky/registerSky
sky.registerSky(owner: string, skyAsset: any?, describe: ((owner: string) -> SkyDescription)?)
Register an application that composes a sky, by its owner, so the drawn sky answers with the asset and the description of that application while a row written under its owner is in force.
Parameters
ownerstring— The application's owner.skyAssetany(optional) — The applied asset.describe((owner: string) -> SkyDescription)(optional) — Describes the sky the application puts in force, given its owner; nil describes it from engine state (sky.describeDrawn).
sky.registerSky(owner, self, function(o) return self:describeSky(o) end)
typed/builtin//modules/api/engine/sky/sky/set
sky.set(opts: SkyOpts)
Configure the scene's sky. All fields are optional — only
provided fields are updated. While a ProceduralSky draws the sky,
its fields (time_of_day, auto_cycle, cycle_speed,
sync_sun_to_light, exposure, the colours and the sun, star, moon
and haze parameters) are written onto that component, so the sun, the
sky material and the picture change with them. Color fields accept
both named {x=r, y=g, z=b} and positional {r, g, b} forms.
color is an alias for solid_color.
Parameters
optsSkyOpts— Sky configuration properties.
sky.set({ type = "procedural", time_of_day = 14, sync_sun_to_light = true })
typed/builtin//modules/api/engine/sky/sky/setSunDirection
sky.setSunDirection(dir: SkyColor)
Set an explicit sun direction and disable time-based sun
positioning. When the scene's sun keeps its fields elsewhere
(lighting.setLightWriter), the direction goes to its writer. Otherwise
the sky configuration takes it directly and the directional light is
updated to match.
Parameters
dirSkyColor— Normalized sun direction vector.
sky.setSunDirection({ 0.5, -1, 0.3 })
typed/builtin//modules/api/engine/sky/sky/setTimeOfDay
sky.setTimeOfDay(time: number)
Set the time of day (0-24 hours). 0 = midnight, 6 = sunrise,
12 = noon, 18 = sunset. When the sky drawn now was written by an applied
asset, the hour lands on that asset as appliedSystem.write lands it: on
the owner that states it, else as its live value. While a
ProceduralSky draws the sky, its timeOfDay is set, which places the
sun and, with syncSunToLight on, orients and colours the scene's
directional light. Otherwise the sky configuration takes it directly.
Parameters
timenumber— Time of day in hours.
sky.setTimeOfDay(18.5)
typed/builtin//modules/api/engine/sky/sky/unregisterSky
sky.unregisterSky(owner: string)
Withdraw a sky application's registration.
Parameters
ownerstring— The application's owner.
sky.unregisterSky(owner)
typed/builtin//modules/api/engine/sky/sky/writeRow
sky.writeRow(entityId: string, fields: { [string]: any }, writer: SkyWriter?)
Write the Sky row on an entity and record who wrote it. The row is
the sky the engine draws once it is the row in force; a backdrop states
{ asset } (the asset of its application), a sky type that writes on an
application's entity states { asset, owner }. Nothing is written on the
entity beside the row.
Parameters
entityIdstring— The entity carrying the row.fields{ [string]: any }— The row's fields, asecs.Skytakes them.writerSkyWriter(optional) —{ asset?, owner?, orient? }.
sky.writeRow(e.id, { skyType = "procedural", timeOfDay = 9 }, { asset = ctx.asset.guid })
typed/builtin//modules/api/engine/sky/sky/writerOf
sky.writerOf(entityId: string) -> SkyWriter?
Who wrote the Sky row on an entity, as sky.writeRow recorded it:
{ asset?, owner? }. Nil for a row sky.writeRow did not write (a
hand-placed component's, a raw row).
Parameters
entityIdstring— The entity carrying the row.
Returns SkyWriter? — The writer, or nil.
local w = sky.writerOf(sky.drawn().entity)