@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
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
// The development build's inspection channel: the calls that the in-page inspector and the MCP
|
|
2
|
+
// server make through the page into the sketch worker. Each call reads or changes the running scene,
|
|
3
|
+
// returns a JSON-safe value, and runs between frames. A release build holds none of it: the sketch
|
|
4
|
+
// worker and the page start the channel only under the development flag.
|
|
5
|
+
//
|
|
6
|
+
// The scene's objects are named by their slot, `#<slot>`, or by their name, which `scene.find` takes.
|
|
7
|
+
// A change is applied at once with the scene's setters, which queue their commands for the next
|
|
8
|
+
// frame; the answer describes the object as the calls left it.
|
|
9
|
+
import { EngineError } from '../errors/engine-error.js';
|
|
10
|
+
import * as C from '../generated/core.js';
|
|
11
|
+
import { AmbientLight, Camera, DirectionalLight, Group, HemisphereLight, Light, Mesh, OrthographicCamera, PerspectiveCamera, PointLight, PrefabInstance, RectAreaLight, SpotLight, TubeLight, } from '../scene/scene.js';
|
|
12
|
+
/** The most errors that the channel keeps. */
|
|
13
|
+
const MAX_ERRORS = 50;
|
|
14
|
+
/** The largest number of objects that one listing returns, unless a call asks for fewer. */
|
|
15
|
+
const MAX_LISTED = 50_000;
|
|
16
|
+
/** The kind of an object, as the inspector names it. */
|
|
17
|
+
function kindOf(object) {
|
|
18
|
+
if (object instanceof PerspectiveCamera ||
|
|
19
|
+
object instanceof OrthographicCamera ||
|
|
20
|
+
object instanceof Camera)
|
|
21
|
+
return 'camera';
|
|
22
|
+
if (object instanceof SpotLight)
|
|
23
|
+
return 'spot-light';
|
|
24
|
+
if (object instanceof PointLight)
|
|
25
|
+
return 'point-light';
|
|
26
|
+
if (object instanceof DirectionalLight)
|
|
27
|
+
return 'directional-light';
|
|
28
|
+
if (object instanceof HemisphereLight)
|
|
29
|
+
return 'hemisphere-light';
|
|
30
|
+
if (object instanceof AmbientLight)
|
|
31
|
+
return 'ambient-light';
|
|
32
|
+
if (object instanceof RectAreaLight)
|
|
33
|
+
return 'rect-area-light';
|
|
34
|
+
if (object instanceof TubeLight)
|
|
35
|
+
return 'tube-light';
|
|
36
|
+
if (object instanceof Light)
|
|
37
|
+
return 'light';
|
|
38
|
+
if (object instanceof PrefabInstance)
|
|
39
|
+
return 'prefab';
|
|
40
|
+
if (object instanceof Group)
|
|
41
|
+
return 'group';
|
|
42
|
+
if (object instanceof Mesh)
|
|
43
|
+
return 'mesh';
|
|
44
|
+
return 'object';
|
|
45
|
+
}
|
|
46
|
+
/** Throws E1213 for a value that is not a record. */
|
|
47
|
+
function recordOf(value, what) {
|
|
48
|
+
if (value !== null && typeof value === 'object' && !Array.isArray(value))
|
|
49
|
+
return value;
|
|
50
|
+
throw new EngineError('E1213', `The inspector got ${String(value)} for ${what}, which is not an object.`);
|
|
51
|
+
}
|
|
52
|
+
/** Reads `count` finite numbers from `value`, or throws E1213. */
|
|
53
|
+
function numbersOf(value, count, what) {
|
|
54
|
+
if (!Array.isArray(value) || value.length !== count)
|
|
55
|
+
throw new EngineError('E1213', `The inspector got ${JSON.stringify(value)} for ${what}, which takes ${count} numbers.`);
|
|
56
|
+
for (const one of value)
|
|
57
|
+
if (!Number.isFinite(one))
|
|
58
|
+
throw new EngineError('E1203', `The inspector got ${String(one)} in ${what}. Pass a finite number.`);
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
/** The development build's inspection channel. */
|
|
62
|
+
export class DebugChannel {
|
|
63
|
+
host;
|
|
64
|
+
errors = [];
|
|
65
|
+
constructor(host) {
|
|
66
|
+
this.host = host;
|
|
67
|
+
}
|
|
68
|
+
/** Records an error that the runner reported, for the `errors` call. */
|
|
69
|
+
recordError(message) {
|
|
70
|
+
this.errors.push(message);
|
|
71
|
+
if (this.errors.length > MAX_ERRORS)
|
|
72
|
+
this.errors.shift();
|
|
73
|
+
}
|
|
74
|
+
/** Runs one inspection call and returns its JSON-safe value, or throws for a bad call. */
|
|
75
|
+
async inspect(call, args) {
|
|
76
|
+
switch (call) {
|
|
77
|
+
case 'objects':
|
|
78
|
+
return this.objects(args);
|
|
79
|
+
case 'object':
|
|
80
|
+
return this.detail(this.find(args));
|
|
81
|
+
case 'setObject':
|
|
82
|
+
return this.setObject(args);
|
|
83
|
+
case 'setMaterial':
|
|
84
|
+
return this.setMaterial(args);
|
|
85
|
+
case 'stats':
|
|
86
|
+
return await this.stats();
|
|
87
|
+
case 'errors':
|
|
88
|
+
return { errors: [...this.errors], count: this.errors.length };
|
|
89
|
+
case 'graph':
|
|
90
|
+
return { graph: this.host.render.dumpGraph() };
|
|
91
|
+
case 'setQuality':
|
|
92
|
+
return await this.setQuality(args);
|
|
93
|
+
case 'highlight':
|
|
94
|
+
return this.highlight(args);
|
|
95
|
+
case 'info':
|
|
96
|
+
return this.host.info();
|
|
97
|
+
default:
|
|
98
|
+
throw new EngineError('E1213', `The inspector has no "${call}" call. Its calls: objects, object, setObject, setMaterial, stats, errors, graph, setQuality, highlight and info.`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async stats() {
|
|
102
|
+
const deadline = performance.now() + 2000;
|
|
103
|
+
for (;;) {
|
|
104
|
+
const stats = this.host.debug.frameStats();
|
|
105
|
+
if (stats.frames > 0 || performance.now() >= deadline)
|
|
106
|
+
return stats;
|
|
107
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/** Lists every live object, or the objects whose name or kind holds `filter`. */
|
|
111
|
+
objects(args) {
|
|
112
|
+
const options = args === undefined || args === null ? {} : recordOf(args, 'a listing');
|
|
113
|
+
const filter = typeof options.filter === 'string' && options.filter.trim() !== ''
|
|
114
|
+
? options.filter.trim().toLowerCase()
|
|
115
|
+
: undefined;
|
|
116
|
+
const limit = typeof options.limit === 'number' && Number.isInteger(options.limit) && options.limit > 0
|
|
117
|
+
? Math.min(options.limit, MAX_LISTED)
|
|
118
|
+
: MAX_LISTED;
|
|
119
|
+
const objects = [];
|
|
120
|
+
let count = 0;
|
|
121
|
+
for (const object of this.host.scene.listObjects()) {
|
|
122
|
+
const summary = this.summary(object);
|
|
123
|
+
if (filter !== undefined && !`${summary.name} ${summary.kind}`.toLowerCase().includes(filter))
|
|
124
|
+
continue;
|
|
125
|
+
count++;
|
|
126
|
+
if (objects.length < limit)
|
|
127
|
+
objects.push(summary);
|
|
128
|
+
}
|
|
129
|
+
return { objects, count, truncated: count > objects.length };
|
|
130
|
+
}
|
|
131
|
+
/** The object that a call's `selector` names. */
|
|
132
|
+
find(args) {
|
|
133
|
+
const options = recordOf(args, 'a call');
|
|
134
|
+
const selector = options.selector ?? options.object;
|
|
135
|
+
const object = this.resolve(selector);
|
|
136
|
+
if (object !== undefined)
|
|
137
|
+
return object;
|
|
138
|
+
const shown = typeof selector === 'string' ? `"${selector}"` : String(selector);
|
|
139
|
+
const near = typeof selector === 'string' ? this.host.scene.nearNames(selector.replace(/^#/, '')) : [];
|
|
140
|
+
const hint = near.length > 0
|
|
141
|
+
? ` Names that are close: ${near.map((name) => `"${name}"`).join(', ')}.`
|
|
142
|
+
: '';
|
|
143
|
+
throw new EngineError('E1213', `The inspector found no live object for ${shown}. Name an object, give its slot as "#<slot>", or use #camera.${hint}`);
|
|
144
|
+
}
|
|
145
|
+
/** The live object that `selector` names, or undefined. */
|
|
146
|
+
resolve(selector) {
|
|
147
|
+
const { scene } = this.host;
|
|
148
|
+
if (typeof selector === 'number' && Number.isInteger(selector) && selector > 0)
|
|
149
|
+
return scene.objectAt(selector);
|
|
150
|
+
if (typeof selector !== 'string')
|
|
151
|
+
return undefined;
|
|
152
|
+
if (selector === '#camera')
|
|
153
|
+
return scene.shownCamera;
|
|
154
|
+
if (selector.startsWith('#')) {
|
|
155
|
+
const slot = Number(selector.slice(1));
|
|
156
|
+
return Number.isInteger(slot) && slot > 0 ? scene.objectAt(slot) : undefined;
|
|
157
|
+
}
|
|
158
|
+
return scene.find(selector);
|
|
159
|
+
}
|
|
160
|
+
/** A listing's view of one object. */
|
|
161
|
+
summary(object) {
|
|
162
|
+
const mesh = object instanceof Mesh ? object : undefined;
|
|
163
|
+
const material = mesh?.material;
|
|
164
|
+
return {
|
|
165
|
+
slot: object.slot,
|
|
166
|
+
handle: object.handle,
|
|
167
|
+
name: object.name,
|
|
168
|
+
kind: kindOf(object),
|
|
169
|
+
dynamic: (object.flags & C.FLAG_DYNAMIC) !== 0,
|
|
170
|
+
visible: (object.flags & C.FLAG_VISIBLE) !== 0,
|
|
171
|
+
layers: object.layerMask,
|
|
172
|
+
parent: object.liveParent?.slot ?? null,
|
|
173
|
+
children: object.childObjects?.size ?? 0,
|
|
174
|
+
...(material?.live ? { material: material.id } : {}),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
/** One object's transform, parent and material. */
|
|
178
|
+
detail(object) {
|
|
179
|
+
const position = [0, 0, 0];
|
|
180
|
+
const rotation = [0, 0, 0, 1];
|
|
181
|
+
const scale = [1, 1, 1];
|
|
182
|
+
const worldPosition = [0, 0, 0];
|
|
183
|
+
object.getPosition(position);
|
|
184
|
+
object.getRotation(rotation);
|
|
185
|
+
this.host.scene.readScale(object.row, scale);
|
|
186
|
+
object.getWorldPosition(worldPosition);
|
|
187
|
+
const mesh = object instanceof Mesh ? object : undefined;
|
|
188
|
+
const material = mesh?.material;
|
|
189
|
+
return {
|
|
190
|
+
...this.summary(object),
|
|
191
|
+
position,
|
|
192
|
+
rotation,
|
|
193
|
+
scale,
|
|
194
|
+
worldPosition,
|
|
195
|
+
...(material?.live
|
|
196
|
+
? { materialValues: { ...material.values() }, shading: material.shading }
|
|
197
|
+
: {}),
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
/** Changes an object's transform, flags or layers and returns its new state. */
|
|
201
|
+
setObject(args) {
|
|
202
|
+
const options = recordOf(args, 'a change');
|
|
203
|
+
const object = this.find(options);
|
|
204
|
+
if (options.position !== undefined) {
|
|
205
|
+
const [x, y, z] = numbersOf(options.position, 3, 'position');
|
|
206
|
+
object.setPosition(x, y, z);
|
|
207
|
+
}
|
|
208
|
+
if (options.rotation !== undefined) {
|
|
209
|
+
const [x, y, z, w] = numbersOf(options.rotation, 4, 'rotation');
|
|
210
|
+
object.setRotation(x, y, z, w);
|
|
211
|
+
}
|
|
212
|
+
if (options.rotationEuler !== undefined) {
|
|
213
|
+
const [x, y, z] = numbersOf(options.rotationEuler, 3, 'rotationEuler');
|
|
214
|
+
object.setRotationEuler(x, y, z);
|
|
215
|
+
}
|
|
216
|
+
if (options.scale !== undefined) {
|
|
217
|
+
const [x, y, z] = numbersOf(options.scale, 3, 'scale');
|
|
218
|
+
object.setScale(x, y, z);
|
|
219
|
+
}
|
|
220
|
+
if (options.visible !== undefined) {
|
|
221
|
+
if (typeof options.visible !== 'boolean')
|
|
222
|
+
throw new EngineError('E1213', `The inspector got ${String(options.visible)} for visible, which takes true or false.`);
|
|
223
|
+
object.setVisible(options.visible);
|
|
224
|
+
}
|
|
225
|
+
if (options.dynamic !== undefined) {
|
|
226
|
+
if (typeof options.dynamic !== 'boolean')
|
|
227
|
+
throw new EngineError('E1213', `The inspector got ${String(options.dynamic)} for dynamic, which takes true or false.`);
|
|
228
|
+
object.setDynamic(options.dynamic);
|
|
229
|
+
}
|
|
230
|
+
if (options.layers !== undefined) {
|
|
231
|
+
if (typeof options.layers !== 'number' || !Number.isInteger(options.layers))
|
|
232
|
+
throw new EngineError('E1213', `The inspector got ${String(options.layers)} for layers, which takes a 32-bit mask.`);
|
|
233
|
+
object.setLayers(options.layers);
|
|
234
|
+
}
|
|
235
|
+
return this.detail(object);
|
|
236
|
+
}
|
|
237
|
+
/** Changes the material of the mesh that `selector` names and returns the object's new state. */
|
|
238
|
+
setMaterial(args) {
|
|
239
|
+
const options = recordOf(args, 'a material change');
|
|
240
|
+
const object = this.find(options);
|
|
241
|
+
if (!(object instanceof Mesh) || object.material === undefined)
|
|
242
|
+
throw new EngineError('E1213', `The inspector got ${object.describe()}, which draws no material. Give a mesh.`);
|
|
243
|
+
const values = recordOf(options.values, 'material values');
|
|
244
|
+
object.material.set(values);
|
|
245
|
+
return this.detail(object);
|
|
246
|
+
}
|
|
247
|
+
/** Applies a quality preset or settings and returns the engine's new quality. */
|
|
248
|
+
async setQuality(args) {
|
|
249
|
+
const options = recordOf(args, 'a quality change');
|
|
250
|
+
const { quality } = this.host;
|
|
251
|
+
if (typeof options.preset === 'string') {
|
|
252
|
+
await quality.setPreset(options.preset);
|
|
253
|
+
}
|
|
254
|
+
if (options.settings !== undefined) {
|
|
255
|
+
await quality.set(recordOf(options.settings, 'quality settings'));
|
|
256
|
+
}
|
|
257
|
+
return { preset: quality.preset, settings: { ...quality.settings } };
|
|
258
|
+
}
|
|
259
|
+
/** Outlines the object that `selector` names, or clears the outline without one. */
|
|
260
|
+
highlight(args) {
|
|
261
|
+
const options = args === undefined || args === null ? {} : recordOf(args, 'a selection');
|
|
262
|
+
const selector = options.selector ?? options.object;
|
|
263
|
+
const object = selector === undefined ? undefined : this.resolve(selector);
|
|
264
|
+
if (selector !== undefined && object === undefined)
|
|
265
|
+
throw new EngineError('E1213', `The inspector found no live object for ${JSON.stringify(selector)}.`);
|
|
266
|
+
this.host.debugDraw?.highlight(object);
|
|
267
|
+
return { selected: object === undefined ? null : this.summary(object) };
|
|
268
|
+
}
|
|
269
|
+
}
|
package/lib/debug/debug.d.ts
CHANGED
|
@@ -12,9 +12,12 @@ import type { EngineDebugView } from './view-names.js';
|
|
|
12
12
|
export interface DebugGridOptions {
|
|
13
13
|
/** The center of the grid. The default is the origin. */
|
|
14
14
|
center?: Vec3Like;
|
|
15
|
-
/** The color of the grid's lines. The default is `'#888888'
|
|
15
|
+
/** The color of the grid's lines. The default is gray, `'#888888'`. */
|
|
16
16
|
color?: ColorInput;
|
|
17
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* The color of the two lines through the center, which an even number of divisions draws. The
|
|
19
|
+
* default is `'#444444'`.
|
|
20
|
+
*/
|
|
18
21
|
centerColor?: ColorInput;
|
|
19
22
|
}
|
|
20
23
|
/**
|
|
@@ -153,13 +156,13 @@ export interface Debug {
|
|
|
153
156
|
axes(target: Object3D | Vec3Like, size?: number): void;
|
|
154
157
|
/**
|
|
155
158
|
* Draws a square grid on the horizontal plane through its center, `size` meters wide, with
|
|
156
|
-
* `divisions` cells along each side
|
|
159
|
+
* `divisions` cells along each side. The defaults are 10 and 10.
|
|
157
160
|
*/
|
|
158
161
|
grid(size?: number, divisions?: number, options?: DebugGridOptions): void;
|
|
159
162
|
/**
|
|
160
163
|
* Draws the space that a camera sees: its near and far planes and the edges between them, in the
|
|
161
164
|
* canvas's shape. The camera takes its place in the frame it draws in. The default color is
|
|
162
|
-
* orange
|
|
165
|
+
* orange.
|
|
163
166
|
*/
|
|
164
167
|
frustum(camera: Camera, color?: ColorInput): void;
|
|
165
168
|
/**
|
|
@@ -170,9 +173,8 @@ export interface Debug {
|
|
|
170
173
|
/**
|
|
171
174
|
* Draws the skeleton that animates an object, such as the copy of a model that
|
|
172
175
|
* `scene.instantiate` made: a line from each joint of the model's skins to its parent joint, in
|
|
173
|
-
* the pose of the frame it draws in.
|
|
174
|
-
*
|
|
175
|
-
* draws nothing.
|
|
176
|
+
* the pose of the frame it draws in. Each line is blue at the joint and green at its parent,
|
|
177
|
+
* unless `color` gives one color. An object without an animator draws nothing.
|
|
176
178
|
*/
|
|
177
179
|
skeleton(object: Object3D, color?: ColorInput): void;
|
|
178
180
|
}
|
package/lib/debug/draw.d.ts
CHANGED
|
@@ -50,6 +50,8 @@ export declare class DebugDraw extends SketchDebug implements ViewHolder {
|
|
|
50
50
|
private readonly sides;
|
|
51
51
|
/** True while the culling spheres of the meshes with levels draw. */
|
|
52
52
|
private cullingSpheresWanted;
|
|
53
|
+
/** The object that the inspector selected, which each frame outlines. */
|
|
54
|
+
private highlighted;
|
|
53
55
|
/** The direction a drawn light's light travels. */
|
|
54
56
|
private readonly direction;
|
|
55
57
|
constructor(core: CoreMemory, host: DebugHost, scene: Scene);
|
|
@@ -65,6 +67,8 @@ export declare class DebugDraw extends SketchDebug implements ViewHolder {
|
|
|
65
67
|
private applyView;
|
|
66
68
|
shadowCamera(camera?: Camera): void;
|
|
67
69
|
cullingSpheres(show?: boolean): void;
|
|
70
|
+
/** Outlines `object` in each frame until another call changes it, or clears it with undefined. */
|
|
71
|
+
highlight(object: Object3D | undefined): void;
|
|
68
72
|
cullingSpheresDrawn(): number;
|
|
69
73
|
line(from: Vec3Like, to: Vec3Like, color?: ColorInput): void;
|
|
70
74
|
box(min: Vec3Like, max: Vec3Like, color?: ColorInput): void;
|
|
@@ -93,6 +97,11 @@ export declare class DebugDraw extends SketchDebug implements ViewHolder {
|
|
|
93
97
|
private drawCullingSpheres;
|
|
94
98
|
/** Draws the culling sphere of one object whose mesh has levels, or passes the limit. */
|
|
95
99
|
private drawCullingSphere;
|
|
100
|
+
/**
|
|
101
|
+
* Outlines the object that the inspector selected: its bounding sphere when it draws a mesh,
|
|
102
|
+
* or a small box at its place otherwise.
|
|
103
|
+
*/
|
|
104
|
+
private drawHighlight;
|
|
96
105
|
/**
|
|
97
106
|
* The skeleton of the animated object whose world matrix the flush just read: a line from each
|
|
98
107
|
* joint of its skins to its parent joint, where the last animation step posed them.
|
package/lib/debug/draw.js
CHANGED
|
@@ -17,7 +17,7 @@ import { linearToSrgb } from '../math/color.js';
|
|
|
17
17
|
import { hexValue, invalidColor } from '../math/hex.js';
|
|
18
18
|
import { activateAddonDebugView, hasAddonDebugView } from '../scene/addon-debug-views.js';
|
|
19
19
|
import { isComponent } from '../scene/color.js';
|
|
20
|
-
import { Object3D, } from '../scene/scene.js';
|
|
20
|
+
import { Mesh, Object3D, } from '../scene/scene.js';
|
|
21
21
|
import { SketchDebug } from './sketch-debug.js';
|
|
22
22
|
/** The points that the arrays first make room for: 2,048 lines. */
|
|
23
23
|
const FIRST_POINTS = 4096;
|
|
@@ -48,6 +48,8 @@ const SKELETON = 4;
|
|
|
48
48
|
const MAX_CULL_SPHERES = 128;
|
|
49
49
|
/** The color of a culling sphere. */
|
|
50
50
|
const CULL_SPHERE_COLOR = 0xffffff;
|
|
51
|
+
/** The color that outlines the object that the inspector selected, as an sRGB hex color. */
|
|
52
|
+
const HIGHLIGHT_COLOR = 0x00ffff;
|
|
51
53
|
/** The color of a skeleton line's joint end and parent end: blue and green, as three.js's. */
|
|
52
54
|
const JOINT_BLUE = 0xffff0000;
|
|
53
55
|
const PARENT_GREEN = 0xff00ff00;
|
|
@@ -147,6 +149,8 @@ export class DebugDraw extends SketchDebug {
|
|
|
147
149
|
sides = new Float64Array(6);
|
|
148
150
|
/** True while the culling spheres of the meshes with levels draw. */
|
|
149
151
|
cullingSpheresWanted = false;
|
|
152
|
+
/** The object that the inspector selected, which each frame outlines. */
|
|
153
|
+
highlighted;
|
|
150
154
|
/** The direction a drawn light's light travels. */
|
|
151
155
|
direction = new Float64Array(3);
|
|
152
156
|
constructor(core, host, scene) {
|
|
@@ -203,6 +207,10 @@ export class DebugDraw extends SketchDebug {
|
|
|
203
207
|
if (!show)
|
|
204
208
|
this.spheresDrawn = 0;
|
|
205
209
|
}
|
|
210
|
+
/** Outlines `object` in each frame until another call changes it, or clears it with undefined. */
|
|
211
|
+
highlight(object) {
|
|
212
|
+
this.highlighted = object;
|
|
213
|
+
}
|
|
206
214
|
cullingSpheresDrawn() {
|
|
207
215
|
return this.spheresDrawn;
|
|
208
216
|
}
|
|
@@ -317,7 +325,11 @@ export class DebugDraw extends SketchDebug {
|
|
|
317
325
|
* any update, so they draw only the lines written since the frame before.
|
|
318
326
|
*/
|
|
319
327
|
flush(width, height, update = true) {
|
|
320
|
-
if (!update &&
|
|
328
|
+
if (!update &&
|
|
329
|
+
this.updated > 0 &&
|
|
330
|
+
this.points === 0 &&
|
|
331
|
+
this.followedCount === 0 &&
|
|
332
|
+
this.highlighted === undefined) {
|
|
321
333
|
this.core.check(this.core.glue.drawDebugLines(this.updated), 'debug drawing', undefined, true);
|
|
322
334
|
return;
|
|
323
335
|
}
|
|
@@ -343,6 +355,7 @@ export class DebugDraw extends SketchDebug {
|
|
|
343
355
|
this.followedCount = 0;
|
|
344
356
|
if (this.cullingSpheresWanted)
|
|
345
357
|
this.drawCullingSpheres();
|
|
358
|
+
this.drawHighlight();
|
|
346
359
|
const points = this.points;
|
|
347
360
|
// Lines written outside an update overwrite the last update's, so none stay to draw again.
|
|
348
361
|
this.updated = update ? points : 0;
|
|
@@ -390,6 +403,40 @@ export class DebugDraw extends SketchDebug {
|
|
|
390
403
|
this.spheresDrawn += 1;
|
|
391
404
|
return true;
|
|
392
405
|
}
|
|
406
|
+
/**
|
|
407
|
+
* Outlines the object that the inspector selected: its bounding sphere when it draws a mesh,
|
|
408
|
+
* or a small box at its place otherwise.
|
|
409
|
+
*/
|
|
410
|
+
drawHighlight() {
|
|
411
|
+
const object = this.highlighted;
|
|
412
|
+
if (object === undefined)
|
|
413
|
+
return;
|
|
414
|
+
if (object.destroyedFrame !== -1) {
|
|
415
|
+
this.highlighted = undefined;
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
if (this.core.readWorldMatrix(object.handle, this.matrix) !== 0)
|
|
419
|
+
return;
|
|
420
|
+
const m = this.matrix;
|
|
421
|
+
if (object instanceof Mesh && object.mesh !== undefined) {
|
|
422
|
+
const scale = Math.max(Math.hypot(m[0], m[4], m[8]), Math.hypot(m[1], m[5], m[9]), Math.hypot(m[2], m[6], m[10]));
|
|
423
|
+
const center = this.sphereCenter;
|
|
424
|
+
const [cx, cy, cz] = object.mesh.center;
|
|
425
|
+
for (let r = 0; r < 3; r++)
|
|
426
|
+
center[r] =
|
|
427
|
+
m[r * 4] * cx +
|
|
428
|
+
m[r * 4 + 1] * cy +
|
|
429
|
+
m[r * 4 + 2] * cz +
|
|
430
|
+
m[r * 4 + 3];
|
|
431
|
+
this.sphere(center, object.mesh.radius * scale, HIGHLIGHT_COLOR);
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
const half = 0.35;
|
|
435
|
+
const x = m[3];
|
|
436
|
+
const y = m[7];
|
|
437
|
+
const z = m[11];
|
|
438
|
+
this.box([x - half, y - half, z - half], [x + half, y + half, z + half], HIGHLIGHT_COLOR);
|
|
439
|
+
}
|
|
393
440
|
/**
|
|
394
441
|
* The skeleton of the animated object whose world matrix the flush just read: a line from each
|
|
395
442
|
* joint of its skins to its parent joint, where the last animation step posed them.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** The calls that the panel makes, as the engine's inspection channel takes them. */
|
|
2
|
+
export interface InspectorBridge {
|
|
3
|
+
inspect(call: string, args?: unknown): Promise<unknown>;
|
|
4
|
+
/** The canvas that the engine draws on. */
|
|
5
|
+
canvas: HTMLCanvasElement;
|
|
6
|
+
}
|
|
7
|
+
/** The panel's element, which a page finds by this attribute. */
|
|
8
|
+
export declare const INSPECTOR_ATTRIBUTE = "data-null3d-inspector";
|
|
9
|
+
/** The panel of the in-page inspector. */
|
|
10
|
+
export declare class Inspector {
|
|
11
|
+
private readonly bridge;
|
|
12
|
+
private readonly host;
|
|
13
|
+
private readonly tree;
|
|
14
|
+
private readonly detail;
|
|
15
|
+
private readonly figures;
|
|
16
|
+
private readonly count;
|
|
17
|
+
private readonly search;
|
|
18
|
+
private readonly error;
|
|
19
|
+
private readonly treeRows;
|
|
20
|
+
private readonly collapsed;
|
|
21
|
+
private selected;
|
|
22
|
+
private summaries;
|
|
23
|
+
private statsTimer;
|
|
24
|
+
private searchTimer;
|
|
25
|
+
private selectToken;
|
|
26
|
+
private listToken;
|
|
27
|
+
private statsBusy;
|
|
28
|
+
private removed;
|
|
29
|
+
constructor(bridge: InspectorBridge);
|
|
30
|
+
/** Takes the panel off the page and clears the selection's outline. */
|
|
31
|
+
remove(): void;
|
|
32
|
+
/** Lists the scene again after the search settles. */
|
|
33
|
+
private scheduleSearch;
|
|
34
|
+
/** Lists the scene, or the objects that the search names, and draws the tree. */
|
|
35
|
+
private list;
|
|
36
|
+
/** Draws the tree from a listing, parents before their children, with the rows nested. */
|
|
37
|
+
private drawTree;
|
|
38
|
+
/** Selects `slot`, outlines it and shows its fields. */
|
|
39
|
+
private select;
|
|
40
|
+
/** Shows an object's title, transform, flags and material. */
|
|
41
|
+
private drawDetail;
|
|
42
|
+
/** A labelled row of three number fields that reports all three when one changes. */
|
|
43
|
+
private vectorGroup;
|
|
44
|
+
/** A labelled checkbox. */
|
|
45
|
+
private checkField;
|
|
46
|
+
/** The base color and the three values that the inspector edits most. */
|
|
47
|
+
private materialSection;
|
|
48
|
+
/** One row of the material section. */
|
|
49
|
+
private materialRow;
|
|
50
|
+
/** Applies a change to the selected object and shows what the scene now holds. */
|
|
51
|
+
private change;
|
|
52
|
+
/** Applies a material change and shows the object's new state. */
|
|
53
|
+
private changeMaterial;
|
|
54
|
+
/** Reads the frame figures and shows them. */
|
|
55
|
+
private refreshStats;
|
|
56
|
+
/** Shows an error under the detail, or clears it. */
|
|
57
|
+
private showError;
|
|
58
|
+
}
|
|
59
|
+
/** Opens the inspector panel on the page, and returns it. */
|
|
60
|
+
export declare function openInspector(bridge: InspectorBridge): Inspector;
|