threedog 0.0.0-stage → 0.2.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 +5 -0
- package/LICENSE +21 -0
- package/README.md +39 -2
- package/core/Animator.js +268 -0
- package/core/Assets.js +256 -0
- package/core/Audio.js +267 -0
- package/core/Baked.js +72 -0
- package/core/Batching.js +247 -0
- package/core/Budget.js +221 -0
- package/core/Clock.js +94 -0
- package/core/Commits.js +77 -0
- package/core/DebugOverrides.js +143 -0
- package/core/Describe.js +145 -0
- package/core/Engine.js +184 -0
- package/core/Events.js +153 -0
- package/core/I18n.js +94 -0
- package/core/Input.js +245 -0
- package/core/Inspect.js +77 -0
- package/core/InspectScene.js +191 -0
- package/core/Jobs.js +146 -0
- package/core/Loading.js +149 -0
- package/core/MaterialInfo.js +32 -0
- package/core/Ops.js +256 -0
- package/core/Random.js +52 -0
- package/core/Rays.js +160 -0
- package/core/SaveStore.js +85 -0
- package/core/Saves.js +254 -0
- package/core/Stream.js +279 -0
- package/core/Threads.js +158 -0
- package/core/UrlState.js +94 -0
- package/core/Vars.js +35 -0
- package/core/Views.js +49 -0
- package/core/actor.js +23 -0
- package/core/assetEntry.js +89 -0
- package/core/assetLoad.js +190 -0
- package/core/assetManifest.js +35 -0
- package/core/assetReport.js +83 -0
- package/core/audioRules.js +121 -0
- package/core/audioVoice.js +225 -0
- package/core/batchGroups.js +116 -0
- package/core/canvasBox.js +63 -0
- package/core/catalog.js +169 -0
- package/core/checks.js +67 -0
- package/core/claims.js +51 -0
- package/core/dayTime.js +15 -0
- package/core/debugView.js +76 -0
- package/core/describeRender.js +45 -0
- package/core/describeText.js +143 -0
- package/core/easing.js +34 -0
- package/core/errorCodes.js +205 -0
- package/core/errorHints.js +208 -0
- package/core/errors.js +40 -0
- package/core/events.generated.js +84 -0
- package/core/ground.js +102 -0
- package/core/holds.js +106 -0
- package/core/inputContext.js +69 -0
- package/core/inputDefaults.js +22 -0
- package/core/inputPad.js +35 -0
- package/core/inputPointer.js +48 -0
- package/core/inputTouch.js +48 -0
- package/core/lifecycle.js +69 -0
- package/core/lightWatch.js +56 -0
- package/core/look/coreParts.js +112 -0
- package/core/look/layers.js +136 -0
- package/core/look/part.js +173 -0
- package/core/look/report.js +79 -0
- package/core/look/write.js +86 -0
- package/core/loop.js +200 -0
- package/core/math.js +33 -0
- package/core/modules.js +196 -0
- package/core/movement.js +19 -0
- package/core/mulberry32.js +14 -0
- package/core/opsAtomic.js +31 -0
- package/core/opsCheck.js +97 -0
- package/core/opsFail.js +20 -0
- package/core/opsGuard.js +26 -0
- package/core/opsHistory.js +27 -0
- package/core/opsRun.js +77 -0
- package/core/page.js +78 -0
- package/core/params.js +132 -0
- package/core/pureWorker.js +5 -0
- package/core/renamed.js +21 -0
- package/core/saveApply.js +128 -0
- package/core/saveFiles.js +139 -0
- package/core/saveIds.js +53 -0
- package/core/saveVersions.js +97 -0
- package/core/scatter.js +92 -0
- package/core/sceneMethods.js +100 -0
- package/core/screenToGround.js +39 -0
- package/core/services.js +73 -0
- package/core/session.js +171 -0
- package/core/shadowTypes.js +15 -0
- package/core/skip.js +104 -0
- package/core/startup.js +135 -0
- package/core/streamCells.js +24 -0
- package/core/streamSources.js +73 -0
- package/core/styleParts.js +96 -0
- package/core/targeting.js +64 -0
- package/core/thingExplain.js +68 -0
- package/core/thingOps.js +168 -0
- package/core/things.js +212 -0
- package/core/threadPure.js +120 -0
- package/core/threadServe.js +25 -0
- package/core/tier.js +11 -0
- package/core/util.js +11 -0
- package/core/validate.js +204 -0
- package/docs/AI.md +123 -0
- package/docs/API.md +83 -0
- package/docs/CODEMAP.md +347 -0
- package/docs/COMMANDS.md +108 -0
- package/docs/CONVENTIONS.md +145 -0
- package/docs/PERF.md +217 -0
- package/docs/THREE.md +86 -0
- package/docs/api/ambience.md +15 -0
- package/docs/api/assets.md +62 -0
- package/docs/api/audio.md +53 -0
- package/docs/api/budget.md +40 -0
- package/docs/api/cameraRig.md +120 -0
- package/docs/api/characters.md +144 -0
- package/docs/api/clock.md +7 -0
- package/docs/api/collision.md +39 -0
- package/docs/api/content.md +64 -0
- package/docs/api/dialogue.md +39 -0
- package/docs/api/engine.md +199 -0
- package/docs/api/entities.md +61 -0
- package/docs/api/events.md +95 -0
- package/docs/api/flow.md +27 -0
- package/docs/api/grids.md +11 -0
- package/docs/api/ground.md +16 -0
- package/docs/api/hlod.md +34 -0
- package/docs/api/hud.md +31 -0
- package/docs/api/i18n.md +10 -0
- package/docs/api/input.md +24 -0
- package/docs/api/interactions.md +31 -0
- package/docs/api/inventory.md +66 -0
- package/docs/api/jobs.md +10 -0
- package/docs/api/level.md +41 -0
- package/docs/api/lightPool.md +56 -0
- package/docs/api/music.md +34 -0
- package/docs/api/nav.md +26 -0
- package/docs/api/net.md +14 -0
- package/docs/api/openWorld.md +24 -0
- package/docs/api/particles.md +41 -0
- package/docs/api/photo.md +15 -0
- package/docs/api/post.md +10 -0
- package/docs/api/quests.md +36 -0
- package/docs/api/rays.md +26 -0
- package/docs/api/rigid.md +84 -0
- package/docs/api/saves.md +32 -0
- package/docs/api/settings.md +36 -0
- package/docs/api/sky.md +58 -0
- package/docs/api/stream.md +31 -0
- package/docs/api/style.md +134 -0
- package/docs/api/terrain.md +34 -0
- package/docs/api/timeline.md +39 -0
- package/docs/api/tools.md +57 -0
- package/docs/api/triggers.md +56 -0
- package/docs/api/vars.md +9 -0
- package/docs/api/vegetation.md +52 -0
- package/docs/api/water.md +48 -0
- package/docs/api/weather.md +29 -0
- package/docs/api/world.md +30 -0
- package/docs/recipes/01-new-game.md +148 -0
- package/docs/recipes/02-npc.md +167 -0
- package/docs/recipes/03-items-pickups.md +158 -0
- package/docs/recipes/04-quests.md +83 -0
- package/docs/recipes/05-props-bake.md +159 -0
- package/docs/recipes/06-clock-events.md +117 -0
- package/docs/recipes/07-flow-scenes-pause.md +132 -0
- package/docs/recipes/08-weather-sky.md +74 -0
- package/docs/recipes/09-style-pack.md +234 -0
- package/docs/recipes/10-blender-level.md +67 -0
- package/docs/recipes/11-vehicles.md +55 -0
- package/docs/recipes/12-navmesh.md +79 -0
- package/docs/recipes/13-animation.md +149 -0
- package/docs/recipes/14-custom-module.md +91 -0
- package/docs/recipes/15-perf.md +78 -0
- package/docs/recipes/16-dev-bridge.md +180 -0
- package/docs/recipes/18-world.md +185 -0
- package/docs/recipes/19-shooting-picking.md +76 -0
- package/docs/recipes/20-content-actions-save.md +176 -0
- package/docs/recipes/21-camera.md +153 -0
- package/docs/recipes/22-shop-gold.md +107 -0
- package/docs/recipes/23-ops.md +175 -0
- package/docs/recipes/26-ui-parts.md +138 -0
- package/docs/recipes/27-net.md +96 -0
- package/docs/recipes/28-terrain.md +80 -0
- package/docs/recipes/29-grid.md +87 -0
- package/docs/recipes/30-templates.md +131 -0
- package/docs/recipes/31-audio.md +126 -0
- package/docs/recipes/32-action-game.md +33 -0
- package/docs/recipes/33-stream-sources.md +37 -0
- package/docs/recipes/34-environment-lighting.md +36 -0
- package/docs/recipes/35-style-from-reference.md +89 -0
- package/docs/recipes/36-sky-ground-plant-looks.md +116 -0
- package/docs/recipes/37-terrain-look-hooks.md +97 -0
- package/docs/recipes/38-environment-look-hooks.md +83 -0
- package/docs/recipes/40-scene.md +108 -0
- package/docs/recipes/41-thing-registry.md +93 -0
- package/docs/recipes/42-terrain-shape.md +64 -0
- package/docs/recipes/43-shader-patches-surface-looks.md +120 -0
- package/docs/recipes/44-water-weather-look-hooks.md +135 -0
- package/docs/recipes/45-cascaded-shadows.md +51 -0
- package/docs/recipes/46-blender-art-route.md +114 -0
- package/docs/recipes/47-island-snow-backdrop.md +44 -0
- package/docs/recipes/48-make-material.md +70 -0
- package/docs/recipes/49-game-module-contract.md +71 -0
- package/docs/recipes/50-own-renderer.md +12 -0
- package/docs/recipes/51-capability-catalog.md +63 -0
- package/docs/recipes/52-look.md +108 -0
- package/examples/action/DESIGN.md +3 -0
- package/examples/action/GAMEMAP.md +127 -0
- package/examples/action/content/actions.js +8 -0
- package/examples/action/content/audio.js +9 -0
- package/examples/action/content/index.js +10 -0
- package/examples/action/content/items.js +4 -0
- package/examples/action/content/places.js +4 -0
- package/examples/action/content/props.js +11 -0
- package/examples/action/content/templates.js +10 -0
- package/examples/action/content/views.js +6 -0
- package/examples/action/look.js +5 -0
- package/examples/action/main.js +137 -0
- package/examples/action/models.js +25 -0
- package/examples/sheepisland/GAMEMAP.md +107 -0
- package/examples/sheepisland/content/index.js +6 -0
- package/examples/sheepisland/content/props.js +19 -0
- package/examples/sheepisland/content/templates.js +5 -0
- package/examples/sheepisland/content/vegetation.js +8 -0
- package/examples/sheepisland/main.js +71 -0
- package/examples/sheepisland/params.js +25 -0
- package/examples/sheepisland/style/index.js +79 -0
- package/examples/sheepisland/style/models.js +59 -0
- package/examples/sheepisland/views.js +9 -0
- package/examples/styletest/GAMEMAP.md +135 -0
- package/examples/styletest/content/index.js +9 -0
- package/examples/styletest/content/items.js +8 -0
- package/examples/styletest/content/npcs.js +8 -0
- package/examples/styletest/content/places.js +5 -0
- package/examples/styletest/content/props.js +16 -0
- package/examples/styletest/content/templates.js +9 -0
- package/examples/styletest/content/vegetation.js +31 -0
- package/examples/styletest/look.js +11 -0
- package/examples/styletest/main.js +95 -0
- package/examples/styletest/models.js +87 -0
- package/examples/styletest/overrides.js +33 -0
- package/examples/styletest/panel.js +135 -0
- package/examples/styletest/params.js +32 -0
- package/examples/styletest/views.js +31 -0
- package/examples/world/DESIGN.md +5 -0
- package/examples/world/GAMEMAP.md +171 -0
- package/examples/world/content/actions.js +8 -0
- package/examples/world/content/audio.js +25 -0
- package/examples/world/content/bodies.js +12 -0
- package/examples/world/content/containers.js +4 -0
- package/examples/world/content/dialogues.js +33 -0
- package/examples/world/content/index.js +17 -0
- package/examples/world/content/items.js +10 -0
- package/examples/world/content/npcs.js +14 -0
- package/examples/world/content/pickups.js +11 -0
- package/examples/world/content/places.js +6 -0
- package/examples/world/content/props.js +12 -0
- package/examples/world/content/quests.js +15 -0
- package/examples/world/content/rules.js +23 -0
- package/examples/world/content/templates.js +5 -0
- package/examples/world/content/vegetation.js +32 -0
- package/examples/world/main.js +168 -0
- package/examples/world/models.js +28 -0
- package/index.d.ts +306 -0
- package/index.js +122 -0
- package/llms.txt +61 -0
- package/modules/ambience/Ambience.js +186 -0
- package/modules/camera/FirstPersonCamera.js +131 -0
- package/modules/camera/FixedCamera.js +162 -0
- package/modules/camera/FollowCamera.js +91 -0
- package/modules/camera/RtsCamera.js +132 -0
- package/modules/camera/common.js +182 -0
- package/modules/camera/index.js +11 -0
- package/modules/camera/projection.js +34 -0
- package/modules/characters/Character.js +235 -0
- package/modules/characters/NPC.js +242 -0
- package/modules/characters/assetModel.js +42 -0
- package/modules/characters/astar.js +66 -0
- package/modules/characters/behaviors.js +72 -0
- package/modules/characters/footsteps.js +13 -0
- package/modules/characters/index.js +215 -0
- package/modules/characters/moveHelpers.js +29 -0
- package/modules/characters/movers/common.js +62 -0
- package/modules/characters/movers/rapier.js +74 -0
- package/modules/characters/movers/simple.js +43 -0
- package/modules/characters/npcAvoid.js +129 -0
- package/modules/characters/npcSim.js +150 -0
- package/modules/characters/npcView.js +42 -0
- package/modules/characters/pathAsync.js +113 -0
- package/modules/characters/pathJob.js +62 -0
- package/modules/characters/pathWorker.js +7 -0
- package/modules/characters/playerStrings.js +12 -0
- package/modules/characters/proceduralRig.js +58 -0
- package/modules/characters/useModel.js +22 -0
- package/modules/characters/walkTo.js +58 -0
- package/modules/collision/Collision.js +274 -0
- package/modules/collision/grid.js +63 -0
- package/modules/content/explain.js +13 -0
- package/modules/content/ids.js +95 -0
- package/modules/content/index.js +154 -0
- package/modules/content/loader.js +190 -0
- package/modules/content/models.js +69 -0
- package/modules/content/packs.js +69 -0
- package/modules/content/props.js +89 -0
- package/modules/content/rules.js +134 -0
- package/modules/content/templates.js +189 -0
- package/modules/debug/DebugPanel.js +174 -0
- package/modules/entities/Entities.js +243 -0
- package/modules/entities/build.js +25 -0
- package/modules/entities/index.js +4 -0
- package/modules/flow/index.js +101 -0
- package/modules/gameplay/Container.js +227 -0
- package/modules/gameplay/Containers.js +89 -0
- package/modules/gameplay/Dialogue.js +219 -0
- package/modules/gameplay/Interactions.js +253 -0
- package/modules/gameplay/Inventory.js +224 -0
- package/modules/gameplay/Quests.js +205 -0
- package/modules/gameplay/boxOps.js +60 -0
- package/modules/gameplay/dialogueBox.js +48 -0
- package/modules/gameplay/interactionPrompt.js +28 -0
- package/modules/gameplay/inventoryOps.js +137 -0
- package/modules/gameplay/pickups.js +115 -0
- package/modules/gameplay/questLog.js +54 -0
- package/modules/gameplay/questSave.js +71 -0
- package/modules/grid/Grid.js +184 -0
- package/modules/grid/Layer.js +142 -0
- package/modules/grid/index.js +236 -0
- package/modules/grid/ops.js +73 -0
- package/modules/grid/preview.js +85 -0
- package/modules/grid/tiles.js +79 -0
- package/modules/hlod/index.js +167 -0
- package/modules/hud/index.js +167 -0
- package/modules/hud/parts.js +80 -0
- package/modules/level/geometry.js +46 -0
- package/modules/level/heightfield.js +160 -0
- package/modules/level/index.js +233 -0
- package/modules/level/nodes.js +84 -0
- package/modules/lights/index.js +227 -0
- package/modules/music/Music.js +294 -0
- package/modules/music/index.js +2 -0
- package/modules/music/rules.js +28 -0
- package/modules/nav/index.js +156 -0
- package/modules/nav/navPath.js +17 -0
- package/modules/net/Client.js +137 -0
- package/modules/net/Host.js +117 -0
- package/modules/net/Net.js +49 -0
- package/modules/net/index.js +77 -0
- package/modules/net/sync.js +114 -0
- package/modules/net/transports.js +118 -0
- package/modules/particles/Particles.js +179 -0
- package/modules/particles/effect.js +112 -0
- package/modules/particles/shaders.js +28 -0
- package/modules/photo/Photo.js +146 -0
- package/modules/rigid/RigidBodies.js +265 -0
- package/modules/rigid/Vehicles.js +97 -0
- package/modules/rigid/sync.js +158 -0
- package/modules/settings/Settings.js +297 -0
- package/modules/settings/apply.js +21 -0
- package/modules/settings/index.js +3 -0
- package/modules/settings/sections.js +156 -0
- package/modules/settings/strings.js +53 -0
- package/modules/settings/view.js +65 -0
- package/modules/sky/Sky.js +259 -0
- package/modules/sky/calendar.js +80 -0
- package/modules/sky/cascades.js +125 -0
- package/modules/sky/clouds.js +79 -0
- package/modules/sky/domeLayers.js +33 -0
- package/modules/sky/environment.js +141 -0
- package/modules/sky/fog.js +139 -0
- package/modules/sky/frame.js +77 -0
- package/modules/sky/layers.js +69 -0
- package/modules/sky/look.js +51 -0
- package/modules/sky/lookFog.js +80 -0
- package/modules/sky/lookShadow.js +50 -0
- package/modules/sky/lookSky.js +108 -0
- package/modules/sky/schedule.js +80 -0
- package/modules/sky/shader.js +96 -0
- package/modules/sky/shadow.js +74 -0
- package/modules/sky/skyModule.js +60 -0
- package/modules/terrain/ChunkManager.js +260 -0
- package/modules/terrain/chunkJob.js +19 -0
- package/modules/terrain/chunkLevels.js +40 -0
- package/modules/terrain/chunkQueries.js +42 -0
- package/modules/terrain/chunkWorker.js +5 -0
- package/modules/terrain/index.js +118 -0
- package/modules/terrain/lookGround.js +61 -0
- package/modules/terrain/mountTerrain.js +32 -0
- package/modules/terrain/terrainColorMap.js +41 -0
- package/modules/terrain/terrainDefaults.js +39 -0
- package/modules/terrain/terrainEdit.js +139 -0
- package/modules/terrain/terrainGen.js +155 -0
- package/modules/terrain/terrainIsland.js +131 -0
- package/modules/terrain/terrainMesh.js +92 -0
- package/modules/terrain/terrainShape.js +108 -0
- package/modules/terrain/terrainShapeMain.js +41 -0
- package/modules/terrain/terrainTexture.js +44 -0
- package/modules/timeline/Timeline.js +253 -0
- package/modules/timeline/Tween.js +114 -0
- package/modules/timeline/letterbox.js +24 -0
- package/modules/timeline/shots.js +90 -0
- package/modules/triggers/index.js +268 -0
- package/modules/vegetation/Vegetation.js +256 -0
- package/modules/vegetation/groundChunks.js +177 -0
- package/modules/vegetation/index.js +43 -0
- package/modules/vegetation/lookWind.js +37 -0
- package/modules/vegetation/modelGeometry.js +21 -0
- package/modules/water/Water.js +160 -0
- package/modules/water/look.js +80 -0
- package/modules/water/surface.js +88 -0
- package/modules/weather/Weather.js +242 -0
- package/modules/weather/look.js +75 -0
- package/modules/weather/particles.js +92 -0
- package/modules/weather/shaders.js +49 -0
- package/modules/weather/strings.js +15 -0
- package/modules/world/World.js +231 -0
- package/modules/world/cells.js +42 -0
- package/modules/world/explain.js +11 -0
- package/modules/world/index.js +71 -0
- package/modules/world/persist.js +107 -0
- package/modules/world/pos.js +20 -0
- package/modules/world/records.js +89 -0
- package/modules/world/sim.js +175 -0
- package/modules/world/simFar.js +82 -0
- package/modules/world/state.js +115 -0
- package/modules/world/thingSource.js +44 -0
- package/modules/world/views.js +182 -0
- package/package.json +66 -4
- package/presets.js +96 -0
- package/render/PostFX.js +240 -0
- package/render/detail.js +105 -0
- package/render/effects.js +144 -0
- package/render/engineUniforms.js +23 -0
- package/render/fuse.js +84 -0
- package/render/lighting.js +100 -0
- package/render/lights.js +18 -0
- package/render/lookSurface.js +161 -0
- package/render/materials.js +220 -0
- package/render/patches.js +252 -0
- package/render/postLook.js +86 -0
- package/render/surface.js +69 -0
- package/render/uniformDecl.js +29 -0
- package/types/common.d.ts +34 -0
- package/types/core.d.ts +1965 -0
- package/types/gameplay.d.ts +1822 -0
- package/types/generated/core/Audio.d.ts +200 -0
- package/types/generated/core/Batching.d.ts +47 -0
- package/types/generated/core/Budget.d.ts +90 -0
- package/types/generated/core/Commits.d.ts +31 -0
- package/types/generated/core/DebugOverrides.d.ts +52 -0
- package/types/generated/core/Events.d.ts +89 -0
- package/types/generated/core/I18n.d.ts +30 -0
- package/types/generated/core/Input.d.ts +118 -0
- package/types/generated/core/Jobs.d.ts +41 -0
- package/types/generated/core/Ops.d.ts +203 -0
- package/types/generated/core/Random.d.ts +49 -0
- package/types/generated/core/Rays.d.ts +49 -0
- package/types/generated/core/Saves.d.ts +162 -0
- package/types/generated/core/Stream.d.ts +93 -0
- package/types/generated/core/Threads.d.ts +82 -0
- package/types/generated/core/Views.d.ts +33 -0
- package/types/generated/core/audioVoice.d.ts +47 -0
- package/types/generated/core/page.d.ts +18 -0
- package/types/generated/core/session.d.ts +48 -0
- package/types/generated/modules/ambience/Ambience.d.ts +48 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +24 -0
- package/types/generated/modules/flow/index.d.ts +10 -0
- package/types/generated/modules/grid/Grid.d.ts +151 -0
- package/types/generated/modules/grid/Layer.d.ts +65 -0
- package/types/generated/modules/grid/index.d.ts +86 -0
- package/types/generated/modules/hlod/index.d.ts +11 -0
- package/types/generated/modules/hud/index.d.ts +10 -0
- package/types/generated/modules/lights/index.d.ts +13 -0
- package/types/generated/modules/music/Music.d.ts +111 -0
- package/types/generated/modules/net/Net.d.ts +34 -0
- package/types/generated/modules/net/index.d.ts +53 -0
- package/types/generated/modules/net/transports.d.ts +58 -0
- package/types/generated/modules/particles/Particles.d.ts +69 -0
- package/types/generated/modules/sky/Sky.d.ts +145 -0
- package/types/generated/modules/sky/skyModule.d.ts +10 -0
- package/types/generated/modules/timeline/Timeline.d.ts +51 -0
- package/types/generated/modules/water/Water.d.ts +29 -0
- package/types/generated/modules/weather/Weather.d.ts +62 -0
- package/types/generated/modules/world/World.d.ts +242 -0
- package/types/generated/modules/world/index.d.ts +15 -0
- package/types/generated/render/PostFX.d.ts +125 -0
- package/types/generated/render/materials.d.ts +100 -0
- package/types/generated/render/patches.d.ts +41 -0
- package/types/generated/ui/Focus.d.ts +11 -0
- package/types/generated/ui/LoadingScreen.d.ts +2 -0
- package/types/generated/ui/UI.d.ts +57 -0
- package/types/nav.d.ts +52 -0
- package/types/physics.d.ts +592 -0
- package/types/style.d.ts +638 -0
- package/types/worker.d.ts +11 -0
- package/types/world.d.ts +772 -0
- package/ui/Focus.js +51 -0
- package/ui/LoadingScreen.js +42 -0
- package/ui/Parts.js +199 -0
- package/ui/UI.js +167 -0
- package/ui/defaults.js +85 -0
- package/ui/theme.js +124 -0
- package/ui/touchPart.js +49 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
// Sky module: dome shader (gradient + sun + moon + stars), sun/moon directional light, hemisphere ambient light and fog, all driven by time.
|
|
2
|
+
// Look (per-time colors, sun size, star density...) comes from style.sky in the style pack; the engine only holds neutral fallbacks.
|
|
3
|
+
//
|
|
4
|
+
// engine.use(sky({ time: 0.3, dayLength: 360 })); // or sky(presets.calendar.cycle)
|
|
5
|
+
// sky() alone keeps a fixed time of day (dayLength Infinity): a day-night cycle is gameplay (a shooter or a dungeon has none), so the game sets
|
|
6
|
+
// dayLength or picks presets.calendar.cycle / fourSeasons.
|
|
7
|
+
// engine.sky.timeOfDay = 0.75; engine.clock.timeScale = 10; engine.sky.clock // "18:00"
|
|
8
|
+
// Calendar: engine.sky.day (1-based); event day:start. Seasons are the game's choice and off by default (a soulslike or a shooter has none):
|
|
9
|
+
// sky({ seasons: ['spring', 'summer', 'autumn', 'winter'], daysPerSeason: 28 }), or each with its own length: [{ name: 'wet', days: 10 },
|
|
10
|
+
// { name: 'dry', days: 20 }]; then season, seasonProgress (0-1), dayOfSeason and the season:change event.
|
|
11
|
+
// Season tint: style pack seasons = { spring: { foliage: 0xffffff, ground: 0xffffff }, autumn: { foliage: 0xffb070 }, ... }, blended smoothly
|
|
12
|
+
// Clouds: style pack sky.clouds = { color, shade, coverage: 1, scale: 0.35, speed: [x, z], kind, glsl, ... } (coverage follows weather; see clouds.js)
|
|
13
|
+
// three.js objects: engine.sky.sun (DirectionalLight; moonlight at night, shadows live on it), hemi (HemisphereLight ambient), dome (dome Mesh),
|
|
14
|
+
// sunDir (Vector3 toward the sun). Light color/intensity is recomputed every frame: adjust brightness through modify() layers (see modify), or
|
|
15
|
+
// take a light over with sky({ sun: 'manual' | false, hemisphere: ... }) (look.js); fog kinds and dome layers: fog.js, domeLayers.js;
|
|
16
|
+
// engine.sky.modifiers is the composite of all layers (read-only)
|
|
17
|
+
// Skybox: style pack sky.skybox = '/textures/sky.jpg' (equirectangular panorama) replaces the gradient sky; brightness follows time
|
|
18
|
+
import * as THREE from 'three';
|
|
19
|
+
import { NEUTRAL_KEYFRAMES, checkKeyframes, makeSkyUniforms, makeDome, loadSkybox } from './shader.js';
|
|
20
|
+
import { shadowMethods, shadowFor } from './shadow.js';
|
|
21
|
+
import { renamed } from '../../core/errorHints.js';
|
|
22
|
+
import { defineSkyLook } from './lookSky.js';
|
|
23
|
+
import { defineFogLook } from './lookFog.js';
|
|
24
|
+
import { defineShadowLook } from './lookShadow.js';
|
|
25
|
+
import { layerMethods, blankLayer } from './layers.js';
|
|
26
|
+
import { environmentMethods, environmentFor, defineEnvLook } from './environment.js';
|
|
27
|
+
import { updateSky, watchOwned } from './frame.js';
|
|
28
|
+
import { prepareLook } from './look.js';
|
|
29
|
+
import { makeFog, applyFogChunks } from './fog.js';
|
|
30
|
+
import { parseSeasons, seasonIndexOf, dayOfSeasonOf, seasonProgressOf, advance } from './calendar.js';
|
|
31
|
+
import { formatClock } from '../../core/dayTime.js';
|
|
32
|
+
import { Schedule } from './schedule.js';
|
|
33
|
+
/** @import { Object3D, Vector3 } from '../../types/common' */
|
|
34
|
+
/** @import { SkyOptions, SkyModifiers, SkyLayer, SkyAtOptions, SkyBetweenOptions, SkyEnvironmentInfo } from '../../types/world' */
|
|
35
|
+
/** @import { Handle } from '../../types/common' */
|
|
36
|
+
/** @import { SkyShadowParams } from '../../types/style' */
|
|
37
|
+
const STRINGS = {
|
|
38
|
+
badDayLength: 'sky({ dayLength }): game seconds per day must be a number > 0 (Infinity = the time of day never moves); got {got}',
|
|
39
|
+
noSeason: "sky.onSeason('{name}'): the calendar has no such season (seasons: {list}). " +
|
|
40
|
+
"Seasons are off by default: sky({ seasons: ['spring', 'summer', 'autumn', 'winter'] })",
|
|
41
|
+
};
|
|
42
|
+
/** engine.sky */
|
|
43
|
+
export class Sky {
|
|
44
|
+
/** @internal */
|
|
45
|
+
constructor(engine, { time = 0.33, dayLength = Infinity, day = 1, daysPerSeason = 7, seasons = [], ...over } = {}) {
|
|
46
|
+
/** @internal */ this.engine = engine;
|
|
47
|
+
const st = { ...(engine.style.sky || {}), ...over };
|
|
48
|
+
/**
|
|
49
|
+
* Sky time of day: 0-1 (0 midnight, 0.25 6am, 0.5 noon, 0.75 6pm); one day = dayLength game seconds (the unit of engine.clock.now). Fixed-step seconds
|
|
50
|
+
* (unaffected by timeScale) are engine.elapsed @type {number}
|
|
51
|
+
*/
|
|
52
|
+
this.timeOfDay = time;
|
|
53
|
+
if (!(dayLength > 0)) throw new Error(STRINGS.badDayLength.replace('{got}', String(dayLength)));
|
|
54
|
+
/**
|
|
55
|
+
* Game seconds per day (1 sky hour = dayLength / 24 game seconds; at timeScale 1 game seconds equal fixed-step seconds); Infinity = the time of day never
|
|
56
|
+
* moves @type {number}
|
|
57
|
+
*/
|
|
58
|
+
this.dayLength = dayLength;
|
|
59
|
+
/** Day number (1-based) @type {number} */
|
|
60
|
+
this.day = day;
|
|
61
|
+
/** Days per season for seasons given by name only @type {number} */
|
|
62
|
+
this.daysPerSeason = daysPerSeason;
|
|
63
|
+
/** Season names, [] when the game has no seasons (the default) @type {string[]} */
|
|
64
|
+
this.seasons = [];
|
|
65
|
+
// kept as names plus the day each season ends (cumulative), so seasons of different lengths cost one short loop in the getters
|
|
66
|
+
/** @internal */ this._ends = [];
|
|
67
|
+
const parsed = parseSeasons(seasons, daysPerSeason);
|
|
68
|
+
this.seasons.push(...parsed.names); this._ends.push(...parsed.ends);
|
|
69
|
+
/** @internal */ this.seasonStyle = engine.style.seasons || null;
|
|
70
|
+
/** @internal */ this._season = this.season;
|
|
71
|
+
/** @internal */ this._sched = new Schedule(this);
|
|
72
|
+
if (st.keyframes) checkKeyframes(st.keyframes);
|
|
73
|
+
/** @internal */ this.kf = (st.keyframes || NEUTRAL_KEYFRAMES).map(k => [k[0], new THREE.Color(k[1]), new THREE.Color(k[2]), new THREE.Color(k[3]), k[4], k[5]]);
|
|
74
|
+
/** @internal */ this.groundTint = new THREE.Color(st.groundTint ?? 0x4a4a4a);
|
|
75
|
+
const scene = engine.scene;
|
|
76
|
+
|
|
77
|
+
const look = prepareLook(this, st, over); // light modes, fog, dome layers (look.js)
|
|
78
|
+
/** @internal */ this.uniforms = { ...makeSkyUniforms(st, engine.uniforms), ...look.uniforms };
|
|
79
|
+
/** Dome mesh @type {Object3D} */
|
|
80
|
+
this.dome = makeDome(this.uniforms, st, look);
|
|
81
|
+
scene.add(this.dome);
|
|
82
|
+
// Skybox (panorama): replaces the gradient sky when present
|
|
83
|
+
/** @internal */ this.skybox = null;
|
|
84
|
+
if (st.skybox) loadSkybox(this, st.skybox);
|
|
85
|
+
|
|
86
|
+
scene.fog = this._drive.fog === false ? null : makeFog(this._fog, engine.fogFar);
|
|
87
|
+
/** @internal */ this._fogOff = this._drive.fog === false ? () => {} : applyFogChunks(this._fog); // throws when another engine holds a different custom fog
|
|
88
|
+
defineFogLook(this, this._fogSpec); // look.fog: style.sky.fog / sky({ fog }) is its style layer
|
|
89
|
+
/** Hemisphere ambient light (engine.lights.hemi, driven by the sky) @type {any} */
|
|
90
|
+
this.hemi = engine.lights.hemi;
|
|
91
|
+
/** Sun directional light (engine.lights.sun driven by the sky; moonlight at night, shadows live on it) @type {any} */
|
|
92
|
+
this.sun = engine.lights.sun;
|
|
93
|
+
this.sun.castShadow = engine.shadows && this._drive.sun !== false;
|
|
94
|
+
const sh = shadowFor(engine.tier, engine.style.sky?.shadow, over.shadow);
|
|
95
|
+
this.sun.shadow.mapSize.set(sh.mapSize ?? 2048, sh.mapSize ?? 2048);
|
|
96
|
+
const ext = sh.extent ?? 70;
|
|
97
|
+
Object.assign(this.sun.shadow.camera, { left: -ext, right: ext, top: ext, bottom: -ext, near: 1, far: 420 });
|
|
98
|
+
/** Sun direction (unit vector toward the sun) @type {Vector3} */
|
|
99
|
+
this.sunDir = new THREE.Vector3();
|
|
100
|
+
/**
|
|
101
|
+
* Sun orbit: tilt = north-south tilt, sway = east-west swing, distance = light distance (meters) @type {{ tilt: number, sway: number, distance: number }}
|
|
102
|
+
*/
|
|
103
|
+
this.orbit = { tilt: st.orbitTilt ?? 0.45, sway: st.orbitSway ?? 0.8, distance: sh.distance ?? 160 };
|
|
104
|
+
// Shadow update policy (default: every frame, center snapped to 0.5 m)
|
|
105
|
+
/** Current shadow params (change via look.shadow.set) @readonly @type {SkyShadowParams} */
|
|
106
|
+
this.shadow = { bias: -0.0006, normalBias: 0.04, updateEvery: 1, snap: 0.5, ahead: 0, type: engine.shadowType, radius: 1, blurSamples: 8,
|
|
107
|
+
cascades: 1, maxFar: 120, fade: true, lightMargin: 100, split: 'practical' };
|
|
108
|
+
/** three's CSM (addons/csm) while shadow.cascades > 1, else null; its lights[0] is sun (recipes/45) @type {any} */
|
|
109
|
+
this.csm = null;
|
|
110
|
+
/** @internal */ this._shadowFrame = 0;
|
|
111
|
+
/** @internal */ this._snapKey = '';
|
|
112
|
+
defineShadowLook(this, sh); // look.shadow: the style / options shadow is its style layer; look.shadow.set writes the game layer
|
|
113
|
+
/** Hours per day @type {number} */
|
|
114
|
+
this.hoursPerDay = over.hoursPerDay ?? 24; // gameplay timing (clock notation, schedules): a sky() option only, never read from the style pack
|
|
115
|
+
// Modifier layers: weather and games each write their own layer (modify); sky composites them into modifiers every frame
|
|
116
|
+
// and applies them on top of its own result (layers.js)
|
|
117
|
+
/** @internal */ this._layers = new Map();
|
|
118
|
+
/** @internal */ this._checked = new Map(); // owner -> the values object whose keys were last checked (layers.js)
|
|
119
|
+
/** Composite of all modifier layers (read-only; use modify to adjust brightness) @readonly @type {SkyModifiers} */
|
|
120
|
+
this.modifiers = blankLayer();
|
|
121
|
+
/** @internal */ this._lightDir = new THREE.Vector3();
|
|
122
|
+
/** @internal */ this._env = null;
|
|
123
|
+
const env = environmentFor(engine.tier, engine.style.sky?.environment, over.environment);
|
|
124
|
+
defineEnvLook(this, env); // look.env: the style / options environment is its style layer, look.env.replace writes the game layer
|
|
125
|
+
defineSkyLook(this, st); // look.sky: live cloud uniforms, backdrop, the clouds / layer:<name> hooks, skybox
|
|
126
|
+
// the keyframes write these light keys every frame: describe().look shows them as style (driver sky) with the live value
|
|
127
|
+
const D = this._drive;
|
|
128
|
+
engine.look.lights.drive([...(D.sun === true ? ['sun.intensity', 'sun.color'] : []), ...(D.hemi === true ? ['hemi.intensity', 'hemi.color', 'hemi.ground'] : [])], 'sky');
|
|
129
|
+
// Per-frame recomputed properties: direct edits by games get overwritten, so warn once in dev (frame.js)
|
|
130
|
+
/** @internal */ this._owned = watchOwned(this);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Write a modifier layer (only the given fields; unwritten fields have no effect); values null removes the layer. Weather uses the 'weather' layer, games use
|
|
135
|
+
* their own layer name.
|
|
136
|
+
* Layers composite every frame: sun / ambient / fog multiply; tint blends weighted by tintAmount; flash takes the max
|
|
137
|
+
* @example engine.sky.modify('cave', { sun: 0.3, ambient: 0.4 }); engine.sky.modify('cave', null);
|
|
138
|
+
* @param {string} owner
|
|
139
|
+
* @param {SkyLayer | null} values
|
|
140
|
+
* @returns {this}
|
|
141
|
+
*/
|
|
142
|
+
modify(owner, values) { return layerMethods.modify.call(this, owner, values); }
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Shadow resolution (pixels)
|
|
146
|
+
* @returns {number}
|
|
147
|
+
*/
|
|
148
|
+
get shadowMapSize() { return this.sun.shadow.mapSize.x; }
|
|
149
|
+
|
|
150
|
+
/** Clock text, e.g. "18:00" */
|
|
151
|
+
get clock() { return formatClock(this.timeOfDay, this.hoursPerDay); }
|
|
152
|
+
/** Sun elevation -1 (midnight) ... 0 (horizon) ... 1 (noon). Day/night is computed only here; other modules read isDay / daylight */
|
|
153
|
+
get sunHeight() { return Math.sin((this.timeOfDay - 0.25) * Math.PI * 2); }
|
|
154
|
+
/** Whether it is daytime (sun above the horizon) */
|
|
155
|
+
get isDay() { return this.sunHeight > 0; }
|
|
156
|
+
/** Daylight amount 0-1 (0 at night, 1 at noon); ambience etc. fade by it */
|
|
157
|
+
get daylight() { return Math.max(0, this.sunHeight); }
|
|
158
|
+
|
|
159
|
+
// ---------- Calendar ----------
|
|
160
|
+
/** Current season index, -1 without seasons */
|
|
161
|
+
get seasonIndex() { return seasonIndexOf(this); }
|
|
162
|
+
/** Current season name, e.g. 'spring'; null without seasons @type {string | null} */
|
|
163
|
+
get season() { return this.seasons[this.seasonIndex] ?? null; }
|
|
164
|
+
/** Day within the season (1-based); 0 without seasons */
|
|
165
|
+
get dayOfSeason() { return dayOfSeasonOf(this); }
|
|
166
|
+
/** Fraction of the season elapsed, 0-1 (includes time of day); 0 without seasons */
|
|
167
|
+
get seasonProgress() { return seasonProgressOf(this); }
|
|
168
|
+
/** Total game time in days (fractional), for growth, cooldowns and the like */
|
|
169
|
+
get totalDays() { return this.day - 1 + this.timeOfDay; }
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Advance time (called by the module every fixed step)
|
|
173
|
+
* @param {number} dt
|
|
174
|
+
* @returns {void}
|
|
175
|
+
* @internal
|
|
176
|
+
*/
|
|
177
|
+
tick(dt) { advance(this, dt); }
|
|
178
|
+
|
|
179
|
+
// ---------- Clock-time / season timers (read sky time of day; for "after N seconds" use engine.clock.after) ----------
|
|
180
|
+
/**
|
|
181
|
+
* Call fn every day at a clock time: at('18:00', fn) or at(0.75, fn).
|
|
182
|
+
* Fires only when time moves forward across the clock time: natural flow, step fast-forward and setting timeOfDay later all count;
|
|
183
|
+
* crossing several triggers at once is replayed per catchUp; rewinding time and loading a save do not fire, they only reset the baseline.
|
|
184
|
+
* To hold a state during a time range (lights, shop door) use between
|
|
185
|
+
* @param {string | number} clock 'HH:MM' or 0-1
|
|
186
|
+
* @param {(day: number) => void} fn
|
|
187
|
+
* @param {SkyAtOptions} [opts]
|
|
188
|
+
* @returns {Handle}
|
|
189
|
+
*/
|
|
190
|
+
at(clock, fn, opts) { return this._sched.at(clock, fn, opts); }
|
|
191
|
+
/**
|
|
192
|
+
* Time-range switch: on() while clock time is in [from, to), otherwise off() (from > to wraps midnight).
|
|
193
|
+
* Aligns once immediately on registration, new game, load, applying a scenario and time rewind; afterwards it calls on/off when crossing a boundary
|
|
194
|
+
* @example engine.sky.between('18:00', '06:00', { on: () => lamp.on(), off: () => lamp.off() })
|
|
195
|
+
* @param {string | number} from
|
|
196
|
+
* @param {string | number} to
|
|
197
|
+
* @param {SkyBetweenOptions} opts
|
|
198
|
+
* @returns {Handle}
|
|
199
|
+
*/
|
|
200
|
+
between(from, to, opts) { return this._sched.between(from, to, opts); }
|
|
201
|
+
/**
|
|
202
|
+
* Call fn(day) at the start of each day (00:00)
|
|
203
|
+
* @param {(day: number) => void} fn
|
|
204
|
+
* @param {SkyAtOptions} [opts]
|
|
205
|
+
* @returns {Handle}
|
|
206
|
+
*/
|
|
207
|
+
daily(fn, opts) { return this._sched.at(0, fn, opts); }
|
|
208
|
+
/**
|
|
209
|
+
* Call fn(seasonName) on entering season name
|
|
210
|
+
* @param {string} name
|
|
211
|
+
* @param {(season: string) => void} fn
|
|
212
|
+
* @returns {Handle}
|
|
213
|
+
*/
|
|
214
|
+
onSeason(name, fn) {
|
|
215
|
+
// a season the calendar does not have would never fire: say so now instead of waiting forever
|
|
216
|
+
if (!this.seasons.includes(name))
|
|
217
|
+
throw new Error(STRINGS.noSeason.replace('{name}', name).replace('{list}', this.seasons.length ? this.seasons.join(', ') : 'none'));
|
|
218
|
+
return this._sched.onSeason(name, fn);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Game seconds until the next clock mark (midnight, at times, between edges); engine.skip ends a segment there; Infinity when the time of day never moves
|
|
222
|
+
* @internal
|
|
223
|
+
*/
|
|
224
|
+
untilMark() { return Number.isFinite(this.dayLength) ? this._sched.untilNext() * this.dayLength : Infinity; }
|
|
225
|
+
/** Number of registered clock-time / season timers, for engine.counts() @internal */
|
|
226
|
+
get scheduled() { return this._sched.size; }
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Update sky, lights and fog every frame (called by the module each frame)
|
|
230
|
+
* @param {Vector3} focus
|
|
231
|
+
* @returns {void}
|
|
232
|
+
* @internal
|
|
233
|
+
*/
|
|
234
|
+
update(focus) { updateSky(this, focus); }
|
|
235
|
+
|
|
236
|
+
// Public shadow methods: implemented in shadow.js, declared here so type and doc tools see them (the rest is mixed in below)
|
|
237
|
+
/**
|
|
238
|
+
* Renamed in 0.2: throws and names the new call, engine.look.shadow.set(opts) (fields: bias, normalBias, updateEvery, snap, ahead, type, radius, blurSamples, cascades; recipes/45)
|
|
239
|
+
* @param {Partial<SkyShadowParams>} [_opts]
|
|
240
|
+
* @returns {never}
|
|
241
|
+
*/
|
|
242
|
+
setShadow(_opts) { return renamed('setShadow'); }
|
|
243
|
+
/**
|
|
244
|
+
* Change shadow resolution (raise temporarily for photo mode)
|
|
245
|
+
* @param {number} n pixels
|
|
246
|
+
* @returns {void}
|
|
247
|
+
*/
|
|
248
|
+
setShadowMapSize(n) { return shadowMethods.setShadowMapSize.call(this, n); }
|
|
249
|
+
/**
|
|
250
|
+
* Renamed in 0.2: throws and names the new call, engine.look.env.replace(source) then engine.look.env.set({ intensity, rotation, interval })
|
|
251
|
+
* @param {{ source?: string | null, intensity?: number, rotation?: number, interval?: number } | null} [_opts]
|
|
252
|
+
* @returns {never}
|
|
253
|
+
*/
|
|
254
|
+
setEnvironment(_opts) { return renamed('setEnvironment'); }
|
|
255
|
+
/** Environment lighting now: { source, intensity, rotation, interval, builds }, null when off @type {SkyEnvironmentInfo | null} */
|
|
256
|
+
get environment() { return environmentMethods._envInfo.call(this); }
|
|
257
|
+
}
|
|
258
|
+
// Mixed in from shadow.js and layers.js; methods the class already defines are kept
|
|
259
|
+
for (const [k, f] of Object.entries({ ...shadowMethods, ...layerMethods, ...environmentMethods })) if (!Object.hasOwn(Sky.prototype, k)) Sky.prototype[k] = f;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Sky season tint (helper of Sky.js): blends style.seasons colors into the engine's foliage / ground tint uniforms every frame.
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
import { warnOnce } from '../../core/validate.js';
|
|
4
|
+
import { inRange } from '../../core/dayTime.js';
|
|
5
|
+
|
|
6
|
+
// This season's color, blending to the next season over the last 20% of the season
|
|
7
|
+
const c1 = new THREE.Color(), c2 = new THREE.Color();
|
|
8
|
+
export function applySeason(sky, uniforms) {
|
|
9
|
+
// no seasons in this game's calendar: the style's season colors never apply, the tint stays neutral (white = no change)
|
|
10
|
+
const S = sky.seasonStyle; if (!S || !sky.seasons.length) return;
|
|
11
|
+
const cur = S[sky.season] || {}, next = S[sky.seasons[(sky.seasonIndex + 1) % sky.seasons.length]] || {};
|
|
12
|
+
const k = Math.max(0, (sky.seasonProgress - 0.8) / 0.2);
|
|
13
|
+
// mode 'multiply' (default): the color multiplies the surface. mode 'mix': the surface moves `strength` of the way to the color (orange on green
|
|
14
|
+
// leaves stays orange instead of turning muddy); a season without a color for the part leaves it alone
|
|
15
|
+
const mix = S.mode === 'mix', strength = S.strength ?? 0.5;
|
|
16
|
+
const blend = (key, out, amount) => {
|
|
17
|
+
const a = cur[key], b = next[key];
|
|
18
|
+
c1.set(a ?? (mix ? b : null) ?? 0xffffff); c2.set(b ?? (mix ? a : null) ?? 0xffffff); out.copy(c1).lerp(c2, k);
|
|
19
|
+
amount.value = mix ? strength * ((a != null ? 1 - k : 0) + (b != null ? k : 0)) : 0;
|
|
20
|
+
};
|
|
21
|
+
blend('foliage', uniforms.uFoliageTint.value, uniforms.uFoliageMix); blend('ground', uniforms.uGroundTint.value, uniforms.uGroundMix);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const STRINGS = {
|
|
25
|
+
badTime: "audio rule condition time: {got} never matches; use 'day', 'night' or a clock range ['18:00', '06:00'] (or 0-1 times [0.75, 0.25])",
|
|
26
|
+
badSeasons: "sky({ seasons }): a list of names (each daysPerSeason days long) or of { name, days } with days >= 1, [] for none; got {got}",
|
|
27
|
+
};
|
|
28
|
+
/** Season names and the cumulative day each one ends on, from sky({ seasons }): names (daysPerSeason long each) or { name, days } with days >= 1 */
|
|
29
|
+
export function parseSeasons(seasons, daysPerSeason) {
|
|
30
|
+
if (!Array.isArray(seasons)) throw new Error(STRINGS.badSeasons.replace('{got}', JSON.stringify(seasons)));
|
|
31
|
+
const names = [], ends = [];
|
|
32
|
+
let end = 0;
|
|
33
|
+
for (const x of seasons) {
|
|
34
|
+
const name = typeof x === 'string' ? x : x?.name, days = typeof x === 'string' ? daysPerSeason : x?.days;
|
|
35
|
+
if (typeof name !== 'string' || !(days >= 1)) throw new Error(STRINGS.badSeasons.replace('{got}', JSON.stringify(x)));
|
|
36
|
+
names.push(name); ends.push(end += days);
|
|
37
|
+
}
|
|
38
|
+
return { names, ends };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Audio rule condition { time: 'day' | 'night' | ['18:00', '06:00'] } for music / ambience rule lists */
|
|
42
|
+
export function timeCondition(s) {
|
|
43
|
+
return v => {
|
|
44
|
+
if (v === 'day') return s.isDay;
|
|
45
|
+
if (v === 'night') return !s.isDay;
|
|
46
|
+
// anything else must be a [from, to] range; 'evening' or a lone '18:00' would silently never match, so say which forms work
|
|
47
|
+
if (!Array.isArray(v) || v.length !== 2) { warnOnce(STRINGS.badTime.replace('{got}', JSON.stringify(v))); return false; }
|
|
48
|
+
return inRange(s.timeOfDay, v[0], v[1], s.hoursPerDay);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Index of the current season in sky.seasons (-1 without seasons) */
|
|
53
|
+
export function seasonIndexOf(sky) {
|
|
54
|
+
const ends = sky._ends, n = ends.length;
|
|
55
|
+
if (!n) return -1;
|
|
56
|
+
const d = (sky.day - 1) % ends[n - 1];
|
|
57
|
+
let i = 0;
|
|
58
|
+
while (d >= ends[i]) i++;
|
|
59
|
+
return i;
|
|
60
|
+
}
|
|
61
|
+
/** Day within the season (1-based); 0 without seasons */
|
|
62
|
+
export function dayOfSeasonOf(sky) {
|
|
63
|
+
const i = sky.seasonIndex, ends = sky._ends;
|
|
64
|
+
return i < 0 ? 0 : (sky.day - 1) % ends[ends.length - 1] - (ends[i - 1] ?? 0) + 1;
|
|
65
|
+
}
|
|
66
|
+
/** Fraction of the season elapsed, 0-1 (includes time of day); 0 without seasons */
|
|
67
|
+
export function seasonProgressOf(sky) {
|
|
68
|
+
const i = sky.seasonIndex, ends = sky._ends;
|
|
69
|
+
return i < 0 ? 0 : (sky.dayOfSeason - 1 + sky.timeOfDay) / (ends[i] - (ends[i - 1] ?? 0));
|
|
70
|
+
}
|
|
71
|
+
/** One fixed step of the sky clock: advance the time of day, and on a new day emit day:start (and season:change when the season turned) */
|
|
72
|
+
export function advance(sky, dt) {
|
|
73
|
+
const t = sky.timeOfDay + dt * sky.engine.clock.timeScale / sky.dayLength;
|
|
74
|
+
if (t >= 1) {
|
|
75
|
+
sky.timeOfDay = t % 1; sky.day += Math.floor(t);
|
|
76
|
+
sky.engine.events.emit('day:start', sky.day);
|
|
77
|
+
if (sky.season !== sky._season) { sky._season = sky.season; sky.engine.events.emit('season:change', sky.season); }
|
|
78
|
+
} else sky.timeOfDay = t;
|
|
79
|
+
sky._sched.tick();
|
|
80
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Sky cascaded shadows (helper of shadow.js), off by default (shadow.cascades 1 = one shadow map, exactly the single-map path).
|
|
2
|
+
// shadow.cascades 2-4 splits the sun's shadow along the view into that many maps (three's CSM addon): sharp near the camera, wide far away.
|
|
3
|
+
// Design choices, each one because the addon used as-is would break something:
|
|
4
|
+
// - engine.lights.sun stays in charge and is the nearest cascade, so the sky keeps driving its color / intensity / direction, the dev
|
|
5
|
+
// guards keep watching it, and photo mode's setShadowMapSize sharpens the cascade that matters most. The other cascades are extra
|
|
6
|
+
// DirectionalLights that copy the sun's color and intensity every frame.
|
|
7
|
+
// - Materials get the cascade lighting through one named patch, 'csm' (render/patches.js), never CSM.setupMaterial: that assigns
|
|
8
|
+
// material.onBeforeCompile and would drop every other patch (wind, clouds, season, detail, lighting), and CSM.dispose deletes it.
|
|
9
|
+
// - The chunk swap is per material (the patch replaces <lights_fragment_begin>): CSM's constructor overwrites ShaderChunk globally and
|
|
10
|
+
// never restores it, which would reach every material and every engine on the page; here _injectInclude does nothing.
|
|
11
|
+
// - Every lit material in the scene must carry the patch: without it the cascade lights would add up (N times the sunlight). So while
|
|
12
|
+
// cascades are on, each frame walks the scene and patches lit materials it has not seen (one Map lookup per mesh).
|
|
13
|
+
// - csm.update() runs only on frames whose shadow maps re-render (shadow.updateEvery), else lights move while the maps stay old.
|
|
14
|
+
import * as THREE from 'three';
|
|
15
|
+
import { CSM } from 'three/addons/csm/CSM.js';
|
|
16
|
+
import { CSMShader } from 'three/addons/csm/CSMShader.js';
|
|
17
|
+
import { patchMaterial, unpatchMaterial } from '../../render/patches.js';
|
|
18
|
+
|
|
19
|
+
const LIT = new Set(['MeshLambertMaterial', 'MeshPhongMaterial', 'MeshStandardMaterial', 'MeshPhysicalMaterial', 'MeshToonMaterial']);
|
|
20
|
+
const lit = m => m.isShaderMaterial ? m.lights && m.fragmentShader.includes('#include <lights_fragment_begin>') : LIT.has(m.type);
|
|
21
|
+
const SPLITS = ['practical', 'uniform', 'logarithmic'];
|
|
22
|
+
const STRINGS = {
|
|
23
|
+
count: 'look.shadow.set({ cascades }): a whole number 1 (one shadow map, the default) to 4; got {got}',
|
|
24
|
+
split: "look.shadow.set({ split }): 'practical' (default) | 'uniform' | 'logarithmic' | (count, near, far, out) => void; got {got}",
|
|
25
|
+
maxFar: 'look.shadow.set({ maxFar }): meters from the camera that cascades cover, a number > 0; got {got}',
|
|
26
|
+
noSun: "look.shadow.set({ cascades }): cascaded shadows split the engine sun's shadow, and sky({ sun: false }) has no engine sun. " +
|
|
27
|
+
"With your own lights use three's CSM addon on them, or keep sun: true / 'manual'",
|
|
28
|
+
};
|
|
29
|
+
const bad = (k, v) => { throw new Error(STRINGS[k].replace('{got}', JSON.stringify(v) ?? String(v))); };
|
|
30
|
+
|
|
31
|
+
/** Throw on cascade fields a look.shadow.set call gets wrong, before anything is applied */
|
|
32
|
+
export function checkCascades(sky, o) {
|
|
33
|
+
if (o.cascades !== undefined && !(Number.isInteger(o.cascades) && o.cascades >= 1 && o.cascades <= 4)) bad('count', o.cascades);
|
|
34
|
+
if (o.split !== undefined && typeof o.split !== 'function' && !SPLITS.includes(o.split)) bad('split', o.split);
|
|
35
|
+
if (o.maxFar !== undefined && !(o.maxFar > 0)) bad('maxFar', o.maxFar);
|
|
36
|
+
if (o.cascades > 1 && sky._drive.sun === false) bad('noSun');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// The addon's split / frustum / texel-snapped placement, with the sun as cascade 0 and the chunk swap left to the 'csm' patch
|
|
40
|
+
class SkyCSM extends CSM {
|
|
41
|
+
constructor(sky, S) {
|
|
42
|
+
const e = sky.engine, custom = typeof S.split === 'function';
|
|
43
|
+
super({ camera: e.camera, parent: e.scene, cascades: S.cascades, maxFar: S.maxFar, mode: custom ? 'custom' : S.split, customSplitsCallback: custom ? S.split : undefined,
|
|
44
|
+
shadowMapSize: sky.sun.shadow.mapSize.x, shadowBias: S.bias, lightMargin: S.lightMargin, lightNear: 1, lightFar: S.lightMargin + 2 * S.maxFar });
|
|
45
|
+
const first = this.lights[0];
|
|
46
|
+
this.parent.remove(first, first.target); first.dispose();
|
|
47
|
+
this.lights[0] = sky.sun;
|
|
48
|
+
// uniforms shared by every patched material: one write here reaches all of them
|
|
49
|
+
this.uniforms = { CSM_cascades: { value: [] }, cameraNear: { value: 0 }, shadowFar: { value: 0 } };
|
|
50
|
+
this.fade = S.fade;
|
|
51
|
+
this.updateFrustums();
|
|
52
|
+
// cacheKey is new for every build: three keeps a material's old programs and, when a key comes back (cascades off, then on again),
|
|
53
|
+
// reuses that program with the uniforms map of the material's latest compile, which lacks these uniforms, so the GPU would keep the
|
|
54
|
+
// old build's split and far values (shadows vanish where the old cascade 0 ended). One recompile per switch, which the light count
|
|
55
|
+
// change costs anyway; each material keeps one program per switch until it is disposed, so switch on a settings screen, not per frame
|
|
56
|
+
sky._csmBuild = (sky._csmBuild ?? 0) + 1;
|
|
57
|
+
this.patch = { name: 'csm', cacheKey: `${S.cascades}${S.fade ? 'f' : ''}.${sky._csmBuild}`, uniforms: this.uniforms, glsl: { fragment: {
|
|
58
|
+
pars: `#define USE_CSM 1\n#define CSM_CASCADES ${S.cascades}\n${S.fade ? '#define CSM_FADE\n' : ''}` +
|
|
59
|
+
'uniform vec2 CSM_cascades[CSM_CASCADES];\nuniform float cameraNear;\nuniform float shadowFar;',
|
|
60
|
+
lights_fragment_begin: { replace: CSMShader.lights_fragment_begin } } } };
|
|
61
|
+
/** material -> the patch object it carries, so a rebuilt CSM re-patches and switching off finds every material */
|
|
62
|
+
this.mats = new Map();
|
|
63
|
+
this.at = new THREE.Vector3(Infinity, 0, 0); // camera position at the last placement
|
|
64
|
+
this.proj = '';
|
|
65
|
+
this.visit = o => { if (!o.isMesh) return; const ms = o.material; if (Array.isArray(ms)) for (const m of ms) this.fit(m); else if (ms) this.fit(ms); };
|
|
66
|
+
}
|
|
67
|
+
fit(m) { if (this.mats.get(m) !== this.patch && lit(m)) { patchMaterial(m, [this.patch], { strict: false }); this.mats.set(m, this.patch); } }
|
|
68
|
+
_injectInclude() {}
|
|
69
|
+
_updateUniforms() {
|
|
70
|
+
const U = this.uniforms;
|
|
71
|
+
if (!U) return; // the base constructor calls this before the uniforms exist
|
|
72
|
+
this._getExtendedBreaks(U.CSM_cascades.value);
|
|
73
|
+
U.cameraNear.value = this.camera.near; U.shadowFar.value = Math.min(this.camera.far, this.maxFar);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Create, rebuild or remove the cascades after look.shadow.set changed shadow fields; copy bias / softness to the extra lights */
|
|
78
|
+
export function syncCascades(sky) {
|
|
79
|
+
const S = sky.shadow, e = sky.engine, want = S.cascades > 1;
|
|
80
|
+
const key = want ? [S.cascades, S.maxFar, S.fade, S.lightMargin, S.split].join('|') : '';
|
|
81
|
+
if (key !== sky._csmKey) {
|
|
82
|
+
dropCascades(sky);
|
|
83
|
+
sky._csmKey = key;
|
|
84
|
+
if (want) {
|
|
85
|
+
const sc = sky.sun.shadow.camera;
|
|
86
|
+
sky._csmSaved = { left: sc.left, right: sc.right, top: sc.top, bottom: sc.bottom, near: sc.near, far: sc.far };
|
|
87
|
+
sky.csm = new SkyCSM(sky, S);
|
|
88
|
+
Object.assign(sc, { near: 1, far: sky.csm.lightFar });
|
|
89
|
+
// these lights are new to the scene: honor engine.setShadows(false) the way it treats existing lights
|
|
90
|
+
for (const l of sky.csm.lights) if (l !== sky.sun) l.castShadow = e.shadows;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (sky.csm) for (const l of sky.csm.lights) Object.assign(l.shadow, { bias: S.bias, normalBias: S.normalBias, radius: S.radius, blurSamples: S.blurSamples });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Remove the cascades: extra lights out, the 'csm' patch off every material it went on, the sun's shadow box restored */
|
|
97
|
+
export function dropCascades(sky) {
|
|
98
|
+
const c = sky.csm;
|
|
99
|
+
if (!c) return;
|
|
100
|
+
for (const l of c.lights) if (l !== sky.sun) { c.parent.remove(l, l.target); l.dispose(); }
|
|
101
|
+
for (const m of c.mats.keys()) unpatchMaterial(m, 'csm');
|
|
102
|
+
const sc = sky.sun.shadow.camera;
|
|
103
|
+
Object.assign(sc, sky._csmSaved); sc.updateProjectionMatrix();
|
|
104
|
+
sky.csm = null; sky._csmKey = ''; sky._snapKey = '';
|
|
105
|
+
sky.engine.renderer.shadowMap.needsUpdate = true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Per frame while cascades are on (instead of _placeShadow): patch new materials, follow the camera and the light, place on shadow frames */
|
|
109
|
+
export function cascadeFrame(sky, lightDir) {
|
|
110
|
+
const c = sky.csm, e = sky.engine, cam = e.camera, sun = sky.sun, S = sky.shadow, sm = e.renderer.shadowMap;
|
|
111
|
+
e.scene.traverse(c.visit);
|
|
112
|
+
const proj = cam.isPerspectiveCamera ? `${cam.fov},${cam.aspect},${cam.near},${cam.far},${cam.zoom}` : `${cam.left},${cam.right},${cam.near},${cam.far},${cam.zoom}`;
|
|
113
|
+
let force = false;
|
|
114
|
+
if (c.camera !== cam || proj !== c.proj) { c.camera = cam; c.proj = proj; c.updateFrustums(); force = true; }
|
|
115
|
+
c.lightDirection.copy(lightDir).negate(); // CSM points from the light into the scene
|
|
116
|
+
const show = sun.visible && e.shadows; // with shadows off the extra lights would only add light: hide them
|
|
117
|
+
for (const l of c.lights) if (l !== sun) { l.color.copy(sun.color); l.intensity = sun.intensity; l.visible = show; }
|
|
118
|
+
cam.updateMatrixWorld();
|
|
119
|
+
// not updating every frame: also place early when the camera left a quarter of the nearest cascade (teleport, fast travel)
|
|
120
|
+
const near = c.breaks[0] * Math.min(cam.far, c.maxFar);
|
|
121
|
+
if (S.updateEvery <= 1 || sm.needsUpdate || force || c.at.distanceToSquared(cam.position) > (near / 4) ** 2) {
|
|
122
|
+
c.update(); c.at.copy(cam.position);
|
|
123
|
+
if (S.updateEvery > 1) sm.needsUpdate = true;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Sky cloud layer for the dome shader: built-in kinds ('plane' default, 'cumulus') or a style-pack GLSL function, plus the
|
|
2
|
+
// uniforms they read. Split out of shader.js so a look can be replaced without touching the dome.
|
|
3
|
+
//
|
|
4
|
+
// Every kind implements the same function, which is the contract for style.sky.clouds.glsl too:
|
|
5
|
+
// vec4 threedogClouds(vec3 dir, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cover)
|
|
6
|
+
// dir unit view direction, dir.y > 0 (only the upper hemisphere calls it; cover > 0.01)
|
|
7
|
+
// time seconds (engine.uniforms.uTime); sunDir unit vector towards the sun (moon is opposite); night 0 day .. 1 night
|
|
8
|
+
// lit/shade style cloud colors (clouds.color / clouds.shade); cover = weather cloud amount * clouds.coverage, 0..1+
|
|
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 (uCloudScale, uCloudSpeed,
|
|
11
|
+
// uCloudHorizon, uCloudFade, uCloudSoft, uCloudOpacity, uCloudMul, uCloudWeights, uCloudRelief) and your clouds.uniforms.
|
|
12
|
+
import * as THREE from 'three';
|
|
13
|
+
import { closest } from '../../core/validate.js';
|
|
14
|
+
import { declareUniforms } from '../../render/uniformDecl.js';
|
|
15
|
+
|
|
16
|
+
const KINDS = ['plane', 'cumulus'];
|
|
17
|
+
|
|
18
|
+
// Defaults per kind. 'plane' values are the original look: nothing changes unless a style sets them.
|
|
19
|
+
const DEFAULTS = {
|
|
20
|
+
plane: { horizon: 0.08, fade: [0, 0.18], opacity: 0.9, soft: 0.3, scales: [2.7, 6.1], weights: [0.6, 0.3, 0.1], relief: 5 },
|
|
21
|
+
cumulus: { horizon: 0.5, fade: [0, 0.12], opacity: 0.95, soft: 0.35, scales: [2.7, 6.1], weights: [0.6, 0.3, 0.1], relief: 5 },
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// Original look: one plane projected onto the sky (cells shrink towards the horizon), 3 fixed noise layers.
|
|
25
|
+
const PLANE = `vec4 threedogClouds(vec3 d, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cov){
|
|
26
|
+
vec2 cp = d.xz / (d.y + uCloudHorizon) * uCloudScale + uCloudSpeed * time;
|
|
27
|
+
float cn = threedogNoise(cp) * uCloudWeights.x + threedogNoise(cp * uCloudMul.x + 7.0) * uCloudWeights.y + threedogNoise(cp * uCloudMul.y) * uCloudWeights.z;
|
|
28
|
+
float cloud = smoothstep(1.0 - cov, 1.0 - cov + uCloudSoft, cn) * smoothstep(uCloudFade.x, uCloudFade.y, d.y);
|
|
29
|
+
vec3 cc = mix(shade, lit, smoothstep(0.3, 0.8, cn)) * (0.35 + 0.65 * (1.0 - night));
|
|
30
|
+
return vec4(cc, cloud * uCloudOpacity);
|
|
31
|
+
}`;
|
|
32
|
+
|
|
33
|
+
// Billowy cumulus: 4-octave fbm over a gently flattened projection (overhead cells are only ~2x larger than near the horizon, so
|
|
34
|
+
// the whole sky fills with clouds), lit by sampling the density again one step towards the sun: where density falls off towards
|
|
35
|
+
// the sun the cloud faces it (bright), the far side stays in shade; thin rims glow, thick cores sit darker.
|
|
36
|
+
// Cost: 8 value-noise samples per cloudy sky pixel (plane: 3). Still one 2D pass, no ray marching.
|
|
37
|
+
const CUMULUS = `float threedogCumulusDensity(vec2 p){
|
|
38
|
+
float a = 0.5, s = 0.0;
|
|
39
|
+
for (int i = 0; i < 4; i++) { s += threedogNoise(p) * a; p = p * 2.03 + 3.7; a *= 0.5; }
|
|
40
|
+
return s / 0.9375;
|
|
41
|
+
}
|
|
42
|
+
vec4 threedogClouds(vec3 d, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cov){
|
|
43
|
+
vec2 cp = d.xz / (d.y + uCloudHorizon) * uCloudScale + uCloudSpeed * time;
|
|
44
|
+
vec2 toSun = normalize(sunDir.xz + vec2(0.0001, 0.0)) * 0.12;
|
|
45
|
+
float n0 = threedogCumulusDensity(cp), n1 = threedogCumulusDensity(cp + toSun);
|
|
46
|
+
float t = 1.0 - cov * 0.9;
|
|
47
|
+
float body = smoothstep(t, t + uCloudSoft, n0);
|
|
48
|
+
float core = smoothstep(t, t + 0.35, n0);
|
|
49
|
+
float sunSide = clamp(0.5 + (n0 - n1) * uCloudRelief, 0.0, 1.0);
|
|
50
|
+
float light = mix(sunSide, 1.0, (1.0 - core) * 0.5) * (0.55 + 0.45 * (1.0 - core * 0.5));
|
|
51
|
+
vec3 cc = mix(shade, lit, light) * (0.35 + 0.65 * (1.0 - night));
|
|
52
|
+
return vec4(cc, body * smoothstep(uCloudFade.x, uCloudFade.y, d.y) * uCloudOpacity);
|
|
53
|
+
}`;
|
|
54
|
+
|
|
55
|
+
/** Checks style.sky.clouds and returns { kind, glsl, uniforms: {name: {value}}, decl: GLSL declarations of the custom uniforms } */
|
|
56
|
+
export function resolveClouds(c) {
|
|
57
|
+
const kind = c?.kind ?? 'plane';
|
|
58
|
+
if (!KINDS.includes(kind)) throw new Error(`style.sky.clouds.kind '${kind}' is not a cloud kind; use ${KINDS.map(k => `'${k}'`).join(' | ')}` + (closest(kind, KINDS) ? ` (did you mean '${closest(kind, KINDS)}'?)` : ''));
|
|
59
|
+
let glsl = kind === 'cumulus' ? CUMULUS : PLANE;
|
|
60
|
+
if (c?.glsl != null) {
|
|
61
|
+
if (typeof c.glsl !== 'string' || !/vec4\s+threedogClouds\s*\(/.test(c.glsl)) throw new Error('style.sky.clouds.glsl must be GLSL that defines `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');
|
|
62
|
+
glsl = c.glsl;
|
|
63
|
+
}
|
|
64
|
+
const { uniforms, decl } = declareUniforms('style.sky.clouds.uniforms', c?.uniforms);
|
|
65
|
+
return { kind, glsl, uniforms, decl };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The built-in cloud uniforms (defaults of the chosen kind; style values override) */
|
|
69
|
+
export function cloudUniforms(c, kind) {
|
|
70
|
+
const d = DEFAULTS[kind], n = c?.noise || {};
|
|
71
|
+
return {
|
|
72
|
+
uCloudHorizon: { value: c?.horizon ?? d.horizon }, uCloudFade: { value: new THREE.Vector2(...(c?.fade ?? d.fade)) },
|
|
73
|
+
uCloudOpacity: { value: c?.opacity ?? d.opacity }, uCloudSoft: { value: c?.softness ?? d.soft },
|
|
74
|
+
uCloudMul: { value: new THREE.Vector2(...(n.scales ?? d.scales)) }, uCloudWeights: { value: new THREE.Vector3(...(n.weights ?? d.weights)) },
|
|
75
|
+
uCloudRelief: { value: c?.relief ?? d.relief },
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const CLOUD_UNIFORM_DECL = `uniform float uCloudHorizon; uniform vec2 uCloudFade; uniform float uCloudOpacity; uniform float uCloudSoft; uniform vec2 uCloudMul; uniform vec3 uCloudWeights; uniform float uCloudRelief;`;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Extra sky layers drawn on the dome after the clouds and stars (rainbow, aurora, a painted band): style.sky.layers / sky({ layers }).
|
|
2
|
+
// Default none, and then the dome shader text is exactly the plain one.
|
|
3
|
+
// layers: [{ glsl, uniforms?, order?, blend? }]
|
|
4
|
+
// glsl defines `vec4 threedogSkyLayer(vec3 dir, float time, vec3 sunDir, float night)`: dir = unit view direction (whole sphere,
|
|
5
|
+
// dir.y < 0 below the horizon), time = engine.uniforms.uTime seconds, sunDir toward the sun, night 0 day .. 1 night;
|
|
6
|
+
// returns (rgb, amount). Each layer's function is renamed (threedogSkyLayer0, 1...), so layers never clash.
|
|
7
|
+
// uniforms like clouds.uniforms (render/uniformDecl.js): { uK: 0.4, uTint: new THREE.Color(...), uMap: texture } -> engine.sky.uniforms.uK
|
|
8
|
+
// order draw order among layers (smaller first, default 0, ties keep list order)
|
|
9
|
+
// blend 'mix' (default: col = mix(col, rgb, amount)) | 'add' (col += rgb * amount: glows such as an aurora)
|
|
10
|
+
// In scope: threedogHash(vec2), threedogNoise(vec2) and the dome's uniforms (uTop, uHorizon, uSunColor, uCloud...).
|
|
11
|
+
import { checkOptions } from '../../core/validate.js';
|
|
12
|
+
import { declareUniforms } from '../../render/uniformDecl.js';
|
|
13
|
+
|
|
14
|
+
const KEYS = ['glsl', 'uniforms', 'order', 'blend', 'name']; // name: the layer's name for look.sky.patch('layer:<name>')
|
|
15
|
+
|
|
16
|
+
/** Check the layer list and return { uniforms, decl, body } for the dome shader (empty strings without layers) */
|
|
17
|
+
export function resolveDomeLayers(list) {
|
|
18
|
+
if (list == null) return { uniforms: {}, decl: '', body: '' };
|
|
19
|
+
if (!Array.isArray(list)) throw new Error('style.sky.layers must be an array of { glsl, uniforms?, order?, blend? }; see modules/sky/domeLayers.js');
|
|
20
|
+
const uniforms = {}, decl = [], body = [];
|
|
21
|
+
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) => {
|
|
22
|
+
const where = `style.sky.layers[${i}]`;
|
|
23
|
+
checkOptions(where, l, KEYS);
|
|
24
|
+
if (typeof l?.glsl !== 'string' || !/vec4\s+threedogSkyLayer\s*\(/.test(l.glsl))
|
|
25
|
+
throw new Error(`${where}.glsl must be GLSL that defines \`vec4 threedogSkyLayer(vec3 dir, float time, vec3 sunDir, float night)\` returning (rgb, amount 0..1)`);
|
|
26
|
+
const blend = l.blend ?? 'mix';
|
|
27
|
+
if (blend !== 'mix' && blend !== 'add') throw new Error(`${where}.blend must be 'mix' or 'add'; got '${blend}'`);
|
|
28
|
+
const u = declareUniforms(`${where}.uniforms`, l.uniforms);
|
|
29
|
+
Object.assign(uniforms, u.uniforms); decl.push(u.decl, l.glsl.replace(/\bthreedogSkyLayer\b/g, `threedogSkyLayer${n}`));
|
|
30
|
+
body.push(`\n { vec4 L = threedogSkyLayer${n}(d, uTime, uSunDir, uNight); col ${blend === 'add' ? '+= L.rgb * L.a' : '= mix(col, L.rgb, L.a)'}; }`);
|
|
31
|
+
});
|
|
32
|
+
return { uniforms, decl: decl.join('\n'), body: body.join('') };
|
|
33
|
+
}
|