@loaders.gl/obj 4.0.0-alpha.4 → 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 (89) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +2 -2
  4. package/dist/dist.min.js +744 -0
  5. package/dist/es5/bundle.js +6 -0
  6. package/dist/es5/bundle.js.map +1 -0
  7. package/dist/es5/index.js +74 -0
  8. package/dist/es5/index.js.map +1 -0
  9. package/dist/es5/lib/get-obj-schema.js +54 -0
  10. package/dist/es5/lib/get-obj-schema.js.map +1 -0
  11. package/dist/es5/lib/obj-types.js +2 -0
  12. package/dist/es5/lib/obj-types.js.map +1 -0
  13. package/dist/es5/lib/parse-mtl.js +86 -0
  14. package/dist/es5/lib/parse-mtl.js.map +1 -0
  15. package/dist/es5/lib/parse-obj-meshes.js +486 -0
  16. package/dist/es5/lib/parse-obj-meshes.js.map +1 -0
  17. package/dist/es5/lib/parse-obj.js +100 -0
  18. package/dist/es5/lib/parse-obj.js.map +1 -0
  19. package/dist/es5/mtl-loader.js +26 -0
  20. package/dist/es5/mtl-loader.js.map +1 -0
  21. package/dist/es5/obj-loader.js +27 -0
  22. package/dist/es5/obj-loader.js.map +1 -0
  23. package/dist/es5/workers/obj-worker.js +6 -0
  24. package/dist/es5/workers/obj-worker.js.map +1 -0
  25. package/dist/esm/bundle.js +4 -0
  26. package/dist/esm/bundle.js.map +1 -0
  27. package/dist/esm/index.js +18 -0
  28. package/dist/esm/index.js.map +1 -0
  29. package/dist/esm/lib/get-obj-schema.js +49 -0
  30. package/dist/esm/lib/get-obj-schema.js.map +1 -0
  31. package/dist/esm/lib/obj-types.js +2 -0
  32. package/dist/esm/lib/obj-types.js.map +1 -0
  33. package/dist/esm/lib/parse-mtl.js +68 -0
  34. package/dist/esm/lib/parse-mtl.js.map +1 -0
  35. package/dist/esm/lib/parse-obj-meshes.js +385 -0
  36. package/dist/esm/lib/parse-obj-meshes.js.map +1 -0
  37. package/dist/{lib/load-obj.js → esm/lib/parse-obj.js} +5 -15
  38. package/dist/esm/lib/parse-obj.js.map +1 -0
  39. package/dist/esm/mtl-loader.js +16 -0
  40. package/dist/esm/mtl-loader.js.map +1 -0
  41. package/dist/esm/obj-loader.js +19 -0
  42. package/dist/esm/obj-loader.js.map +1 -0
  43. package/dist/esm/workers/obj-worker.js +4 -0
  44. package/dist/esm/workers/obj-worker.js.map +1 -0
  45. package/dist/index.d.ts +18 -0
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.js +26 -8
  48. package/dist/lib/get-obj-schema.d.ts +4 -0
  49. package/dist/lib/get-obj-schema.d.ts.map +1 -0
  50. package/dist/lib/get-obj-schema.js +33 -33
  51. package/dist/lib/obj-types.d.ts +1 -0
  52. package/dist/lib/obj-types.d.ts.map +1 -0
  53. package/dist/lib/obj-types.js +1 -2
  54. package/dist/lib/parse-mtl.d.ts +34 -0
  55. package/dist/lib/parse-mtl.d.ts.map +1 -0
  56. package/dist/lib/parse-mtl.js +201 -0
  57. package/dist/lib/parse-obj-meshes.d.ts +5 -0
  58. package/dist/lib/parse-obj-meshes.d.ts.map +1 -0
  59. package/dist/lib/parse-obj-meshes.js +440 -0
  60. package/dist/lib/parse-obj.d.ts +3 -0
  61. package/dist/lib/parse-obj.d.ts.map +1 -0
  62. package/dist/lib/parse-obj.js +63 -449
  63. package/dist/mtl-loader.d.ts +12 -0
  64. package/dist/mtl-loader.d.ts.map +1 -0
  65. package/dist/mtl-loader.js +24 -0
  66. package/dist/obj-loader.d.ts +11 -0
  67. package/dist/obj-loader.d.ts.map +1 -0
  68. package/dist/obj-loader.js +24 -18
  69. package/dist/obj-worker.js +213 -507
  70. package/dist/workers/obj-worker.d.ts +2 -0
  71. package/dist/workers/obj-worker.d.ts.map +1 -0
  72. package/dist/workers/obj-worker.js +5 -4
  73. package/package.json +9 -9
  74. package/src/index.ts +25 -4
  75. package/src/lib/get-obj-schema.ts +24 -20
  76. package/src/lib/parse-mtl.ts +246 -0
  77. package/src/lib/parse-obj-meshes.ts +525 -0
  78. package/src/lib/parse-obj.ts +67 -508
  79. package/src/mtl-loader.ts +31 -0
  80. package/src/obj-loader.ts +8 -3
  81. package/dist/bundle.js.map +0 -1
  82. package/dist/index.js.map +0 -1
  83. package/dist/lib/get-obj-schema.js.map +0 -1
  84. package/dist/lib/load-obj.js.map +0 -1
  85. package/dist/lib/obj-types.js.map +0 -1
  86. package/dist/lib/parse-obj.js.map +0 -1
  87. package/dist/obj-loader.js.map +0 -1
  88. package/src/lib/load-obj.ts +0 -83
  89. /package/src/workers/{obj-worker.js → obj-worker.ts} +0 -0
