@loaders.gl/ply 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 (74) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/dist.min.js +201 -609
  3. package/dist/es5/bundle.js +6 -0
  4. package/dist/es5/bundle.js.map +1 -0
  5. package/dist/es5/index.js +51 -0
  6. package/dist/es5/index.js.map +1 -0
  7. package/dist/es5/lib/get-ply-schema.js +28 -0
  8. package/dist/es5/lib/get-ply-schema.js.map +1 -0
  9. package/dist/es5/lib/normalize-ply.js +93 -0
  10. package/dist/es5/lib/normalize-ply.js.map +1 -0
  11. package/dist/es5/lib/parse-ply-in-batches.js +289 -0
  12. package/dist/es5/lib/parse-ply-in-batches.js.map +1 -0
  13. package/dist/es5/lib/parse-ply.js +348 -0
  14. package/dist/es5/lib/parse-ply.js.map +1 -0
  15. package/dist/es5/lib/ply-types.js +2 -0
  16. package/dist/es5/lib/ply-types.js.map +1 -0
  17. package/dist/es5/ply-loader.js +26 -0
  18. package/dist/es5/ply-loader.js.map +1 -0
  19. package/dist/es5/workers/ply-worker.js +6 -0
  20. package/dist/es5/workers/ply-worker.js.map +1 -0
  21. package/dist/esm/bundle.js +4 -0
  22. package/dist/esm/bundle.js.map +1 -0
  23. package/dist/esm/index.js +12 -0
  24. package/dist/esm/index.js.map +1 -0
  25. package/dist/esm/lib/get-ply-schema.js +22 -0
  26. package/dist/esm/lib/get-ply-schema.js.map +1 -0
  27. package/dist/esm/lib/normalize-ply.js +86 -0
  28. package/dist/esm/lib/normalize-ply.js.map +1 -0
  29. package/dist/esm/lib/parse-ply-in-batches.js +177 -0
  30. package/dist/esm/lib/parse-ply-in-batches.js.map +1 -0
  31. package/dist/esm/lib/parse-ply.js +319 -0
  32. package/dist/esm/lib/parse-ply.js.map +1 -0
  33. package/dist/esm/lib/ply-types.js +2 -0
  34. package/dist/esm/lib/ply-types.js.map +1 -0
  35. package/dist/esm/ply-loader.js +18 -0
  36. package/dist/esm/ply-loader.js.map +1 -0
  37. package/dist/esm/workers/ply-worker.js +4 -0
  38. package/dist/esm/workers/ply-worker.js.map +1 -0
  39. package/dist/index.d.ts +7 -24
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +18 -11
  42. package/dist/lib/get-ply-schema.js +34 -24
  43. package/dist/lib/normalize-ply.js +76 -65
  44. package/dist/lib/parse-ply-in-batches.d.ts +1 -1
  45. package/dist/lib/parse-ply-in-batches.d.ts.map +1 -1
  46. package/dist/lib/parse-ply-in-batches.js +237 -202
  47. package/dist/lib/parse-ply.d.ts +4 -1
  48. package/dist/lib/parse-ply.d.ts.map +1 -1
  49. package/dist/lib/parse-ply.js +378 -299
  50. package/dist/lib/ply-types.d.ts +22 -14
  51. package/dist/lib/ply-types.d.ts.map +1 -1
  52. package/dist/lib/ply-types.js +2 -2
  53. package/dist/ply-loader.d.ts +3 -17
  54. package/dist/ply-loader.d.ts.map +1 -1
  55. package/dist/ply-loader.js +27 -18
  56. package/dist/ply-worker.js +240 -578
  57. package/dist/workers/ply-worker.js +5 -4
  58. package/package.json +6 -6
  59. package/src/index.ts +15 -10
  60. package/src/lib/get-ply-schema.ts +11 -10
  61. package/src/lib/normalize-ply.ts +34 -12
  62. package/src/lib/parse-ply-in-batches.ts +20 -22
  63. package/src/lib/parse-ply.ts +114 -55
  64. package/src/lib/ply-types.ts +21 -12
  65. package/src/ply-loader.ts +4 -3
  66. package/dist/bundle.js.map +0 -1
  67. package/dist/index.js.map +0 -1
  68. package/dist/lib/get-ply-schema.js.map +0 -1
  69. package/dist/lib/normalize-ply.js.map +0 -1
  70. package/dist/lib/parse-ply-in-batches.js.map +0 -1
  71. package/dist/lib/parse-ply.js.map +0 -1
  72. package/dist/lib/ply-types.js.map +0 -1
  73. package/dist/ply-loader.js.map +0 -1
  74. package/dist/workers/ply-worker.js.map +0 -1
package/dist/dist.min.js CHANGED
@@ -22,7 +22,6 @@
22
22
  name: "PLY",
23
23
  id: "ply",
24
24
  module: "ply",
25
- shapes: ["mesh", "gltf", "columnar-table"],
26
25
  version: VERSION,
27
26
  worker: true,
28
27
  extensions: ["ply"],
@@ -37,7 +36,36 @@
37
36
  }
