@loaders.gl/ply 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 +1241 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/lib/get-ply-schema.d.ts +10 -0
- package/dist/lib/get-ply-schema.d.ts.map +1 -0
- package/dist/lib/normalize-ply.d.ts +8 -0
- package/dist/lib/normalize-ply.d.ts.map +1 -0
- package/dist/lib/parse-ply-in-batches.d.ts +8 -0
- package/dist/lib/parse-ply-in-batches.d.ts.map +1 -0
- package/dist/lib/parse-ply-in-batches.js +1 -1
- package/dist/lib/parse-ply-in-batches.js.map +1 -1
- package/dist/lib/parse-ply.d.ts +8 -0
- package/dist/lib/parse-ply.d.ts.map +1 -0
- package/dist/lib/ply-types.d.ts +29 -0
- package/dist/lib/ply-types.d.ts.map +1 -0
- package/dist/ply-loader.d.ts +24 -0
- package/dist/ply-loader.d.ts.map +1 -0
- package/dist/ply-loader.js +1 -1
- package/dist/ply-worker.js +1 -1
- package/dist/workers/ply-worker.d.ts +2 -0
- package/dist/workers/ply-worker.d.ts.map +1 -0
- package/package.json +7 -10
- package/src/lib/parse-ply-in-batches.ts +3 -4
package/dist/dist.min.js
ADDED
|
@@ -0,0 +1,1241 @@
|
|
|
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
|
+
// src/ply-loader.ts
|
|
17
|
+
var VERSION, PLYLoader;
|
|
18
|
+
var init_ply_loader = __esm({
|
|
19
|
+
"src/ply-loader.ts"() {
|
|
20
|
+
VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
21
|
+
PLYLoader = {
|
|
22
|
+
name: "PLY",
|
|
23
|
+
id: "ply",
|
|
24
|
+
module: "ply",
|
|
25
|
+
shapes: ["mesh", "gltf", "columnar-table"],
|
|
26
|
+
version: VERSION,
|
|
27
|
+
worker: true,
|
|
28
|
+
extensions: ["ply"],
|
|
29
|
+
mimeTypes: ["text/plain", "application/octet-stream"],
|
|
30
|
+
text: true,
|
|
31
|
+
binary: true,
|
|
32
|
+
tests: ["ply"],
|
|
33
|
+
options: {
|
|
34
|
+
ply: {}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// ../schema/src/category/mesh/mesh-utils.ts
|
|
41
|
+
function getMeshBoundingBox(attributes) {
|
|
42
|
+
let minX = Infinity;
|
|
43
|
+
let minY = Infinity;
|
|
44
|
+
let minZ = Infinity;
|
|
45
|
+
let maxX = -Infinity;
|
|
46
|
+
let maxY = -Infinity;
|
|
47
|
+
let maxZ = -Infinity;
|
|
48
|
+
const positions = attributes.POSITION ? attributes.POSITION.value : [];
|
|
49
|
+
const len = positions && positions.length;
|
|
50
|
+
for (let i = 0; i < len; i += 3) {
|
|
51
|
+
const x = positions[i];
|
|
52
|
+
const y = positions[i + 1];
|
|
53
|
+
const z = positions[i + 2];
|
|
54
|
+
minX = x < minX ? x : minX;
|
|
55
|
+
minY = y < minY ? y : minY;
|
|
56
|
+
minZ = z < minZ ? z : minZ;
|
|
57
|
+
maxX = x > maxX ? x : maxX;
|
|
58
|
+
maxY = y > maxY ? y : maxY;
|
|
59
|
+
maxZ = z > maxZ ? z : maxZ;
|
|
60
|
+
}
|
|
61
|
+
return [
|
|
62
|
+
[minX, minY, minZ],
|
|
63
|
+
[maxX, maxY, maxZ]
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
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();
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
// ../schema/src/category/mesh/deduce-mesh-schema.ts
|
|
581
|
+
function deduceMeshSchema(attributes, metadata) {
|
|
582
|
+
const fields = deduceMeshFields(attributes);
|
|
583
|
+
return new Schema(fields, metadata);
|
|
584
|
+
}
|
|
585
|
+
function deduceMeshField(attributeName, attribute, optionalMetadata) {
|
|
586
|
+
const type = getArrowTypeFromTypedArray(attribute.value);
|
|
587
|
+
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;
|
|
590
|
+
}
|
|
591
|
+
function deduceMeshFields(attributes) {
|
|
592
|
+
const fields = [];
|
|
593
|
+
for (const attributeName in attributes) {
|
|
594
|
+
const attribute = attributes[attributeName];
|
|
595
|
+
fields.push(deduceMeshField(attributeName, attribute));
|
|
596
|
+
}
|
|
597
|
+
return fields;
|
|
598
|
+
}
|
|
599
|
+
function makeMeshAttributeMetadata(attribute) {
|
|
600
|
+
const result = new Map();
|
|
601
|
+
if ("byteOffset" in attribute) {
|
|
602
|
+
result.set("byteOffset", attribute.byteOffset.toString(10));
|
|
603
|
+
}
|
|
604
|
+
if ("byteStride" in attribute) {
|
|
605
|
+
result.set("byteStride", attribute.byteStride.toString(10));
|
|
606
|
+
}
|
|
607
|
+
if ("normalized" in attribute) {
|
|
608
|
+
result.set("normalized", attribute.normalized.toString());
|
|
609
|
+
}
|
|
610
|
+
return result;
|
|
611
|
+
}
|
|
612
|
+
var init_deduce_mesh_schema = __esm({
|
|
613
|
+
"../schema/src/category/mesh/deduce-mesh-schema.ts"() {
|
|
614
|
+
init_schema2();
|
|
615
|
+
init_arrow_like_type_utils();
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
// ../schema/src/index.ts
|
|
620
|
+
var init_src = __esm({
|
|
621
|
+
"../schema/src/index.ts"() {
|
|
622
|
+
init_mesh_utils();
|
|
623
|
+
init_deduce_mesh_schema();
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
// src/lib/get-ply-schema.ts
|
|
628
|
+
function getPLYSchema(plyHeader, attributes) {
|
|
629
|
+
const metadataMap = makeMetadataFromPlyHeader(plyHeader);
|
|
630
|
+
const schema = deduceMeshSchema(attributes, metadataMap);
|
|
631
|
+
return schema;
|
|
632
|
+
}
|
|
633
|
+
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));
|
|
637
|
+
if (plyHeader.format !== void 0) {
|
|
638
|
+
metadataMap.set("ply_format", plyHeader.format);
|
|
639
|
+
}
|
|
640
|
+
if (plyHeader.version !== void 0) {
|
|
641
|
+
metadataMap.set("ply_version", plyHeader.version);
|
|
642
|
+
}
|
|
643
|
+
if (plyHeader.headerLength !== void 0) {
|
|
644
|
+
metadataMap.set("ply_headerLength", plyHeader.headerLength.toString(10));
|
|
645
|
+
}
|
|
646
|
+
return metadataMap;
|
|
647
|
+
}
|
|
648
|
+
var init_get_ply_schema = __esm({
|
|
649
|
+
"src/lib/get-ply-schema.ts"() {
|
|
650
|
+
init_src();
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
|
|
654
|
+
// src/lib/normalize-ply.ts
|
|
655
|
+
function normalizePLY(plyHeader, plyAttributes, options) {
|
|
656
|
+
const attributes = getMeshAttributes(plyAttributes);
|
|
657
|
+
const boundingBox = getMeshBoundingBox(attributes);
|
|
658
|
+
const vertexCount = plyAttributes.indices.length || plyAttributes.vertices.length / 3;
|
|
659
|
+
const isTriangles = plyAttributes.indices && plyAttributes.indices.length > 0;
|
|
660
|
+
const mode = isTriangles ? 4 : 0;
|
|
661
|
+
const topology = isTriangles ? "triangle-list" : "point-list";
|
|
662
|
+
const schema = getPLYSchema(plyHeader, attributes);
|
|
663
|
+
const plyMesh = {
|
|
664
|
+
loader: "ply",
|
|
665
|
+
loaderData: plyHeader,
|
|
666
|
+
header: {
|
|
667
|
+
vertexCount,
|
|
668
|
+
boundingBox
|
|
669
|
+
},
|
|
670
|
+
schema,
|
|
671
|
+
attributes,
|
|
672
|
+
indices: { value: new Uint32Array(0), size: 0 },
|
|
673
|
+
mode,
|
|
674
|
+
topology
|
|
675
|
+
};
|
|
676
|
+
if (plyAttributes.indices.length > 0) {
|
|
677
|
+
plyMesh.indices = { value: new Uint32Array(plyAttributes.indices), size: 1 };
|
|
678
|
+
}
|
|
679
|
+
return plyMesh;
|
|
680
|
+
}
|
|
681
|
+
function getMeshAttributes(attributes) {
|
|
682
|
+
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 };
|
|
692
|
+
}
|
|
693
|
+
return accessors;
|
|
694
|
+
}
|
|
695
|
+
var init_normalize_ply = __esm({
|
|
696
|
+
"src/lib/normalize-ply.ts"() {
|
|
697
|
+
init_src();
|
|
698
|
+
init_get_ply_schema();
|
|
699
|
+
}
|
|
700
|
+
});
|
|
701
|
+
|
|
702
|
+
// src/lib/parse-ply.ts
|
|
703
|
+
function parsePLY(data, options = {}) {
|
|
704
|
+
let header;
|
|
705
|
+
let attributes;
|
|
706
|
+
if (data instanceof ArrayBuffer) {
|
|
707
|
+
const text = new TextDecoder().decode(data);
|
|
708
|
+
header = parseHeader(text, options);
|
|
709
|
+
attributes = header.format === "ascii" ? parseASCII(text, header) : parseBinary(data, header);
|
|
710
|
+
} else {
|
|
711
|
+
header = parseHeader(data, options);
|
|
712
|
+
attributes = parseASCII(data, header);
|
|
713
|
+
}
|
|
714
|
+
return normalizePLY(header, attributes);
|
|
715
|
+
}
|
|
716
|
+
function parseHeader(data, options) {
|
|
717
|
+
const PLY_HEADER_PATTERN = /ply([\s\S]*)end_header\s/;
|
|
718
|
+
let headerText = "";
|
|
719
|
+
let headerLength = 0;
|
|
720
|
+
const result = PLY_HEADER_PATTERN.exec(data);
|
|
721
|
+
if (result !== null) {
|
|
722
|
+
headerText = result[1];
|
|
723
|
+
headerLength = result[0].length;
|
|
724
|
+
}
|
|
725
|
+
const lines = headerText.split("\n");
|
|
726
|
+
const header = parseHeaderLines(lines, headerLength, options);
|
|
727
|
+
return header;
|
|
728
|
+
}
|
|
729
|
+
function parseHeaderLines(lines, headerLength, options) {
|
|
730
|
+
const header = {
|
|
731
|
+
comments: [],
|
|
732
|
+
elements: [],
|
|
733
|
+
headerLength
|
|
734
|
+
};
|
|
735
|
+
let lineType;
|
|
736
|
+
let lineValues;
|
|
737
|
+
let currentElement2 = null;
|
|
738
|
+
for (let i = 0; i < lines.length; i++) {
|
|
739
|
+
let line = lines[i];
|
|
740
|
+
line = line.trim();
|
|
741
|
+
if (line === "") {
|
|
742
|
+
continue;
|
|
743
|
+
}
|
|
744
|
+
lineValues = line.split(/\s+/);
|
|
745
|
+
lineType = lineValues.shift();
|
|
746
|
+
line = lineValues.join(" ");
|
|
747
|
+
switch (lineType) {
|
|
748
|
+
case "format":
|
|
749
|
+
header.format = lineValues[0];
|
|
750
|
+
header.version = lineValues[1];
|
|
751
|
+
break;
|
|
752
|
+
case "comment":
|
|
753
|
+
header.comments.push(line);
|
|
754
|
+
break;
|
|
755
|
+
case "element":
|
|
756
|
+
if (currentElement2) {
|
|
757
|
+
header.elements.push(currentElement2);
|
|
758
|
+
}
|
|
759
|
+
currentElement2 = {
|
|
760
|
+
name: lineValues[0],
|
|
761
|
+
count: parseInt(lineValues[1], 10),
|
|
762
|
+
properties: []
|
|
763
|
+
};
|
|
764
|
+
break;
|
|
765
|
+
case "property":
|
|
766
|
+
if (!currentElement2) {
|
|
767
|
+
break;
|
|
768
|
+
}
|
|
769
|
+
currentElement2.properties.push(makePLYElementProperty(lineValues, options.propertyNameMapping));
|
|
770
|
+
break;
|
|
771
|
+
default:
|
|
772
|
+
console.log("unhandled", lineType, lineValues);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
if (currentElement2 !== void 0) {
|
|
776
|
+
header.elements.push(currentElement2);
|
|
777
|
+
}
|
|
778
|
+
return header;
|
|
779
|
+
}
|
|
780
|
+
function makePLYElementProperty(propertValues, propertyNameMapping) {
|
|
781
|
+
const property = {
|
|
782
|
+
type: propertValues[0]
|
|
783
|
+
};
|
|
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];
|
|
790
|
+
}
|
|
791
|
+
if (propertyNameMapping && property.name in propertyNameMapping) {
|
|
792
|
+
property.name = propertyNameMapping[property.name];
|
|
793
|
+
}
|
|
794
|
+
return property;
|
|
795
|
+
}
|
|
796
|
+
function parseASCIINumber(n, type) {
|
|
797
|
+
switch (type) {
|
|
798
|
+
case "char":
|
|
799
|
+
case "uchar":
|
|
800
|
+
case "short":
|
|
801
|
+
case "ushort":
|
|
802
|
+
case "int":
|
|
803
|
+
case "uint":
|
|
804
|
+
case "int8":
|
|
805
|
+
case "uint8":
|
|
806
|
+
case "int16":
|
|
807
|
+
case "uint16":
|
|
808
|
+
case "int32":
|
|
809
|
+
case "uint32":
|
|
810
|
+
return parseInt(n, 10);
|
|
811
|
+
case "float":
|
|
812
|
+
case "double":
|
|
813
|
+
case "float32":
|
|
814
|
+
case "float64":
|
|
815
|
+
return parseFloat(n);
|
|
816
|
+
default:
|
|
817
|
+
throw new Error(type);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
function parseASCIIElement(properties, line) {
|
|
821
|
+
const values = line.split(/\s+/);
|
|
822
|
+
const element = {};
|
|
823
|
+
for (let i = 0; i < properties.length; i++) {
|
|
824
|
+
if (properties[i].type === "list") {
|
|
825
|
+
const list = [];
|
|
826
|
+
const n = parseASCIINumber(values.shift(), properties[i].countType);
|
|
827
|
+
for (let j = 0; j < n; j++) {
|
|
828
|
+
list.push(parseASCIINumber(values.shift(), properties[i].itemType));
|
|
829
|
+
}
|
|
830
|
+
element[properties[i].name] = list;
|
|
831
|
+
} else {
|
|
832
|
+
element[properties[i].name] = parseASCIINumber(values.shift(), properties[i].type);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
return element;
|
|
836
|
+
}
|
|
837
|
+
function parseASCII(data, header) {
|
|
838
|
+
const attributes = {
|
|
839
|
+
indices: [],
|
|
840
|
+
vertices: [],
|
|
841
|
+
normals: [],
|
|
842
|
+
uvs: [],
|
|
843
|
+
colors: []
|
|
844
|
+
};
|
|
845
|
+
let result;
|
|
846
|
+
const patternBody = /end_header\s([\s\S]*)$/;
|
|
847
|
+
let body = "";
|
|
848
|
+
if ((result = patternBody.exec(data)) !== null) {
|
|
849
|
+
body = result[1];
|
|
850
|
+
}
|
|
851
|
+
const lines = body.split("\n");
|
|
852
|
+
let currentElement2 = 0;
|
|
853
|
+
let currentElementCount = 0;
|
|
854
|
+
for (let i = 0; i < lines.length; i++) {
|
|
855
|
+
let line = lines[i];
|
|
856
|
+
line = line.trim();
|
|
857
|
+
if (line !== "") {
|
|
858
|
+
if (currentElementCount >= header.elements[currentElement2].count) {
|
|
859
|
+
currentElement2++;
|
|
860
|
+
currentElementCount = 0;
|
|
861
|
+
}
|
|
862
|
+
const element = parseASCIIElement(header.elements[currentElement2].properties, line);
|
|
863
|
+
handleElement(attributes, header.elements[currentElement2].name, element);
|
|
864
|
+
currentElementCount++;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
return attributes;
|
|
868
|
+
}
|
|
869
|
+
function handleElement(buffer, elementName, element = {}) {
|
|
870
|
+
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);
|
|
880
|
+
}
|
|
881
|
+
} else if (elementName === "face") {
|
|
882
|
+
const vertexIndices = element.vertex_indices || element.vertex_index;
|
|
883
|
+
if (vertexIndices.length === 3) {
|
|
884
|
+
buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[2]);
|
|
885
|
+
} else if (vertexIndices.length === 4) {
|
|
886
|
+
buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[3]);
|
|
887
|
+
buffer.indices.push(vertexIndices[1], vertexIndices[2], vertexIndices[3]);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
function binaryRead(dataview, at, type, littleEndian) {
|
|
892
|
+
switch (type) {
|
|
893
|
+
case "int8":
|
|
894
|
+
case "char":
|
|
895
|
+
return [dataview.getInt8(at), 1];
|
|
896
|
+
case "uint8":
|
|
897
|
+
case "uchar":
|
|
898
|
+
return [dataview.getUint8(at), 1];
|
|
899
|
+
case "int16":
|
|
900
|
+
case "short":
|
|
901
|
+
return [dataview.getInt16(at, littleEndian), 2];
|
|
902
|
+
case "uint16":
|
|
903
|
+
case "ushort":
|
|
904
|
+
return [dataview.getUint16(at, littleEndian), 2];
|
|
905
|
+
case "int32":
|
|
906
|
+
case "int":
|
|
907
|
+
return [dataview.getInt32(at, littleEndian), 4];
|
|
908
|
+
case "uint32":
|
|
909
|
+
case "uint":
|
|
910
|
+
return [dataview.getUint32(at, littleEndian), 4];
|
|
911
|
+
case "float32":
|
|
912
|
+
case "float":
|
|
913
|
+
return [dataview.getFloat32(at, littleEndian), 4];
|
|
914
|
+
case "float64":
|
|
915
|
+
case "double":
|
|
916
|
+
return [dataview.getFloat64(at, littleEndian), 8];
|
|
917
|
+
default:
|
|
918
|
+
throw new Error(type);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
function binaryReadElement(dataview, at, properties, littleEndian) {
|
|
922
|
+
const element = {};
|
|
923
|
+
let result;
|
|
924
|
+
let read = 0;
|
|
925
|
+
for (let i = 0; i < properties.length; i++) {
|
|
926
|
+
if (properties[i].type === "list") {
|
|
927
|
+
const list = [];
|
|
928
|
+
result = binaryRead(dataview, at + read, properties[i].countType, littleEndian);
|
|
929
|
+
const n = result[0];
|
|
930
|
+
read += result[1];
|
|
931
|
+
for (let j = 0; j < n; j++) {
|
|
932
|
+
result = binaryRead(dataview, at + read, properties[i].itemType, littleEndian);
|
|
933
|
+
list.push(result[0]);
|
|
934
|
+
read += result[1];
|
|
935
|
+
}
|
|
936
|
+
element[properties[i].name] = list;
|
|
937
|
+
} else {
|
|
938
|
+
result = binaryRead(dataview, at + read, properties[i].type, littleEndian);
|
|
939
|
+
element[properties[i].name] = result[0];
|
|
940
|
+
read += result[1];
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
return [element, read];
|
|
944
|
+
}
|
|
945
|
+
function parseBinary(data, header) {
|
|
946
|
+
const attributes = {
|
|
947
|
+
indices: [],
|
|
948
|
+
vertices: [],
|
|
949
|
+
normals: [],
|
|
950
|
+
uvs: [],
|
|
951
|
+
colors: []
|
|
952
|
+
};
|
|
953
|
+
const littleEndian = header.format === "binary_little_endian";
|
|
954
|
+
const body = new DataView(data, header.headerLength);
|
|
955
|
+
let result;
|
|
956
|
+
let loc = 0;
|
|
957
|
+
for (let currentElement2 = 0; currentElement2 < header.elements.length; currentElement2++) {
|
|
958
|
+
const count = header.elements[currentElement2].count;
|
|
959
|
+
for (let currentElementCount = 0; currentElementCount < count; currentElementCount++) {
|
|
960
|
+
result = binaryReadElement(body, loc, header.elements[currentElement2].properties, littleEndian);
|
|
961
|
+
loc += result[1];
|
|
962
|
+
const element = result[0];
|
|
963
|
+
handleElement(attributes, header.elements[currentElement2].name, element);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
return attributes;
|
|
967
|
+
}
|
|
968
|
+
var init_parse_ply = __esm({
|
|
969
|
+
"src/lib/parse-ply.ts"() {
|
|
970
|
+
init_normalize_ply();
|
|
971
|
+
}
|
|
972
|
+
});
|
|
973
|
+
|
|
974
|
+
// ../loader-utils/src/lib/iterators/text-iterators.ts
|
|
975
|
+
async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
|
|
976
|
+
const textDecoder = new TextDecoder(void 0, options);
|
|
977
|
+
for await (const arrayBuffer of arrayBufferIterator) {
|
|
978
|
+
yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder.decode(arrayBuffer, { stream: true });
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
async function* makeLineIterator(textIterator) {
|
|
982
|
+
let previous = "";
|
|
983
|
+
for await (const textChunk of textIterator) {
|
|
984
|
+
previous += textChunk;
|
|
985
|
+
let eolIndex;
|
|
986
|
+
while ((eolIndex = previous.indexOf("\n")) >= 0) {
|
|
987
|
+
const line = previous.slice(0, eolIndex + 1);
|
|
988
|
+
previous = previous.slice(eolIndex + 1);
|
|
989
|
+
yield line;
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
if (previous.length > 0) {
|
|
993
|
+
yield previous;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
var init_text_iterators = __esm({
|
|
997
|
+
"../loader-utils/src/lib/iterators/text-iterators.ts"() {
|
|
998
|
+
}
|
|
999
|
+
});
|
|
1000
|
+
|
|
1001
|
+
// ../loader-utils/src/lib/iterators/async-iteration.ts
|
|
1002
|
+
async function forEach(iterator, visitor) {
|
|
1003
|
+
while (true) {
|
|
1004
|
+
const { done, value } = await iterator.next();
|
|
1005
|
+
if (done) {
|
|
1006
|
+
iterator.return();
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
const cancel = visitor(value);
|
|
1010
|
+
if (cancel) {
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
var init_async_iteration = __esm({
|
|
1016
|
+
"../loader-utils/src/lib/iterators/async-iteration.ts"() {
|
|
1017
|
+
}
|
|
1018
|
+
});
|
|
1019
|
+
|
|
1020
|
+
// ../loader-utils/src/index.ts
|
|
1021
|
+
var init_src2 = __esm({
|
|
1022
|
+
"../loader-utils/src/index.ts"() {
|
|
1023
|
+
init_text_iterators();
|
|
1024
|
+
init_async_iteration();
|
|
1025
|
+
}
|
|
1026
|
+
});
|
|
1027
|
+
|
|
1028
|
+
// src/lib/parse-ply-in-batches.ts
|
|
1029
|
+
async function* parsePLYInBatches(iterator, options) {
|
|
1030
|
+
const lineIterator = makeLineIterator(makeTextDecoderIterator(iterator));
|
|
1031
|
+
const header = await parsePLYHeader(lineIterator, options);
|
|
1032
|
+
let attributes;
|
|
1033
|
+
switch (header.format) {
|
|
1034
|
+
case "ascii":
|
|
1035
|
+
attributes = await parseASCII2(lineIterator, header);
|
|
1036
|
+
break;
|
|
1037
|
+
default:
|
|
1038
|
+
throw new Error("Binary PLY can not yet be parsed in streaming mode");
|
|
1039
|
+
}
|
|
1040
|
+
yield normalizePLY(header, attributes, options);
|
|
1041
|
+
}
|
|
1042
|
+
async function parsePLYHeader(lineIterator, options) {
|
|
1043
|
+
const header = {
|
|
1044
|
+
comments: [],
|
|
1045
|
+
elements: []
|
|
1046
|
+
};
|
|
1047
|
+
await forEach(lineIterator, (line) => {
|
|
1048
|
+
line = line.trim();
|
|
1049
|
+
if (line === "end_header") {
|
|
1050
|
+
return true;
|
|
1051
|
+
}
|
|
1052
|
+
if (line === "") {
|
|
1053
|
+
return false;
|
|
1054
|
+
}
|
|
1055
|
+
const lineValues = line.split(/\s+/);
|
|
1056
|
+
const lineType = lineValues.shift();
|
|
1057
|
+
line = lineValues.join(" ");
|
|
1058
|
+
switch (lineType) {
|
|
1059
|
+
case "ply":
|
|
1060
|
+
break;
|
|
1061
|
+
case "format":
|
|
1062
|
+
header.format = lineValues[0];
|
|
1063
|
+
header.version = lineValues[1];
|
|
1064
|
+
break;
|
|
1065
|
+
case "comment":
|
|
1066
|
+
header.comments.push(line);
|
|
1067
|
+
break;
|
|
1068
|
+
case "element":
|
|
1069
|
+
if (currentElement) {
|
|
1070
|
+
header.elements.push(currentElement);
|
|
1071
|
+
}
|
|
1072
|
+
currentElement = {
|
|
1073
|
+
name: lineValues[0],
|
|
1074
|
+
count: parseInt(lineValues[1], 10),
|
|
1075
|
+
properties: []
|
|
1076
|
+
};
|
|
1077
|
+
break;
|
|
1078
|
+
case "property":
|
|
1079
|
+
const property = makePLYElementProperty2(lineValues, options.propertyNameMapping);
|
|
1080
|
+
currentElement.properties.push(property);
|
|
1081
|
+
break;
|
|
1082
|
+
default:
|
|
1083
|
+
console.log("unhandled", lineType, lineValues);
|
|
1084
|
+
}
|
|
1085
|
+
return false;
|
|
1086
|
+
});
|
|
1087
|
+
if (currentElement) {
|
|
1088
|
+
header.elements.push(currentElement);
|
|
1089
|
+
}
|
|
1090
|
+
return header;
|
|
1091
|
+
}
|
|
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];
|
|
1105
|
+
}
|
|
1106
|
+
return property;
|
|
1107
|
+
}
|
|
1108
|
+
async function parseASCII2(lineIterator, header) {
|
|
1109
|
+
const attributes = {
|
|
1110
|
+
indices: [],
|
|
1111
|
+
vertices: [],
|
|
1112
|
+
normals: [],
|
|
1113
|
+
uvs: [],
|
|
1114
|
+
colors: []
|
|
1115
|
+
};
|
|
1116
|
+
let currentElement2 = 0;
|
|
1117
|
+
let currentElementCount = 0;
|
|
1118
|
+
for await (let line of lineIterator) {
|
|
1119
|
+
line = line.trim();
|
|
1120
|
+
if (line !== "") {
|
|
1121
|
+
if (currentElementCount >= header.elements[currentElement2].count) {
|
|
1122
|
+
currentElement2++;
|
|
1123
|
+
currentElementCount = 0;
|
|
1124
|
+
}
|
|
1125
|
+
const element = parseASCIIElement2(header.elements[currentElement2].properties, line);
|
|
1126
|
+
handleElement2(attributes, header.elements[currentElement2].name, element);
|
|
1127
|
+
currentElementCount++;
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
return attributes;
|
|
1131
|
+
}
|
|
1132
|
+
function parseASCIINumber2(n, type) {
|
|
1133
|
+
switch (type) {
|
|
1134
|
+
case "char":
|
|
1135
|
+
case "uchar":
|
|
1136
|
+
case "short":
|
|
1137
|
+
case "ushort":
|
|
1138
|
+
case "int":
|
|
1139
|
+
case "uint":
|
|
1140
|
+
case "int8":
|
|
1141
|
+
case "uint8":
|
|
1142
|
+
case "int16":
|
|
1143
|
+
case "uint16":
|
|
1144
|
+
case "int32":
|
|
1145
|
+
case "uint32":
|
|
1146
|
+
return parseInt(n, 10);
|
|
1147
|
+
case "float":
|
|
1148
|
+
case "double":
|
|
1149
|
+
case "float32":
|
|
1150
|
+
case "float64":
|
|
1151
|
+
return parseFloat(n);
|
|
1152
|
+
default:
|
|
1153
|
+
throw new Error(type);
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
function parseASCIIElement2(properties, line) {
|
|
1157
|
+
const values = line.split(/\s+/);
|
|
1158
|
+
const element = {};
|
|
1159
|
+
for (let i = 0; i < properties.length; i++) {
|
|
1160
|
+
if (properties[i].type === "list") {
|
|
1161
|
+
const list = [];
|
|
1162
|
+
const n = parseASCIINumber2(values.shift(), properties[i].countType);
|
|
1163
|
+
for (let j = 0; j < n; j++) {
|
|
1164
|
+
list.push(parseASCIINumber2(values.shift(), properties[i].itemType));
|
|
1165
|
+
}
|
|
1166
|
+
element[properties[i].name] = list;
|
|
1167
|
+
} else {
|
|
1168
|
+
element[properties[i].name] = parseASCIINumber2(values.shift(), properties[i].type);
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
return element;
|
|
1172
|
+
}
|
|
1173
|
+
function handleElement2(buffer, elementName, element = {}) {
|
|
1174
|
+
switch (elementName) {
|
|
1175
|
+
case "vertex":
|
|
1176
|
+
buffer.vertices.push(element.x, element.y, element.z);
|
|
1177
|
+
if ("nx" in element && "ny" in element && "nz" in element) {
|
|
1178
|
+
buffer.normals.push(element.nx, element.ny, element.nz);
|
|
1179
|
+
}
|
|
1180
|
+
if ("s" in element && "t" in element) {
|
|
1181
|
+
buffer.uvs.push(element.s, element.t);
|
|
1182
|
+
}
|
|
1183
|
+
if ("red" in element && "green" in element && "blue" in element) {
|
|
1184
|
+
buffer.colors.push(element.red / 255, element.green / 255, element.blue / 255);
|
|
1185
|
+
}
|
|
1186
|
+
break;
|
|
1187
|
+
case "face":
|
|
1188
|
+
const vertexIndices = element.vertex_indices || element.vertex_index;
|
|
1189
|
+
if (vertexIndices.length === 3) {
|
|
1190
|
+
buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[2]);
|
|
1191
|
+
} else if (vertexIndices.length === 4) {
|
|
1192
|
+
buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[3]);
|
|
1193
|
+
buffer.indices.push(vertexIndices[1], vertexIndices[2], vertexIndices[3]);
|
|
1194
|
+
}
|
|
1195
|
+
break;
|
|
1196
|
+
default:
|
|
1197
|
+
break;
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
var currentElement;
|
|
1201
|
+
var init_parse_ply_in_batches = __esm({
|
|
1202
|
+
"src/lib/parse-ply-in-batches.ts"() {
|
|
1203
|
+
init_src2();
|
|
1204
|
+
init_normalize_ply();
|
|
1205
|
+
}
|
|
1206
|
+
});
|
|
1207
|
+
|
|
1208
|
+
// src/index.ts
|
|
1209
|
+
var src_exports = {};
|
|
1210
|
+
__export(src_exports, {
|
|
1211
|
+
PLYLoader: () => PLYLoader2,
|
|
1212
|
+
PLYWorkerLoader: () => PLYLoader,
|
|
1213
|
+
_typecheckPLYLoader: () => _typecheckPLYLoader
|
|
1214
|
+
});
|
|
1215
|
+
var PLYLoader2, _typecheckPLYLoader;
|
|
1216
|
+
var init_src3 = __esm({
|
|
1217
|
+
"src/index.ts"() {
|
|
1218
|
+
init_ply_loader();
|
|
1219
|
+
init_parse_ply();
|
|
1220
|
+
init_parse_ply_in_batches();
|
|
1221
|
+
PLYLoader2 = {
|
|
1222
|
+
...PLYLoader,
|
|
1223
|
+
parse: async (arrayBuffer, options) => parsePLY(arrayBuffer, options),
|
|
1224
|
+
parseTextSync: parsePLY,
|
|
1225
|
+
parseSync: parsePLY,
|
|
1226
|
+
parseInBatches: parsePLYInBatches
|
|
1227
|
+
};
|
|
1228
|
+
_typecheckPLYLoader = PLYLoader2;
|
|
1229
|
+
}
|
|
1230
|
+
});
|
|
1231
|
+
|
|
1232
|
+
// src/bundle.ts
|
|
1233
|
+
var require_bundle = __commonJS({
|
|
1234
|
+
"src/bundle.ts"(exports, module) {
|
|
1235
|
+
var moduleExports = (init_src3(), src_exports);
|
|
1236
|
+
globalThis.loaders = globalThis.loaders || {};
|
|
1237
|
+
module.exports = Object.assign(globalThis.loaders, moduleExports);
|
|
1238
|
+
}
|
|
1239
|
+
});
|
|
1240
|
+
require_bundle();
|
|
1241
|
+
})();
|