@loaders.gl/gltf 3.1.0-alpha.2 → 3.1.0-beta.1
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 +4481 -5
- package/dist/es5/bundle.js +7 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/glb-loader.js +47 -0
- package/dist/es5/glb-loader.js.map +1 -0
- package/dist/es5/glb-writer.js +42 -0
- package/dist/es5/glb-writer.js.map +1 -0
- package/dist/es5/gltf-loader.js +59 -0
- package/dist/es5/gltf-loader.js.map +1 -0
- package/dist/es5/gltf-writer.js +40 -0
- package/dist/es5/gltf-writer.js.map +1 -0
- package/dist/es5/index.js +56 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/api/gltf-extensions.js +58 -0
- package/dist/es5/lib/api/gltf-extensions.js.map +1 -0
- package/dist/es5/lib/api/gltf-scenegraph.js +529 -0
- package/dist/es5/lib/api/gltf-scenegraph.js.map +1 -0
- package/dist/es5/lib/api/normalize-gltf-v1.js +264 -0
- package/dist/es5/lib/api/normalize-gltf-v1.js.map +1 -0
- package/dist/es5/lib/api/post-process-gltf.js +412 -0
- package/dist/es5/lib/api/post-process-gltf.js.map +1 -0
- package/dist/es5/lib/encoders/encode-glb.js +72 -0
- package/dist/es5/lib/encoders/encode-glb.js.map +1 -0
- package/dist/es5/lib/encoders/encode-gltf.js +24 -0
- package/dist/es5/lib/encoders/encode-gltf.js.map +1 -0
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js +72 -0
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -0
- package/dist/es5/lib/extensions/EXT_texture_webp.js +46 -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 +146 -0
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -0
- package/dist/es5/lib/extensions/KHR_texture_basisu.js +35 -0
- package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -0
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js +65 -0
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -0
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js +52 -0
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -0
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js +83 -0
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -0
- package/dist/es5/lib/gltf-utils/get-typed-array.js +26 -0
- package/dist/es5/lib/gltf-utils/get-typed-array.js.map +1 -0
- package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js +83 -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 +69 -0
- package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -0
- package/dist/es5/lib/gltf-utils/resolve-url.js +23 -0
- package/dist/es5/lib/gltf-utils/resolve-url.js.map +1 -0
- package/dist/es5/lib/parsers/parse-glb.js +138 -0
- package/dist/es5/lib/parsers/parse-glb.js.map +1 -0
- package/dist/es5/lib/parsers/parse-gltf.js +193 -0
- package/dist/es5/lib/parsers/parse-gltf.js.map +1 -0
- package/dist/es5/lib/types/glb-types.js +2 -0
- package/dist/{lib → es5/lib}/types/glb-types.js.map +0 -0
- package/dist/es5/lib/types/gltf-json-schema.js +2 -0
- package/dist/{lib → es5/lib}/types/gltf-json-schema.js.map +0 -0
- package/dist/es5/lib/types/gltf-postprocessed-schema.js +2 -0
- package/dist/{lib → es5/lib}/types/gltf-postprocessed-schema.js.map +0 -0
- package/dist/es5/lib/types/gltf-types.js +2 -0
- package/dist/{lib → es5/lib}/types/gltf-types.js.map +0 -0
- package/dist/es5/lib/utils/assert.js +13 -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 +119 -0
- package/dist/es5/meshopt/meshopt-decoder.js.map +1 -0
- package/dist/{meshopt → es5/meshopt}/meshopt-encoder.ts.disabled +0 -0
- package/dist/es5/webp/webp.js +36 -0
- package/dist/es5/webp/webp.js.map +1 -0
- package/dist/esm/bundle.js +5 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/glb-loader.js +34 -0
- package/dist/esm/glb-loader.js.map +1 -0
- package/dist/esm/glb-writer.js +29 -0
- package/dist/esm/glb-writer.js.map +1 -0
- package/dist/esm/gltf-loader.js +47 -0
- package/dist/esm/gltf-loader.js.map +1 -0
- package/dist/esm/gltf-writer.js +29 -0
- package/dist/esm/gltf-writer.js.map +1 -0
- package/dist/esm/index.js +7 -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 +515 -0
- package/dist/esm/lib/api/gltf-scenegraph.js.map +1 -0
- package/dist/esm/lib/api/normalize-gltf-v1.js +250 -0
- package/dist/esm/lib/api/normalize-gltf-v1.js.map +1 -0
- package/dist/esm/lib/api/post-process-gltf.js +403 -0
- package/dist/esm/lib/api/post-process-gltf.js.map +1 -0
- package/dist/esm/lib/encoders/encode-glb.js +63 -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 +56 -0
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js.map +1 -0
- package/dist/esm/lib/extensions/EXT_texture_webp.js +32 -0
- package/dist/esm/lib/extensions/EXT_texture_webp.js.map +1 -0
- package/dist/esm/lib/extensions/KHR_binary_gltf.js +26 -0
- package/dist/esm/lib/extensions/KHR_binary_gltf.js.map +1 -0
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js +126 -0
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js.map +1 -0
- package/dist/esm/lib/extensions/KHR_texture_basisu.js +22 -0
- package/dist/esm/lib/extensions/KHR_texture_basisu.js.map +1 -0
- package/dist/{lib/extensions → esm/lib/extensions/deprecated}/KHR_lights_punctual.js +4 -3
- package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -0
- package/dist/{lib/extensions → esm/lib/extensions/deprecated}/KHR_materials_unlit.js +3 -2
- package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -0
- package/dist/{lib/extensions → esm/lib/extensions/deprecated}/KHR_techniques_webgl.js +3 -2
- 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 +73 -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 +56 -0
- package/dist/esm/lib/gltf-utils/gltf-utils.js.map +1 -0
- package/dist/esm/lib/gltf-utils/resolve-url.js +16 -0
- package/dist/esm/lib/gltf-utils/resolve-url.js.map +1 -0
- package/dist/esm/lib/parsers/parse-glb.js +128 -0
- package/dist/esm/lib/parsers/parse-glb.js.map +1 -0
- package/dist/esm/lib/parsers/parse-gltf.js +170 -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 +103 -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 +29 -0
- package/dist/esm/webp/webp.js.map +1 -0
- package/dist/glb-loader.d.ts +13 -0
- package/dist/glb-loader.d.ts.map +1 -0
- package/dist/glb-loader.js +33 -28
- package/dist/glb-writer.d.ts +22 -0
- package/dist/glb-writer.d.ts.map +1 -0
- package/dist/glb-writer.js +34 -26
- package/dist/gltf-loader.d.ts +18 -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 +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -8
- package/dist/lib/api/gltf-extensions.d.ts +26 -0
- package/dist/lib/api/gltf-extensions.d.ts.map +1 -0
- package/dist/lib/api/gltf-extensions.js +75 -0
- package/dist/lib/api/gltf-scenegraph.d.ts +183 -0
- package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -0
- package/dist/lib/api/gltf-scenegraph.js +550 -512
- 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 +274 -226
- package/dist/lib/api/post-process-gltf.d.ts +2 -0
- package/dist/lib/api/post-process-gltf.d.ts.map +1 -0
- package/dist/lib/api/post-process-gltf.js +301 -347
- package/dist/lib/encoders/encode-glb.d.ts +2 -0
- package/dist/lib/encoders/encode-glb.d.ts.map +1 -0
- package/dist/lib/encoders/encode-glb.js +56 -58
- package/dist/lib/encoders/encode-gltf.d.ts +2 -0
- package/dist/lib/encoders/encode-gltf.d.ts.map +1 -0
- package/dist/lib/encoders/encode-gltf.js +25 -12
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts +10 -0
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -0
- package/dist/lib/extensions/EXT_meshopt_compression.js +50 -44
- 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 +38 -0
- 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 +40 -24
- 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 +128 -105
- 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 +31 -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 +62 -0
- 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 +47 -0
- 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 +81 -0
- 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 +4 -0
- package/dist/lib/gltf-utils/gltf-constants.d.ts.map +1 -0
- package/dist/lib/gltf-utils/gltf-constants.js +36 -36
- package/dist/lib/gltf-utils/gltf-utils.d.ts +8 -0
- package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -0
- package/dist/lib/gltf-utils/gltf-utils.js +52 -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 +8 -0
- package/dist/lib/parsers/parse-glb.d.ts.map +1 -0
- package/dist/lib/parsers/parse-glb.js +116 -107
- package/dist/lib/parsers/parse-gltf.d.ts +14 -0
- package/dist/lib/parsers/parse-gltf.d.ts.map +1 -0
- package/dist/lib/parsers/parse-gltf.js +177 -123
- 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 +720 -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 +685 -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 +10 -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 +38 -0
- package/package.json +13 -10
- package/src/bundle.ts +2 -3
- package/src/gltf-loader.ts +7 -4
- package/src/index.ts +8 -4
- package/src/lib/api/gltf-extensions.ts +71 -0
- package/src/lib/api/gltf-scenegraph.ts +4 -6
- package/src/lib/api/{normalize-gltf-v1.js → normalize-gltf-v1.ts} +20 -17
- package/src/lib/api/{post-process-gltf.js → post-process-gltf.ts} +8 -1
- package/src/lib/encoders/{encode-glb.js → encode-glb.ts} +0 -0
- package/src/lib/encoders/{encode-gltf.js → encode-gltf.ts} +0 -0
- package/src/lib/extensions/EXT_meshopt_compression.ts +32 -23
- package/src/lib/extensions/EXT_texture_webp.ts +45 -0
- package/src/lib/extensions/KHR_binary_gltf.ts +19 -10
- package/src/lib/extensions/KHR_draco_mesh_compression.ts +29 -4
- package/src/lib/extensions/KHR_texture_basisu.ts +36 -0
- package/src/lib/extensions/{KHR_lights_punctual.ts → deprecated/KHR_lights_punctual.ts} +7 -4
- package/src/lib/extensions/{KHR_materials_unlit.ts → deprecated/KHR_materials_unlit.ts} +6 -3
- package/src/lib/extensions/{KHR_techniques_webgl.ts → deprecated/KHR_techniques_webgl.ts} +6 -3
- package/src/lib/gltf-utils/gltf-constants.ts +0 -12
- package/src/lib/parsers/parse-gltf.ts +72 -20
- package/src/lib/types/gltf-json-schema.ts +96 -3
- package/src/lib/types/gltf-types.ts +19 -21
- package/src/lib/utils/{assert.js → assert.ts} +1 -1
- package/src/lib/utils/{version.js → version.ts} +0 -0
- package/src/webp/webp.ts +41 -0
- package/dist/bundle.js.map +0 -1
- package/dist/dist.min.js +0 -2
- package/dist/dist.min.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-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/KHR_binary_gltf.js.map +0 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.js.map +0 -1
- package/dist/lib/extensions/KHR_lights_punctual.js.map +0 -1
- package/dist/lib/extensions/KHR_materials_unlit.js.map +0 -1
- package/dist/lib/extensions/KHR_techniques_webgl.js.map +0 -1
- package/dist/lib/extensions/gltf-extensions.js +0 -24
- package/dist/lib/extensions/gltf-extensions.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/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/src/lib/extensions/gltf-extensions.ts +0 -48
|
@@ -80,22 +80,24 @@ const GLTF_KEYS = {
|
|
|
80
80
|
* Converts (normalizes) glTF v1 to v2
|
|
81
81
|
*/
|
|
82
82
|
class GLTFV1Normalizer {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
83
|
+
idToIndexMap = {
|
|
84
|
+
animations: {},
|
|
85
|
+
accessors: {},
|
|
86
|
+
buffers: {},
|
|
87
|
+
bufferViews: {},
|
|
88
|
+
images: {},
|
|
89
|
+
materials: {},
|
|
90
|
+
meshes: {},
|
|
91
|
+
nodes: {},
|
|
92
|
+
samplers: {},
|
|
93
|
+
scenes: {},
|
|
94
|
+
skins: {},
|
|
95
|
+
textures: {}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
json;
|
|
99
|
+
|
|
100
|
+
// constructor() {}
|
|
99
101
|
|
|
100
102
|
/**
|
|
101
103
|
* Convert (normalize) glTF < 2.0 to glTF 2.0
|
|
@@ -139,7 +141,8 @@ class GLTFV1Normalizer {
|
|
|
139
141
|
|
|
140
142
|
// Extract bufferView indices for images
|
|
141
143
|
// (this extension needs to be invoked early in the normalization process)
|
|
142
|
-
|
|
144
|
+
// TODO can this be handled by standard extension processing instead of called explicitly?
|
|
145
|
+
KHR_binary_glTF.preprocess(gltf);
|
|
143
146
|
|
|
144
147
|
// Convert object references from ids to indices
|
|
145
148
|
this._convertObjectIdsToArrayIndices(json);
|
|
@@ -56,7 +56,7 @@ const DEFAULT_SAMPLER = {
|
|
|
56
56
|
[GL_SAMPLER.TEXTURE_MAG_FILTER]: GL_SAMPLER.LINEAR,
|
|
57
57
|
[GL_SAMPLER.TEXTURE_MIN_FILTER]: GL_SAMPLER.NEAREST_MIPMAP_LINEAR,
|
|
58
58
|
[GL_SAMPLER.TEXTURE_WRAP_S]: GL_SAMPLER.REPEAT,
|
|
59
|
-
[GL_SAMPLER.
|
|
59
|
+
[GL_SAMPLER.TEXTURE_WRAP_T]: GL_SAMPLER.REPEAT
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
function getBytesFromComponentType(componentType) {
|
|
@@ -68,6 +68,11 @@ function getSizeFromAccessorType(type) {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
class GLTFPostProcessor {
|
|
71
|
+
baseUri: string = '';
|
|
72
|
+
json: Record<string, any> = {};
|
|
73
|
+
buffers: [] = [];
|
|
74
|
+
images: [] = [];
|
|
75
|
+
|
|
71
76
|
postProcess(gltf, options = {}) {
|
|
72
77
|
const {json, buffers = [], images = [], baseUri = ''} = gltf;
|
|
73
78
|
assert(json);
|
|
@@ -359,7 +364,9 @@ class GLTFPostProcessor {
|
|
|
359
364
|
const bufferIndex = bufferView.buffer;
|
|
360
365
|
bufferView.buffer = this.buffers[bufferIndex];
|
|
361
366
|
|
|
367
|
+
// @ts-expect-error
|
|
362
368
|
const arrayBuffer = this.buffers[bufferIndex].arrayBuffer;
|
|
369
|
+
// @ts-expect-error
|
|
363
370
|
let byteOffset = this.buffers[bufferIndex].byteOffset || 0;
|
|
364
371
|
|
|
365
372
|
if ('byteOffset' in bufferView) {
|
|
File without changes
|
|
File without changes
|
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
/* eslint-disable camelcase */
|
|
2
|
+
import type {GLTF, GLTFBufferView, GLTF_EXT_meshopt_compression} from '../types/gltf-types';
|
|
2
3
|
import type {GLTFLoaderOptions} from '../../gltf-loader';
|
|
3
4
|
import GLTFScenegraph from '../api/gltf-scenegraph';
|
|
4
|
-
import {EXT_MESHOPT_COMPRESSION} from '../gltf-utils/gltf-constants';
|
|
5
5
|
import {isMeshoptSupported, meshoptDecodeGltfBuffer} from '../../meshopt/meshopt-decoder';
|
|
6
6
|
|
|
7
|
-
type GLTF_EXT_meshopt_compression = {
|
|
8
|
-
buffer: number;
|
|
9
|
-
byteOffset?: number;
|
|
10
|
-
byteLength: number;
|
|
11
|
-
byteStride: number;
|
|
12
|
-
count: number;
|
|
13
|
-
mode: 'ATTRIBUTES' | 'TRIANGLES' | 'INDICES';
|
|
14
|
-
filter?: 'NONE' | 'OCTAHEDRAL' | 'QUATERNION' | 'EXPONENTIAL';
|
|
15
|
-
};
|
|
16
|
-
|
|
17
7
|
// @ts-ignore
|
|
18
8
|
// eslint-disable-next-line
|
|
19
9
|
const DEFAULT_MESHOPT_OPTIONS = {
|
|
@@ -21,34 +11,51 @@ const DEFAULT_MESHOPT_OPTIONS = {
|
|
|
21
11
|
filter: 'NONE'
|
|
22
12
|
};
|
|
23
13
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
/** Extension name */
|
|
15
|
+
const EXT_MESHOPT_COMPRESSION = 'EXT_meshopt_compression';
|
|
16
|
+
|
|
17
|
+
export const name = EXT_MESHOPT_COMPRESSION;
|
|
18
|
+
|
|
19
|
+
export function preprocess(gltfData: {json: GLTF}) {
|
|
20
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
21
|
+
if (
|
|
22
|
+
scenegraph.getRequiredExtensions().includes(EXT_MESHOPT_COMPRESSION) &&
|
|
23
|
+
!isMeshoptSupported()
|
|
24
|
+
) {
|
|
25
|
+
throw new Error(`gltf: Required extension ${EXT_MESHOPT_COMPRESSION} not supported by browser`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function decode(gltfData: {json: GLTF}, options: GLTFLoaderOptions) {
|
|
30
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
31
|
+
|
|
32
|
+
if (!options?.gltf?.decompressMeshes) {
|
|
27
33
|
return;
|
|
28
34
|
}
|
|
29
35
|
|
|
30
36
|
const promises: Promise<any>[] = [];
|
|
31
37
|
for (const bufferViewIndex of gltfData.json.bufferViews || []) {
|
|
32
|
-
promises.push(decodeMeshoptBufferView(
|
|
38
|
+
promises.push(decodeMeshoptBufferView(scenegraph, bufferViewIndex));
|
|
33
39
|
}
|
|
34
40
|
|
|
35
41
|
// Decompress meshes in parallel
|
|
36
42
|
await Promise.all(promises);
|
|
37
43
|
|
|
38
44
|
// We have now decompressed all primitives, so remove the top-level extensions
|
|
39
|
-
const scenegraph = new GLTFScenegraph(gltfData);
|
|
40
45
|
scenegraph.removeExtension(EXT_MESHOPT_COMPRESSION);
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
/** Decode one meshopt buffer view */
|
|
44
|
-
async function decodeMeshoptBufferView(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
async function decodeMeshoptBufferView(
|
|
50
|
+
scenegraph: GLTFScenegraph,
|
|
51
|
+
bufferView: GLTFBufferView
|
|
52
|
+
): Promise<ArrayBuffer | null> {
|
|
53
|
+
const meshoptExtension = scenegraph.getObjectExtension<GLTF_EXT_meshopt_compression>(
|
|
54
|
+
bufferView,
|
|
55
|
+
EXT_MESHOPT_COMPRESSION
|
|
56
|
+
);
|
|
50
57
|
if (meshoptExtension) {
|
|
51
|
-
const buffer =
|
|
58
|
+
const buffer = bufferView.buffer;
|
|
52
59
|
|
|
53
60
|
const {
|
|
54
61
|
byteOffset = 0,
|
|
@@ -58,6 +65,8 @@ async function decodeMeshoptBufferView(json, index: number): Promise<ArrayBuffer
|
|
|
58
65
|
mode,
|
|
59
66
|
filter = 'NONE'
|
|
60
67
|
} = meshoptExtension;
|
|
68
|
+
|
|
69
|
+
// @ts-expect-error TODO - fix buffer handling
|
|
61
70
|
const source = new Uint8Array(buffer, byteOffset, byteLength);
|
|
62
71
|
const result = new ArrayBuffer(count * byteStride);
|
|
63
72
|
await meshoptDecodeGltfBuffer(new Uint8Array(result), count, byteStride, source, mode, filter);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// GLTF EXTENSION: EXT_TEXTURE_WEBP
|
|
2
|
+
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/EXT_TEXTURE_WEBP
|
|
3
|
+
/* eslint-disable camelcase */
|
|
4
|
+
|
|
5
|
+
import type {GLTF, GLTF_EXT_texture_webp} from '../types/gltf-types';
|
|
6
|
+
import type {GLTFLoaderOptions} from '../../gltf-loader';
|
|
7
|
+
|
|
8
|
+
import {_isImageFormatSupported} from '@loaders.gl/images';
|
|
9
|
+
import GLTFScenegraph from '../api/gltf-scenegraph';
|
|
10
|
+
|
|
11
|
+
const EXT_TEXTURE_WEBP = 'EXT_texture_webp';
|
|
12
|
+
|
|
13
|
+
/** Extension name */
|
|
14
|
+
export const name = EXT_TEXTURE_WEBP;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Replaces a texture source reference with the extension texture
|
|
18
|
+
* Done in preprocess() to prevent load of default image
|
|
19
|
+
*/
|
|
20
|
+
export function preprocess(gltfData: {json: GLTF}, options: GLTFLoaderOptions): void {
|
|
21
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
22
|
+
|
|
23
|
+
if (!_isImageFormatSupported('image/webp')) {
|
|
24
|
+
if (scenegraph.getRequiredExtensions().includes(EXT_TEXTURE_WEBP)) {
|
|
25
|
+
throw new Error(`gltf: Required extension ${EXT_TEXTURE_WEBP} not supported by browser`);
|
|
26
|
+
}
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const {json} = scenegraph;
|
|
31
|
+
|
|
32
|
+
for (const texture of json.textures || []) {
|
|
33
|
+
const extension = scenegraph.getObjectExtension<GLTF_EXT_texture_webp>(
|
|
34
|
+
texture,
|
|
35
|
+
EXT_TEXTURE_WEBP
|
|
36
|
+
);
|
|
37
|
+
if (extension) {
|
|
38
|
+
texture.source = extension.source;
|
|
39
|
+
}
|
|
40
|
+
scenegraph.removeObjectExtension(texture, EXT_TEXTURE_WEBP);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Remove the top-level extension
|
|
44
|
+
scenegraph.removeExtension(EXT_TEXTURE_WEBP);
|
|
45
|
+
}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
// GLTF 1.0 EXTENSION: KHR_binary_glTF
|
|
2
2
|
// https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF
|
|
3
|
+
/* eslint-disable camelcase */
|
|
3
4
|
|
|
4
|
-
import type {GLTF} from '../types/gltf-types';
|
|
5
|
+
import type {GLTF, GLTF_KHR_binary_glTF} from '../types/gltf-types';
|
|
5
6
|
|
|
6
7
|
import GLTFScenegraph from '../api/gltf-scenegraph';
|
|
7
|
-
import {KHR_BINARY_GLTF} from '../gltf-utils/gltf-constants';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
const KHR_BINARY_GLTF = 'KHR_binary_glTF';
|
|
10
|
+
|
|
11
|
+
/** Extension name */
|
|
12
|
+
export const name = KHR_BINARY_GLTF;
|
|
13
|
+
|
|
14
|
+
export function preprocess(gltfData: {json: GLTF}): void {
|
|
10
15
|
const gltfScenegraph = new GLTFScenegraph(gltfData);
|
|
11
16
|
const {json} = gltfScenegraph;
|
|
12
17
|
|
|
@@ -15,15 +20,19 @@ export function decode(gltfData: {json: GLTF}): void {
|
|
|
15
20
|
|
|
16
21
|
// Image and shader nodes can have the extension
|
|
17
22
|
// https://github.com/KhronosGroup/glTF/blob/master/extensions/1.0/Khronos/KHR_binary_glTF/schema/image.KHR_binary_glTF.schema.json
|
|
18
|
-
for (const
|
|
19
|
-
const extension = gltfScenegraph.
|
|
23
|
+
for (const image of json.images || []) {
|
|
24
|
+
const extension = gltfScenegraph.getObjectExtension<GLTF_KHR_binary_glTF>(
|
|
25
|
+
image,
|
|
26
|
+
KHR_BINARY_GLTF
|
|
27
|
+
);
|
|
20
28
|
// The data in the extension is valid as glTF 2.0 data inside the object, so just copy it in
|
|
21
29
|
if (extension) {
|
|
22
|
-
Object.assign(
|
|
30
|
+
Object.assign(image, extension);
|
|
23
31
|
}
|
|
32
|
+
gltfScenegraph.removeObjectExtension(image, KHR_BINARY_GLTF);
|
|
24
33
|
}
|
|
25
34
|
|
|
26
|
-
// TODO shaders
|
|
35
|
+
// TODO shaders - At least traverse and throw error if used?
|
|
27
36
|
// https://github.com/KhronosGroup/glTF/blob/master/extensions/1.0/Khronos/KHR_binary_glTF/schema/shader.KHR_binary_glTF.schema.json
|
|
28
37
|
|
|
29
38
|
// glTF v1 one files have a partially formed URI field that is not expected in (and causes problems in) 2.0
|
|
@@ -36,6 +45,6 @@ export function decode(gltfData: {json: GLTF}): void {
|
|
|
36
45
|
}
|
|
37
46
|
|
|
38
47
|
// KHR_binary_gltf is a 1.0 extension that is supported natively by 2.0
|
|
39
|
-
export function encode() {
|
|
40
|
-
|
|
41
|
-
}
|
|
48
|
+
// export function encode() {
|
|
49
|
+
// throw new Error(KHR_BINARY_GLTF);
|
|
50
|
+
// }
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression
|
|
2
2
|
// Only TRIANGLES: 0x0004 and TRIANGLE_STRIP: 0x0005 are supported
|
|
3
|
+
/* eslint-disable camelcase */
|
|
3
4
|
|
|
4
5
|
/* eslint-disable camelcase */
|
|
5
|
-
import type {
|
|
6
|
+
import type {
|
|
7
|
+
GLTF,
|
|
8
|
+
GLTFAccessor,
|
|
9
|
+
GLTFMeshPrimitive,
|
|
10
|
+
GLTF_KHR_draco_mesh_compression
|
|
11
|
+
} from '../types/gltf-types';
|
|
6
12
|
import type {GLTFLoaderOptions} from '../../gltf-loader';
|
|
7
13
|
|
|
8
14
|
import type {LoaderContext} from '@loaders.gl/loader-utils';
|
|
@@ -10,10 +16,26 @@ import {DracoLoader} from '@loaders.gl/draco';
|
|
|
10
16
|
import {DracoLoaderOptions, DracoMesh} from '@loaders.gl/draco';
|
|
11
17
|
import {sliceArrayBuffer} from '@loaders.gl/loader-utils';
|
|
12
18
|
import {default as Scenegraph} from '../api/gltf-scenegraph';
|
|
13
|
-
import {KHR_DRACO_MESH_COMPRESSION} from '../gltf-utils/gltf-constants';
|
|
14
19
|
import {getGLTFAccessors, getGLTFAccessor} from '../gltf-utils/gltf-attribute-utils';
|
|
15
20
|
|
|
16
|
-
|
|
21
|
+
const KHR_DRACO_MESH_COMPRESSION = 'KHR_draco_mesh_compression';
|
|
22
|
+
|
|
23
|
+
/** Extension name */
|
|
24
|
+
export const name = KHR_DRACO_MESH_COMPRESSION;
|
|
25
|
+
|
|
26
|
+
export function preprocess(
|
|
27
|
+
gltfData: {json: GLTF},
|
|
28
|
+
options: GLTFLoaderOptions,
|
|
29
|
+
context: LoaderContext
|
|
30
|
+
): void {
|
|
31
|
+
const scenegraph = new Scenegraph(gltfData);
|
|
32
|
+
for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {
|
|
33
|
+
if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {
|
|
34
|
+
// TODO - Remove fallback accessors to make sure we don't load unnecessary buffers
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
17
39
|
export async function decode(
|
|
18
40
|
gltfData: {json: GLTF},
|
|
19
41
|
options: GLTFLoaderOptions,
|
|
@@ -64,7 +86,10 @@ async function decompressPrimitive(
|
|
|
64
86
|
options: GLTFLoaderOptions,
|
|
65
87
|
context: LoaderContext
|
|
66
88
|
): Promise<void> {
|
|
67
|
-
const dracoExtension = scenegraph.getObjectExtension(
|
|
89
|
+
const dracoExtension = scenegraph.getObjectExtension<GLTF_KHR_draco_mesh_compression>(
|
|
90
|
+
primitive,
|
|
91
|
+
KHR_DRACO_MESH_COMPRESSION
|
|
92
|
+
);
|
|
68
93
|
if (!dracoExtension) {
|
|
69
94
|
return;
|
|
70
95
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// GLTF EXTENSION: KHR_texture_basisu
|
|
2
|
+
// https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_basisu
|
|
3
|
+
/* eslint-disable camelcase */
|
|
4
|
+
|
|
5
|
+
import type {GLTF, GLTF_KHR_texture_basisu} from '../types/gltf-types';
|
|
6
|
+
import type {GLTFLoaderOptions} from '../../gltf-loader';
|
|
7
|
+
|
|
8
|
+
import GLTFScenegraph from '../api/gltf-scenegraph';
|
|
9
|
+
|
|
10
|
+
const KHR_TEXTURE_BASISU = 'KHR_texture_basisu';
|
|
11
|
+
|
|
12
|
+
/** Extension name */
|
|
13
|
+
export const name = KHR_TEXTURE_BASISU;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Replaces a texture source reference with the extension texture
|
|
17
|
+
* Done in preprocess() to prevent load of default image
|
|
18
|
+
*/
|
|
19
|
+
export function preprocess(gltfData: {json: GLTF}, options: GLTFLoaderOptions): void {
|
|
20
|
+
const scene = new GLTFScenegraph(gltfData);
|
|
21
|
+
const {json} = scene;
|
|
22
|
+
|
|
23
|
+
for (const texture of json.textures || []) {
|
|
24
|
+
const extension = scene.getObjectExtension<GLTF_KHR_texture_basisu>(
|
|
25
|
+
texture,
|
|
26
|
+
KHR_TEXTURE_BASISU
|
|
27
|
+
);
|
|
28
|
+
if (extension) {
|
|
29
|
+
texture.source = extension.source;
|
|
30
|
+
}
|
|
31
|
+
scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Remove the top-level extension
|
|
35
|
+
scene.removeExtension(KHR_TEXTURE_BASISU);
|
|
36
|
+
}
|
|
@@ -1,11 +1,14 @@
|
|
|
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 '
|
|
4
|
+
import type {GLTF} from '../../types/gltf-types';
|
|
5
5
|
|
|
6
|
-
import {assert} from '
|
|
7
|
-
import GLTFScenegraph from '
|
|
8
|
-
|
|
6
|
+
import {assert} from '../../utils/assert';
|
|
7
|
+
import GLTFScenegraph from '../../api/gltf-scenegraph';
|
|
8
|
+
|
|
9
|
+
const KHR_LIGHTS_PUNCTUAL = 'KHR_lights_punctual';
|
|
10
|
+
|
|
11
|
+
export const name = KHR_LIGHTS_PUNCTUAL;
|
|
9
12
|
|
|
10
13
|
export async function decode(gltfData: {json: GLTF}): Promise<void> {
|
|
11
14
|
const gltfScenegraph = new GLTFScenegraph(gltfData);
|
|
@@ -1,10 +1,13 @@
|
|
|
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 '
|
|
4
|
+
import type {GLTF} from '../../types/gltf-types';
|
|
5
5
|
|
|
6
|
-
import GLTFScenegraph from '
|
|
7
|
-
|
|
6
|
+
import GLTFScenegraph from '../../api/gltf-scenegraph';
|
|
7
|
+
|
|
8
|
+
const KHR_MATERIALS_UNLIT = 'KHR_materials_unlit';
|
|
9
|
+
|
|
10
|
+
export const name = KHR_MATERIALS_UNLIT;
|
|
8
11
|
|
|
9
12
|
export async function decode(gltfData: {json: GLTF}): Promise<void> {
|
|
10
13
|
const gltfScenegraph = new GLTFScenegraph(gltfData);
|
|
@@ -1,10 +1,13 @@
|
|
|
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 '
|
|
4
|
+
import type {GLTF} from '../../types/gltf-types';
|
|
5
5
|
|
|
6
|
-
import GLTFScenegraph from '
|
|
7
|
-
|
|
6
|
+
import GLTFScenegraph from '../../api/gltf-scenegraph';
|
|
7
|
+
|
|
8
|
+
const KHR_TECHNIQUES_WEBGL = 'KHR_techniques_webgl';
|
|
9
|
+
|
|
10
|
+
export const name = KHR_TECHNIQUES_WEBGL;
|
|
8
11
|
|
|
9
12
|
export async function decode(gltfData: {json: GLTF}): Promise<void> {
|
|
10
13
|
const gltfScenegraph = new GLTFScenegraph(gltfData);
|
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
// GLTF 1.0 extensions
|
|
2
|
-
export const KHR_BINARY_GLTF = 'KHR_binary_glTF';
|
|
3
|
-
|
|
4
|
-
// GLTF 2.0 extensions
|
|
5
|
-
export const KHR_DRACO_MESH_COMPRESSION = 'KHR_draco_mesh_compression';
|
|
6
|
-
export const KHR_LIGHTS_PUNCTUAL = 'KHR_lights_punctual';
|
|
7
|
-
export const KHR_MATERIALS_UNLIT = 'KHR_materials_unlit';
|
|
8
|
-
export const KHR_TECHNIQUES_WEBGL = 'KHR_techniques_webgl';
|
|
9
|
-
|
|
10
|
-
// External extensions
|
|
11
|
-
export const EXT_MESHOPT_COMPRESSION = 'EXT_meshopt_compression';
|
|
12
|
-
|
|
13
1
|
const COMPONENTS = {
|
|
14
2
|
SCALAR: 1,
|
|
15
3
|
VEC2: 2,
|
|
@@ -1,25 +1,27 @@
|
|
|
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
|
+
import type {GLTFLoaderOptions} from '../../gltf-loader';
|
|
3
5
|
import type {GLB} from '../types/glb-types';
|
|
4
|
-
import type {
|
|
6
|
+
import type {GLTFWithBuffers} from '../types/gltf-types';
|
|
5
7
|
|
|
6
8
|
import {ImageLoader} from '@loaders.gl/images';
|
|
7
9
|
import {parseJSON, sliceArrayBuffer} from '@loaders.gl/loader-utils';
|
|
8
10
|
import {assert} from '../utils/assert';
|
|
9
11
|
import {resolveUrl} from '../gltf-utils/resolve-url';
|
|
10
12
|
import {getTypedArrayForBufferView} from '../gltf-utils/get-typed-array';
|
|
11
|
-
import {decodeExtensions} from '../
|
|
13
|
+
import {preprocessExtensions, decodeExtensions} from '../api/gltf-extensions';
|
|
12
14
|
import {normalizeGLTFV1} from '../api/normalize-gltf-v1';
|
|
13
15
|
import {postProcessGLTF} from '../api/post-process-gltf';
|
|
14
16
|
import parseGLBSync, {isGLB} from './parse-glb';
|
|
15
17
|
|
|
16
18
|
export type GLTFParseOptions = {
|
|
17
|
-
excludeExtensions?: string[];
|
|
18
|
-
decompressMeshes?: boolean;
|
|
19
19
|
normalize?: boolean;
|
|
20
|
-
loadBuffers?: boolean;
|
|
21
20
|
loadImages?: boolean;
|
|
21
|
+
loadBuffers?: boolean;
|
|
22
|
+
decompressMeshes?: boolean;
|
|
22
23
|
postProcess?: boolean;
|
|
24
|
+
excludeExtensions?: string[];
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
// export type GLTFOptions = {
|
|
@@ -32,19 +34,18 @@ export function isGLTF(arrayBuffer, options?): boolean {
|
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
export async function parseGLTF(
|
|
35
|
-
gltf,
|
|
37
|
+
gltf: GLTFWithBuffers,
|
|
36
38
|
arrayBufferOrString,
|
|
37
39
|
byteOffset = 0,
|
|
38
|
-
options:
|
|
39
|
-
gltf?: GLTFParseOptions;
|
|
40
|
-
glb?: GLBParseOptions;
|
|
41
|
-
},
|
|
40
|
+
options: GLTFLoaderOptions,
|
|
42
41
|
context: LoaderContext
|
|
43
42
|
) {
|
|
44
43
|
parseGLTFContainerSync(gltf, arrayBufferOrString, byteOffset, options);
|
|
45
44
|
|
|
46
45
|
normalizeGLTFV1(gltf, {normalize: options?.gltf?.normalize});
|
|
47
46
|
|
|
47
|
+
preprocessExtensions(gltf, options, context);
|
|
48
|
+
|
|
48
49
|
const promises: Promise<any>[] = [];
|
|
49
50
|
|
|
50
51
|
// Load linked buffers asynchronously and decodes base64 buffers in parallel
|
|
@@ -120,10 +121,14 @@ function parseGLTFContainerSync(gltf, data, byteOffset, options) {
|
|
|
120
121
|
gltf.images = new Array(images.length).fill({});
|
|
121
122
|
}
|
|
122
123
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
/** Asynchronously fetch and parse buffers, store in buffers array outside of json
|
|
125
|
+
* TODO - traverse gltf and determine which buffers are actually needed
|
|
126
|
+
*/
|
|
127
|
+
async function loadBuffers(gltf: GLTFWithBuffers, options, context: LoaderContext) {
|
|
128
|
+
// TODO
|
|
129
|
+
const buffers = gltf.json.buffers || [];
|
|
130
|
+
for (let i = 0; i < buffers.length; ++i) {
|
|
131
|
+
const buffer = buffers[i];
|
|
127
132
|
if (buffer.uri) {
|
|
128
133
|
const {fetch} = context;
|
|
129
134
|
assert(fetch);
|
|
@@ -143,19 +148,49 @@ async function loadBuffers(gltf, options, context: LoaderContext) {
|
|
|
143
148
|
}
|
|
144
149
|
}
|
|
145
150
|
|
|
146
|
-
|
|
151
|
+
/**
|
|
152
|
+
* Loads all images
|
|
153
|
+
* TODO - traverse gltf and determine which images are actually needed
|
|
154
|
+
* @param gltf
|
|
155
|
+
* @param options
|
|
156
|
+
* @param context
|
|
157
|
+
* @returns
|
|
158
|
+
*/
|
|
159
|
+
async function loadImages(gltf: GLTFWithBuffers, options, context: LoaderContext) {
|
|
160
|
+
const imageIndices = getReferencesImageIndices(gltf);
|
|
161
|
+
|
|
147
162
|
const images = gltf.json.images || [];
|
|
148
163
|
|
|
149
164
|
const promises: Promise<any>[] = [];
|
|
150
|
-
for (
|
|
151
|
-
promises.push(loadImage(gltf, images[
|
|
165
|
+
for (const imageIndex of imageIndices) {
|
|
166
|
+
promises.push(loadImage(gltf, images[imageIndex], imageIndex, options, context));
|
|
152
167
|
}
|
|
153
168
|
|
|
154
169
|
return await Promise.all(promises);
|
|
155
170
|
}
|
|
156
171
|
|
|
157
|
-
|
|
158
|
-
|
|
172
|
+
/** Make sure we only load images that are actually referenced by textures */
|
|
173
|
+
function getReferencesImageIndices(gltf: GLTFWithBuffers): number[] {
|
|
174
|
+
const imageIndices = new Set<number>();
|
|
175
|
+
|
|
176
|
+
const textures = gltf.json.textures || [];
|
|
177
|
+
for (const texture of textures) {
|
|
178
|
+
if (texture.source !== undefined) {
|
|
179
|
+
imageIndices.add(texture.source);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return Array.from(imageIndices).sort();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Asynchronously fetches and parses one image, store in images array outside of json */
|
|
187
|
+
async function loadImage(
|
|
188
|
+
gltf: GLTFWithBuffers,
|
|
189
|
+
image,
|
|
190
|
+
index: number,
|
|
191
|
+
options,
|
|
192
|
+
context: LoaderContext
|
|
193
|
+
) {
|
|
159
194
|
const {fetch, parse} = context;
|
|
160
195
|
|
|
161
196
|
let arrayBuffer;
|
|
@@ -174,9 +209,26 @@ async function loadImage(gltf, image, index: number, options, context: LoaderCon
|
|
|
174
209
|
assert(arrayBuffer, 'glTF image has no data');
|
|
175
210
|
|
|
176
211
|
// Call `parse`
|
|
177
|
-
|
|
212
|
+
let parsedImage = await parse(
|
|
213
|
+
arrayBuffer,
|
|
214
|
+
[ImageLoader, BasisLoader],
|
|
215
|
+
{mimeType: image.mimeType, basis: {format: selectSupportedBasisFormat()}},
|
|
216
|
+
context
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
if (parsedImage && parsedImage[0]) {
|
|
220
|
+
parsedImage = {
|
|
221
|
+
compressed: true,
|
|
222
|
+
mipmaps: false,
|
|
223
|
+
width: parsedImage[0].width,
|
|
224
|
+
height: parsedImage[0].height,
|
|
225
|
+
data: parsedImage
|
|
226
|
+
};
|
|
227
|
+
}
|
|
178
228
|
// TODO making sure ImageLoader is overridable by using array of loaders
|
|
179
229
|
// const parsedImage = await parse(arrayBuffer, [ImageLoader]);
|
|
180
230
|
|
|
231
|
+
// Store the loaded image
|
|
232
|
+
gltf.images = gltf.images || [];
|
|
181
233
|
gltf.images[index] = parsedImage;
|
|
182
234
|
}
|