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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Vegetation data part: what grows where. Species definitions (placement rule, positions, densityMap, rings), placement per chunk
|
|
2
2
|
// (c.plants[name]: matrices, colors, stable ids), tree collision circles (c.colliders), felled-tree records (saved) and instanceAt.
|
|
3
|
-
// Data only: this file makes no mesh and touches no material.
|
|
4
|
-
// (vegetation/
|
|
3
|
+
// Data only: this file makes no mesh and touches no material. Draw parts subscribe with view({ species, change, ring, show, drop })
|
|
4
|
+
// (vegetation/draw.js is the engine's own, slot 'vegetation-draw'); the models and materials given to define() are read there.
|
|
5
5
|
import { isModelName, vegetationModel } from '../../core/namedModel.js';
|
|
6
6
|
import { warnMissing } from '../../core/validate.js';
|
|
7
7
|
import { readParams, keysSchema } from '../../core/params.js';
|
|
@@ -34,7 +34,7 @@ function checkPositions(label, list, rule) {
|
|
|
34
34
|
// const hit = engine.vegetation.instanceAt(position, { radius: 2, species: '松树' }); // → { species, cx, cz, id, position } or null
|
|
35
35
|
// engine.vegetation.removeInstance(hit.species, hit.cx, hit.cz, hit.id, { regrowSeconds: 300 }); // grows back after 300 game seconds
|
|
36
36
|
// engine.vegetation.restoreInstance(...) // restore immediately
|
|
37
|
-
// Hiding: the slot goes into c.hidden[name] (the
|
|
37
|
+
// Hiding: the slot goes into c.hidden[name] (the draw part draws it as a zero matrix, count unchanged) and out of the chunk's collision circles.
|
|
38
38
|
// Regrowth: the record stores the expiry time (engine.clock game seconds), checked once per second; the clock is saved, so the countdown continues after
|
|
39
39
|
// reload.
|
|
40
40
|
const KEY_RE = /^veg:(.*):(-?\d+),(-?\d+):(\d+)$/;
|
|
@@ -55,10 +55,10 @@ export class Vegetation {
|
|
|
55
55
|
// whatever provides the ground (a level, a code-built ground, flat). Both hosts keep chunks of one shape, so everything below is shared
|
|
56
56
|
if (engine.terrain && Object.keys(opts).length) throw codedError('vegetation-option', `vegetation({ ${Object.keys(opts).join(', ')} }): with terrain() installed vegetation grows on the terrain chunks, and density / view distance are terrain options (terrain({ density, viewChunks })). The vegetation() options are for ground without terrain (a level, a code-built ground)`);
|
|
57
57
|
/** @internal the chunk table vegetation lives in: engine.terrain, or its own GroundChunks */
|
|
58
|
-
/** @internal the
|
|
58
|
+
/** @internal the draw parts drawing the plants (view()) */ this.views = new Set();
|
|
59
59
|
this.host = engine.terrain ?? new GroundChunks(engine, this, opts);
|
|
60
60
|
// on terrain: this is the terrain's planter (it calls mount / unmount / drop / ring; terrain never reads engine.vegetation); a chunk's
|
|
61
|
-
// visibility comes from the terrain data part, so a game that replaces the terrain
|
|
61
|
+
// visibility comes from the terrain data part, so a game that replaces the terrain drawing keeps its trees
|
|
62
62
|
if (engine.terrain) {
|
|
63
63
|
this._planter = engine.terrain.setPlanter(this);
|
|
64
64
|
this._view = engine.terrain.view({ show: (c, v) => this._emit('show', c, v) });
|
|
@@ -104,15 +104,15 @@ export class Vegetation {
|
|
|
104
104
|
* height (rule's scale / stretch / sink / tints / collider still apply; the scatter filters are refused). Stable id = list index
|
|
105
105
|
* densityMap how much survives per spot, 0..1: (x, z) => 0..1, or a gray image { url | data + width + height, size: [w, l], center?, outside? }
|
|
106
106
|
* (the keys of terrain({ heightmap })). Thins the rule's or the positions' placement; call rebuild() after a function's inputs change
|
|
107
|
-
* wind wind sway amplitude (0 disables)
|
|
107
|
+
* wind wind sway amplitude (0 disables), or this species' own sway: { amplitude, glsl, tsl, uniforms }, which vegetation.sway() leaves alone (recipe 36)
|
|
108
108
|
* nearOnly generate only near the player (grass, flowers)
|
|
109
109
|
* maxRing not drawn beyond this ring count
|
|
110
110
|
* fade near-only species shrink out over a band [start, end] metres from the player instead of popping at the ring edge (default on for
|
|
111
111
|
* nearOnly, end = maxRing x chunk size; false = hard edge; { start, end } sets the band)
|
|
112
112
|
* lodRing switch to low-poly beyond this ring count
|
|
113
113
|
* castShadow / shadowRing whether to cast shadows, and within how many rings
|
|
114
|
-
* material
|
|
115
|
-
*
|
|
114
|
+
* material this species' own three.js material (optional; default is engine.vegetation.material); wind, cloud shadows, season tint and the
|
|
115
|
+
* near fade are added to it (and its shadow sways) unless effects: false
|
|
116
116
|
*/
|
|
117
117
|
define(name, o) {
|
|
118
118
|
readParams(`vegetation.define('${name}')`, keysSchema(ADD_KEYS), o);
|
|
@@ -132,7 +132,7 @@ export class Vegetation {
|
|
|
132
132
|
readParams(`vegetation.define('${name}').rule`, keysSchema(RULE_KEYS), o.rule);
|
|
133
133
|
if (o.positions != null) checkPositions(`vegetation.define('${name}')`, o.positions, o.rule);
|
|
134
134
|
const density = o.densityMap != null ? makeDensity(o.densityMap, `vegetation.define('${name}')`) : null;
|
|
135
|
-
// distance fade band of near-only species (nearFade.js), checked here so a bad band throws at define; the
|
|
135
|
+
// distance fade band of near-only species (nearFade.js), checked here so a bad band throws at define; the draw part draws it
|
|
136
136
|
if (o.fade && typeof o.fade === 'object') readParams(`vegetation.define('${name}').fade`, keysSchema(['start', 'end']), o.fade);
|
|
137
137
|
const maxRing = o.maxRing ?? (o.nearOnly ? 1 : 99);
|
|
138
138
|
const sp = {
|
|
@@ -144,8 +144,8 @@ export class Vegetation {
|
|
|
144
144
|
nearOnly: !!o.nearOnly, maxRing, lodRing: o.lodRing ?? 1, fade: o.effects === false ? null : fadeBand(o.fade, !!o.nearOnly, maxRing, this.host.CHUNK),
|
|
145
145
|
castShadow: o.castShadow ?? !o.nearOnly, shadowRing: o.shadowRing ?? 1, receiveShadow: o.receiveShadow ?? true,
|
|
146
146
|
};
|
|
147
|
-
sp.source = o; // what it was made from: the
|
|
148
|
-
this._emit('species', sp); // the
|
|
147
|
+
sp.source = o; // what it was made from: the draw part reads geometry / model / material / wind from it, a hot swap adds it again (_swapped)
|
|
148
|
+
this._emit('species', sp); // the draw part builds geometry and materials now, so a bad model throws here, before anything is registered
|
|
149
149
|
this.species.set(name, sp);
|
|
150
150
|
this.host.registerSpecies(name, sp.rule);
|
|
151
151
|
// a density image still loading: this species places nothing until it is in, then every chunk is placed again. The module's init waits
|
|
@@ -210,10 +210,51 @@ export class Vegetation {
|
|
|
210
210
|
sp.shadowRing = ring;
|
|
211
211
|
this.host.refreshLevels();
|
|
212
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* The shared default material: every species with no material or model of its own draws it. Set it and it is drawn as given, on plants already
|
|
215
|
+
* planted too (no patches added; give it engine.vegetation.patches to keep the sway, season and color code, or use define({ material }) for a species'
|
|
216
|
+
* own amplitude and near fade). null gives the neutral default back. Until set, reading gives the neutral source: each species draws its own copy
|
|
217
|
+
* (engine.vegetationDraw.kind(name).material), so only .color written here reaches them all.
|
|
218
|
+
* @example engine.vegetation.material = applyEffects(new THREE.MeshToonMaterial({ vertexColors: true }), { patches: engine.vegetation.patches });
|
|
219
|
+
* @type {import('three').Material | null}
|
|
220
|
+
*/
|
|
221
|
+
get material() { return this._drawPart('material').material; }
|
|
222
|
+
set material(m) { this._drawPart('material').material = m; }
|
|
223
|
+
/**
|
|
224
|
+
* The engine's shader patches for plants (season tint, sway with one amplitude, the vegetation.color() code), for applyEffects on a game's shared
|
|
225
|
+
* material. sway() and color() make a new array, and the game re-applies it to a material of its own
|
|
226
|
+
* @type {any[]}
|
|
227
|
+
*/
|
|
228
|
+
get patches() { return this._drawPart('patches').patches; }
|
|
229
|
+
/**
|
|
230
|
+
* Replace the sway shape of every species whose wind is a number, planted ones too; null gives the built-in sway back. This is the default shape; a species
|
|
231
|
+
* defined with its own wind object keeps that one (the narrower entry wins). The GLSL defines
|
|
232
|
+
* void threedogWind(inout vec3 transformed, vec3 ip, vec3 position), moving the vertex in object space (ip = world position of this plant; uTime, uWind,
|
|
233
|
+
* uWindFreq, THREEDOG_WIND_AMP and your uniforms are in scope). tsl is the WebGPURenderer form, (ctx) => the moved object-space position.
|
|
234
|
+
* How hard and fast plants sway are the signals engine.uniforms.uWindAmp and uWindFreq
|
|
235
|
+
* @example engine.vegetation.sway('void threedogWind(inout vec3 t, vec3 ip, vec3 p){ t.x += sin(uTime + ip.x) * max(p.y, 0.0) * THREEDOG_WIND_AMP * uWind; }');
|
|
236
|
+
* @param {string | { glsl?: string, tsl?: (ctx: any) => any, uniforms?: Record<string, any> } | null} spec
|
|
237
|
+
* @returns {void}
|
|
238
|
+
*/
|
|
239
|
+
sway(spec) { this._drawPart('sway').sway(spec); }
|
|
240
|
+
/**
|
|
241
|
+
* Code in the 'color' slot of every species' material, planted ones too: diffuseColor (vertex and instance colors, season tint applied) is yours to
|
|
242
|
+
* change. tsl is the WebGPURenderer form, (ctx) => vec4 from ctx.color. null takes it off
|
|
243
|
+
* @example engine.vegetation.color({ glsl: 'diffuseColor.rgb *= vec3(1.1, 0.9, 0.7);', tsl: c => c.color.mul(c.tsl.vec4(1.1, 0.9, 0.7, 1)) });
|
|
244
|
+
* @param {string | { glsl?: string, tsl?: (ctx: any) => any, uniforms?: Record<string, any>, pars?: string } | null} spec
|
|
245
|
+
* @returns {void}
|
|
246
|
+
*/
|
|
247
|
+
color(spec) { this._drawPart('color').color(spec); }
|
|
248
|
+
/** @internal the engine's drawing half; a game that replaced it draws with its own materials, so these entries have nothing to act on */
|
|
249
|
+
_drawPart(entry) {
|
|
250
|
+
const l = this.engine.vegetationDraw;
|
|
251
|
+
if (!l) throw codedError('vegetation-option', `vegetation.${entry}: the plants are drawn by a game module (replaces: 'vegetation-draw'), which owns their materials; set the picture there`);
|
|
252
|
+
return l;
|
|
253
|
+
}
|
|
213
254
|
/**
|
|
214
255
|
* Draw the plants. Hooks: species(sp) (defined or defined again; sp.source is what define() was given), change(c, name) (c.plants[name]
|
|
215
256
|
* placed, replaced or gone, or c.hidden[name] changed: felled slots), ring(c, ring) (LOD ring), show(c, visible) (in view or not), drop(c)
|
|
216
|
-
* (the chunk was released). Species and chunks already there are replayed at once. This is how a
|
|
257
|
+
* (the chunk was released). Species and chunks already there are replayed at once. This is how a draw part that replaces 'vegetation-draw'
|
|
217
258
|
* draws. Returns { remove() } (ctx.track it).
|
|
218
259
|
* @example ctx.track(engine.vegetation.view({ change(c, name) { draw(c, c.plants[name]) }, drop(c) { undraw(c) } }))
|
|
219
260
|
* @param {{ species?: (sp: any) => void, change?: (c: any, name: string) => void, ring?: (c: any, ring: number) => void, show?: (c: any, visible: boolean) => void, drop?: (c: any) => void }} v
|
|
@@ -296,16 +337,16 @@ export class Vegetation {
|
|
|
296
337
|
return best;
|
|
297
338
|
}
|
|
298
339
|
|
|
299
|
-
/** @internal chunk plumbing (terrain chunks and ground chunks): one species' placement result r for chunk c (data; the
|
|
340
|
+
/** @internal chunk plumbing (terrain chunks and ground chunks): one species' placement result r for chunk c (data; the draw parts draw it) */
|
|
300
341
|
mount(c, name, r) {
|
|
301
342
|
const sp = this.species.get(name);
|
|
302
343
|
// densityMap thins here, before the colliders are taken, so a dropped plant blocks nothing; survivors keep their stable ids
|
|
303
344
|
if (sp?.density) r = thin(r, c.cx * this.host.CHUNK, c.cz * this.host.CHUNK, sp.density.at, sp.rule.salt);
|
|
304
345
|
c.plants ||= {}; c.colliders ||= {}; c.collidersAll ||= {};
|
|
305
|
-
// none left (terrain dug, densityMap thinned all): drop the record, so the
|
|
346
|
+
// none left (terrain dug, densityMap thinned all): drop the record, so the draw part tears its mesh down too and collision matches what is drawn
|
|
306
347
|
if (r.n === 0) delete c.plants[name]; else c.plants[name] = r;
|
|
307
348
|
if (r.n && r.k?.length) c.collidersAll[name] = r.k; else delete c.collidersAll[name]; // original circles (before felled trees are filtered)
|
|
308
|
-
this.applyEdits(c, name); // felled trees stay gone after reload; sets the colliders and tells the
|
|
349
|
+
this.applyEdits(c, name); // felled trees stay gone after reload; sets the colliders and tells the draw parts
|
|
309
350
|
}
|
|
310
351
|
/** @internal chunk plumbing: drop a near-only species from a chunk that moved out of its ring */
|
|
311
352
|
unmount(c, name) {
|
|
@@ -315,10 +356,10 @@ export class Vegetation {
|
|
|
315
356
|
}
|
|
316
357
|
/** @internal chunk plumbing: the chunk was released */
|
|
317
358
|
drop(c) { this._emit('drop', c); c.plants = {}; c.hidden = null; }
|
|
318
|
-
/** @internal chunk plumbing: the chunk's ring changed; the
|
|
359
|
+
/** @internal chunk plumbing: the chunk's ring changed; the draw parts pick draw distance, low-poly swap and shadows from it */
|
|
319
360
|
ring(c, ring) { c.ring = ring; this._emit('ring', c, ring); }
|
|
320
361
|
|
|
321
|
-
/** @internal felled-tree records -> c.hidden[name] (instance slots) and the chunk's collision circles; tells the
|
|
362
|
+
/** @internal felled-tree records -> c.hidden[name] (instance slots) and the chunk's collision circles; tells the draw parts */
|
|
322
363
|
applyEdits(c, name) {
|
|
323
364
|
const r = c.plants?.[name], hid = new Set();
|
|
324
365
|
if (r) for (const id of this._removed.get(`${name}:${c.cx},${c.cz}`)?.keys() ?? []) { const s = slotOf(r, id); if (s !== undefined) hid.add(s); }
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// Vegetation drawing: 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
|
+
// 'vegetationDraw' holding the slot 'vegetation-draw'. Its picture entries are reached through engine.vegetation: material, patches, sway(), color().
|
|
5
|
+
//
|
|
6
|
+
// Why a separate module: collision, paths, felling and instanceAt read only the data part, so a game can swap the whole plant picture
|
|
7
|
+
// (engine.use(myPlants, { replaces: 'vegetation-draw' })) and keep everything that plays. A replacement draw part 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 { applyEffects, windCustom } from '../../render/materials.js';
|
|
14
|
+
import { neutralMaterial } from '../../render/neutral.js';
|
|
15
|
+
import { patchMaterial, unpatchMaterial } from '../../render/patches.js';
|
|
16
|
+
import { EFFECTS, hashText } from '../../render/effects.js';
|
|
17
|
+
import { codedError } from '../../core/errorHints.js';
|
|
18
|
+
import { nearFadePatch } from './nearFade.js';
|
|
19
|
+
|
|
20
|
+
const COLOR = 'vegetationColor'; // the patch name of vegetation.color() on every species' material
|
|
21
|
+
// The wind patch in engine.vegetation.patches has one amplitude: a shared material cannot carry each species' own (those are define()'s wind option)
|
|
22
|
+
const SHARED_SWAY = 0.05;
|
|
23
|
+
const code = v => (typeof v === 'string' ? { glsl: v } : v);
|
|
24
|
+
|
|
25
|
+
export class VegetationDraw {
|
|
26
|
+
/** @param {any} e @param {any} v the vegetation data part (engine.vegetation) */
|
|
27
|
+
constructor(e, v) {
|
|
28
|
+
this.engine = e; this.v = v;
|
|
29
|
+
// what engine.vegetation.material reads until the game sets one. Each species draws its own copy (wind amplitude and fade band are per species);
|
|
30
|
+
// the copies share this Color, so a write to material.color reaches them
|
|
31
|
+
/** @internal */ this._base = neutralMaterial('vegetation', { vertexColors: true });
|
|
32
|
+
/** @internal the game's shared material, drawn as given */ this._game = null;
|
|
33
|
+
/** @internal vegetation.sway()'s { glsl, tsl, uniforms } */ this._sway = null;
|
|
34
|
+
/** @internal vegetation.color()'s patch */ this._color = null;
|
|
35
|
+
/** @internal species name -> { geometry, lodGeometry, material, fadeUniforms, shared } */ this.kinds = new Map();
|
|
36
|
+
/** @internal chunk record -> { group, ims: { name: InstancedMesh } } */ this.meshes = new Map();
|
|
37
|
+
this._refreshPatches();
|
|
38
|
+
this._view = v.view(this);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** @internal engine.vegetation.material: every species with no material or model of its own draws it, as given; null gives the neutral default back */
|
|
42
|
+
get material() { return this._game ?? this._base; }
|
|
43
|
+
set material(m) {
|
|
44
|
+
if (m != null && !m.isMaterial) throw codedError('vegetation-option', `vegetation.material is a three.js material (or null for the neutral default); got ${m}`);
|
|
45
|
+
const was = this._game;
|
|
46
|
+
this._game = m || null;
|
|
47
|
+
for (const sp of this.v.list()) {
|
|
48
|
+
const old = this.kinds.get(sp.name);
|
|
49
|
+
if (!old?.shared) continue;
|
|
50
|
+
this.species(sp);
|
|
51
|
+
if (old.material !== was) old.material.dispose(); // a neutral copy of ours; the game's stays the game's
|
|
52
|
+
}
|
|
53
|
+
for (const rec of this.meshes.values()) for (const n in rec.ims) { const k = this.kinds.get(n); if (k) rec.ims[n].material = k.material; }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** @internal engine.vegetation.sway(): the new shape reaches the engine's own species materials; a shared material of the game is the game's to re-patch */
|
|
57
|
+
sway(spec) {
|
|
58
|
+
const s = spec == null ? null : code(spec);
|
|
59
|
+
if (s) { windCustom(s); this._needForm('sway', s); } // a wrong sway function throws here, not later inside vegetation.define
|
|
60
|
+
this._sway = s;
|
|
61
|
+
this._refreshPatches();
|
|
62
|
+
// a number is an amplitude for this shape; a species' own wind object is its own sway and stays (see species())
|
|
63
|
+
this._eachOwn((m, sp) => { if (typeof sp.source.wind === 'number' && sp.source.wind) patchMaterial(m, [this._windPatch(sp.source.wind)], { strict: false }); });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** @internal engine.vegetation.color(): live on the engine's own species materials, one patch object so they keep sharing a program */
|
|
67
|
+
color(spec) {
|
|
68
|
+
const s = spec == null ? null : code(spec);
|
|
69
|
+
if (s) {
|
|
70
|
+
if (typeof s !== 'object' || (s.glsl != null && typeof s.glsl !== 'string') || (s.tsl != null && typeof s.tsl !== 'function')) throw codedError('vegetation-option', 'vegetation.color() takes GLSL code, or { glsl, tsl: (ctx) => vec4, uniforms, pars }');
|
|
71
|
+
this._needForm('color', s);
|
|
72
|
+
}
|
|
73
|
+
this._color = s && { name: COLOR, slot: 'color', cacheKey: hashText(JSON.stringify([s.glsl ?? '', s.pars ?? ''])),
|
|
74
|
+
...(s.uniforms && { uniforms: s.uniforms }), ...(s.glsl != null && { glsl: s.glsl, ...(s.pars && { pars: s.pars }) }), ...(s.tsl && { tsl: s.tsl }) };
|
|
75
|
+
this._refreshPatches();
|
|
76
|
+
this._eachOwn(m => { if (this._color) patchMaterial(m, [this._color]); else unpatchMaterial(m, COLOR); });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Each renderer draws its own form; the one this engine's renderer needs, when missing, is named (else the code would do nothing silently) */
|
|
80
|
+
_needForm(entry, s) {
|
|
81
|
+
const gpu = !!this.engine.renderer?.isWebGPURenderer;
|
|
82
|
+
if (!gpu && s.glsl == null) throw codedError('vegetation-option', `vegetation.${entry}() has only a tsl form, which WebGLRenderer cannot draw: give glsl too ({ glsl, tsl })`);
|
|
83
|
+
if (gpu && s.tsl == null) throw codedError('vegetation-option', `vegetation.${entry}() has only a glsl form, which WebGPURenderer cannot draw: give tsl too ({ glsl, tsl })`);
|
|
84
|
+
}
|
|
85
|
+
_windPatch(amplitude) { return EFFECTS.wind(amplitude, this._sway ? windCustom(this._sway) : undefined); }
|
|
86
|
+
/** engine.vegetation.patches: what a game's shared material needs to behave like the engine's (the near fade is per species: define({ material }) gets it) */
|
|
87
|
+
_refreshPatches() { /** @internal */ this.patches = [EFFECTS.season('foliage'), this._windPatch(SHARED_SWAY), ...(this._color ? [this._color] : [])]; }
|
|
88
|
+
/** Materials the engine patches: not effects: false species, not the game's shared material */
|
|
89
|
+
_eachOwn(fn) {
|
|
90
|
+
for (const sp of this.v.list()) {
|
|
91
|
+
const k = this.kinds.get(sp.name);
|
|
92
|
+
if (!k || sp.source.effects === false || k.material === this._game) continue;
|
|
93
|
+
for (const m of [k.material].flat()) fn(m, sp);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The InstancedMesh drawing one species in one chunk (null when none is drawn there) @param {any} c chunk record @param {string} name */
|
|
98
|
+
mesh(c, name) { return this.meshes.get(c)?.ims[name] ?? null; }
|
|
99
|
+
/** How one species is drawn: { geometry, lodGeometry, material, fadeUniforms } (null for an unknown name) @param {string} name */
|
|
100
|
+
kind(name) { return this.kinds.get(name) ?? null; }
|
|
101
|
+
|
|
102
|
+
/** @internal view hook: a species was defined (or defined again): build its geometry and patched materials. A bad option throws into define() */
|
|
103
|
+
species(sp) {
|
|
104
|
+
const o = sp.source, e = this.engine, label = `vegetation.define('${sp.name}')`;
|
|
105
|
+
const wind = typeof o.wind === 'number' && o.wind && this._sway ? { amplitude: o.wind, ...this._sway } : o.wind; // vegetation.sway() is the default shape, a species' own wind object wins
|
|
106
|
+
// distance fade of near-only species (nearFade.js): the band was worked out (and checked) by define(), null = hard ring edge
|
|
107
|
+
const band = sp.fade, nf = band && nearFadePatch(band);
|
|
108
|
+
const own = [nf?.patch, this._color].filter(Boolean);
|
|
109
|
+
const fx = m => o.effects === false ? m : applyEffects(m, { wind, season: 'foliage', engine: e, patches: own.length ? own : undefined });
|
|
110
|
+
const mdl = o.model && fromModel(o.model, label);
|
|
111
|
+
let lod = o.lodGeometry?.isObject3D ? fromModel(o.lodGeometry, label + '.lodGeometry').geometry : o.lodGeometry || null;
|
|
112
|
+
if (mdl && lod && !lod.groups.length) { lod = lod.clone(); lod.addGroup(0, Infinity, 0); } // a material array draws nothing without groups
|
|
113
|
+
const shared = !mdl && !o.material, game = shared ? this._game : null;
|
|
114
|
+
this.kinds.set(sp.name, {
|
|
115
|
+
geometry: mdl ? mdl.geometry : o.geometry, lodGeometry: lod, fadeUniforms: game ? null : nf?.uniforms ?? null, shared,
|
|
116
|
+
material: game ?? (mdl ? mdl.materials.map(fx) : fx(o.material ?? this._neutral(o))),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
_neutral(o) {
|
|
120
|
+
const m = neutralMaterial('vegetation', { vertexColors: true, side: o.doubleSided ? THREE.DoubleSide : THREE.FrontSide });
|
|
121
|
+
m.color = this._base.color;
|
|
122
|
+
return m;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** @internal view hook: c.plants[name] was placed, replaced, thinned or dropped, or which of its instances are felled changed */
|
|
126
|
+
change(c, name) {
|
|
127
|
+
const r = c.plants?.[name], rec = this.meshes.get(c), old = rec?.ims[name];
|
|
128
|
+
if (!r) { if (old) { rec.group.remove(old); old.dispose(); delete rec.ims[name]; } return; }
|
|
129
|
+
const k = this.kinds.get(name), sp = this.v.get(name);
|
|
130
|
+
if (!k || !sp) return;
|
|
131
|
+
let im = old;
|
|
132
|
+
if (!old || old.userData.plants !== r || old.material !== k.material) { // new placement (or species defined again): a new mesh
|
|
133
|
+
const t0 = performance.now(); // measure: the 'build' stage of engine.budget.cost
|
|
134
|
+
im = new THREE.InstancedMesh(k.geometry, k.material, r.n);
|
|
135
|
+
im.instanceColor = new THREE.InstancedBufferAttribute(r.c, 3);
|
|
136
|
+
im.frustumCulled = false; im.matrixAutoUpdate = false;
|
|
137
|
+
im.receiveShadow = sp.receiveShadow;
|
|
138
|
+
im.userData.plants = r; im.userData.budgetTag = 'vegetation';
|
|
139
|
+
const R = rec ?? this._chunk(c);
|
|
140
|
+
if (old) { R.group.remove(old); old.dispose(); }
|
|
141
|
+
R.group.add(im); im.updateMatrixWorld(true);
|
|
142
|
+
R.ims[name] = im;
|
|
143
|
+
this.engine.budget.cost.end('build', t0);
|
|
144
|
+
}
|
|
145
|
+
// felled instances draw as a zero matrix (count unchanged, so the other instances keep their slots)
|
|
146
|
+
const a = im.instanceMatrix.array, hid = c.hidden?.[name];
|
|
147
|
+
a.set(r.m);
|
|
148
|
+
if (hid) for (const i of hid) if (i < r.n) a.fill(0, i * 16, i * 16 + 16);
|
|
149
|
+
im.instanceMatrix.needsUpdate = true;
|
|
150
|
+
if (c.ring != null) this._level(im, sp, k, c.ring);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** @internal view hook: the chunk's ring changed (or shadows were switched): draw distance, low-poly swap and shadows of every species there */
|
|
154
|
+
ring(c, ring) {
|
|
155
|
+
const rec = this.meshes.get(c); if (!rec) return;
|
|
156
|
+
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); }
|
|
157
|
+
}
|
|
158
|
+
/** @internal view hook: in view or not (ring 1 is always in view, farther chunks by the camera frustum) */
|
|
159
|
+
show(c, visible) { const rec = this.meshes.get(c); if (rec) rec.group.visible = visible; }
|
|
160
|
+
/** @internal view hook: the chunk was released */
|
|
161
|
+
drop(c) {
|
|
162
|
+
const rec = this.meshes.get(c); if (!rec) return;
|
|
163
|
+
this.meshes.delete(c);
|
|
164
|
+
for (const n in rec.ims) rec.ims[n].dispose();
|
|
165
|
+
this.engine.scene.remove(rec.group);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** @internal module frame hook: the fade band is centred on the view focus (the player in a follow camera) */
|
|
169
|
+
updateFade() {
|
|
170
|
+
const f = this.engine.focus;
|
|
171
|
+
for (const k of this.kinds.values()) k.fadeUniforms?.uNearFadeCenter.value.copy(f);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
_level(im, sp, k, ring) {
|
|
175
|
+
im.visible = ring <= sp.maxRing;
|
|
176
|
+
im.geometry = k.lodGeometry && ring > sp.lodRing ? k.lodGeometry : k.geometry;
|
|
177
|
+
im.castShadow = !!this.engine.renderer?.shadowMap?.enabled && sp.castShadow && ring <= sp.shadowRing;
|
|
178
|
+
}
|
|
179
|
+
_chunk(c) {
|
|
180
|
+
const CH = this.v.host.CHUNK, g = new THREE.Group();
|
|
181
|
+
g.userData.budgetTag = 'vegetation';
|
|
182
|
+
g.position.set(c.cx * CH, 0, c.cz * CH); g.matrixAutoUpdate = false; g.updateMatrix();
|
|
183
|
+
g.visible = c.inView !== false;
|
|
184
|
+
this.engine.scene.add(engineOwned('vegetation', g)); g.updateMatrixWorld(true);
|
|
185
|
+
const rec = { group: g, ims: {} };
|
|
186
|
+
this.meshes.set(c, rec);
|
|
187
|
+
return rec;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
dispose() { this._view.remove(); this.kinds.clear(); }
|
|
191
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Vegetation on any ground (no terrain module): a level model, a code-built ground, the flat default. Chunks of the same shape as the terrain's
|
|
2
2
|
// ({ cx, cz, state, plants, colliders, ring, inView, ... }), streamed around every engine.stream source, placed by the same rule code
|
|
3
|
-
// (core/scatter.js) over engine.surface / slope / groundType -- whoever provides the ground. Data only: the vegetation
|
|
3
|
+
// (core/scatter.js) over engine.surface / slope / groundType -- whoever provides the ground. Data only: the vegetation drawing draws c.plants.
|
|
4
4
|
//
|
|
5
5
|
// Why the main thread and not a worker: a ground provider is arbitrary main-thread code (a level heightfield, a game's closure), not
|
|
6
6
|
// serializable data like a terrain generator. Placement is cheap (a few height lookups per attempt) and runs under a per-frame budget.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Vegetation module factory: engine.use(vegetation(...)) installs two modules. 'vegetation' (data: species, placement, tree collision,
|
|
2
|
-
// felled trees; Vegetation.js) and '
|
|
3
|
-
// Why two: collision, paths and felling read only the data, so engine.use(myPlants, { replaces: 'vegetation-
|
|
2
|
+
// felled trees; Vegetation.js) and 'vegetationDraw' (instanced meshes, wind, fade, LOD; draw.js, slot 'vegetation-draw').
|
|
3
|
+
// Why two: collision, paths and felling read only the data, so engine.use(myPlants, { replaces: 'vegetation-draw' }) swaps every pixel
|
|
4
4
|
// of the plants and keeps all of play.
|
|
5
5
|
import { readParams, keysSchema } from '../../core/params.js';
|
|
6
6
|
import { Vegetation } from './Vegetation.js';
|
|
7
|
-
import {
|
|
7
|
+
import { VegetationDraw } from './draw.js';
|
|
8
8
|
import { codedError } from '../../core/errorHints.js';
|
|
9
9
|
|
|
10
10
|
const OPTS = ['chunkSize', 'viewChunks', 'density', 'area', 'seed'];
|
|
@@ -29,7 +29,7 @@ const VEG_PARAMS = keysSchema(OPTS, { chunkSize: 32, viewChunks: 3, density: 1,
|
|
|
29
29
|
*/
|
|
30
30
|
export function vegetation(opts = {}) {
|
|
31
31
|
readParams('vegetation', VEG_PARAMS, opts);
|
|
32
|
-
let v = null, own = null, cols = null, ready = null,
|
|
32
|
+
let v = null, own = null, cols = null, ready = null, drawPart = null;
|
|
33
33
|
const data = { name: 'vegetation', type: 'world', provides: ['vegetation'], label: 'Vegetation', params: VEG_PARAMS, options: opts, stage: 'ground', after: ['terrain', 'level'], optional: ['terrain', 'level'],
|
|
34
34
|
install(e) {
|
|
35
35
|
e.i18n.add({ 'zh-CN': { 'module.vegetation': '植被' }, en: { 'module.vegetation': 'vegetation' } });
|
|
@@ -53,12 +53,12 @@ export function vegetation(opts = {}) {
|
|
|
53
53
|
describe(e, ctx) { if (own) ctx.out.perf.vegetation = { loaded: own.stats.loaded, visible: own.stats.visible, queued: own.stats.queued }; },
|
|
54
54
|
dispose(e) { own?.dispose(); cols?.remove(); ready?.remove(); v?._view?.remove(); v?._planter?.remove(); } };
|
|
55
55
|
const lookModule = {
|
|
56
|
-
// the same vegetation({...}) call (its options are the data part's; the
|
|
57
|
-
name: '
|
|
58
|
-
install(e) { e.i18n.add({ 'zh-CN': { 'module.
|
|
59
|
-
frame() {
|
|
60
|
-
describe() { return { chunks:
|
|
61
|
-
dispose() {
|
|
56
|
+
// the same vegetation({...}) call (its options are the data part's; the draw part reads the species' define() options)
|
|
57
|
+
name: 'vegetationDraw', type: 'picture', label: 'Vegetation drawing', params: VEG_PARAMS, options: opts, requires: ['vegetation'], provides: ['vegetation-draw'], stage: 'effects',
|
|
58
|
+
install(e) { e.i18n.add({ 'zh-CN': { 'module.vegetationDraw': '植被外观' }, en: { 'module.vegetationDraw': 'vegetation drawing' } }); drawPart = new VegetationDraw(e, v); return drawPart; },
|
|
59
|
+
frame() { drawPart.updateFade(); },
|
|
60
|
+
describe() { return { chunks: drawPart?.meshes.size ?? 0 }; },
|
|
61
|
+
dispose() { drawPart?.dispose(); drawPart = null; },
|
|
62
62
|
};
|
|
63
63
|
return [data, lookModule];
|
|
64
64
|
}
|