threedog 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/Animator.js +1 -0
- package/core/Assets.js +16 -0
- package/core/DebugOverrides.js +143 -0
- package/core/Describe.js +14 -3
- package/core/Engine.js +32 -69
- package/core/Events.js +59 -1
- package/core/I18n.js +2 -2
- package/core/Inspect.js +12 -32
- package/core/InspectScene.js +7 -3
- package/core/MaterialInfo.js +32 -0
- package/core/Ops.js +43 -59
- package/core/Saves.js +5 -4
- package/core/UrlState.js +3 -2
- package/core/Vars.js +1 -0
- package/core/Views.js +49 -0
- package/core/actor.js +2 -2
- package/core/assetReport.js +83 -0
- package/core/catalog.js +169 -0
- package/core/checks.js +67 -0
- package/core/claims.js +51 -0
- package/core/debugView.js +76 -0
- package/core/describeRender.js +45 -0
- package/core/describeText.js +11 -4
- package/core/errorCodes.js +33 -0
- package/core/errorHints.js +6 -1
- package/core/holds.js +106 -0
- package/core/lifecycle.js +1 -0
- package/core/lightWatch.js +23 -3
- package/core/look/coreParts.js +112 -0
- package/core/look/layers.js +136 -0
- package/core/look/part.js +173 -0
- package/core/look/report.js +79 -0
- package/core/look/write.js +86 -0
- package/core/loop.js +15 -14
- package/core/modules.js +19 -5
- package/core/opsAtomic.js +31 -0
- package/core/opsCheck.js +25 -14
- package/core/opsFail.js +20 -0
- package/core/opsHistory.js +6 -6
- package/core/opsRun.js +77 -0
- package/core/params.js +132 -0
- package/core/renamed.js +21 -0
- package/core/saveApply.js +2 -2
- package/core/sceneMethods.js +9 -34
- package/core/services.js +73 -0
- package/core/startup.js +3 -1
- package/core/styleParts.js +2 -2
- package/core/thingExplain.js +68 -0
- package/core/thingOps.js +35 -24
- package/core/things.js +15 -1
- package/core/util.js +11 -0
- package/core/validate.js +23 -7
- package/docs/AI.md +83 -109
- package/docs/API.md +7 -8
- package/docs/CODEMAP.md +63 -51
- package/docs/COMMANDS.md +17 -5
- package/docs/CONVENTIONS.md +17 -6
- package/docs/THREE.md +3 -3
- package/docs/api/assets.md +2 -0
- package/docs/api/characters.md +2 -0
- package/docs/api/collision.md +4 -0
- package/docs/api/content.md +1 -0
- package/docs/api/engine.md +20 -11
- package/docs/api/events.md +5 -1
- package/docs/api/post.md +5 -4
- package/docs/api/saves.md +2 -1
- package/docs/api/sky.md +3 -3
- package/docs/api/style.md +3 -3
- package/docs/api/tools.md +2 -0
- package/docs/api/weather.md +1 -1
- package/docs/recipes/02-npc.md +16 -0
- package/docs/recipes/03-items-pickups.md +1 -1
- package/docs/recipes/06-clock-events.md +13 -0
- package/docs/recipes/07-flow-scenes-pause.md +4 -0
- package/docs/recipes/08-weather-sky.md +1 -1
- package/docs/recipes/09-style-pack.md +5 -5
- package/docs/recipes/12-navmesh.md +22 -0
- package/docs/recipes/13-animation.md +3 -0
- package/docs/recipes/15-perf.md +1 -1
- package/docs/recipes/16-dev-bridge.md +51 -17
- package/docs/recipes/21-camera.md +51 -2
- package/docs/recipes/23-ops.md +45 -9
- package/docs/recipes/27-net.md +1 -1
- package/docs/recipes/29-grid.md +1 -1
- package/docs/recipes/34-environment-lighting.md +9 -8
- package/docs/recipes/38-environment-look-hooks.md +8 -6
- package/docs/recipes/40-scene.md +29 -0
- package/docs/recipes/41-thing-registry.md +29 -0
- package/docs/recipes/43-shader-patches-surface-looks.md +2 -0
- package/docs/recipes/44-water-weather-look-hooks.md +6 -4
- package/docs/recipes/45-cascaded-shadows.md +1 -1
- package/docs/recipes/46-blender-art-route.md +22 -0
- package/docs/recipes/48-make-material.md +70 -0
- package/docs/recipes/49-game-module-contract.md +71 -0
- package/docs/recipes/50-own-renderer.md +12 -0
- package/docs/recipes/51-capability-catalog.md +63 -0
- package/docs/recipes/52-look.md +108 -0
- package/examples/action/GAMEMAP.md +5 -5
- package/examples/action/content/index.js +2 -1
- package/examples/action/content/views.js +6 -0
- package/examples/sheepisland/GAMEMAP.md +2 -3
- package/examples/styletest/GAMEMAP.md +3 -3
- package/examples/styletest/main.js +1 -1
- package/examples/styletest/panel.js +3 -3
- package/examples/world/GAMEMAP.md +3 -3
- package/index.d.ts +27 -0
- package/index.js +3 -1
- package/llms.txt +5 -0
- package/modules/ambience/Ambience.js +5 -2
- package/modules/camera/FirstPersonCamera.js +3 -5
- package/modules/camera/FixedCamera.js +19 -12
- package/modules/camera/FollowCamera.js +14 -8
- package/modules/camera/RtsCamera.js +3 -5
- package/modules/camera/common.js +40 -10
- package/modules/camera/index.js +1 -1
- package/modules/camera/projection.js +34 -0
- package/modules/characters/Character.js +29 -17
- package/modules/characters/astar.js +14 -7
- package/modules/characters/index.js +6 -3
- package/modules/characters/movers/simple.js +6 -1
- package/modules/characters/npcSim.js +8 -2
- package/modules/characters/pathAsync.js +12 -6
- package/modules/characters/pathJob.js +2 -1
- package/modules/characters/proceduralRig.js +5 -1
- package/modules/characters/useModel.js +22 -0
- package/modules/characters/walkTo.js +58 -0
- package/modules/collision/Collision.js +102 -4
- package/modules/content/explain.js +13 -0
- package/modules/content/index.js +2 -0
- package/modules/content/loader.js +3 -0
- package/modules/content/rules.js +1 -0
- package/modules/debug/DebugPanel.js +11 -5
- package/modules/entities/Entities.js +6 -2
- package/modules/flow/index.js +5 -2
- package/modules/gameplay/Dialogue.js +5 -2
- package/modules/gameplay/Interactions.js +12 -2
- package/modules/gameplay/Inventory.js +21 -11
- package/modules/gameplay/Quests.js +13 -3
- package/modules/gameplay/pickups.js +5 -3
- package/modules/grid/Layer.js +1 -1
- package/modules/grid/index.js +1 -1
- package/modules/grid/tiles.js +9 -5
- package/modules/hlod/index.js +5 -2
- package/modules/hud/index.js +5 -2
- package/modules/level/index.js +5 -3
- package/modules/lights/index.js +5 -2
- package/modules/music/Music.js +6 -2
- package/modules/nav/index.js +5 -3
- package/modules/net/Client.js +4 -3
- package/modules/net/Host.js +2 -2
- package/modules/net/index.js +5 -3
- package/modules/particles/Particles.js +1 -1
- package/modules/photo/Photo.js +10 -7
- package/modules/rigid/RigidBodies.js +5 -2
- package/modules/settings/Settings.js +6 -3
- package/modules/settings/apply.js +2 -1
- package/modules/sky/Sky.js +21 -19
- package/modules/sky/cascades.js +6 -6
- package/modules/sky/domeLayers.js +1 -1
- package/modules/sky/environment.js +39 -13
- package/modules/sky/fog.js +9 -6
- package/modules/sky/frame.js +4 -3
- package/modules/sky/look.js +3 -2
- package/modules/sky/lookFog.js +80 -0
- package/modules/sky/lookShadow.js +50 -0
- package/modules/sky/lookSky.js +108 -0
- package/modules/sky/shader.js +2 -2
- package/modules/sky/shadow.js +4 -10
- package/modules/sky/skyModule.js +4 -3
- package/modules/terrain/ChunkManager.js +2 -33
- package/modules/terrain/chunkLevels.js +40 -0
- package/modules/terrain/index.js +10 -2
- package/modules/terrain/lookGround.js +61 -0
- package/modules/timeline/Timeline.js +7 -3
- package/modules/timeline/Tween.js +3 -7
- package/modules/timeline/shots.js +6 -4
- package/modules/triggers/index.js +9 -2
- package/modules/vegetation/Vegetation.js +2 -1
- package/modules/vegetation/index.js +6 -3
- package/modules/vegetation/lookWind.js +37 -0
- package/modules/water/Water.js +19 -3
- package/modules/water/look.js +80 -0
- package/modules/weather/Weather.js +22 -31
- package/modules/weather/look.js +75 -0
- package/modules/weather/particles.js +1 -1
- package/modules/weather/strings.js +15 -0
- package/modules/world/explain.js +11 -0
- package/modules/world/index.js +11 -4
- package/modules/world/thingSource.js +44 -0
- package/package.json +1 -1
- package/render/PostFX.js +48 -51
- package/render/effects.js +4 -2
- package/render/fuse.js +12 -0
- package/render/lights.js +4 -2
- package/render/lookSurface.js +161 -0
- package/render/materials.js +27 -10
- package/render/postLook.js +86 -0
- package/render/surface.js +3 -1
- package/types/core.d.ts +216 -24
- package/types/gameplay.d.ts +10 -0
- package/types/generated/core/DebugOverrides.d.ts +52 -0
- package/types/generated/core/Events.d.ts +43 -0
- package/types/generated/core/Ops.d.ts +62 -21
- package/types/generated/core/Saves.d.ts +1 -0
- package/types/generated/core/Views.d.ts +33 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
- package/types/generated/modules/grid/Layer.d.ts +1 -0
- package/types/generated/modules/sky/Sky.d.ts +10 -17
- package/types/generated/modules/weather/Weather.d.ts +5 -15
- package/types/generated/render/PostFX.d.ts +20 -23
- package/types/generated/render/materials.d.ts +10 -0
- package/types/physics.d.ts +8 -0
- package/types/style.d.ts +16 -6
- package/ui/Parts.js +6 -2
- package/ui/UI.js +1 -1
- package/ui/defaults.js +1 -1
- package/docs/api/debug.md +0 -10
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# 52 Change any look: `engine.look`
|
|
2
|
+
|
|
3
|
+
Every look part lives at `engine.look.<part>` and is changed with the same verbs. The style pack gives the starting values; the game changes them on top.
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
const cave = engine.look.tone.set({ exposure: 0.6 }, { owner: 'cave' }); // only the keys you give; null drops a key
|
|
7
|
+
engine.look.lights.set({ sun: { intensity: 0.5 } }, { owner: 'cave' });
|
|
8
|
+
cave.remove(); // or engine.look.tone.clear('cave'): the style value shows again
|
|
9
|
+
engine.look.env.replace('sky'); // take a part over whole; replace(null) gives it back
|
|
10
|
+
engine.describe().look.tone.exposure; // { value: 0.6, by: 'game:cave', at: 'main.js:12', under: ['style'] }
|
|
11
|
+
engine.catalog('look.tone'); // params with default, why, off; hooks; what replace accepts and loses
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
- Layers, upper wins: engine default < style < game (each owner; the last one written wins) < `engine.debug.override(owner, 'look.<part>', values)`.
|
|
15
|
+
- `set` / `patch(name, glsl)` / `replace(impl)`: a part offers only the verbs that make sense for it; the others throw with the verb to use. A part whose verb takes other arguments (`materials.replace(role, impl)`) lists the call shape in `engine.catalog('look.<part>').signatures`, and a wrong call quotes it.
|
|
16
|
+
- `by` in describe is `'engine'`, `'style'`, `'game'` (owner `'game'`), `'<layer>:<owner>'` (for example game:cave or debug:probe: the layer, then the owner you passed) or `'three'`. `describe().render` keeps only renderer facts; its `by` is the path of the record to read here (`'look.tone.exposure'`).
|
|
17
|
+
- Look changes are not saved: after a load, set them again from your own state.
|
|
18
|
+
- Changing the three.js object directly (`engine.renderer.toneMappingExposure = 2`) still works; describe tags it `three` and you lose the owner and the debug layer.
|
|
19
|
+
- Old calls and names throw `renamed-api` and name the new call: see [Renamed in 0.2](#renamed-in-02).
|
|
20
|
+
- Your own module's part: `defineLookPart(engine, { id, params, style, apply })`. Every param declares `default`; a default that changes the picture declares `why` and `off`, or `neutral: true` (checked by `npm run check`; R36 checks that the part's `Look<Part>` type lists the same keys). A part author changes records only through the part's methods `write`, `ownerValue`, `extend`, `retract`, `has`, `resolved`, `restyle` (rule R25 flags `part._...`); `validate(key, value)` in the spec rejects a value before anything is written, and an `apply` that throws leaves no layer behind.
|
|
21
|
+
|
|
22
|
+
## Atmosphere parts (sky module): fog, sky, shadow
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
engine.look.fog.set({ far: 220, color: '#9bb' }, { owner: 'cave' }); // kind, color, density, near, far, height, falloff, enabled
|
|
26
|
+
engine.look.fog.replace('manual'); // or a THREE.Fog: the sky stops writing scene.fog; replace(null) gives it back
|
|
27
|
+
engine.look.sky.set({ clouds: { coverage: 0.7, speed: [0.01, 0] }, backdrop: 0x335577 });
|
|
28
|
+
engine.look.sky.patch('layer:aurora', { glsl: '...threedogSkyLayer...', blend: 'add' }); // a named dome layer; patch('layer:aurora', null) removes it
|
|
29
|
+
engine.look.sky.patch('clouds', glsl); // the cloud function; replace(skyboxName | Texture | Object3D) swaps the dome
|
|
30
|
+
engine.look.shadow.set({ type: 'vsm', radius: 3, cascades: 3, maxFar: 150 }); // set only
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
- `fog` shows `enabled` and `far` (fog reaches full strength at `engine.fogFar`, starting at 0.3 x that) as the visible defaults; turn off with `set({ enabled: false })`. Color, density, near, far, enabled and linear <-> exp2 are live. Kind `'exp'` / `'height'`, `height`, `falloff` and the `'fog'` hook replace three's shared fog shader chunks, so they only work before the first frame (style, `sky({ fog })`, or right after `createEngine`); later they throw and say so.
|
|
34
|
+
- `sky`: `clouds.*` are live uniforms of the dome (they only draw when `clouds.coverage` > 0). A hook change recompiles the dome material once. Style `layers` arrays are named by their `name` key, else `layer0`, `layer1`.
|
|
35
|
+
- `shadow`: no `patch` (the cascade patch is internal) and no `replace` (to own the shadows, light with your own lights: `sky({ sun: false })`).
|
|
36
|
+
|
|
37
|
+
## Surface parts: `materials`, `surface`, `ground`, `wind`
|
|
38
|
+
|
|
39
|
+
A change to these parts reaches the materials made **after** it, with one exception: `look.materials.set` of the plain properties `color`, `emissive`, `emissiveIntensity`, `roughness`, `metalness`, `opacity`, `envMapIntensity`, `shininess` and `specular` also changes the materials already made for that role (no recompile; clearing the layer goes back to the style's value). Shader-changing keys (`type`, `steps`, `ramp`, `soften`, `repeat`, `wrap`, `detail`, `lighting`, `patch`, `replace`) and all of `look.surface` are for new materials only (a Material already handed out, or cloned by your game, is not touched; catalog and describe say so as `appliesTo`, and a debug override warns). `engine.look.<part>.object` is the three.js object behind a part; for `materials` it is a function: `engine.look.materials.object('wool')` is the last Material made for that role, `object()` all of them.
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
const L = engine.look;
|
|
43
|
+
L.materials.set({ wool: { roughness: 0.4, color: 0xf2ece0 } }, { owner: 'shop' }); // merged into style.materials.wool; any role name
|
|
44
|
+
L.materials.patch('dim', { glsl: { fragment: { color_fragment: 'diffuseColor.rgb *= 0.8;' } } }, { roles: ['wool'] }); // a ShaderPatch on those roles
|
|
45
|
+
L.materials.replace('wool', new THREE.MeshMatcapMaterial({ matcap })); // the role is this Material (or (params, purpose, engine) => Material)
|
|
46
|
+
L.surface.set({ lighting: { wrap: 0.3, shadowTint: { color: '#4a5a9a', strength: 0.5 } }, detail: { noise: 'grain', strength: 0.15 } });
|
|
47
|
+
L.surface.set({ ramp: [0.35, 0.7, 1], soften: 0.2 }); // every toon material's ramp
|
|
48
|
+
L.surface.patch('lighting', glsl); // your threedogLighting(...), see recipe 43
|
|
49
|
+
L.ground.set({ shading: 'flat', colors: { grass: '#7cc06b' } }); // colors / biomeColors / steep / variation / shading rebuild the chunks
|
|
50
|
+
L.ground.set({ detail: { noise: 'paper', scale: 0.4, strength: 0.25 } }); // detail layer on the ground (style.terrain.detail)
|
|
51
|
+
L.ground.replace((e) => myGroundMaterial(e)); // Material or (engine) => Material; replace(null) gives it back
|
|
52
|
+
L.wind.set({ frequency: 1.5, amplitude: 0.5 }); // live on every plant, planted ones too
|
|
53
|
+
L.wind.patch('sway', glsl); // threedogWind(...); read when vegetation.add runs, so patch first
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
- `materials`: `set` / `patch` / `replace` all name a role. `set` merges into spec entries; a role whose style entry is a Material or a function is changed with `replace`. Role names are free: invent new ones (`makeMaterial('lantern-glass')`); the engine only warns on a likely typo of a known role.
|
|
57
|
+
- `surface`: `set` / `patch('lighting' | 'detail', glsl)`; no `replace` (swap a whole material with `materials.replace`). `style.lighting` is the style layer.
|
|
58
|
+
- `ground` (terrain module): `set` / `patch('detail', glsl)` / `replace`. What `terrain({ colors, shading, material })` was given shows as owner `terrain()`.
|
|
59
|
+
- `wind` (vegetation module): `set` / `patch('sway', glsl)`; no `replace`. `style.wind` is the style layer.
|
|
60
|
+
- `set({ role: { key } })` accepts a key `makeMaterial` reads (type, steps, ramp, soften, repeat, wrap, detail, lighting, or a three.js material property); a typo throws.
|
|
61
|
+
- `look.cloudShadow` (cloud shadows, core) stays its own part: its `shadow` is read by every material and by the weather, not only by surfaces.
|
|
62
|
+
|
|
63
|
+
## Water, weather, post
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
engine.look.water.set({ opacity: 0.5, waveHeight: 2 }, { owner: 'storm' }); // live, no recompile
|
|
67
|
+
engine.look.water.set({ foam: { color: 0xffffff }, depthColor: { shallow: 0x88ccdd, deep: 0x003355 } }); // rebuilds the water material once
|
|
68
|
+
engine.look.water.patch('wave', 'float threedogWaterWave(vec3 p, float t) { return sin(p.x + t) * 0.2; }'); // hooks: wave, surface
|
|
69
|
+
engine.look.water.replace((engine, { uniforms, waves, surface }) => myMaterial); // the whole surface (style.water.material)
|
|
70
|
+
|
|
71
|
+
engine.look.weather.set({ 'rain.speed': 10, 'snow.size': 8, 'lightning.brightness': 0.5, overcastColor: '#667' }); // rebuilds that field's particles once
|
|
72
|
+
engine.look.weather.patch('rain.fragment', wholeFragmentShaderText); // rain|snow . vertex|fragment: the WHOLE shader text, not a function
|
|
73
|
+
engine.look.weather.replace({ ash: { shape: 'soft', color: 0x555555 }, rain: { create } }); // = weather.define; null gives the fields back
|
|
74
|
+
|
|
75
|
+
engine.look.post.set({ bloom: { strength: 0.6 }, vignette: false }); // keys: '<effect>.<param>', '<effect>.enabled'
|
|
76
|
+
engine.look.post.patch('tint', { glsl: 'color.rgb *= vec3(1.0, 0.9, 0.8);', slot: 'ldr', order: 5 }); // generates a fuse effect named 'tint'; patch('tint', null) removes it
|
|
77
|
+
engine.look.post.add({ name: 'scan', slot: 'hdr', order: 5, create: (ctx) => myPass }, { owner: 'cave' }); // ONE custom pass; returns { remove() }. Same errors as the chain (duplicate name, second 'scene' pass, depth order) and nothing is added. Tune it with set({ 'scan.<param>': v })
|
|
78
|
+
engine.look.post.replace([bloom(), grain()]); // swaps the whole chain; replace(null) gives the style chain back
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
- Water: structural keys (`depthColor`, `foam`, the hooks, `replace`) rebuild the shared material once and hand it to every water mesh; the live keys only write a uniform. `water({ opacity: 0.5 })` options are the game layer.
|
|
82
|
+
- Weather: a field the weather table lacks (`snow` in a desert) has no particles; setting it warns once. `replace({ [field]: spec })` holds one object per owner, so list every field you replace in each call; while a field is replaced, `set` on it is ignored.
|
|
83
|
+
- Post: `look.post.set` writes the `game` layer (keys `<effect>.<param>` and `<effect>.enabled`); style effects (bloom, ao ...) are the style layer; `engine.post.get(name)` only reads an effect. MSAA is `engine.post.setAntialias(on)`. Costly effects start off on low-tier devices: `look.post` lists `<effect>.enabled` with `why` and `off`. `postAdd` / `postRemove` stay style-pack parts (they edit the list before the engine exists).
|
|
84
|
+
- `describe().render.post` reads the same records (`by`: style, game, debug).
|
|
85
|
+
|
|
86
|
+
## sky.modify vs look.lights
|
|
87
|
+
|
|
88
|
+
Two ways to make the light darker or brighter; pick by what you want to keep.
|
|
89
|
+
- `engine.sky.modify('cave', { sun: 0.3, ambient: 0.4, fog: 0.5, tint, tintAmount })` is a **multiplier layer** on what the sky produces each frame (keyframes, weather, season). The time of day keeps moving underneath, layers from different owners multiply, `modify('cave', null)` removes yours, and `sky.modifiers` shows the combined result (read-only). Use it for "darker in the cave" or "ash over the ground" (`groundCover`, `coverAmount`).
|
|
90
|
+
- `engine.look.lights.set({ sun: { intensity: 0.5 } }, { owner: 'cave' })` is an **override layer** on the part's own values: the key you give replaces what the style or the keyframes said, whatever the hour. Use it for "the sun is exactly this".
|
|
91
|
+
## Renamed in 0.2 (old call → new call)
|
|
92
|
+
|
|
93
|
+
The old calls below now throw `renamed-api` and the message names the new call (the list is `RENAMED` in `core/renamed.js`; rule R39 keeps the old names out of the repo).
|
|
94
|
+
|
|
95
|
+
| Old call | New call |
|
|
96
|
+
|---|---|
|
|
97
|
+
| `engine.setExposure(v)`, `engine.setToneMapping(m)` | `engine.look.tone.set({ exposure: v })`, `engine.look.tone.set({ mapping: m })` |
|
|
98
|
+
| `engine.sky.setShadow(o)` | `engine.look.shadow.set(o)` |
|
|
99
|
+
| `engine.sky.setEnvironment(o)` | `engine.look.env.replace('sky')` then `engine.look.env.set({ intensity, rotation })`; `replace(false)` turns it off |
|
|
100
|
+
| `engine.weather.define(field, spec)` | `engine.look.weather.replace({ [field]: spec })` |
|
|
101
|
+
| `engine.post.add(effect)` | `engine.look.post.add(effect, { owner })` (one pass, returns `{ remove() }`), `engine.look.post.patch(name, { glsl })` (a color effect) or `engine.look.post.replace([...effects])` (the whole chain) |
|
|
102
|
+
| `engine.post.enable(name, on)`, handle `.set` / `.enable` / `.remove` | `engine.look.post.set({ 'bloom.enabled': on })`, `engine.look.post.set({ 'bloom.strength': 0.6 })`; MSAA: `engine.post.setAntialias(on)` |
|
|
103
|
+
| `engine.look.clouds` | `engine.look.cloudShadow` |
|
|
104
|
+
| `engine.cameraOverride = { owner }` | `const cam = engine.takeCamera('owner', { focus })`; `cam.remove()` releases it |
|
|
105
|
+
| `engine.views.define(name, { pos })` | `engine.views.define(name, { position: [x, y, z] })` |
|
|
106
|
+
| failure `result.reason` (`ops.run` / `can` / `undo`) | `result.code` (reading `reason` throws) |
|
|
107
|
+
|
|
108
|
+
Not renamed (still the way to do it): per-call `makeMaterial(role, params)` keys win for that one material; `applyEffects(mat, { patches })` is the low-level form of `look.materials.patch(name, spec, { roles })`; `style.terrain.*`, `style.wind.*` and `style.lighting` are the style layer of `look.ground` / `look.wind` / `look.surface`.
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
> Generated by `npm run map` by scanning this folder; paths are relative to it. Pages: /action.html, entry `main.js`.
|
|
4
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()`; for the engine API read `node_modules/threedog/docs/API.md` (index) first, then only the module pages listed below.
|
|
5
5
|
|
|
6
|
-
Content: actions 4 · audio 1 · items 1 · places 1 · props 8 (from templates 8) · templates 4
|
|
6
|
+
Content: actions 4 · audio 1 · items 1 · places 1 · props 8 (from templates 8) · templates 4 · views 2
|
|
7
7
|
|
|
8
8
|
## Design decisions (hand-written, from DESIGN.md)
|
|
9
9
|
|
|
@@ -24,14 +24,13 @@ Content: actions 4 · audio 1 · items 1 · places 1 · props 8 (from templates
|
|
|
24
24
|
|
|
25
25
|
- world: `node_modules/threedog/docs/recipes/18-world.md` · `node_modules/threedog/docs/api/world.md`
|
|
26
26
|
- sky: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/sky.md`
|
|
27
|
-
- collision: `node_modules/threedog/docs/recipes/
|
|
27
|
+
- collision: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/collision.md`
|
|
28
28
|
- characters: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/characters.md`
|
|
29
29
|
- settings: `node_modules/threedog/docs/recipes/26-ui-parts.md` · `node_modules/threedog/docs/api/settings.md`
|
|
30
30
|
- interactions: `node_modules/threedog/docs/recipes/20-content-actions-save.md` · `node_modules/threedog/docs/api/interactions.md`
|
|
31
31
|
- inventory: `node_modules/threedog/docs/recipes/03-items-pickups.md` · `node_modules/threedog/docs/api/inventory.md`
|
|
32
32
|
- content: `node_modules/threedog/docs/recipes/10-blender-level.md` · `node_modules/threedog/docs/api/content.md`
|
|
33
33
|
- hud: `node_modules/threedog/docs/recipes/04-quests.md` · `node_modules/threedog/docs/api/hud.md`
|
|
34
|
-
- debug: `node_modules/threedog/docs/api/debug.md`
|
|
35
34
|
|
|
36
35
|
Not used yet (check these before writing the system yourself):
|
|
37
36
|
|
|
@@ -46,11 +45,12 @@ content/*.js is content data: how to write it in `node_modules/threedog/docs/rec
|
|
|
46
45
|
|---|---|---|
|
|
47
46
|
| content/actions.js | 9 | |
|
|
48
47
|
| content/audio.js | 10 | |
|
|
49
|
-
| content/index.js |
|
|
48
|
+
| content/index.js | 11 | |
|
|
50
49
|
| content/items.js | 5 | |
|
|
51
50
|
| content/places.js | 5 | |
|
|
52
51
|
| content/props.js | 12 | |
|
|
53
52
|
| content/templates.js | 11 | |
|
|
53
|
+
| content/views.js | 7 | |
|
|
54
54
|
| look.js | 6 | This example's look, as a style part merged over the lowpoly pack (createEngine({ style: [lowpoly, … |
|
|
55
55
|
| main.js | 138 | @ts-check Action example: one room, one player, one slime, one drop. Shows how an action game wires… |
|
|
56
56
|
| models.js | 26 | Models this example builds in code (floor, wall, pillar, enemy), registered by name in main.js and … |
|
|
@@ -119,7 +119,7 @@ Code that breaks saves or manages world models: none (rule R33).
|
|
|
119
119
|
- Save slots: slot1
|
|
120
120
|
- Save entries the game registers itself: ' +
|
|
121
121
|
'action
|
|
122
|
-
-
|
|
122
|
+
- Saved parts of the engine modules (vars, inventory, quests, timers, world...): `npx threedog catalog` (saves per module)
|
|
123
123
|
|
|
124
124
|
## Style pack keys
|
|
125
125
|
|
|
@@ -5,5 +5,6 @@ import actions from './actions.js';
|
|
|
5
5
|
import templates from './templates.js';
|
|
6
6
|
import props from './props.js';
|
|
7
7
|
import audio from './audio.js';
|
|
8
|
+
import views from './views.js';
|
|
8
9
|
|
|
9
|
-
export default { places, items, actions, templates, props, audio };
|
|
10
|
+
export default { places, items, actions, templates, props, audio, views };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Named fixed camera views of the room (engine.content.load -> engine.views.define). Same name = same framing every time, so two screenshots
|
|
2
|
+
// differ only by time, style or code: npm run shot -- action --view corner (the page is action.html; add --compare before.png to diff a change).
|
|
3
|
+
export default {
|
|
4
|
+
corner: { position: [7, 5, -8], target: [0, 1, 0], fov: 55 }, // the whole room from a corner, a little above
|
|
5
|
+
door: { position: [0, 2.2, 9], target: [0, 1.2, 0] }, // from the far side looking back at the spawn
|
|
6
|
+
};
|
|
@@ -22,11 +22,10 @@ None yet, write them in `DESIGN.md` (why it is designed this way, what not to ch
|
|
|
22
22
|
- vegetation: `node_modules/threedog/docs/recipes/10-blender-level.md` · `node_modules/threedog/docs/api/vegetation.md`
|
|
23
23
|
- sky: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/sky.md`
|
|
24
24
|
- weather: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/weather.md`
|
|
25
|
-
- collision: `node_modules/threedog/docs/recipes/
|
|
25
|
+
- collision: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/collision.md`
|
|
26
26
|
- characters: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/characters.md`
|
|
27
27
|
- settings: `node_modules/threedog/docs/recipes/26-ui-parts.md` · `node_modules/threedog/docs/api/settings.md`
|
|
28
28
|
- content: `node_modules/threedog/docs/recipes/10-blender-level.md` · `node_modules/threedog/docs/api/content.md`
|
|
29
|
-
- debug: `node_modules/threedog/docs/api/debug.md`
|
|
30
29
|
|
|
31
30
|
Not used yet (check these before writing the system yourself):
|
|
32
31
|
|
|
@@ -99,7 +98,7 @@ Code that breaks saves or manages world models: none (rule R33).
|
|
|
99
98
|
## Saves
|
|
100
99
|
|
|
101
100
|
- Save prefix saveKey: threedog-sheepisland
|
|
102
|
-
-
|
|
101
|
+
- Saved parts of the engine modules (vars, inventory, quests, timers, world...): `npx threedog catalog` (saves per module)
|
|
103
102
|
|
|
104
103
|
## Style pack keys
|
|
105
104
|
|
|
@@ -28,11 +28,11 @@ None yet, write them in `DESIGN.md` (why it is designed this way, what not to ch
|
|
|
28
28
|
- sky: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/sky.md`
|
|
29
29
|
- weather: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/weather.md`
|
|
30
30
|
- water: `node_modules/threedog/docs/recipes/44-water-weather-look-hooks.md` · `node_modules/threedog/docs/api/water.md`
|
|
31
|
-
- collision: `node_modules/threedog/docs/recipes/
|
|
31
|
+
- collision: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/collision.md`
|
|
32
32
|
- rigid: `node_modules/threedog/docs/recipes/11-vehicles.md` · `node_modules/threedog/docs/api/rigid.md`
|
|
33
33
|
- characters: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/characters.md`
|
|
34
34
|
- ambience: `node_modules/threedog/docs/recipes/31-audio.md` · `node_modules/threedog/docs/api/ambience.md`
|
|
35
|
-
- …
|
|
35
|
+
- …7 more modules: their pages are in `node_modules/threedog/docs/api/`
|
|
36
36
|
|
|
37
37
|
Not used yet (check these before writing the system yourself):
|
|
38
38
|
|
|
@@ -126,7 +126,7 @@ Code that breaks saves or manages world models: none (rule R33).
|
|
|
126
126
|
## Saves
|
|
127
127
|
|
|
128
128
|
- Save prefix saveKey: threedog-styletest
|
|
129
|
-
-
|
|
129
|
+
- Saved parts of the engine modules (vars, inventory, quests, timers, world...): `npx threedog catalog` (saves per module)
|
|
130
130
|
|
|
131
131
|
## Style pack keys
|
|
132
132
|
|
|
@@ -44,7 +44,7 @@ engine.assets.manifest(lowpolyAssets);
|
|
|
44
44
|
engine.assets.manifest({ name: 'styletest', models: { woodBlock, stoneBlock, metalBall, glassPanes, shadowStage, room } }); // the names content/templates.js uses
|
|
45
45
|
engine.characters.createPlayer({ ...presets.player.thirdPerson, spawn: { x: stage.x + 0.5, z: stage.z + 6 } });
|
|
46
46
|
engine.content.load(data, { places: { stage, water } });
|
|
47
|
-
if (params.env) { engine.
|
|
47
|
+
if (params.env) { engine.look.env.replace('sky'); engine.look.env.set({ intensity: 0.8 }); engine.sky.modify('env', { ambient: 0.6 }); } // soft ambient from the sky: lower the hemisphere ambient so shadows stay
|
|
48
48
|
|
|
49
49
|
// ---------- 2. The room's lamp: emissive plus one pooled light, on from 18:00 to 06:00 ----------
|
|
50
50
|
const lampPos = [stage.x + 14, engine.surface(stage.x + 14, stage.z - 2) + 2.7, stage.z - 2];
|
|
@@ -58,7 +58,7 @@ export async function openPanel(engine, base) {
|
|
|
58
58
|
const env = pane.addFolder({ title: `环境照明 (${LIVE})` });
|
|
59
59
|
const applyEnv = () => {
|
|
60
60
|
const on = envState.on, opts = { source: 'sky', intensity: envState.intensity };
|
|
61
|
-
engine.sky.
|
|
61
|
+
(on ? (engine.look.env.replace('sky'), engine.look.env.set({ intensity: opts.intensity })) : engine.look.env.replace(false));
|
|
62
62
|
put(['sky', 'environment'], on ? opts : null);
|
|
63
63
|
};
|
|
64
64
|
env.addBinding(envState, 'on', { label: '开 on' }).on('change', applyEnv);
|
|
@@ -77,11 +77,11 @@ export async function openPanel(engine, base) {
|
|
|
77
77
|
for (const { name, enabled } of engine.post.list()) {
|
|
78
78
|
const h = engine.post.get(name), f = post.addFolder({ title: name, expanded: false });
|
|
79
79
|
const noteOf = () => notes.get(name) ?? notes.set(name, {}).get(name);
|
|
80
|
-
f.addBinding({ enabled }, 'enabled', { label: '开 on' }).on('change', e => { engine.post.
|
|
80
|
+
f.addBinding({ enabled }, 'enabled', { label: '开 on' }).on('change', e => { engine.look.post.set({ [name + '.enabled']: e.value }); noteOf().enabled = e.value; });
|
|
81
81
|
for (const [k, v] of Object.entries(h.params)) {
|
|
82
82
|
if (typeof v !== 'number' && typeof v !== 'boolean') continue; // lut textures, functions...: not editable here
|
|
83
83
|
const range = typeof v === 'number' ? { step: Math.abs(v) >= 10 ? 1 : 0.01, min: Math.min(0, v * 2), max: Math.max(1, v * 3) } : {};
|
|
84
|
-
f.addBinding({ [k]: v }, k, range).on('change', e => {
|
|
84
|
+
f.addBinding({ [k]: v }, k, range).on('change', e => { engine.look.post.set({ [name + '.' + k]: e.value }); noteOf()[k] = e.value; });
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
|
|
@@ -35,11 +35,11 @@ Content: actions 4 · audio 3 · containers 1 · dialogues 1 · items 4 · npcs
|
|
|
35
35
|
- sky: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/sky.md`
|
|
36
36
|
- weather: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/weather.md`
|
|
37
37
|
- water: `node_modules/threedog/docs/recipes/44-water-weather-look-hooks.md` · `node_modules/threedog/docs/api/water.md`
|
|
38
|
-
- collision: `node_modules/threedog/docs/recipes/
|
|
38
|
+
- collision: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/collision.md`
|
|
39
39
|
- rigid: `node_modules/threedog/docs/recipes/11-vehicles.md` · `node_modules/threedog/docs/api/rigid.md`
|
|
40
40
|
- characters: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/characters.md`
|
|
41
41
|
- ambience: `node_modules/threedog/docs/recipes/31-audio.md` · `node_modules/threedog/docs/api/ambience.md`
|
|
42
|
-
- …
|
|
42
|
+
- …12 more modules: their pages are in `node_modules/threedog/docs/api/`
|
|
43
43
|
|
|
44
44
|
Not used yet (check these before writing the system yourself):
|
|
45
45
|
|
|
@@ -161,7 +161,7 @@ Code that breaks saves or manages world models: none (rule R33).
|
|
|
161
161
|
- Save prefix saveKey: default
|
|
162
162
|
- Save slots: slot1
|
|
163
163
|
- Autosave: every 3 minutes
|
|
164
|
-
-
|
|
164
|
+
- Saved parts of the engine modules (vars, inventory, quests, timers, world...): `npx threedog catalog` (saves per module)
|
|
165
165
|
|
|
166
166
|
## Style pack keys
|
|
167
167
|
|
package/index.d.ts
CHANGED
|
@@ -227,6 +227,33 @@ export function ease(e: Ease): (t: number) => number;
|
|
|
227
227
|
* @example checkOptions('stamina()', opts, ['max', 'drain', 'regen']);
|
|
228
228
|
*/
|
|
229
229
|
export function checkOptions(where: string, opts: object | null | undefined, known: string[], flags?: { loose?: boolean }): void;
|
|
230
|
+
/** One field of a params / op args schema: 'int?' or the full form (default implies optional) */
|
|
231
|
+
export type ParamSpec = string | { type: string, default?: any, min?: number, max?: number, values?: any[], desc?: string, optional?: boolean };
|
|
232
|
+
/**
|
|
233
|
+
* Module options read through a params schema: unknown keys and wrong types throw in dev with the fix, defaults are filled in.
|
|
234
|
+
* Also put params / options on the module definition so engine.catalog(name) shows them (recipes/51-capability-catalog.md).
|
|
235
|
+
* @example const o = readParams('magnet', { radius: { type: 'number', default: 2, min: 0 } }, opts);
|
|
236
|
+
*/
|
|
237
|
+
export function readParams<T extends object = any>(where: string, schema: Record<string, ParamSpec>, opts?: object): T;
|
|
238
|
+
/** One look part: engine.look.<id>. set changes parameters for an owner, patch swaps a named GLSL hook, replace takes the whole part over (recipes/52-look.md) */
|
|
239
|
+
export interface LookPart {
|
|
240
|
+
readonly id: string;
|
|
241
|
+
readonly object: any;
|
|
242
|
+
set(params: Record<string, any>, o?: { owner?: string }): { remove(): void };
|
|
243
|
+
patch(name: string, glsl: any, o?: { owner?: string }): { remove(): void };
|
|
244
|
+
replace(impl: any, o?: { owner?: string }): { remove(): void };
|
|
245
|
+
clear(owner: string): void;
|
|
246
|
+
value(key: string): any;
|
|
247
|
+
top(key: string): any;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Register a module's own look part: engine.look.<id> with set / patch / replace, engine.catalog('look.<id>') and describe().look (recipes/52-look.md).
|
|
251
|
+
* Every param needs a default; a default that changes the picture also needs why and off (or neutral: true).
|
|
252
|
+
*/
|
|
253
|
+
export function defineLookPart(engine: any, spec: { id: string, group?: string, module?: string, object?: () => any, params?: Record<string, any>,
|
|
254
|
+
style?: () => object, read?: () => object, apply?: (values: any, changed: Set<string>) => void, applyAtStart?: boolean,
|
|
255
|
+
hooks?: Record<string, { signature?: string, scope?: string[], example?: string }>, applyHook?: (name: string, glsl: any) => void, noPatch?: string,
|
|
256
|
+
replace?: { accepts: string, loses?: string[] }, applyReplace?: (impl: any) => void, noReplace?: string, docs?: string[] }): LookPart;
|
|
230
257
|
// The Character, NPC and Engine classes are exported by the export * above (tweens use engine.timeline.tween, pathfinding uses engine.characters.findPath)
|
|
231
258
|
|
|
232
259
|
/** Pure terrain computation (no engine needed), for previewing heights before start: createTerrain({ seed, ...terrainPreset() }).surface(x, z) */
|
package/index.js
CHANGED
|
@@ -58,7 +58,9 @@ export { terrain, vegetation, sky, weather, water, collision, rigid, followCamer
|
|
|
58
58
|
export { net, fakeNetwork, webSocket } from './modules/net/index.js';
|
|
59
59
|
export { screenToGround } from './core/screenToGround.js';
|
|
60
60
|
export { EASINGS, ease } from './core/easing.js';
|
|
61
|
-
export { checkOptions };
|
|
61
|
+
export { checkOptions };
|
|
62
|
+
export { defineLookPart } from './core/look/part.js'; // a module's own look part: engine.look.<id> with set / patch / replace, catalog and describe (recipes/52)
|
|
63
|
+
export { readParams } from './core/params.js'; // params schema for game-made modules: validated, defaults filled, shown by engine.catalog() // for game-made modules (recipes/14): the package exposes no core/* deep paths
|
|
62
64
|
export { createTerrain } from './modules/terrain/index.js';
|
|
63
65
|
export { Character, NPC } from './modules/characters/index.js';
|
|
64
66
|
export { presets } from './presets.js'; // opt-in gameplay presets (weather tables, calendars, player feel, camera): never applied by the engine itself
|
package/llms.txt
CHANGED
|
@@ -54,3 +54,8 @@ Reading order: docs/AI.md (the index: one line per task) -> the recipe for the t
|
|
|
54
54
|
- [45-cascaded-shadows](docs/recipes/45-cascaded-shadows.md): Cascaded shadows
|
|
55
55
|
- [46-blender-art-route](docs/recipes/46-blender-art-route.md): Hand-painted art route: from Blender to the game
|
|
56
56
|
- [47-island-snow-backdrop](docs/recipes/47-island-snow-backdrop.md): Floating island look: round rim, snow that settles, flat backdrop
|
|
57
|
+
- [48-make-material](docs/recipes/48-make-material.md): 48. `engine.makeMaterial(role, spec)`: which keys work, who wins
|
|
58
|
+
- [49-game-module-contract](docs/recipes/49-game-module-contract.md): Writing a game system module (crops, burning, a production machine) that plugs into the engine's contracts
|
|
59
|
+
- [50-own-renderer](docs/recipes/50-own-renderer.md): Bring your own renderer: `createEngine({ renderer })`
|
|
60
|
+
- [51-capability-catalog](docs/recipes/51-capability-catalog.md): Capability catalog: ask what the game can do before reading docs
|
|
61
|
+
- [52-look](docs/recipes/52-look.md): 52 Change any look: `engine.look`
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
import * as THREE from 'three';
|
|
20
20
|
import { checkOptions } from '../../core/validate.js';
|
|
21
|
+
import { readParams, keysSchema } from '../../core/params.js';
|
|
21
22
|
/** @import { ModuleDef, AmbienceRule } from '../../types/core' */
|
|
22
23
|
/** @import { AmbienceOptions } from '../../types/gameplay' */
|
|
23
24
|
const RULE_KEYS = ['sound', 'when', 'volume', 'fade', 'every', 'bus'];
|
|
@@ -160,6 +161,8 @@ const SYNTHS = {
|
|
|
160
161
|
},
|
|
161
162
|
};
|
|
162
163
|
|
|
164
|
+
const AMBIENCE_PARAMS = keysSchema(['rules', 'interval']);
|
|
165
|
+
|
|
163
166
|
/**
|
|
164
167
|
* Ambience -> engine.ambience. Rules come from createEngine({ audio: { ambience: [...] } }) plus opts.rules
|
|
165
168
|
* @param {AmbienceOptions} [opts]
|
|
@@ -167,10 +170,10 @@ const SYNTHS = {
|
|
|
167
170
|
* @example engine.use(ambience({ rules: [{ sound: 'hum', when: { zone: 'lab' }, volume: 0.4 }] }));
|
|
168
171
|
*/
|
|
169
172
|
export function ambience(opts = {}) {
|
|
173
|
+
readParams('ambience', AMBIENCE_PARAMS, opts);
|
|
170
174
|
let a = null;
|
|
171
|
-
return { name: 'ambience', label: 'Ambience', stage: 'late', presentation: true,
|
|
175
|
+
return { name: 'ambience', params: AMBIENCE_PARAMS, options: opts, label: 'Ambience', stage: 'late', presentation: true,
|
|
172
176
|
install(e) {
|
|
173
|
-
checkOptions('ambience()', opts, ['rules', 'interval']);
|
|
174
177
|
for (const [name, fn] of Object.entries(SYNTHS)) e.audio.register(name, fn, { builtIn: true, bus: 'ambience' });
|
|
175
178
|
a = new Ambience(e, opts);
|
|
176
179
|
// measures for data rules (content packs hold no functions). Each reads the listener position itself: music rules call them too,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// - Mobile: drag to turn
|
|
4
4
|
// - Slight vertical bob while walking (headBob), can be turned off
|
|
5
5
|
// - hideTarget: hide the followed character from the camera (no seeing inside your own body); the shadow stays
|
|
6
|
-
// Cutscene takeover:
|
|
6
|
+
// Cutscene takeover: while someone holds engine.takeCamera (engine.cameraOverride is not null) the camera is left alone (see common.js).
|
|
7
7
|
//
|
|
8
8
|
// engine.use(firstPersonCamera({ height: 1.6, sensitivity: 1, fov: 70, headBob: 0.04, pointerLock: true }));
|
|
9
9
|
// engine.cameraRig.yaw = Math.PI; // set facing directly
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
// engine.setCamera('follow'); // switch back to third person at runtime (mouse lock releases, body shows again); see recipes/21-camera.md
|
|
12
12
|
import * as THREE from 'three';
|
|
13
13
|
import { rigModule, defineRig, YAW_RIG, clickToLock, releaseLock } from './common.js';
|
|
14
|
-
import { checkOptions } from '../../core/validate.js';
|
|
15
14
|
import { vec3 } from '../../core/math.js';
|
|
16
15
|
|
|
17
16
|
export class FirstPersonCamera {
|
|
@@ -127,7 +126,6 @@ Object.assign(FirstPersonCamera.prototype, YAW_RIG); // forward / right / focu
|
|
|
127
126
|
*/
|
|
128
127
|
export function firstPersonCamera(opts = {}) { return rigModule('firstPerson', opts); }
|
|
129
128
|
defineRig('firstPerson', (e, opts) => {
|
|
130
|
-
checkOptions('firstPersonCamera()', opts, ['height', 'sensitivity', 'fov', 'headBob', 'bobFrequency', 'hideTarget', 'hideLayer', 'pointerLock', 'yaw', 'pitch',
|
|
131
|
-
'minPitch', 'maxPitch', 'yawLimits', 'smoothing', 'invertY', 'swallowLockClick']);
|
|
132
129
|
return new FirstPersonCamera(e, opts);
|
|
133
|
-
}
|
|
130
|
+
}, ['height', 'sensitivity', 'fov', 'headBob', 'bobFrequency', 'hideTarget', 'hideLayer', 'pointerLock', 'yaw', 'pitch',
|
|
131
|
+
'minPitch', 'maxPitch', 'yawLimits', 'smoothing', 'invertY', 'swallowLockClick']);
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// and a tag 'camera:<shot name>' switches to that shot (triggerBlend decides how)
|
|
5
5
|
// - A shot can look at a fixed point (lookAt) or turn with the player via track: true
|
|
6
6
|
// - Movement direction follows the current view: pressing "up" walks into the screen. If a direction key is still held at a shot change, the old direction is kept until release
|
|
7
|
-
// Cutscene takeover:
|
|
7
|
+
// Cutscene takeover: while someone holds engine.takeCamera (engine.cameraOverride is not null) the camera is left alone (see common.js).
|
|
8
8
|
//
|
|
9
9
|
// engine.use(fixedCamera({
|
|
10
10
|
// shots: {
|
|
@@ -16,19 +16,23 @@
|
|
|
16
16
|
// engine.cameraRig.blend('garden', 1.5);
|
|
17
17
|
import * as THREE from 'three';
|
|
18
18
|
import { rigModule, defineRig, viewForward, rightOf } from './common.js';
|
|
19
|
+
import { setProjection } from './projection.js';
|
|
19
20
|
import { vec3 } from '../../core/math.js';
|
|
20
21
|
import { ease as easing } from '../../core/easing.js';
|
|
21
22
|
import { checkOptions, warnMissing } from '../../core/validate.js';
|
|
22
23
|
|
|
23
24
|
export class FixedCamera {
|
|
24
25
|
/**
|
|
25
|
-
* shots { name: { position, lookAt | track: true, fov, at, trackHeight } }
|
|
26
|
+
* shots { name: { position, lookAt | track: true, fov, at, trackHeight, projection: 'orthographic', size } } (size: world units of view height; default perspective);
|
|
27
|
+
* single-shot shorthand: fixedCamera({ position, lookAt, projection, size }); start initial shot;
|
|
26
28
|
* auto false | 'nearest' (every autoInterval seconds pick the nearest shot); hysteresis how many meters closer a new shot must be to win (avoids flip-flopping);
|
|
27
29
|
* triggerBlend transition seconds for trigger-zone switches (0 = hard cut); trackHeight how high on the character a track shot looks; trackSmoothing head-tracking smoothness;
|
|
28
30
|
* holdDirection keep the direction at a shot change until the key is released (classic fixed-camera controls)
|
|
29
31
|
*/
|
|
30
32
|
constructor(engine, { shots = {}, start = null, auto = false, autoInterval = 0.25, hysteresis = 2, triggerBlend = 0,
|
|
31
|
-
trackHeight = 1.2, trackSmoothing = 8, holdDirection = true, ease = 'inOutCubic' } = {}) {
|
|
33
|
+
trackHeight = 1.2, trackSmoothing = 8, holdDirection = true, ease = 'inOutCubic', ...rest } = {}) {
|
|
34
|
+
if (!Object.keys(shots).length && rest.position) shots = { main: rest }; // setCamera('fixed', { position, lookAt, projection, size })
|
|
35
|
+
else checkOptions('fixedCamera()', rest, []);
|
|
32
36
|
Object.assign(this, { engine, auto, autoInterval, hysteresis, triggerBlend, trackHeight, trackSmoothing, holdDirection, ease });
|
|
33
37
|
this.shots = {};
|
|
34
38
|
for (const [n, s] of Object.entries(shots)) this.add(n, s);
|
|
@@ -49,10 +53,11 @@ export class FixedCamera {
|
|
|
49
53
|
|
|
50
54
|
/** Add or replace a shot */
|
|
51
55
|
add(name, s) {
|
|
52
|
-
checkOptions(`fixedCamera shots.${name}`, s, ['position', 'lookAt', 'track', 'fov', 'at', 'trackHeight']);
|
|
56
|
+
checkOptions(`fixedCamera shots.${name}`, s, ['position', 'lookAt', 'track', 'fov', 'at', 'trackHeight', 'projection', 'size']);
|
|
57
|
+
if (s.projection === 'orthographic' && !(s.size > 0)) throw new Error(`fixedCamera shots.${name}: projection 'orthographic' needs size > 0 (world units of view height)`);
|
|
53
58
|
this.shots[name] = {
|
|
54
59
|
position: vec3(s.position), lookAt: s.lookAt ? vec3(s.lookAt) : null, track: !!s.track || !s.lookAt,
|
|
55
|
-
fov: s.fov ?? null, at: s.at ? vec3(s.at) : null, trackHeight: s.trackHeight,
|
|
60
|
+
fov: s.fov ?? null, size: s.projection === 'orthographic' ? s.size : null, at: s.at ? vec3(s.at) : null, trackHeight: s.trackHeight,
|
|
56
61
|
};
|
|
57
62
|
return this;
|
|
58
63
|
}
|
|
@@ -64,7 +69,7 @@ export class FixedCamera {
|
|
|
64
69
|
this.current = name;
|
|
65
70
|
this._blend?.res(); this._blend = null; // interrupt a running blend: its Promise still resolves (await blend() never hangs)
|
|
66
71
|
this._lookTarget(s, this._look);
|
|
67
|
-
this._place(s.position, this._look, s.fov ?? this._baseFov);
|
|
72
|
+
this._place(s.position, this._look, s.fov ?? this._baseFov, s.size);
|
|
68
73
|
if (changed) { this._latchDirection(); this.engine.events.emit('camera:shot', { name }); }
|
|
69
74
|
}
|
|
70
75
|
/** Blend smoothly to a shot; returns a Promise that resolves when the blend ends */
|
|
@@ -74,7 +79,7 @@ export class FixedCamera {
|
|
|
74
79
|
const cam = this.engine.camera;
|
|
75
80
|
return new Promise(res => {
|
|
76
81
|
this._blend?.res();
|
|
77
|
-
this._blend = { from: cam.position.clone(), fromLook: this._look.clone(), fromFov: cam.fov, t: 0, dur: seconds, ease, res };
|
|
82
|
+
this._blend = { from: cam.position.clone(), fromLook: this._look.clone(), fromFov: cam.fov, fromSize: cam.orthoSize || null, t: 0, dur: seconds, ease, res };
|
|
78
83
|
this.current = name;
|
|
79
84
|
this._latchDirection();
|
|
80
85
|
this.engine.events.emit('camera:shot', { name });
|
|
@@ -105,12 +110,13 @@ export class FixedCamera {
|
|
|
105
110
|
const sh = this.shots[this.current];
|
|
106
111
|
const pos = (this._bp ??= new THREE.Vector3()).copy(b.from).lerp(sh.position, k), look = (this._bl ??= new THREE.Vector3()).copy(b.fromLook).lerp(want, k);
|
|
107
112
|
this._look.copy(look);
|
|
108
|
-
|
|
113
|
+
// size blends only between two orthographic shots; a perspective/orthographic mix switches to the target's mode at once
|
|
114
|
+
this._place(pos, look, b.fromFov + (fov - b.fromFov) * k, sh.size && b.fromSize ? b.fromSize + (sh.size - b.fromSize) * k : sh.size);
|
|
109
115
|
if (b.t >= b.dur) { this._blend = null; b.res(); }
|
|
110
116
|
} else {
|
|
111
117
|
if (this.shots[this.current].track) this._look.lerp(want, 1 - Math.exp(-this.trackSmoothing * dt));
|
|
112
118
|
else this._look.copy(want);
|
|
113
|
-
this._place(this.shots[this.current].position, this._look, fov);
|
|
119
|
+
this._place(this.shots[this.current].position, this._look, fov, s.size);
|
|
114
120
|
}
|
|
115
121
|
// Direction: release the hold once no direction key is pressed
|
|
116
122
|
const a = input.axis;
|
|
@@ -131,9 +137,10 @@ export class FixedCamera {
|
|
|
131
137
|
if (this.target) { out.copy(this.target.position); out.y += s.trackHeight ?? this.trackHeight; return out; }
|
|
132
138
|
return s.lookAt ? out.copy(s.lookAt) : out.set(s.position.x, s.position.y, s.position.z - 1);
|
|
133
139
|
}
|
|
134
|
-
_place(pos, look, fov) {
|
|
140
|
+
_place(pos, look, fov, size = null) {
|
|
135
141
|
const cam = this.engine.camera;
|
|
136
142
|
cam.position.copy(pos); cam.lookAt(look);
|
|
143
|
+
setProjection(cam, size ? 'orthographic' : 'perspective', size);
|
|
137
144
|
if (Math.abs(cam.fov - fov) > 1e-3) { cam.fov = fov; cam.updateProjectionMatrix(); }
|
|
138
145
|
}
|
|
139
146
|
_latchDirection() {
|
|
@@ -150,6 +157,6 @@ export class FixedCamera {
|
|
|
150
157
|
*/
|
|
151
158
|
export function fixedCamera(opts = {}) { return rigModule('fixed', opts); }
|
|
152
159
|
defineRig('fixed', (e, opts) => {
|
|
153
|
-
checkOptions('fixedCamera()', opts, ['shots', 'start', 'auto', 'autoInterval', 'hysteresis', 'triggerBlend', 'trackHeight', 'trackSmoothing', 'holdDirection', 'ease']);
|
|
154
160
|
return new FixedCamera(e, opts);
|
|
155
|
-
}
|
|
161
|
+
}, ['shots', 'start', 'auto', 'autoInterval', 'hysteresis', 'triggerBlend', 'trackHeight', 'trackSmoothing', 'holdDirection', 'ease',
|
|
162
|
+
'position', 'lookAt', 'track', 'fov', 'projection', 'size', 'at']); // the last row: setCamera('fixed', { position, lookAt }) is a one-shot form
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// optional shoulder offset and lock-on framing.
|
|
3
3
|
// yaw is which side of the focus the camera sits on: camera = focus + (sin yaw, cos yaw) * distance, so it looks along forward() = -(sin yaw, cos yaw).
|
|
4
4
|
// To see a character facing angle f from behind, yaw = f + PI.
|
|
5
|
-
// Cutscene takeover:
|
|
5
|
+
// Cutscene takeover: while someone holds engine.takeCamera (engine.cameraOverride is not null) the camera is left alone (see common.js).
|
|
6
6
|
// Other cameras: firstPersonCamera, fixedCamera, rtsCamera (top-down strategy); all are engine.cameraRig; switch at runtime with engine.setCamera('firstPerson').
|
|
7
7
|
import * as THREE from 'three';
|
|
8
8
|
import { rigModule, defineRig, YAW_RIG, clickToLock, releaseLock } from './common.js';
|
|
9
|
-
import {
|
|
9
|
+
import { setProjection } from './projection.js';
|
|
10
10
|
|
|
11
11
|
export class FollowCamera {
|
|
12
12
|
/** yaw/pitch initial angles (yaw: see the top of this file); distance (min/max zoom range); height how high on the character to look; smoothing follow smoothness;
|
|
@@ -14,7 +14,9 @@ export class FollowCamera {
|
|
|
14
14
|
* shoulder meters to the right of the target the camera aims (over-the-shoulder; negative = left shoulder, 0 = centered);
|
|
15
15
|
* pointerLock click locks the mouse (no dragging; the press that locks is swallowed, swallowLockClick: false delivers it) */
|
|
16
16
|
constructor(engine, { yaw = 0.8, pitch = 0.42, distance = 13, minDistance = 4, maxDistance = 45, height = 1.4, smoothing = 10,
|
|
17
|
-
sensitivity = 1, minPitch = 0.05, maxPitch = 1.35, zoomStep = 0.1, groundClearance = 1.2, invertY = false, shoulder = 0, pointerLock = false, swallowLockClick = true } = {}) {
|
|
17
|
+
sensitivity = 1, minPitch = 0.05, maxPitch = 1.35, zoomStep = 0.1, groundClearance = 1.2, invertY = false, shoulder = 0, pointerLock = false, swallowLockClick = true, projection = 'perspective', size = 20 } = {}) {
|
|
18
|
+
this.projection = projection; this.size = size; // 'orthographic': size = world units of view height (the wheel changes size there, clamped to the min/max distance ratio)
|
|
19
|
+
this.size0 = size; this.distance0 = distance;
|
|
18
20
|
Object.assign(this, { engine, yaw, pitch, distance, minDistance, maxDistance, height, smoothing, sensitivity, minPitch, maxPitch, zoomStep, groundClearance });
|
|
19
21
|
Object.assign(this, { invertY, shoulder, pointerLock, swallowLockClick });
|
|
20
22
|
this.target = null;
|
|
@@ -35,7 +37,7 @@ export class FollowCamera {
|
|
|
35
37
|
* @example engine.cameraRig.frame(enemy.object); player.faceMode = 'target'; player.faceTarget = enemy.object;
|
|
36
38
|
*/
|
|
37
39
|
frame(target, { strength = 6 } = {}) { this.framing = target ? { target, strength } : null; }
|
|
38
|
-
onEnter(switched) { clickToLock(this, switched); }
|
|
40
|
+
onEnter(switched) { clickToLock(this, switched); setProjection(this.engine.camera, this.projection, this.size); }
|
|
39
41
|
onExit() { releaseLock(this); }
|
|
40
42
|
onOverride(on) { if (on) releaseLock(this, true); }
|
|
41
43
|
|
|
@@ -49,7 +51,12 @@ export class FollowCamera {
|
|
|
49
51
|
if (input.enabled) {
|
|
50
52
|
if (!fr) this.yaw -= input.look.dx * 0.005 * this.sensitivity;
|
|
51
53
|
if (!this.lockPitch) this.pitch = Math.min(this.maxPitch, Math.max(this.minPitch, this.pitch + input.look.dy * 0.004 * this.sensitivity * (this.invertY ? -1 : 1)));
|
|
52
|
-
if (input.look.zoom
|
|
54
|
+
if (input.look.zoom && this.projection === 'orthographic') {
|
|
55
|
+
// distance shows nothing in an orthographic view: zoom `size`, clamped to the same min/max ratio as distance, same wheel feel
|
|
56
|
+
const lo = this.size0 * this.minDistance / this.distance0, hi = this.size0 * this.maxDistance / this.distance0;
|
|
57
|
+
this.size = Math.min(hi, Math.max(lo, this.size * (1 + input.look.zoom * this.zoomStep)));
|
|
58
|
+
cam.orthoSize = this.size; cam.updateProjectionMatrix();
|
|
59
|
+
} else if (input.look.zoom) this.distance = Math.min(this.maxDistance, Math.max(this.minDistance, this.distance * (1 + input.look.zoom * this.zoomStep)));
|
|
53
60
|
}
|
|
54
61
|
if (!this.target) return;
|
|
55
62
|
const want = this.target.position;
|
|
@@ -79,7 +86,6 @@ Object.assign(FollowCamera.prototype, YAW_RIG);
|
|
|
79
86
|
*/
|
|
80
87
|
export function followCamera(opts = {}) { return rigModule('follow', opts); }
|
|
81
88
|
defineRig('follow', (e, opts) => {
|
|
82
|
-
checkOptions('followCamera()', opts, ['yaw', 'pitch', 'distance', 'minDistance', 'maxDistance', 'height', 'smoothing', 'sensitivity', 'minPitch', 'maxPitch',
|
|
83
|
-
'zoomStep', 'groundClearance', 'invertY', 'lockPitch', 'shoulder', 'pointerLock', 'swallowLockClick']);
|
|
84
89
|
const c = new FollowCamera(e, opts); if (opts.lockPitch) c.lockPitch = true; return c;
|
|
85
|
-
}
|
|
90
|
+
}, ['yaw', 'pitch', 'distance', 'minDistance', 'maxDistance', 'height', 'smoothing', 'sensitivity', 'minPitch', 'maxPitch',
|
|
91
|
+
'zoomStep', 'groundClearance', 'invertY', 'lockPitch', 'shoulder', 'pointerLock', 'swallowLockClick', 'projection', 'size']);
|
|
@@ -5,14 +5,13 @@
|
|
|
5
5
|
// - screenToGround(ndcX, ndcY) -> ground point under a screen point (for click-to-move and placing buildings)
|
|
6
6
|
// - After follow(object) the focus tracks it (done automatically when the player is created) and WASD goes to the character; manual drag/edge pan drops the follow (unless followLock: true)
|
|
7
7
|
// To not follow: call engine.cameraRig.follow(null) after creating the player, and WASD pans the camera
|
|
8
|
-
// Cutscene takeover:
|
|
8
|
+
// Cutscene takeover: while someone holds engine.takeCamera (engine.cameraOverride is not null) the camera is left alone (see common.js).
|
|
9
9
|
//
|
|
10
10
|
// engine.use(rtsCamera({ height: 30, angle: 0.95, panSpeed: 1, edgePan: true, bounds: { minX: -100, maxX: 100, minZ: -100, maxZ: 100 } }));
|
|
11
11
|
// const p = engine.cameraRig.screenToGround(engine.input.pointer.ndcX, engine.input.pointer.ndcY);
|
|
12
12
|
// engine.cameraRig.moveTo(position); // move the view somewhere; { instant: true } skips smoothing
|
|
13
13
|
import * as THREE from 'three';
|
|
14
14
|
import { rigModule, defineRig, screenToGround, CAMERA_STRINGS, YAW_RIG } from './common.js';
|
|
15
|
-
import { checkOptions } from '../../core/validate.js';
|
|
16
15
|
import { xzOf } from '../../core/math.js';
|
|
17
16
|
import { surfaceOr } from '../../core/ground.js';
|
|
18
17
|
|
|
@@ -127,8 +126,7 @@ for (const k of ['forward', 'right']) RtsCamera.prototype[k] = YAW_RIG[k];
|
|
|
127
126
|
*/
|
|
128
127
|
export function rtsCamera(opts = {}) { return rigModule('rts', opts); }
|
|
129
128
|
defineRig('rts', (e, opts) => {
|
|
130
|
-
checkOptions('rtsCamera()', opts, ['height', 'minHeight', 'maxHeight', 'angle', 'yaw', 'panSpeed', 'dragPan', 'edgePan', 'edgeSize', 'bounds', 'rotateKeys',
|
|
131
|
-
'rotateSpeed', 'zoomStep', 'smoothing', 'fov', 'followLock', 'start']);
|
|
132
129
|
e.i18n.add(CAMERA_STRINGS);
|
|
133
130
|
return new RtsCamera(e, opts);
|
|
134
|
-
}
|
|
131
|
+
}, ['height', 'minHeight', 'maxHeight', 'angle', 'yaw', 'panSpeed', 'dragPan', 'edgePan', 'edgeSize', 'bounds', 'rotateKeys',
|
|
132
|
+
'rotateSpeed', 'zoomStep', 'smoothing', 'fov', 'followLock', 'start']);
|