@loaders.gl/gltf 4.0.0-beta.3 → 4.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"EXT_structural_metadata.js","names":["GLTFScenegraph","convertRawBufferToMetadataArray","getPrimitiveTextureData","primitivePropertyDataToAttributes","getArrayElementByteSize","getOffsetsForProperty","parseVariableLengthArrayNumeric","parseFixedLengthArrayNumeric","getPropertyDataString","EXT_STRUCTURAL_METADATA_NAME","name","decode","gltfData","options","scenegraph","decodeExtStructuralMetadata","getPropertyTableFromExtStructuralMetadata","extension","metadataClass","propertyTables","firstPropertyTable","propertyTableWithData","propertyName","properties","data","propertyTextures","firstPropertyTexture","console","warn","_options$gltf","_options$gltf2","gltf","loadBuffers","getExtension","loadImages","decodePropertyTextures","decodePropertyTables","json","meshes","mesh","primitive","primitives","processPrimitivePropertyTextures","schema","schemaClasses","classes","schemaName","propertyTable","findPropertyTableByClass","processPropertyTable","schemaClassName","class","_primitive$extensions","primitiveExtension","extensions","primitivePropertyTextureIndices","primitivePropertyTextureIndex","propertyTexture","processPrimitivePropertyTexture","dataAttributeNames","className","_propertyTexture$prop","attributeName","textureInfoTopLevel","featureTextureTable","propertyData","push","_schema$classes","schemaClass","Error","numberOfElements","count","_propertyTable$proper","classProperty","propertyTableProperty","getPropertyDataFromBinarySource","valuesBufferView","values","valuesDataBytes","getTypedArrayForBufferView","arrayOffsets","getArrayOffsetsForProperty","stringOffsets","getStringOffsetsForProperty","type","getPropertyDataNumeric","getPropertyDataENUM","array","arrayOffsetType","stringOffsetType","isArray","arrayCount","elementSize","componentType","elementCount","byteLength","valuesData","length","_schema$enums","enumType","enumEntry","enums","enumValueType","valueType","parseVariableLengthArrayENUM","valuesDataBytesLength","parseFixedLengthArrayENUM","getEnumsArray","params","attributeValueArray","index","arrayOffset","arrayByteSize","typedArrayOffset","elementOffset","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 parseVariableLengthArrayNumeric,\n parseFixedLengthArrayNumeric,\n getPropertyDataString\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 * 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(numberOfElements, valuesDataBytes, arrayOffsets, stringOffsets);\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;\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 } 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 * 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":"SAmBQA,cAAc;AAAA,SAEpBC,+BAA+B,EAC/BC,uBAAuB,EACvBC,iCAAiC,EACjCC,uBAAuB,EAEvBC,q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U,GAAGC,cAAc,CAACrB,SAAS,EAAEmB,KAAK,CAAC;MACnD,IAAIC,UAAU,EAAE;QACdjC,KAAK,CAACrB,IAAI,CAACsD,UAAU,CAAC9G,IAAI,CAAC;MAC7B,CAAC,MAAM;QACL6E,KAAK,CAACrB,IAAI,CAAC,EAAE,CAAC;MAChB;IACF;EACF;EACA,OAAOqB,KAAK;AACd;AAQA,SAASkC,cAAcA,CACrBrB,SAA4C,EAC5CmB,KAAa,EACkC;EAC/C,KAAK,MAAMG,SAAS,IAAItB,SAAS,CAACvB,MAAM,EAAE;IACxC,IAAI6C,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","parseVariableLengthArrayNumeric","parseFixedLengthArrayNumeric","getPropertyDataString","EXT_STRUCTURAL_METADATA_NAME","name","decode","gltfData","options","scenegraph","decodeExtStructuralMetadata","_options$gltf","_options$gltf2","gltf","loadBuffers","extension","getExtension","loadImages","decodePropertyTextures","decodePropertyTables","propertyTextures","json","meshes","mesh","primitive","primitives","processPrimitivePropertyTextures","schema","schemaClasses","classes","propertyTables","schemaName","propertyTable","findPropertyTableByClass","processPropertyTable","schemaClassName","class","_primitive$extensions","primitiveExtension","extensions","primitivePropertyTextureIndices","primitivePropertyTextureIndex","propertyTexture","processPrimitivePropertyTexture","properties","dataAttributeNames","className","propertyName","_propertyTexture$prop","attributeName","textureInfoTopLevel","data","featureTextureTable","propertyData","push","_schema$classes","schemaClass","Error","numberOfElements","count","_propertyTable$proper","classProperty","propertyTableProperty","getPropertyDataFromBinarySource","valuesBufferView","values","valuesDataBytes","getTypedArrayForBufferView","arrayOffsets","getArrayOffsetsForProperty","stringOffsets","getStringOffsetsForProperty","type","getPropertyDataNumeric","getPropertyDataENUM","array","arrayOffsetType","stringOffsetType","isArray","arrayCount","elementSize","componentType","elementCount","byteLength","valuesData","length","_schema$enums","enumType","enumEntry","enums","enumValueType","valueType","parseVariableLengthArrayENUM","valuesDataBytesLength","parseFixedLengthArrayENUM","getEnumsArray","params","attributeValueArray","index","arrayOffset","arrayByteSize","typedArrayOffset","elementOffset","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';\n\nimport {GLTFScenegraph} from '../api/gltf-scenegraph';\nimport {\n convertRawBufferToMetadataArray,\n getPrimitiveTextureData,\n primitivePropertyDataToAttributes,\n getArrayElementByteSize,\n NumericComponentType,\n getOffsetsForProperty,\n parseVariableLengthArrayNumeric,\n parseFixedLengthArrayNumeric,\n getPropertyDataString\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 * 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(numberOfElements, valuesDataBytes, arrayOffsets, stringOffsets);\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;\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 } 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 * 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":"SAkBQA,cAAc;AAAA,SAEpBC,+BAA+B,EAC/BC,uBAAuB,EACvBC,iCAAiC,EACjCC,uBAAuB,EAEvBC,qBAAqB,EACrBC,+BAA+B,EAC/BC,4BAA4B,EAC5BC,qBAAqB;AAGvB,MAAMC,4BAA4B,GAAG,yBAAyB;AAC9D,OAAO,MAAMC,IAAI,GAAGD,4BAA4B;AAEhD,OAAO,eAAeE,MAAMA,CAACC,QAAsB,EAAEC,OAA0B,EAAiB;EAC9F,MAAMC,UAAU,GAAG,IAAId,cAAc,CAACY,QAAQ,CAAC;EAC/CG,2BAA2B,CAACD,UAAU,EAAED,OAAO,CAAC;AAClD;AAgEA,SAASE,2BAA2BA,CAACD,UAA0B,EAAED,OAA0B,EAAQ;EAAA,IAAAG,aAAA,EAAAC,cAAA;EAGjG,IAAI,GAAAD,aAAA,GAACH,OAAO,CAACK,IAAI,cAAAF,aAAA,eAAZA,aAAA,CAAcG,WAAW,GAAE;IAC9B;EACF;EACA,MAAMC,SAAmD,GAAGN,UAAU,CAACO,YAAY,CACjFZ,4BACF,CAAC;EACD,IAAI,CAACW,SAAS,EAAE;IACd;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K,MAAMG,SAAS,IAAItB,SAAS,CAACvB,MAAM,EAAE;IACxC,IAAI6C,SAAS,CAACH,KAAK,KAAKA,KAAK,EAAE;MAC7B,OAAOG,SAAS;IAClB;EACF;EAEA,OAAO,IAAI;AACb"}
@@ -1,16 +1,7 @@
1
1
  import type { GLTF } from '../../types/gltf-json-schema';
