@maptoolkit/maplibre-scene3d-control 0.3.0 → 0.3.1

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.
@@ -18106,20 +18106,20 @@ function Zg(e) {
18106
18106
  }
18107
18107
  //#endregion
18108
18108
  //#region src/GltfManager.ts
18109
- var Qg = Math.PI / 180, $g = .25, e_ = .1, t_ = 16, n_ = 1, r_ = 1.2, i_ = .1, a_ = 150, o_ = 1.5, s_ = 20, c_ = (e) => `\u0000impostor:${e}`, l_ = new G().makeScale(-1, 1, 1), u_ = 128, d_ = "\n#include <map_fragment>\n#ifdef USE_MAP\n diffuseColor.rgb /= max( sampledDiffuseColor.a, 0.0001 );\n#endif\n", f_ = 20, p_ = "\nuniform vec3 mtkRight;\n#include <common>\n", m_ = "\nvec4 mvPosition = vec4( transformed, 1.0 );\n#ifdef USE_INSTANCING\n mvPosition = vec4(\n instanceMatrix[ 3 ].xyz\n + mtkRight * transformed.x * length( instanceMatrix[ 0 ].xyz )\n + vec3( 0.0, transformed.y * length( instanceMatrix[ 1 ].xyz ), 0.0 ),\n 1.0\n );\n#endif\nmvPosition = modelViewMatrix * mvPosition;\ngl_Position = projectionMatrix * mvPosition;\n", h_ = "\n#include <color_pars_vertex>\n#ifdef MTK_INSTANCE_ALPHA\n attribute float instanceAlpha;\n varying float vInstanceAlpha;\n#endif\n", g_ = "\n#include <color_vertex>\n#ifdef MTK_INSTANCE_ALPHA\n vInstanceAlpha = instanceAlpha;\n#endif\n", __ = "\n#include <color_pars_fragment>\n#if defined( USE_INSTANCING_COLOR ) && !defined( USE_COLOR ) && !defined( USE_COLOR_ALPHA )\n varying vec4 vColor;\n#endif\n#ifdef MTK_INSTANCE_ALPHA\n varying float vInstanceAlpha;\n#endif\n#ifdef MTK_OPACITY\n uniform float mtkOpacity;\n#endif\n", v_ = "\n#ifdef MTK_INSTANCE_ALPHA\n diffuseColor.a *= vInstanceAlpha;\n#endif\n#ifdef MTK_OPACITY\n diffuseColor.a *= mtkOpacity;\n#endif\n", y_ = `
18109
+ var Qg = Math.PI / 180, $g = 25, e_ = .25, t_ = .1, n_ = 16, r_ = 1, i_ = 1.2, a_ = .1, o_ = 150, s_ = 1.5, c_ = 20, l_ = (e) => `\u0000impostor:${e}`, u_ = new G().makeScale(-1, 1, 1), d_ = 128, f_ = "\n#include <map_fragment>\n#ifdef USE_MAP\n diffuseColor.rgb /= max( sampledDiffuseColor.a, 0.0001 );\n#endif\n", p_ = 20, m_ = "\nuniform vec3 mtkRight;\n#include <common>\n", h_ = "\nvec4 mvPosition = vec4( transformed, 1.0 );\n#ifdef USE_INSTANCING\n mvPosition = vec4(\n instanceMatrix[ 3 ].xyz\n + mtkRight * transformed.x * length( instanceMatrix[ 0 ].xyz )\n + vec3( 0.0, transformed.y * length( instanceMatrix[ 1 ].xyz ), 0.0 ),\n 1.0\n );\n#endif\nmvPosition = modelViewMatrix * mvPosition;\ngl_Position = projectionMatrix * mvPosition;\n", g_ = "\n#include <color_pars_vertex>\n#ifdef MTK_INSTANCE_ALPHA\n attribute float instanceAlpha;\n varying float vInstanceAlpha;\n#endif\n", __ = "\n#include <color_vertex>\n#ifdef MTK_INSTANCE_ALPHA\n vInstanceAlpha = instanceAlpha;\n#endif\n", v_ = "\n#include <color_pars_fragment>\n#if defined( USE_INSTANCING_COLOR ) && !defined( USE_COLOR ) && !defined( USE_COLOR_ALPHA )\n varying vec4 vColor;\n#endif\n#ifdef MTK_INSTANCE_ALPHA\n varying float vInstanceAlpha;\n#endif\n#ifdef MTK_OPACITY\n uniform float mtkOpacity;\n#endif\n", y_ = "\n#ifdef MTK_INSTANCE_ALPHA\n diffuseColor.a *= vInstanceAlpha;\n#endif\n#ifdef MTK_OPACITY\n diffuseColor.a *= mtkOpacity;\n#endif\n", b_ = `
18110
18110
  #include <color_fragment>
18111
18111
  #if defined( USE_INSTANCING_COLOR ) && !defined( USE_COLOR ) && !defined( USE_COLOR_ALPHA )
18112
18112
  diffuseColor.rgb *= vColor.rgb;
18113
18113
  #endif
18114
18114
  #ifndef MTK_ALPHA_AFTER_TEST
18115
- ${v_}
18115
+ ${y_}
18116
18116
  #endif
18117
- `, b_ = `
18117
+ `, x_ = `
18118
18118
  #include <alphatest_fragment>
18119
18119
  #ifdef MTK_ALPHA_AFTER_TEST
18120
- ${v_}
18120
+ ${y_}
18121
18121
  #endif
