@loaders.gl/gltf 4.0.0-alpha.9 → 4.0.0-beta.2

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.
Files changed (152) hide show
  1. package/dist/dist.min.js +3777 -3105
  2. package/dist/es5/glb-loader.js +1 -3
  3. package/dist/es5/glb-loader.js.map +1 -1
  4. package/dist/es5/index.js +33 -0
  5. package/dist/es5/index.js.map +1 -1
  6. package/dist/es5/lib/api/gltf-extensions.js +3 -1
  7. package/dist/es5/lib/api/gltf-extensions.js.map +1 -1
  8. package/dist/es5/lib/extensions/EXT_mesh_features.js +99 -0
  9. package/dist/es5/lib/extensions/EXT_mesh_features.js.map +1 -0
  10. package/dist/es5/lib/extensions/EXT_meshopt_compression.js +2 -2
  11. package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -1
  12. package/dist/es5/lib/extensions/EXT_structural_metadata.js +375 -0
  13. package/dist/es5/lib/extensions/EXT_structural_metadata.js.map +1 -0
  14. package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +6 -7
  15. package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
  16. package/dist/es5/lib/extensions/KHR_texture_transform.js +2 -1
  17. package/dist/es5/lib/extensions/KHR_texture_transform.js.map +1 -1
  18. package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +162 -183
  19. package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
  20. package/dist/es5/lib/extensions/utils/3d-tiles-utils.js +254 -0
  21. package/dist/es5/lib/extensions/utils/3d-tiles-utils.js.map +1 -0
  22. package/dist/es5/lib/gltf-utils/gltf-utils.js +29 -0
  23. package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -1
  24. package/dist/es5/lib/parsers/parse-gltf.js +7 -4
  25. package/dist/es5/lib/parsers/parse-gltf.js.map +1 -1
  26. package/dist/es5/lib/types/gltf-ext-feature-metadata-schema.js +2 -0
  27. package/dist/es5/lib/types/gltf-ext-feature-metadata-schema.js.map +1 -0
  28. package/dist/es5/lib/types/gltf-ext-mesh-features-schema.js +2 -0
  29. package/dist/es5/lib/types/gltf-ext-mesh-features-schema.js.map +1 -0
  30. package/dist/es5/lib/types/gltf-ext-structural-metadata-schema.js +2 -0
  31. package/dist/es5/lib/types/gltf-ext-structural-metadata-schema.js.map +1 -0
  32. package/dist/es5/lib/types/gltf-json-schema.js.map +1 -1
  33. package/dist/es5/lib/types/gltf-types.js.map +1 -1
  34. package/dist/es5/lib/utils/version.js +1 -1
  35. package/dist/es5/lib/utils/version.js.map +1 -1
  36. package/dist/esm/glb-loader.js +0 -1
  37. package/dist/esm/glb-loader.js.map +1 -1
  38. package/dist/esm/index.js +5 -0
  39. package/dist/esm/index.js.map +1 -1
  40. package/dist/esm/lib/api/gltf-extensions.js +3 -1
  41. package/dist/esm/lib/api/gltf-extensions.js.map +1 -1
  42. package/dist/esm/lib/extensions/EXT_mesh_features.js +43 -0
  43. package/dist/esm/lib/extensions/EXT_mesh_features.js.map +1 -0
  44. package/dist/esm/lib/extensions/EXT_meshopt_compression.js +2 -2
  45. package/dist/esm/lib/extensions/EXT_meshopt_compression.js.map +1 -1
  46. package/dist/esm/lib/extensions/EXT_structural_metadata.js +302 -0
  47. package/dist/esm/lib/extensions/EXT_structural_metadata.js.map +1 -0
  48. package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js +2 -5
  49. package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
  50. package/dist/esm/lib/extensions/KHR_texture_transform.js +2 -1
  51. package/dist/esm/lib/extensions/KHR_texture_transform.js.map +1 -1
  52. package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js +156 -167
  53. package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
  54. package/dist/esm/lib/extensions/utils/3d-tiles-utils.js +215 -0
  55. package/dist/esm/lib/extensions/utils/3d-tiles-utils.js.map +1 -0
  56. package/dist/esm/lib/gltf-utils/gltf-utils.js +30 -0
  57. package/dist/esm/lib/gltf-utils/gltf-utils.js.map +1 -1
  58. package/dist/esm/lib/parsers/parse-gltf.js +6 -6
  59. package/dist/esm/lib/parsers/parse-gltf.js.map +1 -1
  60. package/dist/esm/lib/types/gltf-ext-feature-metadata-schema.js +2 -0
  61. package/dist/esm/lib/types/gltf-ext-feature-metadata-schema.js.map +1 -0
  62. package/dist/esm/lib/types/gltf-ext-mesh-features-schema.js +2 -0
  63. package/dist/esm/lib/types/gltf-ext-mesh-features-schema.js.map +1 -0
  64. package/dist/esm/lib/types/gltf-ext-structural-metadata-schema.js +2 -0
  65. package/dist/esm/lib/types/gltf-ext-structural-metadata-schema.js.map +1 -0
  66. package/dist/esm/lib/types/gltf-json-schema.js.map +1 -1
  67. package/dist/esm/lib/types/gltf-types.js.map +1 -1
  68. package/dist/esm/lib/utils/version.js +1 -1
  69. package/dist/esm/lib/utils/version.js.map +1 -1
  70. package/dist/glb-loader.d.ts +3 -1
  71. package/dist/glb-loader.d.ts.map +1 -1
  72. package/dist/index.d.ts +10 -2
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
  75. package/dist/lib/extensions/EXT_mesh_features.d.ts +7 -0
  76. package/dist/lib/extensions/EXT_mesh_features.d.ts.map +1 -0
  77. package/dist/lib/extensions/EXT_structural_metadata.d.ts +16 -0
  78. package/dist/lib/extensions/EXT_structural_metadata.d.ts.map +1 -0
  79. package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +1 -1
  80. package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -1
  81. package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +9 -0
  82. package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
  83. package/dist/lib/extensions/utils/3d-tiles-utils.d.ts +82 -0
  84. package/dist/lib/extensions/utils/3d-tiles-utils.d.ts.map +1 -0
  85. package/dist/lib/gltf-utils/gltf-utils.d.ts +2 -0
  86. package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
  87. package/dist/lib/parsers/parse-gltf.d.ts.map +1 -1
  88. package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts +421 -0
  89. package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts.map +1 -0
  90. package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts +43 -0
  91. package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts.map +1 -0
  92. package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts +329 -0
  93. package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts.map +1 -0
  94. package/dist/lib/types/gltf-json-schema.d.ts +12 -404
  95. package/dist/lib/types/gltf-json-schema.d.ts.map +1 -1
  96. package/dist/lib/types/gltf-types.d.ts +4 -1
  97. package/dist/lib/types/gltf-types.d.ts.map +1 -1
  98. package/package.json +6 -6
  99. package/src/glb-loader.ts +3 -3
  100. package/src/index.ts +37 -6
  101. package/src/lib/api/gltf-extensions.ts +6 -2
  102. package/src/lib/extensions/EXT_mesh_features.ts +91 -0
  103. package/src/lib/extensions/EXT_meshopt_compression.ts +1 -1
  104. package/src/lib/extensions/EXT_structural_metadata.ts +750 -0
  105. package/src/lib/extensions/KHR_draco_mesh_compression.ts +7 -7
  106. package/src/lib/extensions/KHR_texture_transform.ts +1 -1
  107. package/src/lib/extensions/deprecated/EXT_feature_metadata.ts +407 -281
  108. package/src/lib/extensions/utils/3d-tiles-utils.ts +430 -0
  109. package/src/lib/gltf-utils/gltf-utils.ts +38 -0
  110. package/src/lib/parsers/parse-gltf.ts +14 -6
  111. package/src/lib/types/gltf-ext-feature-metadata-schema.ts +470 -0
  112. package/src/lib/types/gltf-ext-mesh-features-schema.ts +46 -0
  113. package/src/lib/types/gltf-ext-structural-metadata-schema.ts +378 -0
  114. package/src/lib/types/gltf-json-schema.ts +26 -465
  115. package/src/lib/types/gltf-types.ts +5 -3
  116. package/dist/bundle.js +0 -5
  117. package/dist/glb-loader.js +0 -36
  118. package/dist/glb-writer.js +0 -35
  119. package/dist/gltf-loader.js +0 -50
  120. package/dist/gltf-writer.js +0 -32
  121. package/dist/index.js +0 -28
  122. package/dist/lib/api/gltf-extensions.js +0 -83
  123. package/dist/lib/api/gltf-scenegraph.js +0 -580
  124. package/dist/lib/api/normalize-gltf-v1.js +0 -299
  125. package/dist/lib/api/post-process-gltf.js +0 -433
  126. package/dist/lib/encoders/encode-glb.js +0 -72
  127. package/dist/lib/encoders/encode-gltf.js +0 -32
  128. package/dist/lib/extensions/EXT_meshopt_compression.js +0 -41
  129. package/dist/lib/extensions/EXT_texture_webp.js +0 -36
  130. package/dist/lib/extensions/KHR_binary_gltf.js +0 -39
  131. package/dist/lib/extensions/KHR_draco_mesh_compression.js +0 -138
  132. package/dist/lib/extensions/KHR_texture_basisu.js +0 -29
  133. package/dist/lib/extensions/KHR_texture_transform.js +0 -227
  134. package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +0 -290
  135. package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +0 -59
  136. package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +0 -44
  137. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +0 -79
  138. package/dist/lib/gltf-utils/get-typed-array.js +0 -41
  139. package/dist/lib/gltf-utils/gltf-attribute-utils.js +0 -73
  140. package/dist/lib/gltf-utils/gltf-constants.js +0 -43
  141. package/dist/lib/gltf-utils/gltf-utils.js +0 -90
  142. package/dist/lib/gltf-utils/resolve-url.js +0 -18
  143. package/dist/lib/parsers/parse-glb.js +0 -166
  144. package/dist/lib/parsers/parse-gltf.js +0 -179
  145. package/dist/lib/types/glb-types.js +0 -2
  146. package/dist/lib/types/gltf-json-schema.js +0 -4
  147. package/dist/lib/types/gltf-postprocessed-schema.js +0 -4
  148. package/dist/lib/types/gltf-types.js +0 -3
  149. package/dist/lib/utils/assert.js +0 -12
  150. package/dist/lib/utils/version.js +0 -7
  151. package/dist/meshopt/meshopt-decoder.js +0 -118
  152. package/dist/webp/webp.js +0 -38
