@loaders.gl/ply 4.0.0-beta.2 → 4.0.0-beta.3

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 (51) hide show
  1. package/dist/{dist.min.js → dist.dev.js} +106 -134
  2. package/dist/index.cjs +644 -0
  3. package/dist/{esm/index.js → index.js} +3 -3
  4. package/dist/index.js.map +1 -0
  5. package/dist/lib/get-ply-schema.js.map +1 -0
  6. package/dist/{esm/lib → lib}/normalize-ply.js +1 -1
  7. package/dist/lib/normalize-ply.js.map +1 -0
  8. package/dist/{esm/lib → lib}/parse-ply-in-batches.js +1 -1
  9. package/dist/lib/parse-ply-in-batches.js.map +1 -0
  10. package/dist/{esm/lib → lib}/parse-ply.js +1 -1
  11. package/dist/lib/parse-ply.js.map +1 -0
  12. package/dist/lib/ply-types.js.map +1 -0
  13. package/dist/{esm/ply-loader.js → ply-loader.js} +1 -1
  14. package/dist/ply-loader.js.map +1 -0
  15. package/dist/ply-worker.js +24 -4
  16. package/dist/{esm/workers → workers}/ply-worker.js +1 -1
  17. package/dist/workers/ply-worker.js.map +1 -0
  18. package/package.json +16 -8
  19. package/dist/bundle.d.ts +0 -2
  20. package/dist/bundle.d.ts.map +0 -1
  21. package/dist/es5/bundle.js +0 -6
  22. package/dist/es5/bundle.js.map +0 -1
  23. package/dist/es5/index.js +0 -51
  24. package/dist/es5/index.js.map +0 -1
  25. package/dist/es5/lib/get-ply-schema.js +0 -28
  26. package/dist/es5/lib/get-ply-schema.js.map +0 -1
  27. package/dist/es5/lib/normalize-ply.js +0 -93
  28. package/dist/es5/lib/normalize-ply.js.map +0 -1
  29. package/dist/es5/lib/parse-ply-in-batches.js +0 -289
  30. package/dist/es5/lib/parse-ply-in-batches.js.map +0 -1
  31. package/dist/es5/lib/parse-ply.js +0 -348
  32. package/dist/es5/lib/parse-ply.js.map +0 -1
  33. package/dist/es5/lib/ply-types.js +0 -2
  34. package/dist/es5/lib/ply-types.js.map +0 -1
  35. package/dist/es5/ply-loader.js +0 -24
  36. package/dist/es5/ply-loader.js.map +0 -1
  37. package/dist/es5/workers/ply-worker.js +0 -6
  38. package/dist/es5/workers/ply-worker.js.map +0 -1
  39. package/dist/esm/bundle.js +0 -4
  40. package/dist/esm/bundle.js.map +0 -1
  41. package/dist/esm/index.js.map +0 -1
  42. package/dist/esm/lib/get-ply-schema.js.map +0 -1
  43. package/dist/esm/lib/normalize-ply.js.map +0 -1
  44. package/dist/esm/lib/parse-ply-in-batches.js.map +0 -1
  45. package/dist/esm/lib/parse-ply.js.map +0 -1
  46. package/dist/esm/lib/ply-types.js.map +0 -1
  47. package/dist/esm/ply-loader.js.map +0 -1
  48. package/dist/esm/workers/ply-worker.js.map +0 -1
  49. package/src/bundle.ts +0 -4
  50. /package/dist/{esm/lib → lib}/get-ply-schema.js +0 -0
  51. /package/dist/{esm/lib → lib}/ply-types.js +0 -0
