minidraco 0.2.0 → 0.3.0
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/README.md +38 -100
- package/dist/index.d.ts +1 -98
- package/dist/index.js +1405 -1421
- package/dist/three.d.ts +6 -6
- package/dist/three.js +1417 -1429
- package/dist/worker.js +1406 -1419
- package/package.json +1 -1
package/dist/three.js
CHANGED
|
@@ -10,334 +10,158 @@ import {
|
|
|
10
10
|
SRGBColorSpace
|
|
11
11
|
} from "three";
|
|
12
12
|
|
|
13
|
-
// src/decoder/core/
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
// src/decoder/core/DracoTypes.ts
|
|
14
|
+
var DataType = {
|
|
15
|
+
INVALID: 0,
|
|
16
|
+
INT8: 1,
|
|
17
|
+
UINT8: 2,
|
|
18
|
+
INT16: 3,
|
|
19
|
+
UINT16: 4,
|
|
20
|
+
INT32: 5,
|
|
21
|
+
UINT32: 6,
|
|
22
|
+
INT64: 7,
|
|
23
|
+
UINT64: 8,
|
|
24
|
+
FLOAT32: 9,
|
|
25
|
+
FLOAT64: 10,
|
|
26
|
+
BOOL: 11,
|
|
27
|
+
TYPES_COUNT: 12
|
|
28
|
+
};
|
|
29
|
+
function dataTypeLength(dt) {
|
|
30
|
+
switch (dt) {
|
|
31
|
+
case DataType.INT8:
|
|
32
|
+
case DataType.UINT8:
|
|
33
|
+
return 1;
|
|
34
|
+
case DataType.INT16:
|
|
35
|
+
case DataType.UINT16:
|
|
36
|
+
return 2;
|
|
37
|
+
case DataType.INT32:
|
|
38
|
+
case DataType.UINT32:
|
|
39
|
+
return 4;
|
|
40
|
+
case DataType.INT64:
|
|
41
|
+
case DataType.UINT64:
|
|
42
|
+
return 8;
|
|
43
|
+
case DataType.FLOAT32:
|
|
44
|
+
return 4;
|
|
45
|
+
case DataType.FLOAT64:
|
|
46
|
+
return 8;
|
|
47
|
+
case DataType.BOOL:
|
|
48
|
+
return 1;
|
|
49
|
+
default:
|
|
50
|
+
return -1;
|
|
51
|
+
}
|
|
16
52
|
}
|
|
17
53
|
|
|
18
|
-
// src/decoder/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
54
|
+
// src/decoder/attributes/GeometryAttribute.ts
|
|
55
|
+
var Type = {
|
|
56
|
+
INVALID: -1,
|
|
57
|
+
POSITION: 0,
|
|
58
|
+
NORMAL: 1,
|
|
59
|
+
COLOR: 2,
|
|
60
|
+
TEX_COORD: 3,
|
|
61
|
+
GENERIC: 4,
|
|
62
|
+
NAMED_ATTRIBUTES_COUNT: 5
|
|
63
|
+
};
|
|
64
|
+
var GeometryAttribute = class {
|
|
65
|
+
_buffer;
|
|
66
|
+
_numComponents;
|
|
67
|
+
_dataType;
|
|
68
|
+
_normalized;
|
|
69
|
+
_byteStride;
|
|
70
|
+
_byteOffset;
|
|
71
|
+
_attributeType;
|
|
72
|
+
_uniqueId;
|
|
73
|
+
constructor() {
|
|
74
|
+
this._buffer = null;
|
|
75
|
+
this._numComponents = 1;
|
|
76
|
+
this._dataType = DataType.FLOAT32;
|
|
77
|
+
this._normalized = false;
|
|
78
|
+
this._byteStride = 0;
|
|
79
|
+
this._byteOffset = 0;
|
|
80
|
+
this._attributeType = Type.INVALID;
|
|
81
|
+
this._uniqueId = 0;
|
|
23
82
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
83
|
+
init(attributeType, buffer, numComponents, dataType, normalized, byteStride, byteOffset) {
|
|
84
|
+
this._buffer = buffer;
|
|
85
|
+
this._numComponents = numComponents;
|
|
86
|
+
this._dataType = dataType;
|
|
87
|
+
this._normalized = normalized;
|
|
88
|
+
this._byteStride = byteStride;
|
|
89
|
+
this._byteOffset = byteOffset;
|
|
90
|
+
this._attributeType = attributeType;
|
|
30
91
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (next & 128) {
|
|
47
|
-
bytes.push(next & 127);
|
|
48
|
-
} else {
|
|
49
|
-
bytes.push(next);
|
|
50
|
-
done = true;
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
if (!done) return void 0;
|
|
55
|
-
result = bytes[bytes.length - 1];
|
|
56
|
-
for (let k = bytes.length - 2; k >= 0; k--) {
|
|
57
|
-
result = result * 128 + bytes[k];
|
|
58
|
-
}
|
|
59
|
-
return result;
|
|
92
|
+
// Returns a Uint8Array view of the buffer starting at the attribute entry.
|
|
93
|
+
getAddress(attIndex) {
|
|
94
|
+
const bytePos = this._byteOffset + this._byteStride * attIndex;
|
|
95
|
+
return this._buffer.data.subarray(bytePos);
|
|
96
|
+
}
|
|
97
|
+
copyFrom(srcAtt) {
|
|
98
|
+
this._numComponents = srcAtt._numComponents;
|
|
99
|
+
this._dataType = srcAtt._dataType;
|
|
100
|
+
this._normalized = srcAtt._normalized;
|
|
101
|
+
this._byteStride = srcAtt._byteStride;
|
|
102
|
+
this._byteOffset = srcAtt._byteOffset;
|
|
103
|
+
this._attributeType = srcAtt._attributeType;
|
|
104
|
+
this._uniqueId = srcAtt._uniqueId;
|
|
105
|
+
if (srcAtt._buffer === null) {
|
|
106
|
+
this._buffer = null;
|
|
60
107
|
} else {
|
|
61
|
-
|
|
108
|
+
if (this._buffer === null) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
this._buffer.update(srcAtt._buffer.data, srcAtt._buffer.dataSize);
|
|
62
112
|
}
|
|
113
|
+
return true;
|
|
63
114
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const value = decodeVarintUnsigned(buffer, maxBytes);
|
|
69
|
-
if (value === void 0) return void 0;
|
|
70
|
-
if (signed) {
|
|
71
|
-
return convertSymbolToSignedInt(value);
|
|
115
|
+
resetBuffer(buffer, byteStride, byteOffset) {
|
|
116
|
+
this._buffer = buffer;
|
|
117
|
+
this._byteStride = byteStride;
|
|
118
|
+
this._byteOffset = byteOffset;
|
|
72
119
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
// src/decoder/core/DecoderBuffer.ts
|
|
77
|
-
var BitDecoder = class {
|
|
78
|
-
_bitBuffer;
|
|
79
|
-
_bitOffset;
|
|
80
|
-
_byteLength;
|
|
81
|
-
constructor() {
|
|
82
|
-
this._bitBuffer = null;
|
|
83
|
-
this._bitOffset = 0;
|
|
84
|
-
this._byteLength = 0;
|
|
120
|
+
get attributeType() {
|
|
121
|
+
return this._attributeType;
|
|
85
122
|
}
|
|
86
|
-
|
|
87
|
-
this.
|
|
88
|
-
this._byteLength = byteLength;
|
|
89
|
-
this._bitOffset = 0;
|
|
123
|
+
get dataType() {
|
|
124
|
+
return this._dataType;
|
|
90
125
|
}
|
|
91
|
-
|
|
92
|
-
return this.
|
|
126
|
+
get numComponents() {
|
|
127
|
+
return this._numComponents;
|
|
93
128
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
} else {
|
|
109
|
-
result = val >>> bitShift;
|
|
110
|
-
}
|
|
111
|
-
this._bitOffset = off + nbits;
|
|
112
|
-
return nbits === 32 ? result : result & (1 << nbits) - 1;
|
|
113
|
-
}
|
|
114
|
-
let value = 0;
|
|
115
|
-
let bitsRead = 0;
|
|
116
|
-
let currOff = off;
|
|
117
|
-
while (bitsRead < nbits) {
|
|
118
|
-
const bOff = currOff >> 3;
|
|
119
|
-
if (bOff >= this._byteLength) break;
|
|
120
|
-
const bShift = currOff & 7;
|
|
121
|
-
const bitsAvail = 8 - bShift;
|
|
122
|
-
const bitsNeeded = nbits - bitsRead;
|
|
123
|
-
const bitsToRead = bitsAvail < bitsNeeded ? bitsAvail : bitsNeeded;
|
|
124
|
-
const mask = (1 << bitsToRead) - 1;
|
|
125
|
-
value |= (buf[bOff] >> bShift & mask) << bitsRead;
|
|
126
|
-
bitsRead += bitsToRead;
|
|
127
|
-
currOff += bitsToRead;
|
|
128
|
-
}
|
|
129
|
-
this._bitOffset = currOff;
|
|
130
|
-
return value;
|
|
129
|
+
get buffer() {
|
|
130
|
+
return this._buffer;
|
|
131
|
+
}
|
|
132
|
+
get byteStride() {
|
|
133
|
+
return this._byteStride;
|
|
134
|
+
}
|
|
135
|
+
get byteOffset() {
|
|
136
|
+
return this._byteOffset;
|
|
137
|
+
}
|
|
138
|
+
get uniqueId() {
|
|
139
|
+
return this._uniqueId;
|
|
140
|
+
}
|
|
141
|
+
set uniqueId(id) {
|
|
142
|
+
this._uniqueId = id;
|
|
131
143
|
}
|
|
132
144
|
};
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
_bitstreamVersion;
|
|
145
|
+
|
|
146
|
+
// src/decoder/point_cloud/PointCloud.ts
|
|
147
|
+
var NAMED_ATTRIBUTES_COUNT = 8;
|
|
148
|
+
var PointCloud = class {
|
|
149
|
+
num_points_;
|
|
150
|
+
attributes_;
|
|
151
|
+
named_attribute_index_;
|
|
141
152
|
constructor() {
|
|
142
|
-
this.
|
|
143
|
-
this.
|
|
144
|
-
this.
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
this._bitMode = false;
|
|
148
|
-
this._bitstreamVersion = 0;
|
|
149
|
-
}
|
|
150
|
-
init(data, dataSize, version) {
|
|
151
|
-
if (data instanceof ArrayBuffer) {
|
|
152
|
-
this._data = new Uint8Array(data);
|
|
153
|
-
} else if (data instanceof Uint8Array) {
|
|
154
|
-
this._data = data;
|
|
155
|
-
} else {
|
|
156
|
-
this._data = new Uint8Array(data);
|
|
153
|
+
this.num_points_ = 0;
|
|
154
|
+
this.attributes_ = [];
|
|
155
|
+
this.named_attribute_index_ = [];
|
|
156
|
+
for (let i = 0; i < NAMED_ATTRIBUTES_COUNT; ++i) {
|
|
157
|
+
this.named_attribute_index_.push([]);
|
|
157
158
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
this._bitstreamVersion = version;
|
|
159
|
+
}
|
|
160
|
+
numNamedAttributes(type) {
|
|
161
|
+
if (type < 0 || type >= NAMED_ATTRIBUTES_COUNT) {
|
|
162
|
+
return 0;
|
|
163
163
|
}
|
|
164
|
-
|
|
165
|
-
// Typed little-endian reads.
|
|
166
|
-
decodeUint8() {
|
|
167
|
-
if (this._pos + 1 > this._dataSize) return void 0;
|
|
168
|
-
const val = this._data[this._pos];
|
|
169
|
-
this._pos += 1;
|
|
170
|
-
return val;
|
|
171
|
-
}
|
|
172
|
-
decodeInt8() {
|
|
173
|
-
if (this._pos + 1 > this._dataSize) return void 0;
|
|
174
|
-
const val = this._dataView.getInt8(this._pos);
|
|
175
|
-
this._pos += 1;
|
|
176
|
-
return val;
|
|
177
|
-
}
|
|
178
|
-
decodeUint16() {
|
|
179
|
-
if (this._pos + 2 > this._dataSize) return void 0;
|
|
180
|
-
const val = this._dataView.getUint16(this._pos, true);
|
|
181
|
-
this._pos += 2;
|
|
182
|
-
return val;
|
|
183
|
-
}
|
|
184
|
-
decodeUint32() {
|
|
185
|
-
if (this._pos + 4 > this._dataSize) return void 0;
|
|
186
|
-
const val = this._dataView.getUint32(this._pos, true);
|
|
187
|
-
this._pos += 4;
|
|
188
|
-
return val;
|
|
189
|
-
}
|
|
190
|
-
decodeInt32() {
|
|
191
|
-
if (this._pos + 4 > this._dataSize) return void 0;
|
|
192
|
-
const val = this._dataView.getInt32(this._pos, true);
|
|
193
|
-
this._pos += 4;
|
|
194
|
-
return val;
|
|
195
|
-
}
|
|
196
|
-
decodeFloat32() {
|
|
197
|
-
if (this._pos + 4 > this._dataSize) return void 0;
|
|
198
|
-
const val = this._dataView.getFloat32(this._pos, true);
|
|
199
|
-
this._pos += 4;
|
|
200
|
-
return val;
|
|
201
|
-
}
|
|
202
|
-
decodeUint64() {
|
|
203
|
-
if (this._pos + 8 > this._dataSize) return void 0;
|
|
204
|
-
const lo = this._dataView.getUint32(this._pos, true);
|
|
205
|
-
const hi = this._dataView.getUint32(this._pos + 4, true);
|
|
206
|
-
this._pos += 8;
|
|
207
|
-
return hi * 4294967296 + lo;
|
|
208
|
-
}
|
|
209
|
-
decodeBytes(size) {
|
|
210
|
-
if (this._pos + size > this._dataSize) return void 0;
|
|
211
|
-
const result = this._data.slice(this._pos, this._pos + size);
|
|
212
|
-
this._pos += size;
|
|
213
|
-
return result;
|
|
214
|
-
}
|
|
215
|
-
// Zero-copy variant of decodeBytes: a view into the stream, only valid until
|
|
216
|
-
// the caller's next chance to mutate the buffer — copy out before keeping it.
|
|
217
|
-
decodeBytesView(size) {
|
|
218
|
-
if (this._pos + size > this._dataSize) return void 0;
|
|
219
|
-
const result = this._data.subarray(this._pos, this._pos + size);
|
|
220
|
-
this._pos += size;
|
|
221
|
-
return result;
|
|
222
|
-
}
|
|
223
|
-
startBitDecoding(decodeSize) {
|
|
224
|
-
let outSize = 0;
|
|
225
|
-
if (decodeSize) {
|
|
226
|
-
if (this._bitstreamVersion < bitstreamVersion(2, 2)) {
|
|
227
|
-
outSize = this.decodeUint64();
|
|
228
|
-
if (outSize === void 0) return void 0;
|
|
229
|
-
} else {
|
|
230
|
-
outSize = decodeVarint(this, false);
|
|
231
|
-
if (outSize === void 0) return void 0;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
this._bitMode = true;
|
|
235
|
-
this._bitDecoder.reset(this._data.subarray(this._pos), this._dataSize - this._pos);
|
|
236
|
-
return outSize;
|
|
237
|
-
}
|
|
238
|
-
endBitDecoding() {
|
|
239
|
-
this._bitMode = false;
|
|
240
|
-
const bitsDecoded = this._bitDecoder.bitsDecoded();
|
|
241
|
-
const bytesDecoded = Math.ceil(bitsDecoded / 8);
|
|
242
|
-
this._pos += bytesDecoded;
|
|
243
|
-
}
|
|
244
|
-
decodeLeastSignificantBits32(nbits) {
|
|
245
|
-
if (!this._bitMode) return void 0;
|
|
246
|
-
return this._bitDecoder.getBits(nbits);
|
|
247
|
-
}
|
|
248
|
-
decodeVarintUint32() {
|
|
249
|
-
return decodeVarint(this, false);
|
|
250
|
-
}
|
|
251
|
-
decodeVarintUint64() {
|
|
252
|
-
return decodeVarint(this, false);
|
|
253
|
-
}
|
|
254
|
-
advance(bytes) {
|
|
255
|
-
this._pos += bytes;
|
|
256
|
-
}
|
|
257
|
-
get bitstreamVersion() {
|
|
258
|
-
return this._bitstreamVersion;
|
|
259
|
-
}
|
|
260
|
-
set bitstreamVersion(v) {
|
|
261
|
-
this._bitstreamVersion = v;
|
|
262
|
-
}
|
|
263
|
-
get data() {
|
|
264
|
-
return this._data;
|
|
265
|
-
}
|
|
266
|
-
get dataHead() {
|
|
267
|
-
return this._data.subarray(this._pos);
|
|
268
|
-
}
|
|
269
|
-
get remainingSize() {
|
|
270
|
-
return this._dataSize - this._pos;
|
|
271
|
-
}
|
|
272
|
-
get decodedSize() {
|
|
273
|
-
return this._pos;
|
|
274
|
-
}
|
|
275
|
-
get bitDecoderActive() {
|
|
276
|
-
return this._bitMode;
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
// src/decoder/core/ScratchArena.ts
|
|
281
|
-
var freeInt32 = [];
|
|
282
|
-
var freeUint8 = [];
|
|
283
|
-
var borrowedInt32 = [];
|
|
284
|
-
var borrowedUint8 = [];
|
|
285
|
-
var acquire = (free, borrowed, size) => {
|
|
286
|
-
for (let i = free.length - 1; i >= 0; --i) {
|
|
287
|
-
const buffer = free[i];
|
|
288
|
-
if (buffer.length >= size) {
|
|
289
|
-
free[i] = free[free.length - 1];
|
|
290
|
-
free.pop();
|
|
291
|
-
borrowed.push(buffer);
|
|
292
|
-
return buffer;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
return null;
|
|
296
|
-
};
|
|
297
|
-
var scratchInt32 = (size) => {
|
|
298
|
-
const pooled = acquire(freeInt32, borrowedInt32, size);
|
|
299
|
-
if (pooled !== null) return pooled.subarray(0, size);
|
|
300
|
-
const fresh = new Int32Array(size);
|
|
301
|
-
borrowedInt32.push(fresh);
|
|
302
|
-
return fresh;
|
|
303
|
-
};
|
|
304
|
-
var scratchUint8Zeroed = (size) => {
|
|
305
|
-
const pooled = acquire(freeUint8, borrowedUint8, size);
|
|
306
|
-
if (pooled !== null) {
|
|
307
|
-
const view = pooled.subarray(0, size);
|
|
308
|
-
view.fill(0);
|
|
309
|
-
return view;
|
|
310
|
-
}
|
|
311
|
-
const fresh = new Uint8Array(size);
|
|
312
|
-
borrowedUint8.push(fresh);
|
|
313
|
-
return fresh;
|
|
314
|
-
};
|
|
315
|
-
var releaseScratch = () => {
|
|
316
|
-
for (const buffer of borrowedInt32) freeInt32.push(buffer);
|
|
317
|
-
for (const buffer of borrowedUint8) freeUint8.push(buffer);
|
|
318
|
-
borrowedInt32.length = 0;
|
|
319
|
-
borrowedUint8.length = 0;
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
// src/decoder/point_cloud/PointCloud.ts
|
|
323
|
-
var NAMED_ATTRIBUTES_COUNT = 8;
|
|
324
|
-
var PointCloud = class {
|
|
325
|
-
num_points_;
|
|
326
|
-
attributes_;
|
|
327
|
-
named_attribute_index_;
|
|
328
|
-
constructor() {
|
|
329
|
-
this.num_points_ = 0;
|
|
330
|
-
this.attributes_ = [];
|
|
331
|
-
this.named_attribute_index_ = [];
|
|
332
|
-
for (let i = 0; i < NAMED_ATTRIBUTES_COUNT; ++i) {
|
|
333
|
-
this.named_attribute_index_.push([]);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
numNamedAttributes(type) {
|
|
337
|
-
if (type < 0 || type >= NAMED_ATTRIBUTES_COUNT) {
|
|
338
|
-
return 0;
|
|
339
|
-
}
|
|
340
|
-
return this.named_attribute_index_[type].length;
|
|
164
|
+
return this.named_attribute_index_[type].length;
|
|
341
165
|
}
|
|
342
166
|
getNamedAttributeId(type, i) {
|
|
343
167
|
if (i === void 0) i = 0;
|
|
@@ -447,1237 +271,1401 @@ var Mesh = class extends PointCloud {
|
|
|
447
271
|
}
|
|
448
272
|
};
|
|
449
273
|
|
|
450
|
-
// src/decoder/
|
|
451
|
-
var
|
|
452
|
-
|
|
453
|
-
var kDracoMeshBitstreamVersionMajor = 2;
|
|
454
|
-
var kDracoMeshBitstreamVersionMinor = 2;
|
|
455
|
-
function DRACO_BITSTREAM_VERSION(major, minor) {
|
|
456
|
-
return major << 8 | minor;
|
|
457
|
-
}
|
|
458
|
-
var EncodedGeometryType = {
|
|
459
|
-
INVALID_GEOMETRY_TYPE: -1,
|
|
460
|
-
POINT_CLOUD: 0,
|
|
461
|
-
TRIANGULAR_MESH: 1,
|
|
462
|
-
NUM_ENCODED_GEOMETRY_TYPES: 2
|
|
463
|
-
};
|
|
464
|
-
var MeshEncoderMethod = {
|
|
465
|
-
MESH_SEQUENTIAL_ENCODING: 0,
|
|
466
|
-
MESH_EDGEBREAKER_ENCODING: 1
|
|
467
|
-
};
|
|
468
|
-
var SequentialAttributeEncoderType = {
|
|
469
|
-
SEQUENTIAL_ATTRIBUTE_ENCODER_GENERIC: 0,
|
|
470
|
-
SEQUENTIAL_ATTRIBUTE_ENCODER_INTEGER: 1,
|
|
471
|
-
SEQUENTIAL_ATTRIBUTE_ENCODER_QUANTIZATION: 2,
|
|
472
|
-
SEQUENTIAL_ATTRIBUTE_ENCODER_NORMALS: 3
|
|
473
|
-
};
|
|
474
|
-
var PredictionSchemeMethod = {
|
|
475
|
-
PREDICTION_NONE: -2,
|
|
476
|
-
PREDICTION_UNDEFINED: -1,
|
|
477
|
-
PREDICTION_DIFFERENCE: 0,
|
|
478
|
-
MESH_PREDICTION_PARALLELOGRAM: 1,
|
|
479
|
-
MESH_PREDICTION_MULTI_PARALLELOGRAM: 2,
|
|
480
|
-
MESH_PREDICTION_TEX_COORDS_DEPRECATED: 3,
|
|
481
|
-
MESH_PREDICTION_CONSTRAINED_MULTI_PARALLELOGRAM: 4,
|
|
482
|
-
MESH_PREDICTION_TEX_COORDS_PORTABLE: 5,
|
|
483
|
-
MESH_PREDICTION_GEOMETRIC_NORMAL: 6,
|
|
484
|
-
NUM_PREDICTION_SCHEMES: 7
|
|
485
|
-
};
|
|
486
|
-
var PredictionSchemeTransformType = {
|
|
487
|
-
PREDICTION_TRANSFORM_NONE: -1,
|
|
488
|
-
PREDICTION_TRANSFORM_DELTA: 0,
|
|
489
|
-
PREDICTION_TRANSFORM_WRAP: 1,
|
|
490
|
-
PREDICTION_TRANSFORM_NORMAL_OCTAHEDRON: 2,
|
|
491
|
-
PREDICTION_TRANSFORM_NORMAL_OCTAHEDRON_CANONICALIZED: 3,
|
|
492
|
-
NUM_PREDICTION_SCHEME_TRANSFORM_TYPES: 4
|
|
493
|
-
};
|
|
494
|
-
var MeshTraversalMethod = {
|
|
495
|
-
MESH_TRAVERSAL_DEPTH_FIRST: 0,
|
|
496
|
-
MESH_TRAVERSAL_PREDICTION_DEGREE: 1,
|
|
497
|
-
NUM_TRAVERSAL_METHODS: 2
|
|
498
|
-
};
|
|
499
|
-
var MeshEdgebreakerConnectivityEncodingMethod = {
|
|
500
|
-
MESH_EDGEBREAKER_STANDARD_ENCODING: 0,
|
|
501
|
-
MESH_EDGEBREAKER_PREDICTIVE_ENCODING: 1,
|
|
502
|
-
// Deprecated.
|
|
503
|
-
MESH_EDGEBREAKER_VALENCE_ENCODING: 2
|
|
504
|
-
};
|
|
505
|
-
var DracoHeader = class {
|
|
506
|
-
dracoString;
|
|
507
|
-
versionMajor;
|
|
508
|
-
versionMinor;
|
|
509
|
-
encoderType;
|
|
510
|
-
encoderMethod;
|
|
511
|
-
flags;
|
|
274
|
+
// src/decoder/core/DataBuffer.ts
|
|
275
|
+
var DataBuffer = class {
|
|
276
|
+
_data;
|
|
512
277
|
constructor() {
|
|
513
|
-
this.
|
|
514
|
-
this.versionMajor = 0;
|
|
515
|
-
this.versionMinor = 0;
|
|
516
|
-
this.encoderType = 0;
|
|
517
|
-
this.encoderMethod = 0;
|
|
518
|
-
this.flags = 0;
|
|
278
|
+
this._data = new Uint8Array(0);
|
|
519
279
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
// src/decoder/compression/config/DracoOptions.ts
|
|
534
|
-
var DracoOptions = class {
|
|
535
|
-
_globalOptions;
|
|
536
|
-
_attributeOptions;
|
|
537
|
-
constructor() {
|
|
538
|
-
this._globalOptions = /* @__PURE__ */ new Map();
|
|
539
|
-
this._attributeOptions = /* @__PURE__ */ new Map();
|
|
540
|
-
}
|
|
541
|
-
getGlobalBool(name, defaultVal) {
|
|
542
|
-
if (this._globalOptions.has(name)) {
|
|
543
|
-
return !!this._globalOptions.get(name);
|
|
280
|
+
update(data, size, offset = 0) {
|
|
281
|
+
if (data === null || data === void 0) {
|
|
282
|
+
if (size + offset < 0) return false;
|
|
283
|
+
this._resize(size + offset);
|
|
284
|
+
} else {
|
|
285
|
+
if (size < 0) return false;
|
|
286
|
+
if (size + offset > this._data.length) {
|
|
287
|
+
this._resize(size + offset);
|
|
288
|
+
}
|
|
289
|
+
const view = data;
|
|
290
|
+
const src = new Uint8Array(view.buffer || data, view.byteOffset || 0, size);
|
|
291
|
+
this._data.set(src, offset);
|
|
544
292
|
}
|
|
545
|
-
return
|
|
293
|
+
return true;
|
|
546
294
|
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
return this._attributeOptions.get(attKey);
|
|
550
|
-
}
|
|
551
|
-
return null;
|
|
295
|
+
resize(newSize) {
|
|
296
|
+
this._resize(newSize);
|
|
552
297
|
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
return
|
|
298
|
+
write(bytePos, inArray, dataSize) {
|
|
299
|
+
if (inArray instanceof Uint8Array) {
|
|
300
|
+
this._data.set(inArray.length === dataSize ? inArray : inArray.subarray(0, dataSize), bytePos);
|
|
301
|
+
return;
|
|
557
302
|
}
|
|
558
|
-
|
|
303
|
+
const view = inArray;
|
|
304
|
+
const src = new Uint8Array(view.buffer || inArray, view.byteOffset || 0, dataSize);
|
|
305
|
+
this._data.set(src, bytePos);
|
|
559
306
|
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
// src/decoder/compression/config/DecoderOptions.ts
|
|
563
|
-
var DecoderOptions = class extends DracoOptions {
|
|
564
|
-
constructor() {
|
|
565
|
-
super();
|
|
307
|
+
get data() {
|
|
308
|
+
return this._data;
|
|
566
309
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
// src/decoder/core/Status.ts
|
|
570
|
-
var StatusCode = {
|
|
571
|
-
OK: 0,
|
|
572
|
-
DRACO_ERROR: -1,
|
|
573
|
-
IO_ERROR: -2,
|
|
574
|
-
INVALID_PARAMETER: -3,
|
|
575
|
-
UNSUPPORTED_VERSION: -4,
|
|
576
|
-
UNKNOWN_VERSION: -5,
|
|
577
|
-
UNSUPPORTED_FEATURE: -6
|
|
578
|
-
};
|
|
579
|
-
var Status = class {
|
|
580
|
-
code;
|
|
581
|
-
errorMsg;
|
|
582
|
-
constructor(code = StatusCode.OK, errorMsg = "") {
|
|
583
|
-
this.code = code;
|
|
584
|
-
this.errorMsg = errorMsg;
|
|
310
|
+
get dataSize() {
|
|
311
|
+
return this._data.length;
|
|
585
312
|
}
|
|
586
|
-
|
|
587
|
-
|
|
313
|
+
_resize(newSize) {
|
|
314
|
+
if (newSize === this._data.length) return;
|
|
315
|
+
const newData = new Uint8Array(newSize);
|
|
316
|
+
newData.set(this._data.subarray(0, Math.min(this._data.length, newSize)));
|
|
317
|
+
this._data = newData;
|
|
588
318
|
}
|
|
589
319
|
};
|
|
590
|
-
function okStatus() {
|
|
591
|
-
return new Status(StatusCode.OK);
|
|
592
|
-
}
|
|
593
320
|
|
|
594
|
-
// src/decoder/
|
|
595
|
-
var
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
321
|
+
// src/decoder/attributes/GeometryIndices.ts
|
|
322
|
+
var kInvalidAttributeValueIndex = 4294967295 >>> 0;
|
|
323
|
+
|
|
324
|
+
// src/decoder/attributes/PointAttribute.ts
|
|
325
|
+
var PointAttribute = class extends GeometryAttribute {
|
|
326
|
+
_identityMapping;
|
|
327
|
+
_numUniqueEntries;
|
|
328
|
+
_indicesMap;
|
|
329
|
+
_attributeBuffer;
|
|
330
|
+
_attributeTransformData;
|
|
331
|
+
// Lazily-created cached views over the attribute buffer.
|
|
332
|
+
_cachedFloat32View;
|
|
333
|
+
_cachedFloat32Buffer;
|
|
334
|
+
_cachedInt32View;
|
|
335
|
+
_cachedInt32Buffer;
|
|
336
|
+
_cachedUint32View;
|
|
337
|
+
_cachedUint32Buffer;
|
|
338
|
+
_cachedUint16View;
|
|
339
|
+
_cachedUint16Buffer;
|
|
340
|
+
_cachedInt16View;
|
|
341
|
+
_cachedInt16Buffer;
|
|
342
|
+
_cachedUint8View;
|
|
343
|
+
_cachedUint8Buffer;
|
|
344
|
+
_cachedInt8View;
|
|
345
|
+
_cachedInt8Buffer;
|
|
346
|
+
_cachedFloat64View;
|
|
347
|
+
_cachedFloat64Buffer;
|
|
348
|
+
_cachedDataView;
|
|
349
|
+
_cachedDVBuffer;
|
|
350
|
+
constructor(geometryAttribute) {
|
|
351
|
+
super();
|
|
352
|
+
this._identityMapping = false;
|
|
353
|
+
this._numUniqueEntries = 0;
|
|
354
|
+
this._indicesMap = [];
|
|
355
|
+
this._attributeBuffer = null;
|
|
356
|
+
this._attributeTransformData = null;
|
|
357
|
+
if (geometryAttribute instanceof GeometryAttribute) {
|
|
358
|
+
this._buffer = geometryAttribute._buffer;
|
|
359
|
+
this._numComponents = geometryAttribute._numComponents;
|
|
360
|
+
this._dataType = geometryAttribute._dataType;
|
|
361
|
+
this._normalized = geometryAttribute._normalized;
|
|
362
|
+
this._byteStride = geometryAttribute._byteStride;
|
|
363
|
+
this._byteOffset = geometryAttribute._byteOffset;
|
|
364
|
+
this._attributeType = geometryAttribute._attributeType;
|
|
365
|
+
this._uniqueId = geometryAttribute._uniqueId;
|
|
615
366
|
}
|
|
616
|
-
return this._skipMetadata(0);
|
|
617
367
|
}
|
|
618
|
-
//
|
|
619
|
-
//
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
return false;
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
const numSubMetadata = decodeVarint(this.buffer_);
|
|
634
|
-
if (numSubMetadata === void 0) {
|
|
635
|
-
return false;
|
|
636
|
-
}
|
|
637
|
-
if (numSubMetadata > this.buffer_.remainingSize) {
|
|
638
|
-
return false;
|
|
639
|
-
}
|
|
640
|
-
for (let i = 0; i < numSubMetadata; ++i) {
|
|
641
|
-
if (!this._skipName()) {
|
|
642
|
-
return false;
|
|
643
|
-
}
|
|
644
|
-
if (!this._skipMetadata(level + 1)) {
|
|
645
|
-
return false;
|
|
646
|
-
}
|
|
368
|
+
// Intentionally shadows GeometryAttribute.init with a different signature (matches draco.js / C++ source).
|
|
369
|
+
// @ts-expect-error -- signature intentionally differs from the base class, as in the source.
|
|
370
|
+
init(attributeType, numComponents, dataType, normalized, numAttributeValues) {
|
|
371
|
+
this._attributeBuffer = new DataBuffer();
|
|
372
|
+
const byteStride = dataTypeLength(dataType) * numComponents;
|
|
373
|
+
super.init(attributeType, this._attributeBuffer, numComponents, dataType, normalized, byteStride, 0);
|
|
374
|
+
this.reset(numAttributeValues);
|
|
375
|
+
this.setIdentityMapping();
|
|
376
|
+
}
|
|
377
|
+
reset(numAttributeValues) {
|
|
378
|
+
if (this._attributeBuffer === null) {
|
|
379
|
+
this._attributeBuffer = new DataBuffer();
|
|
647
380
|
}
|
|
381
|
+
const entrySize = dataTypeLength(this.dataType) * this.numComponents;
|
|
382
|
+
this._attributeBuffer.update(null, numAttributeValues * entrySize);
|
|
383
|
+
this.resetBuffer(this._attributeBuffer, entrySize, 0);
|
|
384
|
+
this._numUniqueEntries = numAttributeValues;
|
|
648
385
|
return true;
|
|
649
386
|
}
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
if (!this._skipName()) {
|
|
653
|
-
return false;
|
|
654
|
-
}
|
|
655
|
-
const dataSize = decodeVarint(this.buffer_);
|
|
656
|
-
if (dataSize === void 0 || dataSize === 0) {
|
|
657
|
-
return false;
|
|
658
|
-
}
|
|
659
|
-
if (dataSize > this.buffer_.remainingSize) {
|
|
660
|
-
return false;
|
|
661
|
-
}
|
|
662
|
-
return this.buffer_.decodeBytes(dataSize) !== void 0;
|
|
387
|
+
get size() {
|
|
388
|
+
return this._numUniqueEntries;
|
|
663
389
|
}
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
if (nameLen === void 0) {
|
|
668
|
-
return false;
|
|
669
|
-
}
|
|
670
|
-
if (nameLen === 0) {
|
|
671
|
-
return true;
|
|
390
|
+
mappedIndex(pointIndex) {
|
|
391
|
+
if (this._identityMapping) {
|
|
392
|
+
return pointIndex;
|
|
672
393
|
}
|
|
673
|
-
return this.
|
|
394
|
+
return this._indicesMap[pointIndex];
|
|
674
395
|
}
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
// src/decoder/compression/point_cloud/PointCloudDecoder.ts
|
|
678
|
-
var PointCloudDecoder = class _PointCloudDecoder {
|
|
679
|
-
_pointCloud;
|
|
680
|
-
_buffer;
|
|
681
|
-
_versionMajor;
|
|
682
|
-
_versionMinor;
|
|
683
|
-
_options;
|
|
684
|
-
_attributesDecoders;
|
|
685
|
-
_attributeToDecoderMap;
|
|
686
|
-
constructor() {
|
|
687
|
-
this._pointCloud = null;
|
|
688
|
-
this._buffer = null;
|
|
689
|
-
this._versionMajor = 0;
|
|
690
|
-
this._versionMinor = 0;
|
|
691
|
-
this._options = null;
|
|
692
|
-
this._attributesDecoders = [];
|
|
693
|
-
this._attributeToDecoderMap = [];
|
|
396
|
+
get isMappingIdentity() {
|
|
397
|
+
return this._identityMapping;
|
|
694
398
|
}
|
|
695
|
-
|
|
696
|
-
|
|
399
|
+
get indicesMapSize() {
|
|
400
|
+
if (this._identityMapping) {
|
|
401
|
+
return 0;
|
|
402
|
+
}
|
|
403
|
+
return this._indicesMap.length;
|
|
697
404
|
}
|
|
698
|
-
//
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
return new Status(StatusCode.IO_ERROR, kIoErrorMsg);
|
|
704
|
-
}
|
|
705
|
-
for (let i = 0; i < 5; i++) {
|
|
706
|
-
outHeader.dracoString[i] = bytes[i];
|
|
707
|
-
}
|
|
708
|
-
const magic = String.fromCharCode(bytes[0], bytes[1], bytes[2], bytes[3], bytes[4]);
|
|
709
|
-
if (magic !== "DRACO") {
|
|
710
|
-
return new Status(StatusCode.DRACO_ERROR, "Not a Draco file.");
|
|
711
|
-
}
|
|
712
|
-
const versionMajor = buffer.decodeUint8();
|
|
713
|
-
if (versionMajor === void 0) {
|
|
714
|
-
return new Status(StatusCode.IO_ERROR, kIoErrorMsg);
|
|
715
|
-
}
|
|
716
|
-
outHeader.versionMajor = versionMajor;
|
|
717
|
-
const versionMinor = buffer.decodeUint8();
|
|
718
|
-
if (versionMinor === void 0) {
|
|
719
|
-
return new Status(StatusCode.IO_ERROR, kIoErrorMsg);
|
|
720
|
-
}
|
|
721
|
-
outHeader.versionMinor = versionMinor;
|
|
722
|
-
const encoderType = buffer.decodeUint8();
|
|
723
|
-
if (encoderType === void 0) {
|
|
724
|
-
return new Status(StatusCode.IO_ERROR, kIoErrorMsg);
|
|
725
|
-
}
|
|
726
|
-
outHeader.encoderType = encoderType;
|
|
727
|
-
const encoderMethod = buffer.decodeUint8();
|
|
728
|
-
if (encoderMethod === void 0) {
|
|
729
|
-
return new Status(StatusCode.IO_ERROR, kIoErrorMsg);
|
|
730
|
-
}
|
|
731
|
-
outHeader.encoderMethod = encoderMethod;
|
|
732
|
-
const flags = buffer.decodeUint16();
|
|
733
|
-
if (flags === void 0) {
|
|
734
|
-
return new Status(StatusCode.IO_ERROR, kIoErrorMsg);
|
|
735
|
-
}
|
|
736
|
-
outHeader.flags = flags;
|
|
737
|
-
return okStatus();
|
|
738
|
-
}
|
|
739
|
-
// Main entry point for point cloud decoding.
|
|
740
|
-
decode(options, inBuffer, outPointCloud) {
|
|
741
|
-
this._options = options;
|
|
742
|
-
this._buffer = inBuffer;
|
|
743
|
-
this._pointCloud = outPointCloud;
|
|
744
|
-
const header = new DracoHeader();
|
|
745
|
-
const headerStatus = _PointCloudDecoder.decodeHeader(this._buffer, header);
|
|
746
|
-
if (!headerStatus.ok()) {
|
|
747
|
-
return headerStatus;
|
|
748
|
-
}
|
|
749
|
-
if (header.encoderType !== this.getGeometryType()) {
|
|
750
|
-
return new Status(StatusCode.DRACO_ERROR, "Using incompatible decoder for the input geometry.");
|
|
751
|
-
}
|
|
752
|
-
this._versionMajor = header.versionMajor;
|
|
753
|
-
this._versionMinor = header.versionMinor;
|
|
754
|
-
const maxSupportedMajorVersion = header.encoderType === EncodedGeometryType.POINT_CLOUD ? kDracoPointCloudBitstreamVersionMajor : kDracoMeshBitstreamVersionMajor;
|
|
755
|
-
const maxSupportedMinorVersion = header.encoderType === EncodedGeometryType.POINT_CLOUD ? kDracoPointCloudBitstreamVersionMinor : kDracoMeshBitstreamVersionMinor;
|
|
756
|
-
if (this._versionMajor < 1 || this._versionMajor > maxSupportedMajorVersion) {
|
|
757
|
-
return new Status(StatusCode.UNKNOWN_VERSION, "Unknown major version.");
|
|
758
|
-
}
|
|
759
|
-
if (this._versionMajor === maxSupportedMajorVersion && this._versionMinor > maxSupportedMinorVersion) {
|
|
760
|
-
return new Status(StatusCode.UNKNOWN_VERSION, "Unknown minor version.");
|
|
761
|
-
}
|
|
762
|
-
this._buffer.bitstreamVersion = DRACO_BITSTREAM_VERSION(this._versionMajor, this._versionMinor);
|
|
763
|
-
if (header.encoderType === EncodedGeometryType.TRIANGULAR_MESH && this._buffer.bitstreamVersion < DRACO_BITSTREAM_VERSION(2, 2)) {
|
|
764
|
-
return new Status(
|
|
765
|
-
StatusCode.UNKNOWN_VERSION,
|
|
766
|
-
"Unsupported bitstream version (only Draco 2.2 meshes are supported)."
|
|
767
|
-
);
|
|
768
|
-
}
|
|
769
|
-
if (header.flags & METADATA_FLAG_MASK) {
|
|
770
|
-
const metadataStatus = this._decodeMetadata();
|
|
771
|
-
if (!metadataStatus.ok()) {
|
|
772
|
-
return metadataStatus;
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
if (!this.initializeDecoder()) {
|
|
776
|
-
return new Status(StatusCode.DRACO_ERROR, "Failed to initialize the decoder.");
|
|
777
|
-
}
|
|
778
|
-
if (!this.decodeGeometryData()) {
|
|
779
|
-
return new Status(StatusCode.DRACO_ERROR, "Failed to decode geometry data.");
|
|
780
|
-
}
|
|
781
|
-
if (!this.decodePointAttributes()) {
|
|
782
|
-
return new Status(StatusCode.DRACO_ERROR, "Failed to decode point attributes.");
|
|
783
|
-
}
|
|
784
|
-
return okStatus();
|
|
785
|
-
}
|
|
786
|
-
bitstreamVersion() {
|
|
787
|
-
return DRACO_BITSTREAM_VERSION(this._versionMajor, this._versionMinor);
|
|
788
|
-
}
|
|
789
|
-
setAttributesDecoder(attDecoderId, decoder) {
|
|
790
|
-
if (attDecoderId < 0) {
|
|
791
|
-
return false;
|
|
792
|
-
}
|
|
793
|
-
while (this._attributesDecoders.length <= attDecoderId) {
|
|
794
|
-
this._attributesDecoders.push(null);
|
|
795
|
-
}
|
|
796
|
-
this._attributesDecoders[attDecoderId] = decoder;
|
|
797
|
-
return true;
|
|
798
|
-
}
|
|
799
|
-
getPortableAttribute(parentAttId) {
|
|
800
|
-
if (parentAttId < 0 || parentAttId >= this._pointCloud.numAttributes()) {
|
|
801
|
-
return null;
|
|
802
|
-
}
|
|
803
|
-
const parentAttDecoderId = this._attributeToDecoderMap[parentAttId];
|
|
804
|
-
return this._attributesDecoders[parentAttDecoderId].getPortableAttribute(parentAttId);
|
|
805
|
-
}
|
|
806
|
-
attributesDecoder(decId) {
|
|
807
|
-
return this._attributesDecoders[decId];
|
|
808
|
-
}
|
|
809
|
-
numAttributesDecoders() {
|
|
810
|
-
return this._attributesDecoders.length;
|
|
811
|
-
}
|
|
812
|
-
pointCloud() {
|
|
813
|
-
return this._pointCloud;
|
|
814
|
-
}
|
|
815
|
-
buffer() {
|
|
816
|
-
return this._buffer;
|
|
405
|
+
// Direct access to the explicit point->value index map (Uint32Array after
|
|
406
|
+
// setExplicitMapping). Lets hot mapping loops write entries without a
|
|
407
|
+
// per-entry setPointMapEntry() dispatch.
|
|
408
|
+
get indicesMap() {
|
|
409
|
+
return this._indicesMap;
|
|
817
410
|
}
|
|
818
|
-
|
|
819
|
-
|
|
411
|
+
// Implicit mapping: point index equals attribute entry index.
|
|
412
|
+
setIdentityMapping() {
|
|
413
|
+
this._identityMapping = true;
|
|
414
|
+
this._indicesMap = [];
|
|
820
415
|
}
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
416
|
+
setExplicitMapping(numPoints) {
|
|
417
|
+
this._identityMapping = false;
|
|
418
|
+
this._indicesMap = new Uint32Array(numPoints);
|
|
419
|
+
this._indicesMap.fill(kInvalidAttributeValueIndex);
|
|
824
420
|
}
|
|
825
|
-
//
|
|
826
|
-
|
|
827
|
-
|
|
421
|
+
// Like setExplicitMapping but skips the invalid-index fill. Only for callers
|
|
422
|
+
// that provably write every entry right away (the fill was ~4% of decode
|
|
423
|
+
// time on primitive-heavy files). The array still starts zeroed by the
|
|
424
|
+
// engine, so a buggy caller reads valid-looking zeros — hence opt-in.
|
|
425
|
+
setExplicitMappingUnfilled(numPoints) {
|
|
426
|
+
this._identityMapping = false;
|
|
427
|
+
this._indicesMap = new Uint32Array(numPoints);
|
|
828
428
|
}
|
|
829
|
-
|
|
830
|
-
|
|
429
|
+
setAttributeTransformData(transformData) {
|
|
430
|
+
this._attributeTransformData = transformData;
|
|
831
431
|
}
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
432
|
+
// Mirrors C++ PointAttribute::ConvertValue<T>().
|
|
433
|
+
convertValue(attIndex, outVal) {
|
|
434
|
+
const bytePos = this._byteOffset + this._byteStride * attIndex;
|
|
435
|
+
const bufData = this._buffer.data;
|
|
436
|
+
const dt = this._dataType;
|
|
437
|
+
const nc = this._numComponents;
|
|
438
|
+
if (dt === DataType.FLOAT32) {
|
|
439
|
+
if (this._cachedFloat32View === void 0 || this._cachedFloat32Buffer !== bufData.buffer) {
|
|
440
|
+
this._cachedFloat32Buffer = bufData.buffer;
|
|
441
|
+
this._cachedFloat32View = new Float32Array(bufData.buffer);
|
|
840
442
|
}
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
return false;
|
|
443
|
+
const baseIndex = bufData.byteOffset + bytePos >> 2;
|
|
444
|
+
for (let i = 0; i < nc; ++i) {
|
|
445
|
+
outVal[i] = this._cachedFloat32View[baseIndex + i];
|
|
845
446
|
}
|
|
447
|
+
return;
|
|
846
448
|
}
|
|
847
|
-
|
|
848
|
-
if (
|
|
849
|
-
|
|
449
|
+
if (dt === DataType.INT32) {
|
|
450
|
+
if (this._cachedInt32View === void 0 || this._cachedInt32Buffer !== bufData.buffer) {
|
|
451
|
+
this._cachedInt32Buffer = bufData.buffer;
|
|
452
|
+
this._cachedInt32View = new Int32Array(bufData.buffer);
|
|
850
453
|
}
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
for (let j = 0; j < numAttributes; ++j) {
|
|
855
|
-
const attId = this._attributesDecoders[i].getAttributeId(j);
|
|
856
|
-
while (this._attributeToDecoderMap.length <= attId) {
|
|
857
|
-
this._attributeToDecoderMap.push(0);
|
|
858
|
-
}
|
|
859
|
-
this._attributeToDecoderMap[attId] = i;
|
|
454
|
+
const baseIndex = bufData.byteOffset + bytePos >> 2;
|
|
455
|
+
for (let i = 0; i < nc; ++i) {
|
|
456
|
+
outVal[i] = this._cachedInt32View[baseIndex + i];
|
|
860
457
|
}
|
|
458
|
+
return;
|
|
861
459
|
}
|
|
862
|
-
if (
|
|
863
|
-
|
|
460
|
+
if (dt === DataType.UINT32) {
|
|
461
|
+
if (this._cachedUint32View === void 0 || this._cachedUint32Buffer !== bufData.buffer) {
|
|
462
|
+
this._cachedUint32Buffer = bufData.buffer;
|
|
463
|
+
this._cachedUint32View = new Uint32Array(bufData.buffer);
|
|
464
|
+
}
|
|
465
|
+
const baseIndex = bufData.byteOffset + bytePos >> 2;
|
|
466
|
+
for (let i = 0; i < nc; ++i) {
|
|
467
|
+
outVal[i] = this._cachedUint32View[baseIndex + i];
|
|
468
|
+
}
|
|
469
|
+
return;
|
|
864
470
|
}
|
|
865
|
-
if (
|
|
866
|
-
|
|
471
|
+
if (this._cachedDataView === void 0 || this._cachedDVBuffer !== bufData.buffer) {
|
|
472
|
+
this._cachedDVBuffer = bufData.buffer;
|
|
473
|
+
this._cachedDataView = new DataView(bufData.buffer, bufData.byteOffset, bufData.byteLength);
|
|
867
474
|
}
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
475
|
+
const dv = this._cachedDataView;
|
|
476
|
+
for (let i = 0; i < nc; ++i) {
|
|
477
|
+
switch (dt) {
|
|
478
|
+
case DataType.INT8:
|
|
479
|
+
outVal[i] = dv.getInt8(bytePos + i);
|
|
480
|
+
break;
|
|
481
|
+
case DataType.UINT8:
|
|
482
|
+
outVal[i] = dv.getUint8(bytePos + i);
|
|
483
|
+
break;
|
|
484
|
+
case DataType.INT16:
|
|
485
|
+
outVal[i] = dv.getInt16(bytePos + i * 2, true);
|
|
486
|
+
break;
|
|
487
|
+
case DataType.UINT16:
|
|
488
|
+
outVal[i] = dv.getUint16(bytePos + i * 2, true);
|
|
489
|
+
break;
|
|
490
|
+
case DataType.INT32:
|
|
491
|
+
outVal[i] = dv.getInt32(bytePos + i * 4, true);
|
|
492
|
+
break;
|
|
493
|
+
case DataType.UINT32:
|
|
494
|
+
outVal[i] = dv.getUint32(bytePos + i * 4, true);
|
|
495
|
+
break;
|
|
496
|
+
case DataType.FLOAT64:
|
|
497
|
+
outVal[i] = dv.getFloat64(bytePos + i * 8, true);
|
|
498
|
+
break;
|
|
499
|
+
default:
|
|
500
|
+
outVal[i] = 0;
|
|
501
|
+
break;
|
|
874
502
|
}
|
|
875
503
|
}
|
|
876
|
-
return true;
|
|
877
|
-
}
|
|
878
|
-
onAttributesDecoded() {
|
|
879
|
-
return true;
|
|
880
|
-
}
|
|
881
|
-
_decodeMetadata() {
|
|
882
|
-
const metadataDecoder = new MetadataDecoder();
|
|
883
|
-
if (!metadataDecoder.skipGeometryMetadata(this._buffer)) {
|
|
884
|
-
return new Status(StatusCode.DRACO_ERROR, "Failed to decode metadata.");
|
|
885
|
-
}
|
|
886
|
-
return okStatus();
|
|
887
504
|
}
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
505
|
+
// Flat-array extraction of all values into one output typed array (avoids the
|
|
506
|
+
// per-point temp-array copy via cached typed-array views over the buffer).
|
|
507
|
+
extractTo(OutputTypedArray, numPoints) {
|
|
508
|
+
const numComponents = this._numComponents;
|
|
509
|
+
const array = new OutputTypedArray(numPoints * numComponents);
|
|
510
|
+
if (this._buffer == null || this._buffer.data == null || numPoints === 0) {
|
|
511
|
+
return array;
|
|
512
|
+
}
|
|
513
|
+
const bufData = this._buffer.data;
|
|
514
|
+
const dt = this._dataType;
|
|
515
|
+
const isIdentity = this._identityMapping;
|
|
516
|
+
const indicesMap = this._indicesMap;
|
|
517
|
+
const byteStride = this._byteStride;
|
|
518
|
+
const byteOffset = this._byteOffset;
|
|
519
|
+
let srcView = null;
|
|
520
|
+
let shift = 0;
|
|
521
|
+
if (dt === DataType.FLOAT32) {
|
|
522
|
+
if (this._cachedFloat32View === void 0 || this._cachedFloat32Buffer !== bufData.buffer) {
|
|
523
|
+
this._cachedFloat32Buffer = bufData.buffer;
|
|
524
|
+
this._cachedFloat32View = new Float32Array(bufData.buffer);
|
|
525
|
+
}
|
|
526
|
+
srcView = this._cachedFloat32View;
|
|
527
|
+
shift = 2;
|
|
528
|
+
} else if (dt === DataType.INT32) {
|
|
529
|
+
if (this._cachedInt32View === void 0 || this._cachedInt32Buffer !== bufData.buffer) {
|
|
530
|
+
this._cachedInt32Buffer = bufData.buffer;
|
|
531
|
+
this._cachedInt32View = new Int32Array(bufData.buffer);
|
|
532
|
+
}
|
|
533
|
+
srcView = this._cachedInt32View;
|
|
534
|
+
shift = 2;
|
|
535
|
+
} else if (dt === DataType.UINT32) {
|
|
536
|
+
if (this._cachedUint32View === void 0 || this._cachedUint32Buffer !== bufData.buffer) {
|
|
537
|
+
this._cachedUint32Buffer = bufData.buffer;
|
|
538
|
+
this._cachedUint32View = new Uint32Array(bufData.buffer);
|
|
539
|
+
}
|
|
540
|
+
srcView = this._cachedUint32View;
|
|
541
|
+
shift = 2;
|
|
542
|
+
} else if (dt === DataType.UINT16) {
|
|
543
|
+
if (this._cachedUint16View === void 0 || this._cachedUint16Buffer !== bufData.buffer) {
|
|
544
|
+
this._cachedUint16Buffer = bufData.buffer;
|
|
545
|
+
this._cachedUint16View = new Uint16Array(bufData.buffer);
|
|
546
|
+
}
|
|
547
|
+
srcView = this._cachedUint16View;
|
|
548
|
+
shift = 1;
|
|
549
|
+
} else if (dt === DataType.INT16) {
|
|
550
|
+
if (this._cachedInt16View === void 0 || this._cachedInt16Buffer !== bufData.buffer) {
|
|
551
|
+
this._cachedInt16Buffer = bufData.buffer;
|
|
552
|
+
this._cachedInt16View = new Int16Array(bufData.buffer);
|
|
553
|
+
}
|
|
554
|
+
srcView = this._cachedInt16View;
|
|
555
|
+
shift = 1;
|
|
556
|
+
} else if (dt === DataType.UINT8) {
|
|
557
|
+
if (this._cachedUint8View === void 0 || this._cachedUint8Buffer !== bufData.buffer) {
|
|
558
|
+
this._cachedUint8Buffer = bufData.buffer;
|
|
559
|
+
this._cachedUint8View = new Uint8Array(bufData.buffer);
|
|
560
|
+
}
|
|
561
|
+
srcView = this._cachedUint8View;
|
|
562
|
+
shift = 0;
|
|
563
|
+
} else if (dt === DataType.INT8) {
|
|
564
|
+
if (this._cachedInt8View === void 0 || this._cachedInt8Buffer !== bufData.buffer) {
|
|
565
|
+
this._cachedInt8Buffer = bufData.buffer;
|
|
566
|
+
this._cachedInt8View = new Int8Array(bufData.buffer);
|
|
567
|
+
}
|
|
568
|
+
srcView = this._cachedInt8View;
|
|
569
|
+
shift = 0;
|
|
570
|
+
} else if (dt === DataType.FLOAT64) {
|
|
571
|
+
if (this._cachedFloat64View === void 0 || this._cachedFloat64Buffer !== bufData.buffer) {
|
|
572
|
+
this._cachedFloat64Buffer = bufData.buffer;
|
|
573
|
+
this._cachedFloat64View = new Float64Array(bufData.buffer);
|
|
574
|
+
}
|
|
575
|
+
srcView = this._cachedFloat64View;
|
|
576
|
+
shift = 3;
|
|
577
|
+
}
|
|
578
|
+
if (srcView !== null) {
|
|
579
|
+
const srcStart = bufData.byteOffset + byteOffset >> shift;
|
|
580
|
+
const strideElements = byteStride >> shift;
|
|
581
|
+
if (isIdentity && strideElements === numComponents) {
|
|
582
|
+
const srcEnd = srcStart + numPoints * numComponents;
|
|
583
|
+
if (srcView.constructor === OutputTypedArray) {
|
|
584
|
+
array.set(srcView.subarray(srcStart, srcEnd));
|
|
585
|
+
return array;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
if (isIdentity) {
|
|
589
|
+
let dst = 0;
|
|
590
|
+
for (let i = 0; i < numPoints; i++) {
|
|
591
|
+
const srcOffset = srcStart + i * strideElements;
|
|
592
|
+
for (let j = 0; j < numComponents; j++) {
|
|
593
|
+
array[dst + j] = srcView[srcOffset + j];
|
|
594
|
+
}
|
|
595
|
+
dst += numComponents;
|
|
596
|
+
}
|
|
597
|
+
} else if (numComponents === 3) {
|
|
598
|
+
let dst = 0;
|
|
599
|
+
for (let i = 0; i < numPoints; i++) {
|
|
600
|
+
const srcOffset = srcStart + indicesMap[i] * strideElements;
|
|
601
|
+
array[dst] = srcView[srcOffset];
|
|
602
|
+
array[dst + 1] = srcView[srcOffset + 1];
|
|
603
|
+
array[dst + 2] = srcView[srcOffset + 2];
|
|
604
|
+
dst += 3;
|
|
605
|
+
}
|
|
606
|
+
} else if (numComponents === 2) {
|
|
607
|
+
let dst = 0;
|
|
608
|
+
for (let i = 0; i < numPoints; i++) {
|
|
609
|
+
const srcOffset = srcStart + indicesMap[i] * strideElements;
|
|
610
|
+
array[dst] = srcView[srcOffset];
|
|
611
|
+
array[dst + 1] = srcView[srcOffset + 1];
|
|
612
|
+
dst += 2;
|
|
613
|
+
}
|
|
614
|
+
} else if (numComponents === 4) {
|
|
615
|
+
let dst = 0;
|
|
616
|
+
for (let i = 0; i < numPoints; i++) {
|
|
617
|
+
const srcOffset = srcStart + indicesMap[i] * strideElements;
|
|
618
|
+
array[dst] = srcView[srcOffset];
|
|
619
|
+
array[dst + 1] = srcView[srcOffset + 1];
|
|
620
|
+
array[dst + 2] = srcView[srcOffset + 2];
|
|
621
|
+
array[dst + 3] = srcView[srcOffset + 3];
|
|
622
|
+
dst += 4;
|
|
623
|
+
}
|
|
624
|
+
} else if (numComponents === 1) {
|
|
625
|
+
let dst = 0;
|
|
626
|
+
for (let i = 0; i < numPoints; i++) {
|
|
627
|
+
array[dst++] = srcView[srcStart + indicesMap[i] * strideElements];
|
|
628
|
+
}
|
|
629
|
+
} else {
|
|
630
|
+
let dst = 0;
|
|
631
|
+
for (let i = 0; i < numPoints; i++) {
|
|
632
|
+
const srcOffset = srcStart + indicesMap[i] * strideElements;
|
|
633
|
+
for (let j = 0; j < numComponents; j++) {
|
|
634
|
+
array[dst + j] = srcView[srcOffset + j];
|
|
635
|
+
}
|
|
636
|
+
dst += numComponents;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
return array;
|
|
640
|
+
}
|
|
641
|
+
const temp = new Array(numComponents);
|
|
642
|
+
for (let i = 0; i < numPoints; i++) {
|
|
643
|
+
const attIndex = isIdentity ? i : indicesMap[i];
|
|
644
|
+
this.convertValue(attIndex, temp);
|
|
645
|
+
const dstOffset = i * numComponents;
|
|
646
|
+
for (let j = 0; j < numComponents; j++) {
|
|
647
|
+
array[dstOffset + j] = temp[j];
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
return array;
|
|
896
651
|
}
|
|
897
|
-
|
|
898
|
-
|
|
652
|
+
// Intentionally returns void while the base class returns boolean (matches the source's shape).
|
|
653
|
+
// @ts-expect-error -- return type intentionally differs from the base class, as in the source.
|
|
654
|
+
copyFrom(srcAtt) {
|
|
655
|
+
if (this.buffer === null) {
|
|
656
|
+
this._attributeBuffer = new DataBuffer();
|
|
657
|
+
this.resetBuffer(this._attributeBuffer, 0, 0);
|
|
658
|
+
}
|
|
659
|
+
if (!super.copyFrom(srcAtt)) {
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
this._identityMapping = srcAtt._identityMapping;
|
|
663
|
+
this._numUniqueEntries = srcAtt._numUniqueEntries;
|
|
664
|
+
this._indicesMap = srcAtt._indicesMap.slice();
|
|
665
|
+
if (srcAtt._attributeTransformData) {
|
|
666
|
+
this._attributeTransformData = srcAtt._attributeTransformData;
|
|
667
|
+
} else {
|
|
668
|
+
this._attributeTransformData = null;
|
|
669
|
+
}
|
|
899
670
|
}
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
671
|
+
};
|
|
672
|
+
|
|
673
|
+
// src/decoder/core/Macros.ts
|
|
674
|
+
function bitstreamVersion(major, minor) {
|
|
675
|
+
return (major & 255) << 8 | minor & 255;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
// src/decoder/core/BitUtils.ts
|
|
679
|
+
function convertSymbolsToSignedInts(input, count, output) {
|
|
680
|
+
for (let i = 0; i < count; i++) {
|
|
681
|
+
const val = input[i];
|
|
682
|
+
output[i] = val >>> 1 ^ -(val & 1);
|
|
903
683
|
}
|
|
904
|
-
|
|
905
|
-
|
|
684
|
+
}
|
|
685
|
+
function convertSymbolToSignedInt(val) {
|
|
686
|
+
const isPositive = (val & 1) === 0;
|
|
687
|
+
val >>>= 1;
|
|
688
|
+
if (isPositive) {
|
|
689
|
+
return val;
|
|
906
690
|
}
|
|
907
|
-
|
|
908
|
-
|
|
691
|
+
return -val - 1;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
// src/decoder/core/VarintDecoding.ts
|
|
695
|
+
function decodeVarintUnsigned(buffer, maxBytes) {
|
|
696
|
+
let result = 0;
|
|
697
|
+
let multiplier = 1;
|
|
698
|
+
for (let i = 0; i < maxBytes; i++) {
|
|
699
|
+
const byte = buffer.decodeUint8();
|
|
700
|
+
if (byte === void 0) return void 0;
|
|
701
|
+
if (byte & 128) {
|
|
702
|
+
result += (byte & 127) * multiplier;
|
|
703
|
+
multiplier *= 128;
|
|
704
|
+
} else {
|
|
705
|
+
return result + byte * multiplier;
|
|
706
|
+
}
|
|
909
707
|
}
|
|
910
|
-
|
|
911
|
-
|
|
708
|
+
return void 0;
|
|
709
|
+
}
|
|
710
|
+
function decodeVarint(buffer, signed = false) {
|
|
711
|
+
const maxBytes = 10;
|
|
712
|
+
const value = decodeVarintUnsigned(buffer, maxBytes);
|
|
713
|
+
if (value === void 0) return void 0;
|
|
714
|
+
if (signed) {
|
|
715
|
+
return convertSymbolToSignedInt(value);
|
|
912
716
|
}
|
|
913
|
-
|
|
914
|
-
|
|
717
|
+
return value;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// src/decoder/core/DecoderBuffer.ts
|
|
721
|
+
var BitDecoder = class {
|
|
722
|
+
_bitBuffer;
|
|
723
|
+
_bitOffset;
|
|
724
|
+
_byteLength;
|
|
725
|
+
constructor() {
|
|
726
|
+
this._bitBuffer = null;
|
|
727
|
+
this._bitOffset = 0;
|
|
728
|
+
this._byteLength = 0;
|
|
915
729
|
}
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
730
|
+
reset(uint8Array, byteLength) {
|
|
731
|
+
this._bitBuffer = uint8Array;
|
|
732
|
+
this._byteLength = byteLength;
|
|
733
|
+
this._bitOffset = 0;
|
|
734
|
+
}
|
|
735
|
+
bitsDecoded() {
|
|
736
|
+
return this._bitOffset;
|
|
737
|
+
}
|
|
738
|
+
getBits(nbits) {
|
|
739
|
+
if (nbits > 32) return void 0;
|
|
740
|
+
const buf = this._bitBuffer;
|
|
741
|
+
let off = this._bitOffset;
|
|
742
|
+
const byteOffset = off >> 3;
|
|
743
|
+
const bitShift = off & 7;
|
|
744
|
+
if (byteOffset + 4 < this._byteLength) {
|
|
745
|
+
const val = (buf[byteOffset] | buf[byteOffset + 1] << 8 | buf[byteOffset + 2] << 16 | buf[byteOffset + 3] << 24) >>> 0;
|
|
746
|
+
let result;
|
|
747
|
+
if (nbits > 32 - bitShift) {
|
|
748
|
+
const val2 = buf[byteOffset + 4];
|
|
749
|
+
const low = val >>> bitShift;
|
|
750
|
+
const high = val2 << 32 - bitShift;
|
|
751
|
+
result = (low | high) >>> 0;
|
|
752
|
+
} else {
|
|
753
|
+
result = val >>> bitShift;
|
|
754
|
+
}
|
|
755
|
+
this._bitOffset = off + nbits;
|
|
756
|
+
return nbits === 32 ? result : result & (1 << nbits) - 1;
|
|
919
757
|
}
|
|
920
|
-
|
|
921
|
-
|
|
758
|
+
let value = 0;
|
|
759
|
+
let bitsRead = 0;
|
|
760
|
+
let currOff = off;
|
|
761
|
+
while (bitsRead < nbits) {
|
|
762
|
+
const bOff = currOff >> 3;
|
|
763
|
+
if (bOff >= this._byteLength) return void 0;
|
|
764
|
+
const bShift = currOff & 7;
|
|
765
|
+
const bitsAvail = 8 - bShift;
|
|
766
|
+
const bitsNeeded = nbits - bitsRead;
|
|
767
|
+
const bitsToRead = bitsAvail < bitsNeeded ? bitsAvail : bitsNeeded;
|
|
768
|
+
const mask = (1 << bitsToRead) - 1;
|
|
769
|
+
value |= (buf[bOff] >> bShift & mask) << bitsRead;
|
|
770
|
+
bitsRead += bitsToRead;
|
|
771
|
+
currOff += bitsToRead;
|
|
922
772
|
}
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
// Overridden by derived classes.
|
|
926
|
-
decodeConnectivity() {
|
|
927
|
-
return false;
|
|
773
|
+
this._bitOffset = currOff;
|
|
774
|
+
return value;
|
|
928
775
|
}
|
|
929
776
|
};
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
corner_to_vertex_map_;
|
|
939
|
-
vertex_to_left_most_corner_map_;
|
|
940
|
-
vertex_to_attribute_entry_id_map_;
|
|
941
|
-
corner_table_;
|
|
942
|
-
// Lazily built; see oppositeCornerArray.
|
|
943
|
-
_effectiveOpposite;
|
|
944
|
-
// Every corner passed to addSeamEdge (may contain duplicates); lets
|
|
945
|
-
// oppositeCornerArray patch seams without scanning every corner's flag.
|
|
946
|
-
_seamCorners;
|
|
777
|
+
var DecoderBuffer = class {
|
|
778
|
+
_data;
|
|
779
|
+
_dataView;
|
|
780
|
+
_dataSize;
|
|
781
|
+
_pos;
|
|
782
|
+
_bitDecoder;
|
|
783
|
+
_bitMode;
|
|
784
|
+
_bitstreamVersion;
|
|
947
785
|
constructor() {
|
|
948
|
-
this.
|
|
949
|
-
this.
|
|
950
|
-
this.
|
|
951
|
-
this.
|
|
952
|
-
this.
|
|
953
|
-
this.
|
|
954
|
-
this.
|
|
955
|
-
this._effectiveOpposite = null;
|
|
956
|
-
this._seamCorners = [];
|
|
786
|
+
this._data = null;
|
|
787
|
+
this._dataView = null;
|
|
788
|
+
this._dataSize = 0;
|
|
789
|
+
this._pos = 0;
|
|
790
|
+
this._bitDecoder = new BitDecoder();
|
|
791
|
+
this._bitMode = false;
|
|
792
|
+
this._bitstreamVersion = 0;
|
|
957
793
|
}
|
|
958
|
-
|
|
959
|
-
if (
|
|
960
|
-
|
|
794
|
+
init(data, dataSize, version) {
|
|
795
|
+
if (data instanceof ArrayBuffer) {
|
|
796
|
+
this._data = new Uint8Array(data);
|
|
797
|
+
} else if (data instanceof Uint8Array) {
|
|
798
|
+
this._data = data;
|
|
799
|
+
} else {
|
|
800
|
+
this._data = new Uint8Array(data);
|
|
961
801
|
}
|
|
962
|
-
this.
|
|
963
|
-
this.
|
|
964
|
-
this.
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
this._effectiveOpposite = null;
|
|
968
|
-
this._seamCorners = [];
|
|
969
|
-
this.corner_table_ = table;
|
|
970
|
-
this.no_interior_seams_ = true;
|
|
971
|
-
return true;
|
|
972
|
-
}
|
|
973
|
-
addSeamEdge(c) {
|
|
974
|
-
const cornerToVertex = this.corner_table_.cornerToVertexArray();
|
|
975
|
-
const oppositeCorners = this.corner_table_.oppositeCornerArray();
|
|
976
|
-
const isEdge = this.is_edge_on_seam_;
|
|
977
|
-
const isVert = this.is_vertex_on_seam_;
|
|
978
|
-
isEdge[c] = 1;
|
|
979
|
-
this._seamCorners.push(c);
|
|
980
|
-
let rem = c - (c / 3 | 0) * 3;
|
|
981
|
-
isVert[cornerToVertex[rem === 2 ? c - 2 : c + 1]] = 1;
|
|
982
|
-
isVert[cornerToVertex[rem === 0 ? c + 2 : c - 1]] = 1;
|
|
983
|
-
const oppCorner = oppositeCorners[c];
|
|
984
|
-
if (oppCorner !== kInvalidCornerIndex) {
|
|
985
|
-
this.no_interior_seams_ = false;
|
|
986
|
-
isEdge[oppCorner] = 1;
|
|
987
|
-
this._seamCorners.push(oppCorner);
|
|
988
|
-
rem = oppCorner - (oppCorner / 3 | 0) * 3;
|
|
989
|
-
isVert[cornerToVertex[rem === 2 ? oppCorner - 2 : oppCorner + 1]] = 1;
|
|
990
|
-
isVert[cornerToVertex[rem === 0 ? oppCorner + 2 : oppCorner - 1]] = 1;
|
|
802
|
+
this._dataView = new DataView(this._data.buffer, this._data.byteOffset, this._data.byteLength);
|
|
803
|
+
this._dataSize = dataSize !== void 0 ? dataSize : this._data.length;
|
|
804
|
+
this._pos = 0;
|
|
805
|
+
if (version !== void 0) {
|
|
806
|
+
this._bitstreamVersion = version;
|
|
991
807
|
}
|
|
992
808
|
}
|
|
993
|
-
|
|
994
|
-
|
|
809
|
+
// Typed little-endian reads.
|
|
810
|
+
decodeUint8() {
|
|
811
|
+
if (this._pos + 1 > this._dataSize) return void 0;
|
|
812
|
+
const val = this._data[this._pos];
|
|
813
|
+
this._pos += 1;
|
|
814
|
+
return val;
|
|
995
815
|
}
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
const
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
816
|
+
decodeInt8() {
|
|
817
|
+
if (this._pos + 1 > this._dataSize) return void 0;
|
|
818
|
+
const val = this._dataView.getInt8(this._pos);
|
|
819
|
+
this._pos += 1;
|
|
820
|
+
return val;
|
|
821
|
+
}
|
|
822
|
+
decodeUint16() {
|
|
823
|
+
if (this._pos + 2 > this._dataSize) return void 0;
|
|
824
|
+
const val = this._dataView.getUint16(this._pos, true);
|
|
825
|
+
this._pos += 2;
|
|
826
|
+
return val;
|
|
827
|
+
}
|
|
828
|
+
decodeUint32() {
|
|
829
|
+
if (this._pos + 4 > this._dataSize) return void 0;
|
|
830
|
+
const val = this._dataView.getUint32(this._pos, true);
|
|
831
|
+
this._pos += 4;
|
|
832
|
+
return val;
|
|
833
|
+
}
|
|
834
|
+
decodeInt32() {
|
|
835
|
+
if (this._pos + 4 > this._dataSize) return void 0;
|
|
836
|
+
const val = this._dataView.getInt32(this._pos, true);
|
|
837
|
+
this._pos += 4;
|
|
838
|
+
return val;
|
|
839
|
+
}
|
|
840
|
+
decodeFloat32() {
|
|
841
|
+
if (this._pos + 4 > this._dataSize) return void 0;
|
|
842
|
+
const val = this._dataView.getFloat32(this._pos, true);
|
|
843
|
+
this._pos += 4;
|
|
844
|
+
return val;
|
|
845
|
+
}
|
|
846
|
+
decodeUint64() {
|
|
847
|
+
if (this._pos + 8 > this._dataSize) return void 0;
|
|
848
|
+
const lo = this._dataView.getUint32(this._pos, true);
|
|
849
|
+
const hi = this._dataView.getUint32(this._pos + 4, true);
|
|
850
|
+
this._pos += 8;
|
|
851
|
+
return hi * 4294967296 + lo;
|
|
852
|
+
}
|
|
853
|
+
decodeBytes(size) {
|
|
854
|
+
if (this._pos + size > this._dataSize) return void 0;
|
|
855
|
+
const result = this._data.slice(this._pos, this._pos + size);
|
|
856
|
+
this._pos += size;
|
|
857
|
+
return result;
|
|
858
|
+
}
|
|
859
|
+
// Zero-copy variant of decodeBytes: a view into the stream, only valid until
|
|
860
|
+
// the caller's next chance to mutate the buffer — copy out before keeping it.
|
|
861
|
+
decodeBytesView(size) {
|
|
862
|
+
if (this._pos + size > this._dataSize) return void 0;
|
|
863
|
+
const result = this._data.subarray(this._pos, this._pos + size);
|
|
864
|
+
this._pos += size;
|
|
865
|
+
return result;
|
|
866
|
+
}
|
|
867
|
+
startBitDecoding(decodeSize) {
|
|
868
|
+
let outSize = 0;
|
|
869
|
+
if (decodeSize) {
|
|
870
|
+
if (this._bitstreamVersion < bitstreamVersion(2, 2)) {
|
|
871
|
+
outSize = this.decodeUint64();
|
|
872
|
+
if (outSize === void 0) return void 0;
|
|
873
|
+
} else {
|
|
874
|
+
outSize = decodeVarint(this, false);
|
|
875
|
+
if (outSize === void 0) return void 0;
|
|
1056
876
|
}
|
|
1057
877
|
}
|
|
1058
|
-
this.
|
|
1059
|
-
this.
|
|
1060
|
-
return
|
|
878
|
+
this._bitMode = true;
|
|
879
|
+
this._bitDecoder.reset(this._data.subarray(this._pos), this._dataSize - this._pos);
|
|
880
|
+
return outSize;
|
|
1061
881
|
}
|
|
1062
|
-
|
|
1063
|
-
|
|
882
|
+
endBitDecoding() {
|
|
883
|
+
this._bitMode = false;
|
|
884
|
+
const bitsDecoded = this._bitDecoder.bitsDecoded();
|
|
885
|
+
const bytesDecoded = Math.ceil(bitsDecoded / 8);
|
|
886
|
+
this._pos += bytesDecoded;
|
|
1064
887
|
}
|
|
1065
|
-
|
|
1066
|
-
if (
|
|
1067
|
-
|
|
888
|
+
decodeLeastSignificantBits32(nbits) {
|
|
889
|
+
if (!this._bitMode) return void 0;
|
|
890
|
+
return this._bitDecoder.getBits(nbits);
|
|
891
|
+
}
|
|
892
|
+
decodeVarintUint32() {
|
|
893
|
+
return decodeVarint(this, false);
|
|
894
|
+
}
|
|
895
|
+
decodeVarintUint64() {
|
|
896
|
+
return decodeVarint(this, false);
|
|
897
|
+
}
|
|
898
|
+
advance(bytes) {
|
|
899
|
+
this._pos += bytes;
|
|
900
|
+
}
|
|
901
|
+
get bitstreamVersion() {
|
|
902
|
+
return this._bitstreamVersion;
|
|
903
|
+
}
|
|
904
|
+
set bitstreamVersion(v) {
|
|
905
|
+
this._bitstreamVersion = v;
|
|
906
|
+
}
|
|
907
|
+
get data() {
|
|
908
|
+
return this._data;
|
|
909
|
+
}
|
|
910
|
+
get dataHead() {
|
|
911
|
+
return this._data.subarray(this._pos);
|
|
912
|
+
}
|
|
913
|
+
get remainingSize() {
|
|
914
|
+
return this._dataSize - this._pos;
|
|
915
|
+
}
|
|
916
|
+
get decodedSize() {
|
|
917
|
+
return this._pos;
|
|
918
|
+
}
|
|
919
|
+
get bitDecoderActive() {
|
|
920
|
+
return this._bitMode;
|
|
921
|
+
}
|
|
922
|
+
};
|
|
923
|
+
|
|
924
|
+
// src/decoder/core/ScratchArena.ts
|
|
925
|
+
var freeInt32 = [];
|
|
926
|
+
var freeUint8 = [];
|
|
927
|
+
var borrowedInt32 = [];
|
|
928
|
+
var borrowedUint8 = [];
|
|
929
|
+
var acquire = (free, borrowed, size) => {
|
|
930
|
+
for (let i = free.length - 1; i >= 0; --i) {
|
|
931
|
+
const buffer = free[i];
|
|
932
|
+
if (buffer.length >= size) {
|
|
933
|
+
free[i] = free[free.length - 1];
|
|
934
|
+
free.pop();
|
|
935
|
+
borrowed.push(buffer);
|
|
936
|
+
return buffer;
|
|
1068
937
|
}
|
|
1069
|
-
return this.corner_table_.opposite(corner);
|
|
1070
938
|
}
|
|
1071
|
-
|
|
1072
|
-
|
|
939
|
+
return null;
|
|
940
|
+
};
|
|
941
|
+
var scratchInt32 = (size) => {
|
|
942
|
+
const pooled = acquire(freeInt32, borrowedInt32, size);
|
|
943
|
+
if (pooled !== null) return pooled.subarray(0, size);
|
|
944
|
+
const fresh = new Int32Array(size);
|
|
945
|
+
borrowedInt32.push(fresh);
|
|
946
|
+
return fresh;
|
|
947
|
+
};
|
|
948
|
+
var scratchUint8Zeroed = (size) => {
|
|
949
|
+
const pooled = acquire(freeUint8, borrowedUint8, size);
|
|
950
|
+
if (pooled !== null) {
|
|
951
|
+
const view = pooled.subarray(0, size);
|
|
952
|
+
view.fill(0);
|
|
953
|
+
return view;
|
|
1073
954
|
}
|
|
1074
|
-
|
|
1075
|
-
|
|
955
|
+
const fresh = new Uint8Array(size);
|
|
956
|
+
borrowedUint8.push(fresh);
|
|
957
|
+
return fresh;
|
|
958
|
+
};
|
|
959
|
+
var releaseScratch = () => {
|
|
960
|
+
for (const buffer of borrowedInt32) freeInt32.push(buffer);
|
|
961
|
+
for (const buffer of borrowedUint8) freeUint8.push(buffer);
|
|
962
|
+
borrowedInt32.length = 0;
|
|
963
|
+
borrowedUint8.length = 0;
|
|
964
|
+
};
|
|
965
|
+
|
|
966
|
+
// src/decoder/compression/config/CompressionShared.ts
|
|
967
|
+
var kDracoPointCloudBitstreamVersionMajor = 2;
|
|
968
|
+
var kDracoPointCloudBitstreamVersionMinor = 3;
|
|
969
|
+
var kDracoMeshBitstreamVersionMajor = 2;
|
|
970
|
+
var kDracoMeshBitstreamVersionMinor = 2;
|
|
971
|
+
function DRACO_BITSTREAM_VERSION(major, minor) {
|
|
972
|
+
return major << 8 | minor;
|
|
973
|
+
}
|
|
974
|
+
var EncodedGeometryType = {
|
|
975
|
+
INVALID_GEOMETRY_TYPE: -1,
|
|
976
|
+
POINT_CLOUD: 0,
|
|
977
|
+
TRIANGULAR_MESH: 1,
|
|
978
|
+
NUM_ENCODED_GEOMETRY_TYPES: 2
|
|
979
|
+
};
|
|
980
|
+
var MeshEncoderMethod = {
|
|
981
|
+
MESH_SEQUENTIAL_ENCODING: 0,
|
|
982
|
+
MESH_EDGEBREAKER_ENCODING: 1
|
|
983
|
+
};
|
|
984
|
+
var SequentialAttributeEncoderType = {
|
|
985
|
+
SEQUENTIAL_ATTRIBUTE_ENCODER_GENERIC: 0,
|
|
986
|
+
SEQUENTIAL_ATTRIBUTE_ENCODER_INTEGER: 1,
|
|
987
|
+
SEQUENTIAL_ATTRIBUTE_ENCODER_QUANTIZATION: 2,
|
|
988
|
+
SEQUENTIAL_ATTRIBUTE_ENCODER_NORMALS: 3
|
|
989
|
+
};
|
|
990
|
+
var PredictionSchemeMethod = {
|
|
991
|
+
PREDICTION_NONE: -2,
|
|
992
|
+
PREDICTION_UNDEFINED: -1,
|
|
993
|
+
PREDICTION_DIFFERENCE: 0,
|
|
994
|
+
MESH_PREDICTION_PARALLELOGRAM: 1,
|
|
995
|
+
MESH_PREDICTION_MULTI_PARALLELOGRAM: 2,
|
|
996
|
+
MESH_PREDICTION_TEX_COORDS_DEPRECATED: 3,
|
|
997
|
+
MESH_PREDICTION_CONSTRAINED_MULTI_PARALLELOGRAM: 4,
|
|
998
|
+
MESH_PREDICTION_TEX_COORDS_PORTABLE: 5,
|
|
999
|
+
MESH_PREDICTION_GEOMETRIC_NORMAL: 6,
|
|
1000
|
+
NUM_PREDICTION_SCHEMES: 7
|
|
1001
|
+
};
|
|
1002
|
+
var PredictionSchemeTransformType = {
|
|
1003
|
+
PREDICTION_TRANSFORM_NONE: -1,
|
|
1004
|
+
PREDICTION_TRANSFORM_DELTA: 0,
|
|
1005
|
+
PREDICTION_TRANSFORM_WRAP: 1,
|
|
1006
|
+
PREDICTION_TRANSFORM_NORMAL_OCTAHEDRON: 2,
|
|
1007
|
+
PREDICTION_TRANSFORM_NORMAL_OCTAHEDRON_CANONICALIZED: 3,
|
|
1008
|
+
NUM_PREDICTION_SCHEME_TRANSFORM_TYPES: 4
|
|
1009
|
+
};
|
|
1010
|
+
var MeshTraversalMethod = {
|
|
1011
|
+
MESH_TRAVERSAL_DEPTH_FIRST: 0,
|
|
1012
|
+
MESH_TRAVERSAL_PREDICTION_DEGREE: 1,
|
|
1013
|
+
NUM_TRAVERSAL_METHODS: 2
|
|
1014
|
+
};
|
|
1015
|
+
var MeshEdgebreakerConnectivityEncodingMethod = {
|
|
1016
|
+
MESH_EDGEBREAKER_STANDARD_ENCODING: 0,
|
|
1017
|
+
MESH_EDGEBREAKER_PREDICTIVE_ENCODING: 1,
|
|
1018
|
+
// Deprecated.
|
|
1019
|
+
MESH_EDGEBREAKER_VALENCE_ENCODING: 2
|
|
1020
|
+
};
|
|
1021
|
+
var DracoHeader = class {
|
|
1022
|
+
dracoString;
|
|
1023
|
+
versionMajor;
|
|
1024
|
+
versionMinor;
|
|
1025
|
+
encoderType;
|
|
1026
|
+
encoderMethod;
|
|
1027
|
+
flags;
|
|
1028
|
+
constructor() {
|
|
1029
|
+
this.dracoString = new Int8Array(5);
|
|
1030
|
+
this.versionMajor = 0;
|
|
1031
|
+
this.versionMinor = 0;
|
|
1032
|
+
this.encoderType = 0;
|
|
1033
|
+
this.encoderMethod = 0;
|
|
1034
|
+
this.flags = 0;
|
|
1076
1035
|
}
|
|
1077
|
-
|
|
1078
|
-
|
|
1036
|
+
};
|
|
1037
|
+
var NormalPredictionMode = {
|
|
1038
|
+
ONE_TRIANGLE: 0,
|
|
1039
|
+
// To be deprecated.
|
|
1040
|
+
TRIANGLE_AREA: 1
|
|
1041
|
+
};
|
|
1042
|
+
var SymbolCodingMethod = {
|
|
1043
|
+
SYMBOL_CODING_TAGGED: 0,
|
|
1044
|
+
SYMBOL_CODING_RAW: 1,
|
|
1045
|
+
NUM_SYMBOL_CODING_METHODS: 2
|
|
1046
|
+
};
|
|
1047
|
+
var METADATA_FLAG_MASK = 32768;
|
|
1048
|
+
|
|
1049
|
+
// src/decoder/compression/config/DracoOptions.ts
|
|
1050
|
+
var DracoOptions = class {
|
|
1051
|
+
_globalOptions;
|
|
1052
|
+
_attributeOptions;
|
|
1053
|
+
constructor() {
|
|
1054
|
+
this._globalOptions = /* @__PURE__ */ new Map();
|
|
1055
|
+
this._attributeOptions = /* @__PURE__ */ new Map();
|
|
1079
1056
|
}
|
|
1080
|
-
|
|
1081
|
-
|
|
1057
|
+
getGlobalBool(name, defaultVal) {
|
|
1058
|
+
if (this._globalOptions.has(name)) {
|
|
1059
|
+
return !!this._globalOptions.get(name);
|
|
1060
|
+
}
|
|
1061
|
+
return defaultVal;
|
|
1082
1062
|
}
|
|
1083
|
-
|
|
1084
|
-
|
|
1063
|
+
findAttributeOptions(attKey) {
|
|
1064
|
+
if (this._attributeOptions.has(attKey)) {
|
|
1065
|
+
return this._attributeOptions.get(attKey);
|
|
1066
|
+
}
|
|
1067
|
+
return null;
|
|
1085
1068
|
}
|
|
1086
|
-
|
|
1087
|
-
|
|
1069
|
+
getAttributeBool(attKey, name, defaultVal) {
|
|
1070
|
+
const attOpts = this.findAttributeOptions(attKey);
|
|
1071
|
+
if (attOpts !== null && attOpts.has(name)) {
|
|
1072
|
+
return !!attOpts.get(name);
|
|
1073
|
+
}
|
|
1074
|
+
return this.getGlobalBool(name, defaultVal);
|
|
1088
1075
|
}
|
|
1089
|
-
|
|
1090
|
-
|
|
1076
|
+
};
|
|
1077
|
+
|
|
1078
|
+
// src/decoder/compression/config/DecoderOptions.ts
|
|
1079
|
+
var DecoderOptions = class extends DracoOptions {
|
|
1080
|
+
constructor() {
|
|
1081
|
+
super();
|
|
1091
1082
|
}
|
|
1092
|
-
|
|
1093
|
-
|
|
1083
|
+
};
|
|
1084
|
+
|
|
1085
|
+
// src/decoder/core/Status.ts
|
|
1086
|
+
var StatusCode = {
|
|
1087
|
+
OK: 0,
|
|
1088
|
+
DRACO_ERROR: -1,
|
|
1089
|
+
IO_ERROR: -2,
|
|
1090
|
+
INVALID_PARAMETER: -3,
|
|
1091
|
+
UNSUPPORTED_VERSION: -4,
|
|
1092
|
+
UNKNOWN_VERSION: -5,
|
|
1093
|
+
UNSUPPORTED_FEATURE: -6
|
|
1094
|
+
};
|
|
1095
|
+
var Status = class {
|
|
1096
|
+
code;
|
|
1097
|
+
errorMsg;
|
|
1098
|
+
constructor(code = StatusCode.OK, errorMsg = "") {
|
|
1099
|
+
this.code = code;
|
|
1100
|
+
this.errorMsg = errorMsg;
|
|
1094
1101
|
}
|
|
1095
|
-
|
|
1096
|
-
return this.
|
|
1102
|
+
ok() {
|
|
1103
|
+
return this.code === StatusCode.OK;
|
|
1097
1104
|
}
|
|
1098
|
-
|
|
1099
|
-
|
|
1105
|
+
};
|
|
1106
|
+
function okStatus() {
|
|
1107
|
+
return new Status(StatusCode.OK);
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
// src/decoder/metadata/MetadataDecoder.ts
|
|
1111
|
+
var kMaxSubmetadataLevel = 1e3;
|
|
1112
|
+
var MetadataDecoder = class {
|
|
1113
|
+
buffer_;
|
|
1114
|
+
constructor() {
|
|
1115
|
+
this.buffer_ = null;
|
|
1100
1116
|
}
|
|
1101
|
-
//
|
|
1102
|
-
|
|
1103
|
-
|
|
1117
|
+
// Skips per-attribute metadata followed by the geometry-level metadata.
|
|
1118
|
+
skipGeometryMetadata(inBuffer) {
|
|
1119
|
+
this.buffer_ = inBuffer;
|
|
1120
|
+
const numAttMetadata = decodeVarint(this.buffer_);
|
|
1121
|
+
if (numAttMetadata === void 0) {
|
|
1122
|
+
return false;
|
|
1123
|
+
}
|
|
1124
|
+
for (let i = 0; i < numAttMetadata; ++i) {
|
|
1125
|
+
if (decodeVarint(this.buffer_) === void 0) {
|
|
1126
|
+
return false;
|
|
1127
|
+
}
|
|
1128
|
+
if (!this._skipMetadata(0)) {
|
|
1129
|
+
return false;
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
return this._skipMetadata(0);
|
|
1104
1133
|
}
|
|
1105
|
-
//
|
|
1106
|
-
// first
|
|
1107
|
-
|
|
1108
|
-
if (
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
eff[seamCorners[i]] = kInvalidCornerIndex;
|
|
1119
|
-
}
|
|
1120
|
-
this._effectiveOpposite = eff;
|
|
1134
|
+
// Discards one metadata block (key-value entries plus nested sub-metadata).
|
|
1135
|
+
// Sub-blocks read depth-first in stream order, matching the C++ stack traversal.
|
|
1136
|
+
_skipMetadata(level) {
|
|
1137
|
+
if (level > kMaxSubmetadataLevel) {
|
|
1138
|
+
return false;
|
|
1139
|
+
}
|
|
1140
|
+
const numEntries = decodeVarint(this.buffer_);
|
|
1141
|
+
if (numEntries === void 0) {
|
|
1142
|
+
return false;
|
|
1143
|
+
}
|
|
1144
|
+
for (let i = 0; i < numEntries; ++i) {
|
|
1145
|
+
if (!this._skipEntry()) {
|
|
1146
|
+
return false;
|
|
1121
1147
|
}
|
|
1122
1148
|
}
|
|
1123
|
-
|
|
1149
|
+
const numSubMetadata = decodeVarint(this.buffer_);
|
|
1150
|
+
if (numSubMetadata === void 0) {
|
|
1151
|
+
return false;
|
|
1152
|
+
}
|
|
1153
|
+
if (numSubMetadata > this.buffer_.remainingSize) {
|
|
1154
|
+
return false;
|
|
1155
|
+
}
|
|
1156
|
+
for (let i = 0; i < numSubMetadata; ++i) {
|
|
1157
|
+
if (!this._skipName()) {
|
|
1158
|
+
return false;
|
|
1159
|
+
}
|
|
1160
|
+
if (!this._skipMetadata(level + 1)) {
|
|
1161
|
+
return false;
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
return true;
|
|
1124
1165
|
}
|
|
1125
|
-
|
|
1126
|
-
|
|
1166
|
+
// Skips a key-value entry: name then a length-prefixed value.
|
|
1167
|
+
_skipEntry() {
|
|
1168
|
+
if (!this._skipName()) {
|
|
1169
|
+
return false;
|
|
1170
|
+
}
|
|
1171
|
+
const dataSize = decodeVarint(this.buffer_);
|
|
1172
|
+
if (dataSize === void 0 || dataSize === 0) {
|
|
1173
|
+
return false;
|
|
1174
|
+
}
|
|
1175
|
+
return this._skipBytes(dataSize);
|
|
1127
1176
|
}
|
|
1128
|
-
//
|
|
1129
|
-
|
|
1130
|
-
|
|
1177
|
+
// Skips a name (uint8 length prefix followed by that many bytes).
|
|
1178
|
+
_skipName() {
|
|
1179
|
+
const nameLen = this.buffer_.decodeUint8();
|
|
1180
|
+
if (nameLen === void 0) {
|
|
1181
|
+
return false;
|
|
1182
|
+
}
|
|
1183
|
+
if (nameLen === 0) {
|
|
1184
|
+
return true;
|
|
1185
|
+
}
|
|
1186
|
+
return this._skipBytes(nameLen);
|
|
1131
1187
|
}
|
|
1132
|
-
|
|
1133
|
-
if (
|
|
1134
|
-
|
|
1135
|
-
const seamB = other.is_edge_on_seam_;
|
|
1136
|
-
if (seamA.length !== seamB.length) return false;
|
|
1137
|
-
for (let i = 0, l = seamA.length; i < l; ++i) {
|
|
1138
|
-
if (seamA[i] !== seamB[i]) return false;
|
|
1188
|
+
_skipBytes(size) {
|
|
1189
|
+
if (size > this.buffer_.remainingSize) {
|
|
1190
|
+
return false;
|
|
1139
1191
|
}
|
|
1192
|
+
this.buffer_.advance(size);
|
|
1140
1193
|
return true;
|
|
1141
1194
|
}
|
|
1142
|
-
adoptVertexRecompute(other) {
|
|
1143
|
-
this.corner_to_vertex_map_ = other.corner_to_vertex_map_;
|
|
1144
|
-
this.vertex_to_attribute_entry_id_map_ = other.vertex_to_attribute_entry_id_map_;
|
|
1145
|
-
this.vertex_to_left_most_corner_map_ = other.vertex_to_left_most_corner_map_;
|
|
1146
|
-
this.no_interior_seams_ = other.no_interior_seams_;
|
|
1147
|
-
this._effectiveOpposite = other._effectiveOpposite;
|
|
1148
|
-
this._seamCorners = other._seamCorners;
|
|
1149
|
-
}
|
|
1150
|
-
};
|
|
1151
|
-
|
|
1152
|
-
// src/decoder/core/DracoTypes.ts
|
|
1153
|
-
var DataType = {
|
|
1154
|
-
INVALID: 0,
|
|
1155
|
-
INT8: 1,
|
|
1156
|
-
UINT8: 2,
|
|
1157
|
-
INT16: 3,
|
|
1158
|
-
UINT16: 4,
|
|
1159
|
-
INT32: 5,
|
|
1160
|
-
UINT32: 6,
|
|
1161
|
-
INT64: 7,
|
|
1162
|
-
UINT64: 8,
|
|
1163
|
-
FLOAT32: 9,
|
|
1164
|
-
FLOAT64: 10,
|
|
1165
|
-
BOOL: 11,
|
|
1166
|
-
TYPES_COUNT: 12
|
|
1167
1195
|
};
|
|
1168
|
-
function dataTypeLength(dt) {
|
|
1169
|
-
switch (dt) {
|
|
1170
|
-
case DataType.INT8:
|
|
1171
|
-
case DataType.UINT8:
|
|
1172
|
-
return 1;
|
|
1173
|
-
case DataType.INT16:
|
|
1174
|
-
case DataType.UINT16:
|
|
1175
|
-
return 2;
|
|
1176
|
-
case DataType.INT32:
|
|
1177
|
-
case DataType.UINT32:
|
|
1178
|
-
return 4;
|
|
1179
|
-
case DataType.INT64:
|
|
1180
|
-
case DataType.UINT64:
|
|
1181
|
-
return 8;
|
|
1182
|
-
case DataType.FLOAT32:
|
|
1183
|
-
return 4;
|
|
1184
|
-
case DataType.FLOAT64:
|
|
1185
|
-
return 8;
|
|
1186
|
-
case DataType.BOOL:
|
|
1187
|
-
return 1;
|
|
1188
|
-
default:
|
|
1189
|
-
return -1;
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
1196
|
|
|
1193
|
-
// src/decoder/
|
|
1194
|
-
var
|
|
1195
|
-
|
|
1196
|
-
POSITION: 0,
|
|
1197
|
-
NORMAL: 1,
|
|
1198
|
-
COLOR: 2,
|
|
1199
|
-
TEX_COORD: 3,
|
|
1200
|
-
GENERIC: 4,
|
|
1201
|
-
NAMED_ATTRIBUTES_COUNT: 5
|
|
1202
|
-
};
|
|
1203
|
-
var GeometryAttribute = class {
|
|
1197
|
+
// src/decoder/compression/point_cloud/PointCloudDecoder.ts
|
|
1198
|
+
var PointCloudDecoder = class _PointCloudDecoder {
|
|
1199
|
+
_pointCloud;
|
|
1204
1200
|
_buffer;
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
_attributeType;
|
|
1211
|
-
_uniqueId;
|
|
1201
|
+
_versionMajor;
|
|
1202
|
+
_versionMinor;
|
|
1203
|
+
_options;
|
|
1204
|
+
_attributesDecoders;
|
|
1205
|
+
_attributeToDecoderMap;
|
|
1212
1206
|
constructor() {
|
|
1207
|
+
this._pointCloud = null;
|
|
1213
1208
|
this._buffer = null;
|
|
1214
|
-
this.
|
|
1215
|
-
this.
|
|
1216
|
-
this.
|
|
1217
|
-
this.
|
|
1218
|
-
this.
|
|
1219
|
-
this._attributeType = Type.INVALID;
|
|
1220
|
-
this._uniqueId = 0;
|
|
1209
|
+
this._versionMajor = 0;
|
|
1210
|
+
this._versionMinor = 0;
|
|
1211
|
+
this._options = null;
|
|
1212
|
+
this._attributesDecoders = [];
|
|
1213
|
+
this._attributeToDecoderMap = [];
|
|
1221
1214
|
}
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
this._numComponents = numComponents;
|
|
1225
|
-
this._dataType = dataType;
|
|
1226
|
-
this._normalized = normalized;
|
|
1227
|
-
this._byteStride = byteStride;
|
|
1228
|
-
this._byteOffset = byteOffset;
|
|
1229
|
-
this._attributeType = attributeType;
|
|
1215
|
+
getGeometryType() {
|
|
1216
|
+
return EncodedGeometryType.POINT_CLOUD;
|
|
1230
1217
|
}
|
|
1231
|
-
// Returns a
|
|
1232
|
-
|
|
1233
|
-
const
|
|
1234
|
-
|
|
1218
|
+
// Returns a Status; on success outHeader is populated.
|
|
1219
|
+
static decodeHeader(buffer, outHeader) {
|
|
1220
|
+
const kIoErrorMsg = "Failed to parse Draco header.";
|
|
1221
|
+
const bytes = buffer.decodeBytes(5);
|
|
1222
|
+
if (bytes === void 0) {
|
|
1223
|
+
return new Status(StatusCode.IO_ERROR, kIoErrorMsg);
|
|
1224
|
+
}
|
|
1225
|
+
for (let i = 0; i < 5; i++) {
|
|
1226
|
+
outHeader.dracoString[i] = bytes[i];
|
|
1227
|
+
}
|
|
1228
|
+
const magic = String.fromCharCode(bytes[0], bytes[1], bytes[2], bytes[3], bytes[4]);
|
|
1229
|
+
if (magic !== "DRACO") {
|
|
1230
|
+
return new Status(StatusCode.DRACO_ERROR, "Not a Draco file.");
|
|
1231
|
+
}
|
|
1232
|
+
const versionMajor = buffer.decodeUint8();
|
|
1233
|
+
if (versionMajor === void 0) {
|
|
1234
|
+
return new Status(StatusCode.IO_ERROR, kIoErrorMsg);
|
|
1235
|
+
}
|
|
1236
|
+
outHeader.versionMajor = versionMajor;
|
|
1237
|
+
const versionMinor = buffer.decodeUint8();
|
|
1238
|
+
if (versionMinor === void 0) {
|
|
1239
|
+
return new Status(StatusCode.IO_ERROR, kIoErrorMsg);
|
|
1240
|
+
}
|
|
1241
|
+
outHeader.versionMinor = versionMinor;
|
|
1242
|
+
const encoderType = buffer.decodeUint8();
|
|
1243
|
+
if (encoderType === void 0) {
|
|
1244
|
+
return new Status(StatusCode.IO_ERROR, kIoErrorMsg);
|
|
1245
|
+
}
|
|
1246
|
+
outHeader.encoderType = encoderType;
|
|
1247
|
+
const encoderMethod = buffer.decodeUint8();
|
|
1248
|
+
if (encoderMethod === void 0) {
|
|
1249
|
+
return new Status(StatusCode.IO_ERROR, kIoErrorMsg);
|
|
1250
|
+
}
|
|
1251
|
+
outHeader.encoderMethod = encoderMethod;
|
|
1252
|
+
const flags = buffer.decodeUint16();
|
|
1253
|
+
if (flags === void 0) {
|
|
1254
|
+
return new Status(StatusCode.IO_ERROR, kIoErrorMsg);
|
|
1255
|
+
}
|
|
1256
|
+
outHeader.flags = flags;
|
|
1257
|
+
return okStatus();
|
|
1235
1258
|
}
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
this.
|
|
1239
|
-
this.
|
|
1240
|
-
this.
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1259
|
+
// Main entry point for point cloud decoding.
|
|
1260
|
+
decode(options, inBuffer, outPointCloud) {
|
|
1261
|
+
this._options = options;
|
|
1262
|
+
this._buffer = inBuffer;
|
|
1263
|
+
this._pointCloud = outPointCloud;
|
|
1264
|
+
const header = new DracoHeader();
|
|
1265
|
+
const headerStatus = _PointCloudDecoder.decodeHeader(this._buffer, header);
|
|
1266
|
+
if (!headerStatus.ok()) {
|
|
1267
|
+
return headerStatus;
|
|
1268
|
+
}
|
|
1269
|
+
if (header.encoderType !== this.getGeometryType()) {
|
|
1270
|
+
return new Status(StatusCode.DRACO_ERROR, "Using incompatible decoder for the input geometry.");
|
|
1271
|
+
}
|
|
1272
|
+
this._versionMajor = header.versionMajor;
|
|
1273
|
+
this._versionMinor = header.versionMinor;
|
|
1274
|
+
const maxSupportedMajorVersion = header.encoderType === EncodedGeometryType.POINT_CLOUD ? kDracoPointCloudBitstreamVersionMajor : kDracoMeshBitstreamVersionMajor;
|
|
1275
|
+
const maxSupportedMinorVersion = header.encoderType === EncodedGeometryType.POINT_CLOUD ? kDracoPointCloudBitstreamVersionMinor : kDracoMeshBitstreamVersionMinor;
|
|
1276
|
+
if (this._versionMajor < 1 || this._versionMajor > maxSupportedMajorVersion) {
|
|
1277
|
+
return new Status(StatusCode.UNKNOWN_VERSION, "Unknown major version.");
|
|
1278
|
+
}
|
|
1279
|
+
if (this._versionMajor === maxSupportedMajorVersion && this._versionMinor > maxSupportedMinorVersion) {
|
|
1280
|
+
return new Status(StatusCode.UNKNOWN_VERSION, "Unknown minor version.");
|
|
1281
|
+
}
|
|
1282
|
+
this._buffer.bitstreamVersion = DRACO_BITSTREAM_VERSION(this._versionMajor, this._versionMinor);
|
|
1283
|
+
if (header.encoderType === EncodedGeometryType.TRIANGULAR_MESH && this._buffer.bitstreamVersion < DRACO_BITSTREAM_VERSION(2, 2)) {
|
|
1284
|
+
return new Status(
|
|
1285
|
+
StatusCode.UNKNOWN_VERSION,
|
|
1286
|
+
"Unsupported bitstream version (only Draco 2.2 meshes are supported)."
|
|
1287
|
+
);
|
|
1288
|
+
}
|
|
1289
|
+
if (header.flags & METADATA_FLAG_MASK) {
|
|
1290
|
+
const metadataStatus = this._decodeMetadata();
|
|
1291
|
+
if (!metadataStatus.ok()) {
|
|
1292
|
+
return metadataStatus;
|
|
1249
1293
|
}
|
|
1250
|
-
this._buffer.update(srcAtt._buffer.data, srcAtt._buffer.dataSize);
|
|
1251
1294
|
}
|
|
1295
|
+
if (!this.initializeDecoder()) {
|
|
1296
|
+
return new Status(StatusCode.DRACO_ERROR, "Failed to initialize the decoder.");
|
|
1297
|
+
}
|
|
1298
|
+
if (!this.decodeGeometryData()) {
|
|
1299
|
+
return new Status(StatusCode.DRACO_ERROR, "Failed to decode geometry data.");
|
|
1300
|
+
}
|
|
1301
|
+
if (!this.decodePointAttributes()) {
|
|
1302
|
+
return new Status(StatusCode.DRACO_ERROR, "Failed to decode point attributes.");
|
|
1303
|
+
}
|
|
1304
|
+
return okStatus();
|
|
1305
|
+
}
|
|
1306
|
+
bitstreamVersion() {
|
|
1307
|
+
return DRACO_BITSTREAM_VERSION(this._versionMajor, this._versionMinor);
|
|
1308
|
+
}
|
|
1309
|
+
setAttributesDecoder(attDecoderId, decoder) {
|
|
1310
|
+
if (attDecoderId < 0) {
|
|
1311
|
+
return false;
|
|
1312
|
+
}
|
|
1313
|
+
while (this._attributesDecoders.length <= attDecoderId) {
|
|
1314
|
+
this._attributesDecoders.push(null);
|
|
1315
|
+
}
|
|
1316
|
+
this._attributesDecoders[attDecoderId] = decoder;
|
|
1252
1317
|
return true;
|
|
1253
1318
|
}
|
|
1254
|
-
|
|
1255
|
-
this.
|
|
1256
|
-
|
|
1257
|
-
|
|
1319
|
+
getPortableAttribute(parentAttId) {
|
|
1320
|
+
if (parentAttId < 0 || parentAttId >= this._pointCloud.numAttributes()) {
|
|
1321
|
+
return null;
|
|
1322
|
+
}
|
|
1323
|
+
const parentAttDecoderId = this._attributeToDecoderMap[parentAttId];
|
|
1324
|
+
return this._attributesDecoders[parentAttDecoderId].getPortableAttribute(parentAttId);
|
|
1258
1325
|
}
|
|
1259
|
-
|
|
1260
|
-
return this.
|
|
1326
|
+
attributesDecoder(decId) {
|
|
1327
|
+
return this._attributesDecoders[decId];
|
|
1261
1328
|
}
|
|
1262
|
-
|
|
1263
|
-
return this.
|
|
1329
|
+
numAttributesDecoders() {
|
|
1330
|
+
return this._attributesDecoders.length;
|
|
1264
1331
|
}
|
|
1265
|
-
|
|
1266
|
-
return this.
|
|
1332
|
+
pointCloud() {
|
|
1333
|
+
return this._pointCloud;
|
|
1267
1334
|
}
|
|
1268
|
-
|
|
1335
|
+
buffer() {
|
|
1269
1336
|
return this._buffer;
|
|
1270
1337
|
}
|
|
1271
|
-
|
|
1272
|
-
return this.
|
|
1273
|
-
}
|
|
1274
|
-
get byteOffset() {
|
|
1275
|
-
return this._byteOffset;
|
|
1338
|
+
options() {
|
|
1339
|
+
return this._options;
|
|
1276
1340
|
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1341
|
+
// -- Protected virtual methods (override in subclasses) --
|
|
1342
|
+
initializeDecoder() {
|
|
1343
|
+
return true;
|
|
1279
1344
|
}
|
|
1280
|
-
|
|
1281
|
-
|
|
1345
|
+
// Must be implemented by derived classes.
|
|
1346
|
+
createAttributesDecoder(_attDecoderId) {
|
|
1347
|
+
return false;
|
|
1282
1348
|
}
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
// src/decoder/core/DataBuffer.ts
|
|
1286
|
-
var DataBuffer = class {
|
|
1287
|
-
_data;
|
|
1288
|
-
constructor() {
|
|
1289
|
-
this._data = new Uint8Array(0);
|
|
1349
|
+
decodeGeometryData() {
|
|
1350
|
+
return true;
|
|
1290
1351
|
}
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
}
|
|
1296
|
-
|
|
1297
|
-
if (
|
|
1298
|
-
|
|
1352
|
+
decodePointAttributes() {
|
|
1353
|
+
const numAttributesDecoders = this._buffer.decodeUint8();
|
|
1354
|
+
if (numAttributesDecoders === void 0) {
|
|
1355
|
+
return false;
|
|
1356
|
+
}
|
|
1357
|
+
for (let i = 0; i < numAttributesDecoders; ++i) {
|
|
1358
|
+
if (!this.createAttributesDecoder(i)) {
|
|
1359
|
+
return false;
|
|
1299
1360
|
}
|
|
1300
|
-
const view = data;
|
|
1301
|
-
const src = new Uint8Array(view.buffer || data, view.byteOffset || 0, size);
|
|
1302
|
-
this._data.set(src, offset);
|
|
1303
1361
|
}
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
}
|
|
1309
|
-
write(bytePos, inArray, dataSize) {
|
|
1310
|
-
if (inArray instanceof Uint8Array) {
|
|
1311
|
-
this._data.set(inArray.length === dataSize ? inArray : inArray.subarray(0, dataSize), bytePos);
|
|
1312
|
-
return;
|
|
1362
|
+
for (let i = 0; i < this._attributesDecoders.length; ++i) {
|
|
1363
|
+
if (!this._attributesDecoders[i].init(this, this._pointCloud)) {
|
|
1364
|
+
return false;
|
|
1365
|
+
}
|
|
1313
1366
|
}
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
get data() {
|
|
1319
|
-
return this._data;
|
|
1320
|
-
}
|
|
1321
|
-
get dataSize() {
|
|
1322
|
-
return this._data.length;
|
|
1323
|
-
}
|
|
1324
|
-
_resize(newSize) {
|
|
1325
|
-
if (newSize === this._data.length) return;
|
|
1326
|
-
const newData = new Uint8Array(newSize);
|
|
1327
|
-
newData.set(this._data.subarray(0, Math.min(this._data.length, newSize)));
|
|
1328
|
-
this._data = newData;
|
|
1329
|
-
}
|
|
1330
|
-
};
|
|
1331
|
-
|
|
1332
|
-
// src/decoder/attributes/GeometryIndices.ts
|
|
1333
|
-
var kInvalidAttributeValueIndex = 4294967295 >>> 0;
|
|
1334
|
-
|
|
1335
|
-
// src/decoder/attributes/PointAttribute.ts
|
|
1336
|
-
var PointAttribute = class extends GeometryAttribute {
|
|
1337
|
-
_identityMapping;
|
|
1338
|
-
_numUniqueEntries;
|
|
1339
|
-
_indicesMap;
|
|
1340
|
-
_attributeBuffer;
|
|
1341
|
-
_attributeTransformData;
|
|
1342
|
-
// Lazily-created cached views over the attribute buffer.
|
|
1343
|
-
_cachedFloat32View;
|
|
1344
|
-
_cachedFloat32Buffer;
|
|
1345
|
-
_cachedInt32View;
|
|
1346
|
-
_cachedInt32Buffer;
|
|
1347
|
-
_cachedUint32View;
|
|
1348
|
-
_cachedUint32Buffer;
|
|
1349
|
-
_cachedUint16View;
|
|
1350
|
-
_cachedUint16Buffer;
|
|
1351
|
-
_cachedInt16View;
|
|
1352
|
-
_cachedInt16Buffer;
|
|
1353
|
-
_cachedUint8View;
|
|
1354
|
-
_cachedUint8Buffer;
|
|
1355
|
-
_cachedInt8View;
|
|
1356
|
-
_cachedInt8Buffer;
|
|
1357
|
-
_cachedFloat64View;
|
|
1358
|
-
_cachedFloat64Buffer;
|
|
1359
|
-
_cachedDataView;
|
|
1360
|
-
_cachedDVBuffer;
|
|
1361
|
-
constructor(geometryAttribute) {
|
|
1362
|
-
super();
|
|
1363
|
-
this._identityMapping = false;
|
|
1364
|
-
this._numUniqueEntries = 0;
|
|
1365
|
-
this._indicesMap = [];
|
|
1366
|
-
this._attributeBuffer = null;
|
|
1367
|
-
this._attributeTransformData = null;
|
|
1368
|
-
if (geometryAttribute instanceof GeometryAttribute) {
|
|
1369
|
-
this._buffer = geometryAttribute._buffer;
|
|
1370
|
-
this._numComponents = geometryAttribute._numComponents;
|
|
1371
|
-
this._dataType = geometryAttribute._dataType;
|
|
1372
|
-
this._normalized = geometryAttribute._normalized;
|
|
1373
|
-
this._byteStride = geometryAttribute._byteStride;
|
|
1374
|
-
this._byteOffset = geometryAttribute._byteOffset;
|
|
1375
|
-
this._attributeType = geometryAttribute._attributeType;
|
|
1376
|
-
this._uniqueId = geometryAttribute._uniqueId;
|
|
1367
|
+
for (let i = 0; i < numAttributesDecoders; ++i) {
|
|
1368
|
+
if (!this._attributesDecoders[i].decodeAttributesDecoderData(this._buffer)) {
|
|
1369
|
+
return false;
|
|
1370
|
+
}
|
|
1377
1371
|
}
|
|
1372
|
+
for (let i = 0; i < numAttributesDecoders; ++i) {
|
|
1373
|
+
const numAttributes = this._attributesDecoders[i].getNumAttributes();
|
|
1374
|
+
for (let j = 0; j < numAttributes; ++j) {
|
|
1375
|
+
const attId = this._attributesDecoders[i].getAttributeId(j);
|
|
1376
|
+
while (this._attributeToDecoderMap.length <= attId) {
|
|
1377
|
+
this._attributeToDecoderMap.push(0);
|
|
1378
|
+
}
|
|
1379
|
+
this._attributeToDecoderMap[attId] = i;
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
if (!this.decodeAllAttributes()) {
|
|
1383
|
+
return false;
|
|
1384
|
+
}
|
|
1385
|
+
if (!this.onAttributesDecoded()) {
|
|
1386
|
+
return false;
|
|
1387
|
+
}
|
|
1388
|
+
return true;
|
|
1378
1389
|
}
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
super.init(attributeType, this._attributeBuffer, numComponents, dataType, normalized, byteStride, 0);
|
|
1385
|
-
this.reset(numAttributeValues);
|
|
1386
|
-
this.setIdentityMapping();
|
|
1387
|
-
}
|
|
1388
|
-
reset(numAttributeValues) {
|
|
1389
|
-
if (this._attributeBuffer === null) {
|
|
1390
|
-
this._attributeBuffer = new DataBuffer();
|
|
1390
|
+
decodeAllAttributes() {
|
|
1391
|
+
for (let i = 0; i < this._attributesDecoders.length; i++) {
|
|
1392
|
+
if (!this._attributesDecoders[i].decodeAttributes(this._buffer)) {
|
|
1393
|
+
return false;
|
|
1394
|
+
}
|
|
1391
1395
|
}
|
|
1392
|
-
const entrySize = dataTypeLength(this.dataType) * this.numComponents;
|
|
1393
|
-
this._attributeBuffer.update(null, numAttributeValues * entrySize);
|
|
1394
|
-
this.resetBuffer(this._attributeBuffer, entrySize, 0);
|
|
1395
|
-
this._numUniqueEntries = numAttributeValues;
|
|
1396
1396
|
return true;
|
|
1397
1397
|
}
|
|
1398
|
-
|
|
1399
|
-
return
|
|
1398
|
+
onAttributesDecoded() {
|
|
1399
|
+
return true;
|
|
1400
1400
|
}
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1401
|
+
_decodeMetadata() {
|
|
1402
|
+
const metadataDecoder = new MetadataDecoder();
|
|
1403
|
+
if (!metadataDecoder.skipGeometryMetadata(this._buffer)) {
|
|
1404
|
+
return new Status(StatusCode.DRACO_ERROR, "Failed to decode metadata.");
|
|
1404
1405
|
}
|
|
1405
|
-
return
|
|
1406
|
+
return okStatus();
|
|
1406
1407
|
}
|
|
1407
|
-
|
|
1408
|
-
|
|
1408
|
+
};
|
|
1409
|
+
|
|
1410
|
+
// src/decoder/compression/mesh/MeshDecoder.ts
|
|
1411
|
+
var MeshDecoder = class extends PointCloudDecoder {
|
|
1412
|
+
_mesh;
|
|
1413
|
+
constructor() {
|
|
1414
|
+
super();
|
|
1415
|
+
this._mesh = null;
|
|
1409
1416
|
}
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
return 0;
|
|
1413
|
-
}
|
|
1414
|
-
return this._indicesMap.length;
|
|
1417
|
+
getGeometryType() {
|
|
1418
|
+
return EncodedGeometryType.TRIANGULAR_MESH;
|
|
1415
1419
|
}
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
get indicesMap() {
|
|
1420
|
-
return this._indicesMap;
|
|
1420
|
+
decodeMesh(options, inBuffer, outMesh) {
|
|
1421
|
+
this._mesh = outMesh;
|
|
1422
|
+
return this.decode(options, inBuffer, outMesh);
|
|
1421
1423
|
}
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
this._identityMapping = true;
|
|
1425
|
-
this._indicesMap = [];
|
|
1424
|
+
getCornerTable() {
|
|
1425
|
+
return null;
|
|
1426
1426
|
}
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
this._indicesMap = new Uint32Array(numPoints);
|
|
1430
|
-
this._indicesMap.fill(kInvalidAttributeValueIndex);
|
|
1427
|
+
getAttributeCornerTable(_attId) {
|
|
1428
|
+
return null;
|
|
1431
1429
|
}
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
// time on primitive-heavy files). The array still starts zeroed by the
|
|
1435
|
-
// engine, so a buggy caller reads valid-looking zeros — hence opt-in.
|
|
1436
|
-
setExplicitMappingUnfilled(numPoints) {
|
|
1437
|
-
this._identityMapping = false;
|
|
1438
|
-
this._indicesMap = new Uint32Array(numPoints);
|
|
1430
|
+
getAttributeEncodingData(_attId) {
|
|
1431
|
+
return null;
|
|
1439
1432
|
}
|
|
1440
|
-
|
|
1441
|
-
this.
|
|
1433
|
+
mesh() {
|
|
1434
|
+
return this._mesh;
|
|
1442
1435
|
}
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
const bufData = this._buffer.data;
|
|
1447
|
-
const dt = this._dataType;
|
|
1448
|
-
const nc = this._numComponents;
|
|
1449
|
-
if (dt === DataType.FLOAT32) {
|
|
1450
|
-
if (this._cachedFloat32View === void 0 || this._cachedFloat32Buffer !== bufData.buffer) {
|
|
1451
|
-
this._cachedFloat32Buffer = bufData.buffer;
|
|
1452
|
-
this._cachedFloat32View = new Float32Array(bufData.buffer);
|
|
1453
|
-
}
|
|
1454
|
-
const baseIndex = bufData.byteOffset + bytePos >> 2;
|
|
1455
|
-
for (let i = 0; i < nc; ++i) {
|
|
1456
|
-
outVal[i] = this._cachedFloat32View[baseIndex + i];
|
|
1457
|
-
}
|
|
1458
|
-
return;
|
|
1459
|
-
}
|
|
1460
|
-
if (dt === DataType.INT32) {
|
|
1461
|
-
if (this._cachedInt32View === void 0 || this._cachedInt32Buffer !== bufData.buffer) {
|
|
1462
|
-
this._cachedInt32Buffer = bufData.buffer;
|
|
1463
|
-
this._cachedInt32View = new Int32Array(bufData.buffer);
|
|
1464
|
-
}
|
|
1465
|
-
const baseIndex = bufData.byteOffset + bytePos >> 2;
|
|
1466
|
-
for (let i = 0; i < nc; ++i) {
|
|
1467
|
-
outVal[i] = this._cachedInt32View[baseIndex + i];
|
|
1468
|
-
}
|
|
1469
|
-
return;
|
|
1470
|
-
}
|
|
1471
|
-
if (dt === DataType.UINT32) {
|
|
1472
|
-
if (this._cachedUint32View === void 0 || this._cachedUint32Buffer !== bufData.buffer) {
|
|
1473
|
-
this._cachedUint32Buffer = bufData.buffer;
|
|
1474
|
-
this._cachedUint32View = new Uint32Array(bufData.buffer);
|
|
1475
|
-
}
|
|
1476
|
-
const baseIndex = bufData.byteOffset + bytePos >> 2;
|
|
1477
|
-
for (let i = 0; i < nc; ++i) {
|
|
1478
|
-
outVal[i] = this._cachedUint32View[baseIndex + i];
|
|
1479
|
-
}
|
|
1480
|
-
return;
|
|
1481
|
-
}
|
|
1482
|
-
if (this._cachedDataView === void 0 || this._cachedDVBuffer !== bufData.buffer) {
|
|
1483
|
-
this._cachedDVBuffer = bufData.buffer;
|
|
1484
|
-
this._cachedDataView = new DataView(bufData.buffer, bufData.byteOffset, bufData.byteLength);
|
|
1436
|
+
decodeGeometryData() {
|
|
1437
|
+
if (this._mesh === null) {
|
|
1438
|
+
return false;
|
|
1485
1439
|
}
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
switch (dt) {
|
|
1489
|
-
case DataType.INT8:
|
|
1490
|
-
outVal[i] = dv.getInt8(bytePos + i);
|
|
1491
|
-
break;
|
|
1492
|
-
case DataType.UINT8:
|
|
1493
|
-
outVal[i] = dv.getUint8(bytePos + i);
|
|
1494
|
-
break;
|
|
1495
|
-
case DataType.INT16:
|
|
1496
|
-
outVal[i] = dv.getInt16(bytePos + i * 2, true);
|
|
1497
|
-
break;
|
|
1498
|
-
case DataType.UINT16:
|
|
1499
|
-
outVal[i] = dv.getUint16(bytePos + i * 2, true);
|
|
1500
|
-
break;
|
|
1501
|
-
case DataType.INT32:
|
|
1502
|
-
outVal[i] = dv.getInt32(bytePos + i * 4, true);
|
|
1503
|
-
break;
|
|
1504
|
-
case DataType.UINT32:
|
|
1505
|
-
outVal[i] = dv.getUint32(bytePos + i * 4, true);
|
|
1506
|
-
break;
|
|
1507
|
-
case DataType.FLOAT64:
|
|
1508
|
-
outVal[i] = dv.getFloat64(bytePos + i * 8, true);
|
|
1509
|
-
break;
|
|
1510
|
-
default:
|
|
1511
|
-
outVal[i] = 0;
|
|
1512
|
-
break;
|
|
1513
|
-
}
|
|
1440
|
+
if (!this.decodeConnectivity()) {
|
|
1441
|
+
return false;
|
|
1514
1442
|
}
|
|
1443
|
+
return super.decodeGeometryData();
|
|
1515
1444
|
}
|
|
1516
|
-
//
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1445
|
+
// Overridden by derived classes.
|
|
1446
|
+
decodeConnectivity() {
|
|
1447
|
+
return false;
|
|
1448
|
+
}
|
|
1449
|
+
};
|
|
1450
|
+
|
|
1451
|
+
// src/decoder/mesh/MeshAttributeCornerTable.ts
|
|
1452
|
+
var kInvalidCornerIndex = -1;
|
|
1453
|
+
var kInvalidVertexIndex = -1;
|
|
1454
|
+
var MeshAttributeCornerTable = class {
|
|
1455
|
+
is_edge_on_seam_;
|
|
1456
|
+
is_vertex_on_seam_;
|
|
1457
|
+
no_interior_seams_;
|
|
1458
|
+
corner_to_vertex_map_;
|
|
1459
|
+
vertex_to_left_most_corner_map_;
|
|
1460
|
+
vertex_to_attribute_entry_id_map_;
|
|
1461
|
+
corner_table_;
|
|
1462
|
+
// Lazily built; see oppositeCornerArray.
|
|
1463
|
+
_effectiveOpposite;
|
|
1464
|
+
// Every corner passed to addSeamEdge (may contain duplicates); lets
|
|
1465
|
+
// oppositeCornerArray patch seams without scanning every corner's flag.
|
|
1466
|
+
_seamCorners;
|
|
1467
|
+
constructor() {
|
|
1468
|
+
this.is_edge_on_seam_ = [];
|
|
1469
|
+
this.is_vertex_on_seam_ = [];
|
|
1470
|
+
this.no_interior_seams_ = true;
|
|
1471
|
+
this.corner_to_vertex_map_ = [];
|
|
1472
|
+
this.vertex_to_left_most_corner_map_ = [];
|
|
1473
|
+
this.vertex_to_attribute_entry_id_map_ = [];
|
|
1474
|
+
this.corner_table_ = null;
|
|
1475
|
+
this._effectiveOpposite = null;
|
|
1476
|
+
this._seamCorners = [];
|
|
1477
|
+
}
|
|
1478
|
+
initEmpty(table) {
|
|
1479
|
+
if (table === null) {
|
|
1480
|
+
return false;
|
|
1523
1481
|
}
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
} else if (dt === DataType.UINT16) {
|
|
1554
|
-
if (this._cachedUint16View === void 0 || this._cachedUint16Buffer !== bufData.buffer) {
|
|
1555
|
-
this._cachedUint16Buffer = bufData.buffer;
|
|
1556
|
-
this._cachedUint16View = new Uint16Array(bufData.buffer);
|
|
1557
|
-
}
|
|
1558
|
-
srcView = this._cachedUint16View;
|
|
1559
|
-
shift = 1;
|
|
1560
|
-
} else if (dt === DataType.INT16) {
|
|
1561
|
-
if (this._cachedInt16View === void 0 || this._cachedInt16Buffer !== bufData.buffer) {
|
|
1562
|
-
this._cachedInt16Buffer = bufData.buffer;
|
|
1563
|
-
this._cachedInt16View = new Int16Array(bufData.buffer);
|
|
1564
|
-
}
|
|
1565
|
-
srcView = this._cachedInt16View;
|
|
1566
|
-
shift = 1;
|
|
1567
|
-
} else if (dt === DataType.UINT8) {
|
|
1568
|
-
if (this._cachedUint8View === void 0 || this._cachedUint8Buffer !== bufData.buffer) {
|
|
1569
|
-
this._cachedUint8Buffer = bufData.buffer;
|
|
1570
|
-
this._cachedUint8View = new Uint8Array(bufData.buffer);
|
|
1571
|
-
}
|
|
1572
|
-
srcView = this._cachedUint8View;
|
|
1573
|
-
shift = 0;
|
|
1574
|
-
} else if (dt === DataType.INT8) {
|
|
1575
|
-
if (this._cachedInt8View === void 0 || this._cachedInt8Buffer !== bufData.buffer) {
|
|
1576
|
-
this._cachedInt8Buffer = bufData.buffer;
|
|
1577
|
-
this._cachedInt8View = new Int8Array(bufData.buffer);
|
|
1578
|
-
}
|
|
1579
|
-
srcView = this._cachedInt8View;
|
|
1580
|
-
shift = 0;
|
|
1581
|
-
} else if (dt === DataType.FLOAT64) {
|
|
1582
|
-
if (this._cachedFloat64View === void 0 || this._cachedFloat64Buffer !== bufData.buffer) {
|
|
1583
|
-
this._cachedFloat64Buffer = bufData.buffer;
|
|
1584
|
-
this._cachedFloat64View = new Float64Array(bufData.buffer);
|
|
1585
|
-
}
|
|
1586
|
-
srcView = this._cachedFloat64View;
|
|
1587
|
-
shift = 3;
|
|
1482
|
+
this.is_edge_on_seam_ = new Uint8Array(table.numCorners());
|
|
1483
|
+
this.is_vertex_on_seam_ = new Uint8Array(table.numVertices());
|
|
1484
|
+
this.corner_to_vertex_map_ = new Int32Array(table.numCorners()).fill(kInvalidVertexIndex);
|
|
1485
|
+
this.vertex_to_attribute_entry_id_map_ = [];
|
|
1486
|
+
this.vertex_to_left_most_corner_map_ = [];
|
|
1487
|
+
this._effectiveOpposite = null;
|
|
1488
|
+
this._seamCorners = [];
|
|
1489
|
+
this.corner_table_ = table;
|
|
1490
|
+
this.no_interior_seams_ = true;
|
|
1491
|
+
return true;
|
|
1492
|
+
}
|
|
1493
|
+
addSeamEdge(c) {
|
|
1494
|
+
const cornerToVertex = this.corner_table_.cornerToVertexArray();
|
|
1495
|
+
const oppositeCorners = this.corner_table_.oppositeCornerArray();
|
|
1496
|
+
const isEdge = this.is_edge_on_seam_;
|
|
1497
|
+
const isVert = this.is_vertex_on_seam_;
|
|
1498
|
+
isEdge[c] = 1;
|
|
1499
|
+
this._seamCorners.push(c);
|
|
1500
|
+
let rem = c - (c / 3 | 0) * 3;
|
|
1501
|
+
isVert[cornerToVertex[rem === 2 ? c - 2 : c + 1]] = 1;
|
|
1502
|
+
isVert[cornerToVertex[rem === 0 ? c + 2 : c - 1]] = 1;
|
|
1503
|
+
const oppCorner = oppositeCorners[c];
|
|
1504
|
+
if (oppCorner !== kInvalidCornerIndex) {
|
|
1505
|
+
this.no_interior_seams_ = false;
|
|
1506
|
+
isEdge[oppCorner] = 1;
|
|
1507
|
+
this._seamCorners.push(oppCorner);
|
|
1508
|
+
rem = oppCorner - (oppCorner / 3 | 0) * 3;
|
|
1509
|
+
isVert[cornerToVertex[rem === 2 ? oppCorner - 2 : oppCorner + 1]] = 1;
|
|
1510
|
+
isVert[cornerToVertex[rem === 0 ? oppCorner + 2 : oppCorner - 1]] = 1;
|
|
1588
1511
|
}
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
array[dst + 1] = srcView[srcOffset + 1];
|
|
1623
|
-
dst += 2;
|
|
1624
|
-
}
|
|
1625
|
-
} else if (numComponents === 4) {
|
|
1626
|
-
let dst = 0;
|
|
1627
|
-
for (let i = 0; i < numPoints; i++) {
|
|
1628
|
-
const srcOffset = srcStart + indicesMap[i] * strideElements;
|
|
1629
|
-
array[dst] = srcView[srcOffset];
|
|
1630
|
-
array[dst + 1] = srcView[srcOffset + 1];
|
|
1631
|
-
array[dst + 2] = srcView[srcOffset + 2];
|
|
1632
|
-
array[dst + 3] = srcView[srcOffset + 3];
|
|
1633
|
-
dst += 4;
|
|
1634
|
-
}
|
|
1635
|
-
} else if (numComponents === 1) {
|
|
1636
|
-
let dst = 0;
|
|
1637
|
-
for (let i = 0; i < numPoints; i++) {
|
|
1638
|
-
array[dst++] = srcView[srcStart + indicesMap[i] * strideElements];
|
|
1512
|
+
}
|
|
1513
|
+
recomputeVertices(_cornerTable, _vertexIds) {
|
|
1514
|
+
return this._recomputeVerticesInternal();
|
|
1515
|
+
}
|
|
1516
|
+
// Only the C++ RecomputeVertices(nullptr, nullptr) path: the decoder always
|
|
1517
|
+
// rebuilds the attribute-vertex maps from connectivity alone.
|
|
1518
|
+
_recomputeVerticesInternal() {
|
|
1519
|
+
const ct = this.corner_table_;
|
|
1520
|
+
const numCorners = ct.numCorners();
|
|
1521
|
+
const numBaseVertices = ct.numVertices();
|
|
1522
|
+
const leftMostMap = new Int32Array(numCorners);
|
|
1523
|
+
const cornerToVertex = this.corner_to_vertex_map_;
|
|
1524
|
+
const isVertexOnSeam = this.is_vertex_on_seam_;
|
|
1525
|
+
const isEdgeOnSeam = this.is_edge_on_seam_;
|
|
1526
|
+
const seamOpp = this.oppositeCornerArray();
|
|
1527
|
+
const baseOpp = ct.oppositeCornerArray();
|
|
1528
|
+
const vertexLeftmost = ct.vertexLeftmostCornerArray();
|
|
1529
|
+
let numNewVertices = 0;
|
|
1530
|
+
for (let v = 0; v < numBaseVertices; ++v) {
|
|
1531
|
+
const c = vertexLeftmost[v];
|
|
1532
|
+
if (c === kInvalidCornerIndex) continue;
|
|
1533
|
+
if (!isVertexOnSeam[v]) {
|
|
1534
|
+
const firstVertId = numNewVertices++;
|
|
1535
|
+
leftMostMap[firstVertId] = c;
|
|
1536
|
+
cornerToVertex[c] = firstVertId;
|
|
1537
|
+
let pv = c % 3 === 0 ? c + 2 : c - 1;
|
|
1538
|
+
let bopp = baseOpp[pv];
|
|
1539
|
+
let actC = bopp < 0 ? kInvalidCornerIndex : bopp % 3 === 0 ? bopp + 2 : bopp - 1;
|
|
1540
|
+
while (actC !== kInvalidCornerIndex && actC !== c) {
|
|
1541
|
+
cornerToVertex[actC] = firstVertId;
|
|
1542
|
+
pv = actC % 3 === 0 ? actC + 2 : actC - 1;
|
|
1543
|
+
bopp = baseOpp[pv];
|
|
1544
|
+
actC = bopp < 0 ? kInvalidCornerIndex : bopp % 3 === 0 ? bopp + 2 : bopp - 1;
|
|
1639
1545
|
}
|
|
1640
1546
|
} else {
|
|
1641
|
-
let
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1547
|
+
let firstVertId = numNewVertices++;
|
|
1548
|
+
let firstC = c;
|
|
1549
|
+
let actC;
|
|
1550
|
+
let nx = firstC % 3 === 2 ? firstC - 2 : firstC + 1;
|
|
1551
|
+
let opp = seamOpp[nx];
|
|
1552
|
+
actC = opp < 0 ? kInvalidCornerIndex : opp % 3 === 2 ? opp - 2 : opp + 1;
|
|
1553
|
+
while (actC !== kInvalidCornerIndex) {
|
|
1554
|
+
firstC = actC;
|
|
1555
|
+
nx = firstC % 3 === 2 ? firstC - 2 : firstC + 1;
|
|
1556
|
+
opp = seamOpp[nx];
|
|
1557
|
+
actC = opp < 0 ? kInvalidCornerIndex : opp % 3 === 2 ? opp - 2 : opp + 1;
|
|
1558
|
+
if (actC === c) return false;
|
|
1559
|
+
}
|
|
1560
|
+
cornerToVertex[firstC] = firstVertId;
|
|
1561
|
+
leftMostMap[firstVertId] = firstC;
|
|
1562
|
+
let pv = firstC % 3 === 0 ? firstC + 2 : firstC - 1;
|
|
1563
|
+
let bopp = baseOpp[pv];
|
|
1564
|
+
actC = bopp < 0 ? kInvalidCornerIndex : bopp % 3 === 0 ? bopp + 2 : bopp - 1;
|
|
1565
|
+
while (actC !== kInvalidCornerIndex && actC !== firstC) {
|
|
1566
|
+
const nAct = actC % 3 === 2 ? actC - 2 : actC + 1;
|
|
1567
|
+
if (isEdgeOnSeam[nAct]) {
|
|
1568
|
+
firstVertId = numNewVertices++;
|
|
1569
|
+
leftMostMap[firstVertId] = actC;
|
|
1646
1570
|
}
|
|
1647
|
-
|
|
1571
|
+
cornerToVertex[actC] = firstVertId;
|
|
1572
|
+
pv = actC % 3 === 0 ? actC + 2 : actC - 1;
|
|
1573
|
+
bopp = baseOpp[pv];
|
|
1574
|
+
actC = bopp < 0 ? kInvalidCornerIndex : bopp % 3 === 0 ? bopp + 2 : bopp - 1;
|
|
1648
1575
|
}
|
|
1649
1576
|
}
|
|
1650
|
-
return array;
|
|
1651
|
-
}
|
|
1652
|
-
const temp = new Array(numComponents);
|
|
1653
|
-
for (let i = 0; i < numPoints; i++) {
|
|
1654
|
-
const attIndex = isIdentity ? i : indicesMap[i];
|
|
1655
|
-
this.convertValue(attIndex, temp);
|
|
1656
|
-
const dstOffset = i * numComponents;
|
|
1657
|
-
for (let j = 0; j < numComponents; j++) {
|
|
1658
|
-
array[dstOffset + j] = temp[j];
|
|
1659
|
-
}
|
|
1660
1577
|
}
|
|
1661
|
-
|
|
1578
|
+
this.vertex_to_attribute_entry_id_map_ = new Int32Array(numNewVertices);
|
|
1579
|
+
this.vertex_to_left_most_corner_map_ = leftMostMap.subarray(0, numNewVertices);
|
|
1580
|
+
return true;
|
|
1662
1581
|
}
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1582
|
+
isCornerOppositeToSeamEdge(corner) {
|
|
1583
|
+
return this.is_edge_on_seam_[corner];
|
|
1584
|
+
}
|
|
1585
|
+
opposite(corner) {
|
|
1586
|
+
if (corner === kInvalidCornerIndex || this.isCornerOppositeToSeamEdge(corner)) {
|
|
1587
|
+
return kInvalidCornerIndex;
|
|
1669
1588
|
}
|
|
1670
|
-
|
|
1671
|
-
|
|
1589
|
+
return this.corner_table_.opposite(corner);
|
|
1590
|
+
}
|
|
1591
|
+
next(corner) {
|
|
1592
|
+
return this.corner_table_.next(corner);
|
|
1593
|
+
}
|
|
1594
|
+
previous(corner) {
|
|
1595
|
+
return this.corner_table_.previous(corner);
|
|
1596
|
+
}
|
|
1597
|
+
swingRight(corner) {
|
|
1598
|
+
return this.previous(this.opposite(this.previous(corner)));
|
|
1599
|
+
}
|
|
1600
|
+
swingLeft(corner) {
|
|
1601
|
+
return this.next(this.opposite(this.next(corner)));
|
|
1602
|
+
}
|
|
1603
|
+
numVertices() {
|
|
1604
|
+
return this.vertex_to_attribute_entry_id_map_.length;
|
|
1605
|
+
}
|
|
1606
|
+
numFaces() {
|
|
1607
|
+
return this.corner_table_.numFaces();
|
|
1608
|
+
}
|
|
1609
|
+
numCorners() {
|
|
1610
|
+
return this.corner_table_.numCorners();
|
|
1611
|
+
}
|
|
1612
|
+
vertex(corner) {
|
|
1613
|
+
return this.confidentVertex(corner);
|
|
1614
|
+
}
|
|
1615
|
+
confidentVertex(corner) {
|
|
1616
|
+
return this.corner_to_vertex_map_[corner];
|
|
1617
|
+
}
|
|
1618
|
+
leftMostCorner(v) {
|
|
1619
|
+
return this.vertex_to_left_most_corner_map_[v];
|
|
1620
|
+
}
|
|
1621
|
+
// --- Flat-array accessors: let DepthFirstTraverser avoid per-corner dispatch. ---
|
|
1622
|
+
cornerToVertexArray() {
|
|
1623
|
+
return this.corner_to_vertex_map_;
|
|
1624
|
+
}
|
|
1625
|
+
// Seam-aware opposite corners (seam edges -> -1), matching opposite(). Cached on
|
|
1626
|
+
// first use; seams and connectivity are finalized before traversal, so it's stable.
|
|
1627
|
+
oppositeCornerArray() {
|
|
1628
|
+
if (this._effectiveOpposite === null) {
|
|
1629
|
+
const nc = this.corner_table_.numCorners();
|
|
1630
|
+
const base = this.corner_table_.oppositeCornerArray();
|
|
1631
|
+
const seamCorners = this._seamCorners;
|
|
1632
|
+
if (seamCorners.length === 0) {
|
|
1633
|
+
this._effectiveOpposite = base;
|
|
1634
|
+
} else {
|
|
1635
|
+
const eff = scratchInt32(nc);
|
|
1636
|
+
eff.set(base.length === nc ? base : base.subarray(0, nc));
|
|
1637
|
+
for (let i = 0, l = seamCorners.length; i < l; ++i) {
|
|
1638
|
+
eff[seamCorners[i]] = kInvalidCornerIndex;
|
|
1639
|
+
}
|
|
1640
|
+
this._effectiveOpposite = eff;
|
|
1641
|
+
}
|
|
1672
1642
|
}
|
|
1673
|
-
this.
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1643
|
+
return this._effectiveOpposite;
|
|
1644
|
+
}
|
|
1645
|
+
vertexLeftmostCornerArray() {
|
|
1646
|
+
return this.vertex_to_left_most_corner_map_;
|
|
1647
|
+
}
|
|
1648
|
+
// Per-base-vertex seam flag (Uint8Array); exposed so hot dedup loops inline the lookup.
|
|
1649
|
+
vertexOnSeamArray() {
|
|
1650
|
+
return this.is_vertex_on_seam_;
|
|
1651
|
+
}
|
|
1652
|
+
hasSameSeams(other) {
|
|
1653
|
+
if (other === null || other === void 0) return false;
|
|
1654
|
+
const seamA = this.is_edge_on_seam_;
|
|
1655
|
+
const seamB = other.is_edge_on_seam_;
|
|
1656
|
+
if (seamA.length !== seamB.length) return false;
|
|
1657
|
+
for (let i = 0, l = seamA.length; i < l; ++i) {
|
|
1658
|
+
if (seamA[i] !== seamB[i]) return false;
|
|
1680
1659
|
}
|
|
1660
|
+
return true;
|
|
1661
|
+
}
|
|
1662
|
+
adoptVertexRecompute(other) {
|
|
1663
|
+
this.corner_to_vertex_map_ = other.corner_to_vertex_map_;
|
|
1664
|
+
this.vertex_to_attribute_entry_id_map_ = other.vertex_to_attribute_entry_id_map_;
|
|
1665
|
+
this.vertex_to_left_most_corner_map_ = other.vertex_to_left_most_corner_map_;
|
|
1666
|
+
this.no_interior_seams_ = other.no_interior_seams_;
|
|
1667
|
+
this._effectiveOpposite = other._effectiveOpposite;
|
|
1668
|
+
this._seamCorners = other._seamCorners;
|
|
1681
1669
|
}
|
|
1682
1670
|
};
|
|
1683
1671
|
|
|
@@ -3992,7 +3980,7 @@ var SequentialIntegerAttributeDecoder = class extends SequentialAttributeDecoder
|
|
|
3992
3980
|
if (portableAttributeData.byteLength < 4 * numValues) {
|
|
3993
3981
|
return false;
|
|
3994
3982
|
}
|
|
3995
|
-
const bytes = buffer.
|
|
3983
|
+
const bytes = buffer.decodeBytesView(4 * numValues);
|
|
3996
3984
|
if (bytes === void 0) return false;
|
|
3997
3985
|
const srcView = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
3998
3986
|
for (let i = 0; i < numValues; i++) {
|
|
@@ -4002,12 +3990,13 @@ var SequentialIntegerAttributeDecoder = class extends SequentialAttributeDecoder
|
|
|
4002
3990
|
if (buffer.remainingSize < numBytes * numValues) {
|
|
4003
3991
|
return false;
|
|
4004
3992
|
}
|
|
3993
|
+
const bytes = buffer.decodeBytesView(numBytes * numValues);
|
|
3994
|
+
if (bytes === void 0) return false;
|
|
4005
3995
|
for (let i = 0; i < numValues; i++) {
|
|
4006
|
-
const valueBytes = buffer.decodeBytes(numBytes);
|
|
4007
|
-
if (valueBytes === void 0) return false;
|
|
4008
3996
|
let val = 0;
|
|
3997
|
+
const valueOffset = i * numBytes;
|
|
4009
3998
|
for (let b = 0; b < numBytes; b++) {
|
|
4010
|
-
val |=
|
|
3999
|
+
val |= bytes[valueOffset + b] << b * 8;
|
|
4011
4000
|
}
|
|
4012
4001
|
portableAttributeData[i] = val;
|
|
4013
4002
|
}
|
|
@@ -6154,7 +6143,8 @@ var CornerTable = class {
|
|
|
6154
6143
|
const newVertex = this._numVertices;
|
|
6155
6144
|
this._numVertices++;
|
|
6156
6145
|
if (newVertex >= this._vertexCorners.length) {
|
|
6157
|
-
const
|
|
6146
|
+
const newCapacity = Math.max(newVertex + 1, this._vertexCorners.length * 2, 64);
|
|
6147
|
+
const newArr = new Int32Array(newCapacity);
|
|
6158
6148
|
newArr.fill(-1);
|
|
6159
6149
|
newArr.set(this._vertexCorners);
|
|
6160
6150
|
this._vertexCorners = newArr;
|
|
@@ -6770,13 +6760,11 @@ var Decoder = class {
|
|
|
6770
6760
|
var decodeDracoMesh = (data) => {
|
|
6771
6761
|
const buffer = new DecoderBuffer();
|
|
6772
6762
|
buffer.init(data, data.length);
|
|
6773
|
-
if (Decoder.getEncodedGeometryType(buffer) !== EncodedGeometryType.TRIANGULAR_MESH) {
|
|
6774
|
-
throw new Error("minidraco: Input is not a Draco triangular mesh.");
|
|
6775
|
-
}
|
|
6776
6763
|
const decoder = new Decoder();
|
|
6777
6764
|
const result = decoder.decodeMeshFromBuffer(buffer);
|
|
6778
6765
|
if (!result.ok || result.mesh === null) {
|
|
6779
|
-
|
|
6766
|
+
const message = result.message === "Input is not a mesh." ? "Input is not a Draco triangular mesh." : result.message;
|
|
6767
|
+
throw new Error(`minidraco: ${message}`);
|
|
6780
6768
|
}
|
|
6781
6769
|
return result.mesh;
|
|
6782
6770
|
};
|
|
@@ -6800,17 +6788,17 @@ var _typedArrayMap = {
|
|
|
6800
6788
|
Uint16Array,
|
|
6801
6789
|
Uint32Array
|
|
6802
6790
|
};
|
|
6803
|
-
var
|
|
6791
|
+
var MinidracoLoader = class extends Loader {
|
|
6804
6792
|
defaultAttributeIDs;
|
|
6805
6793
|
defaultAttributeTypes;
|
|
6806
6794
|
workerLimit;
|
|
6807
|
-
// Opt-in (0 = disabled): buffers at or below this size decode
|
|
6808
|
-
//
|
|
6795
|
+
// Opt-in (0 = disabled): buffers at or below this size decode on the main
|
|
6796
|
+
// thread instead of paying the ~0.5 ms worker message roundtrip.
|
|
6809
6797
|
// Worth enabling (e.g. 4096) when the main thread is otherwise idle during
|
|
6810
6798
|
// loads — in a full GLTFLoader parse the main thread is already busy
|
|
6811
6799
|
// building geometries, and measurements show the pool wins there even for
|
|
6812
6800
|
// tiny primitives.
|
|
6813
|
-
|
|
6801
|
+
mainThreadByteThreshold;
|
|
6814
6802
|
_workers;
|
|
6815
6803
|
_taskId;
|
|
6816
6804
|
_tasks;
|
|
@@ -6842,7 +6830,7 @@ var MiniDRACOLoader = class extends Loader {
|
|
|
6842
6830
|
uv: "Float32Array"
|
|
6843
6831
|
};
|
|
6844
6832
|
this.workerLimit = options.workers === false ? 0 : options.workerLimit ?? 4;
|
|
6845
|
-
this.
|
|
6833
|
+
this.mainThreadByteThreshold = options.mainThreadByteThreshold ?? 0;
|
|
6846
6834
|
this._workers = [];
|
|
6847
6835
|
this._taskId = 0;
|
|
6848
6836
|
this._tasks = /* @__PURE__ */ new Map();
|
|
@@ -6864,7 +6852,7 @@ var MiniDRACOLoader = class extends Loader {
|
|
|
6864
6852
|
// no external decoder files to configure. The params are `unknown` (not
|
|
6865
6853
|
// `string`/`object`) so the signatures stay assignable to THREE.DRACOLoader
|
|
6866
6854
|
// across three versions, whose setDecoderPath has grown to accept a
|
|
6867
|
-
// `string | DecoderPaths` — letting `new
|
|
6855
|
+
// `string | DecoderPaths` — letting `new MinidracoLoader()` be passed to
|
|
6868
6856
|
// GLTFLoader.setDRACOLoader() with no cast.
|
|
6869
6857
|
setDecoderPath(_path) {
|
|
6870
6858
|
return this;
|
|
@@ -6894,7 +6882,7 @@ var MiniDRACOLoader = class extends Loader {
|
|
|
6894
6882
|
dispose() {
|
|
6895
6883
|
for (const entry of this._workers) entry.worker.terminate();
|
|
6896
6884
|
this._workers = [];
|
|
6897
|
-
const disposedError = new Error("
|
|
6885
|
+
const disposedError = new Error("MinidracoLoader: disposed while decoding");
|
|
6898
6886
|
disposedError.isDecodeError = true;
|
|
6899
6887
|
for (const task of this._batch) task.reject(disposedError);
|
|
6900
6888
|
this._batch = [];
|
|
@@ -6950,7 +6938,7 @@ var MiniDRACOLoader = class extends Loader {
|
|
|
6950
6938
|
}
|
|
6951
6939
|
async _runTask(buffer, taskConfig) {
|
|
6952
6940
|
if (this._workersAvailable()) {
|
|
6953
|
-
if (buffer.byteLength > this.
|
|
6941
|
+
if (buffer.byteLength > this.mainThreadByteThreshold) {
|
|
6954
6942
|
try {
|
|
6955
6943
|
const raw = await this._decodeInWorker(buffer, taskConfig);
|
|
6956
6944
|
return this._buildGeometryFromRaw(raw, taskConfig);
|
|
@@ -7007,7 +6995,7 @@ var MiniDRACOLoader = class extends Loader {
|
|
|
7007
6995
|
for (const [id, task] of this._tasks) {
|
|
7008
6996
|
if (task.entry.worker === worker) {
|
|
7009
6997
|
this._tasks.delete(id);
|
|
7010
|
-
task.reject(new Error(`
|
|
6998
|
+
task.reject(new Error(`MinidracoLoader worker failed: ${event.message ?? "unknown error"}`));
|
|
7011
6999
|
}
|
|
7012
7000
|
}
|
|
7013
7001
|
};
|
|
@@ -7036,7 +7024,7 @@ var MiniDRACOLoader = class extends Loader {
|
|
|
7036
7024
|
while (this._workers.length < Math.min(this.workerLimit, batch.length) && this._getWorker() !== null) {
|
|
7037
7025
|
}
|
|
7038
7026
|
if (this._workersBroken || this._workers.length === 0) {
|
|
7039
|
-
const error = new Error("
|
|
7027
|
+
const error = new Error("MinidracoLoader: worker unavailable");
|
|
7040
7028
|
for (const task of batch) task.reject(error);
|
|
7041
7029
|
return;
|
|
7042
7030
|
}
|
|
@@ -7132,6 +7120,6 @@ var MiniDRACOLoader = class extends Loader {
|
|
|
7132
7120
|
}
|
|
7133
7121
|
};
|
|
7134
7122
|
export {
|
|
7135
|
-
|
|
7136
|
-
|
|
7123
|
+
MinidracoLoader as DRACOLoader,
|
|
7124
|
+
MinidracoLoader
|
|
7137
7125
|
};
|