@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/gltf.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { EngineError } from '../errors/engine-error.js';
|
|
2
2
|
import type { WasmError } from '../shared/wasm.js';
|
|
3
|
+
import type { GltfAnswer, GltfRequest } from '../workers/gltf-worker.js';
|
|
3
4
|
import type { FileSource, GltfExtensionHandler, LoadGltfOptions } from './assets.js';
|
|
4
5
|
import type { GltfData, PrimitiveData } from './gltf-parse.js';
|
|
5
6
|
import type { CoreMemory } from './memory.js';
|
|
@@ -35,6 +36,32 @@ export interface GltfContext {
|
|
|
35
36
|
/** The handlers that add-ons registered for glTF extensions, if the page loaded any. */
|
|
36
37
|
extensionHandlers: readonly GltfExtensionHandler[];
|
|
37
38
|
}
|
|
39
|
+
/** A request that waits for the worker. */
|
|
40
|
+
interface Waiting {
|
|
41
|
+
resolve(answer: GltfAnswer): void;
|
|
42
|
+
reject(reason: string): void;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The glTF worker and the requests that wait for it. A worker that fails to start fails every
|
|
46
|
+
* request, and a later load starts it again.
|
|
47
|
+
*/
|
|
48
|
+
declare class Parser {
|
|
49
|
+
private readonly stopped;
|
|
50
|
+
private readonly worker;
|
|
51
|
+
private readonly waiting;
|
|
52
|
+
private next;
|
|
53
|
+
constructor(stopped: () => void, error: WasmError);
|
|
54
|
+
/** Stops the worker, and fails every waiting request with `reason`. */
|
|
55
|
+
stop(reason: string): void;
|
|
56
|
+
/** A new request's id, whose answers go to `resolve` until the last one. */
|
|
57
|
+
start(resolve: Waiting['resolve'], reject: Waiting['reject']): number;
|
|
58
|
+
send(request: GltfRequest, transfer: Transferable[]): void;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* This thread's glTF worker, started now unless it runs. A model's load starts it as the file's
|
|
62
|
+
* download begins, so the worker's script and its start overlap the download.
|
|
63
|
+
*/
|
|
64
|
+
export declare function startGltfWorker(error: WasmError): Parser;
|
|
38
65
|
/** Loads a glTF file into a prefab. Throws E1416, E1417, E1411, E1412, E1413 or E1406. */
|
|
39
66
|
export declare function loadGltf(context: GltfContext, file: Blob, address: URL, call: string, options?: LoadGltfOptions): Promise<Prefab>;
|
|
40
67
|
/**
|
|
@@ -96,8 +123,11 @@ export declare function readStageBand(bytes: ArrayBuffer): StageBand | undefined
|
|
|
96
123
|
export declare function warnUnreadExtensions(data: GltfData, address: URL, call: string): void;
|
|
97
124
|
/**
|
|
98
125
|
* One texture for each texture use: from a bitmap the worker decoded, an image file, or KTX2 data.
|
|
99
|
-
*
|
|
100
|
-
*
|
|
126
|
+
* Every use decodes at once, and the textures are made in the order the file lists them once all
|
|
127
|
+
* have decoded, so their order never follows the order in which the images finish decoding: a
|
|
128
|
+
* texture's id, and so the order of the draws that use it, is the same on every run. When one
|
|
129
|
+
* fails, it closes the images and destroys the textures it made, and throws the first failure.
|
|
130
|
+
* Exported for its tests.
|
|
101
131
|
*/
|
|
102
132
|
export declare function makeTextures(context: GltfContext, data: GltfData, bitmaps: (ImageBitmap | undefined)[], address: URL, call: string): Promise<(Texture | undefined)[]>;
|
|
103
133
|
/**
|
package/lib/scene/gltf.js
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
import { FLAG_OCCLUDER, FLAG_VISIBLE, LAYERS_DEFAULT, LIGHT_KIND_DIRECTIONAL, LIGHT_KIND_POINT, LIGHT_KIND_SPOT, LIGHT_VALUE_ANGLE, LIGHT_VALUE_DECAY, LIGHT_VALUE_INTENSITY, LIGHT_VALUE_PENUMBRA, LIGHT_VALUE_RANGE, MAP_SLOT_BASE_COLOR, MAP_SLOT_EMISSIVE, } from '../generated/core.js';
|
|
19
19
|
import { DEV } from '../shared/dev.js';
|
|
20
20
|
import { onEngineStop } from '../shared/helper-workers.js';
|
|
21
|
+
import { importOnce } from '../shared/import-once.js';
|
|
21
22
|
import { compileOnce } from '../shared/tasks.js';
|
|
22
23
|
import { bootstrapFailure, spawnWorker, watchWorkerError } from '../shared/worker-start.js';
|
|
23
24
|
import { destroyRig, loadAnimationRig } from './animation.js';
|
|
@@ -92,20 +93,27 @@ class Parser {
|
|
|
92
93
|
/** This thread's glTF worker, which starts with the first file. */
|
|
93
94
|
let parser;
|
|
94
95
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
96
|
+
* This thread's glTF worker, started now unless it runs. A model's load starts it as the file's
|
|
97
|
+
* download begins, so the worker's script and its start overlap the download.
|
|
97
98
|
*/
|
|
98
|
-
function
|
|
99
|
+
export function startGltfWorker(error) {
|
|
99
100
|
if (!parser) {
|
|
100
101
|
const made = new Parser(() => {
|
|
101
102
|
forget();
|
|
102
103
|
if (parser === made)
|
|
103
104
|
parser = undefined;
|
|
104
|
-
},
|
|
105
|
+
}, error);
|
|
105
106
|
const forget = onEngineStop(() => made.stop('the engine stopped'));
|
|
106
107
|
parser = made;
|
|
107
108
|
}
|
|
108
|
-
|
|
109
|
+
return parser;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Parses a file in the glTF worker, downloading the buffers it names by address on the way, and
|
|
113
|
+
* returns its data and the bitmaps of the images it holds, one for each texture use.
|
|
114
|
+
*/
|
|
115
|
+
function parse(context, file, address, call) {
|
|
116
|
+
const worker = startGltfWorker(context.error);
|
|
109
117
|
return new Promise((resolve, reject) => {
|
|
110
118
|
const id = worker.start((answer) => {
|
|
111
119
|
if ('error' in answer) {
|
|
@@ -876,22 +884,18 @@ async function makeRig(context, data, address, call) {
|
|
|
876
884
|
}
|
|
877
885
|
/**
|
|
878
886
|
* One texture for each texture use: from a bitmap the worker decoded, an image file, or KTX2 data.
|
|
879
|
-
*
|
|
880
|
-
*
|
|
887
|
+
* Every use decodes at once, and the textures are made in the order the file lists them once all
|
|
888
|
+
* have decoded, so their order never follows the order in which the images finish decoding: a
|
|
889
|
+
* texture's id, and so the order of the draws that use it, is the same on every run. When one
|
|
890
|
+
* fails, it closes the images and destroys the textures it made, and throws the first failure.
|
|
891
|
+
* Exported for its tests.
|
|
881
892
|
*/
|
|
882
893
|
export async function makeTextures(context, data, bitmaps, address, call) {
|
|
883
894
|
const files = new Map();
|
|
884
|
-
/** The
|
|
885
|
-
const
|
|
886
|
-
const options = {
|
|
887
|
-
colorSpace: use.colorSpace,
|
|
888
|
-
wrap: use.wrap,
|
|
889
|
-
filter: use.filter,
|
|
890
|
-
mipmaps: use.mipmaps,
|
|
891
|
-
uvSet: use.uvSet,
|
|
892
|
-
};
|
|
895
|
+
/** The decoded image or the transcoded texels of one use. */
|
|
896
|
+
const sourceOf = async (use, bitmap) => {
|
|
893
897
|
if (bitmap)
|
|
894
|
-
return
|
|
898
|
+
return { image: bitmap };
|
|
895
899
|
const image = data.images[use.image];
|
|
896
900
|
let bytes = image?.bytes;
|
|
897
901
|
let source = address;
|
|
@@ -904,55 +908,80 @@ export async function makeTextures(context, data, bitmaps, address, call) {
|
|
|
904
908
|
}
|
|
905
909
|
const blob = await file;
|
|
906
910
|
const head = new Uint8Array(await blob.slice(0, KTX2_IDENTIFIER.length).arrayBuffer());
|
|
907
|
-
if (!isKtx2(head))
|
|
908
|
-
|
|
909
|
-
return context.textures.fromImage(decoded, options, 0, call);
|
|
910
|
-
}
|
|
911
|
+
if (!isKtx2(head))
|
|
912
|
+
return { image: await context.decode(blob, source, use.colorSpace, call) };
|
|
911
913
|
bytes = new Uint8Array(await blob.arrayBuffer());
|
|
912
914
|
}
|
|
913
915
|
if (!bytes)
|
|
914
916
|
return undefined;
|
|
915
|
-
return
|
|
917
|
+
return { texels: await ktx2Texels(context, bytes.slice().buffer, source, use, call) };
|
|
916
918
|
};
|
|
917
|
-
const
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
919
|
+
const sources = await Promise.allSettled(data.textures.map((use, k) => sourceOf(use, bitmaps[k])));
|
|
920
|
+
/** Closes the decoded images of the uses from `first` on, and the bitmaps of those that failed. */
|
|
921
|
+
const closeFrom = (first) => {
|
|
922
|
+
for (let k = first; k < sources.length; k++) {
|
|
923
|
+
const result = sources[k];
|
|
924
|
+
if (result.status === 'rejected')
|
|
925
|
+
bitmaps[k]?.close();
|
|
926
|
+
else if (result.value && 'image' in result.value)
|
|
927
|
+
result.value.image.close();
|
|
928
|
+
}
|
|
929
|
+
};
|
|
930
|
+
const failed = sources.find((r) => r.status === 'rejected');
|
|
931
|
+
if (failed) {
|
|
932
|
+
closeFrom(0);
|
|
933
|
+
throw failed.reason;
|
|
934
|
+
}
|
|
935
|
+
const textures = [];
|
|
936
|
+
try {
|
|
937
|
+
for (const [k, use] of data.textures.entries()) {
|
|
938
|
+
const source = sources[k].value;
|
|
939
|
+
const options = textureOptions(use);
|
|
940
|
+
const texture = source === undefined
|
|
941
|
+
? undefined
|
|
942
|
+
: 'image' in source
|
|
943
|
+
? context.textures.fromImage(source.image, { ...options, mipmaps: use.mipmaps }, 0, call)
|
|
944
|
+
: context.textures.fromTexels(source.texels, options, call);
|
|
945
|
+
textures.push(texture);
|
|
946
|
+
// The texture memory budget may drop the levels of a texture whose file the engine can
|
|
947
|
+
// read again: an image file, or an image inside a buffer of a file.
|
|
948
|
+
const image = data.images[use.image];
|
|
949
|
+
const file = image?.url
|
|
950
|
+
? { url: new URL(image.url) }
|
|
951
|
+
: image?.source && { ...image.source, url: new URL(image.source.url) };
|
|
952
|
+
if (texture && file)
|
|
953
|
+
context.reloadsFrom(texture, file, use.colorSpace, call);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
catch (error) {
|
|
957
|
+
for (const texture of textures)
|
|
958
|
+
texture?.destroy();
|
|
959
|
+
closeFrom(textures.length);
|
|
960
|
+
throw error;
|
|
961
|
+
}
|
|
962
|
+
return textures;
|
|
939
963
|
}
|
|
940
|
-
/**
|
|
941
|
-
|
|
964
|
+
/** The KTX2 loader's module, which a page downloads with its first KTX2 texture. */
|
|
965
|
+
const ktx2Code = importOnce(() => import('./ktx2.js'));
|
|
966
|
+
/** The texels of KTX2 data, through the KTX2 loader, which this imports the first time. */
|
|
967
|
+
async function ktx2Texels(context, file, address, use, call) {
|
|
942
968
|
let ktx2;
|
|
943
969
|
try {
|
|
944
|
-
ktx2 = await
|
|
970
|
+
ktx2 = await ktx2Code();
|
|
945
971
|
}
|
|
946
972
|
catch (error) {
|
|
947
973
|
throw context.error('E1406', `the KTX2 loader did not download for ${call}() of ${address}: ${error instanceof Error ? error.message : String(error)}.`);
|
|
948
974
|
}
|
|
949
|
-
|
|
975
|
+
return ktx2.transcodeKtx2(context.textures, file, address, textureOptions(use), call, (code, message) => context.error(code, message));
|
|
976
|
+
}
|
|
977
|
+
/** A texture use's options for its texture, apart from its mipmaps, which an image takes. */
|
|
978
|
+
function textureOptions(use) {
|
|
979
|
+
return {
|
|
950
980
|
colorSpace: use.colorSpace,
|
|
951
981
|
wrap: use.wrap,
|
|
952
982
|
filter: use.filter,
|
|
953
983
|
uvSet: use.uvSet,
|
|
954
984
|
};
|
|
955
|
-
return ktx2.loadKtx2(context.textures, file, address, options, call, (code, message) => context.error(code, message));
|
|
956
985
|
}
|
|
957
986
|
const KTX2_IDENTIFIER = [0xab, 0x4b, 0x54, 0x58, 0x20, 0x32, 0x30, 0xbb, 0x0d, 0x0a, 0x1a, 0x0a];
|
|
958
987
|
function isKtx2(bytes) {
|
package/lib/scene/grading.d.ts
CHANGED
|
@@ -42,8 +42,8 @@ export interface SplitToningSettings {
|
|
|
42
42
|
strength?: number;
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
|
-
* The grading controls that `post.set` takes: white balance, then lift, gamma
|
|
46
|
-
*
|
|
45
|
+
* The grading controls that `post.set` takes: white balance, then saturation, then lift, gamma
|
|
46
|
+
* and gain on each channel, then split toning. A job worker bakes them into a table of 32 texels a
|
|
47
47
|
* side, which the final pass reads on every GPU path. A setting that a call leaves out keeps its
|
|
48
48
|
* value; `false` turns the grading off.
|
|
49
49
|
*
|
package/lib/scene/grading.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// The grading controls that `post.set({ grading })` sets, and the 32-texel table that a job worker
|
|
2
|
-
// bakes from them: white balance, lift, gamma, gain
|
|
3
|
-
// the picture's display color after the tone mapping. The final pass reads the table,
|
|
4
|
-
// value costs the frames nothing but a texture upload that the worker computed.
|
|
2
|
+
// bakes from them: white balance, saturation, lift, gamma, gain and split toning, in that order,
|
|
3
|
+
// applied to the picture's display color after the tone mapping. The final pass reads the table,
|
|
4
|
+
// so changing a value costs the frames nothing but a texture upload that the worker computed.
|
|
5
5
|
//
|
|
6
6
|
// The lookup takes the color's square root first, so the table's texels lie closer together toward
|
|
7
7
|
// black, where a grade's curve is steepest. This module is loaded on first use, and the job worker
|
package/lib/scene/ktx2.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { EngineError } from '../errors/engine-error.js';
|
|
|
2
2
|
import type { WasmError } from '../shared/wasm.js';
|
|
3
3
|
import type { LoadTextureOptions } from './assets.js';
|
|
4
4
|
import { type Ktx2Header, type Ktx2Target } from './ktx2-file.js';
|
|
5
|
-
import type { Texture, Textures } from './textures.js';
|
|
5
|
+
import type { FileTexels, Texture, Textures } from './textures.js';
|
|
6
6
|
/**
|
|
7
7
|
* The format that a file's data becomes on a device with `capabilities`: UASTC keeps the most
|
|
8
8
|
* detail in ASTC, then BC7, then ETC2. ETC1S data is ETC1, so it becomes ETC2 first, at half the
|
|
@@ -32,3 +32,11 @@ export declare function loadKtx2(textures: Textures, file: ArrayBuffer, address:
|
|
|
32
32
|
* the file: each remaining level's layers in turn, as `transcodeKtx2` gives them.
|
|
33
33
|
*/
|
|
34
34
|
export declare function reloadKtx2(textures: Textures, file: ArrayBuffer, address: URL, options: LoadTextureOptions, level: number, call: string, error: Ktx2Error): Promise<Uint8Array>;
|
|
35
|
+
/**
|
|
36
|
+
* Transcodes a KTX2 file, which moves to the transcoder's worker, into the format of `ktx2Target`,
|
|
37
|
+
* with the file's mip levels unless `mipmaps` is false, for `textures.fromTexels`. Throws as
|
|
38
|
+
* `loadKtx2` does.
|
|
39
|
+
*/
|
|
40
|
+
export declare function transcodeKtx2(textures: Textures, file: ArrayBuffer, address: URL, options: LoadTextureOptions, call: string, error: Ktx2Error): Promise<FileTexels & {
|
|
41
|
+
format: Ktx2Target['format'];
|
|
42
|
+
}>;
|
package/lib/scene/ktx2.js
CHANGED
|
@@ -125,9 +125,10 @@ export async function reloadKtx2(textures, file, address, options, level, call,
|
|
|
125
125
|
}
|
|
126
126
|
/**
|
|
127
127
|
* Transcodes a KTX2 file, which moves to the transcoder's worker, into the format of `ktx2Target`,
|
|
128
|
-
* with the file's mip levels unless `mipmaps` is false. Throws as
|
|
128
|
+
* with the file's mip levels unless `mipmaps` is false, for `textures.fromTexels`. Throws as
|
|
129
|
+
* `loadKtx2` does.
|
|
129
130
|
*/
|
|
130
|
-
async function transcodeKtx2(textures, file, address, options, call, error) {
|
|
131
|
+
export async function transcodeKtx2(textures, file, address, options, call, error) {
|
|
131
132
|
let header;
|
|
132
133
|
try {
|
|
133
134
|
header = readKtx2Header(new Uint8Array(file));
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A view that measures levels of detail: the height it renders, its vertical field of view, and the
|
|
3
|
+
* threshold under which a coarser level draws.
|
|
4
|
+
*
|
|
5
|
+
* @category api/geometry
|
|
6
|
+
*/
|
|
7
|
+
export interface LevelView {
|
|
8
|
+
/** The render height in pixels. */
|
|
9
|
+
readonly height: number;
|
|
10
|
+
/** The vertical field of view in degrees, between 0 and 180. */
|
|
11
|
+
readonly fov: number;
|
|
12
|
+
/**
|
|
13
|
+
* The largest change, in pixels, that a coarser level may make to the picture. The default is 1,
|
|
14
|
+
* the setting of the presets that High and above draw. A larger threshold draws coarser levels
|
|
15
|
+
* from nearer.
|
|
16
|
+
*/
|
|
17
|
+
readonly threshold?: number;
|
|
18
|
+
/**
|
|
19
|
+
* True for an orthographic camera, whose pixels do not shrink with distance. The default is
|
|
20
|
+
* false. An orthographic view compares a level's error at a distance of 1, so the source's scale
|
|
21
|
+
* alone picks the level.
|
|
22
|
+
*/
|
|
23
|
+
readonly orthographic?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* The source's threshold bias, as Godot's `lod_bias`: above 1 switches every level nearer, so
|
|
26
|
+
* coarser levels draw, and below 1 keeps its detail. The default is 1.
|
|
27
|
+
*/
|
|
28
|
+
readonly bias?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* One of a mesh's lower levels and the measure that sets its switch: give exactly one. The fields
|
|
32
|
+
* have the meanings that `MeshLevel` gives them.
|
|
33
|
+
*
|
|
34
|
+
* @category api/geometry
|
|
35
|
+
*/
|
|
36
|
+
export type LevelSwitch = {
|
|
37
|
+
readonly error: number;
|
|
38
|
+
} | {
|
|
39
|
+
readonly distance: number;
|
|
40
|
+
} | {
|
|
41
|
+
readonly coverage: number;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* A source's world bounds about the camera: the centre of its bounding sphere relative to the
|
|
45
|
+
* camera, and the sphere's radius.
|
|
46
|
+
*
|
|
47
|
+
* @category api/geometry
|
|
48
|
+
*/
|
|
49
|
+
export interface LevelBounds {
|
|
50
|
+
/** The bounding sphere's centre, relative to the camera. */
|
|
51
|
+
readonly centre: readonly [number, number, number];
|
|
52
|
+
/** The bounding sphere's radius, in meters. */
|
|
53
|
+
readonly radius: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The two distances that the rule compares for a source's bounds. A level given by its error reads
|
|
57
|
+
* `error`, and a level given by a distance or by a coverage, a draw range and the rule that hides a
|
|
58
|
+
* small bound read `camera`.
|
|
59
|
+
*
|
|
60
|
+
* @category api/geometry
|
|
61
|
+
*/
|
|
62
|
+
export interface LevelDistances {
|
|
63
|
+
/** The distance to the nearest point of the bounds, which a distance or a coverage compares. */
|
|
64
|
+
readonly camera: number;
|
|
65
|
+
/** The distance at which an error is compared, which a level given by its error compares. */
|
|
66
|
+
readonly error: number;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The smallest distance that the rule measures, in meters: a camera inside the bounds reads it.
|
|
70
|
+
*
|
|
71
|
+
* @category api/geometry
|
|
72
|
+
*/
|
|
73
|
+
export declare const LEAST_LEVEL_DISTANCE = 0.001;
|
|
74
|
+
/**
|
|
75
|
+
* The distance at which one of a part's levels switches in.
|
|
76
|
+
*
|
|
77
|
+
* An error switches where it covers the view's threshold in pixels; a distance at its own figure,
|
|
78
|
+
* scaled by the source; and a coverage where the bounds' radius covers that share of the render
|
|
79
|
+
* height. A bias above 1 divides every result, so the level switches nearer.
|
|
80
|
+
*
|
|
81
|
+
* @param view The view that measures the level.
|
|
82
|
+
* @param level The level's switch measure.
|
|
83
|
+
* @param scale The largest axis scale of the source's world matrix.
|
|
84
|
+
* @param radius The radius of the source's world bounds, in meters, which a coverage reads.
|
|
85
|
+
* @returns The distance in meters at which the level draws, or `Infinity` for a coverage that is
|
|
86
|
+
* not above 0.
|
|
87
|
+
* @category api/geometry
|
|
88
|
+
*/
|
|
89
|
+
export declare function levelSwitchDistance(view: LevelView, level: LevelSwitch, scale: number, radius?: number): number;
|
|
90
|
+
/**
|
|
91
|
+
* Both distances that a view's rule compares for a source's bounds. An error measures to a point
|
|
92
|
+
* halfway into the sphere, capped at twice the distance to its nearest point, so a camera beside a
|
|
93
|
+
* large mesh measures the surface below it. A distance or a coverage, and a distance band, measure
|
|
94
|
+
* to the nearest point. Both are at least `LEAST_LEVEL_DISTANCE`. An orthographic view compares an
|
|
95
|
+
* error at a distance of 1, since its pixels do not shrink with distance, and keeps the nearest
|
|
96
|
+
* point for the other measures.
|
|
97
|
+
*
|
|
98
|
+
* @param view The view that measures the source.
|
|
99
|
+
* @param bounds The source's bounds, with the centre relative to the camera.
|
|
100
|
+
* @returns The two distances, in meters.
|
|
101
|
+
* @category api/geometry
|
|
102
|
+
*/
|
|
103
|
+
export declare function levelDistances(view: LevelView, bounds: LevelBounds): LevelDistances;
|
|
104
|
+
/**
|
|
105
|
+
* The level of detail that a source draws: 0 for the base mesh, 1 for the first lower level, and so
|
|
106
|
+
* on, as `setLevels` takes them. The level is the last one whose switch distance lies under the
|
|
107
|
+
* distance, which is how the core's culling picks every source. This gives the level alone, not
|
|
108
|
+
* whether the source draws at all: a bound that covers fewer pixels than the threshold is hidden,
|
|
109
|
+
* and a draw range hides a source outside it.
|
|
110
|
+
*
|
|
111
|
+
* @param view The view that measures the levels.
|
|
112
|
+
* @param levels The lower levels, from the finest to the coarsest.
|
|
113
|
+
* @param scale The largest axis scale of the source's world matrix.
|
|
114
|
+
* @param radius The radius of the source's world bounds, in meters, which a coverage reads.
|
|
115
|
+
* @param distance A distance, which both measures read as a camera does, or the two distances that
|
|
116
|
+
* `levelDistances` gives.
|
|
117
|
+
* @returns The level's index among the base mesh and `levels`.
|
|
118
|
+
* @category api/geometry
|
|
119
|
+
*/
|
|
120
|
+
export declare function levelAt(view: LevelView, levels: readonly LevelSwitch[], scale: number, radius: number, distance: number | LevelDistances): number;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// The engine's rule for a mesh's levels of detail, as a sketch reads it: the distance at which one
|
|
2
|
+
// of a part's levels switches in, the distances at which a view measures a part's bounds, and the
|
|
3
|
+
// level that a distance picks. The core picks the level of every source that a frame draws by this
|
|
4
|
+
// rule (`crates/null3d-core/src/levels.rs`), so a scene that budgets its triangles asks the same
|
|
5
|
+
// rule instead of copying it. A copy is a shadow of the core and drifts from it as soon as the
|
|
6
|
+
// core's figures change.
|
|
7
|
+
//
|
|
8
|
+
// A level's switch measure is its error, a hand-set distance, or the share of the render's height
|
|
9
|
+
// that the bounds cover. An error is the largest distance between the level's surface and the base
|
|
10
|
+
// mesh's, in the units of the base mesh's positions. The switch distance follows:
|
|
11
|
+
//
|
|
12
|
+
// ```text
|
|
13
|
+
// error: error × scale × factor / bias
|
|
14
|
+
// distance: distance × scale / bias
|
|
15
|
+
// coverage: radius × P[1][1] / (coverage × bias)
|
|
16
|
+
// ```
|
|
17
|
+
//
|
|
18
|
+
// `scale` is the largest axis scale of the source's world matrix and `factor` is the render height
|
|
19
|
+
// in pixels times the projection's `P[1][1]`, over twice the threshold in pixels. A level given by
|
|
20
|
+
// its error is compared with a distance halfway into the bounds, so a large mesh keeps its fine
|
|
21
|
+
// levels until its near side shows them; a level given by a distance or by a coverage, and a
|
|
22
|
+
// distance band, compare the distance to the bounds' nearest point.
|
|
23
|
+
/**
|
|
24
|
+
* The smallest distance that the rule measures, in meters: a camera inside the bounds reads it.
|
|
25
|
+
*
|
|
26
|
+
* @category api/geometry
|
|
27
|
+
*/
|
|
28
|
+
export const LEAST_LEVEL_DISTANCE = 1e-3;
|
|
29
|
+
/** The share of the bounds' radius that an error's distance takes off the distance to the centre. */
|
|
30
|
+
const ERROR_RADIUS_SHARE = 0.5;
|
|
31
|
+
/** The multiple of the distance to the nearest point that caps an error's distance. */
|
|
32
|
+
const ERROR_NEAREST_SHARE = 2;
|
|
33
|
+
/** The projection's `P[1][1]` for a perspective view of `fov` degrees, which a coverage reads. */
|
|
34
|
+
function projection(fov) {
|
|
35
|
+
return Math.abs(1 / Math.tan((fov * Math.PI) / 360));
|
|
36
|
+
}
|
|
37
|
+
/** The factor that turns a level's error into a switch distance: height × `P[1][1]` / (2 × threshold). */
|
|
38
|
+
function factor(view) {
|
|
39
|
+
const threshold = view.threshold ?? 1;
|
|
40
|
+
return threshold > 0 && view.height > 0
|
|
41
|
+
? (view.height * projection(view.fov)) / (2 * threshold)
|
|
42
|
+
: 0;
|
|
43
|
+
}
|
|
44
|
+
/** The source's threshold bias, and 1 for a bias that is not above 0. */
|
|
45
|
+
function bias(view) {
|
|
46
|
+
const value = view.bias ?? 1;
|
|
47
|
+
return value > 0 ? value : 1;
|
|
48
|
+
}
|
|
49
|
+
/** The distance at which a level switches in, given the view's factor and bias. */
|
|
50
|
+
function switchDistance(view, levelFactor, level, scale, radius) {
|
|
51
|
+
if ('error' in level)
|
|
52
|
+
return (level.error * scale * levelFactor) / bias(view);
|
|
53
|
+
if ('distance' in level)
|
|
54
|
+
return (level.distance * scale) / bias(view);
|
|
55
|
+
const p11 = projection(view.fov);
|
|
56
|
+
return level.coverage > 0 && p11 > 0
|
|
57
|
+
? (radius * p11) / (level.coverage * bias(view))
|
|
58
|
+
: Number.POSITIVE_INFINITY;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The distance at which one of a part's levels switches in.
|
|
62
|
+
*
|
|
63
|
+
* An error switches where it covers the view's threshold in pixels; a distance at its own figure,
|
|
64
|
+
* scaled by the source; and a coverage where the bounds' radius covers that share of the render
|
|
65
|
+
* height. A bias above 1 divides every result, so the level switches nearer.
|
|
66
|
+
*
|
|
67
|
+
* @param view The view that measures the level.
|
|
68
|
+
* @param level The level's switch measure.
|
|
69
|
+
* @param scale The largest axis scale of the source's world matrix.
|
|
70
|
+
* @param radius The radius of the source's world bounds, in meters, which a coverage reads.
|
|
71
|
+
* @returns The distance in meters at which the level draws, or `Infinity` for a coverage that is
|
|
72
|
+
* not above 0.
|
|
73
|
+
* @category api/geometry
|
|
74
|
+
*/
|
|
75
|
+
export function levelSwitchDistance(view, level, scale, radius = 0) {
|
|
76
|
+
return switchDistance(view, factor(view), level, scale, radius);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Both distances that a view's rule compares for a source's bounds. An error measures to a point
|
|
80
|
+
* halfway into the sphere, capped at twice the distance to its nearest point, so a camera beside a
|
|
81
|
+
* large mesh measures the surface below it. A distance or a coverage, and a distance band, measure
|
|
82
|
+
* to the nearest point. Both are at least `LEAST_LEVEL_DISTANCE`. An orthographic view compares an
|
|
83
|
+
* error at a distance of 1, since its pixels do not shrink with distance, and keeps the nearest
|
|
84
|
+
* point for the other measures.
|
|
85
|
+
*
|
|
86
|
+
* @param view The view that measures the source.
|
|
87
|
+
* @param bounds The source's bounds, with the centre relative to the camera.
|
|
88
|
+
* @returns The two distances, in meters.
|
|
89
|
+
* @category api/geometry
|
|
90
|
+
*/
|
|
91
|
+
export function levelDistances(view, bounds) {
|
|
92
|
+
const [x, y, z] = bounds.centre;
|
|
93
|
+
const length = Math.hypot(x, y, z);
|
|
94
|
+
const nearest = (radius) => Math.max(length - radius, LEAST_LEVEL_DISTANCE);
|
|
95
|
+
const camera = nearest(bounds.radius);
|
|
96
|
+
const error = view.orthographic
|
|
97
|
+
? 1
|
|
98
|
+
: Math.min(nearest(ERROR_RADIUS_SHARE * bounds.radius), ERROR_NEAREST_SHARE * nearest(bounds.radius));
|
|
99
|
+
return { camera, error };
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The level of detail that a source draws: 0 for the base mesh, 1 for the first lower level, and so
|
|
103
|
+
* on, as `setLevels` takes them. The level is the last one whose switch distance lies under the
|
|
104
|
+
* distance, which is how the core's culling picks every source. This gives the level alone, not
|
|
105
|
+
* whether the source draws at all: a bound that covers fewer pixels than the threshold is hidden,
|
|
106
|
+
* and a draw range hides a source outside it.
|
|
107
|
+
*
|
|
108
|
+
* @param view The view that measures the levels.
|
|
109
|
+
* @param levels The lower levels, from the finest to the coarsest.
|
|
110
|
+
* @param scale The largest axis scale of the source's world matrix.
|
|
111
|
+
* @param radius The radius of the source's world bounds, in meters, which a coverage reads.
|
|
112
|
+
* @param distance A distance, which both measures read as a camera does, or the two distances that
|
|
113
|
+
* `levelDistances` gives.
|
|
114
|
+
* @returns The level's index among the base mesh and `levels`.
|
|
115
|
+
* @category api/geometry
|
|
116
|
+
*/
|
|
117
|
+
export function levelAt(view, levels, scale, radius, distance) {
|
|
118
|
+
const levelFactor = factor(view);
|
|
119
|
+
if (!(levelFactor > 0) || levels.length === 0)
|
|
120
|
+
return 0;
|
|
121
|
+
const at = typeof distance === 'number' ? { camera: distance, error: distance } : distance;
|
|
122
|
+
let level = 0;
|
|
123
|
+
for (const measure of levels) {
|
|
124
|
+
const compare = 'error' in measure ? at.error : at.camera;
|
|
125
|
+
if (!(switchDistance(view, levelFactor, measure, scale, radius) < compare))
|
|
126
|
+
break;
|
|
127
|
+
level++;
|
|
128
|
+
}
|
|
129
|
+
return level;
|
|
130
|
+
}
|
package/lib/scene/lines.d.ts
CHANGED
|
@@ -3,17 +3,16 @@ import type { ObjectEventHandler, ObjectEventType, PointerRows } from './pointer
|
|
|
3
3
|
import type { Blending, Geometry, MaterialFeatures, MaterialOptions, Materials, MeshGeometry, StandardValues } from './resources.js';
|
|
4
4
|
import type { Vec3 } from './scene.js';
|
|
5
5
|
/**
|
|
6
|
-
* Which points each segment joins. With `segments`, each pair of points makes a segment
|
|
7
|
-
*
|
|
8
|
-
* `loop`, the last point also joins the first, like `LineLoop`.
|
|
6
|
+
* Which points each segment joins. With `segments`, each pair of points makes a segment. With
|
|
7
|
+
* `strip`, every point joins the next. With `loop`, the last point also joins the first.
|
|
9
8
|
*
|
|
10
9
|
* @category api/lines
|
|
11
10
|
*/
|
|
12
11
|
export type LineMode = 'segments' | 'strip' | 'loop';
|
|
13
12
|
/**
|
|
14
13
|
* The values of a line batch's material, which `lines.material.set` changes at any time. The dash
|
|
15
|
-
* values act on dashed lines,
|
|
16
|
-
*
|
|
14
|
+
* values act on dashed lines. The metalness, roughness and emissive values act on lit lines, as a
|
|
15
|
+
* standard material takes them.
|
|
17
16
|
*
|
|
18
17
|
* @category api/lines
|
|
19
18
|
*/
|
|
@@ -51,22 +50,19 @@ export interface LineOptions extends LineValues, Pick<MaterialFeatures, 'fog' |
|
|
|
51
50
|
colors?: ArrayLike<number>;
|
|
52
51
|
/** Which points each segment joins. The default is `strip`. */
|
|
53
52
|
mode?: LineMode;
|
|
54
|
-
/**
|
|
55
|
-
* The width of the lines: CSS pixels, or world units with `worldUnits`. The default is 1, as
|
|
56
|
-
* three.js's `linewidth`.
|
|
57
|
-
*/
|
|
53
|
+
/** The width of the lines: CSS pixels, or world units with `worldUnits`. The default is 1. */
|
|
58
54
|
width?: number;
|
|
59
55
|
/**
|
|
60
|
-
* True gives the width in world units, so far lines look thinner
|
|
61
|
-
*
|
|
56
|
+
* True gives the width in world units, so far lines look thinner. False gives it in CSS pixels,
|
|
57
|
+
* so every line keeps its width on screen. The default is false.
|
|
62
58
|
*/
|
|
63
59
|
worldUnits?: boolean;
|
|
64
60
|
/** Draws the lines as dashes, which `dashSize`, `gapSize` and the other dash values shape. */
|
|
65
61
|
dashed?: boolean;
|
|
66
62
|
/**
|
|
67
63
|
* Lights the lines as a standard material lights a surface that faces the camera: the sun, the
|
|
68
|
-
* point and spot lights and the ambient light shade them. False draws the color as it is,
|
|
69
|
-
*
|
|
64
|
+
* point and spot lights and the ambient light shade them. False draws the color as it is,
|
|
65
|
+
* whatever the lights. The default is false.
|
|
70
66
|
*/
|
|
71
67
|
lit?: boolean;
|
|
72
68
|
/** Every point updates and uploads every frame; a static batch updates points marked dirty only. */
|
|
@@ -79,7 +75,7 @@ export interface LineOptions extends LineValues, Pick<MaterialFeatures, 'fog' |
|
|
|
79
75
|
* the world's origin.
|
|
80
76
|
*/
|
|
81
77
|
origin?: Vec3;
|
|
82
|
-
/** How the lines use their opacity. The default is `opaque
|
|
78
|
+
/** How the lines use their opacity. The default is `opaque`. */
|
|
83
79
|
alphaMode?: 'opaque' | 'blend';
|
|
84
80
|
}
|
|
85
81
|
/** What a line batch's segment mesh and material are made with: the engine's objects. */
|
|
@@ -134,9 +130,9 @@ export interface LineBatchRows extends PointerRows {
|
|
|
134
130
|
}
|
|
135
131
|
/**
|
|
136
132
|
* Lines of any width: segments between points, each drawn as a quad with round ends that faces the
|
|
137
|
-
* camera
|
|
138
|
-
*
|
|
139
|
-
*
|
|
133
|
+
* camera. Write points straight into the typed arrays, as for an instance batch. A dynamic batch
|
|
134
|
+
* updates every segment every frame, and a static batch updates the segments of the points you
|
|
135
|
+
* mark dirty.
|
|
140
136
|
*
|
|
141
137
|
* @category api/lines
|
|
142
138
|
*/
|
package/lib/scene/lines.js
CHANGED
|
@@ -136,9 +136,9 @@ export function lineParts({ geometry, materials }, core, mesh, options, checks,
|
|
|
136
136
|
const NO_POINTS = { positions: new Float32Array(0), colors: new Float32Array(0) };
|
|
137
137
|
/**
|
|
138
138
|
* Lines of any width: segments between points, each drawn as a quad with round ends that faces the
|
|
139
|
-
* camera
|
|
140
|
-
*
|
|
141
|
-
*
|
|
139
|
+
* camera. Write points straight into the typed arrays, as for an instance batch. A dynamic batch
|
|
140
|
+
* updates every segment every frame, and a static batch updates the segments of the points you
|
|
141
|
+
* mark dirty.
|
|
142
142
|
*
|
|
143
143
|
* @category api/lines
|
|
144
144
|
*/
|
package/lib/scene/lut.d.ts
CHANGED
|
@@ -30,8 +30,7 @@ export interface LutData {
|
|
|
30
30
|
/**
|
|
31
31
|
* A color grading table, which `assets.loadLut` loads from a file and `assets.lutFromData` makes
|
|
32
32
|
* from numbers. It is a 3D texture that maps each color of the picture to its graded color. Give
|
|
33
|
-
* it to `post.set({ lut })`, which applies it to every pixel after the tone mapping
|
|
34
|
-
* `LUTPass` does.
|
|
33
|
+
* it to `post.set({ lut })`, which applies it to every pixel after the tone mapping.
|
|
35
34
|
*
|
|
36
35
|
* @category api/assets
|
|
37
36
|
*/
|