package/dist/index.cjs ADDED
@@ -0,0 +1,644 @@
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
+ PLYLoader: () => PLYLoader2,
24
+ PLYWorkerLoader: () => PLYLoader
25
+ });
26
+ module.exports = __toCommonJS(src_exports);
27
+
28
+ // src/ply-loader.ts
29
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
30
+ var PLYLoader = {
31
+ name: "PLY",
32
+ id: "ply",
33
+ module: "ply",
34
+ // shapes: ['mesh', 'gltf', 'columnar-table'],
35
+ version: VERSION,
36
+ worker: true,
37
+ extensions: ["ply"],
38
+ mimeTypes: ["text/plain", "application/octet-stream"],
39
+ text: true,
40
+ binary: true,
41
+ tests: ["ply"],
42
+ options: {
43
+ ply: {}
44
+ }
45
+ };
46
+
47
+ // src/lib/normalize-ply.ts
48
+ var import_schema2 = require("@loaders.gl/schema");
49
+
50
+ // src/lib/get-ply-schema.ts
51
+ var import_schema = require("@loaders.gl/schema");
52
+ function getPLYSchema(plyHeader, attributes) {
53
+ const metadata = makeMetadataFromPlyHeader(plyHeader);
54
+ const schema = (0, import_schema.deduceMeshSchema)(attributes, metadata);
55
+ return schema;
56
+ }
57
+ function makeMetadataFromPlyHeader(plyHeader) {
58
+ const metadata = {};
59
+ metadata.ply_comments = JSON.stringify(plyHeader.comments);
60
+ metadata.ply_elements = JSON.stringify(plyHeader.elements);
61
+ if (plyHeader.format !== void 0) {
62
+ metadata.ply_format = plyHeader.format;
63
+ }
64
+ if (plyHeader.version !== void 0) {
65
+ metadata.ply_version = plyHeader.version;
66
+ }
67
+ if (plyHeader.headerLength !== void 0) {
68
+ metadata.ply_headerLength = plyHeader.headerLength.toString(10);
69
+ }
70
+ return metadata;
71
+ }
72
+
73
+ // src/lib/normalize-ply.ts
74
+ function normalizePLY(plyHeader, plyAttributes, options) {
75
+ const attributes = getMeshAttributes(plyAttributes);
76
+ const boundingBox = (0, import_schema2.getMeshBoundingBox)(attributes);
77
+ const vertexCount = plyAttributes.indices.length || plyAttributes.vertices.length / 3;
78
+ const isTriangles = plyAttributes.indices && plyAttributes.indices.length > 0;
79
+ const mode = isTriangles ? 4 : 0;
80
+ const topology = isTriangles ? "triangle-list" : "point-list";
81
+ const schema = getPLYSchema(plyHeader, attributes);
82
+ const plyMesh = {
83
+ loader: "ply",
84
+ loaderData: plyHeader,
85
+ header: {
86
+ vertexCount,
87
+ boundingBox
88
+ },
89
+ schema,
90
+ attributes,
91
+ indices: { value: new Uint32Array(0), size: 0 },
92
+ mode,
93
+ topology
94
+ };
95
+ if (plyAttributes.indices.length > 0) {
96
+ plyMesh.indices = { value: new Uint32Array(plyAttributes.indices), size: 1 };
97
+ }
98
+ return plyMesh;
99
+ }
100
+ function getMeshAttributes(attributes) {
101
+ const accessors = {};
102
+ for (const attributeName of Object.keys(attributes)) {
103
+ switch (attributeName) {
104
+ case "vertices":
105
+ if (attributes.vertices.length > 0) {
106
+ accessors.POSITION = { value: new Float32Array(attributes.vertices), size: 3 };
107
+ }
108
+ break;
109
+ case "normals":
110
+ if (attributes.normals.length > 0) {
111
+ accessors.NORMAL = { value: new Float32Array(attributes.normals), size: 3 };
112
+ }
113
+ break;
114
+ case "uvs":
115
+ if (attributes.uvs.length > 0) {
116
+ accessors.TEXCOORD_0 = { value: new Float32Array(attributes.uvs), size: 2 };
117
+ }
118
+ break;
119
+ case "colors":
120
+ if (attributes.colors.length > 0) {
121
+ accessors.COLOR_0 = { value: new Uint8Array(attributes.colors), size: 3, normalized: true };
122
+ }
123
+ break;
124
+ case "indices":
125
+ break;
126
+ default:
127
+ if (attributes[attributeName].length > 0) {
128
+ accessors[attributeName] = { value: new Float32Array(attributes[attributeName]), size: 1 };
129
+ }
130
+ break;
131
+ }
132
+ }
133
+ return accessors;
134
+ }
135
+
136
+ // src/lib/parse-ply.ts
137
+ function parsePLY(data, options = {}) {
138
+ let header;
139
+ let attributes;
140
+ if (data instanceof ArrayBuffer) {
141
+ const text = new TextDecoder().decode(data);
142
+ header = parseHeader(text, options);
143
+ attributes = header.format === "ascii" ? parseASCII(text, header) : parseBinary(data, header);
144
+ } else {
145
+ header = parseHeader(data, options);
146
+ attributes = parseASCII(data, header);
147
+ }
148
+ return normalizePLY(header, attributes);
149
+ }
150
+ function parseHeader(data, options) {
151
+ const PLY_HEADER_PATTERN = /ply([\s\S]*)end_header\s/;
152
+ let headerText = "";
153
+ let headerLength = 0;
154
+ const result = PLY_HEADER_PATTERN.exec(data);
155
+ if (result !== null) {
156
+ headerText = result[1];
157
+ headerLength = result[0].length;
158
+ }
159
+ const lines = headerText.split("\n");
160
+ const header = parseHeaderLines(lines, headerLength, options);
161
+ return header;
162
+ }
163
+ function parseHeaderLines(lines, headerLength, options) {
164
+ const header = {
165
+ comments: [],
166
+ elements: [],
167
+ headerLength
168
+ };
169
+ let lineType;
170
+ let lineValues;
171
+ let currentElement2 = null;
172
+ for (let i = 0; i < lines.length; i++) {
173
+ let line = lines[i];
174
+ line = line.trim();
175
+ if (line === "") {
176
+ continue;
177
+ }
178
+ lineValues = line.split(/\s+/);
179
+ lineType = lineValues.shift();
180
+ line = lineValues.join(" ");
181
+ switch (lineType) {
182
+ case "format":
183
+ header.format = lineValues[0];
184
+ header.version = lineValues[1];
185
+ break;
186
+ case "comment":
187
+ header.comments.push(line);
188
+ break;
189
+ case "element":
190
+ if (currentElement2) {
191
+ header.elements.push(currentElement2);
192
+ }
193
+ currentElement2 = {
194
+ name: lineValues[0],
195
+ count: parseInt(lineValues[1], 10),
196
+ properties: []
197
+ };
198
+ break;
199
+ case "property":
200
+ if (currentElement2) {
201
+ const property = makePLYElementProperty(lineValues);
202
+ if ((options == null ? void 0 : options.propertyNameMapping) && property.name in (options == null ? void 0 : options.propertyNameMapping)) {
203
+ property.name = options == null ? void 0 : options.propertyNameMapping[property.name];
204
+ }
205
+ currentElement2.properties.push(property);
206
+ }
207
+ break;
208
+ default:
209
+ console.log("unhandled", lineType, lineValues);
210
+ }
211
+ }
212
+ if (currentElement2) {
213
+ header.elements.push(currentElement2);
214
+ }
215
+ return header;
216
+ }
217
+ function getPLYAttributes(header) {
218
+ const attributes = {
219
+ indices: [],
220
+ vertices: [],
221
+ normals: [],
222
+ uvs: [],
223
+ colors: []
224
+ };
225
+ for (const element of header.elements) {
226
+ if (element.name === "vertex") {
227
+ for (const property of element.properties) {
228
+ switch (property.name) {
229
+ case "x":
230
+ case "y":
231
+ case "z":
232
+ case "nx":
233
+ case "ny":
234
+ case "nz":
235
+ case "s":
236
+ case "t":
237
+ case "red":
238
+ case "green":
239
+ case "blue":
240
+ break;
241
+ default:
242
+ attributes[property.name] = [];
243
+ break;
244
+ }
245
+ }
246
+ }
247
+ }
248
+ return attributes;
249
+ }
250
+ function makePLYElementProperty(propertyValues) {
251
+ const type = propertyValues[0];
252
+ switch (type) {
253
+ case "list":
254
+ return {
255
+ type,
256
+ name: propertyValues[3],
257
+ countType: propertyValues[1],
258
+ itemType: propertyValues[2]
259
+ };
260
+ default:
261
+ return {
262
+ type,
263
+ name: propertyValues[1]
264
+ };
265
+ }
266
+ }
267
+ function parseASCIINumber(n, type) {
268
+ switch (type) {
269
+ case "char":
270
+ case "uchar":
271
+ case "short":
272
+ case "ushort":
273
+ case "int":
274
+ case "uint":
275
+ case "int8":
276
+ case "uint8":
277
+ case "int16":
278
+ case "uint16":
279
+ case "int32":
280
+ case "uint32":
281
+ return parseInt(n, 10);
282
+ case "float":
283
+ case "double":
284
+ case "float32":
285
+ case "float64":
286
+ return parseFloat(n);
287
+ default:
288
+ throw new Error(type);
289
+ }
290
+ }
291
+ function parsePLYElement(properties, line) {
292
+ const values = line.split(/\s+/);
293
+ const element = {};
294
+ for (let i = 0; i < properties.length; i++) {
295
+ if (properties[i].type === "list") {
296
+ const list = [];
297
+ const n = parseASCIINumber(values.shift(), properties[i].countType);
298
+ for (let j = 0; j < n; j++) {
299
+ list.push(parseASCIINumber(values.shift(), properties[i].itemType));
300
+ }
301
+ element[properties[i].name] = list;
302
+ } else {
303
+ element[properties[i].name] = parseASCIINumber(values.shift(), properties[i].type);
304
+ }
305
+ }
306
+ return element;
307
+ }
308
+ function parseASCII(data, header) {
309
+ const attributes = getPLYAttributes(header);
310
+ let result;
311
+ const patternBody = /end_header\s([\s\S]*)$/;
312
+ let body = "";
313
+ if ((result = patternBody.exec(data)) !== null) {
314
+ body = result[1];
315
+ }
316
+ const lines = body.split("\n");
317
+ let currentElement2 = 0;
318
+ let currentElementCount = 0;
319
+ for (let i = 0; i < lines.length; i++) {
320
+ let line = lines[i];
321
+ line = line.trim();
322
+ if (line !== "") {
323
+ if (currentElementCount >= header.elements[currentElement2].count) {
324
+ currentElement2++;
325
+ currentElementCount = 0;
326
+ }
327
+ const element = parsePLYElement(header.elements[currentElement2].properties, line);
328
+ handleElement(attributes, header.elements[currentElement2].name, element);
329
+ currentElementCount++;
330
+ }
331
+ }
332
+ return attributes;
333
+ }
334
+ function handleElement(buffer, elementName, element = {}) {
335
+ if (elementName === "vertex") {
336
+ for (const propertyName of Object.keys(element)) {
337
+ switch (propertyName) {
338
+ case "x":
339
+ buffer.vertices.push(element.x, element.y, element.z);
340
+ break;
341
+ case "y":
342
+ case "z":
343
+ break;
344
+ case "nx":
345
+ if ("nx" in element && "ny" in element && "nz" in element) {
346
+ buffer.normals.push(element.nx, element.ny, element.nz);
347
+ }
348
+ break;
349
+ case "ny":
350
+ case "nz":
351
+ break;
352
+ case "s":
353
+ if ("s" in element && "t" in element) {
354
+ buffer.uvs.push(element.s, element.t);
355
+ }
356
+ break;
357
+ case "t":
358
+ break;
359
+ case "red":
360
+ if ("red" in element && "green" in element && "blue" in element) {
361
+ buffer.colors.push(element.red, element.green, element.blue);
362
+ }
363
+ break;
364
+ case "green":
365
+ case "blue":
366
+ break;
367
+ default:
368
+ buffer[propertyName].push(element[propertyName]);
369
+ }
370
+ }
371
+ } else if (elementName === "face") {
372
+ const vertexIndices = element.vertex_indices || element.vertex_index;
373
+ if (vertexIndices.length === 3) {
374
+ buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[2]);
375
+ } else if (vertexIndices.length === 4) {
376
+ buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[3]);
377
+ buffer.indices.push(vertexIndices[1], vertexIndices[2], vertexIndices[3]);
378
+ }
379
+ }
380
+ }
381
+ function binaryRead(dataview, at, type, littleEndian) {
382
+ switch (type) {
383
+ case "int8":
384
+ case "char":
385
+ return [dataview.getInt8(at), 1];
386
+ case "uint8":
387
+ case "uchar":
388
+ return [dataview.getUint8(at), 1];
389
+ case "int16":
390
+ case "short":
391
+ return [dataview.getInt16(at, littleEndian), 2];
392
+ case "uint16":
393
+ case "ushort":
394
+ return [dataview.getUint16(at, littleEndian), 2];
395
+ case "int32":
396
+ case "int":
397
+ return [dataview.getInt32(at, littleEndian), 4];
398
+ case "uint32":
399
+ case "uint":
400
+ return [dataview.getUint32(at, littleEndian), 4];
401
+ case "float32":
402
+ case "float":
403
+ return [dataview.getFloat32(at, littleEndian), 4];
404
+ case "float64":
405
+ case "double":
406
+ return [dataview.getFloat64(at, littleEndian), 8];
407
+ default:
408
+ throw new Error(type);
409
+ }
410
+ }
411
+ function binaryReadElement(dataview, at, properties, littleEndian) {
412
+ const element = {};
413
+ let result;
414
+ let read = 0;
415
+ for (let i = 0; i < properties.length; i++) {
416
+ if (properties[i].type === "list") {
417
+ const list = [];
418
+ result = binaryRead(dataview, at + read, properties[i].countType, littleEndian);
419
+ const n = result[0];
420
+ read += result[1];
421
+ for (let j = 0; j < n; j++) {
422
+ result = binaryRead(dataview, at + read, properties[i].itemType, littleEndian);
423
+ list.push(result[0]);
424
+ read += result[1];
425
+ }
426
+ element[properties[i].name] = list;
427
+ } else {
428
+ result = binaryRead(dataview, at + read, properties[i].type, littleEndian);
429
+ element[properties[i].name] = result[0];
430
+ read += result[1];
431
+ }
432
+ }
433
+ return [element, read];
434
+ }
435
+ function parseBinary(data, header) {
436
+ const attributes = getPLYAttributes(header);
437
+ const littleEndian = header.format === "binary_little_endian";
438
+ const body = new DataView(data, header.headerLength);
439
+ let result;
440
+ let loc = 0;
441
+ for (let currentElement2 = 0; currentElement2 < header.elements.length; currentElement2++) {
442
+ const count = header.elements[currentElement2].count;
443
+ for (let currentElementCount = 0; currentElementCount < count; currentElementCount++) {
444
+ result = binaryReadElement(
445
+ body,
446
+ loc,
447
+ header.elements[currentElement2].properties,
448
+ littleEndian
449
+ );
450
+ loc += result[1];
451
+ const element = result[0];
452
+ handleElement(attributes, header.elements[currentElement2].name, element);
453
+ }
454
+ }
455
+ return attributes;
456
+ }
457
+
458
+ // src/lib/parse-ply-in-batches.ts
459
+ var import_loader_utils = require("@loaders.gl/loader-utils");
460
+ var currentElement;
461
+ async function* parsePLYInBatches(iterator, options) {
462
+ const lineIterator = (0, import_loader_utils.makeLineIterator)((0, import_loader_utils.makeTextDecoderIterator)(iterator));
463
+ const header = await parsePLYHeader(lineIterator, options);
464
+ let attributes;
465
+ switch (header.format) {
466
+ case "ascii":
467
+ attributes = await parseASCII2(lineIterator, header);
468
+ break;
469
+ default:
470
+ throw new Error("Binary PLY can not yet be parsed in streaming mode");
471
+ }
472
+ yield normalizePLY(header, attributes, options);
473
+ }
474
+ async function parsePLYHeader(lineIterator, options) {
475
+ const header = {
476
+ comments: [],
477
+ elements: []
478
+ // headerLength
479
+ };
480
+ await (0, import_loader_utils.forEach)(lineIterator, (line) => {
481
+ line = line.trim();
482
+ if (line === "end_header") {
483
+ return true;
484
+ }
485
+ if (line === "") {
486
+ return false;
487
+ }
488
+ const lineValues = line.split(/\s+/);
489
+ const lineType = lineValues.shift();
490
+ line = lineValues.join(" ");
491
+ switch (lineType) {
492
+ case "ply":
493
+ break;
494
+ case "format":
495
+ header.format = lineValues[0];
496
+ header.version = lineValues[1];
497
+ break;
498
+ case "comment":
499
+ header.comments.push(line);
500
+ break;
501
+ case "element":
502
+ if (currentElement) {
503
+ header.elements.push(currentElement);
504
+ }
505
+ currentElement = {
506
+ name: lineValues[0],
507
+ count: parseInt(lineValues[1], 10),
508
+ properties: []
509
+ };
510
+ break;
511
+ case "property":
512
+ const property = makePLYElementProperty2(lineValues, options.propertyNameMapping);
513
+ currentElement.properties.push(property);
514
+ break;
515
+ default:
516
+ console.log("unhandled", lineType, lineValues);
517
+ }
518
+ return false;
519
+ });
520
+ if (currentElement) {
521
+ header.elements.push(currentElement);
522
+ }
523
+ return header;
524
+ }
525
+ function makePLYElementProperty2(propertyValues, propertyNameMapping) {
526
+ const type = propertyValues[0];
527
+ switch (type) {
528
+ case "list":
529
+ return {
530
+ type,
531
+ name: propertyValues[3],
532
+ countType: propertyValues[1],
533
+ itemType: propertyValues[2]
534
+ };
535
+ default:
536
+ return {
537
+ type,
538
+ name: propertyValues[1]
539
+ };
540
+ }
541
+ }
542
+ async function parseASCII2(lineIterator, header) {
543
+ const attributes = {
544
+ indices: [],
545
+ vertices: [],
546
+ normals: [],
547
+ uvs: [],
548
+ colors: []
549
+ };
550
+ let currentElement2 = 0;
551
+ let currentElementCount = 0;
552
+ for await (let line of lineIterator) {
553
+ line = line.trim();
554
+ if (line !== "") {
555
+ if (currentElementCount >= header.elements[currentElement2].count) {
556
+ currentElement2++;
557
+ currentElementCount = 0;
558
+ }
559
+ const element = parsePLYElement2(header.elements[currentElement2].properties, line);
560
+ handleElement2(attributes, header.elements[currentElement2].name, element);
561
+ currentElementCount++;
562
+ }
563
+ }
564
+ return attributes;
565
+ }
566
+ function parseASCIINumber2(n, type) {
567
+ switch (type) {
568
+ case "char":
569
+ case "uchar":
570
+ case "short":
571
+ case "ushort":
572
+ case "int":
573
+ case "uint":
574
+ case "int8":
575
+ case "uint8":
576
+ case "int16":
577
+ case "uint16":
578
+ case "int32":
579
+ case "uint32":
580
+ return parseInt(n, 10);
581
+ case "float":
582
+ case "double":
583
+ case "float32":
584
+ case "float64":
585
+ return parseFloat(n);
586
+ default:
587
+ throw new Error(type);
588
+ }
589
+ }
590
+ function parsePLYElement2(properties, line) {
591
+ const values = line.split(/\s+/);
592
+ const element = {};
593
+ for (let i = 0; i < properties.length; i++) {
594
+ if (properties[i].type === "list") {
595
+ const list = [];
596
+ const n = parseASCIINumber2(values.shift(), properties[i].countType);
597
+ for (let j = 0; j < n; j++) {
598
+ list.push(parseASCIINumber2(values.shift(), properties[i].itemType));
599
+ }
600
+ element[properties[i].name] = list;
601
+ } else {
602
+ element[properties[i].name] = parseASCIINumber2(values.shift(), properties[i].type);
603
+ }
604
+ }
605
+ return element;
606
+ }
607
+ function handleElement2(buffer, elementName, element = {}) {
608
+ switch (elementName) {
609
+ case "vertex":
610
+ buffer.vertices.push(element.x, element.y, element.z);
611
+ if ("nx" in element && "ny" in element && "nz" in element) {
612
+ buffer.normals.push(element.nx, element.ny, element.nz);
613
+ }
614
+ if ("s" in element && "t" in element) {
615
+ buffer.uvs.push(element.s, element.t);
616
+ }
617
+ if ("red" in element && "green" in element && "blue" in element) {
618
+ buffer.colors.push(element.red / 255, element.green / 255, element.blue / 255);
619
+ }
620
+ break;
621
+ case "face":
622
+ const vertexIndices = element.vertex_indices || element.vertex_index;
623
+ if (vertexIndices.length === 3) {
624
+ buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[2]);
625
+ } else if (vertexIndices.length === 4) {
626
+ buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[3]);
627
+ buffer.indices.push(vertexIndices[1], vertexIndices[2], vertexIndices[3]);
628
+ }
629
+ break;
630
+ default:
631
+ break;
632
+ }
633
+ }
634
+
635
+ // src/index.ts
636
+ var PLYLoader2 = {
637
+ ...PLYLoader,
638
+ // Note: parsePLY supports both text and binary
639
+ parse: async (arrayBuffer, options) => parsePLY(arrayBuffer, options == null ? void 0 : options.ply),
640
+ // TODO - this may not detect text correctly?
641
+ parseTextSync: (arrayBuffer, options) => parsePLY(arrayBuffer, options == null ? void 0 : options.ply),
642
+ parseSync: (arrayBuffer, options) => parsePLY(arrayBuffer, options == null ? void 0 : options.ply),
643
+ parseInBatches: (arrayBuffer, options) => parsePLYInBatches(arrayBuffer, options == null ? void 0 : options.ply)
644
+ };
@@ -1,6 +1,6 @@
1
- import { PLYLoader as PLYWorkerLoader } from './ply-loader';
2
- import { parsePLY } from './lib/parse-ply';
3
- import { parsePLYInBatches } from './lib/parse-ply-in-batches';
1
+ import { PLYLoader as PLYWorkerLoader } from "./ply-loader.js";
2
+ import { parsePLY } from "./lib/parse-ply.js";
3
+ import { parsePLYInBatches } from "./lib/parse-ply-in-batches.js";
4
4
  export { PLYWorkerLoader };
