threedog 1.1.0 → 1.3.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 +893 -798
- 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 +187 -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 +17 -7
- 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 +8 -7
- 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 +50 -28
- 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 +36 -15
- package/core/scene/adaptive.js +144 -21
- package/core/scene/drawOnly.js +17 -0
- package/core/scene/gameLights.js +47 -4
- 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 +17 -11
- package/docs/COMMANDS.md +139 -142
- 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 +30 -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/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 +24 -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 +7 -2
- 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 +75 -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 +10 -9
- package/docs/recipes/61-deploy.md +5 -0
- package/docs/recipes/62-picture-code.md +72 -79
- package/docs/recipes/63-third-person-start.md +48 -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/.threedog/content-index.json +1 -1
- 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/.threedog/content-index.json +1 -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/.threedog/content-index.json +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/.threedog/content-index.json +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 +5 -1
- package/presets.js +5 -5
- package/render/PostFX.js +102 -42
- package/render/backend.js +142 -16
- package/render/bindingLimits.js +59 -0
- 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/compareLevel.tsl.js +23 -0
- package/render/fx/detail.tsl.js +9 -7
- package/render/fx/index.js +9 -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 +104 -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 +44 -7
- 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 +115 -47
- 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/core/scene/Views.d.ts +17 -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 +796 -764
- 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,84 +1,73 @@
|
|
|
1
1
|
# Props and baking
|
|
2
2
|
|
|
3
|
-
**
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
> **Covers:** hand-placed props, models built in code, baking, loading, asset packs, deleting.
|
|
4
|
+
> **Use when:** putting objects and models into the world.
|
|
5
|
+
> **Shortest:** `{ model: 'pine', place: 'home', x: -8, z: -6 }` in the props content (§1).
|
|
6
|
+
> **Sections:** 1 Prop data · 2 Large code-generated models · 2a Models in plain · 2b Many copies of · 2c Art iteration loop · 2d Where art comes · 2e Plants on your · 2f Every model through · 3 Loading what is · 3b Asset packs a · 4 Verify · 5 Deleting objects
|
|
6
7
|
|
|
7
|
-
**Props** are a small number of hand-placed objects (a tree
|
|
8
|
-
`
|
|
9
|
-
|
|
10
|
-
things near the player need to block the way).
|
|
8
|
+
**Props** are a small number of hand-placed objects (a tree by a cabin, rocks, lamps), written as data; each entry becomes a `kind: 'prop'` record in
|
|
9
|
+
`engine.world` (needs `world()`, part of `openWorld()`). The model is created only when the player gets close (within `world.radius`, or the stream's
|
|
10
|
+
active radius when larger), and **the collision body and ray registration come and go with the model**.
|
|
11
11
|
Large repeated areas (forests, grass) don't use this; use `content/vegetation.js` (instanced vegetation), or section 2e for plants on your own geometry.
|
|
12
12
|
|
|
13
13
|
## 1. Prop data
|
|
14
14
|
`games/<game>/content/props.js` (a list; remember to add it to `content/index.js`):
|
|
15
15
|
```js
|
|
16
16
|
export default [
|
|
17
|
-
{ model: 'pine', place: 'home', x: -8, z: -6, scale: 1.2, collide: 'circle' },
|
|
18
|
-
{ model: ['flower', 0xf2d16b], place: 'home', x: 1.6, z: 3.4 },
|
|
19
|
-
{ model: 'rock', x: 120, z: -40, rot: 0.6, scale: 0.8, collide: 'box' },
|
|
20
|
-
{ model: 'well', place: 'home', x: 4, z: -4, y: 0, collide: 'box' },
|
|
21
|
-
{ model: 'crate', place: 'tower', x: 1, floor: 6, y: 0.5 },
|
|
17
|
+
{ model: 'pine', place: 'home', x: -8, z: -6, scale: 1.2, collide: 'circle' }, // an asset name (here a generator from an asset pack)
|
|
18
|
+
{ model: ['flower', 0xf2d16b], place: 'home', x: 1.6, z: 3.4 }, // a generator with arguments, use an array: flower(0xf2d16b)
|
|
19
|
+
{ model: 'rock', x: 120, z: -40, rot: 0.6, scale: 0.8, collide: 'box' }, // no place = world coordinates; rot in radians
|
|
20
|
+
{ model: 'well', place: 'home', x: 4, z: -4, y: 0, collide: 'box' }, // a file asset: assets.model('well')
|
|
21
|
+
{ model: 'crate', place: 'tower', x: 1, floor: 6, y: 0.5 }, // on the tower's second floor (not its roof), half a meter up
|
|
22
22
|
];
|
|
23
23
|
```
|
|
24
24
|
Fields: `id` (stable id, see below), `model`, `place` + `x/z` (relative to the place), `floor` (on multi-layer ground — a second storey, a bridge
|
|
25
25
|
deck, a lower dungeon level — the reference height of the layer it stands on; a level-marker place lends its own height), `y` (height above that
|
|
26
|
-
ground), `rot`, `scale`, `collide` (`'box'` / `'circle'` / `{ circle: 0.25, occluder: false }` / omitted = does not block; a circle stands on the model's base, see recipes/30-templates.md), `static: false` (do not register for rays), `batch: false` (see 2b).
|
|
26
|
+
ground), `rot`, `scale`, `collide` (`'box'` / `'circle'` / `{ circle: 0.25, occluder: false, layer: 'gate' }` (layer: recipe 12) / omitted = does not block; a circle stands on the model's base, see recipes/30-templates.md), `static: false` (do not register for rays), `batch: false` (see 2b).
|
|
27
27
|
An entry with `template` instead of `model` (`{ template: 'chest', x: 3, z: 1 }`) places an instance of a content template: a reusable object with
|
|
28
28
|
interaction, container and saved state (recipe 30).
|
|
29
|
-
A model is always an **asset name**, never a path or a function (`npm run check` reports both)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
The game's packs live in `assets.js` (export default one pack or a list), which main.js registers and `npm run check` imports, so the names it
|
|
33
|
-
checks are the names the game registers:
|
|
29
|
+
A model is always an **asset name**, never a path or a function (`npm run check` reports both). A file entry or a generator entry (built once per name + params:
|
|
30
|
+
baked file -> dev cache -> build) means the same in content (props, templates, vegetation, pickups), `assets.model(name)` and `vegetation.define(name, { model })`.
|
|
31
|
+
The game's packs live in `assets.js` (export default one pack or a list), which main.js registers and `npm run check` imports:
|
|
34
32
|
```js
|
|
35
33
|
// assets.js
|
|
36
|
-
import { assets as scenery } from 'some-asset-pack';
|
|
34
|
+
import { assets as scenery } from 'some-asset-pack'; // a published pack, or your own folder's
|
|
37
35
|
export default [scenery, { name: 'props', models: { well: '/models/well.glb', crate: () => makeCrate() } }];
|
|
38
36
|
// main.js
|
|
39
37
|
import packs from './assets.js';
|
|
40
|
-
engine.assets.manifest(packs);
|
|
38
|
+
engine.assets.manifest(packs); // pine, rock, ['flower', color], well, crate...
|
|
41
39
|
```
|
|
42
40
|
Props with the same model share one prototype (geometry and material are built once); each spot gets a clone.
|
|
43
41
|
|
|
44
|
-
**Stable ids and saves**:
|
|
45
|
-
|
|
46
|
-
during development and say how to fix it).
|
|
47
|
-
Inserting a new entry in the middle shifts the later indexes, so moves / deletions in old saves no longer match. **Give an `id` to any prop whose
|
|
42
|
+
**Stable ids and saves**: without an `id` the id is `prop:<model name>:<index in the props array>` (e.g. `prop:flower:5`); colliding ids throw in development.
|
|
43
|
+
Inserting an entry in the middle shifts the later indexes, so old saves' moves / deletions no longer match. **Give an `id` to any prop whose
|
|
48
44
|
content may still change.**
|
|
49
45
|
Get them in code, move or delete them (all saved with the game):
|
|
50
46
|
```js fragment
|
|
51
|
-
engine.world.query({ kind: 'prop' });
|
|
52
|
-
engine.world.move('prop:rock:3', { x: 12, z: -4 });
|
|
47
|
+
engine.world.query({ kind: 'prop' }); // all prop data { id, position, model, rot, scale, collide ... }
|
|
48
|
+
engine.world.move('prop:rock:3', { x: 12, z: -4 }); // move: model, collision and ray registration follow; height is recomputed from the ground
|
|
53
49
|
engine.world.set('prop:rock:3', { rot: 1.2, scale: 1.5 }); // change rotation / size
|
|
54
|
-
engine.world.remove('prop:pine:0');
|
|
55
|
-
engine.world.view('prop:rock:3');
|
|
50
|
+
engine.world.remove('prop:pine:0'); // delete (model and collision are removed together)
|
|
51
|
+
engine.world.view('prop:rock:3'); // the current model (null when the player is not near)
|
|
56
52
|
```
|
|
57
|
-
Props are the world's **initial data**: a save records only moves, changes and deletions, so
|
|
58
|
-
|
|
53
|
+
Props are the world's **initial data**: a save records only moves, changes and deletions, so `content.load` before or after a save load gives the same result,
|
|
54
|
+
and props added in a game update show up in an old save.
|
|
59
55
|
A prop whose position uses a level marker carries a `zone` (= level name): changing level only removes the model, and moves / deletions are still
|
|
60
56
|
there when you come back.
|
|
61
|
-
Procedural models of an asset pack (props, templates, vegetation, pickups) are built through that one path: if baked, the file in
|
|
62
|
-
`public/models/baked/` is read; during development the result is cached automatically.
|
|
63
57
|
Other things made in code have one home each: a texture made in code goes in the manifest's `textures` (a Texture or a function returning one), a
|
|
64
58
|
sound made in code (a synth function) in its `sounds`, and a material made in code is plain three.js in the game's `picture/` (recipe 09), not an asset.
|
|
65
|
-
Models
|
|
66
|
-
built
|
|
67
|
-
`await engine.world.whenReady`).
|
|
68
|
-
If a model fails to generate, world reports it once in the console, does not block loading, and retries when the player walks away and comes back.
|
|
59
|
+
Models load asynchronously; the loading screen waits for the ones nearby at the start (`engine.world.ready`), `world.view(id)` works after `start()`, and a model
|
|
60
|
+
built later appears a frame or two late (`await engine.world.whenReady`). A model that fails to generate is reported once, does not block loading, and retries when the player comes back.
|
|
69
61
|
|
|
70
62
|
## 2. Large code-generated models and baking
|
|
71
|
-
Big things assembled in code
|
|
72
|
-
development they are cached automatically (.threedog/cache) and recomputed when the code changes:
|
|
63
|
+
Big things assembled in code (a city block, a house) are a function registered in the manifest and fetched by name, cached in development (.threedog/cache) and recomputed when the code changes:
|
|
73
64
|
```js fragment
|
|
74
65
|
import { buildBlock } from './block.js';
|
|
75
|
-
engine.assets.manifest({ models: { 'city-block': buildBlock } });
|
|
66
|
+
engine.assets.manifest({ models: { 'city-block': buildBlock } }); // the function returns an Object3D or a geometry
|
|
76
67
|
const block = await engine.assets.model('city-block');
|
|
77
|
-
engine.use(level({ url: 'city-block' }));
|
|
68
|
+
engine.use(level({ url: 'city-block' })); // a level reads it by name: baked file and cache both apply, and loading a save can switch back to this map
|
|
78
69
|
```
|
|
79
|
-
To package a release or edit it in Blender,
|
|
80
|
-
in that game's folder). A game's picture lives in its own `picture/` folder; a model built there is baked the same way, by importing its
|
|
81
|
-
builder into `bake.js`:
|
|
70
|
+
To package a release or edit it in Blender, `npm run bake -- -w <game>` reads the `bake` export of the game's `bake.js` (a model built in `picture/` is baked the same way, by importing its builder):
|
|
82
71
|
```js
|
|
83
72
|
// games/<game>/bake.js
|
|
84
73
|
import { buildBlock } from './block.js';
|
|
@@ -90,9 +79,8 @@ If the generating code changes again: during development you are told to "switch
|
|
|
90
79
|
bake again. To keep editing in Blender, write that entry in `bake.js` as `{ build, source: 'file' }`; it is never overwritten afterwards.
|
|
91
80
|
|
|
92
81
|
## 2a. Models in plain three.js
|
|
93
|
-
No model file yet?
|
|
94
|
-
|
|
95
|
-
it by name, and use the name everywhere. Later a `.glb` registered under the same name replaces it with no other change.
|
|
82
|
+
No model file yet? Instead of loose `THREE.Mesh(new THREE.BoxGeometry())` calls in `main.js`, write the model as one plain three.js function (any geometry,
|
|
83
|
+
`three/addons` such as `RoundedBoxGeometry`, `mergeGeometries`, or a CSG library), register it by name and use the name; a `.glb` under the same name replaces it later.
|
|
96
84
|
|
|
97
85
|
**The generator contract**
|
|
98
86
|
- Return a `BufferGeometry` (drawn with a neutral gray material, or white under its vertex colors) or an `Object3D`
|
|
@@ -105,12 +93,11 @@ it by name, and use the name everywhere. Later a `.glb` registered under the sam
|
|
|
105
93
|
- Shadows: `{ build, castShadow: false }` in the manifest turns them off for every mesh. Without it, a generator that set `castShadow` or
|
|
106
94
|
`receiveShadow` on any of its meshes keeps its own flags (a rug that receives but does not cast); one that set none casts and receives
|
|
107
95
|
everywhere. The same rule holds for `assets.model(name)` and content props.
|
|
108
|
-
- It runs once per name + params; every placement is a clone sharing geometry and materials
|
|
109
|
-
- Who frees what: a copy from `assets.model` holds its original until `engine.remove`. `release` and `trim` skip what a copy still holds, and `describe().assets` counts `leases` and `waiting`. A generated model stays cached for good
|
|
96
|
+
- It runs once per name + params; every placement is a clone sharing geometry and materials.
|
|
97
|
+
- Who frees what: a copy from `assets.model` holds its original until `engine.remove`. `release` and `trim` skip what a copy still holds, and `describe().assets` counts `leases` and `waiting`. A generated model stays cached for good; a prototype (one per model) holds one copy until its last module unloads.
|
|
110
98
|
- Cache key = name + the generator's source (its file and imports) + params + `engine.assets.palette`. Values it reads from outer variables must go in
|
|
111
99
|
`params`, or a change keeps the stale model. In dev a build slower than `assets.cacheMinMs` (20 ms) is stored as GLB in `.threedog/cache` and
|
|
112
|
-
read back next time; `npm run bake` writes the same GLB to `public/models/baked/` (section 2). Neither is needed: unbaked generators run in
|
|
113
|
-
built game (`npm run build`) too.
|
|
100
|
+
read back next time; `npm run bake` writes the same GLB to `public/models/baked/` (section 2). Neither is needed: unbaked generators run in a build too.
|
|
114
101
|
- What the GLB round trip keeps: the hierarchy, names, `userData`, shadow flags, visibility, every material's type and settings, and textures in
|
|
115
102
|
standard slots (`map`, `normalMap`, ...; also ones made in code like `CanvasTexture`). A mesh with a material array comes back as one mesh per
|
|
116
103
|
material. **Lost**: a material's own `onBeforeCompile` and `applyEffects` patches, `lightMap` / `specularMap` / `envMap` and a toon `gradientMap`
|
|
@@ -119,7 +106,7 @@ it by name, and use the name everywhere. Later a `.glb` registered under the sam
|
|
|
119
106
|
|
|
120
107
|
```js
|
|
121
108
|
import * as THREE from 'three';
|
|
122
|
-
function lampPost() {
|
|
109
|
+
function lampPost() { // a function, not an arrow, so this.palette is there
|
|
123
110
|
const root = new THREE.Group();
|
|
124
111
|
root.add(new THREE.Mesh(new THREE.CylinderGeometry(0.05, 0.07, 3, 12), new THREE.MeshStandardMaterial({ color: this.palette.metal ?? 0x3a3d42 })));
|
|
125
112
|
return root;
|
|
@@ -132,8 +119,7 @@ engine.assets.manifest({ name: 'props', models: { lampPost } });
|
|
|
132
119
|
above); vertex colors for a merged model from `mergeColored([[geometry, this.palette.wood], ...])`, which returns one geometry.
|
|
133
120
|
|
|
134
121
|
**The palette.** `engine.assets.palette` is a plain object of named colors: `engine.assets.palette = { wood: 0x8a5a36, leaf: 0xd98a3a }`, or write one key.
|
|
135
|
-
Generators and code-made textures read it as `this.palette`. Set it before the models load
|
|
136
|
-
new colors, while copies already placed keep theirs. `.glb` files never follow it, and a baked file (built with no palette) is skipped while the palette
|
|
122
|
+
Generators and code-made textures read it as `this.palette`. Set it before the models load: copies already placed keep their colors. `.glb` files never follow it, and a baked file (built with no palette) is skipped while the palette
|
|
137
123
|
has keys, unless its bake entry says `source: 'file'`.
|
|
138
124
|
|
|
139
125
|
Very detailed models (faces, sculpted shapes, hand-painted textures) are faster in Blender: export a GLB and register it (recipe 46).
|
|
@@ -145,9 +131,9 @@ drawn by one real `THREE.InstancedMesh` per cell; fewer stay plain meshes. Each
|
|
|
145
131
|
collision and interactions; only its meshes are moved to layer 31 (not drawn), so `engine.raycast` / `pick` / photo return the original object,
|
|
146
132
|
not an instance index.
|
|
147
133
|
|
|
148
|
-
Objects your code
|
|
149
|
-
|
|
150
|
-
|
|
134
|
+
Objects your code adds (`engine.scene.add(mesh)`, `engine.add(mesh)`, `engine.rigid.addBox / addBall / addHull(mesh)`) are never touched unless you ask, so your own
|
|
135
|
+
raycasts and material swaps see the meshes you made. Many static copies of your own mesh (fence posts, tiles) opt in with one flag on the root, set before adding it
|
|
136
|
+
(or `engine.batching.refresh(obj)` after). In dev, `engine.inspect.perf()` and
|
|
151
137
|
`describe().perf.batching.hint` say so when many identical meshes of yours draw one by one.
|
|
152
138
|
```js fragment
|
|
153
139
|
for (const p of postSpots) { const m = new THREE.Mesh(postGeo, woodMat); m.position.copy(p); m.userData.batch = true; engine.scene.add(m); }
|
|
@@ -155,31 +141,30 @@ for (const p of postSpots) { const m = new THREE.Mesh(postGeo, woodMat); m.posit
|
|
|
155
141
|
```js
|
|
156
142
|
const crate = engine.world.view('crate_3');
|
|
157
143
|
if (crate) {
|
|
158
|
-
engine.batching.tint(crate, 0xff8080);
|
|
159
|
-
engine.batching.of(crate);
|
|
144
|
+
engine.batching.tint(crate, 0xff8080); // recolor one copy (instance color; null restores)
|
|
145
|
+
engine.batching.of(crate); // [{ mesh: InstancedMesh, index }], [] when drawn on its own
|
|
160
146
|
}
|
|
161
|
-
engine.batching.stats;
|
|
162
|
-
engine.batching.enabled = false;
|
|
147
|
+
engine.batching.stats; // { batches, instances, saved, note?, hint? } (also describe().perf.batching); engine.batching.batches lists them
|
|
148
|
+
engine.batching.enabled = false; // global switch; createEngine({ batching: false }) never starts it, { minCount, cell } tunes it (wider cells draw fewer objects, narrower cull finer)
|
|
163
149
|
```
|
|
164
150
|
- Move / hide / remove a copy as usual (`world.move`, `obj.visible = false`, `engine.remove`): its instance follows next frame; unloading a cell frees
|
|
165
151
|
its batch.
|
|
166
152
|
- Opt out: `batch: false` on a prop / record entry, or `userData.batch = false` on a model a `world.present` build or stream build returns (clones
|
|
167
|
-
inherit it, so set it on the prototype)
|
|
168
|
-
whose parts you animate or whose materials you swap; if you forget, the copy is taken out of its batch automatically with a one-time dev warning.
|
|
153
|
+
inherit it, so set it on the prototype) for models whose parts you animate or whose materials you swap; forgotten, the copy leaves its batch with a one-time dev warning.
|
|
169
154
|
- Never batched: skinned, morphing or animated models, multi-material or transparent meshes, `ShaderMaterial`, meshes with children, and level
|
|
170
155
|
geometry `hlod` registered (hlod owns far, batching owns near).
|
|
171
156
|
|
|
172
157
|
### Render bundles: three's BundleGroup, for static meshes that cannot batch
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
- **It replays what it recorded.** A child's `visible`, an added or removed child and `castShadow` show only after `bundle.needsUpdate = true
|
|
158
|
+
WebGPU only, no engine API: `BundleGroup` (`three/webgpu`) is plain three.js. Batch first: batching removes objects, a bundle only removes the command recording of objects
|
|
159
|
+
that stay (three still refreshes each every pass). Compare before you keep it.
|
|
160
|
+
- **It replays what it recorded.** A child's `visible`, an added or removed child and `castShadow` show only after `bundle.needsUpdate = true`; recording hitches a frame on a big bundle, so several small bundles beat one huge one if parts change. `bundle.visible` works at once.
|
|
176
161
|
- **Nothing inside is culled**, in the shadow pass too: size groups so `visible` can drop a whole one.
|
|
177
|
-
- **One owner per mesh.** A mesh under a `BundleGroup` is the bundle's: `engine.batching` leaves it alone (`userData.batch = true` on the group warns once) and `hlod.add` skips it with a warning
|
|
162
|
+
- **One owner per mesh.** A mesh under a `BundleGroup` is the bundle's: `engine.batching` leaves it alone (`userData.batch = true` on the group warns once) and `hlod.add` skips it with a warning (neither could hide it); occlusion culling does not reach it. `engine.stream` works as usual, a build may return a `BundleGroup`.
|
|
178
163
|
- On a WebGL backend it is a plain group: correct, no gain. `describe().render.bundles` gives `{ groups, meshes, replayed }`; `engine.inspect.scene()` adds the reason `in-bundle`.
|
|
179
164
|
|
|
180
165
|
## 2c. Art iteration loop: edit -> hot swap -> gallery -> compare
|
|
181
|
-
|
|
182
|
-
|
|
166
|
+
For any model made in code; the tools only build and show. For the models that matter (characters, main buildings, repeated props), plan parts and
|
|
167
|
+
proportions first, and look at the model on its own afterwards, not only inside the level.
|
|
183
168
|
- **Edit, see it in place**: keep generators in modules imported by the game's `assets.js` (for example an `art/` folder). Saving one (dev server) rebuilds
|
|
184
169
|
its models and swaps every live copy in place: content props, template parts, pickups, vegetation instances, `assets.model` copies. Camera,
|
|
185
170
|
player, time and world state stay; `describe().assetSwaps` and a toast say what changed. A collision box keeps its placed size until the next
|
|
@@ -188,11 +173,20 @@ props repeated across the level), think through the parts and their proportions
|
|
|
188
173
|
copies (`engine.assets.setParams(name, values)`). "write back", then `threedog tune write` (dry run; `--apply`) puts the values into the
|
|
189
174
|
schema's `default` where the model is registered.
|
|
190
175
|
- **Review all at once**: `?gallery=1` on the dev page, or `threedog gallery`, puts every registered model and texture on a turntable;
|
|
191
|
-
`--shots` writes one page of pictures, `--mode silhouette,value` adds outline and grayscale shots with measurements (`../COMMANDS.md`).
|
|
192
|
-
narrow p5-p95 spread means hue carries the form; compare assets that must be told apart with each other rather than with a fixed number.
|
|
176
|
+
`--shots` writes one page of pictures, `--mode silhouette,value` adds outline and grayscale shots with measurements (`../COMMANDS.md`). Measurements, not grades: a shape should still read as a silhouette at play distance, a narrow p5-p95 value spread means hue carries the form, and assets to tell apart are compared with each other, not a fixed number.
|
|
193
177
|
- **Compare with the reference**: `threedog picture compare <reference.png> .threedog/gallery/<name>-midday.png --out diff.png` gives numbers
|
|
194
178
|
for one asset against its reference crop, the same way as for a whole screenshot (`recipes/35-picture-from-reference.md`).
|
|
195
179
|
|
|
180
|
+
### Look-dev: one model, material or shader alone, channel by channel, under several environments
|
|
181
|
+
The gallery is also the look-dev page (turntable, environment, exposure, tone mapping, one channel at a time). Headless, one picture per channel and light:
|
|
182
|
+
```sh
|
|
183
|
+
threedog gallery --shots --only crate --mode albedo,normal,roughness,metalness,ao --light midday,studio,game
|
|
184
|
+
threedog gallery --shots --material lava --mode roughness --tone agx --exposure 1.4 # one material of the scene (TSL too) on a sphere
|
|
185
|
+
```
|
|
186
|
+
`studio`: a neutral room to reflect (metals read near black without an environment map); `game`: copies of the game's lights and environment
|
|
187
|
+
map (no post chain). `--tone`: none, linear, reinhard, cineon, aces, agx, neutral. Gray channels show the value itself, so their `p5` / `p50` / `p95`
|
|
188
|
+
are the material's numbers. `?gallery=1` has the same switches (channels on a WebGPU game). The whole scene through the game camera: `engine.debug.view` (recipe 46).
|
|
189
|
+
|
|
196
190
|
## 2d. Where art comes from
|
|
197
191
|
The engine ships no art and picks no source: the game records its choice per kind (ground, vegetation, characters, props, effects, sounds) in
|
|
198
192
|
the DESIGN.md "Asset sources" row, and every source ends up the same way, as a name in an `engine.assets.manifest` pack.
|
|
@@ -205,9 +199,7 @@ the DESIGN.md "Asset sources" row, and every source ends up the same way, as a n
|
|
|
205
199
|
| Your own earlier games | an effect, material, model or texture you already made and liked | `threedog lib list` / `lib pull` (below), or `threedog art copy ../earlier-game name` |
|
|
206
200
|
| AI-generated 3D / textures | one-off props, texture variations | export glTF / PNG, then the same checks as any file: `threedog assets check`, scale, origin, triangle count, UVs |
|
|
207
201
|
|
|
208
|
-
**
|
|
209
|
-
|
|
210
|
-
**Your own library.** `threedog lib add <file|folder|exportName> -w earlier-game` keeps a piece of a finished game in `~/.threedog/library`, `threedog lib list [words]` searches it, `threedog lib pull <name>` copies it into this game; flags and where each kind lands in `../COMMANDS.md`. Look here before writing an effect from scratch. A pulled entry is a copy with no link back and no update: change it to fit this game rather than keeping it as it was, or every game ends up looking alike.
|
|
202
|
+
**Your own library** (`threedog lib add / list / pull / check`, flags in `../COMMANDS.md`): look there before writing an effect from scratch. Each entry has a card measured at `lib add` (needs, provides, shared three.js values it writes, size, usage; `lib list <word> --card`); tag its style with `--style` (two pulled entries with no tag in common are reported). A pulled entry is a copy with no link back: change it to fit this game, or every game looks alike.
|
|
211
203
|
|
|
212
204
|
**Rules (correctness and licensing):**
|
|
213
205
|
- Read the license of every asset you did not make, on the page you downloaded it from, before it goes into the game; a library can mix
|
|
@@ -218,44 +210,58 @@ the DESIGN.md "Asset sources" row, and every source ends up the same way, as a n
|
|
|
218
210
|
- An imported file passes `threedog assets check` (missing UVs, oversized textures) and the gallery before it is used in content.
|
|
219
211
|
|
|
220
212
|
**Principles (style, flexible):**
|
|
221
|
-
- Mixed sources read as one game when they share one texture language (flat
|
|
222
|
-
roughness range) and one palette. When a source does not match, re-material it: keep its shape and swap its materials for the game's own
|
|
213
|
+
- Mixed sources read as one game when they share one texture language (whichever the game chose: flat, painted, pixel, photo, its own;
|
|
214
|
+
one texel density; one roughness range) and one palette. When a source does not match, re-material it: keep its shape and swap its materials for the game's own
|
|
223
215
|
(`recipes/46-blender-art-route.md` section 5) or tint it from the palette, rather than adding a second style.
|
|
224
216
|
- AI-generated meshes usually need cleanup: merge stray parts, set the origin at the base, reduce triangles, and replace baked-in lighting in
|
|
225
217
|
the texture so the game's lights decide the shading.
|
|
226
218
|
- Put a new asset next to the existing ones in `threedog gallery --shots` (and `--mode silhouette,value`) to see whether it stands apart.
|
|
227
219
|
|
|
228
220
|
## 2e. Plants on your own geometry and spots
|
|
229
|
-
|
|
230
|
-
mesh per species, wind, shadows, LOD and felling come with it; the geometry (and material) stay yours.
|
|
221
|
+
Plants need no model files and no random scatter: give `vegetation.define` a three.js geometry and the places. One instanced mesh per species, wind, shadows, LOD and felling come with it.
|
|
231
222
|
```js
|
|
232
|
-
import { THREE, vegetation } from 'threedog';
|
|
233
|
-
engine.use(vegetation({ area: { min: [-30, -30], max: [30, 30] } }));
|
|
234
|
-
const crown = new THREE.IcosahedronGeometry(1.2, 1).translate(0, 3, 0);
|
|
223
|
+
import { THREE, vegetation } from 'threedog'; // collision() must be installed for the collider below
|
|
224
|
+
engine.use(vegetation({ area: { min: [-30, -30], max: [30, 30] } })); // on any ground: setGround, a level, or the flat default
|
|
225
|
+
const crown = new THREE.IcosahedronGeometry(1.2, 1).translate(0, 3, 0); // geometry baked at its final shape; origin at the foot
|
|
235
226
|
engine.vegetation.define('tree', {
|
|
236
|
-
geometry: crown, material: new THREE.MeshStandardMaterial({ color: 0x3f7a3a, flatShading: true }),
|
|
237
|
-
positions: [[-8, 4], [6, -3, 1.3], [10, 9, 0.8, 1.2]],
|
|
238
|
-
wind: 0.2, castShadow: true, rule: { collider: 0.5 } });
|
|
239
|
-
const hit = engine.vegetation.instanceAt(engine.actorPosition(), { radius: 2, species: 'tree' });
|
|
227
|
+
geometry: crown, material: new THREE.MeshStandardMaterial({ color: 0x3f7a3a, flatShading: true }), // omitted: engine.vegetation.material
|
|
228
|
+
positions: [[-8, 4], [6, -3, 1.3], [10, 9, 0.8, 1.2]], // [x, z] | [x, z, scale] | [x, z, scale, yaw], planted at the ground height
|
|
229
|
+
wind: 0.2, castShadow: true, rule: { collider: 0.5 } }); // collider: a trunk radius players and NPCs cannot walk through
|
|
230
|
+
const hit = engine.vegetation.instanceAt(engine.actorPosition(), { radius: 2, species: 'tree' }); // the nearest one, or null
|
|
240
231
|
```
|
|
241
232
|
`define` with a model name returns a Promise; with a `geometry` it is immediate. Many small spots (grass) use `rule: { perChunk }` and `nearOnly: true` instead
|
|
242
233
|
of `positions`; recipe 10 section 4 has both, `densityMap` and felling (`removeInstance`).
|
|
243
234
|
|
|
235
|
+
## 2f. Every model through one setup (post-process, restyle); a node of a multi-part GLB
|
|
236
|
+
```js fragment
|
|
237
|
+
const mine = new Map(); // copies share materials: one of yours per original keeps batching
|
|
238
|
+
engine.assets.onModel(m => m.traverse(o => { if (o.isMesh) o.material = mine.get(o.material) ?? mine.set(o.material, myLook(o.material)).get(o.material); }));
|
|
239
|
+
engine.assets.manifest({ models: { wall: { url: '/models/kit.glb', node: 'Wall.001' } } }); // or Wall001; a second "Fence" is Fence_1
|
|
240
|
+
```
|
|
241
|
+
`onModel` runs once on each copy the engine hands out (props, templates, pickups, bodies, a level, `assets.model`) before it is drawn.
|
|
242
|
+
Synchronous, one per engine, set before `start()`; it leaves the root's transform to the placer (change a child). A `node` part sits at the origin, turned and sized as in the file, which loads once.
|
|
243
|
+
|
|
244
|
+
**Model contract**: a re-export that drops a part or clip fails in the check, not in play.
|
|
245
|
+
```js fragment
|
|
246
|
+
engine.assets.manifest({ models: { hero: { url: '/models/hero.glb', needs: { nodes: ['Hand_R'], clips: ['Idle', 'Run'] } } } });
|
|
247
|
+
```
|
|
248
|
+
`threedog assets check` errors per model with each missing node / clip and the closest name; the load warns the same line once (`[asset-needs]`), the model still shows.
|
|
249
|
+
Optional. The check reads the file the engine will load: the winning entry after all packs (the `optimized` pack included, it keeps `needs`), at `public/<its url, with the pack base>`, whatever folder is checked; a remote url is skipped, a missing file is the missing-file report. Node names compare as the loader spells them (`Hand.R` is `HandR`, a second `Fence` is `Fence_1`), clips as written; on a `{ url, node }` entry only inside that node. Unknown keys in `needs` are rejected.
|
|
250
|
+
|
|
244
251
|
## 3. Loading: what is it waiting for, what failed, does it block the start
|
|
245
|
-
Every asset load is a task in `engine.loading` (so are module init / `isReady`, the stream's nearby builds and the game's own steps)
|
|
246
|
-
phase (`queued` → `download` → `decode` → `upload` / `build` → `done` | `failed`), progress, the error (file, HTTP status, a texture or `.bin`
|
|
247
|
-
|
|
248
|
-
Decide per entry what a failure means:
|
|
252
|
+
Every asset load is a task in `engine.loading` (so are module init / `isReady`, the stream's nearby builds and the game's own steps), with a
|
|
253
|
+
phase (`queued` → `download` → `decode` → `upload` / `build` → `done` | `failed`), progress, the error (file, HTTP status, a missing texture or `.bin`)
|
|
254
|
+
and its source (manifest, path, file version, clip names). Decide per entry what a failure means:
|
|
249
255
|
```js fragment
|
|
250
256
|
engine.assets.manifest({
|
|
251
|
-
name: 'forest',
|
|
257
|
+
name: 'forest', // the source label in engine.loading (default 'manifest#1')
|
|
252
258
|
models: {
|
|
253
|
-
hero: { url: '/models/hero.glb', critical: true },
|
|
254
|
-
bush: '/models/bush.glb',
|
|
255
|
-
fern: { url: '/models/fern.glb', fallback: 'bush' },
|
|
259
|
+
hero: { url: '/models/hero.glb', critical: true }, // the game cannot start without it: start() stops and says why
|
|
260
|
+
bush: '/models/bush.glb', // degradable (default): a gray placeholder, the game continues
|
|
261
|
+
fern: { url: '/models/fern.glb', fallback: 'bush' }, // degradable, shows another entry instead
|
|
256
262
|
},
|
|
257
263
|
});
|
|
258
|
-
const level = await engine.loading.track('level-data', () => fetch('/levels/1.json').then(r => r.json()));
|
|
264
|
+
const level = await engine.loading.track('level-data', () => fetch('/levels/1.json').then(r => r.json())); // the game's own step, critical by default
|
|
259
265
|
```
|
|
260
266
|
- Finished is not succeeded: `describe().loading` has `done` (nothing pending) and `ok` (nothing failed, no missing references); `blocked` is true
|
|
261
267
|
when a critical item failed before the start. `waiting` names the current item, e.g. `decoding model "hero" (/models/hero.glb, manifest "forest")`.
|
|
@@ -273,8 +279,8 @@ export default { name: 'forest', base: '/packs/forest/', models: { oak: 'oak.glb
|
|
|
273
279
|
// an npm package lets vite find and emit each file: models: { oak: new URL('./oak.glb', import.meta.url).href }
|
|
274
280
|
// (keep such a package out of vite's dependency pre-bundling: optimizeDeps: { exclude: ['forest-assets'] })
|
|
275
281
|
import forest from 'forest-assets';
|
|
276
|
-
engine.assets.manifest(forest);
|
|
277
|
-
engine.assets.manifest({ name: 'mine', models: { oak: '/models/my-oak.glb' } });
|
|
282
|
+
engine.assets.manifest(forest); // content and code now say 'oak', 'creek'
|
|
283
|
+
engine.assets.manifest({ name: 'mine', models: { oak: '/models/my-oak.glb' } }); // a later pack replaces a name it shares
|
|
278
284
|
```
|
|
279
285
|
A generator function is also an entry (`models: { pine: () => geometry }`): an asset pack exports its procedural models this way.
|
|
280
286
|
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
# Scheduling events on the game clock
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
> **Covers:** timers on game time, the time table, smooth movement between steps, skipping time.
|
|
4
|
+
> **Use when:** something happens later, repeatedly, or at an hour of the day.
|
|
5
|
+
> **Shortest:** `engine.clock.after(seconds, fn)`.
|
|
6
|
+
> **Sections:** Changing how fast time · The time table the · 1 Where to write · 1b Smooth movement between · 2 Skipping time sleep · 3 Verify
|
|
4
7
|
|
|
5
8
|
## Changing how fast time runs: `engine.mod`
|
|
6
9
|
```js
|
|
7
|
-
engine.time.channel('enemies');
|
|
10
|
+
engine.time.channel('enemies'); // once: a channel of your own (world and player are built in)
|
|
8
11
|
const bt = engine.mod('time.enemies', { owner: 'bullet-time', mul: 0.35, for: 2 }); // bullet time: enemies at 35% for 2 real seconds
|
|
9
|
-
engine.mod('time.player', { owner: 'haste', mul: 1.2, for: 5 });
|
|
10
|
-
engine.mod('freeze', { owner: 'pause-menu' });
|
|
11
|
-
engine.onFixed(dt => moveEnemies(dt), { channel: 'enemies' });
|
|
12
|
+
engine.mod('time.player', { owner: 'haste', mul: 1.2, for: 5 }); // haste on the player
|
|
13
|
+
engine.mod('freeze', { owner: 'pause-menu' }); // pause menu (= engine.freeze('pause-menu'))
|
|
14
|
+
engine.onFixed(dt => moveEnemies(dt), { channel: 'enemies' }); // this dt is already scaled; plain onFixed dt stays 1/60
|
|
12
15
|
```
|
|
13
16
|
`engine.mod(target, { owner, mul | add | set | clamp, for, clock })` is the one entry for every quantity several systems share (time channels,
|
|
14
17
|
`'clock.rate'`, `'freeze'`, your own from `engine.stacks.define(name, { base })`). It returns `{ remove() }`; `remove()` ends only this owner's entry.
|
|
@@ -32,7 +35,7 @@ Details, only when you need them:
|
|
|
32
35
|
**One time source.** `engine.time` counts one thing, `engine.time.tick` (fixed steps run). Every other time is a
|
|
33
36
|
read-only view of it, moved only by the engine, and always together: a fixed step, `engine.skip` and a new playthrough move or reset all of them.
|
|
34
37
|
Read any view with `engine.time.now(name)`: `'real'`, `'ambient'`, `'calendar'` or a channel (`'world'`, `'player'`, your own).
|
|
35
|
-
`'ambient'` (= `engine.uniforms.uTime`: wind, water, clouds) is the one view that keeps moving while gameplay is frozen, unless the freeze is a full still (`{
|
|
38
|
+
`'ambient'` (= `engine.uniforms.uTime`: wind, water, clouds) is the one view that keeps moving while gameplay is frozen, unless the freeze is a full still (`{ still: true }`, which also stops skeletal animation and particles; `engine.still` says so, for your own frame code).
|
|
36
39
|
|
|
37
40
|
Three rulers, always named: **real seconds** (`engine.time.now('real')` = tick / 60; the `dt` of a plain `onFixed` / module `fixed` / `world.simulate`, the N of
|
|
38
41
|
`engine.step(N)`; never scaled), **channel seconds** (`engine.time.now(ch)`, the `dt` of
|
|
@@ -50,7 +53,7 @@ from calendar seconds: one day = `calendar.dayLength` calendar seconds. **Frame
|
|
|
50
53
|
| Crop / template stage growth, vegetation and pickup respawn, "ripe after 10 minutes" | calendar seconds (`clock.now`, `clock.after / every`; saved) | stops | twice as fast: growth that needs 600 calendar seconds is ripe after 300 real seconds |
|
|
51
54
|
| Calendar, day, season, clock hours, lamps and shop doors (`calendar.at / between / daily / onSeason`) | time of day (`engine.calendar`, derived from calendar seconds) | stops | twice as fast: with `dayLength = 360` one hour (15 calendar seconds) passes in 7.5 real seconds |
|
|
52
55
|
| UI animation and effects that follow the game (bobbing, sway) | `engine.time.now('real')` | stops | unchanged |
|
|
53
|
-
| Shader motion that should not stop behind a pause menu (wind, water) | `engine.time.now('ambient')` / `uniforms.uTime` | keeps running (unless `freeze(owner, {
|
|
56
|
+
| Shader motion that should not stop behind a pause menu (wind, water) | `engine.time.now('ambient')` / `uniforms.uTime` | keeps running (unless `freeze(owner, { still: true })`) | unchanged |
|
|
54
57
|
| Menu / HUD animation that must keep running while paused | frame seconds (`onFrame` `dt`) | keeps running | unchanged |
|
|
55
58
|
| Toast and loading fade-out, music volume fades | wall-clock time (they never affect gameplay) | keeps running | unchanged |
|
|
56
59
|
| `saves.autosave(minutes)` | real seconds of play (only while a playthrough runs: not on the title screen, not during newGame / load) | stops | unchanged |
|
|
@@ -64,7 +67,7 @@ seconds = 6.7 hours. The docs say "calendar seconds" and "N clock hours/minutes"
|
|
|
64
67
|
Tick, real and ambient seconds are not saved (a new game or a session load starts them at 0, like a fresh page); channels and the calendar are; to keep a cooldown across a save, use a `mod` with `for` (saved with its time left) or store it in a
|
|
65
68
|
world record. Don't use `setTimeout` / `setInterval` / `performance.now()` (they ignore pause, are not saved, and can't be tested with fast-forward).
|
|
66
69
|
The engine itself runs on the fixed step except the wall-clock items in the table.
|
|
67
|
-
"After how long / every how long" uses `engine.clock` (part of the core; one timer queue for every view: `{ channel: 'real' | '<channel>' }`, default calendar seconds
|
|
70
|
+
"After how long / every how long" uses `engine.clock` (part of the core; one timer queue for every view: `{ channel: 'real' | '<channel>' }`, default calendar seconds); "at what time every day / within a time window / when the season changes"
|
|
68
71
|
uses `engine.calendar` (the `calendar()` module with a `dayLength`; at a fixed time of day these never fire).
|
|
69
72
|
|
|
70
73
|
**The calendar is gameplay, the sky is a picture.** `calendar()` owns the time of day, the day, seasons, the timers below and their save; NPC schedules,
|
|
@@ -79,8 +82,7 @@ the sun, moon, colors and season tint. So each kind of game installs what it nee
|
|
|
79
82
|
A game's own calendar (turns, a lunar calendar) replaces the module by meeting `modules/calendar/contract.js` (recipe 55 "Replacing a module").
|
|
80
83
|
|
|
81
84
|
## 1. Where to write it
|
|
82
|
-
Game logic goes in `
|
|
83
|
-
call `after` in code.
|
|
85
|
+
Game logic goes in `main.js` or the game's own module.
|
|
84
86
|
|
|
85
87
|
```js
|
|
86
88
|
import { parseClock, formatClock } from 'threedog';
|
|
@@ -90,22 +92,21 @@ const lamp = new THREE.PointLight();
|
|
|
90
92
|
const lampHours = engine.calendar.between('18:00', '06:00', { on: () => lamp.visible = true, off: () => lamp.visible = false });
|
|
91
93
|
|
|
92
94
|
// An event when a clock time is crossed (an "action" once per day): open the market at 12:00
|
|
93
|
-
engine.calendar.at('12:00', day => engine.vars.bump('marketDays'), { days: [1, 3, 5] });
|
|
95
|
+
engine.calendar.at('12:00', day => engine.vars.bump('marketDays'), { days: [1, 3, 5] }); // only on days 1, 3, 5; a function also works: day => day % 7 === 6
|
|
94
96
|
|
|
95
97
|
// After how long: pass an event name to make it saveable (still fires after loading a save); a function cannot be saved
|
|
96
98
|
engine.clock.after(120, 'bread:ready', { data: { oven: 1 } });
|
|
97
99
|
engine.events.on('bread:ready', ({ oven }) => engine.vars.bump('bread'));
|
|
98
100
|
|
|
99
|
-
engine.clock.every(30, () => engine.vars.bump('birds'));
|
|
100
|
-
engine.calendar.daily(day => console.log('day', day));
|
|
101
|
-
engine.calendar.onSeason('winter', () => engine.weather?.set('snow', { seconds: 20 }));
|
|
101
|
+
engine.clock.every(30, () => engine.vars.bump('birds')); // every 30 calendar seconds (not 30 clock seconds)
|
|
102
|
+
engine.calendar.daily(day => console.log('day', day)); // every day at 00:00
|
|
103
|
+
engine.calendar.onSeason('winter', () => engine.weather?.set('snow', { seconds: 20 })); // needs seasons (presets.calendar.fourSeasons) and a 'snow' weather (presets.weather.temperate)
|
|
102
104
|
|
|
103
105
|
// Clock conversion: 'HH:MM' <-> fraction of a day 0-1
|
|
104
|
-
engine.calendar.timeOfDay = parseClock('17:30');
|
|
105
|
-
formatClock(engine.calendar.timeOfDay);
|
|
106
|
+
engine.calendar.timeOfDay = parseClock('17:30'); // jump straight to 17:30 (see the catch-up rules below)
|
|
107
|
+
formatClock(engine.calendar.timeOfDay); // '17:30' (engine.calendar.clock is the same text)
|
|
106
108
|
```
|
|
107
|
-
**Use between for states, at for actions.**
|
|
108
|
-
time every step, and no way of jumping the time can leave the state wrong.
|
|
109
|
+
**Use between for states, at for actions.** A lamp on, a shop open, an NPC home are states: `between` checks the time every step, so no time jump leaves them wrong.
|
|
109
110
|
`at` is an event for "crossing a clock time", with these catch-up rules:
|
|
110
111
|
- It fires only when time moves **forward** across the time: walking naturally, `step` fast-forward, or setting `calendar.timeOfDay` later (17:00 -> 19:00
|
|
111
112
|
on the same day). When several trigger points are crossed at once, `catchUp` decides: `'once'` fires once (default), `'all'` fires them all,
|
|
@@ -113,29 +114,28 @@ time every step, and no way of jumping the time can leave the state wrong.
|
|
|
113
114
|
- Turning time **back** does not fire; it only resets the baseline: `applyState({ time })` to an earlier time, or lowering `calendar.timeOfDay` (19:00 ->
|
|
114
115
|
05:50 is going back within the same day, not "a night passed").
|
|
115
116
|
- Loading a save does not fire; it only resets the baseline (trigger points between the save and the load are not made up).
|
|
116
|
-
So
|
|
117
|
-
`between` for states like a lamp.
|
|
117
|
+
So after "applyState back to 17:50" an `at`-driven lamp will not switch itself off: use `between`.
|
|
118
118
|
Length of a day: `openWorld({ camera: 'follow', dayLength: 600 })` / `calendar({ dayLength })` (calendar seconds; without it the time of day never moves,
|
|
119
119
|
`presets.calendar.cycle` is 360); `engine.mod('clock.rate', { owner: 'game', set: 10 })` speeds things up temporarily (`remove()` on its handle undoes it; see the table above).
|
|
120
|
-
For "
|
|
120
|
+
For "has this been done" in a story, use `engine.vars.bump / setFlag` (saved automatically).
|
|
121
121
|
|
|
122
122
|
## 1b. Smooth movement between fixed steps: `engine.stepBlend`
|
|
123
|
-
|
|
123
|
+
Most frames fall between two fixed steps, so something moved in `onFixed` and drawn at its latest position stutters, more on a fast screen. Keep where it was before the step and draw between: `engine.stepBlend` is how far this frame is from the last step to the next, 0 to 1:
|
|
124
124
|
```js fragment
|
|
125
125
|
const body = { x: 0, lastX: 0 };
|
|
126
|
-
engine.onFixed(dt => { body.lastX = body.x; body.x += speed * dt; });
|
|
127
|
-
engine.onFrame(() => { mesh.position.x = body.lastX + (body.x - body.lastX) * engine.stepBlend; });
|
|
126
|
+
engine.onFixed(dt => { body.lastX = body.x; body.x += speed * dt; }); // the rules read body.x
|
|
127
|
+
engine.onFrame(() => { mesh.position.x = body.lastX + (body.x - body.lastX) * engine.stepBlend; }); // the picture only
|
|
128
128
|
```
|
|
129
|
-
The picture runs at most one step behind
|
|
129
|
+
The picture runs at most one step behind; rules read the fixed-step value, never the drawn one. After a teleport set `lastX` to `x` too. While frozen `stepBlend` holds still. `engine.swarm` does this by itself (recipe 65).
|
|
130
130
|
|
|
131
131
|
## 2. Skipping time (sleep until morning, wait an hour)
|
|
132
132
|
`engine.skip` moves calendar seconds and the calendar clock forward without running every fixed step, so even a game with a real-length day can sleep through
|
|
133
133
|
the night instantly.
|
|
134
134
|
```js
|
|
135
|
-
await engine.skip({ to: '06:00' });
|
|
136
|
-
engine.skip({ seconds: 600 });
|
|
135
|
+
await engine.skip({ to: '06:00' }); // until the calendar clock next reads 06:00 (at 06:00 exactly: a full day; throws without a calendar dayLength)
|
|
136
|
+
engine.skip({ seconds: 600 }); // 600 calendar seconds
|
|
137
137
|
await engine.skip({ to: '06:00', fade: 0.6, save: 'auto' }); // fade out, jump, save, fade in (through flow.transition when flow is installed)
|
|
138
|
-
engine.events.on('time:skip', ({ seconds }) => engine.vars.bump('restSeconds', seconds));
|
|
138
|
+
engine.events.on('time:skip', ({ seconds }) => engine.vars.bump('restSeconds', seconds)); // after the jump
|
|
139
139
|
```
|
|
140
140
|
What catches up, and how:
|
|
141
141
|
- `clock.after / every`, `calendar.at / daily / between`, `day:start`, `season:change` fire **in time order, once per crossing, as if stepped** (a 3-day
|