threedog 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +81 -1
- package/README.md +21 -13
- package/core/Assets.js +23 -12
- package/core/Audio.js +1 -1
- package/core/Baked.js +14 -23
- package/core/Budget.js +2 -2
- package/core/DebugOverrides.js +33 -18
- package/core/Describe.js +10 -11
- package/core/Engine.js +50 -46
- package/core/I18n.js +2 -2
- package/core/Input.js +11 -5
- package/core/Inspect.js +6 -3
- package/core/InspectMaterials.js +2 -3
- package/core/InspectPerf.js +11 -4
- package/core/MaterialInfo.js +7 -5
- package/core/Rays.js +7 -2
- package/core/Stream.js +2 -3
- package/core/UrlState.js +49 -9
- package/core/Views.js +1 -0
- package/core/adaptive.js +2 -2
- package/core/assetEntry.js +5 -2
- package/core/assetLoad.js +13 -15
- package/core/assetManifest.js +6 -3
- package/core/assetReport.js +4 -4
- package/core/batchGroups.js +9 -1
- package/core/catalog.js +16 -3
- package/core/chunkStream.js +1 -1
- package/core/copies.js +1 -1
- package/core/debugView.js +4 -4
- package/core/describeRender.js +104 -28
- package/core/describeText.js +6 -6
- package/core/errorCodes.js +72 -45
- package/core/errorHints.js +4 -1
- package/core/errors.js +4 -4
- package/core/events.generated.js +1 -0
- package/core/gameLights.js +9 -2
- package/core/lifecycle.js +2 -4
- package/core/lightWatch.js +5 -3
- package/core/loop.js +18 -11
- package/core/math.js +7 -0
- package/core/moduleSlots.js +32 -7
- package/core/moduleTypes.js +20 -7
- package/core/modules.js +7 -7
- package/core/namedModel.js +8 -4
- package/core/owned.js +33 -30
- package/core/page.js +43 -10
- package/core/pictureSlots.js +33 -0
- package/core/pictureWriters.js +343 -0
- package/core/plugins.js +64 -96
- package/core/sceneDelta.js +12 -4
- package/core/sceneMethods.js +2 -9
- package/core/services.js +1 -1
- package/core/shadowTypes.js +1 -1
- package/core/shadows.js +405 -0
- package/core/sharedPoint.js +5 -19
- package/core/stackFrames.js +16 -5
- package/core/stacks.js +6 -6
- package/core/startup.js +9 -11
- package/core/thingExplain.js +1 -1
- package/core/things.js +1 -1
- package/core/tier.js +1 -1
- package/core/util.js +1 -1
- package/core/validate.js +1 -1
- package/core/view.js +43 -0
- package/docs/AI.md +62 -58
- package/docs/API.md +15 -15
- package/docs/CODEMAP.md +36 -54
- package/docs/COMMANDS.md +28 -25
- package/docs/CONVENTIONS.md +36 -30
- package/docs/MIGRATING-0.4.md +93 -1
- package/docs/MIGRATING-0.6.md +126 -0
- package/docs/MIGRATING-0.7.md +39 -0
- package/docs/THREE.md +24 -22
- package/docs/api/assets.md +5 -3
- package/docs/api/audio.md +2 -2
- package/docs/api/budget.md +4 -0
- package/docs/api/characters.md +3 -1
- package/docs/api/collision.md +2 -2
- package/docs/api/engine.md +47 -20
- package/docs/api/events.md +2 -1
- package/docs/api/grids.md +8 -1
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +3 -0
- package/docs/api/input.md +3 -2
- package/docs/api/interactions.md +3 -1
- package/docs/api/inventory.md +1 -2
- package/docs/api/level.md +0 -1
- package/docs/api/lightPool.md +1 -1
- package/docs/api/occlusion.md +5 -0
- package/docs/api/particles.md +6 -3
- package/docs/api/pickups.md +6 -0
- package/docs/api/post.md +5 -3
- package/docs/api/sky.md +12 -10
- package/docs/api/terrain.md +12 -6
- package/docs/api/terrainDraw.md +12 -0
- package/docs/api/tools.md +8 -7
- package/docs/api/triggers.md +2 -0
- package/docs/api/vegetation.md +7 -2
- package/docs/api/vegetationDraw.md +10 -0
- package/docs/api/water.md +6 -2
- package/docs/api/weather.md +5 -0
- package/docs/api/weatherDraw.md +10 -0
- package/docs/api/world.md +1 -1
- package/docs/recipes/01-new-game.md +19 -23
- package/docs/recipes/03-items-pickups.md +25 -4
- package/docs/recipes/05-props-bake.md +53 -37
- package/docs/recipes/06-clock-events.md +3 -3
- package/docs/recipes/07-flow-scenes-pause.md +12 -3
- package/docs/recipes/08-weather-sky.md +45 -57
- package/docs/recipes/09-materials-lights-models.md +185 -0
- package/docs/recipes/10-blender-level.md +2 -2
- package/docs/recipes/11-vehicles.md +3 -3
- package/docs/recipes/13-animation.md +13 -7
- package/docs/recipes/14-custom-module.md +7 -5
- package/docs/recipes/15-perf.md +3 -3
- package/docs/recipes/16-dev-bridge.md +22 -12
- package/docs/recipes/18-world.md +10 -8
- package/docs/recipes/19-shooting-picking.md +7 -5
- package/docs/recipes/20-content-actions-save.md +6 -2
- package/docs/recipes/21-camera.md +8 -3
- package/docs/recipes/23-ops.md +1 -1
- package/docs/recipes/26-ui-parts.md +35 -11
- package/docs/recipes/28-terrain.md +12 -12
- package/docs/recipes/29-grid.md +14 -5
- package/docs/recipes/30-templates.md +8 -3
- package/docs/recipes/31-audio.md +4 -4
- package/docs/recipes/32-action-game.md +18 -4
- package/docs/recipes/34-environment-lighting.md +102 -38
- package/docs/recipes/35-picture-from-reference.md +147 -0
- package/docs/recipes/36-sky-ground-plants.md +158 -0
- package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -13
- package/docs/recipes/38-environment-hooks.md +67 -0
- package/docs/recipes/40-scene.md +106 -27
- package/docs/recipes/42-terrain-shape.md +1 -1
- package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +66 -77
- package/docs/recipes/44-water-weather-hooks.md +191 -0
- package/docs/recipes/45-cascaded-shadows.md +121 -23
- package/docs/recipes/46-blender-art-route.md +17 -20
- package/docs/recipes/47-island-snow-backdrop.md +10 -12
- package/docs/recipes/49-game-module-contract.md +1 -1
- package/docs/recipes/50-own-renderer.md +3 -3
- package/docs/recipes/52-around-the-picture.md +181 -0
- package/docs/recipes/53-ground-up-close.md +12 -12
- package/docs/recipes/54-three-idioms.md +18 -18
- package/docs/recipes/55-mods-time-wrap.md +17 -5
- package/docs/recipes/56-webgpu-tsl.md +66 -23
- package/docs/recipes/57-control.md +39 -0
- package/docs/recipes/58-input.md +3 -0
- package/docs/recipes/59-depth-post-effects.md +5 -5
- package/docs/recipes/60-judge-the-picture.md +39 -24
- package/docs/recipes/61-deploy.md +27 -0
- package/docs/recipes/62-picture-code.md +244 -0
- package/docs/recipes/63-third-person-start.md +77 -0
- package/docs/recipes/64-particles.md +35 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +7 -5
- package/examples/action/main.js +5 -4
- package/examples/action/models.js +12 -14
- package/examples/action/picture/index.js +13 -0
- package/examples/action/picture/lights.js +35 -0
- package/examples/action/picture/materials.js +8 -0
- package/examples/action/picture/palette.js +33 -0
- package/examples/plain-picture/.threedog/content-index.json +1 -0
- package/examples/plain-picture/FINDINGS.md +53 -0
- package/examples/plain-picture/GAMEMAP.md +90 -0
- package/examples/plain-picture/main.js +48 -0
- package/examples/plain-picture/picture/index.js +21 -0
- package/examples/plain-picture/picture/lights.js +54 -0
- package/examples/plain-picture/picture/materials.js +24 -0
- package/examples/plain-picture/picture/palette.js +16 -0
- package/examples/plain-picture/picture/sky.js +37 -0
- package/examples/pullable.json +31 -9
- package/examples/rc2d/GAMEMAP.md +8 -3
- package/examples/rc2d/README.md +11 -6
- package/examples/rc2d/main.js +25 -33
- package/examples/rc2d/picture/index.js +18 -0
- package/examples/rc2d/picture/lights.js +11 -0
- package/examples/rc2d/picture/materials.js +18 -0
- package/examples/rc2d/picture/palette.js +15 -0
- package/examples/rc2d/picture/post.js +11 -0
- package/examples/rc2d/rc2d.js +18 -28
- package/examples/sheepisland/.threedog/content-index.json +1 -1
- package/examples/sheepisland/GAMEMAP.md +13 -10
- package/examples/sheepisland/assets.js +2 -2
- package/examples/sheepisland/content/templates.js +1 -1
- package/examples/sheepisland/content/vegetation.js +3 -1
- package/examples/sheepisland/main.js +15 -9
- package/examples/sheepisland/{style/models.js → models.js} +13 -24
- package/examples/sheepisland/picture/index.js +20 -0
- package/examples/sheepisland/picture/lights.js +34 -0
- package/examples/sheepisland/picture/materials.js +61 -0
- package/examples/sheepisland/picture/palette.js +60 -0
- package/examples/sheepisland/picture/sky.js +20 -0
- package/examples/sheepisland/views.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +15 -11
- package/examples/styletest/main.js +20 -30
- package/examples/styletest/models.js +29 -29
- package/examples/styletest/params.js +1 -4
- package/examples/styletest/picture/env.js +38 -0
- package/examples/styletest/picture/index.js +16 -0
- package/examples/styletest/picture/lights.js +9 -0
- package/examples/styletest/picture/materials.js +28 -0
- package/examples/styletest/picture/palette.js +22 -0
- package/examples/techniques/contact-shadows/README.md +22 -23
- package/examples/techniques/contact-shadows/contactShadows.js +32 -16
- package/examples/techniques/contact-shadows/main.js +20 -18
- package/examples/techniques/contact-shadows/picture/index.js +14 -0
- package/examples/techniques/contact-shadows/picture/lights.js +34 -0
- package/examples/techniques/contact-shadows/picture/materials.js +12 -0
- package/examples/techniques/contact-shadows/picture/palette.js +17 -0
- package/examples/techniques/day-night-grade/README.md +13 -16
- package/examples/techniques/day-night-grade/main.js +15 -25
- package/examples/techniques/day-night-grade/picture/index.js +20 -0
- package/examples/techniques/day-night-grade/picture/lights.js +45 -0
- package/examples/techniques/day-night-grade/picture/materials.js +15 -0
- package/examples/techniques/day-night-grade/picture/palette.js +59 -0
- package/examples/techniques/day-night-grade/picture/post.js +25 -0
- package/examples/techniques/day-night-grade/picture/sky.js +33 -0
- package/examples/techniques/interior-light/README.md +16 -13
- package/examples/techniques/interior-light/interiorLight.js +19 -17
- package/examples/techniques/interior-light/main.js +30 -67
- package/examples/techniques/interior-light/picture/index.js +24 -0
- package/examples/techniques/interior-light/picture/lights.js +52 -0
- package/examples/techniques/interior-light/picture/materials.js +13 -0
- package/examples/techniques/interior-light/picture/palette.js +32 -0
- package/examples/techniques/interior-light/picture/sky.js +40 -0
- package/examples/techniques/modular-building/README.md +4 -3
- package/examples/techniques/modular-building/kit.js +2 -2
- package/examples/techniques/modular-building/main.js +9 -17
- package/examples/techniques/modular-building/picture/index.js +17 -0
- package/examples/techniques/modular-building/picture/lights.js +26 -0
- package/examples/techniques/modular-building/picture/materials.js +13 -0
- package/examples/techniques/modular-building/picture/palette.js +23 -0
- package/examples/techniques/night-lights/README.md +15 -14
- package/examples/techniques/night-lights/main.js +20 -43
- package/examples/techniques/night-lights/nightLights.js +25 -21
- package/examples/techniques/night-lights/picture/index.js +18 -0
- package/examples/techniques/night-lights/picture/lights.js +44 -0
- package/examples/techniques/night-lights/picture/materials.js +15 -0
- package/examples/techniques/night-lights/picture/palette.js +34 -0
- package/examples/techniques/night-lights/picture/post.js +9 -0
- package/examples/techniques/night-lights/picture/sky.js +36 -0
- package/examples/techniques/outlines-and-rim/README.md +2 -2
- package/examples/techniques/outlines-and-rim/main.js +15 -38
- package/examples/techniques/outlines-and-rim/outlines.js +3 -3
- package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
- package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
- package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
- package/examples/techniques/procedural-animation/README.md +5 -3
- package/examples/techniques/procedural-animation/main.js +9 -7
- package/examples/techniques/procedural-animation/picture/index.js +15 -0
- package/examples/techniques/procedural-animation/picture/lights.js +35 -0
- package/examples/techniques/procedural-animation/picture/materials.js +10 -0
- package/examples/techniques/procedural-animation/picture/palette.js +16 -0
- package/examples/techniques/procedural-animation/picture/sky.js +31 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +1 -1
- package/examples/techniques/procedural-surface/README.md +2 -0
- package/examples/techniques/procedural-surface/main.js +17 -55
- package/examples/techniques/procedural-surface/picture/index.js +14 -0
- package/examples/techniques/procedural-surface/picture/lights.js +18 -0
- package/examples/techniques/procedural-surface/picture/materials.js +34 -0
- package/examples/techniques/procedural-surface/picture/palette.js +15 -0
- package/examples/techniques/stylized-shading/README.md +13 -14
- package/examples/techniques/stylized-shading/main.js +11 -42
- package/examples/techniques/stylized-shading/picture/index.js +14 -0
- package/examples/techniques/stylized-shading/picture/lights.js +23 -0
- package/examples/techniques/stylized-shading/picture/materials.js +18 -0
- package/examples/techniques/stylized-shading/picture/palette.js +19 -0
- package/examples/techniques/stylized-shading/shading.js +2 -2
- package/examples/techniques/sun-and-key-light/README.md +20 -22
- package/examples/techniques/sun-and-key-light/keyLight.js +47 -29
- package/examples/techniques/sun-and-key-light/main.js +19 -63
- package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
- package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
- package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
- package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
- package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
- package/examples/techniques/three-looks/README.md +21 -0
- package/examples/techniques/three-looks/main.js +58 -0
- package/examples/techniques/three-looks/picture/cartoon.js +23 -0
- package/examples/techniques/three-looks/picture/cinematic.js +27 -0
- package/examples/techniques/three-looks/picture/comic.js +27 -0
- package/examples/techniques/three-looks/picture/index.js +14 -0
- package/examples/techniques/three-looks/picture/sun.js +23 -0
- package/examples/techniques/wet-road/README.md +7 -4
- package/examples/techniques/wet-road/main.js +18 -38
- package/examples/techniques/wet-road/picture/index.js +17 -0
- package/examples/techniques/wet-road/picture/lights.js +57 -0
- package/examples/techniques/wet-road/picture/materials.js +16 -0
- package/examples/techniques/wet-road/picture/palette.js +24 -0
- package/examples/techniques/wet-road/picture/sky.js +46 -0
- package/examples/webgpu-tsl/GAMEMAP.md +9 -4
- package/examples/webgpu-tsl/README.md +13 -10
- package/examples/webgpu-tsl/main.js +30 -7
- package/examples/webgpu-tsl/picture/index.js +18 -0
- package/examples/webgpu-tsl/picture/lights.js +25 -0
- package/examples/webgpu-tsl/picture/materials.js +36 -0
- package/examples/webgpu-tsl/picture/palette.js +23 -0
- package/examples/webgpu-tsl/picture/post.js +16 -0
- package/examples/webgpu-tsl/picture/sky.js +30 -0
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +15 -12
- package/examples/world/art/humanoid.js +9 -13
- package/examples/world/art/index.js +2 -2
- package/examples/world/art/models.js +3 -4
- package/examples/world/art/shapes.js +2 -2
- package/examples/world/assets.js +2 -2
- package/examples/world/content/audio.js +1 -1
- package/examples/world/content/items.js +1 -1
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +10 -10
- package/examples/world/models.js +17 -7
- package/examples/world/picture/index.js +20 -0
- package/examples/world/picture/lights.js +41 -0
- package/examples/world/picture/materials.js +34 -0
- package/examples/world/picture/palette.js +74 -0
- package/examples/world/picture/post.js +9 -0
- package/examples/world/picture/sky.js +39 -0
- package/index.d.ts +7 -16
- package/index.js +7 -7
- package/llms.txt +15 -13
- package/modules/ambience/Ambience.js +1 -1
- package/modules/calendar/Calendar.js +1 -1
- package/modules/calendar/index.js +1 -0
- package/modules/camera/FirstPersonCamera.js +1 -1
- package/modules/camera/FixedCamera.js +2 -2
- package/modules/camera/RtsCamera.js +1 -1
- package/modules/camera/common.js +7 -5
- package/modules/characters/Character.js +15 -10
- package/modules/characters/NPC.js +5 -5
- package/modules/characters/assetModel.js +5 -4
- package/modules/characters/index.js +28 -3
- package/modules/characters/movers/common.js +6 -1
- package/modules/characters/movers/manual.js +3 -0
- package/modules/characters/movers/support.js +25 -11
- package/modules/characters/npcSim.js +5 -1
- package/modules/characters/proceduralRig.js +18 -4
- package/modules/characters/useModel.js +2 -2
- package/modules/collision/Collision.js +4 -2
- package/modules/content/index.js +8 -0
- package/modules/content/models.js +56 -11
- package/modules/content/props.js +5 -3
- package/modules/content/rules.js +12 -4
- package/modules/content/templates.js +5 -3
- package/modules/gameplay/Interactions.js +91 -16
- package/modules/gameplay/Inventory.js +3 -3
- package/modules/gameplay/dialogueBox.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +1 -1
- package/modules/gameplay/interactionPrompt.js +1 -1
- package/modules/gameplay/interactions.contract.js +1 -1
- package/modules/gameplay/inventoryOps.js +2 -2
- package/modules/gameplay/pickups.js +62 -24
- package/modules/gameplay/questLog.js +2 -2
- package/modules/grid/Layer.js +13 -0
- package/modules/grid/index.js +40 -11
- package/modules/grid/preview.js +24 -15
- package/modules/grid/tiles.js +15 -19
- package/modules/hlod/index.js +3 -2
- package/modules/hud/index.js +13 -0
- package/modules/hud/parts.js +9 -7
- package/modules/level/index.js +5 -4
- package/modules/lights/index.js +12 -8
- package/modules/music/Music.js +1 -1
- package/modules/particles/Particles.js +41 -20
- package/modules/particles/effect.js +21 -6
- package/modules/photo/Photo.js +11 -10
- package/modules/settings/Settings.js +7 -7
- package/modules/settings/apply.js +5 -5
- package/modules/settings/sections.js +2 -2
- package/modules/settings/strings.js +1 -1
- package/modules/sky/Sky.js +104 -89
- package/modules/sky/clouds.js +16 -17
- package/modules/sky/dome.js +100 -0
- package/modules/sky/domeLayers.js +5 -5
- package/modules/sky/environment.js +45 -169
- package/modules/sky/fog.js +5 -180
- package/modules/sky/frame.js +26 -90
- package/modules/sky/season.js +3 -3
- package/modules/sky/shader.js +35 -29
- package/modules/sky/skyModule.js +25 -22
- package/modules/sky/tint.js +9 -11
- package/modules/terrain/ChunkManager.js +29 -12
- package/modules/terrain/draw.js +154 -0
- package/modules/terrain/index.js +44 -66
- package/modules/terrain/terrainDefaults.js +2 -2
- package/modules/terrain/terrainEdit.js +1 -1
- package/modules/terrain/terrainGen.js +2 -2
- package/modules/triggers/index.js +10 -6
- package/modules/vegetation/Vegetation.js +58 -17
- package/modules/vegetation/draw.js +191 -0
- package/modules/vegetation/groundChunks.js +1 -1
- package/modules/vegetation/index.js +10 -10
- package/modules/water/Water.js +135 -88
- package/modules/water/surface.js +53 -53
- package/modules/weather/Weather.js +52 -17
- package/modules/weather/particles.js +13 -5
- package/modules/weather/shaders.js +1 -1
- package/modules/weather/weatherDraw.js +141 -0
- package/modules/world/World.js +2 -2
- package/modules/world/views.js +1 -1
- package/package.json +3 -2
- package/presets.js +2 -2
- package/render/PostFX.js +199 -41
- package/render/backend.js +52 -6
- package/render/cascades.js +195 -0
- package/render/cascades.tsl.js +96 -0
- package/render/daylight.js +39 -0
- package/render/detail.js +5 -5
- package/render/effects.js +41 -26
- package/render/fx/cel.tsl.js +42 -0
- package/render/fx/index.js +7 -5
- package/render/fx/patchNodes.tsl.js +1 -1
- package/render/fx/postWebGPU.tsl.js +30 -7
- package/render/fx/sky.tsl.js +19 -92
- package/render/fx/water.tsl.js +1 -1
- package/render/layers.js +14 -0
- package/render/lighting.js +6 -5
- package/render/lightmap.js +142 -0
- package/render/lights.js +23 -201
- package/render/materials.js +44 -160
- package/render/neutral.js +23 -0
- package/render/occlusion.js +184 -0
- package/render/ownFrame.js +1 -1
- package/render/patches.js +34 -29
- package/render/postWebGL.js +11 -3
- package/render/probes.js +179 -122
- package/render/slots.js +4 -4
- package/render/terms.js +53 -101
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +333 -296
- package/types/gameplay.d.ts +65 -26
- package/types/generated/core/Audio.d.ts +1 -1
- package/types/generated/core/DebugOverrides.d.ts +14 -6
- package/types/generated/core/Input.d.ts +9 -2
- package/types/generated/core/page.d.ts +9 -2
- package/types/generated/modules/grid/Layer.d.ts +8 -0
- package/types/generated/modules/grid/index.d.ts +29 -5
- package/types/generated/modules/particles/Particles.d.ts +13 -6
- package/types/generated/modules/sky/Sky.d.ts +85 -18
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/water/Water.d.ts +50 -3
- package/types/generated/modules/weather/Weather.d.ts +33 -3
- package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
- package/types/generated/modules/world/World.d.ts +2 -2
- package/types/generated/render/PostFX.d.ts +53 -10
- package/types/generated/render/lighting.d.ts +29 -0
- package/types/generated/render/materials.d.ts +19 -44
- package/types/generated/render/occlusion.d.ts +13 -0
- package/types/physics.d.ts +5 -3
- package/types/tsl.d.ts +8 -0
- package/types/world.d.ts +376 -57
- package/ui/Focus.js +12 -2
- package/ui/LoadingScreen.js +2 -2
- package/ui/Parts.js +8 -4
- package/ui/UI.js +10 -10
- package/ui/cursor.js +1 -1
- package/ui/theme.js +33 -27
- package/ui/touchPart.js +1 -1
- package/core/look/coreParts.js +0 -219
- package/core/look/part.js +0 -253
- package/core/look/points.js +0 -255
- package/core/look/report.js +0 -96
- package/core/look/shadowPart.js +0 -63
- package/core/look/state.js +0 -45
- package/core/look/write.js +0 -70
- package/core/styleParts.js +0 -114
- package/docs/api/style.md +0 -136
- package/docs/api/terrainLook.md +0 -10
- package/docs/api/vegetationLook.md +0 -10
- package/docs/api/weatherLook.md +0 -10
- package/docs/recipes/09-style.md +0 -218
- package/docs/recipes/35-style-from-reference.md +0 -153
- package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
- package/docs/recipes/38-environment-look-hooks.md +0 -99
- package/docs/recipes/41-thing-registry.md +0 -97
- package/docs/recipes/44-water-weather-look-hooks.md +0 -144
- package/docs/recipes/48-make-material.md +0 -75
- package/docs/recipes/52-look.md +0 -282
- package/examples/action/look.js +0 -5
- package/examples/sheepisland/style/index.js +0 -79
- package/examples/styletest/look.js +0 -11
- package/examples/techniques/day-night-grade/dayNightGrade.js +0 -76
- package/examples/webgpu-tsl/tslScene.js +0 -75
- package/examples/world/style/index.js +0 -61
- package/examples/world/style/plugins/10-bloom.js +0 -5
- package/modules/sky/cascades.js +0 -186
- package/modules/sky/cascades.tsl.js +0 -82
- package/modules/sky/look.js +0 -54
- package/modules/sky/lookFog.js +0 -76
- package/modules/sky/lookShadow.js +0 -62
- package/modules/sky/lookSky.js +0 -169
- package/modules/sky/shadow.js +0 -98
- package/modules/terrain/look.js +0 -83
- package/modules/terrain/lookGround.js +0 -66
- package/modules/vegetation/look.js +0 -119
- package/modules/vegetation/lookWind.js +0 -98
- package/modules/water/look.js +0 -91
- package/modules/water/surfaceDefaults.js +0 -3
- package/modules/weather/look.js +0 -74
- package/modules/weather/weatherLook.js +0 -135
- package/render/lookGlow.js +0 -139
- package/render/lookSurface.js +0 -224
- package/render/postLook.js +0 -164
- package/render/surface.js +0 -105
- package/types/generated/modules/weather/weatherLook.d.ts +0 -12
- package/types/style.d.ts +0 -671
package/modules/grid/index.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// Where state lives (nothing is stored twice):
|
|
7
7
|
// placed things -> world records with a `grid` field (saved by world); occupancy is an index rebuilt from them (world:add / change / remove / load)
|
|
8
8
|
// per-cell layers -> Layer maps, saved here under the save key 'grids' (version 2) as a per-cell diff against the authored cells (Layer.js)
|
|
9
|
+
// Picture: grids({ ok, bad, previewOpacity, previewHeight, tiles, tileLift }) for the plain values, pv.material and layer.material for the three.js materials.
|
|
9
10
|
// The index is the "don't go around it" check: in dev a record's grid field is frozen (editing it in place throws), writes outside ops
|
|
10
11
|
// trigger the ops guard, and a record whose footprint overlaps another one is reported with the fix.
|
|
11
12
|
import { Grid, MAIN, occKey } from './Grid.js';
|
|
@@ -41,9 +42,19 @@ const freeze = p => { Object.freeze(p.cell); Object.freeze(p.size); return Objec
|
|
|
41
42
|
* @experimental
|
|
42
43
|
*/
|
|
43
44
|
export class Grids {
|
|
44
|
-
/**
|
|
45
|
-
|
|
45
|
+
/**
|
|
46
|
+
* @internal
|
|
47
|
+
* @param {any} e
|
|
48
|
+
* @param {GridsOptions} o
|
|
49
|
+
*/
|
|
50
|
+
constructor(e, o) {
|
|
46
51
|
/** @internal */ this.engine = e;
|
|
52
|
+
/** Preview color where it can be placed, read when a preview is made @type {any} */ this.ok = o.ok;
|
|
53
|
+
/** Preview color where it cannot be placed, read when a preview is made @type {any} */ this.bad = o.bad;
|
|
54
|
+
/** Opacity of the preview box, read when a preview is made */ this.previewOpacity = o.previewOpacity;
|
|
55
|
+
/** Height of the preview box (meters), read when a preview is made */ this.previewHeight = o.previewHeight;
|
|
56
|
+
/** Tile colors by layer name, { layer: { field: color } } (first truthy field of a cell wins), read when a layer is made @type {Record<string, Record<string, any>>} */ this.tiles = o.tiles;
|
|
57
|
+
/** Height of tiles above the ground (meters), read when a layer is made */ this.tileLift = o.tileLift;
|
|
47
58
|
/** @internal */ this._grids = new Map();
|
|
48
59
|
/** @internal */ this._defs = new Map();
|
|
49
60
|
/** @internal id -> { g, keys } */ this._byId = new Map();
|
|
@@ -131,16 +142,16 @@ export class Grids {
|
|
|
131
142
|
}
|
|
132
143
|
/**
|
|
133
144
|
* Show where an item would go: the target cell under the pointer ('pointer', default), in front of the player ('front') or from your
|
|
134
|
-
* function, turned by the input action rotate (default name 'rotate'; the game binds it, e.g. presets.bindings.gridRotate; the engine binds no key itself), light when can() passes, dark otherwise (neutral tool colors;
|
|
135
|
-
*
|
|
145
|
+
* function, turned by the input action rotate (default name 'rotate'; the game binds it, e.g. presets.bindings.gridRotate; the engine binds no key itself), light when can() passes, dark otherwise (neutral tool colors; grids({ ok, bad }) override them).
|
|
146
|
+
* draw: false = no visual; (engine) => ({ update(view), hide(), dispose() }) = your own; pv.material is the default box's three.js material. place() runs grid.place with what is shown
|
|
136
147
|
* @example engine.input.bind({ place: ['Mouse0'], ...presets.bindings.gridRotate }); // the game's own bindings
|
|
137
148
|
* const pv = engine.grids.preview({ grid: 'field', item: 'tower' });
|
|
138
149
|
* engine.onFrame(() => { if (engine.input.pressed('place')) { const r = pv.place(); if (!r.ok) toast(engine, engine.t('grid.' + r.code)); } });
|
|
139
|
-
* @param {{ grid: string, item: string, from?: 'pointer' | 'front' | ((e: any) => any), rotate?: string | false, rotation?: number,
|
|
150
|
+
* @param {{ grid: string, item: string, from?: 'pointer' | 'front' | ((e: any) => any), rotate?: string | false, rotation?: number, draw?: false | ((e: any) => any) }} opts
|
|
140
151
|
* @returns {{ cell: [number, number] | null, rotation: number, ok: boolean, code: string | null, rotate(n?: number): void, place(fields?: object): { ok: boolean, value?: any, code?: string }, remove(): void }}
|
|
141
152
|
*/
|
|
142
153
|
preview(opts) {
|
|
143
|
-
readParams('grids.preview()', keysSchema(['grid', 'item', 'from', 'rotate', 'rotation', '
|
|
154
|
+
readParams('grids.preview()', keysSchema(['grid', 'item', 'from', 'rotate', 'rotation', 'draw']), opts);
|
|
144
155
|
return makePreview(this.engine, this, opts);
|
|
145
156
|
}
|
|
146
157
|
|
|
@@ -148,11 +159,11 @@ export class Grids {
|
|
|
148
159
|
_layerAdded(l) {
|
|
149
160
|
const d = this._loaded?.[l.grid.name]?.[l.name];
|
|
150
161
|
if (d) l.fromJSON(d);
|
|
151
|
-
const t = layerTiles(this.engine, l);
|
|
162
|
+
const t = layerTiles(this.engine, l, this);
|
|
152
163
|
if (t) this._tiles.set(l, t);
|
|
153
164
|
}
|
|
154
165
|
/** @internal a layer's options changed after content created it: rebuild its tiles */
|
|
155
|
-
_retile(l) { this._tiles.get(l)?.dispose(); this._tiles.delete(l); const t = layerTiles(this.engine, l); if (t) this._tiles.set(l, t); }
|
|
166
|
+
_retile(l) { this._tiles.get(l)?.dispose(); this._tiles.delete(l); const t = layerTiles(this.engine, l, this); if (t) this._tiles.set(l, t); }
|
|
156
167
|
/** @internal */
|
|
157
168
|
_index(rec) {
|
|
158
169
|
const p = rec.grid, g = this._grids.get(p.id);
|
|
@@ -223,19 +234,37 @@ export class Grids {
|
|
|
223
234
|
}
|
|
224
235
|
}
|
|
225
236
|
|
|
237
|
+
// tool colors, not art: neutral defaults that still tell the two apart (light = can place, dark = cannot)
|
|
238
|
+
const GRID_PARAMS = {
|
|
239
|
+
ok: { type: 'any', default: 0xe0e0e0, desc: 'preview color where it can be placed' },
|
|
240
|
+
bad: { type: 'any', default: 0x3a3a3a, desc: 'preview color where it cannot be placed' },
|
|
241
|
+
previewOpacity: { type: 'number', default: 0.45, min: 0, max: 1, desc: 'opacity of the preview box' },
|
|
242
|
+
previewHeight: { type: 'number', default: 0.08, min: 0, desc: 'height of the preview box (meters)' },
|
|
243
|
+
tiles: { type: 'any', default: {}, desc: 'tile colors by layer name: { layer: { field: color } }, first truthy field of a cell wins; a layer named here draws tiles' },
|
|
244
|
+
tileLift: { type: 'number', default: 0.03, desc: 'height of tiles above the ground (meters)' },
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* Options of grids()
|
|
248
|
+
* @typedef {{ ok?: any, bad?: any, previewOpacity?: number, previewHeight?: number, tiles?: Record<string, Record<string, any>>, tileLift?: number }} GridsOptions
|
|
249
|
+
*/
|
|
250
|
+
|
|
226
251
|
/**
|
|
227
252
|
* Grid placement module: installed as engine.grids. Needs world(). Adds the ops grid.place / grid.remove / grid.move and the save key 'grids' (layers).
|
|
253
|
+
* Options: ok, bad, previewOpacity, previewHeight (the preview box), tiles, tileLift (layer tiles). The materials are pv.material and layer.material.
|
|
228
254
|
* @example engine.use(world(), grids())
|
|
255
|
+
* @example engine.use(world(), grids({ ok: 0x66dd88, bad: 0xdd5544, tiles: { soil: { watered: 0x5b3d2a, tilled: 0x8a6243 } } }))
|
|
256
|
+
* @param {GridsOptions} [opts]
|
|
229
257
|
* @returns {import('../../types/core').ModuleDef<Grids>}
|
|
230
258
|
* @experimental
|
|
231
259
|
*/
|
|
232
|
-
export function grids() {
|
|
260
|
+
export function grids(opts = {}) {
|
|
261
|
+
const o = readParams('grids', GRID_PARAMS, opts);
|
|
233
262
|
let G = null, offOps = null;
|
|
234
263
|
const subs = [];
|
|
235
264
|
return {
|
|
236
|
-
name: 'grids', type: 'world', label: 'Grid placement', stage: 'gameplay', requires: ['world'],
|
|
265
|
+
name: 'grids', type: 'world', label: 'Grid placement', stage: 'gameplay', requires: ['world'], params: GRID_PARAMS, options: o,
|
|
237
266
|
install(e) {
|
|
238
|
-
G = new Grids(e);
|
|
267
|
+
G = new Grids(e, o);
|
|
239
268
|
e.i18n.add(TEXT); // grid.<code> player text for every built-in failure code, and the rotate action's label
|
|
240
269
|
e.saves.register('grids', { atomic: true, version: 2, migrate: GRIDS_MIGRATE, save: () => G.toJSON(), load: d => G.fromJSON(d) });
|
|
241
270
|
offOps = defineGridOps(e, G);
|
package/modules/grid/preview.js
CHANGED
|
@@ -1,34 +1,37 @@
|
|
|
1
1
|
// Placement preview (engine.grids.preview): picks the target cell every frame (under the pointer, in front of the player, or from
|
|
2
2
|
// your function), keeps a rotation turned by an input action, asks can(), and shows a see-through footprint
|
|
3
|
-
// (
|
|
4
|
-
// The
|
|
3
|
+
// (grids({ ok, bad }) colors). It never changes gameplay state: place() runs the grid.place op with what it shows.
|
|
4
|
+
// The picture is a replaceable part: draw: false (no visual, the handle still answers), or (engine) => ({ update(view), hide(), dispose() }); pv.material is the default box's.
|
|
5
5
|
import * as THREE from 'three';
|
|
6
|
-
import {
|
|
6
|
+
import { neutralMaterial } from '../../render/neutral.js';
|
|
7
7
|
import { screenToGround } from '../../core/screenToGround.js';
|
|
8
8
|
import { warnOnce } from '../../core/validate.js';
|
|
9
9
|
import { failure } from '../../core/opsFail.js';
|
|
10
|
+
import { codedError } from '../../core/errorHints.js';
|
|
10
11
|
|
|
11
|
-
// tool colors, not art: neutral defaults that still tell the two apart (light = can place, dark = cannot); a style may override them
|
|
12
|
-
const OK = 0xe0e0e0, BAD = 0x3a3a3a;
|
|
13
12
|
const NO_KEY = 'grids.preview(): the action "{a}" has no keys, so the preview cannot be turned by input. Bind it (engine.input.bind("{a}", ["KeyR"]) or presets.bindings.gridRotate), or pass rotate: false and call pv.rotate() from your own control';
|
|
14
13
|
|
|
15
|
-
/** Default
|
|
16
|
-
function
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const mesh = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), mat);
|
|
14
|
+
/** Default picture: a flat translucent box over the footprint @internal */
|
|
15
|
+
function boxPart(e, st) {
|
|
16
|
+
const own = neutralMaterial('decal', { transparent: true, opacity: st.previewOpacity, depthWrite: false });
|
|
17
|
+
const mesh = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), own);
|
|
20
18
|
mesh.name = 'grid:preview'; mesh.visible = false; mesh.renderOrder = 2;
|
|
21
19
|
e.add(mesh, { owner: 'engine:grid' });
|
|
22
|
-
const ok = new THREE.Color(st.ok
|
|
20
|
+
const ok = new THREE.Color(st.ok), bad = new THREE.Color(st.bad), h = st.previewHeight;
|
|
23
21
|
return {
|
|
22
|
+
get material() { return mesh.material; },
|
|
23
|
+
set material(m) {
|
|
24
|
+
if (!m?.isMaterial) throw codedError('grids-misuse', `pv.material takes a three.js material, got ${m}`);
|
|
25
|
+
mesh.material = m;
|
|
26
|
+
},
|
|
24
27
|
update(v) {
|
|
25
28
|
mesh.visible = true;
|
|
26
29
|
mesh.scale.set(v.size[0] - 0.04, h, v.size[1] - 0.04);
|
|
27
30
|
mesh.position.set(v.center.x, v.center.y + h / 2, v.center.z);
|
|
28
|
-
|
|
31
|
+
/** @type {any} */ (mesh.material).color?.copy(v.ok ? ok : bad); // telling can from cannot is the preview's job, on any material that has a color
|
|
29
32
|
},
|
|
30
33
|
hide() { mesh.visible = false; },
|
|
31
|
-
dispose() { e.remove(mesh); mesh.geometry.dispose();
|
|
34
|
+
dispose() { e.remove(mesh); mesh.geometry.dispose(); own.dispose(); }, // a material the game set stays the game's
|
|
32
35
|
};
|
|
33
36
|
}
|
|
34
37
|
|
|
@@ -46,17 +49,23 @@ function target(e, from, g) {
|
|
|
46
49
|
|
|
47
50
|
/** Create a preview handle @internal */
|
|
48
51
|
export function makePreview(e, grids, opts) {
|
|
49
|
-
const { grid, item, from = 'pointer', rotate = 'rotate',
|
|
52
|
+
const { grid, item, from = 'pointer', rotate = 'rotate', draw } = opts;
|
|
50
53
|
const g = grids._must(grid), rule = grids._rule(item);
|
|
51
54
|
// declared by the preview, owned by the grid module and taken away with the preview (or the module), so nothing outlives it; the game binds
|
|
52
55
|
// the key (presets.bindings.gridRotate) like every module action
|
|
53
56
|
const decl = rotate ? e.input.action(rotate, { label: 'grid.rotate', owner: 'grids', optional: true }) : null;
|
|
54
57
|
if (rotate && !e.input.keysOf(rotate).length) warnOnce(NO_KEY.replaceAll('{a}', rotate));
|
|
55
|
-
const part =
|
|
58
|
+
const part = draw === false ? null : typeof draw === 'function' ? draw(e) : boxPart(e, grids);
|
|
56
59
|
const h = {
|
|
57
60
|
/** target cell or null (nothing under the pointer) */ cell: null,
|
|
58
61
|
rotation: opts.rotation ?? 0,
|
|
59
62
|
/** why it cannot be placed: 'noTarget' or the grid.can() code; null when ok */ ok: false, code: 'noTarget',
|
|
63
|
+
/** The default box's three.js material (null with draw: false or your own part). Set it to swap the picture, used as given; its color still shows ok / bad */
|
|
64
|
+
get material() { return part?.material ?? null; },
|
|
65
|
+
set material(m) {
|
|
66
|
+
if (!part || !('material' in part)) throw codedError('grids-misuse', "pv.material: this preview has draw: false or your own part, so it draws no default box");
|
|
67
|
+
part.material = m;
|
|
68
|
+
},
|
|
60
69
|
/** Turn by quarter turns (the rotate action does this too) */
|
|
61
70
|
rotate(n = 1) { h.rotation = (((h.rotation + n) % 4) + 4) % 4; },
|
|
62
71
|
/** Run grid.place with the shown cell and rotation; returns the op result */
|
package/modules/grid/tiles.js
CHANGED
|
@@ -2,39 +2,35 @@
|
|
|
2
2
|
// whose four corners sit on engine.surface + lift, so tiles hug a ramp or terrain and work on any ground provider
|
|
3
3
|
// (procedural terrain, a Blender level, a flat greenhouse floor). One merged mesh = one draw call; it is rebuilt only when
|
|
4
4
|
// the layer version or the ground (level:loaded) changes.
|
|
5
|
-
//
|
|
6
|
-
// (first truthy field in the table's order wins), else neutral gray. tiles: false = off; a function = your own part.
|
|
5
|
+
// Picture: layer option tiles.color(data, cell) -> color | null, else tiles.colors = { field: color }, else the module's table grids({ tiles: { layer: { field: color } } })
|
|
6
|
+
// (first truthy field in the table's order wins), else neutral gray. tiles: false = off; a function = your own part. layer.material is the three.js material they draw with.
|
|
7
7
|
import * as THREE from 'three';
|
|
8
|
-
import {
|
|
8
|
+
import { neutralMaterial } from '../../render/neutral.js';
|
|
9
9
|
import { surfaceOr } from '../../core/ground.js';
|
|
10
|
+
import { readParams, keysSchema } from '../../core/params.js';
|
|
10
11
|
|
|
11
12
|
const GAP = 0.03; // fraction of a cell left between tiles: keeps tiles visibly separate (crisp edges)
|
|
12
13
|
const FALLBACK = 0x9a9a9a;
|
|
13
14
|
|
|
14
|
-
/**
|
|
15
|
-
function
|
|
15
|
+
/** Color function from a { field: color } table: the first truthy field in the table's order wins (the layer's tiles.colors wins over the module's grids({ tiles })) @internal */
|
|
16
|
+
function tableColor(table) {
|
|
16
17
|
if (!table) return null;
|
|
17
18
|
const order = Object.entries(table);
|
|
18
19
|
return d => { for (const [f, c] of order) if (d[f]) return c; return null; };
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
/** Look function from the style table (null if the style has none for this layer) @internal */
|
|
22
|
-
function styleLook(e, name) {
|
|
23
|
-
return tableLook(e.style.grid?.tiles?.[name]);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
22
|
/** Build the tile view of a layer, or null when off. Returns { frame(), dispose() } @internal */
|
|
27
|
-
export function layerTiles(e, layer) {
|
|
23
|
+
export function layerTiles(e, layer, st) {
|
|
28
24
|
const t = layer.opts.tiles, name = layer.name;
|
|
29
25
|
if (t === false) return null;
|
|
30
26
|
if (typeof t === 'function') return customTiles(e, layer, t(e, layer));
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
27
|
+
if (t && typeof t === 'object') readParams(`layer('${name}') tiles`, keysSchema(['color', 'colors', 'lift']), t);
|
|
28
|
+
const color = (t && typeof t === 'object' && (t.color || tableColor(t.colors))) || tableColor(st.tiles[name]) || (t ? () => FALLBACK : null);
|
|
29
|
+
if (!color) return null; // no table and not asked for: a pure data layer
|
|
30
|
+
const lift = t?.lift ?? st.tileLift;
|
|
35
31
|
// drawn over the ground it lies on: depth offset instead of a big lift keeps it glued to slopes
|
|
36
|
-
|
|
37
|
-
const geo = new THREE.BufferGeometry(), mesh = new THREE.Mesh(geo,
|
|
32
|
+
const own = neutralMaterial('decal', { vertexColors: true, polygonOffset: true, polygonOffsetFactor: -2, polygonOffsetUnits: -2 });
|
|
33
|
+
const geo = new THREE.BufferGeometry(), mesh = new THREE.Mesh(geo, own);
|
|
38
34
|
mesh.name = `grid:${layer.grid.name}.${name}`; mesh.receiveShadow = true; mesh.frustumCulled = false;
|
|
39
35
|
e.add(mesh, { owner: 'engine:grid' });
|
|
40
36
|
let ver = -1, ground = 0, built = -1;
|
|
@@ -44,7 +40,7 @@ export function layerTiles(e, layer) {
|
|
|
44
40
|
const cells = layer.query(), pos = [], clr = [], idx = [];
|
|
45
41
|
let last = 0; // height of the previous corner: a corner beyond the island borrows it instead of -Infinity
|
|
46
42
|
for (const { cell, data } of cells) {
|
|
47
|
-
const c =
|
|
43
|
+
const c = color(data, cell);
|
|
48
44
|
if (c == null) continue;
|
|
49
45
|
col.set(c);
|
|
50
46
|
// from the grid's mapping (its cell centers), so a replaced mapping draws where its cells are
|
|
@@ -65,7 +61,7 @@ export function layerTiles(e, layer) {
|
|
|
65
61
|
mesh.visible = g.zone == null || e.world?.zone == null || e.world.zone === g.zone;
|
|
66
62
|
if (layer._ver !== ver || ground !== built) { ver = layer._ver; built = ground; rebuild(); }
|
|
67
63
|
},
|
|
68
|
-
dispose() { off.remove(); e.remove(mesh); geo.dispose();
|
|
64
|
+
dispose() { off.remove(); e.remove(mesh); geo.dispose(); own.dispose(); }, // a material the game set stays the game's
|
|
69
65
|
};
|
|
70
66
|
}
|
|
71
67
|
|
package/modules/hlod/index.js
CHANGED
|
@@ -149,6 +149,7 @@ export function hlod(opts = {}) {
|
|
|
149
149
|
group.add(p); c.proxy.push(p);
|
|
150
150
|
}
|
|
151
151
|
delete c.sources;
|
|
152
|
+
c.watch = e.occlusion.watch([...c.proxy, ...c.originals]);
|
|
152
153
|
api.cells.push(c);
|
|
153
154
|
yield;
|
|
154
155
|
}
|
|
@@ -158,7 +159,7 @@ export function hlod(opts = {}) {
|
|
|
158
159
|
/** Unregister: restore originals, release proxies */
|
|
159
160
|
remove() {
|
|
160
161
|
h.removed = true; handles.delete(h);
|
|
161
|
-
for (const c of list) { setFar(c, false); for (const p of c.proxy) p.geometry.dispose(); for (const m of c.originals) { delete m.userData.hlod; shade.get(m)?.release(); } }
|
|
162
|
+
for (const c of list) { c.watch?.remove(); setFar(c, false); for (const p of c.proxy) p.geometry.dispose(); for (const m of c.originals) { delete m.userData.hlod; shade.get(m)?.release(); } }
|
|
162
163
|
api.cells = api.cells.filter(c => !list.includes(c));
|
|
163
164
|
for (const l of lods.values()) shade.get(l.node)?.release();
|
|
164
165
|
e.detach(group); // proxies share the originals' materials and are never ray-registered: geometries were disposed above
|
|
@@ -183,7 +184,7 @@ export function hlod(opts = {}) {
|
|
|
183
184
|
|
|
184
185
|
const addLevel = root => { levelHandle?.remove(); levelHandle = root ? api.add(root) : null; };
|
|
185
186
|
return {
|
|
186
|
-
name: 'hlod', type: '
|
|
187
|
+
name: 'hlod', type: 'picture', params: HLOD_PARAMS, options: opts, label: 'HLOD', optional: ['terrain', 'level'],
|
|
187
188
|
install(engine, ctx) {
|
|
188
189
|
e = engine;
|
|
189
190
|
e.i18n.add({ 'zh-CN': { 'module.hlod': '远景合并' }, en: { 'module.hlod': 'distant merge' } });
|
package/modules/hud/index.js
CHANGED
|
@@ -153,6 +153,19 @@ export function hud(opts = {}) {
|
|
|
153
153
|
* 'left' | 'right' | 'bottom-left' | 'bottom' | 'bottom-right', the screen corner / edge its column sits at
|
|
154
154
|
*/
|
|
155
155
|
counter(id, o) { item('counter', id, o); },
|
|
156
|
+
/**
|
|
157
|
+
* Add n (default 1; negative takes away) to a number counter and return the new value. A counter not declared yet starts at 0 with its id as the label, so
|
|
158
|
+
* declare it with counter() for a player-facing label and max
|
|
159
|
+
* @example engine.hud.counter('shells', { label: 'Shells', value: 0, max: 4 }); engine.hud.add('shells');
|
|
160
|
+
*/
|
|
161
|
+
add(id, n = 1) {
|
|
162
|
+
const it = items.get(id), v = it?.o.value ?? 0;
|
|
163
|
+
if (typeof v !== 'number') throw codedError('hud-option', `hud.add('${id}'): this counter shows text (${JSON.stringify(v)}), not a number`, TypeError);
|
|
164
|
+
item('counter', id, it ? { value: v + n } : { label: id, value: n });
|
|
165
|
+
return v + n;
|
|
166
|
+
},
|
|
167
|
+
/** Current value of a counter or bar (a number or text); undefined when there is none. This is also where an interaction's `counter` total is read */
|
|
168
|
+
value(id) { return items.get(id)?.o.value; },
|
|
156
169
|
/** Progress bar (calling again with the same id = update): { value, max = 1, label, anchor } (anchor as for counter) */
|
|
157
170
|
bar(id, o) { item('bar', id, o); },
|
|
158
171
|
/** Remove a counter or bar */
|
package/modules/hud/parts.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Default HUD UI parts (hud.marker, hud.counter, hud.bar). hud/index.js keeps the logic (targets, projection, edge arrows, quest sync)
|
|
2
2
|
// and hands each part plain data; a game replaces any of them with engine.ui.set('hud.counter', ...) or turns it off with false.
|
|
3
|
-
//
|
|
4
|
-
// colors
|
|
5
|
-
// Inner HTML:
|
|
3
|
+
// Picture: CSS classes .threedog-hud .threedog-hud-stats .threedog-hud-marker .threedog-hud-arrow .threedog-hud-counter .threedog-hud-bar;
|
|
4
|
+
// colors follow ui.theme bg / fg / accent unless ui.theme hudBg / hudFg / hudAccent say otherwise; layout is plain CSS, so ui.css moves the stats column, sizes, fonts.
|
|
5
|
+
// Inner HTML: ui.templates.hudMarker / hudCounter / hudBar (data, { esc, t }) => HTML.
|
|
6
6
|
import { esc, placeAt } from '../../ui/UI.js';
|
|
7
7
|
/** @import { Engine, UIPart } from '../../types/core' */
|
|
8
8
|
|
|
@@ -15,10 +15,10 @@ export const CSS = `
|
|
|
15
15
|
.threedog-hud-top-left,.threedog-hud-top,.threedog-hud-top-right{top:var(--hy)}
|
|
16
16
|
.threedog-hud-bottom-left,.threedog-hud-bottom,.threedog-hud-bottom-right{bottom:calc(12px + env(safe-area-inset-bottom,0px))}
|
|
17
17
|
.threedog-hud-left,.threedog-hud-right{top:50%;transform:translateY(-50%)}
|
|
18
|
-
.threedog-hud-counter,.threedog-hud-bar{background:var(--threedog-hud-bg);border-radius:
|
|
18
|
+
.threedog-hud-counter,.threedog-hud-bar{background:var(--threedog-hud-bg);border-radius:var(--threedog-radius-small);padding:4px 10px;min-width:120px}
|
|
19
19
|
.threedog-hud-bar-track{height:6px;border-radius:3px;background:var(--threedog-line);overflow:hidden;margin-top:3px}
|
|
20
20
|
.threedog-hud-bar-fill{height:100%;width:calc(var(--threedog-hud-fill,0) * 100%);background:var(--threedog-hud-accent)}
|
|
21
|
-
.threedog-hud-marker{position:absolute;left:0;top:0;transform:translate(-50%,-100%);display:flex;flex-direction:column;align-items:center;white-space:nowrap;text-shadow:
|
|
21
|
+
.threedog-hud-marker{position:absolute;left:0;top:0;transform:translate(-50%,-100%);display:flex;flex-direction:column;align-items:center;white-space:nowrap;text-shadow:var(--threedog-shadow-small)}
|
|
22
22
|
.threedog-hud-marker::after{content:'';width:10px;height:10px;margin-top:2px;border-radius:50%;background:var(--threedog-hud-accent)}
|
|
23
23
|
.threedog-hud-marker.threedog-hud-arrow{transform:translate(-50%,-50%)}
|
|
24
24
|
.threedog-hud-marker.threedog-hud-arrow::after{width:0;height:0;border-radius:0;border:7px solid transparent;border-left:12px solid var(--threedog-hud-accent);order:-1;transform:rotate(var(--threedog-hud-angle,0rad))}
|
|
@@ -33,7 +33,7 @@ export const CSS = `
|
|
|
33
33
|
*/
|
|
34
34
|
export function defineHudParts(e, root) {
|
|
35
35
|
const tools = { esc, t: (k, p) => e.t(k, p) };
|
|
36
|
-
const tpl = name => e.
|
|
36
|
+
const tpl = name => e.ui.templates[name];
|
|
37
37
|
|
|
38
38
|
// One marker: update({ x, y, arrow, angle, label, icon, distance }) moves and redraws it; hide() hides it
|
|
39
39
|
e.ui.define('hud.marker', () => {
|
|
@@ -46,10 +46,12 @@ export function defineHudParts(e, root) {
|
|
|
46
46
|
el.hidden = false;
|
|
47
47
|
el.classList.toggle('threedog-hud-arrow', d.arrow);
|
|
48
48
|
if (d.arrow) el.style.setProperty('--threedog-hud-angle', d.angle.toFixed(3) + 'rad');
|
|
49
|
-
placeAt(el, d.x, d.y);
|
|
50
49
|
const t = tpl('hudMarker');
|
|
51
50
|
const h = t ? t(d, tools) : `${d.icon || d.label ? `<span class="threedog-hud-label">${esc(d.icon)} ${esc(d.label)}</span>` : ''}${d.distance ? `<span class="threedog-hud-dist">${esc(d.distance)}</span>` : ''}`;
|
|
52
51
|
if (h !== html) { html = h; el.innerHTML = h; } // rebuild only when the text changed (called every frame)
|
|
52
|
+
// An edge arrow is centered on its spot, so a long label would run off the screen: keep the whole marker inside
|
|
53
|
+
const half = d.arrow ? el.offsetWidth / 2 : 0, w = el.parentNode?.clientWidth ?? 0;
|
|
54
|
+
placeAt(el, half && w ? Math.min(Math.max(d.x, half), w - half) : d.x, d.y);
|
|
53
55
|
},
|
|
54
56
|
hide() { el.hidden = true; },
|
|
55
57
|
dispose() { el.remove(); },
|
package/modules/level/index.js
CHANGED
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
// scenes built in code (scene) cannot be saved, loading does not switch level -- to support cross-level loading, register the builder in the assets manifest
|
|
57
57
|
// and use level({ url: name }).
|
|
58
58
|
// Event: level:loaded { root, markers, spawn }
|
|
59
|
-
//
|
|
59
|
+
// Picture: the level module draws nothing itself, the scene looks entirely like your model, so it does not read the style.
|
|
60
60
|
import * as THREE from 'three';
|
|
61
61
|
import { buildHeightfield } from './heightfield.js';
|
|
62
62
|
import { toast } from '../../ui/UI.js';
|
|
@@ -99,7 +99,6 @@ export function level(opts = {}) {
|
|
|
99
99
|
|
|
100
100
|
const api = {
|
|
101
101
|
root: null, markers: {}, spawn: new THREE.Vector3(), heightfield: null,
|
|
102
|
-
get object() { return api.root; }, // same as root (consistent with player.object, ent.object)
|
|
103
102
|
get ready() { return done; },
|
|
104
103
|
/** Register things belonging to the current level ({ remove() } handles); auto-removed on level switch / unload; returns the same handle */
|
|
105
104
|
track(h) { if (h) removers.push(h); return h; },
|
|
@@ -204,8 +203,10 @@ export function level(opts = {}) {
|
|
|
204
203
|
const sp = markers.spawn || Object.values(markers).find(m => /^spawn_/i.test(m.name));
|
|
205
204
|
api.spawn = sp ? sp.position.clone() : new THREE.Vector3(0, hf.height(0, 0), 0);
|
|
206
205
|
pendingColliders = colliders === false ? cols.filter(m => COL_RE.test(m.name) || chainValue(m, root, 'collider')) : cols;
|
|
207
|
-
// rays: all meshes; collision meshes and non-walkable meshes also occlude the camera
|
|
208
|
-
|
|
206
|
+
// rays: all meshes; collision meshes and shown non-walkable meshes also occlude the camera, unless a node says userData.occluder = false (a glass roof, a thin railing).
|
|
207
|
+
// col_ meshes are hidden by design and still block; any other hidden mesh is not on screen, so the arm has nothing to avoid
|
|
208
|
+
const blocks = m => chainValue(m, root, 'occluder') !== false, shownHere = m => !chainHas(m, root, p => !p.visible);
|
|
209
|
+
removers.push(e.rays.addStatic(root), e.rays.addStatic([...cols.filter(blocks), ...meshes.filter(m => !walkSet.has(m) && shownHere(m) && blocks(m))], { occluder: true }));
|
|
209
210
|
trimeshCache = null; version++;
|
|
210
211
|
addColliders();
|
|
211
212
|
}
|
package/modules/lights/index.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// Shadows: none by default; lightPool({ shadows: k }) makes k of the point lights cast, used by sources added with castShadow: true.
|
|
15
15
|
// An idle shadow light (no source, or faded to 0) stops re-rendering its cube shadow map (shadow.autoUpdate = false): six shadow passes a frame for a dark light.
|
|
16
16
|
// When every point light casts (shadows >= point) there are no plain ones, so sources without castShadow also take the shadow lights (they cast then) instead of never lighting.
|
|
17
|
-
// Day / night: a source added with `dusk` (street lamps, shop lights) is scaled by the
|
|
17
|
+
// Day / night: a source added with `dusk` (street lamps, shop lights) is scaled by the daylight curve of engine.uniforms.uNight (render/daylight.js,
|
|
18
18
|
// shared code, not a copy), so its real light, its stand-in and the game's window glow switch on together. Off by default: a torch in a cave, a
|
|
19
19
|
// muzzle flash or a lamp the game wants lit at noon keeps its intensity. Its scaled intensity is what the choice scores, so lamps that are off by
|
|
20
20
|
// day give their lights to sources that are lit.
|
|
@@ -24,7 +24,7 @@ import { warnOnce } from '../../core/validate.js';
|
|
|
24
24
|
import { readParams, keysSchema } from '../../core/params.js';
|
|
25
25
|
import { vec3 } from '../../core/math.js';
|
|
26
26
|
import { codedError, coded } from '../../core/errorHints.js';
|
|
27
|
-
import { DUSK, daylightOf, nightOf } from '../../render/
|
|
27
|
+
import { DUSK, daylightOf, nightOf } from '../../render/daylight.js';
|
|
28
28
|
/** @import { ModuleDef } from '../../types/core' */
|
|
29
29
|
/** @import { LightPool, LightPoolOptions } from '../../types/world' */
|
|
30
30
|
|
|
@@ -64,11 +64,11 @@ const LIGHT_POOL_PARAMS = keysSchema(OPT_KEYS);
|
|
|
64
64
|
export function lightPool(opts = {}) {
|
|
65
65
|
readParams('lightPool', LIGHT_POOL_PARAMS, opts);
|
|
66
66
|
const { point = 8, spot = 0, shadows = 0, every = 0.1, fade = 0.3 } = opts;
|
|
67
|
-
let e = null, timer = Infinity, time = 0, seq = 0, daylight = null;
|
|
67
|
+
let e = null, timer = Infinity, time = 0, seq = 0, daylight = null, cut = false, offCut = null;
|
|
68
68
|
const sources = [], groups = [], tmp = new THREE.Vector3(), at = new THREE.Vector3();
|
|
69
69
|
|
|
70
70
|
const worldPos = (src, out) => src.follow ? out.setFromMatrixPosition(src.follow.matrixWorld) : out.copy(src.pos);
|
|
71
|
-
// 1 for a source that ignores the time of day, else
|
|
71
|
+
// 1 for a source that ignores the time of day, else the night factor (0 by day, 1 at night) for its dusk
|
|
72
72
|
const nightK = src => src.dusk === null ? 1 : nightOf(daylight, src.dusk);
|
|
73
73
|
const litOf = src => src.intensity * nightK(src);
|
|
74
74
|
const setGlow = (src, k) => {
|
|
@@ -147,7 +147,7 @@ export function lightPool(opts = {}) {
|
|
|
147
147
|
for (const k of ['intensity', 'distance', 'decay', 'priority', 'angle', 'penumbra', 'flicker', 'target', 'name']) if (k in o) src[k] = o[k];
|
|
148
148
|
if ('dusk' in o) {
|
|
149
149
|
const d = o.dusk === true ? DUSK : o.dusk === false || o.dusk == null ? null : o.dusk;
|
|
150
|
-
if (d !== null && !(typeof d === 'number' && d >= 0 && d <= 1)) throw codedError('
|
|
150
|
+
if (d !== null && !(typeof d === 'number' && d >= 0 && d <= 1)) throw codedError('lightpool-dusk', STRINGS.dusk.replace('{d}', String(DUSK)) + JSON.stringify(o.dusk), TypeError);
|
|
151
151
|
src.dusk = d;
|
|
152
152
|
}
|
|
153
153
|
if ('glow' in o) { if (src.glow) setGlow(src, 1); src.glow = glowOf(o.glow); setGlow(src, src.slot ? 1 - src.slot.w : 1); }
|
|
@@ -224,7 +224,7 @@ export function lightPool(opts = {}) {
|
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
return {
|
|
227
|
-
name: 'lightPool', type: '
|
|
227
|
+
name: 'lightPool', type: 'picture', params: LIGHT_POOL_PARAMS, options: opts, label: 'Light pool', stage: 'late',
|
|
228
228
|
install(engine) { engine.i18n.add({ 'zh-CN': { 'module.lightPool': '光源池' }, en: { 'module.lightPool': 'light pool' } });
|
|
229
229
|
e = engine;
|
|
230
230
|
const k = Math.max(0, Math.min(shadows, point));
|
|
@@ -233,16 +233,20 @@ export function lightPool(opts = {}) {
|
|
|
233
233
|
makeGroup('point', false, point - k);
|
|
234
234
|
makeGroup('spot', false, spot);
|
|
235
235
|
if (e.ready) warnOnce(STRINGS.late);
|
|
236
|
+
offCut = e.events.on('camera:shot', () => { cut = true; });
|
|
236
237
|
return api;
|
|
237
238
|
},
|
|
238
239
|
frame(dt) {
|
|
239
240
|
time += dt; // presentation seconds for flicker: keeps running while gameplay is frozen, like the picture
|
|
240
241
|
daylight = daylightOf(e);
|
|
241
|
-
if (daylight === null && sources.some(s => s.dusk !== null)) warnOnce(coded('
|
|
242
|
+
if (daylight === null && sources.some(s => s.dusk !== null)) warnOnce(coded('lightpool-dusk', STRINGS.noDay));
|
|
243
|
+
// a camera cut (a view, a fixed shot): no fade, the picture is new anyway. Twice: the first pass frees the slots of sources left behind, the
|
|
244
|
+
// second hands them over. Without it `shot --view` drew the lamps of the old spot, 1/30 s after the cut and 0.3 s before any fade would end
|
|
245
|
+
if (cut) { cut = false; timer = 0; for (let i = 0; i < 2; i++) { assign(); update(fade); } return; }
|
|
242
246
|
if ((timer += dt) >= every) { timer = 0; assign(); }
|
|
243
247
|
update(dt);
|
|
244
248
|
},
|
|
245
|
-
dispose() { for (const L of api.lights) { L.removeFromParent(); L.target?.removeFromParent(); L.dispose(); } },
|
|
249
|
+
dispose() { offCut?.remove(); for (const L of api.lights) { L.removeFromParent(); L.target?.removeFromParent(); L.dispose(); } },
|
|
246
250
|
describe() {
|
|
247
251
|
const u = api.usage();
|
|
248
252
|
return { lights: api.lights.length, lit: u.lit, sources: u.sources, shadows: Math.max(0, Math.min(shadows, point)) };
|
package/modules/music/Music.js
CHANGED
|
@@ -297,7 +297,7 @@ export function music(opts = {}) {
|
|
|
297
297
|
readParams('music', MUSIC_PARAMS, opts);
|
|
298
298
|
let m = null;
|
|
299
299
|
return {
|
|
300
|
-
name: 'music', type: '
|
|
300
|
+
name: 'music', type: 'picture', params: MUSIC_PARAMS, options: opts, label: 'Music', optional: ['dialogue'], stage: 'audio',
|
|
301
301
|
install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.music': '音乐' }, en: { 'module.music': 'music' } });
|
|
302
302
|
m = new Music(e, opts, ctx.track);
|
|
303
303
|
ctx.track(e.events.on('session:end', () => m.stop({ fade: 0 }))); // a playthrough ends: its music stops at once
|
|
@@ -31,29 +31,40 @@
|
|
|
31
31
|
// fog true affected by fog
|
|
32
32
|
// maxPixels 512 largest on-screen size of one particle (pixels), so smoke drifting past the camera does not fill the screen
|
|
33
33
|
//
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
//
|
|
34
|
+
// Pictures: particles({ effects: { name: {...same params...} }, default: {...} }). effects[name] sits under the define() params (what define sets wins),
|
|
35
|
+
// so a game can write only engine.particles.define('leaves', { max: 200 }) and keep color and texture with the rest of its picture. default is the fallback for all effects.
|
|
36
|
+
// A name in effects that the game never define()d is defined on the first emit/attach.
|
|
37
|
+
// Material: each effect's material is a plain three.js material, swapped with fx.material = myMaterial and drawn as given; fx.uniforms are the engine's { value } objects.
|
|
38
38
|
import * as THREE from 'three';
|
|
39
39
|
import { vec3 } from '../../core/math.js';
|
|
40
40
|
import { Effect, NEUTRAL, KEYS } from './effect.js';
|
|
41
41
|
import { warnMissing } from '../../core/validate.js';
|
|
42
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
42
|
+
import { readParams, keysSchema, isOptions } from '../../core/params.js';
|
|
43
|
+
import { codedError } from '../../core/errorHints.js';
|
|
43
44
|
// one schema per public entry (unknown keys throw in dev with did-you-mean). Effect param values come in many shapes (number or [min, max], color), so only key names are checked
|
|
44
45
|
const FX_PARAMS = keysSchema(KEYS);
|
|
46
|
+
const PARTICLES_PARAMS = {
|
|
47
|
+
effects: { type: 'object', optional: true, desc: 'effect params by name: under what define() gives, and defined on the first emit / attach when define() never ran' },
|
|
48
|
+
default: { type: 'object', optional: true, desc: 'params every effect starts from' },
|
|
49
|
+
};
|
|
45
50
|
const EMIT_PARAMS = { count: { type: 'number', default: 10, min: 0, desc: 'particles in this burst' }, overrides: 'any?' }; // overrides: null is allowed (no override)
|
|
46
51
|
const ATTACH_PARAMS = { rate: { type: 'number', optional: true, min: 0, desc: 'particles per second (default: the effect rate)' }, offset: 'any?', overrides: 'any?' };
|
|
47
52
|
const _vs = new THREE.Vector2(); // canvas CSS size (particle point scale follows the canvas height, not the window)
|
|
48
53
|
/** @import { ModuleDef } from '../../types/core' */
|
|
49
54
|
/** @import { Object3D, PositionLike } from '../../types/common' */
|
|
50
|
-
/** @import { ParticleEffect, ParticleEmitter, ParticleOptions } from '../../types/gameplay' */
|
|
55
|
+
/** @import { ParticleEffect, ParticleEmitter, ParticleOptions, ParticlesOptions } from '../../types/gameplay' */
|
|
51
56
|
|
|
52
57
|
/** engine.particles */
|
|
53
58
|
export class Particles {
|
|
54
|
-
/**
|
|
55
|
-
|
|
59
|
+
/**
|
|
60
|
+
* @internal
|
|
61
|
+
* @param {any} engine
|
|
62
|
+
* @param {ParticlesOptions} [opts]
|
|
63
|
+
*/
|
|
64
|
+
constructor(engine, { effects = {}, default: fallback = {} } = {}) {
|
|
56
65
|
/** @internal */ this.engine = engine;
|
|
66
|
+
/** @internal what particles({ effects }) gave */ this._given = effects;
|
|
67
|
+
/** @internal what particles({ default }) gave */ this._fallback = fallback;
|
|
57
68
|
/** Defined effects @type {Map<string, ParticleEffect>} */
|
|
58
69
|
this.effects = new Map();
|
|
59
70
|
/** @internal */ this.emitters = new Set();
|
|
@@ -63,12 +74,12 @@ export class Particles {
|
|
|
63
74
|
/** @internal */ this._e = new THREE.Vector3();
|
|
64
75
|
}
|
|
65
76
|
|
|
66
|
-
/** @internal */
|
|
67
|
-
_styleFor(name) { const s = this.engine.style.particles || {}; return { ...(s.default || {}), ...(s[name] || {}) }; }
|
|
68
|
-
|
|
69
77
|
/**
|
|
70
|
-
* Define an effect (same name replaces it, and emitters attached to it move to the new definition); params sit on top of
|
|
71
|
-
*
|
|
78
|
+
* Define an effect (same name replaces it, and emitters attached to it move to the new definition); params sit on top of particles({ effects,
|
|
79
|
+
* default }). Returns the effect object: .points is its THREE.Points (a Sprite on WebGPURenderer); .material is its plain three.js material (set
|
|
80
|
+
* your own and it is drawn as given, null gives the engine's back); .uniforms are the engine material's { value } objects (uMap, uHasMap, uScale,
|
|
81
|
+
* uMaxPx), which a ShaderMaterial of yours can share. A material of yours lasts until the effect is defined again
|
|
82
|
+
* @example engine.particles.define('sparks', { blending: 'additive' }).material = myMaterial;
|
|
72
83
|
* @param {string} name
|
|
73
84
|
* @param {ParticleOptions} [opts]
|
|
74
85
|
* @returns {ParticleEffect}
|
|
@@ -76,7 +87,7 @@ export class Particles {
|
|
|
76
87
|
define(name, opts = {}) {
|
|
77
88
|
readParams(`particles.define('${name}')`, FX_PARAMS, opts);
|
|
78
89
|
const old = this.effects.get(name);
|
|
79
|
-
const o = { ...NEUTRAL, ...this.
|
|
90
|
+
const o = { ...NEUTRAL, ...this._fallback, ...this._given[name], ...opts };
|
|
80
91
|
const fx = new Effect(this, name, o);
|
|
81
92
|
this.effects.set(name, fx);
|
|
82
93
|
// emitters attached to the old effect keep running on the new one (redefining tunes an effect, it does not stop it)
|
|
@@ -92,8 +103,8 @@ export class Particles {
|
|
|
92
103
|
/** @internal */
|
|
93
104
|
_get(name) {
|
|
94
105
|
let fx = this.effects.get(name);
|
|
95
|
-
if (!fx && this.
|
|
96
|
-
if (!fx) warnMissing('particle', name, [...this.effects.keys(), ...Object.keys(this.
|
|
106
|
+
if (!fx && this._given[name]) fx = this.define(name);
|
|
107
|
+
if (!fx) warnMissing('particle', name, [...new Set([...this.effects.keys(), ...Object.keys(this._given)])]);
|
|
97
108
|
return fx;
|
|
98
109
|
}
|
|
99
110
|
|
|
@@ -167,17 +178,27 @@ export class Particles {
|
|
|
167
178
|
h.object.getWorldQuaternion(this._q);
|
|
168
179
|
h.fx.spawn(p, n, o, o.worldSpace === false ? this._q : null);
|
|
169
180
|
}
|
|
170
|
-
for (const fx of this.effects.values()) { fx.
|
|
181
|
+
for (const fx of this.effects.values()) { fx.uniforms.uScale.value = scale; fx.update(dt); }
|
|
171
182
|
}
|
|
172
183
|
}
|
|
173
184
|
|
|
174
185
|
/**
|
|
175
|
-
* Particles -> engine.particles
|
|
186
|
+
* Particles -> engine.particles. effects: params by name, under what define() gives; a name define() never saw is defined on its first emit / attach.
|
|
187
|
+
* default: params every effect starts from
|
|
188
|
+
* @param {ParticlesOptions} [opts]
|
|
176
189
|
* @returns {ModuleDef<Particles>}
|
|
190
|
+
* @example engine.use(particles({ default: { color: 0xc8b89a }, effects: { dust: { max: 300, size: [0.3, 0.8] } } }));
|
|
177
191
|
*/
|
|
178
|
-
export function particles() {
|
|
192
|
+
export function particles(opts = {}) {
|
|
193
|
+
readParams('particles', PARTICLES_PARAMS, opts);
|
|
194
|
+
// checked here, not on the first emit: a typo in a style table should fail at startup, not in the middle of play
|
|
195
|
+
for (const [name, spec] of Object.entries(opts.effects ?? {})) {
|
|
196
|
+
if (!isOptions(spec)) throw codedError('module-params', `particles({ effects: { ${name} } }): an effect is an object of params, e.g. { max: 200, color: 0xcccccc }; got ${JSON.stringify(spec)}`);
|
|
197
|
+
readParams(`particles({ effects: { ${name} } })`, FX_PARAMS, spec);
|
|
198
|
+
}
|
|
199
|
+
if (opts.default) readParams('particles({ default })', FX_PARAMS, opts.default);
|
|
179
200
|
let p = null;
|
|
180
|
-
return { name: 'particles', type: '
|
|
201
|
+
return { name: 'particles', type: 'picture', provides: ['particles'], label: 'Particles', params: PARTICLES_PARAMS, options: opts, stage: 'effects', install(e) { e.i18n.add({ 'zh-CN': { 'module.particles': '粒子' }, en: { 'module.particles': 'particles' } }); p = new Particles(e, opts); return p; }, frame(dt) { p.update(dt); },
|
|
181
202
|
counts() { return { alive: p.count(), emitters: p.emitters.size }; }, // engine.counts().particles
|
|
182
203
|
// "did the dust burst fire": live particles in total and per effect that has any (idle effects left out to stay short). Kept under `alive`
|
|
183
204
|
// because the numbers change every frame (an emitter's smoke): state comparisons (the session spec) skip that key as presentation, not game state
|