5
5
  export const PLYLoader = {
6
6
  ...PLYWorkerLoader,
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["PLYLoader","PLYWorkerLoader","parsePLY","parsePLYInBatches","parse","arrayBuffer","options","ply","parseTextSync","parseSync","parseInBatches"],"sources":["../src/index.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport type {LoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils';\nimport type {PLYMesh} from './lib/ply-types';\nimport {PLYLoader as PLYWorkerLoader} from './ply-loader';\nimport {ParsePLYOptions, parsePLY} from './lib/parse-ply';\nimport {parsePLYInBatches} from './lib/parse-ply-in-batches';\n\n// PLYLoader\n\nexport {PLYWorkerLoader};\n\nexport type PLYLoaderOptions = LoaderOptions & {\n ply?: ParsePLYOptions;\n};\n\n/**\n * Loader for PLY - Polygon File Format\n */\nexport const PLYLoader: LoaderWithParser<PLYMesh, any, PLYLoaderOptions> = {\n ...PLYWorkerLoader,\n // Note: parsePLY supports both text and binary\n parse: async (arrayBuffer, options) => parsePLY(arrayBuffer, options?.ply), // TODO - this may not detect text correctly?\n parseTextSync: (arrayBuffer, options) => parsePLY(arrayBuffer, options?.ply),\n parseSync: (arrayBuffer, options) => parsePLY(arrayBuffer, options?.ply),\n parseInBatches: (arrayBuffer, options) => parsePLYInBatches(arrayBuffer, options?.ply)\n};\n"],"mappings":"SAIQA,SAAS,IAAIC,eAAe;AAAA,SACXC,QAAQ;AAAA,SACzBC,iBAAiB;AAIzB,SAAQF,eAAe;AASvB,OAAO,MAAMD,SAA2D,GAAG;EACzE,GAAGC,eAAe;EAElBG,KAAK,EAAE,MAAAA,CAAOC,WAAW,EAAEC,OAAO,KAAKJ,QAAQ,CAACG,WAAW,EAAEC,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEC,GAAG,CAAC;EAC1EC,aAAa,EAAEA,CAACH,WAAW,EAAEC,OAAO,KAAKJ,QAAQ,CAACG,WAAW,EAAEC,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEC,GAAG,CAAC;EAC5EE,SAAS,EAAEA,CAACJ,WAAW,EAAEC,OAAO,KAAKJ,QAAQ,CAACG,WAAW,EAAEC,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEC,GAAG,CAAC;EACxEG,cAAc,EAAEA,CAACL,WAAW,EAAEC,OAAO,KAAKH,iBAAiB,CAACE,WAAW,EAAEC,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEC,GAAG;AACvF,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-ply-schema.js","names":["deduceMeshSchema","getPLYSchema","plyHeader","attributes","metadata","makeMetadataFromPlyHeader","schema","ply_comments","JSON","stringify","comments","ply_elements","elements","format","undefined","ply_format","version","ply_version","headerLength","ply_headerLength","toString"],"sources":["../../src/lib/get-ply-schema.ts"],"sourcesContent":["import {Schema, MeshAttributes, deduceMeshSchema} from '@loaders.gl/schema';\nimport type {PLYHeader} from './ply-types';\n\n/**\n * Gets schema from PLY header\n * @param plyHeader\n * @param metadata\n * @returns Schema\n */\nexport function getPLYSchema(plyHeader: PLYHeader, attributes: MeshAttributes): Schema {\n const metadata = makeMetadataFromPlyHeader(plyHeader);\n const schema = deduceMeshSchema(attributes, metadata);\n return schema;\n}\n\n/**\n * Make arrow like schema metadata by PlyHeader properties\n * @param plyHeader\n * @returns\n */\nfunction makeMetadataFromPlyHeader(plyHeader: PLYHeader): Record<string, string> {\n /* eslint-disable camelcase */\n const metadata: Record<string, string> = {};\n metadata.ply_comments = JSON.stringify(plyHeader.comments);\n metadata.ply_elements = JSON.stringify(plyHeader.elements);\n if (plyHeader.format !== undefined) {\n metadata.ply_format = plyHeader.format;\n }\n if (plyHeader.version !== undefined) {\n metadata.ply_version = plyHeader.version;\n }\n if (plyHeader.headerLength !== undefined) {\n metadata.ply_headerLength = plyHeader.headerLength.toString(10);\n }\n return metadata;\n}\n"],"mappings":"AAAA,SAAgCA,gBAAgB,QAAO,oBAAoB;AAS3E,OAAO,SAASC,YAAYA,CAACC,SAAoB,EAAEC,UAA0B,EAAU;EACrF,MAAMC,QAAQ,GAAGC,yBAAyB,CAACH,SAAS,CAAC;EACrD,MAAMI,MAAM,GAAGN,gBAAgB,CAACG,UAAU,EAAEC,QAAQ,CAAC;EACrD,OAAOE,MAAM;AACf;AAOA,SAASD,yBAAyBA,CAACH,SAAoB,EAA0B;EAE/E,MAAME,QAAgC,GAAG,CAAC,CAAC;EAC3CA,QAAQ,CAACG,YAAY,GAAGC,IAAI,CAACC,SAAS,CAACP,SAAS,CAACQ,QAAQ,CAAC;EAC1DN,QAAQ,CAACO,YAAY,GAAGH,IAAI,CAACC,SAAS,CAACP,SAAS,CAACU,QAAQ,CAAC;EAC1D,IAAIV,SAAS,CAACW,MAAM,KAAKC,SAAS,EAAE;IAClCV,QAAQ,CAACW,UAAU,GAAGb,SAAS,CAACW,MAAM;EACxC;EACA,IAAIX,SAAS,CAACc,OAAO,KAAKF,SAAS,EAAE;IACnCV,QAAQ,CAACa,WAAW,GAAGf,SAAS,CAACc,OAAO;EAC1C;EACA,IAAId,SAAS,CAACgB,YAAY,KAAKJ,SAAS,EAAE;IACxCV,QAAQ,CAACe,gBAAgB,GAAGjB,SAAS,CAACgB,YAAY,CAACE,QAAQ,CAAC,EAAE,CAAC;EACjE;EACA,OAAOhB,QAAQ;AACjB"}
@@ -1,5 +1,5 @@
1
1
  import { getMeshBoundingBox } from '@loaders.gl/schema';
