@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
@@ -7,6 +7,7 @@ import * as G from '../../generated/gpu.js';
7
7
  import { DEV } from '../../shared/dev.js';
8
8
  import { ImageTable } from '../../shared/images.js';
9
9
  import { DROP_COUNTED_LABEL } from '../../shared/metrics.js';
10
+ import { EarlyBuilds, keyOf, PipelineListing } from '../early-builds.js';
10
11
  import { JoinedBuilds, joinedReady } from '../effect-join.js';
11
12
  import { CLOUD_FIELD_WORD, CLOUD_STEPS_WORD, LAYER_WORD, LIGHT_BUFFER_WORD, } from '../environment-words.js';
12
13
  import { floatOfBits } from '../float-bits.js';
@@ -116,6 +117,14 @@ function passScope(a, length, words) {
116
117
  return words[a + 10];
117
118
  return 0;
118
119
  }
120
+ /**
121
+ * True for a pipeline build that the GPU's driver refused, as a `GPUPipelineError` whose reason is
122
+ * `internal`: it ran out of memory, or its compiler refused the shader. The browser's validation
123
+ * of the engine's descriptor gives the reason `validation`.
124
+ */
125
+ export function refusedByDriver(error) {
126
+ return error?.reason === 'internal';
127
+ }
119
128
  export class WebGPUBackend {
120
129
  device;
121
130
  context;
@@ -144,15 +153,31 @@ export class WebGPUBackend {
144
153
  mipSampler;
145
154
  /** What making each texture's mip levels draws with, by texture id, once it made them. */
146
155
  mipChains = [];
147
- /** Pipelines by id: null while one builds, and undefined for an id that names none. */
156
+ /**
157
+ * Pipelines by id: null while one builds or after the GPU's driver refused it, and undefined for
158
+ * an id that names none. A null pipeline's draws draw nothing.
159
+ */
148
160
  renderPipelines = [];
149
161
  /** True for each render pipeline, by id, that draws lines rather than triangles. */
150
162
  lineLists = [];
151
163
  /** True while the render pass's pipeline draws lines. */
152
164
  lines = false;
153
165
  computePipelines = [];
154
- /** Pipelines that are building, or that wait for their custom material's shader. */
166
+ /** Pipelines that are building, or that wait for their custom material's shader or a retry. */
155
167
  builds = 0;
168
+ /** The builds that the browser runs now. */
169
+ running = 0;
170
+ /**
171
+ * The render pipelines of the scene's objects whose build the GPU's driver refused once. Each
172
+ * builds once more, alone, once no other build runs: a driver can run short of memory while it
173
+ * compiles many shaders at once.
174
+ */
175
+ retries = [];
176
+ /**
177
+ * Hears each render pipeline that the GPU's driver refused twice, by its name and the driver's
178
+ * reason. Its draws draw nothing from then on, and the frames go on without them.
179
+ */
180
+ refused;
156
181
  /**
157
182
  * The operands of each `CreateRenderPipeline` whose custom material's shader has not reached
158
183
  * this thread yet. Each builds once its shader arrives.
@@ -171,6 +196,23 @@ export class WebGPUBackend {
171
196
  * skinning pass's, which loads with the first skinned mesh. Each builds once its file arrives.
172
197
  */
173
198
  parkedCompute = [];
199
+ /** The create commands of the pipelines that the lists before the first frame create. */
200
+ listing = new PipelineListing();
201
+ /** The builds of the pipelines that the last start's first frame built, until this first frame. */
202
+ early;
203
+ /**
204
+ * The builds of the pipelines that a list before the first frame creates after other commands,
205
+ * by the id that the command creates, with the command's key. They start when the list is
206
+ * prepared, and the frame waits for them.
207
+ */
208
+ ahead = new Map();
209
+ /**
210
+ * The builds of `ahead` by the command's key: commands of equal operands under other ids, such
211
+ * as an add-on's compute passes of one shader, share one build. Built one after another, the
212
+ * browser's cache of equal pipelines answers each after the first; started at once, each would
213
+ * compile the shader again.
214
+ */
215
+ aheadByKey = new Map();
174
216
  /**
175
217
  * True when the vertex shaders skin skinned meshes, so a preload of skinning prepares the
176
218
  * shaders of its SKIN builds.
@@ -817,11 +859,100 @@ export class WebGPUBackend {
817
859
  const op = header & 0xff;
818
860
  if (op !== G.OP_CREATE_RENDER_PIPELINE && op !== G.OP_CREATE_COMPUTE_PIPELINE)
819
861
  break;
862
+ this.listing.add(op, words, i + 1);
820
863
  this.createPipeline(op, words, i + 1, true);
821
864
  i += header >>> 8;
822
865
  }
866
+ if (this.listing.active)
867
+ this.buildAhead(words, i, end);
823
868
  return i;
824
869
  }
870
+ /**
871
+ * Starts to build, in the background, each pipeline that the list in `words[start, end)` creates
872
+ * after other commands, such as an add-on's compute pass. The frame before the first one then
873
+ * waits for them, as for the pipelines at the list's front, and its replay takes them. Without
874
+ * this, its replay would build each at once, and the GPU would compile them one after another
875
+ * inside the first frame.
876
+ */
877
+ buildAhead(words, start, end) {
878
+ for (let i = start; i < end;) {
879
+ const header = words[i];
880
+ const length = header >>> 8;
881
+ if (length === 0)
882
+ return;
883
+ const op = header & 0xff;
884
+ const id = words[i + 1];
885
+ if ((op === G.OP_CREATE_RENDER_PIPELINE || op === G.OP_CREATE_COMPUTE_PIPELINE) &&
886
+ !this.ahead.has(id)) {
887
+ const key = keyOf(op, words, i + 1);
888
+ let build = this.aheadByKey.get(key);
889
+ if (!build) {
890
+ build = this.early?.take(op, words, i + 1) ?? this.startAhead(op, words, i + 1);
891
+ if (build) {
892
+ this.aheadByKey.set(key, build);
893
+ this.builds++;
894
+ build.done
895
+ .then(() => undefined, () => undefined)
896
+ .finally(() => {
897
+ this.builds--;
898
+ });
899
+ }
900
+ }
901
+ if (build)
902
+ this.ahead.set(id, { key, build });
903
+ }
904
+ i += length;
905
+ }
906
+ }
907
+ /**
908
+ * The background build of the create command `op` whose operands start at `a`, or undefined
909
+ * while its shader has not arrived or when it builds when its command comes.
910
+ */
911
+ startAhead(op, words, a) {
912
+ const template = words[a + 1];
913
+ const permutation = words[a + 2];
914
+ let done;
915
+ try {
916
+ if (op === G.OP_CREATE_COMPUTE_PIPELINE) {
917
+ if (!this.computeReady(template, permutation))
918
+ return undefined;
919
+ done = this.device.createComputePipelineAsync(this.pipelines.compute(template, permutation));
920
+ }
921
+ else {
922
+ if (this.joins.joined(template) || !this.templateReady(template, permutation))
923
+ return undefined;
924
+ done = this.device.createRenderPipelineAsync(this.renderDescriptor(words, a));
925
+ }
926
+ }
927
+ catch {
928
+ return undefined;
929
+ }
930
+ const made = {
931
+ pipeline: undefined,
932
+ failed: false,
933
+ done,
934
+ };
935
+ done.then((pipeline) => {
936
+ made.pipeline = pipeline;
937
+ }, () => {
938
+ made.failed = true;
939
+ });
940
+ return made;
941
+ }
942
+ /**
943
+ * The built pipeline of a create command that the list creates after other commands, whose build
944
+ * started when the list was prepared, or undefined when there is none, as after the first frame.
945
+ */
946
+ takeAhead(op, words, a) {
947
+ if (this.ahead.size === 0)
948
+ return undefined;
949
+ const id = words[a];
950
+ const ahead = this.ahead.get(id);
951
+ if (!ahead)
952
+ return undefined;
953
+ this.ahead.delete(id);
954
+ return ahead.key === keyOf(op, words, a) ? ahead.build.pipeline : undefined;
955
+ }
825
956
  /**
826
957
  * Where the draw section of the list in `words[start, end)` begins, after the pipelines it
827
958
  * creates. It walks the same ops as `prepare` and starts no build.
@@ -846,6 +977,8 @@ export class WebGPUBackend {
846
977
  this.swapReplaced();
847
978
  if (this.parked.length > 0 || this.parkedCompute.length > 0)
848
979
  this.unpark();
980
+ if (this.retries.length > 0 && this.running === 0)
981
+ this.retryRefused();
849
982
  return this.builds > 0;
850
983
  }
851
984
  /**
@@ -868,6 +1001,7 @@ export class WebGPUBackend {
868
1001
  const swap = ++this.swapCount;
869
1002
  this.swaps.set(id, swap);
870
1003
  this.builds++;
1004
+ this.running++;
871
1005
  this.counts.pipelines++;
872
1006
  const keep = (error) => console.error(`null3D could not build the new WGSL of a custom material on this GPU, so its objects keep the old shader: ${messageOf(error)}`);
873
1007
  Promise.resolve()
@@ -879,6 +1013,7 @@ export class WebGPUBackend {
879
1013
  }, keep)
880
1014
  .finally(() => {
881
1015
  this.builds--;
1016
+ this.running--;
882
1017
  });
883
1018
  }
884
1019
  }
@@ -924,6 +1059,55 @@ export class WebGPUBackend {
924
1059
  .createComputePipelineAsync(this.pipelines.compute(template, bits))
925
1060
  .catch(() => undefined);
926
1061
  }
1062
+ /**
1063
+ * Starts to build the pipelines of `list`, a pipeline list of the pipelines that the first frame
1064
+ * of the sketch's last start built (`gpu/early-builds.ts`). Each build starts once its shader is
1065
+ * there, and a create command of the same pipeline takes it. A joined shader's pipelines build
1066
+ * when their command comes, as their failure sends the effects back to a pass each.
1067
+ */
1068
+ buildEarly(list) {
1069
+ this.early?.stop();
1070
+ this.early = new EarlyBuilds(list, (op, operands) => {
1071
+ const template = operands[1];
1072
+ const permutation = operands[2];
1073
+ if (op === G.OP_CREATE_COMPUTE_PIPELINE) {
1074
+ if (!this.computeReady(template, permutation))
1075
+ return undefined;
1076
+ return this.device.createComputePipelineAsync(this.pipelines.compute(template, permutation));
1077
+ }
1078
+ if (this.joins.joined(template))
1079
+ return null;
1080
+ if (!this.templateReady(template, permutation))
1081
+ return undefined;
1082
+ return this.device.createRenderPipelineAsync(this.renderDescriptor(operands, 0));
1083
+ });
1084
+ }
1085
+ /**
1086
+ * Ends the list of the pipelines that the frames before the first one created, and returns it,
1087
+ * once: the first frame has drawn. The builds of the last start's list that no command took
1088
+ * stop.
1089
+ */
1090
+ takeListing() {
1091
+ this.early?.stop();
1092
+ this.early = undefined;
1093
+ this.ahead.clear();
1094
+ this.aheadByKey.clear();
1095
+ return this.listing.take();
1096
+ }
1097
+ /**
1098
+ * Gives the pipeline `id` of `table` the build that started for it ahead of its command: at once
1099
+ * when it is built, else when it is.
1100
+ */
1101
+ adopt(table, id, early) {
1102
+ const pipeline = early.pipeline;
1103
+ if (pipeline) {
1104
+ table[id] = pipeline;
1105
+ return;
1106
+ }
1107
+ table[id] = null;
1108
+ this.builds++;
1109
+ early.done.then((built) => this.built(table, id, built), (error) => this.failed(error));
1110
+ }
927
1111
  /**
928
1112
  * Makes the skinning pass write normals and tangents as 32-bit floats, as the core's skinned
929
1113
  * vertices hold them in the skinning modes that measure 8-bit ones against floats.
@@ -980,14 +1164,28 @@ export class WebGPUBackend {
980
1164
  this.parkedCompute.push(words.slice(a, a - 1 + (words[a - 1] >>> 8)));
981
1165
  return;
982
1166
  }
983
- const descriptor = this.pipelines.compute(words[a + 1], words[a + 2]);
1167
+ const early = background ? this.early?.take(op, words, a) : undefined;
1168
+ if (early) {
1169
+ this.adopt(this.computePipelines, id, early);
1170
+ return;
1171
+ }
984
1172
  if (!background) {
985
- this.computePipelines[id] = device.createComputePipeline(descriptor);
1173
+ this.computePipelines[id] =
1174
+ this.takeAhead(op, words, a) ??
1175
+ device.createComputePipeline(this.pipelines.compute(words[a + 1], words[a + 2]));
986
1176
  return;
987
1177
  }
1178
+ const descriptor = this.pipelines.compute(words[a + 1], words[a + 2]);
988
1179
  this.computePipelines[id] = null;
989
1180
  this.builds++;
990
- device.createComputePipelineAsync(descriptor).then((pipeline) => this.built(this.computePipelines, id, pipeline), (error) => this.failed(error));
1181
+ this.running++;
1182
+ device.createComputePipelineAsync(descriptor).then((pipeline) => {
1183
+ this.running--;
1184
+ this.built(this.computePipelines, id, pipeline);
1185
+ }, (error) => {
1186
+ this.running--;
1187
+ this.failed(error);
1188
+ });
991
1189
  return;
992
1190
  }
993
1191
  this.lineLists[id] = (words[a + 6] & G.STATE_LINE_LIST) !== 0;
@@ -999,31 +1197,72 @@ export class WebGPUBackend {
999
1197
  this.parked.push(words.slice(a, a - 1 + (words[a - 1] >>> 8)));
1000
1198
  return;
1001
1199
  }
1002
- const descriptor = this.renderDescriptor(words, a);
1003
1200
  // A joined shader always builds in the background, so a frame never waits for it and its
1004
1201
  // failure only sends its effects back to a pass each.
1005
1202
  const template = words[a + 1];
1006
1203
  const joined = this.joins.joined(template);
1007
1204
  if (DEV && !joined && this.images.shaders.has(template))
1008
1205
  this.customOperands.set(id, words.slice(a, a + RENDER_PIPELINE_OPERANDS));
1206
+ const early = background && !joined ? this.early?.take(op, words, a) : undefined;
1207
+ if (early) {
1208
+ this.adopt(this.renderPipelines, id, early);
1209
+ return;
1210
+ }
1009
1211
  if (!background && !joined) {
1010
- this.renderPipelines[id] = device.createRenderPipeline(descriptor);
1212
+ this.renderPipelines[id] =
1213
+ this.takeAhead(op, words, a) ??
1214
+ device.createRenderPipeline(this.renderDescriptor(words, a));
1011
1215
  return;
1012
1216
  }
1217
+ const descriptor = this.renderDescriptor(words, a);
1013
1218
  this.renderPipelines[id] = null;
1014
1219
  this.builds++;
1220
+ this.running++;
1015
1221
  const start = performance.now();
1222
+ const permutation = words[a + 2];
1016
1223
  device.createRenderPipelineAsync(descriptor).then((pipeline) => {
1224
+ this.running--;
1017
1225
  if (joined)
1018
1226
  this.joins.built(template, performance.now() - start);
1019
1227
  this.built(this.renderPipelines, id, pipeline);
1020
1228
  }, (error) => {
1229
+ this.running--;
1021
1230
  if (!joined)
1022
- return this.failed(error);
1231
+ return this.refusedOnce({ id, template, permutation, descriptor }, error);
1023
1232
  this.builds--;
1024
1233
  this.joins.failed(template, error);
1025
1234
  });
1026
1235
  }
1236
+ /**
1237
+ * Hears that a render pipeline did not build. A pipeline of the scene's objects that the GPU's
1238
+ * driver refused waits for its retry, and still counts as building. Any other failure, such as
1239
+ * a descriptor that the browser's validation refused, is an engine fault, which the next replay
1240
+ * reports.
1241
+ */
1242
+ refusedOnce(build, error) {
1243
+ if (refusedByDriver(error) && this.pipelines.drawsObjects(build.template))
1244
+ this.retries.push(build);
1245
+ else
1246
+ this.failed(error);
1247
+ }
1248
+ /**
1249
+ * Builds the first pipeline that waits for its retry. A second refusal leaves its draws drawing
1250
+ * nothing, so the frames go on without those objects, and the backend reports it.
1251
+ */
1252
+ retryRefused() {
1253
+ const build = this.retries.shift();
1254
+ this.running++;
1255
+ this.device.createRenderPipelineAsync(build.descriptor).then((pipeline) => {
1256
+ this.running--;
1257
+ this.built(this.renderPipelines, build.id, pipeline);
1258
+ }, (error) => {
1259
+ this.running--;
1260
+ this.builds--;
1261
+ // A pipeline destroyed meanwhile is no loss.
1262
+ if (this.renderPipelines[build.id] === null)
1263
+ this.refused?.(this.pipelines.describe(build.template, build.permutation), messageOf(error));
1264
+ });
1265
+ }
1027
1266
  /** How to build the render pipeline of a `CreateRenderPipeline` command with its operands at `a`. */
1028
1267
  renderDescriptor(words, a) {
1029
1268
  return this.pipelines.render(words[a + 1], words[a + 2], this.format(words[a + 3]), this.format(words[a + 4]), words[a + 5], words[a + 6], words[a + 7], words[a + 8] | 0, floatOfBits(words[a + 9]));
@@ -1045,6 +1284,11 @@ export class WebGPUBackend {
1045
1284
  this.parked.splice(parked, 1);
1046
1285
  this.builds--;
1047
1286
  }
1287
+ const retry = this.retries.findIndex((build) => build.id === id);
1288
+ if (retry >= 0) {
1289
+ this.retries.splice(retry, 1);
1290
+ this.builds--;
1291
+ }
1048
1292
  this.renderPipelines[id] = undefined;
1049
1293
  if (DEV) {
1050
1294
  this.customOperands.delete(id);
@@ -1242,6 +1486,7 @@ export class WebGPUBackend {
1242
1486
  case G.OP_CREATE_RENDER_PIPELINE:
1243
1487
  case G.OP_CREATE_COMPUTE_PIPELINE:
1244
1488
  // A list that creates a pipeline after other commands builds it at once.
1489
+ this.listing.add(op, words, a);
1245
1490
  this.createPipeline(op, words, a, false);
1246
1491
  break;
1247
1492
  case G.OP_CREATE_BIND_GROUP:
@@ -1534,6 +1779,8 @@ export class WebGPUBackend {
1534
1779
  this.buffers[id] = undefined;
1535
1780
  }
1536
1781
  destroy() {
1782
+ this.early?.stop();
1783
+ this.early = undefined;
1537
1784
  for (let id = 0; id < this.buffers.length; id++)
1538
1785
  this.releaseBuffer(id);
1539
1786
  for (let id = 0; id < this.textures.length; id++)
@@ -38,6 +38,11 @@ export interface RenderTemplate {
38
38
  readonly lastVertices?: boolean;
39
39
  /** The other vertex buffers that the vertex stage reads, by slot, after the mesh's vertices. */
40
40
  readonly vertexBuffers: GPUVertexBufferLayout[];
41
+ /**
42
+ * True for a custom material's draw shader, whose vertex stage makes every vertex: its draws are
43
+ * objects of the scene, as a mesh template's are, though it reads no mesh.
44
+ */
45
+ readonly meshless?: boolean;
41
46
  /**
42
47
  * True for a template whose pipelines draw the depth prepass with their own vertex shader: a
43
48
  * custom material's or a sprite's, whose vertices the depth template does not place. A pipeline
@@ -191,6 +196,14 @@ export declare class Pipelines {
191
196
  replaceCustom(id: number, shader: CustomShader): void;
192
197
  /** True when a template has this id. */
193
198
  has(id: number): boolean;
199
+ /**
200
+ * True when the pipelines of a template draw objects of the scene: meshes, or a custom material's
201
+ * draw shader. A frame can go without such a pipeline's draws, while a pass of the frame's own
202
+ * cannot.
203
+ */
204
+ drawsObjects(id: number): boolean;
205
+ /** The name of a render pipeline of a template, for a message (`pipelineName`). */
206
+ describe(id: number, permutation: number): string;
194
207
  /** The shader variants of a template that exists. */
195
208
  variants(id: number): ShaderVariants;
196
209
  /**
@@ -7,6 +7,7 @@ import { FORMAT_R32_FLOAT, FORMAT_RGBA8_UNORM, LAYOUT_ACCUMULATE, LAYOUT_AO, LAY
7
7
  import { DEBUG_LINES_SHADER, DEBUG_VIEW_SHADER, MOTION_VIEW_SHADER, } from '../../generated/shaders.js';
8
8
  import { LINE_VERTICES } from '../line-vertices.js';
9
9
  import { PARTICLE_RECORDS } from '../particle-records.js';
10
+ import { pipelineName } from '../pipeline-name.js';
10
11
  import { missingVariant, variantFor } from '../variants.js';
11
12
  import { plainScale, variantLocations, vertexAttribute, vertexStride, } from '../vertex-format.js';
12
13
  /**
@@ -1572,7 +1573,7 @@ export class Pipelines {
1572
1573
  // shader that returns that alpha, so the prepass keeps the same fragments.
1573
1574
  prepassCutout: shader.coverage === true || shader.alpha === true,
1574
1575
  ...(shader.meshless === true
1575
- ? { vertexBuffers: [] }
1576
+ ? { vertexBuffers: [], meshless: true }
1576
1577
  : {
1577
1578
  meshLocations: shader.locations,
1578
1579
  vertexBuffers: INSTANCE_BUFFERS,
@@ -1600,6 +1601,19 @@ export class Pipelines {
1600
1601
  has(id) {
1601
1602
  return this.templates[id] !== undefined || this.computeTemplates.has(id);
1602
1603
  }
1604
+ /**
1605
+ * True when the pipelines of a template draw objects of the scene: meshes, or a custom material's
1606
+ * draw shader. A frame can go without such a pipeline's draws, while a pass of the frame's own
1607
+ * cannot.
1608
+ */
1609
+ drawsObjects(id) {
1610
+ const template = this.templates[id];
1611
+ return template?.meshLocations !== undefined || template?.meshless === true;
1612
+ }
1613
+ /** The name of a render pipeline of a template, for a message (`pipelineName`). */
1614
+ describe(id, permutation) {
1615
+ return pipelineName(id, permutation, this.templates[id]?.label);
1616
+ }
1603
1617
  /** The shader variants of a template that exists. */
1604
1618
  variants(id) {
1605
1619
  const template = this.templates[id];
package/lib/index.d.ts CHANGED
@@ -21,8 +21,8 @@ export * as color from './math/color.js';
21
21
  */
22
22
  export * as mat4 from './math/mat4.js';
23
23
  /**
24
- * Number helpers with three.js's names, such as `math.clamp` and `math.damp`, and a random generator
25
- * that a sketch can seed and that hold mode seeds.
24
+ * Number helpers, such as `math.clamp` and `math.damp`, and a random generator that a sketch can
25
+ * seed and that hold mode seeds.
26
26
  *
27
27
  * @category api/math
28
28
  */
@@ -45,13 +45,13 @@ export type { EulerOrder, Mat4Like, QuatLike, Vec2Like, Vec3Like } from './math/
45
45
  export type { CapabilityReport, WebGL2Report, WebGPUReport, WorkerProbeFailure, } from './page/capabilities.js';
46
46
  export type { Engine, EngineCapabilities, EngineMode, EngineOptions, RenderFallback, StartupProgress, StartupStage, } from './page/engine.js';
47
47
  export { createEngine } from './page/engine.js';
48
- export type { FrameMetrics, FrameSummary, GpuPassStats, MainThreadStats, MeasureOptions, MemoryStats, SecondRates, SlowFrame, SlowFrameThread, ThreadStats, } from './page/frame-stats.js';
48
+ export type { DrawingStart, FrameMetrics, FrameSummary, GpuPassStats, MainThreadStats, MeasureOptions, MemoryStats, SecondRates, SlowFrame, SlowFrameThread, ThreadStats, } from './page/frame-stats.js';
49
49
  export type { HeldFrame, HoldDump, HoldFailure, HoldResult, HoldScript, HoldScriptProblem, HoldScriptResult, HoldScriptStep, } from './page/hold.js';
50
50
  export type { EngineLabels } from './page/labels.js';
51
51
  export type { PointerLockOptions } from './page/pointer-lock.js';
52
52
  export type { DepthMode, LatencyMode, SketchThread } from './page/switches.js';
53
53
  export type { VideoOptions } from './page/videos.js';
54
- export type { PresetCheck, PresetCheckRound, TargetFps } from './quality/check.js';
54
+ export type { PresetCheck, PresetCheckRound, PresetCheckTiming, TargetFps } from './quality/check.js';
55
55
  export type { DeviceHints, DeviceKind } from './quality/chooser.js';
56
56
  export { deviceKind } from './quality/chooser.js';
57
57
  export { readDeviceHints } from './quality/device-hints.js';
@@ -75,6 +75,8 @@ export { defineFeature, FeatureRegistry } from './scene/features.js';
75
75
  export type { FogCurve, FogOptions, FogVolumeOptions } from './scene/fog.js';
76
76
  export type { Ray } from './scene/frame-cameras.js';
77
77
  export { registerGltfExtension } from './scene/gltf-extensions.js';
78
+ export type { LevelBounds, LevelDistances, LevelSwitch, LevelView, } from './scene/level-rule.js';
79
+ export { LEAST_LEVEL_DISTANCE, levelAt, levelDistances, levelSwitchDistance, } from './scene/level-rule.js';
78
80
  export type { LightImagePixels } from './scene/light-images.js';
79
81
  export type { BakeProbesOptions, LightProbeGridOptions } from './scene/light-probes.js';
80
82
  export { bakeProbes, LightProbeGridData, ProbeBake } from './scene/light-probes.js';
package/lib/index.js CHANGED
@@ -16,8 +16,8 @@ export * as color from './math/color.js';
16
16
  */
17
17
  export * as mat4 from './math/mat4.js';
18
18
  /**
19
- * Number helpers with three.js's names, such as `math.clamp` and `math.damp`, and a random generator
20
- * that a sketch can seed and that hold mode seeds.
19
+ * Number helpers, such as `math.clamp` and `math.damp`, and a random generator that a sketch can
20
+ * seed and that hold mode seeds.
21
21
  *
22
22
  * @category api/math
23
23
  */
@@ -42,6 +42,7 @@ export { readDeviceHints } from './quality/device-hints.js';
42
42
  export { FeatureHost } from './scene/feature-host.js';
43
43
  export { defineFeature, FeatureRegistry } from './scene/features.js';
44
44
  export { registerGltfExtension } from './scene/gltf-extensions.js';
45
+ export { LEAST_LEVEL_DISTANCE, levelAt, levelDistances, levelSwitchDistance, } from './scene/level-rule.js';
45
46
  export { bakeProbes, LightProbeGridData, ProbeBake } from './scene/light-probes.js';
46
47
  export { AddonNamespaces, addonNamespaces, declareAddonNamespace, } from './scene/namespaces.js';
47
48
  export { emptyTimeOfDay, timeOfDay } from './scene/time-of-day.js';
@@ -1,7 +1,7 @@
1
1
  import type { Vec3Like } from './types.js';
2
- /** An sRGB component from 0 to 1 as a linear one, as three.js's `SRGBToLinear`. */
2
+ /** An sRGB component from 0 to 1 as a linear one, by the sRGB standard's curve. */
3
3
  export declare function srgbToLinear(c: number): number;
4
- /** A linear component from 0 to 1 as an sRGB one, as three.js's `LinearToSRGB`. */
4
+ /** A linear component from 0 to 1 as an sRGB one, by the sRGB standard's curve. */
5
5
  export declare function linearToSrgb(c: number): number;
6
6
  /** Linear RGB from three sRGB components from 0 to 1, such as a color picker gives. */
7
7
  export declare function fromSrgb<T extends Vec3Like>(out: T, r: number, g: number, b: number): T;
@@ -11,8 +11,8 @@ export declare function fromSrgb<T extends Vec3Like>(out: T, r: number, g: numbe
11
11
  */
12
12
  export declare function fromHex<T extends Vec3Like>(out: T, hex: string | number): T;
13
13
  /**
14
- * RGB from a hue, a saturation and a lightness, each from 0 to 1, as three.js's `setHSL`. Like
15
- * three.js, it takes the result as linear RGB, so the same values give the same color in both
16
- * engines.
14
+ * Linear RGB from a hue, a saturation and a lightness, each from 0 to 1. The hue wraps around, and
15
+ * the saturation and lightness stop at 0 and 1. It takes the result of the HSL formula as linear
16
+ * RGB as it is, with no sRGB conversion.
17
17
  */
18
18
  export declare function fromHsl<T extends Vec3Like>(out: T, h: number, s: number, l: number): T;
package/lib/math/color.js CHANGED
@@ -3,11 +3,11 @@
3
3
  // with three.js's constants. A helper writes into `out` and returns `out`, so per-frame code
4
4
  // allocates nothing.
5
5
  import { hexValue, invalidColor } from './hex.js';
6
- /** An sRGB component from 0 to 1 as a linear one, as three.js's `SRGBToLinear`. */
6
+ /** An sRGB component from 0 to 1 as a linear one, by the sRGB standard's curve. */
7
7
  export function srgbToLinear(c) {
8
8
  return c < 0.04045 ? c * 0.0773993808 : (c * 0.9478672986 + 0.0521327014) ** 2.4;
9
9
  }
10
- /** A linear component from 0 to 1 as an sRGB one, as three.js's `LinearToSRGB`. */
10
+ /** A linear component from 0 to 1 as an sRGB one, by the sRGB standard's curve. */
11
11
  export function linearToSrgb(c) {
12
12
  return c < 0.0031308 ? c * 12.92 : 1.055 * c ** 0.41666 - 0.055;
13
13
  }
@@ -32,9 +32,9 @@ export function fromHex(out, hex) {
32
32
  return out;
33
33
  }
34
34
  /**
35
- * RGB from a hue, a saturation and a lightness, each from 0 to 1, as three.js's `setHSL`. Like
36
- * three.js, it takes the result as linear RGB, so the same values give the same color in both
37
- * engines.
35
+ * Linear RGB from a hue, a saturation and a lightness, each from 0 to 1. The hue wraps around, and
36
+ * the saturation and lightness stop at 0 and 1. It takes the result of the HSL formula as linear
37
+ * RGB as it is, with no sRGB conversion.
38
38
  */
39
39
  export function fromHsl(out, h, s, l) {
40
40
  // The hue wraps around, and the saturation and lightness stop at 0 and 1, as in three.js.
@@ -5,24 +5,18 @@ export declare function create(): number[];
5
5
  export declare function identity<T extends Mat4Like>(out: T): T;
6
6
  /** Copies `a` into `out`. */
7
7
  export declare function copy<T extends Mat4Like>(out: T, a: Mat4Like): T;
8
- /**
9
- * The product of `a` and `b`, as three.js's `multiplyMatrices`. It transforms a point by `b` first,
10
- * then by `a`.
11
- */
8
+ /** The product of `a` and `b`. It transforms a point by `b` first, then by `a`. */
12
9
  export declare function multiply<T extends Mat4Like>(out: T, a: Mat4Like, b: Mat4Like): T;
13
- /**
14
- * The inverse of `a`, which undoes it, as three.js's `invert`. A matrix that has no inverse gives
15
- * all zeros.
16
- */
10
+ /** The inverse of `a`, which undoes it. A matrix that has no inverse gives all zeros. */
17
11
  export declare function invert<T extends Mat4Like>(out: T, a: Mat4Like): T;
18
12
  /**
19
13
  * The matrix that scales by `scale`, then turns by the quaternion `rotation`, then moves by
20
- * `position`, as three.js's `compose`.
14
+ * `position`.
21
15
  */
22
16
  export declare function compose<T extends Mat4Like>(out: T, position: Vec3Like, rotation: QuatLike, scale: Vec3Like): T;
23
17
  /**
24
- * Splits the matrix `m` into the position, rotation and scale that `compose` joins, as three.js's
25
- * `decompose`, and writes them into the first three arrays. A matrix that mirrors space gives a
26
- * negative X scale. A matrix that flattens space gives no rotation and a scale of 1.
18
+ * Splits the matrix `m` into the position, rotation and scale that `compose` joins, and writes them
19
+ * into the first three arrays. A matrix that mirrors space gives a negative X scale. A matrix that
20
+ * flattens space gives no rotation and a scale of 1.
27
21
  */
28
22
  export declare function decompose(position: Vec3Like, rotation: QuatLike, scale: Vec3Like, m: Mat4Like): void;
package/lib/math/mat4.js CHANGED
@@ -25,10 +25,7 @@ export function copy(out, a) {
25
25
  out[i] = a[i];
26
26
  return out;
27
27
  }
28
- /**
29
- * The product of `a` and `b`, as three.js's `multiplyMatrices`. It transforms a point by `b` first,
30
- * then by `a`.
31
- */
28
+ /** The product of `a` and `b`. It transforms a point by `b` first, then by `a`. */
32
29
  export function multiply(out, a, b) {
33
30
  const a00 = a[0];
34
31
  const a01 = a[1];
@@ -59,10 +56,7 @@ export function multiply(out, a, b) {
59
56
  }
60
57
  return out;
61
58
  }
62
- /**
63
- * The inverse of `a`, which undoes it, as three.js's `invert`. A matrix that has no inverse gives
64
- * all zeros.
65
- */
59
+ /** The inverse of `a`, which undoes it. A matrix that has no inverse gives all zeros. */
66
60
  export function invert(out, a) {
67
61
  const a00 = a[0];
68
62
  const a01 = a[1];
@@ -119,7 +113,7 @@ export function invert(out, a) {
119
113
  }
120
114
  /**
121
115
  * The matrix that scales by `scale`, then turns by the quaternion `rotation`, then moves by
122
- * `position`, as three.js's `compose`.
116
+ * `position`.
123
117
  */
124
118
  export function compose(out, position, rotation, scale) {
125
119
  const x = rotation[0];
@@ -160,9 +154,9 @@ export function compose(out, position, rotation, scale) {
160
154
  return out;
161
155
  }
162
156
  /**
163
- * Splits the matrix `m` into the position, rotation and scale that `compose` joins, as three.js's
164
- * `decompose`, and writes them into the first three arrays. A matrix that mirrors space gives a
165
- * negative X scale. A matrix that flattens space gives no rotation and a scale of 1.
157
+ * Splits the matrix `m` into the position, rotation and scale that `compose` joins, and writes them
158
+ * into the first three arrays. A matrix that mirrors space gives a negative X scale. A matrix that
159
+ * flattens space gives no rotation and a scale of 1.
166
160
  */
167
161
  export function decompose(position, rotation, scale, m) {
168
162
  const m11 = m[0];
@@ -3,8 +3,8 @@ export * from '../quat.js';
3
3
  /** The rotation of `rad` radians about `axis`, a vector of length 1. */
4
4
  export declare const setAxisAngle: <T extends QuatLike>(out: T, axis: Vec3Like, rad: number) => T;
5
5
  /**
6
- * The rotation of Euler angles in radians, applied in `order`, `'XYZ'` by default, as three.js's
7
- * `setFromEuler`. gl-matrix's `fromEuler` takes degrees, but this one takes radians.
6
+ * The rotation of Euler angles in radians, applied in `order`, `'XYZ'` by default. gl-matrix's
7
+ * `fromEuler` takes degrees, but this one takes radians.
8
8
  */
9
9
  export declare const fromEuler: <T extends QuatLike>(out: T, x: number, y: number, z: number, order?: EulerOrder) => T;
10
10
  /** Turns the rotation `a` by `rad` radians about its own X axis. */
@@ -15,6 +15,6 @@ export declare const rotateY: <T extends QuatLike>(out: T, a: QuatLike, rad: num
15
15
  export declare const rotateZ: <T extends QuatLike>(out: T, a: QuatLike, rad: number) => T;
16
16
  /**
17
17
  * The rotation a fraction `t` of the way from `a` to `b` along the shortest arc, turning at an even
18
- * speed, as three.js's `slerp`.
18
+ * speed.
19
19
  */
20
20
  export declare const slerp: <T extends QuatLike>(out: T, a: QuatLike, b: QuatLike, t: number) => T;