@@ -1,59 +0,0 @@
1
- "use strict";
2
- // GLTF EXTENSION: KHR_lights_punctual
3
- // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.encode = exports.decode = exports.name = void 0;
6
- const assert_1 = require("../../utils/assert");
7
- const gltf_scenegraph_1 = require("../../api/gltf-scenegraph");
8
- const KHR_LIGHTS_PUNCTUAL = 'KHR_lights_punctual';
9
- exports.name = KHR_LIGHTS_PUNCTUAL;
10
- async function decode(gltfData) {
11
- const gltfScenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
12
- const { json } = gltfScenegraph;
13
- // Move the light array out of the extension and remove the extension
14
- const extension = gltfScenegraph.getExtension(KHR_LIGHTS_PUNCTUAL);
15
- if (extension) {
16
- // @ts-ignore
17
- gltfScenegraph.json.lights = extension.lights;
18
- gltfScenegraph.removeExtension(KHR_LIGHTS_PUNCTUAL);
19
- }
20
- // Any nodes that have the extension, add lights field pointing to light object
21
- // and remove the extension
22
- for (const node of json.nodes || []) {
23
- const nodeExtension = gltfScenegraph.getObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
24
- if (nodeExtension) {
25
- // @ts-ignore
26
- node.light = nodeExtension.light;
27
- }
28
- gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
29
- }
30
- }
31
- exports.decode = decode;
32
- // Move the light ar ray out of the extension and remove the extension
33
- async function encode(gltfData) {
34
- const gltfScenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
35
- const { json } = gltfScenegraph;
36
- // @ts-ignore
37
- if (json.lights) {
38
- const extension = gltfScenegraph.addExtension(KHR_LIGHTS_PUNCTUAL);
39
- // @ts-ignore
40
- (0, assert_1.assert)(!extension.lights);
41
- // @ts-ignore
42
- extension.lights = json.lights;
43
- // @ts-ignore
44
- delete json.lights;
45
- }
46
- // Any nodes that have lights field pointing to light object
47
- // add the extension
48
- // @ts-ignore
49
- if (gltfScenegraph.json.lights) {
50
- // @ts-ignore
51
- for (const light of gltfScenegraph.json.lights) {
52
- const node = light.node;
53
- gltfScenegraph.addObjectExtension(node, KHR_LIGHTS_PUNCTUAL, light);
54
- }
55
- // @ts-ignore
56
- delete gltfScenegraph.json.lights;
57
- }
58
- }
59
- exports.encode = encode;
@@ -1,44 +0,0 @@
1
- "use strict";
2
- // GLTF EXTENSION: KHR_materials_unlit
3
- // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.encode = exports.decode = exports.name = void 0;
6
- const gltf_scenegraph_1 = require("../../api/gltf-scenegraph");
7
- const KHR_MATERIALS_UNLIT = 'KHR_materials_unlit';
8
- exports.name = KHR_MATERIALS_UNLIT;
9
- async function decode(gltfData) {
10
- const gltfScenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
11
- const { json } = gltfScenegraph;
12
- // Any nodes that have the extension, add lights field pointing to light object
13
- // and remove the extension
14
- for (const material of json.materials || []) {
15
- const extension = material.extensions && material.extensions.KHR_materials_unlit;
16
- if (extension) {
17
- // @ts-ignore TODO
18
- material.unlit = true;
19
- }
20
- gltfScenegraph.removeObjectExtension(material, KHR_MATERIALS_UNLIT);
21
- }
22
- // Remove the top-level extension
23
- gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT);
24
- }
25
- exports.decode = decode;
26
- function encode(gltfData) {
27
- const gltfScenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
28
- const { json } = gltfScenegraph;
29
- // Any nodes that have lights field pointing to light object
30
- // add the extension
31
- // @ts-ignore
32
- if (gltfScenegraph.materials) {
33
- for (const material of json.materials || []) {
34
- // @ts-ignore
35
- if (material.unlit) {
36
- // @ts-ignore
37
- delete material.unlit;
38
- gltfScenegraph.addObjectExtension(material, KHR_MATERIALS_UNLIT, {});
39
- gltfScenegraph.addExtension(KHR_MATERIALS_UNLIT);
40
- }
41
- }
42
- }
43
- }
44
- exports.encode = encode;
@@ -1,79 +0,0 @@
1
- "use strict";
2
- // GLTF EXTENSION: KHR_techniques_webgl
3
- // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_techniques_webgl
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.encode = exports.decode = exports.name = void 0;
6
- const gltf_scenegraph_1 = require("../../api/gltf-scenegraph");
7
- const KHR_TECHNIQUES_WEBGL = 'KHR_techniques_webgl';
8
- exports.name = KHR_TECHNIQUES_WEBGL;
9
- async function decode(gltfData) {
10
- const gltfScenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
11
- const { json } = gltfScenegraph;
12
- const extension = gltfScenegraph.getExtension(KHR_TECHNIQUES_WEBGL);
13
- if (extension) {
14
- const techniques = resolveTechniques(extension, gltfScenegraph);
15
- for (const material of json.materials || []) {
16
- const materialExtension = gltfScenegraph.getObjectExtension(material, KHR_TECHNIQUES_WEBGL);
17
- if (materialExtension) {
18
- // @ts-ignore TODO
19
- material.technique = Object.assign({}, materialExtension,
20
- // @ts-ignore
21
- techniques[materialExtension.technique]);
22
- // @ts-ignore TODO
23
- material.technique.values = resolveValues(material.technique, gltfScenegraph);
24
- }
25
- gltfScenegraph.removeObjectExtension(material, KHR_TECHNIQUES_WEBGL);
26
- }
27
- // Remove the top-level extension
28
- gltfScenegraph.removeExtension(KHR_TECHNIQUES_WEBGL);
29
- }
30
- }
31
- exports.decode = decode;
32
- // eslint-disable-next-line
33
- async function encode(gltfData, options) {
34
- // TODO
35
- }
36
- exports.encode = encode;
37
- function resolveTechniques(techniquesExtension,
38
- // programs: {[key: string]: any}[],
39
- // shaders: {[key: string]: any}[],
40
- // techniques: {[key: string]: any}[]
41
- gltfScenegraph) {
42
- const { programs = [], shaders = [], techniques = [] } = techniquesExtension;
43
- const textDecoder = new TextDecoder();
44
- shaders.forEach((shader) => {
45
- if (Number.isFinite(shader.bufferView)) {
46
- shader.code = textDecoder.decode(gltfScenegraph.getTypedArrayForBufferView(shader.bufferView));
47
- }
48
- else {
49
- // TODO: handle URI shader
50
- throw new Error('KHR_techniques_webgl: no shader code');
51
- }
52
- });
53
- programs.forEach((program) => {
54
- program.fragmentShader = shaders[program.fragmentShader];
55
- program.vertexShader = shaders[program.vertexShader];
56
- });
57
- techniques.forEach((technique) => {
58
- technique.program = programs[technique.program];
59
- });
60
- return techniques;
61
- }
62
- function resolveValues(technique, gltfScenegraph) {
63
- const values = Object.assign({}, technique.values);
64
- // merge values from uniforms
65
- Object.keys(technique.uniforms || {}).forEach((uniform) => {
66
- if (technique.uniforms[uniform].value && !(uniform in values)) {
67
- values[uniform] = technique.uniforms[uniform].value;
68
- }
69
- });
70
- // resolve textures
71
- Object.keys(values).forEach((uniform) => {
72
- if (typeof values[uniform] === 'object' && values[uniform].index !== undefined) {
73
- // Assume this is a texture
74
- // TODO: find if there are any other types that can be referenced
75
- values[uniform].texture = gltfScenegraph.getTexture(values[uniform].index);
76
- }
77
- });
78
- return values;
79
- }
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTypedArrayForImageData = exports.getTypedArrayForBufferView = void 0;
4
- // TODO - GLTFScenegraph should use these
5
- const assert_1 = require("../utils/assert");
6
- // accepts buffer view index or buffer view object
7
- // returns a `Uint8Array`
8
- function getTypedArrayForBufferView(json, buffers, bufferViewIndex) {
9
- const bufferView = json.bufferViews[bufferViewIndex];
10
- (0, assert_1.assert)(bufferView);
11
- // Get hold of the arrayBuffer
12
- const bufferIndex = bufferView.buffer;
13
- const binChunk = buffers[bufferIndex];
14
- (0, assert_1.assert)(binChunk);
15
- const byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset;
16
- return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength);
17
- }
18
- exports.getTypedArrayForBufferView = getTypedArrayForBufferView;
19
- // accepts accessor index or accessor object
20
- // returns a `Uint8Array`
21
- function getTypedArrayForImageData(json, buffers, imageIndex) {
22
- const image = json.images[imageIndex];
23
- const bufferViewIndex = json.bufferViews[image.bufferView];
24
- return getTypedArrayForBufferView(json, buffers, bufferViewIndex);
25
- }
26
- exports.getTypedArrayForImageData = getTypedArrayForImageData;
27
- /*
28
- // accepts accessor index or accessor object
29
- // returns a typed array with type that matches the types
30
- export function getTypedArrayForAccessor(accessor) {
31
- accessor = this.getAccessor(accessor);
32
- const bufferView = this.getBufferView(accessor.bufferView);
33
- const buffer = this.getBuffer(bufferView.buffer);
34
- const arrayBuffer = buffer.data;
35
-
36
- // Create a new typed array as a view into the combined buffer
37
- const {ArrayType, length} = getAccessorArrayTypeAndLength(accessor, bufferView);
38
- const byteOffset = bufferView.byteOffset + accessor.byteOffset;
39
- return new ArrayType(arrayBuffer, byteOffset, length);
40
- }
41
- */
@@ -1,73 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGLTFAccessor = exports.getGLTFAccessors = void 0;
4
- // TODO - remove
5
- const gltf_utils_1 = require("./gltf-utils");
6
- // Returns a fresh attributes object with glTF-standardized attributes names
7
- // Attributes that cannot be identified will not be included
8
- // Removes `indices` if present, as it should be stored separately from the attributes
9
- function getGLTFAccessors(attributes) {
10
- const accessors = {};
11
- for (const name in attributes) {
12
- const attribute = attributes[name];
13
- if (name !== 'indices') {
14
- const glTFAccessor = getGLTFAccessor(attribute);
15
- accessors[name] = glTFAccessor;
16
- }
17
- }
18
- return accessors;
19
- }
20
- exports.getGLTFAccessors = getGLTFAccessors;
21
- // Fix up a single accessor.
22
- // Input: typed array or a partial accessor object
23
- // Return: accessor object
24
- function getGLTFAccessor(attribute) {
25
- const { buffer, size, count } = getAccessorData(attribute);
26
- const glTFAccessor = {
27
- // glTF Accessor values
28
- // TODO: Instead of a bufferView index we could have an actual buffer (typed array)
29
- // bufferView: null,
30
- // TODO: Deprecate `value` in favor of bufferView?
31
- // @ts-ignore
32
- value: buffer,
33
- size,
34
- byteOffset: 0,
35
- count,
36
- type: (0, gltf_utils_1.getAccessorTypeFromSize)(size),
37
- componentType: (0, gltf_utils_1.getComponentTypeFromArray)(buffer)
38
- };
39
- return glTFAccessor;
40
- }
41
- exports.getGLTFAccessor = getGLTFAccessor;
42
- // export function getGLTFAttribute(data, gltfAttributeName): GLTFAccessor {
43
- // return data.attributes[data.glTFAttributeMap[gltfAttributeName]];
44
- // }
45
- function getAccessorData(attribute) {
46
- let buffer = attribute;
47
- let size = 1;
48
- let count = 0;
49
- if (attribute && attribute.value) {
50
- buffer = attribute.value;
51
- size = attribute.size || 1;
52
- }
53
- if (buffer) {
54
- if (!ArrayBuffer.isView(buffer)) {
55
- buffer = toTypedArray(buffer, Float32Array);
56
- }
57
- count = buffer.length / size;
58
- }
59
- return { buffer, size, count };
60
- }
61
- // Convert non-typed arrays to arrays of specified format
62
- function toTypedArray(array, ArrayType, convertTypedArrays = false) {
63
- if (!array) {
64
- return null;
65
- }
66
- if (Array.isArray(array)) {
67
- return new ArrayType(array);
68
- }
69
- if (convertTypedArrays && !(array instanceof ArrayType)) {
70
- return new ArrayType(array);
71
- }
72
- return array;
73
- }
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGLEnumFromSamplerParameter = exports.getSizeFromAccessorType = exports.getBytesFromComponentType = exports.BYTES = exports.COMPONENTS = void 0;
4
- exports.COMPONENTS = {
5
- SCALAR: 1,
6
- VEC2: 2,
7
- VEC3: 3,
8
- VEC4: 4,
9
- MAT2: 4,
10
- MAT3: 9,
11
- MAT4: 16
12
- };
13
- exports.BYTES = {
14
- 5120: 1,
15
- 5121: 1,
16
- 5122: 2,
17
- 5123: 2,
18
- 5125: 4,
19
- 5126: 4 // FLOAT
20
- };
21
- // ENUM LOOKUP
22
- function getBytesFromComponentType(componentType) {
23
- return exports.BYTES[componentType];
24
- }
25
- exports.getBytesFromComponentType = getBytesFromComponentType;
26
- function getSizeFromAccessorType(type) {
27
- return exports.COMPONENTS[type];
28
- }
29
- exports.getSizeFromAccessorType = getSizeFromAccessorType;
30
- function getGLEnumFromSamplerParameter(parameter) {
31
- const GL_TEXTURE_MAG_FILTER = 0x2800;
32
- const GL_TEXTURE_MIN_FILTER = 0x2801;
33
- const GL_TEXTURE_WRAP_S = 0x2802;
34
- const GL_TEXTURE_WRAP_T = 0x2803;
35
- const PARAMETER_MAP = {
36
- magFilter: GL_TEXTURE_MAG_FILTER,
37
- minFilter: GL_TEXTURE_MIN_FILTER,
38
- wrapS: GL_TEXTURE_WRAP_S,
39
- wrapT: GL_TEXTURE_WRAP_T
40
- };
41
- return PARAMETER_MAP[parameter];
42
- }
43
- exports.getGLEnumFromSamplerParameter = getGLEnumFromSamplerParameter;
@@ -1,90 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getMemoryUsageGLTF = exports.getAccessorArrayTypeAndLength = exports.getComponentTypeFromArray = exports.getAccessorTypeFromSize = void 0;
4
- const assert_1 = require("../utils/assert");
5
- /**
6
- * Memory needed to store texture and all mipmap levels 1 + 1/4 + 1/16 + 1/64 + ...
7
- * Minimum 1.33, but due to GPU layout may be 1.5
8
- */
9
- const MIPMAP_FACTOR = 1.33;
10
- const TYPES = ['SCALAR', 'VEC2', 'VEC3', 'VEC4'];
11
- const ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT = [
12
- [Int8Array, 5120],
13
- [Uint8Array, 5121],
14
- [Int16Array, 5122],
15
- [Uint16Array, 5123],
16
- [Uint32Array, 5125],
17
- [Float32Array, 5126],
18
- [Float64Array, 5130]
19
- ];
20
- const ARRAY_TO_COMPONENT_TYPE = new Map(ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT);
21
- const ATTRIBUTE_TYPE_TO_COMPONENTS = {
22
- SCALAR: 1,
23
- VEC2: 2,
24
- VEC3: 3,
25
- VEC4: 4,
26
- MAT2: 4,
27
- MAT3: 9,
28
- MAT4: 16
29
- };
30
- const ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE = {
31
- 5120: 1,
32
- 5121: 1,
33
- 5122: 2,
34
- 5123: 2,
35
- 5125: 4,
36
- 5126: 4
37
- };
38
- const ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = {
39
- 5120: Int8Array,
40
- 5121: Uint8Array,
41
- 5122: Int16Array,
42
- 5123: Uint16Array,
43
- 5125: Uint32Array,
44
- 5126: Float32Array
45
- };
46
- function getAccessorTypeFromSize(size) {
47
- const type = TYPES[size - 1];
48
- return type || TYPES[0];
49
- }
50
- exports.getAccessorTypeFromSize = getAccessorTypeFromSize;
51
- function getComponentTypeFromArray(typedArray) {
52
- const componentType = ARRAY_TO_COMPONENT_TYPE.get(typedArray.constructor);
53
- if (!componentType) {
54
- throw new Error('Illegal typed array');
55
- }
56
- return componentType;
57
- }
58
- exports.getComponentTypeFromArray = getComponentTypeFromArray;
59
- function getAccessorArrayTypeAndLength(accessor, bufferView) {
60
- const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[accessor.componentType];
61
- const components = ATTRIBUTE_TYPE_TO_COMPONENTS[accessor.type];
62
- const bytesPerComponent = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[accessor.componentType];
63
- const length = accessor.count * components;
64
- const byteLength = accessor.count * components * bytesPerComponent;
65
- (0, assert_1.assert)(byteLength >= 0 && byteLength <= bufferView.byteLength);
66
- return { ArrayType, length, byteLength };
67
- }
68
- exports.getAccessorArrayTypeAndLength = getAccessorArrayTypeAndLength;
69
- /**
70
- * Calculate the GPU memory used by a GLTF tile, for both buffer and texture memory
71
- * @param gltf - the gltf content of a GLTF tile
72
- * @returns - total memory usage in bytes
73
- */
74
- function getMemoryUsageGLTF(gltf) {
75
- let { images, bufferViews } = gltf;
76
- images = images || [];
77
- bufferViews = bufferViews || [];
78
- const imageBufferViews = images.map((i) => i.bufferView);
79
- bufferViews = bufferViews.filter((view) => !imageBufferViews.includes(view));
80
- const bufferMemory = bufferViews.reduce((acc, view) => acc + view.byteLength, 0);
81
- // Assume each pixel of the texture is 4 channel with mimmaps (which add 33%)
82
- // TODO correctly handle compressed textures
83
- const pixelCount = images.reduce((acc, image) => {
84
- // @ts-ignore
85
- const { width, height } = image.image;
86
- return acc + width * height;
87
- }, 0);
88
- return bufferMemory + Math.ceil(4 * pixelCount * MIPMAP_FACTOR);
89
- }
90
- exports.getMemoryUsageGLTF = getMemoryUsageGLTF;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveUrl = void 0;
4
- // Resolves a relative url against a baseUrl
5
- // If url is absolute, return it unchanged
6
- function resolveUrl(url, options) {
7
- // TODO: Use better logic to handle all protocols plus not delay on data
8
- const absolute = url.startsWith('data:') || url.startsWith('http:') || url.startsWith('https:');
9
- if (absolute) {
10
- return url;
11
- }
12
- const baseUrl = options.baseUri || options.uri;
13
- if (!baseUrl) {
14
- throw new Error(`'baseUri' must be provided to resolve relative url ${url}`);
15
- }
16
- return baseUrl.substr(0, baseUrl.lastIndexOf('/') + 1) + url;
17
- }
18
- exports.resolveUrl = resolveUrl;
@@ -1,166 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseGLBSync = exports.isGLB = void 0;
4
- const loader_utils_1 = require("@loaders.gl/loader-utils");
5
- /** Binary GLTF is little endian. */
6
- const LITTLE_ENDIAN = true;
7
- /** 'glTF' in Big-Endian ASCII */
8
- const MAGIC_glTF = 0x676c5446;
9
- const GLB_FILE_HEADER_SIZE = 12;
10
- const GLB_CHUNK_HEADER_SIZE = 8;
11
- const GLB_CHUNK_TYPE_JSON = 0x4e4f534a;
12
- const GLB_CHUNK_TYPE_BIN = 0x004e4942;
13
- const GLB_V1_CONTENT_FORMAT_JSON = 0x0;
14
- /** @deprecated - Backward compatibility for old xviz files */
15
- const GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED = 0;
16
- /** @deprecated - Backward compatibility for old xviz files */
17
- const GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED = 1;
18
- function getMagicString(dataView, byteOffset = 0) {
19
- return `\
20
- ${String.fromCharCode(dataView.getUint8(byteOffset + 0))}\
21
- ${String.fromCharCode(dataView.getUint8(byteOffset + 1))}\
22
- ${String.fromCharCode(dataView.getUint8(byteOffset + 2))}\
23
- ${String.fromCharCode(dataView.getUint8(byteOffset + 3))}`;
24
- }
25
- /** Check if the contents of an array buffer contains GLB byte markers */
26
- function isGLB(arrayBuffer, byteOffset = 0, options = {}) {
27
- const dataView = new DataView(arrayBuffer);
28
- // Check that GLB Header starts with the magic number
29
- const { magic = MAGIC_glTF } = options;
30
- const magic1 = dataView.getUint32(byteOffset, false);
31
- return magic1 === magic || magic1 === MAGIC_glTF;
32
- }
33
- exports.isGLB = isGLB;
34
- /**
35
- * Synchronously parse a GLB
36
- * @param glb - Target, Output is stored there
37
- * @param arrayBuffer - Input data
38
- * @param byteOffset - Offset into arrayBuffer to start parsing from (for "embedded" GLBs, e.g. in 3D tiles)
39
- * @param options
40
- * @returns
41
- */
42
- function parseGLBSync(glb, arrayBuffer, byteOffset = 0, options = {}) {
43
- // Check that GLB Header starts with the magic number
44
- const dataView = new DataView(arrayBuffer);
45
- // Compare format with GLBLoader documentation
46
- const type = getMagicString(dataView, byteOffset + 0);
47
- const version = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN); // Version 2 of binary glTF container format
48
- const byteLength = dataView.getUint32(byteOffset + 8, LITTLE_ENDIAN); // Total byte length of binary file
49
- Object.assign(glb, {
50
- // Put less important stuff in a header, to avoid clutter
51
- header: {
52
- byteOffset,
53
- byteLength,
54
- hasBinChunk: false
55
- },
56
- type,
57
- version,
58
- json: {},
59
- binChunks: []
60
- });
61
- byteOffset += GLB_FILE_HEADER_SIZE;
62
- switch (glb.version) {
63
- case 1:
64
- return parseGLBV1(glb, dataView, byteOffset);
65
- case 2:
66
- return parseGLBV2(glb, dataView, byteOffset, (options = {}));
67
- default:
68
- throw new Error(`Invalid GLB version ${glb.version}. Only supports version 1 and 2.`);
69
- }
70
- }
71
- exports.parseGLBSync = parseGLBSync;
72
- /**
73
- * Parse a V1 GLB
74
- * @param glb - target, output is stored in this object
75
- * @param dataView - Input, memory to be parsed
76
- * @param byteOffset - Offset of first byte of GLB data in the data view
77
- * @returns Number of bytes parsed (there could be additional non-GLB data after the GLB)
78
- */
79
- function parseGLBV1(glb, dataView, byteOffset) {
80
- // Sanity: ensure file is big enough to hold at least the headers
81
- (0, loader_utils_1.assert)(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE);
82
- // Explanation of GLB structure:
83
- // https://cloud.githubusercontent.com/assets/3479527/22600725/36b87122-ea55-11e6-9d40-6fd42819fcab.png
84
- const contentLength = dataView.getUint32(byteOffset + 0, LITTLE_ENDIAN); // Byte length of chunk
85
- const contentFormat = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN); // Chunk format as uint32
86
- byteOffset += GLB_CHUNK_HEADER_SIZE;
87
- // GLB v1 only supports a single chunk type
88
- (0, loader_utils_1.assert)(contentFormat === GLB_V1_CONTENT_FORMAT_JSON);
89
- parseJSONChunk(glb, dataView, byteOffset, contentLength);
90
- // No need to call the function padToBytes() from parseJSONChunk()
91
- byteOffset += contentLength;
92
- byteOffset += parseBINChunk(glb, dataView, byteOffset, glb.header.byteLength);
93
- return byteOffset;
94
- }
95
- /**
96
- * Parse a V2 GLB
97
- * @param glb - target, output is stored in this object
98
- * @param dataView - Input, memory to be parsed
99
- * @param byteOffset - Offset of first byte of GLB data in the data view
100
- * @returns Number of bytes parsed (there could be additional non-GLB data after the GLB)
101
- */
102
- function parseGLBV2(glb, dataView, byteOffset, options) {
103
- // Sanity: ensure file is big enough to hold at least the first chunk header
104
- (0, loader_utils_1.assert)(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE);
105
- parseGLBChunksSync(glb, dataView, byteOffset, options);
106
- return byteOffset + glb.header.byteLength;
107
- }
108
- /** Iterate over GLB chunks and parse them */
109
- function parseGLBChunksSync(glb, dataView, byteOffset, options) {
110
- // Per spec we must iterate over chunks, ignoring all except JSON and BIN
111
- // Iterate as long as there is space left for another chunk header
112
- while (byteOffset + 8 <= glb.header.byteLength) {
113
- const chunkLength = dataView.getUint32(byteOffset + 0, LITTLE_ENDIAN); // Byte length of chunk
114
- const chunkFormat = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN); // Chunk format as uint32
115
- byteOffset += GLB_CHUNK_HEADER_SIZE;
116
- // Per spec we must iterate over chunks, ignoring all except JSON and BIN
117
- switch (chunkFormat) {
118
- case GLB_CHUNK_TYPE_JSON:
119
- parseJSONChunk(glb, dataView, byteOffset, chunkLength);
120
- break;
121
- case GLB_CHUNK_TYPE_BIN:
122
- parseBINChunk(glb, dataView, byteOffset, chunkLength);
123
- break;
124
- // Backward compatibility for very old xviz files
125
- case GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED:
126
- if (!options.strict) {
127
- parseJSONChunk(glb, dataView, byteOffset, chunkLength);
128
- }
129
- break;
130
- case GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED:
131
- if (!options.strict) {
132
- parseBINChunk(glb, dataView, byteOffset, chunkLength);
133
- }
134
- break;
135
- default:
136
- // Ignore, per spec
137
- // console.warn(`Unknown GLB chunk type`); // eslint-disable-line
138
- break;
139
- }
140
- byteOffset += (0, loader_utils_1.padToNBytes)(chunkLength, 4);
141
- }
142
- return byteOffset;
143
- }
144
- /* Parse a GLB JSON chunk */
145
- function parseJSONChunk(glb, dataView, byteOffset, chunkLength) {
146
- // 1. Create a "view" of the binary encoded JSON data inside the GLB
147
- const jsonChunk = new Uint8Array(dataView.buffer, byteOffset, chunkLength);
148
- // 2. Decode the JSON binary array into clear text
149
- const textDecoder = new TextDecoder('utf8');
150
- const jsonText = textDecoder.decode(jsonChunk);
151
- // 3. Parse the JSON text into a JavaScript data structure
152
- glb.json = JSON.parse(jsonText);
153
- return (0, loader_utils_1.padToNBytes)(chunkLength, 4);
154
- }
155
- /** Parse a GLB BIN chunk */
156
- function parseBINChunk(glb, dataView, byteOffset, chunkLength) {
157
- // Note: BIN chunk can be optional
158
- glb.header.hasBinChunk = true;
159
- glb.binChunks.push({
160
- byteOffset,
161
- byteLength: chunkLength,
162
- arrayBuffer: dataView.buffer
163
- // TODO - copy, or create typed array view?
164
- });
165
- return (0, loader_utils_1.padToNBytes)(chunkLength, 4);
166
- }