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