@loaders.gl/gltf 4.0.0-alpha.23 → 4.0.0-alpha.25
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 +378 -241
- package/dist/es5/index.js +12 -0
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/api/gltf-extensions.js +1 -1
- package/dist/es5/lib/api/gltf-extensions.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_mesh_features.js +13 -25
- package/dist/es5/lib/extensions/EXT_mesh_features.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_structural_metadata.js +152 -106
- package/dist/es5/lib/extensions/EXT_structural_metadata.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +64 -16
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
- package/dist/es5/lib/extensions/{data-processing.js → utils/3d-tiles-utils.js} +51 -24
- package/dist/es5/lib/extensions/utils/3d-tiles-utils.js.map +1 -0
- package/dist/es5/lib/gltf-utils/gltf-utils.js +29 -0
- package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -1
- package/dist/es5/lib/types/gltf-ext-feature-metadata-schema.js +2 -0
- package/dist/es5/lib/types/gltf-ext-feature-metadata-schema.js.map +1 -0
- package/dist/es5/lib/types/gltf-ext-mesh-features-schema.js.map +1 -1
- package/dist/es5/lib/types/gltf-ext-structural-metadata-schema.js.map +1 -1
- package/dist/es5/lib/types/gltf-json-schema.js.map +1 -1
- package/dist/es5/lib/types/gltf-types.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/api/gltf-extensions.js +1 -1
- package/dist/esm/lib/api/gltf-extensions.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_mesh_features.js +13 -25
- package/dist/esm/lib/extensions/EXT_mesh_features.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_structural_metadata.js +127 -89
- package/dist/esm/lib/extensions/EXT_structural_metadata.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js +64 -17
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
- package/dist/esm/lib/extensions/{data-processing.js → utils/3d-tiles-utils.js} +50 -24
- package/dist/esm/lib/extensions/utils/3d-tiles-utils.js.map +1 -0
- package/dist/esm/lib/gltf-utils/gltf-utils.js +30 -0
- package/dist/esm/lib/gltf-utils/gltf-utils.js.map +1 -1
- package/dist/esm/lib/types/gltf-ext-feature-metadata-schema.js +2 -0
- package/dist/esm/lib/types/gltf-ext-feature-metadata-schema.js.map +1 -0
- package/dist/esm/lib/types/gltf-ext-mesh-features-schema.js.map +1 -1
- package/dist/esm/lib/types/gltf-ext-structural-metadata-schema.js.map +1 -1
- package/dist/esm/lib/types/gltf-json-schema.js.map +1 -1
- package/dist/esm/lib/types/gltf-types.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_mesh_features.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_structural_metadata.d.ts +12 -4
- package/dist/lib/extensions/EXT_structural_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +9 -0
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/utils/3d-tiles-utils.d.ts +52 -0
- package/dist/lib/extensions/utils/3d-tiles-utils.d.ts.map +1 -0
- package/dist/lib/gltf-utils/gltf-utils.d.ts +2 -0
- package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts +421 -0
- package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts.map +1 -0
- package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts +4 -6
- package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts +48 -29
- package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-json-schema.d.ts +1 -420
- package/dist/lib/types/gltf-json-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-types.d.ts +3 -0
- package/dist/lib/types/gltf-types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +10 -5
- package/src/lib/api/gltf-extensions.ts +1 -1
- package/src/lib/extensions/EXT_mesh_features.ts +18 -44
- package/src/lib/extensions/EXT_structural_metadata.ts +364 -217
- package/src/lib/extensions/deprecated/EXT_feature_metadata.ts +193 -30
- package/src/lib/extensions/{data-processing.ts → utils/3d-tiles-utils.ts} +128 -56
- package/src/lib/gltf-utils/gltf-utils.ts +38 -0
- package/src/lib/types/gltf-ext-feature-metadata-schema.ts +470 -0
- package/src/lib/types/gltf-ext-mesh-features-schema.ts +4 -6
- package/src/lib/types/gltf-ext-structural-metadata-schema.ts +52 -31
- package/src/lib/types/gltf-json-schema.ts +1 -468
- package/src/lib/types/gltf-types.ts +4 -0
- package/dist/bundle.js +0 -5
- package/dist/es5/lib/extensions/data-processing.js.map +0 -1
- package/dist/esm/lib/extensions/data-processing.js.map +0 -1
- package/dist/glb-loader.js +0 -34
- package/dist/glb-writer.js +0 -35
- package/dist/gltf-loader.js +0 -50
- package/dist/gltf-writer.js +0 -32
- package/dist/index.js +0 -34
- package/dist/lib/api/gltf-extensions.js +0 -88
- package/dist/lib/api/gltf-scenegraph.js +0 -580
- package/dist/lib/api/normalize-gltf-v1.js +0 -299
- package/dist/lib/api/post-process-gltf.js +0 -433
- package/dist/lib/encoders/encode-glb.js +0 -72
- package/dist/lib/encoders/encode-gltf.js +0 -32
- package/dist/lib/extensions/EXT_mesh_features.js +0 -89
- package/dist/lib/extensions/EXT_meshopt_compression.js +0 -41
- package/dist/lib/extensions/EXT_structural_metadata.js +0 -504
- package/dist/lib/extensions/EXT_texture_webp.js +0 -36
- package/dist/lib/extensions/KHR_binary_gltf.js +0 -39
- package/dist/lib/extensions/KHR_draco_mesh_compression.js +0 -137
- package/dist/lib/extensions/KHR_texture_basisu.js +0 -29
- package/dist/lib/extensions/KHR_texture_transform.js +0 -227
- package/dist/lib/extensions/data-processing.d.ts +0 -34
- package/dist/lib/extensions/data-processing.d.ts.map +0 -1
- package/dist/lib/extensions/data-processing.js +0 -212
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +0 -282
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +0 -59
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +0 -44
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +0 -79
- package/dist/lib/gltf-utils/get-typed-array.js +0 -41
- package/dist/lib/gltf-utils/gltf-attribute-utils.js +0 -73
- package/dist/lib/gltf-utils/gltf-constants.js +0 -43
- package/dist/lib/gltf-utils/gltf-utils.js +0 -90
- package/dist/lib/gltf-utils/resolve-url.js +0 -18
- package/dist/lib/parsers/parse-glb.js +0 -166
- package/dist/lib/parsers/parse-gltf.js +0 -185
- package/dist/lib/types/glb-types.js +0 -2
- package/dist/lib/types/gltf-ext-mesh-features-schema.js +0 -2
- package/dist/lib/types/gltf-ext-structural-metadata-schema.js +0 -2
- package/dist/lib/types/gltf-json-schema.js +0 -4
- package/dist/lib/types/gltf-postprocessed-schema.js +0 -4
- package/dist/lib/types/gltf-types.js +0 -3
- package/dist/lib/utils/assert.js +0 -12
- package/dist/lib/utils/version.js +0 -7
- package/dist/meshopt/meshopt-decoder.js +0 -118
- package/dist/webp/webp.js +0 -38
|
@@ -1,433 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.postProcessGLTF = void 0;
|
|
5
|
-
const assert_1 = require("../utils/assert");
|
|
6
|
-
const gltf_utils_1 = require("../gltf-utils/gltf-utils");
|
|
7
|
-
// This is a post processor for loaded glTF files
|
|
8
|
-
// The goal is to make the loaded data easier to use in WebGL applications
|
|
9
|
-
//
|
|
10
|
-
// Functions:
|
|
11
|
-
// * Resolve indexed arrays structure of glTF into a linked tree.
|
|
12
|
-
// * Translate stringified enum keys and values into WebGL constants.
|
|
13
|
-
// * Load images (optional)
|
|
14
|
-
// ENUM LOOKUP
|
|
15
|
-
const COMPONENTS = {
|
|
16
|
-
SCALAR: 1,
|
|
17
|
-
VEC2: 2,
|
|
18
|
-
VEC3: 3,
|
|
19
|
-
VEC4: 4,
|
|
20
|
-
MAT2: 4,
|
|
21
|
-
MAT3: 9,
|
|
22
|
-
MAT4: 16
|
|
23
|
-
};
|
|
24
|
-
const BYTES = {
|
|
25
|
-
5120: 1,
|
|
26
|
-
5121: 1,
|
|
27
|
-
5122: 2,
|
|
28
|
-
5123: 2,
|
|
29
|
-
5125: 4,
|
|
30
|
-
5126: 4 // FLOAT
|
|
31
|
-
};
|
|
32
|
-
const GL_SAMPLER = {
|
|
33
|
-
// Sampler parameters
|
|
34
|
-
TEXTURE_MAG_FILTER: 0x2800,
|
|
35
|
-
TEXTURE_MIN_FILTER: 0x2801,
|
|
36
|
-
TEXTURE_WRAP_S: 0x2802,
|
|
37
|
-
TEXTURE_WRAP_T: 0x2803,
|
|
38
|
-
// Sampler default values
|
|
39
|
-
REPEAT: 0x2901,
|
|
40
|
-
LINEAR: 0x2601,
|
|
41
|
-
NEAREST_MIPMAP_LINEAR: 0x2702
|
|
42
|
-
};
|
|
43
|
-
const SAMPLER_PARAMETER_GLTF_TO_GL = {
|
|
44
|
-
magFilter: GL_SAMPLER.TEXTURE_MAG_FILTER,
|
|
45
|
-
minFilter: GL_SAMPLER.TEXTURE_MIN_FILTER,
|
|
46
|
-
wrapS: GL_SAMPLER.TEXTURE_WRAP_S,
|
|
47
|
-
wrapT: GL_SAMPLER.TEXTURE_WRAP_T
|
|
48
|
-
};
|
|
49
|
-
// When undefined, a sampler with repeat wrapping and auto filtering should be used.
|
|
50
|
-
// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#texture
|
|
51
|
-
const DEFAULT_SAMPLER_PARAMETERS = {
|
|
52
|
-
[GL_SAMPLER.TEXTURE_MAG_FILTER]: GL_SAMPLER.LINEAR,
|
|
53
|
-
[GL_SAMPLER.TEXTURE_MIN_FILTER]: GL_SAMPLER.NEAREST_MIPMAP_LINEAR,
|
|
54
|
-
[GL_SAMPLER.TEXTURE_WRAP_S]: GL_SAMPLER.REPEAT,
|
|
55
|
-
[GL_SAMPLER.TEXTURE_WRAP_T]: GL_SAMPLER.REPEAT
|
|
56
|
-
};
|
|
57
|
-
function makeDefaultSampler() {
|
|
58
|
-
return {
|
|
59
|
-
id: 'default-sampler',
|
|
60
|
-
parameters: DEFAULT_SAMPLER_PARAMETERS
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
function getBytesFromComponentType(componentType) {
|
|
64
|
-
return BYTES[componentType];
|
|
65
|
-
}
|
|
66
|
-
function getSizeFromAccessorType(type) {
|
|
67
|
-
return COMPONENTS[type];
|
|
68
|
-
}
|
|
69
|
-
class GLTFPostProcessor {
|
|
70
|
-
constructor() {
|
|
71
|
-
this.baseUri = '';
|
|
72
|
-
this.buffers = [];
|
|
73
|
-
this.images = [];
|
|
74
|
-
}
|
|
75
|
-
postProcess(gltf, options = {}) {
|
|
76
|
-
const { json, buffers = [], images = [] } = gltf;
|
|
77
|
-
// @ts-expect-error
|
|
78
|
-
const { baseUri = '' } = gltf;
|
|
79
|
-
(0, assert_1.assert)(json);
|
|
80
|
-
this.baseUri = baseUri;
|
|
81
|
-
this.buffers = buffers;
|
|
82
|
-
this.images = images;
|
|
83
|
-
this.jsonUnprocessed = json;
|
|
84
|
-
this.json = this._resolveTree(gltf.json, options);
|
|
85
|
-
return this.json;
|
|
86
|
-
}
|
|
87
|
-
// Convert indexed glTF structure into tree structure
|
|
88
|
-
// cross-link index resolution, enum lookup, convenience calculations
|
|
89
|
-
// eslint-disable-next-line complexity, max-statements
|
|
90
|
-
_resolveTree(gltf, options = {}) {
|
|
91
|
-
// @ts-expect-error
|
|
92
|
-
const json = { ...gltf };
|
|
93
|
-
this.json = json;
|
|
94
|
-
if (gltf.bufferViews) {
|
|
95
|
-
json.bufferViews = gltf.bufferViews.map((bufView, i) => this._resolveBufferView(bufView, i));
|
|
96
|
-
}
|
|
97
|
-
if (gltf.images) {
|
|
98
|
-
json.images = gltf.images.map((image, i) => this._resolveImage(image, i));
|
|
99
|
-
}
|
|
100
|
-
if (gltf.samplers) {
|
|
101
|
-
json.samplers = gltf.samplers.map((sampler, i) => this._resolveSampler(sampler, i));
|
|
102
|
-
}
|
|
103
|
-
if (gltf.textures) {
|
|
104
|
-
json.textures = gltf.textures.map((texture, i) => this._resolveTexture(texture, i));
|
|
105
|
-
}
|
|
106
|
-
if (gltf.accessors) {
|
|
107
|
-
json.accessors = gltf.accessors.map((accessor, i) => this._resolveAccessor(accessor, i));
|
|
108
|
-
}
|
|
109
|
-
if (gltf.materials) {
|
|
110
|
-
json.materials = gltf.materials.map((material, i) => this._resolveMaterial(material, i));
|
|
111
|
-
}
|
|
112
|
-
if (gltf.meshes) {
|
|
113
|
-
json.meshes = gltf.meshes.map((mesh, i) => this._resolveMesh(mesh, i));
|
|
114
|
-
}
|
|
115
|
-
if (gltf.nodes) {
|
|
116
|
-
json.nodes = gltf.nodes.map((node, i) => this._resolveNode(node, i));
|
|
117
|
-
json.nodes = json.nodes.map((node, i) => this._resolveNodeChildren(node));
|
|
118
|
-
}
|
|
119
|
-
if (gltf.skins) {
|
|
120
|
-
json.skins = gltf.skins.map((skin, i) => this._resolveSkin(skin, i));
|
|
121
|
-
}
|
|
122
|
-
if (gltf.scenes) {
|
|
123
|
-
json.scenes = gltf.scenes.map((scene, i) => this._resolveScene(scene, i));
|
|
124
|
-
}
|
|
125
|
-
if (typeof this.json.scene === 'number' && json.scenes) {
|
|
126
|
-
json.scene = json.scenes[this.json.scene];
|
|
127
|
-
}
|
|
128
|
-
return json;
|
|
129
|
-
}
|
|
130
|
-
getScene(index) {
|
|
131
|
-
return this._get(this.json.scenes, index);
|
|
132
|
-
}
|
|
133
|
-
getNode(index) {
|
|
134
|
-
return this._get(this.json.nodes, index);
|
|
135
|
-
}
|
|
136
|
-
getSkin(index) {
|
|
137
|
-
return this._get(this.json.skins, index);
|
|
138
|
-
}
|
|
139
|
-
getMesh(index) {
|
|
140
|
-
return this._get(this.json.meshes, index);
|
|
141
|
-
}
|
|
142
|
-
getMaterial(index) {
|
|
143
|
-
return this._get(this.json.materials, index);
|
|
144
|
-
}
|
|
145
|
-
getAccessor(index) {
|
|
146
|
-
return this._get(this.json.accessors, index);
|
|
147
|
-
}
|
|
148
|
-
getCamera(index) {
|
|
149
|
-
return this._get(this.json.cameras, index);
|
|
150
|
-
}
|
|
151
|
-
getTexture(index) {
|
|
152
|
-
return this._get(this.json.textures, index);
|
|
153
|
-
}
|
|
154
|
-
getSampler(index) {
|
|
155
|
-
return this._get(this.json.samplers, index);
|
|
156
|
-
}
|
|
157
|
-
getImage(index) {
|
|
158
|
-
return this._get(this.json.images, index);
|
|
159
|
-
}
|
|
160
|
-
getBufferView(index) {
|
|
161
|
-
return this._get(this.json.bufferViews, index);
|
|
162
|
-
}
|
|
163
|
-
getBuffer(index) {
|
|
164
|
-
return this._get(this.json.buffers, index);
|
|
165
|
-
}
|
|
166
|
-
_get(array, index) {
|
|
167
|
-
// check if already resolved
|
|
168
|
-
if (typeof index === 'object') {
|
|
169
|
-
return index;
|
|
170
|
-
}
|
|
171
|
-
const object = array && array[index];
|
|
172
|
-
if (!object) {
|
|
173
|
-
console.warn(`glTF file error: Could not find ${array}[${index}]`); // eslint-disable-line
|
|
174
|
-
}
|
|
175
|
-
return object;
|
|
176
|
-
}
|
|
177
|
-
// PARSING HELPERS
|
|
178
|
-
_resolveScene(scene, index) {
|
|
179
|
-
return {
|
|
180
|
-
...scene,
|
|
181
|
-
// @ts-ignore
|
|
182
|
-
id: scene.id || `scene-${index}`,
|
|
183
|
-
nodes: (scene.nodes || []).map((node) => this.getNode(node))
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
_resolveNode(gltfNode, index) {
|
|
187
|
-
// @ts-expect-error
|
|
188
|
-
const node = {
|
|
189
|
-
...gltfNode,
|
|
190
|
-
// @ts-expect-error id could already be present, glTF standard does not prevent it
|
|
191
|
-
id: gltfNode?.id || `node-${index}`
|
|
192
|
-
};
|
|
193
|
-
if (gltfNode.mesh !== undefined) {
|
|
194
|
-
node.mesh = this.getMesh(gltfNode.mesh);
|
|
195
|
-
}
|
|
196
|
-
if (gltfNode.camera !== undefined) {
|
|
197
|
-
node.camera = this.getCamera(gltfNode.camera);
|
|
198
|
-
}
|
|
199
|
-
if (gltfNode.skin !== undefined) {
|
|
200
|
-
node.skin = this.getSkin(gltfNode.skin);
|
|
201
|
-
}
|
|
202
|
-
// TODO deprecated - Delete in v4.0?
|
|
203
|
-
// @ts-expect-error node.meshes does not seem to be part of the GLTF standard
|
|
204
|
-
if (gltfNode.meshes !== undefined && gltfNode.meshes.length) {
|
|
205
|
-
// @ts-expect-error
|
|
206
|
-
node.mesh = gltfNode.meshes.reduce((accum, meshIndex) => {
|
|
207
|
-
const mesh = this.getMesh(meshIndex);
|
|
208
|
-
accum.id = mesh.id;
|
|
209
|
-
accum.primitives = accum.primitives.concat(mesh.primitives);
|
|
210
|
-
return accum;
|
|
211
|
-
}, { primitives: [] });
|
|
212
|
-
}
|
|
213
|
-
return node;
|
|
214
|
-
}
|
|
215
|
-
_resolveNodeChildren(node) {
|
|
216
|
-
if (node.children) {
|
|
217
|
-
// @ts-expect-error node.children are numbers at this stage
|
|
218
|
-
node.children = node.children.map((child) => this.getNode(child));
|
|
219
|
-
}
|
|
220
|
-
return node;
|
|
221
|
-
}
|
|
222
|
-
_resolveSkin(gltfSkin, index) {
|
|
223
|
-
const inverseBindMatrices = typeof gltfSkin.inverseBindMatrices === 'number'
|
|
224
|
-
? this.getAccessor(gltfSkin.inverseBindMatrices)
|
|
225
|
-
: undefined;
|
|
226
|
-
return {
|
|
227
|
-
...gltfSkin,
|
|
228
|
-
id: gltfSkin.id || `skin-${index}`,
|
|
229
|
-
inverseBindMatrices
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
_resolveMesh(gltfMesh, index) {
|
|
233
|
-
const mesh = {
|
|
234
|
-
...gltfMesh,
|
|
235
|
-
id: gltfMesh.id || `mesh-${index}`,
|
|
236
|
-
primitives: []
|
|
237
|
-
};
|
|
238
|
-
if (gltfMesh.primitives) {
|
|
239
|
-
mesh.primitives = gltfMesh.primitives.map((gltfPrimitive) => {
|
|
240
|
-
const primitive = {
|
|
241
|
-
...gltfPrimitive,
|
|
242
|
-
attributes: {},
|
|
243
|
-
indices: undefined,
|
|
244
|
-
material: undefined
|
|
245
|
-
};
|
|
246
|
-
const attributes = gltfPrimitive.attributes;
|
|
247
|
-
for (const attribute in attributes) {
|
|
248
|
-
primitive.attributes[attribute] = this.getAccessor(attributes[attribute]);
|
|
249
|
-
}
|
|
250
|
-
if (gltfPrimitive.indices !== undefined) {
|
|
251
|
-
primitive.indices = this.getAccessor(gltfPrimitive.indices);
|
|
252
|
-
}
|
|
253
|
-
if (gltfPrimitive.material !== undefined) {
|
|
254
|
-
primitive.material = this.getMaterial(gltfPrimitive.material);
|
|
255
|
-
}
|
|
256
|
-
return primitive;
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
return mesh;
|
|
260
|
-
}
|
|
261
|
-
_resolveMaterial(gltfMaterial, index) {
|
|
262
|
-
// @ts-expect-error
|
|
263
|
-
const material = {
|
|
264
|
-
...gltfMaterial,
|
|
265
|
-
// @ts-expect-error
|
|
266
|
-
id: gltfMaterial.id || `material-${index}`
|
|
267
|
-
};
|
|
268
|
-
if (material.normalTexture) {
|
|
269
|
-
material.normalTexture = { ...material.normalTexture };
|
|
270
|
-
material.normalTexture.texture = this.getTexture(material.normalTexture.index);
|
|
271
|
-
}
|
|
272
|
-
if (material.occlusionTexture) {
|
|
273
|
-
material.occlusionTexture = { ...material.occlusionTexture };
|
|
274
|
-
material.occlusionTexture.texture = this.getTexture(material.occlusionTexture.index);
|
|
275
|
-
}
|
|
276
|
-
if (material.emissiveTexture) {
|
|
277
|
-
material.emissiveTexture = { ...material.emissiveTexture };
|
|
278
|
-
material.emissiveTexture.texture = this.getTexture(material.emissiveTexture.index);
|
|
279
|
-
}
|
|
280
|
-
if (!material.emissiveFactor) {
|
|
281
|
-
material.emissiveFactor = material.emissiveTexture ? [1, 1, 1] : [0, 0, 0];
|
|
282
|
-
}
|
|
283
|
-
if (material.pbrMetallicRoughness) {
|
|
284
|
-
material.pbrMetallicRoughness = { ...material.pbrMetallicRoughness };
|
|
285
|
-
const mr = material.pbrMetallicRoughness;
|
|
286
|
-
if (mr.baseColorTexture) {
|
|
287
|
-
mr.baseColorTexture = { ...mr.baseColorTexture };
|
|
288
|
-
mr.baseColorTexture.texture = this.getTexture(mr.baseColorTexture.index);
|
|
289
|
-
}
|
|
290
|
-
if (mr.metallicRoughnessTexture) {
|
|
291
|
-
mr.metallicRoughnessTexture = { ...mr.metallicRoughnessTexture };
|
|
292
|
-
mr.metallicRoughnessTexture.texture = this.getTexture(mr.metallicRoughnessTexture.index);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
return material;
|
|
296
|
-
}
|
|
297
|
-
_resolveAccessor(gltfAccessor, index) {
|
|
298
|
-
// Look up enums
|
|
299
|
-
const bytesPerComponent = getBytesFromComponentType(gltfAccessor.componentType);
|
|
300
|
-
const components = getSizeFromAccessorType(gltfAccessor.type);
|
|
301
|
-
const bytesPerElement = bytesPerComponent * components;
|
|
302
|
-
const accessor = {
|
|
303
|
-
...gltfAccessor,
|
|
304
|
-
// @ts-expect-error
|
|
305
|
-
id: gltfAccessor.id || `accessor-${index}`,
|
|
306
|
-
bytesPerComponent,
|
|
307
|
-
components,
|
|
308
|
-
bytesPerElement,
|
|
309
|
-
value: undefined,
|
|
310
|
-
bufferView: undefined,
|
|
311
|
-
sparse: undefined
|
|
312
|
-
};
|
|
313
|
-
if (gltfAccessor.bufferView !== undefined) {
|
|
314
|
-
// Draco encoded meshes don't have bufferView
|
|
315
|
-
accessor.bufferView = this.getBufferView(gltfAccessor.bufferView);
|
|
316
|
-
}
|
|
317
|
-
// Create TypedArray for the accessor
|
|
318
|
-
// Note: The canonical way to instantiate is to ignore this array and create
|
|
319
|
-
// WebGLBuffer's using the bufferViews.
|
|
320
|
-
if (accessor.bufferView) {
|
|
321
|
-
const buffer = accessor.bufferView.buffer;
|
|
322
|
-
const { ArrayType, byteLength } = (0, gltf_utils_1.getAccessorArrayTypeAndLength)(accessor, accessor.bufferView);
|
|
323
|
-
const byteOffset = (accessor.bufferView.byteOffset || 0) + (accessor.byteOffset || 0) + buffer.byteOffset;
|
|
324
|
-
let cutBuffer = buffer.arrayBuffer.slice(byteOffset, byteOffset + byteLength);
|
|
325
|
-
if (accessor.bufferView.byteStride) {
|
|
326
|
-
cutBuffer = this._getValueFromInterleavedBuffer(buffer, byteOffset, accessor.bufferView.byteStride, accessor.bytesPerElement, accessor.count);
|
|
327
|
-
}
|
|
328
|
-
accessor.value = new ArrayType(cutBuffer);
|
|
329
|
-
}
|
|
330
|
-
return accessor;
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Take values of particular accessor from interleaved buffer
|
|
334
|
-
* various parts of the buffer
|
|
335
|
-
* @param buffer
|
|
336
|
-
* @param byteOffset
|
|
337
|
-
* @param byteStride
|
|
338
|
-
* @param bytesPerElement
|
|
339
|
-
* @param count
|
|
340
|
-
* @returns
|
|
341
|
-
*/
|
|
342
|
-
_getValueFromInterleavedBuffer(buffer, byteOffset, byteStride, bytesPerElement, count) {
|
|
343
|
-
const result = new Uint8Array(count * bytesPerElement);
|
|
344
|
-
for (let i = 0; i < count; i++) {
|
|
345
|
-
const elementOffset = byteOffset + i * byteStride;
|
|
346
|
-
result.set(new Uint8Array(buffer.arrayBuffer.slice(elementOffset, elementOffset + bytesPerElement)), i * bytesPerElement);
|
|
347
|
-
}
|
|
348
|
-
return result.buffer;
|
|
349
|
-
}
|
|
350
|
-
_resolveTexture(gltfTexture, index) {
|
|
351
|
-
return {
|
|
352
|
-
...gltfTexture,
|
|
353
|
-
// @ts-expect-error id could already be present, glTF standard does not prevent it
|
|
354
|
-
id: gltfTexture.id || `texture-${index}`,
|
|
355
|
-
sampler: typeof gltfTexture.sampler === 'number'
|
|
356
|
-
? this.getSampler(gltfTexture.sampler)
|
|
357
|
-
: makeDefaultSampler(),
|
|
358
|
-
source: typeof gltfTexture.source === 'number' ? this.getImage(gltfTexture.source) : undefined
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
|
-
_resolveSampler(gltfSampler, index) {
|
|
362
|
-
const sampler = {
|
|
363
|
-
// @ts-expect-error id could already be present, glTF standard does not prevent it
|
|
364
|
-
id: gltfSampler.id || `sampler-${index}`,
|
|
365
|
-
...gltfSampler,
|
|
366
|
-
parameters: {}
|
|
367
|
-
};
|
|
368
|
-
// Map textual parameters to GL parameter values
|
|
369
|
-
for (const key in sampler) {
|
|
370
|
-
const glEnum = this._enumSamplerParameter(key);
|
|
371
|
-
if (glEnum !== undefined) {
|
|
372
|
-
sampler.parameters[glEnum] = sampler[key];
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
return sampler;
|
|
376
|
-
}
|
|
377
|
-
_enumSamplerParameter(key) {
|
|
378
|
-
return SAMPLER_PARAMETER_GLTF_TO_GL[key];
|
|
379
|
-
}
|
|
380
|
-
_resolveImage(gltfImage, index) {
|
|
381
|
-
const image = {
|
|
382
|
-
...gltfImage,
|
|
383
|
-
// @ts-expect-error id could already be present, glTF standard does not prevent it
|
|
384
|
-
id: gltfImage.id || `image-${index}`,
|
|
385
|
-
image: null,
|
|
386
|
-
bufferView: gltfImage.bufferView !== undefined ? this.getBufferView(gltfImage.bufferView) : undefined
|
|
387
|
-
};
|
|
388
|
-
// Check if image has been preloaded by the GLTFLoader
|
|
389
|
-
// If so, link it into the JSON and drop the URI
|
|
390
|
-
const preloadedImage = this.images[index];
|
|
391
|
-
if (preloadedImage) {
|
|
392
|
-
image.image = preloadedImage;
|
|
393
|
-
}
|
|
394
|
-
return image;
|
|
395
|
-
}
|
|
396
|
-
_resolveBufferView(gltfBufferView, index) {
|
|
397
|
-
const bufferIndex = gltfBufferView.buffer;
|
|
398
|
-
const arrayBuffer = this.buffers[bufferIndex].arrayBuffer;
|
|
399
|
-
// Add offset of buffer, then offset of buffer view
|
|
400
|
-
let byteOffset = this.buffers[bufferIndex].byteOffset || 0;
|
|
401
|
-
if (gltfBufferView.byteOffset) {
|
|
402
|
-
byteOffset += gltfBufferView.byteOffset;
|
|
403
|
-
}
|
|
404
|
-
const bufferView = {
|
|
405
|
-
// // @ts-expect-error id could already be present, glTF standard does not prevent it
|
|
406
|
-
id: `bufferView-${index}`,
|
|
407
|
-
...gltfBufferView,
|
|
408
|
-
// ...this.buffers[bufferIndex],
|
|
409
|
-
buffer: this.buffers[bufferIndex],
|
|
410
|
-
data: new Uint8Array(arrayBuffer, byteOffset, gltfBufferView.byteLength)
|
|
411
|
-
};
|
|
412
|
-
return bufferView;
|
|
413
|
-
}
|
|
414
|
-
_resolveCamera(gltfCamera, index) {
|
|
415
|
-
const camera = {
|
|
416
|
-
...gltfCamera,
|
|
417
|
-
// @ts-expect-error id could already be present, glTF standard does not prevent it
|
|
418
|
-
id: gltfCamera.id || `camera-${index}`
|
|
419
|
-
};
|
|
420
|
-
// TODO - create 4x4 matrices
|
|
421
|
-
if (camera.perspective) {
|
|
422
|
-
// camera.matrix = createPerspectiveMatrix(camera.perspective);
|
|
423
|
-
}
|
|
424
|
-
if (camera.orthographic) {
|
|
425
|
-
// camera.matrix = createOrthographicMatrix(camera.orthographic);
|
|
426
|
-
}
|
|
427
|
-
return camera;
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
function postProcessGLTF(gltf, options) {
|
|
431
|
-
return new GLTFPostProcessor().postProcess(gltf, options);
|
|
432
|
-
}
|
|
433
|
-
exports.postProcessGLTF = postProcessGLTF;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.encodeGLBSync = void 0;
|
|
4
|
-
/* eslint-disable camelcase, max-statements */
|
|
5
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
6
|
-
// import type {GLB} from '../types/glb-types';
|
|
7
|
-
const MAGIC_glTF = 0x46546c67; // glTF in ASCII
|
|
8
|
-
const MAGIC_JSON = 0x4e4f534a; // JSON in ASCII
|
|
9
|
-
const MAGIC_BIN = 0x004e4942; // BIN\0 in ASCII
|
|
10
|
-
const LE = true; // Binary GLTF is little endian.
|
|
11
|
-
/**
|
|
12
|
-
* Encode the full GLB buffer with header etc
|
|
13
|
-
*
|
|
14
|
-
* @param glb
|
|
15
|
-
* @param dataView - if `null`, does not encode but just calculates length
|
|
16
|
-
* @param byteOffset
|
|
17
|
-
* @param options
|
|
18
|
-
* @returns
|
|
19
|
-
*
|
|
20
|
-
* @see https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#glb-file-format-specification
|
|
21
|
-
* @todo type GLB argument
|
|
22
|
-
*/
|
|
23
|
-
function encodeGLBSync(glb, dataView, byteOffset = 0, options = {}) {
|
|
24
|
-
const { magic = MAGIC_glTF, version = 2, json = {}, binary } = glb;
|
|
25
|
-
const byteOffsetStart = byteOffset;
|
|
26
|
-
// Write GLB Header
|
|
27
|
-
if (dataView) {
|
|
28
|
-
dataView.setUint32(byteOffset + 0, magic, LE); // Magic number (the ASCII string 'glTF').
|
|
29
|
-
dataView.setUint32(byteOffset + 4, version, LE); // Version 2 of binary glTF container format uint32
|
|
30
|
-
dataView.setUint32(byteOffset + 8, 0, LE); // Total byte length of generated file (uint32), will be set last
|
|
31
|
-
}
|
|
32
|
-
const byteOffsetFileLength = byteOffset + 8;
|
|
33
|
-
byteOffset += 12; // GLB_FILE_HEADER_SIZE
|
|
34
|
-
// Write the JSON chunk header
|
|
35
|
-
const byteOffsetJsonHeader = byteOffset;
|
|
36
|
-
if (dataView) {
|
|
37
|
-
dataView.setUint32(byteOffset + 0, 0, LE); // Byte length of json chunk (will be written later)
|
|
38
|
-
dataView.setUint32(byteOffset + 4, MAGIC_JSON, LE); // Chunk type
|
|
39
|
-
}
|
|
40
|
-
byteOffset += 8; // GLB_CHUNK_HEADER_SIZE
|
|
41
|
-
// Write the JSON chunk
|
|
42
|
-
const jsonString = JSON.stringify(json);
|
|
43
|
-
byteOffset = (0, loader_utils_1.copyPaddedStringToDataView)(dataView, byteOffset, jsonString, 4);
|
|
44
|
-
// Now we know the JSON chunk length so we can write it.
|
|
45
|
-
if (dataView) {
|
|
46
|
-
const jsonByteLength = byteOffset - byteOffsetJsonHeader - 8; // GLB_CHUNK_HEADER_SIZE
|
|
47
|
-
dataView.setUint32(byteOffsetJsonHeader + 0, jsonByteLength, LE); // Byte length of json chunk (uint32)
|
|
48
|
-
}
|
|
49
|
-
// Write the BIN chunk if present. The BIN chunk is optional.
|
|
50
|
-
if (binary) {
|
|
51
|
-
const byteOffsetBinHeader = byteOffset;
|
|
52
|
-
// Write the BIN chunk header
|
|
53
|
-
if (dataView) {
|
|
54
|
-
dataView.setUint32(byteOffset + 0, 0, LE); // Byte length BIN (uint32)
|
|
55
|
-
dataView.setUint32(byteOffset + 4, MAGIC_BIN, LE); // Chunk type
|
|
56
|
-
}
|
|
57
|
-
byteOffset += 8; // GLB_CHUNK_HEADER_SIZE
|
|
58
|
-
byteOffset = (0, loader_utils_1.copyPaddedArrayBufferToDataView)(dataView, byteOffset, binary, 4);
|
|
59
|
-
// Now we know the BIN chunk length so we can write it.
|
|
60
|
-
if (dataView) {
|
|
61
|
-
const binByteLength = byteOffset - byteOffsetBinHeader - 8; // GLB_CHUNK_HEADER_SIZE
|
|
62
|
-
dataView.setUint32(byteOffsetBinHeader + 0, binByteLength, LE); // Byte length BIN (uint32)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
// Now we know the glb file length so we can write it.
|
|
66
|
-
if (dataView) {
|
|
67
|
-
const fileByteLength = byteOffset - byteOffsetStart;
|
|
68
|
-
dataView.setUint32(byteOffsetFileLength, fileByteLength, LE); // Total byte length of generated file (uint32)
|
|
69
|
-
}
|
|
70
|
-
return byteOffset;
|
|
71
|
-
}
|
|
72
|
-
exports.encodeGLBSync = encodeGLBSync;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.encodeGLTFSync = void 0;
|
|
4
|
-
const encode_glb_1 = require("./encode-glb");
|
|
5
|
-
/**
|
|
6
|
-
* Encode the full glTF file as a binary GLB file
|
|
7
|
-
* Returns an ArrayBuffer that represents the complete GLB image that can be saved to file
|
|
8
|
-
*
|
|
9
|
-
* @todo - Does not support encoding to non-GLB versions of glTF format. Other formats
|
|
10
|
-
* - Encode as a textual JSON file with binary data in base64 data URLs.
|
|
11
|
-
* - Encode as a JSON with all images (and buffers?) in separate binary files
|
|
12
|
-
*
|
|
13
|
-
* glb-file-format-specification
|
|
14
|
-
* @see https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#
|
|
15
|
-
*
|
|
16
|
-
* @param gltf
|
|
17
|
-
* @param arrayBuffer
|
|
18
|
-
* @param byteOffset
|
|
19
|
-
* @param options
|
|
20
|
-
* @returns
|
|
21
|
-
*/
|
|
22
|
-
function encodeGLTFSync(gltf, arrayBuffer, byteOffset, options) {
|
|
23
|
-
convertBuffersToBase64(gltf);
|
|
24
|
-
// TODO: Copy buffers to binary
|
|
25
|
-
return (0, encode_glb_1.encodeGLBSync)(gltf, arrayBuffer, byteOffset, options);
|
|
26
|
-
}
|
|
27
|
-
exports.encodeGLTFSync = encodeGLTFSync;
|
|
28
|
-
function convertBuffersToBase64(gltf, { firstBuffer = 0 } = {}) {
|
|
29
|
-
if (gltf.buffers && gltf.buffers.length > firstBuffer) {
|
|
30
|
-
throw new Error('encodeGLTF: multiple buffers not yet implemented');
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.decode = exports.name = void 0;
|
|
4
|
-
const gltf_scenegraph_1 = require("../api/gltf-scenegraph");
|
|
5
|
-
const data_processing_1 = require("./data-processing");
|
|
6
|
-
const EXT_structural_metadata_1 = require("./EXT_structural_metadata");
|
|
7
|
-
const EXT_MESH_FEATURES_NAME = 'EXT_mesh_features';
|
|
8
|
-
exports.name = EXT_MESH_FEATURES_NAME;
|
|
9
|
-
async function decode(gltfData, options) {
|
|
10
|
-
const scenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
|
|
11
|
-
decodeExtMeshFeatures(scenegraph, options);
|
|
12
|
-
}
|
|
13
|
-
exports.decode = decode;
|
|
14
|
-
/**
|
|
15
|
-
* Decodes feature metadata from extension
|
|
16
|
-
* @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.
|
|
17
|
-
* @param {GLTFLoaderOptions} options - loader options.
|
|
18
|
-
*/
|
|
19
|
-
function decodeExtMeshFeatures(scenegraph, options) {
|
|
20
|
-
const json = scenegraph.gltf.json;
|
|
21
|
-
if (!json.meshes) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
// Iterate through all meshes/primitives.
|
|
25
|
-
for (const mesh of json.meshes) {
|
|
26
|
-
for (const primitive of mesh.primitives) {
|
|
27
|
-
processMeshPrimitiveFeatures(scenegraph, primitive, options);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Takes data from EXT_mesh_features and store it in 'data' property of featureIds.
|
|
33
|
-
* If combined with EXT_structural_metadata, corresponding data are taken from the property tables of that extension.
|
|
34
|
-
* @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.
|
|
35
|
-
* @param {GLTFMeshPrimitive} primitive - primitive that contains extensions.
|
|
36
|
-
* @param {GLTFLoaderOptions} options - loader options.
|
|
37
|
-
*/
|
|
38
|
-
function processMeshPrimitiveFeatures(scenegraph, primitive, options) {
|
|
39
|
-
const extension = primitive.extensions?.[EXT_MESH_FEATURES_NAME];
|
|
40
|
-
const featureIds = extension?.featureIds;
|
|
41
|
-
if (!featureIds)
|
|
42
|
-
return;
|
|
43
|
-
if (!extension.dataAttributeNames) {
|
|
44
|
-
extension.dataAttributeNames = [];
|
|
45
|
-
}
|
|
46
|
-
let featureIdCount = 0; // It can be used to name the feature if neither label nor property table name is provided.
|
|
47
|
-
for (const featureId of featureIds) {
|
|
48
|
-
/*
|
|
49
|
-
When combined with the EXT_structural_metadata extension, feature ID sets can be associated with property tables.
|
|
50
|
-
A property table maps each feature ID to a set of values that are associated with the respective feature.
|
|
51
|
-
The feature ID in this case serves as an index for the row of the table.
|
|
52
|
-
The index of the property table that a certain set of feature IDs is associated with is stored in the propertyTable of the feature ID set definition.
|
|
53
|
-
*/
|
|
54
|
-
let propertyTable = null;
|
|
55
|
-
if (typeof featureId.propertyTable === 'number') {
|
|
56
|
-
propertyTable = (0, EXT_structural_metadata_1.getPropertyTablePopulated)(scenegraph, featureId.propertyTable);
|
|
57
|
-
}
|
|
58
|
-
let propertyData = null;
|
|
59
|
-
// Process "Feature ID by Vertex"
|
|
60
|
-
if (typeof featureId.attribute !== 'undefined') {
|
|
61
|
-
const accessorKey = `_FEATURE_ID_${featureId.attribute}`;
|
|
62
|
-
const accessorIndex = primitive.attributes[accessorKey];
|
|
63
|
-
const propertyDataTypedArray = scenegraph.getTypedArrayForAccessor(accessorIndex);
|
|
64
|
-
propertyData = Array.prototype.slice.call(propertyDataTypedArray);
|
|
65
|
-
}
|
|
66
|
-
// Process "Feature ID by Texture Coordinates"
|
|
67
|
-
else if (typeof featureId.texture !== 'undefined' && options?.gltf?.loadImages) {
|
|
68
|
-
propertyData = (0, data_processing_1.getPrimitiveTextureData)(scenegraph, featureId.texture, primitive);
|
|
69
|
-
}
|
|
70
|
-
// Process "Feature ID by Index"
|
|
71
|
-
else {
|
|
72
|
-
/*
|
|
73
|
-
When both featureId.attribute and featureId.texture are undefined,
|
|
74
|
-
then the feature ID value for each vertex is given implicitly, via the index of the vertex.
|
|
75
|
-
In this case, the featureCount must match the number of vertices of the mesh primitive.
|
|
76
|
-
*/
|
|
77
|
-
// TODO: At the moment of writing we don't have a tileset with the data of that kind. Implement it later.
|
|
78
|
-
}
|
|
79
|
-
const attributeName = featureId.label || propertyTable?.name || `featureAttribute${featureIdCount}`;
|
|
80
|
-
// featureTable - an array where unique data from the property data are being stored
|
|
81
|
-
const featureTable = [];
|
|
82
|
-
if (propertyData) {
|
|
83
|
-
(0, data_processing_1.primitivePropertyDataToAttributes)(scenegraph, attributeName, propertyData, featureTable, primitive);
|
|
84
|
-
}
|
|
85
|
-
extension.dataAttributeNames.push(attributeName);
|
|
86
|
-
featureId.data = featureTable;
|
|
87
|
-
featureIdCount++;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.decode = exports.name = void 0;
|
|
4
|
-
const gltf_scenegraph_1 = require("../api/gltf-scenegraph");
|
|
5
|
-
const meshopt_decoder_1 = require("../../meshopt/meshopt-decoder");
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
// eslint-disable-next-line
|
|
8
|
-
const DEFAULT_MESHOPT_OPTIONS = {
|
|
9
|
-
byteOffset: 0,
|
|
10
|
-
filter: 'NONE'
|
|
11
|
-
};
|
|
12
|
-
/** Extension name */
|
|
13
|
-
const EXT_MESHOPT_COMPRESSION = 'EXT_meshopt_compression';
|
|
14
|
-
exports.name = EXT_MESHOPT_COMPRESSION;
|
|
15
|
-
async function decode(gltfData, options) {
|
|
16
|
-
const scenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
|
|
17
|
-
if (!options?.gltf?.decompressMeshes || !options.gltf?.loadBuffers) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const promises = [];
|
|
21
|
-
for (const bufferViewIndex of gltfData.json.bufferViews || []) {
|
|
22
|
-
promises.push(decodeMeshoptBufferView(scenegraph, bufferViewIndex));
|
|
23
|
-
}
|
|
24
|
-
// Decompress meshes in parallel
|
|
25
|
-
await Promise.all(promises);
|
|
26
|
-
// We have now decompressed all primitives, so remove the top-level extension
|
|
27
|
-
scenegraph.removeExtension(EXT_MESHOPT_COMPRESSION);
|
|
28
|
-
}
|
|
29
|
-
exports.decode = decode;
|
|
30
|
-
/** Decode one meshopt buffer view */
|
|
31
|
-
async function decodeMeshoptBufferView(scenegraph, bufferView) {
|
|
32
|
-
const meshoptExtension = scenegraph.getObjectExtension(bufferView, EXT_MESHOPT_COMPRESSION);
|
|
33
|
-
if (meshoptExtension) {
|
|
34
|
-
const { byteOffset = 0, byteLength = 0, byteStride, count, mode, filter = 'NONE', buffer: bufferIndex } = meshoptExtension;
|
|
35
|
-
const buffer = scenegraph.gltf.buffers[bufferIndex];
|
|
36
|
-
const source = new Uint8Array(buffer.arrayBuffer, buffer.byteOffset + byteOffset, byteLength);
|
|
37
|
-
const result = new Uint8Array(scenegraph.gltf.buffers[bufferView.buffer].arrayBuffer, bufferView.byteOffset, bufferView.byteLength);
|
|
38
|
-
await (0, meshopt_decoder_1.meshoptDecodeGltfBuffer)(result, count, byteStride, source, mode, filter);
|
|
39
|
-
scenegraph.removeObjectExtension(bufferView, EXT_MESHOPT_COMPRESSION);
|
|
40
|
-
}
|
|
41
|
-
}
|