@bendyline/molen-client 0.0.13 → 0.0.15

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/dist/vehicles.mjs CHANGED
@@ -1,10 +1,523 @@
1
1
  import { t as createModelSignalVisual } from "./model-signals-DLgvjBeZ.mjs";
2
2
  import { createGlassVisual } from "./glass.mjs";
3
3
  import { t as applyLivery } from "./livery-qcDLzbU9.mjs";
4
- import { i as createAircraftDamageVisual, n as drawGlassInOnePass, r as aircraftObstacleContacts, t as createVehicleInteriorVisual } from "./vehicle-interior-DJ4cXTsQ.mjs";
4
+ import { o as enableSnowCover } from "./snow-cover-Bh0woabf.mjs";
5
+ import { a as createAircraftDamageVisual, i as aircraftObstacleContacts, n as drawGlassInOnePass, t as createVehicleInteriorVisual } from "./vehicle-interior-CNLLi38s.mjs";
5
6
  import * as THREE from "three";
7
+ //#region src/rail-proxy.ts
8
+ const templates$1 = /* @__PURE__ */ new Map();
9
+ const PAINT = new THREE.Color("#ffffff");
10
+ const GEAR = new THREE.Color("#25282b");
11
+ const DECK = new THREE.Color("#34322f");
12
+ const GLASS = new THREE.Color("#1b252d");
13
+ const SCRAP = new THREE.Color("#5d554b");
14
+ /**
15
+ * Low-detail stand-in for a rail vehicle seen from a distance: a parked cut of cars in a yard, or
16
+ * far traffic. One silhouette per `rail.profile` (boxcar, covered hopper, tank car, gondola,
17
+ * flatcar with a load, double-stack well car, autorack, road locomotive, bilevel coach, light-rail
18
+ * car) over two dark trucks. Front +Z, +X the left side, y = 0 the top of rail. The painted faces
19
+ * come first (`userData.bodyVertices`) so a batch tints the body and never the running gear.
20
+ * A few dozen triangles, one material, no textures. Never dispose the cached result.
21
+ */
22
+ function railVehicleProxyGeometry(spec) {
23
+ const profile = spec.rail?.profile ?? "box";
24
+ const W = spec.width, L = spec.length, H = spec.height, r = spec.wheelRadius;
25
+ const tc = spec.rail?.truckCenters ?? L * .7;
26
+ const key = `${profile}:${W}:${L}:${H}:${r}:${tc}`;
27
+ const cached = templates$1.get(key);
28
+ if (cached) return cached;
29
+ const positions = [];
30
+ const colors = [];
31
+ const triangle = (a, b, c, color) => {
32
+ positions.push(...a, ...b, ...c);
33
+ for (let i = 0; i < 3; i++) colors.push(color.r, color.g, color.b);
34
+ };
35
+ const quad = (a, b, c, d, color) => {
36
+ triangle(a, b, c, color);
37
+ triangle(a, c, d, color);
38
+ };
39
+ /**
40
+ * A six-sided block: a `w0` by `l0` rectangle at `y0` under a `w1` by `l1` one at `y1`, centered
41
+ * on (x, z). Tapering the bottom makes a hopper's slopes; the underside is left open.
42
+ */
43
+ const block = (x, z, y0, y1, w0, l0, color, w1 = w0, l1 = l0) => {
44
+ const p = (w, l, y, sx, sz) => [
45
+ x + sx * w / 2,
46
+ y,
47
+ z + sz * l / 2
48
+ ];
49
+ const [a, b, e, d, f, g, h, k] = [
50
+ p(w0, l0, y0, -1, -1),
51
+ p(w0, l0, y0, 1, -1),
52
+ p(w0, l0, y0, 1, 1),
53
+ p(w0, l0, y0, -1, 1),
54
+ p(w1, l1, y1, -1, -1),
55
+ p(w1, l1, y1, 1, -1),
56
+ p(w1, l1, y1, 1, 1),
57
+ p(w1, l1, y1, -1, 1)
58
+ ];
59
+ quad(f, k, h, g, color);
60
+ quad(a, f, g, b, color);
61
+ quad(b, g, h, e, color);
62
+ quad(e, h, k, d, color);
63
+ quad(d, k, f, a, color);
64
+ };
65
+ /** A cylinder along Z (a tank) with closed ends. */
66
+ const barrel = (y, radius, length, color) => {
67
+ const sides = 10;
68
+ const ring = (angle, z) => [
69
+ Math.cos(angle) * radius,
70
+ y + Math.sin(angle) * radius,
71
+ z
72
+ ];
73
+ const z0 = -length / 2, z1 = length / 2;
74
+ for (let i = 0; i < sides; i++) {
75
+ const t0 = i / sides * Math.PI * 2, t1 = (i + 1) / sides * Math.PI * 2;
76
+ quad(ring(t0, z0), ring(t1, z0), ring(t1, z1), ring(t0, z1), color);
77
+ triangle([
78
+ 0,
79
+ y,
80
+ z1
81
+ ], ring(t0, z1), ring(t1, z1), color);
82
+ triangle([
83
+ 0,
84
+ y,
85
+ z0
86
+ ], ring(t1, z0), ring(t0, z0), color);
87
+ }
88
+ };
89
+ /** A dark band (windows) on both sides, a hair outside the body. */
90
+ const windows = (y0, y1, half, length) => {
91
+ for (const side of [-1, 1]) {
92
+ const x = side * (half + .01);
93
+ const a = [
94
+ x,
95
+ y0,
96
+ -length / 2
97
+ ];
98
+ const b = [
99
+ x,
100
+ y0,
101
+ length / 2
102
+ ];
103
+ const c = [
104
+ x,
105
+ y1,
106
+ length / 2
107
+ ];
108
+ const d = [
109
+ x,
110
+ y1,
111
+ -length / 2
112
+ ];
113
+ if (side > 0) quad(a, d, c, b, GLASS);
114
+ else quad(a, b, c, d, GLASS);
115
+ }
116
+ };
117
+ const deck = Math.max(1.05, r * 2 + .15);
118
+ switch (profile) {
119
+ case "hopper":
120
+ block(0, 0, 2.2, H - .12, W * .97, L * .94, PAINT);
121
+ block(0, 0, deck - .1, 2.2, W * .58, L * .6, PAINT, W * .97, L * .94);
122
+ block(0, 0, H - .12, H, W * .97, L * .94, PAINT, W * .55, L * .92);
123
+ break;
124
+ case "tank": {
125
+ const radius = Math.min(W * .48, (H - deck) / 2);
126
+ barrel(H - radius, radius, L * .94, PAINT);
127
+ break;
128
+ }
129
+ case "gondola":
130
+ for (const side of [-1, 1]) {
131
+ block(side * (W - .14) / 2, 0, deck, H, .14, L * .98, PAINT);
132
+ block(0, side * (L * .98 - .14) / 2, deck, H, W, .14, PAINT);
133
+ }
134
+ break;
135
+ case "flat":
136
+ for (const side of [-1, 1]) block(side * (W / 2 + .18) / 2, 0, deck + .25, H - .2, W / 2 - .3, L * .88, PAINT);
137
+ break;
138
+ case "well": {
139
+ const box = Math.min(2.6, W * .8);
140
+ const split = Math.max(deck + 1, (H + .4) / 2);
141
+ block(0, 0, .45, split, box, L * .74, PAINT);
142
+ block(0, 0, split + .02, H, box, L * .74, PAINT);
143
+ break;
144
+ }
145
+ case "locomotive": {
146
+ const cab = L * .17;
147
+ block(0, -L / 2 + (L / 2 + cab) / 2, deck + .25, H - .4, W * .62, L / 2 + cab - .3, PAINT);
148
+ block(0, cab + L * .08, deck + .25, H, W * .95, L * .16, PAINT);
149
+ block(0, L * .415, deck + .25, Math.min(H, deck + 1.55), W * .86, L * .15, PAINT);
150
+ break;
151
+ }
152
+ case "coach":
153
+ case "railcar":
154
+ block(0, 0, profile === "coach" ? .55 : .4, H - .3, W, L * .99, PAINT);
155
+ block(0, 0, H - .3, H, W, L * .99, PAINT, W * .7, L * .97);
156
+ break;
157
+ default: block(0, 0, deck + .2, H, W * .98, L * .98, PAINT);
158
+ }
159
+ const bodyVertices = positions.length / 3;
160
+ switch (profile) {
161
+ case "box":
162
+ case "autorack":
163
+ case "hopper":
164
+ block(0, 0, deck - .05, deck + .2, W * .9, L, DECK);
165
+ break;
166
+ case "tank":
167
+ block(0, 0, deck - .1, deck + .35, .7, L * .9, DECK);
168
+ break;
169
+ case "gondola":
170
+ block(0, 0, deck - .1, deck + .1, W, L, DECK);
171
+ block(0, 0, deck + .1, Math.max(deck + .4, H - .45), W - .4, L * .85, SCRAP, W * .6, L * .6);
172
+ break;
173
+ case "flat":
174
+ block(0, 0, deck - .1, deck + .25, W, L, DECK);
175
+ block(0, 0, deck + .25, H, .25, L * .9, DECK);
176
+ break;
177
+ case "well":
178
+ for (const side of [-1, 1]) block(side * W * .9 / 2, 0, .4, deck + .2, .3, L * .8, DECK);
179
+ for (const end of [-1, 1]) block(0, end * L * .43, deck - .1, deck + .25, W, L * .14, DECK);
180
+ break;
181
+ case "locomotive":
182
+ block(0, 0, deck, deck + .25, W, L, DECK);
183
+ block(0, 0, .55, deck, W * .72, L * .36, DECK);
184
+ quad([
185
+ -W * .42,
186
+ H - .95,
187
+ L * .33 + .01
188
+ ], [
189
+ W * .42,
190
+ H - .95,
191
+ L * .33 + .01
192
+ ], [
193
+ W * .42,
194
+ H - .3,
195
+ L * .33 + .01
196
+ ], [
197
+ -W * .42,
198
+ H - .3,
199
+ L * .33 + .01
200
+ ], GLASS);
201
+ break;
202
+ case "coach":
203
+ windows(1.25, 1.95, W / 2, L * .62);
204
+ windows(2.95, 3.65, W / 2, L * .62);
205
+ break;
206
+ case "railcar":
207
+ windows(1.15, 2.6, W / 2, L * .86);
208
+ break;
209
+ }
210
+ const truck = profile === "locomotive" && L > 20 ? 4.3 : profile === "locomotive" ? 3.3 : 2.9;
211
+ for (const end of [-1, 1]) block(0, end * tc / 2, .12, Math.max(.9, r * 2 + .05), Math.min(W * .85, 2.6), truck, GEAR);
212
+ const geometry = new THREE.BufferGeometry();
213
+ geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
214
+ geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
215
+ geometry.computeVertexNormals();
216
+ geometry.computeBoundingBox();
217
+ geometry.computeBoundingSphere();
218
+ geometry.userData.bodyVertices = bodyVertices;
219
+ templates$1.set(key, geometry);
220
+ return geometry;
221
+ }
222
+ //#endregion
6
223
  //#region src/vehicle-proxy.ts
