@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
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
(
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
83
|
+
if (json.images) {
|
|
84
|
+
json.images = json.images.map((image, i) => this._resolveImage(image, i));
|
|
85
|
+
}
|
|
102
86
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
});
|
|
107
|
-
}
|
|
87
|
+
if (json.samplers) {
|
|
88
|
+
json.samplers = json.samplers.map((sampler, i) => this._resolveSampler(sampler, i));
|
|
89
|
+
}
|
|
108
90
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
});
|
|
113
|
-
}
|
|
91
|
+
if (json.textures) {
|
|
92
|
+
json.textures = json.textures.map((texture, i) => this._resolveTexture(texture, i));
|
|
93
|
+
}
|
|
114
94
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
});
|
|
119
|
-
}
|
|
95
|
+
if (json.accessors) {
|
|
96
|
+
json.accessors = json.accessors.map((accessor, i) => this._resolveAccessor(accessor, i));
|
|
97
|
+
}
|
|
120
98
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
});
|
|
125
|
-
}
|
|
99
|
+
if (json.materials) {
|
|
100
|
+
json.materials = json.materials.map((material, i) => this._resolveMaterial(material, i));
|
|
101
|
+
}
|
|
126
102
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
});
|
|
131
|
-
}
|
|
103
|
+
if (json.meshes) {
|
|
104
|
+
json.meshes = json.meshes.map((mesh, i) => this._resolveMesh(mesh, i));
|
|
105
|
+
}
|
|
132
106
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
});
|
|
137
|
-
}
|
|
107
|
+
if (json.nodes) {
|
|
108
|
+
json.nodes = json.nodes.map((node, i) => this._resolveNode(node, i));
|
|
109
|
+
}
|
|
138
110
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
});
|
|
143
|
-
}
|
|
111
|
+
if (json.skins) {
|
|
112
|
+
json.skins = json.skins.map((skin, i) => this._resolveSkin(skin, i));
|
|
113
|
+
}
|
|
144
114
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
});
|
|
149
|
-
}
|
|
115
|
+
if (json.scenes) {
|
|
116
|
+
json.scenes = json.scenes.map((scene, i) => this._resolveScene(scene, i));
|
|
117
|
+
}
|
|
150
118
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
119
|
+
if (json.scene !== undefined) {
|
|
120
|
+
json.scene = json.scenes[this.json.scene];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
156
123
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
});
|
|
161
|
-
}
|
|
124
|
+
getScene(index) {
|
|
125
|
+
return this._get('scenes', index);
|
|
126
|
+
}
|
|
162
127
|
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
132
|
+
getSkin(index) {
|
|
133
|
+
return this._get('skins', index);
|
|
134
|
+
}
|
|
235
135
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
136
|
+
getMesh(index) {
|
|
137
|
+
return this._get('meshes', index);
|
|
138
|
+
}
|
|
239
139
|
|
|
240
|
-
|
|
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
|
-
|
|
144
|
+
getAccessor(index) {
|
|
145
|
+
return this._get('accessors', index);
|
|
146
|
+
}
|
|
259
147
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
});
|
|
264
|
-
}
|
|
148
|
+
getCamera(index) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
265
151
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
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
|
-
|
|
281
|
-
|
|
282
|
-
|
|
156
|
+
getSampler(index) {
|
|
157
|
+
return this._get('samplers', index);
|
|
158
|
+
}
|
|
283
159
|
|
|
284
|
-
|
|
285
|
-
|
|
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
|
-
|
|
172
|
+
_get(array, index) {
|
|
173
|
+
if (typeof index === 'object') {
|
|
174
|
+
return index;
|
|
289
175
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
-
|
|
183
|
+
return object;
|
|
184
|
+
}
|
|
303
185
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
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
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
192
|
+
_resolveNode(node, index) {
|
|
193
|
+
node.id = node.id || "node-".concat(index);
|
|
313
194
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
195
|
+
if (node.children) {
|
|
196
|
+
node.children = node.children.map(child => this.getNode(child));
|
|
197
|
+
}
|
|
317
198
|
|
|
318
|
-
|
|
319
|
-
|
|
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
|
-
|
|
323
|
-
|
|
324
|
-
|
|
212
|
+
if (node.camera !== undefined) {
|
|
213
|
+
node.camera = this.getCamera(node.camera);
|
|
214
|
+
}
|
|
325
215
|
|
|
326
|
-
|
|
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
|
-
|
|
339
|
-
|
|
340
|
-
material.occlusionTexture.texture = this.getTexture(material.occlusionTexture.index);
|
|
341
|
-
}
|
|
220
|
+
return node;
|
|
221
|
+
}
|
|
342
222
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
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
|
-
|
|
349
|
-
|
|
350
|
-
}
|
|
229
|
+
_resolveMesh(mesh, index) {
|
|
230
|
+
mesh.id = mesh.id || "mesh-".concat(index);
|
|
351
231
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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
|
-
|
|
357
|
-
|
|
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 (
|
|
362
|
-
|
|
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
|
-
|
|
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
|
-
|
|
375
|
-
|
|
376
|
-
|
|
251
|
+
return primitive;
|
|
252
|
+
});
|
|
253
|
+
}
|
|
377
254
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
accessor.bytesPerElement = accessor.bytesPerComponent * accessor.components;
|
|
255
|
+
return mesh;
|
|
256
|
+
}
|
|
381
257
|
|
|
382
|
-
|
|
383
|
-
|
|
258
|
+
_resolveMaterial(material, index) {
|
|
259
|
+
material.id = material.id || "material-".concat(index);
|
|
384
260
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
261
|
+
if (material.normalTexture) {
|
|
262
|
+
material.normalTexture = { ...material.normalTexture
|
|
263
|
+
};
|
|
264
|
+
material.normalTexture.texture = this.getTexture(material.normalTexture.index);
|
|
265
|
+
}
|
|
388
266
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
267
|
+
if (material.occlusionTexture) {
|
|
268
|
+
material.occlustionTexture = { ...material.occlustionTexture
|
|
269
|
+
};
|
|
270
|
+
material.occlusionTexture.texture = this.getTexture(material.occlusionTexture.index);
|
|
271
|
+
}
|
|
393
272
|
|
|
394
|
-
|
|
273
|
+
if (material.emissiveTexture) {
|
|
274
|
+
material.emmisiveTexture = { ...material.emmisiveTexture
|
|
275
|
+
};
|
|
276
|
+
material.emissiveTexture.texture = this.getTexture(material.emissiveTexture.index);
|
|
395
277
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
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
|
-
|
|
411
|
-
|
|
283
|
+
if (material.pbrMetallicRoughness) {
|
|
284
|
+
material.pbrMetallicRoughness = { ...material.pbrMetallicRoughness
|
|
285
|
+
};
|
|
286
|
+
const mr = material.pbrMetallicRoughness;
|
|
412
287
|
|
|
413
|
-
|
|
414
|
-
|
|
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
|
-
|
|
294
|
+
if (mr.metallicRoughnessTexture) {
|
|
295
|
+
mr.metallicRoughnessTexture = { ...mr.metallicRoughnessTexture
|
|
296
|
+
};
|
|
297
|
+
mr.metallicRoughnessTexture.texture = this.getTexture(mr.metallicRoughnessTexture.index);
|
|
298
|
+
}
|
|
419
299
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
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
|
-
|
|
431
|
-
|
|
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
|
-
|
|
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
|
-
|
|
437
|
-
|
|
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
|
-
|
|
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
|
-
|
|
456
|
-
|
|
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
|
-
|
|
368
|
+
return image;
|
|
369
|
+
}
|
|
464
370
|
|
|
465
|
-
|
|
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
|
-
|
|
378
|
+
if ('byteOffset' in bufferView) {
|
|
379
|
+
byteOffset += bufferView.byteOffset;
|
|
468
380
|
}
|
|
469
|
-
|
|
470
|
-
|
|
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);
|