@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
@@ -9,8 +9,8 @@ export * from '../quat.js';
9
9
  export const setAxisAngle =
10
10
  /* @__PURE__ */ makeSetAxisAngle(Math.sin, Math.cos);
11
11
  /**
12
- * The rotation of Euler angles in radians, applied in `order`, `'XYZ'` by default, as three.js's
13
- * `setFromEuler`. gl-matrix's `fromEuler` takes degrees, but this one takes radians.
12
+ * The rotation of Euler angles in radians, applied in `order`, `'XYZ'` by default. gl-matrix's
13
+ * `fromEuler` takes degrees, but this one takes radians.
14
14
  */
15
15
  export const fromEuler = /* @__PURE__ */ makeFromEuler(Math.sin, Math.cos);
16
16
  /** Turns the rotation `a` by `rad` radians about its own X axis. */
@@ -24,7 +24,7 @@ export const rotateZ =
24
24
  /* @__PURE__ */ makeRotateZ(Math.sin, Math.cos);
25
25
  /**
26
26
  * The rotation a fraction `t` of the way from `a` to `b` along the shortest arc, turning at an even
27
- * speed, as three.js's `slerp`.
27
+ * speed.
28
28
  */
29
29
  export const slerp =
30
30
  /* @__PURE__ */ makeSlerp(Math.sin, Math.acos);
@@ -11,28 +11,24 @@ export declare function copy<T extends QuatLike>(out: T, a: QuatLike): T;
11
11
  /** Sets `out` to (0, 0, 0, 1), which turns nothing. */
12
12
  export declare function identity<T extends QuatLike>(out: T): T;
13
13
  /**
14
- * The rotation of the matrix `m`, whose upper 3 by 3 part must hold no scale, as three.js's
15
- * `setFromRotationMatrix`. To read the rotation of a matrix with scale, use `mat4.decompose`.
14
+ * The rotation of the matrix `m`, whose upper 3 by 3 part must hold no scale. To read the rotation
15
+ * of a matrix with scale, use `mat4.decompose`.
16
16
  */
17
17
  export declare function fromMat4<T extends QuatLike>(out: T, m: Mat4Like): T;
18
18
  /**
19
19
  * The rotation that turns an object at `eye` so that its +Z axis points at `target`, with its +Y
20
- * axis as close to `up` as it can be, or to +Y without `up`. A mesh looks at a point this way, in
21
- * null3D and in three.js. Cameras and lights look down their -Z axis instead: for them, swap `eye`
22
- * and `target`.
20
+ * axis as close to `up` as it can be, or to +Y without `up`. A mesh's `lookAt` turns it this way.
21
+ * Cameras and lights look down their -Z axis instead: for them, swap `eye` and `target`.
23
22
  */
24
23
  export declare function lookAt<T extends QuatLike>(out: T, eye: Vec3Like, target: Vec3Like, up?: Vec3Like): T;
25
24
  /**
26
- * The shortest rotation that turns the direction `a` onto the direction `b`, as three.js's
27
- * `setFromUnitVectors`. Both vectors must have length 1.
25
+ * The shortest rotation that turns the direction `a` onto the direction `b`. Both vectors must have
26
+ * length 1.
28
27
  */
29
28
  export declare function rotationTo<T extends QuatLike>(out: T, a: Vec3Like, b: Vec3Like): T;
30
- /**
31
- * The product of `a` and `b`, as three.js's `multiplyQuaternions`. It turns a vector by `b` first,
32
- * then by `a`.
33
- */
29
+ /** The product of `a` and `b`. It turns a vector by `b` first, then by `a`. */
34
30
  export declare function multiply<T extends QuatLike>(out: T, a: QuatLike, b: QuatLike): T;
35
- /** The rotation that undoes `a`, a quaternion of length 1, as three.js's `invert`. */
31
+ /** The rotation that undoes `a`, a quaternion of length 1. */
36
32
  export declare function invert<T extends QuatLike>(out: T, a: QuatLike): T;
37
33
  /** Scales `a` to length 1. A zero quaternion becomes (0, 0, 0, 1). */
38
34
  export declare function normalize<T extends QuatLike>(out: T, a: QuatLike): T;
package/lib/math/quat.js CHANGED
@@ -55,8 +55,8 @@ export function identity(out) {
55
55
  return out;
56
56
  }
