@loaders.gl/pcd 4.2.0-alpha.4 → 4.2.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.
@@ -1,239 +1,280 @@
1
+ // PCD Loader, adapted from THREE.js (MIT license)
2
+ // Description: A loader for PCD ascii and binary files.
3
+ // Limitations: Compressed binary files are not supported.
4
+ //
5
+ // Attributions per original THREE.js source file:
6
+ // @author Filipe Caixeta / http://filipecaixeta.com.br
7
+ // @author Mugen87 / https://github.com/Mugen87
1
8
  import { getMeshBoundingBox } from '@loaders.gl/schema';
2
9
  import { decompressLZF } from "./decompress-lzf.js";
3
10
  import { getPCDSchema } from "./get-pcd-schema.js";
4
11
  const LITTLE_ENDIAN = true;
12
+ /**
13
+ *
14
+ * @param data
15
+ * @returns
16
+ */
5
17
  export default function parsePCD(data) {
6
- const textData = new TextDecoder().decode(data);
7
- const pcdHeader = parsePCDHeader(textData);
8
- let attributes = {};
9
- switch (pcdHeader.data) {
10
- case 'ascii':
11
- attributes = parsePCDASCII(pcdHeader, textData);
12
- break;
13
- case 'binary':
14
- attributes = parsePCDBinary(pcdHeader, data);
15
- break;
16
- case 'binary_compressed':
17
- attributes = parsePCDBinaryCompressed(pcdHeader, data);
18
- break;
19
- default:
20
- throw new Error(`PCD: ${pcdHeader.data} files are not supported`);
21
- }
22
- attributes = getMeshAttributes(attributes);
23
- const header = getMeshHeader(pcdHeader, attributes);
24
- const metadata = Object.fromEntries([['mode', '0'], ['boundingBox', JSON.stringify(header.boundingBox)]]);
25
- const schema = getPCDSchema(pcdHeader, metadata);
26
- return {
27
- loader: 'pcd',
28
- loaderData: pcdHeader,
29
- header,
30
- schema,
31
- mode: 0,
32
- topology: 'point-list',
33
- attributes
34
- };
18
+ // parse header (always ascii format)
19
+ const textData = new TextDecoder().decode(data);
20
+ const pcdHeader = parsePCDHeader(textData);
21
+ let attributes = {};
22
+ // parse data
23
+ switch (pcdHeader.data) {
24
+ case 'ascii':
25
+ attributes = parsePCDASCII(pcdHeader, textData);
26
+ break;
27
+ case 'binary':
28
+ attributes = parsePCDBinary(pcdHeader, data);
29
+ break;
30
+ case 'binary_compressed':
31
+ attributes = parsePCDBinaryCompressed(pcdHeader, data);
32
+ break;
33
+ default:
34
+ throw new Error(`PCD: ${pcdHeader.data} files are not supported`);
35
+ }
36
+ attributes = getMeshAttributes(attributes);
37
+ const header = getMeshHeader(pcdHeader, attributes);
38
+ const metadata = Object.fromEntries([
39
+ ['mode', '0'],
40
+ ['boundingBox', JSON.stringify(header.boundingBox)]
41
+ ]);
42
+ const schema = getPCDSchema(pcdHeader, metadata);
43
+ return {
44
+ loader: 'pcd',
45
+ loaderData: pcdHeader,
46
+ header,
47
+ schema,
48
+ mode: 0, // POINTS
49
+ topology: 'point-list',
50
+ attributes
51
+ };
35
52
  }
53
+ // Create a header that contains common data for PointCloud category loaders
36
54
  function getMeshHeader(pcdHeader, attributes) {
37
- if (typeof pcdHeader.width === 'number' && typeof pcdHeader.height === 'number') {
38
- const pointCount = pcdHeader.width * pcdHeader.height;
55
+ if (typeof pcdHeader.width === 'number' && typeof pcdHeader.height === 'number') {
56
+ const pointCount = pcdHeader.width * pcdHeader.height; // Supports "organized" point sets
57
+ return {
58
+ vertexCount: pointCount,
59
+ boundingBox: getMeshBoundingBox(attributes)
60
+ };
61
+ }
39
62
  return {
40
- vertexCount: pointCount,
41
- boundingBox: getMeshBoundingBox(attributes)
63
+ vertexCount: pcdHeader.vertexCount,
64
+ boundingBox: pcdHeader.boundingBox
42
65
  };
43
- }
44
- return {
45
- vertexCount: pcdHeader.vertexCount,
46
- boundingBox: pcdHeader.boundingBox
47
- };
48
66
  }
