@loaders.gl/gltf 3.1.0-alpha.4 → 3.1.0-beta.3

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 (202) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +4518 -0
  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 +154 -279
  20. package/dist/es5/lib/api/normalize-gltf-v1.js.map +1 -1
  21. package/dist/es5/lib/api/post-process-gltf.js +301 -349
  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/assert.js.map +1 -1
  58. package/dist/es5/lib/utils/version.js +1 -1
  59. package/dist/es5/lib/utils/version.js.map +1 -1
  60. package/dist/es5/meshopt/meshopt-decoder.js +46 -197
  61. package/dist/es5/meshopt/meshopt-decoder.js.map +1 -1
  62. package/dist/es5/webp/webp.js +16 -84
  63. package/dist/es5/webp/webp.js.map +1 -1
  64. package/dist/esm/lib/api/gltf-scenegraph.js +1 -1
  65. package/dist/esm/lib/api/gltf-scenegraph.js.map +1 -1
  66. package/dist/esm/lib/api/normalize-gltf-v1.js +9 -6
  67. package/dist/esm/lib/api/normalize-gltf-v1.js.map +1 -1
  68. package/dist/esm/lib/api/post-process-gltf.js +42 -15
  69. package/dist/esm/lib/api/post-process-gltf.js.map +1 -1
  70. package/dist/esm/lib/encoders/encode-glb.js.map +1 -1
  71. package/dist/esm/lib/encoders/encode-gltf.js.map +1 -1
  72. package/dist/esm/lib/extensions/EXT_meshopt_compression.js +1 -1
  73. package/dist/esm/lib/extensions/EXT_meshopt_compression.js.map +1 -1
  74. package/dist/esm/lib/extensions/EXT_texture_webp.js +1 -1
  75. package/dist/esm/lib/extensions/EXT_texture_webp.js.map +1 -1
  76. package/dist/esm/lib/extensions/KHR_texture_basisu.js.map +1 -1
  77. package/dist/esm/lib/gltf-utils/resolve-url.js +1 -1
  78. package/dist/esm/lib/gltf-utils/resolve-url.js.map +1 -1
  79. package/dist/esm/lib/parsers/parse-glb.js +2 -6
  80. package/dist/esm/lib/parsers/parse-glb.js.map +1 -1
  81. package/dist/esm/lib/parsers/parse-gltf.js +19 -2
  82. package/dist/esm/lib/parsers/parse-gltf.js.map +1 -1
  83. package/dist/esm/lib/utils/assert.js.map +1 -1
  84. package/dist/esm/lib/utils/version.js +1 -1
  85. package/dist/esm/lib/utils/version.js.map +1 -1
  86. package/dist/esm/meshopt/meshopt-decoder.js +1 -1
  87. package/dist/esm/meshopt/meshopt-decoder.js.map +1 -1
  88. package/dist/esm/webp/webp.js +1 -1
  89. package/dist/esm/webp/webp.js.map +1 -1
  90. package/dist/glb-loader.d.ts +13 -0
  91. package/dist/glb-loader.d.ts.map +1 -0
  92. package/dist/glb-loader.js +39 -0
  93. package/dist/glb-writer.d.ts +22 -0
  94. package/dist/glb-writer.d.ts.map +1 -0
  95. package/dist/glb-writer.js +37 -0
  96. package/dist/gltf-loader.d.ts +18 -0
  97. package/dist/gltf-loader.d.ts.map +1 -0
  98. package/dist/gltf-loader.js +50 -0
  99. package/dist/gltf-writer.d.ts +25 -0
  100. package/dist/gltf-writer.d.ts.map +1 -0
  101. package/dist/gltf-writer.js +32 -0
  102. package/dist/index.d.ts +11 -0
  103. package/dist/index.d.ts.map +1 -0
  104. package/dist/index.js +21 -0
  105. package/dist/lib/api/gltf-extensions.d.ts +26 -0
  106. package/dist/lib/api/gltf-extensions.d.ts.map +1 -0
  107. package/dist/lib/api/gltf-extensions.js +75 -0
  108. package/dist/lib/api/gltf-scenegraph.d.ts +183 -0
  109. package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -0
  110. package/dist/lib/api/gltf-scenegraph.js +553 -0
  111. package/dist/lib/api/normalize-gltf-v1.d.ts +2 -0
  112. package/dist/lib/api/normalize-gltf-v1.d.ts.map +1 -0
  113. package/dist/lib/api/normalize-gltf-v1.js +295 -0
  114. package/dist/lib/api/post-process-gltf.d.ts +2 -0
  115. package/dist/lib/api/post-process-gltf.d.ts.map +1 -0
  116. package/dist/lib/api/post-process-gltf.js +367 -0
  117. package/dist/lib/encoders/encode-glb.d.ts +2 -0
  118. package/dist/lib/encoders/encode-glb.d.ts.map +1 -0
  119. package/dist/lib/encoders/encode-glb.js +61 -0
  120. package/dist/lib/encoders/encode-gltf.d.ts +2 -0
  121. package/dist/lib/encoders/encode-gltf.d.ts.map +1 -0
  122. package/dist/lib/encoders/encode-gltf.js +27 -0
  123. package/dist/lib/extensions/EXT_meshopt_compression.d.ts +10 -0
  124. package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -0
  125. package/dist/lib/extensions/EXT_meshopt_compression.js +54 -0
  126. package/dist/lib/extensions/EXT_texture_webp.d.ts +12 -0
  127. package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -0
  128. package/dist/lib/extensions/EXT_texture_webp.js +38 -0
  129. package/dist/lib/extensions/KHR_binary_gltf.d.ts +7 -0
  130. package/dist/lib/extensions/KHR_binary_gltf.d.ts.map +1 -0
  131. package/dist/lib/extensions/KHR_binary_gltf.js +42 -0
  132. package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +13 -0
  133. package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -0
  134. package/dist/lib/extensions/KHR_draco_mesh_compression.js +141 -0
  135. package/dist/lib/extensions/KHR_texture_basisu.d.ts +12 -0
  136. package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -0
  137. package/dist/lib/extensions/KHR_texture_basisu.js +31 -0
  138. package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts +7 -0
  139. package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts.map +1 -0
  140. package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +62 -0
  141. package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts +7 -0
  142. package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts.map +1 -0
  143. package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +47 -0
  144. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts +7 -0
  145. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts.map +1 -0
  146. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +81 -0
  147. package/dist/lib/gltf-utils/get-typed-array.d.ts +3 -0
  148. package/dist/lib/gltf-utils/get-typed-array.d.ts.map +1 -0
  149. package/dist/lib/gltf-utils/get-typed-array.js +41 -0
  150. package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts +6 -0
  151. package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts.map +1 -0
  152. package/dist/lib/gltf-utils/gltf-attribute-utils.js +73 -0
  153. package/dist/lib/gltf-utils/gltf-constants.d.ts +4 -0
  154. package/dist/lib/gltf-utils/gltf-constants.d.ts.map +1 -0
  155. package/dist/lib/gltf-utils/gltf-constants.js +43 -0
  156. package/dist/lib/gltf-utils/gltf-utils.d.ts +8 -0
  157. package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -0
  158. package/dist/lib/gltf-utils/gltf-utils.js +63 -0
  159. package/dist/lib/gltf-utils/resolve-url.d.ts +2 -0
  160. package/dist/lib/gltf-utils/resolve-url.d.ts.map +1 -0
  161. package/dist/lib/gltf-utils/resolve-url.js +18 -0
  162. package/dist/lib/parsers/parse-glb.d.ts +8 -0
  163. package/dist/lib/parsers/parse-glb.d.ts.map +1 -0
  164. package/dist/lib/parsers/parse-glb.js +141 -0
  165. package/dist/lib/parsers/parse-gltf.d.ts +14 -0
  166. package/dist/lib/parsers/parse-gltf.d.ts.map +1 -0
  167. package/dist/lib/parsers/parse-gltf.js +189 -0
  168. package/dist/lib/types/glb-types.d.ts +17 -0
  169. package/dist/lib/types/glb-types.d.ts.map +1 -0
  170. package/dist/lib/types/glb-types.js +2 -0
  171. package/dist/lib/types/gltf-json-schema.d.ts +720 -0
  172. package/dist/lib/types/gltf-json-schema.d.ts.map +1 -0
  173. package/dist/lib/types/gltf-json-schema.js +4 -0
  174. package/dist/lib/types/gltf-postprocessed-schema.d.ts +685 -0
  175. package/dist/lib/types/gltf-postprocessed-schema.d.ts.map +1 -0
  176. package/dist/lib/types/gltf-postprocessed-schema.js +4 -0
  177. package/dist/lib/types/gltf-types.d.ts +10 -0
  178. package/dist/lib/types/gltf-types.d.ts.map +1 -0
  179. package/dist/lib/types/gltf-types.js +3 -0
  180. package/dist/lib/utils/assert.d.ts +2 -0
  181. package/dist/lib/utils/assert.d.ts.map +1 -0
  182. package/dist/lib/utils/assert.js +12 -0
  183. package/dist/lib/utils/version.d.ts +2 -0
  184. package/dist/lib/utils/version.d.ts.map +1 -0
  185. package/dist/lib/utils/version.js +7 -0
  186. package/dist/meshopt/meshopt-decoder.d.ts +6 -0
  187. package/dist/meshopt/meshopt-decoder.d.ts.map +1 -0
  188. package/dist/meshopt/meshopt-decoder.js +118 -0
  189. package/dist/webp/webp.d.ts +7 -0
  190. package/dist/webp/webp.d.ts.map +1 -0
  191. package/dist/webp/webp.js +38 -0
  192. package/package.json +11 -8
  193. package/src/lib/api/{normalize-gltf-v1.js → normalize-gltf-v1.ts} +18 -16
  194. package/src/lib/api/{post-process-gltf.js → post-process-gltf.ts} +41 -3
  195. package/src/lib/encoders/{encode-glb.js → encode-glb.ts} +0 -0
  196. package/src/lib/encoders/{encode-gltf.js → encode-gltf.ts} +0 -0
  197. package/src/lib/extensions/KHR_texture_basisu.ts +2 -2
  198. package/src/lib/parsers/parse-gltf.ts +17 -1
  199. package/src/lib/utils/{assert.js → assert.ts} +1 -1
  200. package/src/lib/utils/{version.js → version.ts} +0 -0
  201. package/dist/dist.min.js +0 -2
  202. package/dist/dist.min.js.map +0 -1
