threedog 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +81 -1
- package/README.md +21 -13
- package/core/Assets.js +23 -12
- package/core/Audio.js +1 -1
- package/core/Baked.js +14 -23
- package/core/Budget.js +2 -2
- package/core/DebugOverrides.js +33 -18
- package/core/Describe.js +10 -11
- package/core/Engine.js +50 -46
- package/core/I18n.js +2 -2
- package/core/Input.js +11 -5
- package/core/Inspect.js +6 -3
- package/core/InspectMaterials.js +2 -3
- package/core/InspectPerf.js +11 -4
- package/core/MaterialInfo.js +7 -5
- package/core/Rays.js +7 -2
- package/core/Stream.js +2 -3
- package/core/UrlState.js +49 -9
- package/core/Views.js +1 -0
- package/core/adaptive.js +2 -2
- package/core/assetEntry.js +5 -2
- package/core/assetLoad.js +13 -15
- package/core/assetManifest.js +6 -3
- package/core/assetReport.js +4 -4
- package/core/batchGroups.js +9 -1
- package/core/catalog.js +16 -3
- package/core/chunkStream.js +1 -1
- package/core/copies.js +1 -1
- package/core/debugView.js +4 -4
- package/core/describeRender.js +104 -28
- package/core/describeText.js +6 -6
- package/core/errorCodes.js +72 -45
- package/core/errorHints.js +4 -1
- package/core/errors.js +4 -4
- package/core/events.generated.js +1 -0
- package/core/gameLights.js +9 -2
- package/core/lifecycle.js +2 -4
- package/core/lightWatch.js +5 -3
- package/core/loop.js +18 -11
- package/core/math.js +7 -0
- package/core/moduleSlots.js +32 -7
- package/core/moduleTypes.js +20 -7
- package/core/modules.js +7 -7
- package/core/namedModel.js +8 -4
- package/core/owned.js +33 -30
- package/core/page.js +43 -10
- package/core/pictureSlots.js +33 -0
- package/core/pictureWriters.js +343 -0
- package/core/plugins.js +64 -96
- package/core/sceneDelta.js +12 -4
- package/core/sceneMethods.js +2 -9
- package/core/services.js +1 -1
- package/core/shadowTypes.js +1 -1
- package/core/shadows.js +405 -0
- package/core/sharedPoint.js +5 -19
- package/core/stackFrames.js +16 -5
- package/core/stacks.js +6 -6
- package/core/startup.js +9 -11
- package/core/thingExplain.js +1 -1
- package/core/things.js +1 -1
- package/core/tier.js +1 -1
- package/core/util.js +1 -1
- package/core/validate.js +1 -1
- package/core/view.js +43 -0
- package/docs/AI.md +62 -58
- package/docs/API.md +15 -15
- package/docs/CODEMAP.md +36 -54
- package/docs/COMMANDS.md +28 -25
- package/docs/CONVENTIONS.md +36 -30
- package/docs/MIGRATING-0.4.md +93 -1
- package/docs/MIGRATING-0.6.md +126 -0
- package/docs/MIGRATING-0.7.md +39 -0
- package/docs/THREE.md +24 -22
- package/docs/api/assets.md +5 -3
- package/docs/api/audio.md +2 -2
- package/docs/api/budget.md +4 -0
- package/docs/api/characters.md +3 -1
- package/docs/api/collision.md +2 -2
- package/docs/api/engine.md +47 -20
- package/docs/api/events.md +2 -1
- package/docs/api/grids.md +8 -1
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +3 -0
- package/docs/api/input.md +3 -2
- package/docs/api/interactions.md +3 -1
- package/docs/api/inventory.md +1 -2
- package/docs/api/level.md +0 -1
- package/docs/api/lightPool.md +1 -1
- package/docs/api/occlusion.md +5 -0
- package/docs/api/particles.md +6 -3
- package/docs/api/pickups.md +6 -0
- package/docs/api/post.md +5 -3
- package/docs/api/sky.md +12 -10
- package/docs/api/terrain.md +12 -6
- package/docs/api/terrainDraw.md +12 -0
- package/docs/api/tools.md +8 -7
- package/docs/api/triggers.md +2 -0
- package/docs/api/vegetation.md +7 -2
- package/docs/api/vegetationDraw.md +10 -0
- package/docs/api/water.md +6 -2
- package/docs/api/weather.md +5 -0
- package/docs/api/weatherDraw.md +10 -0
- package/docs/api/world.md +1 -1
- package/docs/recipes/01-new-game.md +19 -23
- package/docs/recipes/03-items-pickups.md +25 -4
- package/docs/recipes/05-props-bake.md +53 -37
- package/docs/recipes/06-clock-events.md +3 -3
- package/docs/recipes/07-flow-scenes-pause.md +12 -3
- package/docs/recipes/08-weather-sky.md +45 -57
- package/docs/recipes/09-materials-lights-models.md +185 -0
- package/docs/recipes/10-blender-level.md +2 -2
- package/docs/recipes/11-vehicles.md +3 -3
- package/docs/recipes/13-animation.md +13 -7
- package/docs/recipes/14-custom-module.md +7 -5
- package/docs/recipes/15-perf.md +3 -3
- package/docs/recipes/16-dev-bridge.md +22 -12
- package/docs/recipes/18-world.md +10 -8
- package/docs/recipes/19-shooting-picking.md +7 -5
- package/docs/recipes/20-content-actions-save.md +6 -2
- package/docs/recipes/21-camera.md +8 -3
- package/docs/recipes/23-ops.md +1 -1
- package/docs/recipes/26-ui-parts.md +35 -11
- package/docs/recipes/28-terrain.md +12 -12
- package/docs/recipes/29-grid.md +14 -5
- package/docs/recipes/30-templates.md +8 -3
- package/docs/recipes/31-audio.md +4 -4
- package/docs/recipes/32-action-game.md +18 -4
- package/docs/recipes/34-environment-lighting.md +102 -38
- package/docs/recipes/35-picture-from-reference.md +147 -0
- package/docs/recipes/36-sky-ground-plants.md +158 -0
- package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -13
- package/docs/recipes/38-environment-hooks.md +67 -0
- package/docs/recipes/40-scene.md +106 -27
- package/docs/recipes/42-terrain-shape.md +1 -1
- package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +66 -77
- package/docs/recipes/44-water-weather-hooks.md +191 -0
- package/docs/recipes/45-cascaded-shadows.md +121 -23
- package/docs/recipes/46-blender-art-route.md +17 -20
- package/docs/recipes/47-island-snow-backdrop.md +10 -12
- package/docs/recipes/49-game-module-contract.md +1 -1
- package/docs/recipes/50-own-renderer.md +3 -3
- package/docs/recipes/52-around-the-picture.md +181 -0
- package/docs/recipes/53-ground-up-close.md +12 -12
- package/docs/recipes/54-three-idioms.md +18 -18
- package/docs/recipes/55-mods-time-wrap.md +17 -5
- package/docs/recipes/56-webgpu-tsl.md +66 -23
- package/docs/recipes/57-control.md +39 -0
- package/docs/recipes/58-input.md +3 -0
- package/docs/recipes/59-depth-post-effects.md +5 -5
- package/docs/recipes/60-judge-the-picture.md +39 -24
- package/docs/recipes/61-deploy.md +27 -0
- package/docs/recipes/62-picture-code.md +244 -0
- package/docs/recipes/63-third-person-start.md +77 -0
- package/docs/recipes/64-particles.md +35 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +7 -5
- package/examples/action/main.js +5 -4
- package/examples/action/models.js +12 -14
- package/examples/action/picture/index.js +13 -0
- package/examples/action/picture/lights.js +35 -0
- package/examples/action/picture/materials.js +8 -0
- package/examples/action/picture/palette.js +33 -0
- package/examples/plain-picture/.threedog/content-index.json +1 -0
- package/examples/plain-picture/FINDINGS.md +53 -0
- package/examples/plain-picture/GAMEMAP.md +90 -0
- package/examples/plain-picture/main.js +48 -0
- package/examples/plain-picture/picture/index.js +21 -0
- package/examples/plain-picture/picture/lights.js +54 -0
- package/examples/plain-picture/picture/materials.js +24 -0
- package/examples/plain-picture/picture/palette.js +16 -0
- package/examples/plain-picture/picture/sky.js +37 -0
- package/examples/pullable.json +31 -9
- package/examples/rc2d/GAMEMAP.md +8 -3
- package/examples/rc2d/README.md +11 -6
- package/examples/rc2d/main.js +25 -33
- package/examples/rc2d/picture/index.js +18 -0
- package/examples/rc2d/picture/lights.js +11 -0
- package/examples/rc2d/picture/materials.js +18 -0
- package/examples/rc2d/picture/palette.js +15 -0
- package/examples/rc2d/picture/post.js +11 -0
- package/examples/rc2d/rc2d.js +18 -28
- package/examples/sheepisland/.threedog/content-index.json +1 -1
- package/examples/sheepisland/GAMEMAP.md +13 -10
- package/examples/sheepisland/assets.js +2 -2
- package/examples/sheepisland/content/templates.js +1 -1
- package/examples/sheepisland/content/vegetation.js +3 -1
- package/examples/sheepisland/main.js +15 -9
- package/examples/sheepisland/{style/models.js → models.js} +13 -24
- package/examples/sheepisland/picture/index.js +20 -0
- package/examples/sheepisland/picture/lights.js +34 -0
- package/examples/sheepisland/picture/materials.js +61 -0
- package/examples/sheepisland/picture/palette.js +60 -0
- package/examples/sheepisland/picture/sky.js +20 -0
- package/examples/sheepisland/views.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +15 -11
- package/examples/styletest/main.js +20 -30
- package/examples/styletest/models.js +29 -29
- package/examples/styletest/params.js +1 -4
- package/examples/styletest/picture/env.js +38 -0
- package/examples/styletest/picture/index.js +16 -0
- package/examples/styletest/picture/lights.js +9 -0
- package/examples/styletest/picture/materials.js +28 -0
- package/examples/styletest/picture/palette.js +22 -0
- package/examples/techniques/contact-shadows/README.md +22 -23
- package/examples/techniques/contact-shadows/contactShadows.js +32 -16
- package/examples/techniques/contact-shadows/main.js +20 -18
- package/examples/techniques/contact-shadows/picture/index.js +14 -0
- package/examples/techniques/contact-shadows/picture/lights.js +34 -0
- package/examples/techniques/contact-shadows/picture/materials.js +12 -0
- package/examples/techniques/contact-shadows/picture/palette.js +17 -0
- package/examples/techniques/day-night-grade/README.md +13 -16
- package/examples/techniques/day-night-grade/main.js +15 -25
- package/examples/techniques/day-night-grade/picture/index.js +20 -0
- package/examples/techniques/day-night-grade/picture/lights.js +45 -0
- package/examples/techniques/day-night-grade/picture/materials.js +15 -0
- package/examples/techniques/day-night-grade/picture/palette.js +59 -0
- package/examples/techniques/day-night-grade/picture/post.js +25 -0
- package/examples/techniques/day-night-grade/picture/sky.js +33 -0
- package/examples/techniques/interior-light/README.md +16 -13
- package/examples/techniques/interior-light/interiorLight.js +19 -17
- package/examples/techniques/interior-light/main.js +30 -67
- package/examples/techniques/interior-light/picture/index.js +24 -0
- package/examples/techniques/interior-light/picture/lights.js +52 -0
- package/examples/techniques/interior-light/picture/materials.js +13 -0
- package/examples/techniques/interior-light/picture/palette.js +32 -0
- package/examples/techniques/interior-light/picture/sky.js +40 -0
- package/examples/techniques/modular-building/README.md +4 -3
- package/examples/techniques/modular-building/kit.js +2 -2
- package/examples/techniques/modular-building/main.js +9 -17
- package/examples/techniques/modular-building/picture/index.js +17 -0
- package/examples/techniques/modular-building/picture/lights.js +26 -0
- package/examples/techniques/modular-building/picture/materials.js +13 -0
- package/examples/techniques/modular-building/picture/palette.js +23 -0
- package/examples/techniques/night-lights/README.md +15 -14
- package/examples/techniques/night-lights/main.js +20 -43
- package/examples/techniques/night-lights/nightLights.js +25 -21
- package/examples/techniques/night-lights/picture/index.js +18 -0
- package/examples/techniques/night-lights/picture/lights.js +44 -0
- package/examples/techniques/night-lights/picture/materials.js +15 -0
- package/examples/techniques/night-lights/picture/palette.js +34 -0
- package/examples/techniques/night-lights/picture/post.js +9 -0
- package/examples/techniques/night-lights/picture/sky.js +36 -0
- package/examples/techniques/outlines-and-rim/README.md +2 -2
- package/examples/techniques/outlines-and-rim/main.js +15 -38
- package/examples/techniques/outlines-and-rim/outlines.js +3 -3
- package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
- package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
- package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
- package/examples/techniques/procedural-animation/README.md +5 -3
- package/examples/techniques/procedural-animation/main.js +9 -7
- package/examples/techniques/procedural-animation/picture/index.js +15 -0
- package/examples/techniques/procedural-animation/picture/lights.js +35 -0
- package/examples/techniques/procedural-animation/picture/materials.js +10 -0
- package/examples/techniques/procedural-animation/picture/palette.js +16 -0
- package/examples/techniques/procedural-animation/picture/sky.js +31 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +1 -1
- package/examples/techniques/procedural-surface/README.md +2 -0
- package/examples/techniques/procedural-surface/main.js +17 -55
- package/examples/techniques/procedural-surface/picture/index.js +14 -0
- package/examples/techniques/procedural-surface/picture/lights.js +18 -0
- package/examples/techniques/procedural-surface/picture/materials.js +34 -0
- package/examples/techniques/procedural-surface/picture/palette.js +15 -0
- package/examples/techniques/stylized-shading/README.md +13 -14
- package/examples/techniques/stylized-shading/main.js +11 -42
- package/examples/techniques/stylized-shading/picture/index.js +14 -0
- package/examples/techniques/stylized-shading/picture/lights.js +23 -0
- package/examples/techniques/stylized-shading/picture/materials.js +18 -0
- package/examples/techniques/stylized-shading/picture/palette.js +19 -0
- package/examples/techniques/stylized-shading/shading.js +2 -2
- package/examples/techniques/sun-and-key-light/README.md +20 -22
- package/examples/techniques/sun-and-key-light/keyLight.js +47 -29
- package/examples/techniques/sun-and-key-light/main.js +19 -63
- package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
- package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
- package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
- package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
- package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
- package/examples/techniques/three-looks/README.md +21 -0
- package/examples/techniques/three-looks/main.js +58 -0
- package/examples/techniques/three-looks/picture/cartoon.js +23 -0
- package/examples/techniques/three-looks/picture/cinematic.js +27 -0
- package/examples/techniques/three-looks/picture/comic.js +27 -0
- package/examples/techniques/three-looks/picture/index.js +14 -0
- package/examples/techniques/three-looks/picture/sun.js +23 -0
- package/examples/techniques/wet-road/README.md +7 -4
- package/examples/techniques/wet-road/main.js +18 -38
- package/examples/techniques/wet-road/picture/index.js +17 -0
- package/examples/techniques/wet-road/picture/lights.js +57 -0
- package/examples/techniques/wet-road/picture/materials.js +16 -0
- package/examples/techniques/wet-road/picture/palette.js +24 -0
- package/examples/techniques/wet-road/picture/sky.js +46 -0
- package/examples/webgpu-tsl/GAMEMAP.md +9 -4
- package/examples/webgpu-tsl/README.md +13 -10
- package/examples/webgpu-tsl/main.js +30 -7
- package/examples/webgpu-tsl/picture/index.js +18 -0
- package/examples/webgpu-tsl/picture/lights.js +25 -0
- package/examples/webgpu-tsl/picture/materials.js +36 -0
- package/examples/webgpu-tsl/picture/palette.js +23 -0
- package/examples/webgpu-tsl/picture/post.js +16 -0
- package/examples/webgpu-tsl/picture/sky.js +30 -0
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +15 -12
- package/examples/world/art/humanoid.js +9 -13
- package/examples/world/art/index.js +2 -2
- package/examples/world/art/models.js +3 -4
- package/examples/world/art/shapes.js +2 -2
- package/examples/world/assets.js +2 -2
- package/examples/world/content/audio.js +1 -1
- package/examples/world/content/items.js +1 -1
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +10 -10
- package/examples/world/models.js +17 -7
- package/examples/world/picture/index.js +20 -0
- package/examples/world/picture/lights.js +41 -0
- package/examples/world/picture/materials.js +34 -0
- package/examples/world/picture/palette.js +74 -0
- package/examples/world/picture/post.js +9 -0
- package/examples/world/picture/sky.js +39 -0
- package/index.d.ts +7 -16
- package/index.js +7 -7
- package/llms.txt +15 -13
- package/modules/ambience/Ambience.js +1 -1
- package/modules/calendar/Calendar.js +1 -1
- package/modules/calendar/index.js +1 -0
- package/modules/camera/FirstPersonCamera.js +1 -1
- package/modules/camera/FixedCamera.js +2 -2
- package/modules/camera/RtsCamera.js +1 -1
- package/modules/camera/common.js +7 -5
- package/modules/characters/Character.js +15 -10
- package/modules/characters/NPC.js +5 -5
- package/modules/characters/assetModel.js +5 -4
- package/modules/characters/index.js +28 -3
- package/modules/characters/movers/common.js +6 -1
- package/modules/characters/movers/manual.js +3 -0
- package/modules/characters/movers/support.js +25 -11
- package/modules/characters/npcSim.js +5 -1
- package/modules/characters/proceduralRig.js +18 -4
- package/modules/characters/useModel.js +2 -2
- package/modules/collision/Collision.js +4 -2
- package/modules/content/index.js +8 -0
- package/modules/content/models.js +56 -11
- package/modules/content/props.js +5 -3
- package/modules/content/rules.js +12 -4
- package/modules/content/templates.js +5 -3
- package/modules/gameplay/Interactions.js +91 -16
- package/modules/gameplay/Inventory.js +3 -3
- package/modules/gameplay/dialogueBox.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +1 -1
- package/modules/gameplay/interactionPrompt.js +1 -1
- package/modules/gameplay/interactions.contract.js +1 -1
- package/modules/gameplay/inventoryOps.js +2 -2
- package/modules/gameplay/pickups.js +62 -24
- package/modules/gameplay/questLog.js +2 -2
- package/modules/grid/Layer.js +13 -0
- package/modules/grid/index.js +40 -11
- package/modules/grid/preview.js +24 -15
- package/modules/grid/tiles.js +15 -19
- package/modules/hlod/index.js +3 -2
- package/modules/hud/index.js +13 -0
- package/modules/hud/parts.js +9 -7
- package/modules/level/index.js +5 -4
- package/modules/lights/index.js +12 -8
- package/modules/music/Music.js +1 -1
- package/modules/particles/Particles.js +41 -20
- package/modules/particles/effect.js +21 -6
- package/modules/photo/Photo.js +11 -10
- package/modules/settings/Settings.js +7 -7
- package/modules/settings/apply.js +5 -5
- package/modules/settings/sections.js +2 -2
- package/modules/settings/strings.js +1 -1
- package/modules/sky/Sky.js +104 -89
- package/modules/sky/clouds.js +16 -17
- package/modules/sky/dome.js +100 -0
- package/modules/sky/domeLayers.js +5 -5
- package/modules/sky/environment.js +45 -169
- package/modules/sky/fog.js +5 -180
- package/modules/sky/frame.js +26 -90
- package/modules/sky/season.js +3 -3
- package/modules/sky/shader.js +35 -29
- package/modules/sky/skyModule.js +25 -22
- package/modules/sky/tint.js +9 -11
- package/modules/terrain/ChunkManager.js +29 -12
- package/modules/terrain/draw.js +154 -0
- package/modules/terrain/index.js +44 -66
- package/modules/terrain/terrainDefaults.js +2 -2
- package/modules/terrain/terrainEdit.js +1 -1
- package/modules/terrain/terrainGen.js +2 -2
- package/modules/triggers/index.js +10 -6
- package/modules/vegetation/Vegetation.js +58 -17
- package/modules/vegetation/draw.js +191 -0
- package/modules/vegetation/groundChunks.js +1 -1
- package/modules/vegetation/index.js +10 -10
- package/modules/water/Water.js +135 -88
- package/modules/water/surface.js +53 -53
- package/modules/weather/Weather.js +52 -17
- package/modules/weather/particles.js +13 -5
- package/modules/weather/shaders.js +1 -1
- package/modules/weather/weatherDraw.js +141 -0
- package/modules/world/World.js +2 -2
- package/modules/world/views.js +1 -1
- package/package.json +3 -2
- package/presets.js +2 -2
- package/render/PostFX.js +199 -41
- package/render/backend.js +52 -6
- package/render/cascades.js +195 -0
- package/render/cascades.tsl.js +96 -0
- package/render/daylight.js +39 -0
- package/render/detail.js +5 -5
- package/render/effects.js +41 -26
- package/render/fx/cel.tsl.js +42 -0
- package/render/fx/index.js +7 -5
- package/render/fx/patchNodes.tsl.js +1 -1
- package/render/fx/postWebGPU.tsl.js +30 -7
- package/render/fx/sky.tsl.js +19 -92
- package/render/fx/water.tsl.js +1 -1
- package/render/layers.js +14 -0
- package/render/lighting.js +6 -5
- package/render/lightmap.js +142 -0
- package/render/lights.js +23 -201
- package/render/materials.js +44 -160
- package/render/neutral.js +23 -0
- package/render/occlusion.js +184 -0
- package/render/ownFrame.js +1 -1
- package/render/patches.js +34 -29
- package/render/postWebGL.js +11 -3
- package/render/probes.js +179 -122
- package/render/slots.js +4 -4
- package/render/terms.js +53 -101
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +333 -296
- package/types/gameplay.d.ts +65 -26
- package/types/generated/core/Audio.d.ts +1 -1
- package/types/generated/core/DebugOverrides.d.ts +14 -6
- package/types/generated/core/Input.d.ts +9 -2
- package/types/generated/core/page.d.ts +9 -2
- package/types/generated/modules/grid/Layer.d.ts +8 -0
- package/types/generated/modules/grid/index.d.ts +29 -5
- package/types/generated/modules/particles/Particles.d.ts +13 -6
- package/types/generated/modules/sky/Sky.d.ts +85 -18
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/water/Water.d.ts +50 -3
- package/types/generated/modules/weather/Weather.d.ts +33 -3
- package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
- package/types/generated/modules/world/World.d.ts +2 -2
- package/types/generated/render/PostFX.d.ts +53 -10
- package/types/generated/render/lighting.d.ts +29 -0
- package/types/generated/render/materials.d.ts +19 -44
- package/types/generated/render/occlusion.d.ts +13 -0
- package/types/physics.d.ts +5 -3
- package/types/tsl.d.ts +8 -0
- package/types/world.d.ts +376 -57
- package/ui/Focus.js +12 -2
- package/ui/LoadingScreen.js +2 -2
- package/ui/Parts.js +8 -4
- package/ui/UI.js +10 -10
- package/ui/cursor.js +1 -1
- package/ui/theme.js +33 -27
- package/ui/touchPart.js +1 -1
- package/core/look/coreParts.js +0 -219
- package/core/look/part.js +0 -253
- package/core/look/points.js +0 -255
- package/core/look/report.js +0 -96
- package/core/look/shadowPart.js +0 -63
- package/core/look/state.js +0 -45
- package/core/look/write.js +0 -70
- package/core/styleParts.js +0 -114
- package/docs/api/style.md +0 -136
- package/docs/api/terrainLook.md +0 -10
- package/docs/api/vegetationLook.md +0 -10
- package/docs/api/weatherLook.md +0 -10
- package/docs/recipes/09-style.md +0 -218
- package/docs/recipes/35-style-from-reference.md +0 -153
- package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
- package/docs/recipes/38-environment-look-hooks.md +0 -99
- package/docs/recipes/41-thing-registry.md +0 -97
- package/docs/recipes/44-water-weather-look-hooks.md +0 -144
- package/docs/recipes/48-make-material.md +0 -75
- package/docs/recipes/52-look.md +0 -282
- package/examples/action/look.js +0 -5
- package/examples/sheepisland/style/index.js +0 -79
- package/examples/styletest/look.js +0 -11
- package/examples/techniques/day-night-grade/dayNightGrade.js +0 -76
- package/examples/webgpu-tsl/tslScene.js +0 -75
- package/examples/world/style/index.js +0 -61
- package/examples/world/style/plugins/10-bloom.js +0 -5
- package/modules/sky/cascades.js +0 -186
- package/modules/sky/cascades.tsl.js +0 -82
- package/modules/sky/look.js +0 -54
- package/modules/sky/lookFog.js +0 -76
- package/modules/sky/lookShadow.js +0 -62
- package/modules/sky/lookSky.js +0 -169
- package/modules/sky/shadow.js +0 -98
- package/modules/terrain/look.js +0 -83
- package/modules/terrain/lookGround.js +0 -66
- package/modules/vegetation/look.js +0 -119
- package/modules/vegetation/lookWind.js +0 -98
- package/modules/water/look.js +0 -91
- package/modules/water/surfaceDefaults.js +0 -3
- package/modules/weather/look.js +0 -74
- package/modules/weather/weatherLook.js +0 -135
- package/render/lookGlow.js +0 -139
- package/render/lookSurface.js +0 -224
- package/render/postLook.js +0 -164
- package/render/surface.js +0 -105
- package/types/generated/modules/weather/weatherLook.d.ts +0 -12
- package/types/style.d.ts +0 -671
package/examples/world/models.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
// Models this game builds in code: the cabin (registered by name in main.js, placed by content/props.js) and the physics prop meshes (content/bodies.js).
|
|
2
|
-
import { THREE, mergeColored
|
|
2
|
+
import { THREE, mergeColored } from '../../index.js';
|
|
3
|
+
import { mat, pickupMaterial } from './picture/materials.js';
|
|
4
|
+
import items from './content/items.js';
|
|
5
|
+
import { pickup } from './art/shapes.js';
|
|
3
6
|
|
|
4
|
-
/** Low-poly cabin: one merged mesh, plus a 'lamp' mesh and a 'chimney' point that main.js animates by name */
|
|
7
|
+
/** Low-poly cabin: one merged mesh, plus a 'lamp' mesh (picture.doorLamp lights it) and a 'chimney' point that main.js animates by name */
|
|
5
8
|
export function cabin() {
|
|
6
9
|
const g = mergeColored([
|
|
7
10
|
[new THREE.BoxGeometry(6, 3, 5).translate(0, 1.5, 0), 0xe8dcc4],
|
|
@@ -10,9 +13,9 @@ export function cabin() {
|
|
|
10
13
|
[new THREE.BoxGeometry(1, 0.9, 0.1).translate(-1.8, 1.7, 2.52), 0x9cc6d6],
|
|
11
14
|
[new THREE.BoxGeometry(0.6, 1.6, 0.6).translate(1.8, 5, -0.8), 0x7d736a],
|
|
12
15
|
]);
|
|
13
|
-
const house = new THREE.Mesh(g,
|
|
16
|
+
const house = new THREE.Mesh(g, mat.building);
|
|
14
17
|
house.castShadow = true; house.receiveShadow = true;
|
|
15
|
-
const lamp = new THREE.Mesh(new THREE.BoxGeometry(0.3, 0.4, 0.3),
|
|
18
|
+
const lamp = new THREE.Mesh(new THREE.BoxGeometry(0.3, 0.4, 0.3), mat.doorLamp);
|
|
16
19
|
lamp.name = 'lamp'; lamp.position.set(0.9, 2.3, 2.7);
|
|
17
20
|
const chimney = new THREE.Object3D(); chimney.name = 'chimney'; chimney.position.set(1.8, 6, -0.8);
|
|
18
21
|
const root = new THREE.Group(); root.add(house, lamp, chimney);
|
|
@@ -22,7 +25,14 @@ export function cabin() {
|
|
|
22
25
|
const crateGeo = mergeColored([[new THREE.BoxGeometry(0.8, 0.8, 0.8), 0xb08850]]);
|
|
23
26
|
/** Mesh and rigid-body options of a physics prop shape (crate, ball, barrel) */
|
|
24
27
|
export const BODIES = {
|
|
25
|
-
crate: () => [new THREE.Mesh(crateGeo,
|
|
26
|
-
ball: () => [new THREE.Mesh(new THREE.IcosahedronGeometry(0.35, 1),
|
|
27
|
-
barrel: () => [new THREE.Mesh(new THREE.CylinderGeometry(0.4, 0.4, 0.9, 8),
|
|
28
|
+
crate: () => [new THREE.Mesh(crateGeo, mat.crate), 'addBox', { mass: 4 }],
|
|
29
|
+
ball: () => [new THREE.Mesh(new THREE.IcosahedronGeometry(0.35, 1), mat.ball), 'addBall', { radius: 0.35, mass: 1, restitution: 0.55, angularDamping: 0.3 }],
|
|
30
|
+
barrel: () => [new THREE.Mesh(new THREE.CylinderGeometry(0.4, 0.4, 0.9, 8), mat.barrel), 'addHull', { mass: 3 }],
|
|
28
31
|
};
|
|
32
|
+
|
|
33
|
+
/** One ground shape per item, models 'pickup:<item>' (pickups picture for that name first): the shape of art/shapes.js in the item's color */
|
|
34
|
+
export const pickups = Object.fromEntries(Object.entries(items).map(([id, item]) => [`pickup:${id}`, () => {
|
|
35
|
+
const m = new THREE.Mesh(pickup(), pickupMaterial(item.color));
|
|
36
|
+
m.castShadow = true;
|
|
37
|
+
return m;
|
|
38
|
+
}]));
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// The open world's picture: wiring only. Each part writes plain three.js; one onRender drives them from the signals.
|
|
3
|
+
import { EXPOSURE, PARTICLES, TONE_MAPPING, UI } from './palette.js';
|
|
4
|
+
import { createSky } from './sky.js';
|
|
5
|
+
import { createLights } from './lights.js';
|
|
6
|
+
import { createMaterials } from './materials.js';
|
|
7
|
+
import { createPost } from './post.js';
|
|
8
|
+
|
|
9
|
+
/** Call after engine.use(...): it writes into the sky, water and particles modules. @param {any} engine */
|
|
10
|
+
export function createPicture(engine) {
|
|
11
|
+
engine.renderer.toneMapping = TONE_MAPPING;
|
|
12
|
+
engine.renderer.toneMappingExposure = EXPOSURE;
|
|
13
|
+
const sky = createSky(engine), lights = createLights(engine, sky), materials = createMaterials(engine);
|
|
14
|
+
createPost(engine);
|
|
15
|
+
for (const [name, fx] of Object.entries(PARTICLES)) engine.particles.define(name, fx);
|
|
16
|
+
for (const [k, v] of Object.entries(UI)) engine.uiRoot.style.setProperty(`--threedog-${k}`, v);
|
|
17
|
+
// onRender, not onFrame: onFrame runs before the sky module, so it would read last frame's signals and be written over
|
|
18
|
+
engine.onRender(() => { sky.update(engine.uniforms); lights.update(engine.uniforms); });
|
|
19
|
+
return { sun: lights.sun, hemi: lights.hemi, fill: lights.fill, doorLamp: materials.doorLamp };
|
|
20
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Sun or moon and the ambient, from the sky of this moment (sky.js) and the weather. One shadow map that travels with the player: the world streams,
|
|
3
|
+
// so a fixed shadow box would be left behind.
|
|
4
|
+
import { THREE } from '../../../index.js';
|
|
5
|
+
import { FILL, GROUND_BOUNCE, SHADOW, WEATHER_AMBIENT } from './palette.js';
|
|
6
|
+
|
|
7
|
+
const luminance = (/** @type {THREE.Color} */ c) => 0.2126 * c.r + 0.7152 * c.g + 0.0722 * c.b;
|
|
8
|
+
|
|
9
|
+
/** @param {any} engine @param {{ now: { sun: THREE.Color, sunIntensity: number, top: THREE.Color, horizon: THREE.Color, ambient: number } }} sky */
|
|
10
|
+
export function createLights(engine, sky) {
|
|
11
|
+
const { scene } = engine, { now } = sky;
|
|
12
|
+
const hemi = new THREE.HemisphereLight(0xffffff, GROUND_BOUNCE, 1);
|
|
13
|
+
const fill = new THREE.AmbientLight(0xffffff, 0);
|
|
14
|
+
const sun = new THREE.DirectionalLight(0xffffff, 1);
|
|
15
|
+
sun.castShadow = true;
|
|
16
|
+
sun.shadow.mapSize.setScalar(engine.tier === 'low' ? 1024 : 2048);
|
|
17
|
+
Object.assign(sun.shadow.camera, { left: -SHADOW.extent, right: SHADOW.extent, top: SHADOW.extent, bottom: -SHADOW.extent, near: 1, far: SHADOW.far });
|
|
18
|
+
sun.shadow.camera.updateProjectionMatrix(); // three does not redo it for a light's shadow camera: without this line the box stays at its 10 m default
|
|
19
|
+
sun.shadow.bias = SHADOW.bias; sun.shadow.normalBias = SHADOW.normalBias;
|
|
20
|
+
scene.add(hemi, fill, sun, sun.target);
|
|
21
|
+
|
|
22
|
+
const dir = new THREE.Vector3(), snap = (/** @type {number} */ v) => Math.round(v / SHADOW.snap) * SHADOW.snap;
|
|
23
|
+
return {
|
|
24
|
+
sun, hemi, fill,
|
|
25
|
+
/** @param {any} s engine.uniforms */
|
|
26
|
+
update(s) {
|
|
27
|
+
const d = s.uSunDir.value, weather = s.uWeatherLight.value;
|
|
28
|
+
// below the horizon the same light is the moon, across the sky from where the sun went; it fades through 0 at the swap so shadows never jump
|
|
29
|
+
dir.set(d.y < 0 ? -d.x : d.x, Math.abs(d.y), d.z).normalize();
|
|
30
|
+
// snapped: a box that slides by less than a shadow pixel makes every edge in the world shimmer as the player walks
|
|
31
|
+
sun.target.position.set(snap(engine.focus.x), engine.focus.y, snap(engine.focus.z));
|
|
32
|
+
sun.position.copy(sun.target.position).addScaledVector(dir, SHADOW.distance);
|
|
33
|
+
sun.color.copy(now.sun);
|
|
34
|
+
sun.intensity = now.sunIntensity * weather * Math.min(1, Math.abs(d.y) / 0.08);
|
|
35
|
+
// the hemisphere's sky half is the sky itself, halfway between zenith and horizon
|
|
36
|
+
hemi.color.copy(now.top).lerp(now.horizon, 0.5);
|
|
37
|
+
hemi.intensity = now.ambient * (1 - WEATHER_AMBIENT * (1 - weather));
|
|
38
|
+
fill.intensity = hemi.intensity * FILL * luminance(hemi.color);
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Materials by name. They live at module level, not inside createPicture, because the model builders (models.js, art/) are asset generators that `npm run check`
|
|
3
|
+
// imports with no engine. Lambert throughout: this low-poly world is lit by color and shape, nothing here needs a specular model.
|
|
4
|
+
import { THREE, applyEffects } from '../../../index.js';
|
|
5
|
+
import { COLORS, DOOR_LAMP } from './palette.js';
|
|
6
|
+
|
|
7
|
+
const lambert = (/** @type {THREE.MeshLambertMaterialParameters} */ p) => new THREE.MeshLambertMaterial(p);
|
|
8
|
+
const facets = (/** @type {number} */ color) => lambert({ color, flatShading: true });
|
|
9
|
+
|
|
10
|
+
export const mat = {
|
|
11
|
+
building: lambert({ vertexColors: true }),
|
|
12
|
+
crate: lambert({ vertexColors: true }),
|
|
13
|
+
ball: facets(COLORS.ball), barrel: facets(COLORS.barrel),
|
|
14
|
+
doorLamp: lambert({ color: COLORS.lampBody, emissive: COLORS.lampGlow, emissiveIntensity: 0 }),
|
|
15
|
+
cloth: facets(COLORS.cloth), skin: facets(COLORS.skin), trousers: facets(COLORS.trousers), hair: facets(COLORS.hair),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const pickups = new Map();
|
|
19
|
+
/** The ground pickup in one item's color, one material per color: faceted with a faint glow, so a small thing still catches the eye in the grass @param {number} color */
|
|
20
|
+
export function pickupMaterial(color) {
|
|
21
|
+
if (!pickups.has(color)) pickups.set(color, applyEffects(lambert({ color, flatShading: true, emissive: COLORS.pickupGlow })));
|
|
22
|
+
return pickups.get(color);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** @param {any} engine */
|
|
26
|
+
export function createMaterials(engine) {
|
|
27
|
+
// the cloud shadows fall on the cabin, the crates and the people too, not only on the ground and the plants
|
|
28
|
+
for (const m of Object.values(mat)) applyEffects(m, { engine });
|
|
29
|
+
engine.water.material.color.set(COLORS.water);
|
|
30
|
+
return {
|
|
31
|
+
/** The clock in main.js switches the lamp @param {boolean} on */
|
|
32
|
+
doorLamp(on) { mat.doorLamp.emissiveIntensity = on ? DOOR_LAMP : 0; },
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// The open world's palette: every color and key value of the picture, one copy; the other files here read it.
|
|
3
|
+
import { THREE } from '../../../index.js';
|
|
4
|
+
|
|
5
|
+
export const TONE_MAPPING = THREE.ACESFilmicToneMapping;
|
|
6
|
+
export const EXPOSURE = 1.05;
|
|
7
|
+
|
|
8
|
+
/** The day: [time 0-1, zenith, horizon (= fog), sun color (the moon at night), sun intensity, ambient intensity] */
|
|
9
|
+
export const SKY = [
|
|
10
|
+
[0.00, 0x0b1026, 0x1d2747, 0x8fa3d6, 0.45, 0.175], // night: blue moonlight; ambient keeps the land readable
|
|
11
|
+
[0.25, 0x6f8ec4, 0xf0b48c, 0xffb27a, 1.90, 0.40], // sunrise: warm sun and horizon under a still cool zenith
|
|
12
|
+
[0.50, 0x4f95d8, 0xc8e4f6, 0xffffff, 3.00, 0.60],
|
|
13
|
+
[0.75, 0x5a6fb0, 0xf2a07a, 0xff9a5c, 1.90, 0.40],
|
|
14
|
+
[1.00, 0x0b1026, 0x1d2747, 0x8fa3d6, 0.45, 0.175],
|
|
15
|
+
];
|
|
16
|
+
/** What a sky turns into as the weather closes in; `grey` of the weather is how far. Dimmed by the hour, or a rainy night would be a lit grey */
|
|
17
|
+
export const OVERCAST = 0x8c8c8c;
|
|
18
|
+
/** Hemisphere light's lower half: the meadows bouncing back, so undersides stay green and never go black */
|
|
19
|
+
export const GROUND_BOUNCE = 0x4d5a34;
|
|
20
|
+
/** Neutral fill beside the hemisphere light, as a share of its brightness. The hemisphere alone leaves a wall in shade the plain average of sky and meadow,
|
|
21
|
+
* dark and blue; a colorless part keeps shaded faces gray and readable. It rides the same ambient, so nights and rain still darken */
|
|
22
|
+
export const FILL = 1;
|
|
23
|
+
/** How much of the sun the weather takes the ambient loses too: clouds block the sun but scatter its light, so a rainy noon stays a grey day and not a dusk */
|
|
24
|
+
export const WEATHER_AMBIENT = 0.25;
|
|
25
|
+
/** Fog starts at this share of the view distance: the near field stays clear, the far edge hides the end of the streamed world */
|
|
26
|
+
export const FOG_NEAR = 0.3;
|
|
27
|
+
/** Shadow box around the player: wide enough for what the camera sees sharply, one map */
|
|
28
|
+
export const SHADOW = { extent: 70, far: 420, distance: 160, snap: 0.5, bias: -0.00005, normalBias: 0.04 };
|
|
29
|
+
export const BLOOM = { strength: 0.35, radius: 0.5, threshold: 0.85 };
|
|
30
|
+
|
|
31
|
+
/** The dome's clouds and the shadow they drop on the land */
|
|
32
|
+
export const CLOUDS = { color: 0xf8f6f0, shade: 0xb0b8c4, coverage: 1, scale: 0.35, speed: [0.004, 0.002], groundShadow: 0.55 };
|
|
33
|
+
|
|
34
|
+
/** Ground colors, baked into the chunks by the terrain workers; the type names come from terrainPreset() of @threedog/terrain-noise */
|
|
35
|
+
export const TERRAIN = {
|
|
36
|
+
shading: /** @type {'flat'} */ ('flat'),
|
|
37
|
+
colors: { sand: 0xe2cf9c, meadowA: 0x95c45e, meadowB: 0x80b350, forestA: 0x6aa04a, forestB: 0x5a9142, savannaA: 0xc9bd6e, savannaB: 0xb3a85c,
|
|
38
|
+
wetland: 0x6f9a5a, riverbank: 0x8fb06a, highGrass: 0x60954a, rock: 0x8f897d, rockDark: 0x77726a, snow: 0xf1efe8 },
|
|
39
|
+
biomeColors: { beach: ['sand'], snow: ['snow'], rock: ['rock', 'rockDark'], riverbank: ['riverbank', 'meadowA'], wetland: ['wetland', 'meadowB'],
|
|
40
|
+
savanna: ['savannaA', 'savannaB'], forest: ['forestA', 'forestB'], highland: ['highGrass', 'meadowB'], meadow: ['meadowA', 'meadowB'] },
|
|
41
|
+
steep: [{ maxNormalY: 0.62, colors: ['rockDark'] }, { maxNormalY: 0.78, colors: ['rock', 'rockDark'] }],
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** Colors of the things built in code, by material name (materials.js) */
|
|
45
|
+
export const COLORS = { water: 0x4f9cc0, lampBody: 0x6b5a40, lampGlow: 0xffc070, ball: 0xe8c25a, barrel: 0x8a5a36, cloth: 0xd9774a, skin: 0xf1c9a5, trousers: 0x3f4a5c, hair: 0x4a3426,
|
|
46
|
+
pickupGlow: 0x403418 };
|
|
47
|
+
/** How bright the doorway lamp burns when it is on: above 1 so the bloom catches it */
|
|
48
|
+
export const DOOR_LAMP = 1.6;
|
|
49
|
+
|
|
50
|
+
export const PARTICLES = {
|
|
51
|
+
dust: { max: 200, lifetime: [0.5, 1.1], speed: [0.6, 1.8], direction: [0, 1, 0], spread: 1.2, gravity: -1.5, drag: 2, size: [0.25, 0.6], color: [0xd8c8a0, 0xc8b890], opacity: [0.6, 0] },
|
|
52
|
+
smoke: { max: 120, rate: 6, lifetime: [3, 5], speed: [0.4, 0.8], direction: [0.2, 1, 0], spread: 0.25, gravity: 0.15, drag: 0.4, size: [0.6, 2.2], color: [0xc8c4bc, 0xe8e6e2], opacity: [0.55, 0] },
|
|
53
|
+
leaves: { max: 150, lifetime: [3, 6], speed: [0.3, 1], direction: [1, -0.4, 0.3], spread: 1, gravity: -0.6, drag: 1.2, size: [0.18, 0.18], color: [0xd99a4a, 0xb86a30], opacity: [1, 0], spin: 3 },
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** The engine's UI parts read these CSS variables: warm dark panels that sit well over a bright landscape */
|
|
57
|
+
export const UI = { bg: 'rgba(24,22,18,.9)', fg: '#f3eee2', muted: '#a8a294', accent: '#f0b450', line: 'rgba(255,255,255,.15)', radius: '12px' };
|
|
58
|
+
|
|
59
|
+
const rows = SKY.map(([t, top, horizon, sun, sunIntensity, ambient]) => ({ t, top: new THREE.Color(top), horizon: new THREE.Color(horizon), sun: new THREE.Color(sun), sunIntensity, ambient }));
|
|
60
|
+
/** The sky of this moment, as a live object the sky and the lights both read @returns {{ top: THREE.Color, horizon: THREE.Color, sun: THREE.Color, sunIntensity: number, ambient: number }} */
|
|
61
|
+
export const skyNow = () => ({ top: new THREE.Color(), horizon: new THREE.Color(), sun: new THREE.Color(), sunIntensity: 0, ambient: 0 });
|
|
62
|
+
/** Write the day at t into a skyNow() object. Colors blend as colors, never as hex numbers
|
|
63
|
+
* @param {ReturnType<typeof skyNow>} out @param {number} t uTimeOfDay */
|
|
64
|
+
export function sampleSky(out, t) {
|
|
65
|
+
let i = 0;
|
|
66
|
+
while (i < rows.length - 2 && t > rows[i + 1].t) i++;
|
|
67
|
+
const a = rows[i], b = rows[i + 1], k = (t - a.t) / (b.t - a.t);
|
|
68
|
+
out.top.copy(a.top).lerp(b.top, k); out.horizon.copy(a.horizon).lerp(b.horizon, k); out.sun.copy(a.sun).lerp(b.sun, k);
|
|
69
|
+
out.sunIntensity = a.sunIntensity + (b.sunIntensity - a.sunIntensity) * k;
|
|
70
|
+
out.ambient = a.ambient + (b.ambient - a.ambient) * k;
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
/** The brightest ambient of the day: the scale a grey sky dims by */
|
|
74
|
+
export const AMBIENT_PEAK = Math.max(...rows.map(r => r.ambient));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// The glow on the sun, the lamp and bright water. Added but off on low-tier devices: it blurs the whole frame several times, and a slow machine needs that time for the world.
|
|
3
|
+
import { bloom } from '@threedog/post-effects';
|
|
4
|
+
import { BLOOM } from './palette.js';
|
|
5
|
+
|
|
6
|
+
/** @param {any} engine */
|
|
7
|
+
export function createPost(engine) {
|
|
8
|
+
engine.post.add(bloom({ ...BLOOM, enabled: engine.tier !== 'low' }), { name: 'bloom', slot: 'hdr' });
|
|
9
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// The sky and the fog. The engine's dome stays because this world shows its sun, moon, stars and clouds; its colors are this game's, written into the
|
|
3
|
+
// dome's uniforms after the sky module's own pass, so what is drawn is the palette. A gradient sphere of our own would lose all four, and GLSL of our own
|
|
4
|
+
// would stop the ?renderer=webgpu route; the dome's uniforms work on both renderers.
|
|
5
|
+
import { THREE } from '../../../index.js';
|
|
6
|
+
import { AMBIENT_PEAK, CLOUDS, FOG_NEAR, OVERCAST, sampleSky, skyNow } from './palette.js';
|
|
7
|
+
|
|
8
|
+
/** @param {any} engine */
|
|
9
|
+
export function createSky(engine) {
|
|
10
|
+
const { scene, uniforms: E } = engine, U = engine.sky.uniforms, weather = engine.weather;
|
|
11
|
+
const fog = scene.fog = new THREE.Fog(0x000000, 70, 240);
|
|
12
|
+
U.uCloudCover.value = CLOUDS.coverage; U.uCloudScale.value = CLOUDS.scale; U.uCloudSpeed.value.set(...CLOUDS.speed);
|
|
13
|
+
U.uCloudColor.value.set(CLOUDS.color); U.uCloudShade.value.set(CLOUDS.shade);
|
|
14
|
+
E.uCloudShadow.value = CLOUDS.groundShadow;
|
|
15
|
+
|
|
16
|
+
const now = skyNow(), grey = new THREE.Color();
|
|
17
|
+
return {
|
|
18
|
+
now,
|
|
19
|
+
/** @param {any} s engine.uniforms */
|
|
20
|
+
update(s) {
|
|
21
|
+
sampleSky(now, s.uTimeOfDay.value);
|
|
22
|
+
// weather closes the sky toward grey, a grey that dims with the hour; the zenith goes first, the horizon keeps a little of its color
|
|
23
|
+
const amount = weather?.current.grey ?? 0;
|
|
24
|
+
if (amount) {
|
|
25
|
+
grey.set(OVERCAST).multiplyScalar(now.ambient / AMBIENT_PEAK);
|
|
26
|
+
now.top.lerp(grey, amount); now.horizon.lerp(grey, amount * 0.8);
|
|
27
|
+
}
|
|
28
|
+
const flash = weather?.flash ?? 0;
|
|
29
|
+
if (flash) { now.top.addScalar(flash * 0.4); now.horizon.addScalar(flash * 0.3); }
|
|
30
|
+
U.uTop.value.copy(now.top); U.uHorizon.value.copy(now.horizon); U.uSunColor.value.copy(now.sun);
|
|
31
|
+
E.uSkyTop.value.copy(now.top); E.uSkyHorizon.value.copy(now.horizon);
|
|
32
|
+
// the fog is the horizon itself, so the dome needs no band to hide where the ground stops
|
|
33
|
+
U.uFogBand.value = 0;
|
|
34
|
+
fog.color.copy(now.horizon);
|
|
35
|
+
fog.far = s.uViewDistance.value * s.uWeatherFog.value;
|
|
36
|
+
fog.near = fog.far * FOG_NEAR;
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
// File layout:
|
|
8
8
|
// packages/engine/types/common.d.ts shared small types (position, color, easing names)
|
|
9
9
|
// packages/engine/types/core.d.ts Engine class, event map EventMap, input, i18n, saves, assets, audio, module definition
|
|
10
|
-
// packages/engine/types/style.d.ts the Style type
|
|
11
10
|
// packages/engine/types/world.d.ts terrain, vegetation, calendar, sky, weather, water
|
|
12
11
|
// packages/engine/types/physics.d.ts collision, Rapier physics, the four cameras
|
|
13
12
|
// packages/engine/types/gameplay.d.ts timeline, level, trigger zones, particles, settings, music, character/NPC, interactions, dialogue, inventory, quests, photo mode,
|
|
@@ -18,7 +17,7 @@
|
|
|
18
17
|
//
|
|
19
18
|
// When the engine's public API changes (new export, changed parameter), update this file too; `npm run types` checks that every export of index.js is declared.
|
|
20
19
|
|
|
21
|
-
import type { Engine, EngineOptions, ModuleDef, ModuleInput } from './types/core';
|
|
20
|
+
import type { Engine, EngineOptions, ModuleDef, ModuleInput, PictureSlot } from './types/core';
|
|
22
21
|
import type { Ease, EaseName, BufferGeometry, ColorLike, Material, Vector3, PositionLike } from './types/common';
|
|
23
22
|
import type {
|
|
24
23
|
TerrainOptions, TerrainConfig, TerrainGen, Terrain, Vegetation, VegetationModuleOptions, Sky, SkyOptions, Calendar, CalendarOptions, Weather, WeatherOptions, WeatherPreset,
|
|
@@ -36,7 +35,6 @@ import type {
|
|
|
36
35
|
Timeline, TimelineOptions, Character, NPC, UIWindow, WindowOptions,
|
|
37
36
|
Content, Flow, FlowOptions, Hud, HudOptions, ScreenPoint, UIFocus, FocusHandle,
|
|
38
37
|
} from './types/gameplay';
|
|
39
|
-
import type { Style, StyleUI } from './types/style';
|
|
40
38
|
import type { PostEffect } from './types/generated/render/PostFX';
|
|
41
39
|
// Local bindings for the generated module factories (export { x } from re-exports below do not create them), used by OpenWorldOptions
|
|
42
40
|
import type { sky } from './types/generated/modules/sky/skyModule';
|
|
@@ -50,7 +48,6 @@ import type { debug } from './types/generated/modules/debug/DebugPanel';
|
|
|
50
48
|
// Types are exported too, so game code can write JSDoc: /** @type {import('threedog').DialogueScript} */
|
|
51
49
|
export * from './types/common';
|
|
52
50
|
export * from './types/core';
|
|
53
|
-
export * from './types/style';
|
|
54
51
|
export * from './types/world';
|
|
55
52
|
export * from './types/physics';
|
|
56
53
|
export * from './types/gameplay';
|
|
@@ -63,8 +60,10 @@ export * from './types/nav';
|
|
|
63
60
|
/** three.js itself (the same instance the engine uses; typed by @types/three) */
|
|
64
61
|
export * as THREE from 'three';
|
|
65
62
|
|
|
66
|
-
/** Create an engine (core only). canvas is required; style is the game's style (see recipes/09-
|
|
63
|
+
/** Create an engine (core only). canvas is required; style is the game's style (see recipes/09-materials-lights-models.md) */
|
|
67
64
|
export function createEngine(opts: EngineOptions): Engine;
|
|
65
|
+
/** The picture slots: what each one is and which describe('picture').picture.writers names it covers (a name ending in '.' covers everything under it) */
|
|
66
|
+
export const PICTURE_SLOTS: Readonly<Record<PictureSlot, { readonly what: string; readonly values: readonly string[] }>>;
|
|
68
67
|
|
|
69
68
|
/** One openWorld part: false leaves the module out, true / omitted uses defaults, an object is that module's own options */
|
|
70
69
|
type Part<F extends (...a: any) => any> = boolean | NonNullable<Parameters<F>[0]>;
|
|
@@ -249,15 +248,6 @@ export const threePatches: {
|
|
|
249
248
|
list(): { id: string, what: string, scope: string, on: boolean, offable: boolean, lost: string }[];
|
|
250
249
|
off(id: string): void;
|
|
251
250
|
};
|
|
252
|
-
/**
|
|
253
|
-
* Register a module's own look part: engine.look.<id> with set / patch / add / replace / manual / value (module code: part.author),
|
|
254
|
-
* engine.catalog('look.<id>') and describe().look (recipes/52-look.md).
|
|
255
|
-
* Every param needs a default; a default that changes the picture also needs why and off (or neutral: true).
|
|
256
|
-
*/
|
|
257
|
-
export function defineLookPart(engine: any, spec: { id: string, group?: string, module?: string, object?: () => any, params?: Record<string, any>,
|
|
258
|
-
style?: () => object, read?: () => object, apply?: (values: any, changed: Set<string>) => void, applyAtStart?: boolean,
|
|
259
|
-
hooks?: Record<string, { signature?: string, scope?: string[], example?: string }>, applyHook?: (name: string, glsl: any) => void, noPatch?: string,
|
|
260
|
-
replace?: { accepts: string, loses?: string[] }, applyReplace?: (impl: any) => void, noReplace?: string, noAdd?: string, docs?: string[] }): import('./types/core').LookPart;
|
|
261
251
|
// The Character, NPC and Engine classes are exported by the export * above (tweens use engine.timeline.tween, pathfinding uses engine.characters.findPath)
|
|
262
252
|
|
|
263
253
|
/** Pure terrain computation (no engine needed), for previewing heights before start: createTerrain({ seed, ...terrainPreset() }).surface(x, z) */
|
|
@@ -265,7 +255,8 @@ export function createTerrain(cfg?: Partial<TerrainConfig>): TerrainGen;
|
|
|
265
255
|
|
|
266
256
|
// ---------- Materials ----------
|
|
267
257
|
// Migrated: declarations are generated from the JSDoc in packages/engine/render/materials.js (npm run map), not written by hand here
|
|
268
|
-
export { terrainMaterial, mergeColored, applyEffects
|
|
258
|
+
export { terrainMaterial, mergeColored, applyEffects } from './types/generated/render/materials';
|
|
259
|
+
export { rampTexture } from './types/generated/render/lighting';
|
|
269
260
|
export { bakeVertexAO } from './types/generated/render/modeling';
|
|
270
261
|
export { materialPatches } from './types/generated/render/patches';
|
|
271
262
|
|
|
@@ -274,7 +265,7 @@ export { materialPatches } from './types/generated/render/patches';
|
|
|
274
265
|
export { toast, makeWindow, worldToScreen, fadeScreen, uiFocus, toggleOnKey } from './types/generated/ui/UI';
|
|
275
266
|
// Type PostFX (class in render/PostFX.js): used by engine.post in Engine, and exported publicly
|
|
276
267
|
export type { PostFX, PostEffect } from './types/generated/render/PostFX';
|
|
277
|
-
export type { UIPart, UIPartFactory, UIPartValue, UIPartDef, UIParts, UITitleItem } from './types/core';
|
|
268
|
+
export type { UIPart, UIPartFactory, UIPartValue, UIPartDef, UIParts, UITitleItem, UIOptions, UITheme, UITemplate } from './types/core';
|
|
278
269
|
|
|
279
270
|
// ---------- Clock ----------
|
|
280
271
|
/** Clock time -> fraction of the day: parseClock('18:30') = 0.77; a number or numeric string ('0.25') is converted as is. hoursPerDay is hours per day, default 24 */
|
package/index.js
CHANGED
|
@@ -5,10 +5,9 @@
|
|
|
5
5
|
//
|
|
6
6
|
// import { createEngine, terrain, vegetation, sky, weather, water, collision, rigid,
|
|
7
7
|
// followCamera, characters, interactions, dialogue, inventory, quests, photo, ambience, debug } from 'threedog';
|
|
8
|
-
// import
|
|
9
|
-
// import { terrainPreset } from '@threedog/terrain-noise'; // optional: nor a terrain generator
|
|
8
|
+
// import { terrainPreset } from '@threedog/terrain-noise'; // optional: the engine ships no terrain generator either
|
|
10
9
|
//
|
|
11
|
-
// const engine = createEngine({ canvas
|
|
10
|
+
// const engine = createEngine({ canvas }); // lights, fog and materials are plain three.js the game writes (its picture/ folder); the engine gives signals
|
|
12
11
|
// engine.use(terrain({ seed: 7, ...terrainPreset() }), vegetation(), sky(), weather(), water(), collision(), followCamera(), characters());
|
|
13
12
|
// engine.start();
|
|
14
13
|
//
|
|
@@ -63,18 +62,19 @@ export { EASINGS, ease } from './core/easing.js';
|
|
|
63
62
|
export { sampleGrid } from './core/grid.js'; // a grid of numbers (height, moisture, density, walkable) as a function (x, z) -> value; assets.gridFromImage reads one from an image. 'threedog/grid' is the same file without three.js (workers, tests)
|
|
64
63
|
export { checkOptions }; // only for extensible data (game-defined fields); an options bag goes through readParams
|
|
65
64
|
export { contentParts } from './modules/content/parts.js'; // one content kind split over files: content/props/*.js joined in file-name order (recipes/30)
|
|
66
|
-
export { defineLookPart } from './core/look/part.js'; // a module's own look part: engine.look.<id> with set / patch / replace, catalog and describe (recipes/52)
|
|
67
65
|
export { threePatches } from './core/threePatches.js'; // the engine's page-wide changes to three.js classes: list(), off(id) (THREE.md "Global changes")
|
|
68
66
|
export { readParams } from './core/params.js'; // params schema for game-made modules: validated, defaults filled, shown by engine.catalog() // for game-made modules (recipes/14): the package exposes no core/* deep paths
|
|
69
67
|
export { createTerrain } from './modules/terrain/index.js';
|
|
70
68
|
export { Character, NPC } from './modules/characters/index.js';
|
|
71
69
|
export { presets } from './presets.js'; // opt-in gameplay presets (weather tables, calendars, player feel, camera): never applied by the engine itself
|
|
72
|
-
export { terrainMaterial, mergeColored, applyEffects
|
|
70
|
+
export { terrainMaterial, mergeColored, applyEffects } from './render/materials.js';
|
|
71
|
+
export { rampTexture } from './render/lighting.js'; // a toon material's gradientMap from grays or colors (recipes/09)
|
|
73
72
|
export { bakeVertexAO } from './render/modeling.js'; // procedural-modeling gaps three.js lacks (recipe 54 lists what three already has)
|
|
74
73
|
export { materialPatches } from './render/patches.js';
|
|
75
74
|
export { toast, makeWindow, worldToScreen, fadeScreen, uiFocus, toggleOnKey } from './ui/UI.js';
|
|
76
75
|
export { parseClock, formatClock, inRange } from './core/dayTime.js';
|
|
77
76
|
export { pickTarget, switchTarget } from './core/targeting.js';
|
|
77
|
+
export { PICTURE_SLOTS } from './core/pictureSlots.js';
|
|
78
78
|
|
|
79
79
|
/** Create an engine (core only). For the options see core/Engine.js */
|
|
80
80
|
export function createEngine(opts) { return new Engine(opts); }
|
|
@@ -86,7 +86,7 @@ export function createEngine(opts) { return new Engine(opts); }
|
|
|
86
86
|
* engine.use(openWorld({ seed: 7, camera: 'follow' }), interactions({ ...presets.interactions.nearest }), dialogue(), inventory(), quests()); // keys: createEngine({ bindings: { ...presets.bindings.interact, ...presets.bindings.inventory } })
|
|
87
87
|
* Every part takes false (leave it out) or an object (that module's own options), so the preset never has to be abandoned for one setting:
|
|
88
88
|
* openWorld({ seed: 7, camera: 'follow', calendar: { seasons: ['wet', 'dry'], daysPerSeason: 28 }, characters: { npcs: false }, rigid: false, ambience: false })
|
|
89
|
-
* The bundle hides the terrain's far edge in fog (terrain viewFog: true; openWorld({ terrain: { viewFog: false } })
|
|
89
|
+
* The bundle hides the terrain's far edge in fog (terrain viewFog: true; openWorld({ terrain: { viewFog: false } }) leaves uViewDistance alone).
|
|
90
90
|
* Shorthands still work and go to their module: seed / viewChunks / density / flatten → terrain, time / dayLength → calendar,
|
|
91
91
|
* weather: 'rain' (starting weather) and autoWeather → weather. An object for the same module wins over the shorthand.
|
|
92
92
|
* debug: installed only in dev builds by default (players of a release build get no F3 panel); true installs it in release builds too.
|
|
@@ -123,5 +123,5 @@ export function openWorld(opts = {}) {
|
|
|
123
123
|
};
|
|
124
124
|
const cam = camera === false ? null : typeof camera === 'string' ? CAMERAS[camera]() : camera;
|
|
125
125
|
return [part('world'), part('terrain'), part('vegetation'), part('calendar'), part('sky'), part('weather'), part('water'), part('collision'), part('rigid'),
|
|
126
|
-
cam, part('characters'), part('ambience'), part('settings'), part('debug')].filter(Boolean).flat(); // flat: terrain(), vegetation() and weather() are two modules each (data +
|
|
126
|
+
cam, part('characters'), part('ambience'), part('settings'), part('debug')].filter(Boolean).flat(); // flat: terrain(), vegetation() and weather() are two modules each (data + drawing)
|
|
127
127
|
}
|
package/llms.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# threedog
|
|
2
2
|
|
|
3
|
-
> A web 3D game engine on three.js 0.187 (plain three.js, no React): core and modules installed with engine.use. It ships no art: each game draws its own
|
|
3
|
+
> A web 3D game engine on three.js 0.187 (plain three.js, no React): core and modules installed with engine.use. It ships no art: each game draws its own picture (plain three.js in its picture/ folder, and assets).
|
|
4
4
|
|
|
5
5
|
Reading order: docs/AI.md (the index: one line per task) -> the recipe for the task -> docs/api/<module>.md for details -> the game's GAMEMAP.md.
|
|
6
6
|
|
|
@@ -19,7 +19,7 @@ Reading order: docs/AI.md (the index: one line per task) -> the recipe for the t
|
|
|
19
19
|
- [06-clock-events](docs/recipes/06-clock-events.md): Scheduling events on the game clock
|
|
20
20
|
- [07-flow-scenes-pause](docs/recipes/07-flow-scenes-pause.md): Scene transitions and pause (flow)
|
|
21
21
|
- [08-weather-sky](docs/recipes/08-weather-sky.md): Add weather or change the sky
|
|
22
|
-
- [09-
|
|
22
|
+
- [09-materials-lights-models](docs/recipes/09-materials-lights-models.md): Materials, lights and models: the game's own picture
|
|
23
23
|
- [10-blender-level](docs/recipes/10-blender-level.md): Importing Blender models and levels
|
|
24
24
|
- [11-vehicles](docs/recipes/11-vehicles.md): Physics: rigid bodies, pushing, joints, vehicles
|
|
25
25
|
- [12-navmesh](docs/recipes/12-navmesh.md): Navigation mesh (nav)
|
|
@@ -42,23 +42,21 @@ Reading order: docs/AI.md (the index: one line per task) -> the recipe for the t
|
|
|
42
42
|
- [32-action-game](docs/recipes/32-action-game.md): Action game wiring: hp, attacks, enemy AI, drops and death without engine combat rules
|
|
43
43
|
- [33-stream-sources](docs/recipes/33-stream-sources.md): Stream sources: what is loaded where (teleport, far camera)
|
|
44
44
|
- [34-environment-lighting](docs/recipes/34-environment-lighting.md): Environment lighting
|
|
45
|
-
- [35-
|
|
46
|
-
- [36-sky-ground-
|
|
47
|
-
- [37-terrain-
|
|
48
|
-
- [38-environment-
|
|
49
|
-
- [40-scene](docs/recipes/40-scene.md): Scene: what is in the world, where, and what a save keeps
|
|
50
|
-
- [41-thing-registry](docs/recipes/41-thing-registry.md): Things: what is in the scene, who manages it, what a save keeps (engine.thing)
|
|
45
|
+
- [35-picture-from-reference](docs/recipes/35-picture-from-reference.md): Making a new picture from a reference picture
|
|
46
|
+
- [36-sky-ground-plants](docs/recipes/36-sky-ground-plants.md): Sky, ground and plants
|
|
47
|
+
- [37-terrain-hooks](docs/recipes/37-terrain-hooks.md): Crisp ground color borders, terrain normals, height from a grid
|
|
48
|
+
- [38-environment-hooks](docs/recipes/38-environment-hooks.md): Lights, fog and exposure
|
|
49
|
+
- [40-scene](docs/recipes/40-scene.md): Scene: what is in the world, where, who manages it, and what a save keeps (engine.thing)
|
|
51
50
|
- [42-terrain-shape](docs/recipes/42-terrain-shape.md): Terrain outline: islands, floating rocks, a world that ends
|
|
52
|
-
- [43-shader-patches-
|
|
53
|
-
- [44-water-weather-
|
|
54
|
-
- [45-cascaded-shadows](docs/recipes/45-cascaded-shadows.md):
|
|
51
|
+
- [43-shader-patches-surfaces](docs/recipes/43-shader-patches-surfaces.md): Writing shader patches and surfaces
|
|
52
|
+
- [44-water-weather-hooks](docs/recipes/44-water-weather-hooks.md): Water and rain/snow: depth color, foam, reflections, particles, lightning
|
|
53
|
+
- [45-cascaded-shadows](docs/recipes/45-cascaded-shadows.md): Shadows: cascades, box, budget, the switch
|
|
55
54
|
- [46-blender-art-route](docs/recipes/46-blender-art-route.md): Blender to game (GLB) route
|
|
56
55
|
- [47-island-snow-backdrop](docs/recipes/47-island-snow-backdrop.md): Snow cover, flat backdrop, rounded terrain rim
|
|
57
|
-
- [48-make-material](docs/recipes/48-make-material.md): 48. `engine.makeMaterial(role, spec)`: which keys work, who wins
|
|
58
56
|
- [49-game-module-contract](docs/recipes/49-game-module-contract.md): Writing a game system module (a smelter, a recharging turret, growing crops) that plugs into the engine's contracts
|
|
59
57
|
- [50-own-renderer](docs/recipes/50-own-renderer.md): Bring your own renderer: `createEngine({ renderer })`
|
|
60
58
|
- [51-capability-catalog](docs/recipes/51-capability-catalog.md): Capability catalog: ask what the game can do before reading docs
|
|
61
|
-
- [52-
|
|
59
|
+
- [52-around-the-picture](docs/recipes/52-around-the-picture.md): 52 Around the picture: reading it back, the post chain, who writes what
|
|
62
60
|
- [53-ground-up-close](docs/recipes/53-ground-up-close.md): The ground up close: options and diagnosis
|
|
63
61
|
- [54-three-idioms](docs/recipes/54-three-idioms.md): Plain three.js in this engine
|
|
64
62
|
- [55-mods-time-wrap](docs/recipes/55-mods-time-wrap.md): Shared values, exclusive slots, time channels and wrapping module methods
|
|
@@ -67,3 +65,7 @@ Reading order: docs/AI.md (the index: one line per task) -> the recipe for the t
|
|
|
67
65
|
- [58-input](docs/recipes/58-input.md): Input: modules declare actions, the game binds keys
|
|
68
66
|
- [59-depth-post-effects](docs/recipes/59-depth-post-effects.md): A post effect that reads depth (volumetric fog, god rays)
|
|
69
67
|
- [60-judge-the-picture](docs/recipes/60-judge-the-picture.md): 60 Make the picture look good: what each knob does and how to judge it
|
|
68
|
+
- [61-deploy](docs/recipes/61-deploy.md): Deploy: put the built game on a web server, at the site root or under a sub-path
|
|
69
|
+
- [62-picture-code](docs/recipes/62-picture-code.md): The whole picture in plain three.js: signals in, picture out
|
|
70
|
+
- [63-third-person-start](docs/recipes/63-third-person-start.md): Third-person start: walking, camera, save, pause, menu
|
|
71
|
+
- [64-particles](docs/recipes/64-particles.md): Particles: dust, smoke, sparks, splashes
|
|
@@ -177,7 +177,7 @@ const AMBIENCE_PARAMS = keysSchema(['rules', 'interval']);
|
|
|
177
177
|
export function ambience(opts = {}) {
|
|
178
178
|
readParams('ambience', AMBIENCE_PARAMS, opts);
|
|
179
179
|
let a = null;
|
|
180
|
-
return { name: 'ambience', type: '
|
|
180
|
+
return { name: 'ambience', type: 'picture', params: AMBIENCE_PARAMS, options: opts, label: 'Ambience', stage: 'late',
|
|
181
181
|
install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.ambience': '环境音' }, en: { 'module.ambience': 'ambience' } });
|
|
182
182
|
builtInSounds(e.assets, SYNTHS, { bus: 'ambience' }); // sound assets wind / rain / water / birds / crickets, silent until audio.sounds names them
|
|
183
183
|
a = new Ambience(e, opts);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Calendar: the game's time of day, day number, seasons and clock-time timers (engine.calendar). Gameplay time, not a
|
|
1
|
+
// Calendar: the game's time of day, day number, seasons and clock-time timers (engine.calendar). Gameplay time, not a picture: NPC schedules,
|
|
2
2
|
// shop hours, content `clock` conditions, audio rules { time } / { daylight } and engine.skip({ to }) read it, with or without a sky.
|
|
3
3
|
// Why its own module and not part of sky: an indoor game, a management sim with a custom backdrop or a game with its own sky dome has days and
|
|
4
4
|
// opening hours but no engine sky; when the calendar lived in sky, NPC schedules stalled without one. The sky only reads it to draw (sun, moon,
|
|
@@ -34,6 +34,7 @@ export function calendar(opts = {}) {
|
|
|
34
34
|
// from the clock, so an indoor game without a sky still switches its night music
|
|
35
35
|
ctx.track(e.audio.condition('time', timeCondition(c)));
|
|
36
36
|
ctx.track(e.audio.measure('daylight', () => c.daylight));
|
|
37
|
+
ctx.track(e.audio.measure('timeOfDay', () => c.timeOfDay)); // render/daylight.js writes uTimeOfDay from it
|
|
37
38
|
// between() ranges re-check whether they are inside after anything that moves the clock without stepping
|
|
38
39
|
for (const name of ['engine:ready', 'save:loaded', 'state:applied']) ctx.track(e.events.on(name, () => c._sched.syncRanges()));
|
|
39
40
|
// the day and time of day are views of the 'calendar' channel: its events and clock timers run right after the channel moves (a step or a skip segment)
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import * as THREE from 'three';
|
|
13
13
|
import { rigModule, defineRig, YAW_RIG, HIDE_RIG, clickToLock, releaseLock } from './common.js';
|
|
14
14
|
import { vec3 } from '../../core/math.js';
|
|
15
|
-
import { setFov } from '../../core/
|
|
15
|
+
import { setFov } from '../../core/view.js';
|
|
16
16
|
|
|
17
17
|
export class FirstPersonCamera {
|
|
18
18
|
/**
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
import * as THREE from 'three';
|
|
18
18
|
import { rigModule, defineRig, viewForward, rightOf, rigPlaced } from './common.js';
|
|
19
19
|
import { setProjection } from './projection.js';
|
|
20
|
-
import { setFov } from '../../core/
|
|
20
|
+
import { setFov } from '../../core/view.js';
|
|
21
21
|
import { vec3 } from '../../core/math.js';
|
|
22
22
|
import { ease as easing } from '../../core/easing.js';
|
|
23
23
|
import { warnMissing } from '../../core/validate.js';
|
|
@@ -158,7 +158,7 @@ export class FixedCamera {
|
|
|
158
158
|
const cam = this.engine.camera;
|
|
159
159
|
cam.position.copy(pos); cam.lookAt(look);
|
|
160
160
|
setProjection(cam, size ? 'orthographic' : 'perspective', size);
|
|
161
|
-
if (Math.abs(cam.fov - fov) > 1e-3) setFov(this.engine, fov); // yields to a fov the game set itself (
|
|
161
|
+
if (Math.abs(cam.fov - fov) > 1e-3) setFov(this.engine, fov); // yields to a fov the game set itself (engine.view 'fov')
|
|
162
162
|
rigPlaced(this.engine); // a cut between frames is the engine's own write (common.js)
|
|
163
163
|
}
|
|
164
164
|
_latchDirection() {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import * as THREE from 'three';
|
|
14
14
|
import { rigModule, defineRig, CAMERA_STRINGS, YAW_RIG, rigPlaced } from './common.js';
|
|
15
15
|
import { xzOf } from '../../core/math.js';
|
|
16
|
-
import { setFov } from '../../core/
|
|
16
|
+
import { setFov } from '../../core/view.js';
|
|
17
17
|
import { surfaceOr } from '../../core/ground.js';
|
|
18
18
|
|
|
19
19
|
export class RtsCamera {
|
package/modules/camera/common.js
CHANGED
|
@@ -17,12 +17,12 @@ import * as THREE from 'three';
|
|
|
17
17
|
import { defineOwned } from '../../core/owned.js';
|
|
18
18
|
import { readParams, keysSchema } from '../../core/params.js';
|
|
19
19
|
import { setProjection } from './projection.js';
|
|
20
|
-
import { setFov } from '../../core/
|
|
20
|
+
import { setFov } from '../../core/view.js';
|
|
21
21
|
import { codedError } from '../../core/errorHints.js';
|
|
22
22
|
|
|
23
23
|
// the takeover calls the owned-camera warning quotes (core/owned.js): takeCamera is the one explicit entry (its remove() gives the camera back);
|
|
24
24
|
// back is the hand-back for a camera the engine yielded to a direct write (that takeover has no handle)
|
|
25
|
-
const LEVELS = { manual: "const cam = engine.takeCamera('me') (cam.remove() gives it back)", back: "engine.
|
|
25
|
+
const LEVELS = { manual: "const cam = engine.takeCamera('me') (cam.remove() gives it back)", back: "engine.view.manual('camera', false)" };
|
|
26
26
|
|
|
27
27
|
/** True during a cutscene takeover, and updates engine.focus from the focus the owner supplied */
|
|
28
28
|
function applyOverride(e) {
|
|
@@ -110,7 +110,7 @@ function lockView(e, st) {
|
|
|
110
110
|
/** Release the mouse lock; stop listening for clicks too when switched away (call from onExit; from onOverride with keepListening) */
|
|
111
111
|
export function releaseLock(rig, keepListening = false) {
|
|
112
112
|
if (!keepListening) { rig._off?.abort(); if (rig.engine.input.swallowLockClick === rig._swallow) rig.engine.input.swallowLockClick = null; }
|
|
113
|
-
if (document.pointerLockElement === rig.engine.renderer.domElement)
|
|
113
|
+
if (document.pointerLockElement === rig.engine.renderer.domElement) rig.engine.page.releaseLock();
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
/** The camera's own view direction on the XZ plane */
|
|
@@ -178,7 +178,7 @@ export function rigModule(kind, opts) {
|
|
|
178
178
|
return c;
|
|
179
179
|
}
|
|
180
180
|
return {
|
|
181
|
-
name: 'cameraRig', type: '
|
|
181
|
+
name: 'cameraRig', type: 'picture', label: 'Camera', params: RIG_PARAMS.get(kind), options: opts, optional: ['collision'], stage: 'control',
|
|
182
182
|
install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.cameraRig': '相机' }, en: { 'module.cameraRig': 'camera' } });
|
|
183
183
|
engine = e; fov0 = e.camera.fov; modInput = ctx.input; declared.clear();
|
|
184
184
|
e.setCamera = setCamera;
|
|
@@ -194,9 +194,11 @@ export function rigModule(kind, opts) {
|
|
|
194
194
|
c.onEnter?.(false); c.follow(e.player?.cameraFollow ? e.player.root : null); fresh = true; // follows the player only if the game asked (createPlayer({ cameraFollow }))
|
|
195
195
|
e.events.emit('camera:change', { kind, previous: old.kind }); // settings re-apply the player's sensitivity / fov to the new rig
|
|
196
196
|
}));
|
|
197
|
+
// a scenario put the player somewhere else (?at, ?pos): a rig that eases would open on a glide across the map; follow() puts it there at once
|
|
198
|
+
ctx.track(e.events.on('state:placed', () => { if (c.target) { c.follow(c.target); fresh = true; } }));
|
|
197
199
|
// The camera module places position / orientation every frame: a game that moves the camera directly takes it (the rig stops), warned once
|
|
198
200
|
const cam = e.camera, p = cam.position, q = cam.quaternion;
|
|
199
|
-
// One camera state: takeCamera's 'camera' stack.
|
|
201
|
+
// One camera state: takeCamera's 'camera' stack. engine.view.manual('camera') and a direct write become a takeCamera hold too (owner
|
|
200
202
|
// 'manual:<who>' / 'three'), so cameraOverride, describe().holds and the rig's onOverride see every takeover the same way; handing back
|
|
201
203
|
// (manual('camera', false)) removes that hold. Why: four entries with four states meant a pointer lock or focus that only one of them reset.
|
|
202
204
|
let hold = null;
|