roamwright 0.61.20 → 0.61.22
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
- package/tools/README.md +34 -25
- package/tools/cpu-profile.cjs +117 -0
- package/tools/cpu-profile.test.cjs +31 -1
- package/tools/figure-inspect.cjs +475 -0
- package/tools/figure-inspect.test.cjs +153 -0
- package/tools/geometry-hash.cjs +361 -0
- package/tools/geometry-hash.test.cjs +146 -0
- package/tools/load-audit.cjs +199 -2
- package/tools/load-audit.test.cjs +68 -0
- package/tools/quiet-bench.cjs +202 -0
- package/tools/quiet-bench.test.cjs +91 -0
- package/tools/scene-detail.cjs +355 -0
- package/tools/scene-detail.test.cjs +162 -0
- package/tools/scrub-clear.cjs +191 -0
- package/tools/scrub-clear.test.cjs +100 -0
- package/tools/tree-inspect.cjs +271 -0
- package/tools/tree-inspect.test.cjs +123 -0
- package/tools/world-tour.cjs +223 -0
- package/tools/world-tour.test.cjs +77 -0
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { circleClearances } from '../math/circle-clearances.js';
|
|
3
|
+
import { clamp, sstep } from '../math/scalar.js';
|
|
4
|
+
|
|
5
|
+
const LABEL_ASPECT = 72 / 512;
|
|
6
|
+
const HIDDEN = new THREE.Matrix4().makeScale(0, 0, 0);
|
|
7
|
+
const _v = new THREE.Vector3();
|
|
8
|
+
const _m = new THREE.Matrix4();
|
|
9
|
+
const _ringColor = new THREE.Color();
|
|
10
|
+
const _bounds = new THREE.Box3();
|
|
11
|
+
|
|
12
|
+
/** Default HDR marker colours for light shafts, ground rings, and hovering gems. */
|
|
13
|
+
export const DEFAULT_MARKER_COLORS = {
|
|
14
|
+
beam: new THREE.Color(1.5, 0.7, 0.16),
|
|
15
|
+
beamSeen: new THREE.Color(0.16, 0.5, 0.42),
|
|
16
|
+
pending: new THREE.Color(3.2, 1.7, 0.5),
|
|
17
|
+
seen: new THREE.Color(0.2, 0.7, 0.6),
|
|
18
|
+
pendingInside: new THREE.Color(3.2, 1.7, 0.5).multiplyScalar(0.38),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Paint a pill-backed title sprite to float on a scene marker's light shaft.
|
|
23
|
+
*
|
|
24
|
+
* @param {string} text
|
|
25
|
+
* @param {object} [options]
|
|
26
|
+
* @param {string} [options.font]
|
|
27
|
+
* @param {string} [options.textColor]
|
|
28
|
+
* @param {string} [options.bgColor]
|
|
29
|
+
* @param {number} [options.labelWidth]
|
|
30
|
+
* @param {number} [options.renderOrder]
|
|
31
|
+
* @param {number} [options.anisotropy]
|
|
32
|
+
* @returns {THREE.Sprite}
|
|
33
|
+
*/
|
|
34
|
+
export function createShaftLabel(text, options = {}) {
|
|
35
|
+
const {
|
|
36
|
+
font = '500 34px sans-serif',
|
|
37
|
+
textColor = '#ffe3b0',
|
|
38
|
+
bgColor = 'rgba(12,14,16,.62)',
|
|
39
|
+
labelWidth = 6,
|
|
40
|
+
renderOrder = 9,
|
|
41
|
+
anisotropy = 4,
|
|
42
|
+
} = options;
|
|
43
|
+
const c = document.createElement('canvas');
|
|
44
|
+
c.width = 512;
|
|
45
|
+
c.height = 72;
|
|
46
|
+
const g = c.getContext('2d');
|
|
47
|
+
g.font = font;
|
|
48
|
+
g.textAlign = 'center';
|
|
49
|
+
g.textBaseline = 'middle';
|
|
50
|
+
g.shadowColor = 'rgba(0,0,0,.9)';
|
|
51
|
+
g.shadowBlur = 8;
|
|
52
|
+
const w = g.measureText(text).width;
|
|
53
|
+
const bw = Math.min(w, 460) + 40;
|
|
54
|
+
g.fillStyle = bgColor;
|
|
55
|
+
g.beginPath();
|
|
56
|
+
g.roundRect(256 - bw / 2, 6, bw, 60, 30);
|
|
57
|
+
g.fill();
|
|
58
|
+
if (w > 460) {
|
|
59
|
+
g.translate(256, 36);
|
|
60
|
+
g.scale(460 / w, 1);
|
|
61
|
+
g.translate(-256, -36);
|
|
62
|
+
}
|
|
63
|
+
g.shadowBlur = 4;
|
|
64
|
+
g.fillStyle = textColor;
|
|
65
|
+
g.fillText(text, 256, 36);
|
|
66
|
+
const tex = new THREE.CanvasTexture(c);
|
|
67
|
+
tex.colorSpace = THREE.SRGBColorSpace;
|
|
68
|
+
tex.anisotropy = anisotropy;
|
|
69
|
+
const sp = new THREE.Sprite(new THREE.SpriteMaterial({ map: tex, transparent: true, depthWrite: false, fog: false }));
|
|
70
|
+
sp.center.set(0.5, 0);
|
|
71
|
+
sp.userData.bandWidth = bw / c.width;
|
|
72
|
+
sp.scale.set(labelWidth, labelWidth * LABEL_ASPECT, 1);
|
|
73
|
+
sp.renderOrder = renderOrder;
|
|
74
|
+
return sp;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Project a world target into clamped screen coordinates for an on-screen waypoint indicator.
|
|
79
|
+
*
|
|
80
|
+
* @param {{ x: number, y: number, z: number }} target
|
|
81
|
+
* @param {THREE.Camera} camera
|
|
82
|
+
* @param {{ width: number, height: number }} viewport
|
|
83
|
+
* @param {object} [options]
|
|
84
|
+
* @param {number} [options.yOffset]
|
|
85
|
+
* @param {number} [options.clearLeft]
|
|
86
|
+
* @param {number} [options.edgeGap]
|
|
87
|
+
* @param {number} [options.topMargin]
|
|
88
|
+
* @param {number} [options.bottomMargin]
|
|
89
|
+
* @param {object} [out]
|
|
90
|
+
* @returns {{ x: number, y: number, off: boolean, behind: boolean }}
|
|
91
|
+
*/
|
|
92
|
+
export function projectWaypoint(target, camera, viewport, options = {}, out = null) {
|
|
93
|
+
const { yOffset = 3.2, clearLeft = 34, edgeGap = 34, topMargin = 96, bottomMargin = 60 } = options;
|
|
94
|
+
_v.set(target.x, target.y + yOffset, target.z).project(camera);
|
|
95
|
+
const width = viewport.width;
|
|
96
|
+
const height = viewport.height;
|
|
97
|
+
const behind = _v.z > 1;
|
|
98
|
+
let sx = (_v.x * 0.5 + 0.5) * width;
|
|
99
|
+
let sy = (-_v.y * 0.5 + 0.5) * height;
|
|
100
|
+
if (behind) {
|
|
101
|
+
sx = width - sx;
|
|
102
|
+
sy = height * 0.9;
|
|
103
|
+
}
|
|
104
|
+
const off = behind || sx < clearLeft || sx > width - edgeGap || sy < topMargin || sy > height - bottomMargin;
|
|
105
|
+
sx = Math.round(clamp(sx, clearLeft, width - edgeGap));
|
|
106
|
+
sy = Math.round(clamp(sy, topMargin, height - bottomMargin));
|
|
107
|
+
const res = out || { x: 0, y: 0, off: false, behind: false };
|
|
108
|
+
res.x = sx;
|
|
109
|
+
res.y = sy;
|
|
110
|
+
res.off = off;
|
|
111
|
+
res.behind = behind;
|
|
112
|
+
return res;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Create a manager for instanced scene markers (ground rings, bobbing gems, light shafts,
|
|
117
|
+
* overlap-culled title sprites, and walk/fly trigger reach with rearm hysteresis).
|
|
118
|
+
*
|
|
119
|
+
* @param {object} options
|
|
120
|
+
* @param {THREE.PerspectiveCamera} options.camera
|
|
121
|
+
* @param {THREE.Object3D} [options.defaultParent]
|
|
122
|
+
* @param {() => { width: number, height: number }} options.getViewport
|
|
123
|
+
* @param {{ far: number, opacity: (d: number) => number }} options.labelRange
|
|
124
|
+
* @param {(color: THREE.Color, roof: number | null) => THREE.Object3D} [options.createBeam]
|
|
125
|
+
* @param {(color: THREE.Color) => THREE.Material} [options.beamMaterial]
|
|
126
|
+
* @param {string} [options.labelFont]
|
|
127
|
+
* @param {(ev: object) => string} [options.labelText]
|
|
128
|
+
* @param {(sprite: THREE.Sprite) => void} [options.warmLabel]
|
|
129
|
+
* @param {() => number} [options.hudTopBand]
|
|
130
|
+
* @param {(left: number, top: number, right: number, bottom: number) => boolean} [options.labelOccluded]
|
|
131
|
+
* @param {number} [options.eyeHeight]
|
|
132
|
+
* @param {Partial<typeof DEFAULT_MARKER_COLORS>} [options.colors]
|
|
133
|
+
* @param {number} [options.ringRadius]
|
|
134
|
+
* @param {number} [options.ringTube]
|
|
135
|
+
* @param {number} [options.seenRingScale]
|
|
136
|
+
* @param {number} [options.gemRadius]
|
|
137
|
+
* @param {number} [options.ringUp]
|
|
138
|
+
* @param {number} [options.gemUp]
|
|
139
|
+
* @param {[number, number]} [options.gemNear]
|
|
140
|
+
* @param {number} [options.labelWidth]
|
|
141
|
+
* @param {number} [options.labelUp]
|
|
142
|
+
* @param {number} [options.labelMinPx]
|
|
143
|
+
* @param {number} [options.labelMaxPx]
|
|
144
|
+
* @param {number} [options.labelPaintPad]
|
|
145
|
+
* @param {number} [options.rearmFactor]
|
|
146
|
+
* @param {number} [options.walkReachSq]
|
|
147
|
+
* @param {number} [options.flyReachSq]
|
|
148
|
+
* @param {number} [options.walkHeightRange]
|
|
149
|
+
* @param {number} [options.flyHeightRange]
|
|
150
|
+
* @returns {{
|
|
151
|
+
* markers: Array<object>,
|
|
152
|
+
* addMarkers: (entries: Array<object>) => Array<object>,
|
|
153
|
+
* refresh: (state: object) => void,
|
|
154
|
+
* update: (frame: object) => { triggered: object | null, roomEvent: object | null },
|
|
155
|
+
* disarmAll: () => void,
|
|
156
|
+
* }}
|
|
157
|
+
*/
|
|
158
|
+
export function createSceneMarkers(options) {
|
|
159
|
+
const {
|
|
160
|
+
camera,
|
|
161
|
+
defaultParent = null,
|
|
162
|
+
getViewport,
|
|
163
|
+
labelRange,
|
|
164
|
+
createBeam = null,
|
|
165
|
+
beamMaterial = null,
|
|
166
|
+
labelFont = '500 34px sans-serif',
|
|
167
|
+
labelText = ev => ev.title || '',
|
|
168
|
+
warmLabel = null,
|
|
169
|
+
hudTopBand = () => 0,
|
|
170
|
+
labelOccluded = () => false,
|
|
171
|
+
eyeHeight = 1.65,
|
|
172
|
+
ringRadius = 2.3,
|
|
173
|
+
ringTube = 0.1,
|
|
174
|
+
seenRingScale = 0.2,
|
|
175
|
+
gemRadius = 0.55,
|
|
176
|
+
ringUp = 0.25,
|
|
177
|
+
gemUp = 2.6,
|
|
178
|
+
gemNear = [1.5, 5],
|
|
179
|
+
labelWidth = 6,
|
|
180
|
+
labelUp = 3.8,
|
|
181
|
+
labelMinPx = 28,
|
|
182
|
+
labelMaxPx = 40,
|
|
183
|
+
labelPaintPad = 2,
|
|
184
|
+
rearmFactor = 1.5,
|
|
185
|
+
walkReachSq = 17,
|
|
186
|
+
flyReachSq = 30,
|
|
187
|
+
walkHeightRange = 7,
|
|
188
|
+
flyHeightRange = 34,
|
|
189
|
+
} = options;
|
|
190
|
+
const colors = { ...DEFAULT_MARKER_COLORS, ...(options.colors || {}) };
|
|
191
|
+
const roomReach = ringRadius * 0.8;
|
|
192
|
+
const labelPaint = labelRange.far + labelPaintPad;
|
|
193
|
+
|
|
194
|
+
const markers = [];
|
|
195
|
+
const labelled = [];
|
|
196
|
+
let kit = null;
|
|
197
|
+
|
|
198
|
+
function ensureKit() {
|
|
199
|
+
if (kit) return kit;
|
|
200
|
+
kit = {
|
|
201
|
+
ringGeo: new THREE.TorusGeometry(ringRadius, ringTube, 6, 36).rotateX(Math.PI / 2),
|
|
202
|
+
gemGeo: new THREE.OctahedronGeometry(gemRadius),
|
|
203
|
+
solid: new THREE.MeshBasicMaterial(),
|
|
204
|
+
};
|
|
205
|
+
return kit;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function markerSolids(list, parent) {
|
|
209
|
+
_bounds.makeEmpty();
|
|
210
|
+
for (const m of list) _bounds.expandByPoint(_v.set(m.x, m.y, m.z));
|
|
211
|
+
const sphere = _bounds.getBoundingSphere(new THREE.Sphere());
|
|
212
|
+
sphere.radius += 4;
|
|
213
|
+
const makeInstanced = geometry => {
|
|
214
|
+
const mesh = new THREE.InstancedMesh(geometry, kit.solid, list.length);
|
|
215
|
+
for (let i = 0; i < list.length; i++) {
|
|
216
|
+
mesh.setMatrixAt(i, HIDDEN);
|
|
217
|
+
mesh.setColorAt(i, colors.pending);
|
|
218
|
+
}
|
|
219
|
+
mesh.boundingSphere = sphere;
|
|
220
|
+
mesh.matrixAutoUpdate = false;
|
|
221
|
+
parent.add(mesh);
|
|
222
|
+
return mesh;
|
|
223
|
+
};
|
|
224
|
+
const rings = makeInstanced(kit.ringGeo);
|
|
225
|
+
const gems = makeInstanced(kit.gemGeo);
|
|
226
|
+
const clearances = circleClearances(list, 0.1);
|
|
227
|
+
for (let i = 0; i < list.length; i++) {
|
|
228
|
+
const m = list[i];
|
|
229
|
+
const limit = clearances[i];
|
|
230
|
+
const ringScale = Math.min(m.roomScale, limit / (ringRadius + ringTube));
|
|
231
|
+
const reach = m.inRoom ? roomReach * ringScale : limit;
|
|
232
|
+
m.rings = rings;
|
|
233
|
+
m.gems = gems;
|
|
234
|
+
m.i = i;
|
|
235
|
+
m.ringScale = ringScale;
|
|
236
|
+
m.reachSq = reach * reach;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function addMarkers(entries) {
|
|
241
|
+
ensureKit();
|
|
242
|
+
const added = [];
|
|
243
|
+
const bySpace = new Map();
|
|
244
|
+
for (const entry of entries) {
|
|
245
|
+
const parent = entry.parent || defaultParent;
|
|
246
|
+
const { ev, x, y, z, roof = null, spaceId, inside = false } = entry;
|
|
247
|
+
const g = new THREE.Group();
|
|
248
|
+
g.position.set(x, y, z);
|
|
249
|
+
const inRoom = roof !== null && roof !== undefined;
|
|
250
|
+
const beam = createBeam ? createBeam(colors.beam, roof) : null;
|
|
251
|
+
if (beam) g.add(beam);
|
|
252
|
+
parent.add(g);
|
|
253
|
+
const marker = {
|
|
254
|
+
ev,
|
|
255
|
+
g,
|
|
256
|
+
beam,
|
|
257
|
+
label: null,
|
|
258
|
+
labelY: roof == null ? labelUp : Math.min(labelUp, roof * 0.55),
|
|
259
|
+
inRoom,
|
|
260
|
+
roomScale: inRoom ? clamp(roof * 0.2, 0.6, 1.25) / ringRadius : 1,
|
|
261
|
+
ringColor: colors.pending,
|
|
262
|
+
ringIntensity: 1,
|
|
263
|
+
x,
|
|
264
|
+
y,
|
|
265
|
+
z,
|
|
266
|
+
space: spaceId,
|
|
267
|
+
inside: Boolean(inside),
|
|
268
|
+
gemShown: false,
|
|
269
|
+
};
|
|
270
|
+
markers.push(marker);
|
|
271
|
+
added.push(marker);
|
|
272
|
+
const key = spaceId ?? parent;
|
|
273
|
+
let group = bySpace.get(key);
|
|
274
|
+
if (!group) {
|
|
275
|
+
group = { parent, list: [] };
|
|
276
|
+
bySpace.set(key, group);
|
|
277
|
+
}
|
|
278
|
+
group.list.push(marker);
|
|
279
|
+
}
|
|
280
|
+
for (const { parent, list } of bySpace.values()) markerSolids(list, parent);
|
|
281
|
+
return added;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function refresh({ shown = true, isDone, isEligible, isInReach = () => true }) {
|
|
285
|
+
for (const m of markers) {
|
|
286
|
+
if (!shown && m.label) m.label.visible = false;
|
|
287
|
+
const done = isDone(m.ev);
|
|
288
|
+
const reachable = isInReach(m.ev);
|
|
289
|
+
const el = isEligible(m.ev) && reachable;
|
|
290
|
+
m.rings.visible = m.gems.visible = shown;
|
|
291
|
+
m.g.visible = shown && reachable && (done || el);
|
|
292
|
+
if (m.beam) {
|
|
293
|
+
m.beam.visible = m.g.visible;
|
|
294
|
+
if (beamMaterial) m.beam.material = beamMaterial(done ? colors.beamSeen : colors.beam);
|
|
295
|
+
}
|
|
296
|
+
m.gemShown = el;
|
|
297
|
+
const completionScale = done ? seenRingScale : 1;
|
|
298
|
+
const radius = m.ringScale * completionScale;
|
|
299
|
+
const thickness = (m.inRoom ? m.ringScale : 1) * completionScale;
|
|
300
|
+
const ringY = m.inRoom ? ringTube * thickness + 0.025 : ringUp;
|
|
301
|
+
m.rings.setMatrixAt(m.i, m.g.visible ? _m.makeScale(radius, thickness, radius).setPosition(m.x, m.y + ringY, m.z) : HIDDEN);
|
|
302
|
+
m.ringColor = done ? colors.seen : m.inside ? colors.pendingInside : colors.pending;
|
|
303
|
+
m.ringIntensity = 1;
|
|
304
|
+
m.rings.setColorAt(m.i, m.ringColor);
|
|
305
|
+
m.gems.setColorAt(m.i, m.inside ? colors.pendingInside : colors.pending);
|
|
306
|
+
m.rings.instanceMatrix.needsUpdate = m.rings.instanceColor.needsUpdate = m.gems.instanceColor.needsUpdate = true;
|
|
307
|
+
if (!el) {
|
|
308
|
+
m.gems.setMatrixAt(m.i, HIDDEN);
|
|
309
|
+
m.gems.instanceMatrix.needsUpdate = true;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function labelBox(m, proj, up, width, height) {
|
|
315
|
+
_v.set(m.x, m.y + up, m.z).applyMatrix4(camera.matrixWorldInverse);
|
|
316
|
+
const depth = -_v.z;
|
|
317
|
+
if (depth <= camera.near || depth >= camera.far) return false;
|
|
318
|
+
_v.applyMatrix4(camera.projectionMatrix);
|
|
319
|
+
const sx = (_v.x * 0.5 + 0.5) * width;
|
|
320
|
+
const bottom = (0.5 - _v.y * 0.5) * height;
|
|
321
|
+
const tall = clamp((labelWidth * LABEL_ASPECT * proj) / depth, labelMinPx, labelMaxPx);
|
|
322
|
+
const half = (tall * m.label.userData.bandWidth) / (2 * LABEL_ASPECT);
|
|
323
|
+
const top = bottom - tall;
|
|
324
|
+
if (bottom > height || sx + half < 0 || sx - half > width || top <= hudTopBand() || labelOccluded(sx - half, top, sx + half, bottom))
|
|
325
|
+
return false;
|
|
326
|
+
const worldHeight = (tall * depth) / proj;
|
|
327
|
+
m.label.scale.set(worldHeight / LABEL_ASPECT, worldHeight, 1);
|
|
328
|
+
m.label.position.y = up;
|
|
329
|
+
if (!m.box) m.box = [0, 0, 0, 0];
|
|
330
|
+
m.box[0] = sx - half;
|
|
331
|
+
m.box[1] = top;
|
|
332
|
+
m.box[2] = sx + half;
|
|
333
|
+
m.box[3] = bottom;
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function placeLabels() {
|
|
338
|
+
for (let i = 1; i < labelled.length; i++) {
|
|
339
|
+
const m = labelled[i];
|
|
340
|
+
let j = i - 1;
|
|
341
|
+
while (j >= 0 && labelled[j].labelD > m.labelD) {
|
|
342
|
+
labelled[j + 1] = labelled[j];
|
|
343
|
+
j--;
|
|
344
|
+
}
|
|
345
|
+
labelled[j + 1] = m;
|
|
346
|
+
}
|
|
347
|
+
for (let i = 0; i < labelled.length; i++) {
|
|
348
|
+
const a = labelled[i].box;
|
|
349
|
+
let clear = true;
|
|
350
|
+
for (let k = 0; k < i && clear; k++) {
|
|
351
|
+
const b = labelled[k].box;
|
|
352
|
+
if (labelled[k].label.visible && a[2] > b[0] && a[0] < b[2] && a[3] > b[1] && a[1] < b[3]) clear = false;
|
|
353
|
+
}
|
|
354
|
+
labelled[i].label.visible = clear;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function update({ time, spaceId, canTrigger = false, player = null, flying = false, isEligible = () => false, onTrigger = null }) {
|
|
359
|
+
const vp = getViewport();
|
|
360
|
+
const proj = vp.height / (2 * Math.tan((camera.fov * Math.PI) / 360));
|
|
361
|
+
labelled.length = 0;
|
|
362
|
+
let roomEvent = null;
|
|
363
|
+
let roomDistance = labelRange.far;
|
|
364
|
+
for (let i = 0; i < markers.length; i++) {
|
|
365
|
+
const m = markers[i];
|
|
366
|
+
if (!m.g.visible || m.space !== spaceId) continue;
|
|
367
|
+
const d = _v.set(m.x, m.y + gemUp, m.z).distanceTo(camera.position);
|
|
368
|
+
if (d < labelPaint && !m.label) {
|
|
369
|
+
m.label = createShaftLabel(labelText(m.ev), { font: labelFont, labelWidth });
|
|
370
|
+
m.g.add(m.label);
|
|
371
|
+
m.label.visible = false;
|
|
372
|
+
if (warmLabel) warmLabel(m.label);
|
|
373
|
+
}
|
|
374
|
+
const titleOpacity = d < labelRange.far ? labelRange.opacity(d) : 0;
|
|
375
|
+
if (m.inRoom) {
|
|
376
|
+
const intensity = 1 - 0.72 * titleOpacity;
|
|
377
|
+
if (intensity !== m.ringIntensity) {
|
|
378
|
+
m.ringIntensity = intensity;
|
|
379
|
+
m.rings.setColorAt(m.i, _ringColor.copy(m.ringColor).multiplyScalar(intensity));
|
|
380
|
+
m.rings.instanceColor.needsUpdate = true;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
if (titleOpacity > 0) {
|
|
384
|
+
m.label.material.opacity = titleOpacity;
|
|
385
|
+
m.label.visible = false;
|
|
386
|
+
m.labelD = d;
|
|
387
|
+
if (labelBox(m, proj, m.labelY, vp.width, vp.height) || labelBox(m, proj, Math.min(m.labelY, eyeHeight), vp.width, vp.height))
|
|
388
|
+
labelled.push(m);
|
|
389
|
+
if (m.inRoom && m.gemShown && d < roomDistance) {
|
|
390
|
+
roomEvent = m;
|
|
391
|
+
roomDistance = d;
|
|
392
|
+
}
|
|
393
|
+
} else if (m.label) m.label.visible = false;
|
|
394
|
+
if (m.gemShown) {
|
|
395
|
+
const near = sstep(gemNear[0], gemNear[1], Math.hypot(camera.position.x - m.x, camera.position.z - m.z));
|
|
396
|
+
_m.makeRotationY(time * 1.4).scale(_v.setScalar(near * m.roomScale));
|
|
397
|
+
m.gems.setMatrixAt(m.i, _m.setPosition(m.x, m.y + gemUp + Math.sin(time * 1.8 + i) * 0.25, m.z));
|
|
398
|
+
m.gems.instanceMatrix.needsUpdate = true;
|
|
399
|
+
}
|
|
400
|
+
if (canTrigger && player && isEligible(m.ev)) {
|
|
401
|
+
const dx = player.x - m.x;
|
|
402
|
+
const dz = player.z - m.z;
|
|
403
|
+
const reach = Math.min(m.reachSq, flying ? flyReachSq : walkReachSq);
|
|
404
|
+
const within = dx * dx + dz * dz < reach && Math.abs(player.y - eyeHeight - m.y) < (flying ? flyHeightRange : walkHeightRange);
|
|
405
|
+
if (!within && dx * dx + dz * dz > reach * rearmFactor) m.armed = true;
|
|
406
|
+
else if (within && m.armed) {
|
|
407
|
+
if (onTrigger) onTrigger(m.ev, m);
|
|
408
|
+
return { triggered: m, roomEvent };
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
placeLabels();
|
|
413
|
+
return { triggered: null, roomEvent };
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function disarmAll() {
|
|
417
|
+
for (const m of markers) m.armed = false;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
return { markers, addMarkers, refresh, update, disarmAll };
|
|
421
|
+
}
|