@null3d/engine 0.0.0 → 0.1.1
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 +25 -10
- package/dist/wasm/single/null3d_bg.wasm +0 -0
- package/dist/wasm/threaded/null3d.js +25 -10
- package/dist/wasm/threaded/null3d_bg.wasm +0 -0
- package/docs/api/animation.md +114 -86
- package/docs/api/assets.md +135 -49
- package/docs/api/cameras.md +45 -12
- package/docs/api/controls.md +88 -62
- package/docs/api/debug.md +116 -41
- package/docs/api/engine.md +117 -35
- package/docs/api/feature-draws.md +23 -17
- package/docs/api/feature-effects.md +11 -11
- package/docs/api/feature-instances.md +70 -19
- package/docs/api/features.md +77 -47
- package/docs/api/geometry.md +132 -82
- package/docs/api/grass.md +55 -13
- package/docs/api/impostors.md +175 -22
- package/docs/api/input.md +24 -18
- package/docs/api/lights.md +78 -51
- package/docs/api/lines.md +41 -33
- package/docs/api/materials.md +248 -121
- package/docs/api/math.md +12 -13
- package/docs/api/objects.md +47 -22
- package/docs/api/page.md +58 -7
- package/docs/api/particles.md +33 -20
- package/docs/api/points.md +19 -31
- package/docs/api/post.md +75 -42
- package/docs/api/quality.md +42 -17
- package/docs/api/raycast.md +65 -51
- package/docs/api/reference/animation.md +10 -11
- package/docs/api/reference/assets.md +25 -22
- package/docs/api/reference/cameras.md +8 -4
- package/docs/api/reference/controls.md +134 -25
- package/docs/api/reference/debug.md +81 -14
- package/docs/api/reference/engine.md +58 -17
- 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 +287 -97
- package/docs/api/reference/grass.md +63 -3
- package/docs/api/reference/impostors.md +208 -13
- package/docs/api/reference/input.md +4 -5
- package/docs/api/reference/lights.md +13 -12
- package/docs/api/reference/lines.md +10 -11
- package/docs/api/reference/materials.md +54 -53
- package/docs/api/reference/math.md +35 -24
- package/docs/api/reference/objects.md +11 -12
- package/docs/api/reference/particles.md +31 -6
- package/docs/api/reference/points.md +6 -7
- package/docs/api/reference/post.md +21 -20
- package/docs/api/reference/quality.md +8 -5
- package/docs/api/reference/raycast.md +7 -8
- package/docs/api/reference/render.md +5 -4
- package/docs/api/reference/scene.md +52 -30
- package/docs/api/reference/sketch.md +15 -11
- package/docs/api/reference/sound.md +234 -0
- package/docs/api/reference/splats.md +42 -3
- package/docs/api/reference/sprites.md +7 -8
- package/docs/api/reference/tasks.md +16 -3
- package/docs/api/reference/terrain.md +27 -5
- package/docs/api/reference/textures.md +5 -6
- package/docs/api/reference/three-compat.md +18 -7
- package/docs/api/reference/time.md +1 -2
- package/docs/api/reference/ui.md +12 -9
- package/docs/api/reference/vertex-draws.md +5 -6
- package/docs/api/reference/water.md +153 -9
- package/docs/api/reference/wind.md +17 -4
- package/docs/api/render.md +73 -29
- package/docs/api/scene.md +164 -60
- package/docs/api/sketch.md +102 -15
- package/docs/api/sound.md +205 -0
- package/docs/api/splats.md +46 -12
- package/docs/api/sprites.md +10 -24
- package/docs/api/tasks.md +33 -24
- package/docs/api/terrain.md +42 -22
- package/docs/api/textures.md +68 -19
- package/docs/api/three-compat.md +15 -7
- package/docs/api/time.md +3 -5
- package/docs/api/ui.md +19 -23
- package/docs/api/vertex-draws.md +13 -12
- package/docs/api/water.md +262 -35
- package/docs/api/wind.md +63 -17
- package/docs/cli/null3d.md +177 -27
- package/docs/concepts/architecture.md +73 -27
- package/docs/concepts/assets.md +57 -33
- package/docs/concepts/backends.md +69 -27
- package/docs/concepts/color-management.md +54 -36
- package/docs/concepts/culling.md +68 -47
- package/docs/concepts/handles.md +14 -5
- package/docs/concepts/instances.md +74 -25
- package/docs/concepts/large-worlds.md +18 -8
- package/docs/concepts/lighting.md +155 -87
- package/docs/concepts/lod.md +126 -44
- package/docs/concepts/materials.md +58 -27
- package/docs/concepts/particle-buffer.md +48 -35
- package/docs/concepts/post-processing.md +84 -43
- package/docs/concepts/quality-preset-tables.md +56 -52
- package/docs/concepts/quality-presets.md +164 -52
- package/docs/concepts/render-graph.md +69 -29
- package/docs/concepts/render-layers.md +11 -21
- package/docs/concepts/shadows.md +105 -52
- package/docs/concepts/static-dynamic.md +22 -7
- package/docs/cookbook/index.md +164 -120
- package/docs/data/threejs-mapping.json +362 -367
- 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 +14 -6
- 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 +40 -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 +14 -6
- 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 +54 -30
- package/docs/getting-started/cdn.md +32 -10
- package/docs/getting-started/first-scene.md +21 -13
- package/docs/getting-started/hosting.md +152 -63
- package/docs/getting-started/install.md +44 -28
- package/docs/getting-started/network-use.md +33 -15
- package/docs/getting-started/project-structure.md +33 -12
- package/docs/getting-started/third-party-notices.md +12 -14
- package/docs/guides/accessibility.md +5 -5
- package/docs/guides/add-ons.md +86 -15
- package/docs/guides/agents.md +16 -9
- package/docs/guides/assets-pipeline.md +259 -82
- package/docs/guides/audio.md +115 -128
- package/docs/guides/baked-light-data.md +44 -23
- package/docs/guides/car-paint.md +38 -32
- package/docs/guides/content-pages.md +63 -35
- package/docs/guides/custom-passes.md +65 -22
- package/docs/guides/custom-shaders.md +59 -39
- package/docs/guides/debugging.md +74 -10
- package/docs/guides/deploying.md +85 -6
- package/docs/guides/deterministic-simulation.md +24 -17
- package/docs/guides/first-use-shaders.md +83 -45
- package/docs/guides/lens-kit.md +29 -26
- package/docs/guides/loading-screens.md +132 -47
- package/docs/guides/multiple-views.md +63 -13
- package/docs/guides/performance.md +192 -38
- package/docs/guides/phones.md +78 -15
- package/docs/guides/physics.md +7 -11
- package/docs/guides/screens.md +47 -33
- package/docs/guides/start-time.md +363 -0
- package/docs/guides/testing.md +152 -95
- package/docs/guides/ui-overlays.md +19 -14
- 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 +18 -23
- package/docs/moves.json +1 -0
- package/docs/nav.json +300 -0
- package/docs/pages.md +230 -209
- package/docs/porting/react-three-fiber.md +225 -6
- package/docs/porting/threejs-loop-and-threads.md +217 -7
- package/docs/porting/threejs-mapping.md +1249 -233
- package/docs/porting/threejs-materials.md +218 -6
- package/docs/porting/threejs-overview.md +240 -7
- package/docs/porting/threejs-postprocessing.md +4 -8
- package/docs/porting/threejs-shaders.md +301 -6
- package/docs/porting/threejs-unsupported.md +83 -7
- package/docs/porting/verification.md +178 -6
- package/docs/shaders/builtins.md +15 -4
- package/docs/shaders/library.md +72 -45
- package/docs/shaders/surface-functions.md +59 -23
- package/docs/shaders/wgsl-rules.md +12 -5
- package/lib/debug/channel.d.ts +103 -0
- package/lib/debug/channel.js +269 -0
- package/lib/debug/debug.d.ts +11 -9
- package/lib/debug/draw.d.ts +11 -2
- package/lib/debug/draw.js +57 -6
- package/lib/debug/inspector.d.ts +60 -0
- package/lib/debug/inspector.js +475 -0
- 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 +22 -7
- package/lib/debug/stats-panel.js +80 -13
- package/lib/debug/stats.d.ts +2 -3
- package/lib/errors/codes.d.ts +17 -3
- package/lib/errors/codes.js +117 -105
- package/lib/errors/engine-error.js +25 -10
- package/lib/errors/fixes.d.ts +1 -0
- package/lib/errors/fixes.js +20 -19
- 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/variants.d.ts +8 -2
- package/lib/gpu/variants.js +39 -7
- 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 +5 -2
- 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 +28 -14
- package/lib/index.d.ts +7 -5
- 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 +8 -8
- 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 +117 -31
- package/lib/page/engine.js +438 -99
- 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 +26 -14
- 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/stats-switch.js +2 -0
- package/lib/page/switches.d.ts +38 -6
- package/lib/page/switches.js +29 -5
- 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/baked-light.d.ts +2 -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 +3 -3
- package/lib/scene/fog.d.ts +11 -4
- package/lib/scene/fog.js +8 -2
- package/lib/scene/frame-cameras.d.ts +35 -4
- package/lib/scene/frame-cameras.js +86 -10
- package/lib/scene/gltf.d.ts +33 -3
- 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 +121 -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/particles.d.ts +7 -3
- package/lib/scene/particles.js +3 -1
- package/lib/scene/picks.d.ts +2 -2
- package/lib/scene/pointer-events.d.ts +4 -7
- package/lib/scene/post.d.ts +39 -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 +238 -261
- package/lib/scene/resources.js +179 -81
- package/lib/scene/scene.d.ts +167 -120
- package/lib/scene/scene.js +243 -103
- 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 +11 -7
- package/lib/scene/time-of-day.js +11 -8
- 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/labels.d.ts +5 -2
- package/lib/shared/labels.js +5 -2
- package/lib/shared/metrics.d.ts +38 -0
- package/lib/shared/metrics.js +62 -1
- package/lib/shared/permutation-words.d.ts +2 -0
- package/lib/shared/permutation-words.js +8 -0
- package/lib/shared/recording.d.ts +13 -5
- package/lib/shared/recording.js +31 -10
- package/lib/shared/run-task.js +7 -1
- package/lib/shared/sketch-data.d.ts +9 -0
- package/lib/shared/sketch-data.js +57 -0
- 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 +51 -7
- package/lib/sketch/define-sketch.js +2 -1
- 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 +80 -9
- package/lib/sketch/runner.js +390 -52
- package/lib/sketch/ui.d.ts +5 -8
- package/lib/sketch/ui.js +4 -2
- package/lib/stats.d.ts +1 -0
- package/lib/workers/probe-worker.d.ts +5 -0
- package/lib/workers/probe-worker.js +13 -4
- package/lib/workers/protocol.d.ts +71 -13
- package/lib/workers/protocol.js +4 -0
- package/lib/workers/render-worker.js +29 -5
- package/lib/workers/sketch-worker.js +108 -16
- package/package.json +2 -2
package/docs/api/sprites.md
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/sprites
|
|
3
3
|
title: Sprites
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.2"
|
|
6
4
|
summary: "createSprites; world and screen size modes; atlases."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Sprites
|
|
10
8
|
|
|
11
|
-
> Roadmap step 0.2, first released in null3D 0.1.0. The API is experimental, so it can still change between versions. Sprites do not cast or receive shadows, and overlap queries do not find them. Coding agents must not rely on either.
|
|
12
|
-
|
|
13
9
|
```mermaid
|
|
14
10
|
flowchart LR
|
|
15
11
|
code["Sketch code writes rows<br/>into typed arrays"] --> rows[("Sprite rows<br/>position, size, rotation,<br/>color, frame")]
|
|
@@ -22,6 +18,10 @@ A sprite is a flat picture that always faces the camera, such as a particle, a m
|
|
|
22
18
|
|
|
23
19
|
A batch is one draw for the GPU, whatever its size. The engine culls the sprites and sorts blended sprites back to front, as it does for instance rows. This work runs on the job workers or on the GPU. The [sprites and lines demo](https://github.com/null3d-engine/null3d/tree/main/examples/sprites-lines) draws a fountain of 2,000 sparks in one batch.
|
|
24
20
|
|
|
21
|
+

|
|
22
|
+
|
|
23
|
+
Only the sparks are sprites; the helix and the loop are lines.
|
|
24
|
+
|
|
25
25
|
```ts
|
|
26
26
|
import { defineSketch } from '@null3d/engine';
|
|
27
27
|
|
|
@@ -142,13 +142,15 @@ With `sizeAttenuation: false`, sizes are in CSS pixels, at every distance and on
|
|
|
142
142
|
|
|
143
143
|
## Blending, sorting and depth
|
|
144
144
|
|
|
145
|
-
Blended sprites draw after the opaque objects, farthest first, in the same transparent pass as other blended objects. The engine sorts each sprite by the depth of its position in the camera's view. It sorts the sprites of a batch among each other and among the scene's other blended objects and rows, every frame. Sorting costs time in large batches. For particles that add light, such as sparks and fire, `blending: 'additive'` with `depthWrite: false` needs no exact order to look right.
|
|
145
|
+
Blended sprites draw after the opaque objects, farthest first, in the same transparent pass as other blended objects. The engine sorts each sprite by the depth of its position in the camera's view. It sorts the sprites of a batch among each other and among the scene's other blended objects and rows, every frame. Sorting costs time in large batches. For particles that add light, such as sparks and fire, `blending: 'additive'` with `depthWrite: false` needs no exact order to look right. Sprites do not cast or receive shadows.
|
|
146
146
|
|
|
147
147
|
`alphaMode: 'mask'` draws sprites opaque, cut out by their alpha, with no sorting. Use it for foliage and other sharp edged pictures.
|
|
148
148
|
|
|
149
149
|
## Clicks and raycasts
|
|
150
150
|
|
|
151
|
-
Raycasts hit a sprite where the ray crosses its quad
|
|
151
|
+
Raycasts hit a sprite where the ray crosses its quad. The hit's `object` is the batch, and its `instance` is the sprite. A sprite batch takes `sprites.on('click', handler)` and the other [pointer events on objects](input.md#pointer-events-on-objects), as an instance batch does. A ray hits the whole quad, also where the sprite's map is clear.
|
|
152
|
+
|
|
153
|
+
[Raycasting](raycast.md#sprites-points-and-lines) has the details. Overlap queries do not find sprites. Use a raycast.
|
|
152
154
|
|
|
153
155
|
```ts
|
|
154
156
|
sprites.on('click', (event) => {
|
|
@@ -160,25 +162,9 @@ sprites.on('click', (event) => {
|
|
|
160
162
|
|
|
161
163
|
## Speed
|
|
162
164
|
|
|
163
|
-
A batch costs about the same per sprite as an instance batch costs per row. The engine packs each sprite into the data that it keeps for an instance row. So sprites share the culling, sorting and drawing of instance batches. One batch of 100,000 sprites draws in one draw on WebGPU and WebGL2.
|
|
164
|
-
|
|
165
|
-
Every sprite counts toward the device's limit of objects and instance rows, as an instance row does ([Instances and batching](../concepts/instances.md#limits)). Each sprite takes about 215 bytes of engine memory. Sprite batches count toward the limit of 256 instance batches.
|
|
166
|
-
|
|
167
|
-
## Compared with three.js
|
|
168
|
-
|
|
169
|
-
| three.js | null3D |
|
|
170
|
-
| --- | --- |
|
|
171
|
-
| `new THREE.Sprite(new THREE.SpriteMaterial({ map, color }))` | One row of `scene.createSprites({ count, map })`; set `colors` per sprite or `color` for all |
|
|
172
|
-
| `sprite.position` | `positions` |
|
|
173
|
-
| `sprite.scale.set(w, h, 1)` | `sizes` |
|
|
174
|
-
| `material.rotation` | `rotations`, per sprite |
|
|
175
|
-
| `material.sizeAttenuation = false` | `sizeAttenuation: false`, with sizes in CSS pixels |
|
|
176
|
-
| `sprite.center` | `center`, for the whole batch |
|
|
177
|
-
| `texture.offset` and `texture.repeat` for an atlas | `atlas` and `frames` |
|
|
178
|
-
| `material.transparent` (true for sprites) | `alphaMode: 'blend'`, the default |
|
|
179
|
-
| `material.alphaTest` | `alphaMode: 'mask'` with `alphaCutoff` |
|
|
165
|
+
A batch costs about the same per sprite as an instance batch costs per row. The engine packs each sprite into the data that it keeps for an instance row. So sprites share the culling, sorting and drawing of instance batches. One batch of 100,000 sprites draws in one draw on WebGPU and WebGL2, where three.js makes one object and one draw for each sprite.
|
|
180
166
|
|
|
181
|
-
|
|
167
|
+
Every sprite counts toward the device's limit of objects and instance rows, as an instance row does ([Instances and batching](../concepts/instances.md#limits)). Each sprite takes about 215 bytes of engine memory. Sprite batches count toward the limit of 512 instance batches.
|
|
182
168
|
|
|
183
169
|
## API reference
|
|
184
170
|
|
package/docs/api/tasks.md
CHANGED
|
@@ -1,48 +1,57 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/tasks
|
|
3
3
|
title: Tasks on the job workers
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.3"
|
|
6
4
|
summary: "runTask: an add-on's code and WebAssembly on the job workers; shared memory; ordering with the frames; failures."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Tasks on the job workers
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
An add-on can move heavy work off the thread that runs the sketch, and onto the engine's job workers. `runTask` runs a task there while the frames continue. An add-on that chooses what to draw, or in what order, from many objects uses this hook: the Gaussian splats add-on chooses each chunk's prefix there, nearest first. The engine's transparent pass then sorts the chosen rows on the job workers, as it does for every blended draw, so an add-on does not sort its drawn rows through a task.
|
|
9
|
+
An add-on can move heavy work off the thread that runs the sketch, and onto the engine's job workers. `runTask` runs a task there while the frames continue.
|
|
14
10
|
|
|
15
11
|
A task is an object with three parts: a name, the address of the module that runs, and the WebAssembly files that the module uses. The module exports `run`, and the worker calls it for each task. The answer travels back to the thread that called `runTask`.
|
|
16
12
|
|
|
17
13
|
```ts
|
|
18
14
|
import { runTask, type Task } from '@null3d/engine';
|
|
19
15
|
|
|
20
|
-
export const
|
|
21
|
-
name: '
|
|
22
|
-
script: new URL('./
|
|
16
|
+
export const SELECT_TASK: Task = {
|
|
17
|
+
name: 'splats-select',
|
|
18
|
+
script: new URL('./select-task.ts', import.meta.url),
|
|
23
19
|
wasm: [
|
|
24
|
-
{ name: '
|
|
20
|
+
{ name: 'splats', url: new URL('./splats.wasm', import.meta.url), what: 'the splat selector' },
|
|
25
21
|
],
|
|
26
22
|
};
|
|
27
23
|
|
|
28
|
-
export async function
|
|
29
|
-
const answer = await runTask<{
|
|
30
|
-
return answer.
|
|
24
|
+
export async function selectChunks(view: Int32Array): Promise<number[]> {
|
|
25
|
+
const answer = await runTask<{ chosen: number[] }>(SELECT_TASK, { view });
|
|
26
|
+
return answer.chosen;
|
|
31
27
|
}
|
|
32
28
|
```
|
|
33
29
|
|
|
30
|
+
The Gaussian splats add-on uses a task like this to choose each chunk's splats, nearest first. The engine's transparent pass sorts the chosen rows itself, as it does for every blended draw, so a task chooses rows but does not sort them for drawing.
|
|
31
|
+
|
|
34
32
|
The module that the task's address names looks like this:
|
|
35
33
|
|
|
36
34
|
```ts
|
|
37
35
|
export function run(input, wasm) {
|
|
38
|
-
const module = wasm('
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
// ... write the
|
|
42
|
-
return { output: {
|
|
36
|
+
const module = wasm('splats'); // the compiled WebAssembly module, by the name the task gives it
|
|
37
|
+
const selector = startSelector(module); // the add-on's own start of its WebAssembly
|
|
38
|
+
const chosen = selector.select(input.view); // reads the caller's shared buffer
|
|
39
|
+
// ... write the chosen chunks into the shared buffer ...
|
|
40
|
+
return { output: { chosen } };
|
|
43
41
|
}
|
|
44
42
|
```
|
|
45
43
|
|
|
44
|
+
`run` returns an object with the answer in `output`, and the promise of `runTask` resolves with that `output`. A `run` that returns its answer directly resolves the promise with `undefined`.
|
|
45
|
+
|
|
46
|
+
<details>
|
|
47
|
+
<summary>Technical details: what can pass to a worker, and moving buffers</summary>
|
|
48
|
+
|
|
49
|
+
A task's input and output must pass to another worker: numbers, strings, plain objects and arrays, typed arrays, `ArrayBuffer`s and `SharedArrayBuffer`s.
|
|
50
|
+
|
|
51
|
+
The engine copies an `ArrayBuffer` by default. To move one instead of copying it, name it in a transfer list. `run` can return `{ output, transfer: [buffer] }` to move a buffer back to the caller. `runTask(task, input, [buffer])` moves a buffer of the input to the worker. A moved buffer is empty on the side that sent it.
|
|
52
|
+
|
|
53
|
+
</details>
|
|
54
|
+
|
|
46
55
|
The engine imports the module once in each worker that runs the task, so the module keeps its state between tasks. Each WebAssembly file compiles once per page, and the engine sends the compiled module to the workers.
|
|
47
56
|
|
|
48
57
|
The build bundles the module that the task names, so it may be TypeScript with its imports. A worker imports it as it does any module, and raw TypeScript would not parse there. The engine's Vite plugin emits the module as its own chunk for that reason.
|
|
@@ -60,16 +69,16 @@ Throw a `TaskLoadError` when the module's code or WebAssembly cannot start. The
|
|
|
60
69
|
|
|
61
70
|
## Shared memory
|
|
62
71
|
|
|
63
|
-
A per-frame
|
|
72
|
+
A per-frame task copies no data when its input and output live in one `SharedArrayBuffer`. The engine posts the buffer to the worker without copying it, and the task writes the result into it.
|
|
64
73
|
|
|
65
74
|
```ts
|
|
66
75
|
const shared = new SharedArrayBuffer(4 * (1 + count * 2));
|
|
67
76
|
const view = new Int32Array(shared);
|
|
68
|
-
// view[0] holds the count, view[1] to view[count] the values, and the task writes the
|
|
69
|
-
//
|
|
77
|
+
// view[0] holds the count, view[1] to view[count] the values, and the task writes the chosen
|
|
78
|
+
// indices after them.
|
|
70
79
|
Atomics.store(view, 0, count);
|
|
71
|
-
const answer = await runTask(
|
|
72
|
-
const
|
|
80
|
+
const answer = await runTask(SELECT_TASK, { view });
|
|
81
|
+
const chosen = view.subarray(count + 1, count + 1 + count);
|
|
73
82
|
```
|
|
74
83
|
|
|
75
84
|
While a task runs, both threads read the shared memory. Order the writes that both threads read with `Atomics`. Once the promise resolves, the worker has stopped writing, and the sketch reads the buffer as it stands.
|
|
@@ -91,9 +100,9 @@ A task that fails does not stop the engine, and a later task tries again. A modu
|
|
|
91
100
|
|
|
92
101
|
## The task's module in a build
|
|
93
102
|
|
|
94
|
-
The address must name
|
|
103
|
+
The address must name a module that the browser imports. With the engine's Vite plugin, a production build bundles the module that `new URL('./file.ts', import.meta.url)` names into a chunk of its own, with its imports. A development server compiles a TypeScript file on request.
|
|
95
104
|
|
|
96
|
-
The
|
|
105
|
+
The plugin leaves a file under a package's `dist` folder as it is, so a published add-on ships its task already built. That file must run on its own: bundle anything that it imports, or keep it free of imports.
|
|
97
106
|
|
|
98
107
|
## Related pages
|
|
99
108
|
|
package/docs/api/terrain.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/terrain
|
|
3
3
|
title: "Terrain (@null3d/terrain)"
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.2"
|
|
6
4
|
summary: "createTerrain: a height field drawn as a camera-centered quadtree of blocks, lit per pixel from baked normals, with a height-blended splat surface, and heightAt and normalAt for placing objects."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Terrain (@null3d/terrain)
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
The terrain demo.
|
|
12
12
|
|
|
13
13
|
```mermaid
|
|
14
14
|
flowchart LR
|
|
@@ -18,7 +18,9 @@ flowchart LR
|
|
|
18
18
|
splat --> screen["The ground"]
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
The `@null3d/terrain` package draws a height field as terrain. It divides the ground into a quadtree of blocks. A block near the camera draws a fine grid, and a block far away draws a coarse grid over more ground. The ground near the camera then keeps its detail, and the far hills stay cheap.
|
|
21
|
+
The `@null3d/terrain` package draws a height field as terrain. It divides the ground into a quadtree of blocks. A block near the camera draws a fine grid, and a block far away draws a coarse grid over more ground. The ground near the camera then keeps its detail, and the far hills stay cheap.
|
|
22
|
+
|
|
23
|
+
Every pixel takes its normal from a map baked over the whole ground, so a coarse block still shows the relief of the hills. One material blends up to four tiled color layers over every block by a splat map, and each layer's own height shows it through its neighbors where two layers meet.
|
|
22
24
|
|
|
23
25
|
The package is built on the engine's public API. Its surface function ships compiled, so your build does not compile it, and the package needs no extra setup for it.
|
|
24
26
|
|
|
@@ -65,9 +67,11 @@ export default defineSketch((ctx) => {
|
|
|
65
67
|
});
|
|
66
68
|
```
|
|
67
69
|
|
|
70
|
+
[`TerrainOptions`](reference/terrain.md#terrainoptions) lists every option with its default, [`TerrainLayer`](reference/terrain.md#terrainlayer) every layer field, and [`Terrain`](reference/terrain.md#terrain) every member of the object that `createTerrain` returns.
|
|
71
|
+
|
|
68
72
|
## How it works
|
|
69
73
|
|
|
70
|
-
`createTerrain` samples a height field once, into a flat array of heights. The height comes from a function or from a height map
|
|
74
|
+
`createTerrain` samples a height field once, into a flat array of heights. The height comes from a function of x and z, or from a `Float32Array` height map. A map holds `resolution` × `resolution` heights in meters (256 × 256 by default), row by row from the ground's −z edge. [`TerrainOptions`](reference/terrain.md#terrainoptions) lists every option and its default. Later reads, such as `heightAt`, interpolate between the four samples around the point.
|
|
71
75
|
|
|
72
76
|
The ground is a quadtree. The root block covers the whole ground with a coarse grid. A block splits into four while one of its cells would show more screen error than the ground allows.
|
|
73
77
|
|
|
@@ -77,45 +81,59 @@ The `error` option sets the allowed error in pixels. The default follows the qua
|
|
|
77
81
|
|
|
78
82
|
Each block is one mesh whose vertices carry the heights. The height field never changes shape after `createTerrain`. Once a block is made, the engine reuses it. The terrain picks its blocks again when the camera crosses a cell of the finest level, rises by one such cell, or draws through a different lens or buffer size. A still camera therefore costs no work at all.
|
|
79
83
|
|
|
80
|
-
Every pixel lights from a normal map that `createTerrain` bakes from the height field's slopes. A far block covers ground in cells larger than the height samples, so its own vertices cannot show the small hills. The normal map keeps that relief at every distance. Set `bakedNormals: false` to light from the mesh's own normals instead.
|
|
84
|
+
Every pixel lights from a normal map that `createTerrain` bakes from the height field's slopes. A far block covers ground in cells larger than the height samples, so its own vertices cannot show the small hills. The normal map keeps that relief at every distance. Set `bakedNormals: false` to light from the mesh's own normals instead.
|
|
85
|
+
|
|
86
|
+
A map laid from above stretches into streaks on a steep face, so `steepFaces: true` maps the third layer, the rock, from the sides there, for two more samples of that map.
|
|
81
87
|
|
|
82
|
-
Each block morphs toward its parent block's surface as the camera pulls away. A block hands over to its parent at the distance where the parent's own cell would no longer show the allowed error.
|
|
88
|
+
Each block morphs toward its parent block's surface as the camera pulls away. A block hands over to its parent at the distance where the parent's own cell would no longer show the allowed error. `morph: false` switches each block at once instead.
|
|
83
89
|
|
|
84
90
|
The quadtree is the ground's levels of detail, so each block mesh takes `levels: false`, and the engine plans no levels of its own for it.
|
|
85
91
|
|
|
86
|
-
A skirt hangs from the edge of each block
|
|
92
|
+
A skirt hangs from the edge of each block to close the seam between blocks of different detail. On a very steep seam a thin sliver of skirt can still show.
|
|
93
|
+
|
|
94
|
+
<details>
|
|
95
|
+
<summary>Technical details: the morph and the skirt</summary>
|
|
96
|
+
|
|
97
|
+
Over the last part of the approach, the block's vertices move to the parent grid's heights, so the two surfaces match when the switch comes and the ground does not pop. The parent grid is triangulated the same way, so a block whose morph is complete has exactly the parent's surface. The morph adds no draw and no work in a frame: each block carries the parent's height at each vertex in its own vertex record, written when the block is built or reused.
|
|
98
|
+
|
|
99
|
+
The selection does not restrict neighbors, so two blocks that meet can differ by more than one level. The morph ends on a block's own parent, which cannot match a neighbor two levels coarser, so the skirt still covers that seam.
|
|
100
|
+
|
|
101
|
+
</details>
|
|
87
102
|
|
|
88
103
|
## Layers and the splat map
|
|
89
104
|
|
|
90
105
|
The ground's material blends up to four layers. Each layer is a tiled color map with its own repeat distance and roughness. A splat map, one channel per layer, gives the weight of each layer at each point.
|
|
91
106
|
|
|
92
|
-
A layer also carries a height at each texel. Its map's brightness gives that height by default, or its alpha channel where `heightFrom` says `'alpha'`. The four maps that `terrainTextures` makes keep a height in their alpha channel, so give their layers `heightFrom: 'alpha'`. At a boundary between two layers, the heights push one through the other.
|
|
107
|
+
A layer also carries a height at each texel. Its map's brightness gives that height by default, or its alpha channel where `heightFrom` says `'alpha'`. The four maps that `terrainTextures` makes keep a height in their alpha channel, so give their layers `heightFrom: 'alpha'`. At a boundary between two layers, the heights push one through the other.
|
|
108
|
+
|
|
109
|
+
Rock then shows through the grass in ragged patches rather than in a smooth cross-fade. `contrast` sets how strongly a layer's height scales its weight, from 0 to 1. The default is 1, and 0 blends by the splat map's weights alone.
|
|
93
110
|
|
|
94
|
-
The default splat map comes from the ground itself. Grass takes the low, gentle ground, soil the higher dry ground, rock the steep slopes, and snow the ground above. Give `splat` to
|
|
111
|
+
The default splat map comes from the ground itself. Grass takes the low, gentle ground, soil the higher dry ground, rock the steep slopes, and snow the ground above. Give `splat`, a function of x and z that writes the four layer weights into `out`, to set the weights yourself. `terrainTextures` makes the four layer maps in code, or give any `Texture` from `textures.fromData` or `assets`.
|
|
95
112
|
|
|
96
113
|
## Placing things on the ground
|
|
97
114
|
|
|
98
115
|
The terrain carries no collision. Read `heightAt(x, z)` and `normalAt(x, z, out)` to place anything that stands on the ground, and to set its upright direction. Both allocate nothing, so a frame may call them freely.
|
|
99
116
|
|
|
117
|
+
## Hiding and tinting the ground
|
|
118
|
+
|
|
119
|
+
`terrain.setVisible(false)` hides the ground, and `setVisible(true)` shows the current selection again. `terrain.setTint(color)` multiplies the ground's own colors, white by default, so a scene can take the ground down with the hour at night without changing its day look.
|
|
120
|
+
|
|
100
121
|
## Speed
|
|
101
122
|
|
|
102
|
-
A terrain draws one mesh per visible block. The blocks near the camera are the most and the finest, and the few coarse blocks cover the rest. A 1,200 meter ground at the default settings draws about 200 blocks, near 130,000 triangles, from a camera near the ground. That figure is for a picture 1,080 pixels tall. A taller picture draws more and finer blocks, and a shorter one draws fewer.
|
|
123
|
+
A terrain draws one mesh per visible block. The blocks near the camera are the most and the finest, and the few coarse blocks cover the rest. A 1,200 meter ground at the default settings draws about 200 blocks, near 130,000 triangles, from a camera near the ground. That figure is for a picture 1,080 pixels tall. A taller picture draws more and finer blocks, and a shorter one draws fewer.
|
|
103
124
|
|
|
104
|
-
|
|
125
|
+
A higher camera or a wider field of view draws fewer and coarser blocks, and the Low preset draws coarser blocks than High. A block splits or merges only when the camera moves far enough to need other blocks.
|
|
105
126
|
|
|
106
|
-
|
|
127
|
+
The quadtree selection and the block build run in the add-on's own WebAssembly module. The module runs on the engine's job workers, so `update` only asks for the work. A crossing can need tens of new blocks. The ground draws its last complete selection until the new one is built, and `terrain.building` is true meanwhile. `blocksPerUpdate` caps each task's blocks, at 16 by default.
|
|
128
|
+
|
|
129
|
+
<details>
|
|
130
|
+
<summary>Technical details: how blocks build on the job workers</summary>
|
|
107
131
|
|
|
108
|
-
|
|
132
|
+
The first selection builds every block that it needs, over a few tasks. The arrays that the tasks fill are made once and shared, so the frame path allocates nothing. A block that the view leaves gives up its mesh to the next block that the ground needs. A terrain that follows a moving camera therefore builds meshes only until it holds `maxBlocks` of them.
|
|
109
133
|
|
|
110
|
-
|
|
134
|
+
</details>
|
|
111
135
|
|
|
112
|
-
|
|
113
|
-
| --- | --- |
|
|
114
|
-
| A `PlaneGeometry` with displaced vertices | `createTerrain` with a height function or height map |
|
|
115
|
-
| A quadtree or a library for levels of detail | The add-on's own camera-centered quadtree |
|
|
116
|
-
| A hand-painted ground or per-vertex colors | A splat map that blends four tiled layers |
|
|
117
|
-
| A physics collider or a height lookup on the mesh | `heightAt` and `normalAt` |
|
|
118
|
-
| A vertex morph between levels | A block morphs toward its parent, and a skirt covers a neighbour more than one level away |
|
|
136
|
+
A sketch that never imports `@null3d/terrain` ships no terrain code and starts no terrain work. The package follows the engine's add-on rules: its surface function ships compiled, and the selection and build module loads when a terrain first picks its blocks.
|
|
119
137
|
|
|
120
138
|
## Related pages
|
|
121
139
|
|
|
@@ -124,6 +142,8 @@ three.js has no terrain class. Projects displace a `PlaneGeometry` on the CPU, s
|
|
|
124
142
|
- [Materials](materials.md): the standard material and custom surfaces.
|
|
125
143
|
- [Particles](particles.md): the other add-on of the same kind.
|
|
126
144
|
- [The three.js mapping](../porting/threejs-mapping.md): terrain beside three.js's ways of making ground.
|
|
145
|
+
- [Terrain](https://github.com/null3d-engine/null3d/tree/main/examples/terrain): a 1.2 km valley with grass, soil, rock and snow blended by height and slope.
|
|
146
|
+
- [Used in a large scene](https://github.com/null3d-engine/null3d/tree/main/examples/showcase/island): the Island showcase sets `steepFaces` and passes its own `splat` function.
|
|
127
147
|
|
|
128
148
|
## API reference
|
|
129
149
|
|
package/docs/api/textures.md
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/textures
|
|
3
3
|
title: Textures
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.1"
|
|
6
4
|
summary: "loadTexture options; KTX2 files; fromData; fromImageBitmap; fromCanvas; fromVideo; fromPass."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Textures
|
|
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. Step 0.2 adds `textures.fromPass` and `textures.fromCanvas`, and step 0.3 adds `textures.fromVideo`. Materials cannot sample a cube map yet, so coding agents must not try. A cube map can be a background: [Assets](assets.md) loads one with `assets.loadCubemap`.
|
|
12
|
-
|
|
13
9
|
```mermaid
|
|
14
10
|
flowchart LR
|
|
15
11
|
file["An image file"] -->|"assets.loadTexture:<br/>downloaded and decoded<br/>outside the sketch's frames"| image["A decoded image<br/>(ImageBitmap)"]
|
|
@@ -58,7 +54,7 @@ Every call that makes a texture takes these options:
|
|
|
58
54
|
| Option | Values | Default |
|
|
59
55
|
| --- | --- | --- |
|
|
60
56
|
| `colorSpace` | `'srgb'` for color maps, `'linear'` for data maps | `'srgb'` for images, `'linear'` for data |
|
|
61
|
-
| `wrap` | `'clamp'`, `'repeat'` or `'mirror'`, or `[u, v]` for each axis | `'clamp'
|
|
57
|
+
| `wrap` | `'clamp'`, `'repeat'` or `'mirror'`, or `[u, v]` for each axis | `'clamp'` |
|
|
62
58
|
| `filter` | `'linear'`, or `'nearest'` for sharp texels such as pixel art | `'linear'` |
|
|
63
59
|
| `mipmaps` | True to make mip levels on the GPU | True for images, false for data |
|
|
64
60
|
| `anisotropy` | A whole number from 1 to 16 | 1, which is off |
|
|
@@ -66,8 +62,8 @@ Every call that makes a texture takes these options:
|
|
|
66
62
|
|
|
67
63
|
`loadTexture` also takes `flipY` and `premultipliedAlpha`, which say how the image decodes:
|
|
68
64
|
|
|
69
|
-
- `flipY: true`, the default, puts the image's top row at v = 1, the top of a plane
|
|
70
|
-
- `premultipliedAlpha: true` stores each color multiplied by its alpha
|
|
65
|
+
- `flipY: true`, the default, puts the image's top row at v = 1, the top of a plane. glTF textures use `flipY: false`.
|
|
66
|
+
- `premultipliedAlpha: true` stores each color multiplied by its alpha. It is false by default.
|
|
71
67
|
|
|
72
68
|
An option that the engine does not know, such as `wrap: 'tile'` or `anisotropy: 32`, throws [E1208](../errors/E1208.md).
|
|
73
69
|
|
|
@@ -80,6 +76,11 @@ const bricks = await assets.loadTexture('/tex/bricks.ktx2', { wrap: 'repeat' });
|
|
|
80
76
|
console.log(bricks.format); // 'astc-4x4-unorm' on phones and tablets, 'bc7-rgba-unorm' on most desktop GPUs
|
|
81
77
|
```
|
|
82
78
|
|
|
79
|
+
The engine picks the best compressed format that the device supports: `texture.format` says which one it got, and `texture.bytes` its GPU memory.
|
|
80
|
+
|
|
81
|
+
<details>
|
|
82
|
+
<summary>Technical details: which compressed format each device gets</summary>
|
|
83
|
+
|
|
83
84
|
The engine turns the file's data into the first format on its list that the device supports:
|
|
84
85
|
|
|
85
86
|
| Data in the file | Formats, in order |
|
|
@@ -92,14 +93,16 @@ The engine turns the file's data into the first format on its list that the devi
|
|
|
92
93
|
- Phones and tablets have ASTC and ETC2. Desktop GPUs have BC7, and Macs with Apple chips have all three. A device with none gets `rgba8unorm`.
|
|
93
94
|
- On WebGL2, a device with BC7 gets `bc7-rgba-unorm` for both kinds of data. Some desktop drivers, such as Mesa on Linux, offer ETC2 and ASTC on GPUs without them. They then decode those textures in software on the page's thread, which stalls the page. WebGPU offers a format only where the GPU has it.
|
|
94
95
|
- UASTC HDR data holds colors brighter than white, with no alpha. A device with BC formats gets `bc6h-rgb-ufloat`, at 1 byte per texel. Devices without BC formats, such as the iPad and most phones, get `rgb9e5ufloat`: three 9-bit values with a shared exponent, at 4 bytes per texel. That is half the memory of `rgba16float`, and every device filters it. WebGPU and WebGL2 have no ASTC format for HDR data. The texture is always `linear`.
|
|
96
|
+
|
|
97
|
+
</details>
|
|
98
|
+
|
|
95
99
|
- A texture whose width or height is not a multiple of 4 texels gets `rgba8unorm` too, at 4 to 8 times the memory. HDR data then gets `rgb9e5ufloat`. WebGPU keeps compressed textures in whole blocks of 4 x 4 texels. Development builds warn when a file loads this way. `bunx @null3d/cli assets optimize` writes sides that are whole blocks.
|
|
96
|
-
- `texture.format` says which format the device got, and `texture.bytes` its GPU memory.
|
|
97
100
|
|
|
98
101
|
A KTX2 file takes the texture options above, with these differences:
|
|
99
102
|
|
|
100
103
|
- The texture has the mip levels that the file holds. The GPU cannot make mip levels of compressed texels, so encode the file with them, as `basisu -mipmap` and `toktx --genmipmap` do. `mipmaps: false` keeps level 0 alone.
|
|
101
104
|
- The color space comes from the file, which `basisu` writes as sRGB unless you give it `-linear`. The `colorSpace` option overrides it. HDR data is always linear, so in development builds `colorSpace: 'srgb'` throws E1208 for it.
|
|
102
|
-
- The file's first row goes to v = 0, the bottom of a plane
|
|
105
|
+
- The file's first row goes to v = 0, the bottom of a plane. glTF models expect that order. For a plane, encode the file flipped, as `basisu -y_flip` does. Compressed rows cannot turn over. So in development builds, `flipY: true` throws E1208, and so does `premultipliedAlpha: true`. A production build ignores both.
|
|
103
106
|
- A KTX2 file of several layers makes a texture of several layers. Cube maps, 3D textures and KTX2 files of other formats throw [E1412](../errors/E1412.md).
|
|
104
107
|
- A file whose sides pass `textures.maxSize` throws E1412 before the transcoder runs. So do files of more than 256 layers or more mip levels than the size has. A file of more than 256 MiB of texels in the device's format throws it too.
|
|
105
108
|
- `texture.update` throws E1208 on a texture from a KTX2 file. Load the file again instead.
|
|
@@ -108,7 +111,7 @@ The first KTX2 file starts the transcoder: a worker that runs the official build
|
|
|
108
111
|
|
|
109
112
|
## Images
|
|
110
113
|
|
|
111
|
-
`textures.fromImageBitmap` uploads an image as it is: the image's first row goes to v = 0, the bottom of a plane. To make a texture that stands upright
|
|
114
|
+
`textures.fromImageBitmap` uploads an image as it is: the image's first row goes to v = 0, the bottom of a plane. To make a texture that stands upright on a plane, decode the image with its rows flipped. `assets.loadImageBitmap` does so by default. `createImageBitmap` does so with `imageOrientation: 'flipY'`:
|
|
112
115
|
|
|
113
116
|
```ts
|
|
114
117
|
const canvas = new OffscreenCanvas(256, 64);
|
|
@@ -121,7 +124,11 @@ The image moves to the thread that draws, without a copy, so the sketch can use
|
|
|
121
124
|
|
|
122
125
|
## Canvases
|
|
123
126
|
|
|
124
|
-
`textures.fromCanvas` makes a texture that follows an `OffscreenCanvas` drawn in the sketch, such as a score board, a map or a drawing surface. The canvas's last row goes to v = 0, the bottom of a plane, so the canvas stands upright on a plane as on a page. Its first pixels upload as any image's do.
|
|
127
|
+
`textures.fromCanvas` makes a texture that follows an `OffscreenCanvas` drawn in the sketch, such as a score board, a map or a drawing surface. The canvas's last row goes to v = 0, the bottom of a plane, so the canvas stands upright on a plane as on a page. Its first pixels upload as any image's do. The [screens on a canvas demo](https://github.com/null3d-engine/null3d/tree/main/examples/canvas-screen) paints wall panels and a console this way, each at its own rate.
|
|
128
|
+
|
|
129
|
+

|
|
130
|
+
|
|
131
|
+
Screens painted on canvases.
|
|
125
132
|
|
|
126
133
|
`texture.refresh(rect)` reads the canvas again. Give it the rectangle that changed, in the canvas's own coordinates. The rectangle starts at the column and row of its top-left texel, counted from the canvas's top-left corner, and gives its width and height. Only that rectangle uploads, in the texture's turn and within the frame's upload budget. The rest of the texture keeps its texels. Without a rectangle, the call reads the whole canvas.
|
|
127
134
|
|
|
@@ -186,11 +193,11 @@ The video element's own settings, such as its file format and its cross-origin r
|
|
|
186
193
|
|
|
187
194
|
A texture with `depth` above 1 holds that many layers, up to 256, one after another in `data`. Its layers are a texture array of their own. Materials read its first layer.
|
|
188
195
|
|
|
189
|
-
Data of the wrong length or type for the size and format throws E1208. Data textures have no mip levels unless `mipmaps` is true
|
|
196
|
+
Data of the wrong length or type for the size and format throws E1208. Data textures have no mip levels unless `mipmaps` is true. The [security camera demo](https://github.com/null3d-engine/null3d/tree/main/examples/security-camera) makes its ground maps with `textures.fromData`.
|
|
190
197
|
|
|
191
198
|
## Textures of render passes
|
|
192
199
|
|
|
193
|
-
`textures.fromPass(pass)` returns the texture that a scene pass of `render.addPass` draws into
|
|
200
|
+
`textures.fromPass(pass)` returns the texture that a scene pass of `render.addPass` draws into. Materials and sprites take it as a map.
|
|
194
201
|
|
|
195
202
|
```ts
|
|
196
203
|
const map = render.addPass({ kind: 'scene', camera: mapCamera, writes: 'minimap', size: [256, 256] });
|
|
@@ -221,11 +228,29 @@ A texture's `width`, `height` and `depth` give its size, and `bytes` its GPU mem
|
|
|
221
228
|
|
|
222
229
|
Textures of one size, one format and one number of mip levels share a 2D texture array on the GPU. Each texture takes one layer of the array. Materials whose maps are in one array share one bind group when they sample their maps the same way. The GPU then switches textures less often between draws.
|
|
223
230
|
|
|
224
|
-
An array holds at most 256 layers, the most that an iPad allows, and at most 128 MiB.
|
|
231
|
+
An array holds at most 256 layers, the most that an iPad allows, and at most 128 MiB. When a size has more textures than an array holds, another array holds the rest.
|
|
232
|
+
|
|
233
|
+
<details>
|
|
234
|
+
<summary>Technical details: how texture arrays grow and shrink</summary>
|
|
235
|
+
|
|
236
|
+
An array starts with room for a few textures, at most 8 MiB of them, and doubles its layers when it is full. The GPU copies the old array into the new one, so the textures that it holds keep their texels. For one frame the GPU holds both, so the cap of 128 MiB keeps that extra memory small. When under a quarter of an array's layers hold textures, the array shrinks, and its textures move to its lowest layers.
|
|
237
|
+
|
|
238
|
+
A texture from data with several layers has an array of its own, with exactly its layers. So does a texture in a compressed format, because WebGPU's compatibility mode cannot copy compressed texels into a larger array. A texture in `rgb9e5ufloat` has one too, because WebGL2 cannot copy that format.
|
|
239
|
+
|
|
240
|
+
</details>
|
|
225
241
|
|
|
226
242
|
Textures of many different sizes need many arrays. Give the textures of a scene a few common sizes where you can, such as 512 x 512 and 1024 x 1024. An update with an image of another size moves the texture to the array of that size.
|
|
227
243
|
|
|
228
|
-
WebGL2
|
|
244
|
+
On WebGL2, one standard material samples its maps through at most six texture units. Maps in one array that sample the same way share one unit, and each compressed map takes a unit of its own. A glTF material needs more than six only when its seven maps all differ in size, format or sampling. Past six, the material draws without the maps that change its look least.
|
|
245
|
+
|
|
246
|
+
<details>
|
|
247
|
+
<summary>Technical details: which maps WebGL2 drops first</summary>
|
|
248
|
+
|
|
249
|
+
WebGL2 promises each shader stage only 16 textures, so on WebGL2 the maps of one standard material share at most six. A material whose color maps have one size and whose data maps have one size takes two units. Past six, a material draws without the maps that change its look least.
|
|
250
|
+
|
|
251
|
+
It drops its specular intensity map first, then its specular color map, then its light map. A material that lets light through keeps its transmission map in the specular intensity map's place and its thickness map in the specular color map's, so they drop in that same order.
|
|
252
|
+
|
|
253
|
+
</details>
|
|
229
254
|
|
|
230
255
|
A texture can be at most 4096 texels wide and tall, the most that every WebGPU device allows. On a WebGL2 device that allows less, the device's own limit applies: at least 2048 texels. `textures.maxSize` gives the limit, and a larger image throws E1208.
|
|
231
256
|
|
|
@@ -233,7 +258,9 @@ A texture can be at most 4096 texels wide and tall, the most that every WebGPU d
|
|
|
233
258
|
|
|
234
259
|
An image decodes off the main thread into an `ImageBitmap`, and then moves to the thread that draws without a copy. In the default pipelined mode, that thread is the render worker. Data goes into the engine's memory, which that thread reads.
|
|
235
260
|
|
|
236
|
-
The engine spreads uploads over frames, so loading many textures does not make one frame slow. Each frame uploads no more texel bytes than the upload budget, the `uploadBytesPerFrame` setting of the [quality preset](../concepts/quality-presets.md#the-settings-of-each-preset). A large texture goes up in bands of rows, one band per frame. Textures upload in the order that they got their texels.
|
|
261
|
+
The engine spreads uploads over frames, so loading many textures does not make one frame slow. Each frame uploads no more texel bytes than the upload budget, the `uploadBytesPerFrame` setting of the [quality preset](../concepts/quality-presets.md#the-settings-of-each-preset). A large texture goes up in bands of rows, one band per frame. Textures upload in the order that they got their texels.
|
|
262
|
+
|
|
263
|
+
The engine frees its copy of data once the upload is done. Texels from a KTX2 file go into the engine's memory as data does. They go up in bands of rows of blocks, each mip level in turn.
|
|
237
264
|
|
|
238
265
|
Until its texels are on the GPU, a texture draws as if the material had no map. A material then shows its base color alone.
|
|
239
266
|
|
|
@@ -241,21 +268,41 @@ Until its texels are on the GPU, a texture draws as if the material had no map.
|
|
|
241
268
|
|
|
242
269
|
Mip levels are smaller copies of a texture. The GPU reads them where the texture covers few pixels on screen, so distant textures do not shimmer. The engine makes each texture's mip levels on the GPU, after its texels upload. Each level is the average of the level above it, in linear color. Textures in `rgba16float` have no mip levels. A texture from a KTX2 file has the mip levels of its file.
|
|
243
270
|
|
|
271
|
+

|
|
272
|
+
|
|
273
|
+
Mip levels and anisotropic filtering.
|
|
274
|
+
|
|
244
275
|
## Sampling
|
|
245
276
|
|
|
246
277
|
Each texture has its own sampler settings, from its options:
|
|
247
278
|
|
|
248
|
-
- What texture coordinates outside 0 to 1 read along each axis: the texel at the edge, a repeat of the texture, or a mirrored repeat. By default the edge texel repeats outward
|
|
279
|
+
- What texture coordinates outside 0 to 1 read along each axis: the texel at the edge, a repeat of the texture, or a mirrored repeat. By default the edge texel repeats outward.
|
|
249
280
|
- The filter of magnified texels, of minified texels and between mip levels: linear or nearest. It is linear by default.
|
|
250
281
|
- Anisotropic filtering, which keeps a texture sharp on a surface seen at a slant, such as a floor. It reaches at most 16 samples, or the quality preset's cap (`maxAnisotropy`) when that is lower. A nearest filter turns it off. It is off by default.
|
|
251
282
|
|
|
283
|
+

|
|
284
|
+
|
|
285
|
+
Wrap modes and the other texture checks.
|
|
286
|
+
|
|
287
|
+
Materials do not sample cube maps. A cube map can be a background: [Assets](assets.md) loads one with `assets.loadCubemap`.
|
|
288
|
+
|
|
252
289
|
## Color spaces
|
|
253
290
|
|
|
254
291
|
Color maps, such as the base color of a surface, store sRGB colors. The GPU turns their texels into linear values as it samples them, so lighting works in linear color. Data maps, such as normal, roughness and metalness maps, store linear values, which the GPU reads as they are. Choose with the `colorSpace` option. [Color management](../concepts/color-management.md) explains the engine's color spaces.
|
|
255
292
|
|
|
256
293
|
## GPU memory
|
|
257
294
|
|
|
258
|
-
A texture takes the GPU memory of its layers, with every mip level.
|
|
295
|
+
A texture takes the GPU memory of its layers, with every mip level.
|
|
296
|
+
|
|
297
|
+
| Format | Bytes per texel |
|
|
298
|
+
| --- | --- |
|
|
299
|
+
| `rgba8unorm` | 4 |
|
|
300
|
+
| `rgba16float` | 8 |
|
|
301
|
+
| `rgb9e5ufloat` | 4 |
|
|
302
|
+
| Compressed | 1 |
|
|
303
|
+
| `etc2-rgb8unorm` | 0.5 |
|
|
304
|
+
|
|
305
|
+
The mip levels add a third to the image: a texture of 1024 x 1024 texels, at 4 bytes each, takes about 5.3 MiB. The same texture from a KTX2 file then takes about 1.3 MiB or 0.7 MiB. An array also holds its free layers. The count in `textures.memoryBytes` holds them too. It also holds an array's old GPU texture after the array grows or shrinks, until the next frame frees it.
|
|
259
306
|
|
|
260
307
|
The quality preset's texture memory budget, `textureMemoryMiB`, caps the GPU memory of every texture. Past it, the engine drops the largest mip levels of textures from files, and loads them again when room returns. Each texture's `droppedLevels` gives the levels that it lost, from 0 to 3. Its `width` and `height` keep its own size, and its `bytes` give the memory that it takes now. [Quality presets](../concepts/quality-presets.md#texture-memory) explains the order of the drops.
|
|
261
308
|
|
|
@@ -265,7 +312,9 @@ WebGPU and WebGL2 store, upload and sample textures the same way, and make the s
|
|
|
265
312
|
|
|
266
313
|
## When the browser takes the GPU away
|
|
267
314
|
|
|
268
|
-
When the browser takes the GPU away, the engine starts a new device and uploads the texels that it still holds. A texture from a file loads its file again. On a phone or a tablet the engine also keeps its copy of an image or of data after their upload, so the texture draws with its map again.
|
|
315
|
+
When the browser takes the GPU away, the engine starts a new device and uploads the texels that it still holds. A texture from a file loads its file again. On a phone or a tablet the engine also keeps its copy of an image or of data after their upload, so the texture draws with its map again.
|
|
316
|
+
|
|
317
|
+
The `keepTextureCopies` option of `createEngine` turns that on or off on any device ([Page API](engine.md#options)). Keeping the copies costs about one more copy of each image in memory. Where the engine keeps no copy, a texture whose texels it released draws without its map until the texture gets an update.
|
|
269
318
|
|
|
270
319
|
## API reference
|
|
271
320
|
|
package/docs/api/three-compat.md
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/three-compat
|
|
3
|
-
title: three.js
|
|
4
|
-
|
|
5
|
-
since: "0.3"
|
|
6
|
-
summary: "Reinhard and Cineon tone curves for post.set, and an outline with three.js OutlinePass's glow, pulse and blurred edge."
|
|
3
|
+
title: three.js looks (@null3d/three-compat)
|
|
4
|
+
summary: "Reinhard and Cineon tone curves for post.set, and an outline with three.js OutlinePass's glow, pulse and blurred edge. It runs no three.js code."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
|
-
# three.js
|
|
10
|
-
|
|
11
|
-
> Roadmap step 0.3, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
|
|
7
|
+
# three.js looks (@null3d/three-compat)
|
|
12
8
|
|
|
13
9
|
```mermaid
|
|
14
10
|
flowchart LR
|
|
@@ -21,6 +17,18 @@ flowchart LR
|
|
|
21
17
|
|
|
22
18
|
The engine's core holds the looks that most scenes use. This add-on holds the few three.js looks that a port asks for. They are Reinhard's and Cineon's tone curves, and the soft outline of three.js's `OutlinePass`, with its glow, its pulse and its blurred edge. It uses only the engine's public API.
|
|
23
19
|
|
|
20
|
+
## What it is not
|
|
21
|
+
|
|
22
|
+
The add-on is not a compatibility layer. It holds the two tone curves and the outline, and nothing more. It does not run three.js code, and it takes no three.js scene, object, material, shader or pass.
|
|
23
|
+
|
|
24
|
+
A port of a three.js scene is a rewrite in null3D's own API, with or without this add-on:
|
|
25
|
+
|
|
26
|
+
- The scene code moves into a sketch, which runs in a worker. Objects are handles with setters, and many similar objects are rows of a batch that typed arrays fill.
|
|
27
|
+
- GLSL becomes WGSL. A `ShaderMaterial` or an `onBeforeCompile` patch becomes a surface function, an unlit function or a vertex offset ([Porting shaders](../porting/threejs-shaders.md)).
|
|
28
|
+
- An `EffectComposer` chain becomes `post.set` settings, with `post.addEffect` for each custom pass ([Porting post-processing](../porting/threejs-postprocessing.md)).
|
|
29
|
+
|
|
30
|
+
[Porting from three.js](../porting/threejs-overview.md#a-port-is-a-rewrite) gives the workflow and the limits that a port meets.
|
|
31
|
+
|
|
24
32
|
Install it beside the engine:
|
|
25
33
|
|
|
26
34
|
```sh
|
package/docs/api/time.md
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/time
|
|
3
3
|
title: Time
|
|
4
|
-
status: experimental
|
|
5
|
-
since: "0.1"
|
|
6
4
|
summary: "dt, time.now, fixed steps."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Time
|
|
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
|
The engine calls the sketch's `onUpdate` callback once per frame. Its argument, `dt`, is the frame's step: the time in seconds since the sketch's previous frame. The `time` object in the sketch's context holds the sketch time, the frame's step and the frame number. Simulation that must step the same at every frame rate runs in fixed steps instead, in `onFixedUpdate`.
|
|
14
10
|
|
|
15
11
|
Sketch time is the sum of every frame's step. Time while the engine is paused or the page is hidden does not count, so the sketch never jumps over a pause.
|
|
@@ -62,7 +58,7 @@ In hold mode, the first frame gets 0 and each later frame gets 1/60 second. The
|
|
|
62
58
|
| `time.now` | Sketch time in seconds: the sum of every frame's step. It is 0 during the setup function. |
|
|
63
59
|
| `time.dt` | The frame's step in seconds: the `dt` that `onUpdate` and `onLateUpdate` get. It is 0 during the setup function. |
|
|
64
60
|
| `time.frame` | The frame number: 0 during the setup function, 1 in the first frame, and one more in each frame after it. |
|
|
65
|
-
| `time.held` | True while hold mode steps to its held frame, and false otherwise. Work on a cadence reads it to draw in every frame, so a held frame never lands between two of its draws. |
|
|
61
|
+
| `time.held` | True while hold mode steps to its held frame, and false otherwise. Work on a cadence reads it to draw in every frame, so a held frame never lands between two of its draws. Unlike `engine.held`, it is false in the setup function and in a replay. |
|
|
66
62
|
| `time.drawn` | False in a step of hold mode whose frame the GPU never draws, and true in every other frame. Hold mode draws only the frames at the end of its hold. Work that a frame's GPU passes pay for, such as a solver's runs for the time that passed, waits for a frame that draws, so the held frame carries the whole hold's work once. |
|
|
67
63
|
|
|
68
64
|
The engine updates the fields at the start of each frame, before it calls `onFixedUpdate`, so `time.now` already includes the frame's step. The fields keep their values until the next frame, in every callback. In hold mode, `time.now` in the last frame is the held time exactly.
|
|
@@ -128,6 +124,8 @@ A fixed factor per frame, such as `current += (goal - current) * 0.1`, moves fas
|
|
|
128
124
|
- [Page API: createEngine](engine.md): `setPaused`, `detach` and `attach`, which pause and resume the sketch's frames.
|
|
129
125
|
- [Math helpers](math.md): `math.damp`, `math.lerp` and `vec3.lerp`.
|
|
130
126
|
- [Testing your sketch](../guides/testing.md): hold mode's fixed steps.
|
|
127
|
+
- [Hold mode](https://github.com/null3d-engine/null3d/tree/main/examples/hold-mode): a held frame that every run draws the same.
|
|
128
|
+
- [Easing at any frame rate](https://github.com/null3d-engine/null3d/tree/main/examples/math): 300 drones that follow a lamp at their own lag and speed.
|
|
131
129
|
|
|
132
130
|
## API reference
|
|
133
131
|
|