@jgengine/core 0.11.0 → 0.13.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 +52 -0
- package/dist/ai/populationDirector.d.ts +103 -0
- package/dist/ai/populationDirector.js +190 -0
- package/dist/ai/pursuit.d.ts +56 -0
- package/dist/ai/pursuit.js +53 -0
- package/dist/authoring.d.ts +1 -1
- package/dist/authoring.js +1 -1
- package/dist/combat/effects.d.ts +11 -4
- package/dist/combat/effects.js +24 -17
- package/dist/combat/magazine.d.ts +13 -0
- package/dist/combat/magazine.js +27 -0
- package/dist/combat/vfxPresets.d.ts +176 -0
- package/dist/combat/vfxPresets.js +74 -0
- package/dist/combat/weaponFire.d.ts +114 -0
- package/dist/combat/weaponFire.js +96 -0
- package/dist/combat.d.ts +5 -2
- package/dist/combat.js +4 -1
- package/dist/devtools/controls.d.ts +38 -0
- package/dist/devtools/controls.js +181 -0
- package/dist/devtools/devtools.d.ts +5 -197
- package/dist/devtools/devtools.js +38 -774
- package/dist/devtools/discover.d.ts +32 -0
- package/dist/devtools/discover.js +240 -0
- package/dist/devtools/fallbackSeams.d.ts +50 -0
- package/dist/devtools/fallbackSeams.js +111 -0
- package/dist/devtools/frame.d.ts +15 -0
- package/dist/devtools/frame.js +247 -0
- package/dist/devtools/logs.d.ts +15 -0
- package/dist/devtools/logs.js +86 -0
- package/dist/devtools/overrides.d.ts +16 -0
- package/dist/devtools/overrides.js +66 -0
- package/dist/devtools/types.d.ts +212 -0
- package/dist/devtools/types.js +1 -0
- package/dist/devtools/urlFlags.d.ts +22 -0
- package/dist/devtools/urlFlags.js +62 -0
- package/dist/economy/auctionBook.d.ts +122 -0
- package/dist/economy/auctionBook.js +213 -0
- package/dist/economy/priceHistory.d.ts +44 -0
- package/dist/economy/priceHistory.js +89 -0
- package/dist/economy/unlockPoints.d.ts +92 -0
- package/dist/economy/unlockPoints.js +103 -0
- package/dist/editor/commandApply.d.ts +5 -0
- package/dist/editor/commandApply.js +755 -0
- package/dist/editor/commands.d.ts +48 -3
- package/dist/editor/commands.js +40 -754
- package/dist/editor/directives.d.ts +94 -0
- package/dist/editor/directives.js +206 -0
- package/dist/editor/document.d.ts +37 -2
- package/dist/editor/document.js +422 -6
- package/dist/editor/entityCatalog.d.ts +42 -0
- package/dist/editor/entityCatalog.js +101 -0
- package/dist/editor/environment.d.ts +74 -0
- package/dist/editor/environment.js +169 -0
- package/dist/editor/index.d.ts +26 -1
- package/dist/editor/index.js +8 -1
- package/dist/editor/minimap.d.ts +31 -0
- package/dist/editor/minimap.js +73 -0
- package/dist/editor/streamer.d.ts +66 -0
- package/dist/editor/streamer.js +68 -0
- package/dist/editor/types.d.ts +143 -0
- package/dist/editor/world.d.ts +136 -0
- package/dist/editor/world.js +303 -0
- package/dist/game/breeding.d.ts +161 -0
- package/dist/game/breeding.js +181 -0
- package/dist/game/cameraConfig.d.ts +451 -0
- package/dist/game/cameraConfig.js +1 -0
- package/dist/game/clipRoles.d.ts +51 -0
- package/dist/game/clipRoles.js +142 -0
- package/dist/game/defineGame.d.ts +16 -9
- package/dist/game/defineGame.js +14 -6
- package/dist/game/defineSystem.d.ts +2 -0
- package/dist/game/defineSystem.js +2 -0
- package/dist/game/events.d.ts +28 -0
- package/dist/game/partAnimation.d.ts +78 -0
- package/dist/game/partAnimation.js +147 -0
- package/dist/game/playableGame.d.ts +72 -440
- package/dist/game/playableGame.js +1 -1
- package/dist/game/progression.d.ts +35 -0
- package/dist/game/progression.js +22 -1
- package/dist/game/quest.js +1 -3
- package/dist/game/tribe.d.ts +184 -0
- package/dist/game/tribe.js +432 -0
- package/dist/gameplay.d.ts +3 -1
- package/dist/gameplay.js +3 -1
- package/dist/inventory/encumbrance.d.ts +69 -0
- package/dist/inventory/encumbrance.js +68 -0
- package/dist/inventory/inventoryModel.d.ts +24 -8
- package/dist/inventory/inventoryModel.js +47 -8
- package/dist/item/durability.js +1 -3
- package/dist/meta/changelog.d.ts +1 -1
- package/dist/meta/changelog.js +48 -1
- package/dist/movement/movementModel.d.ts +15 -1
- package/dist/movement/movementModel.js +33 -15
- package/dist/movement/playerMovement.js +102 -2
- package/dist/multiplayer/combatSnapshot.js +13 -8
- package/dist/multiplayer/presenceModel.d.ts +2 -0
- package/dist/multiplayer/presenceModel.js +8 -0
- package/dist/physics/drivableVehicle.d.ts +2 -0
- package/dist/physics/drivableVehicle.js +1 -1
- package/dist/physics/flightDynamics.d.ts +82 -0
- package/dist/physics/flightDynamics.js +165 -0
- package/dist/physics/gravityField.d.ts +25 -0
- package/dist/physics/gravityField.js +41 -0
- package/dist/physics/kinematicVehicle.d.ts +87 -0
- package/dist/physics/kinematicVehicle.js +193 -11
- package/dist/physics/physicsWorld.d.ts +26 -0
- package/dist/physics/physicsWorld.js +109 -117
- package/dist/physics/vehicleObstacles.d.ts +44 -0
- package/dist/physics/vehicleObstacles.js +115 -0
- package/dist/random/rng.d.ts +4 -1
- package/dist/random/rng.js +4 -1
- package/dist/runtime/adapter.d.ts +13 -0
- package/dist/runtime/adapter.js +13 -0
- package/dist/runtime/context/combat.d.ts +51 -0
- package/dist/runtime/context/combat.js +131 -0
- package/dist/runtime/context/combatFx.js +15 -5
- package/dist/runtime/context/deathLoot.d.ts +30 -0
- package/dist/runtime/context/deathLoot.js +39 -0
- package/dist/runtime/context/player.d.ts +48 -0
- package/dist/runtime/context/player.js +125 -0
- package/dist/runtime/context/scene.d.ts +60 -0
- package/dist/runtime/context/scene.js +329 -0
- package/dist/runtime/context/snapshotCodecs.d.ts +12 -0
- package/dist/runtime/context/snapshotCodecs.js +26 -0
- package/dist/runtime/descriptors/baseline.js +26 -3
- package/dist/runtime/descriptors/features.d.ts +5 -0
- package/dist/runtime/descriptors/features.js +20 -2
- package/dist/runtime/gameContext.d.ts +2 -428
- package/dist/runtime/gameContext.js +133 -500
- package/dist/runtime/gameContextTypes.d.ts +500 -0
- package/dist/runtime/gameContextTypes.js +1 -0
- package/dist/runtime/headlessRunner.d.ts +17 -2
- package/dist/runtime/headlessRunner.js +15 -0
- package/dist/runtime/hostPolicy.d.ts +51 -0
- package/dist/runtime/hostPolicy.js +68 -0
- package/dist/runtime/hostedGameRunner.d.ts +3 -1
- package/dist/runtime/hostedGameRunner.js +1 -0
- package/dist/runtime/hostedWorldSession.d.ts +3 -1
- package/dist/runtime/hostedWorldSession.js +1 -0
- package/dist/runtime/worldSnapshot.d.ts +13 -1
- package/dist/runtime/worldSnapshot.js +15 -3
- package/dist/scene/assetCatalog.d.ts +7 -0
- package/dist/scene/assetSpace.js +1 -3
- package/dist/scene/authoredTriggers.d.ts +50 -0
- package/dist/scene/authoredTriggers.js +114 -0
- package/dist/scene/builtinSceneKinds.js +8 -3
- package/dist/scene/colliders.d.ts +79 -0
- package/dist/scene/colliders.js +170 -0
- package/dist/scene/collisionMesh.d.ts +94 -0
- package/dist/scene/collisionMesh.js +699 -0
- package/dist/scene/companion.d.ts +147 -0
- package/dist/scene/companion.js +193 -0
- package/dist/scene/entityStats.d.ts +7 -9
- package/dist/scene/entityStats.js +19 -15
- package/dist/scene/sceneKinds.d.ts +16 -0
- package/dist/scene/sceneKinds.js +4 -0
- package/dist/scene/sceneRaycast.js +15 -0
- package/dist/stats/spawnLevelStats.d.ts +110 -0
- package/dist/stats/spawnLevelStats.js +140 -0
- package/dist/stats/statModifiers.d.ts +16 -0
- package/dist/stats/statModifiers.js +30 -1
- package/dist/stats/statPool.d.ts +70 -0
- package/dist/stats/statPool.js +62 -0
- package/dist/store/changeSignal.d.ts +3 -0
- package/dist/store/changeSignal.js +2 -0
- package/dist/store/observableKeyedStore.d.ts +2 -0
- package/dist/store/observableKeyedStore.js +1 -0
- package/dist/survival/decayMeter.js +1 -3
- package/dist/survival/regionHealth.js +1 -3
- package/dist/ui/hudLayout.d.ts +5 -0
- package/dist/ui/hudLayout.js +17 -1
- package/dist/ui/panelModel.d.ts +120 -0
- package/dist/ui/panelModel.js +168 -0
- package/dist/ui.d.ts +1 -0
- package/dist/ui.js +1 -0
- package/dist/world/authoredEntities.d.ts +29 -0
- package/dist/world/authoredEntities.js +29 -0
- package/dist/world/authoredObjects.d.ts +15 -1
- package/dist/world/authoredObjects.js +13 -1
- package/dist/world/authoredSpawn.d.ts +39 -0
- package/dist/world/authoredSpawn.js +37 -0
- package/dist/world/buildSockets.d.ts +152 -0
- package/dist/world/buildSockets.js +188 -0
- package/dist/world/buildingLots.d.ts +84 -0
- package/dist/world/buildingLots.js +119 -0
- package/dist/world/buildings.d.ts +6 -0
- package/dist/world/cityBlocks.d.ts +152 -0
- package/dist/world/cityBlocks.js +670 -0
- package/dist/world/cityContent.d.ts +77 -0
- package/dist/world/cityContent.js +261 -0
- package/dist/world/cityGenerator.d.ts +41 -0
- package/dist/world/cityGenerator.js +58 -0
- package/dist/world/cityGeometry.d.ts +114 -0
- package/dist/world/cityGeometry.js +573 -0
- package/dist/world/cityKind.d.ts +314 -0
- package/dist/world/cityKind.js +1578 -0
- package/dist/world/environmentSummary.js +57 -1
- package/dist/world/features.d.ts +53 -5
- package/dist/world/features.js +15 -3
- package/dist/world/grassKind.js +2 -2
- package/dist/world/markers.d.ts +50 -4
- package/dist/world/markers.js +49 -0
- package/dist/world/massing.js +1 -1
- package/dist/world/minimapBake.d.ts +78 -0
- package/dist/world/minimapBake.js +208 -0
- package/dist/world/minimapTrack.d.ts +17 -0
- package/dist/world/minimapTrack.js +22 -0
- package/dist/world/place.d.ts +166 -0
- package/dist/world/place.js +96 -0
- package/dist/world/placeAsset.js +3 -1
- package/dist/world/poleLineKind.d.ts +40 -0
- package/dist/world/poleLineKind.js +97 -0
- package/dist/world/polyline.js +9 -2
- package/dist/world/resourceNode.d.ts +109 -0
- package/dist/world/resourceNode.js +140 -0
- package/dist/world/roads.d.ts +19 -2
- package/dist/world/roads.js +60 -3
- package/dist/world/scatter.js +2 -20
- package/dist/world/streetGenerator.d.ts +159 -0
- package/dist/world/streetGenerator.js +684 -0
- package/dist/world/streets.d.ts +103 -1
- package/dist/world/streets.js +273 -0
- package/dist/world/terraform.js +58 -88
- package/dist/world/terrain.d.ts +65 -1
- package/dist/world/terrain.js +119 -2
- package/dist/world.d.ts +14 -5
- package/dist/world.js +12 -3
- package/package.json +1 -1
- package/skills/game-design/SKILL.md +28 -0
- package/skills/game-design/agents/openai.yaml +4 -0
- package/skills/game-design/references/application-playbook.md +170 -0
- package/skills/game-design/references/field-guide.md +288 -0
- package/skills/jgengine/SKILL.md +8 -4
- package/skills/jgengine/api.md +182 -81
- package/skills/jgengine/capabilities.md +104 -2
- package/skills/jgengine/recipes/minimal-game.md +88 -0
- package/skills/jgengine-combat/SKILL.md +19 -1
- package/skills/jgengine-combat/api.md +75 -2
- package/skills/jgengine-combat/capabilities.md +61 -1
- package/skills/jgengine-combat/recipes/portable-damage-effects.md +197 -0
- package/skills/jgengine-combat/recipes/portable-runtime-state.md +154 -0
- package/skills/jgengine-combat/recipes/portable-stat-pools.md +122 -0
- package/skills/jgengine-combat/recipes/portable-weapon-plumbing.md +156 -0
- package/skills/jgengine-combat/recipes/visible-attacks.md +81 -0
- package/skills/jgengine-combat/reference.md +33 -4
- package/skills/jgengine-gameplay/SKILL.md +8 -0
- package/skills/jgengine-gameplay/api.md +182 -26
- package/skills/jgengine-gameplay/capabilities.md +96 -2
- package/skills/jgengine-gameplay/recipes/portable-xp-leveling.md +168 -0
- package/skills/jgengine-gameplay/reference-systems.md +10 -5
- package/skills/jgengine-world/SKILL.md +13 -0
- package/skills/jgengine-world/api.md +453 -21
- package/skills/jgengine-world/capabilities.md +112 -2
- package/skills/jgengine-world/recipes/commanding-entities.md +128 -0
- package/skills/jgengine-world/reference.md +43 -4
- package/skills/jgengine/reference-cartridge.md +0 -72
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
export interface CameraFollowState {
|
|
2
|
+
entityId: string;
|
|
3
|
+
target: {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
z: number;
|
|
7
|
+
};
|
|
8
|
+
camera: {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
z: number;
|
|
12
|
+
};
|
|
13
|
+
distance: number;
|
|
14
|
+
}
|
|
15
|
+
export interface FirstPersonCameraConfig {
|
|
16
|
+
/** Camera height above the followed entity's origin. Default 1.6. */
|
|
17
|
+
eyeHeight?: number;
|
|
18
|
+
/** Mouse-look radians per pixel of pointer movement. Default 0.0025. */
|
|
19
|
+
sensitivity?: number;
|
|
20
|
+
/** Clamp on look pitch in radians (± from horizon). Default 1.45. */
|
|
21
|
+
maxPitch?: number;
|
|
22
|
+
/** Show the centered crosshair overlay. Default true. */
|
|
23
|
+
reticle?: boolean;
|
|
24
|
+
/** Render a viewmodel in view: the built-in three-mesh gun, or `PlayableGame.viewmodel` when set (#542). `false` renders no viewmodel regardless of `PlayableGame.viewmodel`. Default true. */
|
|
25
|
+
viewmodel?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Which camera rig the shell mounts. Every rig accepts `followEntityId: null`
|
|
29
|
+
* (avatar-less games — city-builders, card games, auto-battlers — still get a
|
|
30
|
+
* camera). Rigs are tuned through their config block below, never by writing
|
|
31
|
+
* camera positions from `onTick`.
|
|
32
|
+
* - `orbit` — third-person chase (the historical default; `perspective: "third"`).
|
|
33
|
+
* - `first` — pointer-lock mouse-look (`perspective: "first"`).
|
|
34
|
+
* - `topDown` — fixed height/pitch/yaw with decoupled follow (ARPG iso, top-down).
|
|
35
|
+
* - `rts` — free-pan / edge-scroll / rotate / zoom, optional follow.
|
|
36
|
+
* - `shoulder` — over-the-shoulder with ADS transition + shoulder swap.
|
|
37
|
+
* - `lockOn` — yaw bound to the player→target vector; move axis becomes strafe.
|
|
38
|
+
* - `chase` — speed-reactive vehicle chase (speed→FOV, spring arm, shake) + cockpit/hood/rear views.
|
|
39
|
+
* - `observer` — detached spectator/photo cam bound to any entity or fixed point; never reads player input.
|
|
40
|
+
* - `turntable` — slow auto-orbit of a fixed point: a rotating display stand for a scene. The friendly, flat spelling of `observer`'s point-orbit mode; providing `camera.turntable` selects it without an explicit `rig`.
|
|
41
|
+
* - `sideScroll` — fixed lateral follow (2.5D platformer/beat-'em-up side view); reads no player input.
|
|
42
|
+
* - `inspection` — model-viewer / editor rig (#207.7, #866): middle-drag pan, right-drag orbit, scroll zoom toward a configurable anchor; orbits a fixed point, reads no player/entity input.
|
|
43
|
+
* - `none` — no camera rig is mounted; use for HUD-only presentations or a game that manages its own camera.
|
|
44
|
+
*/
|
|
45
|
+
export type CameraRigKind = "orbit" | "first" | "topDown" | "rts" | "shoulder" | "lockOn" | "chase" | "observer" | "turntable" | "sideScroll" | "inspection" | "none";
|
|
46
|
+
/** Canvas camera projection. "orthographic" renders a flat 2D-style view (side-scrollers, falling-block puzzles) — pair with `rig: "sideScroll"`; default "perspective". */
|
|
47
|
+
export type CameraProjection = "perspective" | "orthographic";
|
|
48
|
+
/** Fixed lateral 2.5D follow (side-on platformer cam): the camera sits perpendicular to the travel axis, tracks the followed entity, and never reads player look input. */
|
|
49
|
+
export interface SideScrollCameraConfig {
|
|
50
|
+
/** World axis the action travels along; the camera watches from the perpendicular side. Default "x". */
|
|
51
|
+
axis?: "x" | "z";
|
|
52
|
+
/** Camera distance from the followed entity along the perpendicular axis. Default 10. */
|
|
53
|
+
distance?: number;
|
|
54
|
+
/** Camera height above the followed entity. Default 3. */
|
|
55
|
+
height?: number;
|
|
56
|
+
/** Height of the look point above the entity. Default 1. */
|
|
57
|
+
lookHeight?: number;
|
|
58
|
+
/** Per-second smoothing factor for the follow (0 hard-locks). Default 8. */
|
|
59
|
+
followSmoothing?: number;
|
|
60
|
+
fov?: number;
|
|
61
|
+
}
|
|
62
|
+
/** Fixed top-down / isometric rig (#23) — height/pitch/yaw + decoupled follow. */
|
|
63
|
+
export interface TopDownCameraConfig {
|
|
64
|
+
/** Camera height above the follow point. Default 18. */
|
|
65
|
+
height?: number;
|
|
66
|
+
/** Elevation of the camera above the ground plane in radians (PI/2 = straight down, near 0 = grazing; values below 0.05 clamp to 0.05). Default ~1.02 (~58°, ARPG iso). */
|
|
67
|
+
pitch?: number;
|
|
68
|
+
/** Fixed azimuth in radians; ~PI/4 reads as isometric, 0 as straight top-down. Default PI/4. */
|
|
69
|
+
yaw?: number;
|
|
70
|
+
/** Horizontal look offset applied to the follow point. */
|
|
71
|
+
targetOffset?: {
|
|
72
|
+
x?: number;
|
|
73
|
+
y?: number;
|
|
74
|
+
z?: number;
|
|
75
|
+
};
|
|
76
|
+
/** Exponential follow smoothing (higher = snappier, decoupled from any orbit drag). Default 8. */
|
|
77
|
+
followSmoothing?: number;
|
|
78
|
+
/** Scroll zoom bounds as a height multiplier. */
|
|
79
|
+
zoom?: {
|
|
80
|
+
min?: number;
|
|
81
|
+
max?: number;
|
|
82
|
+
speed?: number;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** Free-pan / edge-scroll RTS rig (#24) — pan/rotate/zoom independent of any avatar. */
|
|
86
|
+
export interface RtsCameraConfig extends TopDownCameraConfig {
|
|
87
|
+
/** WASD / arrow pan speed in world units per second. Default 24. */
|
|
88
|
+
panSpeed?: number;
|
|
89
|
+
/** Edge-scroll when the pointer nears a screen edge; number sets the margin fraction. Default true. */
|
|
90
|
+
edgeScroll?: boolean | {
|
|
91
|
+
margin?: number;
|
|
92
|
+
speed?: number;
|
|
93
|
+
};
|
|
94
|
+
/** Yaw rotate speed (radians/sec) for rotate keys / middle-drag. Default 1.4. */
|
|
95
|
+
rotateSpeed?: number;
|
|
96
|
+
/** World-space clamp for the pan center. */
|
|
97
|
+
bounds?: {
|
|
98
|
+
minX?: number;
|
|
99
|
+
maxX?: number;
|
|
100
|
+
minZ?: number;
|
|
101
|
+
maxZ?: number;
|
|
102
|
+
};
|
|
103
|
+
/** Start centered on this world point when there is no follow target. */
|
|
104
|
+
start?: {
|
|
105
|
+
x?: number;
|
|
106
|
+
z?: number;
|
|
107
|
+
};
|
|
108
|
+
/** Read WASD/arrow pan, edge-scroll, Q/E rotate, and wheel zoom. `false` sits static at the start/bounds position — a backdrop camera, no input at all. Default true. */
|
|
109
|
+
pan?: boolean;
|
|
110
|
+
}
|
|
111
|
+
/** Over-the-shoulder combat rig (#25) — offset, ADS, shoulder swap, decoupled reticle. */
|
|
112
|
+
export interface ShoulderCameraConfig {
|
|
113
|
+
/** Lateral shoulder offset (world units, sign flips on swap). Default 0.6. */
|
|
114
|
+
shoulderOffset?: number;
|
|
115
|
+
/** Vertical offset above the follow point. Default 1.6. */
|
|
116
|
+
heightOffset?: number;
|
|
117
|
+
/** Boom distance behind the shoulder. Default 3.2. */
|
|
118
|
+
distance?: number;
|
|
119
|
+
/** Starting shoulder side. Default "right". */
|
|
120
|
+
side?: "left" | "right";
|
|
121
|
+
/** Aim-down-sights framing, blended in while `aim` is held. */
|
|
122
|
+
ads?: {
|
|
123
|
+
distance?: number;
|
|
124
|
+
shoulderOffset?: number;
|
|
125
|
+
fov?: number;
|
|
126
|
+
heightOffset?: number;
|
|
127
|
+
};
|
|
128
|
+
/** ADS blend speed (higher = snappier). Default 10. */
|
|
129
|
+
adsTransitionSpeed?: number;
|
|
130
|
+
/** Screen-space reticle offset (fraction of viewport), decoupled from camera center. */
|
|
131
|
+
reticleOffset?: {
|
|
132
|
+
x?: number;
|
|
133
|
+
y?: number;
|
|
134
|
+
};
|
|
135
|
+
/** Mouse-look sensitivity (radians per pixel). Default 0.0025. */
|
|
136
|
+
sensitivity?: number;
|
|
137
|
+
/** Base field of view. Default 55. */
|
|
138
|
+
fov?: number;
|
|
139
|
+
}
|
|
140
|
+
/** Lock-on / strafe rig (#26) — yaw bound to player→target, move axis becomes strafe. */
|
|
141
|
+
export interface LockOnCameraConfig {
|
|
142
|
+
/** Target instance id; when omitted the rig reads the follower's current `getTarget`. */
|
|
143
|
+
targetEntityId?: string;
|
|
144
|
+
/** Boom distance behind the player, away from the target. Default 5. */
|
|
145
|
+
distance?: number;
|
|
146
|
+
/** Camera height above the follow point. Default 2.4. */
|
|
147
|
+
height?: number;
|
|
148
|
+
/** Height of the framed look point above the midpoint. Default 1.2. */
|
|
149
|
+
lookHeight?: number;
|
|
150
|
+
/** 0 frames the player, 1 frames the target, 0.5 the midpoint. Default 0.5. */
|
|
151
|
+
framingBias?: number;
|
|
152
|
+
/** Exponential yaw smoothing toward the player→target vector. Default 9. */
|
|
153
|
+
yawSmoothing?: number;
|
|
154
|
+
}
|
|
155
|
+
/** Fixed interior view for the chase rig (#27). */
|
|
156
|
+
export type ChaseView = "chase" | "cockpit" | "hood" | "rear";
|
|
157
|
+
/** Speed-reactive vehicle chase rig (#27) — speed→FOV, spring arm, procedural shake, interior views. */
|
|
158
|
+
export interface ChaseCameraConfig {
|
|
159
|
+
/** Boom distance behind the vehicle. Default 6. */
|
|
160
|
+
distance?: number;
|
|
161
|
+
/** Camera height above the follow point. Default 2.6. */
|
|
162
|
+
height?: number;
|
|
163
|
+
/** Height of the look point above the follow point. Default 1.2. */
|
|
164
|
+
lookHeight?: number;
|
|
165
|
+
/** Spring-arm damping (higher = stiffer, less lag). Default 6. */
|
|
166
|
+
springDamping?: number;
|
|
167
|
+
/** Speed→FOV curve: FOV lerps from `base` to `max` as speed climbs to `speedForMax`. */
|
|
168
|
+
fov?: {
|
|
169
|
+
base?: number;
|
|
170
|
+
max?: number;
|
|
171
|
+
speedForMax?: number;
|
|
172
|
+
};
|
|
173
|
+
/** Procedural shake amplitude per unit of speed (adds to the trauma channel). Default 0.0. */
|
|
174
|
+
shakePerSpeed?: number;
|
|
175
|
+
/** Velocity-lead / predictive follow (#286.9): the rig aims `time` seconds ahead of the target along its velocity, clamped to `max` world units (default 4). */
|
|
176
|
+
lead?: {
|
|
177
|
+
time: number;
|
|
178
|
+
max?: number;
|
|
179
|
+
};
|
|
180
|
+
/** Roll into turns (#286.10): radians of camera roll per rad/s of the target's yaw rate, clamped to `max` (default 0.35), exponentially smoothed by `damping` (default 8). */
|
|
181
|
+
bank?: {
|
|
182
|
+
perYawRate: number;
|
|
183
|
+
max?: number;
|
|
184
|
+
damping?: number;
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* Drift-lag (#1051): when the target slides, rotate the chase anchor partway from
|
|
188
|
+
* its heading toward its travel (velocity) direction so the player sees the car's
|
|
189
|
+
* side while the framing stays stable. Omitting the block keeps the pure-heading
|
|
190
|
+
* behavior. `blend` (default 0.65) is the max fraction of the slip angle to
|
|
191
|
+
* follow, itself scaled by how far the slip has opened so straight-line driving
|
|
192
|
+
* is untouched; below `minSpeed` (default 4) planar speed the feature is off for
|
|
193
|
+
* parking-lot stability; reversing never swings the camera around. `response`
|
|
194
|
+
* (default 6) drives `1-exp(-response*dt)` smoothing toward the blended yaw.
|
|
195
|
+
*/
|
|
196
|
+
velocityYaw?: {
|
|
197
|
+
blend?: number;
|
|
198
|
+
minSpeed?: number;
|
|
199
|
+
response?: number;
|
|
200
|
+
};
|
|
201
|
+
/** Which view to mount. Default "chase". */
|
|
202
|
+
view?: ChaseView;
|
|
203
|
+
/** Local offset for cockpit/hood/rear seats (relative to the vehicle, +z forward). */
|
|
204
|
+
seatOffsets?: {
|
|
205
|
+
cockpit?: {
|
|
206
|
+
x?: number;
|
|
207
|
+
y?: number;
|
|
208
|
+
z?: number;
|
|
209
|
+
};
|
|
210
|
+
hood?: {
|
|
211
|
+
x?: number;
|
|
212
|
+
y?: number;
|
|
213
|
+
z?: number;
|
|
214
|
+
};
|
|
215
|
+
rear?: {
|
|
216
|
+
x?: number;
|
|
217
|
+
y?: number;
|
|
218
|
+
z?: number;
|
|
219
|
+
};
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
/** Detached spectator/photo cam (#120) — binds to any entity or fixed point, never reads player input. */
|
|
223
|
+
export interface ObserverCameraConfig {
|
|
224
|
+
/** What the observer looks at. Omit to stay on a fixed point at the origin (or `point`, if given). */
|
|
225
|
+
bind?: {
|
|
226
|
+
kind: "entity";
|
|
227
|
+
entityId: string;
|
|
228
|
+
} | {
|
|
229
|
+
kind: "point";
|
|
230
|
+
position: {
|
|
231
|
+
x: number;
|
|
232
|
+
y: number;
|
|
233
|
+
z: number;
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
/** Orbit distance from the bound subject. Default 8. */
|
|
237
|
+
distance?: number;
|
|
238
|
+
/** Camera height above the bound subject. Default 3. */
|
|
239
|
+
height?: number;
|
|
240
|
+
/** Height of the look point above the subject. Default 1.2. */
|
|
241
|
+
lookHeight?: number;
|
|
242
|
+
/** Radians/second of automatic orbit around the subject (CCTV-style sweep); 0 holds a fixed angle. Default 0.2. */
|
|
243
|
+
orbitSpeed?: number;
|
|
244
|
+
/** Starting orbit angle in radians. Default 0. */
|
|
245
|
+
startAngle?: number;
|
|
246
|
+
fov?: number;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Turntable / showcase rig — slowly auto-orbits a fixed world point (no player
|
|
250
|
+
* input), the way a museum turntable rotates an object on display. A flat,
|
|
251
|
+
* self-describing spelling of `observer`'s point-orbit mode: `target` names the
|
|
252
|
+
* point directly instead of `bind: { kind: "point", position }`. Set
|
|
253
|
+
* `camera.turntable` and the rig is inferred — you don't also write `rig`.
|
|
254
|
+
*/
|
|
255
|
+
export interface TurntableCameraConfig {
|
|
256
|
+
/** World point the camera circles. Default the world origin. */
|
|
257
|
+
target?: {
|
|
258
|
+
x: number;
|
|
259
|
+
y: number;
|
|
260
|
+
z: number;
|
|
261
|
+
};
|
|
262
|
+
/** Orbit radius from the target. Default 8. */
|
|
263
|
+
distance?: number;
|
|
264
|
+
/** Camera height above the target. Default 3. */
|
|
265
|
+
height?: number;
|
|
266
|
+
/** Height of the look point above the target. Default 1.2. */
|
|
267
|
+
lookHeight?: number;
|
|
268
|
+
/** Radians/second of rotation; 0 holds a fixed angle. Default 0.2. */
|
|
269
|
+
orbitSpeed?: number;
|
|
270
|
+
/** Starting angle in radians. Default 0. */
|
|
271
|
+
startAngle?: number;
|
|
272
|
+
fov?: number;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* How scroll-zoom re-anchors the view for the inspection rig (#207.7):
|
|
276
|
+
* - `target` — dolly toward the orbit target (classic OrbitControls behavior).
|
|
277
|
+
* - `cursor` — dolly toward the point under the pointer.
|
|
278
|
+
* - `center` — dolly toward the viewport center; equivalent to `target` for an
|
|
279
|
+
* OrbitControls-driven rig, since the camera always faces `target` and that
|
|
280
|
+
* point already projects to the exact center of the viewport.
|
|
281
|
+
*/
|
|
282
|
+
export type InspectionZoomAnchor = "target" | "cursor" | "center";
|
|
283
|
+
/** Model-viewer / inspection rig (#207.7) — orbit + pan + anchored zoom around a fixed point, never reads player input. */
|
|
284
|
+
export interface InspectionCameraConfig {
|
|
285
|
+
/** Where scroll-zoom re-anchors the view. Default "target". */
|
|
286
|
+
anchor?: InspectionZoomAnchor;
|
|
287
|
+
/** Orbit target (the point orbited/panned around). Default origin. */
|
|
288
|
+
target?: {
|
|
289
|
+
x?: number;
|
|
290
|
+
y?: number;
|
|
291
|
+
z?: number;
|
|
292
|
+
};
|
|
293
|
+
/** Camera distance from `target` used to seed the initial camera position when `initialPosition` is unset. Default 6. */
|
|
294
|
+
initialDistance?: number;
|
|
295
|
+
/** Explicit starting camera world position; overrides `initialDistance` when set. */
|
|
296
|
+
initialPosition?: {
|
|
297
|
+
x?: number;
|
|
298
|
+
y?: number;
|
|
299
|
+
z?: number;
|
|
300
|
+
};
|
|
301
|
+
minDistance?: number;
|
|
302
|
+
maxDistance?: number;
|
|
303
|
+
/** Vertical orbit clamp (radians). Unset allows a full pole-to-pole orbit, unlike the tighter default on the classic orbit rig. */
|
|
304
|
+
minPolarAngle?: number;
|
|
305
|
+
maxPolarAngle?: number;
|
|
306
|
+
/** Middle-mouse pan. Default true for this rig. */
|
|
307
|
+
pan?: boolean;
|
|
308
|
+
rotateSpeed?: number;
|
|
309
|
+
zoomSpeed?: number;
|
|
310
|
+
dampingFactor?: number;
|
|
311
|
+
}
|
|
312
|
+
/** One stop on a scripted camera path (#29). */
|
|
313
|
+
export interface CameraKeyframe {
|
|
314
|
+
position: {
|
|
315
|
+
x: number;
|
|
316
|
+
y: number;
|
|
317
|
+
z: number;
|
|
318
|
+
};
|
|
319
|
+
lookAt: {
|
|
320
|
+
x: number;
|
|
321
|
+
y: number;
|
|
322
|
+
z: number;
|
|
323
|
+
};
|
|
324
|
+
fov?: number;
|
|
325
|
+
/** Seconds to travel from the previous keyframe to this one. Default 1. */
|
|
326
|
+
duration?: number;
|
|
327
|
+
/** Interpolation into this keyframe. Default "smooth" (smoothstep ease). */
|
|
328
|
+
ease?: "linear" | "smooth";
|
|
329
|
+
}
|
|
330
|
+
/** Scripted keyframe / path player (#29). When set it overrides the active rig. */
|
|
331
|
+
export interface CinematicCameraConfig {
|
|
332
|
+
keyframes: readonly CameraKeyframe[];
|
|
333
|
+
/** Restart from the first keyframe after the last. Default false. */
|
|
334
|
+
loop?: boolean;
|
|
335
|
+
}
|
|
336
|
+
/** Camera-shake / trauma defaults (#28). Any rig reads the trauma channel; game systems feed it via `cameraShake()`. */
|
|
337
|
+
export interface CameraShakeConfig {
|
|
338
|
+
/** Positional shake amplitude at full trauma (world units). Default 0.5. */
|
|
339
|
+
maxOffset?: number;
|
|
340
|
+
/** Rotational shake amplitude at full trauma (radians). Default 0.06. */
|
|
341
|
+
maxRoll?: number;
|
|
342
|
+
/** Trauma decay per second (fraction). Default 1.6. */
|
|
343
|
+
decayPerSecond?: number;
|
|
344
|
+
/** Trauma→shake exponent; 2 = quadratic falloff so small hits are subtle. Default 2. */
|
|
345
|
+
exponent?: number;
|
|
346
|
+
/** Noise frequency (Hz) of the shake oscillation. Default 24. */
|
|
347
|
+
frequency?: number;
|
|
348
|
+
}
|
|
349
|
+
export declare const CAMERA_FRUSTUM_DEFAULTS: {
|
|
350
|
+
readonly fov: 55;
|
|
351
|
+
readonly near: 0.1;
|
|
352
|
+
readonly far: 300;
|
|
353
|
+
readonly zoom: 50;
|
|
354
|
+
};
|
|
355
|
+
/** Player-facing FOV preference applied across every perspective camera rig. Orthographic projections ignore it. */
|
|
356
|
+
export interface PlayerFovConfig {
|
|
357
|
+
/** Inclusive lower bound for the slider and persisted values. Default 40. */
|
|
358
|
+
min?: number;
|
|
359
|
+
/** Inclusive upper bound for the slider and persisted values. Default 120. */
|
|
360
|
+
max?: number;
|
|
361
|
+
/** Initial FOV when nothing is persisted. Defaults to `frustum.fov` or 55. */
|
|
362
|
+
default?: number;
|
|
363
|
+
/** Persist the preference in localStorage across reloads. Default true. */
|
|
364
|
+
persist?: boolean;
|
|
365
|
+
/** Show the shell FOV slider. Default true for perspective cameras; forced off for orthographic. */
|
|
366
|
+
control?: boolean;
|
|
367
|
+
}
|
|
368
|
+
/** Camera tuning for the shell's rig stack: pick the rig via `rig`, then tune it through its matching config block. All fields optional — the default is the third-person orbit rig. */
|
|
369
|
+
export interface GameCameraConfig {
|
|
370
|
+
/** Selects the rig — the one camera-selection knob. Overrides the legacy `perspective` shorthand. */
|
|
371
|
+
rig?: CameraRigKind;
|
|
372
|
+
/** Canvas camera projection. "orthographic" renders a flat 2D-style view (side-scrollers, falling-block puzzles) — pair with `rig: "sideScroll"`; default perspective. */
|
|
373
|
+
projection?: CameraProjection;
|
|
374
|
+
/** Render frustum overrides applied to the canvas camera. `far` defaults to 300 — raise it for worlds whose content spans more than a few hundred units, or distant scenery silently clips. `zoom` is the orthographic zoom in canvas pixels per world unit, read only when `projection` is "orthographic"; default 50. */
|
|
375
|
+
frustum?: {
|
|
376
|
+
fov?: number;
|
|
377
|
+
near?: number;
|
|
378
|
+
far?: number;
|
|
379
|
+
zoom?: number;
|
|
380
|
+
};
|
|
381
|
+
/** Universal player FOV preference (slider + persistence) for perspective rigs. Ignored when `projection` is `"orthographic"`. */
|
|
382
|
+
playerFov?: PlayerFovConfig;
|
|
383
|
+
/** @deprecated Legacy shorthand for `rig: "orbit" | "first"` — set `rig` instead. "third" mounts the orbit camera (default); "first" mounts pointer-lock mouse-look. */
|
|
384
|
+
perspective?: "third" | "first";
|
|
385
|
+
/** First-person tuning; only read when the rig resolves to "first". */
|
|
386
|
+
firstPerson?: FirstPersonCameraConfig;
|
|
387
|
+
/** Top-down / isometric tuning (#23); read when `rig: "topDown"`. */
|
|
388
|
+
topDown?: TopDownCameraConfig;
|
|
389
|
+
/** Free-pan / edge-scroll RTS tuning (#24); read when `rig: "rts"`. */
|
|
390
|
+
rts?: RtsCameraConfig;
|
|
391
|
+
/** Over-the-shoulder tuning (#25); read when `rig: "shoulder"`. */
|
|
392
|
+
shoulder?: ShoulderCameraConfig;
|
|
393
|
+
/** Lock-on / strafe tuning (#26); read when `rig: "lockOn"`. */
|
|
394
|
+
lockOn?: LockOnCameraConfig;
|
|
395
|
+
/** Vehicle chase tuning (#27); read when `rig: "chase"`. */
|
|
396
|
+
chase?: ChaseCameraConfig;
|
|
397
|
+
/** Detached spectator/photo cam tuning (#120); read when `rig: "observer"`. */
|
|
398
|
+
observer?: ObserverCameraConfig;
|
|
399
|
+
/** Turntable / showcase tuning; setting this selects the `turntable` rig on its own. */
|
|
400
|
+
turntable?: TurntableCameraConfig;
|
|
401
|
+
/** Fixed side-on follow tuning; read when `rig: "sideScroll"`. */
|
|
402
|
+
sideScroll?: SideScrollCameraConfig;
|
|
403
|
+
/** Model-viewer / inspection tuning (#207.7); read when `rig: "inspection"`. */
|
|
404
|
+
inspection?: InspectionCameraConfig;
|
|
405
|
+
/** Camera-shake / trauma channel defaults (#28); read by every rig. */
|
|
406
|
+
shake?: CameraShakeConfig;
|
|
407
|
+
/** Scripted keyframe path (#29); when set, plays over the active rig. */
|
|
408
|
+
cinematic?: CinematicCameraConfig;
|
|
409
|
+
/** Seconds to cross-fade the camera when the rig changes (#29). 0 hard-cuts. Default 0.6. */
|
|
410
|
+
transitionSeconds?: number;
|
|
411
|
+
minDistance?: number;
|
|
412
|
+
maxDistance?: number;
|
|
413
|
+
targetHeight?: number;
|
|
414
|
+
/** Extra offset on top of entity position for the orbit target. */
|
|
415
|
+
targetOffset?: {
|
|
416
|
+
x?: number;
|
|
417
|
+
y?: number;
|
|
418
|
+
z?: number;
|
|
419
|
+
};
|
|
420
|
+
initialDistance?: number;
|
|
421
|
+
initialHeight?: number;
|
|
422
|
+
/** Initial horizontal boom facing (radians): 0 = camera behind on -Z, PI = camera on +Z. Seeds the orbit rig; unset keeps the legacy -Z placement. */
|
|
423
|
+
initialYaw?: number;
|
|
424
|
+
/** Initial boom elevation (radians): 0 = level, positive = camera above the target looking down. Seeds the orbit rig; unset derives elevation from `initialHeight`/`initialDistance`. */
|
|
425
|
+
initialPitch?: number;
|
|
426
|
+
/** Lock orbit radius while the follow target moves (default true in shell). */
|
|
427
|
+
followLock?: boolean;
|
|
428
|
+
/** When false, orbit target stays fixed (cinematic / debug). Default true. */
|
|
429
|
+
followEnabled?: boolean;
|
|
430
|
+
/** Instance id to follow, or null for an avatar-less free camera; defaults to local player in the dev shell. */
|
|
431
|
+
followEntityId?: string | null;
|
|
432
|
+
/** Fired each frame after cameraFollow lock is applied. */
|
|
433
|
+
onCameraFollow?: (state: CameraFollowState) => void;
|
|
434
|
+
rotateSpeed?: number;
|
|
435
|
+
zoomSpeed?: number;
|
|
436
|
+
dampingFactor?: number;
|
|
437
|
+
targetSmoothing?: number;
|
|
438
|
+
dragTargetSmoothing?: number;
|
|
439
|
+
distanceSmoothing?: number;
|
|
440
|
+
/** Vertical look clamp (three.js polar angle, radians): 0 = top-down over the head, PI/2 = level, >PI/2 = look up from below. Widen for top-down or vertical aim; unset keeps the standard chase feel. */
|
|
441
|
+
minPolarAngle?: number;
|
|
442
|
+
maxPolarAngle?: number;
|
|
443
|
+
/** Signed boom-elevation clamp `[min, max]` (radians): min < 0 dips the camera below the target, max > 0 rises overhead. Maps onto `minPolarAngle`/`maxPolarAngle` (polar = PI/2 − pitch); explicit polar fields win. */
|
|
444
|
+
pitchClamp?: readonly [number, number];
|
|
445
|
+
/** Spring-arm occlusion for the orbit rig: pull the camera in past walls/terrain so it never clips inside geometry. Off unless `enabled`. */
|
|
446
|
+
collision?: {
|
|
447
|
+
enabled?: boolean;
|
|
448
|
+
padding?: number;
|
|
449
|
+
minTargetDistance?: number;
|
|
450
|
+
};
|
|
451
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const CAMERA_FRUSTUM_DEFAULTS = { fov: 55, near: 0.1, far: 300, zoom: 50 };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ModelAnimationConfig } from "./playableGame.js";
|
|
2
|
+
/**
|
|
3
|
+
* Semantic animation roles a GLB clip name can map to. Rigged packs name the same motion
|
|
4
|
+
* differently (`Idle` / `Walking_A` / `Armature|Run`); roles are the pack-agnostic vocabulary
|
|
5
|
+
* the engine defaults from.
|
|
6
|
+
*/
|
|
7
|
+
export type ClipRole = "idle" | "walk" | "run" | "attack" | "hit" | "death" | "jump" | "spawn" | "interact" | "cheer";
|
|
8
|
+
/**
|
|
9
|
+
* Keyword table driving {@link classifyClip}: lowercase keywords matched against a clip name's
|
|
10
|
+
* tokens (exact token match beats prefix match). Extend or replace per game/pack — the table is
|
|
11
|
+
* plain data, no genre assumptions.
|
|
12
|
+
*/
|
|
13
|
+
export interface ClipRoleTable {
|
|
14
|
+
readonly roles: Readonly<Partial<Record<ClipRole, readonly string[]>>>;
|
|
15
|
+
/** Tokens that disqualify a clip from classification entirely (e.g. `pose` for held-pose variants). */
|
|
16
|
+
readonly exclude?: readonly string[];
|
|
17
|
+
}
|
|
18
|
+
/** Default vocabulary covering KayKit, Quaternius, and Mixamo-style clip naming. */
|
|
19
|
+
export declare const DEFAULT_CLIP_ROLE_TABLE: ClipRoleTable;
|
|
20
|
+
/**
|
|
21
|
+
* Classify a single GLB clip name into a {@link ClipRole}, or `null` when nothing matches (or an
|
|
22
|
+
* exclusion token like `pose` disqualifies it). Deterministic: exact token matches beat prefix
|
|
23
|
+
* matches; remaining ties resolve by fixed role priority (death > hit > attack > … > idle).
|
|
24
|
+
*
|
|
25
|
+
* @capability clip-roles map a rigged asset's pack-specific clip name to its semantic animation role
|
|
26
|
+
*/
|
|
27
|
+
export declare function classifyClip(name: string, table?: ClipRoleTable): ClipRole | null;
|
|
28
|
+
/**
|
|
29
|
+
* Group a GLB's clip names by role. Each role's variants are sorted simplest-first — fewest name
|
|
30
|
+
* tokens, then lexicographic — so the canonical variant (`Idle` over `2H_Melee_Idle`, KayKit
|
|
31
|
+
* `Walking_A` over `Walking_B`) is always first: stable output for the same clip set regardless
|
|
32
|
+
* of source order.
|
|
33
|
+
*/
|
|
34
|
+
export declare function rolesFromClips(clips: readonly string[], table?: ClipRoleTable): Partial<Record<ClipRole, string[]>>;
|
|
35
|
+
/**
|
|
36
|
+
* Build the default `ModelConfig.animation` for a rigged asset from its catalog clip names:
|
|
37
|
+
* speed-driven idle/walk/run states plus hit/death/attack one-shots where identifiable. Returns
|
|
38
|
+
* `undefined` when no idle clip is identifiable — an ambiguous rig renders its bind pose rather
|
|
39
|
+
* than guessing. Walk falls back to idle when the pack has no walk clip.
|
|
40
|
+
*
|
|
41
|
+
* @capability clip-roles derive a complete default animation config from a rigged asset's clip names
|
|
42
|
+
*/
|
|
43
|
+
export declare function defaultAnimationForClips(clips: readonly string[], table?: ClipRoleTable): ModelAnimationConfig | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Collapse `ModelConfig.animation`'s widened union to a concrete playback config: explicit
|
|
46
|
+
* configs pass through, `"none"`/absent render the bind pose, and `"auto"` derives states and
|
|
47
|
+
* one-shots from the model's clip names via {@link defaultAnimationForClips}. The shell calls
|
|
48
|
+
* this with the loaded GLB's actual clip names, so `"auto"` works on any rigged model —
|
|
49
|
+
* catalog-resolved ids are stamped `"auto"` automatically.
|
|
50
|
+
*/
|
|
51
|
+
export declare function resolveAnimationConfig(animation: ModelAnimationConfig | "auto" | "none" | undefined, clips: readonly string[] | undefined, table?: ClipRoleTable): ModelAnimationConfig | undefined;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/** Tie-break priority when a name matches several roles at equal strength ("Idle_Attack" → attack). */
|
|
2
|
+
const ROLE_PRIORITY = [
|
|
3
|
+
"death",
|
|
4
|
+
"hit",
|
|
5
|
+
"attack",
|
|
6
|
+
"jump",
|
|
7
|
+
"spawn",
|
|
8
|
+
"interact",
|
|
9
|
+
"cheer",
|
|
10
|
+
"run",
|
|
11
|
+
"walk",
|
|
12
|
+
"idle",
|
|
13
|
+
];
|
|
14
|
+
/** Default vocabulary covering KayKit, Quaternius, and Mixamo-style clip naming. */
|
|
15
|
+
export const DEFAULT_CLIP_ROLE_TABLE = {
|
|
16
|
+
roles: {
|
|
17
|
+
idle: ["idle"],
|
|
18
|
+
walk: ["walk"],
|
|
19
|
+
run: ["run", "sprint", "jog"],
|
|
20
|
+
attack: ["attack", "punch", "slash", "shoot", "chop", "stab", "cast", "swing", "strike", "kick", "throw"],
|
|
21
|
+
hit: ["hit", "receive", "impact", "hurt", "damage"],
|
|
22
|
+
death: ["death", "die", "dead", "dying"],
|
|
23
|
+
jump: ["jump"],
|
|
24
|
+
spawn: ["spawn"],
|
|
25
|
+
interact: ["interact", "use", "pickup"],
|
|
26
|
+
cheer: ["cheer", "victory", "dance", "wave"],
|
|
27
|
+
},
|
|
28
|
+
exclude: ["pose"],
|
|
29
|
+
};
|
|
30
|
+
/** Lowercased tokens of a clip name: rig prefixes (`Armature|`, `mixamo.com|`) stripped, split on `_ - . space`. */
|
|
31
|
+
function tokenize(name) {
|
|
32
|
+
const segments = name.split("|");
|
|
33
|
+
const last = segments[segments.length - 1] ?? name;
|
|
34
|
+
return last
|
|
35
|
+
.toLowerCase()
|
|
36
|
+
.split(/[_\-. ]+/)
|
|
37
|
+
.filter((token) => token.length > 0);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Classify a single GLB clip name into a {@link ClipRole}, or `null` when nothing matches (or an
|
|
41
|
+
* exclusion token like `pose` disqualifies it). Deterministic: exact token matches beat prefix
|
|
42
|
+
* matches; remaining ties resolve by fixed role priority (death > hit > attack > … > idle).
|
|
43
|
+
*
|
|
44
|
+
* @capability clip-roles map a rigged asset's pack-specific clip name to its semantic animation role
|
|
45
|
+
*/
|
|
46
|
+
export function classifyClip(name, table = DEFAULT_CLIP_ROLE_TABLE) {
|
|
47
|
+
const tokens = tokenize(name);
|
|
48
|
+
if (tokens.length === 0)
|
|
49
|
+
return null;
|
|
50
|
+
const exclude = table.exclude ?? [];
|
|
51
|
+
for (const token of tokens) {
|
|
52
|
+
if (exclude.includes(token))
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
let best = null;
|
|
56
|
+
for (const role of ROLE_PRIORITY) {
|
|
57
|
+
const keywords = table.roles[role] ?? [];
|
|
58
|
+
let score = 0;
|
|
59
|
+
for (const token of tokens) {
|
|
60
|
+
for (const keyword of keywords) {
|
|
61
|
+
if (token === keyword)
|
|
62
|
+
score = Math.max(score, 2);
|
|
63
|
+
else if (token.startsWith(keyword))
|
|
64
|
+
score = Math.max(score, 1);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (score > 0 && (best === null || score > best.score))
|
|
68
|
+
best = { role, score };
|
|
69
|
+
}
|
|
70
|
+
return best?.role ?? null;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Group a GLB's clip names by role. Each role's variants are sorted simplest-first — fewest name
|
|
74
|
+
* tokens, then lexicographic — so the canonical variant (`Idle` over `2H_Melee_Idle`, KayKit
|
|
75
|
+
* `Walking_A` over `Walking_B`) is always first: stable output for the same clip set regardless
|
|
76
|
+
* of source order.
|
|
77
|
+
*/
|
|
78
|
+
export function rolesFromClips(clips, table = DEFAULT_CLIP_ROLE_TABLE) {
|
|
79
|
+
const roles = {};
|
|
80
|
+
for (const clip of clips) {
|
|
81
|
+
const role = classifyClip(clip, table);
|
|
82
|
+
if (role === null)
|
|
83
|
+
continue;
|
|
84
|
+
(roles[role] ??= []).push(clip);
|
|
85
|
+
}
|
|
86
|
+
for (const variants of Object.values(roles)) {
|
|
87
|
+
variants.sort((a, b) => tokenize(a).length - tokenize(b).length || a.localeCompare(b));
|
|
88
|
+
}
|
|
89
|
+
return roles;
|
|
90
|
+
}
|
|
91
|
+
/** A role's variants as a one-shot binding: single name stays a string, several become a random-variant array. */
|
|
92
|
+
function oneShotSpec(variants) {
|
|
93
|
+
if (variants === undefined || variants.length === 0)
|
|
94
|
+
return undefined;
|
|
95
|
+
return variants.length === 1 ? variants[0] : variants;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Build the default `ModelConfig.animation` for a rigged asset from its catalog clip names:
|
|
99
|
+
* speed-driven idle/walk/run states plus hit/death/attack one-shots where identifiable. Returns
|
|
100
|
+
* `undefined` when no idle clip is identifiable — an ambiguous rig renders its bind pose rather
|
|
101
|
+
* than guessing. Walk falls back to idle when the pack has no walk clip.
|
|
102
|
+
*
|
|
103
|
+
* @capability clip-roles derive a complete default animation config from a rigged asset's clip names
|
|
104
|
+
*/
|
|
105
|
+
export function defaultAnimationForClips(clips, table = DEFAULT_CLIP_ROLE_TABLE) {
|
|
106
|
+
const roles = rolesFromClips(clips, table);
|
|
107
|
+
const idle = roles.idle?.[0];
|
|
108
|
+
if (idle === undefined)
|
|
109
|
+
return undefined;
|
|
110
|
+
const walk = roles.walk?.[0] ?? idle;
|
|
111
|
+
const run = roles.run?.[0];
|
|
112
|
+
const oneShots = {};
|
|
113
|
+
const hit = oneShotSpec(roles.hit);
|
|
114
|
+
const death = oneShotSpec(roles.death);
|
|
115
|
+
const attack = oneShotSpec(roles.attack);
|
|
116
|
+
if (hit !== undefined)
|
|
117
|
+
oneShots.hit = hit;
|
|
118
|
+
if (death !== undefined)
|
|
119
|
+
oneShots.death = death;
|
|
120
|
+
if (attack !== undefined)
|
|
121
|
+
oneShots.attack = attack;
|
|
122
|
+
return {
|
|
123
|
+
states: { idle, walk, ...(run === undefined ? {} : { run }) },
|
|
124
|
+
...(Object.keys(oneShots).length === 0 ? {} : { oneShots }),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Collapse `ModelConfig.animation`'s widened union to a concrete playback config: explicit
|
|
129
|
+
* configs pass through, `"none"`/absent render the bind pose, and `"auto"` derives states and
|
|
130
|
+
* one-shots from the model's clip names via {@link defaultAnimationForClips}. The shell calls
|
|
131
|
+
* this with the loaded GLB's actual clip names, so `"auto"` works on any rigged model —
|
|
132
|
+
* catalog-resolved ids are stamped `"auto"` automatically.
|
|
133
|
+
*/
|
|
134
|
+
export function resolveAnimationConfig(animation, clips, table = DEFAULT_CLIP_ROLE_TABLE) {
|
|
135
|
+
if (animation === undefined || animation === "none")
|
|
136
|
+
return undefined;
|
|
137
|
+
if (animation !== "auto")
|
|
138
|
+
return animation;
|
|
139
|
+
if (clips === undefined || clips.length === 0)
|
|
140
|
+
return undefined;
|
|
141
|
+
return defaultAnimationForClips(clips, table);
|
|
142
|
+
}
|