threedog 0.7.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 +196 -1
- package/README.md +6 -9
- package/core/{Animator.js → assets/Animator.js} +28 -18
- package/core/{Assets.js → assets/Assets.js} +98 -54
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +237 -0
- package/core/{assetHot.js → assets/assetHot.js} +7 -6
- 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} +6 -12
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +26 -23
- 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} +98 -110
- package/core/{errorHints.js → base/errorHints.js} +5 -9
- package/core/{errors.js → base/errors.js} +6 -6
- package/core/{events.generated.js → base/events.generated.js} +1 -0
- package/core/{math.js → base/math.js} +15 -4
- package/core/{params.js → base/params.js} +3 -4
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +28 -7
- package/core/{Engine.js → engine/Engine.js} +80 -77
- 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} +14 -12
- package/core/{loop.js → engine/loop.js} +68 -47
- package/core/{moduleSlots.js → engine/moduleSlots.js} +6 -6
- package/core/{moduleTypes.js → engine/moduleTypes.js} +13 -14
- package/core/{modules.js → engine/modules.js} +14 -11
- package/core/{page.js → engine/page.js} +36 -23
- package/core/{plugins.js → engine/plugins.js} +6 -9
- package/core/{services.js → engine/services.js} +47 -40
- package/core/{startup.js → engine/startup.js} +26 -24
- package/core/{Input.js → input/Input.js} +30 -22
- 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} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +30 -16
- package/core/{Describe.js → inspect/Describe.js} +26 -22
- package/core/{Inspect.js → inspect/Inspect.js} +9 -7
- 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} +52 -20
- package/core/{catalog.js → inspect/catalog.js} +3 -3
- 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} +21 -20
- package/core/{describeText.js → inspect/describeText.js} +11 -6
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +15 -16
- 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} +14 -17
- package/core/{sharedPoint.js → ops/sharedPoint.js} +8 -8
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +12 -14
- 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} +23 -25
- package/core/{Views.js → scene/Views.js} +14 -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} +17 -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/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/{sceneDelta.js → scene/sceneDelta.js} +2 -2
- package/core/{sceneMethods.js → scene/sceneMethods.js} +36 -13
- package/core/scene/stepPoses.js +55 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +6 -5
- package/core/{thingOps.js → scene/thingOps.js} +4 -3
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{view.js → scene/view.js} +17 -16
- package/core/{Batching.js → stream/Batching.js} +85 -27
- package/core/{Stream.js → stream/Stream.js} +60 -30
- package/core/{batchGroups.js → stream/batchGroups.js} +10 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- 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 +22 -19
- package/docs/API.md +24 -23
- package/docs/CODEMAP.md +76 -183
- package/docs/COMMANDS.md +66 -58
- package/docs/CONVENTIONS.md +54 -14
- package/docs/MIGRATING-0.8.md +169 -0
- package/docs/THREE.md +78 -29
- 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 +29 -29
- package/docs/api/characters.md +23 -18
- package/docs/api/clock.md +1 -1
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +6 -6
- package/docs/api/dialogue.md +3 -3
- package/docs/api/engine.md +45 -43
- package/docs/api/events.md +3 -2
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +4 -5
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +7 -7
- package/docs/api/interactions.md +4 -4
- package/docs/api/inventory.md +9 -9
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +7 -7
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +10 -10
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +2 -2
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +2 -2
- package/docs/api/post.md +20 -3
- 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 +8 -7
- package/docs/api/stream.md +7 -7
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +7 -8
- package/docs/api/terrainDraw.md +1 -1
- package/docs/api/timeline.md +2 -2
- package/docs/api/tools.md +25 -22
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +1 -1
- package/docs/api/water.md +1 -1
- package/docs/api/weather.md +9 -9
- package/docs/api/weatherDraw.md +3 -3
- package/docs/api/world.md +5 -5
- package/docs/recipes/01-new-game.md +25 -40
- package/docs/recipes/02-npc.md +19 -20
- package/docs/recipes/03-items-pickups.md +27 -43
- package/docs/recipes/04-quests.md +3 -4
- package/docs/recipes/05-props-bake.md +29 -39
- package/docs/recipes/06-clock-events.md +27 -18
- package/docs/recipes/07-flow-scenes-pause.md +12 -17
- package/docs/recipes/08-weather-sky.md +88 -34
- package/docs/recipes/09-materials-lights-models.md +22 -36
- package/docs/recipes/10-blender-level.md +6 -7
- package/docs/recipes/11-vehicles.md +30 -22
- package/docs/recipes/12-navmesh.md +9 -8
- package/docs/recipes/13-animation.md +39 -17
- package/docs/recipes/14-custom-module.md +14 -13
- package/docs/recipes/15-perf.md +49 -26
- package/docs/recipes/16-dev-bridge.md +32 -52
- package/docs/recipes/18-world.md +36 -23
- package/docs/recipes/19-shooting-picking.md +4 -2
- package/docs/recipes/20-content-actions-save.md +30 -35
- package/docs/recipes/21-camera.md +33 -5
- package/docs/recipes/22-shop-gold.md +0 -4
- package/docs/recipes/23-ops.md +10 -10
- package/docs/recipes/26-ui-parts.md +22 -12
- package/docs/recipes/27-net.md +0 -2
- package/docs/recipes/28-terrain.md +117 -21
- package/docs/recipes/29-grid.md +2 -2
- package/docs/recipes/30-templates.md +55 -19
- package/docs/recipes/31-audio.md +5 -5
- package/docs/recipes/32-action-game.md +15 -6
- package/docs/recipes/33-stream-sources.md +2 -2
- package/docs/recipes/34-environment-lighting.md +67 -19
- package/docs/recipes/35-picture-from-reference.md +10 -17
- package/docs/recipes/36-ground-plants.md +105 -0
- package/docs/recipes/40-scene.md +7 -11
- package/docs/recipes/43-shader-patches-surfaces.md +20 -41
- package/docs/recipes/44-water-weather-hooks.md +48 -43
- package/docs/recipes/45-cascaded-shadows.md +39 -17
- package/docs/recipes/46-blender-art-route.md +7 -8
- package/docs/recipes/49-game-module-contract.md +5 -5
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/52-around-the-picture.md +54 -98
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +12 -16
- package/docs/recipes/56-webgpu-tsl.md +16 -14
- package/docs/recipes/57-control.md +9 -2
- package/docs/recipes/58-input.md +2 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +29 -24
- package/docs/recipes/62-picture-code.md +49 -17
- package/docs/recipes/63-third-person-start.md +17 -4
- package/docs/recipes/64-particles.md +1 -1
- package/docs/recipes/65-swarm.md +140 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +2 -2
- package/examples/{sheepisland → perf-island}/.threedog/content-index.json +1 -1
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +12 -11
- 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 +1 -0
- package/examples/rc2d/GAMEMAP.md +3 -2
- package/examples/rc2d/main.js +1 -3
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +3 -2
- 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 +1 -0
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +4 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +8 -7
- package/index.js +31 -31
- package/llms.txt +9 -13
- package/modules/ambience/Ambience.js +11 -8
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +13 -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 +48 -24
- package/modules/camera/contract.js +1 -0
- package/modules/camera/projection.js +2 -2
- package/modules/characters/Character.js +33 -30
- package/modules/characters/NPC.js +27 -19
- package/modules/characters/assetModel.js +14 -10
- 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 +168 -214
- package/modules/characters/moveHelpers.js +14 -3
- package/modules/characters/movers/common.js +16 -14
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +7 -6
- package/modules/characters/movers/simple.js +3 -3
- package/modules/characters/movers/support.js +8 -8
- package/modules/characters/npcAvoid.js +4 -4
- package/modules/characters/npcSim.js +23 -17
- 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 +2 -2
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/walkTo.js +11 -17
- package/modules/collision/Collision.js +26 -20
- 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 +61 -99
- package/modules/content/loader.js +14 -17
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +10 -7
- 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 +17 -14
- package/modules/content/rules.js +25 -21
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +20 -20
- 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 +37 -24
- package/modules/gameplay/Inventory.js +8 -9
- package/modules/gameplay/Quests.js +16 -9
- package/modules/gameplay/boxOps.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +3 -4
- package/modules/gameplay/inventoryOps.js +0 -1
- package/modules/gameplay/pickups.js +22 -23
- package/modules/gameplay/questSave.js +3 -3
- package/modules/grid/Grid.js +1 -1
- package/modules/grid/Layer.js +4 -4
- package/modules/grid/index.js +7 -8
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +37 -55
- package/modules/hud/index.js +17 -11
- package/modules/hud/parts.js +4 -4
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +12 -10
- package/modules/level/index.js +47 -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 +28 -181
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +88 -0
- package/modules/music/Music.js +30 -26
- 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 +11 -8
- package/modules/particles/effect.js +7 -5
- package/modules/particles/shaders.js +2 -1
- package/modules/photo/Photo.js +15 -17
- 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 +108 -39
- package/modules/settings/apply.js +6 -6
- package/modules/settings/sections.js +16 -14
- 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 +14 -27
- package/modules/sky/tint.js +1 -1
- 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 +70 -52
- 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 +28 -34
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +32 -27
- package/modules/terrain/terrainGen.js +17 -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 +27 -19
- package/modules/timeline/Tween.js +6 -6
- package/modules/timeline/shots.js +5 -7
- package/modules/triggers/index.js +9 -9
- package/modules/vegetation/Vegetation.js +30 -23
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +23 -18
- package/modules/vegetation/groundChunks.js +11 -31
- package/modules/vegetation/index.js +8 -6
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +16 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +41 -30
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +22 -18
- package/modules/world/World.js +8 -8
- 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 +11 -9
- package/package.json +42 -7
- package/presets.js +1 -3
- package/render/PostFX.js +39 -27
- package/render/backend.js +26 -32
- 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/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +27 -23
- 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 +1 -1
- package/render/lighting.js +5 -3
- package/render/lightmap.js +20 -20
- 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 +20 -4
- package/render/ownFrame.js +4 -4
- package/render/patches.js +13 -13
- package/render/postWebGL.js +12 -10
- package/render/probes.js +16 -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 +57 -11
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +200 -153
- package/types/gameplay.d.ts +163 -91
- 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} +7 -15
- 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} +12 -8
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +2 -2
- 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 +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 +1 -1
- 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 +2 -1
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +16 -12
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +5 -3
- package/types/generated/render/PostFX.d.ts +17 -11
- 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 +11 -11
- package/types/physics.d.ts +99 -70
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +38 -71
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +4 -3
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +5 -3
- package/core/assetEntry.js +0 -109
- package/core/holds.js +0 -134
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- 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/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/{tier.js → scene/tier.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
package/types/tsl.d.ts
CHANGED
|
@@ -10,13 +10,15 @@ type Node = any;
|
|
|
10
10
|
* position: object space before the instance transform (positionGeometry); origin: the object's world origin (objectOrigin());
|
|
11
11
|
* amplitude: metres per metre of height. Reads uTime, uWind, uWindFreq.
|
|
12
12
|
* @example
|
|
13
|
-
* mat.positionNode = positionLocal.add(wind(positionGeometry, objectOrigin(), float(0.3))); // plain Mesh (InstancedMesh:
|
|
13
|
+
* mat.positionNode = positionLocal.add(wind(positionGeometry, objectOrigin(), float(0.3))); // plain Mesh (InstancedMesh: wrap the offset in instanceOffset())
|
|
14
|
+
* @experimental
|
|
14
15
|
*/
|
|
15
16
|
export function wind(position: Node, origin: Node, amplitude: Node | number): Node;
|
|
16
17
|
/**
|
|
17
|
-
* GLSL float threedogCloudShadow(vec3 worldPos): light factor 0-1 under the drifting clouds (1 = no shadow). Reads uTime,
|
|
18
|
+
* GLSL float threedogCloudShadow(vec3 worldPos): light factor 0-1 under the drifting clouds (1 = no shadow). Reads uTime, uWeatherCloud, uCloudShadow*, uCloudShadowSpeed.
|
|
18
19
|
* @example
|
|
19
20
|
* mat.colorNode = color(0x88aa66).mul(cloudShadow(positionWorld));
|
|
21
|
+
* @experimental
|
|
20
22
|
*/
|
|
21
23
|
export function cloudShadow(worldPos: Node): Node;
|
|
22
24
|
/**
|
|
@@ -24,19 +26,42 @@ export function cloudShadow(worldPos: Node): Node;
|
|
|
24
26
|
* A vec4 color is read as its rgb.
|
|
25
27
|
* @example
|
|
26
28
|
* mat.colorNode = season(texture(map), 0);
|
|
29
|
+
* @experimental
|
|
27
30
|
*/
|
|
28
31
|
export function season(color: Node, kind: Node | 0 | 1): Node;
|
|
29
32
|
/**
|
|
30
33
|
* World position of the drawn object's origin (an InstancedMesh: of each instance), vec3. Works for any Mesh / InstancedMesh sharing the material;
|
|
31
34
|
* BatchedMesh throws [tsl-misuse].
|
|
35
|
+
* @experimental
|
|
32
36
|
*/
|
|
33
37
|
export function objectOrigin(): Node;
|
|
34
38
|
/**
|
|
35
|
-
*
|
|
39
|
+
* An object-space offset carried through the drawn instance's rotation and scale (a plain Mesh: the offset as it is). A positionNode runs after the instance transform, so an
|
|
40
|
+
* offset meant for before it, like wind()'s, goes through this. BatchedMesh throws [tsl-misuse].
|
|
41
|
+
* @example
|
|
42
|
+
* mat.positionNode = positionLocal.add(instanceOffset(wind(positionGeometry, objectOrigin(), float(0.3))));
|
|
43
|
+
* @experimental
|
|
44
|
+
*/
|
|
45
|
+
export function instanceOffset(offset: Node): Node;
|
|
46
|
+
/**
|
|
47
|
+
* GLSL float threedogHash(vec2 p): a repeatable random number 0-1 from a 2D position.
|
|
48
|
+
* @experimental
|
|
49
|
+
*/
|
|
50
|
+
export function hash(p: Node): Node;
|
|
51
|
+
/**
|
|
52
|
+
* GLSL float threedogNoise(vec2 p): smooth value noise 0-1, the one behind the engine's clouds and cloud shadows. No uniforms.
|
|
53
|
+
* @example
|
|
54
|
+
* mat.colorNode = color(0x88aa66).mul(noise(positionWorld.xz.mul(0.5)).mul(0.4).add(0.8));
|
|
55
|
+
* @experimental
|
|
56
|
+
*/
|
|
57
|
+
export function noise(p: Node): Node;
|
|
58
|
+
/**
|
|
59
|
+
* engine.uniforms as TSL uniform nodes (uTime, uWind, uWeatherCloud, uFoliageTint, uSunDir, uDaylight ...), cached per engine. They read the same
|
|
36
60
|
* { value } objects, so engine.uniforms.uWind.value = 2 changes GLSL and TSL materials alike.
|
|
37
61
|
* @example
|
|
38
62
|
* const u = uniforms(engine);
|
|
39
63
|
* mat.emissiveNode = color(0xffcc66).mul(float(1).sub(u.uDaylight));
|
|
64
|
+
* @experimental
|
|
40
65
|
*/
|
|
41
66
|
export function uniforms(engine: { uniforms: object }): Record<string, Node>;
|
|
42
67
|
/**
|
|
@@ -44,6 +69,7 @@ export function uniforms(engine: { uniforms: object }): Record<string, Node>;
|
|
|
44
69
|
* No uniforms: p is any 2D pattern position you choose (world xz times a scale, a uv...). octaves: up to 4 (dabs: 3).
|
|
45
70
|
* @example
|
|
46
71
|
* mat.colorNode = color(0xb09070).mul(detailNoise(positionWorld.xz.mul(4), 1, 2).rgb.mul(2));
|
|
72
|
+
* @experimental
|
|
47
73
|
*/
|
|
48
74
|
export function detailNoise(p: Node, kind: Node | 0 | 1 | 2 | 3, octaves: Node | number): Node;
|
|
49
75
|
/**
|
|
@@ -51,21 +77,25 @@ export function detailNoise(p: Node, kind: Node | 0 | 1 | 2 | 3, octaves: Node |
|
|
|
51
77
|
* View space; the result is a normal for material.normalNode.
|
|
52
78
|
* @example
|
|
53
79
|
* mat.normalNode = detailBump(positionView, normalView, detailNoise(positionWorld.xz.mul(4), 0, 2).a, 1, faceDirection);
|
|
80
|
+
* @experimental
|
|
54
81
|
*/
|
|
55
82
|
export function detailBump(surfPos: Node, surfNorm: Node, h: Node, k: Node | number, faceDir: Node | number): Node;
|
|
56
83
|
/**
|
|
57
84
|
* GLSL vec3 threedogWrapDiffuse(float nl, float wrap, vec3 lightColor, float shadow, vec3 albedo): the half-lambert light beyond plain Lambert,
|
|
58
85
|
* to add to directDiffuse. nl = dot(normal, sunDir). Call it from your LightingModel's direct() (lightColor there already carries the shadow: pass shadow 1).
|
|
86
|
+
* @experimental
|
|
59
87
|
*/
|
|
60
88
|
export function wrapDiffuse(nl: Node, wrap: Node | number, lightColor: Node, shadow: Node | number, albedo: Node): Node;
|
|
61
89
|
/**
|
|
62
90
|
* GLSL vec3 threedogShadowTint(vec3 ambient, vec3 tint, float strength, float soft, float nl, float shadow): the ambient with the shaded side's hue moved
|
|
63
91
|
* toward tint (brightness kept). shadow: 1 lit / 0 shadowed (the sun's lightNode.shadowNode); soft: terminator width in n.l.
|
|
92
|
+
* @experimental
|
|
64
93
|
*/
|
|
65
94
|
export function shadowTint(ambient: Node, tint: Node, strength: Node | number, soft: Node | number, nl: Node, shadow: Node | number): Node;
|
|
66
95
|
/**
|
|
67
96
|
* GLSL vec3 threedogRim(vec3 normal, vec3 viewDir, vec3 color, float strength, float power, float shadowSide, float nl): edge light to add
|
|
68
97
|
* (viewDir from the surface to the eye, e.g. normalView and positionViewDirection); shadowSide 1 = only on the side facing away from the sun.
|
|
98
|
+
* @experimental
|
|
69
99
|
*/
|
|
70
100
|
export function rim(normal: Node, viewDir: Node, color: Node, strength: Node | number, power: Node | number, shadowSide: Node | number, nl: Node): Node;
|
|
71
101
|
/**
|
|
@@ -74,6 +104,7 @@ export function rim(normal: Node, viewDir: Node, color: Node, strength: Node | n
|
|
|
74
104
|
* @example
|
|
75
105
|
* const mat = new MeshToonNodeMaterial({ color: 0xe08050, gradientMap: rampTexture([0x4a5a9a, 0xc0c8e0, 0xffffff]) });
|
|
76
106
|
* mat.setupLightingModel = celLighting;
|
|
107
|
+
* @experimental
|
|
77
108
|
*/
|
|
78
109
|
export function celLighting(): import('three/webgpu').LightingModel;
|
|
79
110
|
/**
|
|
@@ -81,14 +112,16 @@ export function celLighting(): import('three/webgpu').LightingModel;
|
|
|
81
112
|
* @example
|
|
82
113
|
* const h = waterWave(modelWorldMatrix.mul(vec4(positionGeometry, 1)).xyz, uniforms(engine).uTime).toVarying();
|
|
83
114
|
* mat.positionNode = positionLocal.add(vec3(0, h, 0));
|
|
115
|
+
* @experimental
|
|
84
116
|
*/
|
|
85
117
|
export function waterWave(p: Node, t: Node | number): Node;
|
|
86
118
|
/**
|
|
87
119
|
* The built-in water surface as TSL: returns a function with the GLSL signature threedogWaterSurface(base, wave, facing, worldPos, time) -> vec4 (rgb, opacity).
|
|
88
120
|
* Only the parts given exist (depth: shallow / deep by viewing angle or wave height; foam on crests); values are numbers / colors or nodes.
|
|
89
121
|
* wave is waterWave's height, facing = 1 looking straight down.
|
|
122
|
+
* @experimental
|
|
90
123
|
*/
|
|
91
124
|
export function waterSurface(spec?: { depth?: { shallow?: any, deep?: any, curve?: any, by?: 'view' | 'wave' }, foam?: { color?: any, start?: any, end?: any, opacity?: any }, waveMax?: number }):
|
|
92
125
|
(base: Node, wave: Node, facing: Node, worldPos: Node, time: Node) => Node;
|
|
93
|
-
/** The water's fresnel blend: color mixed toward `towards` (the engine uses the fog color) by pow(1 - |viewDir . normal|, 3) * strength, view space */
|
|
126
|
+
/** The water's fresnel blend: color mixed toward `towards` (the engine uses the fog color) by pow(1 - |viewDir . normal|, 3) * strength, view space @experimental */
|
|
94
127
|
export function waterFresnel(color: Node, normal: Node, viewDir: Node, strength: Node | number, towards: Node): Node;
|
package/types/world.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export interface TerrainEditOptions {
|
|
|
42
42
|
* World outline, terrain({ shape }): ground only where mask > 0, cut along straight lines through the cells where it crosses 0, with walls
|
|
43
43
|
* down the rim (side) and optionally a hanging underside (bottom). Off it engine.surface is -Infinity, engine.ground.has false, slope 0,
|
|
44
44
|
* groundType 'void'; nothing grows there; a fall below voidY emits terrain:void. Without shape the terrain is unchanged.
|
|
45
|
-
* Depth and mask functions are pure like height (they run in workers). See recipes/
|
|
45
|
+
* Depth and mask functions are pure like height (they run in workers). See recipes/28-terrain.md.
|
|
46
46
|
* @example terrain({ height: (x, z, n) => 6 * n.fbm(x * 0.02, z * 0.02), shape: { mask: (x, z) => 40 - Math.hypot(x, z),
|
|
47
47
|
* edge: { noise: 5, size: 14 }, side: { depth: 2, ground: 'cliff' }, bottom: { depth: (x, z, n, m) => 4 + m * 0.6, ground: 'rock' } } })
|
|
48
48
|
*/
|
|
@@ -111,7 +111,7 @@ export interface TerrainConfig {
|
|
|
111
111
|
/**
|
|
112
112
|
* How the ground gets its color: 'smooth' (default) blended per grid point | 'flat' one color and normal per triangle (low poly) |
|
|
113
113
|
* 'texture' per-chunk color map sampled per pixel, so color borders (a river bank) are not confined to triangle edges and the mesh can stay coarse.
|
|
114
|
-
* See recipes/
|
|
114
|
+
* See recipes/53-ground-up-close.md.
|
|
115
115
|
*/
|
|
116
116
|
shading: 'flat' | 'smooth' | 'texture';
|
|
117
117
|
/** Texture shading: color map pixels per chunk edge (default 128, 64 on low-tier devices; independent of `resolution`) */
|
|
@@ -221,7 +221,7 @@ export interface TerrainChunk {
|
|
|
221
221
|
/** One species' placement in one chunk: n plants, m = 16 floats per plant (chunk-local matrix), c = 3 colors per plant, ids = stable ids */
|
|
222
222
|
export interface VegetationPlants { n: number; m: Float32Array; c: Float32Array; ids?: Uint32Array; k?: Float32Array }
|
|
223
223
|
|
|
224
|
-
/** engine.terrainDraw: draws the terrain chunks (slot 'terrain-draw'; engine.use(mine, { replaces: 'terrain-draw' }) swaps it) */
|
|
224
|
+
/** engine.terrainDraw: draws the terrain chunks (slot 'terrain-draw'; engine.use(mine, { replaces: 'terrain-draw' }) swaps it) @experimental */
|
|
225
225
|
export interface TerrainDraw {
|
|
226
226
|
/** The ground material every chunk draws with; setting swaps it on every loaded chunk as given (same as engine.terrain.material). Nothing is regenerated, collision is untouched */
|
|
227
227
|
material: Material;
|
|
@@ -235,7 +235,7 @@ export interface TerrainDraw {
|
|
|
235
235
|
meshes: Map<TerrainChunk, { group: Object3D; mesh: Mesh; colorTex: any; colorMat: any }>;
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
/** engine.vegetationDraw: draws the plants (slot 'vegetation-draw'; engine.use(mine, { replaces: 'vegetation-draw' }) swaps it) */
|
|
238
|
+
/** engine.vegetationDraw: draws the plants (slot 'vegetation-draw'; engine.use(mine, { replaces: 'vegetation-draw' }) swaps it) @experimental */
|
|
239
239
|
export interface VegetationDraw {
|
|
240
240
|
/** The InstancedMesh drawing one species in one chunk, null when none */
|
|
241
241
|
mesh(c: TerrainChunk, name: string): InstancedMesh | null;
|
|
@@ -247,8 +247,8 @@ export interface VegetationDraw {
|
|
|
247
247
|
|
|
248
248
|
/** engine.terrain: the terrain data part (chunks, heights, edits, collision); engine.terrainDraw draws it */
|
|
249
249
|
export interface Terrain {
|
|
250
|
-
/** Pure-computation terrain (height, landform) */
|
|
251
|
-
|
|
250
|
+
/** Pure-computation terrain (height, landform), what createTerrain() returns */
|
|
251
|
+
generator: TerrainGen;
|
|
252
252
|
/**
|
|
253
253
|
* The plain three.js material every chunk draws with (null under a draw part that replaced 'terrain-draw'). The neutral one takes direct writes; setting one swaps it on every
|
|
254
254
|
* loaded chunk and draws it as given. Nothing is regenerated, collision is untouched. Chunks carry position, normal, color and uv (world xz / chunk size)
|
|
@@ -265,8 +265,8 @@ export interface Terrain {
|
|
|
265
265
|
* @example engine.terrain.recolor({ colors: { grass: 0x6a8a3a }, biomeColors: { meadow: ['grass'] } });
|
|
266
266
|
*/
|
|
267
267
|
recolor(o?: TerrainRecolor): void;
|
|
268
|
-
/** Chunk edge length (meters) */
|
|
269
|
-
readonly
|
|
268
|
+
/** Chunk edge length (meters), the same value as the chunkSize option and ground.chunkSize */
|
|
269
|
+
readonly chunkSize: number;
|
|
270
270
|
/**
|
|
271
271
|
* terrain({ shape }) only: below this height the player or a moving rigid body has fallen out of the world (one terrain:void per fall).
|
|
272
272
|
* shape.voidY, else 50 m under the lowest island chunk loaded so far; -Infinity without a shape
|
|
@@ -275,21 +275,21 @@ export interface Terrain {
|
|
|
275
275
|
readonly voidY: number;
|
|
276
276
|
/** Loaded chunks: 'cx,cz' → chunk */
|
|
277
277
|
chunks: Map<string, TerrainChunk>;
|
|
278
|
-
/** View distance (in chunks) */
|
|
278
|
+
/** View distance (in chunks); writing it takes effect like setViewChunks @experimental */
|
|
279
279
|
viewChunks: number;
|
|
280
|
-
/** Vegetation density multiplier */
|
|
280
|
+
/** Vegetation density multiplier; writing it takes effect like setDensity */
|
|
281
281
|
density: number;
|
|
282
282
|
/** Time budget (milliseconds) for uploading chunks per frame */
|
|
283
283
|
applyBudgetMs: number;
|
|
284
284
|
/** Statistics (for the debug panel); failed = chunks that failed every try (terrain:chunkFailed) */
|
|
285
285
|
stats: { builtThisFrame: number; applyMs: number; queued: number; failed: number; visible?: number; loaded?: number; instances?: number };
|
|
286
|
-
/** Change the view distance (in chunks); camera far plane and, with viewFog, uViewDistance adjust too */
|
|
286
|
+
/** Change the view distance (in chunks); camera far plane and, with viewFog, uViewDistance adjust too @experimental */
|
|
287
287
|
setViewChunks(n: number): void;
|
|
288
|
-
/** Change the vegetation density: plants are placed again on the loaded chunks; the ground and its collision stay */
|
|
288
|
+
/** Change the vegetation density: plants are placed again on the loaded chunks; the ground and its collision stay @experimental */
|
|
289
289
|
setDensity(d: number): void;
|
|
290
290
|
/**
|
|
291
291
|
* Draw these chunks: the hooks a draw part that replaces 'terrain-draw' uses. add(c): generated (c.data holds pos / nor / col / uv / tex arrays,
|
|
292
|
-
* c.cx / c.cz the chunk); change(c): an edit rewrote c.data (
|
|
292
|
+
* c.cx / c.cz the chunk); change(c): an edit rewrote c.data (the vertex count can differ on the rim of a shape with diagonal 'adaptive'); remove(c): released; show(c, visible): in view or not.
|
|
293
293
|
* Chunks already loaded are added at once. Returns { remove() } (ctx.track it).
|
|
294
294
|
* @example ctx.track(engine.terrain.view({ add(c) { draw(c) }, remove(c) { undraw(c) } }))
|
|
295
295
|
*/
|
|
@@ -309,8 +309,6 @@ export interface Terrain {
|
|
|
309
309
|
* @experimental
|
|
310
310
|
*/
|
|
311
311
|
edit(position: PositionLike, opts: TerrainEditOptions): { heights: number; cells: number };
|
|
312
|
-
/** Whether the chunks within rings rings (default 1) around position are all loaded */
|
|
313
|
-
isReadyAround(position: PositionLike, opts?: { rings?: number }): boolean;
|
|
314
312
|
}
|
|
315
313
|
|
|
316
314
|
// ======================================================================
|
|
@@ -469,13 +467,13 @@ export interface Vegetation {
|
|
|
469
467
|
define(name: string, opts: VegetationOptions): Species | Promise<Species>;
|
|
470
468
|
get(name: string): Species | undefined;
|
|
471
469
|
list(): Species[];
|
|
472
|
-
isRemoved(species: string, cx: number, cz: number, id: number): boolean;
|
|
470
|
+
/** @experimental */ isRemoved(species: string, cx: number, cz: number, id: number): boolean;
|
|
473
471
|
/**
|
|
474
|
-
* Remove one (chop a tree). regrowSeconds: grows back after this many
|
|
472
|
+
* Remove one (chop a tree). regrowSeconds: grows back after this many calendar seconds, 0 = permanent. The record is saved with the save (save key
|
|
475
473
|
* 'vegetation'). Returns the entry name
|
|
476
474
|
*/
|
|
477
475
|
removeInstance(species: string, cx: number, cz: number, id: number, opts?: { regrowSeconds?: number }): string;
|
|
478
|
-
/** Restore one */
|
|
476
|
+
/** Restore one @experimental */
|
|
479
477
|
restoreInstance(species: string, cx: number, cz: number, id: number): void;
|
|
480
478
|
/** The one nearest to position within radius meters (default 2) (species restricts to one kind), null if none */
|
|
481
479
|
instanceAt(position: PositionLike, opts?: { radius?: number; species?: string | null }): VegetationHit | null;
|
|
@@ -488,9 +486,9 @@ export interface Vegetation {
|
|
|
488
486
|
/** What engine.sky.environment reports */
|
|
489
487
|
export interface SkyEnvironmentInfo { source: string, intensity: number, rotation: number, interval: number, builds: number }
|
|
490
488
|
|
|
491
|
-
/** Parameters of sky({...}). The sky computes signals and draws the dome; lights and fog are the game's
|
|
489
|
+
/** Parameters of sky({...}). The sky computes signals and draws the dome; lights and fog are the game's. Picture values are start values here:
|
|
492
490
|
* after install the numbers are engine.uniforms (write .value), the rest engine.sky fields and calls (keyframes, clouds, layer, replace, backdrop, top, horizon, orbit, dim) */
|
|
493
|
-
export interface SkyOptions extends Pick<SkyPictureOptions, 'clouds' | 'backdrop' | 'keyframes' | 'sunSize' | 'sunGlow' | 'sunBrightness' | '
|
|
491
|
+
export interface SkyOptions extends Pick<SkyPictureOptions, 'clouds' | 'backdrop' | 'keyframes' | 'sunSize' | 'sunGlow' | 'sunBrightness' | 'moonColor' | 'moonBrightness' | 'starDensity' | 'dim'> {
|
|
494
492
|
/**
|
|
495
493
|
* The fixed time of day drawn while no calendar() is installed: 'HH:MM' or 0–1 (0.5 noon), default 0.33 (a sunset arena: sky({ time: '18:30' })).
|
|
496
494
|
* With calendar() the sky draws engine.calendar.timeOfDay and this option throws (start the day with calendar({ time }))
|
|
@@ -522,30 +520,22 @@ export interface SkyPictureOptions {
|
|
|
522
520
|
*/
|
|
523
521
|
keyframes?: SkyKeyframe[];
|
|
524
522
|
/**
|
|
525
|
-
* A flat background color in place of the dome (no gradient, horizon line, sun / moon disk, stars or clouds)
|
|
526
|
-
*
|
|
527
|
-
* fog.color of your own still wins). Leave out for the dome.
|
|
528
|
-
* @example backdrop:
|
|
523
|
+
* A flat background color in place of the dome (no gradient, horizon line, sun / moon disk, stars or clouds).
|
|
524
|
+
* Drawn as written (no tone mapping); a fog asked for in the default horizon color takes it (a
|
|
525
|
+
* fog.color of your own still wins). Leave out for the dome. recipes/08
|
|
526
|
+
* @example backdrop: 0xefebe4
|
|
529
527
|
*/
|
|
530
528
|
backdrop?: ColorLike;
|
|
531
529
|
/** Sharpness exponent of the sun disk, default 900 (about 2 deg); larger = smaller. Not a size in degrees: 10 is ~20 deg, under ~3 the "disk" washes most of the sky toward the sun color */
|
|
532
530
|
sunSize?: number;
|
|
533
531
|
/** Sun glow, default 0.18 */
|
|
534
532
|
sunGlow?: number;
|
|
535
|
-
/** Sun brightness, default 6 */
|
|
533
|
+
/** Sun brightness, default 6 @experimental */
|
|
536
534
|
sunBrightness?: number;
|
|
537
|
-
/**
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
moonBrightness?: number;
|
|
541
|
-
/** North-south tilt of the sun path */
|
|
542
|
-
orbitTilt?: number;
|
|
543
|
-
/** East-west swing of the sun path */
|
|
544
|
-
orbitSway?: number;
|
|
545
|
-
/** Share of the sky grid cells (0-1) that hold a star at night, default 0.0025 (0 = no stars). A probability, not a brightness: near 1 every cell is lit and the upper sky turns into a white sheet. The cell size is starScale */
|
|
535
|
+
/** @experimental */ moonColor?: ColorLike;
|
|
536
|
+
/** @experimental */ moonBrightness?: number;
|
|
537
|
+
/** Share of the sky grid cells (0-1) that hold a star at night, default 0.0025 (0 = no stars). A probability, not a brightness: near 1 every cell is lit and the upper sky turns into a white sheet. */
|
|
546
538
|
starDensity?: number;
|
|
547
|
-
/** Star grid resolution (cells per unit of view direction), default 260: larger means smaller and more numerous stars */
|
|
548
|
-
starScale?: number;
|
|
549
539
|
/**
|
|
550
540
|
* What the sky dims for every game unless the style says no (each default true; false turns that one off, the rest stay). The one place these
|
|
551
541
|
* picture decisions are switched:
|
|
@@ -555,36 +545,24 @@ export interface SkyPictureOptions {
|
|
|
555
545
|
* @example sky({ dim: { stars: false } }) // live: engine.sky.dim.tint = false
|
|
556
546
|
*/
|
|
557
547
|
dim?: { tint?: boolean; stars?: boolean };
|
|
558
|
-
/**
|
|
559
|
-
* Gradient curve from horizon to zenith, default 0.55 (color = mix(horizon, zenith, elevation^curve), mixed in linear light, then tone mapped
|
|
560
|
-
* and exposed like the scene). The keyframe zenith shows only high up: a level camera (55 deg fov) sees the lowest ~25 deg, where a warm
|
|
561
|
-
* horizon and a deep-blue zenith mix to a gray-lavender (desert R4: e8d4a8 / 1858c8 read as #9b99bd at the frame's top). Lower curve = more
|
|
562
|
-
* zenith color near the horizon; or bring the horizon color closer to the zenith hue. toneMapping 'aces' also turns a saturated blue toward
|
|
563
|
-
* violet ('agx' / 'neutral' keep the hue closer). Check with threedog shot
|
|
564
|
-
*/
|
|
565
|
-
gradientCurve?: number;
|
|
566
548
|
/** Clouds in the sky (cloud cover follows the weather); see SkyCloudOptions */
|
|
567
549
|
clouds?: SkyCloudOptions;
|
|
568
|
-
/** Panorama (equirectangular) replacing the gradient sky, asset name or path (at run time engine.sky.replace(name)) */
|
|
569
|
-
skybox?: string;
|
|
570
|
-
/** Extra dome layers drawn after the clouds and stars (rainbow, aurora), default none; see SkyLayerOptions */
|
|
571
|
-
layers?: SkyLayerOptions[];
|
|
572
550
|
}
|
|
573
551
|
|
|
574
552
|
/**
|
|
575
553
|
* One extra sky layer (modules/sky/domeLayers.js)
|
|
576
|
-
* @example
|
|
554
|
+
* @example engine.sky.layer('aurora', { blend: 'add', uniforms: { uAurora: [0.2, 1, 0.6] }, glsl: `vec4 threedogSkyLayer(vec3 d, float time, vec3 sunDir, float night){
|
|
577
555
|
* float band = smoothstep(0.25, 0.45, d.y) * (1.0 - smoothstep(0.55, 0.8, d.y)) * threedogNoise(vec2(d.x * 4.0 + time * 0.05, d.z * 2.0));
|
|
578
|
-
* return vec4(uAurora, band * night); }` }
|
|
556
|
+
* return vec4(uAurora, band * night); }` })
|
|
579
557
|
*/
|
|
580
558
|
export interface SkyLayerOptions {
|
|
581
|
-
/**
|
|
559
|
+
/** Not read: the layer's name is the first argument of engine.sky.layer(name, spec) */
|
|
582
560
|
name?: string;
|
|
583
561
|
/** Defines `vec4 threedogSkyLayer(vec3 dir, float time, vec3 sunDir, float night)` returning (rgb, amount 0..1); renamed per layer, so layers never clash. WebGLRenderer draws it */
|
|
584
562
|
glsl?: string;
|
|
585
563
|
/** WebGPURenderer form: (ctx) => vec4 node (rgb, amount); ctx = { dir, time, sunDir, night, color (sky so far), uniforms, fx: { noise, hash }, tsl } (recipe 52 'tsl forms') */
|
|
586
564
|
tsl?: (ctx: any) => any;
|
|
587
|
-
/** Custom uniforms (numbers, THREE.Color, [x, y(, z, w)], THREE.Texture), live in engine.sky.
|
|
565
|
+
/** Custom uniforms (numbers, THREE.Color, [x, y(, z, w)], THREE.Texture), live in engine.sky.uniforms on both renderers */
|
|
588
566
|
uniforms?: Record<string, any>;
|
|
589
567
|
/** Draw order among the layers, smaller first (default 0) */
|
|
590
568
|
order?: number;
|
|
@@ -676,7 +654,7 @@ export interface MaterialDetail {
|
|
|
676
654
|
export interface CalendarOptions {
|
|
677
655
|
/** Time of day at start: 'HH:MM' or fraction of a day 0–1 (0.5 noon), default 0.33 (afterwards read / write engine.calendar.timeOfDay) */
|
|
678
656
|
time?: string | number;
|
|
679
|
-
/**
|
|
657
|
+
/** Calendar seconds per day, default Infinity: the time of day never moves until the game sets a length (presets.calendar.cycle has 360) (one hour = dayLength / hoursPerDay calendar seconds; with clock.rate 1 calendar seconds are real seconds) */
|
|
680
658
|
dayLength?: number;
|
|
681
659
|
/** Hours per day of the displayed clock and of clock notation ('18:30'), default 24 */
|
|
682
660
|
hoursPerDay?: number;
|
|
@@ -780,7 +758,7 @@ export interface WeatherOptions {
|
|
|
780
758
|
/**
|
|
781
759
|
* Snow cover (weather({ snow: { cover } })): the season tint of foliage / ground (vegetation, terrain, materials with season) moves toward these colors
|
|
782
760
|
* as the weather's snow amount rises, `strength` of the way at full snow, and melts back as it falls. Leave it out and snow only draws particles.
|
|
783
|
-
* The same cover for anything else (ash, frost): engine.mod('ground.cover', { owner: 'ash', value: { ground: 0x555555, amount: 0.6 } }). recipes/
|
|
761
|
+
* The same cover for anything else (ash, frost): engine.mod('ground.cover', { owner: 'ash', value: { ground: 0x555555, amount: 0.6 } }). recipes/44
|
|
784
762
|
* @example cover: { foliage: 0xf2f4f6, ground: 0xeef0f2, strength: 0.8 }
|
|
785
763
|
*/
|
|
786
764
|
export interface SnowCover {
|
|
@@ -792,7 +770,7 @@ export interface SnowCover {
|
|
|
792
770
|
strength?: number;
|
|
793
771
|
}
|
|
794
772
|
|
|
795
|
-
/** Falling weather particles: weather({ rain, snow }) and engine.weather.
|
|
773
|
+
/** Falling weather particles: weather({ rain, snow }) and engine.weather.defineField(field, spec). See recipes/44-water-weather-hooks.md */
|
|
796
774
|
export interface WeatherParticles {
|
|
797
775
|
/** 'line' streaks slant with the wind; 'round' | 'soft' | 'square' sprites drift (sway) */
|
|
798
776
|
shape?: Loose<'line' | 'round' | 'soft' | 'square'>;
|
|
@@ -811,7 +789,7 @@ export interface WeatherParticles {
|
|
|
811
789
|
slant?: number;
|
|
812
790
|
/** Sprite drift (meters) */
|
|
813
791
|
sway?: number;
|
|
814
|
-
/** Particle count (default weather({ particles })
|
|
792
|
+
/** Particle count (default weather({ particles }), else 6000, 3000 on low-tier devices; a number the game gives stands) */
|
|
815
793
|
count?: number;
|
|
816
794
|
/** Weather amount 0..1 -> share of particles drawn (rain default a => min(1, a * 1.2), snow () => 1; opacity follows the amount too) */
|
|
817
795
|
density?: (amount: number) => number;
|
|
@@ -822,7 +800,7 @@ export interface WeatherParticles {
|
|
|
822
800
|
glsl?: { vertex?: string; fragment?: string };
|
|
823
801
|
/** Uniforms for your glsl: numbers, colors, [x, y(, z, w)] arrays, textures; live in engine.weather.particles[field].uniforms */
|
|
824
802
|
uniforms?: Record<string, any>;
|
|
825
|
-
/** A system of your own instead (engine.weather.
|
|
803
|
+
/** A system of your own instead (engine.weather.defineField only): the engine adds object, shows it while the amount is above 0.02, calls update */
|
|
826
804
|
create?: (engine: Engine, ctx: { area: number; count: number }) => {
|
|
827
805
|
object: Object3D; update?: (amount: number, ctx: { camera: any; time: number; wind: number }) => void };
|
|
828
806
|
}
|
|
@@ -996,7 +974,7 @@ export interface LightPoolOptions {
|
|
|
996
974
|
}
|
|
997
975
|
/** Options of lightPool.add(position, opts): one light source (a torch, lamp, campfire, muzzle flash...) */
|
|
998
976
|
export interface LightSourceOptions {
|
|
999
|
-
/** Name shown in
|
|
977
|
+
/** Name shown in describe().lightPool */
|
|
1000
978
|
name?: string;
|
|
1001
979
|
/** 'point' (default) or 'spot' (needs lightPool({ spot: n })) */
|
|
1002
980
|
type?: 'point' | 'spot';
|
|
@@ -1059,15 +1037,6 @@ export interface LightSource {
|
|
|
1059
1037
|
/** Unregister: its light fades out and moves on, the stand-in is put back (safe to call twice) */
|
|
1060
1038
|
remove(): void;
|
|
1061
1039
|
}
|
|
1062
|
-
/** lightPool.usage(): what the pool is doing now */
|
|
1063
|
-
export interface LightPoolUsage {
|
|
1064
|
-
/** Registered sources */
|
|
1065
|
-
sources: number;
|
|
1066
|
-
/** Real lights lighting a source now */
|
|
1067
|
-
lit: number;
|
|
1068
|
-
/** One per real light: its kind, whether it casts shadows, the source it holds (name or number, null = idle) and its fade 0-1 */
|
|
1069
|
-
slots: { type: 'point' | 'spot'; shadow: boolean; source: string | number | null; weight: number }[];
|
|
1070
|
-
}
|
|
1071
1040
|
/** engine.lightPool: register any number of light sources; a fixed set of real lights moves to the most relevant ones */
|
|
1072
1041
|
export interface LightPool {
|
|
1073
1042
|
/** The real three.js lights, created once at install and never added, removed or hidden (the pool sets their position, color, intensity) */
|
|
@@ -1081,8 +1050,6 @@ export interface LightPool {
|
|
|
1081
1050
|
* torch.set({ intensity: 0 }); // put out: its light goes to another torch
|
|
1082
1051
|
*/
|
|
1083
1052
|
add(position: PositionLike, opts?: LightSourceOptions): LightSource;
|
|
1084
|
-
/** What the pool is doing now (also in describe().lightPool) */
|
|
1085
|
-
usage(): LightPoolUsage;
|
|
1086
1053
|
}
|
|
1087
1054
|
|
|
1088
1055
|
// ======================================================================
|
|
@@ -1134,8 +1101,8 @@ export interface BudgetOver { category: string; value: number; limit: number; to
|
|
|
1134
1101
|
export interface BudgetTagStat { tag: string; drawCalls: number; triangles: number }
|
|
1135
1102
|
/** Budget report: ok means everything is within budget */
|
|
1136
1103
|
export interface BudgetReport { ok: boolean; over: BudgetOver[] }
|
|
1137
|
-
// Budget (engine.budget) is generated from the JSDoc in core/Budget.js (npm run map); only the types are re-exported here
|
|
1138
|
-
import type { Budget } from './generated/core/Budget';
|
|
1104
|
+
// Budget (engine.budget) is generated from the JSDoc in core/inspect/Budget.js (npm run map); only the types are re-exported here
|
|
1105
|
+
import type { Budget } from './generated/core/inspect/Budget';
|
|
1139
1106
|
export type { Budget };
|
|
1140
1107
|
|
|
1141
1108
|
export type TerrainModule = ModuleDef<Terrain>;
|
package/ui/Focus.js
CHANGED
|
@@ -21,6 +21,7 @@ const stacks = new WeakMap(); // engine -> UI focus stack
|
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* UI focus stack: windows, dialogue and cutscenes push in open order; the back key (Esc) goes to the top only; an empty stack hands it to the settings menu
|
|
24
|
+
* @experimental the stable route for a screen of your own is engine.input.push (recipes/07-flow-scenes-pause.md)
|
|
24
25
|
* @param {Engine} engine
|
|
25
26
|
* @returns {UIFocus}
|
|
26
27
|
*/
|
|
@@ -28,7 +29,8 @@ export function uiFocus(engine) {
|
|
|
28
29
|
let f = stacks.get(engine);
|
|
29
30
|
if (f) return f;
|
|
30
31
|
const entries = [], stick = { key: '', t: 0 };
|
|
31
|
-
let
|
|
32
|
+
let root = null;
|
|
33
|
+
const frame = () => engine.input.frameCount;
|
|
32
34
|
// One place for every window, menu and choice list: under a lock the cursor is gone and a click lands on the canvas. The engine's own release, so it is not read as Esc
|
|
33
35
|
const freeMouse = () => engine.page.releaseLock();
|
|
34
36
|
f = {
|
|
@@ -38,9 +40,9 @@ export function uiFocus(engine) {
|
|
|
38
40
|
/** Push: { cancel, nav }. Returns a handle { id, fresh, index, consumed, setNav(nav), remove() } */
|
|
39
41
|
push(id, { cancel = null, nav = null } = {}) {
|
|
40
42
|
const h = {
|
|
41
|
-
id, cancel, nav, index: null, at: frame, used: -1,
|
|
42
|
-
get fresh() { return h.at === frame; },
|
|
43
|
-
get consumed() { return h.used === frame; },
|
|
43
|
+
id, cancel, nav, index: null, at: frame(), used: -1,
|
|
44
|
+
get fresh() { return h.at === frame(); },
|
|
45
|
+
get consumed() { return h.used === frame(); },
|
|
44
46
|
setNav(n) { forgetNav(h); h.nav = n; h.index = null; if (n) freeMouse(); },
|
|
45
47
|
remove() { forgetNav(h); const i = entries.indexOf(h); if (i >= 0) entries.splice(i, 1); },
|
|
46
48
|
};
|
|
@@ -51,18 +53,17 @@ export function uiFocus(engine) {
|
|
|
51
53
|
/** Who gets the back key when the stack is empty (only one; a later registration replaces the earlier) */
|
|
52
54
|
setRoot(fn) { root = fn; return { remove: () => { if (root === fn) root = null; } }; },
|
|
53
55
|
};
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
+
// Each frame (the onFrame callback runs before module frame hooks): the back key dispatches once, and
|
|
57
|
+
// the cursor of the top entry moves / presses (before the dialogue's own confirm check, which reads h.consumed)
|
|
56
58
|
f.hook = engine.onFrame(dt => {
|
|
57
|
-
frame++;
|
|
58
59
|
const top = entries.at(-1);
|
|
59
|
-
if (top?.nav && stepCursor(engine, top, stick, dt)) top.used = frame;
|
|
60
|
+
if (top?.nav && stepCursor(engine, top, stick, dt)) top.used = frame();
|
|
60
61
|
if (!engine.input.pressedRaw('cancel')) return;
|
|
61
62
|
if (entries.at(-1)) entries.at(-1).cancel?.();
|
|
62
63
|
else root?.();
|
|
63
64
|
});
|
|
64
65
|
// Esc under pointer lock never reaches the page: the browser keeps the key and ends the lock, so the first Esc of a mouse-look game would pause nothing.
|
|
65
|
-
// Only the empty stack in running play. A game ending the lock itself (engine.page.releaseLock(), or document.exitPointerLock(): core/page.js marks both as byEngine)
|
|
66
|
+
// Only the empty stack in running play. A game ending the lock itself (engine.page.releaseLock(), or document.exitPointerLock(): core/engine/page.js marks both as byEngine)
|
|
66
67
|
// to show its own window or screen must not have it closed or covered.
|
|
67
68
|
f.unlock = engine.events.on('page:pointerlock', ({ locked, byEngine }) => {
|
|
68
69
|
if (!locked && !byEngine && !entries.length && !engine.page.away && engine.runState.state === 'running') root?.();
|
package/ui/Parts.js
CHANGED
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
// The same option holds the picture of every default part: createEngine({ ui: { theme: { bg, accent }, css, fonts, templates, toast: false } }) (ui/theme.js).
|
|
15
15
|
// Names and the data each part receives are listed in `engine.ui.describe()` and in recipes/26-ui-parts.md.
|
|
16
16
|
import { uiFocus } from './Focus.js';
|
|
17
|
-
import { codedError } from '../core/errorHints.js';
|
|
17
|
+
import { codedError } from '../core/base/errorHints.js';
|
|
18
|
+
import { fmt } from '../core/base/validate.js';
|
|
18
19
|
/** @import { Engine } from '../types/core' */
|
|
19
20
|
/** @import { UIPart, UIPartFactory, UIPartValue, UIPartDef } from '../types/core' */
|
|
20
21
|
|
|
@@ -27,7 +28,6 @@ const DEV = {
|
|
|
27
28
|
unknown: "engine.ui.set('{name}'): no UI part has that name. Known parts: {known}. (A module's parts exist only after engine.use(module).)",
|
|
28
29
|
notModal: "engine.ui.open('{name}'): only full-screen parts can be opened ({known}).",
|
|
29
30
|
};
|
|
30
|
-
const fmt = (s, p) => s.replace(/\{(\w+)\}/g, (_, k) => p[k]);
|
|
31
31
|
const kind = v => v === null ? 'null' : Array.isArray(v) ? 'array' : typeof v;
|
|
32
32
|
|
|
33
33
|
/** @internal Fill missing verbs with no-ops so callers never write ?. */
|
|
@@ -163,13 +163,14 @@ export class UIParts {
|
|
|
163
163
|
if (!p) return false;
|
|
164
164
|
if (this.opened.has(name)) return true;
|
|
165
165
|
const e = this.engine, m = d.modal;
|
|
166
|
+
const shown = { ...m.data?.(e, this._resolve(name).options), ...data }; // before the holds below: a title list that throws must not leave the game frozen behind nothing
|
|
166
167
|
// Each modal part owns its own freeze ('ui-<name>') and its own input context, so closing help releases only help's hold, never a player pause or another part's.
|
|
167
168
|
// m.freeze may be a function (inventory: pauseGame is switchable at runtime)
|
|
168
169
|
// a string names the freeze kind engine.runState reads ('title' = waiting for start), so core never matches part names
|
|
169
170
|
const fr = typeof m.freeze === 'function' ? m.freeze(e) : m.freeze;
|
|
170
171
|
const freeze = fr ? e.freeze('ui-' + name, { kind: typeof fr === 'string' ? fr : undefined }) : null;
|
|
171
172
|
this.opened.set(name, { freeze, focus: uiFocus(e).push('ui-' + name, { cancel: m.cancel ? () => m.cancel(e) : null, nav: () => p.el ?? null }), ctx: e.input.push('ui-' + name) }); // own opaque context: gameplay actions stop responding
|
|
172
|
-
p.show(
|
|
173
|
+
try { p.show(shown); } catch (err) { this.close(name); throw err; }
|
|
173
174
|
e.events.emit('ui:open', name);
|
|
174
175
|
return true;
|
|
175
176
|
}
|
package/ui/UI.js
CHANGED
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
//
|
|
6
6
|
// Every window and component uses classes (no inline styles), so option 2 always takes effect.
|
|
7
7
|
import * as THREE from 'three';
|
|
8
|
-
import { vec3 } from '../core/math.js';
|
|
8
|
+
import { vec3 } from '../core/base/math.js';
|
|
9
9
|
import { uiFocus } from './Focus.js';
|
|
10
10
|
import { injectUICSS } from './theme.js';
|
|
11
|
-
import { codedError } from '../core/errorHints.js';
|
|
12
|
-
import { uiAfter } from '../core/uiClock.js';
|
|
13
|
-
import { readParams, keysSchema } from '../core/params.js';
|
|
11
|
+
import { codedError } from '../core/base/errorHints.js';
|
|
12
|
+
import { uiAfter } from '../core/time/uiClock.js';
|
|
13
|
+
import { readParams, keysSchema } from '../core/base/params.js';
|
|
14
14
|
const FADE_SCREEN_KEYS = ['seconds'];
|
|
15
15
|
/** @import { Engine } from '../types/core' */
|
|
16
16
|
/** @import { PositionLike, Object3D } from '../types/common' */
|
|
@@ -19,7 +19,6 @@ export { uiFocus, injectUICSS };
|
|
|
19
19
|
|
|
20
20
|
/** @internal */
|
|
21
21
|
export function esc(s) { return String(s ?? '').replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c])); }
|
|
22
|
-
/** Icon: def.iconUrl is an image, def.icon is text/emoji */
|
|
23
22
|
/** @internal icon markup of an item / thing definition (image when it has iconUrl, else its icon text) */
|
|
24
23
|
export const iconHTML = def => def?.iconUrl ? `<img src="${esc(def.iconUrl)}" alt="">` : esc(def?.icon ?? '·');
|
|
25
24
|
|
|
@@ -50,7 +49,7 @@ export function toastPart(engine) {
|
|
|
50
49
|
show({ text, ms = 2600 }) {
|
|
51
50
|
if (!box) { box = document.createElement('div'); box.className = 'threedog-ui threedog-toasts'; engine.uiRoot.appendChild(box); }
|
|
52
51
|
const t = document.createElement('div'); t.className = 'threedog-toast'; t.textContent = text; box.appendChild(t);
|
|
53
|
-
// the page's own time (core/uiClock.js): wall clock in the game, so it goes away while gameplay is paused; the stepped time on a headless
|
|
52
|
+
// the page's own time (core/time/uiClock.js): wall clock in the game, so it goes away while gameplay is paused; the stepped time on a headless
|
|
54
53
|
// page. The 400 ms is the CSS fade; removal is on the same clock, so a stepped page never captures a half-faded message
|
|
55
54
|
uiAfter(engine, ms, () => { t.style.opacity = '0'; });
|
|
56
55
|
uiAfter(engine, ms + 400, () => t.remove());
|
|
@@ -106,6 +105,7 @@ export function makeWindow(engine, opts) {
|
|
|
106
105
|
* @param {{ open: boolean, toggle(on?: boolean): void }} win a makeWindow window or any handle with open / toggle
|
|
107
106
|
* @param {string} action
|
|
108
107
|
* @returns {void}
|
|
108
|
+
* @experimental
|
|
109
109
|
*/
|
|
110
110
|
export function toggleOnKey(engine, win, action) {
|
|
111
111
|
const inp = engine.input;
|
|
@@ -143,7 +143,7 @@ export function placeAt(el, x, y) {
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
const fades = new WeakMap(); // engine → { el, value, from, to, t, d, done }
|
|
146
|
-
// color --threedog-fade-bg. Follows engine frames (step() advances it too; stops while
|
|
146
|
+
// color --threedog-fade-bg. Follows engine frames (step() advances it too; stops while the loop is halted). A new fade interrupts the old (the old Promise resolves at once).
|
|
147
147
|
// Scene transitions use engine.flow.transition and cutscenes use the timeline's { fade: seconds, to } step; both go through here.
|
|
148
148
|
/**
|
|
149
149
|
* Fade the whole screen to `to` (0 clear ... 1 fully covered) over `seconds` (default 0.5); the Promise resolves when the fade ends.
|
package/ui/defaults.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
import { injectUICSS, toastPart, esc } from './UI.js';
|
|
4
4
|
import { loadingScreen } from './LoadingScreen.js';
|
|
5
5
|
import { touchPart } from './touchPart.js';
|
|
6
|
-
import { codedError } from '../core/errorHints.js';
|
|
6
|
+
import { codedError } from '../core/base/errorHints.js';
|
|
7
|
+
import { fmt } from '../core/base/validate.js';
|
|
7
8
|
/** @import { Engine, UIPart, UITitleItem } from '../types/core' */
|
|
8
9
|
|
|
9
10
|
const STRINGS = {
|
|
@@ -40,7 +41,7 @@ function titleItems(e, items) {
|
|
|
40
41
|
if (typeof it === 'string' && BUILTIN[it]) { const b = BUILTIN[it]; if (!b.when || b.when(e)) out.push({ id: it, label: e.t('title.' + it), run: () => b.run(e) }); }
|
|
41
42
|
else if (typeof it === 'string' && e.ui.titleItems.has(it)) out.push(own(e, { id: it, ...e.ui.titleItems.get(it) }));
|
|
42
43
|
else if (it && typeof it.run === 'function') out.push(own(e, it));
|
|
43
|
-
else throw codedError('ui-misuse', DEV.badItem
|
|
44
|
+
else throw codedError('ui-misuse', fmt(DEV.badItem, { added: [...e.ui.titleItems.keys()].join(', ') || 'none', got: String(JSON.stringify(it)) }));
|
|
44
45
|
}
|
|
45
46
|
return out;
|
|
46
47
|
}
|
package/ui/theme.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { codedError } from '../core/errorHints.js';
|
|
1
|
+
import { coded, codedError } from '../core/base/errorHints.js';
|
|
2
|
+
import { DEV, warnOnce } from '../core/base/validate.js';
|
|
3
|
+
import { isObject } from '../core/base/util.js';
|
|
2
4
|
// UI theme and default CSS in <head> (part of ui/UI.js): the --threedog-* variables from createEngine({ ui: { theme } }), the engine's base classes, module
|
|
3
5
|
// defaults, the game's css. The classes use only var(--threedog-*), never a color of their own.
|
|
4
6
|
/** @import { UIOptions } from '../types/core' */
|
|
@@ -121,9 +123,9 @@ export function applyUITheme(engine, ui = {}) {
|
|
|
121
123
|
// The picture keys sit beside the part names in createEngine({ ui }), so a wrong shape would otherwise do nothing or reach a part: refuse it with the right form.
|
|
122
124
|
/** @param {UIOptions} ui */
|
|
123
125
|
function checkUiOptions({ theme, css, fonts, templates }) {
|
|
124
|
-
const plain = v => v == null || (
|
|
126
|
+
const plain = v => v == null || isObject(v);
|
|
125
127
|
if (!plain(theme)) throw codedError('ui-misuse', `ui.theme is an object of CSS values, got ${JSON.stringify(theme)}. Example: ui: { theme: { bg: '#1c140e', accent: '#e8a13a' } }`);
|
|
126
|
-
if (theme?.promptHeight != null)
|
|
128
|
+
if (DEV && theme?.promptHeight != null) warnOnce(coded('ui-misuse', `ui.theme.promptHeight moves nothing: the interaction prompt's height is interactions({ promptHeight: ${theme.promptHeight} })`));
|
|
127
129
|
if (css != null && typeof css !== 'string') throw codedError('ui-misuse', `ui.css is CSS text placed after every default, got ${typeof css}`);
|
|
128
130
|
if (!plain(templates)) throw codedError('ui-misuse', 'ui.templates is { windowName: (data, { esc, t, icon }) => html }');
|
|
129
131
|
// a font file is an asset, so the game names it here: a path would load nothing
|