57
57
  /**
58
- * The rotation of the matrix `m`, whose upper 3 by 3 part must hold no scale, as three.js's
59
- * `setFromRotationMatrix`. To read the rotation of a matrix with scale, use `mat4.decompose`.
58
+ * The rotation of the matrix `m`, whose upper 3 by 3 part must hold no scale. To read the rotation
59
+ * of a matrix with scale, use `mat4.decompose`.
60
60
  */
61
61
  export function fromMat4(out, m) {
62
62
  const m11 = m[0];
@@ -101,9 +101,8 @@ export function fromMat4(out, m) {
101
101
  }
102
102
  /**
103
103
  * The rotation that turns an object at `eye` so that its +Z axis points at `target`, with its +Y
104
- * axis as close to `up` as it can be, or to +Y without `up`. A mesh looks at a point this way, in
105
- * null3D and in three.js. Cameras and lights look down their -Z axis instead: for them, swap `eye`
106
- * and `target`.
104
+ * axis as close to `up` as it can be, or to +Y without `up`. A mesh's `lookAt` turns it this way.
105
+ * Cameras and lights look down their -Z axis instead: for them, swap `eye` and `target`.
107
106
  */
108
107
  export function lookAt(out, eye, target, up) {
109
108
  let zx = target[0] - eye[0];
@@ -149,8 +148,8 @@ export function lookAt(out, eye, target, up) {
149
148
  return fromMat4(out, basis);
150
149
  }
151
150
  /**
152
- * The shortest rotation that turns the direction `a` onto the direction `b`, as three.js's
153
- * `setFromUnitVectors`. Both vectors must have length 1.
151
+ * The shortest rotation that turns the direction `a` onto the direction `b`. Both vectors must have
152
+ * length 1.
154
153
  */
155
154
  export function rotationTo(out, a, b) {
156
155
  const ax = a[0];
@@ -176,10 +175,7 @@ export function rotationTo(out, a, b) {
176
175
  }
177
176
  return normalize(out, unscaled);
178
177
  }
179
- /**
180
- * The product of `a` and `b`, as three.js's `multiplyQuaternions`. It turns a vector by `b` first,
181
- * then by `a`.
182
- */
178
+ /** The product of `a` and `b`. It turns a vector by `b` first, then by `a`. */
183
179
  export function multiply(out, a, b) {
184
180
  const ax = a[0];
185
181
  const ay = a[1];
@@ -195,7 +191,7 @@ export function multiply(out, a, b) {
195
191
  out[3] = aw * bw - ax * bx - ay * by - az * bz;
196
192
  return out;
197
193
  }
198
- /** The rotation that undoes `a`, a quaternion of length 1, as three.js's `invert`. */
194
+ /** The rotation that undoes `a`, a quaternion of length 1. */
199
195
  export function invert(out, a) {
200
196
  out[0] = -a[0];
201
197
  out[1] = -a[1];
@@ -1,12 +1,11 @@
1
1
  /**
2
2
  * The next random number, from 0 up to but not including 1. Each thread has one generator, which
3
3
  * starts from an unpredictable seed. Hold mode seeds it, so a sketch that draws its numbers from it
4
- * draws the same frame on every run. The generator is mulberry32, as in three.js's `seededRandom`.
4
+ * draws the same frame on every run. The generator is mulberry32.
5
5
  */
6
6
  export declare function random(): number;
7
7
  /**
8
- * Starts `random` again from a seed, an integer. The same seed always gives the same numbers:
9
- * `math.seed(s)` followed by `math.random()` gives what three.js's `seededRandom(s)` gives.
8
+ * Starts `random` again from a seed, an integer. The same seed always gives the same numbers.
10
9
  */
11
10
  export declare function seed(value: number): void;
12
11
  /** A random number from `low` up to but not including `high`. */
@@ -27,7 +27,7 @@ function randomState() {
27
27
  /**
28
28
  * The next random number, from 0 up to but not including 1. Each thread has one generator, which
29
29
  * starts from an unpredictable seed. Hold mode seeds it, so a sketch that draws its numbers from it
30
- * draws the same frame on every run. The generator is mulberry32, as in three.js's `seededRandom`.
30
+ * draws the same frame on every run. The generator is mulberry32.
31
31
  */
32
32
  export function random() {
33
33
  const s = state ?? randomState();
@@ -38,8 +38,7 @@ export function random() {
38
38
  return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
39
39
  }
40
40
  /**
41
- * Starts `random` again from a seed, an integer. The same seed always gives the same numbers:
42
- * `math.seed(s)` followed by `math.random()` gives what three.js's `seededRandom(s)` gives.
41
+ * Starts `random` again from a seed, an integer. The same seed always gives the same numbers.
43
42
  */
44
43
  export function seed(value) {
45
44
  (state ?? randomState())[0] = value;
@@ -26,8 +26,8 @@ export type QuatLike = {
26
26
  [index: number]: number;
27
27
  };
28
28
  /**
29
- * A 4 by 4 matrix in an array of 16 numbers, stored column by column, as three.js and WebGPU store
30
- * matrices. Elements 12, 13 and 14 hold the translation.
29
+ * A 4 by 4 matrix in an array of 16 numbers, stored column by column, as WebGPU stores matrices.
30
+ * Elements 12, 13 and 14 hold the translation.
31
31
  *
32
32
  * @category api/math
33
33
  */
@@ -35,8 +35,8 @@ export type Mat4Like = {
35
35
  [index: number]: number;
36
36
  };
37
37
  /**
38
- * The axis order of Euler angles, with three.js's names. `'XYZ'` turns an object about its own X
39
- * axis, then its Y axis, then its Z axis.
38
+ * The axis order of Euler angles. `'XYZ'` turns an object about its own X axis, then its Y axis,
39
+ * then its Z axis.
40
40
  *
41
41
  * @category api/math
42
42
  */
@@ -13,7 +13,7 @@ export declare function sub<T extends Vec3Like>(out: T, a: Vec3Like, b: Vec3Like
13
13
  export declare function multiply<T extends Vec3Like>(out: T, a: Vec3Like, b: Vec3Like): T;
14
14
  /** Multiplies `a` by the number `s`. */
15
15
  export declare function scale<T extends Vec3Like>(out: T, a: Vec3Like, s: number): T;
16
- /** Adds `b` times the number `s` to `a`, as three.js's `addScaledVector`. */
16
+ /** Adds `b` times the number `s` to `a`. */
17
17
  export declare function scaleAndAdd<T extends Vec3Like>(out: T, a: Vec3Like, b: Vec3Like, s: number): T;
18
18
  /** Reverses the direction of `a`. */
19
19
  export declare function negate<T extends Vec3Like>(out: T, a: Vec3Like): T;
@@ -37,10 +37,7 @@ export declare function lerp<T extends Vec3Like>(out: T, a: Vec3Like, b: Vec3Lik
37
37
  export declare function min<T extends Vec3Like>(out: T, a: Vec3Like, b: Vec3Like): T;
38
38
  /** The larger of `a` and `b` on each axis. */
39
39
  export declare function max<T extends Vec3Like>(out: T, a: Vec3Like, b: Vec3Like): T;
40
- /** Turns `a` by the rotation `q`, a quaternion of length 1, as three.js's `applyQuaternion`. */
40
+ /** Turns `a` by the rotation `q`, a quaternion of length 1. */
41
41
  export declare function transformQuat<T extends Vec3Like>(out: T, a: Vec3Like, q: QuatLike): T;
42
- /**
43
- * Transforms the point `a` by the matrix `m`, with the perspective divide, as three.js's
44
- * `applyMatrix4`.
45
- */
42
+ /** Transforms the point `a` by the matrix `m`, with the perspective divide. */
46
43
  export declare function transformMat4<T extends Vec3Like>(out: T, a: Vec3Like, m: Mat4Like): T;
package/lib/math/vec3.js CHANGED
@@ -58,7 +58,7 @@ export function scale(out, a, s) {
58
58
  out[2] = a[2] * s;
59
59
  return out;
60
60
  }
61
- /** Adds `b` times the number `s` to `a`, as three.js's `addScaledVector`. */
61
+ /** Adds `b` times the number `s` to `a`. */
62
62
  export function scaleAndAdd(out, a, b, s) {
63
63
  out[0] = a[0] + b[0] * s;
64
64
  out[1] = a[1] + b[1] * s;
@@ -154,7 +154,7 @@ export function max(out, a, b) {
154
154
  out[2] = Math.max(a[2], b[2]);
155
155
  return out;
156
156
  }
157
- /** Turns `a` by the rotation `q`, a quaternion of length 1, as three.js's `applyQuaternion`. */
157
+ /** Turns `a` by the rotation `q`, a quaternion of length 1. */
158
158
  export function transformQuat(out, a, q) {
159
159
  const vx = a[0];
160
160
  const vy = a[1];
@@ -171,10 +171,7 @@ export function transformQuat(out, a, q) {
171
171
  out[2] = vz + qw * tz + qx * ty - qy * tx;
172
172
  return out;
173
173
  }
174
- /**
175
- * Transforms the point `a` by the matrix `m`, with the perspective divide, as three.js's
176
- * `applyMatrix4`.
177
- */
174
+ /** Transforms the point `a` by the matrix `m`, with the perspective divide. */
178
175
  export function transformMat4(out, a, m) {
179
176
  const x = a[0];
180
177
  const y = a[1];
@@ -176,16 +176,16 @@ type FloatTargetTest = NonNullable<WebGL2Report['floatRenderTargets']>['rgba16f'
176
176
  */
177
177
  export declare function probeFloatTarget(gl: WebGL2RenderingContext, format: number, readBack?: boolean): FloatTargetTest;
178
178
  /**
179
- * Runs the probe worker, with each of `timeoutsMs` in turn as its time limit while it gives no
180
- * answer. A worker that fails to start is not tried again.
179
+ * Runs the probe worker on the GPU that `powerPreference` picks, with each of `timeoutsMs` in turn
180
+ * as its time limit while it gives no answer. A worker that fails to start is not tried again.
181
181
  */
182
- export declare function probeWorker(timeoutsMs?: readonly number[]): Promise<WorkerProbe | WorkerProbeFailure>;
182
+ export declare function probeWorker(timeoutsMs?: readonly number[], powerPreference?: PowerPreference): Promise<WorkerProbe | WorkerProbeFailure>;
183
183
  /**
184
- * The probe worker's answer for the page: the kept answer, the answer of a probe that is running,
185
- * or a new probe's, with `timeoutsMs` as its time limits.
184
+ * The probe worker's answer for the page on the GPU that `powerPreference` picks: the kept answer,
185
+ * the answer of a probe that is running, or a new probe's, with `timeoutsMs` as its time limits.
186
186
  */
187
- export declare function pageWorkerProbe(timeoutsMs?: readonly number[]): Promise<WorkerProbe | WorkerProbeFailure>;
188
- /** Drops the kept answer, as after a lost GPU, so that the next start probes again. */
187
+ export declare function pageWorkerProbe(timeoutsMs?: readonly number[], powerPreference?: PowerPreference): Promise<WorkerProbe | WorkerProbeFailure>;
188
+ /** Drops the kept answers, as after a lost GPU, so that the next start probes again. */
189
189
  export declare function forgetWorkerProbe(): void;
190
190
  /**
191
191
  * Which GPU to use on a device with two: the faster one, or the one that saves battery. Without
@@ -293,12 +293,12 @@ function probeWebGL2(powerPreference, multiDraw = true) {
293
293
  */
294
294
  const WORKER_PROBE_TIMEOUTS_MS = [5000, 10_000];
295
295
  /**
296
- * Runs the probe worker, with each of `timeoutsMs` in turn as its time limit while it gives no
297
- * answer. A worker that fails to start is not tried again.
296
+ * Runs the probe worker on the GPU that `powerPreference` picks, with each of `timeoutsMs` in turn
297
+ * as its time limit while it gives no answer. A worker that fails to start is not tried again.
298
298
  */
299
- export async function probeWorker(timeoutsMs = WORKER_PROBE_TIMEOUTS_MS) {
299
+ export async function probeWorker(timeoutsMs = WORKER_PROBE_TIMEOUTS_MS, powerPreference) {
300
300
  for (const timeoutMs of timeoutsMs) {
301
- const result = await probeWorkerOnce(timeoutMs);
301
+ const result = await probeWorkerOnce(timeoutMs, powerPreference);
302
302
  if (!('failure' in result) || result.failure !== 'no-answer')
303
303
  return result;
304
304
  }
@@ -309,34 +309,39 @@ export async function probeWorker(timeoutsMs = WORKER_PROBE_TIMEOUTS_MS) {
309
309
  };
310
310
  }
311
311
  /**
312
- * The probe worker's answer that the page's engine starts share. Firefox makes a new WebGL2
313
- * context wait for the WebGL work that other contexts have queued, such as a shader link. On a
314
- * software renderer an engine's links take seconds, so a start's probe can outlast its time
315
- * limits while another engine on the page starts. A worker's abilities hold for the page's life,
316
- * so one full answer serves every later start. A failure is not kept.
312
+ * The probe worker's answers that the page's engine starts share, by the power preference that
313
+ * picked the GPU they tested. Firefox makes a new WebGL2 context wait for the WebGL work that other
314
+ * contexts have queued, such as a shader link. On a software renderer an engine's links take
315
+ * seconds, so a start's probe can outlast its time limits while another engine on the page starts.
316
+ * A worker's abilities hold for the page's life, so one full answer serves every later start on
317
+ * the same GPU. A failure is not kept.
317
318
  */
318
- let pageProbe;
319
+ const pageProbes = new Map();
319
320
  /**
320
- * The probe worker's answer for the page: the kept answer, the answer of a probe that is running,
321
- * or a new probe's, with `timeoutsMs` as its time limits.
321
+ * The probe worker's answer for the page on the GPU that `powerPreference` picks: the kept answer,
322
+ * the answer of a probe that is running, or a new probe's, with `timeoutsMs` as its time limits.
322
323
  */
323
- export function pageWorkerProbe(timeoutsMs = WORKER_PROBE_TIMEOUTS_MS) {
324
- if (pageProbe)
325
- return pageProbe;
326
- const probe = probeWorker(timeoutsMs);
327
- pageProbe = probe;
324
+ export function pageWorkerProbe(timeoutsMs = WORKER_PROBE_TIMEOUTS_MS, powerPreference) {
325
+ const kept = pageProbes.get(powerPreference);
326
+ if (kept)
327
+ return kept;
328
+ const probe = probeWorker(timeoutsMs, powerPreference);
329
+ pageProbes.set(powerPreference, probe);
328
330
  void probe.then((result) => {
329
- if ('failure' in result && pageProbe === probe)
330
- pageProbe = undefined;
331
+ if ('failure' in result && pageProbes.get(powerPreference) === probe)
332
+ pageProbes.delete(powerPreference);
331
333
  });
332
334
  return probe;
333
335
  }
334
- /** Drops the kept answer, as after a lost GPU, so that the next start probes again. */
336
+ /** Drops the kept answers, as after a lost GPU, so that the next start probes again. */
335
337
  export function forgetWorkerProbe() {
336
- pageProbe = undefined;
338
+ pageProbes.clear();
337
339
  }
338
- /** Runs one probe worker, which must answer within `timeoutMs` of its script's start. */
339
- function probeWorkerOnce(timeoutMs) {
340
+ /**
341
+ * Runs one probe worker on the GPU that `powerPreference` picks, which must answer within
342
+ * `timeoutMs` of its script's start.
343
+ */
344
+ function probeWorkerOnce(timeoutMs, powerPreference) {
340
345
  return new Promise((resolve) => {
341
346
  let worker;
342
347
  try {
@@ -364,6 +369,8 @@ function probeWorkerOnce(timeoutMs) {
364
369
  failure: 'failed-to-start',
365
370
  error: message || 'the probe worker failed to start',
366
371
  }));
372
+ // The worker reads this once its script runs, and probes then.
373
+ worker.postMessage({ powerPreference });
367
374
  });
368
375
  }
369
376
  /**
@@ -372,7 +379,14 @@ function probeWorkerOnce(timeoutMs) {
372
379
  * reports WebGL2 without `WEBGL_multi_draw`, as the ?multidraw=off switch asks.
373
380
  */
374
381
  export async function probeCapabilities(powerPreference, hints = readDeviceHints(), multiDraw = true) {
375
- const [webgpu, worker] = await Promise.all([probeWebGPU(powerPreference), pageWorkerProbe()]);
382
+ const pending = Promise.all([
383
+ probeWebGPU(powerPreference),
384
+ pageWorkerProbe(WORKER_PROBE_TIMEOUTS_MS, powerPreference),
385
+ ]);
386
+ // The WebGL2 test blocks this thread, so it runs while the adapter request and the probe worker
387
+ // are under way.
388
+ const webgl2 = probeWebGL2(powerPreference, multiDraw);
389
+ const [webgpu, worker] = await pending;
376
390
  // The probe worker measures the draw paths on a device of its own, which the render worker's
377
391
  // device answers the same way for the browser and the driver.
378
392
  const probed = 'directDraws' in worker && webgpu.available;
@@ -389,7 +403,7 @@ export async function probeCapabilities(powerPreference, hints = readDeviceHints
389
403
  transferControlToOffscreen: typeof HTMLCanvasElement === 'function' &&
390
404
  'transferControlToOffscreen' in HTMLCanvasElement.prototype,
391
405
  webgpu: { ...webgpu, directDraws, drawPath },
392
- webgl2: probeWebGL2(powerPreference, multiDraw),
406
+ webgl2,
393
407
  worker,
394
408
  };
395
409
  }
@@ -9,6 +9,16 @@ export declare const STORED_CHECK_MS: number;
9
9
  * larger canvas has more pixels to fill, and a smaller one may hold a heavier preset.
10
10
  */
11
11
  export declare const STORED_CHECK_AREA_RATIO = 1.25;
12
+ /**
13
+ * True when a check's rounds end it: its last round held the target, or measured Low, which has no
14
+ * lighter preset. A check that lowered the preset after its last round has not ended.
15
+ */
16
+ export declare function checkEnded(check: Pick<PresetCheck, 'targetFps' | 'rounds'>): boolean;
17
+ /**
18
+ * The preset that a check's rounds leave the engine at: the last round's preset when the check
19
+ * ended there, or else the one that the check lowered to after the last round missed its target.
20
+ */
21
+ export declare function checkedPreset(check: Pick<PresetCheck, 'from' | 'targetFps' | 'rounds'>): QualityPreset;
12
22
  /**
13
23
  * The facts that a check's result depends on, apart from the canvas size, as one text: the check's
14
24
  * rules, the GPU path and the preset that the check starts from, the frame rate cap, the highest
@@ -18,7 +28,8 @@ export declare const STORED_CHECK_AREA_RATIO = 1.25;
18
28
  export declare function checkConditions(report: CapabilityReport, tier: Tier, from: QualityPreset, fps: number | undefined, maxTargetFps: number): string;
19
29
  /**
20
30
  * The stored result that applies to a start under `conditions` with a canvas of `area` CSS
21
- * pixels at `now`, as a reused check, or undefined when none does.
31
+ * pixels at `now`, as a reused check, or undefined when none does. A check that has not ended
32
+ * gives its rounds so far, which the start's own check goes on from (`checkEnded`).
22
33
  */
23
34
  export declare function reusableCheck(text: string | null, conditions: string, area: number, now: number): PresetCheck | undefined;
24
35
  /** The stored preset check of one sketch, for one start of it. */
@@ -35,7 +46,8 @@ export declare class CheckStore {
35
46
  /** The stored result that applies to this start, or undefined. */
36
47
  read(now?: number): PresetCheck | undefined;
37
48
  /**
38
- * Stores the result of a check that this start measured, when it measured against at least the
49
+ * Stores what a check of this start measured: its result once it ended, and its rounds so far
50
+ * each time it lowers the preset. It stores them when they were measured against at least the
39
51
  * target that the check starts from under the highest target `maxTargetFps`.
40
52
  */
41
53
  save(check: PresetCheck, maxTargetFps: number, now?: number): void;
@@ -1,15 +1,18 @@
1
1
  // The stored preset check: the result of each sketch's last preset check, kept in the page's
2
2
  // localStorage, so that a later start of the sketch in the same browser on the same device takes
3
3
  // the checked preset without measuring again. On a tablet the check takes about a second for each
4
- // preset that it measures, and the page's loading screen waits for it. A stored result applies only
5
- // to a start that would check the same preset with the same rules, on a GPU and display that report
6
- // the same facts, at a canvas size close to the measured one, within a week of the measurement. A
7
- // result measured against a target below the one that the engine starts from, as on a display in a
8
- // power-saving mode, is not stored. The highest target that the page allows is one of the facts, so
9
- // a result never applies to a start that defends another rate. Storage that cannot be read or written counts as empty. The GPU's names only tell
10
- // one GPU from another here; the engine never decides anything from what they say.
11
- import { CHECK_GRACE_MS, CHECK_HOLD_SHARE, CHECK_MAX_FPS, CHECK_UPLOAD_WAIT_MS, CHECK_WINDOW_MS, checkTargetFps, } from '../quality/check.js';
12
- import { QUALITY_PRESETS } from '../quality/presets.js';
4
+ // preset that it measures. A stored result applies only to a start that would check the same
5
+ // preset with the same rules, on a GPU and display that report the same facts, at a canvas size
6
+ // close to the measured one, within a week of the measurement. The store also keeps the rounds of
7
+ // a check that has not ended yet, each time the check lowers the preset, so a page that closes
8
+ // during the check loses no round: the next start begins at the lighter preset, and its own check
9
+ // goes on from there. A result measured against a target below the one that the engine starts
10
+ // from, as on a display in a power-saving mode, is not stored. The highest target that the page
11
+ // allows is one of the facts, so a result never applies to a start that defends another rate.
12
+ // Storage that cannot be read or written counts as empty. The GPU's names only tell one GPU from
13
+ // another here; the engine never decides anything from what they say.
14
+ import { CHECK_GRACE_MS, CHECK_HOLD_SHARE, CHECK_MAX_FPS, CHECK_UPLOAD_WAIT_MS, CHECK_WINDOW_MS, checkTargetFps, holdsTarget, } from '../quality/check.js';
15
+ import { presetAfterMiss, QUALITY_PRESETS } from '../quality/presets.js';
13
16
  import { pageStorage } from './start-marker.js';
14
17
  /** How long a stored check result applies, in ms: a week. */
15
18
  export const STORED_CHECK_MS = 7 * 24 * 60 * 60 * 1000;
@@ -19,6 +22,24 @@ export const STORED_CHECK_MS = 7 * 24 * 60 * 60 * 1000;
19
22
  */
20
23
  export const STORED_CHECK_AREA_RATIO = 1.25;
21
24
  const KEY_PREFIX = 'null3d.check:';
25
+ /**
26
+ * True when a check's rounds end it: its last round held the target, or measured Low, which has no
27
+ * lighter preset. A check that lowered the preset after its last round has not ended.
28
+ */
29
+ export function checkEnded(check) {
30
+ const last = check.rounds.at(-1);
31
+ return last !== undefined && (last.preset === 'low' || holdsTarget(last, check.targetFps));
32
+ }
33
+ /**
34
+ * The preset that a check's rounds leave the engine at: the last round's preset when the check
35
+ * ended there, or else the one that the check lowered to after the last round missed its target.
36
+ */
37
+ export function checkedPreset(check) {
38
+ const last = check.rounds.at(-1);
39
+ if (!last)
40
+ return check.from;
41
+ return checkEnded(check) ? last.preset : presetAfterMiss(last, check.targetFps);
42
+ }
22
43
  const isPreset = (value) => QUALITY_PRESETS.includes(value);
23
44
  const isRound = (round) => round !== null &&
24
45
  isPreset(round.preset) &&
@@ -81,7 +102,8 @@ export function checkConditions(report, tier, from, fps, maxTargetFps) {
81
102
  }
82
103
  /**
83
104
  * The stored result that applies to a start under `conditions` with a canvas of `area` CSS
84
- * pixels at `now`, as a reused check, or undefined when none does.
105
+ * pixels at `now`, as a reused check, or undefined when none does. A check that has not ended
106
+ * gives its rounds so far, which the start's own check goes on from (`checkEnded`).
85
107
  */
86
108
  export function reusableCheck(text, conditions, area, now) {
87
109
  const stored = parseStored(text);
@@ -123,7 +145,8 @@ export class CheckStore {
123
145
  }
124
146
  }
125
147
  /**
126
- * Stores the result of a check that this start measured, when it measured against at least the
148
+ * Stores what a check of this start measured: its result once it ended, and its rounds so far
149
+ * each time it lowers the preset. It stores them when they were measured against at least the
127
150
  * target that the check starts from under the highest target `maxTargetFps`.
128
151
  */
129
152
  save(check, maxTargetFps, now = Date.now()) {