@loaders.gl/gltf 4.0.0-alpha.24 → 4.0.0-alpha.25
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 +237 -146
- package/dist/es5/index.js +12 -0
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/api/gltf-extensions.js +1 -1
- package/dist/es5/lib/api/gltf-extensions.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_mesh_features.js +12 -24
- package/dist/es5/lib/extensions/EXT_mesh_features.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_structural_metadata.js +72 -28
- package/dist/es5/lib/extensions/EXT_structural_metadata.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +38 -3
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
- package/dist/es5/lib/extensions/utils/3d-tiles-utils.js +26 -18
- package/dist/es5/lib/extensions/utils/3d-tiles-utils.js.map +1 -1
- package/dist/es5/lib/gltf-utils/gltf-utils.js +29 -0
- package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -1
- package/dist/es5/lib/types/gltf-ext-feature-metadata-schema.js +2 -0
- package/dist/es5/lib/types/gltf-ext-feature-metadata-schema.js.map +1 -0
- package/dist/es5/lib/types/gltf-ext-mesh-features-schema.js.map +1 -1
- package/dist/es5/lib/types/gltf-ext-structural-metadata-schema.js.map +1 -1
- package/dist/es5/lib/types/gltf-json-schema.js.map +1 -1
- package/dist/es5/lib/types/gltf-types.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/api/gltf-extensions.js +1 -1
- package/dist/esm/lib/api/gltf-extensions.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_mesh_features.js +13 -25
- package/dist/esm/lib/extensions/EXT_mesh_features.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_structural_metadata.js +48 -14
- package/dist/esm/lib/extensions/EXT_structural_metadata.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js +38 -4
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
- package/dist/esm/lib/extensions/utils/3d-tiles-utils.js +27 -19
- package/dist/esm/lib/extensions/utils/3d-tiles-utils.js.map +1 -1
- package/dist/esm/lib/gltf-utils/gltf-utils.js +30 -0
- package/dist/esm/lib/gltf-utils/gltf-utils.js.map +1 -1
- package/dist/esm/lib/types/gltf-ext-feature-metadata-schema.js +2 -0
- package/dist/esm/lib/types/gltf-ext-feature-metadata-schema.js.map +1 -0
- package/dist/esm/lib/types/gltf-ext-mesh-features-schema.js.map +1 -1
- package/dist/esm/lib/types/gltf-ext-structural-metadata-schema.js.map +1 -1
- package/dist/esm/lib/types/gltf-json-schema.js.map +1 -1
- package/dist/esm/lib/types/gltf-types.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_mesh_features.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_structural_metadata.d.ts +9 -1
- package/dist/lib/extensions/EXT_structural_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +9 -0
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/utils/3d-tiles-utils.d.ts +12 -12
- package/dist/lib/extensions/utils/3d-tiles-utils.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-utils.d.ts +2 -0
- package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts +421 -0
- package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts.map +1 -0
- package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts +4 -6
- package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts +44 -25
- package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-json-schema.d.ts +1 -420
- package/dist/lib/types/gltf-json-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-types.d.ts +3 -0
- package/dist/lib/types/gltf-types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +10 -5
- package/src/lib/api/gltf-extensions.ts +1 -1
- package/src/lib/extensions/EXT_mesh_features.ts +18 -44
- package/src/lib/extensions/EXT_structural_metadata.ts +176 -96
- package/src/lib/extensions/deprecated/EXT_feature_metadata.ts +70 -11
- package/src/lib/extensions/utils/3d-tiles-utils.ts +50 -39
- package/src/lib/gltf-utils/gltf-utils.ts +38 -0
- package/src/lib/types/gltf-ext-feature-metadata-schema.ts +470 -0
- package/src/lib/types/gltf-ext-mesh-features-schema.ts +4 -6
- package/src/lib/types/gltf-ext-structural-metadata-schema.ts +46 -27
- package/src/lib/types/gltf-json-schema.ts +1 -468
- package/src/lib/types/gltf-types.ts +4 -0
|
@@ -12,7 +12,7 @@ import type {BigTypedArray, TypedArray} from '@loaders.gl/schema';
|
|
|
12
12
|
import type {ImageType} from '@loaders.gl/images';
|
|
13
13
|
|
|
14
14
|
import {GLTFScenegraph} from '../../api/gltf-scenegraph';
|
|
15
|
-
import {getComponentTypeFromArray} from '../../gltf-utils/gltf-utils';
|
|
15
|
+
import {getComponentTypeFromArray, getFloat32ArrayForAccessor} from '../../gltf-utils/gltf-utils';
|
|
16
16
|
import {getImageData} from '@loaders.gl/images';
|
|
17
17
|
import {emod} from '@loaders.gl/math';
|
|
18
18
|
|
|
@@ -80,7 +80,7 @@ export function getArrayElementByteSize(attributeType, componentType): number {
|
|
|
80
80
|
* @param bufferViewIndex - Buffer view index
|
|
81
81
|
* @param offsetType - The type of values in `arrayOffsets` or `stringOffsets`.
|
|
82
82
|
* @param numberOfElements - The number of elements in each property array.
|
|
83
|
-
* @returns
|
|
83
|
+
* @returns Array of values offsets. The number of offsets in the array is equal to `numberOfElements` plus one.
|
|
84
84
|
*/
|
|
85
85
|
export function getOffsetsForProperty(
|
|
86
86
|
scenegraph: GLTFScenegraph,
|
|
@@ -113,10 +113,10 @@ export function getOffsetsForProperty(
|
|
|
113
113
|
|
|
114
114
|
/**
|
|
115
115
|
* Converts raw bytes that are in the buffer to an array of the type defined by the schema.
|
|
116
|
-
* @param data -
|
|
117
|
-
* @param attributeType - SCALAR, VECN, MATN
|
|
118
|
-
* @param componentType -
|
|
119
|
-
* @param elementCount -
|
|
116
|
+
* @param data - Raw bytes in the buffer.
|
|
117
|
+
* @param attributeType - SCALAR, VECN, MATN.
|
|
118
|
+
* @param componentType - Type of the component in elements, e.g. 'UINT8' or 'FLOAT32'.
|
|
119
|
+
* @param elementCount - Number of elements in the array. Default value is 1.
|
|
120
120
|
* @returns Data array
|
|
121
121
|
*/
|
|
122
122
|
export function convertRawBufferToMetadataArray(
|
|
@@ -144,8 +144,8 @@ export function convertRawBufferToMetadataArray(
|
|
|
144
144
|
* Processes data encoded in the texture associated with the primitive.
|
|
145
145
|
* If Ext_mesh_featues is combined with the Ext_structural_metadata, propertyTable will also be processed.
|
|
146
146
|
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
147
|
-
* @param textureInfo -
|
|
148
|
-
* @param primitive -
|
|
147
|
+
* @param textureInfo - Reference to the texture where extension data are stored.
|
|
148
|
+
* @param primitive - Primitive object in the mesh.
|
|
149
149
|
* @returns Array of data taken. Null if data can't be taken from the texture.
|
|
150
150
|
*/
|
|
151
151
|
export function getPrimitiveTextureData(
|
|
@@ -170,15 +170,14 @@ export function getPrimitiveTextureData(
|
|
|
170
170
|
|
|
171
171
|
const texCoordAccessorKey = `TEXCOORD_${textureInfo.texCoord || 0}`;
|
|
172
172
|
const texCoordAccessorIndex = primitive.attributes[texCoordAccessorKey];
|
|
173
|
-
const texCoordBufferView = scenegraph.getBufferView(texCoordAccessorIndex);
|
|
174
|
-
const texCoordArray: Uint8Array = scenegraph.getTypedArrayForBufferView(texCoordBufferView);
|
|
175
173
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
texCoordArray.byteOffset,
|
|
180
|
-
texCoordArray.length / 4
|
|
174
|
+
const textureCoordinates: Float32Array | null = getFloat32ArrayForAccessor(
|
|
175
|
+
scenegraph.gltf,
|
|
176
|
+
texCoordAccessorIndex
|
|
181
177
|
);
|
|
178
|
+
if (!textureCoordinates) {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
182
181
|
|
|
183
182
|
const textureIndex: number = textureInfo.index;
|
|
184
183
|
const imageIndex = json.textures?.[textureIndex]?.source;
|
|
@@ -208,11 +207,11 @@ export function getPrimitiveTextureData(
|
|
|
208
207
|
* Puts property data to attributes.
|
|
209
208
|
* It creates corresponding buffer, bufferView and accessor
|
|
210
209
|
* so the data can be accessed like regular data stored in buffers.
|
|
211
|
-
* @param scenegraph -
|
|
212
|
-
* @param attributeName -
|
|
213
|
-
* @param propertyData -
|
|
214
|
-
* @param featureTable -
|
|
215
|
-
* @param primitive -
|
|
210
|
+
* @param scenegraph - Scenegraph object.
|
|
211
|
+
* @param attributeName - Name of the attribute.
|
|
212
|
+
* @param propertyData - Property data to store.
|
|
213
|
+
* @param featureTable - Array where unique data from the property data are being stored.
|
|
214
|
+
* @param primitive - Primitive object.
|
|
216
215
|
*/
|
|
217
216
|
export function primitivePropertyDataToAttributes(
|
|
218
217
|
scenegraph: GLTFScenegraph,
|
|
@@ -221,7 +220,10 @@ export function primitivePropertyDataToAttributes(
|
|
|
221
220
|
featureTable: number[],
|
|
222
221
|
primitive: GLTFMeshPrimitive
|
|
223
222
|
): void {
|
|
224
|
-
if
|
|
223
|
+
// No reason to create an empty buffer if there is no property data to store.
|
|
224
|
+
if (!propertyData?.length) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
225
227
|
/*
|
|
226
228
|
featureTable will contain unique values, e.g.
|
|
227
229
|
propertyData = [24, 35, 28, 24]
|
|
@@ -255,11 +257,11 @@ export function primitivePropertyDataToAttributes(
|
|
|
255
257
|
|
|
256
258
|
/**
|
|
257
259
|
* Gets the value from the texture by coordinates provided.
|
|
258
|
-
* @param parsedImage -
|
|
259
|
-
* @param mimeType - MIME type
|
|
260
|
+
* @param parsedImage - Image where the data are stored.
|
|
261
|
+
* @param mimeType - MIME type.
|
|
260
262
|
* @param textureCoordinates - uv coordinates to access data in the image.
|
|
261
|
-
* @param index -
|
|
262
|
-
* @param channels -
|
|
263
|
+
* @param index - Index of uv coordinates in the array textureCoordinates.
|
|
264
|
+
* @param channels - Image channels where data are stored. Channels of an RGBA texture are numbered 0..3 respectively.
|
|
263
265
|
* @returns Value taken from the image.
|
|
264
266
|
*/
|
|
265
267
|
function getImageValueByCoordinates(
|
|
@@ -267,14 +269,14 @@ function getImageValueByCoordinates(
|
|
|
267
269
|
mimeType: string | undefined,
|
|
268
270
|
textureCoordinates: Float32Array,
|
|
269
271
|
index: number,
|
|
270
|
-
channels: number[] = [0]
|
|
272
|
+
channels: number[] | string = [0]
|
|
271
273
|
) {
|
|
272
|
-
const CHANNELS_MAP =
|
|
273
|
-
{offset: 0, shift: 0},
|
|
274
|
-
{offset: 1, shift: 8},
|
|
275
|
-
{offset: 2, shift: 16},
|
|
276
|
-
{offset: 3, shift: 24}
|
|
277
|
-
|
|
274
|
+
const CHANNELS_MAP = {
|
|
275
|
+
r: {offset: 0, shift: 0},
|
|
276
|
+
g: {offset: 1, shift: 8},
|
|
277
|
+
b: {offset: 2, shift: 16},
|
|
278
|
+
a: {offset: 3, shift: 24}
|
|
279
|
+
};
|
|
278
280
|
|
|
279
281
|
const u = textureCoordinates[index];
|
|
280
282
|
const v = textureCoordinates[index + 1];
|
|
@@ -285,7 +287,16 @@ function getImageValueByCoordinates(
|
|
|
285
287
|
const offset = coordinatesToOffset(u, v, parsedImage, components);
|
|
286
288
|
let value: number = 0;
|
|
287
289
|
for (const c of channels) {
|
|
288
|
-
|
|
290
|
+
/*
|
|
291
|
+
According to the EXT_feature_metadata extension specification:
|
|
292
|
+
Channels are labeled by rgba and are swizzled with a string of 1-4 characters.
|
|
293
|
+
According to the EXT_mesh_features extension specification:
|
|
294
|
+
The channels array contains non-negative integer values corresponding to channels of the source texture that the feature ID consists of.
|
|
295
|
+
Channels of an RGBA texture are numbered 0–3 respectively.
|
|
296
|
+
Function getImageValueByCoordinates is used to process both extensions.
|
|
297
|
+
So, there should be possible to get the element of CHANNELS_MAP by either index (0, 1, 2, 3) or key (r, g, b, a).
|
|
298
|
+
*/
|
|
299
|
+
const map = typeof c === 'number' ? Object.values(CHANNELS_MAP)[c] : CHANNELS_MAP[c];
|
|
289
300
|
const imageOffset = offset + map.offset;
|
|
290
301
|
const imageData = getImageData(parsedImage);
|
|
291
302
|
if (imageData.data.length <= imageOffset) {
|
|
@@ -298,12 +309,12 @@ function getImageValueByCoordinates(
|
|
|
298
309
|
}
|
|
299
310
|
|
|
300
311
|
/**
|
|
301
|
-
* Retrieves the offset in the image where the data are stored
|
|
302
|
-
* @param u - u-coordinate
|
|
303
|
-
* @param v - v-coordinate
|
|
304
|
-
* @param parsedImage -
|
|
305
|
-
* @param componentsCount -
|
|
306
|
-
* @returns
|
|
312
|
+
* Retrieves the offset in the image where the data are stored.
|
|
313
|
+
* @param u - u-coordinate.
|
|
314
|
+
* @param v - v-coordinate.
|
|
315
|
+
* @param parsedImage - Image where the data are stored.
|
|
316
|
+
* @param componentsCount - Number of components the data consists of.
|
|
317
|
+
* @returns Offset in the image where the data are stored.
|
|
307
318
|
*/
|
|
308
319
|
function coordinatesToOffset(
|
|
309
320
|
u: number,
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import {assert} from '../utils/assert';
|
|
2
|
+
|
|
3
|
+
import type {GLTFWithBuffers} from '../types/gltf-types';
|
|
2
4
|
import type {GLTFPostprocessed} from '../types/gltf-postprocessed-schema';
|
|
5
|
+
import {BYTES, COMPONENTS} from '../gltf-utils/gltf-constants';
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* Memory needed to store texture and all mipmap levels 1 + 1/4 + 1/16 + 1/64 + ...
|
|
@@ -85,6 +88,41 @@ export function getAccessorArrayTypeAndLength(accessor, bufferView) {
|
|
|
85
88
|
return {ArrayType, length, byteLength};
|
|
86
89
|
}
|
|
87
90
|
|
|
91
|
+
export function getFloat32ArrayForAccessor(
|
|
92
|
+
gltfData: GLTFWithBuffers,
|
|
93
|
+
texCoordAccessor: number
|
|
94
|
+
): Float32Array | null {
|
|
95
|
+
const accessor = gltfData.json.accessors?.[texCoordAccessor];
|
|
96
|
+
if (accessor && typeof accessor.bufferView !== 'undefined') {
|
|
97
|
+
// Get `bufferView` of the `accessor`
|
|
98
|
+
const bufferView = gltfData.json.bufferViews?.[accessor.bufferView];
|
|
99
|
+
if (bufferView) {
|
|
100
|
+
// Get `arrayBuffer` the `bufferView` look at
|
|
101
|
+
const {arrayBuffer, byteOffset: bufferByteOffset} = gltfData.buffers[bufferView.buffer];
|
|
102
|
+
// Resulting byteOffset is sum of the buffer, accessor and bufferView byte offsets
|
|
103
|
+
const byteOffset =
|
|
104
|
+
(bufferByteOffset || 0) + (accessor.byteOffset || 0) + (bufferView.byteOffset || 0);
|
|
105
|
+
// Deduce TypedArray type and its length from `accessor` and `bufferView` data
|
|
106
|
+
const {ArrayType, length} = getAccessorArrayTypeAndLength(accessor, bufferView);
|
|
107
|
+
// Number of bytes each component occupies
|
|
108
|
+
const bytes = BYTES[accessor.componentType];
|
|
109
|
+
// Number of components. For the `TEXCOORD_0` with `VEC2` type, it must return 2
|
|
110
|
+
const components = COMPONENTS[accessor.type];
|
|
111
|
+
// Multiplier to calculate the address of the `TEXCOORD_0` element in the arrayBuffer
|
|
112
|
+
const elementAddressScale = bufferView.byteStride || bytes * components;
|
|
113
|
+
// Data transform to Float32Array
|
|
114
|
+
const result = new Float32Array(length);
|
|
115
|
+
for (let i = 0; i < accessor.count; i++) {
|
|
116
|
+
// Take [u, v] couple from the arrayBuffer
|
|
117
|
+
const uv = new ArrayType(arrayBuffer, byteOffset + i * elementAddressScale, 2);
|
|
118
|
+
result.set(uv, i * components);
|
|
119
|
+
}
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
|
|
88
126
|
/**
|
|
89
127
|
* Calculate the GPU memory used by a GLTF tile, for both buffer and texture memory
|
|
90
128
|
* @param gltf - the gltf content of a GLTF tile
|