@loaders.gl/gltf 4.0.0-alpha.5 → 4.0.0-alpha.6
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 +2037 -1013
- 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 +35 -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 +49 -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 +578 -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 +422 -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 +21 -0
- package/dist/es5/lib/encoders/encode-gltf.js.map +1 -0
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js +96 -0
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -0
- package/dist/es5/lib/extensions/EXT_texture_webp.js +44 -0
- package/dist/es5/lib/extensions/EXT_texture_webp.js.map +1 -0
- package/dist/es5/lib/extensions/KHR_binary_gltf.js +40 -0
- package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +1 -0
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +246 -0
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -0
- package/dist/es5/lib/extensions/KHR_texture_basisu.js +37 -0
- package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -0
- package/dist/es5/lib/extensions/KHR_texture_transform.js +229 -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 +62 -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 +287 -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 +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 +441 -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 +341 -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 +42 -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 +110 -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 +181 -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 +54 -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 +156 -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 +3 -2
- package/dist/glb-loader.d.ts.map +1 -1
- package/dist/glb-loader.js +33 -28
- package/dist/glb-writer.d.ts +7 -16
- package/dist/glb-writer.d.ts.map +1 -1
- package/dist/glb-writer.js +34 -26
- package/dist/gltf-loader.d.ts +3 -2
- 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 +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -7
- package/dist/lib/api/gltf-extensions.d.ts +6 -1
- 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 +5 -11
- package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
- package/dist/lib/api/gltf-scenegraph.js +563 -512
- 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.js +324 -376
- package/dist/lib/encoders/encode-glb.d.ts +2 -1
- package/dist/lib/encoders/encode-glb.d.ts.map +1 -1
- package/dist/lib/encoders/encode-glb.js +56 -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 +33 -12
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts +0 -3
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_meshopt_compression.js +39 -50
- package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_texture_webp.js +35 -28
- package/dist/lib/extensions/KHR_binary_gltf.js +39 -23
- package/dist/lib/extensions/KHR_draco_mesh_compression.js +126 -111
- package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_basisu.js +29 -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 +230 -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 +118 -0
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +57 -44
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +42 -32
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +76 -62
- package/dist/lib/gltf-utils/get-typed-array.js +39 -14
- 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.js +52 -45
- package/dist/lib/gltf-utils/resolve-url.js +17 -15
- package/dist/lib/parsers/parse-glb.d.ts +1 -1
- package/dist/lib/parsers/parse-glb.d.ts.map +1 -1
- package/dist/lib/parsers/parse-glb.js +120 -107
- package/dist/lib/parsers/parse-gltf.d.ts +2 -2
- package/dist/lib/parsers/parse-gltf.d.ts.map +1 -1
- package/dist/lib/parsers/parse-gltf.js +187 -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 +396 -11
- 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 +10 -10
- 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 +8 -5
- 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 +1 -1
- package/src/glb-writer.ts +9 -3
- package/src/gltf-writer.ts +2 -2
- package/src/index.ts +10 -1
- package/src/lib/api/gltf-extensions.ts +13 -2
- package/src/lib/api/gltf-scenegraph.ts +21 -12
- package/src/lib/api/normalize-gltf-v1.ts +2 -1
- package/src/lib/encoders/encode-glb.ts +8 -1
- package/src/lib/encoders/encode-gltf.ts +18 -9
- package/src/lib/extensions/EXT_meshopt_compression.ts +12 -19
- package/src/lib/extensions/EXT_texture_webp.ts +3 -2
- package/src/lib/extensions/KHR_binary_gltf.ts +1 -1
- package/src/lib/extensions/KHR_draco_mesh_compression.ts +1 -1
- package/src/lib/extensions/KHR_texture_basisu.ts +1 -0
- package/src/lib/extensions/KHR_texture_transform.ts +305 -0
- package/src/lib/extensions/deprecated/EXT_feature_metadata.ts +163 -0
- package/src/lib/extensions/deprecated/KHR_materials_unlit.ts +3 -3
- package/src/lib/extensions/deprecated/KHR_techniques_webgl.ts +1 -0
- package/src/lib/gltf-utils/gltf-constants.ts +2 -2
- package/src/lib/parsers/parse-gltf.ts +10 -1
- package/src/lib/types/glb-types.ts +1 -1
- package/src/lib/types/gltf-json-schema.ts +434 -5
- package/src/lib/types/gltf-postprocessed-schema.ts +9 -9
- package/src/lib/types/gltf-types.ts +24 -3
- 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,126 +1,141 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression
|
|
3
|
+
// Only TRIANGLES: 0x0004 and TRIANGLE_STRIP: 0x0005 are supported
|
|
4
|
+
/* eslint-disable camelcase */
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.encode = exports.decode = exports.preprocess = exports.name = void 0;
|
|
10
|
+
const draco_1 = require("@loaders.gl/draco");
|
|
11
|
+
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
12
|
+
const gltf_scenegraph_1 = __importDefault(require("../api/gltf-scenegraph"));
|
|
13
|
+
const gltf_attribute_utils_1 = require("../gltf-utils/gltf-attribute-utils");
|
|
5
14
|
const KHR_DRACO_MESH_COMPRESSION = 'KHR_draco_mesh_compression';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
/** Extension name */
|
|
16
|
+
exports.name = KHR_DRACO_MESH_COMPRESSION;
|
|
17
|
+
function preprocess(gltfData, options, context) {
|
|
18
|
+
const scenegraph = new gltf_scenegraph_1.default(gltfData);
|
|
19
|
+
for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {
|
|
20
|
+
if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {
|
|
21
|
+
// TODO - Remove fallback accessors to make sure we don't load unnecessary buffers
|
|
22
|
+
}
|
|
23
|
+
}
|
|
13
24
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {
|
|
26
|
-
promises.push(decompressPrimitive(scenegraph, primitive, options, context));
|
|
25
|
+
exports.preprocess = preprocess;
|
|
26
|
+
async function decode(gltfData, options, context) {
|
|
27
|
+
if (!options?.gltf?.decompressMeshes) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const scenegraph = new gltf_scenegraph_1.default(gltfData);
|
|
31
|
+
const promises = [];
|
|
32
|
+
for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {
|
|
33
|
+
if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {
|
|
34
|
+
promises.push(decompressPrimitive(scenegraph, primitive, options, context));
|
|
35
|
+
}
|
|
27
36
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
// Decompress meshes in parallel
|
|
38
|
+
await Promise.all(promises);
|
|
39
|
+
// We have now decompressed all primitives, so remove the top-level extension
|
|
40
|
+
scenegraph.removeExtension(KHR_DRACO_MESH_COMPRESSION);
|
|
32
41
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
exports.decode = decode;
|
|
43
|
+
function encode(gltfData, options = {}) {
|
|
44
|
+
const scenegraph = new gltf_scenegraph_1.default(gltfData);
|
|
45
|
+
for (const mesh of scenegraph.json.meshes || []) {
|
|
46
|
+
// eslint-disable-next-line camelcase
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
compressMesh(mesh, options);
|
|
49
|
+
// NOTE: Only add the extension if something was actually compressed
|
|
50
|
+
scenegraph.addRequiredExtension(KHR_DRACO_MESH_COMPRESSION);
|
|
51
|
+
}
|
|
40
52
|
}
|
|
41
|
-
|
|
53
|
+
exports.encode = encode;
|
|
54
|
+
// DECODE
|
|
55
|
+
// Unpacks one mesh primitive and removes the extension from the primitive
|
|
56
|
+
// DracoDecoder needs to be imported and registered by app
|
|
57
|
+
// Returns: Promise that resolves when all pending draco decoder jobs for this mesh complete
|
|
58
|
+
// TODO - Implement fallback behavior per KHR_DRACO_MESH_COMPRESSION spec
|
|
42
59
|
async function decompressPrimitive(scenegraph, primitive, options, context) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
60
|
+
const dracoExtension = scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION);
|
|
61
|
+
if (!dracoExtension) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const buffer = scenegraph.getTypedArrayForBufferView(dracoExtension.bufferView);
|
|
65
|
+
// TODO - parse does not yet deal well with byte offsets embedded in typed arrays. Copy buffer
|
|
66
|
+
// TODO - remove when `parse` is fixed to handle `byteOffset`s
|
|
67
|
+
const bufferCopy = (0, loader_utils_1.sliceArrayBuffer)(buffer.buffer, buffer.byteOffset); // , buffer.byteLength);
|
|
68
|
+
const { parse } = context;
|
|
69
|
+
const dracoOptions = { ...options };
|
|
70
|
+
// TODO - remove hack: The entire tileset might be included, too expensive to serialize
|
|
71
|
+
delete dracoOptions['3d-tiles'];
|
|
72
|
+
const decodedData = (await parse(bufferCopy, draco_1.DracoLoader, dracoOptions, context));
|
|
73
|
+
const decodedAttributes = (0, gltf_attribute_utils_1.getGLTFAccessors)(decodedData.attributes);
|
|
74
|
+
// Restore min/max values
|
|
75
|
+
for (const [attributeName, decodedAttribute] of Object.entries(decodedAttributes)) {
|
|
76
|
+
if (attributeName in primitive.attributes) {
|
|
77
|
+
const accessorIndex = primitive.attributes[attributeName];
|
|
78
|
+
const accessor = scenegraph.getAccessor(accessorIndex);
|
|
79
|
+
if (accessor?.min && accessor?.max) {
|
|
80
|
+
decodedAttribute.min = accessor.min;
|
|
81
|
+
decodedAttribute.max = accessor.max;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
primitive.attributes = decodedAttributes;
|
|
87
|
+
if (decodedData.indices) {
|
|
88
|
+
// @ts-ignore
|
|
89
|
+
primitive.indices = (0, gltf_attribute_utils_1.getGLTFAccessor)(decodedData.indices);
|
|
69
90
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (decodedData.indices) {
|
|
75
|
-
primitive.indices = getGLTFAccessor(decodedData.indices);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
checkPrimitive(primitive);
|
|
91
|
+
// Extension has been processed, delete it
|
|
92
|
+
// delete primitive.extensions[KHR_DRACO_MESH_COMPRESSION];
|
|
93
|
+
checkPrimitive(primitive);
|
|
79
94
|
}
|
|
80
|
-
|
|
95
|
+
// ENCODE
|
|
96
|
+
// eslint-disable-next-line max-len
|
|
97
|
+
// Only TRIANGLES: 0x0004 and TRIANGLE_STRIP: 0x0005 are supported
|
|
81
98
|
function compressMesh(attributes, indices, mode = 4, options, context) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
99
|
+
if (!options.DracoWriter) {
|
|
100
|
+
throw new Error('options.gltf.DracoWriter not provided');
|
|
101
|
+
}
|
|
102
|
+
// TODO - use DracoWriter using encode w/ registered DracoWriter...
|
|
103
|
+
const compressedData = options.DracoWriter.encodeSync({ attributes });
|
|
104
|
+
// Draco compression may change the order and number of vertices in a mesh.
|
|
105
|
+
// To satisfy the requirement that accessors properties be correct for both
|
|
106
|
+
// compressed and uncompressed data, generators should create uncompressed
|
|
107
|
+
// attributes and indices using data that has been decompressed from the Draco buffer,
|
|
108
|
+
// rather than the original source data.
|
|
109
|
+
// @ts-ignore TODO this needs to be fixed
|
|
110
|
+
const decodedData = context?.parseSync?.({ attributes });
|
|
111
|
+
const fauxAccessors = options._addFauxAttributes(decodedData.attributes);
|
|
112
|
+
const bufferViewIndex = options.addBufferView(compressedData);
|
|
113
|
+
const glTFMesh = {
|
|
114
|
+
primitives: [
|
|
115
|
+
{
|
|
116
|
+
attributes: fauxAccessors,
|
|
117
|
+
mode,
|
|
118
|
+
extensions: {
|
|
119
|
+
[KHR_DRACO_MESH_COMPRESSION]: {
|
|
120
|
+
bufferView: bufferViewIndex,
|
|
121
|
+
attributes: fauxAccessors // TODO - verify with spec
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
]
|
|
126
|
+
};
|
|
127
|
+
return glTFMesh;
|
|
111
128
|
}
|
|
112
|
-
|
|
129
|
+
// UTILS
|
|
113
130
|
function checkPrimitive(primitive) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
131
|
+
if (!primitive.attributes && Object.keys(primitive.attributes).length > 0) {
|
|
132
|
+
throw new Error('glTF: Empty primitive detected: Draco decompression failure?');
|
|
133
|
+
}
|
|
117
134
|
}
|
|
118
|
-
|
|
119
135
|
function* makeMeshPrimitiveIterator(scenegraph) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
136
|
+
for (const mesh of scenegraph.json.meshes || []) {
|
|
137
|
+
for (const primitive of mesh.primitives) {
|
|
138
|
+
yield primitive;
|
|
139
|
+
}
|
|
123
140
|
}
|
|
124
|
-
}
|
|
125
141
|
}
|
|
126
|
-
//# sourceMappingURL=KHR_draco_mesh_compression.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_texture_basisu.d.ts","sourceRoot":"","sources":["../../../src/lib/extensions/KHR_texture_basisu.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,IAAI,EAA0B,MAAM,qBAAqB,CAAC;AACvE,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAMzD,qBAAqB;AACrB,eAAO,MAAM,IAAI,uBAAqB,CAAC;AAEvC;;;GAGG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"KHR_texture_basisu.d.ts","sourceRoot":"","sources":["../../../src/lib/extensions/KHR_texture_basisu.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,IAAI,EAA0B,MAAM,qBAAqB,CAAC;AACvE,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAMzD,qBAAqB;AACrB,eAAO,MAAM,IAAI,uBAAqB,CAAC;AAEvC;;;GAGG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAkBnF"}
|
|
@@ -1,22 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// GLTF EXTENSION: KHR_texture_basisu
|
|
3
|
+
// https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_basisu
|
|
4
|
+
/* eslint-disable camelcase */
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.preprocess = exports.name = void 0;
|
|
10
|
+
const gltf_scenegraph_1 = __importDefault(require("../api/gltf-scenegraph"));
|
|
2
11
|
const KHR_TEXTURE_BASISU = 'KHR_texture_basisu';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
/** Extension name */
|
|
13
|
+
exports.name = KHR_TEXTURE_BASISU;
|
|
14
|
+
/**
|
|
15
|
+
* Replaces a texture source reference with the extension texture
|
|
16
|
+
* Done in preprocess() to prevent load of default image
|
|
17
|
+
*/
|
|
18
|
+
function preprocess(gltfData, options) {
|
|
19
|
+
const scene = new gltf_scenegraph_1.default(gltfData);
|
|
20
|
+
const { json } = scene;
|
|
21
|
+
for (const texture of json.textures || []) {
|
|
22
|
+
const extension = scene.getObjectExtension(texture, KHR_TEXTURE_BASISU);
|
|
23
|
+
if (extension) {
|
|
24
|
+
// TODO - if multiple texture extensions are present which one wins?
|
|
25
|
+
texture.source = extension.source;
|
|
26
|
+
}
|
|
27
|
+
scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);
|
|
15
28
|
}
|
|
16
|
-
|
|
17
|
-
scene.
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
scene.removeExtension(KHR_TEXTURE_BASISU);
|
|
29
|
+
// Remove the top-level extension
|
|
30
|
+
scene.removeExtension(KHR_TEXTURE_BASISU);
|
|
21
31
|
}
|
|
22
|
-
|
|
32
|
+
exports.preprocess = preprocess;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_transform/README.md
|
|
3
|
+
*/
|
|
4
|
+
import type { GLTFWithBuffers } from '../types/gltf-types';
|
|
5
|
+
import type { GLTFLoaderOptions } from '../../gltf-loader';
|
|
6
|
+
export declare const name = "KHR_texture_transform";
|
|
7
|
+
/**
|
|
8
|
+
* The extension entry to process the transformation
|
|
9
|
+
* @param gltfData gltf buffers and json
|
|
10
|
+
* @param options GLTFLoader options
|
|
11
|
+
*/
|
|
12
|
+
export declare function decode(gltfData: GLTFWithBuffers, options: GLTFLoaderOptions): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=KHR_texture_transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KHR_texture_transform.d.ts","sourceRoot":"","sources":["../../../src/lib/extensions/KHR_texture_transform.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAoB,eAAe,EAAC,MAAM,qBAAqB,CAAC;AAC5E,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAezD,eAAO,MAAM,IAAI,0BAAwB,CAAC;AA+B1C;;;;GAIG;AACH,wBAAsB,MAAM,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,iBAAiB,iBAUjF"}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_transform/README.md
|
|
4
|
+
*/
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.decode = exports.name = void 0;
|
|
10
|
+
const core_1 = require("@math.gl/core");
|
|
11
|
+
const gltf_utils_1 = require("../gltf-utils/gltf-utils");
|
|
12
|
+
const gltf_constants_1 = require("../gltf-utils/gltf-constants");
|
|
13
|
+
const gltf_scenegraph_1 = __importDefault(require("../api/gltf-scenegraph"));
|
|
14
|
+
/** Extension name */
|
|
15
|
+
const EXT_MESHOPT_TRANSFORM = 'KHR_texture_transform';
|
|
16
|
+
exports.name = EXT_MESHOPT_TRANSFORM;
|
|
17
|
+
const scratchVector = new core_1.Vector3();
|
|
18
|
+
const scratchRotationMatrix = new core_1.Matrix3();
|
|
19
|
+
const scratchScaleMatrix = new core_1.Matrix3();
|
|
20
|
+
/**
|
|
21
|
+
* The extension entry to process the transformation
|
|
22
|
+
* @param gltfData gltf buffers and json
|
|
23
|
+
* @param options GLTFLoader options
|
|
24
|
+
*/
|
|
25
|
+
async function decode(gltfData, options) {
|
|
26
|
+
const gltfScenegraph = new gltf_scenegraph_1.default(gltfData);
|
|
27
|
+
const extension = gltfScenegraph.getExtension(EXT_MESHOPT_TRANSFORM);
|
|
28
|
+
if (!extension) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const materials = gltfData.json.materials || [];
|
|
32
|
+
for (let i = 0; i < materials.length; i++) {
|
|
33
|
+
transformTexCoords(i, gltfData);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.decode = decode;
|
|
37
|
+
/**
|
|
38
|
+
* Transform TEXCOORD by material
|
|
39
|
+
* @param materialIndex processing material index
|
|
40
|
+
* @param gltfData gltf buffers and json
|
|
41
|
+
*/
|
|
42
|
+
function transformTexCoords(materialIndex, gltfData) {
|
|
43
|
+
// Save processed texCoords in order no to process the same twice
|
|
44
|
+
const processedTexCoords = [];
|
|
45
|
+
const material = gltfData.json.materials?.[materialIndex];
|
|
46
|
+
const baseColorTexture = material?.pbrMetallicRoughness?.baseColorTexture;
|
|
47
|
+
if (baseColorTexture) {
|
|
48
|
+
transformPrimitives(gltfData, materialIndex, baseColorTexture, processedTexCoords);
|
|
49
|
+
}
|
|
50
|
+
const emisiveTexture = material?.emissiveTexture;
|
|
51
|
+
if (emisiveTexture) {
|
|
52
|
+
transformPrimitives(gltfData, materialIndex, emisiveTexture, processedTexCoords);
|
|
53
|
+
}
|
|
54
|
+
const normalTexture = material?.normalTexture;
|
|
55
|
+
if (normalTexture) {
|
|
56
|
+
transformPrimitives(gltfData, materialIndex, normalTexture, processedTexCoords);
|
|
57
|
+
}
|
|
58
|
+
const occlusionTexture = material?.occlusionTexture;
|
|
59
|
+
if (occlusionTexture) {
|
|
60
|
+
transformPrimitives(gltfData, materialIndex, occlusionTexture, processedTexCoords);
|
|
61
|
+
}
|
|
62
|
+
const metallicRoughnessTexture = material?.pbrMetallicRoughness?.metallicRoughnessTexture;
|
|
63
|
+
if (metallicRoughnessTexture) {
|
|
64
|
+
transformPrimitives(gltfData, materialIndex, metallicRoughnessTexture, processedTexCoords);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Transform primitives of the particular material
|
|
69
|
+
* @param gltfData gltf data
|
|
70
|
+
* @param materialIndex primitives with this material will be transformed
|
|
71
|
+
* @param texture texture object
|
|
72
|
+
* @param processedTexCoords storage to save already processed texCoords
|
|
73
|
+
*/
|
|
74
|
+
function transformPrimitives(gltfData, materialIndex, texture, processedTexCoords) {
|
|
75
|
+
const transformParameters = getTransformParameters(texture, processedTexCoords);
|
|
76
|
+
if (!transformParameters) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const meshes = gltfData.json.meshes || [];
|
|
80
|
+
for (const mesh of meshes) {
|
|
81
|
+
for (const primitive of mesh.primitives) {
|
|
82
|
+
const material = primitive.material;
|
|
83
|
+
if (Number.isFinite(material) && materialIndex === material) {
|
|
84
|
+
transformPrimitive(gltfData, primitive, transformParameters);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get parameters for TEXCOORD transformation
|
|
91
|
+
* @param texture texture object
|
|
92
|
+
* @param processedTexCoords storage to save already processed texCoords
|
|
93
|
+
* @returns texCoord couple and transformation matrix
|
|
94
|
+
*/
|
|
95
|
+
function getTransformParameters(texture, processedTexCoords) {
|
|
96
|
+
const textureInfo = texture.extensions?.[EXT_MESHOPT_TRANSFORM];
|
|
97
|
+
const { texCoord: originalTexCoord = 0 } = texture;
|
|
98
|
+
// If texCoord is not set in the extension, original attribute data will be replaced
|
|
99
|
+
const { texCoord = originalTexCoord } = textureInfo;
|
|
100
|
+
// Make sure that couple [originalTexCoord, extensionTexCoord] is not processed twice
|
|
101
|
+
const isProcessed = processedTexCoords.findIndex(([original, newTexCoord]) => original === originalTexCoord && newTexCoord === texCoord) !== -1;
|
|
102
|
+
if (!isProcessed) {
|
|
103
|
+
const matrix = makeTransformationMatrix(textureInfo);
|
|
104
|
+
if (originalTexCoord !== texCoord) {
|
|
105
|
+
texture.texCoord = texCoord;
|
|
106
|
+
}
|
|
107
|
+
processedTexCoords.push([originalTexCoord, texCoord]);
|
|
108
|
+
return { originalTexCoord, texCoord, matrix };
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Transform `TEXCOORD_0` attribute in the primitive
|
|
114
|
+
* @param gltfData gltf data
|
|
115
|
+
* @param primitive primitive object
|
|
116
|
+
* @param transformParameters texCoord couple and transformation matrix
|
|
117
|
+
*/
|
|
118
|
+
function transformPrimitive(gltfData, primitive, transformParameters) {
|
|
119
|
+
const { originalTexCoord, texCoord, matrix } = transformParameters;
|
|
120
|
+
const texCoordAccessor = primitive.attributes[`TEXCOORD_${originalTexCoord}`];
|
|
121
|
+
if (Number.isFinite(texCoordAccessor)) {
|
|
122
|
+
// Get accessor of the `TEXCOORD_0` attribute
|
|
123
|
+
const accessor = gltfData.json.accessors?.[texCoordAccessor];
|
|
124
|
+
if (accessor && accessor.bufferView) {
|
|
125
|
+
// Get `bufferView` of the `accessor`
|
|
126
|
+
const bufferView = gltfData.json.bufferViews?.[accessor.bufferView];
|
|
127
|
+
if (bufferView) {
|
|
128
|
+
// Get `arrayBuffer` the `bufferView` look at
|
|
129
|
+
const { arrayBuffer, byteOffset: bufferByteOffset } = gltfData.buffers[bufferView.buffer];
|
|
130
|
+
// Resulting byteOffset is sum of the buffer, accessor and bufferView byte offsets
|
|
131
|
+
const byteOffset = (bufferByteOffset || 0) + (accessor.byteOffset || 0) + (bufferView.byteOffset || 0);
|
|
132
|
+
// Deduce TypedArray type and its length from `accessor` and `bufferView` data
|
|
133
|
+
const { ArrayType, length } = (0, gltf_utils_1.getAccessorArrayTypeAndLength)(accessor, bufferView);
|
|
134
|
+
// Number of bytes each component occupies
|
|
135
|
+
const bytes = gltf_constants_1.BYTES[accessor.componentType];
|
|
136
|
+
// Number of components. For the `TEXCOORD_0` with `VEC2` type, it must return 2
|
|
137
|
+
const components = gltf_constants_1.COMPONENTS[accessor.type];
|
|
138
|
+
// Multiplier to calculate the address of the `TEXCOORD_0` element in the arrayBuffer
|
|
139
|
+
const elementAddressScale = bufferView.byteStride || bytes * components;
|
|
140
|
+
// Data transform to Float32Array
|
|
141
|
+
const result = new Float32Array(length);
|
|
142
|
+
for (let i = 0; i < accessor.count; i++) {
|
|
143
|
+
// Take [u, v] couple from the arrayBuffer
|
|
144
|
+
const uv = new ArrayType(arrayBuffer, byteOffset + i * elementAddressScale, 2);
|
|
145
|
+
// Set and transform Vector3 per https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#overview
|
|
146
|
+
scratchVector.set(uv[0], uv[1], 1);
|
|
147
|
+
scratchVector.transformByMatrix3(matrix);
|
|
148
|
+
// Save result in Float32Array
|
|
149
|
+
result.set([scratchVector[0], scratchVector[1]], i * components);
|
|
150
|
+
}
|
|
151
|
+
// If texCoord the same, replace gltf structural data
|
|
152
|
+
if (originalTexCoord === texCoord) {
|
|
153
|
+
updateGltf(accessor, bufferView, gltfData.buffers, result);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
// If texCoord change, create new attribute
|
|
157
|
+
createAttribute(texCoord, accessor, primitive, gltfData, result);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Update GLTF structural objects with new data as we create new `Float32Array` for `TEXCOORD_0`.
|
|
165
|
+
* @param accessor accessor to change
|
|
166
|
+
* @param bufferView bufferView to change
|
|
167
|
+
* @param buffers binary buffers
|
|
168
|
+
* @param newTexcoordArray typed array with data after transformation
|
|
169
|
+
*/
|
|
170
|
+
function updateGltf(accessor, bufferView, buffers, newTexCoordArray) {
|
|
171
|
+
accessor.componentType = 5126;
|
|
172
|
+
buffers.push({
|
|
173
|
+
arrayBuffer: newTexCoordArray.buffer,
|
|
174
|
+
byteOffset: 0,
|
|
175
|
+
byteLength: newTexCoordArray.buffer.byteLength
|
|
176
|
+
});
|
|
177
|
+
bufferView.buffer = buffers.length - 1;
|
|
178
|
+
bufferView.byteLength = newTexCoordArray.buffer.byteLength;
|
|
179
|
+
bufferView.byteOffset = 0;
|
|
180
|
+
delete bufferView.byteStride;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
*
|
|
184
|
+
* @param newTexCoord new `texCoord` value
|
|
185
|
+
* @param originalAccessor original accessor object, that store data before transformation
|
|
186
|
+
* @param primitive primitive object
|
|
187
|
+
* @param gltfData gltf data
|
|
188
|
+
* @param newTexCoordArray typed array with data after transformation
|
|
189
|
+
* @returns
|
|
190
|
+
*/
|
|
191
|
+
function createAttribute(newTexCoord, originalAccessor, primitive, gltfData, newTexCoordArray) {
|
|
192
|
+
gltfData.buffers.push({
|
|
193
|
+
arrayBuffer: newTexCoordArray.buffer,
|
|
194
|
+
byteOffset: 0,
|
|
195
|
+
byteLength: newTexCoordArray.buffer.byteLength
|
|
196
|
+
});
|
|
197
|
+
const bufferViews = gltfData.json.bufferViews;
|
|
198
|
+
if (!bufferViews) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
bufferViews.push({
|
|
202
|
+
buffer: gltfData.buffers.length - 1,
|
|
203
|
+
byteLength: newTexCoordArray.buffer.byteLength,
|
|
204
|
+
byteOffset: 0
|
|
205
|
+
});
|
|
206
|
+
const accessors = gltfData.json.accessors;
|
|
207
|
+
if (!accessors) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
accessors.push({
|
|
211
|
+
bufferView: bufferViews?.length - 1,
|
|
212
|
+
byteOffset: 0,
|
|
213
|
+
componentType: 5126,
|
|
214
|
+
count: originalAccessor.count,
|
|
215
|
+
type: 'VEC2'
|
|
216
|
+
});
|
|
217
|
+
primitive.attributes[`TEXCOORD_${newTexCoord}`] = accessors.length - 1;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Construct transformation matrix from the extension data (transition, rotation, scale)
|
|
221
|
+
* @param extensionData extension data
|
|
222
|
+
* @returns transformation matrix
|
|
223
|
+
*/
|
|
224
|
+
function makeTransformationMatrix(extensionData) {
|
|
225
|
+
const { offset = [0, 0], rotation = 0, scale = [1, 1] } = extensionData;
|
|
226
|
+
const translationMatirx = new core_1.Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1);
|
|
227
|
+
const rotationMatirx = scratchRotationMatrix.set(Math.cos(rotation), Math.sin(rotation), 0, -Math.sin(rotation), Math.cos(rotation), 0, 0, 0, 1);
|
|
228
|
+
const scaleMatrix = scratchScaleMatrix.set(scale[0], 0, 0, 0, scale[1], 0, 0, 0, 1);
|
|
229
|
+
return translationMatirx.multiplyRight(rotationMatirx).multiplyRight(scaleMatrix);
|
|
230
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EXT_feature_metadata.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/EXT_feature_metadata.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,wBAAwB,CAAC;AAcjD,eAAO,MAAM,IAAI,yBAAuB,CAAC;AAEzC,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAGlE"}
|