@navaramap/three-api 0.2.0 → 0.3.0

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.
@@ -33,10 +33,12 @@ export type PolylineGeometryData = {
33
33
  startLow: Float32Array;
34
34
  endHigh: Float32Array;
35
35
  endLow: Float32Array;
36
- startNormal: Float32Array;
37
- endNormalAndTextureCoordinateNormalizationX: Float32Array;
38
- rightNormalAndTextureCoordinateNormalizationY: Float32Array;
36
+ startNormalAndLengthHigh: Float32Array;
37
+ endNormalAndSegmentLength: Float32Array;
38
+ rightNormalAndLineLength: Float32Array;
39
39
  indices: Uint32Array;
40
+ /** One entry of three RGBA texels per segment, for a dash pattern. */
41
+ lineSegments: Float32Array;
40
42
  extent: GeographicExtent;
41
43
  };
42
44
  /** Flat `[lng, lat, height, ...]`, or ECEF `[x, y, z, ...]` when geocentric. */
package/dist/index.js CHANGED
@@ -1,20 +1,19 @@
1
- import e, { CameraFrustum as t, EllipsoidGeodesic as n, LLE as r, Ray as i, Transform as a, Vec2 as o, Vec3 as s, Window as c, angleToDegree as l, angleToRadian as u, buildPolygonGeometry as d, buildPolylineGeometry as f, eastNorthUpToFixedFrame as p, encodePosition as m, geodeticSurfaceNormal as h, geodeticToXyz as g, getHeightFromEllipsoid as _, getPickRay as v, getPlaneFromPointNormal as y, getRayPlaneIntersection as b, getWGS84Eccentricity as ee, getWGS84EccentricitySquared as te, getWGS84Flattening as ne, getWGS84SemiMajorAxis as re, getWGS84SemiMinorAxis as ie, northEastDownToFixedFrame as ae, northUpEastToFixedFrame as oe, northWestUpToFixedFrame as x, polygonGroundVolume as S, polylineGroundVolume as C, scaleToGeodeticSurface as w, screenToWorld as T, worldToScreen as E, xyzToGeodetic as D } from "@navaramap/engine-api";
2
- import { Euler as O, MathUtils as k, Matrix4 as A, Plane as j, Ray as M, Vector2 as N, Vector3 as P } from "three";
3
- //#region src/frames.ts
4
- function F() {
5
- return new A().makeRotationY(Math.PI / 2);
6
- }
7
- function I(e, t) {
8
- let n = new A().multiplyMatrices(e, new A().makeRotationFromEuler(new O(-k.degToRad(t.pitch ?? 0), -k.degToRad(t.heading ?? 0), k.degToRad(t.roll ?? 0), "YXZ")));
1
+ import e, { CameraFrustum as t, EllipsoidGeodesic as n, LLE as r, Ray as i, Transform as a, Vec2 as o, Vec3 as s, Window as c, angleToDegree as l, angleToRadian as u, buildPolygonGeometry as d, buildPolylineGeometry as f, eastNorthUpToFixedFrame as p, encodePosition as m, geodeticSurfaceNormal as h, geodeticToXyz as g, getHeightFromEllipsoid as _, getPickRay as v, getPlaneFromPointNormal as y, getRayPlaneIntersection as b, getWGS84Eccentricity as ee, getWGS84EccentricitySquared as te, getWGS84Flattening as ne, getWGS84SemiMajorAxis as re, getWGS84SemiMinorAxis as ie, northEastDownToFixedFrame as ae, northUpEastToFixedFrame as oe, northWestUpToFixedFrame as se, polygonGroundVolume as x, polylineGroundVolume as S, scaleToGeodeticSurface as C, screenToWorld as w, worldToScreen as T, xyzToGeodetic as E } from "@navaramap/engine-api";
2
+ import { Euler as D, MathUtils as O, Matrix4 as k, Plane as A, Ray as j, Vector2 as M, Vector3 as N } from "three";
3
+ // src/frames.ts
4
+ function P() {
5
+ return new k().makeRotationY(Math.PI / 2);
6
+ }
7
+ function F(e, t) {
8
+ let n = new k().multiplyMatrices(e, new k().makeRotationFromEuler(new D(-O.degToRad(t.pitch ?? 0), -O.degToRad(t.heading ?? 0), O.degToRad(t.roll ?? 0), "YXZ")));
9
9
  if (t.scale !== void 0) {
10
10
  let e = t.scale;
11
- n.scale(typeof e == "number" ? new P(e, e, e) : new P(e.x, e.y, e.z));
11
+ n.scale(typeof e == "number" ? new N(e, e, e) : new N(e.x, e.y, e.z));
12
12
  }
13
13
  return n;
14
14
  }
15
- //#endregion
16
- //#region src/featureGeometry.ts
17
- function L(e) {
15
+ // src/featureGeometry.ts
16
+ function I(e) {
18
17
  return {
19
18
  west: l(e.west),
20
19
  south: l(e.south),
@@ -22,20 +21,20 @@ function L(e) {
22
21
  north: l(e.north)
23
22
  };
24
23
  }
25
- function R(e) {
24
+ function L(e) {
26
25
  let t = 0;
27
26
  for (let n of e) t += n.length;
28
27
  let n = new Float64Array(t), r = 0;
29
28
  for (let t of e) n.set(t, r), r += t.length;
30
29
  return n;
31
30
  }
32
- function z(e) {
31
+ function R(e) {
33
32
  let t = new Uint32Array(e.length);
34
33
  for (let n = 0; n < e.length; n++) t[n] = e[n].length / 3;
35
34
  return t;
36
35
  }
37
- function B(e, t, n) {
38
- let r = d(R(e), z(e), t, n);
36
+ function z(e, t, n) {
37
+ let r = d(L(e), R(e), t, n);
39
38
  if (r) try {
40
39
  let e = r.position_3d_high(), t = r.position_3d_low(), n = r.extent;
41
40
  if (!e || !t || !n) throw Error("buildPolygonGeometry: incomplete RTE geometry");
@@ -47,17 +46,17 @@ function B(e, t, n) {
47
46
  normal: r.normal(),
48
47
  scaleNormalAndCap: i,
49
48
  indices: r.indices(),
50
- extent: L(n)
49
+ extent: I(n)
51
50
  };
52
51
  } finally {
53
52
  r.free();
54
53
  }
55
54
  }
56
- function V(e, t, n, r) {
55
+ function B(e, t, n, r) {
57
56
  let i = f(e, t, n, r);
58
57
  if (i) try {
59
- let e = i.position_high(), t = i.position_low(), n = i.start_high(), r = i.start_low(), a = i.end_high(), o = i.end_low(), s = i.start_normals(), c = i.end_normal_and_texture_coordinate_normalization_x(), l = i.extent;
60
- if (!e || !t || !n || !r || !a || !o || !s || !c || !l) throw Error("buildPolylineGeometry: incomplete RTE geometry");
58
+ let e = i.position_high(), t = i.position_low(), n = i.start_high(), r = i.start_low(), a = i.end_high(), o = i.end_low(), s = i.start_normal_and_length_high(), c = i.end_normal_and_segment_length(), l = i.line_segments(), u = i.extent;
59
+ if (!e || !t || !n || !r || !a || !o || !s || !c || !l || !u) throw Error("buildPolylineGeometry: incomplete RTE geometry");
61
60
  return {
62
61
  position: i.position(),
63
62
  positionHigh: e,
@@ -66,65 +65,64 @@ function V(e, t, n, r) {
66
65
  startLow: r,
67
66
  endHigh: a,
68
67
  endLow: o,
69
- startNormal: s,
70
- endNormalAndTextureCoordinateNormalizationX: c,
71
- rightNormalAndTextureCoordinateNormalizationY: i.right_normal_and_texture_coordinate_normalization_y(),
68
+ startNormalAndLengthHigh: s,
69
+ endNormalAndSegmentLength: c,
70
+ rightNormalAndLineLength: i.right_normal_and_line_length(),
72
71
  indices: i.indices(),
73
- extent: L(l)
72
+ lineSegments: l,
73
+ extent: I(u)
74
74
  };
75
75
  } finally {
76
76
  i.free();
77
77
  }
78
78
  }
79
- function H(e, t, n) {
79
+ function V(e, t, n) {
80
80
  let r = e(t.min, t.max, u(n.west), u(n.south), u(n.east), u(n.north));
81
81
  return [r[0], r[1]];
82
82
  }
83
+ function H(e, t) {
84
+ return V(x, e, t);
85
+ }
83
86
  function U(e, t) {
84
- return H(S, e, t);
87
+ return V(S, e, t);
85
88
  }
89
+ // src/intersection.ts
86
90
  function W(e, t) {
87
- return H(C, e, t);
88
- }
89
- //#endregion
90
- //#region src/intersection.ts
91
- function G(e, t) {
92
- let n = new s(e.x, e.y, e.z), r = new s(t.x, t.y, t.z), i = y(n, r), a = new P(i.normal.x, i.normal.y, i.normal.z), o = new j(a, -i.distance);
91
+ let n = new s(e.x, e.y, e.z), r = new s(t.x, t.y, t.z), i = y(n, r), a = new N(i.normal.x, i.normal.y, i.normal.z), o = new A(a, -i.distance);
93
92
  return i.free(), o;
94
93
  }
95
- function K(e, n, r) {
94
+ function G(e, n, r) {
96
95
  let i = new c(e.width, e.height, e.pixelRatio);
97
96
  i.width *= i.pixelRatio, i.height *= i.pixelRatio;
98
- let s = new a(n.position.x, n.position.y, n.position.z, n.quaternion.x, n.quaternion.y, n.quaternion.z, n.quaternion.w, n.scale.x, n.scale.y, n.scale.z), l = new t(n.near, n.far, u(n.fov), n.aspect), d = v(i, s, l, new o(r.x, r.y)), f = new P(d.origin.x, d.origin.y, d.origin.z), p = new P(d.direction.x, d.direction.y, d.direction.z), m = new M(f, p);
97
+ let s = new a(n.position.x, n.position.y, n.position.z, n.quaternion.x, n.quaternion.y, n.quaternion.z, n.quaternion.w, n.scale.x, n.scale.y, n.scale.z), l = new t(n.near, n.far, u(n.fov), n.aspect), d = v(i, s, l, new o(r.x, r.y)), f = new N(d.origin.x, d.origin.y, d.origin.z), p = new N(d.direction.x, d.direction.y, d.direction.z), m = new j(f, p);
99
98
  return d.free(), m;
100
99
  }
101
- function q(e, t) {
100
+ function K(e, t) {
102
101
  let n = new i(new s(e.origin.x, e.origin.y, e.origin.z), new s(e.direction.x, e.direction.y, e.direction.z)), r = y(new s(t.normal.x * -t.constant, t.normal.y * -t.constant, t.normal.z * -t.constant), new s(t.normal.x, t.normal.y, t.normal.z)), a = b(n, r);
103
102
  if (a) {
104
- let e = new P(a.x, a.y, a.z);
103
+ let e = new N(a.x, a.y, a.z);
105
104
  return a.free(), e;
106
105
  }
107
106
  }
108
- function se(e) {
107
+ function ce(e) {
109
108
  let t = new s(e.x, e.y, e.z);
110
109
  return _(t);
111
110
  }
112
- //#endregion
113
- //#region src/rte.ts
114
- var ce = Object.freeze({ value: 1 });
115
- function le(e, t = new P(), n = new P()) {
111
+ // src/rte.ts
112
+ var le = Object.freeze({ value: 1 });
113
+ function ue(e, t = new N(), n = new N()) {
116
114
  let r = m(e.x, e.y, e.z);
117
115
  return t.set(r.high.x, r.high.y, r.high.z), n.set(r.low.x, r.low.y, r.low.z), r.free(), {
118
116
  high: t,
119
117
  low: n
120
118
  };
121
119
  }
122
- var ue = (e, t, n = new A()) => {
120
+ var de = (e, t, n = new k()) => {
123
121
  n.multiplyMatrices(t, e);
124
122
  let r = n.elements;
125
123
  return r[12] = 0, r[13] = 0, r[14] = 0, n;
126
124
  };
127
- function de(e, t, n = new P(), r = new A()) {
125
+ function fe(e, t, n = new N(), r = new k()) {
128
126
  r.multiplyMatrices(e, t), n.setFromMatrixPosition(r);
129
127
  let i = r.elements;
130
128
  return i[12] = 0, i[13] = 0, i[14] = 0, {
@@ -132,14 +130,14 @@ function de(e, t, n = new P(), r = new A()) {
132
130
  rotationScale: r
133
131
  };
134
132
  }
135
- var J = new A(), Y = new P(), fe = (e, t) => {
136
- J.copy(t).invert(), Y.copy(e).applyMatrix4(J);
137
- let n = m(Y.x, Y.y, Y.z), r = n.high, i = n.low, a = {
138
- high: new P(r.x, r.y, r.z),
139
- low: new P(i.x, i.y, i.z)
133
+ var q = new k(), J = new N(), pe = (e, t) => {
134
+ q.copy(t).invert(), J.copy(e).applyMatrix4(q);
135
+ let n = m(J.x, J.y, J.z), r = n.high, i = n.low, a = {
136
+ high: new N(r.x, r.y, r.z),
137
+ low: new N(i.x, i.y, i.z)
140
138
  };
141
139
  return n.free(), a;
142
- }, pe = class {
140
+ }, me = class {
143
141
  _raw;
144
142
  constructor(e, t) {
145
143
  this._raw = new n(new r(u(e.lat), u(e.lng), e.height), new r(u(t.lat), u(t.lng), t.height));
@@ -192,96 +190,96 @@ var J = new A(), Y = new P(), fe = (e, t) => {
192
190
  dispose() {
193
191
  this._raw.free();
194
192
  }
195
- };
196
- //#endregion
197
- //#region src/index.ts
198
- async function me() {
199
- await e();
193
+ }, Y = Symbol.for("@navaramap/engine-api/init");
194
+ async function he() {
195
+ let t = globalThis;
196
+ t[Y] ??= e().catch((e) => {
197
+ throw t[Y] = void 0, e;
198
+ }), await t[Y];
200
199
  }
201
200
  function X(e) {
202
- let t = g(new r(u(e.lat), u(e.lng), e.height)), n = new P(t.x, t.y, t.z);
201
+ let t = g(new r(u(e.lat), u(e.lng), e.height)), n = new N(t.x, t.y, t.z);
203
202
  return t.free(), n;
204
203
  }
205
- function he(e) {
206
- let t = new s(e.x, e.y, e.z), n = D(t), r = {
204
+ function ge(e) {
205
+ let t = new s(e.x, e.y, e.z), n = E(t), r = {
207
206
  lat: l(n.lat),
208
207
  lng: l(n.lng),
209
208
  height: n.height
210
209
  };
211
210
  return n.free(), r;
212
211
  }
213
- function ge(e) {
212
+ function _e(e) {
214
213
  return u(e);
215
214
  }
216
- function _e(e) {
215
+ function ve(e) {
217
216
  return l(e);
218
217
  }
219
- function ve(e, n, r) {
218
+ function ye(e, n, r) {
220
219
  let i = new c(e.width, e.height, e.pixelRatio);
221
220
  i.width *= i.pixelRatio, i.height *= i.pixelRatio;
222
- let s = new a(n.position.x, n.position.y, n.position.z, n.quaternion.x, n.quaternion.y, n.quaternion.z, n.quaternion.w, n.scale.x, n.scale.y, n.scale.z), l = new t(n.near, n.far, u(n.fov), n.aspect), d = T(i, s, l, new o(r.x, r.y));
221
+ let s = new a(n.position.x, n.position.y, n.position.z, n.quaternion.x, n.quaternion.y, n.quaternion.z, n.quaternion.w, n.scale.x, n.scale.y, n.scale.z), l = new t(n.near, n.far, u(n.fov), n.aspect), d = w(i, s, l, new o(r.x, r.y));
223
222
  if (!d) return;
224
- let f = new P(d.x, d.y, d.z);
223
+ let f = new N(d.x, d.y, d.z);
225
224
  return d.free(), f;
226
225
  }
227
- function ye(e) {
228
- let t = h(new r(u(e.lat), u(e.lng), e.height)), n = new P(t.x, t.y, t.z);
226
+ function be(e) {
227
+ let t = h(new r(u(e.lat), u(e.lng), e.height)), n = new N(t.x, t.y, t.z);
229
228
  return t.free(), n;
230
229
  }
231
- function be(e) {
232
- let t = w(new s(e.x, e.y, e.z));
230
+ function xe(e) {
231
+ let t = C(new s(e.x, e.y, e.z));
233
232
  if (!t) return;
234
- let n = new P(t.x, t.y, t.z);
233
+ let n = new N(t.x, t.y, t.z);
235
234
  return t.free(), n;
236
235
  }
237
- function xe(e) {
236
+ function Se(e) {
238
237
  let t = new s(e.x, e.y, e.z), n = p(t);
239
- return new A().fromArray(n);
238
+ return new k().fromArray(n);
240
239
  }
241
- function Se(e) {
240
+ function Z(e) {
242
241
  let t = new s(e.x, e.y, e.z), n = ae(t);
243
- return new A().fromArray(n);
242
+ return new k().fromArray(n);
244
243
  }
245
- function Z(e) {
244
+ function Q(e) {
246
245
  let t = new s(e.x, e.y, e.z), n = oe(t);
247
- return new A().fromArray(n);
246
+ return new k().fromArray(n);
248
247
  }
249
248
  function Ce(e) {
250
- let t = new s(e.x, e.y, e.z), n = x(t);
251
- return new A().fromArray(n);
252
- }
253
- function Q(e) {
254
- return Z(e).multiply(F());
249
+ let t = new s(e.x, e.y, e.z), n = se(t);
250
+ return new k().fromArray(n);
255
251
  }
256
252
  function $(e) {
257
- return I(Q(X({
253
+ return Q(e).multiply(P());
254
+ }
255
+ function we(e) {
256
+ return F($(X({
258
257
  lng: e.lng,
259
258
  lat: e.lat,
260
259
  height: e.height ?? 0
261
260
  })), e);
262
261
  }
263
- function we(e, n, r) {
262
+ function Te(e, n, r) {
264
263
  let i = new c(e.width, e.height, e.pixelRatio);
265
264
  i.width *= i.pixelRatio, i.height *= i.pixelRatio;
266
- let o = new a(n.position.x, n.position.y, n.position.z, n.quaternion.x, n.quaternion.y, n.quaternion.z, n.quaternion.w, n.scale.x, n.scale.y, n.scale.z), l = new t(n.near, n.far, u(n.fov), n.aspect), d = E(i, o, l, new s(r.x, r.y, r.z));
265
+ let o = new a(n.position.x, n.position.y, n.position.z, n.quaternion.x, n.quaternion.y, n.quaternion.z, n.quaternion.w, n.scale.x, n.scale.y, n.scale.z), l = new t(n.near, n.far, u(n.fov), n.aspect), d = T(i, o, l, new s(r.x, r.y, r.z));
267
266
  if (!d) return;
268
- let f = new N(d.x, d.y);
267
+ let f = new M(d.x, d.y);
269
268
  return d.free(), f;
270
269
  }
271
- function Te() {
270
+ function Ee() {
272
271
  return re();
273
272
  }
274
- function Ee() {
273
+ function De() {
275
274
  return ie();
276
275
  }
277
- function De() {
276
+ function Oe() {
278
277
  return te();
279
278
  }
280
- function Oe() {
279
+ function ke() {
281
280
  return ne();
282
281
  }
283
- function ke() {
282
+ function Ae() {
284
283
  return ee();
285
284
  }
286
- //#endregion
287
- export { pe as EllipsoidGeodesic, ce as RTE_ONE_UNIFORM, B as buildPolygonGeometry, V as buildPolylineGeometry, fe as calcCameraPosition, ue as calcModelMatrixRTE, de as composeWorldMatrixForRTE, ve as convertScreenToWorld, we as convertWorldToScreen, ge as degreeToRadian, xe as eastNorthUpToFixedFrame, le as encodePositionRTE, ye as geodeticSurfaceNormal, X as geodeticToVector3, se as getHeightFromEllipsoid, K as getPickRay, G as getPlaneFromPointNormal, q as getRayPlaneIntersection, ke as getWGS84Eccentricity, De as getWGS84EccentricitySquared, Oe as getWGS84Flattening, Te as getWGS84SemiMajorAxis, Ee as getWGS84SemiMinorAxis, $ as headingPitchRollToFixedFrame, me as initNavaraApi, Se as northEastDownToFixedFrame, Z as northUpEastToFixedFrame, Ce as northWestUpToFixedFrame, U as polygonGroundVolume, W as polylineGroundVolume, _e as radianToDegree, be as scaleToGeodeticSurface, he as vector3ToGeodetic, Q as westUpNorthToFixedFrame };
285
+ export { me as EllipsoidGeodesic, le as RTE_ONE_UNIFORM, z as buildPolygonGeometry, B as buildPolylineGeometry, pe as calcCameraPosition, de as calcModelMatrixRTE, fe as composeWorldMatrixForRTE, ye as convertScreenToWorld, Te as convertWorldToScreen, _e as degreeToRadian, Se as eastNorthUpToFixedFrame, ue as encodePositionRTE, be as geodeticSurfaceNormal, X as geodeticToVector3, ce as getHeightFromEllipsoid, G as getPickRay, W as getPlaneFromPointNormal, K as getRayPlaneIntersection, Ae as getWGS84Eccentricity, Oe as getWGS84EccentricitySquared, ke as getWGS84Flattening, Ee as getWGS84SemiMajorAxis, De as getWGS84SemiMinorAxis, we as headingPitchRollToFixedFrame, he as initNavaraApi, Z as northEastDownToFixedFrame, Q as northUpEastToFixedFrame, Ce as northWestUpToFixedFrame, H as polygonGroundVolume, U as polylineGroundVolume, ve as radianToDegree, xe as scaleToGeodeticSurface, ge as vector3ToGeodetic, $ as westUpNorthToFixedFrame };
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@navaramap/engine-api"),require("three")):typeof define==`function`&&define.amd?define([`exports`,`@navaramap/engine-api`,`three`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.NavaraThreeApi={},e._navaramap_engine_api,e.three))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=Object.create,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.getPrototypeOf,c=Object.prototype.hasOwnProperty,l=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var s=o(t),l=0,u=s.length,d;l<u;l++)d=s[l],!c.call(e,d)&&d!==n&&i(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=a(t,d))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:r(s(e)),l(t||!e||!e.__esModule||!c.call(e,`default`)?i(n,`default`,{value:e,enumerable:!0}):n,e)))(t,1);function u(){return new n.Matrix4().makeRotationY(Math.PI/2)}function d(e,t){let r=new n.Matrix4().multiplyMatrices(e,new n.Matrix4().makeRotationFromEuler(new n.Euler(-n.MathUtils.degToRad(t.pitch??0),-n.MathUtils.degToRad(t.heading??0),n.MathUtils.degToRad(t.roll??0),`YXZ`)));if(t.scale!==void 0){let e=t.scale;r.scale(typeof e==`number`?new n.Vector3(e,e,e):new n.Vector3(e.x,e.y,e.z))}return r}function f(e){return{west:(0,t.angleToDegree)(e.west),south:(0,t.angleToDegree)(e.south),east:(0,t.angleToDegree)(e.east),north:(0,t.angleToDegree)(e.north)}}function p(e){let t=0;for(let n of e)t+=n.length;let n=new Float64Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}function m(e){let t=new Uint32Array(e.length);for(let n=0;n<e.length;n++)t[n]=e[n].length/3;return t}function h(e,n,r){let i=(0,t.buildPolygonGeometry)(p(e),m(e),n,r);if(i)try{let e=i.position_3d_high(),t=i.position_3d_low(),n=i.extent;if(!e||!t||!n)throw Error(`buildPolygonGeometry: incomplete RTE geometry`);let r=i.scale_normal_and_cap();if(!r)throw Error(`buildPolygonGeometry: missing extrusion attribute`);return{positionHigh:e,positionLow:t,normal:i.normal(),scaleNormalAndCap:r,indices:i.indices(),extent:f(n)}}finally{i.free()}}function g(e,n,r,i){let a=(0,t.buildPolylineGeometry)(e,n,r,i);if(a)try{let e=a.position_high(),t=a.position_low(),n=a.start_high(),r=a.start_low(),i=a.end_high(),o=a.end_low(),s=a.start_normals(),c=a.end_normal_and_texture_coordinate_normalization_x(),l=a.extent;if(!e||!t||!n||!r||!i||!o||!s||!c||!l)throw Error(`buildPolylineGeometry: incomplete RTE geometry`);return{position:a.position(),positionHigh:e,positionLow:t,startHigh:n,startLow:r,endHigh:i,endLow:o,startNormal:s,endNormalAndTextureCoordinateNormalizationX:c,rightNormalAndTextureCoordinateNormalizationY:a.right_normal_and_texture_coordinate_normalization_y(),indices:a.indices(),extent:f(l)}}finally{a.free()}}function _(e,n,r){let i=e(n.min,n.max,(0,t.angleToRadian)(r.west),(0,t.angleToRadian)(r.south),(0,t.angleToRadian)(r.east),(0,t.angleToRadian)(r.north));return[i[0],i[1]]}function v(e,n){return _(t.polygonGroundVolume,e,n)}function y(e,n){return _(t.polylineGroundVolume,e,n)}function b(e,r){let i=new t.Vec3(e.x,e.y,e.z),a=new t.Vec3(r.x,r.y,r.z),o=(0,t.getPlaneFromPointNormal)(i,a),s=new n.Vector3(o.normal.x,o.normal.y,o.normal.z),c=new n.Plane(s,-o.distance);return o.free(),c}function x(e,r,i){let a=new t.Window(e.width,e.height,e.pixelRatio);a.width*=a.pixelRatio,a.height*=a.pixelRatio;let o=new t.Transform(r.position.x,r.position.y,r.position.z,r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w,r.scale.x,r.scale.y,r.scale.z),s=new t.CameraFrustum(r.near,r.far,(0,t.angleToRadian)(r.fov),r.aspect),c=(0,t.getPickRay)(a,o,s,new t.Vec2(i.x,i.y)),l=new n.Vector3(c.origin.x,c.origin.y,c.origin.z),u=new n.Vector3(c.direction.x,c.direction.y,c.direction.z),d=new n.Ray(l,u);return c.free(),d}function S(e,r){let i=new t.Ray(new t.Vec3(e.origin.x,e.origin.y,e.origin.z),new t.Vec3(e.direction.x,e.direction.y,e.direction.z)),a=(0,t.getPlaneFromPointNormal)(new t.Vec3(r.normal.x*-r.constant,r.normal.y*-r.constant,r.normal.z*-r.constant),new t.Vec3(r.normal.x,r.normal.y,r.normal.z)),o=(0,t.getRayPlaneIntersection)(i,a);if(o){let e=new n.Vector3(o.x,o.y,o.z);return o.free(),e}}function C(e){let n=new t.Vec3(e.x,e.y,e.z);return(0,t.getHeightFromEllipsoid)(n)}var w=Object.freeze({value:1});function T(e,r=new n.Vector3,i=new n.Vector3){let a=(0,t.encodePosition)(e.x,e.y,e.z);return r.set(a.high.x,a.high.y,a.high.z),i.set(a.low.x,a.low.y,a.low.z),a.free(),{high:r,low:i}}var E=(e,t,r=new n.Matrix4)=>{r.multiplyMatrices(t,e);let i=r.elements;return i[12]=0,i[13]=0,i[14]=0,r};function D(e,t,r=new n.Vector3,i=new n.Matrix4){i.multiplyMatrices(e,t),r.setFromMatrixPosition(i);let a=i.elements;return a[12]=0,a[13]=0,a[14]=0,{position:r,rotationScale:i}}var O=new n.Matrix4,k=new n.Vector3,A=(e,r)=>{O.copy(r).invert(),k.copy(e).applyMatrix4(O);let i=(0,t.encodePosition)(k.x,k.y,k.z),a=i.high,o=i.low,s={high:new n.Vector3(a.x,a.y,a.z),low:new n.Vector3(o.x,o.y,o.z)};return i.free(),s},j=class{_raw;constructor(e,n){this._raw=new t.EllipsoidGeodesic(new t.LLE((0,t.angleToRadian)(e.lat),(0,t.angleToRadian)(e.lng),e.height),new t.LLE((0,t.angleToRadian)(n.lat),(0,t.angleToRadian)(n.lng),n.height))}get distance(){return this._raw.distance}get converged(){return this._raw.converged}get startHeading(){return(0,t.angleToDegree)(this._raw.start_heading)}get endHeading(){return(0,t.angleToDegree)(this._raw.end_heading)}get start(){let e=this._raw.start;return{lat:(0,t.angleToDegree)(e.lat),lng:(0,t.angleToDegree)(e.lng),height:e.height}}get end(){let e=this._raw.end;return{lat:(0,t.angleToDegree)(e.lat),lng:(0,t.angleToDegree)(e.lng),height:e.height}}interpolatePoints(e){let n=this._raw.interpolateGeodeticPoints(e??null),r=[];for(let e of n)r.push({lat:(0,t.angleToDegree)(e.lat),lng:(0,t.angleToDegree)(e.lng),height:e.height}),e.free();return r}interpolateDistance(e){let n=this._raw.interpolateDistance(e),r={lat:(0,t.angleToDegree)(n.lat),lng:(0,t.angleToDegree)(n.lng),height:n.height};return n.free(),r}dispose(){this._raw.free()}};async function M(){await(0,t.default)()}function N(e){let r=(0,t.geodeticToXyz)(new t.LLE((0,t.angleToRadian)(e.lat),(0,t.angleToRadian)(e.lng),e.height)),i=new n.Vector3(r.x,r.y,r.z);return r.free(),i}function P(e){let n=new t.Vec3(e.x,e.y,e.z),r=(0,t.xyzToGeodetic)(n),i={lat:(0,t.angleToDegree)(r.lat),lng:(0,t.angleToDegree)(r.lng),height:r.height};return r.free(),i}function F(e){return(0,t.angleToRadian)(e)}function I(e){return(0,t.angleToDegree)(e)}function L(e,r,i){let a=new t.Window(e.width,e.height,e.pixelRatio);a.width*=a.pixelRatio,a.height*=a.pixelRatio;let o=new t.Transform(r.position.x,r.position.y,r.position.z,r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w,r.scale.x,r.scale.y,r.scale.z),s=new t.CameraFrustum(r.near,r.far,(0,t.angleToRadian)(r.fov),r.aspect),c=(0,t.screenToWorld)(a,o,s,new t.Vec2(i.x,i.y));if(!c)return;let l=new n.Vector3(c.x,c.y,c.z);return c.free(),l}function R(e){let r=(0,t.geodeticSurfaceNormal)(new t.LLE((0,t.angleToRadian)(e.lat),(0,t.angleToRadian)(e.lng),e.height)),i=new n.Vector3(r.x,r.y,r.z);return r.free(),i}function z(e){let r=(0,t.scaleToGeodeticSurface)(new t.Vec3(e.x,e.y,e.z));if(!r)return;let i=new n.Vector3(r.x,r.y,r.z);return r.free(),i}function B(e){let r=new t.Vec3(e.x,e.y,e.z),i=(0,t.eastNorthUpToFixedFrame)(r);return new n.Matrix4().fromArray(i)}function V(e){let r=new t.Vec3(e.x,e.y,e.z),i=(0,t.northEastDownToFixedFrame)(r);return new n.Matrix4().fromArray(i)}function H(e){let r=new t.Vec3(e.x,e.y,e.z),i=(0,t.northUpEastToFixedFrame)(r);return new n.Matrix4().fromArray(i)}function U(e){let r=new t.Vec3(e.x,e.y,e.z),i=(0,t.northWestUpToFixedFrame)(r);return new n.Matrix4().fromArray(i)}function W(e){return H(e).multiply(u())}function G(e){return d(W(N({lng:e.lng,lat:e.lat,height:e.height??0})),e)}function K(e,r,i){let a=new t.Window(e.width,e.height,e.pixelRatio);a.width*=a.pixelRatio,a.height*=a.pixelRatio;let o=new t.Transform(r.position.x,r.position.y,r.position.z,r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w,r.scale.x,r.scale.y,r.scale.z),s=new t.CameraFrustum(r.near,r.far,(0,t.angleToRadian)(r.fov),r.aspect),c=(0,t.worldToScreen)(a,o,s,new t.Vec3(i.x,i.y,i.z));if(!c)return;let l=new n.Vector2(c.x,c.y);return c.free(),l}function q(){return(0,t.getWGS84SemiMajorAxis)()}function J(){return(0,t.getWGS84SemiMinorAxis)()}function Y(){return(0,t.getWGS84EccentricitySquared)()}function X(){return(0,t.getWGS84Flattening)()}function Z(){return(0,t.getWGS84Eccentricity)()}e.EllipsoidGeodesic=j,e.RTE_ONE_UNIFORM=w,e.buildPolygonGeometry=h,e.buildPolylineGeometry=g,e.calcCameraPosition=A,e.calcModelMatrixRTE=E,e.composeWorldMatrixForRTE=D,e.convertScreenToWorld=L,e.convertWorldToScreen=K,e.degreeToRadian=F,e.eastNorthUpToFixedFrame=B,e.encodePositionRTE=T,e.geodeticSurfaceNormal=R,e.geodeticToVector3=N,e.getHeightFromEllipsoid=C,e.getPickRay=x,e.getPlaneFromPointNormal=b,e.getRayPlaneIntersection=S,e.getWGS84Eccentricity=Z,e.getWGS84EccentricitySquared=Y,e.getWGS84Flattening=X,e.getWGS84SemiMajorAxis=q,e.getWGS84SemiMinorAxis=J,e.headingPitchRollToFixedFrame=G,e.initNavaraApi=M,e.northEastDownToFixedFrame=V,e.northUpEastToFixedFrame=H,e.northWestUpToFixedFrame=U,e.polygonGroundVolume=v,e.polylineGroundVolume=y,e.radianToDegree=I,e.scaleToGeodeticSurface=z,e.vector3ToGeodetic=P,e.westUpNorthToFixedFrame=W});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@navaramap/engine-api"),require("three")):typeof define==`function`&&define.amd?define([`exports`,`@navaramap/engine-api`,`three`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.NavaraThreeApi={},e._navaramap_engine_api,e.three))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=Object.create,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.getPrototypeOf,c=Object.prototype.hasOwnProperty,l=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var s=o(t),l=0,u=s.length,d;l<u;l++)d=s[l],!c.call(e,d)&&d!==n&&i(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=a(t,d))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:r(s(e)),l(i(n,`default`,{value:e,enumerable:!0}),e)))(t,1);function u(){return new n.Matrix4().makeRotationY(Math.PI/2)}function d(e,t){let r=new n.Matrix4().multiplyMatrices(e,new n.Matrix4().makeRotationFromEuler(new n.Euler(-n.MathUtils.degToRad(t.pitch??0),-n.MathUtils.degToRad(t.heading??0),n.MathUtils.degToRad(t.roll??0),`YXZ`)));if(t.scale!==void 0){let e=t.scale;r.scale(typeof e==`number`?new n.Vector3(e,e,e):new n.Vector3(e.x,e.y,e.z))}return r}function f(e){return{west:(0,t.angleToDegree)(e.west),south:(0,t.angleToDegree)(e.south),east:(0,t.angleToDegree)(e.east),north:(0,t.angleToDegree)(e.north)}}function p(e){let t=0;for(let n of e)t+=n.length;let n=new Float64Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}function m(e){let t=new Uint32Array(e.length);for(let n=0;n<e.length;n++)t[n]=e[n].length/3;return t}function h(e,n,r){let i=(0,t.buildPolygonGeometry)(p(e),m(e),n,r);if(i)try{let e=i.position_3d_high(),t=i.position_3d_low(),n=i.extent;if(!e||!t||!n)throw Error(`buildPolygonGeometry: incomplete RTE geometry`);let r=i.scale_normal_and_cap();if(!r)throw Error(`buildPolygonGeometry: missing extrusion attribute`);return{positionHigh:e,positionLow:t,normal:i.normal(),scaleNormalAndCap:r,indices:i.indices(),extent:f(n)}}finally{i.free()}}function g(e,n,r,i){let a=(0,t.buildPolylineGeometry)(e,n,r,i);if(a)try{let e=a.position_high(),t=a.position_low(),n=a.start_high(),r=a.start_low(),i=a.end_high(),o=a.end_low(),s=a.start_normal_and_length_high(),c=a.end_normal_and_segment_length(),l=a.line_segments(),u=a.extent;if(!e||!t||!n||!r||!i||!o||!s||!c||!l||!u)throw Error(`buildPolylineGeometry: incomplete RTE geometry`);return{position:a.position(),positionHigh:e,positionLow:t,startHigh:n,startLow:r,endHigh:i,endLow:o,startNormalAndLengthHigh:s,endNormalAndSegmentLength:c,rightNormalAndLineLength:a.right_normal_and_line_length(),indices:a.indices(),lineSegments:l,extent:f(u)}}finally{a.free()}}function _(e,n,r){let i=e(n.min,n.max,(0,t.angleToRadian)(r.west),(0,t.angleToRadian)(r.south),(0,t.angleToRadian)(r.east),(0,t.angleToRadian)(r.north));return[i[0],i[1]]}function v(e,n){return _(t.polygonGroundVolume,e,n)}function y(e,n){return _(t.polylineGroundVolume,e,n)}function b(e,r){let i=new t.Vec3(e.x,e.y,e.z),a=new t.Vec3(r.x,r.y,r.z),o=(0,t.getPlaneFromPointNormal)(i,a),s=new n.Vector3(o.normal.x,o.normal.y,o.normal.z),c=new n.Plane(s,-o.distance);return o.free(),c}function x(e,r,i){let a=new t.Window(e.width,e.height,e.pixelRatio);a.width*=a.pixelRatio,a.height*=a.pixelRatio;let o=new t.Transform(r.position.x,r.position.y,r.position.z,r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w,r.scale.x,r.scale.y,r.scale.z),s=new t.CameraFrustum(r.near,r.far,(0,t.angleToRadian)(r.fov),r.aspect),c=(0,t.getPickRay)(a,o,s,new t.Vec2(i.x,i.y)),l=new n.Vector3(c.origin.x,c.origin.y,c.origin.z),u=new n.Vector3(c.direction.x,c.direction.y,c.direction.z),d=new n.Ray(l,u);return c.free(),d}function S(e,r){let i=new t.Ray(new t.Vec3(e.origin.x,e.origin.y,e.origin.z),new t.Vec3(e.direction.x,e.direction.y,e.direction.z)),a=(0,t.getPlaneFromPointNormal)(new t.Vec3(r.normal.x*-r.constant,r.normal.y*-r.constant,r.normal.z*-r.constant),new t.Vec3(r.normal.x,r.normal.y,r.normal.z)),o=(0,t.getRayPlaneIntersection)(i,a);if(o){let e=new n.Vector3(o.x,o.y,o.z);return o.free(),e}}function C(e){let n=new t.Vec3(e.x,e.y,e.z);return(0,t.getHeightFromEllipsoid)(n)}var w=Object.freeze({value:1});function T(e,r=new n.Vector3,i=new n.Vector3){let a=(0,t.encodePosition)(e.x,e.y,e.z);return r.set(a.high.x,a.high.y,a.high.z),i.set(a.low.x,a.low.y,a.low.z),a.free(),{high:r,low:i}}var E=(e,t,r=new n.Matrix4)=>{r.multiplyMatrices(t,e);let i=r.elements;return i[12]=0,i[13]=0,i[14]=0,r};function D(e,t,r=new n.Vector3,i=new n.Matrix4){i.multiplyMatrices(e,t),r.setFromMatrixPosition(i);let a=i.elements;return a[12]=0,a[13]=0,a[14]=0,{position:r,rotationScale:i}}var O=new n.Matrix4,k=new n.Vector3,A=(e,r)=>{O.copy(r).invert(),k.copy(e).applyMatrix4(O);let i=(0,t.encodePosition)(k.x,k.y,k.z),a=i.high,o=i.low,s={high:new n.Vector3(a.x,a.y,a.z),low:new n.Vector3(o.x,o.y,o.z)};return i.free(),s},j=class{_raw;constructor(e,n){this._raw=new t.EllipsoidGeodesic(new t.LLE((0,t.angleToRadian)(e.lat),(0,t.angleToRadian)(e.lng),e.height),new t.LLE((0,t.angleToRadian)(n.lat),(0,t.angleToRadian)(n.lng),n.height))}get distance(){return this._raw.distance}get converged(){return this._raw.converged}get startHeading(){return(0,t.angleToDegree)(this._raw.start_heading)}get endHeading(){return(0,t.angleToDegree)(this._raw.end_heading)}get start(){let e=this._raw.start;return{lat:(0,t.angleToDegree)(e.lat),lng:(0,t.angleToDegree)(e.lng),height:e.height}}get end(){let e=this._raw.end;return{lat:(0,t.angleToDegree)(e.lat),lng:(0,t.angleToDegree)(e.lng),height:e.height}}interpolatePoints(e){let n=this._raw.interpolateGeodeticPoints(e??null),r=[];for(let e of n)r.push({lat:(0,t.angleToDegree)(e.lat),lng:(0,t.angleToDegree)(e.lng),height:e.height}),e.free();return r}interpolateDistance(e){let n=this._raw.interpolateDistance(e),r={lat:(0,t.angleToDegree)(n.lat),lng:(0,t.angleToDegree)(n.lng),height:n.height};return n.free(),r}dispose(){this._raw.free()}},M=Symbol.for(`@navaramap/engine-api/init`);async function N(){let e=globalThis;e[M]??=(0,t.default)().catch(t=>{throw e[M]=void 0,t}),await e[M]}function P(e){let r=(0,t.geodeticToXyz)(new t.LLE((0,t.angleToRadian)(e.lat),(0,t.angleToRadian)(e.lng),e.height)),i=new n.Vector3(r.x,r.y,r.z);return r.free(),i}function F(e){let n=new t.Vec3(e.x,e.y,e.z),r=(0,t.xyzToGeodetic)(n),i={lat:(0,t.angleToDegree)(r.lat),lng:(0,t.angleToDegree)(r.lng),height:r.height};return r.free(),i}function I(e){return(0,t.angleToRadian)(e)}function L(e){return(0,t.angleToDegree)(e)}function R(e,r,i){let a=new t.Window(e.width,e.height,e.pixelRatio);a.width*=a.pixelRatio,a.height*=a.pixelRatio;let o=new t.Transform(r.position.x,r.position.y,r.position.z,r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w,r.scale.x,r.scale.y,r.scale.z),s=new t.CameraFrustum(r.near,r.far,(0,t.angleToRadian)(r.fov),r.aspect),c=(0,t.screenToWorld)(a,o,s,new t.Vec2(i.x,i.y));if(!c)return;let l=new n.Vector3(c.x,c.y,c.z);return c.free(),l}function z(e){let r=(0,t.geodeticSurfaceNormal)(new t.LLE((0,t.angleToRadian)(e.lat),(0,t.angleToRadian)(e.lng),e.height)),i=new n.Vector3(r.x,r.y,r.z);return r.free(),i}function B(e){let r=(0,t.scaleToGeodeticSurface)(new t.Vec3(e.x,e.y,e.z));if(!r)return;let i=new n.Vector3(r.x,r.y,r.z);return r.free(),i}function V(e){let r=new t.Vec3(e.x,e.y,e.z),i=(0,t.eastNorthUpToFixedFrame)(r);return new n.Matrix4().fromArray(i)}function H(e){let r=new t.Vec3(e.x,e.y,e.z),i=(0,t.northEastDownToFixedFrame)(r);return new n.Matrix4().fromArray(i)}function U(e){let r=new t.Vec3(e.x,e.y,e.z),i=(0,t.northUpEastToFixedFrame)(r);return new n.Matrix4().fromArray(i)}function W(e){let r=new t.Vec3(e.x,e.y,e.z),i=(0,t.northWestUpToFixedFrame)(r);return new n.Matrix4().fromArray(i)}function G(e){return U(e).multiply(u())}function K(e){return d(G(P({lng:e.lng,lat:e.lat,height:e.height??0})),e)}function q(e,r,i){let a=new t.Window(e.width,e.height,e.pixelRatio);a.width*=a.pixelRatio,a.height*=a.pixelRatio;let o=new t.Transform(r.position.x,r.position.y,r.position.z,r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w,r.scale.x,r.scale.y,r.scale.z),s=new t.CameraFrustum(r.near,r.far,(0,t.angleToRadian)(r.fov),r.aspect),c=(0,t.worldToScreen)(a,o,s,new t.Vec3(i.x,i.y,i.z));if(!c)return;let l=new n.Vector2(c.x,c.y);return c.free(),l}function J(){return(0,t.getWGS84SemiMajorAxis)()}function Y(){return(0,t.getWGS84SemiMinorAxis)()}function X(){return(0,t.getWGS84EccentricitySquared)()}function Z(){return(0,t.getWGS84Flattening)()}function Q(){return(0,t.getWGS84Eccentricity)()}e.EllipsoidGeodesic=j,e.RTE_ONE_UNIFORM=w,e.buildPolygonGeometry=h,e.buildPolylineGeometry=g,e.calcCameraPosition=A,e.calcModelMatrixRTE=E,e.composeWorldMatrixForRTE=D,e.convertScreenToWorld=R,e.convertWorldToScreen=q,e.degreeToRadian=I,e.eastNorthUpToFixedFrame=V,e.encodePositionRTE=T,e.geodeticSurfaceNormal=z,e.geodeticToVector3=P,e.getHeightFromEllipsoid=C,e.getPickRay=x,e.getPlaneFromPointNormal=b,e.getRayPlaneIntersection=S,e.getWGS84Eccentricity=Q,e.getWGS84EccentricitySquared=X,e.getWGS84Flattening=Z,e.getWGS84SemiMajorAxis=J,e.getWGS84SemiMinorAxis=Y,e.headingPitchRollToFixedFrame=K,e.initNavaraApi=N,e.northEastDownToFixedFrame=H,e.northUpEastToFixedFrame=U,e.northWestUpToFixedFrame=W,e.polygonGroundVolume=v,e.polylineGroundVolume=y,e.radianToDegree=L,e.scaleToGeodeticSurface=B,e.vector3ToGeodetic=F,e.westUpNorthToFixedFrame=G});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@navaramap/three-api",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "0.3.0",
5
5
  "main": "dist/index.umd.cjs",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -22,12 +22,12 @@
22
22
  "three": ">=0.183.0"
23
23
  },
24
24
  "dependencies": {
25
- "@navaramap/core": "0.2.0",
26
- "@navaramap/engine-api": "0.2.0"
25
+ "@navaramap/core": "0.3.0",
26
+ "@navaramap/engine-api": "0.3.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@types/three": "0.185.4",
30
- "three": "0.185.1"
29
+ "@types/three": "0.186.0",
30
+ "three": "0.186.1"
31
31
  },
32
32
  "scripts": {
33
33
  "type-check": "tsc && tsc -p tsconfig.node.json",
@@ -48,10 +48,12 @@ export type PolylineGeometryData = {
48
48
  startLow: Float32Array;
49
49
  endHigh: Float32Array;
50
50
  endLow: Float32Array;
51
- startNormal: Float32Array;
52
- endNormalAndTextureCoordinateNormalizationX: Float32Array;
53
- rightNormalAndTextureCoordinateNormalizationY: Float32Array;
51
+ startNormalAndLengthHigh: Float32Array;
52
+ endNormalAndSegmentLength: Float32Array;
53
+ rightNormalAndLineLength: Float32Array;
54
54
  indices: Uint32Array;
55
+ /** One entry of three RGBA texels per segment, for a dash pattern. */
56
+ lineSegments: Float32Array;
55
57
  extent: GeographicExtent;
56
58
  };
57
59
 
@@ -174,8 +176,9 @@ export function buildPolylineGeometry(
174
176
  const startLow = built.start_low();
175
177
  const endHigh = built.end_high();
176
178
  const endLow = built.end_low();
177
- const startNormal = built.start_normals();
178
- const endNormal = built.end_normal_and_texture_coordinate_normalization_x();
179
+ const startNormalAndLengthHigh = built.start_normal_and_length_high();
180
+ const endNormal = built.end_normal_and_segment_length();
181
+ const lineSegments = built.line_segments();
179
182
  const extent = built.extent;
180
183
  if (
181
184
  !positionHigh ||
@@ -184,8 +187,9 @@ export function buildPolylineGeometry(
184
187
  !startLow ||
185
188
  !endHigh ||
186
189
  !endLow ||
187
- !startNormal ||
190
+ !startNormalAndLengthHigh ||
188
191
  !endNormal ||
192
+ !lineSegments ||
189
193
  !extent
190
194
  ) {
191
195
  throw new Error("buildPolylineGeometry: incomplete RTE geometry");
@@ -199,11 +203,11 @@ export function buildPolylineGeometry(
199
203
  startLow,
200
204
  endHigh,
201
205
  endLow,
202
- startNormal,
203
- endNormalAndTextureCoordinateNormalizationX: endNormal,
204
- rightNormalAndTextureCoordinateNormalizationY:
205
- built.right_normal_and_texture_coordinate_normalization_y(),
206
+ startNormalAndLengthHigh,
207
+ endNormalAndSegmentLength: endNormal,
208
+ rightNormalAndLineLength: built.right_normal_and_line_length(),
206
209
  indices: built.indices(),
210
+ lineSegments,
207
211
  extent: toDegrees(extent),
208
212
  };
209
213
  } finally {
package/src/index.ts CHANGED
@@ -49,11 +49,24 @@ export * from "./intersection";
49
49
  export * from "./rte";
50
50
  export * from "./ellipsoidGeodesic";
51
51
 
52
+ // wasm-bindgen's init only short-circuits once a call has finished, so
53
+ // concurrent callers must share one promise or the later instantiation
54
+ // replaces the module the earlier caller's objects live in. @navaramap/font
55
+ // initializes the same module, so the promise lives under a global key both
56
+ // packages use.
57
+ const API_READY = Symbol.for("@navaramap/engine-api/init");
58
+ type ApiReadyHolder = { [API_READY]?: Promise<unknown> };
59
+
52
60
  /**
53
61
  * Initializes the Navara API WASM module. Must be called before using other API functions.
54
62
  */
55
63
  export async function initNavaraApi() {
56
- await initApi();
64
+ const holder = globalThis as ApiReadyHolder;
65
+ holder[API_READY] ??= initApi().catch((e: unknown) => {
66
+ holder[API_READY] = undefined;
67
+ throw e;
68
+ });
69
+ await holder[API_READY];
57
70
  }
58
71
 
59
72
  /**