.level and .chunk files
A level is a folder levels/<name>/ containing <name>.level and chunks/*.chunk. The
level's name is the folder name.
.level
// samples/physics/levels/yard/yard.level
export default level({
chunkSize: 32,
environment: {
sunDirection: vec3(-0.6, -1, -0.4),
sunColor: vec3(1, 0.92, 0.82),
sunIntensity: 1.15,
ambient: vec3(0.29, 0.35, 0.43),
},
});
| Key | Type | Default | Meaning |
|---|---|---|---|
chunkSize |
number | 64 |
Meters per side of a chunk square |
environment |
object | Lighting, below | |
spawnPoints |
array | [] |
{ id: "name", position: dvec3(...), rotation?: euler(...) }. id required and unique |
nextIds |
object | Written by devtools: per id stem, the lowest number a new object may get ({ house: 14, "grid-node": 3 }), so a deleted id is never given out again. Values are positive integers. The game ignores it |
environment keys, all optional:
| Key | Type | Meaning |
|---|---|---|
sunDirection |
vec3 |
Direction the sunlight travels. Creates a level-owned object with a Light |
sunColor |
vec3 |
Linear RGB |
sunIntensity |
number | Light intensity |
ambient |
vec3 |
Light added everywhere |
skybox |
string | A path; accepted but not drawn yet |
.chunk
// samples/gridline/levels/valley/chunks/0_0.chunk (shortened)
export default chunk({
format: "chunk-local-v1",
coord: [0, 0],
objects: [
{ id: "valley", type: Terrain },
{ id: "dispatch", type: GridDispatch },
{ id: "house-1", type: GridNode, position: vec3(-8.3, 0, -1.0) },
],
});
| Key | Type | Meaning |
|---|---|---|
format |
"chunk-local-v1" |
Required format marker |
coord |
[x, z] |
Required. Two integers; must match the file name x_z.chunk |
objects |
array | Placed objects, below |
terrain |
string | A heightmap path. Recorded; terrain rendering comes later |
Each placed object:
| Key | Type | Meaning |
|---|---|---|
id |
string | Required. Unique within the whole level; never changes |
type |
identifier | Required. An object type name (not a string) |
position |
vec3 |
Float offset from the chunk center, default zero |
rotation |
euler(x, y, z) or quat(x, y, z, w) |
Degrees for euler, applied Z, then X, then Y |
scale |
number or vec3 |
A number means uniform scale |
overrides |
object | { componentKey: { field: value } } for this object only |
The object's Transform is the placement composed with its type's own transform.
Chunk x_z covers the square of side chunkSize centered on (x * chunkSize, z * chunkSize). All chunks load with the level.
The loader adds the chunk center in double precision. Saving an object moved across a
boundary moves its entry. Convert older files with castc fmt --convert-chunks FILE....
Errors
| Message | Cause |
|---|---|
unknown object type 'Barn' for placed object 'crate-1' |
No objects/barn.object |
duplicate placed object id 'coin-1' |
Two objects share an id |
chunk coord does not match filename |
0_1.chunk with coord: [0, 0] |
chunk filename must have the form x_z.chunk |
Any other file name |
coord must be an array of two integers |
|
duplicate spawn point id 'start' |
|
nextIds.house must be a positive integer |
A nextIds value that is not a whole number of at least 1 |
unknown key 'k' (allowed keys: id, type, position, rotation, scale, overrides) |
A bad key on a placed object |
Override values outside a field's @range produce a warning in castc check, in the
editor and when the level loads, for
example CoinGame.goal = 500 is outside @range(1, 50).