@loaders.gl/gltf 4.0.0-alpha.6 → 4.0.0-alpha.7

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 (193) hide show
  1. package/dist/dist.min.js +1415 -1339
  2. package/dist/es5/glb-loader.js +2 -2
  3. package/dist/es5/glb-loader.js.map +1 -1
  4. package/dist/es5/glb-writer.js +3 -4
  5. package/dist/es5/glb-writer.js.map +1 -1
  6. package/dist/es5/gltf-loader.js +3 -3
  7. package/dist/es5/gltf-loader.js.map +1 -1
  8. package/dist/es5/index.js +9 -3
  9. package/dist/es5/index.js.map +1 -1
  10. package/dist/es5/lib/api/gltf-extensions.js.map +1 -1
  11. package/dist/es5/lib/api/gltf-scenegraph.js +47 -30
  12. package/dist/es5/lib/api/gltf-scenegraph.js.map +1 -1
  13. package/dist/es5/lib/api/post-process-gltf.js +164 -116
  14. package/dist/es5/lib/api/post-process-gltf.js.map +1 -1
  15. package/dist/es5/lib/encoders/encode-glb.js +1 -1
  16. package/dist/es5/lib/encoders/encode-glb.js.map +1 -1
  17. package/dist/es5/lib/encoders/encode-gltf.js +2 -3
  18. package/dist/es5/lib/encoders/encode-gltf.js.map +1 -1
  19. package/dist/es5/lib/extensions/EXT_meshopt_compression.js +3 -5
  20. package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -1
  21. package/dist/es5/lib/extensions/EXT_texture_webp.js +2 -3
  22. package/dist/es5/lib/extensions/EXT_texture_webp.js.map +1 -1
  23. package/dist/es5/lib/extensions/KHR_binary_gltf.js +2 -3
  24. package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +1 -1
  25. package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +6 -5
  26. package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
  27. package/dist/es5/lib/extensions/KHR_texture_basisu.js +3 -4
  28. package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -1
  29. package/dist/es5/lib/extensions/KHR_texture_transform.js +9 -8
  30. package/dist/es5/lib/extensions/KHR_texture_transform.js.map +1 -1
  31. package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +2 -2
  32. package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
  33. package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js +3 -3
  34. package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -1
  35. package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js +3 -3
  36. package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -1
  37. package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js +2 -2
  38. package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -1
  39. package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js.map +1 -1
  40. package/dist/es5/lib/gltf-utils/gltf-utils.js +24 -0
  41. package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -1
  42. package/dist/es5/lib/parsers/parse-glb.js +10 -10
  43. package/dist/es5/lib/parsers/parse-glb.js.map +1 -1
  44. package/dist/es5/lib/parsers/parse-gltf.js +6 -10
  45. package/dist/es5/lib/parsers/parse-gltf.js.map +1 -1
  46. package/dist/es5/lib/types/gltf-json-schema.js.map +1 -1
  47. package/dist/es5/lib/types/gltf-postprocessed-schema.js.map +1 -1
  48. package/dist/es5/lib/types/gltf-types.js.map +1 -1
  49. package/dist/es5/lib/utils/version.js +1 -1
  50. package/dist/esm/glb-loader.js +1 -1
  51. package/dist/esm/glb-loader.js.map +1 -1
  52. package/dist/esm/glb-writer.js +1 -1
  53. package/dist/esm/glb-writer.js.map +1 -1
  54. package/dist/esm/gltf-loader.js +3 -3
  55. package/dist/esm/gltf-loader.js.map +1 -1
  56. package/dist/esm/index.js +2 -1
  57. package/dist/esm/index.js.map +1 -1
  58. package/dist/esm/lib/api/gltf-extensions.js.map +1 -1
  59. package/dist/esm/lib/api/gltf-scenegraph.js +40 -29
  60. package/dist/esm/lib/api/gltf-scenegraph.js.map +1 -1
  61. package/dist/esm/lib/api/post-process-gltf.js +167 -112
  62. package/dist/esm/lib/api/post-process-gltf.js.map +1 -1
  63. package/dist/esm/lib/encoders/encode-glb.js +1 -1
  64. package/dist/esm/lib/encoders/encode-glb.js.map +1 -1
  65. package/dist/esm/lib/encoders/encode-gltf.js +1 -1
  66. package/dist/esm/lib/encoders/encode-gltf.js.map +1 -1
  67. package/dist/esm/lib/extensions/EXT_meshopt_compression.js +2 -3
  68. package/dist/esm/lib/extensions/EXT_meshopt_compression.js.map +1 -1
  69. package/dist/esm/lib/extensions/EXT_texture_webp.js +1 -1
  70. package/dist/esm/lib/extensions/EXT_texture_webp.js.map +1 -1
  71. package/dist/esm/lib/extensions/KHR_binary_gltf.js +1 -1
  72. package/dist/esm/lib/extensions/KHR_binary_gltf.js.map +1 -1
  73. package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js +5 -4
  74. package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
  75. package/dist/esm/lib/extensions/KHR_texture_basisu.js +2 -2
  76. package/dist/esm/lib/extensions/KHR_texture_basisu.js.map +1 -1
  77. package/dist/esm/lib/extensions/KHR_texture_transform.js +7 -6
  78. package/dist/esm/lib/extensions/KHR_texture_transform.js.map +1 -1
  79. package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js +1 -1
  80. package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
  81. package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js +1 -1
  82. package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -1
  83. package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js +1 -1
  84. package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -1
  85. package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js +1 -1
  86. package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -1
  87. package/dist/esm/lib/gltf-utils/gltf-attribute-utils.js.map +1 -1
  88. package/dist/esm/lib/gltf-utils/gltf-utils.js +20 -0
  89. package/dist/esm/lib/gltf-utils/gltf-utils.js.map +1 -1
  90. package/dist/esm/lib/parsers/parse-glb.js +10 -10
  91. package/dist/esm/lib/parsers/parse-glb.js.map +1 -1
  92. package/dist/esm/lib/parsers/parse-gltf.js +5 -6
  93. package/dist/esm/lib/parsers/parse-gltf.js.map +1 -1
  94. package/dist/esm/lib/types/gltf-json-schema.js.map +1 -1
  95. package/dist/esm/lib/types/gltf-postprocessed-schema.js.map +1 -1
  96. package/dist/esm/lib/types/gltf-types.js.map +1 -1
  97. package/dist/esm/lib/utils/version.js +1 -1
  98. package/dist/glb-loader.d.ts +2 -2
  99. package/dist/glb-loader.js +2 -5
  100. package/dist/glb-writer.d.ts.map +1 -1
  101. package/dist/glb-writer.js +4 -6
  102. package/dist/gltf-loader.d.ts +5 -5
  103. package/dist/gltf-loader.d.ts.map +1 -1
  104. package/dist/gltf-loader.js +3 -3
  105. package/dist/index.d.ts +8 -5
  106. package/dist/index.d.ts.map +1 -1
  107. package/dist/index.js +12 -5
  108. package/dist/lib/api/gltf-extensions.d.ts +1 -1
  109. package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
  110. package/dist/lib/api/gltf-scenegraph.d.ts +6 -4
  111. package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
  112. package/dist/lib/api/gltf-scenegraph.js +43 -30
  113. package/dist/lib/api/post-process-gltf.d.ts +4 -1
  114. package/dist/lib/api/post-process-gltf.d.ts.map +1 -1
  115. package/dist/lib/api/post-process-gltf.js +186 -123
  116. package/dist/lib/encoders/encode-glb.d.ts +13 -1
  117. package/dist/lib/encoders/encode-glb.d.ts.map +1 -1
  118. package/dist/lib/encoders/encode-glb.js +15 -4
  119. package/dist/lib/encoders/encode-gltf.js +2 -5
  120. package/dist/lib/extensions/EXT_meshopt_compression.d.ts +1 -1
  121. package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -1
  122. package/dist/lib/extensions/EXT_meshopt_compression.js +3 -7
  123. package/dist/lib/extensions/EXT_texture_webp.d.ts +1 -1
  124. package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -1
  125. package/dist/lib/extensions/EXT_texture_webp.js +2 -5
  126. package/dist/lib/extensions/KHR_binary_gltf.d.ts +1 -1
  127. package/dist/lib/extensions/KHR_binary_gltf.d.ts.map +1 -1
  128. package/dist/lib/extensions/KHR_binary_gltf.js +2 -5
  129. package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +1 -1
  130. package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -1
  131. package/dist/lib/extensions/KHR_draco_mesh_compression.js +5 -8
  132. package/dist/lib/extensions/KHR_texture_basisu.d.ts +1 -1
  133. package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -1
  134. package/dist/lib/extensions/KHR_texture_basisu.js +3 -6
  135. package/dist/lib/extensions/KHR_texture_transform.d.ts.map +1 -1
  136. package/dist/lib/extensions/KHR_texture_transform.js +7 -10
  137. package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +1 -1
  138. package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
  139. package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +2 -5
  140. package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts +1 -1
  141. package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts.map +1 -1
  142. package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +3 -6
  143. package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts +1 -1
  144. package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts.map +1 -1
  145. package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +3 -6
  146. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts +1 -1
  147. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts.map +1 -1
  148. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +2 -5
  149. package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts +1 -1
  150. package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts.map +1 -1
  151. package/dist/lib/gltf-utils/gltf-utils.d.ts +7 -0
  152. package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
  153. package/dist/lib/gltf-utils/gltf-utils.js +28 -1
  154. package/dist/lib/parsers/parse-glb.d.ts +15 -3
  155. package/dist/lib/parsers/parse-glb.d.ts.map +1 -1
  156. package/dist/lib/parsers/parse-glb.js +43 -18
  157. package/dist/lib/parsers/parse-gltf.d.ts +8 -4
  158. package/dist/lib/parsers/parse-gltf.d.ts.map +1 -1
  159. package/dist/lib/parsers/parse-gltf.js +13 -34
  160. package/dist/lib/types/gltf-json-schema.d.ts +151 -138
  161. package/dist/lib/types/gltf-json-schema.d.ts.map +1 -1
  162. package/dist/lib/types/gltf-postprocessed-schema.d.ts +174 -209
  163. package/dist/lib/types/gltf-postprocessed-schema.d.ts.map +1 -1
  164. package/dist/lib/types/gltf-postprocessed-schema.js +1 -1
  165. package/dist/lib/types/gltf-types.d.ts +18 -6
  166. package/dist/lib/types/gltf-types.d.ts.map +1 -1
  167. package/package.json +6 -6
  168. package/src/glb-loader.ts +3 -3
  169. package/src/glb-writer.ts +3 -1
  170. package/src/gltf-loader.ts +12 -8
  171. package/src/index.ts +32 -13
  172. package/src/lib/api/gltf-extensions.ts +1 -1
  173. package/src/lib/api/gltf-scenegraph.ts +55 -37
  174. package/src/lib/api/post-process-gltf.ts +275 -150
  175. package/src/lib/encoders/encode-glb.ts +15 -5
  176. package/src/lib/encoders/encode-gltf.ts +1 -1
  177. package/src/lib/extensions/EXT_meshopt_compression.ts +4 -6
  178. package/src/lib/extensions/EXT_texture_webp.ts +2 -2
  179. package/src/lib/extensions/KHR_binary_gltf.ts +2 -2
  180. package/src/lib/extensions/KHR_draco_mesh_compression.ts +7 -7
  181. package/src/lib/extensions/KHR_texture_basisu.ts +3 -3
  182. package/src/lib/extensions/KHR_texture_transform.ts +22 -19
  183. package/src/lib/extensions/deprecated/EXT_feature_metadata.ts +2 -2
  184. package/src/lib/extensions/deprecated/KHR_lights_punctual.ts +2 -2
  185. package/src/lib/extensions/deprecated/KHR_materials_unlit.ts +2 -2
  186. package/src/lib/extensions/deprecated/KHR_techniques_webgl.ts +2 -2
  187. package/src/lib/gltf-utils/gltf-attribute-utils.ts +1 -1
  188. package/src/lib/gltf-utils/gltf-utils.ts +31 -0
  189. package/src/lib/parsers/parse-glb.ts +50 -24
  190. package/src/lib/parsers/parse-gltf.ts +22 -16
  191. package/src/lib/types/gltf-json-schema.ts +165 -138
  192. package/src/lib/types/gltf-postprocessed-schema.ts +289 -212
  193. package/src/lib/types/gltf-types.ts +35 -59
