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
|
@@ -141,9 +141,9 @@ Every entry of the UI focus stack (dialogue, `engine.ui.open` parts, `makeWindow
|
|
|
141
141
|
`makeWindow` is the one window: it opens on top of the UI focus stack, locks game input while open, closes with its close button or Esc
|
|
142
142
|
(pad B), and its buttons take the choice cursor, so it works with the keyboard, a gamepad and the mouse (opening it lets go of a locked mouse; the next click on
|
|
143
143
|
the view locks again). A window that ends something, win or lose, takes `closable: false`: no close button and Esc does nothing, so the player cannot slip back into the
|
|
144
|
-
game past it and only your buttons end it. Its picture is your `ui.css` /
|
|
144
|
+
game past it and only your buttons end it. Nothing else closes a window: a game that restarts by another road (a new game from the title, a load) closes it on `session:start`. Its picture is your `ui.css` /
|
|
145
145
|
`ui.templates[id]`. A level clear, a match score, a day's earnings or a run summary are all this:
|
|
146
|
-
```js
|
|
146
|
+
```js fragment
|
|
147
147
|
import { makeWindow } from 'threedog';
|
|
148
148
|
const results = makeWindow(engine, {
|
|
149
149
|
id: 'results', title: () => 'Run complete',
|
|
@@ -157,6 +157,7 @@ results.el.addEventListener('click', ev => { // one li
|
|
|
157
157
|
let held = null; // stop gameplay behind it (the picture keeps drawing)
|
|
158
158
|
engine.events.on('ui:open', id => { if (id === 'results') held = engine.freeze('results'); });
|
|
159
159
|
engine.events.on('ui:close', id => { if (id === 'results') { held?.remove(); held = null; } });
|
|
160
|
+
engine.events.on('session:start', () => results.toggle(false)); // a new run or a load, however it was started
|
|
160
161
|
results.toggle(true); // when the run ends; results.refresh() after the data changes
|
|
161
162
|
```
|
|
162
163
|
|
|
@@ -168,12 +169,27 @@ engine.ui.open('title'); // show it again (the setti
|
|
|
168
169
|
```
|
|
169
170
|
While the title is open gameplay is frozen, input is locked, and Esc goes to it (the settings menu does not open).
|
|
170
171
|
|
|
172
|
+
**A custom item closes the title itself.** The built-in `continue` / `start` call `e.ui.close('title')` after they load; an item you write does not, so `flow` can reach `playing` with the title still on top and no warning. End every item that leaves the title with `e.ui.close('title')`:
|
|
173
|
+
```js fragment
|
|
174
|
+
{ label: 'Tutorial', run: async e => { await e.session.newGame(); e.ui.close('title'); } }
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Photo mode: the picture without the interface, and hiding the interface
|
|
178
|
+
`engine.photo.take()` (op `photo.take`) draws one frame of the game canvas at a higher pixel ratio and reads it back, so the picture never contains DOM: HUD, toasts and windows are not in it (a HUD drawn into the canvas by your own render code is). To hide the interface on screen for a photo mode, hide the engine's UI root, one element that holds every part:
|
|
179
|
+
```js
|
|
180
|
+
const photoMode = on => { engine.uiRoot.style.display = on ? 'none' : ''; }; // engine ui: hud, toasts, windows, title
|
|
181
|
+
engine.photo.take(); // shot.url is the picture, the album keeps it; the DOM was never in it
|
|
182
|
+
photoMode(true); // the player's screen without interface, e.g. while a photo mode is framing
|
|
183
|
+
```
|
|
184
|
+
HUD text follows the engine locale (`createEngine({ locale })`, default `'auto'` = the browser language): a game written in English sets `locale: 'en'`, or distance labels read `50 米` on a Chinese browser.
|
|
185
|
+
|
|
171
186
|
## 6. Settings menu: only the tabs the game needs
|
|
172
187
|
```js
|
|
173
188
|
engine.use(settings({ sections: ['game', 'graphics', 'audio', 'controls', 'camera'] })); // default: graphics, audio, controls, language, saves
|
|
174
189
|
// optional built-ins by name: 'game' (resume / load / back to title), 'camera' (sensitivity, invert Y, field of view; re-applied on 'camera:change')
|
|
175
190
|
engine.settings.addSection('camera');
|
|
176
|
-
|
|
191
|
+
// leave graphics rows out: the entry { id: 'graphics', omit } in the list; an omitted row stays the game's value, and no preset or stored value moves it
|
|
192
|
+
settings({ sections: [{ id: 'graphics', omit: ['pixelRatio', 'antialias', 'adaptive'] }, 'audio', 'controls', 'language', 'saves'] });
|
|
177
193
|
|
|
178
194
|
// a tab of your own: render gets tools with the control helpers (row / toggle / range / segmented) already bound
|
|
179
195
|
engine.settings.define('subtitles', true, on => { document.body.dataset.subtitles = String(on); });
|
|
@@ -185,12 +201,14 @@ engine.settings.addSection('gameplay', {
|
|
|
185
201
|
```
|
|
186
202
|
A row that switches off an effect of your own (a post effect, a picture value): name the shared value it limits, and it works like the
|
|
187
203
|
built-in shadows row. Off holds the value off on the settings layer, so a later scene, weather or cutscene cannot turn it back on; on
|
|
188
|
-
allows whatever the scene chose. A number row from 0 to 1 is a factor on a number value. Define the row after the effect exists.
|
|
189
|
-
```js
|
|
204
|
+
allows whatever the scene chose. A number row from 0 to 1 is a factor on a number value. Define the row after the effect exists. `bloom` and `ao` already have rows of their own (limiting `post.bloom.enabled` / `post.ao.enabled`), so `settings.define('bloom', ...)` throws: switch them with `engine.settings.set('bloom', false)`, or in a preset.
|
|
205
|
+
```js fragment
|
|
190
206
|
engine.post.add(volFog); // post.volFog.enabled now exists
|
|
191
207
|
engine.settings.define('volFog', true, { limits: 'post.volFog.enabled' }); // add apply: v => ... too if the game reacts in code
|
|
192
208
|
engine.settings.define('flashCap', 1, { limits: 'sky.flash' }); // 0.5 = half of any lightning flash
|
|
193
209
|
settings({ presets: { low: { volFog: false } } }); // a preset can switch the row like any other key
|
|
210
|
+
settings({ presets: { low: { viewChunks: 0.5, density: 0.25 } } }); // viewChunks and density in a preset: shares (0 to 1) of the game's own value; the top preset lets everything through
|
|
211
|
+
settings({ presets: { low: { pixelRatio: 0.5 } } }); // pixelRatio in a preset: a share (0 to 1) of the ratio the engine picked for this device
|
|
194
212
|
```
|
|
195
213
|
`engine.describe().shared['post.volFog.enabled']` shows the settings entry and what the scene wanted underneath.
|
|
196
214
|
|
|
@@ -199,13 +217,6 @@ A completely different menu: don't install `settings()`; open your own with `uiF
|
|
|
199
217
|
Check what is in use: `engine.ui.describe()` → `{ loading: 'default', toast: 'off', 'hud.bar': 'custom', ... }`.
|
|
200
218
|
|
|
201
219
|
## 7. Keys, and UI that follows the world
|
|
202
|
-
- Bind keys
|
|
203
|
-
jump) in the fixed step, UI keys in the frame hook. Never `addEventListener('keydown')`, and never read `pointer.clicked` for gameplay; bind a
|
|
204
|
-
`Mouse0` action instead.
|
|
205
|
-
- A menu, vehicle or build mode that takes over keys pushes an input context: `const h = engine.input.push('menu')` (opaque) or
|
|
206
|
-
`push('vehicle', { pass: true })`, then `h.remove()`. Tests and the dev bridge press keys with `engine.input.simulate(action, down)`:
|
|
207
|
-
action names, not keys (`simulate('moveForward')` walks like a held W until `simulate('moveForward', false)`); an unknown name throws.
|
|
220
|
+
- Bind keys and read them by action name (recipe 58): gameplay keys (attack, jump) in the fixed step, UI keys in the frame hook. Never `addEventListener('keydown')`, and never read `pointer.clicked` for gameplay; bind a `Mouse0` action instead.
|
|
208
221
|
- A label over a world position: `worldToScreen(engine, pos)` gives screen coordinates for an HTML element.
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
Bind a counter to an item count (coins): `engine.onFrame(() => engine.hud.counter('coins', { icon: '🪙', label: 'Coins', value: engine.inventory.count('coin') }));`. Same id = update, unchanged value touches no DOM, and a loaded save follows automatically (recipe 22 section 4).
|
|
222
|
+
- A counter bound to an item count: recipe 22 section 4.
|
package/docs/recipes/27-net.md
CHANGED
|
@@ -4,8 +4,6 @@
|
|
|
4
4
|
puzzle, a turn-based board, trading). One player's browser is the **host** and
|
|
5
5
|
owns the game state; friends are **clients** that mirror it and ask for changes through ops. Not installed = no cost.
|
|
6
6
|
**What it is not (yet)**: action netcode. There is no client prediction or rollback, so a client's attack / roll / shot waits one round trip.
|
|
7
|
-
Souls-like and shooter games need that later step; the rules below (ops with self-contained args, state only changed in fixed steps and ops,
|
|
8
|
-
snapshot-able world data) are what it will build on.
|
|
9
7
|
|
|
10
8
|
## 1. Install
|
|
11
9
|
The same game code runs on every machine; only `role` and the transport differ.
|
|
@@ -22,7 +20,8 @@ Run the relay on any machine both can reach: `threedog relay 8787` (no dependenc
|
|
|
22
20
|
and a reconnect key.
|
|
23
21
|
For tests and offline demos use the in-process network instead (latency, jitter and loss adjustable; `manual: true` delivers only on `advance(ms)`):
|
|
24
22
|
```js
|
|
25
|
-
import { fakeNetwork, net } from 'threedog';
|
|
23
|
+
import { createEngine, fakeNetwork, net } from 'threedog';
|
|
24
|
+
const [host, guest] = [1, 2].map(() => createEngine({ canvas: document.createElement('canvas') })); // two games on one page
|
|
26
25
|
const wire = fakeNetwork({ latency: 80, jitter: 30, loss: 0.05 });
|
|
27
26
|
host.use(net({ role: 'host', transport: wire.host() }));
|
|
28
27
|
guest.use(net({ role: 'client', transport: wire.connect() }));
|
|
@@ -75,8 +74,7 @@ world records, containers, `vars`, and every other save part (quests, clock, sky
|
|
|
75
74
|
On a client the mirror is applied at the next fixed step; `world.simulate` does not run there (the host simulates). Other players glide between
|
|
76
75
|
updates (kinds in `interpolate`, default `['player']`). The client moves its own avatar and reports its position; the host clamps it to `maxSpeed`
|
|
77
76
|
(m/s, default 15).
|
|
78
|
-
A character another machine drives is held by net for good ([57-control](57-control.md))
|
|
79
|
-
each peer's avatar. A local `walkTo`, cutscene or `engine.control.take` on one is `[control-net]`; change it with an op the host runs.
|
|
77
|
+
A character another machine drives is held by net for good: a local `walkTo`, cutscene or `engine.control.take` on one is `[control-net]` ([57-control](57-control.md)).
|
|
80
78
|
|
|
81
79
|
## 5. Write the UI from state, not from run's return value
|
|
82
80
|
On a client `engine.ops.run` returns `{ ok: true, pending: true, seq }` after the local `can` passed (so a "no money" refusal is still instant). The
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
# Terrain: your own generator, digging, raising and painting the ground
|
|
1
|
+
# Terrain: your own generator, digging, raising and painting the ground, islands
|
|
2
|
+
|
|
3
|
+
**In this recipe**: 0. Noise preset · 1. Your own generator · 2. Changing the ground · 3. Farming soil and ground types · 4. Height and snapping · 5. Where the ground ends: `shape` · 6. Replace the picture, keep play · 7. A chunk that fails · 8. Triangle cut and bounds margin · 9. Height from a grid or image
|
|
2
4
|
|
|
3
5
|
Requires module `terrain()` (in the `openWorld()` preset). The API list is in `../api/terrain.md`.
|
|
4
6
|
|
|
5
7
|
The engine always does the chunks, streaming, workers, collision and vegetation. It has **no built-in landform**: `terrain()` without a generator is
|
|
6
8
|
flat gray ground at y = 0, with a dev warning. The height and ground type come from your own two functions or a preset, and the player can change the
|
|
7
|
-
ground during play.
|
|
9
|
+
ground during play. How the ground looks: recipes 36 and 53.
|
|
8
10
|
|
|
9
11
|
Flat island (no noise): `terrain({ height: () => 2, shape: { mask: (x, z) => 25 - Math.hypot(x, z) } })`; inside `openWorld` the same object goes under `terrain:`.
|
|
10
12
|
|
|
@@ -18,21 +20,22 @@ const dry = (x, z) => riverAt(x, z, preview.noise) === 0;
|
|
|
18
20
|
```
|
|
19
21
|
Its ground types are `beach snow rock riverbank wetland savanna forest highland meadow`; the game colors them (`terrain({ colors, biomeColors })`),
|
|
20
22
|
and `terrainStrings` names them for `describe()`. Other options:
|
|
21
|
-
`heightScale mountains rivers riverWidth biomes noise island canyon` (types in the package's `index.d.ts`).
|
|
23
|
+
`heightScale mountains rivers riverWidth river biomes noise island canyon` (types in the package's `index.d.ts`).
|
|
22
24
|
|
|
23
25
|
## 1. Your own generator
|
|
24
26
|
```js
|
|
25
27
|
import { terrain } from 'threedog';
|
|
26
28
|
terrain({
|
|
27
|
-
// meters at (x, z); n = { fbm(x, z, octaves), noise(x, z), hash(x, z, salt), seed, waterLevel, params }
|
|
29
|
+
// meters at (x, z); n = { fbm(x, z, octaves), noise(x, z), hash(x, z, salt), seed, waterLevel, params }; fbm, noise and hash all give 0 to 1, not -1 to 1
|
|
30
|
+
// (fbm gathers around 0.5 and seldom reaches either end: subtract 0.5 to center it, and sample the map before choosing a cut for a ground type)
|
|
28
31
|
height: (x, z, n) => 4 + 30 * n.fbm(x * 0.004, z * 0.004) - 8 * Math.abs(Math.sin(x * 0.01)),
|
|
29
32
|
// a ground type name (null = 'default'); its colors come from biomeColors[type]
|
|
30
33
|
groundType: (x, z, h, slope) => slope > 0.8 ? 'rock' : h < 1 ? 'beach' : 'grass',
|
|
31
34
|
waterLevel: 0, // a sea at y = 0; leave it out for no water (the default is -Infinity; terrainPreset() sets 0)
|
|
32
35
|
});
|
|
33
36
|
```
|
|
34
|
-
The terrain moves the camera's far plane out to its view distance
|
|
35
|
-
the
|
|
37
|
+
The terrain moves the camera's far plane out to its view distance and leaves the fog to the game; `terrain({ viewFog: true })` (on in `openWorld()`) writes that
|
|
38
|
+
distance to the signal `engine.uniforms.uViewDistance`, which your fog code reads so the far chunk edge fades out (recipe 34). It never writes `scene.fog`.
|
|
36
39
|
Both functions run in workers, so they are **pure**: they see only their parameters and globals like `Math`. Reading a variable from outside
|
|
37
40
|
(`(x, z) => x * scale`) throws at `terrain()` and names the variable; put the number inside the function, or pass settings as plain data in
|
|
38
41
|
`terrain({ params })` and read them as `n.params`. `flatten` plots still apply on top. A new type name needs colors:
|
|
@@ -40,15 +43,13 @@ Both functions run in workers, so they are **pure**: they see only their paramet
|
|
|
40
43
|
|
|
41
44
|
## 2. Changing the ground: `engine.terrain.edit`
|
|
42
45
|
```js
|
|
43
|
-
const at =
|
|
46
|
+
const at = [12, 0, 20]; // an op's 'position' argument is [x, y, z]
|
|
44
47
|
engine.ops.define('ground.dig', { args: { at: 'position' }, run(e, a) { e.terrain?.edit(a.at, { radius: 3, lower: 1.5 }); } });
|
|
45
48
|
engine.ops.define('ground.level', { args: { at: 'position' }, run(e, a) {
|
|
46
49
|
e.terrain?.edit(a.at, { shape: 'square', radius: 6, flatten: e.surface(a.at) }); // a flat foundation at the height of its center
|
|
47
50
|
} });
|
|
48
51
|
engine.ops.run('ground.dig', { at });
|
|
49
52
|
```
|
|
50
|
-
- One of `raise` / `lower` (meters) / `flatten` (target height), and / or `paint` (a ground type, `null` gives back the generated type). `shape` is
|
|
51
|
-
`'circle'` (default) or `'square'`, `radius` in meters.
|
|
52
53
|
- Edits snap to the terrain grid: heights to grid points, paint to whole cells of `engine.terrain.cellSize` meters (`chunkSize / resolution`, default
|
|
53
54
|
4). A shape smaller than a cell takes the nearest one. For finer paint use a higher `terrain({ resolution })` (64 gives 1 m cells); per-cell
|
|
54
55
|
gameplay state belongs in a grid layer (section 3).
|
|
@@ -72,12 +73,81 @@ engine.ops.define('path.sand', { args: { at: 'position' }, // a sandy path; a
|
|
|
72
73
|
Read the ground with `engine.surface(x, z)` (also `slope`, `groundType`, `waterAt`) and put an object on it with `engine.snapToGround(obj)`. Don't
|
|
73
74
|
raycast the terrain for this: the height function is exact and works before the chunk has a mesh.
|
|
74
75
|
|
|
75
|
-
|
|
76
|
+
## 4b. A road laid on the ground
|
|
77
|
+
|
|
78
|
+
The road and the height function must read the same data, or the road floats or sinks wherever they disagree. Write the road's shape once as plain numbers and hand them over with `terrain({ params })`. The height function runs in workers and sees only `n.params`, so it works out the centre line itself: a formula or a small table of numbers, never a curve object. Near the line it returns the road's level, and it blends to the hills further out.
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
const ROAD = { R: 130, wobble: 24, level: 14, flat: 10, blend: 40 }; // the one copy of the road's shape
|
|
82
|
+
|
|
83
|
+
function height(x, z, n) {
|
|
84
|
+
const p = n.params, t = Math.atan2(z, x);
|
|
85
|
+
const centre = p.R + p.wobble * Math.sin(2 * t);
|
|
86
|
+
const k0 = Math.min(1, Math.max(0, (Math.abs(Math.hypot(x, z) - centre) - p.flat) / p.blend)), k = k0 * k0 * (3 - 2 * k0);
|
|
87
|
+
const hills = 10 + 60 * (n.fbm(x * 0.009, z * 0.009, 4) - 0.5);
|
|
88
|
+
return p.level + (hills - p.level) * k;
|
|
89
|
+
}
|
|
90
|
+
// terrain({ params: ROAD, height })
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The road itself comes from the same numbers, with its heights read from `engine.surface`, so nothing is computed twice:
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
const points = [];
|
|
97
|
+
for (let i = 0; i < 720; i++) {
|
|
98
|
+
const t = i / 720 * Math.PI * 2, r = ROAD.R + ROAD.wobble * Math.sin(2 * t), x = r * Math.cos(t), z = r * Math.sin(t);
|
|
99
|
+
points.push({ x, y: engine.surface(x, z), z });
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Build the road's mesh from `points`, a little above the ground, and keep `flat` wider than half the road. The same data answers gameplay questions too, such as where the road is or how far a car has left it.
|
|
76
104
|
|
|
77
105
|
## 5. Where the ground ends: `shape`
|
|
106
|
+
`terrain({ shape })` decides where there is ground at all: an island, a floating rock, a world that ends. Without it the ground goes on forever. With it, ground exists only
|
|
107
|
+
where `mask > 0`; the rim is cut through the cells in straight lines, walls hang down from it, and an optional underside closes it. The keys and their defaults are `TerrainShape` in `types/world.d.ts`.
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
import { createEngine, openWorld } from 'threedog';
|
|
111
|
+
|
|
112
|
+
const engine = createEngine({ canvas: document.querySelector('canvas') });
|
|
113
|
+
engine.use(openWorld({ camera: 'follow', water: false, terrain: { // water: false -- a floating island has no sea under it
|
|
114
|
+
height: (x, z, n) => 4 + 6 * n.fbm(x * 0.02, z * 0.02),
|
|
115
|
+
shape: {
|
|
116
|
+
mask: (x, z) => 60 - Math.hypot(x, z), // > 0 ground: a 60 m disc (meters read best)
|
|
117
|
+
edge: { noise: 8, size: 20, jitter: 0.6, round: 1.5 }, // ragged outline, jagged rim, top bends down 1.5 m at the edge
|
|
118
|
+
side: { depth: 3, ground: 'cliff' }, // 3 m of cliff band, colored by biomeColors.cliff
|
|
119
|
+
bottom: { depth: (x, z, n, m) => 2 + m * 0.5 + 4 * n.fbm(x * 0.1, z * 0.1), ground: 'rock' }, // hangs lower inland (m grows inward)
|
|
120
|
+
},
|
|
121
|
+
} }));
|
|
122
|
+
await engine.start();
|
|
78
123
|
|
|
79
|
-
|
|
80
|
-
|
|
124
|
+
const home = { x: 0, z: 0 };
|
|
125
|
+
engine.events.on('terrain:void', ({ who }) => { // fell off: the game decides (the engine never respawns)
|
|
126
|
+
if (who === engine.player) engine.player.placeAt(home);
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Colors come from `terrain({ biomeColors })` as usual: add `cliff` and `rock` (a name without a color is neutral gray). The mask is pure like `height`, or a gray image.
|
|
131
|
+
Without `bottom` the island is open underneath (the cheapest choice when the camera never looks up at it). The side wall follows every bend of an `edge.round` top, so no slit shows between them.
|
|
132
|
+
|
|
133
|
+
What the rest of the engine does off the outline:
|
|
134
|
+
|
|
135
|
+
- `engine.surface(x, z)` is `-Infinity`, `engine.ground.has(x, z)` is `false`, `engine.slope` is 0, `engine.groundType` is `'void'`.
|
|
136
|
+
Check `has` before placing things: `engine.snapToGround` over the void warns once and leaves the object where it is, instead of writing an infinite y.
|
|
137
|
+
The same holds for every place-it-here entry (`engine.content.spawn`, content props, pickups, npcs, `character.placeAt`): a warning once per caller with this advice, and they keep the caller's y (or 0), never `-Infinity` (a save would turn it into NaN). Camera starts, HUD anchors, grid tiles and shot paths fall back to y 0 / the last height without a word.
|
|
138
|
+
- Characters walk off the rim and fall; pathfinding and spawn search treat the void as not walkable.
|
|
139
|
+
- Physics: the top and the walls collide (a rolling barrel stops at a wall, a ball falls off the edge); the underside does not.
|
|
140
|
+
- Vegetation never grows off the outline. `engine.terrain.edit` off it does nothing (returns `{ heights: 0, cells: 0 }`); near the rim it
|
|
141
|
+
still digs, and painting works. The outline itself cannot be edited.
|
|
142
|
+
- The player and every moving rigid body that drops below `engine.terrain.voidY` get one `terrain:void { who, position }` per fall.
|
|
143
|
+
- Global water still draws at its level: a floating island usually turns water off (`water: false` above).
|
|
144
|
+
|
|
145
|
+
Limits:
|
|
146
|
+
|
|
147
|
+
- The cut follows cell edges, so detail finer than a cell (`chunkSize / resolution`, 4 m by default) is lost. Keep `edge.size` above a cell,
|
|
148
|
+
or raise `resolution`.
|
|
149
|
+
- `shading: 'texture'`: the color map covers the top only (void pixels keep the color of the ground under them, so no seam shows at the rim, with alpha 0); sides and bottom use vertex colors or `side.material`.
|
|
150
|
+
- The mask is fixed at start; a game that wants the outline to change while playing builds that itself.
|
|
81
151
|
|
|
82
152
|
## 6. Drawing the ground and plants your own way: replace the picture, keep play
|
|
83
153
|
|
|
@@ -85,25 +155,19 @@ Crisp ground color borders, triangle cut, normals, bounds margin, height from a
|
|
|
85
155
|
`engine.vegetation`: species, placement, tree collision, felling) and the picture (`engine.terrainDraw`, slot `'terrain-draw'`;
|
|
86
156
|
`engine.vegetationDraw`, slot `'vegetation-draw'`). Collision, paths, `engine.surface`, `instanceAt` and saves read only the data, so a game that
|
|
87
157
|
replaces a picture keeps all of play. A picture listens to the data part's `view` hooks and never changes the data:
|
|
88
|
-
```js
|
|
158
|
+
```js fragment
|
|
89
159
|
engine.use({ name: 'myGround', type: 'picture', provides: ['terrain-draw'], install(e, ctx) {
|
|
90
160
|
const meshes = new Map();
|
|
91
161
|
ctx.track(e.terrain.view({
|
|
92
|
-
add(c) { const m = buildMesh(c.data.pos, c.data.nor, c.data.col); m.position.set(c.cx * e.terrain.
|
|
93
|
-
change(c) { refill(meshes.get(c), c.data); }, // terrain.edit rewrote the arrays (
|
|
162
|
+
add(c) { const m = buildMesh(c.data.pos, c.data.nor, c.data.col); m.position.set(c.cx * e.terrain.chunkSize, 0, c.cz * e.terrain.chunkSize); e.scene.add(m); meshes.set(c, m); },
|
|
163
|
+
change(c) { refill(meshes.get(c), c.data); }, // terrain.edit rewrote the arrays (the count can differ on an 'adaptive' rim)
|
|
94
164
|
remove(c) { e.scene.remove(meshes.get(c)); meshes.delete(c); },
|
|
95
165
|
show(c, visible) { meshes.get(c).visible = visible; },
|
|
96
166
|
}));
|
|
97
167
|
} }, { replaces: 'terrain-draw' });
|
|
98
|
-
engine.use({ name: 'myPlants', type: 'picture', provides: ['vegetation-draw'], install(e, ctx) {
|
|
99
|
-
ctx.track(e.vegetation.view({
|
|
100
|
-
species(sp) { /* sp.source = what vegetation.define was given (geometry, model, material, wind) */ },
|
|
101
|
-
change(c, name) { /* c.plants[name]: { n, m (16 floats per plant, chunk-local), c (colors), ids }; c.hidden[name]: felled slots; gone = drop that mesh */ },
|
|
102
|
-
ring(c, ring) { /* LOD: ring 1 = the chunk a source stands in plus one ring around */ },
|
|
103
|
-
show(c, visible) {}, drop(c) { /* chunk released */ },
|
|
104
|
-
}));
|
|
105
|
-
} }, { replaces: 'vegetation-draw' });
|
|
106
168
|
```
|
|
169
|
+
Plants work the same way: a module with `provides: ['vegetation-draw']`, `{ replaces: 'vegetation-draw' }` and `e.vegetation.view({ species, change, ring, show, drop })` (hooks in `../api/vegetation.md`). In `change(c, name)`, `c.plants[name]` is `{ n, m (16 floats per plant, chunk-local), c (colors), ids }` and `c.hidden[name]` the felled slots; when it is gone, drop that mesh.
|
|
170
|
+
`c.data` holds `pos`, `nor`, `col`, `uv`, and `tex: { data, size }` in texture mode; `engine.terrain.generator.buildChunk(cx, cz)` returns the same raw arrays.
|
|
107
171
|
Only the material, not the meshes? `engine.terrain.material = material` swaps it on every loaded chunk in place (recipe 36).
|
|
108
172
|
|
|
109
173
|
## 7. A chunk that fails
|
|
@@ -111,3 +175,35 @@ Only the material, not the meshes? `engine.terrain.material = material` swaps it
|
|
|
111
175
|
A chunk job that throws (usually the game's `height` / `groundType` / placement rule at that spot) is tried 3 times, then the chunk stays empty
|
|
112
176
|
(no ground, no collision there): `terrain:chunkFailed` `{ cx, cz, error }` fires, the error `[terrain-chunk-failed]` names the chunk and the cause,
|
|
113
177
|
and `describe().perf.chunks.failed` counts it. Fix the rule, then `engine.terrain.retry()` sends every failed chunk again.
|
|
178
|
+
|
|
179
|
+
## 8. Triangle cut and bounds margin
|
|
180
|
+
```js
|
|
181
|
+
terrain({ diagonal: 'adaptive' }) // 'fixed' (default) | 'adaptive' | 'alternate'
|
|
182
|
+
```
|
|
183
|
+
`fixed` cuts every cell the same way. `adaptive` cuts along the diagonal with the smaller height difference, which removes
|
|
184
|
+
the zigzag ridges a fixed cut leaves on a slope; `alternate` flips every other cell (no directional bias on flat low-poly facets). `engine.surface`,
|
|
185
|
+
collision and vegetation heights follow the chosen cut, so nothing floats. It changes the walkable shape, so `recolor` does not take it.
|
|
186
|
+
|
|
187
|
+
`boundsPad: { up: 3, radius: 8 }` (meters, the defaults) is the margin of the chunk's bounding sphere: the center is raised by `up`, the radius grows
|
|
188
|
+
by `radius`. Raise it if a shader moves vertices far (wind on tall ground cover, a vertex-displacement patch) and chunks pop out at the screen edge.
|
|
189
|
+
|
|
190
|
+
## 9. Height from a grid or image
|
|
191
|
+
`sampleGrid(data, opts)` (`../api/tools.md`) turns numbers laid out on a regular grid into a function `(x, z) => value`;
|
|
192
|
+
`await engine.assets.gridFromImage(nameOrUrl, opts)` (`../api/assets.md`) reads such a grid from an image. Samples sit on the grid nodes, so
|
|
193
|
+
`width` samples span `width - 1` cells. The grid is just a field: height, moisture, a
|
|
194
|
+
ground-type weight, spawn density, a walkable mask, danger, travel cost.
|
|
195
|
+
|
|
196
|
+
`interp` is the picture between nodes, and none of them is the right one: `'nearest'` for terraces, blocky ground, tile masks and ids; `'linear'` (default) for most fields;
|
|
197
|
+
`'cubic'` for slopes without cell creases, which can overshoot beside a sharp step (`clamp: true` keeps it inside the four corner values).
|
|
198
|
+
|
|
199
|
+
```js fragment
|
|
200
|
+
const g = await engine.assets.gridFromImage('/maps/height16.png', { range: [-5, 60] }); // meters, 16-bit file
|
|
201
|
+
const heightAt = sampleGrid(g.data, { ...g, size: [512, 512], origin: [-256, -256], interp: 'cubic', clamp: true });
|
|
202
|
+
heightAt(10, 20); // gameplay side: where to put a camp, a mine, a lighthouse
|
|
203
|
+
const wet = sampleGrid(moisture, { width: 32, height: 32, cellSize: 8 }); // a hand-made field: wetter ground grows reeds, rice, moss
|
|
204
|
+
const walk = sampleGrid(mask, { width: 64, height: 64, cellSize: 1, interp: 'nearest', outside: 0 }); // 0 / 1 per tile; off the map: not walkable
|
|
205
|
+
```
|
|
206
|
+
A terrain `height` function is recompiled in a worker and cannot capture `heightAt`, so the terrain reads the same image through its own
|
|
207
|
+
`heightmap` (bilinear, centered on `center`): `terrain({ heightmap: { ...g, size: [512, 512], min: -5, max: 60 } })` with `g` from `gridFromImage`
|
|
208
|
+
using the default `range` (it expects 0-1 values; `min`/`max` scale them). Use `sampleGrid` for everything outside the terrain module; when you need
|
|
209
|
+
a picture the terrain's bilinear read does not give (terraces: `nearest`), bake it into the data first or write the step in a `height` function.
|
package/docs/recipes/29-grid.md
CHANGED
|
@@ -64,7 +64,7 @@ used by `toCell`, `toWorld`, tiles and flatness (footprints stay rectangles of c
|
|
|
64
64
|
|
|
65
65
|
## 3. Layers: per-cell state (soil, creep, paint)
|
|
66
66
|
```js
|
|
67
|
-
const soil = plot.layer('soil');
|
|
67
|
+
const soil = plot.layer('soil', { tiles: true }); // created on first use, options read then; saved with the game (only cells that differ from content)
|
|
68
68
|
engine.ops.define('plot.till', { args: { cell: 'any' },
|
|
69
69
|
can: (e, { cell }) => (!plot.inside(cell) ? 'outOfBounds' : plot.at(cell) ? 'occupied' : true),
|
|
70
70
|
run: (e, { cell }) => soil.set(cell, { tilled: true }) });
|
|
@@ -128,7 +128,7 @@ engine.ops.define('plot.dig', { args: { cell: 'any' },
|
|
|
128
128
|
e.grids.get('plots').layer('state').set(cell, { dug: true }); // per-cell game state
|
|
129
129
|
} });
|
|
130
130
|
```
|
|
131
|
-
Undo with `paint: null` and `raise`.
|
|
131
|
+
Undo with `paint: null` and `raise`.
|
|
132
132
|
|
|
133
133
|
## 6. Verify
|
|
134
|
-
`engine.describe().grids` -> `{ room: { occupied, items: { bed: 1 }, layers: {} }, plot: { ..., layers: { soil: 30 } } }`.
|
|
134
|
+
`engine.describe().grids` -> `{ room: { occupied, items: { bed: 1 }, layers: {} }, plot: { ..., layers: { soil: 30 } } }`.
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
# Templates: reusable objects, definition vs instance state
|
|
2
2
|
|
|
3
|
-
**In this recipe**: 1. Define a template · 2. Place instances · 3. What belongs to the definition, what to the instance ·
|
|
4
|
-
5. Point -> thing · 6. When to use a template
|
|
3
|
+
**In this recipe**: 1. Define a template · 2. Place instances · 3. What belongs to the definition, what to the instance ·
|
|
4
|
+
5. Point -> thing · 6. When to use a template · 7. A group of things
|
|
5
5
|
|
|
6
6
|
Requires `world()` (in `openWorld()`); a template with `interact` needs `interactions({ ...presets.interactions.nearest })`, with `container` needs
|
|
7
|
-
`inventory()`.
|
|
7
|
+
`inventory()`.
|
|
8
8
|
|
|
9
9
|
A **template** describes one kind of object once: its model, collision, interaction, container, sound, animation and the default values of its saved
|
|
10
10
|
state. Every chest, campfire or bed you place is an **instance**: a world record that names the template (its `kind` is the template name) and holds
|
|
11
|
-
only its own state. There is no inheritance and no variant layer; a different look or behaviour is another template
|
|
11
|
+
only its own state. There is no inheritance and no variant layer; a different look or behaviour is another template, and a template is plain JS, so
|
|
12
|
+
`{ ...chest, model: 'iron-chest' }` is that other template in one line.
|
|
12
13
|
|
|
13
14
|
## 1. Define a template
|
|
14
15
|
`games/<game>/content/templates.js` (add it to `content/index.js`):
|
|
@@ -57,7 +58,7 @@ turret: { model: 'turret', state: { ammo: 30 }, fields: { ammo: { min: 0, max: 9
|
|
|
57
58
|
```
|
|
58
59
|
`npm run check` then reports a placement with `stage: 9`, `sort: 'rice'` or a misspelled `stagee` (with the closest name), and dev `engine.content.spawn`
|
|
59
60
|
throws on the same mistakes. `engine.content.fields('crop')` returns the whole table (placement fields plus state fields, with each state default),
|
|
60
|
-
in the `core/params.js` format; `fields('props')`, `fields('pickups')`, `fields('views')` and `fields('props.grid')` give the engine's own placement
|
|
61
|
+
in the `core/base/params.js` format; `fields('props')`, `fields('pickups')`, `fields('views')` and `fields('props.grid')` give the engine's own placement
|
|
61
62
|
fields, and a game kind in `content/rules.js` can declare `fields` the same way. A state field may not be named `id`, `kind` or `position`: those
|
|
62
63
|
are the record's own.
|
|
63
64
|
|
|
@@ -65,8 +66,7 @@ are the record's own.
|
|
|
65
66
|
its changes by id, and an index id (`<template>:<index>`, `pickup:<item>:<index>`) moves to another entry when one is inserted above it. Without one,
|
|
66
67
|
dev warns once per load and names the id to write. Pure decoration may keep its index id. Two entries with the same id in one load throw with the fix;
|
|
67
68
|
an authored id may not contain `#` or `/` (those are kept for records made during play and for level nodes). Places computed from the seed (a flat
|
|
68
|
-
spot near the river) stay in code and come in through `content.load(data, { places })`.
|
|
69
|
-
(`chest#4`), so they never meet an authored id.
|
|
69
|
+
spot near the river) stay in code and come in through `content.load(data, { places })`.
|
|
70
70
|
|
|
71
71
|
**Writing the ids, renaming them.** `threedog content ids [-w game]` lists each stateful entry that still relies on its index id with the id it
|
|
72
72
|
has now (`-`/`+` lines, dry run); `--write` writes them into the content files. Writing today's id changes nothing for old saves. To give an entry a
|
|
@@ -79,8 +79,9 @@ and drops `prop:rock:12`'s data quietly. `npm run check` errors on a target no e
|
|
|
79
79
|
orphan near an existing id with the exact pair to add.
|
|
80
80
|
|
|
81
81
|
**Physics props.** `body: { shape: 'box' | 'ball' | 'hull', mass, friction?, restitution?, damping?, angularDamping? }` in a definition makes each
|
|
82
|
-
copy a rigid body (needs `rigid()`). The copy rests on the ground asleep until something hits it; then the record follows the
|
|
83
|
-
crate's place
|
|
82
|
+
copy a rigid body (needs `rigid()`). The copy rests on the ground asleep until something hits it; then the record follows the body, and a save keeps
|
|
83
|
+
the crate's place like any other change, with its turn, speed and sleep in the save part `rigid` under the record id. A load puts it back as it was, in
|
|
84
|
+
the air if it was falling. A copy nothing has touched stays out of the save, however it settled on the ground.
|
|
84
85
|
```js
|
|
85
86
|
// content/templates.js
|
|
86
87
|
export default { crate: { model: 'crate', body: { shape: 'box', mass: 2 } } };
|
|
@@ -88,9 +89,8 @@ export default { crate: { model: 'crate', body: { shape: 'box', mass: 2 } } };
|
|
|
88
89
|
|
|
89
90
|
**Grid items and level nodes.** A props entry `{ id: 'bed-home', grid: 'farm', item: 'bed', cell: [4, 4], rotation: 1 }` is the record `grid.place`
|
|
90
91
|
would make, as authored data (the grid comes from the content key `grids`, `{ farm: { cell: 1, origin: [0, 0], size: [16, 12] } }`, or
|
|
91
|
-
`engine.grids.add`). In a level model, a node
|
|
92
|
-
|
|
93
|
-
is `<level file name>/<node name>`, for example `town/door_front` (recipe 10).
|
|
92
|
+
`engine.grids.add`). In a level model, a node tagged `template = 'door'` becomes an instance of that template and one tagged `id = true` a record of kind `levelNode`, with id
|
|
93
|
+
`<level file name>/<node name>` (recipe 10).
|
|
94
94
|
|
|
95
95
|
At runtime (inside an op or a fixed step), `engine.content.spawn(name, at, fields)` places a new instance and returns its record (without `fields.id`
|
|
96
96
|
the id is numbered `<template>#<n>`, for example `chest#3`):
|
|
@@ -122,7 +122,7 @@ export default {
|
|
|
122
122
|
},
|
|
123
123
|
};
|
|
124
124
|
```
|
|
125
|
-
- `duration` is
|
|
125
|
+
- `duration` is calendar seconds (`engine.clock.now`) spent in a stage; only the last stage may leave it out (it stays there). `scale` multiplies the
|
|
126
126
|
instance's scale; `model` is a model name shown from that stage on. Stages are data: content-check validates them with the engine's own rules.
|
|
127
127
|
- Each instance gets the state field `stage` (default 0, an int 0..n-1, so a placement may write `{ template: 'crop', stage: 2 }` and
|
|
128
128
|
`content.fields('crop').stage` describes it) and `stageAt`, the clock time it entered. Both are on the world record and saved like any other field.
|
|
@@ -135,7 +135,7 @@ export default {
|
|
|
135
135
|
**Many placements: split a kind into a folder.** Any content kind may be a folder instead of one file: `content/props/<area>.js`… (by area,
|
|
136
136
|
by theme, as you like). The parts are joined in file-name order; in `content/index.js` write `const props = contentParts(import.meta.glob('./props/*.js', { eager: true }));`
|
|
137
137
|
(`import { contentParts } from 'threedog'`). An id must be unique across all parts (the content check names both files). The content check hints at splitting past
|
|
138
|
-
about 2000 entries in one file; it also writes `.threedog/content-index.json` (id -> file:line), so `threedog content set/add/remove` opens only the one part it edits.
|
|
138
|
+
about 2000 entries in one file; it also writes `.threedog/content-index.json` (id -> file:line), so `threedog content set/add/remove` opens only the one part it edits. After a hand edit or a rename the next write rebuilds it first, and refuses while a content file does not load.
|
|
139
139
|
Add new entries at the end of a part with a written id: an entry without an id gets its position in the joined list, which an insert above it would shift.
|
|
140
140
|
|
|
141
141
|
## 3. What belongs to the definition, what to the instance
|
|
@@ -152,11 +152,6 @@ value on the record instead (`engine.world.set(id, { opened: true })`). Read a d
|
|
|
152
152
|
`engine.inventory.item(id)`. For your own tables of kinds (enemy types, crop types), the same split applies: keep the table in content, store `kind`
|
|
153
153
|
plus the changing values on the record, and wrap the table with `Object.freeze` if you like. <!-- r18-ignore-line -->
|
|
154
154
|
|
|
155
|
-
## 4. Tests
|
|
156
|
-
`tests/specs/templates.mjs`: two chests of one template share the model, open / goods per instance, save and reload restores each, the definition
|
|
157
|
-
never changes. `tests/specs/template-stages.mjs`: stages grow over game time near and far and survive save / load, `update` runs on the
|
|
158
|
-
fixed step, an interaction runs its op, and the engine root has no second placement path (no entities module, no root-level spawn). `tests/specs/single-source.mjs` (`npm test -- "Single source"`): ids, duplicates, baseline + diff, orphans, level nodes, source lines, pick.
|
|
159
|
-
|
|
160
155
|
## 5. Point -> thing: where is this defined
|
|
161
156
|
Runtime ops change only the current session and its saves. To change the level itself, edit the content files or the level model, then reload. To find
|
|
162
157
|
the entry, ask the engine what a thing is:
|
|
@@ -173,16 +168,54 @@ line numbers); a release build has none and pays nothing. From a terminal or an
|
|
|
173
168
|
top-left) or the MCP tool `pick { x, y }`.
|
|
174
169
|
|
|
175
170
|
## 6. When to use a template
|
|
176
|
-
|
|
177
|
-
windmill, colliders, interactions. A template plus a placement with an `id` in `content/props.js` (or `pickups`, `npcs`, `containers`, a game kind
|
|
178
|
-
from `rules.js`, the level model) is what you want when the thing must be saved with its own state, edited without touching code, or copied many
|
|
179
|
-
times. Both land in the same registry: `engine.thing(id)` answers for either and says what a save keeps (recipe 40). Game code keeps the rules: ops,
|
|
180
|
-
`world.simulate` / `world.present`, conditions and UI. Something that appears during play is created inside an op with `engine.content.spawn`.
|
|
171
|
+
Plain three.js or a template: recipe 40 sections 1 and 2 decide. Game code keeps the rules: ops, `world.simulate` / `world.present`, conditions and UI. Something that appears during play is created inside an op with `engine.content.spawn`.
|
|
181
172
|
|
|
182
|
-
`npm run check` (rule R33) flags only what
|
|
173
|
+
`npm run check` (rule R33) flags only what can break, in examples, templates and `games/*` alike. Warning, with `// runtime: <reason>` as the way to say it is fine (no saves, a new run only): `world.add` (without `{ save: false }`),
|
|
183
174
|
`engine.content.spawn`, `pickups.spawn` or `npcs.add` at module top level or in an `engine:ready` / `level:loaded` / `session:start`
|
|
184
|
-
handler, because those are saved whole and the startup code would make a second copy after every load
|
|
185
|
-
anywhere. Warning: code that `engine.add`s a `world.view(id)` model or writes its position / rotation / scale (world puts it back every frame).
|
|
186
|
-
The fix is a placement in content, or an op
|
|
187
|
-
|
|
188
|
-
|
|
175
|
+
handler, because those are saved whole and the startup code would make a second copy after every load. Error: `world.add(…, { initial: true })`
|
|
176
|
+
anywhere, which corrupts what saves compare against. Warning: code that `engine.add`s a `world.view(id)` model or writes its position / rotation / scale (world puts it back every frame).
|
|
177
|
+
The fix is a placement in content, or an op; a mesh built in code becomes a model by name (`engine.assets.manifest({ models: { cabin } })`) when you want it as a template.
|
|
178
|
+
|
|
179
|
+
## 7. A group of things
|
|
180
|
+
A market stall, a gun nest, a pit lane, a shop shelf, a puzzle room: several things that belong together. Content stays flat. Each thing is its own plain
|
|
181
|
+
entry with its own id, and what holds them together is the **place** they stand at. Nothing nests at runtime: there is no group object, no parent and no
|
|
182
|
+
per-part override, so `engine.thing(id)`, the save, `threedog content set` and `engine.pick` see each entry the same way as any other.
|
|
183
|
+
|
|
184
|
+
`content/places.js`, one place per group; `rot` is optional, radians about Y:
|
|
185
|
+
```js
|
|
186
|
+
export default { 'stall-1': { x: 40, z: -12 }, 'nest-1': { x: 8, z: 30, rot: 1.57 } };
|
|
187
|
+
```
|
|
188
|
+
`content/props.js`, entries around that place (`template` is the prototype, `id` the instance):
|
|
189
|
+
```js
|
|
190
|
+
export default [
|
|
191
|
+
{ id: 'stall-1-counter', model: 'counter', collide: 'box', place: 'stall-1', source: 'stall' },
|
|
192
|
+
{ id: 'stall-1-chest', template: 'chest', place: 'stall-1', x: 1, source: 'stall' },
|
|
193
|
+
{ id: 'nest-1-wall', template: 'sandbags', place: 'nest-1', z: 2, source: 'nest' },
|
|
194
|
+
{ id: 'nest-1-gun', template: 'turret', place: 'nest-1', x: 1, rot: 0.5, ammo: 5, source: 'nest' },
|
|
195
|
+
];
|
|
196
|
+
```
|
|
197
|
+
**One edit moves the group.** An entry's `x`, `z` are offsets from the place and turn with its `rot` (the same sense as a model's `rotation.y`); its own `rot` adds to
|
|
198
|
+
the place's. Change the place and every entry follows, with its model and collision. This also holds without a page reload when the place changes through a
|
|
199
|
+
second `engine.content.load(data, { places })`. What play moved or turned stays where the player left it, and a save keeps only what play changed, so an old
|
|
200
|
+
save follows the new place too. Only places in `places.js` (or the `places` of `content.load`) have `rot`; a level marker gives a position.
|
|
201
|
+
|
|
202
|
+
**`source`** (experimental, with `content stamp` and `content capture`) is a plain optional string on a model or template entry, naming what the entry was copied from. It has no effect at runtime; it is there to ask:
|
|
203
|
+
```js fragment
|
|
204
|
+
engine.world.query({ where: r => r.source === 'stall' }); // every thing copied from that arrangement
|
|
205
|
+
```
|
|
206
|
+
**Moving entries by hand.** On the dev server press F2 (or add `?edit=1` to the address), click an entry and drag its handle: letting go writes `x` and `z` into its content file, as an offset when it stands on a place. Comments and alignment stay. A value someone changed since the click is refused, and code-built entries and things added by code say why they cannot be saved.
|
|
207
|
+
|
|
208
|
+
**Arrangements.** To stamp out the same group again (`threedog content stamp <name> id=stall-1 x=20 z=5 rot=1.6`, then `threedog content set --source <name> <part> y=2` changes that part in every copy, as one explicit edit), keep it as a small file, `content/arrangements/<name>.js`: entries around zero, with a local `part` name
|
|
209
|
+
instead of an id and no place. Only the tools read it, when they copy it into `props.js`; the game never loads it, so the copies are ordinary entries from then
|
|
210
|
+
on and changing the file later changes nothing already placed.
|
|
211
|
+
```js
|
|
212
|
+
export default [
|
|
213
|
+
{ part: 'counter', model: 'counter', collide: 'box' },
|
|
214
|
+
{ part: 'chest', template: 'chest', x: 1 },
|
|
215
|
+
];
|
|
216
|
+
```
|
|
217
|
+
Copied to `stall-1`, part `chest` becomes `{ id: 'stall-1-chest', template: 'chest', place: 'stall-1', x: 1, source: 'stall' }`.
|
|
218
|
+
|
|
219
|
+
**Deleting.** Delete an entry and a save that changed it still loads: the change is an orphan (recipe 20, "Orphans are kept");
|
|
220
|
+
the `renames` content file says where it went (`null` = deleted on purpose). Delete a place and `threedog check` names every entry still standing on it; the
|
|
221
|
+
load refuses it too (`content-place`), because an entry with no place has no position.
|
package/docs/recipes/31-audio.md
CHANGED
|
@@ -6,8 +6,7 @@ Everything you hear is the game's. The engine ships no sound files and plays not
|
|
|
6
6
|
|
|
7
7
|
## 1. Config in one place
|
|
8
8
|
Two places, one job each: **the asset manifest says what a sound is** (a file, or a synth function made in code, registered by name like a
|
|
9
|
-
model), **`audio.sounds` says how it plays** (which sound or variants, volume, bus, cooldown...).
|
|
10
|
-
(`footstep`, `shutter`, `thunder`, ambience's `wind` `rain` `water` `birds` `crickets`) as built-in sound assets that stay silent until a rule names them.
|
|
9
|
+
model), **`audio.sounds` says how it plays** (which sound or variants, volume, bus, cooldown...).
|
|
11
10
|
```js
|
|
12
11
|
const engine = createEngine({ canvas, audio: {
|
|
13
12
|
levels: { music: 0.4, voice: 1 }, // volume per bus; an extra key (voice) adds a bus
|
|
@@ -33,9 +32,10 @@ Code may hold functions (a `volume: e => ...`); the same config as data goes in
|
|
|
33
32
|
|
|
34
33
|
## 2. Buses and sounds by name
|
|
35
34
|
Buses are real Web Audio `GainNode`s: `master`, `music`, `sfx`, `ambience`, `ui`, plus the game's own (`levels: { voice: 1 }` or
|
|
36
|
-
`engine.audio.addBus('voice')`). `engine.audio.setVolume('music', 0.3)` sets one; `engine.audio.buses.sfx` is the node to connect your own nodes to.
|
|
35
|
+
`engine.audio.addBus('voice')`). `engine.audio.setVolume('music', 0.3)` sets one; `engine.audio.buses.sfx` is the node to connect your own nodes to, and `buses.master` (also `audio.master`) is the total. `buses` is empty until audio
|
|
36
|
+
unlocks on the player's first click or key: build your own nodes on the `audio:ready` event. A name that is no bus warns once and gives `master`, so the sound still plays.
|
|
37
37
|
|
|
38
|
-
```js
|
|
38
|
+
```js fragment
|
|
39
39
|
engine.audio.sfx('door'); // plays on its bus (default sfx)
|
|
40
40
|
const h = engine.audio.sfx('shot', { at: enemy.root }); // 3D: a PannerNode that follows the Object3D every frame
|
|
41
41
|
const hum = engine.audio.sfx('engine-hum', { loop: true, at: [4, 0, 2] });
|
|
@@ -50,8 +50,7 @@ Built-in synth parameters (`params`): `wind` / `water` take `freq` (filter Hz),
|
|
|
50
50
|
4300); every synth also gets `pitch`, the sfx pitch multiplier (~1). A sound whose file fails to load keeps its ambience rule silent (one warning)
|
|
51
51
|
until the rules load again, instead of refetching.
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
Connect to `out` and return the length in seconds (or `{ stop(t) }` for a loop).
|
|
53
|
+
A synth with default params is `{ build: synthFn, params }` in the manifest.
|
|
55
54
|
|
|
56
55
|
## 3. Ambience: a rule table
|
|
57
56
|
Each rule names a sound and says when and how loud. A rule with `every` is a one-shot at random gaps; without, a loop that fades in and out (and stops
|
|
@@ -84,6 +83,7 @@ engine.music.intensity = 0.8; // stems fade in as
|
|
|
84
83
|
```
|
|
85
84
|
The same `when` keys as ambience. Tracks cross-fade (`fade`, default 2 s); a new rule result must hold `hold` seconds before switching.
|
|
86
85
|
`engine.music.override('boss')` picks by hand; `override(null)` hands back to the rules. `engine.music.stinger('win')` plays a short piece over the music.
|
|
86
|
+
Decoded music is large (about 21 MB a stereo minute), so it lives like any asset: `assets.release(name)` and `assets.trim()` (a level change calls it) free it, the longest-unused long sounds go by themselves over a memory budget, sounds still playing play on, and a freed sound loads again when played; effects under 10 s stay cached, and `preload: true` keeps a track.
|
|
87
87
|
|
|
88
88
|
## 5. Footsteps by surface
|
|
89
89
|
The player's footstep rhythm follows its speed (one step per foot landing). Each step plays the sound named by `footsteps[groundType]`, else
|
|
@@ -117,7 +117,7 @@ export default {
|
|
|
117
117
|
footsteps: { beach: 'step.sand', default: 'footstep' },
|
|
118
118
|
};
|
|
119
119
|
```
|
|
120
|
-
```js
|
|
120
|
+
```js fragment
|
|
121
121
|
engine.assets.manifest({ name: 'sfx', base: '/sounds/', sounds: { door: 'door.ogg', hit1: 'hit1.ogg', hit2: 'hit2.ogg', shot: 'shot.ogg', 'music-day': 'day.ogg' } });
|
|
122
122
|
engine.content.load([base, forest]); // each pack's audio merges in
|
|
123
123
|
```
|