@loaders.gl/gltf 4.0.0-alpha.9 → 4.0.0-beta.2
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 +3777 -3105
- package/dist/es5/glb-loader.js +1 -3
- package/dist/es5/glb-loader.js.map +1 -1
- package/dist/es5/index.js +33 -0
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/api/gltf-extensions.js +3 -1
- package/dist/es5/lib/api/gltf-extensions.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_mesh_features.js +99 -0
- package/dist/es5/lib/extensions/EXT_mesh_features.js.map +1 -0
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js +2 -2
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_structural_metadata.js +375 -0
- package/dist/es5/lib/extensions/EXT_structural_metadata.js.map +1 -0
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +6 -7
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_texture_transform.js +2 -1
- package/dist/es5/lib/extensions/KHR_texture_transform.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +162 -183
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
- package/dist/es5/lib/extensions/utils/3d-tiles-utils.js +254 -0
- 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/parsers/parse-gltf.js +7 -4
- package/dist/es5/lib/parsers/parse-gltf.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 +2 -0
- package/dist/es5/lib/types/gltf-ext-mesh-features-schema.js.map +1 -0
- package/dist/es5/lib/types/gltf-ext-structural-metadata-schema.js +2 -0
- package/dist/es5/lib/types/gltf-ext-structural-metadata-schema.js.map +1 -0
- 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/es5/lib/utils/version.js.map +1 -1
- package/dist/esm/glb-loader.js +0 -1
- package/dist/esm/glb-loader.js.map +1 -1
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/api/gltf-extensions.js +3 -1
- package/dist/esm/lib/api/gltf-extensions.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_mesh_features.js +43 -0
- package/dist/esm/lib/extensions/EXT_mesh_features.js.map +1 -0
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js +2 -2
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_structural_metadata.js +302 -0
- package/dist/esm/lib/extensions/EXT_structural_metadata.js.map +1 -0
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js +2 -5
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_texture_transform.js +2 -1
- package/dist/esm/lib/extensions/KHR_texture_transform.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js +156 -167
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
- package/dist/esm/lib/extensions/utils/3d-tiles-utils.js +215 -0
- 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/parsers/parse-gltf.js +6 -6
- package/dist/esm/lib/parsers/parse-gltf.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 +2 -0
- package/dist/esm/lib/types/gltf-ext-mesh-features-schema.js.map +1 -0
- package/dist/esm/lib/types/gltf-ext-structural-metadata-schema.js +2 -0
- package/dist/esm/lib/types/gltf-ext-structural-metadata-schema.js.map +1 -0
- 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/esm/lib/utils/version.js.map +1 -1
- package/dist/glb-loader.d.ts +3 -1
- package/dist/glb-loader.d.ts.map +1 -1
- package/dist/index.d.ts +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_mesh_features.d.ts +7 -0
- package/dist/lib/extensions/EXT_mesh_features.d.ts.map +1 -0
- package/dist/lib/extensions/EXT_structural_metadata.d.ts +16 -0
- package/dist/lib/extensions/EXT_structural_metadata.d.ts.map +1 -0
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +1 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.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 +82 -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/parsers/parse-gltf.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 +43 -0
- package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts.map +1 -0
- package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts +329 -0
- package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts.map +1 -0
- package/dist/lib/types/gltf-json-schema.d.ts +12 -404
- package/dist/lib/types/gltf-json-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-types.d.ts +4 -1
- package/dist/lib/types/gltf-types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/glb-loader.ts +3 -3
- package/src/index.ts +37 -6
- package/src/lib/api/gltf-extensions.ts +6 -2
- package/src/lib/extensions/EXT_mesh_features.ts +91 -0
- package/src/lib/extensions/EXT_meshopt_compression.ts +1 -1
- package/src/lib/extensions/EXT_structural_metadata.ts +750 -0
- package/src/lib/extensions/KHR_draco_mesh_compression.ts +7 -7
- package/src/lib/extensions/KHR_texture_transform.ts +1 -1
- package/src/lib/extensions/deprecated/EXT_feature_metadata.ts +407 -281
- package/src/lib/extensions/utils/3d-tiles-utils.ts +430 -0
- package/src/lib/gltf-utils/gltf-utils.ts +38 -0
- package/src/lib/parsers/parse-gltf.ts +14 -6
- package/src/lib/types/gltf-ext-feature-metadata-schema.ts +470 -0
- package/src/lib/types/gltf-ext-mesh-features-schema.ts +46 -0
- package/src/lib/types/gltf-ext-structural-metadata-schema.ts +378 -0
- package/src/lib/types/gltf-json-schema.ts +26 -465
- package/src/lib/types/gltf-types.ts +5 -3
- package/dist/bundle.js +0 -5
- package/dist/glb-loader.js +0 -36
- 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 -28
- package/dist/lib/api/gltf-extensions.js +0 -83
- 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_meshopt_compression.js +0 -41
- 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 -138
- package/dist/lib/extensions/KHR_texture_basisu.js +0 -29
- package/dist/lib/extensions/KHR_texture_transform.js +0 -227
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +0 -290
- 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 -179
- package/dist/lib/types/glb-types.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,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) {
|
|
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
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// GLTF EXTENSION: EXT_TEXTURE_WEBP
|
|
3
|
-
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/EXT_TEXTURE_WEBP
|
|
4
|
-
/* eslint-disable camelcase */
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.preprocess = exports.name = void 0;
|
|
7
|
-
const images_1 = require("@loaders.gl/images");
|
|
8
|
-
const gltf_scenegraph_1 = require("../api/gltf-scenegraph");
|
|
9
|
-
const EXT_TEXTURE_WEBP = 'EXT_texture_webp';
|
|
10
|
-
/** Extension name */
|
|
11
|
-
exports.name = EXT_TEXTURE_WEBP;
|
|
12
|
-
/**
|
|
13
|
-
* Replaces a texture source reference with the extension texture
|
|
14
|
-
* Done in preprocess() to prevent load of default image
|
|
15
|
-
*/
|
|
16
|
-
function preprocess(gltfData, options) {
|
|
17
|
-
const scenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
|
|
18
|
-
if (!(0, images_1.isImageFormatSupported)('image/webp')) {
|
|
19
|
-
if (scenegraph.getRequiredExtensions().includes(EXT_TEXTURE_WEBP)) {
|
|
20
|
-
throw new Error(`gltf: Required extension ${EXT_TEXTURE_WEBP} not supported by browser`);
|
|
21
|
-
}
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const { json } = scenegraph;
|
|
25
|
-
for (const texture of json.textures || []) {
|
|
26
|
-
const extension = scenegraph.getObjectExtension(texture, EXT_TEXTURE_WEBP);
|
|
27
|
-
if (extension) {
|
|
28
|
-
// TODO - if multiple texture extensions are present which one wins?
|
|
29
|
-
texture.source = extension.source;
|
|
30
|
-
}
|
|
31
|
-
scenegraph.removeObjectExtension(texture, EXT_TEXTURE_WEBP);
|
|
32
|
-
}
|
|
33
|
-
// Remove the top-level extension
|
|
34
|
-
scenegraph.removeExtension(EXT_TEXTURE_WEBP);
|
|
35
|
-
}
|
|
36
|
-
exports.preprocess = preprocess;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// GLTF 1.0 EXTENSION: KHR_binary_glTF
|
|
3
|
-
// https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF
|
|
4
|
-
/* eslint-disable camelcase */
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.preprocess = exports.name = void 0;
|
|
7
|
-
const gltf_scenegraph_1 = require("../api/gltf-scenegraph");
|
|
8
|
-
const KHR_BINARY_GLTF = 'KHR_binary_glTF';
|
|
9
|
-
/** Extension name */
|
|
10
|
-
exports.name = KHR_BINARY_GLTF;
|
|
11
|
-
function preprocess(gltfData) {
|
|
12
|
-
const gltfScenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
|
|
13
|
-
const { json } = gltfScenegraph;
|
|
14
|
-
// Note: json.buffers.binary_glTF also needs to be replaced
|
|
15
|
-
// This is currently done during gltf normalization
|
|
16
|
-
// Image and shader nodes can have the extension
|
|
17
|
-
// https://github.com/KhronosGroup/glTF/blob/master/extensions/1.0/Khronos/KHR_binary_glTF/schema/image.KHR_binary_glTF.schema.json
|
|
18
|
-
for (const image of json.images || []) {
|
|
19
|
-
const extension = gltfScenegraph.getObjectExtension(image, KHR_BINARY_GLTF);
|
|
20
|
-
// The data in the extension is valid as glTF 2.0 data inside the object, so just copy it in
|
|
21
|
-
if (extension) {
|
|
22
|
-
Object.assign(image, extension);
|
|
23
|
-
}
|
|
24
|
-
gltfScenegraph.removeObjectExtension(image, KHR_BINARY_GLTF);
|
|
25
|
-
}
|
|
26
|
-
// TODO shaders - At least traverse and throw error if used?
|
|
27
|
-
// https://github.com/KhronosGroup/glTF/blob/master/extensions/1.0/Khronos/KHR_binary_glTF/schema/shader.KHR_binary_glTF.schema.json
|
|
28
|
-
// glTF v1 one files have a partially formed URI field that is not expected in (and causes problems in) 2.0
|
|
29
|
-
if (json.buffers && json.buffers[0]) {
|
|
30
|
-
delete json.buffers[0].uri;
|
|
31
|
-
}
|
|
32
|
-
// Remove the top-level extension as it has now been processed
|
|
33
|
-
gltfScenegraph.removeExtension(KHR_BINARY_GLTF);
|
|
34
|
-
}
|
|
35
|
-
exports.preprocess = preprocess;
|
|
36
|
-
// KHR_binary_gltf is a 1.0 extension that is supported natively by 2.0
|
|
37
|
-
// export function encode() {
|
|
38
|
-
// throw new Error(KHR_BINARY_GLTF);
|
|
39
|
-
// }
|