@loaders.gl/pcd 4.0.0-alpha.5 → 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 (68) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/dist.min.js +93 -487
  3. package/dist/es5/bundle.js +6 -0
  4. package/dist/es5/bundle.js.map +1 -0
  5. package/dist/es5/index.js +45 -0
  6. package/dist/es5/index.js.map +1 -0
  7. package/dist/es5/lib/decompress-lzf.js +57 -0
  8. package/dist/es5/lib/decompress-lzf.js.map +1 -0
  9. package/dist/es5/lib/get-pcd-schema.js +54 -0
  10. package/dist/es5/lib/get-pcd-schema.js.map +1 -0
  11. package/dist/es5/lib/parse-pcd.js +299 -0
  12. package/dist/es5/lib/parse-pcd.js.map +1 -0
  13. package/dist/es5/lib/pcd-types.js +2 -0
  14. package/dist/es5/lib/pcd-types.js.map +1 -0
  15. package/dist/es5/pcd-loader.js +21 -0
  16. package/dist/es5/pcd-loader.js.map +1 -0
  17. package/dist/es5/workers/pcd-worker.js +6 -0
  18. package/dist/es5/workers/pcd-worker.js.map +1 -0
  19. package/dist/esm/bundle.js +4 -0
  20. package/dist/esm/bundle.js.map +1 -0
  21. package/dist/esm/index.js +10 -0
  22. package/dist/esm/index.js.map +1 -0
  23. package/dist/esm/lib/decompress-lzf.js +51 -0
  24. package/dist/esm/lib/decompress-lzf.js.map +1 -0
  25. package/dist/esm/lib/get-pcd-schema.js +48 -0
  26. package/dist/esm/lib/get-pcd-schema.js.map +1 -0
  27. package/dist/esm/lib/parse-pcd.js +289 -0
  28. package/dist/esm/lib/parse-pcd.js.map +1 -0
  29. package/dist/esm/lib/pcd-types.js +2 -0
  30. package/dist/esm/lib/pcd-types.js.map +1 -0
  31. package/dist/esm/pcd-loader.js +14 -0
  32. package/dist/esm/pcd-loader.js.map +1 -0
  33. package/dist/esm/workers/pcd-worker.js +4 -0
  34. package/dist/esm/workers/pcd-worker.js.map +1 -0
  35. package/dist/index.d.ts +3 -25
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +17 -8
  38. package/dist/lib/decompress-lzf.d.ts.map +1 -1
  39. package/dist/lib/decompress-lzf.js +61 -43
  40. package/dist/lib/get-pcd-schema.d.ts +1 -3
  41. package/dist/lib/get-pcd-schema.d.ts.map +1 -1
  42. package/dist/lib/get-pcd-schema.js +32 -19
  43. package/dist/lib/parse-pcd.d.ts +2 -11
  44. package/dist/lib/parse-pcd.d.ts.map +1 -1
  45. package/dist/lib/parse-pcd.js +304 -260
  46. package/dist/lib/pcd-types.d.ts +12 -12
  47. package/dist/lib/pcd-types.d.ts.map +1 -1
  48. package/dist/lib/pcd-types.js +2 -2
  49. package/dist/pcd-loader.d.ts +3 -14
  50. package/dist/pcd-loader.d.ts.map +1 -1
  51. package/dist/pcd-loader.js +21 -14
  52. package/dist/pcd-worker.js +140 -466
  53. package/dist/workers/pcd-worker.js +5 -4
  54. package/package.json +6 -6
  55. package/src/index.ts +3 -2
  56. package/src/lib/decompress-lzf.ts +21 -7
  57. package/src/lib/get-pcd-schema.ts +15 -10
  58. package/src/lib/parse-pcd.ts +95 -42
  59. package/src/lib/pcd-types.ts +9 -9
  60. package/src/pcd-loader.ts +5 -4
  61. package/dist/bundle.js.map +0 -1
  62. package/dist/index.js.map +0 -1
  63. package/dist/lib/decompress-lzf.js.map +0 -1
  64. package/dist/lib/get-pcd-schema.js.map +0 -1
  65. package/dist/lib/parse-pcd.js.map +0 -1
  66. package/dist/lib/pcd-types.js.map +0 -1
  67. package/dist/pcd-loader.js.map +0 -1
  68. package/dist/workers/pcd-worker.js.map +0 -1
