@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/geometry.md
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/geometry
|
|
3
3
|
title: Geometry
|
|
4
|
-
|
|
5
|
-
since: "0.1"
|
|
6
|
-
summary: "Generators with three.js parameters; extra shapes in @null3d/geometry; meshes from arrays; morph targets; vertices that change; levels of detail that meshes plan on the job workers; vertex formats; large meshes."
|
|
4
|
+
summary: "Generators of common shapes; extra shapes in @null3d/geometry; meshes from arrays; morph targets; vertices that change; levels of detail that meshes plan on the job workers; vertex formats; large meshes."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Geometry
|
|
10
8
|
|
|
11
|
-
>
|
|
9
|
+
> No call skins a mesh that you build, so its joints and weights do not move its vertices.
|
|
12
10
|
|
|
13
11
|
```mermaid
|
|
14
12
|
flowchart LR
|
|
@@ -21,11 +19,15 @@ flowchart LR
|
|
|
21
19
|
mesh --> objects["scene.createMesh()<br/>scene.createInstances()"]
|
|
22
20
|
```
|
|
23
21
|
|
|
24
|
-
A mesh is the shape that objects draw. `ctx.geometry` makes meshes, and any number of objects and instance batches can share one mesh. The generators make common shapes
|
|
22
|
+
A mesh is the shape that objects draw. `ctx.geometry` makes meshes, and any number of objects and instance batches can share one mesh. The generators make common shapes from named options. `geometry.fromArrays` makes a mesh from your own vertex data.
|
|
25
23
|
|
|
26
24
|
## Generators
|
|
27
25
|
|
|
28
|
-
Each generator takes
|
|
26
|
+
Each generator takes named options. An option that you leave out takes its default.
|
|
27
|
+
|
|
28
|
+

