threedog 0.7.0 → 1.0.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 +411 -1
- package/README.md +8 -11
- package/core/{Animator.js → assets/Animator.js} +30 -18
- package/core/{Assets.js → assets/Assets.js} +131 -56
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +302 -0
- package/core/{assetHot.js → assets/assetHot.js} +9 -7
- package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
- package/core/{assetReport.js → assets/assetReport.js} +7 -14
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +47 -25
- 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} +15 -12
- package/core/{Random.js → base/Random.js} +7 -4
- package/core/{Vars.js → base/Vars.js} +14 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +151 -125
- package/core/{errorHints.js → base/errorHints.js} +17 -10
- package/core/{errors.js → base/errors.js} +12 -10
- package/core/{events.generated.js → base/events.generated.js} +11 -0
- package/core/base/follows.js +26 -0
- package/core/base/math.js +66 -0
- package/core/{params.js → base/params.js} +5 -6
- package/core/base/saveValues.js +81 -0
- package/core/base/sections.js +97 -0
- package/core/base/spelling.js +32 -0
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +34 -34
- package/core/{Engine.js → engine/Engine.js} +137 -91
- package/core/{Loading.js → engine/Loading.js} +34 -5
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +32 -15
- package/core/{lifecycle.js → engine/lifecycle.js} +41 -34
- package/core/{loop.js → engine/loop.js} +88 -49
- package/core/engine/moduleSlots.js +176 -0
- package/core/{moduleTypes.js → engine/moduleTypes.js} +26 -14
- package/core/engine/modules.js +503 -0
- package/core/{page.js → engine/page.js} +59 -29
- package/core/{plugins.js → engine/plugins.js} +21 -12
- package/core/{services.js → engine/services.js} +50 -40
- package/core/{startup.js → engine/startup.js} +66 -54
- package/core/{Input.js → input/Input.js} +67 -39
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/input/inputKeyboard.js +39 -0
- package/core/{inputPad.js → input/inputPad.js} +24 -3
- package/core/{inputPointer.js → input/inputPointer.js} +11 -3
- package/core/input/inputSeat.js +66 -0
- package/core/{inputTouch.js → input/inputTouch.js} +24 -7
- package/core/{Budget.js → inspect/Budget.js} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +43 -18
- package/core/{Describe.js → inspect/Describe.js} +34 -26
- package/core/{Inspect.js → inspect/Inspect.js} +39 -10
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
- package/core/{UrlState.js → inspect/UrlState.js} +60 -24
- package/core/{catalog.js → inspect/catalog.js} +15 -8
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +4 -4
- package/core/{describeRender.js → inspect/describeRender.js} +24 -22
- package/core/{describeText.js → inspect/describeText.js} +17 -8
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/inspect/metadata.generated.js +4140 -0
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +130 -47
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/inspect/toolDoor.js +21 -0
- package/core/inspect/valueHistory.js +35 -0
- package/core/{Ops.js → ops/Ops.js} +44 -14
- package/core/{control.js → ops/control.js} +57 -31
- package/core/ops/holds.js +140 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +18 -5
- package/core/{opsCheck.js → ops/opsCheck.js} +11 -10
- package/core/{opsFail.js → ops/opsFail.js} +5 -7
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +9 -6
- package/core/{owned.js → ops/owned.js} +33 -19
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -16
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +34 -15
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +53 -27
- package/core/{Saves.js → saves/Saves.js} +171 -54
- package/core/saves/saveApply.js +312 -0
- package/core/{saveFiles.js → saves/saveFiles.js} +45 -38
- package/core/{saveVersions.js → saves/saveVersions.js} +24 -23
- package/core/saves/session.js +231 -0
- package/core/saves/stateReplace.js +184 -0
- package/core/{Rays.js → scene/Rays.js} +44 -30
- package/core/{Views.js → scene/Views.js} +16 -8
- package/core/{adaptive.js → scene/adaptive.js} +19 -9
- package/core/{canvasBox.js → scene/canvasBox.js} +4 -3
- package/core/scene/compositeGround.js +72 -0
- package/core/scene/floor.js +17 -0
- package/core/{gameLights.js → scene/gameLights.js} +17 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +6 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/scene/ground.contract.js +14 -0
- package/core/scene/ground.js +139 -0
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/scene/pixel.js +154 -0
- package/core/scene/pixelRatio.js +167 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +5 -5
- package/core/{sceneMethods.js → scene/sceneMethods.js} +43 -15
- package/core/scene/stepPoses.js +60 -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} +25 -16
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +10 -0
- package/core/scene/view.js +161 -0
- package/core/{Batching.js → stream/Batching.js} +85 -28
- package/core/{Stream.js → stream/Stream.js} +80 -38
- package/core/{batchGroups.js → stream/batchGroups.js} +11 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- package/core/{scatter.js → stream/scatter.js} +7 -4
- package/core/{streamSources.js → stream/streamSources.js} +14 -8
- package/core/{Commits.js → threads/Commits.js} +17 -11
- package/core/{Jobs.js → threads/Jobs.js} +25 -13
- package/core/{Threads.js → threads/Threads.js} +21 -18
- 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} +20 -11
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +28 -21
- package/core/{time.js → time/time.js} +32 -20
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +92 -72
- package/docs/API.md +33 -28
- package/docs/CODEMAP.md +121 -200
- package/docs/COMMANDS.md +77 -70
- package/docs/CONVENTIONS.md +167 -24
- package/docs/MIGRATING-0.8.md +171 -0
- package/docs/MIGRATING-1.0.md +101 -0
- package/docs/THREE.md +140 -38
- package/docs/api/assets.md +12 -13
- package/docs/api/audio.md +6 -5
- package/docs/api/budget.md +4 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +32 -29
- package/docs/api/characters.md +35 -24
- package/docs/api/clock.md +1 -1
- package/docs/api/collider3d.md +9 -0
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +18 -17
- package/docs/api/dialogue.md +5 -4
- package/docs/api/engine.md +58 -54
- package/docs/api/events.md +17 -6
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +6 -7
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +9 -8
- package/docs/api/interactions.md +5 -5
- package/docs/api/inventory.md +10 -10
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +10 -9
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +14 -12
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +10 -7
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +3 -3
- package/docs/api/post.md +21 -5
- package/docs/api/quests.md +7 -5
- package/docs/api/rays.md +7 -7
- package/docs/api/rigid.md +29 -19
- package/docs/api/saves.md +13 -11
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +8 -7
- package/docs/api/stream.md +8 -9
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +6 -8
- package/docs/api/terrainDraw.md +2 -2
- package/docs/api/timeline.md +4 -4
- package/docs/api/tools.md +27 -22
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +2 -2
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +27 -12
- package/docs/api/weatherDraw.md +4 -4
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +28 -43
- package/docs/recipes/02-npc.md +21 -23
- package/docs/recipes/03-items-pickups.md +37 -53
- package/docs/recipes/04-quests.md +5 -4
- package/docs/recipes/05-props-bake.md +34 -44
- package/docs/recipes/06-clock-events.md +31 -22
- package/docs/recipes/07-flow-scenes-pause.md +30 -32
- package/docs/recipes/08-weather-sky.md +91 -37
- package/docs/recipes/09-materials-lights-models.md +25 -39
- package/docs/recipes/10-blender-level.md +22 -11
- package/docs/recipes/11-vehicles.md +44 -24
- package/docs/recipes/12-navmesh.md +60 -15
- package/docs/recipes/13-animation.md +70 -22
- package/docs/recipes/14-custom-module.md +33 -20
- package/docs/recipes/15-perf.md +51 -28
- package/docs/recipes/16-dev-bridge.md +39 -58
- package/docs/recipes/18-world.md +49 -28
- package/docs/recipes/19-shooting-picking.md +7 -4
- package/docs/recipes/20-content-actions-save.md +55 -40
- package/docs/recipes/21-camera.md +47 -25
- package/docs/recipes/22-shop-gold.md +21 -16
- package/docs/recipes/23-ops.md +28 -24
- package/docs/recipes/26-ui-parts.md +25 -14
- package/docs/recipes/27-net.md +3 -5
- package/docs/recipes/28-terrain.md +119 -23
- package/docs/recipes/29-grid.md +3 -3
- package/docs/recipes/30-templates.md +63 -30
- package/docs/recipes/31-audio.md +7 -7
- package/docs/recipes/32-action-game.md +21 -11
- package/docs/recipes/33-stream-sources.md +6 -3
- package/docs/recipes/34-environment-lighting.md +72 -25
- package/docs/recipes/35-picture-from-reference.md +20 -23
- package/docs/recipes/36-ground-plants.md +106 -0
- package/docs/recipes/40-scene.md +18 -21
- package/docs/recipes/43-shader-patches-surfaces.md +27 -48
- package/docs/recipes/44-water-weather-hooks.md +56 -50
- package/docs/recipes/45-cascaded-shadows.md +41 -20
- package/docs/recipes/46-blender-art-route.md +9 -10
- package/docs/recipes/49-game-module-contract.md +7 -6
- package/docs/recipes/50-own-renderer.md +3 -2
- package/docs/recipes/51-capability-catalog.md +14 -8
- package/docs/recipes/52-around-the-picture.md +56 -100
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +17 -20
- package/docs/recipes/56-webgpu-tsl.md +28 -15
- package/docs/recipes/57-control.md +39 -12
- package/docs/recipes/58-input.md +15 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +30 -25
- package/docs/recipes/62-picture-code.md +129 -39
- package/docs/recipes/63-third-person-start.md +19 -5
- package/docs/recipes/64-particles.md +54 -5
- package/docs/recipes/65-swarm.md +140 -0
- package/docs/recipes/66-common-tasks.md +313 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +5 -5
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +15 -14
- package/examples/{sheepisland → perf-island}/assets.js +1 -1
- package/examples/{sheepisland → perf-island}/main.js +8 -8
- package/examples/{sheepisland → perf-island}/models.js +1 -1
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/GAMEMAP.md +4 -1
- package/examples/rc2d/GAMEMAP.md +4 -3
- package/examples/rc2d/main.js +1 -3
- package/examples/rc2d/rc2d.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +6 -5
- package/examples/techniques/contact-shadows/contactShadows.js +1 -1
- package/examples/techniques/contact-shadows/main.js +1 -1
- package/examples/techniques/interior-light/main.js +1 -1
- package/examples/techniques/modular-building/README.md +7 -6
- package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/webgpu-tsl/GAMEMAP.md +2 -1
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +9 -7
- package/examples/world/main.js +3 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +16 -12
- package/index.js +53 -32
- package/llms.txt +11 -14
- package/modules/ambience/Ambience.js +16 -11
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +18 -16
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +5 -5
- package/modules/camera/FixedCamera.js +43 -30
- package/modules/camera/FollowCamera.js +24 -15
- package/modules/camera/RtsCamera.js +12 -11
- package/modules/camera/common.js +72 -37
- package/modules/camera/contract.js +1 -0
- package/modules/camera/pixelSnap.js +62 -0
- package/modules/characters/Character.js +166 -70
- package/modules/characters/NPC.js +84 -44
- package/modules/characters/assetModel.js +16 -12
- package/modules/characters/astar.js +48 -27
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/character.contract.js +21 -0
- package/modules/characters/contract.js +17 -3
- package/modules/characters/index.js +240 -226
- package/modules/characters/moveHelpers.js +88 -12
- package/modules/characters/mover.contract.js +14 -0
- package/modules/characters/movers/common.js +22 -18
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +18 -10
- package/modules/characters/movers/simple.js +26 -13
- package/modules/characters/movers/support.js +24 -13
- package/modules/characters/npcAvoid.js +19 -16
- package/modules/characters/npcSim.js +88 -32
- package/modules/characters/npcView.js +19 -11
- package/modules/characters/pathAsync.js +81 -29
- package/modules/characters/pathJob.js +38 -21
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +120 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +2 -2
- package/modules/characters/seat.js +56 -0
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/vehicle.contract.js +8 -5
- package/modules/characters/walkTo.js +40 -33
- package/modules/collision/Collision.js +69 -45
- package/modules/collision/contract.js +15 -0
- package/modules/collision/grid.js +6 -1
- package/modules/content/explain.js +2 -3
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +5 -3
- package/modules/content/index.js +132 -114
- package/modules/content/loader.js +117 -140
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +54 -17
- package/modules/content/packs.js +5 -4
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +36 -0
- package/modules/content/props.js +22 -17
- package/modules/content/rules.js +47 -61
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +80 -49
- package/modules/content/words.js +47 -0
- package/modules/debug/DebugPanel.js +14 -45
- package/modules/flow/contract.js +2 -1
- package/modules/flow/index.js +30 -16
- package/modules/gameplay/Container.js +17 -13
- package/modules/gameplay/Containers.js +23 -6
- package/modules/gameplay/Dialogue.js +93 -34
- package/modules/gameplay/Interactions.js +93 -51
- package/modules/gameplay/Inventory.js +64 -22
- package/modules/gameplay/Quests.js +146 -30
- package/modules/gameplay/boxOps.js +8 -1
- package/modules/gameplay/dialogueBubbles.js +16 -12
- package/modules/gameplay/inventoryOps.js +11 -8
- package/modules/gameplay/pickups.js +63 -37
- package/modules/gameplay/questLog.js +4 -2
- package/modules/gameplay/questSave.js +9 -4
- package/modules/gameplay/quests.contract.js +1 -1
- package/modules/grid/Grid.js +2 -2
- package/modules/grid/Layer.js +12 -8
- package/modules/grid/index.js +28 -23
- package/modules/grid/ops.js +43 -46
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +42 -57
- package/modules/hud/index.js +22 -14
- package/modules/hud/parts.js +8 -8
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +29 -31
- package/modules/level/index.js +113 -161
- package/modules/level/load.js +196 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +40 -23
- package/modules/lights/index.js +33 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +90 -0
- package/modules/music/Music.js +34 -28
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +16 -0
- package/modules/nav/index.js +180 -49
- package/modules/nav/navPath.js +45 -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 +6 -5
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +95 -29
- package/modules/particles/effect.js +86 -32
- package/modules/particles/shaders.js +19 -1
- package/modules/photo/Photo.js +23 -23
- package/modules/rigid/RigidBodies.js +255 -89
- package/modules/rigid/Vehicles.js +17 -8
- package/modules/rigid/collider3d.contract.js +26 -0
- package/modules/rigid/ragdoll.js +298 -0
- package/modules/rigid/ragdollBones.js +209 -0
- package/modules/rigid/refresh.js +10 -0
- package/modules/rigid/sync.js +51 -20
- package/modules/settings/Settings.js +177 -61
- package/modules/settings/apply.js +20 -13
- package/modules/settings/sections.js +19 -14
- package/modules/settings/strings.js +2 -2
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +29 -22
- package/modules/sky/clouds.js +7 -7
- package/modules/sky/dome.js +33 -20
- package/modules/sky/domeLayers.js +9 -9
- package/modules/sky/environment.js +6 -6
- package/modules/sky/frame.js +19 -10
- package/modules/sky/season.js +7 -1
- package/modules/sky/shader.js +24 -25
- package/modules/sky/skyModule.js +17 -28
- package/modules/sky/tint.js +1 -1
- package/modules/swarm/Swarm.js +356 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +71 -59
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +14 -11
- package/modules/terrain/index.js +42 -42
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +45 -29
- package/modules/terrain/terrainGen.js +19 -12
- 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 +83 -43
- package/modules/timeline/Tween.js +25 -19
- package/modules/timeline/shots.js +24 -17
- package/modules/triggers/index.js +95 -28
- package/modules/vegetation/Vegetation.js +34 -26
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +39 -18
- package/modules/vegetation/groundChunks.js +21 -38
- package/modules/vegetation/index.js +37 -12
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +20 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +52 -40
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +28 -23
- package/modules/world/World.js +28 -15
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +30 -17
- package/modules/world/persist.js +90 -27
- package/modules/world/pos.js +5 -5
- package/modules/world/records.js +37 -11
- package/modules/world/sim.js +78 -27
- package/modules/world/simFar.js +2 -2
- package/modules/world/state.js +43 -11
- package/modules/world/thingSource.js +20 -5
- package/modules/world/views.js +27 -14
- package/package.json +48 -7
- package/presets.js +1 -3
- package/render/PostFX.js +83 -53
- package/render/backend.js +31 -33
- package/render/cascades.js +17 -12
- package/render/cascades.tsl.js +5 -8
- package/render/daylight.js +20 -3
- package/render/detail.js +8 -7
- package/render/effects.js +28 -25
- package/render/fuse.js +3 -3
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +5 -10
- 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/particles.tsl.js +8 -6
- package/render/fx/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +30 -26
- package/render/fx/sky.tsl.js +15 -17
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +2 -2
- package/render/lighting.js +5 -3
- package/render/lightmap.js +41 -21
- package/render/lights.js +6 -6
- package/render/lit.js +24 -0
- package/render/materials.js +8 -7
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/occlusion.js +62 -15
- package/render/ownFrame.js +4 -4
- package/render/patches.js +15 -15
- package/render/postWebGL.js +15 -12
- package/render/probes.js +41 -19
- 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/{core → render}/shadows.js +59 -13
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +336 -202
- package/types/gameplay.d.ts +254 -130
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
- 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} +8 -16
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +28 -10
- package/types/generated/core/input/inputSeat.d.ts +26 -0
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +17 -3
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +6 -4
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +14 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +62 -18
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +3 -2
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +2 -2
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +22 -18
- 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/Grid.d.ts +1 -0
- package/types/generated/modules/grid/Layer.d.ts +1 -1
- package/types/generated/modules/grid/index.d.ts +3 -3
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +5 -4
- package/types/generated/modules/sky/Sky.d.ts +21 -10
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +7 -5
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +14 -16
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +11 -7
- package/types/generated/render/PostFX.d.ts +21 -23
- package/types/generated/render/materials.d.ts +1 -0
- package/types/generated/render/occlusion.d.ts +9 -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 +47 -15
- package/types/physics.d.ts +150 -73
- package/types/pixel.d.ts +75 -0
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +48 -75
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +13 -5
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +7 -5
- package/core/assetEntry.js +0 -109
- package/core/engineCamera.js +0 -32
- package/core/ground.js +0 -104
- package/core/holds.js +0 -134
- package/core/math.js +0 -48
- package/core/moduleSlots.js +0 -100
- package/core/modules.js +0 -314
- package/core/saveApply.js +0 -210
- package/core/saveValues.js +0 -46
- package/core/session.js +0 -174
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- package/core/view.js +0 -43
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -320
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/MIGRATING-0.6.md +0 -126
- package/docs/PERF.md +0 -245
- package/docs/recipes/36-sky-ground-plants.md +0 -158
- package/docs/recipes/37-terrain-hooks.md +0 -115
- package/docs/recipes/38-environment-hooks.md +0 -67
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/47-island-snow-backdrop.md +0 -43
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/plain-picture/FINDINGS.md +0 -53
- package/examples/sheepisland/.threedog/content-index.json +0 -1
- package/modules/camera/projection.js +0 -21
- /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/{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
- /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
|
@@ -0,0 +1,302 @@
|
|
|
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 decides what a failed file means: the caller. An entry only says what it can fall back to, because it cannot know who asks: a prop on a gray box is a game that goes on, a level on a gray box
|
|
8
|
+
// is not a level. A caller that cannot use a stand-in waits with { whole: true } (Assets.wholeModel); e.fellBack is the failure the stand-in hides, and such a caller gets that instead, and tries the file
|
|
9
|
+
// again on its next ask. Internal on purpose: a game names `critical` for start(), and asks for a stand-in or not by what it does with the result.
|
|
10
|
+
//
|
|
11
|
+
// Who owns what. An entry is a name; a load is one attempt at its data, and the load is what owns that data:
|
|
12
|
+
// { owner, type, gameOwned, task, stop, value, users, settled, pinned }, reached as e.load.
|
|
13
|
+
// - 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
|
|
14
|
+
// 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
|
|
15
|
+
// name moves on, and only the load knows which copies still hold its data.
|
|
16
|
+
// - 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)
|
|
17
|
+
// keeps that entry's data alive, and freeing the data sends every name reading it back to a fresh load.
|
|
18
|
+
// - e.users is the count Assets._users reads: leases (takeLease) asked for by this name plus leases that borrow its data; a model copy is one lease. load.users frees an old build.
|
|
19
|
+
//
|
|
20
|
+
// A caller already awaiting a load that was ended:
|
|
21
|
+
// - 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
|
|
22
|
+
// (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
|
|
23
|
+
// model() in the game would need a catch for a normal level change, and a rejected promise stays cached in the prototype tables.
|
|
24
|
+
// - the limit: a load that shows no sign of life for engine.loading.timeoutMs fails, by the path any failure takes (fallback, or asset-load). The limit sits on the load and not on each
|
|
25
|
+
// waiter, so every wait above it, a level, a pack, a preload, a save's part, ends by inheritance and none needs a timer of its own. Silence and not total time: a big file on a slow
|
|
26
|
+
// network that still arrives is not stuck.
|
|
27
|
+
// - leaving: a waiter with a signal (waitLoad) may stop waiting. When every waiter on a load has left, nobody wants it and it is aborted; a load shared with a waiter that stays goes on.
|
|
28
|
+
// - 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
|
|
29
|
+
// rejection in teardown, and null would be a TypeError in the same place; the code after the await belongs to a disposed engine.
|
|
30
|
+
import { warnOnce, fmt } from '../base/validate.js';
|
|
31
|
+
import { codedError, coded } from '../base/errorHints.js';
|
|
32
|
+
import { loadGltf, loadTexture, loadFont, loadAudio, generated, placeholder } from './assetLoad.js';
|
|
33
|
+
import { failureText } from '../engine/Loading.js';
|
|
34
|
+
import { paramValues } from './assetManifest.js';
|
|
35
|
+
|
|
36
|
+
const STRINGS = {
|
|
37
|
+
failed: 'Asset failed to load: {what}',
|
|
38
|
+
fellBack: '; using {fallback} instead, the game continues (mark it critical: true if the game cannot start without it)',
|
|
39
|
+
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',
|
|
40
|
+
missingRefs: 'Asset loaded with missing references: {what} (missing {list}); materials show without those files',
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** 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 */
|
|
44
|
+
const LONG_SOUND = 10;
|
|
45
|
+
/** 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) */
|
|
46
|
+
const SOUND_BUDGET = 128 * 2 ** 20;
|
|
47
|
+
const soundBytes = b => b.length * b.numberOfChannels * 4;
|
|
48
|
+
/** A decoded long sound trim and the budget may free; preload: true keeps it, as it keeps a model */
|
|
49
|
+
export const longSound = e => e.type === 'sound' && e.value?.duration >= LONG_SOUND && !e.opts.preload;
|
|
50
|
+
|
|
51
|
+
/** 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) */
|
|
52
|
+
const NEVER = new Promise(() => {});
|
|
53
|
+
|
|
54
|
+
/** Mark a model template's geometry and materials as shared (copies share them; engine.remove must not dispose them) */
|
|
55
|
+
function shareModel(a, g) {
|
|
56
|
+
g.scene.traverse(o => { if (o.geometry) a.shared.add(o.geometry); for (const m of [].concat(o.material || [])) a.shared.add(m); });
|
|
57
|
+
return g;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Shadow flags of a model copy, one rule for files, generators and content props: an explicit castShadow / receiveShadow (the model() call,
|
|
62
|
+
* 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
|
|
63
|
+
* (a decal that must not cast stays that way); otherwise (a file, or a generator that set nothing) every mesh casts and receives.
|
|
64
|
+
* @param {import('three').Object3D} root
|
|
65
|
+
* @param {{ castShadow?: boolean, receiveShadow?: boolean }} [set]
|
|
66
|
+
*/
|
|
67
|
+
export function shadowDefaults(root, { castShadow, receiveShadow } = {}) {
|
|
68
|
+
let decided = false;
|
|
69
|
+
root.traverse(o => { if (/** @type {any} */ (o).isMesh && (o.castShadow || o.receiveShadow)) decided = true; });
|
|
70
|
+
const cast = castShadow ?? (decided ? null : true), recv = receiveShadow ?? (decided ? null : true);
|
|
71
|
+
root.traverse(o => { if (/** @type {any} */ (o).isMesh) { if (cast != null) o.castShadow = cast; if (recv != null) o.receiveShadow = recv; } });
|
|
72
|
+
return root;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Load an entry as a task in engine.loading; a registered, non-critical file that fails resolves to its fallback */
|
|
76
|
+
export function fetchEntry(a, e) {
|
|
77
|
+
if (a._disposed) return NEVER;
|
|
78
|
+
if (a._stale(e)) retireEntry(a, e);
|
|
79
|
+
if (e.promise) { if (e.load) e.load.waits++; return e.promise; }
|
|
80
|
+
e.palette = a._paletteKey;
|
|
81
|
+
const L = a.engine.loading, name = e.variantOf ?? e.name ?? e.url;
|
|
82
|
+
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 });
|
|
83
|
+
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, waits: 1, left: false, stuck: false, whole: false };
|
|
84
|
+
t.signal = load.stop.signal; // the loaders read it between phases, and a download passes it to fetch
|
|
85
|
+
let work;
|
|
86
|
+
if (e.type === 'model') {
|
|
87
|
+
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);
|
|
88
|
+
work = got.then(g => shareModel(a, g));
|
|
89
|
+
} else if (e.type === 'texture') work = loadTexture(a, e, t);
|
|
90
|
+
else if (e.type === 'font') work = loadFont(a, e, t);
|
|
91
|
+
else if (e.type === 'sound' && e.opts.build) work = Promise.resolve(e.opts.build); // a synth function: nothing to download
|
|
92
|
+
else if (e.type === 'sound') work = loadAudio(a, e, t);
|
|
93
|
+
// a._disposed too: an entry a hot swap dropped from the table is not reached by dispose, so its load was never aborted
|
|
94
|
+
const ended = () => cancelled(load) || a._disposed;
|
|
95
|
+
e.promise = limited(a, load, work).then(v => {
|
|
96
|
+
if (ended()) { freeValue(load, v); return again(a, e, load); }
|
|
97
|
+
L._done(t);
|
|
98
|
+
const what = `${e.type} "${name}" <- ${e.url}`;
|
|
99
|
+
if (t.missing.length) warnOnce(coded('asset-missing-ref', fmt(STRINGS.missingRefs, { what, list: t.missing.join(', ') })));
|
|
100
|
+
load.settled = true;
|
|
101
|
+
load.value = e.value = v;
|
|
102
|
+
if (e.type === 'sound') capSounds(a, e);
|
|
103
|
+
return v;
|
|
104
|
+
}, err => (ended() ? again(a, e, load) : failedEntry(a, e, load, err))); // a failure nobody wants any more is not reported
|
|
105
|
+
return e.promise;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** A load ended under its waiters: they carry on with a fresh one (top of the file). Not when every waiter left: that is why it ended, and nobody is here to answer */
|
|
109
|
+
const again = (a, e, load) => load.left ? NEVER : fetchEntry(a, e);
|
|
110
|
+
|
|
111
|
+
/** Someone ended this load on purpose. A load stopped by its limit is aborted too, and that one failed: it takes the failure path */
|
|
112
|
+
const cancelled = load => load.stop.signal.aborted && !load.stuck;
|
|
113
|
+
|
|
114
|
+
/** The one limit on a load (top of the file). A build that ignores the abort may still answer: what it gives then is freed */
|
|
115
|
+
function limited(a, load, work) {
|
|
116
|
+
const t = load.task, L = a.engine.loading;
|
|
117
|
+
work.then(v => { if (load.stuck) freeValue(load, v); }, () => {});
|
|
118
|
+
return L._limit(work, () => cancelled(load) ? null : t.at, () => {
|
|
119
|
+
load.stuck = true;
|
|
120
|
+
queueMicrotask(() => load.stop.abort()); // after the failure below won the race, so a download that rejects on abort is not what the waiters hear
|
|
121
|
+
return new Error(`no answer for ${Math.round(L.timeoutMs / 1000)} s (engine.loading.timeoutMs)`);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The one wait on an entry that can say more than "give me what you have" (top of the file).
|
|
127
|
+
* @param {any} a the Assets instance
|
|
128
|
+
* @param {any} e
|
|
129
|
+
* @param {{ whole?: boolean, signal?: AbortSignal | null }} [o] whole: a stand-in is no answer; signal: this waiter may leave, rejecting with its reason
|
|
130
|
+
* @returns {Promise<any>}
|
|
131
|
+
* @internal
|
|
132
|
+
*/
|
|
133
|
+
export function waitLoad(a, e, { whole = false, signal = null } = {}) {
|
|
134
|
+
if (whole && e.fellBack) retireEntry(a, e); // the last answer was a stand-in: this caller wants the file
|
|
135
|
+
const got = fetchEntry(a, e), load = e.load;
|
|
136
|
+
if (whole && load) load.whole = true;
|
|
137
|
+
if (!signal) return got;
|
|
138
|
+
return new Promise((res, rej) => {
|
|
139
|
+
const leave = () => {
|
|
140
|
+
rej(signal.reason);
|
|
141
|
+
if (load && --load.waits === 0 && !load.settled) { load.left = true; letGoAll(a, load); cancelLoad(a, load); }
|
|
142
|
+
};
|
|
143
|
+
if (signal.aborted) return leave();
|
|
144
|
+
signal.addEventListener('abort', leave, { once: true });
|
|
145
|
+
const stay = fn => v => { signal.removeEventListener('abort', leave); fn(v); };
|
|
146
|
+
got.then(stay(res), stay(rej));
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** 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 */
|
|
151
|
+
function fallbackCycle(a, e) {
|
|
152
|
+
const chain = [e.name ?? e.url];
|
|
153
|
+
for (let x = e; x?.opts.fallback;) {
|
|
154
|
+
const next = a.entries.get(x.opts.fallback);
|
|
155
|
+
chain.push(x.opts.fallback);
|
|
156
|
+
if (chain.indexOf(x.opts.fallback) < chain.length - 1) return chain;
|
|
157
|
+
x = next;
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** A load failed: a registered file entry degrades (warn + fallback); anything else is recorded and rethrown to the caller */
|
|
163
|
+
function failedEntry(a, e, load, err) {
|
|
164
|
+
const t = load.task;
|
|
165
|
+
e.promise = null;
|
|
166
|
+
const degrade = e.named && !e.opts.build && !e.opts.critical;
|
|
167
|
+
const fb = degrade ? (e.opts.fallback ?? (e.type === 'sound' ? 'silence' : e.type === 'font' ? 'the system font' : 'gray placeholder')) : null;
|
|
168
|
+
a.engine.loading._fail(t, err, load.whole ? null : fb); // whole: its caller says what the failure means, no stand-in is promised to the reader
|
|
169
|
+
const msg = fmt(STRINGS.failed, { what: failureText(t) });
|
|
170
|
+
const loop = degrade && e.opts.fallback ? fallbackCycle(a, e) : null;
|
|
171
|
+
// 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)
|
|
172
|
+
if (loop) { e.load = null; throw codedError('asset-fallback-cycle', msg + fmt(STRINGS.cycle, { chain: loop.join(' -> ') })); }
|
|
173
|
+
if (!degrade) { e.load = null; throw codedError('asset-load', msg); }
|
|
174
|
+
e.fellBack = codedError('asset-load', msg);
|
|
175
|
+
if (!load.whole) warnOnce(coded('asset-load', msg + fmt(STRINGS.fellBack, { fallback: e.opts.fallback ? `"${fb}"` : fb })));
|
|
176
|
+
if (e.opts.fallback) return (e.promise = borrow(a, e, load, a._resolve(e.opts.fallback, e.type)));
|
|
177
|
+
load.settled = true;
|
|
178
|
+
load.value = e.value = e.type === 'model' ? shareModel(a, placeholder('model')) : placeholder(e.type);
|
|
179
|
+
return (e.promise = Promise.resolve(e.value));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** 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 */
|
|
183
|
+
function borrow(a, e, load, from) {
|
|
184
|
+
const ended = () => cancelled(load);
|
|
185
|
+
return fetchEntry(a, from).then(v => {
|
|
186
|
+
if (ended()) return again(a, e, load);
|
|
187
|
+
if (from.load?.value !== v) { letGo(e); return fetchEntry(a, e); } // released between its load finishing and this line
|
|
188
|
+
e.load = from.load;
|
|
189
|
+
return v;
|
|
190
|
+
}, err => {
|
|
191
|
+
if (ended()) return again(a, e, load);
|
|
192
|
+
letGo(e); // not kept as a rejected promise: the next use tries again
|
|
193
|
+
throw err;
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** This name reads nothing now; its next use loads again */
|
|
198
|
+
function letGo(e) { e.load = e.value = e.promise = e.fellBack = null; }
|
|
199
|
+
/** Every name reading this load, the owner and any that fell back to it, lets go of it */
|
|
200
|
+
function letGoAll(a, load) { for (const x of a.entries.values()) if (x.load === load) letGo(x); }
|
|
201
|
+
|
|
202
|
+
/** End a load still running. Its task goes too: nobody is waiting for that attempt, and a loading screen must not stay on it */
|
|
203
|
+
function cancelLoad(a, load) {
|
|
204
|
+
load.stop.abort();
|
|
205
|
+
a.engine.loading._drop(load.task);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Give back what one load made. A font that never reached document.fonts is a no-op here */
|
|
209
|
+
function freeValue(load, v) {
|
|
210
|
+
if (!v) return;
|
|
211
|
+
if (load.type === 'texture' && !load.gameOwned) v.dispose(); // a Texture the game registered is the game's: never disposed here
|
|
212
|
+
if (load.type === 'font') document.fonts.delete(v); // a released font stops matching its family
|
|
213
|
+
if (load.type === 'model') { // always { scene, ... }: generated() wraps a bare geometry too
|
|
214
|
+
v.scene.traverse(o => {
|
|
215
|
+
if (!o.geometry) return;
|
|
216
|
+
o.geometry.dispose();
|
|
217
|
+
[].concat(o.material).forEach(m => { for (const k in m) if (m[k]?.isTexture) m[k].dispose(); m.dispose(); });
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** 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 */
|
|
223
|
+
export function freeEntry(a, e) {
|
|
224
|
+
const load = e.load;
|
|
225
|
+
if (!load) return;
|
|
226
|
+
if (load.owner !== e) { letGo(e); return; } // fell back: the data is the other entry's, and this name only stops reading it
|
|
227
|
+
if (!load.settled) { letGoAll(a, load); cancelLoad(a, load); return; }
|
|
228
|
+
if (e.users > 0) { e.releasePending = true; return; }
|
|
229
|
+
freeValue(load, load.value);
|
|
230
|
+
letGoAll(a, load);
|
|
231
|
+
e.releasePending = false;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* 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
|
|
236
|
+
* nothing holds it. Only what is counted can be judged: copies and leases count and geometry() pins. A texture is handed out uncounted, so without a lease a material may still show it: it
|
|
237
|
+
* is left to the game. Loads kept here wait in a._retired for their last copy, and for dispose
|
|
238
|
+
*/
|
|
239
|
+
export function retireEntry(a, e) {
|
|
240
|
+
const load = e.load;
|
|
241
|
+
if (!load) return;
|
|
242
|
+
if (load.owner !== e) { letGo(e); return; }
|
|
243
|
+
letGoAll(a, load);
|
|
244
|
+
if (!load.settled) cancelLoad(a, load);
|
|
245
|
+
else if (load.users > 0 || load.pinned) a._retired.add(load);
|
|
246
|
+
else if (load.type === 'model') freeValue(load, load.value);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* The one count of who holds an entry's data: a model copy holds a lease (Assets._copy, ended by engine.remove), and assets.lease hands one to a module (content models). Why one count and not
|
|
251
|
+
* a lease table beside the copies: release, trim and a retired build would then have two answers to "is anybody using this". The handle is idempotent, so a module may
|
|
252
|
+
* end it itself and still have it tracked.
|
|
253
|
+
* @returns {{ name: string, remove(): void }}
|
|
254
|
+
*/
|
|
255
|
+
export function takeLease(a, e, name = e.name) {
|
|
256
|
+
const load = e.load, owner = load.owner;
|
|
257
|
+
load.users++; e.users = (e.users || 0) + 1;
|
|
258
|
+
if (owner !== e) owner.users = (owner.users || 0) + 1;
|
|
259
|
+
e.releasePending = owner.releasePending = false;
|
|
260
|
+
let held = true;
|
|
261
|
+
return { name, remove() {
|
|
262
|
+
if (!held) return;
|
|
263
|
+
held = false;
|
|
264
|
+
load.users--; e.users--;
|
|
265
|
+
if (owner !== e) owner.users--;
|
|
266
|
+
if (load.users <= 0 && !load.pinned && a._retired.delete(load)) freeValue(load, load.value);
|
|
267
|
+
if (owner.users <= 0 && owner.releasePending) freeEntry(a, owner);
|
|
268
|
+
} };
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** e just loaded: while long sounds are over the budget, the one asked for longest ago goes (never e itself) */
|
|
272
|
+
function capSounds(a, e) {
|
|
273
|
+
const long = [...a.entries.values()].filter(longSound).sort((x, y) => (x.usedAt ?? 0) - (y.usedAt ?? 0));
|
|
274
|
+
let bytes = long.reduce((n, x) => n + soundBytes(x.value), 0);
|
|
275
|
+
for (const x of long) {
|
|
276
|
+
if (bytes <= SOUND_BUDGET) break;
|
|
277
|
+
if (x !== e) { bytes -= soundBytes(x.value); freeEntry(a, x); }
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** Everything goes, copies or not, and no load finishing later may bring anything back (engine.dispose) */
|
|
282
|
+
export function disposeEntries(a) {
|
|
283
|
+
a._disposed = true;
|
|
284
|
+
for (const e of a.entries.values()) { e.users = 0; freeEntry(a, e); }
|
|
285
|
+
for (const load of a._retired) freeValue(load, load.value);
|
|
286
|
+
a._retired.clear();
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** Load the entries preload() wants and report progress; returns { loaded, failed, ok } (Assets.preload documents it) */
|
|
290
|
+
export async function preloadEntries(a, onProgress, onlyMarked) {
|
|
291
|
+
// generators and fonts only when marked: a font pack may hold many faces, and only those ui.fonts names (or preload: true) are wanted
|
|
292
|
+
const list = [...a.entries.entries()].filter(([, e]) => e.opts.build || e.type === 'font' ? e.opts.preload : !onlyMarked || e.opts.preload);
|
|
293
|
+
let done = 0;
|
|
294
|
+
onProgress?.(list.length ? 0 : 1, '');
|
|
295
|
+
// critical failures are reported by start(); others not already warned about (generated models) are warned here
|
|
296
|
+
await Promise.all(list.map(([name, e]) => fetchEntry(a, e).catch(err => { if (!e.opts.critical) warnOnce(err.message); }).finally(() => {
|
|
297
|
+
done++;
|
|
298
|
+
onProgress?.(done / list.length, name);
|
|
299
|
+
})));
|
|
300
|
+
const failed = list.filter(([name, e]) => a.engine.loading.get(name, e.type)?.phase === 'failed').map(([name]) => name);
|
|
301
|
+
return { loaded: list.length - failed.length, failed, ok: !failed.length };
|
|
302
|
+
}
|
|
@@ -10,10 +10,12 @@
|
|
|
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 { clone as skeletonClone } from 'three/addons/utils/SkeletonUtils.js';
|
|
15
|
+
import { list } from '../base/util.js';
|
|
16
|
+
import { reportError } from '../base/errors.js';
|
|
17
|
+
import { codedError } from '../base/errorHints.js';
|
|
18
|
+
import { note } from '../base/validate.js';
|
|
17
19
|
|
|
18
20
|
// a failed rebuild is reported (soft: the old copies stay on screen) and the swap goes on with the other names
|
|
19
21
|
const failWith = e => (err, what) => reportError(e, err, `asset hot swap: ${what}`, { soft: true });
|
|
@@ -27,7 +29,7 @@ const LAST = 10; // swaps kept for describe().assetSwaps
|
|
|
27
29
|
* with the new ones mesh by mesh; every scene mesh using an old geometry / material gets the new one.
|
|
28
30
|
* @param {any} e @param {{ name: string, type: string, old: any }[]} changed @param {string} why for the report ('edit', 'params')
|
|
29
31
|
*/
|
|
30
|
-
|
|
32
|
+
async function swapModels(e, changed, why = 'edit') {
|
|
31
33
|
const t0 = performance.now(), a = e.assets, fail = failWith(e); // measure
|
|
32
34
|
const names = new Set(changed.filter(c => c.type === 'model').map(c => c.name));
|
|
33
35
|
const geo = new Map(), mat = new Map(), tex = new Map(), protoNew = new Map(), structure = new Set(), copies = {};
|
|
@@ -98,7 +100,7 @@ export async function swapModels(e, changed, why = 'edit') {
|
|
|
98
100
|
const neu = [...protoNew.values()].find(p => p.obj.userData.modelKey === ud.modelKey);
|
|
99
101
|
if (neu) {
|
|
100
102
|
for (const c of [...o.children]) if (meshesOf(c).some(m => oldGeo.has(m.geometry))) o.remove(c);
|
|
101
|
-
for (const c of [...neu.obj
|
|
103
|
+
for (const c of [...skeletonClone(neu.obj).children]) { o.add(c); count(list(JSON.parse(ud.modelKey))[0]); } // a copy: add() takes c out of the live list
|
|
102
104
|
}
|
|
103
105
|
}
|
|
104
106
|
});
|
|
@@ -170,7 +172,7 @@ export async function setParams(e, name, values) {
|
|
|
170
172
|
paramValues(ent, values); // a typo or a wrong type throws here, before anything is rebuilt
|
|
171
173
|
const old = { ...ent };
|
|
172
174
|
ent.tuned = { ...ent.tuned, ...values };
|
|
173
|
-
|
|
175
|
+
e.assets._retire(ent);
|
|
174
176
|
return swapModels(e, [{ name, type: 'model', old }], 'params');
|
|
175
177
|
}
|
|
176
178
|
|
|
@@ -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 { neutralMaterial } from '
|
|
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;
|
|
@@ -78,6 +85,8 @@ export async function loadGltf(assets, url, task) {
|
|
|
78
85
|
let gltf;
|
|
79
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,6 +94,20 @@ export async function loadGltf(assets, url, task) {
|
|
|
85
94
|
return gltf;
|
|
86
95
|
}
|
|
87
96
|
|
|
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
|
+
}
|
|
110
|
+
|
|
88
111
|
/** Load a texture (.ktx2 through KTX2Loader, .hdr through HDRLoader), apply the entry's options and upload it */
|
|
89
112
|
export async function loadTexture(assets, e, task) {
|
|
90
113
|
// a texture made in code, registered by name (manifest textures: { brick: () => makeBrick() } or { brick: myTexture }): used as made,
|
|
@@ -100,15 +123,17 @@ export async function loadTexture(assets, e, task) {
|
|
|
100
123
|
const hdr = /\.hdr(\?|$)/i.test(e.url); // Radiance HDR (environment lighting): float data in linear color
|
|
101
124
|
let t;
|
|
102
125
|
try {
|
|
103
|
-
if (ktx)
|
|
126
|
+
if (ktx) { const k = await decoder(assets, 'ktx2'); task.signal.throwIfAborted(); t = await k.loadAsync(e.url); }
|
|
104
127
|
else if (hdr) t = await new (await import('three/addons/loaders/HDRLoader.js')).HDRLoader().loadAsync(e.url);
|
|
105
128
|
else t = await assets.tex.loadAsync(e.url);
|
|
106
129
|
}
|
|
107
130
|
catch (err) {
|
|
131
|
+
if (task.signal.aborted) throw err;
|
|
108
132
|
// an <img> error carries no status: ask the server once so the report says 404 vs a broken file
|
|
109
133
|
const status = await fetch(e.url, { method: 'HEAD' }).then(r => (!r.ok ? r.status : isHtml(r) ? 404 : 0), () => 0);
|
|
110
134
|
throw new LoadError(status === 404 ? NOT_THERE : status ? `HTTP ${status}` : String(err?.message ?? 'not a decodable image'), { url: e.url, status });
|
|
111
135
|
}
|
|
136
|
+
if (task.signal.aborted) return t;
|
|
112
137
|
if (e.opts.color === false) t.colorSpace = THREE.NoColorSpace;
|
|
113
138
|
else if (!t.isCompressedTexture && !hdr) t.colorSpace = THREE.SRGBColorSpace; // KTX2 carries its own color space
|
|
114
139
|
t.anisotropy = maxAnisotropy(assets.engine.renderer);
|
|
@@ -118,10 +143,10 @@ export async function loadTexture(assets, e, task) {
|
|
|
118
143
|
return t;
|
|
119
144
|
}
|
|
120
145
|
|
|
121
|
-
/** 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 */
|
|
122
147
|
function decoder(assets, kind) {
|
|
123
148
|
return assets._loaders[kind] ||= (async () => {
|
|
124
|
-
const dir = assets.engine.
|
|
149
|
+
const dir = assets.engine._decoders;
|
|
125
150
|
if (kind === 'draco') {
|
|
126
151
|
const { DRACOLoader } = await import('three/addons/loaders/DRACOLoader.js');
|
|
127
152
|
assets.draco = new DRACOLoader();
|
|
@@ -130,13 +155,25 @@ function decoder(assets, kind) {
|
|
|
130
155
|
return assets.draco;
|
|
131
156
|
}
|
|
132
157
|
const { KTX2Loader } = await import('three/addons/loaders/KTX2Loader.js');
|
|
133
|
-
|
|
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);
|
|
134
161
|
if (dir) assets.ktx2.setTranscoderPath(dir + 'basis/');
|
|
135
162
|
assets.gltf.setKTX2Loader(assets.ktx2);
|
|
136
163
|
return assets.ktx2;
|
|
137
164
|
})();
|
|
138
165
|
}
|
|
139
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
|
+
|
|
140
177
|
/** FontFace descriptors an asset pack's fonts entry may carry (everything else on the entry is the asset's own: url, family, critical...) */
|
|
141
178
|
const FONT_DESCRIPTORS = ['weight', 'style', 'stretch', 'unicodeRange', 'display', 'featureSettings', 'variationSettings'];
|
|
142
179
|
/**
|
|
@@ -153,7 +190,7 @@ export async function loadFont(assets, e, task) {
|
|
|
153
190
|
const desc = Object.fromEntries(FONT_DESCRIPTORS.filter(k => e.opts[k] != null).map(k => [k, String(e.opts[k])]));
|
|
154
191
|
const face = new FontFace(family, buf, { display: 'swap', ...desc });
|
|
155
192
|
try { await face.load(); } catch (err) { throw new LoadError(`not a font the browser can read (${err.message})`, { url: e.url }); }
|
|
156
|
-
document.fonts.add(face);
|
|
193
|
+
if (!task.signal.aborted) document.fonts.add(face);
|
|
157
194
|
return face;
|
|
158
195
|
}
|
|
159
196
|
|
|
@@ -178,6 +215,7 @@ export async function generated(assets, name, build, params, task) {
|
|
|
178
215
|
const ctx = { palette: assets.palette, engine: assets.engine }; // a function() generator reads this.palette
|
|
179
216
|
const colored = Object.keys(assets.palette).length > 0;
|
|
180
217
|
const baked = (await bakedIndex(assets))[name];
|
|
218
|
+
task.signal.throwIfAborted(); // the generator has not run yet: an ended load need not start it
|
|
181
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
|
|
182
220
|
const bakedOk = baked && JSON.stringify(baked.params ?? null) === same && (!colored || baked.source === 'file');
|
|
183
221
|
const file = async url => wrap(fromGLTF(await loadGltf(assets, url, task)));
|
|
@@ -194,13 +232,14 @@ export async function generated(assets, name, build, params, task) {
|
|
|
194
232
|
if (r.ok && !/^\s*</.test(text)) info = JSON.parse(text);
|
|
195
233
|
else if (!r.ok) why = `${r.status}${text ? ': ' + text.slice(0, 160) : ''}`;
|
|
196
234
|
} catch (err) { why = String(err?.message ?? err); }
|
|
235
|
+
task.signal.throwIfAborted();
|
|
197
236
|
if (!info) {
|
|
198
|
-
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);
|
|
199
238
|
return bakedOk ? file(BASE + 'models/baked/' + baked.file) : wrap(await build.call(ctx, params));
|
|
200
239
|
}
|
|
201
240
|
if (bakedOk) {
|
|
202
241
|
if (baked.source === 'file' || baked.key === info.key) return file(BASE + 'models/baked/' + baked.file);
|
|
203
|
-
warnOnce(coded('asset-cache', STALE
|
|
242
|
+
warnOnce(coded('asset-cache', fmt(STALE, { name })));
|
|
204
243
|
}
|
|
205
244
|
if (info.hit) return file(CACHE + info.key + '.glb');
|
|
206
245
|
const t0 = performance.now(), v = await build.call(ctx, params); // measure:build time
|