@@ -35,16 +35,33 @@
35
35
  }
36
36
 
37
37
  // ../worker-utils/src/lib/worker-farm/worker-body.ts
38
+ function getParentPort() {
39
+ let parentPort;
40
+ try {
41
+ eval("globalThis.parentPort = require('worker_threads').parentPort");
42
+ parentPort = globalThis.parentPort;
43
+ } catch {
44
+ }
45
+ return parentPort;
46
+ }
38
47
  var onMessageWrapperMap = new Map();
39
48
  var WorkerBody = class {
49
+ static inWorkerThread() {
50
+ return typeof self !== "undefined" || Boolean(getParentPort());
51
+ }
40
52
  static set onmessage(onMessage) {
41
- self.onmessage = (message) => {
42
- if (!isKnownMessage(message)) {
43
- return;
44
- }
45
- const { type, payload } = message.data;
53
+ function handleMessage(message) {
54
+ const parentPort3 = getParentPort();
55
+ const { type, payload } = parentPort3 ? message : message.data;
46
56
  onMessage(type, payload);
47
- };
57
+ }
58
+ const parentPort2 = getParentPort();
59
+ if (parentPort2) {
60
+ parentPort2.on("message", handleMessage);
61
+ parentPort2.on("exit", () => console.debug("Node worker closing"));
62
+ } else {
63
+ globalThis.onmessage = handleMessage;
64
+ }
48
65
  }
49
66
  static addEventListener(onMessage) {
50
67
  let onMessageWrapper = onMessageWrapperMap.get(onMessage);
@@ -53,22 +70,36 @@
53
70
  if (!isKnownMessage(message)) {
54
71
  return;
55
72
  }
56
- const { type, payload } = message.data;
73
+ const parentPort3 = getParentPort();
74
+ const { type, payload } = parentPort3 ? message : message.data;
57
75
  onMessage(type, payload);
58
76
  };
59
77
  }
60
- self.addEventListener("message", onMessageWrapper);
78
+ const parentPort2 = getParentPort();
79
+ if (parentPort2) {
80
+ console.error("not implemented");
81
+ } else {
82
+ globalThis.addEventListener("message", onMessageWrapper);
83
+ }
61
84
  }
62
85
  static removeEventListener(onMessage) {
63
86
  const onMessageWrapper = onMessageWrapperMap.get(onMessage);
64
87
  onMessageWrapperMap.delete(onMessage);
65
- self.removeEventListener("message", onMessageWrapper);
88
+ const parentPort2 = getParentPort();
89
+ if (parentPort2) {
90
+ console.error("not implemented");
91
+ } else {
92
+ globalThis.removeEventListener("message", onMessageWrapper);
93
+ }
66
94
  }
67
95
  static postMessage(type, payload) {
68
- if (self) {
69
- const data = { source: "loaders.gl", type, payload };
70
- const transferList = getTransferList(payload);
71
- self.postMessage(data, transferList);
96
+ const data = { source: "loaders.gl", type, payload };
97
+ const transferList = getTransferList(payload);
98
+ const parentPort2 = getParentPort();
99
+ if (parentPort2) {
100
+ parentPort2.postMessage(data, transferList);
101
+ } else {
102
+ globalThis.postMessage(data, transferList);
72
103
  }
73
104
  }
74
105
  };
@@ -80,19 +111,20 @@
80
111
  // ../loader-utils/src/lib/worker-loader-utils/create-loader-worker.ts
