@loaders.gl/pcd 4.0.0-beta.2 → 4.0.0-beta.4

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 (46) hide show
  1. package/dist/{dist.min.js → dist.dev.js} +90 -95
  2. package/dist/index.cjs +449 -0
  3. package/dist/{esm/index.js → index.js} +2 -2
  4. package/dist/index.js.map +1 -0
  5. package/dist/lib/decompress-lzf.js.map +1 -0
  6. package/dist/lib/get-pcd-schema.js.map +1 -0
  7. package/dist/{esm/lib → lib}/parse-pcd.js +3 -3
  8. package/dist/lib/parse-pcd.js.map +1 -0
  9. package/dist/lib/pcd-types.js.map +1 -0
  10. package/dist/{esm/pcd-loader.js → pcd-loader.js} +1 -1
  11. package/dist/pcd-loader.js.map +1 -0
  12. package/dist/pcd-worker.js +68 -15
  13. package/dist/{esm/workers → workers}/pcd-worker.js +1 -1
  14. package/dist/workers/pcd-worker.js.map +1 -0
  15. package/package.json +16 -8
  16. package/dist/bundle.d.ts +0 -2
  17. package/dist/bundle.d.ts.map +0 -1
  18. package/dist/es5/bundle.js +0 -6
  19. package/dist/es5/bundle.js.map +0 -1
  20. package/dist/es5/index.js +0 -42
  21. package/dist/es5/index.js.map +0 -1
  22. package/dist/es5/lib/decompress-lzf.js +0 -57
  23. package/dist/es5/lib/decompress-lzf.js.map +0 -1
  24. package/dist/es5/lib/get-pcd-schema.js +0 -54
  25. package/dist/es5/lib/get-pcd-schema.js.map +0 -1
  26. package/dist/es5/lib/parse-pcd.js +0 -299
  27. package/dist/es5/lib/parse-pcd.js.map +0 -1
  28. package/dist/es5/lib/pcd-types.js +0 -2
  29. package/dist/es5/lib/pcd-types.js.map +0 -1
  30. package/dist/es5/pcd-loader.js +0 -21
  31. package/dist/es5/pcd-loader.js.map +0 -1
  32. package/dist/es5/workers/pcd-worker.js +0 -6
  33. package/dist/es5/workers/pcd-worker.js.map +0 -1
  34. package/dist/esm/bundle.js +0 -4
  35. package/dist/esm/bundle.js.map +0 -1
  36. package/dist/esm/index.js.map +0 -1
  37. package/dist/esm/lib/decompress-lzf.js.map +0 -1
  38. package/dist/esm/lib/get-pcd-schema.js.map +0 -1
  39. package/dist/esm/lib/parse-pcd.js.map +0 -1
  40. package/dist/esm/lib/pcd-types.js.map +0 -1
  41. package/dist/esm/pcd-loader.js.map +0 -1
  42. package/dist/esm/workers/pcd-worker.js.map +0 -1
  43. package/src/bundle.ts +0 -4
  44. /package/dist/{esm/lib → lib}/decompress-lzf.js +0 -0
  45. /package/dist/{esm/lib → lib}/get-pcd-schema.js +0 -0
  46. /package/dist/{esm/lib → lib}/pcd-types.js +0 -0
