@loaders.gl/pcd 4.0.0-alpha.4 → 4.0.0-alpha.6

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.
Files changed (72) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +2 -2
  4. package/dist/dist.min.js +476 -0
  5. package/dist/es5/bundle.js +6 -0
  6. package/dist/es5/bundle.js.map +1 -0
  7. package/dist/es5/index.js +45 -0
  8. package/dist/es5/index.js.map +1 -0
  9. package/dist/es5/lib/decompress-lzf.js +57 -0
  10. package/dist/es5/lib/decompress-lzf.js.map +1 -0
  11. package/dist/es5/lib/get-pcd-schema.js +54 -0
  12. package/dist/es5/lib/get-pcd-schema.js.map +1 -0
  13. package/dist/es5/lib/parse-pcd.js +299 -0
  14. package/dist/es5/lib/parse-pcd.js.map +1 -0
  15. package/dist/es5/lib/pcd-types.js +2 -0
  16. package/dist/es5/lib/pcd-types.js.map +1 -0
  17. package/dist/es5/pcd-loader.js +21 -0
  18. package/dist/es5/pcd-loader.js.map +1 -0
  19. package/dist/es5/workers/pcd-worker.js +6 -0
  20. package/dist/es5/workers/pcd-worker.js.map +1 -0
  21. package/dist/esm/bundle.js +4 -0
  22. package/dist/esm/bundle.js.map +1 -0
  23. package/dist/esm/index.js +10 -0
  24. package/dist/esm/index.js.map +1 -0
  25. package/dist/esm/lib/decompress-lzf.js +51 -0
  26. package/dist/esm/lib/decompress-lzf.js.map +1 -0
  27. package/dist/esm/lib/get-pcd-schema.js +48 -0
  28. package/dist/esm/lib/get-pcd-schema.js.map +1 -0
  29. package/dist/esm/lib/parse-pcd.js +289 -0
  30. package/dist/esm/lib/parse-pcd.js.map +1 -0
  31. package/dist/esm/lib/pcd-types.js +2 -0
  32. package/dist/esm/lib/pcd-types.js.map +1 -0
  33. package/dist/esm/pcd-loader.js +14 -0
  34. package/dist/esm/pcd-loader.js.map +1 -0
  35. package/dist/esm/workers/pcd-worker.js +4 -0
  36. package/dist/esm/workers/pcd-worker.js.map +1 -0
  37. package/dist/index.d.ts +10 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +17 -8
  40. package/dist/lib/decompress-lzf.d.ts +8 -0
  41. package/dist/lib/decompress-lzf.d.ts.map +1 -0
  42. package/dist/lib/decompress-lzf.js +62 -0
  43. package/dist/lib/get-pcd-schema.d.ts +10 -0
  44. package/dist/lib/get-pcd-schema.d.ts.map +1 -0
  45. package/dist/lib/get-pcd-schema.js +32 -19
  46. package/dist/lib/parse-pcd.d.ts +8 -0
  47. package/dist/lib/parse-pcd.d.ts.map +1 -0
  48. package/dist/lib/parse-pcd.js +317 -223
  49. package/dist/lib/pcd-types.d.ts +31 -0
  50. package/dist/lib/pcd-types.d.ts.map +1 -0
  51. package/dist/lib/pcd-types.js +2 -2
  52. package/dist/pcd-loader.d.ts +7 -0
  53. package/dist/pcd-loader.d.ts.map +1 -0
  54. package/dist/pcd-loader.js +21 -14
  55. package/dist/pcd-worker.js +200 -439
  56. package/dist/workers/pcd-worker.d.ts +2 -0
  57. package/dist/workers/pcd-worker.d.ts.map +1 -0
  58. package/dist/workers/pcd-worker.js +5 -4
  59. package/package.json +9 -9
  60. package/src/index.ts +3 -2
  61. package/src/lib/decompress-lzf.ts +64 -0
  62. package/src/lib/get-pcd-schema.ts +15 -10
  63. package/src/lib/parse-pcd.ts +161 -12
  64. package/src/lib/pcd-types.ts +9 -9
  65. package/src/pcd-loader.ts +5 -4
  66. package/dist/bundle.js.map +0 -1
  67. package/dist/index.js.map +0 -1
  68. package/dist/lib/get-pcd-schema.js.map +0 -1
  69. package/dist/lib/parse-pcd.js.map +0 -1
  70. package/dist/lib/pcd-types.js.map +0 -1
  71. package/dist/pcd-loader.js.map +0 -1
  72. package/dist/workers/pcd-worker.js.map +0 -1
