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,108 @@
|
|
|
1
|
+
// look.sky: the sky dome as a look part.
|
|
2
|
+
// set({ clouds: { coverage, scale, speed, opacity, softness, color, shade }, backdrop }) live uniforms of the dome; backdrop = one flat color instead of the dome
|
|
3
|
+
// patch('clouds', glsl) the cloud function threedogClouds (clouds.js); null gives the style / built-in kind back
|
|
4
|
+
// patch('layer:<name>', glsl | { glsl, uniforms, order, blend }) add or change a named dome layer (domeLayers.js); null removes it
|
|
5
|
+
// replace(skybox name | Texture | Object3D) the dome gives way to a panorama or your own background object; null gives the dome back
|
|
6
|
+
// Layers used to be an array addressed by index (style.sky.layers); they are named now. A style's array entries are named by their `name` key, else layer0, layer1 ...
|
|
7
|
+
// 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).
|
|
8
|
+
import * as THREE from 'three';
|
|
9
|
+
import { defineLookPart, REPLACE } from '../../core/look/part.js';
|
|
10
|
+
import { resolveClouds } from './clouds.js';
|
|
11
|
+
import { resolveDomeLayers } from './domeLayers.js';
|
|
12
|
+
import { domeFragment, loadSkybox } from './shader.js';
|
|
13
|
+
import { domeFog } from './fog.js';
|
|
14
|
+
import { resolveBackdrop } from './look.js';
|
|
15
|
+
|
|
16
|
+
const LAYER = 'layer:';
|
|
17
|
+
const CLOUD_KEYS = { 'clouds.coverage': 'uCloudCover', 'clouds.scale': 'uCloudScale', 'clouds.speed': 'uCloudSpeed', 'clouds.opacity': 'uCloudOpacity',
|
|
18
|
+
'clouds.softness': 'uCloudSoft', 'clouds.color': 'uCloudColor', 'clouds.shade': 'uCloudShade' };
|
|
19
|
+
const isColorLike = v => typeof v === 'number' || typeof v === 'string' || !!v?.isColor;
|
|
20
|
+
const glslOf = v => (typeof v === 'string' ? v : v?.glsl);
|
|
21
|
+
|
|
22
|
+
/** @param {any} sky @param {object} st style.sky merged with the sky({ ... }) options */
|
|
23
|
+
export function defineSkyLook(sky, st) {
|
|
24
|
+
const e = sky.engine, scene = e.scene, U = sky.uniforms;
|
|
25
|
+
let part, added = null;
|
|
26
|
+
const layers = new Map((Array.isArray(st.layers) ? st.layers : []).map((l, i) => [l?.name ?? `layer${i}`, l]));
|
|
27
|
+
|
|
28
|
+
// The dome shader from the current clouds function and layers; throws (changing nothing) when a hook is not valid GLSL for its contract
|
|
29
|
+
const rebuild = (cloudsHook, map) => {
|
|
30
|
+
const cl = resolveClouds({ ...(st.clouds ?? {}), glsl: glslOf(cloudsHook), uniforms: { ...(st.clouds?.uniforms), ...(cloudsHook?.uniforms) } });
|
|
31
|
+
const l = resolveDomeLayers([...map.values()].map(v => (typeof v === 'string' ? { glsl: v } : v)));
|
|
32
|
+
const f = 'uFogColor' in U ? domeFog({ color: 'fog' }) : { decl: '', body: '' }; // the fog band exists only when the start fog color was not 'horizon'
|
|
33
|
+
const text = domeFragment(cl, { decl: [f.decl, l.decl].filter(Boolean).join('\n'), body: f.body + l.body });
|
|
34
|
+
return { text, uniforms: { ...cl.uniforms, ...l.uniforms } };
|
|
35
|
+
};
|
|
36
|
+
const apply = r => {
|
|
37
|
+
for (const [k, u] of Object.entries(r.uniforms)) if (!(k in U)) U[k] = u;
|
|
38
|
+
if (sky.dome.material.fragmentShader === r.text) return;
|
|
39
|
+
sky.dome.material.fragmentShader = r.text; sky.dome.material.needsUpdate = true;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const setBackdrop = v => {
|
|
43
|
+
if (v == null) { sky._backdrop = null; sky.dome.visible = !sky.skybox && !added; scene.background = sky.skybox ?? null; return; }
|
|
44
|
+
sky._backdrop = resolveBackdrop({ backdrop: v }); // the sky writes scene.background and hides the dome each frame (frame.js)
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const hooks = { clouds: { signature: 'vec4 threedogClouds(vec3 dir, float time, vec3 sunDir, float night, vec3 lit, vec3 shade, float cover)', scope: ['threedogHash', 'threedogNoise', 'uCloud* uniforms'],
|
|
48
|
+
example: 'vec4 threedogClouds(vec3 d, float t, vec3 s, float night, vec3 lit, vec3 shade, float cover){ return vec4(lit, step(0.5, threedogNoise(d.xz * 4.0)) * cover); }' },
|
|
49
|
+
[LAYER + '<name>']: { signature: 'vec4 threedogSkyLayer(vec3 dir, float time, vec3 sunDir, float night)', scope: ['threedogHash', 'threedogNoise', 'uTop', 'uHorizon', 'uSunColor ...'],
|
|
50
|
+
example: "look.sky.patch('layer:aurora', { glsl: 'vec4 threedogSkyLayer(vec3 d, float t, vec3 s, float n){ return vec4(0.2, 1.0, 0.5, n * smoothstep(0.1, 0.6, d.y) * 0.4); }', blend: 'add' })" } };
|
|
51
|
+
// layer:<name> takes any name: the spec lists one documented entry, the check accepts the prefix
|
|
52
|
+
const hookSpec = new Proxy(hooks, { has: (t, k) => k in t || (typeof k === 'string' && /^layer:[\w-]+$/.test(k)) });
|
|
53
|
+
|
|
54
|
+
const cloudDesc = { coverage: 'cloud amount 0..1+ (also follows the weather)', scale: 'cloud size (smaller = bigger clouds)', speed: 'drift [x, z] per second', opacity: 'cloud opacity',
|
|
55
|
+
softness: 'edge softness', color: 'lit side color', shade: 'shaded side color' };
|
|
56
|
+
const num = d => ({ type: 'number', min: 0, cost: 'uniform', neutral: true, desc: d });
|
|
57
|
+
part = defineLookPart(e, {
|
|
58
|
+
id: 'sky', group: 'atmosphere', module: 'sky', object: () => sky.dome, applyAtStart: false, docs: ['recipes/52-look.md', 'recipes/36-style.md'],
|
|
59
|
+
params: {
|
|
60
|
+
// all neutral: with coverage 0 (no clouds unless the style gives them) nothing of these is drawn
|
|
61
|
+
'clouds.coverage': { ...num(cloudDesc.coverage), neutral: true, default: 0 },
|
|
62
|
+
'clouds.scale': { ...num(cloudDesc.scale), neutral: true, default: 0.35 },
|
|
63
|
+
'clouds.speed': { type: 'array', default: [0.004, 0.002], neutral: true, cost: 'uniform', desc: cloudDesc.speed },
|
|
64
|
+
'clouds.opacity': { ...num(cloudDesc.opacity), neutral: true, default: 0.9 },
|
|
65
|
+
'clouds.softness': { ...num(cloudDesc.softness), neutral: true, default: 0.3 },
|
|
66
|
+
'clouds.color': { type: 'any', default: '#f4f4f4', neutral: true, cost: 'uniform', desc: cloudDesc.color },
|
|
67
|
+
'clouds.shade': { type: 'any', default: '#aaaaaa', neutral: true, cost: 'uniform', desc: cloudDesc.shade },
|
|
68
|
+
backdrop: { type: 'any', default: null, neutral: true, cost: 'uniform', desc: 'a flat color (or (sky) => color) in place of the dome: no gradient, sun, moon, stars or clouds; null = the dome',
|
|
69
|
+
check: v => (isColorLike(v) || typeof v === 'function' ? null : `must be a color (0xefebe4, '#efebe4') or (sky) => color; got ${JSON.stringify(v)}`) },
|
|
70
|
+
},
|
|
71
|
+
style: () => ({
|
|
72
|
+
'clouds.coverage': U.uCloudCover.value, 'clouds.scale': U.uCloudScale.value, 'clouds.speed': U.uCloudSpeed.value.toArray(), 'clouds.opacity': U.uCloudOpacity.value,
|
|
73
|
+
'clouds.softness': U.uCloudSoft.value, 'clouds.color': '#' + U.uCloudColor.value.getHexString(), 'clouds.shade': '#' + U.uCloudShade.value.getHexString(),
|
|
74
|
+
...(st.backdrop != null ? { backdrop: st.backdrop } : {}),
|
|
75
|
+
...(st.clouds?.glsl ? { 'hook:clouds': st.clouds.glsl } : {}),
|
|
76
|
+
...Object.fromEntries([...layers].map(([n, l]) => [`hook:${LAYER}${n}`, l])),
|
|
77
|
+
...(st.skybox ? { [REPLACE]: st.skybox } : {}),
|
|
78
|
+
}),
|
|
79
|
+
apply(v, changed) {
|
|
80
|
+
for (const k of changed) {
|
|
81
|
+
const u = CLOUD_KEYS[k];
|
|
82
|
+
if (!u) continue;
|
|
83
|
+
if (k === 'clouds.speed') U[u].value.set(v[k][0], v[k][1]);
|
|
84
|
+
else if (U[u].value?.isColor) U[u].value.set(v[k]);
|
|
85
|
+
else U[u].value = v[k];
|
|
86
|
+
}
|
|
87
|
+
if (changed.has('backdrop')) setBackdrop(v.backdrop);
|
|
88
|
+
},
|
|
89
|
+
hooks: hookSpec,
|
|
90
|
+
applyHook(name, glsl) {
|
|
91
|
+
if (name === 'clouds') { apply(rebuild(glsl, layers)); return; }
|
|
92
|
+
const n = name.slice(LAYER.length), next = new Map(layers);
|
|
93
|
+
if (glsl == null) next.delete(n); else next.set(n, glsl);
|
|
94
|
+
apply(rebuild(part.value('hook:clouds'), next)); // throws before anything changes when the layer's GLSL is not valid
|
|
95
|
+
layers.clear(); for (const [k, v] of next) layers.set(k, v);
|
|
96
|
+
},
|
|
97
|
+
validate: (k, v) => k === REPLACE && typeof v !== 'string' && !v?.isTexture && !v?.isObject3D ? 'is a skybox asset name, a THREE.Texture or a THREE.Object3D; null gives the dome back' : null,
|
|
98
|
+
replace: { accepts: 'a skybox name (equirectangular panorama asset) | a THREE.Texture | a THREE.Object3D used as the background', loses: ['the gradient dome, sun and moon discs, stars, clouds and dome layers'] },
|
|
99
|
+
applyReplace(impl) {
|
|
100
|
+
if (added) { scene.remove(added); added = null; }
|
|
101
|
+
if (impl == null) { sky.skybox = null; scene.background = sky._backdrop?.color ?? null; sky.dome.visible = !sky._backdrop; return; }
|
|
102
|
+
sky.dome.visible = false;
|
|
103
|
+
if (typeof impl === 'string') loadSkybox(sky, impl);
|
|
104
|
+
else if (impl.isTexture) { impl.mapping = THREE.EquirectangularReflectionMapping; scene.background = impl; sky.skybox = impl; }
|
|
105
|
+
else if (impl.isObject3D) { scene.add(impl); added = impl; scene.background = null; sky.skybox = null; }
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Sky clock-time / season timers (implementation of engine.sky.at / between / daily / onSeason; Sky owns one Schedule).
|
|
2
|
+
// They read sky time of day sky.timeOfDay, not game seconds; for "after N seconds / every N seconds" use engine.clock.after / every.
|
|
3
|
+
// at is a "cross a clock time" event: when time moves forward (natural flow, fast-forward, raising sky.timeOfDay) across several triggers, catchUp decides replay: 'once' fires once (default), 'all' fires all, 'skip' fires none;
|
|
4
|
+
// rewinding time (applyState to an earlier time, lowering sky.timeOfDay) and loading a save only reset the baseline, no replay. To hold a state during a time range use between.
|
|
5
|
+
import { parseClock, inFrac } from '../../core/dayTime.js';
|
|
6
|
+
import { reportError } from '../../core/errors.js';
|
|
7
|
+
|
|
8
|
+
// clock-time conversions needed every step are cached on the registered entry (recomputed only when the clock time or hours per day change)
|
|
9
|
+
function frac(o, key, hoursPerDay) {
|
|
10
|
+
const c = o._c ||= {};
|
|
11
|
+
if (c[key + 'h'] !== hoursPerDay || c[key + 'v'] !== o[key]) { c[key + 'h'] = hoursPerDay; c[key + 'v'] = o[key]; c[key] = parseClock(o[key], hoursPerDay); }
|
|
12
|
+
return c[key];
|
|
13
|
+
}
|
|
14
|
+
export class Schedule {
|
|
15
|
+
constructor(sky) {
|
|
16
|
+
this.sky = sky;
|
|
17
|
+
this.points = []; // at / daily:{ clock, fn, days, catchUp }
|
|
18
|
+
this.ranges = []; // between:{ from, to, on, off, inside }
|
|
19
|
+
this.last = null; // last sky.totalDays (null = reset baseline next step)
|
|
20
|
+
for (const name of ['engine:ready', 'save:loaded', 'state:applied']) sky.engine.events.on(name, () => this.syncRanges());
|
|
21
|
+
}
|
|
22
|
+
get size() { return this.points.length + this.ranges.length; }
|
|
23
|
+
dispose() { this.points = []; this.ranges = []; }
|
|
24
|
+
at(clock, fn, { days = null, catchUp = 'once' } = {}) {
|
|
25
|
+
const p = { clock, fn, days, catchUp };
|
|
26
|
+
this.points.push(p);
|
|
27
|
+
return { remove: () => { this.points = this.points.filter(x => x !== p); } };
|
|
28
|
+
}
|
|
29
|
+
between(from, to, { on, off } = {}) {
|
|
30
|
+
const r = { from, to, on, off, inside: null };
|
|
31
|
+
this.ranges.push(r);
|
|
32
|
+
this.syncRanges();
|
|
33
|
+
return { remove: () => { this.ranges = this.ranges.filter(x => x !== r); } };
|
|
34
|
+
}
|
|
35
|
+
/** A callback that throws is a gameplay error (errors.js), like clock timers; the other timers still run */
|
|
36
|
+
_call(fn, arg) { try { fn(arg); } catch (err) { reportError(this.sky.engine, err, 'sky timer'); } }
|
|
37
|
+
onSeason(name, fn) { return this.sky.engine.events.on('season:change', s => { if (s === name) fn(s); }); }
|
|
38
|
+
syncRanges() {
|
|
39
|
+
const t = this.sky.timeOfDay, hpd = this.sky.hoursPerDay;
|
|
40
|
+
for (const r of this.ranges) {
|
|
41
|
+
const inside = inFrac(t, frac(r, 'from', hpd), frac(r, 'to', hpd));
|
|
42
|
+
if (inside === r.inside) continue;
|
|
43
|
+
r.inside = inside;
|
|
44
|
+
const fn = inside ? r.on : r.off;
|
|
45
|
+
if (fn) this._call(fn);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Fraction of a day until the next clock mark (midnight, an at time, a between edge), in (0, 1]; engine.skip ends a segment there.
|
|
49
|
+
* A mark the clock sits exactly on counts as already crossed (it fired when time arrived), so the next one is a day away */
|
|
50
|
+
untilNext() {
|
|
51
|
+
const t = this.sky.timeOfDay, hpd = this.sky.hoursPerDay;
|
|
52
|
+
let m = 1 - t || 1;
|
|
53
|
+
const near = f => { const d = ((f - t) % 1 + 1) % 1 || 1; if (d < m) m = d; };
|
|
54
|
+
for (const p of this.points) near(frac(p, 'clock', hpd));
|
|
55
|
+
for (const r of this.ranges) { near(frac(r, 'from', hpd)); near(frac(r, 'to', hpd)); }
|
|
56
|
+
return m;
|
|
57
|
+
}
|
|
58
|
+
/** After loading a save the next step only resets the baseline, no replay */
|
|
59
|
+
rebase() { this.last = null; }
|
|
60
|
+
/** Called every fixed step after the sky advances time */
|
|
61
|
+
tick() {
|
|
62
|
+
const sky = this.sky;
|
|
63
|
+
if (this.ranges.length) this.syncRanges();
|
|
64
|
+
const cur = sky.totalDays, last = this.last;
|
|
65
|
+
this.last = cur;
|
|
66
|
+
if (last == null || cur <= last) return; // just loaded or time rewound: only reset the baseline
|
|
67
|
+
for (const p of [...this.points]) {
|
|
68
|
+
const f = frac(p, 'clock', sky.hoursPerDay);
|
|
69
|
+
const first = Math.floor(last - f) + 1, end = Math.floor(cur - f); // triggers crossed: days first..end (0-based)
|
|
70
|
+
if (end < first) continue;
|
|
71
|
+
const n = end - first + 1;
|
|
72
|
+
if (p.catchUp === 'skip' && n > 1) continue;
|
|
73
|
+
for (let d = p.catchUp === 'all' ? first : end; d <= end; d++) {
|
|
74
|
+
const day = d + 1;
|
|
75
|
+
if (p.days && !(typeof p.days === 'function' ? p.days(day) : p.days.includes(day))) continue;
|
|
76
|
+
this._call(p.fn, day);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// Dome shader (gradient + sun + moon + stars + clouds), its uniforms, and neutral fallback keyframes. Look params come from style pack style.sky.
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
import { warnOnce } from '../../core/validate.js';
|
|
4
|
+
import { NOISE_GLSL } from '../../render/effects.js';
|
|
5
|
+
import { resolveClouds, cloudUniforms, CLOUD_UNIFORM_DECL } from './clouds.js';
|
|
6
|
+
|
|
7
|
+
// Keyframes: [time 0-1, zenith color, horizon color (= fog color), light color, light intensity, ambient intensity]
|
|
8
|
+
// Neutral fallback when no style pack: pure gray (no hue), only brightness changes with time
|
|
9
|
+
export const NEUTRAL_KEYFRAMES = [
|
|
10
|
+
[0.00, 0x161616, 0x2a2a2a, 0xa8a8a8, 0.4, 0.35],
|
|
11
|
+
[0.25, 0x7c7c7c, 0xb4b4b4, 0xe4e4e4, 1.8, 0.8],
|
|
12
|
+
[0.50, 0x989898, 0xd4d4d4, 0xffffff, 3.0, 1.2],
|
|
13
|
+
[0.75, 0x7c7c7c, 0xb4b4b4, 0xe4e4e4, 1.8, 0.8],
|
|
14
|
+
[1.00, 0x161616, 0x2a2a2a, 0xa8a8a8, 0.4, 0.35],
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Check keyframes: sorted by time, from 0 to 1, no duplicate times. Anything else would extrapolate (black sky) or divide by
|
|
19
|
+
* zero (NaN colors), so it throws with the fix.
|
|
20
|
+
*/
|
|
21
|
+
export function checkKeyframes(kf) {
|
|
22
|
+
const times = Array.isArray(kf) ? kf.map(k => k?.[0]) : [];
|
|
23
|
+
const bad = times.length < 2 || times[0] !== 0 || times[times.length - 1] !== 1
|
|
24
|
+
|| kf.some(k => !Array.isArray(k) || k.length < 6) || times.some((t, i) => i > 0 && !(t > times[i - 1]));
|
|
25
|
+
if (bad) throw new Error(`style.sky.keyframes must be [time, zenith, horizon, lightColor, lightIntensity, ambientIntensity] rows sorted by time, starting at 0 and ending at 1, with no time repeated; got times [${times.join(', ')}]`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Dome uniforms from the style (st = style.sky + sky() options); time and cloud cover are the engine's (engine.uniforms) */
|
|
29
|
+
export function makeSkyUniforms(st, engineUniforms) {
|
|
30
|
+
const cl = resolveClouds(st.clouds); // throws on a bad kind / glsl / custom uniform before anything is built
|
|
31
|
+
return {
|
|
32
|
+
...cloudUniforms(st.clouds, cl.kind), ...cl.uniforms,
|
|
33
|
+
uTop: { value: new THREE.Color() }, uHorizon: { value: new THREE.Color() },
|
|
34
|
+
uSunDir: { value: new THREE.Vector3(0, 1, 0) }, uSunColor: { value: new THREE.Color() }, uNight: { value: 0 },
|
|
35
|
+
uSunSize: { value: st.sunSize ?? 900 }, uSunGlow: { value: st.sunGlow ?? 0.18 }, uSunPower: { value: st.sunBrightness ?? 6 }, uMoonPower: { value: st.moonBrightness ?? 3 },
|
|
36
|
+
uMoonSize: { value: st.moonSize ?? 1400 }, uMoonColor: { value: new THREE.Color(st.moonColor ?? 0xdcdcdc) },
|
|
37
|
+
uTime: engineUniforms.uTime, uCloud: engineUniforms.uCloud, uCloudCover: { value: st.clouds?.coverage ?? (st.clouds ? 1 : 0) },
|
|
38
|
+
uCloudScale: { value: st.clouds?.scale ?? 0.35 }, uCloudSpeed: { value: new THREE.Vector2(...(st.clouds?.speed ?? [0.004, 0.002])) },
|
|
39
|
+
uCloudColor: { value: new THREE.Color(st.clouds?.color ?? 0xf4f4f4) }, uCloudShade: { value: new THREE.Color(st.clouds?.shade ?? 0xaaaaaa) },
|
|
40
|
+
uStars: { value: st.starDensity ?? 0.0025 }, uStarScale: { value: st.starScale ?? 260 }, uCurve: { value: st.gradientCurve ?? 0.55 },
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The sky dome: a back-faced sphere that follows the camera and is scaled to 0.9 of its far plane (drawn first, no depth).
|
|
46
|
+
* extra = { decl, body }: GLSL added by fog.js (fog-colored horizon band) and domeLayers.js (style layers); empty keeps the plain shader text
|
|
47
|
+
*/
|
|
48
|
+
export function makeDome(uniforms, st, extra = { decl: '', body: '' }) {
|
|
49
|
+
const dome = new THREE.Mesh(new THREE.SphereGeometry(1, 32, 16),
|
|
50
|
+
new THREE.ShaderMaterial({ vertexShader: vert, fragmentShader: domeFragment(resolveClouds(st.clouds), extra), uniforms, side: THREE.BackSide, depthWrite: false, depthTest: false }));
|
|
51
|
+
dome.frustumCulled = false; dome.renderOrder = -1000; dome.userData.budgetTag = 'sky';
|
|
52
|
+
dome.onBeforeRender = (r, sc, cam) => {
|
|
53
|
+
dome.position.copy(cam.position); dome.scale.setScalar(/** @type {THREE.PerspectiveCamera} */ (cam).far * 0.9); dome.updateMatrixWorld();
|
|
54
|
+
};
|
|
55
|
+
return dome;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Panorama skybox (style pack sky.skybox): hides the gradient dome once the texture is wanted, becomes the scene background when loaded */
|
|
59
|
+
export function loadSkybox(sky, name) {
|
|
60
|
+
const e = sky.engine;
|
|
61
|
+
sky.dome.visible = false;
|
|
62
|
+
e.assets.texture(name).then(t => { t.mapping = THREE.EquirectangularReflectionMapping; e.scene.background = t; sky.skybox = t; })
|
|
63
|
+
.catch(err => warnOnce(err.message));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const vert = `varying vec3 vDir;
|
|
67
|
+
void main(){ vDir = normalize(position); vec4 p = projectionMatrix * modelViewMatrix * vec4(position,1.0); gl_Position = p.xyww; }`;
|
|
68
|
+
export const domeFragment = (cl, x) => `uniform vec3 uTop; uniform vec3 uHorizon; uniform vec3 uSunDir; uniform vec3 uSunColor; uniform float uNight;
|
|
69
|
+
uniform float uSunSize; uniform float uSunGlow; uniform float uSunPower; uniform float uMoonPower; uniform float uMoonSize; uniform vec3 uMoonColor; uniform float uStars; uniform float uStarScale; uniform float uCurve;
|
|
70
|
+
uniform float uTime; uniform float uCloud; uniform float uCloudCover; uniform float uCloudScale; uniform vec2 uCloudSpeed; uniform vec3 uCloudColor; uniform vec3 uCloudShade;
|
|
71
|
+
${CLOUD_UNIFORM_DECL}
|
|
72
|
+
${cl.decl}${x.decl ? '\n' + x.decl : ''}
|
|
73
|
+
varying vec3 vDir;
|
|
74
|
+
float h3(vec3 p){ p = fract(p*0.3183099+.1); p*=17.0; return fract(p.x*p.y*p.z*(p.x+p.y+p.z)); }
|
|
75
|
+
${NOISE_GLSL}
|
|
76
|
+
${cl.glsl}
|
|
77
|
+
void main(){
|
|
78
|
+
vec3 d = normalize(vDir);
|
|
79
|
+
float y = max(d.y, 0.0);
|
|
80
|
+
vec3 col = d.y < 0.0 ? uHorizon : mix(uHorizon, uTop, pow(y, uCurve));
|
|
81
|
+
float sd = max(dot(d, uSunDir), 0.0);
|
|
82
|
+
col += uSunColor * (pow(sd, uSunSize) * uSunPower + pow(sd, 12.0) * uSunGlow) * step(0.0, uSunDir.y + 0.05);
|
|
83
|
+
float md = max(dot(d, -uSunDir), 0.0);
|
|
84
|
+
col += uMoonColor * pow(md, uMoonSize) * uMoonPower * uNight;
|
|
85
|
+
vec3 g = floor(d * uStarScale);
|
|
86
|
+
// Clouds: threedogClouds() is the style's (or a built-in kind's) cloud function, see clouds.js; coverage follows weather
|
|
87
|
+
float cov = uCloud * uCloudCover;
|
|
88
|
+
if (d.y > 0.0 && cov > 0.01) {
|
|
89
|
+
vec4 cl = threedogClouds(d, uTime, uSunDir, uNight, uCloudColor, uCloudShade, cov);
|
|
90
|
+
col = mix(col, cl.rgb, cl.a);
|
|
91
|
+
}
|
|
92
|
+
col += vec3(step(1.0 - uStars, h3(g)) * uNight * smoothstep(0.0, 0.25, d.y));${x.body}
|
|
93
|
+
gl_FragColor = vec4(col, 1.0);
|
|
94
|
+
#include <tonemapping_fragment>
|
|
95
|
+
#include <colorspace_fragment>
|
|
96
|
+
}`;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Sky shadow part (mixed into Sky.prototype): shadow params, placing the shadow center at the focus (snapped to a grid or shadow pixels), updating shadows every N frames.
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
import { shadowTypeOf } from '../../core/shadowTypes.js';
|
|
4
|
+
import { checkCascades, syncCascades } from './cascades.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The shadow settings to start with: low-tier devices default to a 1024 shadow map (a quarter of the fill cost; the update rate stays,
|
|
8
|
+
* since skipping frames makes wind-swayed shadows stutter) and one shadow map (cascades redraw the casters once per cascade); the style's
|
|
9
|
+
* shadow.low overrides that, and sky({ shadow }) wins outright except for cascades, which stay at 1 on low unless its low.cascades says so
|
|
10
|
+
*/
|
|
11
|
+
export function shadowFor(tier, styleShadow = {}, optionShadow = undefined) {
|
|
12
|
+
if (optionShadow) { const { low, ...sh } = optionShadow; return tier === 'low' ? { ...sh, cascades: low?.cascades ?? 1 } : sh; }
|
|
13
|
+
const { low, ...sh } = styleShadow;
|
|
14
|
+
return tier === 'low' ? { ...sh, mapSize: Math.min(sh.mapSize ?? 2048, 1024), cascades: 1, ...low } : sh;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const shadowMethods = {
|
|
18
|
+
/** Apply shadow fields (engine.look.shadow.set(o): bias / normalBias, updateEvery, snap, ahead, type, radius, blurSamples, cascades / maxFar / fade / lightMargin / split; lookShadow.js calls this) to the sun and the cascades (look.shadow's apply; the part checked the values when it took them) */
|
|
19
|
+
_applyShadow(o) {
|
|
20
|
+
const s = this.shadow;
|
|
21
|
+
if (o.type !== undefined) shadowTypeOf(o.type, 'look.shadow.set({ type })');
|
|
22
|
+
checkCascades(this, o);
|
|
23
|
+
for (const k of Object.keys(s)) if (o[k] !== undefined) s[k] = o[k];
|
|
24
|
+
const sm = this.engine.renderer.shadowMap, sun = this.sun.shadow;
|
|
25
|
+
// validate before applying so a typo leaves the previous type in place
|
|
26
|
+
if (o.type !== undefined) { sm.type = shadowTypeOf(o.type, 'look.shadow.set({ type })'); this.engine.shadowType = o.type; }
|
|
27
|
+
else s.type = this.engine.shadowType;
|
|
28
|
+
sun.bias = s.bias; sun.normalBias = s.normalBias; sun.radius = s.radius; sun.blurSamples = s.blurSamples;
|
|
29
|
+
sm.autoUpdate = s.updateEvery <= 1;
|
|
30
|
+
syncCascades(this);
|
|
31
|
+
// needed after a type switch when autoUpdate is off: otherwise the rebuilt map stays empty until the next scheduled update
|
|
32
|
+
sm.needsUpdate = true;
|
|
33
|
+
return this;
|
|
34
|
+
},
|
|
35
|
+
/** Call after rendering: when updateEvery > 1, request a shadow update every N frames */
|
|
36
|
+
afterRender() {
|
|
37
|
+
const n = this.shadow.updateEvery;
|
|
38
|
+
if (n > 1 && ++this._shadowFrame >= n) { this._shadowFrame = 0; this.engine.renderer.shadowMap.needsUpdate = true; this._shadowAt?.copy(this.sun.target.position); }
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
/** Change shadow resolution (raise temporarily for photo mode); with cascades it is the nearest cascade's map (the sun's) */
|
|
42
|
+
setShadowMapSize(n) { const sh = this.sun.shadow; if (sh.mapSize.x === n) return; sh.mapSize.set(n, n); sh.map?.dispose(); sh.map = null; },
|
|
43
|
+
|
|
44
|
+
// Shadow center: the focus (optionally shifted ahead of the view) snapped to a grid or shadow pixels; request an update when the snapped cell changes and shadows are not updated every frame
|
|
45
|
+
_placeShadow(focus, lightDir) {
|
|
46
|
+
const S = this.shadow, tp = this.sun.target.position, cam = this.engine.camera;
|
|
47
|
+
tp.copy(focus);
|
|
48
|
+
if (S.ahead) { cam.getWorldDirection(this._ahead ??= new THREE.Vector3()); this._ahead.y = 0; if (this._ahead.lengthSq() > 1e-6) tp.addScaledVector(this._ahead.normalize(), S.ahead); }
|
|
49
|
+
let key;
|
|
50
|
+
if (S.snap === 'texel') {
|
|
51
|
+
// the light-space right and up axes (matching the shadow camera lookAt), rounded to one shadow pixel along each
|
|
52
|
+
const sc = this.sun.shadow.camera, texel = (sc.right - sc.left) / this.sun.shadow.mapSize.x;
|
|
53
|
+
const f = this._f ??= new THREE.Vector3(), r = this._r ??= new THREE.Vector3(), u = this._u ??= new THREE.Vector3();
|
|
54
|
+
f.copy(lightDir).negate();
|
|
55
|
+
r.crossVectors(f, cam.up); if (r.lengthSq() < 1e-8) r.set(1, 0, 0); r.normalize();
|
|
56
|
+
u.crossVectors(r, f);
|
|
57
|
+
const a = Math.round(tp.dot(r) / texel), b = Math.round(tp.dot(u) / texel), c = tp.dot(f);
|
|
58
|
+
tp.copy(r).multiplyScalar(a * texel).addScaledVector(u, b * texel).addScaledVector(f, c);
|
|
59
|
+
key = a + ',' + b;
|
|
60
|
+
} else {
|
|
61
|
+
const g = S.snap || 1e-3;
|
|
62
|
+
tp.x = Math.round(tp.x / g) * g; tp.z = Math.round(tp.z / g) * g;
|
|
63
|
+
key = tp.x + ',' + tp.z;
|
|
64
|
+
}
|
|
65
|
+
// when not updating every frame: update early only if the center is over 1/4 of the coverage radius from the last update (teleport, fast movement); otherwise follow the updateEvery cadence
|
|
66
|
+
if (S.updateEvery > 1 && key !== this._snapKey) {
|
|
67
|
+
const sm = this.engine.renderer.shadowMap, last = this._shadowAt ??= tp.clone();
|
|
68
|
+
if (sm.needsUpdate || last.distanceToSquared(tp) > (this.sun.shadow.camera.right / 4) ** 2) { sm.needsUpdate = true; last.copy(tp); }
|
|
69
|
+
}
|
|
70
|
+
this._snapKey = key;
|
|
71
|
+
this.sun.position.copy(tp).addScaledVector(lightDir, this.orbit.distance);
|
|
72
|
+
this.sun.target.updateMatrixWorld();
|
|
73
|
+
},
|
|
74
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// The sky() module definition (split out of Sky.js): install, per-step time, per-frame update, saves, scenario time, describe.
|
|
2
|
+
// Usage and the engine.sky API are documented in Sky.js.
|
|
3
|
+
import { Sky } from './Sky.js';
|
|
4
|
+
import { dropCascades } from './cascades.js';
|
|
5
|
+
import { timeCondition } from './calendar.js';
|
|
6
|
+
import { readParams, keysSchema } from '../../core/params.js';
|
|
7
|
+
import { parseClock } from '../../core/dayTime.js';
|
|
8
|
+
/** @import { ModuleDef } from '../../types/core' */
|
|
9
|
+
/** @import { SkyOptions } from '../../types/world' */
|
|
10
|
+
|
|
11
|
+
// Options sky() accepts: calendar (time, dayLength, day, seasons, hoursPerDay) + look overrides of style pack style.sky
|
|
12
|
+
const SKY_OPTIONS = ['time', 'dayLength', 'day', 'daysPerSeason', 'seasons', 'keyframes', 'groundTint', 'sunSize', 'sunGlow', 'sunBrightness', 'moonBrightness',
|
|
13
|
+
'moonSize', 'moonColor', 'clouds', 'starDensity', 'starScale', 'gradientCurve', 'skybox', 'shadow', 'orbitTilt', 'orbitSway', 'hoursPerDay', 'environment',
|
|
14
|
+
'sun', 'hemisphere', 'fog', 'layers', 'backdrop'];
|
|
15
|
+
const SKY_PARAMS = keysSchema(SKY_OPTIONS); // keys only: the values take several shapes (time: 'HH:MM' | 0-1), Sky checks them
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Sky, day/night, calendar -> engine.sky
|
|
19
|
+
* @param {SkyOptions} [opts]
|
|
20
|
+
* @returns {ModuleDef<Sky>}
|
|
21
|
+
*/
|
|
22
|
+
export function sky(opts = {}) {
|
|
23
|
+
readParams('sky', SKY_PARAMS, opts);
|
|
24
|
+
let s = null;
|
|
25
|
+
return {
|
|
26
|
+
name: 'sky', label: 'Sky', params: SKY_PARAMS, options: opts, stage: 'environment',
|
|
27
|
+
install(e) {
|
|
28
|
+
s = new Sky(e, opts);
|
|
29
|
+
// audio rule condition { time: 'day' | 'night' | ['18:00', '06:00'] } for music / ambience rule lists
|
|
30
|
+
e.audio.condition('time', timeCondition(s));
|
|
31
|
+
e.audio.measure('daylight', () => s.daylight); // data rules compare it: { daylight: { gt: 0.15 } } (0 at night, about 1 at noon)
|
|
32
|
+
e.saves.register('sky', { save: () => ({ time: s.timeOfDay, day: s.day }),
|
|
33
|
+
load: d => { if (d) { s.timeOfDay = d.time ?? s.timeOfDay; s.day = d.day ?? 1; s._season = s.season; } s._sched.rebase(); } });
|
|
34
|
+
return s;
|
|
35
|
+
},
|
|
36
|
+
counts() { return { timers: s.scheduled }; }, // engine.counts().sky
|
|
37
|
+
fixed(dt) { s.tick(dt); },
|
|
38
|
+
// engine.skip: segments end at clock marks, so each tick crosses at most one mark and one midnight; a skip right after loading
|
|
39
|
+
// counts from now (a step would only reset the baseline)
|
|
40
|
+
skip(dt) { s._sched.last ??= s.totalDays; s.tick(dt); },
|
|
41
|
+
frame(dt, e) { s.update(e.focus); s._envFrame(dt); },
|
|
42
|
+
afterRender() { s.afterRender(); },
|
|
43
|
+
dispose() { s._sched.dispose(); s._envOff(); s._fogOff(); dropCascades(s); },
|
|
44
|
+
// scenario param time: 'HH:MM' or 0-1 (text in the URL)
|
|
45
|
+
// scenario param season: the first day of that season (outside the last-20% blend into the next one), time of day kept
|
|
46
|
+
applyState(e, { time, season }) {
|
|
47
|
+
if (time != null) s.timeOfDay = parseClock(time, s.hoursPerDay) % 1;
|
|
48
|
+
if (season != null) {
|
|
49
|
+
const i = s.seasons.indexOf(season);
|
|
50
|
+
if (i < 0) throw new Error(`applyState({ season: '${season}' }): the calendar has ${s.seasons.length ? 'seasons ' + s.seasons.join(', ') : 'no seasons'}; ` +
|
|
51
|
+
"seasons are off by default: sky({ seasons: ['spring', 'summer', 'autumn', 'winter'] })");
|
|
52
|
+
s.day = (i ? s._ends[i - 1] : 0) + 1; s._season = s.season;
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
describe(e, ctx) {
|
|
56
|
+
Object.assign(ctx.out.time, { clock: s.clock, day: s.day, season: s.season, isDay: s.isDay, timeOfDay: Math.round(s.timeOfDay * 1000) / 1000,
|
|
57
|
+
dayLength: s.dayLength, timeScale: e.clock.timeScale });
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|