@loaders.gl/gltf 4.2.0-alpha.4 → 4.2.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/dist.dev.js +1049 -517
- package/dist/dist.min.js +9 -0
- package/dist/glb-loader.d.ts +2 -2
- package/dist/glb-loader.d.ts.map +1 -1
- package/dist/glb-loader.js +22 -21
- package/dist/glb-writer.d.ts +2 -2
- package/dist/glb-writer.d.ts.map +1 -1
- package/dist/glb-writer.js +27 -24
- package/dist/gltf-loader.d.ts +3 -3
- package/dist/gltf-loader.d.ts.map +1 -1
- package/dist/gltf-loader.js +31 -36
- package/dist/gltf-writer.js +24 -26
- package/dist/index.cjs +95 -284
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +17 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/api/gltf-extensions.d.ts +2 -2
- package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
- package/dist/lib/api/gltf-extensions.js +45 -22
- package/dist/lib/api/gltf-scenegraph.d.ts +2 -2
- package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
- package/dist/lib/api/gltf-scenegraph.js +561 -438
- package/dist/lib/api/normalize-gltf-v1.js +250 -181
- package/dist/lib/api/post-process-gltf.d.ts +3 -3
- package/dist/lib/api/post-process-gltf.d.ts.map +1 -1
- package/dist/lib/api/post-process-gltf.js +375 -339
- package/dist/lib/encoders/encode-glb.js +62 -48
- package/dist/lib/encoders/encode-gltf.js +24 -10
- package/dist/lib/extensions/EXT_mesh_features.d.ts +2 -2
- package/dist/lib/extensions/EXT_mesh_features.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_mesh_features.js +55 -33
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts +2 -2
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_meshopt_compression.js +27 -31
- package/dist/lib/extensions/EXT_structural_metadata.d.ts +2 -2
- package/dist/lib/extensions/EXT_structural_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_structural_metadata.js +434 -230
- package/dist/lib/extensions/EXT_texture_webp.d.ts +2 -2
- package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_texture_webp.js +24 -17
- 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 +29 -15
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +2 -2
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.js +110 -87
- package/dist/lib/extensions/KHR_texture_basisu.d.ts +2 -2
- package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_basisu.js +19 -12
- package/dist/lib/extensions/KHR_texture_transform.d.ts +2 -2
- package/dist/lib/extensions/KHR_texture_transform.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_transform.js +194 -154
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +2 -2
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +263 -143
- 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 +44 -32
- 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 +30 -24
- 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 +65 -52
- package/dist/lib/extensions/utils/3d-tiles-utils.d.ts +2 -2
- package/dist/lib/extensions/utils/3d-tiles-utils.d.ts.map +1 -1
- package/dist/lib/extensions/utils/3d-tiles-utils.js +298 -181
- package/dist/lib/gltf-utils/get-typed-array.d.ts +1 -1
- package/dist/lib/gltf-utils/get-typed-array.d.ts.map +1 -1
- package/dist/lib/gltf-utils/get-typed-array.js +54 -42
- 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-attribute-utils.js +58 -52
- package/dist/lib/gltf-utils/gltf-constants.js +27 -27
- package/dist/lib/gltf-utils/gltf-utils.d.ts +1 -1
- package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-utils.js +67 -60
- package/dist/lib/gltf-utils/resolve-url.js +12 -10
- package/dist/lib/parsers/parse-glb.d.ts +1 -1
- package/dist/lib/parsers/parse-glb.d.ts.map +1 -1
- package/dist/lib/parsers/parse-glb.js +132 -89
- package/dist/lib/parsers/parse-gltf.d.ts +3 -3
- package/dist/lib/parsers/parse-gltf.d.ts.map +1 -1
- package/dist/lib/parsers/parse-gltf.js +155 -126
- package/dist/lib/types/glb-types.js +0 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts +1 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.js +0 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts +1 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.js +0 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts +1 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.js +0 -1
- package/dist/lib/types/gltf-json-schema.js +2 -1
- package/dist/lib/types/gltf-postprocessed-schema.js +2 -1
- package/dist/lib/types/gltf-types.d.ts +3 -3
- package/dist/lib/types/gltf-types.d.ts.map +1 -1
- package/dist/lib/types/gltf-types.js +1 -1
- package/dist/lib/utils/assert.js +6 -4
- package/dist/lib/utils/version.js +3 -1
- package/dist/meshopt/meshopt-decoder.js +86 -67
- package/dist/webp/webp.js +28 -19
- package/package.json +12 -8
- package/dist/glb-loader.js.map +0 -1
- package/dist/glb-writer.js.map +0 -1
- package/dist/gltf-loader.js.map +0 -1
- package/dist/gltf-writer.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/api/gltf-extensions.js.map +0 -1
- package/dist/lib/api/gltf-scenegraph.js.map +0 -1
- package/dist/lib/api/normalize-gltf-v1.js.map +0 -1
- package/dist/lib/api/post-process-gltf.js.map +0 -1
- package/dist/lib/encoders/encode-glb.js.map +0 -1
- package/dist/lib/encoders/encode-gltf.js.map +0 -1
- package/dist/lib/extensions/EXT_mesh_features.js.map +0 -1
- package/dist/lib/extensions/EXT_meshopt_compression.js.map +0 -1
- package/dist/lib/extensions/EXT_structural_metadata.js.map +0 -1
- package/dist/lib/extensions/EXT_texture_webp.js.map +0 -1
- package/dist/lib/extensions/KHR_binary_gltf.js.map +0 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.js.map +0 -1
- package/dist/lib/extensions/KHR_texture_basisu.js.map +0 -1
- package/dist/lib/extensions/KHR_texture_transform.js.map +0 -1
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.js.map +0 -1
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.js.map +0 -1
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.js.map +0 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js.map +0 -1
- package/dist/lib/extensions/utils/3d-tiles-utils.js.map +0 -1
- package/dist/lib/gltf-utils/get-typed-array.js.map +0 -1
- package/dist/lib/gltf-utils/gltf-attribute-utils.js.map +0 -1
- package/dist/lib/gltf-utils/gltf-constants.js.map +0 -1
- package/dist/lib/gltf-utils/gltf-utils.js.map +0 -1
- package/dist/lib/gltf-utils/resolve-url.js.map +0 -1
- package/dist/lib/parsers/parse-glb.js.map +0 -1
- package/dist/lib/parsers/parse-gltf.js.map +0 -1
- package/dist/lib/types/glb-types.js.map +0 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.js.map +0 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.js.map +0 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.js.map +0 -1
- package/dist/lib/types/gltf-json-schema.js.map +0 -1
- package/dist/lib/types/gltf-postprocessed-schema.js.map +0 -1
- package/dist/lib/types/gltf-types.js.map +0 -1
- package/dist/lib/utils/assert.js.map +0 -1
- package/dist/lib/utils/version.js.map +0 -1
- package/dist/meshopt/meshopt-decoder.js.map +0 -1
- package/dist/meshopt/meshopt-encoder.ts.disabled +0 -409
- package/dist/webp/webp.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gltf-attribute-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/gltf-utils/gltf-attribute-utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,YAAY,EAAC,
|
|
1
|
+
{"version":3,"file":"gltf-attribute-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/gltf-utils/gltf-attribute-utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,YAAY,EAAC,qCAAkC;AAO5D,wBAAgB,gBAAgB,CAAC,UAAU,KAAA,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAA;CAAC,CAU1E;AAKD,wBAAgB,eAAe,CAAC,SAAS,KAAA,gBAmBxC"}
|
|
@@ -1,62 +1,68 @@
|
|
|
1
|
+
// TODO - remove
|
|
1
2
|
import { getAccessorTypeFromSize, getComponentTypeFromArray } from "./gltf-utils.js";
|
|
3
|
+
// Returns a fresh attributes object with glTF-standardized attributes names
|
|
4
|
+
// Attributes that cannot be identified will not be included
|
|
5
|
+
// Removes `indices` if present, as it should be stored separately from the attributes
|
|
2
6
|
export function getGLTFAccessors(attributes) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const accessors = {};
|
|
8
|
+
for (const name in attributes) {
|
|
9
|
+
const attribute = attributes[name];
|
|
10
|
+
if (name !== 'indices') {
|
|
11
|
+
const glTFAccessor = getGLTFAccessor(attribute);
|
|
12
|
+
accessors[name] = glTFAccessor;
|
|
13
|
+
}
|
|
9
14
|
}
|
|
10
|
-
|
|
11
|
-
return accessors;
|
|
15
|
+
return accessors;
|
|
12
16
|
}
|
|
17
|
+
// Fix up a single accessor.
|
|
18
|
+
// Input: typed array or a partial accessor object
|
|
19
|
+
// Return: accessor object
|
|
13
20
|
export function getGLTFAccessor(attribute) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
const { buffer, size, count } = getAccessorData(attribute);
|
|
22
|
+
const glTFAccessor = {
|
|
23
|
+
// glTF Accessor values
|
|
24
|
+
// TODO: Instead of a bufferView index we could have an actual buffer (typed array)
|
|
25
|
+
// bufferView: null,
|
|
26
|
+
// TODO: Deprecate `value` in favor of bufferView?
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
value: buffer,
|
|
29
|
+
size, // Decoded `type` (e.g. SCALAR)
|
|
30
|
+
byteOffset: 0,
|
|
31
|
+
count,
|
|
32
|
+
type: getAccessorTypeFromSize(size),
|
|
33
|
+
componentType: getComponentTypeFromArray(buffer)
|
|
34
|
+
};
|
|
35
|
+
return glTFAccessor;
|
|
28
36
|
}
|
|
37
|
+
// export function getGLTFAttribute(data, gltfAttributeName): GLTFAccessor {
|
|
38
|
+
// return data.attributes[data.glTFAttributeMap[gltfAttributeName]];
|
|
39
|
+
// }
|
|
29
40
|
function getAccessorData(attribute) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
if (buffer) {
|
|
38
|
-
if (!ArrayBuffer.isView(buffer)) {
|
|
39
|
-
buffer = toTypedArray(buffer, Float32Array);
|
|
41
|
+
let buffer = attribute;
|
|
42
|
+
let size = 1;
|
|
43
|
+
let count = 0;
|
|
44
|
+
if (attribute && attribute.value) {
|
|
45
|
+
buffer = attribute.value;
|
|
46
|
+
size = attribute.size || 1;
|
|
40
47
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
if (buffer) {
|
|
49
|
+
if (!ArrayBuffer.isView(buffer)) {
|
|
50
|
+
buffer = toTypedArray(buffer, Float32Array);
|
|
51
|
+
}
|
|
52
|
+
count = buffer.length / size;
|
|
53
|
+
}
|
|
54
|
+
return { buffer, size, count };
|
|
48
55
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
// Convert non-typed arrays to arrays of specified format
|
|
57
|
+
function toTypedArray(array, ArrayType, convertTypedArrays = false) {
|
|
58
|
+
if (!array) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
if (Array.isArray(array)) {
|
|
62
|
+
return new ArrayType(array);
|
|
63
|
+
}
|
|
64
|
+
if (convertTypedArrays && !(array instanceof ArrayType)) {
|
|
65
|
+
return new ArrayType(array);
|
|
66
|
+
}
|
|
67
|
+
return array;
|
|
61
68
|
}
|
|
62
|
-
//# sourceMappingURL=gltf-attribute-utils.js.map
|
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
export const COMPONENTS = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
SCALAR: 1,
|
|
3
|
+
VEC2: 2,
|
|
4
|
+
VEC3: 3,
|
|
5
|
+
VEC4: 4,
|
|
6
|
+
MAT2: 4,
|
|
7
|
+
MAT3: 9,
|
|
8
|
+
MAT4: 16
|
|
9
9
|
};
|
|
10
10
|
export const BYTES = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
5120: 1, // BYTE
|
|
12
|
+
5121: 1, // UNSIGNED_BYTE
|
|
13
|
+
5122: 2, // SHORT
|
|
14
|
+
5123: 2, // UNSIGNED_SHORT
|
|
15
|
+
5125: 4, // UNSIGNED_INT
|
|
16
|
+
5126: 4 // FLOAT
|
|
17
17
|
};
|
|
18
|
+
// ENUM LOOKUP
|
|
18
19
|
export function getBytesFromComponentType(componentType) {
|
|
19
|
-
|
|
20
|
+
return BYTES[componentType];
|
|
20
21
|
}
|
|
21
22
|
export function getSizeFromAccessorType(type) {
|
|
22
|
-
|
|
23
|
+
return COMPONENTS[type];
|
|
23
24
|
}
|
|
24
25
|
export function getGLEnumFromSamplerParameter(parameter) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
const GL_TEXTURE_MAG_FILTER = 0x2800;
|
|
27
|
+
const GL_TEXTURE_MIN_FILTER = 0x2801;
|
|
28
|
+
const GL_TEXTURE_WRAP_S = 0x2802;
|
|
29
|
+
const GL_TEXTURE_WRAP_T = 0x2803;
|
|
30
|
+
const PARAMETER_MAP = {
|
|
31
|
+
magFilter: GL_TEXTURE_MAG_FILTER,
|
|
32
|
+
minFilter: GL_TEXTURE_MIN_FILTER,
|
|
33
|
+
wrapS: GL_TEXTURE_WRAP_S,
|
|
34
|
+
wrapT: GL_TEXTURE_WRAP_T
|
|
35
|
+
};
|
|
36
|
+
return PARAMETER_MAP[parameter];
|
|
36
37
|
}
|
|
37
|
-
//# sourceMappingURL=gltf-constants.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GLTFPostprocessed } from
|
|
1
|
+
import type { GLTFPostprocessed } from "../types/gltf-postprocessed-schema.js";
|
|
2
2
|
export declare function getAccessorTypeFromSize(size: any): string;
|
|
3
3
|
export declare function getComponentTypeFromArray(typedArray: any): number;
|
|
4
4
|
export declare function getAccessorArrayTypeAndLength(accessor: any, bufferView: any): {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gltf-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/gltf-utils/gltf-utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,iBAAiB,EAAC,
|
|
1
|
+
{"version":3,"file":"gltf-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/gltf-utils/gltf-utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,iBAAiB,EAAC,8CAA2C;AA8D1E,wBAAgB,uBAAuB,CAAC,IAAI,KAAA,UAG3C;AAED,wBAAgB,yBAAyB,CAAC,UAAU,KAAA,UAMnD;AAED,wBAAgB,6BAA6B,CAAC,QAAQ,KAAA,EAAE,UAAU,KAAA;;;;;;EAUjE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,iBAAiB,GAAG,MAAM,CAiBlE"}
|
|
@@ -1,79 +1,86 @@
|
|
|
1
1
|
import { assert } from "../utils/assert.js";
|
|
2
2
|
import { BYTES, COMPONENTS } from "../gltf-utils/gltf-constants.js";
|
|
3
|
+
/**
|
|
4
|
+
* Memory needed to store texture and all mipmap levels 1 + 1/4 + 1/16 + 1/64 + ...
|
|
5
|
+
* Minimum 1.33, but due to GPU layout may be 1.5
|
|
6
|
+
*/
|
|
3
7
|
const MIPMAP_FACTOR = 1.33;
|
|
4
8
|
const TYPES = ['SCALAR', 'VEC2', 'VEC3', 'VEC4'];
|
|
5
|
-
const ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT = [
|
|
9
|
+
const ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT = [
|
|
10
|
+
[Int8Array, 5120],
|
|
11
|
+
[Uint8Array, 5121],
|
|
12
|
+
[Int16Array, 5122],
|
|
13
|
+
[Uint16Array, 5123],
|
|
14
|
+
[Uint32Array, 5125],
|
|
15
|
+
[Float32Array, 5126],
|
|
16
|
+
[Float64Array, 5130]
|
|
17
|
+
];
|
|
6
18
|
const ARRAY_TO_COMPONENT_TYPE = new Map(ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT);
|
|
7
19
|
const ATTRIBUTE_TYPE_TO_COMPONENTS = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
20
|
+
SCALAR: 1,
|
|
21
|
+
VEC2: 2,
|
|
22
|
+
VEC3: 3,
|
|
23
|
+
VEC4: 4,
|
|
24
|
+
MAT2: 4,
|
|
25
|
+
MAT3: 9,
|
|
26
|
+
MAT4: 16
|
|
15
27
|
};
|
|
16
28
|
const ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
5120: 1,
|
|
30
|
+
5121: 1,
|
|
31
|
+
5122: 2,
|
|
32
|
+
5123: 2,
|
|
33
|
+
5125: 4,
|
|
34
|
+
5126: 4
|
|
23
35
|
};
|
|
24
36
|
const ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
37
|
+
5120: Int8Array,
|
|
38
|
+
5121: Uint8Array,
|
|
39
|
+
5122: Int16Array,
|
|
40
|
+
5123: Uint16Array,
|
|
41
|
+
5125: Uint32Array,
|
|
42
|
+
5126: Float32Array
|
|
31
43
|
};
|
|
32
44
|
export function getAccessorTypeFromSize(size) {
|
|
33
|
-
|
|
34
|
-
|
|
45
|
+
const type = TYPES[size - 1];
|
|
46
|
+
return type || TYPES[0];
|
|
35
47
|
}
|
|
36
48
|
export function getComponentTypeFromArray(typedArray) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
49
|
+
const componentType = ARRAY_TO_COMPONENT_TYPE.get(typedArray.constructor);
|
|
50
|
+
if (!componentType) {
|
|
51
|
+
throw new Error('Illegal typed array');
|
|
52
|
+
}
|
|
53
|
+
return componentType;
|
|
42
54
|
}
|
|
43
55
|
export function getAccessorArrayTypeAndLength(accessor, bufferView) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
ArrayType,
|
|
54
|
-
length,
|
|
55
|
-
byteLength,
|
|
56
|
-
componentByteSize,
|
|
57
|
-
numberOfComponentsInElement
|
|
58
|
-
};
|
|
56
|
+
const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[accessor.componentType];
|
|
57
|
+
const components = ATTRIBUTE_TYPE_TO_COMPONENTS[accessor.type];
|
|
58
|
+
const bytesPerComponent = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[accessor.componentType];
|
|
59
|
+
const length = accessor.count * components;
|
|
60
|
+
const byteLength = accessor.count * components * bytesPerComponent;
|
|
61
|
+
assert(byteLength >= 0 && byteLength <= bufferView.byteLength);
|
|
62
|
+
const componentByteSize = BYTES[accessor.componentType];
|
|
63
|
+
const numberOfComponentsInElement = COMPONENTS[accessor.type];
|
|
64
|
+
return { ArrayType, length, byteLength, componentByteSize, numberOfComponentsInElement };
|
|
59
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Calculate the GPU memory used by a GLTF tile, for both buffer and texture memory
|
|
68
|
+
* @param gltf - the gltf content of a GLTF tile
|
|
69
|
+
* @returns - total memory usage in bytes
|
|
70
|
+
*/
|
|
60
71
|
export function getMemoryUsageGLTF(gltf) {
|
|
61
|
-
|
|
62
|
-
images
|
|
63
|
-
bufferViews
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return acc + width * height;
|
|
76
|
-
}, 0);
|
|
77
|
-
return bufferMemory + Math.ceil(4 * pixelCount * MIPMAP_FACTOR);
|
|
72
|
+
let { images, bufferViews } = gltf;
|
|
73
|
+
images = images || [];
|
|
74
|
+
bufferViews = bufferViews || [];
|
|
75
|
+
const imageBufferViews = images.map((i) => i.bufferView);
|
|
76
|
+
bufferViews = bufferViews.filter((view) => !imageBufferViews.includes(view));
|
|
77
|
+
const bufferMemory = bufferViews.reduce((acc, view) => acc + view.byteLength, 0);
|
|
78
|
+
// Assume each pixel of the texture is 4 channel with mimmaps (which add 33%)
|
|
79
|
+
// TODO correctly handle compressed textures
|
|
80
|
+
const pixelCount = images.reduce((acc, image) => {
|
|
81
|
+
// @ts-ignore
|
|
82
|
+
const { width, height } = image.image;
|
|
83
|
+
return acc + width * height;
|
|
84
|
+
}, 0);
|
|
85
|
+
return bufferMemory + Math.ceil(4 * pixelCount * MIPMAP_FACTOR);
|
|
78
86
|
}
|
|
79
|
-
//# sourceMappingURL=gltf-utils.js.map
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
// Resolves a relative url against a baseUrl
|
|
2
|
+
// If url is absolute, return it unchanged
|
|
1
3
|
export function resolveUrl(url, options) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
// TODO: Use better logic to handle all protocols plus not delay on data
|
|
5
|
+
const absolute = url.startsWith('data:') || url.startsWith('http:') || url.startsWith('https:');
|
|
6
|
+
if (absolute) {
|
|
7
|
+
return url;
|
|
8
|
+
}
|
|
9
|
+
const baseUrl = options.baseUri || options.uri;
|
|
10
|
+
if (!baseUrl) {
|
|
11
|
+
throw new Error(`'baseUri' must be provided to resolve relative url ${url}`);
|
|
12
|
+
}
|
|
13
|
+
return baseUrl.substr(0, baseUrl.lastIndexOf('/') + 1) + url;
|
|
11
14
|
}
|
|
12
|
-
//# sourceMappingURL=resolve-url.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-glb.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-glb.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,GAAG,EAAC,
|
|
1
|
+
{"version":3,"file":"parse-glb.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-glb.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,GAAG,EAAC,8BAA2B;AAG5C,gCAAgC;AAChC,MAAM,MAAM,eAAe,GAAG;IAC5B,8FAA8F;IAC9F,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qFAAqF;IACrF,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AA0BF,yEAAyE;AACzE,wBAAgB,KAAK,CACnB,WAAW,EAAE,WAAW,EACxB,UAAU,GAAE,MAAU,EACtB,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAMT;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,WAAW,EACxB,UAAU,GAAE,MAAU,EACtB,OAAO,GAAE,eAAoB,UAmC9B"}
|
|
@@ -1,118 +1,161 @@
|
|
|
1
1
|
import { padToNBytes, assert } from '@loaders.gl/loader-utils';
|
|
2
|
+
/** Binary GLTF is little endian. */
|
|
2
3
|
const LITTLE_ENDIAN = true;
|
|
4
|
+
/** 'glTF' in Big-Endian ASCII */
|
|
3
5
|
const MAGIC_glTF = 0x676c5446;
|
|
4
6
|
const GLB_FILE_HEADER_SIZE = 12;
|
|
5
7
|
const GLB_CHUNK_HEADER_SIZE = 8;
|
|
6
8
|
const GLB_CHUNK_TYPE_JSON = 0x4e4f534a;
|
|
7
9
|
const GLB_CHUNK_TYPE_BIN = 0x004e4942;
|
|
8
10
|
const GLB_V1_CONTENT_FORMAT_JSON = 0x0;
|
|
11
|
+
/** @deprecated - Backward compatibility for old xviz files */
|
|
9
12
|
const GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED = 0;
|
|
13
|
+
/** @deprecated - Backward compatibility for old xviz files */
|
|
10
14
|
const GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED = 1;
|
|
11
|
-
function getMagicString(dataView) {
|
|
12
|
-
|
|
13
|
-
return `\
|
|
15
|
+
function getMagicString(dataView, byteOffset = 0) {
|
|
16
|
+
return `\
|
|
14
17
|
${String.fromCharCode(dataView.getUint8(byteOffset + 0))}\
|
|
15
18
|
${String.fromCharCode(dataView.getUint8(byteOffset + 1))}\
|
|
16
19
|
${String.fromCharCode(dataView.getUint8(byteOffset + 2))}\
|
|
17
20
|
${String.fromCharCode(dataView.getUint8(byteOffset + 3))}`;
|
|
18
21
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const magic1 = dataView.getUint32(byteOffset, false);
|
|
27
|
-
return magic1 === magic || magic1 === MAGIC_glTF;
|
|
22
|
+
/** Check if the contents of an array buffer contains GLB byte markers */
|
|
23
|
+
export function isGLB(arrayBuffer, byteOffset = 0, options = {}) {
|
|
24
|
+
const dataView = new DataView(arrayBuffer);
|
|
25
|
+
// Check that GLB Header starts with the magic number
|
|
26
|
+
const { magic = MAGIC_glTF } = options;
|
|
27
|
+
const magic1 = dataView.getUint32(byteOffset, false);
|
|
28
|
+
return magic1 === magic || magic1 === MAGIC_glTF;
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Synchronously parse a GLB
|
|
32
|
+
* @param glb - Target, Output is stored there
|
|
33
|
+
* @param arrayBuffer - Input data
|
|
34
|
+
* @param byteOffset - Offset into arrayBuffer to start parsing from (for "embedded" GLBs, e.g. in 3D tiles)
|
|
35
|
+
* @param options
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
export function parseGLBSync(glb, arrayBuffer, byteOffset = 0, options = {}) {
|
|
39
|
+
// Check that GLB Header starts with the magic number
|
|
40
|
+
const dataView = new DataView(arrayBuffer);
|
|
41
|
+
// Compare format with GLBLoader documentation
|
|
42
|
+
const type = getMagicString(dataView, byteOffset + 0);
|
|
43
|
+
const version = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN); // Version 2 of binary glTF container format
|
|
44
|
+
const byteLength = dataView.getUint32(byteOffset + 8, LITTLE_ENDIAN); // Total byte length of binary file
|
|
45
|
+
Object.assign(glb, {
|
|
46
|
+
// Put less important stuff in a header, to avoid clutter
|
|
47
|
+
header: {
|
|
48
|
+
byteOffset, // Byte offset into the initial arrayBuffer
|
|
49
|
+
byteLength,
|
|
50
|
+
hasBinChunk: false
|
|
51
|
+
},
|
|
52
|
+
type,
|
|
53
|
+
version,
|
|
54
|
+
json: {},
|
|
55
|
+
binChunks: []
|
|
56
|
+
});
|
|
57
|
+
byteOffset += GLB_FILE_HEADER_SIZE;
|
|
58
|
+
switch (glb.version) {
|
|
59
|
+
case 1:
|
|
60
|
+
return parseGLBV1(glb, dataView, byteOffset);
|
|
61
|
+
case 2:
|
|
62
|
+
return parseGLBV2(glb, dataView, byteOffset, (options = {}));
|
|
63
|
+
default:
|
|
64
|
+
throw new Error(`Invalid GLB version ${glb.version}. Only supports version 1 and 2.`);
|
|
65
|
+
}
|
|
56
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Parse a V1 GLB
|
|
69
|
+
* @param glb - target, output is stored in this object
|
|
70
|
+
* @param dataView - Input, memory to be parsed
|
|
71
|
+
* @param byteOffset - Offset of first byte of GLB data in the data view
|
|
72
|
+
* @returns Number of bytes parsed (there could be additional non-GLB data after the GLB)
|
|
73
|
+
*/
|
|
57
74
|
function parseGLBV1(glb, dataView, byteOffset) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
75
|
+
// Sanity: ensure file is big enough to hold at least the headers
|
|
76
|
+
assert(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE);
|
|
77
|
+
// Explanation of GLB structure:
|
|
78
|
+
// https://cloud.githubusercontent.com/assets/3479527/22600725/36b87122-ea55-11e6-9d40-6fd42819fcab.png
|
|
79
|
+
const contentLength = dataView.getUint32(byteOffset + 0, LITTLE_ENDIAN); // Byte length of chunk
|
|
80
|
+
const contentFormat = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN); // Chunk format as uint32
|
|
81
|
+
byteOffset += GLB_CHUNK_HEADER_SIZE;
|
|
82
|
+
// GLB v1 only supports a single chunk type
|
|
83
|
+
assert(contentFormat === GLB_V1_CONTENT_FORMAT_JSON);
|
|
84
|
+
parseJSONChunk(glb, dataView, byteOffset, contentLength);
|
|
85
|
+
// No need to call the function padToBytes() from parseJSONChunk()
|
|
86
|
+
byteOffset += contentLength;
|
|
87
|
+
byteOffset += parseBINChunk(glb, dataView, byteOffset, glb.header.byteLength);
|
|
88
|
+
return byteOffset;
|
|
67
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Parse a V2 GLB
|
|
92
|
+
* @param glb - target, output is stored in this object
|
|
93
|
+
* @param dataView - Input, memory to be parsed
|
|
94
|
+
* @param byteOffset - Offset of first byte of GLB data in the data view
|
|
95
|
+
* @returns Number of bytes parsed (there could be additional non-GLB data after the GLB)
|
|
96
|
+
*/
|
|
68
97
|
function parseGLBV2(glb, dataView, byteOffset, options) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
98
|
+
// Sanity: ensure file is big enough to hold at least the first chunk header
|
|
99
|
+
assert(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE);
|
|
100
|
+
parseGLBChunksSync(glb, dataView, byteOffset, options);
|
|
101
|
+
return byteOffset + glb.header.byteLength;
|
|
72
102
|
}
|
|
103
|
+
/** Iterate over GLB chunks and parse them */
|
|
73
104
|
function parseGLBChunksSync(glb, dataView, byteOffset, options) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
105
|
+
// Per spec we must iterate over chunks, ignoring all except JSON and BIN
|
|
106
|
+
// Iterate as long as there is space left for another chunk header
|
|
107
|
+
while (byteOffset + 8 <= glb.header.byteLength) {
|
|
108
|
+
const chunkLength = dataView.getUint32(byteOffset + 0, LITTLE_ENDIAN); // Byte length of chunk
|
|
109
|
+
const chunkFormat = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN); // Chunk format as uint32
|
|
110
|
+
byteOffset += GLB_CHUNK_HEADER_SIZE;
|
|
111
|
+
// Per spec we must iterate over chunks, ignoring all except JSON and BIN
|
|
112
|
+
switch (chunkFormat) {
|
|
113
|
+
case GLB_CHUNK_TYPE_JSON:
|
|
114
|
+
parseJSONChunk(glb, dataView, byteOffset, chunkLength);
|
|
115
|
+
break;
|
|
116
|
+
case GLB_CHUNK_TYPE_BIN:
|
|
117
|
+
parseBINChunk(glb, dataView, byteOffset, chunkLength);
|
|
118
|
+
break;
|
|
119
|
+
// Backward compatibility for very old xviz files
|
|
120
|
+
case GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED:
|
|
121
|
+
if (!options.strict) {
|
|
122
|
+
parseJSONChunk(glb, dataView, byteOffset, chunkLength);
|
|
123
|
+
}
|
|
124
|
+
break;
|
|
125
|
+
case GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED:
|
|
126
|
+
if (!options.strict) {
|
|
127
|
+
parseBINChunk(glb, dataView, byteOffset, chunkLength);
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
default:
|
|
131
|
+
// Ignore, per spec
|
|
132
|
+
// console.warn(`Unknown GLB chunk type`); // eslint-disable-line
|
|
133
|
+
break;
|
|
93
134
|
}
|
|
94
|
-
|
|
95
|
-
default:
|
|
96
|
-
break;
|
|
135
|
+
byteOffset += padToNBytes(chunkLength, 4);
|
|
97
136
|
}
|
|
98
|
-
byteOffset
|
|
99
|
-
}
|
|
100
|
-
return byteOffset;
|
|
137
|
+
return byteOffset;
|
|
101
138
|
}
|
|
139
|
+
/* Parse a GLB JSON chunk */
|
|
102
140
|
function parseJSONChunk(glb, dataView, byteOffset, chunkLength) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
141
|
+
// 1. Create a "view" of the binary encoded JSON data inside the GLB
|
|
142
|
+
const jsonChunk = new Uint8Array(dataView.buffer, byteOffset, chunkLength);
|
|
143
|
+
// 2. Decode the JSON binary array into clear text
|
|
144
|
+
const textDecoder = new TextDecoder('utf8');
|
|
145
|
+
const jsonText = textDecoder.decode(jsonChunk);
|
|
146
|
+
// 3. Parse the JSON text into a JavaScript data structure
|
|
147
|
+
glb.json = JSON.parse(jsonText);
|
|
148
|
+
return padToNBytes(chunkLength, 4);
|
|
108
149
|
}
|
|
150
|
+
/** Parse a GLB BIN chunk */
|
|
109
151
|
function parseBINChunk(glb, dataView, byteOffset, chunkLength) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
152
|
+
// Note: BIN chunk can be optional
|
|
153
|
+
glb.header.hasBinChunk = true;
|
|
154
|
+
glb.binChunks.push({
|
|
155
|
+
byteOffset,
|
|
156
|
+
byteLength: chunkLength,
|
|
157
|
+
arrayBuffer: dataView.buffer
|
|
158
|
+
// TODO - copy, or create typed array view?
|
|
159
|
+
});
|
|
160
|
+
return padToNBytes(chunkLength, 4);
|
|
117
161
|
}
|
|
118
|
-
//# sourceMappingURL=parse-glb.js.map
|