2
- import type { GLTF_EXT_feature_metadata_GLTF } from '../../types/gltf-ext-feature-metadata-schema';
3
- import type { FeatureTableJson } from '../../types/gltf-types';
4
2
  import { GLTFLoaderOptions } from '../../../gltf-loader';
5
3
  export declare const name = "EXT_feature_metadata";
6
4
  export declare function decode(gltfData: {
7
5
  json: GLTF;
8
6
  }, options: GLTFLoaderOptions): Promise<void>;
9
- /**
10
- * Handles EXT_feature_metadata to get property table.
11
- * @param extension - Global level of EXT_FEATURE_METADATA extension.
12
- * @param metadataClass - User selected feature metadata class name.
13
- * @returns {FeatureTableJson | null} Property table or null if the extension can't be handled properly.
14
- */
15
- export declare function getPropertyTableFromExtFeatureMetadata(extension: GLTF_EXT_feature_metadata_GLTF, metadataClass?: string): FeatureTableJson | null;
16
7
  //# sourceMappingURL=EXT_feature_metadata.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EXT_feature_metadata.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/EXT_feature_metadata.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,IAAI,EAA0B,MAAM,8BAA8B,CAAC;AAChF,OAAO,KAAK,EAMV,8BAA8B,EAG/B,MAAM,8CAA8C,CAAC;AAEtD,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,wBAAwB,CAAC;AAG7D,OAAO,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAevD,eAAO,MAAM,IAAI,yBAA4B,CAAC;AAE9C,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAG9F;AAED;;;;;GAKG;AACH,wBAAgB,sCAAsC,CACpD,SAAS,EAAE,8BAA8B,EACzC,aAAa,CAAC,EAAE,MAAM,GACrB,gBAAgB,GAAG,IAAI,CAgDzB"}
1
+ {"version":3,"file":"EXT_feature_metadata.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/EXT_feature_metadata.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,IAAI,EAA0B,MAAM,8BAA8B,CAAC;AAchF,OAAO,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAevD,eAAO,MAAM,IAAI,yBAA4B,CAAC;AAE9C,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAG9F"}
@@ -6,39 +6,6 @@ export async function decode(gltfData, options) {
6
6
  const scenegraph = new GLTFScenegraph(gltfData);
7
7
  decodeExtFeatureMetadata(scenegraph, options);
8
8
  }
