threedog 0.7.0 → 0.8.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 +196 -1
- package/README.md +6 -9
- package/core/{Animator.js → assets/Animator.js} +28 -18
- package/core/{Assets.js → assets/Assets.js} +98 -54
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +237 -0
- package/core/{assetHot.js → assets/assetHot.js} +7 -6
- 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} +6 -12
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +26 -23
- 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} +10 -10
- package/core/{Random.js → base/Random.js} +5 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +98 -110
- package/core/{errorHints.js → base/errorHints.js} +5 -9
- package/core/{errors.js → base/errors.js} +6 -6
- package/core/{events.generated.js → base/events.generated.js} +1 -0
- package/core/{math.js → base/math.js} +15 -4
- package/core/{params.js → base/params.js} +3 -4
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +28 -7
- package/core/{Engine.js → engine/Engine.js} +80 -77
- package/core/{Loading.js → engine/Loading.js} +4 -2
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +4 -4
- package/core/{lifecycle.js → engine/lifecycle.js} +14 -12
- package/core/{loop.js → engine/loop.js} +68 -47
- package/core/{moduleSlots.js → engine/moduleSlots.js} +6 -6
- package/core/{moduleTypes.js → engine/moduleTypes.js} +13 -14
- package/core/{modules.js → engine/modules.js} +14 -11
- package/core/{page.js → engine/page.js} +36 -23
- package/core/{plugins.js → engine/plugins.js} +6 -9
- package/core/{services.js → engine/services.js} +47 -40
- package/core/{startup.js → engine/startup.js} +26 -24
- package/core/{Input.js → input/Input.js} +30 -22
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/{inputPad.js → input/inputPad.js} +1 -1
- package/core/{inputPointer.js → input/inputPointer.js} +8 -2
- package/core/{inputTouch.js → input/inputTouch.js} +1 -1
- package/core/{Budget.js → inspect/Budget.js} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +30 -16
- package/core/{Describe.js → inspect/Describe.js} +26 -22
- package/core/{Inspect.js → inspect/Inspect.js} +9 -7
- 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} +52 -20
- package/core/{catalog.js → inspect/catalog.js} +3 -3
- 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} +21 -20
- package/core/{describeText.js → inspect/describeText.js} +11 -6
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +15 -16
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/{Ops.js → ops/Ops.js} +16 -11
- package/core/{control.js → ops/control.js} +13 -12
- package/core/ops/holds.js +139 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +2 -1
- package/core/{opsCheck.js → ops/opsCheck.js} +4 -5
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +7 -4
- package/core/{owned.js → ops/owned.js} +14 -17
- package/core/{sharedPoint.js → ops/sharedPoint.js} +8 -8
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +12 -14
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +1 -1
- package/core/{Saves.js → saves/Saves.js} +58 -36
- package/core/{saveApply.js → saves/saveApply.js} +13 -9
- package/core/{saveFiles.js → saves/saveFiles.js} +17 -15
- package/core/{saveValues.js → saves/saveValues.js} +20 -3
- package/core/{saveVersions.js → saves/saveVersions.js} +4 -17
- package/core/{session.js → saves/session.js} +31 -17
- package/core/{Rays.js → scene/Rays.js} +23 -25
- package/core/{Views.js → scene/Views.js} +14 -6
- package/core/{adaptive.js → scene/adaptive.js} +15 -8
- package/core/{canvasBox.js → scene/canvasBox.js} +2 -3
- package/core/{engineCamera.js → scene/engineCamera.js} +1 -1
- 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} +4 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/{ground.js → scene/ground.js} +9 -9
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/{sceneDelta.js → scene/sceneDelta.js} +2 -2
- package/core/{sceneMethods.js → scene/sceneMethods.js} +36 -13
- package/core/scene/stepPoses.js +55 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +6 -5
- package/core/{thingOps.js → scene/thingOps.js} +4 -3
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{view.js → scene/view.js} +17 -16
- package/core/{Batching.js → stream/Batching.js} +85 -27
- package/core/{Stream.js → stream/Stream.js} +60 -30
- package/core/{batchGroups.js → stream/batchGroups.js} +10 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- package/core/{scatter.js → stream/scatter.js} +2 -2
- package/core/{streamSources.js → stream/streamSources.js} +12 -7
- package/core/{Commits.js → threads/Commits.js} +6 -5
- package/core/{Jobs.js → threads/Jobs.js} +12 -10
- package/core/{Threads.js → threads/Threads.js} +16 -16
- 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} +17 -10
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +18 -17
- package/core/{time.js → time/time.js} +18 -12
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +22 -19
- package/docs/API.md +24 -23
- package/docs/CODEMAP.md +76 -183
- package/docs/COMMANDS.md +66 -58
- package/docs/CONVENTIONS.md +54 -14
- package/docs/MIGRATING-0.8.md +169 -0
- package/docs/THREE.md +78 -29
- 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 +29 -29
- package/docs/api/characters.md +23 -18
- package/docs/api/clock.md +1 -1
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +6 -6
- package/docs/api/dialogue.md +3 -3
- package/docs/api/engine.md +45 -43
- package/docs/api/events.md +3 -2
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +4 -5
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +7 -7
- package/docs/api/interactions.md +4 -4
- package/docs/api/inventory.md +9 -9
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +7 -7
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +10 -10
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +2 -2
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +2 -2
- package/docs/api/post.md +20 -3
- package/docs/api/quests.md +3 -3
- package/docs/api/rays.md +5 -7
- package/docs/api/rigid.md +27 -18
- package/docs/api/saves.md +8 -7
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +8 -7
- package/docs/api/stream.md +7 -7
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +7 -8
- package/docs/api/terrainDraw.md +1 -1
- package/docs/api/timeline.md +2 -2
- package/docs/api/tools.md +25 -22
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +1 -1
- package/docs/api/water.md +1 -1
- package/docs/api/weather.md +9 -9
- package/docs/api/weatherDraw.md +3 -3
- package/docs/api/world.md +5 -5
- package/docs/recipes/01-new-game.md +25 -40
- package/docs/recipes/02-npc.md +19 -20
- package/docs/recipes/03-items-pickups.md +27 -43
- package/docs/recipes/04-quests.md +3 -4
- package/docs/recipes/05-props-bake.md +29 -39
- package/docs/recipes/06-clock-events.md +27 -18
- package/docs/recipes/07-flow-scenes-pause.md +12 -17
- package/docs/recipes/08-weather-sky.md +88 -34
- package/docs/recipes/09-materials-lights-models.md +22 -36
- package/docs/recipes/10-blender-level.md +6 -7
- package/docs/recipes/11-vehicles.md +30 -22
- package/docs/recipes/12-navmesh.md +9 -8
- package/docs/recipes/13-animation.md +39 -17
- package/docs/recipes/14-custom-module.md +14 -13
- package/docs/recipes/15-perf.md +49 -26
- package/docs/recipes/16-dev-bridge.md +32 -52
- package/docs/recipes/18-world.md +36 -23
- package/docs/recipes/19-shooting-picking.md +4 -2
- package/docs/recipes/20-content-actions-save.md +30 -35
- package/docs/recipes/21-camera.md +33 -5
- package/docs/recipes/22-shop-gold.md +0 -4
- package/docs/recipes/23-ops.md +10 -10
- package/docs/recipes/26-ui-parts.md +22 -12
- package/docs/recipes/27-net.md +0 -2
- package/docs/recipes/28-terrain.md +117 -21
- package/docs/recipes/29-grid.md +2 -2
- package/docs/recipes/30-templates.md +55 -19
- package/docs/recipes/31-audio.md +5 -5
- package/docs/recipes/32-action-game.md +15 -6
- package/docs/recipes/33-stream-sources.md +2 -2
- package/docs/recipes/34-environment-lighting.md +67 -19
- package/docs/recipes/35-picture-from-reference.md +10 -17
- package/docs/recipes/36-ground-plants.md +105 -0
- package/docs/recipes/40-scene.md +7 -11
- package/docs/recipes/43-shader-patches-surfaces.md +20 -41
- package/docs/recipes/44-water-weather-hooks.md +48 -43
- package/docs/recipes/45-cascaded-shadows.md +39 -17
- package/docs/recipes/46-blender-art-route.md +7 -8
- package/docs/recipes/49-game-module-contract.md +5 -5
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/52-around-the-picture.md +54 -98
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +12 -16
- package/docs/recipes/56-webgpu-tsl.md +16 -14
- package/docs/recipes/57-control.md +9 -2
- package/docs/recipes/58-input.md +2 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +29 -24
- package/docs/recipes/62-picture-code.md +49 -17
- package/docs/recipes/63-third-person-start.md +17 -4
- package/docs/recipes/64-particles.md +1 -1
- package/docs/recipes/65-swarm.md +140 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +2 -2
- package/examples/{sheepisland → perf-island}/.threedog/content-index.json +1 -1
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +12 -11
- 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 +1 -0
- package/examples/rc2d/GAMEMAP.md +3 -2
- package/examples/rc2d/main.js +1 -3
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +3 -2
- 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 +1 -0
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +4 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +8 -7
- package/index.js +31 -31
- package/llms.txt +9 -13
- package/modules/ambience/Ambience.js +11 -8
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +13 -13
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +2 -2
- package/modules/camera/FixedCamera.js +14 -15
- package/modules/camera/FollowCamera.js +4 -4
- package/modules/camera/RtsCamera.js +11 -11
- package/modules/camera/common.js +48 -24
- package/modules/camera/contract.js +1 -0
- package/modules/camera/projection.js +2 -2
- package/modules/characters/Character.js +33 -30
- package/modules/characters/NPC.js +27 -19
- package/modules/characters/assetModel.js +14 -10
- package/modules/characters/astar.js +7 -5
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/contract.js +2 -2
- package/modules/characters/index.js +168 -214
- package/modules/characters/moveHelpers.js +14 -3
- package/modules/characters/movers/common.js +16 -14
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +7 -6
- package/modules/characters/movers/simple.js +3 -3
- package/modules/characters/movers/support.js +8 -8
- package/modules/characters/npcAvoid.js +4 -4
- package/modules/characters/npcSim.js +23 -17
- package/modules/characters/npcView.js +6 -5
- package/modules/characters/pathAsync.js +12 -10
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +108 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +2 -2
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/walkTo.js +11 -17
- package/modules/collision/Collision.js +26 -20
- package/modules/collision/contract.js +15 -0
- package/modules/content/explain.js +1 -2
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +2 -2
- package/modules/content/index.js +61 -99
- package/modules/content/loader.js +14 -17
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +10 -7
- package/modules/content/packs.js +3 -3
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +35 -0
- package/modules/content/props.js +17 -14
- package/modules/content/rules.js +25 -21
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +20 -20
- package/modules/content/words.js +34 -0
- package/modules/debug/DebugPanel.js +10 -43
- package/modules/flow/contract.js +1 -1
- package/modules/flow/index.js +11 -7
- package/modules/gameplay/Container.js +12 -11
- package/modules/gameplay/Containers.js +14 -5
- package/modules/gameplay/Dialogue.js +13 -11
- package/modules/gameplay/Interactions.js +37 -24
- package/modules/gameplay/Inventory.js +8 -9
- package/modules/gameplay/Quests.js +16 -9
- package/modules/gameplay/boxOps.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +3 -4
- package/modules/gameplay/inventoryOps.js +0 -1
- package/modules/gameplay/pickups.js +22 -23
- package/modules/gameplay/questSave.js +3 -3
- package/modules/grid/Grid.js +1 -1
- package/modules/grid/Layer.js +4 -4
- package/modules/grid/index.js +7 -8
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +37 -55
- package/modules/hud/index.js +17 -11
- package/modules/hud/parts.js +4 -4
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +12 -10
- package/modules/level/index.js +47 -152
- package/modules/level/load.js +79 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +6 -7
- package/modules/lights/index.js +28 -181
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +88 -0
- package/modules/music/Music.js +30 -26
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +14 -0
- package/modules/nav/index.js +11 -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 +5 -4
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +11 -8
- package/modules/particles/effect.js +7 -5
- package/modules/particles/shaders.js +2 -1
- package/modules/photo/Photo.js +15 -17
- package/modules/rigid/RigidBodies.js +66 -43
- package/modules/rigid/Vehicles.js +2 -3
- package/modules/rigid/ragdoll.js +287 -0
- package/modules/rigid/ragdollBones.js +159 -0
- package/modules/rigid/sync.js +6 -6
- package/modules/settings/Settings.js +108 -39
- package/modules/settings/apply.js +6 -6
- package/modules/settings/sections.js +16 -14
- 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 +14 -27
- package/modules/sky/tint.js +1 -1
- package/modules/swarm/Swarm.js +346 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +70 -52
- 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 +28 -34
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +32 -27
- package/modules/terrain/terrainGen.js +17 -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 +27 -19
- package/modules/timeline/Tween.js +6 -6
- package/modules/timeline/shots.js +5 -7
- package/modules/triggers/index.js +9 -9
- package/modules/vegetation/Vegetation.js +30 -23
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +23 -18
- package/modules/vegetation/groundChunks.js +11 -31
- package/modules/vegetation/index.js +8 -6
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +16 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +41 -30
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +22 -18
- package/modules/world/World.js +8 -8
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -12
- package/modules/world/persist.js +73 -25
- package/modules/world/pos.js +4 -4
- package/modules/world/records.js +28 -8
- package/modules/world/sim.js +4 -4
- package/modules/world/state.js +12 -5
- package/modules/world/thingSource.js +4 -2
- package/modules/world/views.js +11 -9
- package/package.json +42 -7
- package/presets.js +1 -3
- package/render/PostFX.js +39 -27
- package/render/backend.js +26 -32
- 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/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +27 -23
- 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 +1 -1
- package/render/lighting.js +5 -3
- package/render/lightmap.js +20 -20
- 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 +20 -4
- package/render/ownFrame.js +4 -4
- package/render/patches.js +13 -13
- package/render/postWebGL.js +12 -10
- package/render/probes.js +16 -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 +57 -11
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +200 -153
- package/types/gameplay.d.ts +163 -91
- 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} +7 -15
- 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} +12 -8
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +2 -2
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +4 -3
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +4 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +37 -13
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +2 -1
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +1 -1
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +18 -16
- 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/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 +1 -1
- 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 +2 -1
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +16 -12
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +5 -3
- package/types/generated/render/PostFX.d.ts +17 -11
- 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 +11 -11
- package/types/physics.d.ts +99 -70
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +38 -71
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +4 -3
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +5 -3
- package/core/assetEntry.js +0 -109
- package/core/holds.js +0 -134
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- 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/core/{Vars.js → base/Vars.js} +0 -0
- /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/{opsFail.js → ops/opsFail.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/{tier.js → scene/tier.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
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// LOD is split by ring from the nearest source: the chunk a source stands in plus the one ring around it is ring 1, and so on.
|
|
4
4
|
// Visuals and gameplay take effect separately: a generated chunk is handed to the looks at once; collision (forEachCollider, chunkCollision) only takes
|
|
5
5
|
// effect at the tick set by engine.commits (c.solid), and is generated on the main thread on the spot if not done by then -- machine speed never
|
|
6
|
-
// changes whether the player bumps into a tree (see core/Commits.js).
|
|
6
|
+
// changes whether the player bumps into a tree (see core/threads/Commits.js).
|
|
7
7
|
// Data only: this file makes no mesh and touches no material. Each generated chunk keeps its arrays in c.data (pos, nor, col, uv, tex, top...),
|
|
8
8
|
// collision and queries read them, and draw parts subscribe with view({ add, change, remove, show }) (terrain/draw.js is the engine's own).
|
|
9
9
|
// Vegetation plugs in as the chunk planter (its data part sets terrain.plants): this file never reads engine.vegetation.
|
|
@@ -11,38 +11,36 @@ import * as THREE from 'three';
|
|
|
11
11
|
import { createTerrain } from './terrainGen.js';
|
|
12
12
|
import { chunkHandler } from './chunkJob.js';
|
|
13
13
|
import { TerrainEdits } from './terrainEdit.js';
|
|
14
|
-
import { ChunkStream } from '../../core/chunkStream.js';
|
|
14
|
+
import { ChunkStream, bookCollision } from '../../core/stream/chunkStream.js';
|
|
15
15
|
import { chunkQueries } from './chunkQueries.js';
|
|
16
|
-
import { reportError } from '../../core/errors.js';
|
|
17
|
-
import { codedError } from '../../core/errorHints.js';
|
|
16
|
+
import { reportError } from '../../core/base/errors.js';
|
|
17
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
18
18
|
|
|
19
19
|
/** Planter stand-in while no vegetation is installed (the vegetation data part replaces it) */
|
|
20
20
|
const NO_VEG = { baseNames: () => [], nearNames: () => [], list: () => [], get: () => null, mount() {}, unmount() {}, drop() {} };
|
|
21
21
|
// A failed ground job is sent again up to this many times in all (a worker that crashed or ran out of memory usually passes next time); then the
|
|
22
22
|
// chunk is marked failed and reported. Before, it sat in 'pending' for ever and the loading screen waited without a word.
|
|
23
23
|
const MAX_TRIES = 3;
|
|
24
|
-
const COLLIDER_LAG = 30; // base delay before chunk collision takes effect (fixed steps, 30 = 0.5 s), multiplied by (1 + ring)
|
|
25
24
|
|
|
26
25
|
export class ChunkManager {
|
|
27
26
|
constructor(engine, terrainCfg) {
|
|
28
27
|
this.engine = engine;
|
|
29
|
-
this.
|
|
28
|
+
this.generator = createTerrain(terrainCfg); // main-thread copy: height queries for the character and camera
|
|
30
29
|
this.chunks = new Map();
|
|
31
|
-
this.
|
|
32
|
-
this.density = 1;
|
|
30
|
+
/** @internal view distance in chunks and vegetation density: the module sets both at install (terrain/index.js holds the defaults) */ this._viewChunks = 0; this._density = 0;
|
|
33
31
|
this.applyBudgetMs = 3; // max ms per frame spent taking worker results
|
|
34
32
|
this.maxInFlight = 4;
|
|
35
33
|
this.inFlight = 0;
|
|
36
34
|
this.ready = [];
|
|
37
35
|
this._want = []; // chunks not yet dispatched (nearest first)
|
|
38
36
|
this.gen = 0;
|
|
39
|
-
this.vgen = 0; // +1 on a density change: plants placed
|
|
37
|
+
this.vgen = 0; // +1 on a density or species change: plants placed before it are asked again
|
|
40
38
|
this.stats = { builtThisFrame: 0, applyMs: 0, queued: 0, failed: 0 };
|
|
41
39
|
/** @internal the draw parts drawing these chunks (view()) */ this.views = new Set();
|
|
42
40
|
/** @internal the vegetation data part, or NO_VEG */ this.plants = NO_VEG;
|
|
43
41
|
/** @internal the engine's terrain drawing (draw.js), null when a game's picture holds the slot */ this.drawPart = null;
|
|
44
42
|
this.lowest = 0; // lowest island point loaded (default voidY)
|
|
45
|
-
// which chunks the sources need, ring, culling: shared with vegetation's own-ground chunks (core/chunkStream.js)
|
|
43
|
+
// which chunks the sources need, ring, culling: shared with vegetation's own-ground chunks (core/stream/chunkStream.js)
|
|
46
44
|
this._stream = new ChunkStream(this, { show: (c, v) => this._emit('show', c, v), level: (c, ring) => this._setLevel(c, ring),
|
|
47
45
|
count: c => { let n = 0; for (const k in c.plants) n += c.plants[k].n; return n; } });
|
|
48
46
|
|
|
@@ -53,7 +51,7 @@ export class ChunkManager {
|
|
|
53
51
|
/** @internal edit records (saved with the save) */ this.edits = new TerrainEdits(engine, this);
|
|
54
52
|
}
|
|
55
53
|
|
|
56
|
-
get
|
|
54
|
+
get chunkSize() { return this.generator.CHUNK; }
|
|
57
55
|
// the draw part's entries, here because engine.terrain is where a game looks for them; this file stays data only
|
|
58
56
|
/** @internal */
|
|
59
57
|
_drawPart() { return this.drawPart ?? (() => { throw codedError('terrain-option', "the engine's terrain drawing is not installed: a draw part that replaces 'terrain-draw' draws the ground its own way"); })(); }
|
|
@@ -76,9 +74,9 @@ export class ChunkManager {
|
|
|
76
74
|
* chunk loaded (at most -50); -Infinity without a shape
|
|
77
75
|
* @example engine.events.on('terrain:void', ({ who }) => { if (who === engine.player) engine.player.placeAt(home); });
|
|
78
76
|
*/
|
|
79
|
-
get voidY() { return this.
|
|
77
|
+
get voidY() { return this.generator.shape ? this.generator.shape.voidY ?? Math.min(0, this.lowest) - 50 : -Infinity; }
|
|
80
78
|
/** Grid spacing (meters): edits snap to it, and paint colors whole cells of this size. Set by chunkSize / resolution */
|
|
81
|
-
get cellSize() { return this.
|
|
79
|
+
get cellSize() { return this.generator.CELL; }
|
|
82
80
|
/**
|
|
83
81
|
* Change the ground: dig, raise, flatten, or paint the ground type. Call it from an op or a fixed step (it is saved gameplay state).
|
|
84
82
|
* Heights snap to grid points and paint to cells (cellSize); the nearest one is taken when the shape is smaller than a cell.
|
|
@@ -96,14 +94,6 @@ export class ChunkManager {
|
|
|
96
94
|
*/
|
|
97
95
|
edit(position, opts) { return this.edits.edit(position, opts); }
|
|
98
96
|
|
|
99
|
-
/**
|
|
100
|
-
* Draw these chunks. Hooks: add(c) (generated: c.data holds the arrays pos / nor / col / uv / tex, c.cx / c.cz the chunk), change(c) (an edit
|
|
101
|
-
* rewrote c.data, same vertex count), remove(c) (released), show(c, visible) (in the camera view or not). Chunks already loaded are added at
|
|
102
|
-
* once. This is how a draw part that replaces 'terrain-draw' draws the ground. Returns { remove() } (ctx.track it).
|
|
103
|
-
* @example ctx.track(engine.terrain.view({ add(c) { draw(c) }, remove(c) { undraw(c) } }))
|
|
104
|
-
* @param {{ add?: (c: any) => void, change?: (c: any) => void, remove?: (c: any) => void, show?: (c: any, visible: boolean) => void }} v
|
|
105
|
-
* @returns {{ remove(): void }}
|
|
106
|
-
*/
|
|
107
97
|
/**
|
|
108
98
|
* Hand the terrain its planter (the vegetation data part calls this): it is told when chunks mount, unmount and drop. Returns a handle;
|
|
109
99
|
* remove() puts the empty planter back if this one is still set.
|
|
@@ -115,6 +105,14 @@ export class ChunkManager {
|
|
|
115
105
|
return { remove: () => { if (this.plants === planter) this.plants = NO_VEG; } };
|
|
116
106
|
}
|
|
117
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Draw these chunks. Hooks: add(c) (generated: c.data holds the arrays pos / nor / col / uv / tex, c.cx / c.cz the chunk), change(c) (an edit
|
|
110
|
+
* rewrote c.data; the vertex count can differ on the rim of a shape with diagonal 'adaptive'), remove(c) (released), show(c, visible) (in the camera view or not). Chunks already loaded are added at
|
|
111
|
+
* once. This is how a draw part that replaces 'terrain-draw' draws the ground. Returns { remove() } (ctx.track it).
|
|
112
|
+
* @example ctx.track(engine.terrain.view({ add(c) { draw(c) }, remove(c) { undraw(c) } }))
|
|
113
|
+
* @param {{ add?: (c: any) => void, change?: (c: any) => void, remove?: (c: any) => void, show?: (c: any, visible: boolean) => void }} v
|
|
114
|
+
* @returns {{ remove(): void }}
|
|
115
|
+
*/
|
|
118
116
|
view(v) {
|
|
119
117
|
this.views.add(v);
|
|
120
118
|
for (const c of this.chunks.values()) if (c.state === 'ready') v.add?.(c);
|
|
@@ -129,12 +127,13 @@ export class ChunkManager {
|
|
|
129
127
|
*/
|
|
130
128
|
registerSpecies(name, rule) {
|
|
131
129
|
this.lane.broadcast({ type: 'species', name, rule }, 'species:' + name);
|
|
130
|
+
this.vgen++; // a chunk already on its way carries the old species list: update() asks again when it arrives
|
|
132
131
|
if (!this.plants.get(name)?.nearOnly) this._regrow([name]);
|
|
133
|
-
else
|
|
132
|
+
else this._regrowNear([name]);
|
|
134
133
|
}
|
|
135
134
|
/** Replace the terrain config in every worker (height map loaded, recolor); species is the full rule table */
|
|
136
135
|
reinit(terrainCfg, species) {
|
|
137
|
-
this.
|
|
136
|
+
this.generator = createTerrain(terrainCfg);
|
|
138
137
|
this.edits.attach();
|
|
139
138
|
this.lane.broadcast({ type: 'init', terrain: terrainCfg, species }, 'init');
|
|
140
139
|
this.rebuild();
|
|
@@ -154,7 +153,7 @@ export class ChunkManager {
|
|
|
154
153
|
const key = job.cx + ',' + job.cz, c = this.chunks.get(key);
|
|
155
154
|
if (!c || job.gen !== this.gen) return;
|
|
156
155
|
if (!job.terrain) {
|
|
157
|
-
if (job.regrow) c
|
|
156
|
+
if (job.regrow) this._regrown(c);
|
|
158
157
|
c.pendingDetail = false; for (const name of job.species || []) c.detailDone.add(name);
|
|
159
158
|
reportError(this.engine, err, 'terrain chunk worker job'); // one key: a broken rule fails every chunk, report it once
|
|
160
159
|
return;
|
|
@@ -177,24 +176,38 @@ export class ChunkManager {
|
|
|
177
176
|
}
|
|
178
177
|
|
|
179
178
|
/**
|
|
180
|
-
* View distance (in chunks). Also moves the camera far plane out to it; with terrain({ viewFog: true }) the signal uViewDistance follows too (
|
|
181
|
-
*
|
|
179
|
+
* View distance (in chunks). Also moves the camera far plane out to it; with terrain({ viewFog: true }) the signal uViewDistance follows too (see viewFogFar;
|
|
180
|
+
* the game's fog is its own)
|
|
182
181
|
*/
|
|
183
182
|
setViewChunks(n) {
|
|
184
|
-
this.
|
|
185
|
-
|
|
186
|
-
e.viewFar(d + 150); // chunks in view must not be clipped (unless the game owns camera.far)
|
|
183
|
+
this._viewChunks = n;
|
|
184
|
+
this.engine.viewFar(this._viewMeters() + 150); // chunks in view must not be clipped (unless the game owns camera.far)
|
|
187
185
|
}
|
|
186
|
+
/** @internal the view distance in meters */
|
|
187
|
+
_viewMeters() { return (this._viewChunks - 0.3) * this.generator.CHUNK; }
|
|
188
188
|
/** The view distance the signal uViewDistance gets with terrain({ viewFog: true }) (meters), else null; never scene.fog itself */
|
|
189
|
-
get viewFogFar() { return this.viewFog ?
|
|
189
|
+
get viewFogFar() { return this.viewFog ? this._viewMeters() : null; }
|
|
190
190
|
/** Vegetation density multiplier: plants are placed again on the loaded chunks; the ground and its collision stay, old trees block until the new ones are in */
|
|
191
|
-
setDensity(d) { this.
|
|
192
|
-
//
|
|
193
|
-
|
|
191
|
+
setDensity(d) { this._density = d; this.vgen++; this._regrow(this.plants.baseNames()); this._regrowNear(this.plants.nearNames()); }
|
|
192
|
+
// Why setters: a plain write used to change the number and nothing else (no far plane, no new plants), with no error
|
|
193
|
+
/** View distance (in chunks); writing it takes effect like setViewChunks */
|
|
194
|
+
get viewChunks() { return this._viewChunks; }
|
|
195
|
+
set viewChunks(n) { this.setViewChunks(n); }
|
|
196
|
+
/** Vegetation density multiplier; writing it takes effect like setDensity */
|
|
197
|
+
get density() { return this._density; }
|
|
198
|
+
set density(d) { this.setDensity(d); }
|
|
199
|
+
// plants-only jobs for every loaded chunk (the ground and its collision stay; near-only species: _regrowNear). c.regrow counts the ones not yet
|
|
200
|
+
// mounted: readyAt is false until they are, so a headless page (core/engine/headlessLoad.js) keeps running loading frames and stateApplied
|
|
194
201
|
// waits for the new plants, as it did when a species dropped the whole terrain
|
|
195
202
|
_regrow(names) {
|
|
196
203
|
if (!names.length) return;
|
|
197
|
-
for (const c of this.chunks.values()) if (c.state === 'ready') { c.regrow
|
|
204
|
+
for (const c of this.chunks.values()) if (c.state === 'ready') { c.regrow++; this._send({ ...this._job(c, false, names), regrow: true }); }
|
|
205
|
+
}
|
|
206
|
+
// one regrow job came back. A chunk released and loaded again meanwhile is a new record with nothing counted
|
|
207
|
+
_regrown(c) { if (c.regrow > 0) c.regrow--; }
|
|
208
|
+
// near-only species: dropped here, and the LOD pass places them again on the chunks within their ring (never on the far ones _regrow would reach)
|
|
209
|
+
_regrowNear(names) {
|
|
210
|
+
for (const c of this.chunks.values()) { for (const n of names) { this.plants.unmount(c, n); c.detailDone.delete(n); } c.level = -1; }
|
|
198
211
|
}
|
|
199
212
|
|
|
200
213
|
rebuild() {
|
|
@@ -212,15 +225,12 @@ export class ChunkManager {
|
|
|
212
225
|
* Ring 1, which the loading screen waits for, takes effect the moment play starts (lag 0); farther rings get more worker time
|
|
213
226
|
*/
|
|
214
227
|
_queue(cx, cz, key) {
|
|
215
|
-
const c = { cx, cz, key, state: 'queued', data: null, plants: {}, colliders: {}, inView: true, pendingDetail: false, detailDone: new Set(), level: -1, sphere: null, solid: false, gen: this.gen };
|
|
228
|
+
const c = { cx, cz, key, state: 'queued', data: null, plants: {}, colliders: {}, inView: true, pendingDetail: false, detailDone: new Set(), level: -1, sphere: null, solid: false, gen: this.gen, regrow: 0 };
|
|
216
229
|
this.chunks.set(key, c);
|
|
217
|
-
|
|
218
|
-
c.ticket = this.engine.commits.request({
|
|
219
|
-
lag: !this.engine.ready && ring <= 1 ? 0 : COLLIDER_LAG * (1 + ring),
|
|
230
|
+
bookCollision(this, c, this._ring(c), {
|
|
220
231
|
// collision counts from this step on (a new token makes the physics module build this chunk's collision)
|
|
221
232
|
apply: () => { c.solid = true; c.colToken = {}; },
|
|
222
233
|
fallback: () => this._forceReady(c),
|
|
223
|
-
valid: () => this.chunks.get(c.key) === c && c.gen === this.gen,
|
|
224
234
|
});
|
|
225
235
|
return c;
|
|
226
236
|
}
|
|
@@ -229,6 +239,7 @@ export class ChunkManager {
|
|
|
229
239
|
* waiting for replies would idle the worker)
|
|
230
240
|
*/
|
|
231
241
|
_pump() {
|
|
242
|
+
if (!this._want.length) return;
|
|
232
243
|
const species = this.plants.baseNames(), max = this.engine.ready ? Math.max(this.maxInFlight, 2 * this.lane.size) : Infinity;
|
|
233
244
|
while (this.inFlight < max && this._want.length) {
|
|
234
245
|
const c = this._want.shift();
|
|
@@ -240,7 +251,7 @@ export class ChunkManager {
|
|
|
240
251
|
|
|
241
252
|
/** sources: engine.stream.sources() (every stream source; a source radius caps the view distance) */
|
|
242
253
|
update(sources, camera) {
|
|
243
|
-
this._stream.follow(sources, this.
|
|
254
|
+
this._stream.follow(sources, this.generator.CHUNK, this.viewChunks); // queue what a source needs, release what is far from all
|
|
244
255
|
this._pump();
|
|
245
256
|
this.stats.queued = this._want.length;
|
|
246
257
|
|
|
@@ -251,17 +262,18 @@ export class ChunkManager {
|
|
|
251
262
|
for (const r of this.ready) {
|
|
252
263
|
const c = this.chunks.get(r.cx + ',' + r.cz);
|
|
253
264
|
if (!c || r.gen !== this.gen) continue;
|
|
254
|
-
if (this._stale(c, r)) { if (r.regrow) c
|
|
265
|
+
if (this._stale(c, r)) { if (r.regrow) this._regrown(c); continue; }
|
|
255
266
|
if (built > 0 && performance.now() - t0 >= this.applyBudgetMs // measure
|
|
256
267
|
&& !(loading && this._ring(c) <= 1)) { later.push(r); continue; }
|
|
257
268
|
if (r.terrain) { if (c.state === 'ready') continue; this._applyTerrain(c, r.terrain); c.ticket?.resolve(true); }
|
|
258
269
|
else if (c.state !== 'ready') continue;
|
|
259
|
-
if (r.vgen !== this.vgen) { // placed with an old density: keep the ground, ask for
|
|
260
|
-
if (
|
|
261
|
-
|
|
270
|
+
if (r.vgen !== this.vgen) { // placed with an old density or species list: keep the ground, ask for the plants again
|
|
271
|
+
if (r.terrain) c.regrow++; else c.pendingDetail = false;
|
|
272
|
+
// a regrow stays counted until its plants are in; a new chunk asks for today's species, not the list it left with
|
|
273
|
+
this._send({ ...this._job(c, false, r.terrain ? this.plants.baseNames() : Object.keys(r.veg)), regrow: !!(r.regrow || r.terrain) });
|
|
262
274
|
} else {
|
|
263
275
|
for (const name in r.veg) this.plants.mount(c, name, r.veg[name]);
|
|
264
|
-
if (r.regrow) c
|
|
276
|
+
if (r.regrow) this._regrown(c);
|
|
265
277
|
if (!r.terrain) { c.pendingDetail = false; for (const name in r.veg) c.detailDone.add(name); }
|
|
266
278
|
}
|
|
267
279
|
c.level = -1; built++;
|
|
@@ -290,12 +302,17 @@ export class ChunkManager {
|
|
|
290
302
|
|
|
291
303
|
// a generated chunk: keep its arrays and bounds, tell the draw parts
|
|
292
304
|
_applyTerrain(c, t) {
|
|
293
|
-
c.
|
|
294
|
-
|
|
295
|
-
c.sphere = new THREE.Sphere(new THREE.Vector3(t.sphere[0], t.sphere[1], t.sphere[2]), t.sphere[3]);
|
|
305
|
+
c.sphere = new THREE.Sphere();
|
|
306
|
+
this._adopt(c, t);
|
|
296
307
|
c.state = 'ready';
|
|
297
308
|
this._emit('add', c);
|
|
298
309
|
}
|
|
310
|
+
/** @internal the arrays a chunk now holds, freshly generated or rebuilt by an edit */
|
|
311
|
+
_adopt(c, t) {
|
|
312
|
+
c.data = t;
|
|
313
|
+
if (t.top != null) { c.solidCount = t.solid; this.lowest = Math.min(this.lowest, t.minH); } // island: collision takes top and sides, not the bottom
|
|
314
|
+
c.sphere.center.set(t.sphere[0], t.sphere[1], t.sphere[2]); c.sphere.radius = t.sphere[3];
|
|
315
|
+
}
|
|
299
316
|
|
|
300
317
|
// due but not ready: if the worker result already arrived take it now, else generate on the main thread (same code, same result).
|
|
301
318
|
// A failed chunk is not tried here (it was reported; the main thread would throw the same error at every commit)
|
|
@@ -304,8 +321,8 @@ export class ChunkManager {
|
|
|
304
321
|
const i = this.ready.findIndex(r => r.terrain && r.cx === c.cx && r.cz === c.cz && r.gen === c.gen && r.ev === this.edits.version(c.key));
|
|
305
322
|
let r = i >= 0 ? this.ready.splice(i, 1)[0] : null;
|
|
306
323
|
if (!r || r.vgen !== this.vgen) {
|
|
307
|
-
r = { terrain: r?.terrain ?? this.
|
|
308
|
-
for (const name of this.plants.baseNames()) r.veg[name] = this.
|
|
324
|
+
r = { terrain: r?.terrain ?? this.generator.buildChunk(c.cx, c.cz), veg: {} };
|
|
325
|
+
for (const name of this.plants.baseNames()) r.veg[name] = this.generator.place(c.cx, c.cz, this.plants.get(name).rule, this.density);
|
|
309
326
|
}
|
|
310
327
|
this._applyTerrain(c, r.terrain);
|
|
311
328
|
for (const name in r.veg) this.plants.mount(c, name, r.veg[name]);
|
|
@@ -330,12 +347,13 @@ export class ChunkManager {
|
|
|
330
347
|
P.ring?.(c, ring);
|
|
331
348
|
}
|
|
332
349
|
|
|
333
|
-
/** Stop the chunk workers (called by terrain dispose; in-flight results are discarded) */
|
|
334
|
-
dispose() { this.lane.dispose(); this.
|
|
350
|
+
/** Stop the chunk workers and release the chunks with their commit tickets (called by terrain dispose; in-flight results are discarded) */
|
|
351
|
+
dispose() { this.lane.dispose(); this.rebuild(); }
|
|
335
352
|
/** @internal vegetation / settings plumbing */
|
|
336
353
|
refreshLevels() { for (const c of this.chunks.values()) c.level = -1; }
|
|
337
354
|
|
|
338
355
|
_dispose(c) {
|
|
356
|
+
if (c.state === 'failed') this.stats.failed--; // the count is of failed chunks loaded now: retry() can only send those
|
|
339
357
|
if (c.state !== 'ready') return;
|
|
340
358
|
this.plants.drop(c);
|
|
341
359
|
this._emit('remove', c);
|
|
@@ -1,33 +1,16 @@
|
|
|
1
1
|
// Readiness and collision queries on loaded chunks (mixed into ChunkManager.prototype), read by loading and by the collision and physics
|
|
2
2
|
// modules through the ground API.
|
|
3
|
-
import {
|
|
3
|
+
import { collidersNear, ringsReady } from '../../core/stream/chunkStream.js';
|
|
4
4
|
|
|
5
5
|
export const chunkQueries = {
|
|
6
|
-
/** Whether chunks within `rings` rings (default 1) of a position are generated (for the loading screen); solid: also their collision has taken effect */
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const c = this.chunks.get((pcx + dx) + ',' + (pcz + dz));
|
|
11
|
-
if (!c || c.state !== 'ready' || c.regrow > 0 || solid && !c.solid) return false; // regrow: plants of a species added later still on the way
|
|
12
|
-
}
|
|
13
|
-
return true;
|
|
6
|
+
/** @internal Whether chunks within `rings` rings (default 1) of a position are generated (for the loading screen); solid: also their collision has taken effect */
|
|
7
|
+
readyAt(position, { rings = 1, solid = false } = {}) {
|
|
8
|
+
// regrow: plants of a species added later still on the way
|
|
9
|
+
return ringsReady(this.chunks, this.generator.CHUNK, position, rings, c => c?.state === 'ready' && !(c.regrow > 0) && (!solid || c.solid));
|
|
14
10
|
},
|
|
15
11
|
|
|
16
12
|
/** @internal Iterate collision circles near (x,z): fn(cx, cz, r). Only queries loaded chunks near the player */
|
|
17
|
-
forEachCollider(x, z, range, fn) {
|
|
18
|
-
const CH = this.T.CHUNK, x0 = Math.floor((x - range) / CH), x1 = Math.floor((x + range) / CH), z0 = Math.floor((z - range) / CH), z1 = Math.floor((z + range) / CH);
|
|
19
|
-
for (let cz = z0; cz <= z1; cz++) for (let cx = x0; cx <= x1; cx++) {
|
|
20
|
-
const c = this.chunks.get(cx + ',' + cz);
|
|
21
|
-
if (!c?.solid) continue;
|
|
22
|
-
for (const n in c.colliders) {
|
|
23
|
-
const k = c.colliders[n];
|
|
24
|
-
for (let i = 0; i < k.length; i += 3) {
|
|
25
|
-
const dx = k[i] - x, dz = k[i + 1] - z, rr = range + k[i + 2];
|
|
26
|
-
if (dx * dx + dz * dz < rr * rr) fn(k[i], k[i + 1], k[i + 2]);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
},
|
|
13
|
+
forEachCollider(x, z, range, fn) { collidersNear(this.chunks, this.generator.CHUNK, x, z, range, fn); },
|
|
31
14
|
|
|
32
15
|
/** @internal Collision data of a chunk (for the physics module): terrain triangles (chunk-local coordinates) + vegetation collision circles. Returns null if not generated.
|
|
33
16
|
* token tells whether the ground was regenerated, treeToken whether its tree circles changed */
|
|
@@ -39,6 +22,6 @@ export const chunkQueries = {
|
|
|
39
22
|
const p = c.data.pos, positions = c.solidCount == null ? p : p.subarray(0, c.solidCount * 3);
|
|
40
23
|
// treeToken: only the tree circles changed (density, a felled tree): physics rebuilds the trunks, not the ground triangles
|
|
41
24
|
const token = c.colToken ?? c;
|
|
42
|
-
return { token, treeToken: c.treeToken ?? token, positions, ox: cx * this.
|
|
25
|
+
return { token, treeToken: c.treeToken ?? token, positions, ox: cx * this.generator.CHUNK, oz: cz * this.generator.CHUNK, circles: Object.values(c.colliders) };
|
|
43
26
|
},
|
|
44
27
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Terrain worker: generates chunk meshes and vegetation placement off the main thread (one per engine.threads slot).
|
|
2
|
-
import { serve } from '../../core/threadServe.js';
|
|
2
|
+
import { serve } from '../../core/threads/threadServe.js';
|
|
3
3
|
import { chunkHandler } from './chunkJob.js';
|
|
4
4
|
|
|
5
5
|
serve(chunkHandler());
|
package/modules/terrain/draw.js
CHANGED
|
@@ -7,18 +7,19 @@
|
|
|
7
7
|
// (engine.use(myGround, { replaces: 'terrain-draw' })) and keep everything that plays. A replacement draw part does what this file does:
|
|
8
8
|
// install(e, ctx) { ctx.track(e.terrain.view({ add(c) {...c.data.pos...}, change(c) {...}, remove(c) {...}, show(c, visible) {...} })); }
|
|
9
9
|
// This file never changes chunk data; it only reads it.
|
|
10
|
-
import { engineOwned } from '../../core/things.js';
|
|
10
|
+
import { engineOwned } from '../../core/scene/things.js';
|
|
11
|
+
import { needMaterial } from '../../core/base/validate.js';
|
|
11
12
|
import * as THREE from 'three';
|
|
12
13
|
import { terrainMaterial } from '../../render/materials.js';
|
|
13
14
|
import { patchesOf, unpatchMaterial } from '../../render/patches.js';
|
|
14
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
15
|
-
import { codedError } from '../../core/errorHints.js';
|
|
15
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
16
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
16
17
|
import { mountColorMap, updateColorMap, disposeColorMap } from './terrainTexture.js';
|
|
18
|
+
import { SHADINGS, NORMALS } from './terrainDefaults.js';
|
|
17
19
|
|
|
18
20
|
// what the workers bake into each chunk: a change rebuilds every chunk
|
|
19
21
|
const BAKED = ['colors', 'biomeColors', 'steep', 'variation', 'shading', 'normals'];
|
|
20
22
|
const RECOLOR_KEYS = [...BAKED, 'detail'];
|
|
21
|
-
const SHADINGS = ['smooth', 'flat', 'texture'], NORMALS = ['smooth', 'flat'];
|
|
22
23
|
|
|
23
24
|
/** Check the picture values terrain({...}) and engine.terrain.recolor take; null is "none" for each @param {string} where @param {any} o */
|
|
24
25
|
export function checkGround(where, o) {
|
|
@@ -58,7 +59,7 @@ export class TerrainDraw {
|
|
|
58
59
|
/** @internal view hook: a chunk was generated (or regenerated after a full rebuild) */
|
|
59
60
|
add(c) {
|
|
60
61
|
const t0 = performance.now(); // measure: the 'build' stage of engine.budget.cost
|
|
61
|
-
const t = c.data, CH = this.w.
|
|
62
|
+
const t = c.data, CH = this.w.chunkSize, g = new THREE.BufferGeometry();
|
|
62
63
|
g.setAttribute('position', new THREE.BufferAttribute(t.pos, 3));
|
|
63
64
|
g.setAttribute('normal', new THREE.BufferAttribute(t.nor, 3));
|
|
64
65
|
g.setAttribute('color', new THREE.BufferAttribute(t.col, 3));
|
|
@@ -78,13 +79,15 @@ export class TerrainDraw {
|
|
|
78
79
|
this.engine.scene.add(engineOwned('terrain', rec.group));
|
|
79
80
|
this.engine.budget.cost.end('build', t0);
|
|
80
81
|
}
|
|
81
|
-
/** @internal view hook: an edit rebuilt the chunk's arrays
|
|
82
|
+
/** @internal view hook: an edit rebuilt the chunk's arrays */
|
|
82
83
|
change(c) {
|
|
83
84
|
const rec = this.meshes.get(c); if (!rec) return;
|
|
84
85
|
const g = rec.mesh.geometry, t = c.data;
|
|
86
|
+
// the rim of a shape with diagonal 'adaptive': the diagonal follows the heights and cuts a boundary cell into a different number of triangles
|
|
87
|
+
if (g.attributes.position.array.length !== t.pos.length || (g.groups.length && g.groups[0].count !== t.top)) { this.remove(c); this.add(c); return; }
|
|
85
88
|
for (const [n, a] of [['position', t.pos], ['normal', t.nor], ['color', t.col], ['uv', t.uv]]) { g.attributes[n].array.set(a); g.attributes[n].needsUpdate = true; }
|
|
86
89
|
if (t.tex && rec.colorTex) updateColorMap(rec, t.tex);
|
|
87
|
-
g.
|
|
90
|
+
g.boundingSphere = g.boundingBox = null; // only rays read them (chunks are not frustum culled): worked out again when asked
|
|
88
91
|
}
|
|
89
92
|
/** @internal view hook: the chunk was released */
|
|
90
93
|
remove(c) {
|
|
@@ -104,7 +107,7 @@ export class TerrainDraw {
|
|
|
104
107
|
*/
|
|
105
108
|
get material() { return this._material; }
|
|
106
109
|
set material(m) {
|
|
107
|
-
|
|
110
|
+
needMaterial('terrain-option', 'engine.terrain.material', m, '; e.g. engine.terrain.material = applyEffects(new THREE.MeshStandardMaterial({ vertexColors: true }), { patches: engine.terrain.patches })');
|
|
108
111
|
const was = this._material;
|
|
109
112
|
if (m === was) return;
|
|
110
113
|
this._material = m;
|
|
@@ -132,7 +135,7 @@ export class TerrainDraw {
|
|
|
132
135
|
if (!baked.length) return;
|
|
133
136
|
const next = { ...this._config.get() };
|
|
134
137
|
for (const k of baked) if (o[k] == null) delete next[k]; else next[k] = o[k];
|
|
135
|
-
next.shading
|
|
138
|
+
if (next.shading == null && this._shading != null) next.shading = this._shading; // a key holding undefined would hide createTerrain's default
|
|
136
139
|
this._config.set(next);
|
|
137
140
|
this.w.reinit(next, this._config.species());
|
|
138
141
|
}
|
|
@@ -144,11 +147,11 @@ export class TerrainDraw {
|
|
|
144
147
|
|
|
145
148
|
// texture shading: a material with this chunk's color map. Island sides keep vertex colors (the map is sampled by world xz and would smear down them)
|
|
146
149
|
_materialFor(rec, c) {
|
|
147
|
-
const t = c.data, CH = this.w.
|
|
150
|
+
const t = c.data, CH = this.w.chunkSize;
|
|
148
151
|
const mat = t.tex ? mountColorMap(this.engine, this.material, rec, t.tex, c.cx * CH, c.cz * CH, CH) : this.material;
|
|
149
152
|
const rest = t.top != null ? t.pos.length / 3 - t.top : 0;
|
|
150
153
|
return rest && (t.tex || this.sideMat) ? [mat, this.sideMat ?? this.material] : mat;
|
|
151
154
|
}
|
|
152
155
|
|
|
153
|
-
dispose() { this._view.remove(); }
|
|
156
|
+
dispose() { this._view.remove(); this._own.dispose(); }
|
|
154
157
|
}
|
package/modules/terrain/index.js
CHANGED
|
@@ -10,39 +10,40 @@
|
|
|
10
10
|
// Settings a function needs travel as params (plain data, read as n.params). The engine still does chunks, streaming, collision, flatten and edits on top.
|
|
11
11
|
// Height map: terrain({ heightmap: { url: '/textures/height.png', size: [1024, 1024], min: -5, max: 60 } }), a grayscale image, whiter is higher, read at startup.
|
|
12
12
|
// Colors: terrain({ colors, biomeColors, steep, variation }), plain data the workers bake into each chunk; a type without a color is neutral gray.
|
|
13
|
-
// engine.terrain.recolor({ ... }) changes them at run time (recipes/36-
|
|
14
|
-
// Shading: 'smooth' | 'flat' | 'texture' (per-chunk color map, colors independent of the mesh; see recipes/
|
|
13
|
+
// engine.terrain.recolor({ ... }) changes them at run time (recipes/36-ground-plants.md).
|
|
14
|
+
// Shading: 'smooth' | 'flat' | 'texture' (per-chunk color map, colors independent of the mesh; see recipes/53-ground-up-close.md).
|
|
15
15
|
// Material: terrain({ material }), a Material or (engine) => Material; chunks carry position, normal, color and uv (world xz / chunk size, continuous
|
|
16
16
|
// across chunks). Cloud shadows, season tint and terrain({ detail }) are added to it; terrain({ material, effects: false }) draws it exactly as given.
|
|
17
17
|
// engine.terrain.material = m at any time draws m as given too; engine.terrain.patches keeps the effects on it (applyEffects(m, { patches })).
|
|
18
18
|
// Edits: engine.terrain.edit(pos, { radius: 2, lower: 1 }) digs; { paint: 'tilled' } paints a ground type (its color: terrain({ biomeColors })). Saved, see terrainEdit.js.
|
|
19
19
|
|
|
20
20
|
// Outline: terrain({ shape: { mask: (x, z, n) => 40 - Math.hypot(x, z), side: { depth: 2 } } }) keeps ground only where mask > 0 (an island
|
|
21
|
-
// with cliff sides); off it engine.surface is -Infinity, engine.ground.has false, and a fall emits terrain:void. See recipes/
|
|
21
|
+
// with cliff sides); off it engine.surface is -Infinity, engine.ground.has false, and a fall emits terrain:void. See recipes/28-terrain.md.
|
|
22
22
|
|
|
23
23
|
import { ChunkManager } from './ChunkManager.js';
|
|
24
24
|
import { DEFAULT_TERRAIN } from './terrainGen.js';
|
|
25
25
|
|
|
26
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
27
|
-
import { compilePure } from '../../core/threadPure.js';
|
|
28
|
-
import { warnOnce } from '../../core/validate.js';
|
|
29
|
-
import { loadGray } from '../../core/grayMap.js';
|
|
26
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
27
|
+
import { compilePure } from '../../core/threads/threadPure.js';
|
|
28
|
+
import { warnOnce } from '../../core/base/validate.js';
|
|
29
|
+
import { loadGray } from '../../core/scene/grayMap.js';
|
|
30
30
|
import { prepareShape, voidWatcher } from './terrainShapeMain.js';
|
|
31
31
|
import { TerrainDraw, checkGround } from './draw.js';
|
|
32
|
-
import { codedError } from '../../core/errorHints.js';
|
|
32
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
33
33
|
|
|
34
34
|
const NO_HEIGHT = 'terrain(): no height function or height map was given, so the ground is flat gray at y = 0 (a placeholder, not a picture). '
|
|
35
35
|
+ 'Pass terrain({ height, groundType }) or a preset, e.g. terrain({ ...terrainPreset() }) with terrainPreset from @threedog/terrain-noise';
|
|
36
36
|
|
|
37
37
|
export { createTerrain, DEFAULT_TERRAIN } from './terrainGen.js';
|
|
38
38
|
|
|
39
|
-
const
|
|
39
|
+
const VIEW = { viewChunks: 4, density: 1 };
|
|
40
|
+
const TERRAIN_PARAMS = keysSchema(['viewChunks', 'density', 'material', 'effects', 'detail', 'variation', 'viewFog', ...Object.keys(DEFAULT_TERRAIN)], { ...DEFAULT_TERRAIN, ...VIEW, viewFog: false }); // defaults shown in the catalog; createTerrain applies the real ones
|
|
40
41
|
|
|
41
42
|
export function terrain(opts = {}) {
|
|
42
43
|
readParams('terrain', TERRAIN_PARAMS, opts);
|
|
43
44
|
checkGround('terrain', opts);
|
|
44
45
|
// material and detail stay on the main thread (a texture, a function): everything left in cfg is plain data for the workers
|
|
45
|
-
const { viewChunks =
|
|
46
|
+
const { viewChunks = VIEW.viewChunks, density = VIEW.density, material, effects, detail = null, viewFog = false, ...cfg } = opts;
|
|
46
47
|
// effects only says how the game's own material is used: without one it would silently do nothing
|
|
47
48
|
if (effects !== undefined && (material == null || typeof effects !== 'boolean'))
|
|
48
49
|
throw codedError('terrain-option', 'terrain({ effects }): goes with your own material, terrain({ material: myMaterial, effects: false }) = drawn as given (no cloud shadow / season / detail patch); got ' + JSON.stringify({ effects, material: material == null ? material : typeof material }));
|
|
@@ -65,30 +66,33 @@ export function terrain(opts = {}) {
|
|
|
65
66
|
sideMat = terrainCfg.shape ? prepareShape(terrainCfg) : null;
|
|
66
67
|
w = new ChunkManager(e, terrainCfg);
|
|
67
68
|
if (terrainCfg.shape) watchVoid = voidWatcher(e, w);
|
|
68
|
-
w.
|
|
69
|
-
w.viewFog = viewFog; // opt-in: the
|
|
69
|
+
w._density = density; // before anything is placed: nothing to place again yet
|
|
70
|
+
w.viewFog = viewFog; // opt-in: the view distance goes out as the signal uViewDistance (a game's fog reads it to hide the edge)
|
|
70
71
|
state.cfg = terrainCfg;
|
|
71
72
|
e.setGround({
|
|
72
|
-
height: (x, z) => w.
|
|
73
|
-
slope: (x, z) => w.
|
|
74
|
-
type: (x, z) => w.
|
|
75
|
-
waterLevel: w.
|
|
73
|
+
height: (x, z) => w.generator.surface(x, z),
|
|
74
|
+
slope: (x, z) => w.generator.slope(x, z),
|
|
75
|
+
type: (x, z) => w.generator.biomeAt(x, z, w.generator.surface(x, z), w.generator.slope(x, z)), // 'void' outside terrain({ shape })
|
|
76
|
+
waterLevel: w.generator.waterLevel,
|
|
76
77
|
// public collision API: the collision and physics modules read terrain only through these, never chunk internals
|
|
77
78
|
forEachCollider: (x, z, range, fn) => w.forEachCollider(x, z, range, fn),
|
|
78
|
-
chunkSize: w.
|
|
79
|
-
viewRange: () => w.viewChunks * w.
|
|
79
|
+
chunkSize: w.generator.CHUNK,
|
|
80
|
+
viewRange: () => w.viewChunks * w.generator.CHUNK, // stream entries build within the terrain view by default
|
|
80
81
|
chunkCollision: (cx, cz) => w.chunkCollision(cx, cz),
|
|
81
|
-
has: (x, z) => w.
|
|
82
|
+
has: (x, z) => w.generator.has(x, z),
|
|
82
83
|
voidY: () => w.voidY, // the physics module reports its own bodies falling below it (terrain:void)
|
|
83
84
|
});
|
|
84
85
|
w.setViewChunks(viewChunks);
|
|
85
86
|
// a source is ready when the ring around it is generated, and for a physics source its collision has taken effect (chunkCollision non-null)
|
|
86
|
-
e.stream.
|
|
87
|
-
ctx.track(e.events.on('settings:shadows', () => w.refreshLevels()));
|
|
87
|
+
ctx.track(e.stream.addReadyCheck('terrain', s => w.readyAt(s, { rings: 1 }) && (!s.physics || w.readyAt(s, { rings: 1, solid: true }))));
|
|
88
88
|
e.budget.metric('chunkApplyMs', () => w.stats.applyMs); // chunk upload ms per frame (the limit comes from the game's budget)
|
|
89
89
|
return w;
|
|
90
90
|
},
|
|
91
|
-
frame(dt, e) {
|
|
91
|
+
frame(dt, e) {
|
|
92
|
+
w.update(e.stream.sources(), e.camera); // chunks load around every engine.stream source
|
|
93
|
+
// shortcut: the value stays after the terrain unloads; upgrade if a game swaps terrains with different ranges
|
|
94
|
+
const far = w.viewFogFar; if (far != null) e.uniforms.uViewDistance.value = far;
|
|
95
|
+
},
|
|
92
96
|
fixed() { watchVoid?.(); }, // terrain({ shape }) only: falls below voidY are gameplay, so they are seen on the fixed step
|
|
93
97
|
describe(e, ctx) { ctx.out.perf.chunks = { loaded: w.stats.loaded ?? 0, visible: w.stats.visible ?? 0, queued: w.stats.queued, failed: w.stats.failed }; },
|
|
94
98
|
// height map / mask image wait for the image: after it loads, rebuild terrain with the new config (both the main-thread copy and the workers)
|
|
@@ -102,10 +106,10 @@ export function terrain(opts = {}) {
|
|
|
102
106
|
if (needM) cfg2.shape = { ...cfg2.shape, mask: { ...mk, ...await loadGray(mk.url), url: undefined } };
|
|
103
107
|
w.reinit(cfg2, speciesRules(w));
|
|
104
108
|
},
|
|
105
|
-
isReady(e) { return e.stream.sources().every(s => w.
|
|
109
|
+
isReady(e) { return e.stream.sources().every(s => w.readyAt(s)); },
|
|
106
110
|
dispose() { w.dispose(); },
|
|
107
111
|
};
|
|
108
|
-
let drawPart = null
|
|
112
|
+
let drawPart = null;
|
|
109
113
|
const lookModule = {
|
|
110
114
|
// the same terrain({...}) call: material / effects are read here, the rest by the data part
|
|
111
115
|
name: 'terrainDraw', type: 'picture', label: 'Terrain drawing', params: TERRAIN_PARAMS, options: opts, requires: ['terrain'], provides: ['terrain-draw'], stage: 'effects',
|
|
@@ -114,13 +118,11 @@ export function terrain(opts = {}) {
|
|
|
114
118
|
// the colors the workers bake into each chunk: no chunk is generated before the first frame, so this reinit only swaps the config
|
|
115
119
|
state.cfg = { ...state.cfg, ...drawConfig(e, cfg) };
|
|
116
120
|
w.reinit(state.cfg, speciesRules(w));
|
|
117
|
-
fog = viewFogSync(e);
|
|
118
121
|
// effects false (terrain({ material, effects: false })): the game's material is drawn untouched
|
|
119
122
|
drawPart = w.drawPart = new TerrainDraw(e, w, { material, effects: material == null || effects !== false, detail, sideMat,
|
|
120
123
|
config: { get: () => state.cfg, set: c => { state.cfg = c; }, species: () => speciesRules(w) } });
|
|
121
124
|
return drawPart;
|
|
122
125
|
},
|
|
123
|
-
frame() { fog(w.viewFogFar); },
|
|
124
126
|
describe() { return { chunks: drawPart?.meshes.size ?? 0 }; },
|
|
125
127
|
dispose() { drawPart?.dispose(); drawPart = w.drawPart = null; },
|
|
126
128
|
};
|
|
@@ -139,13 +141,5 @@ function drawConfig(e, cfg) {
|
|
|
139
141
|
return out;
|
|
140
142
|
}
|
|
141
143
|
|
|
142
|
-
/**
|
|
143
|
-
* terrain({ viewFog: true }): the view distance goes out as the signal uViewDistance; the fog itself is the game's, which reads it for its far.
|
|
144
|
-
* shortcut: the value stays after the terrain unloads; upgrade if a game swaps terrains with different ranges.
|
|
145
|
-
*/
|
|
146
|
-
function viewFogSync(e) {
|
|
147
|
-
return far => { if (far != null) e.uniforms.uViewDistance.value = far; };
|
|
148
|
-
}
|
|
149
|
-
|
|
150
144
|
/** Every species' placement rule (the workers get the full table when the terrain config is replaced) */
|
|
151
145
|
function speciesRules(w) { const out = {}; for (const sp of w.plants.list()) out[sp.name] = sp.rule; return out; }
|
|
@@ -18,15 +18,18 @@ export function makeColorMap({ cfg, CHUNK, CELL, surface, faceColor, paintColor,
|
|
|
18
18
|
const LUT = new Uint8Array(4097);
|
|
19
19
|
for (let i = 0; i <= 4096; i++) LUT[i] = Math.round(255 * toSRGB(i / 4096));
|
|
20
20
|
const enc = v => LUT[v <= 0 ? 0 : v >= 1 ? 4096 : (v * 4096 + 0.5) | 0];
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
// keep { data, i0, i1, j0, j1 } (an edit): repaint in place only the pixels in those cells; the rest of data is already right
|
|
22
|
+
return function colorMap(cx, cz, keep = null) {
|
|
23
|
+
const data = keep?.data ?? new Uint8Array(S * S * 4), tmp = [0, 0, 0], ox = cx * CHUNK, oz = cz * CHUNK;
|
|
23
24
|
const ny = new Map(); // grid-point normal.y, shared by the pixels of a cell
|
|
24
25
|
const gny = (i, j) => { const k = i * 100003 + j; let v = ny.get(k); if (v === undefined) ny.set(k, v = gridNormal(i, j)[1]); return v; };
|
|
25
26
|
let o = 0;
|
|
26
27
|
for (let pj = 0; pj < S; pj++) {
|
|
27
28
|
const z = oz + (pj - 0.5) * step, j = Math.floor(z / CELL), fz = z / CELL - j;
|
|
28
29
|
for (let pi = 0; pi < S; pi++, o += 4) {
|
|
29
|
-
const x = ox + (pi - 0.5) * step, i = Math.floor(x / CELL), fx = x / CELL - i
|
|
30
|
+
const x = ox + (pi - 0.5) * step, i = Math.floor(x / CELL), fx = x / CELL - i;
|
|
31
|
+
if (keep && (i < keep.i0 || i > keep.i1 || j < keep.j0 || j > keep.j1)) continue;
|
|
32
|
+
const pt = cellType(i, j);
|
|
30
33
|
if (pt !== undefined) paintColor(pt, (i + 0.5) * CELL, (j + 0.5) * CELL, tmp); // a painted cell is one color, like its vertices
|
|
31
34
|
else {
|
|
32
35
|
// steep-slope tests use the normal interpolated between the 4 grid points, so they do not follow triangle edges either
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// dependency (the Worker reads it too). The engine has no built-in landform or ground types: without a height function (or a height map) the
|
|
3
3
|
// ground is flat at y = 0; generators such as noise hills and biome tables are presets a game passes in (e.g. terrainPreset() from
|
|
4
4
|
// @threedog/terrain-noise) or its own height / groundType functions.
|
|
5
|
+
export const SHADINGS = ['smooth', 'flat', 'texture'], NORMALS = ['smooth', 'flat']; // checked by createTerrain and checkGround
|
|
5
6
|
export const DEFAULT_TERRAIN = {
|
|
6
7
|
seed: 1337,
|
|
7
8
|
chunkSize: 64, // chunk edge length (m)
|
|
@@ -27,7 +28,7 @@ export const DEFAULT_TERRAIN = {
|
|
|
27
28
|
// how each cell is cut into two triangles (shape, so it also moves engine.surface): 'fixed' the same diagonal everywhere |
|
|
28
29
|
// 'adaptive' along the diagonal with the smaller height difference | 'alternate' flips every other cell
|
|
29
30
|
diagonal: 'fixed',
|
|
30
|
-
// World outline (null = ground everywhere): { mask, edge, side, bottom, voidY }, see terrainShape.js and recipes/
|
|
31
|
+
// World outline (null = ground everywhere): { mask, edge, side, bottom, voidY }, see terrainShape.js and recipes/28-terrain.md.
|
|
31
32
|
// mask (x, z, n) -> > 0 ground, pure like height; or a gray image { url | data, width, height, size: [w, l], center, threshold }
|
|
32
33
|
shape: null,
|
|
33
34
|
boundsPad: { up: 3, radius: 8 }, // chunk bounding sphere margin (m): center raised by up, radius grown by radius; raise for tall height-moving shaders
|