@loaders.gl/gltf 4.0.0-alpha.5 → 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.
- package/dist/bundle.js +2 -2
- package/dist/dist.min.js +3545 -2445
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/glb-loader.js +56 -0
- package/dist/es5/glb-loader.js.map +1 -0
- package/dist/es5/glb-writer.js +34 -0
- package/dist/es5/glb-writer.js.map +1 -0
- package/dist/es5/gltf-loader.js +81 -0
- package/dist/es5/gltf-loader.js.map +1 -0
- package/dist/es5/gltf-writer.js +35 -0
- package/dist/es5/gltf-writer.js.map +1 -0
- package/dist/es5/index.js +55 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/api/gltf-extensions.js +109 -0
- package/dist/es5/lib/api/gltf-extensions.js.map +1 -0
- package/dist/es5/lib/api/gltf-scenegraph.js +595 -0
- package/dist/es5/lib/api/gltf-scenegraph.js.map +1 -0
- package/dist/es5/lib/api/normalize-gltf-v1.js +331 -0
- package/dist/es5/lib/api/normalize-gltf-v1.js.map +1 -0
- package/dist/es5/lib/api/post-process-gltf.js +470 -0
- package/dist/es5/lib/api/post-process-gltf.js.map +1 -0
- package/dist/es5/lib/encoders/encode-glb.js +61 -0
- package/dist/es5/lib/encoders/encode-glb.js.map +1 -0
- package/dist/es5/lib/encoders/encode-gltf.js +20 -0
- package/dist/es5/lib/encoders/encode-gltf.js.map +1 -0
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js +94 -0
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -0
- package/dist/es5/lib/extensions/EXT_texture_webp.js +43 -0
- package/dist/es5/lib/extensions/EXT_texture_webp.js.map +1 -0
- package/dist/es5/lib/extensions/KHR_binary_gltf.js +39 -0
- package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +1 -0
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +247 -0
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -0
- package/dist/es5/lib/extensions/KHR_texture_basisu.js +36 -0
- package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -0
- package/dist/es5/lib/extensions/KHR_texture_transform.js +230 -0
- package/dist/es5/lib/extensions/KHR_texture_transform.js.map +1 -0
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +103 -0
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -0
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js +99 -0
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -0
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js +76 -0
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -0
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js +113 -0
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -0
- package/dist/es5/lib/gltf-utils/get-typed-array.js +23 -0
- package/dist/es5/lib/gltf-utils/get-typed-array.js.map +1 -0
- package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js +68 -0
- package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js.map +1 -0
- package/dist/es5/lib/gltf-utils/gltf-constants.js +48 -0
- package/dist/es5/lib/gltf-utils/gltf-constants.js.map +1 -0
- package/dist/es5/lib/gltf-utils/gltf-utils.js +86 -0
- package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -0
- package/dist/es5/lib/gltf-utils/resolve-url.js +18 -0
- package/dist/es5/lib/gltf-utils/resolve-url.js.map +1 -0
- package/dist/es5/lib/parsers/parse-glb.js +120 -0
- package/dist/es5/lib/parsers/parse-glb.js.map +1 -0
- package/dist/es5/lib/parsers/parse-gltf.js +283 -0
- package/dist/es5/lib/parsers/parse-gltf.js.map +1 -0
- package/dist/es5/lib/types/glb-types.js +2 -0
- package/dist/es5/lib/types/glb-types.js.map +1 -0
- package/dist/es5/lib/types/gltf-json-schema.js +2 -0
- package/dist/es5/lib/types/gltf-json-schema.js.map +1 -0
- package/dist/es5/lib/types/gltf-postprocessed-schema.js +2 -0
- package/dist/es5/lib/types/gltf-postprocessed-schema.js.map +1 -0
- package/dist/es5/lib/types/gltf-types.js +2 -0
- package/dist/es5/lib/types/gltf-types.js.map +1 -0
- package/dist/es5/lib/utils/assert.js +12 -0
- package/dist/es5/lib/utils/assert.js.map +1 -0
- package/dist/es5/lib/utils/version.js +9 -0
- package/dist/es5/lib/utils/version.js.map +1 -0
- package/dist/es5/meshopt/meshopt-decoder.js +215 -0
- package/dist/es5/meshopt/meshopt-decoder.js.map +1 -0
- package/dist/es5/webp/webp.js +83 -0
- package/dist/es5/webp/webp.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/glb-loader.js +31 -0
- package/dist/esm/glb-loader.js.map +1 -0
- package/dist/esm/glb-writer.js +27 -0
- package/dist/esm/glb-writer.js.map +1 -0
- package/dist/esm/gltf-loader.js +51 -0
- package/dist/esm/gltf-loader.js.map +1 -0
- package/dist/esm/gltf-writer.js +28 -0
- package/dist/esm/gltf-writer.js.map +1 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/api/gltf-extensions.js +35 -0
- package/dist/esm/lib/api/gltf-extensions.js.map +1 -0
- package/dist/esm/lib/api/gltf-scenegraph.js +452 -0
- package/dist/esm/lib/api/gltf-scenegraph.js.map +1 -0
- package/dist/esm/lib/api/normalize-gltf-v1.js +204 -0
- package/dist/esm/lib/api/normalize-gltf-v1.js.map +1 -0
- package/dist/esm/lib/api/post-process-gltf.js +396 -0
- package/dist/esm/lib/api/post-process-gltf.js.map +1 -0
- package/dist/esm/lib/encoders/encode-glb.js +54 -0
- package/dist/esm/lib/encoders/encode-glb.js.map +1 -0
- package/dist/esm/lib/encoders/encode-gltf.js +14 -0
- package/dist/esm/lib/encoders/encode-gltf.js.map +1 -0
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js +41 -0
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js.map +1 -0
- package/dist/esm/lib/extensions/EXT_texture_webp.js +25 -0
- package/dist/esm/lib/extensions/EXT_texture_webp.js.map +1 -0
- package/dist/esm/lib/extensions/KHR_binary_gltf.js +21 -0
- package/dist/esm/lib/extensions/KHR_binary_gltf.js.map +1 -0
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js +111 -0
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js.map +1 -0
- package/dist/esm/lib/extensions/KHR_texture_basisu.js +18 -0
- package/dist/esm/lib/extensions/KHR_texture_basisu.js.map +1 -0
- package/dist/esm/lib/extensions/KHR_texture_transform.js +182 -0
- package/dist/esm/lib/extensions/KHR_texture_transform.js.map +1 -0
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js +77 -0
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -0
- package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js +42 -0
- package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -0
- package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js +33 -0
- package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -0
- package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js +61 -0
- package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -0
- package/dist/esm/lib/gltf-utils/get-typed-array.js +16 -0
- package/dist/esm/lib/gltf-utils/get-typed-array.js.map +1 -0
- package/dist/esm/lib/gltf-utils/gltf-attribute-utils.js +62 -0
- package/dist/esm/lib/gltf-utils/gltf-attribute-utils.js.map +1 -0
- package/dist/esm/lib/gltf-utils/gltf-constants.js +37 -0
- package/dist/esm/lib/gltf-utils/gltf-constants.js.map +1 -0
- package/dist/esm/lib/gltf-utils/gltf-utils.js +74 -0
- package/dist/esm/lib/gltf-utils/gltf-utils.js.map +1 -0
- package/dist/esm/lib/gltf-utils/resolve-url.js +12 -0
- package/dist/esm/lib/gltf-utils/resolve-url.js.map +1 -0
- package/dist/esm/lib/parsers/parse-glb.js +114 -0
- package/dist/esm/lib/parsers/parse-glb.js.map +1 -0
- package/dist/esm/lib/parsers/parse-gltf.js +155 -0
- package/dist/esm/lib/parsers/parse-gltf.js.map +1 -0
- package/dist/esm/lib/types/glb-types.js +2 -0
- package/dist/esm/lib/types/glb-types.js.map +1 -0
- package/dist/esm/lib/types/gltf-json-schema.js +2 -0
- package/dist/esm/lib/types/gltf-json-schema.js.map +1 -0
- package/dist/esm/lib/types/gltf-postprocessed-schema.js +2 -0
- package/dist/esm/lib/types/gltf-postprocessed-schema.js.map +1 -0
- package/dist/esm/lib/types/gltf-types.js +2 -0
- package/dist/esm/lib/types/gltf-types.js.map +1 -0
- package/dist/esm/lib/utils/assert.js +6 -0
- package/dist/esm/lib/utils/assert.js.map +1 -0
- package/dist/esm/lib/utils/version.js +2 -0
- package/dist/esm/lib/utils/version.js.map +1 -0
- package/dist/esm/meshopt/meshopt-decoder.js +91 -0
- package/dist/esm/meshopt/meshopt-decoder.js.map +1 -0
- package/dist/esm/meshopt/meshopt-encoder.ts.disabled +409 -0
- package/dist/esm/webp/webp.js +25 -0
- package/dist/esm/webp/webp.js.map +1 -0
- package/dist/glb-loader.d.ts +5 -4
- package/dist/glb-loader.d.ts.map +1 -1
- package/dist/glb-loader.js +30 -28
- package/dist/glb-writer.d.ts +7 -16
- package/dist/glb-writer.d.ts.map +1 -1
- package/dist/glb-writer.js +32 -26
- package/dist/gltf-loader.d.ts +7 -6
- package/dist/gltf-loader.d.ts.map +1 -1
- package/dist/gltf-loader.js +46 -43
- package/dist/gltf-writer.d.ts +2 -2
- package/dist/gltf-writer.d.ts.map +1 -1
- package/dist/gltf-writer.js +29 -26
- package/dist/index.d.ts +8 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -7
- package/dist/lib/api/gltf-extensions.d.ts +7 -2
- package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
- package/dist/lib/api/gltf-extensions.js +79 -31
- package/dist/lib/api/gltf-scenegraph.d.ts +10 -14
- package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
- package/dist/lib/api/gltf-scenegraph.js +577 -513
- package/dist/lib/api/normalize-gltf-v1.d.ts.map +1 -1
- package/dist/lib/api/normalize-gltf-v1.js +278 -229
- package/dist/lib/api/post-process-gltf.d.ts +4 -1
- package/dist/lib/api/post-process-gltf.d.ts.map +1 -1
- package/dist/lib/api/post-process-gltf.js +385 -374
- package/dist/lib/encoders/encode-glb.d.ts +14 -1
- package/dist/lib/encoders/encode-glb.d.ts.map +1 -1
- package/dist/lib/encoders/encode-glb.js +67 -58
- package/dist/lib/encoders/encode-gltf.d.ts +18 -0
- package/dist/lib/encoders/encode-gltf.d.ts.map +1 -1
- package/dist/lib/encoders/encode-gltf.js +30 -12
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts +1 -4
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_meshopt_compression.js +35 -50
- package/dist/lib/extensions/EXT_texture_webp.d.ts +1 -1
- package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_texture_webp.js +32 -28
- 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 +36 -23
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +1 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.js +123 -111
- package/dist/lib/extensions/KHR_texture_basisu.d.ts +1 -1
- package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_basisu.js +26 -19
- package/dist/lib/extensions/KHR_texture_transform.d.ts +13 -0
- package/dist/lib/extensions/KHR_texture_transform.d.ts.map +1 -0
- package/dist/lib/extensions/KHR_texture_transform.js +227 -0
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +6 -0
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -0
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +115 -0
- 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 +54 -44
- 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 +39 -32
- 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 +73 -62
- package/dist/lib/gltf-utils/get-typed-array.js +39 -14
- 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 +65 -65
- package/dist/lib/gltf-utils/gltf-constants.d.ts +17 -0
- package/dist/lib/gltf-utils/gltf-constants.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-constants.js +38 -32
- package/dist/lib/gltf-utils/gltf-utils.d.ts +7 -0
- package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-utils.js +79 -45
- package/dist/lib/gltf-utils/resolve-url.js +17 -15
- package/dist/lib/parsers/parse-glb.d.ts +15 -3
- package/dist/lib/parsers/parse-glb.d.ts.map +1 -1
- package/dist/lib/parsers/parse-glb.js +143 -105
- package/dist/lib/parsers/parse-gltf.d.ts +8 -4
- package/dist/lib/parsers/parse-gltf.d.ts.map +1 -1
- package/dist/lib/parsers/parse-gltf.js +166 -154
- package/dist/lib/types/glb-types.d.ts +3 -3
- package/dist/lib/types/glb-types.d.ts.map +1 -1
- package/dist/lib/types/glb-types.js +2 -2
- package/dist/lib/types/gltf-json-schema.d.ts +530 -132
- package/dist/lib/types/gltf-json-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-json-schema.js +4 -2
- package/dist/lib/types/gltf-postprocessed-schema.d.ts +175 -210
- package/dist/lib/types/gltf-postprocessed-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-postprocessed-schema.js +4 -2
- package/dist/lib/types/gltf-types.d.ts +22 -7
- package/dist/lib/types/gltf-types.d.ts.map +1 -1
- package/dist/lib/types/gltf-types.js +3 -2
- package/dist/lib/utils/assert.js +11 -5
- package/dist/lib/utils/version.js +7 -2
- package/dist/meshopt/meshopt-decoder.js +97 -82
- package/dist/webp/webp.d.ts +1 -1
- package/dist/webp/webp.d.ts.map +1 -1
- package/dist/webp/webp.js +32 -23
- package/package.json +9 -8
- package/src/glb-loader.ts +4 -4
- package/src/glb-writer.ts +11 -3
- package/src/gltf-loader.ts +12 -8
- package/src/gltf-writer.ts +2 -2
- package/src/index.ts +34 -6
- package/src/lib/api/gltf-extensions.ts +14 -3
- package/src/lib/api/gltf-scenegraph.ts +61 -34
- package/src/lib/api/normalize-gltf-v1.ts +2 -1
- package/src/lib/api/post-process-gltf.ts +275 -150
- package/src/lib/encoders/encode-glb.ts +21 -4
- package/src/lib/encoders/encode-gltf.ts +19 -10
- package/src/lib/extensions/EXT_meshopt_compression.ts +16 -25
- package/src/lib/extensions/EXT_texture_webp.ts +5 -4
- package/src/lib/extensions/KHR_binary_gltf.ts +3 -3
- package/src/lib/extensions/KHR_draco_mesh_compression.ts +8 -8
- package/src/lib/extensions/KHR_texture_basisu.ts +4 -3
- package/src/lib/extensions/KHR_texture_transform.ts +308 -0
- package/src/lib/extensions/deprecated/EXT_feature_metadata.ts +163 -0
- package/src/lib/extensions/deprecated/KHR_lights_punctual.ts +2 -2
- package/src/lib/extensions/deprecated/KHR_materials_unlit.ts +5 -5
- package/src/lib/extensions/deprecated/KHR_techniques_webgl.ts +3 -2
- package/src/lib/gltf-utils/gltf-attribute-utils.ts +1 -1
- package/src/lib/gltf-utils/gltf-constants.ts +2 -2
- package/src/lib/gltf-utils/gltf-utils.ts +31 -0
- package/src/lib/parsers/parse-glb.ts +50 -24
- package/src/lib/parsers/parse-gltf.ts +32 -17
- package/src/lib/types/glb-types.ts +1 -1
- package/src/lib/types/gltf-json-schema.ts +582 -126
- package/src/lib/types/gltf-postprocessed-schema.ts +289 -212
- package/src/lib/types/gltf-types.ts +41 -44
- package/dist/bundle.js.map +0 -1
- 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_meshopt_compression.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/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/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-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/webp/webp.js.map +0 -1
- /package/dist/{meshopt → es5/meshopt}/meshopt-encoder.ts.disabled +0 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
2
|
+
import type {GLTF} from '../../types/gltf-json-schema';
|
|
3
|
+
|
|
4
|
+
import {GLTFScenegraph} from '../../api/gltf-scenegraph';
|
|
5
|
+
import {
|
|
6
|
+
ClassProperty,
|
|
7
|
+
EXT_feature_metadata_class_object,
|
|
8
|
+
EXT_feature_metadata_feature_table,
|
|
9
|
+
FeatureTableProperty,
|
|
10
|
+
GLTF_EXT_feature_metadata
|
|
11
|
+
} from '../../types/gltf-json-schema';
|
|
12
|
+
|
|
13
|
+
/** Extension name */
|
|
14
|
+
const EXT_FEATURE_METADATA = 'EXT_feature_metadata';
|
|
15
|
+
|
|
16
|
+
export const name = EXT_FEATURE_METADATA;
|
|
17
|
+
|
|
18
|
+
export async function decode(gltfData: {json: GLTF}): Promise<void> {
|
|
19
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
20
|
+
decodeExtFeatureMetadata(scenegraph);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Decodes feature metadata from extension
|
|
25
|
+
* @param scenegraph
|
|
26
|
+
*/
|
|
27
|
+
function decodeExtFeatureMetadata(scenegraph: GLTFScenegraph): void {
|
|
28
|
+
const extension: GLTF_EXT_feature_metadata | null = scenegraph.getExtension(EXT_FEATURE_METADATA);
|
|
29
|
+
const schemaClasses = extension?.schema?.classes;
|
|
30
|
+
const featureTables = extension?.featureTables;
|
|
31
|
+
const featureTextures = extension?.featureTextures;
|
|
32
|
+
|
|
33
|
+
if (featureTextures) {
|
|
34
|
+
/*
|
|
35
|
+
* TODO add support for featureTextures
|
|
36
|
+
* Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#feature-textures
|
|
37
|
+
*/
|
|
38
|
+
// eslint-disable-next-line no-console
|
|
39
|
+
console.warn('featureTextures is not yet supported in the "EXT_feature_metadata" extension.');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (schemaClasses && featureTables) {
|
|
43
|
+
for (const schemaName in schemaClasses) {
|
|
44
|
+
const schemaClass = schemaClasses[schemaName];
|
|
45
|
+
const featureTable = findFeatureTableByName(featureTables, schemaName);
|
|
46
|
+
|
|
47
|
+
if (featureTable) {
|
|
48
|
+
handleFeatureTableProperties(scenegraph, featureTable, schemaClass);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Navigate throw all properies in feature table and gets properties data.
|
|
56
|
+
* @param scenegraph
|
|
57
|
+
* @param featureTable
|
|
58
|
+
* @param schemaClass
|
|
59
|
+
*/
|
|
60
|
+
function handleFeatureTableProperties(
|
|
61
|
+
scenegraph: GLTFScenegraph,
|
|
62
|
+
featureTable: EXT_feature_metadata_feature_table,
|
|
63
|
+
schemaClass: EXT_feature_metadata_class_object
|
|
64
|
+
): void {
|
|
65
|
+
for (const propertyName in schemaClass.properties) {
|
|
66
|
+
const schemaProperty = schemaClass.properties[propertyName];
|
|
67
|
+
const featureTableProperty = featureTable?.properties?.[propertyName];
|
|
68
|
+
const numberOfFeatures = featureTable.count;
|
|
69
|
+
|
|
70
|
+
if (featureTableProperty) {
|
|
71
|
+
const data = getPropertyDataFromBinarySource(
|
|
72
|
+
scenegraph,
|
|
73
|
+
schemaProperty,
|
|
74
|
+
numberOfFeatures,
|
|
75
|
+
featureTableProperty
|
|
76
|
+
);
|
|
77
|
+
featureTableProperty.data = data;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Decode properties from binary sourse based on property type.
|
|
84
|
+
* @param scenegraph
|
|
85
|
+
* @param schemaProperty
|
|
86
|
+
* @param numberOfFeatures
|
|
87
|
+
* @param featureTableProperty
|
|
88
|
+
*/
|
|
89
|
+
function getPropertyDataFromBinarySource(
|
|
90
|
+
scenegraph: GLTFScenegraph,
|
|
91
|
+
schemaProperty: ClassProperty,
|
|
92
|
+
numberOfFeatures: number,
|
|
93
|
+
featureTableProperty: FeatureTableProperty
|
|
94
|
+
): Uint8Array | string[] {
|
|
95
|
+
const bufferView = featureTableProperty.bufferView;
|
|
96
|
+
// TODO think maybe we shouldn't get data only in Uint8Array format.
|
|
97
|
+
let data: Uint8Array | string[] = scenegraph.getTypedArrayForBufferView(bufferView);
|
|
98
|
+
|
|
99
|
+
switch (schemaProperty.type) {
|
|
100
|
+
case 'STRING': {
|
|
101
|
+
// stringOffsetBufferView should be available for string type.
|
|
102
|
+
const stringOffsetBufferView = featureTableProperty.stringOffsetBufferView!;
|
|
103
|
+
const offsetsData = scenegraph.getTypedArrayForBufferView(stringOffsetBufferView);
|
|
104
|
+
data = getStringAttributes(data, offsetsData, numberOfFeatures);
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
default:
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return data;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Find the feature table by class name.
|
|
115
|
+
* @param featureTables
|
|
116
|
+
* @param schemaClassName
|
|
117
|
+
*/
|
|
118
|
+
function findFeatureTableByName(
|
|
119
|
+
featureTables: {[key: string]: EXT_feature_metadata_feature_table},
|
|
120
|
+
schemaClassName: string
|
|
121
|
+
): EXT_feature_metadata_feature_table | null {
|
|
122
|
+
for (const featureTableName in featureTables) {
|
|
123
|
+
const featureTable = featureTables[featureTableName];
|
|
124
|
+
|
|
125
|
+
if (featureTable.class === schemaClassName) {
|
|
126
|
+
return featureTable;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Getting string attributes from binary data.
|
|
135
|
+
* Spec - https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata#strings
|
|
136
|
+
* @param data
|
|
137
|
+
* @param offsetsData
|
|
138
|
+
* @param stringsCount
|
|
139
|
+
*/
|
|
140
|
+
function getStringAttributes(
|
|
141
|
+
data: Uint8Array,
|
|
142
|
+
offsetsData: Uint8Array,
|
|
143
|
+
stringsCount: number
|
|
144
|
+
): string[] {
|
|
145
|
+
const stringsArray: string[] = [];
|
|
146
|
+
const textDecoder = new TextDecoder('utf8');
|
|
147
|
+
|
|
148
|
+
let stringOffset = 0;
|
|
149
|
+
const bytesPerStringSize = 4;
|
|
150
|
+
|
|
151
|
+
for (let index = 0; index < stringsCount; index++) {
|
|
152
|
+
// TODO check if it is multiplication on bytesPerStringSize is valid operation?
|
|
153
|
+
const stringByteSize =
|
|
154
|
+
offsetsData[(index + 1) * bytesPerStringSize] - offsetsData[index * bytesPerStringSize];
|
|
155
|
+
const stringData = data.subarray(stringOffset, stringByteSize + stringOffset);
|
|
156
|
+
const stringAttribute = textDecoder.decode(stringData);
|
|
157
|
+
|
|
158
|
+
stringsArray.push(stringAttribute);
|
|
159
|
+
stringOffset += stringByteSize;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return stringsArray;
|
|
163
|
+
}
|
|
@@ -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-
|
|
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-
|
|
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
|
|
|
@@ -13,9 +13,6 @@ export async function decode(gltfData: {json: GLTF}): Promise<void> {
|
|
|
13
13
|
const gltfScenegraph = new GLTFScenegraph(gltfData);
|
|
14
14
|
const {json} = gltfScenegraph;
|
|
15
15
|
|
|
16
|
-
// Remove the top-level extension
|
|
17
|
-
gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT);
|
|
18
|
-
|
|
19
16
|
// Any nodes that have the extension, add lights field pointing to light object
|
|
20
17
|
// and remove the extension
|
|
21
18
|
for (const material of json.materials || []) {
|
|
@@ -26,6 +23,9 @@ export async function decode(gltfData: {json: GLTF}): Promise<void> {
|
|
|
26
23
|
}
|
|
27
24
|
gltfScenegraph.removeObjectExtension(material, KHR_MATERIALS_UNLIT);
|
|
28
25
|
}
|
|
26
|
+
|
|
27
|
+
// Remove the top-level extension
|
|
28
|
+
gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export function encode(gltfData) {
|
|
@@ -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-
|
|
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
|
|
|
@@ -33,6 +33,7 @@ export async function decode(gltfData: {json: GLTF}): Promise<void> {
|
|
|
33
33
|
gltfScenegraph.removeObjectExtension(material, KHR_TECHNIQUES_WEBGL);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
// Remove the top-level extension
|
|
36
37
|
gltfScenegraph.removeExtension(KHR_TECHNIQUES_WEBGL);
|
|
37
38
|
}
|
|
38
39
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// import type {TypedArray} from '../types/loader-utils';
|
|
2
|
-
import type {GLTFAccessor} from '../types/gltf-
|
|
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,4 @@
|
|
|
1
|
-
const COMPONENTS = {
|
|
1
|
+
export const COMPONENTS = {
|
|
2
2
|
SCALAR: 1,
|
|
3
3
|
VEC2: 2,
|
|
4
4
|
VEC3: 3,
|
|
@@ -8,7 +8,7 @@ const COMPONENTS = {
|
|
|
8
8
|
MAT4: 16
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
const BYTES = {
|
|
11
|
+
export const BYTES = {
|
|
12
12
|
5120: 1, // BYTE
|
|
13
13
|
5121: 1, // UNSIGNED_BYTE
|
|
14
14
|
5122: 2, // SHORT
|
|
@@ -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
|
-
|
|
7
|
+
/** Options for parsing a GLB */
|
|
8
|
+
export type ParseGLBOptions = {
|
|
9
|
+
/** @deprecated This option was used by XVIZ protocol to define a non-standard magic number */
|
|
8
10
|
magic?: number;
|
|
11
|
+
/** @deprecated This option was used by XVIZ protocol to embed non-standard chunks */
|
|
9
12
|
strict?: boolean;
|
|
10
13
|
};
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
/** Binary GLTF is little endian. */
|
|
16
|
+
const LITTLE_ENDIAN = true;
|
|
13
17
|
|
|
18
|
+
/** 'glTF' in Big-Endian ASCII */
|
|
19
|
+
const MAGIC_glTF = 0x676c5446;
|
|
14
20
|
const GLB_FILE_HEADER_SIZE = 12;
|
|
15
21
|
const GLB_CHUNK_HEADER_SIZE = 8;
|
|
16
|
-
|
|
17
22
|
const GLB_CHUNK_TYPE_JSON = 0x4e4f534a;
|
|
18
23
|
const GLB_CHUNK_TYPE_BIN = 0x004e4942;
|
|
19
|
-
const GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED = 0; // DEPRECATED - Backward compatibility for old xviz files
|
|
20
|
-
const GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED = 1; // DEPRECATED - Backward compatibility for old xviz files
|
|
21
|
-
|
|
22
24
|
const GLB_V1_CONTENT_FORMAT_JSON = 0x0;
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
/** @deprecated - Backward compatibility for old xviz files */
|
|
27
|
+
const GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED = 0;
|
|
28
|
+
/** @deprecated - Backward compatibility for old xviz files */
|
|
29
|
+
const GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED = 1;
|
|
25
30
|
|
|
26
31
|
function getMagicString(dataView, byteOffset = 0) {
|
|
27
32
|
return `\
|
|
@@ -31,11 +36,11 @@ ${String.fromCharCode(dataView.getUint8(byteOffset + 2))}\
|
|
|
31
36
|
${String.fromCharCode(dataView.getUint8(byteOffset + 3))}`;
|
|
32
37
|
}
|
|
33
38
|
|
|
34
|
-
|
|
39
|
+
/** Check if the contents of an array buffer contains GLB byte markers */
|
|
35
40
|
export function isGLB(
|
|
36
41
|
arrayBuffer: ArrayBuffer,
|
|
37
42
|
byteOffset: number = 0,
|
|
38
|
-
options:
|
|
43
|
+
options: ParseGLBOptions = {}
|
|
39
44
|
): boolean {
|
|
40
45
|
const dataView = new DataView(arrayBuffer);
|
|
41
46
|
// Check that GLB Header starts with the magic number
|
|
@@ -44,19 +49,27 @@ export function isGLB(
|
|
|
44
49
|
return magic1 === magic || magic1 === MAGIC_glTF;
|
|
45
50
|
}
|
|
46
51
|
|
|
47
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Synchronously parse a GLB
|
|
54
|
+
* @param glb - Target, Output is stored there
|
|
55
|
+
* @param arrayBuffer - Input data
|
|
56
|
+
* @param byteOffset - Offset into arrayBuffer to start parsing from (for "embedded" GLBs, e.g. in 3D tiles)
|
|
57
|
+
* @param options
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
export function parseGLBSync(
|
|
48
61
|
glb: GLB,
|
|
49
62
|
arrayBuffer: ArrayBuffer,
|
|
50
63
|
byteOffset: number = 0,
|
|
51
|
-
options:
|
|
64
|
+
options: ParseGLBOptions = {}
|
|
52
65
|
) {
|
|
53
66
|
// Check that GLB Header starts with the magic number
|
|
54
67
|
const dataView = new DataView(arrayBuffer);
|
|
55
68
|
|
|
56
69
|
// Compare format with GLBLoader documentation
|
|
57
70
|
const type = getMagicString(dataView, byteOffset + 0);
|
|
58
|
-
const version = dataView.getUint32(byteOffset + 4,
|
|
59
|
-
const byteLength = dataView.getUint32(byteOffset + 8,
|
|
71
|
+
const version = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN); // Version 2 of binary glTF container format
|
|
72
|
+
const byteLength = dataView.getUint32(byteOffset + 8, LITTLE_ENDIAN); // Total byte length of binary file
|
|
60
73
|
|
|
61
74
|
Object.assign(glb, {
|
|
62
75
|
// Put less important stuff in a header, to avoid clutter
|
|
@@ -77,24 +90,29 @@ export default function parseGLBSync(
|
|
|
77
90
|
|
|
78
91
|
switch (glb.version) {
|
|
79
92
|
case 1:
|
|
80
|
-
// eslint-disable-next-line
|
|
81
93
|
return parseGLBV1(glb, dataView, byteOffset);
|
|
82
94
|
case 2:
|
|
83
|
-
// eslint-disable-next-line
|
|
84
95
|
return parseGLBV2(glb, dataView, byteOffset, (options = {}));
|
|
85
96
|
default:
|
|
86
|
-
throw new Error(`Invalid GLB version ${glb.version}. Only supports
|
|
97
|
+
throw new Error(`Invalid GLB version ${glb.version}. Only supports version 1 and 2.`);
|
|
87
98
|
}
|
|
88
99
|
}
|
|
89
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Parse a V1 GLB
|
|
103
|
+
* @param glb - target, output is stored in this object
|
|
104
|
+
* @param dataView - Input, memory to be parsed
|
|
105
|
+
* @param byteOffset - Offset of first byte of GLB data in the data view
|
|
106
|
+
* @returns Number of bytes parsed (there could be additional non-GLB data after the GLB)
|
|
107
|
+
*/
|
|
90
108
|
function parseGLBV1(glb: GLB, dataView: DataView, byteOffset: number): number {
|
|
91
109
|
// Sanity: ensure file is big enough to hold at least the headers
|
|
92
110
|
assert(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE);
|
|
93
111
|
|
|
94
112
|
// Explanation of GLB structure:
|
|
95
113
|
// https://cloud.githubusercontent.com/assets/3479527/22600725/36b87122-ea55-11e6-9d40-6fd42819fcab.png
|
|
96
|
-
const contentLength = dataView.getUint32(byteOffset + 0,
|
|
97
|
-
const contentFormat = dataView.getUint32(byteOffset + 4,
|
|
114
|
+
const contentLength = dataView.getUint32(byteOffset + 0, LITTLE_ENDIAN); // Byte length of chunk
|
|
115
|
+
const contentFormat = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN); // Chunk format as uint32
|
|
98
116
|
byteOffset += GLB_CHUNK_HEADER_SIZE;
|
|
99
117
|
|
|
100
118
|
// GLB v1 only supports a single chunk type
|
|
@@ -108,11 +126,18 @@ function parseGLBV1(glb: GLB, dataView: DataView, byteOffset: number): number {
|
|
|
108
126
|
return byteOffset;
|
|
109
127
|
}
|
|
110
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Parse a V2 GLB
|
|
131
|
+
* @param glb - target, output is stored in this object
|
|
132
|
+
* @param dataView - Input, memory to be parsed
|
|
133
|
+
* @param byteOffset - Offset of first byte of GLB data in the data view
|
|
134
|
+
* @returns Number of bytes parsed (there could be additional non-GLB data after the GLB)
|
|
135
|
+
*/
|
|
111
136
|
function parseGLBV2(
|
|
112
137
|
glb: GLB,
|
|
113
138
|
dataView: DataView,
|
|
114
139
|
byteOffset: number,
|
|
115
|
-
options:
|
|
140
|
+
options: ParseGLBOptions
|
|
116
141
|
): number {
|
|
117
142
|
// Sanity: ensure file is big enough to hold at least the first chunk header
|
|
118
143
|
assert(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE);
|
|
@@ -122,17 +147,18 @@ function parseGLBV2(
|
|
|
122
147
|
return byteOffset + glb.header.byteLength;
|
|
123
148
|
}
|
|
124
149
|
|
|
150
|
+
/** Iterate over GLB chunks and parse them */
|
|
125
151
|
function parseGLBChunksSync(
|
|
126
152
|
glb: GLB,
|
|
127
153
|
dataView: DataView,
|
|
128
154
|
byteOffset: number,
|
|
129
|
-
options:
|
|
155
|
+
options: ParseGLBOptions
|
|
130
156
|
) {
|
|
131
157
|
// Per spec we must iterate over chunks, ignoring all except JSON and BIN
|
|
132
158
|
// Iterate as long as there is space left for another chunk header
|
|
133
159
|
while (byteOffset + 8 <= glb.header.byteLength) {
|
|
134
|
-
const chunkLength = dataView.getUint32(byteOffset + 0,
|
|
135
|
-
const chunkFormat = dataView.getUint32(byteOffset + 4,
|
|
160
|
+
const chunkLength = dataView.getUint32(byteOffset + 0, LITTLE_ENDIAN); // Byte length of chunk
|
|
161
|
+
const chunkFormat = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN); // Chunk format as uint32
|
|
136
162
|
byteOffset += GLB_CHUNK_HEADER_SIZE;
|
|
137
163
|
|
|
138
164
|
// Per spec we must iterate over chunks, ignoring all except JSON and BIN
|
|
@@ -168,7 +194,7 @@ function parseGLBChunksSync(
|
|
|
168
194
|
return byteOffset;
|
|
169
195
|
}
|
|
170
196
|
|
|
171
|
-
|
|
197
|
+
/* Parse a GLB JSON chunk */
|
|
172
198
|
function parseJSONChunk(glb: GLB, dataView: DataView, byteOffset: number, chunkLength: number) {
|
|
173
199
|
// 1. Create a "view" of the binary encoded JSON data inside the GLB
|
|
174
200
|
const jsonChunk = new Uint8Array(dataView.buffer, byteOffset, chunkLength);
|
|
@@ -183,7 +209,7 @@ function parseJSONChunk(glb: GLB, dataView: DataView, byteOffset: number, chunkL
|
|
|
183
209
|
return padToNBytes(chunkLength, 4);
|
|
184
210
|
}
|
|
185
211
|
|
|
186
|
-
|
|
212
|
+
/** Parse a GLB BIN chunk */
|
|
187
213
|
function parseBINChunk(glb: GLB, dataView, byteOffset, chunkLength) {
|
|
188
214
|
// Note: BIN chunk can be optional
|
|
189
215
|
glb.header.hasBinChunk = true;
|
|
@@ -1,34 +1,35 @@
|
|
|
1
1
|
/* eslint-disable camelcase, max-statements, no-restricted-globals */
|
|
2
2
|
import type {LoaderContext} from '@loaders.gl/loader-utils';
|
|
3
|
-
import {BasisLoader, selectSupportedBasisFormat} from '@loaders.gl/textures';
|
|
4
3
|
import type {GLTFLoaderOptions} from '../../gltf-loader';
|
|
5
|
-
import type {GLB} from '../types/glb-types';
|
|
6
4
|
import type {GLTFWithBuffers} from '../types/gltf-types';
|
|
5
|
+
import type {GLB} from '../types/glb-types';
|
|
6
|
+
import type {ParseGLBOptions} from './parse-glb';
|
|
7
7
|
|
|
8
|
-
import {ImageLoader} from '@loaders.gl/images';
|
|
9
8
|
import {parseJSON, sliceArrayBuffer} from '@loaders.gl/loader-utils';
|
|
9
|
+
import {ImageLoader} from '@loaders.gl/images';
|
|
10
|
+
import {BasisLoader, selectSupportedBasisFormat} from '@loaders.gl/textures';
|
|
11
|
+
|
|
10
12
|
import {assert} from '../utils/assert';
|
|
13
|
+
import {isGLB, parseGLBSync} from './parse-glb';
|
|
11
14
|
import {resolveUrl} from '../gltf-utils/resolve-url';
|
|
12
15
|
import {getTypedArrayForBufferView} from '../gltf-utils/get-typed-array';
|
|
13
16
|
import {preprocessExtensions, decodeExtensions} from '../api/gltf-extensions';
|
|
14
17
|
import {normalizeGLTFV1} from '../api/normalize-gltf-v1';
|
|
15
|
-
import {postProcessGLTF} from '../api/post-process-gltf';
|
|
16
|
-
import parseGLBSync, {isGLB} from './parse-glb';
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
/** */
|
|
20
|
+
export type ParseGLTFOptions = ParseGLBOptions & {
|
|
19
21
|
normalize?: boolean;
|
|
20
22
|
loadImages?: boolean;
|
|
21
23
|
loadBuffers?: boolean;
|
|
22
24
|
decompressMeshes?: boolean;
|
|
23
|
-
postProcess?: boolean;
|
|
24
25
|
excludeExtensions?: string[];
|
|
25
|
-
};
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
/** @deprecated not supported in v4. `postProcessGLTF()` must be called by the application */
|
|
28
|
+
postProcess?: false;
|
|
29
|
+
};
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
/** Check if an array buffer appears to contain GLTF data */
|
|
32
|
+
export function isGLTF(arrayBuffer: ArrayBuffer, options?: ParseGLTFOptions): boolean {
|
|
32
33
|
const byteOffset = 0;
|
|
33
34
|
return isGLB(arrayBuffer, byteOffset, options);
|
|
34
35
|
}
|
|
@@ -39,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
|
-
|
|
68
|
-
return options?.gltf?.postProcess ? postProcessGLTF(gltf, options) : gltf;
|
|
68
|
+
return gltf;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
|
|
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) {
|
|
@@ -144,6 +150,12 @@ async function loadBuffers(gltf: GLTFWithBuffers, options, context: LoaderContex
|
|
|
144
150
|
};
|
|
145
151
|
|
|
146
152
|
delete buffer.uri;
|
|
153
|
+
} else if (gltf.buffers[i] === null) {
|
|
154
|
+
gltf.buffers[i] = {
|
|
155
|
+
arrayBuffer: new ArrayBuffer(buffer.byteLength),
|
|
156
|
+
byteOffset: 0,
|
|
157
|
+
byteLength: buffer.byteLength
|
|
158
|
+
};
|
|
147
159
|
}
|
|
148
160
|
}
|
|
149
161
|
}
|
|
@@ -195,10 +207,13 @@ async function loadImage(
|
|
|
195
207
|
|
|
196
208
|
let arrayBuffer;
|
|
197
209
|
|
|
198
|
-
if (image.uri) {
|
|
210
|
+
if (image.uri && !image.hasOwnProperty('bufferView')) {
|
|
199
211
|
const uri = resolveUrl(image.uri, options);
|
|
200
212
|
const response = await fetch(uri);
|
|
201
213
|
arrayBuffer = await response.arrayBuffer();
|
|
214
|
+
image.bufferView = {
|
|
215
|
+
data: arrayBuffer
|
|
216
|
+
};
|
|
202
217
|
}
|
|
203
218
|
|
|
204
219
|
if (Number.isFinite(image.bufferView)) {
|