7
224
  const templates = /* @__PURE__ */ new Map();
225
+ /** Collects flat-coloured faces; `paint` marks where the tinted body ends. */
226
+ function proxyBuilder() {
227
+ const positions = [];
228
+ const colors = [];
229
+ let bodyVertices = 0;
230
+ const triangle = (a, b, c, color) => {
231
+ positions.push(...a, ...b, ...c);
232
+ for (let i = 0; i < 3; i++) colors.push(color.r, color.g, color.b);
233
+ };
234
+ const quad = (a, b, c, d, color) => {
235
+ triangle(a, b, d, color);
236
+ triangle(b, c, d, color);
237
+ };
238
+ /** An axis-aligned box from min to max corners; the bottom face is left out. */
239
+ const box = (min, max, color, taperTop = 1) => {
240
+ const [x0, y0, z0] = min;
241
+ const [x1, y1, z1] = max;
242
+ const cx = (x0 + x1) / 2;
243
+ const tx0 = cx + (x0 - cx) * taperTop, tx1 = cx + (x1 - cx) * taperTop;
244
+ quad([
245
+ x0,
246
+ y0,
247
+ z1
248
+ ], [
249
+ x1,
250
+ y0,
251
+ z1
252
+ ], [
253
+ tx1,
254
+ y1,
255
+ z1
256
+ ], [
257
+ tx0,
258
+ y1,
259
+ z1
260
+ ], color);
261
+ quad([
262
+ x1,
263
+ y0,
264
+ z0
265
+ ], [
266
+ x0,
267
+ y0,
268
+ z0
269
+ ], [
270
+ tx0,
271
+ y1,
272
+ z0
273
+ ], [
274
+ tx1,
275
+ y1,
276
+ z0
277
+ ], color);
278
+ quad([
279
+ x1,
280
+ y0,
281
+ z1
282
+ ], [
283
+ x1,
284
+ y0,
285
+ z0
286
+ ], [
287
+ tx1,
288
+ y1,
289
+ z0
290
+ ], [
291
+ tx1,
292
+ y1,
293
+ z1
294
+ ], color);
295
+ quad([
296
+ x0,
297
+ y0,
298
+ z0
299
+ ], [
300
+ x0,
301
+ y0,
302
+ z1
303
+ ], [
304
+ tx0,
305
+ y1,
306
+ z1
307
+ ], [
308
+ tx0,
309
+ y1,
310
+ z0
311
+ ], color);
312
+ quad([
313
+ tx0,
314
+ y1,
315
+ z1
316
+ ], [
317
+ tx1,
318
+ y1,
319
+ z1
320
+ ], [
321
+ tx1,
322
+ y1,
323
+ z0
324
+ ], [
325
+ tx0,
326
+ y1,
327
+ z0
328
+ ], color);
329
+ };
330
+ /** An eight-sided tyre on an x axle, both caps. */
331
+ const tyre = (x, z, r, width, tread, face) => {
332
+ const [left, right] = [-1, 1].map((side) => Array.from({ length: 8 }, (_, i) => {
333
+ const a = i * Math.PI / 4;
334
+ return [
335
+ x + side * width / 2,
336
+ r + Math.cos(a) * r,
337
+ z + Math.sin(a) * r
338
+ ];
339
+ }));
340
+ for (let i = 0; i < 8; i++) {
341
+ const j = (i + 1) % 8;
342
+ quad(left[i], left[j], right[j], right[i], tread);
343
+ }
344
+ for (let i = 1; i < 7; i++) {
345
+ triangle(right[0], right[i], right[i + 1], face);
346
+ triangle(left[0], left[i + 1], left[i], face);
347
+ }
348
+ };
349
+ return {
350
+ triangle,
351
+ quad,
352
+ box,
353
+ tyre,
354
+ /** Everything added so far is tinted body. */
355
+ paint() {
356
+ bodyVertices = positions.length / 3;
357
+ },
358
+ finish(key) {
359
+ const geometry = new THREE.BufferGeometry();
360
+ geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
361
+ geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
362
+ geometry.computeVertexNormals();
363
+ geometry.computeBoundingBox();
364
+ geometry.computeBoundingSphere();
365
+ geometry.userData.bodyVertices = bodyVertices;
366
+ templates.set(key, geometry);
367
+ return geometry;
368
+ }
369
+ };
370
+ }
371
+ const PROXY_TYRE = new THREE.Color("#20242a");
372
+ const PROXY_WHEEL = new THREE.Color("#424950");
373
+ const PROXY_SEAT = new THREE.Color("#26292d");
374
+ const PROXY_GLASS = new THREE.Color("#4d6178");
375
+ const PROXY_CANOPY = new THREE.Color("#e2b33c");
376
+ const PROXY_PAINT = new THREE.Color("#ffffff");
377
+ /**
378
+ * Street-distance silhouette of a parked motorcycle, scooter or moped: two tyres in line, a
379
+ * painted body and front shield, seat and bars. About 110 triangles, one material, painted faces
380
+ * first. Never dispose the cached result.
381
+ */
382
+ function twoWheelerProxyGeometry(spec) {
383
+ const { width: w, length: l, height: h, wheelbase: wb, wheelRadius: r } = spec;
384
+ const key = `two:${w}:${l}:${h}:${wb}:${r}`;
385
+ const cached = templates.get(key);
386
+ if (cached) return cached;
387
+ const b = proxyBuilder();
388
+ const body = Math.min(.32, w * .42) / 2;
389
+ const seat = h * .7;
390
+ b.box([
391
+ -body,
392
+ r * .9,
393
+ -l * .45
394
+ ], [
395
+ body,
396
+ seat - .05,
397
+ wb * .12
398
+ ], PROXY_PAINT, .85);
399
+ b.box([
400
+ -body * 1.1,
401
+ r * 1.1,
402
+ wb * .22
403
+ ], [
404
+ body * 1.1,
405
+ h * .82,
406
+ wb * .36
407
+ ], PROXY_PAINT, .8);
408
+ b.box([
409
+ -.05,
410
+ r,
411
+ wb * .36
412
+ ], [
413
+ .05,
414
+ h * .84,
415
+ wb * .46
416
+ ], PROXY_PAINT);
417
+ b.paint();
418
+ b.box([
419
+ -body * .85,
420
+ seat - .05,
421
+ -l * .42
422
+ ], [
423
+ body * .85,
424
+ seat + .04,
425
+ -wb * .02
426
+ ], PROXY_SEAT, .8);
427
+ b.box([
428
+ -w * .45,
429
+ h * .86,
430
+ wb * .24
431
+ ], [
432
+ w * .45,
433
+ h * .9,
434
+ wb * .3
435
+ ], PROXY_SEAT);
436
+ for (const z of [-wb / 2, wb / 2]) b.tyre(0, z, r, .09, PROXY_TYRE, PROXY_WHEEL);
437
+ return b.finish(key);
438
+ }
439
+ /**
440
+ * Street-distance silhouette of a parked auto-rickshaw: a body tapering to the nose under a
441
+ * canvas canopy on four posts, a windscreen, one front and two rear tyres. About 170 triangles,
442
+ * one material, painted faces first. Never dispose the cached result.
443
+ */
444
+ function threeWheelerProxyGeometry(spec) {
445
+ const { width: w, length: l, height: h, wheelbase: wb, wheelTrack: track, wheelRadius: r } = spec;
446
+ const key = `three:${w}:${l}:${h}:${wb}:${track}:${r}`;
447
+ const cached = templates.get(key);
448
+ if (cached) return cached;
449
+ const b = proxyBuilder();
450
+ const front = l / 2 - .05, rear = -l / 2;
451
+ const belt = h * .55;
452
+ b.box([
453
+ -w / 2,
454
+ r * 1.3,
455
+ rear
456
+ ], [
457
+ w / 2,
458
+ belt,
459
+ -l * .12
460
+ ], PROXY_PAINT);
461
+ b.box([
462
+ -w * .42,
463
+ r * 1.3,
464
+ -l * .12
465
+ ], [
466
+ w * .42,
467
+ r * 1.6,
468
+ front - .4
469
+ ], PROXY_PAINT);
470
+ b.box([
471
+ -w * .34,
472
+ r * 2.3,
473
+ front - .45
474
+ ], [
475
+ w * .34,
476
+ belt + .06,
477
+ front
478
+ ], PROXY_PAINT, .7);
479
+ b.paint();
480
+ const roof = h - .06;
481
+ b.box([
482
+ -w * .48,
483
+ roof,
484
+ rear + .08
485
+ ], [
486
+ w * .48,
487
+ h,
488
+ front - .5
489
+ ], PROXY_CANOPY, .94);
490
+ for (const x of [-w * .46, w * .46]) for (const z of [rear + .12, -.08]) b.box([
491
+ x - .025,
492
+ belt,
493
+ z - .025
494
+ ], [
495
+ x + .025,
496
+ roof,
497
+ z + .025
498
+ ], PROXY_SEAT);
499
+ const glassZ = front - .48;
500
+ b.quad([
501
+ -w * .32,
502
+ belt + .06,
503
+ glassZ + .06
504
+ ], [
505
+ w * .32,
506
+ belt + .06,
507
+ glassZ + .06
508
+ ], [
509
+ w * .32,
510
+ roof,
511
+ glassZ - .04
512
+ ], [
513
+ -w * .32,
514
+ roof,
515
+ glassZ - .04
516
+ ], PROXY_GLASS);
517
+ b.tyre(0, wb / 2, r, .1, PROXY_TYRE, PROXY_WHEEL);
518
+ for (const x of [-track / 2, track / 2]) b.tyre(x, -wb / 2, r, .1, PROXY_TYRE, PROXY_WHEEL);
519
+ return b.finish(key);
520
+ }
8
521
  /**
9
522
  * Shared street-distance silhouette for parked cars and instanced traffic. Painted faces come
10
523
  * first so a static batch can tint the body and roof without tinting the glass, tyres or lamps.
@@ -286,6 +799,13 @@ function vehicleCameraPose(transform, spec, options) {
286
799
  }
287
800
  //#endregion
288
801
  //#region src/vehicles.ts
802
+ /** The stand-in for a parked vehicle: a rail car's silhouette on track, a car's on the street. */
803
+ function parkedProxyGeometry(spec) {
804
+ if (spec.rail !== void 0) return railVehicleProxyGeometry(spec);
805
+ if (spec.cycle !== void 0) return twoWheelerProxyGeometry(spec);
806
+ if (spec.bodyStyle === "auto-rickshaw") return threeWheelerProxyGeometry(spec);
807
+ return vehicleProxyGeometry(spec);
808
+ }
289
809
  const bodyLean = new THREE.Quaternion();