9
- export function getPropertyTableFromExtFeatureMetadata(extension, metadataClass) {
10
- if (extension.featureTables) {
11
- var _Object$keys;
12
- const firstFeatureTableName = (_Object$keys = Object.keys(extension.featureTables)) === null || _Object$keys === void 0 ? void 0 : _Object$keys[0];
13
- if (firstFeatureTableName) {
14
- const featureTable = extension.featureTables[firstFeatureTableName];
15
- const propertyTable = {};
16
- for (const propertyName in featureTable.properties) {
17
- propertyTable[propertyName] = featureTable.properties[propertyName].data;
18
- }
19
- return propertyTable;
20
- }
21
- }
22
- if (extension.featureTextures) {
23
- let featureTexture;
24
- for (const textureKey in extension.featureTextures) {
25
- const texture = extension.featureTextures[textureKey];
26
- if (texture.class === metadataClass) {
27
- featureTexture = textureKey;
28
- }
29
- }
30
- if (typeof featureTexture === 'string') {
31
- const featureTable = extension.featureTextures[featureTexture];
32
- const propertyTable = {};
33
- for (const propertyName in featureTable.properties) {
34
- propertyTable[propertyName] = featureTable.properties[propertyName].data;
35
- }
36
- return propertyTable;
37
- }
38
- }
39
- console.warn('Cannot get property table from EXT_feature_metadata extension. There is neither featureTables, nor featureTextures in the extension.');
40
- return null;
41
- }
42
9
  function decodeExtFeatureMetadata(scenegraph, options) {
43
10
  var _options$gltf, _options$gltf2;
44
11
  if (!((_options$gltf = options.gltf) !== null && _options$gltf !== void 0 && _options$gltf.loadBuffers)) {
@@ -1 +1 @@
1
- {"version":3,"file":"EXT_feature_metadata.js","names":["GLTFScenegraph","convertRawBufferToMetadataArray","getPrimitiveTextureData","primitivePropertyDataToAttributes","getArrayElementByteSize","getOffsetsForProperty","parseVariableLengthArrayNumeric","parseFixedLengthArrayNumeric","getPropertyDataString","EXT_FEATURE_METADATA_NAME","name","decode","gltfData","options","scenegraph","decodeExtFeatureMetadata","getPropertyTableFromExtFeatureMetadata","extension","metadataClass","featureTables","_Object$keys","firstFeatureTableName","Object","keys","featureTable","propertyTable","propertyName","properties","data","featureTextures","featureTexture","textureKey","texture","class","console","warn","_options$gltf","_options$gltf2","gltf","loadBuffers","getExtension","loadImages","decodePropertyTextures","decodePropertyTables","schema","schemaClasses","classes","schemaName","schemaClass","findFeatureTextureByClass","handleFeatureTextureProperties","propertyTables","findPropertyTableByClass","processPropertyTable","schemaClassName","propertyTableName","featureTexturesName","_schema$classes","Error","numberOfElements","count","_propertyTable$proper","classProperty","propertyTableProperty","getPropertyDataFromBinarySource","attributeName","_featureTexture$prope","featureTextureProperty","getPropertyDataFromTexture","numberOfFeatures","featureTableProperty","bufferView","dataArray","getTypedArrayForBufferView","arrayOffsets","getArrayOffsetsForProperty","stringOffsets","getStringOffsetsForProperty","type","componentType","isNumericProperty","getPropertyDataNumeric","componentCount","arrayOffsetBufferView","offsetType","stringOffsetBufferView","schemaProperty","types","includes","valuesDataBytes","isArray","arrayCount","attributeType","elementSize","elementCount","byteLength","valuesData","length","json","meshes","featureTextureTable","mesh","primitive","primitives","processPrimitiveTextures","textureInfoTopLevel","channels","propertyData"],"sources":["../../../../src/lib/extensions/deprecated/EXT_feature_metadata.ts"],"sourcesContent":["/* eslint-disable camelcase */\nimport type {GLTF, GLTFTextureInfoMetadata} from '../../types/gltf-json-schema';\nimport type {\n GLTF_EXT_feature_metadata_Class,\n GLTF_EXT_feature_metadata_ClassProperty,\n GLTF_EXT_feature_metadata_FeatureTable,\n GLTF_EXT_feature_metadata_FeatureTableProperty,\n GLTF_EXT_feature_metadata_FeatureTexture,\n GLTF_EXT_feature_metadata_GLTF,\n GLTF_EXT_feature_metadata_TextureAccessor,\n GLTF_EXT_feature_metadata_Schema\n} from '../../types/gltf-ext-feature-metadata-schema';\nimport type {BigTypedArray, TypedArray} from '@loaders.gl/schema';\nimport type {FeatureTableJson} from '../../types/gltf-types';\nimport {GLTFScenegraph} from '../../api/gltf-scenegraph';\nimport {GLTFMeshPrimitive} from '../../types/gltf-json-schema';\nimport {GLTFLoaderOptions} from '../../../gltf-loader';\nimport {\n convertRawBufferToMetadataArray,\n getPrimitiveTextureData,\n primitivePropertyDataToAttributes,\n getArrayElementByteSize,\n NumericComponentType,\n getOffsetsForProperty,\n parseVariableLengthArrayNumeric,\n parseFixedLengthArrayNumeric,\n getPropertyDataString\n} from '../utils/3d-tiles-utils';\n\n/** Extension name */\nconst EXT_FEATURE_METADATA_NAME = 'EXT_feature_metadata';\nexport const name = EXT_FEATURE_METADATA_NAME;\n\nexport async function decode(gltfData: {json: GLTF}, options: GLTFLoaderOptions): Promise<void> {\n const scenegraph = new GLTFScenegraph(gltfData);\n decodeExtFeatureMetadata(scenegraph, options);\n}\n\n/**\n * Handles EXT_feature_metadata to get property table.\n * @param extension - Global level of EXT_FEATURE_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 getPropertyTableFromExtFeatureMetadata(\n extension: GLTF_EXT_feature_metadata_GLTF,\n metadataClass?: string\n): FeatureTableJson | null {\n if (extension.featureTables) {\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 firstFeatureTableName = Object.keys(extension.featureTables)?.[0];\n\n if (firstFeatureTableName) {\n const featureTable = extension.featureTables[firstFeatureTableName];\n const propertyTable = {};\n\n for (const propertyName in featureTable.properties) {\n propertyTable[propertyName] = featureTable.properties[propertyName].data;\n }\n\n return propertyTable;\n }\n }\n\n if (extension.featureTextures) {\n let featureTexture: string | undefined;\n for (const textureKey in extension.featureTextures) {\n const texture = extension.featureTextures[textureKey];\n if (texture.class === metadataClass) {\n featureTexture = textureKey;\n }\n }\n\n if (typeof featureTexture === 'string') {\n const featureTable = extension.featureTextures[featureTexture];\n const propertyTable = {};\n\n for (const propertyName in featureTable.properties) {\n propertyTable[propertyName] = featureTable.properties[propertyName].data;\n }\n\n return propertyTable;\n }\n }\n\n // eslint-disable-next-line no-console\n console.warn(\n 'Cannot get property table from EXT_feature_metadata extension. There is neither featureTables, nor featureTextures in the extension.'\n );\n return null;\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 decodeExtFeatureMetadata(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_feature_metadata_GLTF | null =\n scenegraph.getExtension(EXT_FEATURE_METADATA_NAME);\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_feature_metadata_GLTF\n): void {\n const schema = extension.schema;\n if (!schema) {\n return;\n }\n const schemaClasses = schema.classes;\n\n const {featureTextures} = extension;\n if (schemaClasses && featureTextures) {\n for (const schemaName in schemaClasses) {\n const schemaClass = schemaClasses[schemaName];\n const featureTexture = findFeatureTextureByClass(featureTextures, schemaName);\n\n if (featureTexture) {\n handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass);\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_feature_metadata_GLTF\n): void {\n const schema = extension.schema;\n if (!schema) {\n return;\n }\n const schemaClasses = schema.classes;\n const propertyTables = extension.featureTables;\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: {[key: string]: GLTF_EXT_feature_metadata_FeatureTable},\n schemaClassName: string\n): GLTF_EXT_feature_metadata_FeatureTable | null {\n for (const propertyTableName in propertyTables) {\n const propertyTable = propertyTables[propertyTableName];\n if (propertyTable.class === schemaClassName) {\n return propertyTable;\n }\n }\n\n return null;\n}\n\nfunction findFeatureTextureByClass(\n featureTextures: {[key: string]: GLTF_EXT_feature_metadata_FeatureTexture},\n schemaClassName: string\n): GLTF_EXT_feature_metadata_FeatureTexture | null {\n for (const featureTexturesName in featureTextures) {\n const featureTable = featureTextures[featureTexturesName];\n\n if (featureTable.class === schemaClassName) {\n return featureTable;\n }\n }\n\n return null;\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_feature_metadata_Schema,\n propertyTable: GLTF_EXT_feature_metadata_FeatureTable\n): void {\n // Though 'class' is not required by spec, it doesn't make any scence when it's not provided.\n // So, bale out here.\n if (!propertyTable.class) {\n return;\n }\n\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_feature_metadata_FeatureTableProperty | 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 * Navigates through all properies in feature texture and gets properties data.\n * Data will be stored in featureTexture.properties[propertyName].data.\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param featureTexture\n * @param schemaClass\n */\nfunction handleFeatureTextureProperties(\n scenegraph: GLTFScenegraph,\n featureTexture: GLTF_EXT_feature_metadata_FeatureTexture,\n schemaClass: GLTF_EXT_feature_metadata_Class\n): void {\n const attributeName = featureTexture.class;\n\n for (const propertyName in schemaClass.properties) {\n const featureTextureProperty = featureTexture?.properties?.[propertyName];\n\n if (featureTextureProperty) {\n const data = getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName);\n featureTextureProperty.data = data;\n }\n }\n}\n\n/**\n * Decodes properties from binary sourse based on property type.\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param schemaProperty\n * @param numberOfFeatures\n * @param featureTableProperty\n */\nfunction getPropertyDataFromBinarySource(\n scenegraph: GLTFScenegraph,\n schema: GLTF_EXT_feature_metadata_Schema,\n classProperty: GLTF_EXT_feature_metadata_ClassProperty,\n numberOfFeatures: number,\n featureTableProperty: GLTF_EXT_feature_metadata_FeatureTableProperty\n): string[] | BigTypedArray | string[][] | BigTypedArray[] {\n let data: string[] | BigTypedArray | string[][] | BigTypedArray[] = [];\n const bufferView = featureTableProperty.bufferView;\n const dataArray: Uint8Array = scenegraph.getTypedArrayForBufferView(bufferView);\n\n const arrayOffsets = getArrayOffsetsForProperty(\n scenegraph,\n classProperty,\n featureTableProperty,\n numberOfFeatures\n );\n const stringOffsets = getStringOffsetsForProperty(\n scenegraph,\n classProperty,\n featureTableProperty,\n numberOfFeatures\n );\n\n if (classProperty.type === 'STRING' || classProperty.componentType === 'STRING') {\n data = getPropertyDataString(numberOfFeatures, dataArray, arrayOffsets, stringOffsets);\n } else if (isNumericProperty(classProperty)) {\n data = getPropertyDataNumeric(classProperty, numberOfFeatures, dataArray, arrayOffsets);\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_feature_metadata_ClassProperty,\n propertyTableProperty: GLTF_EXT_feature_metadata_FeatureTableProperty,\n numberOfElements: number\n): TypedArray | null {\n /*\n If ARRAY is used, then componentType must also be specified.\n ARRAY is a fixed-length array when componentCount is defined, and variable-length otherwise.\n*/\n if (\n classProperty.type === 'ARRAY' &&\n // `componentCount` is a number of fixed-length array elements.\n // If `componentCount` is NOT defined, it's a VARIABLE-length array\n typeof classProperty.componentCount === 'undefined' &&\n // `arrayOffsetBufferView` is an index of the buffer view containing offsets for variable-length arrays.\n typeof propertyTableProperty.arrayOffsetBufferView !== 'undefined'\n ) {\n // Data are in a VARIABLE-length array\n return getOffsetsForProperty(\n scenegraph,\n propertyTableProperty.arrayOffsetBufferView,\n propertyTableProperty.offsetType || 'UINT32', // offsetType is used both for stringOffsetBufferView and arrayOffsetBufferView\n numberOfElements\n );\n }\n return null;\n}\n\n/**\n * Parses featureTable.property.stringOffsetBufferView.\n * String offsets is an array of offsets of strings in the united array of characters.\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 of offset values. The number of offsets in the array is equal to `numberOfElements` plus one.\n * @see https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_feature_metadata/schema/featureTable.property.schema.json#L50C10-L50C32\n */\nfunction getStringOffsetsForProperty(\n scenegraph: GLTFScenegraph,\n classProperty: GLTF_EXT_feature_metadata_ClassProperty,\n propertyTableProperty: GLTF_EXT_feature_metadata_FeatureTableProperty,\n numberOfElements: number\n): TypedArray | null {\n if (\n typeof propertyTableProperty.stringOffsetBufferView !== 'undefined' // `stringOffsetBufferView` 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.stringOffsetBufferView,\n propertyTableProperty.offsetType || 'UINT32', // offsetType is used both for stringOffsetBufferView and arrayOffsetBufferView\n numberOfElements\n );\n }\n return null;\n}\n\n/**\n * Checks if the feature table property is of numeric type.\n * @param schemaPropertyType - feature table property\n * @returns true if property is numeric, else - false\n */\nfunction isNumericProperty(schemaProperty: GLTF_EXT_feature_metadata_ClassProperty): boolean {\n const types = [\n 'UINT8',\n 'INT16',\n 'UINT16',\n 'INT32',\n 'UINT32',\n 'INT64',\n 'UINT64',\n 'FLOAT32',\n 'FLOAT64'\n ];\n return (\n types.includes(schemaProperty.type) ||\n (typeof schemaProperty.componentType !== 'undefined' &&\n types.includes(schemaProperty.componentType))\n );\n}\n\n/**\n * Decodes properties of numeric 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_feature_metadata_ClassProperty,\n numberOfElements: number,\n valuesDataBytes: Uint8Array,\n arrayOffsets: TypedArray | null\n): BigTypedArray | BigTypedArray[] {\n const isArray = classProperty.type === 'ARRAY';\n const arrayCount = classProperty.componentCount;\n\n /*\n We are getting Numeric data. So,\n the component type can be one of NumericComponentType,\n the attribute type should be 'SCALAR'\n */\n const attributeType = 'SCALAR';\n const componentType = classProperty.componentType || classProperty.type;\n const elementSize = getArrayElementByteSize(attributeType, componentType);\n const elementCount = valuesDataBytes.byteLength / elementSize;\n\n const valuesData: BigTypedArray = convertRawBufferToMetadataArray(\n valuesDataBytes,\n attributeType,\n componentType as NumericComponentType,\n elementCount\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 * Gets properties from texture associated with all mesh primitives.\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param featureTextureProperty\n * @param attributeName\n * @returns Feature texture data\n */\nfunction getPropertyDataFromTexture(\n scenegraph: GLTFScenegraph,\n featureTextureProperty: GLTF_EXT_feature_metadata_TextureAccessor,\n attributeName: string\n): number[] {\n const json = scenegraph.gltf.json;\n if (!json.meshes) {\n return [];\n }\n const featureTextureTable: number[] = [];\n for (const mesh of json.meshes) {\n for (const primitive of mesh.primitives) {\n processPrimitiveTextures(\n scenegraph,\n attributeName,\n featureTextureProperty,\n featureTextureTable,\n primitive\n );\n }\n }\n return featureTextureTable;\n}\n\n/**\n * Processes data encoded in the texture associated with the primitive. This data will be accessible through the attributes.\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param attributeName\n * @param featureTextureProperty\n * @param featureTextureTable\n * @param primitive\n */\nfunction processPrimitiveTextures(\n scenegraph: GLTFScenegraph,\n attributeName: string,\n featureTextureProperty: GLTF_EXT_feature_metadata_TextureAccessor,\n featureTextureTable: number[],\n primitive: GLTFMeshPrimitive\n): void {\n const textureInfoTopLevel: GLTFTextureInfoMetadata = {\n channels: featureTextureProperty.channels,\n ...featureTextureProperty.texture\n };\n const propertyData: number[] | null = getPrimitiveTextureData(\n scenegraph,\n textureInfoTopLevel,\n primitive\n );\n if (!propertyData) {\n return;\n }\n primitivePropertyDataToAttributes(\n scenegraph,\n attributeName,\n propertyData,\n featureTextureTable,\n primitive\n );\n}\n"],"mappings":"SAcQA,cAAc;AAAA,SAIpBC,+BAA+B,EAC/BC,uBAAuB,EACvBC,iCAAiC,EACjCC,uBAAuB,EAEvBC,qBAAqB,EACrBC,+BAA+B,EAC/BC,4BAA4B,EAC5BC,qBAAqB;AAIvB,MAAMC,yBAAyB,GAAG,sBAAsB;AACxD,OAAO,MAAMC,IAAI,GAAGD,yBAAyB;AAE7C,OAAO,eAAeE,MAAMA,CAACC,QAAsB,EAAEC,OAA0B,EAAiB;EAC9F,MAAMC,UAAU,GAAG,IAAId,cAAc,CAACY,QAAQ,CAAC;EAC/CG,wBAAwB,CAACD,UAAU,EAAED,OAAO,CAAC;AAC/C;AAQA,O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AEd,OAAOpF,4BAA4B,CAACyF,UAAU,EAAErC,gBAAgB,EAAEgC,UAAU,CAAC;IAC/E;IACA,OAAO,EAAE;EACX;EAEA,OAAOK,UAAU;AACnB;AASA,SAAS5B,0BAA0BA,CACjCtD,UAA0B,EAC1BqD,sBAAiE,EACjEF,aAAqB,EACX;EACV,MAAMiC,IAAI,GAAGpF,UAAU,CAACwB,IAAI,CAAC4D,IAAI;EACjC,IAAI,CAACA,IAAI,CAACC,MAAM,EAAE;IAChB,OAAO,EAAE;EACX;EACA,MAAMC,mBAA6B,GAAG,EAAE;EACxC,KAAK,MAAMC,IAAI,IAAIH,IAAI,CAACC,MAAM,EAAE;IAC9B,KAAK,MAAMG,SAAS,IAAID,IAAI,CAACE,UAAU,EAAE;MACvCC,wBAAwB,CACtB1F,UAAU,EACVmD,aAAa,EACbE,sBAAsB,EACtBiC,mBAAmB,EACnBE,SACF,CAAC;IACH;EACF;EACA,OAAOF,mBAAmB;AAC5B;AAUA,SAASI,wBAAwBA,CAC/B1F,UAA0B,EAC1BmD,aAAqB,EACrBE,sBAAiE,EACjEiC,mBAA6B,EAC7BE,SAA4B,EACtB;EACN,MAAMG,mBAA4C,GAAG;IACnDC,QAAQ,EAAEvC,sBAAsB,CAACuC,QAAQ;IACzC,GAAGvC,sBAAsB,CAACnC;EAC5B,CAAC;EACD,MAAM2E,YAA6B,GAAGzG,uBAAuB,CAC3DY,UAAU,EACV2F,mBAAmB,EACnBH,SACF,CAAC;EACD,IAAI,CAACK,YAAY,EAAE;IACjB;EACF;EACAxG,iCAAiC,CAC/BW,UAAU,EACVmD,aAAa,EACb0C,YAAY,EACZP,mBAAmB,EACnBE,SACF,CAAC;AACH"}
1
+ {"version":3,"file":"EXT_feature_metadata.js","names":["GLTFScenegraph","convertRawBufferToMetadataArray","getPrimitiveTextureData","primitivePropertyDataToAttributes","getArrayElementByteSize","getOffsetsForProperty","parseVariableLengthArrayNumeric","parseFixedLengthArrayNumeric","getPropertyDataString","EXT_FEATURE_METADATA_NAME","name","decode","gltfData","options","scenegraph","decodeExtFeatureMetadata","_options$gltf","_options$gltf2","gltf","loadBuffers","extension","getExtension","loadImages","decodePropertyTextures","decodePropertyTables","schema","schemaClasses","classes","featureTextures","schemaName","schemaClass","featureTexture","findFeatureTextureByClass","handleFeatureTextureProperties","propertyTables","featureTables","propertyTable","findPropertyTableByClass","processPropertyTable","schemaClassName","propertyTableName","class","featureTexturesName","featureTable","_schema$classes","Error","numberOfElements","count","propertyName","properties","_propertyTable$proper","classProperty","propertyTableProperty","data","getPropertyDataFromBinarySource","attributeName","_featureTexture$prope","featureTextureProperty","getPropertyDataFromTexture","numberOfFeatures","featureTableProperty","bufferView","dataArray","getTypedArrayForBufferView","arrayOffsets","getArrayOffsetsForProperty","stringOffsets","getStringOffsetsForProperty","type","componentType","isNumericProperty","getPropertyDataNumeric","componentCount","arrayOffsetBufferView","offsetType","stringOffsetBufferView","schemaProperty","types","includes","valuesDataBytes","isArray","arrayCount","attributeType","elementSize","elementCount","byteLength","valuesData","length","json","meshes","featureTextureTable","mesh","primitive","primitives","processPrimitiveTextures","textureInfoTopLevel","channels","texture","propertyData"],"sources":["../../../../src/lib/extensions/deprecated/EXT_feature_metadata.ts"],"sourcesContent":["/* eslint-disable camelcase */\nimport type {GLTF, GLTFTextureInfoMetadata} from '../../types/gltf-json-schema';\nimport type {\n GLTF_EXT_feature_metadata_Class,\n GLTF_EXT_feature_metadata_ClassProperty,\n GLTF_EXT_feature_metadata_FeatureTable,\n GLTF_EXT_feature_metadata_FeatureTableProperty,\n GLTF_EXT_feature_metadata_FeatureTexture,\n GLTF_EXT_feature_metadata_GLTF,\n GLTF_EXT_feature_metadata_TextureAccessor,\n GLTF_EXT_feature_metadata_Schema\n} from '../../types/gltf-ext-feature-metadata-schema';\nimport type {BigTypedArray, TypedArray} from '@loaders.gl/schema';\nimport {GLTFScenegraph} from '../../api/gltf-scenegraph';\nimport {GLTFMeshPrimitive} from '../../types/gltf-json-schema';\nimport {GLTFLoaderOptions} from '../../../gltf-loader';\nimport {\n convertRawBufferToMetadataArray,\n getPrimitiveTextureData,\n primitivePropertyDataToAttributes,\n getArrayElementByteSize,\n NumericComponentType,\n getOffsetsForProperty,\n parseVariableLengthArrayNumeric,\n parseFixedLengthArrayNumeric,\n getPropertyDataString\n} from '../utils/3d-tiles-utils';\n\n/** Extension name */\nconst EXT_FEATURE_METADATA_NAME = 'EXT_feature_metadata';\nexport const name = EXT_FEATURE_METADATA_NAME;\n\nexport async function decode(gltfData: {json: GLTF}, options: GLTFLoaderOptions): Promise<void> {\n const scenegraph = new GLTFScenegraph(gltfData);\n decodeExtFeatureMetadata(scenegraph, options);\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 decodeExtFeatureMetadata(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_feature_metadata_GLTF | null =\n scenegraph.getExtension(EXT_FEATURE_METADATA_NAME);\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_feature_metadata_GLTF\n): void {\n const schema = extension.schema;\n if (!schema) {\n return;\n }\n const schemaClasses = schema.classes;\n\n const {featureTextures} = extension;\n if (schemaClasses && featureTextures) {\n for (const schemaName in schemaClasses) {\n const schemaClass = schemaClasses[schemaName];\n const featureTexture = findFeatureTextureByClass(featureTextures, schemaName);\n\n if (featureTexture) {\n handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass);\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_feature_metadata_GLTF\n): void {\n const schema = extension.schema;\n if (!schema) {\n return;\n }\n const schemaClasses = schema.classes;\n const propertyTables = extension.featureTables;\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: {[key: string]: GLTF_EXT_feature_metadata_FeatureTable},\n schemaClassName: string\n): GLTF_EXT_feature_metadata_FeatureTable | null {\n for (const propertyTableName in propertyTables) {\n const propertyTable = propertyTables[propertyTableName];\n if (propertyTable.class === schemaClassName) {\n return propertyTable;\n }\n }\n\n return null;\n}\n\nfunction findFeatureTextureByClass(\n featureTextures: {[key: string]: GLTF_EXT_feature_metadata_FeatureTexture},\n schemaClassName: string\n): GLTF_EXT_feature_metadata_FeatureTexture | null {\n for (const featureTexturesName in featureTextures) {\n const featureTable = featureTextures[featureTexturesName];\n\n if (featureTable.class === schemaClassName) {\n return featureTable;\n }\n }\n\n return null;\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_feature_metadata_Schema,\n propertyTable: GLTF_EXT_feature_metadata_FeatureTable\n): void {\n // Though 'class' is not required by spec, it doesn't make any scence when it's not provided.\n // So, bale out here.\n if (!propertyTable.class) {\n return;\n }\n\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_feature_metadata_FeatureTableProperty | 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 * Navigates through all properies in feature texture and gets properties data.\n * Data will be stored in featureTexture.properties[propertyName].data.\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param featureTexture\n * @param schemaClass\n */\nfunction handleFeatureTextureProperties(\n scenegraph: GLTFScenegraph,\n featureTexture: GLTF_EXT_feature_metadata_FeatureTexture,\n schemaClass: GLTF_EXT_feature_metadata_Class\n): void {\n const attributeName = featureTexture.class;\n\n for (const propertyName in schemaClass.properties) {\n const featureTextureProperty = featureTexture?.properties?.[propertyName];\n\n if (featureTextureProperty) {\n const data = getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName);\n featureTextureProperty.data = data;\n }\n }\n}\n\n/**\n * Decodes properties from binary sourse based on property type.\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param schemaProperty\n * @param numberOfFeatures\n * @param featureTableProperty\n */\nfunction getPropertyDataFromBinarySource(\n scenegraph: GLTFScenegraph,\n schema: GLTF_EXT_feature_metadata_Schema,\n classProperty: GLTF_EXT_feature_metadata_ClassProperty,\n numberOfFeatures: number,\n featureTableProperty: GLTF_EXT_feature_metadata_FeatureTableProperty\n): string[] | BigTypedArray | string[][] | BigTypedArray[] {\n let data: string[] | BigTypedArray | string[][] | BigTypedArray[] = [];\n const bufferView = featureTableProperty.bufferView;\n const dataArray: Uint8Array = scenegraph.getTypedArrayForBufferView(bufferView);\n\n const arrayOffsets = getArrayOffsetsForProperty(\n scenegraph,\n classProperty,\n featureTableProperty,\n numberOfFeatures\n );\n const stringOffsets = getStringOffsetsForProperty(\n scenegraph,\n classProperty,\n featureTableProperty,\n numberOfFeatures\n );\n\n if (classProperty.type === 'STRING' || classProperty.componentType === 'STRING') {\n data = getPropertyDataString(numberOfFeatures, dataArray, arrayOffsets, stringOffsets);\n } else if (isNumericProperty(classProperty)) {\n data = getPropertyDataNumeric(classProperty, numberOfFeatures, dataArray, arrayOffsets);\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_feature_metadata_ClassProperty,\n propertyTableProperty: GLTF_EXT_feature_metadata_FeatureTableProperty,\n numberOfElements: number\n): TypedArray | null {\n /*\n If ARRAY is used, then componentType must also be specified.\n ARRAY is a fixed-length array when componentCount is defined, and variable-length otherwise.\n*/\n if (\n classProperty.type === 'ARRAY' &&\n // `componentCount` is a number of fixed-length array elements.\n // If `componentCount` is NOT defined, it's a VARIABLE-length array\n typeof classProperty.componentCount === 'undefined' &&\n // `arrayOffsetBufferView` is an index of the buffer view containing offsets for variable-length arrays.\n typeof propertyTableProperty.arrayOffsetBufferView !== 'undefined'\n ) {\n // Data are in a VARIABLE-length array\n return getOffsetsForProperty(\n scenegraph,\n propertyTableProperty.arrayOffsetBufferView,\n propertyTableProperty.offsetType || 'UINT32', // offsetType is used both for stringOffsetBufferView and arrayOffsetBufferView\n numberOfElements\n );\n }\n return null;\n}\n\n/**\n * Parses featureTable.property.stringOffsetBufferView.\n * String offsets is an array of offsets of strings in the united array of characters.\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 of offset values. The number of offsets in the array is equal to `numberOfElements` plus one.\n * @see https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_feature_metadata/schema/featureTable.property.schema.json#L50C10-L50C32\n */\nfunction getStringOffsetsForProperty(\n scenegraph: GLTFScenegraph,\n classProperty: GLTF_EXT_feature_metadata_ClassProperty,\n propertyTableProperty: GLTF_EXT_feature_metadata_FeatureTableProperty,\n numberOfElements: number\n): TypedArray | null {\n if (\n typeof propertyTableProperty.stringOffsetBufferView !== 'undefined' // `stringOffsetBufferView` 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.stringOffsetBufferView,\n propertyTableProperty.offsetType || 'UINT32', // offsetType is used both for stringOffsetBufferView and arrayOffsetBufferView\n numberOfElements\n );\n }\n return null;\n}\n\n/**\n * Checks if the feature table property is of numeric type.\n * @param schemaPropertyType - feature table property\n * @returns true if property is numeric, else - false\n */\nfunction isNumericProperty(schemaProperty: GLTF_EXT_feature_metadata_ClassProperty): boolean {\n const types = [\n 'UINT8',\n 'INT16',\n 'UINT16',\n 'INT32',\n 'UINT32',\n 'INT64',\n 'UINT64',\n 'FLOAT32',\n 'FLOAT64'\n ];\n return (\n types.includes(schemaProperty.type) ||\n (typeof schemaProperty.componentType !== 'undefined' &&\n types.includes(schemaProperty.componentType))\n );\n}\n\n/**\n * Decodes properties of numeric 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_feature_metadata_ClassProperty,\n numberOfElements: number,\n valuesDataBytes: Uint8Array,\n arrayOffsets: TypedArray | null\n): BigTypedArray | BigTypedArray[] {\n const isArray = classProperty.type === 'ARRAY';\n const arrayCount = classProperty.componentCount;\n\n /*\n We are getting Numeric data. So,\n the component type can be one of NumericComponentType,\n the attribute type should be 'SCALAR'\n */\n const attributeType = 'SCALAR';\n const componentType = classProperty.componentType || classProperty.type;\n const elementSize = getArrayElementByteSize(attributeType, componentType);\n const elementCount = valuesDataBytes.byteLength / elementSize;\n\n const valuesData: BigTypedArray = convertRawBufferToMetadataArray(\n valuesDataBytes,\n attributeType,\n componentType as NumericComponentType,\n elementCount\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 * Gets properties from texture associated with all mesh primitives.\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param featureTextureProperty\n * @param attributeName\n * @returns Feature texture data\n */\nfunction getPropertyDataFromTexture(\n scenegraph: GLTFScenegraph,\n featureTextureProperty: GLTF_EXT_feature_metadata_TextureAccessor,\n attributeName: string\n): number[] {\n const json = scenegraph.gltf.json;\n if (!json.meshes) {\n return [];\n }\n const featureTextureTable: number[] = [];\n for (const mesh of json.meshes) {\n for (const primitive of mesh.primitives) {\n processPrimitiveTextures(\n scenegraph,\n attributeName,\n featureTextureProperty,\n featureTextureTable,\n primitive\n );\n }\n }\n return featureTextureTable;\n}\n\n/**\n * Processes data encoded in the texture associated with the primitive. This data will be accessible through the attributes.\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param attributeName\n * @param featureTextureProperty\n * @param featureTextureTable\n * @param primitive\n */\nfunction processPrimitiveTextures(\n scenegraph: GLTFScenegraph,\n attributeName: string,\n featureTextureProperty: GLTF_EXT_feature_metadata_TextureAccessor,\n featureTextureTable: number[],\n primitive: GLTFMeshPrimitive\n): void {\n const textureInfoTopLevel: GLTFTextureInfoMetadata = {\n channels: featureTextureProperty.channels,\n ...featureTextureProperty.texture\n };\n const propertyData: number[] | null = getPrimitiveTextureData(\n scenegraph,\n textureInfoTopLevel,\n primitive\n );\n if (!propertyData) {\n return;\n }\n primitivePropertyDataToAttributes(\n scenegraph,\n attributeName,\n propertyData,\n featureTextureTable,\n primitive\n );\n}\n"],"mappings":"SAaQA,cAAc;AAAA,SAIpBC,+BAA+B,EAC/BC,uBAAuB,EACvBC,iCAAiC,EACjCC,uBAAuB,EAEvBC,qBAAqB,EACrBC,+BAA+B,EAC/BC,4BAA4B,EAC5BC,qBAAqB;AAIvB,MAAMC,yBAAyB,GAAG,sBAAsB;AACxD,OAAO,MAAMC,IAAI,GAAGD,yBAAyB;AAE7C,OAAO,eAAeE,MAAMA,CAACC,QAAsB,EAAEC,OAA0B,EAAiB;EAC9F,MAAMC,UAAU,GAAG,IAAId,cAAc,CAACY,QAAQ,CAAC;EAC/CG,wBAAwB,CAACD,UAAU,EAAED,OAAO,CAAC;AAC/C;AAOA,SAASE,wBAAwBA,CAACD,UAA0B,EAAED,OAA0B,EAAQ;EAAA,IAAAG,aAAA,EAAAC,cAAA;EAG9F,IAAI,GAAAD,aAAA,GAACH,OAAO,CAACK,IAAI,cAAAF,aAAA,eAAZA,aAAA,CAAcG,WAAW,GAAE;IAC9B;EACF;EACA,MAAMC,SAAgD,GACpDN,UAAU,CAACO,YAAY,CAACZ,yBAAyB,CAAC;EACpD,IAAI,CAACW,SAA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AI,IAAIH,IAAI,CAACC,MAAM,EAAE;IAC9B,KAAK,MAAMG,SAAS,IAAID,IAAI,CAACE,UAAU,EAAE;MACvCC,wBAAwB,CACtBhF,UAAU,EACVyC,aAAa,EACbE,sBAAsB,EACtBiC,mBAAmB,EACnBE,SACF,CAAC;IACH;EACF;EACA,OAAOF,mBAAmB;AAC5B;AAUA,SAASI,wBAAwBA,CAC/BhF,UAA0B,EAC1ByC,aAAqB,EACrBE,sBAAiE,EACjEiC,mBAA6B,EAC7BE,SAA4B,EACtB;EACN,MAAMG,mBAA4C,GAAG;IACnDC,QAAQ,EAAEvC,sBAAsB,CAACuC,QAAQ;IACzC,GAAGvC,sBAAsB,CAACwC;EAC5B,CAAC;EACD,MAAMC,YAA6B,GAAGhG,uBAAuB,CAC3DY,UAAU,EACViF,mBAAmB,EACnBH,SACF,CAAC;EACD,IAAI,CAACM,YAAY,EAAE;IACjB;EACF;EACA/F,iCAAiC,CAC/BW,UAAU,EACVyC,aAAa,EACb2C,YAAY,EACZR,mBAAmB,EACnBE,SACF,CAAC;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/gltf",
3
- "version": "4.0.0-beta.3",
3
+ "version": "4.0.0-beta.5",
4
4
  "description": "Framework-independent loader for the glTF format",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -42,11 +42,11 @@
42
42
  "build-bundle": "ocular-bundle ./src/index.ts"
43
43
  },
44
44
  "dependencies": {
45
- "@loaders.gl/draco": "4.0.0-beta.3",
46
- "@loaders.gl/images": "4.0.0-beta.3",
47
- "@loaders.gl/loader-utils": "4.0.0-beta.3",
48
- "@loaders.gl/textures": "4.0.0-beta.3",
45
+ "@loaders.gl/draco": "4.0.0-beta.5",
46
+ "@loaders.gl/images": "4.0.0-beta.5",
47
+ "@loaders.gl/loader-utils": "4.0.0-beta.5",
48
+ "@loaders.gl/textures": "4.0.0-beta.5",
49
49
  "@math.gl/core": "^4.0.0"
50
50
  },
51
- "gitHead": "7ba9621cc51c7a26c407086ac86171f35b8712af"
51
+ "gitHead": "a6f5a0d1a316cc22396e5a4d480c14329d1ef146"
52
52
  }
package/src/index.ts CHANGED
@@ -47,7 +47,14 @@ export type {
47
47
  GLTF_EXT_feature_metadata_FeatureIdTextureAccessor
48
48
  } from './lib/types/gltf-ext-feature-metadata-schema';
49
49
 
50
- export type {GLTF_EXT_structural_metadata_GLTF} from './lib/types/gltf-ext-structural-metadata-schema';
50
+ export type {
51
+ GLTF_EXT_structural_metadata_GLTF,
52
+ GLTF_EXT_structural_metadata_Schema,
53
+ GLTF_EXT_structural_metadata_PropertyTable,
54
+ GLTF_EXT_structural_metadata_PropertyTexture,
55
+ GLTF_EXT_structural_metadata_Class,
56
+ GLTF_EXT_structural_metadata_ClassProperty
57
+ } from './lib/types/gltf-ext-structural-metadata-schema';
51
58
 
52
59
  export type {
53
60
  GLTF_EXT_mesh_features,
@@ -57,8 +64,6 @@ export type {
57
64
  export {name as EXT_MESH_FEATURES} from './lib/extensions/EXT_mesh_features';
58
65
  export {name as EXT_STRUCTURAL_METADATA} from './lib/extensions/EXT_structural_metadata';
59
66
  export {name as EXT_FEATURE_METADATA} from './lib/extensions/deprecated/EXT_feature_metadata';
60
- export {getPropertyTableFromExtFeatureMetadata} from './lib/extensions/deprecated/EXT_feature_metadata';
61
- export {getPropertyTableFromExtStructuralMetadata} from './lib/extensions/EXT_structural_metadata';
62
67
 
63
68
  // Postprocessed types (modified GLTF types)
64
69
  export type {
@@ -78,9 +78,9 @@ export class GLTFScenegraph {
78
78
  return data;
79
79
  }
80
80
 
81
- getExtraData(key: string): {[key: string]: unknown} {
81
+ getExtraData(key: string): unknown {
82
82
  // TODO - Data is already unpacked by GLBParser
83
- const extras = this.json.extras || {};
83
+ const extras = (this.json.extras || {}) as Record<string, unknown>;
84
84
  return extras[key];
85
85
  }
86
86
 
@@ -166,16 +166,16 @@ export class GLTFScenegraph {
166
166
  return this.getObject('buffers', index) as GLTFBuffer;
167
167
  }
168
168
 
169
- getObject(array: string, index: number | object): object {
169
+ getObject(array: string, index: number | object): Record<string, unknown> {
170
170
  // check if already resolved
171
171
  if (typeof index === 'object') {
172
- return index;
172
+ return index as Record<string, unknown>;
173
173
  }
174
174
  const object = this.json[array] && (this.json[array] as {}[])[index];
175
175
  if (!object) {
176
176
  throw new Error(`glTF file error: Could not find ${array}[${index}]`); // eslint-disable-line
177
177
  }
178
- return object;
178
+ return object as Record<string, unknown>;
179
179
  }
180
180
 
181
181
  /**
@@ -15,7 +15,6 @@ import type {
15
15
  GLTF_EXT_structural_metadata_Primitive
16
16
  } from '../types/gltf-ext-structural-metadata-schema';
17
17
  import type {GLTFLoaderOptions} from '../../gltf-loader';
18
- import type {FeatureTableJson} from '../types/gltf-types';
19
18
 
20
19
  import {GLTFScenegraph} from '../api/gltf-scenegraph';
21
20
  import {
@@ -38,52 +37,6 @@ export async function decode(gltfData: {json: GLTF}, options: GLTFLoaderOptions)
38
37
  decodeExtStructuralMetadata(scenegraph, options);
39
38
  }
40
39
 
41
- /**
42
- * Handles EXT_structural_metadata to get property table.
43
- * @param extension - Global level of EXT_STRUCTURAL_METADATA extension.
44
- * @param metadataClass - User selected feature metadata class name.
45
- * @returns {FeatureTableJson | null} Property table or null if the extension can't be handled properly.
46
- */
47
- export function getPropertyTableFromExtStructuralMetadata(
48
- extension: GLTF_EXT_structural_metadata_GLTF,
49
- metadataClass?: string
50
- ): FeatureTableJson | null {
51
- if (extension.propertyTables) {
52
- /**
53
- * Take only first feature table to generate attributes storage info object.
54
- * TODO: Think about getting data from all feature tables?
55
- * It can be tricky just because 3dTiles is able to have multiple featureId attributes and multiple feature tables.
56
- * In I3S we should decide which featureIds attribute will be passed to geometry data.
57
- */
58
- const firstPropertyTable = extension?.propertyTables[0];
59
- const propertyTableWithData = {};
60
-
61
- for (const propertyName in firstPropertyTable.properties) {
62
- propertyTableWithData[propertyName] = firstPropertyTable.properties[propertyName].data;
63
- }
64
-
65
- return propertyTableWithData;
66
- }
67
-
68
- if (extension.propertyTextures) {
69
- // TODO: Think about getting data from all property textures.
70
- const firstPropertyTexture = extension?.propertyTextures[0];
71
- const propertyTableWithData = {};
72
-
73
- for (const propertyName in firstPropertyTexture.properties) {
74
- propertyTableWithData[propertyName] = firstPropertyTexture.properties[propertyName].data;
75
- }
76
-
77
- return propertyTableWithData;
78
- }
79
-
80
- // eslint-disable-next-line no-console
81
- console.warn(
82
- 'Cannot get property table from EXT_structural_metadata extension. There is neither propertyTables, nor propertyTextures in the extension.'
83
- );
84
- return null;
85
- }
86
-
87
40
  /*
88
41
  // Example of the extension.
89
42
  // See more info at https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata
@@ -11,7 +11,6 @@ import type {
11
11
  GLTF_EXT_feature_metadata_Schema
12
12
  } from '../../types/gltf-ext-feature-metadata-schema';
13
13
  import type {BigTypedArray, TypedArray} from '@loaders.gl/schema';
14
- import type {FeatureTableJson} from '../../types/gltf-types';
15
14
  import {GLTFScenegraph} from '../../api/gltf-scenegraph';
16
15
  import {GLTFMeshPrimitive} from '../../types/gltf-json-schema';
17
16
  import {GLTFLoaderOptions} from '../../../gltf-loader';
@@ -36,65 +35,6 @@ export async function decode(gltfData: {json: GLTF}, options: GLTFLoaderOptions)
36
35
  decodeExtFeatureMetadata(scenegraph, options);
37
36
  }
38
37
 
39
- /**
40
- * Handles EXT_feature_metadata to get property table.
41
- * @param extension - Global level of EXT_FEATURE_METADATA extension.
42
- * @param metadataClass - User selected feature metadata class name.
43
- * @returns {FeatureTableJson | null} Property table or null if the extension can't be handled properly.
44
- */
45
- export function getPropertyTableFromExtFeatureMetadata(
46
- extension: GLTF_EXT_feature_metadata_GLTF,
47
- metadataClass?: string
48
- ): FeatureTableJson | null {
49
- if (extension.featureTables) {
50
- /**
51
- * Take only first feature table to generate attributes storage info object.
52
- * TODO: Think about getting data from all feature tables?
53
- * It can be tricky just because 3dTiles is able to have multiple featureId attributes and multiple feature tables.
54
- * In I3S we should decide which featureIds attribute will be passed to geometry data.
55
- */
56
- const firstFeatureTableName = Object.keys(extension.featureTables)?.[0];
57
-
58
- if (firstFeatureTableName) {
59
- const featureTable = extension.featureTables[firstFeatureTableName];
60
- const propertyTable = {};
61
-
62
- for (const propertyName in featureTable.properties) {
63
- propertyTable[propertyName] = featureTable.properties[propertyName].data;
64
- }
65
-
66
- return propertyTable;
67
- }
68
- }
69
-
70
- if (extension.featureTextures) {
71
- let featureTexture: string | undefined;
72
- for (const textureKey in extension.featureTextures) {
73
- const texture = extension.featureTextures[textureKey];
74
- if (texture.class === metadataClass) {
75
- featureTexture = textureKey;
76
- }
77
- }
78
-
79
- if (typeof featureTexture === 'string') {
80
- const featureTable = extension.featureTextures[featureTexture];
81
- const propertyTable = {};
82
-
83
- for (const propertyName in featureTable.properties) {
84
- propertyTable[propertyName] = featureTable.properties[propertyName].data;
85
- }
86
-
87
- return propertyTable;
88
- }
89
- }
90
-
91
- // eslint-disable-next-line no-console
92
- console.warn(
93
- 'Cannot get property table from EXT_feature_metadata extension. There is neither featureTables, nor featureTextures in the extension.'
94
- );
95
- return null;
96
- }
97
-
98
38
  /**
99
39
  * Decodes feature metadata from extension.
100
40
  * @param scenegraph - Instance of the class for structured access to GLTF data.