@loaders.gl/gltf 4.2.0-alpha.3 → 4.2.0-alpha.5

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 (148) hide show
  1. package/dist/dist.dev.js +1049 -517
  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 +95 -284
  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 +561 -438
  24. package/dist/lib/api/normalize-gltf-v1.js +250 -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 +375 -339
  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 +194 -154
  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 +12 -8
  106. package/dist/glb-loader.js.map +0 -1
  107. package/dist/glb-writer.js.map +0 -1
  108. package/dist/gltf-loader.js.map +0 -1
  109. package/dist/gltf-writer.js.map +0 -1
  110. package/dist/index.js.map +0 -1
  111. package/dist/lib/api/gltf-extensions.js.map +0 -1
  112. package/dist/lib/api/gltf-scenegraph.js.map +0 -1
  113. package/dist/lib/api/normalize-gltf-v1.js.map +0 -1
  114. package/dist/lib/api/post-process-gltf.js.map +0 -1
  115. package/dist/lib/encoders/encode-glb.js.map +0 -1
  116. package/dist/lib/encoders/encode-gltf.js.map +0 -1
  117. package/dist/lib/extensions/EXT_mesh_features.js.map +0 -1
  118. package/dist/lib/extensions/EXT_meshopt_compression.js.map +0 -1
  119. package/dist/lib/extensions/EXT_structural_metadata.js.map +0 -1
  120. package/dist/lib/extensions/EXT_texture_webp.js.map +0 -1
  121. package/dist/lib/extensions/KHR_binary_gltf.js.map +0 -1
  122. package/dist/lib/extensions/KHR_draco_mesh_compression.js.map +0 -1
  123. package/dist/lib/extensions/KHR_texture_basisu.js.map +0 -1
  124. package/dist/lib/extensions/KHR_texture_transform.js.map +0 -1
  125. package/dist/lib/extensions/deprecated/EXT_feature_metadata.js.map +0 -1
  126. package/dist/lib/extensions/deprecated/KHR_lights_punctual.js.map +0 -1
  127. package/dist/lib/extensions/deprecated/KHR_materials_unlit.js.map +0 -1
  128. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js.map +0 -1
  129. package/dist/lib/extensions/utils/3d-tiles-utils.js.map +0 -1
  130. package/dist/lib/gltf-utils/get-typed-array.js.map +0 -1
  131. package/dist/lib/gltf-utils/gltf-attribute-utils.js.map +0 -1
  132. package/dist/lib/gltf-utils/gltf-constants.js.map +0 -1
  133. package/dist/lib/gltf-utils/gltf-utils.js.map +0 -1
  134. package/dist/lib/gltf-utils/resolve-url.js.map +0 -1
  135. package/dist/lib/parsers/parse-glb.js.map +0 -1
  136. package/dist/lib/parsers/parse-gltf.js.map +0 -1
  137. package/dist/lib/types/glb-types.js.map +0 -1
  138. package/dist/lib/types/gltf-ext-feature-metadata-schema.js.map +0 -1
  139. package/dist/lib/types/gltf-ext-mesh-features-schema.js.map +0 -1
  140. package/dist/lib/types/gltf-ext-structural-metadata-schema.js.map +0 -1
  141. package/dist/lib/types/gltf-json-schema.js.map +0 -1
  142. package/dist/lib/types/gltf-postprocessed-schema.js.map +0 -1
  143. package/dist/lib/types/gltf-types.js.map +0 -1
  144. package/dist/lib/utils/assert.js.map +0 -1
  145. package/dist/lib/utils/version.js.map +0 -1
  146. package/dist/meshopt/meshopt-decoder.js.map +0 -1
  147. package/dist/meshopt/meshopt-encoder.ts.disabled +0 -409
  148. package/dist/webp/webp.js.map +0 -1
@@ -1,183 +1,223 @@
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";
8
+ /** Extension name */
6
9
  const EXT_MESHOPT_TRANSFORM = 'KHR_texture_transform';
