@origingame/engine 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/bin/og.mjs +25 -0
  2. package/dist/web/origin-engine.d.ts +1233 -0
  3. package/dist/web/origin-engine.js +8628 -0
  4. package/dist/web/origin-engine_bg.wasm +0 -0
  5. package/dist/web/origin-engine_bg.wasm.d.ts +366 -0
  6. package/dist/web-publish/origin-engine-lanes.js +8509 -0
  7. package/dist/web-publish/origin-engine-lanes_bg.wasm +0 -0
  8. package/dist/web-publish/origin-engine.d.ts +1176 -0
  9. package/dist/web-publish/origin-engine.js +8313 -0
  10. package/dist/web-publish/origin-engine_bg.wasm +0 -0
  11. package/dist/web-publish/origin-engine_bg.wasm.d.ts +347 -0
  12. package/dist/web-publish/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.no-bundler.js +77 -0
  13. package/dist/web-publish-2d/origin-engine-lanes.js +8509 -0
  14. package/dist/web-publish-2d/origin-engine-lanes_bg.wasm +0 -0
  15. package/dist/web-publish-2d/origin-engine.d.ts +1176 -0
  16. package/dist/web-publish-2d/origin-engine.js +8313 -0
  17. package/dist/web-publish-2d/origin-engine_bg.wasm +0 -0
  18. package/dist/web-publish-2d/origin-engine_bg.wasm.d.ts +347 -0
  19. package/dist/web-publish-2d/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.no-bundler.js +77 -0
  20. package/knowledge/README.md +31 -0
  21. package/knowledge/knowledge.json +13 -0
  22. package/knowledge/looks/catalogue.json +1871 -0
  23. package/knowledge/package.json +33 -0
  24. package/knowledge/rules/platform.json +329 -0
  25. package/knowledge/scaffold/README.md +27 -0
  26. package/knowledge/scaffold/distribution.json +48 -0
  27. package/knowledge/scaffold/origin-engine.json +19 -0
  28. package/knowledge/scaffold/template/.origin/setup +14 -0
  29. package/knowledge/scaffold/template/LICENSES.md +23 -0
  30. package/knowledge/scaffold/template/README.md +37 -0
  31. package/knowledge/scaffold/template/assets/ai/guard.ogt +48 -0
  32. package/knowledge/scaffold/template/assets/audio/click.ogt +9 -0
  33. package/knowledge/scaffold/template/assets/fonts/NotoSansSC-Regular-subset.ttf.ogt +12 -0
  34. package/knowledge/scaffold/template/assets/fonts/OFL.txt +93 -0
  35. package/knowledge/scaffold/template/assets/looks/origin-game.ogt +12 -0
  36. package/knowledge/scaffold/template/assets/nav/yard.ogt +27 -0
  37. package/knowledge/scaffold/template/assets/scenes/main.ogt +34 -0
  38. package/knowledge/scaffold/template/assets/strings/en.ogt +14 -0
  39. package/knowledge/scaffold/template/assets/textures/stone_n.png.ogt +7 -0
  40. package/knowledge/scaffold/template/gitattributes +22 -0
  41. package/knowledge/scaffold/template/package.json +18 -0
  42. package/knowledge/scaffold/template/project.ogt +25 -0
  43. package/knowledge/scaffold/template/src/main.ts +246 -0
  44. package/knowledge/scaffold/template/tests/guard.og.ts +67 -0
  45. package/knowledge/scaffold/template/tests/smoke.og.ts +43 -0
  46. package/knowledge/scaffold/template/tsconfig.json +17 -0
  47. package/knowledge/scripts/lib.ts +203 -0
  48. package/knowledge/scripts/mount.ts +210 -0
  49. package/knowledge/scripts/pack.ts +24 -0
  50. package/knowledge/scripts/scaffold.ts +72 -0
  51. package/knowledge/scripts/validate.ts +749 -0
  52. package/knowledge/skills/og-ai/SKILL.md +386 -0
  53. package/knowledge/skills/og-audio/SKILL.md +191 -0
  54. package/knowledge/skills/og-build/SKILL.md +330 -0
  55. package/knowledge/skills/og-core/SKILL.md +285 -0
  56. package/knowledge/skills/og-feel/SKILL.md +385 -0
  57. package/knowledge/skills/og-game/SKILL.md +1479 -0
  58. package/knowledge/skills/og-i18n/SKILL.md +220 -0
  59. package/knowledge/skills/og-platform-sdk/SKILL.md +199 -0
  60. package/knowledge/skills/og-taste/SKILL.md +537 -0
  61. package/knowledge/skills/og-ui/SKILL.md +444 -0
  62. package/knowledge/wiki/ai.md +627 -0
  63. package/knowledge/wiki/anim.md +1187 -0
  64. package/knowledge/wiki/atmosphere.md +636 -0
  65. package/knowledge/wiki/audio.md +732 -0
  66. package/knowledge/wiki/camera.md +711 -0
  67. package/knowledge/wiki/commands.md +357 -0
  68. package/knowledge/wiki/game.md +220 -0
  69. package/knowledge/wiki/i18n.md +213 -0
  70. package/knowledge/wiki/index.md +1027 -0
  71. package/knowledge/wiki/input.md +1714 -0
  72. package/knowledge/wiki/load.md +1280 -0
  73. package/knowledge/wiki/math.md +166 -0
  74. package/knowledge/wiki/nav.md +1154 -0
  75. package/knowledge/wiki/physics.md +3142 -0
  76. package/knowledge/wiki/platform.md +857 -0
  77. package/knowledge/wiki/probe.md +1692 -0
  78. package/knowledge/wiki/reflect.md +285 -0
  79. package/knowledge/wiki/render.md +3511 -0
  80. package/knowledge/wiki/rng.md +393 -0
  81. package/knowledge/wiki/stream.md +376 -0
  82. package/knowledge/wiki/system.md +197 -0
  83. package/knowledge/wiki/systems.md +43 -0
  84. package/knowledge/wiki/terrain.md +727 -0
  85. package/knowledge/wiki/tilemap.md +422 -0
  86. package/knowledge/wiki/time.md +150 -0
  87. package/knowledge/wiki/transform.md +230 -0
  88. package/knowledge/wiki/tween.md +580 -0
  89. package/knowledge/wiki/ui.md +8000 -0
  90. package/knowledge/wiki/world.md +909 -0
  91. package/package.json +68 -4
  92. package/schema/api.schema.json +29675 -0
  93. package/shell/README.md +22 -0
  94. package/shell/brand/README.md +23 -0
  95. package/shell/brand/icon-192.png +0 -0
  96. package/shell/brand/icon-512.png +0 -0
  97. package/shell/brand/mark-on-paper.svg +6 -0
  98. package/shell/brand/origin-mark.svg +5 -0
  99. package/shell/brand/origin-motion.css +251 -0
  100. package/shell/brand/tokens.css +20 -0
  101. package/shell/brand.ts +132 -0
  102. package/shell/page.ts +715 -0
  103. package/shell/platform.ts +203 -0
  104. package/shell/player.ts +238 -0
  105. package/shell/shell.css +185 -0
  106. package/shell/sw.ts +177 -0
  107. package/shell/transport.ts +515 -0
  108. package/shell/wire.ts +369 -0
  109. package/src/e6.ts +69 -0
  110. package/src/env.d.ts +100 -0
  111. package/src/generated/abi.ts +980 -0
  112. package/src/index.ts +193 -0
  113. package/src/node/audio.ts +86 -0
  114. package/src/node/build.ts +109 -0
  115. package/src/node/device.ts +981 -0
  116. package/src/node/doctor.ts +60 -0
  117. package/src/node/index.ts +102 -0
  118. package/src/node/platform.ts +24 -0
  119. package/src/node/playtest-run.ts +249 -0
  120. package/src/node/png.ts +130 -0
  121. package/src/node/polish.ts +976 -0
  122. package/src/node/run.ts +373 -0
  123. package/src/node/web-build.ts +808 -0
  124. package/src/p2.ts +35 -0
  125. package/src/platform-local.ts +211 -0
  126. package/src/playtest.ts +131 -0
  127. package/src/runtime.ts +1509 -0
  128. package/src/systems/cameras.ts +247 -0
  129. package/src/ui-kit/bind.ts +141 -0
  130. package/src/ui-kit/huds.ts +303 -0
  131. package/src/ui-kit/index.ts +36 -0
  132. package/src/ui-kit/menus.ts +187 -0
  133. package/src/ui-kit/settings.ts +131 -0
  134. package/src/ui-kit/store.ts +222 -0
  135. package/src/ui-kit/story.ts +89 -0
  136. package/src/ui-kit/util.ts +106 -0
  137. package/src/web/a11y.ts +429 -0
  138. package/src/web/audio-worklet.ts +193 -0
  139. package/src/web/audio.ts +307 -0
  140. package/src/web/basis.ts +239 -0
  141. package/src/web/gamepad.ts +123 -0
  142. package/src/web/host.ts +166 -0
  143. package/src/web/input.ts +237 -0
  144. package/src/web/lanes.ts +21 -0
  145. package/src/web/play.ts +20 -0
  146. package/src/web/rpc-ring.ts +110 -0
  147. package/src/web/settle.ts +122 -0
  148. package/src/web/shell.ts +643 -0
  149. package/src/web/text-input.ts +248 -0
  150. package/src/web/worker.ts +1002 -0
  151. package/types/bindings.json +13654 -0
  152. package/types/index.d.ts +20090 -0
  153. package/vendor/basis/LICENSE +201 -0
  154. package/vendor/basis/NOTICE +15 -0
  155. package/vendor/basis/README.md +18 -0
  156. package/vendor/basis/basis_transcoder.js +19 -0
  157. package/vendor/basis/basis_transcoder.wasm +0 -0
  158. package/README.md +0 -3
