threedog 0.5.0 → 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 +81 -1
- package/README.md +21 -13
- package/core/Assets.js +23 -12
- package/core/Audio.js +1 -1
- package/core/Baked.js +14 -23
- package/core/Budget.js +2 -2
- package/core/DebugOverrides.js +33 -18
- package/core/Describe.js +10 -11
- package/core/Engine.js +50 -46
- package/core/I18n.js +2 -2
- package/core/Input.js +11 -5
- package/core/Inspect.js +6 -3
- package/core/InspectMaterials.js +2 -3
- package/core/InspectPerf.js +11 -4
- package/core/MaterialInfo.js +7 -5
- package/core/Rays.js +7 -2
- package/core/Stream.js +2 -3
- package/core/UrlState.js +49 -9
- package/core/Views.js +1 -0
- package/core/adaptive.js +2 -2
- package/core/assetEntry.js +5 -2
- package/core/assetLoad.js +13 -15
- package/core/assetManifest.js +6 -3
- package/core/assetReport.js +4 -4
- package/core/batchGroups.js +9 -1
- package/core/catalog.js +16 -3
- package/core/chunkStream.js +1 -1
- package/core/copies.js +1 -1
- package/core/debugView.js +4 -4
- package/core/describeRender.js +104 -28
- package/core/describeText.js +6 -6
- package/core/errorCodes.js +72 -45
- package/core/errorHints.js +4 -1
- package/core/errors.js +4 -4
- package/core/events.generated.js +1 -0
- package/core/gameLights.js +9 -2
- package/core/lifecycle.js +2 -4
- package/core/lightWatch.js +5 -3
- package/core/loop.js +18 -11
- package/core/math.js +7 -0
- package/core/moduleSlots.js +32 -7
- package/core/moduleTypes.js +20 -7
- package/core/modules.js +7 -7
- package/core/namedModel.js +8 -4
- package/core/owned.js +33 -30
- package/core/page.js +43 -10
- package/core/pictureSlots.js +33 -0
- package/core/pictureWriters.js +343 -0
- package/core/plugins.js +64 -96
- package/core/sceneDelta.js +12 -4
- package/core/sceneMethods.js +2 -9
- package/core/services.js +1 -1
- package/core/shadowTypes.js +1 -1
- package/core/shadows.js +405 -0
- package/core/sharedPoint.js +5 -19
- package/core/stackFrames.js +16 -5
- package/core/stacks.js +6 -6
- package/core/startup.js +9 -11
- package/core/thingExplain.js +1 -1
- package/core/things.js +1 -1
- package/core/tier.js +1 -1
- package/core/util.js +1 -1
- package/core/validate.js +1 -1
- package/core/view.js +43 -0
- package/docs/AI.md +62 -58
- package/docs/API.md +15 -15
- package/docs/CODEMAP.md +36 -54
- package/docs/COMMANDS.md +28 -25
- package/docs/CONVENTIONS.md +36 -30
- package/docs/MIGRATING-0.4.md +93 -1
- package/docs/MIGRATING-0.6.md +126 -0
- package/docs/MIGRATING-0.7.md +39 -0
- package/docs/THREE.md +24 -22
- package/docs/api/assets.md +5 -3
- package/docs/api/audio.md +2 -2
- package/docs/api/budget.md +4 -0
- package/docs/api/characters.md +3 -1
- package/docs/api/collision.md +2 -2
- package/docs/api/engine.md +47 -20
- package/docs/api/events.md +2 -1
- package/docs/api/grids.md +8 -1
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +3 -0
- package/docs/api/input.md +3 -2
- package/docs/api/interactions.md +3 -1
- package/docs/api/inventory.md +1 -2
- package/docs/api/level.md +0 -1
- package/docs/api/lightPool.md +1 -1
- package/docs/api/occlusion.md +5 -0
- package/docs/api/particles.md +6 -3
- package/docs/api/pickups.md +6 -0
- package/docs/api/post.md +5 -3
- package/docs/api/sky.md +12 -10
- package/docs/api/terrain.md +12 -6
- package/docs/api/terrainDraw.md +12 -0
- package/docs/api/tools.md +8 -7
- package/docs/api/triggers.md +2 -0
- package/docs/api/vegetation.md +7 -2
- package/docs/api/vegetationDraw.md +10 -0
- package/docs/api/water.md +6 -2
- package/docs/api/weather.md +5 -0
- package/docs/api/weatherDraw.md +10 -0
- package/docs/api/world.md +1 -1
- package/docs/recipes/01-new-game.md +19 -23
- package/docs/recipes/03-items-pickups.md +25 -4
- package/docs/recipes/05-props-bake.md +53 -37
- package/docs/recipes/06-clock-events.md +3 -3
- package/docs/recipes/07-flow-scenes-pause.md +12 -3
- package/docs/recipes/08-weather-sky.md +45 -57
- package/docs/recipes/09-materials-lights-models.md +185 -0
- package/docs/recipes/10-blender-level.md +2 -2
- package/docs/recipes/11-vehicles.md +3 -3
- package/docs/recipes/13-animation.md +13 -7
- package/docs/recipes/14-custom-module.md +7 -5
- package/docs/recipes/15-perf.md +3 -3
- package/docs/recipes/16-dev-bridge.md +22 -12
- package/docs/recipes/18-world.md +10 -8
- package/docs/recipes/19-shooting-picking.md +7 -5
- package/docs/recipes/20-content-actions-save.md +6 -2
- package/docs/recipes/21-camera.md +8 -3
- package/docs/recipes/23-ops.md +1 -1
- package/docs/recipes/26-ui-parts.md +35 -11
- package/docs/recipes/28-terrain.md +12 -12
- package/docs/recipes/29-grid.md +14 -5
- package/docs/recipes/30-templates.md +8 -3
- package/docs/recipes/31-audio.md +4 -4
- package/docs/recipes/32-action-game.md +18 -4
- package/docs/recipes/34-environment-lighting.md +102 -38
- 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 -13
- package/docs/recipes/38-environment-hooks.md +67 -0
- package/docs/recipes/40-scene.md +106 -27
- package/docs/recipes/42-terrain-shape.md +1 -1
- package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +66 -77
- package/docs/recipes/44-water-weather-hooks.md +191 -0
- package/docs/recipes/45-cascaded-shadows.md +121 -23
- package/docs/recipes/46-blender-art-route.md +17 -20
- package/docs/recipes/47-island-snow-backdrop.md +10 -12
- package/docs/recipes/49-game-module-contract.md +1 -1
- package/docs/recipes/50-own-renderer.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 +18 -18
- package/docs/recipes/55-mods-time-wrap.md +17 -5
- package/docs/recipes/56-webgpu-tsl.md +66 -23
- package/docs/recipes/57-control.md +39 -0
- 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 +39 -24
- 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 -1
- package/examples/action/GAMEMAP.md +7 -5
- 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/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 +31 -9
- package/examples/rc2d/GAMEMAP.md +8 -3
- package/examples/rc2d/README.md +11 -6
- package/examples/rc2d/main.js +25 -33
- 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/sheepisland/.threedog/content-index.json +1 -1
- package/examples/sheepisland/GAMEMAP.md +13 -10
- package/examples/sheepisland/assets.js +2 -2
- package/examples/sheepisland/content/templates.js +1 -1
- package/examples/sheepisland/content/vegetation.js +3 -1
- package/examples/sheepisland/main.js +15 -9
- 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 -1
- package/examples/styletest/GAMEMAP.md +15 -11
- 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 +30 -67
- 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 +4 -3
- 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 +5 -3
- 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 +9 -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 +15 -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 +7 -16
- package/index.js +7 -7
- package/llms.txt +15 -13
- package/modules/ambience/Ambience.js +1 -1
- package/modules/calendar/Calendar.js +1 -1
- package/modules/calendar/index.js +1 -0
- package/modules/camera/FirstPersonCamera.js +1 -1
- package/modules/camera/FixedCamera.js +2 -2
- package/modules/camera/RtsCamera.js +1 -1
- package/modules/camera/common.js +7 -5
- package/modules/characters/Character.js +15 -10
- package/modules/characters/NPC.js +5 -5
- package/modules/characters/assetModel.js +5 -4
- package/modules/characters/index.js +28 -3
- package/modules/characters/movers/common.js +6 -1
- package/modules/characters/movers/manual.js +3 -0
- package/modules/characters/movers/support.js +25 -11
- package/modules/characters/npcSim.js +5 -1
- package/modules/characters/proceduralRig.js +18 -4
- package/modules/characters/useModel.js +2 -2
- package/modules/collision/Collision.js +4 -2
- package/modules/content/index.js +8 -0
- package/modules/content/models.js +56 -11
- package/modules/content/props.js +5 -3
- package/modules/content/rules.js +12 -4
- package/modules/content/templates.js +5 -3
- package/modules/gameplay/Interactions.js +91 -16
- package/modules/gameplay/Inventory.js +3 -3
- package/modules/gameplay/dialogueBox.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +1 -1
- package/modules/gameplay/interactionPrompt.js +1 -1
- package/modules/gameplay/interactions.contract.js +1 -1
- package/modules/gameplay/inventoryOps.js +2 -2
- package/modules/gameplay/pickups.js +62 -24
- package/modules/gameplay/questLog.js +2 -2
- package/modules/grid/Layer.js +13 -0
- package/modules/grid/index.js +40 -11
- package/modules/grid/preview.js +24 -15
- package/modules/grid/tiles.js +15 -19
- package/modules/hlod/index.js +3 -2
- package/modules/hud/index.js +13 -0
- package/modules/hud/parts.js +9 -7
- package/modules/level/index.js +5 -4
- package/modules/lights/index.js +12 -8
- package/modules/music/Music.js +1 -1
- package/modules/particles/Particles.js +41 -20
- package/modules/particles/effect.js +21 -6
- package/modules/photo/Photo.js +11 -10
- package/modules/settings/Settings.js +7 -7
- package/modules/settings/apply.js +5 -5
- package/modules/settings/sections.js +2 -2
- package/modules/settings/strings.js +1 -1
- package/modules/sky/Sky.js +104 -89
- package/modules/sky/clouds.js +16 -17
- package/modules/sky/dome.js +100 -0
- package/modules/sky/domeLayers.js +5 -5
- package/modules/sky/environment.js +45 -169
- package/modules/sky/fog.js +5 -180
- package/modules/sky/frame.js +26 -90
- package/modules/sky/season.js +3 -3
- package/modules/sky/shader.js +35 -29
- package/modules/sky/skyModule.js +25 -22
- package/modules/sky/tint.js +9 -11
- package/modules/terrain/ChunkManager.js +29 -12
- package/modules/terrain/draw.js +154 -0
- package/modules/terrain/index.js +44 -66
- package/modules/terrain/terrainDefaults.js +2 -2
- package/modules/terrain/terrainEdit.js +1 -1
- package/modules/terrain/terrainGen.js +2 -2
- package/modules/triggers/index.js +10 -6
- package/modules/vegetation/Vegetation.js +58 -17
- package/modules/vegetation/draw.js +191 -0
- package/modules/vegetation/groundChunks.js +1 -1
- package/modules/vegetation/index.js +10 -10
- package/modules/water/Water.js +135 -88
- package/modules/water/surface.js +53 -53
- package/modules/weather/Weather.js +52 -17
- package/modules/weather/particles.js +13 -5
- package/modules/weather/shaders.js +1 -1
- package/modules/weather/weatherDraw.js +141 -0
- package/modules/world/World.js +2 -2
- package/modules/world/views.js +1 -1
- package/package.json +3 -2
- package/presets.js +2 -2
- package/render/PostFX.js +199 -41
- package/render/backend.js +52 -6
- package/render/cascades.js +195 -0
- package/render/cascades.tsl.js +96 -0
- package/render/daylight.js +39 -0
- package/render/detail.js +5 -5
- package/render/effects.js +41 -26
- package/render/fx/cel.tsl.js +42 -0
- package/render/fx/index.js +7 -5
- package/render/fx/patchNodes.tsl.js +1 -1
- package/render/fx/postWebGPU.tsl.js +30 -7
- package/render/fx/sky.tsl.js +19 -92
- package/render/fx/water.tsl.js +1 -1
- package/render/layers.js +14 -0
- package/render/lighting.js +6 -5
- package/render/lightmap.js +142 -0
- package/render/lights.js +23 -201
- package/render/materials.js +44 -160
- package/render/neutral.js +23 -0
- package/render/occlusion.js +184 -0
- package/render/ownFrame.js +1 -1
- package/render/patches.js +34 -29
- package/render/postWebGL.js +11 -3
- package/render/probes.js +179 -122
- package/render/slots.js +4 -4
- package/render/terms.js +53 -101
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +333 -296
- package/types/gameplay.d.ts +65 -26
- package/types/generated/core/Audio.d.ts +1 -1
- package/types/generated/core/DebugOverrides.d.ts +14 -6
- package/types/generated/core/Input.d.ts +9 -2
- package/types/generated/core/page.d.ts +9 -2
- package/types/generated/modules/grid/Layer.d.ts +8 -0
- package/types/generated/modules/grid/index.d.ts +29 -5
- package/types/generated/modules/particles/Particles.d.ts +13 -6
- package/types/generated/modules/sky/Sky.d.ts +85 -18
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/water/Water.d.ts +50 -3
- package/types/generated/modules/weather/Weather.d.ts +33 -3
- package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
- package/types/generated/modules/world/World.d.ts +2 -2
- package/types/generated/render/PostFX.d.ts +53 -10
- package/types/generated/render/lighting.d.ts +29 -0
- package/types/generated/render/materials.d.ts +19 -44
- package/types/generated/render/occlusion.d.ts +13 -0
- package/types/physics.d.ts +5 -3
- package/types/tsl.d.ts +8 -0
- package/types/world.d.ts +376 -57
- package/ui/Focus.js +12 -2
- package/ui/LoadingScreen.js +2 -2
- package/ui/Parts.js +8 -4
- package/ui/UI.js +10 -10
- package/ui/cursor.js +1 -1
- package/ui/theme.js +33 -27
- package/ui/touchPart.js +1 -1
- 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/styleParts.js +0 -114
- 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/38-environment-look-hooks.md +0 -99
- package/docs/recipes/41-thing-registry.md +0 -97
- package/docs/recipes/44-water-weather-look-hooks.md +0 -144
- package/docs/recipes/48-make-material.md +0 -75
- package/docs/recipes/52-look.md +0 -282
- package/examples/action/look.js +0 -5
- 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/modules/weather/weatherLook.d.ts +0 -12
- package/types/style.d.ts +0 -671
package/modules/sky/lookSky.js
DELETED
|
@@ -1,169 +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
|
-
// set({ keyframes, sunSize, sunGlow, sunBrightness, moonSize, moonColor, moonBrightness, starDensity, starScale, gradientCurve, groundTint,
|
|
4
|
-
// orbitTilt, orbitSway, dim: { tint, stars } }) the rest of style.sky's look, live (uniforms and the sky's per-frame inputs)
|
|
5
|
-
// patch('clouds', glsl | { glsl, tsl, uniforms }) the cloud function threedogClouds (clouds.js), the one way to write your own; null gives the built-in kind back
|
|
6
|
-
// patch('layer:<name>', glsl | { glsl, tsl, uniforms, order, blend }) add or change a named dome layer (domeLayers.js); null removes it
|
|
7
|
-
// tsl: the WebGPURenderer form of either hook, (ctx) => vec4 node (render/fx/sky.tsl.js); each renderer draws its own form, a missing one throws by name
|
|
8
|
-
// replace(skybox name | Texture | Object3D) the dome gives way to a panorama or your own background object; null gives the dome back
|
|
9
|
-
// Dome layers are addressed by name; a style's array of layers (style.sky.layers) names its entries by their `name` key, else layer0, layer1 ...
|
|
10
|
-
// 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).
|
|
11
|
-
import { engineOwned } from '../../core/things.js';
|
|
12
|
-
import * as THREE from 'three';
|
|
13
|
-
import { defineLookPart, REPLACE } from '../../core/look/part.js';
|
|
14
|
-
import { resolveClouds } from './clouds.js';
|
|
15
|
-
import { resolveDomeLayers } from './domeLayers.js';
|
|
16
|
-
import { domeFragment, loadSkybox, skyNodes, checkKeyframes, NEUTRAL_KEYFRAMES } from './shader.js';
|
|
17
|
-
import { DOME_FOG } from './fog.js';
|
|
18
|
-
import { isWebGPU } from '../../render/backend.js';
|
|
19
|
-
import { resolveBackdrop } from './look.js';
|
|
20
|
-
|
|
21
|
-
const LAYER = 'layer:';
|
|
22
|
-
const CLOUD_KEYS = { 'clouds.coverage': 'uCloudCover', 'clouds.scale': 'uCloudScale', 'clouds.speed': 'uCloudSpeed', 'clouds.opacity': 'uCloudOpacity',
|
|
23
|
-
'clouds.softness': 'uCloudSoft', 'clouds.color': 'uCloudColor', 'clouds.shade': 'uCloudShade' };
|
|
24
|
-
// the dome's own uniforms behind the style.sky look keys (shader.js makeSkyUniforms reads the same keys at build)
|
|
25
|
-
const DOME_KEYS = { sunSize: 'uSunSize', sunGlow: 'uSunGlow', sunBrightness: 'uSunPower', moonBrightness: 'uMoonPower', moonSize: 'uMoonSize',
|
|
26
|
-
moonColor: 'uMoonColor', starDensity: 'uStars', starScale: 'uStarScale', gradientCurve: 'uCurve' };
|
|
27
|
-
/** The style.sky keys that are look.sky params (sky() no longer takes them; skyModule.js throws naming look.sky.set) */
|
|
28
|
-
export const SKY_LOOK_KEYS = [...Object.keys(DOME_KEYS), 'keyframes', 'groundTint', 'orbitTilt', 'orbitSway', 'dim'];
|
|
29
|
-
const DIM_WHY = 'the sky dims what it draws for every game unless the style says no (types/style.d.ts StyleSky.dim)';
|
|
30
|
-
const isColorLike = v => typeof v === 'number' || typeof v === 'string' || !!v?.isColor;
|
|
31
|
-
const colorOrFn = v => (isColorLike(v) || typeof v === 'function' ? null : `must be a color (0xefebe4, '#efebe4') or ({ time, state }) => color; got ${JSON.stringify(v)}`);
|
|
32
|
-
|
|
33
|
-
/** @param {any} sky @param {object} st style.sky merged with the sky({ ... }) options (which hold no look keys: those are style.sky's only) */
|
|
34
|
-
export function defineSkyLook(sky, st) {
|
|
35
|
-
const e = sky.engine, scene = e.scene, U = sky.uniforms;
|
|
36
|
-
let part, added = null, addedHere = false;
|
|
37
|
-
const layers = new Map((Array.isArray(st.layers) ? st.layers : []).map((l, i) => [l?.name ?? `layer${i}`, l]));
|
|
38
|
-
|
|
39
|
-
// The dome shader from the current clouds function and layers; throws (changing nothing) when a hook is not valid for its contract
|
|
40
|
-
const rebuild = (cloudsHook, map) => {
|
|
41
|
-
// WebGPU dome (node material, render/fx/sky.tsl.js): the hooks' tsl forms, checked there before anything changes (apply)
|
|
42
|
-
const gpu = isWebGPU(e.renderer);
|
|
43
|
-
const cl = resolveClouds(st.clouds, cloudsHook, gpu);
|
|
44
|
-
const l = resolveDomeLayers([...map.values()].map(v => (typeof v === 'string' ? { glsl: v } : v)), { gpu, names: [...map.keys()] });
|
|
45
|
-
if (gpu) return { nodes: { kind: cl.kind, clouds: cloudsHook ?? null, layers: l.layers }, uniforms: { ...cl.uniforms, ...l.uniforms } };
|
|
46
|
-
const f = DOME_FOG; // the fog band is always in the dome, switched by a uniform (fog.js)
|
|
47
|
-
const text = domeFragment(cl, { decl: [f.decl, l.decl].filter(Boolean).join('\n'), body: f.body + l.body });
|
|
48
|
-
return { text, uniforms: { ...cl.uniforms, ...l.uniforms } };
|
|
49
|
-
};
|
|
50
|
-
const apply = r => {
|
|
51
|
-
// node dome: a new color node over the uniforms with the hook's own added (setHooks throws first on a bad hook, the dome unchanged)
|
|
52
|
-
if (r.nodes) skyNodes(e).setHooks(sky.dome.material, { ...r.uniforms, ...U }, r.nodes.kind, e, r.nodes);
|
|
53
|
-
for (const [k, u] of Object.entries(r.uniforms)) if (!(k in U)) U[k] = u;
|
|
54
|
-
if (r.nodes) return;
|
|
55
|
-
if (sky.dome.material.fragmentShader === r.text) return;
|
|
56
|
-
sky.dome.material.fragmentShader = r.text; sky.dome.material.needsUpdate = true;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
// the renderer swap (Sky.js) builds a fresh dome from the style; the hooks set since then go back on it
|
|
60
|
-
sky._lookHooks = () => apply(rebuild(part.value('hook:clouds'), layers));
|
|
61
|
-
|
|
62
|
-
const setBackdrop = v => {
|
|
63
|
-
if (v == null) { sky._backdrop = null; sky.dome.visible = !sky.skybox && !added; scene.background = sky.skybox ?? null; return; }
|
|
64
|
-
sky._backdrop = resolveBackdrop({ backdrop: v }); // the sky writes scene.background and hides the dome each frame (frame.js)
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
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'],
|
|
68
|
-
tsl: 'WebGPU: { glsl, tsl: ({ dir, time, sunDir, night, lit, shade, cover, clouds, uniforms, fx: { noise, hash }, tsl }) => vec4 }',
|
|
69
|
-
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); }' },
|
|
70
|
-
[LAYER + '<name>']: { signature: 'vec4 threedogSkyLayer(vec3 dir, float time, vec3 sunDir, float night)', scope: ['threedogHash', 'threedogNoise', 'uTop', 'uHorizon', 'uSunColor ...'],
|
|
71
|
-
tsl: 'WebGPU: { glsl, tsl: ({ dir, time, sunDir, night, color, uniforms, fx: { noise, hash }, tsl }) => vec4 (rgb, amount) }',
|
|
72
|
-
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' })" } };
|
|
73
|
-
// layer:<name> takes any name: the spec lists one documented entry, the check accepts the prefix
|
|
74
|
-
const hookSpec = new Proxy(hooks, { has: (t, k) => k in t || (typeof k === 'string' && /^layer:[\w-]+$/.test(k)) });
|
|
75
|
-
|
|
76
|
-
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',
|
|
77
|
-
softness: 'edge softness', color: 'lit side color', shade: 'shaded side color' };
|
|
78
|
-
const num = d => ({ type: 'number', min: 0, cost: 'uniform', neutral: true, desc: d });
|
|
79
|
-
const kfCheck = v => { try { checkKeyframes(v); return null; } catch (err) { return err.message; } };
|
|
80
|
-
part = defineLookPart(e, {
|
|
81
|
-
id: 'sky', group: 'atmosphere', module: 'sky', object: () => sky.dome, applyAtStart: false, docs: ['recipes/52-look.md', 'recipes/36-sky-ground-plant-looks.md'],
|
|
82
|
-
params: {
|
|
83
|
-
// all neutral: with coverage 0 (no clouds unless the style gives them) nothing of these is drawn
|
|
84
|
-
'clouds.coverage': { ...num(cloudDesc.coverage), neutral: true, default: 0 },
|
|
85
|
-
'clouds.scale': { ...num(cloudDesc.scale), neutral: true, default: 0.35 },
|
|
86
|
-
'clouds.speed': { type: 'array', default: [0.004, 0.002], neutral: true, cost: 'uniform', desc: cloudDesc.speed },
|
|
87
|
-
'clouds.opacity': { ...num(cloudDesc.opacity), neutral: true, default: 0.9 },
|
|
88
|
-
'clouds.softness': { ...num(cloudDesc.softness), neutral: true, default: 0.3 },
|
|
89
|
-
'clouds.color': { type: 'any', default: '#f4f4f4', neutral: true, cost: 'uniform', desc: cloudDesc.color },
|
|
90
|
-
'clouds.shade': { type: 'any', default: '#aaaaaa', neutral: true, cost: 'uniform', desc: cloudDesc.shade },
|
|
91
|
-
backdrop: { type: 'any', default: null, neutral: true, fn: true, cost: 'uniform', desc: 'a flat color (or ({ time, state }) => color) in place of the dome: no gradient, sun, moon, stars or clouds; null = the dome',
|
|
92
|
-
check: colorOrFn },
|
|
93
|
-
// over the keyframes (null = the keyframes' color): a fixed color, or a function of the frame context (core/look/state.js) evaluated by frame.js
|
|
94
|
-
top: { type: 'any', default: null, neutral: true, fn: true, cost: 'uniform', desc: "zenith color over style.sky.keyframes: a color or ({ time, weather, season, state, sky }) => color; null = the keyframes", check: colorOrFn },
|
|
95
|
-
keyframes: { type: 'array', default: NEUTRAL_KEYFRAMES, neutral: true, cost: 'uniform', check: kfCheck,
|
|
96
|
-
desc: 'rows [time, zenith, horizon, lightColor, lightIntensity, ambient] sorted from 0 to 1: the dome colors and the sun / hemisphere light over the day' },
|
|
97
|
-
sunSize: { ...num('sharpness exponent of the sun disk (larger = smaller)'), neutral: true, default: 900 },
|
|
98
|
-
sunGlow: { ...num('sun glow'), neutral: true, default: 0.18 },
|
|
99
|
-
sunBrightness: { ...num('sun disk brightness'), neutral: true, default: 6 },
|
|
100
|
-
moonSize: { ...num('sharpness exponent of the moon disk (larger = smaller)'), neutral: true, default: 1400 },
|
|
101
|
-
moonColor: { type: 'any', default: 0xdcdcdc, neutral: true, cost: 'uniform', desc: 'moon disk color' },
|
|
102
|
-
moonBrightness: { ...num('moon disk brightness'), neutral: true, default: 3 },
|
|
103
|
-
starDensity: { ...num('share of sky grid cells holding a star at night, 0-1 (0 = none)'), max: 1, neutral: true, default: 0.0025 },
|
|
104
|
-
starScale: { ...num('star grid resolution: larger = smaller, more numerous stars'), neutral: true, default: 260 },
|
|
105
|
-
gradientCurve: { ...num('horizon-to-zenith gradient exponent'), neutral: true, default: 0.55 },
|
|
106
|
-
groundTint: { type: 'any', default: 0x4a4a4a, neutral: true, cost: 'uniform', desc: 'ground bounce color of the hemisphere light' },
|
|
107
|
-
orbitTilt: { type: 'number', default: 0.45, neutral: true, cost: 'uniform', desc: 'north-south tilt of the sun path' },
|
|
108
|
-
orbitSway: { type: 'number', default: 0.8, neutral: true, cost: 'uniform', desc: 'east-west swing of the sun path' },
|
|
109
|
-
'dim.tint': { type: 'bool', default: true, cost: 'uniform', why: DIM_WHY, off: 'look.sky.set({ dim: { tint: false } })', desc: "a sky.tint color dims with the sky's own light" },
|
|
110
|
-
'dim.stars': { type: 'bool', default: true, cost: 'uniform', why: DIM_WHY, off: 'look.sky.set({ dim: { stars: false } })', desc: "stars fade with the weather's cloud cover" },
|
|
111
|
-
horizon: { type: 'any', default: null, neutral: true, fn: true, cost: 'uniform', desc: "horizon color over the keyframes (fog 'horizon' and the hemisphere follow it): a color or a function; null = the keyframes. The color drawn this frame (for your own shader): engine.uniforms.uSkyHorizon", check: colorOrFn },
|
|
112
|
-
},
|
|
113
|
-
style: () => ({
|
|
114
|
-
'clouds.coverage': U.uCloudCover.value, 'clouds.scale': U.uCloudScale.value, 'clouds.speed': U.uCloudSpeed.value.toArray(), 'clouds.opacity': U.uCloudOpacity.value,
|
|
115
|
-
'clouds.softness': U.uCloudSoft.value, 'clouds.color': '#' + U.uCloudColor.value.getHexString(), 'clouds.shade': '#' + U.uCloudShade.value.getHexString(),
|
|
116
|
-
...(st.backdrop != null ? { backdrop: st.backdrop } : {}),
|
|
117
|
-
...Object.fromEntries(SKY_LOOK_KEYS.filter(k => k !== 'dim' && st[k] != null).map(k => [k, st[k]])),
|
|
118
|
-
...Object.fromEntries(['tint', 'stars'].filter(k => st.dim?.[k] != null).map(k => [`dim.${k}`, st.dim[k]])),
|
|
119
|
-
...Object.fromEntries([...layers].map(([n, l]) => [`hook:${LAYER}${n}`, l])),
|
|
120
|
-
...(st.skybox ? { [REPLACE]: st.skybox } : {}),
|
|
121
|
-
}),
|
|
122
|
-
apply(v, changed) {
|
|
123
|
-
for (const k of changed) {
|
|
124
|
-
if (DOME_KEYS[k]) { const d = U[DOME_KEYS[k]]; if (d.value?.isColor) d.value.set(v[k]); else d.value = v[k]; continue; }
|
|
125
|
-
if (k === 'keyframes') { sky._setKeyframes(v[k]); continue; }
|
|
126
|
-
if (k === 'groundTint') { sky.groundTint.set(v[k]); continue; }
|
|
127
|
-
if (k === 'orbitTilt' || k === 'orbitSway') { sky.orbit[k === 'orbitTilt' ? 'tilt' : 'sway'] = v[k]; continue; }
|
|
128
|
-
if (k === 'dim.tint') { sky.dim.tint = v[k]; continue; }
|
|
129
|
-
if (k === 'dim.stars') { sky.dim.stars = v[k]; U.uStarCloudDim.value = v[k] ? 1 : 0; continue; }
|
|
130
|
-
const u = CLOUD_KEYS[k];
|
|
131
|
-
if (!u) continue;
|
|
132
|
-
if (k === 'clouds.speed') U[u].value.set(v[k][0], v[k][1]);
|
|
133
|
-
else if (U[u].value?.isColor) U[u].value.set(v[k]);
|
|
134
|
-
else U[u].value = v[k];
|
|
135
|
-
}
|
|
136
|
-
if (changed.has('backdrop')) setBackdrop(v.backdrop);
|
|
137
|
-
},
|
|
138
|
-
hooks: hookSpec,
|
|
139
|
-
applyHook(name, glsl) {
|
|
140
|
-
if (name === 'clouds') { apply(rebuild(glsl, layers)); return; }
|
|
141
|
-
const n = name.slice(LAYER.length), next = new Map(layers);
|
|
142
|
-
if (glsl == null) next.delete(n); else next.set(n, glsl);
|
|
143
|
-
apply(rebuild(part.value('hook:clouds'), next)); // throws before anything changes when the layer's GLSL is not valid
|
|
144
|
-
layers.clear(); for (const [k, v] of next) layers.set(k, v);
|
|
145
|
-
},
|
|
146
|
-
validate: (k, v) => k !== REPLACE ? null : v === false ? 'false is not a sky: give the dome back with engine.look.sky.replace(null)'
|
|
147
|
-
: 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,
|
|
148
|
-
replace: { accepts: 'a skybox name (equirectangular panorama asset) | a THREE.Texture / CubeTexture | your own THREE.Object3D sky (three/addons Sky, a ShaderMaterial dome); the engine never writes it and keeps feeding engine.uniforms (uSunDir, uDaylight, uTimeOfDay, uWind ...)',
|
|
149
|
-
loses: ['the gradient dome, sun and moon discs, stars, clouds and dome layers (time, lights, fog, weather and the uniforms keep running)'] },
|
|
150
|
-
// The game's own sky (three/addons Sky, a ShaderMaterial dome, a skybox texture) is never written: the engine only hides its dome, adds the
|
|
151
|
-
// object to the scene when it has no parent yet (and takes it out again on hand-back only then), and keeps feeding time / weather / season
|
|
152
|
-
// through engine.uniforms (uSunDir, uDaylight, uTimeOfDay, uWind, uCloud ...) and the day / season / weather events. A plain Texture gets its
|
|
153
|
-
// panorama mapping on a clone, so the game's texture object stays as it was.
|
|
154
|
-
applyReplace(impl) {
|
|
155
|
-
if (added) { if (addedHere) scene.remove(added); added = null; addedHere = false; }
|
|
156
|
-
sky._ownSky = null;
|
|
157
|
-
if (impl == null) { sky.skybox = null; scene.background = sky._backdrop?.color ?? null; sky.dome.visible = !sky._backdrop; return; }
|
|
158
|
-
sky.dome.visible = false;
|
|
159
|
-
if (typeof impl === 'string') loadSkybox(sky, impl);
|
|
160
|
-
else if (impl.isTexture) {
|
|
161
|
-
const tex = impl.isCubeTexture || impl.mapping !== THREE.UVMapping ? impl : Object.assign(impl.clone(), { mapping: THREE.EquirectangularReflectionMapping });
|
|
162
|
-
scene.background = tex; sky.skybox = tex;
|
|
163
|
-
} else if (impl.isObject3D) {
|
|
164
|
-
addedHere = !impl.parent; if (addedHere) scene.add(engineOwned('sky', impl));
|
|
165
|
-
added = impl; sky._ownSky = impl; scene.background = null; sky.skybox = null;
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
});
|
|
169
|
-
}
|
package/modules/sky/shadow.js
DELETED
|
@@ -1,98 +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 { checkCascades, syncCascades } from './cascades.js';
|
|
4
|
-
import { setShadowUpdate, shadowUpdatePending, isWebGPU } from '../../render/backend.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Default sun shadow depth bias. three adds it in the shadow camera's 0-1 depth, which here spans near 1 to far 420 m, so it is a world offset of
|
|
8
|
-
* bias x 419 m: the old -0.0006 was 25 cm, and anything resting on the ground (a character's body, a crate, a step) lost the shadow at its base
|
|
9
|
-
* (demo finding 2026-11-02: "daytime shadows weak"). 2 cm keeps the contact shadow; acne is held by normalBias (0.04 m, measured on a sphere at low sun)
|
|
10
|
-
*/
|
|
11
|
-
export const SKY_BIAS = -0.00005;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 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,
|
|
15
|
-
* since skipping frames makes wind-swayed shadows stutter) and one shadow map (cascades redraw the casters once per cascade); the style's
|
|
16
|
-
* shadow.low overrides that, and sky({ shadow }) wins outright except for cascades, which stay at 1 on low unless its low.cascades says so
|
|
17
|
-
*/
|
|
18
|
-
export function shadowFor(tier, styleShadow = {}, optionShadow = undefined) {
|
|
19
|
-
if (optionShadow) { const { low, ...sh } = optionShadow; return tier === 'low' ? { ...sh, cascades: low?.cascades ?? 1 } : sh; }
|
|
20
|
-
const { low, ...sh } = styleShadow;
|
|
21
|
-
return tier === 'low' ? { ...sh, mapSize: Math.min(sh.mapSize ?? 2048, 1024), cascades: 1, ...low } : sh;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const shadowMethods = {
|
|
25
|
-
/** Apply shadow fields (engine.look.shadow.set(o): bias / normalBias, updateEvery, snap, ahead, 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) */
|
|
26
|
-
_applyShadow(o) {
|
|
27
|
-
const s = this.shadow;
|
|
28
|
-
checkCascades(this, o);
|
|
29
|
-
for (const k of Object.keys(s)) if (o[k] !== undefined) s[k] = o[k];
|
|
30
|
-
const sun = this._sun.shadow;
|
|
31
|
-
sun.bias = s.bias; sun.normalBias = s.normalBias; sun.radius = s.radius; sun.blurSamples = s.blurSamples;
|
|
32
|
-
if (o.extent !== undefined) { const c = sun.camera; c.left = c.bottom = -s.extent; c.right = c.top = s.extent; c.updateProjectionMatrix(); } // one map only: cascades size their own
|
|
33
|
-
syncCascades(this);
|
|
34
|
-
// after the cascades: on WebGPU the switch is per light, so the cascade lights just made get it too (render/backend.js).
|
|
35
|
-
// now: needed after a type switch when autoUpdate is off, otherwise the rebuilt map stays empty until the next scheduled update
|
|
36
|
-
setShadowUpdate(this.engine.renderer, this.engine.scene, { auto: s.updateEvery <= 1, now: true });
|
|
37
|
-
return this;
|
|
38
|
-
},
|
|
39
|
-
/** Call after rendering: when updateEvery > 1, request a shadow update every N frames */
|
|
40
|
-
afterRender() {
|
|
41
|
-
const n = this.shadow.updateEvery;
|
|
42
|
-
if (n > 1 && ++this._shadowFrame >= n) { this._shadowFrame = 0; setShadowUpdate(this.engine.renderer, this.engine.scene, { now: true }); this._shadowAt?.copy(this._sun.target.position); }
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Change shadow resolution (raise temporarily for photo mode); with cascades, every cascade's map. Why each one: the cascades copied the
|
|
47
|
-
* sun's size only when built (WebGL: extra lights; WebGPU: the node's per-cascade shadows), so a later change reached the nearest one at most.
|
|
48
|
-
* WebGL allocates a map only while shadow.map is null; WebGPU's shadow node resizes its own map from mapSize on every redraw.
|
|
49
|
-
*/
|
|
50
|
-
setShadowMapSize(n) {
|
|
51
|
-
const gpu = isWebGPU(this.engine.renderer), sun = this._sun;
|
|
52
|
-
let changed = false;
|
|
53
|
-
for (const sh of [sun.shadow, ...(this.csm?.lights ?? []).filter(l => l !== sun).map(l => l.shadow)]) {
|
|
54
|
-
if (sh.mapSize.x === n) continue;
|
|
55
|
-
sh.mapSize.set(n, n); changed = true;
|
|
56
|
-
if (!gpu) { sh.map?.dispose(); sh.map = null; }
|
|
57
|
-
}
|
|
58
|
-
if (changed) setShadowUpdate(this.engine.renderer, this.engine.scene, { now: true }); // a resized map is empty until redrawn (updateEvery > 1)
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
// 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
|
|
62
|
-
_placeShadow(focus, lightDir) {
|
|
63
|
-
const S = this.shadow, tp = this._sun.target.position, cam = this.engine.camera;
|
|
64
|
-
// owned (core/owned.js): a game that aims the sun itself keeps its direction (the box still follows); one that places the target keeps it
|
|
65
|
-
if (!this._oSunDir.on) lightDir = (this._gameDir ??= new THREE.Vector3()).subVectors(this._sun.position, tp).normalize();
|
|
66
|
-
const follow = S.follow ?? 'focus';
|
|
67
|
-
if (!this._oFollow.on || follow === false) { this._sun.position.copy(tp).addScaledVector(lightDir, this.orbit.distance); this._sun.target.updateMatrixWorld(); return; }
|
|
68
|
-
if (follow === 'camera') tp.copy(cam.position);
|
|
69
|
-
else if (follow?.isObject3D) follow.getWorldPosition(tp);
|
|
70
|
-
else if (typeof follow === 'function') tp.copy(follow());
|
|
71
|
-
else tp.copy(focus);
|
|
72
|
-
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); }
|
|
73
|
-
let key;
|
|
74
|
-
if (S.snap === 'texel') {
|
|
75
|
-
// the light-space right and up axes (matching the shadow camera lookAt), rounded to one shadow pixel along each
|
|
76
|
-
const sc = this._sun.shadow.camera, texel = (sc.right - sc.left) / this._sun.shadow.mapSize.x;
|
|
77
|
-
const f = this._f ??= new THREE.Vector3(), r = this._r ??= new THREE.Vector3(), u = this._u ??= new THREE.Vector3();
|
|
78
|
-
f.copy(lightDir).negate();
|
|
79
|
-
r.crossVectors(f, cam.up); if (r.lengthSq() < 1e-8) r.set(1, 0, 0); r.normalize();
|
|
80
|
-
u.crossVectors(r, f);
|
|
81
|
-
const a = Math.round(tp.dot(r) / texel), b = Math.round(tp.dot(u) / texel), c = tp.dot(f);
|
|
82
|
-
tp.copy(r).multiplyScalar(a * texel).addScaledVector(u, b * texel).addScaledVector(f, c);
|
|
83
|
-
key = a + ',' + b;
|
|
84
|
-
} else {
|
|
85
|
-
const g = S.snap || 1e-3;
|
|
86
|
-
tp.x = Math.round(tp.x / g) * g; tp.z = Math.round(tp.z / g) * g;
|
|
87
|
-
key = tp.x + ',' + tp.z;
|
|
88
|
-
}
|
|
89
|
-
// 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
|
|
90
|
-
if (S.updateEvery > 1 && key !== this._snapKey) {
|
|
91
|
-
const e = this.engine, last = this._shadowAt ??= tp.clone();
|
|
92
|
-
if (shadowUpdatePending(e.renderer, e.scene) || last.distanceToSquared(tp) > (this._sun.shadow.camera.right / 4) ** 2) { setShadowUpdate(e.renderer, e.scene, { now: true }); last.copy(tp); }
|
|
93
|
-
}
|
|
94
|
-
this._snapKey = key;
|
|
95
|
-
this._sun.position.copy(tp).addScaledVector(lightDir, this.orbit.distance);
|
|
96
|
-
this._sun.target.updateMatrixWorld();
|
|
97
|
-
},
|
|
98
|
-
};
|
package/modules/terrain/look.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
// Terrain look: draws the chunks the terrain data part (ChunkManager) generated. One mesh per chunk from the chunk's arrays (c.data: pos, nor,
|
|
2
|
-
// col, uv, tex), the ground material (style / terrain({ material }) / look.ground.replace), the per-chunk color map of shading 'texture',
|
|
3
|
-
// island side material, and frustum visibility. Installed by terrain() as its own module 'terrainLook' holding the slot 'terrain-look'.
|
|
4
|
-
//
|
|
5
|
-
// Why a separate module: collision, paths, engine.surface and vegetation read only the data part, so a game can swap the whole look
|
|
6
|
-
// (engine.use(myGround, { replaces: 'terrain-look' })) and keep everything that plays. A replacement look does what this file does:
|
|
7
|
-
// install(e, ctx) { ctx.track(e.terrain.view({ add(c) {...c.data.pos...}, change(c) {...}, remove(c) {...}, show(c, visible) {...} })); }
|
|
8
|
-
// This file never changes chunk data; it only reads it.
|
|
9
|
-
import { engineOwned } from '../../core/things.js';
|
|
10
|
-
import * as THREE from 'three';
|
|
11
|
-
import { terrainMaterial } from '../../render/materials.js';
|
|
12
|
-
import { mountColorMap, updateColorMap, disposeColorMap } from './terrainTexture.js';
|
|
13
|
-
|
|
14
|
-
export class TerrainLook {
|
|
15
|
-
/** @param {any} e @param {any} w the terrain data part (engine.terrain) @param {{ material?: any, effects?: boolean, sideMat?: any }} o */
|
|
16
|
-
constructor(e, w, { material = null, effects = true, sideMat = null } = {}) {
|
|
17
|
-
this.engine = e; this.w = w;
|
|
18
|
-
/** The ground material every chunk draws with (a texture-shaded chunk draws a clone carrying its color map) */
|
|
19
|
-
this.material = terrainMaterial(typeof material === 'function' ? material(e) : material, e, { effects });
|
|
20
|
-
/** shape.side.material: island sides and bottoms (null: the ground material) */
|
|
21
|
-
this.sideMat = typeof sideMat === 'function' ? sideMat(e) : sideMat;
|
|
22
|
-
this.meshes = new Map(); // chunk record -> { group, mesh, colorTex, colorMat }
|
|
23
|
-
this._view = w.view(this);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** @internal view hook: a chunk was generated (or regenerated after a full rebuild) */
|
|
27
|
-
add(c) {
|
|
28
|
-
const t0 = performance.now(); // measure: the 'build' stage of engine.budget.cost
|
|
29
|
-
const t = c.data, CH = this.w.CHUNK, g = new THREE.BufferGeometry();
|
|
30
|
-
g.setAttribute('position', new THREE.BufferAttribute(t.pos, 3));
|
|
31
|
-
g.setAttribute('normal', new THREE.BufferAttribute(t.nor, 3));
|
|
32
|
-
g.setAttribute('color', new THREE.BufferAttribute(t.col, 3));
|
|
33
|
-
g.setAttribute('uv', new THREE.BufferAttribute(t.uv, 2));
|
|
34
|
-
const rec = { group: new THREE.Group(), mesh: null, colorTex: null, colorMat: null };
|
|
35
|
-
const mesh = rec.mesh = new THREE.Mesh(g, this._materialFor(rec, c));
|
|
36
|
-
if (t.top != null) { // island chunk (terrain({ shape })): vertices are top, side, bottom
|
|
37
|
-
const rest = t.pos.length / 3 - t.top;
|
|
38
|
-
if (rest) { g.addGroup(0, t.top, 0); g.addGroup(t.top, rest, 1); }
|
|
39
|
-
}
|
|
40
|
-
mesh.receiveShadow = true; mesh.frustumCulled = false; mesh.matrixAutoUpdate = false;
|
|
41
|
-
rec.group.userData.budgetTag = 'terrain';
|
|
42
|
-
rec.group.position.set(c.cx * CH, 0, c.cz * CH);
|
|
43
|
-
rec.group.add(mesh); rec.group.updateMatrixWorld(true);
|
|
44
|
-
rec.group.visible = c.inView !== false;
|
|
45
|
-
this.meshes.set(c, rec);
|
|
46
|
-
this.engine.scene.add(engineOwned('terrain', rec.group));
|
|
47
|
-
this.engine.budget.cost.end('build', t0);
|
|
48
|
-
}
|
|
49
|
-
/** @internal view hook: an edit rebuilt the chunk's arrays (same vertex count) */
|
|
50
|
-
change(c) {
|
|
51
|
-
const rec = this.meshes.get(c); if (!rec) return;
|
|
52
|
-
const g = rec.mesh.geometry, t = c.data;
|
|
53
|
-
for (const [n, a] of [['position', t.pos], ['normal', t.nor], ['color', t.col], ['uv', t.uv]]) { g.attributes[n].array.set(a); g.attributes[n].needsUpdate = true; }
|
|
54
|
-
if (t.tex && rec.colorTex) updateColorMap(rec, t.tex);
|
|
55
|
-
g.computeBoundingSphere(); g.boundingBox = null;
|
|
56
|
-
}
|
|
57
|
-
/** @internal view hook: the chunk was released */
|
|
58
|
-
remove(c) {
|
|
59
|
-
const rec = this.meshes.get(c); if (!rec) return;
|
|
60
|
-
this.meshes.delete(c);
|
|
61
|
-
this.engine.scene.remove(rec.group);
|
|
62
|
-
rec.mesh.geometry.dispose();
|
|
63
|
-
disposeColorMap(rec);
|
|
64
|
-
}
|
|
65
|
-
/** @internal view hook: in view or not (ring 1 is always in view, farther chunks by the camera frustum) */
|
|
66
|
-
show(c, visible) { const rec = this.meshes.get(c); if (rec) rec.group.visible = visible; }
|
|
67
|
-
|
|
68
|
-
/** Swap the ground material on every loaded chunk at once (look.ground.replace / detail): no chunk is regenerated, collision is untouched */
|
|
69
|
-
setMaterial(m) {
|
|
70
|
-
this.material = m;
|
|
71
|
-
for (const [c, rec] of this.meshes) { disposeColorMap(rec); rec.colorTex = rec.colorMat = null; rec.mesh.material = this._materialFor(rec, c); }
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// texture shading: a material with this chunk's color map. Island sides keep vertex colors (the map is sampled by world xz and would smear down them)
|
|
75
|
-
_materialFor(rec, c) {
|
|
76
|
-
const t = c.data, CH = this.w.CHUNK;
|
|
77
|
-
const mat = t.tex ? mountColorMap(this.engine, this.material, rec, t.tex, c.cx * CH, c.cz * CH, CH) : this.material;
|
|
78
|
-
const rest = t.top != null ? t.pos.length / 3 - t.top : 0;
|
|
79
|
-
return rest && (t.tex || this.sideMat) ? [mat, this.sideMat ?? this.material] : mat;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
dispose() { this._view.remove(); }
|
|
83
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// look.ground: how the terrain looks (colors, variation, shading, detail layer, material). Registered by the terrain look module (terrainLook): a look that replaces it brings its own controls.
|
|
2
|
-
// set({ colors, biomeColors, steep, variation, shading, normals, detail })
|
|
3
|
-
// colors / biomeColors / steep / variation / shading / normals are baked into the chunks by the workers: a change rebuilds every chunk (cost 'rebuild';
|
|
4
|
-
// edits stay). colors / biomeColors / steep are given whole (they replace the style's table), variation / detail are objects (style.terrain.*).
|
|
5
|
-
// patch('detail', glsl) the detail layer's `vec4 threedogDetailSample(vec2 p)` (render/detail.js); a detail object must be set too
|
|
6
|
-
// replace(Material | (engine) => Material) the ground material (terrain({ material }) / style.terrain.material is the first one); null gives it back
|
|
7
|
-
// Why not in ChunkManager.js: that file is at its size cap, and every ground option below already reached it as config before; this only
|
|
8
|
-
// writes the same config again when a verb changes it.
|
|
9
|
-
import { defineLookPart, REPLACE } from '../../core/look/part.js';
|
|
10
|
-
import { terrainMaterial } from '../../render/materials.js';
|
|
11
|
-
|
|
12
|
-
const GEN = ['colors', 'biomeColors', 'steep', 'variation', 'shading', 'normals'];
|
|
13
|
-
const isObj = v => (v && typeof v === 'object' ? null : 'must be an object');
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @param {any} e @param {any} look the terrain look (look.js) @param {any} w the terrain data part (ChunkManager)
|
|
17
|
-
* @param {{ cfg: () => any, setCfg: (c: any) => void, species: () => any, game: Record<string, any> }} h (game.effects: terrain({ effects }) for its material) the module's current terrain config, and what terrain({...}) itself passed (written as owner 'terrain()')
|
|
18
|
-
*/
|
|
19
|
-
export function defineGroundLook(e, look, w, h) {
|
|
20
|
-
const st = e.style.terrain ?? {}, cfg0 = h.cfg();
|
|
21
|
-
// materials handed over with replace(m, { effects: false }): drawn as given, no cloud / season / detail patch (keyed by the material or function)
|
|
22
|
-
const bare = new WeakSet();
|
|
23
|
-
const rebuild = 'rebuild';
|
|
24
|
-
const part = defineLookPart(e, {
|
|
25
|
-
id: 'ground', group: 'surface', module: 'terrainLook', object: () => look.material, applyAtStart: false, docs: ['recipes/52-look.md'],
|
|
26
|
-
params: {
|
|
27
|
-
colors: { type: 'any', default: {}, neutral: true, cost: rebuild, check: isObj, desc: 'palette name -> color; the whole table (a ground type without a color is neutral gray)' },
|
|
28
|
-
biomeColors: { type: 'any', default: {}, neutral: true, cost: rebuild, check: isObj, desc: 'ground type -> palette name(s); the whole table' },
|
|
29
|
-
steep: { type: 'array', default: [], neutral: true, cost: rebuild, desc: 'slope colors [{ maxNormalY, colors }]' },
|
|
30
|
-
variation: { type: 'any', default: null, neutral: true, cost: rebuild, check: isObj, desc: '{ blend, jitter, patches } color variation (style.terrain.variation); null = none' },
|
|
31
|
-
shading: { type: 'string', values: ['smooth', 'flat', 'texture'], default: 'smooth', cost: rebuild,
|
|
32
|
-
why: 'terrain colors are blended per grid point (smooth) so the ground has no visible facets', off: "look.ground.set({ shading: 'flat' }) for one color per triangle, or 'texture' for a per-chunk color map" },
|
|
33
|
-
// only how the ground is lit (the workers bake it like shading), never its shape: a look value, so not a terrain({...}) option
|
|
34
|
-
normals: { type: 'any', default: null, neutral: true, cost: rebuild, check: v => (v == null || v === 'smooth' || v === 'flat' ? null : `must be 'smooth', 'flat' or null; got ${JSON.stringify(v)}`),
|
|
35
|
-
desc: "texture shading only: lighting normals 'smooth' (null = smooth) | 'flat'; smooth / flat shading fix their own" },
|
|
36
|
-
detail: { type: 'any', default: null, neutral: true, cost: 'recompile', check: isObj, desc: '{ texture | noise | glsl, scale, strength ... } detail layer over the ground (style.terrain.detail); null = none' },
|
|
37
|
-
},
|
|
38
|
-
style: () => ({ colors: st.colors, biomeColors: st.biomeColors, steep: st.steep, variation: st.variation, shading: st.config?.shading, normals: st.config?.normals, detail: st.detail, [REPLACE]: st.material }),
|
|
39
|
-
read: () => ({}),
|
|
40
|
-
hooks: { detail: { signature: 'vec4 threedogDetailSample(vec2 p) // rgb + height 0-1', scope: ['fragment'], example: "engine.look.ground.patch('detail', glsl)" } },
|
|
41
|
-
replace: { accepts: 'a Material, or (engine) => Material; null gives the style\'s back. { effects: false }: used as is, no engine patch', loses: ['the style\'s terrain material (cloud shadows, season tint and detail are added to the new one unless effects: false)'],
|
|
42
|
-
options: ['effects'], withOptions: (impl, o) => { if (impl && typeof impl === 'object' || typeof impl === 'function') (o.effects === false ? bare.add(impl) : bare.delete(impl)); } },
|
|
43
|
-
applyReplace: () => material(), applyHook: () => material(),
|
|
44
|
-
apply(v, changed) {
|
|
45
|
-
if (changed.has('detail')) material();
|
|
46
|
-
if (!GEN.some(k => changed.has(k))) return;
|
|
47
|
-
const next = { ...h.cfg() };
|
|
48
|
-
for (const k of GEN) if (changed.has(k)) { if (v[k] == null) delete next[k]; else next[k] = v[k]; }
|
|
49
|
-
if (!next.shading) next.shading = cfg0.shading;
|
|
50
|
-
h.setCfg(next);
|
|
51
|
-
w.reinit(next, h.species());
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
// what terrain({ colors, shading, material ... }) itself was given sits on the game layer under the owner 'terrain()', so describe shows it
|
|
55
|
-
const given = {};
|
|
56
|
-
for (const k of GEN) if (h.game[k] !== undefined) given[k] = h.game[k];
|
|
57
|
-
if (h.game.material !== undefined) given[REPLACE] = h.game.material;
|
|
58
|
-
if (h.game.material && h.game.effects === false) bare.add(h.game.material); // terrain({ material, effects: false }): the same record replace(m, { effects: false }) keeps
|
|
59
|
-
if (Object.keys(given).length) part.author.write('terrain()', given);
|
|
60
|
-
/** Rebuild the ground material from the resolved replace / detail and swap it on the loaded chunks (no chunk is regenerated) */
|
|
61
|
-
function material() {
|
|
62
|
-
const impl = part.value(REPLACE) ?? null;
|
|
63
|
-
look.setMaterial(terrainMaterial(typeof impl === 'function' ? impl(e) : impl, e, { effects: !(impl && bare.has(impl)) }));
|
|
64
|
-
}
|
|
65
|
-
return part;
|
|
66
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
// Vegetation look: draws what the vegetation data part placed. One InstancedMesh per species per chunk from the chunk's placement records
|
|
2
|
-
// (c.plants[name]: m matrices, c colors, ids, n), the species' geometry / low-poly geometry / material (wind sway, season tint, near fade
|
|
3
|
-
// patched in), ring LOD (draw distance, low-poly swap, shadow distance) and frustum visibility. Installed by vegetation() as its own module
|
|
4
|
-
// 'vegetationLook' holding the slot 'vegetation-look'; it also registers look.wind.
|
|
5
|
-
//
|
|
6
|
-
// Why a separate module: collision, paths, felling and instanceAt read only the data part, so a game can swap the whole plant look
|
|
7
|
-
// (engine.use(myPlants, { replaces: 'vegetation-look' })) and keep everything that plays. A replacement look does what this file does:
|
|
8
|
-
// install(e, ctx) { ctx.track(e.vegetation.view({ species(sp) {...}, change(c, name) {...c.plants[name]...}, ring(c, ring) {...}, show(c, v) {...}, drop(c) {...} })); }
|
|
9
|
-
// This file never changes placement data; it only reads it.
|
|
10
|
-
import { engineOwned } from '../../core/things.js';
|
|
11
|
-
import * as THREE from 'three';
|
|
12
|
-
import { fromModel } from './modelGeometry.js';
|
|
13
|
-
import { makeMaterial, applyEffects } from '../../render/materials.js';
|
|
14
|
-
import { asGiven } from '../../render/terms.js';
|
|
15
|
-
import { swayOf, defineWindLook, defineVegetationLook, colorPatchOf } from './lookWind.js';
|
|
16
|
-
import { nearFadePatch } from './nearFade.js';
|
|
17
|
-
import { shadowsOn } from '../../core/look/shadowPart.js';
|
|
18
|
-
|
|
19
|
-
export class VegetationLook {
|
|
20
|
-
/** @param {any} e @param {any} v the vegetation data part (engine.vegetation) */
|
|
21
|
-
constructor(e, v) {
|
|
22
|
-
this.engine = e; this.v = v;
|
|
23
|
-
defineWindLook(e); // look.wind: before the first species() so its sway hook is read
|
|
24
|
-
defineVegetationLook(e, this); // look.vegetation: the color hook, live on every species' material
|
|
25
|
-
/** @internal species name -> { geometry, lodGeometry, material, fadeUniforms } */ this.kinds = new Map();
|
|
26
|
-
/** @internal chunk record -> { group, ims: { name: InstancedMesh } } */ this.meshes = new Map();
|
|
27
|
-
this._view = v.view(this);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** The InstancedMesh drawing one species in one chunk (null when none is drawn there) @param {any} c chunk record @param {string} name */
|
|
31
|
-
mesh(c, name) { return this.meshes.get(c)?.ims[name] ?? null; }
|
|
32
|
-
/** How one species is drawn: { geometry, lodGeometry, material, fadeUniforms } (null for an unknown name) @param {string} name */
|
|
33
|
-
kind(name) { return this.kinds.get(name) ?? null; }
|
|
34
|
-
|
|
35
|
-
/** @internal view hook: a species was defined (or defined again): build its geometry and patched materials. A bad option throws into define() */
|
|
36
|
-
species(sp) {
|
|
37
|
-
const o = sp.source, e = this.engine, label = `vegetation.define('${sp.name}')`;
|
|
38
|
-
// look.wind 'sway' (a game's engine.look.wind.patch('sway', ...)) replaces the sway shape
|
|
39
|
-
const sw = swayOf(e), wind = o.wind && sw ? { amplitude: o.wind, glsl: sw.glsl, tsl: sw.tsl, uniforms: sw.uniforms } : o.wind;
|
|
40
|
-
// distance fade of near-only species (nearFade.js): the band was worked out (and checked) by define(), null = hard ring edge
|
|
41
|
-
const band = sp.fade, nf = band && nearFadePatch(band), col = colorPatchOf(e);
|
|
42
|
-
const own = [nf?.patch, col].filter(Boolean);
|
|
43
|
-
const fx = m => o.effects === false ? asGiven(m) : applyEffects(m, { wind, season: 'foliage', engine: e, patches: own.length ? own : undefined });
|
|
44
|
-
const mdl = o.model && fromModel(o.model, label);
|
|
45
|
-
let lod = o.lodGeometry?.isObject3D ? fromModel(o.lodGeometry, label + '.lodGeometry').geometry : o.lodGeometry || null;
|
|
46
|
-
if (mdl && lod && !lod.groups.length) { lod = lod.clone(); lod.addGroup(0, Infinity, 0); } // a material array draws nothing without groups
|
|
47
|
-
this.kinds.set(sp.name, {
|
|
48
|
-
geometry: mdl ? mdl.geometry : o.geometry, lodGeometry: lod, fadeUniforms: nf?.uniforms ?? null,
|
|
49
|
-
material: mdl ? mdl.materials.map(fx) : fx(o.material ?? makeMaterial('vegetation', { vertexColors: true, side: o.doubleSided ? THREE.DoubleSide : THREE.FrontSide }, e)),
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** @internal view hook: c.plants[name] was placed, replaced, thinned or dropped, or which of its instances are felled changed */
|
|
54
|
-
change(c, name) {
|
|
55
|
-
const r = c.plants?.[name], rec = this.meshes.get(c), old = rec?.ims[name];
|
|
56
|
-
if (!r) { if (old) { rec.group.remove(old); old.dispose(); delete rec.ims[name]; } return; }
|
|
57
|
-
const k = this.kinds.get(name), sp = this.v.get(name);
|
|
58
|
-
if (!k || !sp) return;
|
|
59
|
-
let im = old;
|
|
60
|
-
if (!old || old.userData.plants !== r || old.material !== k.material) { // new placement (or species defined again): a new mesh
|
|
61
|
-
const t0 = performance.now(); // measure: the 'build' stage of engine.budget.cost
|
|
62
|
-
im = new THREE.InstancedMesh(k.geometry, k.material, r.n);
|
|
63
|
-
im.instanceColor = new THREE.InstancedBufferAttribute(r.c, 3);
|
|
64
|
-
im.frustumCulled = false; im.matrixAutoUpdate = false;
|
|
65
|
-
im.receiveShadow = sp.receiveShadow;
|
|
66
|
-
im.userData.plants = r; im.userData.budgetTag = 'vegetation';
|
|
67
|
-
const R = rec ?? this._chunk(c);
|
|
68
|
-
if (old) { R.group.remove(old); old.dispose(); }
|
|
69
|
-
R.group.add(im); im.updateMatrixWorld(true);
|
|
70
|
-
R.ims[name] = im;
|
|
71
|
-
this.engine.budget.cost.end('build', t0);
|
|
72
|
-
}
|
|
73
|
-
// felled instances draw as a zero matrix (count unchanged, so the other instances keep their slots)
|
|
74
|
-
const a = im.instanceMatrix.array, hid = c.hidden?.[name];
|
|
75
|
-
a.set(r.m);
|
|
76
|
-
if (hid) for (const i of hid) if (i < r.n) a.fill(0, i * 16, i * 16 + 16);
|
|
77
|
-
im.instanceMatrix.needsUpdate = true;
|
|
78
|
-
if (c.ring != null) this._level(im, sp, k, c.ring);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** @internal view hook: the chunk's ring changed (or shadows were switched): draw distance, low-poly swap and shadows of every species there */
|
|
82
|
-
ring(c, ring) {
|
|
83
|
-
const rec = this.meshes.get(c); if (!rec) return;
|
|
84
|
-
for (const n in rec.ims) { const sp = this.v.get(n), k = this.kinds.get(n); if (sp && k && !sp.nearOnly) this._level(rec.ims[n], sp, k, ring); }
|
|
85
|
-
}
|
|
86
|
-
/** @internal view hook: in view or not (ring 1 is always in view, farther chunks by the camera frustum) */
|
|
87
|
-
show(c, visible) { const rec = this.meshes.get(c); if (rec) rec.group.visible = visible; }
|
|
88
|
-
/** @internal view hook: the chunk was released */
|
|
89
|
-
drop(c) {
|
|
90
|
-
const rec = this.meshes.get(c); if (!rec) return;
|
|
91
|
-
this.meshes.delete(c);
|
|
92
|
-
for (const n in rec.ims) rec.ims[n].dispose();
|
|
93
|
-
this.engine.scene.remove(rec.group);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** @internal module frame hook: the fade band is centred on the view focus (the player in a follow camera) */
|
|
97
|
-
updateFade() {
|
|
98
|
-
const f = this.engine.focus;
|
|
99
|
-
for (const k of this.kinds.values()) k.fadeUniforms?.uNearFadeCenter.value.copy(f);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
_level(im, sp, k, ring) {
|
|
103
|
-
im.visible = ring <= sp.maxRing;
|
|
104
|
-
im.geometry = k.lodGeometry && ring > sp.lodRing ? k.lodGeometry : k.geometry;
|
|
105
|
-
im.castShadow = shadowsOn(this.engine) && sp.castShadow && ring <= sp.shadowRing;
|
|
106
|
-
}
|
|
107
|
-
_chunk(c) {
|
|
108
|
-
const CH = this.v.host.CHUNK, g = new THREE.Group();
|
|
109
|
-
g.userData.budgetTag = 'vegetation';
|
|
110
|
-
g.position.set(c.cx * CH, 0, c.cz * CH); g.matrixAutoUpdate = false; g.updateMatrix();
|
|
111
|
-
g.visible = c.inView !== false;
|
|
112
|
-
this.engine.scene.add(engineOwned('vegetation', g)); g.updateMatrixWorld(true);
|
|
113
|
-
const rec = { group: g, ims: {} };
|
|
114
|
-
this.meshes.set(c, rec);
|
|
115
|
-
return rec;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
dispose() { this._view.remove(); this.kinds.clear(); }
|
|
119
|
-
}
|