2
- import { getPLYSchema } from './get-ply-schema';
2
+ import { getPLYSchema } from "./get-ply-schema.js";
3
3
  export default function normalizePLY(plyHeader, plyAttributes, options) {
4
4
  const attributes = getMeshAttributes(plyAttributes);
5
5
  const boundingBox = getMeshBoundingBox(attributes);
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-ply.js","names":["getMeshBoundingBox","getPLYSchema","normalizePLY","plyHeader","plyAttributes","options","attributes","getMeshAttributes","boundingBox","vertexCount","indices","length","vertices","isTriangles","mode","topology","schema","plyMesh","loader","loaderData","header","value","Uint32Array","size","accessors","attributeName","Object","keys","POSITION","Float32Array","normals","NORMAL","uvs","TEXCOORD_0","colors","COLOR_0","Uint8Array","normalized"],"sources":["../../src/lib/normalize-ply.ts"],"sourcesContent":["import type {MeshAttributes} from '@loaders.gl/schema';\nimport {getMeshBoundingBox} from '@loaders.gl/schema';\nimport type {PLYMesh, PLYHeader, PLYAttributes, MeshHeader} from './ply-types';\nimport {getPLYSchema} from './get-ply-schema';\n\n/**\n * @param header\n * @param attributes\n * @returns data and header\n */\nexport default function normalizePLY(\n plyHeader: MeshHeader & PLYHeader,\n plyAttributes: PLYAttributes,\n options?: {}\n): PLYMesh {\n const attributes = getMeshAttributes(plyAttributes);\n const boundingBox = getMeshBoundingBox(attributes);\n const vertexCount = plyAttributes.indices.length || plyAttributes.vertices.length / 3;\n\n // TODO - how to detect POINT CLOUDS vs MESHES?\n // TODO - For Meshes, PLY quadrangles must be split?\n const isTriangles = plyAttributes.indices && plyAttributes.indices.length > 0;\n const mode = isTriangles ? 4 : 0; // TRIANGLES vs POINTS\n const topology = isTriangles ? 'triangle-list' : 'point-list';\n\n const schema = getPLYSchema(plyHeader, attributes);\n\n const plyMesh: PLYMesh = {\n loader: 'ply',\n loaderData: plyHeader,\n header: {\n vertexCount,\n boundingBox\n },\n schema,\n attributes,\n indices: {value: new Uint32Array(0), size: 0},\n mode,\n topology\n };\n\n if (plyAttributes.indices.length > 0) {\n plyMesh.indices = {value: new Uint32Array(plyAttributes.indices), size: 1};\n }\n\n return plyMesh;\n}\n\n/**\n * @param attributes\n * @returns accessors []\n */\n// eslint-disable-next-line complexity\nfunction getMeshAttributes(attributes: PLYAttributes): MeshAttributes {\n const accessors: MeshAttributes = {};\n\n for (const attributeName of Object.keys(attributes)) {\n switch (attributeName) {\n case 'vertices':\n if (attributes.vertices.length > 0) {\n accessors.POSITION = {value: new Float32Array(attributes.vertices), size: 3};\n }\n break;\n\n // optional attributes data\n case 'normals':\n if (attributes.normals.length > 0) {\n accessors.NORMAL = {value: new Float32Array(attributes.normals), size: 3};\n }\n break;\n\n case 'uvs':\n if (attributes.uvs.length > 0) {\n accessors.TEXCOORD_0 = {value: new Float32Array(attributes.uvs), size: 2};\n }\n break;\n\n case 'colors':\n if (attributes.colors.length > 0) {\n // TODO - normalized shoud be based on `uchar` flag in source data?\n accessors.COLOR_0 = {value: new Uint8Array(attributes.colors), size: 3, normalized: true};\n }\n break;\n\n case 'indices':\n break;\n\n default:\n if (attributes[attributeName].length > 0) {\n accessors[attributeName] = {value: new Float32Array(attributes[attributeName]), size: 1};\n }\n break;\n }\n }\n return accessors;\n}\n"],"mappings":"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"}
@@ -1,5 +1,5 @@
1
1
  import { makeLineIterator, makeTextDecoderIterator, forEach } from '@loaders.gl/loader-utils';
2
- import normalizePLY from './normalize-ply';
2
+ import normalizePLY from "./normalize-ply.js";
3
3
  let currentElement;
4
4
  export async function* parsePLYInBatches(iterator, options) {
5
5
  const lineIterator = makeLineIterator(makeTextDecoderIterator(iterator));