@@ -2,11 +2,11 @@
2
2
  // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/EXT_TEXTURE_WEBP
3
3
  /* eslint-disable camelcase */
4
4
 
5
- import type {GLTF, GLTF_EXT_texture_webp} from '../types/gltf-types';
5
+ import type {GLTF, GLTF_EXT_texture_webp} from '../types/gltf-json-schema';
6
6
  import type {GLTFLoaderOptions} from '../../gltf-loader';
7
7
 
8
8
  import {isImageFormatSupported} from '@loaders.gl/images';
9
- import GLTFScenegraph from '../api/gltf-scenegraph';
9
+ import {GLTFScenegraph} from '../api/gltf-scenegraph';
10
10
 
11
11
  const EXT_TEXTURE_WEBP = 'EXT_texture_webp';
12
12
 
@@ -2,9 +2,9 @@
2
2
  // https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF
3
3
  /* eslint-disable camelcase */
4
4
 
5
- import type {GLTF, GLTF_KHR_binary_glTF} from '../types/gltf-types';
5
+ import type {GLTF, GLTF_KHR_binary_glTF} from '../types/gltf-json-schema';
6
6
 
7
- import GLTFScenegraph from '../api/gltf-scenegraph';
7
+ import {GLTFScenegraph} from '../api/gltf-scenegraph';
8
8
 
