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/core/lifecycle.js
CHANGED
|
@@ -16,7 +16,6 @@ import { coded, codedError } from './errorHints.js';
|
|
|
16
16
|
import { dropOwned } from './owned.js';
|
|
17
17
|
import { reportError } from './errors.js';
|
|
18
18
|
import { releaseContext, memory } from '../render/backend.js';
|
|
19
|
-
import { dropPlainTerms } from '../render/terms.js';
|
|
20
19
|
|
|
21
20
|
/** The per-step / per-frame callback lists (onFixed, onFrame, onRender, module hooks), empty: the constructor's starting state and what dispose leaves */
|
|
22
21
|
export function clearHooks(e) {
|
|
@@ -67,17 +66,16 @@ export const lifecycleMethods = {
|
|
|
67
66
|
this._wraps?.dispose(); // engine.wrap: every wrapped method back on its object (a game object or api may outlive the engine)
|
|
68
67
|
this.debug.dispose(); // before the scene is disposed: undoes every diagnostic override and view (puts swapped materials back)
|
|
69
68
|
for (const part of [this.saves, this.audio, this.time, this.commits, this.jobs, this.threads, this.stream, this.batching, this.rays, this.events]) part.dispose();
|
|
70
|
-
this._roomEnv?.dispose(); this._roomEnv = null;
|
|
71
69
|
clearHooks(this); this._afterTick = null;
|
|
72
70
|
this.scene.traverse(disposeObject);
|
|
73
71
|
// scene.environment is never disposed here: the engine's own maps (sky PMREM targets, the baseline room map) were freed above by their
|
|
74
|
-
// owners, and anything else is the game's texture (
|
|
72
|
+
// owners, and anything else is the game's texture (a direct scene.environment write), which stays the game's to free
|
|
75
73
|
this.scene.environment = null;
|
|
76
74
|
if (this.scene.background?.isTexture) this.scene.background.dispose();
|
|
77
75
|
this.assets.dispose();
|
|
76
|
+
this.occlusion.dispose();
|
|
78
77
|
this.post.dispose();
|
|
79
78
|
this._webglOnlyView?.remove(); this._webglOnlyView = null;
|
|
80
|
-
dropPlainTerms(this);
|
|
81
79
|
this._gpu?.dispose();
|
|
82
80
|
this.renderer.dispose();
|
|
83
81
|
if (this._ownsRenderer && !opts.keepContext) { releaseContext(this.renderer); released.add(this.renderer.domElement); }
|
package/core/lightWatch.js
CHANGED
|
@@ -15,7 +15,7 @@ const STRINGS = {
|
|
|
15
15
|
changed: 'Shader programs were compiled during play ({from} -> {to}) and, compared with the last observation, the light layout also changed ({was} -> {now}). ' +
|
|
16
16
|
'three.js compiles every material again for a new light setup, so adding, removing or hiding a light mid-game freezes a frame. ' +
|
|
17
17
|
'Use engine.use(lightPool({ point: 8 })) and engine.lightPool.add(torch, {...}) for many lights, or fade a fixed set with intensity ' +
|
|
18
|
-
'(recipes/09-
|
|
18
|
+
'(recipes/09-materials-lights-models.md "Lights and stalls")',
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
/** Visible lights by the kinds three.js counts in its light setup (ambient and probes do not change programs), as one comparable string */
|
|
@@ -33,7 +33,7 @@ export function lightSetup(scene) {
|
|
|
33
33
|
* each with userData.fixedCount = true; core reads the mark, not a module's naming scheme, so any pool, built-in or the game's, counts the same */
|
|
34
34
|
function countLoose(scene) {
|
|
35
35
|
let c = 0;
|
|
36
|
-
scene.traverseVisible(o => { if (o.isLight && !o.isAmbientLight && !o.isLightProbe && !o.userData.fixedCount) c++; });
|
|
36
|
+
scene.traverseVisible(o => { if (o.isLight && !o.isAmbientLight && !o.isLightProbe && !o.isLightProbeGrid && !o.userData.fixedCount) c++; });
|
|
37
37
|
return c;
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -42,7 +42,8 @@ export function watchLights(e) {
|
|
|
42
42
|
const n = programCount(e.renderer);
|
|
43
43
|
if (n == null) return;
|
|
44
44
|
const first = !e._lightWatch;
|
|
45
|
-
|
|
45
|
+
// changes and setup: the picture check reads them (packages/tools/picture/check.mjs 'light-layout')
|
|
46
|
+
const w = e._lightWatch ??= { n, lights: lightSetup(e.scene), changes: [], setup: () => lightSetup(e.scene) };
|
|
46
47
|
// the scene walk runs on the first observation and when programs grow (a light was added), never on a quiet frame
|
|
47
48
|
if (!w.manyDone && (first || n > w.n)) {
|
|
48
49
|
const c = countLoose(e.scene);
|
|
@@ -51,6 +52,7 @@ export function watchLights(e) {
|
|
|
51
52
|
if (n <= w.n) { w.n = n; return; } // fewer programs (materials disposed) or none new: nothing to say
|
|
52
53
|
const lights = lightSetup(e.scene);
|
|
53
54
|
if (lights !== w.lights) {
|
|
55
|
+
w.changes.push({ from: w.lights, to: lights, programs: n - w.n });
|
|
54
56
|
// the layout is only reread when programs grow, so we say "since the last observation", never "in this frame"
|
|
55
57
|
warnOnce(coded('light-recompile', STRINGS.changed.replace('{from}', String(w.n)).replace('{to}', String(n)).replace('{was}', w.lights).replace('{now}', lights)));
|
|
56
58
|
}
|
package/core/loop.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// adaptive resolution.
|
|
3
3
|
//
|
|
4
4
|
// Hook errors: onFixed / onFrame callbacks and module fixed / frame / afterRender hooks each run in try/catch and are handled by error tier (errors.js):
|
|
5
|
-
//
|
|
5
|
+
// picture / ui modules are disabled, errors elsewhere freeze gameplay in dev / tests and are recorded in engine.error, core steps such as render
|
|
6
6
|
// report only once; input.endFrame() sits in finally so "just pressed" always clears.
|
|
7
7
|
//
|
|
8
8
|
// What freezing (engine.freeze) stops: the whole fixed step is skipped (onFixed, module fixed, tick and every time view but ambient stop);
|
|
@@ -16,13 +16,13 @@ import { reportError } from './errors.js';
|
|
|
16
16
|
import { DEV, warnOnce } from './validate.js';
|
|
17
17
|
import { codedError } from './errorHints.js';
|
|
18
18
|
import { watchLights } from './lightWatch.js';
|
|
19
|
-
import { followFocus
|
|
19
|
+
import { followFocus } from '../render/lights.js';
|
|
20
20
|
import { STEP } from './time.js'; // fixed step length: 60 per second
|
|
21
21
|
import { adapt } from './adaptive.js';
|
|
22
22
|
import { advanceUiClock } from './uiClock.js';
|
|
23
23
|
import { resetStats, programCount, freshFrame } from '../render/backend.js';
|
|
24
24
|
import { engineDraws } from '../render/ownFrame.js';
|
|
25
|
-
import {
|
|
25
|
+
import { writeDaylight } from '../render/daylight.js';
|
|
26
26
|
// Most real time one frame may turn into fixed steps (6 steps). A longer hitch slows the game for that frame
|
|
27
27
|
// instead of replaying it in a burst (no spiral of death, no jump after a stall).
|
|
28
28
|
const MAX_CATCHUP = 0.1;
|
|
@@ -80,7 +80,9 @@ export const loopMethods = {
|
|
|
80
80
|
// one profile frame = one frame-hook cycle (the real loop: one per rendered frame; step(): one per frameEvery fixed steps). Counting rendered frames
|
|
81
81
|
// instead made step(render: false) divide by zero frames and report the whole run's milliseconds as one frame's
|
|
82
82
|
if (this._prof) this._prof.frames++;
|
|
83
|
+
this._picture?.frameStart();
|
|
83
84
|
advanceUiClock(this, dt); // headless pages: UI display timers run on the stepped time (core/uiClock.js)
|
|
85
|
+
writeDaylight(this); // before the hooks: an onFrame reads this frame's signal
|
|
84
86
|
for (const f of this._frame) safe(this, STRINGS.onFrame, f, null, undefined, dt);
|
|
85
87
|
this._runHooks('frame', dt);
|
|
86
88
|
safe(this, 'stream.update', this.stream._update, SOFT, this.stream);
|
|
@@ -89,32 +91,37 @@ export const loopMethods = {
|
|
|
89
91
|
safe(this, 'batching.update', this.batching.update, SOFT, this.batching); // last before rendering: picks up everything built this frame
|
|
90
92
|
safe(this, 'audio.tick', this.audio._tick, SOFT, this.audio); // positional sounds follow their objects (returns at once when there are none)
|
|
91
93
|
},
|
|
92
|
-
|
|
94
|
+
/** @param {number} dt @param {boolean} [hooks] false: draw without the game's onRender hooks (the picture check's probe renders: picture code
|
|
95
|
+
* run there wrote back the light it had just turned off) */
|
|
96
|
+
_render(dt, hooks = true) {
|
|
93
97
|
const r = this.renderer;
|
|
94
98
|
resetStats(r);
|
|
95
99
|
this._gameLights?.frame(); // plain PointLight / SpotLight at intensity 0 stop redrawing their shadow map (gameLights.js)
|
|
100
|
+
writeDaylight(this); // again: a time jump in onFrame / a module's frame hook after the first write must reach uDaylight / uTimeOfDay in the frame that draws it, with uSunDir
|
|
96
101
|
followFocus(this); // baseline sun (no sky module): its shadow box follows engine.focus (render/lights.js)
|
|
97
|
-
syncRoomEnvironment(this); // the baseline room map once a material reads scene.environment (one number compare on a quiet frame)
|
|
98
|
-
syncPlainTerms(this); // plain lit materials added since the last frame take the cloud shadow like the engine's own (render/terms.js)
|
|
99
102
|
const t0 = performance.now(); // measure
|
|
100
103
|
const gpu = this.adaptive.on ? this._gpu : null; // GPU time feeds adaptive resolution only; no queries while it is off
|
|
101
104
|
gpu?.begin();
|
|
102
105
|
// engine.onRender: camera and batching are final here. 'before' may render into its own targets (counted in renderer.info and the render phase)
|
|
103
|
-
const
|
|
106
|
+
const before = hooks ? this._onRender.before : [], after = hooks ? this._onRender.after : [];
|
|
107
|
+
const ctx = before.length || after.length ? { renderer: r, scene: this.scene, camera: this.camera, dt } : null;
|
|
104
108
|
// the game drew the canvas itself since the last engine frame (own composer / render loop): it holds the frame, the engine yields (render/ownFrame.js)
|
|
105
109
|
const draws = engineDraws(this), own = this._ownFrame;
|
|
106
110
|
if (own) own.inside++;
|
|
107
111
|
try {
|
|
108
|
-
for (const f of
|
|
112
|
+
for (const f of before) { safe(this, STRINGS.onRender, f, null, undefined, ctx); r.setRenderTarget(null); }
|
|
113
|
+
this.shadows._frame(); // a game light's cascades, after 'before': picture code aims its light there, and the placement must be what is drawn (core/shadows.js)
|
|
109
114
|
this._checkBackendAdds(); // WebGPU route: a WebGL-only material added since the last frame is named, not drawn blank (startup.js)
|
|
110
115
|
freshFrame(r); // WebGPU: step() several times in one task, or a renderOnce() earlier in this tick, must not reuse that scene pass
|
|
116
|
+
if (this._picture) this._picture.drawing = true;
|
|
111
117
|
if (draws) this.post.render(dt);
|
|
112
|
-
|
|
113
|
-
|
|
118
|
+
if (this._picture) this._picture.drawing = false;
|
|
119
|
+
for (const f of after) safe(this, STRINGS.onRender, f, null, undefined, ctx);
|
|
120
|
+
} finally { if (own) own.inside--; this._picture?.frameEnd(); }
|
|
114
121
|
gpu?.end();
|
|
115
122
|
// frames that first draw new objects pay their GPU upload here (Budget.js ApplyCost); a frame that compiled shaders is not judged by adaptive resolution
|
|
116
123
|
this._compiled = this.budget.cost.rendered(performance.now() - t0, programCount(r) ?? -1, t0 / 1000); // measure
|
|
117
|
-
if (DEV && this.ready) watchLights(this); // dev: a light added / removed mid-play compiled new shaders (one long frame): say so (lightWatch.js)
|
|
124
|
+
if (DEV && this.ready && !this._probing) watchLights(this); // dev: a light added / removed mid-play compiled new shaders (one long frame): say so (lightWatch.js)
|
|
118
125
|
},
|
|
119
126
|
_runHooks(kind, dt) {
|
|
120
127
|
const p = this._prof;
|
package/core/math.js
CHANGED
|
@@ -30,6 +30,13 @@ export function vec3(v, out = new THREE.Vector3()) {
|
|
|
30
30
|
return out.set(v.x ?? 0, v.y ?? 0, v.z ?? 0);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
/** The height a position names, or undefined when it names none ({ x, z }) */
|
|
34
|
+
export function yOf(v) {
|
|
35
|
+
if (v?.isObject3D) v = v.position;
|
|
36
|
+
const y = Array.isArray(v) ? v[1] : v?.y;
|
|
37
|
+
return Number.isFinite(y) ? y : undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
33
40
|
/** Get the horizontal coordinates [x, z] from a Vector3 / Object3D / [x, y, z] / { x, z } */
|
|
34
41
|
export function xzOf(v) {
|
|
35
42
|
if (!v || typeof v !== 'object') throw codedError('options-object', POS_ERR + JSON.stringify(v), TypeError);
|
package/core/moduleSlots.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
// provides: ['inventory'] the module holds the slot while installed (a kind 'one' shared point, core/sharedPoint.js);
|
|
3
3
|
// a second provider is shared-taken, naming both and the replaces fix
|
|
4
4
|
// requires: ['inventory'] depend on the slot, not on whichever module gives it
|
|
5
|
-
// engine.use(mine(), { replaces: 'inventory' }) unload the holder first (its tracked handles, slot, ctx.mod entries,
|
|
5
|
+
// engine.use(mine(), { replaces: 'inventory' }) unload the holder first (its tracked handles, slot, ctx.mod entries, drawing parts, dispose)
|
|
6
6
|
// Why the slot is a shared point and not a module-name table: one owner registry for everything (describe().shared shows the holder beside
|
|
7
7
|
// every shared value, ctx.track releases it with the rest), so there is no second mechanism to learn. Kept apart from modules.js only for size.
|
|
8
|
-
import { fmt } from './validate.js';
|
|
9
|
-
import { codedError } from './errorHints.js';
|
|
8
|
+
import { DEV, fmt, closest, warnOnce } from './validate.js';
|
|
9
|
+
import { codedError, coded } from './errorHints.js';
|
|
10
10
|
import { reportError } from './errors.js';
|
|
11
|
-
import {
|
|
11
|
+
import { PICTURE_SLOTS } from './pictureSlots.js';
|
|
12
12
|
|
|
13
13
|
const STRINGS = {
|
|
14
14
|
provides: 'module {name}: provides is a list of exclusive slot names, e.g. provides: [\'inventory\']; got {got}',
|
|
@@ -17,6 +17,9 @@ const STRINGS = {
|
|
|
17
17
|
notProvided: 'engine.use(..., { replaces: \'{slot}\' }): none of the modules in this call provides \'{slot}\', so the swap would leave it empty. Fix: add provides: [\'{slot}\'] to the module that takes over from {holder}',
|
|
18
18
|
byName: 'engine.use(..., { replaces }): module {name} requires module \'{dep}\' by its name, and the swap unloads {dep}. Fix: in {name}, require the slot (requires: [\'<slot>\']) instead of the module name',
|
|
19
19
|
unuse: 'dispose hook of module {name} (unloaded by replaces)',
|
|
20
|
+
misspelt: "picture module {name} provides '{slot}', which is not a picture slot, so no other part collides with it and the writers tool cannot see it. Fix: provides: ['{hint}'] (the slots: {list})",
|
|
21
|
+
notIn: "engine.unuse('{name}'): no such module is installed. Installed: {list}",
|
|
22
|
+
needed: "engine.unuse('{name}'): module {dep} requires '{slot}', and nothing else provides it. Fix: unload {dep} first, or swap in another provider: engine.use(mine(), { replaces: '{slot}' })",
|
|
20
23
|
};
|
|
21
24
|
|
|
22
25
|
/** engine.use(a(), b(), { replaces: 'sky' }): the options object is the last argument and has `replaces` (a module always has a name) */
|
|
@@ -26,6 +29,11 @@ export const isUseOpts = o => !!o && typeof o === 'object' && !Array.isArray(o)
|
|
|
26
29
|
export function checkProvides(m) {
|
|
27
30
|
if (m.provides != null && !(Array.isArray(m.provides) && m.provides.every(s => typeof s === 'string' && s)))
|
|
28
31
|
throw codedError('module-provides', fmt(STRINGS.provides, { name: m.name, got: JSON.stringify(m.provides) }));
|
|
32
|
+
// a misspelt claim is worse than none: it reads as declared and guards nothing. Picture modules only, and only a near miss: their own slots stay free
|
|
33
|
+
if (DEV && m.type === 'picture') for (const slot of m.provides ?? []) {
|
|
34
|
+
const hint = slot in PICTURE_SLOTS ? null : closest(slot, Object.keys(PICTURE_SLOTS));
|
|
35
|
+
if (hint) warnOnce(coded('module-provides', fmt(STRINGS.misspelt, { name: m.name, slot, hint, list: Object.keys(PICTURE_SLOTS).join(', ') })));
|
|
36
|
+
}
|
|
29
37
|
}
|
|
30
38
|
|
|
31
39
|
export const slotMethods = {
|
|
@@ -48,12 +56,29 @@ export const slotMethods = {
|
|
|
48
56
|
throw codedError('module-replaces', fmt(STRINGS.byName, { name: m.name, dep }));
|
|
49
57
|
return gone;
|
|
50
58
|
},
|
|
51
|
-
/**
|
|
52
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Unload one installed module: its tracked handles, its slots and ctx.mod entries, its dispose. What it added some other way stays (dev reports a picture module's
|
|
61
|
+
* leftovers). To swap a holder use engine.use(mine(), { replaces: 'slot' }).
|
|
62
|
+
* @example engine.unuse('rain');
|
|
63
|
+
* @param {string} name
|
|
64
|
+
*/
|
|
65
|
+
unuse(name) {
|
|
66
|
+
const m = this.modules.get(name);
|
|
67
|
+
if (!m) throw codedError('module-unuse', fmt(STRINGS.notIn, { name, list: [...this.modules.keys()].join(', ') || 'none' }));
|
|
68
|
+
const gives = [name, ...(m.provides ?? [])], others = [...this.modules.values()].filter(o => o !== m);
|
|
69
|
+
for (const o of others) for (const dep of o.requires ?? []) if (gives.includes(dep) && !others.some(p => p.name === dep || p.provides?.includes(dep)))
|
|
70
|
+
throw codedError('module-unuse', fmt(STRINGS.needed, { name, dep: o.name, slot: dep }));
|
|
71
|
+
this._unuse(name);
|
|
72
|
+
},
|
|
73
|
+
/**
|
|
74
|
+
* @internal unload one installed module (engine.unuse, replaces, a plugin taken out): tracked handles and slots, drawing parts, its dispose, the engine property;
|
|
75
|
+
* returns its definition. swapping: a newcomer takes over its slots, so what it wrote to them is the newcomer's to replace
|
|
76
|
+
*/
|
|
77
|
+
_unuse(name, swapping = false) {
|
|
53
78
|
const m = this.modules.get(name);
|
|
54
79
|
this._dropTracked(name);
|
|
55
|
-
disposeLooksOf(this, name);
|
|
56
80
|
try { m.dispose?.(this); } catch (err) { reportError(this, err, fmt(STRINGS.unuse, { name }), { soft: true }); }
|
|
81
|
+
this._picture?.partGone(m, swapping);
|
|
57
82
|
this.modules.delete(name); this._modState.delete(name); this._modInst.delete(name); delete this[name];
|
|
58
83
|
this._sortHooks();
|
|
59
84
|
return m;
|
package/core/moduleTypes.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Module types: what a module may own (a module's `stage` only says when it runs; its `type` says what it may own and how its errors are handled:
|
|
2
|
-
//
|
|
3
|
-
// type: 'world' | '
|
|
4
|
-
// Why a type and not a rule in the docs: an AI follows the shape of the code, not a paragraph. A
|
|
2
|
+
// picture / ui fail soft, see core/errors.js). Mixed into Engine with modules.js.
|
|
3
|
+
// type: 'world' | 'picture' | 'actor' | 'rules' | 'ui' | 'net' | 'tool' -- every module declares one, built-in or the game's (missing = error).
|
|
4
|
+
// Why a type and not a rule in the docs: an AI follows the shape of the code, not a paragraph. A picture module that defines an op, or a ui module that binds
|
|
5
5
|
// keys, is the start of two modules owning one thing; the check names the rule and the one-line fix where the mistake is made.
|
|
6
6
|
// No subtypes: differences inside a type are the declarations the engine already checks (provides, requires, shared values written with ctx.mod,
|
|
7
7
|
// material slots patched, the post stage, backends, sounds).
|
|
@@ -10,11 +10,12 @@
|
|
|
10
10
|
// attributed: the check is a guard rail at the common places, not a sandbox.
|
|
11
11
|
import { DEV, fmt } from './validate.js';
|
|
12
12
|
import { codedError } from './errorHints.js';
|
|
13
|
+
import { callerAt } from './stackFrames.js';
|
|
13
14
|
|
|
14
15
|
/** type -> what it may own (shown in the missing / unknown type error and in recipes/14) */
|
|
15
16
|
export const MODULE_TYPES = {
|
|
16
17
|
world: 'game state: save parts, world records, ops, ground / collision / navigation data (draws nothing)',
|
|
17
|
-
|
|
18
|
+
picture: 'what is seen and heard: picture values, three.js objects, particles, sounds (changes no game state)',
|
|
18
19
|
actor: 'characters: their control slots and movement values (other state only through ops)',
|
|
19
20
|
rules: 'game logic: save parts, ops, events; may take input, control or the camera for a while (a cutscene)',
|
|
20
21
|
ui: 'DOM panels and menus: declares input actions, runs ops (binds no keys, writes no game save)',
|
|
@@ -30,9 +31,9 @@ const STRINGS = {
|
|
|
30
31
|
};
|
|
31
32
|
const RULES = {
|
|
32
33
|
// [types it is wrong for, why, fix]
|
|
33
|
-
'ops.define': [['
|
|
34
|
-
"define the op in a rules (or world) module and let the
|
|
35
|
-
'world.write': [['
|
|
34
|
+
'ops.define': [['picture'], 'a picture module only shows the game, it never adds actions that change it',
|
|
35
|
+
"define the op in a rules (or world) module and let the picture module read the state; or give {name} type: 'rules' if it really is game logic"],
|
|
36
|
+
'world.write': [['picture', 'ui'], 'world records are game state; a {type} module only reads them',
|
|
36
37
|
"run an op that writes it (engine.ops.run('<noun.verb>', args)) or move the write into a rules / world module"],
|
|
37
38
|
'input.bind': [['ui'], 'a ui module declares actions; which key does what is the game\'s choice',
|
|
38
39
|
"declare the action (ctx.input.action(name, { context })) and bind keys in the game: engine.input.bind(name, ['KeyE']) or createEngine({ bindings })"],
|
|
@@ -67,6 +68,18 @@ export function asModule(e, m, fn) {
|
|
|
67
68
|
try { return fn(); } finally { e._curModule = was; }
|
|
68
69
|
}
|
|
69
70
|
|
|
71
|
+
/**
|
|
72
|
+
* @internal dev: a frame hook registered while a module installs stays that module's: it runs as the module, so the picture writers tool can tell two parts in one
|
|
73
|
+
* file apart (a stack cannot) and the type checks reach it. part / at let the leftovers check find a hook that outlived its module. Outside dev fn stays as it is.
|
|
74
|
+
*/
|
|
75
|
+
export function ownHook(e, fn) {
|
|
76
|
+
const m = DEV ? e._curModule : null;
|
|
77
|
+
if (!m) return fn;
|
|
78
|
+
const f = (...a) => asModule(e, m, () => fn(...a));
|
|
79
|
+
f.part = m.name; f.at = callerAt();
|
|
80
|
+
return f;
|
|
81
|
+
}
|
|
82
|
+
|
|
70
83
|
/** @internal describe().modules row: name, type, and provides / requires when there are any */
|
|
71
84
|
export function moduleRow(m) {
|
|
72
85
|
return { name: m.name, type: m.type, ...(m.provides?.length ? { provides: [...m.provides] } : {}), ...(m.requires?.length ? { requires: [...m.requires] } : {}) };
|
package/core/modules.js
CHANGED
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
// removed at once (dev warning naming the module), and its completion or failure changes no state and drops no handle of the newcomer.
|
|
27
27
|
// Exclusive slots: provides: ['inventory'] takes each named slot (a kind 'one' shared point, core/sharedPoint.js) for the module before its install;
|
|
28
28
|
// a second provider is shared-taken. requires may name a slot instead of a module. engine.use(mine(), { replaces: 'inventory' }) unloads the
|
|
29
|
-
// holder first (its handles, slot,
|
|
30
|
-
// critical: true on a module makes a failed init() stop engine.start() with the reason; without it a failed init is reported (
|
|
29
|
+
// holder first (its handles, slot, drawing parts, dispose), and puts it back if the new install fails.
|
|
30
|
+
// critical: true on a module makes a failed init() stop engine.start() with the reason; without it a failed init is reported (picture / ui: disabled;
|
|
31
31
|
// other types: error tiers in errors.js) and start() goes on.
|
|
32
32
|
// Dependencies: requires must be installed first (throws if missing). optional is a soft dependency: an array is only recorded (for GAMEMAP and rule R16);
|
|
33
33
|
// written as { module: 'what is lost without it' }, start() warns once in dev when it is missing: use this form for optional dependencies
|
|
@@ -37,7 +37,6 @@ import { codedError, coded } from './errorHints.js';
|
|
|
37
37
|
import { reportError } from './errors.js';
|
|
38
38
|
import { catalog, catalogSnap, catalogClaim } from './catalog.js';
|
|
39
39
|
import { readParams } from './params.js';
|
|
40
|
-
import { disposeLooksOf } from './look/part.js';
|
|
41
40
|
import { slotMethods, isUseOpts, checkProvides } from './moduleSlots.js';
|
|
42
41
|
import { checkType, asModule } from './moduleTypes.js';
|
|
43
42
|
|
|
@@ -119,14 +118,15 @@ export const moduleMethods = {
|
|
|
119
118
|
const opts = isUseOpts(mods.at(-1)) ? mods.pop() : null;
|
|
120
119
|
const list = mods.flat(Infinity), gone = this._replaced(list, opts?.replaces);
|
|
121
120
|
const plan = this._planUse(list, gone), done = [];
|
|
122
|
-
// replaces: the holder goes first (its tracked handles, its slot, its
|
|
123
|
-
const removed = [...gone].map(n => this._unuse(n));
|
|
121
|
+
// replaces: the holder goes first (its tracked handles, its slot, its drawing parts, its dispose), so the newcomer's install sees a free slot
|
|
122
|
+
const removed = [...gone].map(n => this._unuse(n, true));
|
|
124
123
|
try {
|
|
125
124
|
for (const m of plan) {
|
|
126
125
|
const had = Object.hasOwn(this, m.name), prev = this[m.name], snap = catalogSnap(this);
|
|
127
126
|
done.push({ m, had, prev }); // before install(): what it tracked before throwing is removed too
|
|
128
127
|
this._modInst.set(m.name, {}); // this install's identity: install and init ctx check it, so a stale async init cannot act on a later install
|
|
129
128
|
const ctx = this._modCtx(m);
|
|
129
|
+
this._picture?.installing(m);
|
|
130
130
|
for (const slot of m.provides ?? []) ctx.track(this._slot(slot, m.name).take({ owner: m.name })); // shared-taken when another module holds it
|
|
131
131
|
const api = asModule(this, m, () => m.install?.(this, ctx)) ?? m; // asModule: the type checks know who is installing (moduleTypes.js)
|
|
132
132
|
catalogClaim(this, m.name, snap); // ops / save parts / describe names it registered show under it in engine.catalog()
|
|
@@ -145,7 +145,6 @@ export const moduleMethods = {
|
|
|
145
145
|
this._dropTracked(m.name);
|
|
146
146
|
if (installed) try { m.dispose?.(this); } catch { /* the install error below is the one to report */ }
|
|
147
147
|
}
|
|
148
|
-
for (const m of plan) disposeLooksOf(this, m.name); // look parts and driven keys of every module in the batch, the one that threw too (review M9)
|
|
149
148
|
this._sortHooks();
|
|
150
149
|
// a replaced module comes back, so a failed swap leaves the game as it was (it installs fresh: its old handles already went)
|
|
151
150
|
if (removed.length) try { this.use(...removed); } catch (e2) { reportError(this, e2, 'putting back the module a failed replaces removed', { soft: true }); }
|
|
@@ -217,6 +216,7 @@ export const moduleMethods = {
|
|
|
217
216
|
let set = this._modTracked.get(name);
|
|
218
217
|
if (!set) this._modTracked.set(name, set = new Set());
|
|
219
218
|
set.add(h);
|
|
219
|
+
if (this._curModule === m) this._picture?.learn(m); // the module's own code called this: its file is the part's (core/pictureWriters.js)
|
|
220
220
|
return h;
|
|
221
221
|
};
|
|
222
222
|
// mod: engine.mod with the module as owner, tracked. Why a ctx verb and not "guess the running module": in an async callback the guess is wrong;
|
|
@@ -288,7 +288,7 @@ export const moduleMethods = {
|
|
|
288
288
|
/** Run order of module hooks (module names, first to last), for debugging "who runs first". */
|
|
289
289
|
get moduleOrder() { return this._moduleOrder ?? []; },
|
|
290
290
|
|
|
291
|
-
/** Re-sort the module hooks in the main loop (disabled
|
|
291
|
+
/** Re-sort the module hooks in the main loop (disabled picture / ui modules are not put back). */
|
|
292
292
|
_sortHooks() {
|
|
293
293
|
const order = sortModules([...this.modules.values()]);
|
|
294
294
|
this._moduleOrder = order.map(m => m.name);
|
package/core/namedModel.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// vegetation.define all resolve a model name here, so caching (baked file -> dev cache -> build), the per-name prototype and the shadow rule exist once.
|
|
3
3
|
// It lives in core because several modules need it and none of them owns it (content, inventory, vegetation): no module depends on another for it.
|
|
4
4
|
import * as THREE from 'three';
|
|
5
|
-
import {
|
|
5
|
+
import { neutralMaterial } from '../render/neutral.js';
|
|
6
6
|
import { shadowDefaults } from './assetEntry.js';
|
|
7
7
|
import { paramValues } from './assetManifest.js';
|
|
8
8
|
|
|
@@ -40,21 +40,24 @@ export async function vegetationModel(e, m) {
|
|
|
40
40
|
// One prototype per model name: a generator entry -> assets.cached (baked file / dev cache); a file entry -> assets.model. Content names models only (no paths).
|
|
41
41
|
// The only entry for "reuse a code-made model by name": content props / templates / vegetation and ground pickups all take it from here, so cache, bake and shadow rules exist once.
|
|
42
42
|
const protos = new WeakMap(); // owner (engine.content, or the inventory for pickups) → Map(model key → Promise<{ obj, size, center, fromGeometry }>)
|
|
43
|
+
const protoPalette = new WeakMap(); // prototype promise → the palette it was built from (null for a file model)
|
|
43
44
|
const owners = new WeakMap(); // engine → Set(owner): a hot swap walks every owner's prototypes of a changed name
|
|
44
45
|
/** Every prototype cache of this engine: [{ api, cache }] (cache: model key → Promise of the prototype). For core/assetHot.js @internal */
|
|
45
46
|
export const protoCaches = e => [...(owners.get(e) ?? [])].map(api => ({ api, cache: protos.get(api) }));
|
|
46
47
|
/**
|
|
47
48
|
* The shared prototype of a model name (or [name, ...params]): { obj, size, center, fromGeometry }. fromGeometry: the generator returned a bare
|
|
48
|
-
* geometry, wrapped here in a mesh of
|
|
49
|
+
* geometry, wrapped here in a mesh of neutral gray; a caller with a material of its own (pickups) swaps that one. @internal
|
|
49
50
|
*/
|
|
50
51
|
export function protoOf(e, api, model) {
|
|
51
52
|
if (!protos.has(api)) protos.set(api, new Map());
|
|
52
53
|
(owners.get(e) ?? owners.set(e, new Set()).get(e)).add(api);
|
|
53
|
-
const cache = protos.get(api), key = JSON.stringify(model);
|
|
54
|
+
const cache = protos.get(api), key = JSON.stringify(model), palette = e.assets.builder(list(model)[0]) ? e.assets._paletteKey : null;
|
|
55
|
+
// a palette written since this prototype was built: the next placement builds again, the same rule assets.cached has by its key
|
|
56
|
+
if (cache.has(key) && protoPalette.get(cache.get(key)) !== palette) cache.delete(key);
|
|
54
57
|
if (!cache.has(key)) {
|
|
55
58
|
const gen = cachedModel(e, model);
|
|
56
59
|
cache.set(key, (gen ? gen.then(r => {
|
|
57
|
-
const p = r.isObject3D ? r : new THREE.Mesh(r,
|
|
60
|
+
const p = r.isObject3D ? r : new THREE.Mesh(r, neutralMaterial('prop', { vertexColors: !!r.attributes.color }));
|
|
58
61
|
if (!r.isObject3D) p.userData.fromGeometry = true;
|
|
59
62
|
// the generator's own castShadow / receiveShadow are kept (a decal or flat rug that must not cast); the manifest entry can set them;
|
|
60
63
|
// a generator that set none gets cast + receive. Same rule as assets.model (core/assetEntry.js shadowDefaults)
|
|
@@ -64,6 +67,7 @@ export function protoOf(e, api, model) {
|
|
|
64
67
|
obj.userData.modelKey = key; // copies carry it (clone copies userData): a hot swap whose new model has other parts finds them by it
|
|
65
68
|
return { obj, size: box.getSize(new THREE.Vector3()), center: box.getCenter(new THREE.Vector3()), fromGeometry: !!obj.userData.fromGeometry };
|
|
66
69
|
}));
|
|
70
|
+
protoPalette.set(cache.get(key), palette);
|
|
67
71
|
}
|
|
68
72
|
return cache.get(key);
|
|
69
73
|
}
|
package/core/owned.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
// One ownership model for every property the engine writes on its own (sky
|
|
1
|
+
// One ownership model for every property the engine writes on its own (a sky's background, the shadow box's center, camera, pixel ratio ...).
|
|
2
2
|
//
|
|
3
|
-
// const o = defineOwned(engine, { id: '
|
|
4
|
-
// levels: { manual: "engine.
|
|
5
|
-
// per frame: o.check(); if (o.on)
|
|
3
|
+
// const o = defineOwned(engine, { id: 'view.far', part: 'view', key: 'far', read: () => camera.far, write: v => { camera.far = v; },
|
|
4
|
+
// levels: { manual: "engine.view.manual('far')" } });
|
|
5
|
+
// per frame: o.check(); if (o.on) target.position.copy(focus); o.mark(); (or o.drive(v) when the write is one value: needs write)
|
|
6
6
|
//
|
|
7
|
-
// Why "the engine yields" (user decision 1, 2026-11-02): a game that writes
|
|
7
|
+
// Why "the engine yields" (user decision 1, 2026-11-02): a game that writes sun.target.position directly means it. Silently writing the old value
|
|
8
8
|
// back every frame is the "my change does nothing" bug; warning and still overwriting only moves it. So the first outside write hands the property
|
|
9
9
|
// to the game (mode 'yielded'), the value stays, and one warning names the explicit takeover and the hand-back. Detection runs in release builds too
|
|
10
10
|
// (a few number compares per frame), so the game behaves the same with and without dev checks; only the warning text is dev-only.
|
|
11
11
|
//
|
|
12
|
-
// Modes per property: 'engine' (the engine writes it) | 'manual' (
|
|
13
|
-
// (the game wrote it directly).
|
|
12
|
+
// Modes per property: 'engine' (the engine writes it) | 'manual' (engine.view.manual(key), or the entry that hands the value to the game) | 'yielded'
|
|
13
|
+
// (the game wrote it directly). engine.view.manual(key, false) hands any of them back. describe().owned lists them all.
|
|
14
14
|
import { warnOnce, DEV } from './validate.js';
|
|
15
15
|
import { codedError, coded } from './errorHints.js';
|
|
16
16
|
|
|
@@ -58,9 +58,8 @@ class Owned {
|
|
|
58
58
|
/** who took it: 'game' (manual()), or 'three' for a direct write */ this.by = 'engine';
|
|
59
59
|
this._snap = null;
|
|
60
60
|
this._onChange = spec.onChange;
|
|
61
|
-
// once: the engine writes it once, at creation (renderer.toneMapping)
|
|
62
|
-
//
|
|
63
|
-
// write: describe said 'style' for a curve the game had set), and handing it back writes the creation value again (spec.write)
|
|
61
|
+
// once: the engine writes it once, at creation (renderer.toneMapping). So a direct write is the documented way to change it (yielding warns
|
|
62
|
+
// nothing), and handing it back writes the creation value again (spec.write)
|
|
64
63
|
this._once = spec.once ? { value: this._read() } : null;
|
|
65
64
|
}
|
|
66
65
|
/** Does the engine write this property now */
|
|
@@ -77,8 +76,12 @@ class Owned {
|
|
|
77
76
|
.replace('{set}', L.set ? STRINGS.set.replace('{set}', L.set) : '').replace('{back}', back)));
|
|
78
77
|
}
|
|
79
78
|
}
|
|
80
|
-
/**
|
|
81
|
-
|
|
79
|
+
/**
|
|
80
|
+
* After the engine wrote (or chose not to): remember what is there now.
|
|
81
|
+
* @param {any} [reference] what the engine left there, when that is not what is there now: a property registered after the game could already write it
|
|
82
|
+
* (a sky installed once picture code ran), so the first check() still sees that write
|
|
83
|
+
*/
|
|
84
|
+
mark(reference = this._read()) { this._snap = flat(reference); }
|
|
82
85
|
/** check, write when the engine owns it, mark. Needs spec.write */
|
|
83
86
|
drive(v) { this.check(); if (this.on) this._write(v); this.mark(); }
|
|
84
87
|
/** Take over (on) or hand back (false). Hand-back forgets the snapshot so the engine's next write is not mistaken for an outside one */
|
|
@@ -90,25 +93,28 @@ class Owned {
|
|
|
90
93
|
_set(mode, by) {
|
|
91
94
|
const was = this.mode;
|
|
92
95
|
this.mode = mode; this.by = by; this.at = this._e.time?.frame ?? null;
|
|
93
|
-
if (was !== mode)
|
|
94
|
-
}
|
|
95
|
-
/** @internal tell the look value's shared point (look.<part>.<key>, prefix match: 'sun' covers sun.intensity): a direct write or a manual()
|
|
96
|
-
* takes it from the layers, so describe().shared says writer 'three (engine yielded)'; handing it back reclaims it */
|
|
97
|
-
_point(mode) {
|
|
98
|
-
const S = this._e.stacks, pre = `look.${this.part}.${this.key}`;
|
|
99
|
-
if (!S) return;
|
|
100
|
-
for (const n of S.list()) if (n === pre || n.startsWith(pre + '.')) mode === 'engine' ? S.get(n).reclaim() : S.get(n).yieldToThree(mode === 'manual' ? `manual:${this.by}` : null);
|
|
96
|
+
if (was !== mode) this._onChange?.(this);
|
|
101
97
|
}
|
|
102
98
|
/** describe().owned row: writer = who writes it now ('engine' | 'manual:<who>' | 'three (engine yielded)'); the old field name `by` throws */
|
|
103
|
-
info() {
|
|
99
|
+
info() {
|
|
100
|
+
return ({ part: this.part, key: this.key, writer: this.mode === 'engine' ? 'engine' : this.mode === 'yielded' ? 'three (engine yielded)' : `manual:${this.by}`, ...(this.levels.manual ? { manual: this.levels.manual } : {}) });
|
|
101
|
+
}
|
|
104
102
|
}
|
|
105
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Written-once values (toneMapping) never meet an engine write that would notice a takeover, so describe() looks before any section reads
|
|
106
|
+
* them. Why one place: the render section checked on its own, after the picture section had read the stale writer, and describe('owned') alone
|
|
107
|
+
* said 'engine' for a curve the game had set
|
|
108
|
+
* @param {any} engine @internal
|
|
109
|
+
*/
|
|
110
|
+
export function checkWrittenOnce(engine) { for (const o of engine._owned?.values() ?? []) if (o._once) o.check(); }
|
|
111
|
+
|
|
106
112
|
/**
|
|
107
113
|
* Register one engine-written property. The id is unique per engine (a second defineOwned with the same id replaces the first: a module reinstalled).
|
|
108
114
|
* @param {any} engine
|
|
109
115
|
* @param {{ id: string, part: string, key?: string, read: () => any, write?: (v: any) => void, objects?: any[],
|
|
110
|
-
* levels: { manual: string, set?: string,
|
|
111
|
-
* part: the
|
|
116
|
+
* levels: { manual: string, set?: string, back?: string }, onChange?: (o: Owned) => void, once?: boolean }} spec
|
|
117
|
+
* part: the group whose manual() takes it (engine.view.manual(key)); key: the name manual() matches (prefix match on dots: 'sun' takes
|
|
112
118
|
* 'sun.intensity' and 'sun.color'); once: written only at creation (read now is the creation value; needs write for the hand-back); levels: the copyable calls the warning quotes (manual is required); onChange: mode changed (the sky hides its dome when the game
|
|
113
119
|
* takes scene.background)
|
|
114
120
|
* @returns {Owned}
|
|
@@ -116,7 +122,7 @@ class Owned {
|
|
|
116
122
|
export function defineOwned(engine, spec) {
|
|
117
123
|
if (!spec?.id || !spec.part || typeof spec.read !== 'function') throw codedError('owned-misuse', 'defineOwned(engine, { id, part, read, write?, levels }): id, part and read are required');
|
|
118
124
|
// the yield warning leads with this call, so a property nobody can take on purpose cannot be registered
|
|
119
|
-
if (typeof spec.levels?.manual !== 'string' || !spec.levels.manual) throw codedError('owned-misuse', `defineOwned(engine, { id: '${spec.id}', levels: { manual } }): levels.manual is required, the copyable takeover call the warning quotes, e.g. levels: { manual: "engine.
|
|
125
|
+
if (typeof spec.levels?.manual !== 'string' || !spec.levels.manual) throw codedError('owned-misuse', `defineOwned(engine, { id: '${spec.id}', levels: { manual } }): levels.manual is required, the copyable takeover call the warning quotes, e.g. levels: { manual: "engine.view.manual('far')" }`);
|
|
120
126
|
const reg = engine._owned ??= new Map();
|
|
121
127
|
const o = new Owned(engine, spec);
|
|
122
128
|
const old = reg.get(spec.id); if (old) live.delete(old);
|
|
@@ -126,18 +132,15 @@ export function defineOwned(engine, spec) {
|
|
|
126
132
|
/** Remove registrations (a module disposed) @param {any} engine @param {Iterable<{ id: string }>} list */
|
|
127
133
|
export function dropOwned(engine, list) { for (const o of list) { live.delete(o); if (engine._owned?.get(o.id) === o) engine._owned.delete(o.id); } }
|
|
128
134
|
|
|
129
|
-
/** Re-read every registered property of a part (after a look.<part>.set wrote them on the game's request) */
|
|
130
|
-
export function markOwned(engine, part) { for (const o of engine._owned?.values() ?? []) if (o.part === part && o._snap && !o._once) o.mark(); }
|
|
131
|
-
|
|
132
135
|
/** Registered properties of one part whose key is `key` or starts with `key.` (no keys: all of the part) */
|
|
133
|
-
|
|
136
|
+
function ownedOf(engine, part, keys) {
|
|
134
137
|
const all = [...(engine._owned?.values() ?? [])].filter(o => o.part === part);
|
|
135
138
|
if (keys == null) return all;
|
|
136
139
|
return all.filter(o => [].concat(keys).some(k => o.key === k || o.key.startsWith(k + '.')));
|
|
137
140
|
}
|
|
138
141
|
|
|
139
142
|
/**
|
|
140
|
-
*
|
|
143
|
+
* manual(keys?, on?) of a group (engine.view.manual): the game takes these properties (the engine stops writing them) or hands them back (on false).
|
|
141
144
|
* Throws with the part's takeable keys when nothing matches, so a typo does not silently do nothing.
|
|
142
145
|
* @returns {{ remove(): void }} remove() hands them back
|
|
143
146
|
*/
|
|
@@ -146,7 +149,7 @@ export function manualVerb(engine, part, keys, on = true, by = 'game') {
|
|
|
146
149
|
const hit = ownedOf(engine, part, keys);
|
|
147
150
|
if (!hit.length) {
|
|
148
151
|
const known = [...new Set(ownedOf(engine, part).map(o => o.key))];
|
|
149
|
-
throw codedError('owned-misuse', `engine
|
|
152
|
+
throw codedError('owned-misuse', `engine.${part}.manual(${keys === undefined ? '' : JSON.stringify(keys)}): ${known.length ? `no engine-written key matches; keys: ${known.join(', ')}` : 'the engine writes nothing of this part on its own right now (nothing to take over)'}`);
|
|
150
153
|
}
|
|
151
154
|
for (const o of hit) o.manual(on, by);
|
|
152
155
|
return { remove: () => { for (const o of hit) o.manual(false); } };
|