@null3d/engine 0.0.0 → 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 (311) hide show
  1. package/README.md +109 -0
  2. package/THIRD-PARTY-NOTICES.txt +0 -1
  3. package/dist/wasm/single/null3d.js +19 -6
  4. package/dist/wasm/single/null3d_bg.wasm +0 -0
  5. package/dist/wasm/threaded/null3d.js +19 -6
  6. package/dist/wasm/threaded/null3d_bg.wasm +0 -0
  7. package/docs/api/animation.md +23 -67
  8. package/docs/api/assets.md +42 -26
  9. package/docs/api/cameras.md +8 -6
  10. package/docs/api/controls.md +46 -44
  11. package/docs/api/debug.md +13 -8
  12. package/docs/api/engine.md +17 -11
  13. package/docs/api/feature-draws.md +3 -3
  14. package/docs/api/feature-effects.md +3 -3
  15. package/docs/api/feature-instances.md +2 -2
  16. package/docs/api/features.md +14 -15
  17. package/docs/api/geometry.md +56 -75
  18. package/docs/api/grass.md +1 -1
  19. package/docs/api/impostors.md +120 -9
  20. package/docs/api/input.md +4 -11
  21. package/docs/api/lights.md +14 -38
  22. package/docs/api/lines.md +8 -25
  23. package/docs/api/materials.md +69 -70
  24. package/docs/api/math.md +6 -7
  25. package/docs/api/objects.md +13 -13
  26. package/docs/api/particles.md +2 -14
  27. package/docs/api/points.md +3 -25
  28. package/docs/api/post.md +22 -23
  29. package/docs/api/quality.md +11 -6
  30. package/docs/api/raycast.md +13 -32
  31. package/docs/api/reference/animation.md +9 -9
  32. package/docs/api/reference/assets.md +18 -18
  33. package/docs/api/reference/cameras.md +5 -2
  34. package/docs/api/reference/controls.md +75 -23
  35. package/docs/api/reference/debug.md +23 -8
  36. package/docs/api/reference/engine.md +22 -10
  37. package/docs/api/reference/geometry.md +161 -82
  38. package/docs/api/reference/grass.md +1 -1
  39. package/docs/api/reference/impostors.md +92 -1
  40. package/docs/api/reference/input.md +3 -3
  41. package/docs/api/reference/lights.md +9 -9
  42. package/docs/api/reference/lines.md +7 -7
  43. package/docs/api/reference/materials.md +48 -48
  44. package/docs/api/reference/math.md +22 -22
  45. package/docs/api/reference/objects.md +9 -9
  46. package/docs/api/reference/points.md +4 -4
  47. package/docs/api/reference/post.md +18 -18
  48. package/docs/api/reference/quality.md +7 -3
  49. package/docs/api/reference/raycast.md +6 -6
  50. package/docs/api/reference/render.md +2 -2
  51. package/docs/api/reference/scene.md +29 -26
  52. package/docs/api/reference/sketch.md +4 -0
  53. package/docs/api/reference/sound.md +203 -0
  54. package/docs/api/reference/sprites.md +5 -5
  55. package/docs/api/reference/terrain.md +2 -1
  56. package/docs/api/reference/textures.md +4 -4
  57. package/docs/api/reference/ui.md +3 -3
  58. package/docs/api/reference/vertex-draws.md +3 -3
  59. package/docs/api/reference/water.md +77 -6
  60. package/docs/api/reference/wind.md +2 -2
  61. package/docs/api/render.md +12 -10
  62. package/docs/api/scene.md +40 -29
  63. package/docs/api/sketch.md +64 -3
  64. package/docs/api/sound.md +169 -0
  65. package/docs/api/splats.md +7 -0
  66. package/docs/api/sprites.md +4 -20
  67. package/docs/api/tasks.md +2 -2
  68. package/docs/api/terrain.md +2 -14
  69. package/docs/api/textures.md +9 -9
  70. package/docs/api/ui.md +3 -15
  71. package/docs/api/water.md +198 -15
  72. package/docs/api/wind.md +5 -5
  73. package/docs/cli/null3d.md +93 -18
  74. package/docs/concepts/architecture.md +10 -10
  75. package/docs/concepts/assets.md +2 -19
  76. package/docs/concepts/backends.md +7 -5
  77. package/docs/concepts/color-management.md +15 -26
  78. package/docs/concepts/culling.md +1 -1
  79. package/docs/concepts/instances.md +5 -5
  80. package/docs/concepts/large-worlds.md +1 -1
  81. package/docs/concepts/lighting.md +50 -55
  82. package/docs/concepts/lod.md +2 -15
  83. package/docs/concepts/materials.md +16 -16
  84. package/docs/concepts/post-processing.md +7 -29
  85. package/docs/concepts/quality-preset-tables.md +53 -50
  86. package/docs/concepts/quality-presets.md +56 -27
  87. package/docs/concepts/render-graph.md +19 -14
  88. package/docs/concepts/render-layers.md +3 -17
  89. package/docs/concepts/shadows.md +10 -28
  90. package/docs/concepts/static-dynamic.md +2 -2
  91. package/docs/cookbook/index.md +1 -1
  92. package/docs/data/threejs-mapping.json +136 -102
  93. package/docs/errors/E1214.md +3 -3
  94. package/docs/errors/E1307.md +23 -0
  95. package/docs/errors/E1420.md +3 -3
  96. package/docs/errors/index.md +3 -2
  97. package/docs/getting-started/cdn.md +17 -1
  98. package/docs/getting-started/first-scene.md +1 -1
  99. package/docs/getting-started/hosting.md +50 -9
  100. package/docs/getting-started/install.md +8 -7
  101. package/docs/getting-started/network-use.md +10 -2
  102. package/docs/getting-started/project-structure.md +15 -6
  103. package/docs/getting-started/third-party-notices.md +8 -6
  104. package/docs/guides/accessibility.md +1 -1
  105. package/docs/guides/add-ons.md +3 -2
  106. package/docs/guides/agents.md +16 -5
  107. package/docs/guides/assets-pipeline.md +13 -12
  108. package/docs/guides/audio.md +109 -124
  109. package/docs/guides/car-paint.md +1 -1
  110. package/docs/guides/content-pages.md +10 -6
  111. package/docs/guides/custom-passes.md +9 -8
  112. package/docs/guides/custom-shaders.md +6 -3
  113. package/docs/guides/debugging.md +78 -4
  114. package/docs/guides/deploying.md +105 -5
  115. package/docs/guides/deterministic-simulation.md +1 -1
  116. package/docs/guides/first-use-shaders.md +4 -4
  117. package/docs/guides/loading-screens.md +78 -33
  118. package/docs/guides/multiple-views.md +41 -2
  119. package/docs/guides/performance.md +6 -3
  120. package/docs/guides/phones.md +12 -1
  121. package/docs/guides/physics.md +1 -1
  122. package/docs/guides/screens.md +7 -5
  123. package/docs/guides/start-time.md +328 -0
  124. package/docs/guides/testing.md +23 -5
  125. package/docs/guides/ui-overlays.md +3 -3
  126. package/docs/index.md +12 -8
  127. package/docs/pages.md +26 -23
  128. package/docs/porting/react-three-fiber.md +228 -5
  129. package/docs/porting/threejs-loop-and-threads.md +220 -6
  130. package/docs/porting/threejs-mapping.md +86 -84
  131. package/docs/porting/threejs-materials.md +212 -5
  132. package/docs/porting/threejs-overview.md +218 -5
  133. package/docs/porting/threejs-postprocessing.md +2 -2
  134. package/docs/porting/threejs-shaders.md +298 -5
  135. package/docs/porting/threejs-unsupported.md +82 -6
  136. package/docs/porting/verification.md +181 -5
  137. package/docs/shaders/builtins.md +1 -1
  138. package/docs/shaders/library.md +63 -39
  139. package/docs/shaders/surface-functions.md +11 -10
  140. package/docs/shaders/wgsl-rules.md +1 -1
  141. package/lib/debug/channel.d.ts +103 -0
  142. package/lib/debug/channel.js +269 -0
  143. package/lib/debug/debug.d.ts +9 -7
  144. package/lib/debug/draw.d.ts +9 -0
  145. package/lib/debug/draw.js +49 -2
  146. package/lib/debug/inspector.d.ts +60 -0
  147. package/lib/debug/inspector.js +475 -0
  148. package/lib/debug/stats-panel.d.ts +1 -1
  149. package/lib/debug/stats.d.ts +2 -3
  150. package/lib/errors/codes.js +8 -2
  151. package/lib/errors/engine-error.js +25 -10
  152. package/lib/errors/fixes.d.ts +1 -0
  153. package/lib/errors/fixes.js +3 -2
  154. package/lib/generated/core.d.ts +1 -1
  155. package/lib/generated/core.js +1 -1
  156. package/lib/gpu/early-builds.d.ts +68 -0
  157. package/lib/gpu/early-builds.js +158 -0
  158. package/lib/gpu/pipeline-name.d.ts +6 -0
  159. package/lib/gpu/pipeline-name.js +23 -0
  160. package/lib/gpu/webgl2/backend.d.ts +63 -2
  161. package/lib/gpu/webgl2/backend.js +226 -8
  162. package/lib/gpu/webgl2/programs.d.ts +18 -0
  163. package/lib/gpu/webgl2/programs.js +4 -1
  164. package/lib/gpu/webgpu/backend.d.ts +89 -2
  165. package/lib/gpu/webgpu/backend.js +255 -8
  166. package/lib/gpu/webgpu/pipelines.d.ts +13 -0
  167. package/lib/gpu/webgpu/pipelines.js +15 -1
  168. package/lib/index.d.ts +6 -4
  169. package/lib/index.js +3 -2
  170. package/lib/math/color.d.ts +5 -5
  171. package/lib/math/color.js +5 -5
  172. package/lib/math/mat4.d.ts +6 -12
  173. package/lib/math/mat4.js +6 -12
  174. package/lib/math/namespaces/quat.d.ts +3 -3
  175. package/lib/math/namespaces/quat.js +3 -3
  176. package/lib/math/quat.d.ts +8 -12
  177. package/lib/math/quat.js +8 -12
  178. package/lib/math/random.d.ts +2 -3
  179. package/lib/math/random.js +2 -3
  180. package/lib/math/types.d.ts +4 -4
  181. package/lib/math/vec3.d.ts +3 -6
  182. package/lib/math/vec3.js +3 -6
  183. package/lib/page/capabilities.d.ts +7 -7
  184. package/lib/page/capabilities.js +39 -25
  185. package/lib/page/check-store.d.ts +14 -2
  186. package/lib/page/check-store.js +34 -11
  187. package/lib/page/engine.d.ts +103 -26
  188. package/lib/page/engine.js +420 -97
  189. package/lib/page/first-frame.d.ts +16 -0
  190. package/lib/page/first-frame.js +35 -0
  191. package/lib/page/frame-stats.d.ts +34 -1
  192. package/lib/page/frame-stats.js +15 -0
  193. package/lib/page/label-loop.d.ts +7 -3
  194. package/lib/page/label-loop.js +17 -10
  195. package/lib/page/labels.d.ts +3 -3
  196. package/lib/page/pipeline-store.d.ts +25 -0
  197. package/lib/page/pipeline-store.js +84 -0
  198. package/lib/page/start-marker.d.ts +4 -1
  199. package/lib/page/start-marker.js +5 -2
  200. package/lib/page/switches.d.ts +32 -2
  201. package/lib/page/switches.js +9 -1
  202. package/lib/quality/check.d.ts +24 -3
  203. package/lib/quality/check.js +21 -7
  204. package/lib/quality/chooser.d.ts +6 -0
  205. package/lib/quality/chooser.js +8 -0
  206. package/lib/quality/governor.d.ts +98 -6
  207. package/lib/quality/governor.js +250 -20
  208. package/lib/quality/preset-docs.d.ts +16 -1
  209. package/lib/quality/preset-docs.js +3 -0
  210. package/lib/quality/presets.d.ts +84 -7
  211. package/lib/quality/presets.js +94 -2
  212. package/lib/render/draw.d.ts +3 -2
  213. package/lib/render/draw.js +15 -5
  214. package/lib/render/load-draw.d.ts +7 -5
  215. package/lib/render/load-draw.js +7 -5
  216. package/lib/render/loss.d.ts +28 -10
  217. package/lib/render/loss.js +50 -22
  218. package/lib/render/recovery.d.ts +20 -0
  219. package/lib/render/recovery.js +44 -4
  220. package/lib/render/renderer.d.ts +85 -9
  221. package/lib/render/renderer.js +181 -42
  222. package/lib/render/scene-renderer.d.ts +19 -1
  223. package/lib/render/scene-renderer.js +25 -1
  224. package/lib/render/webgl2-renderers.js +8 -5
  225. package/lib/render/webgpu-renderers.js +5 -4
  226. package/lib/scene/animation.d.ts +28 -32
  227. package/lib/scene/animation.js +12 -15
  228. package/lib/scene/assets.d.ts +61 -86
  229. package/lib/scene/assets.js +103 -236
  230. package/lib/scene/background.d.ts +14 -18
  231. package/lib/scene/background.js +5 -2
  232. package/lib/scene/color.d.ts +3 -3
  233. package/lib/scene/downloads.d.ts +2 -0
  234. package/lib/scene/downloads.js +371 -0
  235. package/lib/scene/environment.d.ts +7 -7
  236. package/lib/scene/environment.js +1 -1
  237. package/lib/scene/fake-call-values.js +1 -1
  238. package/lib/scene/fog.d.ts +11 -4
  239. package/lib/scene/fog.js +8 -2
  240. package/lib/scene/frame-cameras.d.ts +19 -0
  241. package/lib/scene/frame-cameras.js +58 -0
  242. package/lib/scene/gltf.d.ts +32 -2
  243. package/lib/scene/gltf.js +78 -49
  244. package/lib/scene/grading.d.ts +2 -2
  245. package/lib/scene/grading.js +3 -3
  246. package/lib/scene/ktx2.d.ts +9 -1
  247. package/lib/scene/ktx2.js +3 -2
  248. package/lib/scene/level-rule.d.ts +120 -0
  249. package/lib/scene/level-rule.js +130 -0
  250. package/lib/scene/lines.d.ts +13 -17
  251. package/lib/scene/lines.js +3 -3
  252. package/lib/scene/lut.d.ts +1 -2
  253. package/lib/scene/lut.js +1 -2
  254. package/lib/scene/picks.d.ts +2 -2
  255. package/lib/scene/pointer-events.d.ts +4 -7
  256. package/lib/scene/post.d.ts +38 -43
  257. package/lib/scene/post.js +4 -1
  258. package/lib/scene/prefab.d.ts +7 -8
  259. package/lib/scene/prefab.js +7 -8
  260. package/lib/scene/property-animation.d.ts +1 -1
  261. package/lib/scene/property-animation.js +1 -1
  262. package/lib/scene/queries.d.ts +7 -13
  263. package/lib/scene/resources.d.ts +225 -254
  264. package/lib/scene/resources.js +179 -81
  265. package/lib/scene/scene.d.ts +149 -118
  266. package/lib/scene/scene.js +196 -98
  267. package/lib/scene/serial-loads.d.ts +29 -0
  268. package/lib/scene/serial-loads.js +68 -0
  269. package/lib/scene/shader-preloads.d.ts +34 -0
  270. package/lib/scene/shader-preloads.js +38 -0
  271. package/lib/scene/sprites.d.ts +14 -17
  272. package/lib/scene/sprites.js +5 -6
  273. package/lib/scene/textures.d.ts +11 -12
  274. package/lib/scene/textures.js +9 -10
  275. package/lib/scene/time-of-day.d.ts +3 -4
  276. package/lib/scene/time-of-day.js +2 -3
  277. package/lib/scene/vertex-draws.d.ts +5 -4
  278. package/lib/scene/vertex-draws.js +7 -5
  279. package/lib/shader-artifact.json +1 -0
  280. package/lib/shared/core.d.ts +5 -0
  281. package/lib/shared/core.js +1 -0
  282. package/lib/shared/import-once.d.ts +6 -0
  283. package/lib/shared/import-once.js +19 -0
  284. package/lib/shared/metrics.d.ts +38 -0
  285. package/lib/shared/metrics.js +62 -1
  286. package/lib/shared/run-task.js +7 -1
  287. package/lib/shared/task-pending.d.ts +12 -0
  288. package/lib/shared/task-pending.js +61 -1
  289. package/lib/shared/tasks.js +79 -32
  290. package/lib/shared/version.d.ts +17 -1
  291. package/lib/shared/version.js +19 -1
  292. package/lib/shared/wasm.d.ts +12 -4
  293. package/lib/shared/wasm.js +50 -27
  294. package/lib/shared/worker-start.d.ts +7 -0
  295. package/lib/shared/worker-start.js +27 -0
  296. package/lib/sketch/define-sketch.d.ts +35 -0
  297. package/lib/sketch/input.d.ts +2 -2
  298. package/lib/sketch/preset-check.d.ts +20 -6
  299. package/lib/sketch/preset-check.js +42 -17
  300. package/lib/sketch/quality.d.ts +69 -11
  301. package/lib/sketch/quality.js +54 -13
  302. package/lib/sketch/runner.d.ts +76 -9
  303. package/lib/sketch/runner.js +385 -52
  304. package/lib/sketch/ui.d.ts +5 -8
  305. package/lib/workers/probe-worker.d.ts +5 -0
  306. package/lib/workers/probe-worker.js +13 -4
  307. package/lib/workers/protocol.d.ts +61 -13
  308. package/lib/workers/protocol.js +4 -0
  309. package/lib/workers/render-worker.js +25 -4
  310. package/lib/workers/sketch-worker.js +104 -15
  311. package/package.json +2 -2
