threedog 0.8.0 → 1.0.1
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 +223 -4
- package/README.md +6 -6
- package/core/assets/Animator.js +2 -0
- package/core/assets/Assets.js +44 -13
- package/core/assets/assetEntry.js +87 -22
- package/core/assets/assetHot.js +2 -1
- package/core/assets/assetReport.js +1 -2
- package/core/audio/Audio.js +24 -5
- package/core/base/I18n.js +6 -3
- package/core/base/Random.js +3 -1
- package/core/base/Vars.js +14 -4
- package/core/base/errorCodes.js +54 -16
- package/core/base/errorHints.js +12 -1
- package/core/base/errors.js +6 -4
- package/core/base/events.generated.js +10 -0
- package/core/base/follows.js +26 -0
- package/core/base/math.js +15 -8
- package/core/base/params.js +2 -2
- package/core/{saves → base}/saveValues.js +24 -6
- package/core/base/sections.js +97 -0
- package/core/base/spelling.js +32 -0
- package/core/base/validate.js +8 -29
- package/core/engine/Engine.js +61 -18
- package/core/engine/Loading.js +30 -3
- package/core/engine/copies.js +1 -1
- package/core/engine/headlessLoad.js +30 -13
- package/core/engine/lifecycle.js +30 -25
- package/core/engine/loop.js +22 -4
- package/core/engine/moduleSlots.js +91 -15
- package/core/engine/moduleTypes.js +13 -0
- package/core/engine/modules.js +248 -62
- package/core/engine/page.js +25 -8
- package/core/engine/plugins.js +15 -3
- package/core/engine/services.js +3 -0
- package/core/engine/startup.js +46 -36
- package/core/input/Input.js +39 -19
- package/core/input/inputKeyboard.js +39 -0
- package/core/input/inputPad.js +23 -2
- package/core/input/inputPointer.js +3 -1
- package/core/input/inputSeat.js +66 -0
- package/core/input/inputTouch.js +23 -6
- package/core/inspect/DebugOverrides.js +13 -2
- package/core/inspect/Describe.js +10 -6
- package/core/inspect/Inspect.js +31 -4
- package/core/inspect/UrlState.js +14 -10
- package/core/inspect/catalog.js +12 -5
- package/core/inspect/describeRender.js +3 -2
- package/core/inspect/describeText.js +6 -2
- package/core/inspect/metadata.generated.js +4140 -0
- package/core/inspect/pictureWriters.js +117 -33
- package/core/inspect/toolDoor.js +21 -0
- package/core/inspect/valueHistory.js +35 -0
- package/core/ops/Ops.js +32 -7
- package/core/ops/control.js +48 -23
- package/core/ops/holds.js +4 -3
- package/core/ops/opsAtomic.js +18 -6
- package/core/ops/opsCheck.js +7 -5
- package/core/ops/opsFail.js +5 -7
- package/core/ops/opsRun.js +2 -2
- package/core/ops/owned.js +20 -3
- package/core/ops/sharedPoint.js +7 -10
- package/core/ops/stacks.js +22 -1
- package/core/saves/SaveStore.js +52 -26
- package/core/saves/Saves.js +122 -27
- package/core/saves/saveApply.js +159 -61
- package/core/saves/saveFiles.js +30 -25
- package/core/saves/saveVersions.js +20 -6
- package/core/saves/session.js +76 -33
- package/core/saves/stateReplace.js +184 -0
- package/core/scene/Rays.js +21 -5
- package/core/scene/Views.js +6 -6
- package/core/scene/adaptive.js +13 -10
- package/core/scene/canvasBox.js +2 -0
- package/core/scene/compositeGround.js +72 -0
- package/core/scene/floor.js +17 -0
- package/core/scene/grid.js +2 -0
- package/core/scene/ground.contract.js +14 -0
- package/core/scene/ground.js +52 -17
- package/core/scene/pixel.js +154 -0
- package/core/scene/pixelRatio.js +167 -0
- package/core/scene/sceneDelta.js +3 -3
- package/core/scene/sceneMethods.js +11 -6
- package/core/scene/stepPoses.js +6 -1
- package/core/scene/thingExplain.js +1 -1
- package/core/scene/thingOps.js +22 -14
- package/core/scene/things.js +1 -1
- package/core/scene/tier.js +10 -0
- package/core/scene/view.js +126 -9
- package/core/stream/Batching.js +0 -1
- package/core/stream/Stream.js +24 -12
- package/core/stream/batchGroups.js +1 -0
- package/core/stream/scatter.js +5 -2
- package/core/stream/streamSources.js +2 -1
- package/core/threads/Commits.js +12 -7
- package/core/threads/Jobs.js +15 -5
- package/core/threads/Threads.js +5 -2
- package/core/time/Clock.js +3 -1
- package/core/time/skip.js +10 -4
- package/core/time/time.js +16 -10
- package/docs/AI.md +89 -72
- package/docs/API.md +18 -14
- package/docs/CODEMAP.md +68 -40
- package/docs/COMMANDS.md +22 -23
- package/docs/CONVENTIONS.md +120 -17
- package/docs/MIGRATING-0.8.md +2 -0
- package/docs/MIGRATING-1.0.md +101 -0
- package/docs/THREE.md +65 -12
- package/docs/api/cameraRig.md +3 -0
- package/docs/api/characters.md +13 -7
- package/docs/api/collider3d.md +9 -0
- package/docs/api/content.md +16 -15
- package/docs/api/dialogue.md +2 -1
- package/docs/api/engine.md +18 -16
- package/docs/api/events.md +14 -4
- package/docs/api/ground.md +2 -2
- package/docs/api/i18n.md +1 -1
- package/docs/api/input.md +2 -1
- package/docs/api/interactions.md +1 -1
- package/docs/api/inventory.md +1 -1
- package/docs/api/level.md +3 -2
- package/docs/api/nav.md +4 -2
- package/docs/api/particles.md +8 -5
- package/docs/api/pickups.md +1 -1
- package/docs/api/post.md +3 -4
- package/docs/api/quests.md +4 -2
- package/docs/api/rays.md +2 -0
- package/docs/api/rigid.md +3 -2
- package/docs/api/saves.md +8 -7
- package/docs/api/stream.md +4 -5
- package/docs/api/terrain.md +3 -4
- package/docs/api/terrainDraw.md +1 -1
- package/docs/api/timeline.md +2 -2
- package/docs/api/tools.md +3 -1
- package/docs/api/triggers.md +2 -0
- package/docs/api/vegetationDraw.md +1 -1
- package/docs/api/water.md +6 -2
- package/docs/api/weather.md +19 -4
- package/docs/api/weatherDraw.md +1 -1
- package/docs/api/world.md +1 -1
- package/docs/recipes/01-new-game.md +3 -3
- package/docs/recipes/02-npc.md +3 -4
- package/docs/recipes/03-items-pickups.md +11 -11
- package/docs/recipes/04-quests.md +2 -0
- package/docs/recipes/05-props-bake.md +9 -9
- package/docs/recipes/06-clock-events.md +6 -6
- package/docs/recipes/07-flow-scenes-pause.md +18 -15
- package/docs/recipes/08-weather-sky.md +5 -5
- package/docs/recipes/09-materials-lights-models.md +3 -3
- package/docs/recipes/10-blender-level.md +16 -4
- package/docs/recipes/11-vehicles.md +18 -6
- package/docs/recipes/12-navmesh.md +52 -8
- package/docs/recipes/13-animation.md +34 -8
- package/docs/recipes/14-custom-module.md +20 -8
- package/docs/recipes/15-perf.md +4 -4
- package/docs/recipes/16-dev-bridge.md +9 -8
- package/docs/recipes/18-world.md +13 -5
- package/docs/recipes/19-shooting-picking.md +3 -2
- package/docs/recipes/20-content-actions-save.md +26 -6
- package/docs/recipes/21-camera.md +17 -23
- package/docs/recipes/22-shop-gold.md +21 -12
- package/docs/recipes/23-ops.md +19 -15
- package/docs/recipes/26-ui-parts.md +3 -2
- package/docs/recipes/27-net.md +3 -3
- package/docs/recipes/28-terrain.md +3 -3
- package/docs/recipes/29-grid.md +1 -1
- package/docs/recipes/30-templates.md +10 -13
- package/docs/recipes/31-audio.md +2 -2
- package/docs/recipes/32-action-game.md +6 -5
- package/docs/recipes/33-stream-sources.md +4 -1
- package/docs/recipes/34-environment-lighting.md +7 -8
- package/docs/recipes/35-picture-from-reference.md +13 -9
- package/docs/recipes/36-ground-plants.md +3 -2
- package/docs/recipes/40-scene.md +11 -10
- package/docs/recipes/43-shader-patches-surfaces.md +7 -7
- package/docs/recipes/44-water-weather-hooks.md +9 -8
- package/docs/recipes/45-cascaded-shadows.md +3 -4
- package/docs/recipes/46-blender-art-route.md +3 -3
- package/docs/recipes/49-game-module-contract.md +2 -1
- package/docs/recipes/50-own-renderer.md +1 -0
- package/docs/recipes/51-capability-catalog.md +14 -8
- package/docs/recipes/52-around-the-picture.md +4 -4
- package/docs/recipes/55-mods-time-wrap.md +5 -4
- package/docs/recipes/56-webgpu-tsl.md +12 -1
- package/docs/recipes/57-control.md +30 -10
- package/docs/recipes/58-input.md +13 -0
- package/docs/recipes/60-judge-the-picture.md +1 -1
- package/docs/recipes/62-picture-code.md +106 -48
- package/docs/recipes/63-third-person-start.md +2 -1
- package/docs/recipes/64-particles.md +53 -4
- package/docs/recipes/65-swarm.md +2 -2
- package/docs/recipes/66-common-tasks.md +313 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +3 -3
- package/examples/perf-island/.threedog/content-index.json +1 -1
- package/examples/perf-island/GAMEMAP.md +3 -3
- package/examples/perf-island/main.js +2 -2
- package/examples/plain-picture/GAMEMAP.md +3 -1
- package/examples/rc2d/GAMEMAP.md +1 -1
- package/examples/rc2d/rc2d.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +3 -3
- package/examples/webgpu-tsl/GAMEMAP.md +1 -1
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +5 -4
- package/examples/world/main.js +3 -3
- package/index.d.ts +8 -5
- package/index.js +22 -1
- package/llms.txt +2 -1
- package/modules/ambience/Ambience.js +5 -3
- package/modules/calendar/index.js +7 -5
- package/modules/camera/FirstPersonCamera.js +3 -3
- package/modules/camera/FixedCamera.js +34 -20
- package/modules/camera/FollowCamera.js +20 -11
- package/modules/camera/RtsCamera.js +1 -0
- package/modules/camera/common.js +33 -22
- package/modules/camera/pixelSnap.js +62 -0
- package/modules/characters/Character.js +136 -43
- package/modules/characters/NPC.js +60 -28
- package/modules/characters/assetModel.js +2 -2
- package/modules/characters/astar.js +47 -28
- package/modules/characters/character.contract.js +21 -0
- package/modules/characters/contract.js +17 -3
- package/modules/characters/index.js +94 -34
- package/modules/characters/moveHelpers.js +80 -15
- package/modules/characters/mover.contract.js +14 -0
- package/modules/characters/movers/common.js +6 -4
- package/modules/characters/movers/rapier.js +12 -5
- package/modules/characters/movers/simple.js +25 -12
- package/modules/characters/movers/support.js +18 -7
- package/modules/characters/npcAvoid.js +15 -12
- package/modules/characters/npcSim.js +75 -25
- package/modules/characters/npcView.js +13 -6
- package/modules/characters/pathAsync.js +74 -24
- package/modules/characters/pathJob.js +38 -21
- package/modules/characters/player.js +59 -47
- package/modules/characters/seat.js +56 -0
- package/modules/characters/vehicle.contract.js +8 -5
- package/modules/characters/walkTo.js +31 -18
- package/modules/collision/Collision.js +44 -26
- package/modules/collision/contract.js +2 -2
- package/modules/collision/grid.js +6 -1
- package/modules/content/explain.js +1 -1
- package/modules/content/fields.js +3 -3
- package/modules/content/ids.js +3 -1
- package/modules/content/index.js +83 -27
- package/modules/content/loader.js +110 -130
- package/modules/content/markers.js +1 -1
- package/modules/content/models.js +48 -14
- package/modules/content/packs.js +2 -1
- package/modules/content/places.js +5 -4
- package/modules/content/props.js +8 -6
- package/modules/content/rules.js +29 -47
- package/modules/content/templates.js +66 -35
- package/modules/content/words.js +19 -6
- package/modules/debug/DebugPanel.js +4 -2
- package/modules/flow/contract.js +1 -0
- package/modules/flow/index.js +24 -14
- package/modules/gameplay/Container.js +5 -2
- package/modules/gameplay/Containers.js +9 -1
- package/modules/gameplay/Dialogue.js +82 -25
- package/modules/gameplay/Interactions.js +61 -32
- package/modules/gameplay/Inventory.js +56 -13
- package/modules/gameplay/Quests.js +133 -24
- package/modules/gameplay/boxOps.js +7 -0
- package/modules/gameplay/dialogueBubbles.js +14 -9
- package/modules/gameplay/inventoryOps.js +11 -7
- package/modules/gameplay/pickups.js +43 -16
- package/modules/gameplay/questLog.js +4 -2
- package/modules/gameplay/questSave.js +6 -1
- package/modules/gameplay/quests.contract.js +1 -1
- package/modules/grid/Grid.js +1 -1
- package/modules/grid/Layer.js +8 -4
- package/modules/grid/index.js +21 -15
- package/modules/grid/ops.js +43 -46
- package/modules/grid/tiles.js +1 -1
- package/modules/hlod/index.js +6 -3
- package/modules/hud/index.js +6 -4
- package/modules/hud/parts.js +4 -4
- package/modules/level/contract.js +2 -2
- package/modules/level/heightfield.js +17 -21
- package/modules/level/index.js +83 -26
- package/modules/level/load.js +165 -48
- package/modules/level/nodes.js +34 -16
- package/modules/lights/index.js +6 -3
- package/modules/lights/sources.js +3 -1
- package/modules/music/Music.js +4 -2
- package/modules/nav/contract.js +7 -5
- package/modules/nav/index.js +174 -44
- package/modules/nav/navPath.js +45 -10
- package/modules/net/index.js +1 -1
- package/modules/particles/Particles.js +85 -22
- package/modules/particles/effect.js +80 -28
- package/modules/particles/shaders.js +17 -0
- package/modules/photo/Photo.js +12 -10
- package/modules/rigid/RigidBodies.js +200 -57
- package/modules/rigid/Vehicles.js +15 -5
- package/modules/rigid/collider3d.contract.js +26 -0
- package/modules/rigid/ragdoll.js +55 -44
- package/modules/rigid/ragdollBones.js +83 -33
- package/modules/rigid/refresh.js +10 -0
- package/modules/rigid/sync.js +46 -15
- package/modules/settings/Settings.js +84 -37
- package/modules/settings/apply.js +15 -8
- package/modules/settings/sections.js +7 -4
- package/modules/settings/strings.js +2 -2
- package/modules/sky/skyModule.js +3 -1
- package/modules/swarm/Swarm.js +16 -6
- package/modules/terrain/ChunkManager.js +10 -16
- package/modules/terrain/index.js +17 -11
- package/modules/terrain/terrainEdit.js +13 -2
- package/modules/terrain/terrainGen.js +5 -3
- package/modules/terrain/terrainShape.js +1 -1
- package/modules/timeline/Timeline.js +58 -26
- package/modules/timeline/Tween.js +19 -13
- package/modules/timeline/shots.js +19 -10
- package/modules/triggers/index.js +87 -20
- package/modules/vegetation/Vegetation.js +4 -3
- package/modules/vegetation/draw.js +16 -0
- package/modules/vegetation/groundChunks.js +10 -7
- package/modules/vegetation/index.js +30 -7
- package/modules/water/Water.js +6 -2
- package/modules/weather/Weather.js +16 -15
- package/modules/weather/weatherDraw.js +7 -6
- package/modules/world/World.js +20 -7
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +13 -6
- package/modules/world/persist.js +23 -8
- package/modules/world/pos.js +4 -4
- package/modules/world/records.js +13 -7
- package/modules/world/sim.js +74 -23
- package/modules/world/simFar.js +2 -2
- package/modules/world/state.js +31 -6
- package/modules/world/thingSource.js +16 -3
- package/modules/world/views.js +19 -8
- package/package.json +7 -1
- package/render/PostFX.js +47 -29
- package/render/backend.js +5 -1
- package/render/fx/particles.tsl.js +8 -6
- package/render/fx/postWebGPU.tsl.js +3 -3
- package/render/layers.js +1 -1
- package/render/lightmap.js +23 -3
- package/render/occlusion.js +43 -12
- package/render/patches.js +2 -2
- package/render/postWebGL.js +4 -3
- package/render/probes.js +25 -0
- package/render/shadows.js +2 -2
- package/types/core.d.ts +142 -55
- package/types/gameplay.d.ts +92 -40
- package/types/generated/core/base/I18n.d.ts +2 -2
- package/types/generated/core/input/Input.d.ts +16 -2
- package/types/generated/core/input/inputSeat.d.ts +26 -0
- package/types/generated/core/inspect/DebugOverrides.d.ts +15 -1
- package/types/generated/core/ops/Ops.d.ts +2 -1
- package/types/generated/core/ops/control.d.ts +12 -2
- package/types/generated/core/saves/Saves.d.ts +26 -6
- package/types/generated/core/saves/session.d.ts +1 -1
- package/types/generated/core/scene/Views.d.ts +1 -1
- package/types/generated/core/stream/Stream.d.ts +6 -4
- package/types/generated/modules/grid/Grid.d.ts +1 -0
- package/types/generated/modules/particles/Particles.d.ts +4 -3
- package/types/generated/modules/timeline/Timeline.d.ts +5 -4
- package/types/generated/modules/weather/Weather.d.ts +1 -7
- package/types/generated/modules/world/World.d.ts +6 -4
- package/types/generated/render/PostFX.d.ts +6 -14
- package/types/nav.d.ts +36 -4
- package/types/physics.d.ts +55 -7
- package/types/pixel.d.ts +75 -0
- package/types/world.d.ts +14 -8
- package/ui/Parts.js +9 -2
- package/ui/theme.js +2 -2
- package/core/scene/engineCamera.js +0 -32
- package/modules/camera/projection.js +0 -21
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Particles: dust, smoke, sparks, splashes
|
|
2
2
|
|
|
3
|
-
```js
|
|
3
|
+
```js fragment
|
|
4
4
|
import { particles } from 'threedog';
|
|
5
5
|
engine.use(particles({
|
|
6
6
|
default: { color: 0xc8b89a }, // what every effect starts from
|
|
@@ -18,18 +18,67 @@ With no options an effect is a soft gray dot.
|
|
|
18
18
|
Lowest to highest: the neutral fallback, `particles({ default })`, `particles({ effects: { name } })`, `define(name, params)`, then `overrides` of one
|
|
19
19
|
`emit` or `attach`. So the game's picture can sit in one table and a line of play code writes only what it decides: `define('leaves', { max: 200 })`.
|
|
20
20
|
|
|
21
|
+
## Values over life
|
|
22
|
+
`size`, `color` and `opacity` take one value, `[birth, death]`, or more stops: evenly spaced, or timed from 0 (birth) to 1 (death).
|
|
23
|
+
```js
|
|
24
|
+
engine.particles.define('flash', { size: [0.2, 1.5, 0.4] }); // evenly spaced
|
|
25
|
+
engine.particles.define('puff', { opacity: [[0, 0], [0.1, 0.7], [1, 0]] }); // fades in, then out
|
|
26
|
+
engine.particles.define('ember', { color: [[0, 0xffffff], [0.3, 0xffaa33], [1, 0x331100]] });
|
|
27
|
+
```
|
|
28
|
+
Before the first time and after the last, the end stop holds. A stop list in `overrides` belongs to that batch.
|
|
29
|
+
|
|
30
|
+
## Fast emitters
|
|
31
|
+
`rate` is per second, so a fast emitter leaves beads. `ratePerMeter` is per meter it moves, on top of `rate`, with the particles spread along the path of that step.
|
|
32
|
+
```js fragment
|
|
33
|
+
engine.particles.define('trail', { rate: 0, ratePerMeter: 6, lifetime: [0.4, 0.6], max: 200 });
|
|
34
|
+
const trail = engine.particles.attach('trail', rocket);
|
|
35
|
+
trail.ratePerMeter = 12; // live; attach(name, object, { ratePerMeter }) sets it too
|
|
36
|
+
```
|
|
37
|
+
Set `max` to what the trail needs: a step that earns more keeps the newest. A teleport counts as moving: set `active = false` for a frame around it. While frozen nothing is born.
|
|
38
|
+
|
|
39
|
+
## Soft edges
|
|
40
|
+
`soft` is the distance in meters over which a particle fades where it meets what writes depth, so smoke on the ground has no hard line. It is off by default, set at `define`, and live
|
|
41
|
+
through `fx.uniforms.uSoft.value`.
|
|
42
|
+
```js
|
|
43
|
+
engine.particles.define('smoke', { gravity: 0.4, size: [0.5, 2], soft: 0.5 });
|
|
44
|
+
```
|
|
45
|
+
What it costs, only while a soft effect is on screen. On WebGPU, one copy of the depth buffer per render, shared by every soft effect. On WebGLRenderer a shader
|
|
46
|
+
cannot read the depth it draws into, so the scene is drawn once more, depth only, per render, shared the same way: that is real cost in a large scene, and it sees surfaces without their
|
|
47
|
+
wind, displacement or alphaTest. On WebGPURenderer's WebGL2 backend (the fallback where WebGPU is missing) three's depth copy works only with post and antialias on; elsewhere there the
|
|
48
|
+
particles draw hard and the console says so. `soft` applies to the engine's material, not to one of yours.
|
|
49
|
+
|
|
21
50
|
## The material
|
|
22
51
|
```js
|
|
23
52
|
const sparks = engine.particles.define('sparks', { blending: 'additive' });
|
|
24
|
-
sparks.material = new THREE.PointsMaterial({ size: 0.2, color: 0xffaa33 }); // drawn as given
|
|
53
|
+
sparks.material = new THREE.PointsMaterial({ size: 0.2, color: 0xffaa33 }); // WebGLRenderer: drawn as given
|
|
25
54
|
sparks.material = null; // the engine's back
|
|
26
55
|
sparks.uniforms.uMaxPx.value = 64; // live
|
|
27
56
|
```
|
|
28
57
|
`.material` is the effect's plain three.js material, `.points` what draws it. Particle age reaches the picture through the geometry attributes `aSize`,
|
|
29
58
|
`aAlpha`, `aColor`, `aAngle`: a material that ignores them shows every particle alike, and one that wants the fade reads them, as
|
|
30
|
-
`modules/particles/shaders.js` does.
|
|
59
|
+
`modules/particles/shaders.js` does. `aLife` is the life fraction, 0 at birth and 1 at death, for a flipbook, a gradient or a dissolve of your own. Empty slots stay in the
|
|
60
|
+
buffer with `aAlpha` 0, so give them size 0 as the engine's shader does.
|
|
61
|
+
```js fragment
|
|
62
|
+
// GLSL (WebGLRenderer), in the vertex shader: attribute float aLife; attribute float aAlpha;
|
|
63
|
+
// TSL (WebGPURenderer, a new game's route): import { PointsNodeMaterial } from 'three/webgpu'; import { attribute, color, mix, vec4 } from 'three/tsl';
|
|
64
|
+
const m = new PointsNodeMaterial({ transparent: true, depthWrite: false, sizeAttenuation: false });
|
|
65
|
+
m.colorNode = vec4(mix(color(0x00ff00), color(0xff0000), attribute('aLife', 'float')), attribute('aAlpha', 'float'));
|
|
66
|
+
sparks.material = m; // placed and sized by the engine's nodes, unless m sets positionNode / sizeNode (the particle's place is attribute('aPos', 'vec3'))
|
|
67
|
+
```
|
|
68
|
+
A flipbook is the same material with a texture. Each route has its own y: `uv()` runs up, `gl_PointCoord` runs down.
|
|
69
|
+
```js fragment
|
|
70
|
+
import { attribute, float, floor, mod, texture, uv, vec2, vec4 } from 'three/tsl';
|
|
71
|
+
// a 4 x 4 sheet, first frame at the top left
|
|
72
|
+
const f = floor(attribute('aLife', 'float').mul(16)), col = mod(f, 4), row = floor(f.div(4));
|
|
73
|
+
const cell = texture(sheet, vec2(uv().x.add(col).div(4), uv().y.add(float(3).sub(row)).div(4)));
|
|
74
|
+
m.colorNode = vec4(cell.rgb, cell.a.mul(attribute('aAlpha', 'float')));
|
|
75
|
+
// GLSL, in a ShaderMaterial that writes gl_PointSize from aSize, uScale and uMaxPx as shaders.js does (vLife: aLife passed on as a varying):
|
|
76
|
+
// float f = floor(vLife * 16.0); vec2 cell = vec2(mod(f, 4.0), floor(f / 4.0));
|
|
77
|
+
// vec4 c = texture2D(uSheet, vec2((gl_PointCoord.x + cell.x) / 4.0, 1.0 - (gl_PointCoord.y + cell.y) / 4.0));
|
|
78
|
+
```
|
|
79
|
+
`.uniforms` (`uMap`, `uHasMap`, `uScale`, `uMaxPx`) are written whichever material is drawn; a `ShaderMaterial` of yours can
|
|
31
80
|
share them, `uScale` being the pixels per meter at distance 1. Your material is yours: the engine never disposes it, and defining the effect again goes back to
|
|
32
|
-
the engine's. On WebGPURenderer the effect is a sprite
|
|
81
|
+
the engine's. On WebGPURenderer the effect is a sprite quad drawn once per particle, so a material of yours is a node material there (recipe 56), and any other is refused.
|
|
33
82
|
|
|
34
83
|
## Weather
|
|
35
84
|
Rain and snow are separate, because they follow the camera and fade with the weather: `engine.weather.particles` (recipe 44).
|
package/docs/recipes/65-swarm.md
CHANGED
|
@@ -110,6 +110,7 @@ crops.onStep((d, i, dt) => {
|
|
|
110
110
|
- Fields named `yaw`, `pitch`, `roll` (radians, three's order `'YXZ'`) and `scale` are drawn when you list them. Without them only the position is written, which is cheapest.
|
|
111
111
|
- `color: true` adds columns `r`, `g`, `b` (linear) and the spawn key `color: 0xff8800`. Your material's colour multiplies it.
|
|
112
112
|
- `swarm.mesh` is plain three.js: set `castShadow`, `layers`, `renderOrder` on it. The instance index is the row, and `mesh.count` follows the live count.
|
|
113
|
+
- A transparent swarm draws in row order: three sorts objects, not the instances inside one, so overlapping see-through objects can blend in the wrong order.
|
|
113
114
|
- Bounds are kept up to date while matrices are written, so culling is right for the whole swarm; it is one object to the camera, so it is drawn whole or not at all.
|
|
114
115
|
- Leave out `geometry` and `material` for a swarm that only holds data, and draw it your own way from `swarm.data`.
|
|
115
116
|
|
|
@@ -133,8 +134,7 @@ Build it with three's TSL as in three's own compute examples (an `instancedArray
|
|
|
133
134
|
import 'threedog/tsl'; // before createEngine
|
|
134
135
|
const gpu = /** @type {any} */ (engine.renderer); // a WebGPURenderer: the engine's type also covers WebGL
|
|
135
136
|
await gpu.computeAsync(seed); // once, to fill the buffer
|
|
136
|
-
engine.onFrame(d => {
|
|
137
|
+
engine.onFrame(d => { uDt.value = engine.frozen ? 0 : d; }); // time as a uniform set here, so a freeze stops the snow
|
|
137
138
|
engine.onRender(() => { gpu.compute(fall); }); // the shader here, so it runs once per drawn frame
|
|
138
139
|
snow.frustumCulled = false; // the sprite's own bounds know nothing of the flakes
|
|
139
140
|
```
|
|
140
|
-
A full page: `tests/compute-snow` in the engine repository.
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
# Common tasks, complete
|
|
2
|
+
|
|
3
|
+
**In this recipe**: whole examples first, then "In an existing game", the lines to add to a game that runs.
|
|
4
|
+
|
|
5
|
+
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
|
+
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>`.
|
|
7
|
+
|
|
8
|
+
## Pickup: something to take that goes in a bag
|
|
9
|
+
```js
|
|
10
|
+
import { createEngine, presets, world, collision, characters, inventory, pickups, interactions } from 'threedog';
|
|
11
|
+
|
|
12
|
+
const engine = createEngine({ canvas: document.getElementById('view'), bindings: { ...presets.bindings.walk, ...presets.bindings.interact } }); // interact is E
|
|
13
|
+
engine.use(world(), collision(), characters(), inventory(), pickups(), interactions({ ...presets.interactions.nearest }));
|
|
14
|
+
engine.characters.createPlayer({ ...presets.player.thirdPerson, spawn: [0, 0, 0] });
|
|
15
|
+
engine.inventory.define('gem', { name: 'Gem' });
|
|
16
|
+
engine.pickups.spawn([1, 0, 0], { give: 'gem', id: 'gem-1' });
|
|
17
|
+
Object.assign(window, { engine });
|
|
18
|
+
await engine.start();
|
|
19
|
+
```
|
|
20
|
+
```js
|
|
21
|
+
step(0.2);
|
|
22
|
+
engine.input.simulate('interact', true); step(0.1); engine.input.simulate('interact', false); step(0.1);
|
|
23
|
+
expect(engine.inventory.count('gem'), 'E takes it').toBe(1);
|
|
24
|
+
const left = engine.pickups.spawn([3, 0, 0], { give: 'gem', id: 'gem-2' });
|
|
25
|
+
left.remove(); // cleanup: data and model go together
|
|
26
|
+
assert(!engine.world.get('gem-2'), 'a removed pickup is gone');
|
|
27
|
+
```
|
|
28
|
+
**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".
|
|
29
|
+
|
|
30
|
+
## Custom picture piece: your own three.js in the scene
|
|
31
|
+
```js
|
|
32
|
+
import { createEngine, THREE } from 'threedog';
|
|
33
|
+
|
|
34
|
+
const lantern = () => ({ name: 'lantern', type: 'picture', install(e, ctx) {
|
|
35
|
+
const glow = new THREE.PointLight(0xffcc88, 2, 12);
|
|
36
|
+
glow.name = 'lantern-glow';
|
|
37
|
+
e.scene.add(glow);
|
|
38
|
+
ctx.track({ remove() { e.scene.remove(glow); glow.dispose(); } }); // leaves with the piece
|
|
39
|
+
ctx.track(e.onRender(() => { glow.intensity = 2 + Math.sin(e.time.tick / 20) * 0.2; }));
|
|
40
|
+
} });
|
|
41
|
+
|
|
42
|
+
const engine = createEngine({ canvas: document.getElementById('view') });
|
|
43
|
+
engine.use(lantern());
|
|
44
|
+
Object.assign(window, { engine });
|
|
45
|
+
await engine.start();
|
|
46
|
+
```
|
|
47
|
+
```js
|
|
48
|
+
step(0.1);
|
|
49
|
+
assert(engine.scene.getObjectByName('lantern-glow'), 'the piece is in the scene');
|
|
50
|
+
await engine.unuse('lantern'); // cleanup: what it tracked leaves with it
|
|
51
|
+
assert(!engine.scene.getObjectByName('lantern-glow'), 'the piece took its light away');
|
|
52
|
+
```
|
|
53
|
+
**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.
|
|
54
|
+
|
|
55
|
+
## Saved game value: a number that survives a reload
|
|
56
|
+
```js
|
|
57
|
+
import { createEngine } from 'threedog';
|
|
58
|
+
|
|
59
|
+
const engine = createEngine({ canvas: document.getElementById('view') });
|
|
60
|
+
const best = { score: 0 };
|
|
61
|
+
engine.saves.register('best', { version: 1, save: () => ({ ...best }), load: d => { best.score = d.score; } });
|
|
62
|
+
engine.onFixed(() => { best.score += 1; });
|
|
63
|
+
Object.assign(window, { engine, best });
|
|
64
|
+
await engine.start();
|
|
65
|
+
```
|
|
66
|
+
```js
|
|
67
|
+
step(0.1);
|
|
68
|
+
await engine.saves.save('check');
|
|
69
|
+
const kept = best.score;
|
|
70
|
+
step(0.5);
|
|
71
|
+
assert(best.score > kept, 'the value moved on');
|
|
72
|
+
await engine.saves.load('check');
|
|
73
|
+
expect(best.score, 'the save brought it back').toBe(kept);
|
|
74
|
+
await engine.saves.remove('check'); // cleanup: the test slot; the part itself lasts as long as the game
|
|
75
|
+
```
|
|
76
|
+
**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
|
+
|
|
78
|
+
## Input action: your own key
|
|
79
|
+
```js
|
|
80
|
+
import { createEngine } from 'threedog';
|
|
81
|
+
|
|
82
|
+
const engine = createEngine({ canvas: document.getElementById('view'), bindings: { dash: ['KeyQ', 'PadX'] } }); // the game binds keys, the player can rebind them
|
|
83
|
+
const dashes = { n: 0 };
|
|
84
|
+
const action = engine.input.action('dash', { label: 'Dash' });
|
|
85
|
+
const reader = engine.onFixed(() => { if (engine.input.pressed('dash')) dashes.n++; }); // gameplay reads in the fixed step
|
|
86
|
+
Object.assign(window, { engine, dashes, leave: () => { reader.remove(); action.remove(); } });
|
|
87
|
+
await engine.start();
|
|
88
|
+
```
|
|
89
|
+
```js
|
|
90
|
+
engine.input.simulate('dash', true); step(0.1); engine.input.simulate('dash', false); step(0.1);
|
|
91
|
+
expect(dashes.n, 'one press, one dash').toBe(1);
|
|
92
|
+
expect(engine.input.isUnbound('dash'), 'it has a key').toBe(false);
|
|
93
|
+
leave(); // cleanup: the reader and the action go; in a module, ctx.input takes them with it
|
|
94
|
+
```
|
|
95
|
+
**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
|
+
|
|
97
|
+
## Rain effect: weather with its particles
|
|
98
|
+
```js
|
|
99
|
+
import { createEngine, calendar, sky, weather } from 'threedog';
|
|
100
|
+
|
|
101
|
+
const engine = createEngine({ canvas: document.getElementById('view') });
|
|
102
|
+
// the table is the game's: without one only a calm 'clear' exists (presets.weather.temperate has seven types)
|
|
103
|
+
engine.use(calendar(), sky(), weather({ types: { clear: {}, rain: { rain: 1, cloud: 0.8 } }, rain: { count: 500 } }));
|
|
104
|
+
Object.assign(window, { engine });
|
|
105
|
+
await engine.start();
|
|
106
|
+
engine.weather.set('rain', { seconds: 0 });
|
|
107
|
+
```
|
|
108
|
+
```js
|
|
109
|
+
step(0.2);
|
|
110
|
+
expect(engine.describe().weather.name, 'it rains').toBe('rain');
|
|
111
|
+
assert(engine.describe().weather.rain > 0, 'the rain is falling');
|
|
112
|
+
engine.weather.set('clear', { seconds: 0 }); // cleanup: the module stays, the rain stops
|
|
113
|
+
step(0.2);
|
|
114
|
+
expect(engine.describe().weather.name, 'it stopped').toBe('clear');
|
|
115
|
+
```
|
|
116
|
+
**When it does not fit:** a rain that is not weather (a burst in one room, a fountain): `particles()`, recipe 64, or your own three.js `Points`. Your own drawing of the weather table: `weather.defineField`, recipe 44.
|
|
117
|
+
|
|
118
|
+
## Custom NPC behaviour: your own rule for what it does
|
|
119
|
+
```js
|
|
120
|
+
import { createEngine, world, collision, characters } from 'threedog';
|
|
121
|
+
|
|
122
|
+
const engine = createEngine({ canvas: document.getElementById('view') });
|
|
123
|
+
engine.use(world(), collision(), characters());
|
|
124
|
+
engine.npcs.behavior('pace', { // what must be remembered goes in rec.mind: plain values, saved with the NPC
|
|
125
|
+
near(rec, dt) { rec.mind.walked = (rec.mind.walked ?? 0) + dt; },
|
|
126
|
+
far(rec, dt) { rec.mind.walked = (rec.mind.walked ?? 0) + dt; },
|
|
127
|
+
});
|
|
128
|
+
engine.npcs.add({ id: 'guard', name: 'Guard', position: [2, 0, 2], behavior: 'pace', mind: {} });
|
|
129
|
+
Object.assign(window, { engine });
|
|
130
|
+
await engine.start();
|
|
131
|
+
```
|
|
132
|
+
```js
|
|
133
|
+
step(0.5);
|
|
134
|
+
assert(engine.world.get('guard').mind.walked > 0, 'the behaviour runs');
|
|
135
|
+
engine.npcs.remove('guard'); // cleanup: the data, the model and its interaction go together
|
|
136
|
+
assert(!engine.npcs.get('guard'), 'the NPC is gone');
|
|
137
|
+
```
|
|
138
|
+
**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`.
|
|
139
|
+
|
|
140
|
+
## Custom path source: paths that do not come from the ground
|
|
141
|
+
```js
|
|
142
|
+
import { createEngine, world, collision, characters } from 'threedog';
|
|
143
|
+
|
|
144
|
+
const engine = createEngine({ canvas: document.getElementById('view') });
|
|
145
|
+
engine.use(world(), collision(), characters());
|
|
146
|
+
Object.assign(window, { engine });
|
|
147
|
+
await engine.start();
|
|
148
|
+
// a list of points, null for no way, 'walk' for the built-in search
|
|
149
|
+
window.rails = engine.mod('characters.path', { owner: 'rails', set: ({ from, to }) => [from, { x: to.x, y: 0, z: from.z }, to] });
|
|
150
|
+
```
|
|
151
|
+
```js
|
|
152
|
+
const path = engine.characters.findPath({ x: 0, z: 0 }, { x: 4, z: 4 });
|
|
153
|
+
expect(path.length, 'the source answered').toBe(3);
|
|
154
|
+
expect(path[1].x, 'through its corner').toBe(4);
|
|
155
|
+
rails.remove(); // cleanup: the built-in search answers again
|
|
156
|
+
assert(JSON.stringify(engine.characters.findPath({ x: 0, z: 0 }, { x: 4, z: 4 })) !== JSON.stringify(path), 'the source no longer answers');
|
|
157
|
+
```
|
|
158
|
+
**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`.
|
|
159
|
+
|
|
160
|
+
## Two areas built in code: the engine remembers which one
|
|
161
|
+
```js
|
|
162
|
+
import { createEngine, world, collision, characters, level, THREE } from 'threedog';
|
|
163
|
+
|
|
164
|
+
const engine = createEngine({ canvas: document.getElementById('view') });
|
|
165
|
+
const floor = size => new THREE.Mesh(new THREE.BoxGeometry(size, 1, size).translate(0, -0.5, 0), new THREE.MeshStandardMaterial());
|
|
166
|
+
// a name in the manifest is what a save remembers, and its builder is how the area comes back: nothing else to wire
|
|
167
|
+
engine.assets.manifest({ models: { house: () => floor(20), outpost: () => floor(40) } });
|
|
168
|
+
engine.use(world(), collision(), characters(), level({ url: 'house' }));
|
|
169
|
+
engine.characters.createPlayer({ control: () => null, spawn: [0, 0, 0] });
|
|
170
|
+
Object.assign(window, { engine });
|
|
171
|
+
await engine.start();
|
|
172
|
+
```
|
|
173
|
+
```js
|
|
174
|
+
await engine.level.load('outpost'); step(0.1);
|
|
175
|
+
engine.player.placeAt([15, 0, 0]);
|
|
176
|
+
await engine.saves.save('check');
|
|
177
|
+
await engine.level.load('house'); step(0.1);
|
|
178
|
+
expect(engine.world.zone, 'walked back').toBe('house');
|
|
179
|
+
await engine.saves.load('check'); step(0.1);
|
|
180
|
+
expect(engine.world.zone, 'the save went back by itself').toBe('outpost');
|
|
181
|
+
expect(engine.player.position.x, 'with the player where it stood').toBe(15);
|
|
182
|
+
await engine.saves.remove('check'); // cleanup: the test slot
|
|
183
|
+
```
|
|
184
|
+
**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
|
+
|
|
186
|
+
## Climb a ladder: your own movement, kept when loading mid-climb
|
|
187
|
+
```js
|
|
188
|
+
import { createEngine, world, collision, characters } from 'threedog';
|
|
189
|
+
const engine = createEngine({ canvas: document.getElementById('view'), audio: { sounds: { rung: { src: 'footstep' } } } });
|
|
190
|
+
engine.use(world(), collision(), characters(), { name: 'ladder', afterLoad: () => grip() }); // after a load: the hold of the save, or none
|
|
191
|
+
engine.setGround({ height: (x, z) => z > 1 ? 3 : 0, slope: () => 0, type: () => 'wood' }); // the upper floor starts at z = 1
|
|
192
|
+
const player = engine.characters.createPlayer({ control: () => null, spawn: [0, 0, 0] });
|
|
193
|
+
let hold = null; // running code, so no save keeps it: the record field does, and grip puts the hold back
|
|
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; }; // false: placed by hand, no mover, no gravity
|
|
195
|
+
const climb = (dt, ch) => {
|
|
196
|
+
const y = ch.root.position.y += 1.5 * dt;
|
|
197
|
+
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); // the position is saved with the record, the state picks the animation
|
|
199
|
+
if (y >= 3) { engine.world.set('player', { climbing: false }); grip(); ch.placeAt([0, 3, 2]); }
|
|
200
|
+
};
|
|
201
|
+
engine.ops.define('ladder.climb', { run: e => { e.world.set('player', { climbing: true }); grip(); } });
|
|
202
|
+
Object.assign(window, { engine }); await engine.start();
|
|
203
|
+
```
|
|
204
|
+
```js
|
|
205
|
+
engine.ops.run('ladder.climb'); step(1);
|
|
206
|
+
const rung = engine.player.position.y;
|
|
207
|
+
assert(rung > 1 && rung < 3, 'halfway up');
|
|
208
|
+
await engine.saves.save('check');
|
|
209
|
+
step(2);
|
|
210
|
+
expect(engine.player.position.z, 'stepped off at the top').toBe(2);
|
|
211
|
+
expect(engine.control.of(engine.player).owner, 'the keys are back').toBe('player-input');
|
|
212
|
+
await engine.saves.load('check');
|
|
213
|
+
expect(engine.player.position.y, 'back on the rung').toBe(rung);
|
|
214
|
+
expect(engine.control.of(engine.player).owner, 'holding on again').toBe('ladder');
|
|
215
|
+
step(0.5);
|
|
216
|
+
assert(engine.player.position.y > rung, 'and the climb goes on');
|
|
217
|
+
step(2);
|
|
218
|
+
expect(engine.player.position.y, 'to the top').toBe(3);
|
|
219
|
+
await engine.saves.remove('check'); // cleanup: the test slot; the climb ended itself and took its hold away
|
|
220
|
+
```
|
|
221
|
+
**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
|
+
|
|
223
|
+
## In an existing game: pickup
|
|
224
|
+
```js
|
|
225
|
+
// 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
|
+
import { presets, world, collision, characters, inventory, pickups, interactions } from 'threedog';
|
|
227
|
+
engine.use(world(), collision(), characters(), inventory({ capacity: 1, defaultStack: 1 }), pickups(), interactions({ ...presets.interactions.nearest }));
|
|
228
|
+
engine.characters.createPlayer({ ...presets.player.thirdPerson, spawn: [0, 0, 0] }); // only if there is no hero yet
|
|
229
|
+
// where the level is set up
|
|
230
|
+
engine.inventory.define('gem', { name: 'Gem' });
|
|
231
|
+
engine.pickups.spawn([1, 0, 0], { give: 'gem', id: 'gem-1' });
|
|
232
|
+
// giving by hand: the answer is an object, so read .ok; if (inventory.add(...)) is true even when the bag is full
|
|
233
|
+
const given = engine.inventory.add('gem');
|
|
234
|
+
if (!given.ok) console.warn('bag full', given.code);
|
|
235
|
+
```
|
|
236
|
+
```js
|
|
237
|
+
expect(engine.inventory.add('gem').ok, 'a second gem does not fit').toBe(false);
|
|
238
|
+
step(0.2);
|
|
239
|
+
engine.input.simulate('interact', true); step(0.1); engine.input.simulate('interact', false); step(0.1);
|
|
240
|
+
assert(engine.world.get('gem-1'), 'with a full bag it stays on the ground');
|
|
241
|
+
engine.inventory.remove('gem'); // cleanup: the bag as it was
|
|
242
|
+
```
|
|
243
|
+
**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
|
+
|
|
245
|
+
## In an existing game: saved value
|
|
246
|
+
```js
|
|
247
|
+
// beside the system that owns the value, once, before the first load. A module's own state saves itself: this is for yours
|
|
248
|
+
const tally = { score: 0 };
|
|
249
|
+
engine.saves.register('tally', { version: 1, save: () => ({ ...tally }), load: d => { tally.score = d.score; } });
|
|
250
|
+
// at a checkpoint or a menu: false means nothing was written, so say "saved" only after true
|
|
251
|
+
const saveTally = async () => { if (!await engine.saves.save('slot1')) console.warn('not saved'); };
|
|
252
|
+
```
|
|
253
|
+
```js
|
|
254
|
+
tally.score = 7;
|
|
255
|
+
await saveTally();
|
|
256
|
+
tally.score = 0;
|
|
257
|
+
expect(await engine.saves.load('slot1'), 'it loads').toBe(true);
|
|
258
|
+
expect(tally.score, 'the value came back').toBe(7);
|
|
259
|
+
await engine.saves.remove('slot1'); // cleanup: the test slot
|
|
260
|
+
```
|
|
261
|
+
**When it does not fit:** a part that changes shape later needs a `migrate`: recipe 20. A preference is no game state: `localStorage`.
|
|
262
|
+
|
|
263
|
+
## In an existing game: press a key on a thing
|
|
264
|
+
```js
|
|
265
|
+
// main.js imports and engine.use, as in the pickup above. The key is the 'interact' action in your bindings
|
|
266
|
+
import { presets, world, collision, characters, interactions } from 'threedog';
|
|
267
|
+
engine.use(world(), collision(), characters(), interactions({ ...presets.interactions.nearest }));
|
|
268
|
+
engine.characters.createPlayer({ ...presets.player.thirdPerson, spawn: [0, 0, 0] }); // only if there is no hero yet
|
|
269
|
+
// where the level is set up: a mesh of yours, or a position
|
|
270
|
+
const door = { open: false, locked: false };
|
|
271
|
+
const spot = engine.interactions.add([1, 0, 0], { onUse: () => { if (door.locked) return { ok: false, code: 'locked' }; door.open = true; } });
|
|
272
|
+
```
|
|
273
|
+
```js
|
|
274
|
+
step(0.2);
|
|
275
|
+
engine.input.simulate('interact', true); step(0.1); engine.input.simulate('interact', false); step(0.1);
|
|
276
|
+
assert(door.open, 'E opens it');
|
|
277
|
+
spot.remove(); // cleanup: the handle ends it with the door
|
|
278
|
+
```
|
|
279
|
+
**When it does not fit:** something that happens by walking in, with no key: `triggers()`. Clicking with the mouse: `engine.rays`, recipe 19.
|
|
280
|
+
|
|
281
|
+
## In an existing game: after a delay
|
|
282
|
+
```js
|
|
283
|
+
// no setup: the clock is in every engine and stops when the game pauses, setTimeout would run on
|
|
284
|
+
const flags = { late: false };
|
|
285
|
+
const timer = engine.clock.after(2, () => { flags.late = true; }, { channel: 'real' });
|
|
286
|
+
// called off: timer.remove(). A function does not survive a load: pass an event name if the wait must
|
|
287
|
+
```
|
|
288
|
+
```js
|
|
289
|
+
step(2.1);
|
|
290
|
+
assert(flags.late, 'it ran in game time');
|
|
291
|
+
timer.remove(); // cleanup: removing it twice is fine
|
|
292
|
+
```
|
|
293
|
+
**When it does not fit:** hours and days of a calendar: `calendar()`, recipe 06. A wait in real seconds, for a menu or a sound: `{ channel: 'real' }`.
|
|
294
|
+
|
|
295
|
+
## In an existing game: steer the hero for a moment
|
|
296
|
+
```js
|
|
297
|
+
// main.js imports and engine.use, as in the pickup above; a hero must exist
|
|
298
|
+
import { presets, world, collision, characters } from 'threedog';
|
|
299
|
+
engine.use(world(), collision(), characters());
|
|
300
|
+
engine.characters.createPlayer({ ...presets.player.thirdPerson, spawn: [0, 0, 0] }); // only if there is no hero yet
|
|
301
|
+
// from your own rule: a hold outranks the keys until it ends, so never write the hero's position each frame
|
|
302
|
+
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
|
+
```
|
|
304
|
+
```js
|
|
305
|
+
step(0.2);
|
|
306
|
+
const from = engine.player.position.z;
|
|
307
|
+
dash();
|
|
308
|
+
step(0.3);
|
|
309
|
+
assert(engine.player.position.z !== from, 'the hold moved the hero');
|
|
310
|
+
step(0.3); // cleanup: the hold ended by itself
|
|
311
|
+
expect(engine.control.of(engine.player).owner, 'the keys are back').toBe('player-input');
|
|
312
|
+
```
|
|
313
|
+
**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.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":1,"files":{"content/actions.js":{"kind":"actions","mtime":
|
|
1
|
+
{"version":1,"files":{"content/actions.js":{"kind":"actions","mtime":1794045415000,"size":481,"from":0,"count":4,"indexIds":0,"positional":[]},"content/audio.js":{"kind":"audio","mtime":1794045415000,"size":430,"from":0,"count":1,"indexIds":0,"positional":[]},"content/items.js":{"kind":"items","mtime":1794045415000,"size":204,"from":0,"count":1,"indexIds":0,"positional":[]},"content/places.js":{"kind":"places","mtime":1794045415000,"size":209,"from":0,"count":1,"indexIds":0,"positional":[]},"content/props.js":{"kind":"props","mtime":1794045415000,"size":707,"from":0,"count":8,"indexIds":0,"positional":[]},"content/templates.js":{"kind":"templates","mtime":1794045415000,"size":835,"from":0,"count":4,"indexIds":0,"positional":[]},"content/views.js":{"kind":"views","mtime":1794045415000,"size":539,"from":0,"count":2,"indexIds":0,"positional":[]}},"ids":{"attack":[{"file":"content/actions.js","kind":"actions","line":4,"placed":false}],"retry":[{"file":"content/actions.js","kind":"actions","line":5,"placed":false}],"save":[{"file":"content/actions.js","kind":"actions","line":6,"placed":false}],"load":[{"file":"content/actions.js","kind":"actions","line":7,"placed":false}],"sounds":[{"file":"content/audio.js","kind":"audio","line":4,"placed":false}],"gem":[{"file":"content/items.js","kind":"items","line":3,"placed":false}],"room":[{"file":"content/places.js","kind":"places","line":3,"placed":false}],"floor":[{"file":"content/props.js","kind":"props","line":3,"placed":true},{"file":"content/templates.js","kind":"templates","line":4,"placed":false}],"wall-n":[{"file":"content/props.js","kind":"props","line":4,"placed":true}],"wall-s":[{"file":"content/props.js","kind":"props","line":5,"placed":true}],"wall-w":[{"file":"content/props.js","kind":"props","line":6,"placed":true}],"wall-e":[{"file":"content/props.js","kind":"props","line":7,"placed":true}],"pillar-1":[{"file":"content/props.js","kind":"props","line":8,"placed":true}],"pillar-2":[{"file":"content/props.js","kind":"props","line":9,"placed":true}],"slime-1":[{"file":"content/props.js","kind":"props","line":10,"placed":true}],"wall":[{"file":"content/templates.js","kind":"templates","line":5,"placed":false}],"pillar":[{"file":"content/templates.js","kind":"templates","line":6,"placed":false}],"slime":[{"file":"content/templates.js","kind":"templates","line":9,"placed":false}],"corner":[{"file":"content/views.js","kind":"views","line":4,"placed":false}],"door":[{"file":"content/views.js","kind":"views","line":5,"placed":false}]}}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Game map: action (generated, do not edit by hand)
|
|
2
2
|
|
|
3
3
|
> Generated by `npm run map` by scanning this folder; paths are relative to it. Pages: /action.html, entry `main.js`.
|
|
4
|
-
> Content data is in `content/*.js` (condition/effect syntax: `node_modules/threedog/docs/recipes/20-content-actions-save.md`), which main.js hands to the engine with `engine.content.load()`;
|
|
4
|
+
> Content data is in `content/*.js` (condition/effect syntax: `node_modules/threedog/docs/recipes/20-content-actions-save.md`), which main.js hands to the engine with `engine.content.load()`; to look up a name: the module pages listed below (`node_modules/threedog/docs/API.md` indexes them).
|
|
5
5
|
|
|
6
6
|
Content: actions 4 · audio 1 · items 1 · places 1 · props 8 (from templates 8) · templates 4 · views 2
|
|
7
7
|
|
|
@@ -23,11 +23,11 @@ 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/66-common-tasks.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`
|
|
30
|
-
- characters: `node_modules/threedog/docs/recipes/
|
|
30
|
+
- characters: `node_modules/threedog/docs/recipes/66-common-tasks.md` · `node_modules/threedog/docs/api/characters.md`
|
|
31
31
|
- settings: `node_modules/threedog/docs/recipes/26-ui-parts.md` · `node_modules/threedog/docs/api/settings.md`
|
|
32
32
|
- interactions: `node_modules/threedog/docs/recipes/20-content-actions-save.md` · `node_modules/threedog/docs/api/interactions.md`
|
|
33
33
|
- inventory: `node_modules/threedog/docs/recipes/03-items-pickups.md` · `node_modules/threedog/docs/api/inventory.md`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":1,"files":{"content/props.js":{"kind":"props","mtime":
|
|
1
|
+
{"version":1,"files":{"content/props.js":{"kind":"props","mtime":1794045415000,"size":1370,"from":0,"count":15,"indexIds":0,"positional":[]},"content/templates.js":{"kind":"templates","mtime":1794045415000,"size":232,"from":0,"count":2,"indexIds":0,"positional":[]},"content/vegetation.js":{"kind":"vegetation","mtime":1794045415000,"size":522,"from":0,"count":1,"indexIds":0,"positional":[]}},"ids":{"tree-1":[{"file":"content/props.js","kind":"props","line":4,"placed":true}],"tree-2":[{"file":"content/props.js","kind":"props","line":5,"placed":true}],"tree-3":[{"file":"content/props.js","kind":"props","line":6,"placed":true}],"tree-4":[{"file":"content/props.js","kind":"props","line":7,"placed":true}],"tree-5":[{"file":"content/props.js","kind":"props","line":8,"placed":true}],"tree-6":[{"file":"content/props.js","kind":"props","line":9,"placed":true}],"tree-7":[{"file":"content/props.js","kind":"props","line":10,"placed":true}],"sheep-1":[{"file":"content/props.js","kind":"props","line":11,"placed":true}],"sheep-2":[{"file":"content/props.js","kind":"props","line":12,"placed":true}],"sheep-3":[{"file":"content/props.js","kind":"props","line":13,"placed":true}],"sheep-4":[{"file":"content/props.js","kind":"props","line":14,"placed":true}],"sheep-5":[{"file":"content/props.js","kind":"props","line":15,"placed":true}],"sheep-6":[{"file":"content/props.js","kind":"props","line":16,"placed":true}],"sheep-7":[{"file":"content/props.js","kind":"props","line":17,"placed":true}],"sheep-8":[{"file":"content/props.js","kind":"props","line":18,"placed":true}],"tree":[{"file":"content/templates.js","kind":"templates","line":3,"placed":false}],"sheep":[{"file":"content/templates.js","kind":"templates","line":4,"placed":false}],"wheat":[{"file":"content/vegetation.js","kind":"vegetation","line":6,"placed":false}]}}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Game map: perf-island (generated, do not edit by hand)
|
|
2
2
|
|
|
3
3
|
> Generated by `npm run map` by scanning this folder; paths are relative to it. Pages: /perf-island.html, entry `main.js`.
|
|
4
|
-
> Content data is in `content/*.js` (condition/effect syntax: `node_modules/threedog/docs/recipes/20-content-actions-save.md`), which main.js hands to the engine with `engine.content.load()`;
|
|
4
|
+
> Content data is in `content/*.js` (condition/effect syntax: `node_modules/threedog/docs/recipes/20-content-actions-save.md`), which main.js hands to the engine with `engine.content.load()`; to look up a name: the module pages listed below (`node_modules/threedog/docs/API.md` indexes them).
|
|
5
5
|
|
|
6
6
|
Content: props 15 (from templates 15) · templates 2 · vegetation 1
|
|
7
7
|
|
|
@@ -17,14 +17,14 @@ 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/66-common-tasks.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`
|
|
24
24
|
- sky: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/sky.md`
|
|
25
25
|
- weather: `node_modules/threedog/docs/recipes/44-water-weather-hooks.md` · `node_modules/threedog/docs/api/weather.md`
|
|
26
26
|
- collision: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/collision.md`
|
|
27
|
-
- characters: `node_modules/threedog/docs/recipes/
|
|
27
|
+
- characters: `node_modules/threedog/docs/recipes/66-common-tasks.md` · `node_modules/threedog/docs/api/characters.md`
|
|
28
28
|
- settings: `node_modules/threedog/docs/recipes/26-ui-parts.md` · `node_modules/threedog/docs/api/settings.md`
|
|
29
29
|
- content: `node_modules/threedog/docs/recipes/30-templates.md` · `node_modules/threedog/docs/api/content.md`
|
|
30
30
|
|
|
@@ -63,7 +63,7 @@ engine.onFrame(() => {
|
|
|
63
63
|
|
|
64
64
|
// ---------- 4. Views: an op, so the URL, the dev bridge and tests switch the same way ----------
|
|
65
65
|
const state = { view: params.view };
|
|
66
|
-
engine.ops.define('
|
|
66
|
+
engine.ops.define('island.view', {
|
|
67
67
|
desc: 'Move the camera to a named view: overview, flock, field, river, rim', args: { name: 'string' },
|
|
68
68
|
can: (e, { name }) => VIEW_NAMES.includes(name) ? true : 'unknownView',
|
|
69
69
|
run: (e, { name }) => {
|
|
@@ -75,7 +75,7 @@ engine.ops.define('perf-island.view', {
|
|
|
75
75
|
reasons: { unknownView: 'View names: overview, flock, field, river, rim' },
|
|
76
76
|
});
|
|
77
77
|
engine.describe.add('perf-island', () => ({ view: state.view, season: engine.calendar.season, weather: engine.weather?.name }));
|
|
78
|
-
engine.events.on('engine:ready', () => engine.ops.run('
|
|
78
|
+
engine.events.on('engine:ready', () => engine.ops.run('island.view', { name: params.view }));
|
|
79
79
|
if (params.badView) console.warn(`perf-island: unknown view '${params.badView}', showing overview. Views: ${VIEW_NAMES.join(', ')}`);
|
|
80
80
|
|
|
81
81
|
engine.start();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Game map: plain-picture (generated, do not edit by hand)
|
|
2
2
|
|
|
3
3
|
> Generated by `npm run map` by scanning this folder; paths are relative to it. Pages: /plain-picture.html, entry `main.js`.
|
|
4
|
-
> Content data is in `content/*.js` (condition/effect syntax: `node_modules/threedog/docs/recipes/20-content-actions-save.md`), which main.js hands to the engine with `engine.content.load()`;
|
|
4
|
+
> Content data is in `content/*.js` (condition/effect syntax: `node_modules/threedog/docs/recipes/20-content-actions-save.md`), which main.js hands to the engine with `engine.content.load()`; to look up a name: the module pages listed below (`node_modules/threedog/docs/API.md` indexes them).
|
|
5
5
|
|
|
6
6
|
Content: none (no content/ folder)
|
|
7
7
|
|
|
@@ -14,12 +14,14 @@ None yet, write them in `DESIGN.md` (why it is designed this way, what not to ch
|
|
|
14
14
|
- createEngine: { ui: { loading: false }, saveKey: 'threedog-plain-picture', lights: false }
|
|
15
15
|
- calendar ({ ...presets.calendar.fixedTime, time: '22:00' })
|
|
16
16
|
- sky
|
|
17
|
+
- weather ({ types: { clear: {}, rain: { rain: 1, cloud: 0.8, fog: 0.6 } } })
|
|
17
18
|
- fixedCamera ({ shots: { street: { position: [2.5, 1.8, 14], lookAt: [-1, 2.6, -20] } }, start: 'street' })
|
|
18
19
|
|
|
19
20
|
## Read for this game (per installed module: recipe · api page; core API: `node_modules/threedog/docs/api/engine.md`)
|
|
20
21
|
|
|
21
22
|
- calendar: `node_modules/threedog/docs/recipes/06-clock-events.md` · `node_modules/threedog/docs/api/calendar.md`
|
|
22
23
|
- sky: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/sky.md`
|
|
24
|
+
- weather: `node_modules/threedog/docs/recipes/44-water-weather-hooks.md` · `node_modules/threedog/docs/api/weather.md`
|
|
23
25
|
- cameraRig: `node_modules/threedog/docs/recipes/21-camera.md` · `node_modules/threedog/docs/api/cameraRig.md`
|
|
24
26
|
|
|
25
27
|
Not used yet (check these before writing the system yourself):
|
package/examples/rc2d/GAMEMAP.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Game map: rc2d (generated, do not edit by hand)
|
|
2
2
|
|
|
3
3
|
> Generated by `npm run map` by scanning this folder; paths are relative to it. Pages: /rc2d.html, entry `main.js`.
|
|
4
|
-
> Content data is in `content/*.js` (condition/effect syntax: `node_modules/threedog/docs/recipes/20-content-actions-save.md`), which main.js hands to the engine with `engine.content.load()`;
|
|
4
|
+
> Content data is in `content/*.js` (condition/effect syntax: `node_modules/threedog/docs/recipes/20-content-actions-save.md`), which main.js hands to the engine with `engine.content.load()`; to look up a name: the module pages listed below (`node_modules/threedog/docs/API.md` indexes them).
|
|
5
5
|
|
|
6
6
|
Content: none (no content/ folder)
|
|
7
7
|
|
package/examples/rc2d/rc2d.js
CHANGED
|
@@ -98,7 +98,7 @@ export function createRadianceCascades2D(engine, options = {}) {
|
|
|
98
98
|
const swapped = /** @type {[THREE.Mesh, any][]} */ ([]);
|
|
99
99
|
const proxyOf = (/** @type {any} */ m) => {
|
|
100
100
|
let p = proxies.get(m);
|
|
101
|
-
//
|
|
101
|
+
// a flat stand-in whose colour is the source material's emissive, not art
|
|
102
102
|
if (!p) { p = new THREE.MeshBasicMaterial({ fog: false, toneMapped: false }); proxies.set(m, p); }
|
|
103
103
|
p.color.setRGB(0, 0, 0);
|
|
104
104
|
if (m.emissive) p.color.copy(m.emissive).multiplyScalar(m.emissiveIntensity ?? 1); // read every frame: flicker and day / night keep working
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":1,"files":{"content/items.js":{"kind":"items","mtime":
|
|
1
|
+
{"version":1,"files":{"content/items.js":{"kind":"items","mtime":1794045415000,"size":471,"from":0,"count":3,"indexIds":0,"positional":[]},"content/npcs.js":{"kind":"npcs","mtime":1794045415000,"size":352,"from":0,"count":1,"indexIds":0,"positional":[]},"content/places.js":{"kind":"places","mtime":1794045415000,"size":345,"from":0,"count":2,"indexIds":0,"positional":[]},"content/props.js":{"kind":"props","mtime":1794045415000,"size":1208,"from":0,"count":12,"indexIds":0,"positional":[]},"content/templates.js":{"kind":"templates","mtime":1794045415000,"size":394,"from":0,"count":6,"indexIds":0,"positional":[]},"content/vegetation.js":{"kind":"vegetation","mtime":1794045415000,"size":1840,"from":0,"count":5,"indexIds":0,"positional":[]}},"ids":{"apple":[{"file":"content/items.js","kind":"items","line":3,"placed":false}],"key":[{"file":"content/items.js","kind":"items","line":4,"placed":false}],"wood":[{"file":"content/items.js","kind":"items","line":5,"placed":false},{"file":"content/props.js","kind":"props","line":10,"placed":true}],"guide":[{"file":"content/npcs.js","kind":"npcs","line":3,"placed":false}],"stage":[{"file":"content/places.js","kind":"places","line":3,"placed":false}],"water":[{"file":"content/places.js","kind":"places","line":4,"placed":false}],"pine":[{"file":"content/props.js","kind":"props","line":4,"placed":true}],"round-tree":[{"file":"content/props.js","kind":"props","line":5,"placed":true}],"rock":[{"file":"content/props.js","kind":"props","line":6,"placed":true}],"flower-a":[{"file":"content/props.js","kind":"props","line":7,"placed":true}],"flower-b":[{"file":"content/props.js","kind":"props","line":8,"placed":true}],"flower-c":[{"file":"content/props.js","kind":"props","line":9,"placed":true}],"stone":[{"file":"content/props.js","kind":"props","line":11,"placed":true}],"metal":[{"file":"content/props.js","kind":"props","line":12,"placed":true}],"glass":[{"file":"content/props.js","kind":"props","line":13,"placed":true}],"shadow-stage":[{"file":"content/props.js","kind":"props","line":14,"placed":true}],"room":[{"file":"content/props.js","kind":"props","line":15,"placed":true},{"file":"content/templates.js","kind":"templates","line":8,"placed":false}],"woodBlock":[{"file":"content/templates.js","kind":"templates","line":3,"placed":false}],"stoneBlock":[{"file":"content/templates.js","kind":"templates","line":4,"placed":false}],"metalBall":[{"file":"content/templates.js","kind":"templates","line":5,"placed":false}],"glassPanes":[{"file":"content/templates.js","kind":"templates","line":6,"placed":false}],"shadowStage":[{"file":"content/templates.js","kind":"templates","line":7,"placed":false}],"松树":[{"file":"content/vegetation.js","kind":"vegetation","line":4,"placed":false}],"圆树":[{"file":"content/vegetation.js","kind":"vegetation","line":10,"placed":false}],"石头":[{"file":"content/vegetation.js","kind":"vegetation","line":16,"placed":false}],"草":[{"file":"content/vegetation.js","kind":"vegetation","line":20,"placed":false}],"野花":[{"file":"content/vegetation.js","kind":"vegetation","line":25,"placed":false}]}}
|