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
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
// The life of one engine.assets entry, split from Assets.js (which keeps the public API and the manifest):
|
|
2
|
+
// load: fetchEntry runs the load as a task in engine.loading and, for a registered non-critical file that fails, falls back (gray placeholder / silence / the entry's fallback)
|
|
3
|
+
// free: freeEntry gives the GPU memory back, deferred while model copies are still in the scene; shareModel marks what copies share so engine.remove does not dispose it
|
|
4
|
+
// sounds: freeing one needs no count. A playing voice holds its own buffer, so it plays on and the memory goes when it ends; the next play loads the file again
|
|
5
|
+
// Plain functions that take the Assets instance, so they stay out of the class's public surface.
|
|
6
|
+
//
|
|
7
|
+
// Who owns what. An entry is a name; a load is one attempt at its data, and the load is what owns that data:
|
|
8
|
+
// { owner, type, gameOwned, task, stop, value, users, settled, pinned }, reached as e.load.
|
|
9
|
+
// - One rule for freed, replaced and disposed: whoever ends a load aborts `stop`; a result arriving for an aborted load is freed and never written
|
|
10
|
+
// back. Why a record per load and not a counter on the entry: a palette write, a hot swap and a release all leave a load behind while the
|
|
11
|
+
// name moves on, and only the load knows which copies still hold its data.
|
|
12
|
+
// - Each copy counts on the load its data came from, so a name that fell back to another (e.load is then the other entry's load, e.value stays null)
|
|
13
|
+
// keeps that entry's data alive, and freeing the data sends every name reading it back to a fresh load.
|
|
14
|
+
// - e.users is the count Assets._users reads: copies asked for by this name plus copies that borrow its data. load.users frees an old build.
|
|
15
|
+
//
|
|
16
|
+
// A caller already awaiting a load that was ended:
|
|
17
|
+
// - release, trim, a palette write, a name registered again: the game is alive and asked for this asset, so the wait carries on with a fresh load
|
|
18
|
+
// (release says "reloaded on next use", and a wait is a use). It gets a live value, or the failure of that fresh load. Why not reject: every
|
|
19
|
+
// model() in the game would need a catch for a normal level change, and a rejected promise stays cached in the prototype tables.
|
|
20
|
+
// - assets.dispose: the promise stays pending for good. Why not reject or resolve null: `model(x).then(add)` with no catch would be an unhandled
|
|
21
|
+
// rejection in teardown, and null would be a TypeError in the same place; the code after the await belongs to a disposed engine.
|
|
22
|
+
import { warnOnce, fmt } from '../base/validate.js';
|
|
23
|
+
import { codedError, coded } from '../base/errorHints.js';
|
|
24
|
+
import { loadGltf, loadTexture, loadFont, loadAudio, generated, placeholder } from './assetLoad.js';
|
|
25
|
+
import { failureText } from '../engine/Loading.js';
|
|
26
|
+
import { paramValues } from './assetManifest.js';
|
|
27
|
+
|
|
28
|
+
const STRINGS = {
|
|
29
|
+
failed: 'Asset failed to load: {what}',
|
|
30
|
+
fellBack: '; using {fallback} instead, the game continues (mark it critical: true if the game cannot start without it)',
|
|
31
|
+
cycle: '; its fallbacks loop back on themselves ({chain}). Break the loop: give one of them no fallback, or a fallback that is a different file',
|
|
32
|
+
missingRefs: 'Asset loaded with missing references: {what} (missing {list}); materials show without those files',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/** From this many seconds a decoded sound is music or a long loop, worth loading again; shorter ones are effects, played often and small, and stay */
|
|
36
|
+
const LONG_SOUND = 10;
|
|
37
|
+
/** Decoded long sounds kept at once, in bytes: about 6 minutes of stereo at 48 kHz (a decoded minute is 21 MB, whatever the file's size) */
|
|
38
|
+
const SOUND_BUDGET = 128 * 2 ** 20;
|
|
39
|
+
const soundBytes = b => b.length * b.numberOfChannels * 4;
|
|
40
|
+
/** A decoded long sound trim and the budget may free; preload: true keeps it, as it keeps a model */
|
|
41
|
+
export const longSound = e => e.type === 'sound' && e.value?.duration >= LONG_SOUND && !e.opts.preload;
|
|
42
|
+
|
|
43
|
+
/** What a caller holds once the engine is gone: never settles, so nothing runs against a disposed engine (the rule is at the top of this file) */
|
|
44
|
+
const NEVER = new Promise(() => {});
|
|
45
|
+
|
|
46
|
+
/** Mark a model template's geometry and materials as shared (copies share them; engine.remove must not dispose them) */
|
|
47
|
+
function shareModel(a, g) {
|
|
48
|
+
g.scene.traverse(o => { if (o.geometry) a.shared.add(o.geometry); for (const m of [].concat(o.material || [])) a.shared.add(m); });
|
|
49
|
+
return g;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Shadow flags of a model copy, one rule for files, generators and content props: an explicit castShadow / receiveShadow (the model() call,
|
|
54
|
+
* then the manifest entry) wins; otherwise a generator that set either flag on any of its meshes decided for itself and is kept as built
|
|
55
|
+
* (a decal that must not cast stays that way); otherwise (a file, or a generator that set nothing) every mesh casts and receives.
|
|
56
|
+
* @param {import('three').Object3D} root
|
|
57
|
+
* @param {{ castShadow?: boolean, receiveShadow?: boolean }} [set]
|
|
58
|
+
*/
|
|
59
|
+
export function shadowDefaults(root, { castShadow, receiveShadow } = {}) {
|
|
60
|
+
let decided = false;
|
|
61
|
+
root.traverse(o => { if (/** @type {any} */ (o).isMesh && (o.castShadow || o.receiveShadow)) decided = true; });
|
|
62
|
+
const cast = castShadow ?? (decided ? null : true), recv = receiveShadow ?? (decided ? null : true);
|
|
63
|
+
root.traverse(o => { if (/** @type {any} */ (o).isMesh) { if (cast != null) o.castShadow = cast; if (recv != null) o.receiveShadow = recv; } });
|
|
64
|
+
return root;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Load an entry as a task in engine.loading; a registered, non-critical file that fails resolves to its fallback */
|
|
68
|
+
export function fetchEntry(a, e) {
|
|
69
|
+
if (a._disposed) return NEVER;
|
|
70
|
+
if (a._stale(e)) retireEntry(a, e);
|
|
71
|
+
if (e.promise) return e.promise;
|
|
72
|
+
e.palette = a._paletteKey;
|
|
73
|
+
const L = a.engine.loading, name = e.variantOf ?? e.name ?? e.url;
|
|
74
|
+
const t = L._begin(name, e.type, { critical: e.opts.critical === true, url: e.opts.build || e.opts.texture ? null : e.url, manifest: e.manifest ?? null });
|
|
75
|
+
const load = e.load = { owner: e, type: e.type, gameOwned: !!e.opts.texture, task: t, stop: new AbortController(), value: null, users: 0, settled: false, pinned: false };
|
|
76
|
+
t.signal = load.stop.signal; // the loaders read it between phases, and a download passes it to fetch
|
|
77
|
+
let work;
|
|
78
|
+
if (e.type === 'model') {
|
|
79
|
+
const got = e.opts.build ? (t.phase('build'), new Promise(res => res(generated(a, e.url, e.opts.build, e.schema ? paramValues(e) : e.opts.params, t)))) /* a sync throw takes the failure path below */ : loadGltf(a, e.url, t);
|
|
80
|
+
work = got.then(g => shareModel(a, g));
|
|
81
|
+
} else if (e.type === 'texture') work = loadTexture(a, e, t);
|
|
82
|
+
else if (e.type === 'font') work = loadFont(a, e, t);
|
|
83
|
+
else if (e.type === 'sound' && e.opts.build) work = Promise.resolve(e.opts.build); // a synth function: nothing to download
|
|
84
|
+
else if (e.type === 'sound') work = loadAudio(a, e, t);
|
|
85
|
+
// a._disposed too: an entry a hot swap dropped from the table is not reached by dispose, so its load was never aborted
|
|
86
|
+
const ended = () => load.stop.signal.aborted || a._disposed;
|
|
87
|
+
e.promise = work.then(v => {
|
|
88
|
+
if (ended()) { freeValue(load, v); return fetchEntry(a, e); }
|
|
89
|
+
L._done(t);
|
|
90
|
+
const what = `${e.type} "${name}" <- ${e.url}`;
|
|
91
|
+
if (t.missing.length) warnOnce(coded('asset-missing-ref', fmt(STRINGS.missingRefs, { what, list: t.missing.join(', ') })));
|
|
92
|
+
load.settled = true;
|
|
93
|
+
load.value = e.value = v;
|
|
94
|
+
if (e.type === 'sound') capSounds(a, e);
|
|
95
|
+
return v;
|
|
96
|
+
}, err => (ended() ? fetchEntry(a, e) : failedEntry(a, e, load, err))); // a failure nobody wants any more is not reported
|
|
97
|
+
return e.promise;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The fallback chain from e if it comes back to a name already on it (e -> ... -> e or into a ring), as names; null if it ends */
|
|
101
|
+
function fallbackCycle(a, e) {
|
|
102
|
+
const chain = [e.name ?? e.url];
|
|
103
|
+
for (let x = e; x?.opts.fallback;) {
|
|
104
|
+
const next = a.entries.get(x.opts.fallback);
|
|
105
|
+
chain.push(x.opts.fallback);
|
|
106
|
+
if (chain.indexOf(x.opts.fallback) < chain.length - 1) return chain;
|
|
107
|
+
x = next;
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** A load failed: a registered file entry degrades (warn + fallback); anything else is recorded and rethrown to the caller */
|
|
113
|
+
function failedEntry(a, e, load, err) {
|
|
114
|
+
const t = load.task;
|
|
115
|
+
e.promise = null;
|
|
116
|
+
const degrade = e.named && !e.opts.build && !e.opts.critical;
|
|
117
|
+
const fb = degrade ? (e.opts.fallback ?? (e.type === 'sound' ? 'silence' : e.type === 'font' ? 'the system font' : 'gray placeholder')) : null;
|
|
118
|
+
a.engine.loading._fail(t, err, fb);
|
|
119
|
+
const msg = fmt(STRINGS.failed, { what: failureText(t) });
|
|
120
|
+
const loop = degrade && e.opts.fallback ? fallbackCycle(a, e) : null;
|
|
121
|
+
// A -> B -> A: each would wait for the other's fallback forever, so fail once and name the chain (the fix is in the manifest)
|
|
122
|
+
if (loop) { e.load = null; throw codedError('asset-fallback-cycle', msg + fmt(STRINGS.cycle, { chain: loop.join(' -> ') })); }
|
|
123
|
+
if (!degrade) { e.load = null; throw codedError('asset-load', msg); }
|
|
124
|
+
warnOnce(coded('asset-load', msg + fmt(STRINGS.fellBack, { fallback: e.opts.fallback ? `"${fb}"` : fb })));
|
|
125
|
+
if (e.opts.fallback) return (e.promise = borrow(a, e, load, a._resolve(e.opts.fallback, e.type)));
|
|
126
|
+
load.settled = true;
|
|
127
|
+
load.value = e.value = e.type === 'model' ? shareModel(a, placeholder('model')) : placeholder(e.type);
|
|
128
|
+
return (e.promise = Promise.resolve(e.value));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** e falls back to `from`: until `from` answers, e's own failed load stays the token a release ends; then e reads from's load, which owns the data */
|
|
132
|
+
function borrow(a, e, load, from) {
|
|
133
|
+
const ended = () => load.stop.signal.aborted;
|
|
134
|
+
return fetchEntry(a, from).then(v => {
|
|
135
|
+
if (ended()) return fetchEntry(a, e);
|
|
136
|
+
if (from.load?.value !== v) { letGo(e); return fetchEntry(a, e); } // released between its load finishing and this line
|
|
137
|
+
e.load = from.load;
|
|
138
|
+
return v;
|
|
139
|
+
}, err => {
|
|
140
|
+
if (ended()) return fetchEntry(a, e);
|
|
141
|
+
letGo(e); // not kept as a rejected promise: the next use tries again
|
|
142
|
+
throw err;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** This name reads nothing now; its next use loads again */
|
|
147
|
+
function letGo(e) { e.load = e.value = e.promise = null; }
|
|
148
|
+
/** Every name reading this load, the owner and any that fell back to it, lets go of it */
|
|
149
|
+
function letGoAll(a, load) { for (const x of a.entries.values()) if (x.load === load) letGo(x); }
|
|
150
|
+
|
|
151
|
+
/** End a load still running. Its task goes too: nobody is waiting for that attempt, and a loading screen must not stay on it */
|
|
152
|
+
function cancelLoad(a, load) {
|
|
153
|
+
load.stop.abort();
|
|
154
|
+
a.engine.loading._drop(load.task);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Give back what one load made. A font that never reached document.fonts is a no-op here */
|
|
158
|
+
function freeValue(load, v) {
|
|
159
|
+
if (!v) return;
|
|
160
|
+
if (load.type === 'texture' && !load.gameOwned) v.dispose(); // a Texture the game registered is the game's: never disposed here
|
|
161
|
+
if (load.type === 'font') document.fonts.delete(v); // a released font stops matching its family
|
|
162
|
+
if (load.type === 'model') { // always { scene, ... }: generated() wraps a bare geometry too
|
|
163
|
+
v.scene.traverse(o => {
|
|
164
|
+
if (!o.geometry) return;
|
|
165
|
+
o.geometry.dispose();
|
|
166
|
+
[].concat(o.material).forEach(m => { for (const k in m) if (m[k]?.isTexture) m[k].dispose(); m.dispose(); });
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Free an entry's GPU memory; while model copies are still in use it waits (releasePending) and the last engine.remove frees it. A load in flight ends here */
|
|
172
|
+
export function freeEntry(a, e) {
|
|
173
|
+
const load = e.load;
|
|
174
|
+
if (!load) return;
|
|
175
|
+
if (load.owner !== e) { letGo(e); return; } // fell back: the data is the other entry's, and this name only stops reading it
|
|
176
|
+
if (!load.settled) { letGoAll(a, load); cancelLoad(a, load); return; }
|
|
177
|
+
if (e.users > 0) { e.releasePending = true; return; }
|
|
178
|
+
freeValue(load, load.value);
|
|
179
|
+
letGoAll(a, load);
|
|
180
|
+
e.releasePending = false;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* The name moves on from its current load (a palette write, a new registration, tuned params): an unfinished load ends, and finished data goes as soon as
|
|
185
|
+
* nothing holds it. Only models can be judged: copies are counted and geometry() pins. A texture is handed out uncounted, so a material may still show it: it
|
|
186
|
+
* is left to the game. Loads kept here wait in a._retired for their last copy, and for dispose
|
|
187
|
+
*/
|
|
188
|
+
export function retireEntry(a, e) {
|
|
189
|
+
const load = e.load;
|
|
190
|
+
if (!load) return;
|
|
191
|
+
if (load.owner !== e) { letGo(e); return; }
|
|
192
|
+
letGoAll(a, load);
|
|
193
|
+
if (!load.settled) cancelLoad(a, load);
|
|
194
|
+
else if (load.type === 'model') { if (load.users > 0 || load.pinned) a._retired.add(load); else freeValue(load, load.value); }
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** One model copy went away (engine.remove): the argument is what Assets._copy recorded */
|
|
198
|
+
export function dropCopy(a, { e, load }) {
|
|
199
|
+
const owner = load.owner;
|
|
200
|
+
load.users--; e.users--;
|
|
201
|
+
if (owner !== e) owner.users--;
|
|
202
|
+
if (load.users <= 0 && !load.pinned && a._retired.delete(load)) freeValue(load, load.value);
|
|
203
|
+
if (owner.users <= 0 && owner.releasePending) freeEntry(a, owner);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** e just loaded: while long sounds are over the budget, the one asked for longest ago goes (never e itself) */
|
|
207
|
+
function capSounds(a, e) {
|
|
208
|
+
const long = [...a.entries.values()].filter(longSound).sort((x, y) => (x.usedAt ?? 0) - (y.usedAt ?? 0));
|
|
209
|
+
let bytes = long.reduce((n, x) => n + soundBytes(x.value), 0);
|
|
210
|
+
for (const x of long) {
|
|
211
|
+
if (bytes <= SOUND_BUDGET) break;
|
|
212
|
+
if (x !== e) { bytes -= soundBytes(x.value); freeEntry(a, x); }
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Everything goes, copies or not, and no load finishing later may bring anything back (engine.dispose) */
|
|
217
|
+
export function disposeEntries(a) {
|
|
218
|
+
a._disposed = true;
|
|
219
|
+
for (const e of a.entries.values()) { e.users = 0; freeEntry(a, e); }
|
|
220
|
+
for (const load of a._retired) freeValue(load, load.value);
|
|
221
|
+
a._retired.clear();
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** Load the entries preload() wants and report progress; returns { loaded, failed, ok } (Assets.preload documents it) */
|
|
225
|
+
export async function preloadEntries(a, onProgress, onlyMarked) {
|
|
226
|
+
// generators and fonts only when marked: a font pack may hold many faces, and only those ui.fonts names (or preload: true) are wanted
|
|
227
|
+
const list = [...a.entries.entries()].filter(([, e]) => e.opts.build || e.type === 'font' ? e.opts.preload : !onlyMarked || e.opts.preload);
|
|
228
|
+
let done = 0;
|
|
229
|
+
onProgress?.(list.length ? 0 : 1, '');
|
|
230
|
+
// critical failures are reported by start(); others not already warned about (generated models) are warned here
|
|
231
|
+
await Promise.all(list.map(([name, e]) => fetchEntry(a, e).catch(err => { if (!e.opts.critical) warnOnce(err.message); }).finally(() => {
|
|
232
|
+
done++;
|
|
233
|
+
onProgress?.(done / list.length, name);
|
|
234
|
+
})));
|
|
235
|
+
const failed = list.filter(([name, e]) => a.engine.loading.get(name, e.type)?.phase === 'failed').map(([name]) => name);
|
|
236
|
+
return { loaded: list.length - failed.length, failed, ok: !failed.length };
|
|
237
|
+
}
|
|
@@ -10,10 +10,11 @@
|
|
|
10
10
|
// Limits (said in the report): a copy's collision box keeps the size it was placed with until the next load; an InstancedMesh or a merged batch
|
|
11
11
|
// the game built itself from a geometry is not found (only engine paths are).
|
|
12
12
|
import { registerManifest, paramValues } from './assetManifest.js';
|
|
13
|
-
import { protoCaches, protoOf, cachedModel
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
13
|
+
import { protoCaches, protoOf, cachedModel } from './namedModel.js';
|
|
14
|
+
import { list } from '../base/util.js';
|
|
15
|
+
import { reportError } from '../base/errors.js';
|
|
16
|
+
import { codedError } from '../base/errorHints.js';
|
|
17
|
+
import { note } from '../base/validate.js';
|
|
17
18
|
|
|
18
19
|
// a failed rebuild is reported (soft: the old copies stay on screen) and the swap goes on with the other names
|
|
19
20
|
const failWith = e => (err, what) => reportError(e, err, `asset hot swap: ${what}`, { soft: true });
|
|
@@ -27,7 +28,7 @@ const LAST = 10; // swaps kept for describe().assetSwaps
|
|
|
27
28
|
* with the new ones mesh by mesh; every scene mesh using an old geometry / material gets the new one.
|
|
28
29
|
* @param {any} e @param {{ name: string, type: string, old: any }[]} changed @param {string} why for the report ('edit', 'params')
|
|
29
30
|
*/
|
|
30
|
-
|
|
31
|
+
async function swapModels(e, changed, why = 'edit') {
|
|
31
32
|
const t0 = performance.now(), a = e.assets, fail = failWith(e); // measure
|
|
32
33
|
const names = new Set(changed.filter(c => c.type === 'model').map(c => c.name));
|
|
33
34
|
const geo = new Map(), mat = new Map(), tex = new Map(), protoNew = new Map(), structure = new Set(), copies = {};
|
|
@@ -170,7 +171,7 @@ export async function setParams(e, name, values) {
|
|
|
170
171
|
paramValues(ent, values); // a typo or a wrong type throws here, before anything is rebuilt
|
|
171
172
|
const old = { ...ent };
|
|
172
173
|
ent.tuned = { ...ent.tuned, ...values };
|
|
173
|
-
|
|
174
|
+
e.assets._retire(ent);
|
|
174
175
|
return swapModels(e, [{ name, type: 'model', old }], 'params');
|
|
175
176
|
}
|
|
176
177
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// File loading for engine.assets, split into the phases engine.loading reports: download -> decode -> upload.
|
|
2
2
|
// Each step names the failing file and HTTP status, and a glTF records what it references but could not load
|
|
3
3
|
// (a texture / .bin that 404s), so "the model looks gray" is traceable to one path instead of a bare "failed".
|
|
4
|
-
import { coded } from '
|
|
4
|
+
import { coded } from '../base/errorHints.js';
|
|
5
5
|
import * as THREE from 'three';
|
|
6
6
|
import { restoreBaked, toGLB, fromGLTF } from './Baked.js';
|
|
7
|
-
import { warnOnce, DEV_SERVER, BASE_URL } from '
|
|
8
|
-
import {
|
|
9
|
-
import { maxAnisotropy } from '
|
|
7
|
+
import { warnOnce, DEV_SERVER, BASE_URL, fmt } from '../base/validate.js';
|
|
8
|
+
import { neutralMaterial } from '../../render/neutral.js';
|
|
9
|
+
import { maxAnisotropy, isWebGPU } from '../../render/backend.js';
|
|
10
10
|
|
|
11
11
|
const BASE = BASE_URL; // DEV_SERVER: only npm run dev serves the /__threedog/cache endpoint
|
|
12
12
|
const CACHE = '/__threedog/cache/';
|
|
@@ -16,8 +16,8 @@ const NO_CACHE = '[cache] the dev server has no threedog model cache (a plain Vi
|
|
|
16
16
|
const CACHE_ERR = '[cache] the threedog model cache could not key "{name}" ({why}), so code-generated models are built every time; the vite config is fine, the dev server log has the cause';
|
|
17
17
|
|
|
18
18
|
// A dev / preview server answers a missing path with its index.html (status 200): treat an HTML answer for an asset as "not found"
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const NOT_THERE = 'not found (404: the server sent an HTML page instead, so the file is not at this path)';
|
|
20
|
+
const isHtml = res => /text\/html/i.test(res.headers.get('content-type') || '');
|
|
21
21
|
|
|
22
22
|
/** Error with the failing URL and HTTP status (status 0 = network / CORS / not an HTTP failure) */
|
|
23
23
|
export class LoadError extends Error {
|
|
@@ -37,7 +37,7 @@ function gltfExtensions(buf) {
|
|
|
37
37
|
/** Download as ArrayBuffer, reporting progress when the server sends a length; records size and version headers on the task */
|
|
38
38
|
async function download(url, task) {
|
|
39
39
|
task.phase('download', 0);
|
|
40
|
-
const res = await fetch(url);
|
|
40
|
+
const res = await fetch(url, { signal: task.signal });
|
|
41
41
|
if (!res.ok) throw new LoadError(`${res.status} ${res.statusText}`.trim(), { url, status: res.status });
|
|
42
42
|
if (isHtml(res)) throw new LoadError(NOT_THERE, { url, status: 404 });
|
|
43
43
|
const total = +(res.headers.get('content-length') || 0);
|
|
@@ -55,18 +55,25 @@ async function download(url, task) {
|
|
|
55
55
|
return buf;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
/** Upload textures to the GPU now, so the first frame that shows them does not stall (the 'upload' phase)
|
|
58
|
+
/** Upload textures to the GPU now, so the first frame that shows them does not stall (the 'upload' phase). A WebGPURenderer before start() has no GPU to upload to and
|
|
59
|
+
* throws if asked, so a load then leaves the texture for its first frame: this step only saves a stall, it never decides whether the load works */
|
|
59
60
|
function upload(assets, textures, task) {
|
|
60
61
|
task.phase('upload');
|
|
61
|
-
|
|
62
|
+
const r = assets.engine.renderer;
|
|
63
|
+
if (r.initialized === false) return;
|
|
64
|
+
for (const t of textures) r.initTexture(t);
|
|
62
65
|
}
|
|
63
66
|
|
|
67
|
+
// task.signal aborts when the load is ended (assetEntry.js). Before a value exists a phase just stops (the throw goes nowhere: an ended load reports
|
|
68
|
+
// nothing); once one exists it is returned as is, so the caller frees it, and nothing further touches the renderer or document.fonts, which may be gone.
|
|
69
|
+
|
|
64
70
|
/** Download a glTF, set up the Draco / KTX2 decoder it needs, parse it and upload its textures. Returns the gltf */
|
|
65
71
|
export async function loadGltf(assets, url, task) {
|
|
66
72
|
const buf = await download(url, task), used = gltfExtensions(buf);
|
|
67
73
|
task.phase('decode');
|
|
68
74
|
if (used.includes('KHR_draco_mesh_compression')) await decoder(assets, 'draco');
|
|
69
75
|
if (used.includes('KHR_texture_basisu')) await decoder(assets, 'ktx2');
|
|
76
|
+
task.signal.throwIfAborted(); // a disposed decoder would start its workers again
|
|
70
77
|
// A per-file manager hears which referenced files (.bin, textures) failed; GLTFParser reads the manager when parse() starts,
|
|
71
78
|
// so swapping it around the synchronous start of parseAsync scopes it to this file even with several loads in flight
|
|
72
79
|
const mgr = new THREE.LoadingManager(), missing = task.missing;
|
|
@@ -76,8 +83,10 @@ export async function loadGltf(assets, url, task) {
|
|
|
76
83
|
const parsing = assets.gltf.parseAsync(buf, THREE.LoaderUtils.extractUrlBase(url));
|
|
77
84
|
assets.gltf.manager = prev;
|
|
78
85
|
let gltf;
|
|
79
|
-
try { gltf = restoreBaked(await parsing
|
|
86
|
+
try { gltf = restoreBaked(await parsing); } // baked file: restore materials etc.
|
|
80
87
|
catch (err) { throw new LoadError(String(err?.message ?? err) + (missing.length ? ` (missing: ${missing.join(', ')})` : ''), { url: missing[0] ?? url }); }
|
|
88
|
+
if (task.signal.aborted) return gltf;
|
|
89
|
+
await noteFailedTextures(gltf, missing);
|
|
81
90
|
task.source.animations = gltf.animations.map(a => a.name);
|
|
82
91
|
const tex = new Set();
|
|
83
92
|
gltf.scene.traverse(o => { for (const m of [].concat(o.material || [])) for (const k in m) if (m[k]?.isTexture) tex.add(m[k]); });
|
|
@@ -85,8 +94,19 @@ export async function loadGltf(assets, url, task) {
|
|
|
85
94
|
return gltf;
|
|
86
95
|
}
|
|
87
96
|
|
|
88
|
-
/**
|
|
89
|
-
|
|
97
|
+
/** GLTFLoader swallows a texture that fails to decode (KTX2 / basis transcoder, bad image): it logs "Couldn't load texture" and the material just has no map,
|
|
98
|
+
* and the LoadingManager never hears of it. Its texture cache still holds the answer (null), so a model that arrived without a texture is recorded as
|
|
99
|
+
* missing a reference: loading shows it as partial instead of ok. Names are the image file, or "embedded texture" for data inside the file */
|
|
100
|
+
async function noteFailedTextures(gltf, missing) {
|
|
101
|
+
const parser = gltf.parser, cache = parser?.textureCache;
|
|
102
|
+
if (!cache) return;
|
|
103
|
+
for (const [key, p] of Object.entries(cache)) {
|
|
104
|
+
if (await p) continue;
|
|
105
|
+
const ref = key.slice(0, key.lastIndexOf(':')); // the cache key is "<uri or bufferView>:<sampler>"
|
|
106
|
+
const name = /^\d+$/.test(ref) ? `embedded texture (buffer view ${ref}, failed to decode)` : ref.startsWith('data:') ? 'embedded texture (failed to decode)' : ref;
|
|
107
|
+
if (!missing.includes(name)) missing.push(name);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
90
110
|
|
|
91
111
|
/** Load a texture (.ktx2 through KTX2Loader, .hdr through HDRLoader), apply the entry's options and upload it */
|
|
92
112
|
export async function loadTexture(assets, e, task) {
|
|
@@ -94,9 +114,8 @@ export async function loadTexture(assets, e, task) {
|
|
|
94
114
|
// its own colorSpace / wrap / repeat untouched (the game chose them); a function runs once per entry, `this` like a model generator
|
|
95
115
|
if (e.opts.build || e.opts.texture) {
|
|
96
116
|
task.phase('build');
|
|
97
|
-
const t = e.opts.texture ?? await e.opts.build.call({ palette: assets.
|
|
117
|
+
const t = e.opts.texture ?? await e.opts.build.call({ palette: assets.palette, engine: assets.engine });
|
|
98
118
|
if (!t?.isTexture) throw new LoadError(`the texture generator returned ${t === null ? 'null' : typeof t}, not a THREE.Texture`, { url: null });
|
|
99
|
-
CODE_TEXTURES.add(t);
|
|
100
119
|
return t;
|
|
101
120
|
}
|
|
102
121
|
task.phase('download');
|
|
@@ -104,15 +123,17 @@ export async function loadTexture(assets, e, task) {
|
|
|
104
123
|
const hdr = /\.hdr(\?|$)/i.test(e.url); // Radiance HDR (environment lighting): float data in linear color
|
|
105
124
|
let t;
|
|
106
125
|
try {
|
|
107
|
-
if (ktx)
|
|
126
|
+
if (ktx) { const k = await decoder(assets, 'ktx2'); task.signal.throwIfAborted(); t = await k.loadAsync(e.url); }
|
|
108
127
|
else if (hdr) t = await new (await import('three/addons/loaders/HDRLoader.js')).HDRLoader().loadAsync(e.url);
|
|
109
128
|
else t = await assets.tex.loadAsync(e.url);
|
|
110
129
|
}
|
|
111
130
|
catch (err) {
|
|
131
|
+
if (task.signal.aborted) throw err;
|
|
112
132
|
// an <img> error carries no status: ask the server once so the report says 404 vs a broken file
|
|
113
133
|
const status = await fetch(e.url, { method: 'HEAD' }).then(r => (!r.ok ? r.status : isHtml(r) ? 404 : 0), () => 0);
|
|
114
134
|
throw new LoadError(status === 404 ? NOT_THERE : status ? `HTTP ${status}` : String(err?.message ?? 'not a decodable image'), { url: e.url, status });
|
|
115
135
|
}
|
|
136
|
+
if (task.signal.aborted) return t;
|
|
116
137
|
if (e.opts.color === false) t.colorSpace = THREE.NoColorSpace;
|
|
117
138
|
else if (!t.isCompressedTexture && !hdr) t.colorSpace = THREE.SRGBColorSpace; // KTX2 carries its own color space
|
|
118
139
|
t.anisotropy = maxAnisotropy(assets.engine.renderer);
|
|
@@ -122,10 +143,10 @@ export async function loadTexture(assets, e, task) {
|
|
|
122
143
|
return t;
|
|
123
144
|
}
|
|
124
145
|
|
|
125
|
-
/** Import and create DRACOLoader / KTX2Loader on first use. Decoders default to the ones shipped with three (vite bundles them); if
|
|
146
|
+
/** Import and create DRACOLoader / KTX2Loader on first use. Decoders default to the ones shipped with three (vite bundles them); if createEngine({ decoders }) is set, download from there */
|
|
126
147
|
function decoder(assets, kind) {
|
|
127
148
|
return assets._loaders[kind] ||= (async () => {
|
|
128
|
-
const dir = assets.engine.
|
|
149
|
+
const dir = assets.engine._decoders;
|
|
129
150
|
if (kind === 'draco') {
|
|
130
151
|
const { DRACOLoader } = await import('three/addons/loaders/DRACOLoader.js');
|
|
131
152
|
assets.draco = new DRACOLoader();
|
|
@@ -134,13 +155,25 @@ function decoder(assets, kind) {
|
|
|
134
155
|
return assets.draco;
|
|
135
156
|
}
|
|
136
157
|
const { KTX2Loader } = await import('three/addons/loaders/KTX2Loader.js');
|
|
137
|
-
|
|
158
|
+
const r = assets.engine.renderer;
|
|
159
|
+
if (isWebGPU(r)) await r.init(); // detectSupport asks the GPU, and an asset may be requested before start(). three's init runs once, start() goes on from it
|
|
160
|
+
assets.ktx2 = new KTX2Loader().detectSupport(r);
|
|
138
161
|
if (dir) assets.ktx2.setTranscoderPath(dir + 'basis/');
|
|
139
162
|
assets.gltf.setKTX2Loader(assets.ktx2);
|
|
140
163
|
return assets.ktx2;
|
|
141
164
|
})();
|
|
142
165
|
}
|
|
143
166
|
|
|
167
|
+
/** Download a sound file and decode it. Decoding needs no click, so the context is made here if the first click has not come yet */
|
|
168
|
+
export async function loadAudio(assets, e, task) {
|
|
169
|
+
const { audio } = assets.engine; audio._init();
|
|
170
|
+
const { ctx } = audio; // read now: a dispose during the download clears audio.ctx
|
|
171
|
+
if (!ctx) throw new LoadError('this browser has no Web Audio', { url: e.url });
|
|
172
|
+
const buf = await download(e.url, task);
|
|
173
|
+
task.phase('decode');
|
|
174
|
+
try { return await ctx.decodeAudioData(buf); } catch (err) { throw new LoadError(`not a sound file this browser can decode (${err?.message ?? err})`, { url: e.url }); }
|
|
175
|
+
}
|
|
176
|
+
|
|
144
177
|
/** FontFace descriptors an asset pack's fonts entry may carry (everything else on the entry is the asset's own: url, family, critical...) */
|
|
145
178
|
const FONT_DESCRIPTORS = ['weight', 'style', 'stretch', 'unicodeRange', 'display', 'featureSettings', 'variationSettings'];
|
|
146
179
|
/**
|
|
@@ -157,31 +190,34 @@ export async function loadFont(assets, e, task) {
|
|
|
157
190
|
const desc = Object.fromEntries(FONT_DESCRIPTORS.filter(k => e.opts[k] != null).map(k => [k, String(e.opts[k])]));
|
|
158
191
|
const face = new FontFace(family, buf, { display: 'swap', ...desc });
|
|
159
192
|
try { await face.load(); } catch (err) { throw new LoadError(`not a font the browser can read (${err.message})`, { url: e.url }); }
|
|
160
|
-
document.fonts.add(face);
|
|
193
|
+
if (!task.signal.aborted) document.fonts.add(face);
|
|
161
194
|
return face;
|
|
162
195
|
}
|
|
163
196
|
|
|
164
197
|
/** Stand-ins for a degradable asset that failed: neutral gray (hard rule 1: the engine has no art of its own) */
|
|
165
|
-
export function placeholder(type
|
|
198
|
+
export function placeholder(type) {
|
|
166
199
|
if (type === 'texture') { const t = new THREE.DataTexture(new Uint8Array([128, 128, 128, 255]), 1, 1); t.needsUpdate = true; return t; }
|
|
167
200
|
if (type === 'model') {
|
|
168
201
|
const g = new THREE.Group();
|
|
169
|
-
g.add(new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1).translate(0, 0.5, 0),
|
|
202
|
+
g.add(new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1).translate(0, 0.5, 0), neutralMaterial('default')));
|
|
170
203
|
g.name = 'placeholder';
|
|
171
204
|
return { scene: g, animations: [] };
|
|
172
205
|
}
|
|
173
|
-
return null; // sound: silence; font: the next family in
|
|
206
|
+
return null; // sound: silence; font: the next family in ui.theme.font (the system font)
|
|
174
207
|
}
|
|
175
208
|
|
|
176
209
|
/** Code-generated model: baked file -> dev cache -> build now (Assets.cached, internal); returns { scene, animations, geometry? } */
|
|
177
210
|
export async function generated(assets, name, build, params, task) {
|
|
178
211
|
const wrap = v => v.isBufferGeometry
|
|
179
|
-
? { geometry: v, scene: new THREE.Mesh(v,
|
|
212
|
+
? { geometry: v, scene: new THREE.Mesh(v, neutralMaterial('default', { vertexColors: !!v.attributes.color })), animations: [] }
|
|
180
213
|
: { scene: v, animations: v.animations ?? [] };
|
|
181
214
|
const same = JSON.stringify(params ?? null);
|
|
182
|
-
const ctx = { palette: assets.
|
|
215
|
+
const ctx = { palette: assets.palette, engine: assets.engine }; // a function() generator reads this.palette
|
|
216
|
+
const colored = Object.keys(assets.palette).length > 0;
|
|
183
217
|
const baked = (await bakedIndex(assets))[name];
|
|
184
|
-
|
|
218
|
+
task.signal.throwIfAborted(); // the generator has not run yet: an ended load need not start it
|
|
219
|
+
// npm run bake has no engine, so a baked file carries no palette: with one set, only a hand-made file (source: 'file') stands in for the generator
|
|
220
|
+
const bakedOk = baked && JSON.stringify(baked.params ?? null) === same && (!colored || baked.source === 'file');
|
|
185
221
|
const file = async url => wrap(fromGLTF(await loadGltf(assets, url, task)));
|
|
186
222
|
if (!DEV_SERVER) return bakedOk ? file(BASE + 'models/baked/' + baked.file) : wrap(await build.call(ctx, params));
|
|
187
223
|
// In dev: ask the dev server for the current hash of this generator (with its file and imports)
|
|
@@ -191,24 +227,25 @@ export async function generated(assets, name, build, params, task) {
|
|
|
191
227
|
// template's own vite config, which sent the AI to a config that was already right
|
|
192
228
|
let info = null, why = null;
|
|
193
229
|
try {
|
|
194
|
-
const r = await fetch(CACHE + 'key', { method: 'POST', body: JSON.stringify({ name, src: String(build), params:
|
|
230
|
+
const r = await fetch(CACHE + 'key', { method: 'POST', body: JSON.stringify({ name, src: String(build), params: colored ? [params ?? null, ctx.palette] : params ?? null }) });
|
|
195
231
|
const text = await r.text();
|
|
196
232
|
if (r.ok && !/^\s*</.test(text)) info = JSON.parse(text);
|
|
197
233
|
else if (!r.ok) why = `${r.status}${text ? ': ' + text.slice(0, 160) : ''}`;
|
|
198
234
|
} catch (err) { why = String(err?.message ?? err); }
|
|
235
|
+
task.signal.throwIfAborted();
|
|
199
236
|
if (!info) {
|
|
200
|
-
warnOnce(coded('asset-cache', why ? CACHE_ERR
|
|
237
|
+
warnOnce(coded('asset-cache', why ? fmt(CACHE_ERR, { name, why }) : NO_CACHE), why ? 'asset-cache-err' : undefined);
|
|
201
238
|
return bakedOk ? file(BASE + 'models/baked/' + baked.file) : wrap(await build.call(ctx, params));
|
|
202
239
|
}
|
|
203
240
|
if (bakedOk) {
|
|
204
241
|
if (baked.source === 'file' || baked.key === info.key) return file(BASE + 'models/baked/' + baked.file);
|
|
205
|
-
warnOnce(coded('asset-cache', STALE
|
|
242
|
+
warnOnce(coded('asset-cache', fmt(STALE, { name })));
|
|
206
243
|
}
|
|
207
244
|
if (info.hit) return file(CACHE + info.key + '.glb');
|
|
208
245
|
const t0 = performance.now(), v = await build.call(ctx, params); // measure:build time
|
|
209
246
|
// { build, cache: false } in the manifest: never stored (a material the GLB round trip cannot keep, see Baked.js)
|
|
210
247
|
if (performance.now() - t0 >= assets.cacheMinMs && assets.entries.get(name)?.opts.cache !== false) // measure
|
|
211
|
-
toGLB(v,
|
|
248
|
+
toGLB(v, name).then(buf => fetch(CACHE + info.key + '.glb', { method: 'PUT', body: buf })).catch(err => warnOnce(coded('asset-cache', '[cache] could not store a built model in .threedog/cache (' + err.message + '); it is built again next time')));
|
|
212
249
|
return wrap(v);
|
|
213
250
|
}
|
|
214
251
|
/** Bake manifest public/models/baked/index.json (empty if missing) */
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// engine.assets.lod(name) and a prop's `lod: true` (helper of Assets.js): one object as a plain THREE.LOD over the level files `threedog assets optimize --lod` wrote.
|
|
2
|
+
// three.js does the switching (the renderer calls lod.update for WebGL and WebGPU), so lod.levels, lod.addLevel and lod.autoUpdate stay the game's to read and replace.
|
|
3
|
+
// What differs from its neighbours, each owning a different job so they never fight over one mesh:
|
|
4
|
+
// this: ONE heavy model, fewer triangles far away, per object, no merging. Costs its own draw calls.
|
|
5
|
+
// engine.hlod: MANY static level objects merged into one proxy per cell: fewer draw calls, same triangles unless a node xxx_LOD1 exists. Skips LOD objects.
|
|
6
|
+
// vegetation: plants, instanced per chunk; lodGeometry swaps by chunk ring. Thousands of copies, a job THREE.LOD cannot do one object at a time.
|
|
7
|
+
// engine.batching: many copies of a light model as one InstancedMesh. Instances share one geometry, so a copy cannot change level alone: a LOD object is never
|
|
8
|
+
// batched (userData.batch = false). Choosing LOD gives batching up for that object, hence the warning at MANY_COPIES.
|
|
9
|
+
// The full model stays the real one: level 0 is an ordinary copy, collision and saves read the model or record and never see a level, and rays hit level 0 at any
|
|
10
|
+
// distance. Far off it sits on the batch layer with its visible true (RESERVED_LAYERS.batched: not drawn, no shadows, engine.rays hit it), the way hlod hides its far
|
|
11
|
+
// originals, so it is one way of hiding for all three. Low meshes are marked userData.lodLevel, which rays and rays.addStatic leave out. A game's own THREE.Raycaster
|
|
12
|
+
// ignores visible but obeys layers, so it cannot reach a far full mesh: the level on screen passes the ray on to it, and the hit still names the full mesh.
|
|
13
|
+
// Popping: no crossfade (it would need a transparent pass per material, a look the game did not ask for). Hysteresis stops the flicker at a boundary; the error
|
|
14
|
+
// limit of the tool keeps the jump small, and a game that wants a fade has plain meshes in lod.levels to fade.
|
|
15
|
+
import * as THREE from 'three';
|
|
16
|
+
import { warnOnce, DEV } from '../base/validate.js';
|
|
17
|
+
import { codedError, coded } from '../base/errorHints.js';
|
|
18
|
+
import { notePatch, patchOn } from '../scene/threePatches.js';
|
|
19
|
+
import { RESERVED_LAYERS } from '../../render/layers.js';
|
|
20
|
+
import { unhideMask, FAR_BIT } from '../../render/occlusion.js';
|
|
21
|
+
|
|
22
|
+
const HYSTERESIS = 0.1; // share of a level's distance: coming back needs 10% more, so a camera resting on the line does not flicker
|
|
23
|
+
// Default distance of level i, in lengths of the model's diagonal. Why relative: one number in meters is wrong for a chair and for a tower alike, while a model
|
|
24
|
+
// this many of its own lengths away covers the same part of the screen whatever its size.
|
|
25
|
+
const FIRST_LENGTHS = 8, STEP = 3;
|
|
26
|
+
const MANY_COPIES = 32; // from here the draw calls batching would have saved usually outweigh the triangles
|
|
27
|
+
|
|
28
|
+
notePatch('lod-view-camera', 'update and clone on the THREE.LOD objects of assets.lod: only the engine camera moves the level, and a far full model waits on the batch layer instead of visible = false', () => {},
|
|
29
|
+
{ scope: 'LOD objects made by assets.lod and props with lod', lost: 'LOD objects made after it keep three\'s own update and clone: every camera moves the level (the shadow camera too, on WebGPU) and level 0 hides by visible, so far rays miss it. For one object: delete lod.update while level 0 shows (done far off, the full model stays on the batch layer)' });
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The level follows what the player sees. Why: WebGPURenderer walks the scene again for each shadow map and calls lod.update with the shadow camera, which stands far
|
|
33
|
+
* off, so every model ended the frame on its lowest level (measured on real WebGPU: main camera level 0, shadow camera level 2). Shadows were always the coarsest,
|
|
34
|
+
* getCurrentLevel() lied, and hysteresis, which reads visible, stopped working. WebGLRenderer's shadow pass does not do this, so the two now agree.
|
|
35
|
+
* three hides level 0 with visible = false, which rays obey, so that is undone here and the model moves to the batch layer. Layers are per object, not inherited, hence
|
|
36
|
+
* the walk; it runs every far frame so that something the game hangs on the model while far goes with it, and costs no more than the walk three now does anyway.
|
|
37
|
+
* clone: the copy would inherit far masks with no record of what they were, and draw nothing when near, so the masks go home first; the next update moves them again.
|
|
38
|
+
*/
|
|
39
|
+
function driveLevels(lod, engine) {
|
|
40
|
+
if (!patchOn('lod-view-camera')) return;
|
|
41
|
+
const pick = lod.update, away = new Map(); // object of the full model -> its layer mask before it moved
|
|
42
|
+
const moveAway = o => { if (!away.has(o)) { away.set(o, o.layers.mask); o.layers.set(RESERVED_LAYERS.batched); } };
|
|
43
|
+
const bringBack = () => { for (const [o, mask] of away) o.layers.mask = unhideMask(o.layers.mask, FAR_BIT, mask); away.clear(); };
|
|
44
|
+
lod.update = function (camera) {
|
|
45
|
+
if (camera !== engine.camera) return;
|
|
46
|
+
pick.call(this, camera);
|
|
47
|
+
if (this.getCurrentLevel() === 0) { bringBack(); return; }
|
|
48
|
+
const full = this.levels[0].object;
|
|
49
|
+
full.visible = true;
|
|
50
|
+
full.traverse(moveAway);
|
|
51
|
+
};
|
|
52
|
+
lod.clone = function (recursive) {
|
|
53
|
+
bringBack();
|
|
54
|
+
const copy = THREE.LOD.prototype.clone.call(this, recursive), fullMeshes = meshesOf(copy.levels[0].object);
|
|
55
|
+
driveLevels(copy, engine);
|
|
56
|
+
for (const { object } of copy.levels.slice(1)) passRays(object, fullMeshes);
|
|
57
|
+
return copy;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const meshesOf = root => { const out = []; root.traverse(m => { if (m.isMesh) out.push(m); }); return out; };
|
|
62
|
+
|
|
63
|
+
/** A level is never hit itself. While it is on screen it hands a ray that cannot see the full mesh over to that mesh; a ray that can see it (near, or engine.rays) hits it directly, so never twice */
|
|
64
|
+
function passRays(level, fullMeshes) {
|
|
65
|
+
meshesOf(level).forEach((m, j) => {
|
|
66
|
+
const f = fullMeshes[j];
|
|
67
|
+
m.raycast = (ray, out) => { if (level.visible && !f.layers.test(ray.layers)) f.raycast(ray, out); };
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function readDistances(d) {
|
|
72
|
+
if (d === undefined) return null;
|
|
73
|
+
if (!Array.isArray(d) || d.some((x, i) => !(x > 0) || (i && x <= d[i - 1]))) throw codedError('asset-lod', `assets.lod(): distances must be rising positive meters, like [40, 120] (got ${JSON.stringify(d)})`);
|
|
74
|
+
return d;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Wrap one copy of a model. scale: what the copy will be scaled by, so default distances follow its size on screen.
|
|
79
|
+
* @param {any} a the Assets instance @param {string} name @param {THREE.Object3D} full @returns {Promise<THREE.LOD>}
|
|
80
|
+
*/
|
|
81
|
+
export async function wrapLod(a, name, full, { distances, hysteresis = HYSTERESIS, scale = 1 } = {}) {
|
|
82
|
+
const asked = readDistances(distances), e = a.entries.get(name), lod = new THREE.LOD();
|
|
83
|
+
lod.name = full.name;
|
|
84
|
+
Object.assign(lod.userData, { batch: false, ...(full.userData.modelName && { modelName: full.userData.modelName }) });
|
|
85
|
+
lod.animations = full.animations;
|
|
86
|
+
driveLevels(lod, a.engine);
|
|
87
|
+
lod.addLevel(full, 0, hysteresis);
|
|
88
|
+
const urls = e?.load?.owner === e || !e?.load ? e?.opts.lods ?? [] : []; // a model that fell back shows another file: its levels would not match
|
|
89
|
+
if (DEV && !urls.length) warnOnce(coded('asset-lod', `assets.lod('${name}'): no levels for this model, so it draws in full at every distance. Run \`threedog assets optimize --lod\`; its report says when a model is skipped and why`));
|
|
90
|
+
// shortcut: counts copies ever made, not live ones (a prop's clone is no counted copy of the model); enough for a one-time hint, count live ones if it misfires
|
|
91
|
+
if (e) e.lodCopies = (e.lodCopies ?? 0) + 1;
|
|
92
|
+
if (DEV && e?.lodCopies === MANY_COPIES) warnOnce(coded('asset-lod', `assets.lod('${name}'): ${MANY_COPIES} copies, and a LOD object is never batched, so each one is its own draw calls. Check engine.batching is not the better fit: drop lod for this model and compare describe().perf`));
|
|
93
|
+
const fullMeshes = meshesOf(full);
|
|
94
|
+
const size = new THREE.Box3().setFromObject(full).getSize(new THREE.Vector3()).length() * scale;
|
|
95
|
+
const copies = await Promise.all(urls.map(u => a.model(u)));
|
|
96
|
+
copies.forEach((copy, i) => {
|
|
97
|
+
const low = meshesOf(copy), at = asked ? asked[i] : size * FIRST_LENGTHS * STEP ** i;
|
|
98
|
+
// a level built from another version of the model, or more levels than the game gave distances: leave it out rather than draw the wrong material on it
|
|
99
|
+
if (low.length !== fullMeshes.length || at === undefined) {
|
|
100
|
+
if (DEV && at !== undefined) warnOnce(coded('asset-lod', `assets.lod('${name}'): ${urls[i]} has ${low.length} meshes and the model ${fullMeshes.length}, so that level is left out. Run \`threedog assets optimize --lod --force\``));
|
|
101
|
+
a.forget(copy);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
low.forEach((m, j) => {
|
|
105
|
+
const f = fullMeshes[j];
|
|
106
|
+
m.material = f.material; m.castShadow = f.castShadow; m.receiveShadow = f.receiveShadow;
|
|
107
|
+
m.userData.lodLevel = i + 1;
|
|
108
|
+
});
|
|
109
|
+
passRays(copy, fullMeshes);
|
|
110
|
+
lod.addLevel(copy, at, hysteresis);
|
|
111
|
+
});
|
|
112
|
+
return lod;
|
|
113
|
+
}
|