@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
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
2
|
+
import type {GLTF} from '../../types/gltf-json-schema';
|
|
3
|
+
import {GLTFScenegraph} from '../../api/gltf-scenegraph';
|
|
4
|
+
import {getImageData} from '@loaders.gl/images';
|
|
5
|
+
import {
|
|
6
|
+
ClassProperty,
|
|
7
|
+
EXT_feature_metadata_class_object,
|
|
8
|
+
EXT_feature_metadata_feature_table,
|
|
9
|
+
FeatureTableProperty,
|
|
10
|
+
GLTF_EXT_feature_metadata,
|
|
11
|
+
EXT_feature_metadata_feature_texture,
|
|
12
|
+
FeatureTextureProperty,
|
|
13
|
+
GLTFMeshPrimitive
|
|
14
|
+
} from '../../types/gltf-json-schema';
|
|
15
|
+
import {getComponentTypeFromArray} from '../../gltf-utils/gltf-utils';
|
|
16
|
+
import {GLTFLoaderOptions} from '../../../gltf-loader';
|
|
17
|
+
|
|
18
|
+
/** Extension name */
|
|
19
|
+
const EXT_FEATURE_METADATA = 'EXT_feature_metadata';
|
|
20
|
+
|
|
21
|
+
export const name = EXT_FEATURE_METADATA;
|
|
22
|
+
|
|
23
|
+
export async function decode(gltfData: {json: GLTF}, options: GLTFLoaderOptions): Promise<void> {
|
|
24
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
25
|
+
decodeExtFeatureMetadata(scenegraph, options);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Decodes feature metadata from extension
|
|
30
|
+
* @param scenegraph
|
|
31
|
+
*/
|
|
32
|
+
function decodeExtFeatureMetadata(scenegraph: GLTFScenegraph, options: GLTFLoaderOptions): void {
|
|
33
|
+
const extension: GLTF_EXT_feature_metadata | null = scenegraph.getExtension(EXT_FEATURE_METADATA);
|
|
34
|
+
if (!extension) return;
|
|
35
|
+
|
|
36
|
+
const schemaClasses = extension.schema?.classes;
|
|
37
|
+
|
|
38
|
+
const {featureTables} = extension;
|
|
39
|
+
if (schemaClasses && featureTables) {
|
|
40
|
+
for (const schemaName in schemaClasses) {
|
|
41
|
+
const schemaClass = schemaClasses[schemaName];
|
|
42
|
+
const featureTable = findFeatureTableByName(featureTables, schemaName);
|
|
43
|
+
|
|
44
|
+
if (featureTable) {
|
|
45
|
+
handleFeatureTableProperties(scenegraph, featureTable, schemaClass);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const {featureTextures} = extension;
|
|
51
|
+
if (schemaClasses && featureTextures && options.gltf?.loadImages) {
|
|
52
|
+
for (const schemaName in schemaClasses) {
|
|
53
|
+
const schemaClass = schemaClasses[schemaName];
|
|
54
|
+
const featureTexture = findFeatureTextureByName(featureTextures, schemaName);
|
|
55
|
+
|
|
56
|
+
if (featureTexture) {
|
|
57
|
+
handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Navigate throw all properies in feature table and gets properties data.
|
|
65
|
+
* @param scenegraph
|
|
66
|
+
* @param featureTable
|
|
67
|
+
* @param schemaClass
|
|
68
|
+
*/
|
|
69
|
+
function handleFeatureTableProperties(
|
|
70
|
+
scenegraph: GLTFScenegraph,
|
|
71
|
+
featureTable: EXT_feature_metadata_feature_table,
|
|
72
|
+
schemaClass: EXT_feature_metadata_class_object
|
|
73
|
+
): void {
|
|
74
|
+
for (const propertyName in schemaClass.properties) {
|
|
75
|
+
const schemaProperty = schemaClass.properties[propertyName];
|
|
76
|
+
const featureTableProperty = featureTable?.properties?.[propertyName];
|
|
77
|
+
const numberOfFeatures = featureTable.count;
|
|
78
|
+
|
|
79
|
+
if (featureTableProperty) {
|
|
80
|
+
const data = getPropertyDataFromBinarySource(
|
|
81
|
+
scenegraph,
|
|
82
|
+
schemaProperty,
|
|
83
|
+
numberOfFeatures,
|
|
84
|
+
featureTableProperty
|
|
85
|
+
);
|
|
86
|
+
featureTableProperty.data = data;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Navigate throw all properies in feature texture and gets properties data.
|
|
93
|
+
* Data will be stored in featureTexture.properties[propertyName].data
|
|
94
|
+
* @param scenegraph
|
|
95
|
+
* @param featureTexture
|
|
96
|
+
* @param schemaClass
|
|
97
|
+
*/
|
|
98
|
+
function handleFeatureTextureProperties(
|
|
99
|
+
scenegraph: GLTFScenegraph,
|
|
100
|
+
featureTexture: EXT_feature_metadata_feature_texture,
|
|
101
|
+
schemaClass: EXT_feature_metadata_class_object
|
|
102
|
+
): void {
|
|
103
|
+
const attributeName = featureTexture.class;
|
|
104
|
+
|
|
105
|
+
for (const propertyName in schemaClass.properties) {
|
|
106
|
+
const featureTextureProperty = featureTexture?.properties?.[propertyName];
|
|
107
|
+
|
|
108
|
+
if (featureTextureProperty) {
|
|
109
|
+
const data = getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName);
|
|
110
|
+
featureTextureProperty.data = data;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Decode properties from binary sourse based on property type.
|
|
117
|
+
* @param scenegraph
|
|
118
|
+
* @param schemaProperty
|
|
119
|
+
* @param numberOfFeatures
|
|
120
|
+
* @param featureTableProperty
|
|
121
|
+
*/
|
|
122
|
+
function getPropertyDataFromBinarySource(
|
|
123
|
+
scenegraph: GLTFScenegraph,
|
|
124
|
+
schemaProperty: ClassProperty,
|
|
125
|
+
numberOfFeatures: number,
|
|
126
|
+
featureTableProperty: FeatureTableProperty
|
|
127
|
+
): Uint8Array | string[] {
|
|
128
|
+
const bufferView = featureTableProperty.bufferView;
|
|
129
|
+
// TODO think maybe we shouldn't get data only in Uint8Array format.
|
|
130
|
+
const dataArray: Uint8Array = scenegraph.getTypedArrayForBufferView(bufferView);
|
|
131
|
+
|
|
132
|
+
switch (schemaProperty.type) {
|
|
133
|
+
case 'STRING': {
|
|
134
|
+
// stringOffsetBufferView should be available for string type.
|
|
135
|
+
const stringOffsetBufferView = featureTableProperty.stringOffsetBufferView!;
|
|
136
|
+
const offsetsData = scenegraph.getTypedArrayForBufferView(stringOffsetBufferView);
|
|
137
|
+
return getStringAttributes(dataArray, offsetsData, numberOfFeatures);
|
|
138
|
+
}
|
|
139
|
+
default:
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return dataArray;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Get properties from texture associated with all mesh primitives.
|
|
147
|
+
* @param scenegraph
|
|
148
|
+
* @param featureTextureProperty
|
|
149
|
+
* @param attributeName
|
|
150
|
+
* @returns Feature texture data
|
|
151
|
+
*/
|
|
152
|
+
function getPropertyDataFromTexture(
|
|
153
|
+
scenegraph: GLTFScenegraph,
|
|
154
|
+
featureTextureProperty: FeatureTextureProperty,
|
|
155
|
+
attributeName: string
|
|
156
|
+
): number[] {
|
|
157
|
+
const json = scenegraph.gltf.json;
|
|
158
|
+
if (!json.meshes) {
|
|
159
|
+
return [];
|
|
160
|
+
}
|
|
161
|
+
const featureTextureTable: number[] = [];
|
|
162
|
+
for (const mesh of json.meshes) {
|
|
163
|
+
for (const primitive of mesh.primitives) {
|
|
164
|
+
processPrimitiveTextures(
|
|
165
|
+
scenegraph,
|
|
166
|
+
attributeName,
|
|
167
|
+
featureTextureProperty,
|
|
168
|
+
featureTextureTable,
|
|
169
|
+
primitive
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return featureTextureTable;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// eslint-disable-next-line max-statements
|
|
177
|
+
/**
|
|
178
|
+
* Processes data encoded in the texture associated with the primitive. This data will be accessible through the attributes.
|
|
179
|
+
* @param scenegraph
|
|
180
|
+
* @param attributeName
|
|
181
|
+
* @param featureTextureProperty
|
|
182
|
+
* @param featureTextureTable
|
|
183
|
+
* @param primitive
|
|
184
|
+
*/
|
|
185
|
+
function processPrimitiveTextures(
|
|
186
|
+
scenegraph: GLTFScenegraph,
|
|
187
|
+
attributeName: string,
|
|
188
|
+
featureTextureProperty: FeatureTextureProperty,
|
|
189
|
+
featureTextureTable: number[],
|
|
190
|
+
primitive: GLTFMeshPrimitive
|
|
191
|
+
): void {
|
|
192
|
+
/*
|
|
193
|
+
texture.index is an index for the "textures" array.
|
|
194
|
+
The texture object referenced by this index looks like this:
|
|
195
|
+
{
|
|
196
|
+
"sampler": 0,
|
|
197
|
+
"source": 0
|
|
198
|
+
}
|
|
199
|
+
"sampler" is an index for the "samplers" array
|
|
200
|
+
"source" is an index for the "images" array that contains data. These data are stored in rgba channels of the image.
|
|
201
|
+
|
|
202
|
+
texture.texCoord is a number-suffix (like 1) for an attribute like "TEXCOORD_1" in meshes.primitives
|
|
203
|
+
The value of "TEXCOORD_1" is an accessor that is used to get coordinates. These coordinates ared used to get data from the image.
|
|
204
|
+
*/
|
|
205
|
+
const json = scenegraph.gltf.json;
|
|
206
|
+
const textureData: number[] = [];
|
|
207
|
+
const texCoordAccessorKey = `TEXCOORD_${featureTextureProperty.texture.texCoord}`;
|
|
208
|
+
const texCoordAccessorIndex = primitive.attributes[texCoordAccessorKey];
|
|
209
|
+
const texCoordBufferView = scenegraph.getBufferView(texCoordAccessorIndex);
|
|
210
|
+
const texCoordArray: Uint8Array = scenegraph.getTypedArrayForBufferView(texCoordBufferView);
|
|
211
|
+
|
|
212
|
+
const textureCoordinates: Float32Array = new Float32Array(
|
|
213
|
+
texCoordArray.buffer,
|
|
214
|
+
texCoordArray.byteOffset,
|
|
215
|
+
texCoordArray.length / 4
|
|
216
|
+
);
|
|
217
|
+
// textureCoordinates contains UV coordinates of the actual data stored in the texture
|
|
218
|
+
// accessor.count is a number of UV pairs (they are stored as VEC2)
|
|
219
|
+
|
|
220
|
+
const textureIndex = featureTextureProperty.texture.index;
|
|
221
|
+
const texture = json.textures?.[textureIndex];
|
|
222
|
+
const imageIndex = texture?.source;
|
|
223
|
+
if (typeof imageIndex !== 'undefined') {
|
|
224
|
+
const image = json.images?.[imageIndex];
|
|
225
|
+
const mimeType = image?.mimeType;
|
|
226
|
+
const parsedImage = scenegraph.gltf.images?.[imageIndex];
|
|
227
|
+
if (parsedImage) {
|
|
228
|
+
for (let index = 0; index < textureCoordinates.length; index += 2) {
|
|
229
|
+
const value = getImageValueByCoordinates(
|
|
230
|
+
parsedImage,
|
|
231
|
+
mimeType,
|
|
232
|
+
textureCoordinates,
|
|
233
|
+
index,
|
|
234
|
+
featureTextureProperty.channels
|
|
235
|
+
);
|
|
236
|
+
textureData.push(value);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
/*
|
|
241
|
+
featureTextureTable will contain unique values, e.g.
|
|
242
|
+
textureData = [24, 35, 28, 24]
|
|
243
|
+
featureTextureTable = [24, 35, 28]
|
|
244
|
+
featureIndices will contain indices hat refer featureTextureTable, e.g.
|
|
245
|
+
featureIndices = [0, 1, 2, 0]
|
|
246
|
+
*/
|
|
247
|
+
const featureIndices: number[] = [];
|
|
248
|
+
for (const texelData of textureData) {
|
|
249
|
+
let index = featureTextureTable.findIndex((item) => item === texelData);
|
|
250
|
+
if (index === -1) {
|
|
251
|
+
index = featureTextureTable.push(texelData) - 1;
|
|
252
|
+
}
|
|
253
|
+
featureIndices.push(index);
|
|
254
|
+
}
|
|
255
|
+
const typedArray = new Uint32Array(featureIndices);
|
|
256
|
+
const bufferIndex =
|
|
257
|
+
scenegraph.gltf.buffers.push({
|
|
258
|
+
arrayBuffer: typedArray.buffer,
|
|
259
|
+
byteOffset: 0,
|
|
260
|
+
byteLength: typedArray.byteLength
|
|
261
|
+
}) - 1;
|
|
262
|
+
const bufferViewIndex = scenegraph.addBufferView(typedArray, bufferIndex, 0);
|
|
263
|
+
const accessorIndex = scenegraph.addAccessor(bufferViewIndex, {
|
|
264
|
+
size: 1,
|
|
265
|
+
componentType: getComponentTypeFromArray(typedArray),
|
|
266
|
+
count: typedArray.length
|
|
267
|
+
});
|
|
268
|
+
primitive.attributes[attributeName] = accessorIndex;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function getImageValueByCoordinates(
|
|
272
|
+
parsedImage: any,
|
|
273
|
+
mimeType: string | undefined,
|
|
274
|
+
textureCoordinates: Float32Array,
|
|
275
|
+
index: number,
|
|
276
|
+
channels: string
|
|
277
|
+
) {
|
|
278
|
+
const CHANNELS_MAP = {
|
|
279
|
+
r: {offset: 0, shift: 0},
|
|
280
|
+
g: {offset: 1, shift: 8},
|
|
281
|
+
b: {offset: 2, shift: 16},
|
|
282
|
+
a: {offset: 3, shift: 24}
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
const u = textureCoordinates[index];
|
|
286
|
+
const v = textureCoordinates[index + 1];
|
|
287
|
+
|
|
288
|
+
let components = 1;
|
|
289
|
+
if (mimeType && (mimeType.indexOf('image/jpeg') !== -1 || mimeType.indexOf('image/png') !== -1))
|
|
290
|
+
components = 4;
|
|
291
|
+
const offset = coordinatesToOffset(u, v, parsedImage, components);
|
|
292
|
+
let value = 0;
|
|
293
|
+
for (const c of channels) {
|
|
294
|
+
const map = CHANNELS_MAP[c];
|
|
295
|
+
const val = getVal(parsedImage, offset + map.offset);
|
|
296
|
+
value |= val << map.shift;
|
|
297
|
+
}
|
|
298
|
+
return value;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function getVal(parsedImage: any, offset: number): number {
|
|
302
|
+
const imageData = getImageData(parsedImage);
|
|
303
|
+
if (imageData.data.length <= offset) {
|
|
304
|
+
throw new Error(`${imageData.data.length} <= ${offset}`);
|
|
305
|
+
}
|
|
306
|
+
return imageData.data[offset];
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function coordinatesToOffset(
|
|
310
|
+
u: number,
|
|
311
|
+
v: number,
|
|
312
|
+
parsedImage: any,
|
|
313
|
+
componentsCount: number = 1
|
|
314
|
+
): number {
|
|
315
|
+
const w = parsedImage.width;
|
|
316
|
+
const iX = emod(u) * (w - 1);
|
|
317
|
+
const indX = Math.round(iX);
|
|
318
|
+
|
|
319
|
+
const h = parsedImage.height;
|
|
320
|
+
const iY = emod(v) * (h - 1);
|
|
321
|
+
const indY = Math.round(iY);
|
|
322
|
+
const components = parsedImage.components ? parsedImage.components : componentsCount;
|
|
323
|
+
// components is a number of channels in the image
|
|
324
|
+
const offset = (indY * w + indX) * components;
|
|
325
|
+
return offset;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// The following is taken from tile-converter\src\i3s-converter\helpers\batch-ids-extensions.ts
|
|
329
|
+
/**
|
|
330
|
+
* Handle UVs if they are out of range [0,1].
|
|
331
|
+
* @param n
|
|
332
|
+
* @param m
|
|
333
|
+
*/
|
|
334
|
+
function emod(n: number): number {
|
|
335
|
+
const a = ((n % 1) + 1) % 1;
|
|
336
|
+
return a;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Find the feature table by class name.
|
|
341
|
+
* @param featureTables
|
|
342
|
+
* @param schemaClassName
|
|
343
|
+
*/
|
|
344
|
+
function findFeatureTableByName(
|
|
345
|
+
featureTables: {[key: string]: EXT_feature_metadata_feature_table},
|
|
346
|
+
schemaClassName: string
|
|
347
|
+
): EXT_feature_metadata_feature_table | null {
|
|
348
|
+
for (const featureTableName in featureTables) {
|
|
349
|
+
const featureTable = featureTables[featureTableName];
|
|
350
|
+
|
|
351
|
+
if (featureTable.class === schemaClassName) {
|
|
352
|
+
return featureTable;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function findFeatureTextureByName(
|
|
360
|
+
featureTextures: {[key: string]: EXT_feature_metadata_feature_texture},
|
|
361
|
+
schemaClassName: string
|
|
362
|
+
): EXT_feature_metadata_feature_texture | null {
|
|
363
|
+
for (const featureTexturesName in featureTextures) {
|
|
364
|
+
const featureTable = featureTextures[featureTexturesName];
|
|
365
|
+
|
|
366
|
+
if (featureTable.class === schemaClassName) {
|
|
367
|
+
return featureTable;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Getting string attributes from binary data.
|
|
376
|
+
* Spec - https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata#strings
|
|
377
|
+
* @param data
|
|
378
|
+
* @param offsetsData
|
|
379
|
+
* @param stringsCount
|
|
380
|
+
*/
|
|
381
|
+
function getStringAttributes(
|
|
382
|
+
data: Uint8Array,
|
|
383
|
+
offsetsData: Uint8Array,
|
|
384
|
+
stringsCount: number
|
|
385
|
+
): string[] {
|
|
386
|
+
const stringsArray: string[] = [];
|
|
387
|
+
const textDecoder = new TextDecoder('utf8');
|
|
388
|
+
|
|
389
|
+
let stringOffset = 0;
|
|
390
|
+
const bytesPerStringSize = 4;
|
|
391
|
+
|
|
392
|
+
for (let index = 0; index < stringsCount; index++) {
|
|
393
|
+
// TODO check if it is multiplication on bytesPerStringSize is valid operation?
|
|
394
|
+
const stringByteSize =
|
|
395
|
+
offsetsData[(index + 1) * bytesPerStringSize] - offsetsData[index * bytesPerStringSize];
|
|
396
|
+
const stringData = data.subarray(stringOffset, stringByteSize + stringOffset);
|
|
397
|
+
const stringAttribute = textDecoder.decode(stringData);
|
|
398
|
+
|
|
399
|
+
stringsArray.push(stringAttribute);
|
|
400
|
+
stringOffset += stringByteSize;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return stringsArray;
|
|
404
|
+
}
|
|
@@ -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
|
+
}
|