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
|
@@ -96,13 +96,16 @@ engine.saves.autosave(3); // autosave to 'auto' every 3 minutes of play (wai
|
|
|
96
96
|
```
|
|
97
97
|
|
|
98
98
|
## 3. Interact keys: which object, and who acts
|
|
99
|
-
`interactions({ pick })` decides what the interact key uses (no default, `[interaction-setup]` names the fix)
|
|
99
|
+
`interactions({ pick })` decides what the interact key uses (no default, `[interaction-setup]` names the fix). It takes no key: bind one in `createEngine({ bindings: presets.bindings.interact })`, or with `engine.input.bind`.
|
|
100
|
+
`radius` is measured from the object's origin, not its edge. For a large object (a boat, a house) raise it, or add the interaction to a small marker
|
|
101
|
+
object at the spot where it is used.
|
|
102
|
+
|
|
100
103
|
Pick the rule that fits the camera, not the genre default:
|
|
101
104
|
```js
|
|
102
105
|
engine.use(interactions({ ...presets.interactions.nearest })); // E, nearest within 2.5 m (top-down, third person)
|
|
103
106
|
engine.use(interactions({ pick: 'facing' })); // only what the actor faces (within 60°): the door behind you stays dark
|
|
104
107
|
engine.use(interactions({ pick: 'aim', radius: 2 })); // closest to the screen-center ray: first person, shooters
|
|
105
|
-
engine.use(interactions({ pick: (list, ctx) => list.find(c => c.id.startsWith('npc')) ?? list[0]
|
|
108
|
+
engine.use(interactions({ pick: (list, ctx) => list.find(c => c.id.startsWith('npc')) ?? list[0] })); // own rule; list = enabled ones in range, nearest first
|
|
106
109
|
engine.interactions.pickMode = 'aim'; // switch at runtime (entering a first-person mode)
|
|
107
110
|
```
|
|
108
111
|
One object with two verbs = two interactions with different key actions; each key picks among its own action, and `engine.interactions.options` lists
|
|
@@ -120,6 +123,7 @@ when the key is released, the actor leaves the radius, `enabled()` turns false o
|
|
|
120
123
|
skip the hold; an approach returns `{ approaching }`, a promise of onUse's result).
|
|
121
124
|
```js
|
|
122
125
|
engine.interactions.add(well, { label: 'Pump', hold: 1.5, onUse: fill });
|
|
126
|
+
engine.interactions.add(shell, { id: 'shell-1', label: 'Pick up', once: true, counter: 'shells' }); // mesh gone after E, counted: recipe 03 "Pick and count"
|
|
123
127
|
engine.interactions.add(clerk, { label: 'Talk', radius: Infinity, approach: true, onUse: talk });
|
|
124
128
|
```
|
|
125
129
|
**Who acts** is `engine.actor` (a world record id, default `'player'`). Interactions, trigger zones, objective-marker distances, the world simulation
|
|
@@ -55,7 +55,7 @@ engine.cameraRig.shoulder = -0.7; // switch shoulders at any time (plain p
|
|
|
55
55
|
engine.cameraRig.frame(enemy.object); // lock-on: turn to "behind the player, looking at the enemy"; frame(null) lets go
|
|
56
56
|
```
|
|
57
57
|
- **`shoulder`**: meters the aim point (and so the camera) moves to the right along `right()`; negative = left, 0 = centered (default).
|
|
58
|
-
- **`pointerLock`** (default false): a click on the canvas locks the mouse, so moving it turns the view with no dragging; Esc releases. Not on phones. If the browser refuses the lock the camera falls back to dragging; `describe().camera.pointerLock` is a state machine: `state` is `off` / `unsupported` / `waiting-click` / `requesting` / `locked` / `refused`, plus `covered` (what sits on the canvas centre and eats the click), `cameraOverride` (a takeover blocks locking) and `lastFailure { reason, agoSec }`; the text line shows the same.
|
|
58
|
+
- **`pointerLock`** (default false): a click on the canvas locks the mouse, so moving it turns the view with no dragging; Esc releases, and `engine.page.releaseLock()` releases from code without opening the pause menu. Not on phones. If the browser refuses the lock the camera falls back to dragging; `describe().camera.pointerLock` is a state machine: `state` is `off` / `unsupported` / `waiting-click` / `requesting` / `locked` / `refused`, plus `covered` (what sits on the canvas centre and eats the click), `cameraOverride` (a takeover blocks locking) and `lastFailure { reason, agoSec }`; the text line shows the same.
|
|
59
59
|
The press that locks is swallowed (no `Mouse0`, no click) so it cannot attack or fire; `swallowLockClick: false` delivers it.
|
|
60
60
|
Leave it off when the mouse buttons are for UI or clicking the ground.
|
|
61
61
|
- **`yaw` means which side of the player the camera is on**: `camera = focus + (sin yaw, cos yaw) * distance`, so the camera looks along
|
|
@@ -77,8 +77,13 @@ engine.use(followCamera({ minPitch: -0.9, ground: 'shorten' })); // or the sam
|
|
|
77
77
|
`'none'` leaves it; a function `facts => position | null` gets `{ position, lookPoint, dir, arm, distance, groundY, clearance, surface, rig }`.
|
|
78
78
|
Default: `'shorten'` when `minPitch < 0`, otherwise `'raise'` (the older behaviour, fine for a camera that never looks up).
|
|
79
79
|
- **Walls** (with `collision()` installed) pull the arm in at once and let it out slowly; the shortest arm is `collision({ cameraMin })` (default 1.5 m).
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
**What blocks by default**: every `addCircle` / `addBox` / `addSegment` collider, over its footprint and up to its height, and every mesh registered
|
|
81
|
+
with `engine.rays.addStatic(mesh, { occluder: true })` (`level()` registers its buildings and `col_` meshes). A mesh alone blocks nothing, so a tree
|
|
82
|
+
crown or an eave that reaches past its collider lets the camera inside. Register that mesh: it stops the arm and adds no gameplay collider (it does
|
|
83
|
+
join `engine.raycast`). `collision({ cameraOcclusion: 'colliders' })` tests colliders only.
|
|
84
|
+
A content prop or template with `collide` blocks with its whole mesh, crown and eaves included, with no game code. A hand-written mesh stays opt-in: `addStatic(mesh, { occluder: true })`. In a level, `userData.occluder = false` on a node (or a parent) keeps it from blocking, and a hidden mesh does not block (`col_` meshes do). `addStatic` skips `InstancedMesh` and `SkinnedMesh` (dev warns once): rays do not hit them, so give them a collider or register a plain stand-in mesh.
|
|
85
|
+
Give the colliders the camera may pass through `occluder: false`
|
|
86
|
+
(`engine.collision.addCircle(tree, { radius: 0.4, occluder: false })`, or `collide: { circle: 0.4, occluder: false }` / `occluder: false` on a content prop or template): walkers are still stopped, the arm ignores them. A dense forest of
|
|
82
87
|
blocking trunks collapses the camera onto the player; `collision({ canopyHeight })` covers only the terrain's own trees.
|
|
83
88
|
- **Close-up**: when the camera ends up nearer than `hideTargetNear` (default 0.9 m) to the look point, the followed object is hidden from the
|
|
84
89
|
camera (shadow stays, layer `hideLayer`); `hideTargetNear: 0` turns it off.
|
package/docs/recipes/23-ops.md
CHANGED
|
@@ -68,7 +68,7 @@ returns `'halted'`.
|
|
|
68
68
|
| `inventory.trade` | `{ take, give, takeN?, giveN?, container? }` (all or nothing in `ctx.actor`'s container; reversible with `engine.ops.undo`, recipe 03) | `noContainer` `notEnough` `full` |
|
|
69
69
|
| `inventory.use` | `{ item }` (from `ctx.actor`'s container; runs the item's `use`, see recipe 03) | `notEnough` `notUsable` or the item's `canUse` reason |
|
|
70
70
|
| `inventory.drop` | `{ item, n? }` (a pickup at the actor's feet, data kept) | `notEnough` `noWorld` `noPosition` |
|
|
71
|
-
| `thing.set` | `{ id, position?, rotation?, scale?, visible? }` (core; a world record via `world.set` / `move`, an `engine.add` object saved as an override when it has an id; undoable, recipe
|
|
71
|
+
| `thing.set` | `{ id, position?, rotation?, scale?, visible? }` (core; a world record via `world.set` / `move`, an `engine.add` object saved as an override when it has an id; undoable, recipe 40) | `noThing` `engineOwned` `recordVisible` |
|
|
72
72
|
| `thing.remove` | `{ id }` (core; undoable: an `engine.add` object is detached and kept, a record re-added) | `noThing` `engineOwned` |
|
|
73
73
|
| `photo.take` | none (`r.value` is the shot; can = `photo.canTake()`, the key emits `photo:denied { reason }`) | `denied` or yours |
|
|
74
74
|
|
|
@@ -1,12 +1,34 @@
|
|
|
1
1
|
# UI parts: replace or turn off any piece of the engine's screen UI
|
|
2
2
|
|
|
3
|
+
**In this recipe**: Reskin · 1. Pick at start · 2. Your own part · 3. Toasts · 4. Dialogue box · The choice cursor · 5. Title screen · 6. Settings menu · 7. Keys, UI that follows the world
|
|
4
|
+
|
|
3
5
|
Every piece of UI the engine draws is a named **part** with a plain default:
|
|
4
6
|
`loading`, `toast`, `title` (off by default), `touch` (on-screen stick and buttons),
|
|
5
7
|
`hud.marker`, `hud.counter`, `hud.bar`, `dialogue`, `prompt` ("E · Talk"), `questLog`, `inventory` (with the inventory module).
|
|
6
8
|
The engine keeps the behavior (when to show, the UI focus stack and Esc, input lock, i18n); a part only draws the data it gets.
|
|
7
9
|
Each name takes one value: `false` off · `true` default · `{ ...options }` default with options ·
|
|
8
10
|
`(engine, options) => ({ show, update, hide, dispose })` your own (any verb may be omitted).
|
|
9
|
-
Only want different colors / layout? Use
|
|
11
|
+
Only want different colors / layout? Use "Reskin" below, not a new part.
|
|
12
|
+
|
|
13
|
+
## Reskin: your picture on every default part, in one place
|
|
14
|
+
The default parts are neutral gray on purpose. About ten lines give all of them the game's picture; do this before writing a dialogue box or HUD of your own:
|
|
15
|
+
```js
|
|
16
|
+
const theme = { // picture/ui.js
|
|
17
|
+
bg: 'rgba(38,28,20,.94)', // panels: dialogue, prompt, toast, windows; the HUD uses it slightly see-through
|
|
18
|
+
fg: '#f4e8d0', muted: '#b8a88c', // text, secondary text
|
|
19
|
+
accent: '#e8a13a', good: '#9ccf6a', // names, cursor, toast border, HUD bars; "done"
|
|
20
|
+
line: 'rgba(244,232,208,.25)', // borders, dividers
|
|
21
|
+
font: '"Georgia", serif', // a font file: ui.fonts: ['name'] (recipe 05, fonts)
|
|
22
|
+
radius: '4px', radiusSmall: '2px', // windows and dialogue; buttons, prompts, toasts, HUD counters
|
|
23
|
+
loadingBg: '#1c140e', // loading and title screens, cutscene bars
|
|
24
|
+
};
|
|
25
|
+
const engine = createEngine({ canvas, ui: { theme } }); // the same ui option as the parts below
|
|
26
|
+
```
|
|
27
|
+
Each key becomes the CSS variable `--threedog-<key>` (`radiusSmall` -> `--threedog-radius-small`) on `engine.uiRoot`, and no default rule has a color or corner of
|
|
28
|
+
its own. Also there: `shadow` (windows), `shadowSmall` (bubbles, marker labels), `fadeBg` (scene fades), and `hudBg` / `hudFg` / `hudAccent`,
|
|
29
|
+
which follow the main ones unless set. Your own part can read the same variables. Further steps, beside `theme` in the same `ui`: `css` is placed after every default, so it
|
|
30
|
+
overrides the `.threedog-*` classes (sizes, layout); `templates.<window>` replaces a window's HTML (`engine.ui.templates` is the same object, written directly); `fonts` lists
|
|
31
|
+
font assets. Every other key of `ui` is a part name (§1). How high the prompt floats is `interactions({ promptHeight })`. Different behavior, not colors: a part of your own (§2).
|
|
10
32
|
|
|
11
33
|
## 1. Pick at start (copy it)
|
|
12
34
|
```js
|
|
@@ -64,7 +86,7 @@ engine.ui.set('toast', (engine) => ({ show: ({ text, kind }) => { if (kind !== '
|
|
|
64
86
|
engine.use(quests({ notify: false })); // or only silence quest messages; notify: ({ type, id, text }) => ... shows them your way
|
|
65
87
|
```
|
|
66
88
|
|
|
67
|
-
## 4. Dialogue box: your own
|
|
89
|
+
## 4. Dialogue box: your own picture, your own fields
|
|
68
90
|
The engine keeps the dialogue logic (typing on game time, input lock, Esc, number keys, conditions).
|
|
69
91
|
The part draws `view` and answers with `view.advance()` / `view.choose(i)`, which run the ops `dialogue.advance` / `dialogue.choose`.
|
|
70
92
|
`view = { script, node, speaker, text (typed so far), full, typing, choices: [{ text, key, data }], hint, data, lock, advance(), choose(i) }`
|
|
@@ -110,22 +132,24 @@ Every entry of the UI focus stack (dialogue, `engine.ui.open` parts, `makeWindow
|
|
|
110
132
|
(Esc, pad B) is still the back key. Only the top entry moves, so a dialogue over an open window never moves the window's slots.
|
|
111
133
|
- A window or full-screen part: the cursor walks the controls inside the part's `el` (button, input, select, `[data-nav]`) by screen layout,
|
|
112
134
|
so lists, slot grids and settings rows all work without declaring columns; left / right change a slider or a dropdown. The selected control
|
|
113
|
-
has the class `is-cursor` (style it in `
|
|
135
|
+
has the class `is-cursor` (style it in `ui.css`). Your own part opts in by exposing `get el() { return root; }`.
|
|
114
136
|
- Your own focus entry: `uiFocus(engine).push('shop', { cancel, nav: () => shopEl })`, or a list you draw yourself:
|
|
115
137
|
`nav: { count: () => items.length, moved: i => draw(i), confirm: i => engine.ops.run('shop.buy', { item: items[i].id }) }`.
|
|
116
138
|
- Keys are actions: rebind with `createEngine({ bindings: { uiUp: ['KeyI', 'PadUp'], confirm: ['Space', 'PadB'], cancel: ['Escape', 'PadA'] } })` or the settings menu.
|
|
117
139
|
|
|
118
140
|
### A window: results, game over, summary, any modal
|
|
119
141
|
`makeWindow` is the one window: it opens on top of the UI focus stack, locks game input while open, closes with its close button or Esc
|
|
120
|
-
(pad B), and its buttons take the choice cursor, so it works with the keyboard, a gamepad and the mouse
|
|
121
|
-
|
|
142
|
+
(pad B), and its buttons take the choice cursor, so it works with the keyboard, a gamepad and the mouse (opening it lets go of a locked mouse; the next click on
|
|
143
|
+
the view locks again). A window that ends something, win or lose, takes `closable: false`: no close button and Esc does nothing, so the player cannot slip back into the
|
|
144
|
+
game past it and only your buttons end it. Its picture is your `ui.css` /
|
|
145
|
+
`ui.templates[id]`. A level clear, a match score, a day's earnings or a run summary are all this:
|
|
122
146
|
```js
|
|
123
147
|
import { makeWindow } from 'threedog';
|
|
124
148
|
const results = makeWindow(engine, {
|
|
125
149
|
id: 'results', title: () => 'Run complete',
|
|
126
150
|
data: () => ({ score: run.score, best: run.best }), // read on every refresh(), so it shows the current values
|
|
127
151
|
render: (d, { esc }) => `<p>${esc(d.score)} / ${esc(d.best)}</p><button class="threedog-btn" data-act="again">Again</button>`,
|
|
128
|
-
|
|
152
|
+
closable: false, // a run summary ends the run; for a window Esc may leave, drop this (onCancel changes what Esc does)
|
|
129
153
|
});
|
|
130
154
|
results.el.addEventListener('click', ev => { // one listener: refresh() rewrites the content, not this
|
|
131
155
|
if (ev.target.closest('[data-act="again"]')) { results.toggle(false); startRun(); } // a click, Enter or pad A on the cursor
|
|
@@ -159,16 +183,16 @@ engine.settings.addSection('gameplay', {
|
|
|
159
183
|
order: 50,
|
|
160
184
|
});
|
|
161
185
|
```
|
|
162
|
-
A row that switches off an effect of your own (a post effect, a
|
|
186
|
+
A row that switches off an effect of your own (a post effect, a picture value): name the shared value it limits, and it works like the
|
|
163
187
|
built-in shadows row. Off holds the value off on the settings layer, so a later scene, weather or cutscene cannot turn it back on; on
|
|
164
188
|
allows whatever the scene chose. A number row from 0 to 1 is a factor on a number value. Define the row after the effect exists.
|
|
165
189
|
```js
|
|
166
|
-
engine.
|
|
167
|
-
engine.settings.define('volFog', true, { limits: '
|
|
168
|
-
engine.settings.define('
|
|
190
|
+
engine.post.add(volFog); // post.volFog.enabled now exists
|
|
191
|
+
engine.settings.define('volFog', true, { limits: 'post.volFog.enabled' }); // add apply: v => ... too if the game reacts in code
|
|
192
|
+
engine.settings.define('flashCap', 1, { limits: 'sky.flash' }); // 0.5 = half of any lightning flash
|
|
169
193
|
settings({ presets: { low: { volFog: false } } }); // a preset can switch the row like any other key
|
|
170
194
|
```
|
|
171
|
-
`engine.describe().shared['
|
|
195
|
+
`engine.describe().shared['post.volFog.enabled']` shows the settings entry and what the scene wanted underneath.
|
|
172
196
|
|
|
173
197
|
A completely different menu: don't install `settings()`; open your own with `uiFocus(engine).setRoot(() => myMenu.open())` so Esc on an empty stack reaches it.
|
|
174
198
|
|
|
@@ -16,8 +16,8 @@ engine.use(openWorld({ camera: 'follow', seed: 7, terrain: terrainPreset({ shape
|
|
|
16
16
|
const preview = createTerrain({ seed: 7, ...terrainPreset() }); // same heights before the engine starts
|
|
17
17
|
const dry = (x, z) => riverAt(x, z, preview.noise) === 0;
|
|
18
18
|
```
|
|
19
|
-
Its ground types are `beach snow rock riverbank wetland savanna forest highland meadow`;
|
|
20
|
-
|
|
19
|
+
Its ground types are `beach snow rock riverbank wetland savanna forest highland meadow`; the game colors them (`terrain({ colors, biomeColors })`),
|
|
20
|
+
and `terrainStrings` names them for `describe()`. Other options:
|
|
21
21
|
`heightScale mountains rivers riverWidth biomes noise island canyon` (types in the package's `index.d.ts`).
|
|
22
22
|
|
|
23
23
|
## 1. Your own generator
|
|
@@ -72,21 +72,21 @@ engine.ops.define('path.sand', { args: { at: 'position' }, // a sandy path; a
|
|
|
72
72
|
Read the ground with `engine.surface(x, z)` (also `slope`, `groundType`, `waterAt`) and put an object on it with `engine.snapToGround(obj)`. Don't
|
|
73
73
|
raycast the terrain for this: the height function is exact and works before the chunk has a mesh.
|
|
74
74
|
|
|
75
|
-
Crisp ground color borders, triangle cut, normals, bounds margin, height from a grid: `37-terrain-
|
|
75
|
+
Crisp ground color borders, triangle cut, normals, bounds margin, height from a grid: `37-terrain-draw-hooks.md`.
|
|
76
76
|
|
|
77
77
|
## 5. Where the ground ends: `shape`
|
|
78
78
|
|
|
79
79
|
`terrain({ shape: { mask, edge, side, bottom } })` keeps ground only where `mask > 0` (an island, a floating rock): off it `engine.surface` is
|
|
80
80
|
`-Infinity` and `engine.ground.has(x, z)` is false, and falls emit `terrain:void`. Without `shape` nothing changes. See `42-terrain-shape.md`.
|
|
81
81
|
|
|
82
|
-
## 6. Drawing the ground and plants your own way: replace the
|
|
82
|
+
## 6. Drawing the ground and plants your own way: replace the picture, keep play
|
|
83
83
|
|
|
84
84
|
`terrain()` and `vegetation()` each install two modules: the data part (`engine.terrain`: heights, chunks, edits, collision;
|
|
85
|
-
`engine.vegetation`: species, placement, tree collision, felling) and the
|
|
86
|
-
`engine.
|
|
87
|
-
replaces a
|
|
85
|
+
`engine.vegetation`: species, placement, tree collision, felling) and the picture (`engine.terrainDraw`, slot `'terrain-draw'`;
|
|
86
|
+
`engine.vegetationDraw`, slot `'vegetation-draw'`). Collision, paths, `engine.surface`, `instanceAt` and saves read only the data, so a game that
|
|
87
|
+
replaces a picture keeps all of play. A picture listens to the data part's `view` hooks and never changes the data:
|
|
88
88
|
```js
|
|
89
|
-
engine.use({ name: 'myGround', type: '
|
|
89
|
+
engine.use({ name: 'myGround', type: 'picture', provides: ['terrain-draw'], install(e, ctx) {
|
|
90
90
|
const meshes = new Map();
|
|
91
91
|
ctx.track(e.terrain.view({
|
|
92
92
|
add(c) { const m = buildMesh(c.data.pos, c.data.nor, c.data.col); m.position.set(c.cx * e.terrain.CHUNK, 0, c.cz * e.terrain.CHUNK); e.scene.add(m); meshes.set(c, m); },
|
|
@@ -94,17 +94,17 @@ engine.use({ name: 'myGround', type: 'look', provides: ['terrain-look'], install
|
|
|
94
94
|
remove(c) { e.scene.remove(meshes.get(c)); meshes.delete(c); },
|
|
95
95
|
show(c, visible) { meshes.get(c).visible = visible; },
|
|
96
96
|
}));
|
|
97
|
-
} }, { replaces: 'terrain-
|
|
98
|
-
engine.use({ name: 'myPlants', type: '
|
|
97
|
+
} }, { replaces: 'terrain-draw' });
|
|
98
|
+
engine.use({ name: 'myPlants', type: 'picture', provides: ['vegetation-draw'], install(e, ctx) {
|
|
99
99
|
ctx.track(e.vegetation.view({
|
|
100
100
|
species(sp) { /* sp.source = what vegetation.define was given (geometry, model, material, wind) */ },
|
|
101
101
|
change(c, name) { /* c.plants[name]: { n, m (16 floats per plant, chunk-local), c (colors), ids }; c.hidden[name]: felled slots; gone = drop that mesh */ },
|
|
102
102
|
ring(c, ring) { /* LOD: ring 1 = the chunk a source stands in plus one ring around */ },
|
|
103
103
|
show(c, visible) {}, drop(c) { /* chunk released */ },
|
|
104
104
|
}));
|
|
105
|
-
} }, { replaces: 'vegetation-
|
|
105
|
+
} }, { replaces: 'vegetation-draw' });
|
|
106
106
|
```
|
|
107
|
-
Only the material, not the meshes? `engine.
|
|
107
|
+
Only the material, not the meshes? `engine.terrain.material = material` swaps it on every loaded chunk in place (recipe 36).
|
|
108
108
|
|
|
109
109
|
## 7. A chunk that fails
|
|
110
110
|
|
package/docs/recipes/29-grid.md
CHANGED
|
@@ -40,7 +40,7 @@ player text of its own codes (zh-CN and en; override a line with `engine.i18n.ad
|
|
|
40
40
|
`can` codes, need their own `grid.<code>` line through `engine.i18n.add`. `engine.explain({ grid: { grid: 'room', item: 'bed', cell: [4, 4] } }).text` says which cell
|
|
41
41
|
and which record is in the way.
|
|
42
42
|
A placed record looks like `{ id, kind, position, rot, ...fields, grid: { id: 'room', cell: [4, 4], size: [2, 1], rotation: 1, item: 'bed' } }`. Give
|
|
43
|
-
it a
|
|
43
|
+
it a picture with `world.present(kind, ...)` as usual (`rot` is the yaw in radians).
|
|
44
44
|
To build several things at once, call `grid.place` from your own op (`build.wall`), so each placement is still checked.
|
|
45
45
|
|
|
46
46
|
**Occupancy is not saved separately.** `room.at(cell)` / `room.area(cell, size)` read an index built from the world records' `grid` field, so a save
|
|
@@ -80,10 +80,10 @@ Cells that exist from the start go in content: `content/grids.js` <!-- r18-ignor
|
|
|
80
80
|
`plot: { cell: 1, origin: [20, 0], size: [8, 8], layers: { soil: [[3, 5, { tilled: true }]] } }` <!-- r18-ignore-line -->
|
|
81
81
|
(or `grids.add(name, { layers })`). They are the baseline: a save keeps only cells changed from it, so editing the content later still reaches old saves.
|
|
82
82
|
|
|
83
|
-
**Tiles.** The game gives a layer its colors: `plot.layer('soil', { tiles: {
|
|
84
|
-
(what the data means is gameplay, so
|
|
83
|
+
**Tiles.** The game gives a layer its colors: `plot.layer('soil', { tiles: { color: d => d.watered ? 0x5b3d2a : d.tilled ? 0x8a6243 : null } })`
|
|
84
|
+
(what the data means is gameplay, so the game writes these). A layer with tiles shows crisp per-cell quads just above the ground, following its
|
|
85
85
|
height (slopes, ramps, level meshes).
|
|
86
|
-
`tiles: { colors: { watered: 0x5b3d2a, tilled: 0x8a6243 } }` is the same as `
|
|
86
|
+
`tiles: { colors: { watered: 0x5b3d2a, tilled: 0x8a6243 } }` is the same as `color` from a table (first truthy field wins) and wins over the module's `grids({ tiles: { soil: { ... } } })`; `plot.layer('soil', { tiles: false })` turns them off; `{ tiles: true }` draws every non-empty cell gray; `lift` raises them; `{ tiles:
|
|
87
87
|
(engine, layer) => ({ update(cells), dispose() }) }` is your own view. Options are read when the layer is first created.
|
|
88
88
|
|
|
89
89
|
## 4. Preview
|
|
@@ -100,9 +100,18 @@ The engine binds no key: the preview declares the action `rotate` (gone with the
|
|
|
100
100
|
`engine.input.bind('rotate', ['KeyR'])`; pass `rotate: 'myAction'` to read another one, `false` for none. Without a binding the preview warns once and only `pv.rotate()` turns
|
|
101
101
|
it. `pv.cell`, `pv.rotation`, `pv.ok`, `pv.code` (the `can` answer, `'noTarget'` with no cell, null when ok)
|
|
102
102
|
are readable every frame.
|
|
103
|
-
Colors come from `
|
|
103
|
+
Colors come from `grids({ ok, bad, previewOpacity, previewHeight })`. `draw: false` hides the default box; `draw: (engine) => ({ update(view), hide(), dispose()
|
|
104
104
|
})` draws your own (`view = { cells, center, size, rotation, ok, code }`).
|
|
105
105
|
|
|
106
|
+
## Materials
|
|
107
|
+
```js
|
|
108
|
+
engine.use(world(), grids({ ok: 0x66dd88, bad: 0xdd5544, previewOpacity: 0.6, tileLift: 0.05 }));
|
|
109
|
+
plot.layer('soil').material = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 1 });
|
|
110
|
+
pv.material = new THREE.MeshBasicMaterial({ transparent: true, opacity: 0.5, depthWrite: false });
|
|
111
|
+
```
|
|
112
|
+
Both are plain three.js materials, used as given. Tile colors are vertex colors, so a tile material keeps `vertexColors: true` to show them; the default also has a polygon
|
|
113
|
+
offset against the ground. The preview still writes ok / bad to its material's `color`. `layer.material` is null on a layer that draws no tiles, `pv.material` with `draw` off or your own.
|
|
114
|
+
|
|
106
115
|
## 5. Baked data vs state the player changes
|
|
107
116
|
Anything the player can change in play must be runtime state, never baked into generated height or ground-type data: a tilled plot (farming), a dug or mined
|
|
108
117
|
tile (survival), a road or placed floor (city builder), a painted tile (puzzle), a breakable wall (action). Bake only what never changes: the landform (hills,
|
|
@@ -16,7 +16,7 @@ only its own state. There is no inheritance and no variant layer; a different lo
|
|
|
16
16
|
export default {
|
|
17
17
|
chest: {
|
|
18
18
|
model: 'chest', // an asset name (file or generator of an asset pack, the same name pickups and vegetation take); every chest clones one shared prototype
|
|
19
|
-
collide: 'box', // 'box'
|
|
19
|
+
collide: 'box', // 'box' = the model's bounds; 'circle' = a cylinder on its base; omitted = does not block
|
|
20
20
|
state: { opened: false }, // instance fields and their defaults, copied onto each record and saved
|
|
21
21
|
interact: { label: rec => rec.opened ? '关上' : '打开', op: 'chest.toggle', radius: 2 }, // using it runs the op with { id }
|
|
22
22
|
container: { capacity: 6, items: { berry: 2 } }, // each chest gets a container whose id is the record id; items = starting goods (placed once)
|
|
@@ -32,6 +32,11 @@ engine.ops.define('chest.toggle', { run: (e, { id }) => e.world.set(id, { opened
|
|
|
32
32
|
`interact` fields: `op` (required), `label` (text, i18n key, or `(rec, engine) => text`), `radius` (default 2.5), `height`, `action`,
|
|
33
33
|
`enabled: (rec, engine) => boolean`.
|
|
34
34
|
|
|
35
|
+
`collide` forms (the same on a plain prop): `'box'` is the model's bounding box, for buildings and crates. `'circle'` is a cylinder on the model's **base**: the
|
|
36
|
+
geometry in the lowest fifth of its height above the ground, so a tree gets its trunk and a street lamp its pole, and a crown or an arm blocks nobody. Write the radius
|
|
37
|
+
yourself with `collide: { circle: 0.25 }` (model meters: it follows `scale`), still centred on the base; add `occluder: false` when the follow camera may pass it
|
|
38
|
+
(recipes/21-camera.md). A bush or a tree whose crown hangs below head height but above that fifth lets a character walk into the leaves: give it a larger `circle`.
|
|
39
|
+
|
|
35
40
|
## 2. Place instances
|
|
36
41
|
In `content/props.js`, an entry with `template` instead of `model` places an instance. It takes a position and a few explicit overrides:
|
|
37
42
|
```js
|
|
@@ -162,7 +167,7 @@ engine.world.origin('chest-home'); // the same source info for an id
|
|
|
162
167
|
```
|
|
163
168
|
`hit.thing` is on every `engine.pick` / `engine.raycast` hit (computed when read); a hit on a batched copy resolves to its original object.
|
|
164
169
|
`engine.inspect(id).thing` and `engine.explain({ op, args: { id } })` say the same. A hit on a plain object added with `engine.add` gets its
|
|
165
|
-
`hit.thing` from the registry (id, `at` = the file:line of the add, `saved`, `edit`; recipe
|
|
170
|
+
`hit.thing` from the registry (id, `at` = the file:line of the add, `saved`, `edit`; recipe 40). A record made during play shows the op and tick that spawned it
|
|
166
171
|
(`spawned`), a level node its level and node name. Source lines exist in dev and test builds only (a Vite transform tags `content/*.js` with their
|
|
167
172
|
line numbers); a release build has none and pays nothing. From a terminal or an MCP client: `threedog pick 480,270` (screen pixels from the canvas
|
|
168
173
|
top-left) or the MCP tool `pick { x, y }`.
|
|
@@ -171,7 +176,7 @@ top-left) or the MCP tool `pick { x, y }`.
|
|
|
171
176
|
Two doors lead into one scene. Plain three.js, `engine.add(mesh, { id })`, is fine for anything your code rebuilds on every start: a code-built
|
|
172
177
|
windmill, colliders, interactions. A template plus a placement with an `id` in `content/props.js` (or `pickups`, `npcs`, `containers`, a game kind
|
|
173
178
|
from `rules.js`, the level model) is what you want when the thing must be saved with its own state, edited without touching code, or copied many
|
|
174
|
-
times. Both land in the same registry: `engine.thing(id)` answers for either and says what a save keeps (recipe
|
|
179
|
+
times. Both land in the same registry: `engine.thing(id)` answers for either and says what a save keeps (recipe 40). Game code keeps the rules: ops,
|
|
175
180
|
`world.simulate` / `world.present`, conditions and UI. Something that appears during play is created inside an op with `engine.content.spawn`.
|
|
176
181
|
|
|
177
182
|
`npm run check` (rule R33) flags only what breaks, in examples, templates and `games/*` alike. Error: `world.add` (without `{ save: false }`),
|
package/docs/recipes/31-audio.md
CHANGED
|
@@ -9,10 +9,6 @@ Two places, one job each: **the asset manifest says what a sound is** (a file, o
|
|
|
9
9
|
model), **`audio.sounds` says how it plays** (which sound or variants, volume, bus, cooldown...). Engine modules register their own synths
|
|
10
10
|
(`footstep`, `shutter`, `thunder`, ambience's `wind` `rain` `water` `birds` `crickets`) as built-in sound assets that stay silent until a rule names them.
|
|
11
11
|
```js
|
|
12
|
-
engine.assets.manifest({ name: 'sfx', sounds: {
|
|
13
|
-
door: '/sfx/door.ogg', hit1: '/sfx/hit1.ogg', hit2: '/sfx/hit2.ogg', shot: '/sfx/shot.ogg',
|
|
14
|
-
ding: (a, p, out) => { a.tone({ freq: 880 * p.pitch, dur: 0.2, out }); return 0.2; }, // a synth: connect to out, return seconds (or { stop(t) })
|
|
15
|
-
} });
|
|
16
12
|
const engine = createEngine({ canvas, audio: {
|
|
17
13
|
levels: { music: 0.4, voice: 1 }, // volume per bus; an extra key (voice) adds a bus
|
|
18
14
|
sounds: {
|
|
@@ -27,6 +23,10 @@ const engine = createEngine({ canvas, audio: {
|
|
|
27
23
|
music: { tracks: { /* section 4 */ }, rules: [] },
|
|
28
24
|
footsteps: { beach: 'step.sand', default: 'footstep' }, // section 5
|
|
29
25
|
} });
|
|
26
|
+
engine.assets.manifest({ name: 'sfx', sounds: {
|
|
27
|
+
door: '/sfx/door.ogg', hit1: '/sfx/hit1.ogg', hit2: '/sfx/hit2.ogg', shot: '/sfx/shot.ogg',
|
|
28
|
+
ding: (a, p, out) => { a.tone({ freq: 880 * p.pitch, dur: 0.2, out }); return 0.2; }, // a synth: connect to out, return seconds (or { stop(t) })
|
|
29
|
+
} });
|
|
30
30
|
```
|
|
31
31
|
Code may hold functions (a `volume: e => ...`); the same config as data goes in a content pack (section 8). A full working one:
|
|
32
32
|
`examples/world/content/audio.js`.
|
|
@@ -10,7 +10,7 @@ working example is `examples/action/` (page `/action.html`, about 150 lines of r
|
|
|
10
10
|
| The room, the enemy and its stats (hp, damage, drop) | content `templates` + `props` with ids (recipe 30) | `content/templates.js` `slime: { model, static: false, state: { hp, maxHp, damage, cooldown, drop } }` |
|
|
11
11
|
| Player hp, attack cooldown, game over | plain object + `engine.describe.add` + `engine.saves.register` | `const game = fresh()` |
|
|
12
12
|
| Attack, damage, enemy hit, death | ops with `can` / `run` (recipe 23), so keys, the dev bridge, MCP, tests and the AI run one rule | `player.attack`, `enemy.damage`, `enemy.attack`, `player.die` |
|
|
13
|
-
| Enemy AI (chase, face, strike) | `engine.world.simulate(kind, { near })
|
|
13
|
+
| Enemy AI (chase, face, strike) | `engine.world.simulate(kind, { near, channel? })` (channel: bullet time reaches it, section 4), a fixed step per near record; it strikes with `ops.run(..., { actor: rec.id })` | `world.simulate('slime', ...)` |
|
|
14
14
|
| Gameplay keys | content `actions` (`attack: { keys: ['Mouse0', 'KeyF'] }`), read with `input.pressed` in `onFixed` | `onFixed` runs `player.attack` |
|
|
15
15
|
| Drop | `engine.pickups.spawn(at, { give: item, id })` inside the death op; E picks it up through `interactions`, into the bag of whoever presses | `${id}-drop` |
|
|
16
16
|
| HUD, death screen, retry, save keys | `onFrame`: `hud.bar`, `toast`, `engine.session.newGame()` | the frame hook |
|
|
@@ -29,15 +29,17 @@ working example is `examples/action/` (page `/action.html`, about 150 lines of r
|
|
|
29
29
|
`followCamera({ ...presets.camera.overShoulder })` locks the mouse on a click. While locked, mouse buttons still arrive as `Mouse0`..`Mouse4` keys, so
|
|
30
30
|
`attack: { keys: ['Mouse0'] }` works in both states. The click that takes the lock is itself a `Mouse0` press and swings once; a game that does not
|
|
31
31
|
want that ignores attacks until the `page:pointerlock` event reports `locked: true`. `presets.player.aim` turns the player toward where the camera
|
|
32
|
-
looks, so a swing goes where you aim.
|
|
33
|
-
|
|
32
|
+
looks, so a swing goes where you aim. The rules do not need the picture: `?picture=none` runs them under the engine's placeholder lights; the whole picture is
|
|
33
|
+
`examples/action/picture/`.
|
|
34
34
|
|
|
35
35
|
## 4. Movement: jumps, speed effects, bullet time, platforms, falling
|
|
36
36
|
```js
|
|
37
37
|
createPlayer({ ...presets.player.thirdPerson, maxJumps: 2 }); // double jump: the same jump key twice
|
|
38
38
|
engine.player.launch(16, { owner: 'pad' }); // a jump pad / spring
|
|
39
39
|
engine.mod('move.speed', { owner: 'haste', id: 'player', mul: 1.2, for: 5 }); // haste for 5 s; no id = every character (mud, wind)
|
|
40
|
+
engine.time.channel('enemies'); // once, before anything uses it: a channel of your own
|
|
40
41
|
engine.mod('time.enemies', { owner: 'bullet-time', mul: 0.35, for: 2 }); // bullet time: enemies on channel 'enemies' at 35%
|
|
42
|
+
engine.world.simulate('slime', { near: chase, channel: 'enemies' }); // world records (the enemy AI above) get the slowed dt
|
|
41
43
|
engine.onFixed(dt => moveShots(dt), { channel: 'enemies' }); // your own enemy logic on the same slowed dt
|
|
42
44
|
engine.characters.support(liftMesh); // a moving platform: move liftMesh any way, riders follow
|
|
43
45
|
engine.player.mover = 'manual'; /* a cutscene, your own physics */ engine.player.mover = 'simple'; // take over, give back
|
|
@@ -52,12 +54,24 @@ engine.player.mover = 'manual'; /* a cutscene, your own physics */ engine.player
|
|
|
52
54
|
'player', set: 0, for: 0.8 })`. `move()` takes no speed argument; the direction's length (0-1) scales the speed.
|
|
53
55
|
- **Bullet time / time channels**: a character the engine drives moves and animates on `character.channel` (player `'player'`, NPCs `'world'`), so
|
|
54
56
|
`engine.mod('time.enemies', { owner: 'bullet-time', mul: 0.35 })` slows NPCs added with `npcs.add({ channel: 'enemies' })` (far ones too) and
|
|
55
|
-
`onFixed(fn, { channel: 'enemies' })` code; `
|
|
57
|
+
`onFixed(fn, { channel: 'enemies' })` code; world records follow only with `world.simulate(kind, { near, channel: 'enemies' })` (without it they
|
|
58
|
+
keep the 'world' pace while everything else slows); `clock.after(1, 'poison:tick', data, { channel: 'enemies' })` slows a timer with them. The player keeps
|
|
56
59
|
full speed unless you mod `'time.player'`. Your own `player.move(x, z, run, dt)` uses the dt you pass. Effects end in any order (recipe 55).
|
|
57
60
|
- **Platforms**: `characters.support(object, { id?, safe?, carry?: 'position' | 'position+yaw', inherit? })` returns `{ id, remove() }`. The rider
|
|
58
61
|
compares the platform's matrix with the one it recorded, so it does not matter whether the platform moves in your `onFixed` before or after the
|
|
59
62
|
player, in a timeline or in physics. `player.support` says what it stands on (`kind: 'ground' | 'platform' | 'collider' | 'water' | null`, the
|
|
60
63
|
platform's `velocity`); jumping off keeps the platform's speed until landing. With `mover: 'rapier'` give the platform a collider as well.
|
|
64
|
+
**What it needs**: the standing height is the top of the bounding box of every mesh under the object you pass, over that box's footprint. Pass the
|
|
65
|
+
floor mesh, not the whole model: a group with a mast or a railing has its top up there, and the character passes under it to whatever is below (a
|
|
66
|
+
boat at sea leaves it on the sea floor). A character gets on when its feet are at most `stepHeight` below the top, or it falls or is placed onto
|
|
67
|
+
it (`placeAt` over a support stands on it). Moving the parent moves the floor mesh, so move the whole model as you like.
|
|
68
|
+
```js
|
|
69
|
+
const raft = new THREE.Group(), deck = new THREE.Mesh(new THREE.BoxGeometry(3, 0.2, 2), wood);
|
|
70
|
+
raft.add(deck, mast); engine.scene.add(raft);
|
|
71
|
+
engine.characters.support(deck, { id: 'raft' }); // the deck, not the raft with its mast
|
|
72
|
+
engine.onFixed(dt => { raft.position.x += 1.5 * dt; }); // the player on it is carried
|
|
73
|
+
```
|
|
74
|
+
A ride the player does not steer is `engine.control` instead (recipe 57, Moved by script).
|
|
61
75
|
- **Falling out**: `createPlayer({ ..., fall: { belowY: -20 } })` fires `character:fall { character, safe, preventDefault() }` once and puts the player
|
|
62
76
|
back on `player.safeGround` (the last spot it stood still on safe, unmoving ground; saved). Take hp in the listener; `preventDefault()` to handle it yourself.
|
|
63
77
|
- **Your own controller**: `mover: 'manual'` = you write the position; `move()` then only updates `grounded`, `support` (platforms still carry),
|
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
# Environment lighting
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
(lit by the sun and hemisphere lights only) is unchanged. The background (the sky dome or `sky.skybox`) and the environment lighting are two separate fields.
|
|
3
|
+
`scene.environment` is plain three.js and stays `null` until your code writes it. The background (the sky dome or a skybox) and the environment lighting are two separate fields.
|
|
5
4
|
|
|
6
5
|
```js
|
|
7
|
-
engine.
|
|
8
|
-
engine.
|
|
9
|
-
engine.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
engine.
|
|
6
|
+
const env = engine.sky.environment({ into: engine.scene }); // the sky as a map: follows the time of day; env.texture is the live map
|
|
7
|
+
engine.scene.environmentIntensity = 0.8; // intensity and rotation are three.js
|
|
8
|
+
engine.scene.environmentRotation.y = Math.PI / 2;
|
|
9
|
+
env.remove(); // takes the map off, frees it
|
|
10
|
+
// an asset panorama: plain PMREMGenerator
|
|
11
|
+
const pmrem = new THREE.PMREMGenerator(engine.renderer);
|
|
12
|
+
engine.assets.useTexture('hdr/studio.hdr', t => { t.mapping = THREE.EquirectangularReflectionMapping; engine.scene.environment = pmrem.fromEquirectangular(t).texture; });
|
|
13
|
+
// a PMREM result of your own is used as it is
|
|
14
|
+
engine.scene.environment = myPmremTarget.texture;
|
|
14
15
|
```
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
-
|
|
21
|
-
cover actually changed AND at least `interval` seconds (default 1, low
|
|
22
|
-
day builds once.
|
|
23
|
-
-
|
|
24
|
-
|
|
25
|
-
- The cube is at least 256 px per face (PMREMGenerator's floor in 0.187), so a low tier saves time by rebuilding less often or by turning it off, not
|
|
26
|
-
by a smaller cube.
|
|
16
|
+
On `renderer: 'webgpu'` take `PMREMGenerator` from `three/webgpu`. A map you made is yours to dispose.
|
|
17
|
+
|
|
18
|
+
## The sky as a map: `engine.sky.environment({ into?, interval? })`
|
|
19
|
+
- Nothing is built before this call. Without `into` nothing is written anywhere: read `handle.texture` (a live getter) and put it on the materials you choose (`material.envMap`).
|
|
20
|
+
- With `into`, that object's `.environment` gets the map at each rebuild. A map you write there yourself stays: the rebuilds go on, but only `handle.texture` follows them.
|
|
21
|
+
- The dome is rendered into a cube and prefiltered with `PMREMGenerator`. It is rebuilt only when the sky colors, sun direction or cloud
|
|
22
|
+
cover actually changed AND at least `interval` seconds (default 1, 4 times longer on a low-tier device) passed since the last check, never every frame. A fixed time of
|
|
23
|
+
day builds once. A call before the first frame waits for that frame, so the map uses real colors.
|
|
24
|
+
- The cube is at least 256 px per face (PMREMGenerator's floor in 0.187), so a low tier saves time by rebuilding less often, or by your `picture/` code skipping the call on `engine.tier === 'low'`.
|
|
25
|
+
- An asset map is a fixed photo: it does not dim at night. Write `scene.environmentIntensity` from your own frame code reading `engine.uniforms.uDaylight`.
|
|
27
26
|
|
|
28
27
|
## What a MeshLambertMaterial does with it (three 0.187 source, not memory)
|
|
29
28
|
- `WebGLPrograms` hands `scene.environment` to Standard, Lambert and Phong materials; a Lambert material without its own `envMap` uses the PMREM path.
|
|
@@ -32,28 +31,93 @@ Removing a game layer (`h.remove()`) falls back to the pack's env, and with none
|
|
|
32
31
|
- No specular: the cube reflection mix in `envmap_fragment` only runs for `ENVMAP_TYPE_CUBE`, not for a PMREM map. Lambert surfaces never get
|
|
33
32
|
reflections from the scene environment (use a Standard / Physical material for that).
|
|
34
33
|
- Intensity is `scene.environmentIntensity`, direction offset is `scene.environmentRotation` (Y only here).
|
|
35
|
-
- The hemisphere light stays and adds on top. When you turn the environment on, lower
|
|
36
|
-
`engine.mod('look.lights.hemi.intensity', { owner: 'env', mul: 0.5 })`, [recipe 52](52-look.md#how-look-values-stack)) so shadows do not wash out.
|
|
34
|
+
- The hemisphere light stays and adds on top. When you turn the environment on, lower your hemisphere light so shadows do not wash out.
|
|
37
35
|
- The first frame with an environment recompiles every Lambert program once (the program key gains the env map); do it at start-up, not mid-game.
|
|
38
36
|
- Toon, Basic and ShaderMaterial surfaces ignore it.
|
|
39
37
|
|
|
40
38
|
## Light probes (baked indirect light)
|
|
41
|
-
An environment map lights everything as seen from one point. Light probes record how the light changes from place to place (a colored glow beside
|
|
42
|
-
a bright wall, dimmer light under a roof) and
|
|
39
|
+
An environment map lights everything as seen from one point. Light probes (`engine.bakeProbes`) record how the light changes from place to place (a colored glow beside
|
|
40
|
+
a bright wall, dimmer light under a roof), and every lit pixel takes its own light from the grid, on WebGL and WebGPU, with no shader of your own.
|
|
43
41
|
```js
|
|
44
42
|
const probes = await engine.bakeProbes({ bounds: { min: [-30, 0, -30], max: [30, 8, 30] }, spacing: 4, include: o => !o.userData.moving });
|
|
45
|
-
const file = JSON.stringify(probes.toJSON()); // ship this
|
|
46
|
-
const shipped = engine.loadProbes(json
|
|
47
|
-
probes.sample(cart.position
|
|
43
|
+
const file = JSON.stringify(probes.toJSON()); // ship this (half precision, a few tens of KB)
|
|
44
|
+
const shipped = engine.loadProbes(json); // at start-up, instead of the bake; either renderer reads either renderer's file
|
|
45
|
+
probes.sample(cart.position); // the SH at any point, for a "how dark is it here"
|
|
48
46
|
probes.remove();
|
|
49
47
|
```
|
|
50
|
-
- What it builds:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
48
|
+
- What it builds: three's probe grid over `bounds` (`LightProbeGridWebGL` or `LightProbeGrid`; step at most `spacing`, at least 2 layers per axis), in the scene as
|
|
49
|
+
`probes.grid`, a plain three.js light: `priority` and `visible` are yours; `intensity` works on WebGPU only, three's WebGL shader ignores it. The light costs almost nothing per frame.
|
|
50
|
+
- **Outside the grid there is no probe light**, and with no other ambient light a mesh goes black there. The light reaches half a step past `bounds`, so a roof on the edge is fine.
|
|
51
|
+
Size `bounds` to where things are.
|
|
52
|
+
- **Light counted twice**: the bake saw the hemisphere light and the environment, and they still add at run time. Lower them where the probes take over, or bake without them.
|
|
53
|
+
A `material.lightMap` inside the grid doubles the same way. A warning says so when the set is added, and describe keeps saying it.
|
|
54
|
+
- Dark bake indoors: `scene.background` is a display color, far weaker than the sun, so a room lit by the sky comes out black. Raise the sky just for the bake
|
|
55
|
+
(a brighter `scene.background` or `backgroundIntensity`, put back after), and keep a little fill for walls that face away from every window.
|
|
56
|
+
- Cost: 6 renders per probe at load time, a few probes per task, so the page keeps drawing (`probes.bakeMs` says how long). Bake once and ship the JSON: phones often cannot bake, but
|
|
57
|
+
they all read the file. Meshes `include` rejects are hidden only while the cubes render. Adding a grid recompiles lit materials once, so do it at start-up.
|
|
58
|
+
- Check it: `engine.describe().render.probes` (count, step, source, owner, `outside`: lit objects the grid does not hold, `doubled`: what counts twice) and `engine.debug.view('probes')` (a dot per probe in its average color).
|
|
59
|
+
|
|
60
|
+
## Lightmaps (baked light on what never moves)
|
|
61
|
+
The best-looking baked light, and free at run time: it is plain `material.lightMap` on a second UV set, so a file baked on WebGPU draws the same on WebGL. Baking needs a real GPU and Google Chrome on the machine that bakes, not on the player's.
|
|
62
|
+
```js
|
|
63
|
+
floor.userData.static = true; wall.userData.static = true; // named meshes that never move
|
|
64
|
+
// npx threedog bake light --out public/light/level.lightmap --size 1024 --spacing 2
|
|
65
|
+
const light = await engine.loadLightmap('light/level.lightmap'); // once the level is built
|
|
66
|
+
hemi.intensity = 0; // the bake saw it: keep the sun, drop the ambient
|
|
67
|
+
floor.material.lightMapIntensity = 1.2; // plain three.js, yours
|
|
68
|
+
```
|
|
69
|
+
- What is baked: sky and first bounce, from a probe grid over the static meshes. The sun stays real-time, so moving things keep their shadows. The game's hemisphere or ambient light stands in for the sky during the bake.
|
|
70
|
+
- Instanced and skinned meshes and anything moving cannot hold a lightmap: give them `engine.bakeProbes`. A grid also lights the baked meshes, so where the two overlap the light doubles; keep the grid's `bounds` to where the moving things go, or turn `lightMapIntensity` down.
|
|
71
|
+
- Files are large: half precision, 8 MB at 1024, 32 MB at 2048, before the server's compression. Start small.
|
|
72
|
+
- Check it: `engine.describe().render.lightmap` lists `skipped` (instanced), `missing` (not found, or changed since the bake: bake again), `moved`, `doubled` (ambient light or a grid on top) and `shared` (an unbaked mesh on a baked material: give it its own).
|
|
73
|
+
- WebGPU and TSL: nothing changes. `material.lightMap` is read by node materials too, so there is no separate form.
|
|
74
|
+
|
|
75
|
+
## Real-time bounced light (WebGPU games only)
|
|
76
|
+
|
|
77
|
+
Bake first when the scene holds still: probes and lightmaps match it and cost nearly nothing. Real-time bounce is for light that changes while the world stands: a sun that moves, a lamp the player carries, a door that lets a room fill. It needs `renderer: 'webgpu'` chosen when the game starts, and three's real WebGPU backend; there is no WebGL version.
|
|
78
|
+
|
|
79
|
+
```js
|
|
80
|
+
import { voxelGI, temporalAA } from '@threedog/post-effects/tsl';
|
|
81
|
+
engine.post.add(voxelGI({ bounds: new THREE.Box3(min, max), intensity: 1 }));
|
|
82
|
+
engine.post.add(temporalAA()); // clears the dots; it replaces MSAA while it is on
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
- `bounds` is the world box to voxelize. Keep it tight: the same voxels spread over a town are too coarse for a room. `describe().render.post` gives `voxelSize`; judge it against the smallest thing that should throw color.
|
|
86
|
+
- Lights can move every frame. Geometry cannot: moving things go outside the volume (`setup: gi => gi.volume.layers...`), and a rare change (a wall falls) calls `gi.needsUpdate = true`, a stall of many milliseconds.
|
|
87
|
+
- It bounces direct light only, so sky light stays yours: a low hemisphere or environment light, judged by eye once the bounce is on. How to judge: a colored wall should tint what stands next to it, and a sunlit floor should lift the ceiling, without the shadows turning flat. A cartoon look may want one soft bounce; a realistic interior wants more with less fill.
|
|
88
|
+
- Changing any post effect (add, remove, on / off, a setting that rebuilds) rebuilds the chain, and that voxelizes the scene again: a stall. Set the chain at a scene change, not during play.
|
|
89
|
+
- `occlusion` (0 to 1) darkens corners from the voxels. It darkens direct light too, which is why it starts at 0.
|
|
90
|
+
- It costs real frame time on weak GPUs, so it declares `skipOnLowTier` and is held off on `engine.tier === 'low'`. It is also held on a device that fell back from WebGPU and under `forceWebGL: true`. Nothing breaks, `describe().render.post` says `held` and why, so give those players probes or a lightmap as the base. A game that chose `WebGLRenderer` gets a named error instead, as for the other effects of this page.
|
|
91
|
+
- Does not work: metal gets a diffuse bounce instead of a reflection; anything moving is not in the bounce; transparent things are not handled; one volume does not cover a big open world.
|
|
92
|
+
|
|
93
|
+
What runs where, for the four effects above (`voxelGI`, `temporalAA`, `sunShafts`, `lightVolumes`). Held means the game's `enabled` stays as written, the effect costs nothing, and `describe().render.post` says why:
|
|
94
|
+
|
|
95
|
+
| Case | voxelGI | temporalAA, sunShafts, lightVolumes |
|
|
96
|
+
|---|---|---|
|
|
97
|
+
| Real WebGPU | runs (held on `engine.tier` 'low') | run |
|
|
98
|
+
| WebGL2 backend (no WebGPU in the browser, or `forceWebGL: true`) | held | run |
|
|
99
|
+
| Fell back to `WebGLRenderer` (`start()` found no WebGPU) | held | held |
|
|
100
|
+
| Game chose WebGL (`--webgl`, `WebGLRenderer`) | throws by name | throw by name |
|
|
101
|
+
|
|
102
|
+
## Light you can see in the air
|
|
103
|
+
|
|
104
|
+
Pick by the light. These two are WebGPU only; a WebGL game keeps the depth haze of recipe 59.
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
import { sunShafts, lightVolumes } from '@threedog/post-effects/tsl';
|
|
108
|
+
engine.post.add(sunShafts({ light: engine.lights.sun })); // sun through gaps
|
|
109
|
+
engine.post.add(lightVolumes({ bounds: new THREE.Box3(min, max) })); // spot cones, point glows
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
- `sunShafts` (three's `GodraysNode`) marches the sun's shadow map, so the sun and whatever makes the gaps must cast shadows. It is made for air that is mostly in shadow: a room with a window, a forest. In open daylight every pixel of air is lit and it reads as haze; there, lower `density` or leave it out. Raise `density` until the beam reads against the dark behind it, and stop before the far wall washes out. A misty horror game and a clean sunny one will end far apart.
|
|
113
|
+
- `lightVolumes` (three's `VolumeNodeMaterial`) fills a box of air and lights it from point and spot lights, shadows included. **The sun does nothing here**, three skips lights at infinity. It is dithered, so run `temporalAA` after it. `scattering: (tsl, { positionRay, density }) => ...` gives density per point for smoke or ground fog; multiply by `uniforms(engine).uWeatherFog` from `threedog/tsl` to follow the weather.
|
|
114
|
+
- Does not work: shafts from more than one light at once, cones through transparent glass, and either effect on WebGLRenderer (`engine.post.add` throws by name there). If you need crisp sun beams in open air, a spot light aimed along the sun with `lightVolumes` gives a shaft you can place by hand.
|
|
115
|
+
|
|
116
|
+
## Occlusion culling
|
|
117
|
+
|
|
118
|
+
`engine.occlusion.enabled = true` skips the engine's big things while something hides them: hlod cells and `engine.batching` groups. Works on both renderers. Ordinary objects are not watched. Turn it on only when heavy things stand behind others (a walled town, a building full of rooms). In a scene of many small things it is a loss: each box costs CPU, more so on WebGPU. Measure with `describe().render.occlusion` (`hidden`, `trianglesSkipped`) and the frame time, on and off.
|
|
119
|
+
|
|
120
|
+
- Three things share the word occlusion and are separate: occlusion culling (this section) skips drawing what is hidden; camera occlusion (`cameraOcclusion` of `collision()`, recipe 21) moves the camera so a wall does not stand between it and the player; `voxelGI`'s `occlusion` only darkens corners of its bounced light.
|
|
121
|
+
- Hidden things stay in shadows, in `engine.rays` and in `voxelGI`'s volume, and `visible` stays yours. Nothing else sees them while hidden: a second camera of yours and a `THREE.Raycaster` of your own do not (their layers lack it; enable `RESERVED_LAYERS.occlusionHidden` from `threedog/layers` if they must).
|
|
122
|
+
- Answers come a few frames late. Camera moves and cuts are covered. A big occluder that moves fast (a falling wall, a gate thrown open) can show a gap of a few frames.
|
|
123
|
+
|