@@ -1,17 +1,35 @@
1
- (() => {
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if (typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory();
4
+ else if (typeof define === 'function' && define.amd) define([], factory);
5
+ else if (typeof exports === 'object') exports['loader'] = factory();
6
+ else root['loader'] = factory();})(globalThis, function () {
7
+ "use strict";
8
+ var __exports__ = (() => {
2
9
  var __defProp = Object.defineProperty;
3
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
4
- var __esm = (fn, res) => function __init() {
5
- return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
6
- };
7
- var __commonJS = (cb, mod) => function __require() {
8
- return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
- };
10
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
+ var __getOwnPropNames = Object.getOwnPropertyNames;
12
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
13
  var __export = (target, all) => {
11
- __markAsModule(target);
12
14
  for (var name in all)
13
15
  __defProp(target, name, { get: all[name], enumerable: true });
14
16
  };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
+
27
+ // src/index.ts
28
+ var src_exports = {};
29
+ __export(src_exports, {
30
+ PCDLoader: () => PCDLoader2,
31
+ PCDWorkerLoader: () => PCDLoader
32
+ });
15
33
 
16
34
  // ../schema/src/lib/mesh/mesh-utils.ts
17
35
  function getMeshBoundingBox(attributes) {
@@ -34,22 +52,8 @@
34
52
  maxY = y > maxY ? y : maxY;
35
53
  maxZ = z > maxZ ? z : maxZ;
36
54
  }
37
- return [
38
- [minX, minY, minZ],
39
- [maxX, maxY, maxZ]
40
- ];
55
+ return [[minX, minY, minZ], [maxX, maxY, maxZ]];
41
56
  }
42
- var init_mesh_utils = __esm({
43
- "../schema/src/lib/mesh/mesh-utils.ts"() {
44
- }
45
- });
46
-
47
- // ../schema/src/index.ts
48
- var init_src = __esm({
49
- "../schema/src/index.ts"() {
50
- init_mesh_utils();
51
- }
52
- });
53
57
 
54
58
  // src/lib/decompress-lzf.ts
55
59
  function decompressLZF(inData, outLength) {
@@ -102,10 +106,6 @@
102
106
  } while (inPtr < inLength);
103
107
  return outData;
104
108
  }
105
- var init_decompress_lzf = __esm({
106
- "src/lib/decompress-lzf.ts"() {
107
- }
108
- });
109
109
 
110
110
  // src/lib/get-pcd-schema.ts
111
111
  function getPCDSchema(PCDheader, metadata) {
@@ -114,29 +114,50 @@
114
114
  if (offset.x !== void 0) {
115
115
  fields.push({
116
116
  name: "POSITION",
117
- type: { type: "fixed-size-list", listSize: 3, children: [{ name: "xyz", type: "float32" }] }
117
+ type: {
118
+ type: "fixed-size-list",
119
+ listSize: 3,
120
+ children: [{
121
+ name: "xyz",
122
+ type: "float32"
123
+ }]
124
+ }
118
125
  });
119
126
  }
120
127
  if (offset.normal_x !== void 0) {
121
128
  fields.push({
122
129
  name: "NORMAL",
123
- type: { type: "fixed-size-list", listSize: 3, children: [{ name: "xyz", type: "float32" }] }
130
+ type: {
131
+ type: "fixed-size-list",
132
+ listSize: 3,
133
+ children: [{
134
+ name: "xyz",
135
+ type: "float32"
136
+ }]
137
+ }
124
138
  });
125
139
  }
126
140
  if (offset.rgb !== void 0) {
127
141
  fields.push({
128
142
  name: "COLOR_0",
129
- type: { type: "fixed-size-list", listSize: 3, children: [{ name: "rgb", type: "uint8" }] }
143
+ type: {
144
+ type: "fixed-size-list",
145
+ listSize: 3,
146
+ children: [{
147
+ name: "rgb",
148
+ type: "uint8"
149
+ }]
150
+ }
130
151
  });
131
152
  }
132
- return { fields, metadata };
153
+ return {
154
+ fields,
155
+ metadata
156
+ };
133
157
  }
134
- var init_get_pcd_schema = __esm({
135
- "src/lib/get-pcd-schema.ts"() {
136
- }
137
- });
138
158
 
139
159
  // src/lib/parse-pcd.ts
160
+ var LITTLE_ENDIAN = true;
140
161
  function parsePCD(data) {
141
162
  const textData = new TextDecoder().decode(data);
142
163
  const pcdHeader = parsePCDHeader(textData);
@@ -156,10 +177,7 @@
156
177
  }
157
178
  attributes = getMeshAttributes(attributes);
158
179
  const header = getMeshHeader(pcdHeader, attributes);
159
- const metadata = Object.fromEntries([
160
- ["mode", "0"],
161
- ["boundingBox", JSON.stringify(header.boundingBox)]
162
- ]);
180
+ const metadata = Object.fromEntries([["mode", "0"], ["boundingBox", JSON.stringify(header.boundingBox)]]);
163
181
  const schema = getPCDSchema(pcdHeader, metadata);
164
182
  return {
165
183
  loader: "pcd",
@@ -326,7 +344,11 @@
326
344
  }
327
345
  }
328
346
  }
329
- return { position, normal, color };
347
+ return {
348
+ position,
349
+ normal,
350
+ color
351
+ };
330
352
  }
331
353
  function parsePCDBinary(pcdHeader, data) {
332
354
  const position = [];
@@ -359,7 +381,13 @@
359
381
  label.push(dataview.getInt32(row + offset.label, LITTLE_ENDIAN));
360
382
  }
