threedog 0.7.0 → 1.0.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 +411 -1
- package/README.md +8 -11
- package/core/{Animator.js → assets/Animator.js} +30 -18
- package/core/{Assets.js → assets/Assets.js} +131 -56
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +302 -0
- package/core/{assetHot.js → assets/assetHot.js} +9 -7
- package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
- package/core/{assetReport.js → assets/assetReport.js} +7 -14
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +47 -25
- package/core/{audioRules.js → audio/audioRules.js} +8 -5
- package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
- package/core/{Events.js → base/Events.js} +3 -3
- package/core/{I18n.js → base/I18n.js} +15 -12
- package/core/{Random.js → base/Random.js} +7 -4
- package/core/{Vars.js → base/Vars.js} +14 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +151 -125
- package/core/{errorHints.js → base/errorHints.js} +17 -10
- package/core/{errors.js → base/errors.js} +12 -10
- package/core/{events.generated.js → base/events.generated.js} +11 -0
- package/core/base/follows.js +26 -0
- package/core/base/math.js +66 -0
- package/core/{params.js → base/params.js} +5 -6
- package/core/base/saveValues.js +81 -0
- package/core/base/sections.js +97 -0
- package/core/base/spelling.js +32 -0
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +34 -34
- package/core/{Engine.js → engine/Engine.js} +137 -91
- package/core/{Loading.js → engine/Loading.js} +34 -5
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +32 -15
- package/core/{lifecycle.js → engine/lifecycle.js} +41 -34
- package/core/{loop.js → engine/loop.js} +88 -49
- package/core/engine/moduleSlots.js +176 -0
- package/core/{moduleTypes.js → engine/moduleTypes.js} +26 -14
- package/core/engine/modules.js +503 -0
- package/core/{page.js → engine/page.js} +59 -29
- package/core/{plugins.js → engine/plugins.js} +21 -12
- package/core/{services.js → engine/services.js} +50 -40
- package/core/{startup.js → engine/startup.js} +66 -54
- package/core/{Input.js → input/Input.js} +67 -39
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/input/inputKeyboard.js +39 -0
- package/core/{inputPad.js → input/inputPad.js} +24 -3
- package/core/{inputPointer.js → input/inputPointer.js} +11 -3
- package/core/input/inputSeat.js +66 -0
- package/core/{inputTouch.js → input/inputTouch.js} +24 -7
- package/core/{Budget.js → inspect/Budget.js} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +43 -18
- package/core/{Describe.js → inspect/Describe.js} +34 -26
- package/core/{Inspect.js → inspect/Inspect.js} +39 -10
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
- package/core/{UrlState.js → inspect/UrlState.js} +60 -24
- package/core/{catalog.js → inspect/catalog.js} +15 -8
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +4 -4
- package/core/{describeRender.js → inspect/describeRender.js} +24 -22
- package/core/{describeText.js → inspect/describeText.js} +17 -8
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/inspect/metadata.generated.js +4140 -0
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +130 -47
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/inspect/toolDoor.js +21 -0
- package/core/inspect/valueHistory.js +35 -0
- package/core/{Ops.js → ops/Ops.js} +44 -14
- package/core/{control.js → ops/control.js} +57 -31
- package/core/ops/holds.js +140 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +18 -5
- package/core/{opsCheck.js → ops/opsCheck.js} +11 -10
- package/core/{opsFail.js → ops/opsFail.js} +5 -7
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +9 -6
- package/core/{owned.js → ops/owned.js} +33 -19
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -16
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +34 -15
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +53 -27
- package/core/{Saves.js → saves/Saves.js} +171 -54
- package/core/saves/saveApply.js +312 -0
- package/core/{saveFiles.js → saves/saveFiles.js} +45 -38
- package/core/{saveVersions.js → saves/saveVersions.js} +24 -23
- package/core/saves/session.js +231 -0
- package/core/saves/stateReplace.js +184 -0
- package/core/{Rays.js → scene/Rays.js} +44 -30
- package/core/{Views.js → scene/Views.js} +16 -8
- package/core/{adaptive.js → scene/adaptive.js} +19 -9
- package/core/{canvasBox.js → scene/canvasBox.js} +4 -3
- package/core/scene/compositeGround.js +72 -0
- package/core/scene/floor.js +17 -0
- package/core/{gameLights.js → scene/gameLights.js} +17 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +6 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/scene/ground.contract.js +14 -0
- package/core/scene/ground.js +139 -0
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/scene/pixel.js +154 -0
- package/core/scene/pixelRatio.js +167 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +5 -5
- package/core/{sceneMethods.js → scene/sceneMethods.js} +43 -15
- package/core/scene/stepPoses.js +60 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
- package/core/{thingOps.js → scene/thingOps.js} +25 -16
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +10 -0
- package/core/scene/view.js +161 -0
- package/core/{Batching.js → stream/Batching.js} +85 -28
- package/core/{Stream.js → stream/Stream.js} +80 -38
- package/core/{batchGroups.js → stream/batchGroups.js} +11 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- package/core/{scatter.js → stream/scatter.js} +7 -4
- package/core/{streamSources.js → stream/streamSources.js} +14 -8
- package/core/{Commits.js → threads/Commits.js} +17 -11
- package/core/{Jobs.js → threads/Jobs.js} +25 -13
- package/core/{Threads.js → threads/Threads.js} +21 -18
- package/core/{threadPure.js → threads/threadPure.js} +7 -5
- package/core/{threadServe.js → threads/threadServe.js} +3 -3
- package/core/{Clock.js → time/Clock.js} +20 -11
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +28 -21
- package/core/{time.js → time/time.js} +32 -20
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +92 -72
- package/docs/API.md +33 -28
- package/docs/CODEMAP.md +121 -200
- package/docs/COMMANDS.md +77 -70
- package/docs/CONVENTIONS.md +167 -24
- package/docs/MIGRATING-0.8.md +171 -0
- package/docs/MIGRATING-1.0.md +101 -0
- package/docs/THREE.md +140 -38
- package/docs/api/assets.md +12 -13
- package/docs/api/audio.md +6 -5
- package/docs/api/budget.md +4 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +32 -29
- package/docs/api/characters.md +35 -24
- package/docs/api/clock.md +1 -1
- package/docs/api/collider3d.md +9 -0
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +18 -17
- package/docs/api/dialogue.md +5 -4
- package/docs/api/engine.md +58 -54
- package/docs/api/events.md +17 -6
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +6 -7
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +9 -8
- package/docs/api/interactions.md +5 -5
- package/docs/api/inventory.md +10 -10
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +10 -9
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +14 -12
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +10 -7
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +3 -3
- package/docs/api/post.md +21 -5
- package/docs/api/quests.md +7 -5
- package/docs/api/rays.md +7 -7
- package/docs/api/rigid.md +29 -19
- package/docs/api/saves.md +13 -11
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +8 -7
- package/docs/api/stream.md +8 -9
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +6 -8
- package/docs/api/terrainDraw.md +2 -2
- package/docs/api/timeline.md +4 -4
- package/docs/api/tools.md +27 -22
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +2 -2
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +27 -12
- package/docs/api/weatherDraw.md +4 -4
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +28 -43
- package/docs/recipes/02-npc.md +21 -23
- package/docs/recipes/03-items-pickups.md +37 -53
- package/docs/recipes/04-quests.md +5 -4
- package/docs/recipes/05-props-bake.md +34 -44
- package/docs/recipes/06-clock-events.md +31 -22
- package/docs/recipes/07-flow-scenes-pause.md +30 -32
- package/docs/recipes/08-weather-sky.md +91 -37
- package/docs/recipes/09-materials-lights-models.md +25 -39
- package/docs/recipes/10-blender-level.md +22 -11
- package/docs/recipes/11-vehicles.md +44 -24
- package/docs/recipes/12-navmesh.md +60 -15
- package/docs/recipes/13-animation.md +70 -22
- package/docs/recipes/14-custom-module.md +33 -20
- package/docs/recipes/15-perf.md +51 -28
- package/docs/recipes/16-dev-bridge.md +39 -58
- package/docs/recipes/18-world.md +49 -28
- package/docs/recipes/19-shooting-picking.md +7 -4
- package/docs/recipes/20-content-actions-save.md +55 -40
- package/docs/recipes/21-camera.md +47 -25
- package/docs/recipes/22-shop-gold.md +21 -16
- package/docs/recipes/23-ops.md +28 -24
- package/docs/recipes/26-ui-parts.md +25 -14
- package/docs/recipes/27-net.md +3 -5
- package/docs/recipes/28-terrain.md +119 -23
- package/docs/recipes/29-grid.md +3 -3
- package/docs/recipes/30-templates.md +63 -30
- package/docs/recipes/31-audio.md +7 -7
- package/docs/recipes/32-action-game.md +21 -11
- package/docs/recipes/33-stream-sources.md +6 -3
- package/docs/recipes/34-environment-lighting.md +72 -25
- package/docs/recipes/35-picture-from-reference.md +20 -23
- package/docs/recipes/36-ground-plants.md +106 -0
- package/docs/recipes/40-scene.md +18 -21
- package/docs/recipes/43-shader-patches-surfaces.md +27 -48
- package/docs/recipes/44-water-weather-hooks.md +56 -50
- package/docs/recipes/45-cascaded-shadows.md +41 -20
- package/docs/recipes/46-blender-art-route.md +9 -10
- package/docs/recipes/49-game-module-contract.md +7 -6
- package/docs/recipes/50-own-renderer.md +3 -2
- package/docs/recipes/51-capability-catalog.md +14 -8
- package/docs/recipes/52-around-the-picture.md +56 -100
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +17 -20
- package/docs/recipes/56-webgpu-tsl.md +28 -15
- package/docs/recipes/57-control.md +39 -12
- package/docs/recipes/58-input.md +15 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +30 -25
- package/docs/recipes/62-picture-code.md +129 -39
- package/docs/recipes/63-third-person-start.md +19 -5
- package/docs/recipes/64-particles.md +54 -5
- package/docs/recipes/65-swarm.md +140 -0
- package/docs/recipes/66-common-tasks.md +313 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +5 -5
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +15 -14
- package/examples/{sheepisland → perf-island}/assets.js +1 -1
- package/examples/{sheepisland → perf-island}/main.js +8 -8
- package/examples/{sheepisland → perf-island}/models.js +1 -1
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/GAMEMAP.md +4 -1
- package/examples/rc2d/GAMEMAP.md +4 -3
- package/examples/rc2d/main.js +1 -3
- package/examples/rc2d/rc2d.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +6 -5
- package/examples/techniques/contact-shadows/contactShadows.js +1 -1
- package/examples/techniques/contact-shadows/main.js +1 -1
- package/examples/techniques/interior-light/main.js +1 -1
- package/examples/techniques/modular-building/README.md +7 -6
- package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/webgpu-tsl/GAMEMAP.md +2 -1
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +9 -7
- package/examples/world/main.js +3 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +16 -12
- package/index.js +53 -32
- package/llms.txt +11 -14
- package/modules/ambience/Ambience.js +16 -11
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +18 -16
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +5 -5
- package/modules/camera/FixedCamera.js +43 -30
- package/modules/camera/FollowCamera.js +24 -15
- package/modules/camera/RtsCamera.js +12 -11
- package/modules/camera/common.js +72 -37
- package/modules/camera/contract.js +1 -0
- package/modules/camera/pixelSnap.js +62 -0
- package/modules/characters/Character.js +166 -70
- package/modules/characters/NPC.js +84 -44
- package/modules/characters/assetModel.js +16 -12
- package/modules/characters/astar.js +48 -27
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/character.contract.js +21 -0
- package/modules/characters/contract.js +17 -3
- package/modules/characters/index.js +240 -226
- package/modules/characters/moveHelpers.js +88 -12
- package/modules/characters/mover.contract.js +14 -0
- package/modules/characters/movers/common.js +22 -18
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +18 -10
- package/modules/characters/movers/simple.js +26 -13
- package/modules/characters/movers/support.js +24 -13
- package/modules/characters/npcAvoid.js +19 -16
- package/modules/characters/npcSim.js +88 -32
- package/modules/characters/npcView.js +19 -11
- package/modules/characters/pathAsync.js +81 -29
- package/modules/characters/pathJob.js +38 -21
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +120 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +2 -2
- package/modules/characters/seat.js +56 -0
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/vehicle.contract.js +8 -5
- package/modules/characters/walkTo.js +40 -33
- package/modules/collision/Collision.js +69 -45
- package/modules/collision/contract.js +15 -0
- package/modules/collision/grid.js +6 -1
- package/modules/content/explain.js +2 -3
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +5 -3
- package/modules/content/index.js +132 -114
- package/modules/content/loader.js +117 -140
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +54 -17
- package/modules/content/packs.js +5 -4
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +36 -0
- package/modules/content/props.js +22 -17
- package/modules/content/rules.js +47 -61
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +80 -49
- package/modules/content/words.js +47 -0
- package/modules/debug/DebugPanel.js +14 -45
- package/modules/flow/contract.js +2 -1
- package/modules/flow/index.js +30 -16
- package/modules/gameplay/Container.js +17 -13
- package/modules/gameplay/Containers.js +23 -6
- package/modules/gameplay/Dialogue.js +93 -34
- package/modules/gameplay/Interactions.js +93 -51
- package/modules/gameplay/Inventory.js +64 -22
- package/modules/gameplay/Quests.js +146 -30
- package/modules/gameplay/boxOps.js +8 -1
- package/modules/gameplay/dialogueBubbles.js +16 -12
- package/modules/gameplay/inventoryOps.js +11 -8
- package/modules/gameplay/pickups.js +63 -37
- package/modules/gameplay/questLog.js +4 -2
- package/modules/gameplay/questSave.js +9 -4
- package/modules/gameplay/quests.contract.js +1 -1
- package/modules/grid/Grid.js +2 -2
- package/modules/grid/Layer.js +12 -8
- package/modules/grid/index.js +28 -23
- package/modules/grid/ops.js +43 -46
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +42 -57
- package/modules/hud/index.js +22 -14
- package/modules/hud/parts.js +8 -8
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +29 -31
- package/modules/level/index.js +113 -161
- package/modules/level/load.js +196 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +40 -23
- package/modules/lights/index.js +33 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +90 -0
- package/modules/music/Music.js +34 -28
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +16 -0
- package/modules/nav/index.js +180 -49
- package/modules/nav/navPath.js +45 -10
- package/modules/net/Client.js +7 -7
- package/modules/net/Host.js +7 -7
- package/modules/net/Net.js +1 -1
- package/modules/net/index.js +6 -5
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +95 -29
- package/modules/particles/effect.js +86 -32
- package/modules/particles/shaders.js +19 -1
- package/modules/photo/Photo.js +23 -23
- package/modules/rigid/RigidBodies.js +255 -89
- package/modules/rigid/Vehicles.js +17 -8
- package/modules/rigid/collider3d.contract.js +26 -0
- package/modules/rigid/ragdoll.js +298 -0
- package/modules/rigid/ragdollBones.js +209 -0
- package/modules/rigid/refresh.js +10 -0
- package/modules/rigid/sync.js +51 -20
- package/modules/settings/Settings.js +177 -61
- package/modules/settings/apply.js +20 -13
- package/modules/settings/sections.js +19 -14
- package/modules/settings/strings.js +2 -2
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +29 -22
- package/modules/sky/clouds.js +7 -7
- package/modules/sky/dome.js +33 -20
- package/modules/sky/domeLayers.js +9 -9
- package/modules/sky/environment.js +6 -6
- package/modules/sky/frame.js +19 -10
- package/modules/sky/season.js +7 -1
- package/modules/sky/shader.js +24 -25
- package/modules/sky/skyModule.js +17 -28
- package/modules/sky/tint.js +1 -1
- package/modules/swarm/Swarm.js +356 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +71 -59
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +14 -11
- package/modules/terrain/index.js +42 -42
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +45 -29
- package/modules/terrain/terrainGen.js +19 -12
- package/modules/terrain/terrainIsland.js +2 -2
- package/modules/terrain/terrainMesh.js +7 -6
- package/modules/terrain/terrainShape.js +8 -10
- package/modules/terrain/terrainShapeMain.js +3 -3
- package/modules/timeline/Timeline.js +83 -43
- package/modules/timeline/Tween.js +25 -19
- package/modules/timeline/shots.js +24 -17
- package/modules/triggers/index.js +95 -28
- package/modules/vegetation/Vegetation.js +34 -26
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +39 -18
- package/modules/vegetation/groundChunks.js +21 -38
- package/modules/vegetation/index.js +37 -12
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +20 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +52 -40
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +28 -23
- package/modules/world/World.js +28 -15
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +30 -17
- package/modules/world/persist.js +90 -27
- package/modules/world/pos.js +5 -5
- package/modules/world/records.js +37 -11
- package/modules/world/sim.js +78 -27
- package/modules/world/simFar.js +2 -2
- package/modules/world/state.js +43 -11
- package/modules/world/thingSource.js +20 -5
- package/modules/world/views.js +27 -14
- package/package.json +48 -7
- package/presets.js +1 -3
- package/render/PostFX.js +83 -53
- package/render/backend.js +31 -33
- package/render/cascades.js +17 -12
- package/render/cascades.tsl.js +5 -8
- package/render/daylight.js +20 -3
- package/render/detail.js +8 -7
- package/render/effects.js +28 -25
- package/render/fuse.js +3 -3
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +5 -10
- package/render/fx/library.tsl.js +11 -0
- package/render/fx/lighting.tsl.js +2 -1
- package/render/fx/nodeErrors.tsl.js +2 -2
- package/render/fx/objectOrigin.tsl.js +1 -2
- package/render/fx/particles.tsl.js +8 -6
- package/render/fx/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +30 -26
- package/render/fx/sky.tsl.js +15 -17
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +2 -2
- package/render/lighting.js +5 -3
- package/render/lightmap.js +41 -21
- package/render/lights.js +6 -6
- package/render/lit.js +24 -0
- package/render/materials.js +8 -7
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/occlusion.js +62 -15
- package/render/ownFrame.js +4 -4
- package/render/patches.js +15 -15
- package/render/postWebGL.js +15 -12
- package/render/probes.js +41 -19
- package/render/recordSweep.js +117 -0
- package/render/shaderErrors.js +10 -9
- package/render/shadowCache.tsl.js +107 -0
- package/render/shadowTypes.js +9 -0
- package/{core → render}/shadows.js +59 -13
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +336 -202
- package/types/gameplay.d.ts +254 -130
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
- package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
- package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
- package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +8 -16
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +28 -10
- package/types/generated/core/input/inputSeat.d.ts +26 -0
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +17 -3
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +6 -4
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +14 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +62 -18
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +3 -2
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +2 -2
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +22 -18
- package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
- package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
- package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
- package/types/generated/modules/calendar/Calendar.d.ts +10 -11
- package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
- package/types/generated/modules/grid/Grid.d.ts +1 -0
- package/types/generated/modules/grid/Layer.d.ts +1 -1
- package/types/generated/modules/grid/index.d.ts +3 -3
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +5 -4
- package/types/generated/modules/sky/Sky.d.ts +21 -10
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +7 -5
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +14 -16
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +11 -7
- package/types/generated/render/PostFX.d.ts +21 -23
- package/types/generated/render/materials.d.ts +1 -0
- package/types/generated/render/occlusion.d.ts +9 -0
- package/types/generated/render/patches.d.ts +1 -0
- package/types/generated/ui/Focus.d.ts +1 -0
- package/types/generated/ui/UI.d.ts +1 -0
- package/types/nav.d.ts +47 -15
- package/types/physics.d.ts +150 -73
- package/types/pixel.d.ts +75 -0
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +48 -75
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +13 -5
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +7 -5
- package/core/assetEntry.js +0 -109
- package/core/engineCamera.js +0 -32
- package/core/ground.js +0 -104
- package/core/holds.js +0 -134
- package/core/math.js +0 -48
- package/core/moduleSlots.js +0 -100
- package/core/modules.js +0 -314
- package/core/saveApply.js +0 -210
- package/core/saveValues.js +0 -46
- package/core/session.js +0 -174
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- package/core/view.js +0 -43
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -320
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/MIGRATING-0.6.md +0 -126
- package/docs/PERF.md +0 -245
- package/docs/recipes/36-sky-ground-plants.md +0 -158
- package/docs/recipes/37-terrain-hooks.md +0 -115
- package/docs/recipes/38-environment-hooks.md +0 -67
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/47-island-snow-backdrop.md +0 -43
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/plain-picture/FINDINGS.md +0 -53
- package/examples/sheepisland/.threedog/content-index.json +0 -1
- package/modules/camera/projection.js +0 -21
- /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
- /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
- /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
- /package/core/{actor.js → ops/actor.js} +0 -0
- /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
- /package/core/{saveIds.js → saves/saveIds.js} +0 -0
- /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
- /package/core/{cells.js → stream/cells.js} +0 -0
- /package/core/{streamCells.js → stream/streamCells.js} +0 -0
- /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
- /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
// Vegetation on any ground (no terrain module): a level model, a code-built ground, the flat default. Chunks of the same shape as the terrain's
|
|
2
2
|
// ({ cx, cz, state, plants, colliders, ring, inView, ... }), streamed around every engine.stream source, placed by the same rule code
|
|
3
|
-
// (core/scatter.js) over engine.surface / slope / groundType -- whoever provides the ground. Data only: the vegetation drawing draws c.plants.
|
|
3
|
+
// (core/stream/scatter.js) over engine.surface / slope / groundType -- whoever provides the ground. Data only: the vegetation drawing draws c.plants.
|
|
4
4
|
//
|
|
5
5
|
// Why the main thread and not a worker: a ground provider is arbitrary main-thread code (a level heightfield, a game's closure), not
|
|
6
6
|
// serializable data like a terrain generator. Placement is cheap (a few height lookups per attempt) and runs under a per-frame budget.
|
|
7
7
|
// Collision circles take effect at the tick engine.commits sets (lag by ring, built on the spot if still pending): machine speed never
|
|
8
8
|
// changes whether the player bumps into a tree, the same contract as terrain chunks.
|
|
9
9
|
// The ground changing (setGround, a level loaded or switched: ground.staticVersion) rebuilds every chunk.
|
|
10
|
+
import { follows } from '../../core/base/follows.js';
|
|
10
11
|
import * as THREE from 'three';
|
|
11
|
-
import { makePlacer, makeNoise } from '../../core/scatter.js';
|
|
12
|
-
import {
|
|
13
|
-
import { ChunkStream } from '../../core/chunkStream.js';
|
|
12
|
+
import { makePlacer, makeNoise } from '../../core/stream/scatter.js';
|
|
13
|
+
import { ChunkStream, bookCollision, collidersNear, ringsReady } from '../../core/stream/chunkStream.js';
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
export const GROUND_DEFAULTS = { chunkSize: 32, viewChunks: 3, density: 1, seed: 1 }; // shown by engine.catalog too
|
|
16
16
|
|
|
17
17
|
export class GroundChunks {
|
|
18
18
|
/** opts: chunkSize (m), viewChunks (rings drawn), density, area { min: [x, z], max: [x, z] } or null (a level's walkable bounds when a level provides the ground, else unbounded), seed */
|
|
19
|
-
constructor(engine, veg,
|
|
19
|
+
constructor(engine, veg, opts = {}) {
|
|
20
|
+
const { chunkSize, viewChunks, density, seed, area = null } = { ...GROUND_DEFAULTS, ...opts };
|
|
20
21
|
this.engine = engine; this.veg = veg;
|
|
21
|
-
this.chunkSize = chunkSize; this.
|
|
22
|
+
this.chunkSize = chunkSize; this._viewChunks = viewChunks; this._density = density; this.area = area; this.seed = seed;
|
|
22
23
|
this.chunks = new Map();
|
|
23
24
|
this.applyBudgetMs = 3; // max ms per frame spent placing and uploading chunks once playing (loading builds ring 1 at once)
|
|
24
25
|
this.gen = 0;
|
|
25
26
|
this.stats = { loaded: 0, visible: 0, instances: 0, queued: 0 };
|
|
26
|
-
this._want = []; this._ground =
|
|
27
|
-
// which chunks the sources need, ring, culling: the same helper as the terrain chunks (core/chunkStream.js), so both rings mean the same
|
|
27
|
+
this._want = []; this._ground = follows(() => engine.ground, G => G.staticVersion?.());
|
|
28
|
+
// which chunks the sources need, ring, culling: the same helper as the terrain chunks (core/stream/chunkStream.js), so both rings mean the same
|
|
28
29
|
this._stream = new ChunkStream(this, { show: (c, v) => this.veg._emit('show', c, v), level: (c, ring) => this._setLevel(c, ring),
|
|
29
30
|
count: (c, ring) => { let n = 0; for (const k in c.plants) { const sp = this.veg.get(k); if (sp && ring <= sp.maxRing) n += c.plants[k].n; } return n; },
|
|
30
31
|
inArea: (cx, cz) => this._inArea(cx, cz) });
|
|
@@ -33,7 +34,6 @@ export class GroundChunks {
|
|
|
33
34
|
surface: (x, z) => e.surface(x, z), slope: (x, z) => e.slope(x, z), typeAt: (x, z) => e.groundType(x, z) });
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
get CHUNK() { return this.chunkSize; }
|
|
37
37
|
/**
|
|
38
38
|
* @internal vegetation plumbing: a species was added or defined again. Only its plants are placed again on the loaded chunks; the other
|
|
39
39
|
* species and their collision stay (dropping every chunk left the whole map without trees and tree collision until rebuilt)
|
|
@@ -50,7 +50,8 @@ export class GroundChunks {
|
|
|
50
50
|
/** @internal vegetation / settings plumbing */
|
|
51
51
|
refreshLevels() { for (const c of this.chunks.values()) c.level = -1; }
|
|
52
52
|
/** Rings of chunks drawn around each stream source (the settings page's view distance); the next update loads / releases chunks to match */
|
|
53
|
-
|
|
53
|
+
get viewChunks() { return this._viewChunks; }
|
|
54
|
+
set viewChunks(n) { this._viewChunks = n; this.refreshLevels(); }
|
|
54
55
|
/** Drop every chunk; they are placed again around the stream sources (call it after changing the ground behind the same provider) */
|
|
55
56
|
rebuild() {
|
|
56
57
|
this._stream.drop();
|
|
@@ -60,8 +61,9 @@ export class GroundChunks {
|
|
|
60
61
|
* Vegetation density multiplier: the loaded chunks are placed again in place, each species replacing its own plants and collision circles,
|
|
61
62
|
* so trees never go missing in between (dropping the chunks left them without collision until rebuilt)
|
|
62
63
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
get density() { return this._density; }
|
|
65
|
+
set density(d) {
|
|
66
|
+
this._density = d;
|
|
65
67
|
for (const c of this.chunks.values()) if (c.state === 'ready') for (const sp of this.veg.list()) if (!sp.nearOnly || c.plants[sp.name]) this._grow(c, sp);
|
|
66
68
|
}
|
|
67
69
|
|
|
@@ -78,8 +80,8 @@ export class GroundChunks {
|
|
|
78
80
|
|
|
79
81
|
/** @internal module frame hook: follow the ground, queue / release chunks around the sources, build within budget, LOD and culling */
|
|
80
82
|
update(sources, camera) {
|
|
81
|
-
const e = this.engine
|
|
82
|
-
|
|
83
|
+
const e = this.engine;
|
|
84
|
+
this._ground.sync(() => this.rebuild());
|
|
83
85
|
this._stream.follow(sources, this.chunkSize, this.viewChunks); // queue what a source needs, release what is far from all
|
|
84
86
|
const t0 = performance.now(), loading = !e.ready; // measure: placement budget
|
|
85
87
|
while (this._want.length) {
|
|
@@ -96,11 +98,9 @@ export class GroundChunks {
|
|
|
96
98
|
_queue(cx, cz, key) {
|
|
97
99
|
const c = { cx, cz, key, state: 'queued', plants: {}, colliders: {}, collidersAll: {}, inView: true, level: -1, sphere: null, solid: false, gen: this.gen };
|
|
98
100
|
this.chunks.set(key, c);
|
|
99
|
-
c
|
|
100
|
-
lag: !this.engine.ready && this._ring(c) <= 1 ? 0 : COLLIDER_LAG * (1 + this._ring(c)),
|
|
101
|
+
bookCollision(this, c, this._ring(c), {
|
|
101
102
|
apply: () => { c.solid = true; },
|
|
102
103
|
fallback: () => { if (c.state !== 'ready') this._build(c); return true; }, // due before the budget got to it: place it now, same result
|
|
103
|
-
valid: () => this.chunks.get(c.key) === c && c.gen === this.gen,
|
|
104
104
|
});
|
|
105
105
|
return c;
|
|
106
106
|
}
|
|
@@ -145,27 +145,10 @@ export class GroundChunks {
|
|
|
145
145
|
dispose() { this.rebuild(); }
|
|
146
146
|
|
|
147
147
|
/** @internal Collision circles of solid chunks near (x, z): fn(x, z, r). Joined into engine.ground.forEachCollider (collision, path planning) */
|
|
148
|
-
forEachCollider(x, z, range, fn) {
|
|
149
|
-
const CH = this.chunkSize;
|
|
150
|
-
for (let cz = Math.floor((z - range) / CH); cz <= Math.floor((z + range) / CH); cz++)
|
|
151
|
-
for (let cx = Math.floor((x - range) / CH); cx <= Math.floor((x + range) / CH); cx++) {
|
|
152
|
-
const c = this.chunks.get(cx + ',' + cz);
|
|
153
|
-
if (!c?.solid) continue;
|
|
154
|
-
for (const n in c.colliders) {
|
|
155
|
-
const k = c.colliders[n];
|
|
156
|
-
for (let i = 0; i < k.length; i += 3) { const dx = k[i] - x, dz = k[i + 1] - z, rr = range + k[i + 2]; if (dx * dx + dz * dz < rr * rr) fn(k[i], k[i + 1], k[i + 2]); }
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
148
|
+
forEachCollider(x, z, range, fn) { collidersNear(this.chunks, this.chunkSize, x, z, range, fn); }
|
|
160
149
|
|
|
161
150
|
/** Whether chunks within `rings` (default 1) of a position are placed (loading screen / stream ready check) */
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
for (let dz = -rings; dz <= rings; dz++) for (let dx = -rings; dx <= rings; dx++) {
|
|
165
|
-
if (!this._inArea(pcx + dx, pcz + dz)) continue;
|
|
166
|
-
const c = this.chunks.get((pcx + dx) + ',' + (pcz + dz));
|
|
167
|
-
if (!c || c.state !== 'ready') return false;
|
|
168
|
-
}
|
|
169
|
-
return true;
|
|
151
|
+
readyAt(position, { rings = 1 } = {}) {
|
|
152
|
+
return ringsReady(this.chunks, this.chunkSize, position, rings, (c, cx, cz) => !this._inArea(cx, cz) || c?.state === 'ready');
|
|
170
153
|
}
|
|
171
154
|
}
|
|
@@ -2,20 +2,40 @@
|
|
|
2
2
|
// felled trees; Vegetation.js) and 'vegetationDraw' (instanced meshes, wind, fade, LOD; draw.js, slot 'vegetation-draw').
|
|
3
3
|
// Why two: collision, paths and felling read only the data, so engine.use(myPlants, { replaces: 'vegetation-draw' }) swaps every pixel
|
|
4
4
|
// of the plants and keeps all of play.
|
|
5
|
-
import {
|
|
5
|
+
import { vegetationModel } from '../../core/assets/namedModel.js';
|
|
6
|
+
import { reportError } from '../../core/base/errors.js';
|
|
7
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
6
8
|
import { Vegetation } from './Vegetation.js';
|
|
7
9
|
import { VegetationDraw } from './draw.js';
|
|
8
|
-
import {
|
|
10
|
+
import { GROUND_DEFAULTS } from './groundChunks.js';
|
|
11
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
9
12
|
|
|
10
13
|
const OPTS = ['chunkSize', 'viewChunks', 'density', 'area', 'seed'];
|
|
11
|
-
const VEG_PARAMS = keysSchema(OPTS,
|
|
14
|
+
const VEG_PARAMS = keysSchema(OPTS, GROUND_DEFAULTS); // defaults of the own-chunks mode (without terrain)
|
|
15
|
+
/**
|
|
16
|
+
* The vegetation section of content data: model names resolve through vegetationModel, the same resolver vegetation.define uses for a name. All kinds register at
|
|
17
|
+
* the same moment once all models are ready, since each registration rebuilds terrain chunks. One model that fails does not stop the others.
|
|
18
|
+
* The models are made in commit, not prepare: nothing stands on vegetation, so the rest of a pack does not wait for them
|
|
19
|
+
*/
|
|
20
|
+
const VEGETATION_CONTENT = {
|
|
21
|
+
desc: 'vegetation (name -> model, growth rule)',
|
|
22
|
+
// taken back while its models were still generating. On what this load prepared, not on the table: the same table loaded again is a new load
|
|
23
|
+
prepare: table => ({ table, undone: false }),
|
|
24
|
+
undo: load => () => { load.undone = true; },
|
|
25
|
+
commit: (load, { engine: e }) => Promise.all(Object.entries(load.table).map(([name, { model: m, lod, ...rest }]) =>
|
|
26
|
+
Promise.all([vegetationModel(e, m), lod && vegetationModel(e, lod)])
|
|
27
|
+
.then(([main, low]) => [name, { ...rest, ...main, ...(low && { lodGeometry: low.model ?? low.geometry }) }])
|
|
28
|
+
.catch(err => { reportError(e, err, `content vegetation ${name}: model generation`, { soft: true }); return null; })))
|
|
29
|
+
.then(list => { if (!load.undone) for (const v of list) if (v) e.vegetation.define(v[0], v[1]); }),
|
|
30
|
+
};
|
|
31
|
+
|
|
12
32
|
/**
|
|
13
33
|
* Vegetation module. Provides engine.vegetation.define(name, {...}) once installed.
|
|
14
34
|
* With terrain() installed first it grows on the terrain chunks and takes no options (density and view distance are terrain options).
|
|
15
35
|
* Without terrain it grows on its own chunks over whatever provides the ground: a level model (engine.level), a code-built ground
|
|
16
36
|
* (engine.setGround), or the flat default. Rules read engine.surface / slope / groundType, so a level's named surfaces are picked with
|
|
17
37
|
* rule.biomes (a level's ground type is the mesh's groundType property or its material name).
|
|
18
|
-
* Where a species grows is one
|
|
38
|
+
* Where a species grows is one define() call with up to three parts: rule (random scatter), positions (the game's own spots, instead of the
|
|
19
39
|
* scatter) and densityMap (thins either by a function or a gray image). A game that wants full control still builds its own InstancedMesh.
|
|
20
40
|
* @param {{ chunkSize?: number, viewChunks?: number, density?: number, area?: { min: number[], max: number[] }, seed?: number }} [opts]
|
|
21
41
|
* only without terrain: chunkSize meters (default 32), viewChunks rings drawn around each stream source (default 3), density multiplier (default 1),
|
|
@@ -29,15 +49,16 @@ const VEG_PARAMS = keysSchema(OPTS, { chunkSize: 32, viewChunks: 3, density: 1,
|
|
|
29
49
|
*/
|
|
30
50
|
export function vegetation(opts = {}) {
|
|
31
51
|
readParams('vegetation', VEG_PARAMS, opts);
|
|
32
|
-
let v = null, own = null,
|
|
33
|
-
const data = { name: 'vegetation', type: 'world', provides: ['vegetation'], label: 'Vegetation', params: VEG_PARAMS, options: opts, stage: 'ground', after: ['terrain', 'level'], optional: ['terrain', 'level'],
|
|
34
|
-
install(e) {
|
|
52
|
+
let v = null, own = null, drawPart = null;
|
|
53
|
+
const data = { content: { vegetation: VEGETATION_CONTENT }, name: 'vegetation', skipKind: 'approx', type: 'world', provides: ['vegetation'], label: 'Vegetation', params: VEG_PARAMS, options: opts, stage: 'ground', after: ['terrain', 'level'], optional: ['terrain', 'level', 'settings'],
|
|
54
|
+
install(e, ctx) {
|
|
35
55
|
e.i18n.add({ 'zh-CN': { 'module.vegetation': '植被' }, en: { 'module.vegetation': 'vegetation' } });
|
|
36
|
-
v = new Vegetation(e, opts);
|
|
56
|
+
v = new Vegetation(e, opts, ctx);
|
|
57
|
+
ctx.track(e.events.on('settings:shadows', () => v.host.refreshLevels())); // whichever chunks it grows on: each level pass rereads the shadow switch
|
|
37
58
|
if (v.host !== e.terrain) {
|
|
38
59
|
own = v.host;
|
|
39
|
-
|
|
40
|
-
|
|
60
|
+
ctx.ground.addColliders((x, z, range, fn) => own.forEachCollider(x, z, range, fn)); // collision and path planning see the trees
|
|
61
|
+
ctx.stream.addReadyCheck('vegetation', s => own.readyAt(s));
|
|
41
62
|
}
|
|
42
63
|
return v;
|
|
43
64
|
},
|
|
@@ -46,15 +67,17 @@ export function vegetation(opts = {}) {
|
|
|
46
67
|
critical: true,
|
|
47
68
|
async init(e) {
|
|
48
69
|
if (own && e.terrain) throw codedError('module-requires', 'vegetation() was installed before terrain(): put terrain() first, vegetation then grows on its chunks');
|
|
70
|
+
// over a level or a code-built ground these chunks are the only ones: their rows are this module's to offer (on terrain, the terrain's)
|
|
71
|
+
if (own) e.settings?.define('viewChunks', own.viewChunks, n => { if (own.viewChunks !== n) own.viewChunks = n; }).define('density', own.density, n => { if (own.density !== n) own.density = n; });
|
|
49
72
|
await v.whenLoaded(); // densityMap.url images of species added before start
|
|
50
73
|
},
|
|
51
74
|
frame(dt, e) { own?.update(e.stream.sources(), e.camera); },
|
|
52
75
|
fixed(dt) { v.tick(dt); }, skip(dt, e, done) { if (done) v.tick(1); },
|
|
53
76
|
describe(e, ctx) { if (own) ctx.out.perf.vegetation = { loaded: own.stats.loaded, visible: own.stats.visible, queued: own.stats.queued }; },
|
|
54
|
-
dispose(e) { own?.dispose();
|
|
77
|
+
dispose(e) { own?.dispose(); v?._view?.remove(); v?._planter?.remove(); } };
|
|
55
78
|
const lookModule = {
|
|
56
79
|
// the same vegetation({...}) call (its options are the data part's; the draw part reads the species' define() options)
|
|
57
|
-
name: 'vegetationDraw', type: 'picture', label: 'Vegetation drawing', params: VEG_PARAMS, options: opts, requires: ['vegetation'], provides: ['vegetation-draw'], stage: 'effects',
|
|
80
|
+
name: 'vegetationDraw', skipKind: 'none', type: 'picture', label: 'Vegetation drawing', params: VEG_PARAMS, options: opts, requires: ['vegetation'], provides: ['vegetation-draw'], stage: 'effects',
|
|
58
81
|
install(e) { e.i18n.add({ 'zh-CN': { 'module.vegetationDraw': '植被外观' }, en: { 'module.vegetationDraw': 'vegetation drawing' } }); drawPart = new VegetationDraw(e, v); return drawPart; },
|
|
59
82
|
frame() { drawPart.updateFade(); },
|
|
60
83
|
describe() { return { chunks: drawPart?.meshes.size ?? 0 }; },
|
|
@@ -62,3 +85,5 @@ export function vegetation(opts = {}) {
|
|
|
62
85
|
};
|
|
63
86
|
return [data, lookModule];
|
|
64
87
|
}
|
|
88
|
+
|
|
89
|
+
export const handRolled = 'none: plants of its own are plain three.js, used on purpose';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mergeCommon } from '../../render/mergeCommon.js';
|
|
2
2
|
import { copyPatches } from '../../render/patches.js';
|
|
3
|
-
import { codedError } from '../../core/errorHints.js';
|
|
3
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
4
4
|
|
|
5
5
|
// Multi-material model (bark trunk + alpha-cut leaf cards) -> one geometry with a group per mesh + a material array, so a species stays
|
|
6
6
|
// one InstancedMesh: instance matrices, felling and LOD swaps work unchanged for every part. Only attributes all meshes share are kept.
|
|
@@ -15,8 +15,5 @@ export function fromModel(root, label) {
|
|
|
15
15
|
mats.push(copyPatches(n.material, n.material.clone())); // the clone keeps the model material's own shader patches
|
|
16
16
|
});
|
|
17
17
|
if (!geos.length) throw codedError('vegetation-option', `${label}: model has no meshes`);
|
|
18
|
-
|
|
19
|
-
const indexed = geos.every(g => g.index);
|
|
20
|
-
const ready = geos.map(g => { const h = indexed ? g : g.toNonIndexed(); for (const k in h.attributes) if (!names.includes(k)) h.deleteAttribute(k); return h; });
|
|
21
|
-
return { geometry: mergeGeometries(ready, true), materials: mats };
|
|
18
|
+
return { geometry: mergeCommon(geos, true), materials: mats };
|
|
22
19
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// no extra draw call or shader program per frame (the patch is part of the material's one program), the sway of the wind patch is scaled with it, and the
|
|
5
5
|
// shadow pass shrinks the same way. The band ends where the ring can first end, so a clump is already gone when its chunk drops out.
|
|
6
6
|
import * as THREE from 'three';
|
|
7
|
-
import { codedError } from '../../core/errorHints.js';
|
|
7
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
8
8
|
|
|
9
9
|
const PARS = 'uniform vec2 uNearFade; uniform vec3 uNearFadeCenter;';
|
|
10
10
|
const VERTEX = `
|
package/modules/water/Water.js
CHANGED
|
@@ -16,15 +16,15 @@ import * as THREE from 'three';
|
|
|
16
16
|
import { neutralMaterial } from '../../render/neutral.js';
|
|
17
17
|
import { placeholderTexture } from '../../render/effects.js';
|
|
18
18
|
import { patchMaterial, unpatchMaterial } from '../../render/patches.js';
|
|
19
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
19
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
20
20
|
import { waterShader, wavesPatch, surfacePatch } from './surface.js';
|
|
21
|
-
import { codedError } from '../../core/errorHints.js';
|
|
21
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
22
22
|
import { glslFloat, FRESNEL_POWER } from '../../render/fxNumbers.js';
|
|
23
|
-
import {
|
|
23
|
+
import { needMaterial } from '../../core/base/validate.js';
|
|
24
24
|
|
|
25
25
|
const GREY = new THREE.Color(0xcccccc);
|
|
26
26
|
/** @import { ModuleDef } from '../../types/core' */
|
|
27
|
-
/** @import {
|
|
27
|
+
/** @import { Material, Vector3, Texture } from '../../types/common' */
|
|
28
28
|
/** @import { WaterBody, WaterOptions, WaterShaderOptions } from '../../types/world' */
|
|
29
29
|
// Options accepted by water(): the structural choices only
|
|
30
30
|
const WATER_OPTIONS = ['sea', 'level', 'flat', 'size', 'segments'];
|
|
@@ -32,13 +32,6 @@ const WATER_PARAMS = keysSchema(WATER_OPTIONS);
|
|
|
32
32
|
const SHADER_PARAMS = keysSchema(['wave', 'surface', 'depthColor', 'foam', 'uniforms']);
|
|
33
33
|
const NORMAL_PARAMS = { scale: { type: 'number', min: 0, optional: true, desc: 'normal map strength' }, repeat: { type: 'number', min: 0, optional: true, desc: 'tiles per meter' },
|
|
34
34
|
speed: { type: 'position', optional: true, desc: 'scroll [x, z] per second' } };
|
|
35
|
-
// keys that were picture values: each names where the same thing is written now
|
|
36
|
-
const NORMAL = 'engine.water.normalMap(name, { scale, repeat, speed })', PHONG = 'a highlight belongs to your own material: engine.water.material = new THREE.MeshPhongMaterial({ shininess, specular })';
|
|
37
|
-
const SHADER = k => `engine.water.shader({ ${k} })`, TUNE = u => `engine.water.uniforms.${u}.value`;
|
|
38
|
-
const MOVED = { color: 'engine.water.material.color.set(...)', opacity: 'engine.water.material.opacity', material: 'engine.water.material = yourMaterial',
|
|
39
|
-
waveHeight: TUNE('uWave'), waveScale: TUNE('uWaveScale'), waveSpeed: TUNE('uWaveSpeed'), fresnel: TUNE('uFresnel'),
|
|
40
|
-
depthColor: SHADER('depthColor'), foam: SHADER('foam'), uniforms: SHADER('uniforms'), glsl: "engine.water.shader({ wave, surface })",
|
|
41
|
-
normalMap: NORMAL, normalScale: NORMAL, normalRepeat: NORMAL, normalSpeed: NORMAL, shininess: PHONG, specular: PHONG };
|
|
42
35
|
|
|
43
36
|
/** engine.water */
|
|
44
37
|
export class Water {
|
|
@@ -83,13 +76,21 @@ export class Water {
|
|
|
83
76
|
/**
|
|
84
77
|
* Global water mesh (null when absent)
|
|
85
78
|
* @type {THREE.Mesh | null}
|
|
79
|
+
* @experimental
|
|
86
80
|
*/
|
|
87
81
|
this.sea = null;
|
|
88
82
|
/** @internal */ this._seaChecked = st.sea === false; // global water is built on the first frame: terrain (water level) is installed by then, so no dependence on install order
|
|
89
83
|
for (const b of engine.waterBodies) this._addBody(b);
|
|
90
84
|
track(engine.events.on('water:add', b => this._addBody(b)));
|
|
91
|
-
|
|
92
|
-
|
|
85
|
+
track(engine.events.on('water:remove', b => { const m = this.bodies.get(b); if (m) { this._drop(m); this.bodies.delete(b); } }));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** One water mesh out of the scene. The material is shared by all water, so not engine.remove (which would dispose it); the ray registration goes too @internal */
|
|
89
|
+
_drop(m) { const e = this.engine; m.removeFromParent(); e.rays.forget(m); this._uv.delete(m); m.geometry.dispose(); }
|
|
90
|
+
/** The module goes: its meshes and what it made leave with it; a game's material stays the game's @internal */
|
|
91
|
+
dispose() {
|
|
92
|
+
for (const m of [this.sea, ...this.bodies.values()]) if (m) this._drop(m);
|
|
93
|
+
this.sea = null; this.bodies.clear(); this._own.dispose(); this.normalTexture?.dispose();
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
/**
|
|
@@ -99,7 +100,7 @@ export class Water {
|
|
|
99
100
|
*/
|
|
100
101
|
get material() { return this._material; }
|
|
101
102
|
set material(m) {
|
|
102
|
-
|
|
103
|
+
needMaterial('water-option', 'engine.water.material', m, '; e.g. engine.water.material = applyEffects(new THREE.MeshPhongMaterial({ color: 0x3070a0 }), { patches: engine.water.patches })');
|
|
103
104
|
const was = this._material;
|
|
104
105
|
if (m === was) return;
|
|
105
106
|
this._show(m);
|
|
@@ -141,6 +142,7 @@ export class Water {
|
|
|
141
142
|
if ((name ?? null) !== n.name) {
|
|
142
143
|
n.name = name ?? null;
|
|
143
144
|
const t = name ? placeholderTexture('normal') : null;
|
|
145
|
+
this.normalTexture?.dispose(); // the one this replaces: the engine made it, so it frees it (its asset callback ignores it from now on)
|
|
144
146
|
this.normalTexture = own.normalMap = t;
|
|
145
147
|
own.needsUpdate = true;
|
|
146
148
|
if (t) {
|
|
@@ -190,6 +192,7 @@ export class Water {
|
|
|
190
192
|
}
|
|
191
193
|
/** @internal */
|
|
192
194
|
_addBody(b) {
|
|
195
|
+
if (b.query) return; // the game's own water (addWaterBody({ query })): it draws the mesh
|
|
193
196
|
const seg = Math.max(4, Math.round((b.radius ? b.radius * 2 : Math.max(b.hw, b.hd) * 2) / this.cell));
|
|
194
197
|
const geo = b.radius ? new THREE.CircleGeometry(b.radius, Math.max(16, seg * 2)).rotateX(-Math.PI / 2) : new THREE.PlaneGeometry(b.hw * 2, b.hd * 2, seg, seg).rotateX(-Math.PI / 2);
|
|
195
198
|
const m = new THREE.Mesh(geo, this._material);
|
|
@@ -232,10 +235,9 @@ export class Water {
|
|
|
232
235
|
* @returns {ModuleDef<Water>}
|
|
233
236
|
*/
|
|
234
237
|
export function water(opts = {}) {
|
|
235
|
-
if (DEV) for (const k in MOVED) if (k in opts) throw codedError('water-option', `water({ ${k} }) is not an option: after engine.use(water()) use ${MOVED[k]} (recipes/44)`);
|
|
236
238
|
readParams('water', WATER_PARAMS, opts);
|
|
237
239
|
let w = null;
|
|
238
|
-
return { name: 'water', type: 'picture', label: 'Water', params: WATER_PARAMS, options: opts, stage: 'environment',
|
|
240
|
+
return { name: 'water', skipKind: 'none', type: 'picture', label: 'Water', params: WATER_PARAMS, options: opts, stage: 'environment', optional: ['sky'], install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.water': '水面' }, en: { 'module.water': 'water' } }); w = new Water(e, opts, ctx.track); return w; }, frame(dt, e) { w.update(e.focus, dt); }, dispose() { w.dispose(); },
|
|
239
241
|
// "is there water where I think": the global sea (its level and plane size; null = none, e.g. no water level) and each separate body
|
|
240
242
|
describe() {
|
|
241
243
|
const r = v => Math.round(v * 10) / 10, s = w.sea;
|
|
@@ -243,3 +245,5 @@ export function water(opts = {}) {
|
|
|
243
245
|
return { sea: s ? { level: r(s.position.y + 0.2), size: w.st.size } : null, bodies };
|
|
244
246
|
} };
|
|
245
247
|
}
|
|
248
|
+
|
|
249
|
+
export const handRolled = 'none: water of its own is plain three.js, used on purpose';
|
package/modules/water/surface.js
CHANGED
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
// base = material color and opacity; wave = threedogWaterWave at this point; facing = 1 looking straight down, 0 at grazing angles;
|
|
9
9
|
// returns the color and opacity lighting starts from
|
|
10
10
|
import * as THREE from 'three';
|
|
11
|
-
import { closest } from '../../core/validate.js';
|
|
12
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
11
|
+
import { closest } from '../../core/base/validate.js';
|
|
12
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
13
13
|
import { declareUniforms } from '../../render/uniformDecl.js';
|
|
14
14
|
import { hashText } from '../../render/effects.js';
|
|
15
|
-
import { codedError } from '../../core/errorHints.js';
|
|
15
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
16
16
|
import { glslFloat as gf, WAVE as W, WAVE_MAX, DEPTH, FOAM } from '../../render/fxNumbers.js';
|
|
17
17
|
|
|
18
18
|
const DEPTH_KEYS = ['shallow', 'deep', 'by', 'curve'];
|
|
@@ -2,21 +2,24 @@
|
|
|
2
2
|
// Seven temperate ones are an opt-in preset: weather(presets.weather.temperate), extend with types: { ...presets.weather.temperate.types, dust: {...} }.
|
|
3
3
|
// All fields blend smoothly on change.
|
|
4
4
|
// Affects: cloud shadows, sky color, wind (plants sway), rain/snow particles, lightning, ambience; light and fog are the game's, which reads uWeatherLight / uWeatherFog.
|
|
5
|
-
// Particle and lightning pictures: weather({ rain, snow, lightning }), engine.weather.
|
|
5
|
+
// Particle and lightning pictures: weather({ rain, snow, lightning }), engine.weather.defineField(field, spec), engine.weather.particles (particles.js, recipes/44).
|
|
6
6
|
// weather() installs two modules: this state (current / target / progress, auto weather, lightning timing, events, save) and the drawing half
|
|
7
7
|
// (weatherDraw.js: particles, sky effects, thunder). Why split: the state is game data that saves and skips; the picture only reads it,
|
|
8
8
|
// so a game can swap the picture without touching the weather a save restores.
|
|
9
9
|
//
|
|
10
10
|
// engine.weather.set('rain', { seconds: 20 }) // turn to rain over 20 seconds
|
|
11
|
-
// engine.weather.
|
|
11
|
+
// engine.weather.auto = true // change weather at random (uses engine.random, so step/tests are reproducible and saved)
|
|
12
12
|
// Weather display names live in the string table as weather.<name> (describe and the debug panel use them); a game that adds a new weather adds its name with
|
|
13
13
|
// i18n.add.
|
|
14
14
|
import * as THREE from 'three';
|
|
15
|
-
import { warnMissing } from '../../core/validate.js';
|
|
16
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
15
|
+
import { warnMissing, fmt } from '../../core/base/validate.js';
|
|
16
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
17
17
|
import { STRINGS, ERR } from './strings.js';
|
|
18
|
-
import { codedError } from '../../core/errorHints.js';
|
|
18
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
19
|
+
import { STEP } from '../../core/time/time.js';
|
|
19
20
|
import { weatherDrawModule } from './weatherDraw.js';
|
|
21
|
+
import { isPlainObject } from '../../core/base/util.js';
|
|
22
|
+
import { saveNumberOk, saveValues, SAVE_MAX_SECONDS } from '../../core/base/saveValues.js';
|
|
20
23
|
/** @import { ModuleDef } from '../../types/core' */
|
|
21
24
|
/** @import { WeatherName, WeatherPreset, WeatherOptions, WeatherParticles, WeatherParticleSystem } from '../../types/world' */
|
|
22
25
|
|
|
@@ -42,7 +45,7 @@ export class Weather {
|
|
|
42
45
|
/** @internal */ this.engine = engine;
|
|
43
46
|
if (typeof lightning !== 'function') throw codedError('weather-option', 'weather({ lightning }) must be a function (flash 0..1, engine) => sky flash amount, e.g. lightning: f => f * 0.6; return 0 and draw your own bolt on the weather:lightning event');
|
|
44
47
|
// The game's table is the whole list (a desert game has no snow, a space station no rain); without one only a calm 'clear'.
|
|
45
|
-
if (types !== undefined && (!types || typeof types !== 'object' || !Object.keys(types).length)) throw codedError('weather-option', ERR.types
|
|
48
|
+
if (types !== undefined && (!types || typeof types !== 'object' || !Object.keys(types).length)) throw codedError('weather-option', fmt(ERR.types, { got: String(JSON.stringify(types)) }));
|
|
46
49
|
const table = types ?? ONLY_CLEAR;
|
|
47
50
|
/**
|
|
48
51
|
* The weather types this game has: name -> numbers (the standard fields plus any of the game's own, all blended on change) @type {Record<string,
|
|
@@ -51,13 +54,13 @@ export class Weather {
|
|
|
51
54
|
this.types = {};
|
|
52
55
|
for (const k of Object.keys(table)) {
|
|
53
56
|
const v = { ...CALM, ...table[k] };
|
|
54
|
-
for (const f in v) if (typeof v[f] !== 'number') throw codedError('weather-option', ERR.field
|
|
57
|
+
for (const f in v) if (typeof v[f] !== 'number') throw codedError('weather-option', fmt(ERR.field, { k, f, got: String(JSON.stringify(v[f])) }));
|
|
55
58
|
this.types[k] = v;
|
|
56
59
|
}
|
|
57
60
|
// a game field one type has ('heat' on 'heatwave') is 0 on the others, so a change always blends between two numbers
|
|
58
61
|
for (const v of Object.values(this.types)) for (const o of Object.values(this.types)) for (const f in o) v[f] ??= 0;
|
|
59
62
|
start ??= this.types.clear ? 'clear' : Object.keys(this.types)[0];
|
|
60
|
-
if (!this.types[start]) throw codedError('weather-option', ERR.start
|
|
63
|
+
if (!this.types[start]) throw codedError('weather-option', fmt(ERR.start, { got: String(start), list: Object.keys(this.types).join(', ') }));
|
|
61
64
|
/** Current (mid-transition) weather parameters @type {WeatherPreset} */
|
|
62
65
|
this.current = { ...this.types[start] };
|
|
63
66
|
/** @internal */ this.from = { ...this.current };
|
|
@@ -66,22 +69,21 @@ export class Weather {
|
|
|
66
69
|
/** @internal */ this.dur = 1;
|
|
67
70
|
/** Current weather name @type {string} */
|
|
68
71
|
this.name = start;
|
|
69
|
-
/**
|
|
70
|
-
this.auto = false;
|
|
72
|
+
/** @internal */ this._auto = false;
|
|
71
73
|
/** @internal */ this.autoTimer = 0;
|
|
72
|
-
/** Candidates for automatic weather (repeat a name to make it likelier) @type {string[]} */
|
|
74
|
+
/** Candidates for automatic weather (repeat a name to make it likelier) @type {string[]} @experimental */
|
|
73
75
|
this.autoPool = [...(autoPool || Object.keys(this.types))];
|
|
74
|
-
for (const k of this.autoPool) if (!this.types[k]) throw codedError('weather-option', ERR.pool
|
|
75
|
-
/** Automatic weather interval [min, max] seconds @type {number[]} */
|
|
76
|
+
for (const k of this.autoPool) if (!this.types[k]) throw codedError('weather-option', fmt(ERR.pool, { got: String(k), list: Object.keys(this.types).join(', ') }));
|
|
77
|
+
/** Automatic weather interval [min, max] seconds @type {number[]} @experimental */
|
|
76
78
|
this.autoInterval = autoInterval;
|
|
77
|
-
/** Transition seconds for automatic weather @type {number} */
|
|
79
|
+
/** Transition seconds for automatic weather @type {number} @experimental */
|
|
78
80
|
this.autoTransition = transition;
|
|
79
|
-
/** Seconds to the first bolt (also after a load without a saved timer) @type {number} */
|
|
81
|
+
/** Seconds to the first bolt (also after a load without a saved timer) @type {number} @experimental */
|
|
80
82
|
this.lightningFirst = lightningFirst;
|
|
81
|
-
/** [min, max] seconds between bolts while a type with lightning > 0.5 holds @type {number[]} */
|
|
83
|
+
/** [min, max] seconds between bolts while a type with lightning > 0.5 holds @type {number[]} @experimental */
|
|
82
84
|
this.lightningInterval = lightningInterval;
|
|
83
85
|
/** @internal seconds to the next lightning strike while a type with lightning > 0.5 holds */ this.nextBolt = lightningFirst;
|
|
84
|
-
/** Strike picture: flash (1 at the strike, fading in a third of a second) -> sky flash amount. Write it at any time @type {(flash: number, engine: any) => number} */
|
|
86
|
+
/** Strike picture: flash (1 at the strike, fading in a third of a second) -> sky flash amount. Write it at any time @type {(flash: number, engine: any) => number} @experimental */
|
|
85
87
|
this.lightning = lightning;
|
|
86
88
|
/** Multiplies the sky flash of every strike; write it at any time @type {number} */
|
|
87
89
|
this.lightningBrightness = lightningBrightness;
|
|
@@ -90,7 +92,7 @@ export class Weather {
|
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
/**
|
|
93
|
-
* The particle systems drawn now, by field: rain and snow when the table has them, plus what
|
|
95
|
+
* The particle systems drawn now, by field: rain and snow when the table has them, plus what defineField() added. Each has material (the plain three.js
|
|
94
96
|
* material: read it, or set your own, drawn as given; null gives the engine's back), uniforms ({ value } objects the engine writes each frame, a
|
|
95
97
|
* ShaderMaterial of yours shares them; uColor, uLen, uPx, uMaxPx, uSwayAmp are yours to write), spec (opacity, speed, slant, density are read each
|
|
96
98
|
* frame, plain writes), object (the three.js object). Empty when a game replaced the weather drawing
|
|
@@ -105,23 +107,23 @@ export class Weather {
|
|
|
105
107
|
* frame is weather.current[field], so they fade with the weather. spec takes the keys of weather({ rain }), or
|
|
106
108
|
* { create(engine, { area, count }) => { object, update?(amount, { camera, time, wind }) } } for a system of your own; null gives rain / snow back
|
|
107
109
|
* to weather({ rain, snow }) and removes any other field. Defining a field again replaces it. A field no type has throws with the table's fields
|
|
108
|
-
* @example engine.weather.
|
|
110
|
+
* @example engine.weather.defineField('ash', { shape: 'soft', color: 0x555555, size: 14, speed: 0.8, sway: 3 });
|
|
109
111
|
* @param {string} field
|
|
110
112
|
* @param {WeatherParticles | null} spec
|
|
111
113
|
* @returns {WeatherParticleSystem | null}
|
|
112
114
|
*/
|
|
113
|
-
|
|
115
|
+
defineField(field, spec) {
|
|
114
116
|
const drawPart = this.engine.weatherDraw;
|
|
115
|
-
if (!drawPart) throw codedError('weather-option', "weather.
|
|
116
|
-
return drawPart.
|
|
117
|
+
if (!drawPart) throw codedError('weather-option', "weather.defineField(): the weather is drawn by a game module (replaces: 'weatherDraw'); draw this field there, reading engine.weather.current");
|
|
118
|
+
return drawPart.defineField(field, spec);
|
|
117
119
|
}
|
|
118
120
|
|
|
119
121
|
/**
|
|
120
|
-
* Automatic weather on/off
|
|
121
|
-
* @
|
|
122
|
-
* @returns {void}
|
|
122
|
+
* Automatic weather on/off.
|
|
123
|
+
* @type {boolean}
|
|
123
124
|
*/
|
|
124
|
-
|
|
125
|
+
get auto() { return this._auto; }
|
|
126
|
+
set auto(on) { this._auto = on; if (on) this.autoTimer = 0; }
|
|
125
127
|
|
|
126
128
|
/**
|
|
127
129
|
* Switch weather. seconds: transition seconds, default 15; 0 switches at once (current is the new weather before the next step, so a
|
|
@@ -138,8 +140,8 @@ export class Weather {
|
|
|
138
140
|
const p = this.types[name];
|
|
139
141
|
if (!p) { warnMissing('weather', name, Object.keys(this.types)); return; }
|
|
140
142
|
const from = this.name;
|
|
141
|
-
if (!(seconds >= 0 && Number.isFinite(seconds))) throw codedError('
|
|
142
|
-
this.name = name; this.from = { ...this.current }; this.to = { ...p }; this.t = 0; this.dur = seconds;
|
|
143
|
+
if (!(seconds >= 0 && Number.isFinite(seconds))) throw codedError('weather-option', `weather.set('${name}', { seconds }) takes seconds >= 0 (0 = at once); got ${seconds}`);
|
|
144
|
+
this.name = name; this.from = { ...this.current }; this.to = { ...p }; this.t = 0; this.dur = Math.max(seconds, 0.01); // the least a load accepts: a blend divides by it, and the save must read the same after a load
|
|
143
145
|
// seconds 0: land now, not on the next fixed step (a shot or test right after the call saw the old weather, or 1/3 of a short blend)
|
|
144
146
|
if (seconds === 0) { this.t = 1; for (const key in this.to) this.current[key] = this.to[key]; }
|
|
145
147
|
// once per change of name (the blend then runs over `seconds`); setting the same weather again is not a change
|
|
@@ -166,7 +168,7 @@ export class Weather {
|
|
|
166
168
|
this.t = Math.min(1, this.t + dt / this.dur);
|
|
167
169
|
const k = this.t * this.t * (3 - 2 * this.t);
|
|
168
170
|
// a finished blend lands on `to` exactly: from + (to - from) * 1 is off by a rounding error that depends on where the blend started, so a load
|
|
169
|
-
// or session.newGame (set(name, 0.01) from whatever the last playthrough left) would not give the same weather twice
|
|
171
|
+
// or session.newGame (set(name, { seconds: 0.01 }) from whatever the last playthrough left) would not give the same weather twice
|
|
170
172
|
for (const key in this.to) this.current[key] = this.t >= 1 ? this.to[key] : this.from[key] + (this.to[key] - this.from[key]) * k;
|
|
171
173
|
}
|
|
172
174
|
if (this.auto) {
|
|
@@ -185,7 +187,7 @@ export class Weather {
|
|
|
185
187
|
}
|
|
186
188
|
|
|
187
189
|
/**
|
|
188
|
-
* Weather: two modules for one engine.use: the state (engine.weather, type 'world') and its picture (engine.weatherDraw, type 'picture';
|
|
190
|
+
* Weather: two modules for one engine.use: the state (engine.weather, type 'world') and its picture (engine.weatherDraw, type 'picture'; sky optional)
|
|
189
191
|
* @param {WeatherOptions} [opts]
|
|
190
192
|
* @returns {[ModuleDef<Weather>, ModuleDef<import('./weatherDraw.js').WeatherDraw>]}
|
|
191
193
|
* @example engine.use(sky(), weather({ types: presets.weather.temperate.types, start: 'clear' }))
|
|
@@ -194,36 +196,44 @@ export function weather(opts = {}) {
|
|
|
194
196
|
readParams('weather', WEATHER_PARAMS, opts);
|
|
195
197
|
let w = null;
|
|
196
198
|
const state = {
|
|
197
|
-
name: 'weather', type: 'world', provides: ['weather'], label: 'Weather', params: WEATHER_PARAMS, options: opts, stage: 'environment', before: ['sky'],
|
|
198
|
-
install(e) {
|
|
199
|
+
name: 'weather', skipKind: 'step', type: 'world', provides: ['weather'], label: 'Weather', params: WEATHER_PARAMS, options: opts, stage: 'environment', before: ['sky'],
|
|
200
|
+
install(e, ctx) {
|
|
199
201
|
e.i18n.add(STRINGS);
|
|
200
202
|
w = new Weather(e, opts);
|
|
201
203
|
if (opts.auto) w.auto = true;
|
|
202
204
|
// the transition is saved too (current / from / to / t / dur): a save made 30% into sun -> rain loads 30% in, not as full rain, and fires no
|
|
203
|
-
// weather:change (nothing changed for the player).
|
|
204
|
-
|
|
205
|
+
// weather:change (nothing changed for the player). A damaged part, or a weather the game no longer has, loads as a finished switch to that name
|
|
206
|
+
ctx.saves.register('weather', { notAtomic: 'moves on its own timers like the calendar: an op that sets it means it to stay',
|
|
205
207
|
save: () => ({ name: w.name, auto: w.auto, autoTimer: w.autoTimer, nextBolt: w.nextBolt, current: { ...w.current }, from: { ...w.from }, to: { ...w.to }, t: w.t, dur: w.dur }),
|
|
206
208
|
load: d => {
|
|
207
209
|
if (!d) return;
|
|
208
|
-
|
|
209
|
-
|
|
210
|
+
const s = saveValues('weather'), most = { min: 0, max: SAVE_MAX_SECONDS };
|
|
211
|
+
const fields = v => isPlainObject(v) && Object.values(v).every(saveNumberOk); // every blended field is a finite number: one NaN would spread to the sky, fog and sound
|
|
212
|
+
if (Number.isFinite(d.t) && fields(d.current) && fields(d.from) && fields(d.to) && w.types[d.name]) {
|
|
213
|
+
// over the type's own fields: a save older than a field the table has now would blend it from undefined (NaN)
|
|
214
|
+
const full = v => ({ ...w.types[d.name], ...v });
|
|
215
|
+
w.name = d.name; w.current = full(d.current); w.from = full(d.from); w.to = full(d.to); w.t = s.num(d.t, 't', { min: 0, max: 1, fallback: 1 }); w.dur = s.num(d.dur ?? 1, 'dur', { ...most, min: 0.01, fallback: 1 });
|
|
210
216
|
} else w.set(d.name, { seconds: 0 });
|
|
211
|
-
w.auto = d.auto; w.autoTimer = d.autoTimer ?? 0; w.nextBolt = d.nextBolt ?? w.lightningFirst;
|
|
217
|
+
w.auto = d.auto === true; w.autoTimer = s.num(d.autoTimer ?? 0, 'autoTimer', { ...most, fallback: 0 }); w.nextBolt = s.num(d.nextBolt ?? w.lightningFirst, 'nextBolt', { ...most, fallback: w.lightningFirst });
|
|
218
|
+
s.done();
|
|
212
219
|
} });
|
|
213
220
|
return w;
|
|
214
221
|
},
|
|
215
222
|
fixed(dt) { w.tick(dt); },
|
|
216
223
|
// the weather as signals (engine.uniforms) every frame, from the state and not its picture: a game that draws its own rain still reads them
|
|
217
|
-
frame(_dt, e) { const U = e.uniforms, c = w.current; U.
|
|
224
|
+
frame(_dt, e) { const U = e.uniforms, c = w.current; U.uWeatherCloud.value = c.cloud; U.uWind.value = c.wind; U.uRain.value = c.rain; U.uSnow.value = c.snow; U.uWeatherLight.value = c.sun; U.uWeatherFog.value = c.fog; },
|
|
218
225
|
// engine.skip: fixed hooks do not run, so the skipped fixed steps are replayed here without events (a bolt nobody saw)
|
|
219
226
|
skip(dt) { // replay the fixed steps (same random draws, same order as stepping, so checkSkip matches); nothing pending = nothing to replay
|
|
220
227
|
if (w.t >= 1 && !w.auto && !(w.current.lightning > 0.5)) return;
|
|
221
|
-
for (let n = Math.round(dt
|
|
228
|
+
for (let n = Math.round(dt / STEP); n > 0; n--) w.tick(STEP, true);
|
|
222
229
|
},
|
|
223
230
|
// scenario param weather: switch to this weather at once (no transition) and turn off automatic weather, so the scene is reproducible
|
|
231
|
+
stateKeys: ['weather'],
|
|
224
232
|
applyState(e, { weather: name }) {
|
|
225
233
|
if (!name) return;
|
|
226
|
-
w.set(name, { seconds: 0 });
|
|
234
|
+
w.set(name, { seconds: 0 }); // an unknown name warns and changes nothing, so the name is read back
|
|
235
|
+
if (w.name !== name) return { refused: { weather: `no weather named "${name}"; this game has ${Object.keys(w.types).join(', ')} (types in weather({ types }), e.g. presets.weather.temperate)` } };
|
|
236
|
+
w.auto = false;
|
|
227
237
|
},
|
|
228
238
|
describe() {
|
|
229
239
|
const c = w.current, r = v => Math.round(v * 100) / 100;
|
|
@@ -233,3 +243,5 @@ export function weather(opts = {}) {
|
|
|
233
243
|
};
|
|
234
244
|
return [state, weatherDrawModule(Object.fromEntries(['particles', 'area', 'rain', 'snow'].filter(k => opts[k] !== undefined).map(k => [k, opts[k]])))];
|
|
235
245
|
}
|
|
246
|
+
|
|
247
|
+
export const handRolled = 'none: weather by hand is plain values with no one shape';
|