@loaders.gl/gltf 4.2.0-alpha.4 → 4.2.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.
Files changed (149) hide show
  1. package/dist/dist.dev.js +1056 -524
  2. package/dist/dist.min.js +9 -0
  3. package/dist/glb-loader.d.ts +2 -2
  4. package/dist/glb-loader.d.ts.map +1 -1
  5. package/dist/glb-loader.js +22 -21
  6. package/dist/glb-writer.d.ts +2 -2
  7. package/dist/glb-writer.d.ts.map +1 -1
  8. package/dist/glb-writer.js +27 -24
  9. package/dist/gltf-loader.d.ts +3 -3
  10. package/dist/gltf-loader.d.ts.map +1 -1
  11. package/dist/gltf-loader.js +31 -36
  12. package/dist/gltf-writer.js +24 -26
  13. package/dist/index.cjs +138 -330
  14. package/dist/index.cjs.map +7 -0
  15. package/dist/index.d.ts +17 -17
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +3 -1
  18. package/dist/lib/api/gltf-extensions.d.ts +2 -2
  19. package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
  20. package/dist/lib/api/gltf-extensions.js +45 -22
  21. package/dist/lib/api/gltf-scenegraph.d.ts +2 -2
  22. package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
  23. package/dist/lib/api/gltf-scenegraph.js +565 -438
  24. package/dist/lib/api/normalize-gltf-v1.js +249 -181
  25. package/dist/lib/api/post-process-gltf.d.ts +3 -3
  26. package/dist/lib/api/post-process-gltf.d.ts.map +1 -1
  27. package/dist/lib/api/post-process-gltf.js +378 -340
  28. package/dist/lib/encoders/encode-glb.js +62 -48
  29. package/dist/lib/encoders/encode-gltf.js +24 -10
  30. package/dist/lib/extensions/EXT_mesh_features.d.ts +2 -2
  31. package/dist/lib/extensions/EXT_mesh_features.d.ts.map +1 -1
  32. package/dist/lib/extensions/EXT_mesh_features.js +55 -33
  33. package/dist/lib/extensions/EXT_meshopt_compression.d.ts +2 -2
  34. package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -1
  35. package/dist/lib/extensions/EXT_meshopt_compression.js +27 -31
  36. package/dist/lib/extensions/EXT_structural_metadata.d.ts +2 -2
  37. package/dist/lib/extensions/EXT_structural_metadata.d.ts.map +1 -1
  38. package/dist/lib/extensions/EXT_structural_metadata.js +434 -230
  39. package/dist/lib/extensions/EXT_texture_webp.d.ts +2 -2
  40. package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -1
  41. package/dist/lib/extensions/EXT_texture_webp.js +24 -17
  42. package/dist/lib/extensions/KHR_binary_gltf.d.ts +1 -1
  43. package/dist/lib/extensions/KHR_binary_gltf.d.ts.map +1 -1
  44. package/dist/lib/extensions/KHR_binary_gltf.js +29 -15
  45. package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +2 -2
  46. package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -1
  47. package/dist/lib/extensions/KHR_draco_mesh_compression.js +110 -87
  48. package/dist/lib/extensions/KHR_texture_basisu.d.ts +2 -2
  49. package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -1
  50. package/dist/lib/extensions/KHR_texture_basisu.js +19 -12
  51. package/dist/lib/extensions/KHR_texture_transform.d.ts +2 -2
  52. package/dist/lib/extensions/KHR_texture_transform.d.ts.map +1 -1
  53. package/dist/lib/extensions/KHR_texture_transform.js +188 -156
  54. package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +2 -2
  55. package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
  56. package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +263 -143
  57. package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts +1 -1
  58. package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts.map +1 -1
  59. package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +44 -32
  60. package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts +1 -1
  61. package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts.map +1 -1
  62. package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +30 -24
  63. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts +1 -1
  64. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts.map +1 -1
  65. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +65 -52
  66. package/dist/lib/extensions/utils/3d-tiles-utils.d.ts +2 -2
  67. package/dist/lib/extensions/utils/3d-tiles-utils.d.ts.map +1 -1
  68. package/dist/lib/extensions/utils/3d-tiles-utils.js +298 -181
  69. package/dist/lib/gltf-utils/get-typed-array.d.ts +1 -1
  70. package/dist/lib/gltf-utils/get-typed-array.d.ts.map +1 -1
  71. package/dist/lib/gltf-utils/get-typed-array.js +54 -42
  72. package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts +1 -1
  73. package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts.map +1 -1
  74. package/dist/lib/gltf-utils/gltf-attribute-utils.js +58 -52
  75. package/dist/lib/gltf-utils/gltf-constants.js +27 -27
  76. package/dist/lib/gltf-utils/gltf-utils.d.ts +1 -1
  77. package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
  78. package/dist/lib/gltf-utils/gltf-utils.js +67 -60
  79. package/dist/lib/gltf-utils/resolve-url.js +12 -10
  80. package/dist/lib/parsers/parse-glb.d.ts +1 -1
  81. package/dist/lib/parsers/parse-glb.d.ts.map +1 -1
  82. package/dist/lib/parsers/parse-glb.js +132 -89
  83. package/dist/lib/parsers/parse-gltf.d.ts +3 -3
  84. package/dist/lib/parsers/parse-gltf.d.ts.map +1 -1
  85. package/dist/lib/parsers/parse-gltf.js +155 -126
  86. package/dist/lib/types/glb-types.js +0 -1
  87. package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts +1 -1
  88. package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts.map +1 -1
  89. package/dist/lib/types/gltf-ext-feature-metadata-schema.js +0 -1
  90. package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts +1 -1
  91. package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts.map +1 -1
  92. package/dist/lib/types/gltf-ext-mesh-features-schema.js +0 -1
  93. package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts +1 -1
  94. package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts.map +1 -1
  95. package/dist/lib/types/gltf-ext-structural-metadata-schema.js +0 -1
  96. package/dist/lib/types/gltf-json-schema.js +2 -1
  97. package/dist/lib/types/gltf-postprocessed-schema.js +2 -1
  98. package/dist/lib/types/gltf-types.d.ts +3 -3
  99. package/dist/lib/types/gltf-types.d.ts.map +1 -1
  100. package/dist/lib/types/gltf-types.js +1 -1
  101. package/dist/lib/utils/assert.js +6 -4
  102. package/dist/lib/utils/version.js +4 -2
  103. package/dist/meshopt/meshopt-decoder.js +86 -67
  104. package/dist/webp/webp.js +28 -19
  105. package/package.json +13 -8
  106. package/src/lib/extensions/KHR_texture_transform.ts +18 -24
  107. package/dist/glb-loader.js.map +0 -1
  108. package/dist/glb-writer.js.map +0 -1
  109. package/dist/gltf-loader.js.map +0 -1
  110. package/dist/gltf-writer.js.map +0 -1
  111. package/dist/index.js.map +0 -1
  112. package/dist/lib/api/gltf-extensions.js.map +0 -1
  113. package/dist/lib/api/gltf-scenegraph.js.map +0 -1
  114. package/dist/lib/api/normalize-gltf-v1.js.map +0 -1
  115. package/dist/lib/api/post-process-gltf.js.map +0 -1
  116. package/dist/lib/encoders/encode-glb.js.map +0 -1
  117. package/dist/lib/encoders/encode-gltf.js.map +0 -1
  118. package/dist/lib/extensions/EXT_mesh_features.js.map +0 -1
  119. package/dist/lib/extensions/EXT_meshopt_compression.js.map +0 -1
  120. package/dist/lib/extensions/EXT_structural_metadata.js.map +0 -1
  121. package/dist/lib/extensions/EXT_texture_webp.js.map +0 -1
  122. package/dist/lib/extensions/KHR_binary_gltf.js.map +0 -1
  123. package/dist/lib/extensions/KHR_draco_mesh_compression.js.map +0 -1
  124. package/dist/lib/extensions/KHR_texture_basisu.js.map +0 -1
  125. package/dist/lib/extensions/KHR_texture_transform.js.map +0 -1
  126. package/dist/lib/extensions/deprecated/EXT_feature_metadata.js.map +0 -1
  127. package/dist/lib/extensions/deprecated/KHR_lights_punctual.js.map +0 -1
  128. package/dist/lib/extensions/deprecated/KHR_materials_unlit.js.map +0 -1
  129. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js.map +0 -1
  130. package/dist/lib/extensions/utils/3d-tiles-utils.js.map +0 -1
  131. package/dist/lib/gltf-utils/get-typed-array.js.map +0 -1
  132. package/dist/lib/gltf-utils/gltf-attribute-utils.js.map +0 -1
  133. package/dist/lib/gltf-utils/gltf-constants.js.map +0 -1
  134. package/dist/lib/gltf-utils/gltf-utils.js.map +0 -1
  135. package/dist/lib/gltf-utils/resolve-url.js.map +0 -1
  136. package/dist/lib/parsers/parse-glb.js.map +0 -1
  137. package/dist/lib/parsers/parse-gltf.js.map +0 -1
  138. package/dist/lib/types/glb-types.js.map +0 -1
  139. package/dist/lib/types/gltf-ext-feature-metadata-schema.js.map +0 -1
  140. package/dist/lib/types/gltf-ext-mesh-features-schema.js.map +0 -1
  141. package/dist/lib/types/gltf-ext-structural-metadata-schema.js.map +0 -1
  142. package/dist/lib/types/gltf-json-schema.js.map +0 -1
  143. package/dist/lib/types/gltf-postprocessed-schema.js.map +0 -1
  144. package/dist/lib/types/gltf-types.js.map +0 -1
  145. package/dist/lib/utils/assert.js.map +0 -1
  146. package/dist/lib/utils/version.js.map +0 -1
  147. package/dist/meshopt/meshopt-decoder.js.map +0 -1
  148. package/dist/meshopt/meshopt-encoder.ts.disabled +0 -409
  149. package/dist/webp/webp.js.map +0 -1