7
10
  export const name = EXT_MESHOPT_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(EXT_MESHOPT_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
+ // Save processed texCoords in order no to process the same twice
37
+ const processedTexCoords = [];
38
+ const material = gltfData.json.materials?.[materialIndex];
39
+ const baseColorTexture = material?.pbrMetallicRoughness?.baseColorTexture;
40
+ if (baseColorTexture) {
41
+ transformPrimitives(gltfData, materialIndex, baseColorTexture, processedTexCoords);
42
+ }
43
+ const emisiveTexture = material?.emissiveTexture;
44
+ if (emisiveTexture) {
45
+ transformPrimitives(gltfData, materialIndex, emisiveTexture, processedTexCoords);
46
+ }
47
+ const normalTexture = material?.normalTexture;
48
+ if (normalTexture) {
49
+ transformPrimitives(gltfData, materialIndex, normalTexture, processedTexCoords);
50
+ }
51
+ const occlusionTexture = material?.occlusionTexture;
52
+ if (occlusionTexture) {
53
+ transformPrimitives(gltfData, materialIndex, occlusionTexture, processedTexCoords);
54
+ }
55
+ const metallicRoughnessTexture = material?.pbrMetallicRoughness?.metallicRoughnessTexture;
56
+ if (metallicRoughnessTexture) {
57
+ transformPrimitives(gltfData, materialIndex, metallicRoughnessTexture, processedTexCoords);
58
+ }
47
59
  }
60
+ /**
61
+ * Transform primitives of the particular material
62
+ * @param gltfData gltf data
63
+ * @param materialIndex primitives with this material will be transformed
64
+ * @param texture texture object
65
+ * @param processedTexCoords storage to save already processed texCoords
66
+ */
48
67
  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
- }
68
+ const transformParameters = getTransformParameters(texture, processedTexCoords);
69
+ if (!transformParameters) {
70
+ return;
71
+ }
72
+ const meshes = gltfData.json.meshes || [];
73
+ for (const mesh of meshes) {
74
+ for (const primitive of mesh.primitives) {
75
+ const material = primitive.material;
76
+ if (Number.isFinite(material) && materialIndex === material) {
77
+ transformPrimitive(gltfData, primitive, transformParameters);
78
+ }
79
+ }
60
80
  }
61
- }
62
81
  }
82
+ /**
83
+ * Get parameters for TEXCOORD transformation
84
+ * @param texture texture object
85
+ * @param processedTexCoords storage to save already processed texCoords
86
+ * @returns texCoord couple and transformation matrix
87
+ */
63
88
  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;
89
+ const textureInfo = texture.extensions?.[EXT_MESHOPT_TRANSFORM];
90
+ const { texCoord: originalTexCoord = 0 } = texture;
91
+ // If texCoord is not set in the extension, original attribute data will be replaced
92
+ const { texCoord = originalTexCoord } = textureInfo;
93
+ // Make sure that couple [originalTexCoord, extensionTexCoord] is not processed twice
94
+ const isProcessed = processedTexCoords.findIndex(([original, newTexCoord]) => original === originalTexCoord && newTexCoord === texCoord) !== -1;
95
+ if (!isProcessed) {
96
+ const matrix = makeTransformationMatrix(textureInfo);
97
+ if (originalTexCoord !== texCoord) {
98
+ texture.texCoord = texCoord;
99
+ }
100
+ processedTexCoords.push([originalTexCoord, texCoord]);
101
+ return { originalTexCoord, texCoord, matrix };
80
102
  }
81
- processedTexCoords.push([originalTexCoord, texCoord]);
82
- return {
83
- originalTexCoord,
84
- texCoord,
85
- matrix
86
- };
87
- }
88
- return null;
103
+ return null;
89
104
  }
105
+ /**
106
+ * Transform `TEXCOORD_0` attribute in the primitive
107
+ * @param gltfData gltf data
108
+ * @param primitive primitive object
109
+ * @param transformParameters texCoord couple and transformation matrix
110
+ */
90
111
  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);
