@loaders.gl/gltf 3.0.13 → 3.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.es5.min.js +1 -1
- package/dist/dist.es5.min.js.map +1 -1
- package/dist/dist.min.js +1 -1
- package/dist/dist.min.js.map +1 -1
- package/dist/es5/bundle.js +2 -2
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/glb-loader.js +33 -10
- package/dist/es5/glb-loader.js.map +1 -1
- package/dist/es5/glb-writer.js +8 -9
- package/dist/es5/glb-writer.js.map +1 -1
- package/dist/es5/gltf-loader.js +52 -14
- package/dist/es5/gltf-loader.js.map +1 -1
- package/dist/es5/gltf-writer.js +10 -10
- package/dist/es5/gltf-writer.js.map +1 -1
- package/dist/es5/index.js +7 -7
- package/dist/es5/lib/api/gltf-scenegraph.js +541 -447
- package/dist/es5/lib/api/gltf-scenegraph.js.map +1 -1
- package/dist/es5/lib/api/normalize-gltf-v1.js +280 -150
- package/dist/es5/lib/api/normalize-gltf-v1.js.map +1 -1
- package/dist/es5/lib/api/post-process-gltf.js +354 -279
- package/dist/es5/lib/api/post-process-gltf.js.map +1 -1
- package/dist/es5/lib/encoders/encode-glb.js +22 -19
- package/dist/es5/lib/encoders/encode-glb.js.map +1 -1
- package/dist/es5/lib/encoders/encode-gltf.js +5 -3
- package/dist/es5/lib/encoders/encode-gltf.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js +99 -34
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_binary_gltf.js +22 -8
- package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +244 -70
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_lights_punctual.js +102 -38
- package/dist/es5/lib/extensions/KHR_lights_punctual.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_materials_unlit.js +67 -22
- package/dist/es5/lib/extensions/KHR_materials_unlit.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_techniques_webgl.js +88 -32
- package/dist/es5/lib/extensions/KHR_techniques_webgl.js.map +1 -1
- package/dist/es5/lib/extensions/gltf-extensions.js +67 -17
- package/dist/es5/lib/extensions/gltf-extensions.js.map +1 -1
- package/dist/es5/lib/gltf-utils/get-typed-array.js +6 -6
- package/dist/es5/lib/gltf-utils/get-typed-array.js.map +1 -1
- package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js +21 -19
- package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js.map +1 -1
- package/dist/es5/lib/gltf-utils/gltf-constants.js +13 -13
- package/dist/es5/lib/gltf-utils/gltf-constants.js.map +1 -1
- package/dist/es5/lib/gltf-utils/gltf-utils.js +16 -16
- package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -1
- package/dist/es5/lib/gltf-utils/resolve-url.js +2 -2
- package/dist/es5/lib/gltf-utils/resolve-url.js.map +1 -1
- package/dist/es5/lib/parsers/parse-glb.js +38 -34
- package/dist/es5/lib/parsers/parse-glb.js.map +1 -1
- package/dist/es5/lib/parsers/parse-gltf.js +215 -80
- package/dist/es5/lib/parsers/parse-gltf.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/es5/meshopt/meshopt-decoder.js +197 -46
- package/dist/es5/meshopt/meshopt-decoder.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/package.json +6 -6
|
@@ -1,15 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
8
|
exports.postProcessGLTF = postProcessGLTF;
|
|
7
9
|
|
|
10
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
|
+
|
|
12
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
+
|
|
14
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
+
|
|
16
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
|
+
|
|
8
18
|
var _assert = require("../utils/assert");
|
|
9
19
|
|
|
10
20
|
var _gltfUtils = require("../gltf-utils/gltf-utils");
|
|
11
21
|
|
|
12
|
-
|
|
22
|
+
var _DEFAULT_SAMPLER;
|
|
23
|
+
|
|
24
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
25
|
+
|
|
26
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
27
|
+
|
|
28
|
+
var COMPONENTS = {
|
|
13
29
|
SCALAR: 1,
|
|
14
30
|
VEC2: 2,
|
|
15
31
|
VEC3: 3,
|
|
@@ -18,7 +34,7 @@ const COMPONENTS = {
|
|
|
18
34
|
MAT3: 9,
|
|
19
35
|
MAT4: 16
|
|
20
36
|
};
|
|
21
|
-
|
|
37
|
+
var BYTES = {
|
|
22
38
|
5120: 1,
|
|
23
39
|
5121: 1,
|
|
24
40
|
5122: 2,
|
|
@@ -26,7 +42,7 @@ const BYTES = {
|
|
|
26
42
|
5125: 4,
|
|
27
43
|
5126: 4
|
|
28
44
|
};
|
|
29
|
-
|
|
45
|
+
var GL_SAMPLER = {
|
|
30
46
|
TEXTURE_MAG_FILTER: 0x2800,
|
|
31
47
|
TEXTURE_MIN_FILTER: 0x2801,
|
|
32
48
|
TEXTURE_WRAP_S: 0x2802,
|
|
@@ -35,18 +51,13 @@ const GL_SAMPLER = {
|
|
|
35
51
|
LINEAR: 0x2601,
|
|
36
52
|
NEAREST_MIPMAP_LINEAR: 0x2702
|
|
37
53
|
};
|
|
38
|
-
|
|
54
|
+
var SAMPLER_PARAMETER_GLTF_TO_GL = {
|
|
39
55
|
magFilter: GL_SAMPLER.TEXTURE_MAG_FILTER,
|
|
40
56
|
minFilter: GL_SAMPLER.TEXTURE_MIN_FILTER,
|
|
41
57
|
wrapS: GL_SAMPLER.TEXTURE_WRAP_S,
|
|
42
58
|
wrapT: GL_SAMPLER.TEXTURE_WRAP_T
|
|
43
59
|
};
|
|
44
|
-
|
|
45
|
-
[GL_SAMPLER.TEXTURE_MAG_FILTER]: GL_SAMPLER.LINEAR,
|
|
46
|
-
[GL_SAMPLER.TEXTURE_MIN_FILTER]: GL_SAMPLER.NEAREST_MIPMAP_LINEAR,
|
|
47
|
-
[GL_SAMPLER.TEXTURE_WRAP_S]: GL_SAMPLER.REPEAT,
|
|
48
|
-
[GL_SAMPLER.TEXTURE_WRAP_]: GL_SAMPLER.REPEAT
|
|
49
|
-
};
|
|
60
|
+
var DEFAULT_SAMPLER = (_DEFAULT_SAMPLER = {}, (0, _defineProperty2.default)(_DEFAULT_SAMPLER, GL_SAMPLER.TEXTURE_MAG_FILTER, GL_SAMPLER.LINEAR), (0, _defineProperty2.default)(_DEFAULT_SAMPLER, GL_SAMPLER.TEXTURE_MIN_FILTER, GL_SAMPLER.NEAREST_MIPMAP_LINEAR), (0, _defineProperty2.default)(_DEFAULT_SAMPLER, GL_SAMPLER.TEXTURE_WRAP_S, GL_SAMPLER.REPEAT), (0, _defineProperty2.default)(_DEFAULT_SAMPLER, GL_SAMPLER.TEXTURE_WRAP_, GL_SAMPLER.REPEAT), _DEFAULT_SAMPLER);
|
|
50
61
|
|
|
51
62
|
function getBytesFromComponentType(componentType) {
|
|
52
63
|
return BYTES[componentType];
|
|
@@ -56,344 +67,408 @@ function getSizeFromAccessorType(type) {
|
|
|
56
67
|
return COMPONENTS[type];
|
|
57
68
|
}
|
|
58
69
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
json,
|
|
63
|
-
buffers = [],
|
|
64
|
-
images = [],
|
|
65
|
-
baseUri = ''
|
|
66
|
-
} = gltf;
|
|
67
|
-
(0, _assert.assert)(json);
|
|
68
|
-
this.baseUri = baseUri;
|
|
69
|
-
this.json = json;
|
|
70
|
-
this.buffers = buffers;
|
|
71
|
-
this.images = images;
|
|
72
|
-
|
|
73
|
-
this._resolveTree(this.json, options);
|
|
74
|
-
|
|
75
|
-
return this.json;
|
|
70
|
+
var GLTFPostProcessor = function () {
|
|
71
|
+
function GLTFPostProcessor() {
|
|
72
|
+
(0, _classCallCheck2.default)(this, GLTFPostProcessor);
|
|
76
73
|
}
|
|
77
74
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
75
|
+
(0, _createClass2.default)(GLTFPostProcessor, [{
|
|
76
|
+
key: "postProcess",
|
|
77
|
+
value: function postProcess(gltf) {
|
|
78
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
79
|
+
var json = gltf.json,
|
|
80
|
+
_gltf$buffers = gltf.buffers,
|
|
81
|
+
buffers = _gltf$buffers === void 0 ? [] : _gltf$buffers,
|
|
82
|
+
_gltf$images = gltf.images,
|
|
83
|
+
images = _gltf$images === void 0 ? [] : _gltf$images,
|
|
84
|
+
_gltf$baseUri = gltf.baseUri,
|
|
85
|
+
baseUri = _gltf$baseUri === void 0 ? '' : _gltf$baseUri;
|
|
86
|
+
(0, _assert.assert)(json);
|
|
87
|
+
this.baseUri = baseUri;
|
|
88
|
+
this.json = json;
|
|
89
|
+
this.buffers = buffers;
|
|
90
|
+
this.images = images;
|
|
91
|
+
|
|
92
|
+
this._resolveTree(this.json, options);
|
|
93
|
+
|
|
94
|
+
return this.json;
|
|
89
95
|
}
|
|
96
|
+
}, {
|
|
97
|
+
key: "_resolveTree",
|
|
98
|
+
value: function _resolveTree(json) {
|
|
99
|
+
var _this = this;
|
|
90
100
|
|
|
91
|
-
|
|
92
|
-
json.textures = json.textures.map((texture, i) => this._resolveTexture(texture, i));
|
|
93
|
-
}
|
|
101
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
94
102
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
103
|
+
if (json.bufferViews) {
|
|
104
|
+
json.bufferViews = json.bufferViews.map(function (bufView, i) {
|
|
105
|
+
return _this._resolveBufferView(bufView, i);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
98
108
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
109
|
+
if (json.images) {
|
|
110
|
+
json.images = json.images.map(function (image, i) {
|
|
111
|
+
return _this._resolveImage(image, i);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
102
114
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
115
|
+
if (json.samplers) {
|
|
116
|
+
json.samplers = json.samplers.map(function (sampler, i) {
|
|
117
|
+
return _this._resolveSampler(sampler, i);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
106
120
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
121
|
+
if (json.textures) {
|
|
122
|
+
json.textures = json.textures.map(function (texture, i) {
|
|
123
|
+
return _this._resolveTexture(texture, i);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
110
126
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
127
|
+
if (json.accessors) {
|
|
128
|
+
json.accessors = json.accessors.map(function (accessor, i) {
|
|
129
|
+
return _this._resolveAccessor(accessor, i);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
114
132
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
133
|
+
if (json.materials) {
|
|
134
|
+
json.materials = json.materials.map(function (material, i) {
|
|
135
|
+
return _this._resolveMaterial(material, i);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
118
138
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
139
|
+
if (json.meshes) {
|
|
140
|
+
json.meshes = json.meshes.map(function (mesh, i) {
|
|
141
|
+
return _this._resolveMesh(mesh, i);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
123
144
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
145
|
+
if (json.nodes) {
|
|
146
|
+
json.nodes = json.nodes.map(function (node, i) {
|
|
147
|
+
return _this._resolveNode(node, i);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
127
150
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
151
|
+
if (json.skins) {
|
|
152
|
+
json.skins = json.skins.map(function (skin, i) {
|
|
153
|
+
return _this._resolveSkin(skin, i);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
131
156
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
157
|
+
if (json.scenes) {
|
|
158
|
+
json.scenes = json.scenes.map(function (scene, i) {
|
|
159
|
+
return _this._resolveScene(scene, i);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
135
162
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
163
|
+
if (json.scene !== undefined) {
|
|
164
|
+
json.scene = json.scenes[this.json.scene];
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}, {
|
|
168
|
+
key: "getScene",
|
|
169
|
+
value: function getScene(index) {
|
|
170
|
+
return this._get('scenes', index);
|
|
171
|
+
}
|
|
172
|
+
}, {
|
|
173
|
+
key: "getNode",
|
|
174
|
+
value: function getNode(index) {
|
|
175
|
+
return this._get('nodes', index);
|
|
176
|
+
}
|
|
177
|
+
}, {
|
|
178
|
+
key: "getSkin",
|
|
179
|
+
value: function getSkin(index) {
|
|
180
|
+
return this._get('skins', index);
|
|
181
|
+
}
|
|
182
|
+
}, {
|
|
183
|
+
key: "getMesh",
|
|
184
|
+
value: function getMesh(index) {
|
|
185
|
+
return this._get('meshes', index);
|
|
186
|
+
}
|
|
187
|
+
}, {
|
|
188
|
+
key: "getMaterial",
|
|
189
|
+
value: function getMaterial(index) {
|
|
190
|
+
return this._get('materials', index);
|
|
191
|
+
}
|
|
192
|
+
}, {
|
|
193
|
+
key: "getAccessor",
|
|
194
|
+
value: function getAccessor(index) {
|
|
195
|
+
return this._get('accessors', index);
|
|
196
|
+
}
|
|
197
|
+
}, {
|
|
198
|
+
key: "getCamera",
|
|
199
|
+
value: function getCamera(index) {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
}, {
|
|
203
|
+
key: "getTexture",
|
|
204
|
+
value: function getTexture(index) {
|
|
205
|
+
return this._get('textures', index);
|
|
206
|
+
}
|
|
207
|
+
}, {
|
|
208
|
+
key: "getSampler",
|
|
209
|
+
value: function getSampler(index) {
|
|
210
|
+
return this._get('samplers', index);
|
|
211
|
+
}
|
|
212
|
+
}, {
|
|
213
|
+
key: "getImage",
|
|
214
|
+
value: function getImage(index) {
|
|
215
|
+
return this._get('images', index);
|
|
216
|
+
}
|
|
217
|
+
}, {
|
|
218
|
+
key: "getBufferView",
|
|
219
|
+
value: function getBufferView(index) {
|
|
220
|
+
return this._get('bufferViews', index);
|
|
221
|
+
}
|
|
222
|
+
}, {
|
|
223
|
+
key: "getBuffer",
|
|
224
|
+
value: function getBuffer(index) {
|
|
225
|
+
return this._get('buffers', index);
|
|
226
|
+
}
|
|
227
|
+
}, {
|
|
228
|
+
key: "_get",
|
|
229
|
+
value: function _get(array, index) {
|
|
230
|
+
if ((0, _typeof2.default)(index) === 'object') {
|
|
231
|
+
return index;
|
|
232
|
+
}
|
|
139
233
|
|
|
140
|
-
|
|
141
|
-
return this._get('materials', index);
|
|
142
|
-
}
|
|
234
|
+
var object = this.json[array] && this.json[array][index];
|
|
143
235
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
236
|
+
if (!object) {
|
|
237
|
+
console.warn("glTF file error: Could not find ".concat(array, "[").concat(index, "]"));
|
|
238
|
+
}
|
|
147
239
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
240
|
+
return object;
|
|
241
|
+
}
|
|
242
|
+
}, {
|
|
243
|
+
key: "_resolveScene",
|
|
244
|
+
value: function _resolveScene(scene, index) {
|
|
245
|
+
var _this2 = this;
|
|
246
|
+
|
|
247
|
+
scene.id = scene.id || "scene-".concat(index);
|
|
248
|
+
scene.nodes = (scene.nodes || []).map(function (node) {
|
|
249
|
+
return _this2.getNode(node);
|
|
250
|
+
});
|
|
251
|
+
return scene;
|
|
252
|
+
}
|
|
253
|
+
}, {
|
|
254
|
+
key: "_resolveNode",
|
|
255
|
+
value: function _resolveNode(node, index) {
|
|
256
|
+
var _this3 = this;
|
|
151
257
|
|
|
152
|
-
|
|
153
|
-
return this._get('textures', index);
|
|
154
|
-
}
|
|
258
|
+
node.id = node.id || "node-".concat(index);
|
|
155
259
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
260
|
+
if (node.children) {
|
|
261
|
+
node.children = node.children.map(function (child) {
|
|
262
|
+
return _this3.getNode(child);
|
|
263
|
+
});
|
|
264
|
+
}
|
|
159
265
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
266
|
+
if (node.mesh !== undefined) {
|
|
267
|
+
node.mesh = this.getMesh(node.mesh);
|
|
268
|
+
} else if (node.meshes !== undefined && node.meshes.length) {
|
|
269
|
+
node.mesh = node.meshes.reduce(function (accum, meshIndex) {
|
|
270
|
+
var mesh = _this3.getMesh(meshIndex);
|
|
271
|
+
|
|
272
|
+
accum.id = mesh.id;
|
|
273
|
+
accum.primitives = accum.primitives.concat(mesh.primitives);
|
|
274
|
+
return accum;
|
|
275
|
+
}, {
|
|
276
|
+
primitives: []
|
|
277
|
+
});
|
|
278
|
+
}
|
|
163
279
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
280
|
+
if (node.camera !== undefined) {
|
|
281
|
+
node.camera = this.getCamera(node.camera);
|
|
282
|
+
}
|
|
167
283
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
284
|
+
if (node.skin !== undefined) {
|
|
285
|
+
node.skin = this.getSkin(node.skin);
|
|
286
|
+
}
|
|
171
287
|
|
|
172
|
-
|
|
173
|
-
if (typeof index === 'object') {
|
|
174
|
-
return index;
|
|
288
|
+
return node;
|
|
175
289
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
290
|
+
}, {
|
|
291
|
+
key: "_resolveSkin",
|
|
292
|
+
value: function _resolveSkin(skin, index) {
|
|
293
|
+
skin.id = skin.id || "skin-".concat(index);
|
|
294
|
+
skin.inverseBindMatrices = this.getAccessor(skin.inverseBindMatrices);
|
|
295
|
+
return skin;
|
|
181
296
|
}
|
|
297
|
+
}, {
|
|
298
|
+
key: "_resolveMesh",
|
|
299
|
+
value: function _resolveMesh(mesh, index) {
|
|
300
|
+
var _this4 = this;
|
|
182
301
|
|
|
183
|
-
|
|
184
|
-
}
|
|
302
|
+
mesh.id = mesh.id || "mesh-".concat(index);
|
|
185
303
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
304
|
+
if (mesh.primitives) {
|
|
305
|
+
mesh.primitives = mesh.primitives.map(function (primitive) {
|
|
306
|
+
primitive = _objectSpread({}, primitive);
|
|
307
|
+
var attributes = primitive.attributes;
|
|
308
|
+
primitive.attributes = {};
|
|
191
309
|
|
|
192
|
-
|
|
193
|
-
|
|
310
|
+
for (var attribute in attributes) {
|
|
311
|
+
primitive.attributes[attribute] = _this4.getAccessor(attributes[attribute]);
|
|
312
|
+
}
|
|
194
313
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
314
|
+
if (primitive.indices !== undefined) {
|
|
315
|
+
primitive.indices = _this4.getAccessor(primitive.indices);
|
|
316
|
+
}
|
|
198
317
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
node.mesh = node.meshes.reduce((accum, meshIndex) => {
|
|
203
|
-
const mesh = this.getMesh(meshIndex);
|
|
204
|
-
accum.id = mesh.id;
|
|
205
|
-
accum.primitives = accum.primitives.concat(mesh.primitives);
|
|
206
|
-
return accum;
|
|
207
|
-
}, {
|
|
208
|
-
primitives: []
|
|
209
|
-
});
|
|
210
|
-
}
|
|
318
|
+
if (primitive.material !== undefined) {
|
|
319
|
+
primitive.material = _this4.getMaterial(primitive.material);
|
|
320
|
+
}
|
|
211
321
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
322
|
+
return primitive;
|
|
323
|
+
});
|
|
324
|
+
}
|
|
215
325
|
|
|
216
|
-
|
|
217
|
-
node.skin = this.getSkin(node.skin);
|
|
326
|
+
return mesh;
|
|
218
327
|
}
|
|
328
|
+
}, {
|
|
329
|
+
key: "_resolveMaterial",
|
|
330
|
+
value: function _resolveMaterial(material, index) {
|
|
331
|
+
material.id = material.id || "material-".concat(index);
|
|
332
|
+
|
|
333
|
+
if (material.normalTexture) {
|
|
334
|
+
material.normalTexture = _objectSpread({}, material.normalTexture);
|
|
335
|
+
material.normalTexture.texture = this.getTexture(material.normalTexture.index);
|
|
336
|
+
}
|
|
219
337
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
skin.id = skin.id || "skin-".concat(index);
|
|
225
|
-
skin.inverseBindMatrices = this.getAccessor(skin.inverseBindMatrices);
|
|
226
|
-
return skin;
|
|
227
|
-
}
|
|
338
|
+
if (material.occlusionTexture) {
|
|
339
|
+
material.occlustionTexture = _objectSpread({}, material.occlustionTexture);
|
|
340
|
+
material.occlusionTexture.texture = this.getTexture(material.occlusionTexture.index);
|
|
341
|
+
}
|
|
228
342
|
|
|
229
|
-
|
|
230
|
-
|
|
343
|
+
if (material.emissiveTexture) {
|
|
344
|
+
material.emmisiveTexture = _objectSpread({}, material.emmisiveTexture);
|
|
345
|
+
material.emissiveTexture.texture = this.getTexture(material.emissiveTexture.index);
|
|
346
|
+
}
|
|
231
347
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
};
|
|
236
|
-
const attributes = primitive.attributes;
|
|
237
|
-
primitive.attributes = {};
|
|
348
|
+
if (!material.emissiveFactor) {
|
|
349
|
+
material.emissiveFactor = material.emmisiveTexture ? [1, 1, 1] : [0, 0, 0];
|
|
350
|
+
}
|
|
238
351
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
352
|
+
if (material.pbrMetallicRoughness) {
|
|
353
|
+
material.pbrMetallicRoughness = _objectSpread({}, material.pbrMetallicRoughness);
|
|
354
|
+
var mr = material.pbrMetallicRoughness;
|
|
242
355
|
|
|
243
|
-
if (
|
|
244
|
-
|
|
356
|
+
if (mr.baseColorTexture) {
|
|
357
|
+
mr.baseColorTexture = _objectSpread({}, mr.baseColorTexture);
|
|
358
|
+
mr.baseColorTexture.texture = this.getTexture(mr.baseColorTexture.index);
|
|
245
359
|
}
|
|
246
360
|
|
|
247
|
-
if (
|
|
248
|
-
|
|
361
|
+
if (mr.metallicRoughnessTexture) {
|
|
362
|
+
mr.metallicRoughnessTexture = _objectSpread({}, mr.metallicRoughnessTexture);
|
|
363
|
+
mr.metallicRoughnessTexture.texture = this.getTexture(mr.metallicRoughnessTexture.index);
|
|
249
364
|
}
|
|
365
|
+
}
|
|
250
366
|
|
|
251
|
-
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
return mesh;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
_resolveMaterial(material, index) {
|
|
259
|
-
material.id = material.id || "material-".concat(index);
|
|
260
|
-
|
|
261
|
-
if (material.normalTexture) {
|
|
262
|
-
material.normalTexture = { ...material.normalTexture
|
|
263
|
-
};
|
|
264
|
-
material.normalTexture.texture = this.getTexture(material.normalTexture.index);
|
|
367
|
+
return material;
|
|
265
368
|
}
|
|
369
|
+
}, {
|
|
370
|
+
key: "_resolveAccessor",
|
|
371
|
+
value: function _resolveAccessor(accessor, index) {
|
|
372
|
+
accessor.id = accessor.id || "accessor-".concat(index);
|
|
266
373
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
material.occlusionTexture.texture = this.getTexture(material.occlusionTexture.index);
|
|
271
|
-
}
|
|
374
|
+
if (accessor.bufferView !== undefined) {
|
|
375
|
+
accessor.bufferView = this.getBufferView(accessor.bufferView);
|
|
376
|
+
}
|
|
272
377
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
material.emissiveTexture.texture = this.getTexture(material.emissiveTexture.index);
|
|
277
|
-
}
|
|
378
|
+
accessor.bytesPerComponent = getBytesFromComponentType(accessor.componentType);
|
|
379
|
+
accessor.components = getSizeFromAccessorType(accessor.type);
|
|
380
|
+
accessor.bytesPerElement = accessor.bytesPerComponent * accessor.components;
|
|
278
381
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
382
|
+
if (accessor.bufferView) {
|
|
383
|
+
var buffer = accessor.bufferView.buffer;
|
|
282
384
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
const mr = material.pbrMetallicRoughness;
|
|
385
|
+
var _getAccessorArrayType = (0, _gltfUtils.getAccessorArrayTypeAndLength)(accessor, accessor.bufferView),
|
|
386
|
+
ArrayType = _getAccessorArrayType.ArrayType,
|
|
387
|
+
byteLength = _getAccessorArrayType.byteLength;
|
|
287
388
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
mr.baseColorTexture.texture = this.getTexture(mr.baseColorTexture.index);
|
|
389
|
+
var byteOffset = (accessor.bufferView.byteOffset || 0) + (accessor.byteOffset || 0) + buffer.byteOffset;
|
|
390
|
+
var cutBufffer = buffer.arrayBuffer.slice(byteOffset, byteOffset + byteLength);
|
|
391
|
+
accessor.value = new ArrayType(cutBufffer);
|
|
292
392
|
}
|
|
293
393
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
394
|
+
return accessor;
|
|
395
|
+
}
|
|
396
|
+
}, {
|
|
397
|
+
key: "_resolveTexture",
|
|
398
|
+
value: function _resolveTexture(texture, index) {
|
|
399
|
+
texture.id = texture.id || "texture-".concat(index);
|
|
400
|
+
texture.sampler = 'sampler' in texture ? this.getSampler(texture.sampler) : DEFAULT_SAMPLER;
|
|
401
|
+
texture.source = this.getImage(texture.source);
|
|
402
|
+
return texture;
|
|
299
403
|
}
|
|
404
|
+
}, {
|
|
405
|
+
key: "_resolveSampler",
|
|
406
|
+
value: function _resolveSampler(sampler, index) {
|
|
407
|
+
sampler.id = sampler.id || "sampler-".concat(index);
|
|
408
|
+
sampler.parameters = {};
|
|
300
409
|
|
|
301
|
-
|
|
302
|
-
|
|
410
|
+
for (var key in sampler) {
|
|
411
|
+
var glEnum = this._enumSamplerParameter(key);
|
|
303
412
|
|
|
304
|
-
|
|
305
|
-
|
|
413
|
+
if (glEnum !== undefined) {
|
|
414
|
+
sampler.parameters[glEnum] = sampler[key];
|
|
415
|
+
}
|
|
416
|
+
}
|
|
306
417
|
|
|
307
|
-
|
|
308
|
-
accessor.bufferView = this.getBufferView(accessor.bufferView);
|
|
418
|
+
return sampler;
|
|
309
419
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
if (accessor.bufferView) {
|
|
316
|
-
const buffer = accessor.bufferView.buffer;
|
|
317
|
-
const {
|
|
318
|
-
ArrayType,
|
|
319
|
-
byteLength
|
|
320
|
-
} = (0, _gltfUtils.getAccessorArrayTypeAndLength)(accessor, accessor.bufferView);
|
|
321
|
-
const byteOffset = (accessor.bufferView.byteOffset || 0) + (accessor.byteOffset || 0) + buffer.byteOffset;
|
|
322
|
-
const cutBufffer = buffer.arrayBuffer.slice(byteOffset, byteOffset + byteLength);
|
|
323
|
-
accessor.value = new ArrayType(cutBufffer);
|
|
420
|
+
}, {
|
|
421
|
+
key: "_enumSamplerParameter",
|
|
422
|
+
value: function _enumSamplerParameter(key) {
|
|
423
|
+
return SAMPLER_PARAMETER_GLTF_TO_GL[key];
|
|
324
424
|
}
|
|
425
|
+
}, {
|
|
426
|
+
key: "_resolveImage",
|
|
427
|
+
value: function _resolveImage(image, index) {
|
|
428
|
+
image.id = image.id || "image-".concat(index);
|
|
325
429
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
_resolveTexture(texture, index) {
|
|
330
|
-
texture.id = texture.id || "texture-".concat(index);
|
|
331
|
-
texture.sampler = 'sampler' in texture ? this.getSampler(texture.sampler) : DEFAULT_SAMPLER;
|
|
332
|
-
texture.source = this.getImage(texture.source);
|
|
333
|
-
return texture;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
_resolveSampler(sampler, index) {
|
|
337
|
-
sampler.id = sampler.id || "sampler-".concat(index);
|
|
338
|
-
sampler.parameters = {};
|
|
339
|
-
|
|
340
|
-
for (const key in sampler) {
|
|
341
|
-
const glEnum = this._enumSamplerParameter(key);
|
|
342
|
-
|
|
343
|
-
if (glEnum !== undefined) {
|
|
344
|
-
sampler.parameters[glEnum] = sampler[key];
|
|
430
|
+
if (image.bufferView !== undefined) {
|
|
431
|
+
image.bufferView = this.getBufferView(image.bufferView);
|
|
345
432
|
}
|
|
346
|
-
}
|
|
347
433
|
|
|
348
|
-
|
|
349
|
-
}
|
|
434
|
+
var preloadedImage = this.images[index];
|
|
350
435
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
_resolveImage(image, index) {
|
|
356
|
-
image.id = image.id || "image-".concat(index);
|
|
436
|
+
if (preloadedImage) {
|
|
437
|
+
image.image = preloadedImage;
|
|
438
|
+
}
|
|
357
439
|
|
|
358
|
-
|
|
359
|
-
image.bufferView = this.getBufferView(image.bufferView);
|
|
440
|
+
return image;
|
|
360
441
|
}
|
|
442
|
+
}, {
|
|
443
|
+
key: "_resolveBufferView",
|
|
444
|
+
value: function _resolveBufferView(bufferView, index) {
|
|
445
|
+
bufferView.id = bufferView.id || "bufferView-".concat(index);
|
|
446
|
+
var bufferIndex = bufferView.buffer;
|
|
447
|
+
bufferView.buffer = this.buffers[bufferIndex];
|
|
448
|
+
var arrayBuffer = this.buffers[bufferIndex].arrayBuffer;
|
|
449
|
+
var byteOffset = this.buffers[bufferIndex].byteOffset || 0;
|
|
450
|
+
|
|
451
|
+
if ('byteOffset' in bufferView) {
|
|
452
|
+
byteOffset += bufferView.byteOffset;
|
|
453
|
+
}
|
|
361
454
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
if (preloadedImage) {
|
|
365
|
-
image.image = preloadedImage;
|
|
455
|
+
bufferView.data = new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength);
|
|
456
|
+
return bufferView;
|
|
366
457
|
}
|
|
458
|
+
}, {
|
|
459
|
+
key: "_resolveCamera",
|
|
460
|
+
value: function _resolveCamera(camera, index) {
|
|
461
|
+
camera.id = camera.id || "camera-".concat(index);
|
|
367
462
|
|
|
368
|
-
|
|
369
|
-
}
|
|
463
|
+
if (camera.perspective) {}
|
|
370
464
|
|
|
371
|
-
|
|
372
|
-
bufferView.id = bufferView.id || "bufferView-".concat(index);
|
|
373
|
-
const bufferIndex = bufferView.buffer;
|
|
374
|
-
bufferView.buffer = this.buffers[bufferIndex];
|
|
375
|
-
const arrayBuffer = this.buffers[bufferIndex].arrayBuffer;
|
|
376
|
-
let byteOffset = this.buffers[bufferIndex].byteOffset || 0;
|
|
465
|
+
if (camera.orthographic) {}
|
|
377
466
|
|
|
378
|
-
|
|
379
|
-
byteOffset += bufferView.byteOffset;
|
|
467
|
+
return camera;
|
|
380
468
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
_resolveCamera(camera, index) {
|
|
387
|
-
camera.id = camera.id || "camera-".concat(index);
|
|
388
|
-
|
|
389
|
-
if (camera.perspective) {}
|
|
390
|
-
|
|
391
|
-
if (camera.orthographic) {}
|
|
392
|
-
|
|
393
|
-
return camera;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
}
|
|
469
|
+
}]);
|
|
470
|
+
return GLTFPostProcessor;
|
|
471
|
+
}();
|
|
397
472
|
|
|
398
473
|
function postProcessGLTF(gltf, options) {
|
|
399
474
|
return new GLTFPostProcessor().postProcess(gltf, options);
|