@@ -7,12 +7,6 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = void 0;
9
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
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
11
 
18
12
  var _images = require("@loaders.gl/images");
@@ -23,17 +17,7 @@ var _assert = require("../utils/assert");
23
17
 
24
18
  var _gltfUtils = require("../gltf-utils/gltf-utils");
25
19
 
26
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
27
-
28
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
29
-
30
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
31
-
32
- 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; }
33
-
34
- 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; }
35
-
36
- var DEFAULT_GLTF_JSON = {
20
+ const DEFAULT_GLTF_JSON = {
37
21
  asset: {
38
22
  version: '2.0',
39
23
  generator: 'loaders.gl'
@@ -41,14 +25,14 @@ var DEFAULT_GLTF_JSON = {
41
25
  buffers: []
42
26
  };
43
27
 
44
- var GLTFScenegraph = function () {
45
- function GLTFScenegraph(gltf) {
46
- (0, _classCallCheck2.default)(this, GLTFScenegraph);
28
+ class GLTFScenegraph {
29
+ constructor(gltf) {
47
30
  (0, _defineProperty2.default)(this, "gltf", void 0);
48
31
  (0, _defineProperty2.default)(this, "sourceBuffers", void 0);
49
32
  (0, _defineProperty2.default)(this, "byteLength", void 0);
50
33
  this.gltf = gltf || {
51
- json: _objectSpread({}, DEFAULT_GLTF_JSON),
34
+ json: { ...DEFAULT_GLTF_JSON
35
+ },
52
36
  buffers: []
53
37
  };
54
38
  this.sourceBuffers = [];
@@ -60,564 +44,486 @@ var GLTFScenegraph = function () {
60
44
  }
61
45
  }
62
46
 
63
- (0, _createClass2.default)(GLTFScenegraph, [{
64
- key: "json",
65
- get: function get() {
66
- return this.gltf.json;
67
- }
68
- }, {
69
- key: "getApplicationData",
70
- value: function getApplicationData(key) {
71
- var data = this.json[key];
72
- return data;
73
- }
74
- }, {
75
- key: "getExtraData",
76
- value: function getExtraData(key) {
77
- var extras = this.json.extras || {};
78
- return extras[key];
79
- }
80
- }, {
81
- key: "getExtension",
82
- value: function getExtension(extensionName) {
83
- var isExtension = this.getUsedExtensions().find(function (name) {
84
- return name === extensionName;
85
- });
86
- var extensions = this.json.extensions || {};
87
- return isExtension ? extensions[extensionName] || true : null;
88
- }
89
- }, {
90
- key: "getRequiredExtension",
91
- value: function getRequiredExtension(extensionName) {
92
- var isRequired = this.getRequiredExtensions().find(function (name) {
93
- return name === extensionName;
94
- });
95
- return isRequired ? this.getExtension(extensionName) : null;
96
- }
97
- }, {
98
- key: "getRequiredExtensions",
99
- value: function getRequiredExtensions() {
100
- return this.json.extensionsRequired || [];
101
- }
102
- }, {
103
- key: "getUsedExtensions",
104
- value: function getUsedExtensions() {
105
- return this.json.extensionsUsed || [];
106
- }
107
- }, {
108
- key: "getObjectExtension",
109
- value: function getObjectExtension(object, extensionName) {
110
- var extensions = object.extensions || {};
111
- return extensions[extensionName];
112
- }
113
- }, {
114
- key: "getScene",
115
- value: function getScene(index) {
116
- return this.getObject('scenes', index);
117
- }
118
- }, {
119
- key: "getNode",
120
- value: function getNode(index) {
121
- return this.getObject('nodes', index);
122
- }
123
- }, {
124
- key: "getSkin",
125
- value: function getSkin(index) {
126
- return this.getObject('skins', index);
127
- }
128
- }, {
129
- key: "getMesh",
130
- value: function getMesh(index) {
131
- return this.getObject('meshes', index);
132
- }
133
- }, {
134
- key: "getMaterial",
135
- value: function getMaterial(index) {
136
- return this.getObject('materials', index);
137
- }
138
- }, {
139
- key: "getAccessor",
140
- value: function getAccessor(index) {
141
- return this.getObject('accessors', index);
142
- }
143
- }, {
144
- key: "getTexture",
145
- value: function getTexture(index) {
146
- return this.getObject('textures', index);
147
- }
148
- }, {
149
- key: "getSampler",
150
- value: function getSampler(index) {
151
- return this.getObject('samplers', index);
152
- }
153
- }, {
154
- key: "getImage",
155
- value: function getImage(index) {
156
- return this.getObject('images', index);
157
- }
158
- }, {
159
- key: "getBufferView",
160
- value: function getBufferView(index) {
161
- return this.getObject('bufferViews', index);
162
- }
163
- }, {
164
- key: "getBuffer",
165
- value: function getBuffer(index) {
166
- return this.getObject('buffers', index);
167
- }
168
- }, {
169
- key: "getObject",
170
- value: function getObject(array, index) {
171
- if ((0, _typeof2.default)(index) === 'object') {
172
- return index;
173
- }
47
+ get json() {
48
+ return this.gltf.json;
49
+ }
174
50
 
175
- var object = this.json[array] && this.json[array][index];
51
+ getApplicationData(key) {
52
+ const data = this.json[key];
53
+ return data;
54
+ }
176
55
 
177
- if (!object) {
178
- throw new Error("glTF file error: Could not find ".concat(array, "[").concat(index, "]"));
179
- }
56
+ getExtraData(key) {
57
+ const extras = this.json.extras || {};
58
+ return extras[key];
59
+ }
180
60
 
181
- return object;
182
- }
183
- }, {
184
- key: "getTypedArrayForBufferView",
185
- value: function getTypedArrayForBufferView(bufferView) {
186
- bufferView = this.getBufferView(bufferView);
187
- var bufferIndex = bufferView.buffer;
188
- var binChunk = this.gltf.buffers[bufferIndex];
189
- (0, _assert.assert)(binChunk);
190
- var byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset;
191
- return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength);
192
- }
193
- }, {
194
- key: "getTypedArrayForAccessor",
195
- value: function getTypedArrayForAccessor(accessor) {
196
- accessor = this.getAccessor(accessor);
197
- var bufferView = this.getBufferView(accessor.bufferView);
198
- var buffer = this.getBuffer(bufferView.buffer);
199
- var arrayBuffer = buffer.data;
200
-
201
- var _getAccessorArrayType = (0, _gltfUtils.getAccessorArrayTypeAndLength)(accessor, bufferView),
202
- ArrayType = _getAccessorArrayType.ArrayType,
203
- length = _getAccessorArrayType.length;
204
-
205
- var byteOffset = bufferView.byteOffset + accessor.byteOffset;
206
- return new ArrayType(arrayBuffer, byteOffset, length);
207
- }
208
- }, {
209
- key: "getTypedArrayForImageData",
210
- value: function getTypedArrayForImageData(image) {
211
- image = this.getAccessor(image);
212
- var bufferView = this.getBufferView(image.bufferView);
213
- var buffer = this.getBuffer(bufferView.buffer);
214
- var arrayBuffer = buffer.data;
215
- var byteOffset = bufferView.byteOffset || 0;
216
- return new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength);
217
- }
218
- }, {
219
- key: "addApplicationData",
220
- value: function addApplicationData(key, data) {
221
- this.json[key] = data;
222
- return this;
223
- }
224
- }, {
225
- key: "addExtraData",
226
- value: function addExtraData(key, data) {
227
- this.json.extras = this.json.extras || {};
228
- this.json.extras[key] = data;
229
- return this;
230
- }
231
- }, {
232
- key: "addObjectExtension",
233
- value: function addObjectExtension(object, extensionName, data) {
234
- object.extensions = object.extensions || {};
235
- object.extensions[extensionName] = data;
236
- this.registerUsedExtension(extensionName);
237
- return this;
238
- }
239
- }, {
240
- key: "setObjectExtension",
241
- value: function setObjectExtension(object, extensionName, data) {
242
- var extensions = object.extensions || {};
243
- extensions[extensionName] = data;
244
- }
245
- }, {
246
- key: "removeObjectExtension",
247
- value: function removeObjectExtension(object, extensionName) {
248
- var extensions = object.extensions || {};
249
- var extension = extensions[extensionName];
250
- delete extensions[extensionName];
251
- return extension;
252
- }
253
- }, {
254
- key: "addExtension",
255
- value: function addExtension(extensionName) {
256
- var extensionData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
257
- (0, _assert.assert)(extensionData);
258
- this.json.extensions = this.json.extensions || {};
259
- this.json.extensions[extensionName] = extensionData;
260
- this.registerUsedExtension(extensionName);
261
- return extensionData;
262
- }
263
- }, {
264
- key: "addRequiredExtension",
265
- value: function addRequiredExtension(extensionName) {
266
- var extensionData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
267
- (0, _assert.assert)(extensionData);
268
- this.addExtension(extensionName, extensionData);
269
- this.registerRequiredExtension(extensionName);
270
- return extensionData;
61
+ getExtension(extensionName) {
62
+ const isExtension = this.getUsedExtensions().find(name => name === extensionName);
63
+ const extensions = this.json.extensions || {};
64
+ return isExtension ? extensions[extensionName] || true : null;
65
+ }
66
+
67
+ getRequiredExtension(extensionName) {
68
+ const isRequired = this.getRequiredExtensions().find(name => name === extensionName);
69
+ return isRequired ? this.getExtension(extensionName) : null;
70
+ }
71
+
72
+ getRequiredExtensions() {
73
+ return this.json.extensionsRequired || [];
74
+ }
75
+
76
+ getUsedExtensions() {
77
+ return this.json.extensionsUsed || [];
78
+ }
79
+
80
+ getObjectExtension(object, extensionName) {
81
+ const extensions = object.extensions || {};
82
+ return extensions[extensionName];
83
+ }
84
+
85
+ getScene(index) {
86
+ return this.getObject('scenes', index);
87
+ }
88
+
89
+ getNode(index) {
90
+ return this.getObject('nodes', index);
91
+ }
92
+
93
+ getSkin(index) {
94
+ return this.getObject('skins', index);
95
+ }
96
+
97
+ getMesh(index) {
98
+ return this.getObject('meshes', index);
99
+ }
100
+
101
+ getMaterial(index) {
102
+ return this.getObject('materials', index);
103
+ }
104
+
105
+ getAccessor(index) {
106
+ return this.getObject('accessors', index);
107
+ }
108
+
109
+ getTexture(index) {
110
+ return this.getObject('textures', index);
111
+ }
112
+
113
+ getSampler(index) {
114
+ return this.getObject('samplers', index);
115
+ }
116
+
117
+ getImage(index) {
118
+ return this.getObject('images', index);
119
+ }
120
+
121
+ getBufferView(index) {
122
+ return this.getObject('bufferViews', index);
123
+ }
124
+
125
+ getBuffer(index) {
126
+ return this.getObject('buffers', index);
127
+ }
128
+
129
+ getObject(array, index) {
130
+ if (typeof index === 'object') {
131
+ return index;
271
132
  }
272
- }, {
273
- key: "registerUsedExtension",
274
- value: function registerUsedExtension(extensionName) {
275
- this.json.extensionsUsed = this.json.extensionsUsed || [];
276
-
277
- if (!this.json.extensionsUsed.find(function (ext) {
278
- return ext === extensionName;
279
- })) {
280
- this.json.extensionsUsed.push(extensionName);
281
- }
133
+
134
+ const object = this.json[array] && this.json[array][index];
135
+
136
+ if (!object) {
137
+ throw new Error("glTF file error: Could not find ".concat(array, "[").concat(index, "]"));
282
138
  }
283
- }, {
284
- key: "registerRequiredExtension",
285
- value: function registerRequiredExtension(extensionName) {
286
- this.registerUsedExtension(extensionName);
287
- this.json.extensionsRequired = this.json.extensionsRequired || [];
288
-
289
- if (!this.json.extensionsRequired.find(function (ext) {
290
- return ext === extensionName;
291
- })) {
292
- this.json.extensionsRequired.push(extensionName);
293
- }
139
+
140
+ return object;
141
+ }
142
+
143
+ getTypedArrayForBufferView(bufferView) {
144
+ bufferView = this.getBufferView(bufferView);
145
+ const bufferIndex = bufferView.buffer;
146
+ const binChunk = this.gltf.buffers[bufferIndex];
147
+ (0, _assert.assert)(binChunk);
148
+ const byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset;
149
+ return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength);
150
+ }
151
+
152
+ getTypedArrayForAccessor(accessor) {
153
+ accessor = this.getAccessor(accessor);
154
+ const bufferView = this.getBufferView(accessor.bufferView);
155
+ const buffer = this.getBuffer(bufferView.buffer);
156
+ const arrayBuffer = buffer.data;
157
+ const {
158
+ ArrayType,
159
+ length
160
+ } = (0, _gltfUtils.getAccessorArrayTypeAndLength)(accessor, bufferView);
161
+ const byteOffset = bufferView.byteOffset + accessor.byteOffset;
162
+ return new ArrayType(arrayBuffer, byteOffset, length);
163
+ }
164
+
165
+ getTypedArrayForImageData(image) {
166
+ image = this.getAccessor(image);
167
+ const bufferView = this.getBufferView(image.bufferView);
168
+ const buffer = this.getBuffer(bufferView.buffer);
169
+ const arrayBuffer = buffer.data;
170
+ const byteOffset = bufferView.byteOffset || 0;
171
+ return new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength);
172
+ }
173
+
174
+ addApplicationData(key, data) {
175
+ this.json[key] = data;
176
+ return this;
177
+ }
178
+
179
+ addExtraData(key, data) {
180
+ this.json.extras = this.json.extras || {};
181
+ this.json.extras[key] = data;
182
+ return this;
183
+ }
184
+
185
+ addObjectExtension(object, extensionName, data) {
186
+ object.extensions = object.extensions || {};
187
+ object.extensions[extensionName] = data;
188
+ this.registerUsedExtension(extensionName);
189
+ return this;
190
+ }
191
+
192
+ setObjectExtension(object, extensionName, data) {
193
+ const extensions = object.extensions || {};
194
+ extensions[extensionName] = data;
195
+ }
196
+
197
+ removeObjectExtension(object, extensionName) {
198
+ const extensions = object.extensions || {};
199
+ const extension = extensions[extensionName];
200
+ delete extensions[extensionName];
201
+ return extension;
202
+ }
203
+
204
+ addExtension(extensionName, extensionData = {}) {
205
+ (0, _assert.assert)(extensionData);
206
+ this.json.extensions = this.json.extensions || {};
207
+ this.json.extensions[extensionName] = extensionData;
208
+ this.registerUsedExtension(extensionName);
209
+ return extensionData;
210
+ }
211
+
212
+ addRequiredExtension(extensionName, extensionData = {}) {
213
+ (0, _assert.assert)(extensionData);
214
+ this.addExtension(extensionName, extensionData);
215
+ this.registerRequiredExtension(extensionName);
216
+ return extensionData;
217
+ }
218
+
219
+ registerUsedExtension(extensionName) {
220
+ this.json.extensionsUsed = this.json.extensionsUsed || [];
221
+
222
+ if (!this.json.extensionsUsed.find(ext => ext === extensionName)) {
223
+ this.json.extensionsUsed.push(extensionName);
294
224
  }
295
- }, {
296
- key: "removeExtension",
297
- value: function removeExtension(extensionName) {
298
- if (this.json.extensionsRequired) {
299
- this._removeStringFromArray(this.json.extensionsRequired, extensionName);
300
- }
225
+ }
301
226
 
302
- if (this.json.extensionsUsed) {
303
- this._removeStringFromArray(this.json.extensionsUsed, extensionName);
304
- }
227
+ registerRequiredExtension(extensionName) {
228
+ this.registerUsedExtension(extensionName);
229
+ this.json.extensionsRequired = this.json.extensionsRequired || [];
305
230
 
306
- if (this.json.extensions) {
307
- delete this.json.extensions[extensionName];
308
- }
231
+ if (!this.json.extensionsRequired.find(ext => ext === extensionName)) {
232
+ this.json.extensionsRequired.push(extensionName);
309
233
  }
310
- }, {
311
- key: "setDefaultScene",
312
- value: function setDefaultScene(sceneIndex) {
313
- this.json.scene = sceneIndex;
234
+ }
235
+
236
+ removeExtension(extensionName) {
237
+ if (this.json.extensionsRequired) {
238
+ this._removeStringFromArray(this.json.extensionsRequired, extensionName);
314
239
  }
315
- }, {
316
- key: "addScene",
317
- value: function addScene(scene) {
318
- var nodeIndices = scene.nodeIndices;
319
- this.json.scenes = this.json.scenes || [];
320
- this.json.scenes.push({
321
- nodes: nodeIndices
322
- });
323
- return this.json.scenes.length - 1;
240
+
241
+ if (this.json.extensionsUsed) {
242
+ this._removeStringFromArray(this.json.extensionsUsed, extensionName);
324
243
  }
325
- }, {
326
- key: "addNode",
327
- value: function addNode(node) {
328
- var meshIndex = node.meshIndex,
329
- matrix = node.matrix;
330
- this.json.nodes = this.json.nodes || [];
331
- var nodeData = {
332
- mesh: meshIndex
333
- };
334
-
335
- if (matrix) {
336
- nodeData.matrix = matrix;
337
- }
338
244
 
339
- this.json.nodes.push(nodeData);
340
- return this.json.nodes.length - 1;
245
+ if (this.json.extensions) {
246
+ delete this.json.extensions[extensionName];
341
247
  }
342
- }, {
343
- key: "addMesh",
344
- value: function addMesh(mesh) {
345
- var attributes = mesh.attributes,
346
- indices = mesh.indices,
347
- material = mesh.material,
348
- _mesh$mode = mesh.mode,
349
- mode = _mesh$mode === void 0 ? 4 : _mesh$mode;
350
-
351
- var accessors = this._addAttributes(attributes);
352
-
353
- var glTFMesh = {
354
- primitives: [{
355
- attributes: accessors,
356
- mode: mode
357
- }]
358
- };
359
-
360
- if (indices) {
361
- var indicesAccessor = this._addIndices(indices);
362
-
363
- glTFMesh.primitives[0].indices = indicesAccessor;
364
- }
248
+ }
365
249
 
366
- if (Number.isFinite(material)) {
367
- glTFMesh.primitives[0].material = material;
368
- }
250
+ setDefaultScene(sceneIndex) {
251
+ this.json.scene = sceneIndex;
252
+ }
369
253
 
370
- this.json.meshes = this.json.meshes || [];
371
- this.json.meshes.push(glTFMesh);
372
- return this.json.meshes.length - 1;
373
- }
374
- }, {
375
- key: "addPointCloud",
376
- value: function addPointCloud(attributes) {
377
- var accessorIndices = this._addAttributes(attributes);
378
-
379
- var glTFMesh = {
380
- primitives: [{
381
- attributes: accessorIndices,
382
- mode: 0
383
- }]
384
- };
385
- this.json.meshes = this.json.meshes || [];
386
- this.json.meshes.push(glTFMesh);
387
- return this.json.meshes.length - 1;
388
- }
389
- }, {
390
- key: "addImage",
391
- value: function addImage(imageData, mimeTypeOpt) {
392
- var metadata = (0, _images.getBinaryImageMetadata)(imageData);
393
- var mimeType = mimeTypeOpt || (metadata === null || metadata === void 0 ? void 0 : metadata.mimeType);
394
- var bufferViewIndex = this.addBufferView(imageData);
395
- var glTFImage = {
396
- bufferView: bufferViewIndex,
397
- mimeType: mimeType
398
- };
399
- this.json.images = this.json.images || [];
400
- this.json.images.push(glTFImage);
401
- return this.json.images.length - 1;
254
+ addScene(scene) {
255
+ const {
256
+ nodeIndices
257
+ } = scene;
258
+ this.json.scenes = this.json.scenes || [];
259
+ this.json.scenes.push({
260
+ nodes: nodeIndices
261
+ });
262
+ return this.json.scenes.length - 1;
263
+ }
264
+
265
+ addNode(node) {
266
+ const {
267
+ meshIndex,
268
+ matrix
269
+ } = node;
270
+ this.json.nodes = this.json.nodes || [];
271
+ const nodeData = {
272
+ mesh: meshIndex
273
+ };
274
+
275
+ if (matrix) {
276
+ nodeData.matrix = matrix;
402
277
  }
403
- }, {
404
- key: "addBufferView",
405
- value: function addBufferView(buffer) {
406
- var byteLength = buffer.byteLength;
407
- (0, _assert.assert)(Number.isFinite(byteLength));
408
- this.sourceBuffers = this.sourceBuffers || [];
409
- this.sourceBuffers.push(buffer);
410
- var glTFBufferView = {
411
- buffer: 0,
412
- byteOffset: this.byteLength,
413
- byteLength: byteLength
414
- };
415
- this.byteLength += (0, _loaderUtils.padToNBytes)(byteLength, 4);
416
- this.json.bufferViews = this.json.bufferViews || [];
417
- this.json.bufferViews.push(glTFBufferView);
418
- return this.json.bufferViews.length - 1;
278
+
279
+ this.json.nodes.push(nodeData);
280
+ return this.json.nodes.length - 1;
281
+ }
282
+
283
+ addMesh(mesh) {
284
+ const {
285
+ attributes,
286
+ indices,
287
+ material,
288
+ mode = 4
289
+ } = mesh;
290
+
291
+ const accessors = this._addAttributes(attributes);
292
+
293
+ const glTFMesh = {
294
+ primitives: [{
295
+ attributes: accessors,
296
+ mode
297
+ }]
298
+ };
299
+
300
+ if (indices) {
301
+ const indicesAccessor = this._addIndices(indices);
302
+
303
+ glTFMesh.primitives[0].indices = indicesAccessor;
419
304
  }
420
- }, {
421
- key: "addAccessor",
422
- value: function addAccessor(bufferViewIndex, accessor) {
423
- var glTFAccessor = {
424
- bufferView: bufferViewIndex,
425
- type: (0, _gltfUtils.getAccessorTypeFromSize)(accessor.size),
426
- componentType: accessor.componentType,
427
- count: accessor.count,
428
- max: accessor.max,
429
- min: accessor.min
430
- };
431
- this.json.accessors = this.json.accessors || [];
432
- this.json.accessors.push(glTFAccessor);
433
- return this.json.accessors.length - 1;
305
+
306
+ if (Number.isFinite(material)) {
307
+ glTFMesh.primitives[0].material = material;
434
308
  }
435
- }, {
436
- key: "addBinaryBuffer",
437
- value: function addBinaryBuffer(sourceBuffer) {
438
- var accessor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
439
- size: 3
440
- };
441
- var bufferViewIndex = this.addBufferView(sourceBuffer);
442
- var minMax = {
443
- min: accessor.min,
444
- max: accessor.max
445
- };
446
-
447
- if (!minMax.min || !minMax.max) {
448
- minMax = this._getAccessorMinMax(sourceBuffer, accessor.size);
449
- }
450
309
 
451
- var accessorDefaults = {
452
- size: accessor.size,
453
- componentType: (0, _gltfUtils.getComponentTypeFromArray)(sourceBuffer),
454
- count: Math.round(sourceBuffer.length / accessor.size),
455
- min: minMax.min,
456
- max: minMax.max
457
- };
458
- return this.addAccessor(bufferViewIndex, Object.assign(accessorDefaults, accessor));
310
+ this.json.meshes = this.json.meshes || [];
311
+ this.json.meshes.push(glTFMesh);
312
+ return this.json.meshes.length - 1;
313
+ }
314
+
315
+ addPointCloud(attributes) {
316
+ const accessorIndices = this._addAttributes(attributes);
317
+
318
+ const glTFMesh = {
319
+ primitives: [{
320
+ attributes: accessorIndices,
321
+ mode: 0
322
+ }]
323
+ };
324
+ this.json.meshes = this.json.meshes || [];
325
+ this.json.meshes.push(glTFMesh);
326
+ return this.json.meshes.length - 1;
327
+ }
328
+
329
+ addImage(imageData, mimeTypeOpt) {
330
+ const metadata = (0, _images.getBinaryImageMetadata)(imageData);
331
+ const mimeType = mimeTypeOpt || (metadata === null || metadata === void 0 ? void 0 : metadata.mimeType);
332
+ const bufferViewIndex = this.addBufferView(imageData);
333
+ const glTFImage = {
334
+ bufferView: bufferViewIndex,
335
+ mimeType
336
+ };
337
+ this.json.images = this.json.images || [];
338
+ this.json.images.push(glTFImage);
339
+ return this.json.images.length - 1;
340
+ }
341
+
342
+ addBufferView(buffer) {
343
+ const byteLength = buffer.byteLength;
344
+ (0, _assert.assert)(Number.isFinite(byteLength));
345
+ this.sourceBuffers = this.sourceBuffers || [];
346
+ this.sourceBuffers.push(buffer);
347
+ const glTFBufferView = {
348
+ buffer: 0,
349
+ byteOffset: this.byteLength,
350
+ byteLength
351
+ };
352
+ this.byteLength += (0, _loaderUtils.padToNBytes)(byteLength, 4);
353
+ this.json.bufferViews = this.json.bufferViews || [];
354
+ this.json.bufferViews.push(glTFBufferView);
355
+ return this.json.bufferViews.length - 1;
356
+ }
357
+
358
+ addAccessor(bufferViewIndex, accessor) {
359
+ const glTFAccessor = {
360
+ bufferView: bufferViewIndex,
361
+ type: (0, _gltfUtils.getAccessorTypeFromSize)(accessor.size),
362
+ componentType: accessor.componentType,
363
+ count: accessor.count,
364
+ max: accessor.max,
365
+ min: accessor.min
366
+ };
367
+ this.json.accessors = this.json.accessors || [];
368
+ this.json.accessors.push(glTFAccessor);
369
+ return this.json.accessors.length - 1;
370
+ }
371
+
372
+ addBinaryBuffer(sourceBuffer, accessor = {
373
+ size: 3
374
+ }) {
375
+ const bufferViewIndex = this.addBufferView(sourceBuffer);
376
+ let minMax = {
377
+ min: accessor.min,
378
+ max: accessor.max
379
+ };
380
+
381
+ if (!minMax.min || !minMax.max) {
382
+ minMax = this._getAccessorMinMax(sourceBuffer, accessor.size);
459
383
  }
460
- }, {
461
- key: "addTexture",
462
- value: function addTexture(texture) {
463
- var imageIndex = texture.imageIndex;
464
- var glTFTexture = {
465
- source: imageIndex
466
- };
467
- this.json.textures = this.json.textures || [];
468
- this.json.textures.push(glTFTexture);
469
- return this.json.textures.length - 1;
384
+
385
+ const accessorDefaults = {
386
+ size: accessor.size,
387
+ componentType: (0, _gltfUtils.getComponentTypeFromArray)(sourceBuffer),
388
+ count: Math.round(sourceBuffer.length / accessor.size),
389
+ min: minMax.min,
390
+ max: minMax.max
391
+ };
392
+ return this.addAccessor(bufferViewIndex, Object.assign(accessorDefaults, accessor));
393
+ }
394
+
395
+ addTexture(texture) {
396
+ const {
397
+ imageIndex
398
+ } = texture;
399
+ const glTFTexture = {
400
+ source: imageIndex
401
+ };
402
+ this.json.textures = this.json.textures || [];
403
+ this.json.textures.push(glTFTexture);
404
+ return this.json.textures.length - 1;
405
+ }
406
+
407
+ addMaterial(pbrMaterialInfo) {
408
+ this.json.materials = this.json.materials || [];
409
+ this.json.materials.push(pbrMaterialInfo);
410
+ return this.json.materials.length - 1;
411
+ }
412
+
413
+ createBinaryChunk() {
414
+ var _this$json, _this$json$buffers;
415
+
416
+ this.gltf.buffers = [];
417
+ const totalByteLength = this.byteLength;
418
+ const arrayBuffer = new ArrayBuffer(totalByteLength);
419
+ const targetArray = new Uint8Array(arrayBuffer);
420
+ let dstByteOffset = 0;
421
+
422
+ for (const sourceBuffer of this.sourceBuffers || []) {
423
+ dstByteOffset = (0, _loaderUtils.copyToArray)(sourceBuffer, targetArray, dstByteOffset);
470
424
  }
471
- }, {
472
- key: "addMaterial",
473
- value: function addMaterial(pbrMaterialInfo) {
474
- this.json.materials = this.json.materials || [];
475
- this.json.materials.push(pbrMaterialInfo);
476
- return this.json.materials.length - 1;
425
+
426
+ if ((_this$json = this.json) !== null && _this$json !== void 0 && (_this$json$buffers = _this$json.buffers) !== null && _this$json$buffers !== void 0 && _this$json$buffers[0]) {
427
+ this.json.buffers[0].byteLength = totalByteLength;
428
+ } else {
429
+ this.json.buffers = [{
430
+ byteLength: totalByteLength
431
+ }];
477
432
  }
478
- }, {
479
- key: "createBinaryChunk",
480
- value: function createBinaryChunk() {
481
- var _this$json, _this$json$buffers;
482
-
483
- this.gltf.buffers = [];
484
- var totalByteLength = this.byteLength;
485
- var arrayBuffer = new ArrayBuffer(totalByteLength);
486
- var targetArray = new Uint8Array(arrayBuffer);
487
- var dstByteOffset = 0;
488
-
489
- var _iterator = _createForOfIteratorHelper(this.sourceBuffers || []),
490
- _step;
491
-
492
- try {
493
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
494
- var sourceBuffer = _step.value;
495
- dstByteOffset = (0, _loaderUtils.copyToArray)(sourceBuffer, targetArray, dstByteOffset);
496
- }
497
- } catch (err) {
498
- _iterator.e(err);
499
- } finally {
500
- _iterator.f();
501
- }
502
433
 
503
- if ((_this$json = this.json) !== null && _this$json !== void 0 && (_this$json$buffers = _this$json.buffers) !== null && _this$json$buffers !== void 0 && _this$json$buffers[0]) {
504
- this.json.buffers[0].byteLength = totalByteLength;
434
+ this.gltf.binary = arrayBuffer;
435
+ this.sourceBuffers = [arrayBuffer];
436
+ }
437
+
438
+ _removeStringFromArray(array, string) {
439
+ let found = true;
440
+
441
+ while (found) {
442
+ const index = array.indexOf(string);
443
+
444
+ if (index > -1) {
445
+ array.splice(index, 1);
505
446
  } else {
506
- this.json.buffers = [{
507
- byteLength: totalByteLength
508
- }];
447
+ found = false;
509
448
  }
510
-
511
- this.gltf.binary = arrayBuffer;
512
- this.sourceBuffers = [arrayBuffer];
513
449
  }
514
- }, {
515
- key: "_removeStringFromArray",
516
- value: function _removeStringFromArray(array, string) {
517
- var found = true;
518
-
519
- while (found) {
520
- var index = array.indexOf(string);
521
-
522
- if (index > -1) {
523
- array.splice(index, 1);
524
- } else {
525
- found = false;
526
- }
527
- }
450
+ }
451
+
452
+ _addAttributes(attributes = {}) {
453
+ const result = {};
454
+
455
+ for (const attributeKey in attributes) {
456
+ const attributeData = attributes[attributeKey];
457
+
458
+ const attrName = this._getGltfAttributeName(attributeKey);
459
+
460
+ const accessor = this.addBinaryBuffer(attributeData.value, attributeData);
461
+ result[attrName] = accessor;
528
462
  }
529
- }, {
530
- key: "_addAttributes",
531
- value: function _addAttributes() {
532
- var attributes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
533
- var result = {};
534
463
 
535
- for (var attributeKey in attributes) {
536
- var attributeData = attributes[attributeKey];
464
+ return result;
465
+ }
537
466
 
538
- var attrName = this._getGltfAttributeName(attributeKey);
467
+ _addIndices(indices) {
468
+ return this.addBinaryBuffer(indices, {
469
+ size: 1
470
+ });
471
+ }
539
472
 
540
- var accessor = this.addBinaryBuffer(attributeData.value, attributeData);
541
- result[attrName] = accessor;
542
- }
473
+ _getGltfAttributeName(attributeName) {
474
+ switch (attributeName.toLowerCase()) {
475
+ case 'position':
476
+ case 'positions':
477
+ case 'vertices':
478
+ return 'POSITION';
543
479
 
544
- return result;
480
+ case 'normal':
481
+ case 'normals':
482
+ return 'NORMAL';
483
+
484
+ case 'color':
485
+ case 'colors':
486
+ return 'COLOR_0';
487
+
488
+ case 'texcoord':
489
+ case 'texcoords':
490
+ return 'TEXCOORD_0';
491
+
492
+ default:
493
+ return attributeName;
545
494
  }
546
- }, {
547
- key: "_addIndices",
548
- value: function _addIndices(indices) {
549
- return this.addBinaryBuffer(indices, {
550
- size: 1
551
- });
495
+ }
496
+
497
+ _getAccessorMinMax(buffer, size) {
498
+ const result = {
499
+ min: null,
500
+ max: null
501
+ };
502
+
503
+ if (buffer.length < size) {
504
+ return result;
552
505
  }
553
- }, {
554
- key: "_getGltfAttributeName",
555
- value: function _getGltfAttributeName(attributeName) {
556
- switch (attributeName.toLowerCase()) {
557
- case 'position':
558
- case 'positions':
559
- case 'vertices':
560
- return 'POSITION';
561
-
562
- case 'normal':
563
- case 'normals':
564
- return 'NORMAL';
565
-
566
- case 'color':
567
- case 'colors':
568
- return 'COLOR_0';
569
-
570
- case 'texcoord':
571
- case 'texcoords':
572
- return 'TEXCOORD_0';
573
-
574
- default:
575
- return attributeName;
576
- }
506
+
507
+ result.min = [];
508
+ result.max = [];
509
+ const initValues = buffer.subarray(0, size);
510
+
511
+ for (const value of initValues) {
512
+ result.min.push(value);
513
+ result.max.push(value);
577
514
  }
578
- }, {
579
- key: "_getAccessorMinMax",
580
- value: function _getAccessorMinMax(buffer, size) {
581
- var result = {
582
- min: null,
583
- max: null
584
- };
585
-
586
- if (buffer.length < size) {
587
- return result;
588
- }
589
515
 
590
- result.min = [];
591
- result.max = [];
592
- var initValues = buffer.subarray(0, size);
593
-
594
- var _iterator2 = _createForOfIteratorHelper(initValues),
595
- _step2;
596
-
597
- try {
598
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
599
- var value = _step2.value;
600
- result.min.push(value);
601
- result.max.push(value);
602
- }
603
- } catch (err) {
604
- _iterator2.e(err);
605
- } finally {
606
- _iterator2.f();
516
+ for (let index = size; index < buffer.length; index += size) {
517
+ for (let componentIndex = 0; componentIndex < size; componentIndex++) {
518
+ result.min[0 + componentIndex] = Math.min(result.min[0 + componentIndex], buffer[index + componentIndex]);
519
+ result.max[0 + componentIndex] = Math.max(result.max[0 + componentIndex], buffer[index + componentIndex]);
607
520
  }
521
+ }
608
522
 
609
- for (var index = size; index < buffer.length; index += size) {
610
- for (var componentIndex = 0; componentIndex < size; componentIndex++) {
611
- result.min[0 + componentIndex] = Math.min(result.min[0 + componentIndex], buffer[index + componentIndex]);
612
- result.max[0 + componentIndex] = Math.max(result.max[0 + componentIndex], buffer[index + componentIndex]);
613
- }
614
- }
523
+ return result;
524
+ }
615
525
 
616
- return result;
617
- }
618
- }]);
619
- return GLTFScenegraph;
620
- }();
526
+ }
621
527
 
622
528
  exports.default = GLTFScenegraph;
623
529
  //# sourceMappingURL=gltf-scenegraph.js.map