@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/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# null3D
|
|
2
|
+
|
|
3
|
+
The engine package of [null3D](https://github.com/null3d-engine/null3d), a high-performance browser 3D engine for agents.
|
|
4
|
+
|
|
5
|
+
- **Faster than three.js.** null3D beats three.js in five of its six benchmark scenes. The [performance table](https://github.com/null3d-engine/null3d#performance) has the figures.
|
|
6
|
+
- **Wide device compatibility.** One scene runs on current computers, tablets and phones. The engine draws with WebGPU, and with WebGL2 where WebGPU is missing, from the same code.
|
|
7
|
+
|
|
8
|
+
The engine's core is Rust compiled to WebAssembly. It runs on worker threads, so the page's main thread stays free for the page. You write your scenes in TypeScript.
|
|
9
|
+
|
|
10
|
+
## Start a project
|
|
11
|
+
|
|
12
|
+
The command line tool writes a new project with everything below. It needs [Bun](https://bun.sh/) 1.4.3 or newer:
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
bunx @null3d/cli create my-game
|
|
16
|
+
cd my-game
|
|
17
|
+
bun install
|
|
18
|
+
bunx vite
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Add it to a Vite project
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
bun add @null3d/engine
|
|
25
|
+
bun add -d vite @null3d/vite-plugin
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Every Vite build of a null3D project needs the plugin. It sends the two headers that worker threads need, and it compiles your sketch and your shaders:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
// vite.config.ts
|
|
32
|
+
import { defineConfig } from 'vite';
|
|
33
|
+
import null3d from '@null3d/vite-plugin';
|
|
34
|
+
|
|
35
|
+
export default defineConfig({ plugins: [null3d()] });
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The page, `index.html`, needs a canvas and the page module:
|
|
39
|
+
|
|
40
|
+
```html
|
|
41
|
+
<!doctype html>
|
|
42
|
+
<style>
|
|
43
|
+
html, body { margin: 0; height: 100%; }
|
|
44
|
+
canvas { display: block; width: 100%; height: 100%; }
|
|
45
|
+
</style>
|
|
46
|
+
<canvas></canvas>
|
|
47
|
+
<script type="module" src="./page.ts"></script>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The page module starts the engine on the page's main thread:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
// page.ts
|
|
54
|
+
import { createEngine } from '@null3d/engine';
|
|
55
|
+
|
|
56
|
+
const engine = await createEngine({
|
|
57
|
+
canvas: document.querySelector('canvas')!,
|
|
58
|
+
sketch: new URL('./sketch.ts', import.meta.url),
|
|
59
|
+
});
|
|
60
|
+
await engine.firstFrame;
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
In null3D, a 3D scene is called a sketch. A sketch builds its scene and updates it every frame, in a worker of its own:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
// sketch.ts
|
|
67
|
+
import { defineSketch } from '@null3d/engine';
|
|
68
|
+
|
|
69
|
+
export default defineSketch(({ scene, geometry, materials }) => {
|
|
70
|
+
const camera = scene.createPerspectiveCamera({ fov: 60, position: [0, 1.5, 4], target: [0, 0, 0] });
|
|
71
|
+
scene.setActiveCamera(camera);
|
|
72
|
+
scene.createDirectionalLight({ direction: [-1, -2, -1], intensity: 3 });
|
|
73
|
+
|
|
74
|
+
const cube = scene.createMesh({
|
|
75
|
+
mesh: geometry.box({ width: 1, height: 1, depth: 1 }),
|
|
76
|
+
material: materials.standard({ color: '#4a8cff' }),
|
|
77
|
+
dynamic: true, // it moves every frame
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
let angle = 0;
|
|
81
|
+
return {
|
|
82
|
+
onUpdate(dt) {
|
|
83
|
+
angle += dt * 0.8;
|
|
84
|
+
cube.setRotationEuler(0, angle, 0);
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Run `bunx vite` and open the page. A blue cube turns in the light.
|
|
91
|
+
|
|
92
|
+
## Where it runs
|
|
93
|
+
|
|
94
|
+
- WebGPU in Chrome and Edge 113+, Safari 26, and Firefox 141+ on Windows. Chrome 121+ on Android 12+ gets it with ARM, Qualcomm or Intel GPUs.
|
|
95
|
+
- WebGL2 in older browsers down to Safari 18, Chrome and Edge 91, and Firefox 89, and on devices without WebGPU.
|
|
96
|
+
- Worker threads need two HTTP headers on your page. Without them, null3D runs on one thread.
|
|
97
|
+
- WebGPU needs a secure page: HTTPS, or localhost.
|
|
98
|
+
|
|
99
|
+
[Hosting and cross-origin isolation](https://github.com/null3d-engine/null3d/blob/generated/docs/getting-started/hosting.md) shows the headers for common hosts.
|
|
100
|
+
|
|
101
|
+
## Docs
|
|
102
|
+
|
|
103
|
+
The package holds the docs for its own version, in `docs/`. An agent can read them there, by page ID, such as `concepts/architecture`. The same pages are on [GitHub](https://github.com/null3d-engine/null3d/blob/generated/docs/index.md).
|
|
104
|
+
|
|
105
|
+
The [project's README](https://github.com/null3d-engine/null3d#readme) lists the add-on packages, such as water, terrain, grass and particles, and the benchmarks against three.js.
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
|
|
109
|
+
Licensed under either of the Apache License 2.0 or the MIT license, at your option.
|
package/THIRD-PARTY-NOTICES.txt
CHANGED
|
@@ -578,7 +578,6 @@ The engine core is compiled from Rust with these crates, each offered under the
|
|
|
578
578
|
or the Apache License 2.0. null3D takes them under the MIT License.
|
|
579
579
|
|
|
580
580
|
- The Rust standard library: Copyright (c) The Rust Project Contributors
|
|
581
|
-
- bumpalo 3.20.3: Copyright (c) 2019 Nick Fitzgerald
|
|
582
581
|
- cfg-if 1.0.5: Copyright (c) 2014 Alex Crichton
|
|
583
582
|
- dlmalloc 0.2.14: Copyright (c) 2014 Alex Crichton, the threaded build's heap
|
|
584
583
|
- once_cell 1.21.4: Copyright (c) Aleksey Kladov
|
|
@@ -2364,6 +2364,19 @@ export function setDecalLayers(mask) {
|
|
|
2364
2364
|
return ret >>> 0;
|
|
2365
2365
|
}
|
|
2366
2366
|
|
|
2367
|
+
/**
|
|
2368
|
+
* Turns each camera view's depth prepass on or off from the next frame on: the quality settings
|
|
2369
|
+
* set it, and the lowest quality tier turns it off on WebGL2. Ambient occlusion, contact shadows,
|
|
2370
|
+
* the bounce light and screen-space reflections still draw it while they run, as they read its
|
|
2371
|
+
* depth.
|
|
2372
|
+
* @param {boolean} on
|
|
2373
|
+
* @returns {number}
|
|
2374
|
+
*/
|
|
2375
|
+
export function setDepthPrepass(on) {
|
|
2376
|
+
const ret = wasm.setDepthPrepass(on);
|
|
2377
|
+
return ret >>> 0;
|
|
2378
|
+
}
|
|
2379
|
+
|
|
2367
2380
|
/**
|
|
2368
2381
|
* Turns depth of field on with its focus, aperture, focal length, largest blur, blades and focus
|
|
2369
2382
|
* point from the post-processing values, or off, from the next frame on. The TypeScript API checks
|
|
@@ -2500,8 +2513,8 @@ export function setFeatureInstanceRows(id, start, count, values) {
|
|
|
2500
2513
|
/**
|
|
2501
2514
|
* The scene's fog: its curve (`constants::fog_curve`), or no fog. The call values give its linear
|
|
2502
2515
|
* color, the density of exponential and exponential squared fog, the near and far distances of
|
|
2503
|
-
* linear fog, the height where the fog has that density, its height falloff, its sun glow
|
|
2504
|
-
* glow's exponent.
|
|
2516
|
+
* linear fog, the height where the fog has that density, its height falloff, its sun glow, the
|
|
2517
|
+
* glow's exponent and the background's share of the fog.
|
|
2505
2518
|
* @param {number} curve
|
|
2506
2519
|
* @returns {number}
|
|
2507
2520
|
*/
|
|
@@ -3739,13 +3752,13 @@ export function writeParticleRecords(id, count, first) {
|
|
|
3739
3752
|
function __wbg_get_imports() {
|
|
3740
3753
|
const import0 = {
|
|
3741
3754
|
__proto__: null,
|
|
3742
|
-
|
|
3755
|
+
__wbg___null3dWantJobWorkers_d74b30518b896c49: function() {
|
|
3743
3756
|
globalThis.__null3dWantJobWorkers();
|
|
3744
3757
|
},
|
|
3745
|
-
|
|
3758
|
+
__wbg_error_855af7234cde3bcb: function(arg0, arg1) {
|
|
3746
3759
|
console.error(getStringFromWasm0(arg0, arg1));
|
|
3747
3760
|
},
|
|
3748
|
-
|
|
3761
|
+
__wbg_now_47d0b54329145a52: function() {
|
|
3749
3762
|
const ret = performance.now();
|
|
3750
3763
|
return ret;
|
|
3751
3764
|
},
|
|
@@ -3956,4 +3969,4 @@ async function __wbg_init(module_or_path) {
|
|
|
3956
3969
|
|
|
3957
3970
|
export { initSync, __wbg_init as default };
|
|
3958
3971
|
|
|
3959
|
-
export const coreSources = "
|
|
3972
|
+
export const coreSources = "f1573f4cb73d3b40";
|
|
Binary file
|
|
@@ -2364,6 +2364,19 @@ export function setDecalLayers(mask) {
|
|
|
2364
2364
|
return ret >>> 0;
|
|
2365
2365
|
}
|
|
2366
2366
|
|
|
2367
|
+
/**
|
|
2368
|
+
* Turns each camera view's depth prepass on or off from the next frame on: the quality settings
|
|
2369
|
+
* set it, and the lowest quality tier turns it off on WebGL2. Ambient occlusion, contact shadows,
|
|
2370
|
+
* the bounce light and screen-space reflections still draw it while they run, as they read its
|
|
2371
|
+
* depth.
|
|
2372
|
+
* @param {boolean} on
|
|
2373
|
+
* @returns {number}
|
|
2374
|
+
*/
|
|
2375
|
+
export function setDepthPrepass(on) {
|
|
2376
|
+
const ret = wasm.setDepthPrepass(on);
|
|
2377
|
+
return ret >>> 0;
|
|
2378
|
+
}
|
|
2379
|
+
|
|
2367
2380
|
/**
|
|
2368
2381
|
* Turns depth of field on with its focus, aperture, focal length, largest blur, blades and focus
|
|
2369
2382
|
* point from the post-processing values, or off, from the next frame on. The TypeScript API checks
|
|
@@ -2500,8 +2513,8 @@ export function setFeatureInstanceRows(id, start, count, values) {
|
|
|
2500
2513
|
/**
|
|
2501
2514
|
* The scene's fog: its curve (`constants::fog_curve`), or no fog. The call values give its linear
|
|
2502
2515
|
* color, the density of exponential and exponential squared fog, the near and far distances of
|
|
2503
|
-
* linear fog, the height where the fog has that density, its height falloff, its sun glow
|
|
2504
|
-
* glow's exponent.
|
|
2516
|
+
* linear fog, the height where the fog has that density, its height falloff, its sun glow, the
|
|
2517
|
+
* glow's exponent and the background's share of the fog.
|
|
2505
2518
|
* @param {number} curve
|
|
2506
2519
|
* @returns {number}
|
|
2507
2520
|
*/
|
|
@@ -3739,13 +3752,13 @@ export function writeParticleRecords(id, count, first) {
|
|
|
3739
3752
|
function __wbg_get_imports(memory) {
|
|
3740
3753
|
const import0 = {
|
|
3741
3754
|
__proto__: null,
|
|
3742
|
-
|
|
3755
|
+
__wbg___null3dWantJobWorkers_d74b30518b896c49: function() {
|
|
3743
3756
|
globalThis.__null3dWantJobWorkers();
|
|
3744
3757
|
},
|
|
3745
|
-
|
|
3758
|
+
__wbg_error_855af7234cde3bcb: function(arg0, arg1) {
|
|
3746
3759
|
console.error(getStringFromWasm0(arg0, arg1));
|
|
3747
3760
|
},
|
|
3748
|
-
|
|
3761
|
+
__wbg_now_47d0b54329145a52: function() {
|
|
3749
3762
|
const ret = performance.now();
|
|
3750
3763
|
return ret;
|
|
3751
3764
|
},
|
|
@@ -3972,4 +3985,4 @@ export function releaseInstance() {
|
|
|
3972
3985
|
dropMemoryViews();
|
|
3973
3986
|
}
|
|
3974
3987
|
|
|
3975
|
-
export const coreSources = "
|
|
3988
|
+
export const coreSources = "f1573f4cb73d3b40";
|
|
Binary file
|
package/docs/api/animation.md
CHANGED
|
@@ -39,11 +39,11 @@ The engine builds one skeleton for the whole model. Its joints are every node th
|
|
|
39
39
|
- A node that no clip moves keeps its place. One below a joint goes in the copy's group, where the joints rest.
|
|
40
40
|
- A light on a node that a clip moves is left out, and development builds warn about it.
|
|
41
41
|
|
|
42
|
-
A clip without a name
|
|
42
|
+
A clip without a name is named `animation_` and its index among the file's clips, from 0: the third clip becomes `animation_2`. When two clips share a name, the second becomes `Name 2`, the third `Name 3`, and so on.
|
|
43
43
|
|
|
44
44
|
`scene.clone(copy)` gives the clone an animator of its own, with no clip playing. `scene.createInstances(prefab, count)` draws a model's meshes in their rest pose: instance batches do not animate. Batches do not skin either. A skinned mesh whose rest pose differs from its bind pose draws in its bind pose, and development builds warn.
|
|
45
45
|
|
|
46
|
-
A model's morph targets load with their default weights, and its clips animate the weights, as [Morph targets](#morph-targets) says. A node's own `weights` replace its mesh's
|
|
46
|
+
A model's morph targets load with their default weights, and its clips animate the weights, as [Morph targets](#morph-targets) says. A node's own `weights` replace its mesh's.
|
|
47
47
|
|
|
48
48
|
### Load cost
|
|
49
49
|
|
|
@@ -53,7 +53,7 @@ Files from `bunx @null3d/cli assets optimize` store every clip at the engine's r
|
|
|
53
53
|
|
|
54
54
|
## Seeing the skeleton
|
|
55
55
|
|
|
56
|
-
`debug.skeleton(object)` draws the joints of an animated object, such as a copy's group, in the frame's pose. It draws a line from each joint of a skin to its parent joint.
|
|
56
|
+
`debug.skeleton(object)` draws the joints of an animated object, such as a copy's group, in the frame's pose. It draws a line from each joint of a skin to its parent joint. A line is blue at the joint and green at its parent. Pass a color to draw every line in that color. Call it in `onUpdate`, as every debug drawing call. Only development builds draw it.
|
|
57
57
|
|
|
58
58
|
```ts
|
|
59
59
|
return {
|
|
@@ -94,7 +94,7 @@ return {
|
|
|
94
94
|
| `weight` | 1 | The clip's own weight, 0 or more. A play with a weight joins the other clips of its layer instead of fading them out, as [Clip weights](#clip-weights) shows. |
|
|
95
95
|
| `transition` | `'blend'` | How a play with a fade switches what its layer plays. `'blend'` cross-fades the layer's old clips with the new one, and samples both while the fade runs. `'inertial'` samples only the new clip: the pose the layer leaves carries on at its own speed and eases into the new clip, as [Inertial transitions](#inertial-transitions) shows. It needs a fade above 0, no `weight`, a clip to switch from, and a new clip that does not already play on the layer. An additive play always cross-fades. |
|
|
96
96
|
|
|
97
|
-
`crossFade(name, duration, options)` is `play` with a fade of `duration` seconds, and takes `play`'s other options, such as `layer`, `loop` and `weight`. It always cross-fades, whatever its `transition`,
|
|
97
|
+
`crossFade(name, duration, options)` is `play` with a fade of `duration` seconds, and takes `play`'s other options, such as `layer`, `loop` and `weight`. It always cross-fades, whatever its `transition`, so it shows the mix of the clips while the fade runs. A cross-fade always takes over its layer, with a weight too. A clip that already plays on its layer keeps its time when you play it again, and fades back in from its current weight. So calling `play` with the same clip again does no harm. A clip that played once and reached its end starts again.
|
|
98
98
|
|
|
99
99
|
A plain play fades out only the plain clips of its layer, and an additive play only the additive clips. So a walk keeps playing when a breath starts on its layer as an additive clip.
|
|
100
100
|
|
|
@@ -117,7 +117,7 @@ for (const [k, knight] of knights.entries()) {
|
|
|
117
117
|
}
|
|
118
118
|
```
|
|
119
119
|
|
|
120
|
-
`stop(name, { fade })` fades a clip out on every layer. `stop()` with no name stops every clip. A clip that stops at once, or fades out fully, leaves the pose. With no clip playing, the object holds its rest pose.
|
|
120
|
+
`stop(name, { fade })` fades a clip out on every layer. A fade out starts from the clip's current weight, so a quick change of mind does not jump. `stop()` with no name stops every clip. A clip that stops at once, or fades out fully, leaves the pose. With no clip playing, the object holds its rest pose.
|
|
121
121
|
|
|
122
122
|
`setTimeScale(scale)` sets the rate of every clip of the object. Set it to 0 to pause the object's animation.
|
|
123
123
|
|
|
@@ -162,7 +162,7 @@ The returned animation has these calls and values:
|
|
|
162
162
|
|
|
163
163
|
| Call or value | What it does |
|
|
164
164
|
| --- | --- |
|
|
165
|
-
| `setTime(seconds)` | Places the animation at a time,
|
|
165
|
+
| `setTime(seconds)` | Places the animation at a time, in seconds |
|
|
166
166
|
| `setSpeed(rate)` | Sets the rate of its time |
|
|
167
167
|
| `setPaused(paused)` | Starts or stops its time, and leaves the target as it is |
|
|
168
168
|
| `setLoop(loop)` | Repeats the animation, or makes it hold its last key |
|
|
@@ -180,11 +180,11 @@ const copy = scene.instantiate(await assets.loadGltf(url));
|
|
|
180
180
|
copy.animator().play('Cube Animation');
|
|
181
181
|
```
|
|
182
182
|
|
|
183
|
-
A pointer that the engine does not read leaves the value as the file has it. Development builds warn about each one. The names show the kind. The engine leaves out a camera's values, because it reads no cameras from files. It leaves out an animated texture transform's rotation, and an animated transform of every texture but a base color or an emissive one.
|
|
183
|
+
A pointer that the engine does not read leaves the value as the file has it. Development builds warn about each one. The names show the kind. The engine leaves out a camera's values, because it reads no cameras from files. It leaves out an animated texture transform's rotation, and an animated transform of every texture but a base color or an emissive one. It leaves out a light's inner cone angle. It also leaves out `normalTexture/scale`, and the pointers of `KHR_materials_ior`, `KHR_materials_volume`'s attenuation color and distance, and `KHR_materials_iridescence`'s thickness range. It leaves out the values of extensions that it does not draw. A file's own transforms stay per map, so a file that places its maps differently draws that way.
|
|
184
184
|
|
|
185
185
|
## Clip weights
|
|
186
186
|
|
|
187
|
-
Each clip has a weight of its own
|
|
187
|
+
Each clip has a weight of its own. A play with a `weight` joins the clips that already play on its layer, and the layer blends them by their weights. Where the weights add up to less than 1, the rest pose makes up the remainder.
|
|
188
188
|
|
|
189
189
|
```ts
|
|
190
190
|
const anim = knight.animator();
|
|
@@ -200,7 +200,7 @@ return {
|
|
|
200
200
|
};
|
|
201
201
|
```
|
|
202
202
|
|
|
203
|
-
`setWeight(name, weight)` sets the weight of a clip that plays, on every layer that plays it. It writes the weight into engine memory, so you can change it every frame at no cost. A clip at weight 0 leaves the pose. It keeps playing, and its time moves on
|
|
203
|
+
`setWeight(name, weight)` sets the weight of a clip that plays, on every layer that plays it. It writes the weight into engine memory, so you can change it every frame at no cost. A clip at weight 0 leaves the pose. It keeps playing, and its time moves on. A fade multiplies the weight: a clip at weight 0.5 that fades in reaches 0.5. In development builds, `setWeight` on a clip that does not play throws E1218.
|
|
204
204
|
|
|
205
205
|
Clips that blend by weight keep their own times. A walk and a run of different lengths then step at different moments, and the feet slide. A 1D blend keeps their steps together.
|
|
206
206
|
|
|
@@ -232,8 +232,7 @@ fade's share `x`. The pose reaches the new clip exactly when the fade ends.
|
|
|
232
232
|
An inertial transition needs a fade above 0 and no `weight`. The layer must play a clip to switch
|
|
233
233
|
from, and the new clip must not already play on that layer.
|
|
234
234
|
A play that joins its layer keeps the weighted blend. So do a layer with a 1D blend and an additive
|
|
235
|
-
clip. `crossFade` always cross-fades too
|
|
236
|
-
three.js shows.
|
|
235
|
+
clip. `crossFade` always cross-fades too.
|
|
237
236
|
|
|
238
237
|
A transition costs one extrapolated pose and its velocity per joint of the layer. A scene that
|
|
239
238
|
never uses one pays nothing, and a transition that starts allocates nothing.
|
|
@@ -385,7 +384,7 @@ Events come from the clip's data. The animator also reports two events of its ow
|
|
|
385
384
|
|
|
386
385
|
Each event fires once each time the clip's time passes it, however long the frame was. An event at a clip's last frame fires as the clip loops, as one at its first frame does. Backward clips fire events too, in their order of play.
|
|
387
386
|
|
|
388
|
-
Handlers run on your sketch's thread at the start of the next frame, before `onFixedUpdate` and `onUpdate`. So your update code sees what the clips reached in the frame before
|
|
387
|
+
Handlers run on your sketch's thread at the start of the next frame, before `onFixedUpdate` and `onUpdate`. So your update code sees what the clips reached in the frame before. A clip that a handler plays starts in that frame.
|
|
389
388
|
|
|
390
389
|
## Clips
|
|
391
390
|
|
|
@@ -394,33 +393,31 @@ A clip moves the joints of one skeleton. Each track of a clip moves one joint's
|
|
|
394
393
|
When the engine loads a clip, it stores the keys at one fixed rate for the whole clip. The key before any time is then a direct index, with no search.
|
|
395
394
|
|
|
396
395
|
- A clip whose keys all lie on one grid of at most 30 keys per second keeps that grid exactly. Files exported at 24, 25 or 30 frames per second lose nothing.
|
|
397
|
-
- Other clips get 30 keys per second, spaced so that the last key falls on the clip's end. A clip exported at 60 keys per second keeps every second key.
|
|
396
|
+
- Other clips get 30 keys per second, spaced so that the last key falls on the clip's end. A clip exported at 60 keys per second keeps every second key. Where a joint turns fast between keys, the new keys can cut a corner slightly.
|
|
398
397
|
- Rotations take 8 bytes per key: four 16-bit integers. Translations and scales take 12 bytes per key.
|
|
399
398
|
- A track whose value never changes is stored once. So is a track whose keys move by under a millionth of its largest value, or under a millionth when its values lie within 1. Exporters leave rounding noise of that size in tracks that do not move.
|
|
400
399
|
|
|
401
400
|
A track moves in a straight line from key to key. A step track jumps instead: it holds each key's value until the next key.
|
|
402
401
|
|
|
403
|
-
A cubic spline track, as glTF stores one, keeps an in-tangent and an out-tangent with each key. The engine follows
|
|
402
|
+
A cubic spline track, as glTF stores one, keeps an in-tangent and an out-tangent with each key. The engine follows glTF's cubic spline through the keys, and stores it at 30 keys per second. When the file's keys lie on a coarser grid, the engine keeps them and adds keys between them on a finer grid. Keys every half second, for example, get 14 keys between each two.
|
|
404
403
|
|
|
405
404
|
## Blending
|
|
406
405
|
|
|
407
406
|
An object blends up to eight clips in a frame, each at its own time and weight. Two layers that each cross-fade between two clips, with an additive clip on top, fit with room to spare. So does a three-clip blend that cross-fades to another while a second layer cross-fades between two clips. When all eight are busy, a new clip takes the place of a clip that fades out, the one that counts least. Only when no clip fades out does it take the place of the clip that counts least at that moment.
|
|
408
407
|
|
|
409
|
-
Within a layer, the engine blends clips
|
|
408
|
+
Within a layer, the engine blends clips joint by joint:
|
|
410
409
|
|
|
411
410
|
- A clip counts only for the joints and channels it has tracks for. A clip that moves only an arm leaves the legs to the other clips.
|
|
412
411
|
- Each clip moves the blend so far by its share of the weights so far.
|
|
413
412
|
- In layer 0, where the weights add up to less than 1, the joint's rest pose makes up the remainder.
|
|
414
413
|
|
|
415
|
-
Rotations between keys and rotations in a blend use a corrected form of normalized linear interpolation. It stays within 0.0001 radians of
|
|
416
|
-
|
|
417
|
-
Seven glTF sample models play their clips as three.js plays them. Each joint's skinning matrix matches three.js's within 0.0004 in its rotation and scale, and within 0.0004 of the model's size in its position. Fox's run is the exception: its keys follow no single grid, so the engine stores it at 30 keys per second. The joints that turn fastest then cut corners by up to 0.005.
|
|
414
|
+
Rotations between keys and rotations in a blend use a corrected form of normalized linear interpolation. It stays within 0.0001 radians of spherical interpolation for rotations up to 2 radians apart.
|
|
418
415
|
|
|
419
416
|
## Skinned meshes
|
|
420
417
|
|
|
421
|
-
A skinned mesh's vertices follow the joints of an animated object. Each vertex names up to four joints, with a weight for each. Its skinned place is the sum of its joints' skinning matrices applied to it, each times its weight. The mesh's own world matrix then places it
|
|
418
|
+
A skinned mesh's vertices follow the joints of an animated object. Each vertex names up to four joints, with a weight for each. Its skinned place is the sum of its joints' skinning matrices applied to it, each times its weight. The mesh's own world matrix then places it.
|
|
422
419
|
|
|
423
|
-
On both paths, the vertex shader of each pass that draws a skinned mesh skins it
|
|
420
|
+
On both paths, the vertex shader of each pass that draws a skinned mesh skins it. The shadow passes skin it again. On the devices that the engine was measured on, this was as fast as skinning once per frame, or faster. On WebGPU that was a compute pass, and on WebGL2 transform feedback. Each frame uploads the animated objects' skinning matrices to one float texture, 48 bytes per joint. Every material skins in the vertex shader, custom materials included. Skinned meshes that share a mesh and a material draw in one instanced draw in each pass, so a crowd costs few draw calls. On WebGPU, a custom material's skinning builds download the first time the material draws a skinned mesh. A page whose custom materials never draw one never downloads them. The mesh draws once they have arrived, so call `await scene.warmUp()` in the setup to load them before play.
|
|
424
421
|
|
|
425
422
|
On WebGPU, a compute pass, the skinning pass, skins two kinds of mesh once per frame instead. It runs before the shadow passes and the scene passes. The first kind is morphed meshes, which it morphs first. The second is meshes that a debug view draws, or that a [full shader](../guides/custom-shaders.md#full-shaders) of the sketch's draws. Neither has a skinning build of its vertex shader. The passes then draw the skinned vertices as a plain mesh. Each mesh that the pass skins draws on its own, as it has vertices of its own. The pass skips a mesh that no view draws in a frame, neither the camera nor a shadow cascade. It also skips a mesh whose pose and morph weights did not change since its last skin. The `?skinning=compute` switch makes the pass skin every skinned mesh, to compare the two ways ([Testing](../guides/testing.md#switches-for-tests)).
|
|
426
423
|
|
|
@@ -455,7 +452,7 @@ The clips keep their real speed. Each update covers the frames that it skipped,
|
|
|
455
452
|
|
|
456
453
|
## Morph targets
|
|
457
454
|
|
|
458
|
-
A morph target is another shape of a mesh, such as a smile or a blink. Each object of a mesh with targets blends them in by its own weights. A weight of 0 leaves a target out, 1 adds all of it, and other numbers scale it. The call `setMorphWeight` sets a weight by the target's number or name
|
|
455
|
+
A morph target is another shape of a mesh, such as a smile or a blink. Each object of a mesh with targets blends them in by its own weights. A weight of 0 leaves a target out, 1 adds all of it, and other numbers scale it. The call `setMorphWeight` sets a weight by the target's number or name. The call `getMorphWeight` reads it back. The mesh geometry's `morphTargetNames` lists the names in target order, such as `prefab.find('Face')?.mesh?.morphTargetNames`. A target can move positions, normals and tangents, and change vertex colors, as a glTF file's `COLOR_0` targets do. A morphed vertex color stays between 0 and 1, as the glTF specification asks. A target that leaves out `COLOR_0` while another target of the mesh has it changes no color. A mesh from a glTF file has the file's targets and default weights. A mesh that you build takes its targets from `morphTargets` in [geometry.fromArrays](geometry.md#morph-targets).
|
|
459
456
|
|
|
460
457
|
```ts
|
|
461
458
|
const head = scene.instantiate(face).find('Head') as Mesh;
|
|
@@ -463,63 +460,22 @@ head.setMorphWeight('Smile', 0.6);
|
|
|
463
460
|
head.setMorphWeight(1, Math.sin(time.now) * 0.5 + 0.5);
|
|
464
461
|
```
|
|
465
462
|
|
|
466
|
-
A clip of a glTF file can animate a mesh's weights. While it plays, it blends its weights with the object's own
|
|
463
|
+
A clip of a glTF file can animate a mesh's weights. While it plays, it blends its weights with the object's own. A clip at full weight sets the weights, and a fade blends the two. The object's own weights hold when no clip animates them. The call `setMorphWeight` sets the object's own weight, so a weight that you set shows in full only where no clip animates it. Layers and joint masks work on weights too: a layer masked to a node's name takes that node's weights.
|
|
467
464
|
|
|
468
|
-
On WebGPU, the skinning pass morphs each morphed mesh once per frame, before its joints skin it. On WebGL2, the vertex shader of each pass morphs it
|
|
465
|
+
On WebGPU, the skinning pass morphs each morphed mesh once per frame, before its joints skin it. On WebGL2, the vertex shader of each pass morphs it. Each object then keeps only its largest weights, by the `morphTargets` quality setting: 8 on Low, 16 on Medium, 32 on High and 64 on Ultra. WebGPU keeps every weight. The first morphed mesh that a WebGL2 page draws loads the morph shaders, about 20 KB after compression, and draws once they arrive. On WebGPU, it loads the skinning pass's shaders. `createEngine`'s `preload` option loads either before the first frame ([Loading screens](../guides/loading-screens.md#loading-everything-up-front)).
|
|
469
466
|
|
|
470
467
|
A morphed object culls with a sphere that its weights grow: each target's longest move times the size of its weight. On WebGL2, a custom material draws a morphed mesh in its shape at rest.
|
|
471
468
|
|
|
472
|
-
##
|
|
469
|
+
## Speed compared with three.js
|
|
473
470
|
|
|
474
|
-
|
|
475
|
-
| --- | --- |
|
|
476
|
-
| `new AnimationMixer(root)`, then `mixer.update(dt)` each frame | `object.animator()`; the engine advances every animator each frame |
|
|
477
|
-
| `mixer.clipAction(clip).play()` | `anim.play('name')` |
|
|
478
|
-
| `a.crossFadeTo(b, 0.3)`, `fadeIn`, `fadeOut` | `anim.crossFade('b', 0.3)`, `play` with `fade`, `stop` with `fade` |
|
|
479
|
-
| `action.setLoop(LoopOnce)` with `clampWhenFinished` | `play('name', { loop: false })`: it holds its last frame |
|
|
480
|
-
| `action.timeScale`, `mixer.timeScale` | `play` with `speed`, `anim.setTimeScale` |
|
|
481
|
-
| `action.time = t` before `play()` | `play('name', { time: t })` |
|
|
482
|
-
| `action.setEffectiveWeight(w).play()` for clips that play together | `play('name', { weight: w })`, then `anim.setWeight('name', w)` |
|
|
483
|
-
| A blend of actions whose weights and time scales your code works out from a speed | `anim.playBlend({ walk: 1.4, run: 4 })` and `anim.setBlend(speed)`, with the clips kept in step |
|
|
484
|
-
| `AnimationUtils.makeClipAdditive(clip)` and an additive blend mode | `play('name', { additive: true })` |
|
|
485
|
-
| Clips with tracks filtered out, for upper and lower body | Layers with `setLayerMask` |
|
|
486
|
-
| `mixer.addEventListener('loop' or 'finished')` | `anim.onEvent('loop' or 'finished', handler)`, and events from the clip's data |
|
|
487
|
-
| `gltf.animations` and `new AnimationMixer(gltf.scene)` | `prefab.clips` and `scene.instantiate(prefab).animator()` |
|
|
488
|
-
| `SkeletonUtils.clone(gltf.scene)` | `scene.clone(copy)`, whose copy animates on its own |
|
|
489
|
-
| `new SkeletonHelper(object)` | `debug.skeleton(object)` in `onUpdate` |
|
|
490
|
-
| `skeleton.getBoneByName('Head')` | `anim.joint('Head')`, an index that the joint calls take |
|
|
491
|
-
| `bone.quaternion.copy(q)` after `mixer.update(dt)` | `anim.setJointRotation('Head', q)`, which holds until `clearJoint` |
|
|
492
|
-
| `bone.quaternion.multiply(q)` after `mixer.update(dt)` | `anim.addJointRotation('Spine', q)` |
|
|
493
|
-
| `bone.lookAt(point)`, or a look-at chain that your code works out | `anim.lookAt(point, { joints: ['Spine', 'Neck', 'Head'] })` |
|
|
494
|
-
| `AnimationClip` and `NumberKeyframeTrack` built in code, then `mixer.clipAction(clip).play()` | `scene.animateProperty(lamp, 'light.intensity', { times, values })` |
|
|
495
|
-
| `KHR_animation_pointer` through a registered GLTFLoader plugin | The loader reads the pointer itself, and the clip's animator plays it |
|
|
496
|
-
| `mesh.morphTargetInfluences[k] = w` | `mesh.setMorphWeight(k, w)`, or with the target's name |
|
|
497
|
-
| `mesh.morphTargetDictionary['Smile']` | `mesh.setMorphWeight('Smile', w)`; the mesh geometry's `morphTargetNames`, such as `prefab.find('Face')?.mesh?.morphTargetNames`, lists the names in order |
|
|
498
|
-
| `geometry.morphAttributes.position`, with `morphTargetsRelative = true` | `geometry.fromArrays({ ..., morphTargets: { positions } })` |
|
|
499
|
-
| `geometry.morphAttributes.color` | `geometry.fromArrays({ ..., colors, morphTargets: { colors } })` |
|
|
500
|
-
| `SkinnedMesh` skinned in the vertex shader of each pass that draws it | The same on both paths, custom materials included. On WebGPU, the skinning pass skins morphed meshes once per frame instead |
|
|
501
|
-
|
|
502
|
-
Where three.js and null3D differ:
|
|
503
|
-
|
|
504
|
-
- A three.js fade out starts from full weight. null3D fades a clip out from the weight it has, so a quick change of mind does not jump.
|
|
505
|
-
- three.js makes a bone object for each joint of a glTF skin, which you can find and move. null3D's joints are not objects. To turn a joint from code, use the joint calls of [Joint overrides](#joint-overrides). A three.js bone keeps a rotation that you set only until the next `mixer.update`. A null3D joint rotation holds until `clearJoint`.
|
|
506
|
-
- three.js's `bone.lookAt` turns one bone and has no limits. null3D's `lookAt` turns a chain of up to 4 joints, each within its limit.
|
|
507
|
-
- A three.js action played backward starts at time 0 and wraps to the end. A null3D clip with a negative speed starts at its end.
|
|
508
|
-
- three.js has no layers. null3D's layer 0 blends as three.js's mixer does, and each layer above replaces the pose below.
|
|
509
|
-
- A morphed vertex color stays between 0 and 1, as the glTF specification asks. three.js does not clamp it. A glTF target that leaves out `COLOR_0` while another target has it changes no color in null3D, as the specification says. three.js r186 adds the base color there instead. Its WebGPURenderer draws no color targets, and its WebGLRenderer cannot draw them on colors without alpha.
|
|
510
|
-
- A three.js `play()` never stops other actions. A null3D `play` without a weight fades out the other clips of its layer. Give each clip that plays beside others a `weight`.
|
|
511
|
-
- three.js always cross-fades two actions. A null3D play with a fade can switch with an [inertial transition](#inertial-transitions) instead, which samples only the new clip. `crossFade` keeps the cross-fade.
|
|
512
|
-
- three.js's `setEffectiveWeight` stops a fade. null3D's `setWeight` leaves a fade running, which multiplies the weight.
|
|
513
|
-
- three.js has no blend by a value. A three.js blend of walk and run keeps each clip's own rate, so their steps drift apart. A null3D blend keeps them in step.
|
|
514
|
-
- `action.startAt(time)`, which delays a start, has no counterpart. Call `play` at that time in `onUpdate`.
|
|
515
|
-
- three.js reads `KHR_animation_pointer` with a plugin that registers on the loader. null3D's loader reads the pointers of lights, materials, node visibility and the offset and scale of a base color or emissive texture's transform itself. A pointer that it does not read leaves its value as the file has it, and development builds warn.
|
|
471
|
+
The engine takes animation off the main thread, and does less work and stores less data for each key than three.js:
|
|
516
472
|
|
|
517
473
|
| | three.js | null3D |
|
|
518
474
|
| --- | --- | --- |
|
|
519
475
|
| Where clips are sampled | The main thread, one bone at a time | The job workers, four joints per SIMD operation, characters in parallel |
|
|
520
476
|
| Finding the keys | A search of each track's key times | A direct index, from the clip's fixed rate |
|
|
521
477
|
| Memory per rotation key | 20 bytes: four floats and a time | 8 bytes: four 16-bit integers |
|
|
522
|
-
|
|
|
478
|
+
| Rotations between keys and in blends | Spherical interpolation | Corrected normalized interpolation |
|
|
523
479
|
|
|
524
480
|
## Errors
|
|
525
481
|
|