361
383
  }
362
- return { position, normal, color, intensity, label };
384
+ return {
385
+ position,
386
+ normal,
387
+ color,
388
+ intensity,
389
+ label
390
+ };
363
391
  }
364
392
  function parsePCDBinaryCompressed(pcdHeader, data) {
365
393
  const position = [];
@@ -406,64 +434,29 @@
406
434
  label
407
435
  };
408
436
  }
409
- var LITTLE_ENDIAN;
410
- var init_parse_pcd = __esm({
411
- "src/lib/parse-pcd.ts"() {
412
- init_src();
413
- init_decompress_lzf();
414
- init_get_pcd_schema();
415
- LITTLE_ENDIAN = true;
416
- }
417
- });
418
437
 
419
438
  // src/pcd-loader.ts
420
- var VERSION, PCDLoader;
421
- var init_pcd_loader = __esm({
422
- "src/pcd-loader.ts"() {
423
- VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
424
- PCDLoader = {
425
- name: "PCD (Point Cloud Data)",
426
- id: "pcd",
427
- module: "pcd",
428
- version: VERSION,
429
- worker: true,
430
- extensions: ["pcd"],
431
- mimeTypes: ["text/plain"],
432
- options: {
433
- pcd: {}
434
- }
435
- };
439
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
440
+ var PCDLoader = {
441
+ name: "PCD (Point Cloud Data)",
442
+ id: "pcd",
443
+ module: "pcd",
444
+ version: VERSION,
445
+ worker: true,
446
+ extensions: ["pcd"],
447
+ mimeTypes: ["text/plain"],
448
+ options: {
449
+ pcd: {}
436
450
  }
437
- });
451
+ };
438
452
 
439
453
  // src/index.ts
440
- var src_exports = {};
441
- __export(src_exports, {
442
- PCDLoader: () => PCDLoader2,
443
- PCDWorkerLoader: () => PCDLoader
444
- });
445
- var PCDLoader2;
446
- var init_src2 = __esm({
447
- "src/index.ts"() {
448
- init_parse_pcd();
449
- init_pcd_loader();
450
- PCDLoader2 = {
451
- ...PCDLoader,
452
- parse: async (arrayBuffer) => parsePCD(arrayBuffer),
453
- parseSync: parsePCD
454
- };
455
- }
456
- });
457
-
458
- // src/bundle.ts
459
- var require_bundle = __commonJS({
460
- "src/bundle.ts"(exports, module) {
461
- var moduleExports = (init_src2(), src_exports);
462
- globalThis.loaders = globalThis.loaders || {};
463
- module.exports = Object.assign(globalThis.loaders, moduleExports);
464
- }
465
- });
466
- require_bundle();
454
+ var PCDLoader2 = {
455
+ ...PCDLoader,
456
+ parse: async (arrayBuffer) => parsePCD(arrayBuffer),
457
+ parseSync: parsePCD
458
+ };
459
+ return __toCommonJS(src_exports);
467
460
  })();
468
461
  /** Parse compressed PCD data in in binary_compressed form ( https://pointclouds.org/documentation/tutorials/pcd_file_format.html)
469
462
  * from https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/PCDLoader.js
@@ -472,3 +465,5 @@
472
465
  * @param data
473
466
  * @returns [attributes]
474
467
  */