81
112
  var requestId = 0;
82
113
  function createLoaderWorker(loader) {
83
- if (typeof self === "undefined") {
114
+ if (!WorkerBody.inWorkerThread()) {
84
115
  return;
85
116
  }
86
117
  WorkerBody.onmessage = async (type, payload) => {
87
118
  switch (type) {
88
119
  case "process":
89
120
  try {
90
- const { input, options = {} } = payload;
121
+ const { input, options = {}, context = {} } = payload;
91
122
  const result = await parseData({
92
123
  loader,
93
124
  arrayBuffer: input,
94
125
  options,
95
126
  context: {
127
+ ...context,
96
128
  parse: parseOnMainThread
97
129
  }
98
130
  });
@@ -151,7 +183,58 @@
151
183
  return await parser(data, { ...options }, context, loader);
152
184
  }
153
185
 
154
- // ../schema/src/category/mesh/mesh-utils.ts
186
+ // ../schema/src/lib/table/simple-table/data-type.ts
187
+ function getDataTypeFromValue(value, defaultNumberType = "float32") {
188
+ if (value instanceof Date) {
189
+ return "date-millisecond";
190
+ }
191
+ if (value instanceof Number) {
192
+ return defaultNumberType;
193
+ }
194
+ if (typeof value === "string") {
195
+ return "utf8";
196
+ }
197
+ if (value === null || value === "undefined") {
198
+ return "null";
199
+ }
200
+ return "null";
201
+ }
202
+ function getDataTypeFromArray(array) {
203
+ let type = getDataTypeFromTypedArray(array);
204
+ if (type !== "null") {
205
+ return { type, nullable: false };
206
+ }
207
+ if (array.length > 0) {
208
+ type = getDataTypeFromValue(array[0]);
209
+ return { type, nullable: true };
210
+ }
211
+ return { type: "null", nullable: true };
212
+ }
213
+ function getDataTypeFromTypedArray(array) {
214
+ switch (array.constructor) {
215
+ case Int8Array:
216
+ return "int8";
217
+ case Uint8Array:
218
+ case Uint8ClampedArray:
219
+ return "uint8";
220
+ case Int16Array:
221
+ return "int16";
222
+ case Uint16Array:
223
+ return "uint16";
224
+ case Int32Array:
225
+ return "int32";
226
+ case Uint32Array:
227
+ return "uint32";
228
+ case Float32Array:
229
+ return "float32";
230
+ case Float64Array:
231
+ return "float64";
232
+ default:
233
+ return "null";
234
+ }
235
+ }
236
+
237
+ // ../schema/src/lib/mesh/mesh-utils.ts
155
238
  function getMeshBoundingBox(attributes) {
156
239
  let minX = Infinity;
157
240
  let minY = Infinity;
@@ -178,477 +261,7 @@
178
261
  ];
179
262
  }
180
263
 
181
- // ../schema/src/lib/utils/assert.ts
182
- function assert(condition, message) {
183
- if (!condition) {
184
- throw new Error(message || "loader assertion failed.");
185
- }
186
- }
187
-
188
- // ../schema/src/lib/schema/impl/schema.ts
189
- var Schema = class {
190
- constructor(fields, metadata) {
191
- assert(Array.isArray(fields));
192
- checkNames(fields);
193
- this.fields = fields;
194
- this.metadata = metadata || new Map();
195
- }
196
- compareTo(other) {
197
- if (this.metadata !== other.metadata) {
198
- return false;
199
- }
200
- if (this.fields.length !== other.fields.length) {
201
- return false;
202
- }
203
- for (let i = 0; i < this.fields.length; ++i) {
204
- if (!this.fields[i].compareTo(other.fields[i])) {
205
- return false;
206
- }
207
- }
208
- return true;
209
- }
210
- select(...columnNames) {
211
- const nameMap = Object.create(null);
212
- for (const name of columnNames) {
213
- nameMap[name] = true;
214
- }
215
- const selectedFields = this.fields.filter((field) => nameMap[field.name]);
216
- return new Schema(selectedFields, this.metadata);
217
- }
218
- selectAt(...columnIndices) {
219
- const selectedFields = columnIndices.map((index) => this.fields[index]).filter(Boolean);
220
- return new Schema(selectedFields, this.metadata);
221
- }
222
- assign(schemaOrFields) {
223
- let fields;
224
- let metadata = this.metadata;
225
- if (schemaOrFields instanceof Schema) {
226
- const otherSchema = schemaOrFields;
227
- fields = otherSchema.fields;
228
- metadata = mergeMaps(mergeMaps(new Map(), this.metadata), otherSchema.metadata);
229
- } else {
230
- fields = schemaOrFields;
231
- }
232
- const fieldMap = Object.create(null);
233
- for (const field of this.fields) {
234
- fieldMap[field.name] = field;
235
- }
236
- for (const field of fields) {
237
- fieldMap[field.name] = field;
238
- }
239
- const mergedFields = Object.values(fieldMap);
240
- return new Schema(mergedFields, metadata);
241
- }
242
- };
243
- function checkNames(fields) {
244
- const usedNames = {};
245
- for (const field of fields) {
246
- if (usedNames[field.name]) {
247
- console.warn("Schema: duplicated field name", field.name, field);
248
- }
249
- usedNames[field.name] = true;
250
- }
251
- }
252
- function mergeMaps(m1, m2) {
253
- return new Map([...m1 || new Map(), ...m2 || new Map()]);
254
- }
255
-
256
- // ../schema/src/lib/schema/impl/field.ts
257
- var Field = class {
258
- constructor(name, type, nullable = false, metadata = new Map()) {
259
- this.name = name;
260
- this.type = type;
261
- this.nullable = nullable;
262
- this.metadata = metadata;
263
- }
264
- get typeId() {
265
- return this.type && this.type.typeId;
266
- }
267
- clone() {
268
- return new Field(this.name, this.type, this.nullable, this.metadata);
269
- }
270
- compareTo(other) {
271
- return this.name === other.name && this.type === other.type && this.nullable === other.nullable && this.metadata === other.metadata;
272
- }
273
- toString() {
274
- return `${this.type}${this.nullable ? ", nullable" : ""}${this.metadata ? `, metadata: ${this.metadata}` : ""}`;
275
- }
276
- };
277
-
278
- // ../schema/src/lib/schema/impl/enum.ts
279
- var Type;
280
- (function(Type2) {
281
- Type2[Type2["NONE"] = 0] = "NONE";
282
- Type2[Type2["Null"] = 1] = "Null";
283
- Type2[Type2["Int"] = 2] = "Int";
284
- Type2[Type2["Float"] = 3] = "Float";
285
- Type2[Type2["Binary"] = 4] = "Binary";
286
- Type2[Type2["Utf8"] = 5] = "Utf8";
287
- Type2[Type2["Bool"] = 6] = "Bool";
288
- Type2[Type2["Decimal"] = 7] = "Decimal";
289
- Type2[Type2["Date"] = 8] = "Date";
290
- Type2[Type2["Time"] = 9] = "Time";
291
- Type2[Type2["Timestamp"] = 10] = "Timestamp";
292
- Type2[Type2["Interval"] = 11] = "Interval";
293
- Type2[Type2["List"] = 12] = "List";
294
- Type2[Type2["Struct"] = 13] = "Struct";
295
- Type2[Type2["Union"] = 14] = "Union";
296
- Type2[Type2["FixedSizeBinary"] = 15] = "FixedSizeBinary";
297
- Type2[Type2["FixedSizeList"] = 16] = "FixedSizeList";
298
- Type2[Type2["Map"] = 17] = "Map";
299
- Type2[Type2["Dictionary"] = -1] = "Dictionary";
300
- Type2[Type2["Int8"] = -2] = "Int8";
301
- Type2[Type2["Int16"] = -3] = "Int16";
302
- Type2[Type2["Int32"] = -4] = "Int32";
303
- Type2[Type2["Int64"] = -5] = "Int64";
304
- Type2[Type2["Uint8"] = -6] = "Uint8";
305
- Type2[Type2["Uint16"] = -7] = "Uint16";
306
- Type2[Type2["Uint32"] = -8] = "Uint32";
307
- Type2[Type2["Uint64"] = -9] = "Uint64";
308
- Type2[Type2["Float16"] = -10] = "Float16";
309
- Type2[Type2["Float32"] = -11] = "Float32";
310
- Type2[Type2["Float64"] = -12] = "Float64";
311
- Type2[Type2["DateDay"] = -13] = "DateDay";
312
- Type2[Type2["DateMillisecond"] = -14] = "DateMillisecond";
313
- Type2[Type2["TimestampSecond"] = -15] = "TimestampSecond";
314
- Type2[Type2["TimestampMillisecond"] = -16] = "TimestampMillisecond";
315
- Type2[Type2["TimestampMicrosecond"] = -17] = "TimestampMicrosecond";
316
- Type2[Type2["TimestampNanosecond"] = -18] = "TimestampNanosecond";
317
- Type2[Type2["TimeSecond"] = -19] = "TimeSecond";
318
- Type2[Type2["TimeMillisecond"] = -20] = "TimeMillisecond";
319
- Type2[Type2["TimeMicrosecond"] = -21] = "TimeMicrosecond";
320
- Type2[Type2["TimeNanosecond"] = -22] = "TimeNanosecond";
321
- Type2[Type2["DenseUnion"] = -23] = "DenseUnion";
322
- Type2[Type2["SparseUnion"] = -24] = "SparseUnion";
323
- Type2[Type2["IntervalDayTime"] = -25] = "IntervalDayTime";
324
- Type2[Type2["IntervalYearMonth"] = -26] = "IntervalYearMonth";
325
- })(Type || (Type = {}));
326
-
327
- // ../schema/src/lib/schema/impl/type.ts
328
- var DataType = class {
329
- static isNull(x) {
330
- return x && x.typeId === Type.Null;
331
- }
332
- static isInt(x) {
333
- return x && x.typeId === Type.Int;
334
- }
335
- static isFloat(x) {
336
- return x && x.typeId === Type.Float;
337
- }
338
- static isBinary(x) {
339
- return x && x.typeId === Type.Binary;
340
- }
341
- static isUtf8(x) {
342
- return x && x.typeId === Type.Utf8;
343
- }
344
- static isBool(x) {
345
- return x && x.typeId === Type.Bool;
346
- }
347
- static isDecimal(x) {
348
- return x && x.typeId === Type.Decimal;
349
- }
350
- static isDate(x) {
351
- return x && x.typeId === Type.Date;
352
- }
353
- static isTime(x) {
354
- return x && x.typeId === Type.Time;
355
- }
356
- static isTimestamp(x) {
357
- return x && x.typeId === Type.Timestamp;
358
- }
359
- static isInterval(x) {
360
- return x && x.typeId === Type.Interval;
361
- }
362
- static isList(x) {
363
- return x && x.typeId === Type.List;
364
- }
365
- static isStruct(x) {
366
- return x && x.typeId === Type.Struct;
367
- }
368
- static isUnion(x) {
369
- return x && x.typeId === Type.Union;
370
- }
371
- static isFixedSizeBinary(x) {
372
- return x && x.typeId === Type.FixedSizeBinary;
373
- }
374
- static isFixedSizeList(x) {
375
- return x && x.typeId === Type.FixedSizeList;
376
- }
377
- static isMap(x) {
378
- return x && x.typeId === Type.Map;
379
- }
380
- static isDictionary(x) {
381
- return x && x.typeId === Type.Dictionary;
382
- }
383
- get typeId() {
384
- return Type.NONE;
385
- }
386
- compareTo(other) {
387
- return this === other;
388
- }
389
- };
390
- var Null = class extends DataType {
391
- get typeId() {
392
- return Type.Null;
393
- }
394
- get [Symbol.toStringTag]() {
395
- return "Null";
396
- }
397
- toString() {
398
- return "Null";
399
- }
400
- };
401
- var Bool = class extends DataType {
402
- get typeId() {
403
- return Type.Bool;
404
- }
405
- get [Symbol.toStringTag]() {
406
- return "Bool";
407
- }
408
- toString() {
409
- return "Bool";
410
- }
411
- };
412
- var Int = class extends DataType {
413
- constructor(isSigned, bitWidth) {
414
- super();
415
- this.isSigned = isSigned;
416
- this.bitWidth = bitWidth;
417
- }
418
- get typeId() {
419
- return Type.Int;
420
- }
421
- get [Symbol.toStringTag]() {
422
- return "Int";
423
- }
424
- toString() {
425
- return `${this.isSigned ? "I" : "Ui"}nt${this.bitWidth}`;
426
- }
427
- };
428
- var Int8 = class extends Int {
429
- constructor() {
430
- super(true, 8);
431
- }
432
- };
433
- var Int16 = class extends Int {
434
- constructor() {
435
- super(true, 16);
436
- }
437
- };
438
- var Int32 = class extends Int {
439
- constructor() {
440
- super(true, 32);
441
- }
442
- };
443
- var Uint8 = class extends Int {
444
- constructor() {
445
- super(false, 8);
446
- }
447
- };
448
- var Uint16 = class extends Int {
449
- constructor() {
450
- super(false, 16);
451
- }
452
- };
453
- var Uint32 = class extends Int {
454
- constructor() {
455
- super(false, 32);
456
- }
457
- };
458
- var Precision = {
459
- HALF: 16,
460
- SINGLE: 32,
461
- DOUBLE: 64
462
- };
463
- var Float = class extends DataType {
464
- constructor(precision) {
465
- super();
466
- this.precision = precision;
467
- }
468
- get typeId() {
469
- return Type.Float;
470
- }
471
- get [Symbol.toStringTag]() {
472
- return "Float";
473
- }
474
- toString() {
475
- return `Float${this.precision}`;
476
- }
477
- };
478
- var Float32 = class extends Float {
479
- constructor() {
480
- super(Precision.SINGLE);
481
- }
482
- };
483
- var Float64 = class extends Float {
484
- constructor() {
485
- super(Precision.DOUBLE);
486
- }
487
- };
488
- var Binary = class extends DataType {
489
- constructor() {
490
- super();
491
- }
492
- get typeId() {
493
- return Type.Binary;
494
- }
495
- toString() {
496
- return "Binary";
497
- }
498
- get [Symbol.toStringTag]() {
499
- return "Binary";
500
- }
501
- };
502
- var Utf8 = class extends DataType {
503
- get typeId() {
504
- return Type.Utf8;
505
- }
506
- get [Symbol.toStringTag]() {
507
- return "Utf8";
508
- }
509
- toString() {
510
- return "Utf8";
511
- }
512
- };
513
- var DateUnit = {
514
- DAY: 0,
515
- MILLISECOND: 1
516
- };
517
- var Date = class extends DataType {
518
- constructor(unit) {
519
- super();
520
- this.unit = unit;
521
- }
522
- get typeId() {
523
- return Type.Date;
524
- }
525
- get [Symbol.toStringTag]() {
526
- return "Date";
527
- }
528
- toString() {
529
- return `Date${(this.unit + 1) * 32}<${DateUnit[this.unit]}>`;
530
- }
531
- };
532
- var TimeUnit = {
533
- SECOND: 1,
534
- MILLISECOND: 1e3,
535
- MICROSECOND: 1e6,
536
- NANOSECOND: 1e9
537
- };
538
- var Time = class extends DataType {
539
- constructor(unit, bitWidth) {
540
- super();
541
- this.unit = unit;
542
- this.bitWidth = bitWidth;
543
- }
544
- get typeId() {
545
- return Type.Time;
546
- }
547
- toString() {
548
- return `Time${this.bitWidth}<${TimeUnit[this.unit]}>`;
549
- }
550
- get [Symbol.toStringTag]() {
551
- return "Time";
552
- }
553
- };
554
- var Timestamp = class extends DataType {
555
- constructor(unit, timezone = null) {
556
- super();
557
- this.unit = unit;
558
- this.timezone = timezone;
559
- }
560
- get typeId() {
561
- return Type.Timestamp;
562
- }
563
- get [Symbol.toStringTag]() {
564
- return "Timestamp";
565
- }
566
- toString() {
567
- return `Timestamp<${TimeUnit[this.unit]}${this.timezone ? `, ${this.timezone}` : ""}>`;
568
- }
569
- };
570
- var IntervalUnit = {
571
- DAY_TIME: 0,
572
- YEAR_MONTH: 1
573
- };
574
- var Interval = class extends DataType {
575
- constructor(unit) {
576
- super();
577
- this.unit = unit;
578
- }
579
- get typeId() {
580
- return Type.Interval;
581
- }
582
- get [Symbol.toStringTag]() {
583
- return "Interval";
584
- }
585
- toString() {
586
- return `Interval<${IntervalUnit[this.unit]}>`;
587
- }
588
- };
589
- var FixedSizeList = class extends DataType {
590
- constructor(listSize, child) {
591
- super();
592
- this.listSize = listSize;
593
- this.children = [child];
594
- }
595
- get typeId() {
596
- return Type.FixedSizeList;
597
- }
598
- get valueType() {
599
- return this.children[0].type;
600
- }
601
- get valueField() {
602
- return this.children[0];
603
- }
604
- get [Symbol.toStringTag]() {
605
- return "FixedSizeList";
606
- }
607
- toString() {
608
- return `FixedSizeList[${this.listSize}]<${this.valueType}>`;
609
- }
610
- };
611
- var Struct = class extends DataType {
612
- constructor(children) {
613
- super();
614
- this.children = children;
615
- }
616
- get typeId() {
617
- return Type.Struct;
618
- }
619
- toString() {
620
- return `Struct<{${this.children.map((f) => `${f.name}:${f.type}`).join(", ")}}>`;
621
- }
622
- get [Symbol.toStringTag]() {
623
- return "Struct";
624
- }
625
- };
626
-
627
- // ../schema/src/lib/arrow/arrow-like-type-utils.ts
628
- function getArrowTypeFromTypedArray(array) {
629
- switch (array.constructor) {
630
- case Int8Array:
631
- return new Int8();
632
- case Uint8Array:
633
- return new Uint8();
634
- case Int16Array:
635
- return new Int16();
636
- case Uint16Array:
637
- return new Uint16();
638
- case Int32Array:
639
- return new Int32();
640
- case Uint32Array:
641
- return new Uint32();
642
- case Float32Array:
643
- return new Float32();
644
- case Float64Array:
645
- return new Float64();
646
- default:
647
- throw new Error("array type not supported");
648
- }
649
- }
650
-
651
- // src/lib/parse-obj.ts
264
+ // src/lib/parse-obj-meshes.ts
652
265
  var OBJECT_RE = /^[og]\s*(.+)?/;
653
266
  var MATERIAL_RE = /^mtllib /;
654
267
  var MATERIAL_USE_RE = /^usemtl /;
@@ -863,7 +476,7 @@
863
476
  }
864
477
  }
865
478
  };
