threedog 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +90 -0
- package/README.md +1 -1
- package/core/assets/Animator.js +41 -3
- package/core/assets/Assets.js +100 -24
- package/core/assets/assetEntry.js +73 -20
- package/core/assets/assetHot.js +68 -16
- package/core/assets/assetLoad.js +6 -6
- package/core/assets/assetLod.js +9 -2
- package/core/assets/assetManifest.js +12 -2
- package/core/assets/assetPart.js +54 -0
- package/core/assets/ik.js +271 -0
- package/core/assets/modelNeeds.js +37 -0
- package/core/assets/namedModel.js +102 -29
- package/core/assets/nodeVisibility.js +15 -0
- package/core/audio/Audio.js +36 -4
- package/core/audio/audioReverb.js +99 -0
- package/core/audio/audioRules.js +1 -1
- package/core/audio/audioVoice.js +1 -1
- package/core/base/Events.js +14 -4
- package/core/base/Random.js +1 -1
- package/core/base/Vars.js +1 -1
- package/core/base/docRef.js +51 -0
- package/core/base/errorCodes.js +178 -126
- package/core/base/errorHints.js +9 -7
- package/core/base/errors.js +25 -10
- package/core/base/events.generated.js +2 -0
- package/core/base/freeParts.js +76 -0
- package/core/base/math.js +28 -0
- package/core/base/sections.js +5 -5
- package/core/base/validate.js +31 -3
- package/core/engine/Engine.js +16 -6
- package/core/engine/Loading.js +5 -3
- package/core/engine/copies.js +1 -1
- package/core/engine/headlessLoad.js +4 -1
- package/core/engine/lifecycle.js +32 -16
- package/core/engine/loop.js +71 -27
- package/core/engine/moduleSlots.js +2 -2
- package/core/engine/moduleTypes.js +3 -3
- package/core/engine/modules.js +65 -39
- package/core/engine/page.js +6 -3
- package/core/engine/services.js +6 -5
- package/core/engine/startup.js +5 -5
- package/core/input/Input.js +28 -14
- package/core/input/inputContext.js +28 -16
- package/core/input/inputKeyboard.js +31 -3
- package/core/input/inputPad.js +4 -0
- package/core/input/inputPointer.js +2 -1
- package/core/input/inputSeat.js +1 -1
- package/core/inspect/Budget.js +109 -19
- package/core/inspect/DebugOverrides.js +28 -4
- package/core/inspect/Describe.js +17 -9
- package/core/inspect/Inspect.js +4 -2
- package/core/inspect/InspectMaterials.js +3 -1
- package/core/inspect/InspectPerf.js +19 -9
- package/core/inspect/InspectScene.js +32 -7
- package/core/inspect/MaterialInfo.js +19 -2
- package/core/inspect/UrlState.js +46 -27
- package/core/inspect/catalog.js +28 -9
- package/core/inspect/debugView.js +2 -1
- package/core/inspect/describeRender.js +25 -13
- package/core/inspect/describeText.js +14 -6
- package/core/inspect/lightWatch.js +1 -1
- package/core/inspect/metadata.generated.js +35 -17
- package/core/inspect/pictureChecks.js +148 -0
- package/core/inspect/pictureMenu.js +84 -0
- package/core/inspect/pictureWriters.js +26 -6
- package/core/inspect/textureBytes.js +12 -2
- package/core/inspect/toolDoor.js +2 -4
- package/core/ops/Ops.js +11 -4
- package/core/ops/holds.js +27 -10
- package/core/ops/opsAtomic.js +15 -7
- package/core/ops/opsGuard.js +2 -2
- package/core/ops/opsRun.js +8 -7
- package/core/ops/sharedPoint.js +72 -21
- package/core/ops/stacks.js +56 -16
- package/core/saves/SaveStore.js +9 -3
- package/core/saves/Saves.js +32 -23
- package/core/saves/saveApply.js +96 -44
- package/core/saves/saveIds.js +1 -1
- package/core/saves/saveVersions.js +7 -5
- package/core/saves/session.js +17 -8
- package/core/saves/stateReplace.js +34 -15
- package/core/scene/Rays.js +52 -10
- package/core/scene/Views.js +13 -7
- package/core/scene/adaptive.js +144 -21
- package/core/scene/drawOnly.js +17 -0
- package/core/scene/gameLights.js +44 -3
- package/core/scene/sceneMethods.js +13 -11
- package/core/scene/stepPoses.js +11 -3
- package/core/scene/targeting.js +5 -3
- package/core/scene/thingOps.js +1 -1
- package/core/scene/tier.js +15 -0
- package/core/stream/Batching.js +30 -7
- package/core/stream/Stream.js +26 -7
- package/core/stream/batchGroups.js +2 -2
- package/core/stream/chunkStream.js +7 -5
- package/core/stream/prepare.js +77 -0
- package/core/time/skip.js +3 -1
- package/core/time/time.js +4 -2
- package/docs/AI.md +82 -83
- package/docs/API.md +16 -16
- package/docs/CODEMAP.md +16 -11
- package/docs/COMMANDS.md +31 -33
- package/docs/CONVENTIONS.md +37 -49
- package/docs/MIGRATING-0.8.md +2 -2
- package/docs/MIGRATING-1.0.md +2 -2
- package/docs/THREE.md +28 -35
- package/docs/api/assets.md +3 -1
- package/docs/api/audio.md +4 -2
- package/docs/api/budget.md +5 -0
- package/docs/api/cameraRig.md +2 -2
- package/docs/api/characters.md +10 -8
- package/docs/api/collision.md +6 -4
- package/docs/api/engine.md +16 -16
- package/docs/api/events.md +3 -2
- package/docs/api/ground.md +6 -5
- package/docs/api/hud.md +4 -2
- package/docs/api/input.md +5 -5
- package/docs/api/particles.md +2 -1
- package/docs/api/photo.md +3 -0
- package/docs/api/post.md +7 -4
- package/docs/api/quests.md +2 -2
- package/docs/api/rays.md +1 -2
- package/docs/api/saves.md +7 -7
- package/docs/api/settings.md +2 -2
- package/docs/api/tools.md +3 -1
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -2
- package/docs/api/world.md +1 -1
- package/docs/recipes/01-new-game.md +16 -17
- package/docs/recipes/02-npc.md +22 -18
- package/docs/recipes/03-items-pickups.md +37 -35
- package/docs/recipes/04-quests.md +15 -10
- package/docs/recipes/05-props-bake.md +101 -95
- package/docs/recipes/06-clock-events.md +28 -28
- package/docs/recipes/07-flow-scenes-pause.md +29 -26
- package/docs/recipes/08-weather-sky.md +52 -64
- package/docs/recipes/09-materials-lights-models.md +26 -17
- package/docs/recipes/10-blender-level.md +15 -10
- package/docs/recipes/11-vehicles.md +12 -7
- package/docs/recipes/12-navmesh.md +44 -26
- package/docs/recipes/13-animation.md +56 -45
- package/docs/recipes/14-custom-module.md +21 -18
- package/docs/recipes/15-perf.md +61 -55
- package/docs/recipes/16-dev-bridge.md +23 -33
- package/docs/recipes/18-world.md +36 -42
- package/docs/recipes/19-shooting-picking.md +20 -15
- package/docs/recipes/20-content-actions-save.md +48 -56
- package/docs/recipes/21-camera.md +45 -54
- package/docs/recipes/22-shop-gold.md +12 -7
- package/docs/recipes/23-ops.md +25 -23
- package/docs/recipes/26-ui-parts.md +67 -47
- package/docs/recipes/27-net.md +12 -7
- package/docs/recipes/28-terrain.md +24 -21
- package/docs/recipes/29-grid.md +32 -27
- package/docs/recipes/30-templates.md +21 -20
- package/docs/recipes/31-audio.md +39 -22
- package/docs/recipes/32-action-game.md +19 -14
- package/docs/recipes/33-stream-sources.md +15 -11
- package/docs/recipes/34-environment-lighting.md +126 -70
- package/docs/recipes/35-picture-from-reference.md +8 -8
- package/docs/recipes/36-ground-plants.md +27 -21
- package/docs/recipes/40-scene.md +19 -28
- package/docs/recipes/43-shader-patches-surfaces.md +15 -12
- package/docs/recipes/44-water-weather-hooks.md +34 -31
- package/docs/recipes/45-cascaded-shadows.md +35 -26
- package/docs/recipes/46-blender-art-route.md +6 -1
- package/docs/recipes/49-game-module-contract.md +13 -8
- package/docs/recipes/50-own-renderer.md +6 -2
- package/docs/recipes/51-capability-catalog.md +15 -8
- package/docs/recipes/52-around-the-picture.md +34 -32
- package/docs/recipes/53-ground-up-close.md +6 -1
- package/docs/recipes/55-mods-time-wrap.md +27 -19
- package/docs/recipes/56-webgpu-tsl.md +74 -43
- package/docs/recipes/57-control.md +18 -13
- package/docs/recipes/58-input.md +26 -16
- package/docs/recipes/59-depth-post-effects.md +8 -3
- package/docs/recipes/60-judge-the-picture.md +9 -8
- package/docs/recipes/61-deploy.md +5 -0
- package/docs/recipes/62-picture-code.md +70 -79
- package/docs/recipes/63-third-person-start.md +47 -45
- package/docs/recipes/64-particles.md +22 -10
- package/docs/recipes/65-swarm.md +18 -13
- package/docs/recipes/66-common-tasks.md +38 -35
- package/examples/action/GAMEMAP.md +2 -3
- package/examples/action/main.js +3 -3
- package/examples/action/picture/lights.js +3 -1
- package/examples/perf-island/GAMEMAP.md +3 -3
- package/examples/perf-island/picture/lights.js +2 -1
- package/examples/plain-picture/GAMEMAP.md +1 -1
- package/examples/rc2d/GAMEMAP.md +1 -1
- package/examples/styletest/GAMEMAP.md +2 -2
- package/examples/styletest/main.js +1 -1
- package/examples/techniques/interior-light/README.md +3 -3
- package/examples/techniques/interior-light/interiorLight.js +2 -4
- package/examples/techniques/interior-light/picture/lights.js +2 -1
- package/examples/techniques/modular-building/picture/lights.js +3 -1
- package/examples/techniques/outlines-and-rim/picture/lights.js +3 -1
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/techniques/procedural-animation/main.js +1 -1
- package/examples/webgpu-tsl/GAMEMAP.md +1 -1
- package/examples/world/GAMEMAP.md +2 -3
- package/examples/world/art/humanoid.js +1 -1
- package/examples/world/main.js +6 -3
- package/index.d.ts +2 -2
- package/llms.txt +101 -0
- package/modules/ambience/Ambience.js +21 -5
- package/modules/calendar/index.js +9 -5
- package/modules/calendar/schedule.js +23 -8
- package/modules/camera/FirstPersonCamera.js +3 -1
- package/modules/camera/FollowCamera.js +10 -5
- package/modules/camera/RtsCamera.js +4 -3
- package/modules/camera/common.js +70 -8
- package/modules/camera/contract.js +1 -1
- package/modules/characters/Character.js +16 -10
- package/modules/characters/NPC.js +31 -19
- package/modules/characters/assetModel.js +14 -9
- package/modules/characters/astar.js +6 -1
- package/modules/characters/contract.js +2 -2
- package/modules/characters/index.js +34 -22
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +17 -2
- package/modules/characters/movers/simple.js +1 -1
- package/modules/characters/movers/support.js +16 -7
- package/modules/characters/npcAvoid.js +2 -2
- package/modules/characters/npcSim.js +3 -2
- package/modules/characters/pathAsync.js +24 -8
- package/modules/characters/pathJob.js +1 -1
- package/modules/characters/player.js +10 -9
- package/modules/characters/playerStrings.js +5 -5
- package/modules/characters/proceduralRig.js +5 -5
- package/modules/characters/useModel.js +6 -0
- package/modules/characters/walkTo.js +1 -1
- package/modules/collision/Collision.js +29 -18
- package/modules/collision/grid.js +22 -4
- package/modules/content/index.js +3 -1
- package/modules/content/loader.js +1 -1
- package/modules/content/models.js +82 -33
- package/modules/content/props.js +2 -1
- package/modules/content/rules.js +11 -5
- package/modules/content/templates.js +3 -3
- package/modules/content/words.js +2 -2
- package/modules/debug/DebugPanel.js +9 -9
- package/modules/flow/index.js +9 -6
- package/modules/gameplay/Dialogue.js +34 -20
- package/modules/gameplay/Interactions.js +19 -15
- package/modules/gameplay/Inventory.js +9 -4
- package/modules/gameplay/Quests.js +12 -10
- package/modules/gameplay/pickups.js +23 -11
- package/modules/grid/index.js +1 -1
- package/modules/grid/preview.js +2 -2
- package/modules/grid/tiles.js +1 -1
- package/modules/hlod/index.js +4 -1
- package/modules/hud/index.js +47 -10
- package/modules/hud/parts.js +28 -9
- package/modules/level/geometry.js +8 -3
- package/modules/level/index.js +10 -5
- package/modules/level/load.js +4 -2
- package/modules/lights/sources.js +1 -1
- package/modules/music/Music.js +22 -4
- package/modules/nav/index.js +20 -10
- package/modules/particles/Particles.js +31 -14
- package/modules/particles/effect.js +20 -5
- package/modules/particles/lit.js +72 -0
- package/modules/photo/Photo.js +72 -28
- package/modules/photo/pathTrace.js +106 -0
- package/modules/rigid/RigidBodies.js +23 -14
- package/modules/rigid/Vehicles.js +3 -13
- package/modules/rigid/sync.js +2 -1
- package/modules/settings/Settings.js +52 -20
- package/modules/settings/apply.js +23 -9
- package/modules/settings/sections.js +39 -6
- package/modules/settings/strings.js +2 -0
- package/modules/settings/view.js +19 -3
- package/modules/sky/dome.js +15 -3
- package/modules/sky/environment.js +28 -12
- package/modules/sky/fog.js +1 -1
- package/modules/sky/frame.js +6 -1
- package/modules/sky/shader.js +4 -3
- package/modules/sky/skyModule.js +8 -4
- package/modules/swarm/Swarm.js +1 -1
- package/modules/terrain/ChunkManager.js +61 -15
- package/modules/terrain/chunkJob.js +2 -2
- package/modules/terrain/index.js +20 -5
- package/modules/terrain/terrainEdit.js +8 -4
- package/modules/terrain/terrainTexture.js +4 -2
- package/modules/timeline/Timeline.js +4 -3
- package/modules/timeline/Tween.js +3 -0
- package/modules/timeline/letterbox.js +1 -0
- package/modules/triggers/index.js +36 -17
- package/modules/vegetation/Vegetation.js +81 -19
- package/modules/vegetation/densityMap.js +13 -8
- package/modules/vegetation/draw.js +147 -24
- package/modules/vegetation/groundChunks.js +20 -5
- package/modules/vegetation/index.js +3 -3
- package/modules/vegetation/modelGeometry.js +9 -4
- package/modules/water/Water.js +11 -8
- package/modules/weather/Weather.js +7 -2
- package/modules/weather/shaders.js +25 -5
- package/modules/weather/weatherDraw.js +20 -6
- package/modules/world/World.js +2 -1
- package/modules/world/index.js +2 -2
- package/modules/world/persist.js +6 -2
- package/modules/world/views.js +15 -2
- package/package.json +4 -1
- package/presets.js +5 -5
- package/render/PostFX.js +84 -41
- package/render/backend.js +137 -16
- package/render/cascades.js +3 -1
- package/render/cascades.tsl.js +2 -0
- package/render/daylight.js +7 -1
- package/render/detail.js +7 -4
- package/render/effects.js +27 -8
- package/render/fogLook.js +24 -0
- package/render/fuse.js +5 -2
- package/render/fx/detail.tsl.js +9 -7
- package/render/fx/index.js +7 -2
- package/render/fx/library.tsl.js +1 -0
- package/render/fx/lightShaft.tsl.js +114 -0
- package/render/fx/noise.tsl.js +25 -8
- package/render/fx/objectOrigin.tsl.js +39 -10
- package/render/fx/particles.tsl.js +23 -6
- package/render/fx/patchNodes.tsl.js +17 -12
- package/render/fx/pcss.tsl.js +51 -0
- package/render/fx/postWebGPU.tsl.js +89 -29
- package/render/fx/sky.tsl.js +3 -9
- package/render/fxNumbers.js +10 -4
- package/render/impostor.tsl.js +107 -0
- package/render/lighting.js +33 -1
- package/render/lightmap.js +42 -28
- package/render/lights.js +19 -3
- package/render/materials.js +6 -4
- package/render/mergeCommon.js +4 -1
- package/render/occlusion.js +14 -4
- package/render/patches.js +79 -41
- package/render/postRuns.js +32 -0
- package/render/postWebGL.js +97 -10
- package/render/probes.js +10 -14
- package/render/shaderErrors.js +2 -1
- package/render/shadowCache.tsl.js +33 -5
- package/render/shadows.js +42 -16
- package/render/slots.js +8 -5
- package/render/vertexInputs.js +52 -0
- package/types/core.d.ts +114 -46
- package/types/gameplay.d.ts +56 -23
- package/types/generated/core/audio/Audio.d.ts +27 -1
- package/types/generated/core/base/Random.d.ts +1 -1
- package/types/generated/core/input/Input.d.ts +6 -8
- package/types/generated/core/input/inputSeat.d.ts +1 -1
- package/types/generated/core/inspect/Budget.d.ts +26 -0
- package/types/generated/core/inspect/DebugOverrides.d.ts +0 -2
- package/types/generated/core/saves/Saves.d.ts +10 -7
- package/types/generated/core/saves/session.d.ts +8 -2
- package/types/generated/core/scene/Rays.d.ts +1 -3
- package/types/generated/modules/particles/Particles.d.ts +1 -1
- package/types/generated/modules/world/World.d.ts +2 -1
- package/types/generated/render/PostFX.d.ts +35 -9
- package/types/physics.d.ts +43 -11
- package/types/pixel.d.ts +1 -1
- package/types/tsl.d.ts +62 -1
- package/types/world.d.ts +12 -3
- package/ui/Focus.js +7 -5
- package/ui/Parts.js +1 -1
- package/ui/touchPart.js +6 -3
package/docs/THREE.md
CHANGED
|
@@ -24,9 +24,8 @@ yourself: `engine.plugins.add(import.meta.glob('./plugins/*.js', { eager: true }
|
|
|
24
24
|
|
|
25
25
|
## three.js idioms and who writes the value
|
|
26
26
|
|
|
27
|
-
Write the three.js first; it works.
|
|
28
|
-
|
|
29
|
-
explicit call); the full list is recipe 52 "Who writes it". The engine route is optional on top: `engine.mod(point, ...)` adds owners and layers where several
|
|
27
|
+
Write the three.js first; it works. What you need to know is which values the engine **writes on its own** (every frame or on a timer): a direct write
|
|
28
|
+
to one hands it to you (the engine stops and warns once with the explicit call); the full list is recipe 52 "Who writes it". Optional on top: `engine.mod(point, ...)` adds owners and layers where several
|
|
30
29
|
systems share a value (recipe 55); `engine.autoView.manual(key)` takes a value without the warning (`manual(key, false)` gives it back);
|
|
31
30
|
`engine.describe('picture').picture` says what three.js holds now; `describe().owned` who writes each engine-driven value now.
|
|
32
31
|
|
|
@@ -52,13 +51,14 @@ Contact shadows are no engine feature: `threedog examples pull contact-shadows`
|
|
|
52
51
|
|
|
53
52
|
## What the engine changes in three.js (Global changes)
|
|
54
53
|
Everything else in three is untouched. Every change below is listed in `describe().threePatches` (`{ id, what, scope, on, offable, lost }`);
|
|
55
|
-
an offable one is undone page-wide with `threePatches.off(id)` (`import { threePatches } from 'threedog'`)
|
|
56
|
-
|
|
54
|
+
an offable one is undone page-wide with `threePatches.off(id)` (`import { threePatches } from 'threedog'`) before creating the objects that should not
|
|
55
|
+
see it, for every engine on the page; `engine.dispose()` does not undo a change. A wrapper another library put on `Object3D.prototype.add` stays when `scene-add-hook` is turned off. `lost` says what stops working; a change that cannot be undone says why and `off` throws.
|
|
57
56
|
|
|
58
57
|
| id | Change | Effect on your code | Off |
|
|
59
58
|
|---|---|---|---|
|
|
60
59
|
| `occlusion-layers-test` | `layers.test` of a mesh `engine.occlusion` hides, an own property while it is hidden | `engine.camera` skips the mesh; every other camera, shadows and rays see it. `mask`, `visible` and clones stay yours | no; `engine.occlusion.enabled = false` removes it |
|
|
61
60
|
| `shadow-accessors` | `Mesh.prototype.customDepthMaterial / customDistanceMaterial` become accessors | Unassigned, they return a shadow material only for a mesh whose material carries a vertex-moving engine patch (wind), so its shadow sways too; otherwise `undefined` as in three. An assignment always wins | yes |
|
|
61
|
+
| `fog-linear` | `ShaderChunk.fog_pars_fragment`, `tonemapping_fragment` and `fog_fragment` (page-wide, WebGL) | Fog is mixed once, in linear space before the tone curve and the output encoding, on the canvas, under the composer and on WebGPU alike (three mixes after both, so far fog changed colour when the first effect turned on). Adds the GLSL helpers threedogFogColor and threedogFogFactor and the define `THREEDOG_FOG_DONE`; a material `fog` slot patch replaces this mix. A shader without the fog chunks keeps three's code | yes: `threePatches.off('fog-linear')` turns off only the engine's mix (distant fog mixes after tone mapping again); the helpers and the guard stay, so a fog slot patch keeps working |
|
|
62
62
|
| `node-setup-position` | `NodeMaterial.prototype.setupPosition` wrapped | WebGPU only: runs the engine's vertex-moving patches (wind) first; other node materials unchanged | yes |
|
|
63
63
|
| `scene-add-hook` | `Object3D.prototype.add / remove` wrapped (page-wide) | None to the call itself; the engine sees what enters and leaves its scene at any depth (adopting `scene.add`, cascades, cloud shadow, light counts). Another library wrapping the same methods stacks with it | yes (`scene.add` no longer adopted) |
|
|
64
64
|
| `mesh-material-accessor` | `material` on each object entering the engine's scene: an own get / set on that object (a class accessor, e.g. troika text, still runs) | In devtools `mesh.material` shows as an accessor; `mesh.material = other` works as in three and is seen | yes (new objects) |
|
|
@@ -66,14 +66,16 @@ that should not see it. It is page-wide: every engine on the page loses the chan
|
|
|
66
66
|
| `renderer-render` | `engine.renderer.render` (that instance only) wrapped | Counts your full-canvas draws so the engine yields the frame; a scissored / smaller-viewport / `autoClear = false` layer (minimap, HUD) does not count | yes |
|
|
67
67
|
| `shader-chunks` | `THREE.ShaderChunk.threedog_*` added (new names, nothing replaced) | None until you `#include` one | no (the engine's patches include them) |
|
|
68
68
|
| `light-idle-shadow` | `shadow.autoUpdate` of your shadow-casting point / spot lights: off while intensity is 0, back on when lit | Only lights whose autoUpdate was on; writing autoUpdate yourself hands the light back; `light.userData.idleShadow = false` opts one out; `describe().render.lights` shows `shadowIdled` | yes |
|
|
69
|
+
| `ray-bvh` | `geometry.boundsTree` and an own `mesh.raycast` on meshes of 256+ triangles in `engine.rays.addStatic` | Your `Raycaster` gets the BVH too; your own raycast is kept; the last unregister gives the raycast back and drops a tree the engine built | yes |
|
|
69
70
|
| `shadow-cache` | `light.shadow.shadowNode` of a light handed to `engine.shadows.cache`: a `ShadowNode` subclass with float depth, a second depth map and a draw filter | Only that light, only after the call; the handle's `remove()` puts three's node back |
|
|
70
71
|
| `batching-draw-walk` | `children` of a parent holding batched meshes: those meshes leave the array during the engine's own draw and come back right after | None outside the draw: your code, raycasts and `scene.traverse` see the scene as built. A scene change made inside a render (`onBeforeRender`) on such a parent is lost | yes (three walks every batched original twice a frame again) |
|
|
71
|
-
| `picture-writers` | Dev server only (
|
|
72
|
+
| `picture-writers` | Dev server only (not in bundles or release builds): an own get / set on the picture values of objects in the engine's scene (light intensity / color / position, `scene.fog` and its values, tone and exposure, environment, background, material color / emissive / opacity), on plain-property values in `describe().owned` (the camera, `view.far`, the shadow target), on values named with `engine.debug.watch`, and on the components of those colors, vectors and rotations | Reads and writes pass through unchanged; devtools shows accessors. A write records who made it for `describe('picture').writers` and `engine.explain({ value })` | yes: `threePatches.off('picture-writers')`, accessors stay and only pass values through |
|
|
72
73
|
| `post-shadow-hold` | `render` of the first pass of the WebGL post chain wrapped (it may be your own Pass) | None to what the pass draws; shadow maps redraw once a frame | yes |
|
|
73
74
|
| `post-background-tone` | `onBeforeRender` of three's own background mesh, while the engine draws straight to the canvas | A texture background is tone-mapped as it is through the post chain; your own `renderer.render` keeps three's rule | yes |
|
|
74
75
|
| `node-twin-dress` | `renderer.library.fromMaterial` of a WebGPURenderer wrapped | WebGPU only: the node twin of a classic material gets its patches | no (patched materials would lose their picture on WebGPU) |
|
|
75
76
|
| `node-builder-hook` | `renderer.debug.onNodeBuilderCreated` of a WebGPURenderer wrapped | WebGPU only: your own hook still runs; a later write of yours replaces the engine's | yes |
|
|
76
77
|
| `device-lost-hook` | `renderer.onDeviceLost` of a WebGPURenderer wrapped | WebGPU only: three's hook still runs; a later write of yours replaces the engine's | yes |
|
|
78
|
+
| `page-exit-pointer-lock` | `document.exitPointerLock` wrapped (one wrapper for all live engines, gone with the last) | a game-requested unlock reads as the player pressing Esc | yes |
|
|
77
79
|
| `occlusion-readback` | `resolveOccludedAsync` of the WebGPU backend (that one instance), once `engine.occlusion` is on | WebGPU only: an AbortError from a buffer destroyed with the renderer is dropped; any other error still reaches you | no (disposing an engine while occlusion answers are on their way would report an unhandled rejection) |
|
|
78
80
|
| `lod-view-camera` | `update` and `clone` of the `THREE.LOD` objects `assets.lod` and a prop's `lod` make | Only the engine camera moves the level, and far off the full model waits on the batch layer with `visible` still true, so rays reach it | yes |
|
|
79
81
|
| `webgpu-record-sweep` | A `'dispose'` event sent to objects drawn earlier that have left every Scene for a few seconds, found through WebGPURenderer's private record list | WebGPU only: your `'dispose'` listener on such an object runs; drawing it again rebuilds its record | yes |
|
|
@@ -97,7 +99,7 @@ that should not see it. It is page-wide: every engine on the page loses the chan
|
|
|
97
99
|
| Vehicles, navigation, character controller | `engine.rigid.addWheeled(mesh, ...)` returns `{ body, controller }`; `engine.nav.navMesh / query / tileCache / crowd` (they are destroyed and replaced on rebuild; code that caches them compares `engine.nav.version`); `engine.player.mover.controller` (mover: 'rapier') |
|
|
98
100
|
| glTF / compression decoders | `engine.assets.gltf` (GLTFLoader, Meshopt installed), `assets.draco` (DRACOLoader), `assets.ktx2` (KTX2Loader); the last two are created the first time compressed data is met and are null before that |
|
|
99
101
|
| Rays | `engine.raycast(origin, direction)` / `engine.pick(ndcX, ndcY)` return three hits (`object` is the mesh, `face` and `point` unchanged); `{ targets: 'all' }` hits rigid bodies too (the hit carries `entry` and `kind: 'rigid'`); the underlying `engine.rays.ray` (THREE.Raycaster, `firstHitOnly` on) |
|
|
100
|
-
| Ray acceleration (BVH) | three-mesh-bvh, without touching three's prototypes:
|
|
102
|
+
| Ray acceleration (BVH) | three-mesh-bvh, without touching three's prototypes: only on meshes in `engine.rays.addStatic` (`ray-bvh` above); every other mesh is plain three. Page-wide BVH for your rays: three-mesh-bvh's documented setup (`Mesh.prototype.raycast = acceleratedRaycast`, ...) |
|
|
101
103
|
| Streamed-in objects | `.object` of the handle returned by `engine.stream.add({ position, build })` (the Object3D that build returned; null before it is built) |
|
|
102
104
|
| Post-processing | `engine.post.add(pass)`, the one way in (a Pass, or an effect `{ name, slot, create: ctx => pass }` plus its twin for the other renderer, recipe 56; slots `scene` / `hdr` / `tone` / `ldr` / `final`; on / off and params with its handle); `engine.post.own()` hands over the whole chain |
|
|
103
105
|
| Where the mouse points | Ground: `screenToGround(engine, input.pointer.ndcX, ndcY)` -> Vector3; objects: `engine.pick(input.pointer.ndcX, ndcY)` (registered static objects; for any object pass `{ targets: [object] }`) |
|
|
@@ -107,34 +109,25 @@ Anywhere a position is accepted it is **one argument**: Vector3 / Object3D / `[x
|
|
|
107
109
|
|
|
108
110
|
## Engine conventions when using three.js
|
|
109
111
|
|
|
110
|
-
1. **Materials**: `new THREE.MeshStandardMaterial(...)` is the way
|
|
111
|
-
|
|
112
|
-
wind / clouds / season patches after it). The engine adds effects only to materials it made; yours opt in with `applyEffects(mat, { wind: 0.03 })`.
|
|
112
|
+
1. **Materials**: `new THREE.MeshStandardMaterial(...)` is the way. Your own shader code works as in three.js: TSL on WebGPU (recipe 56),
|
|
113
|
+
`ShaderMaterial` / `onBeforeCompile` on WebGL (table above). The engine adds effects only to materials it made; yours opt in with `applyEffects(mat, { wind: 0.03 })`.
|
|
113
114
|
One exception, named: with cascaded shadows on (`engine.shadows.cascades(light)`) every built-in lit material gets the `csm` patch, or it would
|
|
114
115
|
be lit N times; a lit `ShaderMaterial` of yours joins with `engine.shadows.include(mat)` (recipe 45).
|
|
115
|
-
2. **Adding to the scene**: `engine.scene.add(obj)`
|
|
116
|
-
is and what a save keeps). `engine.add(obj, { id })` is only for a stable id, so `thing.set` changes to it are saved (`recipes/40-scene.md`). To attach to a character use `player.root.add(hat)`.
|
|
116
|
+
2. **Adding to the scene**: `engine.scene.add(obj)` registers every root (`engine.thing(obj)` says what a save keeps); `engine.add(obj, { id })` only adds a stable id (`recipes/40-scene.md`). To attach to a character: `player.root.add(hat)`.
|
|
117
117
|
3. **Per-frame logic goes in `engine.onFrame(dt => ...)`** (movement and timing use `engine.onFixed`); it returns a handle, cancel with `h.remove()`.
|
|
118
|
-
Don't start your own `requestAnimationFrame` loop: the engine owns pausing, fast-forward in tests and ordering. Rendering the canvas
|
|
119
|
-
|
|
118
|
+
Don't start your own `requestAnimationFrame` loop: the engine owns pausing, fast-forward in tests and ordering. Rendering the whole canvas yourself takes the frame over
|
|
119
|
+
(post chain, adaptive resolution and photo mode stop applying); a render target of your own goes in `engine.onRender` (table above).
|
|
120
120
|
4. **Snap to ground**: get ground height with `engine.surface(x, z)`, or `engine.snapToGround(obj, heightAboveGround)`. Don't raycast the terrain.
|
|
121
121
|
**Rays** always go through `engine.raycast / pick`: level meshes are registered automatically; register your own static objects with
|
|
122
122
|
`engine.rays.addStatic(obj)` or `assets.model(name, { static: true })`.
|
|
123
|
-
5. **Deleting**:
|
|
124
|
-
|
|
125
|
-
`obj.removeFromParent()`. A copy from `assets.model()` shares resources with other copies (`remove` skips them); they are freed together by
|
|
126
|
-
`assets.release(name)`.
|
|
127
|
-
6. **The sky lights nothing**: it computes signals and draws the dome, and your `picture/` code writes the lights, the fog and the exposure (recipe 62); weather gives `uWeatherLight` / `uWeatherFog` to multiply in. Every engine-written value: recipe 52
|
|
128
|
-
"Who writes it". Adding your own point lights (street lamps, campfires) is fine.
|
|
123
|
+
5. **Deleting**: `engine.remove(obj)` (recipe 05 §5; it also unregisters rays). A copy from `assets.model()` shares resources with other copies (`remove` skips them); `assets.release(name)` frees them together.
|
|
124
|
+
6. **The sky lights nothing**: it computes signals and draws the dome; your `picture/` code writes lights, fog and exposure (recipe 62).
|
|
129
125
|
7. **Camera**: `engine.camera` is a three.js camera: change its properties, or assign your own real `THREE.PerspectiveCamera` or `THREE.OrthographicCamera` (`engine.camera = cam`, keep the old value to swap back). Rendering, post, picking, shadows, audio and an installed camera module all go on with it; any other class, a subclass too, is refused. Aspect, frustum and a rig's `projection`: recipe 21. `engine.setCamera('follow')` swaps the camera *module*, not the object. When a camera
|
|
130
126
|
module is installed it places the camera every frame; to control the view yourself take it with `const cam = engine.takeCamera('me')` and `cam.remove()` it
|
|
131
127
|
(`engine.cameraOverride` is read-only: it shows the holder in charge, or `null`).
|
|
132
128
|
8. Collision: the player only respects `engine.collision` (`addCircle / addBox / addObject(mesh)`); a mesh alone does not block anyone.
|
|
133
|
-
9. **Big code-generated things
|
|
134
|
-
`
|
|
135
|
-
`npm run bake` it reads the file.
|
|
136
|
-
Things needed only nearby use `engine.stream.add({ position, build })`; put long loops in `engine.jobs.add(function* () { ...; yield; })` so they
|
|
137
|
-
are spread over frames and the start does not stall.
|
|
129
|
+
9. **Big code-generated things**: a generator in the manifest, fetched by name (recipe 05 §2). Things needed only nearby: `engine.stream.add({ position, build })`;
|
|
130
|
+
long loops: `engine.jobs.add(function* () { ...; yield; })`, spread over frames.
|
|
138
131
|
10. **One copy of the engine and of three per page**: `resolve: { dedupe: ['threedog', 'three'] }` in vite.config.js. A second engine copy
|
|
139
132
|
(a pack that lists threedog under `dependencies` instead of `peerDependencies`, a linked plus an installed copy) breaks shadows of wind and
|
|
140
133
|
cascaded-shadow materials; the engine warns once at load, naming both paths [engine-two-copies].
|
|
@@ -144,22 +137,22 @@ The same windmill as a template with an id, saved and editable without code, is
|
|
|
144
137
|
|
|
145
138
|
```js
|
|
146
139
|
import { THREE } from 'threedog';
|
|
147
|
-
const mill = new THREE.Group(), blades = new THREE.Group();
|
|
140
|
+
const mill = new THREE.Group(), blades = new THREE.Group(); // plain three.js: meshes and materials as usual
|
|
148
141
|
mill.add(blades);
|
|
149
142
|
mill.position.set(20, 0, -10);
|
|
150
|
-
engine.snapToGround(mill);
|
|
151
|
-
engine.scene.add(mill);
|
|
143
|
+
engine.snapToGround(mill); // snap to ground
|
|
144
|
+
engine.scene.add(mill); // registered like engine.add; engine.add(mill, { id: 'mill' }) also keeps thing.set changes in saves
|
|
152
145
|
engine.collision?.addCircle(mill, { radius: 1.3 }); // block the player (when the collision module is installed)
|
|
153
146
|
engine.onFrame(dt => { blades.rotation.z += dt * 1.5; });
|
|
154
147
|
```
|
|
155
148
|
|
|
156
149
|
## Example: your own rain (three.js drops, a plain call or a module)
|
|
157
|
-
`weather({ rain })` is there if it fits. Your own effect
|
|
150
|
+
`weather({ rain })` is there if it fits. Your own effect: three.js builds it, a call adds it, a module only when something must clean up or swap it.
|
|
158
151
|
|
|
159
152
|
```js
|
|
160
153
|
import { THREE } from 'threedog';
|
|
161
154
|
function makeRain({ count = 2000, area = 40, height = 20, speed = 18 } = {}) {
|
|
162
|
-
const pos = new Float32Array(count * 6);
|
|
155
|
+
const pos = new Float32Array(count * 6); // one short line per drop
|
|
163
156
|
for (let i = 0; i < count; i++) pos.set([(i * 0.618 % 1 - 0.5) * area, i * 0.31 % 1 * height, (i * 0.754 % 1 - 0.5) * area], i * 6);
|
|
164
157
|
const geo = new THREE.BufferGeometry().setAttribute('position', new THREE.BufferAttribute(pos, 3));
|
|
165
158
|
const drops = new THREE.LineSegments(geo, new THREE.LineBasicMaterial({ color: 0x9fb8d0, transparent: true, opacity: 0.5 }));
|
|
@@ -192,14 +185,14 @@ engine.use(rainEffect({ count: 4000 }));
|
|
|
192
185
|
The engine then does the rest: `engine.unuse('rain')`, a failed install or `{ replaces }` runs what `ctx.track` holds, and two modules of one name or two owners of one slot are refused with the fix. A value that others change too (rain slowing the player) goes through `ctx.mod`.
|
|
193
186
|
|
|
194
187
|
## Example: wet stone in rain (the engine gives the signal, the game decides)
|
|
195
|
-
The weather module knows how hard it rains
|
|
188
|
+
The weather module knows how hard it rains, not what your stone looks like wet or whether it is slick: that is the game's look and rule.
|
|
196
189
|
|
|
197
190
|
```js
|
|
198
191
|
import { THREE } from 'threedog';
|
|
199
192
|
const stone = new THREE.MeshStandardMaterial({ color: 0x777066, roughness: 0.9 });
|
|
200
|
-
engine.onFrame(() => { stone.roughness = 0.9 - 0.6 * engine.uniforms.uRain.value; });
|
|
193
|
+
engine.onFrame(() => { stone.roughness = 0.9 - 0.6 * engine.uniforms.uRain.value; }); // the look: the game's material reads the rain
|
|
201
194
|
|
|
202
|
-
let slick = null;
|
|
195
|
+
let slick = null; // the rule, if the game wants one: in game time, through the shared value
|
|
203
196
|
engine.onFixed(() => {
|
|
204
197
|
const wet = (engine.weather?.current.rain ?? 0) > 0.5 && engine.groundType(engine.player.position) === 'stone';
|
|
205
198
|
if (wet && !slick) slick = engine.mod('move.speed', { owner: 'wet-stone', id: 'player', mul: 0.8 });
|
|
@@ -218,14 +211,14 @@ import { mergeGeometries, mergeVertices } from 'three/addons/utils/BufferGeometr
|
|
|
218
211
|
import { SimplexNoise } from 'three/addons/math/SimplexNoise.js';
|
|
219
212
|
import { bakeVertexAO } from 'threedog';
|
|
220
213
|
|
|
221
|
-
const rng = engine.random.seeded(7), simplex = new SimplexNoise({ random: () => rng.next() });
|
|
214
|
+
const rng = engine.random.seeded(7), simplex = new SimplexNoise({ random: () => rng.next() }); // seeded noise: the same shape every load
|
|
222
215
|
// weld first, or the noise opens cracks; mergeVertices compares every attribute, so drop normal and uv (their seams would stay unwelded)
|
|
223
216
|
const rock = mergeVertices(new THREE.IcosahedronGeometry(1, 3).deleteAttribute('normal').deleteAttribute('uv'));
|
|
224
217
|
const p = rock.attributes.position, v = new THREE.Vector3();
|
|
225
218
|
for (let i = 0; i < p.count; i++) { v.fromBufferAttribute(p, i); v.multiplyScalar(1 + 0.25 * simplex.noise3d(v.x, v.y, v.z)); p.setXYZ(i, v.x, v.y, v.z); }
|
|
226
219
|
rock.computeVertexNormals();
|
|
227
220
|
const slab = new THREE.CylinderGeometry(1.2, 1.4, 0.3).translate(0, -0.9, 0).deleteAttribute('uv');
|
|
228
|
-
const model = mergeGeometries([rock, slab]);
|
|
221
|
+
const model = mergeGeometries([rock, slab]); // same attributes (position, normal), both indexed
|
|
229
222
|
bakeVertexAO(model, { samples: 32, strength: 0.7, occluders: [new THREE.PlaneGeometry(6, 6).rotateX(-Math.PI / 2).translate(0, -1.05, 0)] });
|
|
230
223
|
```
|
|
231
224
|
|
package/docs/api/assets.md
CHANGED
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
- `assets.model(nameOrUrl: string, opts?: { castShadow?, receiveShadow?, static? }) → Promise<Object3D>` — Get a model copy (name or path; geometry and materials are shared with other copies). static: true registers it in engine.rays (builds ray acceleration)
|
|
10
10
|
- `assets.lod(nameOrUrl: string, opts?: { distances?, hysteresis?, castShadow?, receiveShadow?, static? }) → Promise<import('three').LOD>` — (experimental) A model copy as a plain THREE.LOD: the full model near, the levels of `threedog assets optimize --lod` far away. Default distances follow the model's size; distances (rising meters) replace them, hysteresis is the share of a distance that stops flicker at the line (default 0.1). Rays, collision and saves keep using the full model. A LOD object is never batched. Without levels it warns in dev and draws in full. Example: `const tower = await engine.assets.lod('tower', { distances: [40, 120] }); engine.add(tower); tower.levels[1].object;`
|
|
11
11
|
- `assets.modelNow(nameOrUrl: string, opts?: { castShadow?, receiveShadow?, static? }) → Object3D | null` — (experimental) A model copy right now if it has already loaded, else null (never starts a load, never waits): lets code that rebuilds often skip the frame an await costs. Code-built models (a build function in the manifest) count too: they are null until one await model(name) or an entry with preload: true ran (dev warns [asset-not-loaded]). Example: `const m = engine.assets.modelNow('villager') ?? await engine.assets.model('villager');`
|
|
12
|
+
- `assets.onModel(fn: (model, name) => void) → { remove(): void }` — The game's setup for every model the engine hands out (assets.model / modelNow / lod, content props and templates, pickups, character bodies, a code-built vegetation model named in define, a level file): runs once per copy, before it is added or drawn. Synchronous; one per engine (a second throws); leaves the root's transform to its placer (dev throws). Copies share materials: map each original to one of yours. Example: `const mine = new Map(); engine.assets.onModel(m => m.traverse(o => { if (o.isMesh) o.material = mine.get(o.material) ?? mine.set(o.material, myLook(o.material)).get(o.material); }));`
|
|
12
13
|
- `assets.geometry(nameOrUrl: string) → Promise<BufferGeometry>` — Get the geometry of the first mesh in a model
|
|
13
14
|
- `assets.gridFromImage(nameOrUrl: string, opts?: { channel?, range?, bits? }) → Promise<{ data: Float32Array; wid…` — An image as grid data for sampleGrid: PNG at 8 or 16 bits (jpg / webp 8). channel 'r' (default) 'g' 'b' 'a' or 0-3; range maps pixels to [min, max] (default [0, 1])
|
|
14
15
|
- `assets.texture(nameOrUrl: string, opts?: { color?, pixelated?, repeat? }) → Promise<Texture>` — Get a texture (.ktx2 compressed textures also work)
|
|
15
16
|
- `assets.useTexture(nameOrUrl: string, use: (texture: Texture) => void, o?: { where?, instead?, opts? }) → Promise<boolean>` — Fetch a texture for something that already shows a stand-in: use(texture) runs when it arrives; a failed load is one asset-load dev warning naming `where` and what shows `instead`, and resolves false (an error inside use() is not swallowed). opts are texture()'s options
|
|
16
17
|
- `assets.release(name: string)` — Release a resource and return its memory. Not released while copies of the model are still in the scene; it is released when the last copy is removed with engine.remove. A sound (name or path) plays on where it is playing and loads again on next use. A load still running ends and its result is thrown away; code awaiting it gets a fresh load, never freed data. A name that fell back holds no data of its own: release the name it fell back to
|
|
17
18
|
- `assets.trim() → string[]` — Release every model that has no copy in use and every long decoded sound (music, long loops; short effects stay; a sound still playing plays on), unless marked preload (called automatically after level changes). Models whose shared geometry was taken by geometry() and code-generated models are not released automatically. Returns the released names
|
|
18
|
-
- `assets.forget(obj: Object3D)` — (experimental) Called when an object is fully removed (engine.remove already calls it, normally you don't need to): decrements the use count of the model copies under it
|
|
19
19
|
- `assets.animate(root: Object3D, config?: AnimatorOptions) → Animator` — Create an animation state machine for a skinned model (without config it is simple play-by-name). A copy of a manifest model whose entry has `animation` starts from that mapping; config wins per state
|
|
20
20
|
- `assets.mapping(root: Object3D) → AnimatorOptions | null` — The manifest entry's animation mapping for a model copy, or null (not a manifest copy, or no mapping)
|
|
21
21
|
- `assets.report(nameOrRoot: string | Object3D) → AssetReport` — Import report of a loaded model (by name, or a copy from model()): materials, textures with colorSpace, clips, colliders, templates, and issues for what the file has but the scene lost
|
|
@@ -63,4 +63,6 @@
|
|
|
63
63
|
- `sync(state: string | null, t?: number) → any` — Gameplay drives the clock: show state at gameplay time t (fixed-step seconds) through its timing. The clip never advances or ends by itself and go() leaves it alone; sync(null) hands control back
|
|
64
64
|
- `describe() → AnimatorInfo` — What is showing: state, clip, clip time, progress, driven, weights
|
|
65
65
|
- `check(actions?: string[]) → string[]` — Check the mapping against the action names the game plays: each problem as text with its fix ([] = all will play). Example: `anim.check(['idle', 'walk', 'attack', 'hurt'])`
|
|
66
|
+
- `addAim(opts: { bones, target?, limit?, speed?, weight?, fade?, … }) → AimLayer` — Look-at IK, the last layer on the clips: a bone or a chain from the body out turns toward target, within limit degrees of the animated pose. Weight 0 leaves the pose exactly; target null looks ahead; forward: the last bone's own front axis when the bind pose does not say (recipe 13 §3e). Example: `const look = npc.anim.addAim({ bones: ['Neck', 'Head'], target: engine.player.root, limit: 70 });`
|
|
67
|
+
- `addFeet(opts?: { legs?, hips?, reach?, far?, speed?, weight?, … }) → FeetLayer` — Feet on the ground: each [upper, lower, foot] leg bends onto the model's own ground (a Character's includes platforms; off while it jumps or swims, beyond far from the camera, while hidden); the hips lower for the foot that reaches down. legs: bone names when they are not recognised. Example: `const feet = engine.player.anim.addFeet();`
|
|
66
68
|
- `dispose()` — Stop the per-frame update when no longer needed
|
package/docs/api/audio.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
- `audio.addBus(name: string, opts?: { level?: number; owner?: string }) → { owner?: string; remove(): void }` — Add a bus of your own (routed to master). It gets a settings slider like the others (label key settings.vol.<name>) until the handle is removed (the one give-back form, like every other handle). A name that is already a bus throws: two owners of one bus could not both remove it. Example: `const voice = engine.audio.addBus('voice', { level: 1 }); engine.audio.sfx('line-01', { bus: 'voice' }); voice.remove();`
|
|
4
4
|
- `audio.setVolume(bus: string, v: number)` — Set a bus volume 0-1 ('master' for the total). Example: `engine.audio.setVolume('music', 0.3);`
|
|
5
|
+
- `audio.reverb(opts: { wet?, decay?, size?, sends?, fade? } | null)` — (experimental) The one reverb: a send/return any bus can feed (a cave, a hall, a bathroom). Off until called: nothing is built or heard before. Each call changes only the keys given (sends merge per bus; 0 stops one); null turns it off. The echo of a bus follows its slider and its ducks, and comes back through master. The impulse is generated (decaying noise, no file): changing size or decay rebuilds it, wet and sends only fade. Called before the first click it waits for audio to unlock. Places: an ambience rule { reverb: 0.6, when: { zone: 'cave' } } sets wet while it holds (recipes/31 §9). Example: `engine.audio.reverb({ sends: { sfx: 0.5, ambience: 0.8 }, decay: 3, size: 0.8, wet: 0.4 });`
|
|
5
6
|
- `audio.duck(levels: Record<string, number>, opts?: { fade?: number }) → { remove(fade?: number): void }` — Lower buses until the handle is removed (dialogue, pause menu, a cutscene). Several ducks stack (their levels multiply). Example: `const d = engine.audio.duck({ music: 0.3, ambience: 0.5 }); engine.events.once('dialogue:end', () => d.remove());`
|
|
6
7
|
- `audio.condition(name: string, test: (value: any, e: any) => boolean) → { remove(): void }` — Add a condition key for music / ambience rule lists: `when: { [name]: value }` calls test(value, engine). Modules add theirs (calendar: time, weather: weather, triggers: zone); the engine has `state` (engine.audio.state). Example: `engine.audio.condition('inside', v => engine.vars.flag('indoors') === v);`
|
|
7
8
|
- `audio.measure(name: string, fn: (e: any) => number) → { remove(): void }` — Add a measure: a number rule data compares (`when: { daylight: { gt: 0.15 } }`; gt / gte / lt / lte) and adds up (`volume: { add: { wind: 0.08 } }`). calendar adds daylight, weather rain / snow / wind, ambience nearWater / altitude. A name is a condition or a measure, not both. Example: `engine.audio.measure('danger', e => e.vars.counter('alarm') / 10); // data: when: { danger: { gt: 0.5 } } Measures are not only for sound: render/daylight.js reads 'daylight' for night glow, so the calendar (or the sky without one) registers it once and nothing else has to know which module tells day from night. remove() drops only this registration (a later one under the name stays).`
|
|
@@ -21,7 +22,7 @@
|
|
|
21
22
|
- `master: any` The master GainNode (every bus ends here)
|
|
22
23
|
- `noise: any` 2 s of white noise, reused by synthesized sounds
|
|
23
24
|
- `running: boolean` (experimental) Is audio usable (the player has clicked/pressed a key)?
|
|
24
|
-
- `info: { running, state, levels, ducks, voices }` What is playing (describe().audio shows it while something is ducked or playing): bus levels, the duck multiplier per bus, live voices per sound name. ducks is the level the active ducks ask for (1 = not lowered), read at once even while a fade is still ramping or the audio clock does not run (headless page). Example: `engine.audio.duck({ music: 0.3 }); engine.audio.info.ducks.music // 0.3`
|
|
25
|
+
- `info: { running, state, levels, ducks, voices, reverb? }` What is playing (describe().audio shows it while something is ducked or playing): bus levels, the duck multiplier per bus, live voices per sound name. ducks is the level the active ducks ask for (1 = not lowered), read at once even while a fade is still ramping or the audio clock does not run (headless page). Example: `engine.audio.duck({ music: 0.3 }); engine.audio.info.ducks.music // 0.3`
|
|
25
26
|
|
|
26
27
|
## Data structures
|
|
27
28
|
- **AudioConfig** The game's sound config: createEngine({ audio }), read back as engine.audio.config (merged with content packs' ContentAudio).
|
|
@@ -42,8 +43,9 @@
|
|
|
42
43
|
- `loop?: boolean`
|
|
43
44
|
- `distance?: { ref?: number; max?: number; rolloff?: number }` 3D falloff for sfx(name, { at }): ref meters at full volume (2), max meters (60), rolloff (1)
|
|
44
45
|
- **AmbienceRule** One ambience rule: while `when` holds, `sound` plays at `volume`. With `every` it is a one-shot repeated at random gaps, else a loop
|
|
45
|
-
- `sound
|
|
46
|
+
- `sound?: string` A name from audio.sounds; required unless the rule is a reverb rule
|
|
46
47
|
- `when?: AudioCondition`
|
|
48
|
+
- `reverb?: number | AudioVolumeData | ((e, ambience) => number)` (experimental) Instead of a sound: the reverb's wet (0-1, or the volume forms) while `when` holds; the highest holding one wins, none gives engine.audio.reverb's own wet back. Not with sound / volume / every / bus
|
|
47
49
|
- `volume?: number | AudioVolumeData | ((e, ambience) => number)` 0-1, data { base, add: { measure: factor }, min, max }, or a function of the moment (e, ambience) => 0-1 (code only)
|
|
48
50
|
- `fade?: number` Fade seconds when the rule turns on / off (1)
|
|
49
51
|
- `every?: number[]` One-shot: [shortest, longest] seconds between plays
|
package/docs/api/budget.md
CHANGED
|
@@ -7,11 +7,14 @@
|
|
|
7
7
|
- `budget.report() → BudgetReport | null` — Budget report; null when off. In the real-time loop it returns the last second's result; in step() mode it is computed on demand
|
|
8
8
|
- `budget.checkStartup(s: { totalMs, modules }) → { category, value, limit, top }[]` — (experimental) Called by the engine when startup finishes: warns if startupMs / moduleMs is exceeded and returns the offenders (empty array if none)
|
|
9
9
|
- `budget.values() → Record<string, number>` — Current value per category (fps/low1/cpuMs exist only once there are frame times)
|
|
10
|
+
- `budget.record() → { where, values }` — This run's numbers in the shape baseline keeps: { where, values: { drawCalls, triangles, cpuMs (live runs), modules: { name: median ms, 0 too } } }. threedog shot / verify --save-baseline write it into the game's .threedog/perf-baseline.json (this machine's, not committed)
|
|
11
|
+
- `budget.notice() → string | null` — One line when something is off, null when all is fine: over a limit the game declared (only when the budget is on; the engine's own reference limits never), slower than the baseline recorded at this spot on this machine (medians, past a noise margin), a module with spikes (p95 over 3x its median and over 2 ms), or what adaptive quality lowered (resolution, effects). threedog shot, verify and describeText print it. Example: `engine.budget.notice() // 'Perf: over budget drawCalls 312 (limit 250, +25%); slower than baseline: modules.terrain 1.4 ms (was 0.6, +133%) -> threedog inspect perf'`
|
|
10
12
|
- `budget.byTag() → BudgetTagStat[]` — Estimate draw calls and triangles by userData.budgetTag (visible meshes inside the frustum; shadow casters count a second shadow draw). Returns [{ tag, drawCalls, triangles }], largest first. Called only on overrun (at most once a second) or when debugging
|
|
11
13
|
- Properties:
|
|
12
14
|
- `enabled: boolean` Is it on?
|
|
13
15
|
- `limits: BudgetLimits` (experimental) Current limits
|
|
14
16
|
- `cost: ApplyCost` Cost of applying background results, split in stages (see ApplyCost)
|
|
17
|
+
- `baseline: Record<string, any> | null` The recorded run to compare against: { [where]: { drawCalls, triangles, cpuMs?, modules: { name: ms } } } as record() makes it. threedog shot / verify load the game's .threedog/perf-baseline.json (this machine's) here when the game set none (and write it with --save-baseline). null = no comparison
|
|
15
18
|
|
|
16
19
|
## Data structures
|
|
17
20
|
- **BudgetLimits** Budget limits: only the given categories are checked. fps/low1 are lower bounds (frame rate must not drop below), the rest are upper bounds
|
|
@@ -21,6 +24,7 @@
|
|
|
21
24
|
- `cpuMs?: number` CPU milliseconds per frame
|
|
22
25
|
- `triangles?: number` Triangle count
|
|
23
26
|
- `textures?: number` Texture count
|
|
27
|
+
- `gpuMemoryMB?: number` GPU memory in MB as three counts it (WebGPURenderer only: an estimate, not driver VRAM)
|
|
24
28
|
- `chunkApplyMs?: number` Terrain chunk upload milliseconds per frame
|
|
25
29
|
- `rigidBodies?: number` Rigid body count
|
|
26
30
|
- `lights?: number` Lit point + spot lights, a game's own and pooled ones (default limit 8)
|
|
@@ -34,6 +38,7 @@
|
|
|
34
38
|
- `applyStreamMs?: number`
|
|
35
39
|
- `startupMs?: number` Time from opening to playable (milliseconds); when exceeded, the slowest module is named
|
|
36
40
|
- `moduleMs?: number` Single module startup (init + wait for ready, milliseconds); when exceeded, that module is named
|
|
41
|
+
- `modules?: Record<string, number>` Hook ms per frame of one module, { terrain: 1.5 } (median of engine.profile(), on in dev builds); reported as category 'modules.<name>'
|
|
37
42
|
- **BudgetReport** Budget report: ok means everything is within budget
|
|
38
43
|
- `ok: boolean`
|
|
39
44
|
- `over: BudgetOver[]`
|
package/docs/api/cameraRig.md
CHANGED
|
@@ -13,8 +13,8 @@ Current camera (one of followCamera / firstPersonCamera / fixedCamera / rtsCamer
|
|
|
13
13
|
- `height?: number` How high above the character to look at (meters), default 1.4
|
|
14
14
|
- `smoothing?: number` (experimental) Follow smoothing, default 10
|
|
15
15
|
- `sensitivity?: number` Drag sensitivity, default 1
|
|
16
|
-
- `minPitch?: number` Pitch range (radians)
|
|
17
|
-
- `maxPitch?: number` (experimental)
|
|
16
|
+
- `minPitch?: number` Pitch range (radians), default 0.05 to 1.35. The camera never goes below the look point, so the view cannot look up (a tall building's roof stays out of sight); a negative minPitch looks up (recipe 21 section 4b)
|
|
17
|
+
- `maxPitch?: number` (experimental) Upper pitch limit (looking down), default 1.35 (about 77 degrees, not straight down)
|
|
18
18
|
- `zoomStep?: number` (experimental) Zoom ratio per wheel notch, default 0.1
|
|
19
19
|
- `groundClearance?: number` (experimental) Minimum camera height above the ground (meters), default 1.2
|
|
20
20
|
- `invertY?: boolean` (experimental) Invert vertical
|
package/docs/api/characters.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# engine.characters — characters(opts?: CharactersOptions)
|
|
2
2
|
|
|
3
|
-
Characters:
|
|
3
|
+
Characters: addPlayer() (characters() module)
|
|
4
4
|
|
|
5
5
|
- Options `CharactersOptions`:
|
|
6
6
|
- `npcs?: boolean` Whether to enable NPCs (engine.npcs), default true
|
|
@@ -10,13 +10,13 @@ Characters: createPlayer() (characters() module)
|
|
|
10
10
|
|
|
11
11
|
## Methods and properties
|
|
12
12
|
- `characters.findSpawn(position?: PositionLike, opts?: FindSpawnOptions) → Vector3` — Find a spawn point: searches outward from position (default origin) for walkable (not steep, no obstacle), non-water ground, without assuming terrain height; e.g. findSpawn(v, { minH: 3, maxH: 20 }). Returns a Vector3 (y is the ground height)
|
|
13
|
-
- `characters.
|
|
13
|
+
- `characters.addPlayer(opts: PlayerOptions) → Character` — Create the player and set engine.player; control is required (no default feel), e.g. addPlayer({ ...presets.player.thirdPerson, spawn }). An existing player is deleted first
|
|
14
14
|
- `characters.moveInput(seat?: Seat) → { x, z, run }` — The 'camera' player control as a value: keys / stick relative to the camera, the 'run' action if bound, input.autopilot. Reused object; call it inside your own control function to wrap it
|
|
15
15
|
- `characters.addVehicle(vehicle: any) → { remove(): void }` — Join the vehicles a saved rider can be seated in again, before or after the load
|
|
16
16
|
- `characters.support(object: any, opts?: { id?, safe?, carry?, inherit? }) → { id: string; remove(): void }` — Something characters stand on and ride (moving platform, lift, raft). Move the object any way (onFixed before or after the player, a timeline, physics): riders follow how its matrix changed, so the order does not matter. safe: false = never a respawn spot; carry 'position+yaw' turns riders with it; inherit: false = jumping off keeps none of its speed. With mover 'rapier' give it a collider too. Example: `const lift = engine.characters.support(liftMesh); engine.onFixed(() => { liftMesh.position.y = 2 + Math.sin(engine.time.now('real')); });`
|
|
17
17
|
- `characters.removePlayer(id?: string)` — (experimental) Delete the current player (exits the vehicle first, stops responding to keys, fully deletes the model). The player save (key player) carries the position and the vehicle; loading an on-foot save exits the vehicle first
|
|
18
18
|
- `characters.findPath(from: PositionLike, to: PositionLike, opts?: FindPathOptions & { detailed?: false }) → NavPathPoint[] | null` / `findPath(from: PositionLike, to: PositionLike, opts: FindPathOptions & { detailed: true }) → PathResult` — Pathfinding (the single entry point): uses the navmesh when nav is installed and ready, otherwise the A* fallback. Returns a path [{ x, y, z }...], or null if unreachable
|
|
19
|
-
- `characters.findPathAsync(from: PositionLike, to: PositionLike, done: (path, status) => void, opts?: { radius?, step?, maxNodes? }) → { remove(): void }` — findPath for many callers (NPC crowds, AI squads): solved in engine.threads workers; done(path, status) runs on a fixed step a few steps later (same paths with threads on or off). Recipe 12 section 4
|
|
19
|
+
- `characters.findPathAsync(from: PositionLike, to: PositionLike, done: (path, status) => void, opts?: { radius?, passes?, step?, maxNodes? }) → { remove(): void }` — findPath for many callers (NPC crowds, AI squads): solved in engine.threads workers; done(path, status) runs on a fixed step a few steps later (same paths with threads on or off). Recipe 12 section 4
|
|
20
20
|
- Properties:
|
|
21
21
|
- `material: Material` The three.js material of every placeholder capsule. Set it to swap the look of all of them at once; used as given, with no patches added. A character with colors.body draws with a copy of it in that color. A model's own materials are the model's. Example: `engine.characters.material = new THREE.MeshToonMaterial({ color: 0xd9a066 });`
|
|
22
22
|
- `kit: { beginMove, groundAt, endMove, ownState }` What a game's mover calls to take part in contact, each optional (recipe 57): a mover calling none owns contact itself (beginMove() groundAt() endMove() ownState())
|
|
@@ -35,7 +35,7 @@ Characters: createPlayer() (characters() module)
|
|
|
35
35
|
- `player.playAction(name: string)` — Play a one-shot action (e.g. 'wave'); skipped if the model has no such clip
|
|
36
36
|
- `player.onPose(fn: (character, dt) => void) → { remove(): void }` — Run fn(character, dt) every frame right after the animation pose is applied (model clips or procedural rig): attach things to bones or adjust bones. h.remove() stops it. Presentation only. Example: `const h = player.onPose(() => sword.position.copy(hand.getWorldPosition(v)));`
|
|
37
37
|
- `player.dispose()` — Fully delete this character: exits the vehicle first, releases animation and movement, removes it from the scene and releases geometry and materials (used by npcs.remove / removePlayer)
|
|
38
|
-
- `player.jump(opts?: { air?: boolean })` — Request a jump (buffered for jumpBuffer s): the ground jump on the ground or in coyote time, else an air jump while maxJumps allows; air: false = ground only. Example: `
|
|
38
|
+
- `player.jump(opts?: { air?: boolean })` — Request a jump (buffered for jumpBuffer s): the ground jump on the ground or in coyote time, else an air jump while maxJumps allows; air: false = ground only. Example: `addPlayer({ ...presets.player.thirdPerson, maxJumps: 2 }) // double jump`
|
|
39
39
|
- `player.placeAt(position: PositionLike)` — Put it on the ground at position (Vector3 / object / [x, y, z] / { x, z })
|
|
40
40
|
- `player.syncRecord()` — After moving root yourself (a cutscene path, a scripted pose): write position and motion back to its world record (the player's), so a save right after has it
|
|
41
41
|
- `player.walkTo(target: Vector3 | { x: number; z: number } | [number, number, number] | …, opts?: { speed?, arrive?, turnRate?, stuckSeconds?, maxRepaths?, run? }) → Promise<{ status: 'arri… & { remove(): void }` — Walk to a point along characters.findPath on fixed steps; never rejects. One walk per character: a new walkTo, dispose() or a save load ends the old one with 'cancelled'. Transient: not saved, not fast-forwarded by engine.skip. Holds the character's control on layer 'script' (owner 'walkTo'): the player's keys / an NPC's schedule pause meanwhile, a cutscene pauses the walk, and another script owner on it is control-conflict
|
|
@@ -45,7 +45,7 @@ Characters: createPlayer() (characters() module)
|
|
|
45
45
|
- `player.saveMotion(out?: CharacterMotion) → CharacterMotion` — (experimental) Copy the motion state into a plain object (velocity, vertical velocity, heading, movement amount, grounded, swimming) to store in world data; after the model is rebuilt or a save is loaded, loadMotion continues from it with identical results
|
|
46
46
|
- `player.loadMotion(m: CharacterMotion | null | undefined)` — (experimental) Restore the motion state from the plain object of saveMotion
|
|
47
47
|
- Properties:
|
|
48
|
-
- `root: Object3D` Root node: add it to the scene with engine.add(character.root) when you built the Character yourself; add children, change visible and scale on it
|
|
48
|
+
- `root: Object3D` Root node, the character's model (there is no character.model; the loaded glTF is a child of root): add it to the scene with engine.add(character.root) when you built the Character yourself; add children, change visible and scale on it
|
|
49
49
|
- `position: Vector3` Position (= root.position)
|
|
50
50
|
- `velocity: Vector2` Horizontal velocity (x, y map to world x, z). Writable: a write is an impulse the mover steers back toward the input (lasting knockback: push(); full control: mover 'manual')
|
|
51
51
|
- `facing: number` Heading (radians): 0 faces +Z, forward = (sin facing, cos facing); increasing turns toward +X (rotation about the Y axis, consistent with root.rotation.y)
|
|
@@ -69,6 +69,7 @@ Characters: createPlayer() (characters() module)
|
|
|
69
69
|
- `jumpBuffer: number` (experimental)
|
|
70
70
|
- `fall: false | { belowY }` (experimental) Fall check (see CharacterOptions.fall); a plain property
|
|
71
71
|
- `channel: string` Time channel the engine drives it on (see CharacterOptions.channel)
|
|
72
|
+
- `passes: readonly string[] | undefined` Collider layers it goes through (the passes option, sorted); undefined = stopped by every collider. Plain: a write counts from its next step and path
|
|
72
73
|
- `id: string` The character's id, the one form engine.mod / time.local take: its world record id ('player', an NPC's record id), else the id option, else a generated one
|
|
73
74
|
- `support: { kind, object, id, safe, velocity }` What it stands on, read-only (reused object); 'platform' = a registered support (characters.support), which carries it
|
|
74
75
|
- `safeGround: Vector3 | null` Last spot it stood still on safe ground (where a fall returns it); null until it first stands. Saved with the motion
|
|
@@ -119,7 +120,7 @@ Characters: createPlayer() (characters() module)
|
|
|
119
120
|
- `at: number`
|
|
120
121
|
- `x: number`
|
|
121
122
|
- `z: number`
|
|
122
|
-
- **PlayerOptions** (extends CharacterOptions) Parameters of
|
|
123
|
+
- **PlayerOptions** (extends CharacterOptions) Parameters of addPlayer()
|
|
123
124
|
- `id?: string` A further local player's id and world record; left out, the one player (engine.player)
|
|
124
125
|
- `input?: Seat` The seat that drives this player (engine.input.seat); default engine.input
|
|
125
126
|
- `spawn?: PositionLike` Spawn point (meters, { x, z } / Vector3 / object); flat ground is found automatically if omitted
|
|
@@ -131,7 +132,7 @@ Characters: createPlayer() (characters() module)
|
|
|
131
132
|
- `runSpeed?: number` Running speed (m/s), default 7
|
|
132
133
|
- `radius?: number` Collision radius (meters), default 0.4
|
|
133
134
|
- `water?: CharacterWater` What water deeper than swimDepth does: 'swim' (default: floats, state 'swim') / 'block' (never enters it) / 'wade' (walks the bottom) / a function deciding per spot (a swim skill, a boat, depth). character:water fires on each change
|
|
134
|
-
- `states?: CharacterStates | null` The game's own states on top of the built-in ones (crouch, climb, glide, dash, roll): run after the mover's state each step, return a state name or null to keep facts.base. The state picks the clip like any other (clips: { crouch: 'Crouch' }); speed changes stay engine.mod('move.speed'). Example: `
|
|
135
|
+
- `states?: CharacterStates | null` The game's own states on top of the built-in ones (crouch, climb, glide, dash, roll): run after the mover's state each step, return a state name or null to keep facts.base. The state picks the clip like any other (clips: { crouch: 'Crouch' }); speed changes stay engine.mod('move.speed'). Example: `addPlayer({ ..., clips: { crouch: 'Crouch' }, states: (c, f) => f.grounded && engine.input.down('crouch') ? 'crouch' : null })`
|
|
135
136
|
- `swimDepth?: number` Water depth (meters) at which water counts as deep, default 1
|
|
136
137
|
- `swimSpeed?: number` Swimming speed multiplier, default 0.45
|
|
137
138
|
- `turnSpeed?: number` How fast it turns, default 10
|
|
@@ -147,7 +148,8 @@ Characters: createPlayer() (characters() module)
|
|
|
147
148
|
- `jumpBuffer?: number` How long a jump() pressed early waits for the ground (seconds), default 0.12
|
|
148
149
|
- `fall?: false | { belowY }` Falling out of the level: below belowY (or when belowY(character) is true) character:fall fires and the rule 'fall' decides: back to safeGround by default, engine.mod('fall', { owner, id, set: false }) leaves it to the game. false (default) = off
|
|
149
150
|
- `channel?: string` Time channel its movement and animation follow when the engine drives it (player default 'player', others 'world')
|
|
150
|
-
- `
|
|
151
|
+
- `passes?: string[]` Collider layers it walks through, e.g. ['gate'] (collision.addBox { layer: 'gate' }): its walking, walkTo and NPC paths, navmesh included, follow it. Default: stopped by every collider
|
|
152
|
+
- `model?: Object3D | string | null` The body, one path for every kind: the name of a registered model asset, or what engine.assets.model() returned. A procedural builder name (from an asset pack) is built at once; a file model name shows a gray capsule and swaps in a copy when it loads (Character.ready / whenReady, event 'character:model'). Example: `engine.assets.manifest(yourAssets); engine.characters.addPlayer({ model: 'yourBody' }) // a generator or GLB name from an asset pack`
|
|
151
153
|
- `rig?: CharacterRig | null` A ready procedural body (CharacterRig), used instead of model (a hand-built guard / pet)
|
|
152
154
|
- `id?: string` Id for engine.mod / time.local entries of a character without a world record (read it back as character.id); the player is 'player', an NPC its record id
|
|
153
155
|
- `clips?: { idle?, walk?, run?, swim?, jump?, fall?, … } | null` Action name mapping { idle, walk, run, swim, jump, fall } (shorthand for animation)
|
package/docs/api/collision.md
CHANGED
|
@@ -13,14 +13,14 @@ Lightweight collision (collision() module): no clipping while walking, the camer
|
|
|
13
13
|
## Methods and properties
|
|
14
14
|
- `collision.addCircle(position: PositionLike, opts?: CircleColliderOptions) → Handle` — Add a circle collider (pillar, campfire): position is the center, e.g. addCircle(mesh, { radius: 1 }). Returns a handle { remove() }
|
|
15
15
|
- `collision.addBox(position: PositionLike, opts?: BoxColliderOptions) → Handle` — Add a box collider (house, fence): position is the center, e.g. addBox(house, { halfWidth: 3, halfDepth: 2, rotation: 0.3 }). Returns a handle { remove() }
|
|
16
|
-
- `collision.addSegment(a: PositionLike, b: PositionLike, opts?: { thickness?, height?, y?, occluder? }) → Handle` — Add a thin wall along a -> b (fence). Options: thickness (default 0.3), height, y, occluder (as in addBox). A gap between segments is a gate. Returns a handle { remove() }
|
|
16
|
+
- `collision.addSegment(a: PositionLike, b: PositionLike, opts?: { thickness?, height?, y?, occluder?, layer? }) → Handle` — Add a thin wall along a -> b (fence). Options: thickness (default 0.3), height, y, occluder, layer (as in addBox). A gap between segments is a gate. Returns a handle { remove() }
|
|
17
17
|
- `collision.addBlocked(fn: (x: number, z: number) => boolean, opts?: { bounds? }) → Handle` — Mark ground impassable where fn(x, z) is true (river, lava); fn must be pure (no side effects, same answer for the same (x, z)); reading engine.ground in it is fine. findPathAsync caches the answers, so after the ground or your own state changes, remove() and add the field again. bounds { minX, maxX, minZ, maxZ } (world metres, the field's x / z extent) skips fn outside it; give it to keep findPathAsync's ground sampling cheap. Returns a handle { remove() }
|
|
18
18
|
- `collision.blockedAt(x: number, z: number, radius?: number) → boolean` — (experimental) Is a character of this radius touching addBlocked ground at (x, z)
|
|
19
|
-
- `collision.addObject(obj: Object3D, opts?: { pad
|
|
19
|
+
- `collision.addObject(obj: Object3D, opts?: { pad?, occluder?, layer? }) → Handle` — Add a collider from an object's bounding box, pad expands outward (meters), occluder and layer as in addBox. Returns a handle { remove() }
|
|
20
20
|
- `collision.forEachStatic(fn: (type, data) => void)` — (experimental) Iterate all static colliders added by hand
|
|
21
21
|
- `collision.mirror(fns: { add, remove }) → { sync, clear, size }` — (experimental) Keep an outside copy of the static colliders in step (physics colliders, navmesh obstacles): add builds one piece, remove drops one; sync() diffs only when colliders changed and returns whether it compared; clear() forgets every piece without remove (the outside world was thrown away)
|
|
22
|
-
- `collision.walkable(position: PositionLike, opts?: { radius
|
|
23
|
-
- `collision.walkableAt(x: number, z: number, radius?: number) → boolean` — walkable with plain numbers, allocating nothing (A* inner loops); radius defaults to engine.movement.radius
|
|
22
|
+
- `collision.walkable(position: PositionLike, opts?: { radius?, passes? }) → boolean` — Whether someone can stand at this position (for pathfinding): not in water, not too steep, not inside an obstacle. radius is the character radius (meters, default engine.movement.radius), passes the collider layers it goes through
|
|
23
|
+
- `collision.walkableAt(x: number, z: number, radius?: number, y?: number, passes?: readonly string[]) → boolean` — walkable with plain numbers, allocating nothing (A* inner loops); radius defaults to engine.movement.radius; y picks the floor; passes as in walkable
|
|
24
24
|
- `collision.lineClear(a: PositionLike, b: PositionLike, opts?: { radius?, who? }) → boolean` — Line of sight with height: is the 3D segment a -> b free of boxes, circles and terrain trees? radius fattens the line; addBlocked water is ignored. Give eye heights in a / b
|
|
25
25
|
- Properties:
|
|
26
26
|
- `maxClimb: number` (experimental)
|
|
@@ -36,6 +36,7 @@ Lightweight collision (collision() module): no clipping while walking, the camer
|
|
|
36
36
|
- `radius?: number` Radius, default 0.5
|
|
37
37
|
- `height?: number` Height, default 6
|
|
38
38
|
- `occluder?: boolean` false: walkers are still stopped but the follow camera's occlusion check ignores it (forest trunks the camera may pass through). Default true
|
|
39
|
+
- `layer?: string` A name: movers whose passes list names it go through it (walking, paths, navmesh), every other mover is stopped, e.g. a gate only some characters use. Omitted: it stops every mover. Sight lines and the camera ignore it
|
|
39
40
|
- **BoxColliderOptions** Parameters of addBox() (meters, radians)
|
|
40
41
|
- `halfWidth?: number` Half width (X direction), default 1
|
|
41
42
|
- `halfDepth?: number` Half depth (Z direction), default 1
|
|
@@ -43,3 +44,4 @@ Lightweight collision (collision() module): no clipping while walking, the camer
|
|
|
43
44
|
- `height?: number` Height, default 6
|
|
44
45
|
- `y?: number` Bottom height of the box; if omitted it sits on the ground (give it for walls placed on platforms in a level)
|
|
45
46
|
- `occluder?: boolean` false: walkers are still stopped but the follow camera's occlusion check ignores it (forest trunks the camera may pass through). Default true
|
|
47
|
+
- `layer?: string` A name: movers whose passes list names it go through it (walking, paths, navmesh), every other mover is stopped, e.g. a gate only some characters use. Omitted: it stops every mover. Sight lines and the camera ignore it
|