468
+ return __exports__;
469
+ });
package/dist/index.cjs ADDED
@@ -0,0 +1,449 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ PCDLoader: () => PCDLoader2,
24
+ PCDWorkerLoader: () => PCDLoader
25
+ });
26
+ module.exports = __toCommonJS(src_exports);
27
+
28
+ // src/lib/parse-pcd.ts
29
+ var import_schema = require("@loaders.gl/schema");
30
+
31
+ // src/lib/decompress-lzf.ts
32
+ function decompressLZF(inData, outLength) {
33
+ const inLength = inData.length;
34
+ const outData = new Uint8Array(outLength);
35
+ let inPtr = 0;
36
+ let outPtr = 0;
37
+ let ctrl;
38
+ let len;
39
+ let ref;
40
+ do {
41
+ ctrl = inData[inPtr++];
42
+ if (ctrl < 1 << 5) {
43
+ ctrl++;
44
+ if (outPtr + ctrl > outLength) {
45
+ throw new Error("Output buffer is not large enough");
46
+ }
47
+ if (inPtr + ctrl > inLength) {
48
+ throw new Error("Invalid compressed data");
49
+ }
50
+ do {
51
+ outData[outPtr++] = inData[inPtr++];
52
+ } while (--ctrl);
53
+ } else {
54
+ len = ctrl >> 5;
55
+ ref = outPtr - ((ctrl & 31) << 8) - 1;
56
+ if (inPtr >= inLength) {
57
+ throw new Error("Invalid compressed data");
58
+ }
59
+ if (len === 7) {
60
+ len += inData[inPtr++];
61
+ if (inPtr >= inLength) {
62
+ throw new Error("Invalid compressed data");
63
+ }
64
+ }
65
+ ref -= inData[inPtr++];
66
+ if (outPtr + len + 2 > outLength) {
67
+ throw new Error("Output buffer is not large enough");
68
+ }
69
+ if (ref < 0) {
70
+ throw new Error("Invalid compressed data");
71
+ }
72
+ if (ref >= outPtr) {
73
+ throw new Error("Invalid compressed data");
74
+ }
75
+ do {
76
+ outData[outPtr++] = outData[ref++];
77
+ } while (--len + 2);
78
+ }
79
+ } while (inPtr < inLength);
80
+ return outData;
81
+ }
82
+
83
+ // src/lib/get-pcd-schema.ts
84
+ function getPCDSchema(PCDheader, metadata) {
85
+ const offset = PCDheader.offset;
86
+ const fields = [];
87
+ if (offset.x !== void 0) {
88
+ fields.push({
89
+ name: "POSITION",
90
+ type: { type: "fixed-size-list", listSize: 3, children: [{ name: "xyz", type: "float32" }] }
91
+ });
92
+ }
93
+ if (offset.normal_x !== void 0) {
94
+ fields.push({
95
+ name: "NORMAL",
96
+ type: { type: "fixed-size-list", listSize: 3, children: [{ name: "xyz", type: "float32" }] }
97
+ });
98
+ }
99
+ if (offset.rgb !== void 0) {
100
+ fields.push({
101
+ name: "COLOR_0",
102
+ type: { type: "fixed-size-list", listSize: 3, children: [{ name: "rgb", type: "uint8" }] }
103
+ });
104
+ }
105
+ return { fields, metadata };
106
+ }
107
+
108
+ // src/lib/parse-pcd.ts
109
+ var LITTLE_ENDIAN = true;
110
+ function parsePCD(data) {
111
+ const textData = new TextDecoder().decode(data);
112
+ const pcdHeader = parsePCDHeader(textData);
113
+ let attributes = {};
114
+ switch (pcdHeader.data) {
115
+ case "ascii":
116
+ attributes = parsePCDASCII(pcdHeader, textData);
117
+ break;
118
+ case "binary":
119
+ attributes = parsePCDBinary(pcdHeader, data);
120
+ break;
121
+ case "binary_compressed":
122
+ attributes = parsePCDBinaryCompressed(pcdHeader, data);
123
+ break;
124
+ default:
125
+ throw new Error(`PCD: ${pcdHeader.data} files are not supported`);
126
+ }
127
+ attributes = getMeshAttributes(attributes);
128
+ const header = getMeshHeader(pcdHeader, attributes);
129
+ const metadata = Object.fromEntries([
130
+ ["mode", "0"],
131
+ ["boundingBox", JSON.stringify(header.boundingBox)]
132
+ ]);
133
+ const schema = getPCDSchema(pcdHeader, metadata);
134
+ return {
135
+ loader: "pcd",
136
+ loaderData: pcdHeader,
137
+ header,
138
+ schema,
139
+ mode: 0,
140
+ // POINTS
141
+ topology: "point-list",
142
+ attributes
143
+ };
144
+ }
145
+ function getMeshHeader(pcdHeader, attributes) {
146
+ if (typeof pcdHeader.width === "number" && typeof pcdHeader.height === "number") {
147
+ const pointCount = pcdHeader.width * pcdHeader.height;
148
+ return {
149
+ vertexCount: pointCount,
150
+ boundingBox: (0, import_schema.getMeshBoundingBox)(attributes)
151
+ };
152
+ }
153
+ return {
154
+ vertexCount: pcdHeader.vertexCount,
155
+ boundingBox: pcdHeader.boundingBox
156
+ };
157
+ }
158
+ function getMeshAttributes(attributes) {
159
+ const normalizedAttributes = {
160
+ POSITION: {
161
+ // Binary PCD is only 32 bit
162
+ value: new Float32Array(attributes.position),
163
+ size: 3
164
+ }
165
+ };
166
+ if (attributes.normal && attributes.normal.length > 0) {
167
+ normalizedAttributes.NORMAL = {
168
+ value: new Float32Array(attributes.normal),
169
+ size: 3
170
+ };
171
+ }
172
+ if (attributes.color && attributes.color.length > 0) {
173
+ normalizedAttributes.COLOR_0 = {
174
+ value: new Uint8Array(attributes.color),
175
+ size: 3
176
+ };
177
+ }
178
+ if (attributes.intensity && attributes.intensity.length > 0) {
179
+ normalizedAttributes.COLOR_0 = {
180
+ value: new Uint8Array(attributes.color),
181
+ size: 3
182
+ };
183
+ }
184
+ if (attributes.label && attributes.label.length > 0) {
185
+ normalizedAttributes.COLOR_0 = {
186
+ value: new Uint8Array(attributes.label),
187
+ size: 3
188
+ };
189
+ }
190
+ return normalizedAttributes;
191
+ }
192
+ function parsePCDHeader(data) {
193
+ const result1 = data.search(/[\r\n]DATA\s(\S*)\s/i);
194
+ const result2 = /[\r\n]DATA\s(\S*)\s/i.exec(data.substr(result1 - 1));
195
+ const pcdHeader = {};
196
+ pcdHeader.data = result2 && result2[1];
197
+ if (result2 !== null) {
198
+ pcdHeader.headerLen = (result2 && result2[0].length) + result1;
199
+ }
200
+ pcdHeader.str = data.substr(0, pcdHeader.headerLen);
201
+ pcdHeader.str = pcdHeader.str.replace(/\#.*/gi, "");
202
+ pcdHeader.version = /VERSION (.*)/i.exec(pcdHeader.str);
203
+ pcdHeader.fields = /FIELDS (.*)/i.exec(pcdHeader.str);
204
+ pcdHeader.size = /SIZE (.*)/i.exec(pcdHeader.str);
205
+ pcdHeader.type = /TYPE (.*)/i.exec(pcdHeader.str);
206
+ pcdHeader.count = /COUNT (.*)/i.exec(pcdHeader.str);
207
+ pcdHeader.width = /WIDTH (.*)/i.exec(pcdHeader.str);
208
+ pcdHeader.height = /HEIGHT (.*)/i.exec(pcdHeader.str);
209
+ pcdHeader.viewpoint = /VIEWPOINT (.*)/i.exec(pcdHeader.str);
210
+ pcdHeader.points = /POINTS (.*)/i.exec(pcdHeader.str);
211
+ if (pcdHeader.version !== null) {
212
+ pcdHeader.version = parseFloat(pcdHeader.version[1]);
213
+ }
214
+ if (pcdHeader.fields !== null) {
215
+ pcdHeader.fields = pcdHeader.fields[1].split(" ");
216
+ }
217
+ if (pcdHeader.type !== null) {
218
+ pcdHeader.type = pcdHeader.type[1].split(" ");
219
+ }
220
+ if (pcdHeader.width !== null) {
221
+ pcdHeader.width = parseInt(pcdHeader.width[1], 10);
222
+ }
223
+ if (pcdHeader.height !== null) {
224
+ pcdHeader.height = parseInt(pcdHeader.height[1], 10);
225
+ }
226
+ if (pcdHeader.viewpoint !== null) {
227
+ pcdHeader.viewpoint = pcdHeader.viewpoint[1];
228
+ }
229
+ if (pcdHeader.points !== null) {
230
+ pcdHeader.points = parseInt(pcdHeader.points[1], 10);
231
+ }
232
+ if (pcdHeader.points === null && typeof pcdHeader.width === "number" && typeof pcdHeader.height === "number") {
233
+ pcdHeader.points = pcdHeader.width * pcdHeader.height;
234
+ }
235
+ if (pcdHeader.size !== null) {
236
+ pcdHeader.size = pcdHeader.size[1].split(" ").map((x) => parseInt(x, 10));
237
+ }
238
+ if (pcdHeader.count !== null) {
239
+ pcdHeader.count = pcdHeader.count[1].split(" ").map((x) => parseInt(x, 10));
240
+ } else {
241
+ pcdHeader.count = [];
242
+ if (pcdHeader.fields !== null) {
243
+ for (let i = 0; i < pcdHeader.fields.length; i++) {
244
+ pcdHeader.count.push(1);
245
+ }
246
+ }
247
+ }
248
+ pcdHeader.offset = {};
249
+ let sizeSum = 0;
250
+ if (pcdHeader.fields !== null && pcdHeader.size !== null) {
251
+ for (let i = 0; i < pcdHeader.fields.length; i++) {
252
+ if (pcdHeader.data === "ascii") {
253
+ pcdHeader.offset[pcdHeader.fields[i]] = i;
254
+ } else {
255
+ pcdHeader.offset[pcdHeader.fields[i]] = sizeSum;
256
+ sizeSum += pcdHeader.size[i];
257
+ }
258
+ }
259
+ }
260
+ pcdHeader.rowSize = sizeSum;
261
+ return pcdHeader;
262
+ }
263
+ function parsePCDASCII(pcdHeader, textData) {
264
+ const position = [];
265
+ const normal = [];
266
+ const color = [];
267
+ const intensity = [];
268
+ const label = [];
269
+ const offset = pcdHeader.offset;
270
+ const pcdData = textData.substr(pcdHeader.headerLen);
271
+ const lines = pcdData.split("\n");
272
+ for (let i = 0; i < lines.length; i++) {
273
+ if (lines[i] !== "") {
274
+ const line = lines[i].split(" ");
275
+ if (offset.x !== void 0) {
276
+ position.push(parseFloat(line[offset.x]));
277
+ position.push(parseFloat(line[offset.y]));
278
+ position.push(parseFloat(line[offset.z]));
279
+ }
280
+ if (offset.rgb !== void 0) {
281
+ const floatValue = parseFloat(line[offset.rgb]);
282
+ const binaryColor = new Float32Array([floatValue]);
283
+ const dataview = new DataView(binaryColor.buffer, 0);
284
+ color.push(dataview.getUint8(0));
285
+ color.push(dataview.getUint8(1));
286
+ color.push(dataview.getUint8(2));
287
+ }
288
+ if (offset.normal_x !== void 0) {
289
+ normal.push(parseFloat(line[offset.normal_x]));
290
+ normal.push(parseFloat(line[offset.normal_y]));
291
+ normal.push(parseFloat(line[offset.normal_z]));
292
+ }
293
+ if (offset.intensity !== void 0) {
294
+ intensity.push(parseFloat(line[offset.intensity]));
295
+ }
296
+ if (offset.label !== void 0) {
297
+ label.push(parseInt(line[offset.label]));
298
+ }
299
+ }
300
+ }
301
+ return { position, normal, color };
302
+ }
303
+ function parsePCDBinary(pcdHeader, data) {
304
+ const position = [];
305
+ const normal = [];
306
+ const color = [];
307
+ const intensity = [];
308
+ const label = [];
309
+ const dataview = new DataView(data, pcdHeader.headerLen);
310
+ const offset = pcdHeader.offset;
311
+ for (let i = 0, row = 0; i < pcdHeader.points; i++, row += pcdHeader.rowSize) {
312
+ if (offset.x !== void 0) {
313
+ position.push(dataview.getFloat32(row + offset.x, LITTLE_ENDIAN));
314
+ position.push(dataview.getFloat32(row + offset.y, LITTLE_ENDIAN));
315
+ position.push(dataview.getFloat32(row + offset.z, LITTLE_ENDIAN));
316
+ }
317
+ if (offset.rgb !== void 0) {
318
+ color.push(dataview.getUint8(row + offset.rgb + 0));
319
+ color.push(dataview.getUint8(row + offset.rgb + 1));
320
+ color.push(dataview.getUint8(row + offset.rgb + 2));
321
+ }
322
+ if (offset.normal_x !== void 0) {
323
+ normal.push(dataview.getFloat32(row + offset.normal_x, LITTLE_ENDIAN));
324
+ normal.push(dataview.getFloat32(row + offset.normal_y, LITTLE_ENDIAN));
325
+ normal.push(dataview.getFloat32(row + offset.normal_z, LITTLE_ENDIAN));
326
+ }
327
+ if (offset.intensity !== void 0) {
328
+ intensity.push(dataview.getFloat32(row + offset.intensity, LITTLE_ENDIAN));
329
+ }
330
+ if (offset.label !== void 0) {
331
+ label.push(dataview.getInt32(row + offset.label, LITTLE_ENDIAN));
332
+ }
333
+ }
334
+ return { position, normal, color, intensity, label };
335
+ }
336
+ function parsePCDBinaryCompressed(pcdHeader, data) {
337
+ const position = [];
338
+ const normal = [];
339
+ const color = [];
340
+ const intensity = [];
341
+ const label = [];
342
+ const sizes = new Uint32Array(data.slice(pcdHeader.headerLen, pcdHeader.headerLen + 8));
343
+ const compressedSize = sizes[0];
344
+ const decompressedSize = sizes[1];
345
+ const decompressed = decompressLZF(
346
+ new Uint8Array(data, pcdHeader.headerLen + 8, compressedSize),
347
+ decompressedSize
348
+ );
349
+ const dataview = new DataView(decompressed.buffer);
350
+ const offset = pcdHeader.offset;
351
+ for (let i = 0; i < pcdHeader.points; i++) {
352
+ if (offset.x !== void 0) {
353
+ position.push(
354
+ dataview.getFloat32(pcdHeader.points * offset.x + pcdHeader.size[0] * i, LITTLE_ENDIAN)
355
+ );
356
+ position.push(
357
+ dataview.getFloat32(pcdHeader.points * offset.y + pcdHeader.size[1] * i, LITTLE_ENDIAN)
358
+ );
359
+ position.push(
360
+ dataview.getFloat32(pcdHeader.points * offset.z + pcdHeader.size[2] * i, LITTLE_ENDIAN)
361
+ );
362
+ }
363
+ if (offset.rgb !== void 0) {
364
+ color.push(
365
+ dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 0) / 255
366
+ );
367
+ color.push(
368
+ dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 1) / 255
369
+ );
370
+ color.push(
371
+ dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 2) / 255
372
+ );
373
+ }
374
+ if (offset.normal_x !== void 0) {
375
+ normal.push(
376
+ dataview.getFloat32(
377
+ pcdHeader.points * offset.normal_x + pcdHeader.size[4] * i,
378
+ LITTLE_ENDIAN
379
+ )
380
+ );
381
+ normal.push(
382
+ dataview.getFloat32(
383
+ pcdHeader.points * offset.normal_y + pcdHeader.size[5] * i,
384
+ LITTLE_ENDIAN
385
+ )
386
+ );
387
+ normal.push(
388
+ dataview.getFloat32(
389
+ pcdHeader.points * offset.normal_z + pcdHeader.size[6] * i,
390
+ LITTLE_ENDIAN
391
+ )
392
+ );
393
+ }
394
+ if (offset.intensity !== void 0) {
395
+ const intensityIndex = pcdHeader.fields.indexOf("intensity");
396
+ intensity.push(
397
+ dataview.getFloat32(
398
+ pcdHeader.points * offset.intensity + pcdHeader.size[intensityIndex] * i,
399
+ LITTLE_ENDIAN
400
+ )
401
+ );
402
+ }
403
+ if (offset.label !== void 0) {
404
+ const labelIndex = pcdHeader.fields.indexOf("label");
405
+ label.push(
406
+ dataview.getInt32(
407
+ pcdHeader.points * offset.label + pcdHeader.size[labelIndex] * i,
408
+ LITTLE_ENDIAN
409
+ )
410
+ );
411
+ }
412
+ }
413
+ return {
414
+ position,
415
+ normal,
416
+ color,
417
+ intensity,
418
+ label
419
+ };
420
+ }
421
+
422
+ // src/pcd-loader.ts
423
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
424
+ var PCDLoader = {
425
+ name: "PCD (Point Cloud Data)",
426
+ id: "pcd",
427
+ module: "pcd",
428
+ version: VERSION,
429
+ worker: true,
430
+ extensions: ["pcd"],
431
+ mimeTypes: ["text/plain"],
432
+ options: {
433
+ pcd: {}
434
+ }
435
+ };
436
+
437
+ // src/index.ts
438
+ var PCDLoader2 = {
439
+ ...PCDLoader,
440
+ parse: async (arrayBuffer) => parsePCD(arrayBuffer),
441
+ parseSync: parsePCD
442
+ };
443
+ /** Parse compressed PCD data in in binary_compressed form ( https://pointclouds.org/documentation/tutorials/pcd_file_format.html)
444
+ * from https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/PCDLoader.js
445
+ * @license MIT (http://opensource.org/licenses/MIT)
446
+ * @param pcdHeader
447
+ * @param data
448
+ * @returns [attributes]
449
+ */