@@ -35,16 +35,33 @@
35
35
  }
36
36
 
37
37
  // ../worker-utils/src/lib/worker-farm/worker-body.ts
38
+ function getParentPort() {
39
+ let parentPort;
40
+ try {
41
+ eval("globalThis.parentPort = require('worker_threads').parentPort");
42
+ parentPort = globalThis.parentPort;
43
+ } catch {
44
+ }
45
+ return parentPort;
46
+ }
38
47
  var onMessageWrapperMap = new Map();
39
48
  var WorkerBody = class {
49
+ static inWorkerThread() {
50
+ return typeof self !== "undefined" || Boolean(getParentPort());
51
+ }
40
52
  static set onmessage(onMessage) {
41
- self.onmessage = (message) => {
42
- if (!isKnownMessage(message)) {
43
- return;
44
- }
45
- const { type, payload } = message.data;
53
+ function handleMessage(message) {
54
+ const parentPort3 = getParentPort();
55
+ const { type, payload } = parentPort3 ? message : message.data;
46
56
  onMessage(type, payload);
47
- };
57
+ }
58
+ const parentPort2 = getParentPort();
59
+ if (parentPort2) {
60
+ parentPort2.on("message", handleMessage);
61
+ parentPort2.on("exit", () => console.debug("Node worker closing"));
62
+ } else {
63
+ globalThis.onmessage = handleMessage;
64
+ }
48
65
  }
49
66
  static addEventListener(onMessage) {
50
67
  let onMessageWrapper = onMessageWrapperMap.get(onMessage);
@@ -53,22 +70,36 @@
53
70
  if (!isKnownMessage(message)) {
54
71
  return;
55
72
  }
56
- const { type, payload } = message.data;
73
+ const parentPort3 = getParentPort();
74
+ const { type, payload } = parentPort3 ? message : message.data;
57
75
  onMessage(type, payload);
58
76
  };
59
77
  }
60
- self.addEventListener("message", onMessageWrapper);
78
+ const parentPort2 = getParentPort();
79
+ if (parentPort2) {
80
+ console.error("not implemented");
81
+ } else {
82
+ globalThis.addEventListener("message", onMessageWrapper);
83
+ }
61
84
  }
62
85
  static removeEventListener(onMessage) {
63
86
  const onMessageWrapper = onMessageWrapperMap.get(onMessage);
64
87
  onMessageWrapperMap.delete(onMessage);
65
- self.removeEventListener("message", onMessageWrapper);
88
+ const parentPort2 = getParentPort();
89
+ if (parentPort2) {
90
+ console.error("not implemented");
91
+ } else {
92
+ globalThis.removeEventListener("message", onMessageWrapper);
93
+ }
66
94
  }
67
95
  static postMessage(type, payload) {
68
- if (self) {
69
- const data = { source: "loaders.gl", type, payload };
70
- const transferList = getTransferList(payload);
71
- self.postMessage(data, transferList);
96
+ const data = { source: "loaders.gl", type, payload };
97
+ const transferList = getTransferList(payload);
98
+ const parentPort2 = getParentPort();
99
+ if (parentPort2) {
100
+ parentPort2.postMessage(data, transferList);
101
+ } else {
102
+ globalThis.postMessage(data, transferList);
72
103
  }
73
104
  }
74
105
  };
@@ -80,19 +111,20 @@
80
111
  // ../loader-utils/src/lib/worker-loader-utils/create-loader-worker.ts
81
112
  var requestId = 0;