@@ -8,7 +8,7 @@ summary: "createImpostors: far objects as camera-facing cards that blend the thr
8
8
 
9
9
  # Impostors
10
10
 
11
- > Roadmap step 0.2, first released in null3D 0.1.0. The API is experimental, so it can still change between versions. Not built yet: an `assets impostor` command that writes the atlases from a file. Coding agents must not use it yet.
11
+ > Roadmap step 0.2, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
12
12
 
13
13
  The demo "Impostors" in `examples/impostors` draws a pine forest three ways by distance. Level-of-detail meshes stand near, one merged mesh stands per grid cell in the middle, and cards baked from the pine stand far out. Press L there to draw the far band as meshes instead, and compare. The near meshes and the cards share the hand-over band.
14
14
 
@@ -41,14 +41,18 @@ bun add @null3d/engine @null3d/impostors
41
41
  import { createImpostors, octahedralAtlas } from '@null3d/impostors';
42
42
  import { defineSketch } from '@null3d/engine';
43
43
 
44
- export default defineSketch(({ scene, materials, geometry, assets }) => {
44
+ export default defineSketch(async ({ scene, materials, geometry, assets }) => {
45
45
  const camera = scene.createPerspectiveCamera({ position: [0, 8, 30], target: [0, 3, 0] });
46
46
  scene.setActiveCamera(camera);
47
47
 
48
- // The atlases hold the object's views. `bakeImpostorAtlas` makes them, or a tool writes them.
48
+ // The atlases hold the object's views. `bakeImpostorAtlas` makes them in the sketch, or
49
+ // `bunx @null3d/cli assets impostor` writes them ahead of time.
49
50
  const atlas = octahedralAtlas(8);
50
- const color = await assets.loadTexture('forest-tree-impostor.png');
51
- const surface = await assets.loadTexture('forest-tree-impostor-surface.png');
51
+ const color = await assets.loadTexture('forest-tree-impostor-color.png', { mipmaps: false });
52
+ const surface = await assets.loadTexture('forest-tree-impostor-surface.png', {
53
+ colorSpace: 'linear',
54
+ mipmaps: false,
55
+ });
52
56
  const positions = new Float32Array(20_000 * 3);
53
57
  const turns = new Float32Array(20_000);
54
58
  for (let i = 0; i < 20_000; i++) {
@@ -102,8 +106,119 @@ const surface = textures.fromData({ ...bake.surface, colorSpace: 'linear', mipma
102
106
 
103
107
  The bake is arithmetic over the arrays. It gives the same pixels on every device, and it needs no GPU pass, so a scene's fog and lights never color the picture. It returns the card's `size`: the width that holds the object's widest horizontal reach, and its full height. A card at scale 1 stands on the object's lowest point. Each picture also holds the object from above, so it is taller than that height by the bake's `room`, which `createImpostors` takes as `room`. A picture that you paint yourself fills its card, and takes the default of 1.
104
108
 
109
+ ## Load a baked atlas
110
+
111
+ A bake in the sketch costs time at each start. `bunx @null3d/cli assets impostor` runs the same bake ahead of time, on a glTF model. It writes a JSON file and the two atlases as PNG images ([the `null3d` command](../cli/null3d.md#assets)). `loadImpostorAtlas(assets, url)` loads the three files. It returns the two textures, the grid, and the card's `size`, `room` and `depth`. These are the fields that `createImpostors` takes from a bake:
112
+
113
+ ```sh
114
+ bunx @null3d/cli assets impostor models/pine.glb --out public/trees
115
+ ```
116
+
117
+ ```ts
118
+ import { createImpostors, loadImpostorAtlas } from '@null3d/impostors';
119
+
120
+ const pine = await loadImpostorAtlas(assets, 'trees/pine-impostor.json');
121
+ const trees = createImpostors(
122
+ { scene, materials, geometry },
123
+ { ...pine, positions, turn: turns, alphaMode: 'mask' },
124
+ );
125
+ ```
126
+
127
+ The images load from the JSON file's folder, with no mipmaps. The color atlas loads in sRGB, and the surface atlas loads linear. The files hold the same texels as a bake in the sketch, for the same model, grid and texels. The loader throws when the JSON file is not an impostor atlas file. It also throws for a version of the format that the package does not read. Bake the model again with the command of the same version.
128
+
129
+ The command reads the model's base color factors and textures, alpha modes and cutoffs, and double-sided flags. A part that needs more, such as a leaf atlas's cells, bakes in the sketch with `bakeImpostorAtlas`.
130
+
105
131
  The bake stores each point's normal in the object's own frame. At draw time the card turns that normal by the copy's turn and lights it, so a turned copy lights as its turned mesh does. The bake reads the mesh's own normals, and makes them where the part gives none.
106
132
 
133
+ ## Make a card read as its mesh
134
+
135
+ A card that draws a different picture from its mesh reads as another species. The difference shows
136
+ most in how the crown lights, not in its outline. The island's trees once baked a card as one unlit
137
+ side view, with one outward-and-up normal over each face and no normal bake. Measured against its
138
+ mesh at the hand-over, that card was 34 to 79 per cent brighter. Its crown's shading spread was 31
139
+ to 44 per cent lower, and its trunk 54 to 185 per cent brighter in red and green. Without the sun
140
+ the same card was darker than its mesh. The baked color was sound; the card lit as no surface of the
141
+ tree does.
142
+
143
+ The bake decides the result:
144
+
145
+ - Bake the mesh that the card replaces. Use the full level when the card stands for it, or the
146
+ coarsest level that draws before it, at the size that the card draws.
147
+ - Bake the color unlit, in sRGB, and with no sun. The engine lights the card, so a baked sun doubles
148
+ the light and fixes it to one hour.
149
+ - Store a normal for every texel, in the object's own frame, in the surface atlas. Without it a card
150
+ catches the sun everywhere. It reads flat and bright, and its trunk lights like a crown.
151
+ - Store enough views that no direction lies far from one. One side view shared by every face shows
152
+ the same picture from every side, and cannot light by direction. The octahedral grid's cells sit
153
+ widely: a four by four grid holds 53 degrees at worst and five by five holds 42.5. A far crown
154
+ needs about five by five cells, and ten by ten hold 23 degrees.
155
+ - Choose the texels in a cell against the card's apparent size. A crown that covers about 80 pixels
156
+ wants 32 to 64 texels across its cell.
157
+ - Take the bake's `size` and its foot. A card at scale 1 stands on the object's lowest point. A card
158
+ pivoted at its middle sinks into the ground.
159
+ - Bake the views with the engine's baker unless the card stays tiny. `bakeImpostorAtlas` draws a
160
+ real grid of views and stores a normal for every texel, so a card blends the views nearest the
161
+ eye and lights as its mesh does from every direction. A hand-painted side view cannot: it shows
162
+ the same picture from every side, and a hand-painted top picture on a horizontal plane reads as a
163
+ flat plate at a shallow sight. Keep a hand bake only for a card that never covers more than a few
164
+ tens of pixels. The island's showcase cards reached 140 to 215 pixels at their switch, and their
165
+ hand bakes read as stacked plates there; the engine's bake is their card now.
166
+ - Check a card beside its mesh before accepting it. Draw both at one pose under one light, and crop
167
+ each to the same size. Compare the mean color per channel within 10 per cent. Compare the
168
+ silhouette's area within 10 per cent, and the crown's shading spread within 25 per cent. A card
169
+ outside those limits reads as another tree at the distance where it appears.
170
+
171
+ ## Bake several views, not one side
172
+
173
+ A card's picture is what the player sees of the object, so it should hold as many views as the
174
+ card's apparent size needs. `bakeImpostorAtlas` draws the mesh from every cell of an octahedral
175
+ grid; the cell's square of texels holds the color, and the surface atlas holds each texel's normal
176
+ in the object's own frame with its depth and its coverage. `createImpostors` blends the three views
177
+ nearest the eye and lights the blend from those normals, so a card turns with the camera and still
178
+ catches the sun on the side the mesh would.
179
+
180
+ Two numbers decide the picture:
181
+
182
+ - **Views.** The grid's cells sit 53 degrees apart at worst on four by four, 42.5 on five by five,
183
+ and 23 on ten by ten. More views smooth the blend as the eye turns; a far crown wants about five
184
+ by five, and a card the size of a landmark wants ten by ten.
185
+ - **Texels.** A cell's texels should cover the card's pixels about one for one. A card 80 pixels
186
+ across wants 32 to 64 texels a cell, and one 215 pixels across wants about 128 to 256. The atlas
187
+ grows with the square of the texels, and each object takes two atlases.
188
+
189
+ The island's five plants bake a five by five grid at 128 texels a cell: two 640-square atlases a
190
+ plant, 3.3 MB of texture apiece at four bytes a texel, and a tenth to four tenths of a second a
191
+ plant in its build.
192
+
193
+ ```ts
194
+ import { bakeImpostorAtlas, octahedralAtlas } from '@null3d/impostors';
195
+
196
+ const bake = bakeImpostorAtlas({
197
+ atlas: octahedralAtlas(25), // five by five views, 42.5 degrees apart at worst
198
+ texels: 128, // a card up to about 215 pixels across
199
+ parts: [
200
+ {
201
+ positions,
202
+ normals,
203
+ uvs,
204
+ indices,
205
+ colors, // the vertex colors that the mesh's material multiplies in
206
+ color: leafMap, // the base color picture, sRGB
207
+ coverage: leafAlpha, // the same picture's alpha, linear, in blue
208
+ alphaCutoff: 0.5,
209
+ doubleSided: true,
210
+ },
211
+ ],
212
+ min,
213
+ max,
214
+ });
215
+ const color = textures.fromData({ ...bake.color, colorSpace: 'srgb', wrap: 'clamp', mipmaps: false });
216
+ const surface = textures.fromData({ ...bake.surface, colorSpace: 'linear', wrap: 'clamp', mipmaps: false });
217
+ // Stand the copies with the bake's own figures:
218
+ // createImpostors(ctx, { color, surface, atlas: bake.atlas, positions, size: bake.size,
219
+ // room: bake.room, depth: bake.depth })
220
+ ```
221
+
107
222
  ## Hand the near meshes over to the cards
108
223
 
109
224
  `handOverToCards(meshes, cards, switchDistance, start)` sets the distance bands of a batch of near meshes and the batch of their cards. Call it once at setup, after you write the cards' sizes.
@@ -154,10 +269,6 @@ for (const group of farCellGroups(centers, 64)) {
154
269
 
155
270
  The merged arrays carry `levels: 'pieces'`, because a cell already draws each copy's coarsest level. So the engine plans no levels of its own for a cell's mesh. A cell of 32,768 triangles or more still sorts its triangles into pieces by space at its first draw, so the view leaves out the parts of the cell that lie outside it. Give the cell `{ ...merged, levels: true }` to plan levels for it anyway, or `levels: false` for neither.
156
271
 
157
- ## Compared with three.js
158
-
159
- three.js has no impostor or merged-far-geometry helper. Its `LOD` picks one whole object by distance, which null3D does with [`mesh.setLevels`](geometry.md). Build the atlases and the merged meshes outside a three.js renderer too, and draw the cards as `InstancedMesh` of one quad with a `ShaderMaterial`, and the merged mesh as a `Mesh`.
160
-
161
272
  ## API reference
162
273
 
163
274
  [The API reference](reference/impostors.md) lists every export of this page with its type and description. The package's doc comments make it.
package/docs/api/input.md CHANGED
@@ -8,7 +8,7 @@ summary: "Pointer, keyboard, touch and gamepad; action maps; pointer events on o
8
8
 
9
9
  # Input
10
10
 
11
- > Roadmap step 0.1, first released in null3D 0.1.0. Step 0.2 adds pointer events on objects and the pointer lock. The API is experimental, so it can still change between versions.
11
+ > Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
12
12
 
13
13
  ```mermaid
14
14
  flowchart LR
@@ -75,14 +75,14 @@ The sketch counts presses and releases per frame. A key can go down and up betwe
75
75
  | `dx`, `dy` | The movement since the previous frame, in CSS pixels |
76
76
  | `dragDx`, `dragDy` | The part of `dx` and `dy` made while a button was held. Movement before a press or after a release in the same frame does not count. |
77
77
  | `buttons` | The buttons held, as `PointerEvent.buttons` gives them: 1 for the main button, 2 for the right button and 4 for the middle button, added together |
78
- | `wheel` | The wheel's scroll since the previous frame, in pixels. It is positive where a page would scroll down. A line counts 16 pixels and a page 100, as three.js's controls count them. |
78
+ | `wheel` | The wheel's scroll since the previous frame, in pixels. It is positive where a page would scroll down. A line counts 16 pixels and a page 100. |
79
79
  | `pinch` | The part of `wheel` that came from a pinch on a trackpad. It is positive as the fingers close. |
80
80
  | `isTouch` | True when the pointer is a finger |
81
81
  | `locked` | True while the canvas holds the pointer lock |
82
82
 
83
83
  Use `dragDx` and `dragDy` for drags, such as turning an object with the mouse. A frame can hold the end of a hover and the start of a drag, and `dx` counts both.
84
84
 
85
- A frame's drag belongs to one press. During a slow frame, one drag can end and the next can start before the sketch reads either. The next press and the events after it then wait for the following frame, so each drag keeps its own button and movement. Two quick clicks between two frames also count as two presses, one in each of the next two frames. Wheel scroll that follows a release waits for the following frame in the same way. So a frame's scroll never comes after the end of its drag. Controls that ignore the wheel during a drag, as three.js's do, still take the scroll after it.
85
+ A frame's drag belongs to one press. During a slow frame, one drag can end and the next can start before the sketch reads either. The next press and the events after it then wait for the following frame, so each drag keeps its own button and movement. Two quick clicks between two frames also count as two presses, one in each of the next two frames. Wheel scroll that follows a release waits for the following frame in the same way. So a frame's scroll never comes after the end of its drag. Controls that ignore the wheel during a drag still take the scroll after it.
86
86
 
87
87
  Browsers send a pinch on a trackpad as wheel scroll with the Control key's flag, while no Control key is down. Unless the page stops it, the browser also zooms the whole page on a pinch. [What the page does](#what-the-page-does) shows how to stop it.
88
88
 
@@ -140,6 +140,7 @@ export default defineSketch(({ scene, geometry, materials, page }) => {
140
140
  - A `click` goes to the closest object that was under the pointer at both the press and the release. A press on one child of a group and a release on another click the group.
141
141
  - `pointerenter` and `pointerleave` do not go on to parents: each object gets its own. A move from one child of a group to another leaves the first child and enters the second, and the group stays entered. Each `pointerenter` gets one `pointerleave` later, unless the object is destroyed or its handler is removed first.
142
142
  - A finger enters the object at its press, and leaves it after its release. A mouse or a pen that leaves the canvas leaves every object. An HTML element over the canvas counts as outside it.
143
+ - A click on nothing gives no event. To catch one, set a flag in your `click` handlers. In `onUpdate`, add up `input.dragDx` and `input.dragDy` from the press. A release with no flag set is a click on nothing, unless the pointer moved more than a click allows.
143
144
 
144
145
  ### When handlers run
145
146
 
@@ -170,14 +171,6 @@ The engine passes one event object to every handler and reuses it, so copy any v
170
171
 
171
172
  In a frame in which no object listens, pointer events cast no ray and copy nothing. Otherwise each event casts one ray, which takes one to three microseconds in a scene of 20,000 objects. The first ray in a frame also updates the scene's trees, as any query does. The engine casts only the rays that the handlers need: with only `click` handlers, a move casts none. Moves of one pointer that follow each other in a frame share one ray.
172
173
 
173
- ### Compared with three.js
174
-
175
- three.js has no pointer events on objects. An app adds DOM listeners to the canvas, then calls `Raycaster.setFromCamera` and `intersectObjects` in each one. In the sketch, `object.on` replaces both. react-three-fiber's mesh events map to `on`: `onClick` to `'click'`, `onPointerDown` to `'pointerdown'`, `onPointerEnter` to `'pointerenter'`, and so on. Three differences:
176
-
177
- - react-three-fiber casts rays only against objects with handlers. It passes an event to every one that the ray hits, nearest first, until a handler calls `stopPropagation`. null3D passes it to the closest object that the camera draws and to its parents only. So an object without handlers in front still takes the event.
178
- - react-three-fiber's `onClick` also comes after a drag, with the drag's length in `event.delta`. null3D gives no click after a drag of more than 2 CSS pixels, or 10 for a finger.
179
- - react-three-fiber's `onPointerMissed` has no equivalent. Set a flag in your `click` handlers, and in `onUpdate` treat `input.wasReleased('Mouse0')` without the flag as a click on nothing.
180
-
181
174
  ## Actions
182
175
 
183
176
  An action names a list of keys and buttons, so the sketch asks for `jump` instead of each key. Players can then use a keyboard, a gamepad or a touch control for the same action.
@@ -8,7 +8,7 @@ summary: "Directional, point, spot, hemisphere, ambient, rectangle and tube ligh
8
8
 
9
9
  # Lights
10
10
 
11
- > Roadmap step 0.1, first released in null3D 0.1.0. Step 0.2 adds the light from the sky, the light of hemisphere lights, rectangle and tube lights and contact shadows. Step 0.3 adds pictures that a spot light projects over its cone. The API is experimental, so it can still change between versions. Surfaces show up to four directional lights: the first casts the shadows, and three more add fill and rim light.
11
+ > Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions. Surfaces show up to four directional lights: the first casts the shadows, and three more add fill and rim light.
12
12
 
13
13
  A light is a scene object, like a mesh or a camera. It has a position, a rotation, a parent and layers, and `setVisible` and `destroy` work on it. Each kind of light has a class and a create call of its own. The standard material reflects lights, and the unlit material ignores them.
14
14
 
@@ -75,7 +75,7 @@ export default defineSketch(({ scene, materials, geometry }) => {
75
75
  ```
76
76
 
77
77
  - The picture fills the square that bounds the cone: a circle in the middle of the picture lands on the cone's edge, where the light ends.
78
- - The picture's top row lies along the world's up, as three.js aims the camera that projects a spot light's map. Aim the light first: turning the light turns the picture with it, and rolling the light about its own axis leaves the picture as it is.
78
+ - The picture's top row lies along the world's up. Aim the light first: turning the light turns the picture with it, and rolling the light about its own axis leaves the picture as it is.
79
79
  - The color and intensity tint the picture: a dark part of it gives less light, and a red part gives red light. `setMap(null)` goes back to one color.
80
80
  - The map is sRGB pixels, four bytes each with the top row first, or a texture. The engine copies a texture into the light's picture once, when the texture's texels reach the GPU, so a later change to the texture does not reach the light: give a still texture. A video's texture and a render pass's texture change every frame, and a 3D or cube texture holds more than one image, so each throws E1112.
81
81
  - The engine keeps the picture's detail up to 512 texels a side, in every mip level, and reduces a larger texture to that. A small gobo therefore costs less memory than a detailed photograph of the same light. A surface far from the light shows the picture blurred and a surface near the light shows it sharp. Up to 32 lights show pictures at once, and rectangle and spot lights share those places. A new picture takes up to a few tens of milliseconds, so set it at setup or now and then.
@@ -95,15 +95,15 @@ Code that draws a picture, such as a canvas or a generated pattern, gives its sR
95
95
 
96
96
  Each color is a hex string or a number, which are sRGB, or three linear components from 0 to 1. The default is white. The intensity scales the color, and the default is 1. A hemisphere light's intensity scales both of its colors.
97
97
 
98
- Units follow three.js since r155. The intensity of a point or spot light is in candela. A directional light's intensity is in lux: the light that reaches a surface facing it. The standard material uses the lighting formulas of three.js's `MeshStandardMaterial`, so the same colors and intensities give the same result in both engines. Take a white directional light with an intensity of π, about 3.14, and no ambient light. A rough surface that faces it shows nearly its full color. [Lighting and environment](../concepts/lighting.md#units-and-exposure) covers the units in full.
98
+ The intensity of a point or spot light is in candela. A directional light's intensity is in lux: the light that reaches a surface facing it. Take a white directional light with an intensity of π, about 3.14, and no ambient light. A rough surface that faces it shows nearly its full color. [Lighting and environment](../concepts/lighting.md#units-and-exposure) covers the units in full.
99
99
 
100
100
  The `intensityUnit` option names another unit for the intensity and for `setIntensity`:
101
101
 
102
102
  | Light | `intensityUnit` | What the engine does |
103
103
  | --- | --- | --- |
104
- | Point | `'lumen'` | Divides by 4π, as three.js's `PointLight.power` does |
105
- | Spot | `'lumen'` | Divides by π at any cone angle, as three.js's `SpotLight.power` does |
106
- | Directional, hemisphere, ambient | `'lux'` | Nothing: lux is three.js's unit for these lights |
104
+ | Point | `'lumen'` | Divides by 4π, the whole sphere |
105
+ | Spot | `'lumen'` | Divides by π at any cone angle, so a narrower cone keeps its brightness |
106
+ | Directional, hemisphere, ambient | `'lux'` | Nothing: these lights take lux already |
107
107
 
108
108
  A light in lumens with no `intensity` gives 1 lumen. A unit that the light does not take throws [E1213](../errors/E1213.md). Lights in real units need a camera exposure to match, such as `post.set({ ev100: 15 })` for a sunny day:
109
109
 
@@ -124,8 +124,6 @@ Every setter allocates nothing, `setColor` and `setGroundColor` included. So `on
124
124
 
125
125
  ## Which lights reach surfaces
126
126
 
127
- In this version:
128
-
129
127
  - Surfaces show up to four directional lights that are visible and share a layer with the camera: the first four you created. The first one lights and casts the shadows. The next three light as fill and rim lights, without shadows. A fifth directional light gives no light.
130
128
  - Every ambient light that is visible and shares a layer with the camera adds its light.
131
129
  - Point and spot lights light the surfaces that their ranges reach. Each frame the engine finds the ones whose ranges reach into the camera's view. It lists each one in the clusters of the view that it reaches. The camera lists up to 1,024 of them, the nearest, and up to 128 in each cluster. [Lighting and environment](../concepts/lighting.md#clustered-forward-shading) explains clusters.
@@ -133,11 +131,11 @@ In this version:
133
131
  - Every hemisphere light that is visible and shares a layer with the camera adds its light. [Hemisphere lights](#hemisphere-lights) says how.
134
132
  - Without lights, standard materials draw black.
135
133
 
136
- To turn a light off, hide it with `setVisible(false)`, set its intensity to 0, or destroy it. A light lights a camera's view only when their layer masks share a bit, as in three.js. [Render layers](../concepts/render-layers.md) explains masks. The light's mask also picks the objects that cast its shadows: an object on a layer that the light lacks casts none ([Layers and shadows](../concepts/render-layers.md#layers-and-shadows)).
134
+ To turn a light off, hide it with `setVisible(false)`, set its intensity to 0, or destroy it. A light lights a camera's view only when their layer masks share a bit. [Render layers](../concepts/render-layers.md) explains masks. The light's mask also picks the objects that cast its shadows: an object on a layer that the light lacks casts none ([Layers and shadows](../concepts/render-layers.md#layers-and-shadows)).
137
135
 
138
136
  ## Area lights
139
137
 
140
- A rectangle light glows over its whole area, like a shop window, a screen or a studio's soft box. A tube light glows along a tube, like a neon sign or a fluorescent lamp. A point light gives a shiny surface a small dot of light. An area light gives it the light's whole shape, stretched along the surface as on a wet street, and lights a rough surface softly. The engine shades them with linearly transformed cosines, as three.js shades its `RectAreaLight`, so a rectangle light gives three.js's look.
138
+ A rectangle light glows over its whole area, like a shop window, a screen or a studio's soft box. A tube light glows along a tube, like a neon sign or a fluorescent lamp. A point light gives a shiny surface a small dot of light. An area light gives it the light's whole shape, stretched along the surface as on a wet street, and lights a rough surface softly. The engine shades them with linearly transformed cosines, the method of Heitz, Dupuy, Hill and Neubelt.
141
139
 
142
140
  ```ts
143
141
  import { defineSketch } from '@null3d/engine';
@@ -153,10 +151,10 @@ export default defineSketch(({ scene, materials, geometry }) => {
153
151
  });
154
152
  ```
155
153
 
156
- - The intensity is the brightness of the light's surface, in nits, as three.js's `RectAreaLight` takes it. A larger light of the same intensity gives more light.
154
+ - The intensity is the brightness of the light's surface, in nits. A larger light of the same intensity gives more light.
157
155
  - A rectangle light's light leaves the side that its -Z axis points to. Surfaces behind it get none. `width` runs along its X axis and `height` along its Y axis, and both default to 1 meter.
158
156
  - A tube light shines all around. `length` runs along its -Z axis, and defaults to 1 meter. `radius` defaults to 0.025 meters, a thin neon tube. The ends of the tube add no light, which a thin tube does not show.
159
- - Area lights need a `range`, as point and spot lights do. The light fades to nothing at the range from the light's middle. three.js's `RectAreaLight` has no range: pick the distance where the light no longer matters.
157
+ - Area lights need a `range`, as point and spot lights do. The light fades to nothing at the range from the light's middle. Pick the distance where the light no longer matters.
160
158
  - A rectangle light can show a picture over its area, such as a shop window or a screen. The `image` option and `setImage({ width, height, data })` take sRGB pixels, four bytes each, top row first. The light then varies over its area: a puddle shows the picture, and a rough wall gets its blurred colors. The color and intensity tint the picture. The light gives out its intensity times the picture's average color, in linear light. A mostly dark picture, such as thin neon tubes on black, lights little around it. Keep the intensity at the tubes' brightness, and paint a faint glow around the tubes to light more. The engine keeps the picture's detail up to 512 texels a side, in every mip level. Up to 32 lights show pictures at once, and `setImage(null)` goes back to one color. A new picture allocates and takes up to a few tens of milliseconds, so set it at setup or now and then.
161
159
  - `setSize`, `setRange`, `setDirection` and `setIntensity` take effect in the next frame and allocate nothing.
162
160
  - Area lights cast no shadows. Use a spot light beside one for a shadow.
@@ -167,7 +165,7 @@ export default defineSketch(({ scene, materials, geometry }) => {
167
165
 
168
166
  ## Hemisphere lights
169
167
 
170
- A hemisphere light gives a cheap fill light from the sky and the ground. A surface that faces up gets the sky color, and a surface that faces down gets the ground color. A surface between them gets a blend. The blend follows the angle between the surface's normal and the light's +Y axis, as three.js's `HemisphereLight` blends it. The light is diffuse only: it gives no highlights, as in three.js.
168
+ A hemisphere light gives a cheap fill light from the sky and the ground. A surface that faces up gets the sky color, and a surface that faces down gets the ground color. A surface between them gets a blend. The blend follows the angle between the surface's normal and the light's +Y axis. The light is diffuse only: it gives no highlights.
171
169
 
172
170
  ```ts
173
171
  import { defineSketch } from '@null3d/engine';
@@ -187,7 +185,7 @@ export default defineSketch(({ scene, time }) => {
187
185
 
188
186
  - Any number of hemisphere lights add up. The engine sums them on the CPU into the ambient light and one color per world axis. So each pixel pays three multiply-adds, however many lights there are, and the same with none.
189
187
  - `setIntensity`, `setColor` (the sky color) and `setGroundColor` take effect in the next frame. Turning the light turns its sky.
190
- - An environment's light adds to the hemisphere lights' light, as in three.js. The environment's `intensity` and a material's `envIntensity` scale only the environment's light, never a hemisphere light's. This holds for every environment: a file's, the built-in room and the sky's.
188
+ - An environment's light adds to the hemisphere lights' light. The environment's `intensity` and a material's `envIntensity` scale only the environment's light, never a hemisphere light's. This holds for every environment: a file's, the built-in room and the sky's.
191
189
  - The occlusion map and ambient occlusion darken a hemisphere light's light, as they darken an ambient light's.
192
190
  - Scene passes and reflection passes draw with the hemisphere lights too.
193
191
 
@@ -211,7 +209,7 @@ export default defineSketch(async ({ scene, assets }) => {
211
209
 
212
210
  ## Shadows
213
211
 
214
- `castShadows: true` and `setCastShadows(true)` make a directional light cast shadows. The first directional light created casts them, and objects need `castShadows` and `receiveShadows` of their own. The `shadow` option and `setShadow` set the light's cascades, map size, distance and biases:
212
+ `castShadows: true` and `setCastShadows(true)` make a directional light cast shadows. The first directional light created casts them, and objects need `castShadows` and `receiveShadows` of their own. The `shadow` option and `setShadow` set the light's cascades, map size, distance and biases, and `intensity`, how much of the shadow it draws, from 0 to 1:
215
213
 
216
214
  ```ts
217
215
  const sun = scene.createDirectionalLight({
@@ -225,7 +223,7 @@ sun.setShadow({ bias: 0.02, normalBias: 0.04 });
225
223
 
226
224
  The `distance` default is `'auto'`. The engine follows the farthest surface that receives shadows in the camera's view, rounded up on a ladder. A small scene then gets sharper shadows without naming a distance. Pass a number to fix it, as a port of a scene with its own shadow distance does. See [Shadows](../concepts/shadows.md#settings).
227
225
 
228
- Spot and point lights cast shadows with `castShadows` too. Their `shadow` option and `setShadow` take the biases alone:
226
+ Spot and point lights cast shadows with `castShadows` too. Their `shadow` option and `setShadow` take the biases and `intensity` alone:
229
227
 
230
228
  ```ts
231
229
  const lamp = scene.createSpotLight({
@@ -255,28 +253,6 @@ The object must cast shadows. Its tile comes from the same atlas as the spot and
255
253
 
256
254
  [Shadows](../concepts/shadows.md) explains cascades, contact shadows, hero shadows, the shadow atlas of spot and point lights, each setting and its default, and the biases.
257
255
 
258
- ## Coming from three.js
259
-
260
- | three.js | null3D |
261
- | --- | --- |
262
- | `new DirectionalLight(color, intensity)` with a position and a target | `createDirectionalLight({ color, intensity, direction })`, with the target minus the position as `direction`, or `lookAt(target)` |
263
- | `light.target = object`, which the light follows | Call `light.lookAt(x, y, z)` with the object's position when it moves |
264
- | `new PointLight(color, intensity, distance, decay)` | `createPointLight({ color, intensity, range: distance, decay })` |
265
- | `new SpotLight(color, intensity, distance, angle, penumbra, decay)` | `createSpotLight({ color, intensity, range: distance, angle, penumbra, decay, target: [x, y, z] })` |
266
- | `new HemisphereLight(skyColor, groundColor, intensity)` | `createHemisphereLight({ skyColor, groundColor, intensity })`. three.js points the sky from the light's position toward the origin, and null3D along the light's +Y axis, so turn the light where three.js moves it |
267
- | `new AmbientLight(color, intensity)` | `createAmbientLight({ color, intensity })` |
268
- | `new RectAreaLight(color, intensity, width, height)`, with `RectAreaLightUniformsLib.init()` | `createRectAreaLight({ color, intensity, width, height, range })`, with no setup call. It needs a `range` |
269
- | `scene.environment = pmremGenerator.fromScene(skyScene).texture`, again after each change of the sky | `scene.setEnvironment(await assets.skyEnvironment())` once: the map follows `setBackground({ sky })` |
270
- | `pointLight.power = lumens` or `spotLight.power = lumens` | `intensity: lumens, intensityUnit: 'lumen'` at create; `setIntensity` then takes lumens |
271
- | `scene.add(light)` or `group.add(light)` | Nothing for the scene; the `parent` option or `setParent(group)` for a group |
272
- | `light.visible = false` | `light.setVisible(false)` |
273
- | `light.castShadow = true`, `light.shadow.mapSize`, `light.shadow.bias` | `castShadows: true`, and `shadow: { mapSize, bias, normalBias, intensity }`, both biases in meters. [Shadows](../concepts/shadows.md) covers the differences. |
274
- | A second shadowed light fitted to one object, or a hand-fitted `DirectionalLight` shadow camera, for a sharper close-up shadow | `sun.setShadow({ hero: object })`: the light gives the object a fitted shadow map of its own, and follows it |
275
- | `spotLight.castShadow = true` or `pointLight.castShadow = true`, and `shadow.bias` | `castShadows: true`, and `shadow: { bias, normalBias, intensity }` in meters. The quality preset sets the tile size. |
276
- | `spotLight.map = texture` | `map: texture` at create, or `setMap(texture)`: the engine copies the texture into its own light image once. `setMap({ width, height, data })` takes sRGB pixels instead. `setMap(null)` goes back to one color |
277
-
278
- A three.js `distance` of 0 means a light with no end. null3D needs a finite range, so pick the distance where the light no longer matters.
279
-
280
256
  ## Related pages
281
257
 
282
258
  - [Lighting and environment](../concepts/lighting.md): light units, and how the engine finds each frame's lights.
package/docs/api/lines.md CHANGED
@@ -8,7 +8,7 @@ summary: "createLines; strips, loops and pairs; pixel and world widths; dashes;
8
8
 
9
9
  # Lines
10
10
 
11
- > Roadmap step 0.2, first released in null3D 0.1.0. The API is experimental, so it can still change between versions. Lines do not cast or receive shadows, and overlap queries do not find them. Coding agents must not rely on either.
11
+ > Roadmap step 0.2, first released in null3D 0.1.0. The API is experimental, so it can still change between versions. Lines do not cast or receive shadows, and overlap queries do not find them.
12
12
 
13
13
  ```mermaid
14
14
  flowchart LR
@@ -114,7 +114,7 @@ The call `lines.material.set` changes the look of every segment at any time. It
114
114
 
115
115
  Point `i` starts at index `i * 3` in both arrays. Both are `Float32Array` views of engine memory, and the rules of [instance batches](../concepts/instances.md#the-row-arrays) apply. Read the arrays from the batch each time you use them, such as at the start of `onUpdate`. A view from before the engine's memory grew can be empty.
116
116
 
117
- A segment blends from the color of its first point to the color of its second. The engine stores each point's color with 8 bits for each channel, in sRGB. So colors from 0 to 1 draw, and colors given as sRGB hex strings come back exactly. For a brighter line, for [bloom](post.md), set a `color` above 1 on the material, or use a lit line with `emissive`. Convert an sRGB color, such as a hex string, with `color.fromHex` from the [math helpers](math.md).
117
+ A segment blends from the color of its first point to the color of its second. The engine stores each point's color with 8 bits for each channel, in sRGB. So colors from 0 to 1 draw, and colors given as sRGB hex strings come back exactly. A `color` on the material takes components from 0 to 1, as every color does. For a line brighter than 1, for [bloom](post.md), use a lit line with `emissive` and an `emissiveIntensity` above 1. Give it a black `color`, so the scene's lights add nothing. Convert an sRGB color, such as a hex string, with `color.fromHex` from the [math helpers](math.md).
118
118
 
119
119
  ## Static and dynamic batches
120
120
 
@@ -128,21 +128,21 @@ With `worldUnits: false`, the default, the width is in CSS pixels, at every dist
128
128
 
129
129
  With `worldUnits: true`, the width is in world units. A line 0.1 units wide is as wide as a rod 0.1 units thick at the same distance, so far lines look thinner. Use it for roads, cables and beams that belong to the world.
130
130
 
131
- The engine culls each segment by a sphere around it. With a width in world units, the sphere holds the whole width. A width in pixels has no size in the world, so the sphere holds the segment's center line alone, as three.js's bounds do. A segment whose center line lies just outside the view can then lose the part of its width that reaches into it.
131
+ The engine culls each segment by a sphere around it. With a width in world units, the sphere holds the whole width. A width in pixels has no size in the world, so the sphere holds the segment's center line alone. A segment whose center line lies just outside the view can then lose the part of its width that reaches into it.
132
132
 
133
133
  ## Dashes
134
134
 
135
- A dashed line draws `dashSize` along the line, then leaves a gap of `gapSize`, from the start of its first segment. Both count in world units along the line, times `dashScale`. `dashOffset` moves the dashes along the line. Dashed lines have flat ends with no round caps, as in three.js.
135
+ A dashed line draws `dashSize` along the line, then leaves a gap of `gapSize`, from the start of its first segment. Both count in world units along the line, times `dashScale`. `dashOffset` moves the dashes along the line. Dashed lines have flat ends with no round caps.
136
136
 
137
137
  The engine keeps each segment's distance along the line. When a point of a static dashed batch moves, the update finds the distances again from that point to the end, one segment after another. A long dashed line that changes every frame costs more than one without dashes.
138
138
 
139
139
  ## Lit lines
140
140
 
141
- `lit: true` shades the lines as a [standard material](materials.md) shades a surface that faces the camera, with the line's color as its base color. The sun, the point and spot lights near each segment and the ambient and hemisphere lights light it, and `emissive` adds light of its own. Lines without `lit` draw their color as it is, as three.js's line materials do. Both kinds take the scene's fog.
141
+ `lit: true` shades the lines as a [standard material](materials.md) shades a surface that faces the camera, with the line's color as its base color. The sun, the point and spot lights near each segment and the ambient and hemisphere lights light it, and `emissive` adds light of its own. Lines without `lit` draw their color as it is, whatever the lights. Both kinds take the scene's fog.
142
142
 
143
143
  ## Blending, sorting and depth
144
144
 
145
- Blended lines draw after the opaque objects, farthest first, in the same transparent pass as other blended objects. The engine sorts each segment by the depth of its middle in the camera's view. Where two segments of one blended line meet, their round ends overlap and blend twice, as in three.js. A line that blends with `blending: 'additive'` and `depthWrite: false` needs no exact order to look right.
145
+ Blended lines draw after the opaque objects, farthest first, in the same transparent pass as other blended objects. The engine sorts each segment by the depth of its middle in the camera's view. Where two segments of one blended line meet, their round ends overlap and blend twice. A line that blends with `blending: 'additive'` and `depthWrite: false` needs no exact order to look right.
146
146
 
147
147
  ## Debug lines
148
148
 
@@ -150,30 +150,13 @@ Blended lines draw after the opaque objects, farthest first, in the same transpa
150
150
 
151
151
  ## Clicks and raycasts
152
152
 
153
- A raycast hits a segment when the ray passes within half the line's width of it, as three.js's `Raycaster` hits a `Line2`. The width counts in pixels on the screen or in world units, as the line draws. The hit's `object` is the batch, and its `instance` is the segment. A line batch takes `lines.on('click', handler)` and the other [pointer events on objects](input.md#pointer-events-on-objects), as an instance batch does. The `lineThreshold` option changes the test: a ray then hits a segment within that many meters, whatever the line's width. A ray hits a dashed line in its gaps too. [Raycasting](raycast.md#sprites-points-and-lines) has the details.
153
+ A raycast hits a segment when the ray passes within half the line's width of it. The width counts in pixels on the screen or in world units, as the line draws. The hit's `object` is the batch, and its `instance` is the segment. A line batch takes `lines.on('click', handler)` and the other [pointer events on objects](input.md#pointer-events-on-objects), as an instance batch does. The `lineThreshold` option changes the test: a ray then hits a segment within that many meters, whatever the line's width. A ray hits a dashed line in its gaps too. [Raycasting](raycast.md#sprites-points-and-lines) has the details.
154
154
 
155
155
  ## Speed
156
156
 
157
157
  A segment costs about as much as an instance row on the GPU and in culling. The engine packs each segment into the data that it keeps for an instance row. So segments share the culling, sorting and drawing of instance batches. One batch of 100,000 segments draws in one draw on WebGPU and WebGL2.
158
158
 
159
- Every segment counts toward the device's limit of objects and instance rows, as an instance row does ([Instances and batching](../concepts/instances.md#limits)). Each point takes about 170 bytes of engine memory. Line batches count toward the limit of 256 instance batches.
160
-
161
- ## Compared with three.js
162
-
163
- | three.js | null3D |
164
- | --- | --- |
165
- | `new Line2(geometry, new LineMaterial({ linewidth }))` with `LineGeometry.setPositions` | `scene.createLines({ positions, width })` |
166
- | `new LineSegments2(...)` with `LineSegmentsGeometry` | `mode: 'segments'` |
167
- | `new THREE.Line(geometry, new THREE.LineBasicMaterial())` | `scene.createLines({ positions })`: a strip 1 pixel wide |
168
- | `THREE.LineSegments` and `THREE.LineLoop` | `mode: 'segments'` and `mode: 'loop'` |
169
- | `geometry.setColors(colors)` with `vertexColors: true` | `colors`, 3 numbers per point |
170
- | `material.linewidth` | `width`, and `lines.setWidth` |
171
- | `material.worldUnits` | `worldUnits` |
172
- | `material.dashed`, `dashSize`, `gapSize`, `dashScale`, `dashOffset` | The same names; `dashed` is fixed when the batch is created |
173
- | `LineDashedMaterial` with `line.computeLineDistances()` | `dashed: true`; the engine keeps the distances |
174
- | `material.resolution` | Not needed: the engine knows the canvas size |
175
-
176
- three.js's `Line`, `LineSegments` and `LineLoop` draw lines one pixel wide on most GPUs, whatever `linewidth` says, and its `Line2` draws wider ones. null3D draws every width with the same quads, so a port of either keeps its look. three.js makes one object and one draw per line, and null3D draws a whole batch in one draw. three.js's `Raycaster` hits a `Line` within `params.Line.threshold`, 1 meter by default, whatever its width, and a `Line2` within half its width. null3D hits each line as `Line2` does, and the `lineThreshold` option gives the test for `Line`.
159
+ Every segment counts toward the device's limit of objects and instance rows, as an instance row does ([Instances and batching](../concepts/instances.md#limits)). Each point takes about 170 bytes of engine memory. Line batches count toward the limit of 512 instance batches.
177
160
 
178
161
  ## API reference
179
162