package/dist/dist.min.js CHANGED
@@ -13,7 +13,7 @@
13
13
  __defProp(target, name, { get: all[name], enumerable: true });
14
14
  };
15
15
 
16
- // ../schema/src/category/mesh/mesh-utils.ts
16
+ // ../schema/src/lib/mesh/mesh-utils.ts
17
17
  function getMeshBoundingBox(attributes) {
18
18
  let minX = Infinity;
19
19
  let minY = Infinity;
@@ -40,457 +40,7 @@
40
40
  ];
41
41
  }
42
42
  var init_mesh_utils = __esm({
43
- "../schema/src/category/mesh/mesh-utils.ts"() {
44
- }
45
- });
46
-
47
- // ../schema/src/lib/utils/assert.ts
48
- function assert(condition, message) {
49
- if (!condition) {
50
- throw new Error(message || "loader assertion failed.");
51
- }
52
- }
53
- var init_assert = __esm({
54
- "../schema/src/lib/utils/assert.ts"() {
55
- }
56
- });
57
-
58
- // ../schema/src/lib/schema/impl/schema.ts
59
- function checkNames(fields) {
60
- const usedNames = {};
61
- for (const field of fields) {
62
- if (usedNames[field.name]) {
63
- console.warn("Schema: duplicated field name", field.name, field);
64
- }
65
- usedNames[field.name] = true;
66
- }
67
- }
68
- function mergeMaps(m1, m2) {
69
- return new Map([...m1 || new Map(), ...m2 || new Map()]);
70
- }
71
- var Schema;
72
- var init_schema = __esm({
73
- "../schema/src/lib/schema/impl/schema.ts"() {
74
- init_assert();
75
- Schema = class {
76
- constructor(fields, metadata) {
77
- assert(Array.isArray(fields));
78
- checkNames(fields);
79
- this.fields = fields;
80
- this.metadata = metadata || new Map();
81
- }
82
- compareTo(other) {
83
- if (this.metadata !== other.metadata) {
84
- return false;
85
- }
86
- if (this.fields.length !== other.fields.length) {
87
- return false;
88
- }
89
- for (let i = 0; i < this.fields.length; ++i) {
90
- if (!this.fields[i].compareTo(other.fields[i])) {
91
- return false;
92
- }
93
- }
94
- return true;
95
- }
96
- select(...columnNames) {
97
- const nameMap = Object.create(null);
98
- for (const name of columnNames) {
99
- nameMap[name] = true;
100
- }
101
- const selectedFields = this.fields.filter((field) => nameMap[field.name]);
102
- return new Schema(selectedFields, this.metadata);
103
- }
104
- selectAt(...columnIndices) {
105
- const selectedFields = columnIndices.map((index) => this.fields[index]).filter(Boolean);
106
- return new Schema(selectedFields, this.metadata);
107
- }
108
- assign(schemaOrFields) {
109
- let fields;
110
- let metadata = this.metadata;
111
- if (schemaOrFields instanceof Schema) {
112
- const otherSchema = schemaOrFields;
113
- fields = otherSchema.fields;
114
- metadata = mergeMaps(mergeMaps(new Map(), this.metadata), otherSchema.metadata);
115
- } else {
116
- fields = schemaOrFields;
117
- }
118
- const fieldMap = Object.create(null);
119
- for (const field of this.fields) {
120
- fieldMap[field.name] = field;
121
- }
122
- for (const field of fields) {
123
- fieldMap[field.name] = field;
124
- }
125
- const mergedFields = Object.values(fieldMap);
126
- return new Schema(mergedFields, metadata);
127
- }
128
- };
129
- }
130
- });
131
-
132
- // ../schema/src/lib/schema/impl/field.ts
133
- var Field;
134
- var init_field = __esm({
135
- "../schema/src/lib/schema/impl/field.ts"() {
136
- Field = class {
137
- constructor(name, type, nullable = false, metadata = new Map()) {
138
- this.name = name;
139
- this.type = type;
140
- this.nullable = nullable;
141
- this.metadata = metadata;
142
- }
143
- get typeId() {
144
- return this.type && this.type.typeId;
145
- }
146
- clone() {
147
- return new Field(this.name, this.type, this.nullable, this.metadata);
148
- }
149
- compareTo(other) {
150
- return this.name === other.name && this.type === other.type && this.nullable === other.nullable && this.metadata === other.metadata;
151
- }
152
- toString() {
153
- return `${this.type}${this.nullable ? ", nullable" : ""}${this.metadata ? `, metadata: ${this.metadata}` : ""}`;
154
- }
155
- };
156
- }
157
- });
158
-
159
- // ../schema/src/lib/schema/impl/enum.ts
160
- var Type;
161
- var init_enum = __esm({
162
- "../schema/src/lib/schema/impl/enum.ts"() {
163
- (function(Type2) {
164
- Type2[Type2["NONE"] = 0] = "NONE";
165
- Type2[Type2["Null"] = 1] = "Null";
166
- Type2[Type2["Int"] = 2] = "Int";
167
- Type2[Type2["Float"] = 3] = "Float";
168
- Type2[Type2["Binary"] = 4] = "Binary";
169
- Type2[Type2["Utf8"] = 5] = "Utf8";
170
- Type2[Type2["Bool"] = 6] = "Bool";
171
- Type2[Type2["Decimal"] = 7] = "Decimal";
172
- Type2[Type2["Date"] = 8] = "Date";
173
- Type2[Type2["Time"] = 9] = "Time";
174
- Type2[Type2["Timestamp"] = 10] = "Timestamp";
175
- Type2[Type2["Interval"] = 11] = "Interval";
176
- Type2[Type2["List"] = 12] = "List";
177
- Type2[Type2["Struct"] = 13] = "Struct";
178
- Type2[Type2["Union"] = 14] = "Union";
179
- Type2[Type2["FixedSizeBinary"] = 15] = "FixedSizeBinary";
180
- Type2[Type2["FixedSizeList"] = 16] = "FixedSizeList";
181
- Type2[Type2["Map"] = 17] = "Map";
182
- Type2[Type2["Dictionary"] = -1] = "Dictionary";
183
- Type2[Type2["Int8"] = -2] = "Int8";
184
- Type2[Type2["Int16"] = -3] = "Int16";
185
- Type2[Type2["Int32"] = -4] = "Int32";
186
- Type2[Type2["Int64"] = -5] = "Int64";
187
- Type2[Type2["Uint8"] = -6] = "Uint8";
188
- Type2[Type2["Uint16"] = -7] = "Uint16";
189
- Type2[Type2["Uint32"] = -8] = "Uint32";
190
- Type2[Type2["Uint64"] = -9] = "Uint64";
191
- Type2[Type2["Float16"] = -10] = "Float16";
192
- Type2[Type2["Float32"] = -11] = "Float32";
193
- Type2[Type2["Float64"] = -12] = "Float64";
194
- Type2[Type2["DateDay"] = -13] = "DateDay";
195
- Type2[Type2["DateMillisecond"] = -14] = "DateMillisecond";
196
- Type2[Type2["TimestampSecond"] = -15] = "TimestampSecond";
197
- Type2[Type2["TimestampMillisecond"] = -16] = "TimestampMillisecond";
198
- Type2[Type2["TimestampMicrosecond"] = -17] = "TimestampMicrosecond";
199
- Type2[Type2["TimestampNanosecond"] = -18] = "TimestampNanosecond";
200
- Type2[Type2["TimeSecond"] = -19] = "TimeSecond";
201
- Type2[Type2["TimeMillisecond"] = -20] = "TimeMillisecond";
202
- Type2[Type2["TimeMicrosecond"] = -21] = "TimeMicrosecond";
203
- Type2[Type2["TimeNanosecond"] = -22] = "TimeNanosecond";
204
- Type2[Type2["DenseUnion"] = -23] = "DenseUnion";
205
- Type2[Type2["SparseUnion"] = -24] = "SparseUnion";
206
- Type2[Type2["IntervalDayTime"] = -25] = "IntervalDayTime";
207
- Type2[Type2["IntervalYearMonth"] = -26] = "IntervalYearMonth";
208
- })(Type || (Type = {}));
209
- }
210
- });
211
-
212
- // ../schema/src/lib/schema/impl/type.ts
213
- var DataType, Null, Bool, Int, Uint8, Precision, Float, Float32, Binary, Utf8, DateUnit, Date, TimeUnit, Time, Timestamp, IntervalUnit, Interval, FixedSizeList, Struct;
214
- var init_type = __esm({
215
- "../schema/src/lib/schema/impl/type.ts"() {
216
- init_enum();
217
- DataType = class {
218
- static isNull(x) {
219
- return x && x.typeId === Type.Null;
220
- }
221
- static isInt(x) {
222
- return x && x.typeId === Type.Int;
223
- }
224
- static isFloat(x) {
225
- return x && x.typeId === Type.Float;
226
- }
227
- static isBinary(x) {
228
- return x && x.typeId === Type.Binary;
229
- }
230
- static isUtf8(x) {
231
- return x && x.typeId === Type.Utf8;
232
- }
233
- static isBool(x) {
234
- return x && x.typeId === Type.Bool;
235
- }
236
- static isDecimal(x) {
237
- return x && x.typeId === Type.Decimal;
238
- }
239
- static isDate(x) {
240
- return x && x.typeId === Type.Date;
241
- }
242
- static isTime(x) {
243
- return x && x.typeId === Type.Time;
244
- }
245
- static isTimestamp(x) {
246
- return x && x.typeId === Type.Timestamp;
247
- }
248
- static isInterval(x) {
249
- return x && x.typeId === Type.Interval;
250
- }
251
- static isList(x) {
252
- return x && x.typeId === Type.List;
253
- }
254
- static isStruct(x) {
255
- return x && x.typeId === Type.Struct;
256
- }
257
- static isUnion(x) {
258
- return x && x.typeId === Type.Union;
259
- }
260
- static isFixedSizeBinary(x) {
261
- return x && x.typeId === Type.FixedSizeBinary;
262
- }
263
- static isFixedSizeList(x) {
264
- return x && x.typeId === Type.FixedSizeList;
265
- }
266
- static isMap(x) {
267
- return x && x.typeId === Type.Map;
268
- }
269
- static isDictionary(x) {
270
- return x && x.typeId === Type.Dictionary;
271
- }
272
- get typeId() {
273
- return Type.NONE;
274
- }
275
- compareTo(other) {
276
- return this === other;
277
- }
278
- };
279
- Null = class extends DataType {
280
- get typeId() {
281
- return Type.Null;
282
- }
283
- get [Symbol.toStringTag]() {
284
- return "Null";
285
- }
286
- toString() {
287
- return "Null";
288
- }
289
- };
290
- Bool = class extends DataType {
291
- get typeId() {
292
- return Type.Bool;
293
- }
294
- get [Symbol.toStringTag]() {
295
- return "Bool";
296
- }
297
- toString() {
298
- return "Bool";
299
- }
300
- };
301
- Int = class extends DataType {
302
- constructor(isSigned, bitWidth) {
303
- super();
304
- this.isSigned = isSigned;
305
- this.bitWidth = bitWidth;
306
- }
307
- get typeId() {
308
- return Type.Int;
309
- }
310
- get [Symbol.toStringTag]() {
311
- return "Int";
312
- }
313
- toString() {
314
- return `${this.isSigned ? "I" : "Ui"}nt${this.bitWidth}`;
315
- }
316
- };
317
- Uint8 = class extends Int {
318
- constructor() {
319
- super(false, 8);
320
- }
321
- };
322
- Precision = {
323
- HALF: 16,
324
- SINGLE: 32,
325
- DOUBLE: 64
326
- };
327
- Float = class extends DataType {
328
- constructor(precision) {
329
- super();
330
- this.precision = precision;
331
- }
332
- get typeId() {
333
- return Type.Float;
334
- }
335
- get [Symbol.toStringTag]() {
336
- return "Float";
337
- }
338
- toString() {
339
- return `Float${this.precision}`;
340
- }
341
- };
342
- Float32 = class extends Float {
343
- constructor() {
344
- super(Precision.SINGLE);
345
- }
346
- };
347
- Binary = class extends DataType {
348
- constructor() {
349
- super();
350
- }
351
- get typeId() {
352
- return Type.Binary;
353
- }
354
- toString() {
355
- return "Binary";
356
- }
357
- get [Symbol.toStringTag]() {
358
- return "Binary";
359
- }
360
- };
361
- Utf8 = class extends DataType {
362
- get typeId() {
363
- return Type.Utf8;
364
- }
365
- get [Symbol.toStringTag]() {
366
- return "Utf8";
367
- }
368
- toString() {
369
- return "Utf8";
370
- }
371
- };
372
- DateUnit = {
373
- DAY: 0,
374
- MILLISECOND: 1
375
- };
376
- Date = class extends DataType {
377
- constructor(unit) {
378
- super();
379
- this.unit = unit;
380
- }
381
- get typeId() {
382
- return Type.Date;
383
- }
384
- get [Symbol.toStringTag]() {
385
- return "Date";
386
- }
387
- toString() {
388
- return `Date${(this.unit + 1) * 32}<${DateUnit[this.unit]}>`;
389
- }
390
- };
391
- TimeUnit = {
392
- SECOND: 1,
393
- MILLISECOND: 1e3,
394
- MICROSECOND: 1e6,
395
- NANOSECOND: 1e9
396
- };
397
- Time = class extends DataType {
398
- constructor(unit, bitWidth) {
399
- super();
400
- this.unit = unit;
401
- this.bitWidth = bitWidth;
402
- }
403
- get typeId() {
404
- return Type.Time;
405
- }
406
- toString() {
407
- return `Time${this.bitWidth}<${TimeUnit[this.unit]}>`;
408
- }
409
- get [Symbol.toStringTag]() {
410
- return "Time";
411
- }
412
- };
413
- Timestamp = class extends DataType {
414
- constructor(unit, timezone = null) {
415
- super();
416
- this.unit = unit;
417
- this.timezone = timezone;
418
- }
419
- get typeId() {
420
- return Type.Timestamp;
421
- }
422
- get [Symbol.toStringTag]() {
423
- return "Timestamp";
424
- }
425
- toString() {
426
- return `Timestamp<${TimeUnit[this.unit]}${this.timezone ? `, ${this.timezone}` : ""}>`;
427
- }
428
- };
429
- IntervalUnit = {
430
- DAY_TIME: 0,
431
- YEAR_MONTH: 1
432
- };
433
- Interval = class extends DataType {
434
- constructor(unit) {
435
- super();
436
- this.unit = unit;
437
- }
438
- get typeId() {
439
- return Type.Interval;
440
- }
441
- get [Symbol.toStringTag]() {
442
- return "Interval";
443
- }
444
- toString() {
445
- return `Interval<${IntervalUnit[this.unit]}>`;
446
- }
447
- };
448
- FixedSizeList = class extends DataType {
449
- constructor(listSize, child) {
450
- super();
451
- this.listSize = listSize;
452
- this.children = [child];
453
- }
454
- get typeId() {
455
- return Type.FixedSizeList;
456
- }
457
- get valueType() {
458
- return this.children[0].type;
459
- }
460
- get valueField() {
461
- return this.children[0];
462
- }
463
- get [Symbol.toStringTag]() {
464
- return "FixedSizeList";
465
- }
466
- toString() {
467
- return `FixedSizeList[${this.listSize}]<${this.valueType}>`;
468
- }
469
- };
470
- Struct = class extends DataType {
471
- constructor(children) {
472
- super();
473
- this.children = children;
474
- }
475
- get typeId() {
476
- return Type.Struct;
477
- }
478
- toString() {
479
- return `Struct<{${this.children.map((f) => `${f.name}:${f.type}`).join(", ")}}>`;
480
- }
481
- get [Symbol.toStringTag]() {
482
- return "Struct";
483
- }
484
- };
485
- }
486
- });
487
-
488
- // ../schema/src/lib/schema/schema.ts
489
- var init_schema2 = __esm({
490
- "../schema/src/lib/schema/schema.ts"() {
491
- init_schema();
492
- init_field();
493
- init_type();
43
+ "../schema/src/lib/mesh/mesh-utils.ts"() {
494
44
  }
495
45
  });
496
46
 
@@ -498,7 +48,6 @@
498
48
  var init_src = __esm({
499
49
  "../schema/src/index.ts"() {
500
50
  init_mesh_utils();
501
- init_schema2();
502
51
  }
503
52
  });
504
53
 
@@ -515,30 +64,37 @@
515
64
  ctrl = inData[inPtr++];
516
65
  if (ctrl < 1 << 5) {
517
66
  ctrl++;
518
- if (outPtr + ctrl > outLength)
67
+ if (outPtr + ctrl > outLength) {
519
68
  throw new Error("Output buffer is not large enough");
520
- if (inPtr + ctrl > inLength)
69
+ }
70
+ if (inPtr + ctrl > inLength) {
521
71
  throw new Error("Invalid compressed data");
72
+ }
522
73
  do {
523
74
  outData[outPtr++] = inData[inPtr++];
524
75
  } while (--ctrl);
525
76
  } else {
526
77
  len = ctrl >> 5;
527
78
  ref = outPtr - ((ctrl & 31) << 8) - 1;
528
- if (inPtr >= inLength)
79
+ if (inPtr >= inLength) {
529
80
  throw new Error("Invalid compressed data");
81
+ }
530
82
  if (len === 7) {
531
83
  len += inData[inPtr++];
532
- if (inPtr >= inLength)
84
+ if (inPtr >= inLength) {
533
85
  throw new Error("Invalid compressed data");
86
+ }
534
87
  }
535
88
  ref -= inData[inPtr++];
536
- if (outPtr + len + 2 > outLength)
89
+ if (outPtr + len + 2 > outLength) {
537
90
  throw new Error("Output buffer is not large enough");
538
- if (ref < 0)
91
+ }
92
+ if (ref < 0) {
539
93
  throw new Error("Invalid compressed data");
540
- if (ref >= outPtr)
94
+ }
95
+ if (ref >= outPtr) {
541
96
  throw new Error("Invalid compressed data");
97
+ }
542
98
  do {
543
99
  outData[outPtr++] = outData[ref++];
544
100
  } while (--len + 2);
@@ -556,19 +112,27 @@
556
112
  const offset = PCDheader.offset;
557
113
  const fields = [];
558
114
  if (offset.x !== void 0) {
559
- fields.push(new Field("POSITION", new FixedSizeList(3, new Field("xyz", new Float32())), false));
115
+ fields.push({
116
+ name: "POSITION",
117
+ type: { type: "fixed-size-list", listSize: 3, children: [{ name: "xyz", type: "float32" }] }
118
+ });
560
119
  }
561
120
  if (offset.normal_x !== void 0) {
562
- fields.push(new Field("NORMAL", new FixedSizeList(3, new Field("xyz", new Float32())), false));
121
+ fields.push({
122
+ name: "NORMAL",
123
+ type: { type: "fixed-size-list", listSize: 3, children: [{ name: "xyz", type: "float32" }] }
124
+ });
563
125
  }
564
126
  if (offset.rgb !== void 0) {
565
- fields.push(new Field("COLOR_0", new FixedSizeList(3, new Field("rgb", new Uint8())), false));
127
+ fields.push({
128
+ name: "COLOR_0",
129
+ type: { type: "fixed-size-list", listSize: 3, children: [{ name: "rgb", type: "uint8" }] }
130
+ });
566
131
  }
567
- return new Schema(fields, metadata);
132
+ return { fields, metadata };
568
133
  }
569
134
  var init_get_pcd_schema = __esm({
570
135
  "src/lib/get-pcd-schema.ts"() {
571
- init_src();
572
136
  }
573
137
  });
574
138
 
@@ -592,19 +156,18 @@
592
156
  }
