@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.
- package/dist/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +4518 -0
- 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 +154 -279
- package/dist/es5/lib/api/normalize-gltf-v1.js.map +1 -1
- package/dist/es5/lib/api/post-process-gltf.js +301 -349
- 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/assert.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 +9 -6
- package/dist/esm/lib/api/normalize-gltf-v1.js.map +1 -1
- package/dist/esm/lib/api/post-process-gltf.js +42 -15
- package/dist/esm/lib/api/post-process-gltf.js.map +1 -1
- package/dist/esm/lib/encoders/encode-glb.js.map +1 -1
- package/dist/esm/lib/encoders/encode-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/extensions/KHR_texture_basisu.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/assert.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/esm/lib/utils/version.js.map +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 +13 -0
- package/dist/glb-loader.d.ts.map +1 -0
- package/dist/glb-loader.js +39 -0
- package/dist/glb-writer.d.ts +22 -0
- package/dist/glb-writer.d.ts.map +1 -0
- package/dist/glb-writer.js +37 -0
- package/dist/gltf-loader.d.ts +18 -0
- package/dist/gltf-loader.d.ts.map +1 -0
- package/dist/gltf-loader.js +50 -0
- package/dist/gltf-writer.d.ts +25 -0
- package/dist/gltf-writer.d.ts.map +1 -0
- package/dist/gltf-writer.js +32 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/lib/api/gltf-extensions.d.ts +26 -0
- package/dist/lib/api/gltf-extensions.d.ts.map +1 -0
- package/dist/lib/api/gltf-extensions.js +75 -0
- package/dist/lib/api/gltf-scenegraph.d.ts +183 -0
- package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -0
- package/dist/lib/api/gltf-scenegraph.js +553 -0
- package/dist/lib/api/normalize-gltf-v1.d.ts +2 -0
- package/dist/lib/api/normalize-gltf-v1.d.ts.map +1 -0
- package/dist/lib/api/normalize-gltf-v1.js +295 -0
- package/dist/lib/api/post-process-gltf.d.ts +2 -0
- package/dist/lib/api/post-process-gltf.d.ts.map +1 -0
- package/dist/lib/api/post-process-gltf.js +367 -0
- package/dist/lib/encoders/encode-glb.d.ts +2 -0
- package/dist/lib/encoders/encode-glb.d.ts.map +1 -0
- package/dist/lib/encoders/encode-glb.js +61 -0
- package/dist/lib/encoders/encode-gltf.d.ts +2 -0
- package/dist/lib/encoders/encode-gltf.d.ts.map +1 -0
- package/dist/lib/encoders/encode-gltf.js +27 -0
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts +10 -0
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -0
- package/dist/lib/extensions/EXT_meshopt_compression.js +54 -0
- package/dist/lib/extensions/EXT_texture_webp.d.ts +12 -0
- package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -0
- package/dist/lib/extensions/EXT_texture_webp.js +38 -0
- package/dist/lib/extensions/KHR_binary_gltf.d.ts +7 -0
- package/dist/lib/extensions/KHR_binary_gltf.d.ts.map +1 -0
- package/dist/lib/extensions/KHR_binary_gltf.js +42 -0
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +13 -0
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -0
- package/dist/lib/extensions/KHR_draco_mesh_compression.js +141 -0
- package/dist/lib/extensions/KHR_texture_basisu.d.ts +12 -0
- package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -0
- package/dist/lib/extensions/KHR_texture_basisu.js +31 -0
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts +7 -0
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts.map +1 -0
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +62 -0
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts +7 -0
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts.map +1 -0
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +47 -0
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts +7 -0
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts.map +1 -0
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +81 -0
- package/dist/lib/gltf-utils/get-typed-array.d.ts +3 -0
- package/dist/lib/gltf-utils/get-typed-array.d.ts.map +1 -0
- package/dist/lib/gltf-utils/get-typed-array.js +41 -0
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts +6 -0
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts.map +1 -0
- package/dist/lib/gltf-utils/gltf-attribute-utils.js +73 -0
- package/dist/lib/gltf-utils/gltf-constants.d.ts +4 -0
- package/dist/lib/gltf-utils/gltf-constants.d.ts.map +1 -0
- package/dist/lib/gltf-utils/gltf-constants.js +43 -0
- package/dist/lib/gltf-utils/gltf-utils.d.ts +8 -0
- package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -0
- package/dist/lib/gltf-utils/gltf-utils.js +63 -0
- package/dist/lib/gltf-utils/resolve-url.d.ts +2 -0
- package/dist/lib/gltf-utils/resolve-url.d.ts.map +1 -0
- package/dist/lib/gltf-utils/resolve-url.js +18 -0
- package/dist/lib/parsers/parse-glb.d.ts +8 -0
- package/dist/lib/parsers/parse-glb.d.ts.map +1 -0
- package/dist/lib/parsers/parse-glb.js +141 -0
- package/dist/lib/parsers/parse-gltf.d.ts +14 -0
- package/dist/lib/parsers/parse-gltf.d.ts.map +1 -0
- package/dist/lib/parsers/parse-gltf.js +189 -0
- package/dist/lib/types/glb-types.d.ts +17 -0
- package/dist/lib/types/glb-types.d.ts.map +1 -0
- package/dist/lib/types/glb-types.js +2 -0
- package/dist/lib/types/gltf-json-schema.d.ts +720 -0
- package/dist/lib/types/gltf-json-schema.d.ts.map +1 -0
- package/dist/lib/types/gltf-json-schema.js +4 -0
- package/dist/lib/types/gltf-postprocessed-schema.d.ts +685 -0
- package/dist/lib/types/gltf-postprocessed-schema.d.ts.map +1 -0
- package/dist/lib/types/gltf-postprocessed-schema.js +4 -0
- package/dist/lib/types/gltf-types.d.ts +10 -0
- package/dist/lib/types/gltf-types.d.ts.map +1 -0
- package/dist/lib/types/gltf-types.js +3 -0
- package/dist/lib/utils/assert.d.ts +2 -0
- package/dist/lib/utils/assert.d.ts.map +1 -0
- package/dist/lib/utils/assert.js +12 -0
- package/dist/lib/utils/version.d.ts +2 -0
- package/dist/lib/utils/version.d.ts.map +1 -0
- package/dist/lib/utils/version.js +7 -0
- package/dist/meshopt/meshopt-decoder.d.ts +6 -0
- package/dist/meshopt/meshopt-decoder.d.ts.map +1 -0
- package/dist/meshopt/meshopt-decoder.js +118 -0
- package/dist/webp/webp.d.ts +7 -0
- package/dist/webp/webp.d.ts.map +1 -0
- package/dist/webp/webp.js +38 -0
- package/package.json +11 -8
- package/src/lib/api/{normalize-gltf-v1.js → normalize-gltf-v1.ts} +18 -16
- package/src/lib/api/{post-process-gltf.js → post-process-gltf.ts} +41 -3
- package/src/lib/encoders/{encode-glb.js → encode-glb.ts} +0 -0
- package/src/lib/encoders/{encode-gltf.js → encode-gltf.ts} +0 -0
- package/src/lib/extensions/KHR_texture_basisu.ts +2 -2
- package/src/lib/parsers/parse-gltf.ts +17 -1
- package/src/lib/utils/{assert.js → assert.ts} +1 -1
- package/src/lib/utils/{version.js → version.ts} +0 -0
- package/dist/dist.min.js +0 -2
- package/dist/dist.min.js.map +0 -1
|
@@ -2,30 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
|
|
5
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.normalizeGLTFV1 = normalizeGLTFV1;
|
|
11
9
|
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
11
|
|
|
16
12
|
var KHR_binary_glTF = _interopRequireWildcard(require("../extensions/KHR_binary_gltf"));
|
|
17
13
|
|
|
18
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function
|
|
19
|
-
|
|
20
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
-
|
|
22
|
-
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; } } }; }
|
|
14
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
23
15
|
|
|
24
|
-
function
|
|
16
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
17
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var GLTF_ARRAYS = {
|
|
18
|
+
const GLTF_ARRAYS = {
|
|
29
19
|
accessors: 'accessor',
|
|
30
20
|
animations: 'animation',
|
|
31
21
|
buffers: 'buffer',
|
|
@@ -39,7 +29,7 @@ var GLTF_ARRAYS = {
|
|
|
39
29
|
skins: 'skin',
|
|
40
30
|
textures: 'texture'
|
|
41
31
|
};
|
|
42
|
-
|
|
32
|
+
const GLTF_KEYS = {
|
|
43
33
|
accessor: 'accessors',
|
|
44
34
|
animations: 'animation',
|
|
45
35
|
buffer: 'buffers',
|
|
@@ -54,10 +44,9 @@ var GLTF_KEYS = {
|
|
|
54
44
|
texture: 'textures'
|
|
55
45
|
};
|
|
56
46
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
(0,
|
|
60
|
-
this.idToIndexMap = {
|
|
47
|
+
class GLTFV1Normalizer {
|
|
48
|
+
constructor() {
|
|
49
|
+
(0, _defineProperty2.default)(this, "idToIndexMap", {
|
|
61
50
|
animations: {},
|
|
62
51
|
accessors: {},
|
|
63
52
|
buffers: {},
|
|
@@ -70,320 +59,206 @@ var GLTFV1Normalizer = function () {
|
|
|
70
59
|
scenes: {},
|
|
71
60
|
skins: {},
|
|
72
61
|
textures: {}
|
|
73
|
-
};
|
|
62
|
+
});
|
|
63
|
+
(0, _defineProperty2.default)(this, "json", void 0);
|
|
74
64
|
}
|
|
75
65
|
|
|
76
|
-
(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this.json = gltf.json;
|
|
80
|
-
var json = gltf.json;
|
|
81
|
-
|
|
82
|
-
switch (json.asset && json.asset.version) {
|
|
83
|
-
case '2.0':
|
|
84
|
-
return;
|
|
66
|
+
normalize(gltf, options) {
|
|
67
|
+
this.json = gltf.json;
|
|
68
|
+
const json = gltf.json;
|
|
85
69
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
70
|
+
switch (json.asset && json.asset.version) {
|
|
71
|
+
case '2.0':
|
|
72
|
+
return;
|
|
89
73
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
74
|
+
case undefined:
|
|
75
|
+
case '1.0':
|
|
76
|
+
break;
|
|
94
77
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
78
|
+
default:
|
|
79
|
+
console.warn("glTF: Unknown version ".concat(json.asset.version));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
98
82
|
|
|
99
|
-
|
|
83
|
+
if (!options.normalize) {
|
|
84
|
+
throw new Error('glTF v1 is not supported.');
|
|
85
|
+
}
|
|
100
86
|
|
|
101
|
-
|
|
87
|
+
console.warn('Converting glTF v1 to glTF v2 format. This is experimental and may fail.');
|
|
102
88
|
|
|
103
|
-
|
|
89
|
+
this._addAsset(json);
|
|
104
90
|
|
|
105
|
-
|
|
91
|
+
this._convertTopLevelObjectsToArrays(json);
|
|
106
92
|
|
|
107
|
-
|
|
93
|
+
KHR_binary_glTF.preprocess(gltf);
|
|
108
94
|
|
|
109
|
-
|
|
95
|
+
this._convertObjectIdsToArrayIndices(json);
|
|
110
96
|
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
}, {
|
|
114
|
-
key: "_addAsset",
|
|
115
|
-
value: function _addAsset(json) {
|
|
116
|
-
json.asset = json.asset || {};
|
|
117
|
-
json.asset.version = '2.0';
|
|
118
|
-
json.asset.generator = json.asset.generator || 'Normalized to glTF 2.0 by loaders.gl';
|
|
119
|
-
}
|
|
120
|
-
}, {
|
|
121
|
-
key: "_convertTopLevelObjectsToArrays",
|
|
122
|
-
value: function _convertTopLevelObjectsToArrays(json) {
|
|
123
|
-
for (var arrayName in GLTF_ARRAYS) {
|
|
124
|
-
this._convertTopLevelObjectToArray(json, arrayName);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}, {
|
|
128
|
-
key: "_convertTopLevelObjectToArray",
|
|
129
|
-
value: function _convertTopLevelObjectToArray(json, mapName) {
|
|
130
|
-
var objectMap = json[mapName];
|
|
97
|
+
this._updateObjects(json);
|
|
131
98
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
99
|
+
this._updateMaterial(json);
|
|
100
|
+
}
|
|
135
101
|
|
|
136
|
-
|
|
102
|
+
_addAsset(json) {
|
|
103
|
+
json.asset = json.asset || {};
|
|
104
|
+
json.asset.version = '2.0';
|
|
105
|
+
json.asset.generator = json.asset.generator || 'Normalized to glTF 2.0 by loaders.gl';
|
|
106
|
+
}
|
|
137
107
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
var index = json[mapName].length;
|
|
142
|
-
json[mapName].push(object);
|
|
143
|
-
this.idToIndexMap[mapName][id] = index;
|
|
144
|
-
}
|
|
108
|
+
_convertTopLevelObjectsToArrays(json) {
|
|
109
|
+
for (const arrayName in GLTF_ARRAYS) {
|
|
110
|
+
this._convertTopLevelObjectToArray(json, arrayName);
|
|
145
111
|
}
|
|
146
|
-
}
|
|
147
|
-
key: "_convertObjectIdsToArrayIndices",
|
|
148
|
-
value: function _convertObjectIdsToArrayIndices(json) {
|
|
149
|
-
for (var arrayName in GLTF_ARRAYS) {
|
|
150
|
-
this._convertIdsToIndices(json, arrayName);
|
|
151
|
-
}
|
|
112
|
+
}
|
|
152
113
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
114
|
+
_convertTopLevelObjectToArray(json, mapName) {
|
|
115
|
+
const objectMap = json[mapName];
|
|
156
116
|
|
|
157
|
-
|
|
158
|
-
|
|
117
|
+
if (!objectMap || Array.isArray(objectMap)) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
159
120
|
|
|
160
|
-
|
|
161
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
162
|
-
var texture = _step.value;
|
|
121
|
+
json[mapName] = [];
|
|
163
122
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
123
|
+
for (const id in objectMap) {
|
|
124
|
+
const object = objectMap[id];
|
|
125
|
+
object.id = object.id || id;
|
|
126
|
+
const index = json[mapName].length;
|
|
127
|
+
json[mapName].push(object);
|
|
128
|
+
this.idToIndexMap[mapName][id] = index;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
171
131
|
|
|
172
|
-
|
|
173
|
-
|
|
132
|
+
_convertObjectIdsToArrayIndices(json) {
|
|
133
|
+
for (const arrayName in GLTF_ARRAYS) {
|
|
134
|
+
this._convertIdsToIndices(json, arrayName);
|
|
135
|
+
}
|
|
174
136
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
137
|
+
if ('scene' in json) {
|
|
138
|
+
json.scene = this._convertIdToIndex(json.scene, 'scene');
|
|
139
|
+
}
|
|
178
140
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
_iterator2.e(err);
|
|
183
|
-
} finally {
|
|
184
|
-
_iterator2.f();
|
|
185
|
-
}
|
|
141
|
+
for (const texture of json.textures) {
|
|
142
|
+
this._convertTextureIds(texture);
|
|
143
|
+
}
|
|
186
144
|
|
|
187
|
-
|
|
188
|
-
|
|
145
|
+
for (const mesh of json.meshes) {
|
|
146
|
+
this._convertMeshIds(mesh);
|
|
147
|
+
}
|
|
189
148
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
149
|
+
for (const node of json.nodes) {
|
|
150
|
+
this._convertNodeIds(node);
|
|
151
|
+
}
|
|
193
152
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
} finally {
|
|
199
|
-
_iterator3.f();
|
|
200
|
-
}
|
|
153
|
+
for (const node of json.scenes) {
|
|
154
|
+
this._convertSceneIds(node);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
201
157
|
|
|
202
|
-
|
|
203
|
-
|
|
158
|
+
_convertTextureIds(texture) {
|
|
159
|
+
if (texture.source) {
|
|
160
|
+
texture.source = this._convertIdToIndex(texture.source, 'image');
|
|
161
|
+
}
|
|
162
|
+
}
|
|
204
163
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
164
|
+
_convertMeshIds(mesh) {
|
|
165
|
+
for (const primitive of mesh.primitives) {
|
|
166
|
+
const {
|
|
167
|
+
attributes,
|
|
168
|
+
indices,
|
|
169
|
+
material
|
|
170
|
+
} = primitive;
|
|
208
171
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
} catch (err) {
|
|
212
|
-
_iterator4.e(err);
|
|
213
|
-
} finally {
|
|
214
|
-
_iterator4.f();
|
|
172
|
+
for (const attributeName in attributes) {
|
|
173
|
+
attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], 'accessor');
|
|
215
174
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
value: function _convertTextureIds(texture) {
|
|
220
|
-
if (texture.source) {
|
|
221
|
-
texture.source = this._convertIdToIndex(texture.source, 'image');
|
|
175
|
+
|
|
176
|
+
if (indices) {
|
|
177
|
+
primitive.indices = this._convertIdToIndex(indices, 'accessor');
|
|
222
178
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
value: function _convertMeshIds(mesh) {
|
|
227
|
-
var _iterator5 = _createForOfIteratorHelper(mesh.primitives),
|
|
228
|
-
_step5;
|
|
229
|
-
|
|
230
|
-
try {
|
|
231
|
-
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
232
|
-
var primitive = _step5.value;
|
|
233
|
-
var attributes = primitive.attributes,
|
|
234
|
-
indices = primitive.indices,
|
|
235
|
-
material = primitive.material;
|
|
236
|
-
|
|
237
|
-
for (var attributeName in attributes) {
|
|
238
|
-
attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], 'accessor');
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
if (indices) {
|
|
242
|
-
primitive.indices = this._convertIdToIndex(indices, 'accessor');
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
if (material) {
|
|
246
|
-
primitive.material = this._convertIdToIndex(material, 'material');
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
} catch (err) {
|
|
250
|
-
_iterator5.e(err);
|
|
251
|
-
} finally {
|
|
252
|
-
_iterator5.f();
|
|
179
|
+
|
|
180
|
+
if (material) {
|
|
181
|
+
primitive.material = this._convertIdToIndex(material, 'material');
|
|
253
182
|
}
|
|
254
183
|
}
|
|
255
|
-
}
|
|
256
|
-
key: "_convertNodeIds",
|
|
257
|
-
value: function _convertNodeIds(node) {
|
|
258
|
-
var _this = this;
|
|
259
|
-
|
|
260
|
-
if (node.children) {
|
|
261
|
-
node.children = node.children.map(function (child) {
|
|
262
|
-
return _this._convertIdToIndex(child, 'node');
|
|
263
|
-
});
|
|
264
|
-
}
|
|
184
|
+
}
|
|
265
185
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
});
|
|
270
|
-
}
|
|
186
|
+
_convertNodeIds(node) {
|
|
187
|
+
if (node.children) {
|
|
188
|
+
node.children = node.children.map(child => this._convertIdToIndex(child, 'node'));
|
|
271
189
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
var _this2 = this;
|
|
276
|
-
|
|
277
|
-
if (scene.nodes) {
|
|
278
|
-
scene.nodes = scene.nodes.map(function (node) {
|
|
279
|
-
return _this2._convertIdToIndex(node, 'node');
|
|
280
|
-
});
|
|
281
|
-
}
|
|
190
|
+
|
|
191
|
+
if (node.meshes) {
|
|
192
|
+
node.meshes = node.meshes.map(mesh => this._convertIdToIndex(mesh, 'mesh'));
|
|
282
193
|
}
|
|
283
|
-
}
|
|
284
|
-
key: "_convertIdsToIndices",
|
|
285
|
-
value: function _convertIdsToIndices(json, topLevelArrayName) {
|
|
286
|
-
if (!json[topLevelArrayName]) {
|
|
287
|
-
console.warn("gltf v1: json doesn't contain attribute ".concat(topLevelArrayName));
|
|
288
|
-
json[topLevelArrayName] = [];
|
|
289
|
-
}
|
|
194
|
+
}
|
|
290
195
|
|
|
291
|
-
|
|
292
|
-
|
|
196
|
+
_convertSceneIds(scene) {
|
|
197
|
+
if (scene.nodes) {
|
|
198
|
+
scene.nodes = scene.nodes.map(node => this._convertIdToIndex(node, 'node'));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
293
201
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
202
|
+
_convertIdsToIndices(json, topLevelArrayName) {
|
|
203
|
+
if (!json[topLevelArrayName]) {
|
|
204
|
+
console.warn("gltf v1: json doesn't contain attribute ".concat(topLevelArrayName));
|
|
205
|
+
json[topLevelArrayName] = [];
|
|
206
|
+
}
|
|
297
207
|
|
|
298
|
-
|
|
299
|
-
|
|
208
|
+
for (const object of json[topLevelArrayName]) {
|
|
209
|
+
for (const key in object) {
|
|
210
|
+
const id = object[key];
|
|
300
211
|
|
|
301
|
-
|
|
212
|
+
const index = this._convertIdToIndex(id, key);
|
|
302
213
|
|
|
303
|
-
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
} catch (err) {
|
|
307
|
-
_iterator6.e(err);
|
|
308
|
-
} finally {
|
|
309
|
-
_iterator6.f();
|
|
214
|
+
object[key] = index;
|
|
310
215
|
}
|
|
311
216
|
}
|
|
312
|
-
}
|
|
313
|
-
key: "_convertIdToIndex",
|
|
314
|
-
value: function _convertIdToIndex(id, key) {
|
|
315
|
-
var arrayName = GLTF_KEYS[key];
|
|
217
|
+
}
|
|
316
218
|
|
|
317
|
-
|
|
318
|
-
|
|
219
|
+
_convertIdToIndex(id, key) {
|
|
220
|
+
const arrayName = GLTF_KEYS[key];
|
|
319
221
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}
|
|
222
|
+
if (arrayName in this.idToIndexMap) {
|
|
223
|
+
const index = this.idToIndexMap[arrayName][id];
|
|
323
224
|
|
|
324
|
-
|
|
225
|
+
if (!Number.isFinite(index)) {
|
|
226
|
+
throw new Error("gltf v1: failed to resolve ".concat(key, " with id ").concat(id));
|
|
325
227
|
}
|
|
326
228
|
|
|
327
|
-
return
|
|
229
|
+
return index;
|
|
328
230
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
337
|
-
var buffer = _step7.value;
|
|
338
|
-
delete buffer.type;
|
|
339
|
-
}
|
|
340
|
-
} catch (err) {
|
|
341
|
-
_iterator7.e(err);
|
|
342
|
-
} finally {
|
|
343
|
-
_iterator7.f();
|
|
344
|
-
}
|
|
231
|
+
|
|
232
|
+
return id;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
_updateObjects(json) {
|
|
236
|
+
for (const buffer of this.json.buffers) {
|
|
237
|
+
delete buffer.type;
|
|
345
238
|
}
|
|
346
|
-
}
|
|
347
|
-
key: "_updateMaterial",
|
|
348
|
-
value: function _updateMaterial(json) {
|
|
349
|
-
var _iterator8 = _createForOfIteratorHelper(json.materials),
|
|
350
|
-
_step8;
|
|
351
|
-
|
|
352
|
-
try {
|
|
353
|
-
var _loop = function _loop() {
|
|
354
|
-
var material = _step8.value;
|
|
355
|
-
material.pbrMetallicRoughness = {
|
|
356
|
-
baseColorFactor: [1, 1, 1, 1],
|
|
357
|
-
metallicFactor: 1,
|
|
358
|
-
roughnessFactor: 1
|
|
359
|
-
};
|
|
360
|
-
var textureId = material.values && material.values.tex;
|
|
361
|
-
var textureIndex = json.textures.findIndex(function (texture) {
|
|
362
|
-
return texture.id === textureId;
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
if (textureIndex !== -1) {
|
|
366
|
-
material.pbrMetallicRoughness.baseColorTexture = {
|
|
367
|
-
index: textureIndex
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
};
|
|
239
|
+
}
|
|
371
240
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
241
|
+
_updateMaterial(json) {
|
|
242
|
+
for (const material of json.materials) {
|
|
243
|
+
material.pbrMetallicRoughness = {
|
|
244
|
+
baseColorFactor: [1, 1, 1, 1],
|
|
245
|
+
metallicFactor: 1,
|
|
246
|
+
roughnessFactor: 1
|
|
247
|
+
};
|
|
248
|
+
const textureId = material.values && material.values.tex;
|
|
249
|
+
const textureIndex = json.textures.findIndex(texture => texture.id === textureId);
|
|
250
|
+
|
|
251
|
+
if (textureIndex !== -1) {
|
|
252
|
+
material.pbrMetallicRoughness.baseColorTexture = {
|
|
253
|
+
index: textureIndex
|
|
254
|
+
};
|
|
379
255
|
}
|
|
380
256
|
}
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
}
|
|
384
260
|
|
|
385
|
-
function normalizeGLTFV1(gltf) {
|
|
386
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
261
|
+
function normalizeGLTFV1(gltf, options = {}) {
|
|
387
262
|
return new GLTFV1Normalizer().normalize(gltf, options);
|
|
388
263
|
}
|
|
389
264
|
//# sourceMappingURL=normalize-gltf-v1.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/api/normalize-gltf-v1.js"],"names":["GLTF_ARRAYS","accessors","animations","buffers","bufferViews","images","materials","meshes","nodes","samplers","scenes","skins","textures","GLTF_KEYS","accessor","buffer","bufferView","image","material","mesh","node","sampler","scene","skin","texture","GLTFV1Normalizer","gltf","idToIndexMap","options","json","asset","version","undefined","console","warn","normalize","Error","_addAsset","_convertTopLevelObjectsToArrays","KHR_binary_glTF","preprocess","_convertObjectIdsToArrayIndices","_updateObjects","_updateMaterial","generator","arrayName","_convertTopLevelObjectToArray","mapName","objectMap","Array","isArray","id","object","index","length","push","_convertIdsToIndices","_convertIdToIndex","_convertTextureIds","_convertMeshIds","_convertNodeIds","_convertSceneIds","source","primitives","primitive","attributes","indices","attributeName","children","map","child","topLevelArrayName","key","Number","isFinite","type","pbrMetallicRoughness","baseColorFactor","metallicFactor","roughnessFactor","textureId","values","tex","textureIndex","findIndex","ba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C;AAMA,cAAMC,SAAS,GAAG9D,QAAQ,CAAC+D,MAAT,IAAmB/D,QAAQ,CAAC+D,MAAT,CAAgBC,GAArD;AACA,cAAMC,YAAY,GAAGtD,IAAI,CAACjB,QAAL,CAAcwE,SAAd,CAAwB,UAAC5D,OAAD;AAAA,mBAAaA,OAAO,CAAC2B,EAAR,KAAe6B,SAA5B;AAAA,WAAxB,CAArB;;AACA,cAAIG,YAAY,KAAK,CAAC,CAAtB,EAAyB;AACvBjE,YAAAA,QAAQ,CAAC0D,oBAAT,CAA8BS,gBAA9B,GAAiD;AAAChC,cAAAA,KAAK,EAAE8B;AAAR,aAAjD;AACD;AAZiB;;AACpB,+DAAuC;AAAA;AAYtC;AAbmB;AAAA;AAAA;AAAA;AAAA;AAcrB;;;;;AAGI,SAASG,eAAT,CAAyB5D,IAAzB,EAA6C;AAAA,MAAdE,OAAc,uEAAJ,EAAI;AAClD,SAAO,IAAIH,gBAAJ,GAAuBU,SAAvB,CAAiCT,IAAjC,EAAuCE,OAAvC,CAAP;AACD","sourcesContent":["/* eslint-disable camelcase */\nimport * as KHR_binary_glTF from '../extensions/KHR_binary_gltf';\n\n// Binary format changes (mainly implemented by GLBLoader)\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF\n\n// JSON format changes:\n// https://github.com/khronosgroup/gltf/issues/605\n\n// - [x] Top-level JSON objects are arrays now\n// - [ ] Removed indirection from animation: sampler now refers directly to accessors, #712\n// - [ ] material.parameter.value and technique.parameter.value must be an array, #690\n// - [ ] Node can have only one mesh #821\n// - [ ] Added reqs on JSON encoding\n// - [ ] Added reqs on binary data alignment #802 (comment)\n\n// Additions:\n// - [ ] Added accessor.normalized, #691, #706\n// - [ ] Added glExtensionsUsed property and 5125 (UNSIGNED_INT) accessor.componentType value, #619\n// - [ ] Added extensionsRequired property, #720, #721\n// - [ ] Added \"STEP\" as valid animation.sampler.interpolation value, #712\n\n// Removals:\n// - [x] Removed buffer.type, #786, #629\n// - [ ] Removed revision number from profile.version, #709\n// - [ ] Removed technique.functions.scissor and removed 3089 (SCISSOR_TEST) as a valid value for technique.states.enable, #681\n// - [ ] Techniques, programs, and shaders were moved out to KHR_technique_webgl extension.\n\n// Other edits:\n// - [x] asset is now required, #642\n// - [ ] buffer.byteLength and bufferView.byteLength are now required, #560.\n// - [ ] accessor.min and accessor.max are now required, #593, and clarified that the JSON value and binary data must be the same, #628.\n// - [ ] Clarified animation.sampler and animation.channel restrictions, #712\n// - [ ] skin.inverseBindMatrices is now optional, #461.\n// - [ ] Attribute parameters can't have a value defined in the technique or parameter, #563 (comment).\n// - [ ] Only TEXCOORD and COLOR attribute semantics can be written in the form [semantic]_[set_index], #563 (comment).\n// - [ ] TEXCOORD and COLOR attribute semantics must be written in the form [semantic]_[set_index], e.g., just TEXCOORD should be TEXCOORD_0, and just COLOR should be COLOR_0, #649\n// - [ ] camera.perspective.aspectRatio and camera.perspective.yfov must now be > 0, not >= 0, #563 (comment).\n// - [ ] Application-specific parameter semantics must start with an underscore, e.g., _TEMPERATURE and _SIMULATION_TIME, #563 (comment).\n// - [ ] Properties in technique.parameters must be defined in technique.uniforms or technique.attributes,\n\n// #563 (comment).\n// - [ ] technique.parameter.count can only be defined when the semantic is JOINTMATRIX or an application-specific semantic is used. It can never be defined for attribute parameters; only uniforms, d2f6945\n// - [ ] technique.parameter.semantic is required when the parameter is an attribute, 28e113d\n// - [ ] Mesh-only models are allowed, e.g., without materials, #642\n// - [ ] Skeleton hierarchies (nodes containing jointName) must be separated from non-skeleton hierarchies., #647\n// - [ ] technique.states.functions.blendColor and technique.states.functions.depthRange parameters now must match WebGL function min/max, #707\n\nconst GLTF_ARRAYS = {\n accessors: 'accessor',\n animations: 'animation',\n buffers: 'buffer',\n bufferViews: 'bufferView',\n images: 'image',\n materials: 'material',\n meshes: 'mesh',\n nodes: 'node',\n samplers: 'sampler',\n scenes: 'scene',\n skins: 'skin',\n textures: 'texture'\n};\n\nconst GLTF_KEYS = {\n accessor: 'accessors',\n animations: 'animation',\n buffer: 'buffers',\n bufferView: 'bufferViews',\n image: 'images',\n material: 'materials',\n mesh: 'meshes',\n node: 'nodes',\n sampler: 'samplers',\n scene: 'scenes',\n skin: 'skins',\n texture: 'textures'\n};\n\n/**\n * Converts (normalizes) glTF v1 to v2\n */\nclass GLTFV1Normalizer {\n constructor(gltf) {\n this.idToIndexMap = {\n animations: {},\n accessors: {},\n buffers: {},\n bufferViews: {},\n images: {},\n materials: {},\n meshes: {},\n nodes: {},\n samplers: {},\n scenes: {},\n skins: {},\n textures: {}\n };\n }\n\n /**\n * Convert (normalize) glTF < 2.0 to glTF 2.0\n * @param gltf - object with json and binChunks\n * @param options\n * @param options normalize Whether to actually normalize\n */\n normalize(gltf, options) {\n this.json = gltf.json;\n const json = gltf.json;\n\n // Check version\n switch (json.asset && json.asset.version) {\n // We are converting to v2 format. Return if there is nothing to do\n case '2.0':\n return;\n\n // This class is written to convert 1.0\n case undefined:\n case '1.0':\n break;\n\n default:\n // eslint-disable-next-line no-undef, no-console\n console.warn(`glTF: Unknown version ${json.asset.version}`);\n return;\n }\n\n if (!options.normalize) {\n // We are still missing a few conversion tricks, remove once addressed\n throw new Error('glTF v1 is not supported.');\n }\n\n // eslint-disable-next-line no-undef, no-console\n console.warn('Converting glTF v1 to glTF v2 format. This is experimental and may fail.');\n\n this._addAsset(json);\n\n // In glTF2 top-level fields are Arrays not Object maps\n this._convertTopLevelObjectsToArrays(json);\n\n // Extract bufferView indices for images\n // (this extension needs to be invoked early in the normalization process)\n // TODO can this be handled by standard extension processing instead of called explicitly?\n KHR_binary_glTF.preprocess(gltf);\n\n // Convert object references from ids to indices\n this._convertObjectIdsToArrayIndices(json);\n\n this._updateObjects(json);\n\n this._updateMaterial(json);\n }\n\n // asset is now required, #642 https://github.com/KhronosGroup/glTF/issues/639\n _addAsset(json) {\n json.asset = json.asset || {};\n // We are normalizing to glTF v2, so change version to \"2.0\"\n json.asset.version = '2.0';\n json.asset.generator = json.asset.generator || 'Normalized to glTF 2.0 by loaders.gl';\n }\n\n _convertTopLevelObjectsToArrays(json) {\n // TODO check that all arrays are covered\n for (const arrayName in GLTF_ARRAYS) {\n this._convertTopLevelObjectToArray(json, arrayName);\n }\n }\n\n /** Convert one top level object to array */\n _convertTopLevelObjectToArray(json, mapName) {\n const objectMap = json[mapName];\n if (!objectMap || Array.isArray(objectMap)) {\n return;\n }\n\n // Rewrite the top-level field as an array\n json[mapName] = [];\n // Copy the map key into object.id\n for (const id in objectMap) {\n const object = objectMap[id];\n object.id = object.id || id; // Mutates the loaded object\n const index = json[mapName].length;\n json[mapName].push(object);\n this.idToIndexMap[mapName][id] = index;\n }\n }\n\n /** Go through all objects in all top-level arrays and replace ids with indices */\n _convertObjectIdsToArrayIndices(json) {\n for (const arrayName in GLTF_ARRAYS) {\n this._convertIdsToIndices(json, arrayName);\n }\n if ('scene' in json) {\n json.scene = this._convertIdToIndex(json.scene, 'scene');\n }\n\n // Convert any index references that are not using array names\n\n // texture.source (image)\n for (const texture of json.textures) {\n this._convertTextureIds(texture);\n }\n for (const mesh of json.meshes) {\n this._convertMeshIds(mesh);\n }\n for (const node of json.nodes) {\n this._convertNodeIds(node);\n }\n for (const node of json.scenes) {\n this._convertSceneIds(node);\n }\n }\n\n _convertTextureIds(texture) {\n if (texture.source) {\n texture.source = this._convertIdToIndex(texture.source, 'image');\n }\n }\n\n _convertMeshIds(mesh) {\n for (const primitive of mesh.primitives) {\n const {attributes, indices, material} = primitive;\n for (const attributeName in attributes) {\n attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], 'accessor');\n }\n if (indices) {\n primitive.indices = this._convertIdToIndex(indices, 'accessor');\n }\n if (material) {\n primitive.material = this._convertIdToIndex(material, 'material');\n }\n }\n }\n\n _convertNodeIds(node) {\n if (node.children) {\n node.children = node.children.map((child) => this._convertIdToIndex(child, 'node'));\n }\n if (node.meshes) {\n node.meshes = node.meshes.map((mesh) => this._convertIdToIndex(mesh, 'mesh'));\n }\n }\n\n _convertSceneIds(scene) {\n if (scene.nodes) {\n scene.nodes = scene.nodes.map((node) => this._convertIdToIndex(node, 'node'));\n }\n }\n\n /** Go through all objects in a top-level array and replace ids with indices */\n _convertIdsToIndices(json, topLevelArrayName) {\n if (!json[topLevelArrayName]) {\n console.warn(`gltf v1: json doesn't contain attribute ${topLevelArrayName}`); // eslint-disable-line no-console, no-undef\n json[topLevelArrayName] = [];\n }\n for (const object of json[topLevelArrayName]) {\n for (const key in object) {\n const id = object[key];\n const index = this._convertIdToIndex(id, key);\n object[key] = index;\n }\n }\n }\n\n _convertIdToIndex(id, key) {\n const arrayName = GLTF_KEYS[key];\n if (arrayName in this.idToIndexMap) {\n const index = this.idToIndexMap[arrayName][id];\n if (!Number.isFinite(index)) {\n throw new Error(`gltf v1: failed to resolve ${key} with id ${id}`);\n }\n return index;\n }\n return id;\n }\n\n /**\n *\n * @param {*} json\n */\n _updateObjects(json) {\n for (const buffer of this.json.buffers) {\n // - [x] Removed buffer.type, #786, #629\n delete buffer.type;\n }\n }\n\n /**\n * Update material (set pbrMetallicRoughness)\n * @param {*} json\n */\n _updateMaterial(json) {\n for (const material of json.materials) {\n material.pbrMetallicRoughness = {\n baseColorFactor: [1, 1, 1, 1],\n metallicFactor: 1,\n roughnessFactor: 1\n };\n\n const textureId = material.values && material.values.tex;\n const textureIndex = json.textures.findIndex((texture) => texture.id === textureId);\n if (textureIndex !== -1) {\n material.pbrMetallicRoughness.baseColorTexture = {index: textureIndex};\n }\n }\n }\n}\n\nexport function normalizeGLTFV1(gltf, options = {}) {\n return new GLTFV1Normalizer().normalize(gltf, options);\n}\n"],"file":"normalize-gltf-v1.js"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/api/normalize-gltf-v1.ts"],"names":["GLTF_ARRAYS","accessors","animations","buffers","bufferViews","images","materials","meshes","nodes","samplers","scenes","skins","textures","GLTF_KEYS","accessor","buffer","bufferView","image","material","mesh","node","sampler","scene","skin","texture","GLTFV1Normalizer","normalize","gltf","options","json","asset","version","undefined","console","warn","Error","_addAsset","_convertTopLevelObjectsToArrays","KHR_binary_glTF","preprocess","_convertObjectIdsToArrayIndices","_updateObjects","_updateMaterial","generator","arrayName","_convertTopLevelObjectToArray","mapName","objectMap","Array","isArray","id","object","index","length","push","idToIndexMap","_convertIdsToIndices","_convertIdToIndex","_convertTextureIds","_convertMeshIds","_convertNodeIds","_convertSceneIds","source","primitive","primitives","attributes","indices","attributeName","children","map","child","topLevelArrayName","key","Number","isFinite","type","pbrMetallicRoughness","baseColorFactor","metallicFactor","roughnessFactor","textureId","values","tex","textureIndex","findIndex","baseColorTexture","normalizeGLTFV1"],"mappings":";;;;;;;;;;;AACA;;;;;;AA+CA,MAAMA,WAAW,GAAG;AAClBC,EAAAA,SAAS,EAAE,UADO;AAElBC,EAAAA,UAAU,EAAE,WAFM;AAGlBC,EAAAA,OAAO,EAAE,QAHS;AAIlBC,EAAAA,WAAW,EAAE,YAJK;AAKlBC,EAAAA,MAAM,EAAE,OALU;AAMlBC,EAAAA,SAAS,EAAE,UANO;AAOlBC,EAAAA,MAAM,EAAE,MAPU;AAQlBC,EAAAA,KAAK,EAAE,MARW;AASlBC,EAAAA,QAAQ,EAAE,SATQ;AAUlBC,EAAAA,MAAM,EAAE,OAVU;AAWlBC,EAAAA,KAAK,EAAE,MAXW;AAYlBC,EAAAA,QAAQ,EAAE;AAZQ,CAApB;AAeA,MAAMC,SAAS,GAAG;AAChBC,EAAAA,QAAQ,EAAE,WADM;AAEhBZ,EAAAA,UAAU,EAAE,WAFI;AAGhBa,EAAAA,MAAM,EAAE,SAHQ;AAIhBC,EAAAA,UAAU,EAAE,aAJI;AAKhBC,EAAAA,KAAK,EAAE,QALS;AAMhBC,EAAAA,QAAQ,EAAE,WANM;AAOhBC,EAAAA,IAAI,EAAE,QAPU;AAQhBC,EAAAA,IAAI,EAAE,OARU;AAShBC,EAAAA,OAAO,EAAE,UATO;AAUhBC,EAAAA,KAAK,EAAE,QAVS;AAWhBC,EA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AAL,CAAcwE,SAAd,CAAyB5D,OAAD,IAAaA,OAAO,CAAC0B,EAAR,KAAe8B,SAApD,CAArB;;AACA,UAAIG,YAAY,KAAK,CAAC,CAAtB,EAAyB;AACvBjE,QAAAA,QAAQ,CAAC0D,oBAAT,CAA8BS,gBAA9B,GAAiD;AAACjC,UAAAA,KAAK,EAAE+B;AAAR,SAAjD;AACD;AACF;AACF;;AAjOoB;;AAoOhB,SAASG,eAAT,CAAyB3D,IAAzB,EAA+BC,OAAO,GAAG,EAAzC,EAA6C;AAClD,SAAO,IAAIH,gBAAJ,GAAuBC,SAAvB,CAAiCC,IAAjC,EAAuCC,OAAvC,CAAP;AACD","sourcesContent":["/* eslint-disable camelcase */\nimport * as KHR_binary_glTF from '../extensions/KHR_binary_gltf';\n\n// Binary format changes (mainly implemented by GLBLoader)\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF\n\n// JSON format changes:\n// https://github.com/khronosgroup/gltf/issues/605\n\n// - [x] Top-level JSON objects are arrays now\n// - [ ] Removed indirection from animation: sampler now refers directly to accessors, #712\n// - [ ] material.parameter.value and technique.parameter.value must be an array, #690\n// - [ ] Node can have only one mesh #821\n// - [ ] Added reqs on JSON encoding\n// - [ ] Added reqs on binary data alignment #802 (comment)\n\n// Additions:\n// - [ ] Added accessor.normalized, #691, #706\n// - [ ] Added glExtensionsUsed property and 5125 (UNSIGNED_INT) accessor.componentType value, #619\n// - [ ] Added extensionsRequired property, #720, #721\n// - [ ] Added \"STEP\" as valid animation.sampler.interpolation value, #712\n\n// Removals:\n// - [x] Removed buffer.type, #786, #629\n// - [ ] Removed revision number from profile.version, #709\n// - [ ] Removed technique.functions.scissor and removed 3089 (SCISSOR_TEST) as a valid value for technique.states.enable, #681\n// - [ ] Techniques, programs, and shaders were moved out to KHR_technique_webgl extension.\n\n// Other edits:\n// - [x] asset is now required, #642\n// - [ ] buffer.byteLength and bufferView.byteLength are now required, #560.\n// - [ ] accessor.min and accessor.max are now required, #593, and clarified that the JSON value and binary data must be the same, #628.\n// - [ ] Clarified animation.sampler and animation.channel restrictions, #712\n// - [ ] skin.inverseBindMatrices is now optional, #461.\n// - [ ] Attribute parameters can't have a value defined in the technique or parameter, #563 (comment).\n// - [ ] Only TEXCOORD and COLOR attribute semantics can be written in the form [semantic]_[set_index], #563 (comment).\n// - [ ] TEXCOORD and COLOR attribute semantics must be written in the form [semantic]_[set_index], e.g., just TEXCOORD should be TEXCOORD_0, and just COLOR should be COLOR_0, #649\n// - [ ] camera.perspective.aspectRatio and camera.perspective.yfov must now be > 0, not >= 0, #563 (comment).\n// - [ ] Application-specific parameter semantics must start with an underscore, e.g., _TEMPERATURE and _SIMULATION_TIME, #563 (comment).\n// - [ ] Properties in technique.parameters must be defined in technique.uniforms or technique.attributes,\n\n// #563 (comment).\n// - [ ] technique.parameter.count can only be defined when the semantic is JOINTMATRIX or an application-specific semantic is used. It can never be defined for attribute parameters; only uniforms, d2f6945\n// - [ ] technique.parameter.semantic is required when the parameter is an attribute, 28e113d\n// - [ ] Mesh-only models are allowed, e.g., without materials, #642\n// - [ ] Skeleton hierarchies (nodes containing jointName) must be separated from non-skeleton hierarchies., #647\n// - [ ] technique.states.functions.blendColor and technique.states.functions.depthRange parameters now must match WebGL function min/max, #707\n\nconst GLTF_ARRAYS = {\n accessors: 'accessor',\n animations: 'animation',\n buffers: 'buffer',\n bufferViews: 'bufferView',\n images: 'image',\n materials: 'material',\n meshes: 'mesh',\n nodes: 'node',\n samplers: 'sampler',\n scenes: 'scene',\n skins: 'skin',\n textures: 'texture'\n};\n\nconst GLTF_KEYS = {\n accessor: 'accessors',\n animations: 'animation',\n buffer: 'buffers',\n bufferView: 'bufferViews',\n image: 'images',\n material: 'materials',\n mesh: 'meshes',\n node: 'nodes',\n sampler: 'samplers',\n scene: 'scenes',\n skin: 'skins',\n texture: 'textures'\n};\n\n/**\n * Converts (normalizes) glTF v1 to v2\n */\nclass GLTFV1Normalizer {\n idToIndexMap = {\n animations: {},\n accessors: {},\n buffers: {},\n bufferViews: {},\n images: {},\n materials: {},\n meshes: {},\n nodes: {},\n samplers: {},\n scenes: {},\n skins: {},\n textures: {}\n };\n\n json;\n\n // constructor() {}\n\n /**\n * Convert (normalize) glTF < 2.0 to glTF 2.0\n * @param gltf - object with json and binChunks\n * @param options\n * @param options normalize Whether to actually normalize\n */\n normalize(gltf, options) {\n this.json = gltf.json;\n const json = gltf.json;\n\n // Check version\n switch (json.asset && json.asset.version) {\n // We are converting to v2 format. Return if there is nothing to do\n case '2.0':\n return;\n\n // This class is written to convert 1.0\n case undefined:\n case '1.0':\n break;\n\n default:\n // eslint-disable-next-line no-undef, no-console\n console.warn(`glTF: Unknown version ${json.asset.version}`);\n return;\n }\n\n if (!options.normalize) {\n // We are still missing a few conversion tricks, remove once addressed\n throw new Error('glTF v1 is not supported.');\n }\n\n // eslint-disable-next-line no-undef, no-console\n console.warn('Converting glTF v1 to glTF v2 format. This is experimental and may fail.');\n\n this._addAsset(json);\n\n // In glTF2 top-level fields are Arrays not Object maps\n this._convertTopLevelObjectsToArrays(json);\n\n // Extract bufferView indices for images\n // (this extension needs to be invoked early in the normalization process)\n // TODO can this be handled by standard extension processing instead of called explicitly?\n KHR_binary_glTF.preprocess(gltf);\n\n // Convert object references from ids to indices\n this._convertObjectIdsToArrayIndices(json);\n\n this._updateObjects(json);\n\n this._updateMaterial(json);\n }\n\n // asset is now required, #642 https://github.com/KhronosGroup/glTF/issues/639\n _addAsset(json) {\n json.asset = json.asset || {};\n // We are normalizing to glTF v2, so change version to \"2.0\"\n json.asset.version = '2.0';\n json.asset.generator = json.asset.generator || 'Normalized to glTF 2.0 by loaders.gl';\n }\n\n _convertTopLevelObjectsToArrays(json) {\n // TODO check that all arrays are covered\n for (const arrayName in GLTF_ARRAYS) {\n this._convertTopLevelObjectToArray(json, arrayName);\n }\n }\n\n /** Convert one top level object to array */\n _convertTopLevelObjectToArray(json, mapName) {\n const objectMap = json[mapName];\n if (!objectMap || Array.isArray(objectMap)) {\n return;\n }\n\n // Rewrite the top-level field as an array\n json[mapName] = [];\n // Copy the map key into object.id\n for (const id in objectMap) {\n const object = objectMap[id];\n object.id = object.id || id; // Mutates the loaded object\n const index = json[mapName].length;\n json[mapName].push(object);\n this.idToIndexMap[mapName][id] = index;\n }\n }\n\n /** Go through all objects in all top-level arrays and replace ids with indices */\n _convertObjectIdsToArrayIndices(json) {\n for (const arrayName in GLTF_ARRAYS) {\n this._convertIdsToIndices(json, arrayName);\n }\n if ('scene' in json) {\n json.scene = this._convertIdToIndex(json.scene, 'scene');\n }\n\n // Convert any index references that are not using array names\n\n // texture.source (image)\n for (const texture of json.textures) {\n this._convertTextureIds(texture);\n }\n for (const mesh of json.meshes) {\n this._convertMeshIds(mesh);\n }\n for (const node of json.nodes) {\n this._convertNodeIds(node);\n }\n for (const node of json.scenes) {\n this._convertSceneIds(node);\n }\n }\n\n _convertTextureIds(texture) {\n if (texture.source) {\n texture.source = this._convertIdToIndex(texture.source, 'image');\n }\n }\n\n _convertMeshIds(mesh) {\n for (const primitive of mesh.primitives) {\n const {attributes, indices, material} = primitive;\n for (const attributeName in attributes) {\n attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], 'accessor');\n }\n if (indices) {\n primitive.indices = this._convertIdToIndex(indices, 'accessor');\n }\n if (material) {\n primitive.material = this._convertIdToIndex(material, 'material');\n }\n }\n }\n\n _convertNodeIds(node) {\n if (node.children) {\n node.children = node.children.map((child) => this._convertIdToIndex(child, 'node'));\n }\n if (node.meshes) {\n node.meshes = node.meshes.map((mesh) => this._convertIdToIndex(mesh, 'mesh'));\n }\n }\n\n _convertSceneIds(scene) {\n if (scene.nodes) {\n scene.nodes = scene.nodes.map((node) => this._convertIdToIndex(node, 'node'));\n }\n }\n\n /** Go through all objects in a top-level array and replace ids with indices */\n _convertIdsToIndices(json, topLevelArrayName) {\n if (!json[topLevelArrayName]) {\n console.warn(`gltf v1: json doesn't contain attribute ${topLevelArrayName}`); // eslint-disable-line no-console, no-undef\n json[topLevelArrayName] = [];\n }\n for (const object of json[topLevelArrayName]) {\n for (const key in object) {\n const id = object[key];\n const index = this._convertIdToIndex(id, key);\n object[key] = index;\n }\n }\n }\n\n _convertIdToIndex(id, key) {\n const arrayName = GLTF_KEYS[key];\n if (arrayName in this.idToIndexMap) {\n const index = this.idToIndexMap[arrayName][id];\n if (!Number.isFinite(index)) {\n throw new Error(`gltf v1: failed to resolve ${key} with id ${id}`);\n }\n return index;\n }\n return id;\n }\n\n /**\n *\n * @param {*} json\n */\n _updateObjects(json) {\n for (const buffer of this.json.buffers) {\n // - [x] Removed buffer.type, #786, #629\n delete buffer.type;\n }\n }\n\n /**\n * Update material (set pbrMetallicRoughness)\n * @param {*} json\n */\n _updateMaterial(json) {\n for (const material of json.materials) {\n material.pbrMetallicRoughness = {\n baseColorFactor: [1, 1, 1, 1],\n metallicFactor: 1,\n roughnessFactor: 1\n };\n\n const textureId = material.values && material.values.tex;\n const textureIndex = json.textures.findIndex((texture) => texture.id === textureId);\n if (textureIndex !== -1) {\n material.pbrMetallicRoughness.baseColorTexture = {index: textureIndex};\n }\n }\n }\n}\n\nexport function normalizeGLTFV1(gltf, options = {}) {\n return new GLTFV1Normalizer().normalize(gltf, options);\n}\n"],"file":"normalize-gltf-v1.js"}
|