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
package/core/assetEntry.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
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
|
-
// Plain functions that take the Assets instance, so they stay out of the class's public surface.
|
|
5
|
-
import { warnOnce, fmt } from './validate.js';
|
|
6
|
-
import { codedError, coded } from './errorHints.js';
|
|
7
|
-
import { loadGltf, loadTexture, loadFont, generated, placeholder, LoadError } from './assetLoad.js';
|
|
8
|
-
import { failureText } from './Loading.js';
|
|
9
|
-
import { paramValues } from './assetManifest.js';
|
|
10
|
-
|
|
11
|
-
const STRINGS = {
|
|
12
|
-
failed: 'Asset failed to load: {what}',
|
|
13
|
-
fellBack: '; using {fallback} instead, the game continues (mark it critical: true if the game cannot start without it)',
|
|
14
|
-
missingRefs: 'Asset loaded with missing references: {what} (missing {list}); materials show without those files',
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/** Mark a model template's geometry and materials as shared (copies share them; engine.remove must not dispose them) */
|
|
18
|
-
function shareModel(a, g) {
|
|
19
|
-
g.scene.traverse(o => { if (o.geometry) a.shared.add(o.geometry); for (const m of [].concat(o.material || [])) a.shared.add(m); });
|
|
20
|
-
return g;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Shadow flags of a model copy, one rule for files, generators and content props: an explicit castShadow / receiveShadow (the model() call,
|
|
25
|
-
* 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
|
|
26
|
-
* (a decal that must not cast stays that way); otherwise (a file, or a generator that set nothing) every mesh casts and receives.
|
|
27
|
-
* @param {import('three').Object3D} root
|
|
28
|
-
* @param {{ castShadow?: boolean, receiveShadow?: boolean }} [set]
|
|
29
|
-
*/
|
|
30
|
-
export function shadowDefaults(root, { castShadow, receiveShadow } = {}) {
|
|
31
|
-
let decided = false;
|
|
32
|
-
root.traverse(o => { if (/** @type {any} */ (o).isMesh && (o.castShadow || o.receiveShadow)) decided = true; });
|
|
33
|
-
const cast = castShadow ?? (decided ? null : true), recv = receiveShadow ?? (decided ? null : true);
|
|
34
|
-
root.traverse(o => { if (/** @type {any} */ (o).isMesh) { if (cast != null) o.castShadow = cast; if (recv != null) o.receiveShadow = recv; } });
|
|
35
|
-
return root;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** Load an entry as a task in engine.loading; a registered, non-critical file that fails resolves to its fallback */
|
|
39
|
-
export function fetchEntry(a, e) {
|
|
40
|
-
if (e.promise) return e.promise;
|
|
41
|
-
const L = a.engine.loading, name = e.variantOf ?? e.name ?? e.url;
|
|
42
|
-
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 });
|
|
43
|
-
if (e.type === 'model') {
|
|
44
|
-
const load = e.opts.build ? (t.phase('build'), generated(a, e.url, e.opts.build, e.schema ? paramValues(e) : e.opts.params, t)) : loadGltf(a, e.url, t);
|
|
45
|
-
e.promise = load.then(g => shareModel(a, g));
|
|
46
|
-
} else if (e.type === 'texture') e.promise = loadTexture(a, e, t);
|
|
47
|
-
else if (e.type === 'font') e.promise = loadFont(a, e, t);
|
|
48
|
-
else if (e.type === 'sound' && e.opts.build) e.promise = Promise.resolve(e.opts.build); // a synth function: nothing to download
|
|
49
|
-
else if (e.type === 'sound') {
|
|
50
|
-
t.phase('download');
|
|
51
|
-
e.promise = a.engine.audio.load(e.url).catch(err => { throw new LoadError(err.reason ?? err.message, { url: e.url }); }); // reason: the bare cause, the asset line adds name and path
|
|
52
|
-
}
|
|
53
|
-
e.promise = e.promise.then(v => {
|
|
54
|
-
L._done(t);
|
|
55
|
-
const what = `${e.type} "${name}" <- ${e.url}`;
|
|
56
|
-
if (t.missing.length) warnOnce(coded('asset-missing-ref', fmt(STRINGS.missingRefs, { what, list: t.missing.join(', ') })));
|
|
57
|
-
return (e.value = v);
|
|
58
|
-
}, err => failedEntry(a, e, t, err));
|
|
59
|
-
return e.promise;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** A load failed: a registered file entry degrades (warn + fallback); anything else is recorded and rethrown to the caller */
|
|
63
|
-
function failedEntry(a, e, t, err) {
|
|
64
|
-
e.promise = null;
|
|
65
|
-
const degrade = e.named && !e.opts.build && !e.opts.critical;
|
|
66
|
-
const fb = degrade ? (e.opts.fallback ?? (e.type === 'sound' ? 'silence' : e.type === 'font' ? 'the system font' : 'gray placeholder')) : null;
|
|
67
|
-
a.engine.loading._fail(t, err, fb);
|
|
68
|
-
const msg = fmt(STRINGS.failed, { what: failureText(t) });
|
|
69
|
-
if (!degrade) throw codedError('asset-load', msg);
|
|
70
|
-
warnOnce(coded('asset-load', msg + fmt(STRINGS.fellBack, { fallback: e.opts.fallback ? `"${fb}"` : fb })));
|
|
71
|
-
if (e.opts.fallback) return (e.promise = fetchEntry(a, a._resolve(e.opts.fallback, e.type))); // e.value stays null: the fallback entry owns the memory
|
|
72
|
-
e.value = e.type === 'model' ? shareModel(a, placeholder('model', a.engine)) : placeholder(e.type);
|
|
73
|
-
return (e.promise = Promise.resolve(e.value));
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** Free an entry's GPU memory; while model copies are still in use it waits (releasePending) and the last engine.remove frees it */
|
|
77
|
-
export function freeEntry(e) {
|
|
78
|
-
if (!e.value) return;
|
|
79
|
-
if (e.users > 0) { e.releasePending = true; return; }
|
|
80
|
-
if (e.type === 'texture' && !e.opts.texture) e.value.dispose(); // a Texture the game registered is the game's: never disposed here
|
|
81
|
-
if (e.type === 'font') document.fonts.delete(e.value); // a released font stops matching its family
|
|
82
|
-
if (e.value.isBufferGeometry) e.value.dispose(); // code-generated geometry
|
|
83
|
-
else if (e.type === 'model') {
|
|
84
|
-
(e.value.scene ?? e.value).traverse?.(o => {
|
|
85
|
-
if (!o.isMesh) return;
|
|
86
|
-
o.geometry.dispose();
|
|
87
|
-
[].concat(o.material).forEach(m => { for (const k in m) if (m[k]?.isTexture) m[k].dispose(); m.dispose(); });
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
e.value = null; e.promise = null; e.releasePending = e.pinned = false;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/** Load the entries preload() wants and report progress; returns { loaded, failed, ok } (Assets.preload documents it) */
|
|
94
|
-
export async function preloadEntries(a, onProgress, onlyMarked) {
|
|
95
|
-
// generators and fonts only when marked: a font pack may hold many faces, and only those style.ui.fonts names (or preload: true) are wanted
|
|
96
|
-
const list = [...a.entries.entries()].filter(([, e]) => e.opts.build || e.type === 'font' ? e.opts.preload : !onlyMarked || e.opts.preload);
|
|
97
|
-
let done = 0;
|
|
98
|
-
onProgress?.(list.length ? 0 : 1, '');
|
|
99
|
-
// critical failures are reported by start(); others not already warned about (generated models) are warned here
|
|
100
|
-
await Promise.all(list.map(([name, e]) => fetchEntry(a, e).catch(err => { if (!e.opts.critical) warnOnce(err.message); }).finally(() => {
|
|
101
|
-
done++;
|
|
102
|
-
onProgress?.(done / list.length, name);
|
|
103
|
-
})));
|
|
104
|
-
const failed = list.filter(([name, e]) => a.engine.loading.get(name, e.type)?.phase === 'failed').map(([name]) => name);
|
|
105
|
-
return { loaded: list.length - failed.length, failed, ok: !failed.length };
|
|
106
|
-
}
|
package/core/describeRender.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
// describe().render: renderer, post, lights and probes. Facts read from three.js and the post chain.
|
|
2
|
-
// Who set a value lives in one place, describe().look: each `look` here is the path of that record ('look.tone.exposure'), and `writer` is copied
|
|
3
|
-
// from that record, not a second answer worked out again (review r2 #11); 'engine' when no look part covers it. `writer` is the one "who set it"
|
|
4
|
-
// field name across describe() (look, owned, render), so a tool never has to know which section says `by` and which says `writer`.
|
|
5
|
-
// This is information only: the engine never warns when a game changes the renderer or lights.
|
|
6
|
-
import { SHADOW_TYPES } from './shadowTypes.js';
|
|
7
|
-
import { describeLook } from './look/report.js';
|
|
8
|
-
import { rv } from './math.js';
|
|
9
|
-
import { toneName } from './look/coreParts.js';
|
|
10
|
-
import { defineOwned } from './owned.js';
|
|
11
|
-
|
|
12
|
-
const shadowName = v => Object.keys(SHADOW_TYPES).find(k => SHADOW_TYPES[k].three === v) ?? String(v);
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Record how the renderer was made.
|
|
16
|
-
* @param {any} e
|
|
17
|
-
* @param {{ owned: boolean }} o owned: false when the game passed its own renderer (then the style's tone mapping / exposure were not applied by the engine)
|
|
18
|
-
*/
|
|
19
|
-
export function recordRender(e, { owned }) {
|
|
20
|
-
// tone mapping is written once at creation (coreParts.js). Who writes it now is one owned record like every other look value (core/owned.js),
|
|
21
|
-
// not a comparison against a remembered creation value here: a direct renderer.toneMapping write yields it ('three (engine yielded)'), quietly (once),
|
|
22
|
-
// because that write is the documented way to change the curve. A game-supplied renderer (owned false) starts manual: the engine never wrote it
|
|
23
|
-
e._oTone = defineOwned(e, { id: 'toneMapping', part: 'tone', key: 'toneMapping', read: () => e.renderer.toneMapping, objects: [e.renderer], once: true,
|
|
24
|
-
write: v => { e.renderer.toneMapping = v; }, levels: { manual: "engine.look.tone.manual('toneMapping')" } });
|
|
25
|
-
if (owned) e._oTone.mark(); else e._oTone.manual(true, 'game renderer');
|
|
26
|
-
// style vs engine only says which default the creation write used (the pack named a curve, or the baseline AgX)
|
|
27
|
-
e._renderBase = { owned, toneBy: e.style?.toneMapping != null ? 'style' : 'engine' };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** The render section: structured data plus one compact text block (`text`) @param {any} e */
|
|
31
|
-
export function describeRender(e) {
|
|
32
|
-
const r = e.renderer, b = e._renderBase;
|
|
33
|
-
if (!b) return undefined;
|
|
34
|
-
const look = describeLook(e) ?? {};
|
|
35
|
-
// { look, writer }: the record to read in describe().look and its writer; 'engine' (no look record) when no part covers it
|
|
36
|
-
const who = (part, key) => { const row = look[part]?.[key]; return row ? { look: `look.${part}.${key}`, writer: row.writer } : { look: null, writer: 'engine' }; };
|
|
37
|
-
e._oTone.check(); // a direct write since the last look turns the record to 'yielded' (quiet: no warning)
|
|
38
|
-
// a post effect in the 'tone' slot replaces the tone-mapping stage (render/PostFX.js): then it, not renderer.toneMapping, makes the picture
|
|
39
|
-
const toneFx = e.post?._list?.find(h => h.slot === 'tone' && h.enabled);
|
|
40
|
-
const tone = toneFx ? { value: `post effect '${toneFx.name}' (tone slot)`, ...who('post', `${toneFx.name}.enabled`) }
|
|
41
|
-
: { value: toneName(r.toneMapping), writer: e._oTone.on ? b.toneBy : 'game' };
|
|
42
|
-
const exposure = { value: rv(r.toneMappingExposure), ...who('tone', 'exposure') }; // keyframes / a function: the value used this frame
|
|
43
|
-
const shadows = { enabled: r.shadowMap.enabled, type: shadowName(r.shadowMap.type), ...who('shadow', 'type') };
|
|
44
|
-
const post = (e.post?._list || []).map(h => ({ name: h.name, on: h.enabled, params: { ...h.params }, ...who('post', `${h.name}.enabled`),
|
|
45
|
-
...(e.post._offWhy?.[h.name] && !h.enabled ? { why: e.post._offWhy[h.name] } : {}) }));
|
|
46
|
-
const lights = Object.entries(e.lights || {}).filter(([, l]) => l.parent)
|
|
47
|
-
.map(([name, l]) => ({ name, type: l.type, intensity: rv(l.intensity), source: 'engine-default', ...who('lights', `${name}.intensity`) }));
|
|
48
|
-
// the game's own point / spot lights (core/gameLights.js): adopted like a lightPool light, listed with the line that added them
|
|
49
|
-
for (const l of e._gameLights?.list() ?? []) lights.push({ name: l.name || l.type, type: l.type, intensity: rv(l.intensity), castShadow: l.castShadow,
|
|
50
|
-
source: 'game', writer: 'game', at: e._things?.entryOf(l)?.[0]?.at ?? null, ...(e._gameLights.idled(l) ? { shadowIdled: true } : {}) });
|
|
51
|
-
const kv = x => Object.entries(x).map(([k, v]) => `${k}=${typeof v === 'number' ? rv(v) : v}`).join(' ');
|
|
52
|
-
const srgb = r.outputColorSpace === 'srgb' ? '' : ' (WRONG: colors are encoded for srgb; color textures must be srgb, data maps linear, see assets.report)';
|
|
53
|
-
let text = [
|
|
54
|
-
`renderer: ${tone.value} (${tone.writer}) exposure ${exposure.value} (${exposure.writer}) shadows ${shadows.enabled ? shadows.type : 'off'} (${shadows.writer})${b.owned ? '' : ' [game-supplied renderer]'} output ${r.outputColorSpace}${srgb}`,
|
|
55
|
-
`post: ${post.map(x => `${x.name}${x.on ? '' : x.why ? ' off (low-tier default)' : ' off'}${Object.keys(x.params).length ? `{${kv(x.params)}}` : ''} (${x.writer})`).join(', ') || 'none'}${e.post?.antialias ? ' + MSAA' : ''}`,
|
|
56
|
-
`lights: ${lights.map(l => `${l.name} ${l.type} ${l.intensity} (${l.writer}${l.at ? ' ' + l.at : ''})`).join(', ')}`,
|
|
57
|
-
].join('\n');
|
|
58
|
-
// probe sets (render/probes.js): how many, how dense, who made them and who writes the scene probe now
|
|
59
|
-
const probes = [...(e._probeSets ?? [])].map(s => s.info());
|
|
60
|
-
if (probes.length) text += `\nprobes: ${probes.map(p => `${p.count} (${p.counts.join('x')}, step ${p.step.join('/')}) from ${p.source} by ${p.owner}, follow ${p.follow}${p.writer ? ` (${p.writer})` : ''}`).join('; ')}`;
|
|
61
|
-
const dv0 = e.debug?.viewState?.(), dv = dv0 && dv0.mode !== 'off' ? dv0 : null;
|
|
62
|
-
if (dv) text = `DEBUG VIEW "${dv.mode}" (by ${dv.owner}) is ON: ${dv.what}. This is NOT the real look; the debug view 'off' restores it.
|
|
63
|
-
` + text;
|
|
64
|
-
// render scale: the canvas resolution against the display. auto: the adaptive resolution lowered it at some point (it raises it back when frames are fast)
|
|
65
|
-
const dpr = (typeof devicePixelRatio === 'number' && devicePixelRatio) || 1, cur = r.getPixelRatio(), ad = e.adaptive;
|
|
66
|
-
const scale = { current: Math.round(cur * 100) / 100, devicePixelRatio: dpr, upscaled: cur < dpr - 0.01, autoLowered: !!ad?.lowered && cur < (ad.max ?? cur) - 0.01,
|
|
67
|
-
adaptive: !!ad?.on, floor: ad?.min ?? null, max: ad?.max ?? null };
|
|
68
|
-
text += `
|
|
69
|
-
render scale: ${scale.current} of device pixel ratio ${dpr}${scale.upscaled ? ' (picture is upscaled, softer than the screen)' : ''}${scale.autoLowered ? ` (auto-lowered by adaptive resolution, floor ${scale.floor}; adaptiveResolution: false turns it off)` : ''}`;
|
|
70
|
-
return { debugView: dv, scale, toneMapping: tone, exposure, shadows, post, lights, probes, text };
|
|
71
|
-
}
|
package/core/holds.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
// Who holds the engine still: pause, freeze (each ends with its handle's remove()), runState, and the camera takeover (takeCamera / cameraOverride).
|
|
2
|
-
// Each is a named stack (core/stacks.js: 'pause' and 'freeze' kind any, 'camera' kind top), so they follow the same owner rules as every shared quantity:
|
|
3
|
-
// engine.freeze('menu') is engine.mod('freeze', { owner: 'menu' }) with the loop's side effects added (ending the last pause restarts the loop).
|
|
4
|
-
// One entry per mechanism: the handle's remove() ends a pause / freeze (there is no engine.resume / engine.unfreeze).
|
|
5
|
-
import { warnOnce } from './validate.js';
|
|
6
|
-
import { coded } from './errorHints.js';
|
|
7
|
-
import { ownerArgs } from './sharedPoint.js';
|
|
8
|
-
|
|
9
|
-
// The pause / freeze handle is { owner, remove() } only: no chaining, so a pause is ended in exactly one way.
|
|
10
|
-
function handle(owner, remove) { return { owner, remove }; }
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* The three hold stacks: 'freeze' and 'pause' (kind any), 'camera' (kind top). services.js and the test engines call this, so both get the same stacks.
|
|
14
|
-
* The pause stack does the loop side effect itself (onChange), not engine.pause(): engine.mod('pause', { owner }), engine.pause(owner), the handle's
|
|
15
|
-
* remove() and _resume(owner) are then one behavior. Making mod('pause') throw instead would leave a quantity that engine.mod names in describe
|
|
16
|
-
* but refuses to change, a special case to remember; with onChange there is no path that holds the stack without stopping the loop.
|
|
17
|
-
* @param {any} engine
|
|
18
|
-
*/
|
|
19
|
-
export function defineHoldStacks(engine) {
|
|
20
|
-
engine.stacks.define('freeze', { kind: 'any', save: false }); // who froze gameplay
|
|
21
|
-
engine.stacks.define('pause', { kind: 'any', save: false, onChange: () => { // who paused the loop; it resumes only when empty
|
|
22
|
-
if (engine.stacks.get('pause').size()) engine.paused = true;
|
|
23
|
-
else if (!engine.disposed) { engine.paused = false; engine._loop(); }
|
|
24
|
-
} });
|
|
25
|
-
engine.stacks.define('camera', { kind: 'top', save: false }); // who holds the camera; the latest is in charge (cameraOverride)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const holdMethods = {
|
|
29
|
-
/**
|
|
30
|
-
* Pause the real-time loop (the picture stops and the game stops advancing). owner names who paused (default 'game'; pause({ owner }) works too): the loop
|
|
31
|
-
* stays paused until every owner has resumed, and _resume(owner) by someone who did not pause does not undo another owner's pause.
|
|
32
|
-
* kind tells engine.runState what the pause means: 'test' (a test or the dev bridge holds it: 'test-paused'); any other pause reads as 'paused'.
|
|
33
|
-
* Returns a handle: remove() resumes this owner.
|
|
34
|
-
* @param {string | { owner?: string, kind?: 'test' }} [owner] @param {{ kind?: 'test' }} [opts]
|
|
35
|
-
* @returns {{ owner: string, remove(): void }}
|
|
36
|
-
* @example const p = engine.pause('perf-test'); ... p.remove();
|
|
37
|
-
*/
|
|
38
|
-
pause(owner, opts) {
|
|
39
|
-
const a = ownerArgs(owner, opts);
|
|
40
|
-
const P = this.stacks.get('pause');
|
|
41
|
-
P.take({ owner: a.owner, value: { kind: a.opts.kind ?? null } }); // the stack's onChange sets this.paused (defineHoldStacks), same as engine.mod('pause')
|
|
42
|
-
return handle(a.owner, () => { if (P.has(a.owner)) this._resume(a.owner); });
|
|
43
|
-
},
|
|
44
|
-
/**
|
|
45
|
-
* @internal The dev bridge and tests: end owner's pause (the handle's remove() calls this); with no pause held (a headless engine) it starts live running.
|
|
46
|
-
* A call by a non-owner while others hold a pause is ignored with a dev warning (a pause that silently stays stops even rendering).
|
|
47
|
-
* @param {string | { owner?: string }} [owner]
|
|
48
|
-
*/
|
|
49
|
-
_resume(owner) {
|
|
50
|
-
const { owner: o } = ownerArgs(owner);
|
|
51
|
-
const P = this.stacks.get('pause');
|
|
52
|
-
if (P.size() && !P.has(o)) { warnOnce(coded('pause-owner', `ending the pause of '${o}': paused by ${P.names().map(n => `'${n}'`).join(', ')}, not by '${o}'. End a pause with the handle pause() returned (p.remove()), or the pause stays`)); return this; }
|
|
53
|
-
// with holders the stack's onChange restarts the loop; with none (headless start) resume itself starts it
|
|
54
|
-
if (!P.release(o) && !P.size() && !this.disposed) { this.paused = false; this._loop(); }
|
|
55
|
-
return this;
|
|
56
|
-
},
|
|
57
|
-
// Gameplay freeze (menus, flow 'paused'): no fixed steps (movement, timers, tick and every time view but ambient stop) while frame hooks
|
|
58
|
-
// and rendering go on, so the picture and UI stay alive.
|
|
59
|
-
// Gameplay logic (quest checks, cutscene waits) belongs in fixed, or check engine.frozen first in frame (see the top of this file).
|
|
60
|
-
// Unlike pause(), which stops rendering too and is for tests and step(). owner is the freezer's name; play resumes only when all
|
|
61
|
-
// have unfrozen. step() obeys freezes as well. Same owner rules as every stack (core/stacks.js).
|
|
62
|
-
/**
|
|
63
|
-
* Freeze gameplay for owner (default 'game'; freeze({ owner, kind }) works too). kind 'title' marks a title screen waiting for start (runState 'title-frozen').
|
|
64
|
-
* Ambient animation (uniforms.uTime: wind, water, clouds) keeps moving behind the freeze; ambient: true stops it too (a photo / cutscene still).
|
|
65
|
-
* Returns a handle whose remove() releases this owner's freeze. Same as engine.mod('freeze', { owner }) plus the kind.
|
|
66
|
-
* @param {string | { owner?: string, kind?: 'title', ambient?: boolean }} [owner] @param {{ kind?: 'title', ambient?: boolean }} [opts]
|
|
67
|
-
* @returns {{ owner: string, remove(): void }}
|
|
68
|
-
*/
|
|
69
|
-
freeze(owner, opts) {
|
|
70
|
-
const a = ownerArgs(owner, opts);
|
|
71
|
-
const h = this.stacks.get('freeze').take({ owner: a.owner, value: { kind: a.opts.kind ?? null, ambient: !!a.opts.ambient } });
|
|
72
|
-
return handle(a.owner, h.remove);
|
|
73
|
-
},
|
|
74
|
-
/** True while someone has frozen gameplay */
|
|
75
|
-
get frozen() { return this.stacks.get('freeze').value(); },
|
|
76
|
-
/**
|
|
77
|
-
* The one answer to "why is the page (not) advancing"; the dev bridge and the MCP tools copy it as-is.
|
|
78
|
-
* state: 'loading' | 'title-frozen' (a freeze of kind 'title' is up, waiting for start) | 'test-paused' (only pauses of kind 'test': the bridge or a test)
|
|
79
|
-
* | 'paused' (paused or frozen by owners, listed in `owners`) | 'running';
|
|
80
|
-
* owners: every pause and freeze owner, so closing one part's pause can be told from a player's;
|
|
81
|
-
* blockedBy: what keeps the player's input from driving the game: each opaque input context ('win-settings', 'ui-title', 'dialogue', 'cutscene'...),
|
|
82
|
-
* 'error' (a gameplay error froze the game) and 'loading' (the loading screen blocks).
|
|
83
|
-
* @returns {{ state: 'loading' | 'title-frozen' | 'test-paused' | 'paused' | 'running', owners: string[], blockedBy: string[] }}
|
|
84
|
-
*/
|
|
85
|
-
get runState() {
|
|
86
|
-
const P = this.stacks.get('pause'), F = this.stacks.get('freeze'), owners = [...P.names(), ...F.names()];
|
|
87
|
-
const lv = this.loading?.view();
|
|
88
|
-
const onlyTest = owners.length > 0 && !F.size() && !P.entries().some(d => d.value.kind !== 'test');
|
|
89
|
-
const state = !this.ready || !lv?.done ? 'loading' : F.entries().some(d => d.value.kind === 'title') ? 'title-frozen'
|
|
90
|
-
: !owners.length && !this.paused ? 'running' : !owners.length || onlyTest ? 'test-paused' : 'paused';
|
|
91
|
-
const blockedBy = (this.input?.holders ?? []).filter(h => !h.pass).map(h => h.context);
|
|
92
|
-
if (F.has('error')) blockedBy.push('error');
|
|
93
|
-
if (lv?.blocked) blockedBy.push('loading');
|
|
94
|
-
return { state, owners, blockedBy };
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
// ---------- camera takeover ----------
|
|
98
|
-
// While anyone holds the camera, no camera module moves it (camera/common.js reads cameraOverride). The 'camera' stack is kind top: the latest holder
|
|
99
|
-
// is in charge, and releasing it hands the camera back to the previous holder (or to the rig when none is left), never to nobody.
|
|
100
|
-
/**
|
|
101
|
-
* Take the camera over: camera modules leave engine.camera alone until every holder has released it. The latest holder is in charge; its focus
|
|
102
|
-
* (optional) is where the world loads around. Returns { remove() } (only this owner's claim). engine.cameraOverride shows the holder in charge.
|
|
103
|
-
* @param {string | { owner: string, focus?: import('three').Vector3 }} owner @param {{ focus?: import('three').Vector3, [k: string]: any }} [opts] extra fields stay readable on cameraOverride
|
|
104
|
-
* @returns {{ owner: string, remove(): void }}
|
|
105
|
-
* @example const cam = engine.takeCamera('photo-mode', { focus: engine.player.position }); ... cam.remove();
|
|
106
|
-
*/
|
|
107
|
-
takeCamera(owner, opts) {
|
|
108
|
-
const a = ownerArgs(owner, opts, undefined);
|
|
109
|
-
const h = this.stacks.get('camera').take({ owner: a.owner, value: { ...a.opts, owner: a.owner } });
|
|
110
|
-
return { owner: a.owner, remove: h.remove };
|
|
111
|
-
},
|
|
112
|
-
/**
|
|
113
|
-
* The camera holder in charge ({ owner, focus? }), or null. Read-only: take the camera with engine.takeCamera(owner).
|
|
114
|
-
* @type {{ owner: string, focus?: import('three').Vector3, [k: string]: any } | null}
|
|
115
|
-
*/
|
|
116
|
-
get cameraOverride() { return this.stacks?.get('camera').value() ?? null; },
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
const HOLD_STACKS = { pause: 'pause', freeze: 'freeze', camera: 'camera', debugView: 'debug.view' };
|
|
120
|
-
/**
|
|
121
|
-
* Everyone who holds something, in one place (empty parts left out): pause / freeze / camera / debugView [{ owner, at }]; input [{ context, owner,
|
|
122
|
-
* pass }] (pushed input contexts); gates { action: [owners] } (input.gate). Every other shared value is in describe().shared (core/stacks.js).
|
|
123
|
-
* Lives here, next to the hold stacks it reads, so describe() and the input-holds test use the same function (no second copy).
|
|
124
|
-
* "Why can't I move / why is time slow" is answered here without knowing which module did it.
|
|
125
|
-
*/
|
|
126
|
-
export function describeHolds(e) {
|
|
127
|
-
const out = {};
|
|
128
|
-
for (const [k, n] of Object.entries(HOLD_STACKS)) { const h = e.stacks.has(n) ? e.stacks.get(n).holders() : []; if (h.length) out[k] = h; }
|
|
129
|
-
const inp = e.input.holders; if (inp.length) out.input = inp;
|
|
130
|
-
const g = e.stacks.has('input.gate') ? e.stacks.get('input.gate') : null, gates = {};
|
|
131
|
-
for (const id of g?.ids() ?? []) if (g.size(id)) gates[id] = g.names(id);
|
|
132
|
-
if (Object.keys(gates).length) out.gates = gates;
|
|
133
|
-
return out;
|
|
134
|
-
}
|
package/core/look/coreParts.js
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
// look.tone, lights, clouds.
|
|
2
|
-
// look.tone = renderer exposure (the curve is written once at creation, then plain three.js), look.lights = the engine's placeholder sun + hemisphere, look.cloudShadow = the cloud-shadow patch.
|
|
3
|
-
// Why here and not in sceneMethods: the 0.2 renames (recipe 52) now write the 'game' layer, and the style values
|
|
4
|
-
// are the 'style' layer, so describe().look / describe().render can say who set a value instead of guessing from start values.
|
|
5
|
-
import * as THREE from 'three';
|
|
6
|
-
import { defineLookPart } from './part.js';
|
|
7
|
-
import { defineOwned } from '../owned.js';
|
|
8
|
-
import { warnOnce } from '../validate.js';
|
|
9
|
-
import { codedError } from '../errorHints.js';
|
|
10
|
-
|
|
11
|
-
const ONCE = 'The engine writes toneMapping once, at createEngine (style.toneMapping, else AgX), and never again, so your write stays';
|
|
12
|
-
|
|
13
|
-
const NO_DRIVER = "look.lights {k}: a function value is evaluated every frame by a time-of-day module; nothing drives {k} now (no sky, sky({ sun / hemisphere: false }), or look.lights.manual(...)), so it is ignored. Install sky(), or set a number / color";
|
|
14
|
-
import { setRoomEnvironment } from '../../render/lights.js';
|
|
15
|
-
import { badTerm, retakeTerms } from '../../render/terms.js';
|
|
16
|
-
|
|
17
|
-
/** style.toneMapping names -> three constants */
|
|
18
|
-
export const TONE = { aces: THREE.ACESFilmicToneMapping, agx: THREE.AgXToneMapping, neutral: THREE.NeutralToneMapping, none: THREE.NoToneMapping };
|
|
19
|
-
/** three's toneMapping constant -> the style name ('agx'), or the number as text for one outside TONE (CustomToneMapping...) */
|
|
20
|
-
export const toneName = v => Object.keys(TONE).find(k => TONE[k] === v) ?? String(v);
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* The curve written once at creation: the style's toneMapping name, else AgX for the baseline (none without it).
|
|
24
|
-
* AgX over ACES for the baseline: it rolls bright values off to white without ACES's hue shifts (saturated colors drifting to yellow / cyan)
|
|
25
|
-
* and extra contrast, so whatever colors a game adds later keep their hue; a style picks its own curve
|
|
26
|
-
*/
|
|
27
|
-
function toneMappingOf(name, baseline) {
|
|
28
|
-
if (name == null) return baseline ? THREE.AgXToneMapping : THREE.NoToneMapping;
|
|
29
|
-
if (!(name in TONE)) throw codedError('style-value', `style.toneMapping must be one of ${Object.keys(TONE).map(k => `"${k}"`).join(', ')}; got ${JSON.stringify(name)}. ` +
|
|
30
|
-
'Any other three curve: engine.renderer.toneMapping = THREE.<Name>ToneMapping after createEngine');
|
|
31
|
-
return TONE[name];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Exposure over the day: [[time 0-1, exposure], ...] sorted by time, wrapping across midnight (after the last row it blends back to the first),
|
|
36
|
-
* or ({ time, weather, season, state, sky }) => number (core/look/state.js). Returns the per-frame function of that context, null for a plain number (set once); throws on anything else
|
|
37
|
-
*/
|
|
38
|
-
export function exposureDriver(v) {
|
|
39
|
-
if (typeof v === 'number') return null;
|
|
40
|
-
if (typeof v === 'function') return v;
|
|
41
|
-
const ok = Array.isArray(v) && v.length > 0 && v.every((k, i) => Array.isArray(k) && typeof k[0] === 'number' && typeof k[1] === 'number' && k[0] >= 0 && k[0] <= 1 && (i === 0 || k[0] > v[i - 1][0]));
|
|
42
|
-
if (!ok) throw codedError('style-value', `exposure must be a number, [[time 0-1, exposure], ...] sorted by time (e.g. [[0, 1.6], [0.5, 1], [0.8, 1.3]]) or ({ time, state }) => number; got ${JSON.stringify(v)}`);
|
|
43
|
-
return ctx => {
|
|
44
|
-
const t = ctx.time, n = v.length;
|
|
45
|
-
let i = -1; for (let k = 0; k < n; k++) if (v[k][0] <= t) i = k;
|
|
46
|
-
const a = v[i < 0 ? n - 1 : i], b = v[(i + 1) % n]; // before the first row or after the last: the segment across midnight
|
|
47
|
-
const span = (b[0] - a[0] + 1) % 1 || 1, f = ((t - a[0] + 1) % 1) / span;
|
|
48
|
-
return a[1] + (b[1] - a[1]) * f;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
const badExposure = v => { try { exposureDriver(v); return null; } catch (err) { return err.message; } };
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Write the tone curve once and register look.tone and look.lights. owned: false when the game passed its own renderer: then neither the style's
|
|
55
|
-
* curve nor its exposure is applied at start (the renderer is the game's), but a later look.tone.set({ exposure }) still writes exposure.
|
|
56
|
-
* baseline: the engine's own renderer, under every style (user decision 2026-11-02). The engine defaults are then a technical render baseline
|
|
57
|
-
* instead of "off": AgX tone mapping, soft sun shadows, a neutral generated environment, a dimmer hemisphere (the environment adds ambient too).
|
|
58
|
-
* Not art: a pack still picks every color, and one that wants none of it says so (style.toneMapping: 'none', look.shadow enabled false, look.lights env.intensity 0).
|
|
59
|
-
* Why under every pack: a pack that never mentioned tone mapping or an environment rendered flatter than a plain, well-set-up three.js scene.
|
|
60
|
-
* @param {any} e @param {{ owned: boolean, baseline?: boolean }} o
|
|
61
|
-
*/
|
|
62
|
-
export function defineCoreLook(e, { owned, baseline = false }) {
|
|
63
|
-
// e.renderer, not a captured renderer: start() may replace it (fallback 'webgl' on the WebGPU route, core/startup.js)
|
|
64
|
-
const r = () => e.renderer;
|
|
65
|
-
const B = 'technical render baseline under every style (not art), so plain three.js materials look as they would in a well-set-up three.js scene';
|
|
66
|
-
// Tone mapping is not a look param (user decision 2026-11-03, plan 2026-11-02 section 3): it is a render baseline the engine writes once here,
|
|
67
|
-
// at creation, and never again. A game changes it with plain three.js (engine.renderer.toneMapping = THREE.ACESFilmicToneMapping) and nothing
|
|
68
|
-
// overwrites it, because no engine code writes toneMapping after this line; a wrapper param would be a second road to the same property.
|
|
69
|
-
if (owned) r().toneMapping = toneMappingOf(e.style.toneMapping, baseline);
|
|
70
|
-
defineLookPart(e, {
|
|
71
|
-
id: 'tone', group: 'atmosphere', module: 'core', object: () => e.renderer, applyAtStart: owned, docs: ['recipes/52-look.md'],
|
|
72
|
-
params: {
|
|
73
|
-
exposure: { type: 'any', default: 1, neutral: true, fn: true, cost: 'uniform', check: badExposure, desc: 'a number, day keyframes [[time 0-1, exposure], ...] or ({ time, weather, season, state, sky }) => number (a time-of-day module evaluates it each frame)' },
|
|
74
|
-
},
|
|
75
|
-
// the old curve key gets the plain three.js line instead of a bare "unknown key" (normalize runs before the key check, write.js)
|
|
76
|
-
normalize: p => { if (p && 'mapping' in p) throw codedError('look-param', `look.tone.set(): there is no mapping key; the curve is plain three.js: engine.renderer.toneMapping = THREE.AgXToneMapping (or ACESFilmic / Neutral / No / Custom). ${ONCE}`); return p; },
|
|
77
|
-
style: () => (owned ? { exposure: e.style.exposure } : {}),
|
|
78
|
-
read: () => ({ exposure: e.exposureDriver ? undefined : r().toneMappingExposure }),
|
|
79
|
-
apply(v, changed) {
|
|
80
|
-
if (changed.has('exposure')) {
|
|
81
|
-
// keyframes / a function become exposureDriver, which a time-of-day module (sky) evaluates each frame; core knows no time of day
|
|
82
|
-
e.exposureDriver = exposureDriver(v.exposure);
|
|
83
|
-
if (typeof v.exposure === 'number') r().toneMappingExposure = v.exposure;
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
// plain three.js always works: the curve itself is three's renderer.toneMapping, so the error shows that instead of saying it is impossible
|
|
87
|
-
// why the tone slot and not THREE.ShaderChunk: a ShaderChunk edit is page-wide and WebGL only; the slot runs on both renderers (recipes/52)
|
|
88
|
-
noPatch: "look.tone has no GLSL hook and no curve param. A curve of your own is a post stage in the 'tone' slot, on WebGL and WebGPU alike: " +
|
|
89
|
-
"engine.look.post.add({ name: 'myCurve', slot: 'tone', create: ctx => pass, node: (input, ctx) => colorNode }) (it replaces the output tone " +
|
|
90
|
-
'mapping and outputs display color). A three.js curve: engine.renderer.toneMapping = THREE.ACESFilmicToneMapping; the engine never writes toneMapping after createEngine',
|
|
91
|
-
noReplace: "to own tone mapping completely, add a post stage in the 'tone' slot: engine.look.post.add({ name: 'myCurve', slot: 'tone', create, node }) " +
|
|
92
|
-
'(both renderers), or set engine.renderer.toneMapping yourself (the engine writes it only once, at creation), or pass your own renderer: createEngine({ renderer }) (recipes/50)',
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
const { sun, hemi } = e.lights, scene = e.scene;
|
|
96
|
-
const off = "look.lights.set({ sun: { intensity: 0 } }) (or hemi), or createEngine({ lights: false }) and light the world with your own three.js lights";
|
|
97
|
-
const why = 'placeholder light so a scene without a sky module (and the gray placeholders) is never black; an installed sky drives it from style.sky.keyframes instead';
|
|
98
|
-
defineLookPart(e, {
|
|
99
|
-
id: 'lights', group: 'atmosphere', module: 'core', object: () => e.lights, docs: ['recipes/52-look.md'],
|
|
100
|
-
params: {
|
|
101
|
-
'sun.intensity': { type: 'number', default: 2, min: 0, fn: true, cost: 'uniform', why, off },
|
|
102
|
-
'sun.color': { type: 'any', default: '#ffffff', fn: true, neutral: true, cost: 'uniform', desc: 'any THREE.Color input' },
|
|
103
|
-
'hemi.intensity': { type: 'number', default: baseline ? 0.6 : 1.2, min: 0, fn: true, cost: 'uniform', why, off },
|
|
104
|
-
'hemi.color': { type: 'any', default: '#ffffff', fn: true, neutral: true, cost: 'uniform', desc: 'sky color of the hemisphere light' },
|
|
105
|
-
'hemi.ground': { type: 'any', default: '#555555', fn: true, cost: 'uniform', why: 'darker ground color, so faces turned down read darker than faces turned up', off: "look.lights.set({ hemi: { ground: '#ffffff' } })" },
|
|
106
|
-
// two keys, one meaning each (render/lights.js refreshRoom): env.intensity is always the absolute scene.environmentIntensity, env.share
|
|
107
|
-
// only the sky's budget split. One key that changed meaning when a sky was installed made a game's 0.7 silently read as "70% of the ambient"
|
|
108
|
-
'env.intensity': { type: 'number', default: baseline ? 0.5 : 0, min: 0, cost: 'uniform',
|
|
109
|
-
desc: "neutral room environment (three's RoomEnvironment through PMREM, generated, no asset) as scene.environment, at this scene.environmentIntensity; 0 = none. Only written while scene.environment is empty or this map: your own scene.environment, or a sky's look.env, wins. Under a sky env.share applies instead, unless a game or style wrote env.intensity: then this value is written as it is (no time-of-day follow; the hemisphere light keeps the whole ambient budget)",
|
|
110
|
-
why: B + '; PBR (Standard / Physical) materials need an environment to reflect, or metals render black', off: 'look.lights.set({ env: { intensity: 0 } })' },
|
|
111
|
-
'env.share': { type: 'number', default: baseline ? 0.5 : 0, min: 0, max: 1, cost: 'uniform',
|
|
112
|
-
desc: "under a sky only: the room map's share (0..1) of the style's ambient budget, following the time of day; the hemisphere light gets the rest (one diffuse budget, not a fill on top). 0 = no room map under the sky. Not read without a sky (env.intensity is) or once a game wrote env.intensity (describe().look.env.source.mode)",
|
|
113
|
-
why: B + '; under a sky the PBR environment is part of the ambient light of the day, so it dims at night', off: 'look.lights.set({ env: { share: 0 } })' },
|
|
114
|
-
},
|
|
115
|
-
read: () => ({ 'sun.intensity': sun.intensity, 'hemi.intensity': hemi.intensity }),
|
|
116
|
-
apply(v, changed) {
|
|
117
|
-
// a key a style driver (sky) drives: the driver writes the three.js light from value(key), which holds game sets and effects
|
|
118
|
-
// a function value (({ time, state }) => ...) is evaluated by the sky each frame (tick with the frame context); without a sky nothing calls it
|
|
119
|
-
const set = (k, fn) => { if (!changed.has(k) || v[k] === undefined || e.look.lights?.author.driven(k)) return; if (typeof v[k] === 'function') { if (!e.look.lights.driven(k)) warnOnce(NO_DRIVER.replace('{k}', k)); return; } fn(v[k]); };
|
|
120
|
-
set('sun.intensity', x => { sun.intensity = x; });
|
|
121
|
-
set('sun.color', x => sun.color.set(x));
|
|
122
|
-
set('hemi.intensity', x => { hemi.intensity = x; });
|
|
123
|
-
set('hemi.color', x => hemi.color.set(x));
|
|
124
|
-
set('hemi.ground', x => hemi.groundColor.set(x));
|
|
125
|
-
if (changed.has('env.intensity') || changed.has('env.share')) {
|
|
126
|
-
// absolute: a game / style / debug layer wrote env.intensity (the engine's own default does not count), so under a sky the engine yields to it
|
|
127
|
-
const src = e.look?.lights?._source('env.intensity');
|
|
128
|
-
// the game's or the sky's map is never overwritten, and the map is built only once a material reads it (render/lights.js refreshRoom)
|
|
129
|
-
setRoomEnvironment(e, { base: v['env.intensity'], share: v['env.share'], absolute: !!src && src.layer !== 'engine' });
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
noPatch: 'lights have no shader of their own; how surfaces take light is look.surface (lighting / ramp)',
|
|
133
|
-
noReplace: "to light the world yourself, turn the engine lights off: createEngine({ lights: false }), or sky({ sun: false }); to write the engine sun yourself: engine.look.lights.manual('sun')",
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* look.view: the camera and the drawing buffer as the engine touches them on its own. No params: the only verb is manual(), which takes
|
|
139
|
-
* camera.far (raised by fog distance / terrain view range), the pixel ratio (adaptive resolution) or the camera pose (a camera module) for the game.
|
|
140
|
-
* Why a part with nothing to set: these writes need a home for manual() and describe().owned.
|
|
141
|
-
* @param {any} e
|
|
142
|
-
*/
|
|
143
|
-
/**
|
|
144
|
-
* Every engine write of camera.fov (settings menu slider, camera modules) goes through here: it yields to a fov the game set itself (owned 'camera.fov').
|
|
145
|
-
* @param {any} e @param {number} v
|
|
146
|
-
*/
|
|
147
|
-
export function setFov(e, v) { e._setFov(v); }
|
|
148
|
-
|
|
149
|
-
export function defineViewLook(e) {
|
|
150
|
-
defineLookPart(e, {
|
|
151
|
-
id: 'view', group: 'screen', module: 'core', object: () => e.camera, docs: ['recipes/52-look.md'],
|
|
152
|
-
noPatch: 'the view has no shader; for your own camera use engine.takeCamera(owner)',
|
|
153
|
-
noReplace: "to place the camera yourself use const cam = engine.takeCamera('me') (cam.remove() gives it back); " +
|
|
154
|
-
"to stop the engine changing camera.far, camera.fov or the pixel ratio: engine.look.view.manual('far' | 'fov' | 'pixelRatio')",
|
|
155
|
-
});
|
|
156
|
-
const cam = () => e.camera;
|
|
157
|
-
e._oFar = defineOwned(e, { id: 'camera.far', part: 'view', key: 'far', read: () => cam().far, objects: [e.camera],
|
|
158
|
-
write: v => { cam().far = v; cam().updateProjectionMatrix(); }, levels: { manual: "engine.look.view.manual('far')" } });
|
|
159
|
-
e._oPixelRatio = defineOwned(e, { id: 'pixelRatio', part: 'view', key: 'pixelRatio', read: () => e.renderer.getPixelRatio(), objects: [e.renderer],
|
|
160
|
-
levels: { manual: "engine.look.view.manual('pixelRatio')", set: 'engine.setPixelRatio(1.5)' } });
|
|
161
|
-
// fov: the settings menu slider and camera modules (first person / rts / fixed shots, and restoring the fov at uninstall) write it.
|
|
162
|
-
// They all go through e._setFov, so a game that sets camera.fov itself (a zoom, a cutscene) is not undone by the next camera switch.
|
|
163
|
-
e._oFov = defineOwned(e, { id: 'camera.fov', part: 'view', key: 'fov', read: () => cam().fov, objects: [e.camera],
|
|
164
|
-
write: v => { if (cam().fov !== v) { cam().fov = v; cam().updateProjectionMatrix(); } }, levels: { manual: "engine.look.view.manual('fov')" } });
|
|
165
|
-
/** @internal every engine write of camera.fov (settings menu, camera modules): yields to the game's own value */
|
|
166
|
-
e._setFov = (/** @type {number} */ v) => e._oFov.drive(v);
|
|
167
|
-
e._oFar.mark(); e._oPixelRatio.mark(); e._oFov.mark();
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* look.cloudShadow: drifting cloud shadows on the ground and on every material from makeMaterial / applyEffects. The patch is on by default (clouds: true)
|
|
172
|
-
* so the style and the weather can darken it later without a recompile; how dark comes from style.clouds.shadow, 0 (nothing drawn) without one.
|
|
173
|
-
* Declared as a part so this default is visible in describe().look and the catalog instead of hiding in applyEffects.
|
|
174
|
-
* @param {any} e
|
|
175
|
-
*/
|
|
176
|
-
export function defineCloudShadowLook(e) {
|
|
177
|
-
const u = e.uniforms, c = e.style.clouds ?? {};
|
|
178
|
-
defineLookPart(e, {
|
|
179
|
-
id: 'cloudShadow', group: 'surface', module: 'core', object: () => u, docs: ['recipes/52-look.md'],
|
|
180
|
-
params: {
|
|
181
|
-
shadow: { type: 'number', default: 0, min: 0, max: 1, cost: 'uniform', desc: 'darkest cloud shadow (uCloudShadow)',
|
|
182
|
-
why: 'every engine material carries the cloud-shadow patch (applyEffects clouds: true) so a style or the weather can darken it with no recompile; at 0 it draws nothing',
|
|
183
|
-
off: 'look.cloudShadow.set({ shadow: 0 }); to leave the patch out of one material: applyEffects(mat, { clouds: false })' },
|
|
184
|
-
scale: { type: 'number', default: 0.006, min: 0, neutral: true, cost: 'uniform', desc: 'cloud size (smaller = bigger clouds)' },
|
|
185
|
-
speed: { type: 'array', default: [0.012, 0.006], neutral: true, cost: 'uniform', desc: 'drift [x, z] per second' },
|
|
186
|
-
},
|
|
187
|
-
style: () => ({ shadow: c.shadow, scale: c.scale, speed: c.speed }),
|
|
188
|
-
read: () => ({ shadow: u.uCloudShadow.value, scale: u.uCloudScale.value }),
|
|
189
|
-
apply(v, changed) {
|
|
190
|
-
if (changed.has('shadow')) u.uCloudShadow.value = v.shadow;
|
|
191
|
-
if (changed.has('scale')) u.uCloudScale.value = v.scale;
|
|
192
|
-
if (changed.has('speed')) u.uCloudSpeed.value.set(v.speed[0], v.speed[1]);
|
|
193
|
-
},
|
|
194
|
-
noPatch: 'the cloud-shadow GLSL is shared with the sky clouds; change the look with look.cloudShadow.set({ shadow, scale, speed }), or put your own term in its place: look.cloudShadow.replace({ glsl, tsl })',
|
|
195
|
-
// (c): the game's own term in place of the engine's on every engine material, both backends (render/terms.js); false = none at all
|
|
196
|
-
replace: { accepts: "{ glsl, tsl, uniforms?, pars?, slot? } (a patch, default slot 'lighting'; uTime / uCloud* and threedogCloudShadow(worldPos) in scope, ctx.fx.cloudShadow on WebGPU) or false (no engine cloud shadow anywhere: draw your own)",
|
|
197
|
-
loses: ["the engine's cloud-shadow math on ground and objects (shadow / scale / speed still write their uniforms, which your code may read)"] },
|
|
198
|
-
validate: (k, v) => k === '@replace' ? badTerm('cloudShadow', v, !!e.renderer?.isWebGPURenderer) : null,
|
|
199
|
-
applyReplace: () => retakeTerms(e, 'clouds'),
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* look.season: the season and snow / ash cover tint on engine materials (the 'season' patch: foliage on plants, ground on the terrain).
|
|
205
|
-
* Its colors are style.seasons and the 'look.ground.cover' point (modules/sky/tint.js); this part only holds the replace slot, so a game can put
|
|
206
|
-
* its own tint in place of the engine's on both backends and still read the signals: uFoliageTint / uGroundTint / uFoliageMix / uGroundMix
|
|
207
|
-
* (season and cover blended), uCover (x foliage, y ground: the cover amount alone), engine.calendar.season in JS.
|
|
208
|
-
* @param {any} e
|
|
209
|
-
*/
|
|
210
|
-
export function defineSeasonLook(e) {
|
|
211
|
-
defineLookPart(e, {
|
|
212
|
-
id: 'season', group: 'surface', module: 'core', object: () => e.uniforms, docs: ['recipes/52-look.md'], params: {},
|
|
213
|
-
noPatch: "the tint colors come from style.seasons and engine.mod('look.ground.cover', { owner, value: { ground, foliage, amount } }); your own tint: look.season.replace(kind => ({ glsl, tsl }))",
|
|
214
|
-
replace: { accepts: "{ glsl, tsl, uniforms?, pars?, slot? } or kind => that ('foliage' | 'ground'; an object spec gets THREEDOG_SEASON_KIND 0 / 1 in GLSL), default slot 'color', the tint and cover uniforms and threedogSeason(color, kind) in scope; or false (no engine tint anywhere)",
|
|
215
|
-
loses: ["the engine's tint math (the calendar and the cover still write the uniforms your code reads)"] },
|
|
216
|
-
validate: (k, v) => k === '@replace' ? badTerm('season', v, !!e.renderer?.isWebGPURenderer) : null,
|
|
217
|
-
applyReplace: () => retakeTerms(e, 'season'),
|
|
218
|
-
});
|
|
219
|
-
}
|