593
157
  attributes = getMeshAttributes(attributes);
594
158
  const header = getMeshHeader(pcdHeader, attributes);
595
- const metadata = new Map([
159
+ const metadata = Object.fromEntries([
596
160
  ["mode", "0"],
597
161
  ["boundingBox", JSON.stringify(header.boundingBox)]
598
162
  ]);
599
163
  const schema = getPCDSchema(pcdHeader, metadata);
600
164
  return {
601
- loaderData: {
602
- header: pcdHeader
603
- },
165
+ loader: "pcd",
166
+ loaderData: pcdHeader,
604
167
  header,
605
168
  schema,
606
169
  mode: 0,
607
- indices: null,
170
+ topology: "point-list",
608
171
  attributes
609
172
  };
610
173
  }
@@ -616,7 +179,10 @@
616
179
  boundingBox: getMeshBoundingBox(attributes)
617
180
  };
618
181
  }
619
- return pcdHeader;
182
+ return {
183
+ vertexCount: pcdHeader.vertexCount,
184
+ boundingBox: pcdHeader.boundingBox
185
+ };
620
186
  }
621
187
  function getMeshAttributes(attributes) {
622
188
  const normalizedAttributes = {
@@ -637,6 +203,18 @@
637
203
  size: 3
638
204
  };
639
205
  }
