threedog 0.2.1 → 0.7.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 +371 -1
- package/README.md +21 -12
- package/core/Animator.js +15 -12
- package/core/Assets.js +92 -26
- package/core/Audio.js +45 -38
- package/core/Baked.js +30 -15
- package/core/Batching.js +102 -15
- package/core/Budget.js +40 -19
- package/core/Clock.js +40 -80
- package/core/DebugOverrides.js +75 -25
- package/core/Describe.js +105 -45
- package/core/Engine.js +203 -75
- package/core/Events.js +4 -1
- package/core/I18n.js +25 -13
- package/core/Input.js +175 -80
- package/core/Inspect.js +8 -5
- package/core/InspectMaterials.js +84 -0
- package/core/InspectPerf.js +68 -0
- package/core/InspectScene.js +13 -2
- package/core/Loading.js +2 -1
- package/core/MaterialInfo.js +7 -5
- package/core/Ops.js +50 -9
- package/core/Random.js +9 -2
- package/core/Rays.js +12 -7
- package/core/SaveStore.js +41 -9
- package/core/Saves.js +71 -15
- package/core/Stream.js +13 -10
- package/core/Threads.js +26 -7
- package/core/UrlState.js +69 -13
- package/core/Views.js +10 -6
- package/core/actor.js +1 -1
- package/core/adaptive.js +93 -0
- package/core/assetEntry.js +27 -7
- package/core/assetHot.js +176 -0
- package/core/assetLoad.js +44 -19
- package/core/assetManifest.js +53 -11
- package/core/assetReport.js +5 -5
- package/core/audioRules.js +13 -11
- package/core/audioVoice.js +69 -42
- package/core/batchGroups.js +9 -1
- package/core/canvasBox.js +1 -2
- package/core/catalog.js +21 -5
- package/core/cells.js +62 -0
- package/core/checks.js +10 -8
- package/core/chunkStream.js +87 -0
- package/core/control.js +149 -0
- package/core/copies.js +32 -0
- package/core/dayTime.js +12 -6
- package/core/debugView.js +85 -18
- package/core/describeRender.js +117 -21
- package/core/describeText.js +41 -21
- package/core/engineCamera.js +32 -0
- package/core/errorCodes.js +478 -32
- package/core/errorHints.js +41 -142
- package/core/errors.js +31 -8
- package/core/events.generated.js +13 -7
- package/core/gameLights.js +69 -0
- package/core/grayMap.js +20 -0
- package/core/grid.js +14 -13
- package/core/gridLoad.js +2 -1
- package/core/ground.js +6 -4
- package/core/headlessLoad.js +55 -0
- package/core/holds.js +78 -50
- package/core/inputContext.js +11 -7
- package/core/inputDefaults.js +24 -21
- package/core/inputPad.js +1 -1
- package/core/inputPointer.js +1 -1
- package/core/inputTouch.js +2 -2
- package/core/lifecycle.js +46 -12
- package/core/lightWatch.js +9 -5
- package/core/loop.js +109 -43
- package/core/math.js +18 -3
- package/core/moduleSlots.js +100 -0
- package/core/moduleTypes.js +86 -0
- package/core/modules.js +147 -29
- package/core/movement.js +2 -2
- package/core/namedModel.js +74 -0
- package/core/opsCheck.js +3 -3
- package/core/opsFail.js +15 -6
- package/core/opsGuard.js +4 -4
- package/core/opsRun.js +4 -3
- package/core/owned.js +171 -0
- package/core/page.js +44 -10
- package/core/params.js +30 -8
- package/core/pictureSlots.js +33 -0
- package/core/pictureWriters.js +343 -0
- package/core/plugins.js +245 -0
- package/core/saveApply.js +99 -17
- package/core/saveFiles.js +8 -6
- package/core/saveValues.js +46 -0
- package/core/saveVersions.js +20 -3
- package/core/scatter.js +48 -19
- package/core/sceneDelta.js +211 -0
- package/core/sceneMethods.js +31 -33
- package/core/screenToGround.js +1 -1
- package/core/services.js +27 -11
- package/core/session.js +28 -25
- package/core/shaderCost.js +78 -0
- package/core/shadowTypes.js +3 -2
- package/core/shadows.js +405 -0
- package/core/sharedPoint.js +303 -0
- package/core/skip.js +36 -28
- package/core/stackFrames.js +45 -0
- package/core/stacks.js +166 -0
- package/core/startup.js +153 -13
- package/core/streamSources.js +0 -11
- package/core/targeting.js +1 -1
- package/core/textureBytes.js +20 -0
- package/core/thingExplain.js +3 -3
- package/core/thingOps.js +29 -6
- package/core/things.js +22 -12
- package/core/threadPure.js +7 -3
- package/core/threePatches.js +47 -0
- package/core/tier.js +21 -10
- package/core/time.js +236 -0
- package/core/uiClock.js +25 -0
- package/core/util.js +8 -2
- package/core/validate.js +66 -87
- package/core/view.js +43 -0
- package/core/wrap.js +106 -0
- package/docs/AI.md +95 -104
- package/docs/API.md +35 -31
- package/docs/CODEMAP.md +231 -176
- package/docs/COMMANDS.md +63 -39
- package/docs/CONVENTIONS.md +99 -31
- package/docs/MIGRATING-0.3.md +248 -0
- package/docs/MIGRATING-0.4.md +320 -0
- package/docs/MIGRATING-0.5.md +68 -0
- package/docs/MIGRATING-0.6.md +126 -0
- package/docs/MIGRATING-0.7.md +39 -0
- package/docs/PERF.md +35 -7
- package/docs/THREE.md +82 -28
- package/docs/api/ambience.md +0 -1
- package/docs/api/assets.md +15 -11
- package/docs/api/audio.md +10 -14
- package/docs/api/budget.md +4 -0
- package/docs/api/calendar.md +41 -0
- package/docs/api/cameraRig.md +16 -5
- package/docs/api/characters.md +41 -24
- package/docs/api/clock.md +6 -5
- package/docs/api/collision.md +10 -7
- package/docs/api/content.md +6 -4
- package/docs/api/dialogue.md +9 -9
- package/docs/api/engine.md +95 -65
- package/docs/api/events.md +20 -14
- package/docs/api/grids.md +10 -3
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +5 -2
- package/docs/api/i18n.md +1 -1
- package/docs/api/input.md +13 -7
- package/docs/api/interactions.md +10 -6
- package/docs/api/inventory.md +17 -17
- package/docs/api/level.md +0 -2
- package/docs/api/lightPool.md +3 -1
- package/docs/api/music.md +1 -1
- package/docs/api/nav.md +3 -0
- package/docs/api/occlusion.md +5 -0
- package/docs/api/openWorld.md +2 -1
- package/docs/api/particles.md +6 -3
- package/docs/api/photo.md +0 -2
- package/docs/api/pickups.md +21 -0
- package/docs/api/post.md +8 -5
- package/docs/api/quests.md +2 -3
- package/docs/api/rigid.md +16 -14
- package/docs/api/saves.md +6 -4
- package/docs/api/settings.md +2 -3
- package/docs/api/sky.md +18 -49
- package/docs/api/stream.md +1 -1
- package/docs/api/terrain.md +16 -7
- package/docs/api/terrainDraw.md +12 -0
- package/docs/api/timeline.md +3 -4
- package/docs/api/tools.md +32 -15
- package/docs/api/triggers.md +7 -10
- package/docs/api/vegetation.md +17 -9
- package/docs/api/vegetationDraw.md +10 -0
- package/docs/api/water.md +9 -21
- package/docs/api/weather.md +10 -15
- package/docs/api/weatherDraw.md +10 -0
- package/docs/api/world.md +3 -2
- package/docs/recipes/01-new-game.md +52 -42
- package/docs/recipes/02-npc.md +24 -7
- package/docs/recipes/03-items-pickups.md +57 -22
- package/docs/recipes/04-quests.md +12 -5
- package/docs/recipes/05-props-bake.md +174 -22
- package/docs/recipes/06-clock-events.md +100 -52
- package/docs/recipes/07-flow-scenes-pause.md +50 -10
- package/docs/recipes/08-weather-sky.md +134 -37
- package/docs/recipes/09-materials-lights-models.md +185 -0
- package/docs/recipes/10-blender-level.md +16 -4
- package/docs/recipes/11-vehicles.md +67 -10
- package/docs/recipes/13-animation.md +23 -9
- package/docs/recipes/14-custom-module.md +63 -29
- package/docs/recipes/15-perf.md +31 -10
- package/docs/recipes/16-dev-bridge.md +74 -40
- package/docs/recipes/18-world.md +26 -14
- package/docs/recipes/19-shooting-picking.md +12 -10
- package/docs/recipes/20-content-actions-save.md +60 -18
- package/docs/recipes/21-camera.md +55 -17
- package/docs/recipes/22-shop-gold.md +3 -3
- package/docs/recipes/23-ops.md +17 -11
- package/docs/recipes/26-ui-parts.md +86 -13
- package/docs/recipes/27-net.md +11 -5
- package/docs/recipes/28-terrain.md +36 -3
- package/docs/recipes/29-grid.md +46 -19
- package/docs/recipes/30-templates.md +72 -15
- package/docs/recipes/31-audio.md +20 -12
- package/docs/recipes/32-action-game.md +51 -4
- package/docs/recipes/34-environment-lighting.md +108 -21
- package/docs/recipes/35-picture-from-reference.md +147 -0
- package/docs/recipes/36-sky-ground-plants.md +158 -0
- package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -12
- package/docs/recipes/38-environment-hooks.md +67 -0
- package/docs/recipes/40-scene.md +114 -32
- package/docs/recipes/42-terrain-shape.md +2 -2
- package/docs/recipes/43-shader-patches-surfaces.md +206 -0
- package/docs/recipes/44-water-weather-hooks.md +191 -0
- package/docs/recipes/45-cascaded-shadows.md +130 -23
- package/docs/recipes/46-blender-art-route.md +17 -20
- package/docs/recipes/47-island-snow-backdrop.md +13 -15
- package/docs/recipes/49-game-module-contract.md +30 -17
- package/docs/recipes/50-own-renderer.md +4 -4
- package/docs/recipes/51-capability-catalog.md +3 -3
- package/docs/recipes/52-around-the-picture.md +181 -0
- package/docs/recipes/53-ground-up-close.md +12 -12
- package/docs/recipes/54-three-idioms.md +88 -0
- package/docs/recipes/55-mods-time-wrap.md +124 -0
- package/docs/recipes/56-webgpu-tsl.md +303 -0
- package/docs/recipes/57-control.md +104 -0
- package/docs/recipes/58-input.md +60 -0
- package/docs/recipes/59-depth-post-effects.md +83 -0
- package/docs/recipes/60-judge-the-picture.md +70 -0
- package/docs/recipes/61-deploy.md +27 -0
- package/docs/recipes/62-picture-code.md +244 -0
- package/docs/recipes/63-third-person-start.md +77 -0
- package/docs/recipes/64-particles.md +35 -0
- package/examples/action/.threedog/content-index.json +1 -0
- package/examples/action/GAMEMAP.md +20 -14
- package/examples/action/assets.js +8 -0
- package/examples/action/content/actions.js +1 -1
- package/examples/action/content/audio.js +5 -5
- package/examples/action/main.js +12 -15
- package/examples/action/models.js +23 -24
- 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/plain-picture/.threedog/content-index.json +1 -0
- package/examples/plain-picture/FINDINGS.md +53 -0
- package/examples/plain-picture/GAMEMAP.md +90 -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 +133 -0
- package/examples/rc2d/.threedog/content-index.json +1 -0
- package/examples/rc2d/GAMEMAP.md +88 -0
- package/examples/rc2d/README.md +57 -0
- package/examples/rc2d/main.js +55 -0
- 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 +187 -0
- package/examples/rc2d/shaders.js +144 -0
- package/examples/sheepisland/.threedog/content-index.json +1 -0
- package/examples/sheepisland/GAMEMAP.md +22 -17
- package/examples/sheepisland/assets.js +5 -0
- package/examples/sheepisland/content/templates.js +1 -1
- package/examples/sheepisland/content/vegetation.js +3 -1
- package/examples/sheepisland/main.js +29 -18
- package/examples/sheepisland/{style/models.js → models.js} +13 -24
- package/examples/sheepisland/picture/index.js +20 -0
- package/examples/sheepisland/picture/lights.js +34 -0
- package/examples/sheepisland/picture/materials.js +61 -0
- package/examples/sheepisland/picture/palette.js +60 -0
- package/examples/sheepisland/picture/sky.js +20 -0
- package/examples/sheepisland/views.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -0
- package/examples/styletest/GAMEMAP.md +25 -22
- package/examples/styletest/assets.js +6 -0
- package/examples/styletest/content/templates.js +1 -1
- package/examples/styletest/content/vegetation.js +1 -1
- package/examples/styletest/main.js +25 -34
- package/examples/styletest/models.js +30 -30
- package/examples/styletest/params.js +2 -5
- 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 +91 -0
- package/examples/techniques/contact-shadows/contactShadows.js +67 -0
- package/examples/techniques/contact-shadows/main.js +55 -0
- 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 +83 -0
- package/examples/techniques/day-night-grade/main.js +41 -0
- 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 +106 -0
- package/examples/techniques/interior-light/interiorLight.js +47 -0
- package/examples/techniques/interior-light/main.js +87 -0
- 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 +126 -0
- package/examples/techniques/modular-building/kit.js +426 -0
- package/examples/techniques/modular-building/main.js +39 -0
- 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 +95 -0
- package/examples/techniques/night-lights/main.js +47 -0
- package/examples/techniques/night-lights/nightLights.js +95 -0
- 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 +59 -0
- package/examples/techniques/outlines-and-rim/main.js +61 -0
- package/examples/techniques/outlines-and-rim/outlines.js +64 -0
- 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 +79 -0
- package/examples/techniques/procedural-animation/creature.js +44 -0
- package/examples/techniques/procedural-animation/main.js +47 -0
- 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 +118 -0
- package/examples/techniques/procedural-surface/README.md +69 -0
- package/examples/techniques/procedural-surface/main.js +65 -0
- 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/procedural-surface/surface.js +120 -0
- package/examples/techniques/stylized-shading/README.md +74 -0
- package/examples/techniques/stylized-shading/main.js +62 -0
- 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 +131 -0
- package/examples/techniques/sun-and-key-light/README.md +133 -0
- package/examples/techniques/sun-and-key-light/keyLight.js +71 -0
- package/examples/techniques/sun-and-key-light/main.js +51 -0
- 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 +102 -0
- package/examples/techniques/wet-road/main.js +48 -0
- 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/techniques/wet-road/wetRoad.js +209 -0
- package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
- package/examples/webgpu-tsl/GAMEMAP.md +89 -0
- package/examples/webgpu-tsl/README.md +45 -0
- package/examples/webgpu-tsl/main.js +44 -0
- 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 -0
- package/examples/world/GAMEMAP.md +31 -21
- package/examples/world/art/humanoid.js +38 -0
- package/examples/world/art/index.js +11 -0
- package/examples/world/art/models.js +57 -0
- package/examples/world/art/shapes.js +9 -0
- package/examples/world/assets.js +6 -0
- package/examples/world/content/audio.js +5 -5
- package/examples/world/content/items.js +1 -1
- package/examples/world/content/npcs.js +1 -1
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/rules.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +22 -18
- 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 +44 -54
- package/index.js +29 -25
- package/llms.txt +24 -15
- package/modules/ambience/Ambience.js +34 -23
- package/modules/calendar/Calendar.js +163 -0
- package/modules/calendar/contract.js +21 -0
- package/modules/calendar/index.js +82 -0
- package/modules/{sky → calendar}/schedule.js +17 -16
- package/modules/calendar/seasons.js +55 -0
- package/modules/camera/FirstPersonCamera.js +6 -15
- package/modules/camera/FixedCamera.js +33 -15
- package/modules/camera/FollowCamera.js +90 -16
- package/modules/camera/RtsCamera.js +18 -17
- package/modules/camera/common.js +73 -20
- package/modules/camera/contract.js +17 -0
- package/modules/camera/projection.js +11 -24
- package/modules/characters/Character.js +188 -48
- package/modules/characters/NPC.js +92 -41
- package/modules/characters/assetModel.js +8 -16
- package/modules/characters/behaviors.js +2 -1
- package/modules/characters/contract.js +13 -0
- package/modules/characters/footsteps.js +1 -1
- package/modules/characters/index.js +112 -49
- package/modules/characters/moveHelpers.js +4 -5
- package/modules/characters/movers/common.js +102 -19
- package/modules/characters/movers/manual.js +23 -0
- package/modules/characters/movers/rapier.js +19 -16
- package/modules/characters/movers/simple.js +14 -11
- package/modules/characters/movers/support.js +186 -0
- package/modules/characters/npcAvoid.js +47 -42
- package/modules/characters/npcSim.js +17 -9
- package/modules/characters/npcView.js +44 -16
- package/modules/characters/pathAsync.js +7 -3
- package/modules/characters/playerStrings.js +4 -3
- package/modules/characters/proceduralRig.js +19 -4
- package/modules/characters/useModel.js +2 -2
- package/modules/characters/vehicle.contract.js +21 -0
- package/modules/characters/walkTo.js +21 -7
- package/modules/collision/Collision.js +69 -27
- package/modules/collision/grid.js +8 -6
- package/modules/content/explain.js +2 -2
- package/modules/content/fields.js +102 -0
- package/modules/content/ids.js +8 -6
- package/modules/content/index.js +104 -27
- package/modules/content/loader.js +45 -33
- package/modules/content/models.js +58 -42
- package/modules/content/packs.js +6 -5
- package/modules/content/parts.js +41 -0
- package/modules/content/props.js +20 -11
- package/modules/content/rules.js +66 -0
- package/modules/content/stages.js +80 -0
- package/modules/content/templates.js +123 -30
- package/modules/debug/DebugPanel.js +24 -17
- package/modules/flow/contract.js +16 -0
- package/modules/flow/index.js +21 -15
- package/modules/gameplay/Container.js +41 -32
- package/modules/gameplay/Containers.js +30 -15
- package/modules/gameplay/Dialogue.js +113 -55
- package/modules/gameplay/Interactions.js +273 -72
- package/modules/gameplay/Inventory.js +72 -76
- package/modules/gameplay/Quests.js +75 -39
- package/modules/gameplay/boxOps.js +3 -3
- package/modules/gameplay/dialogue.contract.js +21 -0
- package/modules/gameplay/dialogueBox.js +4 -2
- package/modules/gameplay/dialogueBubbles.js +116 -0
- package/modules/gameplay/interactionPrompt.js +4 -1
- package/modules/gameplay/interactions.contract.js +16 -0
- package/modules/gameplay/inventory.contract.js +23 -0
- package/modules/gameplay/inventoryOps.js +19 -17
- package/modules/gameplay/pickups.js +306 -85
- package/modules/gameplay/questLog.js +6 -6
- package/modules/gameplay/quests.contract.js +17 -0
- package/modules/grid/Grid.js +92 -50
- package/modules/grid/Layer.js +27 -13
- package/modules/grid/index.js +96 -43
- package/modules/grid/ops.js +20 -18
- package/modules/grid/preview.js +37 -29
- package/modules/grid/strings.js +12 -0
- package/modules/grid/tiles.js +19 -22
- package/modules/hlod/index.js +52 -19
- package/modules/hud/index.js +48 -20
- package/modules/hud/parts.js +28 -13
- package/modules/level/heightfield.js +3 -1
- package/modules/level/index.js +49 -23
- package/modules/level/nodes.js +4 -3
- package/modules/lights/index.js +47 -19
- package/modules/music/Music.js +38 -21
- package/modules/music/rules.js +1 -1
- package/modules/nav/index.js +48 -42
- package/modules/net/Client.js +13 -6
- package/modules/net/Host.js +19 -5
- package/modules/net/Net.js +2 -1
- package/modules/net/index.js +13 -8
- package/modules/net/sync.js +9 -8
- package/modules/net/transports.js +77 -27
- package/modules/particles/Particles.js +58 -28
- package/modules/particles/contract.js +17 -0
- package/modules/particles/effect.js +54 -11
- package/modules/photo/Photo.js +56 -38
- package/modules/rigid/RigidBodies.js +194 -32
- package/modules/rigid/Vehicles.js +18 -15
- package/modules/rigid/sync.js +62 -17
- package/modules/settings/Settings.js +60 -55
- package/modules/settings/apply.js +38 -3
- package/modules/settings/sections.js +5 -3
- package/modules/settings/strings.js +3 -2
- package/modules/settings/view.js +5 -3
- package/modules/sky/Sky.js +132 -205
- package/modules/sky/clouds.js +37 -23
- package/modules/sky/dome.js +100 -0
- package/modules/sky/domeLayers.js +30 -15
- package/modules/sky/environment.js +45 -99
- package/modules/sky/fog.js +9 -139
- package/modules/sky/frame.js +60 -56
- package/modules/sky/season.js +21 -0
- package/modules/sky/shader.js +63 -35
- package/modules/sky/skyModule.js +52 -37
- package/modules/sky/tint.js +59 -0
- package/modules/terrain/ChunkManager.js +194 -110
- package/modules/terrain/chunkJob.js +1 -1
- package/modules/terrain/chunkQueries.js +6 -4
- package/modules/terrain/draw.js +154 -0
- package/modules/terrain/index.js +87 -54
- package/modules/terrain/terrainDefaults.js +2 -2
- package/modules/terrain/terrainEdit.js +18 -20
- package/modules/terrain/terrainGen.js +6 -4
- package/modules/terrain/terrainIsland.js +5 -4
- package/modules/terrain/terrainShape.js +12 -12
- package/modules/terrain/terrainShapeMain.js +8 -7
- package/modules/terrain/terrainTexture.js +21 -19
- package/modules/timeline/Timeline.js +95 -43
- package/modules/timeline/Tween.js +18 -10
- package/modules/timeline/letterbox.js +2 -2
- package/modules/timeline/shots.js +5 -1
- package/modules/triggers/index.js +111 -76
- package/modules/vegetation/Vegetation.js +229 -112
- package/modules/vegetation/densityMap.js +62 -0
- package/modules/vegetation/draw.js +191 -0
- package/modules/vegetation/groundChunks.js +52 -58
- package/modules/vegetation/index.js +32 -11
- package/modules/vegetation/modelGeometry.js +3 -2
- package/modules/vegetation/nearFade.js +8 -2
- package/modules/water/Water.js +157 -72
- package/modules/water/surface.js +86 -47
- package/modules/weather/Weather.js +96 -103
- package/modules/weather/particles.js +37 -14
- package/modules/weather/shaders.js +1 -1
- package/modules/weather/strings.js +2 -2
- package/modules/weather/weatherDraw.js +141 -0
- package/modules/world/World.js +26 -9
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -4
- package/modules/world/persist.js +62 -2
- package/modules/world/pos.js +3 -2
- package/modules/world/records.js +8 -6
- package/modules/world/sim.js +60 -20
- package/modules/world/simFar.js +4 -3
- package/modules/world/state.js +3 -2
- package/modules/world/thingSource.js +1 -1
- package/modules/world/views.js +8 -6
- package/package.json +8 -3
- package/presets.js +43 -29
- package/render/PostFX.js +318 -135
- package/render/backend.js +486 -0
- package/render/cascades.js +195 -0
- package/render/cascades.tsl.js +96 -0
- package/render/daylight.js +39 -0
- package/render/detail.js +122 -41
- package/render/effects.js +155 -48
- package/render/engineUniforms.js +10 -1
- package/render/fuse.js +5 -4
- package/render/fx/cel.tsl.js +42 -0
- package/render/fx/cloudShadow.tsl.js +16 -0
- package/render/fx/detail.tsl.js +66 -0
- package/render/fx/index.js +28 -0
- package/render/fx/lighting.tsl.js +28 -0
- package/render/fx/nodeErrors.tsl.js +68 -0
- package/render/fx/noise.tsl.js +12 -0
- package/render/fx/objectOrigin.tsl.js +42 -0
- package/render/fx/particles.tsl.js +139 -0
- package/render/fx/patchNodes.tsl.js +403 -0
- package/render/fx/postWebGPU.tsl.js +181 -0
- package/render/fx/season.tsl.js +13 -0
- package/render/fx/sky.tsl.js +187 -0
- package/render/fx/uniforms.tsl.js +67 -0
- package/render/fx/water.tsl.js +53 -0
- package/render/fx/wind.tsl.js +22 -0
- package/render/fxNumbers.js +36 -0
- package/render/hotGlsl.js +24 -0
- package/render/layers.js +14 -0
- package/render/lighting.js +71 -18
- package/render/lightmap.js +142 -0
- package/render/lights.js +47 -6
- package/render/materials.js +55 -152
- package/render/modeling.js +73 -0
- package/render/neutral.js +23 -0
- package/render/occlusion.js +184 -0
- package/render/ownFrame.js +76 -0
- package/render/patches.js +317 -35
- package/render/postWebGL.js +205 -0
- package/render/probes.js +288 -0
- package/render/shaderErrors.js +154 -0
- package/render/slots.js +165 -0
- package/render/terms.js +163 -0
- package/render/uniformDecl.js +4 -3
- package/types/common.d.ts +2 -2
- package/types/core.d.ts +757 -346
- package/types/gameplay.d.ts +539 -330
- package/types/generated/core/Audio.d.ts +26 -42
- package/types/generated/core/Batching.d.ts +6 -2
- package/types/generated/core/Budget.d.ts +2 -8
- package/types/generated/core/DebugOverrides.d.ts +58 -9
- package/types/generated/core/I18n.d.ts +2 -2
- package/types/generated/core/Input.d.ts +110 -32
- package/types/generated/core/Ops.d.ts +31 -0
- package/types/generated/core/Random.d.ts +2 -2
- package/types/generated/core/Saves.d.ts +10 -2
- package/types/generated/core/Stream.d.ts +1 -1
- package/types/generated/core/Threads.d.ts +4 -1
- package/types/generated/core/Views.d.ts +0 -1
- package/types/generated/core/audioVoice.d.ts +17 -9
- package/types/generated/core/control.d.ts +55 -0
- package/types/generated/core/page.d.ts +9 -2
- package/types/generated/core/session.d.ts +2 -1
- package/types/generated/modules/ambience/Ambience.d.ts +0 -9
- package/types/generated/modules/calendar/Calendar.d.ts +84 -0
- package/types/generated/modules/calendar/index.d.ts +10 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
- package/types/generated/modules/grid/Grid.d.ts +61 -25
- package/types/generated/modules/grid/Layer.d.ts +13 -5
- package/types/generated/modules/grid/index.d.ts +56 -20
- package/types/generated/modules/music/Music.d.ts +5 -3
- package/types/generated/modules/net/index.d.ts +3 -3
- package/types/generated/modules/net/transports.d.ts +12 -3
- package/types/generated/modules/particles/Particles.d.ts +13 -6
- package/types/generated/modules/sky/Sky.d.ts +85 -110
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/timeline/Timeline.d.ts +8 -6
- package/types/generated/modules/water/Water.d.ts +50 -3
- package/types/generated/modules/weather/Weather.d.ts +44 -15
- package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
- package/types/generated/modules/world/World.d.ts +20 -5
- package/types/generated/render/PostFX.d.ts +109 -29
- package/types/generated/render/lighting.d.ts +29 -0
- package/types/generated/render/materials.d.ts +31 -50
- package/types/generated/render/modeling.d.ts +30 -0
- package/types/generated/render/occlusion.d.ts +13 -0
- package/types/generated/render/patches.d.ts +16 -2
- package/types/generated/ui/UI.d.ts +6 -3
- package/types/nav.d.ts +6 -0
- package/types/physics.d.ts +140 -45
- package/types/tsl.d.ts +94 -0
- package/types/world.d.ts +489 -122
- package/ui/Focus.js +35 -14
- package/ui/LoadingScreen.js +3 -3
- package/ui/Parts.js +35 -15
- package/ui/UI.js +27 -17
- package/ui/cursor.js +115 -0
- package/ui/defaults.js +15 -11
- package/ui/theme.js +36 -27
- package/ui/touchPart.js +2 -2
- package/core/claims.js +0 -51
- package/core/look/coreParts.js +0 -112
- package/core/look/layers.js +0 -136
- package/core/look/part.js +0 -173
- package/core/look/report.js +0 -79
- package/core/look/write.js +0 -86
- package/core/renamed.js +0 -22
- package/core/styleParts.js +0 -98
- package/docs/api/entities.md +0 -61
- package/docs/api/style.md +0 -134
- package/docs/recipes/09-style-pack.md +0 -169
- package/docs/recipes/35-style-from-reference.md +0 -84
- package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
- package/docs/recipes/38-environment-look-hooks.md +0 -88
- package/docs/recipes/41-thing-registry.md +0 -93
- package/docs/recipes/43-shader-patches-surface-looks.md +0 -135
- package/docs/recipes/44-water-weather-look-hooks.md +0 -135
- package/docs/recipes/48-make-material.md +0 -70
- package/docs/recipes/52-look.md +0 -146
- package/examples/action/look.js +0 -5
- package/examples/sheepisland/style/index.js +0 -79
- package/examples/styletest/look.js +0 -11
- package/examples/styletest/overrides.js +0 -33
- package/examples/styletest/panel.js +0 -135
- package/modules/entities/Entities.js +0 -243
- package/modules/entities/build.js +0 -25
- package/modules/entities/index.js +0 -4
- package/modules/sky/calendar.js +0 -80
- package/modules/sky/cascades.js +0 -125
- package/modules/sky/layers.js +0 -69
- package/modules/sky/look.js +0 -51
- package/modules/sky/lookFog.js +0 -80
- package/modules/sky/lookShadow.js +0 -50
- package/modules/sky/lookSky.js +0 -108
- package/modules/sky/shadow.js +0 -74
- package/modules/terrain/chunkLevels.js +0 -40
- package/modules/terrain/lookGround.js +0 -61
- package/modules/terrain/mountTerrain.js +0 -32
- package/modules/vegetation/lookWind.js +0 -37
- package/modules/water/look.js +0 -80
- package/modules/weather/look.js +0 -75
- package/modules/world/cells.js +0 -42
- package/render/lookSurface.js +0 -161
- package/render/postLook.js +0 -86
- package/render/surface.js +0 -69
- package/types/style.d.ts +0 -643
package/modules/sky/cascades.js
DELETED
|
@@ -1,125 +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, and photo mode's setShadowMapSize sharpens the cascade that matters most. The other cascades are extra
|
|
6
|
-
// DirectionalLights that copy the sun's color and intensity every frame.
|
|
7
|
-
// - Materials get the cascade lighting through one named patch, 'csm' (render/patches.js), never CSM.setupMaterial: that assigns
|
|
8
|
-
// material.onBeforeCompile and would drop every other patch (wind, clouds, season, detail, lighting), and CSM.dispose deletes it.
|
|
9
|
-
// - The chunk swap is per material (the patch replaces <lights_fragment_begin>): CSM's constructor overwrites ShaderChunk globally and
|
|
10
|
-
// never restores it, which would reach every material and every engine on the page; here _injectInclude does nothing.
|
|
11
|
-
// - Every lit material in the scene must carry the patch: without it the cascade lights would add up (N times the sunlight). So while
|
|
12
|
-
// cascades are on, each frame walks the scene and patches lit materials it has not seen (one Map lookup per mesh).
|
|
13
|
-
// - csm.update() runs only on frames whose shadow maps re-render (shadow.updateEvery), else lights move while the maps stay old.
|
|
14
|
-
import * as THREE from 'three';
|
|
15
|
-
import { CSM } from 'three/addons/csm/CSM.js';
|
|
16
|
-
import { CSMShader } from 'three/addons/csm/CSMShader.js';
|
|
17
|
-
import { patchMaterial, unpatchMaterial } from '../../render/patches.js';
|
|
18
|
-
|
|
19
|
-
const LIT = new Set(['MeshLambertMaterial', 'MeshPhongMaterial', 'MeshStandardMaterial', 'MeshPhysicalMaterial', 'MeshToonMaterial']);
|
|
20
|
-
const lit = m => m.isShaderMaterial ? m.lights && m.fragmentShader.includes('#include <lights_fragment_begin>') : LIT.has(m.type);
|
|
21
|
-
const SPLITS = ['practical', 'uniform', 'logarithmic'];
|
|
22
|
-
const STRINGS = {
|
|
23
|
-
count: 'look.shadow.set({ cascades }): a whole number 1 (one shadow map, the default) to 4; got {got}',
|
|
24
|
-
split: "look.shadow.set({ split }): 'practical' (default) | 'uniform' | 'logarithmic' | (count, near, far, out) => void; got {got}",
|
|
25
|
-
maxFar: 'look.shadow.set({ maxFar }): meters from the camera that cascades cover, a number > 0; got {got}',
|
|
26
|
-
noSun: "look.shadow.set({ cascades }): cascaded shadows split the engine sun's shadow, and sky({ sun: false }) has no engine sun. " +
|
|
27
|
-
"With your own lights use three's CSM addon on them, or keep sun: true / 'manual'",
|
|
28
|
-
};
|
|
29
|
-
const bad = (k, v) => { throw new Error(STRINGS[k].replace('{got}', JSON.stringify(v) ?? String(v))); };
|
|
30
|
-
|
|
31
|
-
/** Throw on cascade fields a look.shadow.set call gets wrong, before anything is applied */
|
|
32
|
-
export function checkCascades(sky, o) {
|
|
33
|
-
if (o.cascades !== undefined && !(Number.isInteger(o.cascades) && o.cascades >= 1 && o.cascades <= 4)) bad('count', o.cascades);
|
|
34
|
-
if (o.split !== undefined && typeof o.split !== 'function' && !SPLITS.includes(o.split)) bad('split', o.split);
|
|
35
|
-
if (o.maxFar !== undefined && !(o.maxFar > 0)) bad('maxFar', o.maxFar);
|
|
36
|
-
if (o.cascades > 1 && sky._drive.sun === false) bad('noSun');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// The addon's split / frustum / texel-snapped placement, with the sun as cascade 0 and the chunk swap left to the 'csm' patch
|
|
40
|
-
class SkyCSM extends CSM {
|
|
41
|
-
constructor(sky, S) {
|
|
42
|
-
const e = sky.engine, custom = typeof S.split === 'function';
|
|
43
|
-
super({ camera: e.camera, parent: e.scene, cascades: S.cascades, maxFar: S.maxFar, mode: custom ? 'custom' : S.split, customSplitsCallback: custom ? S.split : undefined,
|
|
44
|
-
shadowMapSize: sky.sun.shadow.mapSize.x, shadowBias: S.bias, lightMargin: S.lightMargin, lightNear: 1, lightFar: S.lightMargin + 2 * S.maxFar });
|
|
45
|
-
const first = this.lights[0];
|
|
46
|
-
this.parent.remove(first, first.target); first.dispose();
|
|
47
|
-
this.lights[0] = sky.sun;
|
|
48
|
-
// uniforms shared by every patched material: one write here reaches all of them
|
|
49
|
-
this.uniforms = { CSM_cascades: { value: [] }, cameraNear: { value: 0 }, shadowFar: { value: 0 } };
|
|
50
|
-
this.fade = S.fade;
|
|
51
|
-
this.updateFrustums();
|
|
52
|
-
// cacheKey is new for every build: three keeps a material's old programs and, when a key comes back (cascades off, then on again),
|
|
53
|
-
// reuses that program with the uniforms map of the material's latest compile, which lacks these uniforms, so the GPU would keep the
|
|
54
|
-
// old build's split and far values (shadows vanish where the old cascade 0 ended). One recompile per switch, which the light count
|
|
55
|
-
// change costs anyway; each material keeps one program per switch until it is disposed, so switch on a settings screen, not per frame
|
|
56
|
-
sky._csmBuild = (sky._csmBuild ?? 0) + 1;
|
|
57
|
-
this.patch = { name: 'csm', cacheKey: `${S.cascades}${S.fade ? 'f' : ''}.${sky._csmBuild}`, uniforms: this.uniforms, glsl: { fragment: {
|
|
58
|
-
pars: `#define USE_CSM 1\n#define CSM_CASCADES ${S.cascades}\n${S.fade ? '#define CSM_FADE\n' : ''}` +
|
|
59
|
-
'uniform vec2 CSM_cascades[CSM_CASCADES];\nuniform float cameraNear;\nuniform float shadowFar;',
|
|
60
|
-
lights_fragment_begin: { replace: CSMShader.lights_fragment_begin } } } };
|
|
61
|
-
/** material -> the patch object it carries, so a rebuilt CSM re-patches and switching off finds every material */
|
|
62
|
-
this.mats = new Map();
|
|
63
|
-
this.at = new THREE.Vector3(Infinity, 0, 0); // camera position at the last placement
|
|
64
|
-
this.proj = '';
|
|
65
|
-
this.visit = o => { if (!o.isMesh) return; const ms = o.material; if (Array.isArray(ms)) for (const m of ms) this.fit(m); else if (ms) this.fit(ms); };
|
|
66
|
-
}
|
|
67
|
-
fit(m) { if (this.mats.get(m) !== this.patch && lit(m)) { patchMaterial(m, [this.patch], { strict: false }); this.mats.set(m, this.patch); } }
|
|
68
|
-
_injectInclude() {}
|
|
69
|
-
_updateUniforms() {
|
|
70
|
-
const U = this.uniforms;
|
|
71
|
-
if (!U) return; // the base constructor calls this before the uniforms exist
|
|
72
|
-
this._getExtendedBreaks(U.CSM_cascades.value);
|
|
73
|
-
U.cameraNear.value = this.camera.near; U.shadowFar.value = Math.min(this.camera.far, this.maxFar);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** Create, rebuild or remove the cascades after look.shadow.set changed shadow fields; copy bias / softness to the extra lights */
|
|
78
|
-
export function syncCascades(sky) {
|
|
79
|
-
const S = sky.shadow, e = sky.engine, want = S.cascades > 1;
|
|
80
|
-
const key = want ? [S.cascades, S.maxFar, S.fade, S.lightMargin, S.split].join('|') : '';
|
|
81
|
-
if (key !== sky._csmKey) {
|
|
82
|
-
dropCascades(sky);
|
|
83
|
-
sky._csmKey = key;
|
|
84
|
-
if (want) {
|
|
85
|
-
const sc = sky.sun.shadow.camera;
|
|
86
|
-
sky._csmSaved = { left: sc.left, right: sc.right, top: sc.top, bottom: sc.bottom, near: sc.near, far: sc.far };
|
|
87
|
-
sky.csm = new SkyCSM(sky, S);
|
|
88
|
-
Object.assign(sc, { near: 1, far: sky.csm.lightFar });
|
|
89
|
-
// these lights are new to the scene: honor engine.setShadows(false) the way it treats existing lights
|
|
90
|
-
for (const l of sky.csm.lights) if (l !== sky.sun) l.castShadow = e.shadows;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (sky.csm) for (const l of sky.csm.lights) Object.assign(l.shadow, { bias: S.bias, normalBias: S.normalBias, radius: S.radius, blurSamples: S.blurSamples });
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** Remove the cascades: extra lights out, the 'csm' patch off every material it went on, the sun's shadow box restored */
|
|
97
|
-
export function dropCascades(sky) {
|
|
98
|
-
const c = sky.csm;
|
|
99
|
-
if (!c) return;
|
|
100
|
-
for (const l of c.lights) if (l !== sky.sun) { c.parent.remove(l, l.target); l.dispose(); }
|
|
101
|
-
for (const m of c.mats.keys()) unpatchMaterial(m, 'csm');
|
|
102
|
-
const sc = sky.sun.shadow.camera;
|
|
103
|
-
Object.assign(sc, sky._csmSaved); sc.updateProjectionMatrix();
|
|
104
|
-
sky.csm = null; sky._csmKey = ''; sky._snapKey = '';
|
|
105
|
-
sky.engine.renderer.shadowMap.needsUpdate = true;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/** Per frame while cascades are on (instead of _placeShadow): patch new materials, follow the camera and the light, place on shadow frames */
|
|
109
|
-
export function cascadeFrame(sky, lightDir) {
|
|
110
|
-
const c = sky.csm, e = sky.engine, cam = e.camera, sun = sky.sun, S = sky.shadow, sm = e.renderer.shadowMap;
|
|
111
|
-
e.scene.traverse(c.visit);
|
|
112
|
-
const proj = cam.isPerspectiveCamera ? `${cam.fov},${cam.aspect},${cam.near},${cam.far},${cam.zoom}` : `${cam.left},${cam.right},${cam.near},${cam.far},${cam.zoom}`;
|
|
113
|
-
let force = false;
|
|
114
|
-
if (c.camera !== cam || proj !== c.proj) { c.camera = cam; c.proj = proj; c.updateFrustums(); force = true; }
|
|
115
|
-
c.lightDirection.copy(lightDir).negate(); // CSM points from the light into the scene
|
|
116
|
-
const show = sun.visible && e.shadows; // with shadows off the extra lights would only add light: hide them
|
|
117
|
-
for (const l of c.lights) if (l !== sun) { l.color.copy(sun.color); l.intensity = sun.intensity; l.visible = show; }
|
|
118
|
-
cam.updateMatrixWorld();
|
|
119
|
-
// not updating every frame: also place early when the camera left a quarter of the nearest cascade (teleport, fast travel)
|
|
120
|
-
const near = c.breaks[0] * Math.min(cam.far, c.maxFar);
|
|
121
|
-
if (S.updateEvery <= 1 || sm.needsUpdate || force || c.at.distanceToSquared(cam.position) > (near / 4) ** 2) {
|
|
122
|
-
c.update(); c.at.copy(cam.position);
|
|
123
|
-
if (S.updateEvery > 1) sm.needsUpdate = true;
|
|
124
|
-
}
|
|
125
|
-
}
|
package/modules/sky/layers.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
// Sky modifier layers (mixed into Sky.prototype): weather and games each write their own layer with modify(); every frame the sky
|
|
2
|
-
// composites them into sky.modifiers and applies the result on top of its own colors and light. A layer may also lay a cover color
|
|
3
|
-
// (snow, ash, frost) over the foliage / ground season tint (applyCover).
|
|
4
|
-
import * as THREE from 'three';
|
|
5
|
-
import { checkOptions } from '../../core/validate.js';
|
|
6
|
-
|
|
7
|
-
const LAYER_KEYS = ['sun', 'ambient', 'fog', 'tint', 'tintAmount', 'horizonTintAmount', 'flash', 'foliageCover', 'groundCover', 'coverAmount'];
|
|
8
|
-
/** A layer that changes nothing (also the starting value of sky.modifiers) */
|
|
9
|
-
export const blankLayer = () => ({ sun: 1, ambient: 1, fog: 1, tint: new THREE.Color(0x888888), tintAmount: 0, horizonTintAmount: 0, flash: 0 });
|
|
10
|
-
|
|
11
|
-
export const layerMethods = {
|
|
12
|
-
/** Write a modifier layer (only the given fields); null removes it. See the JSDoc on Sky.modify */
|
|
13
|
-
modify(owner, values) {
|
|
14
|
-
if (values == null) { this._layers.delete(owner); this._checked.delete(owner); return this; }
|
|
15
|
-
// a per-frame writer (weather) reuses one object: its keys are checked once, not every frame
|
|
16
|
-
if (this._checked.get(owner) !== values) { checkOptions(`sky.modify('${owner}')`, values, LAYER_KEYS); this._checked.set(owner, values); }
|
|
17
|
-
let L = this._layers.get(owner);
|
|
18
|
-
if (!L) this._layers.set(owner, L = blankLayer());
|
|
19
|
-
for (const k in values) {
|
|
20
|
-
if (k === 'tint') L.tint.set(values.tint);
|
|
21
|
-
else if (k === 'foliageCover' || k === 'groundCover') L[k] = values[k] == null ? null : (L[k] ?? new THREE.Color()).set(values[k]);
|
|
22
|
-
else if (k in L || k === 'coverAmount') L[k] = values[k];
|
|
23
|
-
}
|
|
24
|
-
return this;
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
// composite all layers -> modifiers: sun / ambient / fog multiply; tint blends weighted by tintAmount; flash takes the max
|
|
28
|
-
_combine() {
|
|
29
|
-
const M = this.modifiers;
|
|
30
|
-
M.sun = M.ambient = M.fog = 1; M.flash = 0;
|
|
31
|
-
let r = 0, g = 0, b = 0, w = 0, keep = 1, keepH = 1;
|
|
32
|
-
for (const L of this._layers.values()) {
|
|
33
|
-
M.sun *= L.sun; M.ambient *= L.ambient; M.fog *= L.fog; M.flash = Math.max(M.flash, L.flash);
|
|
34
|
-
const a = Math.max(L.tintAmount, L.horizonTintAmount);
|
|
35
|
-
r += L.tint.r * a; g += L.tint.g * a; b += L.tint.b * a; w += a;
|
|
36
|
-
keep *= 1 - L.tintAmount; keepH *= 1 - L.horizonTintAmount;
|
|
37
|
-
}
|
|
38
|
-
if (w > 0) M.tint.setRGB(r / w, g / w, b / w);
|
|
39
|
-
M.tintAmount = 1 - keep; M.horizonTintAmount = 1 - keepH;
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const tmp = new THREE.Color(), acc = new THREE.Color();
|
|
44
|
-
/**
|
|
45
|
-
* Lay the layers' cover colors over the season tint uniforms (after applySeason), reusing the season patch instead of a second
|
|
46
|
-
* shader pass. Nothing is touched while no layer covers, so the default look and a game that writes the tint uniforms itself keep
|
|
47
|
-
* working. The patch draws mix(color, tint, m) (multiply when m is 0); a cover of amount a over mix m1 is again one mix:
|
|
48
|
-
* m = 1 - (1 - m1)(1 - a), tint = (T1 m1 (1 - a) + cover a) / m. A season in 'multiply' mode (m1 = 0) gives way to the cover.
|
|
49
|
-
*/
|
|
50
|
-
export function applyCover(sky, U) {
|
|
51
|
-
let on = false;
|
|
52
|
-
// no calendar seasons: nothing rewrites the tint every frame, so start from neutral (and return to it once the cover is gone)
|
|
53
|
-
const calendar = sky.seasonStyle && sky.seasons.length;
|
|
54
|
-
for (const [part, T, mix] of [['foliageCover', U.uFoliageTint, U.uFoliageMix], ['groundCover', U.uGroundTint, U.uGroundMix]]) {
|
|
55
|
-
let a = 0, keep = 1; acc.setRGB(0, 0, 0);
|
|
56
|
-
for (const L of sky._layers.values()) {
|
|
57
|
-
const c = L[part], k = c ? Math.min(1, Math.max(0, L.coverAmount ?? 0)) : 0;
|
|
58
|
-
if (k > 0) { acc.add(tmp.copy(c).multiplyScalar(k)); a += k; keep *= 1 - k; }
|
|
59
|
-
}
|
|
60
|
-
if (!calendar && (a > 0 || sky._covered)) { T.value.setRGB(1, 1, 1); mix.value = 0; }
|
|
61
|
-
if (a <= 0) continue;
|
|
62
|
-
on = true;
|
|
63
|
-
const amt = 1 - keep, m1 = mix.value, m = 1 - (1 - m1) * (1 - amt);
|
|
64
|
-
acc.multiplyScalar(amt / a); // the layers' weighted cover color, times the combined amount
|
|
65
|
-
T.value.multiplyScalar(m1 * (1 - amt)).add(acc).multiplyScalar(1 / m);
|
|
66
|
-
mix.value = m;
|
|
67
|
-
}
|
|
68
|
-
sky._covered = on;
|
|
69
|
-
}
|
package/modules/sky/look.js
DELETED
|
@@ -1,51 +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: 'manual' }) the sky still aims it along the time of day and moves the shadow box; color and intensity are the game's
|
|
5
|
-
// sky({ sun: false }) hidden (visible = false, no shadows) and never touched: light the world with your own three.js lights
|
|
6
|
-
// sky({ hemisphere: true | 'manual' | false }) the same for engine.lights.hemi (ambient): 'manual' leaves its colors and intensity alone
|
|
7
|
-
// sky({ fog: true | 'manual' | false }) scene.fog: true (default) the sky creates it and writes color and distance every frame |
|
|
8
|
-
// 'manual' created once, then never written (the game sets color / near / far / its own object) |
|
|
9
|
-
// false scene.fog = null and never touched. An object here is style.sky.fog settings (= true)
|
|
10
|
-
// Hidden lights are left in the scene (visible = false): three skips them, and toggling visible later recompiles like adding a light would.
|
|
11
|
-
import * as THREE from 'three';
|
|
12
|
-
import { resolveFog, domeFog } from './fog.js';
|
|
13
|
-
import { resolveDomeLayers } from './domeLayers.js';
|
|
14
|
-
|
|
15
|
-
const MODES = [true, false, 'manual'];
|
|
16
|
-
const modeOf = (name, v = true) => {
|
|
17
|
-
if (!MODES.includes(v)) throw new Error(`sky({ ${name} }) must be true (the sky drives it), 'manual' (the game sets its color and intensity) or false (hidden, light the world yourself); got ${JSON.stringify(v)}`);
|
|
18
|
-
return v;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/** Resolve light modes, fog and dome layers for a new Sky; returns the extra dome uniforms and GLSL ({ uniforms, decl, body }) */
|
|
22
|
-
export function prepareLook(sky, st, over) {
|
|
23
|
-
/** @internal which engine lights the sky writes each frame: true / 'manual' / false */
|
|
24
|
-
// fog is also the look override (an object of style.sky.fog settings, which means true); a boolean or 'manual' picks the mode and keeps the style's settings
|
|
25
|
-
const fogObj = over.fog != null && typeof over.fog === 'object';
|
|
26
|
-
sky._drive = { sun: modeOf('sun', over.sun), hemi: modeOf('hemisphere', over.hemisphere), fog: fogObj ? true : modeOf('fog', over.fog) };
|
|
27
|
-
const { sun, hemi } = sky.engine.lights;
|
|
28
|
-
if (sky._drive.sun === false) { sun.visible = false; sun.castShadow = false; }
|
|
29
|
-
if (sky._drive.hemi === false) hemi.visible = false;
|
|
30
|
-
/** @internal resolved fog settings (fog.js) */
|
|
31
|
-
sky._fogSpec = fogObj || over.fog == null ? st.fog : sky.engine.style.sky?.fog; // look.fog's style layer (lookFog.js)
|
|
32
|
-
sky._fog = resolveFog(sky._fogSpec);
|
|
33
|
-
sky._backdrop = resolveBackdrop(st);
|
|
34
|
-
const f = domeFog(sky._fog), l = resolveDomeLayers(st.layers);
|
|
35
|
-
const uniforms = { ...l.uniforms };
|
|
36
|
-
// the fog object is created after the dome, and its color is rewritten each frame: read it at draw time
|
|
37
|
-
if (f.decl) uniforms.uFogColor = { get value() { return sky.engine.scene.fog?.color ?? sky.uniforms.uHorizon.value; } }; // no fog object (fog: false): fade to the horizon
|
|
38
|
-
return { uniforms, decl: [f.decl, l.decl].filter(Boolean).join('\n'), body: f.body + l.body };
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// style.sky.backdrop: one flat color (or (sky) => color each frame) instead of the dome -- no gradient, horizon, sun / moon disk,
|
|
42
|
-
// stars or clouds. The color goes straight to scene.background (no tone mapping), so what is written is what shows; the keyframes
|
|
43
|
-
// still light the world, and fog in its default 'horizon' color follows the backdrop so far things fade into it.
|
|
44
|
-
export function resolveBackdrop(st) {
|
|
45
|
-
const v = st.backdrop;
|
|
46
|
-
if (v == null) return null;
|
|
47
|
-
const color = typeof v === 'number' || typeof v === 'string' || v.isColor;
|
|
48
|
-
if (!color && typeof v !== 'function') throw new Error(`style.sky.backdrop must be a color (0xefebe4, '#efebe4') or (sky) => color; got ${JSON.stringify(v)}`);
|
|
49
|
-
if (st.skybox) throw new Error('style.sky: backdrop and skybox both replace the dome; keep one (backdrop for a flat color, skybox for a panorama)');
|
|
50
|
-
return { fn: color ? null : v, color: new THREE.Color(color ? v : 0x000000) };
|
|
51
|
-
}
|
package/modules/sky/lookFog.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
// look.fog: the sky's fog as a look part. set({ kind, color, density, near, far, height, falloff, enabled }), patch('fog', glsl), replace('manual' | THREE.Fog).
|
|
2
|
-
// The sky still writes color and distance every frame (updateFog in fog.js) from the resolved values, so a game set() simply changes what it writes.
|
|
3
|
-
// What cannot change after the first frame: kind 'exp' / 'height', height, falloff and the 'fog' hook replace three's shared fog_* shader chunks, and
|
|
4
|
-
// three compiles each material once (fog.js explains). Those are accepted before the first frame (style, sky({ fog }), or right after createEngine) and
|
|
5
|
-
// throw afterwards, naming the way out. kind linear <-> exp2, color, density, near, far, enabled work live. The dome's horizon band (a fog-colored fade
|
|
6
|
-
// so the horizon line hides) is part of the dome shader and exists only when the start color was not 'horizon'.
|
|
7
|
-
import { defineLookPart, REPLACE } from '../../core/look/part.js';
|
|
8
|
-
import { resolveFog, makeFog, applyFogChunks, FOG_KINDS } from './fog.js';
|
|
9
|
-
|
|
10
|
-
const LATE = "look.fog: {what} changes three.js's shared fog shader chunks, which are compiled once per material, so it can only be set before the first frame " +
|
|
11
|
-
"(style.sky.fog, sky({ fog }), or right after createEngine). Live now: color, density, near, far, enabled, and kind 'linear' <-> 'exp2'";
|
|
12
|
-
const chunkKey = f => (f.glsl ? JSON.stringify([f.kind, f.height, f.falloff, f.glsl]) : '');
|
|
13
|
-
|
|
14
|
-
/** @param {any} sky @param {object} spec the style.sky.fog settings in use (look.js keeps them in sky._fogSpec) */
|
|
15
|
-
export function defineFogLook(sky, spec) {
|
|
16
|
-
const e = sky.engine, scene = e.scene;
|
|
17
|
-
const rendered = () => (e.renderer?.info?.render?.frame ?? 0) > 0;
|
|
18
|
-
let part;
|
|
19
|
-
sky._fogHeld = false;
|
|
20
|
-
sky._fogKey = chunkKey(sky._fog);
|
|
21
|
-
const late = (key, what) => v => (rendered() && v !== part?.value(key) && (sky._fogKey || (key === 'kind' && (v === 'exp' || v === 'height'))) ? LATE.replace('{what}', what) : null);
|
|
22
|
-
|
|
23
|
-
const rebuild = () => {
|
|
24
|
-
const v = part.values(), glsl = part.value('hook:fog');
|
|
25
|
-
const f = resolveFog({ kind: v.kind, color: v.color, density: v.density ?? undefined, height: v.height, falloff: v.falloff, near: v.near ?? undefined,
|
|
26
|
-
far: v.far ?? undefined, enabled: v.enabled, glsl: typeof glsl === 'string' ? glsl : undefined });
|
|
27
|
-
const key = chunkKey(f);
|
|
28
|
-
if (key !== sky._fogKey) {
|
|
29
|
-
if (rendered()) throw new Error(LATE.replace('{what}', 'this fog change'));
|
|
30
|
-
sky._fogOff();
|
|
31
|
-
try { sky._fogOff = applyFogChunks(f); } catch (err) { sky._fogOff = applyFogChunks(sky._fog); throw err; }
|
|
32
|
-
sky._fogKey = key;
|
|
33
|
-
}
|
|
34
|
-
sky._fog = f;
|
|
35
|
-
// linear is three's Fog, every other kind FogExp2: swap the object (materials recompile for it) when the kind crossed that line
|
|
36
|
-
const cur = scene.fog;
|
|
37
|
-
if (sky._drive.fog === true && !sky._fogHeld && cur && (f.kind === 'linear' ? !cur.isFog : !cur.isFogExp2)) {
|
|
38
|
-
scene.fog = makeFog(f, f.far ?? e.fogFar); scene.fog.color.copy(cur.color);
|
|
39
|
-
for (const o of sky._owned ?? []) o.mark();
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
part = defineLookPart(e, {
|
|
44
|
-
id: 'fog', group: 'atmosphere', module: 'sky', object: () => scene.fog, applyAtStart: false, docs: ['recipes/52-look.md', 'recipes/38-sky.md'],
|
|
45
|
-
params: {
|
|
46
|
-
enabled: { type: 'bool', default: true, cost: 'uniform', desc: 'fog on / off without a recompile',
|
|
47
|
-
why: 'distant things melt into the sky and the edge of a streamed world is hidden', off: 'look.fog.set({ enabled: false }), or sky({ fog: false })' },
|
|
48
|
-
kind: { type: 'string', default: 'linear', values: FOG_KINDS, cost: 'shader', desc: "'linear' | 'exp' | 'exp2' | 'height'", neutral: true,
|
|
49
|
-
check: late('kind', "kind 'exp' / 'height'") },
|
|
50
|
-
color: { type: 'any', default: 'horizon', cost: 'uniform', desc: "'horizon' (the dome's horizon color, written every frame) | a color | (sky) => color", neutral: true },
|
|
51
|
-
density: { type: 'any', default: null, cost: 'uniform', neutral: true, desc: 'per meter for exp / exp2 / height; null = derived so the fog reaches the same distance as linear' },
|
|
52
|
-
far: { type: 'any', default: null, cost: 'uniform', desc: 'fog distance in meters (weather scales it); null = engine.fogFar (createEngine, terrain view range)',
|
|
53
|
-
why: 'fog reaches full strength at engine.fogFar (600 by default), starting at 0.3 x that', off: 'look.fog.set({ enabled: false })' },
|
|
54
|
-
near: { type: 'any', default: null, cost: 'uniform', neutral: true, desc: 'linear only: where the fog starts; null = 0.3 x far' },
|
|
55
|
-
height: { type: 'number', default: 0, neutral: true, cost: 'shader', desc: "kind 'height': the fog's floor (world y)", check: late('height', 'height') },
|
|
56
|
-
falloff: { type: 'number', default: 0.05, min: 0, neutral: true, cost: 'shader', desc: "kind 'height': how fast it thins above the floor (per meter)", check: late('falloff', 'falloff') },
|
|
57
|
-
},
|
|
58
|
-
style: () => {
|
|
59
|
-
const s = spec ?? {};
|
|
60
|
-
return { ...Object.fromEntries(['enabled', 'kind', 'color', 'density', 'far', 'near', 'height', 'falloff'].filter(k => s[k] != null).map(k => [k, s[k]])),
|
|
61
|
-
...(s.glsl ? { 'hook:fog': s.glsl } : {}) };
|
|
62
|
-
},
|
|
63
|
-
apply() { rebuild(); },
|
|
64
|
-
hooks: { fog: { signature: 'vec4 threedogFog(vec3 color, float depth, vec3 worldPos)', scope: ['fogColor', 'cameraPosition', 'fogNear / fogFar (linear)', 'fogDensity (other kinds)', 'THREEDOG_FOG_HEIGHT', 'THREEDOG_FOG_FALLOFF'],
|
|
65
|
-
example: 'vec4 threedogFog(vec3 color, float depth, vec3 worldPos){ return vec4(color, 1.0 - exp(-fogDensity * depth)); }' } },
|
|
66
|
-
applyHook(name, glsl) {
|
|
67
|
-
rebuild();
|
|
68
|
-
},
|
|
69
|
-
// wrong hook GLSL or replace value stops here, before any layer is written
|
|
70
|
-
validate: (k, v) => k === 'hook:fog' ? (typeof v === 'string' && /vec4\s+threedogFog\s*\(/.test(v) ? null : 'needs GLSL that defines `vec4 threedogFog(vec3 color, float depth, vec3 worldPos)` returning (fog rgb, amount 0..1)')
|
|
71
|
-
: k === REPLACE && v !== 'manual' && !v?.isFog && !v?.isFogExp2 ? "is 'manual' or a THREE.Fog / THREE.FogExp2; null gives the fog back to the sky" : null,
|
|
72
|
-
replace: { accepts: "'manual' (the sky stops writing scene.fog) | a THREE.Fog / FogExp2 (becomes scene.fog)", loses: ['weather fog distance (sky.modify fog)', 'the sky-colored horizon fade'] },
|
|
73
|
-
applyReplace(impl) {
|
|
74
|
-
sky._fogHeld = impl != null;
|
|
75
|
-
if (impl?.isFog || impl?.isFogExp2) scene.fog = impl;
|
|
76
|
-
else if (impl == null && sky._drive.fog === true) scene.fog = makeFog(sky._fog, sky._fog.far ?? e.fogFar);
|
|
77
|
-
for (const o of sky._owned ?? []) o.mark(); // the dev guard re-reads the fog it watches
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// look.shadow: the sun's shadow as a look part (set only: the csm patch is internal, and a game that wants its own shadows lights with its own lights).
|
|
2
|
-
// Why a part: the type / cascades / bias a game set were invisible to describe(); now every key says who set it.
|
|
3
|
-
// the work itself is Sky._applyShadow (shadow.js).
|
|
4
|
-
import { defineLookPart } from '../../core/look/part.js';
|
|
5
|
-
import { SHADOW_TYPES } from '../../core/shadowTypes.js';
|
|
6
|
-
|
|
7
|
-
const SPLITS = ['practical', 'uniform', 'logarithmic'];
|
|
8
|
-
const KEYS = ['bias', 'normalBias', 'updateEvery', 'snap', 'ahead', 'type', 'radius', 'blurSamples', 'cascades', 'maxFar', 'fade', 'lightMargin', 'split'];
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @param {any} sky @param {object} sh shadowFor(...) at start: becomes the style layer (style.sky.shadow, tier-adjusted, merged with sky({ shadow }))
|
|
12
|
-
*/
|
|
13
|
-
export function defineShadowLook(sky, sh) {
|
|
14
|
-
const e = sky.engine, sun = sky.sun;
|
|
15
|
-
const cost = 'shadow pass';
|
|
16
|
-
defineLookPart(e, {
|
|
17
|
-
id: 'shadow', group: 'atmosphere', module: 'sky', object: () => sun.shadow, docs: ['recipes/52-look.md', 'recipes/45-cascaded-shadows.md'],
|
|
18
|
-
params: {
|
|
19
|
-
enabled: { type: 'bool', default: e.shadows, cost, desc: 'master shadow switch (engine.setShadows)',
|
|
20
|
-
why: 'the sun casts shadows (createEngine({ shadows }) is the start value)', off: 'look.shadow.set({ enabled: false }), or createEngine({ shadows: false })' },
|
|
21
|
-
type: { type: 'string', default: e.shadowType, values: Object.keys(SHADOW_TYPES), neutral: true, cost, desc: "'basic' hard edge | 'pcf' | 'vsm' softest; switching recompiles materials, do it rarely" },
|
|
22
|
-
radius: { type: 'number', default: 1, min: 0, neutral: true, cost: 'uniform', desc: 'edge softness (pcf, vsm)' },
|
|
23
|
-
blurSamples: { type: 'int', default: 8, min: 1, neutral: true, cost, desc: 'blur quality (vsm only)' },
|
|
24
|
-
bias: { type: 'number', default: -0.0006, neutral: true, cost: 'uniform', desc: 'depth bias against acne' },
|
|
25
|
-
normalBias: { type: 'number', default: 0.04, neutral: true, cost: 'uniform', desc: 'normal offset against acne (meters)' },
|
|
26
|
-
mapSize: { type: 'int', default: 2048, min: 64, neutral: true, cost: 'gpu', desc: 'shadow map pixels (the nearest cascade with cascades)' },
|
|
27
|
-
updateEvery: { type: 'int', default: 1, min: 1, neutral: true, cost, desc: 'update the shadow map every N frames' },
|
|
28
|
-
snap: { type: 'any', default: 0.5, neutral: true, cost: 'uniform', desc: "shadow center snap grid in meters, or 'texel'" },
|
|
29
|
-
ahead: { type: 'number', default: 0, neutral: true, cost: 'uniform', desc: 'meters the shadow center is shifted in front of the view' },
|
|
30
|
-
cascades: { type: 'int', default: 1, neutral: true, cost, desc: '1 = one shadow map; 2-4 = cascaded shadows (recipes/45)',
|
|
31
|
-
check: v => (v < 1 || v > 4 ? `must be a whole number 1 (one shadow map, the default) to 4; got ${v}` : v > 1 && sky._drive.sun === false ? "cannot be above 1: cascades split the engine sun's shadow, and sky({ sun: false }) has no engine sun" : null) },
|
|
32
|
-
maxFar: { type: 'number', default: 120, min: 0.001, neutral: true, cost: 'uniform', desc: 'meters from the camera that cascades cover' },
|
|
33
|
-
fade: { type: 'bool', default: true, neutral: true, cost: 'uniform', desc: 'cascades blend into each other' },
|
|
34
|
-
lightMargin: { type: 'number', default: 100, neutral: true, cost: 'uniform', desc: 'meters the cascade lights sit behind their frustum' },
|
|
35
|
-
split: { type: 'any', default: 'practical', neutral: true, cost: 'uniform', desc: "'practical' | 'uniform' | 'logarithmic' | (count, near, far, out) => void",
|
|
36
|
-
check: v => (typeof v === 'function' || SPLITS.includes(v) ? null : `must be ${SPLITS.map(s => `'${s}'`).join(' | ')} or a function (count, near, far, out) => void; got ${JSON.stringify(v)}`) },
|
|
37
|
-
},
|
|
38
|
-
style: () => ({ ...Object.fromEntries(KEYS.filter(k => sh[k] !== undefined).map(k => [k, sh[k]])), ...(sh.mapSize !== undefined ? { mapSize: sh.mapSize } : {}) }),
|
|
39
|
-
read: () => ({ enabled: e.shadows, type: e.shadowType, radius: sun.shadow.radius, mapSize: sun.shadow.mapSize.x, bias: sun.shadow.bias, normalBias: sun.shadow.normalBias }),
|
|
40
|
-
apply(v, changed) {
|
|
41
|
-
const o = {};
|
|
42
|
-
for (const k of changed) if (KEYS.includes(k)) o[k] = v[k];
|
|
43
|
-
if (changed.has('enabled') && v.enabled !== e.shadows) e.setShadows(v.enabled);
|
|
44
|
-
if (changed.has('mapSize')) sky.setShadowMapSize(v.mapSize);
|
|
45
|
-
if (Object.keys(o).length) sky._applyShadow(o);
|
|
46
|
-
},
|
|
47
|
-
noPatch: "the cascade patch ('csm') is internal; change the shadows with look.shadow.set({ type, radius, cascades, ... })",
|
|
48
|
-
noReplace: 'to own the shadows, light the world with your own three.js lights: sky({ sun: false }) or createEngine({ lights: false })',
|
|
49
|
-
});
|
|
50
|
-
}
|
package/modules/sky/lookSky.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
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
|
-
}
|
package/modules/sky/shadow.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// Chunk loading detail: forcing one chunk ready now and choosing per-species detail level by ring (mixed into ChunkManager.prototype).
|
|
2
|
-
// Split out of ChunkManager.js; the methods use the manager state (chunks, ready, edits, T, density) through this.
|
|
3
|
-
|
|
4
|
-
/** Stand-in for engine.vegetation when the vegetation module is not installed */
|
|
5
|
-
export const NO_VEG = { baseNames: () => [], nearNames: () => [], list: () => [], get: () => null };
|
|
6
|
-
|
|
7
|
-
export const chunkLevels = {
|
|
8
|
-
_forceReady(c) {
|
|
9
|
-
if (c.state === 'ready') return true;
|
|
10
|
-
const i = this.ready.findIndex(r => r.terrain && r.cx === c.cx && r.cz === c.cz && r.gen === c.gen && r.ev === this.edits.version(c.key));
|
|
11
|
-
let r = i >= 0 ? this.ready.splice(i, 1)[0] : null;
|
|
12
|
-
if (!r) {
|
|
13
|
-
const veg = this.engine.vegetation || NO_VEG;
|
|
14
|
-
r = { terrain: this.T.buildChunk(c.cx, c.cz), veg: {} };
|
|
15
|
-
for (const name of veg.baseNames()) r.veg[name] = this.T.place(c.cx, c.cz, veg.get(name).rule, this.density);
|
|
16
|
-
}
|
|
17
|
-
this._applyTerrain(c, r.terrain);
|
|
18
|
-
for (const name in r.veg) this._applyVeg(c, name, r.veg[name]);
|
|
19
|
-
c.level = -1;
|
|
20
|
-
return true;
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
_setLevel(c, ring) {
|
|
24
|
-
if (c.level === ring) return;
|
|
25
|
-
c.level = ring;
|
|
26
|
-
const veg = this.engine.vegetation || NO_VEG;
|
|
27
|
-
for (const sp of veg.list()) {
|
|
28
|
-
const im = c.veg[sp.name];
|
|
29
|
-
if (sp.nearOnly) {
|
|
30
|
-
// detailDone: this species was already placed here and came back empty; without it the empty result would reset the level and re-ask forever
|
|
31
|
-
if (ring <= sp.maxRing && !im && !c.pendingDetail && !c.detailDone.has(sp.name)) {
|
|
32
|
-
c.pendingDetail = true;
|
|
33
|
-
this._send(this._job(c, false, veg.nearNames()));
|
|
34
|
-
} else if (ring > sp.maxRing + 1 && im) { veg.unmount(c, sp.name); c.detailDone.delete(sp.name); }
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
if (im) veg.levelOf(im, sp, ring);
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
};
|