@loaders.gl/draco 3.0.12 → 3.0.13
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.es5.min.js +1 -1
- package/dist/dist.es5.min.js.map +1 -1
- package/dist/dist.min.js +1 -1
- package/dist/dist.min.js.map +1 -1
- package/dist/draco-worker.js +1 -1
- package/dist/draco-worker.js.map +1 -1
- package/dist/es5/bundle.js +2 -2
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/draco-loader.js +4 -8
- package/dist/es5/draco-loader.js.map +1 -1
- package/dist/es5/draco-writer.js +13 -46
- package/dist/es5/draco-writer.js.map +1 -1
- package/dist/es5/draco3d/draco3d-types.js +4 -4
- package/dist/es5/index.js +16 -51
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/draco-builder.js +244 -292
- package/dist/es5/lib/draco-builder.js.map +1 -1
- package/dist/es5/lib/draco-module-loader.js +65 -198
- package/dist/es5/lib/draco-module-loader.js.map +1 -1
- package/dist/es5/lib/draco-parser.js +308 -372
- package/dist/es5/lib/draco-parser.js.map +1 -1
- package/dist/es5/lib/utils/schema-attribute-utils.js +15 -15
- package/dist/es5/lib/utils/schema-attribute-utils.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/draco-builder.js +4 -6
- package/dist/esm/lib/draco-builder.js.map +1 -1
- package/dist/esm/lib/draco-module-loader.js +4 -4
- package/dist/esm/lib/draco-module-loader.js.map +1 -1
- package/dist/esm/lib/draco-parser.js +2 -2
- package/dist/esm/lib/draco-parser.js.map +1 -1
- package/dist/esm/lib/utils/schema-attribute-utils.js +1 -1
- package/dist/esm/lib/utils/schema-attribute-utils.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/package.json +5 -5
|
@@ -7,41 +7,23 @@ 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
|
-
|
|
18
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
19
11
|
|
|
20
12
|
var _schema = require("@loaders.gl/schema");
|
|
21
13
|
|
|
22
14
|
var _schemaAttributeUtils = require("./utils/schema-attribute-utils");
|
|
23
15
|
|
|
24
|
-
|
|
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 = {
|
|
16
|
+
const GEOMETRY_TYPE = {
|
|
35
17
|
TRIANGULAR_MESH: 0,
|
|
36
18
|
POINT_CLOUD: 1
|
|
37
19
|
};
|
|
38
|
-
|
|
20
|
+
const DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP = {
|
|
39
21
|
POSITION: 'POSITION',
|
|
40
22
|
NORMAL: 'NORMAL',
|
|
41
23
|
COLOR: 'COLOR_0',
|
|
42
24
|
TEX_COORD: 'TEXCOORD_0'
|
|
43
25
|
};
|
|
44
|
-
|
|
26
|
+
const DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP = {
|
|
45
27
|
1: Int8Array,
|
|
46
28
|
2: Uint8Array,
|
|
47
29
|
3: Int16Array,
|
|
@@ -50,11 +32,10 @@ var DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP = {
|
|
|
50
32
|
6: Uint32Array,
|
|
51
33
|
9: Float32Array
|
|
52
34
|
};
|
|
53
|
-
|
|
35
|
+
const INDEX_ITEM_SIZE = 4;
|
|
54
36
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
(0, _classCallCheck2.default)(this, DracoParser);
|
|
37
|
+
class DracoParser {
|
|
38
|
+
constructor(draco) {
|
|
58
39
|
(0, _defineProperty2.default)(this, "draco", void 0);
|
|
59
40
|
(0, _defineProperty2.default)(this, "decoder", void 0);
|
|
60
41
|
(0, _defineProperty2.default)(this, "metadataQuerier", void 0);
|
|
@@ -63,416 +44,371 @@ var DracoParser = function () {
|
|
|
63
44
|
this.metadataQuerier = new this.draco.MetadataQuerier();
|
|
64
45
|
}
|
|
65
46
|
|
|
66
|
-
(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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);
|
|
47
|
+
destroy() {
|
|
48
|
+
this.draco.destroy(this.decoder);
|
|
49
|
+
this.draco.destroy(this.metadataQuerier);
|
|
50
|
+
}
|
|
78
51
|
|
|
79
|
-
|
|
52
|
+
parseSync(arrayBuffer, options = {}) {
|
|
53
|
+
const buffer = new this.draco.DecoderBuffer();
|
|
54
|
+
buffer.Init(new Int8Array(arrayBuffer), arrayBuffer.byteLength);
|
|
80
55
|
|
|
81
|
-
|
|
82
|
-
var dracoGeometry = geometry_type === this.draco.TRIANGULAR_MESH ? new this.draco.Mesh() : new this.draco.PointCloud();
|
|
56
|
+
this._disableAttributeTransforms(options);
|
|
83
57
|
|
|
84
|
-
|
|
85
|
-
|
|
58
|
+
const geometry_type = this.decoder.GetEncodedGeometryType(buffer);
|
|
59
|
+
const dracoGeometry = geometry_type === this.draco.TRIANGULAR_MESH ? new this.draco.Mesh() : new this.draco.PointCloud();
|
|
86
60
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
dracoStatus = this.decoder.DecodeBufferToMesh(buffer, dracoGeometry);
|
|
90
|
-
break;
|
|
61
|
+
try {
|
|
62
|
+
let dracoStatus;
|
|
91
63
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
64
|
+
switch (geometry_type) {
|
|
65
|
+
case this.draco.TRIANGULAR_MESH:
|
|
66
|
+
dracoStatus = this.decoder.DecodeBufferToMesh(buffer, dracoGeometry);
|
|
67
|
+
break;
|
|
95
68
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
69
|
+
case this.draco.POINT_CLOUD:
|
|
70
|
+
dracoStatus = this.decoder.DecodeBufferToPointCloud(buffer, dracoGeometry);
|
|
71
|
+
break;
|
|
99
72
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
73
|
+
default:
|
|
74
|
+
throw new Error('DRACO: Unknown geometry type.');
|
|
75
|
+
}
|
|
104
76
|
|
|
105
|
-
|
|
77
|
+
if (!dracoStatus.ok() || !dracoGeometry.ptr) {
|
|
78
|
+
const message = "DRACO decompression failed: ".concat(dracoStatus.error_msg());
|
|
79
|
+
throw new Error(message);
|
|
80
|
+
}
|
|
106
81
|
|
|
107
|
-
|
|
82
|
+
const loaderData = this._getDracoLoaderData(dracoGeometry, geometry_type, options);
|
|
83
|
+
|
|
84
|
+
const geometry = this._getMeshData(dracoGeometry, loaderData, options);
|
|
85
|
+
|
|
86
|
+
const boundingBox = (0, _schema.getMeshBoundingBox)(geometry.attributes);
|
|
87
|
+
const schema = (0, _schemaAttributeUtils.makeSchemaFromAttributes)(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);
|
|
108
101
|
|
|
109
|
-
|
|
110
|
-
|
|
102
|
+
if (dracoGeometry) {
|
|
103
|
+
this.draco.destroy(dracoGeometry);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
111
107
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
loaderData: loaderData,
|
|
115
|
-
header: {
|
|
116
|
-
vertexCount: dracoGeometry.num_points(),
|
|
117
|
-
boundingBox: boundingBox
|
|
118
|
-
}
|
|
119
|
-
}, geometry), {}, {
|
|
120
|
-
schema: schema
|
|
121
|
-
});
|
|
108
|
+
_getDracoLoaderData(dracoGeometry, geometry_type, options) {
|
|
109
|
+
const metadata = this._getTopLevelMetadata(dracoGeometry);
|
|
122
110
|
|
|
123
|
-
|
|
124
|
-
} finally {
|
|
125
|
-
this.draco.destroy(buffer);
|
|
111
|
+
const attributes = this._getDracoAttributes(dracoGeometry, options);
|
|
126
112
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
113
|
+
return {
|
|
114
|
+
geometry_type,
|
|
115
|
+
num_attributes: dracoGeometry.num_attributes(),
|
|
116
|
+
num_points: dracoGeometry.num_points(),
|
|
117
|
+
num_faces: dracoGeometry instanceof this.draco.Mesh ? dracoGeometry.num_faces() : 0,
|
|
118
|
+
metadata,
|
|
119
|
+
attributes
|
|
120
|
+
};
|
|
121
|
+
}
|
|
136
122
|
|
|
137
|
-
|
|
123
|
+
_getDracoAttributes(dracoGeometry, options) {
|
|
124
|
+
const dracoAttributes = {};
|
|
138
125
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
126
|
+
for (let attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) {
|
|
127
|
+
const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attributeId);
|
|
128
|
+
|
|
129
|
+
const metadata = this._getAttributeMetadata(dracoGeometry, attributeId);
|
|
130
|
+
|
|
131
|
+
dracoAttributes[dracoAttribute.unique_id()] = {
|
|
132
|
+
unique_id: dracoAttribute.unique_id(),
|
|
133
|
+
attribute_type: dracoAttribute.attribute_type(),
|
|
134
|
+
data_type: dracoAttribute.data_type(),
|
|
135
|
+
num_components: dracoAttribute.num_components(),
|
|
136
|
+
byte_offset: dracoAttribute.byte_offset(),
|
|
137
|
+
byte_stride: dracoAttribute.byte_stride(),
|
|
138
|
+
normalized: dracoAttribute.normalized(),
|
|
139
|
+
attribute_index: attributeId,
|
|
140
|
+
metadata
|
|
146
141
|
};
|
|
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
|
-
}
|
|
175
142
|
|
|
176
|
-
|
|
143
|
+
const quantization = this._getQuantizationTransform(dracoAttribute, options);
|
|
177
144
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
145
|
+
if (quantization) {
|
|
146
|
+
dracoAttributes[dracoAttribute.unique_id()].quantization_transform = quantization;
|
|
181
147
|
}
|
|
182
148
|
|
|
183
|
-
|
|
149
|
+
const octahedron = this._getOctahedronTransform(dracoAttribute, options);
|
|
150
|
+
|
|
151
|
+
if (octahedron) {
|
|
152
|
+
dracoAttributes[dracoAttribute.unique_id()].octahedron_transform = octahedron;
|
|
153
|
+
}
|
|
184
154
|
}
|
|
185
|
-
}, {
|
|
186
|
-
key: "_getMeshData",
|
|
187
|
-
value: function _getMeshData(dracoGeometry, loaderData, options) {
|
|
188
|
-
var attributes = this._getMeshAttributes(loaderData, dracoGeometry, options);
|
|
189
155
|
|
|
190
|
-
|
|
156
|
+
return dracoAttributes;
|
|
157
|
+
}
|
|
191
158
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
159
|
+
_getMeshData(dracoGeometry, loaderData, options) {
|
|
160
|
+
const attributes = this._getMeshAttributes(loaderData, dracoGeometry, options);
|
|
195
161
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
162
|
+
const positionAttribute = attributes.POSITION;
|
|
163
|
+
|
|
164
|
+
if (!positionAttribute) {
|
|
165
|
+
throw new Error('DRACO: No position attribute found.');
|
|
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
|
+
};
|
|
221
192
|
}
|
|
193
|
+
}
|
|
222
194
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
195
|
+
return {
|
|
196
|
+
topology: 'point-list',
|
|
197
|
+
mode: 0,
|
|
198
|
+
attributes
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
_getMeshAttributes(loaderData, dracoGeometry, options) {
|
|
203
|
+
const attributes = {};
|
|
204
|
+
|
|
205
|
+
for (const loaderAttribute of Object.values(loaderData.attributes)) {
|
|
206
|
+
const attributeName = this._deduceAttributeName(loaderAttribute, options);
|
|
207
|
+
|
|
208
|
+
loaderAttribute.name = attributeName;
|
|
209
|
+
|
|
210
|
+
const {
|
|
211
|
+
value,
|
|
212
|
+
size
|
|
213
|
+
} = this._getAttributeValues(dracoGeometry, loaderAttribute);
|
|
214
|
+
|
|
215
|
+
attributes[attributeName] = {
|
|
216
|
+
value,
|
|
217
|
+
size,
|
|
218
|
+
byteOffset: loaderAttribute.byte_offset,
|
|
219
|
+
byteStride: loaderAttribute.byte_stride,
|
|
220
|
+
normalized: loaderAttribute.normalized
|
|
227
221
|
};
|
|
228
222
|
}
|
|
229
|
-
}, {
|
|
230
|
-
key: "_getMeshAttributes",
|
|
231
|
-
value: function _getMeshAttributes(loaderData, dracoGeometry, options) {
|
|
232
|
-
var attributes = {};
|
|
233
223
|
|
|
234
|
-
|
|
235
|
-
|
|
224
|
+
return attributes;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
_getTriangleListIndices(dracoGeometry) {
|
|
228
|
+
const numFaces = dracoGeometry.num_faces();
|
|
229
|
+
const numIndices = numFaces * 3;
|
|
230
|
+
const byteLength = numIndices * INDEX_ITEM_SIZE;
|
|
236
231
|
|
|
237
|
-
|
|
232
|
+
const ptr = this.draco._malloc(byteLength);
|
|
238
233
|
|
|
239
|
-
|
|
234
|
+
try {
|
|
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
|
+
}
|
|
240
241
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
size = _this$_getAttributeVa.size;
|
|
242
|
+
_getTriangleStripIndices(dracoGeometry) {
|
|
243
|
+
const dracoArray = new this.draco.DracoInt32Array();
|
|
244
244
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
245
|
+
try {
|
|
246
|
+
this.decoder.GetTriangleStripsFromMesh(dracoGeometry, dracoArray);
|
|
247
|
+
return getUint32Array(dracoArray);
|
|
248
|
+
} finally {
|
|
249
|
+
this.draco.destroy(dracoArray);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
253
252
|
|
|
254
|
-
|
|
253
|
+
_getAttributeValues(dracoGeometry, attribute) {
|
|
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);
|
|
255
270
|
}
|
|
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;
|
|
262
271
|
|
|
263
|
-
|
|
272
|
+
return {
|
|
273
|
+
value,
|
|
274
|
+
size: numComponents
|
|
275
|
+
};
|
|
276
|
+
}
|
|
264
277
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
278
|
+
_deduceAttributeName(attribute, options) {
|
|
279
|
+
const uniqueId = attribute.unique_id;
|
|
280
|
+
|
|
281
|
+
for (const [attributeName, attributeUniqueId] of Object.entries(options.extraAttributes || {})) {
|
|
282
|
+
if (attributeUniqueId === uniqueId) {
|
|
283
|
+
return attributeName;
|
|
270
284
|
}
|
|
271
285
|
}
|
|
272
|
-
}, {
|
|
273
|
-
key: "_getTriangleStripIndices",
|
|
274
|
-
value: function _getTriangleStripIndices(dracoGeometry) {
|
|
275
|
-
var dracoArray = new this.draco.DracoInt32Array();
|
|
276
286
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
287
|
+
const thisAttributeType = attribute.attribute_type;
|
|
288
|
+
|
|
289
|
+
for (const dracoAttributeConstant in DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP) {
|
|
290
|
+
const attributeType = this.draco[dracoAttributeConstant];
|
|
291
|
+
|
|
292
|
+
if (attributeType === thisAttributeType) {
|
|
293
|
+
return DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP[dracoAttributeConstant];
|
|
282
294
|
}
|
|
283
295
|
}
|
|
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
|
-
|
|
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
|
-
}
|
|
297
|
+
const entryName = options.attributeNameEntry || 'name';
|
|
304
298
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
size: numComponents
|
|
308
|
-
};
|
|
299
|
+
if (attribute.metadata[entryName]) {
|
|
300
|
+
return attribute.metadata[entryName].string;
|
|
309
301
|
}
|
|
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
|
-
}
|
|
324
302
|
|
|
325
|
-
|
|
303
|
+
return "CUSTOM_ATTRIBUTE_".concat(uniqueId);
|
|
304
|
+
}
|
|
326
305
|
|
|
327
|
-
|
|
328
|
-
|
|
306
|
+
_getTopLevelMetadata(dracoGeometry) {
|
|
307
|
+
const dracoMetadata = this.decoder.GetMetadata(dracoGeometry);
|
|
308
|
+
return this._getDracoMetadata(dracoMetadata);
|
|
309
|
+
}
|
|
329
310
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
311
|
+
_getAttributeMetadata(dracoGeometry, attributeId) {
|
|
312
|
+
const dracoMetadata = this.decoder.GetAttributeMetadata(dracoGeometry, attributeId);
|
|
313
|
+
return this._getDracoMetadata(dracoMetadata);
|
|
314
|
+
}
|
|
334
315
|
|
|
335
|
-
|
|
316
|
+
_getDracoMetadata(dracoMetadata) {
|
|
317
|
+
if (!dracoMetadata || !dracoMetadata.ptr) {
|
|
318
|
+
return {};
|
|
319
|
+
}
|
|
336
320
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
}
|
|
321
|
+
const result = {};
|
|
322
|
+
const numEntries = this.metadataQuerier.NumEntries(dracoMetadata);
|
|
340
323
|
|
|
341
|
-
|
|
324
|
+
for (let entryIndex = 0; entryIndex < numEntries; entryIndex++) {
|
|
325
|
+
const entryName = this.metadataQuerier.GetEntryName(dracoMetadata, entryIndex);
|
|
326
|
+
result[entryName] = this._getDracoMetadataField(dracoMetadata, entryName);
|
|
342
327
|
}
|
|
343
|
-
}, {
|
|
344
|
-
key: "_getTopLevelMetadata",
|
|
345
|
-
value: function _getTopLevelMetadata(dracoGeometry) {
|
|
346
|
-
var dracoMetadata = this.decoder.GetMetadata(dracoGeometry);
|
|
347
|
-
return this._getDracoMetadata(dracoMetadata);
|
|
348
|
-
}
|
|
349
|
-
}, {
|
|
350
|
-
key: "_getAttributeMetadata",
|
|
351
|
-
value: function _getAttributeMetadata(dracoGeometry, attributeId) {
|
|
352
|
-
var dracoMetadata = this.decoder.GetAttributeMetadata(dracoGeometry, attributeId);
|
|
353
|
-
return this._getDracoMetadata(dracoMetadata);
|
|
354
|
-
}
|
|
355
|
-
}, {
|
|
356
|
-
key: "_getDracoMetadata",
|
|
357
|
-
value: function _getDracoMetadata(dracoMetadata) {
|
|
358
|
-
if (!dracoMetadata || !dracoMetadata.ptr) {
|
|
359
|
-
return {};
|
|
360
|
-
}
|
|
361
328
|
|
|
362
|
-
|
|
363
|
-
|
|
329
|
+
return result;
|
|
330
|
+
}
|
|
364
331
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
result[entryName] = this._getDracoMetadataField(dracoMetadata, entryName);
|
|
368
|
-
}
|
|
332
|
+
_getDracoMetadataField(dracoMetadata, entryName) {
|
|
333
|
+
const dracoArray = new this.draco.DracoInt32Array();
|
|
369
334
|
|
|
370
|
-
|
|
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);
|
|
371
346
|
}
|
|
372
|
-
}
|
|
373
|
-
key: "_getDracoMetadataField",
|
|
374
|
-
value: function _getDracoMetadataField(dracoMetadata, entryName) {
|
|
375
|
-
var dracoArray = new this.draco.DracoInt32Array();
|
|
347
|
+
}
|
|
376
348
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
} finally {
|
|
387
|
-
this.draco.destroy(dracoArray);
|
|
388
|
-
}
|
|
349
|
+
_disableAttributeTransforms(options) {
|
|
350
|
+
const {
|
|
351
|
+
quantizedAttributes = [],
|
|
352
|
+
octahedronAttributes = []
|
|
353
|
+
} = options;
|
|
354
|
+
const skipAttributes = [...quantizedAttributes, ...octahedronAttributes];
|
|
355
|
+
|
|
356
|
+
for (const dracoAttributeName of skipAttributes) {
|
|
357
|
+
this.decoder.SkipAttributeTransform(this.draco[dracoAttributeName]);
|
|
389
358
|
}
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
_getQuantizationTransform(dracoAttribute, options) {
|
|
362
|
+
const {
|
|
363
|
+
quantizedAttributes = []
|
|
364
|
+
} = options;
|
|
365
|
+
const attribute_type = dracoAttribute.attribute_type();
|
|
366
|
+
const skip = quantizedAttributes.map(type => this.decoder[type]).includes(attribute_type);
|
|
367
|
+
|
|
368
|
+
if (skip) {
|
|
369
|
+
const transform = new this.draco.AttributeQuantizationTransform();
|
|
401
370
|
|
|
402
371
|
try {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
372
|
+
if (transform.InitFromAttribute(dracoAttribute)) {
|
|
373
|
+
return {
|
|
374
|
+
quantization_bits: transform.quantization_bits(),
|
|
375
|
+
range: transform.range(),
|
|
376
|
+
min_values: new Float32Array([1, 2, 3]).map(i => transform.min_value(i))
|
|
377
|
+
};
|
|
406
378
|
}
|
|
407
|
-
} catch (err) {
|
|
408
|
-
_iterator.e(err);
|
|
409
379
|
} finally {
|
|
410
|
-
|
|
380
|
+
this.draco.destroy(transform);
|
|
411
381
|
}
|
|
412
382
|
}
|
|
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
|
-
}
|
|
442
383
|
|
|
443
|
-
|
|
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);
|
|
384
|
+
return null;
|
|
385
|
+
}
|
|
456
386
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
387
|
+
_getOctahedronTransform(dracoAttribute, options) {
|
|
388
|
+
const {
|
|
389
|
+
octahedronAttributes = []
|
|
390
|
+
} = options;
|
|
391
|
+
const attribute_type = dracoAttribute.attribute_type();
|
|
392
|
+
const octahedron = octahedronAttributes.map(type => this.decoder[type]).includes(attribute_type);
|
|
393
|
+
|
|
394
|
+
if (octahedron) {
|
|
395
|
+
const transform = new this.draco.AttributeQuantizationTransform();
|
|
396
|
+
|
|
397
|
+
try {
|
|
398
|
+
if (transform.InitFromAttribute(dracoAttribute)) {
|
|
399
|
+
return {
|
|
400
|
+
quantization_bits: transform.quantization_bits()
|
|
401
|
+
};
|
|
468
402
|
}
|
|
403
|
+
} finally {
|
|
404
|
+
this.draco.destroy(transform);
|
|
469
405
|
}
|
|
470
|
-
|
|
471
|
-
return null;
|
|
472
406
|
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
}
|
|
407
|
+
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
}
|
|
476
412
|
|
|
477
413
|
exports.default = DracoParser;
|
|
478
414
|
|
|
@@ -505,10 +441,10 @@ function getDracoDataType(draco, attributeType) {
|
|
|
505
441
|
}
|
|
506
442
|
|
|
507
443
|
function getInt32Array(dracoArray) {
|
|
508
|
-
|
|
509
|
-
|
|
444
|
+
const numValues = dracoArray.size();
|
|
445
|
+
const intArray = new Int32Array(numValues);
|
|
510
446
|
|
|
511
|
-
for (
|
|
447
|
+
for (let i = 0; i < numValues; i++) {
|
|
512
448
|
intArray[i] = dracoArray.GetValue(i);
|
|
513
449
|
}
|
|
514
450
|
|
|
@@ -516,10 +452,10 @@ function getInt32Array(dracoArray) {
|
|
|
516
452
|
}
|
|
517
453
|
|
|
518
454
|
function getUint32Array(dracoArray) {
|
|
519
|
-
|
|
520
|
-
|
|
455
|
+
const numValues = dracoArray.size();
|
|
456
|
+
const intArray = new Int32Array(numValues);
|
|
521
457
|
|
|
522
|
-
for (
|
|
458
|
+
for (let i = 0; i < numValues; i++) {
|
|
523
459
|
intArray[i] = dracoArray.GetValue(i);
|
|
524
460
|
}
|
|
525
461
|
|