206
+ if (attributes.intensity && attributes.intensity.length > 0) {
207
+ normalizedAttributes.COLOR_0 = {
208
+ value: new Uint8Array(attributes.color),
209
+ size: 3
210
+ };
211
+ }
212
+ if (attributes.label && attributes.label.length > 0) {
213
+ normalizedAttributes.COLOR_0 = {
214
+ value: new Uint8Array(attributes.label),
215
+ size: 3
216
+ };
217
+ }
640
218
  return normalizedAttributes;
641
219
  }
642
220
  function parsePCDHeader(data) {
@@ -714,6 +292,8 @@
714
292
  const position = [];
715
293
  const normal = [];
716
294
  const color = [];
295
+ const intensity = [];
296
+ const label = [];
717
297
  const offset = pcdHeader.offset;
718
298
  const pcdData = textData.substr(pcdHeader.headerLen);
719
299
  const lines = pcdData.split("\n");
@@ -738,6 +318,12 @@
738
318
  normal.push(parseFloat(line[offset.normal_y]));
739
319
  normal.push(parseFloat(line[offset.normal_z]));
740
320
  }
321
+ if (offset.intensity !== void 0) {
322
+ intensity.push(parseFloat(line[offset.intensity]));
323
+ }
324
+ if (offset.label !== void 0) {
325
+ label.push(parseInt(line[offset.label]));
326
+ }
741
327
  }
