@null3d/engine 0.1.0 → 0.1.2
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/dist/wasm/single/null3d.js +10 -8
- package/dist/wasm/single/null3d_bg.wasm +0 -0
- package/dist/wasm/threaded/null3d.js +10 -8
- package/dist/wasm/threaded/null3d_bg.wasm +0 -0
- package/docs/api/animation.md +96 -24
- package/docs/api/assets.md +99 -29
- package/docs/api/cameras.md +38 -7
- package/docs/api/controls.md +47 -23
- package/docs/api/debug.md +105 -35
- package/docs/api/engine.md +108 -32
- package/docs/api/feature-draws.md +21 -15
- package/docs/api/feature-effects.md +8 -8
- package/docs/api/feature-instances.md +68 -17
- package/docs/api/features.md +68 -37
- package/docs/api/geometry.md +83 -14
- package/docs/api/grass.md +55 -13
- package/docs/api/impostors.md +92 -50
- package/docs/api/input.md +22 -9
- package/docs/api/lights.md +67 -16
- package/docs/api/lines.md +38 -13
- package/docs/api/materials.md +187 -59
- package/docs/api/math.md +6 -6
- package/docs/api/objects.md +40 -15
- package/docs/api/page.md +58 -7
- package/docs/api/particles.md +36 -11
- package/docs/api/points.md +18 -8
- package/docs/api/post.md +57 -23
- package/docs/api/quality.md +36 -16
- package/docs/api/raycast.md +57 -24
- package/docs/api/reference/animation.md +1 -2
- package/docs/api/reference/assets.md +7 -4
- package/docs/api/reference/cameras.md +3 -2
- package/docs/api/reference/controls.md +59 -2
- package/docs/api/reference/debug.md +58 -6
- package/docs/api/reference/engine.md +40 -10
- package/docs/api/reference/feature-draws.md +3 -4
- package/docs/api/reference/feature-effects.md +2 -3
- package/docs/api/reference/feature-instances.md +5 -4
- package/docs/api/reference/features.md +7 -4
- package/docs/api/reference/geometry.md +132 -21
- package/docs/api/reference/grass.md +62 -2
- package/docs/api/reference/impostors.md +120 -16
- package/docs/api/reference/input.md +1 -2
- package/docs/api/reference/lights.md +4 -3
- package/docs/api/reference/lines.md +3 -4
- package/docs/api/reference/materials.md +7 -6
- package/docs/api/reference/math.md +13 -2
- package/docs/api/reference/objects.md +2 -3
- package/docs/api/reference/particles.md +31 -6
- package/docs/api/reference/points.md +2 -3
- package/docs/api/reference/post.md +4 -3
- package/docs/api/reference/quality.md +1 -2
- package/docs/api/reference/raycast.md +1 -2
- package/docs/api/reference/render.md +4 -3
- package/docs/api/reference/scene.md +24 -5
- package/docs/api/reference/sketch.md +11 -11
- package/docs/api/reference/sound.md +33 -2
- package/docs/api/reference/splats.md +42 -3
- package/docs/api/reference/sprites.md +2 -3
- package/docs/api/reference/tasks.md +16 -3
- package/docs/api/reference/terrain.md +26 -5
- package/docs/api/reference/textures.md +1 -2
- package/docs/api/reference/three-compat.md +18 -7
- package/docs/api/reference/time.md +1 -2
- package/docs/api/reference/ui.md +10 -7
- package/docs/api/reference/vertex-draws.md +2 -3
- package/docs/api/reference/water.md +78 -5
- package/docs/api/reference/wind.md +15 -2
- package/docs/api/render.md +67 -25
- package/docs/api/scene.md +129 -36
- package/docs/api/sketch.md +45 -19
- package/docs/api/sound.md +48 -12
- package/docs/api/splats.md +42 -15
- package/docs/api/sprites.md +8 -6
- package/docs/api/tasks.md +31 -22
- package/docs/api/terrain.md +44 -12
- package/docs/api/textures.md +61 -12
- package/docs/api/three-compat.md +15 -7
- package/docs/api/time.md +3 -5
- package/docs/api/ui.md +18 -10
- package/docs/api/vertex-draws.md +13 -12
- package/docs/api/water.md +111 -67
- package/docs/api/wind.md +61 -15
- package/docs/cli/null3d.md +90 -15
- package/docs/concepts/architecture.md +69 -23
- package/docs/concepts/assets.md +57 -16
- package/docs/concepts/backends.md +68 -24
- package/docs/concepts/color-management.md +42 -13
- package/docs/concepts/culling.md +68 -47
- package/docs/concepts/handles.md +14 -5
- package/docs/concepts/instances.md +72 -23
- package/docs/concepts/large-worlds.md +17 -7
- package/docs/concepts/lighting.md +117 -44
- package/docs/concepts/lod.md +128 -33
- package/docs/concepts/materials.md +43 -12
- package/docs/concepts/particle-buffer.md +48 -35
- package/docs/concepts/post-processing.md +77 -14
- package/docs/concepts/quality-preset-tables.md +3 -2
- package/docs/concepts/quality-presets.md +122 -39
- package/docs/concepts/render-graph.md +56 -21
- package/docs/concepts/render-layers.md +9 -5
- package/docs/concepts/shadows.md +96 -25
- package/docs/concepts/static-dynamic.md +22 -7
- package/docs/cookbook/index.md +163 -119
- package/docs/data/threejs-mapping.json +301 -340
- package/docs/errors/E1101.md +23 -5
- package/docs/errors/E1102.md +11 -3
- package/docs/errors/E1103.md +11 -3
- package/docs/errors/E1104.md +11 -3
- package/docs/errors/E1105.md +13 -5
- package/docs/errors/E1106.md +11 -3
- package/docs/errors/E1107.md +15 -5
- package/docs/errors/E1108.md +11 -3
- package/docs/errors/E1109.md +32 -6
- package/docs/errors/E1110.md +23 -5
- package/docs/errors/E1111.md +11 -3
- package/docs/errors/E1112.md +11 -3
- package/docs/errors/E1203.md +12 -4
- package/docs/errors/E1204.md +11 -3
- package/docs/errors/E1205.md +11 -3
- package/docs/errors/E1206.md +28 -6
- package/docs/errors/E1207.md +11 -3
- package/docs/errors/E1208.md +12 -3
- package/docs/errors/E1209.md +11 -3
- package/docs/errors/E1213.md +27 -5
- package/docs/errors/E1214.md +11 -3
- package/docs/errors/E1215.md +31 -6
- package/docs/errors/E1216.md +31 -6
- package/docs/errors/E1217.md +29 -6
- package/docs/errors/E1218.md +22 -6
- package/docs/errors/E1219.md +11 -3
- package/docs/errors/E1220.md +24 -5
- package/docs/errors/E1221.md +24 -5
- package/docs/errors/E1222.md +11 -3
- package/docs/errors/E1223.md +39 -6
- package/docs/errors/E1224.md +11 -3
- package/docs/errors/E1225.md +11 -3
- package/docs/errors/E1301.md +11 -3
- package/docs/errors/E1302.md +11 -3
- package/docs/errors/E1303.md +11 -3
- package/docs/errors/E1304.md +11 -3
- package/docs/errors/E1305.md +13 -3
- package/docs/errors/E1306.md +11 -3
- package/docs/errors/E1307.md +23 -6
- package/docs/errors/E1308.md +31 -0
- package/docs/errors/E1401.md +11 -3
- package/docs/errors/E1402.md +13 -5
- package/docs/errors/E1403.md +11 -3
- package/docs/errors/E1404.md +13 -3
- package/docs/errors/E1405.md +15 -4
- package/docs/errors/E1406.md +31 -5
- package/docs/errors/E1407.md +11 -3
- package/docs/errors/E1408.md +11 -3
- package/docs/errors/E1409.md +11 -3
- package/docs/errors/E1410.md +13 -5
- package/docs/errors/E1411.md +11 -3
- package/docs/errors/E1412.md +29 -6
- package/docs/errors/E1413.md +11 -3
- package/docs/errors/E1414.md +11 -3
- package/docs/errors/E1415.md +11 -3
- package/docs/errors/E1416.md +27 -6
- package/docs/errors/E1417.md +11 -3
- package/docs/errors/E1418.md +12 -3
- package/docs/errors/E1419.md +13 -5
- package/docs/errors/E1420.md +11 -3
- package/docs/errors/E1421.md +11 -3
- package/docs/errors/E1422.md +12 -3
- package/docs/errors/E1423.md +12 -3
- package/docs/errors/E1424.md +24 -5
- package/docs/errors/E1425.md +11 -3
- package/docs/errors/E1426.md +11 -3
- package/docs/errors/E1430.md +11 -3
- package/docs/errors/E1431.md +11 -3
- package/docs/errors/E1432.md +11 -3
- package/docs/errors/E1433.md +11 -3
- package/docs/errors/E1434.md +15 -6
- package/docs/errors/E1435.md +11 -3
- package/docs/errors/E1436.md +11 -3
- package/docs/errors/E1437.md +14 -6
- package/docs/errors/E1501.md +41 -6
- package/docs/errors/E1502.md +13 -3
- package/docs/errors/E1503.md +11 -3
- package/docs/errors/E1504.md +11 -3
- package/docs/errors/E1505.md +23 -5
- package/docs/errors/E1506.md +11 -3
- package/docs/errors/index.md +53 -29
- package/docs/getting-started/cdn.md +15 -9
- package/docs/getting-started/first-scene.md +20 -12
- package/docs/getting-started/hosting.md +113 -63
- package/docs/getting-started/install.md +39 -24
- package/docs/getting-started/network-use.md +31 -21
- package/docs/getting-started/project-structure.md +20 -8
- package/docs/getting-started/third-party-notices.md +6 -10
- package/docs/guides/accessibility.md +4 -4
- package/docs/guides/add-ons.md +83 -13
- package/docs/guides/agents.md +13 -14
- package/docs/guides/assets-pipeline.md +294 -72
- package/docs/guides/audio.md +17 -15
- package/docs/guides/baked-light-data.md +44 -23
- package/docs/guides/car-paint.md +37 -31
- package/docs/guides/content-pages.md +86 -29
- package/docs/guides/custom-passes.md +59 -17
- package/docs/guides/custom-shaders.md +54 -37
- package/docs/guides/debugging.md +31 -41
- package/docs/guides/deploying.md +10 -27
- package/docs/guides/deterministic-simulation.md +23 -16
- package/docs/guides/first-use-shaders.md +83 -45
- package/docs/guides/lens-kit.md +29 -26
- package/docs/guides/loading-screens.md +74 -30
- package/docs/guides/multiple-views.md +22 -11
- package/docs/guides/performance.md +188 -37
- package/docs/guides/phones.md +71 -19
- package/docs/guides/physics.md +6 -10
- package/docs/guides/screens.md +41 -29
- package/docs/guides/start-time.md +126 -85
- package/docs/guides/testing.md +137 -98
- package/docs/guides/ui-overlays.md +17 -12
- package/docs/guides/video-textures.md +14 -13
- package/docs/images/api/animation/character.webp +0 -0
- package/docs/images/api/animation/look-at-ring.webp +0 -0
- package/docs/images/api/animation/morph-tulips.webp +0 -0
- package/docs/images/api/animation/skeleton-lines.webp +0 -0
- package/docs/images/api/controls/gizmo-handles.webp +0 -0
- package/docs/images/api/controls/walk-and-fly.webp +0 -0
- package/docs/images/api/debug/debug-shapes.webp +0 -0
- package/docs/images/api/debug/levels-view.webp +0 -0
- package/docs/images/api/engine/transparent-canvas.webp +0 -0
- package/docs/images/api/feature-draws/feature-draw-clouds.webp +0 -0
- package/docs/images/api/feature-instances/compute-instances.webp +0 -0
- package/docs/images/api/feature-instances/instances-shadow.webp +0 -0
- package/docs/images/api/geometry/extra-shapes.webp +0 -0
- package/docs/images/api/geometry/generators.webp +0 -0
- package/docs/images/api/geometry/mesh-arrays.webp +0 -0
- package/docs/images/api/geometry/vertex-updates.webp +0 -0
- package/docs/images/api/grass/grass-grove.webp +0 -0
- package/docs/images/api/grass/grass-presets.webp +0 -0
- package/docs/images/api/grass/grass-shadow.webp +0 -0
- package/docs/images/api/impostors/impostor-handover.webp +0 -0
- package/docs/images/api/impostors/impostor-shadow.webp +0 -0
- package/docs/images/api/impostors/impostors-forest.webp +0 -0
- package/docs/images/api/lights/spot-cookies.webp +0 -0
- package/docs/images/api/lines/lines-lit.webp +0 -0
- package/docs/images/api/lines/lines-widths.webp +0 -0
- package/docs/images/api/materials/coat-and-sheen.webp +0 -0
- package/docs/images/api/materials/decals.webp +0 -0
- package/docs/images/api/materials/iridescence-and-anisotropy.webp +0 -0
- package/docs/images/api/materials/relief.webp +0 -0
- package/docs/images/api/materials/shader-inputs.webp +0 -0
- package/docs/images/api/materials/standard-grid.webp +0 -0
- package/docs/images/api/materials/subsurface.webp +0 -0
- package/docs/images/api/materials/translucency.webp +0 -0
- package/docs/images/api/objects/objects-turntable.webp +0 -0
- package/docs/images/api/particles/campfire.webp +0 -0
- package/docs/images/api/points/galaxy.webp +0 -0
- package/docs/images/api/reference/textures/texture-wrap.webp +0 -0
- package/docs/images/api/render/fullscreen-glow.webp +0 -0
- package/docs/images/api/render/reflection-mirror.webp +0 -0
- package/docs/images/api/render/security-camera.webp +0 -0
- package/docs/images/api/scene/aurora-sky-layer.webp +0 -0
- package/docs/images/api/sound/sound-demo.webp +0 -0
- package/docs/images/api/splats/splats-demo.webp +0 -0
- package/docs/images/api/sprites/sprites-lines.webp +0 -0
- package/docs/images/api/terrain/terrain-demo.webp +0 -0
- package/docs/images/api/textures/canvas-screen.webp +0 -0
- package/docs/images/api/textures/mipmaps.webp +0 -0
- package/docs/images/api/vertex-draws/rain.webp +0 -0
- package/docs/images/api/water/ocean.webp +0 -0
- package/docs/images/api/water/water-demo.webp +0 -0
- package/docs/images/api/water/water-rain.webp +0 -0
- package/docs/images/api/water/waterfall.webp +0 -0
- package/docs/images/concepts/assets/gltf-model.webp +0 -0
- package/docs/images/concepts/color-management/tone-mapped.webp +0 -0
- package/docs/images/concepts/culling/far-from-origin.webp +0 -0
- package/docs/images/concepts/instances/instances.webp +0 -0
- package/docs/images/concepts/instances/per-row-colors.webp +0 -0
- package/docs/images/concepts/large-worlds/large-world.webp +0 -0
- package/docs/images/concepts/lighting/area-lights.webp +0 -0
- package/docs/images/concepts/lighting/atmosphere.webp +0 -0
- package/docs/images/concepts/lighting/environment.webp +0 -0
- package/docs/images/concepts/lighting/light-shafts.webp +0 -0
- package/docs/images/concepts/lighting/reflection-probes.webp +0 -0
- package/docs/images/concepts/lod/forest.webp +0 -0
- package/docs/images/concepts/materials/weighted-transparency.webp +0 -0
- package/docs/images/concepts/post-processing/auto-exposure.webp +0 -0
- package/docs/images/concepts/post-processing/bounce-light.webp +0 -0
- package/docs/images/concepts/post-processing/depth-of-field.webp +0 -0
- package/docs/images/concepts/post-processing/post-effects-alley.webp +0 -0
- package/docs/images/concepts/post-processing/sharpen.webp +0 -0
- package/docs/images/concepts/post-processing/ssr-wet-street.webp +0 -0
- package/docs/images/concepts/render-layers/layers-cottages.webp +0 -0
- package/docs/images/concepts/shadows/hero-shadow.webp +0 -0
- package/docs/images/cookbook/index/picking.webp +0 -0
- package/docs/images/cookbook/index/time-of-day.webp +0 -0
- package/docs/images/errors/E1431/area-lights-no-tables.webp +0 -0
- package/docs/images/guides/custom-passes/reflection-water.webp +0 -0
- package/docs/images/guides/deterministic-simulation/replay-demo.webp +0 -0
- package/docs/images/guides/multiple-views/split-screen.webp +0 -0
- package/docs/images/guides/performance/overdraw-view.webp +0 -0
- package/docs/images/guides/testing/hold-mode-frame.webp +0 -0
- package/docs/images/index/showcase-island.webp +0 -0
- package/docs/images/porting/threejs-shaders/dissolve.webp +0 -0
- package/docs/images/shaders/builtins/builtins.webp +0 -0
- package/docs/images/shaders/surface-functions/custom-surface.webp +0 -0
- package/docs/images/shaders/surface-functions/vertex-offset.webp +0 -0
- package/docs/images/shots.json +2231 -0
- package/docs/index.md +14 -23
- package/docs/moves.json +1 -0
- package/docs/nav.json +300 -0
- package/docs/pages.md +230 -212
- package/docs/porting/react-three-fiber.md +2 -6
- package/docs/porting/threejs-loop-and-threads.md +1 -5
- package/docs/porting/threejs-mapping.md +1248 -234
- package/docs/porting/threejs-materials.md +10 -5
- package/docs/porting/threejs-overview.md +26 -6
- package/docs/porting/threejs-postprocessing.md +2 -6
- package/docs/porting/threejs-shaders.md +16 -14
- package/docs/porting/threejs-unsupported.md +6 -6
- package/docs/porting/verification.md +0 -4
- package/docs/shaders/builtins.md +15 -4
- package/docs/shaders/library.md +9 -6
- package/docs/shaders/surface-functions.md +51 -16
- package/docs/shaders/wgsl-rules.md +12 -5
- package/lib/debug/debug.d.ts +2 -2
- package/lib/debug/draw.d.ts +2 -2
- package/lib/debug/draw.js +8 -4
- package/lib/debug/overlay-look.d.ts +6 -0
- package/lib/debug/overlay-look.js +29 -7
- package/lib/debug/overlay.js +15 -11
- package/lib/debug/stats-options.d.ts +13 -0
- package/lib/debug/stats-panel.d.ts +21 -6
- package/lib/debug/stats-panel.js +80 -13
- package/lib/errors/codes.d.ts +17 -3
- package/lib/errors/codes.js +116 -105
- package/lib/errors/engine-error.js +1 -1
- package/lib/errors/fixes.d.ts +1 -0
- package/lib/errors/fixes.js +19 -18
- package/lib/generated/shader-permutations.d.ts +6 -0
- package/lib/generated/shader-permutations.js +6 -0
- package/lib/gpu/variants.d.ts +8 -2
- package/lib/gpu/variants.js +39 -7
- package/lib/gpu/webgl2/programs.js +1 -1
- package/lib/gpu/webgpu/pipelines.js +13 -13
- package/lib/index.d.ts +1 -1
- package/lib/page/capabilities.d.ts +1 -1
- package/lib/page/engine.d.ts +29 -7
- package/lib/page/engine.js +79 -7
- package/lib/page/label-loop.js +9 -4
- package/lib/page/stats-switch.js +2 -0
- package/lib/page/switches.d.ts +6 -4
- package/lib/page/switches.js +20 -4
- package/lib/scene/baked-light.d.ts +2 -2
- package/lib/scene/fake-call-values.js +2 -2
- package/lib/scene/frame-cameras.d.ts +16 -4
- package/lib/scene/frame-cameras.js +28 -10
- package/lib/scene/gltf.d.ts +1 -1
- package/lib/scene/level-rule.d.ts +6 -5
- package/lib/scene/level-rule.js +2 -2
- package/lib/scene/particles.d.ts +7 -3
- package/lib/scene/particles.js +3 -1
- package/lib/scene/post.d.ts +3 -2
- package/lib/scene/resources.d.ts +15 -9
- package/lib/scene/scene.d.ts +18 -2
- package/lib/scene/scene.js +47 -5
- package/lib/scene/time-of-day.d.ts +10 -5
- package/lib/scene/time-of-day.js +11 -7
- package/lib/shader-artifact.json +1 -1
- package/lib/shared/labels.d.ts +5 -2
- package/lib/shared/labels.js +5 -2
- package/lib/shared/permutation-words.d.ts +8 -0
- package/lib/shared/permutation-words.js +14 -0
- package/lib/shared/recording.d.ts +13 -5
- package/lib/shared/recording.js +31 -10
- package/lib/shared/sketch-data.d.ts +9 -0
- package/lib/shared/sketch-data.js +57 -0
- package/lib/shared/tier.d.ts +9 -0
- package/lib/shared/tier.js +4 -1
- package/lib/shared/version.d.ts +1 -1
- package/lib/shared/version.js +1 -1
- package/lib/sketch/define-sketch.d.ts +16 -7
- package/lib/sketch/define-sketch.js +2 -1
- package/lib/sketch/runner.d.ts +4 -0
- package/lib/sketch/runner.js +5 -0
- package/lib/sketch/ui.js +4 -2
- package/lib/stats.d.ts +1 -0
- package/lib/workers/protocol.d.ts +10 -0
- package/lib/workers/render-worker.js +4 -1
- package/lib/workers/sketch-worker.js +4 -1
- package/package.json +1 -1
package/docs/api/scene.md
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/scene
|
|
3
3
|
title: Scene
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.1"
|
|
6
4
|
summary: "Creating objects; models and copies; find; multiple views of one scene; background, environment, reflection probes, fog, sky; the light probe grid; the material override; warmUp."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Scene
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
The scene holds everything the engine draws: the objects, the camera that the canvas shows, the lights and the background. A sketch gets it as `scene` in its setup function, and creates everything through it.
|
|
9
|
+
The scene holds everything the engine draws: the objects, the camera that the canvas shows, the lights and the background. A sketch gets it as `scene` in its setup function, and creates everything through it. Wrong options throw one of the codes in [Errors](#errors).
|
|
14
10
|
|
|
15
11
|
```ts
|
|
16
12
|
import { defineSketch } from '@null3d/engine';
|
|
@@ -68,11 +64,17 @@ export default defineSketch(({ scene, geometry, materials }) => {
|
|
|
68
64
|
| `addComputeInstances(description, options)` | A draw of instances from the add-on's own GPU buffer, after an `await`: [Add-on instance draws](feature-instances.md) |
|
|
69
65
|
| `createVertexDraw(options)` | A draw of a custom material over a vertex count, with no mesh data: [Draws from a vertex count](vertex-draws.md) |
|
|
70
66
|
|
|
71
|
-
Groups, meshes, cameras and lights take the same object options: `name`, `position`, `rotation`, `scale`, `parent`, `dynamic` and `layers`. [Objects and transforms](objects.md) describes them.
|
|
67
|
+
Groups, meshes, cameras and lights take the same object options: `name`, `position`, `rotation`, `scale`, `parent`, `dynamic` and `layers`. [Objects and transforms](objects.md) describes them.
|
|
68
|
+
|
|
69
|
+
`createMesh` also takes `castShadows` and `receiveShadows`, which [Shadows](../concepts/shadows.md) explains. It takes `occluder` too, which [Culling](../concepts/culling.md) explains. `createInstances` takes `colors: true` and `values: true` for a color and four values per row: [Instances and batching](../concepts/instances.md).
|
|
70
|
+
|
|
71
|
+
Meshes come from `geometry` and materials from `materials` in the sketch context. One mesh and one material can serve any number of objects.
|
|
72
72
|
|
|
73
73
|
## Models and copies
|
|
74
74
|
|
|
75
|
-
`scene.instantiate(prefab, options)` creates the objects of a model that [`assets.loadGltf`](assets.md#gltf-models) loaded. It returns a `PrefabInstance`: a group that holds the copy of the file's nodes. The `options` place that group as they place any object. Every copy shares the model's meshes, materials and textures, so a second copy costs only its objects.
|
|
75
|
+
`scene.instantiate(prefab, options)` creates the objects of a model that [`assets.loadGltf`](assets.md#gltf-models) loaded. It returns a `PrefabInstance`: a group that holds the copy of the file's nodes. The `options` place that group as they place any object. Every copy shares the model's meshes, materials and textures, so a second copy costs only its objects.
|
|
76
|
+
|
|
77
|
+
`castShadows` and `receiveShadows` apply to every mesh of the copy, and to every row of the instance batches of nodes with instancing of their own. The engine reserves the places of all the copy's objects with one call, and queues their changes as one batch. So no frame shows part of a copy.
|
|
76
78
|
|
|
77
79
|
```ts
|
|
78
80
|
const ship = await assets.loadGltf('/models/ship.glb');
|
|
@@ -85,7 +87,9 @@ turret?.rotateY(0.5);
|
|
|
85
87
|
|
|
86
88
|
`scene.clone(object)` copies an object and every object below it, with their meshes, materials, lights, cameras and settings. The copy goes under the same parent, so it starts in the same place. It uses the same path as `instantiate`: one call and one batch of changes for the whole tree. Instance batches are not objects, so `clone` leaves them out.
|
|
87
89
|
|
|
88
|
-
`scene.createInstances(prefab, count, options)` draws many copies of a model with instance batches, one for each mesh of the model. The batches share one set of rows, so each row places a whole copy. Write the returned batch's `positions`, `rotations` and `scales` as for a batch of one mesh.
|
|
90
|
+
`scene.createInstances(prefab, count, options)` draws many copies of a model with instance batches, one for each mesh of the model. The batches share one set of rows, so each row places a whole copy. Write the returned batch's `positions`, `rotations` and `scales` as for a batch of one mesh.
|
|
91
|
+
|
|
92
|
+
Each mesh keeps its place in the model. The model's lights are left out. A model with no meshes, or with instancing of its own, throws [E1417](../errors/E1417.md). Give `createInstances` one of its meshes and a material instead, from `prefab.find(name)`.
|
|
89
93
|
|
|
90
94
|
```ts
|
|
91
95
|
const tree = await assets.loadGltf('/models/tree.glb');
|
|
@@ -174,7 +178,11 @@ The analytic sky takes these settings:
|
|
|
174
178
|
| `time` | 0 | The time in seconds that moves the clouds, such as the sketch's time |
|
|
175
179
|
| `showSunDisc` | true | Whether the sky shows the sun's disc |
|
|
176
180
|
|
|
177
|
-
The quality preset's [`cloudSteps`](../concepts/quality-preset-tables.md#settings-of-each-preset) chooses which layer draws: Low and Medium draw the flat layer, and High and Ultra draw volumetric clouds, ray marched through a noise volume. Both read the same settings above, so a setting keeps its meaning when the preset changes.
|
|
181
|
+
The quality preset's [`cloudSteps`](../concepts/quality-preset-tables.md#settings-of-each-preset) chooses which layer draws: Low and Medium draw the flat layer, and High and Ultra draw volumetric clouds, ray marched through a noise volume. Both read the same settings above, so a setting keeps its meaning when the preset changes. A `cloudSteps` of 0 draws the flat layer.
|
|
182
|
+
|
|
183
|
+
WebGL2 and compatibility mode stop at Medium, so they draw the flat layer unless the page sets `cloudSteps` above 0, with `quality.set({ cloudSteps: 32 })` or the `cloudSteps` option of `createEngine`. The tier's noise and shaders load at its first use, and a page on the flat presets downloads neither.
|
|
184
|
+
|
|
185
|
+
The sky's environment map takes the clouds too, with two limits. A map marches at most 16 steps. It draws them only when the page starts with `cloudSteps` above 0, because the map picks the tier's shaders at the page's start. To show clouds in reflections on WebGL2, give the `cloudSteps` option of `createEngine`.
|
|
178
186
|
|
|
179
187
|
Two more settings add a second sky, which `timeOfDay` uses to fade the moon's sky in as night falls:
|
|
180
188
|
|
|
@@ -239,17 +247,29 @@ export default defineSketch(async ({ scene, assets }) => {
|
|
|
239
247
|
| `moonIntensity` | 0 | The moon's light above the air. It lights the air as the sun does, and the sky shows its disc, lit from the sun's side. 0 draws no moon |
|
|
240
248
|
| `stars` | 0 | The stars' brightness. They show only where the sky is dark enough. 0 draws no stars |
|
|
241
249
|
|
|
242
|
-
The sky's light is in the units of a directional light's intensity, so the exposure that suits the scene's lights suits the sky. It does not move a light: set the main light's direction and color with it, or take them from [`timeOfDay`](#time-of-day).
|
|
250
|
+
The sky's light is in the units of a directional light's intensity, so the exposure that suits the scene's lights suits the sky. It does not move a light: set the main light's direction and color with it, or take them from [`timeOfDay`](#time-of-day).
|
|
251
|
+
|
|
252
|
+
The quality setting [`physicalSky`](../concepts/quality-presets.md) is off on Low. There the analytic sky stands in, with the same sun, moon, air and clouds, matched to the physical sky's brightness. The haze on objects stays. The first physical sky downloads its shaders, `'physical_sky'`, and the view shows the background color until its tables are drawn.
|
|
243
253
|
|
|
244
254
|
The sky lights nothing by itself. [`assets.skyEnvironment()`](assets.md#environments) makes an environment of it, which follows the sky's settings as they change: [Lighting and environment](../concepts/lighting.md#sky-and-backgrounds) shows how.
|
|
245
255
|
|
|
246
|
-
The first background of each kind downloads its shaders, `'background'`, `'sky'` or `'physical_sky'`, and the view shows the background color until they are built. [Loading screens](../guides/loading-screens.md#loading-everything-up-front) shows how to load them before the first frame.
|
|
256
|
+
The first background of each kind downloads its shaders, `'background'`, `'sky'` or `'physical_sky'`, and the view shows the background color until they are built. [Loading screens](../guides/loading-screens.md#loading-everything-up-front) shows how to load them before the first frame.
|
|
257
|
+
|
|
258
|
+
Each call sets every option and every setting, and one left out takes its default. The settings are values, not shader builds, and the call allocates nothing. So a sketch can move the sun or turn a cube map in every frame. The engine's allocation benchmark checks it.
|
|
259
|
+
|
|
260
|
+
Each background draws behind every object, in the pixels that no object covers, and exposure and tone mapping change it with the rest of the scene. An orthographic camera's view rays are parallel, so an environment, a cube map or the sky fills its view with one color. The color set before an environment or a cube map shows until its texels are on the GPU, and again after you destroy it.
|
|
247
261
|
|
|
248
|
-
|
|
262
|
+
A value out of its range, `blur` on a background that is not an environment, `rotation` on a texture or the sky, or a background that was destroyed throws one of the codes in [Errors](#errors). [Lighting and environment](../concepts/lighting.md#sky-and-backgrounds) says how each background draws, and what it costs.
|
|
249
263
|
|
|
250
264
|
### Sky layers
|
|
251
265
|
|
|
252
|
-
`scene.setSkyLayer(description, { wgsl })` draws an add-on's own layer over the sky: the top of the sky, a second layer of clouds, an aurora or a space backdrop. The description is a [feature description](features.md): it names the feature and records at the `'background'` point, as a `'draw'`, provides `'sky'`, and draws in the `'main'`, `'scenePass'` and `'reflection'` views.
|
|
266
|
+
`scene.setSkyLayer(description, { wgsl })` draws an add-on's own layer over the sky: the top of the sky, a second layer of clouds, an aurora or a space backdrop. The description is a [feature description](features.md): it names the feature and records at the `'background'` point, as a `'draw'`, provides `'sky'`, and draws in the `'main'`, `'scenePass'` and `'reflection'` views.
|
|
267
|
+
|
|
268
|
+

|
|
269
|
+
|
|
270
|
+
A sky layer from the aurora add-on.
|
|
271
|
+
|
|
272
|
+
The layer's WGSL declares `fn skyLayer(input: SkyLayerInput) -> SkyLayer` and the null3D Vite plugin builds it into the engine's sky-layer template, which owns the box around the camera, the bindings, the depth state and the blend. The layer draws right after the background, in the pixels that no object covers, on WebGPU, WebGL2 and in compatibility mode.
|
|
253
273
|
|
|
254
274
|
```ts
|
|
255
275
|
import { defineFeature, defineSketch } from '@null3d/engine';
|
|
@@ -293,9 +313,15 @@ The layer's function reads one input and returns one value:
|
|
|
293
313
|
|
|
294
314
|
A layer declares no uniforms, textures or bindings of its own: the engine binds the frame and the layer's values, and the add-on's numbers are constants in its WGSL. It draws in the camera's view, in scene passes and in reflections, and it draws nothing where the background draws nothing, as in a debug view. A second call replaces the layer, `set` changes its values, and `scene.clearSkyLayer()` removes it and gives the core sky its full sun back.
|
|
295
315
|
|
|
296
|
-
The layer reaches the sky's environment map as well as the background, so every place that a sky is seen shows it
|
|
316
|
+
The layer reaches the sky's environment map as well as the background, so every place that a sky is seen shows it. A lake or a window reflects the layer, and the diffuse light that the sky gives the scene carries its color. So the layer lights the ground under it.
|
|
317
|
+
|
|
318
|
+
The engine builds the layer's WGSL a second time into the shader that fills the map's cube faces. A small pass sums a level of the map onto the nine coefficients of its diffuse light. The engine reads them back once for each fill. The read is asynchronous and runs in no frame, so nothing waits. A fill that cannot start while another runs starts on a later frame.
|
|
319
|
+
|
|
320
|
+
None of this is the add-on's work, and the light matches the reflections because it comes from them.
|
|
297
321
|
|
|
298
|
-
A fill spreads over some twenty frames, one stage a frame
|
|
322
|
+
A fill spreads over some twenty frames, one stage a frame. A layer that its clock moves sets `refresh`, in seconds, to tell the map how often to capture it again. The map starts one fill each `refresh` seconds, so a shorter time follows a faster layer. At the default of one second, that is about 20 stage draws a second. A layer with `refresh: 0` stands still and costs one fill for each change.
|
|
323
|
+
|
|
324
|
+
Until the first capture of a new layer lands, the scene keeps the core sky's own light, and a frame or two passes before the map's light follows its texels. The aurora example add-on in `examples/addons/aurora/` draws one, over a frozen lake that reflects it.
|
|
299
325
|
|
|
300
326
|
## Multiple views
|
|
301
327
|
|
|
@@ -316,11 +342,17 @@ export default defineSketch(({ scene }) => {
|
|
|
316
342
|
|
|
317
343
|
The view's camera gives its layer mask, as the active camera's does, and the view follows the camera's layers when they change. The rectangle's shape sets the camera's aspect ratio, so objects keep their proportions in a half-width view. `setCamera` changes the view's camera, `setRect` changes its rectangle, and `destroy` removes the view.
|
|
318
344
|
|
|
319
|
-
Each view culls the scene on its own, and draws it at its rectangle's pixels with its own depth. The sun's and the spot lights' shadows, the environment's light and the fog cost nothing more than the camera's view.
|
|
345
|
+
Each view culls the scene on its own, and draws it at its rectangle's pixels with its own depth. The sun's and the spot lights' shadows, the environment's light and the fog cost nothing more than the camera's view.
|
|
346
|
+
|
|
347
|
+
On every GPU path and in every thread mode the view draws in the same frame as the camera's view. The final image takes the tone mapping, the effects and bloom once. On the 8-bit path the view writes display color into the camera's image. The resolve pass or the final pass draws it to the canvas.
|
|
348
|
+
|
|
349
|
+
A view costs one more cull and one more scene draw. The camera's view still draws the whole canvas first, with the canvas's aspect ratio, so a split screen of two half-width views draws the scene three times: once across the canvas underneath and once for each half. A picture in picture draws it twice. The rectangle follows the render scale, as the camera's view does, so a lower scale lowers a view's cost too.
|
|
350
|
+
|
|
351
|
+
A small rectangle costs little on a phone. Bloom's threshold and the tone curve see the whole image once.
|
|
320
352
|
|
|
321
|
-
A view
|
|
353
|
+
A view's objects take no ambient occlusion or screen-space reflections, which shade the camera's view. The camera's volumetric fog and outline are added to the whole image after the views draw, so they also reach a view's rectangle. An object whose material shows a render pass's texture does not draw in a view, as it does not draw in another pass.
|
|
322
354
|
|
|
323
|
-
|
|
355
|
+
`camera.screenToRay` and `camera.worldToScreen` map the whole canvas. `view.screenToRay` and `view.worldToScreen` map the view's image, and `scene.viewAt(x, y)` finds the view under a point ([Multiple views](../guides/multiple-views.md#picking-in-a-view)). A scene and its passes share 32 views, the camera's included; `scene.createView` throws [E1501](../errors/E1501.md) when none is free.
|
|
324
356
|
|
|
325
357
|
[Multiple views](../guides/multiple-views.md) covers split screens, picture in picture and their cost.
|
|
326
358
|
|
|
@@ -338,13 +370,19 @@ scene.setEnvironment(sunset, { intensity: 0.8, rotation: [0, Math.PI / 2, 0] });
|
|
|
338
370
|
| `intensity` | 1 | The factor of the environment's light, 0 or more |
|
|
339
371
|
| `rotation` | `[0, 0, 0]` | The environment's turn, as Euler angles in radians in the order X, Y, Z |
|
|
340
372
|
|
|
341
|
-
Each call sets both options, and an option left out takes its default. The call allocates nothing, so a sketch can turn the environment in every frame.
|
|
373
|
+
Each call sets both options, and an option left out takes its default. The call allocates nothing, so a sketch can turn the environment in every frame. The engine's allocation benchmark checks it. A material's `envIntensity` scales the light on that material.
|
|
374
|
+
|
|
375
|
+
The scene draws without a file's environment until its map is on the GPU. The built-in room's map and the sky's map are whole in the first frame that uses them. The sky's map follows the sky background: after a change that shows, the scene takes the new light up to 19 frames later, and a smaller change waits for its next step. The scene draws without the environment again after `environment.destroy()`.
|
|
376
|
+
|
|
377
|
+
Development builds throw E1203, E1108 and E1213 for values that they refuse, and every build throws E1101 for an environment that was destroyed ([Errors](#errors)). [Lighting and environment](../concepts/lighting.md#environment-maps) says how the environment lights a surface, and what it costs.
|
|
342
378
|
|
|
343
379
|
## The light probe grid
|
|
344
380
|
|
|
345
381
|
`setLightProbeGrid` lights the scene with a grid of irradiance probes, so light that changes with a surface's place, bounced from colored walls or sky, reaches it. Each probe holds L1 spherical harmonics of the light that its surroundings bounce back. Standard materials read the grid per pixel, with four filtered reads each. Its light takes the place of the environment's diffuse light, and the environment keeps its reflections.
|
|
346
382
|
|
|
347
|
-
A grid baked elsewhere passes in through `LightProbeGridData`, which packs its coefficients and its two masks into the texture. Each probe holds four RGB coefficients, 12 numbers: L0, then L1 along y, z and x. It also holds a validity and a sky visibility. The validity is 1 where the probe stands in open space and 0 where geometry encloses it, which stops its light leaking through the wall around it. The sky visibility is the share of the sky that its rays reached.
|
|
383
|
+
A grid baked elsewhere passes in through `LightProbeGridData`, which packs its coefficients and its two masks into the texture. Each probe holds four RGB coefficients, 12 numbers: L0, then L1 along y, z and x. It also holds a validity and a sky visibility. The validity is 1 where the probe stands in open space and 0 where geometry encloses it, which stops its light leaking through the wall around it. The sky visibility is the share of the sky that its rays reached.
|
|
384
|
+
|
|
385
|
+
A grid that a tool outside the engine baked can also come from a file: [`assets.loadLightProbeGrid`](assets.md#baked-light) reads the [baked light file](../guides/baked-light-data.md) format and gives the options below, with the texture already made. `assets.lightProbeGridFile` writes that format from a grid that `bakeProbes` made.
|
|
348
386
|
|
|
349
387
|
```ts
|
|
350
388
|
const grid = new LightProbeGridData(
|
|
@@ -372,9 +410,21 @@ scene.setLightProbeGrid({
|
|
|
372
410
|
| `intensity` | 1 | The factor of the grid's light, 0 or more. A factor of 0 gives none of it |
|
|
373
411
|
| `environmentWeight` | 1 | The share of the environment's diffuse light that the grid takes over, 0 to 1 |
|
|
374
412
|
|
|
375
|
-
`bakeProbes` bakes a grid in the browser. It casts directions from each probe with `scene.raycastBatch`, testing both faces of every triangle. A ray that reaches the sky counts toward the probe's sky visibility, which the live environment's light multiplies at draw time, weighted by how much the surface faces the sky above the horizon, so a change of the hour needs no new bake.
|
|
413
|
+
`bakeProbes` bakes a grid in the browser. It casts directions from each probe with `scene.raycastBatch`, testing both faces of every triangle. A ray that reaches the sky counts toward the probe's sky visibility, which the live environment's light multiplies at draw time, weighted by how much the surface faces the sky above the horizon, so a change of the hour needs no new bake.
|
|
376
414
|
|
|
377
|
-
|
|
415
|
+
A ray that meets a surface's back means geometry encloses the probe: the probe takes no validity, and the bake fills it from the probes around it. Where a ray hits a surface's front, `albedo` gives the surface's color for one colored bounce: the surface sends back that share of the environment's light at its normal, as a matte surface does. The bake counts no lamps, so the grid holds one colored bounce, its occlusion of the sky and which probes are enclosed.
|
|
416
|
+
|
|
417
|
+
| Option | Default | What it sets |
|
|
418
|
+
| --- | --- | --- |
|
|
419
|
+
| `box` | required | The box the probes cover, in the world, as `min` and `max` corners |
|
|
420
|
+
| `spacing` | 2 | The distance between probes along each axis, in meters, or one number for every axis. The grid starts at the box's least corner and takes as many probes as fit, at least two along each axis |
|
|
421
|
+
| `samples` | 64 | The directions cast from each probe, 8 to 1024 |
|
|
422
|
+
| `distance` | the box's diagonal | How far a ray reaches before it counts as the sky, in meters |
|
|
423
|
+
| `environment` | none | The environment whose light a hit surface sends back. Without one, the bake counts no bounce light |
|
|
424
|
+
| `environmentOptions` | those of `scene.setEnvironment` | The intensity and rotation that `scene.setEnvironment` got, so the bounce matches the scene |
|
|
425
|
+
| `albedo` | none | A function that gives a hit surface's color. Without it, the bake holds sky visibility and validity alone |
|
|
426
|
+
|
|
427
|
+
`bake.step(n)` bakes up to n probes, 4 by default, and returns true once every probe is baked. `bake.done` counts the probes baked so far. `bake.grid` holds the result. `bake.finish()` bakes the rest at once and returns the grid. Bake a few probes a frame so a loading screen can show progress.
|
|
378
428
|
|
|
379
429
|
```ts
|
|
380
430
|
import { bakeProbes, defineSketch } from '@null3d/engine';
|
|
@@ -384,13 +434,13 @@ export default defineSketch(async ({ scene, assets, textures }) => {
|
|
|
384
434
|
const environmentOptions = { intensity: 0.8 };
|
|
385
435
|
scene.setEnvironment(environment, environmentOptions);
|
|
386
436
|
// ... build the room here ...
|
|
387
|
-
const
|
|
437
|
+
const gray = [0.8, 0.8, 0.8] as const; // every surface a light gray
|
|
388
438
|
const bake = bakeProbes(scene, {
|
|
389
439
|
box: { min: [-12, 0, -12], max: [12, 8, 12] },
|
|
390
440
|
spacing: [1, 2, 1],
|
|
391
441
|
environment,
|
|
392
442
|
environmentOptions,
|
|
393
|
-
albedo: () =>
|
|
443
|
+
albedo: () => gray,
|
|
394
444
|
});
|
|
395
445
|
let baking = true;
|
|
396
446
|
return {
|
|
@@ -409,7 +459,7 @@ export default defineSketch(async ({ scene, assets, textures }) => {
|
|
|
409
459
|
});
|
|
410
460
|
```
|
|
411
461
|
|
|
412
|
-
|
|
462
|
+
A texture that is not a 3D texture throws [E1222](../errors/E1222.md): make the grid's texture with `LightProbeGridData.toTexture()`. The grid takes 32 bytes of GPU memory per probe, plus a padding slice at either end of each sub-volume, and each lit pixel reads it four times. [Lighting and environment](../concepts/lighting.md#light-probe-grid) gives the grid's limits, what takes its light, and how its shaders load.
|
|
413
463
|
|
|
414
464
|
## Reflection probes
|
|
415
465
|
|
|
@@ -447,9 +497,11 @@ export default defineSketch(async ({ scene, assets, input }) => {
|
|
|
447
497
|
| `layers` | The default layer | The layers of the objects that the captures draw |
|
|
448
498
|
| `priority` | 0 | Where boxes overlap, the higher priority wins, then the smaller box |
|
|
449
499
|
|
|
450
|
-
`probe.set(options)` sets every option again. A new position or new layers capture again. `probe.capture()` captures again in a frame soon after the call, as after an object around the probe moved. The surfaces in its box read the new map from that frame. Without a call, a probe that refreshes once keeps its last map.
|
|
500
|
+
`probe.set(options)` sets every option again. A new position or new layers capture again. `probe.capture()` captures again in a frame soon after the call, as after an object around the probe moved. The surfaces in its box read the new map from that frame. Without a call, a probe that refreshes once keeps its last map.
|
|
451
501
|
|
|
452
|
-
|
|
502
|
+
`probe.destroy()` removes the probe. Its box takes the light of other probes or of the environment from the next frame.
|
|
503
|
+
|
|
504
|
+
A scene has at most 16 probes, and their captures take 6 of the 32 views that the scene and its [passes](render.md) share. Each throws [E1430](../errors/E1430.md) past its limit. An option that probes do not take, or a call on a probe that was destroyed, throws one of the codes in [Errors](#errors).
|
|
453
505
|
|
|
454
506
|
## Fog
|
|
455
507
|
|
|
@@ -459,7 +511,7 @@ A scene has at most 16 probes, and their captures take 6 of the 32 views that th
|
|
|
459
511
|
- `'exp2'`: thicker with the square of the distance, 1 - exp(-(density × d)²).
|
|
460
512
|
- `'linear'`: clear up to `near`, and hides objects from `far`, with a smooth change between them.
|
|
461
513
|
|
|
462
|
-
The fog can also thin with height, as mist lies in a valley, and glow toward the main directional light. `setFog(null)` removes the fog. The call allocates nothing, so a sketch can change the fog in every frame
|
|
514
|
+
The fog can also thin with height, as mist lies in a valley, and glow toward the main directional light. `setFog(null)` removes the fog. The call allocates nothing, so a sketch can change the fog in every frame. The engine's allocation benchmark checks it, the volumetric fog included.
|
|
463
515
|
|
|
464
516
|
```ts
|
|
465
517
|
scene.setBackground('#b8c4d0');
|
|
@@ -485,7 +537,11 @@ scene.setFog({ color: '#b8c4d0', density: 0.04, sunGlow: 1.5 });
|
|
|
485
537
|
|
|
486
538
|
Height fog sums the fog along each line of sight. A view down into the mist then sees thick fog, and a view up sees clear air. The sun glow takes the color and the intensity of the scene's main directional light, so it follows the light as it moves. Shadows do not block the glow.
|
|
487
539
|
|
|
488
|
-
`background` mixes the scene's fog into the sky and the background, as if they stood at the camera's far plane. The haze over the land then runs on over the sky it meets, so a scene needs no haze sheet. It runs from 0 to 1 and defaults to 0.
|
|
540
|
+
`background` mixes the scene's fog into the sky and the background, as if they stood at the camera's far plane. The haze over the land then runs on over the sky it meets, so a scene needs no haze sheet. It runs from 0 to 1 and defaults to 0.
|
|
541
|
+
|
|
542
|
+
At 0 the background takes no fog, and the background's color or the scene's own sheets must blend the edge; [Where the land ends](../concepts/lighting.md#where-the-land-ends) says how. A material created with `fog: false` keeps its color at every distance, as [Materials](materials.md#options-fixed-at-creation) says.
|
|
543
|
+
|
|
544
|
+
The engine mixes the fog into each pixel as it shades the pixel, before the tone mapping, so fog adds almost no work. The fog applies from the next frame. The `null3d::fog` module of the [shader library](../shaders/library.md#null3dfog) holds the same formulas for WGSL shaders.
|
|
489
545
|
|
|
490
546
|
### Volumetric fog
|
|
491
547
|
|
|
@@ -509,13 +565,19 @@ scene.setFog({
|
|
|
509
565
|
|
|
510
566
|
The lit fog takes the fog's `density` and `heightFalloff`, so it lights the same air that dims the objects. It takes `density` with every curve, the linear one too. While it draws, its own light of the sun replaces `sunGlow`, with the shadows. Past its `distance`, the fog still scatters the sun's light, without shadows, so no edge shows.
|
|
511
567
|
|
|
512
|
-
The lit fog needs HDR color. In WebGPU's compatibility mode with MSAA, turning it on moves the engine to HDR color with FXAA, as bloom does, once `fogSlices` is above 0. On a device with no HDR target, the fog keeps its sun glow. The quality setting `fogSlices` sets its detail: 32 slices on Medium, 64 on High and 96 on Ultra. On Low it is 0, so phones draw the fog with its sun glow at no cost.
|
|
568
|
+
The lit fog needs HDR color. In WebGPU's compatibility mode with MSAA, turning it on moves the engine to HDR color with FXAA, as bloom does, once `fogSlices` is above 0. On a device with no HDR target, the fog keeps its sun glow. The quality setting `fogSlices` sets its detail: 32 slices on Medium, 64 on High and 96 on Ultra. On Low it is 0, so phones draw the fog with its sun glow at no cost.
|
|
513
569
|
|
|
514
|
-
|
|
570
|
+
Surfaces that blend or let light through, such as water and glass, take the lit fog of the whole line of sight to the opaque surface behind them. [Lighting and environment](../concepts/lighting.md#volumetric-fog) says how it works and what it costs.
|
|
515
571
|
|
|
516
572
|
## Time of day
|
|
517
573
|
|
|
518
|
-
`timeOfDay(hours)` works out the settings of a time of day. They are the sky, the main light (the sun, or the moon at night), the fog's color and glow, an ambient light, the sky's intensity and the exposure. It takes an hour from 0 to 24, or a preset: `'afternoon'`, `'goldenHour'`, `'blueHour'` or `'night'`.
|
|
574
|
+
`timeOfDay(hours)` works out the settings of a time of day. They are the sky, the main light (the sun, or the moon at night), the fog's color and glow, an ambient light, the sky's intensity and the exposure. It takes an hour from 0 to 24, or a preset: `'afternoon'`, `'goldenHour'`, `'blueHour'` or `'night'`.
|
|
575
|
+
|
|
576
|
+
It returns plain values, which the sketch applies to its own objects. Pass its exposure to `post.set({ exposure })`, or set one of your own. At dusk and at night the default exposure shows the scene several times too dark.
|
|
577
|
+
|
|
578
|
+
A second argument takes `heading` and `noonElevation`. `heading` turns the sun's path about the up axis. `noonElevation` is the noon sun's height in radians, π/3 by default.
|
|
579
|
+
|
|
580
|
+
At night the sky is lit from the moon's place, a navy blue, and the sky's sun disc draws the moon. As night falls the sunset's sky fades straight into the moon's sky.
|
|
519
581
|
|
|
520
582
|
```ts
|
|
521
583
|
import { defineSketch, timeOfDay } from '@null3d/engine';
|
|
@@ -546,7 +608,9 @@ export default defineSketch(async ({ scene, assets, post }) => {
|
|
|
546
608
|
});
|
|
547
609
|
```
|
|
548
610
|
|
|
549
|
-
A third argument is an object that the call fills, in place of making one: `timeOfDay(hour, {}, day)` writes the new settings into `day`, so a day cycle that moves the time in every frame makes no settings object and no arrays of its own. The browser still makes an object of each fraction that one step of the sky model hands to another step that it has not inlined, as it does in any code of this size.
|
|
611
|
+
A third argument is an object that the call fills, in place of making one: `timeOfDay(hour, {}, day)` writes the new settings into `day`, so a day cycle that moves the time in every frame makes no settings object and no arrays of its own. The browser still makes an object of each fraction that one step of the sky model hands to another step that it has not inlined, as it does in any code of this size. The engine's allocation benchmark measures both.
|
|
612
|
+
|
|
613
|
+
`emptyTimeOfDay()` makes the first such object. The [atmosphere demo](https://github.com/null3d-engine/null3d/tree/main/examples/atmosphere) passes one and moves the hour with the pointer.
|
|
550
614
|
|
|
551
615
|
[Lighting and environment](../concepts/lighting.md#time-of-day) explains each value, the presets and the sun's path. A value that is not a finite number, or an unknown preset, throws a `RangeError`. The [time of day demo](https://github.com/null3d-engine/null3d/tree/main/examples/time-of-day) passes a whole day over a lighthouse in 40 seconds, and lights its windows and its lamp at dusk.
|
|
552
616
|
|
|
@@ -570,7 +634,7 @@ The change reaches the frame after the call, and that frame rebuilds the engine'
|
|
|
570
634
|
|
|
571
635
|
Creating an object, `destroy`, `setParent`, `setVisible`, `setLayers` and `setDynamic` change the structure of the scene, and so do the mesh calls: `setMaterial`, `setMesh`, `setCastShadows`, `setReceiveShadows`, `setRenderOrder` and `setFrustumCulled`, and so does `setBounds`. The engine queues these changes and applies them after `onUpdate` returns, before it updates transforms and draws. The frame drawn after the call shows the change. Some of them make the engine rebuild its draw tables, as the [performance guide](../guides/performance.md#objects-during-play) lists.
|
|
572
636
|
|
|
573
|
-
Values that the engine computes, such as the result of `getWorldPosition`, come from the engine's last transform update. In `onUpdate` they come from the previous frame.
|
|
637
|
+
Values that the engine computes, such as the result of `getWorldPosition`, come from the engine's last transform update. In `onUpdate` they come from the previous frame. `onLateUpdate` sees this frame's values; [Sketch API](sketch.md#when-changes-show) gives its timing rules.
|
|
574
638
|
|
|
575
639
|
When the engine cannot apply a change, such as a parent loop (E1104), it skips that change and logs the error to the console. The rest of the queue still applies.
|
|
576
640
|
|
|
@@ -580,7 +644,9 @@ The GPU draws each kind of object with a pipeline, which takes time to build. Th
|
|
|
580
644
|
|
|
581
645
|
## Instance batches
|
|
582
646
|
|
|
583
|
-
An instance batch is one object that draws many copies of one mesh with one material. Its rows live in typed arrays that sketch code writes directly, with no call per row. A static batch, the default, uploads the rows you mark with `markDirty`. A batch created with `dynamic: true` uploads every row in every frame.
|
|
647
|
+
An instance batch is one object that draws many copies of one mesh with one material. Its rows live in typed arrays that sketch code writes directly, with no call per row. A static batch, the default, uploads the rows you mark with `markDirty`. A batch created with `dynamic: true` uploads every row in every frame.
|
|
648
|
+
|
|
649
|
+
Every row of a batch shares the batch's layers, which the `layers` option and `setLayers(mask)` set, as [Render layers](../concepts/render-layers.md) explains. Rows are relative to the batch's `origin`, which keeps rows precise far from the world's origin: [Batch origins](../concepts/large-worlds.md#batch-origins). An add-on whose rows arrive in chunks stores each chunk once with `batch.createChunkRows()`, which packs the chosen rows in the engine's core: [Rows that arrive in chunks](../concepts/instances.md#rows-that-arrive-in-chunks). [Instances and batching](../concepts/instances.md) explains batches in full.
|
|
584
650
|
|
|
585
651
|
## Limits
|
|
586
652
|
|
|
@@ -589,7 +655,25 @@ An instance batch is one object that draws many copies of one mesh with one mate
|
|
|
589
655
|
- A scene holds up to 1,048,575 objects, the most that a handle can name. Past that, a create call throws E1102. A growth that the engine's memory cannot hold throws E1109. Each place counts toward the objects and instance rows that the GPU draws (`engine.capabilities.maxInstances`), and a growth past that limit throws E1501.
|
|
590
656
|
- The rows of an instance batch take none of those places. One engine holds up to 512 batches, and `createInstances(prefab, ...)` takes one for each mesh of the model.
|
|
591
657
|
- The queue holds up to 65,536 changes between two frames. One more throws E1102.
|
|
592
|
-
- Each copy of a model with clips or skins takes a place in the animation table, and its joints take places too. The table starts with room for 1,024 animated objects and 65,536 joints. When a copy does not fit, it doubles what it lacks, in one short pause that copies the table. It holds up to 1,048,576 joints in all.
|
|
658
|
+
- Each copy of a model with clips or skins takes a place in the animation table, and its joints take places too. The table starts with room for 1,024 animated objects and 65,536 joints. When a copy does not fit, it doubles what it lacks, in one short pause that copies the table. It holds up to 1,048,576 joints in all.
|
|
659
|
+
- That is the most that the joint texture holds on every WebGL2 device: about 24,000 copies of a character of 43 joints. A copy past that throws E1102, and a growth that the engine's memory cannot hold throws E1109. Either way, `instantiate` or `clone` then creates no part of the copy.
|
|
660
|
+
|
|
661
|
+
## Errors
|
|
662
|
+
|
|
663
|
+
| Code | Cause |
|
|
664
|
+
| --- | --- |
|
|
665
|
+
| [E1101](../errors/E1101.md) | A call on an object, background, environment or probe that was destroyed. |
|
|
666
|
+
| [E1102](../errors/E1102.md) | A scene past its object, change-queue or animation-table limit, or a copy that does not fit. |
|
|
667
|
+
| [E1104](../errors/E1104.md) | A parent loop: `setParent` given the object itself or one of its descendants. A self-parent throws; a queued loop is skipped and logged. |
|
|
668
|
+
| [E1108](../errors/E1108.md) | A number out of its range, such as a negative blend or intensity, or a box whose `min` is not below its `max`. Development builds throw it. |
|
|
669
|
+
| [E1109](../errors/E1109.md) | The engine's memory cannot hold a growth. |
|
|
670
|
+
| [E1203](../errors/E1203.md) | A number that is not finite. Development builds throw it. |
|
|
671
|
+
| [E1213](../errors/E1213.md) | A value that a call does not take, such as a background option on the wrong kind of background, a value that is not an environment, a camera or rectangle that a view does not take, or a probe option that probes do not take. Development builds throw it. |
|
|
672
|
+
| [E1222](../errors/E1222.md) | A light-probe texture that is not a 3D texture. |
|
|
673
|
+
| [E1224](../errors/E1224.md) | The material override set to a sprite, point or line material. |
|
|
674
|
+
| [E1417](../errors/E1417.md) | `createInstances(prefab, ...)` on a model with no meshes or with instancing of its own. |
|
|
675
|
+
| [E1430](../errors/E1430.md) | Past the scene's limit of 16 reflection probes. |
|
|
676
|
+
| [E1501](../errors/E1501.md) | Past the scene's limit of objects and instance rows, or of views. |
|
|
593
677
|
|
|
594
678
|
## Related pages
|
|
595
679
|
|
|
@@ -600,6 +684,15 @@ An instance batch is one object that draws many copies of one mesh with one mate
|
|
|
600
684
|
- [Loading screens and warm-up](../guides/loading-screens.md): waiting for the scene's pipelines.
|
|
601
685
|
- [Assets and prefabs](../concepts/assets.md): models from glTF files, and what a prefab shares.
|
|
602
686
|
- [Lighting and environment](../concepts/lighting.md#environment-maps): how an environment lights the scene.
|
|
687
|
+
- [The physical sky](https://github.com/null3d-engine/null3d/tree/main/examples/atmosphere): a day over a valley of ridges under the physical sky.
|
|
688
|
+
- [Sky layers](https://github.com/null3d-engine/null3d/tree/main/examples/aurora): curtains of green and violet light over a frozen lake.
|
|
689
|
+
- [Multiple views](https://github.com/null3d-engine/null3d/tree/main/examples/multiple-views): one scene drawn from two cameras in the same frame.
|
|
690
|
+
- [Reflection probes](https://github.com/null3d-engine/null3d/tree/main/examples/reflection-probes): two rooms over one polished floor, each with a probe.
|
|
691
|
+
- [Volumetric fog](https://github.com/null3d-engine/null3d/tree/main/examples/light-shafts): sun rays and lantern cones in a pine wood at dusk.
|
|
692
|
+
- [The environment](https://github.com/null3d-engine/null3d/tree/main/examples/environment): spheres lit by an HDR file, an EXR file and the built-in room.
|
|
693
|
+
- [Instance batches](https://github.com/null3d-engine/null3d/tree/main/examples/instances): 100,000 columns in one batch at golden hour.
|
|
694
|
+
- [Decals](https://github.com/null3d-engine/null3d/tree/main/examples/decals): road paint, posters and stains projected onto a street.
|
|
695
|
+
- [The material override](https://github.com/null3d-engine/null3d/tree/main/examples/objects): the Look button draws the whole stage in one material.
|
|
603
696
|
|
|
604
697
|
## API reference
|
|
605
698
|
|
package/docs/api/sketch.md
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/sketch
|
|
3
3
|
title: "Sketch API: defineSketch and the context"
|
|
4
|
-
|
|
5
|
-
since: "0.1"
|
|
6
|
-
summary: "The context object: scene, assets, materials, geometry, textures, input, time, engine, quality, post, render, page, ui, debug; the callbacks; the options, with the download list."
|
|
4
|
+
summary: "The context object: the start data, scene, assets, materials, geometry, textures, input, time, engine, quality, post, render, page, ui, debug; the callbacks; the options, with the download list."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Sketch API: defineSketch and the context
|
|
10
8
|
|
|
11
|
-
> Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
|
|
12
|
-
|
|
13
9
|
In null3D, a 3D scene is called a sketch. A sketch module builds the scene and updates it every frame, and its default export is `defineSketch(setup)`. The engine loads the module, calls `setup` once with the sketch's context, and then calls the callbacks that `setup` returns.
|
|
14
10
|
|
|
15
11
|
```ts
|
|
@@ -40,18 +36,29 @@ export default defineSketch(({ scene, geometry, materials, input, page }) => {
|
|
|
40
36
|
|
|
41
37
|
## Where the sketch runs
|
|
42
38
|
|
|
43
|
-
The page passes the module's address to `createEngine`, and the engine loads the module in the sketch worker. The sketch worker has no `document` and no `window`, so the page keeps the HTML and the two sides talk through [messages](page.md). On a page without cross-origin isolation, the engine runs the sketch on the page's own thread, with the same API ([Hosting and cross-origin isolation](../getting-started/hosting.md)).
|
|
39
|
+
The page passes the module's address to `createEngine`, and the engine loads the module in the sketch worker. The sketch worker has no `document` and no `window`, so the page keeps the HTML and the two sides talk through [messages](page.md). On a page without cross-origin isolation, the engine runs the sketch on the page's own thread, with the same API ([Hosting and cross-origin isolation](../getting-started/hosting.md)). The [hold mode demo](https://github.com/null3d-engine/null3d/tree/main/examples/hold-mode) runs the same sketch with a held frame.
|
|
40
|
+
|
|
41
|
+
Code at the top of the module can run before the engine has started, so it must not call the engine ([E1403](../errors/E1403.md)).
|
|
42
|
+
|
|
43
|
+
A module whose default export is not `defineSketch(...)` fails the start with [E1401](../errors/E1401.md). A module that does not load fails it with [E1410](../errors/E1410.md): the module did not download, or its code threw an error while it loaded. The engine imports a module that does not load once more, after a short wait, so a short break in the network does not fail the start.
|
|
44
|
+
|
|
45
|
+
<details>
|
|
46
|
+
<summary>Technical details: how the engine loads the module</summary>
|
|
44
47
|
|
|
45
|
-
|
|
48
|
+
The console notes the second import. Only a second failure gives E1410, with the first failure's reason. Code at the top of the module runs once, when the module loads, before the engine calls `setup`. The engine loads the module while it downloads its core, in the sketch worker or, in the single-threaded build, on the page. So the module's own imports and its top-level code take no time of their own on a slow network. Code there can also run when the start fails.
|
|
46
49
|
|
|
47
|
-
|
|
50
|
+
Work there must not need the engine. Every call that makes scene data goes through the setup's context. Work that needs no engine, such as a large table that the first view reads, can run there and overlap the download.
|
|
48
51
|
|
|
49
|
-
|
|
52
|
+
In hold mode, a replay and a recording, the engine loads the module only after it has started and seeded the thread's random numbers. There, code at the top of the module draws the same numbers from `Math.random` on every run ([Testing](../guides/testing.md#hold-mode)).
|
|
53
|
+
|
|
54
|
+
</details>
|
|
50
55
|
|
|
51
56
|
## The setup function
|
|
52
57
|
|
|
53
58
|
The engine calls `setup` once, with the context, before the first frame. `setup` returns the callbacks, or nothing when the sketch needs no frame callback. It can also be `async` and return them through a promise, for example to await data first. The first frame waits for the promise, and `createEngine` resolves only after it.
|
|
54
59
|
|
|
60
|
+
The setup reads the page's start data as `ctx.data`. It holds what the page knows before the scene starts, such as the section that its address names. With `defineSketch<Data>(setup)`, its type is `Data | undefined`. It is `undefined` when the page passes no `sketchData`. [Start data](page.md#start-data) shows both sides.
|
|
61
|
+
|
|
55
62
|
An error that `setup` throws ends the start: `createEngine` rejects with it. An engine error keeps its code, such as [E1204](../errors/E1204.md) for a color the engine cannot read. In the threaded build, any other error arrives as [E1405](../errors/E1405.md), with its message.
|
|
56
63
|
|
|
57
64
|
## Options
|
|
@@ -62,7 +69,7 @@ An error that `setup` throws ends the start: `createEngine` rejects with it. An
|
|
|
62
69
|
| --- | --- | --- |
|
|
63
70
|
| `fixedRate` | 60 | Fixed steps per second of sketch time: how often `onFixedUpdate` runs |
|
|
64
71
|
| `maxFixedSteps` | 8 | The most fixed steps that one frame runs, after a slow frame |
|
|
65
|
-
| `lowestTier` | true |
|
|
72
|
+
| `lowestTier` | true | `false` keeps the governor out of its [lowest quality tier](../concepts/quality-presets.md#the-lowest-quality-tier), which cuts the render scale, shadows and bloom. Set it when the sketch's own code, not the GPU, makes frames slow: the cuts cannot make that code faster. The page's `?tier=off` switch does the same. |
|
|
66
73
|
| `downloads` | none | The files that the setup loads, which start to download as soon as the module has loaded ([The download list](#the-download-list)) |
|
|
67
74
|
| `serialLoadWarning` | true | False turns off a development build's warning for a load that waited for another one ([Loads one after another](#loads-one-after-another)) |
|
|
68
75
|
|
|
@@ -105,14 +112,22 @@ An entry that is not a file's address, such as an empty string, fails the start
|
|
|
105
112
|
|
|
106
113
|
### Loads one after another
|
|
107
114
|
|
|
108
|
-
A development build watches the setup's loads. Sometimes a load starts its download only after another load's file has arrived, while no other file downloads. The console then shows one warning that names both files. The two files could have downloaded together, and the first frame waited for the gap. Start both loads before you await either, as `Promise.all` does above, or name both files in `downloads`.
|
|
115
|
+
A development build watches the setup's loads. Sometimes a load starts its download only after another load's file has arrived, while no other file downloads. The console then shows one warning that names both files. The two files could have downloaded together, and the first frame waited for the gap. Start both loads before you await either, as `Promise.all` does above, or name both files in `downloads`.
|
|
116
|
+
|
|
117
|
+
When the second file's address comes from the first file, as a level file names its models, the order is needed. A JSON file that holds the second file's name passes without a warning. For other such cases, pass `serialLoadWarning: false`.
|
|
109
118
|
|
|
110
|
-
|
|
119
|
+
<details>
|
|
120
|
+
<summary>Technical details: what the warning watches</summary>
|
|
121
|
+
|
|
122
|
+
An environment that the engine makes with no file counts as an earlier load too. A load that starts only after `assets.builtinEnvironment` or `assets.skyEnvironment` has finished could have started beside it. The engine watches only the loads of a live setup, not a model's own files and not loads after the first frame. A production build has no warning.
|
|
123
|
+
|
|
124
|
+
</details>
|
|
111
125
|
|
|
112
126
|
## The context
|
|
113
127
|
|
|
114
128
|
| Field | What it holds |
|
|
115
129
|
| --- | --- |
|
|
130
|
+
| `data` | The page's start data, or `undefined` when it passes none: [Start data](page.md#start-data) |
|
|
116
131
|
| `scene` | Objects, cameras, lights, instance batches and the background: [Scene](scene.md) |
|
|
117
132
|
| `geometry` | Mesh generators, such as `geometry.box` and `geometry.sphere` |
|
|
118
133
|
| `materials` | Material factories: [Materials](materials.md) |
|
|
@@ -126,18 +141,29 @@ When the second file's address comes from the first file, as a level file names
|
|
|
126
141
|
| `engine` | The canvas's size, and what the device can do: [The engine field](#the-engine-field) |
|
|
127
142
|
| `preferences` | What the user's system asks of every page, such as less motion: [Accessibility](../guides/accessibility.md) |
|
|
128
143
|
| `page` | Messages to and from the page: [Messages between sketch and page](page.md) |
|
|
129
|
-
| `ui` | HTML labels that follow scene objects: [
|
|
144
|
+
| `ui` | HTML labels that follow scene objects: [Labels that follow objects](ui.md) |
|
|
130
145
|
| `debug` | Lines, boxes, spheres, axes, grids, frustums and lights, drawn for one frame in development builds: [Debug drawing and stats](debug.md) |
|
|
131
146
|
|
|
132
147
|
## The engine field
|
|
133
148
|
|
|
134
|
-
`engine.viewport` holds the canvas's size in CSS pixels, as `width` and `height`. Its `pixelRatio` gives the device pixels per CSS pixel that the engine draws with. That is the display's ratio, capped by the `maxPixelRatio` setting of [`ctx.quality`](quality.md). It is lower on a canvas too large for the GPU's largest texture at that ratio.
|
|
149
|
+
`engine.viewport` holds the canvas's size in CSS pixels, as `width` and `height`. Its `pixelRatio` gives the device pixels per CSS pixel that the engine draws with. That is the display's ratio, capped by the `maxPixelRatio` setting of [`ctx.quality`](quality.md). It is lower on a canvas too large for the GPU's largest texture at that ratio.
|
|
150
|
+
|
|
151
|
+
The engine reads the size at the start of each frame, so it stays the same throughout a frame. The object changes in place, so read its fields when you need them.
|
|
135
152
|
|
|
136
153
|
`engine.capabilities` holds the values of `engine.capabilities` on the page: the GPU path, its optional features and limits, the depth mode, and the most objects the device draws. [Page API: createEngine](engine.md#what-the-engine-reports) describes them. Check a capability before you use an optional feature, and never check GPU or browser names.
|
|
137
154
|
|
|
138
|
-
`engine.held` is true when the engine steps the sketch itself, as hold mode and a replay do. It is false when the sketch runs live.
|
|
155
|
+
`engine.held` is true when the engine steps the sketch itself, as hold mode and a replay do. It is false when the sketch runs live. Unlike `time.held`, it is true for the whole session, the setup included, and in a replay too.
|
|
156
|
+
|
|
157
|
+
A sketch that returns before its scene is complete waits for it when this is true. A held frame or a replay then shows the finished scene. A live page starts the work without awaiting it, and the result appears as it lands.
|
|
158
|
+
|
|
159
|
+
`engine.firstFrame` is a promise that resolves once the GPU has finished the engine's first frame, as `engine.firstFrame` does on the page. Start the downloads that the first frame does not need when it resolves; they then leave the network to the first frame's own files, such as its shaders. Never await the promise in the setup, because the first frame waits for the setup. The [Creek showcase](https://github.com/null3d-engine/null3d/tree/main/examples/showcase/creek) waits for it before it loads its models on a live page.
|
|
160
|
+
|
|
161
|
+
<details>
|
|
162
|
+
<summary>Technical details: firstFrame in hold mode and replays</summary>
|
|
163
|
+
|
|
164
|
+
A frame number is no such signal: the thread that draws can still be drawing the first frame while the sketch runs the second. In hold mode and a replay, the promise resolves once the engine has stepped the sketch to its last frame. No frame follows that one, so the work that it starts never changes what those modes show. The promise never resolves when the engine stops first.
|
|
139
165
|
|
|
140
|
-
|
|
166
|
+
</details>
|
|
141
167
|
|
|
142
168
|
```ts
|
|
143
169
|
export default defineSketch(({ scene, engine }) => {
|
|
@@ -180,9 +206,9 @@ Each frame runs the callbacks in this order, and each callback is optional:
|
|
|
180
206
|
|
|
181
207
|
Setters take effect at once. Changes that `onFixedUpdate` and `onUpdate` make show in the frame that the engine draws next. Creating, destroying and reparenting objects take effect when the engine processes the frame, after `onUpdate` returns ([Scene](scene.md#when-changes-take-effect)).
|
|
182
208
|
|
|
183
|
-
In `onLateUpdate`, world positions already hold the frame's changes, so `getWorldPosition` gives the place where the frame draws an object. Setters that `onLateUpdate` calls also show in the same frame. Before it culls and draws, the engine updates the objects that they move and the objects below them. A camera that follows an object there does not lag a frame behind it.
|
|
209
|
+
In `onLateUpdate`, world positions already hold the frame's changes, so `getWorldPosition` gives the place where the frame draws an object. Setters that `onLateUpdate` calls also show in the same frame. Before it culls and draws, the engine updates the objects that they move and the objects below them. A camera that follows an object there does not lag a frame behind it.
|
|
184
210
|
|
|
185
|
-
The engine runs this second update only for a sketch with `onLateUpdate`, and then only for the objects that it moved and the objects below them.
|
|
211
|
+
The engine runs this second update only for a sketch with `onLateUpdate`, and then only for the objects that it moved and the objects below them. Structural changes that `onLateUpdate` makes, such as creating an object, take effect in the next frame.
|
|
186
212
|
|
|
187
213
|
## Example: a camera that follows a moving object
|
|
188
214
|
|
|
@@ -213,7 +239,7 @@ export default defineSketch(({ scene, geometry, materials, time }) => {
|
|
|
213
239
|
});
|
|
214
240
|
```
|
|
215
241
|
|
|
216
|
-
The camera moves in `onLateUpdate`, after the car's move in `onUpdate` reached its world position. In `onUpdate`, `getWorldPosition` would give the car's place in the previous frame, and the camera would trail it.
|
|
242
|
+
The camera moves in `onLateUpdate`, after the car's move in `onUpdate` reached its world position. In `onUpdate`, `getWorldPosition` would give the car's place in the previous frame, and the camera would trail it. The [input demo](https://github.com/null3d-engine/null3d/tree/main/examples/input) follows its walking robot with a camera in `onLateUpdate`.
|
|
217
243
|
|
|
218
244
|
## Errors in callbacks
|
|
219
245
|
|