@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.
- package/README.md +109 -0
- package/THIRD-PARTY-NOTICES.txt +0 -1
- package/dist/wasm/single/null3d.js +19 -6
- package/dist/wasm/single/null3d_bg.wasm +0 -0
- package/dist/wasm/threaded/null3d.js +19 -6
- package/dist/wasm/threaded/null3d_bg.wasm +0 -0
- package/docs/api/animation.md +23 -67
- package/docs/api/assets.md +42 -26
- package/docs/api/cameras.md +8 -6
- package/docs/api/controls.md +46 -44
- package/docs/api/debug.md +13 -8
- package/docs/api/engine.md +17 -11
- package/docs/api/feature-draws.md +3 -3
- package/docs/api/feature-effects.md +3 -3
- package/docs/api/feature-instances.md +2 -2
- package/docs/api/features.md +14 -15
- package/docs/api/geometry.md +56 -75
- package/docs/api/grass.md +1 -1
- package/docs/api/impostors.md +120 -9
- package/docs/api/input.md +4 -11
- package/docs/api/lights.md +14 -38
- package/docs/api/lines.md +8 -25
- package/docs/api/materials.md +69 -70
- package/docs/api/math.md +6 -7
- package/docs/api/objects.md +13 -13
- package/docs/api/particles.md +2 -14
- package/docs/api/points.md +3 -25
- package/docs/api/post.md +22 -23
- package/docs/api/quality.md +11 -6
- package/docs/api/raycast.md +13 -32
- package/docs/api/reference/animation.md +9 -9
- package/docs/api/reference/assets.md +18 -18
- package/docs/api/reference/cameras.md +5 -2
- package/docs/api/reference/controls.md +75 -23
- package/docs/api/reference/debug.md +23 -8
- package/docs/api/reference/engine.md +22 -10
- package/docs/api/reference/geometry.md +161 -82
- package/docs/api/reference/grass.md +1 -1
- package/docs/api/reference/impostors.md +92 -1
- package/docs/api/reference/input.md +3 -3
- package/docs/api/reference/lights.md +9 -9
- package/docs/api/reference/lines.md +7 -7
- package/docs/api/reference/materials.md +48 -48
- package/docs/api/reference/math.md +22 -22
- package/docs/api/reference/objects.md +9 -9
- package/docs/api/reference/points.md +4 -4
- package/docs/api/reference/post.md +18 -18
- package/docs/api/reference/quality.md +7 -3
- package/docs/api/reference/raycast.md +6 -6
- package/docs/api/reference/render.md +2 -2
- package/docs/api/reference/scene.md +29 -26
- package/docs/api/reference/sketch.md +4 -0
- package/docs/api/reference/sound.md +203 -0
- package/docs/api/reference/sprites.md +5 -5
- package/docs/api/reference/terrain.md +2 -1
- package/docs/api/reference/textures.md +4 -4
- package/docs/api/reference/ui.md +3 -3
- package/docs/api/reference/vertex-draws.md +3 -3
- package/docs/api/reference/water.md +77 -6
- package/docs/api/reference/wind.md +2 -2
- package/docs/api/render.md +12 -10
- package/docs/api/scene.md +40 -29
- package/docs/api/sketch.md +64 -3
- package/docs/api/sound.md +169 -0
- package/docs/api/splats.md +7 -0
- package/docs/api/sprites.md +4 -20
- package/docs/api/tasks.md +2 -2
- package/docs/api/terrain.md +2 -14
- package/docs/api/textures.md +9 -9
- package/docs/api/ui.md +3 -15
- package/docs/api/water.md +198 -15
- package/docs/api/wind.md +5 -5
- package/docs/cli/null3d.md +93 -18
- package/docs/concepts/architecture.md +10 -10
- package/docs/concepts/assets.md +2 -19
- package/docs/concepts/backends.md +7 -5
- package/docs/concepts/color-management.md +15 -26
- package/docs/concepts/culling.md +1 -1
- package/docs/concepts/instances.md +5 -5
- package/docs/concepts/large-worlds.md +1 -1
- package/docs/concepts/lighting.md +50 -55
- package/docs/concepts/lod.md +2 -15
- package/docs/concepts/materials.md +16 -16
- package/docs/concepts/post-processing.md +7 -29
- package/docs/concepts/quality-preset-tables.md +53 -50
- package/docs/concepts/quality-presets.md +56 -27
- package/docs/concepts/render-graph.md +19 -14
- package/docs/concepts/render-layers.md +3 -17
- package/docs/concepts/shadows.md +10 -28
- package/docs/concepts/static-dynamic.md +2 -2
- package/docs/cookbook/index.md +1 -1
- package/docs/data/threejs-mapping.json +136 -102
- package/docs/errors/E1214.md +3 -3
- package/docs/errors/E1307.md +23 -0
- package/docs/errors/E1420.md +3 -3
- package/docs/errors/index.md +3 -2
- package/docs/getting-started/cdn.md +17 -1
- package/docs/getting-started/first-scene.md +1 -1
- package/docs/getting-started/hosting.md +50 -9
- package/docs/getting-started/install.md +8 -7
- package/docs/getting-started/network-use.md +10 -2
- package/docs/getting-started/project-structure.md +15 -6
- package/docs/getting-started/third-party-notices.md +8 -6
- package/docs/guides/accessibility.md +1 -1
- package/docs/guides/add-ons.md +3 -2
- package/docs/guides/agents.md +16 -5
- package/docs/guides/assets-pipeline.md +13 -12
- package/docs/guides/audio.md +109 -124
- package/docs/guides/car-paint.md +1 -1
- package/docs/guides/content-pages.md +10 -6
- package/docs/guides/custom-passes.md +9 -8
- package/docs/guides/custom-shaders.md +6 -3
- package/docs/guides/debugging.md +78 -4
- package/docs/guides/deploying.md +105 -5
- package/docs/guides/deterministic-simulation.md +1 -1
- package/docs/guides/first-use-shaders.md +4 -4
- package/docs/guides/loading-screens.md +78 -33
- package/docs/guides/multiple-views.md +41 -2
- package/docs/guides/performance.md +6 -3
- package/docs/guides/phones.md +12 -1
- package/docs/guides/physics.md +1 -1
- package/docs/guides/screens.md +7 -5
- package/docs/guides/start-time.md +328 -0
- package/docs/guides/testing.md +23 -5
- package/docs/guides/ui-overlays.md +3 -3
- package/docs/index.md +12 -8
- package/docs/pages.md +26 -23
- package/docs/porting/react-three-fiber.md +228 -5
- package/docs/porting/threejs-loop-and-threads.md +220 -6
- package/docs/porting/threejs-mapping.md +86 -84
- package/docs/porting/threejs-materials.md +212 -5
- package/docs/porting/threejs-overview.md +218 -5
- package/docs/porting/threejs-postprocessing.md +2 -2
- package/docs/porting/threejs-shaders.md +298 -5
- package/docs/porting/threejs-unsupported.md +82 -6
- package/docs/porting/verification.md +181 -5
- package/docs/shaders/builtins.md +1 -1
- package/docs/shaders/library.md +63 -39
- package/docs/shaders/surface-functions.md +11 -10
- package/docs/shaders/wgsl-rules.md +1 -1
- package/lib/debug/channel.d.ts +103 -0
- package/lib/debug/channel.js +269 -0
- package/lib/debug/debug.d.ts +9 -7
- package/lib/debug/draw.d.ts +9 -0
- package/lib/debug/draw.js +49 -2
- package/lib/debug/inspector.d.ts +60 -0
- package/lib/debug/inspector.js +475 -0
- package/lib/debug/stats-panel.d.ts +1 -1
- package/lib/debug/stats.d.ts +2 -3
- package/lib/errors/codes.js +8 -2
- package/lib/errors/engine-error.js +25 -10
- package/lib/errors/fixes.d.ts +1 -0
- package/lib/errors/fixes.js +3 -2
- package/lib/generated/core.d.ts +1 -1
- package/lib/generated/core.js +1 -1
- package/lib/gpu/early-builds.d.ts +68 -0
- package/lib/gpu/early-builds.js +158 -0
- package/lib/gpu/pipeline-name.d.ts +6 -0
- package/lib/gpu/pipeline-name.js +23 -0
- package/lib/gpu/webgl2/backend.d.ts +63 -2
- package/lib/gpu/webgl2/backend.js +226 -8
- package/lib/gpu/webgl2/programs.d.ts +18 -0
- package/lib/gpu/webgl2/programs.js +4 -1
- package/lib/gpu/webgpu/backend.d.ts +89 -2
- package/lib/gpu/webgpu/backend.js +255 -8
- package/lib/gpu/webgpu/pipelines.d.ts +13 -0
- package/lib/gpu/webgpu/pipelines.js +15 -1
- package/lib/index.d.ts +6 -4
- package/lib/index.js +3 -2
- package/lib/math/color.d.ts +5 -5
- package/lib/math/color.js +5 -5
- package/lib/math/mat4.d.ts +6 -12
- package/lib/math/mat4.js +6 -12
- package/lib/math/namespaces/quat.d.ts +3 -3
- package/lib/math/namespaces/quat.js +3 -3
- package/lib/math/quat.d.ts +8 -12
- package/lib/math/quat.js +8 -12
- package/lib/math/random.d.ts +2 -3
- package/lib/math/random.js +2 -3
- package/lib/math/types.d.ts +4 -4
- package/lib/math/vec3.d.ts +3 -6
- package/lib/math/vec3.js +3 -6
- package/lib/page/capabilities.d.ts +7 -7
- package/lib/page/capabilities.js +39 -25
- package/lib/page/check-store.d.ts +14 -2
- package/lib/page/check-store.js +34 -11
- package/lib/page/engine.d.ts +103 -26
- package/lib/page/engine.js +420 -97
- package/lib/page/first-frame.d.ts +16 -0
- package/lib/page/first-frame.js +35 -0
- package/lib/page/frame-stats.d.ts +34 -1
- package/lib/page/frame-stats.js +15 -0
- package/lib/page/label-loop.d.ts +7 -3
- package/lib/page/label-loop.js +17 -10
- package/lib/page/labels.d.ts +3 -3
- package/lib/page/pipeline-store.d.ts +25 -0
- package/lib/page/pipeline-store.js +84 -0
- package/lib/page/start-marker.d.ts +4 -1
- package/lib/page/start-marker.js +5 -2
- package/lib/page/switches.d.ts +32 -2
- package/lib/page/switches.js +9 -1
- package/lib/quality/check.d.ts +24 -3
- package/lib/quality/check.js +21 -7
- package/lib/quality/chooser.d.ts +6 -0
- package/lib/quality/chooser.js +8 -0
- package/lib/quality/governor.d.ts +98 -6
- package/lib/quality/governor.js +250 -20
- package/lib/quality/preset-docs.d.ts +16 -1
- package/lib/quality/preset-docs.js +3 -0
- package/lib/quality/presets.d.ts +84 -7
- package/lib/quality/presets.js +94 -2
- package/lib/render/draw.d.ts +3 -2
- package/lib/render/draw.js +15 -5
- package/lib/render/load-draw.d.ts +7 -5
- package/lib/render/load-draw.js +7 -5
- package/lib/render/loss.d.ts +28 -10
- package/lib/render/loss.js +50 -22
- package/lib/render/recovery.d.ts +20 -0
- package/lib/render/recovery.js +44 -4
- package/lib/render/renderer.d.ts +85 -9
- package/lib/render/renderer.js +181 -42
- package/lib/render/scene-renderer.d.ts +19 -1
- package/lib/render/scene-renderer.js +25 -1
- package/lib/render/webgl2-renderers.js +8 -5
- package/lib/render/webgpu-renderers.js +5 -4
- package/lib/scene/animation.d.ts +28 -32
- package/lib/scene/animation.js +12 -15
- package/lib/scene/assets.d.ts +61 -86
- package/lib/scene/assets.js +103 -236
- package/lib/scene/background.d.ts +14 -18
- package/lib/scene/background.js +5 -2
- package/lib/scene/color.d.ts +3 -3
- package/lib/scene/downloads.d.ts +2 -0
- package/lib/scene/downloads.js +371 -0
- package/lib/scene/environment.d.ts +7 -7
- package/lib/scene/environment.js +1 -1
- package/lib/scene/fake-call-values.js +1 -1
- package/lib/scene/fog.d.ts +11 -4
- package/lib/scene/fog.js +8 -2
- package/lib/scene/frame-cameras.d.ts +19 -0
- package/lib/scene/frame-cameras.js +58 -0
- package/lib/scene/gltf.d.ts +32 -2
- package/lib/scene/gltf.js +78 -49
- package/lib/scene/grading.d.ts +2 -2
- package/lib/scene/grading.js +3 -3
- package/lib/scene/ktx2.d.ts +9 -1
- package/lib/scene/ktx2.js +3 -2
- package/lib/scene/level-rule.d.ts +120 -0
- package/lib/scene/level-rule.js +130 -0
- package/lib/scene/lines.d.ts +13 -17
- package/lib/scene/lines.js +3 -3
- package/lib/scene/lut.d.ts +1 -2
- package/lib/scene/lut.js +1 -2
- package/lib/scene/picks.d.ts +2 -2
- package/lib/scene/pointer-events.d.ts +4 -7
- package/lib/scene/post.d.ts +38 -43
- package/lib/scene/post.js +4 -1
- package/lib/scene/prefab.d.ts +7 -8
- package/lib/scene/prefab.js +7 -8
- package/lib/scene/property-animation.d.ts +1 -1
- package/lib/scene/property-animation.js +1 -1
- package/lib/scene/queries.d.ts +7 -13
- package/lib/scene/resources.d.ts +225 -254
- package/lib/scene/resources.js +179 -81
- package/lib/scene/scene.d.ts +149 -118
- package/lib/scene/scene.js +196 -98
- package/lib/scene/serial-loads.d.ts +29 -0
- package/lib/scene/serial-loads.js +68 -0
- package/lib/scene/shader-preloads.d.ts +34 -0
- package/lib/scene/shader-preloads.js +38 -0
- package/lib/scene/sprites.d.ts +14 -17
- package/lib/scene/sprites.js +5 -6
- package/lib/scene/textures.d.ts +11 -12
- package/lib/scene/textures.js +9 -10
- package/lib/scene/time-of-day.d.ts +3 -4
- package/lib/scene/time-of-day.js +2 -3
- package/lib/scene/vertex-draws.d.ts +5 -4
- package/lib/scene/vertex-draws.js +7 -5
- package/lib/shader-artifact.json +1 -0
- package/lib/shared/core.d.ts +5 -0
- package/lib/shared/core.js +1 -0
- package/lib/shared/import-once.d.ts +6 -0
- package/lib/shared/import-once.js +19 -0
- package/lib/shared/metrics.d.ts +38 -0
- package/lib/shared/metrics.js +62 -1
- package/lib/shared/run-task.js +7 -1
- package/lib/shared/task-pending.d.ts +12 -0
- package/lib/shared/task-pending.js +61 -1
- package/lib/shared/tasks.js +79 -32
- package/lib/shared/version.d.ts +17 -1
- package/lib/shared/version.js +19 -1
- package/lib/shared/wasm.d.ts +12 -4
- package/lib/shared/wasm.js +50 -27
- package/lib/shared/worker-start.d.ts +7 -0
- package/lib/shared/worker-start.js +27 -0
- package/lib/sketch/define-sketch.d.ts +35 -0
- package/lib/sketch/input.d.ts +2 -2
- package/lib/sketch/preset-check.d.ts +20 -6
- package/lib/sketch/preset-check.js +42 -17
- package/lib/sketch/quality.d.ts +69 -11
- package/lib/sketch/quality.js +54 -13
- package/lib/sketch/runner.d.ts +76 -9
- package/lib/sketch/runner.js +385 -52
- package/lib/sketch/ui.d.ts +5 -8
- package/lib/workers/probe-worker.d.ts +5 -0
- package/lib/workers/probe-worker.js +13 -4
- package/lib/workers/protocol.d.ts +61 -13
- package/lib/workers/protocol.js +4 -0
- package/lib/workers/render-worker.js +25 -4
- package/lib/workers/sketch-worker.js +104 -15
- package/package.json +2 -2
package/lib/scene/assets.js
CHANGED
|
@@ -3,18 +3,26 @@
|
|
|
3
3
|
// environment map reader (environment-file.ts) or by the HDR file readers (panorama.ts), outside
|
|
4
4
|
// the sketch's frames, and the bytes of the downloads for loading screens. Built-in environments need
|
|
5
5
|
// no file: the GPU makes them (builtin-environments.ts), as it filters HDR files. Relative addresses resolve against the page's address, in every thread
|
|
6
|
-
// mode.
|
|
7
|
-
//
|
|
6
|
+
// mode. The downloads themselves, with the files that `preload` and the sketch's download list
|
|
7
|
+
// fetched ahead of their loads, are downloads.ts's.
|
|
8
8
|
import { DEV } from '../errors/checks.js';
|
|
9
9
|
import { EngineError } from '../errors/engine-error.js';
|
|
10
10
|
import { reasonOf } from '../errors/message.js';
|
|
11
11
|
import { Cubemap, writeSkyDefaults } from './background.js';
|
|
12
12
|
import { derivedCache } from './derived-cache.js';
|
|
13
|
+
import { Downloads } from './downloads.js';
|
|
13
14
|
import { Environment } from './environment.js';
|
|
14
15
|
import { FILE_LIMITS, imageSize, imageTooLarge } from './file-limits.js';
|
|
15
16
|
import { GltfExtensions } from './gltf-extensions.js';
|
|
16
17
|
import { toHalfFloat } from './half-float.js';
|
|
17
18
|
import { Lut } from './lut.js';
|
|
19
|
+
/**
|
|
20
|
+
* @internal The thread that runs a live sketch makes the downloads of its list from this module,
|
|
21
|
+
* before the engine's core has arrived, so they share this module's file. The class is internal,
|
|
22
|
+
* so the published declarations leave out this export as they leave out the class: a re-export of
|
|
23
|
+
* its own, unlike an export of the imported name, takes no import with it into them.
|
|
24
|
+
*/
|
|
25
|
+
export { Downloads } from './downloads.js';
|
|
18
26
|
/**
|
|
19
27
|
* Loads files, and textures from image files. Every call runs outside the sketch's frames, so a
|
|
20
28
|
* frame never waits for a download or a decode. A sketch finds it as `ctx.assets`. Addresses
|
|
@@ -24,19 +32,10 @@ import { Lut } from './lut.js';
|
|
|
24
32
|
*/
|
|
25
33
|
export class Assets {
|
|
26
34
|
textures;
|
|
35
|
+
base;
|
|
27
36
|
makers;
|
|
28
37
|
extensions;
|
|
29
|
-
|
|
30
|
-
/** Downloads that `preload` started, by address, which the first load of each takes. */
|
|
31
|
-
preloaded = new Map();
|
|
32
|
-
/** Downloads under way, by address, which loads at the same time share. */
|
|
33
|
-
pending = new Map();
|
|
34
|
-
handlers = new Set();
|
|
35
|
-
/** The handlers in registration order, for the report to walk by index. */
|
|
36
|
-
handlerList = [];
|
|
37
|
-
/** Bytes that have arrived, and the bytes of the responses whose length is known so far. */
|
|
38
|
-
loadedBytes = 0;
|
|
39
|
-
totalBytes = 0;
|
|
38
|
+
downloads;
|
|
40
39
|
/** @internal */
|
|
41
40
|
constructor(textures,
|
|
42
41
|
/** The page's address, which relative addresses resolve against. */
|
|
@@ -45,11 +44,14 @@ export class Assets {
|
|
|
45
44
|
* The handlers of glTF extensions that a sketch registered. They live outside the loader so
|
|
46
45
|
* that a registration answers at once, before the loader has loaded.
|
|
47
46
|
*/
|
|
48
|
-
extensions = new GltfExtensions()
|
|
47
|
+
extensions = new GltfExtensions(),
|
|
48
|
+
/** The downloads, which may have started before the loader, for the sketch's list. */
|
|
49
|
+
downloads = new Downloads(base)) {
|
|
49
50
|
this.textures = textures;
|
|
51
|
+
this.base = base;
|
|
50
52
|
this.makers = makers;
|
|
51
53
|
this.extensions = extensions;
|
|
52
|
-
this.
|
|
54
|
+
this.downloads = downloads;
|
|
53
55
|
}
|
|
54
56
|
/**
|
|
55
57
|
* Downloads an image file or a KTX2 file, decodes it off the sketch's frames, and makes a
|
|
@@ -66,7 +68,7 @@ export class Assets {
|
|
|
66
68
|
async loadTexture(url, options = {}) {
|
|
67
69
|
const call = 'assets.loadTexture';
|
|
68
70
|
const address = this.resolve(url);
|
|
69
|
-
const blob = await this.
|
|
71
|
+
const blob = await this.downloads.load(address, call);
|
|
70
72
|
const texture = (await isKtx2(blob))
|
|
71
73
|
? await loadKtx2(this.textures, blob, address, options, call)
|
|
72
74
|
: this.textures.fromImage(await decode(blob, address, options, call, this.textures.maxSize), options, options.premultipliedAlpha ? 1 : 0, call);
|
|
@@ -83,7 +85,7 @@ export class Assets {
|
|
|
83
85
|
const blob = await fetchAgain(source, call);
|
|
84
86
|
if (await isKtx2(blob)) {
|
|
85
87
|
const ktx2 = await ktx2Module(source.url, call);
|
|
86
|
-
const texels = await ktx2.reloadKtx2(textures, await blob.arrayBuffer(), source.url, options, level, call,
|
|
88
|
+
const texels = await ktx2.reloadKtx2(textures, await blob.arrayBuffer(), source.url, options, level, call, engineError);
|
|
87
89
|
textures.setTexels(target, texels, call);
|
|
88
90
|
}
|
|
89
91
|
else {
|
|
@@ -94,13 +96,12 @@ export class Assets {
|
|
|
94
96
|
});
|
|
95
97
|
}
|
|
96
98
|
/**
|
|
97
|
-
* Registers a handler for glTF extensions that an add-on reads
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* that reads an extension which another handler reads.
|
|
99
|
+
* Registers a handler for glTF extensions that an add-on reads. A file that carries one of the
|
|
100
|
+
* handler's extensions hands each primitive that holds one to the handler, and draws the parts
|
|
101
|
+
* that it returns. A file that requires such an extension loads with the handler and fails with
|
|
102
|
+
* E1417 without it. Register the handler before the first load that needs it. Returns a function
|
|
103
|
+
* that unregisters it. Throws E1213 for a handler without a list of extension names or a `load`
|
|
104
|
+
* function, and for one that reads an extension which another handler reads.
|
|
104
105
|
*/
|
|
105
106
|
registerGltfExtension(handler) {
|
|
106
107
|
return this.extensions.register(handler);
|
|
@@ -125,18 +126,22 @@ export class Assets {
|
|
|
125
126
|
const makers = this.makers;
|
|
126
127
|
if (!makers)
|
|
127
128
|
throw new Error(`${call}() needs the engine's meshes and materials`);
|
|
128
|
-
const
|
|
129
|
+
const loader = loadModule(address, call);
|
|
130
|
+
// The loader's worker starts as soon as its code arrives, while the file still downloads. A
|
|
131
|
+
// worker that fails reports it to the load that needs it.
|
|
132
|
+
loader.then((gltf) => gltf.startGltfWorker(engineError), () => { });
|
|
133
|
+
const [file, gltf] = await Promise.all([this.downloads.load(address, call), loader]);
|
|
129
134
|
return gltf.loadGltf({
|
|
130
135
|
...makers,
|
|
131
136
|
textures: this.textures,
|
|
132
|
-
download: (at, during) => this.file(rewritten(at, address, options, during), during),
|
|
137
|
+
download: (at, during) => this.downloads.file(rewritten(at, address, options, during), during),
|
|
133
138
|
decode: (blob, at, colorSpace, during) => decode(blob, at, { colorSpace, flipY: false }, during, this.textures.maxSize),
|
|
134
139
|
reloadsFrom: (texture, source, colorSpace, during) => {
|
|
135
140
|
// A load again reads the address that the first load read, as rewriteUrl gave it.
|
|
136
141
|
const url = source.url.href === address.href ? address : source.url;
|
|
137
142
|
this.reloadsFrom(texture, { ...source, url: rewritten(url, address, options, during) }, { colorSpace, flipY: false }, during);
|
|
138
143
|
},
|
|
139
|
-
error:
|
|
144
|
+
error: engineError,
|
|
140
145
|
extensionHandlers: this.extensions.all(),
|
|
141
146
|
}, file, address, call, options);
|
|
142
147
|
}
|
|
@@ -148,17 +153,18 @@ export class Assets {
|
|
|
148
153
|
async loadImageBitmap(url, options = {}) {
|
|
149
154
|
const call = 'assets.loadImageBitmap';
|
|
150
155
|
const address = this.resolve(url);
|
|
151
|
-
const blob = await this.
|
|
156
|
+
const blob = await this.downloads.load(address, call);
|
|
152
157
|
return decode(blob, address, options, call, FILE_LIMITS.imageSide);
|
|
153
158
|
}
|
|
154
159
|
/**
|
|
155
|
-
* Downloads six images and makes a `Cubemap` from them, a sky box for `scene.setBackground
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
* square or not of one size, and E1208
|
|
160
|
+
* Downloads six images and makes a `Cubemap` from them, a sky box for `scene.setBackground`:
|
|
161
|
+
* the faces toward +X, -X, +Y, -Y, +Z and -Z, in that order, each square and of one size, at
|
|
162
|
+
* most 2,048 pixels a side. The engine reads the faces as seen from inside the cube, mirrored
|
|
163
|
+
* across x, so a common six-image sky box shows the right way round. The images decode off the sketch's frames and upload in the frames
|
|
164
|
+
* after the call. A cube map does not light the scene: for light, and for a background that
|
|
165
|
+
* blurs, make an environment with `bunx @null3d/cli assets env`. Throws E1411, E1412 or E1413
|
|
166
|
+
* as `loadTexture` does, E1412 also when the faces are not square or not of one size, and E1208
|
|
167
|
+
* when `urls` does not hold six addresses.
|
|
162
168
|
*/
|
|
163
169
|
async loadCubemap(urls) {
|
|
164
170
|
const call = 'assets.loadCubemap';
|
|
@@ -167,7 +173,7 @@ export class Assets {
|
|
|
167
173
|
const limit = Math.min(this.textures.maxSize, CUBE_FACE_LIMIT);
|
|
168
174
|
const faces = await Promise.all(urls.map(async (url) => {
|
|
169
175
|
const address = this.resolve(url);
|
|
170
|
-
const blob = await this.
|
|
176
|
+
const blob = await this.downloads.load(address, call);
|
|
171
177
|
// A face keeps its first row at the top, as three.js uploads a cube texture's images.
|
|
172
178
|
return decode(blob, address, { flipY: false }, call, limit);
|
|
173
179
|
}));
|
|
@@ -183,17 +189,16 @@ export class Assets {
|
|
|
183
189
|
}
|
|
184
190
|
/**
|
|
185
191
|
* Downloads a color grading table in a `.cube` or a `.3dl` file and makes a `Lut` from it, for
|
|
186
|
-
* `post.set({ lut })`. It reads
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
* load.
|
|
192
|
+
* `post.set({ lut })`. It reads tables of 2 to 256 texels a side. A `.cube` file's domain and
|
|
193
|
+
* title come along; a `.3dl` file's values are whole numbers of the depth that its largest value
|
|
194
|
+
* or its `Mesh` line gives. The first table loads the readers. Throws E1411 or E1413 as
|
|
195
|
+
* `loadTexture` does, E1412 when the file holds no table that the engine reads, and E1406 when
|
|
196
|
+
* the readers do not load.
|
|
192
197
|
*/
|
|
193
198
|
async loadLut(url) {
|
|
194
199
|
const call = 'assets.loadLut';
|
|
195
200
|
const address = this.resolve(url);
|
|
196
|
-
const text = await (await this.
|
|
201
|
+
const text = await (await this.downloads.load(address, call)).text();
|
|
197
202
|
const files = await lutMakers(`${call}() of ${address}`);
|
|
198
203
|
let table;
|
|
199
204
|
try {
|
|
@@ -205,13 +210,12 @@ export class Assets {
|
|
|
205
210
|
return this.lut(table, call);
|
|
206
211
|
}
|
|
207
212
|
/**
|
|
208
|
-
* Makes a color grading table from numbers, for `post.set({ lut })
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
* above its minimum. Throws E1406 when the code does not load.
|
|
213
|
+
* Makes a color grading table from numbers, for `post.set({ lut })`. It takes the numbers in the
|
|
214
|
+
* order of a `.cube` file: three or four per texel, red changing fastest. A file and its numbers
|
|
215
|
+
* make the same table. The first table loads the code that makes it, as `loadLut` does. Throws
|
|
216
|
+
* E1208 when the size is not a whole number from 2 to 256, when `data` does not hold three or
|
|
217
|
+
* four numbers per texel, or holds a number that is not finite, and when a domain is not three
|
|
218
|
+
* numbers whose maximum is above its minimum. Throws E1406 when the code does not load.
|
|
215
219
|
*/
|
|
216
220
|
async lutFromData(table) {
|
|
217
221
|
const call = 'assets.lutFromData';
|
|
@@ -234,8 +238,7 @@ export class Assets {
|
|
|
234
238
|
/**
|
|
235
239
|
* Downloads an environment and makes an `Environment` from it, for `scene.setEnvironment`. It
|
|
236
240
|
* takes a KTX2 file that `bunx @null3d/cli assets env` made, the fast path, or an HDR file: a
|
|
237
|
-
* Radiance file (`.hdr`) or an OpenEXR file (`.exr`) of an equirectangular panorama
|
|
238
|
-
* three.js's `HDRLoader` and `EXRLoader` read them with `PMREMGenerator`.
|
|
241
|
+
* Radiance file (`.hdr`) or an OpenEXR file (`.exr`) of an equirectangular panorama.
|
|
239
242
|
*
|
|
240
243
|
* A KTX2 map's cube texture uploads in the frames after the call, and the scene draws without
|
|
241
244
|
* the environment until it is on the GPU. A worker reads an HDR file, off the sketch's
|
|
@@ -254,48 +257,54 @@ export class Assets {
|
|
|
254
257
|
return this.environment(address, call);
|
|
255
258
|
}
|
|
256
259
|
/**
|
|
257
|
-
* Makes a built-in environment: `room`,
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
* code does not download.
|
|
260
|
+
* Makes a built-in environment: `room`, a white room with boxes and glowing panels, for soft,
|
|
261
|
+
* neutral light with no file of your own. No file downloads: the GPU draws the room into its
|
|
262
|
+
* cube map and filters it for each roughness. It resolves once the code and the shaders that
|
|
263
|
+
* make the map are ready. The next frame then makes the whole map before it draws, so the first
|
|
264
|
+
* frame with the environment already has its light. That frame takes longer, by the map's GPU
|
|
265
|
+
* time: call it while the scene loads, since a call during play makes one long frame. The first
|
|
266
|
+
* one loads the code that makes it, about 12 KB after Brotli. Throws E1213 for a name that no
|
|
267
|
+
* built-in environment has, and E1406 when its code does not download.
|
|
266
268
|
*/
|
|
267
269
|
async builtinEnvironment(name) {
|
|
268
270
|
const call = 'assets.builtinEnvironment';
|
|
271
|
+
// The thread that draws loads the generators' code while the environments' tables load here.
|
|
272
|
+
this.makers?.materials.shaders.needGenerators();
|
|
269
273
|
const builtins = await builtinEnvironments(call);
|
|
270
274
|
if (!Object.hasOwn(builtins.BUILTIN_ENVIRONMENTS, name))
|
|
271
275
|
throw new EngineError('E1213', `${call}() got ${JSON.stringify(name)}, which names no built-in environment. Use 'room'.`);
|
|
272
276
|
const { size, levels, sh } = builtins.BUILTIN_ENVIRONMENTS[name];
|
|
273
277
|
const texture = await this.textures.fromGenerator(name, size, levels, call);
|
|
278
|
+
if (DEV)
|
|
279
|
+
this.downloads.noteMade(`${call}('${name}')`);
|
|
274
280
|
return new Environment(texture, size, levels, 'rgb9e5ufloat', sh);
|
|
275
281
|
}
|
|
276
282
|
/**
|
|
277
|
-
* Makes an environment of the scene's sky, the sky that `scene.setBackground({ sky })` draws
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
* the
|
|
281
|
-
* the scene's
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
* Brotli. Throws E1406 when that code does not download.
|
|
283
|
+
* Makes an environment of the scene's sky, the sky that `scene.setBackground({ sky })` draws.
|
|
284
|
+
* Light it with `scene.setEnvironment`. The map follows the sky: when the sketch moves the sun or
|
|
285
|
+
* changes the air or the clouds, the map refreshes over the next frames, and no call is needed.
|
|
286
|
+
* Until the scene's first sky background, it shows the sky's defaults. The map leaves out the
|
|
287
|
+
* sun's disc: the scene's directional light gives the sun's own light. The GPU draws the sky into
|
|
288
|
+
* the map and filters it for each roughness, and the CPU works out its diffuse light. It
|
|
289
|
+
* resolves once the code and the shaders that make the map are ready, and the next frame makes
|
|
290
|
+
* the whole map before it draws. The first call loads the code that makes environments, about
|
|
291
|
+
* 12 KB after Brotli. Throws E1406 when that code does not download.
|
|
287
292
|
*/
|
|
288
293
|
async skyEnvironment() {
|
|
289
294
|
const call = 'assets.skyEnvironment';
|
|
295
|
+
// The thread that draws loads the generators' code while the environments' tables load here.
|
|
296
|
+
this.makers?.materials.shaders.needGenerators();
|
|
290
297
|
const { size, levels, stages, capture, sh } = (await builtinEnvironments(call)).SKY_MAP;
|
|
291
298
|
const texture = await this.textures.fromGenerator('sky', size, levels, call);
|
|
292
299
|
this.textures.addSkyMap(texture, stages, capture, call, writeSkyDefaults);
|
|
300
|
+
if (DEV)
|
|
301
|
+
this.downloads.noteMade(`${call}()`);
|
|
293
302
|
return new Environment(texture, size, levels, 'rgb9e5ufloat', sh);
|
|
294
303
|
}
|
|
295
304
|
/** Downloads and reads an environment map's file, and makes its cube texture. */
|
|
296
305
|
async environment(address, call) {
|
|
297
306
|
const [file, reader] = await Promise.all([
|
|
298
|
-
this.
|
|
307
|
+
this.downloads.load(address, call),
|
|
299
308
|
environmentReader(call, String(address)),
|
|
300
309
|
]);
|
|
301
310
|
const bytes = await file.arrayBuffer();
|
|
@@ -321,7 +330,7 @@ export class Assets {
|
|
|
321
330
|
*/
|
|
322
331
|
prepareHdr() {
|
|
323
332
|
this.makers?.materials.shaders.needGenerators();
|
|
324
|
-
panoramaLoader().then((loader) => loader.startPanoramaReader(
|
|
333
|
+
panoramaLoader().then((loader) => loader.startPanoramaReader(engineError), () => undefined);
|
|
325
334
|
}
|
|
326
335
|
/**
|
|
327
336
|
* Reads a Radiance or OpenEXR file in the panorama worker, and makes its cube texture on the
|
|
@@ -336,7 +345,7 @@ export class Assets {
|
|
|
336
345
|
throw new EngineError('E1406', `the HDR file reader did not download for ${call}() of ${address}: ${reasonOf(error)}.`);
|
|
337
346
|
}
|
|
338
347
|
const { size, levels } = loader.PANORAMA_MAP;
|
|
339
|
-
const { panorama, sh } = await loader.readPanoramaFile(bytes, address, call,
|
|
348
|
+
const { panorama, sh } = await loader.readPanoramaFile(bytes, address, call, engineError);
|
|
340
349
|
const texture = await this.textures.fromGenerator(panorama, size, levels, call);
|
|
341
350
|
return new Environment(texture, size, levels, 'rgb9e5ufloat', sh);
|
|
342
351
|
}
|
|
@@ -351,7 +360,7 @@ export class Assets {
|
|
|
351
360
|
async loadLightProbeGrid(url) {
|
|
352
361
|
const call = 'assets.loadLightProbeGrid';
|
|
353
362
|
const address = this.resolve(url);
|
|
354
|
-
const text = await (await this.
|
|
363
|
+
const text = await (await this.downloads.load(address, call)).text();
|
|
355
364
|
const file = await bakedLightFile(text, address, call);
|
|
356
365
|
if (file.kind !== 'probe-grid')
|
|
357
366
|
wrongKind(address, call, file.kind, 'probe-grid');
|
|
@@ -374,7 +383,7 @@ export class Assets {
|
|
|
374
383
|
async loadLightMap(url) {
|
|
375
384
|
const call = 'assets.loadLightMap';
|
|
376
385
|
const address = this.resolve(url);
|
|
377
|
-
const text = await (await this.
|
|
386
|
+
const text = await (await this.downloads.load(address, call)).text();
|
|
378
387
|
const file = await bakedLightFile(text, address, call);
|
|
379
388
|
if (file.kind !== 'light-map')
|
|
380
389
|
wrongKind(address, call, file.kind, 'light-map');
|
|
@@ -468,7 +477,9 @@ export class Assets {
|
|
|
468
477
|
async loadJson(url) {
|
|
469
478
|
const call = 'assets.loadJson';
|
|
470
479
|
const address = this.resolve(url);
|
|
471
|
-
const text = await (await this.
|
|
480
|
+
const text = await (await this.downloads.load(address, call)).text();
|
|
481
|
+
if (DEV)
|
|
482
|
+
this.downloads.noteText(address, text);
|
|
472
483
|
try {
|
|
473
484
|
return JSON.parse(text);
|
|
474
485
|
}
|
|
@@ -479,7 +490,7 @@ export class Assets {
|
|
|
479
490
|
/** Downloads a file as bytes. Throws E1411 or E1413 as `loadTexture` does. */
|
|
480
491
|
async loadBinary(url) {
|
|
481
492
|
const address = this.resolve(url);
|
|
482
|
-
return (await this.
|
|
493
|
+
return (await this.downloads.load(address, 'assets.loadBinary')).arrayBuffer();
|
|
483
494
|
}
|
|
484
495
|
/**
|
|
485
496
|
* A namespace of the cache of derived data: bytes that a sketch or an add-on makes from its
|
|
@@ -496,174 +507,30 @@ export class Assets {
|
|
|
496
507
|
/**
|
|
497
508
|
* Downloads files ahead of their loads, all at once, and resolves when every one has arrived.
|
|
498
509
|
* The next load of each address takes its file from memory. Pair it with `onProgress` for a
|
|
499
|
-
* loading screen.
|
|
510
|
+
* loading screen. For the files that the setup loads, name them in `defineSketch`'s `downloads`
|
|
511
|
+
* option instead, which starts them sooner. Throws the error of the first file that fails, as
|
|
512
|
+
* `loadBinary` does, and the next load of that file downloads it again.
|
|
500
513
|
*/
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
const downloads = urls.map((url) => {
|
|
504
|
-
const address = this.resolve(url);
|
|
505
|
-
const key = address.href;
|
|
506
|
-
let download = this.preloaded.get(key);
|
|
507
|
-
if (!download) {
|
|
508
|
-
download = this.share(address, call);
|
|
509
|
-
this.preloaded.set(key, download);
|
|
510
|
-
// A failed file is not kept: a later load downloads it again.
|
|
511
|
-
download.then(undefined, () => this.preloaded.delete(key));
|
|
512
|
-
}
|
|
513
|
-
return download;
|
|
514
|
-
});
|
|
515
|
-
await Promise.all(downloads);
|
|
514
|
+
preload(urls) {
|
|
515
|
+
return this.downloads.preload(urls.map((url) => this.resolve(url)), 'assets.preload');
|
|
516
516
|
}
|
|
517
517
|
/**
|
|
518
518
|
* Calls `handler` as a download's bytes arrive and when one finishes or fails, with the bytes
|
|
519
519
|
* downloaded so far, the bytes expected so far and the address whose bytes moved, as
|
|
520
|
-
* `ProgressHandler` describes.
|
|
521
|
-
*
|
|
520
|
+
* `ProgressHandler` describes. The files of `defineSketch`'s `downloads` option count too, from
|
|
521
|
+
* before the setup adds the handler. Loads that take a file that `preload` or that option
|
|
522
|
+
* downloaded report no further. Returns a function that removes the handler.
|
|
522
523
|
*/
|
|
523
524
|
onProgress(handler) {
|
|
524
|
-
|
|
525
|
-
this.handlers.add(handler);
|
|
526
|
-
this.handlerList.push(handler);
|
|
527
|
-
}
|
|
528
|
-
return () => {
|
|
529
|
-
if (!this.handlers.delete(handler))
|
|
530
|
-
return;
|
|
531
|
-
// A new list, so a report that is walking the old one keeps its place and skips this
|
|
532
|
-
// handler by the set's membership.
|
|
533
|
-
this.handlerList = this.handlerList.filter((each) => each !== handler);
|
|
534
|
-
};
|
|
525
|
+
return this.downloads.onProgress(handler);
|
|
535
526
|
}
|
|
536
527
|
resolve(url) {
|
|
537
528
|
return new URL(url, this.base);
|
|
538
529
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
if (preloaded) {
|
|
544
|
-
this.preloaded.delete(key);
|
|
545
|
-
return preloaded;
|
|
546
|
-
}
|
|
547
|
-
return this.share(address, call);
|
|
548
|
-
}
|
|
549
|
-
/** The download of an address under way, or a new one. */
|
|
550
|
-
share(address, call) {
|
|
551
|
-
const key = address.href;
|
|
552
|
-
let download = this.pending.get(key);
|
|
553
|
-
if (!download) {
|
|
554
|
-
download = this.download(address, call);
|
|
555
|
-
this.pending.set(key, download);
|
|
556
|
-
const forget = () => this.pending.delete(key);
|
|
557
|
-
download.then(forget, forget);
|
|
558
|
-
}
|
|
559
|
-
return download;
|
|
560
|
-
}
|
|
561
|
-
/** Downloads a file, counts its bytes for the progress handlers, and gives failures their codes. */
|
|
562
|
-
async download(address, call) {
|
|
563
|
-
// The bytes this download's response announced, and whether it delivered them.
|
|
564
|
-
let announced = 0;
|
|
565
|
-
let delivered = false;
|
|
566
|
-
try {
|
|
567
|
-
let response;
|
|
568
|
-
try {
|
|
569
|
-
response = await fetch(address);
|
|
570
|
-
}
|
|
571
|
-
catch (error) {
|
|
572
|
-
// Fetch gives no reason for a blocked response, so another origin's refusal and a
|
|
573
|
-
// network failure look alike. Another origin's file usually fails for its headers.
|
|
574
|
-
if (address.origin !== new URL(this.base).origin)
|
|
575
|
-
throw new EngineError('E1413', `${call}() could not read ${address}: its server did not allow this page to read it, or could not be reached (${reasonOf(error)}).`);
|
|
576
|
-
throw new EngineError('E1411', `${call}() could not download ${address}: ${reasonOf(error)}.`);
|
|
577
|
-
}
|
|
578
|
-
if (!response.ok)
|
|
579
|
-
throw new EngineError('E1411', `${call}() could not download ${address}: HTTP ${response.status}.`);
|
|
580
|
-
const length = Number(response.headers.get('content-length'));
|
|
581
|
-
if (Number.isFinite(length) && length > 0) {
|
|
582
|
-
this.totalBytes += length;
|
|
583
|
-
announced = length;
|
|
584
|
-
}
|
|
585
|
-
try {
|
|
586
|
-
// A page that watches progress reads the body in chunks, which is the only way to see
|
|
587
|
-
// the bytes before the whole file arrives. With no handler the browser makes the blob
|
|
588
|
-
// in one step, as before.
|
|
589
|
-
if (this.handlers.size > 0 && response.body) {
|
|
590
|
-
const streamed = await this.read(response, address);
|
|
591
|
-
delivered = true;
|
|
592
|
-
return streamed;
|
|
593
|
-
}
|
|
594
|
-
const blob = await response.blob();
|
|
595
|
-
this.loadedBytes += blob.size;
|
|
596
|
-
this.report(address.href);
|
|
597
|
-
delivered = true;
|
|
598
|
-
return blob;
|
|
599
|
-
}
|
|
600
|
-
catch (error) {
|
|
601
|
-
throw new EngineError('E1411', `${call}() could not download ${address}: ${reasonOf(error)}.`);
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
finally {
|
|
605
|
-
// A file that failed counts as done, so a loading bar reaches its end: the bytes its
|
|
606
|
-
// response announced still count, and a failure that announced none counts one byte. A
|
|
607
|
-
// file that arrived reported as its last bytes came, so it reports nothing here.
|
|
608
|
-
if (!delivered) {
|
|
609
|
-
if (announced > 0)
|
|
610
|
-
this.loadedBytes += announced;
|
|
611
|
-
else {
|
|
612
|
-
this.loadedBytes += 1;
|
|
613
|
-
this.totalBytes += 1;
|
|
614
|
-
}
|
|
615
|
-
this.report(address.href);
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
/** Reads a response's body in chunks, counting each as it arrives. */
|
|
620
|
-
async read(response, address) {
|
|
621
|
-
const reader = response.body?.getReader();
|
|
622
|
-
if (!reader) {
|
|
623
|
-
const blob = await response.blob();
|
|
624
|
-
this.loadedBytes += blob.size;
|
|
625
|
-
return blob;
|
|
626
|
-
}
|
|
627
|
-
const chunks = [];
|
|
628
|
-
for (;;) {
|
|
629
|
-
const { done, value } = await reader.read();
|
|
630
|
-
if (done)
|
|
631
|
-
break;
|
|
632
|
-
chunks.push(value);
|
|
633
|
-
this.loadedBytes += value.byteLength;
|
|
634
|
-
this.report(address.href);
|
|
635
|
-
}
|
|
636
|
-
return new Blob(chunks);
|
|
637
|
-
}
|
|
638
|
-
/** The bytes, total and address that the handlers last saw, so a repeat reports nothing. */
|
|
639
|
-
reportedLoaded = 0;
|
|
640
|
-
reportedTotal = 0;
|
|
641
|
-
reportedUrl = null;
|
|
642
|
-
report(url) {
|
|
643
|
-
// A chunk's report and the download's end can hold the same numbers; the handlers see one.
|
|
644
|
-
if (url === this.reportedUrl &&
|
|
645
|
-
this.loadedBytes === this.reportedLoaded &&
|
|
646
|
-
this.totalBytes === this.reportedTotal)
|
|
647
|
-
return;
|
|
648
|
-
this.reportedLoaded = this.loadedBytes;
|
|
649
|
-
this.reportedTotal = this.totalBytes;
|
|
650
|
-
this.reportedUrl = url;
|
|
651
|
-
// The handlers as this report began: one removed during it is skipped. An addition is
|
|
652
|
-
// appended to the same list, so the walk reaches it unless an earlier removal replaced the
|
|
653
|
-
// list. Walking by index makes no iterator per report.
|
|
654
|
-
const handlers = this.handlerList;
|
|
655
|
-
for (let i = 0; i < handlers.length; i++) {
|
|
656
|
-
const handler = handlers[i];
|
|
657
|
-
if (handler === undefined || !this.handlers.has(handler))
|
|
658
|
-
continue;
|
|
659
|
-
try {
|
|
660
|
-
handler(this.loadedBytes, this.totalBytes, url);
|
|
661
|
-
}
|
|
662
|
-
catch (error) {
|
|
663
|
-
console.error(error);
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
}
|
|
530
|
+
}
|
|
531
|
+
/** Makes an engine error, for the loaders that run off this module and give their errors codes. */
|
|
532
|
+
function engineError(code, message) {
|
|
533
|
+
return new EngineError(code, message);
|
|
667
534
|
}
|
|
668
535
|
/** The identifier that starts every KTX2 file. */
|
|
669
536
|
const KTX2_IDENTIFIER = [0xab, 0x4b, 0x54, 0x58, 0x20, 0x32, 0x30, 0xbb, 0x0d, 0x0a, 0x1a, 0x0a];
|
|
@@ -715,7 +582,7 @@ async function loadKtx2(textures, blob, address, options, call) {
|
|
|
715
582
|
throw refuse('premultipliedAlpha', 'Its compressed colors cannot change: encode the file from colors multiplied by alpha.');
|
|
716
583
|
}
|
|
717
584
|
const ktx2 = await ktx2Module(address, call);
|
|
718
|
-
return ktx2.loadKtx2(textures, await blob.arrayBuffer(), address, options, call,
|
|
585
|
+
return ktx2.loadKtx2(textures, await blob.arrayBuffer(), address, options, call, engineError);
|
|
719
586
|
}
|
|
720
587
|
/**
|
|
721
588
|
* The address to download for one that a model file at `file` names: `options.rewriteUrl`'s
|
|
@@ -3,8 +3,8 @@ import type { CompiledWgsl } from './resources.js';
|
|
|
3
3
|
import { Texture } from './textures.js';
|
|
4
4
|
/**
|
|
5
5
|
* A cube map of six images, which `assets.loadCubemap` loads, for a sky box behind every object:
|
|
6
|
-
* `scene.setBackground(cubemap)
|
|
7
|
-
*
|
|
6
|
+
* `scene.setBackground(cubemap)`. The engine reads the faces as seen from inside the cube, mirrored
|
|
7
|
+
* across x. It does not light the scene: light comes from an environment.
|
|
8
8
|
*
|
|
9
9
|
* @category api/assets
|
|
10
10
|
*/
|
|
@@ -22,17 +22,16 @@ export declare class Cubemap {
|
|
|
22
22
|
destroy(): void;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
* The settings of
|
|
26
|
-
* call that leaves a setting out takes its default.
|
|
25
|
+
* The settings of the analytic sky, the Preetham daylight model with a sun disc and drifting
|
|
26
|
+
* clouds. A call that leaves a setting out takes its default.
|
|
27
27
|
*
|
|
28
28
|
* @category api/scene
|
|
29
29
|
*/
|
|
30
30
|
export interface SkyOptions {
|
|
31
31
|
/**
|
|
32
|
-
* A point toward the sun
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* example sets it: `[0, 0.0349, -0.9994]`.
|
|
32
|
+
* A point toward the sun. Its direction places the sun. A point far below the horizon, hundreds
|
|
33
|
+
* of thousands of units down, also dims the sky. The default is the sun 2 degrees above the
|
|
34
|
+
* horizon toward -Z: `[0, 0.0349, -0.9994]`.
|
|
36
35
|
*/
|
|
37
36
|
sunPosition?: readonly [number, number, number];
|
|
38
37
|
/** The haze in the air, 0 or more. The default is 2. */
|
|
@@ -73,7 +72,7 @@ export interface SkyOptions {
|
|
|
73
72
|
secondSkyWeight?: number;
|
|
74
73
|
}
|
|
75
74
|
/**
|
|
76
|
-
*
|
|
75
|
+
* The analytic sky as a background: `scene.setBackground({ sky: { sunPosition } })`.
|
|
77
76
|
*
|
|
78
77
|
* @category api/scene
|
|
79
78
|
*/
|
|
@@ -162,26 +161,23 @@ export interface AtmosphereBackground {
|
|
|
162
161
|
* @category api/scene
|
|
163
162
|
*/
|
|
164
163
|
export interface BackgroundOptions {
|
|
165
|
-
/**
|
|
166
|
-
* The factor of the background's light, 0 or more, as three.js's `scene.backgroundIntensity`.
|
|
167
|
-
* The default is 1.
|
|
168
|
-
*/
|
|
164
|
+
/** The factor of the background's light, 0 or more. The default is 1. */
|
|
169
165
|
intensity?: number;
|
|
170
166
|
/**
|
|
171
|
-
* How much an environment blurs, from 0 (sharp) to 1
|
|
172
|
-
*
|
|
173
|
-
*
|
|
167
|
+
* How much an environment blurs, from 0 (sharp) to 1. It reads the environment's light at that
|
|
168
|
+
* roughness, so a blurred background costs no more than a sharp one. Only environments blur.
|
|
169
|
+
* The default is 0.
|
|
174
170
|
*/
|
|
175
171
|
blur?: number;
|
|
176
172
|
/**
|
|
177
173
|
* The turn of a cube map or an environment about the scene, as Euler angles in radians in the
|
|
178
|
-
* order X, Y, Z
|
|
174
|
+
* order X, Y, Z. The default is `[0, 0, 0]`.
|
|
179
175
|
*/
|
|
180
176
|
rotation?: readonly [number, number, number];
|
|
181
177
|
}
|
|
182
178
|
/**
|
|
183
179
|
* What `scene.setBackground` draws behind every object in place of a plain color: a texture, an
|
|
184
|
-
* environment, a cube map,
|
|
180
|
+
* environment, a cube map, the analytic sky or the physical sky.
|
|
185
181
|
*
|
|
186
182
|
* @category api/scene
|
|
187
183
|
*/
|