82
113
  function createLoaderWorker(loader) {
83
- if (typeof self === "undefined") {
114
+ if (!WorkerBody.inWorkerThread()) {
84
115
  return;
85
116
  }
86
117
  WorkerBody.onmessage = async (type, payload) => {
87
118
  switch (type) {
88
119
  case "process":
89
120
  try {
90
- const { input, options = {} } = payload;
121
+ const { input, options = {}, context = {} } = payload;
91
122
  const result = await parseData({
92
123
  loader,
93
124
  arrayBuffer: input,
94
125
  options,
95
126
  context: {
127
+ ...context,
96
128
  parse: parseOnMainThread
97
129
  }
98
130
  });
@@ -151,7 +183,7 @@
151
183
  return await parser(data, { ...options }, context, loader);
152
184
  }
153
185
 
154
- // ../schema/src/category/mesh/mesh-utils.ts
186
+ // ../schema/src/lib/mesh/mesh-utils.ts
155
187
  function getMeshBoundingBox(attributes) {
156
188
  let minX = Infinity;
157
189
  let minY = Infinity;
@@ -178,436 +210,81 @@
178
210
  ];
179
211
  }
180
212
 
181
- // ../schema/src/lib/utils/assert.ts
182
- function assert(condition, message) {
183
- if (!condition) {
184
- throw new Error(message || "loader assertion failed.");
185
- }
186
- }
187
-
188
- // ../schema/src/lib/schema/impl/schema.ts
189
- var Schema = class {
190
- constructor(fields, metadata) {
191
- assert(Array.isArray(fields));
192
- checkNames(fields);
193
- this.fields = fields;
194
- this.metadata = metadata || new Map();
195
- }
196
- compareTo(other) {
197
- if (this.metadata !== other.metadata) {
198
- return false;
199
- }
200
- if (this.fields.length !== other.fields.length) {
201
- return false;
202
- }
203
- for (let i = 0; i < this.fields.length; ++i) {
204
- if (!this.fields[i].compareTo(other.fields[i])) {
205
- return false;
213
+ // src/lib/decompress-lzf.ts
214
+ function decompressLZF(inData, outLength) {
215
+ const inLength = inData.length;
216
+ const outData = new Uint8Array(outLength);
217
+ let inPtr = 0;
218
+ let outPtr = 0;
219
+ let ctrl;
220
+ let len;
221
+ let ref;
222
+ do {
223
+ ctrl = inData[inPtr++];
224
+ if (ctrl < 1 << 5) {
225
+ ctrl++;
226
+ if (outPtr + ctrl > outLength) {
227
+ throw new Error("Output buffer is not large enough");
206
228
  }
207
- }
208
- return true;
209
- }
210
- select(...columnNames) {
211
- const nameMap = Object.create(null);
212
- for (const name of columnNames) {
213
- nameMap[name] = true;
214
- }
215
- const selectedFields = this.fields.filter((field) => nameMap[field.name]);
216
- return new Schema(selectedFields, this.metadata);
217
- }
218
- selectAt(...columnIndices) {
219
- const selectedFields = columnIndices.map((index) => this.fields[index]).filter(Boolean);
220
- return new Schema(selectedFields, this.metadata);
221
- }
222
- assign(schemaOrFields) {
223
- let fields;
224
- let metadata = this.metadata;
225
- if (schemaOrFields instanceof Schema) {
226
- const otherSchema = schemaOrFields;
227
- fields = otherSchema.fields;
228
- metadata = mergeMaps(mergeMaps(new Map(), this.metadata), otherSchema.metadata);
229
+ if (inPtr + ctrl > inLength) {
230
+ throw new Error("Invalid compressed data");
231
+ }
232
+ do {
233
+ outData[outPtr++] = inData[inPtr++];
234
+ } while (--ctrl);
229
235
  } else {
230
- fields = schemaOrFields;
231
- }
232
- const fieldMap = Object.create(null);
233
- for (const field of this.fields) {
234
- fieldMap[field.name] = field;
235
- }
236
- for (const field of fields) {
237
- fieldMap[field.name] = field;
238
- }
239
- const mergedFields = Object.values(fieldMap);
240
- return new Schema(mergedFields, metadata);
241
- }
242
- };
243
- function checkNames(fields) {
244
- const usedNames = {};
245
- for (const field of fields) {
246
- if (usedNames[field.name]) {
247
- console.warn("Schema: duplicated field name", field.name, field);
236
+ len = ctrl >> 5;
237
+ ref = outPtr - ((ctrl & 31) << 8) - 1;
238
+ if (inPtr >= inLength) {
239
+ throw new Error("Invalid compressed data");
240
+ }
241
+ if (len === 7) {
242
+ len += inData[inPtr++];
243
+ if (inPtr >= inLength) {
244
+ throw new Error("Invalid compressed data");
245
+ }
246
+ }
247
+ ref -= inData[inPtr++];
248
+ if (outPtr + len + 2 > outLength) {
249
+ throw new Error("Output buffer is not large enough");
250
+ }
251
+ if (ref < 0) {
252
+ throw new Error("Invalid compressed data");
253
+ }
254
+ if (ref >= outPtr) {
255
+ throw new Error("Invalid compressed data");
256
+ }
257
+ do {
258
+ outData[outPtr++] = outData[ref++];
259
+ } while (--len + 2);
248
260
  }
249
- usedNames[field.name] = true;
250
- }
261
+ } while (inPtr < inLength);
262
+ return outData;
251
263
  }
252
- function mergeMaps(m1, m2) {
253
- return new Map([...m1 || new Map(), ...m2 || new Map()]);
254
- }
255
-
256
- // ../schema/src/lib/schema/impl/field.ts
257
- var Field = class {
258
- constructor(name, type, nullable = false, metadata = new Map()) {
259
- this.name = name;
260
- this.type = type;
261
- this.nullable = nullable;
262
- this.metadata = metadata;
263
- }
264
- get typeId() {
265
- return this.type && this.type.typeId;
266
- }
267
- clone() {
268
- return new Field(this.name, this.type, this.nullable, this.metadata);
269
- }
270
- compareTo(other) {
271
- return this.name === other.name && this.type === other.type && this.nullable === other.nullable && this.metadata === other.metadata;
272
- }
273
- toString() {
274
- return `${this.type}${this.nullable ? ", nullable" : ""}${this.metadata ? `, metadata: ${this.metadata}` : ""}`;
275
- }
276
- };
277
-
278
- // ../schema/src/lib/schema/impl/enum.ts
279
- var Type;
280
- (function(Type2) {
281
- Type2[Type2["NONE"] = 0] = "NONE";
282
- Type2[Type2["Null"] = 1] = "Null";
283
- Type2[Type2["Int"] = 2] = "Int";
284
- Type2[Type2["Float"] = 3] = "Float";
285
- Type2[Type2["Binary"] = 4] = "Binary";
286
- Type2[Type2["Utf8"] = 5] = "Utf8";
287
- Type2[Type2["Bool"] = 6] = "Bool";
288
- Type2[Type2["Decimal"] = 7] = "Decimal";
289
- Type2[Type2["Date"] = 8] = "Date";
290
- Type2[Type2["Time"] = 9] = "Time";
291
- Type2[Type2["Timestamp"] = 10] = "Timestamp";
292
- Type2[Type2["Interval"] = 11] = "Interval";
293
- Type2[Type2["List"] = 12] = "List";
294
- Type2[Type2["Struct"] = 13] = "Struct";
295
- Type2[Type2["Union"] = 14] = "Union";
296
- Type2[Type2["FixedSizeBinary"] = 15] = "FixedSizeBinary";
297
- Type2[Type2["FixedSizeList"] = 16] = "FixedSizeList";
298
- Type2[Type2["Map"] = 17] = "Map";
299
- Type2[Type2["Dictionary"] = -1] = "Dictionary";
300
- Type2[Type2["Int8"] = -2] = "Int8";
301
- Type2[Type2["Int16"] = -3] = "Int16";
302
- Type2[Type2["Int32"] = -4] = "Int32";
303
- Type2[Type2["Int64"] = -5] = "Int64";
304
- Type2[Type2["Uint8"] = -6] = "Uint8";
305
- Type2[Type2["Uint16"] = -7] = "Uint16";
306
- Type2[Type2["Uint32"] = -8] = "Uint32";
307
- Type2[Type2["Uint64"] = -9] = "Uint64";
308
- Type2[Type2["Float16"] = -10] = "Float16";
309
- Type2[Type2["Float32"] = -11] = "Float32";
310
- Type2[Type2["Float64"] = -12] = "Float64";
311
- Type2[Type2["DateDay"] = -13] = "DateDay";
312
- Type2[Type2["DateMillisecond"] = -14] = "DateMillisecond";
313
- Type2[Type2["TimestampSecond"] = -15] = "TimestampSecond";
314
- Type2[Type2["TimestampMillisecond"] = -16] = "TimestampMillisecond";
315
- Type2[Type2["TimestampMicrosecond"] = -17] = "TimestampMicrosecond";
316
- Type2[Type2["TimestampNanosecond"] = -18] = "TimestampNanosecond";
317
- Type2[Type2["TimeSecond"] = -19] = "TimeSecond";
318
- Type2[Type2["TimeMillisecond"] = -20] = "TimeMillisecond";
319
- Type2[Type2["TimeMicrosecond"] = -21] = "TimeMicrosecond";
320
- Type2[Type2["TimeNanosecond"] = -22] = "TimeNanosecond";
321
- Type2[Type2["DenseUnion"] = -23] = "DenseUnion";
322
- Type2[Type2["SparseUnion"] = -24] = "SparseUnion";
323
- Type2[Type2["IntervalDayTime"] = -25] = "IntervalDayTime";
324
- Type2[Type2["IntervalYearMonth"] = -26] = "IntervalYearMonth";
325
- })(Type || (Type = {}));
326
-
327
- // ../schema/src/lib/schema/impl/type.ts
328
- var DataType = class {
329
- static isNull(x) {
330
- return x && x.typeId === Type.Null;
331
- }
332
- static isInt(x) {
333
- return x && x.typeId === Type.Int;
334
- }
335
- static isFloat(x) {
336
- return x && x.typeId === Type.Float;
337
- }
338
- static isBinary(x) {
339
- return x && x.typeId === Type.Binary;
340
- }
341
- static isUtf8(x) {
342
- return x && x.typeId === Type.Utf8;
343
- }
344
- static isBool(x) {
345
- return x && x.typeId === Type.Bool;
346
- }
347
- static isDecimal(x) {
348
- return x && x.typeId === Type.Decimal;
349
- }
350
- static isDate(x) {
351
- return x && x.typeId === Type.Date;
352
- }
353
- static isTime(x) {
354
- return x && x.typeId === Type.Time;
355
- }
356
- static isTimestamp(x) {
357
- return x && x.typeId === Type.Timestamp;
358
- }
359
- static isInterval(x) {
360
- return x && x.typeId === Type.Interval;
361
- }
362
- static isList(x) {
363
- return x && x.typeId === Type.List;
364
- }
365
- static isStruct(x) {
366
- return x && x.typeId === Type.Struct;
367
- }
368
- static isUnion(x) {
369
- return x && x.typeId === Type.Union;
370
- }
371
- static isFixedSizeBinary(x) {
372
- return x && x.typeId === Type.FixedSizeBinary;
373
- }
374
- static isFixedSizeList(x) {
375
- return x && x.typeId === Type.FixedSizeList;
376
- }
377
- static isMap(x) {
378
- return x && x.typeId === Type.Map;
379
- }
380
- static isDictionary(x) {
381
- return x && x.typeId === Type.Dictionary;
382
- }
383
- get typeId() {
384
- return Type.NONE;
385
- }
386
- compareTo(other) {
387
- return this === other;
388
- }
389
- };
390
- var Null = class extends DataType {
391
- get typeId() {
392
- return Type.Null;
393
- }
394
- get [Symbol.toStringTag]() {
395
- return "Null";
396
- }
397
- toString() {
398
- return "Null";
399
- }
400
- };
401
- var Bool = class extends DataType {
402
- get typeId() {
403
- return Type.Bool;
404
- }
405
- get [Symbol.toStringTag]() {
406
- return "Bool";
407
- }
408
- toString() {
409
- return "Bool";
410
- }
411
- };
412
- var Int = class extends DataType {
413
- constructor(isSigned, bitWidth) {
414
- super();
415
- this.isSigned = isSigned;
416
- this.bitWidth = bitWidth;
417
- }
418
- get typeId() {
419
- return Type.Int;
420
- }
421
- get [Symbol.toStringTag]() {
422
- return "Int";
423
- }
424
- toString() {
425
- return `${this.isSigned ? "I" : "Ui"}nt${this.bitWidth}`;
426
- }
427
- };
428
- var Uint8 = class extends Int {
429
- constructor() {
430
- super(false, 8);
431
- }
432
- };
433
- var Precision = {
434
- HALF: 16,
435
- SINGLE: 32,
436
- DOUBLE: 64
437
- };
438
- var Float = class extends DataType {
439
- constructor(precision) {
440
- super();
441
- this.precision = precision;
442
- }
443
- get typeId() {
444
- return Type.Float;
445
- }
446
- get [Symbol.toStringTag]() {
447
- return "Float";
448
- }
449
- toString() {
450
- return `Float${this.precision}`;
451
- }
452
- };
453
- var Float32 = class extends Float {
454
- constructor() {
455
- super(Precision.SINGLE);
456
- }
457
- };
458
- var Binary = class extends DataType {
459
- constructor() {
460
- super();
461
- }
462
- get typeId() {
463
- return Type.Binary;
464
- }
465
- toString() {
466
- return "Binary";
467
- }
468
- get [Symbol.toStringTag]() {
469
- return "Binary";
470
- }
471
- };
472
- var Utf8 = class extends DataType {
473
- get typeId() {
474
- return Type.Utf8;
475
- }
476
- get [Symbol.toStringTag]() {
477
- return "Utf8";
478
- }
479
- toString() {
480
- return "Utf8";
481
- }
482
- };
483
- var DateUnit = {
484
- DAY: 0,
485
- MILLISECOND: 1
486
- };
487
- var Date = class extends DataType {
488
- constructor(unit) {
489
- super();
490
- this.unit = unit;
491
- }
492
- get typeId() {
493
- return Type.Date;
494
- }
495
- get [Symbol.toStringTag]() {
496
- return "Date";
497
- }
498
- toString() {
499
- return `Date${(this.unit + 1) * 32}<${DateUnit[this.unit]}>`;
500
- }
501
- };
502
- var TimeUnit = {
503
- SECOND: 1,
504
- MILLISECOND: 1e3,
505
- MICROSECOND: 1e6,
506
- NANOSECOND: 1e9
507
- };
508
- var Time = class extends DataType {
509
- constructor(unit, bitWidth) {
510
- super();
511
- this.unit = unit;
512
- this.bitWidth = bitWidth;
513
- }
514
- get typeId() {
515
- return Type.Time;
516
- }
517
- toString() {
518
- return `Time${this.bitWidth}<${TimeUnit[this.unit]}>`;
519
- }
520
- get [Symbol.toStringTag]() {
521
- return "Time";
522
- }
523
- };
524
- var Timestamp = class extends DataType {
525
- constructor(unit, timezone = null) {
526
- super();
527
- this.unit = unit;
528
- this.timezone = timezone;
529
- }
530
- get typeId() {
531
- return Type.Timestamp;
532
- }
533
- get [Symbol.toStringTag]() {
534
- return "Timestamp";
535
- }
536
- toString() {
537
- return `Timestamp<${TimeUnit[this.unit]}${this.timezone ? `, ${this.timezone}` : ""}>`;
538
- }
539
- };
540
- var IntervalUnit = {
541
- DAY_TIME: 0,
542
- YEAR_MONTH: 1
543
- };
544
- var Interval = class extends DataType {
545
- constructor(unit) {
546
- super();
547
- this.unit = unit;
548
- }
549
- get typeId() {
550
- return Type.Interval;
551
- }
552
- get [Symbol.toStringTag]() {
553
- return "Interval";
554
- }
555
- toString() {
556
- return `Interval<${IntervalUnit[this.unit]}>`;
557
- }
558
- };
559
- var FixedSizeList = class extends DataType {
560
- constructor(listSize, child) {
561
- super();
562
- this.listSize = listSize;
563
- this.children = [child];
564
- }
565
- get typeId() {
566
- return Type.FixedSizeList;
567
- }
568
- get valueType() {
569
- return this.children[0].type;
570
- }
571
- get valueField() {
572
- return this.children[0];
573
- }
574
- get [Symbol.toStringTag]() {
575
- return "FixedSizeList";
576
- }
577
- toString() {
578
- return `FixedSizeList[${this.listSize}]<${this.valueType}>`;
579
- }
580
- };
581
- var Struct = class extends DataType {
582
- constructor(children) {
583
- super();
584
- this.children = children;
585
- }
586
- get typeId() {
587
- return Type.Struct;
588
- }
589
- toString() {
590
- return `Struct<{${this.children.map((f) => `${f.name}:${f.type}`).join(", ")}}>`;
591
- }
592
- get [Symbol.toStringTag]() {
593
- return "Struct";
594
- }
595
- };
596
264
 
597
265
  // src/lib/get-pcd-schema.ts
598
266
  function getPCDSchema(PCDheader, metadata) {
599
267
  const offset = PCDheader.offset;
600
268
  const fields = [];
601
269
  if (offset.x !== void 0) {
602
- fields.push(new Field("POSITION", new FixedSizeList(3, new Field("xyz", new Float32())), false));
270
+ fields.push({
271
+ name: "POSITION",
272
+ type: { type: "fixed-size-list", listSize: 3, children: [{ name: "xyz", type: "float32" }] }
273
+ });
603
274
  }
604
275
  if (offset.normal_x !== void 0) {
605
- fields.push(new Field("NORMAL", new FixedSizeList(3, new Field("xyz", new Float32())), false));
276
+ fields.push({
277
+ name: "NORMAL",
278
+ type: { type: "fixed-size-list", listSize: 3, children: [{ name: "xyz", type: "float32" }] }
279
+ });
606
280
  }
607
281
  if (offset.rgb !== void 0) {
608
- fields.push(new Field("COLOR_0", new FixedSizeList(3, new Field("rgb", new Uint8())), false));
282
+ fields.push({
283
+ name: "COLOR_0",
284
+ type: { type: "fixed-size-list", listSize: 3, children: [{ name: "rgb", type: "uint8" }] }
285
+ });
609
286
  }
610
- return new Schema(fields, metadata);
287
+ return { fields, metadata };
611
288
  }
612
289
 
613
290
  // src/lib/parse-pcd.ts
@@ -624,24 +301,25 @@
624
301
  attributes = parsePCDBinary(pcdHeader, data);
625
302
  break;
626
303
  case "binary_compressed":
304
+ attributes = parsePCDBinaryCompressed(pcdHeader, data);
305
+ break;
627
306
  default:
628
307
  throw new Error(`PCD: ${pcdHeader.data} files are not supported`);
629
308
  }
630
309
  attributes = getMeshAttributes(attributes);
631
310
  const header = getMeshHeader(pcdHeader, attributes);
632
- const metadata = new Map([
311
+ const metadata = Object.fromEntries([
633
312
  ["mode", "0"],
634
313
  ["boundingBox", JSON.stringify(header.boundingBox)]
635
314
  ]);
636
315
  const schema = getPCDSchema(pcdHeader, metadata);
637
316
  return {
638
- loaderData: {
639
- header: pcdHeader
640
- },
317
+ loader: "pcd",
318
+ loaderData: pcdHeader,
641
319
  header,
642
320
  schema,
643
321
  mode: 0,
644
- indices: null,
322
+ topology: "point-list",
645
323
  attributes
646
324
  };
647
325
  }
@@ -653,7 +331,10 @@
653
331
  boundingBox: getMeshBoundingBox(attributes)
654
332
  };
655
333
  }
656
- return pcdHeader;
334
+ return {
335
+ vertexCount: pcdHeader.vertexCount,
336
+ boundingBox: pcdHeader.boundingBox
337
+ };
657
338
  }
658
339
  function getMeshAttributes(attributes) {
659
340
  const normalizedAttributes = {
@@ -674,6 +355,18 @@
674
355
  size: 3
675
356
  };
676
357
  }
358
+ if (attributes.intensity && attributes.intensity.length > 0) {
359
+ normalizedAttributes.COLOR_0 = {
360
+ value: new Uint8Array(attributes.color),
361
+ size: 3
362
+ };
363
+ }
364
+ if (attributes.label && attributes.label.length > 0) {
365
+ normalizedAttributes.COLOR_0 = {
366
+ value: new Uint8Array(attributes.label),
367
+ size: 3
368
+ };
369
+ }
677
370
  return normalizedAttributes;
678
371
  }
679
372
  function parsePCDHeader(data) {
@@ -751,6 +444,8 @@
751
444
  const position = [];
752
445
  const normal = [];
753
446
  const color = [];
447
+ const intensity = [];
448
+ const label = [];
754
449
  const offset = pcdHeader.offset;
755
450
  const pcdData = textData.substr(pcdHeader.headerLen);
756
451
  const lines = pcdData.split("\n");
@@ -775,6 +470,12 @@
775
470
  normal.push(parseFloat(line[offset.normal_y]));
776
471
  normal.push(parseFloat(line[offset.normal_z]));
777
472
  }
473
+ if (offset.intensity !== void 0) {
474
+ intensity.push(parseFloat(line[offset.intensity]));
475
+ }
476
+ if (offset.label !== void 0) {
477
+ label.push(parseInt(line[offset.label]));
478
+ }
778
479
  }
779
480
  }
