@loaders.gl/gltf 4.2.0-alpha.4 → 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.
- package/dist/dist.dev.js +1049 -517
- 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 +95 -284
- 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 +561 -438
- package/dist/lib/api/normalize-gltf-v1.js +250 -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 +375 -339
- 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 +194 -154
- 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 +3 -1
- package/dist/meshopt/meshopt-decoder.js +86 -67
- package/dist/webp/webp.js +28 -19
- package/package.json +12 -8
- 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,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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
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;
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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);
|
|
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
|
|
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"}
|