@@ -1,183 +1,215 @@
1
+ /**
2
+ * https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_transform/README.md
3
+ */
1
4
  import { Vector3, Matrix3 } from '@math.gl/core';
2
5
  import { getAccessorArrayTypeAndLength } from "../gltf-utils/gltf-utils.js";
3
6
  import { BYTES, COMPONENTS } from "../gltf-utils/gltf-constants.js";
4
- import "../types/gltf-json-schema.js";
5
7
  import { GLTFScenegraph } from "../api/gltf-scenegraph.js";
6
- const EXT_MESHOPT_TRANSFORM = 'KHR_texture_transform';
7
- export const name = EXT_MESHOPT_TRANSFORM;
8
+ /** Extension name */
9
+ const KHR_TEXTURE_TRANSFORM = 'KHR_texture_transform';
10
+ export const name = KHR_TEXTURE_TRANSFORM;
8
11
  const scratchVector = new Vector3();
9
12
  const scratchRotationMatrix = new Matrix3();
10
13
  const scratchScaleMatrix = new Matrix3();
14
+ /**
15
+ * The extension entry to process the transformation
16
+ * @param gltfData gltf buffers and json
17
+ * @param options GLTFLoader options
18
+ */
11
19
  export async function decode(gltfData, options) {
12
- var _options$gltf;
13
- const gltfScenegraph = new GLTFScenegraph(gltfData);
14
- const hasExtension = gltfScenegraph.hasExtension(EXT_MESHOPT_TRANSFORM);
15
- if (!hasExtension || !((_options$gltf = options.gltf) !== null && _options$gltf !== void 0 && _options$gltf.loadBuffers)) {
16
- return;
17
- }
18
- const materials = gltfData.json.materials || [];
19
- for (let i = 0; i < materials.length; i++) {
20
- transformTexCoords(i, gltfData);
21
- }
20
+ const gltfScenegraph = new GLTFScenegraph(gltfData);
21
+ const hasExtension = gltfScenegraph.hasExtension(KHR_TEXTURE_TRANSFORM);
22
+ if (!hasExtension || !options.gltf?.loadBuffers) {
23
+ return;
24
+ }
25
+ const materials = gltfData.json.materials || [];
26
+ for (let i = 0; i < materials.length; i++) {
27
+ transformTexCoords(i, gltfData);
28
+ }
22
29
  }
