roamwright 0.61.19 → 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.
@@ -0,0 +1,500 @@
1
+ /**
2
+ * Automatic scene camera coverage: resolves live head-crown height, validates lens bounds and
3
+ * clear sightlines against terrain, colliders, props, plants, actors, and walking crowds, and
4
+ * chooses clean close, over-the-shoulder, two-shot, or full-body cuts respecting the 180-degree
5
+ * axis, headroom, bystander edges, sun glare, and master reveal holds.
6
+ * @module
7
+ */
8
+
9
+ import * as THREE from 'three';
10
+ import { wrapRadians } from '../math/periodic.js';
11
+ import { backlitGlarePenalty, bystanderEdgePenalty, conversationBearings, ensureHeadroom, masterHoldsReveal } from './stage-framing.js';
12
+
13
+ const LENS = 30, // closer shot vertical FOV (degrees) on stage-aspect screens
14
+ STAGE_ASPECT = 1.5,
15
+ OPENING = 4.6, // seconds under opening title card with no cut-ins
16
+ CLOSING = 2, // final seconds kept on master
17
+ MASTER = 1.35, // minimum seconds back on master between cut-ins
18
+ BREATH = 1.85, // minimum seconds before replacing one cut-in with another
19
+ HOLD = { close: 3.1, ots: 3.6, full: 3.6, pair: 3.8 },
20
+ VISIBLE = { close: 1.04, ots: 1.28, full: 1.95 },
21
+ AIM = { close: 0.68, ots: 0.64, full: 0.44, low: 0.12 },
22
+ PAIR_ROOM = 2.4,
23
+ CONVERSE_MAX = 5.2,
24
+ OTS_MAX = 3.6,
25
+ NEAR_ENOUGH = 1.28,
26
+ FAR_AWAY = 55,
27
+ SIDES = [0.38, -0.38, 0.78, -0.78, 0.12, -0.12, 1.12, -1.12],
28
+ SIGHT_STEP = 0.35,
29
+ CLEAR_MIDDLE = 0.6,
30
+ OVER_THE_FALLEN = 0.95,
31
+ ROOM_TO_SET_UP = 2.2,
32
+ ROOM_TO_STAY = 1.25,
33
+ UPHILL = 0.42,
34
+ BEHIND = 1.18,
35
+ TURNED_AWAY = 1.52,
36
+ BODY_ROOM = 0.58,
37
+ HORSE_ROOM = 1.45,
38
+ TALL = 1.9, // taller humanoids receive proportionally wider lens clearance
39
+ FIGHT_ROOM = 1.2,
40
+ MOUNTED_REACH = 5.1,
41
+ LENS_CLEAR = 0.42,
42
+ ROOF_CLEAR = 45,
43
+ HILL_CLEAR = 2,
44
+ QUIET_AFTER_BLAST = 2.6,
45
+ QUIET_ON_ARRIVAL = 2.8,
46
+ HEADROOM_SHARE = 0.11,
47
+ WALK_STEP = 0.4,
48
+ MARCH_RATE = 1.2;
49
+
50
+ /**
51
+ * Default mapping from actor pose names to automatic coverage shot kinds (`'close'`, `'full'`, or `'pair'`).
52
+ */
53
+ export const DEFAULT_POSE_SHOTS = Object.freeze({
54
+ talk: 'close',
55
+ sittalk: 'close',
56
+ point: 'close',
57
+ reach: 'close',
58
+ cast: 'close',
59
+ carry: 'full',
60
+ sit: 'close',
61
+ cower: 'full',
62
+ kneel: 'full',
63
+ guard: 'full',
64
+ strike: 'full',
65
+ dead: 'full',
66
+ aim: 'close',
67
+ shoot: 'close',
68
+ read: 'close',
69
+ write: 'close',
70
+ warm: 'close',
71
+ embrace: 'pair',
72
+ rest: 'full',
73
+ crouch: 'full',
74
+ crawl: 'full',
75
+ climb: 'full',
76
+ lie: 'full',
77
+ prone: 'full',
78
+ slump: 'full',
79
+ wounded: 'full',
80
+ suspended: 'full',
81
+ bound: 'full',
82
+ crucified: 'full',
83
+ search: 'close',
84
+ restrain: 'pair',
85
+ lean: 'close',
86
+ });
87
+
88
+ const ON_THE_GROUND = { dead: true, cower: true, lie: true, prone: true, crawl: true },
89
+ LOW = { kneel: true, crouch: true, rest: true, slump: true, wounded: true },
90
+ SEATED = { sit: true, sittalk: true };
91
+
92
+ const _head = new THREE.Vector3();
93
+
94
+ /**
95
+ * Computes the world-space top height of `actor`'s head/headgear, sampling the live head bone when
96
+ * built so seated, kneeling, mounted, and rising figures never misestimate crown height.
97
+ * @param {object} actor Actor record with `y`, `height`, `pose`, and optional `built`/`head`/`group`.
98
+ * @returns {number} World Y coordinate of the top of the actor's head in metres.
99
+ */
100
+ export function actorHeadTop(actor) {
101
+ if (actor.built && actor.head && !ON_THE_GROUND[actor.pose]) {
102
+ actor.head.updateWorldMatrix(true, false);
103
+ actor.head.getWorldPosition(_head);
104
+ return _head.y + 0.25 * (actor.group?.scale.y || 1);
105
+ }
106
+ if (ON_THE_GROUND[actor.pose]) return actor.y + 0.38;
107
+ if (SEATED[actor.pose]) return actor.y + actor.height * 0.78;
108
+ if (LOW[actor.pose]) return actor.y + actor.height * 0.64;
109
+ return actor.y + actor.height * 1.04;
110
+ }
111
+
112
+ const offFacing = (bearing, facing) => Math.abs(wrapRadians(bearing - facing));
113
+
114
+ /**
115
+ * Creates a scene coverage director for automatic closer shots and sightline validation.
116
+ * @param {object} options
117
+ * @param {THREE.PerspectiveCamera} options.camera Active scene camera (reads `aspect`).
118
+ * @param {object[]} [options.actorList] Live array of actors in the world.
119
+ * @param {object[]} [options.crowds] Live array of crowd groups to avoid walking across the lens.
120
+ * @param {() => object[]} [options.getCombatList] Returns active melee exchange records.
121
+ * @param {() => object} options.getSpace Returns the active space object (`id`, `ground`, `bound`, `bx`, `bz`, `cx`, `cz`, `round`, `roofHeight`, `ceiling`).
122
+ * @param {(sp: object) => boolean} [options.isWorldSpace] True when `sp` is the unbounded exterior world space.
123
+ * @param {(sp: object) => boolean} [options.isIndoors] True when `sp` is an interior space (disables sun glare checks).
124
+ * @param {(x: number, z: number, radius: number) => boolean} [options.collide] Solid obstacle collider test.
125
+ * @param {(p: THREE.Vector3, at: THREE.Vector3) => boolean} [options.propInTheWay] Standing prop occlusion test.
126
+ * @param {(spaceId: string, p: THREE.Vector3, at: THREE.Vector3, halfTan: number) => boolean} [options.plantInTheWay] Foliage occlusion test.
127
+ * @param {() => THREE.Vector3 | null} [options.getSunDir] Returns unit direction toward the sun.
128
+ * @param {() => number} [options.getDaylight] Returns daylight share in `[0, 1]`.
129
+ * @param {() => number} [options.getElapsed] Returns simulation time in seconds.
130
+ * @param {() => number} [options.getFrame] Returns monotonic frame counter.
131
+ * @param {Record<string, string>} [options.poseShots] Pose-to-shot-kind table (defaults to {@link DEFAULT_POSE_SHOTS}).
132
+ * @param {string[]} [options.skipKinds] Actor kinds excluded from automatic close-ups (default `['dragon', 'raven']`).
133
+ * @returns {object} Coverage controller exposing `actorHeadTop`, `lensBlocked`, `clearSight`, `crowded`, `clearCoverage`, `coverCue`, `coverPose`, `coverQuiet`, `coverArrival`, and `coverShot`.
134
+ */
135
+ export function createSceneCoverage({
136
+ camera,
137
+ actorList = [],
138
+ crowds = [],
139
+ getCombatList = () => [],
140
+ getSpace,
141
+ isWorldSpace = () => true,
142
+ isIndoors = sp => !!sp?.indoors,
143
+ collide = () => false,
144
+ propInTheWay = () => false,
145
+ plantInTheWay = () => false,
146
+ getSunDir = () => null,
147
+ getDaylight = () => 1,
148
+ getElapsed = () => 0,
149
+ getFrame = () => 0,
150
+ poseShots = DEFAULT_POSE_SHOTS,
151
+ skipKinds = ['dragon', 'raven'],
152
+ }) {
153
+ const skipSet = new Set(skipKinds);
154
+ const cover = { cue: null, shot: null, masterSince: 0, quietUntil: 0 };
155
+ const _at = new THREE.Vector3(),
156
+ _p = new THREE.Vector3(),
157
+ _bystanders = [],
158
+ near = { x: 0, z: 0, room: 0 },
159
+ nearLens = (x, z) => Math.hypot(x - near.x, z - near.z) < near.room;
160
+
161
+ function lensBlocked(x, y, z) {
162
+ const sp = getSpace();
163
+ if (!isWorldSpace(sp)) {
164
+ const dx = Math.abs(x - sp.cx),
165
+ dz = Math.abs(z - sp.cz);
166
+ if (sp.round ? Math.hypot(dx, dz) > sp.bound : dx > (sp.bx ?? sp.bound) || dz > (sp.bz ?? sp.bound)) return true;
167
+ }
168
+ const over = y - sp.ground(x, z),
169
+ roof = (sp.roofHeight ?? sp.ceiling)?.(x, z);
170
+ if (Number.isFinite(roof) && over > roof - 0.22) return true;
171
+ return over < -HILL_CLEAR || (over < ROOF_CLEAR && collide(x, z, LENS_CLEAR));
172
+ }
173
+
174
+ function alongWalk(g, span, test) {
175
+ const x0 = g.ax,
176
+ z0 = g.az,
177
+ m = g.move;
178
+ let x1 = x0,
179
+ z1 = z0;
180
+ if (m && span > 0) {
181
+ const endX = m.x0 + m.dx,
182
+ endZ = m.z0 + m.dz,
183
+ left = Math.hypot(endX - x0, endZ - z0),
184
+ going = Math.min(left, (m.len / m.dur) * MARCH_RATE * (span + Math.max(0, m.t0 - getElapsed())));
185
+ if (left > 1e-3) {
186
+ x1 = x0 + ((endX - x0) / left) * going;
187
+ z1 = z0 + ((endZ - z0) / left) * going;
188
+ }
189
+ } else if (!m && g.sp > 1e-3 && g.len > 0.5 && !g.legs && !g.r) {
190
+ x1 = g.bx;
191
+ z1 = g.bz;
192
+ }
193
+ const steps = Math.ceil(Math.hypot(x1 - x0, z1 - z0) / WALK_STEP);
194
+ for (let i = 0; i <= steps; i++) {
195
+ const u = steps ? i / steps : 0;
196
+ if (test(x0 + (x1 - x0) * u, z0 + (z1 - z0) * u)) return true;
197
+ }
198
+ return false;
199
+ }
200
+
201
+ const roomOf = (a, room) => (a.mount || a.loose ? room + HORSE_ROOM : room * Math.max(1, a.height / TALL));
202
+
203
+ function fighting(a) {
204
+ const list = getCombatList();
205
+ for (let i = 0; i < list.length; i++) if (list[i].a === a || list[i].d === a) return true;
206
+ return false;
207
+ }
208
+
209
+ function clearSight(p, at, a, b, span) {
210
+ const sp = getSpace();
211
+ const reach = p.distanceTo(at);
212
+ if (reach < 0.6) return false;
213
+ const steps = Math.ceil((reach - 0.52) / SIGHT_STEP),
214
+ dx = (at.x - p.x) / reach,
215
+ dz = (at.z - p.z) / reach;
216
+ for (let i = 0; i <= steps; i++) {
217
+ const u = (i * SIGHT_STEP) / reach;
218
+ if (lensBlocked(p.x + (at.x - p.x) * u, p.y + (at.y - p.y) * u, p.z + (at.z - p.z) * u)) return false;
219
+ }
220
+ if (propInTheWay(p, at)) return false;
221
+ if (plantInTheWay(sp.id, p, at, Math.tan((LENS * Math.PI) / 360) * CLEAR_MIDDLE)) return false;
222
+ const inTheWay = (x, z, more = 0) => {
223
+ const along = (x - p.x) * dx + (z - p.z) * dz,
224
+ aside = Math.abs((x - p.x) * dz - (z - p.z) * dx);
225
+ return along > -0.5 - more && along < reach - 0.45 && aside < BODY_ROOM + more + along * 0.08;
226
+ };
227
+ for (let i = 0; i < actorList.length; i++) {
228
+ const other = actorList[i];
229
+ if (!other.active || !other.inScene) continue;
230
+ if (other !== a && other !== b && inTheWay(other.x, other.z, roomOf(other, BODY_ROOM) - BODY_ROOM)) return false;
231
+ const freeHorse = other.beside || other.loose;
232
+ if (freeHorse?.H?.mesh?.visible) {
233
+ const hp = freeHorse.H.mesh.position;
234
+ if (inTheWay(hp.x, hp.z, HORSE_ROOM * 0.75)) return false;
235
+ }
236
+ }
237
+ for (let i = 0; i < crowds.length; i++) {
238
+ const crowd = crowds[i];
239
+ if (crowd.space !== sp.id || Math.hypot(crowd.cx - at.x, crowd.cz - at.z) > crowd.range + reach) continue;
240
+ for (let j = 0; j < crowd.list.length; j++) if (alongWalk(crowd.list[j], span, inTheWay)) return false;
241
+ }
242
+ return true;
243
+ }
244
+
245
+ function crowded(p, room, a, b, span = 0) {
246
+ const sp = getSpace();
247
+ for (let i = 0; i < actorList.length; i++) {
248
+ const other = actorList[i];
249
+ if (other === a || other === b || !other.active || !other.inScene) continue;
250
+ const apart = Math.hypot(other.x - p.x, other.z - p.z),
251
+ theirs = roomOf(other, room);
252
+ if (apart < theirs || (apart < theirs + FIGHT_ROOM && fighting(other))) return true;
253
+ }
254
+ near.x = p.x;
255
+ near.z = p.z;
256
+ near.room = room;
257
+ for (let i = 0; i < crowds.length; i++) {
258
+ const crowd = crowds[i];
259
+ if (crowd.space !== sp.id || Math.hypot(crowd.cx - p.x, crowd.cz - p.z) > crowd.range + room) continue;
260
+ for (let j = 0; j < crowd.list.length; j++) {
261
+ const figure = crowd.list[j];
262
+ if (span ? alongWalk(figure, span, nearLens) : Math.hypot(figure.ax - p.x, figure.az - p.z) < room) return true;
263
+ }
264
+ }
265
+ return false;
266
+ }
267
+
268
+ function clearCoverage() {
269
+ cover.cue = cover.shot = null;
270
+ cover.masterSince = cover.quietUntil = 0;
271
+ }
272
+
273
+ function coverCue(t, a, kind, b) {
274
+ if (a && a.active && kind && !skipSet.has(a.kind)) cover.cue = { a, b: b && b.active ? b : null, kind, at: t };
275
+ }
276
+
277
+ function coverPose(t, a, pose) {
278
+ coverCue(t, a, poseShots[pose]);
279
+ }
280
+
281
+ function coverQuiet(t, seconds = QUIET_AFTER_BLAST) {
282
+ cover.shot = cover.cue = null;
283
+ cover.quietUntil = Math.max(cover.quietUntil, t + seconds);
284
+ cover.masterSince = t;
285
+ }
286
+
287
+ function coverArrival(t) {
288
+ cover.shot = cover.cue = null;
289
+ cover.quietUntil = Math.max(cover.quietUntil, t + QUIET_ON_ARRIVAL);
290
+ cover.masterSince = t;
291
+ }
292
+
293
+ function aimAt(a, kind) {
294
+ const share = ON_THE_GROUND[a.pose] ? AIM.low : SEATED[a.pose] ? AIM[kind] * 0.86 : LOW[a.pose] ? AIM[kind] * 0.72 : AIM[kind];
295
+ return _at.set(a.x, a.y + a.height * share, a.z);
296
+ }
297
+
298
+ const lensNow = () =>
299
+ camera.aspect >= STAGE_ASPECT
300
+ ? LENS
301
+ : (Math.atan(Math.tan((LENS * Math.PI) / 360) * Math.min(2, STAGE_ASPECT / camera.aspect)) * 360) / Math.PI;
302
+
303
+ function nearestCastToAim(aim) {
304
+ let best = Infinity;
305
+ for (let i = 0; i < actorList.length; i++) {
306
+ const a = actorList[i];
307
+ if (!a.active || !a.inScene) continue;
308
+ const d = Math.hypot(a.x - aim.x, a.z - aim.z);
309
+ if (d < best) best = d;
310
+ }
311
+ return best;
312
+ }
313
+
314
+ function findConversant(a) {
315
+ if (a.move || ON_THE_GROUND[a.pose] || fighting(a)) return null;
316
+ if (a.watch?.inScene && a.watch.active && a.watch !== a) {
317
+ const d = Math.hypot(a.watch.x - a.x, a.watch.z - a.z);
318
+ if (d >= 0.8 && d <= CONVERSE_MAX) return a.watch;
319
+ }
320
+ let best = null,
321
+ bestScore = Infinity;
322
+ for (let i = 0; i < actorList.length; i++) {
323
+ const other = actorList[i];
324
+ if (other === a || !other.active || !other.inScene || skipSet.has(other.kind) || other.move) continue;
325
+ const d = Math.hypot(other.x - a.x, other.z - a.z);
326
+ if (d < 0.85 || d > CONVERSE_MAX || Math.abs(other.y - a.y) > 2.2) continue;
327
+ const toOther = Math.atan2(other.x - a.x, other.z - a.z),
328
+ toA = toOther + Math.PI,
329
+ aFaces = offFacing(toOther, a.yaw),
330
+ bFaces = offFacing(toA, other.yaw);
331
+ if (aFaces > 1.2 && bFaces > 1.05) continue;
332
+ const score = d + aFaces * 1.4 + bFaces * 0.9;
333
+ if (score < bestScore) {
334
+ bestScore = score;
335
+ best = other;
336
+ }
337
+ }
338
+ return best;
339
+ }
340
+
341
+ function collectBystanders(a, b) {
342
+ _bystanders.length = 0;
343
+ for (let i = 0; i < actorList.length; i++) {
344
+ const other = actorList[i];
345
+ if (other === a || other === b || !other.active || !other.inScene) continue;
346
+ _bystanders.push({
347
+ x: other.x,
348
+ y: other.y,
349
+ z: other.z,
350
+ height: other.height,
351
+ radius: other.mount ? 0.65 : 0.28 * Math.max(1, other.height / TALL),
352
+ });
353
+ }
354
+ return _bystanders;
355
+ }
356
+
357
+ function aimRelational(a, partner, kind) {
358
+ const bias = kind === 'ots' ? 0.3 : 0.5,
359
+ ay = actorHeadTop(a) - a.height * 0.28,
360
+ by = actorHeadTop(partner) - partner.height * 0.28;
361
+ return _at.set(a.x + (partner.x - a.x) * bias, ay + (by - ay) * bias, a.z + (partner.z - a.z) * bias);
362
+ }
363
+
364
+ function setUp(cue, master, masterAim, trackState, t) {
365
+ const sp = getSpace(),
366
+ { a } = cue,
367
+ conversant = cue.b || (cue.kind === 'close' ? findConversant(a) : null),
368
+ explicitPair = cue.kind === 'pair' && !!cue.b,
369
+ down = !!ON_THE_GROUND[a.pose],
370
+ partnerDist = conversant ? Math.hypot(conversant.x - a.x, conversant.z - a.z) : 0,
371
+ ots = !explicitPair && !down && !!conversant && partnerDist <= OTS_MAX,
372
+ pair = explicitPair || (!down && !!conversant && !ots),
373
+ partner = ots || pair ? conversant : null,
374
+ kind = pair || down ? 'full' : ots ? 'ots' : cue.kind,
375
+ hold = HOLD[pair ? 'pair' : kind];
376
+
377
+ if (partner) aimRelational(a, partner, ots ? 'ots' : 'pair');
378
+ else aimAt(a, kind);
379
+
380
+ if (a.move && !partner) {
381
+ _at.x = (a.x + a.move.x1) / 2;
382
+ _at.z = (a.z + a.move.z1) / 2;
383
+ _at.y += sp.ground(_at.x, _at.z) - sp.ground(a.x, a.z);
384
+ }
385
+
386
+ if (masterHoldsReveal(master, masterAim, _at, trackState, nearestCastToAim(masterAim))) return null;
387
+
388
+ let across = a.move && !partner ? Math.hypot(a.move.x1 - a.x, a.move.z1 - a.z) * 0.6 : 0;
389
+ if (pair) across = partnerDist + PAIR_ROOM;
390
+ else if (ots) across = partnerDist * 1.15 + 1.55;
391
+
392
+ const fov = lensNow(),
393
+ half = Math.tan((LENS * Math.PI) / 360),
394
+ tall = Math.max(a.height, partner ? partner.height : 0) * VISIBLE[kind],
395
+ reach = Math.max(Math.max(tall, across / STAGE_ASPECT) / (2 * half), a.mount || partner?.mount ? MOUNTED_REACH : 0),
396
+ toMaster = Math.atan2(master.x - _at.x, master.z - _at.z),
397
+ apart = master.distanceTo(_at);
398
+ if (apart < reach * NEAR_ENOUGH || apart > FAR_AWAY) return null;
399
+
400
+ const facing = a.move ? Math.atan2(a.move.x1 - a.x, a.move.z1 - a.z) : a.yaw;
401
+ let bearings;
402
+ if (partner) {
403
+ bearings = conversationBearings(a, partner, master);
404
+ } else {
405
+ let line = toMaster;
406
+ if (!a.move && !down) {
407
+ const off = wrapRadians(toMaster - a.yaw);
408
+ line = a.yaw + Math.sign(off || 1) * Math.min(Math.abs(off), 0.35);
409
+ }
410
+ const offsets = a.move || down ? [0, ...SIDES] : SIDES;
411
+ bearings = offsets.map(side => line + side);
412
+ }
413
+
414
+ const bystanders = collectBystanders(a, partner),
415
+ sunDir = isIndoors(sp) ? null : getSunDir(),
416
+ daylight = getDaylight(),
417
+ headTop = partner ? Math.max(actorHeadTop(a), actorHeadTop(partner)) : actorHeadTop(a),
418
+ phoneAspect = Math.max(camera.aspect, 1.95);
419
+ let bestP = null,
420
+ bestScore = Infinity;
421
+
422
+ for (let i = 0; i < bearings.length; i++) {
423
+ const angle = bearings[i];
424
+ if (!down && offFacing(angle, facing) > (pair ? 1.32 : BEHIND)) continue;
425
+ if (explicitPair && partner && offFacing(angle, partner.yaw) > 1.75 && offFacing(angle, facing) > 1.15) continue;
426
+
427
+ const x = _at.x + Math.sin(angle) * reach,
428
+ z = _at.z + Math.cos(angle) * reach,
429
+ lift = down ? OVER_THE_FALLEN : kind === 'close' || kind === 'ots' ? 0.07 : 0.12,
430
+ y = Math.max(sp.ground(x, z) + 0.55, _at.y + lift * a.height);
431
+ if (!down && y > _at.y + UPHILL * a.height) continue;
432
+ _p.set(x, y, z);
433
+ if (lensBlocked(x, y, z) || crowded(_p, ROOM_TO_SET_UP, a, partner, hold) || !clearSight(_p, _at, a, partner, hold)) continue;
434
+
435
+ const subjectDepth = _p.distanceTo(_at),
436
+ edgeScore = Math.max(
437
+ bystanderEdgePenalty(_p, _at, fov, camera.aspect, bystanders, subjectDepth),
438
+ bystanderEdgePenalty(_p, _at, LENS, phoneAspect, bystanders, subjectDepth) * 0.85,
439
+ ),
440
+ glareScore = backlitGlarePenalty(_p, _at, sunDir, daylight),
441
+ score = i * 0.18 + edgeScore + glareScore;
442
+
443
+ if (score < bestScore) {
444
+ bestScore = score;
445
+ bestP = _p.clone();
446
+ if (score < 0.35) break;
447
+ }
448
+ }
449
+ if (!bestP || bestScore > 3.6) return null;
450
+ ensureHeadroom(bestP, _at, headTop, fov, HEADROOM_SHARE);
451
+ return { a, b: partner, kind, ots, began: t, until: t + hold, p: bestP };
452
+ }
453
+
454
+ function coverShot(ev, t, p, l, trackState) {
455
+ if (ev.coverage === false) return 0;
456
+ let shot = cover.shot;
457
+ if (shot) {
458
+ if (shot.b) aimRelational(shot.a, shot.b, shot.ots ? 'ots' : 'pair');
459
+ else aimAt(shot.a, shot.kind);
460
+ const turnedOut =
461
+ !ON_THE_GROUND[shot.a.pose] &&
462
+ offFacing(Math.atan2(shot.p.x - shot.a.x, shot.p.z - shot.a.z), shot.a.yaw) > (shot.b && !shot.ots ? 1.72 : TURNED_AWAY),
463
+ occluded = (getFrame() & 1) === 0 && !clearSight(shot.p, _at, shot.a, shot.b, 0);
464
+ if (
465
+ t >= shot.until ||
466
+ !shot.a.active ||
467
+ (shot.b && !shot.b.active) ||
468
+ Math.hypot(shot.a.x - shot.p.x, shot.a.z - shot.p.z) < ROOM_TO_STAY ||
469
+ turnedOut ||
470
+ occluded ||
471
+ crowded(shot.p, ROOM_TO_STAY, shot.a, shot.b)
472
+ ) {
473
+ shot = cover.shot = null;
474
+ cover.masterSince = t;
475
+ }
476
+ }
477
+ const cue = cover.cue;
478
+ if (cue && t - cue.at > 0.6) cover.cue = null;
479
+ else if (cue && t > OPENING && t < ev.dur - CLOSING && t >= cover.quietUntil) {
480
+ const free = shot ? cue.a !== shot.a && t - shot.began >= BREATH : t - cover.masterSince >= MASTER;
481
+ if (free) {
482
+ const next = setUp(cue, p, l, trackState, t);
483
+ if (next) shot = cover.shot = next;
484
+ cover.cue = null;
485
+ }
486
+ }
487
+ if (!shot) return 0;
488
+ const fov = lensNow(),
489
+ creep = 0.03 * ((t - shot.began) / (shot.until - shot.began));
490
+ if (shot.b) aimRelational(shot.a, shot.b, shot.ots ? 'ots' : 'pair');
491
+ else aimAt(shot.a, shot.kind);
492
+ l.copy(_at);
493
+ p.copy(shot.p).lerp(l, creep);
494
+ const headTop = shot.b ? Math.max(actorHeadTop(shot.a), actorHeadTop(shot.b)) : actorHeadTop(shot.a);
495
+ ensureHeadroom(p, l, headTop, fov, HEADROOM_SHARE);
496
+ return fov;
497
+ }
498
+
499
+ return { actorHeadTop, lensBlocked, clearSight, crowded, clearCoverage, coverCue, coverPose, coverQuiet, coverArrival, coverShot };
500
+ }