290
810
  const leanEuler = new THREE.Euler(0, 0, 0, "YXZ");
291
811
  const leaned = new THREE.Vector3();
@@ -317,6 +837,7 @@ function createVehicleVisual(model, vehicle, livery, glassData) {
317
837
  const cloned = (Array.isArray(object.material) ? object.material : [object.material]).map((source) => {
318
838
  const material = source.clone();
319
839
  if (color !== void 0 && source.name === vehicle.visual.paintMaterial && "color" in material) material.color.copy(color);
840
+ if (source.name === vehicle.visual.paintMaterial && vehicle.spec?.cycle === void 0) enableSnowCover(material, VEHICLE_SNOW);
320
841
  return material;
321
842
  });
322
843
  object.material = Array.isArray(object.material) ? cloned : cloned[0];
@@ -393,11 +914,16 @@ function createVehicleVisual(model, vehicle, livery, glassData) {
393
914
  }
394
915
  };
395
916
  }
396
- const parkedMaterial = new THREE.MeshStandardMaterial({
917
+ /**
918
+ * Share of a standing vehicle's up-facing bodywork that lying snow whitens (`enableSnowCover`): a
919
+ * frosting on the roof, hood and trunk rather than a drift, since a car is also driven away.
920
+ */
921
+ const VEHICLE_SNOW = .7;
922
+ const parkedMaterial = enableSnowCover(new THREE.MeshStandardMaterial({
397
923
  vertexColors: true,
398
924
  roughness: .55,
399
925
  metalness: .12
400
- });
926
+ }), VEHICLE_SNOW);
401
927
  const paints = /* @__PURE__ */ new Map();
