@loaders.gl/gltf 4.0.0-alpha.6 → 4.0.0-alpha.8
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/dist.min.js +1661 -1459
- package/dist/es5/glb-loader.js +2 -2
- package/dist/es5/glb-loader.js.map +1 -1
- package/dist/es5/glb-writer.js +3 -4
- package/dist/es5/glb-writer.js.map +1 -1
- package/dist/es5/gltf-loader.js +3 -3
- package/dist/es5/gltf-loader.js.map +1 -1
- package/dist/es5/index.js +9 -3
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/api/gltf-extensions.js.map +1 -1
- package/dist/es5/lib/api/gltf-scenegraph.js +52 -32
- package/dist/es5/lib/api/gltf-scenegraph.js.map +1 -1
- package/dist/es5/lib/api/post-process-gltf.js +164 -116
- package/dist/es5/lib/api/post-process-gltf.js.map +1 -1
- package/dist/es5/lib/encoders/encode-glb.js +1 -1
- package/dist/es5/lib/encoders/encode-glb.js.map +1 -1
- package/dist/es5/lib/encoders/encode-gltf.js +2 -3
- package/dist/es5/lib/encoders/encode-gltf.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js +3 -5
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_texture_webp.js +2 -3
- package/dist/es5/lib/extensions/EXT_texture_webp.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_binary_gltf.js +2 -3
- package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +6 -5
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_texture_basisu.js +3 -4
- package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_texture_transform.js +9 -8
- package/dist/es5/lib/extensions/KHR_texture_transform.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +195 -17
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js +3 -3
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js +3 -3
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js +2 -2
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -1
- package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js.map +1 -1
- package/dist/es5/lib/gltf-utils/gltf-utils.js +24 -0
- package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -1
- package/dist/es5/lib/parsers/parse-glb.js +10 -10
- package/dist/es5/lib/parsers/parse-glb.js.map +1 -1
- package/dist/es5/lib/parsers/parse-gltf.js +18 -25
- package/dist/es5/lib/parsers/parse-gltf.js.map +1 -1
- package/dist/es5/lib/types/gltf-json-schema.js.map +1 -1
- package/dist/es5/lib/types/gltf-postprocessed-schema.js.map +1 -1
- package/dist/es5/lib/types/gltf-types.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/esm/glb-loader.js +1 -1
- package/dist/esm/glb-loader.js.map +1 -1
- package/dist/esm/glb-writer.js +1 -1
- package/dist/esm/glb-writer.js.map +1 -1
- package/dist/esm/gltf-loader.js +3 -3
- package/dist/esm/gltf-loader.js.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/api/gltf-extensions.js.map +1 -1
- package/dist/esm/lib/api/gltf-scenegraph.js +45 -31
- package/dist/esm/lib/api/gltf-scenegraph.js.map +1 -1
- package/dist/esm/lib/api/post-process-gltf.js +167 -112
- package/dist/esm/lib/api/post-process-gltf.js.map +1 -1
- package/dist/esm/lib/encoders/encode-glb.js +1 -1
- package/dist/esm/lib/encoders/encode-glb.js.map +1 -1
- package/dist/esm/lib/encoders/encode-gltf.js +1 -1
- package/dist/esm/lib/encoders/encode-gltf.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js +2 -3
- 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_binary_gltf.js +1 -1
- package/dist/esm/lib/extensions/KHR_binary_gltf.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js +5 -4
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_texture_basisu.js +2 -2
- package/dist/esm/lib/extensions/KHR_texture_basisu.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_texture_transform.js +7 -6
- package/dist/esm/lib/extensions/KHR_texture_transform.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js +161 -15
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -1
- package/dist/esm/lib/gltf-utils/gltf-attribute-utils.js.map +1 -1
- package/dist/esm/lib/gltf-utils/gltf-utils.js +20 -0
- package/dist/esm/lib/gltf-utils/gltf-utils.js.map +1 -1
- package/dist/esm/lib/parsers/parse-glb.js +10 -10
- package/dist/esm/lib/parsers/parse-glb.js.map +1 -1
- package/dist/esm/lib/parsers/parse-gltf.js +7 -12
- package/dist/esm/lib/parsers/parse-gltf.js.map +1 -1
- package/dist/esm/lib/types/gltf-json-schema.js.map +1 -1
- package/dist/esm/lib/types/gltf-postprocessed-schema.js.map +1 -1
- package/dist/esm/lib/types/gltf-types.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/glb-loader.d.ts +2 -2
- package/dist/glb-loader.js +2 -5
- package/dist/glb-writer.d.ts.map +1 -1
- package/dist/glb-writer.js +4 -6
- package/dist/gltf-loader.d.ts +5 -5
- package/dist/gltf-loader.d.ts.map +1 -1
- package/dist/gltf-loader.js +3 -3
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -5
- package/dist/lib/api/gltf-extensions.d.ts +1 -1
- package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
- package/dist/lib/api/gltf-extensions.js +1 -1
- package/dist/lib/api/gltf-scenegraph.d.ts +8 -5
- package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
- package/dist/lib/api/gltf-scenegraph.js +47 -33
- package/dist/lib/api/post-process-gltf.d.ts +4 -1
- package/dist/lib/api/post-process-gltf.d.ts.map +1 -1
- package/dist/lib/api/post-process-gltf.js +186 -123
- package/dist/lib/encoders/encode-glb.d.ts +13 -1
- package/dist/lib/encoders/encode-glb.d.ts.map +1 -1
- package/dist/lib/encoders/encode-glb.js +15 -4
- package/dist/lib/encoders/encode-gltf.js +2 -5
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts +1 -1
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_meshopt_compression.js +3 -7
- package/dist/lib/extensions/EXT_texture_webp.d.ts +1 -1
- package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_texture_webp.js +2 -5
- package/dist/lib/extensions/KHR_binary_gltf.d.ts +1 -1
- package/dist/lib/extensions/KHR_binary_gltf.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_binary_gltf.js +2 -5
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +1 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.js +5 -8
- package/dist/lib/extensions/KHR_texture_basisu.d.ts +1 -1
- package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_basisu.js +3 -6
- package/dist/lib/extensions/KHR_texture_transform.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_transform.js +7 -10
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +3 -2
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +195 -23
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +3 -6
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +3 -6
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +2 -5
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts +1 -1
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-utils.d.ts +7 -0
- package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-utils.js +28 -1
- package/dist/lib/parsers/parse-glb.d.ts +15 -3
- package/dist/lib/parsers/parse-glb.d.ts.map +1 -1
- package/dist/lib/parsers/parse-glb.js +43 -18
- package/dist/lib/parsers/parse-gltf.d.ts +8 -4
- package/dist/lib/parsers/parse-gltf.d.ts.map +1 -1
- package/dist/lib/parsers/parse-gltf.js +17 -41
- package/dist/lib/types/gltf-json-schema.d.ts +153 -139
- package/dist/lib/types/gltf-json-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-postprocessed-schema.d.ts +174 -209
- package/dist/lib/types/gltf-postprocessed-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-postprocessed-schema.js +1 -1
- package/dist/lib/types/gltf-types.d.ts +18 -6
- package/dist/lib/types/gltf-types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/glb-loader.ts +3 -3
- package/src/glb-writer.ts +3 -1
- package/src/gltf-loader.ts +12 -8
- package/src/index.ts +32 -13
- package/src/lib/api/gltf-extensions.ts +1 -1
- package/src/lib/api/gltf-scenegraph.ts +60 -41
- package/src/lib/api/post-process-gltf.ts +275 -150
- package/src/lib/encoders/encode-glb.ts +15 -5
- package/src/lib/encoders/encode-gltf.ts +1 -1
- package/src/lib/extensions/EXT_meshopt_compression.ts +4 -6
- package/src/lib/extensions/EXT_texture_webp.ts +2 -2
- package/src/lib/extensions/KHR_binary_gltf.ts +2 -2
- package/src/lib/extensions/KHR_draco_mesh_compression.ts +7 -7
- package/src/lib/extensions/KHR_texture_basisu.ts +3 -3
- package/src/lib/extensions/KHR_texture_transform.ts +22 -19
- package/src/lib/extensions/deprecated/EXT_feature_metadata.ts +264 -23
- package/src/lib/extensions/deprecated/KHR_lights_punctual.ts +2 -2
- package/src/lib/extensions/deprecated/KHR_materials_unlit.ts +2 -2
- package/src/lib/extensions/deprecated/KHR_techniques_webgl.ts +2 -2
- package/src/lib/gltf-utils/gltf-attribute-utils.ts +1 -1
- package/src/lib/gltf-utils/gltf-utils.ts +31 -0
- package/src/lib/parsers/parse-glb.ts +50 -24
- package/src/lib/parsers/parse-gltf.ts +26 -25
- package/src/lib/types/gltf-json-schema.ts +168 -138
- package/src/lib/types/gltf-postprocessed-schema.ts +289 -212
- package/src/lib/types/gltf-types.ts +35 -59
|
@@ -4,24 +4,29 @@
|
|
|
4
4
|
import type {GLB} from '../types/glb-types';
|
|
5
5
|
import {padToNBytes, assert} from '@loaders.gl/loader-utils';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/** Options for parsing a GLB */
|
|
8
|
+
export type ParseGLBOptions = {
|
|
9
|
+
/** @deprecated This option was used by XVIZ protocol to define a non-standard magic number */
|
|
8
10
|
magic?: number;
|
|
11
|
+
/** @deprecated This option was used by XVIZ protocol to embed non-standard chunks */
|
|
9
12
|
strict?: boolean;
|
|
10
13
|
};
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
/** Binary GLTF is little endian. */
|
|
16
|
+
const LITTLE_ENDIAN = true;
|
|
13
17
|
|
|
18
|
+
/** 'glTF' in Big-Endian ASCII */
|
|
19
|
+
const MAGIC_glTF = 0x676c5446;
|
|
14
20
|
const GLB_FILE_HEADER_SIZE = 12;
|
|
15
21
|
const GLB_CHUNK_HEADER_SIZE = 8;
|
|
16
|
-
|
|
17
22
|
const GLB_CHUNK_TYPE_JSON = 0x4e4f534a;
|
|
18
23
|
const GLB_CHUNK_TYPE_BIN = 0x004e4942;
|
|
19
|
-
const GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED = 0; // DEPRECATED - Backward compatibility for old xviz files
|
|
20
|
-
const GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED = 1; // DEPRECATED - Backward compatibility for old xviz files
|
|
21
|
-
|
|
22
24
|
const GLB_V1_CONTENT_FORMAT_JSON = 0x0;
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
/** @deprecated - Backward compatibility for old xviz files */
|
|
27
|
+
const GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED = 0;
|
|
28
|
+
/** @deprecated - Backward compatibility for old xviz files */
|
|
29
|
+
const GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED = 1;
|
|
25
30
|
|
|
26
31
|
function getMagicString(dataView, byteOffset = 0) {
|
|
27
32
|
return `\
|
|
@@ -31,11 +36,11 @@ ${String.fromCharCode(dataView.getUint8(byteOffset + 2))}\
|
|
|
31
36
|
${String.fromCharCode(dataView.getUint8(byteOffset + 3))}`;
|
|
32
37
|
}
|
|
33
38
|
|
|
34
|
-
|
|
39
|
+
/** Check if the contents of an array buffer contains GLB byte markers */
|
|
35
40
|
export function isGLB(
|
|
36
41
|
arrayBuffer: ArrayBuffer,
|
|
37
42
|
byteOffset: number = 0,
|
|
38
|
-
options:
|
|
43
|
+
options: ParseGLBOptions = {}
|
|
39
44
|
): boolean {
|
|
40
45
|
const dataView = new DataView(arrayBuffer);
|
|
41
46
|
// Check that GLB Header starts with the magic number
|
|
@@ -44,19 +49,27 @@ export function isGLB(
|
|
|
44
49
|
return magic1 === magic || magic1 === MAGIC_glTF;
|
|
45
50
|
}
|
|
46
51
|
|
|
47
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Synchronously parse a GLB
|
|
54
|
+
* @param glb - Target, Output is stored there
|
|
55
|
+
* @param arrayBuffer - Input data
|
|
56
|
+
* @param byteOffset - Offset into arrayBuffer to start parsing from (for "embedded" GLBs, e.g. in 3D tiles)
|
|
57
|
+
* @param options
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
export function parseGLBSync(
|
|
48
61
|
glb: GLB,
|
|
49
62
|
arrayBuffer: ArrayBuffer,
|
|
50
63
|
byteOffset: number = 0,
|
|
51
|
-
options:
|
|
64
|
+
options: ParseGLBOptions = {}
|
|
52
65
|
) {
|
|
53
66
|
// Check that GLB Header starts with the magic number
|
|
54
67
|
const dataView = new DataView(arrayBuffer);
|
|
55
68
|
|
|
56
69
|
// Compare format with GLBLoader documentation
|
|
57
70
|
const type = getMagicString(dataView, byteOffset + 0);
|
|
58
|
-
const version = dataView.getUint32(byteOffset + 4,
|
|
59
|
-
const byteLength = dataView.getUint32(byteOffset + 8,
|
|
71
|
+
const version = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN); // Version 2 of binary glTF container format
|
|
72
|
+
const byteLength = dataView.getUint32(byteOffset + 8, LITTLE_ENDIAN); // Total byte length of binary file
|
|
60
73
|
|
|
61
74
|
Object.assign(glb, {
|
|
62
75
|
// Put less important stuff in a header, to avoid clutter
|
|
@@ -77,24 +90,29 @@ export default function parseGLBSync(
|
|
|
77
90
|
|
|
78
91
|
switch (glb.version) {
|
|
79
92
|
case 1:
|
|
80
|
-
// eslint-disable-next-line
|
|
81
93
|
return parseGLBV1(glb, dataView, byteOffset);
|
|
82
94
|
case 2:
|
|
83
|
-
// eslint-disable-next-line
|
|
84
95
|
return parseGLBV2(glb, dataView, byteOffset, (options = {}));
|
|
85
96
|
default:
|
|
86
|
-
throw new Error(`Invalid GLB version ${glb.version}. Only supports
|
|
97
|
+
throw new Error(`Invalid GLB version ${glb.version}. Only supports version 1 and 2.`);
|
|
87
98
|
}
|
|
88
99
|
}
|
|
89
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Parse a V1 GLB
|
|
103
|
+
* @param glb - target, output is stored in this object
|
|
104
|
+
* @param dataView - Input, memory to be parsed
|
|
105
|
+
* @param byteOffset - Offset of first byte of GLB data in the data view
|
|
106
|
+
* @returns Number of bytes parsed (there could be additional non-GLB data after the GLB)
|
|
107
|
+
*/
|
|
90
108
|
function parseGLBV1(glb: GLB, dataView: DataView, byteOffset: number): number {
|
|
91
109
|
// Sanity: ensure file is big enough to hold at least the headers
|
|
92
110
|
assert(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE);
|
|
93
111
|
|
|
94
112
|
// Explanation of GLB structure:
|
|
95
113
|
// https://cloud.githubusercontent.com/assets/3479527/22600725/36b87122-ea55-11e6-9d40-6fd42819fcab.png
|
|
96
|
-
const contentLength = dataView.getUint32(byteOffset + 0,
|
|
97
|
-
const contentFormat = dataView.getUint32(byteOffset + 4,
|
|
114
|
+
const contentLength = dataView.getUint32(byteOffset + 0, LITTLE_ENDIAN); // Byte length of chunk
|
|
115
|
+
const contentFormat = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN); // Chunk format as uint32
|
|
98
116
|
byteOffset += GLB_CHUNK_HEADER_SIZE;
|
|
99
117
|
|
|
100
118
|
// GLB v1 only supports a single chunk type
|
|
@@ -108,11 +126,18 @@ function parseGLBV1(glb: GLB, dataView: DataView, byteOffset: number): number {
|
|
|
108
126
|
return byteOffset;
|
|
109
127
|
}
|
|
110
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Parse a V2 GLB
|
|
131
|
+
* @param glb - target, output is stored in this object
|
|
132
|
+
* @param dataView - Input, memory to be parsed
|
|
133
|
+
* @param byteOffset - Offset of first byte of GLB data in the data view
|
|
134
|
+
* @returns Number of bytes parsed (there could be additional non-GLB data after the GLB)
|
|
135
|
+
*/
|
|
111
136
|
function parseGLBV2(
|
|
112
137
|
glb: GLB,
|
|
113
138
|
dataView: DataView,
|
|
114
139
|
byteOffset: number,
|
|
115
|
-
options:
|
|
140
|
+
options: ParseGLBOptions
|
|
116
141
|
): number {
|
|
117
142
|
// Sanity: ensure file is big enough to hold at least the first chunk header
|
|
118
143
|
assert(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE);
|
|
@@ -122,17 +147,18 @@ function parseGLBV2(
|
|
|
122
147
|
return byteOffset + glb.header.byteLength;
|
|
123
148
|
}
|
|
124
149
|
|
|
150
|
+
/** Iterate over GLB chunks and parse them */
|
|
125
151
|
function parseGLBChunksSync(
|
|
126
152
|
glb: GLB,
|
|
127
153
|
dataView: DataView,
|
|
128
154
|
byteOffset: number,
|
|
129
|
-
options:
|
|
155
|
+
options: ParseGLBOptions
|
|
130
156
|
) {
|
|
131
157
|
// Per spec we must iterate over chunks, ignoring all except JSON and BIN
|
|
132
158
|
// Iterate as long as there is space left for another chunk header
|
|
133
159
|
while (byteOffset + 8 <= glb.header.byteLength) {
|
|
134
|
-
const chunkLength = dataView.getUint32(byteOffset + 0,
|
|
135
|
-
const chunkFormat = dataView.getUint32(byteOffset + 4,
|
|
160
|
+
const chunkLength = dataView.getUint32(byteOffset + 0, LITTLE_ENDIAN); // Byte length of chunk
|
|
161
|
+
const chunkFormat = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN); // Chunk format as uint32
|
|
136
162
|
byteOffset += GLB_CHUNK_HEADER_SIZE;
|
|
137
163
|
|
|
138
164
|
// Per spec we must iterate over chunks, ignoring all except JSON and BIN
|
|
@@ -168,7 +194,7 @@ function parseGLBChunksSync(
|
|
|
168
194
|
return byteOffset;
|
|
169
195
|
}
|
|
170
196
|
|
|
171
|
-
|
|
197
|
+
/* Parse a GLB JSON chunk */
|
|
172
198
|
function parseJSONChunk(glb: GLB, dataView: DataView, byteOffset: number, chunkLength: number) {
|
|
173
199
|
// 1. Create a "view" of the binary encoded JSON data inside the GLB
|
|
174
200
|
const jsonChunk = new Uint8Array(dataView.buffer, byteOffset, chunkLength);
|
|
@@ -183,7 +209,7 @@ function parseJSONChunk(glb: GLB, dataView: DataView, byteOffset: number, chunkL
|
|
|
183
209
|
return padToNBytes(chunkLength, 4);
|
|
184
210
|
}
|
|
185
211
|
|
|
186
|
-
|
|
212
|
+
/** Parse a GLB BIN chunk */
|
|
187
213
|
function parseBINChunk(glb: GLB, dataView, byteOffset, chunkLength) {
|
|
188
214
|
// Note: BIN chunk can be optional
|
|
189
215
|
glb.header.hasBinChunk = true;
|
|
@@ -1,34 +1,35 @@
|
|
|
1
1
|
/* eslint-disable camelcase, max-statements, no-restricted-globals */
|
|
2
2
|
import type {LoaderContext} from '@loaders.gl/loader-utils';
|
|
3
|
-
import {BasisLoader, selectSupportedBasisFormat} from '@loaders.gl/textures';
|
|
4
3
|
import type {GLTFLoaderOptions} from '../../gltf-loader';
|
|
5
|
-
import type {GLB} from '../types/glb-types';
|
|
6
4
|
import type {GLTFWithBuffers} from '../types/gltf-types';
|
|
5
|
+
import type {GLB} from '../types/glb-types';
|
|
6
|
+
import type {ParseGLBOptions} from './parse-glb';
|
|
7
7
|
|
|
8
|
-
import {ImageLoader} from '@loaders.gl/images';
|
|
9
8
|
import {parseJSON, sliceArrayBuffer} from '@loaders.gl/loader-utils';
|
|
9
|
+
import {ImageLoader} from '@loaders.gl/images';
|
|
10
|
+
import {BasisLoader, selectSupportedBasisFormat} from '@loaders.gl/textures';
|
|
11
|
+
|
|
10
12
|
import {assert} from '../utils/assert';
|
|
13
|
+
import {isGLB, parseGLBSync} from './parse-glb';
|
|
11
14
|
import {resolveUrl} from '../gltf-utils/resolve-url';
|
|
12
15
|
import {getTypedArrayForBufferView} from '../gltf-utils/get-typed-array';
|
|
13
16
|
import {preprocessExtensions, decodeExtensions} from '../api/gltf-extensions';
|
|
14
17
|
import {normalizeGLTFV1} from '../api/normalize-gltf-v1';
|
|
15
|
-
import {postProcessGLTF} from '../api/post-process-gltf';
|
|
16
|
-
import parseGLBSync, {isGLB} from './parse-glb';
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
/** */
|
|
20
|
+
export type ParseGLTFOptions = ParseGLBOptions & {
|
|
19
21
|
normalize?: boolean;
|
|
20
22
|
loadImages?: boolean;
|
|
21
23
|
loadBuffers?: boolean;
|
|
22
24
|
decompressMeshes?: boolean;
|
|
23
|
-
postProcess?: boolean;
|
|
24
25
|
excludeExtensions?: string[];
|
|
25
|
-
};
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
/** @deprecated not supported in v4. `postProcessGLTF()` must be called by the application */
|
|
28
|
+
postProcess?: false;
|
|
29
|
+
};
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
/** Check if an array buffer appears to contain GLTF data */
|
|
32
|
+
export function isGLTF(arrayBuffer: ArrayBuffer, options?: ParseGLTFOptions): boolean {
|
|
32
33
|
const byteOffset = 0;
|
|
33
34
|
return isGLB(arrayBuffer, byteOffset, options);
|
|
34
35
|
}
|
|
@@ -39,36 +40,36 @@ export async function parseGLTF(
|
|
|
39
40
|
byteOffset = 0,
|
|
40
41
|
options: GLTFLoaderOptions,
|
|
41
42
|
context: LoaderContext
|
|
42
|
-
) {
|
|
43
|
+
): Promise<GLTFWithBuffers> {
|
|
43
44
|
parseGLTFContainerSync(gltf, arrayBufferOrString, byteOffset, options);
|
|
44
45
|
|
|
45
46
|
normalizeGLTFV1(gltf, {normalize: options?.gltf?.normalize});
|
|
46
47
|
|
|
47
48
|
preprocessExtensions(gltf, options, context);
|
|
48
49
|
|
|
49
|
-
const promises: Promise<any>[] = [];
|
|
50
|
-
|
|
51
50
|
// Load linked buffers asynchronously and decodes base64 buffers in parallel
|
|
52
51
|
if (options?.gltf?.loadBuffers && gltf.json.buffers) {
|
|
53
52
|
await loadBuffers(gltf, options, context);
|
|
54
53
|
}
|
|
55
54
|
|
|
55
|
+
// loadImages and decodeExtensions should not be running in parallel, because
|
|
56
|
+
// decodeExtensions uses data from images taken during the loadImages call.
|
|
56
57
|
if (options?.gltf?.loadImages) {
|
|
57
|
-
|
|
58
|
-
promises.push(promise);
|
|
58
|
+
await loadImages(gltf, options, context);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
promises.push(promise);
|
|
63
|
-
|
|
64
|
-
// Parallelize image loading and buffer loading/extension decoding
|
|
65
|
-
await Promise.all(promises);
|
|
61
|
+
await decodeExtensions(gltf, options, context);
|
|
66
62
|
|
|
67
|
-
|
|
68
|
-
return options?.gltf?.postProcess ? postProcessGLTF(gltf, options) : gltf;
|
|
63
|
+
return gltf;
|
|
69
64
|
}
|
|
70
65
|
|
|
71
|
-
|
|
66
|
+
/**
|
|
67
|
+
*
|
|
68
|
+
* @param gltf
|
|
69
|
+
* @param data - can be ArrayBuffer (GLB), ArrayBuffer (Binary JSON), String (JSON), or Object (parsed JSON)
|
|
70
|
+
* @param byteOffset
|
|
71
|
+
* @param options
|
|
72
|
+
*/
|
|
72
73
|
function parseGLTFContainerSync(gltf, data, byteOffset, options) {
|
|
73
74
|
// Initialize gltf container
|
|
74
75
|
if (options.uri) {
|