67
+ /**
68
+ * @param attributes
69
+ * @returns Normalized attributes
70
+ */
49
71
  function getMeshAttributes(attributes) {
50
- const normalizedAttributes = {
51
- POSITION: {
52
- value: new Float32Array(attributes.position),
53
- size: 3
54
- }
55
- };
56
- if (attributes.normal && attributes.normal.length > 0) {
57
- normalizedAttributes.NORMAL = {
58
- value: new Float32Array(attributes.normal),
59
- size: 3
60
- };
61
- }
62
- if (attributes.color && attributes.color.length > 0) {
63
- normalizedAttributes.COLOR_0 = {
64
- value: new Uint8Array(attributes.color),
65
- size: 3
72
+ const normalizedAttributes = {
73
+ POSITION: {
74
+ // Binary PCD is only 32 bit
75
+ value: new Float32Array(attributes.position),
76
+ size: 3
77
+ }
66
78
  };
67
- }
68
- if (attributes.intensity && attributes.intensity.length > 0) {
69
- normalizedAttributes.COLOR_0 = {
70
- value: new Uint8Array(attributes.color),
71
- size: 3
72
- };
73
- }
74
- if (attributes.label && attributes.label.length > 0) {
75
- normalizedAttributes.COLOR_0 = {
76
- value: new Uint8Array(attributes.label),
77
- size: 3
78
- };
79
- }
80
- return normalizedAttributes;
79
+ if (attributes.normal && attributes.normal.length > 0) {
80
+ normalizedAttributes.NORMAL = {
81
+ value: new Float32Array(attributes.normal),
82
+ size: 3
83
+ };
84
+ }
85
+ if (attributes.color && attributes.color.length > 0) {
86
+ // TODO - RGBA
87
+ normalizedAttributes.COLOR_0 = {
88
+ value: new Uint8Array(attributes.color),
89
+ size: 3
90
+ };
91
+ }
92
+ if (attributes.intensity && attributes.intensity.length > 0) {
93
+ // TODO - RGBA
94
+ normalizedAttributes.COLOR_0 = {
95
+ value: new Uint8Array(attributes.color),
96
+ size: 3
97
+ };
98
+ }
99
+ if (attributes.label && attributes.label.length > 0) {
100
+ // TODO - RGBA
101
+ normalizedAttributes.COLOR_0 = {
102
+ value: new Uint8Array(attributes.label),
103
+ size: 3
104
+ };
105
+ }
106
+ return normalizedAttributes;
81
107
  }
108
+ /**
109
+ * Incoming data parsing
110
+ * @param data
111
+ * @returns Header
112
+ */
113
+ /* eslint-disable complexity, max-statements */
82
114
  function parsePCDHeader(data) {
83
- const result1 = data.search(/[\r\n]DATA\s(\S*)\s/i);
84
- const result2 = /[\r\n]DATA\s(\S*)\s/i.exec(data.substr(result1 - 1));
85
- const pcdHeader = {};
86
- pcdHeader.data = result2 && result2[1];
87
- if (result2 !== null) {
88
- pcdHeader.headerLen = (result2 && result2[0].length) + result1;
89
- }
90
- pcdHeader.str = data.substr(0, pcdHeader.headerLen);
91
- pcdHeader.str = pcdHeader.str.replace(/\#.*/gi, '');
92
- pcdHeader.version = /VERSION (.*)/i.exec(pcdHeader.str);
93
- pcdHeader.fields = /FIELDS (.*)/i.exec(pcdHeader.str);
94
- pcdHeader.size = /SIZE (.*)/i.exec(pcdHeader.str);
95
- pcdHeader.type = /TYPE (.*)/i.exec(pcdHeader.str);
96
- pcdHeader.count = /COUNT (.*)/i.exec(pcdHeader.str);
97
- pcdHeader.width = /WIDTH (.*)/i.exec(pcdHeader.str);
98
- pcdHeader.height = /HEIGHT (.*)/i.exec(pcdHeader.str);
99
- pcdHeader.viewpoint = /VIEWPOINT (.*)/i.exec(pcdHeader.str);
100
- pcdHeader.points = /POINTS (.*)/i.exec(pcdHeader.str);
101
- if (pcdHeader.version !== null) {
102
- pcdHeader.version = parseFloat(pcdHeader.version[1]);
103
- }
104
- if (pcdHeader.fields !== null) {
105
- pcdHeader.fields = pcdHeader.fields[1].split(' ');
106
- }
107
- if (pcdHeader.type !== null) {
108
- pcdHeader.type = pcdHeader.type[1].split(' ');
109
- }
110
- if (pcdHeader.width !== null) {
111
- pcdHeader.width = parseInt(pcdHeader.width[1], 10);
112
- }
113
- if (pcdHeader.height !== null) {
114
- pcdHeader.height = parseInt(pcdHeader.height[1], 10);
115
- }
116
- if (pcdHeader.viewpoint !== null) {
117
- pcdHeader.viewpoint = pcdHeader.viewpoint[1];
118
- }
119
- if (pcdHeader.points !== null) {
120
- pcdHeader.points = parseInt(pcdHeader.points[1], 10);
121
- }
122
- if (pcdHeader.points === null && typeof pcdHeader.width === 'number' && typeof pcdHeader.height === 'number') {
123
- pcdHeader.points = pcdHeader.width * pcdHeader.height;
124
- }
125
- if (pcdHeader.size !== null) {
126
- pcdHeader.size = pcdHeader.size[1].split(' ').map(x => parseInt(x, 10));
127
- }
128
- if (pcdHeader.count !== null) {
129
- pcdHeader.count = pcdHeader.count[1].split(' ').map(x => parseInt(x, 10));
130
- } else {
131
- pcdHeader.count = [];
115
+ const result1 = data.search(/[\r\n]DATA\s(\S*)\s/i);
116
+ const result2 = /[\r\n]DATA\s(\S*)\s/i.exec(data.substr(result1 - 1));
117
+ const pcdHeader = {};
118
+ pcdHeader.data = result2 && result2[1];
119
+ if (result2 !== null) {
120
+ pcdHeader.headerLen = (result2 && result2[0].length) + result1;
121
+ }
122
+ pcdHeader.str = data.substr(0, pcdHeader.headerLen);
123
+ // remove comments
124
+ pcdHeader.str = pcdHeader.str.replace(/\#.*/gi, '');
125
+ // parse
126
+ pcdHeader.version = /VERSION (.*)/i.exec(pcdHeader.str);
127
+ pcdHeader.fields = /FIELDS (.*)/i.exec(pcdHeader.str);
128
+ pcdHeader.size = /SIZE (.*)/i.exec(pcdHeader.str);
129
+ pcdHeader.type = /TYPE (.*)/i.exec(pcdHeader.str);
130
+ pcdHeader.count = /COUNT (.*)/i.exec(pcdHeader.str);
131
+ pcdHeader.width = /WIDTH (.*)/i.exec(pcdHeader.str);
132
+ pcdHeader.height = /HEIGHT (.*)/i.exec(pcdHeader.str);
133
+ pcdHeader.viewpoint = /VIEWPOINT (.*)/i.exec(pcdHeader.str);
134
+ pcdHeader.points = /POINTS (.*)/i.exec(pcdHeader.str);
135
+ // evaluate
136
+ if (pcdHeader.version !== null) {
137
+ pcdHeader.version = parseFloat(pcdHeader.version[1]);
138
+ }
132
139
  if (pcdHeader.fields !== null) {
133
- for (let i = 0; i < pcdHeader.fields.length; i++) {
134
- pcdHeader.count.push(1);
135
- }
140
+ pcdHeader.fields = pcdHeader.fields[1].split(' ');
136
141
  }
137
- }
138
- pcdHeader.offset = {};
139
- let sizeSum = 0;
140
- if (pcdHeader.fields !== null && pcdHeader.size !== null) {
141
- for (let i = 0; i < pcdHeader.fields.length; i++) {
142
- if (pcdHeader.data === 'ascii') {
143
- pcdHeader.offset[pcdHeader.fields[i]] = i;
144
- } else {
145
- pcdHeader.offset[pcdHeader.fields[i]] = sizeSum;
146
- sizeSum += pcdHeader.size[i];
147
- }
142
+ if (pcdHeader.type !== null) {
143
+ pcdHeader.type = pcdHeader.type[1].split(' ');
148
144
  }
149
- }
150
- pcdHeader.rowSize = sizeSum;
151
- return pcdHeader;
152
- }
153
- function parsePCDASCII(pcdHeader, textData) {
154
- const position = [];
155
- const normal = [];
156
- const color = [];
157
- const intensity = [];
158
- const label = [];
159
- const offset = pcdHeader.offset;
160
- const pcdData = textData.substr(pcdHeader.headerLen);
161
- const lines = pcdData.split('\n');
162
- for (let i = 0; i < lines.length; i++) {
163
- if (lines[i] !== '') {
164
- const line = lines[i].split(' ');
165
- if (offset.x !== undefined) {
166
- position.push(parseFloat(line[offset.x]));
167
- position.push(parseFloat(line[offset.y]));
168
- position.push(parseFloat(line[offset.z]));
169
- }
170
- if (offset.rgb !== undefined) {
171
- const floatValue = parseFloat(line[offset.rgb]);
172
- const binaryColor = new Float32Array([floatValue]);
173
- const dataview = new DataView(binaryColor.buffer, 0);
174
- color.push(dataview.getUint8(0));
175
- color.push(dataview.getUint8(1));
176
- color.push(dataview.getUint8(2));
177
- }
178
- if (offset.normal_x !== undefined) {
179
- normal.push(parseFloat(line[offset.normal_x]));
180
- normal.push(parseFloat(line[offset.normal_y]));
181
- normal.push(parseFloat(line[offset.normal_z]));
182
- }
183
- if (offset.intensity !== undefined) {
184
- intensity.push(parseFloat(line[offset.intensity]));
185
- }
186
- if (offset.label !== undefined) {
187
- label.push(parseInt(line[offset.label]));
188
- }
145
+ if (pcdHeader.width !== null) {
146
+ pcdHeader.width = parseInt(pcdHeader.width[1], 10);
189
147
  }
190
- }
191
- return {
192
- position,
193
- normal,
194
- color
195
- };
196
- }
197
- function parsePCDBinary(pcdHeader, data) {
198
- const position = [];
199
- const normal = [];
200
- const color = [];
201
- const intensity = [];
202
- const label = [];
203
- const dataview = new DataView(data, pcdHeader.headerLen);
204
- const offset = pcdHeader.offset;
205
- for (let i = 0, row = 0; i < pcdHeader.points; i++, row += pcdHeader.rowSize) {
206
- if (offset.x !== undefined) {
207
- position.push(dataview.getFloat32(row + offset.x, LITTLE_ENDIAN));
208
- position.push(dataview.getFloat32(row + offset.y, LITTLE_ENDIAN));
209
- position.push(dataview.getFloat32(row + offset.z, LITTLE_ENDIAN));
148
+ if (pcdHeader.height !== null) {
149
+ pcdHeader.height = parseInt(pcdHeader.height[1], 10);
210
150
  }
211
- if (offset.rgb !== undefined) {
212
- color.push(dataview.getUint8(row + offset.rgb + 0));
213
- color.push(dataview.getUint8(row + offset.rgb + 1));
214
- color.push(dataview.getUint8(row + offset.rgb + 2));
151
+ if (pcdHeader.viewpoint !== null) {
152
+ pcdHeader.viewpoint = pcdHeader.viewpoint[1];
215
153
  }
216
- if (offset.normal_x !== undefined) {
217
- normal.push(dataview.getFloat32(row + offset.normal_x, LITTLE_ENDIAN));
218
- normal.push(dataview.getFloat32(row + offset.normal_y, LITTLE_ENDIAN));
219
- normal.push(dataview.getFloat32(row + offset.normal_z, LITTLE_ENDIAN));
154
+ if (pcdHeader.points !== null) {
155
+ pcdHeader.points = parseInt(pcdHeader.points[1], 10);
220
156
  }
221
- if (offset.intensity !== undefined) {
222
- intensity.push(dataview.getFloat32(row + offset.intensity, LITTLE_ENDIAN));
157
+ if (pcdHeader.points === null &&
158
+ typeof pcdHeader.width === 'number' &&
159
+ typeof pcdHeader.height === 'number') {
160
+ pcdHeader.points = pcdHeader.width * pcdHeader.height;
223
161
  }
224
- if (offset.label !== undefined) {
225
- label.push(dataview.getInt32(row + offset.label, LITTLE_ENDIAN));
162
+ if (pcdHeader.size !== null) {
163
+ pcdHeader.size = pcdHeader.size[1].split(' ').map((x) => parseInt(x, 10));
226
164
  }
227
- }
228
- return {
229
- position,
230
- normal,
231
- color,
232
- intensity,
233
- label
234
- };
165
+ if (pcdHeader.count !== null) {
166
+ pcdHeader.count = pcdHeader.count[1].split(' ').map((x) => parseInt(x, 10));
167
+ }
168
+ else {
169
+ pcdHeader.count = [];
170
+ if (pcdHeader.fields !== null) {
171
+ for (let i = 0; i < pcdHeader.fields.length; i++) {
172
+ pcdHeader.count.push(1);
173
+ }
174
+ }
175
+ }
176
+ pcdHeader.offset = {};
177
+ let sizeSum = 0;
178
+ if (pcdHeader.fields !== null && pcdHeader.size !== null) {
179
+ for (let i = 0; i < pcdHeader.fields.length; i++) {
180
+ if (pcdHeader.data === 'ascii') {
181
+ pcdHeader.offset[pcdHeader.fields[i]] = i;
182
+ }
183
+ else {
184
+ pcdHeader.offset[pcdHeader.fields[i]] = sizeSum;
185
+ sizeSum += pcdHeader.size[i];
186
+ }
187
+ }
188
+ }
189
+ // for binary only
190
+ pcdHeader.rowSize = sizeSum;
191
+ return pcdHeader;
192
+ }
193
+ /**
194
+ * @param pcdHeader
195
+ * @param textData
196
+ * @returns [attributes]
197
+ */
198
+ // eslint-enable-next-line complexity, max-statements
199
+ function parsePCDASCII(pcdHeader, textData) {
200
+ const position = [];
201
+ const normal = [];
202
+ const color = [];
203
+ const intensity = [];
204
+ const label = [];
205
+ const offset = pcdHeader.offset;
206
+ const pcdData = textData.substr(pcdHeader.headerLen);
207
+ const lines = pcdData.split('\n');
208
+ for (let i = 0; i < lines.length; i++) {
209
+ if (lines[i] !== '') {
210
+ const line = lines[i].split(' ');
211
+ if (offset.x !== undefined) {
212
+ position.push(parseFloat(line[offset.x]));
213
+ position.push(parseFloat(line[offset.y]));
214
+ position.push(parseFloat(line[offset.z]));
215
+ }
216
+ if (offset.rgb !== undefined) {
217
+ const floatValue = parseFloat(line[offset.rgb]);
218
+ const binaryColor = new Float32Array([floatValue]);
219
+ const dataview = new DataView(binaryColor.buffer, 0);
220
+ color.push(dataview.getUint8(0));
221
+ color.push(dataview.getUint8(1));
222
+ color.push(dataview.getUint8(2));
223
+ // TODO - handle alpha channel / RGBA?
224
+ }
225
+ if (offset.normal_x !== undefined) {
226
+ normal.push(parseFloat(line[offset.normal_x]));
227
+ normal.push(parseFloat(line[offset.normal_y]));
228
+ normal.push(parseFloat(line[offset.normal_z]));
229
+ }
230
+ if (offset.intensity !== undefined) {
231
+ intensity.push(parseFloat(line[offset.intensity]));
232
+ }
233
+ if (offset.label !== undefined) {
234
+ label.push(parseInt(line[offset.label]));
235
+ }
236
+ }
237
+ }
238
+ return { position, normal, color };
239
+ }
240
+ /**
241
+ * @param pcdHeader
242
+ * @param data
243
+ * @returns [attributes]
244
+ */
245
+ function parsePCDBinary(pcdHeader, data) {
246
+ const position = [];
247
+ const normal = [];
248
+ const color = [];
249
+ const intensity = [];
250
+ const label = [];
251
+ const dataview = new DataView(data, pcdHeader.headerLen);
252
+ const offset = pcdHeader.offset;
253
+ for (let i = 0, row = 0; i < pcdHeader.points; i++, row += pcdHeader.rowSize) {
254
+ if (offset.x !== undefined) {
255
+ position.push(dataview.getFloat32(row + offset.x, LITTLE_ENDIAN));
256
+ position.push(dataview.getFloat32(row + offset.y, LITTLE_ENDIAN));
257
+ position.push(dataview.getFloat32(row + offset.z, LITTLE_ENDIAN));
258
+ }
259
+ if (offset.rgb !== undefined) {
260
+ color.push(dataview.getUint8(row + offset.rgb + 0));
261
+ color.push(dataview.getUint8(row + offset.rgb + 1));
262
+ color.push(dataview.getUint8(row + offset.rgb + 2));
263
+ }
264
+ if (offset.normal_x !== undefined) {
265
+ normal.push(dataview.getFloat32(row + offset.normal_x, LITTLE_ENDIAN));
266
+ normal.push(dataview.getFloat32(row + offset.normal_y, LITTLE_ENDIAN));
267
+ normal.push(dataview.getFloat32(row + offset.normal_z, LITTLE_ENDIAN));
268
+ }
269
+ if (offset.intensity !== undefined) {
270
+ intensity.push(dataview.getFloat32(row + offset.intensity, LITTLE_ENDIAN));
271
+ }
272
+ if (offset.label !== undefined) {
273
+ label.push(dataview.getInt32(row + offset.label, LITTLE_ENDIAN));
274
+ }
275
+ }
276
+ return { position, normal, color, intensity, label };
235
277
  }
236
-
237
278
  /** Parse compressed PCD data in in binary_compressed form ( https://pointclouds.org/documentation/tutorials/pcd_file_format.html)
238
279
  * from https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/PCDLoader.js
239
280
  * @license MIT (http://opensource.org/licenses/MIT)
@@ -241,49 +282,49 @@ function parsePCDBinary(pcdHeader, data) {
241
282
  * @param data
242
283
  * @returns [attributes]
243
284
  */
285
+ // eslint-enable-next-line complexity, max-statements
244
286
  function parsePCDBinaryCompressed(pcdHeader, data) {
245
- const position = [];
246
- const normal = [];
247
- const color = [];
248
- const intensity = [];
249
- const label = [];
250
- const sizes = new Uint32Array(data.slice(pcdHeader.headerLen, pcdHeader.headerLen + 8));
251
- const compressedSize = sizes[0];
252
- const decompressedSize = sizes[1];
253
- const decompressed = decompressLZF(new Uint8Array(data, pcdHeader.headerLen + 8, compressedSize), decompressedSize);
254
- const dataview = new DataView(decompressed.buffer);
255
- const offset = pcdHeader.offset;
256
- for (let i = 0; i < pcdHeader.points; i++) {
257
- if (offset.x !== undefined) {
258
- position.push(dataview.getFloat32(pcdHeader.points * offset.x + pcdHeader.size[0] * i, LITTLE_ENDIAN));
259
- position.push(dataview.getFloat32(pcdHeader.points * offset.y + pcdHeader.size[1] * i, LITTLE_ENDIAN));
260
- position.push(dataview.getFloat32(pcdHeader.points * offset.z + pcdHeader.size[2] * i, LITTLE_ENDIAN));
261
- }
262
- if (offset.rgb !== undefined) {
263
- color.push(dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 0) / 255.0);
264
- color.push(dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 1) / 255.0);
265
- color.push(dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 2) / 255.0);
287
+ const position = [];
288
+ const normal = [];
289
+ const color = [];
290
+ const intensity = [];
291
+ const label = [];
292
+ const sizes = new Uint32Array(data.slice(pcdHeader.headerLen, pcdHeader.headerLen + 8));
293
+ const compressedSize = sizes[0];
294
+ const decompressedSize = sizes[1];
295
+ const decompressed = decompressLZF(new Uint8Array(data, pcdHeader.headerLen + 8, compressedSize), decompressedSize);
296
+ const dataview = new DataView(decompressed.buffer);
297
+ const offset = pcdHeader.offset;
298
+ for (let i = 0; i < pcdHeader.points; i++) {
299
+ if (offset.x !== undefined) {
300
+ position.push(dataview.getFloat32(pcdHeader.points * offset.x + pcdHeader.size[0] * i, LITTLE_ENDIAN));
301
+ position.push(dataview.getFloat32(pcdHeader.points * offset.y + pcdHeader.size[1] * i, LITTLE_ENDIAN));
302
+ position.push(dataview.getFloat32(pcdHeader.points * offset.z + pcdHeader.size[2] * i, LITTLE_ENDIAN));
303
+ }
304
+ if (offset.rgb !== undefined) {
305
+ color.push(dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 0) / 255.0);
306
+ color.push(dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 1) / 255.0);
307
+ color.push(dataview.getUint8(pcdHeader.points * offset.rgb + pcdHeader.size[3] * i + 2) / 255.0);
308
+ }
309
+ if (offset.normal_x !== undefined) {
310
+ normal.push(dataview.getFloat32(pcdHeader.points * offset.normal_x + pcdHeader.size[4] * i, LITTLE_ENDIAN));
311
+ normal.push(dataview.getFloat32(pcdHeader.points * offset.normal_y + pcdHeader.size[5] * i, LITTLE_ENDIAN));
312
+ normal.push(dataview.getFloat32(pcdHeader.points * offset.normal_z + pcdHeader.size[6] * i, LITTLE_ENDIAN));
313
+ }
314
+ if (offset.intensity !== undefined) {
315
+ const intensityIndex = pcdHeader.fields.indexOf('intensity');
316
+ intensity.push(dataview.getFloat32(pcdHeader.points * offset.intensity + pcdHeader.size[intensityIndex] * i, LITTLE_ENDIAN));
317
+ }
318
+ if (offset.label !== undefined) {
319
+ const labelIndex = pcdHeader.fields.indexOf('label');
320
+ label.push(dataview.getInt32(pcdHeader.points * offset.label + pcdHeader.size[labelIndex] * i, LITTLE_ENDIAN));
321
+ }
266
322
  }
267
- if (offset.normal_x !== undefined) {
268
- normal.push(dataview.getFloat32(pcdHeader.points * offset.normal_x + pcdHeader.size[4] * i, LITTLE_ENDIAN));
269
- normal.push(dataview.getFloat32(pcdHeader.points * offset.normal_y + pcdHeader.size[5] * i, LITTLE_ENDIAN));
270
- normal.push(dataview.getFloat32(pcdHeader.points * offset.normal_z + pcdHeader.size[6] * i, LITTLE_ENDIAN));
271
- }
272
- if (offset.intensity !== undefined) {
273
- const intensityIndex = pcdHeader.fields.indexOf('intensity');
274
- intensity.push(dataview.getFloat32(pcdHeader.points * offset.intensity + pcdHeader.size[intensityIndex] * i, LITTLE_ENDIAN));
275
- }
276
- if (offset.label !== undefined) {
277
- const labelIndex = pcdHeader.fields.indexOf('label');
278
- label.push(dataview.getInt32(pcdHeader.points * offset.label + pcdHeader.size[labelIndex] * i, LITTLE_ENDIAN));
279
- }
280
- }
281
- return {
282
- position,
283
- normal,
284
- color,
285
- intensity,
286
- label
287
- };
323
+ return {
324
+ position,
325
+ normal,
326
+ color,
327
+ intensity,
328
+ label
329
+ };
288
330
  }
289
- //# sourceMappingURL=parse-pcd.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=pcd-types.js.map
@@ -1,5 +1,5 @@
1
1
  import type { Loader, LoaderOptions } from '@loaders.gl/loader-utils';
2
- import { PCDMesh } from './lib/pcd-types';
2
+ import { PCDMesh } from "./lib/pcd-types.js";
3
3
  /**
4
4
  * Worker loader for PCD - Point Cloud Data
5
5
  */
@@ -1 +1 @@
1
- {"version":3,"file":"pcd-loader.d.ts","sourceRoot":"","sources":["../src/pcd-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAC,OAAO,EAAC,MAAM,iBAAiB,CAAC;AAMxC;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,aAAa,CAW3D,CAAC"}
1
+ {"version":3,"file":"pcd-loader.d.ts","sourceRoot":"","sources":["../src/pcd-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAC,OAAO,EAAC,2BAAwB;AAMxC;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,aAAa,CAW3D,CAAC"}
@@ -1,14 +1,21 @@
1
- const VERSION = typeof "4.2.0-alpha.4" !== 'undefined' ? "4.2.0-alpha.4" : 'latest';
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ // __VERSION__ is injected by babel-plugin-version-inline
5
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
6
+ const VERSION = typeof "4.2.0-alpha.5" !== 'undefined' ? "4.2.0-alpha.5" : 'latest';
7
+ /**
8
+ * Worker loader for PCD - Point Cloud Data
9
+ */
2
10
  export const PCDLoader = {
3
- name: 'PCD (Point Cloud Data)',
4
- id: 'pcd',
5
- module: 'pcd',
6
- version: VERSION,
7
- worker: true,
8
- extensions: ['pcd'],
9
- mimeTypes: ['text/plain'],
10
- options: {
11
- pcd: {}
12
- }
11
+ name: 'PCD (Point Cloud Data)',
12
+ id: 'pcd',
13
+ module: 'pcd',
14
+ version: VERSION,
15
+ worker: true,
16
+ extensions: ['pcd'],
17
+ mimeTypes: ['text/plain'],
18
+ options: {
19
+ pcd: {}
20
+ }
13
21
  };
14
- //# sourceMappingURL=pcd-loader.js.map
@@ -59,7 +59,9 @@
59
59
  }
60
60
  getParentPort().then((parentPort2) => {
61
61
  if (parentPort2) {
62
- parentPort2.on("message", handleMessage);
62
+ parentPort2.on("message", (message) => {
63
+ handleMessage(message);
64
+ });
63
65
  parentPort2.on("exit", () => console.debug("Node worker closing"));
64
66
  } else {
65
67
  globalThis.onmessage = handleMessage;
@@ -616,7 +618,7 @@
616
618
  }
617
619
 
618
620
  // src/pcd-loader.ts
619
- var VERSION = true ? "4.2.0-alpha.4" : "latest";
621
+ var VERSION = true ? "4.2.0-alpha.5" : "latest";
620
622
  var PCDLoader = {
621
623
  name: "PCD (Point Cloud Data)",
622
624
  id: "pcd",
@@ -1,4 +1,3 @@
1
1
  import { createLoaderWorker } from '@loaders.gl/loader-utils';
2
2
  import { PCDLoader } from "../index.js";
3
3
  createLoaderWorker(PCDLoader);
4
- //# sourceMappingURL=pcd-worker.js.map