@loaders.gl/gltf 4.0.0-alpha.24 → 4.0.0-alpha.26
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
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["name","EXT_MESH_FEATURES","EXT_STRUCTURAL_METADATA","EXT_FEATURE_METADATA","GLTFLoader","GLTFWriter","GLBLoader","GLBWriter","GLTFScenegraph","postProcessGLTF","getMemoryUsageGLTF","_getMemoryUsageGLTF"],"sources":["../../src/index.ts"],"sourcesContent":["/* eslint-disable camelcase, indent */\nexport type {GLB} from './lib/types/glb-types';\n\n// Raw GLTF Types (i.e. not post-processed)\nexport type {\n GLTF,\n GLTFAccessor,\n GLTFBuffer,\n GLTFBufferView,\n GLTFMeshPrimitive,\n GLTFMesh,\n GLTFNode,\n GLTFMaterial,\n GLTFSampler,\n GLTFScene,\n GLTFSkin,\n GLTFTexture,\n GLTFImage,\n GLTFObject,\n // The following extensions are handled by the GLTFLoader and removed from the parsed glTF (disable via options.gltf.excludeExtensions)\n GLTF_KHR_binary_glTF,\n GLTF_KHR_draco_mesh_compression,\n GLTF_KHR_texture_basisu,\n GLTF_EXT_meshopt_compression,\n GLTF_EXT_texture_webp
|
|
1
|
+
{"version":3,"file":"index.js","names":["name","EXT_MESH_FEATURES","EXT_STRUCTURAL_METADATA","EXT_FEATURE_METADATA","getPropertyTableFromExtFeatureMetadata","getPropertyTableFromExtStructuralMetadata","GLTFLoader","GLTFWriter","GLBLoader","GLBWriter","GLTFScenegraph","postProcessGLTF","getMemoryUsageGLTF","_getMemoryUsageGLTF"],"sources":["../../src/index.ts"],"sourcesContent":["/* eslint-disable camelcase, indent */\nexport type {GLB} from './lib/types/glb-types';\n\n// Raw GLTF Types (i.e. not post-processed)\nexport type {\n GLTF,\n GLTFAccessor,\n GLTFBuffer,\n GLTFBufferView,\n GLTFMeshPrimitive,\n GLTFMesh,\n GLTFNode,\n GLTFMaterial,\n GLTFSampler,\n GLTFScene,\n GLTFSkin,\n GLTFTexture,\n GLTFImage,\n GLTFObject,\n // The following extensions are handled by the GLTFLoader and removed from the parsed glTF (disable via options.gltf.excludeExtensions)\n GLTF_KHR_binary_glTF,\n GLTF_KHR_draco_mesh_compression,\n GLTF_KHR_texture_basisu,\n GLTF_EXT_meshopt_compression,\n GLTF_EXT_texture_webp\n} from './lib/types/gltf-json-schema';\n\n// 3DTiles extensions\nexport type {\n GLTF_EXT_feature_metadata_GLTF,\n GLTF_EXT_feature_metadata_Schema,\n GLTF_EXT_feature_metadata_Class,\n GLTF_EXT_feature_metadata_ClassProperty,\n GLTF_EXT_feature_metadata_Enum,\n GLTF_EXT_feature_metadata_EnumValue,\n GLTF_EXT_feature_metadata_FeatureTable,\n GLTF_EXT_feature_metadata_FeatureTableProperty,\n GLTF_EXT_feature_metadata_FeatureTexture,\n GLTF_EXT_feature_metadata_TextureAccessor,\n GLTF_EXT_feature_metadata_Statistics,\n GLTF_EXT_feature_metadata_StatisticsClass,\n GLTF_EXT_feature_metadata_StatisticsClassProperty,\n GLTF_EXT_feature_metadata_Primitive,\n GLTF_EXT_feature_metadata_FeatureIdAttribute,\n GLTF_EXT_feature_metadata_FeatureIdAttributeFeatureIds,\n GLTF_EXT_feature_metadata_FeatureIdTexture,\n GLTF_EXT_feature_metadata_FeatureIdTextureAccessor\n} from './lib/types/gltf-ext-feature-metadata-schema';\n\nexport type {GLTF_EXT_structural_metadata_GLTF} from './lib/types/gltf-ext-structural-metadata-schema';\n\nexport type {\n GLTF_EXT_mesh_features,\n GLTF_EXT_mesh_features_featureId\n} from './lib/types/gltf-ext-mesh-features-schema';\n\nexport {name as EXT_MESH_FEATURES} from './lib/extensions/EXT_mesh_features';\nexport {name as EXT_STRUCTURAL_METADATA} from './lib/extensions/EXT_structural_metadata';\nexport {name as EXT_FEATURE_METADATA} from './lib/extensions/deprecated/EXT_feature_metadata';\nexport {getPropertyTableFromExtFeatureMetadata} from './lib/extensions/deprecated/EXT_feature_metadata';\nexport {getPropertyTableFromExtStructuralMetadata} from './lib/extensions/EXT_structural_metadata';\n\n// Postprocessed types (modified GLTF types)\nexport type {\n GLTFPostprocessed,\n GLTFAccessorPostprocessed,\n GLTFNodePostprocessed,\n GLTFMaterialPostprocessed,\n GLTFMeshPostprocessed,\n GLTFMeshPrimitivePostprocessed,\n GLTFImagePostprocessed,\n GLTFTexturePostprocessed\n} from './lib/types/gltf-postprocessed-schema';\n\nexport type {GLTFWithBuffers, FeatureTableJson} from './lib/types/gltf-types';\n\n// glTF loader/writer definition objects\nexport {GLTFLoader} from './gltf-loader';\nexport {GLTFWriter} from './gltf-writer';\n\n// GLB Loader & Writer (for custom formats that want to leverage the GLB binary \"envelope\")\nexport {GLBLoader} from './glb-loader';\nexport {GLBWriter} from './glb-writer';\n\n// glTF Data Access Helper Class\nexport {GLTFScenegraph} from './lib/api/gltf-scenegraph';\nexport {postProcessGLTF} from './lib/api/post-process-gltf';\nexport {getMemoryUsageGLTF as _getMemoryUsageGLTF} from './lib/gltf-utils/gltf-utils';\n\n/** @deprecated */\n// export type {GLTFMesh as Mesh} from './lib/types/gltf-json-schema';\n/** @deprecated */\n// export type {GLTFNodePostprocessed as Node} from './lib/types/gltf-postprocessed-schema';\n/** @deprecated */\n// export type {GLTFAccessorPostprocessed as Accessor} from './lib/types/gltf-postprocessed-schema';\n// /** @deprecated */\n// export type {GLTFImagePostprocessed as Image} from './lib/types/gltf-postprocessed-schema';\n"],"mappings":"AAwDA,SAAQA,IAAI,IAAIC,iBAAiB,QAAO,oCAAoC;AAC5E,SAAQD,IAAI,IAAIE,uBAAuB,QAAO,0CAA0C;AACxF,SAAQF,IAAI,IAAIG,oBAAoB,QAAO,kDAAkD;AAC7F,SAAQC,sCAAsC,QAAO,kDAAkD;AACvG,SAAQC,yCAAyC,QAAO,0CAA0C;AAiBlG,SAAQC,UAAU,QAAO,eAAe;AACxC,SAAQC,UAAU,QAAO,eAAe;AAGxC,SAAQC,SAAS,QAAO,cAAc;AACtC,SAAQC,SAAS,QAAO,cAAc;AAGtC,SAAQC,cAAc,QAAO,2BAA2B;AACxD,SAAQC,eAAe,QAAO,6BAA6B;AAC3D,SAAQC,kBAAkB,IAAIC,mBAAmB,QAAO,6BAA6B"}
|
|
@@ -9,7 +9,7 @@ import * as KHR_lights_punctual from '../extensions/deprecated/KHR_lights_punctu
|
|
|
9
9
|
import * as KHR_materials_unlit from '../extensions/deprecated/KHR_materials_unlit';
|
|
10
10
|
import * as KHR_techniques_webgl from '../extensions/deprecated/KHR_techniques_webgl';
|
|
11
11
|
import * as EXT_feature_metadata from '../extensions/deprecated/EXT_feature_metadata';
|
|
12
|
-
export const EXTENSIONS = [
|
|
12
|
+
export const EXTENSIONS = [EXT_structural_metadata, EXT_mesh_features, EXT_meshopt_compression, EXT_texture_webp, KHR_texture_basisu, KHR_draco_mesh_compression, KHR_lights_punctual, KHR_materials_unlit, KHR_techniques_webgl, KHR_texture_transform, EXT_feature_metadata];
|
|
13
13
|
export function preprocessExtensions(gltf) {
|
|
14
14
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
15
15
|
let context = arguments.length > 2 ? arguments[2] : undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gltf-extensions.js","names":["EXT_mesh_features","EXT_structural_metadata","EXT_meshopt_compression","EXT_texture_webp","KHR_texture_basisu","KHR_draco_mesh_compression","KHR_texture_transform","KHR_lights_punctual","KHR_materials_unlit","KHR_techniques_webgl","EXT_feature_metadata","EXTENSIONS","preprocessExtensions","gltf","options","arguments","length","undefined","context","extensions","filter","extension","useExtension","name","_extension$preprocess","preprocess","call","decodeExtensions","_extension$decode","decode","extensionName","_options$gltf","excludes","excludeExtensions","exclude"],"sources":["../../../../src/lib/api/gltf-extensions.ts"],"sourcesContent":["/* eslint-disable camelcase */\nimport {GLTF} from '../types/gltf-json-schema';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\n\n// GLTF 1.0 extensions (decode only)\n// import * as KHR_binary_gltf from './KHR_draco_mesh_compression';\n\n// GLTF 2.0 Vendor extensions\nimport * as EXT_mesh_features from '../extensions/EXT_mesh_features';\nimport * as EXT_structural_metadata from '../extensions/EXT_structural_metadata';\n\n// GLTF 2.0 Khronos extensions (decode/encode)\nimport * as EXT_meshopt_compression from '../extensions/EXT_meshopt_compression';\nimport * as EXT_texture_webp from '../extensions/EXT_texture_webp';\nimport * as KHR_texture_basisu from '../extensions/KHR_texture_basisu';\nimport * as KHR_draco_mesh_compression from '../extensions/KHR_draco_mesh_compression';\nimport * as KHR_texture_transform from '../extensions/KHR_texture_transform';\n\n// Deprecated. These should be handled by rendering library (e.g. luma.gl), not the loader.\nimport * as KHR_lights_punctual from '../extensions/deprecated/KHR_lights_punctual';\nimport * as KHR_materials_unlit from '../extensions/deprecated/KHR_materials_unlit';\nimport * as KHR_techniques_webgl from '../extensions/deprecated/KHR_techniques_webgl';\nimport * as EXT_feature_metadata from '../extensions/deprecated/EXT_feature_metadata';\n\ntype GLTFExtensionPlugin = {\n name: string;\n preprocess?: (gltfData: {json: GLTF}, options: GLTFLoaderOptions, context) => void;\n decode?: (\n gltfData: {\n json: GLTF;\n buffers: {arrayBuffer: ArrayBuffer; byteOffset: number; byteLength: number}[];\n },\n options: GLTFLoaderOptions,\n context\n ) => Promise<void>;\n encode?: (gltfData: {json: GLTF}, options: GLTFLoaderOptions) => void;\n};\n\n/**\n * List of extensions processed by the GLTFLoader\n * Note that may extensions can only be handled on the rendering stage and are left out here\n * These are just extensions that can be handled fully or partially during loading.\n */\nexport const EXTENSIONS: GLTFExtensionPlugin[] = [\n // 1.0\n // KHR_binary_gltf is handled separately - must be processed before other parsing starts\n // KHR_binary_gltf,\n\n // 2.0\n
|
|
1
|
+
{"version":3,"file":"gltf-extensions.js","names":["EXT_mesh_features","EXT_structural_metadata","EXT_meshopt_compression","EXT_texture_webp","KHR_texture_basisu","KHR_draco_mesh_compression","KHR_texture_transform","KHR_lights_punctual","KHR_materials_unlit","KHR_techniques_webgl","EXT_feature_metadata","EXTENSIONS","preprocessExtensions","gltf","options","arguments","length","undefined","context","extensions","filter","extension","useExtension","name","_extension$preprocess","preprocess","call","decodeExtensions","_extension$decode","decode","extensionName","_options$gltf","excludes","excludeExtensions","exclude"],"sources":["../../../../src/lib/api/gltf-extensions.ts"],"sourcesContent":["/* eslint-disable camelcase */\nimport {GLTF} from '../types/gltf-json-schema';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\n\n// GLTF 1.0 extensions (decode only)\n// import * as KHR_binary_gltf from './KHR_draco_mesh_compression';\n\n// GLTF 2.0 Vendor extensions\nimport * as EXT_mesh_features from '../extensions/EXT_mesh_features';\nimport * as EXT_structural_metadata from '../extensions/EXT_structural_metadata';\n\n// GLTF 2.0 Khronos extensions (decode/encode)\nimport * as EXT_meshopt_compression from '../extensions/EXT_meshopt_compression';\nimport * as EXT_texture_webp from '../extensions/EXT_texture_webp';\nimport * as KHR_texture_basisu from '../extensions/KHR_texture_basisu';\nimport * as KHR_draco_mesh_compression from '../extensions/KHR_draco_mesh_compression';\nimport * as KHR_texture_transform from '../extensions/KHR_texture_transform';\n\n// Deprecated. These should be handled by rendering library (e.g. luma.gl), not the loader.\nimport * as KHR_lights_punctual from '../extensions/deprecated/KHR_lights_punctual';\nimport * as KHR_materials_unlit from '../extensions/deprecated/KHR_materials_unlit';\nimport * as KHR_techniques_webgl from '../extensions/deprecated/KHR_techniques_webgl';\nimport * as EXT_feature_metadata from '../extensions/deprecated/EXT_feature_metadata';\n\ntype GLTFExtensionPlugin = {\n name: string;\n preprocess?: (gltfData: {json: GLTF}, options: GLTFLoaderOptions, context) => void;\n decode?: (\n gltfData: {\n json: GLTF;\n buffers: {arrayBuffer: ArrayBuffer; byteOffset: number; byteLength: number}[];\n },\n options: GLTFLoaderOptions,\n context\n ) => Promise<void>;\n encode?: (gltfData: {json: GLTF}, options: GLTFLoaderOptions) => void;\n};\n\n/**\n * List of extensions processed by the GLTFLoader\n * Note that may extensions can only be handled on the rendering stage and are left out here\n * These are just extensions that can be handled fully or partially during loading.\n */\nexport const EXTENSIONS: GLTFExtensionPlugin[] = [\n // 1.0\n // KHR_binary_gltf is handled separately - must be processed before other parsing starts\n // KHR_binary_gltf,\n\n // 2.0\n EXT_structural_metadata,\n EXT_mesh_features,\n EXT_meshopt_compression,\n EXT_texture_webp,\n // Basisu should come after webp, we want basisu to be preferred if both are provided\n KHR_texture_basisu,\n KHR_draco_mesh_compression,\n KHR_lights_punctual,\n KHR_materials_unlit,\n KHR_techniques_webgl,\n KHR_texture_transform,\n EXT_feature_metadata\n];\n\n/** Call before any resource loading starts */\nexport function preprocessExtensions(gltf, options: GLTFLoaderOptions = {}, context?) {\n const extensions = EXTENSIONS.filter((extension) => useExtension(extension.name, options));\n for (const extension of extensions) {\n extension.preprocess?.(gltf, options, context);\n }\n}\n\n/** Call after resource loading */\nexport async function decodeExtensions(gltf, options: GLTFLoaderOptions = {}, context?) {\n const extensions = EXTENSIONS.filter((extension) => useExtension(extension.name, options));\n for (const extension of extensions) {\n // Note: We decode async extensions sequentially, this might not be necessary\n // Currently we only have Draco, but when we add Basis we may revisit\n await extension.decode?.(gltf, options, context);\n }\n}\n\nfunction useExtension(extensionName: string, options: GLTFLoaderOptions) {\n const excludes = options?.gltf?.excludeExtensions || {};\n const exclude = extensionName in excludes && !excludes[extensionName];\n return !exclude;\n}\n"],"mappings":"AAQA,OAAO,KAAKA,iBAAiB,MAAM,iCAAiC;AACpE,OAAO,KAAKC,uBAAuB,MAAM,uCAAuC;AAGhF,OAAO,KAAKC,uBAAuB,MAAM,uCAAuC;AAChF,OAAO,KAAKC,gBAAgB,MAAM,gCAAgC;AAClE,OAAO,KAAKC,kBAAkB,MAAM,kCAAkC;AACtE,OAAO,KAAKC,0BAA0B,MAAM,0CAA0C;AACtF,OAAO,KAAKC,qBAAqB,MAAM,qCAAqC;AAG5E,OAAO,KAAKC,mBAAmB,MAAM,8CAA8C;AACnF,OAAO,KAAKC,mBAAmB,MAAM,8CAA8C;AACnF,OAAO,KAAKC,oBAAoB,MAAM,+CAA+C;AACrF,OAAO,KAAKC,oBAAoB,MAAM,+CAA+C;AAqBrF,OAAO,MAAMC,UAAiC,GAAG,CAM/CV,uBAAuB,EACvBD,iBAAiB,EACjBE,uBAAuB,EACvBC,gBAAgB,EAEhBC,kBAAkB,EAClBC,0BAA0B,EAC1BE,mBAAmB,EACnBC,mBAAmB,EACnBC,oBAAoB,EACpBH,qBAAqB,EACrBI,oBAAoB,CACrB;AAGD,OAAO,SAASE,oBAAoBA,CAACC,IAAI,EAA6C;EAAA,IAA3CC,OAA0B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAAA,IAAEG,OAAQ,GAAAH,SAAA,CAAAC,MAAA,OAAAD,SAAA,MAAAE,SAAA;EAClF,MAAME,UAAU,GAAGR,UAAU,CAACS,MAAM,CAAEC,SAAS,IAAKC,YAAY,CAACD,SAAS,CAACE,IAAI,EAAET,OAAO,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ph';
|
|
2
|
-
import { getPrimitiveTextureData
|
|
3
|
-
import { getPropertyTablePopulated } from './EXT_structural_metadata';
|
|
2
|
+
import { getPrimitiveTextureData } from './utils/3d-tiles-utils';
|
|
4
3
|
const EXT_MESH_FEATURES_NAME = 'EXT_mesh_features';
|
|
5
4
|
export const name = EXT_MESH_FEATURES_NAME;
|
|
6
5
|
export async function decode(gltfData, options) {
|
|
@@ -19,37 +18,26 @@ function decodeExtMeshFeatures(scenegraph, options) {
|
|
|
19
18
|
}
|
|
20
19
|
}
|
|
21
20
|
function processMeshPrimitiveFeatures(scenegraph, primitive, options) {
|
|
22
|
-
var _primitive$extensions;
|
|
21
|
+
var _options$gltf, _primitive$extensions;
|
|
22
|
+
if (!(options !== null && options !== void 0 && (_options$gltf = options.gltf) !== null && _options$gltf !== void 0 && _options$gltf.loadBuffers)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
23
25
|
const extension = (_primitive$extensions = primitive.extensions) === null || _primitive$extensions === void 0 ? void 0 : _primitive$extensions[EXT_MESH_FEATURES_NAME];
|
|
24
26
|
const featureIds = extension === null || extension === void 0 ? void 0 : extension.featureIds;
|
|
25
|
-
if (!featureIds)
|
|
26
|
-
|
|
27
|
-
extension.dataAttributeNames = [];
|
|
27
|
+
if (!featureIds) {
|
|
28
|
+
return;
|
|
28
29
|
}
|
|
29
|
-
let featureIdCount = 0;
|
|
30
30
|
for (const featureId of featureIds) {
|
|
31
|
-
var _options$
|
|
32
|
-
let
|
|
33
|
-
if (typeof featureId.propertyTable === 'number') {
|
|
34
|
-
propertyTable = getPropertyTablePopulated(scenegraph, featureId.propertyTable);
|
|
35
|
-
}
|
|
36
|
-
let propertyData = null;
|
|
31
|
+
var _options$gltf2;
|
|
32
|
+
let featureIdData = null;
|
|
37
33
|
if (typeof featureId.attribute !== 'undefined') {
|
|
38
34
|
const accessorKey = "_FEATURE_ID_".concat(featureId.attribute);
|
|
39
35
|
const accessorIndex = primitive.attributes[accessorKey];
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
propertyData = getPrimitiveTextureData(scenegraph, featureId.texture, primitive);
|
|
36
|
+
featureIdData = scenegraph.getTypedArrayForAccessor(accessorIndex);
|
|
37
|
+
} else if (typeof featureId.texture !== 'undefined' && options !== null && options !== void 0 && (_options$gltf2 = options.gltf) !== null && _options$gltf2 !== void 0 && _options$gltf2.loadImages) {
|
|
38
|
+
featureIdData = getPrimitiveTextureData(scenegraph, featureId.texture, primitive);
|
|
44
39
|
} else {}
|
|
45
|
-
|
|
46
|
-
const featureTable = [];
|
|
47
|
-
if (propertyData) {
|
|
48
|
-
primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTable, primitive);
|
|
49
|
-
}
|
|
50
|
-
extension.dataAttributeNames.push(attributeName);
|
|
51
|
-
featureId.data = featureTable;
|
|
52
|
-
featureIdCount++;
|
|
40
|
+
featureId.data = featureIdData;
|
|
53
41
|
}
|
|
54
42
|
}
|
|
55
43
|
//# sourceMappingURL=EXT_mesh_features.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EXT_mesh_features.js","names":["GLTFScenegraph","getPrimitiveTextureData","
|
|
1
|
+
{"version":3,"file":"EXT_mesh_features.js","names":["GLTFScenegraph","getPrimitiveTextureData","EXT_MESH_FEATURES_NAME","name","decode","gltfData","options","scenegraph","decodeExtMeshFeatures","json","gltf","meshes","mesh","primitive","primitives","processMeshPrimitiveFeatures","_options$gltf","_primitive$extensions","loadBuffers","extension","extensions","featureIds","featureId","_options$gltf2","featureIdData","attribute","accessorKey","concat","accessorIndex","attributes","getTypedArrayForAccessor","texture","loadImages","data"],"sources":["../../../../src/lib/extensions/EXT_mesh_features.ts"],"sourcesContent":["// GLTF EXTENSION: EXT_mesh_features\n// https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_mesh_features\n/* eslint-disable camelcase */\nimport type {GLTF, GLTFMeshPrimitive} from '../types/gltf-json-schema';\nimport {GLTFLoaderOptions} from '../../gltf-loader';\nimport type {\n GLTF_EXT_mesh_features,\n GLTF_EXT_mesh_features_featureId\n} from '../types/gltf-ext-mesh-features-schema';\n\nimport {GLTFScenegraph} from '../api/gltf-scenegraph';\nimport {getPrimitiveTextureData} from './utils/3d-tiles-utils';\n\nconst EXT_MESH_FEATURES_NAME = 'EXT_mesh_features';\nexport const name = EXT_MESH_FEATURES_NAME;\n\nexport async function decode(gltfData: {json: GLTF}, options: GLTFLoaderOptions): Promise<void> {\n const scenegraph = new GLTFScenegraph(gltfData);\n decodeExtMeshFeatures(scenegraph, options);\n}\n\n/**\n * Decodes feature metadata from extension.\n * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.\n * @param {GLTFLoaderOptions} options - GLTFLoader options.\n */\nfunction decodeExtMeshFeatures(scenegraph: GLTFScenegraph, options: GLTFLoaderOptions): void {\n const json = scenegraph.gltf.json;\n if (!json.meshes) {\n return;\n }\n\n // Iterate through all meshes/primitives.\n for (const mesh of json.meshes) {\n for (const primitive of mesh.primitives) {\n processMeshPrimitiveFeatures(scenegraph, primitive, options);\n }\n }\n}\n\n/**\n * Takes data from EXT_mesh_features and store it in 'data' property of featureIds.\n * If combined with EXT_structural_metadata, corresponding data are taken from the property tables of that extension.\n * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.\n * @param {GLTFMeshPrimitive} primitive - Primitive that contains extensions.\n * @param {GLTFLoaderOptions} options - GLTFLoader options.\n */\nfunction processMeshPrimitiveFeatures(\n scenegraph: GLTFScenegraph,\n primitive: GLTFMeshPrimitive,\n options: GLTFLoaderOptions\n): void {\n // Processing of mesh primitive features requires buffers to be loaded.\n if (!options?.gltf?.loadBuffers) {\n return;\n }\n\n const extension = primitive.extensions?.[EXT_MESH_FEATURES_NAME] as GLTF_EXT_mesh_features;\n const featureIds: GLTF_EXT_mesh_features_featureId[] = extension?.featureIds;\n\n if (!featureIds) {\n return;\n }\n\n for (const featureId of featureIds) {\n let featureIdData: number[] | null = null;\n // Process \"Feature ID by Vertex\"\n if (typeof featureId.attribute !== 'undefined') {\n const accessorKey = `_FEATURE_ID_${featureId.attribute}`;\n const accessorIndex = primitive.attributes[accessorKey];\n featureIdData = scenegraph.getTypedArrayForAccessor(accessorIndex) as number[];\n }\n\n // Process \"Feature ID by Texture Coordinates\"\n else if (typeof featureId.texture !== 'undefined' && options?.gltf?.loadImages) {\n featureIdData = getPrimitiveTextureData(scenegraph, featureId.texture, primitive);\n }\n\n // Process \"Feature ID by Index\"\n else {\n /*\n When both featureId.attribute and featureId.texture are undefined,\n then the feature ID value for each vertex is given implicitly, via the index of the vertex.\n In this case, the featureCount must match the number of vertices of the mesh primitive.\n */\n // TODO: At the moment of writing we don't have a tileset with the data of that kind. Implement it later.\n }\n\n featureId.data = featureIdData;\n }\n}\n"],"mappings":"AAUA,SAAQA,cAAc,QAAO,wBAAwB;AACrD,SAAQC,uBAAuB,QAAO,wBAAwB;AAE9D,MAAMC,sBAAsB,GAAG,mBAAmB;AAClD,OAAO,MAAMC,IAAI,GAAGD,sBAAsB;AAE1C,OAAO,eAAeE,MAAMA,CAACC,QAAsB,EAAEC,OAA0B,EAAiB;EAC9F,MAAMC,UAAU,GAAG,IAAIP,cAAc,CAACK,QAAQ,CAAC;EAC/CG,qBAAqB,CAACD,UAAU,EAAED,OAAO,CAAC;AAC5C;AAOA,SAASE,qBAAqBA,CAACD,UAA0B,EAAED,OAA0B,EAAQ;EAC3F,MAAMG,IAAI,GAAGF,UAAU,CAACG,IAAI,CAACD,IAAI;EACjC,IAAI,CAACA,IAAI,CAACE,MAAM,EAAE;IAChB;EACF;EAGA,KAAK,MAAMC,IAAI,IAAIH,IAAI,CAACE,MAAM,EAAE;IAC9B,KAAK,MAAME,SAAS,IAAID,IAAI,CAACE,UAAU,EAAE;MACvCC,4BAA4B,CAACR,UAAU,EAAEM,SAAS,EAAEP,OAAO,CAAC;IAC9D;EACF;AACF;AASA,SAASS,4BAA4BA,CACnCR,UAA0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Metadata(scenegraph, options);
|
|
8
8
|
}
|
|
9
|
+
export function getPropertyTableFromExtStructuralMetadata(extension, metadataClass) {
|
|
10
|
+
if (extension.propertyTables) {
|
|
11
|
+
const firstPropertyTable = extension === null || extension === void 0 ? void 0 : extension.propertyTables[0];
|
|
12
|
+
const propertyTableWithData = {};
|
|
13
|
+
for (const propertyName in firstPropertyTable.properties) {
|
|
14
|
+
propertyTableWithData[propertyName] = firstPropertyTable.properties[propertyName].data;
|
|
15
|
+
}
|
|
16
|
+
return propertyTableWithData;
|
|
17
|
+
}
|
|
18
|
+
if (extension.propertyTextures) {
|
|
19
|
+
const firstPropertyTexture = extension === null || extension === void 0 ? void 0 : extension.propertyTextures[0];
|
|
20
|
+
const propertyTableWithData = {};
|
|
21
|
+
for (const propertyName in firstPropertyTexture.properties) {
|
|
22
|
+
propertyTableWithData[propertyName] = firstPropertyTexture.properties[propertyName].data;
|
|
23
|
+
}
|
|
24
|
+
return propertyTableWithData;
|
|
25
|
+
}
|
|
26
|
+
console.warn('Cannot get property table from EXT_structural_metadata extension. There is neither propertyTables, nor propertyTextures in the extension.');
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
9
29
|
export function getPropertyTablePopulated(scenegraph, propertyTableIndex) {
|
|
10
30
|
var _extension$propertyTa;
|
|
11
31
|
const extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME);
|
|
@@ -17,34 +37,48 @@ export function getPropertyTablePopulated(scenegraph, propertyTableIndex) {
|
|
|
17
37
|
throw new Error("Incorrect data in the EXT_structural_metadata extension: no property table with index ".concat(propertyTableIndex));
|
|
18
38
|
}
|
|
19
39
|
function decodeExtStructuralMetadata(scenegraph, options) {
|
|
20
|
-
var _options$gltf;
|
|
40
|
+
var _options$gltf, _options$gltf2;
|
|
41
|
+
if (!((_options$gltf = options.gltf) !== null && _options$gltf !== void 0 && _options$gltf.loadBuffers)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
21
44
|
const extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME);
|
|
22
|
-
if (!
|
|
45
|
+
if (!extension) {
|
|
23
46
|
return;
|
|
24
47
|
}
|
|
48
|
+
if ((_options$gltf2 = options.gltf) !== null && _options$gltf2 !== void 0 && _options$gltf2.loadImages) {
|
|
49
|
+
decodePropertyTextures(scenegraph, extension);
|
|
50
|
+
}
|
|
51
|
+
decodePropertyTables(scenegraph, extension);
|
|
52
|
+
}
|
|
53
|
+
function decodePropertyTextures(scenegraph, extension) {
|
|
25
54
|
const propertyTextures = extension.propertyTextures;
|
|
26
55
|
const json = scenegraph.gltf.json;
|
|
27
|
-
if (propertyTextures && json.meshes
|
|
56
|
+
if (propertyTextures && json.meshes) {
|
|
28
57
|
for (const mesh of json.meshes) {
|
|
29
58
|
for (const primitive of mesh.primitives) {
|
|
30
59
|
processPrimitivePropertyTextures(scenegraph, propertyTextures, primitive, extension);
|
|
31
60
|
}
|
|
32
61
|
}
|
|
33
62
|
}
|
|
34
|
-
|
|
63
|
+
}
|
|
64
|
+
function decodePropertyTables(scenegraph, extension) {
|
|
65
|
+
const schema = extension.schema;
|
|
66
|
+
if (!schema) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const schemaClasses = schema.classes;
|
|
35
70
|
const propertyTables = extension.propertyTables;
|
|
36
71
|
if (schemaClasses && propertyTables) {
|
|
37
72
|
for (const schemaName in schemaClasses) {
|
|
38
73
|
const propertyTable = findPropertyTableByClass(propertyTables, schemaName);
|
|
39
74
|
if (propertyTable) {
|
|
40
|
-
processPropertyTable(scenegraph,
|
|
75
|
+
processPropertyTable(scenegraph, schema, propertyTable);
|
|
41
76
|
}
|
|
42
77
|
}
|
|
43
78
|
}
|
|
44
79
|
}
|
|
45
80
|
function findPropertyTableByClass(propertyTables, schemaClassName) {
|
|
46
|
-
for (
|
|
47
|
-
const propertyTable = propertyTables[i];
|
|
81
|
+
for (const propertyTable of propertyTables) {
|
|
48
82
|
if (propertyTable.class === schemaClassName) {
|
|
49
83
|
return propertyTable;
|
|
50
84
|
}
|
|
@@ -74,10 +108,10 @@ function processPrimitivePropertyTexture(scenegraph, propertyTexture, primitive,
|
|
|
74
108
|
extension.dataAttributeNames = [];
|
|
75
109
|
}
|
|
76
110
|
const className = propertyTexture.class;
|
|
77
|
-
for (const
|
|
111
|
+
for (const propertyName in propertyTexture.properties) {
|
|
78
112
|
var _propertyTexture$prop;
|
|
79
|
-
const attributeName = "".concat(className, "_").concat(
|
|
80
|
-
const textureInfoTopLevel = (_propertyTexture$prop = propertyTexture.properties) === null || _propertyTexture$prop === void 0 ? void 0 : _propertyTexture$prop[
|
|
113
|
+
const attributeName = "".concat(className, "_").concat(propertyName);
|
|
114
|
+
const textureInfoTopLevel = (_propertyTexture$prop = propertyTexture.properties) === null || _propertyTexture$prop === void 0 ? void 0 : _propertyTexture$prop[propertyName];
|
|
81
115
|
if (!textureInfoTopLevel) {
|
|
82
116
|
continue;
|
|
83
117
|
}
|
|
@@ -149,14 +183,14 @@ function getPropertyDataFromBinarySource(scenegraph, schema, classProperty, numb
|
|
|
149
183
|
return data;
|
|
150
184
|
}
|
|
151
185
|
function getArrayOffsetsForProperty(scenegraph, classProperty, propertyTableProperty, numberOfElements) {
|
|
152
|
-
if (classProperty.array && typeof classProperty.count === 'undefined' && typeof propertyTableProperty.arrayOffsets !== 'undefined'
|
|
153
|
-
return getOffsetsForProperty(scenegraph, propertyTableProperty.arrayOffsets, propertyTableProperty.arrayOffsetType, numberOfElements);
|
|
186
|
+
if (classProperty.array && typeof classProperty.count === 'undefined' && typeof propertyTableProperty.arrayOffsets !== 'undefined') {
|
|
187
|
+
return getOffsetsForProperty(scenegraph, propertyTableProperty.arrayOffsets, propertyTableProperty.arrayOffsetType || 'UINT32', numberOfElements);
|
|
154
188
|
}
|
|
155
189
|
return null;
|
|
156
190
|
}
|
|
157
191
|
function getStringOffsetsForProperty(scenegraph, propertyTableProperty, numberOfElements) {
|
|
158
|
-
if (typeof propertyTableProperty.stringOffsets !== 'undefined'
|
|
159
|
-
return getOffsetsForProperty(scenegraph, propertyTableProperty.stringOffsets, propertyTableProperty.stringOffsetType, numberOfElements);
|
|
192
|
+
if (typeof propertyTableProperty.stringOffsets !== 'undefined') {
|
|
193
|
+
return getOffsetsForProperty(scenegraph, propertyTableProperty.stringOffsets, propertyTableProperty.stringOffsetType || 'UINT32', numberOfElements);
|
|
160
194
|
}
|
|
161
195
|
return null;
|
|
162
196
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EXT_structural_metadata.js","names":["GLTFScenegraph","convertRawBufferToMetadataArray","getPrimitiveTextureData","primitivePropertyDataToAttributes","getArrayElementByteSize","getOffsetsForProperty","EXT_STRUCTURAL_METADATA_NAME","name","decode","gltfData","options","scenegraph","decodeExtStructuralMetadata","getPropertyTablePopulated","propertyTableIndex","_extension$propertyTa","extension","getExtension","propertyTable","propertyTables","schema","processPropertyTable","Error","concat","_options$gltf","propertyTextures","json","gltf","meshes","loadImages","mesh","primitive","primitives","processPrimitivePropertyTextures","schemaClasses","classes","schemaName","findPropertyTableByClass","schemaClassName","i","len","length","class","_primitive$extensions","primitiveExtension","extensions","primitivePropertyTextureIndices","primitivePropertyTextureIndex","propertyTexture","processPrimitivePropertyTexture","properties","dataAttributeNames","className","propName","_propertyTexture$prop","attributeName","textureInfoTopLevel","data","featureTextureTable","propertyData","push","_schema$classes","schemaClass","numberOfElements","count","propertyName","_propertyTable$proper","classProperty","propertyTableProperty","getPropertyDataFromBinarySource","valuesBufferView","values","valuesDataBytes","getTypedArrayForBufferView","arrayOffsets","getArrayOffsetsForProperty","stringOffsets","getStringOffsetsForProperty","type","getPropertyDataNumeric","getPropertyDataString","getPropertyDataENUM","array","arrayOffsetType","stringOffsetType","isArray","arrayCount","elementSize","componentType","elementCount","byteLength","valuesData","parseVariableLengthArrayNumeric","parseFixedLengthArrayNumeric","valuesDataBytesLength","valueSize","attributeValueArray","index","arrayOffset","arrayByteSize","typedArrayOffset","slice","elementOffset","stringsArray","textDecoder","TextDecoder","stringOffset","stringByteSize","stringData","subarray","stringAttribute","_schema$enums","enumType","enumEntry","enums","enumValueType","valueType","parseVariableLengthArrayENUM","parseFixedLengthArrayENUM","getEnumsArray","params","offset","BigInt64Array","BigUint64Array","value","enumObject","getEnumByValue","enumValue"],"sources":["../../../../src/lib/extensions/EXT_structural_metadata.ts"],"sourcesContent":["/* eslint-disable camelcase */\nimport type {BigTypedArray, TypedArray} from '@loaders.gl/schema';\nimport type {GLTF, GLTFTextureInfoMetadata, GLTFMeshPrimitive} from '../types/gltf-json-schema';\nimport type {\n GLTF_EXT_structural_metadata_Schema,\n GLTF_EXT_structural_metadata_ClassProperty,\n GLTF_EXT_structural_metadata_Enum,\n GLTF_EXT_structural_metadata_EnumValue,\n GLTF_EXT_structural_metadata_PropertyTable,\n GLTF_EXT_structural_metadata,\n GLTF_EXT_structural_metadata_PropertyTexture,\n GLTF_EXT_structural_metadata_PropertyTable_Property,\n GLTF_EXT_structural_metadata_Primitive\n} from '../types/gltf-ext-structural-metadata-schema';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\n\nimport {GLTFScenegraph} from '../api/gltf-scenegraph';\nimport {\n convertRawBufferToMetadataArray,\n getPrimitiveTextureData,\n primitivePropertyDataToAttributes,\n getArrayElementByteSize,\n NumericComponentType,\n getOffsetsForProperty\n} from './utils/3d-tiles-utils';\n\nconst EXT_STRUCTURAL_METADATA_NAME = 'EXT_structural_metadata';\nexport const name = EXT_STRUCTURAL_METADATA_NAME;\n\nexport async function decode(gltfData: {json: GLTF}, options: GLTFLoaderOptions): Promise<void> {\n const scenegraph = new GLTFScenegraph(gltfData);\n decodeExtStructuralMetadata(scenegraph, options);\n}\n\n/*\n// Example of the extension.\n// See more info at https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata\nconst extensions = {\n \"extensions\": {\n \"EXT_structural_metadata\": {\n \"schema\": {\n \"classes\": {\n \"tree\": {\n \"name\": \"Tree\",\n \"description\": \"Woody, perennial plant.\",\n \"properties\": {\n \"species\": {\n \"description\": \"Type of tree.\",\n \"type\": \"ENUM\",\n \"enumType\": \"speciesEnum\",\n \"required\": true\n },\n \"age\": {\n \"description\": \"The age of the tree, in years\",\n \"type\": \"SCALAR\",\n \"componentType\": \"UINT8\",\n \"required\": true\n }\n }\n }\n },\n \"enums\": {\n \"speciesEnum\": {\n \"name\": \"Species\",\n \"description\": \"An example enum for tree species.\",\n // valueType is not defined here. Default is \"UINT16\"\n \"values\": [\n { \"name\": \"Unspecified\", \"value\": 0 },\n { \"name\": \"Oak\", \"value\": 1 }\n ]\n }\n }\n },\n \"propertyTables\": [{\n \"name\": \"tree_survey_2021-09-29\",\n \"class\": \"tree\",\n \"count\": 10, // The number of elements in each property array (in `species`, in `age`).\n \"properties\": {\n \"species\": {\n \"values\": 0, // It's an index of the buffer view containing property values.\n },\n \"age\": {\n \"values\": 1\n }\n }\n }]\n }\n }\n}\n*/\n\n/**\n * Returns the property table populated with the data taken according to the extension schema.\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param propertyTableIndex - Index of the property table to locate.\n * @returns Property table populated with the data.\n * Throws an exception if no property table was found for propertyTableIndex provided.\n */\nexport function getPropertyTablePopulated(\n scenegraph: GLTFScenegraph,\n propertyTableIndex: number\n): GLTF_EXT_structural_metadata_PropertyTable {\n const extension: GLTF_EXT_structural_metadata | null = scenegraph.getExtension(\n EXT_STRUCTURAL_METADATA_NAME\n );\n const propertyTable = extension?.propertyTables?.[propertyTableIndex];\n if (extension?.schema && propertyTable) {\n processPropertyTable(scenegraph, extension.schema, propertyTable);\n return propertyTable;\n }\n throw new Error(\n `Incorrect data in the EXT_structural_metadata extension: no property table with index ${propertyTableIndex}`\n );\n}\n\n/**\n * Decodes feature metadata from extension\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param options - loader options.\n */\nfunction decodeExtStructuralMetadata(scenegraph: GLTFScenegraph, options: GLTFLoaderOptions): void {\n const extension: GLTF_EXT_structural_metadata | null = scenegraph.getExtension(\n EXT_STRUCTURAL_METADATA_NAME\n );\n if (!extension?.schema) {\n return;\n }\n\n const propertyTextures = extension.propertyTextures;\n const json = scenegraph.gltf.json;\n if (propertyTextures && json.meshes && options?.gltf?.loadImages) {\n // Iterate through all meshes/primitives.\n for (const mesh of json.meshes) {\n for (const primitive of mesh.primitives) {\n processPrimitivePropertyTextures(scenegraph, propertyTextures, primitive, extension);\n }\n }\n }\n\n const schemaClasses = extension.schema.classes;\n const propertyTables = extension.propertyTables;\n if (schemaClasses && propertyTables) {\n for (const schemaName in schemaClasses) {\n const propertyTable = findPropertyTableByClass(propertyTables, schemaName);\n if (propertyTable) {\n processPropertyTable(scenegraph, extension.schema, propertyTable);\n }\n }\n }\n}\n\n/**\n * Find the property table by class name.\n * @param propertyTables - propertyTable definition taken from the top-level extension\n * @param schemaClassName - class name in the extension schema\n */\nfunction findPropertyTableByClass(\n propertyTables: GLTF_EXT_structural_metadata_PropertyTable[],\n schemaClassName: string\n): GLTF_EXT_structural_metadata_PropertyTable | null {\n for (let i = 0, len = propertyTables.length; i < len; i++) {\n const propertyTable = propertyTables[i];\n\n if (propertyTable.class === schemaClassName) {\n return propertyTable;\n }\n }\n\n return null;\n}\n\n/**\n * Takes data from property textures reffered by the primitive\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param propertyTextures - propertyTexture definition taken from the top-level extention\n * @param primitive - Primitive object\n * @param extension - top-level extension\n */\nfunction processPrimitivePropertyTextures(\n scenegraph: GLTFScenegraph,\n propertyTextures: GLTF_EXT_structural_metadata_PropertyTexture[],\n primitive: GLTFMeshPrimitive,\n extension: GLTF_EXT_structural_metadata\n): void {\n if (!propertyTextures) {\n return;\n }\n const primitiveExtension: GLTF_EXT_structural_metadata_Primitive = primitive.extensions?.[\n EXT_STRUCTURAL_METADATA_NAME\n ] as GLTF_EXT_structural_metadata_Primitive;\n const primitivePropertyTextureIndices = primitiveExtension?.propertyTextures;\n if (!primitivePropertyTextureIndices) {\n return;\n }\n\n for (const primitivePropertyTextureIndex of primitivePropertyTextureIndices) {\n const propertyTexture = propertyTextures[primitivePropertyTextureIndex];\n processPrimitivePropertyTexture(scenegraph, propertyTexture, primitive, extension);\n }\n}\n\n/**\n * Takes property data from the texture pointed by the primitive and appends them to `exension.data`\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param propertyTexture - propertyTexture definition taken from the top-level extension.\n * @param primitive - Primitive object\n * @param extension - top-level extension\n */\nfunction processPrimitivePropertyTexture(\n scenegraph: GLTFScenegraph,\n propertyTexture: GLTF_EXT_structural_metadata_PropertyTexture,\n primitive: GLTFMeshPrimitive,\n extension: GLTF_EXT_structural_metadata\n): void {\n if (!propertyTexture.properties) {\n return;\n }\n\n if (!extension.dataAttributeNames) {\n extension.dataAttributeNames = [];\n }\n\n /* Iterate through all properties defined in propertyTexture, e.g. \"speed\" and \"direction\":\n {\n \"class\": \"wind\",\n \"properties\": {\n \"speed\": {\n \"index\": 0,\n \"texCoord\": 0,\n \"channels\": [0]\n },\n \"direction\": {\n \"index\": 0,\n \"texCoord\": 0,\n \"channels\": [1, 2]\n }\n }\n }\n */\n const className = propertyTexture.class;\n for (const propName in propertyTexture.properties) {\n // propName has values like \"speed\", \"direction\"\n // Make attributeName as a combination of the class name and the propertyName like \"wind_speed\" or \"wind_direction\"\n const attributeName = `${className}_${propName}`;\n const textureInfoTopLevel: GLTFTextureInfoMetadata | undefined =\n propertyTexture.properties?.[propName];\n if (!textureInfoTopLevel) {\n // eslint-disable-next-line no-continue\n continue;\n }\n\n // 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\n // Initially textureInfoTopLevel.data will be initialized with an empty array.\n if (!textureInfoTopLevel.data) {\n textureInfoTopLevel.data = [];\n }\n const featureTextureTable: number[] = textureInfoTopLevel.data as number[];\n\n const propertyData: number[] | null = getPrimitiveTextureData(\n scenegraph,\n textureInfoTopLevel,\n primitive\n );\n if (propertyData === null) {\n // eslint-disable-next-line no-continue\n continue;\n }\n primitivePropertyDataToAttributes(\n scenegraph,\n attributeName,\n propertyData,\n featureTextureTable,\n primitive\n );\n textureInfoTopLevel.data = featureTextureTable;\n extension.dataAttributeNames.push(attributeName);\n }\n}\n\n/**\n * Navigates through all properies in the property table, gets properties data,\n * and put the data to `propertyTable.data` as an array.\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param schema - schema object\n * @param propertyTable - propertyTable definition taken from the top-level extension\n */\nfunction processPropertyTable(\n scenegraph: GLTFScenegraph,\n schema: GLTF_EXT_structural_metadata_Schema,\n propertyTable: GLTF_EXT_structural_metadata_PropertyTable\n): void {\n const schemaClass = schema.classes?.[propertyTable.class];\n if (!schemaClass) {\n throw new Error(\n `Incorrect data in the EXT_structural_metadata extension: no schema class with name ${propertyTable.class}`\n );\n }\n\n const numberOfElements = propertyTable.count; // `propertyTable.count` is a number of elements in each property array.\n\n for (const propertyName in schemaClass.properties) {\n const classProperty = schemaClass.properties[propertyName];\n const propertyTableProperty: GLTF_EXT_structural_metadata_PropertyTable_Property | undefined =\n propertyTable.properties?.[propertyName];\n\n if (propertyTableProperty) {\n // Getting all elements (`numberOfElements`) of the array in the `propertyTableProperty`\n const data = getPropertyDataFromBinarySource(\n scenegraph,\n schema,\n classProperty,\n numberOfElements,\n propertyTableProperty\n );\n propertyTableProperty.data = data;\n }\n }\n}\n\n/**\n * Decodes a propertyTable column from binary source based on property type\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param schema - Schema object\n * @param classProperty - class property object\n * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.\n * @param propertyTableProperty - propertyTable's property metadata\n * @returns {string[] | number[] | string[][] | number[][]}\n */\nfunction getPropertyDataFromBinarySource(\n scenegraph: GLTFScenegraph,\n schema: GLTF_EXT_structural_metadata_Schema,\n classProperty: GLTF_EXT_structural_metadata_ClassProperty,\n numberOfElements: number,\n propertyTableProperty: GLTF_EXT_structural_metadata_PropertyTable_Property\n): string[] | BigTypedArray | string[][] | BigTypedArray[] {\n let data: string[] | BigTypedArray | string[][] | BigTypedArray[] = [];\n const valuesBufferView = propertyTableProperty.values;\n const valuesDataBytes: Uint8Array = scenegraph.getTypedArrayForBufferView(valuesBufferView);\n\n const arrayOffsets = getArrayOffsetsForProperty(\n scenegraph,\n classProperty,\n propertyTableProperty,\n numberOfElements\n );\n const stringOffsets = getStringOffsetsForProperty(\n scenegraph,\n propertyTableProperty,\n numberOfElements\n );\n\n switch (classProperty.type) {\n case 'SCALAR':\n case 'VEC2':\n case 'VEC3':\n case 'VEC4':\n case 'MAT2':\n case 'MAT3':\n case 'MAT4': {\n data = getPropertyDataNumeric(classProperty, numberOfElements, valuesDataBytes, arrayOffsets);\n break;\n }\n case 'BOOLEAN': {\n // TODO: implement it as soon as we have the corresponding tileset\n throw new Error(`Not implemented - classProperty.type=${classProperty.type}`);\n }\n case 'STRING': {\n data = getPropertyDataString(\n classProperty,\n numberOfElements,\n valuesDataBytes,\n arrayOffsets,\n stringOffsets\n );\n break;\n }\n case 'ENUM': {\n data = getPropertyDataENUM(\n schema,\n classProperty,\n numberOfElements,\n valuesDataBytes,\n arrayOffsets\n );\n break;\n }\n default:\n throw new Error(`Unknown classProperty type ${classProperty.type}`);\n }\n\n return data;\n}\n\n/**\n * Parse propertyTable.property.arrayOffsets that are offsets of sub-arrays in a flatten array of values\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param classProperty - class property object\n * @param propertyTableProperty - propertyTable's property metadata\n * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.\n * @returns typed array with offset values\n * @see https://github.com/CesiumGS/glTF/blob/2976f1183343a47a29e4059a70961371cd2fcee8/extensions/2.0/Vendor/EXT_structural_metadata/schema/propertyTable.property.schema.json#L21\n */\nfunction getArrayOffsetsForProperty(\n scenegraph: GLTFScenegraph,\n classProperty: GLTF_EXT_structural_metadata_ClassProperty,\n propertyTableProperty: GLTF_EXT_structural_metadata_PropertyTable_Property,\n numberOfElements: number\n): TypedArray | null {\n if (\n classProperty.array &&\n // `count` is a number of array elements. May only be defined when `array` is true.\n // If `count` is NOT defined, it's a VARIABLE-length array\n typeof classProperty.count === 'undefined' &&\n // `arrayOffsets` is an index of the buffer view containing offsets for variable-length arrays.\n typeof propertyTableProperty.arrayOffsets !== 'undefined' &&\n typeof propertyTableProperty.arrayOffsetType !== 'undefined'\n ) {\n // Data are in a VARIABLE-length array\n return getOffsetsForProperty(\n scenegraph,\n propertyTableProperty.arrayOffsets,\n propertyTableProperty.arrayOffsetType,\n numberOfElements\n );\n }\n return null;\n}\n\n/**\n * Parse propertyTable.property.stringOffsets\n * @param scenegraph - Instance of the class for structured access to GLTF data\n * @param propertyTableProperty - propertyTable's property metadata\n * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table\n * @returns typed array with offset values\n * @see https://github.com/CesiumGS/glTF/blob/2976f1183343a47a29e4059a70961371cd2fcee8/extensions/2.0/Vendor/EXT_structural_metadata/schema/propertyTable.property.schema.json#L29C10-L29C23\n */\nfunction getStringOffsetsForProperty(\n scenegraph: GLTFScenegraph,\n propertyTableProperty: GLTF_EXT_structural_metadata_PropertyTable_Property,\n numberOfElements: number\n): TypedArray | null {\n if (\n typeof propertyTableProperty.stringOffsets !== 'undefined' && // `stringOffsets` is an index of the buffer view containing offsets for strings.\n typeof propertyTableProperty.stringOffsetType !== 'undefined'\n ) {\n // Data are in a FIXED-length array\n return getOffsetsForProperty(\n scenegraph,\n propertyTableProperty.stringOffsets,\n propertyTableProperty.stringOffsetType,\n numberOfElements\n );\n }\n return null;\n}\n\n/**\n * Decodes properties of SCALAR, VEC-N, MAT-N types from binary sourse.\n * @param classProperty - class property object\n * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.\n * @param valuesDataBytes - data taken from values property of the property table property.\n * @param arrayOffsets - offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.\n * @returns property values in a typed array or in an array of typed arrays\n */\nfunction getPropertyDataNumeric(\n classProperty: GLTF_EXT_structural_metadata_ClassProperty,\n numberOfElements: number,\n valuesDataBytes: Uint8Array,\n arrayOffsets: TypedArray | null\n): BigTypedArray | BigTypedArray[] {\n const isArray = classProperty.array;\n const arrayCount = classProperty.count;\n\n const elementSize = getArrayElementByteSize(classProperty.type, classProperty.componentType);\n const elementCount = valuesDataBytes.byteLength / elementSize;\n\n let valuesData: BigTypedArray | null;\n if (classProperty.componentType) {\n valuesData = convertRawBufferToMetadataArray(\n valuesDataBytes,\n classProperty.type,\n // The datatype of the element's components. Only applicable to `SCALAR`, `VECN`, and `MATN` types.\n classProperty.componentType as NumericComponentType,\n elementCount\n );\n if (!valuesData) {\n valuesData = valuesDataBytes;\n }\n } else {\n // The spec doesn't provide any info what to do if componentType is not set.\n valuesData = valuesDataBytes;\n }\n\n if (isArray) {\n if (arrayOffsets) {\n // VARIABLE-length array\n return parseVariableLengthArrayNumeric(\n valuesData,\n numberOfElements,\n arrayOffsets,\n valuesDataBytes.length,\n elementSize\n );\n }\n if (arrayCount) {\n // FIXED-length array\n return parseFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount);\n }\n return [];\n }\n\n return valuesData;\n}\n\n/**\n * Parse variable-length array data.\n * In this case every value of the property in the table will be an array\n * of arbitrary length\n * @param valuesData - values in a flat typed array\n * @param numberOfElements - number of rows in the property table\n * @param arrayOffsets - offsets of nested arrays in the flat values array\n * @param valuesDataBytesLength - data byte length\n * @param valueSize - value size in bytes\n * @returns array of typed arrays\n */\nfunction parseVariableLengthArrayNumeric(\n valuesData: BigTypedArray,\n numberOfElements: number,\n arrayOffsets: TypedArray,\n valuesDataBytesLength: number,\n valueSize: number\n): BigTypedArray[] {\n const attributeValueArray: BigTypedArray[] = [];\n for (let index = 0; index < numberOfElements; index++) {\n const arrayOffset = arrayOffsets[index];\n const arrayByteSize = arrayOffsets[index + 1] - arrayOffsets[index];\n if (arrayByteSize + arrayOffset > valuesDataBytesLength) {\n break;\n }\n const typedArrayOffset = arrayOffset / valueSize;\n const elementCount = arrayByteSize / valueSize;\n attributeValueArray.push(valuesData.slice(typedArrayOffset, typedArrayOffset + elementCount));\n }\n return attributeValueArray;\n}\n\n/**\n * Parse fixed-length array data\n * In this case every value of the property in the table will be an array\n * of constant length equal to `arrayCount`\n * @param valuesData - values in a flat typed array\n * @param numberOfElements - number of rows in the property table\n * @param arrayCount - nested arrays length\n * @returns array of typed arrays\n */\nfunction parseFixedLengthArrayNumeric(\n valuesData: BigTypedArray,\n numberOfElements: number,\n arrayCount: number\n): BigTypedArray[] {\n const attributeValueArray: BigTypedArray[] = [];\n for (let index = 0; index < numberOfElements; index++) {\n const elementOffset = index * arrayCount;\n attributeValueArray.push(valuesData.slice(elementOffset, elementOffset + arrayCount));\n }\n return attributeValueArray;\n}\n\n/**\n * Decodes properties of string type from binary source.\n * @param classProperty - class property object\n * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.\n * @param valuesDataBytes - data taken from values property of the property table property.\n * @param arrayOffsets - offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.\n * @param stringOffsets - index of the buffer view containing offsets for strings. It should be available for string type.\n * @returns string property values\n */\nfunction getPropertyDataString(\n classProperty: GLTF_EXT_structural_metadata_ClassProperty,\n numberOfElements: number,\n valuesDataBytes: Uint8Array,\n arrayOffsets: TypedArray | null,\n stringOffsets: TypedArray | null\n): string[] | string[][] {\n if (arrayOffsets) {\n // TODO: implement it as soon as we have the corresponding tileset\n throw new Error(`Not implemented - classProperty.type=${classProperty.type}`);\n }\n\n if (stringOffsets) {\n const stringsArray: string[] = [];\n const textDecoder = new TextDecoder('utf8');\n\n let stringOffset = 0;\n for (let index = 0; index < numberOfElements; index++) {\n const stringByteSize = stringOffsets[index + 1] - stringOffsets[index];\n\n if (stringByteSize + stringOffset <= valuesDataBytes.length) {\n const stringData = valuesDataBytes.subarray(stringOffset, stringByteSize + stringOffset);\n const stringAttribute = textDecoder.decode(stringData);\n\n stringsArray.push(stringAttribute);\n stringOffset += stringByteSize;\n }\n }\n\n return stringsArray;\n }\n return [];\n}\n\n/**\n * Decodes properties of enum type from binary source.\n * @param schema - schema object\n * @param classProperty - class property object\n * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.\n * @param valuesDataBytes - data taken from values property of the property table property.\n * @param arrayOffsets - offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.\n * @returns strings array of nested strings array\n */\nfunction getPropertyDataENUM(\n schema: GLTF_EXT_structural_metadata_Schema,\n classProperty: GLTF_EXT_structural_metadata_ClassProperty,\n numberOfElements: number,\n valuesDataBytes: Uint8Array,\n arrayOffsets: TypedArray | null\n): string[] | string[][] {\n const enumType = classProperty.enumType;\n // Enum ID as declared in the `enums` dictionary. Required when `type` is `ENUM`.\n if (!enumType) {\n throw new Error(\n 'Incorrect data in the EXT_structural_metadata extension: classProperty.enumType is not set for type ENUM'\n );\n }\n\n const enumEntry: GLTF_EXT_structural_metadata_Enum | undefined = schema.enums?.[enumType];\n if (!enumEntry) {\n throw new Error(\n `Incorrect data in the EXT_structural_metadata extension: schema.enums does't contain ${enumType}`\n );\n }\n\n const enumValueType = enumEntry.valueType || 'UINT16';\n const elementSize = getArrayElementByteSize(classProperty.type, enumValueType);\n const elementCount = valuesDataBytes.byteLength / elementSize;\n let valuesData: BigTypedArray | null = convertRawBufferToMetadataArray(\n valuesDataBytes,\n classProperty.type,\n enumValueType,\n elementCount\n );\n if (!valuesData) {\n valuesData = valuesDataBytes;\n }\n\n if (classProperty.array) {\n if (arrayOffsets) {\n // VARIABLE-length array\n return parseVariableLengthArrayENUM({\n valuesData,\n numberOfElements,\n arrayOffsets,\n valuesDataBytesLength: valuesDataBytes.length,\n elementSize,\n enumEntry\n });\n }\n\n const arrayCount = classProperty.count;\n if (arrayCount) {\n // FIXED-length array\n return parseFixedLengthArrayENUM(valuesData, numberOfElements, arrayCount, enumEntry);\n }\n return [];\n }\n\n // Single value (not an array)\n return getEnumsArray(valuesData, 0, numberOfElements, enumEntry);\n}\n\n/**\n * Parse variable length nested ENUM arrays\n * @param params.valuesData - values in a flat typed array\n * @param params.numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.\n * @param params.arrayOffsets - offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.\n * @param params.valuesDataBytesLength - byte length of values array\n * @param params.elementSize - single element byte size\n * @param params.enumEntry - enums dictionary\n * @returns nested strings array\n */\nfunction parseVariableLengthArrayENUM(params: {\n valuesData: BigTypedArray;\n numberOfElements: number;\n arrayOffsets: TypedArray;\n valuesDataBytesLength: number;\n elementSize: number;\n enumEntry: GLTF_EXT_structural_metadata_Enum;\n}): string[][] {\n const {\n valuesData,\n numberOfElements,\n arrayOffsets,\n valuesDataBytesLength,\n elementSize,\n enumEntry\n } = params;\n const attributeValueArray: string[][] = [];\n for (let index = 0; index < numberOfElements; index++) {\n const arrayOffset = arrayOffsets[index];\n const arrayByteSize = arrayOffsets[index + 1] - arrayOffsets[index];\n if (arrayByteSize + arrayOffset > valuesDataBytesLength) {\n break;\n }\n\n const typedArrayOffset = arrayOffset / elementSize;\n const elementCount = arrayByteSize / elementSize;\n const array: string[] = getEnumsArray(valuesData, typedArrayOffset, elementCount, enumEntry);\n attributeValueArray.push(array);\n }\n return attributeValueArray;\n}\n\n/**\n * Parse fixed length ENUM arrays\n * @param valuesData - values in a flat typed array\n * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.\n * @param arrayCount - nested arrays length\n * @param enumEntry - enums dictionary\n * @returns nested strings array\n */\nfunction parseFixedLengthArrayENUM(\n valuesData: BigTypedArray,\n numberOfElements: number,\n arrayCount: number,\n enumEntry: GLTF_EXT_structural_metadata_Enum\n): string[][] {\n const attributeValueArray: string[][] = [];\n for (let index = 0; index < numberOfElements; index++) {\n const elementOffset = arrayCount * index;\n const array: string[] = getEnumsArray(valuesData, elementOffset, arrayCount, enumEntry);\n attributeValueArray.push(array);\n }\n return attributeValueArray;\n}\n\n/**\n * Parse ENUM values into a string array\n * @param valuesData - values in a flat typed array\n * @param offset - offset to start parse from\n * @param count - values length to parse\n * @param enumEntry - enums dictionary\n * @returns array of string with parsed ENUM names\n */\nfunction getEnumsArray(\n valuesData: BigTypedArray,\n offset: number,\n count: number,\n enumEntry: GLTF_EXT_structural_metadata_Enum\n): string[] {\n const array: string[] = [];\n for (let i = 0; i < count; i++) {\n // At the moment we don't support BigInt. It requires additional calculations logic\n // and might be an issue in Safari\n if (valuesData instanceof BigInt64Array || valuesData instanceof BigUint64Array) {\n array.push('');\n } else {\n const value = valuesData[offset + i];\n\n const enumObject = getEnumByValue(enumEntry, value);\n if (enumObject) {\n array.push(enumObject.name);\n } else {\n array.push('');\n }\n }\n }\n return array;\n}\n\n/**\n * Looks up ENUM whose `value` property matches the specified number in the parameter `value`.\n * @param {GLTF_EXT_structural_metadata_Enum} enumEntry - ENUM entry containing the array of possible enums.\n * @param {number} value - the value of the ENUM to locate.\n * @returns {GLTF_EXT_structural_metadata_EnumValue | null} ENUM matcihng the specified value or null of no ENUM object was found.\n */\nfunction getEnumByValue(\n enumEntry: GLTF_EXT_structural_metadata_Enum,\n value: number\n): GLTF_EXT_structural_metadata_EnumValue | null {\n for (const enumValue of enumEntry.values) {\n if (enumValue.value === value) {\n return enumValue;\n }\n }\n\n return null;\n}\n"],"mappings":"AAgBA,SAAQA,cAAc,QAAO,wBAAwB;AACrD,SACEC,+BAA+B,EAC/BC,uBAAuB,EACvBC,iCAAiC,EACjCC,uBAAuB,EAEvBC,qBAAqB,QAChB,wBAAwB;AAE/B,MAAMC,4BAA4B,GAAG,yBAAyB;AAC9D,OAAO,MAAMC,IAAI,GAAGD,4BAA4B;AAEhD,OAAO,eAAeE,MAAMA,CAACC,QAAsB,EAAEC,OAA0B,EAAiB;EAC9F,MAAMC,UAAU,GAAG,IAAIX,cAAc,CAACS,QAAQ,CAAC;EAC/CG,2BAA2B,CAACD,UAAU,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AAE,CAAC;IAChB,CAAC,MAAM;MACL,MAAMgE,KAAK,GAAGjC,UAAU,CAAC8B,MAAM,GAAGlF,CAAC,CAAC;MAEpC,MAAMsF,UAAU,GAAGC,cAAc,CAACb,SAAS,EAAEW,KAAK,CAAC;MACnD,IAAIC,UAAU,EAAE;QACd3C,KAAK,CAACtB,IAAI,CAACiE,UAAU,CAACtH,IAAI,CAAC;MAC7B,CAAC,MAAM;QACL2E,KAAK,CAACtB,IAAI,CAAC,EAAE,CAAC;MAChB;IACF;EACF;EACA,OAAOsB,KAAK;AACd;AAQA,SAAS4C,cAAcA,CACrBb,SAA4C,EAC5CW,KAAa,EACkC;EAC/C,KAAK,MAAMG,SAAS,IAAId,SAAS,CAAC1C,MAAM,EAAE;IACxC,IAAIwD,SAAS,CAACH,KAAK,KAAKA,KAAK,EAAE;MAC7B,OAAOG,SAAS;IAClB;EACF;EAEA,OAAO,IAAI;AACb"}
|
|
1
|
+
{"version":3,"file":"EXT_structural_metadata.js","names":["GLTFScenegraph","convertRawBufferToMetadataArray","getPrimitiveTextureData","primitivePropertyDataToAttributes","getArrayElementByteSize","getOffsetsForProperty","EXT_STRUCTURAL_METADATA_NAME","name","decode","gltfData","options","scenegraph","decodeExtStructuralMetadata","getPropertyTableFromExtStructuralMetadata","extension","metadataClass","propertyTables","firstPropertyTable","propertyTableWithData","propertyName","properties","data","propertyTextures","firstPropertyTexture","console","warn","getPropertyTablePopulated","propertyTableIndex","_extension$propertyTa","getExtension","propertyTable","schema","processPropertyTable","Error","concat","_options$gltf","_options$gltf2","gltf","loadBuffers","loadImages","decodePropertyTextures","decodePropertyTables","json","meshes","mesh","primitive","primitives","processPrimitivePropertyTextures","schemaClasses","classes","schemaName","findPropertyTableByClass","schemaClassName","class","_primitive$extensions","primitiveExtension","extensions","primitivePropertyTextureIndices","primitivePropertyTextureIndex","propertyTexture","processPrimitivePropertyTexture","dataAttributeNames","className","_propertyTexture$prop","attributeName","textureInfoTopLevel","featureTextureTable","propertyData","push","_schema$classes","schemaClass","numberOfElements","count","_propertyTable$proper","classProperty","propertyTableProperty","getPropertyDataFromBinarySource","valuesBufferView","values","valuesDataBytes","getTypedArrayForBufferView","arrayOffsets","getArrayOffsetsForProperty","stringOffsets","getStringOffsetsForProperty","type","getPropertyDataNumeric","getPropertyDataString","getPropertyDataENUM","array","arrayOffsetType","stringOffsetType","isArray","arrayCount","elementSize","componentType","elementCount","byteLength","valuesData","parseVariableLengthArrayNumeric","length","parseFixedLengthArrayNumeric","valuesDataBytesLength","valueSize","attributeValueArray","index","arrayOffset","arrayByteSize","typedArrayOffset","slice","elementOffset","stringsArray","textDecoder","TextDecoder","stringOffset","stringByteSize","stringData","subarray","stringAttribute","_schema$enums","enumType","enumEntry","enums","enumValueType","valueType","parseVariableLengthArrayENUM","parseFixedLengthArrayENUM","getEnumsArray","params","offset","i","BigInt64Array","BigUint64Array","value","enumObject","getEnumByValue","enumValue"],"sources":["../../../../src/lib/extensions/EXT_structural_metadata.ts"],"sourcesContent":["// GLTF EXTENSION: EXT_structural_metadata\n// https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata\n/* eslint-disable camelcase */\nimport type {BigTypedArray, TypedArray} from '@loaders.gl/schema';\nimport type {GLTF, GLTFTextureInfoMetadata, GLTFMeshPrimitive} from '../types/gltf-json-schema';\nimport type {\n GLTF_EXT_structural_metadata_Schema,\n GLTF_EXT_structural_metadata_ClassProperty,\n GLTF_EXT_structural_metadata_Enum,\n GLTF_EXT_structural_metadata_EnumValue,\n GLTF_EXT_structural_metadata_PropertyTable,\n GLTF_EXT_structural_metadata_GLTF,\n GLTF_EXT_structural_metadata_PropertyTexture,\n GLTF_EXT_structural_metadata_PropertyTable_Property,\n GLTF_EXT_structural_metadata_Primitive\n} from '../types/gltf-ext-structural-metadata-schema';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\nimport type {FeatureTableJson} from '../types/gltf-types';\n\nimport {GLTFScenegraph} from '../api/gltf-scenegraph';\nimport {\n convertRawBufferToMetadataArray,\n getPrimitiveTextureData,\n primitivePropertyDataToAttributes,\n getArrayElementByteSize,\n NumericComponentType,\n getOffsetsForProperty\n} from './utils/3d-tiles-utils';\n\nconst EXT_STRUCTURAL_METADATA_NAME = 'EXT_structural_metadata';\nexport const name = EXT_STRUCTURAL_METADATA_NAME;\n\nexport async function decode(gltfData: {json: GLTF}, options: GLTFLoaderOptions): Promise<void> {\n const scenegraph = new GLTFScenegraph(gltfData);\n decodeExtStructuralMetadata(scenegraph, options);\n}\n\n/**\n * Handles EXT_structural_metadata to get property table.\n * @param extension - Global level of EXT_STRUCTURAL_METADATA extension.\n * @param metadataClass - User selected feature metadata class name.\n * @returns {FeatureTableJson | null} Property table or null if the extension can't be handled properly.\n */\nexport function getPropertyTableFromExtStructuralMetadata(\n extension: GLTF_EXT_structural_metadata_GLTF,\n metadataClass?: string\n): FeatureTableJson | null {\n if (extension.propertyTables) {\n /**\n * Take only first feature table to generate attributes storage info object.\n * TODO: Think about getting data from all feature tables?\n * It can be tricky just because 3dTiles is able to have multiple featureId attributes and multiple feature tables.\n * In I3S we should decide which featureIds attribute will be passed to geometry data.\n */\n const firstPropertyTable = extension?.propertyTables[0];\n const propertyTableWithData = {};\n\n for (const propertyName in firstPropertyTable.properties) {\n propertyTableWithData[propertyName] = firstPropertyTable.properties[propertyName].data;\n }\n\n return propertyTableWithData;\n }\n\n if (extension.propertyTextures) {\n // TODO: Think about getting data from all property textures.\n const firstPropertyTexture = extension?.propertyTextures[0];\n const propertyTableWithData = {};\n\n for (const propertyName in firstPropertyTexture.properties) {\n propertyTableWithData[propertyName] = firstPropertyTexture.properties[propertyName].data;\n }\n\n return propertyTableWithData;\n }\n\n // eslint-disable-next-line no-console\n console.warn(\n 'Cannot get property table from EXT_structural_metadata extension. There is neither propertyTables, nor propertyTextures in the extension.'\n );\n return null;\n}\n\n/*\n// Example of the extension.\n// See more info at https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata\nconst extensions = {\n \"extensions\": {\n \"EXT_structural_metadata\": {\n \"schema\": {\n \"classes\": {\n \"tree\": {\n \"name\": \"Tree\",\n \"description\": \"Woody, perennial plant.\",\n \"properties\": {\n \"species\": {\n \"description\": \"Type of tree.\",\n \"type\": \"ENUM\",\n \"enumType\": \"speciesEnum\",\n \"required\": true\n },\n \"age\": {\n \"description\": \"The age of the tree, in years\",\n \"type\": \"SCALAR\",\n \"componentType\": \"UINT8\",\n \"required\": true\n }\n }\n }\n },\n \"enums\": {\n \"speciesEnum\": {\n \"name\": \"Species\",\n \"description\": \"An example enum for tree species.\",\n // valueType is not defined here. Default is \"UINT16\"\n \"values\": [\n { \"name\": \"Unspecified\", \"value\": 0 },\n { \"name\": \"Oak\", \"value\": 1 }\n ]\n }\n }\n },\n \"propertyTables\": [{\n \"name\": \"tree_survey_2021-09-29\",\n \"class\": \"tree\",\n \"count\": 10, // The number of elements in each property array (in `species`, in `age`).\n \"properties\": {\n \"species\": {\n \"values\": 0, // It's an index of the buffer view containing property values.\n },\n \"age\": {\n \"values\": 1\n }\n }\n }]\n }\n }\n}\n*/\n\n/**\n * Returns the property table populated with the data taken according to the extension schema.\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param propertyTableIndex - Index of the property table to locate.\n * @returns Property table populated with the data.\n * Throws an exception if no property table was found for propertyTableIndex provided.\n */\nexport function getPropertyTablePopulated(\n scenegraph: GLTFScenegraph,\n propertyTableIndex: number\n): GLTF_EXT_structural_metadata_PropertyTable {\n const extension: GLTF_EXT_structural_metadata_GLTF | null = scenegraph.getExtension(\n EXT_STRUCTURAL_METADATA_NAME\n );\n const propertyTable = extension?.propertyTables?.[propertyTableIndex];\n if (extension?.schema && propertyTable) {\n processPropertyTable(scenegraph, extension.schema, propertyTable);\n return propertyTable;\n }\n throw new Error(\n `Incorrect data in the EXT_structural_metadata extension: no property table with index ${propertyTableIndex}`\n );\n}\n\n/**\n * Decodes feature metadata from extension.\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param options - GLTFLoader options.\n */\nfunction decodeExtStructuralMetadata(scenegraph: GLTFScenegraph, options: GLTFLoaderOptions): void {\n // Decoding metadata involves buffers processing.\n // So, if buffers have not been loaded, there is no reason to process metadata.\n if (!options.gltf?.loadBuffers) {\n return;\n }\n const extension: GLTF_EXT_structural_metadata_GLTF | null = scenegraph.getExtension(\n EXT_STRUCTURAL_METADATA_NAME\n );\n if (!extension) {\n return;\n }\n\n if (options.gltf?.loadImages) {\n decodePropertyTextures(scenegraph, extension);\n }\n\n decodePropertyTables(scenegraph, extension);\n}\n\n/**\n * Processes the data stored in the textures\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param extension - Top-level extension.\n */\nfunction decodePropertyTextures(\n scenegraph: GLTFScenegraph,\n extension: GLTF_EXT_structural_metadata_GLTF\n): void {\n const propertyTextures = extension.propertyTextures;\n const json = scenegraph.gltf.json;\n if (propertyTextures && json.meshes) {\n // Iterate through all meshes/primitives.\n for (const mesh of json.meshes) {\n for (const primitive of mesh.primitives) {\n processPrimitivePropertyTextures(scenegraph, propertyTextures, primitive, extension);\n }\n }\n }\n}\n\n/**\n * Processes the data stored in the property tables.\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param extension - Top-level extension.\n */\nfunction decodePropertyTables(\n scenegraph: GLTFScenegraph,\n extension: GLTF_EXT_structural_metadata_GLTF\n): void {\n const schema = extension.schema;\n if (!schema) {\n return;\n }\n const schemaClasses = schema.classes;\n const propertyTables = extension.propertyTables;\n if (schemaClasses && propertyTables) {\n for (const schemaName in schemaClasses) {\n const propertyTable = findPropertyTableByClass(propertyTables, schemaName);\n if (propertyTable) {\n processPropertyTable(scenegraph, schema, propertyTable);\n }\n }\n }\n}\n\n/**\n * Finds the property table by class name.\n * @param propertyTables - propertyTable definition taken from the top-level extension.\n * @param schemaClassName - class name in the extension schema.\n */\nfunction findPropertyTableByClass(\n propertyTables: GLTF_EXT_structural_metadata_PropertyTable[],\n schemaClassName: string\n): GLTF_EXT_structural_metadata_PropertyTable | null {\n for (const propertyTable of propertyTables) {\n if (propertyTable.class === schemaClassName) {\n return propertyTable;\n }\n }\n\n return null;\n}\n\n/**\n * Takes data from property textures reffered by the primitive.\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param propertyTextures - propertyTexture definition taken from the top-level extention.\n * @param primitive - Primitive object.\n * @param extension - Top-level extension.\n */\nfunction processPrimitivePropertyTextures(\n scenegraph: GLTFScenegraph,\n propertyTextures: GLTF_EXT_structural_metadata_PropertyTexture[],\n primitive: GLTFMeshPrimitive,\n extension: GLTF_EXT_structural_metadata_GLTF\n): void {\n if (!propertyTextures) {\n return;\n }\n const primitiveExtension: GLTF_EXT_structural_metadata_Primitive = primitive.extensions?.[\n EXT_STRUCTURAL_METADATA_NAME\n ] as GLTF_EXT_structural_metadata_Primitive;\n const primitivePropertyTextureIndices = primitiveExtension?.propertyTextures;\n if (!primitivePropertyTextureIndices) {\n return;\n }\n\n for (const primitivePropertyTextureIndex of primitivePropertyTextureIndices) {\n const propertyTexture = propertyTextures[primitivePropertyTextureIndex];\n processPrimitivePropertyTexture(scenegraph, propertyTexture, primitive, extension);\n }\n}\n\n/**\n * Takes property data from the texture pointed by the primitive and appends them to `exension.data`.\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param propertyTexture - propertyTexture definition taken from the top-level extension.\n * @param primitive - Primitive object.\n * @param extension - Top-level extension.\n */\nfunction processPrimitivePropertyTexture(\n scenegraph: GLTFScenegraph,\n propertyTexture: GLTF_EXT_structural_metadata_PropertyTexture,\n primitive: GLTFMeshPrimitive,\n extension: GLTF_EXT_structural_metadata_GLTF\n): void {\n if (!propertyTexture.properties) {\n return;\n }\n\n if (!extension.dataAttributeNames) {\n extension.dataAttributeNames = [];\n }\n\n /* Iterate through all properties defined in propertyTexture, e.g. \"speed\" and \"direction\":\n {\n \"class\": \"wind\",\n \"properties\": {\n \"speed\": {\n \"index\": 0,\n \"texCoord\": 0,\n \"channels\": [0]\n },\n \"direction\": {\n \"index\": 0,\n \"texCoord\": 0,\n \"channels\": [1, 2]\n }\n }\n }\n */\n const className = propertyTexture.class;\n for (const propertyName in propertyTexture.properties) {\n // propertyName has values like \"speed\", \"direction\"\n // Make attributeName as a combination of the class name and the propertyName like \"wind_speed\" or \"wind_direction\"\n const attributeName = `${className}_${propertyName}`;\n const textureInfoTopLevel: GLTFTextureInfoMetadata | undefined =\n propertyTexture.properties?.[propertyName];\n if (!textureInfoTopLevel) {\n // eslint-disable-next-line no-continue\n continue;\n }\n\n // 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\n // Initially textureInfoTopLevel.data will be initialized with an empty array.\n if (!textureInfoTopLevel.data) {\n textureInfoTopLevel.data = [];\n }\n const featureTextureTable: number[] = textureInfoTopLevel.data as number[];\n\n const propertyData: number[] | null = getPrimitiveTextureData(\n scenegraph,\n textureInfoTopLevel,\n primitive\n );\n if (propertyData === null) {\n // eslint-disable-next-line no-continue\n continue;\n }\n primitivePropertyDataToAttributes(\n scenegraph,\n attributeName,\n propertyData,\n featureTextureTable,\n primitive\n );\n textureInfoTopLevel.data = featureTextureTable;\n extension.dataAttributeNames.push(attributeName);\n }\n}\n\n/**\n * Navigates through all properies in the property table, gets properties data,\n * and put the data to `propertyTable.data` as an array.\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param schema - schema object.\n * @param propertyTable - propertyTable definition taken from the top-level extension.\n */\nfunction processPropertyTable(\n scenegraph: GLTFScenegraph,\n schema: GLTF_EXT_structural_metadata_Schema,\n propertyTable: GLTF_EXT_structural_metadata_PropertyTable\n): void {\n const schemaClass = schema.classes?.[propertyTable.class];\n if (!schemaClass) {\n throw new Error(\n `Incorrect data in the EXT_structural_metadata extension: no schema class with name ${propertyTable.class}`\n );\n }\n\n const numberOfElements = propertyTable.count; // `propertyTable.count` is a number of elements in each property array.\n\n for (const propertyName in schemaClass.properties) {\n const classProperty = schemaClass.properties[propertyName];\n const propertyTableProperty: GLTF_EXT_structural_metadata_PropertyTable_Property | undefined =\n propertyTable.properties?.[propertyName];\n\n if (propertyTableProperty) {\n // Getting all elements (`numberOfElements`) of the array in the `propertyTableProperty`\n const data = getPropertyDataFromBinarySource(\n scenegraph,\n schema,\n classProperty,\n numberOfElements,\n propertyTableProperty\n );\n propertyTableProperty.data = data;\n }\n }\n}\n\n/**\n * Decodes a propertyTable column from binary source based on property type.\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param schema - Schema object.\n * @param classProperty - class property object.\n * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.\n * @param propertyTableProperty - propertyTable's property metadata.\n * @returns {string[] | number[] | string[][] | number[][]}\n */\nfunction getPropertyDataFromBinarySource(\n scenegraph: GLTFScenegraph,\n schema: GLTF_EXT_structural_metadata_Schema,\n classProperty: GLTF_EXT_structural_metadata_ClassProperty,\n numberOfElements: number,\n propertyTableProperty: GLTF_EXT_structural_metadata_PropertyTable_Property\n): string[] | BigTypedArray | string[][] | BigTypedArray[] {\n let data: string[] | BigTypedArray | string[][] | BigTypedArray[] = [];\n const valuesBufferView = propertyTableProperty.values;\n const valuesDataBytes: Uint8Array = scenegraph.getTypedArrayForBufferView(valuesBufferView);\n\n const arrayOffsets = getArrayOffsetsForProperty(\n scenegraph,\n classProperty,\n propertyTableProperty,\n numberOfElements\n );\n const stringOffsets = getStringOffsetsForProperty(\n scenegraph,\n propertyTableProperty,\n numberOfElements\n );\n\n switch (classProperty.type) {\n case 'SCALAR':\n case 'VEC2':\n case 'VEC3':\n case 'VEC4':\n case 'MAT2':\n case 'MAT3':\n case 'MAT4': {\n data = getPropertyDataNumeric(classProperty, numberOfElements, valuesDataBytes, arrayOffsets);\n break;\n }\n case 'BOOLEAN': {\n // TODO: implement it as soon as we have the corresponding tileset\n throw new Error(`Not implemented - classProperty.type=${classProperty.type}`);\n }\n case 'STRING': {\n data = getPropertyDataString(\n classProperty,\n numberOfElements,\n valuesDataBytes,\n arrayOffsets,\n stringOffsets\n );\n break;\n }\n case 'ENUM': {\n data = getPropertyDataENUM(\n schema,\n classProperty,\n numberOfElements,\n valuesDataBytes,\n arrayOffsets\n );\n break;\n }\n default:\n throw new Error(`Unknown classProperty type ${classProperty.type}`);\n }\n\n return data;\n}\n\n/**\n * Parses propertyTable.property.arrayOffsets that are offsets of sub-arrays in a flatten array of values.\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param classProperty - class property object.\n * @param propertyTableProperty - propertyTable's property metadata.\n * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.\n * @returns Typed array with offset values.\n * @see https://github.com/CesiumGS/glTF/blob/2976f1183343a47a29e4059a70961371cd2fcee8/extensions/2.0/Vendor/EXT_structural_metadata/schema/propertyTable.property.schema.json#L21\n */\nfunction getArrayOffsetsForProperty(\n scenegraph: GLTFScenegraph,\n classProperty: GLTF_EXT_structural_metadata_ClassProperty,\n propertyTableProperty: GLTF_EXT_structural_metadata_PropertyTable_Property,\n numberOfElements: number\n): TypedArray | null {\n if (\n classProperty.array &&\n // `count` is a number of array elements. May only be defined when `array` is true.\n // If `count` is NOT defined, it's a VARIABLE-length array\n typeof classProperty.count === 'undefined' &&\n // `arrayOffsets` is an index of the buffer view containing offsets for variable-length arrays.\n typeof propertyTableProperty.arrayOffsets !== 'undefined'\n ) {\n // Data are in a VARIABLE-length array\n return getOffsetsForProperty(\n scenegraph,\n propertyTableProperty.arrayOffsets,\n propertyTableProperty.arrayOffsetType || 'UINT32',\n numberOfElements\n );\n }\n return null;\n}\n\n/**\n * Parses propertyTable.property.stringOffsets.\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param propertyTableProperty - propertyTable's property metadata.\n * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.\n * @returns Typed array with offset values.\n * @see https://github.com/CesiumGS/glTF/blob/2976f1183343a47a29e4059a70961371cd2fcee8/extensions/2.0/Vendor/EXT_structural_metadata/schema/propertyTable.property.schema.json#L29C10-L29C23\n */\nfunction getStringOffsetsForProperty(\n scenegraph: GLTFScenegraph,\n propertyTableProperty: GLTF_EXT_structural_metadata_PropertyTable_Property,\n numberOfElements: number\n): TypedArray | null {\n if (\n typeof propertyTableProperty.stringOffsets !== 'undefined' // `stringOffsets` is an index of the buffer view containing offsets for strings.\n ) {\n // Data are in a FIXED-length array\n return getOffsetsForProperty(\n scenegraph,\n propertyTableProperty.stringOffsets,\n propertyTableProperty.stringOffsetType || 'UINT32',\n numberOfElements\n );\n }\n return null;\n}\n\n/**\n * Decodes properties of SCALAR, VEC-N, MAT-N types from binary sourse.\n * @param classProperty - class property object.\n * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.\n * @param valuesDataBytes - Data taken from values property of the property table property.\n * @param arrayOffsets - Offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.\n * @returns Property values in a typed array or in an array of typed arrays.\n */\nfunction getPropertyDataNumeric(\n classProperty: GLTF_EXT_structural_metadata_ClassProperty,\n numberOfElements: number,\n valuesDataBytes: Uint8Array,\n arrayOffsets: TypedArray | null\n): BigTypedArray | BigTypedArray[] {\n const isArray = classProperty.array;\n const arrayCount = classProperty.count;\n\n const elementSize = getArrayElementByteSize(classProperty.type, classProperty.componentType);\n const elementCount = valuesDataBytes.byteLength / elementSize;\n\n let valuesData: BigTypedArray | null;\n if (classProperty.componentType) {\n valuesData = convertRawBufferToMetadataArray(\n valuesDataBytes,\n classProperty.type,\n // The datatype of the element's components. Only applicable to `SCALAR`, `VECN`, and `MATN` types.\n classProperty.componentType as NumericComponentType,\n elementCount\n );\n if (!valuesData) {\n valuesData = valuesDataBytes;\n }\n } else {\n // The spec doesn't provide any info what to do if componentType is not set.\n valuesData = valuesDataBytes;\n }\n\n if (isArray) {\n if (arrayOffsets) {\n // VARIABLE-length array\n return parseVariableLengthArrayNumeric(\n valuesData,\n numberOfElements,\n arrayOffsets,\n valuesDataBytes.length,\n elementSize\n );\n }\n if (arrayCount) {\n // FIXED-length array\n return parseFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount);\n }\n return [];\n }\n\n return valuesData;\n}\n\n/**\n * Parses variable-length array data.\n * In this case every value of the property in the table will be an array\n * of arbitrary length.\n * @param valuesData - Values in a flat typed array.\n * @param numberOfElements - Number of rows in the property table.\n * @param arrayOffsets - Offsets of nested arrays in the flat values array.\n * @param valuesDataBytesLength - Data byte length.\n * @param valueSize - Value size in bytes.\n * @returns Array of typed arrays.\n */\nfunction parseVariableLengthArrayNumeric(\n valuesData: BigTypedArray,\n numberOfElements: number,\n arrayOffsets: TypedArray,\n valuesDataBytesLength: number,\n valueSize: number\n): BigTypedArray[] {\n const attributeValueArray: BigTypedArray[] = [];\n for (let index = 0; index < numberOfElements; index++) {\n const arrayOffset = arrayOffsets[index];\n const arrayByteSize = arrayOffsets[index + 1] - arrayOffsets[index];\n if (arrayByteSize + arrayOffset > valuesDataBytesLength) {\n break;\n }\n const typedArrayOffset = arrayOffset / valueSize;\n const elementCount = arrayByteSize / valueSize;\n attributeValueArray.push(valuesData.slice(typedArrayOffset, typedArrayOffset + elementCount));\n }\n return attributeValueArray;\n}\n\n/**\n * Parses fixed-length array data.\n * In this case every value of the property in the table will be an array\n * of constant length equal to `arrayCount`.\n * @param valuesData - Values in a flat typed array.\n * @param numberOfElements - Number of rows in the property table.\n * @param arrayCount - Nested arrays length.\n * @returns Array of typed arrays.\n */\nfunction parseFixedLengthArrayNumeric(\n valuesData: BigTypedArray,\n numberOfElements: number,\n arrayCount: number\n): BigTypedArray[] {\n const attributeValueArray: BigTypedArray[] = [];\n for (let index = 0; index < numberOfElements; index++) {\n const elementOffset = index * arrayCount;\n attributeValueArray.push(valuesData.slice(elementOffset, elementOffset + arrayCount));\n }\n return attributeValueArray;\n}\n\n/**\n * Decodes properties of string type from binary source.\n * @param classProperty - Class property object.\n * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.\n * @param valuesDataBytes - Data taken from values property of the property table property.\n * @param arrayOffsets - Offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.\n * @param stringOffsets - Index of the buffer view containing offsets for strings. It should be available for string type.\n * @returns String property values\n */\nfunction getPropertyDataString(\n classProperty: GLTF_EXT_structural_metadata_ClassProperty,\n numberOfElements: number,\n valuesDataBytes: Uint8Array,\n arrayOffsets: TypedArray | null,\n stringOffsets: TypedArray | null\n): string[] | string[][] {\n if (arrayOffsets) {\n // TODO: implement it as soon as we have the corresponding tileset\n throw new Error(`Not implemented - classProperty.type=${classProperty.type}`);\n }\n\n if (stringOffsets) {\n const stringsArray: string[] = [];\n const textDecoder = new TextDecoder('utf8');\n\n let stringOffset = 0;\n for (let index = 0; index < numberOfElements; index++) {\n const stringByteSize = stringOffsets[index + 1] - stringOffsets[index];\n\n if (stringByteSize + stringOffset <= valuesDataBytes.length) {\n const stringData = valuesDataBytes.subarray(stringOffset, stringByteSize + stringOffset);\n const stringAttribute = textDecoder.decode(stringData);\n\n stringsArray.push(stringAttribute);\n stringOffset += stringByteSize;\n }\n }\n\n return stringsArray;\n }\n return [];\n}\n\n/**\n * Decodes properties of enum type from binary source.\n * @param schema - Schema object.\n * @param classProperty - Class property object.\n * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.\n * @param valuesDataBytes - Data taken from values property of the property table property.\n * @param arrayOffsets - Offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.\n * @returns Strings array of nested strings array.\n */\nfunction getPropertyDataENUM(\n schema: GLTF_EXT_structural_metadata_Schema,\n classProperty: GLTF_EXT_structural_metadata_ClassProperty,\n numberOfElements: number,\n valuesDataBytes: Uint8Array,\n arrayOffsets: TypedArray | null\n): string[] | string[][] {\n const enumType = classProperty.enumType;\n // Enum ID as declared in the `enums` dictionary. Required when `type` is `ENUM`.\n if (!enumType) {\n throw new Error(\n 'Incorrect data in the EXT_structural_metadata extension: classProperty.enumType is not set for type ENUM'\n );\n }\n\n const enumEntry: GLTF_EXT_structural_metadata_Enum | undefined = schema.enums?.[enumType];\n if (!enumEntry) {\n throw new Error(\n `Incorrect data in the EXT_structural_metadata extension: schema.enums does't contain ${enumType}`\n );\n }\n\n const enumValueType = enumEntry.valueType || 'UINT16';\n const elementSize = getArrayElementByteSize(classProperty.type, enumValueType);\n const elementCount = valuesDataBytes.byteLength / elementSize;\n let valuesData: BigTypedArray | null = convertRawBufferToMetadataArray(\n valuesDataBytes,\n classProperty.type,\n enumValueType,\n elementCount\n );\n if (!valuesData) {\n valuesData = valuesDataBytes;\n }\n\n if (classProperty.array) {\n if (arrayOffsets) {\n // VARIABLE-length array\n return parseVariableLengthArrayENUM({\n valuesData,\n numberOfElements,\n arrayOffsets,\n valuesDataBytesLength: valuesDataBytes.length,\n elementSize,\n enumEntry\n });\n }\n\n const arrayCount = classProperty.count;\n if (arrayCount) {\n // FIXED-length array\n return parseFixedLengthArrayENUM(valuesData, numberOfElements, arrayCount, enumEntry);\n }\n return [];\n }\n\n // Single value (not an array)\n return getEnumsArray(valuesData, 0, numberOfElements, enumEntry);\n}\n\n/**\n * Parses variable length nested ENUM arrays.\n * @param params.valuesData - Values in a flat typed array.\n * @param params.numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.\n * @param params.arrayOffsets - Offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.\n * @param params.valuesDataBytesLength - Byte length of values array.\n * @param params.elementSize - Single element byte size.\n * @param params.enumEntry - Enums dictionary.\n * @returns Nested strings array.\n */\nfunction parseVariableLengthArrayENUM(params: {\n valuesData: BigTypedArray;\n numberOfElements: number;\n arrayOffsets: TypedArray;\n valuesDataBytesLength: number;\n elementSize: number;\n enumEntry: GLTF_EXT_structural_metadata_Enum;\n}): string[][] {\n const {\n valuesData,\n numberOfElements,\n arrayOffsets,\n valuesDataBytesLength,\n elementSize,\n enumEntry\n } = params;\n const attributeValueArray: string[][] = [];\n for (let index = 0; index < numberOfElements; index++) {\n const arrayOffset = arrayOffsets[index];\n const arrayByteSize = arrayOffsets[index + 1] - arrayOffsets[index];\n if (arrayByteSize + arrayOffset > valuesDataBytesLength) {\n break;\n }\n\n const typedArrayOffset = arrayOffset / elementSize;\n const elementCount = arrayByteSize / elementSize;\n const array: string[] = getEnumsArray(valuesData, typedArrayOffset, elementCount, enumEntry);\n attributeValueArray.push(array);\n }\n return attributeValueArray;\n}\n\n/**\n * Parses fixed length ENUM arrays.\n * @param valuesData - Values in a flat typed array.\n * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.\n * @param arrayCount - Nested arrays length.\n * @param enumEntry - Enums dictionary.\n * @returns Nested strings array.\n */\nfunction parseFixedLengthArrayENUM(\n valuesData: BigTypedArray,\n numberOfElements: number,\n arrayCount: number,\n enumEntry: GLTF_EXT_structural_metadata_Enum\n): string[][] {\n const attributeValueArray: string[][] = [];\n for (let index = 0; index < numberOfElements; index++) {\n const elementOffset = arrayCount * index;\n const array: string[] = getEnumsArray(valuesData, elementOffset, arrayCount, enumEntry);\n attributeValueArray.push(array);\n }\n return attributeValueArray;\n}\n\n/**\n * Parses ENUM values into a string array.\n * @param valuesData - Values in a flat typed array.\n * @param offset - Offset to start parse from.\n * @param count - Values length to parse.\n * @param enumEntry - Enums dictionary.\n * @returns Array of strings with parsed ENUM names.\n */\nfunction getEnumsArray(\n valuesData: BigTypedArray,\n offset: number,\n count: number,\n enumEntry: GLTF_EXT_structural_metadata_Enum\n): string[] {\n const array: string[] = [];\n for (let i = 0; i < count; i++) {\n // At the moment we don't support BigInt. It requires additional calculations logic\n // and might be an issue in Safari\n if (valuesData instanceof BigInt64Array || valuesData instanceof BigUint64Array) {\n array.push('');\n } else {\n const value = valuesData[offset + i];\n\n const enumObject = getEnumByValue(enumEntry, value);\n if (enumObject) {\n array.push(enumObject.name);\n } else {\n array.push('');\n }\n }\n }\n return array;\n}\n\n/**\n * Looks up ENUM whose `value` property matches the specified number in the parameter `value`.\n * @param {GLTF_EXT_structural_metadata_Enum} enumEntry - ENUM entry containing the array of possible enums.\n * @param {number} value - The value of the ENUM to locate.\n * @returns {GLTF_EXT_structural_metadata_EnumValue | null} ENUM matcihng the specified value or null of no ENUM object was found.\n */\nfunction getEnumByValue(\n enumEntry: GLTF_EXT_structural_metadata_Enum,\n value: number\n): GLTF_EXT_structural_metadata_EnumValue | null {\n for (const enumValue of enumEntry.values) {\n if (enumValue.value === value) {\n return enumValue;\n }\n }\n\n return null;\n}\n"],"mappings":"AAmBA,SAAQA,cAAc,QAAO,wBAAwB;AACrD,SACEC,+BAA+B,EAC/BC,uBAAuB,EACvBC,iCAAiC,EACjCC,uBAAuB,EAEvBC,qBAAqB,QAChB,wBAAwB;AAE/B,MAAMC,4BAA4B,GAAG,yBAAyB;AAC9D,OAAO,MAAMC,IAAI,GAAGD,4BAA4B;AAEhD,OAAO,eAAeE,MAAMA,CAACC,QAAsB,EAAEC,OAA0B,EAAiB;EAC9F,MAAMC,UAAU,GAAG,IAAIX,cAAc,CAACS,QAAQ,CAAC;EAC/CG,2BAA2B,CAACD,UAAU,EAAED,OAAO,CAAC;AAClD;AAQA,OAAO,SAASG,yCAAyCA,CACvDC,SAA4C,EAC5CC,aAAsB,EACG;EACzB,IAAID,SAAS,CAACE,cAAc,EAAE;IAO5B,MAAMC,kBAAkB,GAAGH,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAEE,cAAc,CAAC,CAAC,CAAC;IACvD,MAAME,qBAAqB,GAAG,CAAC,CAAC;IAEhC,KAAK,MAAMC,YAAY,IAAIF,kBAAkB,CAACG,UAAU,EAAE;MACxDF,qBAAqB,CAACC,YAAY,CAAC,GAAGF,kBAAkB,CAACG,UAAU,CAACD,YAAY,CAAC,CAACE,IAAI;IACxF;IAEA,OAAOH,qBAAqB;EAC9B;EAEA,IAAIJ,SAAS,CAACQ,gBAAgB,EAAE;IAE9B,MAAMC,oBAAoB,GAAGT,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAEQ,gBAAgB,CA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K,aAAa,GAAGjB,UAAU,GAAGY,KAAK;IACxC,MAAMhB,KAAe,GAAGsC,aAAa,CAAC7B,UAAU,EAAEY,aAAa,EAAEjB,UAAU,EAAE4B,SAAS,CAAC;IACvFjB,mBAAmB,CAACpC,IAAI,CAACqB,KAAK,CAAC;EACjC;EACA,OAAOe,mBAAmB;AAC5B;AAUA,SAASuB,aAAaA,CACpB7B,UAAyB,EACzB+B,MAAc,EACdzD,KAAa,EACbiD,SAA4C,EAClC;EACV,MAAMhC,KAAe,GAAG,EAAE;EAC1B,KAAK,IAAIyC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAG1D,KAAK,EAAE0D,CAAC,EAAE,EAAE;IAG9B,IAAIhC,UAAU,YAAYiC,aAAa,IAAIjC,UAAU,YAAYkC,cAAc,EAAE;MAC/E3C,KAAK,CAACrB,IAAI,CAAC,EAAE,CAAC;IAChB,CAAC,MAAM;MACL,MAAMiE,KAAK,GAAGnC,UAAU,CAAC+B,MAAM,GAAGC,CAAC,CAAC;MAEpC,MAAMI,UAAU,GAAGC,cAAc,CAACd,SAAS,EAAEY,KAAK,CAAC;MACnD,IAAIC,UAAU,EAAE;QACd7C,KAAK,CAACrB,IAAI,CAACkE,UAAU,CAAC/H,IAAI,CAAC;MAC7B,CAAC,MAAM;QACLkF,KAAK,CAACrB,IAAI,CAAC,EAAE,CAAC;MAChB;IACF;EACF;EACA,OAAOqB,KAAK;AACd;AAQA,SAAS8C,cAAcA,CACrBd,SAA4C,EAC5CY,KAAa,EACkC;EAC/C,KAAK,MAAMG,SAAS,IAAIf,SAAS,CAAC3C,MAAM,EAAE;IACxC,IAAI0D,SAAS,CAACH,KAAK,KAAKA,KAAK,EAAE;MAC7B,OAAOG,SAAS;IAClB;EACF;EAEA,OAAO,IAAI;AACb"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GLTFScenegraph } from '../../api/gltf-scenegraph';
|
|
2
2
|
import { getImageData } from '@loaders.gl/images';
|
|
3
|
-
import { getComponentTypeFromArray } from '../../gltf-utils/gltf-utils';
|
|
3
|
+
import { getComponentTypeFromArray, getFloat32ArrayForAccessor } from '../../gltf-utils/gltf-utils';
|
|
4
4
|
import { emod } from '@loaders.gl/math';
|
|
5
5
|
import { convertRawBufferToMetadataArray, getOffsetsForProperty } from '../utils/3d-tiles-utils';
|
|
6
6
|
const EXT_FEATURE_METADATA_NAME = 'EXT_feature_metadata';
|
|
@@ -9,6 +9,39 @@ export async function decode(gltfData, options) {
|
|
|
9
9
|
const scenegraph = new GLTFScenegraph(gltfData);
|
|
10
10
|
decodeExtFeatureMetadata(scenegraph, options);
|
|
11
11
|
}
|
|
12
|
+
export function getPropertyTableFromExtFeatureMetadata(extension, metadataClass) {
|
|
13
|
+
if (extension.featureTables) {
|
|
14
|
+
var _Object$keys;
|
|
15
|
+
const firstFeatureTableName = (_Object$keys = Object.keys(extension.featureTables)) === null || _Object$keys === void 0 ? void 0 : _Object$keys[0];
|
|
16
|
+
if (firstFeatureTableName) {
|
|
17
|
+
const featureTable = extension.featureTables[firstFeatureTableName];
|
|
18
|
+
const propertyTable = {};
|
|
19
|
+
for (const propertyName in featureTable.properties) {
|
|
20
|
+
propertyTable[propertyName] = featureTable.properties[propertyName].data;
|
|
21
|
+
}
|
|
22
|
+
return propertyTable;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (extension.featureTextures) {
|
|
26
|
+
let featureTexture;
|
|
27
|
+
for (const textureKey in extension.featureTextures) {
|
|
28
|
+
const texture = extension.featureTextures[textureKey];
|
|
29
|
+
if (texture.class === metadataClass) {
|
|
30
|
+
featureTexture = textureKey;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (typeof featureTexture === 'string') {
|
|
34
|
+
const featureTable = extension.featureTextures[featureTexture];
|
|
35
|
+
const propertyTable = {};
|
|
36
|
+
for (const propertyName in featureTable.properties) {
|
|
37
|
+
propertyTable[propertyName] = featureTable.properties[propertyName].data;
|
|
38
|
+
}
|
|
39
|
+
return propertyTable;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
console.warn('Cannot get property table from EXT_feature_metadata extension. There is neither featureTables, nor featureTextures in the extension.');
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
12
45
|
function decodeExtFeatureMetadata(scenegraph, options) {
|
|
13
46
|
var _extension$schema, _options$gltf;
|
|
14
47
|
const extension = scenegraph.getExtension(EXT_FEATURE_METADATA_NAME);
|
|
@@ -111,9 +144,10 @@ function processPrimitiveTextures(scenegraph, attributeName, featureTexturePrope
|
|
|
111
144
|
const textureData = [];
|
|
112
145
|
const texCoordAccessorKey = "TEXCOORD_".concat(featureTextureProperty.texture.texCoord);
|
|
113
146
|
const texCoordAccessorIndex = primitive.attributes[texCoordAccessorKey];
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
147
|
+
const textureCoordinates = getFloat32ArrayForAccessor(scenegraph.gltf, texCoordAccessorIndex);
|
|
148
|
+
if (!textureCoordinates) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
117
151
|
const textureIndex = featureTextureProperty.texture.index;
|
|
118
152
|
const texture = (_json$textures = json.textures) === null || _json$textures === void 0 ? void 0 : _json$textures[textureIndex];
|
|
119
153
|
const imageIndex = texture === null || texture === void 0 ? void 0 : texture.source;
|