866
- var parse_obj_default = (text) => {
479
+ function parseOBJMeshes(text) {
867
480
  const state = new ParserState();
868
481
  if (text.indexOf("\r\n") !== -1) {
869
482
  text = text.replace(/\r\n/g, "\n");
@@ -1012,40 +625,42 @@
1012
625
  meshes.push(mesh);
1013
626
  }
1014
627
  return { meshes, materials };
1015
- };
628
+ }
1016
629
 
1017
630
  // src/lib/get-obj-schema.ts
1018
631
  function getOBJSchema(attributes, metadata = {}) {
1019
- let metadataMap;
632
+ const stringMetadata = {};
1020
633
  for (const key in metadata) {
1021
- metadataMap = metadataMap || new Map();
1022
634
  if (key !== "value") {
1023
- metadataMap.set(key, JSON.stringify(metadata[key]));
635
+ stringMetadata[key] = JSON.stringify(metadata[key]);
1024
636
  }
1025
637
  }
1026
638
  const fields = [];
1027
639
  for (const attributeName in attributes) {
1028
640
  const attribute = attributes[attributeName];
1029
- const field = getArrowFieldFromAttribute(attributeName, attribute);
641
+ const field = getFieldFromAttribute(attributeName, attribute);
1030
642
  fields.push(field);
1031
643
  }
1032
- return new Schema(fields, metadataMap);
644
+ return { fields, metadata: stringMetadata };
1033
645
  }
