"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name12 in all) __defProp(target, name12, { get: all[name12], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // dist/index.js var dist_exports = {}; __export(dist_exports, { EXT_FEATURE_METADATA: () => name3, EXT_MESH_FEATURES: () => name, EXT_STRUCTURAL_METADATA: () => name2, GLBLoader: () => GLBLoader, GLBWriter: () => GLBWriter, GLTFLoader: () => GLTFLoader, GLTFScenegraph: () => GLTFScenegraph, GLTFWriter: () => GLTFWriter, _getMemoryUsageGLTF: () => getMemoryUsageGLTF, createExtMeshFeatures: () => createExtMeshFeatures, createExtStructuralMetadata: () => createExtStructuralMetadata, postProcessGLTF: () => postProcessGLTF }); module.exports = __toCommonJS(dist_exports); // dist/lib/extensions/EXT_mesh_features.js var EXT_mesh_features_exports = {}; __export(EXT_mesh_features_exports, { createExtMeshFeatures: () => createExtMeshFeatures, decode: () => decode, encode: () => encode, name: () => name }); // dist/lib/api/gltf-scenegraph.js var import_images = require("@loaders.gl/images"); var import_loader_utils = require("@loaders.gl/loader-utils"); // dist/lib/utils/assert.js function assert(condition, message) { if (!condition) { throw new Error(message || "assert failed: gltf"); } } // dist/lib/gltf-utils/gltf-constants.js var COMPONENTS = { SCALAR: 1, VEC2: 2, VEC3: 3, VEC4: 4, MAT2: 4, MAT3: 9, MAT4: 16 }; var BYTES = { 5120: 1, // BYTE 5121: 1, // UNSIGNED_BYTE 5122: 2, // SHORT 5123: 2, // UNSIGNED_SHORT 5125: 4, // UNSIGNED_INT 5126: 4 // FLOAT }; // dist/lib/gltf-utils/gltf-utils.js var MIPMAP_FACTOR = 1.33; var TYPES = ["SCALAR", "VEC2", "VEC3", "VEC4"]; var ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT = [ [Int8Array, 5120], [Uint8Array, 5121], [Int16Array, 5122], [Uint16Array, 5123], [Uint32Array, 5125], [Float32Array, 5126], [Float64Array, 5130] ]; var ARRAY_TO_COMPONENT_TYPE = new Map(ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT); var ATTRIBUTE_TYPE_TO_COMPONENTS = { SCALAR: 1, VEC2: 2, VEC3: 3, VEC4: 4, MAT2: 4, MAT3: 9, MAT4: 16 }; var ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE = { 5120: 1, 5121: 1, 5122: 2, 5123: 2, 5125: 4, 5126: 4 }; var ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = { 5120: Int8Array, 5121: Uint8Array, 5122: Int16Array, 5123: Uint16Array, 5125: Uint32Array, 5126: Float32Array }; function getAccessorTypeFromSize(size) { const type = TYPES[size - 1]; return type || TYPES[0]; } function getComponentTypeFromArray(typedArray) { const componentType = ARRAY_TO_COMPONENT_TYPE.get(typedArray.constructor); if (!componentType) { throw new Error("Illegal typed array"); } return componentType; } function getAccessorArrayTypeAndLength(accessor, bufferView) { const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[accessor.componentType]; const components = ATTRIBUTE_TYPE_TO_COMPONENTS[accessor.type]; const bytesPerComponent = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[accessor.componentType]; const length = accessor.count * components; const byteLength = accessor.count * components * bytesPerComponent; assert(byteLength >= 0 && byteLength <= bufferView.byteLength); const componentByteSize = BYTES[accessor.componentType]; const numberOfComponentsInElement = COMPONENTS[accessor.type]; return { ArrayType, length, byteLength, componentByteSize, numberOfComponentsInElement }; } function getMemoryUsageGLTF(gltf) { let { images, bufferViews } = gltf; images = images || []; bufferViews = bufferViews || []; const imageBufferViews = images.map((i) => i.bufferView); bufferViews = bufferViews.filter((view) => !imageBufferViews.includes(view)); const bufferMemory = bufferViews.reduce((acc, view) => acc + view.byteLength, 0); const pixelCount = images.reduce((acc, image) => { const { width, height } = image.image; return acc + width * height; }, 0); return bufferMemory + Math.ceil(4 * pixelCount * MIPMAP_FACTOR); } // dist/lib/gltf-utils/get-typed-array.js function getTypedArrayForBufferView(json, buffers, bufferViewIndex) { const bufferView = json.bufferViews[bufferViewIndex]; assert(bufferView); const bufferIndex = bufferView.buffer; const binChunk = buffers[bufferIndex]; assert(binChunk); const byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset; return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength); } function getTypedArrayForAccessor(json, buffers, accessor) { var _a, _b; const gltfAccessor = typeof accessor === "number" ? (_a = json.accessors) == null ? void 0 : _a[accessor] : accessor; if (!gltfAccessor) { throw new Error(`No gltf accessor ${JSON.stringify(accessor)}`); } const bufferView = (_b = json.bufferViews) == null ? void 0 : _b[gltfAccessor.bufferView || 0]; if (!bufferView) { throw new Error(`No gltf buffer view for accessor ${bufferView}`); } const { arrayBuffer, byteOffset: bufferByteOffset } = buffers[bufferView.buffer]; const byteOffset = (bufferByteOffset || 0) + (gltfAccessor.byteOffset || 0) + (bufferView.byteOffset || 0); const { ArrayType, length, componentByteSize, numberOfComponentsInElement } = getAccessorArrayTypeAndLength(gltfAccessor, bufferView); const elementByteSize = componentByteSize * numberOfComponentsInElement; const elementAddressScale = bufferView.byteStride || elementByteSize; if (typeof bufferView.byteStride === "undefined" || bufferView.byteStride === elementByteSize) { const result2 = new ArrayType(arrayBuffer, byteOffset, length); return result2; } const result = new ArrayType(length); for (let i = 0; i < gltfAccessor.count; i++) { const values = new ArrayType(arrayBuffer, byteOffset + i * elementAddressScale, numberOfComponentsInElement); result.set(values, i * numberOfComponentsInElement); } return result; } // dist/lib/api/gltf-scenegraph.js function makeDefaultGLTFJson() { return { asset: { version: "2.0", generator: "loaders.gl" }, buffers: [], extensions: {}, extensionsRequired: [], extensionsUsed: [] }; } var GLTFScenegraph = class { // internal gltf; sourceBuffers; byteLength; // TODO - why is this not GLTFWithBuffers - what happens to images? constructor(gltf) { this.gltf = { json: (gltf == null ? void 0 : gltf.json) || makeDefaultGLTFJson(), buffers: (gltf == null ? void 0 : gltf.buffers) || [], images: (gltf == null ? void 0 : gltf.images) || [] }; this.sourceBuffers = []; this.byteLength = 0; if (this.gltf.buffers && this.gltf.buffers[0]) { this.byteLength = this.gltf.buffers[0].byteLength; this.sourceBuffers = [this.gltf.buffers[0]]; } } // Accessors get json() { return this.gltf.json; } getApplicationData(key) { const data = this.json[key]; return data; } getExtraData(key) { const extras = this.json.extras || {}; return extras[key]; } hasExtension(extensionName) { const isUsedExtension = this.getUsedExtensions().find((name12) => name12 === extensionName); const isRequiredExtension = this.getRequiredExtensions().find((name12) => name12 === extensionName); return typeof isUsedExtension === "string" || typeof isRequiredExtension === "string"; } getExtension(extensionName) { const isExtension = this.getUsedExtensions().find((name12) => name12 === extensionName); const extensions = this.json.extensions || {}; return isExtension ? extensions[extensionName] : null; } getRequiredExtension(extensionName) { const isRequired = this.getRequiredExtensions().find((name12) => name12 === extensionName); return isRequired ? this.getExtension(extensionName) : null; } getRequiredExtensions() { return this.json.extensionsRequired || []; } getUsedExtensions() { return this.json.extensionsUsed || []; } getRemovedExtensions() { return this.json.extensionsRemoved || []; } getObjectExtension(object, extensionName) { const extensions = object.extensions || {}; return extensions[extensionName]; } getScene(index) { return this.getObject("scenes", index); } getNode(index) { return this.getObject("nodes", index); } getSkin(index) { return this.getObject("skins", index); } getMesh(index) { return this.getObject("meshes", index); } getMaterial(index) { return this.getObject("materials", index); } getAccessor(index) { return this.getObject("accessors", index); } // getCamera(index: number): object | null { // return null; // TODO: fix thi: object as null; // } getTexture(index) { return this.getObject("textures", index); } getSampler(index) { return this.getObject("samplers", index); } getImage(index) { return this.getObject("images", index); } getBufferView(index) { return this.getObject("bufferViews", index); } getBuffer(index) { return this.getObject("buffers", index); } getObject(array, index) { if (typeof index === "object") { return index; } const object = this.json[array] && this.json[array][index]; if (!object) { throw new Error(`glTF file error: Could not find ${array}[${index}]`); } return object; } /** * Accepts buffer view index or buffer view object * @returns a `Uint8Array` */ getTypedArrayForBufferView(bufferView) { bufferView = this.getBufferView(bufferView); const bufferIndex = bufferView.buffer; const binChunk = this.gltf.buffers[bufferIndex]; assert(binChunk); const byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset; return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength); } /** Accepts accessor index or accessor object * @returns a typed array with type that matches the types */ getTypedArrayForAccessor(accessor) { const gltfAccessor = this.getAccessor(accessor); return getTypedArrayForAccessor(this.gltf.json, this.gltf.buffers, gltfAccessor); } /** accepts accessor index or accessor object * returns a `Uint8Array` */ getTypedArrayForImageData(image) { image = this.getAccessor(image); const bufferView = this.getBufferView(image.bufferView); const buffer = this.getBuffer(bufferView.buffer); const arrayBuffer = buffer.data; const byteOffset = bufferView.byteOffset || 0; return new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength); } // MODIFERS /** * Add an extra application-defined key to the top-level data structure */ addApplicationData(key, data) { this.json[key] = data; return this; } /** * `extras` - Standard GLTF field for storing application specific data */ addExtraData(key, data) { this.json.extras = this.json.extras || {}; this.json.extras[key] = data; return this; } addObjectExtension(object, extensionName, data) { object.extensions = object.extensions || {}; object.extensions[extensionName] = data; this.registerUsedExtension(extensionName); return this; } setObjectExtension(object, extensionName, data) { const extensions = object.extensions || {}; extensions[extensionName] = data; } removeObjectExtension(object, extensionName) { const extensions = (object == null ? void 0 : object.extensions) || {}; if (extensions[extensionName]) { this.json.extensionsRemoved = this.json.extensionsRemoved || []; const extensionsRemoved = this.json.extensionsRemoved; if (!extensionsRemoved.includes(extensionName)) { extensionsRemoved.push(extensionName); } } delete extensions[extensionName]; } /** * Add to standard GLTF top level extension object, mark as used */ addExtension(extensionName, extensionData = {}) { assert(extensionData); this.json.extensions = this.json.extensions || {}; this.json.extensions[extensionName] = extensionData; this.registerUsedExtension(extensionName); return extensionData; } /** * Standard GLTF top level extension object, mark as used and required */ addRequiredExtension(extensionName, extensionData = {}) { assert(extensionData); this.addExtension(extensionName, extensionData); this.registerRequiredExtension(extensionName); return extensionData; } /** * Add extensionName to list of used extensions */ registerUsedExtension(extensionName) { this.json.extensionsUsed = this.json.extensionsUsed || []; if (!this.json.extensionsUsed.find((ext) => ext === extensionName)) { this.json.extensionsUsed.push(extensionName); } } /** * Add extensionName to list of required extensions */ registerRequiredExtension(extensionName) { this.registerUsedExtension(extensionName); this.json.extensionsRequired = this.json.extensionsRequired || []; if (!this.json.extensionsRequired.find((ext) => ext === extensionName)) { this.json.extensionsRequired.push(extensionName); } } /** * Removes an extension from the top-level list */ removeExtension(extensionName) { var _a; if ((_a = this.json.extensions) == null ? void 0 : _a[extensionName]) { this.json.extensionsRemoved = this.json.extensionsRemoved || []; const extensionsRemoved = this.json.extensionsRemoved; if (!extensionsRemoved.includes(extensionName)) { extensionsRemoved.push(extensionName); } } if (this.json.extensions) { delete this.json.extensions[extensionName]; } if (this.json.extensionsRequired) { this._removeStringFromArray(this.json.extensionsRequired, extensionName); } if (this.json.extensionsUsed) { this._removeStringFromArray(this.json.extensionsUsed, extensionName); } } /** * Set default scene which is to be displayed at load time */ setDefaultScene(sceneIndex) { this.json.scene = sceneIndex; } /** * @todo: add more properties for scene initialization: * name`, `extensions`, `extras` * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-scene */ addScene(scene) { const { nodeIndices } = scene; this.json.scenes = this.json.scenes || []; this.json.scenes.push({ nodes: nodeIndices }); return this.json.scenes.length - 1; } /** * @todo: add more properties for node initialization: * `name`, `extensions`, `extras`, `camera`, `children`, `skin`, `rotation`, `scale`, `translation`, `weights` * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#node */ addNode(node) { const { meshIndex, matrix } = node; this.json.nodes = this.json.nodes || []; const nodeData = { mesh: meshIndex }; if (matrix) { nodeData.matrix = matrix; } this.json.nodes.push(nodeData); return this.json.nodes.length - 1; } /** Adds a mesh to the json part */ addMesh(mesh) { const { attributes, indices, material, mode = 4 } = mesh; const accessors = this._addAttributes(attributes); const glTFMesh = { primitives: [ { attributes: accessors, mode } ] }; if (indices) { const indicesAccessor = this._addIndices(indices); glTFMesh.primitives[0].indices = indicesAccessor; } if (Number.isFinite(material)) { glTFMesh.primitives[0].material = material; } this.json.meshes = this.json.meshes || []; this.json.meshes.push(glTFMesh); return this.json.meshes.length - 1; } addPointCloud(attributes) { const accessorIndices = this._addAttributes(attributes); const glTFMesh = { primitives: [ { attributes: accessorIndices, mode: 0 // GL.POINTS } ] }; this.json.meshes = this.json.meshes || []; this.json.meshes.push(glTFMesh); return this.json.meshes.length - 1; } /** * Adds a binary image. Builds glTF "JSON metadata" and saves buffer reference * Buffer will be copied into BIN chunk during "pack" * Currently encodes as glTF image * @param imageData * @param mimeType */ addImage(imageData, mimeTypeOpt) { const metadata = (0, import_images.getBinaryImageMetadata)(imageData); const mimeType = mimeTypeOpt || (metadata == null ? void 0 : metadata.mimeType); const bufferViewIndex = this.addBufferView(imageData); const glTFImage = { bufferView: bufferViewIndex, mimeType }; this.json.images = this.json.images || []; this.json.images.push(glTFImage); return this.json.images.length - 1; } /** * Add one untyped source buffer, create a matching glTF `bufferView`, and return its index * @param buffer */ addBufferView(buffer, bufferIndex = 0, byteOffset = this.byteLength) { const byteLength = buffer.byteLength; assert(Number.isFinite(byteLength)); this.sourceBuffers = this.sourceBuffers || []; this.sourceBuffers.push(buffer); const glTFBufferView = { buffer: bufferIndex, // Write offset from the start of the binary body byteOffset, byteLength }; this.byteLength += (0, import_loader_utils.padToNBytes)(byteLength, 4); this.json.bufferViews = this.json.bufferViews || []; this.json.bufferViews.push(glTFBufferView); return this.json.bufferViews.length - 1; } /** * Adds an accessor to a bufferView * @param bufferViewIndex * @param accessor */ addAccessor(bufferViewIndex, accessor) { const glTFAccessor = { bufferView: bufferViewIndex, // @ts-ignore type: getAccessorTypeFromSize(accessor.size), // @ts-ignore componentType: accessor.componentType, // @ts-ignore count: accessor.count, // @ts-ignore max: accessor.max, // @ts-ignore min: accessor.min }; this.json.accessors = this.json.accessors || []; this.json.accessors.push(glTFAccessor); return this.json.accessors.length - 1; } /** * Add a binary buffer. Builds glTF "JSON metadata" and saves buffer reference * Buffer will be copied into BIN chunk during "pack" * Currently encodes buffers as glTF accessors, but this could be optimized * @param sourceBuffer * @param accessor */ addBinaryBuffer(sourceBuffer, accessor = { size: 3 }) { const bufferViewIndex = this.addBufferView(sourceBuffer); let minMax = { min: accessor.min, max: accessor.max }; if (!minMax.min || !minMax.max) { minMax = this._getAccessorMinMax(sourceBuffer, accessor.size); } const accessorDefaults = { // @ts-ignore size: accessor.size, componentType: getComponentTypeFromArray(sourceBuffer), // @ts-ignore count: Math.round(sourceBuffer.length / accessor.size), min: minMax.min, max: minMax.max }; return this.addAccessor(bufferViewIndex, Object.assign(accessorDefaults, accessor)); } /** * Adds a texture to the json part * @todo: add more properties for texture initialization * `sampler`, `name`, `extensions`, `extras` * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#texture */ addTexture(texture) { const { imageIndex } = texture; const glTFTexture = { source: imageIndex }; this.json.textures = this.json.textures || []; this.json.textures.push(glTFTexture); return this.json.textures.length - 1; } /** Adds a material to the json part */ addMaterial(pbrMaterialInfo) { this.json.materials = this.json.materials || []; this.json.materials.push(pbrMaterialInfo); return this.json.materials.length - 1; } /** Pack the binary chunk */ createBinaryChunk() { var _a, _b; const totalByteLength = this.byteLength; const arrayBuffer = new ArrayBuffer(totalByteLength); const targetArray = new Uint8Array(arrayBuffer); let dstByteOffset = 0; for (const sourceBuffer of this.sourceBuffers || []) { dstByteOffset = (0, import_loader_utils.copyToArray)(sourceBuffer, targetArray, dstByteOffset); } if ((_b = (_a = this.json) == null ? void 0 : _a.buffers) == null ? void 0 : _b[0]) { this.json.buffers[0].byteLength = totalByteLength; } else { this.json.buffers = [{ byteLength: totalByteLength }]; } this.gltf.binary = arrayBuffer; this.sourceBuffers = [arrayBuffer]; this.gltf.buffers = [{ arrayBuffer, byteOffset: 0, byteLength: arrayBuffer.byteLength }]; } // PRIVATE _removeStringFromArray(array, string) { let found = true; while (found) { const index = array.indexOf(string); if (index > -1) { array.splice(index, 1); } else { found = false; } } } /** * Add attributes to buffers and create `attributes` object which is part of `mesh` */ _addAttributes(attributes = {}) { const result = {}; for (const attributeKey in attributes) { const attributeData = attributes[attributeKey]; const attrName = this._getGltfAttributeName(attributeKey); const accessor = this.addBinaryBuffer(attributeData.value, attributeData); result[attrName] = accessor; } return result; } /** * Add indices to buffers */ _addIndices(indices) { return this.addBinaryBuffer(indices, { size: 1 }); } /** * Deduce gltf specific attribue name from input attribute name */ _getGltfAttributeName(attributeName) { switch (attributeName.toLowerCase()) { case "position": case "positions": case "vertices": return "POSITION"; case "normal": case "normals": return "NORMAL"; case "color": case "colors": return "COLOR_0"; case "texcoord": case "texcoords": return "TEXCOORD_0"; default: return attributeName; } } /** * Calculate `min` and `max` arrays of accessor according to spec: * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-accessor */ _getAccessorMinMax(buffer, size) { const result = { min: null, max: null }; if (buffer.length < size) { return result; } result.min = []; result.max = []; const initValues = buffer.subarray(0, size); for (const value of initValues) { result.min.push(value); result.max.push(value); } for (let index = size; index < buffer.length; index += size) { for (let componentIndex = 0; componentIndex < size; componentIndex++) { result.min[0 + componentIndex] = Math.min( // @ts-ignore result.min[0 + componentIndex], buffer[index + componentIndex] ); result.max[0 + componentIndex] = Math.max( // @ts-ignore result.max[0 + componentIndex], buffer[index + componentIndex] ); } } return result; } }; // dist/lib/extensions/utils/3d-tiles-utils.js var import_images2 = require("@loaders.gl/images"); function emod(n) { return (n % 1 + 1) % 1; } var ATTRIBUTE_TYPE_TO_COMPONENTS2 = { SCALAR: 1, VEC2: 2, VEC3: 3, VEC4: 4, MAT2: 4, MAT3: 9, MAT4: 16, BOOLEAN: 1, STRING: 1, ENUM: 1 }; var ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY2 = { INT8: Int8Array, UINT8: Uint8Array, INT16: Int16Array, UINT16: Uint16Array, INT32: Int32Array, UINT32: Uint32Array, INT64: BigInt64Array, UINT64: BigUint64Array, FLOAT32: Float32Array, FLOAT64: Float64Array }; var ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE2 = { INT8: 1, UINT8: 1, INT16: 2, UINT16: 2, INT32: 4, UINT32: 4, INT64: 8, UINT64: 8, FLOAT32: 4, FLOAT64: 8 }; function getArrayElementByteSize(attributeType, componentType) { return ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE2[componentType] * ATTRIBUTE_TYPE_TO_COMPONENTS2[attributeType]; } function getOffsetsForProperty(scenegraph, bufferViewIndex, offsetType, numberOfElements) { if (offsetType !== "UINT8" && offsetType !== "UINT16" && offsetType !== "UINT32" && offsetType !== "UINT64") { return null; } const arrayOffsetsBytes = scenegraph.getTypedArrayForBufferView(bufferViewIndex); const arrayOffsets = convertRawBufferToMetadataArray( arrayOffsetsBytes, "SCALAR", // offsets consist of ONE component offsetType, numberOfElements + 1 // The number of offsets is equal to the property table `count` plus one. ); if (arrayOffsets instanceof BigInt64Array || arrayOffsets instanceof BigUint64Array) { return null; } return arrayOffsets; } function convertRawBufferToMetadataArray(data, attributeType, componentType, elementCount = 1) { const numberOfComponents = ATTRIBUTE_TYPE_TO_COMPONENTS2[attributeType]; const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY2[componentType]; const size = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE2[componentType]; const length = elementCount * numberOfComponents; const byteLength = length * size; let buffer = data.buffer; let offset = data.byteOffset; if (offset % size !== 0) { const bufferArray = new Uint8Array(buffer); buffer = bufferArray.slice(offset, offset + byteLength).buffer; offset = 0; } return new ArrayType(buffer, offset, length); } function getPrimitiveTextureData(scenegraph, textureInfo, primitive) { var _a, _b, _c, _d, _e; const texCoordAccessorKey = `TEXCOORD_${textureInfo.texCoord || 0}`; const texCoordAccessorIndex = primitive.attributes[texCoordAccessorKey]; const textureCoordinates = scenegraph.getTypedArrayForAccessor(texCoordAccessorIndex); const json = scenegraph.gltf.json; const textureIndex = textureInfo.index; const imageIndex = (_b = (_a = json.textures) == null ? void 0 : _a[textureIndex]) == null ? void 0 : _b.source; if (typeof imageIndex !== "undefined") { const mimeType = (_d = (_c = json.images) == null ? void 0 : _c[imageIndex]) == null ? void 0 : _d.mimeType; const parsedImage = (_e = scenegraph.gltf.images) == null ? void 0 : _e[imageIndex]; if (parsedImage && typeof parsedImage.width !== "undefined") { const textureData = []; for (let index = 0; index < textureCoordinates.length; index += 2) { const value = getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index, textureInfo.channels); textureData.push(value); } return textureData; } } return []; } function primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTable, primitive) { if (!(propertyData == null ? void 0 : propertyData.length)) { return; } const featureIndices = []; for (const texelData of propertyData) { let index = featureTable.findIndex((item) => item === texelData); if (index === -1) { index = featureTable.push(texelData) - 1; } featureIndices.push(index); } const typedArray = new Uint32Array(featureIndices); const bufferIndex = scenegraph.gltf.buffers.push({ arrayBuffer: typedArray.buffer, byteOffset: typedArray.byteOffset, byteLength: typedArray.byteLength }) - 1; const bufferViewIndex = scenegraph.addBufferView(typedArray, bufferIndex, 0); const accessorIndex = scenegraph.addAccessor(bufferViewIndex, { size: 1, componentType: getComponentTypeFromArray(typedArray), count: typedArray.length }); primitive.attributes[attributeName] = accessorIndex; } function getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index, channels = [0]) { const CHANNELS_MAP = { r: { offset: 0, shift: 0 }, g: { offset: 1, shift: 8 }, b: { offset: 2, shift: 16 }, a: { offset: 3, shift: 24 } }; const u = textureCoordinates[index]; const v = textureCoordinates[index + 1]; let components = 1; if (mimeType && (mimeType.indexOf("image/jpeg") !== -1 || mimeType.indexOf("image/png") !== -1)) components = 4; const offset = coordinatesToOffset(u, v, parsedImage, components); let value = 0; for (const c of channels) { const map = typeof c === "number" ? Object.values(CHANNELS_MAP)[c] : CHANNELS_MAP[c]; const imageOffset = offset + map.offset; const imageData = (0, import_images2.getImageData)(parsedImage); if (imageData.data.length <= imageOffset) { throw new Error(`${imageData.data.length} <= ${imageOffset}`); } const imageValue = imageData.data[imageOffset]; value |= imageValue << map.shift; } return value; } function coordinatesToOffset(u, v, parsedImage, componentsCount = 1) { const w = parsedImage.width; const iX = emod(u) * (w - 1); const indX = Math.round(iX); const h = parsedImage.height; const iY = emod(v) * (h - 1); const indY = Math.round(iY); const components = parsedImage.components ? parsedImage.components : componentsCount; const offset = (indY * w + indX) * components; return offset; } function parseVariableLengthArrayNumeric(valuesData, numberOfElements, arrayOffsets, valuesDataBytesLength, valueSize) { const attributeValueArray = []; for (let index = 0; index < numberOfElements; index++) { const arrayOffset = arrayOffsets[index]; const arrayByteSize = arrayOffsets[index + 1] - arrayOffsets[index]; if (arrayByteSize + arrayOffset > valuesDataBytesLength) { break; } const typedArrayOffset = arrayOffset / valueSize; const elementCount = arrayByteSize / valueSize; attributeValueArray.push(valuesData.slice(typedArrayOffset, typedArrayOffset + elementCount)); } return attributeValueArray; } function parseFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount) { const attributeValueArray = []; for (let index = 0; index < numberOfElements; index++) { const elementOffset = index * arrayCount; attributeValueArray.push(valuesData.slice(elementOffset, elementOffset + arrayCount)); } return attributeValueArray; } function getPropertyDataString(numberOfElements, valuesDataBytes, arrayOffsets, stringOffsets) { if (arrayOffsets) { throw new Error("Not implemented - arrayOffsets for strings is specified"); } if (stringOffsets) { const stringsArray = []; const textDecoder = new TextDecoder("utf8"); let stringOffset = 0; for (let index = 0; index < numberOfElements; index++) { const stringByteSize = stringOffsets[index + 1] - stringOffsets[index]; if (stringByteSize + stringOffset <= valuesDataBytes.length) { const stringData = valuesDataBytes.subarray(stringOffset, stringByteSize + stringOffset); const stringAttribute = textDecoder.decode(stringData); stringsArray.push(stringAttribute); stringOffset += stringByteSize; } } return stringsArray; } return []; } // dist/lib/extensions/EXT_mesh_features.js var EXT_MESH_FEATURES_NAME = "EXT_mesh_features"; var name = EXT_MESH_FEATURES_NAME; async function decode(gltfData, options) { const scenegraph = new GLTFScenegraph(gltfData); decodeExtMeshFeatures(scenegraph, options); } function encode(gltfData, options) { const scenegraph = new GLTFScenegraph(gltfData); encodeExtMeshFeatures(scenegraph, options); scenegraph.createBinaryChunk(); return scenegraph.gltf; } function decodeExtMeshFeatures(scenegraph, options) { const json = scenegraph.gltf.json; if (!json.meshes) { return; } for (const mesh of json.meshes) { for (const primitive of mesh.primitives) { processMeshPrimitiveFeatures(scenegraph, primitive, options); } } } function processMeshPrimitiveFeatures(scenegraph, primitive, options) { var _a, _b, _c; if (!((_a = options == null ? void 0 : options.gltf) == null ? void 0 : _a.loadBuffers)) { return; } const extension = (_b = primitive.extensions) == null ? void 0 : _b[EXT_MESH_FEATURES_NAME]; const featureIds = extension == null ? void 0 : extension.featureIds; if (!featureIds) { return; } for (const featureId of featureIds) { let featureIdData; if (typeof featureId.attribute !== "undefined") { const accessorKey = `_FEATURE_ID_${featureId.attribute}`; const accessorIndex = primitive.attributes[accessorKey]; featureIdData = scenegraph.getTypedArrayForAccessor(accessorIndex); } else if (typeof featureId.texture !== "undefined" && ((_c = options == null ? void 0 : options.gltf) == null ? void 0 : _c.loadImages)) { featureIdData = getPrimitiveTextureData(scenegraph, featureId.texture, primitive); } else { featureIdData = []; } featureId.data = featureIdData; } } function encodeExtMeshFeatures(scenegraph, options) { const meshes = scenegraph.gltf.json.meshes; if (!meshes) { return; } for (const mesh of meshes) { for (const primitive of mesh.primitives) { encodeExtMeshFeaturesForPrimitive(scenegraph, primitive); } } } function createExtMeshFeatures(scenegraph, primitive, featureIdArray, propertyTableIndex) { if (!primitive.extensions) { primitive.extensions = {}; } let extension = primitive.extensions[EXT_MESH_FEATURES_NAME]; if (!extension) { extension = { featureIds: [] }; primitive.extensions[EXT_MESH_FEATURES_NAME] = extension; } const { featureIds } = extension; const featureId = { featureCount: featureIdArray.length, propertyTable: propertyTableIndex, data: featureIdArray }; featureIds.push(featureId); scenegraph.addObjectExtension(primitive, EXT_MESH_FEATURES_NAME, extension); } function encodeExtMeshFeaturesForPrimitive(scenegraph, primitive) { var _a; const extension = (_a = primitive.extensions) == null ? void 0 : _a[EXT_MESH_FEATURES_NAME]; if (!extension) { return; } const featureIds = extension.featureIds; featureIds.forEach((featureId, elementIndex) => { if (featureId.data) { const { accessorKey, index } = createAccessorKey(primitive.attributes); const typedArray = new Uint32Array(featureId.data); featureIds[elementIndex] = { featureCount: typedArray.length, propertyTable: featureId.propertyTable, attribute: index }; scenegraph.gltf.buffers.push({ arrayBuffer: typedArray.buffer, byteOffset: typedArray.byteOffset, byteLength: typedArray.byteLength }); const bufferViewIndex = scenegraph.addBufferView(typedArray); const accessorIndex = scenegraph.addAccessor(bufferViewIndex, { size: 1, componentType: getComponentTypeFromArray(typedArray), count: typedArray.length }); primitive.attributes[accessorKey] = accessorIndex; } }); } function createAccessorKey(attributes) { const prefix = "_FEATURE_ID_"; const attrs = Object.keys(attributes).filter((item) => item.indexOf(prefix) === 0); let max = -1; for (const a of attrs) { const n = Number(a.substring(prefix.length)); if (n > max) { max = n; } } max++; const accessorKey = `${prefix}${max}`; return { accessorKey, index: max }; } // dist/lib/extensions/EXT_structural_metadata.js var EXT_structural_metadata_exports = {}; __export(EXT_structural_metadata_exports, { createExtStructuralMetadata: () => createExtStructuralMetadata, decode: () => decode2, encode: () => encode2, name: () => name2 }); var EXT_STRUCTURAL_METADATA_NAME = "EXT_structural_metadata"; var name2 = EXT_STRUCTURAL_METADATA_NAME; async function decode2(gltfData, options) { const scenegraph = new GLTFScenegraph(gltfData); decodeExtStructuralMetadata(scenegraph, options); } function encode2(gltfData, options) { const scenegraph = new GLTFScenegraph(gltfData); encodeExtStructuralMetadata(scenegraph, options); scenegraph.createBinaryChunk(); return scenegraph.gltf; } function decodeExtStructuralMetadata(scenegraph, options) { var _a, _b; if (!((_a = options.gltf) == null ? void 0 : _a.loadBuffers)) { return; } const extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME); if (!extension) { return; } if ((_b = options.gltf) == null ? void 0 : _b.loadImages) { decodePropertyTextures(scenegraph, extension); } decodePropertyTables(scenegraph, extension); } function decodePropertyTextures(scenegraph, extension) { const propertyTextures = extension.propertyTextures; const json = scenegraph.gltf.json; if (propertyTextures && json.meshes) { for (const mesh of json.meshes) { for (const primitive of mesh.primitives) { processPrimitivePropertyTextures(scenegraph, propertyTextures, primitive, extension); } } } } function decodePropertyTables(scenegraph, extension) { const schema = extension.schema; if (!schema) { return; } const schemaClasses = schema.classes; const propertyTables = extension.propertyTables; if (schemaClasses && propertyTables) { for (const schemaName in schemaClasses) { const propertyTable = findPropertyTableByClass(propertyTables, schemaName); if (propertyTable) { processPropertyTable(scenegraph, schema, propertyTable); } } } } function findPropertyTableByClass(propertyTables, schemaClassName) { for (const propertyTable of propertyTables) { if (propertyTable.class === schemaClassName) { return propertyTable; } } return null; } function processPrimitivePropertyTextures(scenegraph, propertyTextures, primitive, extension) { var _a; if (!propertyTextures) { return; } const primitiveExtension = (_a = primitive.extensions) == null ? void 0 : _a[EXT_STRUCTURAL_METADATA_NAME]; const primitivePropertyTextureIndices = primitiveExtension == null ? void 0 : primitiveExtension.propertyTextures; if (!primitivePropertyTextureIndices) { return; } for (const primitivePropertyTextureIndex of primitivePropertyTextureIndices) { const propertyTexture = propertyTextures[primitivePropertyTextureIndex]; processPrimitivePropertyTexture(scenegraph, propertyTexture, primitive, extension); } } function processPrimitivePropertyTexture(scenegraph, propertyTexture, primitive, extension) { var _a; if (!propertyTexture.properties) { return; } if (!extension.dataAttributeNames) { extension.dataAttributeNames = []; } const className = propertyTexture.class; for (const propertyName in propertyTexture.properties) { const attributeName = `${className}_${propertyName}`; const textureInfoTopLevel = (_a = propertyTexture.properties) == null ? void 0 : _a[propertyName]; if (!textureInfoTopLevel) { continue; } if (!textureInfoTopLevel.data) { textureInfoTopLevel.data = []; } const featureTextureTable = textureInfoTopLevel.data; const propertyData = getPrimitiveTextureData(scenegraph, textureInfoTopLevel, primitive); if (propertyData === null) { continue; } primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTextureTable, primitive); textureInfoTopLevel.data = featureTextureTable; extension.dataAttributeNames.push(attributeName); } } function processPropertyTable(scenegraph, schema, propertyTable) { var _a, _b; const schemaClass = (_a = schema.classes) == null ? void 0 : _a[propertyTable.class]; if (!schemaClass) { throw new Error(`Incorrect data in the EXT_structural_metadata extension: no schema class with name ${propertyTable.class}`); } const numberOfElements = propertyTable.count; for (const propertyName in schemaClass.properties) { const classProperty = schemaClass.properties[propertyName]; const propertyTableProperty = (_b = propertyTable.properties) == null ? void 0 : _b[propertyName]; if (propertyTableProperty) { const data = getPropertyDataFromBinarySource(scenegraph, schema, classProperty, numberOfElements, propertyTableProperty); propertyTableProperty.data = data; } } } function getPropertyDataFromBinarySource(scenegraph, schema, classProperty, numberOfElements, propertyTableProperty) { let data = []; const valuesBufferView = propertyTableProperty.values; const valuesDataBytes = scenegraph.getTypedArrayForBufferView(valuesBufferView); const arrayOffsets = getArrayOffsetsForProperty(scenegraph, classProperty, propertyTableProperty, numberOfElements); const stringOffsets = getStringOffsetsForProperty(scenegraph, propertyTableProperty, numberOfElements); switch (classProperty.type) { case "SCALAR": case "VEC2": case "VEC3": case "VEC4": case "MAT2": case "MAT3": case "MAT4": { data = getPropertyDataNumeric(classProperty, numberOfElements, valuesDataBytes, arrayOffsets); break; } case "BOOLEAN": { throw new Error(`Not implemented - classProperty.type=${classProperty.type}`); } case "STRING": { data = getPropertyDataString(numberOfElements, valuesDataBytes, arrayOffsets, stringOffsets); break; } case "ENUM": { data = getPropertyDataENUM(schema, classProperty, numberOfElements, valuesDataBytes, arrayOffsets); break; } default: throw new Error(`Unknown classProperty type ${classProperty.type}`); } return data; } function getArrayOffsetsForProperty(scenegraph, classProperty, propertyTableProperty, numberOfElements) { if (classProperty.array && // `count` is a number of array elements. May only be defined when `array` is true. // If `count` is NOT defined, it's a VARIABLE-length array typeof classProperty.count === "undefined" && // `arrayOffsets` is an index of the buffer view containing offsets for variable-length arrays. typeof propertyTableProperty.arrayOffsets !== "undefined") { return getOffsetsForProperty(scenegraph, propertyTableProperty.arrayOffsets, propertyTableProperty.arrayOffsetType || "UINT32", numberOfElements); } return null; } function getStringOffsetsForProperty(scenegraph, propertyTableProperty, numberOfElements) { if (typeof propertyTableProperty.stringOffsets !== "undefined") { return getOffsetsForProperty(scenegraph, propertyTableProperty.stringOffsets, propertyTableProperty.stringOffsetType || "UINT32", numberOfElements); } return null; } function getPropertyDataNumeric(classProperty, numberOfElements, valuesDataBytes, arrayOffsets) { const isArray = classProperty.array; const arrayCount = classProperty.count; const elementSize = getArrayElementByteSize(classProperty.type, classProperty.componentType); const elementCount = valuesDataBytes.byteLength / elementSize; let valuesData; if (classProperty.componentType) { valuesData = convertRawBufferToMetadataArray( valuesDataBytes, classProperty.type, // The datatype of the element's components. Only applicable to `SCALAR`, `VECN`, and `MATN` types. classProperty.componentType, elementCount ); } else { valuesData = valuesDataBytes; } if (isArray) { if (arrayOffsets) { return parseVariableLengthArrayNumeric(valuesData, numberOfElements, arrayOffsets, valuesDataBytes.length, elementSize); } if (arrayCount) { return parseFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount); } return []; } return valuesData; } function getPropertyDataENUM(schema, classProperty, numberOfElements, valuesDataBytes, arrayOffsets) { var _a; const enumType = classProperty.enumType; if (!enumType) { throw new Error("Incorrect data in the EXT_structural_metadata extension: classProperty.enumType is not set for type ENUM"); } const enumEntry = (_a = schema.enums) == null ? void 0 : _a[enumType]; if (!enumEntry) { throw new Error(`Incorrect data in the EXT_structural_metadata extension: schema.enums does't contain ${enumType}`); } const enumValueType = enumEntry.valueType || "UINT16"; const elementSize = getArrayElementByteSize(classProperty.type, enumValueType); const elementCount = valuesDataBytes.byteLength / elementSize; let valuesData = convertRawBufferToMetadataArray(valuesDataBytes, classProperty.type, enumValueType, elementCount); if (!valuesData) { valuesData = valuesDataBytes; } if (classProperty.array) { if (arrayOffsets) { return parseVariableLengthArrayENUM({ valuesData, numberOfElements, arrayOffsets, valuesDataBytesLength: valuesDataBytes.length, elementSize, enumEntry }); } const arrayCount = classProperty.count; if (arrayCount) { return parseFixedLengthArrayENUM(valuesData, numberOfElements, arrayCount, enumEntry); } return []; } return getEnumsArray(valuesData, 0, numberOfElements, enumEntry); } function parseVariableLengthArrayENUM(params) { const { valuesData, numberOfElements, arrayOffsets, valuesDataBytesLength, elementSize, enumEntry } = params; const attributeValueArray = []; for (let index = 0; index < numberOfElements; index++) { const arrayOffset = arrayOffsets[index]; const arrayByteSize = arrayOffsets[index + 1] - arrayOffsets[index]; if (arrayByteSize + arrayOffset > valuesDataBytesLength) { break; } const typedArrayOffset = arrayOffset / elementSize; const elementCount = arrayByteSize / elementSize; const array = getEnumsArray(valuesData, typedArrayOffset, elementCount, enumEntry); attributeValueArray.push(array); } return attributeValueArray; } function parseFixedLengthArrayENUM(valuesData, numberOfElements, arrayCount, enumEntry) { const attributeValueArray = []; for (let index = 0; index < numberOfElements; index++) { const elementOffset = arrayCount * index; const array = getEnumsArray(valuesData, elementOffset, arrayCount, enumEntry); attributeValueArray.push(array); } return attributeValueArray; } function getEnumsArray(valuesData, offset, count, enumEntry) { const array = []; for (let i = 0; i < count; i++) { if (valuesData instanceof BigInt64Array || valuesData instanceof BigUint64Array) { array.push(""); } else { const value = valuesData[offset + i]; const enumObject = getEnumByValue(enumEntry, value); if (enumObject) { array.push(enumObject.name); } else { array.push(""); } } } return array; } function getEnumByValue(enumEntry, value) { for (const enumValue of enumEntry.values) { if (enumValue.value === value) { return enumValue; } } return null; } var SCHEMA_CLASS_ID_DEFAULT = "schemaClassId"; function encodeExtStructuralMetadata(scenegraph, options) { var _a, _b; const extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME); if (!extension) { return; } if (extension.propertyTables) { for (const table of extension.propertyTables) { const classId = table.class; const schemaClass = (_b = (_a = extension.schema) == null ? void 0 : _a.classes) == null ? void 0 : _b[classId]; if (table.properties && schemaClass) { encodeProperties(table, schemaClass, scenegraph); } } } } function encodeProperties(table, schemaClass, scenegraph) { for (const propertyName in table.properties) { const data = table.properties[propertyName].data; if (data) { const classProperty = schemaClass.properties[propertyName]; if (classProperty) { const tableProperty = createPropertyTableProperty(data, classProperty, scenegraph); table.properties[propertyName] = tableProperty; } } } } function createExtStructuralMetadata(scenegraph, propertyAttributes, classId = SCHEMA_CLASS_ID_DEFAULT) { let extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME); if (!extension) { extension = scenegraph.addExtension(EXT_STRUCTURAL_METADATA_NAME); } extension.schema = createSchema(propertyAttributes, classId, extension.schema); const table = createPropertyTable(propertyAttributes, classId, extension.schema); if (!extension.propertyTables) { extension.propertyTables = []; } return extension.propertyTables.push(table) - 1; } function createSchema(propertyAttributes, classId, schemaToUpdate) { const schema = schemaToUpdate ?? { id: "schema_id" }; const schemaClass = { properties: {} }; for (const attribute of propertyAttributes) { const classProperty = { type: attribute.elementType, componentType: attribute.componentType }; schemaClass.properties[attribute.name] = classProperty; } schema.classes = {}; schema.classes[classId] = schemaClass; return schema; } function createPropertyTable(propertyAttributes, classId, schema) { var _a; const table = { class: classId, count: 0 }; let count = 0; const schemaClass = (_a = schema.classes) == null ? void 0 : _a[classId]; for (const attribute of propertyAttributes) { if (count === 0) { count = attribute.values.length; } if (count !== attribute.values.length && attribute.values.length) { throw new Error("Illegal values in attributes"); } const classProperty = schemaClass == null ? void 0 : schemaClass.properties[attribute.name]; if (classProperty) { if (!table.properties) { table.properties = {}; } table.properties[attribute.name] = { values: 0, data: attribute.values }; } } table.count = count; return table; } function createPropertyTableProperty(values, classProperty, scenegraph) { const prop = { values: 0 }; if (classProperty.type === "STRING") { const { stringData, stringOffsets } = createPropertyDataString(values); prop.stringOffsets = createBufferView(stringOffsets, scenegraph); prop.values = createBufferView(stringData, scenegraph); } else if (classProperty.type === "SCALAR" && classProperty.componentType) { const data = createPropertyDataScalar(values, classProperty.componentType); prop.values = createBufferView(data, scenegraph); } return prop; } var COMPONENT_TYPE_TO_ARRAY_CONSTRUCTOR = { INT8: Int8Array, UINT8: Uint8Array, INT16: Int16Array, UINT16: Uint16Array, INT32: Int32Array, UINT32: Uint32Array, INT64: Int32Array, UINT64: Uint32Array, FLOAT32: Float32Array, FLOAT64: Float64Array }; function createPropertyDataScalar(array, componentType) { const numberArray = []; for (const value of array) { numberArray.push(Number(value)); } const Construct = COMPONENT_TYPE_TO_ARRAY_CONSTRUCTOR[componentType]; if (!Construct) { throw new Error("Illegal component type"); } return new Construct(numberArray); } function createPropertyDataString(strings) { const utf8Encode = new TextEncoder(); const arr = []; let len = 0; for (const str of strings) { const uint8Array = utf8Encode.encode(str); len += uint8Array.length; arr.push(uint8Array); } const strArray = new Uint8Array(len); const strOffsets = []; let offset = 0; for (const str of arr) { strArray.set(str, offset); strOffsets.push(offset); offset += str.length; } strOffsets.push(offset); const stringOffsetsTypedArray = new Uint32Array(strOffsets); return { stringData: strArray, stringOffsets: stringOffsetsTypedArray }; } function createBufferView(typedArray, scenegraph) { scenegraph.gltf.buffers.push({ arrayBuffer: typedArray.buffer, byteOffset: typedArray.byteOffset, byteLength: typedArray.byteLength }); return scenegraph.addBufferView(typedArray); } // dist/lib/extensions/deprecated/EXT_feature_metadata.js var EXT_feature_metadata_exports = {}; __export(EXT_feature_metadata_exports, { decode: () => decode3, name: () => name3 }); var EXT_FEATURE_METADATA_NAME = "EXT_feature_metadata"; var name3 = EXT_FEATURE_METADATA_NAME; async function decode3(gltfData, options) { const scenegraph = new GLTFScenegraph(gltfData); decodeExtFeatureMetadata(scenegraph, options); } function decodeExtFeatureMetadata(scenegraph, options) { var _a, _b; if (!((_a = options.gltf) == null ? void 0 : _a.loadBuffers)) { return; } const extension = scenegraph.getExtension(EXT_FEATURE_METADATA_NAME); if (!extension) { return; } if ((_b = options.gltf) == null ? void 0 : _b.loadImages) { decodePropertyTextures2(scenegraph, extension); } decodePropertyTables2(scenegraph, extension); } function decodePropertyTextures2(scenegraph, extension) { const schema = extension.schema; if (!schema) { return; } const schemaClasses = schema.classes; const { featureTextures } = extension; if (schemaClasses && featureTextures) { for (const schemaName in schemaClasses) { const schemaClass = schemaClasses[schemaName]; const featureTexture = findFeatureTextureByClass(featureTextures, schemaName); if (featureTexture) { handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass); } } } } function decodePropertyTables2(scenegraph, extension) { const schema = extension.schema; if (!schema) { return; } const schemaClasses = schema.classes; const propertyTables = extension.featureTables; if (schemaClasses && propertyTables) { for (const schemaName in schemaClasses) { const propertyTable = findPropertyTableByClass2(propertyTables, schemaName); if (propertyTable) { processPropertyTable2(scenegraph, schema, propertyTable); } } } } function findPropertyTableByClass2(propertyTables, schemaClassName) { for (const propertyTableName in propertyTables) { const propertyTable = propertyTables[propertyTableName]; if (propertyTable.class === schemaClassName) { return propertyTable; } } return null; } function findFeatureTextureByClass(featureTextures, schemaClassName) { for (const featureTexturesName in featureTextures) { const featureTable = featureTextures[featureTexturesName]; if (featureTable.class === schemaClassName) { return featureTable; } } return null; } function processPropertyTable2(scenegraph, schema, propertyTable) { var _a, _b; if (!propertyTable.class) { return; } const schemaClass = (_a = schema.classes) == null ? void 0 : _a[propertyTable.class]; if (!schemaClass) { throw new Error(`Incorrect data in the EXT_structural_metadata extension: no schema class with name ${propertyTable.class}`); } const numberOfElements = propertyTable.count; for (const propertyName in schemaClass.properties) { const classProperty = schemaClass.properties[propertyName]; const propertyTableProperty = (_b = propertyTable.properties) == null ? void 0 : _b[propertyName]; if (propertyTableProperty) { const data = getPropertyDataFromBinarySource2(scenegraph, schema, classProperty, numberOfElements, propertyTableProperty); propertyTableProperty.data = data; } } } function handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass) { var _a; const attributeName = featureTexture.class; for (const propertyName in schemaClass.properties) { const featureTextureProperty = (_a = featureTexture == null ? void 0 : featureTexture.properties) == null ? void 0 : _a[propertyName]; if (featureTextureProperty) { const data = getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName); featureTextureProperty.data = data; } } } function getPropertyDataFromBinarySource2(scenegraph, schema, classProperty, numberOfFeatures, featureTableProperty) { let data = []; const bufferView = featureTableProperty.bufferView; const dataArray = scenegraph.getTypedArrayForBufferView(bufferView); const arrayOffsets = getArrayOffsetsForProperty2(scenegraph, classProperty, featureTableProperty, numberOfFeatures); const stringOffsets = getStringOffsetsForProperty2(scenegraph, classProperty, featureTableProperty, numberOfFeatures); if (classProperty.type === "STRING" || classProperty.componentType === "STRING") { data = getPropertyDataString(numberOfFeatures, dataArray, arrayOffsets, stringOffsets); } else if (isNumericProperty(classProperty)) { data = getPropertyDataNumeric2(classProperty, numberOfFeatures, dataArray, arrayOffsets); } return data; } function getArrayOffsetsForProperty2(scenegraph, classProperty, propertyTableProperty, numberOfElements) { if (classProperty.type === "ARRAY" && // `componentCount` is a number of fixed-length array elements. // If `componentCount` is NOT defined, it's a VARIABLE-length array typeof classProperty.componentCount === "undefined" && // `arrayOffsetBufferView` is an index of the buffer view containing offsets for variable-length arrays. typeof propertyTableProperty.arrayOffsetBufferView !== "undefined") { return getOffsetsForProperty( scenegraph, propertyTableProperty.arrayOffsetBufferView, propertyTableProperty.offsetType || "UINT32", // offsetType is used both for stringOffsetBufferView and arrayOffsetBufferView numberOfElements ); } return null; } function getStringOffsetsForProperty2(scenegraph, classProperty, propertyTableProperty, numberOfElements) { if (typeof propertyTableProperty.stringOffsetBufferView !== "undefined") { return getOffsetsForProperty( scenegraph, propertyTableProperty.stringOffsetBufferView, propertyTableProperty.offsetType || "UINT32", // offsetType is used both for stringOffsetBufferView and arrayOffsetBufferView numberOfElements ); } return null; } function isNumericProperty(schemaProperty) { const types = [ "UINT8", "INT16", "UINT16", "INT32", "UINT32", "INT64", "UINT64", "FLOAT32", "FLOAT64" ]; return types.includes(schemaProperty.type) || typeof schemaProperty.componentType !== "undefined" && types.includes(schemaProperty.componentType); } function getPropertyDataNumeric2(classProperty, numberOfElements, valuesDataBytes, arrayOffsets) { const isArray = classProperty.type === "ARRAY"; const arrayCount = classProperty.componentCount; const attributeType = "SCALAR"; const componentType = classProperty.componentType || classProperty.type; const elementSize = getArrayElementByteSize(attributeType, componentType); const elementCount = valuesDataBytes.byteLength / elementSize; const valuesData = convertRawBufferToMetadataArray(valuesDataBytes, attributeType, componentType, elementCount); if (isArray) { if (arrayOffsets) { return parseVariableLengthArrayNumeric(valuesData, numberOfElements, arrayOffsets, valuesDataBytes.length, elementSize); } if (arrayCount) { return parseFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount); } return []; } return valuesData; } function getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName) { const json = scenegraph.gltf.json; if (!json.meshes) { return []; } const featureTextureTable = []; for (const mesh of json.meshes) { for (const primitive of mesh.primitives) { processPrimitiveTextures(scenegraph, attributeName, featureTextureProperty, featureTextureTable, primitive); } } return featureTextureTable; } function processPrimitiveTextures(scenegraph, attributeName, featureTextureProperty, featureTextureTable, primitive) { const textureInfoTopLevel = { channels: featureTextureProperty.channels, ...featureTextureProperty.texture }; const propertyData = getPrimitiveTextureData(scenegraph, textureInfoTopLevel, primitive); if (!propertyData) { return; } primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTextureTable, primitive); } // dist/lib/utils/version.js var VERSION = true ? "4.3.1" : "latest"; // dist/lib/parsers/parse-gltf.js var import_loader_utils4 = require("@loaders.gl/loader-utils"); var import_images4 = require("@loaders.gl/images"); var import_textures = require("@loaders.gl/textures"); // dist/lib/parsers/parse-glb.js var import_loader_utils2 = require("@loaders.gl/loader-utils"); var LITTLE_ENDIAN = true; var MAGIC_glTF = 1735152710; var GLB_FILE_HEADER_SIZE = 12; var GLB_CHUNK_HEADER_SIZE = 8; var GLB_CHUNK_TYPE_JSON = 1313821514; var GLB_CHUNK_TYPE_BIN = 5130562; var GLB_V1_CONTENT_FORMAT_JSON = 0; var GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED = 0; var GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED = 1; function getMagicString(dataView, byteOffset = 0) { return `${String.fromCharCode(dataView.getUint8(byteOffset + 0))}${String.fromCharCode(dataView.getUint8(byteOffset + 1))}${String.fromCharCode(dataView.getUint8(byteOffset + 2))}${String.fromCharCode(dataView.getUint8(byteOffset + 3))}`; } function isGLB(arrayBuffer, byteOffset = 0, options = {}) { const dataView = new DataView(arrayBuffer); const { magic = MAGIC_glTF } = options; const magic1 = dataView.getUint32(byteOffset, false); return magic1 === magic || magic1 === MAGIC_glTF; } function parseGLBSync(glb, arrayBuffer, byteOffset = 0, options = {}) { const dataView = new DataView(arrayBuffer); const type = getMagicString(dataView, byteOffset + 0); const version = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN); const byteLength = dataView.getUint32(byteOffset + 8, LITTLE_ENDIAN); Object.assign(glb, { // Put less important stuff in a header, to avoid clutter header: { byteOffset, // Byte offset into the initial arrayBuffer byteLength, hasBinChunk: false }, type, version, json: {}, binChunks: [] }); byteOffset += GLB_FILE_HEADER_SIZE; switch (glb.version) { case 1: return parseGLBV1(glb, dataView, byteOffset); case 2: return parseGLBV2(glb, dataView, byteOffset, options = {}); default: throw new Error(`Invalid GLB version ${glb.version}. Only supports version 1 and 2.`); } } function parseGLBV1(glb, dataView, byteOffset) { (0, import_loader_utils2.assert)(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE); const contentLength = dataView.getUint32(byteOffset + 0, LITTLE_ENDIAN); const contentFormat = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN); byteOffset += GLB_CHUNK_HEADER_SIZE; (0, import_loader_utils2.assert)(contentFormat === GLB_V1_CONTENT_FORMAT_JSON); parseJSONChunk(glb, dataView, byteOffset, contentLength); byteOffset += contentLength; byteOffset += parseBINChunk(glb, dataView, byteOffset, glb.header.byteLength); return byteOffset; } function parseGLBV2(glb, dataView, byteOffset, options) { (0, import_loader_utils2.assert)(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE); parseGLBChunksSync(glb, dataView, byteOffset, options); return byteOffset + glb.header.byteLength; } function parseGLBChunksSync(glb, dataView, byteOffset, options) { while (byteOffset + 8 <= glb.header.byteLength) { const chunkLength = dataView.getUint32(byteOffset + 0, LITTLE_ENDIAN); const chunkFormat = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN); byteOffset += GLB_CHUNK_HEADER_SIZE; switch (chunkFormat) { case GLB_CHUNK_TYPE_JSON: parseJSONChunk(glb, dataView, byteOffset, chunkLength); break; case GLB_CHUNK_TYPE_BIN: parseBINChunk(glb, dataView, byteOffset, chunkLength); break; case GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED: if (!options.strict) { parseJSONChunk(glb, dataView, byteOffset, chunkLength); } break; case GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED: if (!options.strict) { parseBINChunk(glb, dataView, byteOffset, chunkLength); } break; default: break; } byteOffset += (0, import_loader_utils2.padToNBytes)(chunkLength, 4); } return byteOffset; } function parseJSONChunk(glb, dataView, byteOffset, chunkLength) { const jsonChunk = new Uint8Array(dataView.buffer, byteOffset, chunkLength); const textDecoder = new TextDecoder("utf8"); const jsonText = textDecoder.decode(jsonChunk); glb.json = JSON.parse(jsonText); return (0, import_loader_utils2.padToNBytes)(chunkLength, 4); } function parseBINChunk(glb, dataView, byteOffset, chunkLength) { glb.header.hasBinChunk = true; glb.binChunks.push({ byteOffset, byteLength: chunkLength, arrayBuffer: dataView.buffer // TODO - copy, or create typed array view? }); return (0, import_loader_utils2.padToNBytes)(chunkLength, 4); } // dist/lib/gltf-utils/resolve-url.js function resolveUrl(url, options) { const absolute = url.startsWith("data:") || url.startsWith("http:") || url.startsWith("https:"); if (absolute) { return url; } const baseUrl = options.baseUri || options.uri; if (!baseUrl) { throw new Error(`'baseUri' must be provided to resolve relative url ${url}`); } return baseUrl.substr(0, baseUrl.lastIndexOf("/") + 1) + url; } // dist/lib/extensions/EXT_meshopt_compression.js var EXT_meshopt_compression_exports = {}; __export(EXT_meshopt_compression_exports, { decode: () => decode5, name: () => name4 }); // dist/meshopt/meshopt-decoder.js var wasm_base = "B9h9z9tFBBBF8fL9gBB9gLaaaaaFa9gEaaaB9gFaFa9gEaaaFaEMcBFFFGGGEIIILF9wFFFLEFBFKNFaFCx/IFMO/LFVK9tv9t9vq95GBt9f9f939h9z9t9f9j9h9s9s9f9jW9vq9zBBp9tv9z9o9v9wW9f9kv9j9v9kv9WvqWv94h919m9mvqBF8Z9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv94h919m9mvqBGy9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv949TvZ91v9u9jvBEn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9P9jWBIi9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9R919hWBLn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9F949wBKI9z9iqlBOc+x8ycGBM/qQFTa8jUUUUBCU/EBlHL8kUUUUBC9+RKGXAGCFJAI9LQBCaRKAE2BBC+gF9HQBALAEAIJHOAGlAGTkUUUBRNCUoBAG9uC/wgBZHKCUGAKCUG9JyRVAECFJRICBRcGXEXAcAF9PQFAVAFAclAcAVJAF9JyRMGXGXAG9FQBAMCbJHKC9wZRSAKCIrCEJCGrRQANCUGJRfCBRbAIRTEXGXAOATlAQ9PQBCBRISEMATAQJRIGXAS9FQBCBRtCBREEXGXAOAIlCi9PQBCBRISLMANCU/CBJAEJRKGXGXGXGXGXATAECKrJ2BBAtCKZrCEZfIBFGEBMAKhB83EBAKCNJhB83EBSEMAKAI2BIAI2BBHmCKrHYAYCE6HYy86BBAKCFJAICIJAYJHY2BBAmCIrCEZHPAPCE6HPy86BBAKCGJAYAPJHY2BBAmCGrCEZHPAPCE6HPy86BBAKCEJAYAPJHY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FMAFREMAEMMMFBCUNMIT9tBB"; var detector = new Uint8Array([ 0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 3, 2, 0, 0, 5, 3, 1, 0, 1, 12, 1, 0, 10, 22, 2, 12, 0, 65, 0, 65, 0, 65, 0, 252, 10, 0, 0, 11, 7, 0, 65, 0, 253, 15, 26, 11 ]); var wasmpack = new Uint8Array([ 32, 0, 65, 253, 3, 1, 2, 34, 4, 106, 6, 5, 11, 8, 7, 20, 13, 33, 12, 16, 128, 9, 116, 64, 19, 113, 127, 15, 10, 21, 22, 14, 255, 66, 24, 54, 136, 107, 18, 23, 192, 26, 114, 118, 132, 17, 77, 101, 130, 144, 27, 87, 131, 44, 45, 74, 156, 154, 70, 167 ]); var FILTERS = { // legacy index-based enums for glTF 0: "", 1: "meshopt_decodeFilterOct", 2: "meshopt_decodeFilterQuat", 3: "meshopt_decodeFilterExp", // string-based enums for glTF NONE: "", OCTAHEDRAL: "meshopt_decodeFilterOct", QUATERNION: "meshopt_decodeFilterQuat", EXPONENTIAL: "meshopt_decodeFilterExp" }; var DECODERS = { // legacy index-based enums for glTF 0: "meshopt_decodeVertexBuffer", 1: "meshopt_decodeIndexBuffer", 2: "meshopt_decodeIndexSequence", // string-based enums for glTF ATTRIBUTES: "meshopt_decodeVertexBuffer", TRIANGLES: "meshopt_decodeIndexBuffer", INDICES: "meshopt_decodeIndexSequence" }; async function meshoptDecodeGltfBuffer(target, count, size, source, mode, filter = "NONE") { const instance = await loadWasmInstance(); decode4(instance, instance.exports[DECODERS[mode]], target, count, size, source, instance.exports[FILTERS[filter || "NONE"]]); } var wasmPromise; async function loadWasmInstance() { if (!wasmPromise) { wasmPromise = loadWasmModule(); } return wasmPromise; } async function loadWasmModule() { let wasm = wasm_base; if (WebAssembly.validate(detector)) { wasm = wasm_simd; console.log("Warning: meshopt_decoder is using experimental SIMD support"); } const result = await WebAssembly.instantiate(unpack(wasm), {}); await result.instance.exports.__wasm_call_ctors(); return result.instance; } function unpack(data) { const result = new Uint8Array(data.length); for (let i = 0; i < data.length; ++i) { const ch = data.charCodeAt(i); result[i] = ch > 96 ? ch - 71 : ch > 64 ? ch - 65 : ch > 47 ? ch + 4 : ch > 46 ? 63 : 62; } let write = 0; for (let i = 0; i < data.length; ++i) { result[write++] = result[i] < 60 ? wasmpack[result[i]] : (result[i] - 60) * 64 + result[++i]; } return result.buffer.slice(0, write); } function decode4(instance, fun, target, count, size, source, filter) { const sbrk = instance.exports.sbrk; const count4 = count + 3 & ~3; const tp = sbrk(count4 * size); const sp = sbrk(source.length); const heap = new Uint8Array(instance.exports.memory.buffer); heap.set(source, sp); const res = fun(tp, count, size, sp, source.length); if (res === 0 && filter) { filter(tp, count4, size); } target.set(heap.subarray(tp, tp + count * size)); sbrk(tp - sbrk(0)); if (res !== 0) { throw new Error(`Malformed buffer data: ${res}`); } } // dist/lib/extensions/EXT_meshopt_compression.js var EXT_MESHOPT_COMPRESSION = "EXT_meshopt_compression"; var name4 = EXT_MESHOPT_COMPRESSION; async function decode5(gltfData, options) { var _a, _b; const scenegraph = new GLTFScenegraph(gltfData); if (!((_a = options == null ? void 0 : options.gltf) == null ? void 0 : _a.decompressMeshes) || !((_b = options.gltf) == null ? void 0 : _b.loadBuffers)) { return; } const promises = []; for (const bufferViewIndex of gltfData.json.bufferViews || []) { promises.push(decodeMeshoptBufferView(scenegraph, bufferViewIndex)); } await Promise.all(promises); scenegraph.removeExtension(EXT_MESHOPT_COMPRESSION); } async function decodeMeshoptBufferView(scenegraph, bufferView) { const meshoptExtension = scenegraph.getObjectExtension(bufferView, EXT_MESHOPT_COMPRESSION); if (meshoptExtension) { const { byteOffset = 0, byteLength = 0, byteStride, count, mode, filter = "NONE", buffer: bufferIndex } = meshoptExtension; const buffer = scenegraph.gltf.buffers[bufferIndex]; const source = new Uint8Array(buffer.arrayBuffer, buffer.byteOffset + byteOffset, byteLength); const result = new Uint8Array(scenegraph.gltf.buffers[bufferView.buffer].arrayBuffer, bufferView.byteOffset, bufferView.byteLength); await meshoptDecodeGltfBuffer(result, count, byteStride, source, mode, filter); scenegraph.removeObjectExtension(bufferView, EXT_MESHOPT_COMPRESSION); } } // dist/lib/extensions/EXT_texture_webp.js var EXT_texture_webp_exports = {}; __export(EXT_texture_webp_exports, { name: () => name5, preprocess: () => preprocess }); var import_images3 = require("@loaders.gl/images"); var EXT_TEXTURE_WEBP = "EXT_texture_webp"; var name5 = EXT_TEXTURE_WEBP; function preprocess(gltfData, options) { const scenegraph = new GLTFScenegraph(gltfData); if (!(0, import_images3.isImageFormatSupported)("image/webp")) { if (scenegraph.getRequiredExtensions().includes(EXT_TEXTURE_WEBP)) { throw new Error(`gltf: Required extension ${EXT_TEXTURE_WEBP} not supported by browser`); } return; } const { json } = scenegraph; for (const texture of json.textures || []) { const extension = scenegraph.getObjectExtension(texture, EXT_TEXTURE_WEBP); if (extension) { texture.source = extension.source; } scenegraph.removeObjectExtension(texture, EXT_TEXTURE_WEBP); } scenegraph.removeExtension(EXT_TEXTURE_WEBP); } // dist/lib/extensions/KHR_texture_basisu.js var KHR_texture_basisu_exports = {}; __export(KHR_texture_basisu_exports, { name: () => name6, preprocess: () => preprocess2 }); var KHR_TEXTURE_BASISU = "KHR_texture_basisu"; var name6 = KHR_TEXTURE_BASISU; function preprocess2(gltfData, options) { const scene = new GLTFScenegraph(gltfData); const { json } = scene; for (const texture of json.textures || []) { const extension = scene.getObjectExtension(texture, KHR_TEXTURE_BASISU); if (extension) { texture.source = extension.source; scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU); } } scene.removeExtension(KHR_TEXTURE_BASISU); } // dist/lib/extensions/KHR_draco_mesh_compression.js var KHR_draco_mesh_compression_exports = {}; __export(KHR_draco_mesh_compression_exports, { decode: () => decode6, encode: () => encode3, name: () => name7, preprocess: () => preprocess3 }); var import_loader_utils3 = require("@loaders.gl/loader-utils"); var import_draco = require("@loaders.gl/draco"); // dist/lib/gltf-utils/gltf-attribute-utils.js function getGLTFAccessors(attributes) { const accessors = {}; for (const name12 in attributes) { const attribute = attributes[name12]; if (name12 !== "indices") { const glTFAccessor = getGLTFAccessor(attribute); accessors[name12] = glTFAccessor; } } return accessors; } function getGLTFAccessor(attribute) { const { buffer, size, count } = getAccessorData(attribute); const glTFAccessor = { // glTF Accessor values // TODO: Instead of a bufferView index we could have an actual buffer (typed array) // bufferView: null, // TODO: Deprecate `value` in favor of bufferView? // @ts-ignore value: buffer, size, // Decoded `type` (e.g. SCALAR) byteOffset: 0, count, type: getAccessorTypeFromSize(size), componentType: getComponentTypeFromArray(buffer) }; return glTFAccessor; } function getAccessorData(attribute) { let buffer = attribute; let size = 1; let count = 0; if (attribute && attribute.value) { buffer = attribute.value; size = attribute.size || 1; } if (buffer) { if (!ArrayBuffer.isView(buffer)) { buffer = toTypedArray(buffer, Float32Array); } count = buffer.length / size; } return { buffer, size, count }; } function toTypedArray(array, ArrayType, convertTypedArrays = false) { if (!array) { return null; } if (Array.isArray(array)) { return new ArrayType(array); } if (convertTypedArrays && !(array instanceof ArrayType)) { return new ArrayType(array); } return array; } // dist/lib/extensions/KHR_draco_mesh_compression.js var KHR_DRACO_MESH_COMPRESSION = "KHR_draco_mesh_compression"; var name7 = KHR_DRACO_MESH_COMPRESSION; function preprocess3(gltfData, options, context) { const scenegraph = new GLTFScenegraph(gltfData); for (const primitive of makeMeshPrimitiveIterator(scenegraph)) { if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) { } } } async function decode6(gltfData, options, context) { var _a; if (!((_a = options == null ? void 0 : options.gltf) == null ? void 0 : _a.decompressMeshes)) { return; } const scenegraph = new GLTFScenegraph(gltfData); const promises = []; for (const primitive of makeMeshPrimitiveIterator(scenegraph)) { if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) { promises.push(decompressPrimitive(scenegraph, primitive, options, context)); } } await Promise.all(promises); scenegraph.removeExtension(KHR_DRACO_MESH_COMPRESSION); } function encode3(gltfData, options = {}) { const scenegraph = new GLTFScenegraph(gltfData); for (const mesh of scenegraph.json.meshes || []) { compressMesh(mesh, options); scenegraph.addRequiredExtension(KHR_DRACO_MESH_COMPRESSION); } } async function decompressPrimitive(scenegraph, primitive, options, context) { const dracoExtension = scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION); if (!dracoExtension) { return; } const buffer = scenegraph.getTypedArrayForBufferView(dracoExtension.bufferView); const bufferCopy = (0, import_loader_utils3.sliceArrayBuffer)(buffer.buffer, buffer.byteOffset); const dracoOptions = { ...options }; delete dracoOptions["3d-tiles"]; const decodedData = await (0, import_loader_utils3.parseFromContext)(bufferCopy, import_draco.DracoLoader, dracoOptions, context); const decodedAttributes = getGLTFAccessors(decodedData.attributes); for (const [attributeName, decodedAttribute] of Object.entries(decodedAttributes)) { if (attributeName in primitive.attributes) { const accessorIndex = primitive.attributes[attributeName]; const accessor = scenegraph.getAccessor(accessorIndex); if ((accessor == null ? void 0 : accessor.min) && (accessor == null ? void 0 : accessor.max)) { decodedAttribute.min = accessor.min; decodedAttribute.max = accessor.max; } } } primitive.attributes = decodedAttributes; if (decodedData.indices) { primitive.indices = getGLTFAccessor(decodedData.indices); } scenegraph.removeObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION); checkPrimitive(primitive); } function compressMesh(attributes, indices, mode = 4, options, context) { var _a; if (!options.DracoWriter) { throw new Error("options.gltf.DracoWriter not provided"); } const compressedData = options.DracoWriter.encodeSync({ attributes }); const decodedData = (_a = context == null ? void 0 : context.parseSync) == null ? void 0 : _a.call(context, { attributes }); const fauxAccessors = options._addFauxAttributes(decodedData.attributes); const bufferViewIndex = options.addBufferView(compressedData); const glTFMesh = { primitives: [ { attributes: fauxAccessors, // TODO - verify with spec mode, // GL.POINTS extensions: { [KHR_DRACO_MESH_COMPRESSION]: { bufferView: bufferViewIndex, attributes: fauxAccessors // TODO - verify with spec } } } ] }; return glTFMesh; } function checkPrimitive(primitive) { if (!primitive.attributes && Object.keys(primitive.attributes).length > 0) { throw new Error("glTF: Empty primitive detected: Draco decompression failure?"); } } function* makeMeshPrimitiveIterator(scenegraph) { for (const mesh of scenegraph.json.meshes || []) { for (const primitive of mesh.primitives) { yield primitive; } } } // dist/lib/extensions/KHR_texture_transform.js var KHR_texture_transform_exports = {}; __export(KHR_texture_transform_exports, { decode: () => decode7, name: () => name8 }); var import_core = require("@math.gl/core"); var KHR_TEXTURE_TRANSFORM = "KHR_texture_transform"; var name8 = KHR_TEXTURE_TRANSFORM; var scratchVector = new import_core.Vector3(); var scratchRotationMatrix = new import_core.Matrix3(); var scratchScaleMatrix = new import_core.Matrix3(); async function decode7(gltfData, options) { var _a; const gltfScenegraph = new GLTFScenegraph(gltfData); const hasExtension = gltfScenegraph.hasExtension(KHR_TEXTURE_TRANSFORM); if (!hasExtension || !((_a = options.gltf) == null ? void 0 : _a.loadBuffers)) { return; } const materials = gltfData.json.materials || []; for (let i = 0; i < materials.length; i++) { transformTexCoords(i, gltfData); } } function transformTexCoords(materialIndex, gltfData) { var _a, _b, _c, _d; const material = (_a = gltfData.json.materials) == null ? void 0 : _a[materialIndex]; const materialTextures = [ (_b = material == null ? void 0 : material.pbrMetallicRoughness) == null ? void 0 : _b.baseColorTexture, material == null ? void 0 : material.emissiveTexture, material == null ? void 0 : material.normalTexture, material == null ? void 0 : material.occlusionTexture, (_c = material == null ? void 0 : material.pbrMetallicRoughness) == null ? void 0 : _c.metallicRoughnessTexture ]; const processedTexCoords = []; for (const textureInfo of materialTextures) { if (textureInfo && ((_d = textureInfo == null ? void 0 : textureInfo.extensions) == null ? void 0 : _d[KHR_TEXTURE_TRANSFORM])) { transformPrimitives(gltfData, materialIndex, textureInfo, processedTexCoords); } } } function transformPrimitives(gltfData, materialIndex, texture, processedTexCoords) { const transformParameters = getTransformParameters(texture, processedTexCoords); if (!transformParameters) { return; } const meshes = gltfData.json.meshes || []; for (const mesh of meshes) { for (const primitive of mesh.primitives) { const material = primitive.material; if (Number.isFinite(material) && materialIndex === material) { transformPrimitive(gltfData, primitive, transformParameters); } } } } function getTransformParameters(texture, processedTexCoords) { var _a; const textureInfo = (_a = texture.extensions) == null ? void 0 : _a[KHR_TEXTURE_TRANSFORM]; const { texCoord: originalTexCoord = 0 } = texture; const { texCoord = originalTexCoord } = textureInfo; const isProcessed = processedTexCoords.findIndex(([original, newTexCoord]) => original === originalTexCoord && newTexCoord === texCoord) !== -1; if (!isProcessed) { const matrix = makeTransformationMatrix(textureInfo); if (originalTexCoord !== texCoord) { texture.texCoord = texCoord; } processedTexCoords.push([originalTexCoord, texCoord]); return { originalTexCoord, texCoord, matrix }; } return null; } function transformPrimitive(gltfData, primitive, transformParameters) { var _a, _b; const { originalTexCoord, texCoord, matrix } = transformParameters; const texCoordAccessor = primitive.attributes[`TEXCOORD_${originalTexCoord}`]; if (Number.isFinite(texCoordAccessor)) { const accessor = (_a = gltfData.json.accessors) == null ? void 0 : _a[texCoordAccessor]; if (accessor && accessor.bufferView) { const bufferView = (_b = gltfData.json.bufferViews) == null ? void 0 : _b[accessor.bufferView]; if (bufferView) { const { arrayBuffer, byteOffset: bufferByteOffset } = gltfData.buffers[bufferView.buffer]; const byteOffset = (bufferByteOffset || 0) + (accessor.byteOffset || 0) + (bufferView.byteOffset || 0); const { ArrayType, length } = getAccessorArrayTypeAndLength(accessor, bufferView); const bytes = BYTES[accessor.componentType]; const components = COMPONENTS[accessor.type]; const elementAddressScale = bufferView.byteStride || bytes * components; const result = new Float32Array(length); for (let i = 0; i < accessor.count; i++) { const uv = new ArrayType(arrayBuffer, byteOffset + i * elementAddressScale, 2); scratchVector.set(uv[0], uv[1], 1); scratchVector.transformByMatrix3(matrix); result.set([scratchVector[0], scratchVector[1]], i * components); } if (originalTexCoord === texCoord) { updateGltf(accessor, bufferView, gltfData.buffers, result); } else { createAttribute(texCoord, accessor, primitive, gltfData, result); } } } } } function updateGltf(accessor, bufferView, buffers, newTexCoordArray) { accessor.componentType = 5126; buffers.push({ arrayBuffer: newTexCoordArray.buffer, byteOffset: 0, byteLength: newTexCoordArray.buffer.byteLength }); bufferView.buffer = buffers.length - 1; bufferView.byteLength = newTexCoordArray.buffer.byteLength; bufferView.byteOffset = 0; delete bufferView.byteStride; } function createAttribute(newTexCoord, originalAccessor, primitive, gltfData, newTexCoordArray) { gltfData.buffers.push({ arrayBuffer: newTexCoordArray.buffer, byteOffset: 0, byteLength: newTexCoordArray.buffer.byteLength }); const bufferViews = gltfData.json.bufferViews; if (!bufferViews) { return; } bufferViews.push({ buffer: gltfData.buffers.length - 1, byteLength: newTexCoordArray.buffer.byteLength, byteOffset: 0 }); const accessors = gltfData.json.accessors; if (!accessors) { return; } accessors.push({ bufferView: (bufferViews == null ? void 0 : bufferViews.length) - 1, byteOffset: 0, componentType: 5126, count: originalAccessor.count, type: "VEC2" }); primitive.attributes[`TEXCOORD_${newTexCoord}`] = accessors.length - 1; } function makeTransformationMatrix(extensionData) { const { offset = [0, 0], rotation = 0, scale = [1, 1] } = extensionData; const translationMatrix = new import_core.Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1); const rotationMatrix = scratchRotationMatrix.set(Math.cos(rotation), Math.sin(rotation), 0, -Math.sin(rotation), Math.cos(rotation), 0, 0, 0, 1); const scaleMatrix = scratchScaleMatrix.set(scale[0], 0, 0, 0, scale[1], 0, 0, 0, 1); return translationMatrix.multiplyRight(rotationMatrix).multiplyRight(scaleMatrix); } // dist/lib/extensions/deprecated/KHR_lights_punctual.js var KHR_lights_punctual_exports = {}; __export(KHR_lights_punctual_exports, { decode: () => decode8, encode: () => encode4, name: () => name9 }); var KHR_LIGHTS_PUNCTUAL = "KHR_lights_punctual"; var name9 = KHR_LIGHTS_PUNCTUAL; async function decode8(gltfData) { const gltfScenegraph = new GLTFScenegraph(gltfData); const { json } = gltfScenegraph; const extension = gltfScenegraph.getExtension(KHR_LIGHTS_PUNCTUAL); if (extension) { gltfScenegraph.json.lights = extension.lights; gltfScenegraph.removeExtension(KHR_LIGHTS_PUNCTUAL); } for (const node of json.nodes || []) { const nodeExtension = gltfScenegraph.getObjectExtension(node, KHR_LIGHTS_PUNCTUAL); if (nodeExtension) { node.light = nodeExtension.light; } gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL); } } async function encode4(gltfData) { const gltfScenegraph = new GLTFScenegraph(gltfData); const { json } = gltfScenegraph; if (json.lights) { const extension = gltfScenegraph.addExtension(KHR_LIGHTS_PUNCTUAL); assert(!extension.lights); extension.lights = json.lights; delete json.lights; } if (gltfScenegraph.json.lights) { for (const light of gltfScenegraph.json.lights) { const node = light.node; gltfScenegraph.addObjectExtension(node, KHR_LIGHTS_PUNCTUAL, light); } delete gltfScenegraph.json.lights; } } // dist/lib/extensions/deprecated/KHR_materials_unlit.js var KHR_materials_unlit_exports = {}; __export(KHR_materials_unlit_exports, { decode: () => decode9, encode: () => encode5, name: () => name10 }); var KHR_MATERIALS_UNLIT = "KHR_materials_unlit"; var name10 = KHR_MATERIALS_UNLIT; async function decode9(gltfData) { const gltfScenegraph = new GLTFScenegraph(gltfData); const { json } = gltfScenegraph; for (const material of json.materials || []) { const extension = material.extensions && material.extensions.KHR_materials_unlit; if (extension) { material.unlit = true; } gltfScenegraph.removeObjectExtension(material, KHR_MATERIALS_UNLIT); } gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT); } function encode5(gltfData) { const gltfScenegraph = new GLTFScenegraph(gltfData); const { json } = gltfScenegraph; if (gltfScenegraph.materials) { for (const material of json.materials || []) { if (material.unlit) { delete material.unlit; gltfScenegraph.addObjectExtension(material, KHR_MATERIALS_UNLIT, {}); gltfScenegraph.addExtension(KHR_MATERIALS_UNLIT); } } } } // dist/lib/extensions/deprecated/KHR_techniques_webgl.js var KHR_techniques_webgl_exports = {}; __export(KHR_techniques_webgl_exports, { decode: () => decode10, encode: () => encode6, name: () => name11 }); var KHR_TECHNIQUES_WEBGL = "KHR_techniques_webgl"; var name11 = KHR_TECHNIQUES_WEBGL; async function decode10(gltfData) { const gltfScenegraph = new GLTFScenegraph(gltfData); const { json } = gltfScenegraph; const extension = gltfScenegraph.getExtension(KHR_TECHNIQUES_WEBGL); if (extension) { const techniques = resolveTechniques(extension, gltfScenegraph); for (const material of json.materials || []) { const materialExtension = gltfScenegraph.getObjectExtension(material, KHR_TECHNIQUES_WEBGL); if (materialExtension) { material.technique = Object.assign( {}, materialExtension, // @ts-ignore techniques[materialExtension.technique] ); material.technique.values = resolveValues(material.technique, gltfScenegraph); } gltfScenegraph.removeObjectExtension(material, KHR_TECHNIQUES_WEBGL); } gltfScenegraph.removeExtension(KHR_TECHNIQUES_WEBGL); } } async function encode6(gltfData, options) { } function resolveTechniques(techniquesExtension, gltfScenegraph) { const { programs = [], shaders = [], techniques = [] } = techniquesExtension; const textDecoder = new TextDecoder(); shaders.forEach((shader) => { if (Number.isFinite(shader.bufferView)) { shader.code = textDecoder.decode(gltfScenegraph.getTypedArrayForBufferView(shader.bufferView)); } else { throw new Error("KHR_techniques_webgl: no shader code"); } }); programs.forEach((program) => { program.fragmentShader = shaders[program.fragmentShader]; program.vertexShader = shaders[program.vertexShader]; }); techniques.forEach((technique) => { technique.program = programs[technique.program]; }); return techniques; } function resolveValues(technique, gltfScenegraph) { const values = Object.assign({}, technique.values); Object.keys(technique.uniforms || {}).forEach((uniform) => { if (technique.uniforms[uniform].value && !(uniform in values)) { values[uniform] = technique.uniforms[uniform].value; } }); Object.keys(values).forEach((uniform) => { if (typeof values[uniform] === "object" && values[uniform].index !== void 0) { values[uniform].texture = gltfScenegraph.getTexture(values[uniform].index); } }); return values; } // dist/lib/api/gltf-extensions.js var EXTENSIONS = [ // 1.0 // KHR_binary_gltf is handled separately - must be processed before other parsing starts // KHR_binary_gltf, // 2.0 EXT_structural_metadata_exports, EXT_mesh_features_exports, EXT_meshopt_compression_exports, EXT_texture_webp_exports, // Basisu should come after webp, we want basisu to be preferred if both are provided KHR_texture_basisu_exports, KHR_draco_mesh_compression_exports, KHR_lights_punctual_exports, KHR_materials_unlit_exports, KHR_techniques_webgl_exports, KHR_texture_transform_exports, EXT_feature_metadata_exports ]; var EXTENSIONS_ENCODING = [EXT_structural_metadata_exports, EXT_mesh_features_exports]; function preprocessExtensions(gltf, options = {}, context) { var _a; const extensions = EXTENSIONS.filter((extension) => useExtension(extension.name, options)); for (const extension of extensions) { (_a = extension.preprocess) == null ? void 0 : _a.call(extension, gltf, options, context); } } async function decodeExtensions(gltf, options = {}, context) { var _a; const extensions = EXTENSIONS.filter((extension) => useExtension(extension.name, options)); for (const extension of extensions) { await ((_a = extension.decode) == null ? void 0 : _a.call(extension, gltf, options, context)); } } function encodeExtensions(gltf, options = {}) { var _a; for (const extension of EXTENSIONS_ENCODING) { gltf = ((_a = extension.encode) == null ? void 0 : _a.call(extension, gltf, options)) ?? gltf; } return gltf; } function useExtension(extensionName, options) { var _a; const excludes = ((_a = options == null ? void 0 : options.gltf) == null ? void 0 : _a.excludeExtensions) || {}; const exclude = extensionName in excludes && !excludes[extensionName]; return !exclude; } // dist/lib/extensions/KHR_binary_gltf.js var KHR_BINARY_GLTF = "KHR_binary_glTF"; function preprocess4(gltfData) { const gltfScenegraph = new GLTFScenegraph(gltfData); const { json } = gltfScenegraph; for (const image of json.images || []) { const extension = gltfScenegraph.getObjectExtension(image, KHR_BINARY_GLTF); if (extension) { Object.assign(image, extension); } gltfScenegraph.removeObjectExtension(image, KHR_BINARY_GLTF); } if (json.buffers && json.buffers[0]) { delete json.buffers[0].uri; } gltfScenegraph.removeExtension(KHR_BINARY_GLTF); } // dist/lib/api/normalize-gltf-v1.js var GLTF_ARRAYS = { accessors: "accessor", animations: "animation", buffers: "buffer", bufferViews: "bufferView", images: "image", materials: "material", meshes: "mesh", nodes: "node", samplers: "sampler", scenes: "scene", skins: "skin", textures: "texture" }; var GLTF_KEYS = { accessor: "accessors", animations: "animation", buffer: "buffers", bufferView: "bufferViews", image: "images", material: "materials", mesh: "meshes", node: "nodes", sampler: "samplers", scene: "scenes", skin: "skins", texture: "textures" }; var GLTFV1Normalizer = class { idToIndexMap = { animations: {}, accessors: {}, buffers: {}, bufferViews: {}, images: {}, materials: {}, meshes: {}, nodes: {}, samplers: {}, scenes: {}, skins: {}, textures: {} }; json; // constructor() {} /** * Convert (normalize) glTF < 2.0 to glTF 2.0 * @param gltf - object with json and binChunks * @param options * @param options normalize Whether to actually normalize */ normalize(gltf, options) { this.json = gltf.json; const json = gltf.json; switch (json.asset && json.asset.version) { case "2.0": return; case void 0: case "1.0": break; default: console.warn(`glTF: Unknown version ${json.asset.version}`); return; } if (!options.normalize) { throw new Error("glTF v1 is not supported."); } console.warn("Converting glTF v1 to glTF v2 format. This is experimental and may fail."); this._addAsset(json); this._convertTopLevelObjectsToArrays(json); preprocess4(gltf); this._convertObjectIdsToArrayIndices(json); this._updateObjects(json); this._updateMaterial(json); } // asset is now required, #642 https://github.com/KhronosGroup/glTF/issues/639 _addAsset(json) { json.asset = json.asset || {}; json.asset.version = "2.0"; json.asset.generator = json.asset.generator || "Normalized to glTF 2.0 by loaders.gl"; } _convertTopLevelObjectsToArrays(json) { for (const arrayName in GLTF_ARRAYS) { this._convertTopLevelObjectToArray(json, arrayName); } } /** Convert one top level object to array */ _convertTopLevelObjectToArray(json, mapName) { const objectMap = json[mapName]; if (!objectMap || Array.isArray(objectMap)) { return; } json[mapName] = []; for (const id in objectMap) { const object = objectMap[id]; object.id = object.id || id; const index = json[mapName].length; json[mapName].push(object); this.idToIndexMap[mapName][id] = index; } } /** Go through all objects in all top-level arrays and replace ids with indices */ _convertObjectIdsToArrayIndices(json) { for (const arrayName in GLTF_ARRAYS) { this._convertIdsToIndices(json, arrayName); } if ("scene" in json) { json.scene = this._convertIdToIndex(json.scene, "scene"); } for (const texture of json.textures) { this._convertTextureIds(texture); } for (const mesh of json.meshes) { this._convertMeshIds(mesh); } for (const node of json.nodes) { this._convertNodeIds(node); } for (const node of json.scenes) { this._convertSceneIds(node); } } _convertTextureIds(texture) { if (texture.source) { texture.source = this._convertIdToIndex(texture.source, "image"); } } _convertMeshIds(mesh) { for (const primitive of mesh.primitives) { const { attributes, indices, material } = primitive; for (const attributeName in attributes) { attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], "accessor"); } if (indices) { primitive.indices = this._convertIdToIndex(indices, "accessor"); } if (material) { primitive.material = this._convertIdToIndex(material, "material"); } } } _convertNodeIds(node) { if (node.children) { node.children = node.children.map((child) => this._convertIdToIndex(child, "node")); } if (node.meshes) { node.meshes = node.meshes.map((mesh) => this._convertIdToIndex(mesh, "mesh")); } } _convertSceneIds(scene) { if (scene.nodes) { scene.nodes = scene.nodes.map((node) => this._convertIdToIndex(node, "node")); } } /** Go through all objects in a top-level array and replace ids with indices */ _convertIdsToIndices(json, topLevelArrayName) { if (!json[topLevelArrayName]) { console.warn(`gltf v1: json doesn't contain attribute ${topLevelArrayName}`); json[topLevelArrayName] = []; } for (const object of json[topLevelArrayName]) { for (const key in object) { const id = object[key]; const index = this._convertIdToIndex(id, key); object[key] = index; } } } _convertIdToIndex(id, key) { const arrayName = GLTF_KEYS[key]; if (arrayName in this.idToIndexMap) { const index = this.idToIndexMap[arrayName][id]; if (!Number.isFinite(index)) { throw new Error(`gltf v1: failed to resolve ${key} with id ${id}`); } return index; } return id; } /** * * @param {*} json */ _updateObjects(json) { for (const buffer of this.json.buffers) { delete buffer.type; } } /** * Update material (set pbrMetallicRoughness) * @param {*} json */ _updateMaterial(json) { var _a, _b, _c; for (const material of json.materials) { material.pbrMetallicRoughness = { baseColorFactor: [1, 1, 1, 1], metallicFactor: 1, roughnessFactor: 1 }; const textureId = ((_a = material.values) == null ? void 0 : _a.tex) || ((_b = material.values) == null ? void 0 : _b.texture2d_0) || ((_c = material.values) == null ? void 0 : _c.diffuseTex); const textureIndex = json.textures.findIndex((texture) => texture.id === textureId); if (textureIndex !== -1) { material.pbrMetallicRoughness.baseColorTexture = { index: textureIndex }; } } } }; function normalizeGLTFV1(gltf, options = {}) { return new GLTFV1Normalizer().normalize(gltf, options); } // dist/lib/parsers/parse-gltf.js async function parseGLTF(gltf, arrayBufferOrString, byteOffset = 0, options, context) { var _a, _b, _c; parseGLTFContainerSync(gltf, arrayBufferOrString, byteOffset, options); normalizeGLTFV1(gltf, { normalize: (_a = options == null ? void 0 : options.gltf) == null ? void 0 : _a.normalize }); preprocessExtensions(gltf, options, context); if (((_b = options == null ? void 0 : options.gltf) == null ? void 0 : _b.loadBuffers) && gltf.json.buffers) { await loadBuffers(gltf, options, context); } if ((_c = options == null ? void 0 : options.gltf) == null ? void 0 : _c.loadImages) { await loadImages(gltf, options, context); } await decodeExtensions(gltf, options, context); return gltf; } function parseGLTFContainerSync(gltf, data, byteOffset, options) { if (options.uri) { gltf.baseUri = options.uri; } if (data instanceof ArrayBuffer && !isGLB(data, byteOffset, options)) { const textDecoder = new TextDecoder(); data = textDecoder.decode(data); } if (typeof data === "string") { gltf.json = (0, import_loader_utils4.parseJSON)(data); } else if (data instanceof ArrayBuffer) { const glb = {}; byteOffset = parseGLBSync(glb, data, byteOffset, options.glb); assert(glb.type === "glTF", `Invalid GLB magic string ${glb.type}`); gltf._glb = glb; gltf.json = glb.json; } else { assert(false, "GLTF: must be ArrayBuffer or string"); } const buffers = gltf.json.buffers || []; gltf.buffers = new Array(buffers.length).fill(null); if (gltf._glb && gltf._glb.header.hasBinChunk) { const { binChunks } = gltf._glb; gltf.buffers[0] = { arrayBuffer: binChunks[0].arrayBuffer, byteOffset: binChunks[0].byteOffset, byteLength: binChunks[0].byteLength }; } const images = gltf.json.images || []; gltf.images = new Array(images.length).fill({}); } async function loadBuffers(gltf, options, context) { var _a, _b; const buffers = gltf.json.buffers || []; for (let i = 0; i < buffers.length; ++i) { const buffer = buffers[i]; if (buffer.uri) { const { fetch } = context; assert(fetch); const uri = resolveUrl(buffer.uri, options); const response = await ((_a = context == null ? void 0 : context.fetch) == null ? void 0 : _a.call(context, uri)); const arrayBuffer = await ((_b = response == null ? void 0 : response.arrayBuffer) == null ? void 0 : _b.call(response)); gltf.buffers[i] = { arrayBuffer, byteOffset: 0, byteLength: arrayBuffer.byteLength }; delete buffer.uri; } else if (gltf.buffers[i] === null) { gltf.buffers[i] = { arrayBuffer: new ArrayBuffer(buffer.byteLength), byteOffset: 0, byteLength: buffer.byteLength }; } } } async function loadImages(gltf, options, context) { const imageIndices = getReferencesImageIndices(gltf); const images = gltf.json.images || []; const promises = []; for (const imageIndex of imageIndices) { promises.push(loadImage(gltf, images[imageIndex], imageIndex, options, context)); } return await Promise.all(promises); } function getReferencesImageIndices(gltf) { const imageIndices = /* @__PURE__ */ new Set(); const textures = gltf.json.textures || []; for (const texture of textures) { if (texture.source !== void 0) { imageIndices.add(texture.source); } } return Array.from(imageIndices).sort(); } async function loadImage(gltf, image, index, options, context) { let arrayBuffer; if (image.uri && !image.hasOwnProperty("bufferView")) { const uri = resolveUrl(image.uri, options); const { fetch } = context; const response = await fetch(uri); arrayBuffer = await response.arrayBuffer(); image.bufferView = { data: arrayBuffer }; } if (Number.isFinite(image.bufferView)) { const array = getTypedArrayForBufferView(gltf.json, gltf.buffers, image.bufferView); arrayBuffer = (0, import_loader_utils4.sliceArrayBuffer)(array.buffer, array.byteOffset, array.byteLength); } assert(arrayBuffer, "glTF image has no data"); let parsedImage = await (0, import_loader_utils4.parseFromContext)(arrayBuffer, [import_images4.ImageLoader, import_textures.BasisLoader], { ...options, mimeType: image.mimeType, basis: options.basis || { format: (0, import_textures.selectSupportedBasisFormat)() } }, context); if (parsedImage && parsedImage[0]) { parsedImage = { compressed: true, // @ts-expect-error mipmaps: false, width: parsedImage[0].width, height: parsedImage[0].height, data: parsedImage[0] }; } gltf.images = gltf.images || []; gltf.images[index] = parsedImage; } // dist/gltf-loader.js var GLTFLoader = { dataType: null, batchType: null, name: "glTF", id: "gltf", module: "gltf", version: VERSION, extensions: ["gltf", "glb"], mimeTypes: ["model/gltf+json", "model/gltf-binary"], text: true, binary: true, tests: ["glTF"], parse, options: { gltf: { normalize: true, // Normalize glTF v1 to glTF v2 format (not yet stable) loadBuffers: true, // Fetch any linked .BIN buffers, decode base64 loadImages: true, // Create image objects decompressMeshes: true // Decompress Draco encoded meshes }, // common? log: console // eslint-disable-line } }; async function parse(arrayBuffer, options = {}, context) { options = { ...GLTFLoader.options, ...options }; options.gltf = { ...GLTFLoader.options.gltf, ...options.gltf }; const { byteOffset = 0 } = options; const gltf = {}; return await parseGLTF(gltf, arrayBuffer, byteOffset, options, context); } // dist/lib/encoders/encode-glb.js var import_loader_utils5 = require("@loaders.gl/loader-utils"); var MAGIC_glTF2 = 1179937895; var MAGIC_JSON = 1313821514; var MAGIC_BIN = 5130562; var LE = true; function encodeGLBSync(glb, dataView, byteOffset = 0, options = {}) { const { magic = MAGIC_glTF2, version = 2, json = {}, binary } = glb; const byteOffsetStart = byteOffset; if (dataView) { dataView.setUint32(byteOffset + 0, magic, LE); dataView.setUint32(byteOffset + 4, version, LE); dataView.setUint32(byteOffset + 8, 0, LE); } const byteOffsetFileLength = byteOffset + 8; byteOffset += 12; const byteOffsetJsonHeader = byteOffset; if (dataView) { dataView.setUint32(byteOffset + 0, 0, LE); dataView.setUint32(byteOffset + 4, MAGIC_JSON, LE); } byteOffset += 8; const jsonString = JSON.stringify(json); byteOffset = (0, import_loader_utils5.copyPaddedStringToDataView)(dataView, byteOffset, jsonString, 4); if (dataView) { const jsonByteLength = byteOffset - byteOffsetJsonHeader - 8; dataView.setUint32(byteOffsetJsonHeader + 0, jsonByteLength, LE); } if (binary) { const byteOffsetBinHeader = byteOffset; if (dataView) { dataView.setUint32(byteOffset + 0, 0, LE); dataView.setUint32(byteOffset + 4, MAGIC_BIN, LE); } byteOffset += 8; byteOffset = (0, import_loader_utils5.copyPaddedArrayBufferToDataView)(dataView, byteOffset, binary, 4); if (dataView) { const binByteLength = byteOffset - byteOffsetBinHeader - 8; dataView.setUint32(byteOffsetBinHeader + 0, binByteLength, LE); } } if (dataView) { const fileByteLength = byteOffset - byteOffsetStart; dataView.setUint32(byteOffsetFileLength, fileByteLength, LE); } return byteOffset; } // dist/lib/encoders/encode-gltf.js function encodeGLTFSync(gltf, arrayBuffer, byteOffset, options) { validateGltf(gltf); return encodeGLBSync(gltf, arrayBuffer, byteOffset, options); } function validateGltf(gltf) { if (gltf.buffers && gltf.buffers.length > 1) { throw new Error("encodeGLTF: multiple buffers not yet implemented"); } } // dist/gltf-writer.js var GLTFWriter = { dataType: null, batchType: null, name: "glTF", id: "gltf", module: "gltf", version: VERSION, extensions: ["glb"], // We only support encoding to binary GLB, not to JSON GLTF mimeTypes: ["model/gltf-binary"], // 'model/gltf+json', binary: true, options: { gltf: {} }, encode: async (gltf, options = {}) => encodeSync(gltf, options), encodeSync }; function encodeSync(gltf, options = {}) { const { byteOffset = 0 } = options; const gltfToEncode = encodeExtensions(gltf); const byteLength = encodeGLTFSync(gltfToEncode, null, byteOffset, options); const arrayBuffer = new ArrayBuffer(byteLength); const dataView = new DataView(arrayBuffer); encodeGLTFSync(gltfToEncode, dataView, byteOffset, options); return arrayBuffer; } // dist/glb-loader.js var GLBLoader = { dataType: null, batchType: null, name: "GLB", id: "glb", module: "gltf", version: VERSION, extensions: ["glb"], mimeTypes: ["model/gltf-binary"], binary: true, parse: parse2, parseSync, options: { glb: { strict: false // Enables deprecated XVIZ support (illegal CHUNK formats) } } }; async function parse2(arrayBuffer, options) { return parseSync(arrayBuffer, options); } function parseSync(arrayBuffer, options) { const { byteOffset = 0 } = options || {}; const glb = {}; parseGLBSync(glb, arrayBuffer, byteOffset, options == null ? void 0 : options.glb); return glb; } // dist/glb-writer.js var GLBWriter = { name: "GLB", id: "glb", module: "gltf", version: VERSION, extensions: ["glb"], mimeTypes: ["model/gltf-binary"], binary: true, options: { glb: {} }, encode: async (glb, options = {}) => encodeSync2(glb, options), encodeSync: encodeSync2 }; function encodeSync2(glb, options) { const { byteOffset = 0 } = options ?? {}; const byteLength = encodeGLBSync(glb, null, byteOffset, options); const arrayBuffer = new ArrayBuffer(byteLength); const dataView = new DataView(arrayBuffer); encodeGLBSync(glb, dataView, byteOffset, options); return arrayBuffer; } // dist/lib/api/post-process-gltf.js var COMPONENTS2 = { SCALAR: 1, VEC2: 2, VEC3: 3, VEC4: 4, MAT2: 4, MAT3: 9, MAT4: 16 }; var BYTES2 = { 5120: 1, // BYTE 5121: 1, // UNSIGNED_BYTE 5122: 2, // SHORT 5123: 2, // UNSIGNED_SHORT 5125: 4, // UNSIGNED_INT 5126: 4 // FLOAT }; var GL_SAMPLER = { // Sampler parameters TEXTURE_MAG_FILTER: 10240, TEXTURE_MIN_FILTER: 10241, TEXTURE_WRAP_S: 10242, TEXTURE_WRAP_T: 10243, // Sampler default values REPEAT: 10497, LINEAR: 9729, NEAREST_MIPMAP_LINEAR: 9986 }; var SAMPLER_PARAMETER_GLTF_TO_GL = { magFilter: GL_SAMPLER.TEXTURE_MAG_FILTER, minFilter: GL_SAMPLER.TEXTURE_MIN_FILTER, wrapS: GL_SAMPLER.TEXTURE_WRAP_S, wrapT: GL_SAMPLER.TEXTURE_WRAP_T }; var DEFAULT_SAMPLER_PARAMETERS = { [GL_SAMPLER.TEXTURE_MAG_FILTER]: GL_SAMPLER.LINEAR, [GL_SAMPLER.TEXTURE_MIN_FILTER]: GL_SAMPLER.NEAREST_MIPMAP_LINEAR, [GL_SAMPLER.TEXTURE_WRAP_S]: GL_SAMPLER.REPEAT, [GL_SAMPLER.TEXTURE_WRAP_T]: GL_SAMPLER.REPEAT }; function makeDefaultSampler() { return { id: "default-sampler", parameters: DEFAULT_SAMPLER_PARAMETERS }; } function getBytesFromComponentType(componentType) { return BYTES2[componentType]; } function getSizeFromAccessorType(type) { return COMPONENTS2[type]; } var GLTFPostProcessor = class { baseUri = ""; // @ts-expect-error jsonUnprocessed; // @ts-expect-error json; buffers = []; images = []; postProcess(gltf, options = {}) { const { json, buffers = [], images = [] } = gltf; const { baseUri = "" } = gltf; assert(json); this.baseUri = baseUri; this.buffers = buffers; this.images = images; this.jsonUnprocessed = json; this.json = this._resolveTree(gltf.json, options); return this.json; } // Convert indexed glTF structure into tree structure // cross-link index resolution, enum lookup, convenience calculations // eslint-disable-next-line complexity, max-statements _resolveTree(gltf, options = {}) { const json = { ...gltf }; this.json = json; if (gltf.bufferViews) { json.bufferViews = gltf.bufferViews.map((bufView, i) => this._resolveBufferView(bufView, i)); } if (gltf.images) { json.images = gltf.images.map((image, i) => this._resolveImage(image, i)); } if (gltf.samplers) { json.samplers = gltf.samplers.map((sampler, i) => this._resolveSampler(sampler, i)); } if (gltf.textures) { json.textures = gltf.textures.map((texture, i) => this._resolveTexture(texture, i)); } if (gltf.accessors) { json.accessors = gltf.accessors.map((accessor, i) => this._resolveAccessor(accessor, i)); } if (gltf.materials) { json.materials = gltf.materials.map((material, i) => this._resolveMaterial(material, i)); } if (gltf.meshes) { json.meshes = gltf.meshes.map((mesh, i) => this._resolveMesh(mesh, i)); } if (gltf.nodes) { json.nodes = gltf.nodes.map((node, i) => this._resolveNode(node, i)); json.nodes = json.nodes.map((node, i) => this._resolveNodeChildren(node)); } if (gltf.skins) { json.skins = gltf.skins.map((skin, i) => this._resolveSkin(skin, i)); } if (gltf.scenes) { json.scenes = gltf.scenes.map((scene, i) => this._resolveScene(scene, i)); } if (typeof this.json.scene === "number" && json.scenes) { json.scene = json.scenes[this.json.scene]; } return json; } getScene(index) { return this._get(this.json.scenes, index); } getNode(index) { return this._get(this.json.nodes, index); } getSkin(index) { return this._get(this.json.skins, index); } getMesh(index) { return this._get(this.json.meshes, index); } getMaterial(index) { return this._get(this.json.materials, index); } getAccessor(index) { return this._get(this.json.accessors, index); } getCamera(index) { return this._get(this.json.cameras, index); } getTexture(index) { return this._get(this.json.textures, index); } getSampler(index) { return this._get(this.json.samplers, index); } getImage(index) { return this._get(this.json.images, index); } getBufferView(index) { return this._get(this.json.bufferViews, index); } getBuffer(index) { return this._get(this.json.buffers, index); } _get(array, index) { if (typeof index === "object") { return index; } const object = array && array[index]; if (!object) { console.warn(`glTF file error: Could not find ${array}[${index}]`); } return object; } // PARSING HELPERS _resolveScene(scene, index) { return { ...scene, // @ts-ignore id: scene.id || `scene-${index}`, nodes: (scene.nodes || []).map((node) => this.getNode(node)) }; } _resolveNode(gltfNode, index) { const node = { ...gltfNode, // @ts-expect-error id could already be present, glTF standard does not prevent it id: (gltfNode == null ? void 0 : gltfNode.id) || `node-${index}` }; if (gltfNode.mesh !== void 0) { node.mesh = this.getMesh(gltfNode.mesh); } if (gltfNode.camera !== void 0) { node.camera = this.getCamera(gltfNode.camera); } if (gltfNode.skin !== void 0) { node.skin = this.getSkin(gltfNode.skin); } if (gltfNode.meshes !== void 0 && gltfNode.meshes.length) { node.mesh = gltfNode.meshes.reduce((accum, meshIndex) => { const mesh = this.getMesh(meshIndex); accum.id = mesh.id; accum.primitives = accum.primitives.concat(mesh.primitives); return accum; }, { primitives: [] }); } return node; } _resolveNodeChildren(node) { if (node.children) { node.children = node.children.map((child) => this.getNode(child)); } return node; } _resolveSkin(gltfSkin, index) { const inverseBindMatrices = typeof gltfSkin.inverseBindMatrices === "number" ? this.getAccessor(gltfSkin.inverseBindMatrices) : void 0; return { ...gltfSkin, id: gltfSkin.id || `skin-${index}`, inverseBindMatrices }; } _resolveMesh(gltfMesh, index) { const mesh = { ...gltfMesh, id: gltfMesh.id || `mesh-${index}`, primitives: [] }; if (gltfMesh.primitives) { mesh.primitives = gltfMesh.primitives.map((gltfPrimitive) => { const primitive = { ...gltfPrimitive, attributes: {}, indices: void 0, material: void 0 }; const attributes = gltfPrimitive.attributes; for (const attribute in attributes) { primitive.attributes[attribute] = this.getAccessor(attributes[attribute]); } if (gltfPrimitive.indices !== void 0) { primitive.indices = this.getAccessor(gltfPrimitive.indices); } if (gltfPrimitive.material !== void 0) { primitive.material = this.getMaterial(gltfPrimitive.material); } return primitive; }); } return mesh; } _resolveMaterial(gltfMaterial, index) { const material = { ...gltfMaterial, // @ts-expect-error id: gltfMaterial.id || `material-${index}` }; if (material.normalTexture) { material.normalTexture = { ...material.normalTexture }; material.normalTexture.texture = this.getTexture(material.normalTexture.index); } if (material.occlusionTexture) { material.occlusionTexture = { ...material.occlusionTexture }; material.occlusionTexture.texture = this.getTexture(material.occlusionTexture.index); } if (material.emissiveTexture) { material.emissiveTexture = { ...material.emissiveTexture }; material.emissiveTexture.texture = this.getTexture(material.emissiveTexture.index); } if (!material.emissiveFactor) { material.emissiveFactor = material.emissiveTexture ? [1, 1, 1] : [0, 0, 0]; } if (material.pbrMetallicRoughness) { material.pbrMetallicRoughness = { ...material.pbrMetallicRoughness }; const mr = material.pbrMetallicRoughness; if (mr.baseColorTexture) { mr.baseColorTexture = { ...mr.baseColorTexture }; mr.baseColorTexture.texture = this.getTexture(mr.baseColorTexture.index); } if (mr.metallicRoughnessTexture) { mr.metallicRoughnessTexture = { ...mr.metallicRoughnessTexture }; mr.metallicRoughnessTexture.texture = this.getTexture(mr.metallicRoughnessTexture.index); } } return material; } _resolveAccessor(gltfAccessor, index) { const bytesPerComponent = getBytesFromComponentType(gltfAccessor.componentType); const components = getSizeFromAccessorType(gltfAccessor.type); const bytesPerElement = bytesPerComponent * components; const accessor = { ...gltfAccessor, // @ts-expect-error id: gltfAccessor.id || `accessor-${index}`, bytesPerComponent, components, bytesPerElement, value: void 0, bufferView: void 0, sparse: void 0 }; if (gltfAccessor.bufferView !== void 0) { accessor.bufferView = this.getBufferView(gltfAccessor.bufferView); } if (accessor.bufferView) { const buffer = accessor.bufferView.buffer; const { ArrayType, byteLength } = getAccessorArrayTypeAndLength(accessor, accessor.bufferView); const byteOffset = (accessor.bufferView.byteOffset || 0) + (accessor.byteOffset || 0) + buffer.byteOffset; let cutBuffer = buffer.arrayBuffer.slice(byteOffset, byteOffset + byteLength); if (accessor.bufferView.byteStride) { cutBuffer = this._getValueFromInterleavedBuffer(buffer, byteOffset, accessor.bufferView.byteStride, accessor.bytesPerElement, accessor.count); } accessor.value = new ArrayType(cutBuffer); } return accessor; } /** * Take values of particular accessor from interleaved buffer * various parts of the buffer * @param buffer * @param byteOffset * @param byteStride * @param bytesPerElement * @param count * @returns */ _getValueFromInterleavedBuffer(buffer, byteOffset, byteStride, bytesPerElement, count) { const result = new Uint8Array(count * bytesPerElement); for (let i = 0; i < count; i++) { const elementOffset = byteOffset + i * byteStride; result.set(new Uint8Array(buffer.arrayBuffer.slice(elementOffset, elementOffset + bytesPerElement)), i * bytesPerElement); } return result.buffer; } _resolveTexture(gltfTexture, index) { return { ...gltfTexture, // @ts-expect-error id could already be present, glTF standard does not prevent it id: gltfTexture.id || `texture-${index}`, sampler: typeof gltfTexture.sampler === "number" ? this.getSampler(gltfTexture.sampler) : makeDefaultSampler(), source: typeof gltfTexture.source === "number" ? this.getImage(gltfTexture.source) : void 0 }; } _resolveSampler(gltfSampler, index) { const sampler = { // @ts-expect-error id could already be present, glTF standard does not prevent it id: gltfSampler.id || `sampler-${index}`, ...gltfSampler, parameters: {} }; for (const key in sampler) { const glEnum = this._enumSamplerParameter(key); if (glEnum !== void 0) { sampler.parameters[glEnum] = sampler[key]; } } return sampler; } _enumSamplerParameter(key) { return SAMPLER_PARAMETER_GLTF_TO_GL[key]; } _resolveImage(gltfImage, index) { const image = { ...gltfImage, // @ts-expect-error id could already be present, glTF standard does not prevent it id: gltfImage.id || `image-${index}`, image: null, bufferView: gltfImage.bufferView !== void 0 ? this.getBufferView(gltfImage.bufferView) : void 0 }; const preloadedImage = this.images[index]; if (preloadedImage) { image.image = preloadedImage; } return image; } _resolveBufferView(gltfBufferView, index) { const bufferIndex = gltfBufferView.buffer; const arrayBuffer = this.buffers[bufferIndex].arrayBuffer; let byteOffset = this.buffers[bufferIndex].byteOffset || 0; if (gltfBufferView.byteOffset) { byteOffset += gltfBufferView.byteOffset; } const bufferView = { // // @ts-expect-error id could already be present, glTF standard does not prevent it id: `bufferView-${index}`, ...gltfBufferView, // ...this.buffers[bufferIndex], buffer: this.buffers[bufferIndex], data: new Uint8Array(arrayBuffer, byteOffset, gltfBufferView.byteLength) }; return bufferView; } _resolveCamera(gltfCamera, index) { const camera = { ...gltfCamera, // @ts-expect-error id could already be present, glTF standard does not prevent it id: gltfCamera.id || `camera-${index}` }; if (camera.perspective) { } if (camera.orthographic) { } return camera; } }; function postProcessGLTF(gltf, options) { return new GLTFPostProcessor().postProcess(gltf, options); } //# sourceMappingURL=index.cjs.map