threedog 0.5.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +276 -1
- package/README.md +18 -13
- package/core/{Animator.js → assets/Animator.js} +28 -18
- package/core/{Assets.js → assets/Assets.js} +116 -61
- package/core/{Baked.js → assets/Baked.js} +16 -25
- package/core/assets/assetEntry.js +237 -0
- package/core/{assetHot.js → assets/assetHot.js} +7 -6
- package/core/{assetLoad.js → assets/assetLoad.js} +66 -29
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +23 -12
- package/core/{assetReport.js → assets/assetReport.js} +9 -15
- package/core/{namedModel.js → assets/namedModel.js} +24 -16
- package/core/{Audio.js → audio/Audio.js} +27 -24
- package/core/{audioRules.js → audio/audioRules.js} +8 -5
- package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
- package/core/{Events.js → base/Events.js} +3 -3
- package/core/{I18n.js → base/I18n.js} +10 -10
- package/core/{Random.js → base/Random.js} +5 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +154 -139
- package/core/{errorHints.js → base/errorHints.js} +9 -10
- package/core/{errors.js → base/errors.js} +9 -9
- package/core/{events.generated.js → base/events.generated.js} +2 -0
- package/core/{math.js → base/math.js} +22 -4
- package/core/{params.js → base/params.js} +3 -4
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +29 -8
- package/core/{Engine.js → engine/Engine.js} +112 -105
- package/core/{Loading.js → engine/Loading.js} +4 -2
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +4 -4
- package/core/{lifecycle.js → engine/lifecycle.js} +16 -16
- package/core/{loop.js → engine/loop.js} +80 -52
- package/core/{moduleSlots.js → engine/moduleSlots.js} +35 -10
- package/core/{moduleTypes.js → engine/moduleTypes.js} +30 -18
- package/core/{modules.js → engine/modules.js} +20 -17
- package/core/engine/page.js +125 -0
- package/core/{plugins.js → engine/plugins.js} +68 -103
- package/core/{services.js → engine/services.js} +47 -40
- package/core/{startup.js → engine/startup.js} +35 -35
- package/core/{Input.js → input/Input.js} +41 -27
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/{inputPad.js → input/inputPad.js} +1 -1
- package/core/{inputPointer.js → input/inputPointer.js} +8 -2
- package/core/{inputTouch.js → input/inputTouch.js} +1 -1
- package/core/{Budget.js → inspect/Budget.js} +23 -22
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +60 -31
- package/core/{Describe.js → inspect/Describe.js} +33 -30
- package/core/{Inspect.js → inspect/Inspect.js} +14 -9
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +8 -10
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +29 -16
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +9 -6
- package/core/inspect/UrlState.js +182 -0
- package/core/{catalog.js → inspect/catalog.js} +18 -5
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +8 -8
- package/core/inspect/describeRender.js +148 -0
- package/core/{describeText.js → inspect/describeText.js} +17 -12
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +11 -9
- package/core/inspect/pictureWriters.js +342 -0
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/{Ops.js → ops/Ops.js} +16 -11
- package/core/{control.js → ops/control.js} +13 -12
- package/core/ops/holds.js +139 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +2 -1
- package/core/{opsCheck.js → ops/opsCheck.js} +4 -5
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +7 -4
- package/core/{owned.js → ops/owned.js} +37 -37
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -27
- package/core/{stackFrames.js → ops/stackFrames.js} +17 -6
- package/core/{stacks.js → ops/stacks.js} +18 -20
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +1 -1
- package/core/{Saves.js → saves/Saves.js} +58 -36
- package/core/{saveApply.js → saves/saveApply.js} +13 -9
- package/core/{saveFiles.js → saves/saveFiles.js} +17 -15
- package/core/{saveValues.js → saves/saveValues.js} +20 -3
- package/core/{saveVersions.js → saves/saveVersions.js} +4 -17
- package/core/{session.js → saves/session.js} +31 -17
- package/core/{Rays.js → scene/Rays.js} +27 -24
- package/core/{Views.js → scene/Views.js} +15 -6
- package/core/{adaptive.js → scene/adaptive.js} +15 -8
- package/core/{canvasBox.js → scene/canvasBox.js} +2 -3
- package/core/{engineCamera.js → scene/engineCamera.js} +1 -1
- package/core/{gameLights.js → scene/gameLights.js} +24 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +4 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/{ground.js → scene/ground.js} +9 -9
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/scene/pictureSlots.js +33 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +14 -6
- package/core/{sceneMethods.js → scene/sceneMethods.js} +36 -20
- package/core/scene/stepPoses.js +55 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
- package/core/{thingOps.js → scene/thingOps.js} +4 -3
- package/core/{things.js → scene/things.js} +19 -6
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +1 -1
- package/core/scene/view.js +44 -0
- package/core/{Batching.js → stream/Batching.js} +85 -27
- package/core/{Stream.js → stream/Stream.js} +62 -33
- package/core/{batchGroups.js → stream/batchGroups.js} +18 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +41 -1
- package/core/{scatter.js → stream/scatter.js} +2 -2
- package/core/{streamSources.js → stream/streamSources.js} +12 -7
- package/core/{Commits.js → threads/Commits.js} +6 -5
- package/core/{Jobs.js → threads/Jobs.js} +12 -10
- package/core/{Threads.js → threads/Threads.js} +16 -16
- package/core/{threadPure.js → threads/threadPure.js} +7 -5
- package/core/{threadServe.js → threads/threadServe.js} +3 -3
- package/core/{Clock.js → time/Clock.js} +17 -10
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +18 -17
- package/core/{time.js → time/time.js} +18 -12
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +70 -63
- package/docs/API.md +30 -29
- package/docs/CODEMAP.md +98 -223
- package/docs/COMMANDS.md +80 -69
- package/docs/CONVENTIONS.md +87 -41
- package/docs/MIGRATING-0.7.md +39 -0
- package/docs/MIGRATING-0.8.md +169 -0
- package/docs/THREE.md +100 -49
- package/docs/api/assets.md +17 -16
- package/docs/api/audio.md +8 -7
- package/docs/api/budget.md +8 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +29 -29
- package/docs/api/characters.md +26 -19
- package/docs/api/clock.md +1 -1
- package/docs/api/collision.md +14 -11
- package/docs/api/content.md +6 -6
- package/docs/api/dialogue.md +3 -3
- package/docs/api/engine.md +82 -53
- package/docs/api/events.md +5 -3
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +9 -2
- package/docs/api/ground.md +4 -5
- package/docs/api/hud.md +4 -1
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +10 -9
- package/docs/api/interactions.md +6 -4
- package/docs/api/inventory.md +10 -11
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +7 -8
- package/docs/api/lightPool.md +2 -7
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +10 -10
- package/docs/api/occlusion.md +5 -0
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +8 -5
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +7 -1
- package/docs/api/post.md +24 -5
- package/docs/api/quests.md +3 -3
- package/docs/api/rays.md +5 -7
- package/docs/api/rigid.md +27 -18
- package/docs/api/saves.md +8 -7
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +17 -14
- package/docs/api/stream.md +7 -7
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +17 -12
- package/docs/api/terrainDraw.md +12 -0
- package/docs/api/timeline.md +2 -2
- package/docs/api/tools.md +30 -26
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +11 -5
- package/docs/api/vegetationDraw.md +10 -0
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +11 -6
- package/docs/api/weatherDraw.md +10 -0
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +38 -57
- package/docs/recipes/02-npc.md +19 -20
- package/docs/recipes/03-items-pickups.md +47 -42
- package/docs/recipes/04-quests.md +3 -4
- package/docs/recipes/05-props-bake.md +72 -66
- package/docs/recipes/06-clock-events.md +30 -21
- package/docs/recipes/07-flow-scenes-pause.md +21 -17
- package/docs/recipes/08-weather-sky.md +117 -75
- package/docs/recipes/09-materials-lights-models.md +171 -0
- package/docs/recipes/10-blender-level.md +6 -7
- package/docs/recipes/11-vehicles.md +33 -25
- package/docs/recipes/12-navmesh.md +9 -8
- package/docs/recipes/13-animation.md +50 -22
- package/docs/recipes/14-custom-module.md +20 -17
- package/docs/recipes/15-perf.md +52 -29
- package/docs/recipes/16-dev-bridge.md +47 -57
- package/docs/recipes/18-world.md +45 -30
- package/docs/recipes/19-shooting-picking.md +11 -7
- package/docs/recipes/20-content-actions-save.md +36 -37
- package/docs/recipes/21-camera.md +41 -8
- package/docs/recipes/22-shop-gold.md +0 -4
- package/docs/recipes/23-ops.md +11 -11
- package/docs/recipes/26-ui-parts.md +56 -22
- package/docs/recipes/27-net.md +0 -2
- package/docs/recipes/28-terrain.md +126 -30
- package/docs/recipes/29-grid.md +16 -7
- package/docs/recipes/30-templates.md +62 -21
- package/docs/recipes/31-audio.md +9 -9
- package/docs/recipes/32-action-game.md +32 -9
- package/docs/recipes/33-stream-sources.md +2 -2
- package/docs/recipes/34-environment-lighting.md +164 -52
- package/docs/recipes/35-picture-from-reference.md +140 -0
- package/docs/recipes/36-ground-plants.md +105 -0
- package/docs/recipes/40-scene.md +105 -30
- package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +74 -106
- package/docs/recipes/44-water-weather-hooks.md +196 -0
- package/docs/recipes/45-cascaded-shadows.md +145 -25
- package/docs/recipes/46-blender-art-route.md +21 -25
- package/docs/recipes/49-game-module-contract.md +5 -5
- package/docs/recipes/50-own-renderer.md +3 -3
- package/docs/recipes/52-around-the-picture.md +137 -0
- package/docs/recipes/53-ground-up-close.md +65 -28
- package/docs/recipes/55-mods-time-wrap.md +25 -17
- package/docs/recipes/56-webgpu-tsl.md +73 -28
- package/docs/recipes/57-control.md +47 -1
- package/docs/recipes/58-input.md +3 -0
- package/docs/recipes/59-depth-post-effects.md +5 -5
- package/docs/recipes/60-judge-the-picture.md +47 -27
- package/docs/recipes/61-deploy.md +27 -0
- package/docs/recipes/62-picture-code.md +276 -0
- package/docs/recipes/63-third-person-start.md +90 -0
- package/docs/recipes/64-particles.md +35 -0
- package/docs/recipes/65-swarm.md +140 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +9 -7
- package/examples/action/main.js +5 -4
- package/examples/action/models.js +12 -14
- package/examples/action/picture/index.js +13 -0
- package/examples/action/picture/lights.js +35 -0
- package/examples/action/picture/materials.js +8 -0
- package/examples/action/picture/palette.js +33 -0
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +18 -14
- package/examples/{sheepisland → perf-island}/assets.js +2 -2
- package/examples/{sheepisland → perf-island}/content/templates.js +1 -1
- package/examples/{sheepisland → perf-island}/content/vegetation.js +3 -1
- package/examples/{sheepisland → perf-island}/main.js +22 -16
- package/examples/{sheepisland/style → perf-island}/models.js +13 -24
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/perf-island/picture/index.js +20 -0
- package/examples/perf-island/picture/lights.js +34 -0
- package/examples/perf-island/picture/materials.js +61 -0
- package/examples/perf-island/picture/palette.js +60 -0
- package/examples/perf-island/picture/sky.js +20 -0
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/.threedog/content-index.json +1 -0
- package/examples/plain-picture/GAMEMAP.md +91 -0
- package/examples/plain-picture/main.js +48 -0
- package/examples/plain-picture/picture/index.js +21 -0
- package/examples/plain-picture/picture/lights.js +54 -0
- package/examples/plain-picture/picture/materials.js +24 -0
- package/examples/plain-picture/picture/palette.js +16 -0
- package/examples/plain-picture/picture/sky.js +37 -0
- package/examples/pullable.json +31 -9
- package/examples/rc2d/GAMEMAP.md +10 -4
- package/examples/rc2d/README.md +11 -6
- package/examples/rc2d/main.js +26 -36
- package/examples/rc2d/picture/index.js +18 -0
- package/examples/rc2d/picture/lights.js +11 -0
- package/examples/rc2d/picture/materials.js +18 -0
- package/examples/rc2d/picture/palette.js +15 -0
- package/examples/rc2d/picture/post.js +11 -0
- package/examples/rc2d/rc2d.js +18 -28
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +15 -10
- package/examples/styletest/main.js +20 -30
- package/examples/styletest/models.js +29 -29
- package/examples/styletest/params.js +1 -4
- package/examples/styletest/picture/env.js +38 -0
- package/examples/styletest/picture/index.js +16 -0
- package/examples/styletest/picture/lights.js +9 -0
- package/examples/styletest/picture/materials.js +28 -0
- package/examples/styletest/picture/palette.js +22 -0
- package/examples/techniques/contact-shadows/README.md +22 -23
- package/examples/techniques/contact-shadows/contactShadows.js +32 -16
- package/examples/techniques/contact-shadows/main.js +20 -18
- package/examples/techniques/contact-shadows/picture/index.js +14 -0
- package/examples/techniques/contact-shadows/picture/lights.js +34 -0
- package/examples/techniques/contact-shadows/picture/materials.js +12 -0
- package/examples/techniques/contact-shadows/picture/palette.js +17 -0
- package/examples/techniques/day-night-grade/README.md +13 -16
- package/examples/techniques/day-night-grade/main.js +15 -25
- package/examples/techniques/day-night-grade/picture/index.js +20 -0
- package/examples/techniques/day-night-grade/picture/lights.js +45 -0
- package/examples/techniques/day-night-grade/picture/materials.js +15 -0
- package/examples/techniques/day-night-grade/picture/palette.js +59 -0
- package/examples/techniques/day-night-grade/picture/post.js +25 -0
- package/examples/techniques/day-night-grade/picture/sky.js +33 -0
- package/examples/techniques/interior-light/README.md +16 -13
- package/examples/techniques/interior-light/interiorLight.js +19 -17
- package/examples/techniques/interior-light/main.js +31 -68
- package/examples/techniques/interior-light/picture/index.js +24 -0
- package/examples/techniques/interior-light/picture/lights.js +52 -0
- package/examples/techniques/interior-light/picture/materials.js +13 -0
- package/examples/techniques/interior-light/picture/palette.js +32 -0
- package/examples/techniques/interior-light/picture/sky.js +40 -0
- package/examples/techniques/modular-building/README.md +8 -6
- package/examples/techniques/modular-building/kit.js +2 -2
- package/examples/techniques/modular-building/main.js +9 -17
- package/examples/techniques/modular-building/picture/index.js +17 -0
- package/examples/techniques/modular-building/picture/lights.js +26 -0
- package/examples/techniques/modular-building/picture/materials.js +13 -0
- package/examples/techniques/modular-building/picture/palette.js +23 -0
- package/examples/techniques/night-lights/README.md +15 -14
- package/examples/techniques/night-lights/main.js +20 -43
- package/examples/techniques/night-lights/nightLights.js +25 -21
- package/examples/techniques/night-lights/picture/index.js +18 -0
- package/examples/techniques/night-lights/picture/lights.js +44 -0
- package/examples/techniques/night-lights/picture/materials.js +15 -0
- package/examples/techniques/night-lights/picture/palette.js +34 -0
- package/examples/techniques/night-lights/picture/post.js +9 -0
- package/examples/techniques/night-lights/picture/sky.js +36 -0
- package/examples/techniques/outlines-and-rim/README.md +2 -2
- package/examples/techniques/outlines-and-rim/main.js +15 -38
- package/examples/techniques/outlines-and-rim/outlines.js +3 -3
- package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
- package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
- package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
- package/examples/techniques/procedural-animation/README.md +6 -4
- package/examples/techniques/procedural-animation/main.js +9 -7
- package/examples/techniques/procedural-animation/picture/index.js +15 -0
- package/examples/techniques/procedural-animation/picture/lights.js +35 -0
- package/examples/techniques/procedural-animation/picture/materials.js +10 -0
- package/examples/techniques/procedural-animation/picture/palette.js +16 -0
- package/examples/techniques/procedural-animation/picture/sky.js +31 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +1 -1
- package/examples/techniques/procedural-surface/README.md +2 -0
- package/examples/techniques/procedural-surface/main.js +17 -55
- package/examples/techniques/procedural-surface/picture/index.js +14 -0
- package/examples/techniques/procedural-surface/picture/lights.js +18 -0
- package/examples/techniques/procedural-surface/picture/materials.js +34 -0
- package/examples/techniques/procedural-surface/picture/palette.js +15 -0
- package/examples/techniques/stylized-shading/README.md +13 -14
- package/examples/techniques/stylized-shading/main.js +11 -42
- package/examples/techniques/stylized-shading/picture/index.js +14 -0
- package/examples/techniques/stylized-shading/picture/lights.js +23 -0
- package/examples/techniques/stylized-shading/picture/materials.js +18 -0
- package/examples/techniques/stylized-shading/picture/palette.js +19 -0
- package/examples/techniques/stylized-shading/shading.js +2 -2
- package/examples/techniques/sun-and-key-light/README.md +20 -22
- package/examples/techniques/sun-and-key-light/keyLight.js +47 -29
- package/examples/techniques/sun-and-key-light/main.js +19 -63
- package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
- package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
- package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
- package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
- package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
- package/examples/techniques/three-looks/README.md +21 -0
- package/examples/techniques/three-looks/main.js +58 -0
- package/examples/techniques/three-looks/picture/cartoon.js +23 -0
- package/examples/techniques/three-looks/picture/cinematic.js +27 -0
- package/examples/techniques/three-looks/picture/comic.js +27 -0
- package/examples/techniques/three-looks/picture/index.js +14 -0
- package/examples/techniques/three-looks/picture/sun.js +23 -0
- package/examples/techniques/wet-road/README.md +7 -4
- package/examples/techniques/wet-road/main.js +18 -38
- package/examples/techniques/wet-road/picture/index.js +17 -0
- package/examples/techniques/wet-road/picture/lights.js +57 -0
- package/examples/techniques/wet-road/picture/materials.js +16 -0
- package/examples/techniques/wet-road/picture/palette.js +24 -0
- package/examples/techniques/wet-road/picture/sky.js +46 -0
- package/examples/webgpu-tsl/GAMEMAP.md +10 -4
- package/examples/webgpu-tsl/README.md +13 -10
- package/examples/webgpu-tsl/main.js +30 -7
- package/examples/webgpu-tsl/picture/index.js +18 -0
- package/examples/webgpu-tsl/picture/lights.js +25 -0
- package/examples/webgpu-tsl/picture/materials.js +36 -0
- package/examples/webgpu-tsl/picture/palette.js +23 -0
- package/examples/webgpu-tsl/picture/post.js +16 -0
- package/examples/webgpu-tsl/picture/sky.js +30 -0
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +16 -12
- package/examples/world/art/humanoid.js +9 -13
- package/examples/world/art/index.js +2 -2
- package/examples/world/art/models.js +3 -4
- package/examples/world/art/shapes.js +2 -2
- package/examples/world/assets.js +2 -2
- package/examples/world/content/audio.js +1 -1
- package/examples/world/content/items.js +1 -1
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +10 -10
- package/examples/world/models.js +17 -7
- package/examples/world/picture/index.js +20 -0
- package/examples/world/picture/lights.js +41 -0
- package/examples/world/picture/materials.js +34 -0
- package/examples/world/picture/palette.js +74 -0
- package/examples/world/picture/post.js +9 -0
- package/examples/world/picture/sky.js +39 -0
- package/index.d.ts +14 -22
- package/index.js +36 -36
- package/llms.txt +19 -21
- package/modules/ambience/Ambience.js +12 -9
- package/modules/calendar/Calendar.js +20 -20
- package/modules/calendar/index.js +14 -13
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +2 -2
- package/modules/camera/FixedCamera.js +14 -15
- package/modules/camera/FollowCamera.js +4 -4
- package/modules/camera/RtsCamera.js +11 -11
- package/modules/camera/common.js +51 -25
- package/modules/camera/contract.js +1 -0
- package/modules/camera/projection.js +2 -2
- package/modules/characters/Character.js +47 -39
- package/modules/characters/NPC.js +30 -22
- package/modules/characters/assetModel.js +18 -13
- package/modules/characters/astar.js +7 -5
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/contract.js +2 -2
- package/modules/characters/index.js +172 -193
- package/modules/characters/moveHelpers.js +14 -3
- package/modules/characters/movers/common.js +22 -15
- package/modules/characters/movers/manual.js +4 -1
- package/modules/characters/movers/rapier.js +7 -6
- package/modules/characters/movers/simple.js +3 -3
- package/modules/characters/movers/support.js +32 -18
- package/modules/characters/npcAvoid.js +4 -4
- package/modules/characters/npcSim.js +28 -18
- package/modules/characters/npcView.js +6 -5
- package/modules/characters/pathAsync.js +12 -10
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +108 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +19 -5
- package/modules/characters/useModel.js +5 -5
- package/modules/characters/walkTo.js +11 -17
- package/modules/collision/Collision.js +30 -22
- package/modules/collision/contract.js +15 -0
- package/modules/content/explain.js +1 -2
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +2 -2
- package/modules/content/index.js +68 -98
- package/modules/content/loader.js +14 -17
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +66 -18
- package/modules/content/packs.js +3 -3
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +35 -0
- package/modules/content/props.js +19 -14
- package/modules/content/rules.js +34 -22
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +24 -22
- package/modules/content/words.js +34 -0
- package/modules/debug/DebugPanel.js +10 -43
- package/modules/flow/contract.js +1 -1
- package/modules/flow/index.js +11 -7
- package/modules/gameplay/Container.js +12 -11
- package/modules/gameplay/Containers.js +14 -5
- package/modules/gameplay/Dialogue.js +13 -11
- package/modules/gameplay/Interactions.js +115 -27
- package/modules/gameplay/Inventory.js +11 -12
- package/modules/gameplay/Quests.js +16 -9
- package/modules/gameplay/boxOps.js +1 -1
- package/modules/gameplay/dialogueBox.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +4 -5
- package/modules/gameplay/interactionPrompt.js +1 -1
- package/modules/gameplay/interactions.contract.js +1 -1
- package/modules/gameplay/inventoryOps.js +2 -3
- package/modules/gameplay/pickups.js +81 -44
- package/modules/gameplay/questLog.js +2 -2
- package/modules/gameplay/questSave.js +3 -3
- package/modules/grid/Grid.js +1 -1
- package/modules/grid/Layer.js +16 -3
- package/modules/grid/index.js +47 -19
- package/modules/grid/preview.js +29 -20
- package/modules/grid/tiles.js +19 -23
- package/modules/hlod/index.js +38 -55
- package/modules/hud/index.js +27 -8
- package/modules/hud/parts.js +13 -11
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +12 -10
- package/modules/level/index.js +48 -152
- package/modules/level/load.js +79 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +6 -7
- package/modules/lights/index.js +34 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +88 -0
- package/modules/music/Music.js +31 -27
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +14 -0
- package/modules/nav/index.js +11 -10
- package/modules/net/Client.js +7 -7
- package/modules/net/Host.js +7 -7
- package/modules/net/Net.js +1 -1
- package/modules/net/index.js +5 -4
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +49 -25
- package/modules/particles/effect.js +27 -10
- package/modules/particles/shaders.js +2 -1
- package/modules/photo/Photo.js +26 -27
- package/modules/rigid/RigidBodies.js +66 -43
- package/modules/rigid/Vehicles.js +2 -3
- package/modules/rigid/ragdoll.js +287 -0
- package/modules/rigid/ragdollBones.js +159 -0
- package/modules/rigid/sync.js +6 -6
- package/modules/settings/Settings.js +114 -45
- package/modules/settings/apply.js +10 -10
- package/modules/settings/sections.js +16 -14
- package/modules/settings/strings.js +1 -1
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +125 -103
- package/modules/sky/clouds.js +22 -23
- package/modules/sky/dome.js +113 -0
- package/modules/sky/domeLayers.js +13 -13
- package/modules/sky/environment.js +47 -171
- package/modules/sky/fog.js +5 -180
- package/modules/sky/frame.js +42 -97
- package/modules/sky/season.js +9 -3
- package/modules/sky/shader.js +49 -44
- package/modules/sky/skyModule.js +25 -35
- package/modules/sky/tint.js +9 -11
- package/modules/swarm/Swarm.js +346 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +97 -62
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +157 -0
- package/modules/terrain/index.js +60 -88
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +4 -3
- package/modules/terrain/terrainEdit.js +32 -27
- package/modules/terrain/terrainGen.js +19 -14
- package/modules/terrain/terrainIsland.js +2 -2
- package/modules/terrain/terrainMesh.js +7 -6
- package/modules/terrain/terrainShape.js +8 -10
- package/modules/terrain/terrainShapeMain.js +3 -3
- package/modules/timeline/Timeline.js +27 -19
- package/modules/timeline/Tween.js +6 -6
- package/modules/timeline/shots.js +5 -7
- package/modules/triggers/index.js +19 -15
- package/modules/vegetation/Vegetation.js +87 -39
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +196 -0
- package/modules/vegetation/groundChunks.js +11 -31
- package/modules/vegetation/index.js +18 -16
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +140 -93
- package/modules/water/surface.js +56 -56
- package/modules/weather/Weather.js +84 -38
- package/modules/weather/particles.js +18 -10
- package/modules/weather/shaders.js +1 -1
- package/modules/weather/weatherDraw.js +145 -0
- package/modules/world/World.js +10 -10
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -12
- package/modules/world/persist.js +73 -25
- package/modules/world/pos.js +4 -4
- package/modules/world/records.js +28 -8
- package/modules/world/sim.js +4 -4
- package/modules/world/state.js +12 -5
- package/modules/world/thingSource.js +4 -2
- package/modules/world/views.js +12 -10
- package/package.json +44 -8
- package/presets.js +3 -5
- package/render/PostFX.js +233 -63
- package/render/backend.js +72 -32
- package/render/cascades.js +200 -0
- package/render/cascades.tsl.js +93 -0
- package/render/daylight.js +56 -0
- package/render/detail.js +13 -12
- package/render/effects.js +60 -42
- package/render/fuse.js +3 -3
- package/render/fx/cel.tsl.js +42 -0
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +10 -13
- package/render/fx/library.tsl.js +11 -0
- package/render/fx/lighting.tsl.js +2 -1
- package/render/fx/nodeErrors.tsl.js +2 -2
- package/render/fx/objectOrigin.tsl.js +1 -2
- package/render/fx/patchNodes.tsl.js +6 -16
- package/render/fx/postWebGPU.tsl.js +55 -28
- package/render/fx/sky.tsl.js +34 -109
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/water.tsl.js +1 -1
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +14 -0
- package/render/lighting.js +11 -8
- package/render/lightmap.js +142 -0
- package/render/lights.js +26 -204
- package/render/lit.js +24 -0
- package/render/materials.js +47 -162
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/neutral.js +23 -0
- package/render/occlusion.js +200 -0
- package/render/ownFrame.js +5 -5
- package/render/patches.js +46 -41
- package/render/postWebGL.js +19 -9
- package/render/probes.js +182 -128
- package/render/recordSweep.js +117 -0
- package/render/shaderErrors.js +10 -9
- package/render/shadowCache.tsl.js +107 -0
- package/render/shadowTypes.js +9 -0
- package/render/shadows.js +451 -0
- package/render/slots.js +11 -11
- package/render/terms.js +63 -113
- package/render/uniformDecl.js +2 -2
- package/types/core.d.ts +489 -405
- package/types/gameplay.d.ts +225 -114
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +23 -8
- package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
- package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
- package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +7 -15
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/engine/page.d.ts +24 -0
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +21 -10
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +16 -8
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +4 -3
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +4 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +37 -13
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +2 -1
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +1 -1
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +18 -16
- package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
- package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
- package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
- package/types/generated/modules/calendar/Calendar.d.ts +10 -11
- package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
- package/types/generated/modules/grid/Layer.d.ts +9 -1
- package/types/generated/modules/grid/index.d.ts +32 -8
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +14 -7
- package/types/generated/modules/sky/Sky.d.ts +101 -23
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +2 -1
- package/types/generated/modules/water/Water.d.ts +51 -3
- package/types/generated/modules/weather/Weather.d.ts +44 -10
- package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
- package/types/generated/modules/world/World.d.ts +7 -5
- package/types/generated/render/PostFX.d.ts +69 -20
- package/types/generated/render/lighting.d.ts +29 -0
- package/types/generated/render/materials.d.ts +20 -44
- package/types/generated/render/occlusion.d.ts +22 -0
- package/types/generated/render/patches.d.ts +1 -0
- package/types/generated/ui/Focus.d.ts +1 -0
- package/types/generated/ui/UI.d.ts +1 -0
- package/types/nav.d.ts +11 -11
- package/types/physics.d.ts +104 -73
- package/types/tsl.d.ts +45 -4
- package/types/world.d.ts +372 -86
- package/ui/Focus.js +21 -10
- package/ui/LoadingScreen.js +2 -2
- package/ui/Parts.js +12 -7
- package/ui/UI.js +17 -17
- package/ui/cursor.js +1 -1
- package/ui/defaults.js +3 -2
- package/ui/theme.js +36 -28
- package/ui/touchPart.js +1 -1
- package/core/UrlState.js +0 -110
- package/core/assetEntry.js +0 -106
- package/core/describeRender.js +0 -71
- package/core/holds.js +0 -134
- package/core/look/coreParts.js +0 -219
- package/core/look/part.js +0 -253
- package/core/look/points.js +0 -255
- package/core/look/report.js +0 -96
- package/core/look/shadowPart.js +0 -63
- package/core/look/state.js +0 -45
- package/core/look/write.js +0 -70
- package/core/page.js +0 -79
- package/core/shadowTypes.js +0 -16
- package/core/styleParts.js +0 -114
- package/core/util.js +0 -17
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -228
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/PERF.md +0 -245
- package/docs/api/style.md +0 -136
- package/docs/api/terrainLook.md +0 -10
- package/docs/api/vegetationLook.md +0 -10
- package/docs/api/weatherLook.md +0 -10
- package/docs/recipes/09-style.md +0 -218
- package/docs/recipes/35-style-from-reference.md +0 -153
- package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
- package/docs/recipes/37-terrain-look-hooks.md +0 -119
- package/docs/recipes/38-environment-look-hooks.md +0 -99
- package/docs/recipes/41-thing-registry.md +0 -97
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/44-water-weather-look-hooks.md +0 -144
- package/docs/recipes/47-island-snow-backdrop.md +0 -45
- package/docs/recipes/48-make-material.md +0 -75
- package/docs/recipes/52-look.md +0 -282
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/action/look.js +0 -5
- package/examples/sheepisland/.threedog/content-index.json +0 -1
- package/examples/sheepisland/style/index.js +0 -79
- package/examples/styletest/look.js +0 -11
- package/examples/techniques/day-night-grade/dayNightGrade.js +0 -76
- package/examples/webgpu-tsl/tslScene.js +0 -75
- package/examples/world/style/index.js +0 -61
- package/examples/world/style/plugins/10-bloom.js +0 -5
- package/modules/sky/cascades.js +0 -186
- package/modules/sky/cascades.tsl.js +0 -82
- package/modules/sky/look.js +0 -54
- package/modules/sky/lookFog.js +0 -76
- package/modules/sky/lookShadow.js +0 -62
- package/modules/sky/lookSky.js +0 -169
- package/modules/sky/shadow.js +0 -98
- package/modules/terrain/look.js +0 -83
- package/modules/terrain/lookGround.js +0 -66
- package/modules/vegetation/look.js +0 -119
- package/modules/vegetation/lookWind.js +0 -98
- package/modules/water/look.js +0 -91
- package/modules/water/surfaceDefaults.js +0 -3
- package/modules/weather/look.js +0 -74
- package/modules/weather/weatherLook.js +0 -135
- package/render/lookGlow.js +0 -139
- package/render/lookSurface.js +0 -224
- package/render/postLook.js +0 -164
- package/render/surface.js +0 -105
- package/types/generated/core/page.d.ts +0 -18
- package/types/generated/modules/weather/weatherLook.d.ts +0 -12
- package/types/style.d.ts +0 -671
- /package/core/{Vars.js → base/Vars.js} +0 -0
- /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
- /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
- /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
- /package/core/{actor.js → ops/actor.js} +0 -0
- /package/core/{opsFail.js → ops/opsFail.js} +0 -0
- /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
- /package/core/{saveIds.js → saves/saveIds.js} +0 -0
- /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
- /package/core/{cells.js → stream/cells.js} +0 -0
- /package/core/{streamCells.js → stream/streamCells.js} +0 -0
- /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
- /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// engine.assets.manifest(pack) (helper of Assets.js): registers the named models, textures, sounds and fonts of an asset pack. `a` is the Assets instance.
|
|
2
|
-
import { fmt, warnOnce } from '
|
|
3
|
-
import { codedError } from '
|
|
4
|
-
import { parseSchema, readParams, keysSchema } from '
|
|
2
|
+
import { fmt, warnOnce, BASE_URL } from '../base/validate.js';
|
|
3
|
+
import { codedError } from '../base/errorHints.js';
|
|
4
|
+
import { parseSchema, readParams, keysSchema } from '../base/params.js';
|
|
5
5
|
|
|
6
6
|
const STRINGS = {
|
|
7
7
|
clash: 'assets.manifest(): "{name}" is already registered as a {was} (manifest "{list}"), and now as a {type}; one name is one asset, ' +
|
|
@@ -15,7 +15,7 @@ const MANIFEST_KEYS = ['name', 'base', 'models', 'textures', 'sounds', 'fonts'];
|
|
|
15
15
|
const FONT_KEYS = ['url', 'family', 'weight', 'style', 'stretch', 'unicodeRange', 'display', 'featureSettings', 'variationSettings', 'critical', 'preload'];
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* hot: { changed: [] } = a dev hot swap (core/assetHot.js) registering the edited packs again: an entry whose build function and url are unchanged
|
|
18
|
+
* hot: { changed: [] } = a dev hot swap (core/assets/assetHot.js) registering the edited packs again: an entry whose build function (or Texture) and url are unchanged
|
|
19
19
|
* is kept as it is (loaded value and all, so nothing reloads), a changed one is replaced and pushed to changed as { name, type, old } for the swap;
|
|
20
20
|
* no "replaced" warning, since the same pack coming back is not a mod overriding it
|
|
21
21
|
*/
|
|
@@ -25,25 +25,36 @@ export function registerManifest(a, pack, hot = null) {
|
|
|
25
25
|
readParams('assets.manifest()', keysSchema(MANIFEST_KEYS), pack);
|
|
26
26
|
const { models = {}, textures = {}, sounds = {}, fonts = {}, base = null } = pack, list = pack.name ?? 'manifest#' + (a._lists = (a._lists || 0) + 1);
|
|
27
27
|
const at = base == null ? null : new URL(String(base).replace(/\/?$/, '/'), location.href);
|
|
28
|
-
|
|
28
|
+
// '/models/x.glb' means the game's public/ folder, which a build with --base /my-game/ serves under that path (recipes/61-deploy.md): vite
|
|
29
|
+
// rewrites bundled URLs only, never these strings, so a game deployed under a sub-path asked the site root for every asset
|
|
30
|
+
const resolve = u => typeof u !== 'string' || /^[a-z][a-z\d+.-]*:/i.test(u) || u.startsWith('//') ? u
|
|
31
|
+
: u.startsWith('/') ? BASE_URL + u.slice(1) : at ? new URL(u, at).href : u;
|
|
29
32
|
const add = (type, map) => {
|
|
30
33
|
for (const [name, v] of Object.entries(map)) {
|
|
31
34
|
const o0 = typeof v === 'string' ? { url: v } : typeof v === 'function' ? { build: v } : v?.isTexture && type === 'texture' ? { texture: v } : v;
|
|
32
35
|
if (type === 'font') readParams(`assets.manifest() fonts.${name}`, keysSchema(FONT_KEYS), o0);
|
|
33
|
-
const o = o0.url
|
|
36
|
+
const o = o0.url ? { ...o0, url: resolve(o0.url), ...(o0.lods && { lods: o0.lods.map(resolve) }) } : o0;
|
|
34
37
|
const old = a.entries.get(name);
|
|
35
|
-
// a model's params is a schema (core/params.js format, parsed here so a bad spec fails at registration, naming the field)
|
|
38
|
+
// a model's params is a schema (core/base/params.js format, parsed here so a bad spec fails at registration, naming the field)
|
|
36
39
|
const schema = type === 'model' && o.params ? parseSchema(`assets.manifest() models.${name}.params`, o.params) : null;
|
|
37
40
|
if (hot && old?.named && old.type === type) {
|
|
38
|
-
if (old.opts.build === o.build && old.url === (o.url ?? name) && JSON.stringify(old.opts.params ?? null) === JSON.stringify(o.params ?? null)) continue;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
if (old.opts.build === o.build && old.opts.texture === o.texture && old.url === (o.url ?? name) && JSON.stringify(old.opts.params ?? null) === JSON.stringify(o.params ?? null)) continue;
|
|
42
|
+
const was = { ...old }; // the swap pairs the old data with the new
|
|
43
|
+
a._retire(old);
|
|
44
|
+
Object.assign(old, { url: o.url ?? name, opts: o, schema });
|
|
45
|
+
hot.changed.push({ name, type, old: was });
|
|
41
46
|
continue;
|
|
42
47
|
}
|
|
43
48
|
if (old?.named && !old.builtIn && old.type !== type) throw codedError('asset-name-clash', fmt(STRINGS.clash, { name, was: old.type, list: old.manifest, type }));
|
|
44
49
|
// same type from another manifest: allowed (a mod overriding a model) but never silent, the two packs may just share a name by accident
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
// the pack named 'optimized' (written by `threedog assets optimize`) exists to replace the originals, so that override is no accident
|
|
51
|
+
if (old?.named && !old.builtIn && old.manifest !== list && list !== 'optimized') warnOnce(fmt(STRINGS.replaced, { type, name, was: old.manifest, list }));
|
|
52
|
+
const fresh = { type, name, url: o.url ?? name, opts: o, schema, promise: null, named: true, manifest: list };
|
|
53
|
+
if (!old) { a.entries.set(name, fresh); continue; }
|
|
54
|
+
// the same object, rewritten: code awaiting the old registration lands on the new one, and copies already out still count here
|
|
55
|
+
a._retire(old);
|
|
56
|
+
for (const k of Object.keys(old)) if (k !== 'users') delete old[k];
|
|
57
|
+
Object.assign(old, fresh);
|
|
47
58
|
}
|
|
48
59
|
};
|
|
49
60
|
add('model', models); add('texture', textures); add('sound', sounds); add('font', fonts);
|
|
@@ -4,8 +4,11 @@
|
|
|
4
4
|
// Color-space basis: three's color management manual. Color slots (map, emissiveMap) hold sRGB, data slots (normal, roughness, metalness, ao...) stay linear.
|
|
5
5
|
import * as THREE from 'three';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
// The one slot table: engine.assets.report and engine.inspect.materials judge a texture by it. A lightMap holds light, not a color or a value: a linear bake and an sRGB
|
|
8
|
+
// picture are both right, so it is in neither list
|
|
9
|
+
export const COLOR_SLOTS = ['map', 'emissiveMap', 'specularColorMap', 'sheenColorMap'];
|
|
10
|
+
export const DATA_SLOTS = ['normalMap', 'roughnessMap', 'metalnessMap', 'aoMap', 'bumpMap', 'alphaMap', 'displacementMap', 'specularMap', 'specularIntensityMap', 'clearcoatMap', 'clearcoatNormalMap',
|
|
11
|
+
'clearcoatRoughnessMap', 'transmissionMap', 'thicknessMap', 'iridescenceMap', 'anisotropyMap', 'sheenRoughnessMap'];
|
|
9
12
|
const SRGB = THREE.SRGBColorSpace, LINEAR = THREE.NoColorSpace;
|
|
10
13
|
// three's PropertyBinding.sanitizeNodeName: the name the engine sees ("door.001" -> "door001")
|
|
11
14
|
const sanitize = n => String(n ?? '').replace(/\s/g, '_').replace(/[[\].:/]/g, '');
|
|
@@ -37,12 +40,12 @@ export function reportGltf(gltf, entry = {}, root = gltf.scene, renderer) {
|
|
|
37
40
|
});
|
|
38
41
|
const mats = [...materials].map(m => {
|
|
39
42
|
const maps = {};
|
|
40
|
-
for (const k of [...COLOR_SLOTS, ...DATA_SLOTS]) if (m[k]?.isTexture) {
|
|
41
|
-
maps[k] = m[k].colorSpace || LINEAR
|
|
43
|
+
for (const k of [...COLOR_SLOTS, ...DATA_SLOTS, 'lightMap']) if (m[k]?.isTexture) {
|
|
44
|
+
maps[k] = m[k].colorSpace || 'none'; // not LINEAR: NoColorSpace is '', so a correct data map read as absent and every intact normal map was reported lost
|
|
42
45
|
const t = textures.get(m[k]) ?? textures.set(m[k], { name: m[k].name || '(unnamed)', slots: [] }).get(m[k]);
|
|
43
46
|
if (!t.slots.includes(k)) t.slots.push(k);
|
|
44
47
|
}
|
|
45
|
-
return { name: m.name || '(unnamed)', type: m.type, maps, flatShading: !!m.flatShading, vertexColors: !!m.vertexColors,
|
|
48
|
+
return { name: m.name || '(unnamed)', type: m.type, maps, flatShading: !!m.flatShading, vertexColors: !!m.vertexColors, madeByEngine: !!m.userData?.purpose };
|
|
46
49
|
});
|
|
47
50
|
const texList = [...textures].map(([t, v]) => ({ ...v, colorSpace: t.colorSpace || LINEAR, problems: colorSpaceIssues(t, v.slots) }));
|
|
48
51
|
for (const t of texList) for (const p of t.problems) flag('warn', 'color-space', `texture ${t.name}: ${p}`);
|
|
@@ -57,7 +60,7 @@ export function reportGltf(gltf, entry = {}, root = gltf.scene, renderer) {
|
|
|
57
60
|
if (fm.pbrMetallicRoughness?.baseColorTexture && !live.maps.map) flag('warn', 'base-color-lost', `material "${live.name}" has a base color texture in the file but none in the scene`);
|
|
58
61
|
if (fm.pbrMetallicRoughness?.metallicRoughnessTexture && !live.maps.roughnessMap && !live.maps.metalnessMap) flag('warn', 'metal-rough-lost', `material "${live.name}" has a metallic-roughness texture in the file but none in the scene`);
|
|
59
62
|
if (live.flatShading) flag('warn', 'flat-shading', `material "${live.name}" is flat shaded; the file asks for smooth normals`);
|
|
60
|
-
if (live.
|
|
63
|
+
if (live.madeByEngine) flag('warn', 'material-replaced', `material "${live.name}" was made by the engine, not read from the file`);
|
|
61
64
|
}
|
|
62
65
|
for (const a of json.animations || []) if (!clips.some(c => c.name === a.name)) flag('warn', 'clip-lost', `file clip "${a.name}" did not load`);
|
|
63
66
|
const names = new Set(nodes.map(sanitize)), gone = (json.nodes || []).map(n => sanitize(n.name)).filter(n => n && !names.has(n));
|
|
@@ -72,12 +75,3 @@ export function reportGltf(gltf, entry = {}, root = gltf.scene, renderer) {
|
|
|
72
75
|
materials: mats, textures: texList, clips, colliders, templates, issues,
|
|
73
76
|
};
|
|
74
77
|
}
|
|
75
|
-
|
|
76
|
-
/** Text for the console / describe: one block, issues last */
|
|
77
|
-
export function reportText(r) {
|
|
78
|
-
const c = r.counts, L = [`model ${r.name ?? r.url}${r.fromFile ? '' : ' (built in code: no file to compare with)'}: ${c.nodes} nodes · ${c.materials} materials · ${c.textures} textures (${c.normalMaps} normal maps) · ${c.clips} clips · ${c.colliders} col_ · ${c.templates} template/id nodes`];
|
|
79
|
-
for (const m of r.materials) L.push(` material ${m.name} (${m.type}${m.flatShading ? ', flat' : ''}${m.madeByStyle ? ', from style' : ''}) ${Object.entries(m.maps).map(([k, v]) => `${k}:${v}`).join(' ') || 'no textures'}`);
|
|
80
|
-
for (const c of r.clips) L.push(` clip ${c.name} ${c.seconds}s`);
|
|
81
|
-
for (const i of r.issues) L.push(` ${i.severity === 'warn' ? '!' : '·'} [${i.code}] ${i.msg}`);
|
|
82
|
-
return L.join('\n');
|
|
83
|
-
}
|
|
@@ -2,31 +2,35 @@
|
|
|
2
2
|
// vegetation.define all resolve a model name here, so caching (baked file -> dev cache -> build), the per-name prototype and the shadow rule exist once.
|
|
3
3
|
// It lives in core because several modules need it and none of them owns it (content, inventory, vegetation): no module depends on another for it.
|
|
4
4
|
import * as THREE from 'three';
|
|
5
|
-
import {
|
|
5
|
+
import { neutralMaterial } from '../../render/neutral.js';
|
|
6
6
|
import { shadowDefaults } from './assetEntry.js';
|
|
7
7
|
import { paramValues } from './assetManifest.js';
|
|
8
|
-
|
|
9
|
-
/** One value or a list, as a list @internal */
|
|
10
|
-
export const list = v => (Array.isArray(v) ? v : [v]);
|
|
8
|
+
import { list } from '../base/util.js';
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
11
|
* A model name (name or [name, params...]) whose asset entry is a generator (an asset pack's procedural model) goes through assets.cached:
|
|
14
12
|
* name = model name, params count into the cache key. Returns a Promise (geometry or Object3D); null for a file model or an unknown name (assets.model takes those)
|
|
15
13
|
*/
|
|
16
14
|
export function cachedModel(e, m) {
|
|
17
|
-
const [name
|
|
15
|
+
const [name] = list(m), fn = e.assets.builder(name);
|
|
18
16
|
if (!fn) return null;
|
|
19
|
-
// every model asked for by name is remembered, so a dev hot swap (core/assetHot.js) can build the same name + params list again
|
|
17
|
+
// every model asked for by name is remembered, so a dev hot swap (core/assets/assetHot.js) can build the same name + params list again
|
|
20
18
|
const made = (e.assets._made ||= new Map());
|
|
21
19
|
(made.get(name) ?? made.set(name, new Map()).get(name)).set(JSON.stringify(m), m);
|
|
22
|
-
|
|
23
|
-
const entry = e.assets.entries.get(name), args = entry?.schema ? [paramValues(entry, args0[0])] : args0;
|
|
20
|
+
const args = builderArgs(e, m);
|
|
24
21
|
// pass the generator function to cached as is (dev cache hashes its source); wrap only when there are several params
|
|
25
|
-
|
|
22
|
+
if (args.length < 2) return e.assets.cached(name, fn, args[0]);
|
|
23
|
+
const spread = function (p) { return fn.apply(this, p); };
|
|
24
|
+
spread.toString = () => String(fn); // the cache keys on the source text: the wrapper's own text never changes, so an edit to fn would keep serving the old model
|
|
25
|
+
return e.assets.cached(name, spread, args);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** What a generator is called with for a model name: a generator with a params schema gets one object, defaults < dev panel values < the call's own object (assetManifest.js paramValues) @internal */
|
|
29
|
+
export function builderArgs(e, m) {
|
|
30
|
+
const [name, ...args] = list(m), entry = e.assets.entries.get(name);
|
|
31
|
+
return entry?.schema ? [paramValues(entry, args[0])] : args;
|
|
26
32
|
}
|
|
27
33
|
|
|
28
|
-
/** A model name in model / lod position: 'pine' or ['flower', 0xff0000] (content data and vegetation.define take the same form) @internal */
|
|
29
|
-
export const isModelName = m => typeof m === 'string' || Array.isArray(m) && typeof m[0] === 'string';
|
|
30
34
|
/**
|
|
31
35
|
* A vegetation model by name: { geometry } for a generator that returns geometry or for a file model (its first mesh), { model } for a generator
|
|
32
36
|
* that returns an Object3D (one material per mesh kept). content's vegetation table and vegetation.define(name, { model: 'pine' }) both resolve here,
|
|
@@ -40,30 +44,34 @@ export async function vegetationModel(e, m) {
|
|
|
40
44
|
// One prototype per model name: a generator entry -> assets.cached (baked file / dev cache); a file entry -> assets.model. Content names models only (no paths).
|
|
41
45
|
// The only entry for "reuse a code-made model by name": content props / templates / vegetation and ground pickups all take it from here, so cache, bake and shadow rules exist once.
|
|
42
46
|
const protos = new WeakMap(); // owner (engine.content, or the inventory for pickups) → Map(model key → Promise<{ obj, size, center, fromGeometry }>)
|
|
47
|
+
const protoPalette = new WeakMap(); // prototype promise → the palette it was built from (null for a file model)
|
|
43
48
|
const owners = new WeakMap(); // engine → Set(owner): a hot swap walks every owner's prototypes of a changed name
|
|
44
|
-
/** Every prototype cache of this engine: [{ api, cache }] (cache: model key → Promise of the prototype). For core/assetHot.js @internal */
|
|
49
|
+
/** Every prototype cache of this engine: [{ api, cache }] (cache: model key → Promise of the prototype). For core/assets/assetHot.js @internal */
|
|
45
50
|
export const protoCaches = e => [...(owners.get(e) ?? [])].map(api => ({ api, cache: protos.get(api) }));
|
|
46
51
|
/**
|
|
47
52
|
* The shared prototype of a model name (or [name, ...params]): { obj, size, center, fromGeometry }. fromGeometry: the generator returned a bare
|
|
48
|
-
* geometry, wrapped here in a mesh of
|
|
53
|
+
* geometry, wrapped here in a mesh of neutral gray; a caller with a material of its own (pickups) swaps that one. @internal
|
|
49
54
|
*/
|
|
50
55
|
export function protoOf(e, api, model) {
|
|
51
56
|
if (!protos.has(api)) protos.set(api, new Map());
|
|
52
57
|
(owners.get(e) ?? owners.set(e, new Set()).get(e)).add(api);
|
|
53
|
-
const cache = protos.get(api), key = JSON.stringify(model);
|
|
58
|
+
const cache = protos.get(api), key = JSON.stringify(model), palette = e.assets.builder(list(model)[0]) ? e.assets._paletteKey : null;
|
|
59
|
+
// a palette written since this prototype was built: the next placement builds again, the same rule assets.cached has by its key
|
|
60
|
+
if (cache.has(key) && protoPalette.get(cache.get(key)) !== palette) cache.delete(key);
|
|
54
61
|
if (!cache.has(key)) {
|
|
55
62
|
const gen = cachedModel(e, model);
|
|
56
63
|
cache.set(key, (gen ? gen.then(r => {
|
|
57
|
-
const p = r.isObject3D ? r : new THREE.Mesh(r,
|
|
64
|
+
const p = r.isObject3D ? r : new THREE.Mesh(r, neutralMaterial('prop', { vertexColors: !!r.attributes.color }));
|
|
58
65
|
if (!r.isObject3D) p.userData.fromGeometry = true;
|
|
59
66
|
// the generator's own castShadow / receiveShadow are kept (a decal or flat rug that must not cast); the manifest entry can set them;
|
|
60
|
-
// a generator that set none gets cast + receive. Same rule as assets.model (core/assetEntry.js shadowDefaults)
|
|
67
|
+
// a generator that set none gets cast + receive. Same rule as assets.model (core/assets/assetEntry.js shadowDefaults)
|
|
61
68
|
return shadowDefaults(p, e.assets.entries.get(list(model)[0])?.opts);
|
|
62
69
|
}) : e.assets.model(list(model)[0])).then(obj => {
|
|
63
70
|
const box = new THREE.Box3().setFromObject(obj); // collision and the "build within what distance" check both use the prototype's bounding box, computed once
|
|
64
71
|
obj.userData.modelKey = key; // copies carry it (clone copies userData): a hot swap whose new model has other parts finds them by it
|
|
65
72
|
return { obj, size: box.getSize(new THREE.Vector3()), center: box.getCenter(new THREE.Vector3()), fromGeometry: !!obj.userData.fromGeometry };
|
|
66
73
|
}));
|
|
74
|
+
protoPalette.set(cache.get(key), palette);
|
|
67
75
|
}
|
|
68
76
|
return cache.get(key);
|
|
69
77
|
}
|
|
@@ -6,16 +6,14 @@
|
|
|
6
6
|
// Usage: recipes/31-audio.md.
|
|
7
7
|
// Browsers only allow sound after the first click/keypress; this waits for it automatically.
|
|
8
8
|
|
|
9
|
-
/** @import {
|
|
10
|
-
import { codedError } from '
|
|
11
|
-
import { missingText, warnOnce } from '
|
|
12
|
-
import { readParams
|
|
9
|
+
/** @import { AudioCondition, AudioVolume } from '../../types/core' */
|
|
10
|
+
import { codedError, coded } from '../base/errorHints.js';
|
|
11
|
+
import { missingText, warnOnce } from '../base/validate.js';
|
|
12
|
+
import { readParams } from '../base/params.js';
|
|
13
13
|
import { SoundHandle, playSound, placeListener, synthNoise, synthTone, loadSound, playFile, soundDef } from './audioVoice.js';
|
|
14
14
|
import { matchesWhen, volumeOf, checkRuleName, packAudio, applyDucks, audioInfo } from './audioRules.js';
|
|
15
15
|
// createEngine({ audio }) schema: unknown keys throw in dev with did-you-mean. Object / array defaults are not kept here: they would be shared by all engines as one object
|
|
16
16
|
const AUDIO_PARAMS = { levels: 'object?', sounds: 'object?', ambience: 'array?', music: 'object?', footsteps: 'object?' };
|
|
17
|
-
// Values inside music come in many shapes (duckDialogue is a number or false), so only key spelling is checked here; music() checks the values itself
|
|
18
|
-
const MUSIC_PARAMS = keysSchema(['tracks', 'rules', 'fade', 'duckDialogue', 'duckFade', 'hold', 'interval']);
|
|
19
17
|
const BUS_PARAMS = { level: { type: 'number', default: 1, min: 0, desc: 'bus volume 0-1' }, owner: 'string?' };
|
|
20
18
|
const DUCK_PARAMS = { fade: { type: 'number', default: 0.3, min: 0, desc: 'fade seconds both ways' } };
|
|
21
19
|
const DEFAULT_LEVELS = { master: 0.8, music: 0.5, sfx: 0.8, ambience: 0.7, ui: 0.8 };
|
|
@@ -25,8 +23,6 @@ export class Audio {
|
|
|
25
23
|
/** @internal */
|
|
26
24
|
constructor(engine, opts = {}) {
|
|
27
25
|
const { levels = {}, sounds = {}, ambience = [], music = {}, footsteps = {} } = readParams('createEngine({ audio })', AUDIO_PARAMS, opts);
|
|
28
|
-
// a typo (trakcs) would just play nothing
|
|
29
|
-
readParams('createEngine({ audio: { music } })', MUSIC_PARAMS, music);
|
|
30
26
|
/** @internal */ this.engine = engine;
|
|
31
27
|
/** The browser AudioContext (exists only after the first click) @type {any} */
|
|
32
28
|
this.ctx = null;
|
|
@@ -35,15 +31,18 @@ export class Audio {
|
|
|
35
31
|
/**
|
|
36
32
|
* The game's sound config from createEngine({ audio }); sounds and footsteps also hold content packs' (copies: the game's object is never changed).
|
|
37
33
|
* Content packs' ambience / music rules go to ambience() / music(), not here
|
|
38
|
-
* @type {import('
|
|
34
|
+
* @type {import('../../types/core').AudioConfig}
|
|
39
35
|
*/
|
|
40
36
|
for (const [n, v] of Object.entries(sounds)) soundDef(n, v); // the old synth forms fail here, at createEngine, not at the first play
|
|
41
37
|
this.config = { sounds: { ...sounds }, ambience, music, footsteps: { ...footsteps } };
|
|
42
|
-
/** Bus input GainNodes by name (connect your own nodes here); empty until audio unlocks @type {Record<string, any>} */
|
|
43
|
-
this.buses = {}
|
|
38
|
+
/** Bus input GainNodes by name, 'master' included (connect your own nodes here); empty until audio unlocks. A name that is no bus warns and gives master: node.connect(undefined) would throw, and in dev a throw freezes gameplay @type {Record<string, any>} */
|
|
39
|
+
this.buses = new Proxy({}, { get: (t, k) => {
|
|
40
|
+
if (typeof k !== 'string' || k in t || k === 'toJSON' || k === 'then') return t[k];
|
|
41
|
+
warnOnce(coded('unknown-name', this.master ? `audio.buses.${k} is not a bus, so master was given instead. Buses: ${Object.keys(t).join(', ')}` : `audio.buses.${k}: buses are empty until audio unlocks; connect after the 'audio:ready' event`), `audio-bus-${k}`);
|
|
42
|
+
return this.master;
|
|
43
|
+
} });
|
|
44
44
|
/** The game's current mode for rule lists, e.g. 'combat' / 'explore' (condition `state` in music and ambience rules) @type {string | null} */
|
|
45
45
|
this.state = null;
|
|
46
|
-
/** @internal */ this.buffers = new Map();
|
|
47
46
|
/** @internal */ this.conditions = new Map([['state', v => [].concat(v).includes(this.state)]]);
|
|
48
47
|
/** @internal name -> (engine) => number: values rule data compares ({ daylight: { gt: 0.15 } }) and data volumes add up */
|
|
49
48
|
this.measures = new Map();
|
|
@@ -60,8 +59,9 @@ export class Audio {
|
|
|
60
59
|
/** @internal */ this._readySent = false;
|
|
61
60
|
// Create or resume audio on the first click/keypress (a context created earlier is suspended and must be resumed inside a user gesture)
|
|
62
61
|
const stop = new AbortController(), signal = AbortSignal.any([stop.signal, engine.signal]); // remove after unlocking once, or when the engine is disposed
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
// given up only once it worked: a touch pointerdown or Escape is no activation for the browser, and the pointerup after it is
|
|
63
|
+
const unlock = () => { this._init(); this.ctx?.resume().then(() => stop.abort(), () => {}); };
|
|
64
|
+
for (const ev of ['pointerdown', 'pointerup', 'keydown']) addEventListener(ev, unlock, { signal });
|
|
65
65
|
}
|
|
66
66
|
/** @internal Close the audio context (engine.dispose calls it): playing sounds and nodes modules attached stop together */
|
|
67
67
|
dispose() { this.ctx?.close(); this.ctx = null; }
|
|
@@ -73,7 +73,7 @@ export class Audio {
|
|
|
73
73
|
if (!AC) return;
|
|
74
74
|
const ctx = this.ctx = new AC();
|
|
75
75
|
/** The master GainNode (every bus ends here) @type {any} */
|
|
76
|
-
this.master = ctx.createGain(); this.master.gain.value = this.levels.master; this.master.connect(ctx.destination);
|
|
76
|
+
this.master = this.buses.master = ctx.createGain(); this.master.gain.value = this.levels.master; this.master.connect(ctx.destination);
|
|
77
77
|
for (const name of Object.keys(this.levels)) if (name !== 'master') this._makeBus(name);
|
|
78
78
|
this._applyDucks(0);
|
|
79
79
|
const len = ctx.sampleRate * 2, buf = ctx.createBuffer(1, len, ctx.sampleRate), d = buf.getChannelData(0);
|
|
@@ -89,7 +89,7 @@ export class Audio {
|
|
|
89
89
|
g.gain.value = this.levels[name]; g.connect(d).connect(this.master);
|
|
90
90
|
this.buses[name] = g; this._duckNodes[name] = d;
|
|
91
91
|
}
|
|
92
|
-
/** Is audio usable (the player has clicked/pressed a key)? @returns {boolean} */
|
|
92
|
+
/** Is audio usable (the player has clicked/pressed a key)? @returns {boolean} @experimental */
|
|
93
93
|
get running() { return this.ctx?.state === 'running'; }
|
|
94
94
|
/** @internal */
|
|
95
95
|
_warn(msg) { warnOnce(msg); }
|
|
@@ -116,7 +116,7 @@ export class Audio {
|
|
|
116
116
|
return { owner, remove: () => {
|
|
117
117
|
if (!(name in this.levels)) return;
|
|
118
118
|
delete this.levels[name];
|
|
119
|
-
this.buses[name]
|
|
119
|
+
if (this.ctx) { this.buses[name].disconnect(); this._duckNodes[name].disconnect(); } // sounds still playing on this bus are cut with the node (bus gone, no sound should linger)
|
|
120
120
|
delete this.buses[name]; delete this._duckNodes[name];
|
|
121
121
|
} };
|
|
122
122
|
}
|
|
@@ -128,7 +128,7 @@ export class Audio {
|
|
|
128
128
|
* @example engine.audio.setVolume('music', 0.3);
|
|
129
129
|
*/
|
|
130
130
|
setVolume(bus, v) {
|
|
131
|
-
if (bus !== 'master') this._bus(bus);
|
|
131
|
+
if (bus !== 'master' && !(bus in this.levels)) this._bus(bus); // throws with the fix; a known bus has no node before audio unlocks, and only its level changes then
|
|
132
132
|
this.levels[bus] = v; if (!this.ctx) return;
|
|
133
133
|
(bus === 'master' ? this.master : this.buses[bus]).gain.value = v;
|
|
134
134
|
}
|
|
@@ -157,7 +157,7 @@ export class Audio {
|
|
|
157
157
|
* @returns {{ remove(): void }}
|
|
158
158
|
* @example engine.audio.condition('inside', v => engine.vars.flag('indoors') === v);
|
|
159
159
|
*/
|
|
160
|
-
condition(name, test) { checkRuleName(this, name, false); this.conditions.set(name, test); return { remove: () => this.conditions.delete(name) }; }
|
|
160
|
+
condition(name, test) { checkRuleName(this, name, false); this.conditions.set(name, test); return { remove: () => { if (this.conditions.get(name) === test) this.conditions.delete(name); } }; }
|
|
161
161
|
/**
|
|
162
162
|
* Add a measure: a number rule data compares (`when: { daylight: { gt: 0.15 } }`; gt / gte / lt / lte) and adds up (`volume: { add: { wind: 0.08 } }`).
|
|
163
163
|
* calendar adds daylight, weather rain / snow / wind, ambience nearWater / altitude. A name is a condition or a measure, not both
|
|
@@ -165,7 +165,7 @@ export class Audio {
|
|
|
165
165
|
* @param {(e: any) => number} fn
|
|
166
166
|
* @returns {{ remove(): void }}
|
|
167
167
|
* @example engine.audio.measure('danger', e => e.vars.counter('alarm') / 10); // data: when: { danger: { gt: 0.5 } }
|
|
168
|
-
* Measures are not only for sound: render/
|
|
168
|
+
* Measures are not only for sound: render/daylight.js reads 'daylight' for night glow, so the calendar (or the sky without one) registers it once
|
|
169
169
|
* and nothing else has to know which module tells day from night. remove() drops only this registration (a later one under the name stays).
|
|
170
170
|
*/
|
|
171
171
|
measure(name, fn) {
|
|
@@ -185,6 +185,7 @@ export class Audio {
|
|
|
185
185
|
* @param {...any} extra
|
|
186
186
|
* @returns {boolean}
|
|
187
187
|
* @example engine.audio.matches({ time: 'night', zone: 'forest', rain: { lt: 0.2 } });
|
|
188
|
+
* @experimental
|
|
188
189
|
*/
|
|
189
190
|
matches(when, ...extra) { return matchesWhen(this, when, extra); }
|
|
190
191
|
/**
|
|
@@ -193,6 +194,7 @@ export class Audio {
|
|
|
193
194
|
* @param {...any} extra
|
|
194
195
|
* @returns {number}
|
|
195
196
|
* @example engine.audio.volumeOf({ base: 0, add: { rain: 0.22 } }); // 0.22 in full rain
|
|
197
|
+
* @experimental
|
|
196
198
|
*/
|
|
197
199
|
volumeOf(volume, ...extra) { return volumeOf(this, volume, extra); }
|
|
198
200
|
/**
|
|
@@ -234,9 +236,10 @@ export class Audio {
|
|
|
234
236
|
for (const v of this._spatial) { if (!v.playing) this._spatial.delete(v); else if (v.follow) v.setPosition(v.follow); }
|
|
235
237
|
}
|
|
236
238
|
/**
|
|
237
|
-
* What is playing (
|
|
239
|
+
* What is playing (describe().audio shows it while something is ducked or playing): bus levels, the duck multiplier per bus, live voices per sound name.
|
|
240
|
+
* ducks is the level the active ducks ask for (1 = not lowered), read at once even while a fade is still ramping or the audio clock does not run (headless page).
|
|
238
241
|
* @returns {{ running: boolean, state: string | null, levels: Record<string, number>, ducks: Record<string, number>, voices: Record<string, number> }}
|
|
239
|
-
* @
|
|
242
|
+
* @example engine.audio.duck({ music: 0.3 }); engine.audio.info.ducks.music // 0.3
|
|
240
243
|
*/
|
|
241
244
|
get info() { return audioInfo(this); }
|
|
242
245
|
|
|
@@ -257,8 +260,8 @@ export class Audio {
|
|
|
257
260
|
|
|
258
261
|
// ---------- audio files ----------
|
|
259
262
|
/**
|
|
260
|
-
* Download and decode an audio file
|
|
261
|
-
* engine.
|
|
263
|
+
* Download and decode an audio file, as an engine.loading task: a path or a sound name from an asset pack (manifest sounds), so sounds entries and music
|
|
264
|
+
* tracks may name assets instead of paths. engine.assets caches it: short effects stay; long sounds go with assets.release / trim or over a memory budget, and load again on next use
|
|
262
265
|
* @param {string} url a file path or an asset pack sound name
|
|
263
266
|
* @returns {Promise<any>}
|
|
264
267
|
*/
|
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
// Why measures: a content pack is data, so `when: e => e.calendar.daylight > 0.15` cannot live in it. A module registers the number once
|
|
6
6
|
// (calendar: daylight; weather: rain, snow, wind; ambience: nearWater, altitude) and data compares it: `when: { daylight: { gt: 0.15 } }`,
|
|
7
7
|
// `volume: { base: 0.05, add: { wind: 0.08 }, max: 0.5 }`. Code may still pass functions (createEngine({ audio }), ambience.add).
|
|
8
|
-
import { codedError, coded } from '
|
|
9
|
-
import { DEV, fmt, missingText, warnOnce } from '
|
|
10
|
-
import { readParams, keysSchema } from '
|
|
8
|
+
import { codedError, coded } from '../base/errorHints.js';
|
|
9
|
+
import { DEV, fmt, missingText, warnOnce } from '../base/validate.js';
|
|
10
|
+
import { readParams, keysSchema } from '../base/params.js';
|
|
11
|
+
import { isObject } from '../base/util.js';
|
|
11
12
|
|
|
12
13
|
const COMPARE = { gt: (x, v) => x > v, gte: (x, v) => x >= v, lt: (x, v) => x < v, lte: (x, v) => x <= v };
|
|
13
14
|
const VOLUME_KEYS = ['base', 'add', 'min', 'max'];
|
|
@@ -32,7 +33,7 @@ const hasFn = v => typeof v === 'function' || (v !== null && typeof v === 'objec
|
|
|
32
33
|
|
|
33
34
|
/** Does a measure comparison hold? cmp = { gt: 0.15 } / { lt: 0.2, gte: 0 } (every key must hold) */
|
|
34
35
|
function compare(audio, key, cmp) {
|
|
35
|
-
const ok =
|
|
36
|
+
const ok = isObject(cmp) && Object.keys(cmp).length && Object.keys(cmp).every(k => k in COMPARE);
|
|
36
37
|
if (!ok) { warnOnce(fmt(STRINGS.compare, { key, got: JSON.stringify(cmp) })); return false; }
|
|
37
38
|
const x = audio.measures.get(key)(audio.engine);
|
|
38
39
|
return Object.entries(cmp).every(([k, v]) => COMPARE[k](x, v));
|
|
@@ -117,7 +118,9 @@ export function applyDucks(a, fade) {
|
|
|
117
118
|
/** What is playing: bus levels, duck multipliers, live voices per sound name (Audio.info) */
|
|
118
119
|
export function audioInfo(a) {
|
|
119
120
|
const ducks = {}, voices = {};
|
|
120
|
-
|
|
121
|
+
// the TARGET multiplier (every active duck's level multiplied), not the node's gain right now: a duck with a fade ramps on the audio clock, which stands
|
|
122
|
+
// still on a headless page, so the node would read 1 for ever there. The target is what the game asked for, and what the ramp ends at
|
|
123
|
+
for (const b of Object.keys(a._duckNodes)) { let v = 1; for (const d of a._ducks) v *= d.levels[b] ?? 1; ducks[b] = +v.toFixed(3); }
|
|
121
124
|
for (const [name, list] of a._voices) { const n = list.filter(v => v.playing).length; if (n) voices[name] = n; }
|
|
122
125
|
return { running: a.running, state: a.state, levels: { ...a.levels }, ducks, voices };
|
|
123
126
|
}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// Split out of Audio.js so the bus / config side and the per-sound side each stay small enough to read in one go.
|
|
3
3
|
// Randomness here (variant pick, jitter) only changes what is heard, never gameplay, so it uses Math.random and carries // presentation.
|
|
4
4
|
import * as THREE from 'three';
|
|
5
|
-
import { xzOf } from '
|
|
6
|
-
import { warnOnce, fmt } from '
|
|
7
|
-
import { readParams, keysSchema } from '
|
|
8
|
-
import { codedError } from '
|
|
9
|
-
import {
|
|
5
|
+
import { xzOf } from '../base/math.js';
|
|
6
|
+
import { warnOnce, fmt } from '../base/validate.js';
|
|
7
|
+
import { readParams, keysSchema } from '../base/params.js';
|
|
8
|
+
import { codedError } from '../base/errorHints.js';
|
|
9
|
+
import { isObject } from '../base/util.js';
|
|
10
10
|
|
|
11
11
|
const SFX_KEYS = ['volume', 'pitch', 'at', 'bus', 'loop', 'params', 'fadeIn'];
|
|
12
12
|
const jit = (v, j) => v * (1 + (Math.random() * 2 - 1) * (j || 0)); // presentation
|
|
@@ -26,14 +26,14 @@ const _v = new THREE.Vector3(), _d = new THREE.Vector3(), _u = new THREE.Vector3
|
|
|
26
26
|
export function soundDef(name, v) {
|
|
27
27
|
if (v == null) return null;
|
|
28
28
|
if (v === 'synth') throw codedError('audio-synth-gone', fmt(SYNTH_GONE, { name, what: "'synth'", src: name, fix: `'${name}' (or {} with volume, bus...)` }));
|
|
29
|
-
if (
|
|
29
|
+
if (isObject(v) && 'synth' in v) throw codedError('audio-synth-gone',
|
|
30
30
|
fmt(SYNTH_GONE, { name, what: '{ synth }', src: v.synth, fix: `{ src: '${v.synth}', params, ... }` }));
|
|
31
31
|
if (typeof v === 'string' || Array.isArray(v)) return { src: v };
|
|
32
32
|
return v.src == null ? { ...v, src: name } : v;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/** The synth behind a sound asset name: { fn, params, bus, builtIn } for a manifest sound whose value is a function, else null (a file or unknown) @internal */
|
|
36
|
-
|
|
36
|
+
function synthOf(audio, src) {
|
|
37
37
|
const a = typeof src === 'string' ? audio.engine.assets.entries.get(src) : null;
|
|
38
38
|
return a?.type === 'sound' && a.opts.build ? { fn: a.opts.build, params: a.opts.params || {}, bus: a.opts.bus, builtIn: !!a.builtIn } : null;
|
|
39
39
|
}
|
|
@@ -53,8 +53,8 @@ function resolveDef(audio, name) {
|
|
|
53
53
|
function pickVariant(list, last) {
|
|
54
54
|
if (!Array.isArray(list)) return [list, 0];
|
|
55
55
|
if (list.length < 2) return [list[0], 0];
|
|
56
|
-
let i = Math.floor(Math.random() * (list.length - 1)); // presentation
|
|
57
|
-
if (i >= last) i++;
|
|
56
|
+
let i = Math.floor(Math.random() * (list.length - (last >= 0 ? 1 : 0))); // presentation
|
|
57
|
+
if (last >= 0 && i >= last) i++;
|
|
58
58
|
return [list[i], i];
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -95,7 +95,6 @@ export class SoundHandle {
|
|
|
95
95
|
/** @internal */ this.endsAt = Infinity;
|
|
96
96
|
/** @internal */ this.loop = null; // a synth loop's { stop(t) }
|
|
97
97
|
/** @internal */ this.follow = null;
|
|
98
|
-
/** @internal */ this.startedAt = ctx.currentTime;
|
|
99
98
|
if (at) {
|
|
100
99
|
const p = this.panner = ctx.createPanner();
|
|
101
100
|
p.panningModel = 'equalpower'; p.distanceModel = 'inverse';
|
|
@@ -193,33 +192,21 @@ export function synthTone(audio, opts) {
|
|
|
193
192
|
o.connect(g).connect(p).connect(out ?? audio._bus(bus)); o.start(t0); o.stop(t0 + dur + 0.02);
|
|
194
193
|
}
|
|
195
194
|
|
|
196
|
-
/** audio.load body:
|
|
195
|
+
/** audio.load body: a file sound is an engine.assets entry, by name or by path (a path gets an entry of its own, like a model path), so release, trim and dispose reach it */
|
|
197
196
|
export async function loadSound(audio, url) {
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
if (
|
|
201
|
-
if (asset?.named && asset.type === 'sound' && asset.url !== url) return audio.engine.assets._fetch(asset);
|
|
197
|
+
const { assets } = audio.engine, e = assets._resolve(url, 'sound');
|
|
198
|
+
if (e.type !== 'sound') throw codedError('asset-load', `audio.load('${url}'): ${url} is a ${e.type}, not a sound`);
|
|
199
|
+
if (e.opts.build) throw codedError('audio-synth-gone', `audio.load('${url}'): ${url} is a synth (a function in the asset pack), not a file: play it with audio.sfx('${url}')`);
|
|
202
200
|
audio._init();
|
|
203
|
-
if (!audio.ctx) throw codedError('audio-unsupported', 'Audio is not supported by this browser; check typeof AudioContext before calling');
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const fail = reason => Object.assign(codedError('asset-load', `Sound failed to load: "${url}": ${reason}`), { reason, url });
|
|
207
|
-
const p = fetch(url).then(r => {
|
|
208
|
-
if (!r.ok) throw fail(`${r.status} ${r.statusText}`.trim());
|
|
209
|
-
if (isHtml(r)) throw fail(NOT_THERE);
|
|
210
|
-
return r.arrayBuffer();
|
|
211
|
-
}).then(b => audio.ctx.decodeAudioData(b).catch(err => { throw fail(`not a sound file this browser can decode (${err?.message ?? err})`); }));
|
|
212
|
-
p.catch(() => { if (audio.buffers.get(url) === p) audio.buffers.delete(url); }); // a failed download is not cached: the next play tries again
|
|
213
|
-
audio.buffers.set(url, p);
|
|
214
|
-
}
|
|
215
|
-
return audio.buffers.get(url);
|
|
201
|
+
if (!audio.ctx && !e.named) throw codedError('audio-unsupported', 'Audio is not supported by this browser; check typeof AudioContext before calling'); // a named sound falls back to silence
|
|
202
|
+
e.usedAt = performance.now(); // presentation: which long sound goes first when memory is over budget (assetEntry.js)
|
|
203
|
+
return assets._fetch(e);
|
|
216
204
|
}
|
|
217
205
|
/** audio.play body: a file by path or asset name, no sounds entry needed */
|
|
218
206
|
export async function playFile(audio, url, opts) {
|
|
219
207
|
readParams('audio.play()', keysSchema(['bus', 'volume', 'loop', 'fadeIn', 'pitch', 'at']), opts);
|
|
220
208
|
const { bus = 'sfx', volume = 1, loop = false, fadeIn = 0, pitch = 1, at } = opts;
|
|
221
|
-
// create the (suspended) context now: a
|
|
222
|
-
// there would be no context to build the voice on. The sound starts when the first click / key resumes the context
|
|
209
|
+
// create the (suspended) context now: a voice needs one, and without Web Audio there is nothing to play. The sound starts when the first click / key resumes it
|
|
223
210
|
audio._init();
|
|
224
211
|
if (!audio.ctx) return null; // no Web Audio in this browser: nothing to play (audio.load still throws with the fix)
|
|
225
212
|
const buf = await audio.load(url), ctx = audio.ctx;
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
//
|
|
9
9
|
// All events, who emits and who listens: see packages/engine/docs/CODEMAP.md (generated by npm run map)
|
|
10
10
|
// In dev (npm run dev) event names are checked: a name never seen before that is one or two letters off a known event warns "did you mean xxx".
|
|
11
|
-
/** @import { Handle } from '
|
|
12
|
-
/** @import { EventName, EventArgs } from '
|
|
11
|
+
/** @import { Handle } from '../../types/common' */
|
|
12
|
+
/** @import { EventName, EventArgs } from '../../types/core' */
|
|
13
13
|
import { checkEventName } from './validate.js';
|
|
14
14
|
|
|
15
15
|
// Event names the engine and modules emit (for spelling checks): generated from EventMap in packages/engine/types/core.d.ts, never a hand-written second copy
|
|
@@ -129,7 +129,7 @@ export class Events {
|
|
|
129
129
|
const s = this.map.get(name); if (!s) { if (this.traceSize > 0) this._note(name); return; }
|
|
130
130
|
const prev = this._cur;
|
|
131
131
|
if (this.traceSize > 0) this._cur = `ev:${this._note(name)}`; // handlers run under this event: what they emit names it as parent
|
|
132
|
-
try { for (const fn of [...s]) { try { fn(...args); } catch (err) { if (this._scopes.length) this._scopes.at(-1).push({ name, err }); else if (this.onError) this.onError(name, err); else console.error(`[event ${name}]`, err); } } }
|
|
132
|
+
try { for (const fn of [...s]) { if (!s.has(fn)) continue; /* removed by an earlier listener of this emit */ try { fn(...args); } catch (err) { if (this._scopes.length) this._scopes.at(-1).push({ name, err }); else if (this.onError) this.onError(name, err); else console.error(`[event ${name}]`, err); } } }
|
|
133
133
|
finally { this._cur = prev; }
|
|
134
134
|
}
|
|
135
135
|
/** @internal trace entries old -> new */
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
//
|
|
8
8
|
// {name} in a string is replaced by the param; {key:interact} becomes the currently bound key label.
|
|
9
9
|
|
|
10
|
-
/** @import { StringTables } from '
|
|
10
|
+
/** @import { StringTables } from '../../types/core' */
|
|
11
11
|
import { warnMissing, warnOnce, missingText } from './validate.js';
|
|
12
12
|
import { coded } from './errorHints.js';
|
|
13
13
|
|
|
@@ -17,7 +17,7 @@ const CORE = {
|
|
|
17
17
|
'common.generating': '生成 {name}', 'common.world': '世界',
|
|
18
18
|
'loading.queued': '等待 {name}', 'loading.download': '下载 {name}', 'loading.decode': '解码 {name}', 'loading.upload': '上传 {name}', 'loading.build': '生成 {name}', 'loading.failed': '加载失败:{name}', 'common.on': '开', 'common.off': '关',
|
|
19
19
|
'input.moveForward': '前进', 'input.moveBack': '后退', 'input.moveLeft': '向左', 'input.moveRight': '向右',
|
|
20
|
-
'input.run': '奔跑', 'input.interact': '交互', 'input.confirm': '确认', 'input.cancel': '返回', 'input.uiUp': '菜单上移', 'input.uiDown': '菜单下移', 'input.uiLeft': '菜单左移', 'input.uiRight': '菜单右移',
|
|
20
|
+
'input.run': '奔跑', 'input.jump': '跳跃', 'input.interact': '交互', 'input.noKey': '无按键', 'input.confirm': '确认', 'input.cancel': '返回', 'input.uiUp': '菜单上移', 'input.uiDown': '菜单下移', 'input.uiLeft': '菜单左移', 'input.uiRight': '菜单右移',
|
|
21
21
|
'key.Space': '空格', 'key.Mouse0': '鼠标左键', 'key.Mouse1': '鼠标中键', 'key.Mouse2': '鼠标右键', 'key.Enter': '回车', 'ground.default': '默认',
|
|
22
22
|
},
|
|
23
23
|
en: {
|
|
@@ -25,7 +25,7 @@ const CORE = {
|
|
|
25
25
|
'common.generating': 'Generating {name}', 'common.world': 'world',
|
|
26
26
|
'loading.queued': 'Waiting for {name}', 'loading.download': 'Downloading {name}', 'loading.decode': 'Decoding {name}', 'loading.upload': 'Uploading {name}', 'loading.build': 'Building {name}', 'loading.failed': 'Failed to load: {name}', 'common.on': 'On', 'common.off': 'Off',
|
|
27
27
|
'input.moveForward': 'Forward', 'input.moveBack': 'Back', 'input.moveLeft': 'Left', 'input.moveRight': 'Right',
|
|
28
|
-
'input.run': 'Run', 'input.interact': 'Interact', 'input.confirm': 'Confirm', 'input.cancel': 'Back', 'input.uiUp': 'Menu up', 'input.uiDown': 'Menu down', 'input.uiLeft': 'Menu left', 'input.uiRight': 'Menu right',
|
|
28
|
+
'input.run': 'Run', 'input.jump': 'Jump', 'input.interact': 'Interact', 'input.noKey': 'No key', 'input.confirm': 'Confirm', 'input.cancel': 'Back', 'input.uiUp': 'Menu up', 'input.uiDown': 'Menu down', 'input.uiLeft': 'Menu left', 'input.uiRight': 'Menu right',
|
|
29
29
|
'key.Space': 'Space', 'key.Mouse0': 'Left click', 'key.Mouse1': 'Middle click', 'key.Mouse2': 'Right click', 'key.Enter': 'Enter', 'ground.default': 'default',
|
|
30
30
|
},
|
|
31
31
|
};
|
|
@@ -41,19 +41,19 @@ function resolveLocale(l, languages) {
|
|
|
41
41
|
return languages.find(x => x.toLowerCase() === low) ?? languages.find(x => x.toLowerCase().split(/[-_]/)[0] === base) ?? (auto ? 'en' : s);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
/** engine.i18n: string tables; t(key, params) fetches text and replaces {name} with params */
|
|
44
|
+
/** engine.i18n: string tables; engine.t(key, params) fetches text and replaces {name} with params */
|
|
45
45
|
export class I18n {
|
|
46
46
|
/** @internal */
|
|
47
47
|
constructor(engine, { locale = 'auto', fallback = 'en', strings = {} } = {}) {
|
|
48
48
|
/** @internal */ this.engine = engine;
|
|
49
|
-
/** Language used when a key is missing in the current one (default 'en') */
|
|
49
|
+
/** Language used when a key is missing in the current one (default 'en') @experimental */
|
|
50
50
|
this.fallback = fallback;
|
|
51
51
|
/** @internal the locale already checked for having a table (t() runs every frame: build the warning text at most once per locale) */ this._checked = null;
|
|
52
52
|
/** @internal keys already reported missing (t() may run every frame) */ this._missing = new Set();
|
|
53
53
|
/** @internal @type {StringTables} */ this.tables = {};
|
|
54
54
|
this.add(CORE);
|
|
55
55
|
/** @internal Game-given text wins @type {StringTables} */ this.overrides = strings;
|
|
56
|
-
/** Current language, e.g. 'zh-CN' ('zh' and 'zh-Hans' resolve to it, 'en-US' to 'en') */
|
|
56
|
+
/** Current language, e.g. 'zh-CN' ('zh' and 'zh-Hans' resolve to it, 'en-US' to 'en') @experimental */
|
|
57
57
|
this.locale = resolveLocale(locale, this.languages);
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
@@ -63,9 +63,9 @@ export class I18n {
|
|
|
63
63
|
* @example engine.i18n.add({ 'zh-CN': { 'shop.buy': '购买 {name}' }, en: { 'shop.buy': 'Buy {name}' } });
|
|
64
64
|
*/
|
|
65
65
|
add(tables) { for (const lang in tables) this.tables[lang] = { ...this.tables[lang], ...tables[lang] }; return this; }
|
|
66
|
-
/** Switch language ('auto' picks from the browser like createEngine) @param {string} l */
|
|
66
|
+
/** Switch language ('auto' picks from the browser like createEngine) @param {string} l @experimental */
|
|
67
67
|
setLocale(l) { this.locale = resolveLocale(l, this.languages); this.engine.events.emit('i18n:change', this.locale); }
|
|
68
|
-
/** All available languages @returns {string[]} */
|
|
68
|
+
/** All available languages @returns {string[]} @experimental */
|
|
69
69
|
get languages() { return [...new Set([...Object.keys(this.tables), ...Object.keys(this.overrides)])]; }
|
|
70
70
|
/** Whether the key exists @param {string} key @returns {boolean} */
|
|
71
71
|
has(key) { return this._raw(key) != null; }
|
|
@@ -89,9 +89,9 @@ export class I18n {
|
|
|
89
89
|
* @param {string} key
|
|
90
90
|
* @param {Record<string, any>} [params]
|
|
91
91
|
* @returns {string}
|
|
92
|
-
* @example engine.
|
|
92
|
+
* @example engine.t('shop.buy', { name: '鱼' });
|
|
93
93
|
*/
|
|
94
|
-
|
|
94
|
+
_t(key, params = {}) {
|
|
95
95
|
const raw = this._raw(key);
|
|
96
96
|
if (raw == null) {
|
|
97
97
|
// Looks like a key (a.b form) but has no text: probably misspelled or never registered
|