18122
- `, x_ = class {
18122
+ `, S_ = class {
18123
18123
  origin;
18124
18124
  map;
18125
18125
  group;
@@ -18134,6 +18134,7 @@ ${v_}
18134
18134
  patched = /* @__PURE__ */ new WeakSet();
18135
18135
  impostorRight = { value: new H(1, 0, 0) };
18136
18136
  lastThinScale = 1;
18137
+ viewMatrix;
18137
18138
  impostorMaterials = /* @__PURE__ */ new WeakSet();
18138
18139
  ownTransparent = /* @__PURE__ */ new WeakMap();
18139
18140
  opacityUniform = { value: 1 };
@@ -18159,7 +18160,7 @@ ${v_}
18159
18160
  sMat = new G();
18160
18161
  sColor = new K();
18161
18162
  constructor(e, t, n, r, i) {
18162
- this.map = e, this.scene = t, this.terrainSourceId = r, this.config = i, this.origin = k_(n), this.filter = Zm(i.filter, "filter").filter, this.group = new On(), t.add(this.group);
18163
+ this.map = e, this.scene = t, this.terrainSourceId = r, this.config = i, this.origin = A_(n), this.filter = Zm(i.filter, "filter").filter, this.group = new On(), t.add(this.group);
18163
18164
  let a = e.getSource(i.sourceId);
18164
18165
  a || console.error(`GltfLayer: source '${i.sourceId}' not found — add it before the layer`), this.wholeDataset = a?.type === "geojson";
18165
18166
  for (let [e, t] of Object.entries(i.models)) this.loadModel(e, t);
@@ -18195,7 +18196,7 @@ ${v_}
18195
18196
  refreshSoon() {
18196
18197
  this.disposed || (this.settleTimer !== void 0 && clearTimeout(this.settleTimer), this.settleTimer = setTimeout(() => {
18197
18198
  this.settleTimer = void 0, this.map.isMoving() || this.refresh();
18198
- }, a_));
18199
+ }, o_));
18199
18200
  }
18200
18201
  refresh() {
18201
18202
  this.schedule(!0, !0);
@@ -18225,7 +18226,7 @@ ${v_}
18225
18226
  let e = this.pendingDemRegions;
18226
18227
  if (this.pendingDemRegions = [], e.length === 0) return;
18227
18228
  let t = 0;
18228
- for (let n of this.batches.values()) e.some((e) => U_(e, n.bounds)) && (this.writeInstances(n), t++);
18229
+ for (let n of this.batches.values()) e.some((e) => q_(e, n.bounds)) && (this.writeInstances(n), t++);
18229
18230
  t && this.map.triggerRepaint();
18230
18231
  }
18231
18232
  hidden() {
@@ -18243,7 +18244,7 @@ ${v_}
18243
18244
  return this.warnOnce("query", "GltfLayer: querySourceFeatures failed", t), e;
18244
18245
  }
