threedog 0.7.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +411 -1
- package/README.md +8 -11
- package/core/{Animator.js → assets/Animator.js} +30 -18
- package/core/{Assets.js → assets/Assets.js} +131 -56
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +302 -0
- package/core/{assetHot.js → assets/assetHot.js} +9 -7
- package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
- package/core/{assetReport.js → assets/assetReport.js} +7 -14
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +47 -25
- package/core/{audioRules.js → audio/audioRules.js} +8 -5
- package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
- package/core/{Events.js → base/Events.js} +3 -3
- package/core/{I18n.js → base/I18n.js} +15 -12
- package/core/{Random.js → base/Random.js} +7 -4
- package/core/{Vars.js → base/Vars.js} +14 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +151 -125
- package/core/{errorHints.js → base/errorHints.js} +17 -10
- package/core/{errors.js → base/errors.js} +12 -10
- package/core/{events.generated.js → base/events.generated.js} +11 -0
- package/core/base/follows.js +26 -0
- package/core/base/math.js +66 -0
- package/core/{params.js → base/params.js} +5 -6
- package/core/base/saveValues.js +81 -0
- package/core/base/sections.js +97 -0
- package/core/base/spelling.js +32 -0
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +34 -34
- package/core/{Engine.js → engine/Engine.js} +137 -91
- package/core/{Loading.js → engine/Loading.js} +34 -5
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +32 -15
- package/core/{lifecycle.js → engine/lifecycle.js} +41 -34
- package/core/{loop.js → engine/loop.js} +88 -49
- package/core/engine/moduleSlots.js +176 -0
- package/core/{moduleTypes.js → engine/moduleTypes.js} +26 -14
- package/core/engine/modules.js +503 -0
- package/core/{page.js → engine/page.js} +59 -29
- package/core/{plugins.js → engine/plugins.js} +21 -12
- package/core/{services.js → engine/services.js} +50 -40
- package/core/{startup.js → engine/startup.js} +66 -54
- package/core/{Input.js → input/Input.js} +67 -39
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/input/inputKeyboard.js +39 -0
- package/core/{inputPad.js → input/inputPad.js} +24 -3
- package/core/{inputPointer.js → input/inputPointer.js} +11 -3
- package/core/input/inputSeat.js +66 -0
- package/core/{inputTouch.js → input/inputTouch.js} +24 -7
- package/core/{Budget.js → inspect/Budget.js} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +43 -18
- package/core/{Describe.js → inspect/Describe.js} +34 -26
- package/core/{Inspect.js → inspect/Inspect.js} +39 -10
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
- package/core/{UrlState.js → inspect/UrlState.js} +60 -24
- package/core/{catalog.js → inspect/catalog.js} +15 -8
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +4 -4
- package/core/{describeRender.js → inspect/describeRender.js} +24 -22
- package/core/{describeText.js → inspect/describeText.js} +17 -8
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/inspect/metadata.generated.js +4140 -0
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +130 -47
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/inspect/toolDoor.js +21 -0
- package/core/inspect/valueHistory.js +35 -0
- package/core/{Ops.js → ops/Ops.js} +44 -14
- package/core/{control.js → ops/control.js} +57 -31
- package/core/ops/holds.js +140 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +18 -5
- package/core/{opsCheck.js → ops/opsCheck.js} +11 -10
- package/core/{opsFail.js → ops/opsFail.js} +5 -7
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +9 -6
- package/core/{owned.js → ops/owned.js} +33 -19
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -16
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +34 -15
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +53 -27
- package/core/{Saves.js → saves/Saves.js} +171 -54
- package/core/saves/saveApply.js +312 -0
- package/core/{saveFiles.js → saves/saveFiles.js} +45 -38
- package/core/{saveVersions.js → saves/saveVersions.js} +24 -23
- package/core/saves/session.js +231 -0
- package/core/saves/stateReplace.js +184 -0
- package/core/{Rays.js → scene/Rays.js} +44 -30
- package/core/{Views.js → scene/Views.js} +16 -8
- package/core/{adaptive.js → scene/adaptive.js} +19 -9
- package/core/{canvasBox.js → scene/canvasBox.js} +4 -3
- package/core/scene/compositeGround.js +72 -0
- package/core/scene/floor.js +17 -0
- package/core/{gameLights.js → scene/gameLights.js} +17 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +6 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/scene/ground.contract.js +14 -0
- package/core/scene/ground.js +139 -0
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/scene/pixel.js +154 -0
- package/core/scene/pixelRatio.js +167 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +5 -5
- package/core/{sceneMethods.js → scene/sceneMethods.js} +43 -15
- package/core/scene/stepPoses.js +60 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
- package/core/{thingOps.js → scene/thingOps.js} +25 -16
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +10 -0
- package/core/scene/view.js +161 -0
- package/core/{Batching.js → stream/Batching.js} +85 -28
- package/core/{Stream.js → stream/Stream.js} +80 -38
- package/core/{batchGroups.js → stream/batchGroups.js} +11 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- package/core/{scatter.js → stream/scatter.js} +7 -4
- package/core/{streamSources.js → stream/streamSources.js} +14 -8
- package/core/{Commits.js → threads/Commits.js} +17 -11
- package/core/{Jobs.js → threads/Jobs.js} +25 -13
- package/core/{Threads.js → threads/Threads.js} +21 -18
- package/core/{threadPure.js → threads/threadPure.js} +7 -5
- package/core/{threadServe.js → threads/threadServe.js} +3 -3
- package/core/{Clock.js → time/Clock.js} +20 -11
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +28 -21
- package/core/{time.js → time/time.js} +32 -20
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +92 -72
- package/docs/API.md +33 -28
- package/docs/CODEMAP.md +121 -200
- package/docs/COMMANDS.md +77 -70
- package/docs/CONVENTIONS.md +167 -24
- package/docs/MIGRATING-0.8.md +171 -0
- package/docs/MIGRATING-1.0.md +101 -0
- package/docs/THREE.md +140 -38
- package/docs/api/assets.md +12 -13
- package/docs/api/audio.md +6 -5
- package/docs/api/budget.md +4 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +32 -29
- package/docs/api/characters.md +35 -24
- package/docs/api/clock.md +1 -1
- package/docs/api/collider3d.md +9 -0
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +18 -17
- package/docs/api/dialogue.md +5 -4
- package/docs/api/engine.md +58 -54
- package/docs/api/events.md +17 -6
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +6 -7
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +9 -8
- package/docs/api/interactions.md +5 -5
- package/docs/api/inventory.md +10 -10
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +10 -9
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +14 -12
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +10 -7
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +3 -3
- package/docs/api/post.md +21 -5
- package/docs/api/quests.md +7 -5
- package/docs/api/rays.md +7 -7
- package/docs/api/rigid.md +29 -19
- package/docs/api/saves.md +13 -11
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +8 -7
- package/docs/api/stream.md +8 -9
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +6 -8
- package/docs/api/terrainDraw.md +2 -2
- package/docs/api/timeline.md +4 -4
- package/docs/api/tools.md +27 -22
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +2 -2
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +27 -12
- package/docs/api/weatherDraw.md +4 -4
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +28 -43
- package/docs/recipes/02-npc.md +21 -23
- package/docs/recipes/03-items-pickups.md +37 -53
- package/docs/recipes/04-quests.md +5 -4
- package/docs/recipes/05-props-bake.md +34 -44
- package/docs/recipes/06-clock-events.md +31 -22
- package/docs/recipes/07-flow-scenes-pause.md +30 -32
- package/docs/recipes/08-weather-sky.md +91 -37
- package/docs/recipes/09-materials-lights-models.md +25 -39
- package/docs/recipes/10-blender-level.md +22 -11
- package/docs/recipes/11-vehicles.md +44 -24
- package/docs/recipes/12-navmesh.md +60 -15
- package/docs/recipes/13-animation.md +70 -22
- package/docs/recipes/14-custom-module.md +33 -20
- package/docs/recipes/15-perf.md +51 -28
- package/docs/recipes/16-dev-bridge.md +39 -58
- package/docs/recipes/18-world.md +49 -28
- package/docs/recipes/19-shooting-picking.md +7 -4
- package/docs/recipes/20-content-actions-save.md +55 -40
- package/docs/recipes/21-camera.md +47 -25
- package/docs/recipes/22-shop-gold.md +21 -16
- package/docs/recipes/23-ops.md +28 -24
- package/docs/recipes/26-ui-parts.md +25 -14
- package/docs/recipes/27-net.md +3 -5
- package/docs/recipes/28-terrain.md +119 -23
- package/docs/recipes/29-grid.md +3 -3
- package/docs/recipes/30-templates.md +63 -30
- package/docs/recipes/31-audio.md +7 -7
- package/docs/recipes/32-action-game.md +21 -11
- package/docs/recipes/33-stream-sources.md +6 -3
- package/docs/recipes/34-environment-lighting.md +72 -25
- package/docs/recipes/35-picture-from-reference.md +20 -23
- package/docs/recipes/36-ground-plants.md +106 -0
- package/docs/recipes/40-scene.md +18 -21
- package/docs/recipes/43-shader-patches-surfaces.md +27 -48
- package/docs/recipes/44-water-weather-hooks.md +56 -50
- package/docs/recipes/45-cascaded-shadows.md +41 -20
- package/docs/recipes/46-blender-art-route.md +9 -10
- package/docs/recipes/49-game-module-contract.md +7 -6
- package/docs/recipes/50-own-renderer.md +3 -2
- package/docs/recipes/51-capability-catalog.md +14 -8
- package/docs/recipes/52-around-the-picture.md +56 -100
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +17 -20
- package/docs/recipes/56-webgpu-tsl.md +28 -15
- package/docs/recipes/57-control.md +39 -12
- package/docs/recipes/58-input.md +15 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +30 -25
- package/docs/recipes/62-picture-code.md +129 -39
- package/docs/recipes/63-third-person-start.md +19 -5
- package/docs/recipes/64-particles.md +54 -5
- package/docs/recipes/65-swarm.md +140 -0
- package/docs/recipes/66-common-tasks.md +313 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +5 -5
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +15 -14
- package/examples/{sheepisland → perf-island}/assets.js +1 -1
- package/examples/{sheepisland → perf-island}/main.js +8 -8
- package/examples/{sheepisland → perf-island}/models.js +1 -1
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/GAMEMAP.md +4 -1
- package/examples/rc2d/GAMEMAP.md +4 -3
- package/examples/rc2d/main.js +1 -3
- package/examples/rc2d/rc2d.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +6 -5
- package/examples/techniques/contact-shadows/contactShadows.js +1 -1
- package/examples/techniques/contact-shadows/main.js +1 -1
- package/examples/techniques/interior-light/main.js +1 -1
- package/examples/techniques/modular-building/README.md +7 -6
- package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/webgpu-tsl/GAMEMAP.md +2 -1
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +9 -7
- package/examples/world/main.js +3 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +16 -12
- package/index.js +53 -32
- package/llms.txt +11 -14
- package/modules/ambience/Ambience.js +16 -11
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +18 -16
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +5 -5
- package/modules/camera/FixedCamera.js +43 -30
- package/modules/camera/FollowCamera.js +24 -15
- package/modules/camera/RtsCamera.js +12 -11
- package/modules/camera/common.js +72 -37
- package/modules/camera/contract.js +1 -0
- package/modules/camera/pixelSnap.js +62 -0
- package/modules/characters/Character.js +166 -70
- package/modules/characters/NPC.js +84 -44
- package/modules/characters/assetModel.js +16 -12
- package/modules/characters/astar.js +48 -27
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/character.contract.js +21 -0
- package/modules/characters/contract.js +17 -3
- package/modules/characters/index.js +240 -226
- package/modules/characters/moveHelpers.js +88 -12
- package/modules/characters/mover.contract.js +14 -0
- package/modules/characters/movers/common.js +22 -18
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +18 -10
- package/modules/characters/movers/simple.js +26 -13
- package/modules/characters/movers/support.js +24 -13
- package/modules/characters/npcAvoid.js +19 -16
- package/modules/characters/npcSim.js +88 -32
- package/modules/characters/npcView.js +19 -11
- package/modules/characters/pathAsync.js +81 -29
- package/modules/characters/pathJob.js +38 -21
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +120 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +2 -2
- package/modules/characters/seat.js +56 -0
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/vehicle.contract.js +8 -5
- package/modules/characters/walkTo.js +40 -33
- package/modules/collision/Collision.js +69 -45
- package/modules/collision/contract.js +15 -0
- package/modules/collision/grid.js +6 -1
- package/modules/content/explain.js +2 -3
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +5 -3
- package/modules/content/index.js +132 -114
- package/modules/content/loader.js +117 -140
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +54 -17
- package/modules/content/packs.js +5 -4
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +36 -0
- package/modules/content/props.js +22 -17
- package/modules/content/rules.js +47 -61
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +80 -49
- package/modules/content/words.js +47 -0
- package/modules/debug/DebugPanel.js +14 -45
- package/modules/flow/contract.js +2 -1
- package/modules/flow/index.js +30 -16
- package/modules/gameplay/Container.js +17 -13
- package/modules/gameplay/Containers.js +23 -6
- package/modules/gameplay/Dialogue.js +93 -34
- package/modules/gameplay/Interactions.js +93 -51
- package/modules/gameplay/Inventory.js +64 -22
- package/modules/gameplay/Quests.js +146 -30
- package/modules/gameplay/boxOps.js +8 -1
- package/modules/gameplay/dialogueBubbles.js +16 -12
- package/modules/gameplay/inventoryOps.js +11 -8
- package/modules/gameplay/pickups.js +63 -37
- package/modules/gameplay/questLog.js +4 -2
- package/modules/gameplay/questSave.js +9 -4
- package/modules/gameplay/quests.contract.js +1 -1
- package/modules/grid/Grid.js +2 -2
- package/modules/grid/Layer.js +12 -8
- package/modules/grid/index.js +28 -23
- package/modules/grid/ops.js +43 -46
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +42 -57
- package/modules/hud/index.js +22 -14
- package/modules/hud/parts.js +8 -8
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +29 -31
- package/modules/level/index.js +113 -161
- package/modules/level/load.js +196 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +40 -23
- package/modules/lights/index.js +33 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +90 -0
- package/modules/music/Music.js +34 -28
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +16 -0
- package/modules/nav/index.js +180 -49
- package/modules/nav/navPath.js +45 -10
- package/modules/net/Client.js +7 -7
- package/modules/net/Host.js +7 -7
- package/modules/net/Net.js +1 -1
- package/modules/net/index.js +6 -5
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +95 -29
- package/modules/particles/effect.js +86 -32
- package/modules/particles/shaders.js +19 -1
- package/modules/photo/Photo.js +23 -23
- package/modules/rigid/RigidBodies.js +255 -89
- package/modules/rigid/Vehicles.js +17 -8
- package/modules/rigid/collider3d.contract.js +26 -0
- package/modules/rigid/ragdoll.js +298 -0
- package/modules/rigid/ragdollBones.js +209 -0
- package/modules/rigid/refresh.js +10 -0
- package/modules/rigid/sync.js +51 -20
- package/modules/settings/Settings.js +177 -61
- package/modules/settings/apply.js +20 -13
- package/modules/settings/sections.js +19 -14
- package/modules/settings/strings.js +2 -2
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +29 -22
- package/modules/sky/clouds.js +7 -7
- package/modules/sky/dome.js +33 -20
- package/modules/sky/domeLayers.js +9 -9
- package/modules/sky/environment.js +6 -6
- package/modules/sky/frame.js +19 -10
- package/modules/sky/season.js +7 -1
- package/modules/sky/shader.js +24 -25
- package/modules/sky/skyModule.js +17 -28
- package/modules/sky/tint.js +1 -1
- package/modules/swarm/Swarm.js +356 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +71 -59
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +14 -11
- package/modules/terrain/index.js +42 -42
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +45 -29
- package/modules/terrain/terrainGen.js +19 -12
- package/modules/terrain/terrainIsland.js +2 -2
- package/modules/terrain/terrainMesh.js +7 -6
- package/modules/terrain/terrainShape.js +8 -10
- package/modules/terrain/terrainShapeMain.js +3 -3
- package/modules/timeline/Timeline.js +83 -43
- package/modules/timeline/Tween.js +25 -19
- package/modules/timeline/shots.js +24 -17
- package/modules/triggers/index.js +95 -28
- package/modules/vegetation/Vegetation.js +34 -26
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +39 -18
- package/modules/vegetation/groundChunks.js +21 -38
- package/modules/vegetation/index.js +37 -12
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +20 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +52 -40
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +28 -23
- package/modules/world/World.js +28 -15
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +30 -17
- package/modules/world/persist.js +90 -27
- package/modules/world/pos.js +5 -5
- package/modules/world/records.js +37 -11
- package/modules/world/sim.js +78 -27
- package/modules/world/simFar.js +2 -2
- package/modules/world/state.js +43 -11
- package/modules/world/thingSource.js +20 -5
- package/modules/world/views.js +27 -14
- package/package.json +48 -7
- package/presets.js +1 -3
- package/render/PostFX.js +83 -53
- package/render/backend.js +31 -33
- package/render/cascades.js +17 -12
- package/render/cascades.tsl.js +5 -8
- package/render/daylight.js +20 -3
- package/render/detail.js +8 -7
- package/render/effects.js +28 -25
- package/render/fuse.js +3 -3
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +5 -10
- package/render/fx/library.tsl.js +11 -0
- package/render/fx/lighting.tsl.js +2 -1
- package/render/fx/nodeErrors.tsl.js +2 -2
- package/render/fx/objectOrigin.tsl.js +1 -2
- package/render/fx/particles.tsl.js +8 -6
- package/render/fx/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +30 -26
- package/render/fx/sky.tsl.js +15 -17
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +2 -2
- package/render/lighting.js +5 -3
- package/render/lightmap.js +41 -21
- package/render/lights.js +6 -6
- package/render/lit.js +24 -0
- package/render/materials.js +8 -7
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/occlusion.js +62 -15
- package/render/ownFrame.js +4 -4
- package/render/patches.js +15 -15
- package/render/postWebGL.js +15 -12
- package/render/probes.js +41 -19
- package/render/recordSweep.js +117 -0
- package/render/shaderErrors.js +10 -9
- package/render/shadowCache.tsl.js +107 -0
- package/render/shadowTypes.js +9 -0
- package/{core → render}/shadows.js +59 -13
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +336 -202
- package/types/gameplay.d.ts +254 -130
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
- package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
- package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
- package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +8 -16
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +28 -10
- package/types/generated/core/input/inputSeat.d.ts +26 -0
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +17 -3
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +6 -4
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +14 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +62 -18
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +3 -2
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +2 -2
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +22 -18
- package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
- package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
- package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
- package/types/generated/modules/calendar/Calendar.d.ts +10 -11
- package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
- package/types/generated/modules/grid/Grid.d.ts +1 -0
- package/types/generated/modules/grid/Layer.d.ts +1 -1
- package/types/generated/modules/grid/index.d.ts +3 -3
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +5 -4
- package/types/generated/modules/sky/Sky.d.ts +21 -10
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +7 -5
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +14 -16
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +11 -7
- package/types/generated/render/PostFX.d.ts +21 -23
- package/types/generated/render/materials.d.ts +1 -0
- package/types/generated/render/occlusion.d.ts +9 -0
- package/types/generated/render/patches.d.ts +1 -0
- package/types/generated/ui/Focus.d.ts +1 -0
- package/types/generated/ui/UI.d.ts +1 -0
- package/types/nav.d.ts +47 -15
- package/types/physics.d.ts +150 -73
- package/types/pixel.d.ts +75 -0
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +48 -75
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +13 -5
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +7 -5
- package/core/assetEntry.js +0 -109
- package/core/engineCamera.js +0 -32
- package/core/ground.js +0 -104
- package/core/holds.js +0 -134
- package/core/math.js +0 -48
- package/core/moduleSlots.js +0 -100
- package/core/modules.js +0 -314
- package/core/saveApply.js +0 -210
- package/core/saveValues.js +0 -46
- package/core/session.js +0 -174
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- package/core/view.js +0 -43
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -320
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/MIGRATING-0.6.md +0 -126
- package/docs/PERF.md +0 -245
- package/docs/recipes/36-sky-ground-plants.md +0 -158
- package/docs/recipes/37-terrain-hooks.md +0 -115
- package/docs/recipes/38-environment-hooks.md +0 -67
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/47-island-snow-backdrop.md +0 -43
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/plain-picture/FINDINGS.md +0 -53
- package/examples/sheepisland/.threedog/content-index.json +0 -1
- package/modules/camera/projection.js +0 -21
- /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
- /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
- /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
- /package/core/{actor.js → ops/actor.js} +0 -0
- /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
- /package/core/{saveIds.js → saves/saveIds.js} +0 -0
- /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
- /package/core/{cells.js → stream/cells.js} +0 -0
- /package/core/{streamCells.js → stream/streamCells.js} +0 -0
- /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
- /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// Built-in tabs of the settings menu: graphics, audio, keys, language.
|
|
1
|
+
// Built-in tabs of the settings menu: graphics, audio, keys, language, saves.
|
|
2
2
|
// Each tab is { title: engine => text, render: (tools, engine, settings) => HTML, bind?: (element, engine, settings) => void, when?: engine => show or not, order }
|
|
3
|
-
// Controls bind no events directly; they carry data-* attributes that
|
|
3
|
+
// Controls bind no events directly; they carry data-* attributes that view.js handles in one place (a game's whole-page template can use the same attributes):
|
|
4
4
|
// data-tab="graphics" switch tab
|
|
5
5
|
// data-set="shadows" data-value="true" click sets the setting shadows to true (value parsed as JSON, falls back to a string)
|
|
6
6
|
// data-range="vol.music" slider <input type="range">; applies live while dragging, saves on release
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// data-reset="controls" restore default keys
|
|
9
9
|
// data-locale="en" switch language
|
|
10
10
|
|
|
11
|
-
import { setFov } from '../../core/view.js';
|
|
11
|
+
import { setFov, lensFov } from '../../core/scene/view.js';
|
|
12
12
|
|
|
13
13
|
const pct = v => Math.round(v * 100) + '%';
|
|
14
14
|
/** Value shown beside a slider */
|
|
@@ -51,20 +51,25 @@ export const BUILTIN_SECTIONS = {
|
|
|
51
51
|
render(tools, e, s) {
|
|
52
52
|
const { esc, t } = tools, v = s.values;
|
|
53
53
|
const opts = ['low', 'medium', 'high', 'custom'].map(k => [k, t('settings.quality.' + k)]);
|
|
54
|
-
let h =
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (e.
|
|
61
|
-
if (
|
|
62
|
-
|
|
54
|
+
let h = '';
|
|
55
|
+
const add = (key, label, ctl) => { if (!s._omit.has(key)) h += row(label, ctl, esc); }; // a row the game left out: settings({ sections: [{ id: 'graphics', omit }] })
|
|
56
|
+
add('quality', t('settings.quality'), segmented('quality', v.quality, opts, tools, ['custom']));
|
|
57
|
+
add('pixelRatio', t('settings.pixelRatio'), range('pixelRatio', v.pixelRatio, 0.5, 2, 0.05, tools));
|
|
58
|
+
add('shadows', t('settings.shadows'), toggle('shadows', v.shadows, tools));
|
|
59
|
+
add('antialias', t('settings.antialias'), toggle('antialias', v.antialias, tools));
|
|
60
|
+
if (e.post.get('bloom')) add('bloom', t('settings.bloom'), toggle('bloom', v.bloom, tools));
|
|
61
|
+
if (e.post.get('ao')) add('ao', t('settings.ao'), toggle('ao', v.ao, tools));
|
|
62
|
+
add('adaptive', t('settings.adaptive'), toggle('adaptive', v.adaptive, tools));
|
|
63
|
+
// the ground's own rows: the slider reaches at least as far as the game's value and the share Low gave it
|
|
64
|
+
const view = s.custom.get('viewChunks');
|
|
65
|
+
if (view) add('viewChunks', t('settings.viewDistance'), range('viewChunks', v.viewChunks, Math.min(2, v.viewChunks), Math.max(8, view.def), 1, tools));
|
|
66
|
+
if (s.custom.has('density')) add('density', t('settings.density'), range('density', v.density, 0.25, 1.5, 0.25, tools));
|
|
67
|
+
if (v.antialias !== e.post.antialias) h += `<p class="threedog-set-note">${esc(t('settings.nextStart'))}</p>`; // MSAA is fixed with the canvas: say why the picture did not change
|
|
63
68
|
return h;
|
|
64
69
|
},
|
|
65
70
|
},
|
|
66
71
|
audio: {
|
|
67
|
-
order: 20, title: e => e.t('settings.audio'),
|
|
72
|
+
order: 20, title: e => e.t('settings.audio'),
|
|
68
73
|
render(tools, e, s) {
|
|
69
74
|
const { esc, t } = tools;
|
|
70
75
|
// every bus of engine.audio (master first); a game's own bus is labeled by its key settings.vol.<bus>, else by its name
|
|
@@ -144,7 +149,7 @@ export const OPTIONAL_SECTIONS = {
|
|
|
144
149
|
const e = s.engine, rig = () => e.cameraRig;
|
|
145
150
|
s.define('camera.sensitivity', rig()?.sensitivity ?? 1, v => { if (rig() && 'sensitivity' in rig()) rig().sensitivity = v; });
|
|
146
151
|
s.define('camera.invertY', rig()?.invertY ?? false, v => { if (rig() && 'invertY' in rig()) rig().invertY = v; });
|
|
147
|
-
s.define('camera.fov', e
|
|
152
|
+
s.define('camera.fov', lensFov(e) ?? 50, v => setFov(e, v)); // the player's slider: yields to a fov the game took (engine.autoView.manual('fov'))
|
|
148
153
|
// a new rig starts from its own defaults (and setCamera resets the fov): put the player's choices back on it
|
|
149
154
|
s._track(e.events.on('camera:change', () => { for (const k of ['camera.sensitivity', 'camera.invertY', 'camera.fov']) s.custom.get(k)?.apply(s.values[k], e); }));
|
|
150
155
|
},
|
|
@@ -6,7 +6,7 @@ export const STRINGS = {
|
|
|
6
6
|
'settings.title': '设置', 'settings.action': '菜单', 'title.settings': '设置', 'module.settings': '设置',
|
|
7
7
|
'settings.graphics': '画质', 'settings.audio': '声音', 'settings.controls': '按键', 'settings.language': '语言',
|
|
8
8
|
'settings.quality': '画质预设', 'settings.quality.low': '低', 'settings.quality.medium': '中', 'settings.quality.high': '高', 'settings.quality.custom': '自定义',
|
|
9
|
-
'settings.pixelRatio': '渲染精度', 'settings.shadows': '阴影', 'settings.antialias': '抗锯齿', 'settings.bloom': '泛光', 'settings.ao': '环境光遮蔽',
|
|
9
|
+
'settings.pixelRatio': '渲染精度', 'settings.shadows': '阴影', 'settings.antialias': '抗锯齿', 'settings.nextStart': '抗锯齿的改动下次启动时生效', 'settings.bloom': '泛光', 'settings.ao': '环境光遮蔽',
|
|
10
10
|
'settings.adaptive': '自动分辨率', 'settings.viewDistance': '视距', 'settings.density': '植被密度',
|
|
11
11
|
'settings.vol.master': '总音量', 'settings.vol.music': '音乐', 'settings.vol.sfx': '音效', 'settings.vol.ambience': '环境音', 'settings.vol.ui': '界面音',
|
|
12
12
|
'settings.pressKey': '请按一个键…', 'settings.unbound': '未绑定', 'settings.rebindHint': '点击按键后按下新键,Esc 取消。',
|
|
@@ -22,7 +22,7 @@ export const STRINGS = {
|
|
|
22
22
|
'settings.title': 'Settings', 'settings.action': 'Menu',
|
|
23
23
|
'settings.graphics': 'Graphics', 'settings.audio': 'Audio', 'settings.controls': 'Controls', 'settings.language': 'Language',
|
|
24
24
|
'settings.quality': 'Quality preset', 'settings.quality.low': 'Low', 'settings.quality.medium': 'Medium', 'settings.quality.high': 'High', 'settings.quality.custom': 'Custom',
|
|
25
|
-
'settings.pixelRatio': 'Render scale', 'settings.shadows': 'Shadows', 'settings.antialias': 'Anti-aliasing', 'settings.bloom': 'Bloom', 'settings.ao': 'Ambient occlusion',
|
|
25
|
+
'settings.pixelRatio': 'Render scale', 'settings.shadows': 'Shadows', 'settings.antialias': 'Anti-aliasing', 'settings.nextStart': 'The anti-aliasing change applies the next time the game starts', 'settings.bloom': 'Bloom', 'settings.ao': 'Ambient occlusion',
|
|
26
26
|
'settings.adaptive': 'Adaptive resolution', 'settings.viewDistance': 'View distance', 'settings.density': 'Vegetation density',
|
|
27
27
|
'settings.vol.master': 'Master volume', 'settings.vol.music': 'Music', 'settings.vol.sfx': 'Sound effects', 'settings.vol.ambience': 'Ambience', 'settings.vol.ui': 'Interface',
|
|
28
28
|
'settings.pressKey': 'Press a key…', 'settings.unbound': 'Unbound', 'settings.rebindHint': 'Click a key, then press the new one. Esc cancels.',
|
package/modules/settings/view.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// UI part of the settings menu (tabs, redraw, click/slider events); Settings inherits it.
|
|
2
2
|
import { formatValue, BUILTIN_SECTIONS, OPTIONAL_SECTIONS, settingsTools } from './sections.js';
|
|
3
3
|
import { esc } from '../../ui/UI.js';
|
|
4
|
-
import { codedError } from '../../core/errorHints.js';
|
|
5
|
-
import { reportError } from '../../core/errors.js';
|
|
4
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
5
|
+
import { reportError } from '../../core/base/errors.js';
|
|
6
6
|
|
|
7
7
|
const CSS_ESC = s => (globalThis.CSS?.escape ? globalThis.CSS.escape(s) : String(s).replace(/["\\]/g, '\\$&'));
|
|
8
8
|
|
|
@@ -55,7 +55,7 @@ export class SettingsView {
|
|
|
55
55
|
el.addEventListener('input', ev => {
|
|
56
56
|
const r = ev.target.closest?.('[data-range]'); if (!r) return;
|
|
57
57
|
const key = r.dataset.range, v = +r.value;
|
|
58
|
-
this.
|
|
58
|
+
this._values[key] = v;
|
|
59
59
|
if (key !== 'density' && key !== 'viewChunks') this._apply(key, v); // these two rebuild the world, so they apply on release
|
|
60
60
|
const lab = el.querySelector(`[data-val="${CSS_ESC(key)}"]`); if (lab) lab.textContent = formatValue(key, v);
|
|
61
61
|
});
|
package/modules/sky/Sky.js
CHANGED
|
@@ -12,32 +12,28 @@
|
|
|
12
12
|
// Clouds: sky({ clouds: { color, shade, coverage: 1, scale: 0.35, speed: [x, z], kind, ... } }) (coverage follows weather; see clouds.js); your own function: engine.sky.clouds(spec)
|
|
13
13
|
// three.js objects: dome (dome Mesh), sunDir (Vector3 toward the sun). Dome layers: domeLayers.js
|
|
14
14
|
// Skybox: engine.sky.replace('sky.jpg') (equirectangular panorama) replaces the gradient sky; brightness follows time
|
|
15
|
-
import { engineOwned } from '../../core/things.js';
|
|
15
|
+
import { engineOwned } from '../../core/scene/things.js';
|
|
16
16
|
import * as THREE from 'three';
|
|
17
|
-
import { readParams } from '../../core/params.js';
|
|
18
|
-
import { NEUTRAL_KEYFRAMES, checkKeyframes, makeSkyUniforms, makeDome
|
|
17
|
+
import { readParams } from '../../core/base/params.js';
|
|
18
|
+
import { NEUTRAL_KEYFRAMES, checkKeyframes, makeSkyUniforms, makeDome } from './shader.js';
|
|
19
19
|
import { defineSkyPoints } from './tint.js';
|
|
20
20
|
import { environmentMethods } from './environment.js';
|
|
21
|
-
import { codedError } from '../../core/errorHints.js';
|
|
22
21
|
import { updateSky, watchOwned, skyLight } from './frame.js';
|
|
23
22
|
import { prepareDome, domeEntries } from './dome.js';
|
|
24
|
-
import { parseClock } from '../../core/dayTime.js';
|
|
23
|
+
import { parseClock, sunHeightAt } from '../../core/time/dayTime.js';
|
|
25
24
|
import { onRendererSwap } from '../../render/backend.js';
|
|
26
25
|
// sky({ dim }) (SkyPictureOptions.dim in types/world.d.ts): each picture decision the sky makes for every game, on unless the game turns it off (engine.sky.dim is the live value)
|
|
27
26
|
const DIM_PARAMS = {
|
|
28
27
|
tint: { type: 'bool', default: true, desc: 'a sky.tint color (weather grey, a cave tint) dims with the sky\'s own light, so a grey rain tint stays dark at night' },
|
|
29
|
-
stars: { type: 'bool', default: true, desc: 'stars fade with the weather\'s cloud cover (
|
|
28
|
+
stars: { type: 'bool', default: true, desc: 'stars fade with the weather\'s cloud cover (uWeatherCloud), not only behind drawn clouds' },
|
|
30
29
|
};
|
|
31
30
|
/** @import { Object3D, Vector3 } from '../../types/common' */
|
|
32
|
-
/** @import { SkyOptions } from '../../types/world' */
|
|
33
|
-
/** @import { Handle } from '../../types/common' */
|
|
34
31
|
/** engine.sky */
|
|
35
32
|
export class Sky {
|
|
36
33
|
/** @internal */
|
|
37
34
|
constructor(engine, { time = 0.33, ...over } = {}) {
|
|
38
35
|
/** @internal */ this.engine = engine;
|
|
39
36
|
const st = over;
|
|
40
|
-
if (st.environment) throw codedError('sky-option', 'sky({ environment }) is gone: call engine.sky.environment({ into: engine.scene }) for the sky as a map; an asset map is plain three.js (recipes/34)');
|
|
41
37
|
/**
|
|
42
38
|
* The time of day drawn while no calendar is installed (0-1; sky({ time: '17:30' }) or applyState({ time })); with engine.calendar the sky
|
|
43
39
|
* draws the calendar's time and this is unused @type {number}
|
|
@@ -63,7 +59,11 @@ export class Sky {
|
|
|
63
59
|
const scene = engine.scene;
|
|
64
60
|
|
|
65
61
|
const domeParts = prepareDome(this, st); // backdrop, dome layers (dome.js)
|
|
66
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* The dome's { value } objects, live on both renderers: the built-in ones (the same objects as engine.uniforms where the names match) and the uniforms
|
|
64
|
+
* given to engine.sky.clouds() and engine.sky.layer(), which join here once the call has run @type {Record<string, { value: any }>}
|
|
65
|
+
*/
|
|
66
|
+
this.uniforms = { ...makeSkyUniforms(st, engine.uniforms), ...domeParts.uniforms };
|
|
67
67
|
/** Dome mesh @type {Object3D} */
|
|
68
68
|
this.dome = makeDome(this.uniforms, st, domeParts, engine);
|
|
69
69
|
scene.add(engineOwned('sky', this.dome));
|
|
@@ -78,16 +78,13 @@ export class Sky {
|
|
|
78
78
|
this._entries?.reapply();
|
|
79
79
|
this._envSwap();
|
|
80
80
|
});
|
|
81
|
-
// Skybox (panorama)
|
|
81
|
+
// Skybox (panorama) while engine.sky.replace gave one
|
|
82
82
|
/** @internal */ this.skybox = null;
|
|
83
|
-
if (st.skybox) loadSkybox(this, st.skybox);
|
|
84
83
|
|
|
85
|
-
/** Sun direction (unit vector toward the sun) @type {Vector3} */
|
|
86
|
-
this.sunDir = new THREE.Vector3();
|
|
87
84
|
/**
|
|
88
85
|
* Sun orbit: tilt = north-south tilt, sway = east-west swing, distance = light distance (meters) @type {{ tilt: number, sway: number, distance: number }}
|
|
89
86
|
*/
|
|
90
|
-
this.orbit = { tilt:
|
|
87
|
+
this.orbit = { tilt: 0.45, sway: 0.8, distance: 160 };
|
|
91
88
|
// the engine's own box on its placeholder sun, the sky's one job there: what is written on that light stays (render/lights.js holds the defaults).
|
|
92
89
|
// createEngine({ lights: false }): the sun is not in the scene, nothing to place
|
|
93
90
|
const box = engine.lights.sun.parent ? engine.shadows.sunBox({ follow: 'focus', snap: 0.5, ahead: 0 }, () => this.orbit.distance) : null;
|
|
@@ -106,6 +103,7 @@ export class Sky {
|
|
|
106
103
|
// brightest row of the sky's ambient light (ambient column x the hemi color's brightness, frame.js skyLight): the sky's light now / this is
|
|
107
104
|
// the 0-1 scale the sky.tint color (weather grey) follows
|
|
108
105
|
/** @internal */ this._lightPeak = Math.max(...this.kf.map(k => skyLight(k[1], k[2], k[4])));
|
|
106
|
+
/** @internal brightest row's ambient column: a skybox is at full brightness there (frame.js) */ this._ambientPeak = Math.max(...this.kf.map(k => k[4]));
|
|
109
107
|
}
|
|
110
108
|
|
|
111
109
|
/**
|
|
@@ -117,6 +115,14 @@ export class Sky {
|
|
|
117
115
|
*/
|
|
118
116
|
keyframes(rows) { checkKeyframes(rows); this._setKeyframes(rows); }
|
|
119
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Sun direction (unit vector toward the sun): the same vector as engine.uniforms.uSunDir. Computed each frame from the time and orbit until a game writes either,
|
|
120
|
+
* then the value is the game's (the sun at a compass direction of your choice); engine.autoView.manual('sunDir', false) gives it back.
|
|
121
|
+
* @type {Vector3}
|
|
122
|
+
*/
|
|
123
|
+
get sunDir() { return this.uniforms.uSunDir.value; }
|
|
124
|
+
set sunDir(v) { this.uniforms.uSunDir.value.copy(v); }
|
|
125
|
+
|
|
120
126
|
/**
|
|
121
127
|
* Your own cloud function on the dome: glsl defines `vec4 threedogClouds(vec3 dir, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cover)`,
|
|
122
128
|
* tsl is its WebGPURenderer form (ctx) => vec4 node; each renderer needs its own form (modules/sky/clouds.js). null gives the built-in kind back.
|
|
@@ -138,12 +144,13 @@ export class Sky {
|
|
|
138
144
|
layer(name, spec) { this._entries.layer(name, spec); }
|
|
139
145
|
|
|
140
146
|
/**
|
|
141
|
-
* Replace or hide the dome: a skybox asset name (equirectangular panorama), a THREE.Texture / CubeTexture, or your own THREE.Object3D sky; null gives the dome back
|
|
147
|
+
* Replace or hide the dome: a skybox asset name (equirectangular panorama), a THREE.Texture / CubeTexture, or your own THREE.Object3D sky; null gives the dome back,
|
|
148
|
+
* false draws no sky (the scene shows its base background, the signals keep running).
|
|
142
149
|
* The engine never writes your object: it hides the dome, adds your object to the scene only when it has no parent, puts a plain texture's panorama
|
|
143
150
|
* mapping on a clone, and keeps feeding engine.uniforms (uSunDir, uWind ...).
|
|
144
151
|
* @example engine.sky.replace(new SkyMesh());
|
|
145
152
|
* @example engine.sky.replace(null);
|
|
146
|
-
* @param {string | import('three').Texture | Object3D | null} sky
|
|
153
|
+
* @param {string | import('three').Texture | Object3D | null | false} sky
|
|
147
154
|
* @returns {void}
|
|
148
155
|
*/
|
|
149
156
|
replace(sky) { this._entries.replace(sky); }
|
|
@@ -155,10 +162,10 @@ export class Sky {
|
|
|
155
162
|
get backdrop() { return this._backdrop?.color ?? null; }
|
|
156
163
|
set backdrop(v) { this._entries.backdrop(v); }
|
|
157
164
|
|
|
158
|
-
/** Time of day being drawn, 0-1: engine.calendar.timeOfDay, or fixedTime without a calendar. Read-only: the time itself is the calendar's */
|
|
165
|
+
/** Time of day being drawn, 0-1: engine.calendar.timeOfDay, or fixedTime without a calendar. Read-only: the time itself is the calendar's @experimental */
|
|
159
166
|
get drawnTime() { return this.engine.calendar?.timeOfDay ?? this.fixedTime; }
|
|
160
|
-
/** Sun elevation -1 (midnight) ... 0 (horizon) ... 1 (noon) of the drawn sun (the calendar's daylight is the gameplay value) */
|
|
161
|
-
get sunHeight() { return
|
|
167
|
+
/** Sun elevation -1 (midnight) ... 0 (horizon) ... 1 (noon) of the drawn sun (the calendar's daylight is the gameplay value) @experimental */
|
|
168
|
+
get sunHeight() { return sunHeightAt(this.drawnTime); }
|
|
162
169
|
/** Whether the drawn sun is above the horizon (picture functions: ({ sky }) => sky.isDay ? ...; gameplay reads engine.calendar.isDay) */
|
|
163
170
|
get isDay() { return this.sunHeight > 0; }
|
|
164
171
|
/** Daylight of the drawn sun 0-1 (0 at night, 1 at noon) */
|
|
@@ -173,7 +180,7 @@ export class Sky {
|
|
|
173
180
|
|
|
174
181
|
/**
|
|
175
182
|
* Render the sky into an environment map. Only after this call is anything built: a PMREM target, rebuilt when the sky changed and interval seconds passed
|
|
176
|
-
* (default 1, 4
|
|
183
|
+
* (default 1, 4 on a low-tier device). With into, that object's .environment gets the map at each rebuild (a map you wrote there yourself stays); without it nothing
|
|
177
184
|
* is written anywhere and you read handle.texture. handle.remove() takes the map off and frees it. One at a time. Intensity and rotation are three.js: scene.environmentIntensity.
|
|
178
185
|
* @example const env = engine.sky.environment({ into: engine.scene });
|
|
179
186
|
* @example env.remove();
|
|
@@ -182,5 +189,5 @@ export class Sky {
|
|
|
182
189
|
*/
|
|
183
190
|
environment(options) { return environmentMethods._envStart.call(this, options); }
|
|
184
191
|
}
|
|
185
|
-
// Mixed in from
|
|
192
|
+
// Mixed in from environment.js; methods the class already defines are kept
|
|
186
193
|
for (const [k, f] of Object.entries(environmentMethods)) if (!Object.hasOwn(Sky.prototype, k)) Sky.prototype[k] = f;
|
package/modules/sky/clouds.js
CHANGED
|
@@ -7,15 +7,15 @@
|
|
|
7
7
|
// time seconds (engine.uniforms.uTime); sunDir unit vector towards the sun (moon is opposite); night 0 day .. 1 night
|
|
8
8
|
// lit / shade cloud colors (clouds.color / clouds.shade); cover = weather cloud amount * clouds.coverage, 0..1+
|
|
9
9
|
// returns rgb = final cloud color, a = opacity 0..1 (the dome does mix(sky, rgb, a)); apply your own horizon fade
|
|
10
|
-
// In scope for your code: threedogHash(vec2), threedogNoise(vec2), the built-in cloud uniforms (
|
|
11
|
-
// uCloudHorizon, uCloudFade, uCloudSoft, uCloudOpacity, uCloudMul, uCloudWeights, uCloudRelief) and the patch's own uniforms.
|
|
10
|
+
// In scope for your code: threedogHash(vec2), threedogNoise(vec2), the built-in cloud uniforms (uSkyCloudScale, uSkyCloudSpeed,
|
|
11
|
+
// uCloudHorizon, uCloudFade, uCloudSoft, uCloudOpacity, uCloudMul, uCloudWeights, uCloudRelief) and the patch's own uniforms (later writes: engine.sky.uniforms.uK.value).
|
|
12
12
|
// WebGPURenderer draws the hook's tsl form instead ({ glsl, tsl, uniforms }; render/fx/sky.tsl.js): tsl: (ctx) => vec4 node, ctx = { dir, time,
|
|
13
13
|
// sunDir, night, lit, shade, cover (the same arguments as nodes), clouds (the built-in kind's vec4, the value so far), uniforms (the dome's
|
|
14
14
|
// uniforms as nodes, the patch's own included), fx: { noise, hash }, tsl (three/tsl) }. Each renderer needs its own form; a missing one throws by name.
|
|
15
15
|
import * as THREE from 'three';
|
|
16
|
-
import { closest } from '../../core/validate.js';
|
|
16
|
+
import { closest, oneForm } from '../../core/base/validate.js';
|
|
17
17
|
import { declareUniforms } from '../../render/uniformDecl.js';
|
|
18
|
-
import { codedError } from '../../core/errorHints.js';
|
|
18
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
19
19
|
import { SKY as K, glslFloat as f } from '../../render/fxNumbers.js';
|
|
20
20
|
|
|
21
21
|
const KINDS = ['plane', 'cumulus'];
|
|
@@ -28,7 +28,7 @@ const DEFAULTS = {
|
|
|
28
28
|
|
|
29
29
|
// Original picture: one plane projected onto the sky (cells shrink towards the horizon), 3 fixed noise layers.
|
|
30
30
|
const PLANE = `vec4 threedogClouds(vec3 d, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cov){
|
|
31
|
-
vec2 cp = d.xz / (d.y + uCloudHorizon) *
|
|
31
|
+
vec2 cp = d.xz / (d.y + uCloudHorizon) * uSkyCloudScale + uSkyCloudSpeed * time;
|
|
32
32
|
float cn = threedogNoise(cp) * uCloudWeights.x + threedogNoise(cp * uCloudMul.x + 7.0) * uCloudWeights.y + threedogNoise(cp * uCloudMul.y) * uCloudWeights.z;
|
|
33
33
|
float cloud = smoothstep(1.0 - cov, 1.0 - cov + uCloudSoft, cn) * smoothstep(uCloudFade.x, uCloudFade.y, d.y);
|
|
34
34
|
vec3 cc = mix(shade, lit, smoothstep(${f(K.planeTone[0])}, ${f(K.planeTone[1])}, cn)) * (${f(K.nightDim)} + ${f(1 - K.nightDim)} * (1.0 - night));
|
|
@@ -45,7 +45,7 @@ const CUMULUS = `float threedogCumulusDensity(vec2 p){
|
|
|
45
45
|
return s / ${f(K.norm)};
|
|
46
46
|
}
|
|
47
47
|
vec4 threedogClouds(vec3 d, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cov){
|
|
48
|
-
vec2 cp = d.xz / (d.y + uCloudHorizon) *
|
|
48
|
+
vec2 cp = d.xz / (d.y + uCloudHorizon) * uSkyCloudScale + uSkyCloudSpeed * time;
|
|
49
49
|
vec2 toSun = normalize(sunDir.xz + vec2(0.0001, 0.0)) * ${f(K.toSun)};
|
|
50
50
|
float n0 = threedogCumulusDensity(cp), n1 = threedogCumulusDensity(cp + toSun);
|
|
51
51
|
float t = 1.0 - cov * ${f(K.cover)};
|
|
@@ -70,7 +70,7 @@ export function resolveClouds(c, hook, gpu = false) {
|
|
|
70
70
|
let glsl = kind === 'cumulus' ? CUMULUS : PLANE;
|
|
71
71
|
if (h?.tsl != null && typeof h.tsl !== 'function') throw codedError('sky-option', "engine.sky.clouds(): tsl must be (ctx) => vec4 node (WebGPURenderer); see modules/sky/clouds.js");
|
|
72
72
|
// gpu: the node dome draws h.tsl (render/fx/sky.tsl.js checks it); the GLSL, when given too, is still checked here
|
|
73
|
-
if (h && h.glsl == null && !gpu) throw
|
|
73
|
+
if (h && h.glsl == null && !gpu) throw oneForm('sky-option', 'engine.sky.clouds()', false);
|
|
74
74
|
if (h?.glsl != null) {
|
|
75
75
|
if (typeof h.glsl !== 'string' || !/vec4\s+threedogClouds\s*\(/.test(h.glsl)) throw codedError('sky-option', "engine.sky.clouds(): glsl must define `vec4 threedogClouds(vec3 dir, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cover)` returning (rgb color, alpha); see modules/sky/clouds.js");
|
|
76
76
|
glsl = h.glsl;
|
package/modules/sky/dome.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
// The dome's game entries (helper of Sky.js): the backdrop, the cloud function, the dome layers, and handing the dome over to the game's own sky.
|
|
2
2
|
// A hook change rebuilds the dome shader text and recompiles that one material (a hitch, so do it at a scene change, not every frame).
|
|
3
3
|
// Each renderer draws its own form of a hook: glsl on WebGLRenderer, tsl ((ctx) => vec4 node, render/fx/sky.tsl.js) on WebGPURenderer; a missing one throws by name.
|
|
4
|
-
import { engineOwned } from '../../core/things.js';
|
|
4
|
+
import { engineOwned } from '../../core/scene/things.js';
|
|
5
5
|
import * as THREE from 'three';
|
|
6
6
|
import { resolveClouds } from './clouds.js';
|
|
7
7
|
import { resolveDomeLayers } from './domeLayers.js';
|
|
8
8
|
import { domeFragment, loadSkybox, skyNodes } from './shader.js';
|
|
9
9
|
import { DOME_FOG } from './fog.js';
|
|
10
|
-
import { codedError } from '../../core/errorHints.js';
|
|
10
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
11
11
|
import { isWebGPU } from '../../render/backend.js';
|
|
12
12
|
|
|
13
13
|
const isColorLike = v => typeof v === 'number' || typeof v === 'string' || !!v?.isColor;
|
|
14
14
|
|
|
15
|
-
/** The fog band's uniforms and
|
|
15
|
+
/** The fog band's uniforms and GLSL for a new Sky: the extra dome parts ({ uniforms, decl, body }); it starts with no layers, engine.sky.layer adds them */
|
|
16
16
|
export function prepareDome(sky, st) {
|
|
17
17
|
sky._backdrop = resolveBackdrop(st);
|
|
18
|
-
const f = DOME_FOG
|
|
18
|
+
const f = DOME_FOG;
|
|
19
19
|
// the fog object belongs to the game and may be replaced: read its color at draw time (fog.js fogBand turns the band on)
|
|
20
|
-
const uniforms = {
|
|
21
|
-
return { uniforms, decl:
|
|
20
|
+
const uniforms = { uFogBand: { value: 0 }, uFogColor: { get value() { return sky.engine.scene.fog?.color ?? sky.uniforms.uHorizon.value; } } };
|
|
21
|
+
return { uniforms, decl: f.decl, body: f.body, layers: [] };
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
// backdrop: one flat color instead of the dome: no gradient, horizon, sun / moon disk, stars or clouds. The color goes straight to scene.background
|
|
25
25
|
// (no tone mapping), so what is written is what shows, and uSkyHorizon reports it so a game's fog can fade far things into it.
|
|
26
|
-
|
|
26
|
+
function resolveBackdrop(st) {
|
|
27
27
|
const v = st.backdrop;
|
|
28
28
|
if (v == null) return null;
|
|
29
29
|
if (!isColorLike(v)) throw codedError('sky-option', `sky backdrop must be a color (0xefebe4, '#efebe4'); got ${typeof v === 'function' ? 'a function' : JSON.stringify(v)}. A color that changes: engine.sky.backdrop.set(...) each frame`);
|
|
@@ -37,7 +37,9 @@ export function resolveBackdrop(st) {
|
|
|
37
37
|
export function domeEntries(sky, st) {
|
|
38
38
|
const e = sky.engine, scene = e.scene, U = sky.uniforms;
|
|
39
39
|
let cloudsHook = null, added = null, addedHere = false;
|
|
40
|
-
const layers = new Map(
|
|
40
|
+
const layers = new Map();
|
|
41
|
+
// a skybox dims with the hour through scene.backgroundIntensity: it comes off with the skybox, or whatever shows next stays dimmed
|
|
42
|
+
const undim = () => { if (sky.skybox && scene.background === sky.skybox) scene.backgroundIntensity = 1; };
|
|
41
43
|
|
|
42
44
|
// The dome shader from a clouds function and layers; throws (changing nothing) when a hook is not valid for its contract
|
|
43
45
|
const rebuild = (hook, map) => {
|
|
@@ -50,10 +52,12 @@ export function domeEntries(sky, st) {
|
|
|
50
52
|
const text = domeFragment(cl, { decl: [f.decl, l.decl].filter(Boolean).join('\n'), body: f.body + l.body });
|
|
51
53
|
return { text, uniforms: { ...cl.uniforms, ...l.uniforms } };
|
|
52
54
|
};
|
|
53
|
-
|
|
55
|
+
// given: the uniforms of the hook being set. Its start values replace the old ones under those names (in place: a game's handle stays live);
|
|
56
|
+
// every other hook's uniforms keep what was written since
|
|
57
|
+
const apply = (r, given) => {
|
|
54
58
|
// node dome: a new color node over the uniforms with the hook's own added (setHooks throws first on a bad hook, the dome unchanged)
|
|
55
59
|
if (r.nodes) skyNodes(e).setHooks(sky.dome.material, { ...r.uniforms, ...U }, r.nodes.kind, e, r.nodes);
|
|
56
|
-
for (const [k, u] of Object.entries(r.uniforms)) if (!(k in U)) U[k] = u;
|
|
60
|
+
for (const [k, u] of Object.entries(r.uniforms)) { if (!(k in U)) U[k] = u; else if (given && k in given) U[k].value = u.value; }
|
|
57
61
|
if (r.nodes) return;
|
|
58
62
|
if (sky.dome.material.fragmentShader === r.text) return;
|
|
59
63
|
sky.dome.material.fragmentShader = r.text; sky.dome.material.needsUpdate = true;
|
|
@@ -62,30 +66,32 @@ export function domeEntries(sky, st) {
|
|
|
62
66
|
return {
|
|
63
67
|
/** the renderer swap (Sky.js) builds a fresh dome; the hooks set since then go back on it */
|
|
64
68
|
reapply() { apply(rebuild(cloudsHook, layers)); },
|
|
65
|
-
clouds(spec) { apply(rebuild(spec, layers)); cloudsHook = spec ?? null; },
|
|
69
|
+
clouds(spec) { apply(rebuild(spec, layers), spec?.uniforms); cloudsHook = spec ?? null; },
|
|
66
70
|
layer(name, spec) {
|
|
67
|
-
if (typeof name !== 'string' ||
|
|
71
|
+
if (typeof name !== 'string' || !name) throw codedError('sky-option', `engine.sky.layer(name, spec): name is a non-empty string such as 'aurora'; got ${JSON.stringify(name)}`);
|
|
68
72
|
const next = new Map(layers);
|
|
69
73
|
if (spec == null) next.delete(name); else next.set(name, spec);
|
|
70
|
-
apply(rebuild(cloudsHook, next)); // throws before anything changes when the layer's GLSL is not valid
|
|
74
|
+
apply(rebuild(cloudsHook, next), spec?.uniforms); // throws before anything changes when the layer's GLSL is not valid
|
|
71
75
|
layers.clear(); for (const [k, v] of next) layers.set(k, v);
|
|
72
76
|
},
|
|
73
77
|
backdrop(v) {
|
|
74
|
-
if (v == null) { sky._backdrop = null; sky.dome.visible = !sky.skybox && !added; scene.background = sky.skybox ?? null; sky._oBg.mark(); return; }
|
|
78
|
+
if (v == null) { sky._backdrop = null; sky.dome.visible = !sky.skybox && !added && !sky._noSky; scene.background = sky.skybox ?? (sky._noSky ? e.baseBackground : null); sky._oBg.mark(); return; }
|
|
75
79
|
if (sky._backdrop && isColorLike(v)) { sky._backdrop.color.set(v); return; }
|
|
76
|
-
sky._backdrop = resolveBackdrop({ backdrop: v
|
|
80
|
+
sky._backdrop = resolveBackdrop({ backdrop: v }); // the sky writes scene.background and hides the dome each frame (frame.js)
|
|
77
81
|
},
|
|
78
82
|
// The game's own sky (three/addons Sky, a ShaderMaterial dome, a skybox texture) is never written: the engine only hides its dome, adds the
|
|
79
83
|
// object to the scene when it has no parent yet (and takes it out again on hand-back only then), and keeps feeding time / weather / season
|
|
80
|
-
// through engine.uniforms (uSunDir, uDaylight, uTimeOfDay, uWind,
|
|
84
|
+
// through engine.uniforms (uSunDir, uDaylight, uTimeOfDay, uWind, uWeatherCloud ...) and the day / season / weather events. A plain Texture gets its
|
|
81
85
|
// panorama mapping on a clone, so the game's texture object stays as it was.
|
|
82
86
|
replace(impl) {
|
|
83
|
-
if (impl
|
|
84
|
-
if (impl != null && typeof impl !== 'string' && !impl.isTexture && !impl.isObject3D) throw codedError('sky-option', 'engine.sky.replace(sky): sky is a skybox asset name, a THREE.Texture or a THREE.Object3D; null gives the dome back');
|
|
87
|
+
if (impl !== false && impl != null && typeof impl !== 'string' && !impl.isTexture && !impl.isObject3D) throw codedError('sky-option', 'engine.sky.replace(sky): sky is a skybox asset name, a THREE.Texture or a THREE.Object3D; null gives the dome back, false draws no sky');
|
|
85
88
|
if (added) { if (addedHere) scene.remove(added); added = null; addedHere = false; }
|
|
86
|
-
|
|
89
|
+
undim();
|
|
90
|
+
sky._ownSky = null; sky._noSky = impl === false; sky._panorama = null;
|
|
91
|
+
// false: no drawn sky. The signals keep running and the scene shows its base background (a game's palette color lives there)
|
|
92
|
+
if (impl === false) { sky.skybox = null; sky._backdrop = null; sky.dome.visible = false; scene.background = e.baseBackground; sky._oBg.manual(false); sky._oBg.mark(); return; }
|
|
87
93
|
if (impl == null) { sky.skybox = null; scene.background = sky._backdrop?.color ?? null; sky.dome.visible = !sky._backdrop; sky._oBg.manual(false); sky._oBg.mark(); return; }
|
|
88
|
-
sky.dome.visible = false;
|
|
94
|
+
sky.dome.visible = false; sky._backdrop = null; // a backdrop left on would be written over this sky every frame
|
|
89
95
|
if (typeof impl === 'string') loadSkybox(sky, impl);
|
|
90
96
|
else if (impl.isTexture) {
|
|
91
97
|
const tex = impl.isCubeTexture || impl.mapping !== THREE.UVMapping ? impl : Object.assign(impl.clone(), { mapping: THREE.EquirectangularReflectionMapping });
|
|
@@ -96,5 +102,12 @@ export function domeEntries(sky, st) {
|
|
|
96
102
|
}
|
|
97
103
|
sky._oBg.mark();
|
|
98
104
|
},
|
|
105
|
+
/** the module goes: the game's own sky added here and a background the sky wrote go with it; a background the game wrote stays */
|
|
106
|
+
dispose() {
|
|
107
|
+
sky._panorama = null;
|
|
108
|
+
if (added && addedHere) scene.remove(added);
|
|
109
|
+
undim();
|
|
110
|
+
if (scene.background && (scene.background === sky.skybox || scene.background === sky._backdrop?.color)) scene.background = e.baseBackground;
|
|
111
|
+
},
|
|
99
112
|
};
|
|
100
113
|
}
|
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
// Extra sky layers drawn on the dome after the clouds and stars (rainbow, aurora, a painted band): engine.sky.layer(name, spec).
|
|
2
2
|
// Default none, and then the dome shader text is exactly the plain one.
|
|
3
|
-
//
|
|
3
|
+
// spec: { glsl, uniforms?, order?, blend? }
|
|
4
4
|
// glsl defines `vec4 threedogSkyLayer(vec3 dir, float time, vec3 sunDir, float night)`: dir = unit view direction (whole sphere,
|
|
5
5
|
// dir.y < 0 below the horizon), time = engine.uniforms.uTime seconds, sunDir toward the sun, night 0 day .. 1 night;
|
|
6
6
|
// returns (rgb, amount). Each layer's function is renamed (threedogSkyLayer0, 1...), so layers never clash.
|
|
7
|
-
// uniforms
|
|
7
|
+
// uniforms as in engine.sky.clouds({ uniforms }) (render/uniformDecl.js): { uK: 0.4, uTint: new THREE.Color(...), uMap: texture } -> engine.sky.uniforms.uK.value, live on both renderers
|
|
8
8
|
// order draw order among layers (smaller first, default 0, ties keep list order)
|
|
9
9
|
// blend 'mix' (default: col = mix(col, rgb, amount)) | 'add' (col += rgb * amount: glows such as an aurora)
|
|
10
10
|
// tsl the WebGPURenderer form (render/fx/sky.tsl.js): (ctx) => vec4 node (rgb, amount), ctx = { dir, time, sunDir, night, color (the sky
|
|
11
11
|
// so far, vec3), uniforms (the dome's uniforms as nodes, the layer's own included), fx: { noise, hash }, tsl (three/tsl) }. Each
|
|
12
12
|
// renderer needs its own form; a layer without it throws by name there.
|
|
13
|
-
// In scope: threedogHash(vec2), threedogNoise(vec2) and the dome's uniforms (uTop, uHorizon, uSunColor,
|
|
14
|
-
import { readParams, keysSchema
|
|
13
|
+
// In scope: threedogHash(vec2), threedogNoise(vec2) and the dome's uniforms (uTop, uHorizon, uSunColor, uWeatherCloud...).
|
|
14
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
15
|
+
import { isOptions } from '../../core/base/util.js';
|
|
16
|
+
import { oneForm } from '../../core/base/validate.js';
|
|
15
17
|
import { declareUniforms } from '../../render/uniformDecl.js';
|
|
16
|
-
import { codedError } from '../../core/errorHints.js';
|
|
18
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
17
19
|
|
|
18
20
|
const KEYS = ['glsl', 'tsl', 'uniforms', 'order', 'blend', 'name']; // name: the layer's name for engine.sky.layer(name, ...)
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
|
-
* Check the layer list and return { uniforms, decl, body } for the GLSL dome (empty strings without layers) and `layers` ({ tsl, blend, where }
|
|
23
|
+
* Check the layer list (engine.sky.layer's entries) and return { uniforms, decl, body } for the GLSL dome (empty strings without layers) and `layers` ({ tsl, blend, where }
|
|
22
24
|
* in draw order) for the node dome.
|
|
23
25
|
* @param {any[]} list @param {{ gpu?: boolean, names?: string[] }} [o] gpu: the dome is a node material (tsl drawn, glsl optional);
|
|
24
26
|
* names: the layer names per entry, so an error says engine.sky.layer('<name>') instead of the index
|
|
25
27
|
*/
|
|
26
28
|
export function resolveDomeLayers(list, { gpu = false, names } = {}) {
|
|
27
|
-
if (list == null) return { uniforms: {}, decl: '', body: '', layers: [] };
|
|
28
|
-
if (!Array.isArray(list)) throw codedError('sky-option', 'dome layers must be an array of { glsl, uniforms?, order?, blend? }; see modules/sky/domeLayers.js');
|
|
29
29
|
const uniforms = {}, decl = [], body = [], layers = [];
|
|
30
30
|
list.map((l, i) => ({ l, i })).sort((a, b) => (a.l?.order ?? 0) - (b.l?.order ?? 0) || a.i - b.i).forEach(({ l, i }, n) => {
|
|
31
31
|
const where = names?.[i] != null ? `engine.sky.layer('${names[i]}')` : `dome layer ${i}`;
|
|
32
32
|
if (isOptions(l)) readParams(where, keysSchema(KEYS), l);
|
|
33
33
|
if (l?.tsl != null && typeof l.tsl !== 'function') throw codedError('sky-option', `${where}.tsl must be (ctx) => vec4 node (WebGPURenderer); see modules/sky/domeLayers.js`);
|
|
34
|
-
if (l?.glsl == null && l?.tsl != null && !gpu) throw
|
|
34
|
+
if (l?.glsl == null && l?.tsl != null && !gpu) throw oneForm('sky-option', where, false);
|
|
35
35
|
// gpu: the glsl may be left out (render/fx/sky.tsl.js names a layer that has no tsl); when given it is checked all the same
|
|
36
36
|
if ((l?.glsl != null || !gpu) && (typeof l?.glsl !== 'string' || !/vec4\s+threedogSkyLayer\s*\(/.test(l.glsl)))
|
|
37
37
|
throw codedError('sky-option', `${where}.glsl must be GLSL that defines \`vec4 threedogSkyLayer(vec3 dir, float time, vec3 sunDir, float night)\` returning (rgb, amount 0..1)`);
|
|
@@ -10,27 +10,27 @@
|
|
|
10
10
|
// - Adding or removing scene.environment changes the program key of every Lambert material: one recompile at the switch, none after.
|
|
11
11
|
// - The hemisphere light adds on top of it.
|
|
12
12
|
import * as THREE from 'three';
|
|
13
|
-
import { codedError } from '../../core/errorHints.js';
|
|
13
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
14
14
|
import { isWebGPU, webgpuPart } from '../../render/backend.js';
|
|
15
15
|
|
|
16
16
|
const DEFAULT_INTERVAL = 1; // seconds between rebuilds (only when the sky actually changed)
|
|
17
|
-
const LOW_TIER_SLOWER = 4; // a low-tier device rebuilds this many times less often: the cube cannot be made smaller (256 px is PMREMGenerator's floor)
|
|
17
|
+
const LOW_TIER_SLOWER = 4; // by default a low-tier device rebuilds this many times less often (an interval the game gives stands): the cube cannot be made smaller (256 px is PMREMGenerator's floor)
|
|
18
18
|
|
|
19
19
|
// Numbers that decide how the procedural sky looks right now: when they stay put the environment is not rebuilt
|
|
20
20
|
function skyKey(u) {
|
|
21
21
|
const f = x => Math.round(x * 400);
|
|
22
|
-
return [...u.uTop.value.toArray(), ...u.uHorizon.value.toArray(), ...u.uSunDir.value.toArray(), ...u.uSunColor.value.toArray(), u.uNight.value, u.
|
|
22
|
+
return [...u.uTop.value.toArray(), ...u.uHorizon.value.toArray(), ...u.uSunDir.value.toArray(), ...u.uSunColor.value.toArray(), u.uNight.value, u.uWeatherCloud.value].map(f).join(',');
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export const environmentMethods = {
|
|
26
26
|
// engine.sky.environment(): the first build waits for the first frame's colors, later calls build at once
|
|
27
|
-
_envStart({ into = null, interval = DEFAULT_INTERVAL, ...rest } = {}) {
|
|
27
|
+
_envStart({ into = null, interval = this.engine.tier === 'low' ? DEFAULT_INTERVAL * LOW_TIER_SLOWER : DEFAULT_INTERVAL, ...rest } = {}) {
|
|
28
28
|
const bad = Object.keys(rest)[0];
|
|
29
29
|
if (bad) throw codedError('sky-option', `engine.sky.environment({ ${bad} }): the options are into and interval. Intensity and rotation are plain three.js: scene.environmentIntensity, scene.environmentRotation`);
|
|
30
30
|
if (into !== null && typeof into !== 'object') throw codedError('sky-option', 'engine.sky.environment({ into }): into is the object whose .environment is written, usually engine.scene');
|
|
31
31
|
if (typeof interval !== 'number' || !(interval >= 0)) throw codedError('sky-option', `engine.sky.environment({ interval }): interval is seconds, 0 or more; got ${JSON.stringify(interval)}`);
|
|
32
|
-
|
|
33
|
-
const env = this._env = { into, interval
|
|
32
|
+
this._envOff(); // a second call replaces the first (a new interval, hot reload, another scene); the old handle's remove() then does nothing
|
|
33
|
+
const env = this._env = { into, interval, key: null, since: 0, builds: 0, target: null, deferred: !this._envFramed };
|
|
34
34
|
if (!env.deferred) this._envBuild();
|
|
35
35
|
// a lost context takes the map's pixels with it, and the key cannot see that: with the sky standing still (a fixed hour) the map would stay black
|
|
36
36
|
env.restored = this.engine.events.on('page:contextrestored', () => { env.key = null; env.deferred = true; });
|
package/modules/sky/frame.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
// Sky per-frame work (helper of Sky.js): signals (uSunDir, uSunColor, uSkyTop, uSkyHorizon, season, cover) and the dome. Lights, fog,
|
|
2
2
|
// exposure and the environment are the game's (its picture/ folder reads the signals): nothing here writes them, because a value with two writers
|
|
3
|
-
// is what made a game's picture depend on code it never saw (plan 2026-11-04 rule 1). The shadow box around the focus is engine.shadows.box (
|
|
4
|
-
import { defineOwned } from '../../core/owned.js';
|
|
3
|
+
// is what made a game's picture depend on code it never saw (plan 2026-11-04 rule 1). The shadow box around the focus is engine.shadows.box (render/shadows.js).
|
|
4
|
+
import { defineOwned } from '../../core/ops/owned.js';
|
|
5
5
|
import { applySeason } from './season.js';
|
|
6
6
|
import { applyCover, skyTint } from './tint.js';
|
|
7
7
|
import { fogBand } from './fog.js';
|
|
8
|
+
import { signalWatch } from '../../render/daylight.js';
|
|
9
|
+
import { sunAngle } from '../../core/time/dayTime.js';
|
|
10
|
+
import { LUMA } from '../../render/fxNumbers.js';
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
13
|
* Brightness of the sky's ambient light for one sky color pair: ambient intensity x the luminance of the hemi color (top / horizon halfway,
|
|
@@ -12,27 +15,32 @@ import { fogBand } from './fog.js';
|
|
|
12
15
|
* @param {import('three').Color} top @param {import('three').Color} horizon @param {number} ambient
|
|
13
16
|
*/
|
|
14
17
|
export const skyLight = (top, horizon, ambient) => ambient * (lum(top) + lum(horizon)) / 2;
|
|
15
|
-
const lum = c => 0
|
|
18
|
+
const lum = c => LUMA[0] * c.r + LUMA[1] * c.g + LUMA[2] * c.b;
|
|
16
19
|
|
|
17
|
-
// The copyable takeover calls each owned property's warning quotes (core/owned.js): the engine yields to a direct write, these say it explicitly
|
|
20
|
+
// The copyable takeover calls each owned property's warning quotes (core/ops/owned.js): the engine yields to a direct write, these say it explicitly
|
|
18
21
|
const L = {
|
|
19
22
|
background: { manual: 'engine.sky.dome.visible = false', back: 'engine.sky.replace(null)' },
|
|
23
|
+
sunDir: { manual: "engine.autoView.manual('sunDir')", back: "engine.autoView.manual('sunDir', false)" },
|
|
20
24
|
};
|
|
21
25
|
|
|
22
26
|
/**
|
|
23
|
-
* Register what the sky still moves on its own: the background (backdrop / skybox). It yields to a direct write. (The shadow box is engine.shadows.box,
|
|
27
|
+
* Register what the sky still moves on its own: the background (backdrop / skybox). It yields to a direct write. (The shadow box is engine.shadows.box, render/shadows.js)
|
|
24
28
|
*/
|
|
25
29
|
export function watchOwned(sky) {
|
|
26
30
|
const e = sky.engine, scene = e.scene;
|
|
31
|
+
sky._signals = signalWatch(e, { uSkyTop: 'engine.sky.top = color', uSkyHorizon: 'engine.sky.horizon = color' });
|
|
27
32
|
const own = (id, part, key, read, levels, objects) => defineOwned(e, { id, part, key, read, levels, objects });
|
|
28
33
|
const list = [];
|
|
29
34
|
// background: the sky writes it with a backdrop / skybox; with the dome it draws over whatever scene.background holds, so a game that sets one
|
|
30
35
|
// takes it, and the dome hides (onChange) so the game's background shows; handing it back shows the dome again
|
|
31
36
|
list.push(sky._oBg = own('background', 'sky', 'background', () => [scene.background, scene.backgroundIntensity], L.background, [scene]));
|
|
32
|
-
sky._oBg._onChange = o => { if (!sky._backdrop && !sky.skybox && !sky._ownSky) sky.dome.visible = o.on; }; // a replaced sky keeps the dome hidden
|
|
37
|
+
sky._oBg._onChange = o => { if (!sky._backdrop && !sky.skybox && !sky._ownSky && !sky._noSky) sky.dome.visible = o.on; }; // a replaced sky keeps the dome hidden
|
|
33
38
|
// the reference is the scene as the engine made it, not what is there now: picture code runs before start() (and may run before sky()), and a write
|
|
34
39
|
// with no reference to differ from would leave the dome drawn over the game's background for good
|
|
35
40
|
sky._oBg.mark([e.baseBackground, 1]);
|
|
41
|
+
// the sun: part 'view', so engine.autoView.manual('sunDir') is the one takeover entry. The shadow and the game's lights follow this value, so a sun at a chosen
|
|
42
|
+
// direction has to survive the frame. sunDir and uSunDir are one vector (Sky.js), so a write to either name is seen here
|
|
43
|
+
list.push(sky._oSun = defineOwned(e, { id: 'sky.sunDir', part: 'view', key: 'sunDir', read: () => sky.sunDir.toArray(), levels: L.sunDir, objects: [sky] }));
|
|
36
44
|
return list;
|
|
37
45
|
}
|
|
38
46
|
|
|
@@ -66,16 +74,17 @@ export function updateSky(sky) {
|
|
|
66
74
|
const bd = sky._backdrop; // engine.sky.backdrop (dome.js): a flat background in place of the dome
|
|
67
75
|
if (bd && sky._oBg.on) { sky.dome.visible = false; scene.background = bd.color; }
|
|
68
76
|
// the drawn sky colors for game shaders (render/effects.js uSkyTop / uSkyHorizon): the horizon a game's fog can copy
|
|
77
|
+
sky._signals.check();
|
|
69
78
|
sky.engine.uniforms.uSkyTop.value.copy(u.uTop.value); sky.engine.uniforms.uSkyHorizon.value.copy(bd ? bd.color : u.uHorizon.value);
|
|
79
|
+
sky._signals.mark();
|
|
70
80
|
u.uFogBand.value = fogBand(scene.fog, u.uHorizon.value); // compared to the dome's horizon (not the backdrop): the band is drawn on the dome
|
|
71
81
|
u.uSunColor.value.copy(a[3]).lerp(b[3], f); // the keyframes' sun color: the dome's sun disk, and a signal for the game's own sun (shader.js shares the object)
|
|
72
82
|
|
|
73
|
-
const ang = (t
|
|
74
|
-
sky.sunDir.set(Math.cos(ang) * sky.orbit.sway, elev, sky.orbit.tilt).normalize();
|
|
75
|
-
u.uSunDir.value.copy(sky.sunDir);
|
|
83
|
+
const ang = sunAngle(t), elev = Math.sin(ang);
|
|
84
|
+
if (sky._oSun.on) sky.sunDir.set(Math.cos(ang) * sky.orbit.sway, elev, sky.orbit.tilt).normalize();
|
|
76
85
|
// uDaylight / uTimeOfDay are not written here: render/daylight.js writes them from the 'daylight' / 'timeOfDay' measures (one writer each)
|
|
77
86
|
u.uNight.value = Math.min(1, Math.max(0, -elev * 4));
|
|
78
87
|
// a skybox is the dome's stand-in, so it dims with the keyframes' ambient column like the dome dims with its colors
|
|
79
|
-
if (sky.skybox && sky._oBg.on) sky.engine.scene.backgroundIntensity = Math.max(0.05, hemiI / 1
|
|
88
|
+
if (sky.skybox && sky._oBg.on) sky.engine.scene.backgroundIntensity = Math.max(0.05, sky._ambientPeak > 0 ? hemiI / sky._ambientPeak : 1);
|
|
80
89
|
for (const o of sky._owned) o.mark();
|
|
81
90
|
}
|
package/modules/sky/season.js
CHANGED
|
@@ -6,7 +6,13 @@ import * as THREE from 'three';
|
|
|
6
6
|
const c1 = new THREE.Color(), c2 = new THREE.Color();
|
|
7
7
|
export function applySeason(sky, uniforms) {
|
|
8
8
|
// no seasons in this game's calendar (or no calendar: sky alone is a fixed time): the season colors never apply, the tint stays neutral
|
|
9
|
-
const S = sky.seasonTints, cal = sky.engine.calendar;
|
|
9
|
+
const S = sky.seasonTints, cal = sky.engine.calendar;
|
|
10
|
+
if (!S || !cal?.seasons.length) {
|
|
11
|
+
// nothing is written while no tint was ever drawn (a game may write these uniforms itself); a tint just taken away goes back to neutral
|
|
12
|
+
if (sky._seasoned) { sky._seasoned = false; uniforms.uFoliageTint.value.setRGB(1, 1, 1); uniforms.uGroundTint.value.setRGB(1, 1, 1); uniforms.uFoliageMix.value = uniforms.uGroundMix.value = 0; }
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
sky._seasoned = true;
|
|
10
16
|
const cur = S[cal.season] || {}, next = S[cal.seasons[(cal.seasonIndex + 1) % cal.seasons.length]] || {};
|
|
11
17
|
const k = Math.max(0, (cal.seasonProgress - 0.8) / 0.2);
|
|
12
18
|
// mode 'multiply' (default): the color multiplies the surface. mode 'mix': the surface moves `strength` of the way to the color (orange on green
|