@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.
- package/dist/bundle.d.ts +1 -0
- package/dist/dist.min.js +1 -1
- package/dist/dist.min.js.map +1 -1
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/glb-loader.js +10 -33
- package/dist/es5/glb-loader.js.map +1 -1
- package/dist/es5/glb-writer.js +9 -8
- package/dist/es5/glb-writer.js.map +1 -1
- package/dist/es5/gltf-loader.js +14 -52
- 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 +6 -6
- package/dist/es5/lib/api/gltf-extensions.js +18 -106
- package/dist/es5/lib/api/gltf-extensions.js.map +1 -1
- package/dist/es5/lib/api/gltf-scenegraph.js +447 -541
- package/dist/es5/lib/api/gltf-scenegraph.js.map +1 -1
- package/dist/es5/lib/api/normalize-gltf-v1.js +150 -280
- package/dist/es5/lib/api/normalize-gltf-v1.js.map +1 -1
- package/dist/es5/lib/api/post-process-gltf.js +279 -354
- package/dist/es5/lib/api/post-process-gltf.js.map +1 -1
- package/dist/es5/lib/encoders/encode-glb.js +19 -22
- package/dist/es5/lib/encoders/encode-glb.js.map +1 -1
- package/dist/es5/lib/encoders/encode-gltf.js +3 -5
- package/dist/es5/lib/encoders/encode-gltf.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js +39 -104
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_texture_webp.js +12 -26
- package/dist/es5/lib/extensions/EXT_texture_webp.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_binary_gltf.js +12 -26
- package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +76 -261
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_texture_basisu.js +12 -26
- package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js +40 -104
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js +24 -69
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js +34 -90
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.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 +19 -21
- package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js.map +1 -1
- package/dist/es5/lib/gltf-utils/gltf-constants.js +7 -7
- 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 +34 -38
- package/dist/es5/lib/parsers/parse-glb.js.map +1 -1
- package/dist/es5/lib/parsers/parse-gltf.js +107 -249
- 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 +46 -197
- package/dist/es5/meshopt/meshopt-decoder.js.map +1 -1
- package/dist/es5/webp/webp.js +16 -84
- package/dist/es5/webp/webp.js.map +1 -1
- package/dist/esm/lib/api/gltf-scenegraph.js +1 -1
- package/dist/esm/lib/api/gltf-scenegraph.js.map +1 -1
- package/dist/esm/lib/api/normalize-gltf-v1.js +3 -3
- package/dist/esm/lib/api/normalize-gltf-v1.js.map +1 -1
- package/dist/esm/lib/api/post-process-gltf.js +12 -12
- package/dist/esm/lib/api/post-process-gltf.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js +1 -1
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_texture_webp.js +1 -1
- package/dist/esm/lib/extensions/EXT_texture_webp.js.map +1 -1
- package/dist/esm/lib/gltf-utils/resolve-url.js +1 -1
- package/dist/esm/lib/gltf-utils/resolve-url.js.map +1 -1
- package/dist/esm/lib/parsers/parse-glb.js +2 -6
- package/dist/esm/lib/parsers/parse-glb.js.map +1 -1
- package/dist/esm/lib/parsers/parse-gltf.js +19 -2
- package/dist/esm/lib/parsers/parse-gltf.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/esm/meshopt/meshopt-decoder.js +1 -1
- package/dist/esm/meshopt/meshopt-decoder.js.map +1 -1
- package/dist/esm/webp/webp.js +1 -1
- package/dist/esm/webp/webp.js.map +1 -1
- package/dist/glb-loader.d.ts +12 -0
- package/dist/glb-writer.d.ts +21 -0
- package/dist/gltf-loader.d.ts +17 -0
- package/dist/gltf-writer.d.ts +24 -0
- package/dist/index.d.ts +10 -0
- package/dist/lib/api/gltf-extensions.d.ts +25 -0
- package/dist/lib/api/gltf-scenegraph.d.ts +182 -0
- package/dist/lib/api/normalize-gltf-v1.d.ts +1 -0
- package/dist/lib/api/post-process-gltf.d.ts +1 -0
- package/dist/lib/encoders/encode-glb.d.ts +1 -0
- package/dist/lib/encoders/encode-gltf.d.ts +1 -0
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts +9 -0
- package/dist/lib/extensions/EXT_texture_webp.d.ts +11 -0
- package/dist/lib/extensions/KHR_binary_gltf.d.ts +6 -0
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +12 -0
- package/dist/lib/extensions/KHR_texture_basisu.d.ts +11 -0
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts +6 -0
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts +6 -0
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts +6 -0
- package/dist/lib/gltf-utils/get-typed-array.d.ts +2 -0
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts +5 -0
- package/dist/lib/gltf-utils/gltf-constants.d.ts +3 -0
- package/dist/lib/gltf-utils/gltf-utils.d.ts +7 -0
- package/dist/lib/gltf-utils/resolve-url.d.ts +1 -0
- package/dist/lib/parsers/parse-glb.d.ts +7 -0
- package/dist/lib/parsers/parse-gltf.d.ts +13 -0
- package/dist/lib/types/glb-types.d.ts +16 -0
- package/dist/lib/types/gltf-json-schema.d.ts +719 -0
- package/dist/lib/types/gltf-postprocessed-schema.d.ts +684 -0
- package/dist/lib/types/gltf-types.d.ts +9 -0
- package/dist/lib/utils/assert.d.ts +1 -0
- package/dist/lib/utils/version.d.ts +1 -0
- package/dist/meshopt/meshopt-decoder.d.ts +5 -0
- package/dist/webp/webp.d.ts +6 -0
- package/package.json +11 -7
- package/src/lib/parsers/parse-gltf.ts +17 -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
|
-
|
|
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
|
-
|
|
45
|
-
|
|
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:
|
|
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
|
-
(
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
51
|
+
getApplicationData(key) {
|
|
52
|
+
const data = this.json[key];
|
|
53
|
+
return data;
|
|
54
|
+
}
|
|
176
55
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
56
|
+
getExtraData(key) {
|
|
57
|
+
const extras = this.json.extras || {};
|
|
58
|
+
return extras[key];
|
|
59
|
+
}
|
|
180
60
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
return
|
|
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
|
-
|
|
274
|
-
|
|
275
|
-
|
|
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
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
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
|
-
|
|
303
|
-
|
|
304
|
-
|
|
227
|
+
registerRequiredExtension(extensionName) {
|
|
228
|
+
this.registerUsedExtension(extensionName);
|
|
229
|
+
this.json.extensionsRequired = this.json.extensionsRequired || [];
|
|
305
230
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
231
|
+
if (!this.json.extensionsRequired.find(ext => ext === extensionName)) {
|
|
232
|
+
this.json.extensionsRequired.push(extensionName);
|
|
309
233
|
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
removeExtension(extensionName) {
|
|
237
|
+
if (this.json.extensionsRequired) {
|
|
238
|
+
this._removeStringFromArray(this.json.extensionsRequired, extensionName);
|
|
314
239
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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
|
-
|
|
340
|
-
|
|
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
|
-
|
|
367
|
-
|
|
368
|
-
|
|
250
|
+
setDefaultScene(sceneIndex) {
|
|
251
|
+
this.json.scene = sceneIndex;
|
|
252
|
+
}
|
|
369
253
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
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
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
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
|
-
|
|
422
|
-
|
|
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
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
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
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
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
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
this.json.
|
|
476
|
-
|
|
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
|
-
|
|
504
|
-
|
|
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
|
-
|
|
507
|
-
byteLength: totalByteLength
|
|
508
|
-
}];
|
|
447
|
+
found = false;
|
|
509
448
|
}
|
|
510
|
-
|
|
511
|
-
this.gltf.binary = arrayBuffer;
|
|
512
|
-
this.sourceBuffers = [arrayBuffer];
|
|
513
449
|
}
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
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
|
-
|
|
536
|
-
|
|
464
|
+
return result;
|
|
465
|
+
}
|
|
537
466
|
|
|
538
|
-
|
|
467
|
+
_addIndices(indices) {
|
|
468
|
+
return this.addBinaryBuffer(indices, {
|
|
469
|
+
size: 1
|
|
470
|
+
});
|
|
471
|
+
}
|
|
539
472
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
473
|
+
_getGltfAttributeName(attributeName) {
|
|
474
|
+
switch (attributeName.toLowerCase()) {
|
|
475
|
+
case 'position':
|
|
476
|
+
case 'positions':
|
|
477
|
+
case 'vertices':
|
|
478
|
+
return 'POSITION';
|
|
543
479
|
|
|
544
|
-
|
|
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
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
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
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
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
|
-
|
|
591
|
-
|
|
592
|
-
|
|
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
|
-
|
|
610
|
-
|
|
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
|
-
|
|
617
|
-
}
|
|
618
|
-
}]);
|
|
619
|
-
return GLTFScenegraph;
|
|
620
|
-
}();
|
|
526
|
+
}
|
|
621
527
|
|
|
622
528
|
exports.default = GLTFScenegraph;
|
|
623
529
|
//# sourceMappingURL=gltf-scenegraph.js.map
|