@@ -0,0 +1,727 @@
1
+ <!-- Generated from crates/og-api/api.ogt by `og api gen`. Do not edit: `og api check` fails on any difference; change api.ogt and regenerate. -->
2
+
3
+ # The `terrain` module
4
+
5
+ Terrain (phase 2): a height field over a rectangle, cooked by `og cook` from a `type terrain` .ogt (a 16-bit grey PNG or an EXR heightmap, an optional control map, up to four layered materials with slope and altitude rules, their maps separate textures or layers of two texture arrays: `layers` and `layerNormals` with each layer's `albedoLayer` and `normalLayer`, two sampled textures instead of up to eight) into tiles; drawn as a geometry clipmap around the camera (nested levels by distance, no cracks) that casts and receives shadows under the fog; collided with as a height field; baked into navmeshes by a navmesh file's `terrain` entry.
6
+
7
+ Load it with og.terrain.load, then place it: an og.Terrain on an entity draws it placed by the entity's world transform (centred on its position, turned and scaled with it), and an og.Collider of shape SHAPE_HEIGHTFIELD naming the TerrainInfo's geometry makes it solid. og.TerrainScatter grows grass, flowers or stones over a layer near the camera. og.terrain.sample answers the surface's height and normal anywhere (pass it the entity's position, quaternion and scale); og.terrain.edit raises, lowers, flattens, smooths or paints it at runtime, and og.terrain.setLayer retunes a layer. Edits are world state: a snapshot keeps them, the world hash covers them, and a restore brings the ground back as it was (rebuilt from the cook with the restored edits replayed, for the renderer, physics and sample alike).
8
+
9
+ Its tiles stream (phase 3): the cook stores the field as a pyramid of tiles, each compressed on its own, and every frame the renderer keeps on the GPU only the tiles the camera's clipmap wants, within each terrain's tile budget (16 MiB by default), decoded off the frame (a worker thread natively, the browser's DecompressionStream on the Web) a few at a time, the most needed first; until a tile arrives its area draws from the coarser level that holds it, then fades in. Nothing a tick reads depends on which tiles are resident (collision and og.terrain.sample read the whole field), so a run's world hash is the same streamed or not. The probe's `terrain_stream:resident` decodes every wanted tile before each frame instead (`terrain_stream:stream[:<MiB>]` streams again, within that budget), and `dump_stream`'s `terrain` gives the tiles resident, waiting, decoding and cached.
10
+
11
+ - **TypeScript**: functions are the namespace `og.terrain`; components, resources and events are tokens on `og`.
12
+ - **Publish builds**: kept (members may override).
13
+ - **Skill**: `og-game`, which teaches the module (how much of it to use, and how to prove it).
14
+ - **Index**: [every module and name](index.md).
15
+
16
+ ```ogt
17
+ module terrain {
18
+ # declarations follow, each quoted below
19
+ ```
20
+
21
+ <sub>`api.ogt` line 10947</sub>
22
+
23
+ ## Contents
24
+
25
+ | Name | Kind | Summary |
26
+ |---|---|---|
27
+ | [`TerrainData`](#type-TerrainData) | handle | A loaded terrain: its heights, control map and layers. |
28
+ | [`TerrainData()`](#column-TerrainData) | column kind | A TerrainData handle field. |
29
+ | [`TerrainBrushMode`](#type-TerrainBrushMode) | enum | What og.terrain.edit does under its brush. |
30
+ | [`og.Terrain`](#record-Terrain) | component | Draws a loaded terrain placed by the entity's world transform (centred on its position, turned and scaled with it), with its layers (as cooked, or as og.terrain.setLayer left them), casting shadows unless told not to. |
31
+ | [`og.TerrainScatter`](#record-TerrainScatter) | component | Scatters copies of a mesh (grass, flowers, stones) over a loaded terrain near the camera, where one of its layers shows: on a jittered grid fixed to the terrain, so each copy keeps its place, size and turn as the camera moves, every cell growing one with the probability of the layer's weight there (its control-map channel times its slope and altitude rules, over all the layers' weights). Copies keep their size and thin out (dithered) over the outer `fade` of `distance`. The renderer places them itself, a chunk of the grid at a time, once, and draws the chunks in range: copies cost about nothing per frame while the camera stays. They grow over the og.Terrain drawing the same data, placed as it is. Drawn only: no colliders, and the copies are not entities. |
32
+ | [`TerrainInfo`](#type-TerrainInfo) | struct | A loaded terrain. |
33
+ | [`TerrainSampleDesc`](#type-TerrainSampleDesc) | desc struct | Where og.terrain.sample looks. |
34
+ | [`TerrainSample`](#type-TerrainSample) | struct | The terrain under a point. |
35
+ | [`TerrainBounds`](#type-TerrainBounds) | struct | A terrain's box in world space. |
36
+ | [`TerrainBrush`](#type-TerrainBrush) | desc struct | One runtime edit of a terrain (og.terrain.edit). |
37
+ | [`TerrainEdit`](#type-TerrainEdit) | struct | What an edit changed. |
38
+ | [`TerrainLayerDesc`](#type-TerrainLayerDesc) | desc struct | One material layer of a terrain: its look and the rules that place it. A layer shows where its control-map channel (1 without a map) times its slope band times its altitude band is high; the layers' weights are normalised. |
39
+ | [`og.terrain.load`](#fn-load) | function | Load a cooked terrain (a `type terrain` .ogt under assets/) and its layers' textures (or texture arrays, kept resident while it is loaded), and register its height field with physics under TerrainInfo.geometry. Loading the same path again answers the same terrain. |
40
+ | [`og.terrain.sample`](#fn-sample) | function | The surface under a world point: its height, normal and slope. Callable inside systems (it reads the terrain, not the world). |
41
+ | [`og.terrain.bounds`](#fn-bounds) | function | A terrain's box in world space when it stands at `origin`, turned by `quaternion` and scaled by `scale` (its entity's world transform): the box around its turned corners. |
42
+ | [`og.terrain.edit`](#fn-edit) | function | Change a terrain under a round brush: raise, lower, flatten or smooth its heights (the renderer, physics and og.terrain.sample see the change from the next frame and tick), or paint a layer into its control map (making one when it has none). |
43
+ | [`og.terrain.layer`](#fn-layer) | function | A terrain's layer as it is now (for a tuning tool: read it, change it, setLayer it). |
44
+ | [`og.terrain.setLayer`](#fn-setLayer) | function | Replace a terrain's layer look and rules (its textures stay). Drawn from the next frame. |
45
+
46
+ ## Functions
47
+
48
+ <a id="fn-load"></a>
49
+
50
+ ### `og.terrain.load`
51
+
52
+ Load a cooked terrain (a `type terrain` .ogt under assets/) and its layers' textures (or texture arrays, kept resident while it is loaded), and register its height field with physics under TerrainInfo.geometry. Loading the same path again answers the same terrain.
53
+
54
+ ```ts
55
+ og.terrain.load(world: World, path: string): Result<TerrainInfo>
56
+ ```
57
+
58
+ | Parameter | Type | Optional | Doc |
59
+ |---|---|---|---|
60
+ | `world` | `World` | no | The world. |
61
+ | `path` | `string` | no | The terrain file, such as `terrain/island.ogt`. |
62
+
63
+ **Returns** `Result<TerrainInfo>`: Refused for a path that is not a cooked terrain, or a layer texture that does not load.
64
+
65
+ Binding symbol `og_terrain_load` · publish builds: kept
66
+
67
+ ```ogt
68
+ fn load {
69
+ doc "Load a cooked terrain (a `type terrain` .ogt under assets/) and its layers' textures (or texture arrays, kept resident while it is loaded), and register its height field with physics under TerrainInfo.geometry. Loading the same path again answers the same terrain."
70
+ param world World "The world."
71
+ param path String "The terrain file, such as `terrain/island.ogt`."
72
+ returns Result.TerrainInfo "Refused for a path that is not a cooked terrain, or a layer texture that does not load."
73
+ }
74
+ ```
75
+
76
+ <sub>`api.ogt` line 11199</sub>
77
+
78
+ <a id="fn-sample"></a>
79
+
80
+ ### `og.terrain.sample`
81
+
82
+ The surface under a world point: its height, normal and slope. Callable inside systems (it reads the terrain, not the world).
83
+
84
+ ```ts
85
+ og.terrain.sample(world: World, desc?: TerrainSampleDesc): Result<TerrainSample>
86
+ ```
87
+
88
+ | Parameter | Type | Optional | Doc |
89
+ |---|---|---|---|
90
+ | `world` | `World` | no | The world. |
91
+ | `desc` | `TerrainSampleDesc` | yes | The terrain, where it stands and the point. |
92
+
93
+ **Returns** `Result<TerrainSample>`: Refused for an unknown terrain.
94
+
95
+ Binding symbol `og_terrain_sample` · publish builds: kept
96
+
97
+ ```ogt
98
+ fn sample {
99
+ doc "The surface under a world point: its height, normal and slope. Callable inside systems (it reads the terrain, not the world)."
100
+ param world World "The world."
101
+ param desc TerrainSampleDesc "The terrain, where it stands and the point."
102
+ returns Result.TerrainSample "Refused for an unknown terrain."
103
+ }
104
+ ```
105
+
106
+ <sub>`api.ogt` line 11206</sub>
107
+
108
+ <a id="fn-bounds"></a>
109
+
110
+ ### `og.terrain.bounds`
111
+
112
+ A terrain's box in world space when it stands at `origin`, turned by `quaternion` and scaled by `scale` (its entity's world transform): the box around its turned corners.
113
+
114
+ ```ts
115
+ og.terrain.bounds(world: World, data: TerrainData, origin?: Vector3, quaternion?: Quaternion, scale?: Vector3): Result<TerrainBounds>
116
+ ```
117
+
118
+ | Parameter | Type | Optional | Doc |
119
+ |---|---|---|---|
120
+ | `world` | `World` | no | The world. |
121
+ | `data` | `TerrainData` | no | The terrain. |
122
+ | `origin` | `Vector3` | yes | Where it stands. |
123
+ | `quaternion` | `Quaternion` | yes | How it is turned. |
124
+ | `scale` | `Vector3` | yes | How it is scaled. |
125
+
126
+ **Returns** `Result<TerrainBounds>`: Refused for an unknown terrain.
127
+
128
+ Binding symbol `og_terrain_bounds` · publish builds: kept
129
+
130
+ ```ogt
131
+ fn bounds {
132
+ doc "A terrain's box in world space when it stands at `origin`, turned by `quaternion` and scaled by `scale` (its entity's world transform): the box around its turned corners."
133
+ param world World "The world."
134
+ param data TerrainData "The terrain."
135
+ param origin Vector3 "Where it stands." {
136
+ optional true
137
+ }
138
+ param quaternion Quaternion "How it is turned." {
139
+ optional true
140
+ }
141
+ param scale Vector3 "How it is scaled." {
142
+ optional true
143
+ }
144
+ returns Result.TerrainBounds "Refused for an unknown terrain."
145
+ }
146
+ ```
147
+
148
+ <sub>`api.ogt` line 11213</sub>
149
+
150
+ <a id="fn-edit"></a>
151
+
152
+ ### `og.terrain.edit`
153
+
154
+ Change a terrain under a round brush: raise, lower, flatten or smooth its heights (the renderer, physics and og.terrain.sample see the change from the next frame and tick), or paint a layer into its control map (making one when it has none).
155
+
156
+ ```ts
157
+ og.terrain.edit(world: World, data: TerrainData, brush?: TerrainBrush): Result<TerrainEdit>
158
+ ```
159
+
160
+ | Parameter | Type | Optional | Doc |
161
+ |---|---|---|---|
162
+ | `world` | `World` | no | The world. |
163
+ | `data` | `TerrainData` | no | The terrain. |
164
+ | `brush` | `TerrainBrush` | yes | What to do and where. |
165
+
166
+ **Returns** `Result<TerrainEdit>`: Refused for an unknown terrain, a layer beyond its layers, or a brush that misses it.
167
+
168
+ Binding symbol `og_terrain_edit` · publish builds: kept
169
+
170
+ ```ogt
171
+ fn edit {
172
+ doc "Change a terrain under a round brush: raise, lower, flatten or smooth its heights (the renderer, physics and og.terrain.sample see the change from the next frame and tick), or paint a layer into its control map (making one when it has none)."
173
+ param world World "The world."
174
+ param data TerrainData "The terrain."
175
+ param brush TerrainBrush "What to do and where."
176
+ returns Result.TerrainEdit "Refused for an unknown terrain, a layer beyond its layers, or a brush that misses it."
177
+ }
178
+ ```
179
+
180
+ <sub>`api.ogt` line 11229</sub>
181
+
182
+ <a id="fn-layer"></a>
183
+
184
+ ### `og.terrain.layer`
185
+
186
+ A terrain's layer as it is now (for a tuning tool: read it, change it, setLayer it).
187
+
188
+ ```ts
189
+ og.terrain.layer(world: World, data: TerrainData, index: number): Result<TerrainLayerDesc>
190
+ ```
191
+
192
+ | Parameter | Type | Optional | Doc |
193
+ |---|---|---|---|
194
+ | `world` | `World` | no | The world. |
195
+ | `data` | `TerrainData` | no | The terrain. |
196
+ | `index` | `number` | no | The layer, from 0. |
197
+
198
+ **Returns** `Result<TerrainLayerDesc>`: Refused for an unknown terrain or layer.
199
+
200
+ Binding symbol `og_terrain_layer` · publish builds: kept
201
+
202
+ ```ogt
203
+ fn layer {
204
+ doc "A terrain's layer as it is now (for a tuning tool: read it, change it, setLayer it)."
205
+ param world World "The world."
206
+ param data TerrainData "The terrain."
207
+ param index u32 "The layer, from 0."
208
+ returns Result.TerrainLayerDesc "Refused for an unknown terrain or layer."
209
+ }
210
+ ```
211
+
212
+ <sub>`api.ogt` line 11237</sub>
213
+
214
+ <a id="fn-setLayer"></a>
215
+
216
+ ### `og.terrain.setLayer`
217
+
218
+ Replace a terrain's layer look and rules (its textures stay). Drawn from the next frame.
219
+
220
+ ```ts
221
+ og.terrain.setLayer(world: World, data: TerrainData, index: number, layer?: TerrainLayerDesc): Result<void>
222
+ ```
223
+
224
+ | Parameter | Type | Optional | Doc |
225
+ |---|---|---|---|
226
+ | `world` | `World` | no | The world. |
227
+ | `data` | `TerrainData` | no | The terrain. |
228
+ | `index` | `number` | no | The layer, from 0. |
229
+ | `layer` | `TerrainLayerDesc` | yes | The layer. |
230
+
231
+ **Returns** `Result<void>`: Refused for an unknown terrain or layer.
232
+
233
+ Binding symbol `og_terrain_set_layer` · publish builds: kept
234
+
235
+ ```ogt
236
+ fn setLayer {
237
+ doc "Replace a terrain's layer look and rules (its textures stay). Drawn from the next frame."
238
+ param world World "The world."
239
+ param data TerrainData "The terrain."
240
+ param index u32 "The layer, from 0."
241
+ param layer TerrainLayerDesc "The layer."
242
+ returns Result.Void "Refused for an unknown terrain or layer."
243
+ }
244
+ ```
245
+
246
+ <sub>`api.ogt` line 11245</sub>
247
+
248
+ ## Components, resources and events
249
+
250
+ <a id="record-Terrain"></a>
251
+
252
+ ### `og.Terrain` (component)
253
+
254
+ Draws a loaded terrain placed by the entity's world transform (centred on its position, turned and scaled with it), with its layers (as cooked, or as og.terrain.setLayer left them), casting shadows unless told not to.
255
+
256
+ Token `og.Terrain`, registered under the schema name `og.Terrain`; its value type is `Terrain`.
257
+
258
+ | Field | Type | Default | Range | Unit | Notes | Doc |
259
+ |---|---|---|---|---|---|---|
260
+ | `data` | `TerrainData` | `0` | — | — | — | The terrain (og.terrain.load's TerrainInfo.data). |
261
+ | `castShadows` | `boolean` | `true` | — | — | — | Cast the directional and local lights' shadows (it always receives them). |
262
+ | `lodSpacing` | `number` | `0` | 0 … 64 | `m` | tunable | The finest clipmap level's spacing (0: the terrain file's, or the samples' spacing). |
263
+ | `lodRing` | `number` | `0` | 0 … 256 | — | — | Quads per side of every clipmap level (0: the terrain file's, else 64; 16 to 256, rounded to a multiple of 4). |
264
+
265
+ ```ogt
266
+ component Terrain {
267
+ doc "Draws a loaded terrain placed by the entity's world transform (centred on its position, turned and scaled with it), with its layers (as cooked, or as og.terrain.setLayer left them), casting shadows unless told not to."
268
+ field data TerrainData "The terrain (og.terrain.load's TerrainInfo.data)."
269
+ field castShadows bool "Cast the directional and local lights' shadows (it always receives them)." {
270
+ default true
271
+ }
272
+ field lodSpacing f32 "The finest clipmap level's spacing (0: the terrain file's, or the samples' spacing)." {
273
+ min 0
274
+ max 64
275
+ unit m
276
+ tunable true
277
+ }
278
+ field lodRing u32 "Quads per side of every clipmap level (0: the terrain file's, else 64; 16 to 256, rounded to a multiple of 4)." {
279
+ min 0
280
+ max 256
281
+ }
282
+ }
283
+ ```
284
+
285
+ <sub>`api.ogt` line 10971</sub>
286
+
287
+ <a id="record-TerrainScatter"></a>
288
+
289
+ ### `og.TerrainScatter` (component)
290
+
291
+ Scatters copies of a mesh (grass, flowers, stones) over a loaded terrain near the camera, where one of its layers shows: on a jittered grid fixed to the terrain, so each copy keeps its place, size and turn as the camera moves, every cell growing one with the probability of the layer's weight there (its control-map channel times its slope and altitude rules, over all the layers' weights). Copies keep their size and thin out (dithered) over the outer `fade` of `distance`. The renderer places them itself, a chunk of the grid at a time, once, and draws the chunks in range: copies cost about nothing per frame while the camera stays. They grow over the og.Terrain drawing the same data, placed as it is. Drawn only: no colliders, and the copies are not entities.
292
+
293
+ Token `og.TerrainScatter`, registered under the schema name `og.TerrainScatter`; its value type is `TerrainScatter`.
294
+
295
+ | Field | Type | Default | Range | Unit | Notes | Doc |
296
+ |---|---|---|---|---|---|---|
297
+ | `data` | `TerrainData` | `0` | — | — | — | The terrain (og.terrain.load's TerrainInfo.data). |
298
+ | `geometry` | `Geometry` | `0` | — | — | — | The mesh, its origin at its root. |
299
+ | `material` | `Material` | `0` | — | — | — | Its material. |
300
+ | `layer` | `number` | `0` | ≤ 3 | — | — | The terrain layer that places it, 0 to 3. |
301
+ | `density` | `number` | `2` | 0 … 400 | — | tunable | Copies per square metre where the layer's weight is 1. |
302
+ | `distance` | `number` | `40` | 0 … 500 | `m` | tunable | How far from the camera, along x and z, copies are placed. |
303
+ | `fade` | `number` | `0.3` | 0 … 1 | `ratio` | tunable | The outer part of `distance` over which copies thin out to nothing. |
304
+ | `minScale` | `number` | `0.8` | ≥ 0 | — | tunable | The smallest copy's uniform scale. |
305
+ | `maxScale` | `number` | `1.2` | ≥ 0 | — | tunable | The largest copy's uniform scale. |
306
+ | `align` | `number` | `0` | 0 … 1 | `ratio` | tunable | How far copies lean with the ground: 0 upright, 1 along its normal. |
307
+ | `seed` | `number` | `1` | — | — | — | Another seed places the copies elsewhere. |
308
+
309
+ ```ogt
310
+ component TerrainScatter {
311
+ doc "Scatters copies of a mesh (grass, flowers, stones) over a loaded terrain near the camera, where one of its layers shows: on a jittered grid fixed to the terrain, so each copy keeps its place, size and turn as the camera moves, every cell growing one with the probability of the layer's weight there (its control-map channel times its slope and altitude rules, over all the layers' weights). Copies keep their size and thin out (dithered) over the outer `fade` of `distance`. The renderer places them itself, a chunk of the grid at a time, once, and draws the chunks in range: copies cost about nothing per frame while the camera stays. They grow over the og.Terrain drawing the same data, placed as it is. Drawn only: no colliders, and the copies are not entities."
312
+ field data TerrainData "The terrain (og.terrain.load's TerrainInfo.data)."
313
+ field geometry Geometry "The mesh, its origin at its root."
314
+ field material Material "Its material."
315
+ field layer u32 "The terrain layer that places it, 0 to 3." {
316
+ max 3
317
+ }
318
+ field density f32 "Copies per square metre where the layer's weight is 1." {
319
+ default 2
320
+ min 0
321
+ max 400
322
+ tunable true
323
+ }
324
+ field distance f32 "How far from the camera, along x and z, copies are placed." {
325
+ default 40
326
+ min 0
327
+ max 500
328
+ unit m
329
+ tunable true
330
+ }
331
+ field fade f32 "The outer part of `distance` over which copies thin out to nothing." {
332
+ default 0.3
333
+ min 0
334
+ max 1
335
+ unit ratio
336
+ tunable true
337
+ }
338
+ field minScale f32 "The smallest copy's uniform scale." {
339
+ default 0.8
340
+ min 0
341
+ tunable true
342
+ }
343
+ field maxScale f32 "The largest copy's uniform scale." {
344
+ default 1.2
345
+ min 0
346
+ tunable true
347
+ }
348
+ field align f32 "How far copies lean with the ground: 0 upright, 1 along its normal." {
349
+ min 0
350
+ max 1
351
+ unit ratio
352
+ tunable true
353
+ }
354
+ field seed u32 "Another seed places the copies elsewhere." {
355
+ default 1
356
+ }
357
+ }
358
+ ```
359
+
360
+ <sub>`api.ogt` line 10989</sub>
361
+
362
+ ## Types
363
+
364
+ <a id="type-TerrainData"></a>
365
+
366
+ ### `TerrainData` (handle)
367
+
368
+ A loaded terrain: its heights, control map and layers.
369
+
370
+ A generational handle: a number the engine hands out. A dead handle is an error value, never a crash.
371
+
372
+ ```ogt
373
+ handle TerrainData "A loaded terrain: its heights, control map and layers."
374
+ ```
375
+
376
+ <sub>`api.ogt` line 10953</sub>
377
+
378
+ <a id="type-TerrainBrushMode"></a>
379
+
380
+ ### `TerrainBrushMode` (enum)
381
+
382
+ What og.terrain.edit does under its brush.
383
+
384
+ A string: one of the variants below. The zero value is `"raise"`.
385
+
386
+ | Variant | Doc |
387
+ |---|---|
388
+ | `"raise"` | Raise the heights by `strength` metres at the centre. |
389
+ | `"lower"` | Lower them by `strength` metres at the centre. |
390
+ | `"flatten"` | Pull them towards the brush centre's y, by `strength` (0 to 1) at the centre. |
391
+ | `"smooth"` | Pull each towards its neighbours' mean, by `strength` (0 to 1) at the centre. |
392
+ | `"paint"` | Paint `layer` into the control map, by `strength` (0 to 1) at the centre. |
393
+
394
+ ```ogt
395
+ enum TerrainBrushMode {
396
+ doc "What og.terrain.edit does under its brush."
397
+ variant raise "Raise the heights by `strength` metres at the centre."
398
+ variant lower "Lower them by `strength` metres at the centre."
399
+ variant flatten "Pull them towards the brush centre's y, by `strength` (0 to 1) at the centre."
400
+ variant smooth "Pull each towards its neighbours' mean, by `strength` (0 to 1) at the centre."
401
+ variant paint "Paint `layer` into the control map, by `strength` (0 to 1) at the centre."
402
+ }
403
+ ```
404
+
405
+ <sub>`api.ogt` line 10962</sub>
406
+
407
+ <a id="type-TerrainInfo"></a>
408
+
409
+ ### `TerrainInfo` (struct)
410
+
411
+ A loaded terrain.
412
+
413
+ | Field | Type | Default | Range | Unit | Notes | Doc |
414
+ |---|---|---|---|---|---|---|
415
+ | `data` | `TerrainData` | `0` | — | — | — | Its handle, for og.Terrain.data and this module's functions. |
416
+ | `geometry` | `Geometry` | `0` | — | — | — | The height field registered with physics under this handle: the mesh of an og.Collider of shape SHAPE_HEIGHTFIELD. |
417
+ | `size` | `Vector2` | `{ x: 0, y: 0 }` | — | `m` | — | Its extent along x and z, centred on its entity. |
418
+ | `columns` | `number` | `0` | — | — | — | Height samples along x. |
419
+ | `rows` | `number` | `0` | — | — | — | Height samples along z. |
420
+ | `minHeight` | `number` | `0` | — | `m` | — | The lowest point above its entity. |
421
+ | `maxHeight` | `number` | `0` | — | `m` | — | The highest. |
422
+ | `layers` | `number` | `0` | — | — | — | Its material layers (up to 4). |
423
+ | `collision` | `boolean` | `false` | — | — | — | Whether its terrain file asks for a collider (`collision`, default true). |
424
+ | `castShadows` | `boolean` | `false` | — | — | — | Its terrain file's `castShadows`. |
425
+
426
+ ```ogt
427
+ struct TerrainInfo {
428
+ doc "A loaded terrain."
429
+ field data TerrainData "Its handle, for og.Terrain.data and this module's functions."
430
+ field geometry Geometry "The height field registered with physics under this handle: the mesh of an og.Collider of shape SHAPE_HEIGHTFIELD."
431
+ field size Vector2 "Its extent along x and z, centred on its entity." {
432
+ unit m
433
+ }
434
+ field columns u32 "Height samples along x."
435
+ field rows u32 "Height samples along z."
436
+ field minHeight f32 "The lowest point above its entity." {
437
+ unit m
438
+ }
439
+ field maxHeight f32 "The highest." {
440
+ unit m
441
+ }
442
+ field layers u32 "Its material layers (up to 4)."
443
+ field collision bool "Whether its terrain file asks for a collider (`collision`, default true)."
444
+ field castShadows bool "Its terrain file's `castShadows`."
445
+ }
446
+ ```
447
+
448
+ <sub>`api.ogt` line 11038</sub>
449
+
450
+ <a id="type-TerrainSampleDesc"></a>
451
+
452
+ ### `TerrainSampleDesc` (desc struct)
453
+
454
+ Where og.terrain.sample looks.
455
+
456
+ A desc: every field may be omitted and takes its default; `{}` is valid.
457
+
458
+ | Field | Type | Default | Range | Unit | Notes | Doc |
459
+ |---|---|---|---|---|---|---|
460
+ | `data` | `TerrainData` | `0` | — | — | — | The terrain. |
461
+ | `origin` | `Vector3` | `{ x: 0, y: 0, z: 0 }` | — | `m` | — | Where it stands: its og.Terrain entity's world position. |
462
+ | `quaternion` | `Quaternion` | `{ x: 0, y: 0, z: 0, w: 1 }` | — | — | — | How it is turned: its og.Terrain entity's world rotation (the zero value: along world x and z). |
463
+ | `scale` | `Vector3` | `{ x: 1, y: 1, z: 1 }` | — | — | — | How it is scaled: its og.Terrain entity's world scale. |
464
+ | `x` | `number` | `0` | — | `m` | — | The world x. |
465
+ | `z` | `number` | `0` | — | `m` | — | The world z. |
466
+
467
+ ```ogt
468
+ struct TerrainSampleDesc {
469
+ doc "Where og.terrain.sample looks."
470
+ desc true
471
+ field data TerrainData "The terrain."
472
+ field origin Vector3 "Where it stands: its og.Terrain entity's world position." {
473
+ unit m
474
+ }
475
+ field quaternion Quaternion "How it is turned: its og.Terrain entity's world rotation (the zero value: along world x and z)."
476
+ field scale Vector3 "How it is scaled: its og.Terrain entity's world scale." {
477
+ default 1 1 1
478
+ }
479
+ field x f32 "The world x." {
480
+ unit m
481
+ }
482
+ field z f32 "The world z." {
483
+ unit m
484
+ }
485
+ }
486
+ ```
487
+
488
+ <sub>`api.ogt` line 11058</sub>
489
+
490
+ <a id="type-TerrainSample"></a>
491
+
492
+ ### `TerrainSample` (struct)
493
+
494
+ The terrain under a point.
495
+
496
+ | Field | Type | Default | Range | Unit | Notes | Doc |
497
+ |---|---|---|---|---|---|---|
498
+ | `height` | `number` | `0` | — | `m` | — | The world y of the surface (the triangles drawn at the finest level and collided with) on the terrain's up axis through (x, z): straight down for a terrain turned only about y. |
499
+ | `normal` | `Vector3` | `{ x: 0, y: 0, z: 0 }` | — | — | — | The surface normal, smoothed between samples as the renderer shades it. |
500
+ | `slope` | `number` | `0` | — | `deg` | — | The normal's angle from straight up. |
501
+ | `inside` | `boolean` | `false` | — | — | — | Whether the point is over the terrain (outside, the nearest edge answers). |
502
+
503
+ ```ogt
504
+ struct TerrainSample {
505
+ doc "The terrain under a point."
506
+ field height f32 "The world y of the surface (the triangles drawn at the finest level and collided with) on the terrain's up axis through (x, z): straight down for a terrain turned only about y." {
507
+ unit m
508
+ }
509
+ field normal Vector3 "The surface normal, smoothed between samples as the renderer shades it."
510
+ field slope f32 "The normal's angle from straight up." {
511
+ unit deg
512
+ }
513
+ field inside bool "Whether the point is over the terrain (outside, the nearest edge answers)."
514
+ }
515
+ ```
516
+
517
+ <sub>`api.ogt` line 11077</sub>
518
+
519
+ <a id="type-TerrainBounds"></a>
520
+
521
+ ### `TerrainBounds` (struct)
522
+
523
+ A terrain's box in world space.
524
+
525
+ | Field | Type | Default | Range | Unit | Notes | Doc |
526
+ |---|---|---|---|---|---|---|
527
+ | `min` | `Vector3` | `{ x: 0, y: 0, z: 0 }` | — | `m` | — | The lowest corner. |
528
+ | `max` | `Vector3` | `{ x: 0, y: 0, z: 0 }` | — | `m` | — | The highest corner. |
529
+
530
+ ```ogt
531
+ struct TerrainBounds {
532
+ doc "A terrain's box in world space."
533
+ field min Vector3 "The lowest corner." {
534
+ unit m
535
+ }
536
+ field max Vector3 "The highest corner." {
537
+ unit m
538
+ }
539
+ }
540
+ ```
541
+
542
+ <sub>`api.ogt` line 11089</sub>
543
+
544
+ <a id="type-TerrainBrush"></a>
545
+
546
+ ### `TerrainBrush` (desc struct)
547
+
548
+ One runtime edit of a terrain (og.terrain.edit).
549
+
550
+ A desc: every field may be omitted and takes its default; `{}` is valid.
551
+
552
+ | Field | Type | Default | Range | Unit | Notes | Doc |
553
+ |---|---|---|---|---|---|---|
554
+ | `mode` | `TerrainBrushMode` | `"raise"` | — | — | — | What it does. |
555
+ | `origin` | `Vector3` | `{ x: 0, y: 0, z: 0 }` | — | `m` | — | Where the terrain stands: its og.Terrain entity's world position. |
556
+ | `quaternion` | `Quaternion` | `{ x: 0, y: 0, z: 0, w: 1 }` | — | — | — | How it is turned: its og.Terrain entity's world rotation. |
557
+ | `scale` | `Vector3` | `{ x: 1, y: 1, z: 1 }` | — | — | — | How it is scaled: its og.Terrain entity's world scale. |
558
+ | `center` | `Vector3` | `{ x: 0, y: 0, z: 0 }` | — | `m` | — | The brush's centre in world space; its y is flatten's target height. |
559
+ | `radius` | `number` | `8` | ≥ 0.01 | `m` | — | The brush's radius in world metres (across the terrain's surface). |
560
+ | `strength` | `number` | `1` | ≥ 0 | — | — | World metres at the centre (raise, lower), or how far to go, 0 to 1 (flatten, smooth, paint). |
561
+ | `falloff` | `number` | `0.5` | 0 … 1 | `ratio` | — | The outer part of the radius over which it fades to nothing (0: a hard edge, 1: fading from the centre). |
562
+ | `layer` | `number` | `0` | ≤ 3 | — | — | paint: the layer painted, 0 to 3. |
563
+
564
+ ```ogt
565
+ struct TerrainBrush {
566
+ doc "One runtime edit of a terrain (og.terrain.edit)."
567
+ desc true
568
+ field mode TerrainBrushMode "What it does."
569
+ field origin Vector3 "Where the terrain stands: its og.Terrain entity's world position." {
570
+ unit m
571
+ }
572
+ field quaternion Quaternion "How it is turned: its og.Terrain entity's world rotation."
573
+ field scale Vector3 "How it is scaled: its og.Terrain entity's world scale." {
574
+ default 1 1 1
575
+ }
576
+ field center Vector3 "The brush's centre in world space; its y is flatten's target height." {
577
+ unit m
578
+ }
579
+ field radius f32 "The brush's radius in world metres (across the terrain's surface)." {
580
+ default 8
581
+ min 0.01
582
+ unit m
583
+ }
584
+ field strength f32 "World metres at the centre (raise, lower), or how far to go, 0 to 1 (flatten, smooth, paint)." {
585
+ default 1
586
+ min 0
587
+ }
588
+ field falloff f32 "The outer part of the radius over which it fades to nothing (0: a hard edge, 1: fading from the centre)." {
589
+ default 0.5
590
+ min 0
591
+ max 1
592
+ unit ratio
593
+ }
594
+ field layer u32 "paint: the layer painted, 0 to 3." {
595
+ max 3
596
+ }
597
+ }
598
+ ```
599
+
600
+ <sub>`api.ogt` line 11099</sub>
601
+
602
+ <a id="type-TerrainEdit"></a>
603
+
604
+ ### `TerrainEdit` (struct)
605
+
606
+ What an edit changed.
607
+
608
+ | Field | Type | Default | Range | Unit | Notes | Doc |
609
+ |---|---|---|---|---|---|---|
610
+ | `samples` | `number` | `0` | — | — | — | Height or control-map samples it touched. |
611
+ | `minHeight` | `number` | `0` | — | `m` | — | The terrain's lowest point now. |
612
+ | `maxHeight` | `number` | `0` | — | `m` | — | Its highest now. |
613
+
614
+ ```ogt
615
+ struct TerrainEdit {
616
+ doc "What an edit changed."
617
+ field samples u32 "Height or control-map samples it touched."
618
+ field minHeight f32 "The terrain's lowest point now." {
619
+ unit m
620
+ }
621
+ field maxHeight f32 "Its highest now." {
622
+ unit m
623
+ }
624
+ }
625
+ ```
626
+
627
+ <sub>`api.ogt` line 11133</sub>
628
+
629
+ <a id="type-TerrainLayerDesc"></a>
630
+
631
+ ### `TerrainLayerDesc` (desc struct)
632
+
633
+ One material layer of a terrain: its look and the rules that place it. A layer shows where its control-map channel (1 without a map) times its slope band times its altitude band is high; the layers' weights are normalised.
634
+
635
+ A desc: every field may be omitted and takes its default; `{}` is valid.
636
+
637
+ | Field | Type | Default | Range | Unit | Notes | Doc |
638
+ |---|---|---|---|---|---|---|
639
+ | `color` | `Color` | `{ r: 1, g: 1, b: 1 }` | — | — | — | Multiplies the layer's texture (linear). |
640
+ | `roughness` | `number` | `0.9` | 0.04 … 1 | — | — | Its roughness. |
641
+ | `tile` | `number` | `4` | 0.01 … 1000 | `m` | — | Metres per repeat of its textures. |
642
+ | `triplanar` | `boolean` | `false` | — | — | — | Sample by three projections blended by the normal (for cliffs). |
643
+ | `normalStrength` | `number` | `1` | 0 … 4 | — | — | How strongly its normal map bends the surface. |
644
+ | `slopeMin` | `number` | `0` | 0 … 90 | `deg` | — | The flattest slope it shows on. |
645
+ | `slopeMax` | `number` | `90` | 0 … 90 | `deg` | — | The steepest. |
646
+ | `slopeFade` | `number` | `4` | 0 … 90 | `deg` | — | How far past its slopes it fades out. |
647
+ | `altitudeMin` | `number` | `-1000000` | — | `m` | — | The lowest height above the terrain's origin it shows at. |
648
+ | `altitudeMax` | `number` | `1000000` | — | `m` | — | The highest. |
649
+ | `altitudeFade` | `number` | `4` | ≥ 0 | `m` | — | How far past its heights it fades out. |
650
+
651
+ ```ogt
652
+ struct TerrainLayerDesc {
653
+ doc "One material layer of a terrain: its look and the rules that place it. A layer shows where its control-map channel (1 without a map) times its slope band times its altitude band is high; the layers' weights are normalised."
654
+ desc true
655
+ field color Color "Multiplies the layer's texture (linear)." {
656
+ default 1 1 1
657
+ }
658
+ field roughness f32 "Its roughness." {
659
+ default 0.9
660
+ min 0.04
661
+ max 1
662
+ }
663
+ field tile f32 "Metres per repeat of its textures." {
664
+ default 4
665
+ min 0.01
666
+ max 1000
667
+ unit m
668
+ }
669
+ field triplanar bool "Sample by three projections blended by the normal (for cliffs)."
670
+ field normalStrength f32 "How strongly its normal map bends the surface." {
671
+ default 1
672
+ min 0
673
+ max 4
674
+ }
675
+ field slopeMin f32 "The flattest slope it shows on." {
676
+ min 0
677
+ max 90
678
+ unit deg
679
+ }
680
+ field slopeMax f32 "The steepest." {
681
+ default 90
682
+ min 0
683
+ max 90
684
+ unit deg
685
+ }
686
+ field slopeFade f32 "How far past its slopes it fades out." {
687
+ default 4
688
+ min 0
689
+ max 90
690
+ unit deg
691
+ }
692
+ field altitudeMin f32 "The lowest height above the terrain's origin it shows at." {
693
+ default -1000000
694
+ unit m
695
+ }
696
+ field altitudeMax f32 "The highest." {
697
+ default 1000000
698
+ unit m
699
+ }
700
+ field altitudeFade f32 "How far past its heights it fades out." {
701
+ default 4
702
+ min 0
703
+ unit m
704
+ }
705
+ }
706
+ ```
707
+
708
+ <sub>`api.ogt` line 11144</sub>
709
+
710
+ ## Column kinds
711
+
712
+ Each is a factory, `TerrainData(value?, options?)`, that makes one field of a component or resource layout.
713
+
714
+ | Column | Value | Typed array | Stride | Doc |
715
+ |---|---|---|---|---|
716
+ | <a id="column-TerrainData"></a>`TerrainData` | `TerrainData` | `Uint32Array` | 2 | A TerrainData handle field. |
717
+
718
+ ```ogt
719
+ column TerrainData {
720
+ doc "A TerrainData handle field."
721
+ array Uint32Array
722
+ stride 2
723
+ value TerrainData
724
+ }
725
+ ```
726
+
727
+ <sub>`api.ogt` line 10955</sub>