30
+ /**
31
+ * Transform TEXCOORD by material
32
+ * @param materialIndex processing material index
33
+ * @param gltfData gltf buffers and json
34
+ */
23
35
  function transformTexCoords(materialIndex, gltfData) {
24
- var _gltfData$json$materi, _material$pbrMetallic, _material$pbrMetallic2;
25
- const processedTexCoords = [];
26
- const material = (_gltfData$json$materi = gltfData.json.materials) === null || _gltfData$json$materi === void 0 ? void 0 : _gltfData$json$materi[materialIndex];
27
- const baseColorTexture = material === null || material === void 0 ? void 0 : (_material$pbrMetallic = material.pbrMetallicRoughness) === null || _material$pbrMetallic === void 0 ? void 0 : _material$pbrMetallic.baseColorTexture;
28
- if (baseColorTexture) {
29
- transformPrimitives(gltfData, materialIndex, baseColorTexture, processedTexCoords);
30
- }
31
- const emisiveTexture = material === null || material === void 0 ? void 0 : material.emissiveTexture;
32
- if (emisiveTexture) {
33
- transformPrimitives(gltfData, materialIndex, emisiveTexture, processedTexCoords);
34
- }
35
- const normalTexture = material === null || material === void 0 ? void 0 : material.normalTexture;
36
- if (normalTexture) {
37
- transformPrimitives(gltfData, materialIndex, normalTexture, processedTexCoords);
38
- }
39
- const occlusionTexture = material === null || material === void 0 ? void 0 : material.occlusionTexture;
40
- if (occlusionTexture) {
41
- transformPrimitives(gltfData, materialIndex, occlusionTexture, processedTexCoords);
42
- }
43
- const metallicRoughnessTexture = material === null || material === void 0 ? void 0 : (_material$pbrMetallic2 = material.pbrMetallicRoughness) === null || _material$pbrMetallic2 === void 0 ? void 0 : _material$pbrMetallic2.metallicRoughnessTexture;
44
- if (metallicRoughnessTexture) {
45
- transformPrimitives(gltfData, materialIndex, metallicRoughnessTexture, processedTexCoords);
46
- }
36
+ const material = gltfData.json.materials?.[materialIndex];
37
+ const materialTextures = [
38
+ material?.pbrMetallicRoughness?.baseColorTexture,
39
+ material?.emissiveTexture,
40
+ material?.normalTexture,
41
+ material?.occlusionTexture,
42
+ material?.pbrMetallicRoughness?.metallicRoughnessTexture
43
+ ];
44
+ // Save processed texCoords in order no to process the same twice
45
+ const processedTexCoords = [];
46
+ for (const textureInfo of materialTextures) {
47
+ if (textureInfo && textureInfo?.extensions?.[KHR_TEXTURE_TRANSFORM]) {
48
+ transformPrimitives(gltfData, materialIndex, textureInfo, processedTexCoords);
49
+ }
50
+ }
47
51
  }
