@loaders.gl/gltf 3.4.14 → 3.4.15
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/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/glb-loader.js +10 -26
- package/dist/es5/glb-loader.js.map +1 -1
- package/dist/es5/glb-writer.js +9 -8
- package/dist/es5/glb-writer.js.map +1 -1
- package/dist/es5/gltf-loader.js +18 -40
- package/dist/es5/gltf-loader.js.map +1 -1
- package/dist/es5/gltf-writer.js +10 -9
- package/dist/es5/gltf-writer.js.map +1 -1
- package/dist/es5/index.js +7 -7
- package/dist/es5/lib/api/gltf-extensions.js +19 -82
- package/dist/es5/lib/api/gltf-extensions.js.map +1 -1
- package/dist/es5/lib/api/gltf-scenegraph.js +395 -524
- package/dist/es5/lib/api/gltf-scenegraph.js.map +1 -1
- package/dist/es5/lib/api/normalize-gltf-v1.js +141 -259
- package/dist/es5/lib/api/normalize-gltf-v1.js.map +1 -1
- package/dist/es5/lib/api/post-process-gltf.js +263 -337
- package/dist/es5/lib/api/post-process-gltf.js.map +1 -1
- package/dist/es5/lib/encoders/encode-glb.js +20 -21
- package/dist/es5/lib/encoders/encode-glb.js.map +1 -1
- package/dist/es5/lib/encoders/encode-gltf.js +3 -3
- package/dist/es5/lib/encoders/encode-gltf.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js +34 -79
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_texture_webp.js +11 -21
- package/dist/es5/lib/extensions/EXT_texture_webp.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_binary_gltf.js +11 -21
- package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +76 -201
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_texture_basisu.js +11 -21
- package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_texture_transform.js +75 -114
- package/dist/es5/lib/extensions/KHR_texture_transform.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +31 -48
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js +37 -84
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js +24 -57
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js +33 -75
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -1
- package/dist/es5/lib/gltf-utils/get-typed-array.js +6 -6
- package/dist/es5/lib/gltf-utils/get-typed-array.js.map +1 -1
- package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js +19 -18
- package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js.map +1 -1
- package/dist/es5/lib/gltf-utils/gltf-constants.js +7 -7
- package/dist/es5/lib/gltf-utils/gltf-constants.js.map +1 -1
- package/dist/es5/lib/gltf-utils/gltf-utils.js +28 -31
- package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -1
- package/dist/es5/lib/gltf-utils/resolve-url.js +2 -2
- package/dist/es5/lib/gltf-utils/resolve-url.js.map +1 -1
- package/dist/es5/lib/parsers/parse-glb.js +35 -34
- package/dist/es5/lib/parsers/parse-glb.js.map +1 -1
- package/dist/es5/lib/parsers/parse-gltf.js +108 -230
- package/dist/es5/lib/parsers/parse-gltf.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/es5/lib/utils/version.js.map +1 -1
- package/dist/es5/meshopt/meshopt-decoder.js +48 -162
- package/dist/es5/meshopt/meshopt-decoder.js.map +1 -1
- package/dist/es5/webp/webp.js +17 -69
- package/dist/es5/webp/webp.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/package.json +6 -6
|
@@ -6,161 +6,123 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.decode = decode;
|
|
8
8
|
exports.name = void 0;
|
|
9
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
10
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
12
9
|
var _core = require("@math.gl/core");
|
|
13
10
|
var _gltfUtils = require("../gltf-utils/gltf-utils");
|
|
14
11
|
var _gltfConstants = require("../gltf-utils/gltf-constants");
|
|
15
12
|
var _gltfScenegraph = _interopRequireDefault(require("../api/gltf-scenegraph"));
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
19
|
-
var EXT_MESHOPT_TRANSFORM = 'KHR_texture_transform';
|
|
20
|
-
var name = EXT_MESHOPT_TRANSFORM;
|
|
13
|
+
const EXT_MESHOPT_TRANSFORM = 'KHR_texture_transform';
|
|
14
|
+
const name = EXT_MESHOPT_TRANSFORM;
|
|
21
15
|
exports.name = name;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function decode(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
extension = gltfScenegraph.getExtension(EXT_MESHOPT_TRANSFORM);
|
|
36
|
-
if (extension) {
|
|
37
|
-
_context.next = 4;
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
return _context.abrupt("return");
|
|
41
|
-
case 4:
|
|
42
|
-
materials = gltfData.json.materials || [];
|
|
43
|
-
for (i = 0; i < materials.length; i++) {
|
|
44
|
-
transformTexCoords(i, gltfData);
|
|
45
|
-
}
|
|
46
|
-
case 6:
|
|
47
|
-
case "end":
|
|
48
|
-
return _context.stop();
|
|
49
|
-
}
|
|
50
|
-
}, _callee);
|
|
51
|
-
}));
|
|
52
|
-
return _decode.apply(this, arguments);
|
|
16
|
+
const scratchVector = new _core.Vector3();
|
|
17
|
+
const scratchRotationMatrix = new _core.Matrix3();
|
|
18
|
+
const scratchScaleMatrix = new _core.Matrix3();
|
|
19
|
+
async function decode(gltfData, options) {
|
|
20
|
+
const gltfScenegraph = new _gltfScenegraph.default(gltfData);
|
|
21
|
+
const extension = gltfScenegraph.getExtension(EXT_MESHOPT_TRANSFORM);
|
|
22
|
+
if (!extension) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const materials = gltfData.json.materials || [];
|
|
26
|
+
for (let i = 0; i < materials.length; i++) {
|
|
27
|
+
transformTexCoords(i, gltfData);
|
|
28
|
+
}
|
|
53
29
|
}
|
|
54
30
|
function transformTexCoords(materialIndex, gltfData) {
|
|
55
31
|
var _gltfData$json$materi, _material$pbrMetallic, _material$pbrMetallic2;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
32
|
+
const processedTexCoords = [];
|
|
33
|
+
const material = (_gltfData$json$materi = gltfData.json.materials) === null || _gltfData$json$materi === void 0 ? void 0 : _gltfData$json$materi[materialIndex];
|
|
34
|
+
const baseColorTexture = material === null || material === void 0 ? void 0 : (_material$pbrMetallic = material.pbrMetallicRoughness) === null || _material$pbrMetallic === void 0 ? void 0 : _material$pbrMetallic.baseColorTexture;
|
|
59
35
|
if (baseColorTexture) {
|
|
60
36
|
transformPrimitives(gltfData, materialIndex, baseColorTexture, processedTexCoords);
|
|
61
37
|
}
|
|
62
|
-
|
|
38
|
+
const emisiveTexture = material === null || material === void 0 ? void 0 : material.emissiveTexture;
|
|
63
39
|
if (emisiveTexture) {
|
|
64
40
|
transformPrimitives(gltfData, materialIndex, emisiveTexture, processedTexCoords);
|
|
65
41
|
}
|
|
66
|
-
|
|
42
|
+
const normalTexture = material === null || material === void 0 ? void 0 : material.normalTexture;
|
|
67
43
|
if (normalTexture) {
|
|
68
44
|
transformPrimitives(gltfData, materialIndex, normalTexture, processedTexCoords);
|
|
69
45
|
}
|
|
70
|
-
|
|
46
|
+
const occlusionTexture = material === null || material === void 0 ? void 0 : material.occlusionTexture;
|
|
71
47
|
if (occlusionTexture) {
|
|
72
48
|
transformPrimitives(gltfData, materialIndex, occlusionTexture, processedTexCoords);
|
|
73
49
|
}
|
|
74
|
-
|
|
50
|
+
const metallicRoughnessTexture = material === null || material === void 0 ? void 0 : (_material$pbrMetallic2 = material.pbrMetallicRoughness) === null || _material$pbrMetallic2 === void 0 ? void 0 : _material$pbrMetallic2.metallicRoughnessTexture;
|
|
75
51
|
if (metallicRoughnessTexture) {
|
|
76
52
|
transformPrimitives(gltfData, materialIndex, metallicRoughnessTexture, processedTexCoords);
|
|
77
53
|
}
|
|
78
54
|
}
|
|
79
55
|
function transformPrimitives(gltfData, materialIndex, texture, processedTexCoords) {
|
|
80
|
-
|
|
56
|
+
const transformParameters = getTransformParameters(texture, processedTexCoords);
|
|
81
57
|
if (!transformParameters) {
|
|
82
58
|
return;
|
|
83
59
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
var _iterator2 = _createForOfIteratorHelper(mesh.primitives),
|
|
91
|
-
_step2;
|
|
92
|
-
try {
|
|
93
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
94
|
-
var primitive = _step2.value;
|
|
95
|
-
var material = primitive.material;
|
|
96
|
-
if (Number.isFinite(material) && materialIndex === material) {
|
|
97
|
-
transformPrimitive(gltfData, primitive, transformParameters);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
} catch (err) {
|
|
101
|
-
_iterator2.e(err);
|
|
102
|
-
} finally {
|
|
103
|
-
_iterator2.f();
|
|
60
|
+
const meshes = gltfData.json.meshes || [];
|
|
61
|
+
for (const mesh of meshes) {
|
|
62
|
+
for (const primitive of mesh.primitives) {
|
|
63
|
+
const material = primitive.material;
|
|
64
|
+
if (Number.isFinite(material) && materialIndex === material) {
|
|
65
|
+
transformPrimitive(gltfData, primitive, transformParameters);
|
|
104
66
|
}
|
|
105
67
|
}
|
|
106
|
-
} catch (err) {
|
|
107
|
-
_iterator.e(err);
|
|
108
|
-
} finally {
|
|
109
|
-
_iterator.f();
|
|
110
68
|
}
|
|
111
69
|
}
|
|
112
70
|
function getTransformParameters(texture, processedTexCoords) {
|
|
113
71
|
var _texture$extensions;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
originalTexCoord =
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
72
|
+
const textureInfo = (_texture$extensions = texture.extensions) === null || _texture$extensions === void 0 ? void 0 : _texture$extensions[EXT_MESHOPT_TRANSFORM];
|
|
73
|
+
const {
|
|
74
|
+
texCoord: originalTexCoord = 0
|
|
75
|
+
} = texture;
|
|
76
|
+
const {
|
|
77
|
+
texCoord = originalTexCoord
|
|
78
|
+
} = textureInfo;
|
|
79
|
+
const isProcessed = processedTexCoords.findIndex(_ref => {
|
|
80
|
+
let [original, newTexCoord] = _ref;
|
|
123
81
|
return original === originalTexCoord && newTexCoord === texCoord;
|
|
124
82
|
}) !== -1;
|
|
125
83
|
if (!isProcessed) {
|
|
126
|
-
|
|
84
|
+
const matrix = makeTransformationMatrix(textureInfo);
|
|
127
85
|
if (originalTexCoord !== texCoord) {
|
|
128
86
|
texture.texCoord = texCoord;
|
|
129
87
|
}
|
|
130
88
|
processedTexCoords.push([originalTexCoord, texCoord]);
|
|
131
89
|
return {
|
|
132
|
-
originalTexCoord
|
|
133
|
-
texCoord
|
|
134
|
-
matrix
|
|
90
|
+
originalTexCoord,
|
|
91
|
+
texCoord,
|
|
92
|
+
matrix
|
|
135
93
|
};
|
|
136
94
|
}
|
|
137
95
|
return null;
|
|
138
96
|
}
|
|
139
97
|
function transformPrimitive(gltfData, primitive, transformParameters) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
98
|
+
const {
|
|
99
|
+
originalTexCoord,
|
|
100
|
+
texCoord,
|
|
101
|
+
matrix
|
|
102
|
+
} = transformParameters;
|
|
103
|
+
const texCoordAccessor = primitive.attributes["TEXCOORD_".concat(originalTexCoord)];
|
|
144
104
|
if (Number.isFinite(texCoordAccessor)) {
|
|
145
105
|
var _gltfData$json$access;
|
|
146
|
-
|
|
106
|
+
const accessor = (_gltfData$json$access = gltfData.json.accessors) === null || _gltfData$json$access === void 0 ? void 0 : _gltfData$json$access[texCoordAccessor];
|
|
147
107
|
if (accessor && accessor.bufferView) {
|
|
148
108
|
var _gltfData$json$buffer;
|
|
149
|
-
|
|
109
|
+
const bufferView = (_gltfData$json$buffer = gltfData.json.bufferViews) === null || _gltfData$json$buffer === void 0 ? void 0 : _gltfData$json$buffer[accessor.bufferView];
|
|
150
110
|
if (bufferView) {
|
|
151
|
-
|
|
152
|
-
arrayBuffer
|
|
153
|
-
bufferByteOffset
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
111
|
+
const {
|
|
112
|
+
arrayBuffer,
|
|
113
|
+
byteOffset: bufferByteOffset
|
|
114
|
+
} = gltfData.buffers[bufferView.buffer];
|
|
115
|
+
const byteOffset = (bufferByteOffset || 0) + (accessor.byteOffset || 0) + (bufferView.byteOffset || 0);
|
|
116
|
+
const {
|
|
117
|
+
ArrayType,
|
|
118
|
+
length
|
|
119
|
+
} = (0, _gltfUtils.getAccessorArrayTypeAndLength)(accessor, bufferView);
|
|
120
|
+
const bytes = _gltfConstants.BYTES[accessor.componentType];
|
|
121
|
+
const components = _gltfConstants.COMPONENTS[accessor.type];
|
|
122
|
+
const elementAddressScale = bufferView.byteStride || bytes * components;
|
|
123
|
+
const result = new Float32Array(length);
|
|
124
|
+
for (let i = 0; i < accessor.count; i++) {
|
|
125
|
+
const uv = new ArrayType(arrayBuffer, byteOffset + i * elementAddressScale, 2);
|
|
164
126
|
scratchVector.set(uv[0], uv[1], 1);
|
|
165
127
|
scratchVector.transformByMatrix3(matrix);
|
|
166
128
|
result.set([scratchVector[0], scratchVector[1]], i * components);
|
|
@@ -192,7 +154,7 @@ function createAttribute(newTexCoord, originalAccessor, primitive, gltfData, new
|
|
|
192
154
|
byteOffset: 0,
|
|
193
155
|
byteLength: newTexCoordArray.buffer.byteLength
|
|
194
156
|
});
|
|
195
|
-
|
|
157
|
+
const bufferViews = gltfData.json.bufferViews;
|
|
196
158
|
if (!bufferViews) {
|
|
197
159
|
return;
|
|
198
160
|
}
|
|
@@ -201,7 +163,7 @@ function createAttribute(newTexCoord, originalAccessor, primitive, gltfData, new
|
|
|
201
163
|
byteLength: newTexCoordArray.buffer.byteLength,
|
|
202
164
|
byteOffset: 0
|
|
203
165
|
});
|
|
204
|
-
|
|
166
|
+
const accessors = gltfData.json.accessors;
|
|
205
167
|
if (!accessors) {
|
|
206
168
|
return;
|
|
207
169
|
}
|
|
@@ -215,15 +177,14 @@ function createAttribute(newTexCoord, originalAccessor, primitive, gltfData, new
|
|
|
215
177
|
primitive.attributes["TEXCOORD_".concat(newTexCoord)] = accessors.length - 1;
|
|
216
178
|
}
|
|
217
179
|
function makeTransformationMatrix(extensionData) {
|
|
218
|
-
|
|
219
|
-
offset =
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
var scaleMatrix = scratchScaleMatrix.set(scale[0], 0, 0, 0, scale[1], 0, 0, 0, 1);
|
|
180
|
+
const {
|
|
181
|
+
offset = [0, 0],
|
|
182
|
+
rotation = 0,
|
|
183
|
+
scale = [1, 1]
|
|
184
|
+
} = extensionData;
|
|
185
|
+
const translationMatirx = new _core.Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1);
|
|
186
|
+
const rotationMatirx = scratchRotationMatrix.set(Math.cos(rotation), Math.sin(rotation), 0, -Math.sin(rotation), Math.cos(rotation), 0, 0, 0, 1);
|
|
187
|
+
const scaleMatrix = scratchScaleMatrix.set(scale[0], 0, 0, 0, scale[1], 0, 0, 0, 1);
|
|
227
188
|
return translationMatirx.multiplyRight(rotationMatirx).multiplyRight(scaleMatrix);
|
|
228
189
|
}
|
|
229
190
|
//# sourceMappingURL=KHR_texture_transform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_texture_transform.js","names":["_core","require","_gltfUtils","_gltfConstants","_gltfScenegraph","_interopRequireDefault","_createForOfIteratorHelper","o","allowArrayLike","it","Symbol","iterator","Array","isArray","_unsupportedIterableToArray","length","i","F","s","n","done","value","e","_e","f","TypeError","normalCompletion","didErr","err","call","step","next","_e2","return","minLen","_arrayLikeToArray","Object","prototype","toString","slice","constructor","name","from","test","arr","len","arr2","EXT_MESHOPT_TRANSFORM","exports","scratchVector","Vector3","scratchRotationMatrix","Matrix3","scratchScaleMatrix","decode","_x","_x2","_decode","apply","arguments","_asyncToGenerator2","default","_regenerator","mark","_callee","gltfData","options","gltfScenegraph","extension","materials","wrap","_callee$","_context","prev","GLTFScenegraph","getExtension","abrupt","json","transformTexCoords","stop","materialIndex","_gltfData$json$materi","_material$pbrMetallic","_material$pbrMetallic2","processedTexCoords","material","baseColorTexture","pbrMetallicRoughness","transformPrimitives","emisiveTexture","emissiveTexture","normalTexture","occlusionTexture","metallicRoughnessTexture","texture","transformParameters","getTransformParameters","meshes","_iterator","_step","mesh","_iterator2","primitives","_step2","primitive","Number","isFinite","transformPrimitive","_texture$extensions","textureInfo","extensions","_texture$texCoord","texCoord","originalTexCoord","_textureInfo$texCoord","isProcessed","findIndex","_ref","_ref2","_slicedToArray2","original","newTexCoord","matrix","makeTransformationMatrix","push","texCoordAccessor","attributes","concat","_gltfData$json$access","accessor","accessors","bufferView","_gltfData$json$buffer","bufferViews","_gltfData$buffers$buf","buffers","buffer","arrayBuffer","bufferByteOffset","byteOffset","_getAccessorArrayType","getAccessorArrayTypeAndLength","ArrayType","bytes","BYTES","componentType","components","COMPONENTS","type","elementAddressScale","byteStride","result","Float32Array","count","uv","set","transformByMatrix3","updateGltf","createAttribute","newTexCoordArray","byteLength","originalAccessor","extensionData","_extensionData$offset","offset","_extensionData$rotati","rotation","_extensionData$scale","scale","translationMatirx","rotationMatirx","Math","cos","sin","scaleMatrix","multiplyRight"],"sources":["../../../../src/lib/extensions/KHR_texture_transform.ts"],"sourcesContent":["/**\n * https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_transform/README.md\n */\n\nimport {Vector3, Matrix3} from '@math.gl/core';\nimport type {GLTFMeshPrimitive, GLTFWithBuffers} from '../types/gltf-types';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\nimport {getAccessorArrayTypeAndLength} from '../gltf-utils/gltf-utils';\nimport {BYTES, COMPONENTS} from '../gltf-utils/gltf-constants';\nimport {\n Accessor,\n BufferView,\n MaterialNormalTextureInfo,\n MaterialOcclusionTextureInfo,\n TextureInfo as GLTFTextureInfo\n} from '../types/gltf-json-schema';\nimport GLTFScenegraph from '../api/gltf-scenegraph';\n\n/** Extension name */\nconst EXT_MESHOPT_TRANSFORM = 'KHR_texture_transform';\n\nexport const name = EXT_MESHOPT_TRANSFORM;\n\nconst scratchVector = new Vector3();\nconst scratchRotationMatrix = new Matrix3();\nconst scratchScaleMatrix = new Matrix3();\n\n/** Extension textureInfo https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates */\ntype TextureInfo = {\n /** The offset of the UV coordinate origin as a factor of the texture dimensions. */\n offset?: [number, number];\n /** Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise. */\n rotation?: number;\n /** The scale factor applied to the components of the UV coordinates. */\n scale?: [number, number];\n /** Overrides the textureInfo texCoord value if supplied, and if this extension is supported. */\n texCoord?: number;\n};\n/** Intersection of all GLTF textures */\ntype CompoundGLTFTextureInfo = GLTFTextureInfo &\n MaterialNormalTextureInfo &\n MaterialOcclusionTextureInfo;\n/** Parameters for TEXCOORD transformation */\ntype TransformParameters = {\n /** Original texCoord value https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#_textureinfo_texcoord */\n originalTexCoord: number;\n /** New texCoord value from extension https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates */\n texCoord: number;\n /** Transformation matrix */\n matrix: Matrix3;\n};\n\n/**\n * The extension entry to process the transformation\n * @param gltfData gltf buffers and json\n * @param options GLTFLoader options\n */\nexport async function decode(gltfData: GLTFWithBuffers, options: GLTFLoaderOptions) {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const extension = gltfScenegraph.getExtension(EXT_MESHOPT_TRANSFORM);\n if (!extension) {\n return;\n }\n const materials = gltfData.json.materials || [];\n for (let i = 0; i < materials.length; i++) {\n transformTexCoords(i, gltfData);\n }\n}\n\n/**\n * Transform TEXCOORD by material\n * @param materialIndex processing material index\n * @param gltfData gltf buffers and json\n */\nfunction transformTexCoords(materialIndex: number, gltfData: GLTFWithBuffers): void {\n // Save processed texCoords in order no to process the same twice\n const processedTexCoords: [number, number][] = [];\n const material = gltfData.json.materials?.[materialIndex];\n const baseColorTexture = material?.pbrMetallicRoughness?.baseColorTexture;\n if (baseColorTexture) {\n transformPrimitives(gltfData, materialIndex, baseColorTexture, processedTexCoords);\n }\n const emisiveTexture = material?.emissiveTexture;\n if (emisiveTexture) {\n transformPrimitives(gltfData, materialIndex, emisiveTexture, processedTexCoords);\n }\n const normalTexture = material?.normalTexture;\n if (normalTexture) {\n transformPrimitives(gltfData, materialIndex, normalTexture, processedTexCoords);\n }\n const occlusionTexture = material?.occlusionTexture;\n if (occlusionTexture) {\n transformPrimitives(gltfData, materialIndex, occlusionTexture, processedTexCoords);\n }\n const metallicRoughnessTexture = material?.pbrMetallicRoughness?.metallicRoughnessTexture;\n if (metallicRoughnessTexture) {\n transformPrimitives(gltfData, materialIndex, metallicRoughnessTexture, processedTexCoords);\n }\n}\n\n/**\n * Transform primitives of the particular material\n * @param gltfData gltf data\n * @param materialIndex primitives with this material will be transformed\n * @param texture texture object\n * @param processedTexCoords storage to save already processed texCoords\n */\nfunction transformPrimitives(\n gltfData: GLTFWithBuffers,\n materialIndex: number,\n texture: CompoundGLTFTextureInfo,\n processedTexCoords: [number, number][]\n) {\n const transformParameters = getTransformParameters(texture, processedTexCoords);\n if (!transformParameters) {\n return;\n }\n const meshes = gltfData.json.meshes || [];\n for (const mesh of meshes) {\n for (const primitive of mesh.primitives) {\n const material = primitive.material;\n if (Number.isFinite(material) && materialIndex === material) {\n transformPrimitive(gltfData, primitive, transformParameters);\n }\n }\n }\n}\n\n/**\n * Get parameters for TEXCOORD transformation\n * @param texture texture object\n * @param processedTexCoords storage to save already processed texCoords\n * @returns texCoord couple and transformation matrix\n */\nfunction getTransformParameters(\n texture: CompoundGLTFTextureInfo,\n processedTexCoords: [number, number][]\n): TransformParameters | null {\n const textureInfo = texture.extensions?.[EXT_MESHOPT_TRANSFORM];\n const {texCoord: originalTexCoord = 0} = texture;\n // If texCoord is not set in the extension, original attribute data will be replaced\n const {texCoord = originalTexCoord} = textureInfo;\n // Make sure that couple [originalTexCoord, extensionTexCoord] is not processed twice\n const isProcessed =\n processedTexCoords.findIndex(\n ([original, newTexCoord]) => original === originalTexCoord && newTexCoord === texCoord\n ) !== -1;\n if (!isProcessed) {\n const matrix = makeTransformationMatrix(textureInfo);\n if (originalTexCoord !== texCoord) {\n texture.texCoord = texCoord;\n }\n processedTexCoords.push([originalTexCoord, texCoord]);\n return {originalTexCoord, texCoord, matrix};\n }\n return null;\n}\n\n/**\n * Transform `TEXCOORD_0` attribute in the primitive\n * @param gltfData gltf data\n * @param primitive primitive object\n * @param transformParameters texCoord couple and transformation matrix\n */\nfunction transformPrimitive(\n gltfData: GLTFWithBuffers,\n primitive: GLTFMeshPrimitive,\n transformParameters: TransformParameters\n) {\n const {originalTexCoord, texCoord, matrix} = transformParameters;\n const texCoordAccessor = primitive.attributes[`TEXCOORD_${originalTexCoord}`];\n if (Number.isFinite(texCoordAccessor)) {\n // Get accessor of the `TEXCOORD_0` attribute\n const accessor = gltfData.json.accessors?.[texCoordAccessor];\n if (accessor && accessor.bufferView) {\n // Get `bufferView` of the `accessor`\n const bufferView = gltfData.json.bufferViews?.[accessor.bufferView];\n if (bufferView) {\n // Get `arrayBuffer` the `bufferView` look at\n const {arrayBuffer, byteOffset: bufferByteOffset} = gltfData.buffers[bufferView.buffer];\n // Resulting byteOffset is sum of the buffer, accessor and bufferView byte offsets\n const byteOffset =\n (bufferByteOffset || 0) + (accessor.byteOffset || 0) + (bufferView.byteOffset || 0);\n // Deduce TypedArray type and its length from `accessor` and `bufferView` data\n const {ArrayType, length} = getAccessorArrayTypeAndLength(accessor, bufferView);\n // Number of bytes each component occupies\n const bytes = BYTES[accessor.componentType];\n // Number of components. For the `TEXCOORD_0` with `VEC2` type, it must return 2\n const components = COMPONENTS[accessor.type];\n // Multiplier to calculate the address of the `TEXCOORD_0` element in the arrayBuffer\n const elementAddressScale = bufferView.byteStride || bytes * components;\n // Data transform to Float32Array\n const result = new Float32Array(length);\n for (let i = 0; i < accessor.count; i++) {\n // Take [u, v] couple from the arrayBuffer\n const uv = new ArrayType(arrayBuffer, byteOffset + i * elementAddressScale, 2);\n // Set and transform Vector3 per https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#overview\n scratchVector.set(uv[0], uv[1], 1);\n scratchVector.transformByMatrix3(matrix);\n // Save result in Float32Array\n result.set([scratchVector[0], scratchVector[1]], i * components);\n }\n // If texCoord the same, replace gltf structural data\n if (originalTexCoord === texCoord) {\n updateGltf(accessor, bufferView, gltfData.buffers, result);\n } else {\n // If texCoord change, create new attribute\n createAttribute(texCoord, accessor, primitive, gltfData, result);\n }\n }\n }\n }\n}\n\n/**\n * Update GLTF structural objects with new data as we create new `Float32Array` for `TEXCOORD_0`.\n * @param accessor accessor to change\n * @param bufferView bufferView to change\n * @param buffers binary buffers\n * @param newTexcoordArray typed array with data after transformation\n */\nfunction updateGltf(\n accessor: Accessor,\n bufferView: BufferView,\n buffers: {arrayBuffer: ArrayBuffer; byteOffset: number; byteLength: number}[],\n newTexCoordArray: Float32Array\n): void {\n accessor.componentType = 5126;\n buffers.push({\n arrayBuffer: newTexCoordArray.buffer,\n byteOffset: 0,\n byteLength: newTexCoordArray.buffer.byteLength\n });\n bufferView.buffer = buffers.length - 1;\n bufferView.byteLength = newTexCoordArray.buffer.byteLength;\n bufferView.byteOffset = 0;\n delete bufferView.byteStride;\n}\n\n/**\n *\n * @param newTexCoord new `texCoord` value\n * @param originalAccessor original accessor object, that store data before transformation\n * @param primitive primitive object\n * @param gltfData gltf data\n * @param newTexCoordArray typed array with data after transformation\n * @returns\n */\nfunction createAttribute(\n newTexCoord: number,\n originalAccessor: Accessor,\n primitive: GLTFMeshPrimitive,\n gltfData: GLTFWithBuffers,\n newTexCoordArray: Float32Array\n) {\n gltfData.buffers.push({\n arrayBuffer: newTexCoordArray.buffer,\n byteOffset: 0,\n byteLength: newTexCoordArray.buffer.byteLength\n });\n const bufferViews = gltfData.json.bufferViews;\n if (!bufferViews) {\n return;\n }\n bufferViews.push({\n buffer: gltfData.buffers.length - 1,\n byteLength: newTexCoordArray.buffer.byteLength,\n byteOffset: 0\n });\n const accessors = gltfData.json.accessors;\n if (!accessors) {\n return;\n }\n accessors.push({\n bufferView: bufferViews?.length - 1,\n byteOffset: 0,\n componentType: 5126,\n count: originalAccessor.count,\n type: 'VEC2'\n });\n primitive.attributes[`TEXCOORD_${newTexCoord}`] = accessors.length - 1;\n}\n\n/**\n * Construct transformation matrix from the extension data (transition, rotation, scale)\n * @param extensionData extension data\n * @returns transformation matrix\n */\nfunction makeTransformationMatrix(extensionData: TextureInfo): Matrix3 {\n const {offset = [0, 0], rotation = 0, scale = [1, 1]} = extensionData;\n const translationMatirx = new Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1);\n const rotationMatirx = scratchRotationMatrix.set(\n Math.cos(rotation),\n Math.sin(rotation),\n 0,\n -Math.sin(rotation),\n Math.cos(rotation),\n 0,\n 0,\n 0,\n 1\n );\n const scaleMatrix = scratchScaleMatrix.set(scale[0], 0, 0, 0, scale[1], 0, 0, 0, 1);\n return translationMatirx.multiplyRight(rotationMatirx).multiplyRight(scaleMatrix);\n}\n"],"mappings":";;;;;;;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AAGA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AAQA,IAAAG,eAAA,GAAAC,sBAAA,CAAAJ,OAAA;AAAoD,SAAAK,2BAAAC,CAAA,EAAAC,cAAA,QAAAC,EAAA,UAAAC,MAAA,oBAAAH,CAAA,CAAAG,MAAA,CAAAC,QAAA,KAAAJ,CAAA,qBAAAE,EAAA,QAAAG,KAAA,CAAAC,OAAA,CAAAN,CAAA,MAAAE,EAAA,GAAAK,2BAAA,CAAAP,CAAA,MAAAC,cAAA,IAAAD,CAAA,WAAAA,CAAA,CAAAQ,MAAA,qBAAAN,EAAA,EAAAF,CAAA,GAAAE,EAAA,MAAAO,CAAA,UAAAC,CAAA,YAAAA,EAAA,eAAAC,CAAA,EAAAD,CAAA,EAAAE,CAAA,WAAAA,EAAA,QAAAH,CAAA,IAAAT,CAAA,CAAAQ,MAAA,WAAAK,IAAA,mBAAAA,IAAA,SAAAC,KAAA,EAAAd,CAAA,CAAAS,CAAA,UAAAM,CAAA,WAAAA,EAAAC,EAAA,UAAAA,EAAA,KAAAC,CAAA,EAAAP,CA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L,cAAc,CAAC,CAACK,aAAa,CAACD,WAAW,CAAC;AACnF"}
|
|
1
|
+
{"version":3,"file":"KHR_texture_transform.js","names":["_core","require","_gltfUtils","_gltfConstants","_gltfScenegraph","_interopRequireDefault","EXT_MESHOPT_TRANSFORM","name","exports","scratchVector","Vector3","scratchRotationMatrix","Matrix3","scratchScaleMatrix","decode","gltfData","options","gltfScenegraph","GLTFScenegraph","extension","getExtension","materials","json","i","length","transformTexCoords","materialIndex","_gltfData$json$materi","_material$pbrMetallic","_material$pbrMetallic2","processedTexCoords","material","baseColorTexture","pbrMetallicRoughness","transformPrimitives","emisiveTexture","emissiveTexture","normalTexture","occlusionTexture","metallicRoughnessTexture","texture","transformParameters","getTransformParameters","meshes","mesh","primitive","primitives","Number","isFinite","transformPrimitive","_texture$extensions","textureInfo","extensions","texCoord","originalTexCoord","isProcessed","findIndex","_ref","original","newTexCoord","matrix","makeTransformationMatrix","push","texCoordAccessor","attributes","concat","_gltfData$json$access","accessor","accessors","bufferView","_gltfData$json$buffer","bufferViews","arrayBuffer","byteOffset","bufferByteOffset","buffers","buffer","ArrayType","getAccessorArrayTypeAndLength","bytes","BYTES","componentType","components","COMPONENTS","type","elementAddressScale","byteStride","result","Float32Array","count","uv","set","transformByMatrix3","updateGltf","createAttribute","newTexCoordArray","byteLength","originalAccessor","extensionData","offset","rotation","scale","translationMatirx","rotationMatirx","Math","cos","sin","scaleMatrix","multiplyRight"],"sources":["../../../../src/lib/extensions/KHR_texture_transform.ts"],"sourcesContent":["/**\n * https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_transform/README.md\n */\n\nimport {Vector3, Matrix3} from '@math.gl/core';\nimport type {GLTFMeshPrimitive, GLTFWithBuffers} from '../types/gltf-types';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\nimport {getAccessorArrayTypeAndLength} from '../gltf-utils/gltf-utils';\nimport {BYTES, COMPONENTS} from '../gltf-utils/gltf-constants';\nimport {\n Accessor,\n BufferView,\n MaterialNormalTextureInfo,\n MaterialOcclusionTextureInfo,\n TextureInfo as GLTFTextureInfo\n} from '../types/gltf-json-schema';\nimport GLTFScenegraph from '../api/gltf-scenegraph';\n\n/** Extension name */\nconst EXT_MESHOPT_TRANSFORM = 'KHR_texture_transform';\n\nexport const name = EXT_MESHOPT_TRANSFORM;\n\nconst scratchVector = new Vector3();\nconst scratchRotationMatrix = new Matrix3();\nconst scratchScaleMatrix = new Matrix3();\n\n/** Extension textureInfo https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates */\ntype TextureInfo = {\n /** The offset of the UV coordinate origin as a factor of the texture dimensions. */\n offset?: [number, number];\n /** Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise. */\n rotation?: number;\n /** The scale factor applied to the components of the UV coordinates. */\n scale?: [number, number];\n /** Overrides the textureInfo texCoord value if supplied, and if this extension is supported. */\n texCoord?: number;\n};\n/** Intersection of all GLTF textures */\ntype CompoundGLTFTextureInfo = GLTFTextureInfo &\n MaterialNormalTextureInfo &\n MaterialOcclusionTextureInfo;\n/** Parameters for TEXCOORD transformation */\ntype TransformParameters = {\n /** Original texCoord value https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#_textureinfo_texcoord */\n originalTexCoord: number;\n /** New texCoord value from extension https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates */\n texCoord: number;\n /** Transformation matrix */\n matrix: Matrix3;\n};\n\n/**\n * The extension entry to process the transformation\n * @param gltfData gltf buffers and json\n * @param options GLTFLoader options\n */\nexport async function decode(gltfData: GLTFWithBuffers, options: GLTFLoaderOptions) {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const extension = gltfScenegraph.getExtension(EXT_MESHOPT_TRANSFORM);\n if (!extension) {\n return;\n }\n const materials = gltfData.json.materials || [];\n for (let i = 0; i < materials.length; i++) {\n transformTexCoords(i, gltfData);\n }\n}\n\n/**\n * Transform TEXCOORD by material\n * @param materialIndex processing material index\n * @param gltfData gltf buffers and json\n */\nfunction transformTexCoords(materialIndex: number, gltfData: GLTFWithBuffers): void {\n // Save processed texCoords in order no to process the same twice\n const processedTexCoords: [number, number][] = [];\n const material = gltfData.json.materials?.[materialIndex];\n const baseColorTexture = material?.pbrMetallicRoughness?.baseColorTexture;\n if (baseColorTexture) {\n transformPrimitives(gltfData, materialIndex, baseColorTexture, processedTexCoords);\n }\n const emisiveTexture = material?.emissiveTexture;\n if (emisiveTexture) {\n transformPrimitives(gltfData, materialIndex, emisiveTexture, processedTexCoords);\n }\n const normalTexture = material?.normalTexture;\n if (normalTexture) {\n transformPrimitives(gltfData, materialIndex, normalTexture, processedTexCoords);\n }\n const occlusionTexture = material?.occlusionTexture;\n if (occlusionTexture) {\n transformPrimitives(gltfData, materialIndex, occlusionTexture, processedTexCoords);\n }\n const metallicRoughnessTexture = material?.pbrMetallicRoughness?.metallicRoughnessTexture;\n if (metallicRoughnessTexture) {\n transformPrimitives(gltfData, materialIndex, metallicRoughnessTexture, processedTexCoords);\n }\n}\n\n/**\n * Transform primitives of the particular material\n * @param gltfData gltf data\n * @param materialIndex primitives with this material will be transformed\n * @param texture texture object\n * @param processedTexCoords storage to save already processed texCoords\n */\nfunction transformPrimitives(\n gltfData: GLTFWithBuffers,\n materialIndex: number,\n texture: CompoundGLTFTextureInfo,\n processedTexCoords: [number, number][]\n) {\n const transformParameters = getTransformParameters(texture, processedTexCoords);\n if (!transformParameters) {\n return;\n }\n const meshes = gltfData.json.meshes || [];\n for (const mesh of meshes) {\n for (const primitive of mesh.primitives) {\n const material = primitive.material;\n if (Number.isFinite(material) && materialIndex === material) {\n transformPrimitive(gltfData, primitive, transformParameters);\n }\n }\n }\n}\n\n/**\n * Get parameters for TEXCOORD transformation\n * @param texture texture object\n * @param processedTexCoords storage to save already processed texCoords\n * @returns texCoord couple and transformation matrix\n */\nfunction getTransformParameters(\n texture: CompoundGLTFTextureInfo,\n processedTexCoords: [number, number][]\n): TransformParameters | null {\n const textureInfo = texture.extensions?.[EXT_MESHOPT_TRANSFORM];\n const {texCoord: originalTexCoord = 0} = texture;\n // If texCoord is not set in the extension, original attribute data will be replaced\n const {texCoord = originalTexCoord} = textureInfo;\n // Make sure that couple [originalTexCoord, extensionTexCoord] is not processed twice\n const isProcessed =\n processedTexCoords.findIndex(\n ([original, newTexCoord]) => original === originalTexCoord && newTexCoord === texCoord\n ) !== -1;\n if (!isProcessed) {\n const matrix = makeTransformationMatrix(textureInfo);\n if (originalTexCoord !== texCoord) {\n texture.texCoord = texCoord;\n }\n processedTexCoords.push([originalTexCoord, texCoord]);\n return {originalTexCoord, texCoord, matrix};\n }\n return null;\n}\n\n/**\n * Transform `TEXCOORD_0` attribute in the primitive\n * @param gltfData gltf data\n * @param primitive primitive object\n * @param transformParameters texCoord couple and transformation matrix\n */\nfunction transformPrimitive(\n gltfData: GLTFWithBuffers,\n primitive: GLTFMeshPrimitive,\n transformParameters: TransformParameters\n) {\n const {originalTexCoord, texCoord, matrix} = transformParameters;\n const texCoordAccessor = primitive.attributes[`TEXCOORD_${originalTexCoord}`];\n if (Number.isFinite(texCoordAccessor)) {\n // Get accessor of the `TEXCOORD_0` attribute\n const accessor = gltfData.json.accessors?.[texCoordAccessor];\n if (accessor && accessor.bufferView) {\n // Get `bufferView` of the `accessor`\n const bufferView = gltfData.json.bufferViews?.[accessor.bufferView];\n if (bufferView) {\n // Get `arrayBuffer` the `bufferView` look at\n const {arrayBuffer, byteOffset: bufferByteOffset} = gltfData.buffers[bufferView.buffer];\n // Resulting byteOffset is sum of the buffer, accessor and bufferView byte offsets\n const byteOffset =\n (bufferByteOffset || 0) + (accessor.byteOffset || 0) + (bufferView.byteOffset || 0);\n // Deduce TypedArray type and its length from `accessor` and `bufferView` data\n const {ArrayType, length} = getAccessorArrayTypeAndLength(accessor, bufferView);\n // Number of bytes each component occupies\n const bytes = BYTES[accessor.componentType];\n // Number of components. For the `TEXCOORD_0` with `VEC2` type, it must return 2\n const components = COMPONENTS[accessor.type];\n // Multiplier to calculate the address of the `TEXCOORD_0` element in the arrayBuffer\n const elementAddressScale = bufferView.byteStride || bytes * components;\n // Data transform to Float32Array\n const result = new Float32Array(length);\n for (let i = 0; i < accessor.count; i++) {\n // Take [u, v] couple from the arrayBuffer\n const uv = new ArrayType(arrayBuffer, byteOffset + i * elementAddressScale, 2);\n // Set and transform Vector3 per https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#overview\n scratchVector.set(uv[0], uv[1], 1);\n scratchVector.transformByMatrix3(matrix);\n // Save result in Float32Array\n result.set([scratchVector[0], scratchVector[1]], i * components);\n }\n // If texCoord the same, replace gltf structural data\n if (originalTexCoord === texCoord) {\n updateGltf(accessor, bufferView, gltfData.buffers, result);\n } else {\n // If texCoord change, create new attribute\n createAttribute(texCoord, accessor, primitive, gltfData, result);\n }\n }\n }\n }\n}\n\n/**\n * Update GLTF structural objects with new data as we create new `Float32Array` for `TEXCOORD_0`.\n * @param accessor accessor to change\n * @param bufferView bufferView to change\n * @param buffers binary buffers\n * @param newTexcoordArray typed array with data after transformation\n */\nfunction updateGltf(\n accessor: Accessor,\n bufferView: BufferView,\n buffers: {arrayBuffer: ArrayBuffer; byteOffset: number; byteLength: number}[],\n newTexCoordArray: Float32Array\n): void {\n accessor.componentType = 5126;\n buffers.push({\n arrayBuffer: newTexCoordArray.buffer,\n byteOffset: 0,\n byteLength: newTexCoordArray.buffer.byteLength\n });\n bufferView.buffer = buffers.length - 1;\n bufferView.byteLength = newTexCoordArray.buffer.byteLength;\n bufferView.byteOffset = 0;\n delete bufferView.byteStride;\n}\n\n/**\n *\n * @param newTexCoord new `texCoord` value\n * @param originalAccessor original accessor object, that store data before transformation\n * @param primitive primitive object\n * @param gltfData gltf data\n * @param newTexCoordArray typed array with data after transformation\n * @returns\n */\nfunction createAttribute(\n newTexCoord: number,\n originalAccessor: Accessor,\n primitive: GLTFMeshPrimitive,\n gltfData: GLTFWithBuffers,\n newTexCoordArray: Float32Array\n) {\n gltfData.buffers.push({\n arrayBuffer: newTexCoordArray.buffer,\n byteOffset: 0,\n byteLength: newTexCoordArray.buffer.byteLength\n });\n const bufferViews = gltfData.json.bufferViews;\n if (!bufferViews) {\n return;\n }\n bufferViews.push({\n buffer: gltfData.buffers.length - 1,\n byteLength: newTexCoordArray.buffer.byteLength,\n byteOffset: 0\n });\n const accessors = gltfData.json.accessors;\n if (!accessors) {\n return;\n }\n accessors.push({\n bufferView: bufferViews?.length - 1,\n byteOffset: 0,\n componentType: 5126,\n count: originalAccessor.count,\n type: 'VEC2'\n });\n primitive.attributes[`TEXCOORD_${newTexCoord}`] = accessors.length - 1;\n}\n\n/**\n * Construct transformation matrix from the extension data (transition, rotation, scale)\n * @param extensionData extension data\n * @returns transformation matrix\n */\nfunction makeTransformationMatrix(extensionData: TextureInfo): Matrix3 {\n const {offset = [0, 0], rotation = 0, scale = [1, 1]} = extensionData;\n const translationMatirx = new Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1);\n const rotationMatirx = scratchRotationMatrix.set(\n Math.cos(rotation),\n Math.sin(rotation),\n 0,\n -Math.sin(rotation),\n Math.cos(rotation),\n 0,\n 0,\n 0,\n 1\n );\n const scaleMatrix = scratchScaleMatrix.set(scale[0], 0, 0, 0, scale[1], 0, 0, 0, 1);\n return translationMatirx.multiplyRight(rotationMatirx).multiplyRight(scaleMatrix);\n}\n"],"mappings":";;;;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AAGA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AAQA,IAAAG,eAAA,GAAAC,sBAAA,CAAAJ,OAAA;AAGA,MAAMK,qBAAqB,GAAG,uBAAuB;AAE9C,MAAMC,IAAI,GAAGD,qBAAqB;AAACE,OAAA,CAAAD,IAAA,GAAAA,IAAA;AAE1C,MAAME,aAAa,GAAG,IAAIC,aAAO,CAAC,CAAC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CAAC,CAAC,EAAEA,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;EACtF,MAAMI,cAAc,GAAG5F,qBAAqB,CAACgF,GAAG,CAC9Ca,IAAI,CAACC,GAAG,CAACL,QAAQ,CAAC,EAClBI,IAAI,CAACE,GAAG,CAACN,QAAQ,CAAC,EAClB,CAAC,EACD,CAACI,IAAI,CAACE,GAAG,CAACN,QAAQ,CAAC,EACnBI,IAAI,CAACC,GAAG,CAACL,QAAQ,CAAC,EAClB,CAAC,EACD,CAAC,EACD,CAAC,EACD,CACF,CAAC;EACD,MAAMO,WAAW,GAAG9F,kBAAkB,CAAC8E,GAAG,CAACU,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAEA,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;EACnF,OAAOC,iBAAiB,CAACM,aAAa,CAACL,cAAc,CAAC,CAACK,aAAa,CAACD,WAAW,CAAC;AACnF"}
|
|
@@ -6,44 +6,27 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.decode = decode;
|
|
8
8
|
exports.name = void 0;
|
|
9
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
10
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
9
|
var _gltfScenegraph = _interopRequireDefault(require("../../api/gltf-scenegraph"));
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const EXT_FEATURE_METADATA = 'EXT_feature_metadata';
|
|
11
|
+
const name = EXT_FEATURE_METADATA;
|
|
14
12
|
exports.name = name;
|
|
15
|
-
function decode(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function _decode() {
|
|
19
|
-
_decode = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(gltfData) {
|
|
20
|
-
var scenegraph;
|
|
21
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
22
|
-
while (1) switch (_context.prev = _context.next) {
|
|
23
|
-
case 0:
|
|
24
|
-
scenegraph = new _gltfScenegraph.default(gltfData);
|
|
25
|
-
decodeExtFeatureMetadata(scenegraph);
|
|
26
|
-
case 2:
|
|
27
|
-
case "end":
|
|
28
|
-
return _context.stop();
|
|
29
|
-
}
|
|
30
|
-
}, _callee);
|
|
31
|
-
}));
|
|
32
|
-
return _decode.apply(this, arguments);
|
|
13
|
+
async function decode(gltfData) {
|
|
14
|
+
const scenegraph = new _gltfScenegraph.default(gltfData);
|
|
15
|
+
decodeExtFeatureMetadata(scenegraph);
|
|
33
16
|
}
|
|
34
17
|
function decodeExtFeatureMetadata(scenegraph) {
|
|
35
18
|
var _extension$schema;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
19
|
+
const extension = scenegraph.getExtension(EXT_FEATURE_METADATA);
|
|
20
|
+
const schemaClasses = extension === null || extension === void 0 ? void 0 : (_extension$schema = extension.schema) === null || _extension$schema === void 0 ? void 0 : _extension$schema.classes;
|
|
21
|
+
const featureTables = extension === null || extension === void 0 ? void 0 : extension.featureTables;
|
|
22
|
+
const featureTextures = extension === null || extension === void 0 ? void 0 : extension.featureTextures;
|
|
40
23
|
if (featureTextures) {
|
|
41
24
|
console.warn('featureTextures is not yet supported in the "EXT_feature_metadata" extension.');
|
|
42
25
|
}
|
|
43
26
|
if (schemaClasses && featureTables) {
|
|
44
|
-
for (
|
|
45
|
-
|
|
46
|
-
|
|
27
|
+
for (const schemaName in schemaClasses) {
|
|
28
|
+
const schemaClass = schemaClasses[schemaName];
|
|
29
|
+
const featureTable = findFeatureTableByName(featureTables, schemaName);
|
|
47
30
|
if (featureTable) {
|
|
48
31
|
handleFeatureTableProperties(scenegraph, featureTable, schemaClass);
|
|
49
32
|
}
|
|
@@ -51,25 +34,25 @@ function decodeExtFeatureMetadata(scenegraph) {
|
|
|
51
34
|
}
|
|
52
35
|
}
|
|
53
36
|
function handleFeatureTableProperties(scenegraph, featureTable, schemaClass) {
|
|
54
|
-
for (
|
|
37
|
+
for (const propertyName in schemaClass.properties) {
|
|
55
38
|
var _featureTable$propert;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
39
|
+
const schemaProperty = schemaClass.properties[propertyName];
|
|
40
|
+
const featureTableProperty = featureTable === null || featureTable === void 0 ? void 0 : (_featureTable$propert = featureTable.properties) === null || _featureTable$propert === void 0 ? void 0 : _featureTable$propert[propertyName];
|
|
41
|
+
const numberOfFeatures = featureTable.count;
|
|
59
42
|
if (featureTableProperty) {
|
|
60
|
-
|
|
43
|
+
const data = getPropertyDataFromBinarySource(scenegraph, schemaProperty, numberOfFeatures, featureTableProperty);
|
|
61
44
|
featureTableProperty.data = data;
|
|
62
45
|
}
|
|
63
46
|
}
|
|
64
47
|
}
|
|
65
48
|
function getPropertyDataFromBinarySource(scenegraph, schemaProperty, numberOfFeatures, featureTableProperty) {
|
|
66
|
-
|
|
67
|
-
|
|
49
|
+
const bufferView = featureTableProperty.bufferView;
|
|
50
|
+
let data = scenegraph.getTypedArrayForBufferView(bufferView);
|
|
68
51
|
switch (schemaProperty.type) {
|
|
69
52
|
case 'STRING':
|
|
70
53
|
{
|
|
71
|
-
|
|
72
|
-
|
|
54
|
+
const stringOffsetBufferView = featureTableProperty.stringOffsetBufferView;
|
|
55
|
+
const offsetsData = scenegraph.getTypedArrayForBufferView(stringOffsetBufferView);
|
|
73
56
|
data = getStringAttributes(data, offsetsData, numberOfFeatures);
|
|
74
57
|
break;
|
|
75
58
|
}
|
|
@@ -78,8 +61,8 @@ function getPropertyDataFromBinarySource(scenegraph, schemaProperty, numberOfFea
|
|
|
78
61
|
return data;
|
|
79
62
|
}
|
|
80
63
|
function findFeatureTableByName(featureTables, schemaClassName) {
|
|
81
|
-
for (
|
|
82
|
-
|
|
64
|
+
for (const featureTableName in featureTables) {
|
|
65
|
+
const featureTable = featureTables[featureTableName];
|
|
83
66
|
if (featureTable.class === schemaClassName) {
|
|
84
67
|
return featureTable;
|
|
85
68
|
}
|
|
@@ -87,14 +70,14 @@ function findFeatureTableByName(featureTables, schemaClassName) {
|
|
|
87
70
|
return null;
|
|
88
71
|
}
|
|
89
72
|
function getStringAttributes(data, offsetsData, stringsCount) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
for (
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
73
|
+
const stringsArray = [];
|
|
74
|
+
const textDecoder = new TextDecoder('utf8');
|
|
75
|
+
let stringOffset = 0;
|
|
76
|
+
const bytesPerStringSize = 4;
|
|
77
|
+
for (let index = 0; index < stringsCount; index++) {
|
|
78
|
+
const stringByteSize = offsetsData[(index + 1) * bytesPerStringSize] - offsetsData[index * bytesPerStringSize];
|
|
79
|
+
const stringData = data.subarray(stringOffset, stringByteSize + stringOffset);
|
|
80
|
+
const stringAttribute = textDecoder.decode(stringData);
|
|
98
81
|
stringsArray.push(stringAttribute);
|
|
99
82
|
stringOffset += stringByteSize;
|
|
100
83
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EXT_feature_metadata.js","names":["_gltfScenegraph","_interopRequireDefault","require","EXT_FEATURE_METADATA","name","exports","decode","
|
|
1
|
+
{"version":3,"file":"EXT_feature_metadata.js","names":["_gltfScenegraph","_interopRequireDefault","require","EXT_FEATURE_METADATA","name","exports","decode","gltfData","scenegraph","GLTFScenegraph","decodeExtFeatureMetadata","_extension$schema","extension","getExtension","schemaClasses","schema","classes","featureTables","featureTextures","console","warn","schemaName","schemaClass","featureTable","findFeatureTableByName","handleFeatureTableProperties","propertyName","properties","_featureTable$propert","schemaProperty","featureTableProperty","numberOfFeatures","count","data","getPropertyDataFromBinarySource","bufferView","getTypedArrayForBufferView","type","stringOffsetBufferView","offsetsData","getStringAttributes","schemaClassName","featureTableName","class","stringsCount","stringsArray","textDecoder","TextDecoder","stringOffset","bytesPerStringSize","index","stringByteSize","stringData","subarray","stringAttribute","push"],"sources":["../../../../../src/lib/extensions/deprecated/EXT_feature_metadata.ts"],"sourcesContent":["/* eslint-disable camelcase */\nimport type {GLTF} from '../../types/gltf-types';\n\nimport GLTFScenegraph from '../../api/gltf-scenegraph';\nimport {\n ClassProperty,\n EXT_feature_metadata_class_object,\n EXT_feature_metadata_feature_table,\n FeatureTableProperty,\n GLTF_EXT_feature_metadata\n} from '../../types/gltf-json-schema';\n\n/** Extension name */\nconst EXT_FEATURE_METADATA = 'EXT_feature_metadata';\n\nexport const name = EXT_FEATURE_METADATA;\n\nexport async function decode(gltfData: {json: GLTF}): Promise<void> {\n const scenegraph = new GLTFScenegraph(gltfData);\n decodeExtFeatureMetadata(scenegraph);\n}\n\n/**\n * Decodes feature metadata from extension\n * @param scenegraph\n */\nfunction decodeExtFeatureMetadata(scenegraph: GLTFScenegraph): void {\n const extension: GLTF_EXT_feature_metadata | null = scenegraph.getExtension(EXT_FEATURE_METADATA);\n const schemaClasses = extension?.schema?.classes;\n const featureTables = extension?.featureTables;\n const featureTextures = extension?.featureTextures;\n\n if (featureTextures) {\n /*\n * TODO add support for featureTextures\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#feature-textures\n */\n // eslint-disable-next-line no-console\n console.warn('featureTextures is not yet supported in the \"EXT_feature_metadata\" extension.');\n }\n\n if (schemaClasses && featureTables) {\n for (const schemaName in schemaClasses) {\n const schemaClass = schemaClasses[schemaName];\n const featureTable = findFeatureTableByName(featureTables, schemaName);\n\n if (featureTable) {\n handleFeatureTableProperties(scenegraph, featureTable, schemaClass);\n }\n }\n }\n}\n\n/**\n * Navigate throw all properies in feature table and gets properties data.\n * @param scenegraph\n * @param featureTable\n * @param schemaClass\n */\nfunction handleFeatureTableProperties(\n scenegraph: GLTFScenegraph,\n featureTable: EXT_feature_metadata_feature_table,\n schemaClass: EXT_feature_metadata_class_object\n): void {\n for (const propertyName in schemaClass.properties) {\n const schemaProperty = schemaClass.properties[propertyName];\n const featureTableProperty = featureTable?.properties?.[propertyName];\n const numberOfFeatures = featureTable.count;\n\n if (featureTableProperty) {\n const data = getPropertyDataFromBinarySource(\n scenegraph,\n schemaProperty,\n numberOfFeatures,\n featureTableProperty\n );\n featureTableProperty.data = data;\n }\n }\n}\n\n/**\n * Decode properties from binary sourse based on property type.\n * @param scenegraph\n * @param schemaProperty\n * @param numberOfFeatures\n * @param featureTableProperty\n */\nfunction getPropertyDataFromBinarySource(\n scenegraph: GLTFScenegraph,\n schemaProperty: ClassProperty,\n numberOfFeatures: number,\n featureTableProperty: FeatureTableProperty\n): Uint8Array | string[] {\n const bufferView = featureTableProperty.bufferView;\n // TODO think maybe we shouldn't get data only in Uint8Array format.\n let data: Uint8Array | string[] = scenegraph.getTypedArrayForBufferView(bufferView);\n\n switch (schemaProperty.type) {\n case 'STRING': {\n // stringOffsetBufferView should be available for string type.\n const stringOffsetBufferView = featureTableProperty.stringOffsetBufferView!;\n const offsetsData = scenegraph.getTypedArrayForBufferView(stringOffsetBufferView);\n data = getStringAttributes(data, offsetsData, numberOfFeatures);\n break;\n }\n default:\n }\n\n return data;\n}\n\n/**\n * Find the feature table by class name.\n * @param featureTables\n * @param schemaClassName\n */\nfunction findFeatureTableByName(\n featureTables: {[key: string]: EXT_feature_metadata_feature_table},\n schemaClassName: string\n): EXT_feature_metadata_feature_table | null {\n for (const featureTableName in featureTables) {\n const featureTable = featureTables[featureTableName];\n\n if (featureTable.class === schemaClassName) {\n return featureTable;\n }\n }\n\n return null;\n}\n\n/**\n * Getting string attributes from binary data.\n * Spec - https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata#strings\n * @param data\n * @param offsetsData\n * @param stringsCount\n */\nfunction getStringAttributes(\n data: Uint8Array,\n offsetsData: Uint8Array,\n stringsCount: number\n): string[] {\n const stringsArray: string[] = [];\n const textDecoder = new TextDecoder('utf8');\n\n let stringOffset = 0;\n const bytesPerStringSize = 4;\n\n for (let index = 0; index < stringsCount; index++) {\n // TODO check if it is multiplication on bytesPerStringSize is valid operation?\n const stringByteSize =\n offsetsData[(index + 1) * bytesPerStringSize] - offsetsData[index * bytesPerStringSize];\n const stringData = data.subarray(stringOffset, stringByteSize + stringOffset);\n const stringAttribute = textDecoder.decode(stringData);\n\n stringsArray.push(stringAttribute);\n stringOffset += stringByteSize;\n }\n\n return stringsArray;\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,eAAA,GAAAC,sBAAA,CAAAC,OAAA;AAUA,MAAMC,oBAAoB,GAAG,sBAAsB;AAE5C,MAAMC,IAAI,GAAGD,oBAAoB;AAACE,OAAA,CAAAD,IAAA,GAAAA,IAAA;AAElC,eAAeE,MAAMA,CAACC,QAAsB,EAAiB;EAClE,MAAMC,UAAU,GAAG,IAAIC,uBAAc,CAACF,QAAQ,CAAC;EAC/CG,wBAAwB,CAACF,UAAU,CAAC;AACtC;AAMA,SAASE,wBAAwBA,CAACF,UAA0B,EAAQ;EAAA,IAAAG,iBAAA;EAClE,MAAMC,SAA2C,GAAGJ,UAAU,CAACK,YAAY,CAACV,oBAAoB,CAAC;EACjG,MAAMW,aAAa,GAAGF,SAAS,aAATA,SAAS,wBAAAD,iBAAA,GAATC,SAAS,CAAEG,MAAM,cAAAJ,iBAAA,uBAAjBA,iBAAA,CAAmBK,OAAO;EAChD,MAAMC,aAAa,GAAGL,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAEK,aAAa;EAC9C,MAAMC,eAAe,GAAGN,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAEM,eAAe;EAElD,IAAIA,eAAe,EAAE;IAMnBC,OAAO,CAACC,IAAI,CAAC,+EAA+E,CAAC;EAC/F;EAEA,IAAIN,aAAa,IAAIG,aAAa,EAAE;IAClC,KAAK,MAAMI,UAAU,IAAIP,aAAa,EAAE;MACtC,MAAMQ,WAAW,GAAGR,aAAa,CAACO,UAAU,CAAC;MAC7C,MAAME,YAAY,GAAGC,sBAAsB,CAACP,aA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