@loaders.gl/gltf 4.0.0-alpha.1 → 4.0.0-alpha.11
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.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +2 -2
- package/dist/dist.min.js +5767 -0
- 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 +598 -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 +281 -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 +280 -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 +455 -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 +223 -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 +151 -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 +14 -0
- package/dist/glb-loader.d.ts.map +1 -0
- package/dist/glb-loader.js +30 -28
- package/dist/glb-writer.d.ts +13 -0
- package/dist/glb-writer.d.ts.map +1 -0
- package/dist/glb-writer.js +32 -26
- package/dist/gltf-loader.d.ts +19 -0
- package/dist/gltf-loader.d.ts.map +1 -0
- package/dist/gltf-loader.js +46 -43
- package/dist/gltf-writer.d.ts +25 -0
- package/dist/gltf-writer.d.ts.map +1 -0
- package/dist/gltf-writer.js +29 -26
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -7
- package/dist/lib/api/gltf-extensions.d.ts +31 -0
- package/dist/lib/api/gltf-extensions.d.ts.map +1 -0
- package/dist/lib/api/gltf-extensions.js +79 -31
- package/dist/lib/api/gltf-scenegraph.d.ts +180 -0
- package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -0
- package/dist/lib/api/gltf-scenegraph.js +578 -513
- package/dist/lib/api/normalize-gltf-v1.d.ts +2 -0
- package/dist/lib/api/normalize-gltf-v1.d.ts.map +1 -0
- package/dist/lib/api/normalize-gltf-v1.js +278 -226
- package/dist/lib/api/post-process-gltf.d.ts +5 -0
- package/dist/lib/api/post-process-gltf.d.ts.map +1 -0
- package/dist/lib/api/post-process-gltf.js +386 -345
- package/dist/lib/encoders/encode-glb.d.ts +15 -0
- package/dist/lib/encoders/encode-glb.d.ts.map +1 -0
- package/dist/lib/encoders/encode-glb.js +67 -58
- package/dist/lib/encoders/encode-gltf.d.ts +20 -0
- package/dist/lib/encoders/encode-gltf.d.ts.map +1 -0
- package/dist/lib/encoders/encode-gltf.js +30 -12
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts +7 -0
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -0
- package/dist/lib/extensions/EXT_meshopt_compression.js +35 -50
- package/dist/lib/extensions/EXT_texture_webp.d.ts +12 -0
- package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -0
- package/dist/lib/extensions/EXT_texture_webp.js +32 -28
- package/dist/lib/extensions/KHR_binary_gltf.d.ts +7 -0
- package/dist/lib/extensions/KHR_binary_gltf.d.ts.map +1 -0
- package/dist/lib/extensions/KHR_binary_gltf.js +36 -23
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +13 -0
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -0
- package/dist/lib/extensions/KHR_draco_mesh_compression.js +123 -111
- package/dist/lib/extensions/KHR_texture_basisu.d.ts +12 -0
- package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -0
- 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 +7 -0
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -0
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +290 -0
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts +7 -0
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts.map +1 -0
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +54 -44
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts +7 -0
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts.map +1 -0
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +39 -32
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts +7 -0
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts.map +1 -0
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +73 -62
- package/dist/lib/gltf-utils/get-typed-array.d.ts +3 -0
- package/dist/lib/gltf-utils/get-typed-array.d.ts.map +1 -0
- package/dist/lib/gltf-utils/get-typed-array.js +39 -14
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts +6 -0
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts.map +1 -0
- package/dist/lib/gltf-utils/gltf-attribute-utils.js +65 -65
- package/dist/lib/gltf-utils/gltf-constants.d.ts +21 -0
- package/dist/lib/gltf-utils/gltf-constants.d.ts.map +1 -0
- package/dist/lib/gltf-utils/gltf-constants.js +38 -32
- package/dist/lib/gltf-utils/gltf-utils.d.ts +15 -0
- package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -0
- package/dist/lib/gltf-utils/gltf-utils.js +79 -45
- package/dist/lib/gltf-utils/resolve-url.d.ts +2 -0
- package/dist/lib/gltf-utils/resolve-url.d.ts.map +1 -0
- package/dist/lib/gltf-utils/resolve-url.js +17 -15
- package/dist/lib/parsers/parse-glb.d.ts +20 -0
- package/dist/lib/parsers/parse-glb.d.ts.map +1 -0
- package/dist/lib/parsers/parse-glb.js +143 -105
- package/dist/lib/parsers/parse-gltf.d.ts +18 -0
- package/dist/lib/parsers/parse-gltf.d.ts.map +1 -0
- package/dist/lib/parsers/parse-gltf.js +164 -155
- package/dist/lib/types/glb-types.d.ts +17 -0
- package/dist/lib/types/glb-types.d.ts.map +1 -0
- package/dist/lib/types/glb-types.js +2 -2
- package/dist/lib/types/gltf-json-schema.d.ts +1119 -0
- package/dist/lib/types/gltf-json-schema.d.ts.map +1 -0
- package/dist/lib/types/gltf-json-schema.js +4 -2
- package/dist/lib/types/gltf-postprocessed-schema.d.ts +651 -0
- package/dist/lib/types/gltf-postprocessed-schema.d.ts.map +1 -0
- package/dist/lib/types/gltf-postprocessed-schema.js +4 -2
- package/dist/lib/types/gltf-types.d.ts +26 -0
- package/dist/lib/types/gltf-types.d.ts.map +1 -0
- package/dist/lib/types/gltf-types.js +3 -2
- package/dist/lib/utils/assert.d.ts +2 -0
- package/dist/lib/utils/assert.d.ts.map +1 -0
- package/dist/lib/utils/assert.js +11 -5
- package/dist/lib/utils/version.d.ts +2 -0
- package/dist/lib/utils/version.d.ts.map +1 -0
- package/dist/lib/utils/version.js +7 -2
- package/dist/meshopt/meshopt-decoder.d.ts +6 -0
- package/dist/meshopt/meshopt-decoder.d.ts.map +1 -0
- package/dist/meshopt/meshopt-decoder.js +97 -82
- package/dist/webp/webp.d.ts +7 -0
- package/dist/webp/webp.d.ts.map +1 -0
- package/dist/webp/webp.js +32 -23
- package/package.json +11 -13
- 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 -5
- package/src/lib/api/gltf-extensions.ts +14 -3
- package/src/lib/api/gltf-scenegraph.ts +68 -40
- package/src/lib/api/{normalize-gltf-v1.js → normalize-gltf-v1.ts} +20 -17
- package/src/lib/api/post-process-gltf.ts +556 -0
- package/src/lib/encoders/{encode-glb.js → encode-glb.ts} +21 -4
- package/src/lib/encoders/encode-gltf.ts +34 -0
- 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 +6 -5
- package/src/lib/extensions/KHR_texture_transform.ts +308 -0
- package/src/lib/extensions/deprecated/EXT_feature_metadata.ts +404 -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 +38 -28
- package/src/lib/types/glb-types.ts +1 -1
- package/src/lib/types/gltf-json-schema.ts +585 -126
- package/src/lib/types/gltf-postprocessed-schema.ts +290 -212
- package/src/lib/types/gltf-types.ts +43 -43
- package/src/lib/utils/{assert.js → assert.ts} +1 -1
- 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/src/lib/api/post-process-gltf.js +0 -388
- package/src/lib/encoders/encode-gltf.js +0 -25
- /package/dist/{meshopt → es5/meshopt}/meshopt-encoder.ts.disabled +0 -0
- /package/src/lib/utils/{version.js → version.ts} +0 -0
|
@@ -1,128 +1,166 @@
|
|
|
1
|
-
|
|
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 */
|
|
2
8
|
const MAGIC_glTF = 0x676c5446;
|
|
3
9
|
const GLB_FILE_HEADER_SIZE = 12;
|
|
4
10
|
const GLB_CHUNK_HEADER_SIZE = 8;
|
|
5
11
|
const GLB_CHUNK_TYPE_JSON = 0x4e4f534a;
|
|
6
12
|
const GLB_CHUNK_TYPE_BIN = 0x004e4942;
|
|
13
|
+
const GLB_V1_CONTENT_FORMAT_JSON = 0x0;
|
|
14
|
+
/** @deprecated - Backward compatibility for old xviz files */
|
|
7
15
|
const GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED = 0;
|
|
16
|
+
/** @deprecated - Backward compatibility for old xviz files */
|
|
8
17
|
const GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED = 1;
|
|
9
|
-
const GLB_V1_CONTENT_FORMAT_JSON = 0x0;
|
|
10
|
-
const LE = true;
|
|
11
|
-
|
|
12
18
|
function getMagicString(dataView, byteOffset = 0) {
|
|
13
|
-
|
|
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))}`;
|
|
14
24
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
magic = MAGIC_glTF
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return magic1 === magic || magic1 === MAGIC_glTF;
|
|
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;
|
|
23
32
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
+
}
|
|
52
70
|
}
|
|
53
|
-
|
|
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
|
+
*/
|
|
54
79
|
function parseGLBV1(glb, dataView, byteOffset) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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;
|
|
64
94
|
}
|
|
65
|
-
|
|
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
|
+
*/
|
|
66
102
|
function parseGLBV2(glb, dataView, byteOffset, options) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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;
|
|
70
107
|
}
|
|
71
|
-
|
|
108
|
+
/** Iterate over GLB chunks and parse them */
|
|
72
109
|
function parseGLBChunksSync(glb, dataView, byteOffset, options) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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;
|
|
97
139
|
}
|
|
98
|
-
|
|
99
|
-
break;
|
|
100
|
-
|
|
101
|
-
default:
|
|
102
|
-
break;
|
|
140
|
+
byteOffset += (0, loader_utils_1.padToNBytes)(chunkLength, 4);
|
|
103
141
|
}
|
|
104
|
-
|
|
105
|
-
byteOffset += padToNBytes(chunkLength, 4);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return byteOffset;
|
|
142
|
+
return byteOffset;
|
|
109
143
|
}
|
|
110
|
-
|
|
144
|
+
/* Parse a GLB JSON chunk */
|
|
111
145
|
function parseJSONChunk(glb, dataView, byteOffset, chunkLength) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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);
|
|
117
154
|
}
|
|
118
|
-
|
|
155
|
+
/** Parse a GLB BIN chunk */
|
|
119
156
|
function parseBINChunk(glb, dataView, byteOffset, chunkLength) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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);
|
|
127
166
|
}
|
|
128
|
-
//# sourceMappingURL=parse-glb.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { LoaderContext } from '@loaders.gl/loader-utils';
|
|
2
|
+
import type { GLTFLoaderOptions } from '../../gltf-loader';
|
|
3
|
+
import type { GLTFWithBuffers } from '../types/gltf-types';
|
|
4
|
+
import type { ParseGLBOptions } from './parse-glb';
|
|
5
|
+
/** */
|
|
6
|
+
export type ParseGLTFOptions = ParseGLBOptions & {
|
|
7
|
+
normalize?: boolean;
|
|
8
|
+
loadImages?: boolean;
|
|
9
|
+
loadBuffers?: boolean;
|
|
10
|
+
decompressMeshes?: boolean;
|
|
11
|
+
excludeExtensions?: string[];
|
|
12
|
+
/** @deprecated not supported in v4. `postProcessGLTF()` must be called by the application */
|
|
13
|
+
postProcess?: false;
|
|
14
|
+
};
|
|
15
|
+
/** Check if an array buffer appears to contain GLTF data */
|
|
16
|
+
export declare function isGLTF(arrayBuffer: ArrayBuffer, options?: ParseGLTFOptions): boolean;
|
|
17
|
+
export declare function parseGLTF(gltf: GLTFWithBuffers, arrayBufferOrString: any, byteOffset: number | undefined, options: GLTFLoaderOptions, context: LoaderContext): Promise<GLTFWithBuffers>;
|
|
18
|
+
//# sourceMappingURL=parse-gltf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-gltf.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-gltf.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,aAAa,CAAC;AAajD,OAAO;AACP,MAAM,MAAM,gBAAgB,GAAG,eAAe,GAAG;IAC/C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE7B,6FAA6F;IAC7F,WAAW,CAAC,EAAE,KAAK,CAAC;CACrB,CAAC;AAEF,4DAA4D;AAC5D,wBAAgB,MAAM,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAGpF;AAED,wBAAsB,SAAS,CAC7B,IAAI,EAAE,eAAe,EACrB,mBAAmB,KAAA,EACnB,UAAU,oBAAI,EACd,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,eAAe,CAAC,CAqB1B"}
|
|
@@ -1,170 +1,179 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseGLTF = exports.isGLTF = void 0;
|
|
4
|
+
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
+
const images_1 = require("@loaders.gl/images");
|
|
6
|
+
const textures_1 = require("@loaders.gl/textures");
|
|
7
|
+
const assert_1 = require("../utils/assert");
|
|
8
|
+
const parse_glb_1 = require("./parse-glb");
|
|
9
|
+
const resolve_url_1 = require("../gltf-utils/resolve-url");
|
|
10
|
+
const get_typed_array_1 = require("../gltf-utils/get-typed-array");
|
|
11
|
+
const gltf_extensions_1 = require("../api/gltf-extensions");
|
|
12
|
+
const normalize_gltf_v1_1 = require("../api/normalize-gltf-v1");
|
|
13
|
+
/** Check if an array buffer appears to contain GLTF data */
|
|
14
|
+
function isGLTF(arrayBuffer, options) {
|
|
15
|
+
const byteOffset = 0;
|
|
16
|
+
return (0, parse_glb_1.isGLB)(arrayBuffer, byteOffset, options);
|
|
14
17
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
promises.push(promise);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const promise = decodeExtensions(gltf, options, context);
|
|
35
|
-
promises.push(promise);
|
|
36
|
-
await Promise.all(promises);
|
|
37
|
-
return options !== null && options !== void 0 && (_options$gltf4 = options.gltf) !== null && _options$gltf4 !== void 0 && _options$gltf4.postProcess ? postProcessGLTF(gltf, options) : gltf;
|
|
18
|
+
exports.isGLTF = isGLTF;
|
|
19
|
+
async function parseGLTF(gltf, arrayBufferOrString, byteOffset = 0, options, context) {
|
|
20
|
+
parseGLTFContainerSync(gltf, arrayBufferOrString, byteOffset, options);
|
|
21
|
+
(0, normalize_gltf_v1_1.normalizeGLTFV1)(gltf, { normalize: options?.gltf?.normalize });
|
|
22
|
+
(0, gltf_extensions_1.preprocessExtensions)(gltf, options, context);
|
|
23
|
+
// Load linked buffers asynchronously and decodes base64 buffers in parallel
|
|
24
|
+
if (options?.gltf?.loadBuffers && gltf.json.buffers) {
|
|
25
|
+
await loadBuffers(gltf, options, context);
|
|
26
|
+
}
|
|
27
|
+
// loadImages and decodeExtensions should not be running in parallel, because
|
|
28
|
+
// decodeExtensions uses data from images taken during the loadImages call.
|
|
29
|
+
if (options?.gltf?.loadImages) {
|
|
30
|
+
await loadImages(gltf, options, context);
|
|
31
|
+
}
|
|
32
|
+
await (0, gltf_extensions_1.decodeExtensions)(gltf, options, context);
|
|
33
|
+
return gltf;
|
|
38
34
|
}
|
|
39
|
-
|
|
35
|
+
exports.parseGLTF = parseGLTF;
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* @param gltf
|
|
39
|
+
* @param data - can be ArrayBuffer (GLB), ArrayBuffer (Binary JSON), String (JSON), or Object (parsed JSON)
|
|
40
|
+
* @param byteOffset
|
|
41
|
+
* @param options
|
|
42
|
+
*/
|
|
40
43
|
function parseGLTFContainerSync(gltf, data, byteOffset, options) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
44
|
+
// Initialize gltf container
|
|
45
|
+
if (options.uri) {
|
|
46
|
+
gltf.baseUri = options.uri;
|
|
47
|
+
}
|
|
48
|
+
// If data is binary and starting with magic bytes, assume binary JSON text, convert to string
|
|
49
|
+
if (data instanceof ArrayBuffer && !(0, parse_glb_1.isGLB)(data, byteOffset, options)) {
|
|
50
|
+
const textDecoder = new TextDecoder();
|
|
51
|
+
data = textDecoder.decode(data);
|
|
52
|
+
}
|
|
53
|
+
if (typeof data === 'string') {
|
|
54
|
+
// If string, try to parse as JSON
|
|
55
|
+
gltf.json = (0, loader_utils_1.parseJSON)(data);
|
|
56
|
+
}
|
|
57
|
+
else if (data instanceof ArrayBuffer) {
|
|
58
|
+
// If still ArrayBuffer, parse as GLB container
|
|
59
|
+
const glb = {};
|
|
60
|
+
byteOffset = (0, parse_glb_1.parseGLBSync)(glb, data, byteOffset, options.glb);
|
|
61
|
+
(0, assert_1.assert)(glb.type === 'glTF', `Invalid GLB magic string ${glb.type}`);
|
|
62
|
+
gltf._glb = glb;
|
|
63
|
+
gltf.json = glb.json;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
(0, assert_1.assert)(false, 'GLTF: must be ArrayBuffer or string');
|
|
67
|
+
}
|
|
68
|
+
// Populate buffers
|
|
69
|
+
// Create an external buffers array to hold binary data
|
|
70
|
+
const buffers = gltf.json.buffers || [];
|
|
71
|
+
gltf.buffers = new Array(buffers.length).fill(null);
|
|
72
|
+
// Populates JSON and some bin chunk info
|
|
73
|
+
if (gltf._glb && gltf._glb.header.hasBinChunk) {
|
|
74
|
+
const { binChunks } = gltf._glb;
|
|
75
|
+
gltf.buffers[0] = {
|
|
76
|
+
arrayBuffer: binChunks[0].arrayBuffer,
|
|
77
|
+
byteOffset: binChunks[0].byteOffset,
|
|
78
|
+
byteLength: binChunks[0].byteLength
|
|
79
|
+
};
|
|
80
|
+
// TODO - this modifies JSON and is a post processing thing
|
|
81
|
+
// gltf.json.buffers[0].data = gltf.buffers[0].arrayBuffer;
|
|
82
|
+
// gltf.json.buffers[0].byteOffset = gltf.buffers[0].byteOffset;
|
|
83
|
+
}
|
|
84
|
+
// Populate images
|
|
85
|
+
const images = gltf.json.images || [];
|
|
86
|
+
gltf.images = new Array(images.length).fill({});
|
|
78
87
|
}
|
|
79
|
-
|
|
88
|
+
/** Asynchronously fetch and parse buffers, store in buffers array outside of json
|
|
89
|
+
* TODO - traverse gltf and determine which buffers are actually needed
|
|
90
|
+
*/
|
|
80
91
|
async function loadBuffers(gltf, options, context) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
92
|
+
// TODO
|
|
93
|
+
const buffers = gltf.json.buffers || [];
|
|
94
|
+
for (let i = 0; i < buffers.length; ++i) {
|
|
95
|
+
const buffer = buffers[i];
|
|
96
|
+
if (buffer.uri) {
|
|
97
|
+
const { fetch } = context;
|
|
98
|
+
(0, assert_1.assert)(fetch);
|
|
99
|
+
const uri = (0, resolve_url_1.resolveUrl)(buffer.uri, options);
|
|
100
|
+
const response = await context?.fetch?.(uri);
|
|
101
|
+
const arrayBuffer = await response?.arrayBuffer?.();
|
|
102
|
+
gltf.buffers[i] = {
|
|
103
|
+
arrayBuffer,
|
|
104
|
+
byteOffset: 0,
|
|
105
|
+
byteLength: arrayBuffer.byteLength
|
|
106
|
+
};
|
|
107
|
+
delete buffer.uri;
|
|
108
|
+
}
|
|
109
|
+
else if (gltf.buffers[i] === null) {
|
|
110
|
+
gltf.buffers[i] = {
|
|
111
|
+
arrayBuffer: new ArrayBuffer(buffer.byteLength),
|
|
112
|
+
byteOffset: 0,
|
|
113
|
+
byteLength: buffer.byteLength
|
|
114
|
+
};
|
|
115
|
+
}
|
|
102
116
|
}
|
|
103
|
-
}
|
|
104
117
|
}
|
|
105
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Loads all images
|
|
120
|
+
* TODO - traverse gltf and determine which images are actually needed
|
|
121
|
+
* @param gltf
|
|
122
|
+
* @param options
|
|
123
|
+
* @param context
|
|
124
|
+
* @returns
|
|
125
|
+
*/
|
|
106
126
|
async function loadImages(gltf, options, context) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return await Promise.all(promises);
|
|
127
|
+
const imageIndices = getReferencesImageIndices(gltf);
|
|
128
|
+
const images = gltf.json.images || [];
|
|
129
|
+
const promises = [];
|
|
130
|
+
for (const imageIndex of imageIndices) {
|
|
131
|
+
promises.push(loadImage(gltf, images[imageIndex], imageIndex, options, context));
|
|
132
|
+
}
|
|
133
|
+
return await Promise.all(promises);
|
|
116
134
|
}
|
|
117
|
-
|
|
135
|
+
/** Make sure we only load images that are actually referenced by textures */
|
|
118
136
|
function getReferencesImageIndices(gltf) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
137
|
+
const imageIndices = new Set();
|
|
138
|
+
const textures = gltf.json.textures || [];
|
|
139
|
+
for (const texture of textures) {
|
|
140
|
+
if (texture.source !== undefined) {
|
|
141
|
+
imageIndices.add(texture.source);
|
|
142
|
+
}
|
|
125
143
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return Array.from(imageIndices).sort();
|
|
144
|
+
return Array.from(imageIndices).sort();
|
|
129
145
|
}
|
|
130
|
-
|
|
146
|
+
/** Asynchronously fetches and parses one image, store in images array outside of json */
|
|
131
147
|
async function loadImage(gltf, image, index, options, context) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
148
|
+
const { fetch, parse } = context;
|
|
149
|
+
let arrayBuffer;
|
|
150
|
+
if (image.uri && !image.hasOwnProperty('bufferView')) {
|
|
151
|
+
const uri = (0, resolve_url_1.resolveUrl)(image.uri, options);
|
|
152
|
+
const response = await fetch(uri);
|
|
153
|
+
arrayBuffer = await response.arrayBuffer();
|
|
154
|
+
image.bufferView = {
|
|
155
|
+
data: arrayBuffer
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
if (Number.isFinite(image.bufferView)) {
|
|
159
|
+
const array = (0, get_typed_array_1.getTypedArrayForBufferView)(gltf.json, gltf.buffers, image.bufferView);
|
|
160
|
+
arrayBuffer = (0, loader_utils_1.sliceArrayBuffer)(array.buffer, array.byteOffset, array.byteLength);
|
|
161
|
+
}
|
|
162
|
+
(0, assert_1.assert)(arrayBuffer, 'glTF image has no data');
|
|
163
|
+
// Call `parse`
|
|
164
|
+
let parsedImage = await parse(arrayBuffer, [images_1.ImageLoader, textures_1.BasisLoader], { mimeType: image.mimeType, basis: options.basis || { format: (0, textures_1.selectSupportedBasisFormat)() } }, context);
|
|
165
|
+
if (parsedImage && parsedImage[0]) {
|
|
166
|
+
parsedImage = {
|
|
167
|
+
compressed: true,
|
|
168
|
+
mipmaps: false,
|
|
169
|
+
width: parsedImage[0].width,
|
|
170
|
+
height: parsedImage[0].height,
|
|
171
|
+
data: parsedImage[0]
|
|
172
|
+
};
|
|
154
173
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
mipmaps: false,
|
|
161
|
-
width: parsedImage[0].width,
|
|
162
|
-
height: parsedImage[0].height,
|
|
163
|
-
data: parsedImage
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
gltf.images = gltf.images || [];
|
|
168
|
-
gltf.images[index] = parsedImage;
|
|
174
|
+
// TODO making sure ImageLoader is overridable by using array of loaders
|
|
175
|
+
// const parsedImage = await parse(arrayBuffer, [ImageLoader]);
|
|
176
|
+
// Store the loaded image
|
|
177
|
+
gltf.images = gltf.images || [];
|
|
178
|
+
gltf.images[index] = parsedImage;
|
|
169
179
|
}
|
|
170
|
-
//# sourceMappingURL=parse-gltf.js.map
|