@openglobus/og 0.10.2 → 0.10.5

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.
@@ -1,407 +1,425 @@
1
- "use strict";
2
-
3
- // import { QueueArray } from '../QueueArray.js';
4
- import { EPSG4326 } from "../proj/EPSG4326.js";
5
-
6
- class PlainSegmentWorker {
7
- constructor(numWorkers = 2) {
8
- this._id = 0;
9
- this._segments = {};
10
-
11
- this._workerQueue = [];
12
-
13
- var elevationProgramm = new Blob([_programm], { type: "application/javascript" });
14
-
15
- let _this = this;
16
-
17
- for (let i = 0; i < numWorkers; i++) {
18
- let w = new Worker(URL.createObjectURL(elevationProgramm));
19
-
20
- w.onmessage = function (e) {
21
- _this._segments[e.data.id]._plainSegmentWorkerCallback(e.data);
22
-
23
- e.data.plainVertices = null;
24
- e.data.plainVerticesHigh = null;
25
- e.data.plainVerticesLow = null;
26
- e.data.plainNormals = null;
27
- e.data.normalMapNormals = null;
28
- e.data.normalMapVertices = null;
29
- e.data.normalMapVerticesHigh = null;
30
- e.data.normalMapVerticesLow = null;
31
-
32
- _this._segments[e.data.id] = null;
33
- delete _this._segments[e.data.id];
34
-
35
- _this._workerQueue.unshift(this);
36
- _this.check();
37
- };
38
-
39
- this._workerQueue.push(w);
40
- }
41
-
42
- this._pendingQueue = [];
43
- }
44
-
45
- check() {
46
- if (this._pendingQueue.length) {
47
- this.make(this._pendingQueue.pop());
48
- }
49
- }
50
-
51
- setGeoid(geoid) {
52
- let m = geoid.model;
53
-
54
- let model = {
55
- scale: m.scale,
56
- offset: m.offset,
57
- width: m.width,
58
- height: m.height,
59
- rlonres: m.rlonres,
60
- rlatres: m.rlatres,
61
- i: m.i
62
- };
63
-
64
- this._workerQueue.forEach((w) => {
65
- let rawfile = new Uint8Array(m.rawfile.length);
66
- rawfile.set(m.rawfile);
67
-
68
- w.postMessage(
69
- {
70
- model: model,
71
- rawfile: rawfile
72
- },
73
- [rawfile.buffer]
74
- );
75
- });
76
- }
77
-
78
- make(segment) {
79
- if (segment.initialized) {
80
- if (this._workerQueue.length) {
81
- let w = this._workerQueue.pop();
82
-
83
- this._segments[this._id] = segment;
84
-
85
- let params = new Float64Array([
86
- this._id++,
87
- segment._projection.id === EPSG4326.id ? 1.0 : 0.0,
88
- segment.planet.terrain.gridSizeByZoom[segment.tileZoom],
89
- segment.planet.terrain.plainGridSize,
90
- segment._extent.southWest.lon,
91
- segment._extent.southWest.lat,
92
- segment._extent.northEast.lon,
93
- segment._extent.northEast.lat,
94
- segment.planet.ellipsoid._e2,
95
- segment.planet.ellipsoid._a,
96
- segment.planet.ellipsoid._invRadii2.x,
97
- segment.planet.ellipsoid._invRadii2.y,
98
- segment.planet.ellipsoid._invRadii2.z
99
- ]);
100
-
101
- w.postMessage(
102
- {
103
- params: params
104
- },
105
- [params.buffer]
106
- );
107
- } else {
108
- this._pendingQueue.push(segment);
109
- }
110
- } else {
111
- this.check();
112
- }
113
- }
114
- }
115
-
116
- const _programm = `
117
- 'use strict';
118
-
119
- let cached_ix = null;
120
- let cached_iy = null;
121
- let v00 = null;
122
- let v01 = null;
123
- let v10 = null;
124
- let v11 = null;
125
- let t = null;
126
-
127
- function rawval(ix, iy) {
128
-
129
- if (iy < 0) {
130
- iy = -iy;
131
- ix += model.width / 2;
132
- } else if (iy >= model.height) {
133
- iy = 2 * (model.height - 1) - iy;
134
- ix += model.width / 2;
135
- }
136
-
137
- if (ix < 0) {
138
- ix += model.width;
139
- } else if (ix >= model.width) {
140
- ix -= model.width;
141
- }
142
-
143
- var k = (iy * model.width + ix) * 2 + model.i;
144
-
145
- return (model.rawfile[k] << 8) | model.rawfile[k + 1];
146
- };
147
-
148
- function getHeight(lon, lat) {
149
-
150
- if (!model) return 0;
151
-
152
- if (lon < 0) lon += 360.0;
153
-
154
- var fy = (90 - lat) * model.rlatres;
155
- var fx = lon * model.rlonres;
156
- var iy = Math.floor(fy);
157
- var ix = Math.floor(fx);
158
-
159
- fx -= ix;
160
- fy -= iy;
161
-
162
- if (iy === (model.height - 1)) {
163
- iy--;
164
- }
165
-
166
- if ((cached_ix !== ix) || (cached_iy !== iy)) {
167
-
168
- cached_ix = ix;
169
- cached_iy = iy;
170
-
171
- v00 = rawval(ix, iy);
172
- v01 = rawval(ix + 1, iy);
173
- v10 = rawval(ix, iy + 1);
174
- v11 = rawval(ix + 1, iy + 1);
175
- }
176
-
177
- let h = null;
178
-
179
- var a = (1 - fx) * v00 + fx * v01;
180
- var b = (1 - fx) * v10 + fx * v11;
181
-
182
- h = (1 - fy) * a + fy * b;
183
-
184
- return model.offset + model.scale * h;
185
- };
186
-
187
- let model = null;
188
-
189
- const HALF_PI = Math.PI * 0.5;
190
- const POLE = 20037508.34;
191
- const PI_BY_POLE = Math.PI / POLE;
192
- const INV_POLE_BY_180 = 180.0 / POLE;
193
- const INV_PI_BY_180 = 180.0 / Math.PI;
194
- const INV_PI_BY_180_HALF_PI = INV_PI_BY_180 * HALF_PI;
195
- const RADIANS = Math.PI / 180.0;
196
- const INV_PI_BY_360 = INV_PI_BY_180 * 2.0;
197
-
198
- let E2 = 0.0, A = 0.0;
199
-
200
- let _projFunc = null;
201
-
202
- const Vec3 = function (x, y, z) {
203
- this.x = x;
204
- this.y = y;
205
- this.z = z;
206
- };
207
-
208
- var lonLatToCartesian = function (lon, lat, res) {
209
-
210
- let h = getHeight(lon, lat);
211
-
212
- let latrad = RADIANS * lat,
213
- lonrad = RADIANS * lon;
214
-
215
- let slt = Math.sin(latrad);
216
-
217
- let N = A / Math.sqrt(1.0 - E2 * slt * slt);
218
- let nc = (N + h) * Math.cos(latrad);
219
-
220
- res.x = nc * Math.sin(lonrad);
221
- res.y = (N * (1.0 - E2) + h) * slt;
222
- res.z = nc * Math.cos(lonrad);
223
- };
224
-
225
- var lonLatToCartesianInverse = function (lon, lat, res){
226
- lonLatToCartesian(
227
- lon * INV_POLE_BY_180,
228
- INV_PI_BY_360 * Math.atan(Math.exp(lat * PI_BY_POLE)) - INV_PI_BY_180_HALF_PI,
229
- res);
230
- };
231
-
232
- var v = new Vec3(0.0, 0.0, 0.0);
233
- var _tempHigh = new Vec3(0.0, 0.0, 0.0);
234
- var _tempLow = new Vec3(0.0, 0.0, 0.0);
235
-
236
- var doubleToTwoFloats = function(v, high, low) {
237
-
238
- let x = v.x, y = v.y, z = v.z;
239
-
240
- if (x >= 0.0) {
241
- var doubleHigh = Math.floor(x / 65536.0) * 65536.0;
242
- high.x = Math.fround(doubleHigh);
243
- low.x = Math.fround(x - doubleHigh);
244
- } else {
245
- var doubleHigh = Math.floor(-x / 65536.0) * 65536.0;
246
- high.x = Math.fround(-doubleHigh);
247
- low.x = Math.fround(x + doubleHigh);
248
- }
249
-
250
- if (y >= 0.0) {
251
- var doubleHigh = Math.floor(y / 65536.0) * 65536.0;
252
- high.y = Math.fround(doubleHigh);
253
- low.y = Math.fround(y - doubleHigh);
254
- } else {
255
- var doubleHigh = Math.floor(-y / 65536.0) * 65536.0;
256
- high.y = Math.fround(-doubleHigh);
257
- low.y = Math.fround(y + doubleHigh);
258
- }
259
-
260
- if (z >= 0.0) {
261
- var doubleHigh = Math.floor(z / 65536.0) * 65536.0;
262
- high.z = Math.fround(doubleHigh);
263
- low.z = Math.fround(z - doubleHigh);
264
- } else {
265
- var doubleHigh = Math.floor(-z / 65536.0) * 65536.0;
266
- high.z = Math.fround(-doubleHigh);
267
- low.z = Math.fround(z + doubleHigh);
268
- }
269
- };
270
-
271
- self.onmessage = function (msg) {
272
- if(msg.data.model) {
273
- model = msg.data.model;
274
- model.rawfile = msg.data.rawfile;
275
- } else if(msg.data.params) {
276
-
277
- let xmin = 549755748352.0, xmax = -549755748352.0,
278
- ymin = 549755748352.0, ymax = -549755748352.0,
279
- zmin = 549755748352.0, zmax = -549755748352.0;
280
-
281
- E2 = msg.data.params[8];
282
- A = msg.data.params[9];
283
-
284
- let gridSize = msg.data.params[2],
285
- fgs = msg.data.params[3],
286
- r2_x = msg.data.params[10],
287
- r2_y = msg.data.params[11],
288
- r2_z = msg.data.params[12];
289
-
290
- if(msg.data.params[1] === 0.0){
291
- _projFunc = lonLatToCartesianInverse;
292
- }else{
293
- _projFunc = lonLatToCartesian;
294
- }
295
-
296
- let maxFgs = Math.max(fgs, gridSize);
297
- let llStep = (msg.data.params[6] - msg.data.params[4]) / maxFgs;
298
- let ltStep = (msg.data.params[7] - msg.data.params[5]) / maxFgs;
299
-
300
- let esw_lon = msg.data.params[4],
301
- ene_lat = msg.data.params[7];
302
-
303
- let dg = Math.max(fgs / gridSize, 1.0),
304
- gs = maxFgs + 1;
305
-
306
- const gsgs = gs * gs;
307
-
308
- const gridSize3 = (gridSize + 1) * (gridSize + 1) * 3;
309
-
310
- let plainNormals = new Float32Array(gridSize3);
311
-
312
- let plainVertices = new Float64Array(gridSize3);
313
- let plainVerticesHigh = new Float32Array(gridSize3);
314
- let plainVerticesLow = new Float32Array(gridSize3);
315
-
316
- let normalMapNormals = new Float32Array(gsgs * 3);
317
-
318
- let normalMapVertices = new Float64Array(gsgs * 3);
319
- let normalMapVerticesHigh = new Float32Array(gsgs * 3);
320
- let normalMapVerticesLow = new Float32Array(gsgs * 3);
321
-
322
- let ind = 0,
323
- nmInd = 0;
324
-
325
- for (let k = 0; k < gsgs; k++) {
326
-
327
- let j = k % gs,
328
- i = ~~(k / gs);
329
-
330
- _projFunc(esw_lon + j * llStep, ene_lat - i * ltStep, v);
331
-
332
- let nx = v.x * r2_x, ny = v.y * r2_y, nz = v.z * r2_z;
333
- let l = 1.0 / Math.sqrt(nx * nx + ny * ny + nz * nz);
334
- let nxl = nx * l,
335
- nyl = ny * l,
336
- nzl = nz * l;
337
-
338
- doubleToTwoFloats(v, _tempHigh, _tempLow);
339
-
340
- normalMapVertices[nmInd] = v.x;
341
- normalMapVerticesHigh[nmInd] = _tempHigh.x;
342
- normalMapVerticesLow[nmInd] = _tempLow.x;
343
- normalMapNormals[nmInd++] = nxl;
344
-
345
- normalMapVertices[nmInd] = v.y;
346
- normalMapVerticesHigh[nmInd] = _tempHigh.y;
347
- normalMapVerticesLow[nmInd] = _tempLow.y;
348
- normalMapNormals[nmInd++] = nyl;
349
-
350
- normalMapVertices[nmInd] = v.z;
351
- normalMapVerticesHigh[nmInd] = _tempHigh.z;
352
- normalMapVerticesLow[nmInd] = _tempLow.z;
353
- normalMapNormals[nmInd++] = nzl;
354
-
355
- if (i % dg === 0 && j % dg === 0) {
356
- plainVertices[ind] = v.x;
357
- plainVerticesHigh[ind] = _tempHigh.x;
358
- plainVerticesLow[ind] = _tempLow.x;
359
- plainNormals[ind++] = nxl;
360
-
361
- plainVertices[ind] = v.y;
362
- plainVerticesHigh[ind] = _tempHigh.y;
363
- plainVerticesLow[ind] = _tempLow.y;
364
- plainNormals[ind++] = nyl;
365
-
366
- plainVertices[ind] = v.z;
367
- plainVerticesHigh[ind] = _tempHigh.z;
368
- plainVerticesLow[ind] = _tempLow.z;
369
- plainNormals[ind++] = nzl;
370
-
371
- if (v.x < xmin) xmin = v.x; if (v.x > xmax) xmax = v.x;
372
- if (v.y < ymin) ymin = v.y; if (v.y > ymax) ymax = v.y;
373
- if (v.z < zmin) zmin = v.z; if (v.z > zmax) zmax = v.z;
374
- }
375
- }
376
-
377
- let x = (xmax - xmin) * 0.5,
378
- y = (ymax - ymin) * 0.5,
379
- z = (zmax - zmin) * 0.5;
380
-
381
- let plainRadius = Math.sqrt(x * x + y * y + z * z);
382
-
383
- self.postMessage({
384
- id: msg.data.params[0],
385
- plainVertices: plainVertices,
386
- plainVerticesHigh: plainVerticesHigh,
387
- plainVerticesLow: plainVerticesLow,
388
- plainNormals: plainNormals,
389
- normalMapNormals: normalMapNormals,
390
- normalMapVertices: normalMapVertices,
391
- normalMapVerticesHigh: normalMapVerticesHigh,
392
- normalMapVerticesLow: normalMapVerticesLow,
393
- plainRadius: plainRadius
394
- }, [
395
- plainVertices.buffer,
396
- plainVerticesHigh.buffer,
397
- plainVerticesLow.buffer,
398
- plainNormals.buffer,
399
- normalMapNormals.buffer,
400
- normalMapVertices.buffer,
401
- normalMapVerticesHigh.buffer,
402
- normalMapVerticesLow.buffer
403
- ]);
404
- }
405
- }`;
406
-
407
- export { PlainSegmentWorker };
1
+ "use strict";
2
+
3
+ // import { QueueArray } from '../QueueArray.js';
4
+ import { EPSG4326 } from "../proj/EPSG4326.js";
5
+
6
+ class PlainSegmentWorker {
7
+ constructor(numWorkers = 2) {
8
+ this._id = 0;
9
+ this._segments = {};
10
+
11
+ this._workerQueue = [];
12
+
13
+ var elevationProgramm = new Blob([_programm], { type: "application/javascript" });
14
+
15
+ let _this = this;
16
+
17
+ for (let i = 0; i < numWorkers; i++) {
18
+ let w = new Worker(URL.createObjectURL(elevationProgramm));
19
+
20
+ w.onmessage = function (e) {
21
+ _this._segments[e.data.id]._plainSegmentWorkerCallback(e.data);
22
+
23
+ e.data.plainVertices = null;
24
+ e.data.plainVerticesHigh = null;
25
+ e.data.plainVerticesLow = null;
26
+ e.data.plainNormals = null;
27
+ e.data.normalMapNormals = null;
28
+ e.data.normalMapVertices = null;
29
+ e.data.normalMapVerticesHigh = null;
30
+ e.data.normalMapVerticesLow = null;
31
+
32
+ _this._segments[e.data.id] = null;
33
+ delete _this._segments[e.data.id];
34
+
35
+ _this._workerQueue.unshift(this);
36
+ _this.check();
37
+ };
38
+
39
+ this._workerQueue.push(w);
40
+ }
41
+
42
+ this._pendingQueue = [];
43
+ }
44
+
45
+ check() {
46
+ if (this._pendingQueue.length) {
47
+ this.make(this._pendingQueue.pop());
48
+ }
49
+ }
50
+
51
+ setGeoid(geoid) {
52
+ let m = geoid.model;
53
+
54
+ let model = {
55
+ scale: m.scale,
56
+ offset: m.offset,
57
+ width: m.width,
58
+ height: m.height,
59
+ rlonres: m.rlonres,
60
+ rlatres: m.rlatres,
61
+ i: m.i
62
+ };
63
+
64
+ this._workerQueue.forEach((w) => {
65
+ let rawfile = new Uint8Array(m.rawfile.length);
66
+ rawfile.set(m.rawfile);
67
+
68
+ w.postMessage(
69
+ {
70
+ model: model,
71
+ rawfile: rawfile
72
+ },
73
+ [rawfile.buffer]
74
+ );
75
+ });
76
+ }
77
+
78
+ make(segment) {
79
+ if (segment.initialized) {
80
+ if (this._workerQueue.length) {
81
+ let w = this._workerQueue.pop();
82
+
83
+ this._segments[this._id] = segment;
84
+
85
+ let params = new Float64Array([
86
+ this._id++,
87
+ segment._projection.id === EPSG4326.id ? 1.0 : 0.0,
88
+ segment.planet.terrain.gridSizeByZoom[segment.tileZoom],
89
+ segment.planet.terrain.plainGridSize,
90
+ segment._extent.southWest.lon,
91
+ segment._extent.southWest.lat,
92
+ segment._extent.northEast.lon,
93
+ segment._extent.northEast.lat,
94
+ segment.planet.ellipsoid._e2,
95
+ segment.planet.ellipsoid._a,
96
+ segment.planet.ellipsoid._invRadii2.x,
97
+ segment.planet.ellipsoid._invRadii2.y,
98
+ segment.planet.ellipsoid._invRadii2.z,
99
+ segment.planet._heightFactor
100
+ ]);
101
+
102
+ w.postMessage(
103
+ {
104
+ params: params
105
+ },
106
+ [params.buffer]
107
+ );
108
+ } else {
109
+ this._pendingQueue.push(segment);
110
+ }
111
+ } else {
112
+ this.check();
113
+ }
114
+ }
115
+ }
116
+
117
+ const _programm = `
118
+ 'use strict';
119
+
120
+ let cached_ix = null;
121
+ let cached_iy = null;
122
+ let v00 = null;
123
+ let v01 = null;
124
+ let v10 = null;
125
+ let v11 = null;
126
+ let t = null;
127
+
128
+ function rawval(ix, iy) {
129
+
130
+ if (iy < 0) {
131
+ iy = -iy;
132
+ ix += model.width / 2;
133
+ } else if (iy >= model.height) {
134
+ iy = 2 * (model.height - 1) - iy;
135
+ ix += model.width / 2;
136
+ }
137
+
138
+ if (ix < 0) {
139
+ ix += model.width;
140
+ } else if (ix >= model.width) {
141
+ ix -= model.width;
142
+ }
143
+
144
+ var k = (iy * model.width + ix) * 2 + model.i;
145
+
146
+ return (model.rawfile[k] << 8) | model.rawfile[k + 1];
147
+ };
148
+
149
+ function getHeightMSL(lon, lat) {
150
+
151
+ if (!model) return 0;
152
+
153
+ if (lon < 0) lon += 360.0;
154
+
155
+ var fy = (90 - lat) * model.rlatres;
156
+ var fx = lon * model.rlonres;
157
+ var iy = Math.floor(fy);
158
+ var ix = Math.floor(fx);
159
+
160
+ fx -= ix;
161
+ fy -= iy;
162
+
163
+ if (iy === (model.height - 1)) {
164
+ iy--;
165
+ }
166
+
167
+ if ((cached_ix !== ix) || (cached_iy !== iy)) {
168
+
169
+ cached_ix = ix;
170
+ cached_iy = iy;
171
+
172
+ v00 = rawval(ix, iy);
173
+ v01 = rawval(ix + 1, iy);
174
+ v10 = rawval(ix, iy + 1);
175
+ v11 = rawval(ix + 1, iy + 1);
176
+ }
177
+
178
+ let h = null;
179
+
180
+ var a = (1 - fx) * v00 + fx * v01;
181
+ var b = (1 - fx) * v10 + fx * v11;
182
+
183
+ h = (1 - fy) * a + fy * b;
184
+
185
+ return model.offset + model.scale * h;
186
+ };
187
+
188
+ let model = null;
189
+
190
+ const HALF_PI = Math.PI * 0.5;
191
+ const POLE = 20037508.34;
192
+ const PI_BY_POLE = Math.PI / POLE;
193
+ const INV_POLE_BY_180 = 180.0 / POLE;
194
+ const INV_PI_BY_180 = 180.0 / Math.PI;
195
+ const INV_PI_BY_180_HALF_PI = INV_PI_BY_180 * HALF_PI;
196
+ const RADIANS = Math.PI / 180.0;
197
+ const INV_PI_BY_360 = INV_PI_BY_180 * 2.0;
198
+
199
+ let E2 = 0.0,
200
+ A = 0.0;
201
+
202
+ let _projFunc = null;
203
+
204
+ const Vec3 = function (x, y, z) {
205
+ this.x = x;
206
+ this.y = y;
207
+ this.z = z;
208
+ };
209
+
210
+ var lonLatToCartesian = function (lon, lat, heightFactor, res) {
211
+
212
+ let h = getHeightMSL(lon, lat) * heightFactor;
213
+
214
+ let latrad = RADIANS * lat,
215
+ lonrad = RADIANS * lon;
216
+
217
+ let slt = Math.sin(latrad);
218
+
219
+ let N = A / Math.sqrt(1.0 - E2 * slt * slt);
220
+ let nc = (N + h) * Math.cos(latrad);
221
+
222
+ res.x = nc * Math.sin(lonrad);
223
+ res.y = (N * (1.0 - E2) + h) * slt;
224
+ res.z = nc * Math.cos(lonrad);
225
+
226
+ //let cosLat = Math.cos(lat * RADIANS)
227
+ //let sinLat = Math.sin(lat * RADIANS)
228
+
229
+ //let cosLong = Math.cos(lon * RADIANS)
230
+ //let sinLong = Math.sin(lon * RADIANS)
231
+
232
+ //let c = 1.0 / Math.sqrt(cosLat * cosLat + (1 - f) * (1 - f) * sinLat * sinLat)
233
+ //s = (1 - f) * (1 - f) * c
234
+
235
+ //x = (R*c + altitude) * cosLat * cosLong
236
+ //y = (R*c + altitude) * cosLat * sinLong
237
+ //z = (R*s + altitude) * sinLat
238
+ };
239
+
240
+ var lonLatToCartesianInverse = function (lon, lat, heightFactor, res){
241
+ lonLatToCartesian(
242
+ lon * INV_POLE_BY_180,
243
+ INV_PI_BY_360 * Math.atan(Math.exp(lat * PI_BY_POLE)) - INV_PI_BY_180_HALF_PI,
244
+ heightFactor,
245
+ res);
246
+ };
247
+
248
+ var v = new Vec3(0.0, 0.0, 0.0);
249
+ var _tempHigh = new Vec3(0.0, 0.0, 0.0);
250
+ var _tempLow = new Vec3(0.0, 0.0, 0.0);
251
+
252
+ var doubleToTwoFloats = function(v, high, low) {
253
+
254
+ let x = v.x, y = v.y, z = v.z;
255
+
256
+ if (x >= 0.0) {
257
+ var doubleHigh = Math.floor(x / 65536.0) * 65536.0;
258
+ high.x = Math.fround(doubleHigh);
259
+ low.x = Math.fround(x - doubleHigh);
260
+ } else {
261
+ var doubleHigh = Math.floor(-x / 65536.0) * 65536.0;
262
+ high.x = Math.fround(-doubleHigh);
263
+ low.x = Math.fround(x + doubleHigh);
264
+ }
265
+
266
+ if (y >= 0.0) {
267
+ var doubleHigh = Math.floor(y / 65536.0) * 65536.0;
268
+ high.y = Math.fround(doubleHigh);
269
+ low.y = Math.fround(y - doubleHigh);
270
+ } else {
271
+ var doubleHigh = Math.floor(-y / 65536.0) * 65536.0;
272
+ high.y = Math.fround(-doubleHigh);
273
+ low.y = Math.fround(y + doubleHigh);
274
+ }
275
+
276
+ if (z >= 0.0) {
277
+ var doubleHigh = Math.floor(z / 65536.0) * 65536.0;
278
+ high.z = Math.fround(doubleHigh);
279
+ low.z = Math.fround(z - doubleHigh);
280
+ } else {
281
+ var doubleHigh = Math.floor(-z / 65536.0) * 65536.0;
282
+ high.z = Math.fround(-doubleHigh);
283
+ low.z = Math.fround(z + doubleHigh);
284
+ }
285
+ };
286
+
287
+ self.onmessage = function (msg) {
288
+ if(msg.data.model) {
289
+ model = msg.data.model;
290
+ model.rawfile = msg.data.rawfile;
291
+ } else if(msg.data.params) {
292
+
293
+ let xmin = 549755748352.0, xmax = -549755748352.0,
294
+ ymin = 549755748352.0, ymax = -549755748352.0,
295
+ zmin = 549755748352.0, zmax = -549755748352.0;
296
+
297
+ E2 = msg.data.params[8];
298
+ A = msg.data.params[9];
299
+
300
+ let gridSize = msg.data.params[2],
301
+ fgs = msg.data.params[3],
302
+ r2_x = msg.data.params[10],
303
+ r2_y = msg.data.params[11],
304
+ r2_z = msg.data.params[12];
305
+
306
+ let heightFactor = msg.data.params[13];
307
+
308
+ if(msg.data.params[1] === 0.0){
309
+ _projFunc = lonLatToCartesianInverse;
310
+ }else{
311
+ _projFunc = lonLatToCartesian;
312
+ }
313
+
314
+ let maxFgs = Math.max(fgs, gridSize);
315
+ let llStep = (msg.data.params[6] - msg.data.params[4]) / maxFgs;
316
+ let ltStep = (msg.data.params[7] - msg.data.params[5]) / maxFgs;
317
+
318
+ let esw_lon = msg.data.params[4],
319
+ ene_lat = msg.data.params[7];
320
+
321
+ let dg = Math.max(fgs / gridSize, 1.0),
322
+ gs = maxFgs + 1;
323
+
324
+ const gsgs = gs * gs;
325
+
326
+ const gridSize3 = (gridSize + 1) * (gridSize + 1) * 3;
327
+
328
+ let plainNormals = new Float32Array(gridSize3);
329
+
330
+ let plainVertices = new Float64Array(gridSize3);
331
+ let plainVerticesHigh = new Float32Array(gridSize3);
332
+ let plainVerticesLow = new Float32Array(gridSize3);
333
+
334
+ let normalMapNormals = new Float32Array(gsgs * 3);
335
+
336
+ let normalMapVertices = new Float64Array(gsgs * 3);
337
+ let normalMapVerticesHigh = new Float32Array(gsgs * 3);
338
+ let normalMapVerticesLow = new Float32Array(gsgs * 3);
339
+
340
+ let ind = 0,
341
+ nmInd = 0;
342
+
343
+ for (let k = 0; k < gsgs; k++) {
344
+
345
+ let j = k % gs,
346
+ i = ~~(k / gs);
347
+
348
+ _projFunc(esw_lon + j * llStep, ene_lat - i * ltStep, heightFactor, v);
349
+
350
+ let nx = v.x * r2_x, ny = v.y * r2_y, nz = v.z * r2_z;
351
+ let l = 1.0 / Math.sqrt(nx * nx + ny * ny + nz * nz);
352
+ let nxl = nx * l,
353
+ nyl = ny * l,
354
+ nzl = nz * l;
355
+
356
+ doubleToTwoFloats(v, _tempHigh, _tempLow);
357
+
358
+ normalMapVertices[nmInd] = v.x;
359
+ normalMapVerticesHigh[nmInd] = _tempHigh.x;
360
+ normalMapVerticesLow[nmInd] = _tempLow.x;
361
+ normalMapNormals[nmInd++] = nxl;
362
+
363
+ normalMapVertices[nmInd] = v.y;
364
+ normalMapVerticesHigh[nmInd] = _tempHigh.y;
365
+ normalMapVerticesLow[nmInd] = _tempLow.y;
366
+ normalMapNormals[nmInd++] = nyl;
367
+
368
+ normalMapVertices[nmInd] = v.z;
369
+ normalMapVerticesHigh[nmInd] = _tempHigh.z;
370
+ normalMapVerticesLow[nmInd] = _tempLow.z;
371
+ normalMapNormals[nmInd++] = nzl;
372
+
373
+ if (i % dg === 0 && j % dg === 0) {
374
+ plainVertices[ind] = v.x;
375
+ plainVerticesHigh[ind] = _tempHigh.x;
376
+ plainVerticesLow[ind] = _tempLow.x;
377
+ plainNormals[ind++] = nxl;
378
+
379
+ plainVertices[ind] = v.y;
380
+ plainVerticesHigh[ind] = _tempHigh.y;
381
+ plainVerticesLow[ind] = _tempLow.y;
382
+ plainNormals[ind++] = nyl;
383
+
384
+ plainVertices[ind] = v.z;
385
+ plainVerticesHigh[ind] = _tempHigh.z;
386
+ plainVerticesLow[ind] = _tempLow.z;
387
+ plainNormals[ind++] = nzl;
388
+
389
+ if (v.x < xmin) xmin = v.x; if (v.x > xmax) xmax = v.x;
390
+ if (v.y < ymin) ymin = v.y; if (v.y > ymax) ymax = v.y;
391
+ if (v.z < zmin) zmin = v.z; if (v.z > zmax) zmax = v.z;
392
+ }
393
+ }
394
+
395
+ let x = (xmax - xmin) * 0.5,
396
+ y = (ymax - ymin) * 0.5,
397
+ z = (zmax - zmin) * 0.5;
398
+
399
+ let plainRadius = Math.sqrt(x * x + y * y + z * z);
400
+
401
+ self.postMessage({
402
+ id: msg.data.params[0],
403
+ plainVertices: plainVertices,
404
+ plainVerticesHigh: plainVerticesHigh,
405
+ plainVerticesLow: plainVerticesLow,
406
+ plainNormals: plainNormals,
407
+ normalMapNormals: normalMapNormals,
408
+ normalMapVertices: normalMapVertices,
409
+ normalMapVerticesHigh: normalMapVerticesHigh,
410
+ normalMapVerticesLow: normalMapVerticesLow,
411
+ plainRadius: plainRadius
412
+ }, [
413
+ plainVertices.buffer,
414
+ plainVerticesHigh.buffer,
415
+ plainVerticesLow.buffer,
416
+ plainNormals.buffer,
417
+ normalMapNormals.buffer,
418
+ normalMapVertices.buffer,
419
+ normalMapVerticesHigh.buffer,
420
+ normalMapVerticesLow.buffer
421
+ ]);
422
+ }
423
+ }`;
424
+
425
+ export { PlainSegmentWorker };