1034
- function getArrowFieldFromAttribute(attributeName, attribute) {
1035
- const metadataMap = new Map();
646
+ function getFieldFromAttribute(name, attribute) {
647
+ const metadata = {};
1036
648
  for (const key in attribute) {
1037
649
  if (key !== "value") {
1038
- metadataMap.set(key, JSON.stringify(attribute[key]));
650
+ metadata[key] = JSON.stringify(attribute[key]);
1039
651
  }
1040
652
  }
1041
- const type = getArrowTypeFromTypedArray(attribute.value);
1042
- const isSingleValue = !("size" in attribute) || attribute.size === 1;
1043
- return isSingleValue ? new Field(attributeName, type, false, metadataMap) : new Field(attributeName, new FixedSizeList(attribute.size, new Field("value", type)), false, metadataMap);
653
+ let { type } = getDataTypeFromArray(attribute.value);
654
+ const isSingleValue = attribute.size === 1 || attribute.size === void 0;
655
+ if (!isSingleValue) {
656
+ type = { type: "fixed-size-list", listSize: attribute.size, children: [{ name: "values", type }] };
657
+ }
658
+ return { name, type, nullable: false, metadata };
1044
659
  }
1045
660
 
1046
- // src/lib/load-obj.ts
1047
- function loadOBJ(text, options) {
1048
- const { meshes } = parse_obj_default(text);
661
+ // src/lib/parse-obj.ts
662
+ function parseOBJ(text, options) {
663
+ const { meshes } = parseOBJMeshes(text);
1049
664
  const vertexCount = meshes.reduce((s, mesh) => s + mesh.header.vertexCount, 0);
1050
665
  const attributes = mergeAttributes(meshes, vertexCount);
1051
666
  const header = {
@@ -1063,6 +678,7 @@
1063
678
  schema,
1064
679
  header,
1065
680
  mode: 4,
681
+ topology: "point-list",
1066
682
  attributes
1067
683
  };
1068
684
  }
@@ -1104,7 +720,7 @@
1104
720
  }
1105
721
 
1106
722
  // src/obj-loader.ts
1107
- var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
723
+ var VERSION = true ? "4.0.0-alpha.6" : "latest";
1108
724
  var OBJLoader = {
1109
725
  name: "OBJ",
1110
726
  id: "obj",
@@ -1122,13 +738,103 @@
1122
738
  return text[0] === "v";
1123
739
  }
1124
740
 
741
+ // src/lib/parse-mtl.ts
742
+ var DELIMITER_PATTERN = /\s+/;
743
+ function parseMTL(text, options) {
744
+ const materials = [];
745
+ let currentMaterial = { name: "placeholder" };
746
+ const lines = text.split("\n");
747
+ for (let line of lines) {
748
+ line = line.trim();
749
+ if (line.length === 0 || line.charAt(0) === "#") {
750
+ continue;
751
+ }
752
+ const pos = line.indexOf(" ");
753
+ let key = pos >= 0 ? line.substring(0, pos) : line;
754
+ key = key.toLowerCase();
755
+ let value = pos >= 0 ? line.substring(pos + 1) : "";
756
+ value = value.trim();
757
+ switch (key) {
758
+ case "newmtl":
759
+ currentMaterial = { name: value };
760
+ materials.push(currentMaterial);
761
+ break;
762
+ case "ka":
763
+ currentMaterial.ambientColor = parseColor(value);
764
+ break;
765
+ case "kd":
766
+ currentMaterial.diffuseColor = parseColor(value);
767
+ break;
768
+ case "map_kd":
769
+ currentMaterial.diffuseTextureUrl = value;
770
+ break;
771
+ case "ks":
772
+ currentMaterial.specularColor = parseColor(value);
773
+ break;
774
+ case "map_ks":
775
+ currentMaterial.specularTextureUrl = value;
776
+ break;
777
+ case "ke":
778
+ currentMaterial.emissiveColor = parseColor(value);
779
+ break;
780
+ case "map_ke":
781
+ currentMaterial.emissiveTextureUrl = value;
782
+ break;
783
+ case "ns":
784
+ currentMaterial.shininess = parseFloat(value);
785
+ break;
786
+ case "map_ns":
787
+ break;
788
+ case "ni":
789
+ currentMaterial.refraction = parseFloat(value);
790
+ break;
791
+ case "illum":
792
+ currentMaterial.illumination = parseFloat(value);
793
+ break;
794
+ default:
795
+ break;
796
+ }
797
+ }
798
+ return materials;
799
+ }
800
+ function parseColor(value, options) {
801
+ const rgb = value.split(DELIMITER_PATTERN, 3);
802
+ const color = [
803
+ parseFloat(rgb[0]),
804
+ parseFloat(rgb[1]),
805
+ parseFloat(rgb[2])
806
+ ];
807
+ return color;
808
+ }
809
+
810
+ // src/mtl-loader.ts
811
+ var VERSION2 = true ? "4.0.0-alpha.6" : "latest";
812
+ var MTLLoader = {
813
+ name: "MTL",
814
+ id: "mtl",
815
+ module: "mtl",
816
+ version: VERSION2,
817
+ worker: true,
818
+ extensions: ["mtl"],
819
+ mimeTypes: ["text/plain"],
820
+ testText: (text) => text.includes("newmtl"),
821
+ options: {
822
+ mtl: {}
823
+ }
824
+ };
825
+
1125
826
  // src/index.ts
1126
827
  var OBJLoader2 = {
1127
828
  ...OBJLoader,
1128
- parse: async (arrayBuffer, options) => loadOBJ(new TextDecoder().decode(arrayBuffer), options),
1129
- parseTextSync: loadOBJ
829
+ parse: async (arrayBuffer, options) => parseOBJ(new TextDecoder().decode(arrayBuffer), options),
830
+ parseTextSync: (text, options) => parseOBJ(text, options)
831
+ };
832
+ var MTLLoader2 = {
833
+ ...MTLLoader,
834
+ parse: async (arrayBuffer, options) => parseMTL(new TextDecoder().decode(arrayBuffer), options?.mtl),
835
+ parseTextSync: (text, options) => parseMTL(text, options?.mtl)
1130
836
  };
1131
837
 
1132
- // src/workers/obj-worker.js
838
+ // src/workers/obj-worker.ts
1133
839
  createLoaderWorker(OBJLoader2);
1134
840
  })();