742
328
  }
743
329
  return { position, normal, color };
@@ -746,6 +332,8 @@
746
332
  const position = [];
747
333
  const normal = [];
748
334
  const color = [];
335
+ const intensity = [];
336
+ const label = [];
749
337
  const dataview = new DataView(data, pcdHeader.headerLen);
750
338
  const offset = pcdHeader.offset;
751
339
  for (let i = 0, row = 0; i < pcdHeader.points; i++, row += pcdHeader.rowSize) {
@@ -764,40 +352,58 @@
764
352
  normal.push(dataview.getFloat32(row + offset.normal_y, LITTLE_ENDIAN));
765
353
  normal.push(dataview.getFloat32(row + offset.normal_z, LITTLE_ENDIAN));
766
354
  }
355
+ if (offset.intensity !== void 0) {
356
+ intensity.push(dataview.getFloat32(row + offset.intensity, LITTLE_ENDIAN));
357
+ }
358
+ if (offset.label !== void 0) {
359
+ label.push(dataview.getInt32(row + offset.label, LITTLE_ENDIAN));
360
+ }
767
361
  }
768
- return { position, normal, color };
362
+ return { position, normal, color, intensity, label };
769
363
  }
770
- function parsePCDBinaryCompressed(PCDheader, data) {
364
+ function parsePCDBinaryCompressed(pcdHeader, data) {
771
365
  const position = [];
772
366
  const normal = [];
773
367
  const color = [];
774
- const sizes = new Uint32Array(data.slice(PCDheader.headerLen, PCDheader.headerLen + 8));
368
+ const intensity = [];
369
+ const label = [];
370
+ const sizes = new Uint32Array(data.slice(pcdHeader.headerLen, pcdHeader.headerLen + 8));
775
371
  const compressedSize = sizes[0];
776
372
  const decompressedSize = sizes[1];
777
- const decompressed = decompressLZF(new Uint8Array(data, PCDheader.headerLen + 8, compressedSize), decompressedSize);
373
+ const decompressed = decompressLZF(new Uint8Array(data, pcdHeader.headerLen + 8, compressedSize), decompressedSize);
778
374
  const dataview = new DataView(decompressed.buffer);
779
- const offset = PCDheader.offset;
780
- for (let i = 0; i < PCDheader.points; i++) {
375
+ const offset = pcdHeader.offset;
376
+ for (let i = 0; i < pcdHeader.points; i++) {
781
377
  if (offset.x !== void 0) {
782
- position.push(dataview.getFloat32(PCDheader.points * offset.x + PCDheader.size[0] * i, LITTLE_ENDIAN));
783
- position.push(dataview.getFloat32(PCDheader.points * offset.y + PCDheader.size[1] * i, LITTLE_ENDIAN));
784
- position.push(dataview.getFloat32(PCDheader.points * offset.z + PCDheader.size[2] * i, LITTLE_ENDIAN));
378
+ position.push(dataview.getFloat32(pcdHeader.points * offset.x + pcdHeader.size[0] * i, LITTLE_ENDIAN));
379
+ position.push(dataview.getFloat32(pcdHeader.points * offset.y + pcdHeader.size[1] * i, LITTLE_ENDIAN));
380
+ position.push(dataview.getFloat32(pcdHeader.points * offset.z + pcdHeader.size[2] * i, LITTLE_ENDIAN));
785
381
  }
786
382
  if (offset.rgb !== void 0) {
787
- color.push(dataview.getUint8(PCDheader.points * offset.rgb + PCDheader.size[3] * i + 0) / 255);
788
- color.push(dataview.getUint8(PCDheader.points * offset.rgb + PCDheader.size[3] * i + 1) / 255);
789
- color.push(dataview.getUint8(PCDheader.points * offset.rgb + PCDheader.size[3] * i + 2) / 255);
383
+ color.push(dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 0) / 255);
384
+ color.push(dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 1) / 255);
385
+ color.push(dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 2) / 255);
790
386
  }
791
387
  if (offset.normal_x !== void 0) {
792
- normal.push(dataview.getFloat32(PCDheader.points * offset.normal_x + PCDheader.size[4] * i, LITTLE_ENDIAN));
793
- normal.push(dataview.getFloat32(PCDheader.points * offset.normal_y + PCDheader.size[5] * i, LITTLE_ENDIAN));
794
- normal.push(dataview.getFloat32(PCDheader.points * offset.normal_z + PCDheader.size[6] * i, LITTLE_ENDIAN));
388
+ normal.push(dataview.getFloat32(pcdHeader.points * offset.normal_x + pcdHeader.size[4] * i, LITTLE_ENDIAN));
389
+ normal.push(dataview.getFloat32(pcdHeader.points * offset.normal_y + pcdHeader.size[5] * i, LITTLE_ENDIAN));
390
+ normal.push(dataview.getFloat32(pcdHeader.points * offset.normal_z + pcdHeader.size[6] * i, LITTLE_ENDIAN));
391
+ }
392
+ if (offset.intensity !== void 0) {
393
+ const intensityIndex = pcdHeader.fields.indexOf("intensity");
394
+ intensity.push(dataview.getFloat32(pcdHeader.points * offset.intensity + pcdHeader.size[intensityIndex] * i, LITTLE_ENDIAN));
395
+ }
396
+ if (offset.label !== void 0) {
397
+ const labelIndex = pcdHeader.fields.indexOf("label");
398
+ label.push(dataview.getInt32(pcdHeader.points * offset.label + pcdHeader.size[labelIndex] * i, LITTLE_ENDIAN));
795
399
  }
796
400
  }
797
401
  return {
798
402
  position,
799
403
  normal,
800
- color
404
+ color,
405
+ intensity,
406
+ label
801
407
  };
802
408
  }
803
409
  var LITTLE_ENDIAN;