@loaders.gl/gltf 4.2.0-alpha.4 → 4.2.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +1049 -517
- package/dist/dist.min.js +9 -0
- package/dist/glb-loader.d.ts +2 -2
- package/dist/glb-loader.d.ts.map +1 -1
- package/dist/glb-loader.js +22 -21
- package/dist/glb-writer.d.ts +2 -2
- package/dist/glb-writer.d.ts.map +1 -1
- package/dist/glb-writer.js +27 -24
- package/dist/gltf-loader.d.ts +3 -3
- package/dist/gltf-loader.d.ts.map +1 -1
- package/dist/gltf-loader.js +31 -36
- package/dist/gltf-writer.js +24 -26
- package/dist/index.cjs +95 -284
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +17 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/api/gltf-extensions.d.ts +2 -2
- package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
- package/dist/lib/api/gltf-extensions.js +45 -22
- package/dist/lib/api/gltf-scenegraph.d.ts +2 -2
- package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
- package/dist/lib/api/gltf-scenegraph.js +561 -438
- package/dist/lib/api/normalize-gltf-v1.js +250 -181
- package/dist/lib/api/post-process-gltf.d.ts +3 -3
- package/dist/lib/api/post-process-gltf.d.ts.map +1 -1
- package/dist/lib/api/post-process-gltf.js +375 -339
- package/dist/lib/encoders/encode-glb.js +62 -48
- package/dist/lib/encoders/encode-gltf.js +24 -10
- package/dist/lib/extensions/EXT_mesh_features.d.ts +2 -2
- package/dist/lib/extensions/EXT_mesh_features.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_mesh_features.js +55 -33
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts +2 -2
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_meshopt_compression.js +27 -31
- package/dist/lib/extensions/EXT_structural_metadata.d.ts +2 -2
- package/dist/lib/extensions/EXT_structural_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_structural_metadata.js +434 -230
- package/dist/lib/extensions/EXT_texture_webp.d.ts +2 -2
- package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_texture_webp.js +24 -17
- package/dist/lib/extensions/KHR_binary_gltf.d.ts +1 -1
- package/dist/lib/extensions/KHR_binary_gltf.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_binary_gltf.js +29 -15
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +2 -2
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.js +110 -87
- package/dist/lib/extensions/KHR_texture_basisu.d.ts +2 -2
- package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_basisu.js +19 -12
- package/dist/lib/extensions/KHR_texture_transform.d.ts +2 -2
- package/dist/lib/extensions/KHR_texture_transform.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_transform.js +194 -154
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +2 -2
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +263 -143
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +44 -32
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +30 -24
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +65 -52
- package/dist/lib/extensions/utils/3d-tiles-utils.d.ts +2 -2
- package/dist/lib/extensions/utils/3d-tiles-utils.d.ts.map +1 -1
- package/dist/lib/extensions/utils/3d-tiles-utils.js +298 -181
- package/dist/lib/gltf-utils/get-typed-array.d.ts +1 -1
- package/dist/lib/gltf-utils/get-typed-array.d.ts.map +1 -1
- package/dist/lib/gltf-utils/get-typed-array.js +54 -42
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts +1 -1
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-attribute-utils.js +58 -52
- package/dist/lib/gltf-utils/gltf-constants.js +27 -27
- package/dist/lib/gltf-utils/gltf-utils.d.ts +1 -1
- package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-utils.js +67 -60
- package/dist/lib/gltf-utils/resolve-url.js +12 -10
- package/dist/lib/parsers/parse-glb.d.ts +1 -1
- package/dist/lib/parsers/parse-glb.d.ts.map +1 -1
- package/dist/lib/parsers/parse-glb.js +132 -89
- package/dist/lib/parsers/parse-gltf.d.ts +3 -3
- package/dist/lib/parsers/parse-gltf.d.ts.map +1 -1
- package/dist/lib/parsers/parse-gltf.js +155 -126
- package/dist/lib/types/glb-types.js +0 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts +1 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.js +0 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts +1 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.js +0 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts +1 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.js +0 -1
- package/dist/lib/types/gltf-json-schema.js +2 -1
- package/dist/lib/types/gltf-postprocessed-schema.js +2 -1
- package/dist/lib/types/gltf-types.d.ts +3 -3
- package/dist/lib/types/gltf-types.d.ts.map +1 -1
- package/dist/lib/types/gltf-types.js +1 -1
- package/dist/lib/utils/assert.js +6 -4
- package/dist/lib/utils/version.js +3 -1
- package/dist/meshopt/meshopt-decoder.js +86 -67
- package/dist/webp/webp.js +28 -19
- package/package.json +12 -8
- package/dist/glb-loader.js.map +0 -1
- package/dist/glb-writer.js.map +0 -1
- package/dist/gltf-loader.js.map +0 -1
- package/dist/gltf-writer.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/api/gltf-extensions.js.map +0 -1
- package/dist/lib/api/gltf-scenegraph.js.map +0 -1
- package/dist/lib/api/normalize-gltf-v1.js.map +0 -1
- package/dist/lib/api/post-process-gltf.js.map +0 -1
- package/dist/lib/encoders/encode-glb.js.map +0 -1
- package/dist/lib/encoders/encode-gltf.js.map +0 -1
- package/dist/lib/extensions/EXT_mesh_features.js.map +0 -1
- package/dist/lib/extensions/EXT_meshopt_compression.js.map +0 -1
- package/dist/lib/extensions/EXT_structural_metadata.js.map +0 -1
- package/dist/lib/extensions/EXT_texture_webp.js.map +0 -1
- package/dist/lib/extensions/KHR_binary_gltf.js.map +0 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.js.map +0 -1
- package/dist/lib/extensions/KHR_texture_basisu.js.map +0 -1
- package/dist/lib/extensions/KHR_texture_transform.js.map +0 -1
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.js.map +0 -1
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.js.map +0 -1
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.js.map +0 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js.map +0 -1
- package/dist/lib/extensions/utils/3d-tiles-utils.js.map +0 -1
- package/dist/lib/gltf-utils/get-typed-array.js.map +0 -1
- package/dist/lib/gltf-utils/gltf-attribute-utils.js.map +0 -1
- package/dist/lib/gltf-utils/gltf-constants.js.map +0 -1
- package/dist/lib/gltf-utils/gltf-utils.js.map +0 -1
- package/dist/lib/gltf-utils/resolve-url.js.map +0 -1
- package/dist/lib/parsers/parse-glb.js.map +0 -1
- package/dist/lib/parsers/parse-gltf.js.map +0 -1
- package/dist/lib/types/glb-types.js.map +0 -1
- package/dist/lib/types/gltf-ext-feature-metadata-schema.js.map +0 -1
- package/dist/lib/types/gltf-ext-mesh-features-schema.js.map +0 -1
- package/dist/lib/types/gltf-ext-structural-metadata-schema.js.map +0 -1
- package/dist/lib/types/gltf-json-schema.js.map +0 -1
- package/dist/lib/types/gltf-postprocessed-schema.js.map +0 -1
- package/dist/lib/types/gltf-types.js.map +0 -1
- package/dist/lib/utils/assert.js.map +0 -1
- package/dist/lib/utils/version.js.map +0 -1
- package/dist/meshopt/meshopt-decoder.js.map +0 -1
- package/dist/meshopt/meshopt-encoder.ts.disabled +0 -409
- package/dist/webp/webp.js.map +0 -1
|
@@ -3,280 +3,484 @@ import { convertRawBufferToMetadataArray, getPrimitiveTextureData, primitiveProp
|
|
|
3
3
|
const EXT_STRUCTURAL_METADATA_NAME = 'EXT_structural_metadata';
|
|
4
4
|
export const name = EXT_STRUCTURAL_METADATA_NAME;
|
|
5
5
|
export async function decode(gltfData, options) {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
7
|
+
decodeExtStructuralMetadata(scenegraph, options);
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
/*
|
|
10
|
+
// Example of the extension.
|
|
11
|
+
// See more info at https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata
|
|
12
|
+
const extensions = {
|
|
13
|
+
"extensions": {
|
|
14
|
+
"EXT_structural_metadata": {
|
|
15
|
+
"schema": {
|
|
16
|
+
"classes": {
|
|
17
|
+
"tree": {
|
|
18
|
+
"name": "Tree",
|
|
19
|
+
"description": "Woody, perennial plant.",
|
|
20
|
+
"properties": {
|
|
21
|
+
"species": {
|
|
22
|
+
"description": "Type of tree.",
|
|
23
|
+
"type": "ENUM",
|
|
24
|
+
"enumType": "speciesEnum",
|
|
25
|
+
"required": true
|
|
26
|
+
},
|
|
27
|
+
"age": {
|
|
28
|
+
"description": "The age of the tree, in years",
|
|
29
|
+
"type": "SCALAR",
|
|
30
|
+
"componentType": "UINT8",
|
|
31
|
+
"required": true
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"enums": {
|
|
37
|
+
"speciesEnum": {
|
|
38
|
+
"name": "Species",
|
|
39
|
+
"description": "An example enum for tree species.",
|
|
40
|
+
// valueType is not defined here. Default is "UINT16"
|
|
41
|
+
"values": [
|
|
42
|
+
{ "name": "Unspecified", "value": 0 },
|
|
43
|
+
{ "name": "Oak", "value": 1 }
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"propertyTables": [{
|
|
49
|
+
"name": "tree_survey_2021-09-29",
|
|
50
|
+
"class": "tree",
|
|
51
|
+
"count": 10, // The number of elements in each property array (in `species`, in `age`).
|
|
52
|
+
"properties": {
|
|
53
|
+
"species": {
|
|
54
|
+
"values": 0, // It's an index of the buffer view containing property values.
|
|
55
|
+
},
|
|
56
|
+
"age": {
|
|
57
|
+
"values": 1
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}]
|
|
61
|
+
}
|
|
20
62
|
}
|
|
21
|
-
decodePropertyTables(scenegraph, extension);
|
|
22
63
|
}
|
|
64
|
+
*/
|
|
65
|
+
/**
|
|
66
|
+
* Decodes feature metadata from extension.
|
|
67
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
68
|
+
* @param options - GLTFLoader options.
|
|
69
|
+
*/
|
|
70
|
+
function decodeExtStructuralMetadata(scenegraph, options) {
|
|
71
|
+
// Decoding metadata involves buffers processing.
|
|
72
|
+
// So, if buffers have not been loaded, there is no reason to process metadata.
|
|
73
|
+
if (!options.gltf?.loadBuffers) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME);
|
|
77
|
+
if (!extension) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (options.gltf?.loadImages) {
|
|
81
|
+
decodePropertyTextures(scenegraph, extension);
|
|
82
|
+
}
|
|
83
|
+
decodePropertyTables(scenegraph, extension);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Processes the data stored in the textures
|
|
87
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
88
|
+
* @param extension - Top-level extension.
|
|
89
|
+
*/
|
|
23
90
|
function decodePropertyTextures(scenegraph, extension) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
91
|
+
const propertyTextures = extension.propertyTextures;
|
|
92
|
+
const json = scenegraph.gltf.json;
|
|
93
|
+
if (propertyTextures && json.meshes) {
|
|
94
|
+
// Iterate through all meshes/primitives.
|
|
95
|
+
for (const mesh of json.meshes) {
|
|
96
|
+
for (const primitive of mesh.primitives) {
|
|
97
|
+
processPrimitivePropertyTextures(scenegraph, propertyTextures, primitive, extension);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
31
100
|
}
|
|
32
|
-
}
|
|
33
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Processes the data stored in the property tables.
|
|
104
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
105
|
+
* @param extension - Top-level extension.
|
|
106
|
+
*/
|
|
34
107
|
function decodePropertyTables(scenegraph, extension) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
108
|
+
const schema = extension.schema;
|
|
109
|
+
if (!schema) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const schemaClasses = schema.classes;
|
|
113
|
+
const propertyTables = extension.propertyTables;
|
|
114
|
+
if (schemaClasses && propertyTables) {
|
|
115
|
+
for (const schemaName in schemaClasses) {
|
|
116
|
+
const propertyTable = findPropertyTableByClass(propertyTables, schemaName);
|
|
117
|
+
if (propertyTable) {
|
|
118
|
+
processPropertyTable(scenegraph, schema, propertyTable);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
47
121
|
}
|
|
48
|
-
}
|
|
49
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Finds the property table by class name.
|
|
125
|
+
* @param propertyTables - propertyTable definition taken from the top-level extension.
|
|
126
|
+
* @param schemaClassName - class name in the extension schema.
|
|
127
|
+
*/
|
|
50
128
|
function findPropertyTableByClass(propertyTables, schemaClassName) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
129
|
+
for (const propertyTable of propertyTables) {
|
|
130
|
+
if (propertyTable.class === schemaClassName) {
|
|
131
|
+
return propertyTable;
|
|
132
|
+
}
|
|
54
133
|
}
|
|
55
|
-
|
|
56
|
-
return null;
|
|
134
|
+
return null;
|
|
57
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Takes data from property textures reffered by the primitive.
|
|
138
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
139
|
+
* @param propertyTextures - propertyTexture definition taken from the top-level extention.
|
|
140
|
+
* @param primitive - Primitive object.
|
|
141
|
+
* @param extension - Top-level extension.
|
|
142
|
+
*/
|
|
58
143
|
function processPrimitivePropertyTextures(scenegraph, propertyTextures, primitive, extension) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
144
|
+
if (!propertyTextures) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const primitiveExtension = primitive.extensions?.[EXT_STRUCTURAL_METADATA_NAME];
|
|
148
|
+
const primitivePropertyTextureIndices = primitiveExtension?.propertyTextures;
|
|
149
|
+
if (!primitivePropertyTextureIndices) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
for (const primitivePropertyTextureIndex of primitivePropertyTextureIndices) {
|
|
153
|
+
const propertyTexture = propertyTextures[primitivePropertyTextureIndex];
|
|
154
|
+
processPrimitivePropertyTexture(scenegraph, propertyTexture, primitive, extension);
|
|
155
|
+
}
|
|
72
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Takes property data from the texture pointed by the primitive and appends them to `exension.data`.
|
|
159
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
160
|
+
* @param propertyTexture - propertyTexture definition taken from the top-level extension.
|
|
161
|
+
* @param primitive - Primitive object.
|
|
162
|
+
* @param extension - Top-level extension.
|
|
163
|
+
*/
|
|
73
164
|
function processPrimitivePropertyTexture(scenegraph, propertyTexture, primitive, extension) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
if (!extension.dataAttributeNames) {
|
|
78
|
-
extension.dataAttributeNames = [];
|
|
79
|
-
}
|
|
80
|
-
const className = propertyTexture.class;
|
|
81
|
-
for (const propertyName in propertyTexture.properties) {
|
|
82
|
-
var _propertyTexture$prop;
|
|
83
|
-
const attributeName = `${className}_${propertyName}`;
|
|
84
|
-
const textureInfoTopLevel = (_propertyTexture$prop = propertyTexture.properties) === null || _propertyTexture$prop === void 0 ? void 0 : _propertyTexture$prop[propertyName];
|
|
85
|
-
if (!textureInfoTopLevel) {
|
|
86
|
-
continue;
|
|
165
|
+
if (!propertyTexture.properties) {
|
|
166
|
+
return;
|
|
87
167
|
}
|
|
88
|
-
if (!
|
|
89
|
-
|
|
168
|
+
if (!extension.dataAttributeNames) {
|
|
169
|
+
extension.dataAttributeNames = [];
|
|
90
170
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
171
|
+
/* Iterate through all properties defined in propertyTexture, e.g. "speed" and "direction":
|
|
172
|
+
{
|
|
173
|
+
"class": "wind",
|
|
174
|
+
"properties": {
|
|
175
|
+
"speed": {
|
|
176
|
+
"index": 0,
|
|
177
|
+
"texCoord": 0,
|
|
178
|
+
"channels": [0]
|
|
179
|
+
},
|
|
180
|
+
"direction": {
|
|
181
|
+
"index": 0,
|
|
182
|
+
"texCoord": 0,
|
|
183
|
+
"channels": [1, 2]
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
*/
|
|
188
|
+
const className = propertyTexture.class;
|
|
189
|
+
for (const propertyName in propertyTexture.properties) {
|
|
190
|
+
// propertyName has values like "speed", "direction"
|
|
191
|
+
// Make attributeName as a combination of the class name and the propertyName like "wind_speed" or "wind_direction"
|
|
192
|
+
const attributeName = `${className}_${propertyName}`;
|
|
193
|
+
const textureInfoTopLevel = propertyTexture.properties?.[propertyName];
|
|
194
|
+
if (!textureInfoTopLevel) {
|
|
195
|
+
// eslint-disable-next-line no-continue
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
// The data taken from all meshes/primitives (the same property, e.g. "speed" or "direction") will be combined into one array and saved in textureInfoTopLevel.data
|
|
199
|
+
// Initially textureInfoTopLevel.data will be initialized with an empty array.
|
|
200
|
+
if (!textureInfoTopLevel.data) {
|
|
201
|
+
textureInfoTopLevel.data = [];
|
|
202
|
+
}
|
|
203
|
+
const featureTextureTable = textureInfoTopLevel.data;
|
|
204
|
+
const propertyData = getPrimitiveTextureData(scenegraph, textureInfoTopLevel, primitive);
|
|
205
|
+
if (propertyData === null) {
|
|
206
|
+
// eslint-disable-next-line no-continue
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTextureTable, primitive);
|
|
210
|
+
textureInfoTopLevel.data = featureTextureTable;
|
|
211
|
+
extension.dataAttributeNames.push(attributeName);
|
|
95
212
|
}
|
|
96
|
-
primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTextureTable, primitive);
|
|
97
|
-
textureInfoTopLevel.data = featureTextureTable;
|
|
98
|
-
extension.dataAttributeNames.push(attributeName);
|
|
99
|
-
}
|
|
100
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* Navigates through all properies in the property table, gets properties data,
|
|
216
|
+
* and put the data to `propertyTable.data` as an array.
|
|
217
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
218
|
+
* @param schema - schema object.
|
|
219
|
+
* @param propertyTable - propertyTable definition taken from the top-level extension.
|
|
220
|
+
*/
|
|
101
221
|
function processPropertyTable(scenegraph, schema, propertyTable) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
222
|
+
const schemaClass = schema.classes?.[propertyTable.class];
|
|
223
|
+
if (!schemaClass) {
|
|
224
|
+
throw new Error(`Incorrect data in the EXT_structural_metadata extension: no schema class with name ${propertyTable.class}`);
|
|
225
|
+
}
|
|
226
|
+
const numberOfElements = propertyTable.count; // `propertyTable.count` is a number of elements in each property array.
|
|
227
|
+
for (const propertyName in schemaClass.properties) {
|
|
228
|
+
const classProperty = schemaClass.properties[propertyName];
|
|
229
|
+
const propertyTableProperty = propertyTable.properties?.[propertyName];
|
|
230
|
+
if (propertyTableProperty) {
|
|
231
|
+
// Getting all elements (`numberOfElements`) of the array in the `propertyTableProperty`
|
|
232
|
+
const data = getPropertyDataFromBinarySource(scenegraph, schema, classProperty, numberOfElements, propertyTableProperty);
|
|
233
|
+
propertyTableProperty.data = data;
|
|
234
|
+
}
|
|
115
235
|
}
|
|
116
|
-
}
|
|
117
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Decodes a propertyTable column from binary source based on property type.
|
|
239
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
240
|
+
* @param schema - Schema object.
|
|
241
|
+
* @param classProperty - class property object.
|
|
242
|
+
* @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
|
|
243
|
+
* @param propertyTableProperty - propertyTable's property metadata.
|
|
244
|
+
* @returns {string[] | number[] | string[][] | number[][]}
|
|
245
|
+
*/
|
|
118
246
|
function getPropertyDataFromBinarySource(scenegraph, schema, classProperty, numberOfElements, propertyTableProperty) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
throw new Error(`Unknown classProperty type ${classProperty.type}`);
|
|
152
|
-
}
|
|
153
|
-
return data;
|
|
247
|
+
let data = [];
|
|
248
|
+
const valuesBufferView = propertyTableProperty.values;
|
|
249
|
+
const valuesDataBytes = scenegraph.getTypedArrayForBufferView(valuesBufferView);
|
|
250
|
+
const arrayOffsets = getArrayOffsetsForProperty(scenegraph, classProperty, propertyTableProperty, numberOfElements);
|
|
251
|
+
const stringOffsets = getStringOffsetsForProperty(scenegraph, propertyTableProperty, numberOfElements);
|
|
252
|
+
switch (classProperty.type) {
|
|
253
|
+
case 'SCALAR':
|
|
254
|
+
case 'VEC2':
|
|
255
|
+
case 'VEC3':
|
|
256
|
+
case 'VEC4':
|
|
257
|
+
case 'MAT2':
|
|
258
|
+
case 'MAT3':
|
|
259
|
+
case 'MAT4': {
|
|
260
|
+
data = getPropertyDataNumeric(classProperty, numberOfElements, valuesDataBytes, arrayOffsets);
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
case 'BOOLEAN': {
|
|
264
|
+
// TODO: implement it as soon as we have the corresponding tileset
|
|
265
|
+
throw new Error(`Not implemented - classProperty.type=${classProperty.type}`);
|
|
266
|
+
}
|
|
267
|
+
case 'STRING': {
|
|
268
|
+
data = getPropertyDataString(numberOfElements, valuesDataBytes, arrayOffsets, stringOffsets);
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
case 'ENUM': {
|
|
272
|
+
data = getPropertyDataENUM(schema, classProperty, numberOfElements, valuesDataBytes, arrayOffsets);
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
275
|
+
default:
|
|
276
|
+
throw new Error(`Unknown classProperty type ${classProperty.type}`);
|
|
277
|
+
}
|
|
278
|
+
return data;
|
|
154
279
|
}
|
|
280
|
+
/**
|
|
281
|
+
* Parses propertyTable.property.arrayOffsets that are offsets of sub-arrays in a flatten array of values.
|
|
282
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
283
|
+
* @param classProperty - class property object.
|
|
284
|
+
* @param propertyTableProperty - propertyTable's property metadata.
|
|
285
|
+
* @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
|
|
286
|
+
* @returns Typed array with offset values.
|
|
287
|
+
* @see https://github.com/CesiumGS/glTF/blob/2976f1183343a47a29e4059a70961371cd2fcee8/extensions/2.0/Vendor/EXT_structural_metadata/schema/propertyTable.property.schema.json#L21
|
|
288
|
+
*/
|
|
155
289
|
function getArrayOffsetsForProperty(scenegraph, classProperty, propertyTableProperty, numberOfElements) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
290
|
+
if (classProperty.array &&
|
|
291
|
+
// `count` is a number of array elements. May only be defined when `array` is true.
|
|
292
|
+
// If `count` is NOT defined, it's a VARIABLE-length array
|
|
293
|
+
typeof classProperty.count === 'undefined' &&
|
|
294
|
+
// `arrayOffsets` is an index of the buffer view containing offsets for variable-length arrays.
|
|
295
|
+
typeof propertyTableProperty.arrayOffsets !== 'undefined') {
|
|
296
|
+
// Data are in a VARIABLE-length array
|
|
297
|
+
return getOffsetsForProperty(scenegraph, propertyTableProperty.arrayOffsets, propertyTableProperty.arrayOffsetType || 'UINT32', numberOfElements);
|
|
298
|
+
}
|
|
299
|
+
return null;
|
|
160
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
* Parses propertyTable.property.stringOffsets.
|
|
303
|
+
* @param scenegraph - Instance of the class for structured access to GLTF data.
|
|
304
|
+
* @param propertyTableProperty - propertyTable's property metadata.
|
|
305
|
+
* @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
|
|
306
|
+
* @returns Typed array with offset values.
|
|
307
|
+
* @see https://github.com/CesiumGS/glTF/blob/2976f1183343a47a29e4059a70961371cd2fcee8/extensions/2.0/Vendor/EXT_structural_metadata/schema/propertyTable.property.schema.json#L29C10-L29C23
|
|
308
|
+
*/
|
|
161
309
|
function getStringOffsetsForProperty(scenegraph, propertyTableProperty, numberOfElements) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
310
|
+
if (typeof propertyTableProperty.stringOffsets !== 'undefined' // `stringOffsets` is an index of the buffer view containing offsets for strings.
|
|
311
|
+
) {
|
|
312
|
+
// Data are in a FIXED-length array
|
|
313
|
+
return getOffsetsForProperty(scenegraph, propertyTableProperty.stringOffsets, propertyTableProperty.stringOffsetType || 'UINT32', numberOfElements);
|
|
314
|
+
}
|
|
315
|
+
return null;
|
|
166
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* Decodes properties of SCALAR, VEC-N, MAT-N types from binary sourse.
|
|
319
|
+
* @param classProperty - class property object.
|
|
320
|
+
* @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
|
|
321
|
+
* @param valuesDataBytes - Data taken from values property of the property table property.
|
|
322
|
+
* @param arrayOffsets - Offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.
|
|
323
|
+
* @returns Property values in a typed array or in an array of typed arrays.
|
|
324
|
+
*/
|
|
167
325
|
function getPropertyDataNumeric(classProperty, numberOfElements, valuesDataBytes, arrayOffsets) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
if (isArray) {
|
|
179
|
-
if (arrayOffsets) {
|
|
180
|
-
return parseVariableLengthArrayNumeric(valuesData, numberOfElements, arrayOffsets, valuesDataBytes.length, elementSize);
|
|
326
|
+
const isArray = classProperty.array;
|
|
327
|
+
const arrayCount = classProperty.count;
|
|
328
|
+
const elementSize = getArrayElementByteSize(classProperty.type, classProperty.componentType);
|
|
329
|
+
const elementCount = valuesDataBytes.byteLength / elementSize;
|
|
330
|
+
let valuesData;
|
|
331
|
+
if (classProperty.componentType) {
|
|
332
|
+
valuesData = convertRawBufferToMetadataArray(valuesDataBytes, classProperty.type,
|
|
333
|
+
// The datatype of the element's components. Only applicable to `SCALAR`, `VECN`, and `MATN` types.
|
|
334
|
+
classProperty.componentType, elementCount);
|
|
181
335
|
}
|
|
182
|
-
|
|
183
|
-
|
|
336
|
+
else {
|
|
337
|
+
// The spec doesn't provide any info what to do if componentType is not set.
|
|
338
|
+
valuesData = valuesDataBytes;
|
|
184
339
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
340
|
+
if (isArray) {
|
|
341
|
+
if (arrayOffsets) {
|
|
342
|
+
// VARIABLE-length array
|
|
343
|
+
return parseVariableLengthArrayNumeric(valuesData, numberOfElements, arrayOffsets, valuesDataBytes.length, elementSize);
|
|
344
|
+
}
|
|
345
|
+
if (arrayCount) {
|
|
346
|
+
// FIXED-length array
|
|
347
|
+
return parseFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount);
|
|
348
|
+
}
|
|
349
|
+
return [];
|
|
350
|
+
}
|
|
351
|
+
return valuesData;
|
|
188
352
|
}
|
|
353
|
+
/**
|
|
354
|
+
* Decodes properties of enum type from binary source.
|
|
355
|
+
* @param schema - Schema object.
|
|
356
|
+
* @param classProperty - Class property object.
|
|
357
|
+
* @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
|
|
358
|
+
* @param valuesDataBytes - Data taken from values property of the property table property.
|
|
359
|
+
* @param arrayOffsets - Offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.
|
|
360
|
+
* @returns Strings array of nested strings array.
|
|
361
|
+
*/
|
|
189
362
|
function getPropertyDataENUM(schema, classProperty, numberOfElements, valuesDataBytes, arrayOffsets) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
const enumEntry = (_schema$enums = schema.enums) === null || _schema$enums === void 0 ? void 0 : _schema$enums[enumType];
|
|
196
|
-
if (!enumEntry) {
|
|
197
|
-
throw new Error(`Incorrect data in the EXT_structural_metadata extension: schema.enums does't contain ${enumType}`);
|
|
198
|
-
}
|
|
199
|
-
const enumValueType = enumEntry.valueType || 'UINT16';
|
|
200
|
-
const elementSize = getArrayElementByteSize(classProperty.type, enumValueType);
|
|
201
|
-
const elementCount = valuesDataBytes.byteLength / elementSize;
|
|
202
|
-
let valuesData = convertRawBufferToMetadataArray(valuesDataBytes, classProperty.type, enumValueType, elementCount);
|
|
203
|
-
if (!valuesData) {
|
|
204
|
-
valuesData = valuesDataBytes;
|
|
205
|
-
}
|
|
206
|
-
if (classProperty.array) {
|
|
207
|
-
if (arrayOffsets) {
|
|
208
|
-
return parseVariableLengthArrayENUM({
|
|
209
|
-
valuesData,
|
|
210
|
-
numberOfElements,
|
|
211
|
-
arrayOffsets,
|
|
212
|
-
valuesDataBytesLength: valuesDataBytes.length,
|
|
213
|
-
elementSize,
|
|
214
|
-
enumEntry
|
|
215
|
-
});
|
|
363
|
+
const enumType = classProperty.enumType;
|
|
364
|
+
// Enum ID as declared in the `enums` dictionary. Required when `type` is `ENUM`.
|
|
365
|
+
if (!enumType) {
|
|
366
|
+
throw new Error('Incorrect data in the EXT_structural_metadata extension: classProperty.enumType is not set for type ENUM');
|
|
216
367
|
}
|
|
217
|
-
const
|
|
218
|
-
if (
|
|
219
|
-
|
|
368
|
+
const enumEntry = schema.enums?.[enumType];
|
|
369
|
+
if (!enumEntry) {
|
|
370
|
+
throw new Error(`Incorrect data in the EXT_structural_metadata extension: schema.enums does't contain ${enumType}`);
|
|
220
371
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
372
|
+
const enumValueType = enumEntry.valueType || 'UINT16';
|
|
373
|
+
const elementSize = getArrayElementByteSize(classProperty.type, enumValueType);
|
|
374
|
+
const elementCount = valuesDataBytes.byteLength / elementSize;
|
|
375
|
+
let valuesData = convertRawBufferToMetadataArray(valuesDataBytes, classProperty.type, enumValueType, elementCount);
|
|
376
|
+
if (!valuesData) {
|
|
377
|
+
valuesData = valuesDataBytes;
|
|
378
|
+
}
|
|
379
|
+
if (classProperty.array) {
|
|
380
|
+
if (arrayOffsets) {
|
|
381
|
+
// VARIABLE-length array
|
|
382
|
+
return parseVariableLengthArrayENUM({
|
|
383
|
+
valuesData,
|
|
384
|
+
numberOfElements,
|
|
385
|
+
arrayOffsets,
|
|
386
|
+
valuesDataBytesLength: valuesDataBytes.length,
|
|
387
|
+
elementSize,
|
|
388
|
+
enumEntry
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
const arrayCount = classProperty.count;
|
|
392
|
+
if (arrayCount) {
|
|
393
|
+
// FIXED-length array
|
|
394
|
+
return parseFixedLengthArrayENUM(valuesData, numberOfElements, arrayCount, enumEntry);
|
|
395
|
+
}
|
|
396
|
+
return [];
|
|
397
|
+
}
|
|
398
|
+
// Single value (not an array)
|
|
399
|
+
return getEnumsArray(valuesData, 0, numberOfElements, enumEntry);
|
|
224
400
|
}
|
|
401
|
+
/**
|
|
402
|
+
* Parses variable length nested ENUM arrays.
|
|
403
|
+
* @param params.valuesData - Values in a flat typed array.
|
|
404
|
+
* @param params.numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
|
|
405
|
+
* @param params.arrayOffsets - Offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.
|
|
406
|
+
* @param params.valuesDataBytesLength - Byte length of values array.
|
|
407
|
+
* @param params.elementSize - Single element byte size.
|
|
408
|
+
* @param params.enumEntry - Enums dictionary.
|
|
409
|
+
* @returns Nested strings array.
|
|
410
|
+
*/
|
|
225
411
|
function parseVariableLengthArrayENUM(params) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
numberOfElements
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
if (arrayByteSize + arrayOffset > valuesDataBytesLength) {
|
|
239
|
-
break;
|
|
412
|
+
const { valuesData, numberOfElements, arrayOffsets, valuesDataBytesLength, elementSize, enumEntry } = params;
|
|
413
|
+
const attributeValueArray = [];
|
|
414
|
+
for (let index = 0; index < numberOfElements; index++) {
|
|
415
|
+
const arrayOffset = arrayOffsets[index];
|
|
416
|
+
const arrayByteSize = arrayOffsets[index + 1] - arrayOffsets[index];
|
|
417
|
+
if (arrayByteSize + arrayOffset > valuesDataBytesLength) {
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
const typedArrayOffset = arrayOffset / elementSize;
|
|
421
|
+
const elementCount = arrayByteSize / elementSize;
|
|
422
|
+
const array = getEnumsArray(valuesData, typedArrayOffset, elementCount, enumEntry);
|
|
423
|
+
attributeValueArray.push(array);
|
|
240
424
|
}
|
|
241
|
-
|
|
242
|
-
const elementCount = arrayByteSize / elementSize;
|
|
243
|
-
const array = getEnumsArray(valuesData, typedArrayOffset, elementCount, enumEntry);
|
|
244
|
-
attributeValueArray.push(array);
|
|
245
|
-
}
|
|
246
|
-
return attributeValueArray;
|
|
425
|
+
return attributeValueArray;
|
|
247
426
|
}
|
|
427
|
+
/**
|
|
428
|
+
* Parses fixed length ENUM arrays.
|
|
429
|
+
* @param valuesData - Values in a flat typed array.
|
|
430
|
+
* @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
|
|
431
|
+
* @param arrayCount - Nested arrays length.
|
|
432
|
+
* @param enumEntry - Enums dictionary.
|
|
433
|
+
* @returns Nested strings array.
|
|
434
|
+
*/
|
|
248
435
|
function parseFixedLengthArrayENUM(valuesData, numberOfElements, arrayCount, enumEntry) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
436
|
+
const attributeValueArray = [];
|
|
437
|
+
for (let index = 0; index < numberOfElements; index++) {
|
|
438
|
+
const elementOffset = arrayCount * index;
|
|
439
|
+
const array = getEnumsArray(valuesData, elementOffset, arrayCount, enumEntry);
|
|
440
|
+
attributeValueArray.push(array);
|
|
441
|
+
}
|
|
442
|
+
return attributeValueArray;
|
|
256
443
|
}
|
|
444
|
+
/**
|
|
445
|
+
* Parses ENUM values into a string array.
|
|
446
|
+
* @param valuesData - Values in a flat typed array.
|
|
447
|
+
* @param offset - Offset to start parse from.
|
|
448
|
+
* @param count - Values length to parse.
|
|
449
|
+
* @param enumEntry - Enums dictionary.
|
|
450
|
+
* @returns Array of strings with parsed ENUM names.
|
|
451
|
+
*/
|
|
257
452
|
function getEnumsArray(valuesData, offset, count, enumEntry) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
453
|
+
const array = [];
|
|
454
|
+
for (let i = 0; i < count; i++) {
|
|
455
|
+
// At the moment we don't support BigInt. It requires additional calculations logic
|
|
456
|
+
// and might be an issue in Safari
|
|
457
|
+
if (valuesData instanceof BigInt64Array || valuesData instanceof BigUint64Array) {
|
|
458
|
+
array.push('');
|
|
459
|
+
}
|
|
460
|
+
else {
|
|
461
|
+
const value = valuesData[offset + i];
|
|
462
|
+
const enumObject = getEnumByValue(enumEntry, value);
|
|
463
|
+
if (enumObject) {
|
|
464
|
+
array.push(enumObject.name);
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
array.push('');
|
|
468
|
+
}
|
|
469
|
+
}
|
|
270
470
|
}
|
|
271
|
-
|
|
272
|
-
return array;
|
|
471
|
+
return array;
|
|
273
472
|
}
|
|
473
|
+
/**
|
|
474
|
+
* Looks up ENUM whose `value` property matches the specified number in the parameter `value`.
|
|
475
|
+
* @param {GLTF_EXT_structural_metadata_Enum} enumEntry - ENUM entry containing the array of possible enums.
|
|
476
|
+
* @param {number} value - The value of the ENUM to locate.
|
|
477
|
+
* @returns {GLTF_EXT_structural_metadata_EnumValue | null} ENUM matcihng the specified value or null of no ENUM object was found.
|
|
478
|
+
*/
|
|
274
479
|
function getEnumByValue(enumEntry, value) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
480
|
+
for (const enumValue of enumEntry.values) {
|
|
481
|
+
if (enumValue.value === value) {
|
|
482
|
+
return enumValue;
|
|
483
|
+
}
|
|
278
484
|
}
|
|
279
|
-
|
|
280
|
-
return null;
|
|
485
|
+
return null;
|
|
281
486
|
}
|
|
282
|
-
//# sourceMappingURL=EXT_structural_metadata.js.map
|