roamwright 0.61.20 → 0.61.21
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/README.md +13 -12
- package/examples/scenes.html +54 -0
- package/examples/scenes.js +594 -0
- package/geometry/projectile-shapes.js +85 -0
- package/index.js +50 -0
- package/motion/fallen-mount.js +63 -0
- package/motion/melee-combat.js +328 -0
- package/motion/melee-cuts.js +395 -0
- package/motion/melee-duels.js +142 -0
- package/motion/melee-exchange-creatures.js +86 -0
- package/motion/melee-exchange.js +498 -0
- package/motion/melee-reactions.js +147 -0
- package/motion/prop-contact.js +87 -0
- package/package.json +1 -1
- package/rendering/blade-trails.js +128 -0
- package/rendering/scene-beams.js +486 -0
- package/rendering/scene-coverage.js +500 -0
- package/rendering/scene-markers.js +421 -0
- package/rendering/scene-projectiles.js +395 -0
- package/rendering/scene-props.js +383 -0
- package/rendering/scene-shots.js +199 -0
- package/runtime/foley-surface.js +79 -0
- package/runtime/scene-script.js +137 -0
- package/runtime/scene-zones.js +117 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedural ballistic projectile meshes: broadhead arrows, steel-bodied crossbow quarrels,
|
|
3
|
+
* and double-edged throwing knives. Local origin sits right behind the striking point with `+z`
|
|
4
|
+
* pointing forward into the target and `-z` extending back along the shaft or grip.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { TAU } from '../math/scalar.js';
|
|
9
|
+
import { GB } from './builder.js';
|
|
10
|
+
import { C, TRS, createUnitShapes, stick } from './primitives.js';
|
|
11
|
+
|
|
12
|
+
let defaultShapes = null;
|
|
13
|
+
const shapesOf = shapes => shapes || (defaultShapes ??= createUnitShapes());
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Builds a feathered broadhead arrow `BufferGeometry` with vertex colours.
|
|
17
|
+
* @param {object} [shapes] Optional shared unit shape table from {@link createUnitShapes}.
|
|
18
|
+
* @returns {import('three').BufferGeometry} Built arrow geometry.
|
|
19
|
+
*/
|
|
20
|
+
export function buildArrowGeometry(shapes) {
|
|
21
|
+
const U = shapesOf(shapes),
|
|
22
|
+
gb = new GB(),
|
|
23
|
+
shaft = C(0xd4b886),
|
|
24
|
+
fletch = C(0xf4eee0),
|
|
25
|
+
steel = C(0xdfe4ea),
|
|
26
|
+
binding = C(0x2e241c);
|
|
27
|
+
stick(gb, [0, 0, -0.84], [0, 0, -0.01], 0.0105, shaft);
|
|
28
|
+
stick(gb, [0, 0, -0.05], [0, 0, -0.01], 0.0125, binding);
|
|
29
|
+
stick(gb, [0, 0, -0.84], [0, 0, -0.81], 0.0115, binding);
|
|
30
|
+
gb.add(U.box, steel, TRS(0, -0.005, 0.036, 0.034, 0.01, 0.082));
|
|
31
|
+
gb.add(U.pyr, steel, TRS(0, 0.062, 0.012, 0.032, 0.052, 0.011, 0, Math.PI / 2));
|
|
32
|
+
for (let k = 0; k < 3; k++) {
|
|
33
|
+
const a = (k * TAU) / 3;
|
|
34
|
+
gb.add(U.box, fletch, TRS(Math.cos(a) * 0.014, Math.sin(a) * 0.014 - 0.014, -0.71, 0.003, 0.028, 0.16, 0, 0, a));
|
|
35
|
+
}
|
|
36
|
+
const geo = gb.build();
|
|
37
|
+
gb.release();
|
|
38
|
+
return geo;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Builds a heavy steel-pointed crossbow quarrel `BufferGeometry` with vertex colours.
|
|
43
|
+
* @param {object} [shapes] Optional shared unit shape table from {@link createUnitShapes}.
|
|
44
|
+
* @returns {import('three').BufferGeometry} Built quarrel geometry.
|
|
45
|
+
*/
|
|
46
|
+
export function buildQuarrelGeometry(shapes) {
|
|
47
|
+
const U = shapesOf(shapes),
|
|
48
|
+
gb = new GB(),
|
|
49
|
+
shaft = C(0xcca974),
|
|
50
|
+
flight = C(0xefe7d4),
|
|
51
|
+
steel = C(0xe0e5eb),
|
|
52
|
+
ferrule = C(0x36322e);
|
|
53
|
+
stick(gb, [0, 0, -0.52], [0, 0, -0.015], 0.0118, shaft);
|
|
54
|
+
stick(gb, [0, 0, -0.055], [0, 0, -0.012], 0.0138, ferrule);
|
|
55
|
+
gb.add(U.box, steel, TRS(0, -0.011, 0.026, 0.025, 0.022, 0.07));
|
|
56
|
+
gb.add(U.pyr, steel, TRS(0, 0.055, 0.01, 0.026, 0.05, 0.026, Math.PI / 4, Math.PI / 2));
|
|
57
|
+
for (const side of [-1, 1]) {
|
|
58
|
+
gb.add(U.box, flight, TRS(side * 0.015, -0.014, -0.41, 0.0032, 0.028, 0.135));
|
|
59
|
+
}
|
|
60
|
+
const geo = gb.build();
|
|
61
|
+
gb.release();
|
|
62
|
+
return geo;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Builds a balanced double-edged throwing knife `BufferGeometry` with cross-guard, grip, and pommel.
|
|
67
|
+
* @param {object} [shapes] Optional shared unit shape table from {@link createUnitShapes}.
|
|
68
|
+
* @returns {import('three').BufferGeometry} Built throwing knife geometry.
|
|
69
|
+
*/
|
|
70
|
+
export function buildKnifeGeometry(shapes) {
|
|
71
|
+
const U = shapesOf(shapes),
|
|
72
|
+
gb = new GB(),
|
|
73
|
+
steel = C(0xe2e8ea),
|
|
74
|
+
guard = C(0x322e2a),
|
|
75
|
+
grip = C(0x664734),
|
|
76
|
+
pommel = C(0x94999e);
|
|
77
|
+
gb.add(U.box, steel, TRS(0, -0.004, 0.0, 0.042, 0.008, 0.18));
|
|
78
|
+
gb.add(U.pyr, steel, TRS(0, 0.088, 0.002, 0.042, 0.062, 0.009, 0, Math.PI / 2));
|
|
79
|
+
gb.add(U.box, guard, TRS(0, -0.046, -0.095, 0.018, 0.092, 0.016, 0, 0, Math.PI / 2));
|
|
80
|
+
stick(gb, [0, 0, -0.22], [0, 0, -0.1], 0.013, grip);
|
|
81
|
+
gb.add(U.sph, pommel, TRS(0, 0, -0.23, 0.03, 0.03, 0.028));
|
|
82
|
+
const geo = gb.build();
|
|
83
|
+
gb.release();
|
|
84
|
+
return geo;
|
|
85
|
+
}
|
package/index.js
CHANGED
|
@@ -300,6 +300,56 @@ export { PERF_BOX_DEFAULTS, attachPerfBoxWorker, createPerfBoxRenderer } from '.
|
|
|
300
300
|
export { createFrameSampler } from './runtime/perf-probe.js';
|
|
301
301
|
export { flyProbeRoute, runSelfProbe } from './rendering/perf-probe.js';
|
|
302
302
|
|
|
303
|
+
// ── Scene playback, melee, projectiles, beams, props & markers ───────────
|
|
304
|
+
export {
|
|
305
|
+
DEFAULT_CUTS,
|
|
306
|
+
DEFAULT_CUT_STYLES,
|
|
307
|
+
DEFAULT_DODGE_STEP,
|
|
308
|
+
MELEE_MEET,
|
|
309
|
+
MELEE_THRU,
|
|
310
|
+
SPEAR_ACROSS,
|
|
311
|
+
SPEAR_PARRY,
|
|
312
|
+
deathOf,
|
|
313
|
+
dodgeBody,
|
|
314
|
+
dodgeOf,
|
|
315
|
+
parryBody,
|
|
316
|
+
pickCut,
|
|
317
|
+
swingBody,
|
|
318
|
+
swingRow,
|
|
319
|
+
woundBody,
|
|
320
|
+
woundDrive,
|
|
321
|
+
} from './motion/melee-cuts.js';
|
|
322
|
+
export { createBladeTrailPool } from './rendering/blade-trails.js';
|
|
323
|
+
export { fellMount, raiseFallenMount, updateFallenMount } from './motion/fallen-mount.js';
|
|
324
|
+
export { createMeleeDuels } from './motion/melee-duels.js';
|
|
325
|
+
export { createMeleeReactions } from './motion/melee-reactions.js';
|
|
326
|
+
export { createMeleeExchanges, flankOf, sideOn } from './motion/melee-exchange.js';
|
|
327
|
+
export {
|
|
328
|
+
AT_HORSE_GAP,
|
|
329
|
+
BODY_GAP,
|
|
330
|
+
DEFAULT_WEAPON_LENGTHS,
|
|
331
|
+
HORSES_GAP,
|
|
332
|
+
RIDER_GAP,
|
|
333
|
+
addBattleWear,
|
|
334
|
+
createSceneCombat,
|
|
335
|
+
duelMeasure,
|
|
336
|
+
fightFx,
|
|
337
|
+
horseGap,
|
|
338
|
+
resetBattleWear,
|
|
339
|
+
strikeReach,
|
|
340
|
+
} from './motion/melee-combat.js';
|
|
341
|
+
export { buildArrowGeometry, buildKnifeGeometry, buildQuarrelGeometry } from './geometry/projectile-shapes.js';
|
|
342
|
+
export { createProjectilePool } from './rendering/scene-projectiles.js';
|
|
343
|
+
export { DEFAULT_BEAM_COLORS, DEFAULT_BEAM_STYLE, DEFAULT_BEAM_STYLES, createEnergyBeams } from './rendering/scene-beams.js';
|
|
344
|
+
export { applyBurstWear, resolveScenePos, resolveSceneY, stepRidesProp, stepWalksOn } from './runtime/scene-script.js';
|
|
345
|
+
export { DEFAULT_ZONE_STRIDE, captionIndexAt, collectSceneZones, prepareSceneZones, resolveSceneAnchor } from './runtime/scene-zones.js';
|
|
346
|
+
export { createSurfaceClassifier } from './runtime/foley-surface.js';
|
|
347
|
+
export { DEFAULT_POSE_SHOTS, actorHeadTop, createSceneCoverage } from './rendering/scene-coverage.js';
|
|
348
|
+
export { createSceneShots, gallopTremorLevel, protectMasterHeadroom, trackOrigin } from './rendering/scene-shots.js';
|
|
349
|
+
export { createPropContact } from './motion/prop-contact.js';
|
|
350
|
+
export { createSceneProps } from './rendering/scene-props.js';
|
|
351
|
+
export { createSceneMarkers, createShaftLabel, DEFAULT_MARKER_COLORS, projectWaypoint } from './rendering/scene-markers.js';
|
|
352
|
+
|
|
303
353
|
// ── Map kit ──────────────────────────────────────────────────────────────
|
|
304
354
|
export {
|
|
305
355
|
clampViewCenter,
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Brings a ridden horse down onto its side after its rider is pulled from the saddle, folding its
|
|
3
|
+
* legs and rolling its barrel cleanly onto the ground using the quadruped stillness constants.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as THREE from 'three';
|
|
8
|
+
import { clamp, lerp } from '../math/scalar.js';
|
|
9
|
+
import { HALF_BARREL, LIE_ROLL, SPINE_UP } from './animal-horse-still.js';
|
|
10
|
+
|
|
11
|
+
const LAG = 0.3, // seconds between the rider going down and the horse collapsing
|
|
12
|
+
FALL = 0.75, // seconds the horse takes to roll onto its side
|
|
13
|
+
_roll = new THREE.Quaternion(),
|
|
14
|
+
_off = new THREE.Vector3(),
|
|
15
|
+
ALONG = new THREE.Vector3(0, 0, 1);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Marks a rider's mount to fold and roll onto its side once detached from the rider.
|
|
19
|
+
* @param {object} fightState Actor fight state receiving the `fell` record.
|
|
20
|
+
* @param {{ H: { mesh: THREE.Object3D, down: number } }} mount Rider mount handle.
|
|
21
|
+
* @param {number} side Roll direction (`1` or `-1`).
|
|
22
|
+
*/
|
|
23
|
+
export function fellMount(fightState, mount, side) {
|
|
24
|
+
fightState.fell = { H: mount.H, side, t: 0, base: null, at: null };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Advances a felled mount's roll onto its side each frame once detached from `actor.group`.
|
|
29
|
+
* @param {object} actor Fallen rider record.
|
|
30
|
+
* @param {object} fightState Rider's fight state containing `fell`.
|
|
31
|
+
* @param {number} dt Frame step in seconds.
|
|
32
|
+
*/
|
|
33
|
+
export function updateFallenMount(actor, fightState, dt) {
|
|
34
|
+
const F = fightState.fell,
|
|
35
|
+
horse = F.H.mesh;
|
|
36
|
+
if (horse.parent === actor.group) return;
|
|
37
|
+
if (!F.base) {
|
|
38
|
+
F.base = horse.quaternion.clone();
|
|
39
|
+
F.at = horse.position.clone();
|
|
40
|
+
F.H.down = 1;
|
|
41
|
+
}
|
|
42
|
+
F.t += dt;
|
|
43
|
+
const k = clamp((F.t - LAG) / FALL, 0, 1),
|
|
44
|
+
fall = k * k,
|
|
45
|
+
roll = fall * LIE_ROLL * F.side,
|
|
46
|
+
spine = lerp(SPINE_UP, HALF_BARREL, fall);
|
|
47
|
+
horse.quaternion.copy(F.base).multiply(_roll.setFromAxisAngle(ALONG, roll));
|
|
48
|
+
_off
|
|
49
|
+
.set(SPINE_UP * Math.sin(roll), spine - SPINE_UP * Math.cos(roll), 0)
|
|
50
|
+
.applyQuaternion(F.base)
|
|
51
|
+
.multiplyScalar(horse.scale.x);
|
|
52
|
+
horse.position.copy(F.at).add(_off);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Restores a felled mount back to standing when a scene ends or restarts.
|
|
57
|
+
* @param {object} fightState Rider's fight state containing `fell`.
|
|
58
|
+
*/
|
|
59
|
+
export function raiseFallenMount(fightState) {
|
|
60
|
+
if (!fightState.fell) return;
|
|
61
|
+
fightState.fell.H.down = 0;
|
|
62
|
+
fightState.fell = null;
|
|
63
|
+
}
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Melee combat coordinator: shared weapon reach tables, progressive battle wear, zero-allocation
|
|
3
|
+
* clash impulses, actor fight-state initialization, and frame stepping for exchanges, duels,
|
|
4
|
+
* bystander reactions, blade trails, and fallen mounts.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as THREE from 'three';
|
|
9
|
+
import { clamp } from '../math/scalar.js';
|
|
10
|
+
import { LIE } from './figure-pose-table.js';
|
|
11
|
+
import { fellMount, raiseFallenMount, updateFallenMount } from './fallen-mount.js';
|
|
12
|
+
import { createBladeTrailPool } from '../rendering/blade-trails.js';
|
|
13
|
+
import { DEFAULT_CUTS, DEFAULT_CUT_STYLES } from './melee-cuts.js';
|
|
14
|
+
import { createMeleeDuels } from './melee-duels.js';
|
|
15
|
+
import { createMeleeExchanges } from './melee-exchange.js';
|
|
16
|
+
import { createMeleeReactions } from './melee-reactions.js';
|
|
17
|
+
|
|
18
|
+
const LANDED = 0.92; // lie-blend share at which a falling body strikes the ground
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Minimum centre-to-centre distance in metres between two full-size fighters on foot.
|
|
22
|
+
*/
|
|
23
|
+
export const BODY_GAP = 0.72;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Minimum separation in metres between a mounted rider's horse centre and an opponent on foot.
|
|
27
|
+
*/
|
|
28
|
+
export const RIDER_GAP = 1.8;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Minimum separation in metres kept by a foot fighter against a mounted opponent's horse.
|
|
32
|
+
*/
|
|
33
|
+
export const AT_HORSE_GAP = 1.5;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Minimum separation in metres between two mounted fighters so their mounts clear each other.
|
|
37
|
+
*/
|
|
38
|
+
export const HORSES_GAP = 2.2;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Default effective blade and polearm lengths in metres for generic weapon categories.
|
|
42
|
+
* Worlds may spread this object and add their own named weapons.
|
|
43
|
+
*/
|
|
44
|
+
export const DEFAULT_WEAPON_LENGTHS = Object.freeze({
|
|
45
|
+
sword: 0.95,
|
|
46
|
+
rapier: 1.05,
|
|
47
|
+
daggers: 0.38,
|
|
48
|
+
scimitars: 0.8,
|
|
49
|
+
axe: 0.85,
|
|
50
|
+
spear: 1.48,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Returns the minimum separation in metres required to keep any mount under `a` or `d` clear.
|
|
55
|
+
* @param {{ mount?: object | null }} a First fighter.
|
|
56
|
+
* @param {{ mount?: object | null }} d Second fighter.
|
|
57
|
+
* @returns {number} Clearance in metres (`0` when neither fighter is mounted).
|
|
58
|
+
*/
|
|
59
|
+
export function horseGap(a, d) {
|
|
60
|
+
return a.mount ? (d.mount ? HORSES_GAP : RIDER_GAP) : d.mount ? AT_HORSE_GAP : 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Computes physical centre-to-centre strike reach in metres for actor `a` attacking actor `d`.
|
|
65
|
+
* @param {object} a Attacking actor.
|
|
66
|
+
* @param {object} d Defending actor.
|
|
67
|
+
* @param {string} [kind] Exchange kind (`'parry' | 'dodge' | 'hit' | 'kill'`).
|
|
68
|
+
* @param {Record<string, number>} [weaponLengths] Weapon length lookup table.
|
|
69
|
+
* @returns {number} Centre-to-centre contact distance in metres.
|
|
70
|
+
*/
|
|
71
|
+
export function strikeReach(a, d, kind = 'parry', weaponLengths = DEFAULT_WEAPON_LENGTHS) {
|
|
72
|
+
const ha = a.group.scale.y,
|
|
73
|
+
hd = d.group.scale.y,
|
|
74
|
+
blade = weaponLengths[a.def.look?.item] || 0.65,
|
|
75
|
+
guardDepth = kind === 'parry' ? (d.shield ? 0.28 : 0.24) : 0.14,
|
|
76
|
+
weaponContact = (0.5 + 0.58 * blade) * ha + guardDepth * hd;
|
|
77
|
+
return Math.max(weaponContact, BODY_GAP * Math.max(ha, hd), horseGap(a, d));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Returns the balanced circling sword-measure distance in metres between two duelists.
|
|
82
|
+
* @param {object} a First duelist.
|
|
83
|
+
* @param {object} b Second duelist.
|
|
84
|
+
* @param {Record<string, number>} [weaponLengths] Weapon length lookup table.
|
|
85
|
+
* @returns {number} Mean parry reach in metres.
|
|
86
|
+
*/
|
|
87
|
+
export function duelMeasure(a, b, weaponLengths = DEFAULT_WEAPON_LENGTHS) {
|
|
88
|
+
return 0.5 * (strikeReach(a, b, 'parry', weaponLengths) + strikeReach(b, a, 'parry', weaponLengths));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Accumulates progressive battle wear (`{ x: dust, y: sweat, z: blood, w: scorch }`) in place on `actor.wear`.
|
|
93
|
+
* @param {object | null | undefined} actor Actor holding an optional `wear` Vector4.
|
|
94
|
+
* @param {number} [dust] Dust increment.
|
|
95
|
+
* @param {number} [sweat] Sweat increment.
|
|
96
|
+
* @param {number} [blood] Blood increment.
|
|
97
|
+
* @param {number} [scorch] Scorch increment.
|
|
98
|
+
*/
|
|
99
|
+
export function addBattleWear(actor, dust = 0, sweat = 0, blood = 0, scorch = 0) {
|
|
100
|
+
const wear = actor?.wear;
|
|
101
|
+
if (!wear) return;
|
|
102
|
+
if (dust) wear.x = clamp(wear.x + dust, 0, 1);
|
|
103
|
+
if (sweat) wear.y = clamp(wear.y + sweat, 0, 1);
|
|
104
|
+
if (blood) wear.z = clamp(wear.z + blood, 0, 1);
|
|
105
|
+
if (scorch) wear.w = clamp(wear.w + scorch, 0, 1);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Ensures `actor.wear` exists as a `THREE.Vector4` and zeroes all four channels.
|
|
110
|
+
* @param {object | null | undefined} actor Actor record.
|
|
111
|
+
*/
|
|
112
|
+
export function resetBattleWear(actor) {
|
|
113
|
+
if (!actor) return;
|
|
114
|
+
if (actor.wear) actor.wear.set(0, 0, 0, 0);
|
|
115
|
+
else actor.wear = new THREE.Vector4(0, 0, 0, 0);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Lazily initializes and returns an actor's melee fight-state record (`actor.fx_`).
|
|
120
|
+
* @param {object} actor Actor record.
|
|
121
|
+
* @returns {object} Mutable fight-state object read by figure pose solvers.
|
|
122
|
+
*/
|
|
123
|
+
export function fightFx(actor) {
|
|
124
|
+
return (
|
|
125
|
+
actor.fx_ ||
|
|
126
|
+
(actor.fx_ = {
|
|
127
|
+
ra: 0,
|
|
128
|
+
la: 0,
|
|
129
|
+
outR: 0,
|
|
130
|
+
outL: 0,
|
|
131
|
+
foreR: -0.2,
|
|
132
|
+
foreL: -0.2,
|
|
133
|
+
lw: 0,
|
|
134
|
+
wrist: 0,
|
|
135
|
+
across: 0,
|
|
136
|
+
cover: 0,
|
|
137
|
+
nod: 0,
|
|
138
|
+
turn: 0,
|
|
139
|
+
tw: 0,
|
|
140
|
+
lean: 0,
|
|
141
|
+
sink: 0,
|
|
142
|
+
shift: 0,
|
|
143
|
+
w: 0,
|
|
144
|
+
y: 0,
|
|
145
|
+
busy: false,
|
|
146
|
+
die: 0,
|
|
147
|
+
fl: 0,
|
|
148
|
+
br: 0,
|
|
149
|
+
bx: 0,
|
|
150
|
+
bz: 0,
|
|
151
|
+
reach: 0,
|
|
152
|
+
cr: 0,
|
|
153
|
+
jaw: 0,
|
|
154
|
+
worry: 0,
|
|
155
|
+
thrown: 0,
|
|
156
|
+
down: false,
|
|
157
|
+
landing: false,
|
|
158
|
+
fell: null,
|
|
159
|
+
tuck: 0,
|
|
160
|
+
})
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Creates a complete scene combat coordinator binding exchanges, duels, reactions, blade trails,
|
|
166
|
+
* fallen mounts, and battle wear to a world's actors, collision, audio, and effects callbacks.
|
|
167
|
+
* @param {object} options
|
|
168
|
+
* @param {THREE.Object3D} [options.scene] Scene receiving blade trail meshes.
|
|
169
|
+
* @param {Record<string, object>} options.actors Actor map by id.
|
|
170
|
+
* @param {object[]} options.actorList Live actor array.
|
|
171
|
+
* @param {() => string} options.getSpaceId Returns active space id.
|
|
172
|
+
* @param {() => number} options.getElapsed Returns elapsed time in seconds.
|
|
173
|
+
* @param {(x: number, z: number, radius: number) => boolean} [options.collide] Obstacle check.
|
|
174
|
+
* @param {(x: number, z: number) => number} [options.groundAt] Ground height sampler.
|
|
175
|
+
* @param {(x: number, y: number, salt: number) => number} options.hash Deterministic `[0, 1)` hash function.
|
|
176
|
+
* @param {Function} [options.reachArm] Two-bone arm IK function for parry weapon lock.
|
|
177
|
+
* @param {Record<string, number>} [options.weaponLengths] Effective weapon lengths in metres.
|
|
178
|
+
* @param {Record<string, readonly string[]>} [options.cutStyles] Weapon-to-cut preference table.
|
|
179
|
+
* @param {Record<string, object>} [options.cuts] Cut keyframe table.
|
|
180
|
+
* @param {(impulse: { x: number, y: number, z: number, strength: number }) => void} [options.onImpulse] Zero-allocation camera impulse emitter.
|
|
181
|
+
* @param {(x: number, y: number, z: number) => void} [options.onBodyLand] Called when a dying body hits the ground.
|
|
182
|
+
* @param {(dt: number) => void} [options.onUpdatePrints] Optional ground print updater.
|
|
183
|
+
* @param {Function} [options.onParry] Parry impact visual/audio hook.
|
|
184
|
+
* @param {Function} [options.onHit] Wound/kill impact visual/audio hook.
|
|
185
|
+
* @param {Function} [options.onDodge] Dodge visual/audio hook.
|
|
186
|
+
* @param {Function} [options.onScuff] Foot scuff hook.
|
|
187
|
+
* @param {Function} [options.onAlarm] Crowd alarm hook.
|
|
188
|
+
* @param {number} [options.trailLayer] Render layer for blade trails (default `1`).
|
|
189
|
+
* @param {string} [options.wingedKind] Aerial stooping actor kind (default `'dragon'`).
|
|
190
|
+
* @returns {object} Combat controller with `combat`, `startAttack`, `startDuel`, `updateCombat`, `applyMeleeContactIK`, `clearCombat`, `combatFlinch`, `throwDown`, `sceneImpulse`, `strikeReach`, `duelMeasure`, `trails`, and `dispose`.
|
|
191
|
+
*/
|
|
192
|
+
export function createSceneCombat({
|
|
193
|
+
scene = null,
|
|
194
|
+
actors = {},
|
|
195
|
+
actorList = [],
|
|
196
|
+
getSpaceId = () => 'world',
|
|
197
|
+
getElapsed = () => 0,
|
|
198
|
+
collide = () => false,
|
|
199
|
+
groundAt = () => 0,
|
|
200
|
+
hash,
|
|
201
|
+
reachArm = null,
|
|
202
|
+
weaponLengths = DEFAULT_WEAPON_LENGTHS,
|
|
203
|
+
cutStyles = DEFAULT_CUT_STYLES,
|
|
204
|
+
cuts = DEFAULT_CUTS,
|
|
205
|
+
onImpulse = null,
|
|
206
|
+
onBodyLand = null,
|
|
207
|
+
onUpdatePrints = null,
|
|
208
|
+
onParry = null,
|
|
209
|
+
onHit = null,
|
|
210
|
+
onDodge = null,
|
|
211
|
+
onScuff = null,
|
|
212
|
+
onAlarm = null,
|
|
213
|
+
trailLayer = 1,
|
|
214
|
+
wingedKind = 'dragon',
|
|
215
|
+
}) {
|
|
216
|
+
const _impulse = { x: 0, y: 0, z: 0, strength: 0 };
|
|
217
|
+
const trails = scene ? createBladeTrailPool({ scene, layer: trailLayer }) : null;
|
|
218
|
+
const reactions = createMeleeReactions({ actorList, getSpaceId, collide, getElapsed, fightFx });
|
|
219
|
+
const exchanges = createMeleeExchanges({
|
|
220
|
+
actors,
|
|
221
|
+
collide,
|
|
222
|
+
groundAt,
|
|
223
|
+
hash,
|
|
224
|
+
reachArm,
|
|
225
|
+
weaponLengths,
|
|
226
|
+
cutStyles,
|
|
227
|
+
cuts,
|
|
228
|
+
trails,
|
|
229
|
+
fightFx,
|
|
230
|
+
addWear: addBattleWear,
|
|
231
|
+
onParry,
|
|
232
|
+
onHit,
|
|
233
|
+
onDodge,
|
|
234
|
+
onScuff,
|
|
235
|
+
onAlarm,
|
|
236
|
+
onFlinch: reactions.combatFlinch,
|
|
237
|
+
onFellMount: fellMount,
|
|
238
|
+
wingedKind,
|
|
239
|
+
});
|
|
240
|
+
const duelRunner = createMeleeDuels({
|
|
241
|
+
startAttack: exchanges.startAttack,
|
|
242
|
+
collide,
|
|
243
|
+
hash,
|
|
244
|
+
duelMeasure: (a, b) => duelMeasure(a, b, weaponLengths),
|
|
245
|
+
addWear: addBattleWear,
|
|
246
|
+
});
|
|
247
|
+
const combat = { list: exchanges.list, duels: duelRunner.duels };
|
|
248
|
+
|
|
249
|
+
function sceneImpulse(x, y, z, strength) {
|
|
250
|
+
if (!(strength > 0) || !onImpulse) return;
|
|
251
|
+
_impulse.x = x;
|
|
252
|
+
_impulse.y = y;
|
|
253
|
+
_impulse.z = z;
|
|
254
|
+
_impulse.strength = strength;
|
|
255
|
+
onImpulse(_impulse);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function clearCombat() {
|
|
259
|
+
exchanges.clear();
|
|
260
|
+
duelRunner.clear();
|
|
261
|
+
for (let i = 0; i < actorList.length; i++) {
|
|
262
|
+
const a = actorList[i];
|
|
263
|
+
if (a.pose === 'dead') fightFx(a).down = true;
|
|
264
|
+
if (a.wear) a.wear.set(0, 0, 0, 0);
|
|
265
|
+
const X = a.fx_;
|
|
266
|
+
if (!X) continue;
|
|
267
|
+
if (X.fell) raiseFallenMount(X);
|
|
268
|
+
X.w = 0;
|
|
269
|
+
X.lean = 0;
|
|
270
|
+
X.y = 0;
|
|
271
|
+
X.die = 0;
|
|
272
|
+
X.fl = 0;
|
|
273
|
+
X.br = 0;
|
|
274
|
+
X.reach = 0;
|
|
275
|
+
X.tuck = 0;
|
|
276
|
+
X.thrown = 0;
|
|
277
|
+
X.landing = false;
|
|
278
|
+
}
|
|
279
|
+
trails?.clear();
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function updateCombat(dt) {
|
|
283
|
+
for (let i = 0; i < actorList.length; i++) {
|
|
284
|
+
const a = actorList[i];
|
|
285
|
+
if (a.pose === 'dead' && a.inScene && a.kind === 'human' && !(a.fx_ && a.fx_.down)) reactions.throwDown(a);
|
|
286
|
+
const X = a.fx_;
|
|
287
|
+
if (!X) continue;
|
|
288
|
+
if (X.fell) updateFallenMount(a, X, dt);
|
|
289
|
+
X.busy = false;
|
|
290
|
+
X.sink = X.shift = X.outR = X.outL = X.wrist = X.nod = X.turn = 0;
|
|
291
|
+
if (X.die > 0 && (X.die -= dt) <= 0 && a.pose !== 'dead') {
|
|
292
|
+
a.pose = 'dead';
|
|
293
|
+
X.down = X.landing = true;
|
|
294
|
+
} else if (X.landing && a.cur && a.cur[LIE] > LANDED) {
|
|
295
|
+
X.landing = false;
|
|
296
|
+
addBattleWear(a, 0.22, 0.04, 0, 0);
|
|
297
|
+
onBodyLand?.(a.x, a.y, a.z);
|
|
298
|
+
} else if (X.down && X.die <= 0 && a.pose !== 'dead') X.down = false;
|
|
299
|
+
}
|
|
300
|
+
duelRunner.updateDuels(dt);
|
|
301
|
+
exchanges.updateExchanges(dt);
|
|
302
|
+
reactions.updateReactions(dt);
|
|
303
|
+
trails?.update(dt);
|
|
304
|
+
onUpdatePrints?.(dt);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function dispose() {
|
|
308
|
+
clearCombat();
|
|
309
|
+
trails?.dispose();
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return {
|
|
313
|
+
combat,
|
|
314
|
+
trails,
|
|
315
|
+
startAttack: exchanges.startAttack,
|
|
316
|
+
startDuel: duelRunner.startDuel,
|
|
317
|
+
updateCombat,
|
|
318
|
+
applyMeleeContactIK: exchanges.applyMeleeContactIK,
|
|
319
|
+
clearCombat,
|
|
320
|
+
combatFlinch: reactions.combatFlinch,
|
|
321
|
+
throwDown: reactions.throwDown,
|
|
322
|
+
updateReactions: reactions.updateReactions,
|
|
323
|
+
sceneImpulse,
|
|
324
|
+
strikeReach: (a, d, kind) => strikeReach(a, d, kind, weaponLengths),
|
|
325
|
+
duelMeasure: (a, b) => duelMeasure(a, b, weaponLengths),
|
|
326
|
+
dispose,
|
|
327
|
+
};
|
|
328
|
+
}
|