112
+ const { originalTexCoord, texCoord, matrix } = transformParameters;
113
+ const texCoordAccessor = primitive.attributes[`TEXCOORD_${originalTexCoord}`];
114
+ if (Number.isFinite(texCoordAccessor)) {
115
+ // Get accessor of the `TEXCOORD_0` attribute
116
+ const accessor = gltfData.json.accessors?.[texCoordAccessor];
117
+ if (accessor && accessor.bufferView) {
118
+ // Get `bufferView` of the `accessor`
119
+ const bufferView = gltfData.json.bufferViews?.[accessor.bufferView];
120
+ if (bufferView) {
121
+ // Get `arrayBuffer` the `bufferView` look at
122
+ const { arrayBuffer, byteOffset: bufferByteOffset } = gltfData.buffers[bufferView.buffer];
123
+ // Resulting byteOffset is sum of the buffer, accessor and bufferView byte offsets
124
+ const byteOffset = (bufferByteOffset || 0) + (accessor.byteOffset || 0) + (bufferView.byteOffset || 0);
125
+ // Deduce TypedArray type and its length from `accessor` and `bufferView` data
126
+ const { ArrayType, length } = getAccessorArrayTypeAndLength(accessor, bufferView);
127
+ // Number of bytes each component occupies
128
+ const bytes = BYTES[accessor.componentType];
129
+ // Number of components. For the `TEXCOORD_0` with `VEC2` type, it must return 2
130
+ const components = COMPONENTS[accessor.type];
131
+ // Multiplier to calculate the address of the `TEXCOORD_0` element in the arrayBuffer
132
+ const elementAddressScale = bufferView.byteStride || bytes * components;
133
+ // Data transform to Float32Array
134
+ const result = new Float32Array(length);
135
+ for (let i = 0; i < accessor.count; i++) {
136
+ // Take [u, v] couple from the arrayBuffer
137
+ const uv = new ArrayType(arrayBuffer, byteOffset + i * elementAddressScale, 2);
138
+ // Set and transform Vector3 per https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#overview
139
+ scratchVector.set(uv[0], uv[1], 1);
140
+ scratchVector.transformByMatrix3(matrix);
141
+ // Save result in Float32Array
142
+ result.set([scratchVector[0], scratchVector[1]], i * components);
143
+ }
144
+ // If texCoord the same, replace gltf structural data
145
+ if (originalTexCoord === texCoord) {
146
+ updateGltf(accessor, bufferView, gltfData.buffers, result);
147
+ }
148
+ else {
149
+ // If texCoord change, create new attribute
150
+ createAttribute(texCoord, accessor, primitive, gltfData, result);
151
+ }
152
+ }
122
153
  }
123
- if (originalTexCoord === texCoord) {
124
- updateGltf(accessor, bufferView, gltfData.buffers, result);
125
- } else {
126
- createAttribute(texCoord, accessor, primitive, gltfData, result);
127
- }
128
- }
129
154
  }
130
- }
131
155
  }
156
+ /**
157
+ * Update GLTF structural objects with new data as we create new `Float32Array` for `TEXCOORD_0`.
158
+ * @param accessor accessor to change
159
+ * @param bufferView bufferView to change
160
+ * @param buffers binary buffers
161
+ * @param newTexcoordArray typed array with data after transformation
162
+ */
132
163
  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;
164
+ accessor.componentType = 5126;
165
+ buffers.push({
166
+ arrayBuffer: newTexCoordArray.buffer,
167
+ byteOffset: 0,
168
+ byteLength: newTexCoordArray.buffer.byteLength
169
+ });
170
+ bufferView.buffer = buffers.length - 1;
171
+ bufferView.byteLength = newTexCoordArray.buffer.byteLength;
172
+ bufferView.byteOffset = 0;
173
+ delete bufferView.byteStride;
143
174
  }
175
+ /**
176
+ *
177
+ * @param newTexCoord new `texCoord` value
178
+ * @param originalAccessor original accessor object, that store data before transformation
179
+ * @param primitive primitive object
180
+ * @param gltfData gltf data
181
+ * @param newTexCoordArray typed array with data after transformation
182
+ * @returns
183
+ */
144
184
  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;
185
+ gltfData.buffers.push({
186
+ arrayBuffer: newTexCoordArray.buffer,
187
+ byteOffset: 0,
188
+ byteLength: newTexCoordArray.buffer.byteLength
189
+ });
190
+ const bufferViews = gltfData.json.bufferViews;
191
+ if (!bufferViews) {
192
+ return;
193
+ }
194
+ bufferViews.push({
195
+ buffer: gltfData.buffers.length - 1,
196
+ byteLength: newTexCoordArray.buffer.byteLength,
197
+ byteOffset: 0
198
+ });
199
+ const accessors = gltfData.json.accessors;
200
+ if (!accessors) {
201
+ return;
202
+ }
203
+ accessors.push({
204
+ bufferView: bufferViews?.length - 1,
205
+ byteOffset: 0,
206
+ componentType: 5126,
207
+ count: originalAccessor.count,
208
+ type: 'VEC2'
209
+ });
210
+ primitive.attributes[`TEXCOORD_${newTexCoord}`] = accessors.length - 1;
171
211
  }
212
+ /**
213
+ * Construct transformation matrix from the extension data (transition, rotation, scale)
214
+ * @param extensionData extension data
215
+ * @returns transformation matrix
216
+ */
172
217
  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);
218
+ const { offset = [0, 0], rotation = 0, scale = [1, 1] } = extensionData;
219
+ const translationMatrix = new Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1);
220
+ const rotationMatrix = scratchRotationMatrix.set(Math.cos(rotation), Math.sin(rotation), 0, -Math.sin(rotation), Math.cos(rotation), 0, 0, 0, 1);
221
+ const scaleMatrix = scratchScaleMatrix.set(scale[0], 0, 0, 0, scale[1], 0, 0, 0, 1);
222
+ return translationMatrix.multiplyRight(rotationMatrix).multiplyRight(scaleMatrix);
182
223
  }
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"}