@loaders.gl/gltf 4.0.0-alpha.5 → 4.0.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +2 -2
- package/dist/dist.min.js +3545 -2445
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/glb-loader.js +56 -0
- package/dist/es5/glb-loader.js.map +1 -0
- package/dist/es5/glb-writer.js +34 -0
- package/dist/es5/glb-writer.js.map +1 -0
- package/dist/es5/gltf-loader.js +81 -0
- package/dist/es5/gltf-loader.js.map +1 -0
- package/dist/es5/gltf-writer.js +35 -0
- package/dist/es5/gltf-writer.js.map +1 -0
- package/dist/es5/index.js +55 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/api/gltf-extensions.js +109 -0
- package/dist/es5/lib/api/gltf-extensions.js.map +1 -0
- package/dist/es5/lib/api/gltf-scenegraph.js +595 -0
- package/dist/es5/lib/api/gltf-scenegraph.js.map +1 -0
- package/dist/es5/lib/api/normalize-gltf-v1.js +331 -0
- package/dist/es5/lib/api/normalize-gltf-v1.js.map +1 -0
- package/dist/es5/lib/api/post-process-gltf.js +470 -0
- package/dist/es5/lib/api/post-process-gltf.js.map +1 -0
- package/dist/es5/lib/encoders/encode-glb.js +61 -0
- package/dist/es5/lib/encoders/encode-glb.js.map +1 -0
- package/dist/es5/lib/encoders/encode-gltf.js +20 -0
- package/dist/es5/lib/encoders/encode-gltf.js.map +1 -0
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js +94 -0
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -0
- package/dist/es5/lib/extensions/EXT_texture_webp.js +43 -0
- package/dist/es5/lib/extensions/EXT_texture_webp.js.map +1 -0
- package/dist/es5/lib/extensions/KHR_binary_gltf.js +39 -0
- package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +1 -0
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +247 -0
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -0
- package/dist/es5/lib/extensions/KHR_texture_basisu.js +36 -0
- package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -0
- package/dist/es5/lib/extensions/KHR_texture_transform.js +230 -0
- package/dist/es5/lib/extensions/KHR_texture_transform.js.map +1 -0
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +103 -0
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -0
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js +99 -0
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -0
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js +76 -0
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -0
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js +113 -0
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -0
- package/dist/es5/lib/gltf-utils/get-typed-array.js +23 -0
- package/dist/es5/lib/gltf-utils/get-typed-array.js.map +1 -0
- package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js +68 -0
- package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js.map +1 -0
- package/dist/es5/lib/gltf-utils/gltf-constants.js +48 -0
- package/dist/es5/lib/gltf-utils/gltf-constants.js.map +1 -0
- package/dist/es5/lib/gltf-utils/gltf-utils.js +86 -0
- package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -0
- package/dist/es5/lib/gltf-utils/resolve-url.js +18 -0
- package/dist/es5/lib/gltf-utils/resolve-url.js.map +1 -0
- package/dist/es5/lib/parsers/parse-glb.js +120 -0
- package/dist/es5/lib/parsers/parse-glb.js.map +1 -0
- package/dist/es5/lib/parsers/parse-gltf.js +283 -0
- package/dist/es5/lib/parsers/parse-gltf.js.map +1 -0
- package/dist/es5/lib/types/glb-types.js +2 -0
- package/dist/es5/lib/types/glb-types.js.map +1 -0
- package/dist/es5/lib/types/gltf-json-schema.js +2 -0
- package/dist/es5/lib/types/gltf-json-schema.js.map +1 -0
- package/dist/es5/lib/types/gltf-postprocessed-schema.js +2 -0
- package/dist/es5/lib/types/gltf-postprocessed-schema.js.map +1 -0
- package/dist/es5/lib/types/gltf-types.js +2 -0
- package/dist/es5/lib/types/gltf-types.js.map +1 -0
- package/dist/es5/lib/utils/assert.js +12 -0
- package/dist/es5/lib/utils/assert.js.map +1 -0
- package/dist/es5/lib/utils/version.js +9 -0
- package/dist/es5/lib/utils/version.js.map +1 -0
- package/dist/es5/meshopt/meshopt-decoder.js +215 -0
- package/dist/es5/meshopt/meshopt-decoder.js.map +1 -0
- package/dist/es5/webp/webp.js +83 -0
- package/dist/es5/webp/webp.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/glb-loader.js +31 -0
- package/dist/esm/glb-loader.js.map +1 -0
- package/dist/esm/glb-writer.js +27 -0
- package/dist/esm/glb-writer.js.map +1 -0
- package/dist/esm/gltf-loader.js +51 -0
- package/dist/esm/gltf-loader.js.map +1 -0
- package/dist/esm/gltf-writer.js +28 -0
- package/dist/esm/gltf-writer.js.map +1 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/api/gltf-extensions.js +35 -0
- package/dist/esm/lib/api/gltf-extensions.js.map +1 -0
- package/dist/esm/lib/api/gltf-scenegraph.js +452 -0
- package/dist/esm/lib/api/gltf-scenegraph.js.map +1 -0
- package/dist/esm/lib/api/normalize-gltf-v1.js +204 -0
- package/dist/esm/lib/api/normalize-gltf-v1.js.map +1 -0
- package/dist/esm/lib/api/post-process-gltf.js +396 -0
- package/dist/esm/lib/api/post-process-gltf.js.map +1 -0
- package/dist/esm/lib/encoders/encode-glb.js +54 -0
- package/dist/esm/lib/encoders/encode-glb.js.map +1 -0
- package/dist/esm/lib/encoders/encode-gltf.js +14 -0
- package/dist/esm/lib/encoders/encode-gltf.js.map +1 -0
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js +41 -0
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js.map +1 -0
- package/dist/esm/lib/extensions/EXT_texture_webp.js +25 -0
- package/dist/esm/lib/extensions/EXT_texture_webp.js.map +1 -0
- package/dist/esm/lib/extensions/KHR_binary_gltf.js +21 -0
- package/dist/esm/lib/extensions/KHR_binary_gltf.js.map +1 -0
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js +111 -0
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js.map +1 -0
- package/dist/esm/lib/extensions/KHR_texture_basisu.js +18 -0
- package/dist/esm/lib/extensions/KHR_texture_basisu.js.map +1 -0
- package/dist/esm/lib/extensions/KHR_texture_transform.js +182 -0
- package/dist/esm/lib/extensions/KHR_texture_transform.js.map +1 -0
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js +77 -0
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -0
- package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js +42 -0
- package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -0
- package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js +33 -0
- package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -0
- package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js +61 -0
- package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -0
- package/dist/esm/lib/gltf-utils/get-typed-array.js +16 -0
- package/dist/esm/lib/gltf-utils/get-typed-array.js.map +1 -0
- package/dist/esm/lib/gltf-utils/gltf-attribute-utils.js +62 -0
- package/dist/esm/lib/gltf-utils/gltf-attribute-utils.js.map +1 -0
- package/dist/esm/lib/gltf-utils/gltf-constants.js +37 -0
- package/dist/esm/lib/gltf-utils/gltf-constants.js.map +1 -0
- package/dist/esm/lib/gltf-utils/gltf-utils.js +74 -0
- package/dist/esm/lib/gltf-utils/gltf-utils.js.map +1 -0
- package/dist/esm/lib/gltf-utils/resolve-url.js +12 -0
- package/dist/esm/lib/gltf-utils/resolve-url.js.map +1 -0
- package/dist/esm/lib/parsers/parse-glb.js +114 -0
- package/dist/esm/lib/parsers/parse-glb.js.map +1 -0
- package/dist/esm/lib/parsers/parse-gltf.js +155 -0
- package/dist/esm/lib/parsers/parse-gltf.js.map +1 -0
- package/dist/esm/lib/types/glb-types.js +2 -0
- package/dist/esm/lib/types/glb-types.js.map +1 -0
- package/dist/esm/lib/types/gltf-json-schema.js +2 -0
- package/dist/esm/lib/types/gltf-json-schema.js.map +1 -0
- package/dist/esm/lib/types/gltf-postprocessed-schema.js +2 -0
- package/dist/esm/lib/types/gltf-postprocessed-schema.js.map +1 -0
- package/dist/esm/lib/types/gltf-types.js +2 -0
- package/dist/esm/lib/types/gltf-types.js.map +1 -0
- package/dist/esm/lib/utils/assert.js +6 -0
- package/dist/esm/lib/utils/assert.js.map +1 -0
- package/dist/esm/lib/utils/version.js +2 -0
- package/dist/esm/lib/utils/version.js.map +1 -0
- package/dist/esm/meshopt/meshopt-decoder.js +91 -0
- package/dist/esm/meshopt/meshopt-decoder.js.map +1 -0
- package/dist/esm/meshopt/meshopt-encoder.ts.disabled +409 -0
- package/dist/esm/webp/webp.js +25 -0
- package/dist/esm/webp/webp.js.map +1 -0
- package/dist/glb-loader.d.ts +5 -4
- package/dist/glb-loader.d.ts.map +1 -1
- package/dist/glb-loader.js +30 -28
- package/dist/glb-writer.d.ts +7 -16
- package/dist/glb-writer.d.ts.map +1 -1
- package/dist/glb-writer.js +32 -26
- package/dist/gltf-loader.d.ts +7 -6
- package/dist/gltf-loader.d.ts.map +1 -1
- package/dist/gltf-loader.js +46 -43
- package/dist/gltf-writer.d.ts +2 -2
- package/dist/gltf-writer.d.ts.map +1 -1
- package/dist/gltf-writer.js +29 -26
- package/dist/index.d.ts +8 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -7
- package/dist/lib/api/gltf-extensions.d.ts +7 -2
- package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
- package/dist/lib/api/gltf-extensions.js +79 -31
- package/dist/lib/api/gltf-scenegraph.d.ts +10 -14
- package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
- package/dist/lib/api/gltf-scenegraph.js +577 -513
- package/dist/lib/api/normalize-gltf-v1.d.ts.map +1 -1
- package/dist/lib/api/normalize-gltf-v1.js +278 -229
- package/dist/lib/api/post-process-gltf.d.ts +4 -1
- package/dist/lib/api/post-process-gltf.d.ts.map +1 -1
- package/dist/lib/api/post-process-gltf.js +385 -374
- package/dist/lib/encoders/encode-glb.d.ts +14 -1
- package/dist/lib/encoders/encode-glb.d.ts.map +1 -1
- package/dist/lib/encoders/encode-glb.js +67 -58
- package/dist/lib/encoders/encode-gltf.d.ts +18 -0
- package/dist/lib/encoders/encode-gltf.d.ts.map +1 -1
- package/dist/lib/encoders/encode-gltf.js +30 -12
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts +1 -4
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_meshopt_compression.js +35 -50
- package/dist/lib/extensions/EXT_texture_webp.d.ts +1 -1
- package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_texture_webp.js +32 -28
- package/dist/lib/extensions/KHR_binary_gltf.d.ts +1 -1
- package/dist/lib/extensions/KHR_binary_gltf.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_binary_gltf.js +36 -23
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +1 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.js +123 -111
- package/dist/lib/extensions/KHR_texture_basisu.d.ts +1 -1
- package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_basisu.js +26 -19
- package/dist/lib/extensions/KHR_texture_transform.d.ts +13 -0
- package/dist/lib/extensions/KHR_texture_transform.d.ts.map +1 -0
- package/dist/lib/extensions/KHR_texture_transform.js +227 -0
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +6 -0
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -0
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +115 -0
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +54 -44
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +39 -32
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +73 -62
- package/dist/lib/gltf-utils/get-typed-array.js +39 -14
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts +1 -1
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-attribute-utils.js +65 -65
- package/dist/lib/gltf-utils/gltf-constants.d.ts +17 -0
- package/dist/lib/gltf-utils/gltf-constants.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-constants.js +38 -32
- package/dist/lib/gltf-utils/gltf-utils.d.ts +7 -0
- package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-utils.js +79 -45
- package/dist/lib/gltf-utils/resolve-url.js +17 -15
- package/dist/lib/parsers/parse-glb.d.ts +15 -3
- package/dist/lib/parsers/parse-glb.d.ts.map +1 -1
- package/dist/lib/parsers/parse-glb.js +143 -105
- package/dist/lib/parsers/parse-gltf.d.ts +8 -4
- package/dist/lib/parsers/parse-gltf.d.ts.map +1 -1
- package/dist/lib/parsers/parse-gltf.js +166 -154
- package/dist/lib/types/glb-types.d.ts +3 -3
- package/dist/lib/types/glb-types.d.ts.map +1 -1
- package/dist/lib/types/glb-types.js +2 -2
- package/dist/lib/types/gltf-json-schema.d.ts +530 -132
- package/dist/lib/types/gltf-json-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-json-schema.js +4 -2
- package/dist/lib/types/gltf-postprocessed-schema.d.ts +175 -210
- package/dist/lib/types/gltf-postprocessed-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-postprocessed-schema.js +4 -2
- package/dist/lib/types/gltf-types.d.ts +22 -7
- package/dist/lib/types/gltf-types.d.ts.map +1 -1
- package/dist/lib/types/gltf-types.js +3 -2
- package/dist/lib/utils/assert.js +11 -5
- package/dist/lib/utils/version.js +7 -2
- package/dist/meshopt/meshopt-decoder.js +97 -82
- package/dist/webp/webp.d.ts +1 -1
- package/dist/webp/webp.d.ts.map +1 -1
- package/dist/webp/webp.js +32 -23
- package/package.json +9 -8
- package/src/glb-loader.ts +4 -4
- package/src/glb-writer.ts +11 -3
- package/src/gltf-loader.ts +12 -8
- package/src/gltf-writer.ts +2 -2
- package/src/index.ts +34 -6
- package/src/lib/api/gltf-extensions.ts +14 -3
- package/src/lib/api/gltf-scenegraph.ts +61 -34
- package/src/lib/api/normalize-gltf-v1.ts +2 -1
- package/src/lib/api/post-process-gltf.ts +275 -150
- package/src/lib/encoders/encode-glb.ts +21 -4
- package/src/lib/encoders/encode-gltf.ts +19 -10
- package/src/lib/extensions/EXT_meshopt_compression.ts +16 -25
- package/src/lib/extensions/EXT_texture_webp.ts +5 -4
- package/src/lib/extensions/KHR_binary_gltf.ts +3 -3
- package/src/lib/extensions/KHR_draco_mesh_compression.ts +8 -8
- package/src/lib/extensions/KHR_texture_basisu.ts +4 -3
- package/src/lib/extensions/KHR_texture_transform.ts +308 -0
- package/src/lib/extensions/deprecated/EXT_feature_metadata.ts +163 -0
- package/src/lib/extensions/deprecated/KHR_lights_punctual.ts +2 -2
- package/src/lib/extensions/deprecated/KHR_materials_unlit.ts +5 -5
- package/src/lib/extensions/deprecated/KHR_techniques_webgl.ts +3 -2
- package/src/lib/gltf-utils/gltf-attribute-utils.ts +1 -1
- package/src/lib/gltf-utils/gltf-constants.ts +2 -2
- package/src/lib/gltf-utils/gltf-utils.ts +31 -0
- package/src/lib/parsers/parse-glb.ts +50 -24
- package/src/lib/parsers/parse-gltf.ts +32 -17
- package/src/lib/types/glb-types.ts +1 -1
- package/src/lib/types/gltf-json-schema.ts +582 -126
- package/src/lib/types/gltf-postprocessed-schema.ts +289 -212
- package/src/lib/types/gltf-types.ts +41 -44
- package/dist/bundle.js.map +0 -1
- package/dist/glb-loader.js.map +0 -1
- package/dist/glb-writer.js.map +0 -1
- package/dist/gltf-loader.js.map +0 -1
- package/dist/gltf-writer.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/api/gltf-extensions.js.map +0 -1
- package/dist/lib/api/gltf-scenegraph.js.map +0 -1
- package/dist/lib/api/normalize-gltf-v1.js.map +0 -1
- package/dist/lib/api/post-process-gltf.js.map +0 -1
- package/dist/lib/encoders/encode-glb.js.map +0 -1
- package/dist/lib/encoders/encode-gltf.js.map +0 -1
- package/dist/lib/extensions/EXT_meshopt_compression.js.map +0 -1
- package/dist/lib/extensions/EXT_texture_webp.js.map +0 -1
- package/dist/lib/extensions/KHR_binary_gltf.js.map +0 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.js.map +0 -1
- package/dist/lib/extensions/KHR_texture_basisu.js.map +0 -1
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.js.map +0 -1
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.js.map +0 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js.map +0 -1
- package/dist/lib/gltf-utils/get-typed-array.js.map +0 -1
- package/dist/lib/gltf-utils/gltf-attribute-utils.js.map +0 -1
- package/dist/lib/gltf-utils/gltf-constants.js.map +0 -1
- package/dist/lib/gltf-utils/gltf-utils.js.map +0 -1
- package/dist/lib/gltf-utils/resolve-url.js.map +0 -1
- package/dist/lib/parsers/parse-glb.js.map +0 -1
- package/dist/lib/parsers/parse-gltf.js.map +0 -1
- package/dist/lib/types/glb-types.js.map +0 -1
- package/dist/lib/types/gltf-json-schema.js.map +0 -1
- package/dist/lib/types/gltf-postprocessed-schema.js.map +0 -1
- package/dist/lib/types/gltf-types.js.map +0 -1
- package/dist/lib/utils/assert.js.map +0 -1
- package/dist/lib/utils/version.js.map +0 -1
- package/dist/meshopt/meshopt-decoder.js.map +0 -1
- package/dist/webp/webp.js.map +0 -1
- /package/dist/{meshopt → es5/meshopt}/meshopt-encoder.ts.disabled +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* eslint-disable camelcase */
|
|
2
|
-
import type {GLTF, GLTFBufferView, GLTF_EXT_meshopt_compression} from '../types/gltf-
|
|
2
|
+
import type {GLTF, GLTFBufferView, GLTF_EXT_meshopt_compression} from '../types/gltf-json-schema';
|
|
3
3
|
import type {GLTFLoaderOptions} from '../../gltf-loader';
|
|
4
|
-
import GLTFScenegraph from '../api/gltf-scenegraph';
|
|
5
|
-
import {
|
|
4
|
+
import {GLTFScenegraph} from '../api/gltf-scenegraph';
|
|
5
|
+
import {meshoptDecodeGltfBuffer} from '../../meshopt/meshopt-decoder';
|
|
6
6
|
|
|
7
7
|
// @ts-ignore
|
|
8
8
|
// eslint-disable-next-line
|
|
@@ -16,16 +16,6 @@ const EXT_MESHOPT_COMPRESSION = 'EXT_meshopt_compression';
|
|
|
16
16
|
|
|
17
17
|
export const name = EXT_MESHOPT_COMPRESSION;
|
|
18
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
19
|
export async function decode(gltfData: {json: GLTF}, options: GLTFLoaderOptions) {
|
|
30
20
|
const scenegraph = new GLTFScenegraph(gltfData);
|
|
31
21
|
|
|
@@ -41,7 +31,7 @@ export async function decode(gltfData: {json: GLTF}, options: GLTFLoaderOptions)
|
|
|
41
31
|
// Decompress meshes in parallel
|
|
42
32
|
await Promise.all(promises);
|
|
43
33
|
|
|
44
|
-
// We have now decompressed all primitives, so remove the top-level
|
|
34
|
+
// We have now decompressed all primitives, so remove the top-level extension
|
|
45
35
|
scenegraph.removeExtension(EXT_MESHOPT_COMPRESSION);
|
|
46
36
|
}
|
|
47
37
|
|
|
@@ -49,29 +39,30 @@ export async function decode(gltfData: {json: GLTF}, options: GLTFLoaderOptions)
|
|
|
49
39
|
async function decodeMeshoptBufferView(
|
|
50
40
|
scenegraph: GLTFScenegraph,
|
|
51
41
|
bufferView: GLTFBufferView
|
|
52
|
-
): Promise<
|
|
42
|
+
): Promise<void> {
|
|
53
43
|
const meshoptExtension = scenegraph.getObjectExtension<GLTF_EXT_meshopt_compression>(
|
|
54
44
|
bufferView,
|
|
55
45
|
EXT_MESHOPT_COMPRESSION
|
|
56
46
|
);
|
|
57
47
|
if (meshoptExtension) {
|
|
58
|
-
const buffer = bufferView.buffer;
|
|
59
|
-
|
|
60
48
|
const {
|
|
61
49
|
byteOffset = 0,
|
|
62
50
|
byteLength = 0,
|
|
63
51
|
byteStride,
|
|
64
52
|
count,
|
|
65
53
|
mode,
|
|
66
|
-
filter = 'NONE'
|
|
54
|
+
filter = 'NONE',
|
|
55
|
+
buffer: bufferIndex
|
|
67
56
|
} = meshoptExtension;
|
|
57
|
+
const buffer = scenegraph.gltf.buffers[bufferIndex];
|
|
68
58
|
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
59
|
+
const source = new Uint8Array(buffer.arrayBuffer, buffer.byteOffset + byteOffset, byteLength);
|
|
60
|
+
const result = new Uint8Array(
|
|
61
|
+
scenegraph.gltf.buffers[bufferView.buffer].arrayBuffer,
|
|
62
|
+
bufferView.byteOffset,
|
|
63
|
+
bufferView.byteLength
|
|
64
|
+
);
|
|
65
|
+
await meshoptDecodeGltfBuffer(result, count, byteStride, source, mode, filter);
|
|
66
|
+
scenegraph.removeObjectExtension(bufferView, EXT_MESHOPT_COMPRESSION);
|
|
74
67
|
}
|
|
75
|
-
|
|
76
|
-
return null;
|
|
77
68
|
}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/EXT_TEXTURE_WEBP
|
|
3
3
|
/* eslint-disable camelcase */
|
|
4
4
|
|
|
5
|
-
import type {GLTF, GLTF_EXT_texture_webp} from '../types/gltf-
|
|
5
|
+
import type {GLTF, GLTF_EXT_texture_webp} from '../types/gltf-json-schema';
|
|
6
6
|
import type {GLTFLoaderOptions} from '../../gltf-loader';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import GLTFScenegraph from '../api/gltf-scenegraph';
|
|
8
|
+
import {isImageFormatSupported} from '@loaders.gl/images';
|
|
9
|
+
import {GLTFScenegraph} from '../api/gltf-scenegraph';
|
|
10
10
|
|
|
11
11
|
const EXT_TEXTURE_WEBP = 'EXT_texture_webp';
|
|
12
12
|
|
|
@@ -20,7 +20,7 @@ export const name = EXT_TEXTURE_WEBP;
|
|
|
20
20
|
export function preprocess(gltfData: {json: GLTF}, options: GLTFLoaderOptions): void {
|
|
21
21
|
const scenegraph = new GLTFScenegraph(gltfData);
|
|
22
22
|
|
|
23
|
-
if (!
|
|
23
|
+
if (!isImageFormatSupported('image/webp')) {
|
|
24
24
|
if (scenegraph.getRequiredExtensions().includes(EXT_TEXTURE_WEBP)) {
|
|
25
25
|
throw new Error(`gltf: Required extension ${EXT_TEXTURE_WEBP} not supported by browser`);
|
|
26
26
|
}
|
|
@@ -35,6 +35,7 @@ export function preprocess(gltfData: {json: GLTF}, options: GLTFLoaderOptions):
|
|
|
35
35
|
EXT_TEXTURE_WEBP
|
|
36
36
|
);
|
|
37
37
|
if (extension) {
|
|
38
|
+
// TODO - if multiple texture extensions are present which one wins?
|
|
38
39
|
texture.source = extension.source;
|
|
39
40
|
}
|
|
40
41
|
scenegraph.removeObjectExtension(texture, EXT_TEXTURE_WEBP);
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF
|
|
3
3
|
/* eslint-disable camelcase */
|
|
4
4
|
|
|
5
|
-
import type {GLTF, GLTF_KHR_binary_glTF} from '../types/gltf-
|
|
5
|
+
import type {GLTF, GLTF_KHR_binary_glTF} from '../types/gltf-json-schema';
|
|
6
6
|
|
|
7
|
-
import GLTFScenegraph from '../api/gltf-scenegraph';
|
|
7
|
+
import {GLTFScenegraph} from '../api/gltf-scenegraph';
|
|
8
8
|
|
|
9
9
|
const KHR_BINARY_GLTF = 'KHR_binary_glTF';
|
|
10
10
|
|
|
@@ -40,7 +40,7 @@ export function preprocess(gltfData: {json: GLTF}): void {
|
|
|
40
40
|
delete json.buffers[0].uri;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
// Remove the top-level extension as it has now been
|
|
43
|
+
// Remove the top-level extension as it has now been processed
|
|
44
44
|
gltfScenegraph.removeExtension(KHR_BINARY_GLTF);
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -8,14 +8,14 @@ import type {
|
|
|
8
8
|
GLTFAccessor,
|
|
9
9
|
GLTFMeshPrimitive,
|
|
10
10
|
GLTF_KHR_draco_mesh_compression
|
|
11
|
-
} from '../types/gltf-
|
|
11
|
+
} from '../types/gltf-json-schema';
|
|
12
12
|
import type {GLTFLoaderOptions} from '../../gltf-loader';
|
|
13
13
|
|
|
14
14
|
import type {LoaderContext} from '@loaders.gl/loader-utils';
|
|
15
15
|
import {DracoLoader} from '@loaders.gl/draco';
|
|
16
16
|
import {DracoLoaderOptions, DracoMesh} from '@loaders.gl/draco';
|
|
17
17
|
import {sliceArrayBuffer} from '@loaders.gl/loader-utils';
|
|
18
|
-
import {
|
|
18
|
+
import {GLTFScenegraph} from '../api/gltf-scenegraph';
|
|
19
19
|
import {getGLTFAccessors, getGLTFAccessor} from '../gltf-utils/gltf-attribute-utils';
|
|
20
20
|
|
|
21
21
|
const KHR_DRACO_MESH_COMPRESSION = 'KHR_draco_mesh_compression';
|
|
@@ -28,7 +28,7 @@ export function preprocess(
|
|
|
28
28
|
options: GLTFLoaderOptions,
|
|
29
29
|
context: LoaderContext
|
|
30
30
|
): void {
|
|
31
|
-
const scenegraph = new
|
|
31
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
32
32
|
for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {
|
|
33
33
|
if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {
|
|
34
34
|
// TODO - Remove fallback accessors to make sure we don't load unnecessary buffers
|
|
@@ -45,7 +45,7 @@ export async function decode(
|
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
const scenegraph = new
|
|
48
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
49
49
|
const promises: Promise<void>[] = [];
|
|
50
50
|
for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {
|
|
51
51
|
if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {
|
|
@@ -56,12 +56,12 @@ export async function decode(
|
|
|
56
56
|
// Decompress meshes in parallel
|
|
57
57
|
await Promise.all(promises);
|
|
58
58
|
|
|
59
|
-
// We have now decompressed all primitives, so remove the top-level
|
|
59
|
+
// We have now decompressed all primitives, so remove the top-level extension
|
|
60
60
|
scenegraph.removeExtension(KHR_DRACO_MESH_COMPRESSION);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
export function encode(gltfData, options: GLTFLoaderOptions = {}): void {
|
|
64
|
-
const scenegraph = new
|
|
64
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
65
65
|
|
|
66
66
|
for (const mesh of scenegraph.json.meshes || []) {
|
|
67
67
|
// eslint-disable-next-line camelcase
|
|
@@ -81,7 +81,7 @@ export function encode(gltfData, options: GLTFLoaderOptions = {}): void {
|
|
|
81
81
|
// TODO - Implement fallback behavior per KHR_DRACO_MESH_COMPRESSION spec
|
|
82
82
|
|
|
83
83
|
async function decompressPrimitive(
|
|
84
|
-
scenegraph:
|
|
84
|
+
scenegraph: GLTFScenegraph,
|
|
85
85
|
primitive: GLTFMeshPrimitive,
|
|
86
86
|
options: GLTFLoaderOptions,
|
|
87
87
|
context: LoaderContext
|
|
@@ -128,7 +128,7 @@ async function decompressPrimitive(
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
// Extension has been processed, delete it
|
|
131
|
-
|
|
131
|
+
scenegraph.removeObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION);
|
|
132
132
|
|
|
133
133
|
checkPrimitive(primitive);
|
|
134
134
|
}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_basisu
|
|
3
3
|
/* eslint-disable camelcase */
|
|
4
4
|
|
|
5
|
-
import type {GLTF, GLTF_KHR_texture_basisu} from '../types/gltf-
|
|
5
|
+
import type {GLTF, GLTF_KHR_texture_basisu} from '../types/gltf-json-schema';
|
|
6
6
|
import type {GLTFLoaderOptions} from '../../gltf-loader';
|
|
7
7
|
|
|
8
|
-
import GLTFScenegraph from '../api/gltf-scenegraph';
|
|
8
|
+
import {GLTFScenegraph} from '../api/gltf-scenegraph';
|
|
9
9
|
|
|
10
10
|
const KHR_TEXTURE_BASISU = 'KHR_texture_basisu';
|
|
11
11
|
|
|
@@ -26,9 +26,10 @@ export function preprocess(gltfData: {json: GLTF}, options: GLTFLoaderOptions):
|
|
|
26
26
|
KHR_TEXTURE_BASISU
|
|
27
27
|
);
|
|
28
28
|
if (extension) {
|
|
29
|
+
// TODO - if multiple texture extensions are present which one wins?
|
|
29
30
|
texture.source = extension.source;
|
|
31
|
+
scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);
|
|
30
32
|
}
|
|
31
|
-
scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
// Remove the top-level extension
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_transform/README.md
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {Vector3, Matrix3} from '@math.gl/core';
|
|
6
|
+
import type {GLTFWithBuffers} from '../types/gltf-types';
|
|
7
|
+
import type {
|
|
8
|
+
GLTFMeshPrimitive,
|
|
9
|
+
GLTFAccessor,
|
|
10
|
+
GLTFBufferView,
|
|
11
|
+
GLTFMaterialNormalTextureInfo,
|
|
12
|
+
GLTFMaterialOcclusionTextureInfo,
|
|
13
|
+
GLTFTextureInfo
|
|
14
|
+
} from '../types/gltf-json-schema';
|
|
15
|
+
import type {GLTFLoaderOptions} from '../../gltf-loader';
|
|
16
|
+
|
|
17
|
+
import {getAccessorArrayTypeAndLength} from '../gltf-utils/gltf-utils';
|
|
18
|
+
import {BYTES, COMPONENTS} from '../gltf-utils/gltf-constants';
|
|
19
|
+
import {} from '../types/gltf-json-schema';
|
|
20
|
+
import {GLTFScenegraph} from '../api/gltf-scenegraph';
|
|
21
|
+
|
|
22
|
+
/** Extension name */
|
|
23
|
+
const EXT_MESHOPT_TRANSFORM = 'KHR_texture_transform';
|
|
24
|
+
|
|
25
|
+
export const name = EXT_MESHOPT_TRANSFORM;
|
|
26
|
+
|
|
27
|
+
const scratchVector = new Vector3();
|
|
28
|
+
const scratchRotationMatrix = new Matrix3();
|
|
29
|
+
const scratchScaleMatrix = new Matrix3();
|
|
30
|
+
|
|
31
|
+
/** Extension textureInfo https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates */
|
|
32
|
+
type TextureInfo = {
|
|
33
|
+
/** The offset of the UV coordinate origin as a factor of the texture dimensions. */
|
|
34
|
+
offset?: [number, number];
|
|
35
|
+
/** Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise. */
|
|
36
|
+
rotation?: number;
|
|
37
|
+
/** The scale factor applied to the components of the UV coordinates. */
|
|
38
|
+
scale?: [number, number];
|
|
39
|
+
/** Overrides the textureInfo texCoord value if supplied, and if this extension is supported. */
|
|
40
|
+
texCoord?: number;
|
|
41
|
+
};
|
|
42
|
+
/** Intersection of all GLTF textures */
|
|
43
|
+
type CompoundGLTFTextureInfo = GLTFTextureInfo &
|
|
44
|
+
GLTFMaterialNormalTextureInfo &
|
|
45
|
+
GLTFMaterialOcclusionTextureInfo;
|
|
46
|
+
/** Parameters for TEXCOORD transformation */
|
|
47
|
+
type TransformParameters = {
|
|
48
|
+
/** Original texCoord value https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#_textureinfo_texcoord */
|
|
49
|
+
originalTexCoord: number;
|
|
50
|
+
/** New texCoord value from extension https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates */
|
|
51
|
+
texCoord: number;
|
|
52
|
+
/** Transformation matrix */
|
|
53
|
+
matrix: Matrix3;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The extension entry to process the transformation
|
|
58
|
+
* @param gltfData gltf buffers and json
|
|
59
|
+
* @param options GLTFLoader options
|
|
60
|
+
*/
|
|
61
|
+
export async function decode(gltfData: GLTFWithBuffers, options: GLTFLoaderOptions) {
|
|
62
|
+
const gltfScenegraph = new GLTFScenegraph(gltfData);
|
|
63
|
+
const hasExtension = gltfScenegraph.hasExtension(EXT_MESHOPT_TRANSFORM);
|
|
64
|
+
if (!hasExtension) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const materials = gltfData.json.materials || [];
|
|
68
|
+
for (let i = 0; i < materials.length; i++) {
|
|
69
|
+
transformTexCoords(i, gltfData);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Transform TEXCOORD by material
|
|
75
|
+
* @param materialIndex processing material index
|
|
76
|
+
* @param gltfData gltf buffers and json
|
|
77
|
+
*/
|
|
78
|
+
function transformTexCoords(materialIndex: number, gltfData: GLTFWithBuffers): void {
|
|
79
|
+
// Save processed texCoords in order no to process the same twice
|
|
80
|
+
const processedTexCoords: [number, number][] = [];
|
|
81
|
+
const material = gltfData.json.materials?.[materialIndex];
|
|
82
|
+
const baseColorTexture = material?.pbrMetallicRoughness?.baseColorTexture;
|
|
83
|
+
if (baseColorTexture) {
|
|
84
|
+
transformPrimitives(gltfData, materialIndex, baseColorTexture, processedTexCoords);
|
|
85
|
+
}
|
|
86
|
+
const emisiveTexture = material?.emissiveTexture;
|
|
87
|
+
if (emisiveTexture) {
|
|
88
|
+
transformPrimitives(gltfData, materialIndex, emisiveTexture, processedTexCoords);
|
|
89
|
+
}
|
|
90
|
+
const normalTexture = material?.normalTexture;
|
|
91
|
+
if (normalTexture) {
|
|
92
|
+
transformPrimitives(gltfData, materialIndex, normalTexture, processedTexCoords);
|
|
93
|
+
}
|
|
94
|
+
const occlusionTexture = material?.occlusionTexture;
|
|
95
|
+
if (occlusionTexture) {
|
|
96
|
+
transformPrimitives(gltfData, materialIndex, occlusionTexture, processedTexCoords);
|
|
97
|
+
}
|
|
98
|
+
const metallicRoughnessTexture = material?.pbrMetallicRoughness?.metallicRoughnessTexture;
|
|
99
|
+
if (metallicRoughnessTexture) {
|
|
100
|
+
transformPrimitives(gltfData, materialIndex, metallicRoughnessTexture, processedTexCoords);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Transform primitives of the particular material
|
|
106
|
+
* @param gltfData gltf data
|
|
107
|
+
* @param materialIndex primitives with this material will be transformed
|
|
108
|
+
* @param texture texture object
|
|
109
|
+
* @param processedTexCoords storage to save already processed texCoords
|
|
110
|
+
*/
|
|
111
|
+
function transformPrimitives(
|
|
112
|
+
gltfData: GLTFWithBuffers,
|
|
113
|
+
materialIndex: number,
|
|
114
|
+
texture: CompoundGLTFTextureInfo,
|
|
115
|
+
processedTexCoords: [number, number][]
|
|
116
|
+
) {
|
|
117
|
+
const transformParameters = getTransformParameters(texture, processedTexCoords);
|
|
118
|
+
if (!transformParameters) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const meshes = gltfData.json.meshes || [];
|
|
122
|
+
for (const mesh of meshes) {
|
|
123
|
+
for (const primitive of mesh.primitives) {
|
|
124
|
+
const material = primitive.material;
|
|
125
|
+
if (Number.isFinite(material) && materialIndex === material) {
|
|
126
|
+
transformPrimitive(gltfData, primitive, transformParameters);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Get parameters for TEXCOORD transformation
|
|
134
|
+
* @param texture texture object
|
|
135
|
+
* @param processedTexCoords storage to save already processed texCoords
|
|
136
|
+
* @returns texCoord couple and transformation matrix
|
|
137
|
+
*/
|
|
138
|
+
function getTransformParameters(
|
|
139
|
+
texture: CompoundGLTFTextureInfo,
|
|
140
|
+
processedTexCoords: [number, number][]
|
|
141
|
+
): TransformParameters | null {
|
|
142
|
+
const textureInfo = texture.extensions?.[EXT_MESHOPT_TRANSFORM];
|
|
143
|
+
const {texCoord: originalTexCoord = 0} = texture;
|
|
144
|
+
// If texCoord is not set in the extension, original attribute data will be replaced
|
|
145
|
+
const {texCoord = originalTexCoord} = textureInfo;
|
|
146
|
+
// Make sure that couple [originalTexCoord, extensionTexCoord] is not processed twice
|
|
147
|
+
const isProcessed =
|
|
148
|
+
processedTexCoords.findIndex(
|
|
149
|
+
([original, newTexCoord]) => original === originalTexCoord && newTexCoord === texCoord
|
|
150
|
+
) !== -1;
|
|
151
|
+
if (!isProcessed) {
|
|
152
|
+
const matrix = makeTransformationMatrix(textureInfo);
|
|
153
|
+
if (originalTexCoord !== texCoord) {
|
|
154
|
+
texture.texCoord = texCoord;
|
|
155
|
+
}
|
|
156
|
+
processedTexCoords.push([originalTexCoord, texCoord]);
|
|
157
|
+
return {originalTexCoord, texCoord, matrix};
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Transform `TEXCOORD_0` attribute in the primitive
|
|
164
|
+
* @param gltfData gltf data
|
|
165
|
+
* @param primitive primitive object
|
|
166
|
+
* @param transformParameters texCoord couple and transformation matrix
|
|
167
|
+
*/
|
|
168
|
+
function transformPrimitive(
|
|
169
|
+
gltfData: GLTFWithBuffers,
|
|
170
|
+
primitive: GLTFMeshPrimitive,
|
|
171
|
+
transformParameters: TransformParameters
|
|
172
|
+
) {
|
|
173
|
+
const {originalTexCoord, texCoord, matrix} = transformParameters;
|
|
174
|
+
const texCoordAccessor = primitive.attributes[`TEXCOORD_${originalTexCoord}`];
|
|
175
|
+
if (Number.isFinite(texCoordAccessor)) {
|
|
176
|
+
// Get accessor of the `TEXCOORD_0` attribute
|
|
177
|
+
const accessor = gltfData.json.accessors?.[texCoordAccessor];
|
|
178
|
+
if (accessor && accessor.bufferView) {
|
|
179
|
+
// Get `bufferView` of the `accessor`
|
|
180
|
+
const bufferView = gltfData.json.bufferViews?.[accessor.bufferView];
|
|
181
|
+
if (bufferView) {
|
|
182
|
+
// Get `arrayBuffer` the `bufferView` look at
|
|
183
|
+
const {arrayBuffer, byteOffset: bufferByteOffset} = gltfData.buffers[bufferView.buffer];
|
|
184
|
+
// Resulting byteOffset is sum of the buffer, accessor and bufferView byte offsets
|
|
185
|
+
const byteOffset =
|
|
186
|
+
(bufferByteOffset || 0) + (accessor.byteOffset || 0) + (bufferView.byteOffset || 0);
|
|
187
|
+
// Deduce TypedArray type and its length from `accessor` and `bufferView` data
|
|
188
|
+
const {ArrayType, length} = getAccessorArrayTypeAndLength(accessor, bufferView);
|
|
189
|
+
// Number of bytes each component occupies
|
|
190
|
+
const bytes = BYTES[accessor.componentType];
|
|
191
|
+
// Number of components. For the `TEXCOORD_0` with `VEC2` type, it must return 2
|
|
192
|
+
const components = COMPONENTS[accessor.type];
|
|
193
|
+
// Multiplier to calculate the address of the `TEXCOORD_0` element in the arrayBuffer
|
|
194
|
+
const elementAddressScale = bufferView.byteStride || bytes * components;
|
|
195
|
+
// Data transform to Float32Array
|
|
196
|
+
const result = new Float32Array(length);
|
|
197
|
+
for (let i = 0; i < accessor.count; i++) {
|
|
198
|
+
// Take [u, v] couple from the arrayBuffer
|
|
199
|
+
const uv = new ArrayType(arrayBuffer, byteOffset + i * elementAddressScale, 2);
|
|
200
|
+
// Set and transform Vector3 per https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#overview
|
|
201
|
+
scratchVector.set(uv[0], uv[1], 1);
|
|
202
|
+
scratchVector.transformByMatrix3(matrix);
|
|
203
|
+
// Save result in Float32Array
|
|
204
|
+
result.set([scratchVector[0], scratchVector[1]], i * components);
|
|
205
|
+
}
|
|
206
|
+
// If texCoord the same, replace gltf structural data
|
|
207
|
+
if (originalTexCoord === texCoord) {
|
|
208
|
+
updateGltf(accessor, bufferView, gltfData.buffers, result);
|
|
209
|
+
} else {
|
|
210
|
+
// If texCoord change, create new attribute
|
|
211
|
+
createAttribute(texCoord, accessor, primitive, gltfData, result);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Update GLTF structural objects with new data as we create new `Float32Array` for `TEXCOORD_0`.
|
|
220
|
+
* @param accessor accessor to change
|
|
221
|
+
* @param bufferView bufferView to change
|
|
222
|
+
* @param buffers binary buffers
|
|
223
|
+
* @param newTexcoordArray typed array with data after transformation
|
|
224
|
+
*/
|
|
225
|
+
function updateGltf(
|
|
226
|
+
accessor: GLTFAccessor,
|
|
227
|
+
bufferView: GLTFBufferView,
|
|
228
|
+
buffers: {arrayBuffer: ArrayBuffer; byteOffset: number; byteLength: number}[],
|
|
229
|
+
newTexCoordArray: Float32Array
|
|
230
|
+
): void {
|
|
231
|
+
accessor.componentType = 5126;
|
|
232
|
+
buffers.push({
|
|
233
|
+
arrayBuffer: newTexCoordArray.buffer,
|
|
234
|
+
byteOffset: 0,
|
|
235
|
+
byteLength: newTexCoordArray.buffer.byteLength
|
|
236
|
+
});
|
|
237
|
+
bufferView.buffer = buffers.length - 1;
|
|
238
|
+
bufferView.byteLength = newTexCoordArray.buffer.byteLength;
|
|
239
|
+
bufferView.byteOffset = 0;
|
|
240
|
+
delete bufferView.byteStride;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
*
|
|
245
|
+
* @param newTexCoord new `texCoord` value
|
|
246
|
+
* @param originalAccessor original accessor object, that store data before transformation
|
|
247
|
+
* @param primitive primitive object
|
|
248
|
+
* @param gltfData gltf data
|
|
249
|
+
* @param newTexCoordArray typed array with data after transformation
|
|
250
|
+
* @returns
|
|
251
|
+
*/
|
|
252
|
+
function createAttribute(
|
|
253
|
+
newTexCoord: number,
|
|
254
|
+
originalAccessor: GLTFAccessor,
|
|
255
|
+
primitive: GLTFMeshPrimitive,
|
|
256
|
+
gltfData: GLTFWithBuffers,
|
|
257
|
+
newTexCoordArray: Float32Array
|
|
258
|
+
) {
|
|
259
|
+
gltfData.buffers.push({
|
|
260
|
+
arrayBuffer: newTexCoordArray.buffer,
|
|
261
|
+
byteOffset: 0,
|
|
262
|
+
byteLength: newTexCoordArray.buffer.byteLength
|
|
263
|
+
});
|
|
264
|
+
const bufferViews = gltfData.json.bufferViews;
|
|
265
|
+
if (!bufferViews) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
bufferViews.push({
|
|
269
|
+
buffer: gltfData.buffers.length - 1,
|
|
270
|
+
byteLength: newTexCoordArray.buffer.byteLength,
|
|
271
|
+
byteOffset: 0
|
|
272
|
+
});
|
|
273
|
+
const accessors = gltfData.json.accessors;
|
|
274
|
+
if (!accessors) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
accessors.push({
|
|
278
|
+
bufferView: bufferViews?.length - 1,
|
|
279
|
+
byteOffset: 0,
|
|
280
|
+
componentType: 5126,
|
|
281
|
+
count: originalAccessor.count,
|
|
282
|
+
type: 'VEC2'
|
|
283
|
+
});
|
|
284
|
+
primitive.attributes[`TEXCOORD_${newTexCoord}`] = accessors.length - 1;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Construct transformation matrix from the extension data (transition, rotation, scale)
|
|
289
|
+
* @param extensionData extension data
|
|
290
|
+
* @returns transformation matrix
|
|
291
|
+
*/
|
|
292
|
+
function makeTransformationMatrix(extensionData: TextureInfo): Matrix3 {
|
|
293
|
+
const {offset = [0, 0], rotation = 0, scale = [1, 1]} = extensionData;
|
|
294
|
+
const translationMatrix = new Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1);
|
|
295
|
+
const rotationMatrix = scratchRotationMatrix.set(
|
|
296
|
+
Math.cos(rotation),
|
|
297
|
+
Math.sin(rotation),
|
|
298
|
+
0,
|
|
299
|
+
-Math.sin(rotation),
|
|
300
|
+
Math.cos(rotation),
|
|
301
|
+
0,
|
|
302
|
+
0,
|
|
303
|
+
0,
|
|
304
|
+
1
|
|
305
|
+
);
|
|
306
|
+
const scaleMatrix = scratchScaleMatrix.set(scale[0], 0, 0, 0, scale[1], 0, 0, 0, 1);
|
|
307
|
+
return translationMatrix.multiplyRight(rotationMatrix).multiplyRight(scaleMatrix);
|
|
308
|
+
}
|