9
9
  const KHR_BINARY_GLTF = 'KHR_binary_glTF';
10
10
 
@@ -8,14 +8,14 @@ import type {
8
8
  GLTFAccessor,
9
9
  GLTFMeshPrimitive,
10
10
  GLTF_KHR_draco_mesh_compression
11
- } from '../types/gltf-types';
11
+ } from '../types/gltf-json-schema';
12
12
  import type {GLTFLoaderOptions} from '../../gltf-loader';
13
13
 
14
14
  import type {LoaderContext} from '@loaders.gl/loader-utils';
15
15
  import {DracoLoader} from '@loaders.gl/draco';
16
16
  import {DracoLoaderOptions, DracoMesh} from '@loaders.gl/draco';
17
17
  import {sliceArrayBuffer} from '@loaders.gl/loader-utils';
18
- import {default as Scenegraph} from '../api/gltf-scenegraph';
18
+ import {GLTFScenegraph} from '../api/gltf-scenegraph';
19
19
  import {getGLTFAccessors, getGLTFAccessor} from '../gltf-utils/gltf-attribute-utils';
20
20
 
21
21
  const KHR_DRACO_MESH_COMPRESSION = 'KHR_draco_mesh_compression';
@@ -28,7 +28,7 @@ export function preprocess(
28
28
  options: GLTFLoaderOptions,
29
29
  context: LoaderContext
30
30
  ): void {
31
- const scenegraph = new Scenegraph(gltfData);
31
+ const scenegraph = new GLTFScenegraph(gltfData);
32
32
  for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {
33
33
  if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {
34
34
  // TODO - Remove fallback accessors to make sure we don't load unnecessary buffers
@@ -45,7 +45,7 @@ export async function decode(
45
45
  return;
46
46
  }
47
47
 
48
- const scenegraph = new Scenegraph(gltfData);
48
+ const scenegraph = new GLTFScenegraph(gltfData);
49
49
  const promises: Promise<void>[] = [];
50
50
  for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {
51
51
  if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {
@@ -61,7 +61,7 @@ export async function decode(
61
61
  }
62
62
 
63
63
  export function encode(gltfData, options: GLTFLoaderOptions = {}): void {
64
- const scenegraph = new Scenegraph(gltfData);
64
+ const scenegraph = new GLTFScenegraph(gltfData);
65
65
 
66
66
  for (const mesh of scenegraph.json.meshes || []) {
67
67
  // eslint-disable-next-line camelcase
@@ -81,7 +81,7 @@ export function encode(gltfData, options: GLTFLoaderOptions = {}): void {
81
81
  // TODO - Implement fallback behavior per KHR_DRACO_MESH_COMPRESSION spec
82
82
 
83
83
  async function decompressPrimitive(
84
- scenegraph: Scenegraph,
84
+ scenegraph: GLTFScenegraph,
85
85
  primitive: GLTFMeshPrimitive,
86
86
  options: GLTFLoaderOptions,
87
87
  context: LoaderContext
@@ -128,7 +128,7 @@ async function decompressPrimitive(
128
128
  }
129
129
 
130
130
  // Extension has been processed, delete it
131
- // delete primitive.extensions[KHR_DRACO_MESH_COMPRESSION];
131
+ scenegraph.removeObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION);
132
132
 
133
133
  checkPrimitive(primitive);
134
134
  }
@@ -2,10 +2,10 @@
2
2
  // https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_basisu
3
3
  /* eslint-disable camelcase */
4
4
 
5
- import type {GLTF, GLTF_KHR_texture_basisu} from '../types/gltf-types';
5
+ import type {GLTF, GLTF_KHR_texture_basisu} from '../types/gltf-json-schema';
6
6
  import type {GLTFLoaderOptions} from '../../gltf-loader';
7
7
 
8
- import GLTFScenegraph from '../api/gltf-scenegraph';
8
+ import {GLTFScenegraph} from '../api/gltf-scenegraph';
9
9
 
10
10
  const KHR_TEXTURE_BASISU = 'KHR_texture_basisu';
11
11
 
@@ -28,8 +28,8 @@ export function preprocess(gltfData: {json: GLTF}, options: GLTFLoaderOptions):
28
28
  if (extension) {
29
29
  // TODO - if multiple texture extensions are present which one wins?
30
30
  texture.source = extension.source;
31
+ scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);
31
32
  }
32
- scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);
33
33
  }
34
34
 
35
35
  // Remove the top-level extension
@@ -3,18 +3,21 @@
3
3
  */
4
4
 
5
5
  import {Vector3, Matrix3} from '@math.gl/core';
6
- import type {GLTFMeshPrimitive, GLTFWithBuffers} from '../types/gltf-types';
6
+ import type {GLTFWithBuffers} from '../types/gltf-types';
7
+ import type {
8
+ GLTFMeshPrimitive,
9
+ GLTFAccessor,
10
+ GLTFBufferView,
11
+ GLTFMaterialNormalTextureInfo,
12
+ GLTFMaterialOcclusionTextureInfo,
13
+ GLTFTextureInfo
14
+ } from '../types/gltf-json-schema';
7
15
  import type {GLTFLoaderOptions} from '../../gltf-loader';
16
+
8
17
  import {getAccessorArrayTypeAndLength} from '../gltf-utils/gltf-utils';
9
18
  import {BYTES, COMPONENTS} from '../gltf-utils/gltf-constants';
10
- import {
11
- Accessor,
12
- BufferView,
13
- MaterialNormalTextureInfo,
14
- MaterialOcclusionTextureInfo,
15
- TextureInfo as GLTFTextureInfo
16
- } from '../types/gltf-json-schema';
17
- import GLTFScenegraph from '../api/gltf-scenegraph';
19
+ import {} from '../types/gltf-json-schema';
20
+ import {GLTFScenegraph} from '../api/gltf-scenegraph';
18
21
 
19
22
  /** Extension name */
20
23
  const EXT_MESHOPT_TRANSFORM = 'KHR_texture_transform';
@@ -38,8 +41,8 @@ type TextureInfo = {
38
41
  };
39
42
  /** Intersection of all GLTF textures */
40
43
  type CompoundGLTFTextureInfo = GLTFTextureInfo &
41
- MaterialNormalTextureInfo &
42
- MaterialOcclusionTextureInfo;
44
+ GLTFMaterialNormalTextureInfo &
45
+ GLTFMaterialOcclusionTextureInfo;
43
46
  /** Parameters for TEXCOORD transformation */
44
47
  type TransformParameters = {
45
48
  /** Original texCoord value https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#_textureinfo_texcoord */
@@ -57,8 +60,8 @@ type TransformParameters = {
57
60
  */
58
61
  export async function decode(gltfData: GLTFWithBuffers, options: GLTFLoaderOptions) {
59
62
  const gltfScenegraph = new GLTFScenegraph(gltfData);
60
- const extension = gltfScenegraph.getExtension(EXT_MESHOPT_TRANSFORM);
61
- if (!extension) {
63
+ const hasExtension = gltfScenegraph.hasExtension(EXT_MESHOPT_TRANSFORM);
64
+ if (!hasExtension) {
62
65
  return;
63
66
  }
64
67
  const materials = gltfData.json.materials || [];
@@ -220,8 +223,8 @@ function transformPrimitive(
220
223
  * @param newTexcoordArray typed array with data after transformation
221
224
  */
222
225
  function updateGltf(
223
- accessor: Accessor,
224
- bufferView: BufferView,
226
+ accessor: GLTFAccessor,
227
+ bufferView: GLTFBufferView,
225
228
  buffers: {arrayBuffer: ArrayBuffer; byteOffset: number; byteLength: number}[],
226
229
  newTexCoordArray: Float32Array
227
230
  ): void {
@@ -248,7 +251,7 @@ function updateGltf(
248
251
  */
249
252
  function createAttribute(
250
253
  newTexCoord: number,
251
- originalAccessor: Accessor,
254
+ originalAccessor: GLTFAccessor,
252
255
  primitive: GLTFMeshPrimitive,
253
256
  gltfData: GLTFWithBuffers,
254
257
  newTexCoordArray: Float32Array
@@ -288,8 +291,8 @@ function createAttribute(
288
291
  */
289
292
  function makeTransformationMatrix(extensionData: TextureInfo): Matrix3 {
290
293
  const {offset = [0, 0], rotation = 0, scale = [1, 1]} = extensionData;
291
- const translationMatirx = new Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1);
292
- const rotationMatirx = scratchRotationMatrix.set(
294
+ const translationMatrix = new Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1);
295
+ const rotationMatrix = scratchRotationMatrix.set(
293
296
  Math.cos(rotation),
294
297
  Math.sin(rotation),
295
298
  0,
@@ -301,5 +304,5 @@ function makeTransformationMatrix(extensionData: TextureInfo): Matrix3 {
301
304
  1
302
305
  );
303
306
  const scaleMatrix = scratchScaleMatrix.set(scale[0], 0, 0, 0, scale[1], 0, 0, 0, 1);
304
- return translationMatirx.multiplyRight(rotationMatirx).multiplyRight(scaleMatrix);
307
+ return translationMatrix.multiplyRight(rotationMatrix).multiplyRight(scaleMatrix);
305
308
  }
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable camelcase */
2
- import type {GLTF} from '../../types/gltf-types';
2
+ import type {GLTF} from '../../types/gltf-json-schema';
3
3
 
4
- import GLTFScenegraph from '../../api/gltf-scenegraph';
4
+ import {GLTFScenegraph} from '../../api/gltf-scenegraph';
5
5
  import {
6
6
  ClassProperty,
7
7
  EXT_feature_metadata_class_object,
@@ -1,10 +1,10 @@
1
1
  // GLTF EXTENSION: KHR_lights_punctual
2
2
  // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
3
3
 
4
- import type {GLTF} from '../../types/gltf-types';
4
+ import type {GLTF} from '../../types/gltf-json-schema';
5
5
 
6
6
  import {assert} from '../../utils/assert';
7
- import GLTFScenegraph from '../../api/gltf-scenegraph';
7
+ import {GLTFScenegraph} from '../../api/gltf-scenegraph';
8
8
 
9
9
  const KHR_LIGHTS_PUNCTUAL = 'KHR_lights_punctual';
10
10
 
@@ -1,9 +1,9 @@
1
1
  // GLTF EXTENSION: KHR_materials_unlit
2
2
  // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
3
3
 
4
- import type {GLTF} from '../../types/gltf-types';
4
+ import type {GLTF} from '../../types/gltf-json-schema';
5
5
 
6
- import GLTFScenegraph from '../../api/gltf-scenegraph';
6
+ import {GLTFScenegraph} from '../../api/gltf-scenegraph';
7
7
 
8
8
  const KHR_MATERIALS_UNLIT = 'KHR_materials_unlit';
9
9
 
@@ -1,9 +1,9 @@
1
1
  // GLTF EXTENSION: KHR_techniques_webgl
2
2
  // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_techniques_webgl
3
3
 
4
- import type {GLTF} from '../../types/gltf-types';
4
+ import type {GLTF} from '../../types/gltf-json-schema';
5
5
 
6
- import GLTFScenegraph from '../../api/gltf-scenegraph';
6
+ import {GLTFScenegraph} from '../../api/gltf-scenegraph';
7
7
 
8
8
  const KHR_TECHNIQUES_WEBGL = 'KHR_techniques_webgl';
9
9
 
@@ -1,5 +1,5 @@
1
1
  // import type {TypedArray} from '../types/loader-utils';
2
- import type {GLTFAccessor} from '../types/gltf-types';
2
+ import type {GLTFAccessor} from '../types/gltf-json-schema';
3
3
  // TODO - remove
4
4
  import {getAccessorTypeFromSize, getComponentTypeFromArray} from './gltf-utils';
5
5
 
@@ -1,4 +1,11 @@
1
1
  import {assert} from '../utils/assert';
2
+ import type {GLTFPostprocessed} from '../types/gltf-postprocessed-schema';
3
+
4
+ /**
5
+ * Memory needed to store texture and all mipmap levels 1 + 1/4 + 1/16 + 1/64 + ...
6
+ * Minimum 1.33, but due to GPU layout may be 1.5
7
+ */
8
+ const MIPMAP_FACTOR = 1.33;
2
9
 
3
10
  const TYPES = ['SCALAR', 'VEC2', 'VEC3', 'VEC4'];
4
11
 
@@ -77,3 +84,27 @@ export function getAccessorArrayTypeAndLength(accessor, bufferView) {
77
84
  assert(byteLength >= 0 && byteLength <= bufferView.byteLength);
78
85
  return {ArrayType, length, byteLength};
79
86
  }
87
+
88
+ /**
89
+ * Calculate the GPU memory used by a GLTF tile, for both buffer and texture memory
90
+ * @param gltf - the gltf content of a GLTF tile
91
+ * @returns - total memory usage in bytes
92
+ */
93
+ export function getMemoryUsageGLTF(gltf: GLTFPostprocessed): number {
94
+ let {images, bufferViews} = gltf;
95
+ images = images || [];
96
+ bufferViews = bufferViews || [];
97
+ const imageBufferViews = images.map((i) => i.bufferView);
98
+ bufferViews = bufferViews.filter((view) => !imageBufferViews.includes(view as any));
99
+
100
+ const bufferMemory = bufferViews.reduce((acc, view) => acc + view.byteLength, 0);
101
+
102
+ // Assume each pixel of the texture is 4 channel with mimmaps (which add 33%)
103
+ // TODO correctly handle compressed textures
104
+ const pixelCount = images.reduce((acc, image) => {
105
+ // @ts-ignore
106
+ const {width, height} = (image as any).image;
107
+ return acc + width * height;
108
+ }, 0);
109
+ return bufferMemory + Math.ceil(4 * pixelCount * MIPMAP_FACTOR);
110
+ }
@@ -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
- export type GLBParseOptions = {
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
- const MAGIC_glTF = 0x676c5446; // glTF in Big-Endian ASCII
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
- const LE = true; // Binary GLTF is little endian.
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
- // Check if a data view is a GLB
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: GLBParseOptions = {}
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
- export default function parseGLBSync(
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: GLBParseOptions = {}
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, LE); // Version 2 of binary glTF container format
59
- const byteLength = dataView.getUint32(byteOffset + 8, LE); // Total byte length of binary file
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 v1 and v2.`);
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, LE); // Byte length of chunk
97
- const contentFormat = dataView.getUint32(byteOffset + 4, LE); // Chunk format as uint32
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: GLBParseOptions
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: GLBParseOptions
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, LE); // Byte length of chunk
135
- const chunkFormat = dataView.getUint32(byteOffset + 4, LE); // Chunk format as uint32
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
- // Parse a GLB JSON chunk
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
- // Parse a GLB BIN chunk
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
- export type GLTFParseOptions = {
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
- // export type GLTFOptions = {
28
- // gltf?: GLTFParseOptions;
29
- // };
27
+ /** @deprecated not supported in v4. `postProcessGLTF()` must be called by the application */
28
+ postProcess?: false;
29
+ };
30
30
 
31
- export function isGLTF(arrayBuffer, options?): boolean {
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,7 +40,7 @@ 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});
@@ -64,11 +65,16 @@ export async function parseGLTF(
64
65
  // Parallelize image loading and buffer loading/extension decoding
65
66
  await Promise.all(promises);
66
67
 
67
- // Post processing resolves indices to objects, buffers
68
- return options?.gltf?.postProcess ? postProcessGLTF(gltf, options) : gltf;
68
+ return gltf;
69
69
  }
70
70
 
71
- // `data` - can be ArrayBuffer (GLB), ArrayBuffer (Binary JSON), String (JSON), or Object (parsed JSON)
71
+ /**
72
+ *
73
+ * @param gltf
74
+ * @param data - can be ArrayBuffer (GLB), ArrayBuffer (Binary JSON), String (JSON), or Object (parsed JSON)
75
+ * @param byteOffset
76
+ * @param options
77
+ */
72
78
  function parseGLTFContainerSync(gltf, data, byteOffset, options) {
73
79
  // Initialize gltf container
74
80
  if (options.uri) {