threedog 1.0.1 → 1.2.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 +90 -0
- package/README.md +1 -1
- package/core/assets/Animator.js +41 -3
- package/core/assets/Assets.js +100 -24
- package/core/assets/assetEntry.js +73 -20
- package/core/assets/assetHot.js +68 -16
- package/core/assets/assetLoad.js +6 -6
- package/core/assets/assetLod.js +9 -2
- package/core/assets/assetManifest.js +12 -2
- package/core/assets/assetPart.js +54 -0
- package/core/assets/ik.js +271 -0
- package/core/assets/modelNeeds.js +37 -0
- package/core/assets/namedModel.js +102 -29
- package/core/assets/nodeVisibility.js +15 -0
- package/core/audio/Audio.js +36 -4
- package/core/audio/audioReverb.js +99 -0
- package/core/audio/audioRules.js +1 -1
- package/core/audio/audioVoice.js +1 -1
- package/core/base/Events.js +14 -4
- package/core/base/Random.js +1 -1
- package/core/base/Vars.js +1 -1
- package/core/base/docRef.js +51 -0
- package/core/base/errorCodes.js +178 -126
- package/core/base/errorHints.js +9 -7
- package/core/base/errors.js +25 -10
- package/core/base/events.generated.js +2 -0
- package/core/base/freeParts.js +76 -0
- package/core/base/math.js +28 -0
- package/core/base/sections.js +5 -5
- package/core/base/validate.js +31 -3
- package/core/engine/Engine.js +16 -6
- package/core/engine/Loading.js +5 -3
- package/core/engine/copies.js +1 -1
- package/core/engine/headlessLoad.js +4 -1
- package/core/engine/lifecycle.js +32 -16
- package/core/engine/loop.js +71 -27
- package/core/engine/moduleSlots.js +2 -2
- package/core/engine/moduleTypes.js +3 -3
- package/core/engine/modules.js +65 -39
- package/core/engine/page.js +6 -3
- package/core/engine/services.js +6 -5
- package/core/engine/startup.js +5 -5
- package/core/input/Input.js +28 -14
- package/core/input/inputContext.js +28 -16
- package/core/input/inputKeyboard.js +31 -3
- package/core/input/inputPad.js +4 -0
- package/core/input/inputPointer.js +2 -1
- package/core/input/inputSeat.js +1 -1
- package/core/inspect/Budget.js +109 -19
- package/core/inspect/DebugOverrides.js +28 -4
- package/core/inspect/Describe.js +17 -9
- package/core/inspect/Inspect.js +4 -2
- package/core/inspect/InspectMaterials.js +3 -1
- package/core/inspect/InspectPerf.js +19 -9
- package/core/inspect/InspectScene.js +32 -7
- package/core/inspect/MaterialInfo.js +19 -2
- package/core/inspect/UrlState.js +46 -27
- package/core/inspect/catalog.js +28 -9
- package/core/inspect/debugView.js +2 -1
- package/core/inspect/describeRender.js +25 -13
- package/core/inspect/describeText.js +14 -6
- package/core/inspect/lightWatch.js +1 -1
- package/core/inspect/metadata.generated.js +35 -17
- package/core/inspect/pictureChecks.js +148 -0
- package/core/inspect/pictureMenu.js +84 -0
- package/core/inspect/pictureWriters.js +26 -6
- package/core/inspect/textureBytes.js +12 -2
- package/core/inspect/toolDoor.js +2 -4
- package/core/ops/Ops.js +11 -4
- package/core/ops/holds.js +27 -10
- package/core/ops/opsAtomic.js +15 -7
- package/core/ops/opsGuard.js +2 -2
- package/core/ops/opsRun.js +8 -7
- package/core/ops/sharedPoint.js +72 -21
- package/core/ops/stacks.js +56 -16
- package/core/saves/SaveStore.js +9 -3
- package/core/saves/Saves.js +32 -23
- package/core/saves/saveApply.js +96 -44
- package/core/saves/saveIds.js +1 -1
- package/core/saves/saveVersions.js +7 -5
- package/core/saves/session.js +17 -8
- package/core/saves/stateReplace.js +34 -15
- package/core/scene/Rays.js +52 -10
- package/core/scene/Views.js +13 -7
- package/core/scene/adaptive.js +144 -21
- package/core/scene/drawOnly.js +17 -0
- package/core/scene/gameLights.js +44 -3
- package/core/scene/sceneMethods.js +13 -11
- package/core/scene/stepPoses.js +11 -3
- package/core/scene/targeting.js +5 -3
- package/core/scene/thingOps.js +1 -1
- package/core/scene/tier.js +15 -0
- package/core/stream/Batching.js +30 -7
- package/core/stream/Stream.js +26 -7
- package/core/stream/batchGroups.js +2 -2
- package/core/stream/chunkStream.js +7 -5
- package/core/stream/prepare.js +77 -0
- package/core/time/skip.js +3 -1
- package/core/time/time.js +4 -2
- package/docs/AI.md +82 -83
- package/docs/API.md +16 -16
- package/docs/CODEMAP.md +16 -11
- package/docs/COMMANDS.md +31 -33
- package/docs/CONVENTIONS.md +37 -49
- package/docs/MIGRATING-0.8.md +2 -2
- package/docs/MIGRATING-1.0.md +2 -2
- package/docs/THREE.md +28 -35
- package/docs/api/assets.md +3 -1
- package/docs/api/audio.md +4 -2
- package/docs/api/budget.md +5 -0
- package/docs/api/cameraRig.md +2 -2
- package/docs/api/characters.md +10 -8
- package/docs/api/collision.md +6 -4
- package/docs/api/engine.md +16 -16
- package/docs/api/events.md +3 -2
- package/docs/api/ground.md +6 -5
- package/docs/api/hud.md +4 -2
- package/docs/api/input.md +5 -5
- package/docs/api/particles.md +2 -1
- package/docs/api/photo.md +3 -0
- package/docs/api/post.md +7 -4
- package/docs/api/quests.md +2 -2
- package/docs/api/rays.md +1 -2
- package/docs/api/saves.md +7 -7
- package/docs/api/settings.md +2 -2
- package/docs/api/tools.md +3 -1
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -2
- package/docs/api/world.md +1 -1
- package/docs/recipes/01-new-game.md +16 -17
- package/docs/recipes/02-npc.md +22 -18
- package/docs/recipes/03-items-pickups.md +37 -35
- package/docs/recipes/04-quests.md +15 -10
- package/docs/recipes/05-props-bake.md +101 -95
- package/docs/recipes/06-clock-events.md +28 -28
- package/docs/recipes/07-flow-scenes-pause.md +29 -26
- package/docs/recipes/08-weather-sky.md +52 -64
- package/docs/recipes/09-materials-lights-models.md +26 -17
- package/docs/recipes/10-blender-level.md +15 -10
- package/docs/recipes/11-vehicles.md +12 -7
- package/docs/recipes/12-navmesh.md +44 -26
- package/docs/recipes/13-animation.md +56 -45
- package/docs/recipes/14-custom-module.md +21 -18
- package/docs/recipes/15-perf.md +61 -55
- package/docs/recipes/16-dev-bridge.md +23 -33
- package/docs/recipes/18-world.md +36 -42
- package/docs/recipes/19-shooting-picking.md +20 -15
- package/docs/recipes/20-content-actions-save.md +48 -56
- package/docs/recipes/21-camera.md +45 -54
- package/docs/recipes/22-shop-gold.md +12 -7
- package/docs/recipes/23-ops.md +25 -23
- package/docs/recipes/26-ui-parts.md +67 -47
- package/docs/recipes/27-net.md +12 -7
- package/docs/recipes/28-terrain.md +24 -21
- package/docs/recipes/29-grid.md +32 -27
- package/docs/recipes/30-templates.md +21 -20
- package/docs/recipes/31-audio.md +39 -22
- package/docs/recipes/32-action-game.md +19 -14
- package/docs/recipes/33-stream-sources.md +15 -11
- package/docs/recipes/34-environment-lighting.md +126 -70
- package/docs/recipes/35-picture-from-reference.md +8 -8
- package/docs/recipes/36-ground-plants.md +27 -21
- package/docs/recipes/40-scene.md +19 -28
- package/docs/recipes/43-shader-patches-surfaces.md +15 -12
- package/docs/recipes/44-water-weather-hooks.md +34 -31
- package/docs/recipes/45-cascaded-shadows.md +35 -26
- package/docs/recipes/46-blender-art-route.md +6 -1
- package/docs/recipes/49-game-module-contract.md +13 -8
- package/docs/recipes/50-own-renderer.md +6 -2
- package/docs/recipes/51-capability-catalog.md +15 -8
- package/docs/recipes/52-around-the-picture.md +34 -32
- package/docs/recipes/53-ground-up-close.md +6 -1
- package/docs/recipes/55-mods-time-wrap.md +27 -19
- package/docs/recipes/56-webgpu-tsl.md +74 -43
- package/docs/recipes/57-control.md +18 -13
- package/docs/recipes/58-input.md +26 -16
- package/docs/recipes/59-depth-post-effects.md +8 -3
- package/docs/recipes/60-judge-the-picture.md +9 -8
- package/docs/recipes/61-deploy.md +5 -0
- package/docs/recipes/62-picture-code.md +70 -79
- package/docs/recipes/63-third-person-start.md +47 -45
- package/docs/recipes/64-particles.md +22 -10
- package/docs/recipes/65-swarm.md +18 -13
- package/docs/recipes/66-common-tasks.md +38 -35
- package/examples/action/GAMEMAP.md +2 -3
- package/examples/action/main.js +3 -3
- package/examples/action/picture/lights.js +3 -1
- package/examples/perf-island/GAMEMAP.md +3 -3
- package/examples/perf-island/picture/lights.js +2 -1
- package/examples/plain-picture/GAMEMAP.md +1 -1
- package/examples/rc2d/GAMEMAP.md +1 -1
- package/examples/styletest/GAMEMAP.md +2 -2
- package/examples/styletest/main.js +1 -1
- package/examples/techniques/interior-light/README.md +3 -3
- package/examples/techniques/interior-light/interiorLight.js +2 -4
- package/examples/techniques/interior-light/picture/lights.js +2 -1
- package/examples/techniques/modular-building/picture/lights.js +3 -1
- package/examples/techniques/outlines-and-rim/picture/lights.js +3 -1
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/techniques/procedural-animation/main.js +1 -1
- package/examples/webgpu-tsl/GAMEMAP.md +1 -1
- package/examples/world/GAMEMAP.md +2 -3
- package/examples/world/art/humanoid.js +1 -1
- package/examples/world/main.js +6 -3
- package/index.d.ts +2 -2
- package/llms.txt +101 -0
- package/modules/ambience/Ambience.js +21 -5
- package/modules/calendar/index.js +9 -5
- package/modules/calendar/schedule.js +23 -8
- package/modules/camera/FirstPersonCamera.js +3 -1
- package/modules/camera/FollowCamera.js +10 -5
- package/modules/camera/RtsCamera.js +4 -3
- package/modules/camera/common.js +70 -8
- package/modules/camera/contract.js +1 -1
- package/modules/characters/Character.js +16 -10
- package/modules/characters/NPC.js +31 -19
- package/modules/characters/assetModel.js +14 -9
- package/modules/characters/astar.js +6 -1
- package/modules/characters/contract.js +2 -2
- package/modules/characters/index.js +34 -22
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +17 -2
- package/modules/characters/movers/simple.js +1 -1
- package/modules/characters/movers/support.js +16 -7
- package/modules/characters/npcAvoid.js +2 -2
- package/modules/characters/npcSim.js +3 -2
- package/modules/characters/pathAsync.js +24 -8
- package/modules/characters/pathJob.js +1 -1
- package/modules/characters/player.js +10 -9
- package/modules/characters/playerStrings.js +5 -5
- package/modules/characters/proceduralRig.js +5 -5
- package/modules/characters/useModel.js +6 -0
- package/modules/characters/walkTo.js +1 -1
- package/modules/collision/Collision.js +29 -18
- package/modules/collision/grid.js +22 -4
- package/modules/content/index.js +3 -1
- package/modules/content/loader.js +1 -1
- package/modules/content/models.js +82 -33
- package/modules/content/props.js +2 -1
- package/modules/content/rules.js +11 -5
- package/modules/content/templates.js +3 -3
- package/modules/content/words.js +2 -2
- package/modules/debug/DebugPanel.js +9 -9
- package/modules/flow/index.js +9 -6
- package/modules/gameplay/Dialogue.js +34 -20
- package/modules/gameplay/Interactions.js +19 -15
- package/modules/gameplay/Inventory.js +9 -4
- package/modules/gameplay/Quests.js +12 -10
- package/modules/gameplay/pickups.js +23 -11
- package/modules/grid/index.js +1 -1
- package/modules/grid/preview.js +2 -2
- package/modules/grid/tiles.js +1 -1
- package/modules/hlod/index.js +4 -1
- package/modules/hud/index.js +47 -10
- package/modules/hud/parts.js +28 -9
- package/modules/level/geometry.js +8 -3
- package/modules/level/index.js +10 -5
- package/modules/level/load.js +4 -2
- package/modules/lights/sources.js +1 -1
- package/modules/music/Music.js +22 -4
- package/modules/nav/index.js +20 -10
- package/modules/particles/Particles.js +31 -14
- package/modules/particles/effect.js +20 -5
- package/modules/particles/lit.js +72 -0
- package/modules/photo/Photo.js +72 -28
- package/modules/photo/pathTrace.js +106 -0
- package/modules/rigid/RigidBodies.js +23 -14
- package/modules/rigid/Vehicles.js +3 -13
- package/modules/rigid/sync.js +2 -1
- package/modules/settings/Settings.js +52 -20
- package/modules/settings/apply.js +23 -9
- package/modules/settings/sections.js +39 -6
- package/modules/settings/strings.js +2 -0
- package/modules/settings/view.js +19 -3
- package/modules/sky/dome.js +15 -3
- package/modules/sky/environment.js +28 -12
- package/modules/sky/fog.js +1 -1
- package/modules/sky/frame.js +6 -1
- package/modules/sky/shader.js +4 -3
- package/modules/sky/skyModule.js +8 -4
- package/modules/swarm/Swarm.js +1 -1
- package/modules/terrain/ChunkManager.js +61 -15
- package/modules/terrain/chunkJob.js +2 -2
- package/modules/terrain/index.js +20 -5
- package/modules/terrain/terrainEdit.js +8 -4
- package/modules/terrain/terrainTexture.js +4 -2
- package/modules/timeline/Timeline.js +4 -3
- package/modules/timeline/Tween.js +3 -0
- package/modules/timeline/letterbox.js +1 -0
- package/modules/triggers/index.js +36 -17
- package/modules/vegetation/Vegetation.js +81 -19
- package/modules/vegetation/densityMap.js +13 -8
- package/modules/vegetation/draw.js +147 -24
- package/modules/vegetation/groundChunks.js +20 -5
- package/modules/vegetation/index.js +3 -3
- package/modules/vegetation/modelGeometry.js +9 -4
- package/modules/water/Water.js +11 -8
- package/modules/weather/Weather.js +7 -2
- package/modules/weather/shaders.js +25 -5
- package/modules/weather/weatherDraw.js +20 -6
- package/modules/world/World.js +2 -1
- package/modules/world/index.js +2 -2
- package/modules/world/persist.js +6 -2
- package/modules/world/views.js +15 -2
- package/package.json +4 -1
- package/presets.js +5 -5
- package/render/PostFX.js +84 -41
- package/render/backend.js +137 -16
- package/render/cascades.js +3 -1
- package/render/cascades.tsl.js +2 -0
- package/render/daylight.js +7 -1
- package/render/detail.js +7 -4
- package/render/effects.js +27 -8
- package/render/fogLook.js +24 -0
- package/render/fuse.js +5 -2
- package/render/fx/detail.tsl.js +9 -7
- package/render/fx/index.js +7 -2
- package/render/fx/library.tsl.js +1 -0
- package/render/fx/lightShaft.tsl.js +114 -0
- package/render/fx/noise.tsl.js +25 -8
- package/render/fx/objectOrigin.tsl.js +39 -10
- package/render/fx/particles.tsl.js +23 -6
- package/render/fx/patchNodes.tsl.js +17 -12
- package/render/fx/pcss.tsl.js +51 -0
- package/render/fx/postWebGPU.tsl.js +89 -29
- package/render/fx/sky.tsl.js +3 -9
- package/render/fxNumbers.js +10 -4
- package/render/impostor.tsl.js +107 -0
- package/render/lighting.js +33 -1
- package/render/lightmap.js +42 -28
- package/render/lights.js +19 -3
- package/render/materials.js +6 -4
- package/render/mergeCommon.js +4 -1
- package/render/occlusion.js +14 -4
- package/render/patches.js +79 -41
- package/render/postRuns.js +32 -0
- package/render/postWebGL.js +97 -10
- package/render/probes.js +10 -14
- package/render/shaderErrors.js +2 -1
- package/render/shadowCache.tsl.js +33 -5
- package/render/shadows.js +42 -16
- package/render/slots.js +8 -5
- package/render/vertexInputs.js +52 -0
- package/types/core.d.ts +114 -46
- package/types/gameplay.d.ts +56 -23
- package/types/generated/core/audio/Audio.d.ts +27 -1
- package/types/generated/core/base/Random.d.ts +1 -1
- package/types/generated/core/input/Input.d.ts +6 -8
- package/types/generated/core/input/inputSeat.d.ts +1 -1
- package/types/generated/core/inspect/Budget.d.ts +26 -0
- package/types/generated/core/inspect/DebugOverrides.d.ts +0 -2
- package/types/generated/core/saves/Saves.d.ts +10 -7
- package/types/generated/core/saves/session.d.ts +8 -2
- package/types/generated/core/scene/Rays.d.ts +1 -3
- package/types/generated/modules/particles/Particles.d.ts +1 -1
- package/types/generated/modules/world/World.d.ts +2 -1
- package/types/generated/render/PostFX.d.ts +35 -9
- package/types/physics.d.ts +43 -11
- package/types/pixel.d.ts +1 -1
- package/types/tsl.d.ts +62 -1
- package/types/world.d.ts +12 -3
- package/ui/Focus.js +7 -5
- package/ui/Parts.js +1 -1
- package/ui/touchPart.js +6 -3
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Who steers a character: engine.control
|
|
2
2
|
|
|
3
|
+
> **Covers:** who steers a character: the control slot, script moves, vehicles, your own mover.
|
|
4
|
+
> **Use when:** a quest, cutscene or vehicle takes over a character.
|
|
5
|
+
> **Shortest:** `engine.control.take(character, { owner, step })`.
|
|
6
|
+
> **Sections:** Who takes what · Control is not the · Moved by script ride · Vehicles · Saves · Advanced your own mover
|
|
7
|
+
|
|
3
8
|
Every character (the player, an NPC, a hand-built `Character`) has one control slot. One owner is in charge of it at a time, and only that
|
|
4
9
|
owner moves the character. Take it, steer, give it back:
|
|
5
10
|
|
|
@@ -16,8 +21,8 @@ engine.clock.after(0.4, () => roll.remove(), { channel: 'real' });
|
|
|
16
21
|
const h = engine.control.take(drone, { owner: 'ai', layer: 'script' });
|
|
17
22
|
engine.onFixed(dt => h.move(dir.x, dir.z, false, dt));
|
|
18
23
|
|
|
19
|
-
engine.control.of(engine.player);
|
|
20
|
-
engine.describe().control;
|
|
24
|
+
engine.control.of(engine.player); // { owner: 'timeline', layer: 'cutscene', waiting: [{ owner: 'walkTo', layer: 'script' }, { owner: 'player-input', layer: 'base' }] }
|
|
25
|
+
engine.describe().control; // the same for every held character, by id
|
|
21
26
|
```
|
|
22
27
|
|
|
23
28
|
What to remember:
|
|
@@ -38,7 +43,7 @@ What to remember:
|
|
|
38
43
|
|
|
39
44
|
| Driver | Layer | Owner | Notes |
|
|
40
45
|
|---|---|---|---|
|
|
41
|
-
| `
|
|
46
|
+
| `addPlayer({ control })` | base | `'player-input'` | `control` is `'camera'` or `(player, input, dt) => ({ x, z, run })`; jump and driving live here too |
|
|
42
47
|
| NPC behaviour (schedule, wander, your own) | base | `'npcs'` | paused near and far while anything above holds the NPC; kept by NPC id, so it survives the model being rebuilt |
|
|
43
48
|
| `character.walkTo(target)` | script | `'walkTo'` | paused under a cutscene (no progress, no stuck clock), resumes after |
|
|
44
49
|
| `timeline.play(steps, { actors })` | cutscene | `'timeline'` | `actors` defaults to `[engine.player]`; `[]` drives nobody; a `path` step adds its character. Resolves `{ ending, error? }`: `'finished'`, `'skipped'`, `'dropped'` (a load, new game or dispose took its state) or `'failed'`; `timeline:end` carries the same. While the player is an actor, the `'cutscene'` input context is up |
|
|
@@ -71,7 +76,7 @@ const ride = engine.control.take(engine.player, { owner: 'boat', layer: 'script'
|
|
|
71
76
|
boat.updateWorldMatrix(true, false);
|
|
72
77
|
boat.localToWorld(ch.root.position.copy(seat));
|
|
73
78
|
ch.syncRecord();
|
|
74
|
-
return false;
|
|
79
|
+
return false; // placed by hand this step
|
|
75
80
|
} });
|
|
76
81
|
```
|
|
77
82
|
To lock the player's input during a scripted ride, one line: `const lock = engine.input.push('ride');` and `lock.remove()` at the end.
|
|
@@ -79,14 +84,14 @@ Gravity comes back the moment the hold ends, so end a ride where the character c
|
|
|
79
84
|
fixed step or an op. The camera and saves follow the position as usual.
|
|
80
85
|
|
|
81
86
|
```js fragment
|
|
82
|
-
// a ladder (the landing point must be ground or a registered platform, engine.characters.support; anywhere else it drops to what is below):
|
|
87
|
+
// a ladder (the landing point must be ground or a registered platform, engine.characters.support; anywhere else it drops to what is below): addPlayer({ clips: { climb: 'Climb' }, states: () => climbing ? 'climb' : null }), then call this when the player uses the ladder
|
|
83
88
|
let climbing = false;
|
|
84
|
-
function climb(player, top) {
|
|
85
|
-
climbing = true; player.mover = 'manual';
|
|
89
|
+
function climb(player, top) { // top: { x, y, z }, where it steps off, on ground or a registered platform
|
|
90
|
+
climbing = true; player.mover = 'manual'; // no gravity, the position is yours
|
|
86
91
|
const h = engine.control.take(player, { owner: 'ladder', layer: 'script', step: (dt, ch) => {
|
|
87
92
|
const up = (engine.input.down('moveForward') ? 1 : 0) - (engine.input.down('moveBack') ? 1 : 0);
|
|
88
93
|
ch.root.position.y += up * 2 * dt;
|
|
89
|
-
if (ch.root.position.y < top.y) return null;
|
|
94
|
+
if (ch.root.position.y < top.y) return null; // null: the mover runs, so states picks climb
|
|
90
95
|
climbing = false; ch.mover = 'simple'; h.remove(); ch.placeAt(top);
|
|
91
96
|
return false;
|
|
92
97
|
} });
|
|
@@ -100,9 +105,9 @@ cutscene that takes the player while driving stops the steering; the rider stays
|
|
|
100
105
|
|
|
101
106
|
Holding a car on the grid (a countdown, after the finish) is the same take, plus the brake, since a released pedal only rolls:
|
|
102
107
|
```js
|
|
103
|
-
const hold = engine.control.take(engine.player, { owner: 'race', layer: 'script', step: () => null });
|
|
104
|
-
engine.onFixed(() => { if (hold.active) car.drive(0, 0, 1); });
|
|
105
|
-
hold.remove();
|
|
108
|
+
const hold = engine.control.take(engine.player, { owner: 'race', layer: 'script', step: () => null }); // the keys stop driving
|
|
109
|
+
engine.onFixed(() => { if (hold.active) car.drive(0, 0, 1); }); // throttle, steer, brake
|
|
110
|
+
hold.remove(); // go
|
|
106
111
|
```
|
|
107
112
|
|
|
108
113
|
## Saves
|
|
@@ -122,8 +127,8 @@ const fly = (c, e) => ({ name: 'fly', move(x, z, run, dt, y) {
|
|
|
122
127
|
p.x += x * v; p.y += y * v; p.z += z * v;
|
|
123
128
|
c.grounded = false; e.characters.kit.ownState(c, 'fly', v / dt);
|
|
124
129
|
} });
|
|
125
|
-
const held = engine.mod('character.mover', { owner: 'wings', id: 'player', set: fly });
|
|
126
|
-
engine.player.mover = fly;
|
|
130
|
+
const held = engine.mod('character.mover', { owner: 'wings', id: 'player', set: fly }); // for a while: held.remove() puts back what was there
|
|
131
|
+
engine.player.mover = fly; // or for good
|
|
127
132
|
```
|
|
128
133
|
|
|
129
134
|
A mover that keeps something in the physics world gives it a `leave()`: the engine calls it when another mover takes over, and `move` runs again when it is back. `mover: 'rapier'` does this, so an NPC taking off leaves no capsule behind.
|
package/docs/recipes/58-input.md
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
# Input: modules declare actions, the game binds keys
|
|
2
2
|
|
|
3
|
+
> **Covers:** input: modules declare actions, the game binds keys, contexts, rebinding, local players.
|
|
4
|
+
> **Use when:** keys, mouse, gamepad or touch.
|
|
5
|
+
> **Shortest:** `createEngine({ bindings: { attack: ['KeyJ', 'Mouse0'] } })`.
|
|
6
|
+
> **Sections:** 1 Bind keys the · 2 Contexts the top · 3 In a module · 4 What the engine · 5 Rebinding the player) · Local players on one
|
|
7
|
+
|
|
3
8
|
Three roles, one rule each:
|
|
4
|
-
- **A module declares** an action and the context it is read in, never a key: `ctx.input.
|
|
9
|
+
- **A module declares** an action and the context it is read in, never a key: `ctx.input.define('choice1', { context: 'dialog' })`.
|
|
5
10
|
- **The game binds** keys: `createEngine({ bindings })`, `engine.input.bind(...)`, or a ready map from `presets.bindings`.
|
|
6
11
|
- **The player rebinds** in the settings menu, which calls `engine.input.rebind` and saves it.
|
|
7
12
|
|
|
@@ -12,14 +17,14 @@ Only the basics have default keys, the one default preset: WASD / arrows move (`
|
|
|
12
17
|
```js
|
|
13
18
|
import { createEngine, presets } from 'threedog';
|
|
14
19
|
const engine = createEngine({ canvas, bindings: {
|
|
15
|
-
attack: ['KeyJ', 'Mouse0', 'PadX'],
|
|
16
|
-
...presets.bindings.dialogNumbers,
|
|
17
|
-
...presets.bindings.debug,
|
|
20
|
+
attack: ['KeyJ', 'Mouse0', 'PadX'], // keyboard, mouse buttons (Mouse0 / 1 / 2) and gamepad buttons go in one list
|
|
21
|
+
...presets.bindings.dialogNumbers, // 1-9 pick dialogue choices
|
|
22
|
+
...presets.bindings.debug, // F3 debug panel, F4 trigger wireframes
|
|
18
23
|
} });
|
|
19
|
-
engine.input.bind('dodge', ['ShiftLeft']);
|
|
20
|
-
engine.input.bind(presets.bindings.rtsRotate);
|
|
21
|
-
engine.input.
|
|
22
|
-
engine.onFixed(() => { if (engine.input.pressed('attack')) swing(); });
|
|
24
|
+
engine.input.bind('dodge', ['ShiftLeft']); // later, in code; returns a handle, remove() takes the keys away
|
|
25
|
+
engine.input.bind(presets.bindings.rtsRotate); // a whole map at once: rotateLeft Q, rotateRight R
|
|
26
|
+
engine.input.define('brake', { context: 'vehicle', label: 'Brake', keys: ['KeyB'] }); // your own action with a context and a label for the menu
|
|
27
|
+
engine.onFixed(() => { if (engine.input.pressed('attack')) swing(); }); // gameplay keys are read in the fixed step
|
|
23
28
|
```
|
|
24
29
|
`presets.bindings`: `walk` (run / jump), `interact`, `inventory`, `quests`, `photo`, `gridRotate` (rotate), `brake`, `dialogNumbers` (choice1..9),
|
|
25
30
|
`rtsRotate` (rotateLeft / rotateRight), `cutsceneSkip` (skip: Backspace; cancel always skips), `debug` (debugPanel F3, triggersDebug F4). Spread one
|
|
@@ -30,16 +35,16 @@ its actions (gone with the module), the game binds them; `[]` is deliberately no
|
|
|
30
35
|
Every action belongs to one context. The stack starts with `walk`; a module or the game pushes others: `vehicle` (pass: unrelated `walk` actions
|
|
31
36
|
keep working), `dialog`, `menu`, `cutscene` (opaque: nothing below reads). The top context wins a key both bind.
|
|
32
37
|
```js
|
|
33
|
-
const car = engine.input.push('vehicle', { pass: true, owner: 'car' });
|
|
34
|
-
engine.describe().input
|
|
38
|
+
const car = engine.input.push('vehicle', { pass: true, owner: 'car' }); // brake (context vehicle) reads now; car.remove() pops it
|
|
39
|
+
engine.describe().input // { stack: ['walk', 'vehicle(owner: car)'], unbound: [], rebound: { attack: ['KeyK'] } }
|
|
35
40
|
```
|
|
36
41
|
Details of switching (next fixed step, no stuck keys, focus loss): recipe 07 §2b.
|
|
37
42
|
|
|
38
43
|
## 3. In a module: declare, read, leave
|
|
39
44
|
```js
|
|
40
45
|
const sprint = () => ({ name: 'sprint', type: 'rules', install(e, ctx) {
|
|
41
|
-
ctx.input.
|
|
42
|
-
ctx.input.
|
|
46
|
+
ctx.input.define('sprint', { label: 'sprint.action' }); // no keys: the game binds 'sprint'
|
|
47
|
+
ctx.input.define('sprintHud', { label: 'sprint.hud', optional: true }); // optional: reading it unbound is silent
|
|
43
48
|
}, fixed(dt, e) { if (e.input.down('sprint')) boost(e.player); } });
|
|
44
49
|
```
|
|
45
50
|
Everything a module declares or binds through `ctx.input` leaves with it (rollback, `replaces`, dispose).
|
|
@@ -47,8 +52,7 @@ Everything a module declares or binds through `ctx.input` leaves with it (rollba
|
|
|
47
52
|
## 4. What the engine tells you
|
|
48
53
|
- **`input-unbound`** (dev, once per action): a module needs an action nobody bound. The message names the action, its context and the bind line.
|
|
49
54
|
`engine.input.isUnbound('interact')` asks the same thing: true for no key at all, false for any key, an optional action or `[]` (no key on purpose).
|
|
50
|
-
- **`interaction-no-key`** (dev warning, once per action): interactions were added to an action with no key
|
|
51
|
-
and `ops` does not offer it, but `interaction.use` still runs when code asks: a click-only or touch-only game is right. `engine.input.bind('interact', [])` says so and ends the warning.
|
|
55
|
+
- **`interaction-no-key`** (dev warning, once per action): interactions were added to an action with no key (rule R51 warns in `check` too). A click-only or touch-only game is right: `engine.input.bind('interact', [])` says so and ends the warning.
|
|
52
56
|
- **`input-bound-twice`** (dev throws; release: the later wins): two owners bind one action, e.g. the game's `createEngine({ bindings })` and a
|
|
53
57
|
module's `ctx.input.bind` for the same action. Keep one. The same owner binding again only replaces its keys.
|
|
54
58
|
- **`input-action-context`**: two owners declare one action in different contexts. Rename one, or use the same context to share it.
|
|
@@ -59,15 +63,21 @@ Everything a module declares or binds through `ctx.input` leaves with it (rollba
|
|
|
59
63
|
`engine.input.rebound()` lists them (the settings menu saves exactly that and restores it at start, even before the module declaring an action is
|
|
60
64
|
installed). The settings menu's key page, its reset button and its save all go through these two calls.
|
|
61
65
|
|
|
66
|
+
## 6. Browser keys while playing
|
|
67
|
+
Playing (no menu or dialogue context, not paused) stops the browser acting on any key the game binds, modifiers included (Ctrl+S, F1, `/`, Backspace);
|
|
68
|
+
menus, pause and text fields get them back. `createEngine({ blockBrowserKeys: false })` turns it off. In dev, F5, Ctrl+R, F12 and Ctrl+Shift+I stay the browser's.
|
|
69
|
+
Limits: outside fullscreen Ctrl+W/T/N and Alt+F4 cannot be blocked; Esc always leaves fullscreen and pointer lock. In fullscreen on Chromium only, Keyboard Lock
|
|
70
|
+
captures the bound keys (Ctrl+W too; Esc then needs a long press). A desktop wrapper (Electron) can block all.
|
|
71
|
+
|
|
62
72
|
## Local players on one screen
|
|
63
73
|
|
|
64
74
|
A seat is one player's own keys and gamepad. It reads like `engine.input` (`axis`, `down`, `pressed`, `released`), so a control function works on either.
|
|
65
75
|
|
|
66
76
|
```js
|
|
67
77
|
const two = engine.input.seat({ pad: 1, keys: { moveForward: 'KeyI', moveBack: 'KeyK', moveLeft: 'KeyJ', moveRight: 'KeyL', jump: 'KeyU' } });
|
|
68
|
-
const p2 = engine.characters.
|
|
78
|
+
const p2 = engine.characters.addPlayer({ id: 'two', input: two, control: 'camera', spawn: [4, 0, 0] });
|
|
69
79
|
```
|
|
70
80
|
|
|
71
81
|
The seat's pad leaves `engine.input` and answers the game's pad bindings on this seat alone, so `bind('jump', ['PadA'])` works for it as written. A seat's keys are its own list: keep them out of the first player's bindings. Two seats on one pad or key, or one seat on two players, throw `input-seat`.
|
|
72
82
|
|
|
73
|
-
`engine.player` stays the first player; `p2` has its own world record, saved with the world, and `removePlayer('two')` takes it away. There is one screen and one camera. Footstep sounds and NPCs giving way cover every player. A seat with its own `interact` key uses what its player stands by, as that player (`seat.actor`, set by `
|
|
83
|
+
`engine.player` stays the first player; `p2` has its own world record, saved with the world, and `removePlayer('two')` takes it away. There is one screen and one camera. Footstep sounds and NPCs giving way cover every player. A seat with its own `interact` key uses what its player stands by, as that player (`seat.actor`, set by `addPlayer`; `ctx.actor` in the op). The prompt shows `engine.actor`'s choice alone, and one hold runs at a time. A trigger zone hears every player when its `who` names them.
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# A post effect that reads depth (volumetric fog, god rays)
|
|
2
2
|
|
|
3
|
+
> **Covers:** a post effect that reads depth on both renderers: volumetric fog, god rays.
|
|
4
|
+
> **Use when:** an effect needs the distance behind each pixel.
|
|
5
|
+
> **Shortest:** a Pass that reads the depth texture (§1).
|
|
6
|
+
> **Sections:** One effect, both renderers · Volumetric fog march along · God rays
|
|
7
|
+
|
|
3
8
|
Fog you march through, light shafts, haze that thickens with distance, edge or focus effects: they all read the scene depth behind each pixel
|
|
4
9
|
and turn it into a distance or a world position. This recipe writes one such effect with both forms, a three.js `Pass` (GLSL) for
|
|
5
10
|
WebGLRenderer and a TSL node for WebGPURenderer, in one effect object. How effects are ordered, switched and tuned is recipe 52's
|
|
@@ -26,7 +31,7 @@ class DepthHazePass extends Pass {
|
|
|
26
31
|
void main() {
|
|
27
32
|
vec4 base = texture2D(tDiffuse, vUv);
|
|
28
33
|
float z = texture2D(tDepth, vUv).x * 2.0 - 1.0;
|
|
29
|
-
float dist = 2.0 * uNear * uFar / (uFar + uNear - z * (uFar - uNear));
|
|
34
|
+
float dist = 2.0 * uNear * uFar / (uFar + uNear - z * (uFar - uNear)); // view distance in world units
|
|
30
35
|
gl_FragColor = vec4(mix(base.rgb, uColor, 1.0 - exp(-uDensity * dist)), base.a);
|
|
31
36
|
}`,
|
|
32
37
|
depthTest: false, depthWrite: false,
|
|
@@ -54,7 +59,7 @@ function depthHazeNode(input, { tsl: T, scenePass, camera, p }) {
|
|
|
54
59
|
const update = (pass, p) => { pass.material.uniforms.uColor.value.copy(p.color); pass.material.uniforms.uDensity.value = p.density; };
|
|
55
60
|
engine.post.add({ name: 'depthHaze', slot: 'hdr', needsDepth: true, params: { color: new THREE.Color(0.72, 0.76, 0.82), density: 0.02 },
|
|
56
61
|
create: ({ camera, params }) => { const pass = new DepthHazePass(camera); update(pass, params); return pass; }, update, node: depthHazeNode });
|
|
57
|
-
engine.post.get('depthHaze').set({ density: 0.05 });
|
|
62
|
+
engine.post.get('depthHaze').set({ density: 0.05 }); // live on both renderers
|
|
58
63
|
```
|
|
59
64
|
- Slot `hdr`: the effect works in linear color, before tone mapping, so a bright sun shaft can bloom after it.
|
|
60
65
|
- A world position instead of a distance (height fog, a fog volume): on WebGL multiply the clip-space point by `camera.projectionMatrixInverse`,
|
|
@@ -71,7 +76,7 @@ for an effect's node). On WebGL it is a plain `for` loop in the fragment shader.
|
|
|
71
76
|
function marchedFogNode(input, { tsl: T, p }) {
|
|
72
77
|
return T.Fn(() => {
|
|
73
78
|
const acc = T.float(0).toVar();
|
|
74
|
-
T.Loop(16, ({ i }) => { acc.addAssign(p.density.mul(T.float(i).add(0.5))); });
|
|
79
|
+
T.Loop(16, ({ i }) => { acc.addAssign(p.density.mul(T.float(i).add(0.5))); }); // your density per step goes here
|
|
75
80
|
return T.vec4(T.mix(input.rgb, p.color, acc.clamp(0, 1)), input.a);
|
|
76
81
|
})();
|
|
77
82
|
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
# 60 Make the picture look good: what each knob does and how to judge it
|
|
2
2
|
|
|
3
|
+
> **Covers:** visual polish, how to tune the picture: the knobs, what each does on screen, how to judge it.
|
|
4
|
+
> **Use when:** the picture looks flat or off and you want to know what to try.
|
|
5
|
+
> **Shortest:** judge in the loop of §1.
|
|
6
|
+
> **Sections:** How to judge, in · The knobs · When the picture check · Same knob, different styles
|
|
7
|
+
|
|
3
8
|
A map for visual polish: when you want to tune the picture, make a scene look prettier or closer to what the game wants, this page lists the
|
|
4
9
|
knobs, what each one changes on screen and how to tell it is right. **It is not a list of steps and nothing here is required**: pick the knobs
|
|
5
10
|
your style needs and leave the rest alone. There are no values to copy on purpose; the right value depends on the style, the camera and the
|
|
6
11
|
time of day, so every row says what to look for instead.
|
|
7
12
|
|
|
8
|
-
Where the rest lives (one home each,
|
|
9
|
-
- the calls, their parameters and who writes what: [recipe 52](52-around-the-picture.md) (reading the picture, the post chain, the ownership table);
|
|
10
|
-
- the plain three.js way and how the engine yields to it: [THREE.md](../THREE.md);
|
|
11
|
-
- questions about the whole picture (light roles, readability, consistency) and the numbers each shot prints: [recipe 35](35-picture-from-reference.md) "Picture questions" and "Picture check after every shot";
|
|
12
|
-
- a whole picture: the game's `picture/` code ([recipe 62](62-picture-code.md), materials and lights in [recipe 09](09-materials-lights-models.md)).
|
|
13
|
+
Where the rest lives (one home each): calls, parameters and who writes what: [recipe 52](52-around-the-picture.md); the plain three.js way: [THREE.md](../THREE.md); whole-picture questions and the numbers each shot prints: [recipe 35](35-picture-from-reference.md) "Picture questions" and "Picture check after every shot"; a whole picture: `picture/` code ([62](62-picture-code.md), materials and lights [09](09-materials-lights-models.md)).
|
|
13
14
|
|
|
14
15
|
## How to judge, in one loop
|
|
15
16
|
Change one knob, take a shot (`threedog shot`, or `threedog snap` on a running page), compare with the one before, keep or undo. Shoot the
|
|
@@ -25,14 +26,14 @@ shadow. `threedog examples pull sun-and-key-light` shows three routes side by si
|
|
|
25
26
|
|
|
26
27
|
| Knob | What it changes on screen | It is right when | How (details) |
|
|
27
28
|
|---|---|---|---|
|
|
28
|
-
| Sky gradient, horizon | the color from the top of the sky down to where it meets the ground | the horizon band and the fog agree where they meet; the top-to-horizon change matches the hour and mood; no visible seam | `engine.sky.top`, `engine.sky.horizon` ([08 §3](08-weather-sky.md#3-changing-sky-colors-sun-stars)); own shader: share `engine.uniforms.uSkyHorizon` / `uSkyTop` ([08](08-weather-sky.md#sky-color-for-my-shader-horizon-color-zenith-color)); own sky: `engine.sky.replace(mySky)` |
|
|
29
|
+
| Sky gradient, horizon | the color from the top of the sky down to where it meets the ground | the horizon band and the fog agree where they meet; the top-to-horizon change matches the hour and mood; no visible seam | `engine.sky.top`, `engine.sky.horizon` ([08 §3](08-weather-sky.md#3-changing-sky-colors-sun-stars-the-day-and-night-sky)); own shader: share `engine.uniforms.uSkyHorizon` / `uSkyTop` ([08](08-weather-sky.md#sky-color-for-my-shader-horizon-color-zenith-color)); own sky: `engine.sky.replace(mySky)` |
|
|
29
30
|
| Fog near / far | how fast distant things fade | the play space stays clear, the far edge of the world dissolves instead of ending in a line, landmarks you want seen still read | `engine.scene.fog = new THREE.Fog(color, near, far)` ([34 Fog](34-environment-lighting.md#fog-plain-threejs-signals-your-own-math)) |
|
|
30
31
|
| Fog color vs sky | whether the distance melts into the sky or into its own haze | distant hills fade toward the sky behind them; a fog color of its own is a choice you can name (smoke, mist, a dream) | `scene.fog.color`, your `picture/` code reads `uSkyHorizon` ([34 Fog](34-environment-lighting.md#fog-plain-threejs-signals-your-own-math)) |
|
|
31
32
|
| Exposure | overall brightness after lighting | the brightest things you care about keep detail and the darkest still read; a night is dark because the lights are, not because exposure hides it | `engine.renderer.toneMappingExposure` ([34 Exposure](34-environment-lighting.md#exposure-and-the-tone-curve)) |
|
|
32
33
|
| Tone mapping curve | how highlights roll off and how saturated bright colors stay | bright colors keep their hue where the style wants color, highlights soften where it wants film; flat-color styles may want almost no curve | `engine.renderer.toneMapping = THREE.AgXToneMapping` (or ACESFilmic, Neutral, No) ([52 Who writes it](52-around-the-picture.md#who-writes-it-the-ownership-table)) |
|
|
33
34
|
| Sun direction | where shadows fall and which faces are lit | shapes read from the camera (lit side and shaded side both visible), shadows point somewhere useful, the hour looks like the hour | time of day (`engine.calendar`, [06](06-clock-events.md)); sun path: `engine.sky.orbit.tilt`; the lights do not move on their own: aim yours from `engine.uniforms.uSunDir` ([62](62-picture-code.md)) |
|
|
34
35
|
| Sun color, intensity | the key light: color and strength of lit faces | lit and shaded sides separate; whites under the sun are the white the style wants (warm, neutral, cool) | your `picture/` code writes the light ([62](62-picture-code.md)) |
|
|
35
|
-
| Ambient / hemisphere, environment | the fill: how bright and what color the shaded side is | shadows are as deep as the style wants and still show shape; up-facing and down-facing faces differ; metals have something to reflect | your `picture/` code writes the hemisphere light and `scene.environment`, `scene.environmentIntensity` ([34](34-environment-lighting.md), [08 brightness](08-weather-sky.md#3-changing-sky-colors-sun-stars)) |
|
|
36
|
+
| Ambient / hemisphere, environment | the fill: how bright and what color the shaded side is | shadows are as deep as the style wants and still show shape; up-facing and down-facing faces differ; metals have something to reflect | your `picture/` code writes the hemisphere light and `scene.environment`, `scene.environmentIntensity` ([34](34-environment-lighting.md), [08 brightness](08-weather-sky.md#3-changing-sky-colors-sun-stars-the-day-and-night-sky)) |
|
|
36
37
|
| Shadow softness | hard or blurred shadow edges | edges match the light (crisp under a clear sun, soft under cloud or for a gentle style); no stair-steps or speckle | `renderer.shadowMap.type`, `light.shadow.radius` ([45](45-cascaded-shadows.md)) |
|
|
37
38
|
| Shadow distance, detail | how far shadows reach and how sharp small ones are | the area the player looks at has shadows; small props keep theirs; objects touch the ground (no gap under a foot) | `engine.shadows.box(sun, { extent })`, `engine.shadows.cascades(sun, { count, maxFar })`, `light.shadow.bias`, `mapSize` ([45](45-cascaded-shadows.md)) |
|
|
38
39
|
| Bloom | light bleeding around bright pixels | the bright things you meant (sun, lamps, magic) glow and nothing else does; the picture does not turn milky | `engine.post.add(bloom())` from `@threedog/post-effects`, or three's `UnrealBloomPass` through `engine.post.add(pass)` ([52 Post chain](52-around-the-picture.md#post-effect-chain)) |
|
|
@@ -45,7 +46,7 @@ shadow. `threedog examples pull sun-and-key-light` shows three routes side by si
|
|
|
45
46
|
| Ambient occlusion | darker creases and contact corners | objects sit on the ground and corners have weight; no dark halo around thin things | `engine.post.add(ao())` ([52 Post chain](52-around-the-picture.md#post-effect-chain)) |
|
|
46
47
|
| Outline | lines around shapes | lines help read shapes at play distance and match the style's line weight | `engine.post.add(outline())` ([52 Post chain](52-around-the-picture.md#post-effect-chain)), or three/addons `OutlinePass` |
|
|
47
48
|
| Surface shading | how light falls across a surface (smooth, banded, flat) | materials that should differ (wood, stone, metal, cloth) differ in response, not only in color | `new THREE.MeshToonMaterial({ gradientMap })` or any material of yours; `applyEffects(mat, { lighting })`, `rampTexture` ([43](43-shader-patches-surfaces.md), [09](09-materials-lights-models.md)) |
|
|
48
|
-
| God rays, volumetric fog | light shafts, fog thick in the air | shafts come from where the light is and fade when it leaves the screen |
|
|
49
|
+
| God rays, volumetric fog | light shafts, fog thick in the air | shafts come from where the light is and fade when it leaves the screen | `lightShaft`, `sunShafts`, `lightVolumes` ([34](34-environment-lighting.md)); haze by depth ([59](59-depth-post-effects.md)) |
|
|
49
50
|
|
|
50
51
|
## When the picture check names a feature
|
|
51
52
|
The check printed after every shot states a fact and, where the engine has a feature for it, one line of usage. Each is a way out, not a request: a
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Deploy: put the built game on a web server, at the site root or under a sub-path
|
|
2
2
|
|
|
3
|
+
> **Covers:** putting the built game on a web server, at the root or under a sub-path.
|
|
4
|
+
> **Use when:** publishing the game.
|
|
5
|
+
> **Shortest:** `npm run build`, then copy `dist/`.
|
|
6
|
+
> **Sections:** At the site root · Under a sub-path https · The server
|
|
7
|
+
|
|
3
8
|
`npm run build` writes the game to its `dist/`: plain files (HTML, JS, assets) that any static web server serves. Copy the whole folder.
|
|
4
9
|
|
|
5
10
|
## At the site root (`https://example.com/`)
|