@loaders.gl/draco 3.1.0-beta.7 → 3.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.min.js +3 -3
- package/dist/dist.min.js.map +2 -2
- package/dist/draco-loader.js +1 -1
- package/dist/draco-worker.js +1 -1
- package/dist/draco-worker.js.map +3 -3
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/draco-loader.js +8 -4
- package/dist/es5/draco-loader.js.map +1 -1
- package/dist/es5/draco-writer.js +46 -13
- package/dist/es5/draco-writer.js.map +1 -1
- package/dist/es5/draco3d/draco3d-types.js +4 -4
- package/dist/es5/index.js +51 -16
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/draco-builder.js +292 -244
- package/dist/es5/lib/draco-builder.js.map +1 -1
- package/dist/es5/lib/draco-module-loader.js +198 -65
- package/dist/es5/lib/draco-module-loader.js.map +1 -1
- package/dist/es5/lib/draco-parser.js +372 -308
- package/dist/es5/lib/draco-parser.js.map +1 -1
- package/dist/es5/lib/utils/get-draco-schema.js +15 -15
- package/dist/es5/lib/utils/get-draco-schema.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/es5/lib/utils/version.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/esm/lib/utils/version.js.map +1 -1
- package/package.json +5 -5
|
@@ -7,23 +7,41 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
|
|
10
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
+
|
|
12
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
13
|
+
|
|
14
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
15
|
+
|
|
16
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
|
+
|
|
10
18
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
19
|
|
|
12
20
|
var _schema = require("@loaders.gl/schema");
|
|
13
21
|
|
|
14
22
|
var _getDracoSchema = require("./utils/get-draco-schema");
|
|
15
23
|
|
|
16
|
-
|
|
24
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
25
|
+
|
|
26
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
27
|
+
|
|
28
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
29
|
+
|
|
30
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
31
|
+
|
|
32
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
33
|
+
|
|
34
|
+
var GEOMETRY_TYPE = {
|
|
17
35
|
TRIANGULAR_MESH: 0,
|
|
18
36
|
POINT_CLOUD: 1
|
|
19
37
|
};
|
|
20
|
-
|
|
38
|
+
var DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP = {
|
|
21
39
|
POSITION: 'POSITION',
|
|
22
40
|
NORMAL: 'NORMAL',
|
|
23
41
|
COLOR: 'COLOR_0',
|
|
24
42
|
TEX_COORD: 'TEXCOORD_0'
|
|
25
43
|
};
|
|
26
|
-
|
|
44
|
+
var DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP = {
|
|
27
45
|
1: Int8Array,
|
|
28
46
|
2: Uint8Array,
|
|
29
47
|
3: Int16Array,
|
|
@@ -32,10 +50,11 @@ const DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP = {
|
|
|
32
50
|
6: Uint32Array,
|
|
33
51
|
9: Float32Array
|
|
34
52
|
};
|
|
35
|
-
|
|
53
|
+
var INDEX_ITEM_SIZE = 4;
|
|
36
54
|
|
|
37
|
-
|
|
38
|
-
|
|
55
|
+
var DracoParser = function () {
|
|
56
|
+
function DracoParser(draco) {
|
|
57
|
+
(0, _classCallCheck2.default)(this, DracoParser);
|
|
39
58
|
(0, _defineProperty2.default)(this, "draco", void 0);
|
|
40
59
|
(0, _defineProperty2.default)(this, "decoder", void 0);
|
|
41
60
|
(0, _defineProperty2.default)(this, "metadataQuerier", void 0);
|
|
@@ -44,371 +63,416 @@ class DracoParser {
|
|
|
44
63
|
this.metadataQuerier = new this.draco.MetadataQuerier();
|
|
45
64
|
}
|
|
46
65
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
66
|
+
(0, _createClass2.default)(DracoParser, [{
|
|
67
|
+
key: "destroy",
|
|
68
|
+
value: function destroy() {
|
|
69
|
+
this.draco.destroy(this.decoder);
|
|
70
|
+
this.draco.destroy(this.metadataQuerier);
|
|
71
|
+
}
|
|
72
|
+
}, {
|
|
73
|
+
key: "parseSync",
|
|
74
|
+
value: function parseSync(arrayBuffer) {
|
|
75
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
76
|
+
var buffer = new this.draco.DecoderBuffer();
|
|
77
|
+
buffer.Init(new Int8Array(arrayBuffer), arrayBuffer.byteLength);
|
|
55
78
|
|
|
56
|
-
|
|
79
|
+
this._disableAttributeTransforms(options);
|
|
57
80
|
|
|
58
|
-
|
|
59
|
-
|
|
81
|
+
var geometry_type = this.decoder.GetEncodedGeometryType(buffer);
|
|
82
|
+
var dracoGeometry = geometry_type === this.draco.TRIANGULAR_MESH ? new this.draco.Mesh() : new this.draco.PointCloud();
|
|
60
83
|
|
|
61
|
-
|
|
62
|
-
|
|
84
|
+
try {
|
|
85
|
+
var dracoStatus;
|
|
63
86
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
87
|
+
switch (geometry_type) {
|
|
88
|
+
case this.draco.TRIANGULAR_MESH:
|
|
89
|
+
dracoStatus = this.decoder.DecodeBufferToMesh(buffer, dracoGeometry);
|
|
90
|
+
break;
|
|
68
91
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
92
|
+
case this.draco.POINT_CLOUD:
|
|
93
|
+
dracoStatus = this.decoder.DecodeBufferToPointCloud(buffer, dracoGeometry);
|
|
94
|
+
break;
|
|
72
95
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
96
|
+
default:
|
|
97
|
+
throw new Error('DRACO: Unknown geometry type.');
|
|
98
|
+
}
|
|
76
99
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
100
|
+
if (!dracoStatus.ok() || !dracoGeometry.ptr) {
|
|
101
|
+
var message = "DRACO decompression failed: ".concat(dracoStatus.error_msg());
|
|
102
|
+
throw new Error(message);
|
|
103
|
+
}
|
|
81
104
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const geometry = this._getMeshData(dracoGeometry, loaderData, options);
|
|
85
|
-
|
|
86
|
-
const boundingBox = (0, _schema.getMeshBoundingBox)(geometry.attributes);
|
|
87
|
-
const schema = (0, _getDracoSchema.getDracoSchema)(geometry.attributes, loaderData, geometry.indices);
|
|
88
|
-
const data = {
|
|
89
|
-
loader: 'draco',
|
|
90
|
-
loaderData,
|
|
91
|
-
header: {
|
|
92
|
-
vertexCount: dracoGeometry.num_points(),
|
|
93
|
-
boundingBox
|
|
94
|
-
},
|
|
95
|
-
...geometry,
|
|
96
|
-
schema
|
|
97
|
-
};
|
|
98
|
-
return data;
|
|
99
|
-
} finally {
|
|
100
|
-
this.draco.destroy(buffer);
|
|
105
|
+
var loaderData = this._getDracoLoaderData(dracoGeometry, geometry_type, options);
|
|
101
106
|
|
|
102
|
-
|
|
103
|
-
this.draco.destroy(dracoGeometry);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
+
var geometry = this._getMeshData(dracoGeometry, loaderData, options);
|
|
107
108
|
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
var boundingBox = (0, _schema.getMeshBoundingBox)(geometry.attributes);
|
|
110
|
+
var schema = (0, _getDracoSchema.getDracoSchema)(geometry.attributes, loaderData, geometry.indices);
|
|
110
111
|
|
|
111
|
-
|
|
112
|
+
var data = _objectSpread(_objectSpread({
|
|
113
|
+
loader: 'draco',
|
|
114
|
+
loaderData: loaderData,
|
|
115
|
+
header: {
|
|
116
|
+
vertexCount: dracoGeometry.num_points(),
|
|
117
|
+
boundingBox: boundingBox
|
|
118
|
+
}
|
|
119
|
+
}, geometry), {}, {
|
|
120
|
+
schema: schema
|
|
121
|
+
});
|
|
112
122
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
num_points: dracoGeometry.num_points(),
|
|
117
|
-
num_faces: dracoGeometry instanceof this.draco.Mesh ? dracoGeometry.num_faces() : 0,
|
|
118
|
-
metadata,
|
|
119
|
-
attributes
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
_getDracoAttributes(dracoGeometry, options) {
|
|
124
|
-
const dracoAttributes = {};
|
|
123
|
+
return data;
|
|
124
|
+
} finally {
|
|
125
|
+
this.draco.destroy(buffer);
|
|
125
126
|
|
|
126
|
-
|
|
127
|
-
|
|
127
|
+
if (dracoGeometry) {
|
|
128
|
+
this.draco.destroy(dracoGeometry);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}, {
|
|
133
|
+
key: "_getDracoLoaderData",
|
|
134
|
+
value: function _getDracoLoaderData(dracoGeometry, geometry_type, options) {
|
|
135
|
+
var metadata = this._getTopLevelMetadata(dracoGeometry);
|
|
128
136
|
|
|
129
|
-
|
|
137
|
+
var attributes = this._getDracoAttributes(dracoGeometry, options);
|
|
130
138
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
normalized: dracoAttribute.normalized(),
|
|
139
|
-
attribute_index: attributeId,
|
|
140
|
-
metadata
|
|
139
|
+
return {
|
|
140
|
+
geometry_type: geometry_type,
|
|
141
|
+
num_attributes: dracoGeometry.num_attributes(),
|
|
142
|
+
num_points: dracoGeometry.num_points(),
|
|
143
|
+
num_faces: dracoGeometry instanceof this.draco.Mesh ? dracoGeometry.num_faces() : 0,
|
|
144
|
+
metadata: metadata,
|
|
145
|
+
attributes: attributes
|
|
141
146
|
};
|
|
147
|
+
}
|
|
148
|
+
}, {
|
|
149
|
+
key: "_getDracoAttributes",
|
|
150
|
+
value: function _getDracoAttributes(dracoGeometry, options) {
|
|
151
|
+
var dracoAttributes = {};
|
|
152
|
+
|
|
153
|
+
for (var attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) {
|
|
154
|
+
var dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attributeId);
|
|
155
|
+
|
|
156
|
+
var metadata = this._getAttributeMetadata(dracoGeometry, attributeId);
|
|
157
|
+
|
|
158
|
+
dracoAttributes[dracoAttribute.unique_id()] = {
|
|
159
|
+
unique_id: dracoAttribute.unique_id(),
|
|
160
|
+
attribute_type: dracoAttribute.attribute_type(),
|
|
161
|
+
data_type: dracoAttribute.data_type(),
|
|
162
|
+
num_components: dracoAttribute.num_components(),
|
|
163
|
+
byte_offset: dracoAttribute.byte_offset(),
|
|
164
|
+
byte_stride: dracoAttribute.byte_stride(),
|
|
165
|
+
normalized: dracoAttribute.normalized(),
|
|
166
|
+
attribute_index: attributeId,
|
|
167
|
+
metadata: metadata
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
var quantization = this._getQuantizationTransform(dracoAttribute, options);
|
|
171
|
+
|
|
172
|
+
if (quantization) {
|
|
173
|
+
dracoAttributes[dracoAttribute.unique_id()].quantization_transform = quantization;
|
|
174
|
+
}
|
|
142
175
|
|
|
143
|
-
|
|
176
|
+
var octahedron = this._getOctahedronTransform(dracoAttribute, options);
|
|
144
177
|
|
|
145
|
-
|
|
146
|
-
|
|
178
|
+
if (octahedron) {
|
|
179
|
+
dracoAttributes[dracoAttribute.unique_id()].octahedron_transform = octahedron;
|
|
180
|
+
}
|
|
147
181
|
}
|
|
148
182
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (octahedron) {
|
|
152
|
-
dracoAttributes[dracoAttribute.unique_id()].octahedron_transform = octahedron;
|
|
153
|
-
}
|
|
183
|
+
return dracoAttributes;
|
|
154
184
|
}
|
|
185
|
+
}, {
|
|
186
|
+
key: "_getMeshData",
|
|
187
|
+
value: function _getMeshData(dracoGeometry, loaderData, options) {
|
|
188
|
+
var attributes = this._getMeshAttributes(loaderData, dracoGeometry, options);
|
|
155
189
|
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
_getMeshData(dracoGeometry, loaderData, options) {
|
|
160
|
-
const attributes = this._getMeshAttributes(loaderData, dracoGeometry, options);
|
|
161
|
-
|
|
162
|
-
const positionAttribute = attributes.POSITION;
|
|
190
|
+
var positionAttribute = attributes.POSITION;
|
|
163
191
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (dracoGeometry instanceof this.draco.Mesh) {
|
|
169
|
-
switch (options.topology) {
|
|
170
|
-
case 'triangle-strip':
|
|
171
|
-
return {
|
|
172
|
-
topology: 'triangle-strip',
|
|
173
|
-
mode: 4,
|
|
174
|
-
attributes,
|
|
175
|
-
indices: {
|
|
176
|
-
value: this._getTriangleStripIndices(dracoGeometry),
|
|
177
|
-
size: 1
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
case 'triangle-list':
|
|
182
|
-
default:
|
|
183
|
-
return {
|
|
184
|
-
topology: 'triangle-list',
|
|
185
|
-
mode: 5,
|
|
186
|
-
attributes,
|
|
187
|
-
indices: {
|
|
188
|
-
value: this._getTriangleListIndices(dracoGeometry),
|
|
189
|
-
size: 1
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
+
if (!positionAttribute) {
|
|
193
|
+
throw new Error('DRACO: No position attribute found.');
|
|
192
194
|
}
|
|
193
|
-
}
|
|
194
195
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
196
|
+
if (dracoGeometry instanceof this.draco.Mesh) {
|
|
197
|
+
switch (options.topology) {
|
|
198
|
+
case 'triangle-strip':
|
|
199
|
+
return {
|
|
200
|
+
topology: 'triangle-strip',
|
|
201
|
+
mode: 4,
|
|
202
|
+
attributes: attributes,
|
|
203
|
+
indices: {
|
|
204
|
+
value: this._getTriangleStripIndices(dracoGeometry),
|
|
205
|
+
size: 1
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
case 'triangle-list':
|
|
210
|
+
default:
|
|
211
|
+
return {
|
|
212
|
+
topology: 'triangle-list',
|
|
213
|
+
mode: 5,
|
|
214
|
+
attributes: attributes,
|
|
215
|
+
indices: {
|
|
216
|
+
value: this._getTriangleListIndices(dracoGeometry),
|
|
217
|
+
size: 1
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
}
|
|
214
222
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
byteStride: loaderAttribute.byte_stride,
|
|
220
|
-
normalized: loaderAttribute.normalized
|
|
223
|
+
return {
|
|
224
|
+
topology: 'point-list',
|
|
225
|
+
mode: 0,
|
|
226
|
+
attributes: attributes
|
|
221
227
|
};
|
|
222
228
|
}
|
|
229
|
+
}, {
|
|
230
|
+
key: "_getMeshAttributes",
|
|
231
|
+
value: function _getMeshAttributes(loaderData, dracoGeometry, options) {
|
|
232
|
+
var attributes = {};
|
|
223
233
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
_getTriangleListIndices(dracoGeometry) {
|
|
228
|
-
const numFaces = dracoGeometry.num_faces();
|
|
229
|
-
const numIndices = numFaces * 3;
|
|
230
|
-
const byteLength = numIndices * INDEX_ITEM_SIZE;
|
|
234
|
+
for (var _i = 0, _Object$values = Object.values(loaderData.attributes); _i < _Object$values.length; _i++) {
|
|
235
|
+
var loaderAttribute = _Object$values[_i];
|
|
231
236
|
|
|
232
|
-
|
|
237
|
+
var _attributeName = this._deduceAttributeName(loaderAttribute, options);
|
|
233
238
|
|
|
234
|
-
|
|
235
|
-
this.decoder.GetTrianglesUInt32Array(dracoGeometry, byteLength, ptr);
|
|
236
|
-
return new Uint32Array(this.draco.HEAPF32.buffer, ptr, numIndices).slice();
|
|
237
|
-
} finally {
|
|
238
|
-
this.draco._free(ptr);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
239
|
+
loaderAttribute.name = _attributeName;
|
|
241
240
|
|
|
242
|
-
|
|
243
|
-
|
|
241
|
+
var _this$_getAttributeVa = this._getAttributeValues(dracoGeometry, loaderAttribute),
|
|
242
|
+
value = _this$_getAttributeVa.value,
|
|
243
|
+
size = _this$_getAttributeVa.size;
|
|
244
244
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
245
|
+
attributes[_attributeName] = {
|
|
246
|
+
value: value,
|
|
247
|
+
size: size,
|
|
248
|
+
byteOffset: loaderAttribute.byte_offset,
|
|
249
|
+
byteStride: loaderAttribute.byte_stride,
|
|
250
|
+
normalized: loaderAttribute.normalized
|
|
251
|
+
};
|
|
252
|
+
}
|
|
252
253
|
|
|
253
|
-
|
|
254
|
-
const TypedArrayCtor = DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP[attribute.data_type];
|
|
255
|
-
const numComponents = attribute.num_components;
|
|
256
|
-
const numPoints = dracoGeometry.num_points();
|
|
257
|
-
const numValues = numPoints * numComponents;
|
|
258
|
-
const byteLength = numValues * TypedArrayCtor.BYTES_PER_ELEMENT;
|
|
259
|
-
const dataType = getDracoDataType(this.draco, TypedArrayCtor);
|
|
260
|
-
let value;
|
|
261
|
-
|
|
262
|
-
const ptr = this.draco._malloc(byteLength);
|
|
263
|
-
|
|
264
|
-
try {
|
|
265
|
-
const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attribute.attribute_index);
|
|
266
|
-
this.decoder.GetAttributeDataArrayForAllPoints(dracoGeometry, dracoAttribute, dataType, byteLength, ptr);
|
|
267
|
-
value = new TypedArrayCtor(this.draco.HEAPF32.buffer, ptr, numValues).slice();
|
|
268
|
-
} finally {
|
|
269
|
-
this.draco._free(ptr);
|
|
254
|
+
return attributes;
|
|
270
255
|
}
|
|
256
|
+
}, {
|
|
257
|
+
key: "_getTriangleListIndices",
|
|
258
|
+
value: function _getTriangleListIndices(dracoGeometry) {
|
|
259
|
+
var numFaces = dracoGeometry.num_faces();
|
|
260
|
+
var numIndices = numFaces * 3;
|
|
261
|
+
var byteLength = numIndices * INDEX_ITEM_SIZE;
|
|
271
262
|
|
|
272
|
-
|
|
273
|
-
value,
|
|
274
|
-
size: numComponents
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
_deduceAttributeName(attribute, options) {
|
|
279
|
-
const uniqueId = attribute.unique_id;
|
|
263
|
+
var ptr = this.draco._malloc(byteLength);
|
|
280
264
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
return
|
|
265
|
+
try {
|
|
266
|
+
this.decoder.GetTrianglesUInt32Array(dracoGeometry, byteLength, ptr);
|
|
267
|
+
return new Uint32Array(this.draco.HEAPF32.buffer, ptr, numIndices).slice();
|
|
268
|
+
} finally {
|
|
269
|
+
this.draco._free(ptr);
|
|
284
270
|
}
|
|
285
271
|
}
|
|
272
|
+
}, {
|
|
273
|
+
key: "_getTriangleStripIndices",
|
|
274
|
+
value: function _getTriangleStripIndices(dracoGeometry) {
|
|
275
|
+
var dracoArray = new this.draco.DracoInt32Array();
|
|
286
276
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
if (attributeType === thisAttributeType) {
|
|
293
|
-
return DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP[dracoAttributeConstant];
|
|
277
|
+
try {
|
|
278
|
+
this.decoder.GetTriangleStripsFromMesh(dracoGeometry, dracoArray);
|
|
279
|
+
return getUint32Array(dracoArray);
|
|
280
|
+
} finally {
|
|
281
|
+
this.draco.destroy(dracoArray);
|
|
294
282
|
}
|
|
295
283
|
}
|
|
284
|
+
}, {
|
|
285
|
+
key: "_getAttributeValues",
|
|
286
|
+
value: function _getAttributeValues(dracoGeometry, attribute) {
|
|
287
|
+
var TypedArrayCtor = DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP[attribute.data_type];
|
|
288
|
+
var numComponents = attribute.num_components;
|
|
289
|
+
var numPoints = dracoGeometry.num_points();
|
|
290
|
+
var numValues = numPoints * numComponents;
|
|
291
|
+
var byteLength = numValues * TypedArrayCtor.BYTES_PER_ELEMENT;
|
|
292
|
+
var dataType = getDracoDataType(this.draco, TypedArrayCtor);
|
|
293
|
+
var value;
|
|
294
|
+
|
|
295
|
+
var ptr = this.draco._malloc(byteLength);
|
|
296
296
|
|
|
297
|
-
|
|
297
|
+
try {
|
|
298
|
+
var dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attribute.attribute_index);
|
|
299
|
+
this.decoder.GetAttributeDataArrayForAllPoints(dracoGeometry, dracoAttribute, dataType, byteLength, ptr);
|
|
300
|
+
value = new TypedArrayCtor(this.draco.HEAPF32.buffer, ptr, numValues).slice();
|
|
301
|
+
} finally {
|
|
302
|
+
this.draco._free(ptr);
|
|
303
|
+
}
|
|
298
304
|
|
|
299
|
-
|
|
300
|
-
|
|
305
|
+
return {
|
|
306
|
+
value: value,
|
|
307
|
+
size: numComponents
|
|
308
|
+
};
|
|
301
309
|
}
|
|
310
|
+
}, {
|
|
311
|
+
key: "_deduceAttributeName",
|
|
312
|
+
value: function _deduceAttributeName(attribute, options) {
|
|
313
|
+
var uniqueId = attribute.unique_id;
|
|
314
|
+
|
|
315
|
+
for (var _i2 = 0, _Object$entries = Object.entries(options.extraAttributes || {}); _i2 < _Object$entries.length; _i2++) {
|
|
316
|
+
var _Object$entries$_i = (0, _slicedToArray2.default)(_Object$entries[_i2], 2),
|
|
317
|
+
_attributeName2 = _Object$entries$_i[0],
|
|
318
|
+
attributeUniqueId = _Object$entries$_i[1];
|
|
319
|
+
|
|
320
|
+
if (attributeUniqueId === uniqueId) {
|
|
321
|
+
return _attributeName2;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
302
324
|
|
|
303
|
-
|
|
304
|
-
}
|
|
325
|
+
var thisAttributeType = attribute.attribute_type;
|
|
305
326
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
return this._getDracoMetadata(dracoMetadata);
|
|
309
|
-
}
|
|
327
|
+
for (var dracoAttributeConstant in DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP) {
|
|
328
|
+
var attributeType = this.draco[dracoAttributeConstant];
|
|
310
329
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
330
|
+
if (attributeType === thisAttributeType) {
|
|
331
|
+
return DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP[dracoAttributeConstant];
|
|
332
|
+
}
|
|
333
|
+
}
|
|
315
334
|
|
|
316
|
-
|
|
317
|
-
if (!dracoMetadata || !dracoMetadata.ptr) {
|
|
318
|
-
return {};
|
|
319
|
-
}
|
|
335
|
+
var entryName = options.attributeNameEntry || 'name';
|
|
320
336
|
|
|
321
|
-
|
|
322
|
-
|
|
337
|
+
if (attribute.metadata[entryName]) {
|
|
338
|
+
return attribute.metadata[entryName].string;
|
|
339
|
+
}
|
|
323
340
|
|
|
324
|
-
|
|
325
|
-
const entryName = this.metadataQuerier.GetEntryName(dracoMetadata, entryIndex);
|
|
326
|
-
result[entryName] = this._getDracoMetadataField(dracoMetadata, entryName);
|
|
341
|
+
return "CUSTOM_ATTRIBUTE_".concat(uniqueId);
|
|
327
342
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const dracoArray = new this.draco.DracoInt32Array();
|
|
334
|
-
|
|
335
|
-
try {
|
|
336
|
-
this.metadataQuerier.GetIntEntryArray(dracoMetadata, entryName, dracoArray);
|
|
337
|
-
const intArray = getInt32Array(dracoArray);
|
|
338
|
-
return {
|
|
339
|
-
int: this.metadataQuerier.GetIntEntry(dracoMetadata, entryName),
|
|
340
|
-
string: this.metadataQuerier.GetStringEntry(dracoMetadata, entryName),
|
|
341
|
-
double: this.metadataQuerier.GetDoubleEntry(dracoMetadata, entryName),
|
|
342
|
-
intArray
|
|
343
|
-
};
|
|
344
|
-
} finally {
|
|
345
|
-
this.draco.destroy(dracoArray);
|
|
343
|
+
}, {
|
|
344
|
+
key: "_getTopLevelMetadata",
|
|
345
|
+
value: function _getTopLevelMetadata(dracoGeometry) {
|
|
346
|
+
var dracoMetadata = this.decoder.GetMetadata(dracoGeometry);
|
|
347
|
+
return this._getDracoMetadata(dracoMetadata);
|
|
346
348
|
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
octahedronAttributes = []
|
|
353
|
-
} = options;
|
|
354
|
-
const skipAttributes = [...quantizedAttributes, ...octahedronAttributes];
|
|
355
|
-
|
|
356
|
-
for (const dracoAttributeName of skipAttributes) {
|
|
357
|
-
this.decoder.SkipAttributeTransform(this.draco[dracoAttributeName]);
|
|
349
|
+
}, {
|
|
350
|
+
key: "_getAttributeMetadata",
|
|
351
|
+
value: function _getAttributeMetadata(dracoGeometry, attributeId) {
|
|
352
|
+
var dracoMetadata = this.decoder.GetAttributeMetadata(dracoGeometry, attributeId);
|
|
353
|
+
return this._getDracoMetadata(dracoMetadata);
|
|
358
354
|
}
|
|
359
|
-
}
|
|
355
|
+
}, {
|
|
356
|
+
key: "_getDracoMetadata",
|
|
357
|
+
value: function _getDracoMetadata(dracoMetadata) {
|
|
358
|
+
if (!dracoMetadata || !dracoMetadata.ptr) {
|
|
359
|
+
return {};
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
var result = {};
|
|
363
|
+
var numEntries = this.metadataQuerier.NumEntries(dracoMetadata);
|
|
360
364
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
const attribute_type = dracoAttribute.attribute_type();
|
|
366
|
-
const skip = quantizedAttributes.map(type => this.decoder[type]).includes(attribute_type);
|
|
365
|
+
for (var entryIndex = 0; entryIndex < numEntries; entryIndex++) {
|
|
366
|
+
var entryName = this.metadataQuerier.GetEntryName(dracoMetadata, entryIndex);
|
|
367
|
+
result[entryName] = this._getDracoMetadataField(dracoMetadata, entryName);
|
|
368
|
+
}
|
|
367
369
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
+
return result;
|
|
371
|
+
}
|
|
372
|
+
}, {
|
|
373
|
+
key: "_getDracoMetadataField",
|
|
374
|
+
value: function _getDracoMetadataField(dracoMetadata, entryName) {
|
|
375
|
+
var dracoArray = new this.draco.DracoInt32Array();
|
|
370
376
|
|
|
371
377
|
try {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
378
|
+
this.metadataQuerier.GetIntEntryArray(dracoMetadata, entryName, dracoArray);
|
|
379
|
+
var intArray = getInt32Array(dracoArray);
|
|
380
|
+
return {
|
|
381
|
+
int: this.metadataQuerier.GetIntEntry(dracoMetadata, entryName),
|
|
382
|
+
string: this.metadataQuerier.GetStringEntry(dracoMetadata, entryName),
|
|
383
|
+
double: this.metadataQuerier.GetDoubleEntry(dracoMetadata, entryName),
|
|
384
|
+
intArray: intArray
|
|
385
|
+
};
|
|
379
386
|
} finally {
|
|
380
|
-
this.draco.destroy(
|
|
387
|
+
this.draco.destroy(dracoArray);
|
|
381
388
|
}
|
|
382
389
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
if (octahedron) {
|
|
395
|
-
const transform = new this.draco.AttributeQuantizationTransform();
|
|
390
|
+
}, {
|
|
391
|
+
key: "_disableAttributeTransforms",
|
|
392
|
+
value: function _disableAttributeTransforms(options) {
|
|
393
|
+
var _options$quantizedAtt = options.quantizedAttributes,
|
|
394
|
+
quantizedAttributes = _options$quantizedAtt === void 0 ? [] : _options$quantizedAtt,
|
|
395
|
+
_options$octahedronAt = options.octahedronAttributes,
|
|
396
|
+
octahedronAttributes = _options$octahedronAt === void 0 ? [] : _options$octahedronAt;
|
|
397
|
+
var skipAttributes = [].concat((0, _toConsumableArray2.default)(quantizedAttributes), (0, _toConsumableArray2.default)(octahedronAttributes));
|
|
398
|
+
|
|
399
|
+
var _iterator = _createForOfIteratorHelper(skipAttributes),
|
|
400
|
+
_step;
|
|
396
401
|
|
|
397
402
|
try {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
};
|
|
403
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
404
|
+
var dracoAttributeName = _step.value;
|
|
405
|
+
this.decoder.SkipAttributeTransform(this.draco[dracoAttributeName]);
|
|
402
406
|
}
|
|
407
|
+
} catch (err) {
|
|
408
|
+
_iterator.e(err);
|
|
403
409
|
} finally {
|
|
404
|
-
|
|
410
|
+
_iterator.f();
|
|
405
411
|
}
|
|
406
412
|
}
|
|
413
|
+
}, {
|
|
414
|
+
key: "_getQuantizationTransform",
|
|
415
|
+
value: function _getQuantizationTransform(dracoAttribute, options) {
|
|
416
|
+
var _this = this;
|
|
417
|
+
|
|
418
|
+
var _options$quantizedAtt2 = options.quantizedAttributes,
|
|
419
|
+
quantizedAttributes = _options$quantizedAtt2 === void 0 ? [] : _options$quantizedAtt2;
|
|
420
|
+
var attribute_type = dracoAttribute.attribute_type();
|
|
421
|
+
var skip = quantizedAttributes.map(function (type) {
|
|
422
|
+
return _this.decoder[type];
|
|
423
|
+
}).includes(attribute_type);
|
|
424
|
+
|
|
425
|
+
if (skip) {
|
|
426
|
+
var transform = new this.draco.AttributeQuantizationTransform();
|
|
427
|
+
|
|
428
|
+
try {
|
|
429
|
+
if (transform.InitFromAttribute(dracoAttribute)) {
|
|
430
|
+
return {
|
|
431
|
+
quantization_bits: transform.quantization_bits(),
|
|
432
|
+
range: transform.range(),
|
|
433
|
+
min_values: new Float32Array([1, 2, 3]).map(function (i) {
|
|
434
|
+
return transform.min_value(i);
|
|
435
|
+
})
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
} finally {
|
|
439
|
+
this.draco.destroy(transform);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
407
442
|
|
|
408
|
-
|
|
409
|
-
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
}, {
|
|
446
|
+
key: "_getOctahedronTransform",
|
|
447
|
+
value: function _getOctahedronTransform(dracoAttribute, options) {
|
|
448
|
+
var _this2 = this;
|
|
449
|
+
|
|
450
|
+
var _options$octahedronAt2 = options.octahedronAttributes,
|
|
451
|
+
octahedronAttributes = _options$octahedronAt2 === void 0 ? [] : _options$octahedronAt2;
|
|
452
|
+
var attribute_type = dracoAttribute.attribute_type();
|
|
453
|
+
var octahedron = octahedronAttributes.map(function (type) {
|
|
454
|
+
return _this2.decoder[type];
|
|
455
|
+
}).includes(attribute_type);
|
|
410
456
|
|
|
411
|
-
|
|
457
|
+
if (octahedron) {
|
|
458
|
+
var transform = new this.draco.AttributeQuantizationTransform();
|
|
459
|
+
|
|
460
|
+
try {
|
|
461
|
+
if (transform.InitFromAttribute(dracoAttribute)) {
|
|
462
|
+
return {
|
|
463
|
+
quantization_bits: transform.quantization_bits()
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
} finally {
|
|
467
|
+
this.draco.destroy(transform);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
return null;
|
|
472
|
+
}
|
|
473
|
+
}]);
|
|
474
|
+
return DracoParser;
|
|
475
|
+
}();
|
|
412
476
|
|
|
413
477
|
exports.default = DracoParser;
|
|
414
478
|
|
|
@@ -441,10 +505,10 @@ function getDracoDataType(draco, attributeType) {
|
|
|
441
505
|
}
|
|
442
506
|
|
|
443
507
|
function getInt32Array(dracoArray) {
|
|
444
|
-
|
|
445
|
-
|
|
508
|
+
var numValues = dracoArray.size();
|
|
509
|
+
var intArray = new Int32Array(numValues);
|
|
446
510
|
|
|
447
|
-
for (
|
|
511
|
+
for (var i = 0; i < numValues; i++) {
|
|
448
512
|
intArray[i] = dracoArray.GetValue(i);
|
|
449
513
|
}
|
|
450
514
|
|
|
@@ -452,10 +516,10 @@ function getInt32Array(dracoArray) {
|
|
|
452
516
|
}
|
|
453
517
|
|
|
454
518
|
function getUint32Array(dracoArray) {
|
|
455
|
-
|
|
456
|
-
|
|
519
|
+
var numValues = dracoArray.size();
|
|
520
|
+
var intArray = new Int32Array(numValues);
|
|
457
521
|
|
|
458
|
-
for (
|
|
522
|
+
for (var i = 0; i < numValues; i++) {
|
|
459
523
|
intArray[i] = dracoArray.GetValue(i);
|
|
460
524
|
}
|
|
461
525
|
|