@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.
- package/dist/dist.dev.js +1056 -524
- package/dist/dist.min.js +9 -0
- package/dist/glb-loader.d.ts +2 -2
- package/dist/glb-loader.d.ts.map +1 -1
- package/dist/glb-loader.js +22 -21
- package/dist/glb-writer.d.ts +2 -2
- package/dist/glb-writer.d.ts.map +1 -1
- package/dist/glb-writer.js +27 -24
- package/dist/gltf-loader.d.ts +3 -3
- package/dist/gltf-loader.d.ts.map +1 -1
- package/dist/gltf-loader.js +31 -36
- package/dist/gltf-writer.js +24 -26
- package/dist/index.cjs +138 -330
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +17 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/api/gltf-extensions.d.ts +2 -2
- package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
- package/dist/lib/api/gltf-extensions.js +45 -22
- package/dist/lib/api/gltf-scenegraph.d.ts +2 -2
- package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
- package/dist/lib/api/gltf-scenegraph.js +565 -438
- package/dist/lib/api/normalize-gltf-v1.js +249 -181
- package/dist/lib/api/post-process-gltf.d.ts +3 -3
- package/dist/lib/api/post-process-gltf.d.ts.map +1 -1
- package/dist/lib/api/post-process-gltf.js +378 -340
- package/dist/lib/encoders/encode-glb.js +62 -48
- package/dist/lib/encoders/encode-gltf.js +24 -10
- package/dist/lib/extensions/EXT_mesh_features.d.ts +2 -2
- package/dist/lib/extensions/EXT_mesh_features.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_mesh_features.js +55 -33
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts +2 -2
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_meshopt_compression.js +27 -31
- package/dist/lib/extensions/EXT_structural_metadata.d.ts +2 -2
- package/dist/lib/extensions/EXT_structural_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_structural_metadata.js +434 -230
- package/dist/lib/extensions/EXT_texture_webp.d.ts +2 -2
- package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_texture_webp.js +24 -17
- package/dist/lib/extensions/KHR_binary_gltf.d.ts +1 -1
- package/dist/lib/extensions/KHR_binary_gltf.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_binary_gltf.js +29 -15
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +2 -2
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.js +110 -87
- package/dist/lib/extensions/KHR_texture_basisu.d.ts +2 -2
- package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_basisu.js +19 -12
- package/dist/lib/extensions/KHR_texture_transform.d.ts +2 -2
- package/dist/lib/extensions/KHR_texture_transform.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_transform.js +188 -156
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +2 -2
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +263 -143
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +44 -32
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +30 -24
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +65 -52
- package/dist/lib/extensions/utils/3d-tiles-utils.d.ts +2 -2
- package/dist/lib/extensions/utils/3d-tiles-utils.d.ts.map +1 -1
- package/dist/lib/extensions/utils/3d-tiles-utils.js +298 -181
- package/dist/lib/gltf-utils/get-typed-array.d.ts +1 -1
- package/dist/lib/gltf-utils/get-typed-array.d.ts.map +1 -1
- package/dist/lib/gltf-utils/get-typed-array.js +54 -42
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts +1 -1
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-attribute-utils.js +58 -52
- package/dist/lib/gltf-utils/gltf-constants.js +27 -27
- package/dist/lib/gltf-utils/gltf-utils.d.ts +1 -1
- package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-utils.js +67 -60
- package/dist/lib/gltf-utils/resolve-url.js +12 -10
- 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 +132 -89
- package/dist/lib/parsers/parse-gltf.d.ts +3 -3
- package/dist/lib/parsers/parse-gltf.d.ts.map +1 -1
- package/dist/lib/parsers/parse-gltf.js +155 -126
- package/dist/lib/types/glb-types.js +0 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts +1 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.js +0 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts +1 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.js +0 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts +1 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.js +0 -1
- package/dist/lib/types/gltf-json-schema.js +2 -1
- package/dist/lib/types/gltf-postprocessed-schema.js +2 -1
- package/dist/lib/types/gltf-types.d.ts +3 -3
- package/dist/lib/types/gltf-types.d.ts.map +1 -1
- package/dist/lib/types/gltf-types.js +1 -1
- package/dist/lib/utils/assert.js +6 -4
- package/dist/lib/utils/version.js +4 -2
- package/dist/meshopt/meshopt-decoder.js +86 -67
- package/dist/webp/webp.js +28 -19
- package/package.json +13 -8
- package/src/lib/extensions/KHR_texture_transform.ts +18 -24
- 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_mesh_features.js.map +0 -1
- package/dist/lib/extensions/EXT_meshopt_compression.js.map +0 -1
- package/dist/lib/extensions/EXT_structural_metadata.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/KHR_texture_transform.js.map +0 -1
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.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/extensions/utils/3d-tiles-utils.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-ext-feature-metadata-schema.js.map +0 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.js.map +0 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.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/meshopt/meshopt-encoder.ts.disabled +0 -409
- 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
|
-
|
|
7
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
texCoord
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
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
|
-
|
|
92
|
-
originalTexCoord
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
|
2
|
-
import { GLTFLoaderOptions } from
|
|
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,
|
|
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"}
|