@jgengine/core 0.18.0 → 0.19.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 +265 -2
- package/dist/ai/decisionGraph.d.ts +96 -0
- package/dist/ai/decisionGraph.js +212 -0
- package/dist/ai/groupAssist.d.ts +10 -0
- package/dist/ai/groupAssist.js +11 -0
- package/dist/ai/mobBrainGraph.d.ts +3 -0
- package/dist/ai/mobBrainGraph.js +25 -0
- package/dist/ai/pursuit.d.ts +1 -1
- package/dist/ai/pursuit.js +1 -1
- package/dist/ai/tacticalQueries.d.ts +30 -0
- package/dist/ai/tacticalQueries.js +45 -0
- package/dist/ai/threat.d.ts +8 -0
- package/dist/ai/threat.js +10 -0
- package/dist/anim/animGraph.d.ts +155 -0
- package/dist/anim/animGraph.js +414 -0
- package/dist/anim/boneTexture.d.ts +55 -0
- package/dist/anim/boneTexture.js +43 -0
- package/dist/anim/footPlacement.d.ts +57 -0
- package/dist/anim/footPlacement.js +67 -0
- package/dist/anim/ikSolver.d.ts +51 -0
- package/dist/anim/ikSolver.js +124 -0
- package/dist/anim/locomotionGraph.d.ts +35 -0
- package/dist/anim/locomotionGraph.js +62 -0
- package/dist/assets/spriteAtlas.d.ts +21 -0
- package/dist/assets/spriteAtlas.js +103 -0
- package/dist/audio/audioFalloff.d.ts +12 -0
- package/dist/audio/doppler.d.ts +21 -0
- package/dist/audio/doppler.js +32 -0
- package/dist/audio/engineLayers.d.ts +83 -0
- package/dist/audio/engineLayers.js +115 -0
- package/dist/combat/abilityKit.d.ts +1 -0
- package/dist/combat/abilityKit.js +1 -0
- package/dist/combat/death.d.ts +7 -0
- package/dist/combat/shotOrigin.d.ts +6 -0
- package/dist/combat/shotOrigin.js +6 -0
- package/dist/combat/weaponFeedback.d.ts +36 -0
- package/dist/combat/weaponFeedback.js +42 -0
- package/dist/combat/weaponHandling.d.ts +161 -0
- package/dist/combat/weaponHandling.js +202 -0
- package/dist/combat/weaponPresentation.d.ts +115 -0
- package/dist/combat/weaponPresentation.js +96 -0
- package/dist/devtools/warnOnce.d.ts +8 -0
- package/dist/devtools/warnOnce.js +18 -0
- package/dist/economy/currency.d.ts +16 -2
- package/dist/economy/currency.js +55 -14
- package/dist/economy/wallet.d.ts +5 -4
- package/dist/economy/wallet.js +8 -4
- package/dist/editor/commandApply.js +1 -0
- package/dist/editor/commands.d.ts +4 -1
- package/dist/editor/document.d.ts +2 -1
- package/dist/editor/document.js +92 -1
- package/dist/editor/environment.d.ts +3 -0
- package/dist/editor/environment.js +24 -0
- package/dist/editor/index.d.ts +4 -2
- package/dist/editor/index.js +1 -1
- package/dist/editor/types.d.ts +20 -0
- package/dist/faction/reputation.d.ts +6 -0
- package/dist/faction/reputation.js +11 -0
- package/dist/game/cameraConfig.d.ts +59 -1
- package/dist/game/chat.d.ts +22 -1
- package/dist/game/chat.js +48 -19
- package/dist/game/controlGate.d.ts +6 -0
- package/dist/game/controlGate.js +30 -1
- package/dist/game/defineGame.d.ts +10 -1
- package/dist/game/events.d.ts +14 -1
- package/dist/game/lootTable.d.ts +4 -0
- package/dist/game/lootTable.js +16 -0
- package/dist/game/pixelPerfect.d.ts +25 -0
- package/dist/game/pixelPerfect.js +29 -0
- package/dist/game/playableGame.d.ts +167 -6
- package/dist/game/systemRuntime.js +6 -1
- package/dist/game/toasts.d.ts +8 -0
- package/dist/game/toasts.js +7 -0
- package/dist/game/vfxInstance.d.ts +9 -0
- package/dist/game/vfxInstance.js +12 -1
- package/dist/game/viewports.d.ts +43 -0
- package/dist/game/viewports.js +46 -0
- package/dist/game/worldItem.d.ts +5 -1
- package/dist/game/worldItem.js +0 -1
- package/dist/input/actionBindings.d.ts +17 -2
- package/dist/input/actionBindings.js +24 -11
- package/dist/input/actionContexts.d.ts +45 -0
- package/dist/input/actionContexts.js +113 -0
- package/dist/input/axisInput.d.ts +4 -0
- package/dist/input/axisInput.js +4 -0
- package/dist/input/axisShaper.d.ts +73 -0
- package/dist/input/axisShaper.js +105 -0
- package/dist/input/gamepadModel.d.ts +79 -0
- package/dist/input/gamepadModel.js +108 -0
- package/dist/input/haptics.d.ts +50 -0
- package/dist/input/haptics.js +74 -0
- package/dist/input/inputBuffer.d.ts +40 -0
- package/dist/input/inputBuffer.js +59 -0
- package/dist/input/lookChannel.d.ts +10 -0
- package/dist/input/lookChannel.js +6 -0
- package/dist/input/pointer.d.ts +2 -0
- package/dist/input/pointer.js +4 -0
- package/dist/item/affix.d.ts +6 -0
- package/dist/item/affix.js +6 -0
- package/dist/meta/changelog.d.ts +1 -1
- package/dist/meta/changelog.js +196 -1
- package/dist/movement/characterController.d.ts +76 -0
- package/dist/movement/characterController.js +216 -0
- package/dist/movement/freeFlight.d.ts +119 -0
- package/dist/movement/freeFlight.js +294 -0
- package/dist/movement/glideModel.d.ts +3 -0
- package/dist/movement/glideModel.js +6 -0
- package/dist/movement/grappleSwing.d.ts +2 -0
- package/dist/movement/grappleSwing.js +5 -1
- package/dist/movement/movementModel.d.ts +39 -0
- package/dist/movement/movementModel.js +62 -19
- package/dist/movement/movementProbe.d.ts +51 -0
- package/dist/movement/movementProbe.js +119 -0
- package/dist/movement/playerMovement.d.ts +30 -3
- package/dist/movement/playerMovement.js +304 -7
- package/dist/movement/serverStep.d.ts +5 -0
- package/dist/movement/serverStep.js +6 -0
- package/dist/movement/solidObstacles.d.ts +39 -8
- package/dist/movement/solidObstacles.js +71 -6
- package/dist/movement/voxelController.js +7 -7
- package/dist/multiplayer/poseSyncGate.d.ts +3 -1
- package/dist/multiplayer/poseSyncGate.js +9 -1
- package/dist/multiplayer/presenceContract.d.ts +6 -0
- package/dist/multiplayer/presenceModel.d.ts +2 -0
- package/dist/multiplayer/presenceModel.js +11 -0
- package/dist/nav/navFromEnvironment.d.ts +9 -3
- package/dist/nav/navFromEnvironment.js +18 -12
- package/dist/nav/navMesh.d.ts +74 -0
- package/dist/nav/navMesh.js +570 -0
- package/dist/physics/aircraftDynamics.d.ts +390 -0
- package/dist/physics/aircraftDynamics.js +704 -0
- package/dist/physics/boatDynamics.d.ts +116 -0
- package/dist/physics/boatDynamics.js +160 -0
- package/dist/physics/drivableVehicle.d.ts +22 -8
- package/dist/physics/drivableVehicle.js +4 -2
- package/dist/physics/flightDynamics.d.ts +29 -4
- package/dist/physics/flightDynamics.js +28 -5
- package/dist/physics/handlingProbe.d.ts +249 -0
- package/dist/physics/handlingProbe.js +606 -0
- package/dist/physics/kinematicVehicle.d.ts +37 -2
- package/dist/physics/kinematicVehicle.js +15 -0
- package/dist/physics/physicsBackend.d.ts +203 -0
- package/dist/physics/physicsBackend.js +49 -0
- package/dist/physics/physicsBackendConformance.d.ts +27 -0
- package/dist/physics/physicsBackendConformance.js +151 -0
- package/dist/physics/physicsWorldBackend.d.ts +45 -0
- package/dist/physics/physicsWorldBackend.js +518 -0
- package/dist/physics/vehicleBackendLink.d.ts +49 -0
- package/dist/physics/vehicleBackendLink.js +102 -0
- package/dist/physics/vehicleDynamics.d.ts +374 -0
- package/dist/physics/vehicleDynamics.js +737 -0
- package/dist/physics/worldColliders.d.ts +13 -0
- package/dist/physics/worldColliders.js +128 -0
- package/dist/puzzle/cellGrid.d.ts +15 -9
- package/dist/puzzle/cellGrid.js +13 -9
- package/dist/random/rng.d.ts +12 -1
- package/dist/random/rng.js +20 -3
- package/dist/render/environment.d.ts +23 -0
- package/dist/render/environment.js +1 -0
- package/dist/render/lookPreset.d.ts +19 -6
- package/dist/render/lookPreset.js +56 -4
- package/dist/render/postProcessing.d.ts +40 -1
- package/dist/render/postProcessing.js +1 -1
- package/dist/render/sprite2d.d.ts +38 -0
- package/dist/render/sprite2d.js +40 -0
- package/dist/runtime/adapter.d.ts +20 -1
- package/dist/runtime/adapter.js +8 -1
- package/dist/runtime/cameraDirector.d.ts +17 -3
- package/dist/runtime/cameraDirector.js +25 -0
- package/dist/runtime/commandInput.d.ts +52 -0
- package/dist/runtime/commandInput.js +71 -0
- package/dist/runtime/commandRunner.d.ts +39 -7
- package/dist/runtime/commandRunner.js +35 -5
- package/dist/runtime/context/combat.d.ts +1 -0
- package/dist/runtime/context/combat.js +2 -1
- package/dist/runtime/context/deathLoot.d.ts +2 -0
- package/dist/runtime/context/deathLoot.js +1 -0
- package/dist/runtime/gameContext.js +18 -1
- package/dist/runtime/gameContextTypes.d.ts +33 -7
- package/dist/runtime/gameRuntime.d.ts +23 -5
- package/dist/runtime/gameRuntime.js +21 -4
- package/dist/runtime/headlessRunner.d.ts +10 -0
- package/dist/runtime/headlessRunner.js +26 -8
- package/dist/runtime/hostPolicy.d.ts +3 -2
- package/dist/runtime/hostPolicy.js +8 -10
- package/dist/runtime/hostedGameRunner.js +34 -6
- package/dist/runtime/hostedWorldSession.d.ts +12 -16
- package/dist/runtime/hostedWorldSession.js +29 -6
- package/dist/runtime/hostedWorldStore.d.ts +20 -0
- package/dist/runtime/hostedWorldStore.js +1 -0
- package/dist/runtime/inputRecorder.d.ts +30 -0
- package/dist/runtime/inputRecorder.js +59 -0
- package/dist/runtime/inputSnapshot.d.ts +14 -0
- package/dist/runtime/inputSnapshot.js +11 -0
- package/dist/runtime/localPlayers.d.ts +73 -0
- package/dist/runtime/localPlayers.js +119 -0
- package/dist/runtime/poseInterpolation.d.ts +36 -0
- package/dist/runtime/poseInterpolation.js +91 -0
- package/dist/runtime/prediction.d.ts +45 -0
- package/dist/runtime/prediction.js +62 -0
- package/dist/runtime/simContext.d.ts +45 -0
- package/dist/runtime/simContext.js +65 -0
- package/dist/runtime/simLoop.d.ts +52 -0
- package/dist/runtime/simLoop.js +72 -0
- package/dist/runtime/simSnapshot.d.ts +32 -0
- package/dist/runtime/simSnapshot.js +60 -0
- package/dist/runtime/snapshot.d.ts +8 -0
- package/dist/runtime/snapshotBuffer.d.ts +33 -0
- package/dist/runtime/snapshotBuffer.js +58 -0
- package/dist/runtime/transport.d.ts +41 -2
- package/dist/runtime/transport.js +7 -1
- package/dist/runtime/worldChunks.d.ts +2 -0
- package/dist/runtime/worldChunks.js +14 -0
- package/dist/runtime/worldProjection.d.ts +9 -0
- package/dist/runtime/worldProjection.js +17 -1
- package/dist/runtime/worldSnapshot.d.ts +6 -0
- package/dist/runtime/worldSnapshot.js +3 -0
- package/dist/scene/behaviorRuntime.d.ts +29 -1
- package/dist/scene/behaviorRuntime.js +71 -4
- package/dist/scene/behaviors.d.ts +12 -1
- package/dist/scene/builtinSceneKinds.js +10 -0
- package/dist/scene/sceneKinds.d.ts +9 -0
- package/dist/scene/vehicleSeat.d.ts +5 -1
- package/dist/scene/vehicleSeat.js +5 -1
- package/dist/sensor/concealment.d.ts +6 -0
- package/dist/sensor/concealment.js +8 -0
- package/dist/sensor/freezeMonitor.d.ts +6 -0
- package/dist/sensor/freezeMonitor.js +8 -0
- package/dist/sensor/perception.d.ts +70 -0
- package/dist/sensor/perception.js +189 -0
- package/dist/sensor/recordingBuffer.d.ts +3 -0
- package/dist/sensor/recordingBuffer.js +8 -0
- package/dist/session/roundState.d.ts +4 -0
- package/dist/session/roundState.js +11 -0
- package/dist/settings/frameRateLimit.d.ts +16 -0
- package/dist/settings/frameRateLimit.js +37 -0
- package/dist/settings/graphicsProfile.d.ts +21 -0
- package/dist/settings/graphicsProfile.js +48 -0
- package/dist/settings/graphicsSettings.d.ts +40 -0
- package/dist/settings/graphicsSettings.js +81 -0
- package/dist/settings/settingsModel.d.ts +9 -1
- package/dist/settings/settingsModel.js +10 -0
- package/dist/stats/eventMeter.d.ts +1 -1
- package/dist/stats/eventMeter.js +1 -1
- package/dist/time/accrueSince.d.ts +10 -0
- package/dist/time/accrueSince.js +9 -0
- package/dist/time/rateWindow.d.ts +16 -0
- package/dist/time/rateWindow.js +14 -0
- package/dist/time/serverTick.d.ts +21 -3
- package/dist/time/serverTick.js +14 -13
- package/dist/vfx/feedbackMixer.d.ts +61 -0
- package/dist/vfx/feedbackMixer.js +106 -0
- package/dist/vfx/particleDirector.d.ts +68 -0
- package/dist/vfx/particleDirector.js +81 -0
- package/dist/visibility/simulationCulling.d.ts +8 -1
- package/dist/visibility/simulationCulling.js +7 -0
- package/dist/visibility/spatialIndex.d.ts +21 -0
- package/dist/visibility/spatialIndex.js +16 -0
- package/dist/world/authoredSolids.d.ts +46 -0
- package/dist/world/authoredSolids.js +75 -0
- package/dist/world/buildingGenerator.js +2 -2
- package/dist/world/buildingKit.d.ts +3 -1
- package/dist/world/buildings.d.ts +46 -2
- package/dist/world/buildings.js +53 -3
- package/dist/world/cityContent.js +103 -25
- package/dist/world/cityKind.d.ts +139 -0
- package/dist/world/cityKind.js +367 -16
- package/dist/world/features.d.ts +56 -3
- package/dist/world/features.js +13 -2
- package/dist/world/footprintGrid.d.ts +7 -0
- package/dist/world/footprintGrid.js +16 -0
- package/dist/world/interiors.d.ts +1 -0
- package/dist/world/interiors.js +5 -3
- package/dist/world/lod.d.ts +6 -0
- package/dist/world/lod.js +8 -0
- package/dist/world/placement.d.ts +7 -0
- package/dist/world/placement.js +2 -0
- package/dist/world/placementController.d.ts +1 -1
- package/dist/world/placementController.js +7 -0
- package/dist/world/raceCircuit.d.ts +168 -0
- package/dist/world/raceCircuit.js +797 -0
- package/dist/world/terraform.d.ts +8 -0
- package/dist/world/terraform.js +7 -0
- package/dist/world/terrain.d.ts +5 -1
- package/dist/world/terrain.js +5 -0
- package/dist/world/territory.d.ts +97 -0
- package/dist/world/territory.js +182 -0
- package/dist/world/walls.d.ts +7 -0
- package/dist/world/walls.js +7 -0
- package/dist/world/worldSolids.d.ts +84 -0
- package/dist/world/worldSolids.js +240 -0
- package/dist/world.d.ts +5 -3
- package/dist/world.js +4 -2
- package/package.json +1 -1
- package/skills/ce-handoff/SKILL.md +2 -2
- package/skills/game-design/SKILL.md +11 -1
- package/skills/jgengine/SKILL.md +9 -5
- package/skills/jgengine/api.md +205 -101
- package/skills/jgengine/capabilities.md +56 -0
- package/skills/jgengine/recipes/minimal-game.md +3 -0
- package/skills/jgengine-combat/SKILL.md +5 -0
- package/skills/jgengine-combat/api.md +138 -103
- package/skills/jgengine-combat/capabilities.md +29 -1
- package/skills/jgengine-combat/recipes/weapon-feel.md +50 -0
- package/skills/jgengine-gameplay/SKILL.md +10 -0
- package/skills/jgengine-gameplay/api.md +501 -453
- package/skills/jgengine-gameplay/capabilities.md +36 -0
- package/skills/jgengine-gameplay/reference-systems.md +4 -0
- package/skills/jgengine-world/SKILL.md +21 -3
- package/skills/jgengine-world/api.md +1172 -625
- package/skills/jgengine-world/capabilities.md +229 -3
- package/skills/jgengine-world/recipes/character-animation.md +39 -0
- package/skills/jgengine-world/recipes/controls.md +44 -0
- package/skills/jgengine-world/recipes/flight-feel.md +76 -0
- package/skills/jgengine-world/recipes/npc-senses.md +43 -0
- package/skills/jgengine-world/recipes/vehicle-feel.md +85 -0
- package/skills/jgengine-world/reference.md +31 -2
- package/skills/jgengine-world/visibility.md +112 -0
|
@@ -17,7 +17,15 @@ function poseChanged(a, b, tuning) {
|
|
|
17
17
|
|| Math.abs(a.rotationPitch - b.rotationPitch) > tuning.rotationEpsilon
|
|
18
18
|
|| appearanceChanged(a.appearance, b.appearance));
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
/** Default ten-hertz client pose gate with a five-second heartbeat. */
|
|
21
|
+
export const DEFAULT_POSE_SYNC_TUNING = {
|
|
22
|
+
minIntervalMs: 100,
|
|
23
|
+
heartbeatMs: 5_000,
|
|
24
|
+
positionEpsilon: 0.01,
|
|
25
|
+
verticalEpsilon: 0.01,
|
|
26
|
+
rotationEpsilon: 0.01,
|
|
27
|
+
};
|
|
28
|
+
export function createPoseSyncGate(tuning = DEFAULT_POSE_SYNC_TUNING) {
|
|
21
29
|
let lastSentPose = null;
|
|
22
30
|
let lastSentAt = 0;
|
|
23
31
|
return {
|
|
@@ -16,6 +16,12 @@ export interface PresencePose {
|
|
|
16
16
|
export interface PresenceSession<TGameId extends string = string> {
|
|
17
17
|
homeGameId: TGameId;
|
|
18
18
|
externalId: string;
|
|
19
|
+
viewerChunkKey?: string;
|
|
20
|
+
}
|
|
21
|
+
/** Resident identity used to suppress offline actors while their owner is online. */
|
|
22
|
+
export interface PresenceResidentRow {
|
|
23
|
+
actorExternalId: string;
|
|
24
|
+
ownerActorId?: string;
|
|
19
25
|
}
|
|
20
26
|
export interface EnsurePresenceArgs<TGameId extends string = string> {
|
|
21
27
|
gameId: TGameId;
|
|
@@ -22,6 +22,8 @@ export interface IncomingPose {
|
|
|
22
22
|
export interface PoseSyncRules {
|
|
23
23
|
/** Speed cap (units/sec) for client-authoritative movement. */
|
|
24
24
|
maxSpeed: number;
|
|
25
|
+
/** Minimum time between accepted pose writes. Defaults to 100 ms. */
|
|
26
|
+
minIntervalMs?: number;
|
|
25
27
|
/** Vertical offset clamp above floorY (e.g. peak jump height). */
|
|
26
28
|
maxVerticalOffset: number;
|
|
27
29
|
/** World-floor Y used as the base of the jump band. Defaults to 0. */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** Canonical client-authoritative pose-sync tuning shared by every host transport (WS, Convex). */
|
|
2
2
|
export const DEFAULT_POSE_SYNC_RULES = {
|
|
3
3
|
maxSpeed: 12,
|
|
4
|
+
minIntervalMs: 100,
|
|
4
5
|
maxVerticalOffset: 3,
|
|
5
6
|
minElapsedSec: 0.05,
|
|
6
7
|
maxElapsedSec: 0.5,
|
|
@@ -29,6 +30,16 @@ export function spawnPresenceState(origin = DEFAULT_SPAWN_ORIGIN, nowMs, rules)
|
|
|
29
30
|
}
|
|
30
31
|
/** @internal */
|
|
31
32
|
export function decidePoseSync(current, incoming, rules, nowMs, floorY) {
|
|
33
|
+
if (current.lastSeenAtMs !== undefined && nowMs - current.lastSeenAtMs < (rules.minIntervalMs ?? 100)) {
|
|
34
|
+
return {
|
|
35
|
+
position: { ...current.position },
|
|
36
|
+
rotationY: current.rotationY,
|
|
37
|
+
rotationPitch: current.rotationPitch ?? 0,
|
|
38
|
+
appearance: current.appearance,
|
|
39
|
+
changed: false,
|
|
40
|
+
refreshKeepAlive: false,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
32
43
|
const rawElapsedSec = Math.max(0, (nowMs - (current.lastSeenAtMs ?? nowMs)) / 1000);
|
|
33
44
|
const elapsedSec = Math.min(rules.maxElapsedSec, rawElapsedSec);
|
|
34
45
|
const maxDist = rules.maxSpeed * elapsedSec;
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import type { EnvironmentWorldFeature } from "../world/features.js";
|
|
2
2
|
import type { Aabb } from "../world/geometry.js";
|
|
3
|
+
import { type WorldSolids } from "../world/worldSolids.js";
|
|
3
4
|
export interface NavObstacleGrid {
|
|
4
5
|
blockAabb(aabb: Aabb): void;
|
|
5
6
|
}
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* number of buildings blocked.
|
|
8
|
+
* Blocks the footprint of every solid building an environment feature's `structures` generate — the
|
|
9
|
+
* same set `ctx.world.solids` holds for it. Returns the number of buildings blocked.
|
|
10
10
|
*/
|
|
11
11
|
export declare function populateNavGridFromEnvironment(grid: NavObstacleGrid, world: EnvironmentWorldFeature): number;
|
|
12
|
+
/**
|
|
13
|
+
* Blocks the XZ footprint of every solid in `solids` (usually `ctx.world.solids`) on `grid`, so NPC
|
|
14
|
+
* paths avoid exactly what movement and physics collide with. Returns the number of solids blocked.
|
|
15
|
+
* @capability nav-from-solids block world solids on a nav grid
|
|
16
|
+
*/
|
|
17
|
+
export declare function populateNavGridFromSolids(grid: NavObstacleGrid, solids: Pick<WorldSolids, "all">): number;
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { structureSolids, worldSolidFootprint } from "../world/worldSolids.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* number of buildings blocked.
|
|
3
|
+
* Blocks the footprint of every solid building an environment feature's `structures` generate — the
|
|
4
|
+
* same set `ctx.world.solids` holds for it. Returns the number of buildings blocked.
|
|
6
5
|
*/
|
|
7
6
|
export function populateNavGridFromEnvironment(grid, world) {
|
|
8
|
-
|
|
9
|
-
for (const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
const solids = structureSolids(world);
|
|
8
|
+
for (const solid of solids)
|
|
9
|
+
grid.blockAabb(worldSolidFootprint(solid));
|
|
10
|
+
return solids.length;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Blocks the XZ footprint of every solid in `solids` (usually `ctx.world.solids`) on `grid`, so NPC
|
|
14
|
+
* paths avoid exactly what movement and physics collide with. Returns the number of solids blocked.
|
|
15
|
+
* @capability nav-from-solids block world solids on a nav grid
|
|
16
|
+
*/
|
|
17
|
+
export function populateNavGridFromSolids(grid, solids) {
|
|
18
|
+
const all = solids.all();
|
|
19
|
+
for (const solid of all)
|
|
20
|
+
grid.blockAabb(worldSolidFootprint(solid));
|
|
21
|
+
return all.length;
|
|
16
22
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Vec3 } from "../world/geometry.js";
|
|
2
|
+
/** Explicit traversable connection between two navigation polygons. */
|
|
3
|
+
export interface NavMeshLink {
|
|
4
|
+
from: number;
|
|
5
|
+
to: number;
|
|
6
|
+
cost?: number;
|
|
7
|
+
/** Where the link leaves `from`; defaults to that polygon's center. */
|
|
8
|
+
start?: Vec3;
|
|
9
|
+
/** Where the link lands in `to`; defaults to that polygon's center. */
|
|
10
|
+
end?: Vec3;
|
|
11
|
+
}
|
|
12
|
+
/** Serializable polygon navigation mesh data. Treat it as immutable once queried; queries cache derived geometry per object. */
|
|
13
|
+
export interface NavMeshData {
|
|
14
|
+
/** Flat xyz vertex coordinates. Polygon indices refer to triples in this array. */
|
|
15
|
+
verts: number[];
|
|
16
|
+
/** Convex polygons as vertex index lists. */
|
|
17
|
+
polys: number[][];
|
|
18
|
+
links: NavMeshLink[];
|
|
19
|
+
/** Area id per polygon, priced by {@link NavMeshQueryOptions.areaCosts}. */
|
|
20
|
+
areas?: number[];
|
|
21
|
+
}
|
|
22
|
+
/** Neighbor relationship for one navigation polygon. */
|
|
23
|
+
export interface NavMeshAdjacency {
|
|
24
|
+
neighbors: number[];
|
|
25
|
+
cost: number;
|
|
26
|
+
}
|
|
27
|
+
/** Route points and polygons selected through a navigation mesh. */
|
|
28
|
+
export interface NavMeshPath {
|
|
29
|
+
points: Vec3[];
|
|
30
|
+
polys: number[];
|
|
31
|
+
/** True when the search budget ran out and the route ends at the polygon nearest the goal. */
|
|
32
|
+
partial?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** Tunable pricing and bounds for a {@link NavMeshQuery}. */
|
|
35
|
+
export interface NavMeshQueryOptions {
|
|
36
|
+
/** Cost multiplier per area id; unlisted areas cost 1, and a negative or non-finite cost blocks the area. */
|
|
37
|
+
areaCosts?: Readonly<Record<number, number>>;
|
|
38
|
+
/** Most polygons one path search may expand before returning a partial path. Default 2048. */
|
|
39
|
+
maxNodes?: number;
|
|
40
|
+
}
|
|
41
|
+
/** Serializable tuning of a {@link NavMeshQuery}. */
|
|
42
|
+
export interface NavMeshQuerySnapshot {
|
|
43
|
+
areaCosts: Record<number, number>;
|
|
44
|
+
maxNodes: number;
|
|
45
|
+
}
|
|
46
|
+
/** Cached, allocation-light queries over one {@link NavMeshData}. */
|
|
47
|
+
export interface NavMeshQuery {
|
|
48
|
+
readonly mesh: NavMeshData;
|
|
49
|
+
/** Polygon nearest the point in 3D, so stacked floors resolve by height; null for an empty mesh. */
|
|
50
|
+
findPolygon(point: Vec3): number | null;
|
|
51
|
+
/** Closest point on the mesh surface, or null for an empty mesh. */
|
|
52
|
+
closestPoint(point: Vec3): Vec3 | null;
|
|
53
|
+
/** Cheapest polygon corridor by A*, straightened with a portal funnel. */
|
|
54
|
+
findPath(from: Vec3, to: Vec3): NavMeshPath | null;
|
|
55
|
+
/** True when the straight segment stays on walkable, unblocked polygons. */
|
|
56
|
+
raycast(from: Vec3, to: Vec3): boolean;
|
|
57
|
+
retune(patch: NavMeshQueryOptions): void;
|
|
58
|
+
snapshot(): NavMeshQuerySnapshot;
|
|
59
|
+
restore(next: NavMeshQuerySnapshot): void;
|
|
60
|
+
}
|
|
61
|
+
/** Build polygon adjacency from shared edges and explicit off-mesh links. */
|
|
62
|
+
export declare function buildNavAdjacency(mesh: NavMeshData): NavMeshAdjacency[];
|
|
63
|
+
/**
|
|
64
|
+
* Create a cached query over a nav mesh: height-aware polygon lookup through a uniform grid, binary-heap A*
|
|
65
|
+
* priced by area costs and bounded by `maxNodes`, portal-funnel path straightening, and edge-walking raycasts.
|
|
66
|
+
* @capability navmesh-query route, snap, and raycast on a polygon navmesh with retunable area costs and a bounded search
|
|
67
|
+
*/
|
|
68
|
+
export declare function createNavMeshQuery(mesh: NavMeshData, options?: NavMeshQueryOptions): NavMeshQuery;
|
|
69
|
+
/** Return the closest point on the mesh surface, or null for an empty mesh. */
|
|
70
|
+
export declare function closestPoint(mesh: NavMeshData, point: Vec3): Vec3 | null;
|
|
71
|
+
/** A* over polygon portals with default area costs, straightened by a portal funnel. Use {@link createNavMeshQuery} to price areas. */
|
|
72
|
+
export declare function findPath(mesh: NavMeshData, from: Vec3, to: Vec3): NavMeshPath | null;
|
|
73
|
+
/** True when the segment remains over walkable polygons. */
|
|
74
|
+
export declare function raycastNav(mesh: NavMeshData, from: Vec3, to: Vec3): boolean;
|