402
928
  /** The shared vertex-coloured material of parked and proxy vehicles. */
403
929
  const vehicleProxyMaterial = parkedMaterial;
@@ -411,7 +937,7 @@ function createParkedVehicleBatch(placements, origin = [0, 0]) {
411
937
  const group = new THREE.Group();
412
938
  group.name = "surface:parked-cars";
413
939
  if (placements.length === 0) return group;
414
- const templates = placements.map((placement) => vehicleProxyGeometry(placement.spec));
940
+ const templates = placements.map((placement) => parkedProxyGeometry(placement.spec));
415
941
  const vertices = templates.reduce((sum, template) => sum + template.getAttribute("position").count, 0);
416
942
  const positions = new Float32Array(vertices * 3);
417
943
  const normals = new Float32Array(vertices * 3);
@@ -485,6 +1011,47 @@ function createParkedVehicleBatch(placements, origin = [0, 0]) {
485
1011
  group.add(mesh);
486
1012
  return group;
487
1013
  }
1014
+ /**
1015
+ * Dormant cars as one instanced mesh per body size, for a car park of hundreds where a merged
1016
+ * batch would cost more than the building. Each mesh keeps the batch's `vehicleIds` contract:
1017
+ * instance `i` belongs to `userData.vehicleIds[i]`, and `setParkedVehicleHidden` hides it.
1018
+ */
1019
+ function createParkedVehicleInstances(placements, origin = [0, 0]) {
1020
+ const group = new THREE.Group();
1021
+ group.name = "surface:parked-cars";
1022
+ const sizes = /* @__PURE__ */ new Map();
1023
+ for (const placement of placements) {
1024
+ const { width, length, height, wheelbase, rail } = placement.spec;
1025
+ const key = `${width}:${length}:${height}:${wheelbase}:${rail?.profile ?? ""}`;
1026
+ const size = sizes.get(key);
1027
+ if (size) size.push(placement);
1028
+ else sizes.set(key, [placement]);
1029
+ }
1030
+ const matrix = new THREE.Matrix4();
1031
+ const rotation = new THREE.Quaternion();
1032
+ const position = new THREE.Vector3();
1033
+ const scale = new THREE.Vector3(1, 1, 1);
1034
+ const euler = new THREE.Euler(0, 0, 0, "YXZ");
1035
+ const paint = new THREE.Color();
1036
+ for (const size of sizes.values()) {
1037
+ const first = size[0];
1038
+ const mesh = new THREE.InstancedMesh(parkedProxyGeometry(first.spec), vehicleProxyMaterial, size.length);
1039
+ size.forEach((placement, index) => {
1040
+ position.set(placement.position[0] - origin[0], placement.position[1], placement.position[2] - origin[1]);
1041
+ euler.set(placement.pitch ?? 0, placement.yaw, placement.roll ?? 0);
1042
+ rotation.setFromEuler(euler);
1043
+ mesh.setMatrixAt(index, matrix.compose(position, rotation, scale));
1044
+ mesh.setColorAt(index, paint.set(placement.color));
1045
+ });
1046
+ mesh.computeBoundingBox();
1047
+ mesh.computeBoundingSphere();
1048
+ mesh.name = "vehicle:parked";
1049
+ mesh.userData.vehicleIds = size.map((placement) => placement.id);
1050
+ mesh.receiveShadow = true;
1051
+ group.add(mesh);
1052
+ }
1053
+ return group;
1054
+ }
488
1055
  /** Whether `setParkedVehicleHidden` currently hides car `index` of a parked batch. */
489
1056
  function isParkedVehicleHidden(batch, index) {
490
1057
  return batch.userData.vehicleHidden?.has(index) ?? false;
@@ -494,6 +1061,7 @@ function isParkedVehicleHidden(batch, index) {
494
1061
  * model or a driven entity stands in for it. Returns whether the geometry changed.
495
1062
  */
496
1063
  function setParkedVehicleHidden(batch, index, hidden) {
1064
+ if (batch.isInstancedMesh) return setInstanceHidden(batch, index, hidden);
497
1065
  const ranges = batch.userData.vehicleRanges;
498
1066
  const start = ranges?.[index * 2];
499
1067
  const count = ranges?.[index * 2 + 1];
@@ -518,5 +1086,26 @@ function setParkedVehicleHidden(batch, index, hidden) {
518
1086
  attribute.needsUpdate = true;
519
1087
  return true;
520
1088
  }
1089
+ /** A zero matrix collapses the instance to a point, as a hidden batch car does. */
1090
+ function setInstanceHidden(mesh, index, hidden) {
1091
+ if (index < 0 || index >= mesh.count) return false;
1092
+ let saved = mesh.userData.vehicleHidden;
1093
+ if (saved === void 0) {
1094
+ saved = /* @__PURE__ */ new Map();
1095
+ mesh.userData.vehicleHidden = saved;
1096
+ }
1097
+ if (saved.has(index) === hidden) return false;
1098
+ const array = mesh.instanceMatrix.array;
1099
+ const from = index * 16;
1100
+ if (hidden) {
1101
+ saved.set(index, array.slice(from, from + 16));
1102
+ array.fill(0, from, from + 16);
1103
+ } else {
1104
+ array.set(saved.get(index), from);
1105
+ saved.delete(index);
1106
+ }
1107
+ mesh.instanceMatrix.needsUpdate = true;
1108
+ return true;
1109
+ }
521
1110
  //#endregion
522
- export { createParkedVehicleBatch, createVehicleInteriorVisual, createVehicleVisual, isParkedVehicleHidden, setParkedVehicleHidden, vehicleCameraPose, aircraftObstacleContacts as vehicleObstacleContacts, vehicleProxyGeometry, vehicleProxyMaterial };
1111
+ export { createParkedVehicleBatch, createParkedVehicleInstances, createVehicleInteriorVisual, createVehicleVisual, isParkedVehicleHidden, railVehicleProxyGeometry, setParkedVehicleHidden, threeWheelerProxyGeometry, twoWheelerProxyGeometry, vehicleCameraPose, aircraftObstacleContacts as vehicleObstacleContacts, vehicleProxyGeometry, vehicleProxyMaterial };
@@ -159,17 +159,21 @@ function installWebGpuCloudShadows(renderer, uniforms) {
159
159
  const field = uniform(uniforms.molenCloudField.value).setGroup(renderGroup);
160
160
  const weights = uniform(uniforms.molenCloudMix.value).setGroup(renderGroup);
161
161
  const fit = uniform(uniforms.molenCloudFit.value).setGroup(renderGroup);
162
- const factor = (light) => {
163
- const toLight = normalize(lightPosition(light).sub(lightTargetPosition(light))).toVar();
164
- const world = positionWorld;
165
- const cast = mix(shadow.y, shadow.z, fit.z);
166
- const w = texture(map, world.xz.add(toLight.xz.mul(max(cast.sub(world.y), 0).div(max(toLight.y, .05)))).mul(field.x).add(field.yz), 0);
167
- const soft = fit.x;
168
- const cell = dot(w, weights).toVar();
169
- const cover = clamp(cell.add(field.w.mul(soft.add(1))).sub(1).div(soft), 0, 1).mul(fit.w.mul(cell.oneMinus()).oneMinus());
170
- const strength = select(toLight.y.greaterThan(0), shadow.x.mul(smoothstep(shadow.y, shadow.z, world.y).oneMinus()), float(0));
171
- return mix(float(1), exp(cover.mul(fit.y).negate()), strength);
172
- };
162
+ const factor = (light) => Fn(() => {
163
+ const result = float(1).toVar();
164
+ If(shadow.x.greaterThan(0), () => {
165
+ const toLight = normalize(lightPosition(light).sub(lightTargetPosition(light))).toVar();
166
+ const world = positionWorld;
167
+ const cast = mix(shadow.y, shadow.z, fit.z);
168
+ const w = texture(map, world.xz.add(toLight.xz.mul(max(cast.sub(world.y), 0).div(max(toLight.y, .05)))).mul(field.x).add(field.yz), 0);
169
+ const soft = fit.x;
170
+ const cell = dot(w, weights).toVar();
171
+ const cover = clamp(cell.add(field.w.mul(soft.add(1))).sub(1).div(soft), 0, 1).mul(fit.w.mul(cell.oneMinus()).oneMinus());
172
+ const strength = select(toLight.y.greaterThan(0), shadow.x.mul(smoothstep(shadow.y, shadow.z, world.y).oneMinus()), float(0));
173
+ result.assign(mix(float(1), exp(cover.mul(fit.y).negate()), strength));
174
+ });
175
+ return result;
176
+ })();
173
177
  class CloudShadowedLightNode extends DirectionalLightNode {
174
178
  setupDirect(builder) {
175
179
  const direct = super.setupDirect(builder);