@loaders.gl/gltf 3.1.0-alpha.4 → 3.1.0-alpha.5

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