@loaders.gl/gltf 3.2.7 → 3.3.0-alpha.3
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.min.js +1494 -38
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/api/gltf-extensions.js +5 -1
- package/dist/es5/lib/api/gltf-extensions.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_texture_transform.js +293 -0
- package/dist/es5/lib/extensions/KHR_texture_transform.js.map +1 -0
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +131 -0
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -0
- package/dist/es5/lib/gltf-utils/gltf-constants.js +3 -0
- package/dist/es5/lib/gltf-utils/gltf-constants.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/esm/index.js.map +1 -1
- package/dist/esm/lib/api/gltf-extensions.js +3 -1
- package/dist/esm/lib/api/gltf-extensions.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_texture_transform.js +218 -0
- package/dist/esm/lib/extensions/KHR_texture_transform.js.map +1 -0
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js +95 -0
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -0
- package/dist/esm/lib/gltf-utils/gltf-constants.js +2 -2
- package/dist/esm/lib/gltf-utils/gltf-constants.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/esm/lib/utils/version.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/api/gltf-extensions.d.ts +5 -0
- package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
- package/dist/lib/api/gltf-extensions.js +5 -1
- package/dist/lib/extensions/KHR_texture_transform.d.ts +13 -0
- package/dist/lib/extensions/KHR_texture_transform.d.ts.map +1 -0
- package/dist/lib/extensions/KHR_texture_transform.js +230 -0
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +6 -0
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -0
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +118 -0
- package/dist/lib/gltf-utils/gltf-constants.d.ts +17 -0
- package/dist/lib/gltf-utils/gltf-constants.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-constants.js +5 -5
- package/dist/lib/types/gltf-json-schema.d.ts +386 -2
- package/dist/lib/types/gltf-json-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-types.d.ts +2 -2
- package/dist/lib/types/gltf-types.d.ts.map +1 -1
- package/package.json +7 -6
- package/src/index.ts +2 -1
- package/src/lib/api/gltf-extensions.ts +13 -2
- package/src/lib/extensions/KHR_texture_transform.ts +305 -0
- package/src/lib/extensions/deprecated/EXT_feature_metadata.ts +163 -0
- package/src/lib/gltf-utils/gltf-constants.ts +2 -2
- package/src/lib/types/gltf-json-schema.ts +431 -2
- package/src/lib/types/gltf-types.ts +4 -2
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_transform/README.md
|
|
4
|
+
*/
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.decode = exports.name = void 0;
|
|
10
|
+
const core_1 = require("@math.gl/core");
|
|
11
|
+
const gltf_utils_1 = require("../gltf-utils/gltf-utils");
|
|
12
|
+
const gltf_constants_1 = require("../gltf-utils/gltf-constants");
|
|
13
|
+
const gltf_scenegraph_1 = __importDefault(require("../api/gltf-scenegraph"));
|
|
14
|
+
/** Extension name */
|
|
15
|
+
const EXT_MESHOPT_TRANSFORM = 'KHR_texture_transform';
|
|
16
|
+
exports.name = EXT_MESHOPT_TRANSFORM;
|
|
17
|
+
const scratchVector = new core_1.Vector3();
|
|
18
|
+
const scratchRotationMatrix = new core_1.Matrix3();
|
|
19
|
+
const scratchScaleMatrix = new core_1.Matrix3();
|
|
20
|
+
/**
|
|
21
|
+
* The extension entry to process the transformation
|
|
22
|
+
* @param gltfData gltf buffers and json
|
|
23
|
+
* @param options GLTFLoader options
|
|
24
|
+
*/
|
|
25
|
+
async function decode(gltfData, options) {
|
|
26
|
+
const gltfScenegraph = new gltf_scenegraph_1.default(gltfData);
|
|
27
|
+
const extension = gltfScenegraph.getExtension(EXT_MESHOPT_TRANSFORM);
|
|
28
|
+
if (!extension) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const materials = gltfData.json.materials || [];
|
|
32
|
+
for (let i = 0; i < materials.length; i++) {
|
|
33
|
+
transformTexCoords(i, gltfData);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.decode = decode;
|
|
37
|
+
/**
|
|
38
|
+
* Transform TEXCOORD by material
|
|
39
|
+
* @param materialIndex processing material index
|
|
40
|
+
* @param gltfData gltf buffers and json
|
|
41
|
+
*/
|
|
42
|
+
function transformTexCoords(materialIndex, gltfData) {
|
|
43
|
+
// Save processed texCoords in order no to process the same twice
|
|
44
|
+
const processedTexCoords = [];
|
|
45
|
+
const material = gltfData.json.materials?.[materialIndex];
|
|
46
|
+
const baseColorTexture = material?.pbrMetallicRoughness?.baseColorTexture;
|
|
47
|
+
if (baseColorTexture) {
|
|
48
|
+
transformPrimitives(gltfData, materialIndex, baseColorTexture, processedTexCoords);
|
|
49
|
+
}
|
|
50
|
+
const emisiveTexture = material?.emissiveTexture;
|
|
51
|
+
if (emisiveTexture) {
|
|
52
|
+
transformPrimitives(gltfData, materialIndex, emisiveTexture, processedTexCoords);
|
|
53
|
+
}
|
|
54
|
+
const normalTexture = material?.normalTexture;
|
|
55
|
+
if (normalTexture) {
|
|
56
|
+
transformPrimitives(gltfData, materialIndex, normalTexture, processedTexCoords);
|
|
57
|
+
}
|
|
58
|
+
const occlusionTexture = material?.occlusionTexture;
|
|
59
|
+
if (occlusionTexture) {
|
|
60
|
+
transformPrimitives(gltfData, materialIndex, occlusionTexture, processedTexCoords);
|
|
61
|
+
}
|
|
62
|
+
const metallicRoughnessTexture = material?.pbrMetallicRoughness?.metallicRoughnessTexture;
|
|
63
|
+
if (metallicRoughnessTexture) {
|
|
64
|
+
transformPrimitives(gltfData, materialIndex, metallicRoughnessTexture, processedTexCoords);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Transform primitives of the particular material
|
|
69
|
+
* @param gltfData gltf data
|
|
70
|
+
* @param materialIndex primitives with this material will be transformed
|
|
71
|
+
* @param texture texture object
|
|
72
|
+
* @param processedTexCoords storage to save already processed texCoords
|
|
73
|
+
*/
|
|
74
|
+
function transformPrimitives(gltfData, materialIndex, texture, processedTexCoords) {
|
|
75
|
+
const transformParameters = getTransformParameters(texture, processedTexCoords);
|
|
76
|
+
if (!transformParameters) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const meshes = gltfData.json.meshes || [];
|
|
80
|
+
for (const mesh of meshes) {
|
|
81
|
+
for (const primitive of mesh.primitives) {
|
|
82
|
+
const material = primitive.material;
|
|
83
|
+
if (Number.isFinite(material) && materialIndex === material) {
|
|
84
|
+
transformPrimitive(gltfData, primitive, transformParameters);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get parameters for TEXCOORD transformation
|
|
91
|
+
* @param texture texture object
|
|
92
|
+
* @param processedTexCoords storage to save already processed texCoords
|
|
93
|
+
* @returns texCoord couple and transformation matrix
|
|
94
|
+
*/
|
|
95
|
+
function getTransformParameters(texture, processedTexCoords) {
|
|
96
|
+
const textureInfo = texture.extensions?.[EXT_MESHOPT_TRANSFORM];
|
|
97
|
+
const { texCoord: originalTexCoord = 0 } = texture;
|
|
98
|
+
// If texCoord is not set in the extension, original attribute data will be replaced
|
|
99
|
+
const { texCoord = originalTexCoord } = textureInfo;
|
|
100
|
+
// Make sure that couple [originalTexCoord, extensionTexCoord] is not processed twice
|
|
101
|
+
const isProcessed = processedTexCoords.findIndex(([original, newTexCoord]) => original === originalTexCoord && newTexCoord === texCoord) !== -1;
|
|
102
|
+
if (!isProcessed) {
|
|
103
|
+
const matrix = makeTransformationMatrix(textureInfo);
|
|
104
|
+
if (originalTexCoord !== texCoord) {
|
|
105
|
+
texture.texCoord = texCoord;
|
|
106
|
+
}
|
|
107
|
+
processedTexCoords.push([originalTexCoord, texCoord]);
|
|
108
|
+
return { originalTexCoord, texCoord, matrix };
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Transform `TEXCOORD_0` attribute in the primitive
|
|
114
|
+
* @param gltfData gltf data
|
|
115
|
+
* @param primitive primitive object
|
|
116
|
+
* @param transformParameters texCoord couple and transformation matrix
|
|
117
|
+
*/
|
|
118
|
+
function transformPrimitive(gltfData, primitive, transformParameters) {
|
|
119
|
+
const { originalTexCoord, texCoord, matrix } = transformParameters;
|
|
120
|
+
const texCoordAccessor = primitive.attributes[`TEXCOORD_${originalTexCoord}`];
|
|
121
|
+
if (Number.isFinite(texCoordAccessor)) {
|
|
122
|
+
// Get accessor of the `TEXCOORD_0` attribute
|
|
123
|
+
const accessor = gltfData.json.accessors?.[texCoordAccessor];
|
|
124
|
+
if (accessor && accessor.bufferView) {
|
|
125
|
+
// Get `bufferView` of the `accessor`
|
|
126
|
+
const bufferView = gltfData.json.bufferViews?.[accessor.bufferView];
|
|
127
|
+
if (bufferView) {
|
|
128
|
+
// Get `arrayBuffer` the `bufferView` look at
|
|
129
|
+
const { arrayBuffer, byteOffset: bufferByteOffset } = gltfData.buffers[bufferView.buffer];
|
|
130
|
+
// Resulting byteOffset is sum of the buffer, accessor and bufferView byte offsets
|
|
131
|
+
const byteOffset = (bufferByteOffset || 0) + (accessor.byteOffset || 0) + (bufferView.byteOffset || 0);
|
|
132
|
+
// Deduce TypedArray type and its length from `accessor` and `bufferView` data
|
|
133
|
+
const { ArrayType, length } = (0, gltf_utils_1.getAccessorArrayTypeAndLength)(accessor, bufferView);
|
|
134
|
+
// Number of bytes each component occupies
|
|
135
|
+
const bytes = gltf_constants_1.BYTES[accessor.componentType];
|
|
136
|
+
// Number of components. For the `TEXCOORD_0` with `VEC2` type, it must return 2
|
|
137
|
+
const components = gltf_constants_1.COMPONENTS[accessor.type];
|
|
138
|
+
// Multiplier to calculate the address of the `TEXCOORD_0` element in the arrayBuffer
|
|
139
|
+
const elementAddressScale = bufferView.byteStride || bytes * components;
|
|
140
|
+
// Data transform to Float32Array
|
|
141
|
+
const result = new Float32Array(length);
|
|
142
|
+
for (let i = 0; i < accessor.count; i++) {
|
|
143
|
+
// Take [u, v] couple from the arrayBuffer
|
|
144
|
+
const uv = new ArrayType(arrayBuffer, byteOffset + i * elementAddressScale, 2);
|
|
145
|
+
// Set and transform Vector3 per https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#overview
|
|
146
|
+
scratchVector.set(uv[0], uv[1], 1);
|
|
147
|
+
scratchVector.transformByMatrix3(matrix);
|
|
148
|
+
// Save result in Float32Array
|
|
149
|
+
result.set([scratchVector[0], scratchVector[1]], i * components);
|
|
150
|
+
}
|
|
151
|
+
// If texCoord the same, replace gltf structural data
|
|
152
|
+
if (originalTexCoord === texCoord) {
|
|
153
|
+
updateGltf(accessor, bufferView, gltfData.buffers, result);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
// If texCoord change, create new attribute
|
|
157
|
+
createAttribute(texCoord, accessor, primitive, gltfData, result);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Update GLTF structural objects with new data as we create new `Float32Array` for `TEXCOORD_0`.
|
|
165
|
+
* @param accessor accessor to change
|
|
166
|
+
* @param bufferView bufferView to change
|
|
167
|
+
* @param buffers binary buffers
|
|
168
|
+
* @param newTexcoordArray typed array with data after transformation
|
|
169
|
+
*/
|
|
170
|
+
function updateGltf(accessor, bufferView, buffers, newTexCoordArray) {
|
|
171
|
+
accessor.componentType = 5126;
|
|
172
|
+
buffers.push({
|
|
173
|
+
arrayBuffer: newTexCoordArray.buffer,
|
|
174
|
+
byteOffset: 0,
|
|
175
|
+
byteLength: newTexCoordArray.buffer.byteLength
|
|
176
|
+
});
|
|
177
|
+
bufferView.buffer = buffers.length - 1;
|
|
178
|
+
bufferView.byteLength = newTexCoordArray.buffer.byteLength;
|
|
179
|
+
bufferView.byteOffset = 0;
|
|
180
|
+
delete bufferView.byteStride;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
*
|
|
184
|
+
* @param newTexCoord new `texCoord` value
|
|
185
|
+
* @param originalAccessor original accessor object, that store data before transformation
|
|
186
|
+
* @param primitive primitive object
|
|
187
|
+
* @param gltfData gltf data
|
|
188
|
+
* @param newTexCoordArray typed array with data after transformation
|
|
189
|
+
* @returns
|
|
190
|
+
*/
|
|
191
|
+
function createAttribute(newTexCoord, originalAccessor, primitive, gltfData, newTexCoordArray) {
|
|
192
|
+
gltfData.buffers.push({
|
|
193
|
+
arrayBuffer: newTexCoordArray.buffer,
|
|
194
|
+
byteOffset: 0,
|
|
195
|
+
byteLength: newTexCoordArray.buffer.byteLength
|
|
196
|
+
});
|
|
197
|
+
const bufferViews = gltfData.json.bufferViews;
|
|
198
|
+
if (!bufferViews) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
bufferViews.push({
|
|
202
|
+
buffer: gltfData.buffers.length - 1,
|
|
203
|
+
byteLength: newTexCoordArray.buffer.byteLength,
|
|
204
|
+
byteOffset: 0
|
|
205
|
+
});
|
|
206
|
+
const accessors = gltfData.json.accessors;
|
|
207
|
+
if (!accessors) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
accessors.push({
|
|
211
|
+
bufferView: bufferViews?.length - 1,
|
|
212
|
+
byteOffset: 0,
|
|
213
|
+
componentType: 5126,
|
|
214
|
+
count: originalAccessor.count,
|
|
215
|
+
type: 'VEC2'
|
|
216
|
+
});
|
|
217
|
+
primitive.attributes[`TEXCOORD_${newTexCoord}`] = accessors.length - 1;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Construct transformation matrix from the extension data (transition, rotation, scale)
|
|
221
|
+
* @param extensionData extension data
|
|
222
|
+
* @returns transformation matrix
|
|
223
|
+
*/
|
|
224
|
+
function makeTransformationMatrix(extensionData) {
|
|
225
|
+
const { offset = [0, 0], rotation = 0, scale = [1, 1] } = extensionData;
|
|
226
|
+
const translationMatirx = new core_1.Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1);
|
|
227
|
+
const rotationMatirx = scratchRotationMatrix.set(Math.cos(rotation), Math.sin(rotation), 0, -Math.sin(rotation), Math.cos(rotation), 0, 0, 0, 1);
|
|
228
|
+
const scaleMatrix = scratchScaleMatrix.set(scale[0], 0, 0, 0, scale[1], 0, 0, 0, 1);
|
|
229
|
+
return translationMatirx.multiplyRight(rotationMatirx).multiplyRight(scaleMatrix);
|
|
230
|
+
}
|
|
@@ -0,0 +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,EAAC,MAAM,wBAAwB,CAAC;AAcjD,eAAO,MAAM,IAAI,yBAAuB,CAAC;AAEzC,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAGlE"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.decode = exports.name = void 0;
|
|
7
|
+
const gltf_scenegraph_1 = __importDefault(require("../../api/gltf-scenegraph"));
|
|
8
|
+
/** Extension name */
|
|
9
|
+
const EXT_FEATURE_METADATA = 'EXT_feature_metadata';
|
|
10
|
+
exports.name = EXT_FEATURE_METADATA;
|
|
11
|
+
async function decode(gltfData) {
|
|
12
|
+
const scenegraph = new gltf_scenegraph_1.default(gltfData);
|
|
13
|
+
decodeExtFeatureMetadata(scenegraph);
|
|
14
|
+
}
|
|
15
|
+
exports.decode = decode;
|
|
16
|
+
/**
|
|
17
|
+
* Decodes feature metadata from extension
|
|
18
|
+
* @param scenegraph
|
|
19
|
+
*/
|
|
20
|
+
function decodeExtFeatureMetadata(scenegraph) {
|
|
21
|
+
const extension = scenegraph.getExtension(EXT_FEATURE_METADATA);
|
|
22
|
+
const schemaClasses = extension?.schema?.classes;
|
|
23
|
+
const featureTables = extension?.featureTables;
|
|
24
|
+
const featureTextures = extension?.featureTextures;
|
|
25
|
+
if (featureTextures) {
|
|
26
|
+
/*
|
|
27
|
+
* TODO add support for featureTextures
|
|
28
|
+
* Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#feature-textures
|
|
29
|
+
*/
|
|
30
|
+
// eslint-disable-next-line no-console
|
|
31
|
+
console.warn('featureTextures is not yet supported in the "EXT_feature_metadata" extension.');
|
|
32
|
+
}
|
|
33
|
+
if (schemaClasses && featureTables) {
|
|
34
|
+
for (const schemaName in schemaClasses) {
|
|
35
|
+
const schemaClass = schemaClasses[schemaName];
|
|
36
|
+
const featureTable = findFeatureTableByName(featureTables, schemaName);
|
|
37
|
+
if (featureTable) {
|
|
38
|
+
handleFeatureTableProperties(scenegraph, featureTable, schemaClass);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Navigate throw all properies in feature table and gets properties data.
|
|
45
|
+
* @param scenegraph
|
|
46
|
+
* @param featureTable
|
|
47
|
+
* @param schemaClass
|
|
48
|
+
*/
|
|
49
|
+
function handleFeatureTableProperties(scenegraph, featureTable, schemaClass) {
|
|
50
|
+
for (const propertyName in schemaClass.properties) {
|
|
51
|
+
const schemaProperty = schemaClass.properties[propertyName];
|
|
52
|
+
const featureTableProperty = featureTable?.properties?.[propertyName];
|
|
53
|
+
const numberOfFeatures = featureTable.count;
|
|
54
|
+
if (featureTableProperty) {
|
|
55
|
+
const data = getPropertyDataFromBinarySource(scenegraph, schemaProperty, numberOfFeatures, featureTableProperty);
|
|
56
|
+
featureTableProperty.data = data;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Decode properties from binary sourse based on property type.
|
|
62
|
+
* @param scenegraph
|
|
63
|
+
* @param schemaProperty
|
|
64
|
+
* @param numberOfFeatures
|
|
65
|
+
* @param featureTableProperty
|
|
66
|
+
*/
|
|
67
|
+
function getPropertyDataFromBinarySource(scenegraph, schemaProperty, numberOfFeatures, featureTableProperty) {
|
|
68
|
+
const bufferView = featureTableProperty.bufferView;
|
|
69
|
+
// TODO think maybe we shouldn't get data only in Uint8Array format.
|
|
70
|
+
let data = scenegraph.getTypedArrayForBufferView(bufferView);
|
|
71
|
+
switch (schemaProperty.type) {
|
|
72
|
+
case 'STRING': {
|
|
73
|
+
// stringOffsetBufferView should be available for string type.
|
|
74
|
+
const stringOffsetBufferView = featureTableProperty.stringOffsetBufferView;
|
|
75
|
+
const offsetsData = scenegraph.getTypedArrayForBufferView(stringOffsetBufferView);
|
|
76
|
+
data = getStringAttributes(data, offsetsData, numberOfFeatures);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
default:
|
|
80
|
+
}
|
|
81
|
+
return data;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Find the feature table by class name.
|
|
85
|
+
* @param featureTables
|
|
86
|
+
* @param schemaClassName
|
|
87
|
+
*/
|
|
88
|
+
function findFeatureTableByName(featureTables, schemaClassName) {
|
|
89
|
+
for (const featureTableName in featureTables) {
|
|
90
|
+
const featureTable = featureTables[featureTableName];
|
|
91
|
+
if (featureTable.class === schemaClassName) {
|
|
92
|
+
return featureTable;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Getting string attributes from binary data.
|
|
99
|
+
* Spec - https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata#strings
|
|
100
|
+
* @param data
|
|
101
|
+
* @param offsetsData
|
|
102
|
+
* @param stringsCount
|
|
103
|
+
*/
|
|
104
|
+
function getStringAttributes(data, offsetsData, stringsCount) {
|
|
105
|
+
const stringsArray = [];
|
|
106
|
+
const textDecoder = new TextDecoder('utf8');
|
|
107
|
+
let stringOffset = 0;
|
|
108
|
+
const bytesPerStringSize = 4;
|
|
109
|
+
for (let index = 0; index < stringsCount; index++) {
|
|
110
|
+
// TODO check if it is multiplication on bytesPerStringSize is valid operation?
|
|
111
|
+
const stringByteSize = offsetsData[(index + 1) * bytesPerStringSize] - offsetsData[index * bytesPerStringSize];
|
|
112
|
+
const stringData = data.subarray(stringOffset, stringByteSize + stringOffset);
|
|
113
|
+
const stringAttribute = textDecoder.decode(stringData);
|
|
114
|
+
stringsArray.push(stringAttribute);
|
|
115
|
+
stringOffset += stringByteSize;
|
|
116
|
+
}
|
|
117
|
+
return stringsArray;
|
|
118
|
+
}
|
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
export declare const COMPONENTS: {
|
|
2
|
+
SCALAR: number;
|
|
3
|
+
VEC2: number;
|
|
4
|
+
VEC3: number;
|
|
5
|
+
VEC4: number;
|
|
6
|
+
MAT2: number;
|
|
7
|
+
MAT3: number;
|
|
8
|
+
MAT4: number;
|
|
9
|
+
};
|
|
10
|
+
export declare const BYTES: {
|
|
11
|
+
5120: number;
|
|
12
|
+
5121: number;
|
|
13
|
+
5122: number;
|
|
14
|
+
5123: number;
|
|
15
|
+
5125: number;
|
|
16
|
+
5126: number;
|
|
17
|
+
};
|
|
1
18
|
export declare function getBytesFromComponentType(componentType: any): any;
|
|
2
19
|
export declare function getSizeFromAccessorType(type: any): any;
|
|
3
20
|
export declare function getGLEnumFromSamplerParameter(parameter: any): any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gltf-constants.d.ts","sourceRoot":"","sources":["../../../src/lib/gltf-utils/gltf-constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"gltf-constants.d.ts","sourceRoot":"","sources":["../../../src/lib/gltf-utils/gltf-constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU;;;;;;;;CAQtB,CAAC;AAEF,eAAO,MAAM,KAAK;;;;;;;CAOjB,CAAC;AAIF,wBAAgB,yBAAyB,CAAC,aAAa,KAAA,OAEtD;AAED,wBAAgB,uBAAuB,CAAC,IAAI,KAAA,OAE3C;AAED,wBAAgB,6BAA6B,CAAC,SAAS,KAAA,OActD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getGLEnumFromSamplerParameter = exports.getSizeFromAccessorType = exports.getBytesFromComponentType = void 0;
|
|
4
|
-
|
|
3
|
+
exports.getGLEnumFromSamplerParameter = exports.getSizeFromAccessorType = exports.getBytesFromComponentType = exports.BYTES = exports.COMPONENTS = void 0;
|
|
4
|
+
exports.COMPONENTS = {
|
|
5
5
|
SCALAR: 1,
|
|
6
6
|
VEC2: 2,
|
|
7
7
|
VEC3: 3,
|
|
@@ -10,7 +10,7 @@ const COMPONENTS = {
|
|
|
10
10
|
MAT3: 9,
|
|
11
11
|
MAT4: 16
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
exports.BYTES = {
|
|
14
14
|
5120: 1,
|
|
15
15
|
5121: 1,
|
|
16
16
|
5122: 2,
|
|
@@ -20,11 +20,11 @@ const BYTES = {
|
|
|
20
20
|
};
|
|
21
21
|
// ENUM LOOKUP
|
|
22
22
|
function getBytesFromComponentType(componentType) {
|
|
23
|
-
return BYTES[componentType];
|
|
23
|
+
return exports.BYTES[componentType];
|
|
24
24
|
}
|
|
25
25
|
exports.getBytesFromComponentType = getBytesFromComponentType;
|
|
26
26
|
function getSizeFromAccessorType(type) {
|
|
27
|
-
return COMPONENTS[type];
|
|
27
|
+
return exports.COMPONENTS[type];
|
|
28
28
|
}
|
|
29
29
|
exports.getSizeFromAccessorType = getSizeFromAccessorType;
|
|
30
30
|
function getGLEnumFromSamplerParameter(parameter) {
|