38
37
  });
39
38
 
40
- // ../schema/src/category/mesh/mesh-utils.ts
39
+ // ../schema/src/lib/table/simple-table/data-type.ts
40
+ function getDataTypeFromTypedArray(array) {
41
+ switch (array.constructor) {
42
+ case Int8Array:
43
+ return "int8";
44
+ case Uint8Array:
45
+ case Uint8ClampedArray:
46
+ return "uint8";
47
+ case Int16Array:
48
+ return "int16";
49
+ case Uint16Array:
50
+ return "uint16";
51
+ case Int32Array:
52
+ return "int32";
53
+ case Uint32Array:
54
+ return "uint32";
55
+ case Float32Array:
56
+ return "float32";
57
+ case Float64Array:
58
+ return "float64";
59
+ default:
60
+ return "null";
61
+ }
62
+ }
63
+ var init_data_type = __esm({
64
+ "../schema/src/lib/table/simple-table/data-type.ts"() {
65
+ }
66
+ });
67
+
68
+ // ../schema/src/lib/mesh/mesh-utils.ts
41
69
  function getMeshBoundingBox(attributes) {
42
70
  let minX = Infinity;
43
71
  let minY = Infinity;
@@ -64,529 +92,24 @@
64
92
  ];
65
93
  }
66
94
  var init_mesh_utils = __esm({
67
- "../schema/src/category/mesh/mesh-utils.ts"() {
68
- }
69
- });
70
-
71
- // ../schema/src/lib/utils/assert.ts
72
- function assert(condition, message) {
73
- if (!condition) {
74
- throw new Error(message || "loader assertion failed.");
75
- }
76
- }
77
- var init_assert = __esm({
78
- "../schema/src/lib/utils/assert.ts"() {
79
- }
80
- });
81
-
82
- // ../schema/src/lib/schema/impl/schema.ts
83
- function checkNames(fields) {
84
- const usedNames = {};
85
- for (const field of fields) {
86
- if (usedNames[field.name]) {
87
- console.warn("Schema: duplicated field name", field.name, field);
88
- }
89
- usedNames[field.name] = true;
90
- }
91
- }
92
- function mergeMaps(m1, m2) {
93
- return new Map([...m1 || new Map(), ...m2 || new Map()]);
94
- }
95
- var Schema;
96
- var init_schema = __esm({
97
- "../schema/src/lib/schema/impl/schema.ts"() {
98
- init_assert();
99
- Schema = class {
100
- constructor(fields, metadata) {
101
- assert(Array.isArray(fields));
102
- checkNames(fields);
103
- this.fields = fields;
104
- this.metadata = metadata || new Map();
105
- }
106
- compareTo(other) {
107
- if (this.metadata !== other.metadata) {
108
- return false;
109
- }
110
- if (this.fields.length !== other.fields.length) {
111
- return false;
112
- }
113
- for (let i = 0; i < this.fields.length; ++i) {
114
- if (!this.fields[i].compareTo(other.fields[i])) {
115
- return false;
116
- }
117
- }
118
- return true;
119
- }
120
- select(...columnNames) {
121
- const nameMap = Object.create(null);
122
- for (const name of columnNames) {
123
- nameMap[name] = true;
124
- }
125
- const selectedFields = this.fields.filter((field) => nameMap[field.name]);
126
- return new Schema(selectedFields, this.metadata);
127
- }
128
- selectAt(...columnIndices) {
129
- const selectedFields = columnIndices.map((index) => this.fields[index]).filter(Boolean);
130
- return new Schema(selectedFields, this.metadata);
131
- }
132
- assign(schemaOrFields) {
133
- let fields;
134
- let metadata = this.metadata;
135
- if (schemaOrFields instanceof Schema) {
136
- const otherSchema = schemaOrFields;
137
- fields = otherSchema.fields;
138
- metadata = mergeMaps(mergeMaps(new Map(), this.metadata), otherSchema.metadata);
139
- } else {
140
- fields = schemaOrFields;
141
- }
142
- const fieldMap = Object.create(null);
143
- for (const field of this.fields) {
144
- fieldMap[field.name] = field;
145
- }
146
- for (const field of fields) {
147
- fieldMap[field.name] = field;
148
- }
149
- const mergedFields = Object.values(fieldMap);
150
- return new Schema(mergedFields, metadata);
151
- }
152
- };
153
- }
154
- });
155
-
156
- // ../schema/src/lib/schema/impl/field.ts
157
- var Field;
158
- var init_field = __esm({
159
- "../schema/src/lib/schema/impl/field.ts"() {
160
- Field = class {
161
- constructor(name, type, nullable = false, metadata = new Map()) {
162
- this.name = name;
163
- this.type = type;
164
- this.nullable = nullable;
165
- this.metadata = metadata;
166
- }
167
- get typeId() {
168
- return this.type && this.type.typeId;
169
- }
170
- clone() {
171
- return new Field(this.name, this.type, this.nullable, this.metadata);
172
- }
173
- compareTo(other) {
174
- return this.name === other.name && this.type === other.type && this.nullable === other.nullable && this.metadata === other.metadata;
175
- }
176
- toString() {
177
- return `${this.type}${this.nullable ? ", nullable" : ""}${this.metadata ? `, metadata: ${this.metadata}` : ""}`;
178
- }
179
- };
180
- }
181
- });
182
-
183
- // ../schema/src/lib/schema/impl/enum.ts
184
- var Type;
185
- var init_enum = __esm({
186
- "../schema/src/lib/schema/impl/enum.ts"() {
187
- (function(Type2) {
188
- Type2[Type2["NONE"] = 0] = "NONE";
189
- Type2[Type2["Null"] = 1] = "Null";
190
- Type2[Type2["Int"] = 2] = "Int";
191
- Type2[Type2["Float"] = 3] = "Float";
192
- Type2[Type2["Binary"] = 4] = "Binary";
193
- Type2[Type2["Utf8"] = 5] = "Utf8";
194
- Type2[Type2["Bool"] = 6] = "Bool";
195
- Type2[Type2["Decimal"] = 7] = "Decimal";
196
- Type2[Type2["Date"] = 8] = "Date";
197
- Type2[Type2["Time"] = 9] = "Time";
198
- Type2[Type2["Timestamp"] = 10] = "Timestamp";
199
- Type2[Type2["Interval"] = 11] = "Interval";
200
- Type2[Type2["List"] = 12] = "List";
201
- Type2[Type2["Struct"] = 13] = "Struct";
202
- Type2[Type2["Union"] = 14] = "Union";
203
- Type2[Type2["FixedSizeBinary"] = 15] = "FixedSizeBinary";
204
- Type2[Type2["FixedSizeList"] = 16] = "FixedSizeList";
205
- Type2[Type2["Map"] = 17] = "Map";
206
- Type2[Type2["Dictionary"] = -1] = "Dictionary";
207
- Type2[Type2["Int8"] = -2] = "Int8";
208
- Type2[Type2["Int16"] = -3] = "Int16";
209
- Type2[Type2["Int32"] = -4] = "Int32";
210
- Type2[Type2["Int64"] = -5] = "Int64";
211
- Type2[Type2["Uint8"] = -6] = "Uint8";
212
- Type2[Type2["Uint16"] = -7] = "Uint16";
213
- Type2[Type2["Uint32"] = -8] = "Uint32";
214
- Type2[Type2["Uint64"] = -9] = "Uint64";
215
- Type2[Type2["Float16"] = -10] = "Float16";
216
- Type2[Type2["Float32"] = -11] = "Float32";
217
- Type2[Type2["Float64"] = -12] = "Float64";
218
- Type2[Type2["DateDay"] = -13] = "DateDay";
219
- Type2[Type2["DateMillisecond"] = -14] = "DateMillisecond";
220
- Type2[Type2["TimestampSecond"] = -15] = "TimestampSecond";
221
- Type2[Type2["TimestampMillisecond"] = -16] = "TimestampMillisecond";
222
- Type2[Type2["TimestampMicrosecond"] = -17] = "TimestampMicrosecond";
223
- Type2[Type2["TimestampNanosecond"] = -18] = "TimestampNanosecond";
224
- Type2[Type2["TimeSecond"] = -19] = "TimeSecond";
225
- Type2[Type2["TimeMillisecond"] = -20] = "TimeMillisecond";
226
- Type2[Type2["TimeMicrosecond"] = -21] = "TimeMicrosecond";
227
- Type2[Type2["TimeNanosecond"] = -22] = "TimeNanosecond";
228
- Type2[Type2["DenseUnion"] = -23] = "DenseUnion";
229
- Type2[Type2["SparseUnion"] = -24] = "SparseUnion";
230
- Type2[Type2["IntervalDayTime"] = -25] = "IntervalDayTime";
231
- Type2[Type2["IntervalYearMonth"] = -26] = "IntervalYearMonth";
232
- })(Type || (Type = {}));
233
- }
234
- });
235
-
236
- // ../schema/src/lib/schema/impl/type.ts
237
- var DataType, Null, Bool, Int, Int8, Int16, Int32, Uint8, Uint16, Uint32, Precision, Float, Float32, Float64, Binary, Utf8, DateUnit, Date, TimeUnit, Time, Timestamp, IntervalUnit, Interval, FixedSizeList, Struct;
238
- var init_type = __esm({
239
- "../schema/src/lib/schema/impl/type.ts"() {
240
- init_enum();
241
- DataType = class {
242
- static isNull(x) {
243
- return x && x.typeId === Type.Null;
244
- }
245
- static isInt(x) {
246
- return x && x.typeId === Type.Int;
247
- }
248
- static isFloat(x) {
249
- return x && x.typeId === Type.Float;
250
- }
251
- static isBinary(x) {
252
- return x && x.typeId === Type.Binary;
253
- }
254
- static isUtf8(x) {
255
- return x && x.typeId === Type.Utf8;
256
- }
257
- static isBool(x) {
258
- return x && x.typeId === Type.Bool;
259
- }
260
- static isDecimal(x) {
261
- return x && x.typeId === Type.Decimal;
262
- }
263
- static isDate(x) {
264
- return x && x.typeId === Type.Date;
265
- }
266
- static isTime(x) {
267
- return x && x.typeId === Type.Time;
268
- }
269
- static isTimestamp(x) {
270
- return x && x.typeId === Type.Timestamp;
271
- }
272
- static isInterval(x) {
273
- return x && x.typeId === Type.Interval;
274
- }
275
- static isList(x) {
276
- return x && x.typeId === Type.List;
277
- }
278
- static isStruct(x) {
279
- return x && x.typeId === Type.Struct;
280
- }
281
- static isUnion(x) {
282
- return x && x.typeId === Type.Union;
283
- }
284
- static isFixedSizeBinary(x) {
285
- return x && x.typeId === Type.FixedSizeBinary;
286
- }
287
- static isFixedSizeList(x) {
288
- return x && x.typeId === Type.FixedSizeList;
289
- }
290
- static isMap(x) {
291
- return x && x.typeId === Type.Map;
292
- }
293
- static isDictionary(x) {
294
- return x && x.typeId === Type.Dictionary;
295
- }
296
- get typeId() {
297
- return Type.NONE;
298
- }
299
- compareTo(other) {
300
- return this === other;
301
- }
302
- };
303
- Null = class extends DataType {
304
- get typeId() {
305
- return Type.Null;
306
- }
307
- get [Symbol.toStringTag]() {
308
- return "Null";
309
- }
310
- toString() {
311
- return "Null";
312
- }
313
- };
314
- Bool = class extends DataType {
315
- get typeId() {
316
- return Type.Bool;
317
- }
318
- get [Symbol.toStringTag]() {
319
- return "Bool";
320
- }
321
- toString() {
322
- return "Bool";
323
- }
324
- };
325
- Int = class extends DataType {
326
- constructor(isSigned, bitWidth) {
327
- super();
328
- this.isSigned = isSigned;
329
- this.bitWidth = bitWidth;
330
- }
331
- get typeId() {
332
- return Type.Int;
333
- }
334
- get [Symbol.toStringTag]() {
335
- return "Int";
336
- }
337
- toString() {
338
- return `${this.isSigned ? "I" : "Ui"}nt${this.bitWidth}`;
339
- }
340
- };
341
- Int8 = class extends Int {
342
- constructor() {
343
- super(true, 8);
344
- }
345
- };
346
- Int16 = class extends Int {
347
- constructor() {
348
- super(true, 16);
349
- }
350
- };
351
- Int32 = class extends Int {
352
- constructor() {
353
- super(true, 32);
354
- }
355
- };
356
- Uint8 = class extends Int {
357
- constructor() {
358
- super(false, 8);
359
- }
360
- };
361
- Uint16 = class extends Int {
362
- constructor() {
363
- super(false, 16);
364
- }
365
- };
366
- Uint32 = class extends Int {
367
- constructor() {
368
- super(false, 32);
369
- }
370
- };
371
- Precision = {
372
- HALF: 16,
373
- SINGLE: 32,
374
- DOUBLE: 64
375
- };
376
- Float = class extends DataType {
377
- constructor(precision) {
378
- super();
379
- this.precision = precision;
380
- }
381
- get typeId() {
382
- return Type.Float;
383
- }
384
- get [Symbol.toStringTag]() {
385
- return "Float";
386
- }
387
- toString() {
388
- return `Float${this.precision}`;
389
- }
390
- };
391
- Float32 = class extends Float {
392
- constructor() {
393
- super(Precision.SINGLE);
394
- }
395
- };
396
- Float64 = class extends Float {
397
- constructor() {
398
- super(Precision.DOUBLE);
399
- }
400
- };
401
- Binary = class extends DataType {
402
- constructor() {
403
- super();
404
- }
405
- get typeId() {
406
- return Type.Binary;
407
- }
408
- toString() {
409
- return "Binary";
410
- }
411
- get [Symbol.toStringTag]() {
412
- return "Binary";
413
- }
414
- };
415
- Utf8 = class extends DataType {
416
- get typeId() {
417
- return Type.Utf8;
418
- }
419
- get [Symbol.toStringTag]() {
420
- return "Utf8";
421
- }
422
- toString() {
423
- return "Utf8";
424
- }
425
- };
426
- DateUnit = {
427
- DAY: 0,
428
- MILLISECOND: 1
429
- };
430
- Date = class extends DataType {
431
- constructor(unit) {
432
- super();
433
- this.unit = unit;
434
- }
435
- get typeId() {
436
- return Type.Date;
437
- }
438
- get [Symbol.toStringTag]() {
439
- return "Date";
440
- }
441
- toString() {
442
- return `Date${(this.unit + 1) * 32}<${DateUnit[this.unit]}>`;
443
- }
444
- };
445
- TimeUnit = {
446
- SECOND: 1,
447
- MILLISECOND: 1e3,
448
- MICROSECOND: 1e6,
449
- NANOSECOND: 1e9
450
- };
451
- Time = class extends DataType {
452
- constructor(unit, bitWidth) {
453
- super();
454
- this.unit = unit;
455
- this.bitWidth = bitWidth;
456
- }
457
- get typeId() {
458
- return Type.Time;
459
- }
460
- toString() {
461
- return `Time${this.bitWidth}<${TimeUnit[this.unit]}>`;
462
- }
463
- get [Symbol.toStringTag]() {
464
- return "Time";
465
- }
466
- };
467
- Timestamp = class extends DataType {
468
- constructor(unit, timezone = null) {
469
- super();
470
- this.unit = unit;
471
- this.timezone = timezone;
472
- }
473
- get typeId() {
474
- return Type.Timestamp;
475
- }
476
- get [Symbol.toStringTag]() {
477
- return "Timestamp";
478
- }
479
- toString() {
480
- return `Timestamp<${TimeUnit[this.unit]}${this.timezone ? `, ${this.timezone}` : ""}>`;
481
- }
482
- };
483
- IntervalUnit = {
484
- DAY_TIME: 0,
485
- YEAR_MONTH: 1
486
- };
487
- Interval = class extends DataType {
488
- constructor(unit) {
489
- super();
490
- this.unit = unit;
491
- }
492
- get typeId() {
493
- return Type.Interval;
494
- }
495
- get [Symbol.toStringTag]() {
496
- return "Interval";
497
- }
498
- toString() {
499
- return `Interval<${IntervalUnit[this.unit]}>`;
500
- }
501
- };
502
- FixedSizeList = class extends DataType {
503
- constructor(listSize, child) {
504
- super();
505
- this.listSize = listSize;
506
- this.children = [child];
507
- }
508
- get typeId() {
509
- return Type.FixedSizeList;
510
- }
511
- get valueType() {
512
- return this.children[0].type;
513
- }
514
- get valueField() {
515
- return this.children[0];
516
- }
517
- get [Symbol.toStringTag]() {
518
- return "FixedSizeList";
519
- }
520
- toString() {
521
- return `FixedSizeList[${this.listSize}]<${this.valueType}>`;
522
- }
523
- };
524
- Struct = class extends DataType {
525
- constructor(children) {
526
- super();
527
- this.children = children;
528
- }
529
- get typeId() {
530
- return Type.Struct;
531
- }
532
- toString() {
533
- return `Struct<{${this.children.map((f) => `${f.name}:${f.type}`).join(", ")}}>`;
534
- }
535
- get [Symbol.toStringTag]() {
536
- return "Struct";
537
- }
538
- };
539
- }
540
- });
541
-
542
- // ../schema/src/lib/schema/schema.ts
543
- var init_schema2 = __esm({
544
- "../schema/src/lib/schema/schema.ts"() {
545
- init_schema();
546
- init_field();
547
- init_type();
548
- }
549
- });
550
-
551
- // ../schema/src/lib/arrow/arrow-like-type-utils.ts
552
- function getArrowTypeFromTypedArray(array) {
553
- switch (array.constructor) {
554
- case Int8Array:
555
- return new Int8();
556
- case Uint8Array:
557
- return new Uint8();
558
- case Int16Array:
559
- return new Int16();
560
- case Uint16Array:
561
- return new Uint16();
562
- case Int32Array:
563
- return new Int32();
564
- case Uint32Array:
565
- return new Uint32();
566
- case Float32Array:
567
- return new Float32();
568
- case Float64Array:
569
- return new Float64();
570
- default:
571
- throw new Error("array type not supported");
572
- }
573
- }
574
- var init_arrow_like_type_utils = __esm({
575
- "../schema/src/lib/arrow/arrow-like-type-utils.ts"() {
576
- init_schema2();
95
+ "../schema/src/lib/mesh/mesh-utils.ts"() {
577
96
  }
578
97
  });
579
98
 
580
- // ../schema/src/category/mesh/deduce-mesh-schema.ts
581
- function deduceMeshSchema(attributes, metadata) {
99
+ // ../schema/src/lib/mesh/deduce-mesh-schema.ts
100
+ function deduceMeshSchema(attributes, metadata = {}) {
582
101
  const fields = deduceMeshFields(attributes);
583
- return new Schema(fields, metadata);
102
+ return { fields, metadata };
584
103
  }
585
- function deduceMeshField(attributeName, attribute, optionalMetadata) {
586
- const type = getArrowTypeFromTypedArray(attribute.value);
104
+ function deduceMeshField(name, attribute, optionalMetadata) {
105
+ const type = getDataTypeFromTypedArray(attribute.value);
587
106
  const metadata = optionalMetadata ? optionalMetadata : makeMeshAttributeMetadata(attribute);
588
- const field = new Field(attributeName, new FixedSizeList(attribute.size, new Field("value", type)), false, metadata);
589
- return field;
107
+ return {
108
+ name,
109
+ type: { type: "fixed-size-list", listSize: attribute.size, children: [{ name: "value", type }] },
110
+ nullable: false,
111
+ metadata
112
+ };
590
113
  }
591
114
  function deduceMeshFields(attributes) {
592
115
  const fields = [];
@@ -597,22 +120,21 @@
597
120
  return fields;
598
121
  }
599
122
  function makeMeshAttributeMetadata(attribute) {
600
- const result = new Map();
123
+ const result = {};
601
124
  if ("byteOffset" in attribute) {
602
- result.set("byteOffset", attribute.byteOffset.toString(10));
125
+ result.byteOffset = attribute.byteOffset.toString(10);
603
126
  }
604
127
  if ("byteStride" in attribute) {
605
- result.set("byteStride", attribute.byteStride.toString(10));
128
+ result.byteStride = attribute.byteStride.toString(10);
606
129
  }
607
130
  if ("normalized" in attribute) {
608
- result.set("normalized", attribute.normalized.toString());
131
+ result.normalized = attribute.normalized.toString();
609
132
  }
610
133
  return result;
611
134
  }
612
135
  var init_deduce_mesh_schema = __esm({
613
- "../schema/src/category/mesh/deduce-mesh-schema.ts"() {
614
- init_schema2();
615
- init_arrow_like_type_utils();
136
+ "../schema/src/lib/mesh/deduce-mesh-schema.ts"() {
137
+ init_data_type();
616
138
  }
617
139
  });
618
140
 
@@ -626,24 +148,24 @@
626
148
 
627
149
  // src/lib/get-ply-schema.ts
628
150
  function getPLYSchema(plyHeader, attributes) {
629
- const metadataMap = makeMetadataFromPlyHeader(plyHeader);
630
- const schema = deduceMeshSchema(attributes, metadataMap);
151
+ const metadata = makeMetadataFromPlyHeader(plyHeader);
152
+ const schema = deduceMeshSchema(attributes, metadata);
631
153
  return schema;
632
154
  }
633
155
  function makeMetadataFromPlyHeader(plyHeader) {
634
- const metadataMap = new Map();
635
- metadataMap.set("ply_comments", JSON.stringify(plyHeader.comments));
636
- metadataMap.set("ply_elements", JSON.stringify(plyHeader.elements));
156
+ const metadata = {};
157
+ metadata.ply_comments = JSON.stringify(plyHeader.comments);
158
+ metadata.ply_elements = JSON.stringify(plyHeader.elements);
637
159
  if (plyHeader.format !== void 0) {
638
- metadataMap.set("ply_format", plyHeader.format);
160
+ metadata.ply_format = plyHeader.format;
639
161
  }
640
162
  if (plyHeader.version !== void 0) {
641
- metadataMap.set("ply_version", plyHeader.version);
163
+ metadata.ply_version = plyHeader.version;
642
164
  }
643
165
  if (plyHeader.headerLength !== void 0) {
644
- metadataMap.set("ply_headerLength", plyHeader.headerLength.toString(10));
166
+ metadata.ply_headerLength = plyHeader.headerLength.toString(10);
645
167
  }
646
- return metadataMap;
168
+ return metadata;
647
169
  }
648
170
  var init_get_ply_schema = __esm({
649
171
  "src/lib/get-ply-schema.ts"() {
@@ -680,15 +202,36 @@
680
202
  }
681
203
  function getMeshAttributes(attributes) {
682
204
  const accessors = {};
683
- accessors.POSITION = { value: new Float32Array(attributes.vertices), size: 3 };
684
- if (attributes.normals.length > 0) {
685
- accessors.NORMAL = { value: new Float32Array(attributes.normals), size: 3 };
686
- }
687
- if (attributes.uvs.length > 0) {
688
- accessors.TEXCOORD_0 = { value: new Float32Array(attributes.uvs), size: 2 };
689
- }
690
- if (attributes.colors.length > 0) {
691
- accessors.COLOR_0 = { value: new Uint8Array(attributes.colors), size: 3, normalized: true };
205
+ for (const attributeName of Object.keys(attributes)) {
206
+ switch (attributeName) {
207
+ case "vertices":
208
+ if (attributes.vertices.length > 0) {
209
+ accessors.POSITION = { value: new Float32Array(attributes.vertices), size: 3 };
210
+ }
211
+ break;
212
+ case "normals":
213
+ if (attributes.normals.length > 0) {
214
+ accessors.NORMAL = { value: new Float32Array(attributes.normals), size: 3 };
215
+ }
216
+ break;
217
+ case "uvs":
218
+ if (attributes.uvs.length > 0) {
219
+ accessors.TEXCOORD_0 = { value: new Float32Array(attributes.uvs), size: 2 };
220
+ }
221
+ break;
222
+ case "colors":
223
+ if (attributes.colors.length > 0) {
224
+ accessors.COLOR_0 = { value: new Uint8Array(attributes.colors), size: 3, normalized: true };
225
+ }
226
+ break;
227
+ case "indices":
228
+ break;
229
+ default:
230
+ if (attributes[attributeName].length > 0) {
231
+ accessors[attributeName] = { value: new Float32Array(attributes[attributeName]), size: 1 };
232
+ }
233
+ break;
234
+ }
692
235
  }
693
236
  return accessors;
694
237
  }
@@ -763,35 +306,72 @@
763
306
  };
764
307
  break;
765
308
  case "property":
766
- if (!currentElement2) {
767
- break;
309
+ if (currentElement2) {
310
+ const property = makePLYElementProperty(lineValues);
311
+ if (options?.propertyNameMapping && property.name in options?.propertyNameMapping) {
312
+ property.name = options?.propertyNameMapping[property.name];
313
+ }
314
+ currentElement2.properties.push(property);
768
315
  }
769
- currentElement2.properties.push(makePLYElementProperty(lineValues, options.propertyNameMapping));
770
316
  break;
771
317
  default:
772
318
  console.log("unhandled", lineType, lineValues);
773
319
  }
774
320
  }
775
- if (currentElement2 !== void 0) {
321
+ if (currentElement2) {
776
322
  header.elements.push(currentElement2);
777
323
  }
778
324
  return header;
779
325
  }
780
- function makePLYElementProperty(propertValues, propertyNameMapping) {
781
- const property = {
782
- type: propertValues[0]
326
+ function getPLYAttributes(header) {
327
+ const attributes = {
328
+ indices: [],
329
+ vertices: [],
330
+ normals: [],
331
+ uvs: [],
332
+ colors: []
783
333
  };
784
- if (property.type === "list") {
785
- property.name = propertValues[3];
786
- property.countType = propertValues[1];
787
- property.itemType = propertValues[2];
788
- } else {
789
- property.name = propertValues[1];
334
+ for (const element of header.elements) {
335
+ if (element.name === "vertex") {
336
+ for (const property of element.properties) {
337
+ switch (property.name) {
338
+ case "x":
339
+ case "y":
340
+ case "z":
341
+ case "nx":
342
+ case "ny":
343
+ case "nz":
344
+ case "s":
345
+ case "t":
346
+ case "red":
347
+ case "green":
348
+ case "blue":
349
+ break;
350
+ default:
351
+ attributes[property.name] = [];
352
+ break;
353
+ }
354
+ }
355
+ }
790
356
  }
791
- if (propertyNameMapping && property.name in propertyNameMapping) {
792
- property.name = propertyNameMapping[property.name];
357
+ return attributes;
358
+ }
359
+ function makePLYElementProperty(propertyValues) {
360
+ const type = propertyValues[0];
361
+ switch (type) {
362
+ case "list":
363
+ return {
364
+ type,
365
+ name: propertyValues[3],
366
+ countType: propertyValues[1],
367
+ itemType: propertyValues[2]
368
+ };
369
+ default:
370
+ return {
371
+ type,
372
+ name: propertyValues[1]
373
+ };
793
374
  }
794
- return property;
795
375
  }
796
376
  function parseASCIINumber(n, type) {
797
377
  switch (type) {
@@ -817,7 +397,7 @@
817
397
  throw new Error(type);
818
398
  }
819
399
  }
820
- function parseASCIIElement(properties, line) {
400
+ function parsePLYElement(properties, line) {
821
401
  const values = line.split(/\s+/);
822
402
  const element = {};
823
403
  for (let i = 0; i < properties.length; i++) {
@@ -835,13 +415,7 @@
835
415
  return element;
836
416
  }
837
417
  function parseASCII(data, header) {
838
- const attributes = {
839
- indices: [],
840
- vertices: [],
841
- normals: [],
842
- uvs: [],
843
- colors: []
844
- };
418
+ const attributes = getPLYAttributes(header);
845
419
  let result;
846
420
  const patternBody = /end_header\s([\s\S]*)$/;
847
421
  let body = "";
@@ -859,7 +433,7 @@
859
433
  currentElement2++;
860
434
  currentElementCount = 0;
861
435
  }
862
- const element = parseASCIIElement(header.elements[currentElement2].properties, line);
436
+ const element = parsePLYElement(header.elements[currentElement2].properties, line);
863
437
  handleElement(attributes, header.elements[currentElement2].name, element);
864
438
  currentElementCount++;
865
439
  }
@@ -868,15 +442,40 @@
868
442
  }
869
443
  function handleElement(buffer, elementName, element = {}) {
870
444
  if (elementName === "vertex") {
871
- buffer.vertices.push(element.x, element.y, element.z);
872
- if ("nx" in element && "ny" in element && "nz" in element) {
873
- buffer.normals.push(element.nx, element.ny, element.nz);
874
- }
875
- if ("s" in element && "t" in element) {
876
- buffer.uvs.push(element.s, element.t);
877
- }
878
- if ("red" in element && "green" in element && "blue" in element) {
879
- buffer.colors.push(element.red, element.green, element.blue);
445
+ for (const propertyName of Object.keys(element)) {
446
+ switch (propertyName) {
447
+ case "x":
448
+ buffer.vertices.push(element.x, element.y, element.z);
449
+ break;
450
+ case "y":
451
+ case "z":
452
+ break;
453
+ case "nx":
454
+ if ("nx" in element && "ny" in element && "nz" in element) {
455
+ buffer.normals.push(element.nx, element.ny, element.nz);
456
+ }
457
+ break;
458
+ case "ny":
459
+ case "nz":
460
+ break;
461
+ case "s":
462
+ if ("s" in element && "t" in element) {
463
+ buffer.uvs.push(element.s, element.t);
464
+ }
465
+ break;
466
+ case "t":
467
+ break;
468
+ case "red":
469
+ if ("red" in element && "green" in element && "blue" in element) {
470
+ buffer.colors.push(element.red, element.green, element.blue);
471
+ }
472
+ break;
473
+ case "green":
474
+ case "blue":
475
+ break;
476
+ default:
477
+ buffer[propertyName].push(element[propertyName]);
478
+ }
880
479
  }
881
480
  } else if (elementName === "face") {
882
481
  const vertexIndices = element.vertex_indices || element.vertex_index;
@@ -943,13 +542,7 @@
943
542
  return [element, read];
944
543
  }
945
544
  function parseBinary(data, header) {
946
- const attributes = {
947
- indices: [],
948
- vertices: [],
949
- normals: [],
950
- uvs: [],
951
- colors: []
952
- };
545
+ const attributes = getPLYAttributes(header);
953
546
  const littleEndian = header.format === "binary_little_endian";
954
547
  const body = new DataView(data, header.headerLength);
955
548
  let result;
@@ -1089,21 +682,22 @@
1089
682
  }
1090
683
  return header;
1091
684
  }
1092
- function makePLYElementProperty2(propertValues, propertyNameMapping) {
1093
- const property = {
1094
- type: propertValues[0]
1095
- };
1096
- if (property.type === "list") {
1097
- property.name = propertValues[3];
1098
- property.countType = propertValues[1];
1099
- property.itemType = propertValues[2];
1100
- } else {
1101
- property.name = propertValues[1];
1102
- }
1103
- if (propertyNameMapping && property.name in propertyNameMapping) {
1104
- property.name = propertyNameMapping[property.name];
685
+ function makePLYElementProperty2(propertyValues, propertyNameMapping) {
686
+ const type = propertyValues[0];
687
+ switch (type) {
688
+ case "list":
689
+ return {
690
+ type,
691
+ name: propertyValues[3],
692
+ countType: propertyValues[1],
693
+ itemType: propertyValues[2]
694
+ };
695
+ default:
696
+ return {
697
+ type,
698
+ name: propertyValues[1]
699
+ };
1105
700
  }
1106
- return property;
1107
701
  }
1108
702
  async function parseASCII2(lineIterator, header) {
1109
703
  const attributes = {
@@ -1122,7 +716,7 @@
1122
716
  currentElement2++;
1123
717
  currentElementCount = 0;
1124
718
  }
1125
- const element = parseASCIIElement2(header.elements[currentElement2].properties, line);
719
+ const element = parsePLYElement2(header.elements[currentElement2].properties, line);
1126
720
  handleElement2(attributes, header.elements[currentElement2].name, element);
1127
721
  currentElementCount++;
1128
722
  }
@@ -1153,7 +747,7 @@
1153
747
  throw new Error(type);
1154
748
  }
1155
749
  }
1156
- function parseASCIIElement2(properties, line) {
750
+ function parsePLYElement2(properties, line) {
1157
751
  const values = line.split(/\s+/);
1158
752
  const element = {};
1159
753
  for (let i = 0; i < properties.length; i++) {
@@ -1209,10 +803,9 @@
1209
803
  var src_exports = {};
1210
804
  __export(src_exports, {
1211
805
  PLYLoader: () => PLYLoader2,
1212
- PLYWorkerLoader: () => PLYLoader,
1213
- _typecheckPLYLoader: () => _typecheckPLYLoader
806
+ PLYWorkerLoader: () => PLYLoader
1214
807
  });
1215
- var PLYLoader2, _typecheckPLYLoader;
808
+ var PLYLoader2;
1216
809
  var init_src3 = __esm({
1217
810
  "src/index.ts"() {
1218
811
  init_ply_loader();
@@ -1220,12 +813,11 @@
1220
813
  init_parse_ply_in_batches();
1221
814
  PLYLoader2 = {
1222
815
  ...PLYLoader,
1223
- parse: async (arrayBuffer, options) => parsePLY(arrayBuffer, options),
1224
- parseTextSync: parsePLY,
1225
- parseSync: parsePLY,
1226
- parseInBatches: parsePLYInBatches
816
+ parse: async (arrayBuffer, options) => parsePLY(arrayBuffer, options?.ply),
817
+ parseTextSync: (arrayBuffer, options) => parsePLY(arrayBuffer, options?.ply),
818
+ parseSync: (arrayBuffer, options) => parsePLY(arrayBuffer, options?.ply),
819
+ parseInBatches: (arrayBuffer, options) => parsePLYInBatches(arrayBuffer, options?.ply)
1227
820
  };
1228
- _typecheckPLYLoader = PLYLoader2;
1229
821
  }
1230
822
  });
1231
823