@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.
- package/css/og.css +1 -1
- package/package.json +4 -4
- package/src/og/Extent.js +274 -273
- package/src/og/Globe.js +11 -3
- package/src/og/LonLat.js +148 -147
- package/src/og/camera/PlanetCamera.js +110 -38
- package/src/og/control/EarthNavigation.js +259 -0
- package/src/og/control/MouseNavigation.js +68 -40
- package/src/og/layer/KML.js +157 -0
- package/src/og/quadTree/Node.js +8 -8
- package/src/og/quadTree/quadTree.js +22 -18
- package/src/og/renderer/RendererEvents.js +21 -16
- package/src/og/scene/Planet.js +12 -7
- package/src/og/segment/Segment.js +2 -4
- package/src/og/utils/FontAtlas.js +1 -0
- package/src/og/{segment → utils}/PlainSegmentWorker.js +425 -407
- package/src/og/webgl/Handler.js +866 -845
|
@@ -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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
let
|
|
121
|
-
let
|
|
122
|
-
let
|
|
123
|
-
let
|
|
124
|
-
let
|
|
125
|
-
let
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
var
|
|
156
|
-
var
|
|
157
|
-
var
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
var
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const
|
|
191
|
-
const
|
|
192
|
-
const
|
|
193
|
-
const
|
|
194
|
-
const
|
|
195
|
-
const
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
this.
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
let
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
let
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
res.
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
var doubleHigh = Math.floor(
|
|
262
|
-
high.
|
|
263
|
-
low.
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
let
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
let
|
|
315
|
-
|
|
316
|
-
let
|
|
317
|
-
|
|
318
|
-
let
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
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 };
|