780
481
  return { position, normal, color };
@@ -783,6 +484,8 @@
783
484
  const position = [];
784
485
  const normal = [];
785
486
  const color = [];
487
+ const intensity = [];
488
+ const label = [];
786
489
  const dataview = new DataView(data, pcdHeader.headerLen);
787
490
  const offset = pcdHeader.offset;
788
491
  for (let i = 0, row = 0; i < pcdHeader.points; i++, row += pcdHeader.rowSize) {
@@ -801,12 +504,63 @@
801
504
  normal.push(dataview.getFloat32(row + offset.normal_y, LITTLE_ENDIAN));
802
505
  normal.push(dataview.getFloat32(row + offset.normal_z, LITTLE_ENDIAN));
803
506
  }
507
+ if (offset.intensity !== void 0) {
508
+ intensity.push(dataview.getFloat32(row + offset.intensity, LITTLE_ENDIAN));
509
+ }
510
+ if (offset.label !== void 0) {
511
+ label.push(dataview.getInt32(row + offset.label, LITTLE_ENDIAN));
512
+ }
804
513
  }
805
- return { position, normal, color };
514
+ return { position, normal, color, intensity, label };
515
+ }
516
+ function parsePCDBinaryCompressed(pcdHeader, data) {
517
+ const position = [];
518
+ const normal = [];
519
+ const color = [];
520
+ const intensity = [];
521
+ const label = [];
522
+ const sizes = new Uint32Array(data.slice(pcdHeader.headerLen, pcdHeader.headerLen + 8));
523
+ const compressedSize = sizes[0];
524
+ const decompressedSize = sizes[1];
525
+ const decompressed = decompressLZF(new Uint8Array(data, pcdHeader.headerLen + 8, compressedSize), decompressedSize);
526
+ const dataview = new DataView(decompressed.buffer);
527
+ const offset = pcdHeader.offset;
528
+ for (let i = 0; i < pcdHeader.points; i++) {
529
+ if (offset.x !== void 0) {
530
+ position.push(dataview.getFloat32(pcdHeader.points * offset.x + pcdHeader.size[0] * i, LITTLE_ENDIAN));
531
+ position.push(dataview.getFloat32(pcdHeader.points * offset.y + pcdHeader.size[1] * i, LITTLE_ENDIAN));
532
+ position.push(dataview.getFloat32(pcdHeader.points * offset.z + pcdHeader.size[2] * i, LITTLE_ENDIAN));
533
+ }
534
+ if (offset.rgb !== void 0) {
535
+ color.push(dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 0) / 255);
536
+ color.push(dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 1) / 255);
537
+ color.push(dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 2) / 255);
538
+ }
539
+ if (offset.normal_x !== void 0) {
540
+ normal.push(dataview.getFloat32(pcdHeader.points * offset.normal_x + pcdHeader.size[4] * i, LITTLE_ENDIAN));
541
+ normal.push(dataview.getFloat32(pcdHeader.points * offset.normal_y + pcdHeader.size[5] * i, LITTLE_ENDIAN));
542
+ normal.push(dataview.getFloat32(pcdHeader.points * offset.normal_z + pcdHeader.size[6] * i, LITTLE_ENDIAN));
543
+ }
544
+ if (offset.intensity !== void 0) {
545
+ const intensityIndex = pcdHeader.fields.indexOf("intensity");
546
+ intensity.push(dataview.getFloat32(pcdHeader.points * offset.intensity + pcdHeader.size[intensityIndex] * i, LITTLE_ENDIAN));
547
+ }
548
+ if (offset.label !== void 0) {
549
+ const labelIndex = pcdHeader.fields.indexOf("label");
550
+ label.push(dataview.getInt32(pcdHeader.points * offset.label + pcdHeader.size[labelIndex] * i, LITTLE_ENDIAN));
551
+ }
552
+ }
553
+ return {
554
+ position,
555
+ normal,
556
+ color,
557
+ intensity,
558
+ label
559
+ };
806
560
  }
807
561
 
808
562
  // src/pcd-loader.ts
809
- var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
563
+ var VERSION = true ? "4.0.0-alpha.6" : "latest";
810
564
  var PCDLoader = {
811
565
  name: "PCD (Point Cloud Data)",
812
566
  id: "pcd",
@@ -830,3 +584,10 @@
830
584
  // src/workers/pcd-worker.ts
831
585
  createLoaderWorker(PCDLoader2);
832
586
  })();
587
+ /** Parse compressed PCD data in in binary_compressed form ( https://pointclouds.org/documentation/tutorials/pcd_file_format.html)
588
+ * from https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/PCDLoader.js
589
+ * @license MIT (http://opensource.org/licenses/MIT)
590
+ * @param pcdHeader
591
+ * @param data
592
+ * @returns [attributes]
593
+ */