@loaders.gl/obj 4.0.0-alpha.4 → 4.0.0-alpha.5
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.
- package/dist/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/dist.min.js +1196 -0
- package/dist/index.d.ts +72 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/get-obj-schema.d.ts +3 -0
- package/dist/lib/get-obj-schema.d.ts.map +1 -0
- package/dist/lib/obj-types.d.ts +1 -0
- package/dist/lib/obj-types.d.ts.map +1 -0
- package/dist/lib/parse-mtl.d.ts +34 -0
- package/dist/lib/parse-mtl.d.ts.map +1 -0
- package/dist/lib/parse-mtl.js +86 -0
- package/dist/lib/parse-mtl.js.map +1 -0
- package/dist/lib/parse-obj-meshes.d.ts +5 -0
- package/dist/lib/parse-obj-meshes.d.ts.map +1 -0
- package/dist/lib/parse-obj-meshes.js +458 -0
- package/dist/lib/parse-obj-meshes.js.map +1 -0
- package/dist/lib/parse-obj.d.ts +14 -0
- package/dist/lib/parse-obj.d.ts.map +1 -0
- package/dist/lib/parse-obj.js +71 -437
- package/dist/lib/parse-obj.js.map +1 -1
- package/dist/mtl-loader.d.ts +24 -0
- package/dist/mtl-loader.d.ts.map +1 -0
- package/dist/mtl-loader.js +16 -0
- package/dist/mtl-loader.js.map +1 -0
- package/dist/obj-loader.d.ts +24 -0
- package/dist/obj-loader.d.ts.map +1 -0
- package/dist/obj-loader.js +1 -1
- package/dist/obj-loader.js.map +1 -1
- package/dist/obj-worker.js +100 -10
- package/dist/workers/obj-worker.d.ts +2 -0
- package/dist/workers/obj-worker.d.ts.map +1 -0
- package/dist/workers/obj-worker.js +3 -3
- package/dist/workers/obj-worker.js.map +1 -0
- package/package.json +7 -7
- package/src/index.ts +21 -3
- package/src/lib/parse-mtl.ts +246 -0
- package/src/lib/parse-obj-meshes.ts +525 -0
- package/src/lib/parse-obj.ts +66 -508
- package/src/mtl-loader.ts +31 -0
- package/src/obj-loader.ts +6 -2
- package/src/workers/{obj-worker.js → obj-worker.ts} +0 -0
- package/dist/lib/load-obj.js +0 -92
- package/dist/lib/load-obj.js.map +0 -1
- package/src/lib/load-obj.ts +0 -83
package/dist/dist.min.js
ADDED
|
@@ -0,0 +1,1196 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
4
|
+
var __esm = (fn, res) => function __init() {
|
|
5
|
+
return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
|
|
6
|
+
};
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
__markAsModule(target);
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// ../schema/src/category/mesh/mesh-utils.ts
|
|
17
|
+
function getMeshBoundingBox(attributes) {
|
|
18
|
+
let minX = Infinity;
|
|
19
|
+
let minY = Infinity;
|
|
20
|
+
let minZ = Infinity;
|
|
21
|
+
let maxX = -Infinity;
|
|
22
|
+
let maxY = -Infinity;
|
|
23
|
+
let maxZ = -Infinity;
|
|
24
|
+
const positions = attributes.POSITION ? attributes.POSITION.value : [];
|
|
25
|
+
const len = positions && positions.length;
|
|
26
|
+
for (let i = 0; i < len; i += 3) {
|
|
27
|
+
const x = positions[i];
|
|
28
|
+
const y = positions[i + 1];
|
|
29
|
+
const z = positions[i + 2];
|
|
30
|
+
minX = x < minX ? x : minX;
|
|
31
|
+
minY = y < minY ? y : minY;
|
|
32
|
+
minZ = z < minZ ? z : minZ;
|
|
33
|
+
maxX = x > maxX ? x : maxX;
|
|
34
|
+
maxY = y > maxY ? y : maxY;
|
|
35
|
+
maxZ = z > maxZ ? z : maxZ;
|
|
36
|
+
}
|
|
37
|
+
return [
|
|
38
|
+
[minX, minY, minZ],
|
|
39
|
+
[maxX, maxY, maxZ]
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
var init_mesh_utils = __esm({
|
|
43
|
+
"../schema/src/category/mesh/mesh-utils.ts"() {
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// ../schema/src/lib/utils/assert.ts
|
|
48
|
+
function assert(condition, message) {
|
|
49
|
+
if (!condition) {
|
|
50
|
+
throw new Error(message || "loader assertion failed.");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
var init_assert = __esm({
|
|
54
|
+
"../schema/src/lib/utils/assert.ts"() {
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// ../schema/src/lib/schema/impl/schema.ts
|
|
59
|
+
function checkNames(fields) {
|
|
60
|
+
const usedNames = {};
|
|
61
|
+
for (const field of fields) {
|
|
62
|
+
if (usedNames[field.name]) {
|
|
63
|
+
console.warn("Schema: duplicated field name", field.name, field);
|
|
64
|
+
}
|
|
65
|
+
usedNames[field.name] = true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function mergeMaps(m1, m2) {
|
|
69
|
+
return new Map([...m1 || new Map(), ...m2 || new Map()]);
|
|
70
|
+
}
|
|
71
|
+
var Schema;
|
|
72
|
+
var init_schema = __esm({
|
|
73
|
+
"../schema/src/lib/schema/impl/schema.ts"() {
|
|
74
|
+
init_assert();
|
|
75
|
+
Schema = class {
|
|
76
|
+
constructor(fields, metadata) {
|
|
77
|
+
assert(Array.isArray(fields));
|
|
78
|
+
checkNames(fields);
|
|
79
|
+
this.fields = fields;
|
|
80
|
+
this.metadata = metadata || new Map();
|
|
81
|
+
}
|
|
82
|
+
compareTo(other) {
|
|
83
|
+
if (this.metadata !== other.metadata) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
if (this.fields.length !== other.fields.length) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
for (let i = 0; i < this.fields.length; ++i) {
|
|
90
|
+
if (!this.fields[i].compareTo(other.fields[i])) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
select(...columnNames) {
|
|
97
|
+
const nameMap = Object.create(null);
|
|
98
|
+
for (const name of columnNames) {
|
|
99
|
+
nameMap[name] = true;
|
|
100
|
+
}
|
|
101
|
+
const selectedFields = this.fields.filter((field) => nameMap[field.name]);
|
|
102
|
+
return new Schema(selectedFields, this.metadata);
|
|
103
|
+
}
|
|
104
|
+
selectAt(...columnIndices) {
|
|
105
|
+
const selectedFields = columnIndices.map((index) => this.fields[index]).filter(Boolean);
|
|
106
|
+
return new Schema(selectedFields, this.metadata);
|
|
107
|
+
}
|
|
108
|
+
assign(schemaOrFields) {
|
|
109
|
+
let fields;
|
|
110
|
+
let metadata = this.metadata;
|
|
111
|
+
if (schemaOrFields instanceof Schema) {
|
|
112
|
+
const otherSchema = schemaOrFields;
|
|
113
|
+
fields = otherSchema.fields;
|
|
114
|
+
metadata = mergeMaps(mergeMaps(new Map(), this.metadata), otherSchema.metadata);
|
|
115
|
+
} else {
|
|
116
|
+
fields = schemaOrFields;
|
|
117
|
+
}
|
|
118
|
+
const fieldMap = Object.create(null);
|
|
119
|
+
for (const field of this.fields) {
|
|
120
|
+
fieldMap[field.name] = field;
|
|
121
|
+
}
|
|
122
|
+
for (const field of fields) {
|
|
123
|
+
fieldMap[field.name] = field;
|
|
124
|
+
}
|
|
125
|
+
const mergedFields = Object.values(fieldMap);
|
|
126
|
+
return new Schema(mergedFields, metadata);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// ../schema/src/lib/schema/impl/field.ts
|
|
133
|
+
var Field;
|
|
134
|
+
var init_field = __esm({
|
|
135
|
+
"../schema/src/lib/schema/impl/field.ts"() {
|
|
136
|
+
Field = class {
|
|
137
|
+
constructor(name, type, nullable = false, metadata = new Map()) {
|
|
138
|
+
this.name = name;
|
|
139
|
+
this.type = type;
|
|
140
|
+
this.nullable = nullable;
|
|
141
|
+
this.metadata = metadata;
|
|
142
|
+
}
|
|
143
|
+
get typeId() {
|
|
144
|
+
return this.type && this.type.typeId;
|
|
145
|
+
}
|
|
146
|
+
clone() {
|
|
147
|
+
return new Field(this.name, this.type, this.nullable, this.metadata);
|
|
148
|
+
}
|
|
149
|
+
compareTo(other) {
|
|
150
|
+
return this.name === other.name && this.type === other.type && this.nullable === other.nullable && this.metadata === other.metadata;
|
|
151
|
+
}
|
|
152
|
+
toString() {
|
|
153
|
+
return `${this.type}${this.nullable ? ", nullable" : ""}${this.metadata ? `, metadata: ${this.metadata}` : ""}`;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// ../schema/src/lib/schema/impl/enum.ts
|
|
160
|
+
var Type;
|
|
161
|
+
var init_enum = __esm({
|
|
162
|
+
"../schema/src/lib/schema/impl/enum.ts"() {
|
|
163
|
+
(function(Type2) {
|
|
164
|
+
Type2[Type2["NONE"] = 0] = "NONE";
|
|
165
|
+
Type2[Type2["Null"] = 1] = "Null";
|
|
166
|
+
Type2[Type2["Int"] = 2] = "Int";
|
|
167
|
+
Type2[Type2["Float"] = 3] = "Float";
|
|
168
|
+
Type2[Type2["Binary"] = 4] = "Binary";
|
|
169
|
+
Type2[Type2["Utf8"] = 5] = "Utf8";
|
|
170
|
+
Type2[Type2["Bool"] = 6] = "Bool";
|
|
171
|
+
Type2[Type2["Decimal"] = 7] = "Decimal";
|
|
172
|
+
Type2[Type2["Date"] = 8] = "Date";
|
|
173
|
+
Type2[Type2["Time"] = 9] = "Time";
|
|
174
|
+
Type2[Type2["Timestamp"] = 10] = "Timestamp";
|
|
175
|
+
Type2[Type2["Interval"] = 11] = "Interval";
|
|
176
|
+
Type2[Type2["List"] = 12] = "List";
|
|
177
|
+
Type2[Type2["Struct"] = 13] = "Struct";
|
|
178
|
+
Type2[Type2["Union"] = 14] = "Union";
|
|
179
|
+
Type2[Type2["FixedSizeBinary"] = 15] = "FixedSizeBinary";
|
|
180
|
+
Type2[Type2["FixedSizeList"] = 16] = "FixedSizeList";
|
|
181
|
+
Type2[Type2["Map"] = 17] = "Map";
|
|
182
|
+
Type2[Type2["Dictionary"] = -1] = "Dictionary";
|
|
183
|
+
Type2[Type2["Int8"] = -2] = "Int8";
|
|
184
|
+
Type2[Type2["Int16"] = -3] = "Int16";
|
|
185
|
+
Type2[Type2["Int32"] = -4] = "Int32";
|
|
186
|
+
Type2[Type2["Int64"] = -5] = "Int64";
|
|
187
|
+
Type2[Type2["Uint8"] = -6] = "Uint8";
|
|
188
|
+
Type2[Type2["Uint16"] = -7] = "Uint16";
|
|
189
|
+
Type2[Type2["Uint32"] = -8] = "Uint32";
|
|
190
|
+
Type2[Type2["Uint64"] = -9] = "Uint64";
|
|
191
|
+
Type2[Type2["Float16"] = -10] = "Float16";
|
|
192
|
+
Type2[Type2["Float32"] = -11] = "Float32";
|
|
193
|
+
Type2[Type2["Float64"] = -12] = "Float64";
|
|
194
|
+
Type2[Type2["DateDay"] = -13] = "DateDay";
|
|
195
|
+
Type2[Type2["DateMillisecond"] = -14] = "DateMillisecond";
|
|
196
|
+
Type2[Type2["TimestampSecond"] = -15] = "TimestampSecond";
|
|
197
|
+
Type2[Type2["TimestampMillisecond"] = -16] = "TimestampMillisecond";
|
|
198
|
+
Type2[Type2["TimestampMicrosecond"] = -17] = "TimestampMicrosecond";
|
|
199
|
+
Type2[Type2["TimestampNanosecond"] = -18] = "TimestampNanosecond";
|
|
200
|
+
Type2[Type2["TimeSecond"] = -19] = "TimeSecond";
|
|
201
|
+
Type2[Type2["TimeMillisecond"] = -20] = "TimeMillisecond";
|
|
202
|
+
Type2[Type2["TimeMicrosecond"] = -21] = "TimeMicrosecond";
|
|
203
|
+
Type2[Type2["TimeNanosecond"] = -22] = "TimeNanosecond";
|
|
204
|
+
Type2[Type2["DenseUnion"] = -23] = "DenseUnion";
|
|
205
|
+
Type2[Type2["SparseUnion"] = -24] = "SparseUnion";
|
|
206
|
+
Type2[Type2["IntervalDayTime"] = -25] = "IntervalDayTime";
|
|
207
|
+
Type2[Type2["IntervalYearMonth"] = -26] = "IntervalYearMonth";
|
|
208
|
+
})(Type || (Type = {}));
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
// ../schema/src/lib/schema/impl/type.ts
|
|
213
|
+
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;
|
|
214
|
+
var init_type = __esm({
|
|
215
|
+
"../schema/src/lib/schema/impl/type.ts"() {
|
|
216
|
+
init_enum();
|
|
217
|
+
DataType = class {
|
|
218
|
+
static isNull(x) {
|
|
219
|
+
return x && x.typeId === Type.Null;
|
|
220
|
+
}
|
|
221
|
+
static isInt(x) {
|
|
222
|
+
return x && x.typeId === Type.Int;
|
|
223
|
+
}
|
|
224
|
+
static isFloat(x) {
|
|
225
|
+
return x && x.typeId === Type.Float;
|
|
226
|
+
}
|
|
227
|
+
static isBinary(x) {
|
|
228
|
+
return x && x.typeId === Type.Binary;
|
|
229
|
+
}
|
|
230
|
+
static isUtf8(x) {
|
|
231
|
+
return x && x.typeId === Type.Utf8;
|
|
232
|
+
}
|
|
233
|
+
static isBool(x) {
|
|
234
|
+
return x && x.typeId === Type.Bool;
|
|
235
|
+
}
|
|
236
|
+
static isDecimal(x) {
|
|
237
|
+
return x && x.typeId === Type.Decimal;
|
|
238
|
+
}
|
|
239
|
+
static isDate(x) {
|
|
240
|
+
return x && x.typeId === Type.Date;
|
|
241
|
+
}
|
|
242
|
+
static isTime(x) {
|
|
243
|
+
return x && x.typeId === Type.Time;
|
|
244
|
+
}
|
|
245
|
+
static isTimestamp(x) {
|
|
246
|
+
return x && x.typeId === Type.Timestamp;
|
|
247
|
+
}
|
|
248
|
+
static isInterval(x) {
|
|
249
|
+
return x && x.typeId === Type.Interval;
|
|
250
|
+
}
|
|
251
|
+
static isList(x) {
|
|
252
|
+
return x && x.typeId === Type.List;
|
|
253
|
+
}
|
|
254
|
+
static isStruct(x) {
|
|
255
|
+
return x && x.typeId === Type.Struct;
|
|
256
|
+
}
|
|
257
|
+
static isUnion(x) {
|
|
258
|
+
return x && x.typeId === Type.Union;
|
|
259
|
+
}
|
|
260
|
+
static isFixedSizeBinary(x) {
|
|
261
|
+
return x && x.typeId === Type.FixedSizeBinary;
|
|
262
|
+
}
|
|
263
|
+
static isFixedSizeList(x) {
|
|
264
|
+
return x && x.typeId === Type.FixedSizeList;
|
|
265
|
+
}
|
|
266
|
+
static isMap(x) {
|
|
267
|
+
return x && x.typeId === Type.Map;
|
|
268
|
+
}
|
|
269
|
+
static isDictionary(x) {
|
|
270
|
+
return x && x.typeId === Type.Dictionary;
|
|
271
|
+
}
|
|
272
|
+
get typeId() {
|
|
273
|
+
return Type.NONE;
|
|
274
|
+
}
|
|
275
|
+
compareTo(other) {
|
|
276
|
+
return this === other;
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
Null = class extends DataType {
|
|
280
|
+
get typeId() {
|
|
281
|
+
return Type.Null;
|
|
282
|
+
}
|
|
283
|
+
get [Symbol.toStringTag]() {
|
|
284
|
+
return "Null";
|
|
285
|
+
}
|
|
286
|
+
toString() {
|
|
287
|
+
return "Null";
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
Bool = class extends DataType {
|
|
291
|
+
get typeId() {
|
|
292
|
+
return Type.Bool;
|
|
293
|
+
}
|
|
294
|
+
get [Symbol.toStringTag]() {
|
|
295
|
+
return "Bool";
|
|
296
|
+
}
|
|
297
|
+
toString() {
|
|
298
|
+
return "Bool";
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
Int = class extends DataType {
|
|
302
|
+
constructor(isSigned, bitWidth) {
|
|
303
|
+
super();
|
|
304
|
+
this.isSigned = isSigned;
|
|
305
|
+
this.bitWidth = bitWidth;
|
|
306
|
+
}
|
|
307
|
+
get typeId() {
|
|
308
|
+
return Type.Int;
|
|
309
|
+
}
|
|
310
|
+
get [Symbol.toStringTag]() {
|
|
311
|
+
return "Int";
|
|
312
|
+
}
|
|
313
|
+
toString() {
|
|
314
|
+
return `${this.isSigned ? "I" : "Ui"}nt${this.bitWidth}`;
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
Int8 = class extends Int {
|
|
318
|
+
constructor() {
|
|
319
|
+
super(true, 8);
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
Int16 = class extends Int {
|
|
323
|
+
constructor() {
|
|
324
|
+
super(true, 16);
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
Int32 = class extends Int {
|
|
328
|
+
constructor() {
|
|
329
|
+
super(true, 32);
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
Uint8 = class extends Int {
|
|
333
|
+
constructor() {
|
|
334
|
+
super(false, 8);
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
Uint16 = class extends Int {
|
|
338
|
+
constructor() {
|
|
339
|
+
super(false, 16);
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
Uint32 = class extends Int {
|
|
343
|
+
constructor() {
|
|
344
|
+
super(false, 32);
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
Precision = {
|
|
348
|
+
HALF: 16,
|
|
349
|
+
SINGLE: 32,
|
|
350
|
+
DOUBLE: 64
|
|
351
|
+
};
|
|
352
|
+
Float = class extends DataType {
|
|
353
|
+
constructor(precision) {
|
|
354
|
+
super();
|
|
355
|
+
this.precision = precision;
|
|
356
|
+
}
|
|
357
|
+
get typeId() {
|
|
358
|
+
return Type.Float;
|
|
359
|
+
}
|
|
360
|
+
get [Symbol.toStringTag]() {
|
|
361
|
+
return "Float";
|
|
362
|
+
}
|
|
363
|
+
toString() {
|
|
364
|
+
return `Float${this.precision}`;
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
Float32 = class extends Float {
|
|
368
|
+
constructor() {
|
|
369
|
+
super(Precision.SINGLE);
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
Float64 = class extends Float {
|
|
373
|
+
constructor() {
|
|
374
|
+
super(Precision.DOUBLE);
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
Binary = class extends DataType {
|
|
378
|
+
constructor() {
|
|
379
|
+
super();
|
|
380
|
+
}
|
|
381
|
+
get typeId() {
|
|
382
|
+
return Type.Binary;
|
|
383
|
+
}
|
|
384
|
+
toString() {
|
|
385
|
+
return "Binary";
|
|
386
|
+
}
|
|
387
|
+
get [Symbol.toStringTag]() {
|
|
388
|
+
return "Binary";
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
Utf8 = class extends DataType {
|
|
392
|
+
get typeId() {
|
|
393
|
+
return Type.Utf8;
|
|
394
|
+
}
|
|
395
|
+
get [Symbol.toStringTag]() {
|
|
396
|
+
return "Utf8";
|
|
397
|
+
}
|
|
398
|
+
toString() {
|
|
399
|
+
return "Utf8";
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
DateUnit = {
|
|
403
|
+
DAY: 0,
|
|
404
|
+
MILLISECOND: 1
|
|
405
|
+
};
|
|
406
|
+
Date = class extends DataType {
|
|
407
|
+
constructor(unit) {
|
|
408
|
+
super();
|
|
409
|
+
this.unit = unit;
|
|
410
|
+
}
|
|
411
|
+
get typeId() {
|
|
412
|
+
return Type.Date;
|
|
413
|
+
}
|
|
414
|
+
get [Symbol.toStringTag]() {
|
|
415
|
+
return "Date";
|
|
416
|
+
}
|
|
417
|
+
toString() {
|
|
418
|
+
return `Date${(this.unit + 1) * 32}<${DateUnit[this.unit]}>`;
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
TimeUnit = {
|
|
422
|
+
SECOND: 1,
|
|
423
|
+
MILLISECOND: 1e3,
|
|
424
|
+
MICROSECOND: 1e6,
|
|
425
|
+
NANOSECOND: 1e9
|
|
426
|
+
};
|
|
427
|
+
Time = class extends DataType {
|
|
428
|
+
constructor(unit, bitWidth) {
|
|
429
|
+
super();
|
|
430
|
+
this.unit = unit;
|
|
431
|
+
this.bitWidth = bitWidth;
|
|
432
|
+
}
|
|
433
|
+
get typeId() {
|
|
434
|
+
return Type.Time;
|
|
435
|
+
}
|
|
436
|
+
toString() {
|
|
437
|
+
return `Time${this.bitWidth}<${TimeUnit[this.unit]}>`;
|
|
438
|
+
}
|
|
439
|
+
get [Symbol.toStringTag]() {
|
|
440
|
+
return "Time";
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
Timestamp = class extends DataType {
|
|
444
|
+
constructor(unit, timezone = null) {
|
|
445
|
+
super();
|
|
446
|
+
this.unit = unit;
|
|
447
|
+
this.timezone = timezone;
|
|
448
|
+
}
|
|
449
|
+
get typeId() {
|
|
450
|
+
return Type.Timestamp;
|
|
451
|
+
}
|
|
452
|
+
get [Symbol.toStringTag]() {
|
|
453
|
+
return "Timestamp";
|
|
454
|
+
}
|
|
455
|
+
toString() {
|
|
456
|
+
return `Timestamp<${TimeUnit[this.unit]}${this.timezone ? `, ${this.timezone}` : ""}>`;
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
IntervalUnit = {
|
|
460
|
+
DAY_TIME: 0,
|
|
461
|
+
YEAR_MONTH: 1
|
|
462
|
+
};
|
|
463
|
+
Interval = class extends DataType {
|
|
464
|
+
constructor(unit) {
|
|
465
|
+
super();
|
|
466
|
+
this.unit = unit;
|
|
467
|
+
}
|
|
468
|
+
get typeId() {
|
|
469
|
+
return Type.Interval;
|
|
470
|
+
}
|
|
471
|
+
get [Symbol.toStringTag]() {
|
|
472
|
+
return "Interval";
|
|
473
|
+
}
|
|
474
|
+
toString() {
|
|
475
|
+
return `Interval<${IntervalUnit[this.unit]}>`;
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
FixedSizeList = class extends DataType {
|
|
479
|
+
constructor(listSize, child) {
|
|
480
|
+
super();
|
|
481
|
+
this.listSize = listSize;
|
|
482
|
+
this.children = [child];
|
|
483
|
+
}
|
|
484
|
+
get typeId() {
|
|
485
|
+
return Type.FixedSizeList;
|
|
486
|
+
}
|
|
487
|
+
get valueType() {
|
|
488
|
+
return this.children[0].type;
|
|
489
|
+
}
|
|
490
|
+
get valueField() {
|
|
491
|
+
return this.children[0];
|
|
492
|
+
}
|
|
493
|
+
get [Symbol.toStringTag]() {
|
|
494
|
+
return "FixedSizeList";
|
|
495
|
+
}
|
|
496
|
+
toString() {
|
|
497
|
+
return `FixedSizeList[${this.listSize}]<${this.valueType}>`;
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
Struct = class extends DataType {
|
|
501
|
+
constructor(children) {
|
|
502
|
+
super();
|
|
503
|
+
this.children = children;
|
|
504
|
+
}
|
|
505
|
+
get typeId() {
|
|
506
|
+
return Type.Struct;
|
|
507
|
+
}
|
|
508
|
+
toString() {
|
|
509
|
+
return `Struct<{${this.children.map((f) => `${f.name}:${f.type}`).join(", ")}}>`;
|
|
510
|
+
}
|
|
511
|
+
get [Symbol.toStringTag]() {
|
|
512
|
+
return "Struct";
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
// ../schema/src/lib/schema/schema.ts
|
|
519
|
+
var init_schema2 = __esm({
|
|
520
|
+
"../schema/src/lib/schema/schema.ts"() {
|
|
521
|
+
init_schema();
|
|
522
|
+
init_field();
|
|
523
|
+
init_type();
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
// ../schema/src/lib/arrow/arrow-like-type-utils.ts
|
|
528
|
+
function getArrowTypeFromTypedArray(array) {
|
|
529
|
+
switch (array.constructor) {
|
|
530
|
+
case Int8Array:
|
|
531
|
+
return new Int8();
|
|
532
|
+
case Uint8Array:
|
|
533
|
+
return new Uint8();
|
|
534
|
+
case Int16Array:
|
|
535
|
+
return new Int16();
|
|
536
|
+
case Uint16Array:
|
|
537
|
+
return new Uint16();
|
|
538
|
+
case Int32Array:
|
|
539
|
+
return new Int32();
|
|
540
|
+
case Uint32Array:
|
|
541
|
+
return new Uint32();
|
|
542
|
+
case Float32Array:
|
|
543
|
+
return new Float32();
|
|
544
|
+
case Float64Array:
|
|
545
|
+
return new Float64();
|
|
546
|
+
default:
|
|
547
|
+
throw new Error("array type not supported");
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
var init_arrow_like_type_utils = __esm({
|
|
551
|
+
"../schema/src/lib/arrow/arrow-like-type-utils.ts"() {
|
|
552
|
+
init_schema2();
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
// ../schema/src/index.ts
|
|
557
|
+
var init_src = __esm({
|
|
558
|
+
"../schema/src/index.ts"() {
|
|
559
|
+
init_mesh_utils();
|
|
560
|
+
init_schema2();
|
|
561
|
+
init_arrow_like_type_utils();
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
// src/lib/parse-obj-meshes.ts
|
|
566
|
+
function parseOBJMeshes(text) {
|
|
567
|
+
const state = new ParserState();
|
|
568
|
+
if (text.indexOf("\r\n") !== -1) {
|
|
569
|
+
text = text.replace(/\r\n/g, "\n");
|
|
570
|
+
}
|
|
571
|
+
if (text.indexOf("\\\n") !== -1) {
|
|
572
|
+
text = text.replace(/\\\n/g, "");
|
|
573
|
+
}
|
|
574
|
+
const lines = text.split("\n");
|
|
575
|
+
let line = "";
|
|
576
|
+
let lineFirstChar = "";
|
|
577
|
+
let lineLength = 0;
|
|
578
|
+
let result = [];
|
|
579
|
+
const trimLeft = typeof "".trimLeft === "function";
|
|
580
|
+
for (let i = 0, l = lines.length; i < l; i++) {
|
|
581
|
+
line = lines[i];
|
|
582
|
+
line = trimLeft ? line.trimLeft() : line.trim();
|
|
583
|
+
lineLength = line.length;
|
|
584
|
+
if (lineLength === 0)
|
|
585
|
+
continue;
|
|
586
|
+
lineFirstChar = line.charAt(0);
|
|
587
|
+
if (lineFirstChar === "#")
|
|
588
|
+
continue;
|
|
589
|
+
if (lineFirstChar === "v") {
|
|
590
|
+
const data = line.split(/\s+/);
|
|
591
|
+
switch (data[0]) {
|
|
592
|
+
case "v":
|
|
593
|
+
state.vertices.push(parseFloat(data[1]), parseFloat(data[2]), parseFloat(data[3]));
|
|
594
|
+
if (data.length === 8) {
|
|
595
|
+
state.colors.push(parseFloat(data[4]), parseFloat(data[5]), parseFloat(data[6]));
|
|
596
|
+
}
|
|
597
|
+
break;
|
|
598
|
+
case "vn":
|
|
599
|
+
state.normals.push(parseFloat(data[1]), parseFloat(data[2]), parseFloat(data[3]));
|
|
600
|
+
break;
|
|
601
|
+
case "vt":
|
|
602
|
+
state.uvs.push(parseFloat(data[1]), parseFloat(data[2]));
|
|
603
|
+
break;
|
|
604
|
+
default:
|
|
605
|
+
}
|
|
606
|
+
} else if (lineFirstChar === "f") {
|
|
607
|
+
const lineData = line.substr(1).trim();
|
|
608
|
+
const vertexData = lineData.split(/\s+/);
|
|
609
|
+
const faceVertices = [];
|
|
610
|
+
for (let j = 0, jl = vertexData.length; j < jl; j++) {
|
|
611
|
+
const vertex = vertexData[j];
|
|
612
|
+
if (vertex.length > 0) {
|
|
613
|
+
const vertexParts = vertex.split("/");
|
|
614
|
+
faceVertices.push(vertexParts);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
const v1 = faceVertices[0];
|
|
618
|
+
for (let j = 1, jl = faceVertices.length - 1; j < jl; j++) {
|
|
619
|
+
const v2 = faceVertices[j];
|
|
620
|
+
const v3 = faceVertices[j + 1];
|
|
621
|
+
state.addFace(v1[0], v2[0], v3[0], v1[1], v2[1], v3[1], v1[2], v2[2], v3[2]);
|
|
622
|
+
}
|
|
623
|
+
} else if (lineFirstChar === "l") {
|
|
624
|
+
const lineParts = line.substring(1).trim().split(" ");
|
|
625
|
+
let lineVertices;
|
|
626
|
+
const lineUVs = [];
|
|
627
|
+
if (line.indexOf("/") === -1) {
|
|
628
|
+
lineVertices = lineParts;
|
|
629
|
+
} else {
|
|
630
|
+
lineVertices = [];
|
|
631
|
+
for (let li = 0, llen = lineParts.length; li < llen; li++) {
|
|
632
|
+
const parts = lineParts[li].split("/");
|
|
633
|
+
if (parts[0] !== "")
|
|
634
|
+
lineVertices.push(parts[0]);
|
|
635
|
+
if (parts[1] !== "")
|
|
636
|
+
lineUVs.push(parts[1]);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
state.addLineGeometry(lineVertices, lineUVs);
|
|
640
|
+
} else if (lineFirstChar === "p") {
|
|
641
|
+
const lineData = line.substr(1).trim();
|
|
642
|
+
const pointData = lineData.split(" ");
|
|
643
|
+
state.addPointGeometry(pointData);
|
|
644
|
+
} else if ((result = OBJECT_RE.exec(line)) !== null) {
|
|
645
|
+
const name = (" " + result[0].substr(1).trim()).substr(1);
|
|
646
|
+
state.startObject(name);
|
|
647
|
+
} else if (MATERIAL_USE_RE.test(line)) {
|
|
648
|
+
state.object.startMaterial(line.substring(7).trim(), state.materialLibraries);
|
|
649
|
+
} else if (MATERIAL_RE.test(line)) {
|
|
650
|
+
state.materialLibraries.push(line.substring(7).trim());
|
|
651
|
+
} else if (lineFirstChar === "s") {
|
|
652
|
+
result = line.split(" ");
|
|
653
|
+
if (result.length > 1) {
|
|
654
|
+
const value = result[1].trim().toLowerCase();
|
|
655
|
+
state.object.smooth = value !== "0" && value !== "off";
|
|
656
|
+
} else {
|
|
657
|
+
state.object.smooth = true;
|
|
658
|
+
}
|
|
659
|
+
const material = state.object.currentMaterial();
|
|
660
|
+
if (material)
|
|
661
|
+
material.smooth = state.object.smooth;
|
|
662
|
+
} else {
|
|
663
|
+
if (line === "\0")
|
|
664
|
+
continue;
|
|
665
|
+
throw new Error(`Unexpected line: "${line}"`);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
state.finalize();
|
|
669
|
+
const meshes = [];
|
|
670
|
+
const materials = [];
|
|
671
|
+
for (const object of state.objects) {
|
|
672
|
+
const { geometry } = object;
|
|
673
|
+
if (geometry.vertices.length === 0)
|
|
674
|
+
continue;
|
|
675
|
+
const mesh = {
|
|
676
|
+
header: {
|
|
677
|
+
vertexCount: geometry.vertices.length / 3
|
|
678
|
+
},
|
|
679
|
+
attributes: {}
|
|
680
|
+
};
|
|
681
|
+
switch (geometry.type) {
|
|
682
|
+
case "Points":
|
|
683
|
+
mesh.mode = 0;
|
|
684
|
+
break;
|
|
685
|
+
case "Line":
|
|
686
|
+
mesh.mode = 1;
|
|
687
|
+
break;
|
|
688
|
+
default:
|
|
689
|
+
mesh.mode = 4;
|
|
690
|
+
break;
|
|
691
|
+
}
|
|
692
|
+
mesh.attributes.POSITION = { value: new Float32Array(geometry.vertices), size: 3 };
|
|
693
|
+
if (geometry.normals.length > 0) {
|
|
694
|
+
mesh.attributes.NORMAL = { value: new Float32Array(geometry.normals), size: 3 };
|
|
695
|
+
}
|
|
696
|
+
if (geometry.colors.length > 0) {
|
|
697
|
+
mesh.attributes.COLOR_0 = { value: new Float32Array(geometry.colors), size: 3 };
|
|
698
|
+
}
|
|
699
|
+
if (geometry.uvs.length > 0) {
|
|
700
|
+
mesh.attributes.TEXCOORD_0 = { value: new Float32Array(geometry.uvs), size: 2 };
|
|
701
|
+
}
|
|
702
|
+
mesh.materials = [];
|
|
703
|
+
for (const sourceMaterial of object.materials) {
|
|
704
|
+
const _material = {
|
|
705
|
+
name: sourceMaterial.name,
|
|
706
|
+
flatShading: !sourceMaterial.smooth
|
|
707
|
+
};
|
|
708
|
+
mesh.materials.push(_material);
|
|
709
|
+
materials.push(_material);
|
|
710
|
+
}
|
|
711
|
+
mesh.name = object.name;
|
|
712
|
+
meshes.push(mesh);
|
|
713
|
+
}
|
|
714
|
+
return { meshes, materials };
|
|
715
|
+
}
|
|
716
|
+
var OBJECT_RE, MATERIAL_RE, MATERIAL_USE_RE, MeshMaterial, MeshObject, ParserState;
|
|
717
|
+
var init_parse_obj_meshes = __esm({
|
|
718
|
+
"src/lib/parse-obj-meshes.ts"() {
|
|
719
|
+
OBJECT_RE = /^[og]\s*(.+)?/;
|
|
720
|
+
MATERIAL_RE = /^mtllib /;
|
|
721
|
+
MATERIAL_USE_RE = /^usemtl /;
|
|
722
|
+
MeshMaterial = class {
|
|
723
|
+
constructor({ index, name = "", mtllib, smooth, groupStart }) {
|
|
724
|
+
this.index = index;
|
|
725
|
+
this.name = name;
|
|
726
|
+
this.mtllib = mtllib;
|
|
727
|
+
this.smooth = smooth;
|
|
728
|
+
this.groupStart = groupStart;
|
|
729
|
+
this.groupEnd = -1;
|
|
730
|
+
this.groupCount = -1;
|
|
731
|
+
this.inherited = false;
|
|
732
|
+
}
|
|
733
|
+
clone(index = this.index) {
|
|
734
|
+
return new MeshMaterial({
|
|
735
|
+
index,
|
|
736
|
+
name: this.name,
|
|
737
|
+
mtllib: this.mtllib,
|
|
738
|
+
smooth: this.smooth,
|
|
739
|
+
groupStart: 0
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
};
|
|
743
|
+
MeshObject = class {
|
|
744
|
+
constructor(name = "") {
|
|
745
|
+
this.name = name;
|
|
746
|
+
this.geometry = {
|
|
747
|
+
vertices: [],
|
|
748
|
+
normals: [],
|
|
749
|
+
colors: [],
|
|
750
|
+
uvs: []
|
|
751
|
+
};
|
|
752
|
+
this.materials = [];
|
|
753
|
+
this.smooth = true;
|
|
754
|
+
this.fromDeclaration = null;
|
|
755
|
+
}
|
|
756
|
+
startMaterial(name, libraries) {
|
|
757
|
+
const previous = this._finalize(false);
|
|
758
|
+
if (previous && (previous.inherited || previous.groupCount <= 0)) {
|
|
759
|
+
this.materials.splice(previous.index, 1);
|
|
760
|
+
}
|
|
761
|
+
const material = new MeshMaterial({
|
|
762
|
+
index: this.materials.length,
|
|
763
|
+
name,
|
|
764
|
+
mtllib: Array.isArray(libraries) && libraries.length > 0 ? libraries[libraries.length - 1] : "",
|
|
765
|
+
smooth: previous !== void 0 ? previous.smooth : this.smooth,
|
|
766
|
+
groupStart: previous !== void 0 ? previous.groupEnd : 0
|
|
767
|
+
});
|
|
768
|
+
this.materials.push(material);
|
|
769
|
+
return material;
|
|
770
|
+
}
|
|
771
|
+
currentMaterial() {
|
|
772
|
+
if (this.materials.length > 0) {
|
|
773
|
+
return this.materials[this.materials.length - 1];
|
|
774
|
+
}
|
|
775
|
+
return void 0;
|
|
776
|
+
}
|
|
777
|
+
_finalize(end) {
|
|
778
|
+
const lastMultiMaterial = this.currentMaterial();
|
|
779
|
+
if (lastMultiMaterial && lastMultiMaterial.groupEnd === -1) {
|
|
780
|
+
lastMultiMaterial.groupEnd = this.geometry.vertices.length / 3;
|
|
781
|
+
lastMultiMaterial.groupCount = lastMultiMaterial.groupEnd - lastMultiMaterial.groupStart;
|
|
782
|
+
lastMultiMaterial.inherited = false;
|
|
783
|
+
}
|
|
784
|
+
if (end && this.materials.length > 1) {
|
|
785
|
+
for (let mi = this.materials.length - 1; mi >= 0; mi--) {
|
|
786
|
+
if (this.materials[mi].groupCount <= 0) {
|
|
787
|
+
this.materials.splice(mi, 1);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
if (end && this.materials.length === 0) {
|
|
792
|
+
this.materials.push({
|
|
793
|
+
name: "",
|
|
794
|
+
smooth: this.smooth
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
return lastMultiMaterial;
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
ParserState = class {
|
|
801
|
+
constructor() {
|
|
802
|
+
this.objects = [];
|
|
803
|
+
this.object = null;
|
|
804
|
+
this.vertices = [];
|
|
805
|
+
this.normals = [];
|
|
806
|
+
this.colors = [];
|
|
807
|
+
this.uvs = [];
|
|
808
|
+
this.materialLibraries = [];
|
|
809
|
+
this.startObject("", false);
|
|
810
|
+
}
|
|
811
|
+
startObject(name, fromDeclaration = true) {
|
|
812
|
+
if (this.object && !this.object.fromDeclaration) {
|
|
813
|
+
this.object.name = name;
|
|
814
|
+
this.object.fromDeclaration = fromDeclaration;
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
const previousMaterial = this.object && typeof this.object.currentMaterial === "function" ? this.object.currentMaterial() : void 0;
|
|
818
|
+
if (this.object && typeof this.object._finalize === "function") {
|
|
819
|
+
this.object._finalize(true);
|
|
820
|
+
}
|
|
821
|
+
this.object = new MeshObject(name);
|
|
822
|
+
this.object.fromDeclaration = fromDeclaration;
|
|
823
|
+
if (previousMaterial && previousMaterial.name && typeof previousMaterial.clone === "function") {
|
|
824
|
+
const declared = previousMaterial.clone(0);
|
|
825
|
+
declared.inherited = true;
|
|
826
|
+
this.object.materials.push(declared);
|
|
827
|
+
}
|
|
828
|
+
this.objects.push(this.object);
|
|
829
|
+
}
|
|
830
|
+
finalize() {
|
|
831
|
+
if (this.object && typeof this.object._finalize === "function") {
|
|
832
|
+
this.object._finalize(true);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
parseVertexIndex(value, len) {
|
|
836
|
+
const index = parseInt(value);
|
|
837
|
+
return (index >= 0 ? index - 1 : index + len / 3) * 3;
|
|
838
|
+
}
|
|
839
|
+
parseNormalIndex(value, len) {
|
|
840
|
+
const index = parseInt(value);
|
|
841
|
+
return (index >= 0 ? index - 1 : index + len / 3) * 3;
|
|
842
|
+
}
|
|
843
|
+
parseUVIndex(value, len) {
|
|
844
|
+
const index = parseInt(value);
|
|
845
|
+
return (index >= 0 ? index - 1 : index + len / 2) * 2;
|
|
846
|
+
}
|
|
847
|
+
addVertex(a, b, c) {
|
|
848
|
+
const src = this.vertices;
|
|
849
|
+
const dst = this.object.geometry.vertices;
|
|
850
|
+
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
851
|
+
dst.push(src[b + 0], src[b + 1], src[b + 2]);
|
|
852
|
+
dst.push(src[c + 0], src[c + 1], src[c + 2]);
|
|
853
|
+
}
|
|
854
|
+
addVertexPoint(a) {
|
|
855
|
+
const src = this.vertices;
|
|
856
|
+
const dst = this.object.geometry.vertices;
|
|
857
|
+
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
858
|
+
}
|
|
859
|
+
addVertexLine(a) {
|
|
860
|
+
const src = this.vertices;
|
|
861
|
+
const dst = this.object.geometry.vertices;
|
|
862
|
+
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
863
|
+
}
|
|
864
|
+
addNormal(a, b, c) {
|
|
865
|
+
const src = this.normals;
|
|
866
|
+
const dst = this.object.geometry.normals;
|
|
867
|
+
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
868
|
+
dst.push(src[b + 0], src[b + 1], src[b + 2]);
|
|
869
|
+
dst.push(src[c + 0], src[c + 1], src[c + 2]);
|
|
870
|
+
}
|
|
871
|
+
addColor(a, b, c) {
|
|
872
|
+
const src = this.colors;
|
|
873
|
+
const dst = this.object.geometry.colors;
|
|
874
|
+
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
875
|
+
dst.push(src[b + 0], src[b + 1], src[b + 2]);
|
|
876
|
+
dst.push(src[c + 0], src[c + 1], src[c + 2]);
|
|
877
|
+
}
|
|
878
|
+
addUV(a, b, c) {
|
|
879
|
+
const src = this.uvs;
|
|
880
|
+
const dst = this.object.geometry.uvs;
|
|
881
|
+
dst.push(src[a + 0], src[a + 1]);
|
|
882
|
+
dst.push(src[b + 0], src[b + 1]);
|
|
883
|
+
dst.push(src[c + 0], src[c + 1]);
|
|
884
|
+
}
|
|
885
|
+
addUVLine(a) {
|
|
886
|
+
const src = this.uvs;
|
|
887
|
+
const dst = this.object.geometry.uvs;
|
|
888
|
+
dst.push(src[a + 0], src[a + 1]);
|
|
889
|
+
}
|
|
890
|
+
addFace(a, b, c, ua, ub, uc, na, nb, nc) {
|
|
891
|
+
const vLen = this.vertices.length;
|
|
892
|
+
let ia = this.parseVertexIndex(a, vLen);
|
|
893
|
+
let ib = this.parseVertexIndex(b, vLen);
|
|
894
|
+
let ic = this.parseVertexIndex(c, vLen);
|
|
895
|
+
this.addVertex(ia, ib, ic);
|
|
896
|
+
if (ua !== void 0 && ua !== "") {
|
|
897
|
+
const uvLen = this.uvs.length;
|
|
898
|
+
ia = this.parseUVIndex(ua, uvLen);
|
|
899
|
+
ib = this.parseUVIndex(ub, uvLen);
|
|
900
|
+
ic = this.parseUVIndex(uc, uvLen);
|
|
901
|
+
this.addUV(ia, ib, ic);
|
|
902
|
+
}
|
|
903
|
+
if (na !== void 0 && na !== "") {
|
|
904
|
+
const nLen = this.normals.length;
|
|
905
|
+
ia = this.parseNormalIndex(na, nLen);
|
|
906
|
+
ib = na === nb ? ia : this.parseNormalIndex(nb, nLen);
|
|
907
|
+
ic = na === nc ? ia : this.parseNormalIndex(nc, nLen);
|
|
908
|
+
this.addNormal(ia, ib, ic);
|
|
909
|
+
}
|
|
910
|
+
if (this.colors.length > 0) {
|
|
911
|
+
this.addColor(ia, ib, ic);
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
addPointGeometry(vertices) {
|
|
915
|
+
this.object.geometry.type = "Points";
|
|
916
|
+
const vLen = this.vertices.length;
|
|
917
|
+
for (const vertex of vertices) {
|
|
918
|
+
this.addVertexPoint(this.parseVertexIndex(vertex, vLen));
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
addLineGeometry(vertices, uvs) {
|
|
922
|
+
this.object.geometry.type = "Line";
|
|
923
|
+
const vLen = this.vertices.length;
|
|
924
|
+
const uvLen = this.uvs.length;
|
|
925
|
+
for (const vertex of vertices) {
|
|
926
|
+
this.addVertexLine(this.parseVertexIndex(vertex, vLen));
|
|
927
|
+
}
|
|
928
|
+
for (const uv of uvs) {
|
|
929
|
+
this.addUVLine(this.parseUVIndex(uv, uvLen));
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
});
|
|
935
|
+
|
|
936
|
+
// src/lib/get-obj-schema.ts
|
|
937
|
+
function getOBJSchema(attributes, metadata = {}) {
|
|
938
|
+
let metadataMap;
|
|
939
|
+
for (const key in metadata) {
|
|
940
|
+
metadataMap = metadataMap || new Map();
|
|
941
|
+
if (key !== "value") {
|
|
942
|
+
metadataMap.set(key, JSON.stringify(metadata[key]));
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
const fields = [];
|
|
946
|
+
for (const attributeName in attributes) {
|
|
947
|
+
const attribute = attributes[attributeName];
|
|
948
|
+
const field = getArrowFieldFromAttribute(attributeName, attribute);
|
|
949
|
+
fields.push(field);
|
|
950
|
+
}
|
|
951
|
+
return new Schema(fields, metadataMap);
|
|
952
|
+
}
|
|
953
|
+
function getArrowFieldFromAttribute(attributeName, attribute) {
|
|
954
|
+
const metadataMap = new Map();
|
|
955
|
+
for (const key in attribute) {
|
|
956
|
+
if (key !== "value") {
|
|
957
|
+
metadataMap.set(key, JSON.stringify(attribute[key]));
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
const type = getArrowTypeFromTypedArray(attribute.value);
|
|
961
|
+
const isSingleValue = !("size" in attribute) || attribute.size === 1;
|
|
962
|
+
return isSingleValue ? new Field(attributeName, type, false, metadataMap) : new Field(attributeName, new FixedSizeList(attribute.size, new Field("value", type)), false, metadataMap);
|
|
963
|
+
}
|
|
964
|
+
var init_get_obj_schema = __esm({
|
|
965
|
+
"src/lib/get-obj-schema.ts"() {
|
|
966
|
+
init_src();
|
|
967
|
+
}
|
|
968
|
+
});
|
|
969
|
+
|
|
970
|
+
// src/lib/parse-obj.ts
|
|
971
|
+
function parseOBJ(text, options) {
|
|
972
|
+
const { meshes } = parseOBJMeshes(text);
|
|
973
|
+
const vertexCount = meshes.reduce((s, mesh) => s + mesh.header.vertexCount, 0);
|
|
974
|
+
const attributes = mergeAttributes(meshes, vertexCount);
|
|
975
|
+
const header = {
|
|
976
|
+
vertexCount,
|
|
977
|
+
boundingBox: getMeshBoundingBox(attributes)
|
|
978
|
+
};
|
|
979
|
+
const schema = getOBJSchema(attributes, {
|
|
980
|
+
mode: 4,
|
|
981
|
+
boundingBox: header.boundingBox
|
|
982
|
+
});
|
|
983
|
+
return {
|
|
984
|
+
loaderData: {
|
|
985
|
+
header: {}
|
|
986
|
+
},
|
|
987
|
+
schema,
|
|
988
|
+
header,
|
|
989
|
+
mode: 4,
|
|
990
|
+
attributes
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
function mergeAttributes(meshes, vertexCount) {
|
|
994
|
+
const positions = new Float32Array(vertexCount * 3);
|
|
995
|
+
let normals;
|
|
996
|
+
let colors;
|
|
997
|
+
let uvs;
|
|
998
|
+
let i = 0;
|
|
999
|
+
for (const mesh of meshes) {
|
|
1000
|
+
const { POSITION, NORMAL, COLOR_0, TEXCOORD_0 } = mesh.attributes;
|
|
1001
|
+
positions.set(POSITION.value, i * 3);
|
|
1002
|
+
if (NORMAL) {
|
|
1003
|
+
normals = normals || new Float32Array(vertexCount * 3);
|
|
1004
|
+
normals.set(NORMAL.value, i * 3);
|
|
1005
|
+
}
|
|
1006
|
+
if (COLOR_0) {
|
|
1007
|
+
colors = colors || new Float32Array(vertexCount * 3);
|
|
1008
|
+
colors.set(COLOR_0.value, i * 3);
|
|
1009
|
+
}
|
|
1010
|
+
if (TEXCOORD_0) {
|
|
1011
|
+
uvs = uvs || new Float32Array(vertexCount * 2);
|
|
1012
|
+
uvs.set(TEXCOORD_0.value, i * 2);
|
|
1013
|
+
}
|
|
1014
|
+
i += POSITION.value.length / 3;
|
|
1015
|
+
}
|
|
1016
|
+
const attributes = {};
|
|
1017
|
+
attributes.POSITION = { value: positions, size: 3 };
|
|
1018
|
+
if (normals) {
|
|
1019
|
+
attributes.NORMAL = { value: normals, size: 3 };
|
|
1020
|
+
}
|
|
1021
|
+
if (colors) {
|
|
1022
|
+
attributes.COLOR_0 = { value: colors, size: 3 };
|
|
1023
|
+
}
|
|
1024
|
+
if (uvs) {
|
|
1025
|
+
attributes.TEXCOORD_0 = { value: uvs, size: 2 };
|
|
1026
|
+
}
|
|
1027
|
+
return attributes;
|
|
1028
|
+
}
|
|
1029
|
+
var init_parse_obj = __esm({
|
|
1030
|
+
"src/lib/parse-obj.ts"() {
|
|
1031
|
+
init_src();
|
|
1032
|
+
init_parse_obj_meshes();
|
|
1033
|
+
init_get_obj_schema();
|
|
1034
|
+
}
|
|
1035
|
+
});
|
|
1036
|
+
|
|
1037
|
+
// src/lib/parse-mtl.ts
|
|
1038
|
+
function parseMTL(text, options) {
|
|
1039
|
+
const materials = [];
|
|
1040
|
+
let currentMaterial = { name: "placeholder" };
|
|
1041
|
+
const lines = text.split("\n");
|
|
1042
|
+
for (let line of lines) {
|
|
1043
|
+
line = line.trim();
|
|
1044
|
+
if (line.length === 0 || line.charAt(0) === "#") {
|
|
1045
|
+
continue;
|
|
1046
|
+
}
|
|
1047
|
+
const pos = line.indexOf(" ");
|
|
1048
|
+
let key = pos >= 0 ? line.substring(0, pos) : line;
|
|
1049
|
+
key = key.toLowerCase();
|
|
1050
|
+
let value = pos >= 0 ? line.substring(pos + 1) : "";
|
|
1051
|
+
value = value.trim();
|
|
1052
|
+
switch (key) {
|
|
1053
|
+
case "newmtl":
|
|
1054
|
+
currentMaterial = { name: value };
|
|
1055
|
+
materials.push(currentMaterial);
|
|
1056
|
+
break;
|
|
1057
|
+
case "ka":
|
|
1058
|
+
currentMaterial.ambientColor = parseColor(value);
|
|
1059
|
+
break;
|
|
1060
|
+
case "kd":
|
|
1061
|
+
currentMaterial.diffuseColor = parseColor(value);
|
|
1062
|
+
break;
|
|
1063
|
+
case "map_kd":
|
|
1064
|
+
currentMaterial.diffuseTextureUrl = value;
|
|
1065
|
+
break;
|
|
1066
|
+
case "ks":
|
|
1067
|
+
currentMaterial.specularColor = parseColor(value);
|
|
1068
|
+
break;
|
|
1069
|
+
case "map_ks":
|
|
1070
|
+
currentMaterial.specularTextureUrl = value;
|
|
1071
|
+
break;
|
|
1072
|
+
case "ke":
|
|
1073
|
+
currentMaterial.emissiveColor = parseColor(value);
|
|
1074
|
+
break;
|
|
1075
|
+
case "map_ke":
|
|
1076
|
+
currentMaterial.emissiveTextureUrl = value;
|
|
1077
|
+
break;
|
|
1078
|
+
case "ns":
|
|
1079
|
+
currentMaterial.shininess = parseFloat(value);
|
|
1080
|
+
break;
|
|
1081
|
+
case "map_ns":
|
|
1082
|
+
break;
|
|
1083
|
+
case "ni":
|
|
1084
|
+
currentMaterial.refraction = parseFloat(value);
|
|
1085
|
+
break;
|
|
1086
|
+
case "illum":
|
|
1087
|
+
currentMaterial.illumination = parseFloat(value);
|
|
1088
|
+
break;
|
|
1089
|
+
default:
|
|
1090
|
+
break;
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
return materials;
|
|
1094
|
+
}
|
|
1095
|
+
function parseColor(value, options) {
|
|
1096
|
+
const rgb = value.split(DELIMITER_PATTERN, 3);
|
|
1097
|
+
const color = [
|
|
1098
|
+
parseFloat(rgb[0]),
|
|
1099
|
+
parseFloat(rgb[1]),
|
|
1100
|
+
parseFloat(rgb[2])
|
|
1101
|
+
];
|
|
1102
|
+
return color;
|
|
1103
|
+
}
|
|
1104
|
+
var DELIMITER_PATTERN;
|
|
1105
|
+
var init_parse_mtl = __esm({
|
|
1106
|
+
"src/lib/parse-mtl.ts"() {
|
|
1107
|
+
DELIMITER_PATTERN = /\s+/;
|
|
1108
|
+
}
|
|
1109
|
+
});
|
|
1110
|
+
|
|
1111
|
+
// src/obj-loader.ts
|
|
1112
|
+
function testOBJFile(text) {
|
|
1113
|
+
return text[0] === "v";
|
|
1114
|
+
}
|
|
1115
|
+
var VERSION, OBJLoader;
|
|
1116
|
+
var init_obj_loader = __esm({
|
|
1117
|
+
"src/obj-loader.ts"() {
|
|
1118
|
+
VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
1119
|
+
OBJLoader = {
|
|
1120
|
+
name: "OBJ",
|
|
1121
|
+
id: "obj",
|
|
1122
|
+
module: "obj",
|
|
1123
|
+
version: VERSION,
|
|
1124
|
+
worker: true,
|
|
1125
|
+
extensions: ["obj"],
|
|
1126
|
+
mimeTypes: ["text/plain"],
|
|
1127
|
+
testText: testOBJFile,
|
|
1128
|
+
options: {
|
|
1129
|
+
obj: {}
|
|
1130
|
+
}
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
});
|
|
1134
|
+
|
|
1135
|
+
// src/mtl-loader.ts
|
|
1136
|
+
var VERSION2, MTLLoader;
|
|
1137
|
+
var init_mtl_loader = __esm({
|
|
1138
|
+
"src/mtl-loader.ts"() {
|
|
1139
|
+
VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
1140
|
+
MTLLoader = {
|
|
1141
|
+
name: "MTL",
|
|
1142
|
+
id: "mtl",
|
|
1143
|
+
module: "mtl",
|
|
1144
|
+
version: VERSION2,
|
|
1145
|
+
worker: true,
|
|
1146
|
+
extensions: ["mtl"],
|
|
1147
|
+
mimeTypes: ["text/plain"],
|
|
1148
|
+
testText: (text) => text.includes("newmtl"),
|
|
1149
|
+
options: {
|
|
1150
|
+
mtl: {}
|
|
1151
|
+
}
|
|
1152
|
+
};
|
|
1153
|
+
}
|
|
1154
|
+
});
|
|
1155
|
+
|
|
1156
|
+
// src/index.ts
|
|
1157
|
+
var src_exports = {};
|
|
1158
|
+
__export(src_exports, {
|
|
1159
|
+
MTLLoader: () => MTLLoader2,
|
|
1160
|
+
OBJLoader: () => OBJLoader2,
|
|
1161
|
+
OBJWorkerLoader: () => OBJLoader,
|
|
1162
|
+
_typecheckMTLLoader: () => _typecheckMTLLoader,
|
|
1163
|
+
_typecheckOBJLoader: () => _typecheckOBJLoader
|
|
1164
|
+
});
|
|
1165
|
+
var OBJLoader2, MTLLoader2, _typecheckOBJLoader, _typecheckMTLLoader;
|
|
1166
|
+
var init_src2 = __esm({
|
|
1167
|
+
"src/index.ts"() {
|
|
1168
|
+
init_parse_obj();
|
|
1169
|
+
init_parse_mtl();
|
|
1170
|
+
init_obj_loader();
|
|
1171
|
+
init_mtl_loader();
|
|
1172
|
+
OBJLoader2 = {
|
|
1173
|
+
...OBJLoader,
|
|
1174
|
+
parse: async (arrayBuffer, options) => parseOBJ(new TextDecoder().decode(arrayBuffer), options),
|
|
1175
|
+
parseTextSync: (text, options) => parseOBJ(text, options)
|
|
1176
|
+
};
|
|
1177
|
+
MTLLoader2 = {
|
|
1178
|
+
...MTLLoader,
|
|
1179
|
+
parse: async (arrayBuffer, options) => parseMTL(new TextDecoder().decode(arrayBuffer), options?.mtl),
|
|
1180
|
+
parseTextSync: (text, options) => parseMTL(text, options?.mtl)
|
|
1181
|
+
};
|
|
1182
|
+
_typecheckOBJLoader = OBJLoader2;
|
|
1183
|
+
_typecheckMTLLoader = MTLLoader2;
|
|
1184
|
+
}
|
|
1185
|
+
});
|
|
1186
|
+
|
|
1187
|
+
// src/bundle.ts
|
|
1188
|
+
var require_bundle = __commonJS({
|
|
1189
|
+
"src/bundle.ts"(exports, module) {
|
|
1190
|
+
var moduleExports = (init_src2(), src_exports);
|
|
1191
|
+
globalThis.loaders = globalThis.loaders || {};
|
|
1192
|
+
module.exports = Object.assign(globalThis.loaders, moduleExports);
|
|
1193
|
+
}
|
|
1194
|
+
});
|
|
1195
|
+
require_bundle();
|
|
1196
|
+
})();
|