18245
18246
  for (let n of t) {
18246
- let t = E_(n.geometry);
18247
+ let t = D_(n.geometry);
18247
18248
  t && e.push({
18248
18249
  geometry: n.geometry,
18249
18250
  bbox: t,
@@ -18268,10 +18269,10 @@ ${v_}
18268
18269
  zoom: this.map.getZoom(),
18269
18270
  globalState: fu(this.map)
18270
18271
  };
18271
- for (let e of D_(t)) {
18272
- let t = e.properties ?? {}, i = E_(e.geometry);
18272
+ for (let e of O_(t)) {
18273
+ let t = e.properties ?? {}, i = D_(e.geometry);
18273
18274
  i && this.filter(r, {
18274
- type: T_(e.geometry),
18275
+ type: E_(e.geometry),
18275
18276
  properties: t,
18276
18277
  id: e.id
18277
18278
  }) && n.push({
@@ -18291,7 +18292,7 @@ ${v_}
18291
18292
  z: r.z,
18292
18293
  s: r.meterInMercatorCoordinateUnits()
18293
18294
  };
18294
- let i = A_(this.map), a = this.config.thinningDistance(e, {}, void 0, n), o = Number.isFinite(a) && a > 0 ? V_(this.map) : void 0, s = o ? a * 7 * o.s : Infinity, c = this.config.impostorDistance(e, {}, void 0, n), l = Number.isFinite(c) ? o ?? V_(this.map) : void 0, u = this.map.getCanvas(), d = Math.hypot(u.clientWidth, u.clientHeight) / 2 * 1.1 / (512 * 2 ** e);
18295
+ let i = P_(this.map), a = this.config.thinningDistance(e, {}, void 0, n), o = Number.isFinite(a) && a > 0 ? G_(this.map) : void 0, s = o ? a * 7 * o.s : Infinity, c = this.config.impostorDistance(e, {}, void 0, n), l = Number.isFinite(c) ? o ?? G_(this.map) : void 0, u = this.map.getCanvas(), d = Math.hypot(u.clientWidth, u.clientHeight) / 2 * 1.1 / (512 * 2 ** e);
18295
18296
  if (o) {
18296
18297
  let e = new t(o.x - s, o.y - s).toLngLat(), n = new t(o.x + s, o.y + s).toLngLat();
18297
18298
  i = {
@@ -18306,23 +18307,26 @@ ${v_}
18306
18307
  minY: Pg(i.south),
18307
18308
  maxX: Ng(i.east),
18308
18309
  maxY: Pg(i.north)
18309
- }, p = this.features.filter((e) => U_(i, e.bbox)), m = this.config.maxInstances, h = m * s_, { cells: g, keep: _ } = this.planCells(p, e, n, i, h), v = I_(this.map, e_), y = L_(this.map, e_, o, s), b = o ? Math.min(1, this.lastThinScale * o_) : 1, x = o ? (e, t, n) => M_(Math.hypot(Lg(e) - o.x, Rg(t) - o.y) / o.s, a, n) < b : void 0, S = /* @__PURE__ */ new Set(), C = Math.round(this.config.maxInstances * r_), w = 0, T = [], E = new globalThis.Map(), D = (e, t) => {
18310
- let n = t.x === void 0 ? P_(t.lng) : Lg(t.x), r = t.y === void 0 ? F_(t.lat) : Rg(t.y);
18311
- if (v && !v(n, r)) return !0;
18312
- let i = o ? M_(Math.hypot(n - o.x, r - o.y) / o.s, a, t.id) : 0;
18313
- return i >= b || (T.push({
18314
- f: e,
18315
- point: t,
18316
- x: n,
18317
- y: r,
18318
- need: i
18319
- }), T.length < h);
18320
- }, O = (t, r, i, a) => {
18310
+ }, p = this.maxReach(e, n), m = this.features.filter((e) => q_(j_(i, p), e.bbox)), h = this.config.maxInstances, g = h * c_, { cells: _, keep: v } = this.planCells(m, e, n, i, g), y = B_(this.map, t_), b = this.viewMatrix ? N_(this.viewMatrix, t_) : void 0, x = this.map.terrain ? this.map.getCenterElevation() : 0, S = V_(this.map, t_, o, s), C = o ? Math.min(1, this.lastThinScale * s_) : 1, w = o ? (e, t, n) => I_(Math.hypot(Lg(e) - o.x, Rg(t) - o.y) / o.s, a, n) < C : void 0, T = /* @__PURE__ */ new Set(), E = Math.round(this.config.maxInstances * i_), D = 0, O = [], k = new globalThis.Map(), A = (t, r) => {
18311
+ let i = r.x === void 0 ? R_(r.lng) : Lg(r.x), s = r.y === void 0 ? z_(r.lat) : Rg(r.y), c = b ? this.reachOf(t, r.id, e, n) : void 0;
18312
+ if (c && b) {
18313
+ let e = this.origin.s;
18314
+ if (!b(i, s, c.radius * e, (x + c.bottom) * e, (x + c.top) * e)) return !0;
18315
+ } else if (y && !y(i, s)) return !0;
18316
+ let l = c && o ? Math.max(0, Math.hypot(i - o.x, s - o.y) - c.radius * o.s) : 0, u = o ? I_((c ? l : Math.hypot(i - o.x, s - o.y)) / o.s, a, r.id) : 0;
18317
+ return u >= C || (O.push({
18318
+ f: t,
18319
+ point: r,
18320
+ x: i,
18321
+ y: s,
18322
+ need: u
18323
+ }), O.length < g);
18324
+ }, ee = (t, r, i, a) => {
18321
18325
  let o = r.id, s = this.config.modelId(e, t.props, o, n), u = this.models.get(s);
18322
18326
  if (!u) return this.warnOnce(`model:${s}`, `GltfLayer: no model '${s}' in \`models\` — feature skipped`), !0;
18323
18327
  if (u.state !== "ready") return !0;
18324
- let f = l !== void 0 && Math.hypot(i - l.x, a - l.y) / l.s >= c && Math.hypot(i - this.origin.x, a - this.origin.y) > d && this.models.get(c_(s))?.state === "ready" ? c_(s) : s, p = E.get(f);
18325
- return p || E.set(f, p = {
18328
+ let f = l !== void 0 && Math.hypot(i - l.x, a - l.y) / l.s >= c && Math.hypot(i - this.origin.x, a - this.origin.y) > d && this.models.get(l_(s))?.state === "ready" ? l_(s) : s, p = k.get(f);
18329
+ return p || k.set(f, p = {
18326
18330
  recs: [],
18327
18331
  colors: this.config.color ? [] : void 0,
18328
18332
  alphas: this.instanceOpacity ? [] : void 0
@@ -18336,16 +18340,16 @@ ${v_}
18336
18340
  tr: [...this.config.translation(e, t.props, o, n)],
18337
18341
  props: t.props,
18338
18342
  id: o
18339
- }), p.colors?.push(this.config.color(e, t.props, o, n)), p.alphas?.push(this.config.opacity(e, t.props, o, n)), ++w < C;
18340
- }, k = () => {
18341
- S.clear(), T.length = 0;
18342
- outer: for (let e = 0; e < p.length; e++) {
18343
- let t = p[e], n = g[e];
18343
+ }), p.colors?.push(this.config.color(e, t.props, o, n)), p.alphas?.push(this.config.opacity(e, t.props, o, n)), ++D < E;
18344
+ }, te = () => {
18345
+ T.clear(), O.length = 0;
18346
+ outer: for (let e = 0; e < m.length; e++) {
18347
+ let t = m[e], n = _[e];
18344
18348
  switch (this.placementFor(t)) {
18345
18349
  case "point":
18346
- for (let [e, n] of S_(t.geometry)) {
18350
+ for (let [e, n] of C_(t.geometry)) {
18347
18351
  let r = Kg(Ng(e), Pg(n));
18348
- if (!S.has(r) && (S.add(r), !D(t, {
18352
+ if (!T.has(r) && (T.add(r), !A(t, {
18349
18353
  lng: e,
18350
18354
  lat: n,
18351
18355
  id: t.id
@@ -18353,27 +18357,45 @@ ${v_}
18353
18357
  }
18354
18358
  break;
18355
18359
  case "line":
18356
- if (!Jg(C_(t.geometry), n, f, S, (e) => D(t, e))) break outer;
18360
+ if (!Jg(w_(t.geometry), n, f, T, (e) => A(t, e))) break outer;
18357
18361
  break;
18358
- case "fill": if (!Yg(w_(t.geometry), n, f, S, (e) => D(t, e), _, y, x)) break outer;
18362
+ case "fill": if (!Yg(T_(t.geometry), n, f, T, (e) => A(t, e), v, S, w)) break outer;
18359
18363
  }
18360
18364
  }
18361
18365
  };
18362
- if (k(), b < 1 && T.length <= m && (b = 1, k()), T.length) {
18363
- let e = o ? N_(T, m) : 1;
18366
+ if (te(), C < 1 && O.length <= h && (C = 1, te()), O.length) {
18367
+ let e = o ? L_(O, h) : 1;
18364
18368
  o && (this.lastThinScale = e);
18365
- let t = o ? 1 : Math.min(1, m / T.length);
18366
- t < 1 && this.warnOnce("budget", `GltfLayer: ${T.length} instances in view exceed maxInstances (${m}) — keeping ${(t * 100).toFixed(0)}% of them; raise maxInstances, use a zoom-driven model-spacing or set model-thinning-distance`);
18367
- for (let n of T) if (!(o ? n.need >= e : j_(n.point.id) >= t) && !O(n.f, n.point, n.x, n.y)) break;
18369
+ let t = o ? 1 : Math.min(1, h / O.length);
18370
+ t < 1 && this.warnOnce("budget", `GltfLayer: ${O.length} instances in view exceed maxInstances (${h}) — keeping ${(t * 100).toFixed(0)}% of them; raise maxInstances, use a zoom-driven model-spacing or set model-thinning-distance`);
18371
+ for (let n of O) if (!(o ? n.need >= e : F_(n.point.id) >= t) && !ee(n.f, n.point, n.x, n.y)) break;
18368
18372
  }
18369
- for (let [e, t] of this.batches) E.has(e) || this.disposeBatch(e, t);
18370
- this.instanceFading = [...E.values()].some((e) => e.alphas?.some((e) => e < 1)), this.setFading(this.instanceFading || this.uniformFading);
18371
- for (let [e, t] of E) {
18373
+ for (let [e, t] of this.batches) k.has(e) || this.disposeBatch(e, t);
18374
+ this.instanceFading = [...k.values()].some((e) => e.alphas?.some((e) => e < 1)), this.setFading(this.instanceFading || this.uniformFading);
18375
+ for (let [e, t] of k) {
18372
18376
  let n = this.batchFor(e, t.recs.length);
18373
- n.recs = t.recs, n.bounds = H_(t.recs), this.writeInstances(n, t.colors, t.alphas);
18377
+ n.recs = t.recs, n.bounds = K_(t.recs), this.writeInstances(n, t.colors, t.alphas);
18374
18378
  }
18375
18379
  this.map.triggerRepaint();
18376
18380
  }
18381
+ reachOf(e, t, n, r) {
18382
+ let i = this.models.get(this.config.modelId(n, e.props, t, r))?.extent;
18383
+ if (!i || i.radius < $g && i.top - i.bottom < $g) return;
18384
+ let a = this.config.scale(n, e.props, t, r), o = this.config.translation(n, e.props, t, r), s = this.config.rotation(n, e.props, t, r), c = Math.max(Math.abs(a[0]), Math.abs(a[2])), l = i.bottom * a[1], u = i.top * a[1], d = i.radius * c + Math.hypot(o[0], o[1]), f = Math.min(l, u) + o[2], p = Math.max(l, u) + o[2];
18385
+ return (s[0] || s[1]) && (d = Math.max(d, Math.abs(f), Math.abs(p)), f = Math.min(f, -d), p = Math.max(p, d)), {
18386
+ radius: d,
18387
+ bottom: f,
18388
+ top: p
18389
+ };
18390
+ }
18391
+ maxReach(e, t) {
18392
+ let n = this.config.scale(e, {}, void 0, t), r = this.config.translation(e, {}, void 0, t), i = Math.max(Math.abs(n[0]), Math.abs(n[1]), Math.abs(n[2])), a = 0;
18393
+ for (let e of this.models.values()) {
18394
+ let t = e.extent;
18395
+ t && (a = Math.max(a, Math.hypot(t.radius, Math.max(Math.abs(t.top), Math.abs(t.bottom))) * i));
18396
+ }
18397
+ return a + Math.hypot(r[0], r[1], r[2]);
18398
+ }
18377
18399
  placementFor(e) {
18378
18400
  let t = e.geometry.type, n = this.config.placement === "auto" ? t === "Point" || t === "MultiPoint" ? "point" : t === "LineString" || t === "MultiLineString" ? "line" : t === "Polygon" || t === "MultiPolygon" ? "fill" : void 0 : this.config.placement;
18379
18401
  if (n) {
@@ -18393,13 +18415,13 @@ ${v_}
18393
18415
  continue;
18394
18416
  }
18395
18417
  if (c === "point") {
18396
- a[i] = 0, o += S_(s.geometry).length;
18418
+ a[i] = 0, o += C_(s.geometry).length;
18397
18419
  continue;
18398
18420
  }
18399
- let l = Math.max(n_, this.config.spacing(t, s.props, s.id, n));
18421
+ let l = Math.max(r_, this.config.spacing(t, s.props, s.id, n));
18400
18422
  a[i] = l;
18401
18423
  let u = l * Vg((s.bbox.south + s.bbox.north) / 2);
18402
- o += c === "fill" ? Xg(w_(s.geometry)) / (u * u) * B_(s.bbox, r) : Zg(C_(s.geometry)) / u;
18424
+ o += c === "fill" ? Xg(T_(s.geometry)) / (u * u) * W_(s.bbox, r) : Zg(w_(s.geometry)) / u;
18403
18425
  }
18404
18426
  if (o <= i) return {
18405
18427
  cells: a,
@@ -18413,9 +18435,9 @@ ${v_}
18413
18435
  }
18414
18436
  batchFor(e, t) {
18415
18437
  let n = this.batches.get(e);
18416
- if (n && t <= n.capacity && (n.capacity <= t_ || t * 4 >= n.capacity)) return n;
18438
+ if (n && t <= n.capacity && (n.capacity <= n_ || t * 4 >= n.capacity)) return n;
18417
18439
  n && this.disposeBatch(e, n);
18418
- let r = this.models.get(e), i = Math.max(t_, O_(t)), a = [], o;
18440
+ let r = this.models.get(e), i = Math.max(n_, k_(t)), a = [], o;
18419
18441
  this.instanceOpacity && (o = new bi(new Float32Array(i), 1));
18420
18442
  for (let e of r.protos) {
18421
18443
  let t = new Oi(e.geometry, e.material, i);
@@ -18482,7 +18504,7 @@ ${v_}
18482
18504
  protos: []
18483
18505
  };
18484
18506
  this.models.set(e, n), this.loader.load(t, (e) => {
18485
- this.disposed || (n.protos = this.flatten(e.scene), n.state = "ready", this.schedule(!1, !0));
18507
+ this.disposed || (n.protos = this.flatten(e.scene), n.extent = M_(n.protos), n.state = "ready", this.schedule(!1, !0));
18486
18508
  }, void 0, (r) => {
18487
18509
  n.state = "error", console.error(`GltfLayer: failed to load model '${e}' (${t})`, r);
18488
18510
  });
@@ -18502,21 +18524,27 @@ ${v_}
18502
18524
  }
18503
18525
  let i = Array.isArray(r.material) ? r.material : [r.material];
18504
18526
  for (let e of i) this.patchMaterial(e);
18505
- R_(r.geometry, n), t.push({
18527
+ H_(r.geometry, n), t.push({
18506
18528
  geometry: r.geometry,
18507
18529
  material: r.material,
18508
- matrix: l_.clone().multiply(r.matrixWorld).multiply(l_)
18530
+ matrix: u_.clone().multiply(r.matrixWorld).multiply(u_)
18509
18531
  });
18510
18532
  }), this.config.doubleSided === void 0) {
18511
18533
  let e = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set();
18512
18534
  for (let r of t) {
18513
- let t = z_(r.geometry) <= i_;
18535
+ let t = U_(r.geometry) <= a_;
18514
18536
  for (let i of Array.isArray(r.material) ? r.material : [r.material]) n.add(i), t || e.add(i);
18515
18537
  }
18516
18538
  for (let t of n) t.side === 2 && !e.has(t) && (t.side = 0);
18517
18539
  }
18518
18540
  return t;
18519
18541
  }
18542
+ setViewMatrix(e) {
18543
+ let t = !this.viewMatrix;
18544
+ t && (this.viewMatrix = /* @__PURE__ */ new Float64Array(16));
18545
+ for (let t = 0; t < 16; t++) this.viewMatrix[t] = e[t];
18546
+ t && this.schedule(!1, !0);
18547
+ }
18520
18548
  setViewBearing(e) {
18521
18549
  let t = e * Math.PI / 180;
18522
18550
  this.impostorRight.value.set(Math.cos(t), 0, -Math.sin(t));
@@ -18524,11 +18552,11 @@ ${v_}
18524
18552
  needsImpostors() {
18525
18553
  let e = this.config.impostorDistance(this.map.getZoom(), {}, void 0, fu(this.map));
18526
18554
  if (!Number.isFinite(e)) return !1;
18527
- for (let [e, t] of this.models) if (t.state === "ready" && !e.startsWith("\0") && !this.models.has(c_(e))) return !0;
18555
+ for (let [e, t] of this.models) if (t.state === "ready" && !e.startsWith("\0") && !this.models.has(l_(e))) return !0;
18528
18556
  return !1;
18529
18557
  }
18530
18558
  bakeImpostors(e, t) {
18531
- for (let [n, r] of [...this.models]) r.state !== "ready" || n.startsWith("\0") || this.models.has(c_(n)) || this.models.set(c_(n), this.bakeImpostor(e, r, t));
18559
+ for (let [n, r] of [...this.models]) r.state !== "ready" || n.startsWith("\0") || this.models.has(l_(n)) || this.models.set(l_(n), this.bakeImpostor(e, r, t));
18532
18560
  this.schedule(!1, !0);
18533
18561
  }
18534
18562
  bakeImpostor(e, t, n) {
@@ -18542,7 +18570,7 @@ ${v_}
18542
18570
  }), n = new ni(e.geometry, Array.isArray(e.material) ? t : t[0]);
18543
18571
  n.matrixAutoUpdate = !1, n.matrix.copy(e.matrix), i.add(n), e.geometry.computeBoundingBox(), a.union(e.geometry.boundingBox.clone().applyMatrix4(e.matrix));
18544
18572
  }
18545
- let s = a.getCenter(new H()), c = Math.max(a.max.x - a.min.x, a.max.z - a.min.z) / 2 || .5, l = f_ * Math.PI / 180, u = c * 2 + (a.max.y - a.min.y) + 10, f = new bo(-1, 1, 1, -1, .1, u * 2);
18573
+ let s = a.getCenter(new H()), c = Math.max(a.max.x - a.min.x, a.max.z - a.min.z) / 2 || .5, l = p_ * Math.PI / 180, u = c * 2 + (a.max.y - a.min.y) + 10, f = new bo(-1, 1, 1, -1, .1, u * 2);
18546
18574
  f.position.set(s.x, s.y + Math.sin(l) * u, Math.cos(l) * u), f.lookAt(s.x, s.y, 0), f.updateMatrixWorld();
18547
18575
  let p = new Zn(), m = new H();
18548
18576
  for (let e of [s.x - c, s.x + c]) for (let t of [a.min.y, a.max.y]) for (let n of [-c, c]) p.expandByPoint(m.set(e, t, n).applyMatrix4(f.matrixWorldInverse));
@@ -18551,7 +18579,7 @@ ${v_}
18551
18579
  r.add(new no(n.color, 10132122, n.ambient));
18552
18580
  let v = new So(n.color, n.directional);
18553
18581
  v.position.copy(n.direction).normalize().multiplyScalar(1e3), r.add(v, v.target), r.environment = n.environment, r.environmentIntensity = n.environmentIntensity;
18554
- let y = new Zt(u_, Math.max(1, Math.round(u_ * g / h)), {
18582
+ let y = new Zt(d_, Math.max(1, Math.round(d_ * g / h)), {
18555
18583
  samples: 4,
18556
18584
  colorSpace: Ue
18557
18585
  });
@@ -18566,7 +18594,7 @@ ${v_}
18566
18594
  alphaTest: .5
18567
18595
  });
18568
18596
  return C.alphaToCoverage = !0, C.onBeforeCompile = (e) => {
18569
- e.uniforms.mtkRight = this.impostorRight, e.vertexShader = e.vertexShader.replace("#include <common>", p_).replace("#include <project_vertex>", m_), e.fragmentShader = e.fragmentShader.replace("#include <map_fragment>", d_);
18597
+ e.uniforms.mtkRight = this.impostorRight, e.vertexShader = e.vertexShader.replace("#include <common>", m_).replace("#include <project_vertex>", h_), e.fragmentShader = e.fragmentShader.replace("#include <map_fragment>", f_);
18570
18598
  }, this.patchMaterial(C), C.defines = {
18571
18599
  ...C.defines,
18572
18600
  MTK_ALPHA_AFTER_TEST: ""
@@ -18599,7 +18627,7 @@ ${v_}
18599
18627
  }, e.depthWrite = !0);
18600
18628
  let t = e.onBeforeCompile;
18601
18629
  e.onBeforeCompile = (n, r) => {
18602
- t?.call(e, n, r), this.uniformOpacity && (n.uniforms.mtkOpacity = this.opacityUniform), n.vertexShader = n.vertexShader.replace("#include <color_pars_vertex>", h_).replace("#include <color_vertex>", g_), n.fragmentShader = n.fragmentShader.replace("#include <color_pars_fragment>", __).replace("#include <color_fragment>", y_).replace("#include <alphatest_fragment>", b_);
18630
+ t?.call(e, n, r), this.uniformOpacity && (n.uniforms.mtkOpacity = this.opacityUniform), n.vertexShader = n.vertexShader.replace("#include <color_pars_vertex>", g_).replace("#include <color_vertex>", __), n.fragmentShader = n.fragmentShader.replace("#include <color_pars_fragment>", v_).replace("#include <color_fragment>", b_).replace("#include <alphatest_fragment>", x_);
18603
18631
  }, e.customProgramCacheKey = () => `mtk-gltf-${this.opacityKey}`, e.needsUpdate = !0;
18604
18632
  }
18605
18633
  get opacityKey() {
@@ -18623,19 +18651,19 @@ ${v_}
18623
18651
  this.models.clear(), this.scene.remove(this.group);
18624
18652
  }
18625
18653
  };
18626
- function S_(e) {
18654
+ function C_(e) {
18627
18655
  return e.type === "Point" ? [e.coordinates] : e.coordinates;
18628
18656
  }
18629
- function C_(e) {
18657
+ function w_(e) {
18630
18658
  return e.type === "LineString" ? [e.coordinates] : e.coordinates;
18631
18659
  }
18632
- function w_(e) {
18660
+ function T_(e) {
18633
18661
  return e.type === "Polygon" ? [e.coordinates] : e.coordinates;
18634
18662
  }
18635
- function T_(e) {
18663
+ function E_(e) {
18636
18664
  return e ? e.type === "LineString" || e.type === "MultiLineString" ? 2 : e.type === "Polygon" || e.type === "MultiPolygon" ? 3 : 1 : 1;
18637
18665
  }
18638
- function E_(e) {
18666
+ function D_(e) {
18639
18667
  if (!e) return;
18640
18668
  let t = {
18641
18669
  west: Infinity,
@@ -18666,16 +18694,16 @@ function E_(e) {
18666
18694
  }
18667
18695
  return n ? t : void 0;
18668
18696
  }
18669
- function D_(e) {
18697
+ function O_(e) {
18670
18698
  let t = e;
18671
18699
  return t?.type === "FeatureCollection" ? t.features ?? [] : t?.type === "Feature" ? [t] : [];
18672
18700
  }
18673
- function O_(e) {
18701
+ function k_(e) {
18674
18702
  let t = 1;
18675
18703
  for (; t < e;) t *= 2;
18676
18704
  return t;
18677
18705
  }
18678
- function k_(e) {
18706
+ function A_(e) {
18679
18707
  let n = t.fromLngLat(e, 0);
18680
18708
  return {
18681
18709
  x: n.x,
@@ -18684,8 +18712,47 @@ function k_(e) {
18684
18712
  s: n.meterInMercatorCoordinateUnits()
18685
18713
  };
18686
18714
  }
18687
- function A_(e) {
18688
- let t = e.getBounds(), n = (t.getEast() - t.getWest()) * $g, r = (t.getNorth() - t.getSouth()) * $g;
18715
+ function j_(e, t) {
18716
+ if (!(t > 0)) return e;
18717
+ let n = t / 111320, r = n / Math.max(.01, Math.cos((e.north + e.south) / 2 * Math.PI / 180));
18718
+ return {
18719
+ west: e.west - r,
18720
+ east: e.east + r,
18721
+ south: e.south - n,
18722
+ north: e.north + n
18723
+ };
18724
+ }
18725
+ function M_(e) {
18726
+ let t = new Zn();
18727
+ for (let n of e) n.geometry.boundingBox || n.geometry.computeBoundingBox(), t.union(n.geometry.boundingBox.clone().applyMatrix4(n.matrix));
18728
+ if (t.isEmpty()) return;
18729
+ let n = 0;
18730
+ for (let e of [t.min.x, t.max.x]) for (let r of [t.min.z, t.max.z]) n = Math.max(n, Math.hypot(e, r));
18731
+ return {
18732
+ radius: n,
18733
+ bottom: t.min.y,
18734
+ top: t.max.y
18735
+ };
18736
+ }
18737
+ function N_(e, t) {
18738
+ let n = -1 - 2 * t, r = 1 + 2 * t;
18739
+ return (t, i, a, o, s) => {
18740
+ let c = Infinity, l = -Infinity, u = Infinity, d = -Infinity, f = !1, p = !1;
18741
+ for (let n = 0; n < 8; n++) {
18742
+ let r = n & 1 ? t + a : t - a, m = n & 2 ? i + a : i - a, h = n & 4 ? s : o, g = e[3] * r + e[7] * m + e[11] * h + e[15];
18743
+ if (g <= 0) {
18744
+ f = !0;
18745
+ continue;
18746
+ }
18747
+ p = !0;
18748
+ let _ = (e[0] * r + e[4] * m + e[8] * h + e[12]) / g, v = (e[1] * r + e[5] * m + e[9] * h + e[13]) / g;
18749
+ _ < c && (c = _), _ > l && (l = _), v < u && (u = v), v > d && (d = v);
18750
+ }
18751
+ return p ? f ? !0 : l >= n && c <= r && d >= n && u <= 1 : !1;
18752
+ };
18753
+ }
18754
+ function P_(e) {
18755
+ let t = e.getBounds(), n = (t.getEast() - t.getWest()) * e_, r = (t.getNorth() - t.getSouth()) * e_;
18689
18756
  return {
18690
18757
  west: t.getWest() - n,
18691
18758
  east: t.getEast() + n,
@@ -18693,13 +18760,13 @@ function A_(e) {
18693
18760
  north: t.getNorth() + r
18694
18761
  };
18695
18762
  }
18696
- function j_(e) {
18763
+ function F_(e) {
18697
18764
  return Gg(e | 0, 20973) / 4294967296;
18698
18765
  }
18699
- function M_(e, t, n) {
18700
- return e / (t * (1 - Math.log2(j_(n))));
18766
+ function I_(e, t, n) {
18767
+ return e / (t * (1 - Math.log2(F_(n))));
18701
18768
  }
18702
- function N_(e, t) {
18769
+ function L_(e, t) {
18703
18770
  let n = 0;
18704
18771
  for (let t of e) t.need < 1 && n++;
18705
18772
  if (n <= t) return 1;
@@ -18707,13 +18774,13 @@ function N_(e, t) {
18707
18774
  for (let t = 0; t < e.length; t++) r[t] = e[t].need;
18708
18775
  return r.sort(), r[t];
18709
18776
  }
18710
- function P_(e) {
18777
+ function R_(e) {
18711
18778
  return (180 + e) / 360;
18712
18779
  }
18713
- function F_(e) {
18780
+ function z_(e) {
18714
18781
  return (180 - 180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + e * Math.PI / 360))) / 360;
18715
18782
  }
18716
- function I_(e, t) {
18783
+ function B_(e, t) {
18717
18784
  let n = e, r = n.transform ?? n._camera?.transform, i = e.terrain ? r?._pixelMatrix3D : r?._pixelMatrix;
18718
18785
  if (!r || !i || !r.worldSize) return;
18719
18786
  let a = e.terrain ? r.elevation ?? 0 : 0, o = r.worldSize, s = r.width * t, c = r.height * t;
@@ -18724,7 +18791,7 @@ function I_(e, t) {
18724
18791
  return d >= -s && d <= r.width + s && f >= 0 && f <= r.height + c;
18725
18792
  };
18726
18793
  }
18727
- function L_(e, t, n, r) {
18794
+ function V_(e, t, n, r) {
18728
18795
  let i = e, a = i.transform ?? i._camera?.transform, o = e.terrain ? a?._pixelMatrix3D : a?._pixelMatrix;
18729
18796
  if (!a || !o || !a.worldSize) return;
18730
18797
  let s = new G().fromArray(Array.from(o)).invert(), c = e.terrain ? a.elevation ?? 0 : 0, l = a.worldSize, u = new Yt(), d = new Yt(), f = (e, t) => {
@@ -18757,7 +18824,7 @@ function L_(e, t, n, r) {
18757
18824
  return n <= r ? [n, r] : null;
18758
18825
  };
18759
18826
  }
18760
- function R_(e, t) {
18827
+ function H_(e, t) {
18761
18828
  let n = (e, t) => !e.has(t) && !!e.add(t);
18762
18829
  for (let r of [
18763
18830
  "position",
@@ -18779,7 +18846,7 @@ function R_(e, t) {
18779
18846
  }
18780
18847
  e.boundingBox = null, e.boundingSphere = null;
18781
18848
  }
18782
- function z_(e) {
18849
+ function U_(e) {
18783
18850
  let t = e.getAttribute("position");
18784
18851
  if (!t) return 1;
18785
18852
  let n = e.getIndex(), r = n ? n.count : t.count;
@@ -18806,13 +18873,13 @@ function z_(e) {
18806
18873
  for (let e of s.values()) e !== 0 && l++;
18807
18874
  return l / s.size;
18808
18875
  }
18809
- function B_(e, t) {
18876
+ function W_(e, t) {
18810
18877
  let n = Math.min(e.east, t.east) - Math.max(e.west, t.west), r = Math.min(e.north, t.north) - Math.max(e.south, t.south);
18811
18878
  if (n <= 0 || r <= 0) return 0;
18812
18879
  let i = (e.east - e.west) * (e.north - e.south);
18813
18880
  return i > 0 ? Math.min(1, n * r / i) : 1;
18814
18881
  }
18815
- function V_(e) {
18882
+ function G_(e) {
18816
18883
  let n = e, r = (n.transform ?? n._camera?.transform)?.getCameraLngLat?.() ?? e.getCenter(), i = t.fromLngLat(r, 0);
18817
18884
  return {
18818
18885
  x: i.x,
@@ -18820,7 +18887,7 @@ function V_(e) {
18820
18887
  s: i.meterInMercatorCoordinateUnits()
18821
18888
  };
18822
18889
  }
18823
- function H_(e) {
18890
+ function K_(e) {
18824
18891
  let t = {
18825
18892
  west: 180,
18826
18893
  east: -180,
@@ -18830,16 +18897,16 @@ function H_(e) {
18830
18897
  for (let n of e) n.lng < t.west && (t.west = n.lng), n.lng > t.east && (t.east = n.lng), n.lat < t.south && (t.south = n.lat), n.lat > t.north && (t.north = n.lat);
18831
18898
  return t;
18832
18899
  }
18833
- function U_(e, t) {
18900
+ function q_(e, t) {
18834
18901
  return e.west <= t.east && e.east >= t.west && e.south <= t.north && e.north >= t.south;
18835
18902
  }
18836
18903
  //#endregion
18837
18904
  //#region src/GltfLayer.ts
18838
- var W_ = 1, G_ = {
18905
+ var J_ = 1, Y_ = {
18839
18906
  ambient: 1.5,
18840
18907
  directional: 2.5,
18841
18908
  environment: .7
18842
- }, K_ = 25, q_ = 2e4, J_ = [
18909
+ }, X_ = 25, Z_ = 2e4, Q_ = [
18843
18910
  "interpolate",
18844
18911
  ["exponential", .5],
18845
18912
  ["zoom"],
@@ -18847,7 +18914,7 @@ var W_ = 1, G_ = {
18847
18914
  4e4,
18848
18915
  20,
18849
18916
  156.25
18850
- ], Y_ = [
18917
+ ], $_ = [
18851
18918
  "interpolate",
18852
18919
  ["exponential", .5],
18853
18920
  ["zoom"],
@@ -18855,12 +18922,12 @@ var W_ = 1, G_ = {
18855
18922
  12800,
18856
18923
  20,
18857
18924
  50
18858
- ], X_ = [
18925
+ ], ev = [
18859
18926
  "auto",
18860
18927
  "point",
18861
18928
  "line",
18862
18929
  "fill"
18863
- ], Z_ = class {
18930
+ ], tv = class {
18864
18931
  id;
18865
18932
  type = "custom";
18866
18933
  renderingMode = "3d";
@@ -18891,11 +18958,11 @@ var W_ = 1, G_ = {
18891
18958
  if (!e.source) throw Error("GltfLayer: `source` (a source id) is required");
18892
18959
  if (!e.models || Object.keys(e.models).length === 0) throw Error("GltfLayer: `models` must hold at least one { id: url } entry");
18893
18960
  this.id = e.id, this.minzoom = e.minzoom, this.maxzoom = e.maxzoom, this.options = e, this.visible = e.layout?.visibility !== "none", this.lighting = {
18894
- ...G_,
18961
+ ...Y_,
18895
18962
  ...e.lighting
18896
18963
  };
18897
18964
  let t = e.layout?.["model-placement"] ?? "auto";
18898
- if (!X_.includes(t)) throw Error(`GltfLayer: model-placement must be one of ${X_.join(", ")} — got '${t}'`);
18965
+ if (!ev.includes(t)) throw Error(`GltfLayer: model-placement must be one of ${ev.join(", ")} — got '${t}'`);
18899
18966
  this.placement = t;
18900
18967
  }
18901
18968
  onAdd(t, n) {
@@ -18907,48 +18974,48 @@ var W_ = 1, G_ = {
18907
18974
  antialias: !0
18908
18975
  }), this.renderer.autoClear = !1;
18909
18976
  let i = this.options.paint ?? {}, a = this.options.layout ?? {}, o = Object.keys(this.options.models);
18910
- this.manager = new x_(t, this.scene, e.convert(t.getCenter()), r, {
18977
+ this.manager = new S_(t, this.scene, e.convert(t.getCenter()), r, {
18911
18978
  sourceId: this.options.source,
18912
18979
  sourceLayer: this.options["source-layer"],
18913
18980
  filter: this.options.filter,
18914
18981
  minzoom: this.options.minzoom,
18915
18982
  maxzoom: this.options.maxzoom,
18916
18983
  models: this.options.models,
18917
- modelId: yh(a["model-id"], "model-id", o[0], W_),
18984
+ modelId: yh(a["model-id"], "model-id", o[0], J_),
18918
18985
  placement: this.placement,
18919
- spacing: vh(a["model-spacing"], "model-spacing", K_, W_),
18920
- thinningDistance: vh(a["model-thinning-distance"] ?? J_, "model-thinning-distance", Infinity, W_),
18921
- impostorDistance: vh(a["model-impostor-distance"] ?? Y_, "model-impostor-distance", Infinity, W_),
18922
- maxInstances: this.options.maxInstances ?? q_,
18986
+ spacing: vh(a["model-spacing"], "model-spacing", X_, J_),
18987
+ thinningDistance: vh(a["model-thinning-distance"] ?? Q_, "model-thinning-distance", Infinity, J_),
18988
+ impostorDistance: vh(a["model-impostor-distance"] ?? $_, "model-impostor-distance", Infinity, J_),
18989
+ maxInstances: this.options.maxInstances ?? Z_,
18923
18990
  doubleSided: this.options.doubleSided,
18924
18991
  rotation: bh(i["model-rotation"], "model-rotation", [
18925
18992
  0,
18926
18993
  0,
18927
18994
  0
18928
- ], W_),
18995
+ ], J_),
18929
18996
  scale: bh(i["model-scale"], "model-scale", [
18930
18997
  1,
18931
18998
  1,
18932
18999
  1
18933
- ], W_),
19000
+ ], J_),
18934
19001
  translation: bh(i["model-translation"], "model-translation", [
18935
19002
  0,
18936
19003
  0,
18937
19004
  0
18938
- ], W_),
19005
+ ], J_),
18939
19006
  color: i["model-color"] === void 0 ? void 0 : _h(i["model-color"], "model-color", [
18940
19007
  1,
18941
19008
  1,
18942
19009
  1,
18943
19010
  1
18944
- ], W_),
18945
- opacity: i["model-opacity"] === void 0 ? void 0 : vh(i["model-opacity"], "model-opacity", 1, W_)
19011
+ ], J_),
19012
+ opacity: i["model-opacity"] === void 0 ? void 0 : vh(i["model-opacity"], "model-opacity", 1, J_)
18946
19013
  });
18947
19014
  }
18948
19015
  render(e, t) {
18949
19016
  if (!this.visible || this.manager.syncOpacity() <= 0) return;
18950
19017
  let n = this.manager.origin;
18951
- this.mainMat.fromArray(t.defaultProjectionData.mainMatrix), this.originMat.makeTranslation(n.x, n.y, n.z).scale(this.originScale.set(n.s, -n.s, n.s)), this.sceneToClip.multiplyMatrices(this.mainMat, this.originMat), this.placeCamera(), this.syncLight(), this.renderer.resetState(), this.environmentDone || this.buildEnvironment(), this.manager.needsImpostors() && (this.manager.bakeImpostors(this.renderer, this.impostorLight()), this.renderer.resetState()), this.manager.setViewBearing(this.map.getBearing()), this.renderer.render(this.scene, this.camera);
19018
+ this.mainMat.fromArray(t.defaultProjectionData.mainMatrix), this.manager.setViewMatrix(t.defaultProjectionData.mainMatrix), this.originMat.makeTranslation(n.x, n.y, n.z).scale(this.originScale.set(n.s, -n.s, n.s)), this.sceneToClip.multiplyMatrices(this.mainMat, this.originMat), this.placeCamera(), this.syncLight(), this.renderer.resetState(), this.environmentDone || this.buildEnvironment(), this.manager.needsImpostors() && (this.manager.bakeImpostors(this.renderer, this.impostorLight()), this.renderer.resetState()), this.manager.setViewBearing(this.map.getBearing()), this.renderer.render(this.scene, this.camera);
18952
19019
  }
18953
19020
  placeCamera() {
18954
19021
  let e = this.sceneToClip;
@@ -18993,4 +19060,4 @@ var W_ = 1, G_ = {
18993
19060
  }
18994
19061
  };
18995
19062
  //#endregion
18996
- export { wh as Fill3DLayer, Z_ as GltfLayer };
19063
+ export { wh as Fill3DLayer, tv as GltfLayer };
@@ -266,7 +266,7 @@ var t = "maptoolkit:scene3d", n = {
266
266
  }
267
267
  }, l = () => import(
268
268
  /* @vite-ignore */
269
- new URL("./maplibre-3d-layers-0.5.4.standalone.mjs", import.meta.url).href
269
+ new URL("./maplibre-3d-layers-0.5.5.standalone.mjs", import.meta.url).href
270
270
  ), u = class extends c {
271
271
  constructor(e = {}) {
272
272
  super({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maptoolkit/maplibre-scene3d-control",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "A MapLibre GL JS control plugin that adds the 3D scene of a Maptoolkit style: 3D buildings and glTF vegetation.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -49,7 +49,7 @@
49
49
  "maplibre-gl": ">=6.0.0"
50
50
  },
51
51
  "dependencies": {
52
- "@maptoolkit/maplibre-3d-layers": "^0.5.4",
52
+ "@maptoolkit/maplibre-3d-layers": "^0.5.5",
53
53
  "three": ">=0.160.0"
54
54
  },
55
55
  "devDependencies": {