threedog 0.5.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +276 -1
- package/README.md +18 -13
- package/core/{Animator.js → assets/Animator.js} +28 -18
- package/core/{Assets.js → assets/Assets.js} +116 -61
- package/core/{Baked.js → assets/Baked.js} +16 -25
- package/core/assets/assetEntry.js +237 -0
- package/core/{assetHot.js → assets/assetHot.js} +7 -6
- package/core/{assetLoad.js → assets/assetLoad.js} +66 -29
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +23 -12
- package/core/{assetReport.js → assets/assetReport.js} +9 -15
- package/core/{namedModel.js → assets/namedModel.js} +24 -16
- package/core/{Audio.js → audio/Audio.js} +27 -24
- package/core/{audioRules.js → audio/audioRules.js} +8 -5
- package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
- package/core/{Events.js → base/Events.js} +3 -3
- package/core/{I18n.js → base/I18n.js} +10 -10
- package/core/{Random.js → base/Random.js} +5 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +154 -139
- package/core/{errorHints.js → base/errorHints.js} +9 -10
- package/core/{errors.js → base/errors.js} +9 -9
- package/core/{events.generated.js → base/events.generated.js} +2 -0
- package/core/{math.js → base/math.js} +22 -4
- package/core/{params.js → base/params.js} +3 -4
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +29 -8
- package/core/{Engine.js → engine/Engine.js} +112 -105
- package/core/{Loading.js → engine/Loading.js} +4 -2
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +4 -4
- package/core/{lifecycle.js → engine/lifecycle.js} +16 -16
- package/core/{loop.js → engine/loop.js} +80 -52
- package/core/{moduleSlots.js → engine/moduleSlots.js} +35 -10
- package/core/{moduleTypes.js → engine/moduleTypes.js} +30 -18
- package/core/{modules.js → engine/modules.js} +20 -17
- package/core/engine/page.js +125 -0
- package/core/{plugins.js → engine/plugins.js} +68 -103
- package/core/{services.js → engine/services.js} +47 -40
- package/core/{startup.js → engine/startup.js} +35 -35
- package/core/{Input.js → input/Input.js} +41 -27
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/{inputPad.js → input/inputPad.js} +1 -1
- package/core/{inputPointer.js → input/inputPointer.js} +8 -2
- package/core/{inputTouch.js → input/inputTouch.js} +1 -1
- package/core/{Budget.js → inspect/Budget.js} +23 -22
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +60 -31
- package/core/{Describe.js → inspect/Describe.js} +33 -30
- package/core/{Inspect.js → inspect/Inspect.js} +14 -9
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +8 -10
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +29 -16
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +9 -6
- package/core/inspect/UrlState.js +182 -0
- package/core/{catalog.js → inspect/catalog.js} +18 -5
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +8 -8
- package/core/inspect/describeRender.js +148 -0
- package/core/{describeText.js → inspect/describeText.js} +17 -12
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +11 -9
- package/core/inspect/pictureWriters.js +342 -0
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/{Ops.js → ops/Ops.js} +16 -11
- package/core/{control.js → ops/control.js} +13 -12
- package/core/ops/holds.js +139 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +2 -1
- package/core/{opsCheck.js → ops/opsCheck.js} +4 -5
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +7 -4
- package/core/{owned.js → ops/owned.js} +37 -37
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -27
- package/core/{stackFrames.js → ops/stackFrames.js} +17 -6
- package/core/{stacks.js → ops/stacks.js} +18 -20
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +1 -1
- package/core/{Saves.js → saves/Saves.js} +58 -36
- package/core/{saveApply.js → saves/saveApply.js} +13 -9
- package/core/{saveFiles.js → saves/saveFiles.js} +17 -15
- package/core/{saveValues.js → saves/saveValues.js} +20 -3
- package/core/{saveVersions.js → saves/saveVersions.js} +4 -17
- package/core/{session.js → saves/session.js} +31 -17
- package/core/{Rays.js → scene/Rays.js} +27 -24
- package/core/{Views.js → scene/Views.js} +15 -6
- package/core/{adaptive.js → scene/adaptive.js} +15 -8
- package/core/{canvasBox.js → scene/canvasBox.js} +2 -3
- package/core/{engineCamera.js → scene/engineCamera.js} +1 -1
- package/core/{gameLights.js → scene/gameLights.js} +24 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +4 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/{ground.js → scene/ground.js} +9 -9
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/scene/pictureSlots.js +33 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +14 -6
- package/core/{sceneMethods.js → scene/sceneMethods.js} +36 -20
- package/core/scene/stepPoses.js +55 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
- package/core/{thingOps.js → scene/thingOps.js} +4 -3
- package/core/{things.js → scene/things.js} +19 -6
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +1 -1
- package/core/scene/view.js +44 -0
- package/core/{Batching.js → stream/Batching.js} +85 -27
- package/core/{Stream.js → stream/Stream.js} +62 -33
- package/core/{batchGroups.js → stream/batchGroups.js} +18 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +41 -1
- package/core/{scatter.js → stream/scatter.js} +2 -2
- package/core/{streamSources.js → stream/streamSources.js} +12 -7
- package/core/{Commits.js → threads/Commits.js} +6 -5
- package/core/{Jobs.js → threads/Jobs.js} +12 -10
- package/core/{Threads.js → threads/Threads.js} +16 -16
- package/core/{threadPure.js → threads/threadPure.js} +7 -5
- package/core/{threadServe.js → threads/threadServe.js} +3 -3
- package/core/{Clock.js → time/Clock.js} +17 -10
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +18 -17
- package/core/{time.js → time/time.js} +18 -12
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +70 -63
- package/docs/API.md +30 -29
- package/docs/CODEMAP.md +98 -223
- package/docs/COMMANDS.md +80 -69
- package/docs/CONVENTIONS.md +87 -41
- package/docs/MIGRATING-0.7.md +39 -0
- package/docs/MIGRATING-0.8.md +169 -0
- package/docs/THREE.md +100 -49
- package/docs/api/assets.md +17 -16
- package/docs/api/audio.md +8 -7
- package/docs/api/budget.md +8 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +29 -29
- package/docs/api/characters.md +26 -19
- package/docs/api/clock.md +1 -1
- package/docs/api/collision.md +14 -11
- package/docs/api/content.md +6 -6
- package/docs/api/dialogue.md +3 -3
- package/docs/api/engine.md +82 -53
- package/docs/api/events.md +5 -3
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +9 -2
- package/docs/api/ground.md +4 -5
- package/docs/api/hud.md +4 -1
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +10 -9
- package/docs/api/interactions.md +6 -4
- package/docs/api/inventory.md +10 -11
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +7 -8
- package/docs/api/lightPool.md +2 -7
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +10 -10
- package/docs/api/occlusion.md +5 -0
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +8 -5
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +7 -1
- package/docs/api/post.md +24 -5
- package/docs/api/quests.md +3 -3
- package/docs/api/rays.md +5 -7
- package/docs/api/rigid.md +27 -18
- package/docs/api/saves.md +8 -7
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +17 -14
- package/docs/api/stream.md +7 -7
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +17 -12
- package/docs/api/terrainDraw.md +12 -0
- package/docs/api/timeline.md +2 -2
- package/docs/api/tools.md +30 -26
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +11 -5
- package/docs/api/vegetationDraw.md +10 -0
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +11 -6
- package/docs/api/weatherDraw.md +10 -0
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +38 -57
- package/docs/recipes/02-npc.md +19 -20
- package/docs/recipes/03-items-pickups.md +47 -42
- package/docs/recipes/04-quests.md +3 -4
- package/docs/recipes/05-props-bake.md +72 -66
- package/docs/recipes/06-clock-events.md +30 -21
- package/docs/recipes/07-flow-scenes-pause.md +21 -17
- package/docs/recipes/08-weather-sky.md +117 -75
- package/docs/recipes/09-materials-lights-models.md +171 -0
- package/docs/recipes/10-blender-level.md +6 -7
- package/docs/recipes/11-vehicles.md +33 -25
- package/docs/recipes/12-navmesh.md +9 -8
- package/docs/recipes/13-animation.md +50 -22
- package/docs/recipes/14-custom-module.md +20 -17
- package/docs/recipes/15-perf.md +52 -29
- package/docs/recipes/16-dev-bridge.md +47 -57
- package/docs/recipes/18-world.md +45 -30
- package/docs/recipes/19-shooting-picking.md +11 -7
- package/docs/recipes/20-content-actions-save.md +36 -37
- package/docs/recipes/21-camera.md +41 -8
- package/docs/recipes/22-shop-gold.md +0 -4
- package/docs/recipes/23-ops.md +11 -11
- package/docs/recipes/26-ui-parts.md +56 -22
- package/docs/recipes/27-net.md +0 -2
- package/docs/recipes/28-terrain.md +126 -30
- package/docs/recipes/29-grid.md +16 -7
- package/docs/recipes/30-templates.md +62 -21
- package/docs/recipes/31-audio.md +9 -9
- package/docs/recipes/32-action-game.md +32 -9
- package/docs/recipes/33-stream-sources.md +2 -2
- package/docs/recipes/34-environment-lighting.md +164 -52
- package/docs/recipes/35-picture-from-reference.md +140 -0
- package/docs/recipes/36-ground-plants.md +105 -0
- package/docs/recipes/40-scene.md +105 -30
- package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +74 -106
- package/docs/recipes/44-water-weather-hooks.md +196 -0
- package/docs/recipes/45-cascaded-shadows.md +145 -25
- package/docs/recipes/46-blender-art-route.md +21 -25
- package/docs/recipes/49-game-module-contract.md +5 -5
- package/docs/recipes/50-own-renderer.md +3 -3
- package/docs/recipes/52-around-the-picture.md +137 -0
- package/docs/recipes/53-ground-up-close.md +65 -28
- package/docs/recipes/55-mods-time-wrap.md +25 -17
- package/docs/recipes/56-webgpu-tsl.md +73 -28
- package/docs/recipes/57-control.md +47 -1
- package/docs/recipes/58-input.md +3 -0
- package/docs/recipes/59-depth-post-effects.md +5 -5
- package/docs/recipes/60-judge-the-picture.md +47 -27
- package/docs/recipes/61-deploy.md +27 -0
- package/docs/recipes/62-picture-code.md +276 -0
- package/docs/recipes/63-third-person-start.md +90 -0
- package/docs/recipes/64-particles.md +35 -0
- package/docs/recipes/65-swarm.md +140 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +9 -7
- package/examples/action/main.js +5 -4
- package/examples/action/models.js +12 -14
- package/examples/action/picture/index.js +13 -0
- package/examples/action/picture/lights.js +35 -0
- package/examples/action/picture/materials.js +8 -0
- package/examples/action/picture/palette.js +33 -0
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +18 -14
- package/examples/{sheepisland → perf-island}/assets.js +2 -2
- package/examples/{sheepisland → perf-island}/content/templates.js +1 -1
- package/examples/{sheepisland → perf-island}/content/vegetation.js +3 -1
- package/examples/{sheepisland → perf-island}/main.js +22 -16
- package/examples/{sheepisland/style → perf-island}/models.js +13 -24
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/perf-island/picture/index.js +20 -0
- package/examples/perf-island/picture/lights.js +34 -0
- package/examples/perf-island/picture/materials.js +61 -0
- package/examples/perf-island/picture/palette.js +60 -0
- package/examples/perf-island/picture/sky.js +20 -0
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/.threedog/content-index.json +1 -0
- package/examples/plain-picture/GAMEMAP.md +91 -0
- package/examples/plain-picture/main.js +48 -0
- package/examples/plain-picture/picture/index.js +21 -0
- package/examples/plain-picture/picture/lights.js +54 -0
- package/examples/plain-picture/picture/materials.js +24 -0
- package/examples/plain-picture/picture/palette.js +16 -0
- package/examples/plain-picture/picture/sky.js +37 -0
- package/examples/pullable.json +31 -9
- package/examples/rc2d/GAMEMAP.md +10 -4
- package/examples/rc2d/README.md +11 -6
- package/examples/rc2d/main.js +26 -36
- package/examples/rc2d/picture/index.js +18 -0
- package/examples/rc2d/picture/lights.js +11 -0
- package/examples/rc2d/picture/materials.js +18 -0
- package/examples/rc2d/picture/palette.js +15 -0
- package/examples/rc2d/picture/post.js +11 -0
- package/examples/rc2d/rc2d.js +18 -28
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +15 -10
- package/examples/styletest/main.js +20 -30
- package/examples/styletest/models.js +29 -29
- package/examples/styletest/params.js +1 -4
- package/examples/styletest/picture/env.js +38 -0
- package/examples/styletest/picture/index.js +16 -0
- package/examples/styletest/picture/lights.js +9 -0
- package/examples/styletest/picture/materials.js +28 -0
- package/examples/styletest/picture/palette.js +22 -0
- package/examples/techniques/contact-shadows/README.md +22 -23
- package/examples/techniques/contact-shadows/contactShadows.js +32 -16
- package/examples/techniques/contact-shadows/main.js +20 -18
- package/examples/techniques/contact-shadows/picture/index.js +14 -0
- package/examples/techniques/contact-shadows/picture/lights.js +34 -0
- package/examples/techniques/contact-shadows/picture/materials.js +12 -0
- package/examples/techniques/contact-shadows/picture/palette.js +17 -0
- package/examples/techniques/day-night-grade/README.md +13 -16
- package/examples/techniques/day-night-grade/main.js +15 -25
- package/examples/techniques/day-night-grade/picture/index.js +20 -0
- package/examples/techniques/day-night-grade/picture/lights.js +45 -0
- package/examples/techniques/day-night-grade/picture/materials.js +15 -0
- package/examples/techniques/day-night-grade/picture/palette.js +59 -0
- package/examples/techniques/day-night-grade/picture/post.js +25 -0
- package/examples/techniques/day-night-grade/picture/sky.js +33 -0
- package/examples/techniques/interior-light/README.md +16 -13
- package/examples/techniques/interior-light/interiorLight.js +19 -17
- package/examples/techniques/interior-light/main.js +31 -68
- package/examples/techniques/interior-light/picture/index.js +24 -0
- package/examples/techniques/interior-light/picture/lights.js +52 -0
- package/examples/techniques/interior-light/picture/materials.js +13 -0
- package/examples/techniques/interior-light/picture/palette.js +32 -0
- package/examples/techniques/interior-light/picture/sky.js +40 -0
- package/examples/techniques/modular-building/README.md +8 -6
- package/examples/techniques/modular-building/kit.js +2 -2
- package/examples/techniques/modular-building/main.js +9 -17
- package/examples/techniques/modular-building/picture/index.js +17 -0
- package/examples/techniques/modular-building/picture/lights.js +26 -0
- package/examples/techniques/modular-building/picture/materials.js +13 -0
- package/examples/techniques/modular-building/picture/palette.js +23 -0
- package/examples/techniques/night-lights/README.md +15 -14
- package/examples/techniques/night-lights/main.js +20 -43
- package/examples/techniques/night-lights/nightLights.js +25 -21
- package/examples/techniques/night-lights/picture/index.js +18 -0
- package/examples/techniques/night-lights/picture/lights.js +44 -0
- package/examples/techniques/night-lights/picture/materials.js +15 -0
- package/examples/techniques/night-lights/picture/palette.js +34 -0
- package/examples/techniques/night-lights/picture/post.js +9 -0
- package/examples/techniques/night-lights/picture/sky.js +36 -0
- package/examples/techniques/outlines-and-rim/README.md +2 -2
- package/examples/techniques/outlines-and-rim/main.js +15 -38
- package/examples/techniques/outlines-and-rim/outlines.js +3 -3
- package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
- package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
- package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
- package/examples/techniques/procedural-animation/README.md +6 -4
- package/examples/techniques/procedural-animation/main.js +9 -7
- package/examples/techniques/procedural-animation/picture/index.js +15 -0
- package/examples/techniques/procedural-animation/picture/lights.js +35 -0
- package/examples/techniques/procedural-animation/picture/materials.js +10 -0
- package/examples/techniques/procedural-animation/picture/palette.js +16 -0
- package/examples/techniques/procedural-animation/picture/sky.js +31 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +1 -1
- package/examples/techniques/procedural-surface/README.md +2 -0
- package/examples/techniques/procedural-surface/main.js +17 -55
- package/examples/techniques/procedural-surface/picture/index.js +14 -0
- package/examples/techniques/procedural-surface/picture/lights.js +18 -0
- package/examples/techniques/procedural-surface/picture/materials.js +34 -0
- package/examples/techniques/procedural-surface/picture/palette.js +15 -0
- package/examples/techniques/stylized-shading/README.md +13 -14
- package/examples/techniques/stylized-shading/main.js +11 -42
- package/examples/techniques/stylized-shading/picture/index.js +14 -0
- package/examples/techniques/stylized-shading/picture/lights.js +23 -0
- package/examples/techniques/stylized-shading/picture/materials.js +18 -0
- package/examples/techniques/stylized-shading/picture/palette.js +19 -0
- package/examples/techniques/stylized-shading/shading.js +2 -2
- package/examples/techniques/sun-and-key-light/README.md +20 -22
- package/examples/techniques/sun-and-key-light/keyLight.js +47 -29
- package/examples/techniques/sun-and-key-light/main.js +19 -63
- package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
- package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
- package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
- package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
- package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
- package/examples/techniques/three-looks/README.md +21 -0
- package/examples/techniques/three-looks/main.js +58 -0
- package/examples/techniques/three-looks/picture/cartoon.js +23 -0
- package/examples/techniques/three-looks/picture/cinematic.js +27 -0
- package/examples/techniques/three-looks/picture/comic.js +27 -0
- package/examples/techniques/three-looks/picture/index.js +14 -0
- package/examples/techniques/three-looks/picture/sun.js +23 -0
- package/examples/techniques/wet-road/README.md +7 -4
- package/examples/techniques/wet-road/main.js +18 -38
- package/examples/techniques/wet-road/picture/index.js +17 -0
- package/examples/techniques/wet-road/picture/lights.js +57 -0
- package/examples/techniques/wet-road/picture/materials.js +16 -0
- package/examples/techniques/wet-road/picture/palette.js +24 -0
- package/examples/techniques/wet-road/picture/sky.js +46 -0
- package/examples/webgpu-tsl/GAMEMAP.md +10 -4
- package/examples/webgpu-tsl/README.md +13 -10
- package/examples/webgpu-tsl/main.js +30 -7
- package/examples/webgpu-tsl/picture/index.js +18 -0
- package/examples/webgpu-tsl/picture/lights.js +25 -0
- package/examples/webgpu-tsl/picture/materials.js +36 -0
- package/examples/webgpu-tsl/picture/palette.js +23 -0
- package/examples/webgpu-tsl/picture/post.js +16 -0
- package/examples/webgpu-tsl/picture/sky.js +30 -0
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +16 -12
- package/examples/world/art/humanoid.js +9 -13
- package/examples/world/art/index.js +2 -2
- package/examples/world/art/models.js +3 -4
- package/examples/world/art/shapes.js +2 -2
- package/examples/world/assets.js +2 -2
- package/examples/world/content/audio.js +1 -1
- package/examples/world/content/items.js +1 -1
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +10 -10
- package/examples/world/models.js +17 -7
- package/examples/world/picture/index.js +20 -0
- package/examples/world/picture/lights.js +41 -0
- package/examples/world/picture/materials.js +34 -0
- package/examples/world/picture/palette.js +74 -0
- package/examples/world/picture/post.js +9 -0
- package/examples/world/picture/sky.js +39 -0
- package/index.d.ts +14 -22
- package/index.js +36 -36
- package/llms.txt +19 -21
- package/modules/ambience/Ambience.js +12 -9
- package/modules/calendar/Calendar.js +20 -20
- package/modules/calendar/index.js +14 -13
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +2 -2
- package/modules/camera/FixedCamera.js +14 -15
- package/modules/camera/FollowCamera.js +4 -4
- package/modules/camera/RtsCamera.js +11 -11
- package/modules/camera/common.js +51 -25
- package/modules/camera/contract.js +1 -0
- package/modules/camera/projection.js +2 -2
- package/modules/characters/Character.js +47 -39
- package/modules/characters/NPC.js +30 -22
- package/modules/characters/assetModel.js +18 -13
- package/modules/characters/astar.js +7 -5
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/contract.js +2 -2
- package/modules/characters/index.js +172 -193
- package/modules/characters/moveHelpers.js +14 -3
- package/modules/characters/movers/common.js +22 -15
- package/modules/characters/movers/manual.js +4 -1
- package/modules/characters/movers/rapier.js +7 -6
- package/modules/characters/movers/simple.js +3 -3
- package/modules/characters/movers/support.js +32 -18
- package/modules/characters/npcAvoid.js +4 -4
- package/modules/characters/npcSim.js +28 -18
- package/modules/characters/npcView.js +6 -5
- package/modules/characters/pathAsync.js +12 -10
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +108 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +19 -5
- package/modules/characters/useModel.js +5 -5
- package/modules/characters/walkTo.js +11 -17
- package/modules/collision/Collision.js +30 -22
- package/modules/collision/contract.js +15 -0
- package/modules/content/explain.js +1 -2
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +2 -2
- package/modules/content/index.js +68 -98
- package/modules/content/loader.js +14 -17
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +66 -18
- package/modules/content/packs.js +3 -3
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +35 -0
- package/modules/content/props.js +19 -14
- package/modules/content/rules.js +34 -22
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +24 -22
- package/modules/content/words.js +34 -0
- package/modules/debug/DebugPanel.js +10 -43
- package/modules/flow/contract.js +1 -1
- package/modules/flow/index.js +11 -7
- package/modules/gameplay/Container.js +12 -11
- package/modules/gameplay/Containers.js +14 -5
- package/modules/gameplay/Dialogue.js +13 -11
- package/modules/gameplay/Interactions.js +115 -27
- package/modules/gameplay/Inventory.js +11 -12
- package/modules/gameplay/Quests.js +16 -9
- package/modules/gameplay/boxOps.js +1 -1
- package/modules/gameplay/dialogueBox.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +4 -5
- package/modules/gameplay/interactionPrompt.js +1 -1
- package/modules/gameplay/interactions.contract.js +1 -1
- package/modules/gameplay/inventoryOps.js +2 -3
- package/modules/gameplay/pickups.js +81 -44
- package/modules/gameplay/questLog.js +2 -2
- package/modules/gameplay/questSave.js +3 -3
- package/modules/grid/Grid.js +1 -1
- package/modules/grid/Layer.js +16 -3
- package/modules/grid/index.js +47 -19
- package/modules/grid/preview.js +29 -20
- package/modules/grid/tiles.js +19 -23
- package/modules/hlod/index.js +38 -55
- package/modules/hud/index.js +27 -8
- package/modules/hud/parts.js +13 -11
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +12 -10
- package/modules/level/index.js +48 -152
- package/modules/level/load.js +79 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +6 -7
- package/modules/lights/index.js +34 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +88 -0
- package/modules/music/Music.js +31 -27
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +14 -0
- package/modules/nav/index.js +11 -10
- package/modules/net/Client.js +7 -7
- package/modules/net/Host.js +7 -7
- package/modules/net/Net.js +1 -1
- package/modules/net/index.js +5 -4
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +49 -25
- package/modules/particles/effect.js +27 -10
- package/modules/particles/shaders.js +2 -1
- package/modules/photo/Photo.js +26 -27
- package/modules/rigid/RigidBodies.js +66 -43
- package/modules/rigid/Vehicles.js +2 -3
- package/modules/rigid/ragdoll.js +287 -0
- package/modules/rigid/ragdollBones.js +159 -0
- package/modules/rigid/sync.js +6 -6
- package/modules/settings/Settings.js +114 -45
- package/modules/settings/apply.js +10 -10
- package/modules/settings/sections.js +16 -14
- package/modules/settings/strings.js +1 -1
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +125 -103
- package/modules/sky/clouds.js +22 -23
- package/modules/sky/dome.js +113 -0
- package/modules/sky/domeLayers.js +13 -13
- package/modules/sky/environment.js +47 -171
- package/modules/sky/fog.js +5 -180
- package/modules/sky/frame.js +42 -97
- package/modules/sky/season.js +9 -3
- package/modules/sky/shader.js +49 -44
- package/modules/sky/skyModule.js +25 -35
- package/modules/sky/tint.js +9 -11
- package/modules/swarm/Swarm.js +346 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +97 -62
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +157 -0
- package/modules/terrain/index.js +60 -88
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +4 -3
- package/modules/terrain/terrainEdit.js +32 -27
- package/modules/terrain/terrainGen.js +19 -14
- package/modules/terrain/terrainIsland.js +2 -2
- package/modules/terrain/terrainMesh.js +7 -6
- package/modules/terrain/terrainShape.js +8 -10
- package/modules/terrain/terrainShapeMain.js +3 -3
- package/modules/timeline/Timeline.js +27 -19
- package/modules/timeline/Tween.js +6 -6
- package/modules/timeline/shots.js +5 -7
- package/modules/triggers/index.js +19 -15
- package/modules/vegetation/Vegetation.js +87 -39
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +196 -0
- package/modules/vegetation/groundChunks.js +11 -31
- package/modules/vegetation/index.js +18 -16
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +140 -93
- package/modules/water/surface.js +56 -56
- package/modules/weather/Weather.js +84 -38
- package/modules/weather/particles.js +18 -10
- package/modules/weather/shaders.js +1 -1
- package/modules/weather/weatherDraw.js +145 -0
- package/modules/world/World.js +10 -10
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -12
- package/modules/world/persist.js +73 -25
- package/modules/world/pos.js +4 -4
- package/modules/world/records.js +28 -8
- package/modules/world/sim.js +4 -4
- package/modules/world/state.js +12 -5
- package/modules/world/thingSource.js +4 -2
- package/modules/world/views.js +12 -10
- package/package.json +44 -8
- package/presets.js +3 -5
- package/render/PostFX.js +233 -63
- package/render/backend.js +72 -32
- package/render/cascades.js +200 -0
- package/render/cascades.tsl.js +93 -0
- package/render/daylight.js +56 -0
- package/render/detail.js +13 -12
- package/render/effects.js +60 -42
- package/render/fuse.js +3 -3
- package/render/fx/cel.tsl.js +42 -0
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +10 -13
- package/render/fx/library.tsl.js +11 -0
- package/render/fx/lighting.tsl.js +2 -1
- package/render/fx/nodeErrors.tsl.js +2 -2
- package/render/fx/objectOrigin.tsl.js +1 -2
- package/render/fx/patchNodes.tsl.js +6 -16
- package/render/fx/postWebGPU.tsl.js +55 -28
- package/render/fx/sky.tsl.js +34 -109
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/water.tsl.js +1 -1
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +14 -0
- package/render/lighting.js +11 -8
- package/render/lightmap.js +142 -0
- package/render/lights.js +26 -204
- package/render/lit.js +24 -0
- package/render/materials.js +47 -162
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/neutral.js +23 -0
- package/render/occlusion.js +200 -0
- package/render/ownFrame.js +5 -5
- package/render/patches.js +46 -41
- package/render/postWebGL.js +19 -9
- package/render/probes.js +182 -128
- package/render/recordSweep.js +117 -0
- package/render/shaderErrors.js +10 -9
- package/render/shadowCache.tsl.js +107 -0
- package/render/shadowTypes.js +9 -0
- package/render/shadows.js +451 -0
- package/render/slots.js +11 -11
- package/render/terms.js +63 -113
- package/render/uniformDecl.js +2 -2
- package/types/core.d.ts +489 -405
- package/types/gameplay.d.ts +225 -114
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +23 -8
- package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
- package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
- package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +7 -15
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/engine/page.d.ts +24 -0
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +21 -10
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +16 -8
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +4 -3
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +4 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +37 -13
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +2 -1
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +1 -1
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +18 -16
- package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
- package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
- package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
- package/types/generated/modules/calendar/Calendar.d.ts +10 -11
- package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
- package/types/generated/modules/grid/Layer.d.ts +9 -1
- package/types/generated/modules/grid/index.d.ts +32 -8
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +14 -7
- package/types/generated/modules/sky/Sky.d.ts +101 -23
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +2 -1
- package/types/generated/modules/water/Water.d.ts +51 -3
- package/types/generated/modules/weather/Weather.d.ts +44 -10
- package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
- package/types/generated/modules/world/World.d.ts +7 -5
- package/types/generated/render/PostFX.d.ts +69 -20
- package/types/generated/render/lighting.d.ts +29 -0
- package/types/generated/render/materials.d.ts +20 -44
- package/types/generated/render/occlusion.d.ts +22 -0
- package/types/generated/render/patches.d.ts +1 -0
- package/types/generated/ui/Focus.d.ts +1 -0
- package/types/generated/ui/UI.d.ts +1 -0
- package/types/nav.d.ts +11 -11
- package/types/physics.d.ts +104 -73
- package/types/tsl.d.ts +45 -4
- package/types/world.d.ts +372 -86
- package/ui/Focus.js +21 -10
- package/ui/LoadingScreen.js +2 -2
- package/ui/Parts.js +12 -7
- package/ui/UI.js +17 -17
- package/ui/cursor.js +1 -1
- package/ui/defaults.js +3 -2
- package/ui/theme.js +36 -28
- package/ui/touchPart.js +1 -1
- package/core/UrlState.js +0 -110
- package/core/assetEntry.js +0 -106
- package/core/describeRender.js +0 -71
- package/core/holds.js +0 -134
- package/core/look/coreParts.js +0 -219
- package/core/look/part.js +0 -253
- package/core/look/points.js +0 -255
- package/core/look/report.js +0 -96
- package/core/look/shadowPart.js +0 -63
- package/core/look/state.js +0 -45
- package/core/look/write.js +0 -70
- package/core/page.js +0 -79
- package/core/shadowTypes.js +0 -16
- package/core/styleParts.js +0 -114
- package/core/util.js +0 -17
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -228
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/PERF.md +0 -245
- package/docs/api/style.md +0 -136
- package/docs/api/terrainLook.md +0 -10
- package/docs/api/vegetationLook.md +0 -10
- package/docs/api/weatherLook.md +0 -10
- package/docs/recipes/09-style.md +0 -218
- package/docs/recipes/35-style-from-reference.md +0 -153
- package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
- package/docs/recipes/37-terrain-look-hooks.md +0 -119
- package/docs/recipes/38-environment-look-hooks.md +0 -99
- package/docs/recipes/41-thing-registry.md +0 -97
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/44-water-weather-look-hooks.md +0 -144
- package/docs/recipes/47-island-snow-backdrop.md +0 -45
- package/docs/recipes/48-make-material.md +0 -75
- package/docs/recipes/52-look.md +0 -282
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/action/look.js +0 -5
- package/examples/sheepisland/.threedog/content-index.json +0 -1
- package/examples/sheepisland/style/index.js +0 -79
- package/examples/styletest/look.js +0 -11
- package/examples/techniques/day-night-grade/dayNightGrade.js +0 -76
- package/examples/webgpu-tsl/tslScene.js +0 -75
- package/examples/world/style/index.js +0 -61
- package/examples/world/style/plugins/10-bloom.js +0 -5
- package/modules/sky/cascades.js +0 -186
- package/modules/sky/cascades.tsl.js +0 -82
- package/modules/sky/look.js +0 -54
- package/modules/sky/lookFog.js +0 -76
- package/modules/sky/lookShadow.js +0 -62
- package/modules/sky/lookSky.js +0 -169
- package/modules/sky/shadow.js +0 -98
- package/modules/terrain/look.js +0 -83
- package/modules/terrain/lookGround.js +0 -66
- package/modules/vegetation/look.js +0 -119
- package/modules/vegetation/lookWind.js +0 -98
- package/modules/water/look.js +0 -91
- package/modules/water/surfaceDefaults.js +0 -3
- package/modules/weather/look.js +0 -74
- package/modules/weather/weatherLook.js +0 -135
- package/render/lookGlow.js +0 -139
- package/render/lookSurface.js +0 -224
- package/render/postLook.js +0 -164
- package/render/surface.js +0 -105
- package/types/generated/core/page.d.ts +0 -18
- package/types/generated/modules/weather/weatherLook.d.ts +0 -12
- package/types/style.d.ts +0 -671
- /package/core/{Vars.js → base/Vars.js} +0 -0
- /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
- /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
- /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
- /package/core/{actor.js → ops/actor.js} +0 -0
- /package/core/{opsFail.js → ops/opsFail.js} +0 -0
- /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
- /package/core/{saveIds.js → saves/saveIds.js} +0 -0
- /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
- /package/core/{cells.js → stream/cells.js} +0 -0
- /package/core/{streamCells.js → stream/streamCells.js} +0 -0
- /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
- /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
// Day-night lighting and color grade: one set of keyframes over the day for the sky (sun / moon, hemisphere, fog), exposure, a post color grade,
|
|
3
|
-
// and the game's own lamps. Technique example (README.md next to this file); copy and adapt: the numbers are a neutral starting point, the
|
|
4
|
-
// colors of your game come from its DESIGN.md look, not from here.
|
|
5
|
-
import { lut } from '@threedog/post-effects';
|
|
6
|
-
|
|
7
|
-
/** Sky keyframes: [time 0-1, zenith, horizon (= fog color), sun color (the moon at night), sun intensity, ambient intensity] */
|
|
8
|
-
export const SKY = [
|
|
9
|
-
[0.00, 0x0d1626, 0x1f2c44, 0x8fa4d4, 0.35, 0.26], // night: the "sun" row is moonlight, blue and weak; ambient keeps a floor
|
|
10
|
-
[0.21, 0x172036, 0x3a4058, 0x9aa8d4, 0.35, 0.26],
|
|
11
|
-
[0.26, 0x55688c, 0xd09c7c, 0xffb27c, 1.2, 0.6], // sunrise: warm sun, horizon warm, zenith still cool (the contrast IS the look)
|
|
12
|
-
[0.33, 0x6d92c2, 0xc6d2dc, 0xfff0dc, 2.4, 0.9],
|
|
13
|
-
[0.50, 0x6e98ce, 0xcfdae4, 0xfffaf2, 3.0, 1.1], // noon: sun 3 + hemi 1.1 ~ pi: mid-tone albedos show at their own value
|
|
14
|
-
[0.68, 0x6a8ebe, 0xd4d0c6, 0xfff0d8, 2.6, 1.0],
|
|
15
|
-
[0.73, 0x4c5c86, 0xdc9c6c, 0xffa264, 1.6, 0.7], // dusk: warmth in the LIGHT color, ambient drops so shadows turn cool by contrast
|
|
16
|
-
[0.78, 0x222e4c, 0x5c5068, 0x9aa6d4, 0.35, 0.32], // blue hour: the moon row again, a little more ambient than deep night
|
|
17
|
-
[1.00, 0x0d1626, 0x1f2c44, 0x8fa4d4, 0.35, 0.26],
|
|
18
|
-
];
|
|
19
|
-
/** Exposure over the day [time, exposure]: lifted at night so the moonlit scene reads, but never back to day brightness */
|
|
20
|
-
export const EXPOSURE = [[0, 1.15], [0.22, 1.15], [0.3, 1.0], [0.7, 1.0], [0.77, 1.1], [1, 1.15]];
|
|
21
|
-
/** Color grade over the day [time, temperature (-1 cool..1 warm), saturation, contrast] (the lut() post effect's params) */
|
|
22
|
-
export const GRADE = [
|
|
23
|
-
[0.00, -0.45, 0.72, 1.06], // night: cooler and less saturated (eyes lose color in the dark), a touch of contrast keeps edges
|
|
24
|
-
[0.22, -0.3, 0.8, 1.04],
|
|
25
|
-
[0.28, 0.35, 0.95, 1.0],
|
|
26
|
-
[0.40, 0, 1, 1],
|
|
27
|
-
[0.65, 0, 1, 1],
|
|
28
|
-
[0.73, 0.5, 0.9, 1.04], // dusk: warm, and saturation DOWN as warmth goes up, or oranges clip into neon
|
|
29
|
-
[0.79, -0.25, 0.78, 1.05],
|
|
30
|
-
[1.00, -0.45, 0.72, 1.06],
|
|
31
|
-
];
|
|
32
|
-
/** Lamps: fully on below this daylight (0 night .. 1 noon), fading in above it */
|
|
33
|
-
export const LAMPS = { onBelow: 0.02, offAbove: 0.35 }; // daylight 0.35 is about 16:40: windows and lamps come on before dark, as people switch them on
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* The style fragment that carries the keyframes: createEngine({ style: [yourStyle, dayNightStyle()] }) or merge the keys into your own.
|
|
37
|
-
* The grade is a look plugin of this fragment (the shape a plugins/ file exports), so it reaches the chain through look.post.add like any effect
|
|
38
|
-
*/
|
|
39
|
-
export function dayNightStyle() {
|
|
40
|
-
return { name: 'dayNight', sky: { keyframes: SKY, moonColor: 0xc8d4f0 }, exposure: EXPOSURE, plugins: { 'lut.js': { default: lut({ enabled: true }) } } };
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** Linear interpolation over [[t, ...values]] rows sorted by t, wrapping at 1 */
|
|
44
|
-
export function sample(rows, t) {
|
|
45
|
-
let i = rows.findIndex(r => r[0] > t);
|
|
46
|
-
if (i <= 0) i = i === 0 ? 0 : rows.length - 1;
|
|
47
|
-
const a = rows[Math.max(0, i - 1)], b = rows[i], k = b[0] === a[0] ? 0 : (t - a[0]) / (b[0] - a[0]);
|
|
48
|
-
return a.slice(1).map((v, j) => v + (b[j + 1] - v) * Math.min(1, Math.max(0, k)));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Drive the grade and the game's lamps from engine.calendar every frame. Lamps: [{ light?: THREE.Light, material?: { emissiveIntensity },
|
|
53
|
-
* intensity, emissive }]: full values at night. The grade is written through look.post (owner 'day-night'), only when it moved, so
|
|
54
|
-
* describe() shows who set it and the fused post shader is not refreshed every frame (the same owner overwrites its keys). Returns { remove(), level() }.
|
|
55
|
-
* @param {import('threedog').Engine} engine
|
|
56
|
-
* @param {{ lamps?: { light?: any, material?: any, intensity?: number, emissive?: number }[] }} [o]
|
|
57
|
-
*/
|
|
58
|
-
export function followDayNight(engine, { lamps = [] } = {}) {
|
|
59
|
-
let last = null, level = 0, post = null;
|
|
60
|
-
const smooth = (/** @type {number} */ x) => x * x * (3 - 2 * x);
|
|
61
|
-
const frame = engine.onFrame(() => {
|
|
62
|
-
const cal = /** @type {any} */ (engine).calendar, t = cal.timeOfDay;
|
|
63
|
-
const [temperature, saturation, contrast] = sample(GRADE, t);
|
|
64
|
-
if (!last || Math.abs(last[0] - temperature) + Math.abs(last[1] - saturation) + Math.abs(last[2] - contrast) > 0.004) {
|
|
65
|
-
last = [temperature, saturation, contrast];
|
|
66
|
-
post = engine.look.post.set({ 'lut.temperature': temperature, 'lut.saturation': saturation, 'lut.contrast': contrast }, { owner: 'day-night' });
|
|
67
|
-
}
|
|
68
|
-
level = 1 - smooth(Math.min(1, Math.max(0, (cal.daylight - LAMPS.onBelow) / (LAMPS.offAbove - LAMPS.onBelow))));
|
|
69
|
-
for (const l of lamps) {
|
|
70
|
-
// intensity only, never visible = false: a light count change recompiles every lit material (a stall at dusk)
|
|
71
|
-
if (l.light) l.light.intensity = (l.intensity ?? 1) * level;
|
|
72
|
-
if (l.material) l.material.emissiveIntensity = (l.emissive ?? 1) * level;
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
return { remove() { frame.remove(); post?.remove(); }, level: () => level };
|
|
76
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
// A whole small scene on the WebGPU route, every material a three.js NodeMaterial written in TSL: ground, wind-blown grass, one material of
|
|
3
|
-
// the game's own (a lantern that lights up as the day ends) and one post effect (soft scanlines). README.md next to this file; copy and adapt.
|
|
4
|
-
// What it shows: the engine's shader functions (threedog/tsl) are plain TSL functions called inside your own nodes, and the engine's values
|
|
5
|
-
// (time, wind, daylight, season) reach your nodes through uniforms(engine). Nothing here is a style: colors are neutral starting points.
|
|
6
|
-
// Needs: import 'threedog/tsl' at the top of the game's main.js and createEngine({ renderer: 'webgpu' }) (or your own WebGPURenderer).
|
|
7
|
-
import * as THREE from 'three';
|
|
8
|
-
import { MeshLambertNodeMaterial, MeshStandardNodeMaterial } from 'three/webgpu';
|
|
9
|
-
import { color, float, mix, positionGeometry, positionLocal, positionWorld, sin, smoothstep, uv } from 'three/tsl';
|
|
10
|
-
import { wind, objectOrigin, cloudShadow, season, detailNoise, uniforms } from 'threedog/tsl';
|
|
11
|
-
|
|
12
|
-
export const PARAMS = {
|
|
13
|
-
size: 40, // m, side of the square ground
|
|
14
|
-
grass: 1500, // blades (one InstancedMesh: one draw call however many)
|
|
15
|
-
sway: 0.25, // wind amplitude, meters per meter of blade height (times engine.uniforms.uWind, which weather changes)
|
|
16
|
-
scanlines: 0.08, // post effect strength 0..1; 0 = the effect stays in the chain but does nothing
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Build the scene into engine.scene. Call before engine.start().
|
|
21
|
-
* @param {import('threedog').Engine} engine
|
|
22
|
-
* @param {Partial<typeof PARAMS>} [o]
|
|
23
|
-
* @returns {{ ground: THREE.Mesh, grass: THREE.InstancedMesh, lantern: THREE.Mesh, post: { remove(): void } }}
|
|
24
|
-
*/
|
|
25
|
-
export function createTslScene(engine, o = {}) {
|
|
26
|
-
const P = { ...PARAMS, ...o }, u = uniforms(engine);
|
|
27
|
-
|
|
28
|
-
// Ground: two earth tones mixed by the engine's detail noise (a world-space pattern, so tiles never repeat), tinted by the season and
|
|
29
|
-
// darkened under the drifting cloud shadows. All three are functions of the position; none of them needs a texture.
|
|
30
|
-
const patches = detailNoise(positionWorld.xz.mul(0.15), 0, 3).a;
|
|
31
|
-
const groundMat = new MeshStandardNodeMaterial({ roughness: 1 });
|
|
32
|
-
groundMat.colorNode = season(mix(color(0x5f7a3c), color(0x857452), smoothstep(0.35, 0.65, patches)), 1).mul(cloudShadow(positionWorld));
|
|
33
|
-
const ground = new THREE.Mesh(new THREE.PlaneGeometry(P.size, P.size).rotateX(-Math.PI / 2), groundMat);
|
|
34
|
-
ground.receiveShadow = true;
|
|
35
|
-
ground.name = 'ground';
|
|
36
|
-
|
|
37
|
-
// Grass: one blade shape drawn many times. wind() returns an object-space offset; positionGeometry is the blade before the instance
|
|
38
|
-
// transform, objectOrigin() each instance's own world origin (so neighbours sway out of phase). positionNode is also what three's shadow
|
|
39
|
-
// pass reads, so the shadows sway with the blades without a second material.
|
|
40
|
-
// Instances are only moved, never rotated or scaled: then the object-space offset is already right after the instance transform. Rotated
|
|
41
|
-
// instances: use the patch form applyEffects(mat, { wind }) (recipe 56, section 5), which turns the offset with each instance.
|
|
42
|
-
const blade = new THREE.PlaneGeometry(0.07, 0.5, 1, 3).translate(0, 0.25, 0);
|
|
43
|
-
const grassMat = new MeshLambertNodeMaterial({ side: THREE.DoubleSide });
|
|
44
|
-
grassMat.colorNode = season(mix(color(0x2f4a1c), color(0x8fb052), uv().y), 0);
|
|
45
|
-
grassMat.positionNode = positionLocal.add(wind(positionGeometry, objectOrigin(), float(P.sway)));
|
|
46
|
-
const grass = new THREE.InstancedMesh(blade, grassMat, P.grass);
|
|
47
|
-
const m = new THREE.Matrix4(), r = engine.random, half = P.size * 0.45;
|
|
48
|
-
for (let i = 0; i < P.grass; i++) grass.setMatrixAt(i, m.makeTranslation(r.range(-half, half), 0, r.range(-half, half)));
|
|
49
|
-
grass.castShadow = true;
|
|
50
|
-
grass.name = 'grass';
|
|
51
|
-
|
|
52
|
-
// The game's own material: a lantern whose glow follows the engine's daylight (1 at noon, 0 at night) and flickers with engine time.
|
|
53
|
-
// uniforms(engine) are nodes over engine.uniforms: when the sky moves uDaylight, this node moves with it; nothing to update per frame.
|
|
54
|
-
const night = float(1).sub(u.uDaylight);
|
|
55
|
-
const flicker = sin(u.uTime.mul(7)).mul(0.08).add(0.92);
|
|
56
|
-
const lanternMat = new MeshStandardNodeMaterial({ color: 0x3a2a18, roughness: 0.6 });
|
|
57
|
-
lanternMat.emissiveNode = color(0xffa040).mul(smoothstep(0.3, 0.9, night).mul(3).mul(flicker));
|
|
58
|
-
const lantern = new THREE.Mesh(new THREE.OctahedronGeometry(0.35, 1), lanternMat);
|
|
59
|
-
lantern.position.set(0, 1.2, 0);
|
|
60
|
-
lantern.castShadow = true;
|
|
61
|
-
lantern.name = 'lantern';
|
|
62
|
-
|
|
63
|
-
engine.scene.add(ground, grass, lantern);
|
|
64
|
-
|
|
65
|
-
// Post on the WebGPU route: an effect gives node(input, ctx) => color node. input is the picture so far; slot 'ldr' runs after tone
|
|
66
|
-
// mapping, so the values are display colors 0..1. ctx.p holds a live uniform per number param: look.post.set({ 'scanlines.amount': 0.2 })
|
|
67
|
-
// changes it without rebuilding the chain. A three.js Pass (create) does not run on WebGPURenderer.
|
|
68
|
-
const post = engine.look.post.add({ name: 'scanlines', slot: 'ldr', params: { amount: P.scanlines },
|
|
69
|
-
node: (input, { tsl: T, p }) => {
|
|
70
|
-
const line = T.sin(T.screenCoordinate.y.mul(Math.PI)).mul(0.5).add(0.5); // 0..1 every other device pixel row
|
|
71
|
-
return T.vec4(input.rgb.mul(T.float(1).sub(p.amount.mul(line))), input.a);
|
|
72
|
-
} });
|
|
73
|
-
|
|
74
|
-
return { ground, grass, lantern, post };
|
|
75
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
// The world example's look: one folder = one style (recipes/09-style.md). Starting values only; the game and effects change them on top
|
|
2
|
-
// (engine.look.<part>.set, weather, settings). The trees, rocks and the humanoid body are this example's art (../art/), not part of the look:
|
|
3
|
-
// the material roles below decide how they are shaded.
|
|
4
|
-
// A style folder also brings look plugins (a sky, a post effect, a material per role...): each file the same shapes as the game's plugins/
|
|
5
|
-
// folder. This one brings its bloom that way (plugins/10-bloom.js); a Vite game lists the folder with import.meta.glob('./plugins/*.js', { eager: true }).
|
|
6
|
-
import * as bloom from './plugins/10-bloom.js';
|
|
7
|
-
import { PALETTE } from '../art/models.js';
|
|
8
|
-
|
|
9
|
-
/** @type {import('threedog').Style} */
|
|
10
|
-
export default {
|
|
11
|
-
name: 'world',
|
|
12
|
-
exposure: 1.05,
|
|
13
|
-
toneMapping: 'aces',
|
|
14
|
-
background: 0xcfe6f2,
|
|
15
|
-
plugins: { './plugins/10-bloom.js': bloom },
|
|
16
|
-
|
|
17
|
-
// the material per role: look.materials' style layer (makeMaterial(role) reads it; the game's look.materials.set goes on top)
|
|
18
|
-
materials: {
|
|
19
|
-
default: { type: 'lambert' },
|
|
20
|
-
water: { type: 'phong', shininess: 90, specular: 0x9ac8e0 },
|
|
21
|
-
pickup: { flatShading: true, emissive: 0x403418 }, // the item's own color is the base color
|
|
22
|
-
// the roles the humanoid body uses (art/humanoid.js)
|
|
23
|
-
cloth: { flatShading: true, color: 0xd9774a }, skin: { flatShading: true, color: 0xf1c9a5 },
|
|
24
|
-
trousers: { flatShading: true, color: 0x3f4a5c }, hair: { flatShading: true, color: 0x4a3426 },
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
palette: PALETTE, // the colors the procedural art reads (art/models.js); style: [style, { palette: { leaf } }] retints every tree
|
|
28
|
-
clouds: { shadow: 0.55, scale: 0.006, speed: [0.012, 0.006] },
|
|
29
|
-
|
|
30
|
-
// ground type colors; the type names come from terrainPreset() of @threedog/terrain-noise
|
|
31
|
-
terrain: {
|
|
32
|
-
config: { shading: 'flat' },
|
|
33
|
-
colors: { sand: 0xe2cf9c, meadowA: 0x95c45e, meadowB: 0x80b350, forestA: 0x6aa04a, forestB: 0x5a9142, savannaA: 0xc9bd6e, savannaB: 0xb3a85c,
|
|
34
|
-
wetland: 0x6f9a5a, riverbank: 0x8fb06a, highGrass: 0x60954a, rock: 0x8f897d, rockDark: 0x77726a, snow: 0xf1efe8 },
|
|
35
|
-
biomeColors: { beach: ['sand'], snow: ['snow'], rock: ['rock', 'rockDark'], riverbank: ['riverbank', 'meadowA'], wetland: ['wetland', 'meadowB'],
|
|
36
|
-
savanna: ['savannaA', 'savannaB'], forest: ['forestA', 'forestB'], highland: ['highGrass', 'meadowB'], meadow: ['meadowA', 'meadowB'] },
|
|
37
|
-
steep: [{ maxNormalY: 0.62, colors: ['rockDark'] }, { maxNormalY: 0.78, colors: ['rock', 'rockDark'] }],
|
|
38
|
-
},
|
|
39
|
-
|
|
40
|
-
// [time 0-1, zenith, horizon (= fog), sun color, sun intensity, ambient intensity]
|
|
41
|
-
sky: {
|
|
42
|
-
keyframes: [
|
|
43
|
-
[0.00, 0x0b1026, 0x1d2747, 0x8fa3d6, 0.45, 0.35],
|
|
44
|
-
[0.25, 0x6f8ec4, 0xf0b48c, 0xffb27a, 1.90, 0.80],
|
|
45
|
-
[0.50, 0x4f95d8, 0xc8e4f6, 0xffffff, 3.00, 1.20],
|
|
46
|
-
[0.75, 0x5a6fb0, 0xf2a07a, 0xff9a5c, 1.90, 0.80],
|
|
47
|
-
[1.00, 0x0b1026, 0x1d2747, 0x8fa3d6, 0.45, 0.35],
|
|
48
|
-
],
|
|
49
|
-
groundTint: 0x4d5a34,
|
|
50
|
-
clouds: { color: 0xf8f6f0, shade: 0xb0b8c4, coverage: 1, scale: 0.35, speed: [0.004, 0.002] },
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
water: { color: 0x4f9cc0, opacity: 0.85, flat: true, fresnel: 0.5 },
|
|
54
|
-
pickup: { color: 0xf0d27a, size: 0.25, lift: 0.4 },
|
|
55
|
-
ui: { bg: 'rgba(24,22,18,.9)', fg: '#f3eee2', muted: '#a8a294', accent: '#f0b450', line: 'rgba(255,255,255,.15)', radius: '12px' },
|
|
56
|
-
particles: {
|
|
57
|
-
dust: { max: 200, lifetime: [0.5, 1.1], speed: [0.6, 1.8], direction: [0, 1, 0], spread: 1.2, gravity: -1.5, drag: 2, size: [0.25, 0.6], color: [0xd8c8a0, 0xc8b890], opacity: [0.6, 0] },
|
|
58
|
-
smoke: { max: 120, rate: 6, lifetime: [3, 5], speed: [0.4, 0.8], direction: [0.2, 1, 0], spread: 0.25, gravity: 0.15, drag: 0.4, size: [0.6, 2.2], color: [0xc8c4bc, 0xe8e6e2], opacity: [0.55, 0] },
|
|
59
|
-
leaves: { max: 150, lifetime: [3, 6], speed: [0.3, 1], direction: [1, -0.4, 0.3], spread: 1, gravity: -0.6, drag: 1.2, size: [0.18, 0.18], color: [0xd99a4a, 0xb86a30], opacity: [1, 0], spin: 3 },
|
|
60
|
-
},
|
|
61
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
// The world look's bloom: a post effect plugin of the style (look.post.add puts it in the chain; look.post.set({ bloom: false }) or
|
|
2
|
-
// engine.plugins.off('world/10-bloom') turns it off). Costly: starts off on low-tier devices.
|
|
3
|
-
import { bloom } from '@threedog/post-effects';
|
|
4
|
-
|
|
5
|
-
export default bloom({ strength: 0.35, radius: 0.5, threshold: 0.85 });
|
package/modules/sky/cascades.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
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. 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 visits only what entered the scene since the last one (core/sceneDelta.js: an add at any depth, or
|
|
13
|
-
// mesh.material = x) and patches lit materials it has not seen (one Map lookup per mesh); the whole scene is walked once, when they turn on.
|
|
14
|
-
// - Which materials (user decision 4, option A, 2026-11-02): every BUILT-IN lit type, the game's own `new` materials too. This is the one named
|
|
15
|
-
// exception to "the engine does not change what it did not create": unpatched, a lit material is lit by every cascade light (N times as
|
|
16
|
-
// bright, doubled shadows), so leaving it alone is not neutral, it is a wrong picture. describe().owned lists the game materials it patched.
|
|
17
|
-
// A ShaderMaterial with lights: true is the game's own shader code, so it is never patched silently: one warning names
|
|
18
|
-
// engine.look.shadow.include(mat), which opts it in.
|
|
19
|
-
// - csm.update() runs only on frames whose shadow maps re-render (shadow.updateEvery), else lights move while the maps stay old.
|
|
20
|
-
// On WebGPURenderer all of the above is replaced by three's CSMShadowNode on the sun (cascades.tsl.js, registered by threedog/tsl): one light,
|
|
21
|
-
// so no patch, no scene walk, and look.shadow.include() does nothing. This file only hands over to it, so WebGL bundles never load three/webgpu.
|
|
22
|
-
import * as THREE from 'three';
|
|
23
|
-
import { CSM } from 'three/addons/csm/CSM.js';
|
|
24
|
-
import { CSMShader } from 'three/addons/csm/CSMShader.js';
|
|
25
|
-
import { patchMaterial, unpatchMaterial, isEngineMade } from '../../render/patches.js';
|
|
26
|
-
|
|
27
|
-
import { warnOnce } from '../../core/validate.js';
|
|
28
|
-
import { sceneVisitor } from '../../core/sceneDelta.js';
|
|
29
|
-
import { codedError } from '../../core/errorHints.js';
|
|
30
|
-
import { setShadowUpdate, shadowUpdatePending, isWebGPU, webgpuPart } from '../../render/backend.js';
|
|
31
|
-
import { shadowsOn } from '../../core/look/shadowPart.js';
|
|
32
|
-
|
|
33
|
-
const LIT = new Set(['MeshLambertMaterial', 'MeshPhongMaterial', 'MeshStandardMaterial', 'MeshPhysicalMaterial', 'MeshToonMaterial']);
|
|
34
|
-
const litShader = m => m.isShaderMaterial && m.lights && m.fragmentShader.includes('#include <lights_fragment_begin>');
|
|
35
|
-
/** ShaderMaterials the game opted in with engine.look.shadow.include(mat) (per engine: the sky owns it) */
|
|
36
|
-
const optedIn = sky => sky._csmInclude ??= new WeakSet();
|
|
37
|
-
/**
|
|
38
|
-
* engine.look.shadow.include(material): let the cascades patch a ShaderMaterial (lights: true) of yours. Built-in lit materials need nothing.
|
|
39
|
-
* @example engine.look.shadow.include(myLitShaderMaterial);
|
|
40
|
-
*/
|
|
41
|
-
export function includeInCascades(sky, m) {
|
|
42
|
-
if (!m?.isMaterial) throw codedError('sky-option', `engine.look.shadow.include(material): needs a three.js Material; got ${m}. Example: engine.look.shadow.include(myShaderMaterial)`);
|
|
43
|
-
if (m.isShaderMaterial && !litShader(m)) throw codedError('sky-option', "engine.look.shadow.include(material): this ShaderMaterial has no lights: true + '#include <lights_fragment_begin>', so the cascades cannot reach it; build it on THREE.ShaderLib's lit shaders, or leave it out");
|
|
44
|
-
if (isWebGPU(sky.engine.renderer)) { // the cascades are the sun's shadow node there: every material is lit once without opting in
|
|
45
|
-
warnOnce('engine.look.shadow.include(mat) does nothing on WebGPURenderer: cascaded shadows there are one light (three CSMShadowNode) and patch no material');
|
|
46
|
-
return m;
|
|
47
|
-
}
|
|
48
|
-
optedIn(sky).add(m);
|
|
49
|
-
if (sky.csm?.mats.has(m)) sky.csm.fit(m); // already looked at and left alone: patch it now (fit is per material, so no scene walk)
|
|
50
|
-
return m;
|
|
51
|
-
}
|
|
52
|
-
const lit = (sky, m) => {
|
|
53
|
-
if (LIT.has(m.type)) return true;
|
|
54
|
-
if (!litShader(m)) return false;
|
|
55
|
-
if (optedIn(sky).has(m)) return true;
|
|
56
|
-
warnOnce(`cascaded shadows: engine.look.shadow.include(mat) opts ShaderMaterial '${m.name || m.uuid.slice(0, 8)}' in. Until then it has lights: true and is lit by all ` +
|
|
57
|
-
`${sky.csm?.lights.length ?? 'the'} cascade lights (too bright, doubled shadows): the engine does not patch your own shader code unasked`);
|
|
58
|
-
return false;
|
|
59
|
-
};
|
|
60
|
-
const SPLITS = ['practical', 'uniform', 'logarithmic'];
|
|
61
|
-
const STRINGS = {
|
|
62
|
-
count: 'look.shadow.set({ cascades }): a whole number 1 (one shadow map, the default) to 4; got {got}',
|
|
63
|
-
split: "look.shadow.set({ split }): 'practical' (default) | 'uniform' | 'logarithmic' | (count, near, far, out) => void; got {got}",
|
|
64
|
-
maxFar: 'look.shadow.set({ maxFar }): meters from the camera that cascades cover, a number > 0; got {got}',
|
|
65
|
-
noSun: "look.shadow.set({ cascades }): cascaded shadows split the engine sun's shadow, and sky({ sun: false }) has no engine sun. " +
|
|
66
|
-
"With your own lights use three's CSM addon on them, or keep sun: true / 'manual'",
|
|
67
|
-
};
|
|
68
|
-
const bad = (k, v) => { throw codedError('sky-option', STRINGS[k].replace('{got}', JSON.stringify(v) ?? String(v))); };
|
|
69
|
-
|
|
70
|
-
/** Throw on cascade fields a look.shadow.set call gets wrong, before anything is applied */
|
|
71
|
-
export function checkCascades(sky, o) {
|
|
72
|
-
if (o.cascades !== undefined && !(Number.isInteger(o.cascades) && o.cascades >= 1 && o.cascades <= 4)) bad('count', o.cascades);
|
|
73
|
-
if (o.split !== undefined && typeof o.split !== 'function' && !SPLITS.includes(o.split)) bad('split', o.split);
|
|
74
|
-
if (o.maxFar !== undefined && !(o.maxFar > 0)) bad('maxFar', o.maxFar);
|
|
75
|
-
if (o.cascades > 1 && sky._drive.sun === false) bad('noSun');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// The addon's split / frustum / texel-snapped placement, with the sun as cascade 0 and the chunk swap left to the 'csm' patch
|
|
79
|
-
class SkyCSM extends CSM {
|
|
80
|
-
constructor(sky, S) {
|
|
81
|
-
const e = sky.engine, custom = typeof S.split === 'function';
|
|
82
|
-
super({ camera: e.camera, parent: e.scene, cascades: S.cascades, maxFar: S.maxFar, mode: custom ? 'custom' : S.split, customSplitsCallback: custom ? S.split : undefined,
|
|
83
|
-
shadowMapSize: sky._sun.shadow.mapSize.x, shadowBias: S.bias, lightMargin: S.lightMargin, lightNear: 1, lightFar: S.lightMargin + 2 * S.maxFar });
|
|
84
|
-
const first = this.lights[0];
|
|
85
|
-
this.parent.remove(first, first.target); first.dispose();
|
|
86
|
-
this.lights[0] = sky._sun;
|
|
87
|
-
// uniforms shared by every patched material: one write here reaches all of them
|
|
88
|
-
this.uniforms = { CSM_cascades: { value: [] }, cameraNear: { value: 0 }, shadowFar: { value: 0 } };
|
|
89
|
-
this.fade = S.fade;
|
|
90
|
-
this.updateFrustums();
|
|
91
|
-
// cacheKey is new for every build: three keeps a material's old programs and, when a key comes back (cascades off, then on again),
|
|
92
|
-
// reuses that program with the uniforms map of the material's latest compile, which lacks these uniforms, so the GPU would keep the
|
|
93
|
-
// old build's split and far values (shadows vanish where the old cascade 0 ended). One recompile per switch, which the light count
|
|
94
|
-
// change costs anyway; each material keeps one program per switch until it is disposed, so switch on a settings screen, not per frame
|
|
95
|
-
sky._csmBuild = (sky._csmBuild ?? 0) + 1;
|
|
96
|
-
this.patch = { name: 'csm', cacheKey: `${S.cascades}${S.fade ? 'f' : ''}.${sky._csmBuild}`, uniforms: this.uniforms, slot: 'lightingModel',
|
|
97
|
-
pars: `#define USE_CSM 1\n#define CSM_CASCADES ${S.cascades}\n${S.fade ? '#define CSM_FADE\n' : ''}` +
|
|
98
|
-
'uniform vec2 CSM_cascades[CSM_CASCADES];\nuniform float cameraNear;\nuniform float shadowFar;',
|
|
99
|
-
glsl: CSMShader.lights_fragment_begin };
|
|
100
|
-
/** material -> the patch object it carries, so a rebuilt CSM re-patches and switching off finds every material */
|
|
101
|
-
this.mats = new Map();
|
|
102
|
-
this.sky = sky;
|
|
103
|
-
this.at = new THREE.Vector3(Infinity, 0, 0); // camera position at the last placement
|
|
104
|
-
this.proj = '';
|
|
105
|
-
/** what entered the scene since the last frame (view.walks: how many full walks ran; tests read it) */
|
|
106
|
-
this.view = sceneVisitor(sky.engine.scene, { enter: 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); } });
|
|
107
|
-
}
|
|
108
|
-
fit(m) {
|
|
109
|
-
const was = this.mats.get(m);
|
|
110
|
-
if (was === this.patch || (was === null && !optedIn(this.sky).has(m))) return;
|
|
111
|
-
if (!lit(this.sky, m)) { this.mats.set(m, null); return; } // null: looked at, left alone (no per-frame recheck / rewarn)
|
|
112
|
-
patchMaterial(m, [this.patch], { strict: false }); this.mats.set(m, this.patch);
|
|
113
|
-
}
|
|
114
|
-
/** describe().owned row: the game's own materials the csm patch went on (the named exception, see the header) */
|
|
115
|
-
gameMaterials() { return [...this.mats].filter(([m, p]) => p && !isEngineMade(m)).map(([m]) => m.name || m.type); }
|
|
116
|
-
_injectInclude() {}
|
|
117
|
-
_updateUniforms() {
|
|
118
|
-
const U = this.uniforms;
|
|
119
|
-
if (!U) return; // the base constructor calls this before the uniforms exist
|
|
120
|
-
this._getExtendedBreaks(U.CSM_cascades.value);
|
|
121
|
-
U.cameraNear.value = this.camera.near; U.shadowFar.value = Math.min(this.camera.far, this.maxFar);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** Create, rebuild or remove the cascades after look.shadow.set changed shadow fields; copy bias / softness to the extra lights */
|
|
126
|
-
export function syncCascades(sky) {
|
|
127
|
-
const S = sky.shadow, e = sky.engine, want = S.cascades > 1;
|
|
128
|
-
const key = want ? [S.cascades, S.maxFar, S.fade, S.lightMargin, S.split].join('|') : '';
|
|
129
|
-
if (key !== sky._csmKey) {
|
|
130
|
-
dropCascades(sky);
|
|
131
|
-
sky._csmKey = key;
|
|
132
|
-
if (want) {
|
|
133
|
-
const sc = sky._sun.shadow.camera;
|
|
134
|
-
sky._csmSaved = { left: sc.left, right: sc.right, top: sc.top, bottom: sc.bottom, near: sc.near, far: sc.far };
|
|
135
|
-
if (isWebGPU(e.renderer)) { // three's CSMShadowNode on the sun (cascades.tsl.js): no extra lights in the scene, no patches
|
|
136
|
-
let node;
|
|
137
|
-
try { node = webgpuPart('cascades', '[sky] cascaded shadows (style.sky.cascades)'); } catch (err) { sky._csmKey = ''; throw err; }
|
|
138
|
-
sky.csm = node.create(sky, S);
|
|
139
|
-
sky.csm.shadowParams(S);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
sky.csm = new SkyCSM(sky, S);
|
|
143
|
-
Object.assign(sc, { near: 1, far: sky.csm.lightFar });
|
|
144
|
-
// these lights are new to the scene: honor look.shadow enabled false the way it treats existing lights
|
|
145
|
-
for (const l of sky.csm.lights) if (l !== sky._sun) l.castShadow = shadowsOn(e);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
if (sky.csm?.isSkyCascadeNode) sky.csm.shadowParams(S);
|
|
149
|
-
else 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 });
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/** Remove the cascades: extra lights out, the 'csm' patch off every material it went on, the sun's shadow box restored */
|
|
153
|
-
export function dropCascades(sky) {
|
|
154
|
-
const c = sky.csm;
|
|
155
|
-
if (!c) return;
|
|
156
|
-
if (c.isSkyCascadeNode) c.drop();
|
|
157
|
-
else {
|
|
158
|
-
for (const l of c.lights) if (l !== sky._sun) { c.parent.remove(l, l.target); l.dispose(); }
|
|
159
|
-
c.view.remove();
|
|
160
|
-
for (const [m, p] of c.mats) if (p) unpatchMaterial(m, 'csm');
|
|
161
|
-
}
|
|
162
|
-
const sc = sky._sun.shadow.camera;
|
|
163
|
-
Object.assign(sc, sky._csmSaved); sc.updateProjectionMatrix();
|
|
164
|
-
sky.csm = null; sky._csmKey = ''; sky._snapKey = '';
|
|
165
|
-
setShadowUpdate(sky.engine.renderer, sky.engine.scene, { now: true });
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/** Per frame while cascades are on (instead of _placeShadow): patch materials that entered the scene, follow the camera and the light, place on shadow frames */
|
|
169
|
-
export function cascadeFrame(sky, lightDir) {
|
|
170
|
-
const c = sky.csm, e = sky.engine, cam = e.camera, sun = sky._sun, S = sky.shadow;
|
|
171
|
-
if (c.isSkyCascadeNode) { c.frame(lightDir); return; }
|
|
172
|
-
c.view.sync();
|
|
173
|
-
const proj = cam.isPerspectiveCamera ? `${cam.fov},${cam.aspect},${cam.near},${cam.far},${cam.zoom}` : `${cam.left},${cam.right},${cam.near},${cam.far},${cam.zoom}`;
|
|
174
|
-
let force = false;
|
|
175
|
-
if (c.camera !== cam || proj !== c.proj) { c.camera = cam; c.proj = proj; c.updateFrustums(); force = true; }
|
|
176
|
-
c.lightDirection.copy(lightDir).negate(); // CSM points from the light into the scene
|
|
177
|
-
const show = sun.visible && shadowsOn(e); // with shadows off the extra lights would only add light: hide them
|
|
178
|
-
for (const l of c.lights) if (l !== sun) { l.color.copy(sun.color); l.intensity = sun.intensity; l.visible = show; }
|
|
179
|
-
cam.updateMatrixWorld();
|
|
180
|
-
// not updating every frame: also place early when the camera left a quarter of the nearest cascade (teleport, fast travel)
|
|
181
|
-
const near = c.breaks[0] * Math.min(cam.far, c.maxFar);
|
|
182
|
-
if (S.updateEvery <= 1 || shadowUpdatePending(e.renderer, e.scene) || force || c.at.distanceToSquared(cam.position) > (near / 4) ** 2) {
|
|
183
|
-
c.update(); c.at.copy(cam.position);
|
|
184
|
-
if (S.updateEvery > 1) setShadowUpdate(e.renderer, e.scene, { now: true });
|
|
185
|
-
}
|
|
186
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
// Sky cascaded shadows on WebGPURenderer (the WebGPU half of cascades.js; loaded only through threedog/tsl, render/fx/index.js).
|
|
2
|
-
// Why three's CSMShadowNode and not the WebGL design: the cascades become the shadow node of the one sun light (sun.shadow.shadowNode),
|
|
3
|
-
// so a material is lit by the sun once and shadowed by whichever cascade covers it. Nothing is patched and the scene is never walked:
|
|
4
|
-
// the 'csm' patch, the per-frame scene visitor and look.shadow.include() exist on WebGL only because there every cascade is a full
|
|
5
|
-
// DirectionalLight that would light an unpatched material N times (user decision 4, docs/plans/2026-11-03-webgpu-phase2.md).
|
|
6
|
-
// How it differs from the node used as-is, each one because the plain node would break something here:
|
|
7
|
-
// - The sun's shadow camera gets near 1 / far lightMargin + 2 * maxFar before the node clones it into the cascades. The node only sizes
|
|
8
|
-
// each cascade sideways and puts its light lightMargin behind the slice; with the sky's far kept, the far cascades' ground lies past far
|
|
9
|
-
// and draws no shadow at all (what E2 saw). Three's WebGL CSM sets the same lightFar itself.
|
|
10
|
-
// - The cascades are built with engine.camera, never with whatever camera compiles first (a probe or photo render would own them).
|
|
11
|
-
// - Placement waits for frames whose cascade maps redraw (shadow.updateEvery > 1): moving the cascade lights while the maps stay old
|
|
12
|
-
// shifts every shadow, the same reason cascades.js only calls csm.update() on shadow frames.
|
|
13
|
-
// - Switching it on or off tells three's light node to rebuild its shadow (the light's 'dispose' event): the node caches the shadow it
|
|
14
|
-
// built first and would keep drawing the old one.
|
|
15
|
-
import { CSMShadowNode } from 'three/addons/csm/CSMShadowNode.js';
|
|
16
|
-
import { setShadowUpdate, shadowUpdatePending, registerWebGPUPart } from '../../render/backend.js';
|
|
17
|
-
|
|
18
|
-
class SkyCascadeNode extends CSMShadowNode {
|
|
19
|
-
/** @param {any} sky @param {any} S sky.shadow */
|
|
20
|
-
constructor(sky, S) {
|
|
21
|
-
const custom = typeof S.split === 'function';
|
|
22
|
-
super(sky._sun, { cascades: S.cascades, maxFar: S.maxFar, mode: custom ? 'custom' : S.split, customSplitsCallback: custom ? S.split : undefined, lightMargin: S.lightMargin });
|
|
23
|
-
this.isSkyCascadeNode = true;
|
|
24
|
-
this.fade = S.fade;
|
|
25
|
-
this._sky = sky; // underscore names: three walks a node's public fields looking for child nodes
|
|
26
|
-
/** the WebGL route's material bookkeeping, empty here (nothing is patched): includeInCascades and the describe().owned row read it */
|
|
27
|
-
this.mats = new Map();
|
|
28
|
-
this._at = { x: Infinity, y: 0, z: 0 }; // camera position at the last early update
|
|
29
|
-
this._proj = '';
|
|
30
|
-
const sc = sky._sun.shadow.camera;
|
|
31
|
-
Object.assign(sc, { near: 1, far: S.lightMargin + 2 * S.maxFar }); sc.updateProjectionMatrix();
|
|
32
|
-
sky._sun.shadow.shadowNode = this;
|
|
33
|
-
rebuildShadow(sky._sun);
|
|
34
|
-
}
|
|
35
|
-
setup(builder) {
|
|
36
|
-
// _init is the node's own first-build step (cascade stand-in lights, frustums); run it with the engine camera instead of builder.camera
|
|
37
|
-
// (private to three, so not in @types/three)
|
|
38
|
-
if (this.camera === null) /** @type {any} */ (this)._init({ camera: this._sky.engine.camera, renderer: builder.renderer });
|
|
39
|
-
return super.setup(builder);
|
|
40
|
-
}
|
|
41
|
-
/** @param {any} frame @returns {boolean} false would make three call it again this frame (NodeFrame) */
|
|
42
|
-
updateBefore(frame) {
|
|
43
|
-
if (this.lights.length && !this.lights.some(l => l.shadow.autoUpdate || l.shadow.needsUpdate)) return true; // no cascade map redraws this frame
|
|
44
|
-
return super.updateBefore(frame);
|
|
45
|
-
}
|
|
46
|
-
fit() {}
|
|
47
|
-
gameMaterials() { return []; }
|
|
48
|
-
/** Copy look.shadow fields to the cascades (the node itself scales bias by cascade: bias x (i + 1), kept) @param {any} S */
|
|
49
|
-
shadowParams(S) {
|
|
50
|
-
this.lights.forEach((l, i) => Object.assign(l.shadow, { bias: S.bias * (i + 1), normalBias: S.normalBias, radius: S.radius, blurSamples: S.blurSamples }));
|
|
51
|
-
}
|
|
52
|
-
/** Per frame (cascades.js cascadeFrame): aim the sun, follow a new camera / projection, update early after a jump @param {any} lightDir unit vector toward the light */
|
|
53
|
-
frame(lightDir) {
|
|
54
|
-
const sky = this._sky, e = sky.engine, cam = e.camera, sun = sky._sun, S = sky.shadow;
|
|
55
|
-
sun.position.copy(sun.target.position).addScaledVector(lightDir, sky.orbit.distance);
|
|
56
|
-
sun.updateMatrixWorld(); sun.target.updateMatrixWorld();
|
|
57
|
-
if (this.camera === null) return; // not built yet: setup() takes engine.camera
|
|
58
|
-
const proj = cam.isPerspectiveCamera ? `${cam.fov},${cam.aspect},${cam.near},${cam.far},${cam.zoom}` : `${cam.left},${cam.right},${cam.near},${cam.far},${cam.zoom}`;
|
|
59
|
-
let force = false;
|
|
60
|
-
if (this.camera !== cam || proj !== this._proj) { this.camera = cam; this._proj = proj; this.updateFrustums(); force = true; }
|
|
61
|
-
cam.updateMatrixWorld();
|
|
62
|
-
if (S.updateEvery <= 1) return;
|
|
63
|
-
// not updating every frame: also update early when the camera left a quarter of the nearest cascade (teleport, fast travel)
|
|
64
|
-
const near = this.breaks[0] * Math.min(cam.far, this.maxFar), p = cam.position, d = (p.x - this._at.x) ** 2 + (p.y - this._at.y) ** 2 + (p.z - this._at.z) ** 2;
|
|
65
|
-
if (force || d > (near / 4) ** 2) { setShadowUpdate(e.renderer, e.scene, { now: true }); this._at = { x: p.x, y: p.y, z: p.z }; }
|
|
66
|
-
else if (shadowUpdatePending(e.renderer, e.scene)) this._at = { x: p.x, y: p.y, z: p.z };
|
|
67
|
-
}
|
|
68
|
-
/** Switch off: the cascade lights and maps go, the sun gets its plain shadow back */
|
|
69
|
-
drop() {
|
|
70
|
-
const sun = this._sky._sun;
|
|
71
|
-
delete sun.shadow.shadowNode; // three tests `!== undefined`: null would count as a node
|
|
72
|
-
for (const n of /** @type {any} */ (this)._shadowNodes) n.dispose(); // the node's own dispose() leaves the cascade maps on the GPU (private field)
|
|
73
|
-
this.dispose();
|
|
74
|
-
rebuildShadow(sun);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** Make three's light node drop the shadow it cached (AnalyticLightNode listens for the light's 'dispose'; its version bump recompiles) */
|
|
79
|
-
function rebuildShadow(light) { light.dispatchEvent({ type: 'dispose' }); }
|
|
80
|
-
|
|
81
|
-
// cascades.js looks this up when the renderer is a WebGPURenderer (the WebGL bundle never imports three/webgpu); nothing to call
|
|
82
|
-
registerWebGPUPart('cascades', Object.freeze({ create: (sky, S) => new SkyCascadeNode(sky, S) }));
|
package/modules/sky/look.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// Sky look setup (helper of Sky.js): which engine lights the sky drives, the fog model, extra dome layers.
|
|
2
|
-
// Light modes, sky() options only (whether the engine's two lights exist is how the game lights its world, not a swappable look):
|
|
3
|
-
// sky({ sun: true }) default: the sky drives engine.lights.sun (color, intensity, direction, shadow box) from the keyframes
|
|
4
|
-
// sky({ sun: false }) hidden (visible = false, no shadows) and never touched: light the world with your own three.js lights
|
|
5
|
-
// sky({ hemisphere: true | false }) the same for engine.lights.hemi (ambient)
|
|
6
|
-
// sky({ fog: true | false }) scene.fog: true (default) the sky creates it and writes color and distance every frame | false scene.fog = null
|
|
7
|
-
// and never touched. An object here is style.sky.fog settings (= true)
|
|
8
|
-
// Keeping a light / the fog but writing it yourself is not a sky() option: one takeover entry per look value (2026-11-02), engine.look.lights.manual(
|
|
9
|
-
// 'sun' | 'hemi' | 'sun.intensity' ...) and engine.look.fog.manual() (core/owned.js). manual(key, false) hands it back, and a direct write without
|
|
10
|
-
// either takes it too (the sky yields and warns once). The removed 'manual' mode throws and names that call, so old code learns the one way.
|
|
11
|
-
// Hidden lights are left in the scene (visible = false): three skips them, and toggling visible later recompiles like adding a light would.
|
|
12
|
-
import * as THREE from 'three';
|
|
13
|
-
import { resolveFog, DOME_FOG } from './fog.js';
|
|
14
|
-
import { resolveDomeLayers } from './domeLayers.js';
|
|
15
|
-
import { codedError } from '../../core/errorHints.js';
|
|
16
|
-
import { isWebGPU } from '../../render/backend.js';
|
|
17
|
-
|
|
18
|
-
const TAKE = { sun: "engine.look.lights.manual(['sun.intensity', 'sun.color'])", hemisphere: "engine.look.lights.manual('hemi')", fog: 'engine.look.fog.manual()' };
|
|
19
|
-
const modeOf = (name, v = true) => {
|
|
20
|
-
if (v === 'manual') throw codedError('sky-option', `sky({ ${name}: 'manual' }) is not an option; keep the default and take it over after engine.use(sky()) with ${TAKE[name]} (manual(..., false) hands it back)`);
|
|
21
|
-
if (v !== true && v !== false) throw codedError('sky-option', `sky({ ${name} }) must be true (the sky drives it) or false (${name === 'fog' ? 'no fog' : 'hidden, light the world yourself'}); to write it yourself: ${TAKE[name]}; got ${JSON.stringify(v)}`);
|
|
22
|
-
return v;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/** Resolve light modes, fog and dome layers for a new Sky; returns the extra dome uniforms and GLSL ({ uniforms, decl, body }), and the layers for a node dome */
|
|
26
|
-
export function prepareLook(sky, st, over) {
|
|
27
|
-
/** @internal which engine lights / fog the sky writes each frame: true / false */
|
|
28
|
-
// fog is also the look override (an object of style.sky.fog settings, which means true); a boolean picks the mode and keeps the style's settings
|
|
29
|
-
const fogObj = over.fog != null && typeof over.fog === 'object';
|
|
30
|
-
sky._drive = { sun: modeOf('sun', over.sun), hemi: modeOf('hemisphere', over.hemisphere), fog: fogObj ? true : modeOf('fog', over.fog) };
|
|
31
|
-
const { sun, hemi } = sky.engine.lights;
|
|
32
|
-
if (sky._drive.sun === false) { sun.visible = false; sun.castShadow = false; }
|
|
33
|
-
if (sky._drive.hemi === false) hemi.visible = false;
|
|
34
|
-
/** @internal resolved fog settings (fog.js) */
|
|
35
|
-
sky._fogSpec = fogObj || over.fog == null ? st.fog : sky.engine.style.sky?.fog; // look.fog's style layer (lookFog.js)
|
|
36
|
-
sky._fog = resolveFog(sky._fogSpec);
|
|
37
|
-
sky._backdrop = resolveBackdrop(st);
|
|
38
|
-
const f = DOME_FOG, l = resolveDomeLayers(st.layers, { gpu: isWebGPU(sky.engine.renderer) });
|
|
39
|
-
// the fog object is created after the dome and may be replaced by the game: read its color at draw time (fog.js fogBand turns the band on)
|
|
40
|
-
const uniforms = { ...l.uniforms, uFogBand: { value: 0 }, uFogColor: { get value() { return sky.engine.scene.fog?.color ?? sky.uniforms.uHorizon.value; } } };
|
|
41
|
-
return { uniforms, decl: [f.decl, l.decl].filter(Boolean).join('\n'), body: f.body + l.body, layers: l.layers };
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// style.sky.backdrop: one flat color (or ({ time, weather, season, state, sky }) => color each frame, core/look/state.js) instead of the dome -- no gradient, horizon, sun / moon disk,
|
|
45
|
-
// stars or clouds. The color goes straight to scene.background (no tone mapping), so what is written is what shows; the keyframes
|
|
46
|
-
// still light the world, and fog in its default 'horizon' color follows the backdrop so far things fade into it.
|
|
47
|
-
export function resolveBackdrop(st) {
|
|
48
|
-
const v = st.backdrop;
|
|
49
|
-
if (v == null) return null;
|
|
50
|
-
const color = typeof v === 'number' || typeof v === 'string' || v.isColor;
|
|
51
|
-
if (!color && typeof v !== 'function') throw codedError('sky-option', `style.sky.backdrop must be a color (0xefebe4, '#efebe4') or ({ time, state }) => color; got ${JSON.stringify(v)}`);
|
|
52
|
-
if (st.skybox) throw codedError('sky-option', 'style.sky: backdrop and skybox both replace the dome; keep one (backdrop for a flat color, skybox for a panorama)');
|
|
53
|
-
return { fn: color ? null : v, color: new THREE.Color(color ? v : 0x000000) };
|
|
54
|
-
}
|