-
Notifications
You must be signed in to change notification settings - Fork 1
/
DUMP_OBJ_CITY_NOASYNC.js
701 lines (598 loc) · 36 KB
/
DUMP_OBJ_CITY_NOASYNC.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
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
262
263
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
"use strict"
const fs = require('fs-extra');
const path = require('path');
const decodeTexture = require('./lib/decode-texture');
/**************************** config ****************************/
const PLANET = 'earth';
const URL_PREFIX = `https://kh.google.com/rt/${PLANET}/`;
//Keep an eye on the directory paths because they might change during git push...
const DL_DIR = './downloaded_files';
const [ DUMP_NEW_NEW_DIR, DUMP_NEW_DIR, DUMP_NEW_DIR_UTRECHT, DUMP_NEW_DIR_RIO, DUMP_NEW_DIR_MIAMI, DUMP_NEW_DIR_AZORES, DUMP_NEW_DIR_DENHAAG, DUMP_NEW_DIR_SCHWEIZ, DUMP_NEW_DIR_NEWYORK, DUMP_NEW_DIR_BRUSSEL, DUMP_NEW_DIR_ENSCHEDE, DUMP_NEW_DIR_LA, DUMP_NEW_DIR_AMSTERDAM, DUMP_OBJ_DIR, DUMP_JSON_DIR, DUMP_RAW_DIR ] =
[ 'new/new', 'new', 'new/Utrecht', 'new/Rio', 'new/Miami', 'new/Azores', 'new/DenHaag', 'new/Schweiz', 'new/NewYork', 'new/Brussel', 'new/Enschede', 'new/LA', 'new/Amsterdam', 'obj_new', 'json', 'raw' ].map(x => path.join(DL_DIR, x));
const DL_DIR1 = 'G:/PACMAN/EARTH/downloaded_files';
const [ DUMP_NEW_NEW_DIR1, DUMP_NEW_DIR1, DUMP_NEW_DIR_UTRECHT1, DUMP_NEW_DIR_RIO1, DUMP_NEW_DIR_MIAMI1, DUMP_NEW_DIR_AZORES1, DUMP_NEW_DIR_DENHAAG1, DUMP_NEW_DIR_SCHWEIZ1, DUMP_NEW_DIR_NEWYORK1, DUMP_NEW_DIR_BRUSSEL1, DUMP_NEW_DIR_ENSCHEDE1, DUMP_NEW_DIR_LA1, DUMP_NEW_DIR_AMSTERDAM1, DUMP_OBJ_DIR1, DUMP_JSON_DIR1, DUMP_RAW_DIR1 ] =
[ 'new/new', 'new', 'new/Utrecht', 'new/Rio', 'new/Miami', 'new/Azores', 'new/DenHaag', 'new/Schweiz', 'new/NewYork', 'new/Brussel', 'new/Enschede', 'new/LA', 'new/Amsterdam', 'obj', 'json', 'raw' ].map(x => path.join(DL_DIR1, x));
const DL_DIR2 = 'E:/PACMAN/EARTH/downloaded_files';
const [ DUMP_NEW_NEW_DIR2, DUMP_NEW_DIR2, DUMP_NEW_DIR_UTRECHT2, DUMP_NEW_DIR_RIO2, DUMP_NEW_DIR_MIAMI2, DUMP_NEW_DIR_AZORES2, DUMP_NEW_DIR_DENHAAG2, DUMP_NEW_DIR_SCHWEIZ2, DUMP_NEW_DIR_NEWYORK2, DUMP_NEW_DIR_BRUSSEL2, DUMP_NEW_DIR_ENSCHEDE2, DUMP_NEW_DIR_LA2, DUMP_NEW_DIR_AMSTERDAM2, DUMP_OBJ_DIR2, DUMP_JSON_DIR2, DUMP_RAW_DIR2 ] =
[ 'new/new', 'new', 'new/Utrecht', 'new/Rio', 'new/Miami', 'new/Azores', 'new/DenHaag', 'new/Schweiz', 'new/NewYork', 'new/Brussel', 'new/Enschede', 'new/LA', 'new/Amsterdam', 'obj', 'json', 'raw' ].map(x => path.join(DL_DIR2, x));
const DL_DIR3 = 'E:/PACMAN/EARTH/downloaded_files';
const [ DUMP_NEW_NEW_DIR3, DUMP_NEW_DIR3, DUMP_NEW_DIR_UTRECHT3, DUMP_NEW_DIR_RIO3, DUMP_NEW_DIR_MIAMI3, DUMP_NEW_DIR_AZORES3, DUMP_NEW_DIR_DENHAAG3, DUMP_NEW_DIR_SCHWEIZ3, DUMP_NEW_DIR_NEWYORK3, DUMP_NEW_DIR_BRUSSEL3, DUMP_NEW_DIR_ENSCHEDE3, DUMP_NEW_DIR_LA3, DUMP_NEW_DIR_AMSTERDAM3, DUMP_OBJ_DIR3, DUMP_JSON_DIR3, DUMP_RAW_DIR3 ] =
[ 'new/new', 'new', 'new/Utrecht', 'new/Rio', 'new/Miami', 'new/Azores', 'new/DenHaag', 'new/Schweiz', 'new/NewYork', 'new/Brussel', 'new/Enschede', 'new/LA', 'new/Amsterdam', 'obj', 'json', 'raw' ].map(x => path.join(DL_DIR3, x));
const { OCTANTS, MAX_LEVEL, CITYNAME, DUMP_JSON, DUMP_RAW, PARALLEL_SEARCH } = require('./lib/parse-command-line2')(__filename);
const DUMP_OBJ = !(DUMP_JSON || DUMP_RAW);
/****************************************************************/
const { getPlanetoid, getBulk, getNode, bulk: { getIndexByPath, hasBulkMetadataAtIndex, hasNodeAtIndex } } = require('./lib/utils')({
URL_PREFIX, DUMP_JSON_DIR, DUMP_RAW_DIR, DUMP_JSON, DUMP_RAW
});
/***************************** main *****************************/
async function pathExists (pad) {
return fs.access(pad).then(() => 1).catch(() => 0)
}
var offset_x=0.0;
var offset_y=0.0;
var offset_z=0.0;
var max_x_x=0.0; var max_x_y=0.0; var max_x_z=0.0;
var max_y_x=0.0; var max_y_y=0.0; var max_y_z=0.0;
var max_z_x=0.0; var max_z_y=0.0; var max_z_z=0.0;
var min_x_x=0.0; var min_x_y=0.0; var min_x_z=0.0;
var min_y_x=0.0; var min_y_y=0.0; var min_y_z=0.0;
var min_z_x=0.0; var min_z_y=0.0; var min_z_z=0.0;
let num_vertices=0;
let num_objects=0;
let num_normals=0;
let num_faces=0;
let num_materials=0;
async function run() {
// console.log(CITYNAME[0]);
const subdir = `${OCTANTS}`.substr(0,14);
const newDir = path.join(DUMP_NEW_DIR, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newnewDir = path.join(DUMP_NEW_NEW_DIR, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_AMSTERDAM = path.join(DUMP_NEW_DIR_AMSTERDAM, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_RIO = path.join(DUMP_NEW_DIR_RIO, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_UTRECHT = path.join(DUMP_NEW_DIR_UTRECHT, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_BRUSSEL = path.join(DUMP_NEW_DIR_BRUSSEL, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_ENSCHEDE = path.join(DUMP_NEW_DIR_ENSCHEDE, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_LA = path.join(DUMP_NEW_DIR_LA, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_NEWYORK = path.join(DUMP_NEW_DIR_NEWYORK, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_MIAMI = path.join(DUMP_NEW_DIR_MIAMI, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_DENHAAG = path.join(DUMP_NEW_DIR_DENHAAG, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_SCHWEIZ = path.join(DUMP_NEW_DIR_SCHWEIZ, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_AZORES = path.join(DUMP_NEW_DIR_AZORES, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const objDir = path.join(DUMP_OBJ_DIR, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_RIOb = path.join(DUMP_NEW_DIR_RIO, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_AMSTERDAMb = path.join(DUMP_NEW_DIR_AMSTERDAM, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_UTRECHTb = path.join(DUMP_NEW_DIR_UTRECHT, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_BRUSSELb = path.join(DUMP_NEW_DIR_BRUSSEL, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_ENSCHEDEb = path.join(DUMP_NEW_DIR_ENSCHEDE, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_LAb = path.join(DUMP_NEW_DIR_LA, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_NEWYORKb = path.join(DUMP_NEW_DIR_NEWYORK, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_MIAMIb = path.join(DUMP_NEW_DIR_MIAMI, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_DENHAAGb = path.join(DUMP_NEW_DIR_DENHAAG, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_AZORESb = path.join(DUMP_NEW_DIR_AZORES, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_SCHWEIZb = path.join(DUMP_NEW_DIR_SCHWEIZ, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir1 = path.join(DUMP_NEW_DIR1, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newnewDir1 = path.join(DUMP_NEW_NEW_DIR1, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_BRUSSEL1 = path.join(DUMP_NEW_DIR_BRUSSEL1, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_ENSCHEDE1 = path.join(DUMP_NEW_DIR_ENSCHEDE1, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_LA1 = path.join(DUMP_NEW_DIR_LA1, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_AMSTERDAM1 = path.join(DUMP_NEW_DIR_AMSTERDAM1, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_RIO1 = path.join(DUMP_NEW_DIR_RIO1, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_UTRECHT1 = path.join(DUMP_NEW_DIR_UTRECHT1, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_NEWYORK1 = path.join(DUMP_NEW_DIR_NEWYORK1, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_MIAMI1 = path.join(DUMP_NEW_DIR_MIAMI1, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_DENHAAG1 = path.join(DUMP_NEW_DIR_DENHAAG1, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_SCHWEIZ1 = path.join(DUMP_NEW_DIR_SCHWEIZ1, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_AZORES1 = path.join(DUMP_NEW_DIR_AZORES1, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const objDir1 = path.join(DUMP_OBJ_DIR1, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_AMSTERDAMb1= path.join(DUMP_NEW_DIR_AMSTERDAM1, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_RIOb1 = path.join(DUMP_NEW_DIR_RIO1, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_UTRECHTb1 = path.join(DUMP_NEW_DIR_UTRECHT1, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_BRUSSELb1 = path.join(DUMP_NEW_DIR_BRUSSEL1, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_ENSCHEDEb1 = path.join(DUMP_NEW_DIR_ENSCHEDE1, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_LAb1 = path.join(DUMP_NEW_DIR_LA1, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_NEWYORKb1 = path.join(DUMP_NEW_DIR_NEWYORK1, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_MIAMIb1 = path.join(DUMP_NEW_DIR_MIAMI1, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_DENHAAGb1 = path.join(DUMP_NEW_DIR_DENHAAG1, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_SCHWEIZb1 = path.join(DUMP_NEW_DIR_SCHWEIZ1, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_AZORESb1 = path.join(DUMP_NEW_DIR_AZORES1, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir2 = path.join(DUMP_NEW_DIR2, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newnewDir2 = path.join(DUMP_NEW_NEW_DIR2, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_BRUSSEL2 = path.join(DUMP_NEW_DIR_BRUSSEL2, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_ENSCHEDE2 = path.join(DUMP_NEW_DIR_ENSCHEDE2, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_LA2 = path.join(DUMP_NEW_DIR_LA2, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_AMSTERDAM2 = path.join(DUMP_NEW_DIR_AMSTERDAM2, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_RIO2 = path.join(DUMP_NEW_DIR_RIO2, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_UTRECHT2 = path.join(DUMP_NEW_DIR_UTRECHT2, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_NEWYORK2 = path.join(DUMP_NEW_DIR_NEWYORK2, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_MIAMI2 = path.join(DUMP_NEW_DIR_MIAMI2, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_DENHAAG2 = path.join(DUMP_NEW_DIR_DENHAAG2, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_SCHWEIZ2 = path.join(DUMP_NEW_DIR_SCHWEIZ2, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_AZORES2 = path.join(DUMP_NEW_DIR_AZORES2, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const objDir2 = path.join(DUMP_OBJ_DIR2, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_AMSTERDAMb2= path.join(DUMP_NEW_DIR_AMSTERDAM2, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_RIOb2 = path.join(DUMP_NEW_DIR_RIO2, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_UTRECHTb2 = path.join(DUMP_NEW_DIR_UTRECHT2, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_BRUSSELb2 = path.join(DUMP_NEW_DIR_BRUSSEL2, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_ENSCHEDEb2 = path.join(DUMP_NEW_DIR_ENSCHEDE2, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_LAb2 = path.join(DUMP_NEW_DIR_LA2, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_NEWYORKb2 = path.join(DUMP_NEW_DIR_NEWYORK2, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_MIAMIb2 = path.join(DUMP_NEW_DIR_MIAMI2, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_DENHAAGb2 = path.join(DUMP_NEW_DIR_DENHAAG2, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_SCHWEIZb2 = path.join(DUMP_NEW_DIR_SCHWEIZ2, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_AZORESb2 = path.join(DUMP_NEW_DIR_AZORES2, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir3 = path.join(DUMP_NEW_DIR3, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newnewDir3 = path.join(DUMP_NEW_NEW_DIR3, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_BRUSSEL3 = path.join(DUMP_NEW_DIR_BRUSSEL3, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_ENSCHEDE3 = path.join(DUMP_NEW_DIR_ENSCHEDE3, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_LA3 = path.join(DUMP_NEW_DIR_LA3, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_AMSTERDAM3 = path.join(DUMP_NEW_DIR_AMSTERDAM3, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_RIO3 = path.join(DUMP_NEW_DIR_RIO3, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_UTRECHT3 = path.join(DUMP_NEW_DIR_UTRECHT3, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_NEWYORK3 = path.join(DUMP_NEW_DIR_NEWYORK3, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_MIAMI3 = path.join(DUMP_NEW_DIR_MIAMI3, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_DENHAAG3 = path.join(DUMP_NEW_DIR_DENHAAG3, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_SCHWEIZ3 = path.join(DUMP_NEW_DIR_SCHWEIZ3, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_AZORES3 = path.join(DUMP_NEW_DIR_AZORES3, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const objDir3 = path.join(DUMP_OBJ_DIR3, `${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_AMSTERDAMb3= path.join(DUMP_NEW_DIR_AMSTERDAM3, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_RIOb3 = path.join(DUMP_NEW_DIR_RIO3, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_UTRECHTb3 = path.join(DUMP_NEW_DIR_UTRECHT3, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_BRUSSELb3 = path.join(DUMP_NEW_DIR_BRUSSEL3, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_ENSCHEDEb3 = path.join(DUMP_NEW_DIR_ENSCHEDE3, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_LAb3 = path.join(DUMP_NEW_DIR_LA3, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_NEWYORKb3 = path.join(DUMP_NEW_DIR_NEWYORK3, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_MIAMIb3 = path.join(DUMP_NEW_DIR_MIAMI3, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_DENHAAGb3 = path.join(DUMP_NEW_DIR_DENHAAG3, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_SCHWEIZb3 = path.join(DUMP_NEW_DIR_SCHWEIZ3, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
const newDir_AZORESb3 = path.join(DUMP_NEW_DIR_AZORES3, `${subdir}/${OCTANTS.join('+')}-${MAX_LEVEL}`);
if (DUMP_OBJ) {
if (fs.existsSync(newDir) ) { console.log('exists in: ' + newDir); return; }
else if (fs.existsSync(newnewDir) ) { console.log('exists in: ' + newnewDir); return; }
else if (fs.existsSync(newDir_AMSTERDAM) ) { console.log('exists in: ' + newDir_AMSTERDAM); return; }
else if (fs.existsSync(newDir_RIO) ) { console.log('exists in: ' + newDir_RIO); return; }
else if (fs.existsSync(newDir_UTRECHT) ) { console.log('exists in: ' + newDir_UTRECHT); return; }
else if (fs.existsSync(newDir_BRUSSEL) ) { console.log('exists in: ' + newDir_BRUSSEL); return; }
else if (fs.existsSync(newDir_ENSCHEDE) ) { console.log('exists in: ' + newDir_ENSCHEDE); return; }
else if (fs.existsSync(newDir_LA) ) { console.log('exists in: ' + newDir_LA); return; }
else if (fs.existsSync(newDir_NEWYORK) ) { console.log('exists in: ' + newDir_NEWYORK); return; }
else if (fs.existsSync(newDir_MIAMI) ) { console.log('exists in: ' + newDir_MIAMI); return; }
else if (fs.existsSync(newDir_DENHAAG) ) { console.log('exists in: ' + newDir_DENHAAG); return; }
else if (fs.existsSync(newDir_SCHWEIZ) ) { console.log('exists in: ' + newDir_SCHWEIZ); return; }
else if (fs.existsSync(newDir_AZORES) ) { console.log('exists in: ' + newDir_AZORES); return; }
else if (fs.existsSync(objDir)) { console.log('exists in: ' + objDir); return; }
else if (fs.existsSync(newDir_AMSTERDAMb) ) { console.log('exists in: ' + newDir_AMSTERDAMb); return; }
else if (fs.existsSync(newDir_RIOb) ) { console.log('exists in: ' + newDir_RIOb); return; }
else if (fs.existsSync(newDir_UTRECHTb) ) { console.log('exists in: ' + newDir_UTRECHTb); return; }
else if (fs.existsSync(newDir_BRUSSELb) ) { console.log('exists in: ' + newDir_BRUSSELb); return; }
else if (fs.existsSync(newDir_ENSCHEDEb) ) { console.log('exists in: ' + newDir_ENSCHEDEb); return; }
else if (fs.existsSync(newDir_LAb) ) { console.log('exists in: ' + newDir_LAb); return; }
else if (fs.existsSync(newDir_NEWYORKb) ) { console.log('exists in: ' + newDir_NEWYORKb); return; }
else if (fs.existsSync(newDir_MIAMIb) ) { console.log('exists in: ' + newDir_MIAMIb); return; }
else if (fs.existsSync(newDir_DENHAAGb) ) { console.log('exists in: ' + newDir_DENHAAGb); return; }
else if (fs.existsSync(newDir_SCHWEIZb) ) { console.log('exists in: ' + newDir_SCHWEIZb); return; }
else if (fs.existsSync(newDir_AZORESb) ) { console.log('exists in: ' + newDir_AZORESb); return; }
// else { console.log('not exist: ' + objDir); }
// else { console.log('not exist: ' + DL_DIR); }
if (fs.existsSync(newDir1) ) { console.log('exists in: ' + newDir1); return; }
else if (fs.existsSync(newnewDir1) ) { console.log('exists in: ' + newnewDir1); return; }
else if (fs.existsSync(newDir_BRUSSEL1) ) { console.log('exists in: ' + newDir_BRUSSEL1); return; }
else if (fs.existsSync(newDir_ENSCHEDE1) ) { console.log('exists in: ' + newDir_ENSCHEDE1); return; }
else if (fs.existsSync(newDir_LA1) ) { console.log('exists in: ' + newDir_LA1); return; }
else if (fs.existsSync(newDir_AMSTERDAM1) ) { console.log('exists in: ' + newDir_AMSTERDAM1); return; }
else if (fs.existsSync(newDir_RIO1) ) { console.log('exists in: ' + newDir_RIO1); return; }
else if (fs.existsSync(newDir_UTRECHT1) ) { console.log('exists in: ' + newDir_UTRECHT1); return; }
else if (fs.existsSync(newDir_NEWYORK1) ) { console.log('exists in: ' + newDir_NEWYORK1); return; }
else if (fs.existsSync(newDir_MIAMI1) ) { console.log('exists in: ' + newDir_MIAMI1); return; }
else if (fs.existsSync(newDir_DENHAAG1) ) { console.log('exists in: ' + newDir_DENHAAG1); return; }
else if (fs.existsSync(newDir_SCHWEIZ1) ) { console.log('exists in: ' + newDir_SCHWEIZ1); return; }
else if (fs.existsSync(newDir_AZORES1) ) { console.log('exists in: ' + newDir_AZORES1); return; }
else if (fs.existsSync(objDir1)) { console.log('exists in: ' + objDir1); return; }
else if (fs.existsSync(newDir_AMSTERDAMb1) ){ console.log('exists in: ' + newDir_AMSTERDAMb1);return; }
else if (fs.existsSync(newDir_RIOb1) ) { console.log('exists in: ' + newDir_RIOb1); return; }
else if (fs.existsSync(newDir_UTRECHTb1) ) { console.log('exists in: ' + newDir_UTRECHTb1); return; }
else if (fs.existsSync(newDir_BRUSSELb1) ) { console.log('exists in: ' + newDir_BRUSSELb1); return; }
else if (fs.existsSync(newDir_ENSCHEDEb1) ) { console.log('exists in: ' + newDir_ENSCHEDEb1); return; }
else if (fs.existsSync(newDir_LAb1) ) { console.log('exists in: ' + newDir_LAb1); return; }
else if (fs.existsSync(newDir_NEWYORKb1) ) { console.log('exists in: ' + newDir_NEWYORKb1); return; }
else if (fs.existsSync(newDir_MIAMIb1) ) { console.log('exists in: ' + newDir_MIAMIb1); return; }
else if (fs.existsSync(newDir_DENHAAGb1) ) { console.log('exists in: ' + newDir_DENHAAGb1); return; }
else if (fs.existsSync(newDir_SCHWEIZb1) ) { console.log('exists in: ' + newDir_SCHWEIZb1); return; }
else if (fs.existsSync(newDir_AZORESb1) ) { console.log('exists in: ' + newDir_AZORESb1); return; }
// else { console.log('not exist: ' + objDir1); }
// else { console.log('not exist: ' + DL_DIR1); }
if (fs.existsSync(newDir2) ) { console.log('exists in: ' + newDir2); return; }
else if (fs.existsSync(newnewDir2) ) { console.log('exists in: ' + newnewDir2); return; }
else if (fs.existsSync(newDir_BRUSSEL2) ) { console.log('exists in: ' + newDir_BRUSSEL2); return; }
else if (fs.existsSync(newDir_ENSCHEDE2) ) { console.log('exists in: ' + newDir_ENSCHEDE2); return; }
else if (fs.existsSync(newDir_LA2) ) { console.log('exists in: ' + newDir_LA2); return; }
else if (fs.existsSync(newDir_AMSTERDAM2) ) { console.log('exists in: ' + newDir_AMSTERDAM2); return; }
else if (fs.existsSync(newDir_RIO2) ) { console.log('exists in: ' + newDir_RIO2); return; }
else if (fs.existsSync(newDir_UTRECHT2) ) { console.log('exists in: ' + newDir_UTRECHT2); return; }
else if (fs.existsSync(newDir_NEWYORK2) ) { console.log('exists in: ' + newDir_NEWYORK2); return; }
else if (fs.existsSync(newDir_MIAMI2) ) { console.log('exists in: ' + newDir_MIAMI2); return; }
else if (fs.existsSync(newDir_DENHAAG2) ) { console.log('exists in: ' + newDir_DENHAAG2); return; }
else if (fs.existsSync(newDir_SCHWEIZ2) ) { console.log('exists in: ' + newDir_SCHWEIZ2); return; }
else if (fs.existsSync(newDir_AZORES2) ) { console.log('exists in: ' + newDir_AZORES2); return; }
else if (fs.existsSync(objDir2)) { console.log('exists in: ' + objDir2); return; }
else if (fs.existsSync(newDir_AMSTERDAMb2) ){ console.log('exists in: ' + newDir_AMSTERDAMb2);return; }
else if (fs.existsSync(newDir_RIOb2) ) { console.log('exists in: ' + newDir_RIOb2); return; }
else if (fs.existsSync(newDir_UTRECHTb2) ) { console.log('exists in: ' + newDir_UTRECHTb2); return; }
else if (fs.existsSync(newDir_BRUSSELb2) ) { console.log('exists in: ' + newDir_BRUSSELb2); return; }
else if (fs.existsSync(newDir_ENSCHEDEb2) ) { console.log('exists in: ' + newDir_ENSCHEDEb2); return; }
else if (fs.existsSync(newDir_LAb2) ) { console.log('exists in: ' + newDir_LAb2); return; }
else if (fs.existsSync(newDir_NEWYORKb2) ) { console.log('exists in: ' + newDir_NEWYORKb2); return; }
else if (fs.existsSync(newDir_MIAMIb2) ) { console.log('exists in: ' + newDir_MIAMIb2); return; }
else if (fs.existsSync(newDir_DENHAAGb2) ) { console.log('exists in: ' + newDir_DENHAAGb2); return; }
else if (fs.existsSync(newDir_SCHWEIZb2) ) { console.log('exists in: ' + newDir_SCHWEIZb2); return; }
else if (fs.existsSync(newDir_AZORESb2) ) { console.log('exists in: ' + newDir_AZORESb2); return; }
// else { console.log('not exist: ' + objDir2); }
// else { console.log('not exist: ' + DL_DIR2); }
if (fs.existsSync(newDir3) ) { console.log('exists in: ' + newDir3); return; }
else if (fs.existsSync(newnewDir3) ) { console.log('exists in: ' + newnewDir3); return; }
else if (fs.existsSync(newDir_BRUSSEL3) ) { console.log('exists in: ' + newDir_BRUSSEL3); return; }
else if (fs.existsSync(newDir_ENSCHEDE3) ) { console.log('exists in: ' + newDir_ENSCHEDE3); return; }
else if (fs.existsSync(newDir_LA3) ) { console.log('exists in: ' + newDir_LA3); return; }
else if (fs.existsSync(newDir_RIO3) ) { console.log('exists in: ' + newDir_RIO3); return; }
else if (fs.existsSync(newDir_AMSTERDAM3) ) { console.log('exists in: ' + newDir_AMSTERDAM3); return; }
else if (fs.existsSync(newDir_UTRECHT3) ) { console.log('exists in: ' + newDir_UTRECHT3); return; }
else if (fs.existsSync(newDir_NEWYORK3) ) { console.log('exists in: ' + newDir_NEWYORK3); return; }
else if (fs.existsSync(newDir_MIAMI3) ) { console.log('exists in: ' + newDir_MIAMI3); return; }
else if (fs.existsSync(newDir_DENHAAG3) ) { console.log('exists in: ' + newDir_DENHAAG3); return; }
else if (fs.existsSync(newDir_SCHWEIZ3) ) { console.log('exists in: ' + newDir_SCHWEIZ3); return; }
else if (fs.existsSync(newDir_AZORES3) ) { console.log('exists in: ' + newDir_AZORES3); return; }
else if (fs.existsSync(objDir3)) { console.log('exists in: ' + objDir3); return; }
else if (fs.existsSync(newDir_AMSTERDAMb3) ){ console.log('exists in: ' + newDir_AMSTERDAMb3);return; }
else if (fs.existsSync(newDir_RIOb3) ) { console.log('exists in: ' + newDir_RIOb3); return; }
else if (fs.existsSync(newDir_UTRECHTb3) ) { console.log('exists in: ' + newDir_UTRECHTb3); return; }
else if (fs.existsSync(newDir_BRUSSELb3) ) { console.log('exists in: ' + newDir_BRUSSELb3); return; }
else if (fs.existsSync(newDir_ENSCHEDEb3) ) { console.log('exists in: ' + newDir_ENSCHEDEb3); return; }
else if (fs.existsSync(newDir_LAb3) ) { console.log('exists in: ' + newDir_LAb3); return; }
else if (fs.existsSync(newDir_NEWYORKb3) ) { console.log('exists in: ' + newDir_NEWYORKb3); return; }
else if (fs.existsSync(newDir_MIAMIb3) ) { console.log('exists in: ' + newDir_MIAMIb3); return; }
else if (fs.existsSync(newDir_DENHAAGb3) ) { console.log('exists in: ' + newDir_DENHAAGb3); return; }
else if (fs.existsSync(newDir_SCHWEIZb3) ) { console.log('exists in: ' + newDir_SCHWEIZb3); return; }
else if (fs.existsSync(newDir_AZORESb3) ) { console.log('exists in: ' + newDir_AZORESb3); return; }
// else { console.log('not exist: ' + objDir3); }
// else { console.log('not exist: ' + DL_DIR3); }
}
if (CITYNAME[0]=="--ENSCHEDE") { offset_x=3875099.0; offset_y=468154.0; offset_z=5035344.0; }
else if (CITYNAME[0]=="--UTRECHT") { offset_x=3899275.0; offset_y=348997.0; offset_z=5026376.0; }
else if (CITYNAME[0]=="--AMSTERDAM") { offset_x=3876534.0; offset_y=331582.0; offset_z=5045027.0; }
//planet_037062636161604273407_0 4279407.080373702 -4011609.541706613 -2486650.8940397883
else if (CITYNAME[0]=="--RIO") { offset_x=4279407; offset_y=-4011609; offset_z=-2486650; }
else if (CITYNAME[0]=="--BRUSSEL") { offset_x=4014897.0; offset_y=296156.0; offset_z=4937953.0; }
else if (CITYNAME[0]=="--LA") { offset_x=-2490962; offset_y=-4656517; offset_z=3564040; }
else if (CITYNAME[0]=="--NEWYORK") { offset_x=1323854.370856056; offset_y=-4649129.837542839; offset_z=4150030.4071031474; }
else if (CITYNAME[0]=="--JOCELYN") { offset_x=-3151877; offset_y=5289017; offset_z=1637629; }
else if (CITYNAME[0]=="--MIAMI") { offset_x=975859; offset_y=-5652918; offset_z=2771644; }
else if (CITYNAME[0]=="--DENHAAG") { offset_x=3904479.2616487066; offset_y=294625.81305996777; offset_z=5025795.962117693; }
else if (CITYNAME[0]=="--SCHWEIZ") { offset_x=4386153.408482799; offset_y=576284.5001272303; offset_z=4587395.669652603; }
else if (CITYNAME[0]=="--AZORES") { offset_x=4547134.555436776; offset_y=-2165128.87501796; offset_z=3903020.5406996952; }
else {
console.log('NO OFFSET DATA!!! ');
return false;
}
console.log("OFFSET X="+offset_x);
console.log("OFFSET Y="+offset_y);
console.log("OFFSET Z="+offset_z);
const planetoid = await getPlanetoid();
const rootEpoch = planetoid.bulkMetadataEpoch[0];
max_x_x=-9999999999999999.9;
max_y_y=-9999999999999999.9;
max_z_z=-9999999999999999.9;
min_x_x=9999999999999999.9;
min_y_y=9999999999999999.9;
min_z_z=9999999999999999.9;
let data_file="";
let objCtx;
if (DUMP_OBJ) {
fs.removeSync(objDir);
fs.ensureDirSync(objDir);
objCtx = initCtxOBJ(objDir);
}
let num_octants = 0;
let num_downloaded = 0;
const search = initNodeSearch(rootEpoch, PARALLEL_SEARCH ? 8 : 1,
function nodeFound(path) {
num_octants++;
console.log( num_downloaded.toString().padStart(3, ' ') + '/' + num_octants.toString().padStart(3, ' ') + ' found ', path );
},
function nodeDownloaded(path, node, octantsToExclude) {
DUMP_OBJ && writeNodeOBJ(objCtx, node, path, octantsToExclude);
num_downloaded++;
console.log( num_downloaded.toString().padStart(3, ' ') + '/' + num_octants.toString().padStart(3, ' ') + ' downloaded', path );
}
);
for (const oct of OCTANTS) {
await search(oct, MAX_LEVEL);
}
data_file=
"MIN X: X="+min_x_x+" Y="+min_x_y+" Z="+min_x_z+"\n"+
"MIN Y: X="+min_y_x+" Y="+min_y_y+" Z="+min_y_z+"\n"+
"MIN Z: X="+min_z_x+" Y="+min_z_y+" Z="+min_z_z+"\n"+
"MAX X: X="+max_x_x+" Y="+max_x_y+" Z="+max_x_z+"\n"+
"MAX Y: X="+max_y_x+" Y="+max_y_y+" Z="+max_y_z+"\n"+
"MAX Z: X="+max_z_x+" Y="+max_z_y+" Z="+max_z_z+"\n"+
"VERTICES="+num_vertices+"\n"+
"OBJECTS="+num_objects+"\n"+
"NORMALS="+num_normals+"\n"+
"FACES="+num_faces+"\n"+
"MATERIALS="+num_materials+"\n";
fs.writeFileSync(path.join(objCtx.objDir, OCTANTS+'.dat'), data_file);
console.log('octants', num_octants)
// console.log('.3');
return
}
/****************************************************************/
/**************************** search ****************************/
function initNodeSearch(rootEpoch, numParallelBranches = 1, nodeFound = null, nodeDownloaded = null) {
const sem = semaphore(numParallelBranches - 1);
return async function search(k, maxLevel = 999) {
if (k.length > maxLevel) return false;
let check;
try {
check = await checkNodeAtNodePath(rootEpoch, k);
if (check === null) return false;
} catch (ex) {
console.error(ex);
return false;
}
try {
nodeFound && nodeFound(k);
} catch (ex) {
console.error('Unhandled nodeFound callback error', ex);
return false;
}
const [promises, results] = [[], []];
for (const oct of [0, 1, 2, 3, 4, 5, 6, 7]) {
promises.push((async function fn() {
try {
results.push({ oct, res: await search(k + oct, maxLevel) });
if (results.length === 8) {
const octs = results.filter(({ res }) => res).map(({ oct }) => oct)
const node = await getNode(k, check.bulk, check.index);
try {
nodeDownloaded && nodeDownloaded(k, node, octs);
} catch (ex) {
console.error('Unhandled nodeDownload callback error');
throw ex;
}
}
} finally {
await new Promise((r, _) => setImmediate(r));
sem.signal();
}
})());
await sem.wait(true);
}
try {
await Promise.all(promises);
} catch (ex) {
console.error(ex);
return false;
}
return true;
};
}
async function checkNodeAtNodePath(rootEpoch, nodePath) {
let bulk = null, index = -1;
for (let epoch = rootEpoch, i = 4; i < nodePath.length + 4; i += 4) {
const bulkPath = nodePath.substring(0, i - 4);
const subPath = nodePath.substring(0, i);
if (bulk) {
const idx = getIndexByPath(bulk, bulkPath);
if (hasBulkMetadataAtIndex(bulk, idx)) return null;
}
const nextBulk = await getBulk(bulkPath, epoch);
bulk = nextBulk;
index = getIndexByPath(bulk, subPath);
epoch = bulk.bulkMetadataEpoch[index];
}
if (index < 0) return null;
if (!hasNodeAtIndex(bulk, index)) return null;
return { bulk, index };
}
/****************************************************************/
/**************************** export ****************************/
function initCtxOBJ(dir) {
fs.writeFileSync(path.join(dir, OCTANTS+'.obj'), 'mtllib ' + OCTANTS + '.mtl\n');
console.log('found ', dir);
return { objDir: dir, c_v: 0, c_n: 0, c_u: 0 };
}
function writeNodeOBJ(ctx, node, nodeName, exclude) {
for (const [meshIndex, mesh] of Object.entries(node.meshes)) {
const meshName = `${nodeName}_${meshIndex}`;
const tex = mesh.texture;
const texName = `tex_${nodeName}_${meshIndex}`;
const obj = writeMeshOBJ(ctx, meshName, texName, node, mesh, exclude);
fs.appendFileSync(path.join(ctx.objDir, OCTANTS+'.obj'), obj);
num_objects=num_objects+1;
num_materials=num_materials+1;
const { buffer: buf, extension: ext } = decodeTexture(tex);
fs.appendFileSync(path.join(ctx.objDir, OCTANTS+'.mtl'), `
newmtl ${texName}
Ka 1.000000 1.000000 1.000000
Kd 1.000000 1.000000 1.000000
Ks 0.000000 0.000000 0.000000
Tr 1.000000
illum 1
Ns 0.000000
map_Kd ${texName}.${ext}
`.split('\n').map(s => s.trim()).join('\n'));
fs.writeFileSync(path.join(ctx.objDir, `${texName}.${ext}`), buf);
}
}
function writeMeshOBJ(ctx, meshName, texName, payload, mesh, exclude) {
function shouldExclude(w) {
return (exclude instanceof Array)
? exclude.indexOf(w) >= 0
: false;
}
let str = "";
const indices = mesh.indices;
const vertices = mesh.vertices;
const normals = mesh.normals;
const _c_v = ctx.c_v;
const _c_n = ctx.c_n;
const _c_u = ctx.c_u;
let c_v = _c_v;
let c_n = _c_n;
let c_u = _c_u;
const console = { log: function (s) { str += s + "\n" } };
// console.log(`usemtl ${texName}`);
console.log(`o planet_${meshName}`);
console.log("# vertices");
let first = 1;
for (let i = 0; i < vertices.length; i += 8) {
num_vertices=num_vertices+1;
let x = vertices[i + 0]
let y = vertices[i + 1]
let z = vertices[i + 2]
let w = 1;
let _x = 0;
let _y = 0;
let _z = 0;
let _w = 0;
const ma = payload.matrixGlobeFromMesh;
_x = x * ma[0] + y * ma[4] + z * ma[8] + w * ma[12];
_y = x * ma[1] + y * ma[5] + z * ma[9] + w * ma[13];
_z = x * ma[2] + y * ma[6] + z * ma[10] + w * ma[14];
_w = x * ma[3] + y * ma[7] + z * ma[11] + w * ma[15];
x = _x;
y = _y;
z = _z;
x = ((x - offset_x) );
y = ((y - offset_y) );
z = ((z - offset_z) );
if (x<min_x_x) { min_x_x=x; min_x_y=y; min_x_z=z; }
if (x>max_x_x) { max_x_x=x; max_x_y=y; max_x_z=z; }
if (y<min_y_y) { min_y_x=x; min_y_y=y; min_y_z=z; }
if (y>max_y_y) { max_y_x=x; max_y_y=y; max_y_z=z; }
if (z<min_z_z) { min_z_x=x; min_z_y=y; min_z_z=z; }
if (z>max_z_z) { max_z_x=x; max_z_y=y; max_z_z=z; }
console.log(`v ${x} ${y} ${z}`);
c_v++;
}
if (mesh.uvOffsetAndScale) {
console.log("# UV");
for (let i = 0; i < vertices.length; i += 8) {
const u1 = vertices[i + 4];
const u2 = vertices[i + 5];
const v1 = vertices[i + 6];
const v2 = vertices[i + 7];
const u = u2 * 256 + u1;
const v = v2 * 256 + v1;
let ut = (u + mesh.uvOffsetAndScale[0]) * mesh.uvOffsetAndScale[2];
let vt = (v + mesh.uvOffsetAndScale[1]) * mesh.uvOffsetAndScale[3];
const tex = mesh.texture;
if (tex.textureFormat == 6) {
vt = 1 - vt;
console.log(`vt ${ut} ${vt}`)
}
else {
console.log(`vt ${ut} ${vt}`)
}
c_u++;
}
}
console.log("# Normals");
for (let i = 0; i < normals.length; i += 4) {
num_normals=num_normals+1;
let x = normals[i + 0] - 127;
let y = normals[i + 1] - 127;
let z = normals[i + 2] - 127;
let w = 0;
let _x = 0;
let _y = 0;
let _z = 0;
let _w = 0;
const ma = payload.matrixGlobeFromMesh;
_x = x * ma[0] + y * ma[4] + z * ma[8] + w * ma[12];
_y = x * ma[1] + y * ma[5] + z * ma[9] + w * ma[13];
_z = x * ma[2] + y * ma[6] + z * ma[10] + w * ma[14];
_w = x * ma[3] + y * ma[7] + z * ma[11] + w * ma[15];
x = _x;
y = _y;
z = _z;
console.log(`vn ${x} ${y} ${z}`)
c_n++;
}
console.log(`usemtl ${texName}`);
console.log("# faces");
const triangle_groups = {};
for (let i = 0; i < indices.length - 2; i += 1) {
num_faces=num_faces+1;
if (i === mesh.layerBounds[3]) break;
const a = indices[i + 0];
const b = indices[i + 1];
const c = indices[i + 2];
if (a == b || a == c || b == c) {
continue;
}
if (!(vertices[a * 8 + 3] === vertices[b * 8 + 3] && vertices[b * 8 + 3] === vertices[c * 8 + 3])) {
throw new Error("vertex w mismatch");
}
const w = vertices[a * 8 + 3];
if (shouldExclude(w)) continue;
triangle_groups[w] = [].concat(triangle_groups[w] || [], [(i & 1) ? [a, c, b] : [a, b, c]]);
}
for (let k in triangle_groups) {
if (!triangle_groups.hasOwnProperty(k)) throw new Error("no k property");
const triangles = triangle_groups[k];
for (let t in triangles) {
if (!triangles.hasOwnProperty(t)) throw new Error("no t property");
const v = triangles[t];
const a = v[0] + 1, b = v[1] + 1, c = v[2] + 1;
if (mesh.uvOffsetAndScale) {
console.log(`f ${a + _c_v}/${a + _c_u}/${a + _c_n} ${b + _c_v}/${b + _c_u}/${b + _c_n} ${c + _c_v}/${c + _c_u}/${c + _c_n}`)
} else {
console.log(`f ${a + _c_v} ${b + _c_v} ${c + _c_v}`)
}
}
}
ctx.c_v = c_v;
ctx.c_u = c_u;
ctx.c_n = c_n;
return str;
}
/****************************************************************/
/**************************** helper ****************************/
function semaphore(num) {
let concurrent = num;
const waiting = [];
return {
wait(highestPriority = false) {
return new Promise((resolve, reject) => {
if (concurrent <= 0) {
if (highestPriority) {
waiting.splice(0, 0, { resolve, reject });
} else {
waiting.push(({ resolve, reject }));
}
} else {
concurrent--;
resolve();
}
})
},
signal() {
concurrent++;
if (concurrent > 0) {
if (waiting.length > 0) {
concurrent--;
waiting.splice(0, 1)[0].resolve();
}
}
}
};
}
/****************************************************************/
(async function program() {
await run();
// console.log('.4');
})().then(() => {
process.exit(0);
}).catch(e => {
console.error(e);
process.exit(1);
});