@loaders.gl/draco 3.4.14 → 3.4.15

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.
@@ -5,29 +5,20 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
9
  var _schema = require("@loaders.gl/schema");
14
10
  var _getDracoSchema = require("./utils/get-draco-schema");
15
- 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; } } }; }
16
- 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); }
17
- 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; }
18
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
19
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
20
- var GEOMETRY_TYPE = {
11
+ const GEOMETRY_TYPE = {
21
12
  TRIANGULAR_MESH: 0,
22
13
  POINT_CLOUD: 1
23
14
  };
24
- var DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP = {
15
+ const DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP = {
25
16
  POSITION: 'POSITION',
26
17
  NORMAL: 'NORMAL',
27
18
  COLOR: 'COLOR_0',
28
19
  TEX_COORD: 'TEXCOORD_0'
29
20
  };
30
- var DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP = {
21
+ const DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP = {
31
22
  1: Int8Array,
32
23
  2: Uint8Array,
33
24
  3: Int16Array,
@@ -36,10 +27,9 @@ var DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP = {
36
27
  6: Uint32Array,
37
28
  9: Float32Array
38
29
  };
39
- var INDEX_ITEM_SIZE = 4;
40
- var DracoParser = function () {
41
- function DracoParser(draco) {
42
- (0, _classCallCheck2.default)(this, DracoParser);
30
+ const INDEX_ITEM_SIZE = 4;
31
+ class DracoParser {
32
+ constructor(draco) {
43
33
  (0, _defineProperty2.default)(this, "draco", void 0);
44
34
  (0, _defineProperty2.default)(this, "decoder", void 0);
45
35
  (0, _defineProperty2.default)(this, "metadataQuerier", void 0);
@@ -47,354 +37,300 @@ var DracoParser = function () {
47
37
  this.decoder = new this.draco.Decoder();
48
38
  this.metadataQuerier = new this.draco.MetadataQuerier();
49
39
  }
50
- (0, _createClass2.default)(DracoParser, [{
51
- key: "destroy",
52
- value: function destroy() {
53
- this.draco.destroy(this.decoder);
54
- this.draco.destroy(this.metadataQuerier);
55
- }
56
- }, {
57
- key: "parseSync",
58
- value: function parseSync(arrayBuffer) {
59
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
60
- var buffer = new this.draco.DecoderBuffer();
61
- buffer.Init(new Int8Array(arrayBuffer), arrayBuffer.byteLength);
62
- this._disableAttributeTransforms(options);
63
- var geometry_type = this.decoder.GetEncodedGeometryType(buffer);
64
- var dracoGeometry = geometry_type === this.draco.TRIANGULAR_MESH ? new this.draco.Mesh() : new this.draco.PointCloud();
65
- try {
66
- var dracoStatus;
67
- switch (geometry_type) {
68
- case this.draco.TRIANGULAR_MESH:
69
- dracoStatus = this.decoder.DecodeBufferToMesh(buffer, dracoGeometry);
70
- break;
71
- case this.draco.POINT_CLOUD:
72
- dracoStatus = this.decoder.DecodeBufferToPointCloud(buffer, dracoGeometry);
73
- break;
74
- default:
75
- throw new Error('DRACO: Unknown geometry type.');
76
- }
77
- if (!dracoStatus.ok() || !dracoGeometry.ptr) {
78
- var message = "DRACO decompression failed: ".concat(dracoStatus.error_msg());
79
- throw new Error(message);
80
- }
81
- var loaderData = this._getDracoLoaderData(dracoGeometry, geometry_type, options);
82
- var geometry = this._getMeshData(dracoGeometry, loaderData, options);
83
- var boundingBox = (0, _schema.getMeshBoundingBox)(geometry.attributes);
84
- var schema = (0, _getDracoSchema.getDracoSchema)(geometry.attributes, loaderData, geometry.indices);
85
- var data = _objectSpread(_objectSpread({
86
- loader: 'draco',
87
- loaderData: loaderData,
88
- header: {
89
- vertexCount: dracoGeometry.num_points(),
90
- boundingBox: boundingBox
91
- }
92
- }, geometry), {}, {
93
- schema: schema
94
- });
95
- return data;
96
- } finally {
97
- this.draco.destroy(buffer);
98
- if (dracoGeometry) {
99
- this.draco.destroy(dracoGeometry);
100
- }
40
+ destroy() {
41
+ this.draco.destroy(this.decoder);
42
+ this.draco.destroy(this.metadataQuerier);
43
+ }
44
+ parseSync(arrayBuffer) {
45
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
46
+ const buffer = new this.draco.DecoderBuffer();
47
+ buffer.Init(new Int8Array(arrayBuffer), arrayBuffer.byteLength);
48
+ this._disableAttributeTransforms(options);
49
+ const geometry_type = this.decoder.GetEncodedGeometryType(buffer);
50
+ const dracoGeometry = geometry_type === this.draco.TRIANGULAR_MESH ? new this.draco.Mesh() : new this.draco.PointCloud();
51
+ try {
52
+ let dracoStatus;
53
+ switch (geometry_type) {
54
+ case this.draco.TRIANGULAR_MESH:
55
+ dracoStatus = this.decoder.DecodeBufferToMesh(buffer, dracoGeometry);
56
+ break;
57
+ case this.draco.POINT_CLOUD:
58
+ dracoStatus = this.decoder.DecodeBufferToPointCloud(buffer, dracoGeometry);
59
+ break;
60
+ default:
61
+ throw new Error('DRACO: Unknown geometry type.');
101
62
  }
102
- }
103
- }, {
104
- key: "_getDracoLoaderData",
105
- value: function _getDracoLoaderData(dracoGeometry, geometry_type, options) {
106
- var metadata = this._getTopLevelMetadata(dracoGeometry);
107
- var attributes = this._getDracoAttributes(dracoGeometry, options);
108
- return {
109
- geometry_type: geometry_type,
110
- num_attributes: dracoGeometry.num_attributes(),
111
- num_points: dracoGeometry.num_points(),
112
- num_faces: dracoGeometry instanceof this.draco.Mesh ? dracoGeometry.num_faces() : 0,
113
- metadata: metadata,
114
- attributes: attributes
63
+ if (!dracoStatus.ok() || !dracoGeometry.ptr) {
64
+ const message = "DRACO decompression failed: ".concat(dracoStatus.error_msg());
65
+ throw new Error(message);
66
+ }
67
+ const loaderData = this._getDracoLoaderData(dracoGeometry, geometry_type, options);
68
+ const geometry = this._getMeshData(dracoGeometry, loaderData, options);
69
+ const boundingBox = (0, _schema.getMeshBoundingBox)(geometry.attributes);
70
+ const schema = (0, _getDracoSchema.getDracoSchema)(geometry.attributes, loaderData, geometry.indices);
71
+ const data = {
72
+ loader: 'draco',
73
+ loaderData,
74
+ header: {
75
+ vertexCount: dracoGeometry.num_points(),
76
+ boundingBox
77
+ },
78
+ ...geometry,
79
+ schema
115
80
  };
116
- }
117
- }, {
118
- key: "_getDracoAttributes",
119
- value: function _getDracoAttributes(dracoGeometry, options) {
120
- var dracoAttributes = {};
121
- for (var attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) {
122
- var dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attributeId);
123
- var metadata = this._getAttributeMetadata(dracoGeometry, attributeId);
124
- dracoAttributes[dracoAttribute.unique_id()] = {
125
- unique_id: dracoAttribute.unique_id(),
126
- attribute_type: dracoAttribute.attribute_type(),
127
- data_type: dracoAttribute.data_type(),
128
- num_components: dracoAttribute.num_components(),
129
- byte_offset: dracoAttribute.byte_offset(),
130
- byte_stride: dracoAttribute.byte_stride(),
131
- normalized: dracoAttribute.normalized(),
132
- attribute_index: attributeId,
133
- metadata: metadata
134
- };
135
- var quantization = this._getQuantizationTransform(dracoAttribute, options);
136
- if (quantization) {
137
- dracoAttributes[dracoAttribute.unique_id()].quantization_transform = quantization;
138
- }
139
- var octahedron = this._getOctahedronTransform(dracoAttribute, options);
140
- if (octahedron) {
141
- dracoAttributes[dracoAttribute.unique_id()].octahedron_transform = octahedron;
142
- }
81
+ return data;
82
+ } finally {
83
+ this.draco.destroy(buffer);
84
+ if (dracoGeometry) {
85
+ this.draco.destroy(dracoGeometry);
143
86
  }
144
- return dracoAttributes;
145
87
  }
146
- }, {
147
- key: "_getMeshData",
148
- value: function _getMeshData(dracoGeometry, loaderData, options) {
149
- var attributes = this._getMeshAttributes(loaderData, dracoGeometry, options);
150
- var positionAttribute = attributes.POSITION;
151
- if (!positionAttribute) {
152
- throw new Error('DRACO: No position attribute found.');
153
- }
154
- if (dracoGeometry instanceof this.draco.Mesh) {
155
- switch (options.topology) {
156
- case 'triangle-strip':
157
- return {
158
- topology: 'triangle-strip',
159
- mode: 4,
160
- attributes: attributes,
161
- indices: {
162
- value: this._getTriangleStripIndices(dracoGeometry),
163
- size: 1
164
- }
165
- };
166
- case 'triangle-list':
167
- default:
168
- return {
169
- topology: 'triangle-list',
170
- mode: 5,
171
- attributes: attributes,
172
- indices: {
173
- value: this._getTriangleListIndices(dracoGeometry),
174
- size: 1
175
- }
176
- };
177
- }
178
- }
179
- return {
180
- topology: 'point-list',
181
- mode: 0,
182
- attributes: attributes
88
+ }
89
+ _getDracoLoaderData(dracoGeometry, geometry_type, options) {
90
+ const metadata = this._getTopLevelMetadata(dracoGeometry);
91
+ const attributes = this._getDracoAttributes(dracoGeometry, options);
92
+ return {
93
+ geometry_type,
94
+ num_attributes: dracoGeometry.num_attributes(),
95
+ num_points: dracoGeometry.num_points(),
96
+ num_faces: dracoGeometry instanceof this.draco.Mesh ? dracoGeometry.num_faces() : 0,
97
+ metadata,
98
+ attributes
99
+ };
100
+ }
101
+ _getDracoAttributes(dracoGeometry, options) {
102
+ const dracoAttributes = {};
103
+ for (let attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) {
104
+ const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attributeId);
105
+ const metadata = this._getAttributeMetadata(dracoGeometry, attributeId);
106
+ dracoAttributes[dracoAttribute.unique_id()] = {
107
+ unique_id: dracoAttribute.unique_id(),
108
+ attribute_type: dracoAttribute.attribute_type(),
109
+ data_type: dracoAttribute.data_type(),
110
+ num_components: dracoAttribute.num_components(),
111
+ byte_offset: dracoAttribute.byte_offset(),
112
+ byte_stride: dracoAttribute.byte_stride(),
113
+ normalized: dracoAttribute.normalized(),
114
+ attribute_index: attributeId,
115
+ metadata
183
116
  };
184
- }
185
- }, {
186
- key: "_getMeshAttributes",
187
- value: function _getMeshAttributes(loaderData, dracoGeometry, options) {
188
- var attributes = {};
189
- for (var _i = 0, _Object$values = Object.values(loaderData.attributes); _i < _Object$values.length; _i++) {
190
- var loaderAttribute = _Object$values[_i];
191
- var _attributeName = this._deduceAttributeName(loaderAttribute, options);
192
- loaderAttribute.name = _attributeName;
193
- var _this$_getAttributeVa = this._getAttributeValues(dracoGeometry, loaderAttribute),
194
- value = _this$_getAttributeVa.value,
195
- size = _this$_getAttributeVa.size;
196
- attributes[_attributeName] = {
197
- value: value,
198
- size: size,
199
- byteOffset: loaderAttribute.byte_offset,
200
- byteStride: loaderAttribute.byte_stride,
201
- normalized: loaderAttribute.normalized
202
- };
117
+ const quantization = this._getQuantizationTransform(dracoAttribute, options);
118
+ if (quantization) {
119
+ dracoAttributes[dracoAttribute.unique_id()].quantization_transform = quantization;
203
120
  }
204
- return attributes;
205
- }
206
- }, {
207
- key: "_getTriangleListIndices",
208
- value: function _getTriangleListIndices(dracoGeometry) {
209
- var numFaces = dracoGeometry.num_faces();
210
- var numIndices = numFaces * 3;
211
- var byteLength = numIndices * INDEX_ITEM_SIZE;
212
- var ptr = this.draco._malloc(byteLength);
213
- try {
214
- this.decoder.GetTrianglesUInt32Array(dracoGeometry, byteLength, ptr);
215
- return new Uint32Array(this.draco.HEAPF32.buffer, ptr, numIndices).slice();
216
- } finally {
217
- this.draco._free(ptr);
121
+ const octahedron = this._getOctahedronTransform(dracoAttribute, options);
122
+ if (octahedron) {
123
+ dracoAttributes[dracoAttribute.unique_id()].octahedron_transform = octahedron;
218
124
  }
219
125
  }
220
- }, {
221
- key: "_getTriangleStripIndices",
222
- value: function _getTriangleStripIndices(dracoGeometry) {
223
- var dracoArray = new this.draco.DracoInt32Array();
224
- try {
225
- this.decoder.GetTriangleStripsFromMesh(dracoGeometry, dracoArray);
226
- return getUint32Array(dracoArray);
227
- } finally {
228
- this.draco.destroy(dracoArray);
229
- }
126
+ return dracoAttributes;
127
+ }
128
+ _getMeshData(dracoGeometry, loaderData, options) {
129
+ const attributes = this._getMeshAttributes(loaderData, dracoGeometry, options);
130
+ const positionAttribute = attributes.POSITION;
131
+ if (!positionAttribute) {
132
+ throw new Error('DRACO: No position attribute found.');
230
133
  }
231
- }, {
232
- key: "_getAttributeValues",
233
- value: function _getAttributeValues(dracoGeometry, attribute) {
234
- var TypedArrayCtor = DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP[attribute.data_type];
235
- var numComponents = attribute.num_components;
236
- var numPoints = dracoGeometry.num_points();
237
- var numValues = numPoints * numComponents;
238
- var byteLength = numValues * TypedArrayCtor.BYTES_PER_ELEMENT;
239
- var dataType = getDracoDataType(this.draco, TypedArrayCtor);
240
- var value;
241
- var ptr = this.draco._malloc(byteLength);
242
- try {
243
- var dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attribute.attribute_index);
244
- this.decoder.GetAttributeDataArrayForAllPoints(dracoGeometry, dracoAttribute, dataType, byteLength, ptr);
245
- value = new TypedArrayCtor(this.draco.HEAPF32.buffer, ptr, numValues).slice();
246
- } finally {
247
- this.draco._free(ptr);
134
+ if (dracoGeometry instanceof this.draco.Mesh) {
135
+ switch (options.topology) {
136
+ case 'triangle-strip':
137
+ return {
138
+ topology: 'triangle-strip',
139
+ mode: 4,
140
+ attributes,
141
+ indices: {
142
+ value: this._getTriangleStripIndices(dracoGeometry),
143
+ size: 1
144
+ }
145
+ };
146
+ case 'triangle-list':
147
+ default:
148
+ return {
149
+ topology: 'triangle-list',
150
+ mode: 5,
151
+ attributes,
152
+ indices: {
153
+ value: this._getTriangleListIndices(dracoGeometry),
154
+ size: 1
155
+ }
156
+ };
248
157
  }
249
- return {
250
- value: value,
251
- size: numComponents
158
+ }
159
+ return {
160
+ topology: 'point-list',
161
+ mode: 0,
162
+ attributes
163
+ };
164
+ }
165
+ _getMeshAttributes(loaderData, dracoGeometry, options) {
166
+ const attributes = {};
167
+ for (const loaderAttribute of Object.values(loaderData.attributes)) {
168
+ const attributeName = this._deduceAttributeName(loaderAttribute, options);
169
+ loaderAttribute.name = attributeName;
170
+ const {
171
+ value,
172
+ size
173
+ } = this._getAttributeValues(dracoGeometry, loaderAttribute);
174
+ attributes[attributeName] = {
175
+ value,
176
+ size,
177
+ byteOffset: loaderAttribute.byte_offset,
178
+ byteStride: loaderAttribute.byte_stride,
179
+ normalized: loaderAttribute.normalized
252
180
  };
253
181
  }
254
- }, {
255
- key: "_deduceAttributeName",
256
- value: function _deduceAttributeName(attribute, options) {
257
- var uniqueId = attribute.unique_id;
258
- for (var _i2 = 0, _Object$entries = Object.entries(options.extraAttributes || {}); _i2 < _Object$entries.length; _i2++) {
259
- var _Object$entries$_i = (0, _slicedToArray2.default)(_Object$entries[_i2], 2),
260
- _attributeName2 = _Object$entries$_i[0],
261
- attributeUniqueId = _Object$entries$_i[1];
262
- if (attributeUniqueId === uniqueId) {
263
- return _attributeName2;
264
- }
265
- }
266
- var thisAttributeType = attribute.attribute_type;
267
- for (var dracoAttributeConstant in DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP) {
268
- var attributeType = this.draco[dracoAttributeConstant];
269
- if (attributeType === thisAttributeType) {
270
- return DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP[dracoAttributeConstant];
271
- }
272
- }
273
- var entryName = options.attributeNameEntry || 'name';
274
- if (attribute.metadata[entryName]) {
275
- return attribute.metadata[entryName].string;
276
- }
277
- return "CUSTOM_ATTRIBUTE_".concat(uniqueId);
182
+ return attributes;
183
+ }
184
+ _getTriangleListIndices(dracoGeometry) {
185
+ const numFaces = dracoGeometry.num_faces();
186
+ const numIndices = numFaces * 3;
187
+ const byteLength = numIndices * INDEX_ITEM_SIZE;
188
+ const ptr = this.draco._malloc(byteLength);
189
+ try {
190
+ this.decoder.GetTrianglesUInt32Array(dracoGeometry, byteLength, ptr);
191
+ return new Uint32Array(this.draco.HEAPF32.buffer, ptr, numIndices).slice();
192
+ } finally {
193
+ this.draco._free(ptr);
278
194
  }
279
- }, {
280
- key: "_getTopLevelMetadata",
281
- value: function _getTopLevelMetadata(dracoGeometry) {
282
- var dracoMetadata = this.decoder.GetMetadata(dracoGeometry);
283
- return this._getDracoMetadata(dracoMetadata);
195
+ }
196
+ _getTriangleStripIndices(dracoGeometry) {
197
+ const dracoArray = new this.draco.DracoInt32Array();
198
+ try {
199
+ this.decoder.GetTriangleStripsFromMesh(dracoGeometry, dracoArray);
200
+ return getUint32Array(dracoArray);
201
+ } finally {
202
+ this.draco.destroy(dracoArray);
284
203
  }
285
- }, {
286
- key: "_getAttributeMetadata",
287
- value: function _getAttributeMetadata(dracoGeometry, attributeId) {
288
- var dracoMetadata = this.decoder.GetAttributeMetadata(dracoGeometry, attributeId);
289
- return this._getDracoMetadata(dracoMetadata);
204
+ }
205
+ _getAttributeValues(dracoGeometry, attribute) {
206
+ const TypedArrayCtor = DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP[attribute.data_type];
207
+ const numComponents = attribute.num_components;
208
+ const numPoints = dracoGeometry.num_points();
209
+ const numValues = numPoints * numComponents;
210
+ const byteLength = numValues * TypedArrayCtor.BYTES_PER_ELEMENT;
211
+ const dataType = getDracoDataType(this.draco, TypedArrayCtor);
212
+ let value;
213
+ const ptr = this.draco._malloc(byteLength);
214
+ try {
215
+ const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attribute.attribute_index);
216
+ this.decoder.GetAttributeDataArrayForAllPoints(dracoGeometry, dracoAttribute, dataType, byteLength, ptr);
217
+ value = new TypedArrayCtor(this.draco.HEAPF32.buffer, ptr, numValues).slice();
218
+ } finally {
219
+ this.draco._free(ptr);
290
220
  }
291
- }, {
292
- key: "_getDracoMetadata",
293
- value: function _getDracoMetadata(dracoMetadata) {
294
- if (!dracoMetadata || !dracoMetadata.ptr) {
295
- return {};
296
- }
297
- var result = {};
298
- var numEntries = this.metadataQuerier.NumEntries(dracoMetadata);
299
- for (var entryIndex = 0; entryIndex < numEntries; entryIndex++) {
300
- var entryName = this.metadataQuerier.GetEntryName(dracoMetadata, entryIndex);
301
- result[entryName] = this._getDracoMetadataField(dracoMetadata, entryName);
221
+ return {
222
+ value,
223
+ size: numComponents
224
+ };
225
+ }
226
+ _deduceAttributeName(attribute, options) {
227
+ const uniqueId = attribute.unique_id;
228
+ for (const [attributeName, attributeUniqueId] of Object.entries(options.extraAttributes || {})) {
229
+ if (attributeUniqueId === uniqueId) {
230
+ return attributeName;
302
231
  }
303
- return result;
304
232
  }
305
- }, {
306
- key: "_getDracoMetadataField",
307
- value: function _getDracoMetadataField(dracoMetadata, entryName) {
308
- var dracoArray = new this.draco.DracoInt32Array();
309
- try {
310
- this.metadataQuerier.GetIntEntryArray(dracoMetadata, entryName, dracoArray);
311
- var intArray = getInt32Array(dracoArray);
312
- return {
313
- int: this.metadataQuerier.GetIntEntry(dracoMetadata, entryName),
314
- string: this.metadataQuerier.GetStringEntry(dracoMetadata, entryName),
315
- double: this.metadataQuerier.GetDoubleEntry(dracoMetadata, entryName),
316
- intArray: intArray
317
- };
318
- } finally {
319
- this.draco.destroy(dracoArray);
233
+ const thisAttributeType = attribute.attribute_type;
234
+ for (const dracoAttributeConstant in DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP) {
235
+ const attributeType = this.draco[dracoAttributeConstant];
236
+ if (attributeType === thisAttributeType) {
237
+ return DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP[dracoAttributeConstant];
320
238
  }
321
239
  }
322
- }, {
323
- key: "_disableAttributeTransforms",
324
- value: function _disableAttributeTransforms(options) {
325
- var _options$quantizedAtt = options.quantizedAttributes,
326
- quantizedAttributes = _options$quantizedAtt === void 0 ? [] : _options$quantizedAtt,
327
- _options$octahedronAt = options.octahedronAttributes,
328
- octahedronAttributes = _options$octahedronAt === void 0 ? [] : _options$octahedronAt;
329
- var skipAttributes = [].concat((0, _toConsumableArray2.default)(quantizedAttributes), (0, _toConsumableArray2.default)(octahedronAttributes));
330
- var _iterator = _createForOfIteratorHelper(skipAttributes),
331
- _step;
240
+ const entryName = options.attributeNameEntry || 'name';
241
+ if (attribute.metadata[entryName]) {
242
+ return attribute.metadata[entryName].string;
243
+ }
244
+ return "CUSTOM_ATTRIBUTE_".concat(uniqueId);
245
+ }
246
+ _getTopLevelMetadata(dracoGeometry) {
247
+ const dracoMetadata = this.decoder.GetMetadata(dracoGeometry);
248
+ return this._getDracoMetadata(dracoMetadata);
249
+ }
250
+ _getAttributeMetadata(dracoGeometry, attributeId) {
251
+ const dracoMetadata = this.decoder.GetAttributeMetadata(dracoGeometry, attributeId);
252
+ return this._getDracoMetadata(dracoMetadata);
253
+ }
254
+ _getDracoMetadata(dracoMetadata) {
255
+ if (!dracoMetadata || !dracoMetadata.ptr) {
256
+ return {};
257
+ }
258
+ const result = {};
259
+ const numEntries = this.metadataQuerier.NumEntries(dracoMetadata);
260
+ for (let entryIndex = 0; entryIndex < numEntries; entryIndex++) {
261
+ const entryName = this.metadataQuerier.GetEntryName(dracoMetadata, entryIndex);
262
+ result[entryName] = this._getDracoMetadataField(dracoMetadata, entryName);
263
+ }
264
+ return result;
265
+ }
266
+ _getDracoMetadataField(dracoMetadata, entryName) {
267
+ const dracoArray = new this.draco.DracoInt32Array();
268
+ try {
269
+ this.metadataQuerier.GetIntEntryArray(dracoMetadata, entryName, dracoArray);
270
+ const intArray = getInt32Array(dracoArray);
271
+ return {
272
+ int: this.metadataQuerier.GetIntEntry(dracoMetadata, entryName),
273
+ string: this.metadataQuerier.GetStringEntry(dracoMetadata, entryName),
274
+ double: this.metadataQuerier.GetDoubleEntry(dracoMetadata, entryName),
275
+ intArray
276
+ };
277
+ } finally {
278
+ this.draco.destroy(dracoArray);
279
+ }
280
+ }
281
+ _disableAttributeTransforms(options) {
282
+ const {
283
+ quantizedAttributes = [],
284
+ octahedronAttributes = []
285
+ } = options;
286
+ const skipAttributes = [...quantizedAttributes, ...octahedronAttributes];
287
+ for (const dracoAttributeName of skipAttributes) {
288
+ this.decoder.SkipAttributeTransform(this.draco[dracoAttributeName]);
289
+ }
290
+ }
291
+ _getQuantizationTransform(dracoAttribute, options) {
292
+ const {
293
+ quantizedAttributes = []
294
+ } = options;
295
+ const attribute_type = dracoAttribute.attribute_type();
296
+ const skip = quantizedAttributes.map(type => this.decoder[type]).includes(attribute_type);
297
+ if (skip) {
298
+ const transform = new this.draco.AttributeQuantizationTransform();
332
299
  try {
333
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
334
- var dracoAttributeName = _step.value;
335
- this.decoder.SkipAttributeTransform(this.draco[dracoAttributeName]);
300
+ if (transform.InitFromAttribute(dracoAttribute)) {
301
+ return {
302
+ quantization_bits: transform.quantization_bits(),
303
+ range: transform.range(),
304
+ min_values: new Float32Array([1, 2, 3]).map(i => transform.min_value(i))
305
+ };
336
306
  }
337
- } catch (err) {
338
- _iterator.e(err);
339
307
  } finally {
340
- _iterator.f();
341
- }
342
- }
343
- }, {
344
- key: "_getQuantizationTransform",
345
- value: function _getQuantizationTransform(dracoAttribute, options) {
346
- var _this = this;
347
- var _options$quantizedAtt2 = options.quantizedAttributes,
348
- quantizedAttributes = _options$quantizedAtt2 === void 0 ? [] : _options$quantizedAtt2;
349
- var attribute_type = dracoAttribute.attribute_type();
350
- var skip = quantizedAttributes.map(function (type) {
351
- return _this.decoder[type];
352
- }).includes(attribute_type);
353
- if (skip) {
354
- var transform = new this.draco.AttributeQuantizationTransform();
355
- try {
356
- if (transform.InitFromAttribute(dracoAttribute)) {
357
- return {
358
- quantization_bits: transform.quantization_bits(),
359
- range: transform.range(),
360
- min_values: new Float32Array([1, 2, 3]).map(function (i) {
361
- return transform.min_value(i);
362
- })
363
- };
364
- }
365
- } finally {
366
- this.draco.destroy(transform);
367
- }
308
+ this.draco.destroy(transform);
368
309
  }
369
- return null;
370
310
  }
371
- }, {
372
- key: "_getOctahedronTransform",
373
- value: function _getOctahedronTransform(dracoAttribute, options) {
374
- var _this2 = this;
375
- var _options$octahedronAt2 = options.octahedronAttributes,
376
- octahedronAttributes = _options$octahedronAt2 === void 0 ? [] : _options$octahedronAt2;
377
- var attribute_type = dracoAttribute.attribute_type();
378
- var octahedron = octahedronAttributes.map(function (type) {
379
- return _this2.decoder[type];
380
- }).includes(attribute_type);
381
- if (octahedron) {
382
- var transform = new this.draco.AttributeQuantizationTransform();
383
- try {
384
- if (transform.InitFromAttribute(dracoAttribute)) {
385
- return {
386
- quantization_bits: transform.quantization_bits()
387
- };
388
- }
389
- } finally {
390
- this.draco.destroy(transform);
311
+ return null;
312
+ }
313
+ _getOctahedronTransform(dracoAttribute, options) {
314
+ const {
315
+ octahedronAttributes = []
316
+ } = options;
317
+ const attribute_type = dracoAttribute.attribute_type();
318
+ const octahedron = octahedronAttributes.map(type => this.decoder[type]).includes(attribute_type);
319
+ if (octahedron) {
320
+ const transform = new this.draco.AttributeQuantizationTransform();
321
+ try {
322
+ if (transform.InitFromAttribute(dracoAttribute)) {
323
+ return {
324
+ quantization_bits: transform.quantization_bits()
325
+ };
391
326
  }
327
+ } finally {
328
+ this.draco.destroy(transform);
392
329
  }
393
- return null;
394
330
  }
395
- }]);
396
- return DracoParser;
397
- }();
331
+ return null;
332
+ }
333
+ }
398
334
  exports.default = DracoParser;
399
335
  function getDracoDataType(draco, attributeType) {
400
336
  switch (attributeType) {
@@ -417,17 +353,17 @@ function getDracoDataType(draco, attributeType) {
417
353
  }
418
354
  }
419
355
  function getInt32Array(dracoArray) {
420
- var numValues = dracoArray.size();
421
- var intArray = new Int32Array(numValues);
422
- for (var i = 0; i < numValues; i++) {
356
+ const numValues = dracoArray.size();
357
+ const intArray = new Int32Array(numValues);
358
+ for (let i = 0; i < numValues; i++) {
423
359
  intArray[i] = dracoArray.GetValue(i);
424
360
  }
425
361
  return intArray;
426
362
  }
427
363
  function getUint32Array(dracoArray) {
428
- var numValues = dracoArray.size();
429
- var intArray = new Int32Array(numValues);
430
- for (var i = 0; i < numValues; i++) {
364
+ const numValues = dracoArray.size();
365
+ const intArray = new Int32Array(numValues);
366
+ for (let i = 0; i < numValues; i++) {
431
367
  intArray[i] = dracoArray.GetValue(i);
432
368
  }
433
369
  return intArray;