@loaders.gl/draco 3.1.3 → 4.0.0-alpha.5
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/bundle.js +2 -2
- package/dist/bundle.js.map +1 -0
- package/dist/dist.min.js +2 -2
- package/dist/dist.min.js.map +2 -2
- package/dist/draco-loader.js +21 -27
- package/dist/draco-loader.js.map +1 -0
- package/dist/draco-worker.js +1 -1
- package/dist/draco-worker.js.map +2 -2
- package/dist/draco-writer.js +27 -39
- package/dist/draco-writer.js.map +1 -0
- package/dist/draco3d/draco3d-types.js +44 -47
- package/dist/draco3d/draco3d-types.js.map +1 -0
- package/dist/index.js +21 -28
- package/dist/index.js.map +1 -0
- package/dist/lib/draco-builder.js +329 -313
- package/dist/lib/draco-builder.js.map +1 -0
- package/dist/lib/draco-module-loader.js +72 -78
- package/dist/lib/draco-module-loader.js.map +1 -0
- package/dist/lib/draco-parser.js +416 -440
- package/dist/lib/draco-parser.js.map +1 -0
- package/dist/lib/draco-types.js +2 -3
- package/dist/{es5/lib → lib}/draco-types.js.map +0 -0
- package/dist/lib/utils/get-draco-schema.js +41 -35
- package/dist/lib/utils/get-draco-schema.js.map +1 -0
- package/dist/lib/utils/version.js +2 -7
- package/dist/lib/utils/version.js.map +1 -0
- package/dist/workers/draco-worker.js +4 -5
- package/dist/workers/draco-worker.js.map +1 -0
- package/package.json +8 -8
- package/dist/es5/bundle.js +0 -7
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/draco-loader.js +0 -38
- package/dist/es5/draco-loader.js.map +0 -1
- package/dist/es5/draco-writer.js +0 -78
- package/dist/es5/draco-writer.js.map +0 -1
- package/dist/es5/draco3d/draco3d-types.js +0 -58
- package/dist/es5/draco3d/draco3d-types.js.map +0 -1
- package/dist/es5/index.js +0 -85
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/draco-builder.js +0 -409
- package/dist/es5/lib/draco-builder.js.map +0 -1
- package/dist/es5/lib/draco-module-loader.js +0 -229
- package/dist/es5/lib/draco-module-loader.js.map +0 -1
- package/dist/es5/lib/draco-parser.js +0 -528
- package/dist/es5/lib/draco-parser.js.map +0 -1
- package/dist/es5/lib/draco-types.js +0 -2
- package/dist/es5/lib/utils/get-draco-schema.js +0 -55
- package/dist/es5/lib/utils/get-draco-schema.js.map +0 -1
- package/dist/es5/lib/utils/version.js +0 -9
- package/dist/es5/lib/utils/version.js.map +0 -1
- package/dist/es5/workers/draco-worker.js +0 -8
- package/dist/es5/workers/draco-worker.js.map +0 -1
- package/dist/esm/bundle.js +0 -5
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/draco-loader.js +0 -24
- package/dist/esm/draco-loader.js.map +0 -1
- package/dist/esm/draco-writer.js +0 -32
- package/dist/esm/draco-writer.js.map +0 -1
- package/dist/esm/draco3d/draco3d-types.js +0 -48
- package/dist/esm/draco3d/draco3d-types.js.map +0 -1
- package/dist/esm/index.js +0 -24
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/draco-builder.js +0 -354
- package/dist/esm/lib/draco-builder.js.map +0 -1
- package/dist/esm/lib/draco-module-loader.js +0 -85
- package/dist/esm/lib/draco-module-loader.js.map +0 -1
- package/dist/esm/lib/draco-parser.js +0 -452
- package/dist/esm/lib/draco-parser.js.map +0 -1
- package/dist/esm/lib/draco-types.js +0 -2
- package/dist/esm/lib/draco-types.js.map +0 -1
- package/dist/esm/lib/utils/get-draco-schema.js +0 -48
- package/dist/esm/lib/utils/get-draco-schema.js.map +0 -1
- package/dist/esm/lib/utils/version.js +0 -2
- package/dist/esm/lib/utils/version.js.map +0 -1
- package/dist/esm/workers/draco-worker.js +0 -4
- package/dist/esm/workers/draco-worker.js.map +0 -1
package/dist/lib/draco-parser.js
CHANGED
|
@@ -1,476 +1,452 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const schema_1 = require("@loaders.gl/schema");
|
|
5
|
-
const get_draco_schema_1 = require("./utils/get-draco-schema");
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
import { getMeshBoundingBox } from '@loaders.gl/schema';
|
|
3
|
+
import { getDracoSchema } from './utils/get-draco-schema';
|
|
8
4
|
const GEOMETRY_TYPE = {
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
TRIANGULAR_MESH: 0,
|
|
6
|
+
POINT_CLOUD: 1
|
|
11
7
|
};
|
|
12
|
-
// Native Draco attribute names to GLTF attribute names.
|
|
13
8
|
const DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
POSITION: 'POSITION',
|
|
10
|
+
NORMAL: 'NORMAL',
|
|
11
|
+
COLOR: 'COLOR_0',
|
|
12
|
+
TEX_COORD: 'TEXCOORD_0'
|
|
18
13
|
};
|
|
19
14
|
const DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
1: Int8Array,
|
|
16
|
+
2: Uint8Array,
|
|
17
|
+
3: Int16Array,
|
|
18
|
+
4: Uint16Array,
|
|
19
|
+
5: Int32Array,
|
|
20
|
+
6: Uint32Array,
|
|
21
|
+
9: Float32Array
|
|
27
22
|
};
|
|
28
23
|
const INDEX_ITEM_SIZE = 4;
|
|
29
|
-
class DracoParser {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
24
|
+
export default class DracoParser {
|
|
25
|
+
constructor(draco) {
|
|
26
|
+
_defineProperty(this, "draco", void 0);
|
|
27
|
+
|
|
28
|
+
_defineProperty(this, "decoder", void 0);
|
|
29
|
+
|
|
30
|
+
_defineProperty(this, "metadataQuerier", void 0);
|
|
31
|
+
|
|
32
|
+
this.draco = draco;
|
|
33
|
+
this.decoder = new this.draco.Decoder();
|
|
34
|
+
this.metadataQuerier = new this.draco.MetadataQuerier();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
destroy() {
|
|
38
|
+
this.draco.destroy(this.decoder);
|
|
39
|
+
this.draco.destroy(this.metadataQuerier);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
parseSync(arrayBuffer, options = {}) {
|
|
43
|
+
const buffer = new this.draco.DecoderBuffer();
|
|
44
|
+
buffer.Init(new Int8Array(arrayBuffer), arrayBuffer.byteLength);
|
|
45
|
+
|
|
46
|
+
this._disableAttributeTransforms(options);
|
|
47
|
+
|
|
48
|
+
const geometry_type = this.decoder.GetEncodedGeometryType(buffer);
|
|
49
|
+
const dracoGeometry = geometry_type === this.draco.TRIANGULAR_MESH ? new this.draco.Mesh() : new this.draco.PointCloud();
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
let dracoStatus;
|
|
53
|
+
|
|
54
|
+
switch (geometry_type) {
|
|
55
|
+
case this.draco.TRIANGULAR_MESH:
|
|
56
|
+
dracoStatus = this.decoder.DecodeBufferToMesh(buffer, dracoGeometry);
|
|
57
|
+
break;
|
|
58
|
+
|
|
59
|
+
case this.draco.POINT_CLOUD:
|
|
60
|
+
dracoStatus = this.decoder.DecodeBufferToPointCloud(buffer, dracoGeometry);
|
|
61
|
+
break;
|
|
62
|
+
|
|
63
|
+
default:
|
|
64
|
+
throw new Error('DRACO: Unknown geometry type.');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (!dracoStatus.ok() || !dracoGeometry.ptr) {
|
|
68
|
+
const message = "DRACO decompression failed: ".concat(dracoStatus.error_msg());
|
|
69
|
+
throw new Error(message);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const loaderData = this._getDracoLoaderData(dracoGeometry, geometry_type, options);
|
|
73
|
+
|
|
74
|
+
const geometry = this._getMeshData(dracoGeometry, loaderData, options);
|
|
75
|
+
|
|
76
|
+
const boundingBox = getMeshBoundingBox(geometry.attributes);
|
|
77
|
+
const schema = getDracoSchema(geometry.attributes, loaderData, geometry.indices);
|
|
78
|
+
const data = {
|
|
79
|
+
loader: 'draco',
|
|
80
|
+
loaderData,
|
|
81
|
+
header: {
|
|
82
|
+
vertexCount: dracoGeometry.num_points(),
|
|
83
|
+
boundingBox
|
|
84
|
+
},
|
|
85
|
+
...geometry,
|
|
86
|
+
schema
|
|
87
|
+
};
|
|
88
|
+
return data;
|
|
89
|
+
} finally {
|
|
90
|
+
this.draco.destroy(buffer);
|
|
91
|
+
|
|
92
|
+
if (dracoGeometry) {
|
|
93
|
+
this.draco.destroy(dracoGeometry);
|
|
94
|
+
}
|
|
42
95
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (dracoGeometry) {
|
|
92
|
-
this.draco.destroy(dracoGeometry);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
_getDracoLoaderData(dracoGeometry, geometry_type, options) {
|
|
99
|
+
const metadata = this._getTopLevelMetadata(dracoGeometry);
|
|
100
|
+
|
|
101
|
+
const attributes = this._getDracoAttributes(dracoGeometry, options);
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
geometry_type,
|
|
105
|
+
num_attributes: dracoGeometry.num_attributes(),
|
|
106
|
+
num_points: dracoGeometry.num_points(),
|
|
107
|
+
num_faces: dracoGeometry instanceof this.draco.Mesh ? dracoGeometry.num_faces() : 0,
|
|
108
|
+
metadata,
|
|
109
|
+
attributes
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
_getDracoAttributes(dracoGeometry, options) {
|
|
114
|
+
const dracoAttributes = {};
|
|
115
|
+
|
|
116
|
+
for (let attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) {
|
|
117
|
+
const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attributeId);
|
|
118
|
+
|
|
119
|
+
const metadata = this._getAttributeMetadata(dracoGeometry, attributeId);
|
|
120
|
+
|
|
121
|
+
dracoAttributes[dracoAttribute.unique_id()] = {
|
|
122
|
+
unique_id: dracoAttribute.unique_id(),
|
|
123
|
+
attribute_type: dracoAttribute.attribute_type(),
|
|
124
|
+
data_type: dracoAttribute.data_type(),
|
|
125
|
+
num_components: dracoAttribute.num_components(),
|
|
126
|
+
byte_offset: dracoAttribute.byte_offset(),
|
|
127
|
+
byte_stride: dracoAttribute.byte_stride(),
|
|
128
|
+
normalized: dracoAttribute.normalized(),
|
|
129
|
+
attribute_index: attributeId,
|
|
130
|
+
metadata
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const quantization = this._getQuantizationTransform(dracoAttribute, options);
|
|
134
|
+
|
|
135
|
+
if (quantization) {
|
|
136
|
+
dracoAttributes[dracoAttribute.unique_id()].quantization_transform = quantization;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const octahedron = this._getOctahedronTransform(dracoAttribute, options);
|
|
140
|
+
|
|
141
|
+
if (octahedron) {
|
|
142
|
+
dracoAttributes[dracoAttribute.unique_id()].octahedron_transform = octahedron;
|
|
143
|
+
}
|
|
95
144
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
return {
|
|
108
|
-
geometry_type,
|
|
109
|
-
num_attributes: dracoGeometry.num_attributes(),
|
|
110
|
-
num_points: dracoGeometry.num_points(),
|
|
111
|
-
num_faces: dracoGeometry instanceof this.draco.Mesh ? dracoGeometry.num_faces() : 0,
|
|
112
|
-
metadata,
|
|
113
|
-
attributes
|
|
114
|
-
};
|
|
145
|
+
|
|
146
|
+
return dracoAttributes;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
_getMeshData(dracoGeometry, loaderData, options) {
|
|
150
|
+
const attributes = this._getMeshAttributes(loaderData, dracoGeometry, options);
|
|
151
|
+
|
|
152
|
+
const positionAttribute = attributes.POSITION;
|
|
153
|
+
|
|
154
|
+
if (!positionAttribute) {
|
|
155
|
+
throw new Error('DRACO: No position attribute found.');
|
|
115
156
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attributeId);
|
|
128
|
-
const metadata = this._getAttributeMetadata(dracoGeometry, attributeId);
|
|
129
|
-
dracoAttributes[dracoAttribute.unique_id()] = {
|
|
130
|
-
unique_id: dracoAttribute.unique_id(),
|
|
131
|
-
attribute_type: dracoAttribute.attribute_type(),
|
|
132
|
-
data_type: dracoAttribute.data_type(),
|
|
133
|
-
num_components: dracoAttribute.num_components(),
|
|
134
|
-
byte_offset: dracoAttribute.byte_offset(),
|
|
135
|
-
byte_stride: dracoAttribute.byte_stride(),
|
|
136
|
-
normalized: dracoAttribute.normalized(),
|
|
137
|
-
attribute_index: attributeId,
|
|
138
|
-
metadata
|
|
139
|
-
};
|
|
140
|
-
// Add transformation parameters for any attributes app wants untransformed
|
|
141
|
-
const quantization = this._getQuantizationTransform(dracoAttribute, options);
|
|
142
|
-
if (quantization) {
|
|
143
|
-
dracoAttributes[dracoAttribute.unique_id()].quantization_transform = quantization;
|
|
157
|
+
|
|
158
|
+
if (dracoGeometry instanceof this.draco.Mesh) {
|
|
159
|
+
switch (options.topology) {
|
|
160
|
+
case 'triangle-strip':
|
|
161
|
+
return {
|
|
162
|
+
topology: 'triangle-strip',
|
|
163
|
+
mode: 4,
|
|
164
|
+
attributes,
|
|
165
|
+
indices: {
|
|
166
|
+
value: this._getTriangleStripIndices(dracoGeometry),
|
|
167
|
+
size: 1
|
|
144
168
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
case 'triangle-list':
|
|
172
|
+
default:
|
|
173
|
+
return {
|
|
174
|
+
topology: 'triangle-list',
|
|
175
|
+
mode: 5,
|
|
176
|
+
attributes,
|
|
177
|
+
indices: {
|
|
178
|
+
value: this._getTriangleListIndices(dracoGeometry),
|
|
179
|
+
size: 1
|
|
148
180
|
}
|
|
149
|
-
|
|
150
|
-
|
|
181
|
+
};
|
|
182
|
+
}
|
|
151
183
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
topology: 'triangle-list',
|
|
181
|
-
mode: 5,
|
|
182
|
-
attributes,
|
|
183
|
-
indices: {
|
|
184
|
-
value: this._getTriangleListIndices(dracoGeometry),
|
|
185
|
-
size: 1
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
// PointCloud - must come last as Mesh inherits from PointCloud
|
|
191
|
-
return {
|
|
192
|
-
topology: 'point-list',
|
|
193
|
-
mode: 0,
|
|
194
|
-
attributes
|
|
195
|
-
};
|
|
184
|
+
|
|
185
|
+
return {
|
|
186
|
+
topology: 'point-list',
|
|
187
|
+
mode: 0,
|
|
188
|
+
attributes
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
_getMeshAttributes(loaderData, dracoGeometry, options) {
|
|
193
|
+
const attributes = {};
|
|
194
|
+
|
|
195
|
+
for (const loaderAttribute of Object.values(loaderData.attributes)) {
|
|
196
|
+
const attributeName = this._deduceAttributeName(loaderAttribute, options);
|
|
197
|
+
|
|
198
|
+
loaderAttribute.name = attributeName;
|
|
199
|
+
|
|
200
|
+
const {
|
|
201
|
+
value,
|
|
202
|
+
size
|
|
203
|
+
} = this._getAttributeValues(dracoGeometry, loaderAttribute);
|
|
204
|
+
|
|
205
|
+
attributes[attributeName] = {
|
|
206
|
+
value,
|
|
207
|
+
size,
|
|
208
|
+
byteOffset: loaderAttribute.byte_offset,
|
|
209
|
+
byteStride: loaderAttribute.byte_stride,
|
|
210
|
+
normalized: loaderAttribute.normalized
|
|
211
|
+
};
|
|
196
212
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
213
|
+
|
|
214
|
+
return attributes;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
_getTriangleListIndices(dracoGeometry) {
|
|
218
|
+
const numFaces = dracoGeometry.num_faces();
|
|
219
|
+
const numIndices = numFaces * 3;
|
|
220
|
+
const byteLength = numIndices * INDEX_ITEM_SIZE;
|
|
221
|
+
|
|
222
|
+
const ptr = this.draco._malloc(byteLength);
|
|
223
|
+
|
|
224
|
+
try {
|
|
225
|
+
this.decoder.GetTrianglesUInt32Array(dracoGeometry, byteLength, ptr);
|
|
226
|
+
return new Uint32Array(this.draco.HEAPF32.buffer, ptr, numIndices).slice();
|
|
227
|
+
} finally {
|
|
228
|
+
this.draco._free(ptr);
|
|
212
229
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const ptr = this.draco._malloc(byteLength);
|
|
224
|
-
try {
|
|
225
|
-
this.decoder.GetTrianglesUInt32Array(dracoGeometry, byteLength, ptr);
|
|
226
|
-
return new Uint32Array(this.draco.HEAPF32.buffer, ptr, numIndices).slice();
|
|
227
|
-
}
|
|
228
|
-
finally {
|
|
229
|
-
this.draco._free(ptr);
|
|
230
|
-
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
_getTriangleStripIndices(dracoGeometry) {
|
|
233
|
+
const dracoArray = new this.draco.DracoInt32Array();
|
|
234
|
+
|
|
235
|
+
try {
|
|
236
|
+
this.decoder.GetTriangleStripsFromMesh(dracoGeometry, dracoArray);
|
|
237
|
+
return getUint32Array(dracoArray);
|
|
238
|
+
} finally {
|
|
239
|
+
this.draco.destroy(dracoArray);
|
|
231
240
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
_getAttributeValues(dracoGeometry, attribute) {
|
|
244
|
+
const TypedArrayCtor = DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP[attribute.data_type];
|
|
245
|
+
const numComponents = attribute.num_components;
|
|
246
|
+
const numPoints = dracoGeometry.num_points();
|
|
247
|
+
const numValues = numPoints * numComponents;
|
|
248
|
+
const byteLength = numValues * TypedArrayCtor.BYTES_PER_ELEMENT;
|
|
249
|
+
const dataType = getDracoDataType(this.draco, TypedArrayCtor);
|
|
250
|
+
let value;
|
|
251
|
+
|
|
252
|
+
const ptr = this.draco._malloc(byteLength);
|
|
253
|
+
|
|
254
|
+
try {
|
|
255
|
+
const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attribute.attribute_index);
|
|
256
|
+
this.decoder.GetAttributeDataArrayForAllPoints(dracoGeometry, dracoAttribute, dataType, byteLength, ptr);
|
|
257
|
+
value = new TypedArrayCtor(this.draco.HEAPF32.buffer, ptr, numValues).slice();
|
|
258
|
+
} finally {
|
|
259
|
+
this.draco._free(ptr);
|
|
245
260
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
const ptr = this.draco._malloc(byteLength);
|
|
261
|
-
try {
|
|
262
|
-
const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attribute.attribute_index);
|
|
263
|
-
this.decoder.GetAttributeDataArrayForAllPoints(dracoGeometry, dracoAttribute, dataType, byteLength, ptr);
|
|
264
|
-
value = new TypedArrayCtor(this.draco.HEAPF32.buffer, ptr, numValues).slice();
|
|
265
|
-
}
|
|
266
|
-
finally {
|
|
267
|
-
this.draco._free(ptr);
|
|
268
|
-
}
|
|
269
|
-
return { value, size: numComponents };
|
|
261
|
+
|
|
262
|
+
return {
|
|
263
|
+
value,
|
|
264
|
+
size: numComponents
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
_deduceAttributeName(attribute, options) {
|
|
269
|
+
const uniqueId = attribute.unique_id;
|
|
270
|
+
|
|
271
|
+
for (const [attributeName, attributeUniqueId] of Object.entries(options.extraAttributes || {})) {
|
|
272
|
+
if (attributeUniqueId === uniqueId) {
|
|
273
|
+
return attributeName;
|
|
274
|
+
}
|
|
270
275
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
const attributeNames: {[unique_id: number]: string} = {};
|
|
280
|
-
for (let attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) {
|
|
281
|
-
const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attributeId);
|
|
282
|
-
const attributeName = this._deduceAttributeName(dracoAttribute, options);
|
|
283
|
-
attributeNames[attributeName] = attributeName;
|
|
276
|
+
|
|
277
|
+
const thisAttributeType = attribute.attribute_type;
|
|
278
|
+
|
|
279
|
+
for (const dracoAttributeConstant in DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP) {
|
|
280
|
+
const attributeType = this.draco[dracoAttributeConstant];
|
|
281
|
+
|
|
282
|
+
if (attributeType === thisAttributeType) {
|
|
283
|
+
return DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP[dracoAttributeConstant];
|
|
284
284
|
}
|
|
285
|
-
return attributeNames;
|
|
286
285
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
* types
|
|
293
|
-
* @param attributeData
|
|
294
|
-
*/
|
|
295
|
-
_deduceAttributeName(attribute, options) {
|
|
296
|
-
// Deduce name based on application provided map
|
|
297
|
-
const uniqueId = attribute.unique_id;
|
|
298
|
-
for (const [attributeName, attributeUniqueId] of Object.entries(options.extraAttributes || {})) {
|
|
299
|
-
if (attributeUniqueId === uniqueId) {
|
|
300
|
-
return attributeName;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
// Deduce name based on attribute type
|
|
304
|
-
const thisAttributeType = attribute.attribute_type;
|
|
305
|
-
for (const dracoAttributeConstant in DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP) {
|
|
306
|
-
const attributeType = this.draco[dracoAttributeConstant];
|
|
307
|
-
if (attributeType === thisAttributeType) {
|
|
308
|
-
// TODO - Return unique names if there multiple attributes per type
|
|
309
|
-
// (e.g. multiple TEX_COORDS or COLORS)
|
|
310
|
-
return DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP[dracoAttributeConstant];
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
// Look up in metadata
|
|
314
|
-
// TODO - shouldn't this have priority?
|
|
315
|
-
const entryName = options.attributeNameEntry || 'name';
|
|
316
|
-
if (attribute.metadata[entryName]) {
|
|
317
|
-
return attribute.metadata[entryName].string;
|
|
318
|
-
}
|
|
319
|
-
// Attribute of "GENERIC" type, we need to assign some name
|
|
320
|
-
return `CUSTOM_ATTRIBUTE_${uniqueId}`;
|
|
286
|
+
|
|
287
|
+
const entryName = options.attributeNameEntry || 'name';
|
|
288
|
+
|
|
289
|
+
if (attribute.metadata[entryName]) {
|
|
290
|
+
return attribute.metadata[entryName].string;
|
|
321
291
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
292
|
+
|
|
293
|
+
return "CUSTOM_ATTRIBUTE_".concat(uniqueId);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
_getTopLevelMetadata(dracoGeometry) {
|
|
297
|
+
const dracoMetadata = this.decoder.GetMetadata(dracoGeometry);
|
|
298
|
+
return this._getDracoMetadata(dracoMetadata);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
_getAttributeMetadata(dracoGeometry, attributeId) {
|
|
302
|
+
const dracoMetadata = this.decoder.GetAttributeMetadata(dracoGeometry, attributeId);
|
|
303
|
+
return this._getDracoMetadata(dracoMetadata);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
_getDracoMetadata(dracoMetadata) {
|
|
307
|
+
if (!dracoMetadata || !dracoMetadata.ptr) {
|
|
308
|
+
return {};
|
|
327
309
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
310
|
+
|
|
311
|
+
const result = {};
|
|
312
|
+
const numEntries = this.metadataQuerier.NumEntries(dracoMetadata);
|
|
313
|
+
|
|
314
|
+
for (let entryIndex = 0; entryIndex < numEntries; entryIndex++) {
|
|
315
|
+
const entryName = this.metadataQuerier.GetEntryName(dracoMetadata, entryIndex);
|
|
316
|
+
result[entryName] = this._getDracoMetadataField(dracoMetadata, entryName);
|
|
332
317
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
318
|
+
|
|
319
|
+
return result;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
_getDracoMetadataField(dracoMetadata, entryName) {
|
|
323
|
+
const dracoArray = new this.draco.DracoInt32Array();
|
|
324
|
+
|
|
325
|
+
try {
|
|
326
|
+
this.metadataQuerier.GetIntEntryArray(dracoMetadata, entryName, dracoArray);
|
|
327
|
+
const intArray = getInt32Array(dracoArray);
|
|
328
|
+
return {
|
|
329
|
+
int: this.metadataQuerier.GetIntEntry(dracoMetadata, entryName),
|
|
330
|
+
string: this.metadataQuerier.GetStringEntry(dracoMetadata, entryName),
|
|
331
|
+
double: this.metadataQuerier.GetDoubleEntry(dracoMetadata, entryName),
|
|
332
|
+
intArray
|
|
333
|
+
};
|
|
334
|
+
} finally {
|
|
335
|
+
this.draco.destroy(dracoArray);
|
|
350
336
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
return {
|
|
363
|
-
int: this.metadataQuerier.GetIntEntry(dracoMetadata, entryName),
|
|
364
|
-
string: this.metadataQuerier.GetStringEntry(dracoMetadata, entryName),
|
|
365
|
-
double: this.metadataQuerier.GetDoubleEntry(dracoMetadata, entryName),
|
|
366
|
-
intArray
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
finally {
|
|
370
|
-
this.draco.destroy(dracoArray);
|
|
371
|
-
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
_disableAttributeTransforms(options) {
|
|
340
|
+
const {
|
|
341
|
+
quantizedAttributes = [],
|
|
342
|
+
octahedronAttributes = []
|
|
343
|
+
} = options;
|
|
344
|
+
const skipAttributes = [...quantizedAttributes, ...octahedronAttributes];
|
|
345
|
+
|
|
346
|
+
for (const dracoAttributeName of skipAttributes) {
|
|
347
|
+
this.decoder.SkipAttributeTransform(this.draco[dracoAttributeName]);
|
|
372
348
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
_getQuantizationTransform(dracoAttribute, options) {
|
|
352
|
+
const {
|
|
353
|
+
quantizedAttributes = []
|
|
354
|
+
} = options;
|
|
355
|
+
const attribute_type = dracoAttribute.attribute_type();
|
|
356
|
+
const skip = quantizedAttributes.map(type => this.decoder[type]).includes(attribute_type);
|
|
357
|
+
|
|
358
|
+
if (skip) {
|
|
359
|
+
const transform = new this.draco.AttributeQuantizationTransform();
|
|
360
|
+
|
|
361
|
+
try {
|
|
362
|
+
if (transform.InitFromAttribute(dracoAttribute)) {
|
|
363
|
+
return {
|
|
364
|
+
quantization_bits: transform.quantization_bits(),
|
|
365
|
+
range: transform.range(),
|
|
366
|
+
min_values: new Float32Array([1, 2, 3]).map(i => transform.min_value(i))
|
|
367
|
+
};
|
|
380
368
|
}
|
|
369
|
+
} finally {
|
|
370
|
+
this.draco.destroy(transform);
|
|
371
|
+
}
|
|
381
372
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
finally {
|
|
402
|
-
this.draco.destroy(transform);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
return null;
|
|
406
|
-
}
|
|
407
|
-
_getOctahedronTransform(dracoAttribute, options) {
|
|
408
|
-
const { octahedronAttributes = [] } = options;
|
|
409
|
-
const attribute_type = dracoAttribute.attribute_type();
|
|
410
|
-
const octahedron = octahedronAttributes
|
|
411
|
-
.map((type) => this.decoder[type])
|
|
412
|
-
.includes(attribute_type);
|
|
413
|
-
if (octahedron) {
|
|
414
|
-
const transform = new this.draco.AttributeQuantizationTransform();
|
|
415
|
-
try {
|
|
416
|
-
if (transform.InitFromAttribute(dracoAttribute)) {
|
|
417
|
-
return {
|
|
418
|
-
quantization_bits: transform.quantization_bits()
|
|
419
|
-
};
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
finally {
|
|
423
|
-
this.draco.destroy(transform);
|
|
424
|
-
}
|
|
373
|
+
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
_getOctahedronTransform(dracoAttribute, options) {
|
|
378
|
+
const {
|
|
379
|
+
octahedronAttributes = []
|
|
380
|
+
} = options;
|
|
381
|
+
const attribute_type = dracoAttribute.attribute_type();
|
|
382
|
+
const octahedron = octahedronAttributes.map(type => this.decoder[type]).includes(attribute_type);
|
|
383
|
+
|
|
384
|
+
if (octahedron) {
|
|
385
|
+
const transform = new this.draco.AttributeQuantizationTransform();
|
|
386
|
+
|
|
387
|
+
try {
|
|
388
|
+
if (transform.InitFromAttribute(dracoAttribute)) {
|
|
389
|
+
return {
|
|
390
|
+
quantization_bits: transform.quantization_bits()
|
|
391
|
+
};
|
|
425
392
|
}
|
|
426
|
-
|
|
393
|
+
} finally {
|
|
394
|
+
this.draco.destroy(transform);
|
|
395
|
+
}
|
|
427
396
|
}
|
|
397
|
+
|
|
398
|
+
return null;
|
|
399
|
+
}
|
|
400
|
+
|
|
428
401
|
}
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
* Get draco specific data type by TypedArray constructor type
|
|
432
|
-
* @param attributeType
|
|
433
|
-
* @returns draco specific data type
|
|
434
|
-
*/
|
|
402
|
+
|
|
435
403
|
function getDracoDataType(draco, attributeType) {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
404
|
+
switch (attributeType) {
|
|
405
|
+
case Float32Array:
|
|
406
|
+
return draco.DT_FLOAT32;
|
|
407
|
+
|
|
408
|
+
case Int8Array:
|
|
409
|
+
return draco.DT_INT8;
|
|
410
|
+
|
|
411
|
+
case Int16Array:
|
|
412
|
+
return draco.DT_INT16;
|
|
413
|
+
|
|
414
|
+
case Int32Array:
|
|
415
|
+
return draco.DT_INT32;
|
|
416
|
+
|
|
417
|
+
case Uint8Array:
|
|
418
|
+
return draco.DT_UINT8;
|
|
419
|
+
|
|
420
|
+
case Uint16Array:
|
|
421
|
+
return draco.DT_UINT16;
|
|
422
|
+
|
|
423
|
+
case Uint32Array:
|
|
424
|
+
return draco.DT_UINT32;
|
|
425
|
+
|
|
426
|
+
default:
|
|
427
|
+
return draco.DT_INVALID;
|
|
428
|
+
}
|
|
454
429
|
}
|
|
455
|
-
|
|
456
|
-
* Copy a Draco int32 array into a JS typed array
|
|
457
|
-
*/
|
|
430
|
+
|
|
458
431
|
function getInt32Array(dracoArray) {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
432
|
+
const numValues = dracoArray.size();
|
|
433
|
+
const intArray = new Int32Array(numValues);
|
|
434
|
+
|
|
435
|
+
for (let i = 0; i < numValues; i++) {
|
|
436
|
+
intArray[i] = dracoArray.GetValue(i);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return intArray;
|
|
465
440
|
}
|
|
466
|
-
|
|
467
|
-
* Copy a Draco int32 array into a JS typed array
|
|
468
|
-
*/
|
|
441
|
+
|
|
469
442
|
function getUint32Array(dracoArray) {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
443
|
+
const numValues = dracoArray.size();
|
|
444
|
+
const intArray = new Int32Array(numValues);
|
|
445
|
+
|
|
446
|
+
for (let i = 0; i < numValues; i++) {
|
|
447
|
+
intArray[i] = dracoArray.GetValue(i);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
return intArray;
|
|
476
451
|
}
|
|
452
|
+
//# sourceMappingURL=draco-parser.js.map
|