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
package/docs/recipes/65-swarm.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Swarm: shots, crowds, pickups, debris by the thousand
|
|
2
2
|
|
|
3
|
+
> **Covers:** swarm: thousands of shots, crowds, pickups or debris in one draw.
|
|
4
|
+
> **Use when:** very many simple moving things.
|
|
5
|
+
> **Shortest:** `engine.use(swarm())`, then `engine.swarm({ name, capacity, geometry, material })`.
|
|
6
|
+
> **Sections:** Which tool for many · The id rule handles · Hits near · The same thing in · Drawing · Time, saves, limits · Pure picture GPU compute
|
|
7
|
+
|
|
3
8
|
```js
|
|
4
9
|
import * as THREE from 'three';
|
|
5
10
|
import { swarm } from 'threedog';
|
|
@@ -8,12 +13,12 @@ const bullets = engine.swarm({
|
|
|
8
13
|
name: 'bullets', capacity: 4096,
|
|
9
14
|
geometry: new THREE.SphereGeometry(0.1, 6, 4),
|
|
10
15
|
material: new THREE.MeshBasicMaterial({ color: 0xffffff }),
|
|
11
|
-
fields: ['vx', 'vz', 'life'],
|
|
16
|
+
fields: ['vx', 'vz', 'life'], // your own number columns, beside x, y, z
|
|
12
17
|
});
|
|
13
|
-
bullets.onStep((d, i, dt) => {
|
|
18
|
+
bullets.onStep((d, i, dt) => { // set once; runs every fixed step, for each live object
|
|
14
19
|
d.x[i] += d.vx[i] * dt;
|
|
15
20
|
d.z[i] += d.vz[i] * dt;
|
|
16
|
-
return (d.life[i] -= dt) > 0;
|
|
21
|
+
return (d.life[i] -= dt) > 0; // false removes it; anything else keeps it
|
|
17
22
|
});
|
|
18
23
|
engine.onFixed(() => {
|
|
19
24
|
if (engine.input.pressed('fire')) bullets.spawn({ x: 0, y: 1, z: 0, vx: 20, life: 2 });
|
|
@@ -45,9 +50,9 @@ Two numbers, never mixed up.
|
|
|
45
50
|
`swarm.row(handle)` turns a handle into today's row, -1 when it is gone. `free` takes a handle; given a row by mistake it throws `[swarm-handle]`.
|
|
46
51
|
```js
|
|
47
52
|
const enemies = engine.swarm({ name: 'enemies', capacity: 2000, fields: ['hp'] });
|
|
48
|
-
let target = enemies.spawn({ x: 5, z: 2, hp: 3 });
|
|
53
|
+
let target = enemies.spawn({ x: 5, z: 2, hp: 3 }); // a handle: safe to keep
|
|
49
54
|
engine.onFixed(() => {
|
|
50
|
-
const i = enemies.row(target);
|
|
55
|
+
const i = enemies.row(target); // today's row, -1 once it died
|
|
51
56
|
if (i < 0) return;
|
|
52
57
|
enemies.data.hp[i] -= 1;
|
|
53
58
|
if (enemies.data.hp[i] <= 0) enemies.free(target);
|
|
@@ -68,7 +73,7 @@ shots.onStep((d, i, dt) => {
|
|
|
68
73
|
crowd.near(d.x[i], d.z[i], 0.6, (c, j) => {
|
|
69
74
|
hit = true;
|
|
70
75
|
if ((c.hp[j] -= 1) <= 0) crowd.free(c.id[j]);
|
|
71
|
-
return false;
|
|
76
|
+
return false; // false stops the query: this shot is spent
|
|
72
77
|
});
|
|
73
78
|
return !hit;
|
|
74
79
|
});
|
|
@@ -88,7 +93,7 @@ const creeps = engine.swarm({ name: 'creeps', capacity: 500, fields: ['along', '
|
|
|
88
93
|
const towers = [{ x: 4, z: 4, target: -1 }];
|
|
89
94
|
engine.onFixed(() => {
|
|
90
95
|
for (const t of towers) {
|
|
91
|
-
if (creeps.row(t.target) >= 0) continue;
|
|
96
|
+
if (creeps.row(t.target) >= 0) continue; // still alive: keep shooting it
|
|
92
97
|
t.target = -1;
|
|
93
98
|
creeps.near(t.x, t.z, 8, (d, i) => { t.target = d.id[i]; return false; });
|
|
94
99
|
}
|
|
@@ -131,10 +136,10 @@ WebGPU device to be worth it: without one, use `engine.particles` or a swarm. Pi
|
|
|
131
136
|
code needs an answer back: reading a GPU buffer takes frames, so `near` and hits are out.
|
|
132
137
|
Build it with three's TSL as in three's own compute examples (an `instancedArray` buffer, compute nodes, a `SpriteNodeMaterial` reading the buffer through `positionNode`). What the engine adds is where each call goes:
|
|
133
138
|
```js fragment
|
|
134
|
-
import 'threedog/tsl';
|
|
135
|
-
const gpu = /** @type {any} */ (engine.renderer);
|
|
136
|
-
await gpu.computeAsync(seed);
|
|
137
|
-
engine.onFrame(d => { uDt.value = engine.frozen ? 0 : d; });
|
|
138
|
-
engine.onRender(() => { gpu.compute(fall); });
|
|
139
|
-
snow.frustumCulled = false;
|
|
139
|
+
import 'threedog/tsl'; // before createEngine
|
|
140
|
+
const gpu = /** @type {any} */ (engine.renderer); // a WebGPURenderer: the engine's type also covers WebGL
|
|
141
|
+
await gpu.computeAsync(seed); // once, to fill the buffer
|
|
142
|
+
engine.onFrame(d => { uDt.value = engine.frozen ? 0 : d; }); // time as a uniform set here, so a freeze stops the snow
|
|
143
|
+
engine.onRender(() => { gpu.compute(fall); }); // the shader here, so it runs once per drawn frame
|
|
144
|
+
snow.frustumCulled = false; // the sprite's own bounds know nothing of the flakes
|
|
140
145
|
```
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# Common tasks, complete
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
> **Covers:** common tasks as whole files that a test runs.
|
|
4
|
+
> **Use when:** you want a complete working example to copy.
|
|
5
|
+
> **Shortest:** the section for your task, printed by `threedog how`.
|
|
6
|
+
> **Sections:** Pickup something to take · Custom picture piece your · Saved game value a · Input action your own · Rain effect weather with · Custom NPC behaviour your · Custom path source paths · Two areas built in · Climb a ladder your · In an existing game · In an existing game · In an existing game · In an existing game · In an existing game
|
|
4
7
|
|
|
5
8
|
The most asked tasks, each as one short whole file: the modules it needs, the definitions, the input, then a check that also shows the cleanup. `threedog how` prints these sections whole, and a test runs every block, so they cannot go stale.
|
|
6
9
|
The sections "In an existing game" hold only the lines to add to a game that runs, with where they go, what to skip if it is there, the failure to handle and the check; `threedog how` prints them when it finds a game. They are a starting point, not the only way: each ends with the next route. Names like `gem` and `pace` stand for yours. The second block of a section runs on the live page with `threedog js --file <file>`.
|
|
@@ -9,9 +12,9 @@ The sections "In an existing game" hold only the lines to add to a game that run
|
|
|
9
12
|
```js
|
|
10
13
|
import { createEngine, presets, world, collision, characters, inventory, pickups, interactions } from 'threedog';
|
|
11
14
|
|
|
12
|
-
const engine = createEngine({ canvas: document.getElementById('view'), bindings: { ...presets.bindings.walk, ...presets.bindings.interact } });
|
|
15
|
+
const engine = createEngine({ canvas: document.getElementById('view'), bindings: { ...presets.bindings.walk, ...presets.bindings.interact } }); // interact is E
|
|
13
16
|
engine.use(world(), collision(), characters(), inventory(), pickups(), interactions({ ...presets.interactions.nearest }));
|
|
14
|
-
engine.characters.
|
|
17
|
+
engine.characters.addPlayer({ ...presets.player.thirdPerson, spawn: [0, 0, 0] });
|
|
15
18
|
engine.inventory.define('gem', { name: 'Gem' });
|
|
16
19
|
engine.pickups.spawn([1, 0, 0], { give: 'gem', id: 'gem-1' });
|
|
17
20
|
Object.assign(window, { engine });
|
|
@@ -22,7 +25,7 @@ step(0.2);
|
|
|
22
25
|
engine.input.simulate('interact', true); step(0.1); engine.input.simulate('interact', false); step(0.1);
|
|
23
26
|
expect(engine.inventory.count('gem'), 'E takes it').toBe(1);
|
|
24
27
|
const left = engine.pickups.spawn([3, 0, 0], { give: 'gem', id: 'gem-2' });
|
|
25
|
-
left.remove();
|
|
28
|
+
left.remove(); // cleanup: data and model go together
|
|
26
29
|
assert(!engine.world.get('gem-2'), 'a removed pickup is gone');
|
|
27
30
|
```
|
|
28
31
|
**When it does not fit:** a mesh you already have and a number on screen, with no bag: `engine.interactions.add(mesh, { once: true, counter })`, recipe 03 "Pick and count".
|
|
@@ -35,7 +38,7 @@ const lantern = () => ({ name: 'lantern', type: 'picture', install(e, ctx) {
|
|
|
35
38
|
const glow = new THREE.PointLight(0xffcc88, 2, 12);
|
|
36
39
|
glow.name = 'lantern-glow';
|
|
37
40
|
e.scene.add(glow);
|
|
38
|
-
ctx.track({ remove() { e.scene.remove(glow); glow.dispose(); } });
|
|
41
|
+
ctx.track({ remove() { e.scene.remove(glow); glow.dispose(); } }); // leaves with the piece
|
|
39
42
|
ctx.track(e.onRender(() => { glow.intensity = 2 + Math.sin(e.time.tick / 20) * 0.2; }));
|
|
40
43
|
} });
|
|
41
44
|
|
|
@@ -47,7 +50,7 @@ await engine.start();
|
|
|
47
50
|
```js
|
|
48
51
|
step(0.1);
|
|
49
52
|
assert(engine.scene.getObjectByName('lantern-glow'), 'the piece is in the scene');
|
|
50
|
-
await engine.unuse('lantern');
|
|
53
|
+
await engine.unuse('lantern'); // cleanup: what it tracked leaves with it
|
|
51
54
|
assert(!engine.scene.getObjectByName('lantern-glow'), 'the piece took its light away');
|
|
52
55
|
```
|
|
53
56
|
**When it does not fit:** one author and one look: put it in `picture/` and call it from `picture/index.js`, recipe 62. No module is needed to add a mesh: `engine.scene.add(mesh)` is plain three.js.
|
|
@@ -58,7 +61,7 @@ import { createEngine } from 'threedog';
|
|
|
58
61
|
|
|
59
62
|
const engine = createEngine({ canvas: document.getElementById('view') });
|
|
60
63
|
const best = { score: 0 };
|
|
61
|
-
engine.saves.
|
|
64
|
+
engine.saves.define('best', { version: 1, save: () => ({ ...best }), load: d => { best.score = d.score; } });
|
|
62
65
|
engine.onFixed(() => { best.score += 1; });
|
|
63
66
|
Object.assign(window, { engine, best });
|
|
64
67
|
await engine.start();
|
|
@@ -71,7 +74,7 @@ step(0.5);
|
|
|
71
74
|
assert(best.score > kept, 'the value moved on');
|
|
72
75
|
await engine.saves.load('check');
|
|
73
76
|
expect(best.score, 'the save brought it back').toBe(kept);
|
|
74
|
-
await engine.saves.remove('check');
|
|
77
|
+
await engine.saves.remove('check'); // cleanup: the test slot; the part itself lasts as long as the game
|
|
75
78
|
```
|
|
76
79
|
**When it does not fit:** a preference (volume, language) is not game state: `localStorage` with `engine.saves.storageKey(name)`. A best time that outlives every save: recipe 20. A value several systems change: `engine.mod`, recipe 55.
|
|
77
80
|
|
|
@@ -79,10 +82,10 @@ await engine.saves.remove('check'); // cleanup: the test slot; the
|
|
|
79
82
|
```js
|
|
80
83
|
import { createEngine } from 'threedog';
|
|
81
84
|
|
|
82
|
-
const engine = createEngine({ canvas: document.getElementById('view'), bindings: { dash: ['KeyQ', 'PadX'] } });
|
|
85
|
+
const engine = createEngine({ canvas: document.getElementById('view'), bindings: { dash: ['KeyQ', 'PadX'] } }); // the game binds keys, the player can rebind them
|
|
83
86
|
const dashes = { n: 0 };
|
|
84
|
-
const action = engine.input.
|
|
85
|
-
const reader = engine.onFixed(() => { if (engine.input.pressed('dash')) dashes.n++; });
|
|
87
|
+
const action = engine.input.define('dash', { label: 'Dash' });
|
|
88
|
+
const reader = engine.onFixed(() => { if (engine.input.pressed('dash')) dashes.n++; }); // gameplay reads in the fixed step
|
|
86
89
|
Object.assign(window, { engine, dashes, leave: () => { reader.remove(); action.remove(); } });
|
|
87
90
|
await engine.start();
|
|
88
91
|
```
|
|
@@ -90,7 +93,7 @@ await engine.start();
|
|
|
90
93
|
engine.input.simulate('dash', true); step(0.1); engine.input.simulate('dash', false); step(0.1);
|
|
91
94
|
expect(dashes.n, 'one press, one dash').toBe(1);
|
|
92
95
|
expect(engine.input.isUnbound('dash'), 'it has a key').toBe(false);
|
|
93
|
-
leave();
|
|
96
|
+
leave(); // cleanup: the reader and the action go; in a module, ctx.input takes them with it
|
|
94
97
|
```
|
|
95
98
|
**When it does not fit:** a key only inside a vehicle or menu: a context, `engine.input.push`, recipe 58 §2. A text field keeps its own browser listener.
|
|
96
99
|
|
|
@@ -109,7 +112,7 @@ engine.weather.set('rain', { seconds: 0 });
|
|
|
109
112
|
step(0.2);
|
|
110
113
|
expect(engine.describe().weather.name, 'it rains').toBe('rain');
|
|
111
114
|
assert(engine.describe().weather.rain > 0, 'the rain is falling');
|
|
112
|
-
engine.weather.set('clear', { seconds: 0 });
|
|
115
|
+
engine.weather.set('clear', { seconds: 0 }); // cleanup: the module stays, the rain stops
|
|
113
116
|
step(0.2);
|
|
114
117
|
expect(engine.describe().weather.name, 'it stopped').toBe('clear');
|
|
115
118
|
```
|
|
@@ -121,7 +124,7 @@ import { createEngine, world, collision, characters } from 'threedog';
|
|
|
121
124
|
|
|
122
125
|
const engine = createEngine({ canvas: document.getElementById('view') });
|
|
123
126
|
engine.use(world(), collision(), characters());
|
|
124
|
-
engine.npcs.behavior('pace', {
|
|
127
|
+
engine.npcs.behavior('pace', { // what must be remembered goes in rec.mind: plain values, saved with the NPC
|
|
125
128
|
near(rec, dt) { rec.mind.walked = (rec.mind.walked ?? 0) + dt; },
|
|
126
129
|
far(rec, dt) { rec.mind.walked = (rec.mind.walked ?? 0) + dt; },
|
|
127
130
|
});
|
|
@@ -132,7 +135,7 @@ await engine.start();
|
|
|
132
135
|
```js
|
|
133
136
|
step(0.5);
|
|
134
137
|
assert(engine.world.get('guard').mind.walked > 0, 'the behaviour runs');
|
|
135
|
-
engine.npcs.remove('guard');
|
|
138
|
+
engine.npcs.remove('guard'); // cleanup: the data, the model and its interaction go together
|
|
136
139
|
assert(!engine.npcs.get('guard'), 'the NPC is gone');
|
|
137
140
|
```
|
|
138
141
|
**When it does not fit:** a daily route needs no code: `schedule` or `behavior: 'wander'`, recipe 02. Something that is not a person (a crowd of birds): recipe 65, or your own objects and `engine.onFixed`.
|
|
@@ -152,7 +155,7 @@ window.rails = engine.mod('characters.path', { owner: 'rails', set: ({ from, to
|
|
|
152
155
|
const path = engine.characters.findPath({ x: 0, z: 0 }, { x: 4, z: 4 });
|
|
153
156
|
expect(path.length, 'the source answered').toBe(3);
|
|
154
157
|
expect(path[1].x, 'through its corner').toBe(4);
|
|
155
|
-
rails.remove();
|
|
158
|
+
rails.remove(); // cleanup: the built-in search answers again
|
|
156
159
|
assert(JSON.stringify(engine.characters.findPath({ x: 0, z: 0 }, { x: 4, z: 4 })) !== JSON.stringify(path), 'the source no longer answers');
|
|
157
160
|
```
|
|
158
161
|
**When it does not fit:** walking around obstacles on the ground needs no source: `engine.characters.findPath`, or `nav()` for a navmesh, recipe 12. One character only: give the entry an `id`.
|
|
@@ -166,7 +169,7 @@ const floor = size => new THREE.Mesh(new THREE.BoxGeometry(size, 1, size).transl
|
|
|
166
169
|
// a name in the manifest is what a save remembers, and its builder is how the area comes back: nothing else to wire
|
|
167
170
|
engine.assets.manifest({ models: { house: () => floor(20), outpost: () => floor(40) } });
|
|
168
171
|
engine.use(world(), collision(), characters(), level({ url: 'house' }));
|
|
169
|
-
engine.characters.
|
|
172
|
+
engine.characters.addPlayer({ control: () => null, spawn: [0, 0, 0] });
|
|
170
173
|
Object.assign(window, { engine });
|
|
171
174
|
await engine.start();
|
|
172
175
|
```
|
|
@@ -179,7 +182,7 @@ expect(engine.world.zone, 'walked back').toBe('house');
|
|
|
179
182
|
await engine.saves.load('check'); step(0.1);
|
|
180
183
|
expect(engine.world.zone, 'the save went back by itself').toBe('outpost');
|
|
181
184
|
expect(engine.player.position.x, 'with the player where it stood').toBe(15);
|
|
182
|
-
await engine.saves.remove('check');
|
|
185
|
+
await engine.saves.remove('check'); // cleanup: the test slot
|
|
183
186
|
```
|
|
184
187
|
**When it does not fit:** `level({ scene })` takes an object with no name, so a save cannot rebuild it: fine for a game with one area. Records with `zone: 'outpost'` show only there, recipe 07. Changing area in play: `engine.flow.transition`, recipe 07.
|
|
185
188
|
|
|
@@ -187,15 +190,15 @@ await engine.saves.remove('check'); // cleanup: the test slot
|
|
|
187
190
|
```js
|
|
188
191
|
import { createEngine, world, collision, characters } from 'threedog';
|
|
189
192
|
const engine = createEngine({ canvas: document.getElementById('view'), audio: { sounds: { rung: { src: 'footstep' } } } });
|
|
190
|
-
engine.use(world(), collision(), characters(), { name: 'ladder', afterLoad: () => grip() });
|
|
191
|
-
engine.setGround({ height: (x, z) => z > 1 ? 3 : 0, slope: () => 0, type: () => 'wood' });
|
|
192
|
-
const player = engine.characters.
|
|
193
|
-
let hold = null;
|
|
194
|
-
const grip = () => { hold?.remove(); hold = engine.world.get('player').climbing ? engine.control.take(player, { owner: 'ladder', step: (dt, ch) => (climb(dt, ch), false) }) : null; };
|
|
193
|
+
engine.use(world(), collision(), characters(), { name: 'ladder', afterLoad: () => grip() }); // after a load: the hold of the save, or none
|
|
194
|
+
engine.setGround({ height: (x, z) => z > 1 ? 3 : 0, slope: () => 0, type: () => 'wood' }); // the upper floor starts at z = 1
|
|
195
|
+
const player = engine.characters.addPlayer({ control: () => null, spawn: [0, 0, 0] });
|
|
196
|
+
let hold = null; // running code, so no save keeps it: the record field does, and grip puts the hold back
|
|
197
|
+
const grip = () => { hold?.remove(); hold = engine.world.get('player').climbing ? engine.control.take(player, { owner: 'ladder', step: (dt, ch) => (climb(dt, ch), false) }) : null; }; // false: placed by hand, no mover, no gravity
|
|
195
198
|
const climb = (dt, ch) => {
|
|
196
199
|
const y = ch.root.position.y += 1.5 * dt;
|
|
197
200
|
if (y % 0.5 < 1.5 * dt) engine.audio.sfx('rung', { at: ch.root });
|
|
198
|
-
ch.syncRecord(); engine.characters.kit.ownState(ch, 'climb', 1.5);
|
|
201
|
+
ch.syncRecord(); engine.characters.kit.ownState(ch, 'climb', 1.5); // the position is saved with the record, the state picks the animation
|
|
199
202
|
if (y >= 3) { engine.world.set('player', { climbing: false }); grip(); ch.placeAt([0, 3, 2]); }
|
|
200
203
|
};
|
|
201
204
|
engine.ops.define('ladder.climb', { run: e => { e.world.set('player', { climbing: true }); grip(); } });
|
|
@@ -216,7 +219,7 @@ step(0.5);
|
|
|
216
219
|
assert(engine.player.position.y > rung, 'and the climb goes on');
|
|
217
220
|
step(2);
|
|
218
221
|
expect(engine.player.position.y, 'to the top').toBe(3);
|
|
219
|
-
await engine.saves.remove('check');
|
|
222
|
+
await engine.saves.remove('check'); // cleanup: the test slot; the climb ended itself and took its hold away
|
|
220
223
|
```
|
|
221
224
|
**When it does not fit:** climbing with the up and down keys, or a climb animation clip: recipe 57 "a ladder". A climb that stops for a cutscene: a higher `layer` pauses this hold, recipe 57. Your own way of moving for a whole game (flying, swimming): your own mover, recipe 57.
|
|
222
225
|
|
|
@@ -225,7 +228,7 @@ await engine.saves.remove('check'); // cleanup: the test slot; the
|
|
|
225
228
|
// main.js imports: add the ones it lacks. engine.use goes before engine.start(); a module it already has is ignored with a warning, so drop those
|
|
226
229
|
import { presets, world, collision, characters, inventory, pickups, interactions } from 'threedog';
|
|
227
230
|
engine.use(world(), collision(), characters(), inventory({ capacity: 1, defaultStack: 1 }), pickups(), interactions({ ...presets.interactions.nearest }));
|
|
228
|
-
engine.characters.
|
|
231
|
+
engine.characters.addPlayer({ ...presets.player.thirdPerson, spawn: [0, 0, 0] }); // only if there is no hero yet
|
|
229
232
|
// where the level is set up
|
|
230
233
|
engine.inventory.define('gem', { name: 'Gem' });
|
|
231
234
|
engine.pickups.spawn([1, 0, 0], { give: 'gem', id: 'gem-1' });
|
|
@@ -238,7 +241,7 @@ expect(engine.inventory.add('gem').ok, 'a second gem does not fit').toBe(false);
|
|
|
238
241
|
step(0.2);
|
|
239
242
|
engine.input.simulate('interact', true); step(0.1); engine.input.simulate('interact', false); step(0.1);
|
|
240
243
|
assert(engine.world.get('gem-1'), 'with a full bag it stays on the ground');
|
|
241
|
-
engine.inventory.remove('gem');
|
|
244
|
+
engine.inventory.remove('gem'); // cleanup: the bag as it was
|
|
242
245
|
```
|
|
243
246
|
**When it does not fit:** it reuses what your game has: the whole file is "Pickup" above. Items in your own data: `inventory.define` takes them from `content/`, recipe 03.
|
|
244
247
|
|
|
@@ -246,7 +249,7 @@ engine.inventory.remove('gem'); // cleanup: the bag as it was
|
|
|
246
249
|
```js
|
|
247
250
|
// beside the system that owns the value, once, before the first load. A module's own state saves itself: this is for yours
|
|
248
251
|
const tally = { score: 0 };
|
|
249
|
-
engine.saves.
|
|
252
|
+
engine.saves.define('tally', { version: 1, save: () => ({ ...tally }), load: d => { tally.score = d.score; } });
|
|
250
253
|
// at a checkpoint or a menu: false means nothing was written, so say "saved" only after true
|
|
251
254
|
const saveTally = async () => { if (!await engine.saves.save('slot1')) console.warn('not saved'); };
|
|
252
255
|
```
|
|
@@ -256,7 +259,7 @@ await saveTally();
|
|
|
256
259
|
tally.score = 0;
|
|
257
260
|
expect(await engine.saves.load('slot1'), 'it loads').toBe(true);
|
|
258
261
|
expect(tally.score, 'the value came back').toBe(7);
|
|
259
|
-
await engine.saves.remove('slot1');
|
|
262
|
+
await engine.saves.remove('slot1'); // cleanup: the test slot
|
|
260
263
|
```
|
|
261
264
|
**When it does not fit:** a part that changes shape later needs a `migrate`: recipe 20. A preference is no game state: `localStorage`.
|
|
262
265
|
|
|
@@ -265,7 +268,7 @@ await engine.saves.remove('slot1'); // cleanup: the test slot
|
|
|
265
268
|
// main.js imports and engine.use, as in the pickup above. The key is the 'interact' action in your bindings
|
|
266
269
|
import { presets, world, collision, characters, interactions } from 'threedog';
|
|
267
270
|
engine.use(world(), collision(), characters(), interactions({ ...presets.interactions.nearest }));
|
|
268
|
-
engine.characters.
|
|
271
|
+
engine.characters.addPlayer({ ...presets.player.thirdPerson, spawn: [0, 0, 0] }); // only if there is no hero yet
|
|
269
272
|
// where the level is set up: a mesh of yours, or a position
|
|
270
273
|
const door = { open: false, locked: false };
|
|
271
274
|
const spot = engine.interactions.add([1, 0, 0], { onUse: () => { if (door.locked) return { ok: false, code: 'locked' }; door.open = true; } });
|
|
@@ -274,7 +277,7 @@ const spot = engine.interactions.add([1, 0, 0], { onUse: () => { if (door.locked
|
|
|
274
277
|
step(0.2);
|
|
275
278
|
engine.input.simulate('interact', true); step(0.1); engine.input.simulate('interact', false); step(0.1);
|
|
276
279
|
assert(door.open, 'E opens it');
|
|
277
|
-
spot.remove();
|
|
280
|
+
spot.remove(); // cleanup: the handle ends it with the door
|
|
278
281
|
```
|
|
279
282
|
**When it does not fit:** something that happens by walking in, with no key: `triggers()`. Clicking with the mouse: `engine.rays`, recipe 19.
|
|
280
283
|
|
|
@@ -288,16 +291,16 @@ const timer = engine.clock.after(2, () => { flags.late = true; }, { channel: 're
|
|
|
288
291
|
```js
|
|
289
292
|
step(2.1);
|
|
290
293
|
assert(flags.late, 'it ran in game time');
|
|
291
|
-
timer.remove();
|
|
294
|
+
timer.remove(); // cleanup: removing it twice is fine
|
|
292
295
|
```
|
|
293
|
-
**When it does not fit:** hours and days of a calendar: `calendar()`, recipe 06. A
|
|
296
|
+
**When it does not fit:** hours and days of a calendar: `calendar()`, recipe 06. A menu or a sound that must run while paused: frame seconds (`onFrame` dt), recipe 06.
|
|
294
297
|
|
|
295
298
|
## In an existing game: steer the hero for a moment
|
|
296
299
|
```js
|
|
297
300
|
// main.js imports and engine.use, as in the pickup above; a hero must exist
|
|
298
301
|
import { presets, world, collision, characters } from 'threedog';
|
|
299
302
|
engine.use(world(), collision(), characters());
|
|
300
|
-
engine.characters.
|
|
303
|
+
engine.characters.addPlayer({ ...presets.player.thirdPerson, spawn: [0, 0, 0] }); // only if there is no hero yet
|
|
301
304
|
// from your own rule: a hold outranks the keys until it ends, so never write the hero's position each frame
|
|
302
305
|
const dash = () => { const hold = engine.control.take(engine.player, { owner: 'dash', layer: 'script', step: () => ({ x: 0, z: 1, run: true }) }); engine.clock.after(0.4, () => hold.remove(), { channel: 'real' }); };
|
|
303
306
|
```
|
|
@@ -307,7 +310,7 @@ const from = engine.player.position.z;
|
|
|
307
310
|
dash();
|
|
308
311
|
step(0.3);
|
|
309
312
|
assert(engine.player.position.z !== from, 'the hold moved the hero');
|
|
310
|
-
step(0.3);
|
|
313
|
+
step(0.3); // cleanup: the hold ended by itself
|
|
311
314
|
expect(engine.control.of(engine.player).owner, 'the keys are back').toBe('player-input');
|
|
312
315
|
```
|
|
313
316
|
**When it does not fit:** a whole new way of moving: "Climb a ladder" above. A car or a ship: recipe 11. Who holds what: recipe 57.
|
|
@@ -23,7 +23,7 @@ Content: actions 4 · audio 1 · items 1 · places 1 · props 8 (from templates
|
|
|
23
23
|
|
|
24
24
|
## Read for this game (per installed module: recipe · api page; core API: `node_modules/threedog/docs/api/engine.md`)
|
|
25
25
|
|
|
26
|
-
- world: `node_modules/threedog/docs/recipes/
|
|
26
|
+
- world: `node_modules/threedog/docs/recipes/18-world.md` · `node_modules/threedog/docs/api/world.md`
|
|
27
27
|
- calendar: `node_modules/threedog/docs/recipes/06-clock-events.md` · `node_modules/threedog/docs/api/calendar.md`
|
|
28
28
|
- sky: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/sky.md`
|
|
29
29
|
- collision: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/collision.md`
|
|
@@ -59,7 +59,7 @@ content/*.js is content data: how to write it in `node_modules/threedog/docs/rec
|
|
|
59
59
|
| main.js | 136 | @ts-check Action example: one room, one player, one slime, one drop. Shows how an action game wires… |
|
|
60
60
|
| models.js | 25 | Models this example builds in code (floor, wall, pillar, enemy), registered by name through assets.… |
|
|
61
61
|
| picture/index.js | 14 | @ts-check The action room's picture: wiring only. No sky.js: the engine's dome is what shows beyond… |
|
|
62
|
-
| picture/lights.js |
|
|
62
|
+
| picture/lights.js | 38 | @ts-check Sun or moon and the ambient, from the signals. The ambient's sky half follows the engine'… |
|
|
63
63
|
| picture/materials.js | 9 | @ts-check Materials by name. Module level, because models.js is an asset generator that `npm run ch… |
|
|
64
64
|
| picture/palette.js | 34 | @ts-check The action room's palette: every color and key value of the picture, one copy; the other … |
|
|
65
65
|
|
|
@@ -106,7 +106,6 @@ Code that breaks saves or manages world models: none (rule R33).
|
|
|
106
106
|
|
|
107
107
|
- hud.bar('hp') — main.js
|
|
108
108
|
- hud.bar('enemy') — main.js
|
|
109
|
-
- hud.counter('gem') — main.js
|
|
110
109
|
|
|
111
110
|
## Key actions defined by the game (the engine's own are in node_modules/threedog/docs/CODEMAP.md)
|
|
112
111
|
|
package/examples/action/main.js
CHANGED
|
@@ -28,7 +28,7 @@ engine.use(openWorld({ camera: followCamera({ ...presets.camera.overShoulder, ya
|
|
|
28
28
|
const picture = withPicture ? createPicture(engine) : null;
|
|
29
29
|
|
|
30
30
|
engine.assets.manifest(packs); // assets.js: floor / wall / pillar / enemy (content/templates.js) and the blip synth (content/audio.js)
|
|
31
|
-
engine.characters.
|
|
31
|
+
engine.characters.addPlayer({ ...presets.player.aim, spawn: TUNE.spawn }); // no body asset: the engine's gray capsule; face where the camera looks: a swing goes where you aim
|
|
32
32
|
engine.content.load(data, { places: { room: { x: 0, z: 0 } } });
|
|
33
33
|
|
|
34
34
|
// ---------- Game state: plain values, described and saved (one player, so it is not keyed by actor) ----------
|
|
@@ -37,7 +37,7 @@ const fresh = () => ({ hp: TUNE.hp, cooldown: 0, over: false, deaths: 0 });
|
|
|
37
37
|
const game = fresh();
|
|
38
38
|
const slimes = () => engine.world.query({ kind: 'slime' }).map(r => ({ id: r.id, hp: r.hp, x: +r.position.x.toFixed(2), z: +r.position.z.toFixed(2) }));
|
|
39
39
|
engine.describe.add('action', () => ({ ...game, maxHp: TUNE.hp, onDeath: TUNE.onDeath, slimes: slimes() }));
|
|
40
|
-
engine.saves.
|
|
40
|
+
engine.saves.define('action', { version: 1, save: () => ({ ...game }), load: d => { Object.assign(game, fresh(), d); } });
|
|
41
41
|
|
|
42
42
|
// ---------- Ops: every caller (mouse, key, dev bridge, MCP, tests, enemy AI) runs the same rule ----------
|
|
43
43
|
const dist = (a, b) => Math.hypot(a.x - b.x, a.z - b.z);
|
|
@@ -124,7 +124,7 @@ engine.onFrame(() => {
|
|
|
124
124
|
engine.hud.bar('hp', { value: game.hp, max: TUNE.hp, label: 'HP' });
|
|
125
125
|
const s = engine.world.query({ kind: 'slime', near: engine.player.position, radius: TUNE.aggro + 2 })[0];
|
|
126
126
|
if (s) engine.hud.bar('enemy', { value: s.hp, max: s.maxHp, label: 'Slime' }); else engine.hud.remove('enemy');
|
|
127
|
-
engine.hud.
|
|
127
|
+
engine.hud.addCounter('gem', { icon: '💎', label: 'Gems', value: engine.inventory.count('gem') });
|
|
128
128
|
if (game.over !== shownOver && (shownOver = game.over) && TUNE.onDeath === 'gameover') toast(engine, 'You died. Press R to retry');
|
|
129
129
|
if (game.over && !restarting && (TUNE.onDeath === 'restart' || engine.input.pressed('retry'))) restarting = engine.session.newGame().finally(() => { restarting = null; });
|
|
130
130
|
if (engine.input.pressed('save')) engine.saves.save('slot1').then(ok => { if (ok) toast(engine, 'Saved'); });
|
|
@@ -13,7 +13,9 @@ export function createLights(engine) {
|
|
|
13
13
|
sun.shadow.mapSize.setScalar(engine.tier === 'low' ? 1024 : 2048);
|
|
14
14
|
Object.assign(sun.shadow.camera, { left: -SHADOW.extent, right: SHADOW.extent, top: SHADOW.extent, bottom: -SHADOW.extent, near: 1, far: SHADOW.far });
|
|
15
15
|
sun.shadow.camera.updateProjectionMatrix(); // three does not redo it for a light's shadow camera: without this line the box stays at its 10 m default
|
|
16
|
-
sun.shadow.bias = SHADOW.bias; sun.shadow.normalBias = SHADOW.normalBias;
|
|
16
|
+
sun.shadow.bias = SHADOW.bias; sun.shadow.normalBias = SHADOW.normalBias;
|
|
17
|
+
// radius is in shadow texels: scaled with the map so the low tier's half-size map blurs the same meters, never under 2 texels (stair steps) unless set lower
|
|
18
|
+
sun.shadow.radius = Math.max(Math.min(SHADOW.radius, 2), SHADOW.radius * sun.shadow.mapSize.x / 2048);
|
|
17
19
|
scene.add(hemi, fill, sun, sun.target);
|
|
18
20
|
|
|
19
21
|
const dir = new THREE.Vector3();
|
|
@@ -17,7 +17,7 @@ None yet, write them in `DESIGN.md` (why it is designed this way, what not to ch
|
|
|
17
17
|
|
|
18
18
|
## Read for this game (per installed module: recipe · api page; core API: `node_modules/threedog/docs/api/engine.md`)
|
|
19
19
|
|
|
20
|
-
- world: `node_modules/threedog/docs/recipes/
|
|
20
|
+
- world: `node_modules/threedog/docs/recipes/18-world.md` · `node_modules/threedog/docs/api/world.md`
|
|
21
21
|
- terrain: `node_modules/threedog/docs/recipes/28-terrain.md` · `node_modules/threedog/docs/api/terrain.md`
|
|
22
22
|
- vegetation: `node_modules/threedog/docs/recipes/36-ground-plants.md` · `node_modules/threedog/docs/api/vegetation.md`
|
|
23
23
|
- calendar: `node_modules/threedog/docs/recipes/06-clock-events.md` · `node_modules/threedog/docs/api/calendar.md`
|
|
@@ -31,7 +31,7 @@ None yet, write them in `DESIGN.md` (why it is designed this way, what not to ch
|
|
|
31
31
|
Not used yet (check these before writing the system yourself):
|
|
32
32
|
|
|
33
33
|
- inventory: items, stacks, containers and pickups: `inventory()` + key map presets.bindings.inventory, content/items.js (node_modules/threedog/docs/recipes/03-items-pickups.md)
|
|
34
|
-
- saves: save your own state: `engine.saves.
|
|
34
|
+
- saves: save your own state: `engine.saves.define(key, { version, save, load })` (node_modules/threedog/docs/recipes/20-content-actions-save.md)
|
|
35
35
|
- interactions: press a key near a thing: `interactions({ ...presets.interactions.nearest })` (E, nearest; the game picks the pick mode and keys), template `interact: { label, op }` (node_modules/threedog/docs/recipes/30-templates.md)
|
|
36
36
|
- quests: goals with steps, conditions and rewards: `quests()` + key map presets.bindings.quests, content/quests.js (node_modules/threedog/docs/recipes/04-quests.md)
|
|
37
37
|
- swarm: many same-kind moving things (shots, crowds, flocks, debris) in typed arrays, drawn as one mesh: `swarm()` (node_modules/threedog/docs/recipes/65-swarm.md)
|
|
@@ -52,7 +52,7 @@ content/*.js is content data: how to write it in `node_modules/threedog/docs/rec
|
|
|
52
52
|
| models.js | 49 | perf-island procedural models: a round tree, a sheep, a wheat tuft. Built in code, no files; regist… |
|
|
53
53
|
| params.js | 26 | URL parameters of the perf island page. Import this file first in main.js: it rewrites word values … |
|
|
54
54
|
| picture/index.js | 21 | @ts-check The picture of perf island: wiring only. Each part writes plain three.js from the signals… |
|
|
55
|
-
| picture/lights.js |
|
|
55
|
+
| picture/lights.js | 36 | @ts-check Sun or moon and ambient, both from the day table in palette.js. |
|
|
56
56
|
| picture/materials.js | 62 | @ts-check Materials by name. All matte Lambert with two shader additions: soft light (the wrap and … |
|
|
57
57
|
| picture/palette.js | 61 | @ts-check Perf island palette: every color and key value of the picture, one copy. A soft painted d… |
|
|
58
58
|
| picture/sky.js | 21 | @ts-check A flat painted backdrop: one color at every height, the same as the fog, so the island fl… |
|
|
@@ -11,7 +11,8 @@ export function createLights(engine) {
|
|
|
11
11
|
sun.castShadow = true;
|
|
12
12
|
sun.shadow.mapSize.setScalar(engine.tier === 'low' ? SHADOW.lowMapSize : SHADOW.mapSize);
|
|
13
13
|
Object.assign(sun.shadow.camera, { left: -SHADOW.extent, right: SHADOW.extent, top: SHADOW.extent, bottom: -SHADOW.extent, near: 1, far: 420 });
|
|
14
|
-
|
|
14
|
+
// radius is in shadow texels: scaled with the map so the low tier's half-size map blurs the same meters, never under 2 texels (stair steps) unless set lower
|
|
15
|
+
sun.shadow.radius = Math.max(Math.min(SHADOW.radius, 2), SHADOW.radius * sun.shadow.mapSize.x / SHADOW.mapSize);
|
|
15
16
|
sun.shadow.bias = -0.00005;
|
|
16
17
|
sun.shadow.normalBias = 0.04;
|
|
17
18
|
scene.add(hemi, sun, sun.target); // the target stays at the origin: the island is the whole world
|
|
@@ -29,7 +29,7 @@ Not used yet (check these before writing the system yourself):
|
|
|
29
29
|
- inventory: items, stacks, containers and pickups: `inventory()` + key map presets.bindings.inventory, content/items.js (node_modules/threedog/docs/recipes/03-items-pickups.md)
|
|
30
30
|
- collision: walls and blocking for characters: `collision()` (in openWorld), template `collide` (node_modules/threedog/docs/recipes/18-world.md)
|
|
31
31
|
- characters: player and NPC movement, spawn, schedules: `characters()` (in openWorld), content/npcs.js (node_modules/threedog/docs/recipes/02-npc.md)
|
|
32
|
-
- saves: save your own state: `engine.saves.
|
|
32
|
+
- saves: save your own state: `engine.saves.define(key, { version, save, load })` (node_modules/threedog/docs/recipes/20-content-actions-save.md)
|
|
33
33
|
- interactions: press a key near a thing: `interactions({ ...presets.interactions.nearest })` (E, nearest; the game picks the pick mode and keys), template `interact: { label, op }` (node_modules/threedog/docs/recipes/30-templates.md)
|
|
34
34
|
- quests: goals with steps, conditions and rewards: `quests()` + key map presets.bindings.quests, content/quests.js (node_modules/threedog/docs/recipes/04-quests.md)
|
|
35
35
|
- swarm: many same-kind moving things (shots, crowds, flocks, debris) in typed arrays, drawn as one mesh: `swarm()` (node_modules/threedog/docs/recipes/65-swarm.md)
|
package/examples/rc2d/GAMEMAP.md
CHANGED
|
@@ -23,7 +23,7 @@ Not used yet (check these before writing the system yourself):
|
|
|
23
23
|
- inventory: items, stacks, containers and pickups: `inventory()` + key map presets.bindings.inventory, content/items.js (node_modules/threedog/docs/recipes/03-items-pickups.md)
|
|
24
24
|
- collision: walls and blocking for characters: `collision()` (in openWorld), template `collide` (node_modules/threedog/docs/recipes/18-world.md)
|
|
25
25
|
- characters: player and NPC movement, spawn, schedules: `characters()` (in openWorld), content/npcs.js (node_modules/threedog/docs/recipes/02-npc.md)
|
|
26
|
-
- saves: save your own state: `engine.saves.
|
|
26
|
+
- saves: save your own state: `engine.saves.define(key, { version, save, load })` (node_modules/threedog/docs/recipes/20-content-actions-save.md)
|
|
27
27
|
- interactions: press a key near a thing: `interactions({ ...presets.interactions.nearest })` (E, nearest; the game picks the pick mode and keys), template `interact: { label, op }` (node_modules/threedog/docs/recipes/30-templates.md)
|
|
28
28
|
- quests: goals with steps, conditions and rewards: `quests()` + key map presets.bindings.quests, content/quests.js (node_modules/threedog/docs/recipes/04-quests.md)
|
|
29
29
|
- swarm: many same-kind moving things (shots, crowds, flocks, debris) in typed arrays, drawn as one mesh: `swarm()` (node_modules/threedog/docs/recipes/65-swarm.md)
|
|
@@ -23,7 +23,7 @@ None yet, write them in `DESIGN.md` (why it is designed this way, what not to ch
|
|
|
23
23
|
|
|
24
24
|
## Read for this game (per installed module: recipe · api page; core API: `node_modules/threedog/docs/api/engine.md`)
|
|
25
25
|
|
|
26
|
-
- world: `node_modules/threedog/docs/recipes/
|
|
26
|
+
- world: `node_modules/threedog/docs/recipes/18-world.md` · `node_modules/threedog/docs/api/world.md`
|
|
27
27
|
- terrain: `node_modules/threedog/docs/recipes/28-terrain.md` · `node_modules/threedog/docs/api/terrain.md`
|
|
28
28
|
- vegetation: `node_modules/threedog/docs/recipes/36-ground-plants.md` · `node_modules/threedog/docs/api/vegetation.md`
|
|
29
29
|
- calendar: `node_modules/threedog/docs/recipes/06-clock-events.md` · `node_modules/threedog/docs/api/calendar.md`
|
|
@@ -37,7 +37,7 @@ None yet, write them in `DESIGN.md` (why it is designed this way, what not to ch
|
|
|
37
37
|
|
|
38
38
|
Not used yet (check these before writing the system yourself):
|
|
39
39
|
|
|
40
|
-
- saves: save your own state: `engine.saves.
|
|
40
|
+
- saves: save your own state: `engine.saves.define(key, { version, save, load })` (node_modules/threedog/docs/recipes/20-content-actions-save.md)
|
|
41
41
|
- quests: goals with steps, conditions and rewards: `quests()` + key map presets.bindings.quests, content/quests.js (node_modules/threedog/docs/recipes/04-quests.md)
|
|
42
42
|
- swarm: many same-kind moving things (shots, crowds, flocks, debris) in typed arrays, drawn as one mesh: `swarm()` (node_modules/threedog/docs/recipes/65-swarm.md)
|
|
43
43
|
- grids: cell placement for farming and building: `grids()` (node_modules/threedog/docs/recipes/29-grid.md)
|
|
@@ -41,7 +41,7 @@ engine.use(openWorld({ camera: fixedCamera(), seed: SEED, terrain: { ...terrainP
|
|
|
41
41
|
|
|
42
42
|
const picture = createPicture(engine, { env: params.env });
|
|
43
43
|
engine.assets.manifest(packs); // assets.js: the world example's trees / rocks and the test models content/templates.js uses
|
|
44
|
-
engine.characters.
|
|
44
|
+
engine.characters.addPlayer({ ...presets.player.thirdPerson, model: 'humanoid', spawn: { x: stage.x + 0.5, z: stage.z + 6 } });
|
|
45
45
|
engine.content.load(data, { places: { stage, water } });
|
|
46
46
|
|
|
47
47
|
// ---------- 2. The room's lamp: on from 18:00 to 06:00 ----------
|
|
@@ -41,7 +41,7 @@ window dark but still readable if the game needs it readable. Check from the cam
|
|
|
41
41
|
## Plain three.js
|
|
42
42
|
- Sun patch: a `DirectionalLight` with `castShadow`, every wall / ceiling / frame `castShadow`, and `shadow.camera` fitted to the room
|
|
43
43
|
([DirectionalLightShadow](https://threejs.org/docs/#api/en/lights/shadows/DirectionalLightShadow)).
|
|
44
|
-
- Window sky light: [RectAreaLight](https://threejs.org/docs/#api/en/lights/RectAreaLight)
|
|
44
|
+
- Window sky light: [RectAreaLight](https://threejs.org/docs/#api/en/lights/RectAreaLight) (the engine loads its tables when it enters the scene)
|
|
45
45
|
([webgl_lights_rectarealight](https://threejs.org/examples/#webgl_lights_rectarealight)).
|
|
46
46
|
- Bounce: a [LightProbe](https://threejs.org/docs/#api/en/lights/LightProbe) filled by `LightProbeGenerator.fromCubeRenderTarget` after a
|
|
47
47
|
`CubeCamera` render inside the room; or a weak unshadowed `PointLight` above the patch; or a lightmap (`material.lightMap`, needs a second UV set).
|
|
@@ -64,7 +64,7 @@ window dark but still readable if the game needs it readable. Check from the cam
|
|
|
64
64
|
when the zone changes. It writes `hemi.intensity`, `scene.environmentIntensity` and `renderer.toneMappingExposure`; call its `update(dt)` from
|
|
65
65
|
`engine.onFrame`, and `update()` to jump to the zone's values at once. The page uses a box around the room and `EXPOSURE.day.outside` / `.inside`,
|
|
66
66
|
eased over `EXPOSURE.ease` seconds.
|
|
67
|
-
- `windowLight(engine, { position, lookAt, width, height })`: a `RectAreaLight`
|
|
67
|
+
- `windowLight(engine, { position, lookAt, width, height })`: a `RectAreaLight` placed in the opening and aimed.
|
|
68
68
|
|
|
69
69
|
| fill | what it gives | cost |
|
|
70
70
|
|---|---|---|
|
|
@@ -86,7 +86,7 @@ decay 2, intensity in candela) inside shades with an emissive of 0.35; one casts
|
|
|
86
86
|
only to the light that needs it). With bloom (`@threedog/post-effects`), keep the emitter's `emissiveIntensity` low or it blooms across the room.
|
|
87
87
|
|
|
88
88
|
Rules (correctness):
|
|
89
|
-
- `RectAreaLight`
|
|
89
|
+
- `RectAreaLight` lights only `MeshStandardMaterial` / `MeshPhysicalMaterial`, and **casts no
|
|
90
90
|
shadow**: it lights through furniture and walls on its front side. Use it for the window's soft sky light or a screen, and keep the
|
|
91
91
|
shadowed part to the sun (a DirectionalLight) or a SpotLight.
|
|
92
92
|
- The sun through a window needs every wall, the ceiling and the window frame to `castShadow`, and a shadow box that covers the room. `picture/lights.js`
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
// Interior light helpers (technique example, README.md next to this file). Imports only three
|
|
2
|
+
// Interior light helpers (technique example, README.md next to this file). Imports only three.
|
|
3
3
|
// Why helpers: the zone switch has to change exposure and the leaking outdoor ambient together, eased, and only when the zone changes;
|
|
4
|
-
// the window light
|
|
4
|
+
// the window light is placed and aimed in one call. The engine loads the RectAreaLight tables itself when the light enters the scene.
|
|
5
5
|
import * as THREE from 'three';
|
|
6
|
-
import { RectAreaLightUniformsLib } from 'three/addons/lights/RectAreaLightUniformsLib.js';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Exposure and ambient by zone, following the camera. `isInside(cameraPosition)` decides the zone; on a change the hemisphere / environment
|
|
@@ -38,7 +37,6 @@ export function exposureZones(engine, { hemi, isInside, exposure, ambient, ease
|
|
|
38
37
|
* @param {{ position: number[], lookAt: number[], width: number, height: number, color?: THREE.ColorRepresentation, intensity?: number }} o
|
|
39
38
|
*/
|
|
40
39
|
export function windowLight(engine, { position, lookAt, width, height, color = '#cfe0ff', intensity = 2 }) {
|
|
41
|
-
RectAreaLightUniformsLib.init(); // once per page is enough; calling it again is harmless
|
|
42
40
|
const area = new THREE.RectAreaLight(color, intensity, width, height);
|
|
43
41
|
area.position.set(position[0], position[1], position[2]);
|
|
44
42
|
area.lookAt(lookAt[0], lookAt[1], lookAt[2]);
|
|
@@ -20,7 +20,8 @@ export function createLights(engine, { night, fill, windowOpening }) {
|
|
|
20
20
|
const { extent: e, distance } = SHADOW;
|
|
21
21
|
Object.assign(sun.shadow.camera, { left: -e, right: e, top: e, bottom: -e, near: 1, far: distance * 2 });
|
|
22
22
|
// three adds bias in the shadow camera's 0-1 depth, i.e. a world offset of bias x (far - near)
|
|
23
|
-
|
|
23
|
+
// radius is in shadow texels: scaled with the map so the low tier's half-size map blurs the same meters, never under 2 texels (stair steps) unless set lower
|
|
24
|
+
Object.assign(sun.shadow, { normalBias: SHADOW.normalBias, bias: -SHADOW.biasCm / 100 / (distance * 2 - 1), radius: Math.max(Math.min(SHADOW.radius, 2), SHADOW.radius * sun.shadow.mapSize.x / SHADOW.mapSize.high) });
|
|
24
25
|
scene.add(hemi, sun, sun.target);
|
|
25
26
|
|
|
26
27
|
if (windowOpening && !night) windowLight(engine, { ...windowOpening, ...WINDOW_LIGHT });
|
|
@@ -11,7 +11,9 @@ export function createLights(engine) {
|
|
|
11
11
|
sun.castShadow = true;
|
|
12
12
|
sun.shadow.mapSize.setScalar(engine.tier === 'low' ? lowMapSize : mapSize);
|
|
13
13
|
Object.assign(sun.shadow.camera, { left: -extent, right: extent, top: extent, bottom: -extent, near: 1, far });
|
|
14
|
-
Object.assign(sun.shadow, { bias, normalBias
|
|
14
|
+
Object.assign(sun.shadow, { bias, normalBias });
|
|
15
|
+
// radius is in shadow texels: scaled with the map so the low tier's half-size map blurs the same meters, never under 2 texels (stair steps) unless set lower
|
|
16
|
+
sun.shadow.radius = Math.max(Math.min(radius, 2), radius * sun.shadow.mapSize.x / mapSize);
|
|
15
17
|
engine.scene.add(hemi, sun, sun.target);
|
|
16
18
|
|
|
17
19
|
const [ox, oy, oz] = key.offset;
|
|
@@ -12,7 +12,9 @@ export function createLights(engine) {
|
|
|
12
12
|
sun.castShadow = true;
|
|
13
13
|
sun.shadow.mapSize.setScalar(engine.tier === 'low' ? 1024 : 2048);
|
|
14
14
|
Object.assign(sun.shadow.camera, { left: -30, right: 30, top: 30, bottom: -30, near: 1, far: 250 });
|
|
15
|
-
sun.shadow.bias = -0.0001; sun.shadow.normalBias = 0.03;
|
|
15
|
+
sun.shadow.bias = -0.0001; sun.shadow.normalBias = 0.03; // the box covers the row of columns with a little margin
|
|
16
|
+
// radius is in shadow texels: scaled with the map so the low tier's half-size map blurs the same meters, never under 2 texels (stair steps) unless set lower
|
|
17
|
+
sun.shadow.radius = Math.max(Math.min(3, 2), 3 * sun.shadow.mapSize.x / 2048);
|
|
16
18
|
engine.scene.add(hemi, sun, sun.target);
|
|
17
19
|
return { sun, hemi };
|
|
18
20
|
}
|
|
@@ -49,7 +49,7 @@ do ears and tail settle without jitter? Values are a starting point to tune by e
|
|
|
49
49
|
is the sub-stepped spring (a long frame stays stable). `creature.js` (`buildCreature`, imports `three`) is a neutral box quadruped that exists
|
|
50
50
|
only so there is something to move; `main.js` wires it to a player.
|
|
51
51
|
1. Build the body with a pivot (a `Group`) at every joint. Names do not matter to the animator, only the `parts` object you pass.
|
|
52
|
-
2. Give it to a character as a ready rig: `
|
|
52
|
+
2. Give it to a character as a ready rig: `addPlayer({ ..., rig: { root, body: parts.body, limbs: [] } })` (`npcs.add` takes the same
|
|
53
53
|
`rig`). `limbs: []` means the engine swings nothing itself (recipe 13 section 3b describes its own limb swing, for comparison).
|
|
54
54
|
3. Drive the animator from `character.onPose((ch, dt) => animator.update(dt, { speed: ch.moveAmount, state: ch.state, grounded: ch.grounded, vy: ch.vy }))`.
|
|
55
55
|
For a prop or a creature that is not a character, call `update` from `engine.onFrame` with your own speed and state.
|
|
@@ -19,7 +19,7 @@ const { root, parts } = buildCreature({ material: mat.creature });
|
|
|
19
19
|
const RUN_SPEED = 7;
|
|
20
20
|
// The game's own state: 'sit' after 4 s without moving. The hook runs every fixed step after the mover's state; null keeps the mover's.
|
|
21
21
|
let stillSince = 0;
|
|
22
|
-
const player = engine.characters.
|
|
22
|
+
const player = engine.characters.addPlayer({
|
|
23
23
|
...presets.player.thirdPerson, runSpeed: RUN_SPEED,
|
|
24
24
|
// rig: the body is ours; limbs: [] so the engine swings nothing. The engine still bobs `body` from its own rule; onPose below overwrites it.
|
|
25
25
|
rig: { root, body: parts.body, limbs: [] },
|