52
+ /**
53
+ * Transform primitives of the particular material
54
+ * @param gltfData gltf data
55
+ * @param materialIndex primitives with this material will be transformed
56
+ * @param texture texture object
57
+ * @param processedTexCoords storage to save already processed texCoords
58
+ */
48
59
  function transformPrimitives(gltfData, materialIndex, texture, processedTexCoords) {
49
- const transformParameters = getTransformParameters(texture, processedTexCoords);
50
- if (!transformParameters) {
51
- return;
52
- }
53
- const meshes = gltfData.json.meshes || [];
54
- for (const mesh of meshes) {
55
- for (const primitive of mesh.primitives) {
56
- const material = primitive.material;
57
- if (Number.isFinite(material) && materialIndex === material) {
58
- transformPrimitive(gltfData, primitive, transformParameters);
59
- }
60
+ const transformParameters = getTransformParameters(texture, processedTexCoords);
61
+ if (!transformParameters) {
62
+ return;
63
+ }
64
+ const meshes = gltfData.json.meshes || [];
65
+ for (const mesh of meshes) {
66
+ for (const primitive of mesh.primitives) {
67
+ const material = primitive.material;
68
+ if (Number.isFinite(material) && materialIndex === material) {
69
+ transformPrimitive(gltfData, primitive, transformParameters);
70
+ }
71
+ }
60
72
  }
61
- }
62
73
  }
74
+ /**
75
+ * Get parameters for TEXCOORD transformation
76
+ * @param texture texture object
77
+ * @param processedTexCoords storage to save already processed texCoords
78
+ * @returns texCoord couple and transformation matrix
79
+ */
63
80
  function getTransformParameters(texture, processedTexCoords) {
64
- var _texture$extensions;
65
- const textureInfo = (_texture$extensions = texture.extensions) === null || _texture$extensions === void 0 ? void 0 : _texture$extensions[EXT_MESHOPT_TRANSFORM];
66
- const {
67
- texCoord: originalTexCoord = 0
68
- } = texture;
69
- const {
70
- texCoord = originalTexCoord
71
- } = textureInfo;
72
- const isProcessed = processedTexCoords.findIndex(_ref => {
73
- let [original, newTexCoord] = _ref;
74
- return original === originalTexCoord && newTexCoord === texCoord;
75
- }) !== -1;
76
- if (!isProcessed) {
77
- const matrix = makeTransformationMatrix(textureInfo);
78
- if (originalTexCoord !== texCoord) {
79
- texture.texCoord = texCoord;
81
+ const textureInfo = texture.extensions?.[KHR_TEXTURE_TRANSFORM];
82
+ const { texCoord: originalTexCoord = 0 } = texture;
83
+ // If texCoord is not set in the extension, original attribute data will be replaced
84
+ const { texCoord = originalTexCoord } = textureInfo;
85
+ // Make sure that couple [originalTexCoord, extensionTexCoord] is not processed twice
86
+ const isProcessed = processedTexCoords.findIndex(([original, newTexCoord]) => original === originalTexCoord && newTexCoord === texCoord) !== -1;
87
+ if (!isProcessed) {
88
+ const matrix = makeTransformationMatrix(textureInfo);
89
+ if (originalTexCoord !== texCoord) {
90
+ texture.texCoord = texCoord;
91
+ }
92
+ processedTexCoords.push([originalTexCoord, texCoord]);
93
+ return { originalTexCoord, texCoord, matrix };
80
94
  }
81
- processedTexCoords.push([originalTexCoord, texCoord]);
82
- return {
83
- originalTexCoord,
84
- texCoord,
85
- matrix
86
- };
87
- }
88
- return null;
95
+ return null;
89
96
  }
97
+ /**
98
+ * Transform `TEXCOORD_0` attribute in the primitive
99
+ * @param gltfData gltf data
100
+ * @param primitive primitive object
101
+ * @param transformParameters texCoord couple and transformation matrix
102
+ */
90
103
  function transformPrimitive(gltfData, primitive, transformParameters) {
91
- const {
92
- originalTexCoord,
93
- texCoord,
94
- matrix
95
- } = transformParameters;
96
- const texCoordAccessor = primitive.attributes[`TEXCOORD_${originalTexCoord}`];
97
- if (Number.isFinite(texCoordAccessor)) {
98
- var _gltfData$json$access;
99
- const accessor = (_gltfData$json$access = gltfData.json.accessors) === null || _gltfData$json$access === void 0 ? void 0 : _gltfData$json$access[texCoordAccessor];
100
- if (accessor && accessor.bufferView) {
101
- var _gltfData$json$buffer;
102
- const bufferView = (_gltfData$json$buffer = gltfData.json.bufferViews) === null || _gltfData$json$buffer === void 0 ? void 0 : _gltfData$json$buffer[accessor.bufferView];
103
- if (bufferView) {
104
- const {
105
- arrayBuffer,
106
- byteOffset: bufferByteOffset
107
- } = gltfData.buffers[bufferView.buffer];
108
- const byteOffset = (bufferByteOffset || 0) + (accessor.byteOffset || 0) + (bufferView.byteOffset || 0);
109
- const {
110
- ArrayType,
111
- length
112
- } = getAccessorArrayTypeAndLength(accessor, bufferView);
113
- const bytes = BYTES[accessor.componentType];
114
- const components = COMPONENTS[accessor.type];
115
- const elementAddressScale = bufferView.byteStride || bytes * components;
116
- const result = new Float32Array(length);
117
- for (let i = 0; i < accessor.count; i++) {
118
- const uv = new ArrayType(arrayBuffer, byteOffset + i * elementAddressScale, 2);
119
- scratchVector.set(uv[0], uv[1], 1);
120
- scratchVector.transformByMatrix3(matrix);
121
- result.set([scratchVector[0], scratchVector[1]], i * components);
122
- }
123
- if (originalTexCoord === texCoord) {
124
- updateGltf(accessor, bufferView, gltfData.buffers, result);
125
- } else {
126
- createAttribute(texCoord, accessor, primitive, gltfData, result);
104
+ const { originalTexCoord, texCoord, matrix } = transformParameters;
105
+ const texCoordAccessor = primitive.attributes[`TEXCOORD_${originalTexCoord}`];
106
+ if (Number.isFinite(texCoordAccessor)) {
107
+ // Get accessor of the `TEXCOORD_0` attribute
108
+ const accessor = gltfData.json.accessors?.[texCoordAccessor];
109
+ if (accessor && accessor.bufferView) {
110
+ // Get `bufferView` of the `accessor`
111
+ const bufferView = gltfData.json.bufferViews?.[accessor.bufferView];
112
+ if (bufferView) {
113
+ // Get `arrayBuffer` the `bufferView` look at
114
+ const { arrayBuffer, byteOffset: bufferByteOffset } = gltfData.buffers[bufferView.buffer];
115
+ // Resulting byteOffset is sum of the buffer, accessor and bufferView byte offsets
116
+ const byteOffset = (bufferByteOffset || 0) + (accessor.byteOffset || 0) + (bufferView.byteOffset || 0);
117
+ // Deduce TypedArray type and its length from `accessor` and `bufferView` data
118
+ const { ArrayType, length } = getAccessorArrayTypeAndLength(accessor, bufferView);
119
+ // Number of bytes each component occupies
120
+ const bytes = BYTES[accessor.componentType];
121
+ // Number of components. For the `TEXCOORD_0` with `VEC2` type, it must return 2
122
+ const components = COMPONENTS[accessor.type];
123
+ // Multiplier to calculate the address of the `TEXCOORD_0` element in the arrayBuffer
124
+ const elementAddressScale = bufferView.byteStride || bytes * components;
125
+ // Data transform to Float32Array
126
+ const result = new Float32Array(length);
127
+ for (let i = 0; i < accessor.count; i++) {
128
+ // Take [u, v] couple from the arrayBuffer
129
+ const uv = new ArrayType(arrayBuffer, byteOffset + i * elementAddressScale, 2);
130
+ // Set and transform Vector3 per https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#overview
131
+ scratchVector.set(uv[0], uv[1], 1);
132
+ scratchVector.transformByMatrix3(matrix);
133
+ // Save result in Float32Array
134
+ result.set([scratchVector[0], scratchVector[1]], i * components);
135
+ }
136
+ // If texCoord the same, replace gltf structural data
137
+ if (originalTexCoord === texCoord) {
138
+ updateGltf(accessor, bufferView, gltfData.buffers, result);
139
+ }
140
+ else {
141
+ // If texCoord change, create new attribute
142
+ createAttribute(texCoord, accessor, primitive, gltfData, result);
143
+ }
144
+ }
127
145
  }
128
- }
129
146
  }
130
- }
131
147
  }
148
+ /**
149
+ * Update GLTF structural objects with new data as we create new `Float32Array` for `TEXCOORD_0`.
150
+ * @param accessor accessor to change
151
+ * @param bufferView bufferView to change
152
+ * @param buffers binary buffers
153
+ * @param newTexcoordArray typed array with data after transformation
154
+ */
132
155
  function updateGltf(accessor, bufferView, buffers, newTexCoordArray) {
133
- accessor.componentType = 5126;
134
- buffers.push({
135
- arrayBuffer: newTexCoordArray.buffer,
136
- byteOffset: 0,
137
- byteLength: newTexCoordArray.buffer.byteLength
138
- });
139
- bufferView.buffer = buffers.length - 1;
140
- bufferView.byteLength = newTexCoordArray.buffer.byteLength;
141
- bufferView.byteOffset = 0;
142
- delete bufferView.byteStride;
156
+ accessor.componentType = 5126;
157
+ buffers.push({
158
+ arrayBuffer: newTexCoordArray.buffer,
159
+ byteOffset: 0,
160
+ byteLength: newTexCoordArray.buffer.byteLength
161
+ });
162
+ bufferView.buffer = buffers.length - 1;
163
+ bufferView.byteLength = newTexCoordArray.buffer.byteLength;
164
+ bufferView.byteOffset = 0;
165
+ delete bufferView.byteStride;
143
166
  }
167
+ /**
168
+ *
169
+ * @param newTexCoord new `texCoord` value
170
+ * @param originalAccessor original accessor object, that store data before transformation
171
+ * @param primitive primitive object
172
+ * @param gltfData gltf data
173
+ * @param newTexCoordArray typed array with data after transformation
174
+ * @returns
175
+ */
144
176
  function createAttribute(newTexCoord, originalAccessor, primitive, gltfData, newTexCoordArray) {
145
- gltfData.buffers.push({
146
- arrayBuffer: newTexCoordArray.buffer,
147
- byteOffset: 0,
148
- byteLength: newTexCoordArray.buffer.byteLength
149
- });
150
- const bufferViews = gltfData.json.bufferViews;
151
- if (!bufferViews) {
152
- return;
153
- }
154
- bufferViews.push({
155
- buffer: gltfData.buffers.length - 1,
156
- byteLength: newTexCoordArray.buffer.byteLength,
157
- byteOffset: 0
158
- });
159
- const accessors = gltfData.json.accessors;
160
- if (!accessors) {
161
- return;
162
- }
163
- accessors.push({
164
- bufferView: (bufferViews === null || bufferViews === void 0 ? void 0 : bufferViews.length) - 1,
165
- byteOffset: 0,
166
- componentType: 5126,
167
- count: originalAccessor.count,
168
- type: 'VEC2'
169
- });
170
- primitive.attributes[`TEXCOORD_${newTexCoord}`] = accessors.length - 1;
177
+ gltfData.buffers.push({
178
+ arrayBuffer: newTexCoordArray.buffer,
179
+ byteOffset: 0,
180
+ byteLength: newTexCoordArray.buffer.byteLength
181
+ });
182
+ const bufferViews = gltfData.json.bufferViews;
183
+ if (!bufferViews) {
184
+ return;
185
+ }
186
+ bufferViews.push({
187
+ buffer: gltfData.buffers.length - 1,
188
+ byteLength: newTexCoordArray.buffer.byteLength,
189
+ byteOffset: 0
190
+ });
191
+ const accessors = gltfData.json.accessors;
192
+ if (!accessors) {
193
+ return;
194
+ }
195
+ accessors.push({
196
+ bufferView: bufferViews?.length - 1,
197
+ byteOffset: 0,
198
+ componentType: 5126,
199
+ count: originalAccessor.count,
200
+ type: 'VEC2'
201
+ });
202
+ primitive.attributes[`TEXCOORD_${newTexCoord}`] = accessors.length - 1;
171
203
  }
204
+ /**
205
+ * Construct transformation matrix from the extension data (transition, rotation, scale)
206
+ * @param extensionData extension data
207
+ * @returns transformation matrix
208
+ */
172
209
  function makeTransformationMatrix(extensionData) {
173
- const {
174
- offset = [0, 0],
175
- rotation = 0,
176
- scale = [1, 1]
177
- } = extensionData;
178
- const translationMatrix = new Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1);
179
- const rotationMatrix = scratchRotationMatrix.set(Math.cos(rotation), Math.sin(rotation), 0, -Math.sin(rotation), Math.cos(rotation), 0, 0, 0, 1);
180
- const scaleMatrix = scratchScaleMatrix.set(scale[0], 0, 0, 0, scale[1], 0, 0, 0, 1);
181
- return translationMatrix.multiplyRight(rotationMatrix).multiplyRight(scaleMatrix);
210
+ const { offset = [0, 0], rotation = 0, scale = [1, 1] } = extensionData;
211
+ const translationMatrix = new Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1);
212
+ const rotationMatrix = scratchRotationMatrix.set(Math.cos(rotation), Math.sin(rotation), 0, -Math.sin(rotation), Math.cos(rotation), 0, 0, 0, 1);
213
+ const scaleMatrix = scratchScaleMatrix.set(scale[0], 0, 0, 0, scale[1], 0, 0, 0, 1);
214
+ return translationMatrix.multiplyRight(rotationMatrix).multiplyRight(scaleMatrix);
182
215
  }
183
- //# sourceMappingURL=KHR_texture_transform.js.map
@@ -1,5 +1,5 @@
1
- import type { GLTF } from '../../types/gltf-json-schema';
2
- import { GLTFLoaderOptions } from '../../../gltf-loader';
1
+ import type { GLTF } from "../../types/gltf-json-schema.js";
2
+ import { GLTFLoaderOptions } from "../../../gltf-loader.js";
3
3
  export declare const name = "EXT_feature_metadata";
4
4
  export declare function decode(gltfData: {
5
5
  json: GLTF;
@@ -1 +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,EAA0B,MAAM,8BAA8B,CAAC;AAchF,OAAO,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAevD,eAAO,MAAM,IAAI,yBAA4B,CAAC;AAE9C,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAG9F"}
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,EAA0B,wCAAqC;AAchF,OAAO,EAAC,iBAAiB,EAAC,gCAA6B;AAevD,eAAO,MAAM,IAAI,yBAA4B,CAAC;AAE9C,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAG9F"}