|
|
29
|
+
|
|
30
|
+
The geometry generators.
|
|
29
31
|
|
|
30
32
|
```ts
|
|
31
33
|
// sketch.ts
|
|
@@ -35,31 +37,35 @@ const pillar = geometry.cylinder({ radiusTop: 0.3, radiusBottom: 0.4, height: 2
|
|
|
35
37
|
scene.createMesh({ mesh: crate, material: materials.standard({ color: '#c8a064' }) });
|
|
36
38
|
```
|
|
37
39
|
|
|
38
|
-
| Generator |
|
|
39
|
-
| --- | --- |
|
|
40
|
-
| `geometry.box` |
|
|
41
|
-
| `geometry.sphere` |
|
|
42
|
-
| `geometry.plane` |
|
|
43
|
-
| `geometry.cylinder` |
|
|
44
|
-
| `geometry.cone` |
|
|
45
|
-
| `geometry.torus` |
|
|
46
|
-
| `geometry.capsule` |
|
|
47
|
-
| `geometry.circle` |
|
|
48
|
-
| `geometry.ring` |
|
|
40
|
+
| Generator | Shape |
|
|
41
|
+
| --- | --- |
|
|
42
|
+
| `geometry.box` | A box |
|
|
43
|
+
| `geometry.sphere` | A sphere with its poles on the Y axis, or a part of one |
|
|
44
|
+
| `geometry.plane` | A rectangle in the XY plane that faces +Z |
|
|
45
|
+
| `geometry.cylinder` | A cylinder on the Y axis, closed at each end unless `openEnded` is true |
|
|
46
|
+
| `geometry.cone` | A cone on the Y axis, with its point at the top |
|
|
47
|
+
| `geometry.torus` | A tube bent into a ring around the Z axis |
|
|
48
|
+
| `geometry.capsule` | A cylinder on the Y axis with a half sphere on each end |
|
|
49
|
+
| `geometry.circle` | A disc in the XY plane that faces +Z, or a slice of one |
|
|
50
|
+
| `geometry.ring` | A disc with a hole, in the XY plane, that faces +Z |
|
|
49
51
|
|
|
50
|
-
Every shape is centered on its origin. The
|
|
52
|
+
Every shape is centered on its origin. The API reference below gives each option and its default. Angles are in radians. Segment counts round down to whole numbers. Each count has a least, which the API reference gives, and a smaller count rises to it. A sphere, for example, has at least 3 segments around it.
|
|
51
53
|
|
|
52
|
-
The generators give each vertex a position, a normal and texture coordinates
|
|
54
|
+
The generators give each vertex a position, a normal and texture coordinates. The [geometry generators demo](https://github.com/null3d-engine/null3d/tree/main/examples/generators) draws all nine shapes.
|
|
53
55
|
|
|
54
56
|
## Extra shapes
|
|
55
57
|
|
|
56
|
-
The `@null3d/geometry` package holds the
|
|
58
|
+
The `@null3d/geometry` package holds more shapes, and the curves and outlines that build them. Install it beside the engine:
|
|
59
|
+
|
|
60
|
+

|
|
61
|
+
|
|
62
|
+
Extra shapes from @null3d/geometry.
|
|
57
63
|
|
|
58
64
|
```sh
|
|
59
65
|
bun add @null3d/geometry
|
|
60
66
|
```
|
|
61
67
|
|
|
62
|
-
Each function takes
|
|
68
|
+
Each function takes named options, and an option that you leave out takes its default. It returns arrays for `geometry.fromArrays`. The arrays hold a position, a normal and texture coordinates for each vertex, and indices for some shapes. The mesh that `fromArrays` makes from them plans its [levels of detail](#levels-of-detail) as any mesh made in code does, and keeps its vertices in their order.
|
|
63
69
|
|
|
64
70
|
```ts
|
|
65
71
|
// sketch.ts
|
|
@@ -70,23 +76,23 @@ const outline = new Shape().moveTo(0, 0).lineTo(1, 0).lineTo(0.5, 1).lineTo(0, 0
|
|
|
70
76
|
const wedge = geometry.fromArrays(extrude({ shapes: outline, depth: 0.4, bevelEnabled: false }));
|
|
71
77
|
```
|
|
72
78
|
|
|
73
|
-
| Function |
|
|
74
|
-
| --- | --- |
|
|
75
|
-
| `torusKnot` |
|
|
76
|
-
| `tetrahedron`, `octahedron`, `icosahedron`, `dodecahedron` |
|
|
77
|
-
| `polyhedron` |
|
|
78
|
-
| `lathe` |
|
|
79
|
-
| `shape` |
|
|
80
|
-
| `extrude` |
|
|
81
|
-
| `tube` |
|
|
79
|
+
| Function | Shape |
|
|
80
|
+
| --- | --- |
|
|
81
|
+
| `torusKnot` | A tube that winds around a torus |
|
|
82
|
+
| `tetrahedron`, `octahedron`, `icosahedron`, `dodecahedron` | A polyhedron, with `detail` that splits its faces toward a sphere |
|
|
83
|
+
| `polyhedron` | A polyhedron from your own corners and faces |
|
|
84
|
+
| `lathe` | A profile of points turned around the Y axis, such as a vase |
|
|
85
|
+
| `shape` | A flat shape from outlines, with holes, in the XY plane |
|
|
86
|
+
| `extrude` | A shape pushed along +Z or along a curve, with an optional bevel |
|
|
87
|
+
| `tube` | A tube along a 3D curve |
|
|
82
88
|
|
|
83
|
-
The package also has the classes that these shapes take
|
|
89
|
+
The package also has the classes that these shapes take. `Shape` and `Path` draw with `moveTo`, `lineTo`, `bezierCurveTo` and the rest. The 2D and 3D curves, such as `CatmullRomCurve3`, and `ShapeUtils` come too. Points are arrays of numbers, `[x, y]` or `[x, y, z]`. A method that returns a point returns a new array, or fills the array that you pass last.
|
|
84
90
|
|
|
85
|
-
A mesh has one material
|
|
91
|
+
A mesh has one material, and an extrusion's caps and sides form one mesh. To give the caps a material of their own, make them as a second mesh with `shape`, at each end. The [extra shapes demo](https://github.com/null3d-engine/null3d/tree/main/examples/extra-shapes) draws a shape from each function.
|
|
86
92
|
|
|
87
93
|
## Meshes from arrays
|
|
88
94
|
|
|
89
|
-
`geometry.fromArrays` takes one array per vertex attribute
|
|
95
|
+
`geometry.fromArrays` takes one flat array per vertex attribute: the values of vertex 0, then vertex 1, and so on. Typed arrays and plain arrays of numbers both work. An attribute can also come as 8-bit or 16-bit integers, as [integer attributes](#integer-attributes) shows.
|
|
90
96
|
|
|
91
97
|
```ts
|
|
92
98
|
// sketch.ts: a quad that faces +z, with texture coordinates
|
|
@@ -99,24 +105,25 @@ const quad = geometry.fromArrays({
|
|
|
99
105
|
scene.createMesh({ mesh: quad, material: materials.unlit({ color: '#ffffff' }) });
|
|
100
106
|
```
|
|
101
107
|
|
|
102
|
-
| Array | Numbers per vertex |
|
|
103
|
-
| --- | --- |
|
|
104
|
-
| `positions` | 3 |
|
|
105
|
-
| `normals` | 3 |
|
|
106
|
-
| `uvs` | 2 |
|
|
107
|
-
| `uvs1` | 2, such as a light map's coordinates |
|
|
108
|
-
| `colors` | 3, or 4 with alpha, as linear values from 0 to 1 |
|
|
109
|
-
| `tangents` | 4: the direction in which u grows, then 1 or -1 for the direction of v |
|
|
110
|
-
| `joints` | 4 joint indices, for skinned meshes |
|
|
111
|
-
| `weights` | 4: how much each joint moves the vertex, which add up to 1 |
|
|
112
|
-
| `targets` | 4
|
|
108
|
+
| Array | Numbers per vertex |
|
|
109
|
+
| --- | --- |
|
|
110
|
+
| `positions` | 3 |
|
|
111
|
+
| `normals` | 3 |
|
|
112
|
+
| `uvs` | 2 |
|
|
113
|
+
| `uvs1` | 2, such as a light map's coordinates |
|
|
114
|
+
| `colors` | 3, or 4 with alpha, as linear values from 0 to 1 |
|
|
115
|
+
| `tangents` | 4: the direction in which u grows, then 1 or -1 for the direction of v |
|
|
116
|
+
| `joints` | 4 joint indices, for skinned meshes |
|
|
117
|
+
| `weights` | 4: how much each joint moves the vertex, which add up to 1 |
|
|
118
|
+
| `targets` | 4 numbers that a custom material's vertex offset reads, such as the position that the vertex takes at the next coarser level and that level's error |
|
|
113
119
|
|
|
114
120
|
The arrays follow these rules:
|
|
115
121
|
|
|
116
122
|
- `positions` is required. Give `normals`, or set `computeNormals: true`.
|
|
117
123
|
- `indices` takes a `Uint16Array`, a `Uint32Array` or an array of numbers, with three indices per triangle. Without indices, each three vertices in a row make one triangle.
|
|
118
|
-
- `joints` and `weights` come together. A mesh keeps them for [skinning](animation.md#skinned-meshes).
|
|
124
|
+
- `joints` and `weights` come together. A mesh keeps them for [skinning](animation.md#skinned-meshes). A mesh that you build draws in the pose that its positions give.
|
|
119
125
|
- `targets` takes floats only, and a mesh takes it or `morphTargets`, never both: the two share one vertex record.
|
|
126
|
+
- `targets` is for a shape whose material moves its vertices between levels of detail, as the [terrain](terrain.md#how-it-works) does. The material's vertex offset reads the four numbers as `input.vertexRecord` ([Vertex offsets](../shaders/surface-functions.md#vertex-offsets)). Leave it out unless your vertex offset reads it.
|
|
120
127
|
- A triangle's front face has its vertices in counter-clockwise order.
|
|
121
128
|
- Each array's length must fit the vertex count, and its type must be one that its attribute takes. Each index must name a vertex, and each value must be a finite number. Otherwise the call throws [E1206](../errors/E1206.md).
|
|
122
129
|
- The engine copies the arrays. You can change or drop them after the call.
|
|
@@ -125,7 +132,7 @@ The arrays follow these rules:
|
|
|
125
132
|
|
|
126
133
|
Each attribute can come as 8-bit or 16-bit integers instead of 32-bit floats, as glTF's `KHR_mesh_quantization` extension allows. The mesh keeps the integers on the GPU, so it takes less memory and uploads faster. A position of 16-bit integers takes 8 bytes, where floats take 12. A normal of 8-bit integers takes 4 bytes, where floats take 12.
|
|
127
134
|
|
|
128
|
-
Integers read in one of two ways. Normalized integers read as fractions: from 0 to 1 when they are unsigned, and from -1 to 1 when they are signed. Plain integers read as whole numbers. Give an attribute as `{ array, normalized }` to choose
|
|
135
|
+
Integers read in one of two ways. Normalized integers read as fractions: from 0 to 1 when they are unsigned, and from -1 to 1 when they are signed. Plain integers read as whole numbers. Give an attribute as `{ array, normalized }` to choose. The default is plain, as in glTF.
|
|
129
136
|
|
|
130
137
|
| Array | Takes | Integers read as |
|
|
131
138
|
| --- | --- | --- |
|
|
@@ -152,13 +159,19 @@ Integer positions keep their own units. Give the object the scale and the positi
|
|
|
152
159
|
|
|
153
160
|
## Computing normals and tangents
|
|
154
161
|
|
|
155
|
-
`computeNormals: true` computes the normals
|
|
162
|
+
`computeNormals: true` computes the normals from the triangles. Each vertex gets the average of the normals of its triangles, weighted by their areas. Vertices that triangles share get smooth normals. For hard edges, give each face its own vertices. The [meshes from arrays demo](https://github.com/null3d-engine/null3d/tree/main/examples/mesh-arrays) shows both: a smooth height field, an island with a color at each vertex, and a crystal with hard edges.
|
|
156
163
|
|
|
157
|
-
|
|
164
|
+

|
|
165
|
+
|
|
166
|
+
Meshes from arrays.
|
|
167
|
+
|
|
168
|
+
`computeTangents: true` computes tangents from the positions, the normals and `uvs`, with Eric Lengyel's method. It needs `uvs`, and it works with or without indices. The job workers share the work, so a large mesh takes less time. Both options compute from integer positions, normals and texture coordinates too, as shaders read them, and give 32-bit floats.
|
|
158
169
|
|
|
159
170
|
## Morph targets
|
|
160
171
|
|
|
161
|
-
A morph target is another shape of a mesh, such as a smile on a face. The `morphTargets` option gives a mesh its targets, as
|
|
172
|
+
A morph target is another shape of a mesh, such as a smile on a face. The `morphTargets` option gives a mesh its targets, as glTF stores them. Each target is an array of three numbers per vertex: how far the target moves the vertex at weight 1. The list `positions` moves the vertices, `normals` turns their normals, and `tangents` turns their tangents.
|
|
173
|
+
|
|
174
|
+
The list `colors` changes the mesh's vertex colors, with as many numbers per vertex as `colors` has, three or four. Every list holds the same number of targets, from 1 to 256. The list `names` names the targets.
|
|
162
175
|
|
|
163
176
|
```ts
|
|
164
177
|
const count = positions.length / 3;
|
|
@@ -175,11 +188,26 @@ const head = scene.createMesh({ mesh: face, material });
|
|
|
175
188
|
head.setMorphWeight('Smile', 0.8);
|
|
176
189
|
```
|
|
177
190
|
|
|
178
|
-
Each object of the mesh has weights of its own, which start at 0. `setMorphWeight` sets them, and clips from glTF files animate them ([Morph targets](animation.md#morph-targets)). The [morph targets demo](https://github.com/null3d-engine/null3d/tree/main/examples/morph-flowers) makes tulips with one target, which opens the petals, turns their normals and changes their color. Each tulip has a weight of its own.
|
|
191
|
+
Each object of the mesh has weights of its own, which start at 0. `setMorphWeight` sets them, and clips from glTF files animate them ([Morph targets](animation.md#morph-targets)). The [morph targets demo](https://github.com/null3d-engine/null3d/tree/main/examples/morph-flowers) makes tulips with one target, which opens the petals, turns their normals and changes their color. Each tulip has a weight of its own.
|
|
192
|
+
|
|
193
|
+
The targets of a mesh have size limits. Past them, `fromArrays` throws [E1206](../errors/E1206.md).
|
|
194
|
+
|
|
195
|
+
<details>
|
|
196
|
+
<summary>Technical details: how morph targets are stored</summary>
|
|
197
|
+
|
|
198
|
+
The engine stores, for each vertex, only the targets that move it. So a face whose targets each move a small part of it takes far less memory than a copy of every vertex for every target. A vertex can take up to 255 targets.
|
|
199
|
+
|
|
200
|
+
The targets of every mesh together can take up to 4,194,304 deltas, 32 MiB of GPU memory. Each of a vertex's positions, normals, tangents and colors counts once. The GPU keeps each delta in a 16-bit float, which is exact to 1/2048 of the delta's size, and each weight in a 32-bit float. A morphed color stays between 0 and 1, as the glTF specification asks.
|
|
201
|
+
|
|
202
|
+
</details>
|
|
179
203
|
|
|
180
204
|
## Vertices that change
|
|
181
205
|
|
|
182
|
-
`mesh.updateVertices(name, values, start, count)` writes new values into one attribute of a mesh
|
|
206
|
+
`mesh.updateVertices(name, values, start, count)` writes new values into one attribute of a mesh. Keep the arrays that you made the mesh with, change them, and pass them again:
|
|
207
|
+
|
|
208
|
+

|
|
209
|
+
|
|
210
|
+
updateVertices every frame.
|
|
183
211
|
|
|
184
212
|
```ts
|
|
185
213
|
// sketch.ts: a sheet whose middle rows rise and fall
|
|
@@ -198,14 +226,16 @@ The call follows these rules:
|
|
|
198
226
|
|
|
199
227
|
- `name` is `positions`, `normals`, `uvs`, `uvs1`, `colors` or `tangents`, and the mesh must have that attribute. Colors take three or four numbers per vertex. Three keep each vertex's alpha.
|
|
200
228
|
- `values` holds the values of every vertex, in the array type that the mesh was made with. That is a `Float32Array` or a plain array for floats, or the same integer array.
|
|
201
|
-
- `start` and `count` pick the vertices that change
|
|
229
|
+
- `start` and `count` pick the vertices that change. By default every vertex changes. The next frame uploads only the bytes of those vertices.
|
|
202
230
|
- Values that do not fit the mesh throw [E1206](../errors/E1206.md), and so does a mesh with joints or morph targets.
|
|
203
231
|
- The first call takes away the levels of detail that the mesh planned, which measured the old shape, and the mesh plans no levels on its own again. Give a mesh whose vertices change in every frame `levels: false`, so it plans none.
|
|
204
|
-
- The call allocates nothing, so a call in every frame makes no garbage.
|
|
232
|
+
- The call allocates nothing, so a call in every frame makes no garbage. The engine's allocation benchmark checks it in every frame.
|
|
205
233
|
|
|
206
234
|
Change the normals with the positions when the shape changes, because the engine does not compute them again. The [vertex updates demo](https://github.com/null3d-engine/null3d/tree/main/examples/vertex-updates) moves rings over a pool of water this way.
|
|
207
235
|
|
|
208
|
-
The mesh keeps the bounding sphere of the vertices that it was made with
|
|
236
|
+
The mesh keeps the bounding sphere of the vertices that it was made with. Culling tests that sphere. When the new vertices reach outside it, give each object that draws the mesh bounds that hold every shape, with [`setBounds`](objects.md#mesh-calls). Raycasts and overlap queries always test the new vertices.
|
|
237
|
+
|
|
238
|
+
The first query after an update builds the mesh's tree again. So a scene that updates a large mesh and raycasts in each frame pays for a build in each frame. Shadows of point and spot lights draw again when a mesh that casts them changes.
|
|
209
239
|
|
|
210
240
|
The first update of a mesh rebuilds the draw tables once, as `setMesh` does, so make it at setup or behind a loading screen. Later updates cost only the copy and the upload. On WebGL2, a mesh whose positions changed no longer hides the objects behind it from software occlusion culling. For many objects that move as wholes, use [instance batches](../concepts/instances.md) instead: they move each object with one matrix, not each vertex.
|
|
211
241
|
|
|
@@ -225,7 +255,9 @@ Meshes of one vertex format share GPU buffers, so the engine draws them with few
|
|
|
225
255
|
|
|
226
256
|
## Levels of detail
|
|
227
257
|
|
|
228
|
-
A mesh made in code plans its own levels of detail the first time the scene draws it, when it holds 4,096 triangles or more, or when its copies hold 65,536 triangles together and it holds at least 256, as a batch of pebbles does. Meshes from `geometry.fromArrays` and from the generators both plan. The plan runs on the job workers, never in a frame.
|
|
258
|
+
A mesh made in code plans its own levels of detail the first time the scene draws it, when it holds 4,096 triangles or more, or when its copies hold 65,536 triangles together and it holds at least 256, as a batch of pebbles does. Meshes from `geometry.fromArrays` and from the generators both plan. The plan runs on the job workers, never in a frame.
|
|
259
|
+
|
|
260
|
+
It uses the planner of the asset tool's `--lod`, with the same simplifier, so a mesh made in code gets the levels that the same mesh in a file gets. The mesh draws its full shape until the levels arrive, a few frames later. Then every object and instance batch that draws it picks its level:
|
|
229
261
|
|
|
230
262
|
```ts
|
|
231
263
|
// 32,768 triangles: the first draw plans about six levels, down to a few hundred triangles.
|
|
@@ -235,9 +267,33 @@ scene.createInstances(ground, 400, { material: grass });
|
|
|
235
267
|
const levels = await ground.buildLevels();
|
|
236
268
|
```
|
|
237
269
|
|
|
238
|
-
Each level about halves the triangles of the level above and keeps the largest distance between its surface and the mesh's as its error. So it switches in at once, with no fade, while that distance covers less than the `lodThreshold` setting's pixels. The governor can raise that threshold past about one and a half pixels, where the switch shows, and the level then fades. A preset's own threshold never makes it fade.
|
|
270
|
+
Each level about halves the triangles of the level above and keeps the largest distance between its surface and the mesh's as its error. So it switches in at once, with no fade, while that distance covers less than the `lodThreshold` setting's pixels. The governor can raise that threshold past about one and a half pixels, where the switch shows, and the level then fades. A preset's own threshold never makes it fade.
|
|
271
|
+
|
|
272
|
+
A level costs only its indices. The plan runs on the job workers, and the frames go on meanwhile.
|
|
273
|
+
|
|
274
|
+
<details>
|
|
275
|
+
<summary>Technical details: how the planner works</summary>
|
|
276
|
+
|
|
277
|
+
The levels name the mesh's own vertices: the mesh keeps its vertices and triangles in their order, and a level costs its indices alone. A mesh of more than 65,535 vertices, which the engine splits into parts, shares its vertices part by part. Only the few triangles that cross from one part to another copy their vertices.
|
|
278
|
+
|
|
279
|
+
A plan of 130,000 triangles takes about half a second of one job worker, and a plan of a million about six seconds. A large mesh spreads its work over frames, so no frame waits for it.
|
|
280
|
+
|
|
281
|
+
The engine reads one part of the mesh in each frame for the plan. It makes one level in each frame when the plan is done. It gives the scene the whole set once, so its draw tables rebuild once. The planner, about 23 KB after Brotli, downloads with the first mesh that plans.
|
|
282
|
+
|
|
283
|
+
</details>
|
|
284
|
+
|
|
285
|
+
The plan also sorts large levels into pieces, so each copy skips the pieces that lie outside the view or face away from the camera. [Pieces of a large level](../concepts/lod.md#pieces-of-a-large-level) gives the rules.
|
|
286
|
+
|
|
287
|
+
<details>
|
|
288
|
+
<summary>Technical details: how the planner builds and splits levels</summary>
|
|
239
289
|
|
|
240
|
-
The plan
|
|
290
|
+
The plan sorts the mesh and each level of 32,768 triangles or more into 8 to 16 pieces. A mesh that one object draws gets pieces of its own too, over a sorted copy of its indices that arrives in the frame after the last level, so the mesh keeps its triangles in their order. Copies of a large mesh draw their full mesh only near the camera, so only their levels get pieces.
|
|
291
|
+
|
|
292
|
+
A list that faces mostly one way, such as a ground, splits by space. A smaller list of 1,024 triangles or more that many copies draw gets facing pieces where its triangles face a few ways. A building's walls are such a list: they get one piece for each way, and one for the rest.
|
|
293
|
+
|
|
294
|
+
A mesh whose levels are set by hand plans such pieces of its own list too. They draw only once the scene's copies of the mesh hold 65,536 triangles together.
|
|
295
|
+
|
|
296
|
+
</details>
|
|
241
297
|
|
|
242
298
|
The `levels` option of `fromArrays` and of every generator controls the plan:
|
|
243
299
|
|
|
@@ -274,9 +330,20 @@ rock.setLevels([
|
|
|
274
330
|
]);
|
|
275
331
|
```
|
|
276
332
|
|
|
277
|
-
An `error` level draws while it covers fewer pixels than the `lodThreshold` quality setting. A `distance` level draws while the camera lies farther than that distance. A `coverage` level draws while the bounds cover less than that share of the render's height. A level given by a distance, by a coverage or by a hand-set error fades over a short band.
|
|
333
|
+
An `error` level draws while it covers fewer pixels than the `lodThreshold` quality setting. A `distance` level draws while the camera lies farther than that distance. A `coverage` level draws while the bounds cover less than that share of the render's height. A level given by a distance, by a coverage or by a hand-set error fades over a short band.
|
|
334
|
+
|
|
335
|
+
A level with a measured error switches at once, and fades once the governor raises the threshold above about one and a half pixels. A glTF file marks a measured error with the screen coverage that the asset tool writes beside it. An error alone is hand-set, and it fades. `setLevels(levels, { fade: false })` switches every level at once while the threshold stays small.
|
|
336
|
+
|
|
337
|
+
Each level must have the mesh's vertex attributes, as it draws with the same pipelines. A level may name a `material` of its own, so a far level shades more cheaply. A level without one draws with the material of the level before it. The base level draws with the object's or the instance batch's material.
|
|
278
338
|
|
|
279
|
-
|
|
339
|
+
An empty list takes the levels away, and destroying a level's mesh takes every level away. `mesh.levels` lists them as you gave them. A mesh whose bound covers fewer pixels than the threshold draws nothing: its last level holds no geometry. Wrong levels throw [E1221](../errors/E1221.md).
|
|
340
|
+
|
|
341
|
+
[Levels of detail](../concepts/lod.md) explains the three measures, the hide distance, the fading bands and the shadows. It also explains how glTF files from the asset tool bring their levels. The [forest demo](https://github.com/null3d-engine/null3d/tree/main/examples/forest) calls `setLevels` on each tree mesh, with measured errors.
|
|
342
|
+
|
|
343
|
+
A far object that draws as a card follows its own rules. A card that lights unlike its mesh reads as
|
|
344
|
+
another tree. [Impostors](impostors.md#make-a-card-read-as-its-mesh) says which mesh to bake, the
|
|
345
|
+
color space, the views and texels, the normal bake, and the matched-crop check before a card is
|
|
346
|
+
accepted.
|
|
280
347
|
|
|
281
348
|
## Destroying a mesh
|
|
282
349
|
|
|
@@ -295,31 +362,14 @@ While an object or an instance batch still uses the mesh, `destroy` throws [E111
|
|
|
295
362
|
|
|
296
363
|
## Large meshes
|
|
297
364
|
|
|
298
|
-
A mesh can have any number of vertices.
|
|
365
|
+
A mesh can have any number of vertices. A mesh of more than 65,535 vertices splits into parts that draw one after another. For the fewest draw calls, keep meshes under 65,535 vertices. A mesh that draws a cluster tree is the exception. Its patches draw in one draw across all its parts, as [cluster levels](../concepts/lod.md#cluster-levels) describes.
|
|
299
366
|
|
|
300
|
-
|
|
367
|
+
<details>
|
|
368
|
+
<summary>Technical details: why large meshes split</summary>
|
|
301
369
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
| `rotateX`, `translate` or `scale` on a generated shape, such as a plane laid flat | Turn, move or scale the object instead: `floor.setRotationEuler(-Math.PI / 2, 0, 0)` |
|
|
306
|
-
| `new BufferGeometry()` with `setAttribute` and `setIndex` | `geometry.fromArrays({ positions, normals, uvs, indices })` |
|
|
307
|
-
| `new BufferAttribute(new Int16Array(values), 3, true)` | `{ array: new Int16Array(values), normalized: true }` |
|
|
308
|
-
| `geometry.computeVertexNormals()` | `computeNormals: true` |
|
|
309
|
-
| `geometry.computeTangents()` | `computeTangents: true` |
|
|
310
|
-
| `geometry.computeBoundingSphere()` | Nothing: the engine computes bounds itself |
|
|
311
|
-
| `geometry.morphAttributes.position = [...]` with `morphTargetsRelative = true` | `morphTargets: { positions: [...] }` |
|
|
312
|
-
| `geometry.morphAttributes.color = [...]` | `morphTargets: { colors: [...] }`, with `colors` on the mesh |
|
|
313
|
-
| `mesh.morphTargetDictionary` | The mesh geometry's `morphTargetNames`, a list in target order; `setMorphWeight` takes a name too |
|
|
314
|
-
| `geometry.dispose()` | `mesh.destroy()`, once no object or batch uses the mesh |
|
|
315
|
-
| `lod.addLevel(object, distance)` | `mesh.setLevels([{ mesh, distance }])` on the base mesh ([Levels of detail](../concepts/lod.md#from-threejs)) |
|
|
316
|
-
| `SimplifyModifier.modify(geometry, count)` from three/addons, for a far copy | Nothing: a mesh of 4,096 triangles or more plans its levels on the job workers when it first draws. `mesh.buildLevels()` plans a smaller one |
|
|
317
|
-
| `new TorusKnotGeometry(1, 0.4)`, and `Icosahedron`, `Lathe`, `Shape`, `Extrude`, `Tube` and the other geometry classes | `geometry.fromArrays(torusKnot({ radius: 1, tube: 0.4 }))`, with the functions of `@null3d/geometry` |
|
|
318
|
-
| `new THREE.Shape()`, `new THREE.CatmullRomCurve3(points)` | The same classes from `@null3d/geometry`, with points as arrays: `new CatmullRomCurve3([[0, 0, 0], [1, 1, 0]])` |
|
|
319
|
-
| `attribute.needsUpdate = true`, `setUsage(DynamicDrawUsage)` | `mesh.updateVertices('positions', positions)`. There is no usage hint |
|
|
320
|
-
| `attribute.addUpdateRange(start, count)` | `mesh.updateVertices(name, values, startVertex, vertexCount)`, in vertices rather than numbers |
|
|
321
|
-
|
|
322
|
-
[three.js to null3D](../porting/threejs-mapping.md) lists every mapping.
|
|
370
|
+
The engine uses 16-bit indices, and WebGL2 always reads the largest one, 65,535, as the end of a primitive, so one draw reaches 65,535 vertices. Each part holds a copy of the vertices that it shares with the part before it.
|
|
371
|
+
|
|
372
|
+
</details>
|
|
323
373
|
|
|
324
374
|
## API reference
|
|
325
375
|
|
package/docs/api/grass.md
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: api/grass
|
|
3
3
|
title: "Grass (@null3d/grass)"
|
|
4
|
-
|
|
5
|
-
since: "0.3"
|
|
6
|
-
summary: "createGrass: tufts of bent blades over a ground, placed by integer hashes, built in a compute pass on WebGPU with near shadows, swaying in the wind add-on's field, with a share for each quality preset."
|
|
4
|
+
summary: "createGrass: tufts of bent blades over a ground, placed by integer hashes, built in a compute pass on WebGPU with the sun's shadows, swaying in the wind add-on's field, with a share for each quality preset."
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
# Grass (@null3d/grass)
|
|
10
8
|
|
|
11
|
-
> Roadmap step 0.3, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
|
|
12
|
-
|
|
13
9
|
```mermaid
|
|
14
10
|
flowchart LR
|
|
15
11
|
ground["The ground's height,<br/>a mask, a seed"] --> place["Tufts placed<br/>by integer hash"]
|
|
16
12
|
place --> gpu["WebGPU: a compute pass<br/>writes the blade list"]
|
|
17
13
|
place --> batch["WebGL2: one instance<br/>batch for each shape"]
|
|
18
14
|
camera["The camera"] --> gpu
|
|
19
|
-
gpu --> draw["The blades, with<br/>
|
|
15
|
+
gpu --> draw["The blades, with<br/>the sun's shadows"]
|
|
20
16
|
batch --> draw
|
|
21
17
|
wind["The wind add-on's field"] --> draw
|
|
22
18
|
preset["The quality preset"] --> place
|
|
@@ -24,6 +20,10 @@ flowchart LR
|
|
|
24
20
|
|
|
25
21
|
`@null3d/grass` draws tufts of bent blades over a square of ground. One seed places the same tufts on every device, and the blades bend in the air of the wind add-on's field. On WebGPU a compute pass builds the blade list each frame, culls it to the view and thins the far tufts. WebGL2 draws the same rows as an instance batch. The grass casts and receives the sun's shadows on both paths.
|
|
26
22
|
|
|
23
|
+

|
|
24
|
+
|
|
25
|
+
The plants in wind demo. On feature-instances: the grass add-on places and counts its blades with a compute pass on WebGPU.
|
|
26
|
+
|
|
27
27
|
The package is built on the engine's public API. Its two shaders ship compiled, so your build does not compile them. It reads the field of `@null3d/wind`, which it lists as a peer dependency.
|
|
28
28
|
|
|
29
29
|
```sh
|
|
@@ -37,12 +37,19 @@ import { createGrass, swayDistanceFor } from '@null3d/grass';
|
|
|
37
37
|
import { createWind } from '@null3d/wind';
|
|
38
38
|
|
|
39
39
|
export default defineSketch(async (ctx) => {
|
|
40
|
-
const { scene, quality } = ctx;
|
|
40
|
+
const { scene, quality, geometry, materials } = ctx;
|
|
41
41
|
const camera = scene.createPerspectiveCamera({ position: [0, 2, 12], target: [0, 0, 0] });
|
|
42
42
|
scene.setActiveCamera(camera);
|
|
43
43
|
scene.createDirectionalLight({ direction: [-0.4, -1, -0.3], intensity: 3, castShadows: true });
|
|
44
44
|
|
|
45
|
-
const height = (
|
|
45
|
+
const height = () => 0;
|
|
46
|
+
scene.setBackground('#8fb3cf');
|
|
47
|
+
scene.createMesh({
|
|
48
|
+
mesh: geometry.plane({ width: 40, height: 40 }),
|
|
49
|
+
material: materials.standard({ color: '#4f6b2a' }),
|
|
50
|
+
rotation: [-Math.SQRT1_2, 0, 0, Math.SQRT1_2],
|
|
51
|
+
receiveShadows: true,
|
|
52
|
+
});
|
|
46
53
|
const wind = createWind(ctx, { camera, box: 128 });
|
|
47
54
|
wind.setBase(3, 0.4);
|
|
48
55
|
const grass = await createGrass(ctx, {
|
|
@@ -54,6 +61,10 @@ export default defineSketch(async (ctx) => {
|
|
|
54
61
|
camera,
|
|
55
62
|
swayDistance: swayDistanceFor(quality.preset),
|
|
56
63
|
});
|
|
64
|
+
quality.onChange(() => {
|
|
65
|
+
grass.fit(quality.preset);
|
|
66
|
+
grass.setSwayDistance(swayDistanceFor(quality.preset));
|
|
67
|
+
});
|
|
57
68
|
|
|
58
69
|
return {
|
|
59
70
|
onUpdate() {
|
|
@@ -66,13 +77,30 @@ export default defineSketch(async (ctx) => {
|
|
|
66
77
|
|
|
67
78
|
## Grass on the ground
|
|
68
79
|
|
|
69
|
-
`await createGrass(ctx,
|
|
80
|
+
`await createGrass(ctx, options)` draws tufts of bent blades over a square of ground. Await the call in the sketch's setup, because WebGPU makes its draw then. The [`GrassOptions` table](reference/grass.md#grassoptions) lists every option with its default.
|
|
81
|
+
|
|
82
|
+

|
|
83
|
+
|
|
84
|
+
Grass counts follow the preset.
|
|
85
|
+
|
|
86
|
+
The tufts stand on `height(x, z)` and skip ground steeper than `maxSlope`. They also skip ground that `mask` refuses, such as water or a footprint, and ground that `where` refuses, such as a road. A tuft grows only where both allow it.
|
|
87
|
+
|
|
88
|
+
`count` is the tufts at the High preset. Low, Medium and Ultra draw 0.35, 0.6 and 1.25 of it. `createGrass` fits the engine's starting preset, and `grass.fit(preset)` takes a new one.
|
|
89
|
+
|
|
90
|
+
<details>
|
|
91
|
+
<summary>Technical details: how the tufts are placed</summary>
|
|
92
|
+
|
|
93
|
+
Each tuft's turn and size come from integer hashes, so one seed places the same grass on every device. Each tuft's tint comes from a hash of its root's place, in the shader.
|
|
94
|
+
|
|
95
|
+
</details>
|
|
70
96
|
|
|
71
97
|
The blades bend in the wind add-on's field. Give `createGrass` its `wind` field, and call `grass.setWindLayer(field)` in each frame with the field's newest state. A page that gives no field grows grass that stands still.
|
|
72
98
|
|
|
73
99
|
## The blade shape
|
|
74
100
|
|
|
75
|
-
Without a shape, each blade narrows to a point from its root. The `blade` option gives every blade one shape. Its `widthAt(t)` is the blade's width in meters at a share `t` of its length, from 0 at the root to 1 at the tip. Its `fold` is the degrees that each half rises from the keel.
|
|
101
|
+
Without a shape, each blade narrows to a point from its root. The `blade` option gives every blade one shape. Its `widthAt(t)` is the blade's width in meters at a share `t` of its length, from 0 at the root to 1 at the tip. Its `fold` is the degrees that each half rises from the keel.
|
|
102
|
+
|
|
103
|
+
A blade with a fold draws a vertex at its keel, so its two halves light apart. Give a plant's own blade with the plant's own `color`, so the cover reads as the same grass where the plant stands.
|
|
76
104
|
|
|
77
105
|
```ts
|
|
78
106
|
const grass = await createGrass(ctx, {
|
|
@@ -89,15 +117,25 @@ const grass = await createGrass(ctx, {
|
|
|
89
117
|
|
|
90
118
|
On WebGPU and compatibility mode a compute pass builds the blade list. It writes each tuft's row and the count into a draw that the frame culls no further. The engine copies the count into the main view and every drawn shadow view.
|
|
91
119
|
|
|
92
|
-
Give the pass the drawing `camera`, and it culls the tiles outside the view and thins the far tufts. A far tuft draws the share that its root's hash picks. Its blades widen by the inverse of that share, so the hill's cover stays the same.
|
|
120
|
+
Give the pass the drawing `camera`, and it culls the tiles outside the view and thins the far tufts. A far tuft draws the share that its root's hash picks. Its blades widen by the inverse of that share, so the hill's cover stays the same.
|
|
121
|
+
|
|
122
|
+
The draw shader then culls each view to its own box, from that view's matrix. The camera's view draws its frustum. A light's view draws its cascade, whose box reaches toward the light over the casters. So a shadow view does not draw the whole kept list.
|
|
93
123
|
|
|
94
124
|
WebGL2 fills one instance batch for each tuft shape on the CPU. Its vertex shader applies the same share and the same per-view cull, so both paths draw the same hill. The rows are built for Ultra's share once. A preset change then changes only how many rows draw, not the memory. A page that drives the rows itself gives `compute: false`, which keeps the instance batch on both paths.
|
|
95
125
|
|
|
96
126
|
The tuft meshes plan no levels of detail: the wind bends their blades in the shader, and the tufts thin with distance by themselves.
|
|
97
127
|
|
|
98
|
-
##
|
|
128
|
+
## Shadows and the sway distance
|
|
129
|
+
|
|
130
|
+
The grass casts and receives the sun's shadows on both paths. Far shadow cascades draw only every few frames, unless a moving caster touches them. Swaying blades count as moving, so by default the far cascades draw in every frame ([Shadows](../concepts/shadows.md#update-rates)).
|
|
131
|
+
|
|
132
|
+

|
|
133
|
+
|
|
134
|
+
Near grass shadows.
|
|
135
|
+
|
|
136
|
+
Give the grass a `swayDistance` to stop the blades past that distance. Then a far cascade that only the grass reaches keeps its turns. The default, 0, sways at every distance. Call `grass.setSwayDistance(distance)` when the preset changes.
|
|
99
137
|
|
|
100
|
-
|
|
138
|
+
`swayDistanceFor(preset)` gives each preset's distance from `PLANT_SWAY_DISTANCE`: 8, 16, 24 and 32 meters from Low to Ultra. Give a swaying plant's material the same distance, so plants and grass stop at one line. The ground's own color and the blades' root colors should meet at the hill's foot.
|
|
101
139
|
|
|
102
140
|
## The placement hash
|
|
103
141
|
|
|
@@ -111,4 +149,8 @@ The grass casts and receives the sun's shadows on both paths. Give it a `swayDis
|
|
|
111
149
|
|
|
112
150
|
- [Wind](wind.md): the field of air that the blades bend in.
|
|
113
151
|
- [Add-on instance draws](feature-instances.md): the draw whose count the blade list writes.
|
|
152
|
+
- [Shadows](../concepts/shadows.md#update-rates): how the far cascades keep their layers.
|
|
114
153
|
- [Quality API](quality.md): the preset and the frame-budget governor.
|
|
154
|
+
- [Grass in the wind](https://github.com/null3d-engine/null3d/tree/main/examples/vegetation-wind): a grove whose grass and plants sway in the wind field.
|
|
155
|
+
- [Grass in a scene](https://github.com/null3d-engine/null3d/tree/main/examples/contact-shadows): tufts of grass that cast contact shadows in a stone garden.
|
|
156
|
+
- [Grass at scale](https://github.com/null3d-engine/null3d/tree/main/examples/showcase/island): the island sets `compute: false`, so its grass draws as an instance batch on both paths.
|